aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorDavid Vrabel <david.vrabel@citrix.com>2014-04-07 08:52:12 -0400
committerDavid Vrabel <david.vrabel@citrix.com>2014-04-07 08:52:12 -0400
commit2c5cb2770392fb9c5d8518688c8bc61986d70dc6 (patch)
treeb19210e709de6ee0d22b67ef605a569500cf1a18 /drivers
parentcd979883b9ede90643e019f33cb317933eb867b4 (diff)
parent683b6c6f82a60fabf47012581c2cfbf1b037ab95 (diff)
Merge commit '683b6c6f82a60fabf47012581c2cfbf1b037ab95' into stable/for-linus-3.15
This merge of the irq-core-for-linus branch broke the ARM build when Xen is enabled. Conflicts: drivers/xen/events/events_base.c
Diffstat (limited to 'drivers')
-rw-r--r--drivers/acpi/ec.c64
-rw-r--r--drivers/acpi/processor_throttling.c69
-rw-r--r--drivers/acpi/resource.c10
-rw-r--r--drivers/acpi/sleep.c32
-rw-r--r--drivers/ata/Kconfig56
-rw-r--r--drivers/ata/Makefile8
-rw-r--r--drivers/ata/acard-ahci.c1
-rw-r--r--drivers/ata/ahci.c7
-rw-r--r--drivers/ata/ahci.h14
-rw-r--r--drivers/ata/ahci_da850.c114
-rw-r--r--drivers/ata/ahci_imx.c333
-rw-r--r--drivers/ata/ahci_platform.c291
-rw-r--r--drivers/ata/ahci_st.c245
-rw-r--r--drivers/ata/ahci_sunxi.c249
-rw-r--r--drivers/ata/ahci_xgene.c486
-rw-r--r--drivers/ata/ata_generic.c1
-rw-r--r--drivers/ata/libahci.c38
-rw-r--r--drivers/ata/libahci_platform.c541
-rw-r--r--drivers/ata/libata-acpi.c1
-rw-r--r--drivers/ata/libata-core.c138
-rw-r--r--drivers/ata/libata-eh.c18
-rw-r--r--drivers/ata/libata-zpodd.c21
-rw-r--r--drivers/ata/pata_acpi.c1
-rw-r--r--drivers/ata/pata_amd.c1
-rw-r--r--drivers/ata/pata_arasan_cf.c2
-rw-r--r--drivers/ata/pata_artop.c1
-rw-r--r--drivers/ata/pata_at91.c1
-rw-r--r--drivers/ata/pata_atiixp.c1
-rw-r--r--drivers/ata/pata_atp867x.c1
-rw-r--r--drivers/ata/pata_cmd640.c1
-rw-r--r--drivers/ata/pata_cmd64x.c1
-rw-r--r--drivers/ata/pata_cs5520.c1
-rw-r--r--drivers/ata/pata_cs5530.c1
-rw-r--r--drivers/ata/pata_cs5535.c1
-rw-r--r--drivers/ata/pata_cs5536.c1
-rw-r--r--drivers/ata/pata_cypress.c1
-rw-r--r--drivers/ata/pata_efar.c1
-rw-r--r--drivers/ata/pata_ep93xx.c1
-rw-r--r--drivers/ata/pata_hpt366.c1
-rw-r--r--drivers/ata/pata_hpt37x.c1
-rw-r--r--drivers/ata/pata_hpt3x2n.c1
-rw-r--r--drivers/ata/pata_hpt3x3.c1
-rw-r--r--drivers/ata/pata_imx.c18
-rw-r--r--drivers/ata/pata_it8213.c1
-rw-r--r--drivers/ata/pata_it821x.c1
-rw-r--r--drivers/ata/pata_jmicron.c1
-rw-r--r--drivers/ata/pata_legacy.c1
-rw-r--r--drivers/ata/pata_marvell.c1
-rw-r--r--drivers/ata/pata_mpiix.c1
-rw-r--r--drivers/ata/pata_netcell.c1
-rw-r--r--drivers/ata/pata_ninja32.c1
-rw-r--r--drivers/ata/pata_ns87410.c1
-rw-r--r--drivers/ata/pata_ns87415.c1
-rw-r--r--drivers/ata/pata_oldpiix.c1
-rw-r--r--drivers/ata/pata_opti.c1
-rw-r--r--drivers/ata/pata_optidma.c1
-rw-r--r--drivers/ata/pata_pcmcia.c1
-rw-r--r--drivers/ata/pata_pdc2027x.c1
-rw-r--r--drivers/ata/pata_pdc202xx_old.c1
-rw-r--r--drivers/ata/pata_piccolo.c1
-rw-r--r--drivers/ata/pata_platform.c1
-rw-r--r--drivers/ata/pata_pxa.c1
-rw-r--r--drivers/ata/pata_radisys.c1
-rw-r--r--drivers/ata/pata_rdc.c1
-rw-r--r--drivers/ata/pata_rz1000.c1
-rw-r--r--drivers/ata/pata_sc1200.c1
-rw-r--r--drivers/ata/pata_scc.c1
-rw-r--r--drivers/ata/pata_sch.c1
-rw-r--r--drivers/ata/pata_serverworks.c1
-rw-r--r--drivers/ata/pata_sil680.c1
-rw-r--r--drivers/ata/pata_sis.c1
-rw-r--r--drivers/ata/pata_sl82c105.c1
-rw-r--r--drivers/ata/pata_triflex.c1
-rw-r--r--drivers/ata/pata_via.c1
-rw-r--r--drivers/ata/pdc_adma.c1
-rw-r--r--drivers/ata/sata_dwc_460ex.c4
-rw-r--r--drivers/ata/sata_highbank.c6
-rw-r--r--drivers/ata/sata_nv.c1
-rw-r--r--drivers/ata/sata_promise.c1
-rw-r--r--drivers/ata/sata_qstor.c1
-rw-r--r--drivers/ata/sata_sil.c1
-rw-r--r--drivers/ata/sata_sis.c1
-rw-r--r--drivers/ata/sata_svw.c1
-rw-r--r--drivers/ata/sata_sx4.c10
-rw-r--r--drivers/ata/sata_uli.c1
-rw-r--r--drivers/ata/sata_via.c1
-rw-r--r--drivers/ata/sata_vsc.c1
-rw-r--r--drivers/base/firmware_class.c1
-rw-r--r--drivers/block/aoe/aoecmd.c4
-rw-r--r--drivers/block/floppy.c42
-rw-r--r--drivers/block/mtip32xx/mtip32xx.c2
-rw-r--r--drivers/block/mtip32xx/mtip32xx.h2
-rw-r--r--drivers/block/nvme-core.c18
-rw-r--r--drivers/block/rbd.c1
-rw-r--r--drivers/block/zram/zram_drv.c2
-rw-r--r--drivers/clk/at91/clk-master.c2
-rw-r--r--drivers/clk/clk-nomadik.c3
-rw-r--r--drivers/clk/clk.c13
-rw-r--r--drivers/clk/keystone/gate.c1
-rw-r--r--drivers/clk/mvebu/armada-370.c21
-rw-r--r--drivers/clk/mvebu/armada-xp.c20
-rw-r--r--drivers/clk/mvebu/dove.c19
-rw-r--r--drivers/clk/mvebu/kirkwood.c34
-rw-r--r--drivers/clk/shmobile/clk-rcar-gen2.c48
-rw-r--r--drivers/clk/tegra/clk-divider.c2
-rw-r--r--drivers/clk/tegra/clk-id.h4
-rw-r--r--drivers/clk/tegra/clk-tegra-periph.c10
-rw-r--r--drivers/clk/tegra/clk-tegra-super-gen4.c2
-rw-r--r--drivers/clk/tegra/clk-tegra114.c8
-rw-r--r--drivers/clk/tegra/clk-tegra124.c48
-rw-r--r--drivers/clk/tegra/clk-tegra20.c2
-rw-r--r--drivers/clocksource/Kconfig48
-rw-r--r--drivers/clocksource/Makefile2
-rw-r--r--drivers/clocksource/arm_arch_timer.c1
-rw-r--r--drivers/clocksource/cadence_ttc_timer.c121
-rw-r--r--drivers/clocksource/exynos_mct.c2
-rw-r--r--drivers/clocksource/sun4i_timer.c2
-rw-r--r--drivers/clocksource/time-armada-370-xp.c12
-rw-r--r--drivers/clocksource/time-orion.c28
-rw-r--r--drivers/clocksource/timer-keystone.c241
-rw-r--r--drivers/clocksource/timer-u300.c447
-rw-r--r--drivers/clocksource/vf_pit_timer.c2
-rw-r--r--drivers/cpufreq/Kconfig2
-rw-r--r--drivers/cpufreq/cpufreq.c55
-rw-r--r--drivers/cpufreq/cpufreq_stats.c2
-rw-r--r--drivers/cpufreq/intel_pstate.c28
-rw-r--r--drivers/cpuidle/cpuidle-powernv.c5
-rw-r--r--drivers/cpuidle/cpuidle-pseries.c6
-rw-r--r--drivers/cpuidle/cpuidle.c14
-rw-r--r--drivers/dma/imx-sdma.c1
-rw-r--r--drivers/dma/ioat/dma.c52
-rw-r--r--drivers/dma/ioat/dma.h1
-rw-r--r--drivers/dma/ioat/dma_v2.c11
-rw-r--r--drivers/dma/ioat/dma_v3.c3
-rw-r--r--drivers/dma/ste_dma40.c4
-rw-r--r--drivers/edac/i7300_edac.c38
-rw-r--r--drivers/edac/i7core_edac.c9
-rw-r--r--drivers/extcon/extcon-arizona.c12
-rw-r--r--drivers/firewire/core-device.c22
-rw-r--r--drivers/firewire/net.c6
-rw-r--r--drivers/firewire/ohci.c15
-rw-r--r--drivers/firewire/sbp2.c17
-rw-r--r--drivers/firmware/dcdbas.c2
-rw-r--r--drivers/firmware/efi/efi-stub-helper.c136
-rw-r--r--drivers/firmware/efi/efi.c5
-rw-r--r--drivers/firmware/efi/efivars.c2
-rw-r--r--drivers/fmc/fmc-write-eeprom.c2
-rw-r--r--drivers/gpu/drm/armada/armada_drv.c10
-rw-r--r--drivers/gpu/drm/bochs/Kconfig1
-rw-r--r--drivers/gpu/drm/drm_cache.c10
-rw-r--r--drivers/gpu/drm/drm_pci.c2
-rw-r--r--drivers/gpu/drm/exynos/exynos_drm_drv.c10
-rw-r--r--drivers/gpu/drm/gma500/mmu.c2
-rw-r--r--drivers/gpu/drm/i915/i915_drv.c23
-rw-r--r--drivers/gpu/drm/i915/i915_gem_gtt.c2
-rw-r--r--drivers/gpu/drm/i915/i915_gem_stolen.c26
-rw-r--r--drivers/gpu/drm/i915/i915_irq.c71
-rw-r--r--drivers/gpu/drm/i915/intel_ddi.c1
-rw-r--r--drivers/gpu/drm/i915/intel_display.c8
-rw-r--r--drivers/gpu/drm/i915/intel_dp.c12
-rw-r--r--drivers/gpu/drm/i915/intel_hdmi.c6
-rw-r--r--drivers/gpu/drm/i915/intel_panel.c4
-rw-r--r--drivers/gpu/drm/i915/intel_pm.c6
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_drm.c14
-rw-r--r--drivers/gpu/drm/radeon/atombios_crtc.c16
-rw-r--r--drivers/gpu/drm/radeon/atombios_encoders.c2
-rw-r--r--drivers/gpu/drm/radeon/cik.c10
-rw-r--r--drivers/gpu/drm/radeon/cik_sdma.c14
-rw-r--r--drivers/gpu/drm/radeon/dce6_afmt.c15
-rw-r--r--drivers/gpu/drm/radeon/evergreen.c5
-rw-r--r--drivers/gpu/drm/radeon/evergreen_hdmi.c26
-rw-r--r--drivers/gpu/drm/radeon/evergreen_smc.h2
-rw-r--r--drivers/gpu/drm/radeon/ni.c3
-rw-r--r--drivers/gpu/drm/radeon/r100.c2
-rw-r--r--drivers/gpu/drm/radeon/r300.c2
-rw-r--r--drivers/gpu/drm/radeon/r420.c2
-rw-r--r--drivers/gpu/drm/radeon/r520.c2
-rw-r--r--drivers/gpu/drm/radeon/r600.c3
-rw-r--r--drivers/gpu/drm/radeon/r600_audio.c14
-rw-r--r--drivers/gpu/drm/radeon/r600_hdmi.c15
-rw-r--r--drivers/gpu/drm/radeon/radeon.h6
-rw-r--r--drivers/gpu/drm/radeon/radeon_atpx_handler.c3
-rw-r--r--drivers/gpu/drm/radeon/radeon_device.c5
-rw-r--r--drivers/gpu/drm/radeon/radeon_drv.c17
-rw-r--r--drivers/gpu/drm/radeon/radeon_kms.c16
-rw-r--r--drivers/gpu/drm/radeon/radeon_ttm.c5
-rw-r--r--drivers/gpu/drm/radeon/radeon_uvd.c2
-rw-r--r--drivers/gpu/drm/radeon/rs400.c2
-rw-r--r--drivers/gpu/drm/radeon/rs600.c2
-rw-r--r--drivers/gpu/drm/radeon/rs690.c2
-rw-r--r--drivers/gpu/drm/radeon/rv515.c2
-rw-r--r--drivers/gpu/drm/radeon/rv770.c5
-rw-r--r--drivers/gpu/drm/radeon/si.c3
-rw-r--r--drivers/gpu/drm/tegra/drm.c2
-rw-r--r--drivers/gpu/drm/tegra/rgb.c11
-rw-r--r--drivers/gpu/drm/ttm/ttm_bo.c8
-rw-r--r--drivers/gpu/drm/ttm/ttm_bo_vm.c12
-rw-r--r--drivers/gpu/drm/udl/udl_gem.c11
-rw-r--r--drivers/gpu/drm/vmwgfx/svga3d_reg.h7
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_drv.h2
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_mob.c35
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_resource.c3
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_surface.c18
-rw-r--r--drivers/gpu/host1x/job.c2
-rw-r--r--drivers/hid/hid-lg4ff.c2
-rw-r--r--drivers/hid/hid-sony.c27
-rw-r--r--drivers/hid/hidraw.c4
-rw-r--r--drivers/hv/vmbus_drv.c57
-rw-r--r--drivers/i2c/busses/Kconfig2
-rw-r--r--drivers/i2c/busses/i2c-cpm.c2
-rw-r--r--drivers/iio/gyro/Kconfig2
-rw-r--r--drivers/iio/gyro/st_gyro.h1
-rw-r--r--drivers/iio/gyro/st_gyro_core.c9
-rw-r--r--drivers/iio/gyro/st_gyro_i2c.c1
-rw-r--r--drivers/iio/gyro/st_gyro_spi.c1
-rw-r--r--drivers/iio/light/cm32181.c16
-rw-r--r--drivers/iio/light/cm36651.c45
-rw-r--r--drivers/infiniband/hw/mlx4/main.c4
-rw-r--r--drivers/infiniband/hw/mlx5/main.c4
-rw-r--r--drivers/infiniband/ulp/isert/ib_isert.c180
-rw-r--r--drivers/infiniband/ulp/isert/ib_isert.h7
-rw-r--r--drivers/input/evdev.c4
-rw-r--r--drivers/input/keyboard/adp5588-keys.c12
-rw-r--r--drivers/input/misc/arizona-haptics.c19
-rw-r--r--drivers/input/misc/da9052_onkey.c29
-rw-r--r--drivers/input/mouse/cypress_ps2.c1
-rw-r--r--drivers/input/mouse/synaptics.c55
-rw-r--r--drivers/input/mousedev.c73
-rw-r--r--drivers/iommu/omap-iommu-debug.c4
-rw-r--r--drivers/irqchip/Makefile1
-rw-r--r--drivers/irqchip/irq-armada-370-xp.c98
-rw-r--r--drivers/irqchip/irq-bcm2835.c4
-rw-r--r--drivers/irqchip/irq-gic.c11
-rw-r--r--drivers/irqchip/irq-metag-ext.c2
-rw-r--r--drivers/irqchip/irq-metag.c2
-rw-r--r--drivers/irqchip/irq-mmp.c6
-rw-r--r--drivers/irqchip/irq-moxart.c2
-rw-r--r--drivers/irqchip/irq-orion.c2
-rw-r--r--drivers/irqchip/irq-sirfsoc.c2
-rw-r--r--drivers/irqchip/irq-sun4i.c42
-rw-r--r--drivers/irqchip/irq-sunxi-nmi.c208
-rw-r--r--drivers/irqchip/irq-vic.c2
-rw-r--r--drivers/irqchip/irq-vt8500.c3
-rw-r--r--drivers/irqchip/irq-xtensa-mx.c2
-rw-r--r--drivers/irqchip/irq-zevio.c2
-rw-r--r--drivers/irqchip/irqchip.c3
-rw-r--r--drivers/isdn/capi/Kconfig18
-rw-r--r--drivers/md/Kconfig10
-rw-r--r--drivers/md/dm-cache-policy-mq.c4
-rw-r--r--drivers/md/dm-cache-target.c24
-rw-r--r--drivers/md/dm-io.c23
-rw-r--r--drivers/md/dm-mpath.c7
-rw-r--r--drivers/md/dm-raid1.c3
-rw-r--r--drivers/md/dm-snap-persistent.c3
-rw-r--r--drivers/md/dm-thin-metadata.c58
-rw-r--r--drivers/md/dm-thin-metadata.h21
-rw-r--r--drivers/md/dm-thin.c343
-rw-r--r--drivers/md/persistent-data/Kconfig10
-rw-r--r--drivers/md/persistent-data/dm-space-map-metadata.c115
-rw-r--r--drivers/md/persistent-data/dm-space-map-metadata.h11
-rw-r--r--drivers/misc/sgi-xp/xpc_uv.c2
-rw-r--r--drivers/mmc/host/dw_mmc.c2
-rw-r--r--drivers/mtd/nand/nand_base.c2
-rw-r--r--drivers/mtd/nand/omap2.c61
-rw-r--r--drivers/mtd/ubi/fastmap.c8
-rw-r--r--drivers/net/bonding/bond_3ad.c16
-rw-r--r--drivers/net/bonding/bond_alb.c2
-rw-r--r--drivers/net/bonding/bond_main.c124
-rw-r--r--drivers/net/bonding/bond_options.c1
-rw-r--r--drivers/net/bonding/bonding.h47
-rw-r--r--drivers/net/can/flexcan.c172
-rw-r--r--drivers/net/ethernet/atheros/alx/main.c14
-rw-r--r--drivers/net/ethernet/atheros/atl1e/atl1e_main.c4
-rw-r--r--drivers/net/ethernet/broadcom/b44.c14
-rw-r--r--drivers/net/ethernet/broadcom/bnx2.c37
-rw-r--r--drivers/net/ethernet/broadcom/bnx2.h5
-rw-r--r--drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c9
-rw-r--r--drivers/net/ethernet/broadcom/cnic.c111
-rw-r--r--drivers/net/ethernet/broadcom/cnic.h2
-rw-r--r--drivers/net/ethernet/broadcom/cnic_defs.h2
-rw-r--r--drivers/net/ethernet/broadcom/cnic_if.h16
-rw-r--r--drivers/net/ethernet/broadcom/tg3.c8
-rw-r--r--drivers/net/ethernet/broadcom/tg3.h6
-rw-r--r--drivers/net/ethernet/brocade/bna/bfa_ioc.c2
-rw-r--r--drivers/net/ethernet/brocade/bna/bnad.c40
-rw-r--r--drivers/net/ethernet/cadence/macb.c16
-rw-r--r--drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c1
-rw-r--r--drivers/net/ethernet/emulex/benet/be.h4
-rw-r--r--drivers/net/ethernet/emulex/benet/be_main.c84
-rw-r--r--drivers/net/ethernet/freescale/fec_main.c27
-rw-r--r--drivers/net/ethernet/ibm/ibmveth.c25
-rw-r--r--drivers/net/ethernet/ibm/ibmveth.h1
-rw-r--r--drivers/net/ethernet/marvell/mvneta.c60
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/en_netdev.c10
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/fw.c11
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/main.c20
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/mlx4.h4
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/mlx4_en.h4
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/main.c4
-rw-r--r--drivers/net/ethernet/micrel/ks8851.c30
-rw-r--r--drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_hw.c1
-rw-r--r--drivers/net/ethernet/qlogic/qlcnic/qlcnic_dcb.c4
-rw-r--r--drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c5
-rw-r--r--drivers/net/ethernet/qlogic/qlcnic/qlcnic_sriov_pf.c9
-rw-r--r--drivers/net/ethernet/qlogic/qlge/qlge_main.c4
-rw-r--r--drivers/net/ethernet/realtek/r8169.c4
-rw-r--r--drivers/net/ethernet/sfc/ptp.c7
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/chain_mode.c2
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/common.h20
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/ring_mode.c9
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/stmmac_main.c93
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c2
-rw-r--r--drivers/net/ethernet/ti/cpsw.c10
-rw-r--r--drivers/net/ethernet/ti/davinci_cpdma.c4
-rw-r--r--drivers/net/ethernet/ti/davinci_emac.c53
-rw-r--r--drivers/net/ethernet/via/via-rhine.c8
-rw-r--r--drivers/net/hyperv/netvsc_drv.c4
-rw-r--r--drivers/net/hyperv/rndis_filter.c21
-rw-r--r--drivers/net/ieee802154/at86rf230.c11
-rw-r--r--drivers/net/ifb.c3
-rw-r--r--drivers/net/macvlan.c7
-rw-r--r--drivers/net/phy/phy.c11
-rw-r--r--drivers/net/phy/phy_device.c19
-rw-r--r--drivers/net/tun.c4
-rw-r--r--drivers/net/usb/Makefile2
-rw-r--r--drivers/net/usb/ax88179_178a.c42
-rw-r--r--drivers/net/usb/cdc_ether.c7
-rw-r--r--drivers/net/usb/cdc_ncm.c48
-rw-r--r--drivers/net/usb/r8152.c15
-rw-r--r--drivers/net/usb/r815x.c248
-rw-r--r--drivers/net/usb/usbnet.c33
-rw-r--r--drivers/net/veth.c6
-rw-r--r--drivers/net/virtio_net.c9
-rw-r--r--drivers/net/vmxnet3/vmxnet3_drv.c19
-rw-r--r--drivers/net/vxlan.c130
-rw-r--r--drivers/net/wireless/ath/ath9k/ar9462_2p0_initvals.h4
-rw-r--r--drivers/net/wireless/ath/ath9k/hw.c7
-rw-r--r--drivers/net/wireless/ath/ath9k/recv.c70
-rw-r--r--drivers/net/wireless/ath/ath9k/xmit.c15
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/dhd_sdio.c18
-rw-r--r--drivers/net/wireless/hostap/hostap_ap.c2
-rw-r--r--drivers/net/wireless/iwlwifi/dvm/sta.c1
-rw-r--r--drivers/net/wireless/iwlwifi/dvm/tx.c14
-rw-r--r--drivers/net/wireless/iwlwifi/mvm/bt-coex.c7
-rw-r--r--drivers/net/wireless/iwlwifi/mvm/mvm.h2
-rw-r--r--drivers/net/wireless/iwlwifi/mvm/tx.c18
-rw-r--r--drivers/net/wireless/iwlwifi/pcie/drv.c5
-rw-r--r--drivers/net/wireless/libertas/cfg.c2
-rw-r--r--drivers/net/wireless/mwifiex/11ac.c3
-rw-r--r--drivers/net/wireless/mwifiex/11n.c3
-rw-r--r--drivers/net/wireless/mwifiex/pcie.c34
-rw-r--r--drivers/net/wireless/mwifiex/scan.c8
-rw-r--r--drivers/net/wireless/mwifiex/usb.c12
-rw-r--r--drivers/net/wireless/mwifiex/wmm.c3
-rw-r--r--drivers/net/wireless/rt2x00/rt2800lib.c6
-rw-r--r--drivers/net/wireless/rt2x00/rt2800usb.c2
-rw-r--r--drivers/net/wireless/ti/wl1251/rx.c2
-rw-r--r--drivers/net/xen-netback/interface.c3
-rw-r--r--drivers/net/xen-netback/netback.c39
-rw-r--r--drivers/net/xen-netfront.c1
-rw-r--r--drivers/pci/bus.c2
-rw-r--r--drivers/pci/host/pcie-designware.c4
-rw-r--r--drivers/pci/pci.c3
-rw-r--r--drivers/pinctrl/Kconfig2
-rw-r--r--drivers/pinctrl/pinctrl-capri.c2
-rw-r--r--drivers/pinctrl/pinctrl-sunxi.c6
-rw-r--r--drivers/pinctrl/pinctrl-sunxi.h6
-rw-r--r--drivers/pinctrl/sh-pfc/pfc-r8a7791.c6
-rw-r--r--drivers/pinctrl/sirf/pinctrl-sirf.c4
-rw-r--r--drivers/pnp/pnpacpi/rsparser.c15
-rw-r--r--drivers/pnp/pnpbios/bioscalls.c9
-rw-r--r--drivers/ps3/ps3-vuart.c4
-rw-r--r--drivers/pwm/pwm-lp3943.c4
-rw-r--r--drivers/rapidio/devices/tsi721.h1
-rw-r--r--drivers/rapidio/devices/tsi721_dma.c27
-rw-r--r--drivers/regulator/core.c48
-rw-r--r--drivers/rtc/rtc-s3c.c17
-rw-r--r--drivers/s390/char/con3215.c8
-rw-r--r--drivers/s390/char/con3270.c13
-rw-r--r--drivers/s390/char/raw3270.c26
-rw-r--r--drivers/s390/char/raw3270.h3
-rw-r--r--drivers/s390/char/sclp_early.c31
-rw-r--r--drivers/s390/cio/airq.c66
-rw-r--r--drivers/s390/cio/chsc.c1
-rw-r--r--drivers/s390/cio/chsc_sch.c3
-rw-r--r--drivers/s390/cio/cio.c12
-rw-r--r--drivers/s390/cio/device.c52
-rw-r--r--drivers/s390/crypto/zcrypt_msgtype6.c24
-rw-r--r--drivers/s390/net/qeth_core_main.c9
-rw-r--r--drivers/s390/net/qeth_l2_main.c3
-rw-r--r--drivers/s390/net/qeth_l3_main.c3
-rw-r--r--drivers/scsi/atari_scsi.c12
-rw-r--r--drivers/scsi/be2iscsi/be_main.c2
-rw-r--r--drivers/scsi/bnx2fc/bnx2fc_io.c16
-rw-r--r--drivers/scsi/bnx2fc/bnx2fc_tgt.c38
-rw-r--r--drivers/scsi/bnx2i/bnx2i_hwi.c52
-rw-r--r--drivers/scsi/bnx2i/bnx2i_iscsi.c23
-rw-r--r--drivers/scsi/isci/host.h5
-rw-r--r--drivers/scsi/isci/port_config.c7
-rw-r--r--drivers/scsi/isci/task.c2
-rw-r--r--drivers/scsi/libsas/sas_ata.c35
-rw-r--r--drivers/scsi/qla2xxx/qla_def.h3
-rw-r--r--drivers/scsi/qla2xxx/qla_isr.c46
-rw-r--r--drivers/scsi/qla2xxx/qla_target.c42
-rw-r--r--drivers/scsi/qla2xxx/qla_target.h2
-rw-r--r--drivers/scsi/qla2xxx/tcm_qla2xxx.c158
-rw-r--r--drivers/scsi/qla2xxx/tcm_qla2xxx.h7
-rw-r--r--drivers/scsi/storvsc_drv.c3
-rw-r--r--drivers/spi/spi-ath79.c4
-rw-r--r--drivers/spi/spi-atmel.c17
-rw-r--r--drivers/spi/spi-coldfire-qspi.c6
-rw-r--r--drivers/spi/spi-fsl-dspi.c6
-rw-r--r--drivers/spi/spi-imx.c4
-rw-r--r--drivers/spi/spi-topcliff-pch.c15
-rw-r--r--drivers/staging/cxt1e1/linux.c2
-rw-r--r--drivers/staging/fwserial/fwserial.c13
-rw-r--r--drivers/staging/fwserial/fwserial.h1
-rw-r--r--drivers/staging/iio/adc/mxs-lradc.c1
-rw-r--r--drivers/staging/rtl8188eu/os_dep/usb_intf.c1
-rw-r--r--drivers/target/iscsi/iscsi_target.c10
-rw-r--r--drivers/target/iscsi/iscsi_target_erl2.c16
-rw-r--r--drivers/target/iscsi/iscsi_target_tpg.c2
-rw-r--r--drivers/target/target_core_sbc.c47
-rw-r--r--drivers/target/target_core_transport.c3
-rw-r--r--drivers/thermal/Kconfig13
-rw-r--r--drivers/thermal/thermal_core.c27
-rw-r--r--drivers/thermal/x86_pkg_temp_thermal.c11
-rw-r--r--drivers/tty/serial/sunhv.c22
-rw-r--r--drivers/tty/serial/sunsab.c14
-rw-r--r--drivers/tty/serial/sunsu.c14
-rw-r--r--drivers/tty/serial/sunzilog.c14
-rw-r--r--drivers/tty/tty_ldsem.c15
-rw-r--r--drivers/usb/core/config.c4
-rw-r--r--drivers/usb/core/hub.c4
-rw-r--r--drivers/usb/core/quirks.c4
-rw-r--r--drivers/usb/host/ehci-hcd.c13
-rw-r--r--drivers/usb/host/xhci.c14
-rw-r--r--drivers/usb/serial/ftdi_sio.c2
-rw-r--r--drivers/usb/serial/ftdi_sio_ids.h6
-rw-r--r--drivers/vfio/vfio_iommu_type1.c4
-rw-r--r--drivers/vhost/net.c20
-rw-r--r--drivers/vhost/scsi.c6
-rw-r--r--drivers/xen/balloon.c24
-rw-r--r--drivers/xen/events/events_2l.c15
-rw-r--r--drivers/xen/events/events_base.c25
-rw-r--r--drivers/xen/events/events_fifo.c8
446 files changed, 6810 insertions, 3274 deletions
diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c
index 959d41acc108..d7d32c28829b 100644
--- a/drivers/acpi/ec.c
+++ b/drivers/acpi/ec.c
@@ -67,6 +67,8 @@ enum ec_command {
67#define ACPI_EC_DELAY 500 /* Wait 500ms max. during EC ops */ 67#define ACPI_EC_DELAY 500 /* Wait 500ms max. during EC ops */
68#define ACPI_EC_UDELAY_GLK 1000 /* Wait 1ms max. to get global lock */ 68#define ACPI_EC_UDELAY_GLK 1000 /* Wait 1ms max. to get global lock */
69#define ACPI_EC_MSI_UDELAY 550 /* Wait 550us for MSI EC */ 69#define ACPI_EC_MSI_UDELAY 550 /* Wait 550us for MSI EC */
70#define ACPI_EC_CLEAR_MAX 100 /* Maximum number of events to query
71 * when trying to clear the EC */
70 72
71enum { 73enum {
72 EC_FLAGS_QUERY_PENDING, /* Query is pending */ 74 EC_FLAGS_QUERY_PENDING, /* Query is pending */
@@ -116,6 +118,7 @@ EXPORT_SYMBOL(first_ec);
116static int EC_FLAGS_MSI; /* Out-of-spec MSI controller */ 118static int EC_FLAGS_MSI; /* Out-of-spec MSI controller */
117static int EC_FLAGS_VALIDATE_ECDT; /* ASUStec ECDTs need to be validated */ 119static int EC_FLAGS_VALIDATE_ECDT; /* ASUStec ECDTs need to be validated */
118static int EC_FLAGS_SKIP_DSDT_SCAN; /* Not all BIOS survive early DSDT scan */ 120static int EC_FLAGS_SKIP_DSDT_SCAN; /* Not all BIOS survive early DSDT scan */
121static int EC_FLAGS_CLEAR_ON_RESUME; /* Needs acpi_ec_clear() on boot/resume */
119 122
120/* -------------------------------------------------------------------------- 123/* --------------------------------------------------------------------------
121 Transaction Management 124 Transaction Management
@@ -440,6 +443,29 @@ acpi_handle ec_get_handle(void)
440 443
441EXPORT_SYMBOL(ec_get_handle); 444EXPORT_SYMBOL(ec_get_handle);
442 445
446static int acpi_ec_query_unlocked(struct acpi_ec *ec, u8 *data);
447
448/*
449 * Clears stale _Q events that might have accumulated in the EC.
450 * Run with locked ec mutex.
451 */
452static void acpi_ec_clear(struct acpi_ec *ec)
453{
454 int i, status;
455 u8 value = 0;
456
457 for (i = 0; i < ACPI_EC_CLEAR_MAX; i++) {
458 status = acpi_ec_query_unlocked(ec, &value);
459 if (status || !value)
460 break;
461 }
462
463 if (unlikely(i == ACPI_EC_CLEAR_MAX))
464 pr_warn("Warning: Maximum of %d stale EC events cleared\n", i);
465 else
466 pr_info("%d stale EC events cleared\n", i);
467}
468
443void acpi_ec_block_transactions(void) 469void acpi_ec_block_transactions(void)
444{ 470{
445 struct acpi_ec *ec = first_ec; 471 struct acpi_ec *ec = first_ec;
@@ -463,6 +489,10 @@ void acpi_ec_unblock_transactions(void)
463 mutex_lock(&ec->mutex); 489 mutex_lock(&ec->mutex);
464 /* Allow transactions to be carried out again */ 490 /* Allow transactions to be carried out again */
465 clear_bit(EC_FLAGS_BLOCKED, &ec->flags); 491 clear_bit(EC_FLAGS_BLOCKED, &ec->flags);
492
493 if (EC_FLAGS_CLEAR_ON_RESUME)
494 acpi_ec_clear(ec);
495
466 mutex_unlock(&ec->mutex); 496 mutex_unlock(&ec->mutex);
467} 497}
468 498
@@ -821,6 +851,13 @@ static int acpi_ec_add(struct acpi_device *device)
821 851
822 /* EC is fully operational, allow queries */ 852 /* EC is fully operational, allow queries */
823 clear_bit(EC_FLAGS_QUERY_PENDING, &ec->flags); 853 clear_bit(EC_FLAGS_QUERY_PENDING, &ec->flags);
854
855 /* Clear stale _Q events if hardware might require that */
856 if (EC_FLAGS_CLEAR_ON_RESUME) {
857 mutex_lock(&ec->mutex);
858 acpi_ec_clear(ec);
859 mutex_unlock(&ec->mutex);
860 }
824 return ret; 861 return ret;
825} 862}
826 863
@@ -922,6 +959,30 @@ static int ec_enlarge_storm_threshold(const struct dmi_system_id *id)
922 return 0; 959 return 0;
923} 960}
924 961
962/*
963 * On some hardware it is necessary to clear events accumulated by the EC during
964 * sleep. These ECs stop reporting GPEs until they are manually polled, if too
965 * many events are accumulated. (e.g. Samsung Series 5/9 notebooks)
966 *
967 * https://bugzilla.kernel.org/show_bug.cgi?id=44161
968 *
969 * Ideally, the EC should also be instructed NOT to accumulate events during
970 * sleep (which Windows seems to do somehow), but the interface to control this
971 * behaviour is not known at this time.
972 *
973 * Models known to be affected are Samsung 530Uxx/535Uxx/540Uxx/550Pxx/900Xxx,
974 * however it is very likely that other Samsung models are affected.
975 *
976 * On systems which don't accumulate _Q events during sleep, this extra check
977 * should be harmless.
978 */
979static int ec_clear_on_resume(const struct dmi_system_id *id)
980{
981 pr_debug("Detected system needing EC poll on resume.\n");
982 EC_FLAGS_CLEAR_ON_RESUME = 1;
983 return 0;
984}
985
925static struct dmi_system_id ec_dmi_table[] __initdata = { 986static struct dmi_system_id ec_dmi_table[] __initdata = {
926 { 987 {
927 ec_skip_dsdt_scan, "Compal JFL92", { 988 ec_skip_dsdt_scan, "Compal JFL92", {
@@ -965,6 +1026,9 @@ static struct dmi_system_id ec_dmi_table[] __initdata = {
965 ec_validate_ecdt, "ASUS hardware", { 1026 ec_validate_ecdt, "ASUS hardware", {
966 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTek Computer Inc."), 1027 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTek Computer Inc."),
967 DMI_MATCH(DMI_PRODUCT_NAME, "L4R"),}, NULL}, 1028 DMI_MATCH(DMI_PRODUCT_NAME, "L4R"),}, NULL},
1029 {
1030 ec_clear_on_resume, "Samsung hardware", {
1031 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD.")}, NULL},
968 {}, 1032 {},
969}; 1033};
970 1034
diff --git a/drivers/acpi/processor_throttling.c b/drivers/acpi/processor_throttling.c
index 28baa05b8018..84243c32e29c 100644
--- a/drivers/acpi/processor_throttling.c
+++ b/drivers/acpi/processor_throttling.c
@@ -56,6 +56,12 @@ struct throttling_tstate {
56 int target_state; /* target T-state */ 56 int target_state; /* target T-state */
57}; 57};
58 58
59struct acpi_processor_throttling_arg {
60 struct acpi_processor *pr;
61 int target_state;
62 bool force;
63};
64
59#define THROTTLING_PRECHANGE (1) 65#define THROTTLING_PRECHANGE (1)
60#define THROTTLING_POSTCHANGE (2) 66#define THROTTLING_POSTCHANGE (2)
61 67
@@ -1060,16 +1066,24 @@ static int acpi_processor_set_throttling_ptc(struct acpi_processor *pr,
1060 return 0; 1066 return 0;
1061} 1067}
1062 1068
1069static long acpi_processor_throttling_fn(void *data)
1070{
1071 struct acpi_processor_throttling_arg *arg = data;
1072 struct acpi_processor *pr = arg->pr;
1073
1074 return pr->throttling.acpi_processor_set_throttling(pr,
1075 arg->target_state, arg->force);
1076}
1077
1063int acpi_processor_set_throttling(struct acpi_processor *pr, 1078int acpi_processor_set_throttling(struct acpi_processor *pr,
1064 int state, bool force) 1079 int state, bool force)
1065{ 1080{
1066 cpumask_var_t saved_mask;
1067 int ret = 0; 1081 int ret = 0;
1068 unsigned int i; 1082 unsigned int i;
1069 struct acpi_processor *match_pr; 1083 struct acpi_processor *match_pr;
1070 struct acpi_processor_throttling *p_throttling; 1084 struct acpi_processor_throttling *p_throttling;
1085 struct acpi_processor_throttling_arg arg;
1071 struct throttling_tstate t_state; 1086 struct throttling_tstate t_state;
1072 cpumask_var_t online_throttling_cpus;
1073 1087
1074 if (!pr) 1088 if (!pr)
1075 return -EINVAL; 1089 return -EINVAL;
@@ -1080,14 +1094,6 @@ int acpi_processor_set_throttling(struct acpi_processor *pr,
1080 if ((state < 0) || (state > (pr->throttling.state_count - 1))) 1094 if ((state < 0) || (state > (pr->throttling.state_count - 1)))
1081 return -EINVAL; 1095 return -EINVAL;
1082 1096
1083 if (!alloc_cpumask_var(&saved_mask, GFP_KERNEL))
1084 return -ENOMEM;
1085
1086 if (!alloc_cpumask_var(&online_throttling_cpus, GFP_KERNEL)) {
1087 free_cpumask_var(saved_mask);
1088 return -ENOMEM;
1089 }
1090
1091 if (cpu_is_offline(pr->id)) { 1097 if (cpu_is_offline(pr->id)) {
1092 /* 1098 /*
1093 * the cpu pointed by pr->id is offline. Unnecessary to change 1099 * the cpu pointed by pr->id is offline. Unnecessary to change
@@ -1096,17 +1102,15 @@ int acpi_processor_set_throttling(struct acpi_processor *pr,
1096 return -ENODEV; 1102 return -ENODEV;
1097 } 1103 }
1098 1104
1099 cpumask_copy(saved_mask, &current->cpus_allowed);
1100 t_state.target_state = state; 1105 t_state.target_state = state;
1101 p_throttling = &(pr->throttling); 1106 p_throttling = &(pr->throttling);
1102 cpumask_and(online_throttling_cpus, cpu_online_mask, 1107
1103 p_throttling->shared_cpu_map);
1104 /* 1108 /*
1105 * The throttling notifier will be called for every 1109 * The throttling notifier will be called for every
1106 * affected cpu in order to get one proper T-state. 1110 * affected cpu in order to get one proper T-state.
1107 * The notifier event is THROTTLING_PRECHANGE. 1111 * The notifier event is THROTTLING_PRECHANGE.
1108 */ 1112 */
1109 for_each_cpu(i, online_throttling_cpus) { 1113 for_each_cpu_and(i, cpu_online_mask, p_throttling->shared_cpu_map) {
1110 t_state.cpu = i; 1114 t_state.cpu = i;
1111 acpi_processor_throttling_notifier(THROTTLING_PRECHANGE, 1115 acpi_processor_throttling_notifier(THROTTLING_PRECHANGE,
1112 &t_state); 1116 &t_state);
@@ -1118,21 +1122,18 @@ int acpi_processor_set_throttling(struct acpi_processor *pr,
1118 * it can be called only for the cpu pointed by pr. 1122 * it can be called only for the cpu pointed by pr.
1119 */ 1123 */
1120 if (p_throttling->shared_type == DOMAIN_COORD_TYPE_SW_ANY) { 1124 if (p_throttling->shared_type == DOMAIN_COORD_TYPE_SW_ANY) {
1121 /* FIXME: use work_on_cpu() */ 1125 arg.pr = pr;
1122 if (set_cpus_allowed_ptr(current, cpumask_of(pr->id))) { 1126 arg.target_state = state;
1123 /* Can't migrate to the pr->id CPU. Exit */ 1127 arg.force = force;
1124 ret = -ENODEV; 1128 ret = work_on_cpu(pr->id, acpi_processor_throttling_fn, &arg);
1125 goto exit;
1126 }
1127 ret = p_throttling->acpi_processor_set_throttling(pr,
1128 t_state.target_state, force);
1129 } else { 1129 } else {
1130 /* 1130 /*
1131 * When the T-state coordination is SW_ALL or HW_ALL, 1131 * When the T-state coordination is SW_ALL or HW_ALL,
1132 * it is necessary to set T-state for every affected 1132 * it is necessary to set T-state for every affected
1133 * cpus. 1133 * cpus.
1134 */ 1134 */
1135 for_each_cpu(i, online_throttling_cpus) { 1135 for_each_cpu_and(i, cpu_online_mask,
1136 p_throttling->shared_cpu_map) {
1136 match_pr = per_cpu(processors, i); 1137 match_pr = per_cpu(processors, i);
1137 /* 1138 /*
1138 * If the pointer is invalid, we will report the 1139 * If the pointer is invalid, we will report the
@@ -1153,13 +1154,12 @@ int acpi_processor_set_throttling(struct acpi_processor *pr,
1153 "on CPU %d\n", i)); 1154 "on CPU %d\n", i));
1154 continue; 1155 continue;
1155 } 1156 }
1156 t_state.cpu = i; 1157
1157 /* FIXME: use work_on_cpu() */ 1158 arg.pr = match_pr;
1158 if (set_cpus_allowed_ptr(current, cpumask_of(i))) 1159 arg.target_state = state;
1159 continue; 1160 arg.force = force;
1160 ret = match_pr->throttling. 1161 ret = work_on_cpu(pr->id, acpi_processor_throttling_fn,
1161 acpi_processor_set_throttling( 1162 &arg);
1162 match_pr, t_state.target_state, force);
1163 } 1163 }
1164 } 1164 }
1165 /* 1165 /*
@@ -1168,17 +1168,12 @@ int acpi_processor_set_throttling(struct acpi_processor *pr,
1168 * affected cpu to update the T-states. 1168 * affected cpu to update the T-states.
1169 * The notifier event is THROTTLING_POSTCHANGE 1169 * The notifier event is THROTTLING_POSTCHANGE
1170 */ 1170 */
1171 for_each_cpu(i, online_throttling_cpus) { 1171 for_each_cpu_and(i, cpu_online_mask, p_throttling->shared_cpu_map) {
1172 t_state.cpu = i; 1172 t_state.cpu = i;
1173 acpi_processor_throttling_notifier(THROTTLING_POSTCHANGE, 1173 acpi_processor_throttling_notifier(THROTTLING_POSTCHANGE,
1174 &t_state); 1174 &t_state);
1175 } 1175 }
1176 /* restore the previous state */ 1176
1177 /* FIXME: use work_on_cpu() */
1178 set_cpus_allowed_ptr(current, saved_mask);
1179exit:
1180 free_cpumask_var(online_throttling_cpus);
1181 free_cpumask_var(saved_mask);
1182 return ret; 1177 return ret;
1183} 1178}
1184 1179
diff --git a/drivers/acpi/resource.c b/drivers/acpi/resource.c
index b7201fc6f1e1..0bdacc5e26a3 100644
--- a/drivers/acpi/resource.c
+++ b/drivers/acpi/resource.c
@@ -77,18 +77,24 @@ bool acpi_dev_resource_memory(struct acpi_resource *ares, struct resource *res)
77 switch (ares->type) { 77 switch (ares->type) {
78 case ACPI_RESOURCE_TYPE_MEMORY24: 78 case ACPI_RESOURCE_TYPE_MEMORY24:
79 memory24 = &ares->data.memory24; 79 memory24 = &ares->data.memory24;
80 if (!memory24->address_length)
81 return false;
80 acpi_dev_get_memresource(res, memory24->minimum, 82 acpi_dev_get_memresource(res, memory24->minimum,
81 memory24->address_length, 83 memory24->address_length,
82 memory24->write_protect); 84 memory24->write_protect);
83 break; 85 break;
84 case ACPI_RESOURCE_TYPE_MEMORY32: 86 case ACPI_RESOURCE_TYPE_MEMORY32:
85 memory32 = &ares->data.memory32; 87 memory32 = &ares->data.memory32;
88 if (!memory32->address_length)
89 return false;
86 acpi_dev_get_memresource(res, memory32->minimum, 90 acpi_dev_get_memresource(res, memory32->minimum,
87 memory32->address_length, 91 memory32->address_length,
88 memory32->write_protect); 92 memory32->write_protect);
89 break; 93 break;
90 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32: 94 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
91 fixed_memory32 = &ares->data.fixed_memory32; 95 fixed_memory32 = &ares->data.fixed_memory32;
96 if (!fixed_memory32->address_length)
97 return false;
92 acpi_dev_get_memresource(res, fixed_memory32->address, 98 acpi_dev_get_memresource(res, fixed_memory32->address,
93 fixed_memory32->address_length, 99 fixed_memory32->address_length,
94 fixed_memory32->write_protect); 100 fixed_memory32->write_protect);
@@ -144,12 +150,16 @@ bool acpi_dev_resource_io(struct acpi_resource *ares, struct resource *res)
144 switch (ares->type) { 150 switch (ares->type) {
145 case ACPI_RESOURCE_TYPE_IO: 151 case ACPI_RESOURCE_TYPE_IO:
146 io = &ares->data.io; 152 io = &ares->data.io;
153 if (!io->address_length)
154 return false;
147 acpi_dev_get_ioresource(res, io->minimum, 155 acpi_dev_get_ioresource(res, io->minimum,
148 io->address_length, 156 io->address_length,
149 io->io_decode); 157 io->io_decode);
150 break; 158 break;
151 case ACPI_RESOURCE_TYPE_FIXED_IO: 159 case ACPI_RESOURCE_TYPE_FIXED_IO:
152 fixed_io = &ares->data.fixed_io; 160 fixed_io = &ares->data.fixed_io;
161 if (!fixed_io->address_length)
162 return false;
153 acpi_dev_get_ioresource(res, fixed_io->address, 163 acpi_dev_get_ioresource(res, fixed_io->address,
154 fixed_io->address_length, 164 fixed_io->address_length,
155 ACPI_DECODE_10); 165 ACPI_DECODE_10);
diff --git a/drivers/acpi/sleep.c b/drivers/acpi/sleep.c
index b718806657cd..c40fb2e81bbc 100644
--- a/drivers/acpi/sleep.c
+++ b/drivers/acpi/sleep.c
@@ -71,6 +71,17 @@ static int acpi_sleep_prepare(u32 acpi_state)
71 return 0; 71 return 0;
72} 72}
73 73
74static bool acpi_sleep_state_supported(u8 sleep_state)
75{
76 acpi_status status;
77 u8 type_a, type_b;
78
79 status = acpi_get_sleep_type_data(sleep_state, &type_a, &type_b);
80 return ACPI_SUCCESS(status) && (!acpi_gbl_reduced_hardware
81 || (acpi_gbl_FADT.sleep_control.address
82 && acpi_gbl_FADT.sleep_status.address));
83}
84
74#ifdef CONFIG_ACPI_SLEEP 85#ifdef CONFIG_ACPI_SLEEP
75static u32 acpi_target_sleep_state = ACPI_STATE_S0; 86static u32 acpi_target_sleep_state = ACPI_STATE_S0;
76 87
@@ -604,15 +615,9 @@ static void acpi_sleep_suspend_setup(void)
604{ 615{
605 int i; 616 int i;
606 617
607 for (i = ACPI_STATE_S1; i < ACPI_STATE_S4; i++) { 618 for (i = ACPI_STATE_S1; i < ACPI_STATE_S4; i++)
608 acpi_status status; 619 if (acpi_sleep_state_supported(i))
609 u8 type_a, type_b;
610
611 status = acpi_get_sleep_type_data(i, &type_a, &type_b);
612 if (ACPI_SUCCESS(status)) {
613 sleep_states[i] = 1; 620 sleep_states[i] = 1;
614 }
615 }
616 621
617 suspend_set_ops(old_suspend_ordering ? 622 suspend_set_ops(old_suspend_ordering ?
618 &acpi_suspend_ops_old : &acpi_suspend_ops); 623 &acpi_suspend_ops_old : &acpi_suspend_ops);
@@ -740,11 +745,7 @@ static const struct platform_hibernation_ops acpi_hibernation_ops_old = {
740 745
741static void acpi_sleep_hibernate_setup(void) 746static void acpi_sleep_hibernate_setup(void)
742{ 747{
743 acpi_status status; 748 if (!acpi_sleep_state_supported(ACPI_STATE_S4))
744 u8 type_a, type_b;
745
746 status = acpi_get_sleep_type_data(ACPI_STATE_S4, &type_a, &type_b);
747 if (ACPI_FAILURE(status))
748 return; 749 return;
749 750
750 hibernation_set_ops(old_suspend_ordering ? 751 hibernation_set_ops(old_suspend_ordering ?
@@ -793,8 +794,6 @@ static void acpi_power_off(void)
793 794
794int __init acpi_sleep_init(void) 795int __init acpi_sleep_init(void)
795{ 796{
796 acpi_status status;
797 u8 type_a, type_b;
798 char supported[ACPI_S_STATE_COUNT * 3 + 1]; 797 char supported[ACPI_S_STATE_COUNT * 3 + 1];
799 char *pos = supported; 798 char *pos = supported;
800 int i; 799 int i;
@@ -806,8 +805,7 @@ int __init acpi_sleep_init(void)
806 acpi_sleep_suspend_setup(); 805 acpi_sleep_suspend_setup();
807 acpi_sleep_hibernate_setup(); 806 acpi_sleep_hibernate_setup();
808 807
809 status = acpi_get_sleep_type_data(ACPI_STATE_S5, &type_a, &type_b); 808 if (acpi_sleep_state_supported(ACPI_STATE_S5)) {
810 if (ACPI_SUCCESS(status)) {
811 sleep_states[ACPI_STATE_S5] = 1; 809 sleep_states[ACPI_STATE_S5] = 1;
812 pm_power_off_prepare = acpi_power_off_prepare; 810 pm_power_off_prepare = acpi_power_off_prepare;
813 pm_power_off = acpi_power_off; 811 pm_power_off = acpi_power_off;
diff --git a/drivers/ata/Kconfig b/drivers/ata/Kconfig
index 868429a47be4..20e03a7eb8b4 100644
--- a/drivers/ata/Kconfig
+++ b/drivers/ata/Kconfig
@@ -11,13 +11,13 @@ config HAVE_PATA_PLATFORM
11 to update the PATA_PLATFORM entry. 11 to update the PATA_PLATFORM entry.
12 12
13menuconfig ATA 13menuconfig ATA
14 tristate "Serial ATA and Parallel ATA drivers" 14 tristate "Serial ATA and Parallel ATA drivers (libata)"
15 depends on HAS_IOMEM 15 depends on HAS_IOMEM
16 depends on BLOCK 16 depends on BLOCK
17 depends on !(M32R || M68K || S390) || BROKEN 17 depends on !(M32R || M68K || S390) || BROKEN
18 select SCSI 18 select SCSI
19 ---help--- 19 ---help---
20 If you want to use a ATA hard disk, ATA tape drive, ATA CD-ROM or 20 If you want to use an ATA hard disk, ATA tape drive, ATA CD-ROM or
21 any other ATA device under Linux, say Y and make sure that you know 21 any other ATA device under Linux, say Y and make sure that you know
22 the name of your ATA host adapter (the card inside your computer 22 the name of your ATA host adapter (the card inside your computer
23 that "speaks" the ATA protocol, also called ATA controller), 23 that "speaks" the ATA protocol, also called ATA controller),
@@ -60,7 +60,7 @@ config ATA_ACPI
60 60
61config SATA_ZPODD 61config SATA_ZPODD
62 bool "SATA Zero Power Optical Disc Drive (ZPODD) support" 62 bool "SATA Zero Power Optical Disc Drive (ZPODD) support"
63 depends on ATA_ACPI 63 depends on ATA_ACPI && PM_RUNTIME
64 default n 64 default n
65 help 65 help
66 This option adds support for SATA Zero Power Optical Disc 66 This option adds support for SATA Zero Power Optical Disc
@@ -97,15 +97,48 @@ config SATA_AHCI_PLATFORM
97 97
98 If unsure, say N. 98 If unsure, say N.
99 99
100config AHCI_DA850
101 tristate "DaVinci DA850 AHCI SATA support"
102 depends on ARCH_DAVINCI_DA850
103 help
104 This option enables support for the DaVinci DA850 SoC's
105 onboard AHCI SATA.
106
107 If unsure, say N.
108
109config AHCI_ST
110 tristate "ST AHCI SATA support"
111 depends on ARCH_STI
112 help
113 This option enables support for ST AHCI SATA controller.
114
115 If unsure, say N.
116
100config AHCI_IMX 117config AHCI_IMX
101 tristate "Freescale i.MX AHCI SATA support" 118 tristate "Freescale i.MX AHCI SATA support"
102 depends on SATA_AHCI_PLATFORM && MFD_SYSCON 119 depends on MFD_SYSCON
103 help 120 help
104 This option enables support for the Freescale i.MX SoC's 121 This option enables support for the Freescale i.MX SoC's
105 onboard AHCI SATA. 122 onboard AHCI SATA.
106 123
107 If unsure, say N. 124 If unsure, say N.
108 125
126config AHCI_SUNXI
127 tristate "Allwinner sunxi AHCI SATA support"
128 depends on ARCH_SUNXI
129 help
130 This option enables support for the Allwinner sunxi SoC's
131 onboard AHCI SATA.
132
133 If unsure, say N.
134
135config AHCI_XGENE
136 tristate "APM X-Gene 6.0Gbps AHCI SATA host controller support"
137 depends on ARM64 || COMPILE_TEST
138 select PHY_XGENE
139 help
140 This option enables support for APM X-Gene SoC SATA host controller.
141
109config SATA_FSL 142config SATA_FSL
110 tristate "Freescale 3.0Gbps SATA support" 143 tristate "Freescale 3.0Gbps SATA support"
111 depends on FSL_SOC 144 depends on FSL_SOC
@@ -239,6 +272,7 @@ config SATA_DWC_VDEBUG
239 272
240config SATA_HIGHBANK 273config SATA_HIGHBANK
241 tristate "Calxeda Highbank SATA support" 274 tristate "Calxeda Highbank SATA support"
275 depends on ARCH_HIGHBANK || COMPILE_TEST
242 help 276 help
243 This option enables support for the Calxeda Highbank SoC's 277 This option enables support for the Calxeda Highbank SoC's
244 onboard SATA. 278 onboard SATA.
@@ -247,6 +281,8 @@ config SATA_HIGHBANK
247 281
248config SATA_MV 282config SATA_MV
249 tristate "Marvell SATA support" 283 tristate "Marvell SATA support"
284 depends on PCI || ARCH_DOVE || ARCH_KIRKWOOD || ARCH_MV78XX0 || \
285 ARCH_MVEBU || ARCH_ORION5X || COMPILE_TEST
250 select GENERIC_PHY 286 select GENERIC_PHY
251 help 287 help
252 This option enables support for the Marvell Serial ATA family. 288 This option enables support for the Marvell Serial ATA family.
@@ -273,6 +309,7 @@ config SATA_PROMISE
273 309
274config SATA_RCAR 310config SATA_RCAR
275 tristate "Renesas R-Car SATA support" 311 tristate "Renesas R-Car SATA support"
312 depends on ARCH_SHMOBILE || COMPILE_TEST
276 help 313 help
277 This option enables support for Renesas R-Car Serial ATA. 314 This option enables support for Renesas R-Car Serial ATA.
278 315
@@ -352,6 +389,7 @@ config PATA_AMD
352 389
353config PATA_ARASAN_CF 390config PATA_ARASAN_CF
354 tristate "ARASAN CompactFlash PATA Controller Support" 391 tristate "ARASAN CompactFlash PATA Controller Support"
392 depends on ARCH_SPEAR13XX || COMPILE_TEST
355 depends on DMADEVICES 393 depends on DMADEVICES
356 select DMA_ENGINE 394 select DMA_ENGINE
357 help 395 help
@@ -403,7 +441,7 @@ config PATA_CMD64X
403 441
404config PATA_CS5520 442config PATA_CS5520
405 tristate "CS5510/5520 PATA support" 443 tristate "CS5510/5520 PATA support"
406 depends on PCI 444 depends on PCI && (X86_32 || COMPILE_TEST)
407 help 445 help
408 This option enables support for the Cyrix 5510/5520 446 This option enables support for the Cyrix 5510/5520
409 companion chip used with the MediaGX/Geode processor family. 447 companion chip used with the MediaGX/Geode processor family.
@@ -412,7 +450,7 @@ config PATA_CS5520
412 450
413config PATA_CS5530 451config PATA_CS5530
414 tristate "CS5530 PATA support" 452 tristate "CS5530 PATA support"
415 depends on PCI 453 depends on PCI && (X86_32 || COMPILE_TEST)
416 help 454 help
417 This option enables support for the Cyrix/NatSemi/AMD CS5530 455 This option enables support for the Cyrix/NatSemi/AMD CS5530
418 companion chip used with the MediaGX/Geode processor family. 456 companion chip used with the MediaGX/Geode processor family.
@@ -421,7 +459,7 @@ config PATA_CS5530
421 459
422config PATA_CS5535 460config PATA_CS5535
423 tristate "CS5535 PATA support (Experimental)" 461 tristate "CS5535 PATA support (Experimental)"
424 depends on PCI && X86 && !X86_64 462 depends on PCI && X86_32
425 help 463 help
426 This option enables support for the NatSemi/AMD CS5535 464 This option enables support for the NatSemi/AMD CS5535
427 companion chip used with the Geode processor family. 465 companion chip used with the Geode processor family.
@@ -430,7 +468,7 @@ config PATA_CS5535
430 468
431config PATA_CS5536 469config PATA_CS5536
432 tristate "CS5536 PATA support" 470 tristate "CS5536 PATA support"
433 depends on PCI 471 depends on PCI && (X86_32 || MIPS || COMPILE_TEST)
434 help 472 help
435 This option enables support for the AMD CS5536 473 This option enables support for the AMD CS5536
436 companion chip used with the Geode LX processor family. 474 companion chip used with the Geode LX processor family.
@@ -666,7 +704,7 @@ config PATA_RDC
666 704
667config PATA_SC1200 705config PATA_SC1200
668 tristate "SC1200 PATA support" 706 tristate "SC1200 PATA support"
669 depends on PCI 707 depends on PCI && (X86_32 || COMPILE_TEST)
670 help 708 help
671 This option enables support for the NatSemi/AMD SC1200 SoC 709 This option enables support for the NatSemi/AMD SC1200 SoC
672 companion chip used with the Geode processor family. 710 companion chip used with the Geode processor family.
diff --git a/drivers/ata/Makefile b/drivers/ata/Makefile
index 46518c622460..44c8016e565c 100644
--- a/drivers/ata/Makefile
+++ b/drivers/ata/Makefile
@@ -4,13 +4,17 @@ obj-$(CONFIG_ATA) += libata.o
4# non-SFF interface 4# non-SFF interface
5obj-$(CONFIG_SATA_AHCI) += ahci.o libahci.o 5obj-$(CONFIG_SATA_AHCI) += ahci.o libahci.o
6obj-$(CONFIG_SATA_ACARD_AHCI) += acard-ahci.o libahci.o 6obj-$(CONFIG_SATA_ACARD_AHCI) += acard-ahci.o libahci.o
7obj-$(CONFIG_SATA_AHCI_PLATFORM) += ahci_platform.o libahci.o 7obj-$(CONFIG_SATA_AHCI_PLATFORM) += ahci_platform.o libahci.o libahci_platform.o
8obj-$(CONFIG_SATA_FSL) += sata_fsl.o 8obj-$(CONFIG_SATA_FSL) += sata_fsl.o
9obj-$(CONFIG_SATA_INIC162X) += sata_inic162x.o 9obj-$(CONFIG_SATA_INIC162X) += sata_inic162x.o
10obj-$(CONFIG_SATA_SIL24) += sata_sil24.o 10obj-$(CONFIG_SATA_SIL24) += sata_sil24.o
11obj-$(CONFIG_SATA_DWC) += sata_dwc_460ex.o 11obj-$(CONFIG_SATA_DWC) += sata_dwc_460ex.o
12obj-$(CONFIG_SATA_HIGHBANK) += sata_highbank.o libahci.o 12obj-$(CONFIG_SATA_HIGHBANK) += sata_highbank.o libahci.o
13obj-$(CONFIG_AHCI_IMX) += ahci_imx.o 13obj-$(CONFIG_AHCI_DA850) += ahci_da850.o libahci.o libahci_platform.o
14obj-$(CONFIG_AHCI_IMX) += ahci_imx.o libahci.o libahci_platform.o
15obj-$(CONFIG_AHCI_SUNXI) += ahci_sunxi.o libahci.o libahci_platform.o
16obj-$(CONFIG_AHCI_ST) += ahci_st.o libahci.o libahci_platform.o
17obj-$(CONFIG_AHCI_XGENE) += ahci_xgene.o libahci.o libahci_platform.o
14 18
15# SFF w/ custom DMA 19# SFF w/ custom DMA
16obj-$(CONFIG_PDC_ADMA) += pdc_adma.o 20obj-$(CONFIG_PDC_ADMA) += pdc_adma.o
diff --git a/drivers/ata/acard-ahci.c b/drivers/ata/acard-ahci.c
index fd665d919df2..b51605ac5974 100644
--- a/drivers/ata/acard-ahci.c
+++ b/drivers/ata/acard-ahci.c
@@ -36,7 +36,6 @@
36#include <linux/kernel.h> 36#include <linux/kernel.h>
37#include <linux/module.h> 37#include <linux/module.h>
38#include <linux/pci.h> 38#include <linux/pci.h>
39#include <linux/init.h>
40#include <linux/blkdev.h> 39#include <linux/blkdev.h>
41#include <linux/delay.h> 40#include <linux/delay.h>
42#include <linux/interrupt.h> 41#include <linux/interrupt.h>
diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
index c81d809c111b..a52a5b662f35 100644
--- a/drivers/ata/ahci.c
+++ b/drivers/ata/ahci.c
@@ -35,7 +35,6 @@
35#include <linux/kernel.h> 35#include <linux/kernel.h>
36#include <linux/module.h> 36#include <linux/module.h>
37#include <linux/pci.h> 37#include <linux/pci.h>
38#include <linux/init.h>
39#include <linux/blkdev.h> 38#include <linux/blkdev.h>
40#include <linux/delay.h> 39#include <linux/delay.h>
41#include <linux/interrupt.h> 40#include <linux/interrupt.h>
@@ -578,6 +577,7 @@ static int ahci_vt8251_hardreset(struct ata_link *link, unsigned int *class,
578 unsigned long deadline) 577 unsigned long deadline)
579{ 578{
580 struct ata_port *ap = link->ap; 579 struct ata_port *ap = link->ap;
580 struct ahci_host_priv *hpriv = ap->host->private_data;
581 bool online; 581 bool online;
582 int rc; 582 int rc;
583 583
@@ -588,7 +588,7 @@ static int ahci_vt8251_hardreset(struct ata_link *link, unsigned int *class,
588 rc = sata_link_hardreset(link, sata_ehc_deb_timing(&link->eh_context), 588 rc = sata_link_hardreset(link, sata_ehc_deb_timing(&link->eh_context),
589 deadline, &online, NULL); 589 deadline, &online, NULL);
590 590
591 ahci_start_engine(ap); 591 hpriv->start_engine(ap);
592 592
593 DPRINTK("EXIT, rc=%d, class=%u\n", rc, *class); 593 DPRINTK("EXIT, rc=%d, class=%u\n", rc, *class);
594 594
@@ -603,6 +603,7 @@ static int ahci_p5wdh_hardreset(struct ata_link *link, unsigned int *class,
603{ 603{
604 struct ata_port *ap = link->ap; 604 struct ata_port *ap = link->ap;
605 struct ahci_port_priv *pp = ap->private_data; 605 struct ahci_port_priv *pp = ap->private_data;
606 struct ahci_host_priv *hpriv = ap->host->private_data;
606 u8 *d2h_fis = pp->rx_fis + RX_FIS_D2H_REG; 607 u8 *d2h_fis = pp->rx_fis + RX_FIS_D2H_REG;
607 struct ata_taskfile tf; 608 struct ata_taskfile tf;
608 bool online; 609 bool online;
@@ -618,7 +619,7 @@ static int ahci_p5wdh_hardreset(struct ata_link *link, unsigned int *class,
618 rc = sata_link_hardreset(link, sata_ehc_deb_timing(&link->eh_context), 619 rc = sata_link_hardreset(link, sata_ehc_deb_timing(&link->eh_context),
619 deadline, &online, NULL); 620 deadline, &online, NULL);
620 621
621 ahci_start_engine(ap); 622 hpriv->start_engine(ap);
622 623
623 /* The pseudo configuration device on SIMG4726 attached to 624 /* The pseudo configuration device on SIMG4726 attached to
624 * ASUS P5W-DH Deluxe doesn't send signature FIS after 625 * ASUS P5W-DH Deluxe doesn't send signature FIS after
diff --git a/drivers/ata/ahci.h b/drivers/ata/ahci.h
index 2289efdf8203..51af275b3388 100644
--- a/drivers/ata/ahci.h
+++ b/drivers/ata/ahci.h
@@ -37,6 +37,8 @@
37 37
38#include <linux/clk.h> 38#include <linux/clk.h>
39#include <linux/libata.h> 39#include <linux/libata.h>
40#include <linux/phy/phy.h>
41#include <linux/regulator/consumer.h>
40 42
41/* Enclosure Management Control */ 43/* Enclosure Management Control */
42#define EM_CTRL_MSG_TYPE 0x000f0000 44#define EM_CTRL_MSG_TYPE 0x000f0000
@@ -51,6 +53,7 @@
51 53
52enum { 54enum {
53 AHCI_MAX_PORTS = 32, 55 AHCI_MAX_PORTS = 32,
56 AHCI_MAX_CLKS = 3,
54 AHCI_MAX_SG = 168, /* hardware max is 64K */ 57 AHCI_MAX_SG = 168, /* hardware max is 64K */
55 AHCI_DMA_BOUNDARY = 0xffffffff, 58 AHCI_DMA_BOUNDARY = 0xffffffff,
56 AHCI_MAX_CMDS = 32, 59 AHCI_MAX_CMDS = 32,
@@ -321,8 +324,17 @@ struct ahci_host_priv {
321 u32 em_loc; /* enclosure management location */ 324 u32 em_loc; /* enclosure management location */
322 u32 em_buf_sz; /* EM buffer size in byte */ 325 u32 em_buf_sz; /* EM buffer size in byte */
323 u32 em_msg_type; /* EM message type */ 326 u32 em_msg_type; /* EM message type */
324 struct clk *clk; /* Only for platforms supporting clk */ 327 bool got_runtime_pm; /* Did we do pm_runtime_get? */
328 struct clk *clks[AHCI_MAX_CLKS]; /* Optional */
329 struct regulator *target_pwr; /* Optional */
330 struct phy *phy; /* If platform uses phy */
325 void *plat_data; /* Other platform data */ 331 void *plat_data; /* Other platform data */
332 /*
333 * Optional ahci_start_engine override, if not set this gets set to the
334 * default ahci_start_engine during ahci_save_initial_config, this can
335 * be overridden anytime before the host is activated.
336 */
337 void (*start_engine)(struct ata_port *ap);
326}; 338};
327 339
328extern int ahci_ignore_sss; 340extern int ahci_ignore_sss;
diff --git a/drivers/ata/ahci_da850.c b/drivers/ata/ahci_da850.c
new file mode 100644
index 000000000000..2c83613ce2db
--- /dev/null
+++ b/drivers/ata/ahci_da850.c
@@ -0,0 +1,114 @@
1/*
2 * DaVinci DA850 AHCI SATA platform driver
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, or (at your option)
7 * any later version.
8 */
9
10#include <linux/kernel.h>
11#include <linux/module.h>
12#include <linux/pm.h>
13#include <linux/device.h>
14#include <linux/platform_device.h>
15#include <linux/libata.h>
16#include <linux/ahci_platform.h>
17#include "ahci.h"
18
19/* SATA PHY Control Register offset from AHCI base */
20#define SATA_P0PHYCR_REG 0x178
21
22#define SATA_PHY_MPY(x) ((x) << 0)
23#define SATA_PHY_LOS(x) ((x) << 6)
24#define SATA_PHY_RXCDR(x) ((x) << 10)
25#define SATA_PHY_RXEQ(x) ((x) << 13)
26#define SATA_PHY_TXSWING(x) ((x) << 19)
27#define SATA_PHY_ENPLL(x) ((x) << 31)
28
29/*
30 * The multiplier needed for 1.5GHz PLL output.
31 *
32 * NOTE: This is currently hardcoded to be suitable for 100MHz crystal
33 * frequency (which is used by DA850 EVM board) and may need to be changed
34 * if you would like to use this driver on some other board.
35 */
36#define DA850_SATA_CLK_MULTIPLIER 7
37
38static void da850_sata_init(struct device *dev, void __iomem *pwrdn_reg,
39 void __iomem *ahci_base)
40{
41 unsigned int val;
42
43 /* Enable SATA clock receiver */
44 val = readl(pwrdn_reg);
45 val &= ~BIT(0);
46 writel(val, pwrdn_reg);
47
48 val = SATA_PHY_MPY(DA850_SATA_CLK_MULTIPLIER + 1) | SATA_PHY_LOS(1) |
49 SATA_PHY_RXCDR(4) | SATA_PHY_RXEQ(1) | SATA_PHY_TXSWING(3) |
50 SATA_PHY_ENPLL(1);
51
52 writel(val, ahci_base + SATA_P0PHYCR_REG);
53}
54
55static const struct ata_port_info ahci_da850_port_info = {
56 .flags = AHCI_FLAG_COMMON,
57 .pio_mask = ATA_PIO4,
58 .udma_mask = ATA_UDMA6,
59 .port_ops = &ahci_platform_ops,
60};
61
62static int ahci_da850_probe(struct platform_device *pdev)
63{
64 struct device *dev = &pdev->dev;
65 struct ahci_host_priv *hpriv;
66 struct resource *res;
67 void __iomem *pwrdn_reg;
68 int rc;
69
70 hpriv = ahci_platform_get_resources(pdev);
71 if (IS_ERR(hpriv))
72 return PTR_ERR(hpriv);
73
74 rc = ahci_platform_enable_resources(hpriv);
75 if (rc)
76 return rc;
77
78 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
79 if (!res)
80 goto disable_resources;
81
82 pwrdn_reg = devm_ioremap(dev, res->start, resource_size(res));
83 if (!pwrdn_reg)
84 goto disable_resources;
85
86 da850_sata_init(dev, pwrdn_reg, hpriv->mmio);
87
88 rc = ahci_platform_init_host(pdev, hpriv, &ahci_da850_port_info, 0, 0);
89 if (rc)
90 goto disable_resources;
91
92 return 0;
93disable_resources:
94 ahci_platform_disable_resources(hpriv);
95 return rc;
96}
97
98static SIMPLE_DEV_PM_OPS(ahci_da850_pm_ops, ahci_platform_suspend,
99 ahci_platform_resume);
100
101static struct platform_driver ahci_da850_driver = {
102 .probe = ahci_da850_probe,
103 .remove = ata_platform_remove_one,
104 .driver = {
105 .name = "ahci_da850",
106 .owner = THIS_MODULE,
107 .pm = &ahci_da850_pm_ops,
108 },
109};
110module_platform_driver(ahci_da850_driver);
111
112MODULE_DESCRIPTION("DaVinci DA850 AHCI SATA platform driver");
113MODULE_AUTHOR("Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>");
114MODULE_LICENSE("GPL");
diff --git a/drivers/ata/ahci_imx.c b/drivers/ata/ahci_imx.c
index dd4d6f74d7bd..497c7abe1c7d 100644
--- a/drivers/ata/ahci_imx.c
+++ b/drivers/ata/ahci_imx.c
@@ -42,13 +42,7 @@ enum ahci_imx_type {
42struct imx_ahci_priv { 42struct imx_ahci_priv {
43 struct platform_device *ahci_pdev; 43 struct platform_device *ahci_pdev;
44 enum ahci_imx_type type; 44 enum ahci_imx_type type;
45
46 /* i.MX53 clock */
47 struct clk *sata_gate_clk;
48 /* Common clock */
49 struct clk *sata_ref_clk;
50 struct clk *ahb_clk; 45 struct clk *ahb_clk;
51
52 struct regmap *gpr; 46 struct regmap *gpr;
53 bool no_device; 47 bool no_device;
54 bool first_time; 48 bool first_time;
@@ -58,28 +52,52 @@ static int ahci_imx_hotplug;
58module_param_named(hotplug, ahci_imx_hotplug, int, 0644); 52module_param_named(hotplug, ahci_imx_hotplug, int, 0644);
59MODULE_PARM_DESC(hotplug, "AHCI IMX hot-plug support (0=Don't support, 1=support)"); 53MODULE_PARM_DESC(hotplug, "AHCI IMX hot-plug support (0=Don't support, 1=support)");
60 54
61static int imx_sata_clock_enable(struct device *dev) 55static void ahci_imx_host_stop(struct ata_host *host);
56
57static int imx_sata_enable(struct ahci_host_priv *hpriv)
62{ 58{
63 struct imx_ahci_priv *imxpriv = dev_get_drvdata(dev->parent); 59 struct imx_ahci_priv *imxpriv = hpriv->plat_data;
64 int ret; 60 int ret;
65 61
66 if (imxpriv->type == AHCI_IMX53) { 62 if (imxpriv->no_device)
67 ret = clk_prepare_enable(imxpriv->sata_gate_clk); 63 return 0;
68 if (ret < 0) { 64
69 dev_err(dev, "prepare-enable sata_gate clock err:%d\n", 65 if (hpriv->target_pwr) {
70 ret); 66 ret = regulator_enable(hpriv->target_pwr);
67 if (ret)
71 return ret; 68 return ret;
72 }
73 } 69 }
74 70
75 ret = clk_prepare_enable(imxpriv->sata_ref_clk); 71 ret = ahci_platform_enable_clks(hpriv);
76 if (ret < 0) { 72 if (ret < 0)
77 dev_err(dev, "prepare-enable sata_ref clock err:%d\n", 73 goto disable_regulator;
78 ret);
79 goto clk_err;
80 }
81 74
82 if (imxpriv->type == AHCI_IMX6Q) { 75 if (imxpriv->type == AHCI_IMX6Q) {
76 /*
77 * set PHY Paremeters, two steps to configure the GPR13,
78 * one write for rest of parameters, mask of first write
79 * is 0x07ffffff, and the other one write for setting
80 * the mpll_clk_en.
81 */
82 regmap_update_bits(imxpriv->gpr, IOMUXC_GPR13,
83 IMX6Q_GPR13_SATA_RX_EQ_VAL_MASK |
84 IMX6Q_GPR13_SATA_RX_LOS_LVL_MASK |
85 IMX6Q_GPR13_SATA_RX_DPLL_MODE_MASK |
86 IMX6Q_GPR13_SATA_SPD_MODE_MASK |
87 IMX6Q_GPR13_SATA_MPLL_SS_EN |
88 IMX6Q_GPR13_SATA_TX_ATTEN_MASK |
89 IMX6Q_GPR13_SATA_TX_BOOST_MASK |
90 IMX6Q_GPR13_SATA_TX_LVL_MASK |
91 IMX6Q_GPR13_SATA_MPLL_CLK_EN |
92 IMX6Q_GPR13_SATA_TX_EDGE_RATE,
93 IMX6Q_GPR13_SATA_RX_EQ_VAL_3_0_DB |
94 IMX6Q_GPR13_SATA_RX_LOS_LVL_SATA2M |
95 IMX6Q_GPR13_SATA_RX_DPLL_MODE_2P_4F |
96 IMX6Q_GPR13_SATA_SPD_MODE_3P0G |
97 IMX6Q_GPR13_SATA_MPLL_SS_EN |
98 IMX6Q_GPR13_SATA_TX_ATTEN_9_16 |
99 IMX6Q_GPR13_SATA_TX_BOOST_3_33_DB |
100 IMX6Q_GPR13_SATA_TX_LVL_1_025_V);
83 regmap_update_bits(imxpriv->gpr, IOMUXC_GPR13, 101 regmap_update_bits(imxpriv->gpr, IOMUXC_GPR13,
84 IMX6Q_GPR13_SATA_MPLL_CLK_EN, 102 IMX6Q_GPR13_SATA_MPLL_CLK_EN,
85 IMX6Q_GPR13_SATA_MPLL_CLK_EN); 103 IMX6Q_GPR13_SATA_MPLL_CLK_EN);
@@ -89,15 +107,19 @@ static int imx_sata_clock_enable(struct device *dev)
89 107
90 return 0; 108 return 0;
91 109
92clk_err: 110disable_regulator:
93 if (imxpriv->type == AHCI_IMX53) 111 if (hpriv->target_pwr)
94 clk_disable_unprepare(imxpriv->sata_gate_clk); 112 regulator_disable(hpriv->target_pwr);
113
95 return ret; 114 return ret;
96} 115}
97 116
98static void imx_sata_clock_disable(struct device *dev) 117static void imx_sata_disable(struct ahci_host_priv *hpriv)
99{ 118{
100 struct imx_ahci_priv *imxpriv = dev_get_drvdata(dev->parent); 119 struct imx_ahci_priv *imxpriv = hpriv->plat_data;
120
121 if (imxpriv->no_device)
122 return;
101 123
102 if (imxpriv->type == AHCI_IMX6Q) { 124 if (imxpriv->type == AHCI_IMX6Q) {
103 regmap_update_bits(imxpriv->gpr, IOMUXC_GPR13, 125 regmap_update_bits(imxpriv->gpr, IOMUXC_GPR13,
@@ -105,10 +127,10 @@ static void imx_sata_clock_disable(struct device *dev)
105 !IMX6Q_GPR13_SATA_MPLL_CLK_EN); 127 !IMX6Q_GPR13_SATA_MPLL_CLK_EN);
106 } 128 }
107 129
108 clk_disable_unprepare(imxpriv->sata_ref_clk); 130 ahci_platform_disable_clks(hpriv);
109 131
110 if (imxpriv->type == AHCI_IMX53) 132 if (hpriv->target_pwr)
111 clk_disable_unprepare(imxpriv->sata_gate_clk); 133 regulator_disable(hpriv->target_pwr);
112} 134}
113 135
114static void ahci_imx_error_handler(struct ata_port *ap) 136static void ahci_imx_error_handler(struct ata_port *ap)
@@ -118,7 +140,7 @@ static void ahci_imx_error_handler(struct ata_port *ap)
118 struct ata_host *host = dev_get_drvdata(ap->dev); 140 struct ata_host *host = dev_get_drvdata(ap->dev);
119 struct ahci_host_priv *hpriv = host->private_data; 141 struct ahci_host_priv *hpriv = host->private_data;
120 void __iomem *mmio = hpriv->mmio; 142 void __iomem *mmio = hpriv->mmio;
121 struct imx_ahci_priv *imxpriv = dev_get_drvdata(ap->dev->parent); 143 struct imx_ahci_priv *imxpriv = hpriv->plat_data;
122 144
123 ahci_error_handler(ap); 145 ahci_error_handler(ap);
124 146
@@ -136,7 +158,7 @@ static void ahci_imx_error_handler(struct ata_port *ap)
136 */ 158 */
137 reg_val = readl(mmio + PORT_PHY_CTL); 159 reg_val = readl(mmio + PORT_PHY_CTL);
138 writel(reg_val | PORT_PHY_CTL_PDDQ_LOC, mmio + PORT_PHY_CTL); 160 writel(reg_val | PORT_PHY_CTL_PDDQ_LOC, mmio + PORT_PHY_CTL);
139 imx_sata_clock_disable(ap->dev); 161 imx_sata_disable(hpriv);
140 imxpriv->no_device = true; 162 imxpriv->no_device = true;
141} 163}
142 164
@@ -144,7 +166,9 @@ static int ahci_imx_softreset(struct ata_link *link, unsigned int *class,
144 unsigned long deadline) 166 unsigned long deadline)
145{ 167{
146 struct ata_port *ap = link->ap; 168 struct ata_port *ap = link->ap;
147 struct imx_ahci_priv *imxpriv = dev_get_drvdata(ap->dev->parent); 169 struct ata_host *host = dev_get_drvdata(ap->dev);
170 struct ahci_host_priv *hpriv = host->private_data;
171 struct imx_ahci_priv *imxpriv = hpriv->plat_data;
148 int ret = -EIO; 172 int ret = -EIO;
149 173
150 if (imxpriv->type == AHCI_IMX53) 174 if (imxpriv->type == AHCI_IMX53)
@@ -156,7 +180,8 @@ static int ahci_imx_softreset(struct ata_link *link, unsigned int *class,
156} 180}
157 181
158static struct ata_port_operations ahci_imx_ops = { 182static struct ata_port_operations ahci_imx_ops = {
159 .inherits = &ahci_platform_ops, 183 .inherits = &ahci_ops,
184 .host_stop = ahci_imx_host_stop,
160 .error_handler = ahci_imx_error_handler, 185 .error_handler = ahci_imx_error_handler,
161 .softreset = ahci_imx_softreset, 186 .softreset = ahci_imx_softreset,
162}; 187};
@@ -168,79 +193,6 @@ static const struct ata_port_info ahci_imx_port_info = {
168 .port_ops = &ahci_imx_ops, 193 .port_ops = &ahci_imx_ops,
169}; 194};
170 195
171static int imx_sata_init(struct device *dev, void __iomem *mmio)
172{
173 int ret = 0;
174 unsigned int reg_val;
175 struct imx_ahci_priv *imxpriv = dev_get_drvdata(dev->parent);
176
177 ret = imx_sata_clock_enable(dev);
178 if (ret < 0)
179 return ret;
180
181 /*
182 * Configure the HWINIT bits of the HOST_CAP and HOST_PORTS_IMPL,
183 * and IP vendor specific register HOST_TIMER1MS.
184 * Configure CAP_SSS (support stagered spin up).
185 * Implement the port0.
186 * Get the ahb clock rate, and configure the TIMER1MS register.
187 */
188 reg_val = readl(mmio + HOST_CAP);
189 if (!(reg_val & HOST_CAP_SSS)) {
190 reg_val |= HOST_CAP_SSS;
191 writel(reg_val, mmio + HOST_CAP);
192 }
193 reg_val = readl(mmio + HOST_PORTS_IMPL);
194 if (!(reg_val & 0x1)) {
195 reg_val |= 0x1;
196 writel(reg_val, mmio + HOST_PORTS_IMPL);
197 }
198
199 reg_val = clk_get_rate(imxpriv->ahb_clk) / 1000;
200 writel(reg_val, mmio + HOST_TIMER1MS);
201
202 return 0;
203}
204
205static void imx_sata_exit(struct device *dev)
206{
207 imx_sata_clock_disable(dev);
208}
209
210static int imx_ahci_suspend(struct device *dev)
211{
212 struct imx_ahci_priv *imxpriv = dev_get_drvdata(dev->parent);
213
214 /*
215 * If no_device is set, The CLKs had been gated off in the
216 * initialization so don't do it again here.
217 */
218 if (!imxpriv->no_device)
219 imx_sata_clock_disable(dev);
220
221 return 0;
222}
223
224static int imx_ahci_resume(struct device *dev)
225{
226 struct imx_ahci_priv *imxpriv = dev_get_drvdata(dev->parent);
227 int ret = 0;
228
229 if (!imxpriv->no_device)
230 ret = imx_sata_clock_enable(dev);
231
232 return ret;
233}
234
235static struct ahci_platform_data imx_sata_pdata = {
236 .init = imx_sata_init,
237 .exit = imx_sata_exit,
238 .ata_port_info = &ahci_imx_port_info,
239 .suspend = imx_ahci_suspend,
240 .resume = imx_ahci_resume,
241
242};
243
244static const struct of_device_id imx_ahci_of_match[] = { 196static const struct of_device_id imx_ahci_of_match[] = {
245 { .compatible = "fsl,imx53-ahci", .data = (void *)AHCI_IMX53 }, 197 { .compatible = "fsl,imx53-ahci", .data = (void *)AHCI_IMX53 },
246 { .compatible = "fsl,imx6q-ahci", .data = (void *)AHCI_IMX6Q }, 198 { .compatible = "fsl,imx6q-ahci", .data = (void *)AHCI_IMX6Q },
@@ -251,151 +203,124 @@ MODULE_DEVICE_TABLE(of, imx_ahci_of_match);
251static int imx_ahci_probe(struct platform_device *pdev) 203static int imx_ahci_probe(struct platform_device *pdev)
252{ 204{
253 struct device *dev = &pdev->dev; 205 struct device *dev = &pdev->dev;
254 struct resource *mem, *irq, res[2];
255 const struct of_device_id *of_id; 206 const struct of_device_id *of_id;
256 enum ahci_imx_type type; 207 struct ahci_host_priv *hpriv;
257 const struct ahci_platform_data *pdata = NULL;
258 struct imx_ahci_priv *imxpriv; 208 struct imx_ahci_priv *imxpriv;
259 struct device *ahci_dev; 209 unsigned int reg_val;
260 struct platform_device *ahci_pdev;
261 int ret; 210 int ret;
262 211
263 of_id = of_match_device(imx_ahci_of_match, dev); 212 of_id = of_match_device(imx_ahci_of_match, dev);
264 if (!of_id) 213 if (!of_id)
265 return -EINVAL; 214 return -EINVAL;
266 215
267 type = (enum ahci_imx_type)of_id->data;
268 pdata = &imx_sata_pdata;
269
270 imxpriv = devm_kzalloc(dev, sizeof(*imxpriv), GFP_KERNEL); 216 imxpriv = devm_kzalloc(dev, sizeof(*imxpriv), GFP_KERNEL);
271 if (!imxpriv) { 217 if (!imxpriv)
272 dev_err(dev, "can't alloc ahci_host_priv\n");
273 return -ENOMEM; 218 return -ENOMEM;
274 }
275
276 ahci_pdev = platform_device_alloc("ahci", -1);
277 if (!ahci_pdev)
278 return -ENODEV;
279
280 ahci_dev = &ahci_pdev->dev;
281 ahci_dev->parent = dev;
282 219
283 imxpriv->no_device = false; 220 imxpriv->no_device = false;
284 imxpriv->first_time = true; 221 imxpriv->first_time = true;
285 imxpriv->type = type; 222 imxpriv->type = (enum ahci_imx_type)of_id->data;
286
287 imxpriv->ahb_clk = devm_clk_get(dev, "ahb"); 223 imxpriv->ahb_clk = devm_clk_get(dev, "ahb");
288 if (IS_ERR(imxpriv->ahb_clk)) { 224 if (IS_ERR(imxpriv->ahb_clk)) {
289 dev_err(dev, "can't get ahb clock.\n"); 225 dev_err(dev, "can't get ahb clock.\n");
290 ret = PTR_ERR(imxpriv->ahb_clk); 226 return PTR_ERR(imxpriv->ahb_clk);
291 goto err_out;
292 } 227 }
293 228
294 if (type == AHCI_IMX53) { 229 if (imxpriv->type == AHCI_IMX6Q) {
295 imxpriv->sata_gate_clk = devm_clk_get(dev, "sata_gate"); 230 imxpriv->gpr = syscon_regmap_lookup_by_compatible(
296 if (IS_ERR(imxpriv->sata_gate_clk)) { 231 "fsl,imx6q-iomuxc-gpr");
297 dev_err(dev, "can't get sata_gate clock.\n"); 232 if (IS_ERR(imxpriv->gpr)) {
298 ret = PTR_ERR(imxpriv->sata_gate_clk); 233 dev_err(dev,
299 goto err_out; 234 "failed to find fsl,imx6q-iomux-gpr regmap\n");
235 return PTR_ERR(imxpriv->gpr);
300 } 236 }
301 } 237 }
302 238
303 imxpriv->sata_ref_clk = devm_clk_get(dev, "sata_ref"); 239 hpriv = ahci_platform_get_resources(pdev);
304 if (IS_ERR(imxpriv->sata_ref_clk)) { 240 if (IS_ERR(hpriv))
305 dev_err(dev, "can't get sata_ref clock.\n"); 241 return PTR_ERR(hpriv);
306 ret = PTR_ERR(imxpriv->sata_ref_clk); 242
307 goto err_out; 243 hpriv->plat_data = imxpriv;
308 }
309 244
310 imxpriv->ahci_pdev = ahci_pdev; 245 ret = imx_sata_enable(hpriv);
311 platform_set_drvdata(pdev, imxpriv); 246 if (ret)
247 return ret;
312 248
313 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 249 /*
314 irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 250 * Configure the HWINIT bits of the HOST_CAP and HOST_PORTS_IMPL,
315 if (!mem || !irq) { 251 * and IP vendor specific register HOST_TIMER1MS.
316 dev_err(dev, "no mmio/irq resource\n"); 252 * Configure CAP_SSS (support stagered spin up).
317 ret = -ENOMEM; 253 * Implement the port0.
318 goto err_out; 254 * Get the ahb clock rate, and configure the TIMER1MS register.
255 */
256 reg_val = readl(hpriv->mmio + HOST_CAP);
257 if (!(reg_val & HOST_CAP_SSS)) {
258 reg_val |= HOST_CAP_SSS;
259 writel(reg_val, hpriv->mmio + HOST_CAP);
260 }
261 reg_val = readl(hpriv->mmio + HOST_PORTS_IMPL);
262 if (!(reg_val & 0x1)) {
263 reg_val |= 0x1;
264 writel(reg_val, hpriv->mmio + HOST_PORTS_IMPL);
319 } 265 }
320 266
321 res[0] = *mem; 267 reg_val = clk_get_rate(imxpriv->ahb_clk) / 1000;
322 res[1] = *irq; 268 writel(reg_val, hpriv->mmio + HOST_TIMER1MS);
323 269
324 ahci_dev->coherent_dma_mask = DMA_BIT_MASK(32); 270 ret = ahci_platform_init_host(pdev, hpriv, &ahci_imx_port_info, 0, 0);
325 ahci_dev->dma_mask = &ahci_dev->coherent_dma_mask; 271 if (ret)
326 ahci_dev->of_node = dev->of_node; 272 imx_sata_disable(hpriv);
327 273
328 if (type == AHCI_IMX6Q) { 274 return ret;
329 imxpriv->gpr = syscon_regmap_lookup_by_compatible( 275}
330 "fsl,imx6q-iomuxc-gpr");
331 if (IS_ERR(imxpriv->gpr)) {
332 dev_err(dev,
333 "failed to find fsl,imx6q-iomux-gpr regmap\n");
334 ret = PTR_ERR(imxpriv->gpr);
335 goto err_out;
336 }
337 276
338 /* 277static void ahci_imx_host_stop(struct ata_host *host)
339 * Set PHY Paremeters, two steps to configure the GPR13, 278{
340 * one write for rest of parameters, mask of first write 279 struct ahci_host_priv *hpriv = host->private_data;
341 * is 0x07fffffe, and the other one write for setting
342 * the mpll_clk_en happens in imx_sata_clock_enable().
343 */
344 regmap_update_bits(imxpriv->gpr, IOMUXC_GPR13,
345 IMX6Q_GPR13_SATA_RX_EQ_VAL_MASK |
346 IMX6Q_GPR13_SATA_RX_LOS_LVL_MASK |
347 IMX6Q_GPR13_SATA_RX_DPLL_MODE_MASK |
348 IMX6Q_GPR13_SATA_SPD_MODE_MASK |
349 IMX6Q_GPR13_SATA_MPLL_SS_EN |
350 IMX6Q_GPR13_SATA_TX_ATTEN_MASK |
351 IMX6Q_GPR13_SATA_TX_BOOST_MASK |
352 IMX6Q_GPR13_SATA_TX_LVL_MASK |
353 IMX6Q_GPR13_SATA_MPLL_CLK_EN |
354 IMX6Q_GPR13_SATA_TX_EDGE_RATE,
355 IMX6Q_GPR13_SATA_RX_EQ_VAL_3_0_DB |
356 IMX6Q_GPR13_SATA_RX_LOS_LVL_SATA2M |
357 IMX6Q_GPR13_SATA_RX_DPLL_MODE_2P_4F |
358 IMX6Q_GPR13_SATA_SPD_MODE_3P0G |
359 IMX6Q_GPR13_SATA_MPLL_SS_EN |
360 IMX6Q_GPR13_SATA_TX_ATTEN_9_16 |
361 IMX6Q_GPR13_SATA_TX_BOOST_3_33_DB |
362 IMX6Q_GPR13_SATA_TX_LVL_1_025_V);
363 }
364 280
365 ret = platform_device_add_resources(ahci_pdev, res, 2); 281 imx_sata_disable(hpriv);
366 if (ret) 282}
367 goto err_out;
368 283
369 ret = platform_device_add_data(ahci_pdev, pdata, sizeof(*pdata)); 284#ifdef CONFIG_PM_SLEEP
370 if (ret) 285static int imx_ahci_suspend(struct device *dev)
371 goto err_out; 286{
287 struct ata_host *host = dev_get_drvdata(dev);
288 struct ahci_host_priv *hpriv = host->private_data;
289 int ret;
372 290
373 ret = platform_device_add(ahci_pdev); 291 ret = ahci_platform_suspend_host(dev);
374 if (ret) { 292 if (ret)
375err_out:
376 platform_device_put(ahci_pdev);
377 return ret; 293 return ret;
378 } 294
295 imx_sata_disable(hpriv);
379 296
380 return 0; 297 return 0;
381} 298}
382 299
383static int imx_ahci_remove(struct platform_device *pdev) 300static int imx_ahci_resume(struct device *dev)
384{ 301{
385 struct imx_ahci_priv *imxpriv = platform_get_drvdata(pdev); 302 struct ata_host *host = dev_get_drvdata(dev);
386 struct platform_device *ahci_pdev = imxpriv->ahci_pdev; 303 struct ahci_host_priv *hpriv = host->private_data;
304 int ret;
387 305
388 platform_device_unregister(ahci_pdev); 306 ret = imx_sata_enable(hpriv);
389 return 0; 307 if (ret)
308 return ret;
309
310 return ahci_platform_resume_host(dev);
390} 311}
312#endif
313
314static SIMPLE_DEV_PM_OPS(ahci_imx_pm_ops, imx_ahci_suspend, imx_ahci_resume);
391 315
392static struct platform_driver imx_ahci_driver = { 316static struct platform_driver imx_ahci_driver = {
393 .probe = imx_ahci_probe, 317 .probe = imx_ahci_probe,
394 .remove = imx_ahci_remove, 318 .remove = ata_platform_remove_one,
395 .driver = { 319 .driver = {
396 .name = "ahci-imx", 320 .name = "ahci-imx",
397 .owner = THIS_MODULE, 321 .owner = THIS_MODULE,
398 .of_match_table = imx_ahci_of_match, 322 .of_match_table = imx_ahci_of_match,
323 .pm = &ahci_imx_pm_ops,
399 }, 324 },
400}; 325};
401module_platform_driver(imx_ahci_driver); 326module_platform_driver(imx_ahci_driver);
diff --git a/drivers/ata/ahci_platform.c b/drivers/ata/ahci_platform.c
index 4b231baceb09..ef67e79944f9 100644
--- a/drivers/ata/ahci_platform.c
+++ b/drivers/ata/ahci_platform.c
@@ -12,135 +12,36 @@
12 * any later version. 12 * any later version.
13 */ 13 */
14 14
15#include <linux/clk.h>
16#include <linux/kernel.h> 15#include <linux/kernel.h>
17#include <linux/gfp.h>
18#include <linux/module.h> 16#include <linux/module.h>
19#include <linux/pm.h> 17#include <linux/pm.h>
20#include <linux/init.h>
21#include <linux/interrupt.h>
22#include <linux/device.h> 18#include <linux/device.h>
23#include <linux/platform_device.h> 19#include <linux/platform_device.h>
24#include <linux/libata.h> 20#include <linux/libata.h>
25#include <linux/ahci_platform.h> 21#include <linux/ahci_platform.h>
26#include "ahci.h" 22#include "ahci.h"
27 23
28static void ahci_host_stop(struct ata_host *host); 24static const struct ata_port_info ahci_port_info = {
29 25 .flags = AHCI_FLAG_COMMON,
30enum ahci_type { 26 .pio_mask = ATA_PIO4,
31 AHCI, /* standard platform ahci */ 27 .udma_mask = ATA_UDMA6,
32 IMX53_AHCI, /* ahci on i.mx53 */ 28 .port_ops = &ahci_platform_ops,
33 STRICT_AHCI, /* delayed DMA engine start */
34};
35
36static struct platform_device_id ahci_devtype[] = {
37 {
38 .name = "ahci",
39 .driver_data = AHCI,
40 }, {
41 .name = "imx53-ahci",
42 .driver_data = IMX53_AHCI,
43 }, {
44 .name = "strict-ahci",
45 .driver_data = STRICT_AHCI,
46 }, {
47 /* sentinel */
48 }
49};
50MODULE_DEVICE_TABLE(platform, ahci_devtype);
51
52struct ata_port_operations ahci_platform_ops = {
53 .inherits = &ahci_ops,
54 .host_stop = ahci_host_stop,
55};
56EXPORT_SYMBOL_GPL(ahci_platform_ops);
57
58static struct ata_port_operations ahci_platform_retry_srst_ops = {
59 .inherits = &ahci_pmp_retry_srst_ops,
60 .host_stop = ahci_host_stop,
61};
62
63static const struct ata_port_info ahci_port_info[] = {
64 /* by features */
65 [AHCI] = {
66 .flags = AHCI_FLAG_COMMON,
67 .pio_mask = ATA_PIO4,
68 .udma_mask = ATA_UDMA6,
69 .port_ops = &ahci_platform_ops,
70 },
71 [IMX53_AHCI] = {
72 .flags = AHCI_FLAG_COMMON,
73 .pio_mask = ATA_PIO4,
74 .udma_mask = ATA_UDMA6,
75 .port_ops = &ahci_platform_retry_srst_ops,
76 },
77 [STRICT_AHCI] = {
78 AHCI_HFLAGS (AHCI_HFLAG_DELAY_ENGINE),
79 .flags = AHCI_FLAG_COMMON,
80 .pio_mask = ATA_PIO4,
81 .udma_mask = ATA_UDMA6,
82 .port_ops = &ahci_platform_ops,
83 },
84};
85
86static struct scsi_host_template ahci_platform_sht = {
87 AHCI_SHT("ahci_platform"),
88}; 29};
89 30
90static int ahci_probe(struct platform_device *pdev) 31static int ahci_probe(struct platform_device *pdev)
91{ 32{
92 struct device *dev = &pdev->dev; 33 struct device *dev = &pdev->dev;
93 struct ahci_platform_data *pdata = dev_get_platdata(dev); 34 struct ahci_platform_data *pdata = dev_get_platdata(dev);
94 const struct platform_device_id *id = platform_get_device_id(pdev);
95 struct ata_port_info pi = ahci_port_info[id ? id->driver_data : 0];
96 const struct ata_port_info *ppi[] = { &pi, NULL };
97 struct ahci_host_priv *hpriv; 35 struct ahci_host_priv *hpriv;
98 struct ata_host *host;
99 struct resource *mem;
100 int irq;
101 int n_ports;
102 int i;
103 int rc; 36 int rc;
104 37
105 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 38 hpriv = ahci_platform_get_resources(pdev);
106 if (!mem) { 39 if (IS_ERR(hpriv))
107 dev_err(dev, "no mmio space\n"); 40 return PTR_ERR(hpriv);
108 return -EINVAL;
109 }
110
111 irq = platform_get_irq(pdev, 0);
112 if (irq <= 0) {
113 dev_err(dev, "no irq\n");
114 return -EINVAL;
115 }
116
117 if (pdata && pdata->ata_port_info)
118 pi = *pdata->ata_port_info;
119
120 hpriv = devm_kzalloc(dev, sizeof(*hpriv), GFP_KERNEL);
121 if (!hpriv) {
122 dev_err(dev, "can't alloc ahci_host_priv\n");
123 return -ENOMEM;
124 }
125
126 hpriv->flags |= (unsigned long)pi.private_data;
127
128 hpriv->mmio = devm_ioremap(dev, mem->start, resource_size(mem));
129 if (!hpriv->mmio) {
130 dev_err(dev, "can't map %pR\n", mem);
131 return -ENOMEM;
132 }
133 41
134 hpriv->clk = clk_get(dev, NULL); 42 rc = ahci_platform_enable_resources(hpriv);
135 if (IS_ERR(hpriv->clk)) { 43 if (rc)
136 dev_err(dev, "can't get clock\n"); 44 return rc;
137 } else {
138 rc = clk_prepare_enable(hpriv->clk);
139 if (rc) {
140 dev_err(dev, "clock prepare enable failed");
141 goto free_clk;
142 }
143 }
144 45
145 /* 46 /*
146 * Some platforms might need to prepare for mmio region access, 47 * Some platforms might need to prepare for mmio region access,
@@ -151,69 +52,10 @@ static int ahci_probe(struct platform_device *pdev)
151 if (pdata && pdata->init) { 52 if (pdata && pdata->init) {
152 rc = pdata->init(dev, hpriv->mmio); 53 rc = pdata->init(dev, hpriv->mmio);
153 if (rc) 54 if (rc)
154 goto disable_unprepare_clk; 55 goto disable_resources;
155 }
156
157 ahci_save_initial_config(dev, hpriv,
158 pdata ? pdata->force_port_map : 0,
159 pdata ? pdata->mask_port_map : 0);
160
161 /* prepare host */
162 if (hpriv->cap & HOST_CAP_NCQ)
163 pi.flags |= ATA_FLAG_NCQ;
164
165 if (hpriv->cap & HOST_CAP_PMP)
166 pi.flags |= ATA_FLAG_PMP;
167
168 ahci_set_em_messages(hpriv, &pi);
169
170 /* CAP.NP sometimes indicate the index of the last enabled
171 * port, at other times, that of the last possible port, so
172 * determining the maximum port number requires looking at
173 * both CAP.NP and port_map.
174 */
175 n_ports = max(ahci_nr_ports(hpriv->cap), fls(hpriv->port_map));
176
177 host = ata_host_alloc_pinfo(dev, ppi, n_ports);
178 if (!host) {
179 rc = -ENOMEM;
180 goto pdata_exit;
181 }
182
183 host->private_data = hpriv;
184
185 if (!(hpriv->cap & HOST_CAP_SSS) || ahci_ignore_sss)
186 host->flags |= ATA_HOST_PARALLEL_SCAN;
187 else
188 dev_info(dev, "SSS flag set, parallel bus scan disabled\n");
189
190 if (pi.flags & ATA_FLAG_EM)
191 ahci_reset_em(host);
192
193 for (i = 0; i < host->n_ports; i++) {
194 struct ata_port *ap = host->ports[i];
195
196 ata_port_desc(ap, "mmio %pR", mem);
197 ata_port_desc(ap, "port 0x%x", 0x100 + ap->port_no * 0x80);
198
199 /* set enclosure management message type */
200 if (ap->flags & ATA_FLAG_EM)
201 ap->em_message_type = hpriv->em_msg_type;
202
203 /* disabled/not-implemented port */
204 if (!(hpriv->port_map & (1 << i)))
205 ap->ops = &ata_dummy_port_ops;
206 } 56 }
207 57
208 rc = ahci_reset_controller(host); 58 rc = ahci_platform_init_host(pdev, hpriv, &ahci_port_info, 0, 0);
209 if (rc)
210 goto pdata_exit;
211
212 ahci_init_controller(host);
213 ahci_print_info(host, "platform");
214
215 rc = ata_host_activate(host, irq, ahci_interrupt, IRQF_SHARED,
216 &ahci_platform_sht);
217 if (rc) 59 if (rc)
218 goto pdata_exit; 60 goto pdata_exit;
219 61
@@ -221,115 +63,19 @@ static int ahci_probe(struct platform_device *pdev)
221pdata_exit: 63pdata_exit:
222 if (pdata && pdata->exit) 64 if (pdata && pdata->exit)
223 pdata->exit(dev); 65 pdata->exit(dev);
224disable_unprepare_clk: 66disable_resources:
225 if (!IS_ERR(hpriv->clk)) 67 ahci_platform_disable_resources(hpriv);
226 clk_disable_unprepare(hpriv->clk);
227free_clk:
228 if (!IS_ERR(hpriv->clk))
229 clk_put(hpriv->clk);
230 return rc;
231}
232
233static void ahci_host_stop(struct ata_host *host)
234{
235 struct device *dev = host->dev;
236 struct ahci_platform_data *pdata = dev_get_platdata(dev);
237 struct ahci_host_priv *hpriv = host->private_data;
238
239 if (pdata && pdata->exit)
240 pdata->exit(dev);
241
242 if (!IS_ERR(hpriv->clk)) {
243 clk_disable_unprepare(hpriv->clk);
244 clk_put(hpriv->clk);
245 }
246}
247
248#ifdef CONFIG_PM_SLEEP
249static int ahci_suspend(struct device *dev)
250{
251 struct ahci_platform_data *pdata = dev_get_platdata(dev);
252 struct ata_host *host = dev_get_drvdata(dev);
253 struct ahci_host_priv *hpriv = host->private_data;
254 void __iomem *mmio = hpriv->mmio;
255 u32 ctl;
256 int rc;
257
258 if (hpriv->flags & AHCI_HFLAG_NO_SUSPEND) {
259 dev_err(dev, "firmware update required for suspend/resume\n");
260 return -EIO;
261 }
262
263 /*
264 * AHCI spec rev1.1 section 8.3.3:
265 * Software must disable interrupts prior to requesting a
266 * transition of the HBA to D3 state.
267 */
268 ctl = readl(mmio + HOST_CTL);
269 ctl &= ~HOST_IRQ_EN;
270 writel(ctl, mmio + HOST_CTL);
271 readl(mmio + HOST_CTL); /* flush */
272
273 rc = ata_host_suspend(host, PMSG_SUSPEND);
274 if (rc)
275 return rc;
276
277 if (pdata && pdata->suspend)
278 return pdata->suspend(dev);
279
280 if (!IS_ERR(hpriv->clk))
281 clk_disable_unprepare(hpriv->clk);
282
283 return 0;
284}
285
286static int ahci_resume(struct device *dev)
287{
288 struct ahci_platform_data *pdata = dev_get_platdata(dev);
289 struct ata_host *host = dev_get_drvdata(dev);
290 struct ahci_host_priv *hpriv = host->private_data;
291 int rc;
292
293 if (!IS_ERR(hpriv->clk)) {
294 rc = clk_prepare_enable(hpriv->clk);
295 if (rc) {
296 dev_err(dev, "clock prepare enable failed");
297 return rc;
298 }
299 }
300
301 if (pdata && pdata->resume) {
302 rc = pdata->resume(dev);
303 if (rc)
304 goto disable_unprepare_clk;
305 }
306
307 if (dev->power.power_state.event == PM_EVENT_SUSPEND) {
308 rc = ahci_reset_controller(host);
309 if (rc)
310 goto disable_unprepare_clk;
311
312 ahci_init_controller(host);
313 }
314
315 ata_host_resume(host);
316
317 return 0;
318
319disable_unprepare_clk:
320 if (!IS_ERR(hpriv->clk))
321 clk_disable_unprepare(hpriv->clk);
322
323 return rc; 68 return rc;
324} 69}
325#endif
326 70
327static SIMPLE_DEV_PM_OPS(ahci_pm_ops, ahci_suspend, ahci_resume); 71static SIMPLE_DEV_PM_OPS(ahci_pm_ops, ahci_platform_suspend,
72 ahci_platform_resume);
328 73
329static const struct of_device_id ahci_of_match[] = { 74static const struct of_device_id ahci_of_match[] = {
330 { .compatible = "snps,spear-ahci", }, 75 { .compatible = "snps,spear-ahci", },
331 { .compatible = "snps,exynos5440-ahci", }, 76 { .compatible = "snps,exynos5440-ahci", },
332 { .compatible = "ibm,476gtr-ahci", }, 77 { .compatible = "ibm,476gtr-ahci", },
78 { .compatible = "snps,dwc-ahci", },
333 {}, 79 {},
334}; 80};
335MODULE_DEVICE_TABLE(of, ahci_of_match); 81MODULE_DEVICE_TABLE(of, ahci_of_match);
@@ -343,7 +89,6 @@ static struct platform_driver ahci_driver = {
343 .of_match_table = ahci_of_match, 89 .of_match_table = ahci_of_match,
344 .pm = &ahci_pm_ops, 90 .pm = &ahci_pm_ops,
345 }, 91 },
346 .id_table = ahci_devtype,
347}; 92};
348module_platform_driver(ahci_driver); 93module_platform_driver(ahci_driver);
349 94
diff --git a/drivers/ata/ahci_st.c b/drivers/ata/ahci_st.c
new file mode 100644
index 000000000000..633222226c19
--- /dev/null
+++ b/drivers/ata/ahci_st.c
@@ -0,0 +1,245 @@
1/*
2 * Copyright (C) 2012 STMicroelectronics Limited
3 *
4 * Authors: Francesco Virlinzi <francesco.virlinzi@st.com>
5 * Alexandre Torgue <alexandre.torgue@st.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#include <linux/init.h>
13#include <linux/module.h>
14#include <linux/export.h>
15#include <linux/platform_device.h>
16#include <linux/clk.h>
17#include <linux/of.h>
18#include <linux/ahci_platform.h>
19#include <linux/libata.h>
20#include <linux/reset.h>
21#include <linux/io.h>
22#include <linux/dma-mapping.h>
23
24#include "ahci.h"
25
26#define ST_AHCI_OOBR 0xbc
27#define ST_AHCI_OOBR_WE BIT(31)
28#define ST_AHCI_OOBR_CWMIN_SHIFT 24
29#define ST_AHCI_OOBR_CWMAX_SHIFT 16
30#define ST_AHCI_OOBR_CIMIN_SHIFT 8
31#define ST_AHCI_OOBR_CIMAX_SHIFT 0
32
33struct st_ahci_drv_data {
34 struct platform_device *ahci;
35 struct reset_control *pwr;
36 struct reset_control *sw_rst;
37 struct reset_control *pwr_rst;
38 struct ahci_host_priv *hpriv;
39};
40
41static void st_ahci_configure_oob(void __iomem *mmio)
42{
43 unsigned long old_val, new_val;
44
45 new_val = (0x02 << ST_AHCI_OOBR_CWMIN_SHIFT) |
46 (0x04 << ST_AHCI_OOBR_CWMAX_SHIFT) |
47 (0x08 << ST_AHCI_OOBR_CIMIN_SHIFT) |
48 (0x0C << ST_AHCI_OOBR_CIMAX_SHIFT);
49
50 old_val = readl(mmio + ST_AHCI_OOBR);
51 writel(old_val | ST_AHCI_OOBR_WE, mmio + ST_AHCI_OOBR);
52 writel(new_val | ST_AHCI_OOBR_WE, mmio + ST_AHCI_OOBR);
53 writel(new_val, mmio + ST_AHCI_OOBR);
54}
55
56static int st_ahci_deassert_resets(struct device *dev)
57{
58 struct st_ahci_drv_data *drv_data = dev_get_drvdata(dev);
59 int err;
60
61 if (drv_data->pwr) {
62 err = reset_control_deassert(drv_data->pwr);
63 if (err) {
64 dev_err(dev, "unable to bring out of pwrdwn\n");
65 return err;
66 }
67 }
68
69 st_ahci_configure_oob(drv_data->hpriv->mmio);
70
71 if (drv_data->sw_rst) {
72 err = reset_control_deassert(drv_data->sw_rst);
73 if (err) {
74 dev_err(dev, "unable to bring out of sw-rst\n");
75 return err;
76 }
77 }
78
79 if (drv_data->pwr_rst) {
80 err = reset_control_deassert(drv_data->pwr_rst);
81 if (err) {
82 dev_err(dev, "unable to bring out of pwr-rst\n");
83 return err;
84 }
85 }
86
87 return 0;
88}
89
90static void st_ahci_host_stop(struct ata_host *host)
91{
92 struct ahci_host_priv *hpriv = host->private_data;
93 struct device *dev = host->dev;
94 struct st_ahci_drv_data *drv_data = dev_get_drvdata(dev);
95 int err;
96
97 if (drv_data->pwr) {
98 err = reset_control_assert(drv_data->pwr);
99 if (err)
100 dev_err(dev, "unable to pwrdwn\n");
101 }
102
103 ahci_platform_disable_resources(hpriv);
104}
105
106static int st_ahci_probe_resets(struct platform_device *pdev)
107{
108 struct st_ahci_drv_data *drv_data = platform_get_drvdata(pdev);
109
110 drv_data->pwr = devm_reset_control_get(&pdev->dev, "pwr-dwn");
111 if (IS_ERR(drv_data->pwr)) {
112 dev_info(&pdev->dev, "power reset control not defined\n");
113 drv_data->pwr = NULL;
114 }
115
116 drv_data->sw_rst = devm_reset_control_get(&pdev->dev, "sw-rst");
117 if (IS_ERR(drv_data->sw_rst)) {
118 dev_info(&pdev->dev, "soft reset control not defined\n");
119 drv_data->sw_rst = NULL;
120 }
121
122 drv_data->pwr_rst = devm_reset_control_get(&pdev->dev, "pwr-rst");
123 if (IS_ERR(drv_data->pwr_rst)) {
124 dev_dbg(&pdev->dev, "power soft reset control not defined\n");
125 drv_data->pwr_rst = NULL;
126 }
127
128 return st_ahci_deassert_resets(&pdev->dev);
129}
130
131static struct ata_port_operations st_ahci_port_ops = {
132 .inherits = &ahci_platform_ops,
133 .host_stop = st_ahci_host_stop,
134};
135
136static const struct ata_port_info st_ahci_port_info = {
137 .flags = AHCI_FLAG_COMMON,
138 .pio_mask = ATA_PIO4,
139 .udma_mask = ATA_UDMA6,
140 .port_ops = &st_ahci_port_ops,
141};
142
143static int st_ahci_probe(struct platform_device *pdev)
144{
145 struct st_ahci_drv_data *drv_data;
146 struct ahci_host_priv *hpriv;
147 int err;
148
149 drv_data = devm_kzalloc(&pdev->dev, sizeof(*drv_data), GFP_KERNEL);
150 if (!drv_data)
151 return -ENOMEM;
152
153 platform_set_drvdata(pdev, drv_data);
154
155 hpriv = ahci_platform_get_resources(pdev);
156 if (IS_ERR(hpriv))
157 return PTR_ERR(hpriv);
158
159 drv_data->hpriv = hpriv;
160
161 err = st_ahci_probe_resets(pdev);
162 if (err)
163 return err;
164
165 err = ahci_platform_enable_resources(hpriv);
166 if (err)
167 return err;
168
169 err = ahci_platform_init_host(pdev, hpriv, &st_ahci_port_info, 0, 0);
170 if (err) {
171 ahci_platform_disable_resources(hpriv);
172 return err;
173 }
174
175 return 0;
176}
177
178#ifdef CONFIG_PM_SLEEP
179static int st_ahci_suspend(struct device *dev)
180{
181 struct st_ahci_drv_data *drv_data = dev_get_drvdata(dev);
182 struct ahci_host_priv *hpriv = drv_data->hpriv;
183 int err;
184
185 err = ahci_platform_suspend_host(dev);
186 if (err)
187 return err;
188
189 if (drv_data->pwr) {
190 err = reset_control_assert(drv_data->pwr);
191 if (err) {
192 dev_err(dev, "unable to pwrdwn");
193 return err;
194 }
195 }
196
197 ahci_platform_disable_resources(hpriv);
198
199 return 0;
200}
201
202static int st_ahci_resume(struct device *dev)
203{
204 struct st_ahci_drv_data *drv_data = dev_get_drvdata(dev);
205 struct ahci_host_priv *hpriv = drv_data->hpriv;
206 int err;
207
208 err = ahci_platform_enable_resources(hpriv);
209 if (err)
210 return err;
211
212 err = st_ahci_deassert_resets(dev);
213 if (err) {
214 ahci_platform_disable_resources(hpriv);
215 return err;
216 }
217
218 return ahci_platform_resume_host(dev);
219}
220#endif
221
222static SIMPLE_DEV_PM_OPS(st_ahci_pm_ops, st_ahci_suspend, st_ahci_resume);
223
224static struct of_device_id st_ahci_match[] = {
225 { .compatible = "st,ahci", },
226 {},
227};
228MODULE_DEVICE_TABLE(of, st_ahci_match);
229
230static struct platform_driver st_ahci_driver = {
231 .driver = {
232 .name = "st_ahci",
233 .owner = THIS_MODULE,
234 .pm = &st_ahci_pm_ops,
235 .of_match_table = of_match_ptr(st_ahci_match),
236 },
237 .probe = st_ahci_probe,
238 .remove = ata_platform_remove_one,
239};
240module_platform_driver(st_ahci_driver);
241
242MODULE_AUTHOR("Alexandre Torgue <alexandre.torgue@st.com>");
243MODULE_AUTHOR("Francesco Virlinzi <francesco.virlinzi@st.com>");
244MODULE_DESCRIPTION("STMicroelectronics SATA AHCI Driver");
245MODULE_LICENSE("GPL v2");
diff --git a/drivers/ata/ahci_sunxi.c b/drivers/ata/ahci_sunxi.c
new file mode 100644
index 000000000000..42d3f64e74b3
--- /dev/null
+++ b/drivers/ata/ahci_sunxi.c
@@ -0,0 +1,249 @@
1/*
2 * Allwinner sunxi AHCI SATA platform driver
3 * Copyright 2013 Olliver Schinagl <oliver@schinagl.nl>
4 * Copyright 2014 Hans de Goede <hdegoede@redhat.com>
5 *
6 * based on the AHCI SATA platform driver by Jeff Garzik and Anton Vorontsov
7 * Based on code from Allwinner Technology Co., Ltd. <www.allwinnertech.com>,
8 * Daniel Wang <danielwang@allwinnertech.com>
9 *
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms and conditions of the GNU General Public License,
12 * version 2, as published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * more details.
18 */
19
20#include <linux/ahci_platform.h>
21#include <linux/clk.h>
22#include <linux/errno.h>
23#include <linux/kernel.h>
24#include <linux/module.h>
25#include <linux/of_device.h>
26#include <linux/platform_device.h>
27#include <linux/regulator/consumer.h>
28#include "ahci.h"
29
30#define AHCI_BISTAFR 0x00a0
31#define AHCI_BISTCR 0x00a4
32#define AHCI_BISTFCTR 0x00a8
33#define AHCI_BISTSR 0x00ac
34#define AHCI_BISTDECR 0x00b0
35#define AHCI_DIAGNR0 0x00b4
36#define AHCI_DIAGNR1 0x00b8
37#define AHCI_OOBR 0x00bc
38#define AHCI_PHYCS0R 0x00c0
39#define AHCI_PHYCS1R 0x00c4
40#define AHCI_PHYCS2R 0x00c8
41#define AHCI_TIMER1MS 0x00e0
42#define AHCI_GPARAM1R 0x00e8
43#define AHCI_GPARAM2R 0x00ec
44#define AHCI_PPARAMR 0x00f0
45#define AHCI_TESTR 0x00f4
46#define AHCI_VERSIONR 0x00f8
47#define AHCI_IDR 0x00fc
48#define AHCI_RWCR 0x00fc
49#define AHCI_P0DMACR 0x0170
50#define AHCI_P0PHYCR 0x0178
51#define AHCI_P0PHYSR 0x017c
52
53static void sunxi_clrbits(void __iomem *reg, u32 clr_val)
54{
55 u32 reg_val;
56
57 reg_val = readl(reg);
58 reg_val &= ~(clr_val);
59 writel(reg_val, reg);
60}
61
62static void sunxi_setbits(void __iomem *reg, u32 set_val)
63{
64 u32 reg_val;
65
66 reg_val = readl(reg);
67 reg_val |= set_val;
68 writel(reg_val, reg);
69}
70
71static void sunxi_clrsetbits(void __iomem *reg, u32 clr_val, u32 set_val)
72{
73 u32 reg_val;
74
75 reg_val = readl(reg);
76 reg_val &= ~(clr_val);
77 reg_val |= set_val;
78 writel(reg_val, reg);
79}
80
81static u32 sunxi_getbits(void __iomem *reg, u8 mask, u8 shift)
82{
83 return (readl(reg) >> shift) & mask;
84}
85
86static int ahci_sunxi_phy_init(struct device *dev, void __iomem *reg_base)
87{
88 u32 reg_val;
89 int timeout;
90
91 /* This magic is from the original code */
92 writel(0, reg_base + AHCI_RWCR);
93 msleep(5);
94
95 sunxi_setbits(reg_base + AHCI_PHYCS1R, BIT(19));
96 sunxi_clrsetbits(reg_base + AHCI_PHYCS0R,
97 (0x7 << 24),
98 (0x5 << 24) | BIT(23) | BIT(18));
99 sunxi_clrsetbits(reg_base + AHCI_PHYCS1R,
100 (0x3 << 16) | (0x1f << 8) | (0x3 << 6),
101 (0x2 << 16) | (0x6 << 8) | (0x2 << 6));
102 sunxi_setbits(reg_base + AHCI_PHYCS1R, BIT(28) | BIT(15));
103 sunxi_clrbits(reg_base + AHCI_PHYCS1R, BIT(19));
104 sunxi_clrsetbits(reg_base + AHCI_PHYCS0R,
105 (0x7 << 20), (0x3 << 20));
106 sunxi_clrsetbits(reg_base + AHCI_PHYCS2R,
107 (0x1f << 5), (0x19 << 5));
108 msleep(5);
109
110 sunxi_setbits(reg_base + AHCI_PHYCS0R, (0x1 << 19));
111
112 timeout = 250; /* Power up takes aprox 50 us */
113 do {
114 reg_val = sunxi_getbits(reg_base + AHCI_PHYCS0R, 0x7, 28);
115 if (reg_val == 0x02)
116 break;
117
118 if (--timeout == 0) {
119 dev_err(dev, "PHY power up failed.\n");
120 return -EIO;
121 }
122 udelay(1);
123 } while (1);
124
125 sunxi_setbits(reg_base + AHCI_PHYCS2R, (0x1 << 24));
126
127 timeout = 100; /* Calibration takes aprox 10 us */
128 do {
129 reg_val = sunxi_getbits(reg_base + AHCI_PHYCS2R, 0x1, 24);
130 if (reg_val == 0x00)
131 break;
132
133 if (--timeout == 0) {
134 dev_err(dev, "PHY calibration failed.\n");
135 return -EIO;
136 }
137 udelay(1);
138 } while (1);
139
140 msleep(15);
141
142 writel(0x7, reg_base + AHCI_RWCR);
143
144 return 0;
145}
146
147static void ahci_sunxi_start_engine(struct ata_port *ap)
148{
149 void __iomem *port_mmio = ahci_port_base(ap);
150 struct ahci_host_priv *hpriv = ap->host->private_data;
151
152 /* Setup DMA before DMA start */
153 sunxi_clrsetbits(hpriv->mmio + AHCI_P0DMACR, 0x0000ff00, 0x00004400);
154
155 /* Start DMA */
156 sunxi_setbits(port_mmio + PORT_CMD, PORT_CMD_START);
157}
158
159static const struct ata_port_info ahci_sunxi_port_info = {
160 AHCI_HFLAGS(AHCI_HFLAG_32BIT_ONLY | AHCI_HFLAG_NO_MSI |
161 AHCI_HFLAG_NO_PMP | AHCI_HFLAG_YES_NCQ),
162 .flags = AHCI_FLAG_COMMON | ATA_FLAG_NCQ,
163 .pio_mask = ATA_PIO4,
164 .udma_mask = ATA_UDMA6,
165 .port_ops = &ahci_platform_ops,
166};
167
168static int ahci_sunxi_probe(struct platform_device *pdev)
169{
170 struct device *dev = &pdev->dev;
171 struct ahci_host_priv *hpriv;
172 int rc;
173
174 hpriv = ahci_platform_get_resources(pdev);
175 if (IS_ERR(hpriv))
176 return PTR_ERR(hpriv);
177
178 hpriv->start_engine = ahci_sunxi_start_engine;
179
180 rc = ahci_platform_enable_resources(hpriv);
181 if (rc)
182 return rc;
183
184 rc = ahci_sunxi_phy_init(dev, hpriv->mmio);
185 if (rc)
186 goto disable_resources;
187
188 rc = ahci_platform_init_host(pdev, hpriv, &ahci_sunxi_port_info, 0, 0);
189 if (rc)
190 goto disable_resources;
191
192 return 0;
193
194disable_resources:
195 ahci_platform_disable_resources(hpriv);
196 return rc;
197}
198
199#ifdef CONFIG_PM_SLEEP
200static int ahci_sunxi_resume(struct device *dev)
201{
202 struct ata_host *host = dev_get_drvdata(dev);
203 struct ahci_host_priv *hpriv = host->private_data;
204 int rc;
205
206 rc = ahci_platform_enable_resources(hpriv);
207 if (rc)
208 return rc;
209
210 rc = ahci_sunxi_phy_init(dev, hpriv->mmio);
211 if (rc)
212 goto disable_resources;
213
214 rc = ahci_platform_resume_host(dev);
215 if (rc)
216 goto disable_resources;
217
218 return 0;
219
220disable_resources:
221 ahci_platform_disable_resources(hpriv);
222 return rc;
223}
224#endif
225
226static SIMPLE_DEV_PM_OPS(ahci_sunxi_pm_ops, ahci_platform_suspend,
227 ahci_sunxi_resume);
228
229static const struct of_device_id ahci_sunxi_of_match[] = {
230 { .compatible = "allwinner,sun4i-a10-ahci", },
231 { },
232};
233MODULE_DEVICE_TABLE(of, ahci_sunxi_of_match);
234
235static struct platform_driver ahci_sunxi_driver = {
236 .probe = ahci_sunxi_probe,
237 .remove = ata_platform_remove_one,
238 .driver = {
239 .name = "ahci-sunxi",
240 .owner = THIS_MODULE,
241 .of_match_table = ahci_sunxi_of_match,
242 .pm = &ahci_sunxi_pm_ops,
243 },
244};
245module_platform_driver(ahci_sunxi_driver);
246
247MODULE_DESCRIPTION("Allwinner sunxi AHCI SATA driver");
248MODULE_AUTHOR("Olliver Schinagl <oliver@schinagl.nl>");
249MODULE_LICENSE("GPL");
diff --git a/drivers/ata/ahci_xgene.c b/drivers/ata/ahci_xgene.c
new file mode 100644
index 000000000000..77c89bf171f1
--- /dev/null
+++ b/drivers/ata/ahci_xgene.c
@@ -0,0 +1,486 @@
1/*
2 * AppliedMicro X-Gene SoC SATA Host Controller Driver
3 *
4 * Copyright (c) 2014, Applied Micro Circuits Corporation
5 * Author: Loc Ho <lho@apm.com>
6 * Tuan Phan <tphan@apm.com>
7 * Suman Tripathi <stripathi@apm.com>
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2 of the License, or (at your
12 * 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, see <http://www.gnu.org/licenses/>.
21 *
22 * NOTE: PM support is not currently available.
23 *
24 */
25#include <linux/module.h>
26#include <linux/platform_device.h>
27#include <linux/ahci_platform.h>
28#include <linux/of_address.h>
29#include <linux/of_irq.h>
30#include <linux/phy/phy.h>
31#include "ahci.h"
32
33/* Max # of disk per a controller */
34#define MAX_AHCI_CHN_PERCTR 2
35
36/* MUX CSR */
37#define SATA_ENET_CONFIG_REG 0x00000000
38#define CFG_SATA_ENET_SELECT_MASK 0x00000001
39
40/* SATA core host controller CSR */
41#define SLVRDERRATTRIBUTES 0x00000000
42#define SLVWRERRATTRIBUTES 0x00000004
43#define MSTRDERRATTRIBUTES 0x00000008
44#define MSTWRERRATTRIBUTES 0x0000000c
45#define BUSCTLREG 0x00000014
46#define IOFMSTRWAUX 0x00000018
47#define INTSTATUSMASK 0x0000002c
48#define ERRINTSTATUS 0x00000030
49#define ERRINTSTATUSMASK 0x00000034
50
51/* SATA host AHCI CSR */
52#define PORTCFG 0x000000a4
53#define PORTADDR_SET(dst, src) \
54 (((dst) & ~0x0000003f) | (((u32)(src)) & 0x0000003f))
55#define PORTPHY1CFG 0x000000a8
56#define PORTPHY1CFG_FRCPHYRDY_SET(dst, src) \
57 (((dst) & ~0x00100000) | (((u32)(src) << 0x14) & 0x00100000))
58#define PORTPHY2CFG 0x000000ac
59#define PORTPHY3CFG 0x000000b0
60#define PORTPHY4CFG 0x000000b4
61#define PORTPHY5CFG 0x000000b8
62#define SCTL0 0x0000012C
63#define PORTPHY5CFG_RTCHG_SET(dst, src) \
64 (((dst) & ~0xfff00000) | (((u32)(src) << 0x14) & 0xfff00000))
65#define PORTAXICFG_EN_CONTEXT_SET(dst, src) \
66 (((dst) & ~0x01000000) | (((u32)(src) << 0x18) & 0x01000000))
67#define PORTAXICFG 0x000000bc
68#define PORTAXICFG_OUTTRANS_SET(dst, src) \
69 (((dst) & ~0x00f00000) | (((u32)(src) << 0x14) & 0x00f00000))
70
71/* SATA host controller AXI CSR */
72#define INT_SLV_TMOMASK 0x00000010
73
74/* SATA diagnostic CSR */
75#define CFG_MEM_RAM_SHUTDOWN 0x00000070
76#define BLOCK_MEM_RDY 0x00000074
77
78struct xgene_ahci_context {
79 struct ahci_host_priv *hpriv;
80 struct device *dev;
81 void __iomem *csr_core; /* Core CSR address of IP */
82 void __iomem *csr_diag; /* Diag CSR address of IP */
83 void __iomem *csr_axi; /* AXI CSR address of IP */
84 void __iomem *csr_mux; /* MUX CSR address of IP */
85};
86
87static int xgene_ahci_init_memram(struct xgene_ahci_context *ctx)
88{
89 dev_dbg(ctx->dev, "Release memory from shutdown\n");
90 writel(0x0, ctx->csr_diag + CFG_MEM_RAM_SHUTDOWN);
91 readl(ctx->csr_diag + CFG_MEM_RAM_SHUTDOWN); /* Force a barrier */
92 msleep(1); /* reset may take up to 1ms */
93 if (readl(ctx->csr_diag + BLOCK_MEM_RDY) != 0xFFFFFFFF) {
94 dev_err(ctx->dev, "failed to release memory from shutdown\n");
95 return -ENODEV;
96 }
97 return 0;
98}
99
100/**
101 * xgene_ahci_read_id - Read ID data from the specified device
102 * @dev: device
103 * @tf: proposed taskfile
104 * @id: data buffer
105 *
106 * This custom read ID function is required due to the fact that the HW
107 * does not support DEVSLP and the controller state machine may get stuck
108 * after processing the ID query command.
109 */
110static unsigned int xgene_ahci_read_id(struct ata_device *dev,
111 struct ata_taskfile *tf, u16 *id)
112{
113 u32 err_mask;
114 void __iomem *port_mmio = ahci_port_base(dev->link->ap);
115
116 err_mask = ata_do_dev_read_id(dev, tf, id);
117 if (err_mask)
118 return err_mask;
119
120 /*
121 * Mask reserved area. Word78 spec of Link Power Management
122 * bit15-8: reserved
123 * bit7: NCQ autosence
124 * bit6: Software settings preservation supported
125 * bit5: reserved
126 * bit4: In-order sata delivery supported
127 * bit3: DIPM requests supported
128 * bit2: DMA Setup FIS Auto-Activate optimization supported
129 * bit1: DMA Setup FIX non-Zero buffer offsets supported
130 * bit0: Reserved
131 *
132 * Clear reserved bit 8 (DEVSLP bit) as we don't support DEVSLP
133 */
134 id[ATA_ID_FEATURE_SUPP] &= ~(1 << 8);
135
136 /*
137 * Due to HW errata, restart the port if no other command active.
138 * Otherwise the controller may get stuck.
139 */
140 if (!readl(port_mmio + PORT_CMD_ISSUE)) {
141 writel(PORT_CMD_FIS_RX, port_mmio + PORT_CMD);
142 readl(port_mmio + PORT_CMD); /* Force a barrier */
143 writel(PORT_CMD_FIS_RX | PORT_CMD_START, port_mmio + PORT_CMD);
144 readl(port_mmio + PORT_CMD); /* Force a barrier */
145 }
146 return 0;
147}
148
149static void xgene_ahci_set_phy_cfg(struct xgene_ahci_context *ctx, int channel)
150{
151 void __iomem *mmio = ctx->hpriv->mmio;
152 u32 val;
153
154 dev_dbg(ctx->dev, "port configure mmio 0x%p channel %d\n",
155 mmio, channel);
156 val = readl(mmio + PORTCFG);
157 val = PORTADDR_SET(val, channel == 0 ? 2 : 3);
158 writel(val, mmio + PORTCFG);
159 readl(mmio + PORTCFG); /* Force a barrier */
160 /* Disable fix rate */
161 writel(0x0001fffe, mmio + PORTPHY1CFG);
162 readl(mmio + PORTPHY1CFG); /* Force a barrier */
163 writel(0x5018461c, mmio + PORTPHY2CFG);
164 readl(mmio + PORTPHY2CFG); /* Force a barrier */
165 writel(0x1c081907, mmio + PORTPHY3CFG);
166 readl(mmio + PORTPHY3CFG); /* Force a barrier */
167 writel(0x1c080815, mmio + PORTPHY4CFG);
168 readl(mmio + PORTPHY4CFG); /* Force a barrier */
169 /* Set window negotiation */
170 val = readl(mmio + PORTPHY5CFG);
171 val = PORTPHY5CFG_RTCHG_SET(val, 0x300);
172 writel(val, mmio + PORTPHY5CFG);
173 readl(mmio + PORTPHY5CFG); /* Force a barrier */
174 val = readl(mmio + PORTAXICFG);
175 val = PORTAXICFG_EN_CONTEXT_SET(val, 0x1); /* Enable context mgmt */
176 val = PORTAXICFG_OUTTRANS_SET(val, 0xe); /* Set outstanding */
177 writel(val, mmio + PORTAXICFG);
178 readl(mmio + PORTAXICFG); /* Force a barrier */
179}
180
181/**
182 * xgene_ahci_do_hardreset - Issue the actual COMRESET
183 * @link: link to reset
184 * @deadline: deadline jiffies for the operation
185 * @online: Return value to indicate if device online
186 *
187 * Due to the limitation of the hardware PHY, a difference set of setting is
188 * required for each supported disk speed - Gen3 (6.0Gbps), Gen2 (3.0Gbps),
189 * and Gen1 (1.5Gbps). Otherwise during long IO stress test, the PHY will
190 * report disparity error and etc. In addition, during COMRESET, there can
191 * be error reported in the register PORT_SCR_ERR. For SERR_DISPARITY and
192 * SERR_10B_8B_ERR, the PHY receiver line must be reseted. The following
193 * algorithm is followed to proper configure the hardware PHY during COMRESET:
194 *
195 * Alg Part 1:
196 * 1. Start the PHY at Gen3 speed (default setting)
197 * 2. Issue the COMRESET
198 * 3. If no link, go to Alg Part 3
199 * 4. If link up, determine if the negotiated speed matches the PHY
200 * configured speed
201 * 5. If they matched, go to Alg Part 2
202 * 6. If they do not matched and first time, configure the PHY for the linked
203 * up disk speed and repeat step 2
204 * 7. Go to Alg Part 2
205 *
206 * Alg Part 2:
207 * 1. On link up, if there are any SERR_DISPARITY and SERR_10B_8B_ERR error
208 * reported in the register PORT_SCR_ERR, then reset the PHY receiver line
209 * 2. Go to Alg Part 3
210 *
211 * Alg Part 3:
212 * 1. Clear any pending from register PORT_SCR_ERR.
213 *
214 * NOTE: For the initial version, we will NOT support Gen1/Gen2. In addition
215 * and until the underlying PHY supports an method to reset the receiver
216 * line, on detection of SERR_DISPARITY or SERR_10B_8B_ERR errors,
217 * an warning message will be printed.
218 */
219static int xgene_ahci_do_hardreset(struct ata_link *link,
220 unsigned long deadline, bool *online)
221{
222 const unsigned long *timing = sata_ehc_deb_timing(&link->eh_context);
223 struct ata_port *ap = link->ap;
224 struct ahci_host_priv *hpriv = ap->host->private_data;
225 struct xgene_ahci_context *ctx = hpriv->plat_data;
226 struct ahci_port_priv *pp = ap->private_data;
227 u8 *d2h_fis = pp->rx_fis + RX_FIS_D2H_REG;
228 void __iomem *port_mmio = ahci_port_base(ap);
229 struct ata_taskfile tf;
230 int rc;
231 u32 val;
232
233 /* clear D2H reception area to properly wait for D2H FIS */
234 ata_tf_init(link->device, &tf);
235 tf.command = ATA_BUSY;
236 ata_tf_to_fis(&tf, 0, 0, d2h_fis);
237 rc = sata_link_hardreset(link, timing, deadline, online,
238 ahci_check_ready);
239
240 val = readl(port_mmio + PORT_SCR_ERR);
241 if (val & (SERR_DISPARITY | SERR_10B_8B_ERR))
242 dev_warn(ctx->dev, "link has error\n");
243
244 /* clear all errors if any pending */
245 val = readl(port_mmio + PORT_SCR_ERR);
246 writel(val, port_mmio + PORT_SCR_ERR);
247
248 return rc;
249}
250
251static int xgene_ahci_hardreset(struct ata_link *link, unsigned int *class,
252 unsigned long deadline)
253{
254 struct ata_port *ap = link->ap;
255 struct ahci_host_priv *hpriv = ap->host->private_data;
256 void __iomem *port_mmio = ahci_port_base(ap);
257 bool online;
258 int rc;
259 u32 portcmd_saved;
260 u32 portclb_saved;
261 u32 portclbhi_saved;
262 u32 portrxfis_saved;
263 u32 portrxfishi_saved;
264
265 /* As hardreset resets these CSR, save it to restore later */
266 portcmd_saved = readl(port_mmio + PORT_CMD);
267 portclb_saved = readl(port_mmio + PORT_LST_ADDR);
268 portclbhi_saved = readl(port_mmio + PORT_LST_ADDR_HI);
269 portrxfis_saved = readl(port_mmio + PORT_FIS_ADDR);
270 portrxfishi_saved = readl(port_mmio + PORT_FIS_ADDR_HI);
271
272 ahci_stop_engine(ap);
273
274 rc = xgene_ahci_do_hardreset(link, deadline, &online);
275
276 /* As controller hardreset clears them, restore them */
277 writel(portcmd_saved, port_mmio + PORT_CMD);
278 writel(portclb_saved, port_mmio + PORT_LST_ADDR);
279 writel(portclbhi_saved, port_mmio + PORT_LST_ADDR_HI);
280 writel(portrxfis_saved, port_mmio + PORT_FIS_ADDR);
281 writel(portrxfishi_saved, port_mmio + PORT_FIS_ADDR_HI);
282
283 hpriv->start_engine(ap);
284
285 if (online)
286 *class = ahci_dev_classify(ap);
287
288 return rc;
289}
290
291static void xgene_ahci_host_stop(struct ata_host *host)
292{
293 struct ahci_host_priv *hpriv = host->private_data;
294
295 ahci_platform_disable_resources(hpriv);
296}
297
298static struct ata_port_operations xgene_ahci_ops = {
299 .inherits = &ahci_ops,
300 .host_stop = xgene_ahci_host_stop,
301 .hardreset = xgene_ahci_hardreset,
302 .read_id = xgene_ahci_read_id,
303};
304
305static const struct ata_port_info xgene_ahci_port_info = {
306 AHCI_HFLAGS(AHCI_HFLAG_NO_PMP | AHCI_HFLAG_YES_NCQ),
307 .flags = AHCI_FLAG_COMMON | ATA_FLAG_NCQ,
308 .pio_mask = ATA_PIO4,
309 .udma_mask = ATA_UDMA6,
310 .port_ops = &xgene_ahci_ops,
311};
312
313static int xgene_ahci_hw_init(struct ahci_host_priv *hpriv)
314{
315 struct xgene_ahci_context *ctx = hpriv->plat_data;
316 int i;
317 int rc;
318 u32 val;
319
320 /* Remove IP RAM out of shutdown */
321 rc = xgene_ahci_init_memram(ctx);
322 if (rc)
323 return rc;
324
325 for (i = 0; i < MAX_AHCI_CHN_PERCTR; i++)
326 xgene_ahci_set_phy_cfg(ctx, i);
327
328 /* AXI disable Mask */
329 writel(0xffffffff, hpriv->mmio + HOST_IRQ_STAT);
330 readl(hpriv->mmio + HOST_IRQ_STAT); /* Force a barrier */
331 writel(0, ctx->csr_core + INTSTATUSMASK);
332 val = readl(ctx->csr_core + INTSTATUSMASK); /* Force a barrier */
333 dev_dbg(ctx->dev, "top level interrupt mask 0x%X value 0x%08X\n",
334 INTSTATUSMASK, val);
335
336 writel(0x0, ctx->csr_core + ERRINTSTATUSMASK);
337 readl(ctx->csr_core + ERRINTSTATUSMASK); /* Force a barrier */
338 writel(0x0, ctx->csr_axi + INT_SLV_TMOMASK);
339 readl(ctx->csr_axi + INT_SLV_TMOMASK);
340
341 /* Enable AXI Interrupt */
342 writel(0xffffffff, ctx->csr_core + SLVRDERRATTRIBUTES);
343 writel(0xffffffff, ctx->csr_core + SLVWRERRATTRIBUTES);
344 writel(0xffffffff, ctx->csr_core + MSTRDERRATTRIBUTES);
345 writel(0xffffffff, ctx->csr_core + MSTWRERRATTRIBUTES);
346
347 /* Enable coherency */
348 val = readl(ctx->csr_core + BUSCTLREG);
349 val &= ~0x00000002; /* Enable write coherency */
350 val &= ~0x00000001; /* Enable read coherency */
351 writel(val, ctx->csr_core + BUSCTLREG);
352
353 val = readl(ctx->csr_core + IOFMSTRWAUX);
354 val |= (1 << 3); /* Enable read coherency */
355 val |= (1 << 9); /* Enable write coherency */
356 writel(val, ctx->csr_core + IOFMSTRWAUX);
357 val = readl(ctx->csr_core + IOFMSTRWAUX);
358 dev_dbg(ctx->dev, "coherency 0x%X value 0x%08X\n",
359 IOFMSTRWAUX, val);
360
361 return rc;
362}
363
364static int xgene_ahci_mux_select(struct xgene_ahci_context *ctx)
365{
366 u32 val;
367
368 /* Check for optional MUX resource */
369 if (IS_ERR(ctx->csr_mux))
370 return 0;
371
372 val = readl(ctx->csr_mux + SATA_ENET_CONFIG_REG);
373 val &= ~CFG_SATA_ENET_SELECT_MASK;
374 writel(val, ctx->csr_mux + SATA_ENET_CONFIG_REG);
375 val = readl(ctx->csr_mux + SATA_ENET_CONFIG_REG);
376 return val & CFG_SATA_ENET_SELECT_MASK ? -1 : 0;
377}
378
379static int xgene_ahci_probe(struct platform_device *pdev)
380{
381 struct device *dev = &pdev->dev;
382 struct ahci_host_priv *hpriv;
383 struct xgene_ahci_context *ctx;
384 struct resource *res;
385 int rc;
386
387 hpriv = ahci_platform_get_resources(pdev);
388 if (IS_ERR(hpriv))
389 return PTR_ERR(hpriv);
390
391 ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
392 if (!ctx)
393 return -ENOMEM;
394
395 hpriv->plat_data = ctx;
396 ctx->hpriv = hpriv;
397 ctx->dev = dev;
398
399 /* Retrieve the IP core resource */
400 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
401 ctx->csr_core = devm_ioremap_resource(dev, res);
402 if (IS_ERR(ctx->csr_core))
403 return PTR_ERR(ctx->csr_core);
404
405 /* Retrieve the IP diagnostic resource */
406 res = platform_get_resource(pdev, IORESOURCE_MEM, 2);
407 ctx->csr_diag = devm_ioremap_resource(dev, res);
408 if (IS_ERR(ctx->csr_diag))
409 return PTR_ERR(ctx->csr_diag);
410
411 /* Retrieve the IP AXI resource */
412 res = platform_get_resource(pdev, IORESOURCE_MEM, 3);
413 ctx->csr_axi = devm_ioremap_resource(dev, res);
414 if (IS_ERR(ctx->csr_axi))
415 return PTR_ERR(ctx->csr_axi);
416
417 /* Retrieve the optional IP mux resource */
418 res = platform_get_resource(pdev, IORESOURCE_MEM, 4);
419 ctx->csr_mux = devm_ioremap_resource(dev, res);
420
421 dev_dbg(dev, "VAddr 0x%p Mmio VAddr 0x%p\n", ctx->csr_core,
422 hpriv->mmio);
423
424 /* Select ATA */
425 if ((rc = xgene_ahci_mux_select(ctx))) {
426 dev_err(dev, "SATA mux selection failed error %d\n", rc);
427 return -ENODEV;
428 }
429
430 /* Due to errata, HW requires full toggle transition */
431 rc = ahci_platform_enable_clks(hpriv);
432 if (rc)
433 goto disable_resources;
434 ahci_platform_disable_clks(hpriv);
435
436 rc = ahci_platform_enable_resources(hpriv);
437 if (rc)
438 goto disable_resources;
439
440 /* Configure the host controller */
441 xgene_ahci_hw_init(hpriv);
442
443 /*
444 * Setup DMA mask. This is preliminary until the DMA range is sorted
445 * out.
446 */
447 rc = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64));
448 if (rc) {
449 dev_err(dev, "Unable to set dma mask\n");
450 goto disable_resources;
451 }
452
453 rc = ahci_platform_init_host(pdev, hpriv, &xgene_ahci_port_info, 0, 0);
454 if (rc)
455 goto disable_resources;
456
457 dev_dbg(dev, "X-Gene SATA host controller initialized\n");
458 return 0;
459
460disable_resources:
461 ahci_platform_disable_resources(hpriv);
462 return rc;
463}
464
465static const struct of_device_id xgene_ahci_of_match[] = {
466 {.compatible = "apm,xgene-ahci"},
467 {},
468};
469MODULE_DEVICE_TABLE(of, xgene_ahci_of_match);
470
471static struct platform_driver xgene_ahci_driver = {
472 .probe = xgene_ahci_probe,
473 .remove = ata_platform_remove_one,
474 .driver = {
475 .name = "xgene-ahci",
476 .owner = THIS_MODULE,
477 .of_match_table = xgene_ahci_of_match,
478 },
479};
480
481module_platform_driver(xgene_ahci_driver);
482
483MODULE_DESCRIPTION("APM X-Gene AHCI SATA driver");
484MODULE_AUTHOR("Loc Ho <lho@apm.com>");
485MODULE_LICENSE("GPL");
486MODULE_VERSION("0.4");
diff --git a/drivers/ata/ata_generic.c b/drivers/ata/ata_generic.c
index 7d196656adb5..9498a7d3846f 100644
--- a/drivers/ata/ata_generic.c
+++ b/drivers/ata/ata_generic.c
@@ -19,7 +19,6 @@
19#include <linux/kernel.h> 19#include <linux/kernel.h>
20#include <linux/module.h> 20#include <linux/module.h>
21#include <linux/pci.h> 21#include <linux/pci.h>
22#include <linux/init.h>
23#include <linux/blkdev.h> 22#include <linux/blkdev.h>
24#include <linux/delay.h> 23#include <linux/delay.h>
25#include <scsi/scsi_host.h> 24#include <scsi/scsi_host.h>
diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
index 36605abe5a67..6bd4f660b4e1 100644
--- a/drivers/ata/libahci.c
+++ b/drivers/ata/libahci.c
@@ -35,7 +35,6 @@
35#include <linux/kernel.h> 35#include <linux/kernel.h>
36#include <linux/gfp.h> 36#include <linux/gfp.h>
37#include <linux/module.h> 37#include <linux/module.h>
38#include <linux/init.h>
39#include <linux/blkdev.h> 38#include <linux/blkdev.h>
40#include <linux/delay.h> 39#include <linux/delay.h>
41#include <linux/interrupt.h> 40#include <linux/interrupt.h>
@@ -394,6 +393,9 @@ static ssize_t ahci_show_em_supported(struct device *dev,
394 * 393 *
395 * If inconsistent, config values are fixed up by this function. 394 * If inconsistent, config values are fixed up by this function.
396 * 395 *
396 * If it is not set already this function sets hpriv->start_engine to
397 * ahci_start_engine.
398 *
397 * LOCKING: 399 * LOCKING:
398 * None. 400 * None.
399 */ 401 */
@@ -500,6 +502,9 @@ void ahci_save_initial_config(struct device *dev,
500 hpriv->cap = cap; 502 hpriv->cap = cap;
501 hpriv->cap2 = cap2; 503 hpriv->cap2 = cap2;
502 hpriv->port_map = port_map; 504 hpriv->port_map = port_map;
505
506 if (!hpriv->start_engine)
507 hpriv->start_engine = ahci_start_engine;
503} 508}
504EXPORT_SYMBOL_GPL(ahci_save_initial_config); 509EXPORT_SYMBOL_GPL(ahci_save_initial_config);
505 510
@@ -766,7 +771,7 @@ static void ahci_start_port(struct ata_port *ap)
766 771
767 /* enable DMA */ 772 /* enable DMA */
768 if (!(hpriv->flags & AHCI_HFLAG_DELAY_ENGINE)) 773 if (!(hpriv->flags & AHCI_HFLAG_DELAY_ENGINE))
769 ahci_start_engine(ap); 774 hpriv->start_engine(ap);
770 775
771 /* turn on LEDs */ 776 /* turn on LEDs */
772 if (ap->flags & ATA_FLAG_EM) { 777 if (ap->flags & ATA_FLAG_EM) {
@@ -1032,12 +1037,13 @@ static ssize_t ahci_led_show(struct ata_port *ap, char *buf)
1032static ssize_t ahci_led_store(struct ata_port *ap, const char *buf, 1037static ssize_t ahci_led_store(struct ata_port *ap, const char *buf,
1033 size_t size) 1038 size_t size)
1034{ 1039{
1035 int state; 1040 unsigned int state;
1036 int pmp; 1041 int pmp;
1037 struct ahci_port_priv *pp = ap->private_data; 1042 struct ahci_port_priv *pp = ap->private_data;
1038 struct ahci_em_priv *emp; 1043 struct ahci_em_priv *emp;
1039 1044
1040 state = simple_strtoul(buf, NULL, 0); 1045 if (kstrtouint(buf, 0, &state) < 0)
1046 return -EINVAL;
1041 1047
1042 /* get the slot number from the message */ 1048 /* get the slot number from the message */
1043 pmp = (state & EM_MSG_LED_PMP_SLOT) >> 8; 1049 pmp = (state & EM_MSG_LED_PMP_SLOT) >> 8;
@@ -1234,7 +1240,7 @@ int ahci_kick_engine(struct ata_port *ap)
1234 1240
1235 /* restart engine */ 1241 /* restart engine */
1236 out_restart: 1242 out_restart:
1237 ahci_start_engine(ap); 1243 hpriv->start_engine(ap);
1238 return rc; 1244 return rc;
1239} 1245}
1240EXPORT_SYMBOL_GPL(ahci_kick_engine); 1246EXPORT_SYMBOL_GPL(ahci_kick_engine);
@@ -1387,8 +1393,8 @@ static int ahci_bad_pmp_check_ready(struct ata_link *link)
1387 return ata_check_ready(status); 1393 return ata_check_ready(status);
1388} 1394}
1389 1395
1390int ahci_pmp_retry_softreset(struct ata_link *link, unsigned int *class, 1396static int ahci_pmp_retry_softreset(struct ata_link *link, unsigned int *class,
1391 unsigned long deadline) 1397 unsigned long deadline)
1392{ 1398{
1393 struct ata_port *ap = link->ap; 1399 struct ata_port *ap = link->ap;
1394 void __iomem *port_mmio = ahci_port_base(ap); 1400 void __iomem *port_mmio = ahci_port_base(ap);
@@ -1426,6 +1432,7 @@ static int ahci_hardreset(struct ata_link *link, unsigned int *class,
1426 const unsigned long *timing = sata_ehc_deb_timing(&link->eh_context); 1432 const unsigned long *timing = sata_ehc_deb_timing(&link->eh_context);
1427 struct ata_port *ap = link->ap; 1433 struct ata_port *ap = link->ap;
1428 struct ahci_port_priv *pp = ap->private_data; 1434 struct ahci_port_priv *pp = ap->private_data;
1435 struct ahci_host_priv *hpriv = ap->host->private_data;
1429 u8 *d2h_fis = pp->rx_fis + RX_FIS_D2H_REG; 1436 u8 *d2h_fis = pp->rx_fis + RX_FIS_D2H_REG;
1430 struct ata_taskfile tf; 1437 struct ata_taskfile tf;
1431 bool online; 1438 bool online;
@@ -1443,7 +1450,7 @@ static int ahci_hardreset(struct ata_link *link, unsigned int *class,
1443 rc = sata_link_hardreset(link, timing, deadline, &online, 1450 rc = sata_link_hardreset(link, timing, deadline, &online,
1444 ahci_check_ready); 1451 ahci_check_ready);
1445 1452
1446 ahci_start_engine(ap); 1453 hpriv->start_engine(ap);
1447 1454
1448 if (online) 1455 if (online)
1449 *class = ahci_dev_classify(ap); 1456 *class = ahci_dev_classify(ap);
@@ -1629,7 +1636,7 @@ static void ahci_error_intr(struct ata_port *ap, u32 irq_stat)
1629 } 1636 }
1630 1637
1631 if (irq_stat & PORT_IRQ_UNK_FIS) { 1638 if (irq_stat & PORT_IRQ_UNK_FIS) {
1632 u32 *unk = (u32 *)(pp->rx_fis + RX_FIS_UNK); 1639 u32 *unk = pp->rx_fis + RX_FIS_UNK;
1633 1640
1634 active_ehi->err_mask |= AC_ERR_HSM; 1641 active_ehi->err_mask |= AC_ERR_HSM;
1635 active_ehi->action |= ATA_EH_RESET; 1642 active_ehi->action |= ATA_EH_RESET;
@@ -2007,10 +2014,12 @@ static void ahci_thaw(struct ata_port *ap)
2007 2014
2008void ahci_error_handler(struct ata_port *ap) 2015void ahci_error_handler(struct ata_port *ap)
2009{ 2016{
2017 struct ahci_host_priv *hpriv = ap->host->private_data;
2018
2010 if (!(ap->pflags & ATA_PFLAG_FROZEN)) { 2019 if (!(ap->pflags & ATA_PFLAG_FROZEN)) {
2011 /* restart engine */ 2020 /* restart engine */
2012 ahci_stop_engine(ap); 2021 ahci_stop_engine(ap);
2013 ahci_start_engine(ap); 2022 hpriv->start_engine(ap);
2014 } 2023 }
2015 2024
2016 sata_pmp_error_handler(ap); 2025 sata_pmp_error_handler(ap);
@@ -2031,6 +2040,7 @@ static void ahci_post_internal_cmd(struct ata_queued_cmd *qc)
2031 2040
2032static void ahci_set_aggressive_devslp(struct ata_port *ap, bool sleep) 2041static void ahci_set_aggressive_devslp(struct ata_port *ap, bool sleep)
2033{ 2042{
2043 struct ahci_host_priv *hpriv = ap->host->private_data;
2034 void __iomem *port_mmio = ahci_port_base(ap); 2044 void __iomem *port_mmio = ahci_port_base(ap);
2035 struct ata_device *dev = ap->link.device; 2045 struct ata_device *dev = ap->link.device;
2036 u32 devslp, dm, dito, mdat, deto; 2046 u32 devslp, dm, dito, mdat, deto;
@@ -2094,7 +2104,7 @@ static void ahci_set_aggressive_devslp(struct ata_port *ap, bool sleep)
2094 PORT_DEVSLP_ADSE); 2104 PORT_DEVSLP_ADSE);
2095 writel(devslp, port_mmio + PORT_DEVSLP); 2105 writel(devslp, port_mmio + PORT_DEVSLP);
2096 2106
2097 ahci_start_engine(ap); 2107 hpriv->start_engine(ap);
2098 2108
2099 /* enable device sleep feature for the drive */ 2109 /* enable device sleep feature for the drive */
2100 err_mask = ata_dev_set_feature(dev, 2110 err_mask = ata_dev_set_feature(dev,
@@ -2106,6 +2116,7 @@ static void ahci_set_aggressive_devslp(struct ata_port *ap, bool sleep)
2106 2116
2107static void ahci_enable_fbs(struct ata_port *ap) 2117static void ahci_enable_fbs(struct ata_port *ap)
2108{ 2118{
2119 struct ahci_host_priv *hpriv = ap->host->private_data;
2109 struct ahci_port_priv *pp = ap->private_data; 2120 struct ahci_port_priv *pp = ap->private_data;
2110 void __iomem *port_mmio = ahci_port_base(ap); 2121 void __iomem *port_mmio = ahci_port_base(ap);
2111 u32 fbs; 2122 u32 fbs;
@@ -2134,11 +2145,12 @@ static void ahci_enable_fbs(struct ata_port *ap)
2134 } else 2145 } else
2135 dev_err(ap->host->dev, "Failed to enable FBS\n"); 2146 dev_err(ap->host->dev, "Failed to enable FBS\n");
2136 2147
2137 ahci_start_engine(ap); 2148 hpriv->start_engine(ap);
2138} 2149}
2139 2150
2140static void ahci_disable_fbs(struct ata_port *ap) 2151static void ahci_disable_fbs(struct ata_port *ap)
2141{ 2152{
2153 struct ahci_host_priv *hpriv = ap->host->private_data;
2142 struct ahci_port_priv *pp = ap->private_data; 2154 struct ahci_port_priv *pp = ap->private_data;
2143 void __iomem *port_mmio = ahci_port_base(ap); 2155 void __iomem *port_mmio = ahci_port_base(ap);
2144 u32 fbs; 2156 u32 fbs;
@@ -2166,7 +2178,7 @@ static void ahci_disable_fbs(struct ata_port *ap)
2166 pp->fbs_enabled = false; 2178 pp->fbs_enabled = false;
2167 } 2179 }
2168 2180
2169 ahci_start_engine(ap); 2181 hpriv->start_engine(ap);
2170} 2182}
2171 2183
2172static void ahci_pmp_attach(struct ata_port *ap) 2184static void ahci_pmp_attach(struct ata_port *ap)
diff --git a/drivers/ata/libahci_platform.c b/drivers/ata/libahci_platform.c
new file mode 100644
index 000000000000..7cb3a85719c0
--- /dev/null
+++ b/drivers/ata/libahci_platform.c
@@ -0,0 +1,541 @@
1/*
2 * AHCI SATA platform library
3 *
4 * Copyright 2004-2005 Red Hat, Inc.
5 * Jeff Garzik <jgarzik@pobox.com>
6 * Copyright 2010 MontaVista Software, LLC.
7 * Anton Vorontsov <avorontsov@ru.mvista.com>
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, or (at your option)
12 * any later version.
13 */
14
15#include <linux/clk.h>
16#include <linux/kernel.h>
17#include <linux/gfp.h>
18#include <linux/module.h>
19#include <linux/pm.h>
20#include <linux/interrupt.h>
21#include <linux/device.h>
22#include <linux/platform_device.h>
23#include <linux/libata.h>
24#include <linux/ahci_platform.h>
25#include <linux/phy/phy.h>
26#include <linux/pm_runtime.h>
27#include "ahci.h"
28
29static void ahci_host_stop(struct ata_host *host);
30
31struct ata_port_operations ahci_platform_ops = {
32 .inherits = &ahci_ops,
33 .host_stop = ahci_host_stop,
34};
35EXPORT_SYMBOL_GPL(ahci_platform_ops);
36
37static struct scsi_host_template ahci_platform_sht = {
38 AHCI_SHT("ahci_platform"),
39};
40
41/**
42 * ahci_platform_enable_clks - Enable platform clocks
43 * @hpriv: host private area to store config values
44 *
45 * This function enables all the clks found in hpriv->clks, starting at
46 * index 0. If any clk fails to enable it disables all the clks already
47 * enabled in reverse order, and then returns an error.
48 *
49 * RETURNS:
50 * 0 on success otherwise a negative error code
51 */
52int ahci_platform_enable_clks(struct ahci_host_priv *hpriv)
53{
54 int c, rc;
55
56 for (c = 0; c < AHCI_MAX_CLKS && hpriv->clks[c]; c++) {
57 rc = clk_prepare_enable(hpriv->clks[c]);
58 if (rc)
59 goto disable_unprepare_clk;
60 }
61 return 0;
62
63disable_unprepare_clk:
64 while (--c >= 0)
65 clk_disable_unprepare(hpriv->clks[c]);
66 return rc;
67}
68EXPORT_SYMBOL_GPL(ahci_platform_enable_clks);
69
70/**
71 * ahci_platform_disable_clks - Disable platform clocks
72 * @hpriv: host private area to store config values
73 *
74 * This function disables all the clks found in hpriv->clks, in reverse
75 * order of ahci_platform_enable_clks (starting at the end of the array).
76 */
77void ahci_platform_disable_clks(struct ahci_host_priv *hpriv)
78{
79 int c;
80
81 for (c = AHCI_MAX_CLKS - 1; c >= 0; c--)
82 if (hpriv->clks[c])
83 clk_disable_unprepare(hpriv->clks[c]);
84}
85EXPORT_SYMBOL_GPL(ahci_platform_disable_clks);
86
87/**
88 * ahci_platform_enable_resources - Enable platform resources
89 * @hpriv: host private area to store config values
90 *
91 * This function enables all ahci_platform managed resources in the
92 * following order:
93 * 1) Regulator
94 * 2) Clocks (through ahci_platform_enable_clks)
95 * 3) Phy
96 *
97 * If resource enabling fails at any point the previous enabled resources
98 * are disabled in reverse order.
99 *
100 * RETURNS:
101 * 0 on success otherwise a negative error code
102 */
103int ahci_platform_enable_resources(struct ahci_host_priv *hpriv)
104{
105 int rc;
106
107 if (hpriv->target_pwr) {
108 rc = regulator_enable(hpriv->target_pwr);
109 if (rc)
110 return rc;
111 }
112
113 rc = ahci_platform_enable_clks(hpriv);
114 if (rc)
115 goto disable_regulator;
116
117 if (hpriv->phy) {
118 rc = phy_init(hpriv->phy);
119 if (rc)
120 goto disable_clks;
121
122 rc = phy_power_on(hpriv->phy);
123 if (rc) {
124 phy_exit(hpriv->phy);
125 goto disable_clks;
126 }
127 }
128
129 return 0;
130
131disable_clks:
132 ahci_platform_disable_clks(hpriv);
133
134disable_regulator:
135 if (hpriv->target_pwr)
136 regulator_disable(hpriv->target_pwr);
137 return rc;
138}
139EXPORT_SYMBOL_GPL(ahci_platform_enable_resources);
140
141/**
142 * ahci_platform_disable_resources - Disable platform resources
143 * @hpriv: host private area to store config values
144 *
145 * This function disables all ahci_platform managed resources in the
146 * following order:
147 * 1) Phy
148 * 2) Clocks (through ahci_platform_disable_clks)
149 * 3) Regulator
150 */
151void ahci_platform_disable_resources(struct ahci_host_priv *hpriv)
152{
153 if (hpriv->phy) {
154 phy_power_off(hpriv->phy);
155 phy_exit(hpriv->phy);
156 }
157
158 ahci_platform_disable_clks(hpriv);
159
160 if (hpriv->target_pwr)
161 regulator_disable(hpriv->target_pwr);
162}
163EXPORT_SYMBOL_GPL(ahci_platform_disable_resources);
164
165static void ahci_platform_put_resources(struct device *dev, void *res)
166{
167 struct ahci_host_priv *hpriv = res;
168 int c;
169
170 if (hpriv->got_runtime_pm) {
171 pm_runtime_put_sync(dev);
172 pm_runtime_disable(dev);
173 }
174
175 for (c = 0; c < AHCI_MAX_CLKS && hpriv->clks[c]; c++)
176 clk_put(hpriv->clks[c]);
177}
178
179/**
180 * ahci_platform_get_resources - Get platform resources
181 * @pdev: platform device to get resources for
182 *
183 * This function allocates an ahci_host_priv struct, and gets the following
184 * resources, storing a reference to them inside the returned struct:
185 *
186 * 1) mmio registers (IORESOURCE_MEM 0, mandatory)
187 * 2) regulator for controlling the targets power (optional)
188 * 3) 0 - AHCI_MAX_CLKS clocks, as specified in the devs devicetree node,
189 * or for non devicetree enabled platforms a single clock
190 * 4) phy (optional)
191 *
192 * RETURNS:
193 * The allocated ahci_host_priv on success, otherwise an ERR_PTR value
194 */
195struct ahci_host_priv *ahci_platform_get_resources(struct platform_device *pdev)
196{
197 struct device *dev = &pdev->dev;
198 struct ahci_host_priv *hpriv;
199 struct clk *clk;
200 int i, rc = -ENOMEM;
201
202 if (!devres_open_group(dev, NULL, GFP_KERNEL))
203 return ERR_PTR(-ENOMEM);
204
205 hpriv = devres_alloc(ahci_platform_put_resources, sizeof(*hpriv),
206 GFP_KERNEL);
207 if (!hpriv)
208 goto err_out;
209
210 devres_add(dev, hpriv);
211
212 hpriv->mmio = devm_ioremap_resource(dev,
213 platform_get_resource(pdev, IORESOURCE_MEM, 0));
214 if (IS_ERR(hpriv->mmio)) {
215 dev_err(dev, "no mmio space\n");
216 rc = PTR_ERR(hpriv->mmio);
217 goto err_out;
218 }
219
220 hpriv->target_pwr = devm_regulator_get_optional(dev, "target");
221 if (IS_ERR(hpriv->target_pwr)) {
222 rc = PTR_ERR(hpriv->target_pwr);
223 if (rc == -EPROBE_DEFER)
224 goto err_out;
225 hpriv->target_pwr = NULL;
226 }
227
228 for (i = 0; i < AHCI_MAX_CLKS; i++) {
229 /*
230 * For now we must use clk_get(dev, NULL) for the first clock,
231 * because some platforms (da850, spear13xx) are not yet
232 * converted to use devicetree for clocks. For new platforms
233 * this is equivalent to of_clk_get(dev->of_node, 0).
234 */
235 if (i == 0)
236 clk = clk_get(dev, NULL);
237 else
238 clk = of_clk_get(dev->of_node, i);
239
240 if (IS_ERR(clk)) {
241 rc = PTR_ERR(clk);
242 if (rc == -EPROBE_DEFER)
243 goto err_out;
244 break;
245 }
246 hpriv->clks[i] = clk;
247 }
248
249 hpriv->phy = devm_phy_get(dev, "sata-phy");
250 if (IS_ERR(hpriv->phy)) {
251 rc = PTR_ERR(hpriv->phy);
252 switch (rc) {
253 case -ENODEV:
254 case -ENOSYS:
255 /* continue normally */
256 hpriv->phy = NULL;
257 break;
258
259 case -EPROBE_DEFER:
260 goto err_out;
261
262 default:
263 dev_err(dev, "couldn't get sata-phy\n");
264 goto err_out;
265 }
266 }
267
268 pm_runtime_enable(dev);
269 pm_runtime_get_sync(dev);
270 hpriv->got_runtime_pm = true;
271
272 devres_remove_group(dev, NULL);
273 return hpriv;
274
275err_out:
276 devres_release_group(dev, NULL);
277 return ERR_PTR(rc);
278}
279EXPORT_SYMBOL_GPL(ahci_platform_get_resources);
280
281/**
282 * ahci_platform_init_host - Bring up an ahci-platform host
283 * @pdev: platform device pointer for the host
284 * @hpriv: ahci-host private data for the host
285 * @pi_template: template for the ata_port_info to use
286 * @force_port_map: param passed to ahci_save_initial_config
287 * @mask_port_map: param passed to ahci_save_initial_config
288 *
289 * This function does all the usual steps needed to bring up an
290 * ahci-platform host, note any necessary resources (ie clks, phy, etc.)
291 * must be initialized / enabled before calling this.
292 *
293 * RETURNS:
294 * 0 on success otherwise a negative error code
295 */
296int ahci_platform_init_host(struct platform_device *pdev,
297 struct ahci_host_priv *hpriv,
298 const struct ata_port_info *pi_template,
299 unsigned int force_port_map,
300 unsigned int mask_port_map)
301{
302 struct device *dev = &pdev->dev;
303 struct ata_port_info pi = *pi_template;
304 const struct ata_port_info *ppi[] = { &pi, NULL };
305 struct ata_host *host;
306 int i, irq, n_ports, rc;
307
308 irq = platform_get_irq(pdev, 0);
309 if (irq <= 0) {
310 dev_err(dev, "no irq\n");
311 return -EINVAL;
312 }
313
314 /* prepare host */
315 hpriv->flags |= (unsigned long)pi.private_data;
316
317 ahci_save_initial_config(dev, hpriv, force_port_map, mask_port_map);
318
319 if (hpriv->cap & HOST_CAP_NCQ)
320 pi.flags |= ATA_FLAG_NCQ;
321
322 if (hpriv->cap & HOST_CAP_PMP)
323 pi.flags |= ATA_FLAG_PMP;
324
325 ahci_set_em_messages(hpriv, &pi);
326
327 /* CAP.NP sometimes indicate the index of the last enabled
328 * port, at other times, that of the last possible port, so
329 * determining the maximum port number requires looking at
330 * both CAP.NP and port_map.
331 */
332 n_ports = max(ahci_nr_ports(hpriv->cap), fls(hpriv->port_map));
333
334 host = ata_host_alloc_pinfo(dev, ppi, n_ports);
335 if (!host)
336 return -ENOMEM;
337
338 host->private_data = hpriv;
339
340 if (!(hpriv->cap & HOST_CAP_SSS) || ahci_ignore_sss)
341 host->flags |= ATA_HOST_PARALLEL_SCAN;
342 else
343 dev_info(dev, "SSS flag set, parallel bus scan disabled\n");
344
345 if (pi.flags & ATA_FLAG_EM)
346 ahci_reset_em(host);
347
348 for (i = 0; i < host->n_ports; i++) {
349 struct ata_port *ap = host->ports[i];
350
351 ata_port_desc(ap, "mmio %pR",
352 platform_get_resource(pdev, IORESOURCE_MEM, 0));
353 ata_port_desc(ap, "port 0x%x", 0x100 + ap->port_no * 0x80);
354
355 /* set enclosure management message type */
356 if (ap->flags & ATA_FLAG_EM)
357 ap->em_message_type = hpriv->em_msg_type;
358
359 /* disabled/not-implemented port */
360 if (!(hpriv->port_map & (1 << i)))
361 ap->ops = &ata_dummy_port_ops;
362 }
363
364 rc = ahci_reset_controller(host);
365 if (rc)
366 return rc;
367
368 ahci_init_controller(host);
369 ahci_print_info(host, "platform");
370
371 return ata_host_activate(host, irq, ahci_interrupt, IRQF_SHARED,
372 &ahci_platform_sht);
373}
374EXPORT_SYMBOL_GPL(ahci_platform_init_host);
375
376static void ahci_host_stop(struct ata_host *host)
377{
378 struct device *dev = host->dev;
379 struct ahci_platform_data *pdata = dev_get_platdata(dev);
380 struct ahci_host_priv *hpriv = host->private_data;
381
382 if (pdata && pdata->exit)
383 pdata->exit(dev);
384
385 ahci_platform_disable_resources(hpriv);
386}
387
388#ifdef CONFIG_PM_SLEEP
389/**
390 * ahci_platform_suspend_host - Suspend an ahci-platform host
391 * @dev: device pointer for the host
392 *
393 * This function does all the usual steps needed to suspend an
394 * ahci-platform host, note any necessary resources (ie clks, phy, etc.)
395 * must be disabled after calling this.
396 *
397 * RETURNS:
398 * 0 on success otherwise a negative error code
399 */
400int ahci_platform_suspend_host(struct device *dev)
401{
402 struct ata_host *host = dev_get_drvdata(dev);
403 struct ahci_host_priv *hpriv = host->private_data;
404 void __iomem *mmio = hpriv->mmio;
405 u32 ctl;
406
407 if (hpriv->flags & AHCI_HFLAG_NO_SUSPEND) {
408 dev_err(dev, "firmware update required for suspend/resume\n");
409 return -EIO;
410 }
411
412 /*
413 * AHCI spec rev1.1 section 8.3.3:
414 * Software must disable interrupts prior to requesting a
415 * transition of the HBA to D3 state.
416 */
417 ctl = readl(mmio + HOST_CTL);
418 ctl &= ~HOST_IRQ_EN;
419 writel(ctl, mmio + HOST_CTL);
420 readl(mmio + HOST_CTL); /* flush */
421
422 return ata_host_suspend(host, PMSG_SUSPEND);
423}
424EXPORT_SYMBOL_GPL(ahci_platform_suspend_host);
425
426/**
427 * ahci_platform_resume_host - Resume an ahci-platform host
428 * @dev: device pointer for the host
429 *
430 * This function does all the usual steps needed to resume an ahci-platform
431 * host, note any necessary resources (ie clks, phy, etc.) must be
432 * initialized / enabled before calling this.
433 *
434 * RETURNS:
435 * 0 on success otherwise a negative error code
436 */
437int ahci_platform_resume_host(struct device *dev)
438{
439 struct ata_host *host = dev_get_drvdata(dev);
440 int rc;
441
442 if (dev->power.power_state.event == PM_EVENT_SUSPEND) {
443 rc = ahci_reset_controller(host);
444 if (rc)
445 return rc;
446
447 ahci_init_controller(host);
448 }
449
450 ata_host_resume(host);
451
452 return 0;
453}
454EXPORT_SYMBOL_GPL(ahci_platform_resume_host);
455
456/**
457 * ahci_platform_suspend - Suspend an ahci-platform device
458 * @dev: the platform device to suspend
459 *
460 * This function suspends the host associated with the device, followed by
461 * disabling all the resources of the device.
462 *
463 * RETURNS:
464 * 0 on success otherwise a negative error code
465 */
466int ahci_platform_suspend(struct device *dev)
467{
468 struct ahci_platform_data *pdata = dev_get_platdata(dev);
469 struct ata_host *host = dev_get_drvdata(dev);
470 struct ahci_host_priv *hpriv = host->private_data;
471 int rc;
472
473 rc = ahci_platform_suspend_host(dev);
474 if (rc)
475 return rc;
476
477 if (pdata && pdata->suspend) {
478 rc = pdata->suspend(dev);
479 if (rc)
480 goto resume_host;
481 }
482
483 ahci_platform_disable_resources(hpriv);
484
485 return 0;
486
487resume_host:
488 ahci_platform_resume_host(dev);
489 return rc;
490}
491EXPORT_SYMBOL_GPL(ahci_platform_suspend);
492
493/**
494 * ahci_platform_resume - Resume an ahci-platform device
495 * @dev: the platform device to resume
496 *
497 * This function enables all the resources of the device followed by
498 * resuming the host associated with the device.
499 *
500 * RETURNS:
501 * 0 on success otherwise a negative error code
502 */
503int ahci_platform_resume(struct device *dev)
504{
505 struct ahci_platform_data *pdata = dev_get_platdata(dev);
506 struct ata_host *host = dev_get_drvdata(dev);
507 struct ahci_host_priv *hpriv = host->private_data;
508 int rc;
509
510 rc = ahci_platform_enable_resources(hpriv);
511 if (rc)
512 return rc;
513
514 if (pdata && pdata->resume) {
515 rc = pdata->resume(dev);
516 if (rc)
517 goto disable_resources;
518 }
519
520 rc = ahci_platform_resume_host(dev);
521 if (rc)
522 goto disable_resources;
523
524 /* We resumed so update PM runtime state */
525 pm_runtime_disable(dev);
526 pm_runtime_set_active(dev);
527 pm_runtime_enable(dev);
528
529 return 0;
530
531disable_resources:
532 ahci_platform_disable_resources(hpriv);
533
534 return rc;
535}
536EXPORT_SYMBOL_GPL(ahci_platform_resume);
537#endif
538
539MODULE_DESCRIPTION("AHCI SATA platform library");
540MODULE_AUTHOR("Anton Vorontsov <avorontsov@ru.mvista.com>");
541MODULE_LICENSE("GPL");
diff --git a/drivers/ata/libata-acpi.c b/drivers/ata/libata-acpi.c
index 9e69a5308693..b4f7cc2522d9 100644
--- a/drivers/ata/libata-acpi.c
+++ b/drivers/ata/libata-acpi.c
@@ -835,6 +835,7 @@ void ata_acpi_on_resume(struct ata_port *ap)
835 ata_for_each_dev(dev, &ap->link, ALL) { 835 ata_for_each_dev(dev, &ap->link, ALL) {
836 ata_acpi_clear_gtf(dev); 836 ata_acpi_clear_gtf(dev);
837 if (ata_dev_enabled(dev) && 837 if (ata_dev_enabled(dev) &&
838 ata_dev_acpi_handle(dev) &&
838 ata_dev_get_GTF(dev, NULL) >= 0) 839 ata_dev_get_GTF(dev, NULL) >= 0)
839 dev->flags |= ATA_DFLAG_ACPI_PENDING; 840 dev->flags |= ATA_DFLAG_ACPI_PENDING;
840 } 841 }
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index 1a3dbd1b196e..34406f7fdd7a 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -4175,6 +4175,7 @@ static const struct ata_blacklist_entry ata_device_blacklist [] = {
4175 4175
4176 /* Seagate Momentus SpinPoint M8 seem to have FPMDA_AA issues */ 4176 /* Seagate Momentus SpinPoint M8 seem to have FPMDA_AA issues */
4177 { "ST1000LM024 HN-M101MBB", "2AR10001", ATA_HORKAGE_BROKEN_FPDMA_AA }, 4177 { "ST1000LM024 HN-M101MBB", "2AR10001", ATA_HORKAGE_BROKEN_FPDMA_AA },
4178 { "ST1000LM024 HN-M101MBB", "2BA30001", ATA_HORKAGE_BROKEN_FPDMA_AA },
4178 4179
4179 /* Blacklist entries taken from Silicon Image 3124/3132 4180 /* Blacklist entries taken from Silicon Image 3124/3132
4180 Windows driver .inf file - also several Linux problem reports */ 4181 Windows driver .inf file - also several Linux problem reports */
@@ -4224,7 +4225,7 @@ static const struct ata_blacklist_entry ata_device_blacklist [] = {
4224 4225
4225 /* devices that don't properly handle queued TRIM commands */ 4226 /* devices that don't properly handle queued TRIM commands */
4226 { "Micron_M500*", NULL, ATA_HORKAGE_NO_NCQ_TRIM, }, 4227 { "Micron_M500*", NULL, ATA_HORKAGE_NO_NCQ_TRIM, },
4227 { "Crucial_CT???M500SSD1", NULL, ATA_HORKAGE_NO_NCQ_TRIM, }, 4228 { "Crucial_CT???M500SSD*", NULL, ATA_HORKAGE_NO_NCQ_TRIM, },
4228 4229
4229 /* 4230 /*
4230 * Some WD SATA-I drives spin up and down erratically when the link 4231 * Some WD SATA-I drives spin up and down erratically when the link
@@ -5351,22 +5352,17 @@ bool ata_link_offline(struct ata_link *link)
5351} 5352}
5352 5353
5353#ifdef CONFIG_PM 5354#ifdef CONFIG_PM
5354static int ata_port_request_pm(struct ata_port *ap, pm_message_t mesg, 5355static void ata_port_request_pm(struct ata_port *ap, pm_message_t mesg,
5355 unsigned int action, unsigned int ehi_flags, 5356 unsigned int action, unsigned int ehi_flags,
5356 int *async) 5357 bool async)
5357{ 5358{
5358 struct ata_link *link; 5359 struct ata_link *link;
5359 unsigned long flags; 5360 unsigned long flags;
5360 int rc = 0;
5361 5361
5362 /* Previous resume operation might still be in 5362 /* Previous resume operation might still be in
5363 * progress. Wait for PM_PENDING to clear. 5363 * progress. Wait for PM_PENDING to clear.
5364 */ 5364 */
5365 if (ap->pflags & ATA_PFLAG_PM_PENDING) { 5365 if (ap->pflags & ATA_PFLAG_PM_PENDING) {
5366 if (async) {
5367 *async = -EAGAIN;
5368 return 0;
5369 }
5370 ata_port_wait_eh(ap); 5366 ata_port_wait_eh(ap);
5371 WARN_ON(ap->pflags & ATA_PFLAG_PM_PENDING); 5367 WARN_ON(ap->pflags & ATA_PFLAG_PM_PENDING);
5372 } 5368 }
@@ -5375,11 +5371,6 @@ static int ata_port_request_pm(struct ata_port *ap, pm_message_t mesg,
5375 spin_lock_irqsave(ap->lock, flags); 5371 spin_lock_irqsave(ap->lock, flags);
5376 5372
5377 ap->pm_mesg = mesg; 5373 ap->pm_mesg = mesg;
5378 if (async)
5379 ap->pm_result = async;
5380 else
5381 ap->pm_result = &rc;
5382
5383 ap->pflags |= ATA_PFLAG_PM_PENDING; 5374 ap->pflags |= ATA_PFLAG_PM_PENDING;
5384 ata_for_each_link(link, ap, HOST_FIRST) { 5375 ata_for_each_link(link, ap, HOST_FIRST) {
5385 link->eh_info.action |= action; 5376 link->eh_info.action |= action;
@@ -5390,87 +5381,81 @@ static int ata_port_request_pm(struct ata_port *ap, pm_message_t mesg,
5390 5381
5391 spin_unlock_irqrestore(ap->lock, flags); 5382 spin_unlock_irqrestore(ap->lock, flags);
5392 5383
5393 /* wait and check result */
5394 if (!async) { 5384 if (!async) {
5395 ata_port_wait_eh(ap); 5385 ata_port_wait_eh(ap);
5396 WARN_ON(ap->pflags & ATA_PFLAG_PM_PENDING); 5386 WARN_ON(ap->pflags & ATA_PFLAG_PM_PENDING);
5397 } 5387 }
5398
5399 return rc;
5400} 5388}
5401 5389
5402static int __ata_port_suspend_common(struct ata_port *ap, pm_message_t mesg, int *async) 5390/*
5391 * On some hardware, device fails to respond after spun down for suspend. As
5392 * the device won't be used before being resumed, we don't need to touch the
5393 * device. Ask EH to skip the usual stuff and proceed directly to suspend.
5394 *
5395 * http://thread.gmane.org/gmane.linux.ide/46764
5396 */
5397static const unsigned int ata_port_suspend_ehi = ATA_EHI_QUIET
5398 | ATA_EHI_NO_AUTOPSY
5399 | ATA_EHI_NO_RECOVERY;
5400
5401static void ata_port_suspend(struct ata_port *ap, pm_message_t mesg)
5403{ 5402{
5404 /* 5403 ata_port_request_pm(ap, mesg, 0, ata_port_suspend_ehi, false);
5405 * On some hardware, device fails to respond after spun down
5406 * for suspend. As the device won't be used before being
5407 * resumed, we don't need to touch the device. Ask EH to skip
5408 * the usual stuff and proceed directly to suspend.
5409 *
5410 * http://thread.gmane.org/gmane.linux.ide/46764
5411 */
5412 unsigned int ehi_flags = ATA_EHI_QUIET | ATA_EHI_NO_AUTOPSY |
5413 ATA_EHI_NO_RECOVERY;
5414 return ata_port_request_pm(ap, mesg, 0, ehi_flags, async);
5415} 5404}
5416 5405
5417static int ata_port_suspend_common(struct device *dev, pm_message_t mesg) 5406static void ata_port_suspend_async(struct ata_port *ap, pm_message_t mesg)
5418{ 5407{
5419 struct ata_port *ap = to_ata_port(dev); 5408 ata_port_request_pm(ap, mesg, 0, ata_port_suspend_ehi, true);
5420
5421 return __ata_port_suspend_common(ap, mesg, NULL);
5422} 5409}
5423 5410
5424static int ata_port_suspend(struct device *dev) 5411static int ata_port_pm_suspend(struct device *dev)
5425{ 5412{
5413 struct ata_port *ap = to_ata_port(dev);
5414
5426 if (pm_runtime_suspended(dev)) 5415 if (pm_runtime_suspended(dev))
5427 return 0; 5416 return 0;
5428 5417
5429 return ata_port_suspend_common(dev, PMSG_SUSPEND); 5418 ata_port_suspend(ap, PMSG_SUSPEND);
5419 return 0;
5430} 5420}
5431 5421
5432static int ata_port_do_freeze(struct device *dev) 5422static int ata_port_pm_freeze(struct device *dev)
5433{ 5423{
5424 struct ata_port *ap = to_ata_port(dev);
5425
5434 if (pm_runtime_suspended(dev)) 5426 if (pm_runtime_suspended(dev))
5435 return 0; 5427 return 0;
5436 5428
5437 return ata_port_suspend_common(dev, PMSG_FREEZE); 5429 ata_port_suspend(ap, PMSG_FREEZE);
5430 return 0;
5438} 5431}
5439 5432
5440static int ata_port_poweroff(struct device *dev) 5433static int ata_port_pm_poweroff(struct device *dev)
5441{ 5434{
5442 return ata_port_suspend_common(dev, PMSG_HIBERNATE); 5435 ata_port_suspend(to_ata_port(dev), PMSG_HIBERNATE);
5436 return 0;
5443} 5437}
5444 5438
5445static int __ata_port_resume_common(struct ata_port *ap, pm_message_t mesg, 5439static const unsigned int ata_port_resume_ehi = ATA_EHI_NO_AUTOPSY
5446 int *async) 5440 | ATA_EHI_QUIET;
5447{
5448 int rc;
5449 5441
5450 rc = ata_port_request_pm(ap, mesg, ATA_EH_RESET, 5442static void ata_port_resume(struct ata_port *ap, pm_message_t mesg)
5451 ATA_EHI_NO_AUTOPSY | ATA_EHI_QUIET, async); 5443{
5452 return rc; 5444 ata_port_request_pm(ap, mesg, ATA_EH_RESET, ata_port_resume_ehi, false);
5453} 5445}
5454 5446
5455static int ata_port_resume_common(struct device *dev, pm_message_t mesg) 5447static void ata_port_resume_async(struct ata_port *ap, pm_message_t mesg)
5456{ 5448{
5457 struct ata_port *ap = to_ata_port(dev); 5449 ata_port_request_pm(ap, mesg, ATA_EH_RESET, ata_port_resume_ehi, true);
5458
5459 return __ata_port_resume_common(ap, mesg, NULL);
5460} 5450}
5461 5451
5462static int ata_port_resume(struct device *dev) 5452static int ata_port_pm_resume(struct device *dev)
5463{ 5453{
5464 int rc; 5454 ata_port_resume_async(to_ata_port(dev), PMSG_RESUME);
5465 5455 pm_runtime_disable(dev);
5466 rc = ata_port_resume_common(dev, PMSG_RESUME); 5456 pm_runtime_set_active(dev);
5467 if (!rc) { 5457 pm_runtime_enable(dev);
5468 pm_runtime_disable(dev); 5458 return 0;
5469 pm_runtime_set_active(dev);
5470 pm_runtime_enable(dev);
5471 }
5472
5473 return rc;
5474} 5459}
5475 5460
5476/* 5461/*
@@ -5499,21 +5484,23 @@ static int ata_port_runtime_idle(struct device *dev)
5499 5484
5500static int ata_port_runtime_suspend(struct device *dev) 5485static int ata_port_runtime_suspend(struct device *dev)
5501{ 5486{
5502 return ata_port_suspend_common(dev, PMSG_AUTO_SUSPEND); 5487 ata_port_suspend(to_ata_port(dev), PMSG_AUTO_SUSPEND);
5488 return 0;
5503} 5489}
5504 5490
5505static int ata_port_runtime_resume(struct device *dev) 5491static int ata_port_runtime_resume(struct device *dev)
5506{ 5492{
5507 return ata_port_resume_common(dev, PMSG_AUTO_RESUME); 5493 ata_port_resume(to_ata_port(dev), PMSG_AUTO_RESUME);
5494 return 0;
5508} 5495}
5509 5496
5510static const struct dev_pm_ops ata_port_pm_ops = { 5497static const struct dev_pm_ops ata_port_pm_ops = {
5511 .suspend = ata_port_suspend, 5498 .suspend = ata_port_pm_suspend,
5512 .resume = ata_port_resume, 5499 .resume = ata_port_pm_resume,
5513 .freeze = ata_port_do_freeze, 5500 .freeze = ata_port_pm_freeze,
5514 .thaw = ata_port_resume, 5501 .thaw = ata_port_pm_resume,
5515 .poweroff = ata_port_poweroff, 5502 .poweroff = ata_port_pm_poweroff,
5516 .restore = ata_port_resume, 5503 .restore = ata_port_pm_resume,
5517 5504
5518 .runtime_suspend = ata_port_runtime_suspend, 5505 .runtime_suspend = ata_port_runtime_suspend,
5519 .runtime_resume = ata_port_runtime_resume, 5506 .runtime_resume = ata_port_runtime_resume,
@@ -5525,18 +5512,17 @@ static const struct dev_pm_ops ata_port_pm_ops = {
5525 * level. sas suspend/resume is async to allow parallel port recovery 5512 * level. sas suspend/resume is async to allow parallel port recovery
5526 * since sas has multiple ata_port instances per Scsi_Host. 5513 * since sas has multiple ata_port instances per Scsi_Host.
5527 */ 5514 */
5528int ata_sas_port_async_suspend(struct ata_port *ap, int *async) 5515void ata_sas_port_suspend(struct ata_port *ap)
5529{ 5516{
5530 return __ata_port_suspend_common(ap, PMSG_SUSPEND, async); 5517 ata_port_suspend_async(ap, PMSG_SUSPEND);
5531} 5518}
5532EXPORT_SYMBOL_GPL(ata_sas_port_async_suspend); 5519EXPORT_SYMBOL_GPL(ata_sas_port_suspend);
5533 5520
5534int ata_sas_port_async_resume(struct ata_port *ap, int *async) 5521void ata_sas_port_resume(struct ata_port *ap)
5535{ 5522{
5536 return __ata_port_resume_common(ap, PMSG_RESUME, async); 5523 ata_port_resume_async(ap, PMSG_RESUME);
5537} 5524}
5538EXPORT_SYMBOL_GPL(ata_sas_port_async_resume); 5525EXPORT_SYMBOL_GPL(ata_sas_port_resume);
5539
5540 5526
5541/** 5527/**
5542 * ata_host_suspend - suspend host 5528 * ata_host_suspend - suspend host
diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c
index 6d8757008318..6760fc4e85b8 100644
--- a/drivers/ata/libata-eh.c
+++ b/drivers/ata/libata-eh.c
@@ -95,12 +95,13 @@ enum {
95 * represents timeout for that try. The first try can be soft or 95 * represents timeout for that try. The first try can be soft or
96 * hardreset. All others are hardreset if available. In most cases 96 * hardreset. All others are hardreset if available. In most cases
97 * the first reset w/ 10sec timeout should succeed. Following entries 97 * the first reset w/ 10sec timeout should succeed. Following entries
98 * are mostly for error handling, hotplug and retarded devices. 98 * are mostly for error handling, hotplug and those outlier devices that
99 * take an exceptionally long time to recover from reset.
99 */ 100 */
100static const unsigned long ata_eh_reset_timeouts[] = { 101static const unsigned long ata_eh_reset_timeouts[] = {
101 10000, /* most drives spin up by 10sec */ 102 10000, /* most drives spin up by 10sec */
102 10000, /* > 99% working drives spin up before 20sec */ 103 10000, /* > 99% working drives spin up before 20sec */
103 35000, /* give > 30 secs of idleness for retarded devices */ 104 35000, /* give > 30 secs of idleness for outlier devices */
104 5000, /* and sweet one last chance */ 105 5000, /* and sweet one last chance */
105 ULONG_MAX, /* > 1 min has elapsed, give up */ 106 ULONG_MAX, /* > 1 min has elapsed, give up */
106}; 107};
@@ -4069,7 +4070,7 @@ static void ata_eh_handle_port_suspend(struct ata_port *ap)
4069 4070
4070 ata_acpi_set_state(ap, ap->pm_mesg); 4071 ata_acpi_set_state(ap, ap->pm_mesg);
4071 out: 4072 out:
4072 /* report result */ 4073 /* update the flags */
4073 spin_lock_irqsave(ap->lock, flags); 4074 spin_lock_irqsave(ap->lock, flags);
4074 4075
4075 ap->pflags &= ~ATA_PFLAG_PM_PENDING; 4076 ap->pflags &= ~ATA_PFLAG_PM_PENDING;
@@ -4078,11 +4079,6 @@ static void ata_eh_handle_port_suspend(struct ata_port *ap)
4078 else if (ap->pflags & ATA_PFLAG_FROZEN) 4079 else if (ap->pflags & ATA_PFLAG_FROZEN)
4079 ata_port_schedule_eh(ap); 4080 ata_port_schedule_eh(ap);
4080 4081
4081 if (ap->pm_result) {
4082 *ap->pm_result = rc;
4083 ap->pm_result = NULL;
4084 }
4085
4086 spin_unlock_irqrestore(ap->lock, flags); 4082 spin_unlock_irqrestore(ap->lock, flags);
4087 4083
4088 return; 4084 return;
@@ -4134,13 +4130,9 @@ static void ata_eh_handle_port_resume(struct ata_port *ap)
4134 /* tell ACPI that we're resuming */ 4130 /* tell ACPI that we're resuming */
4135 ata_acpi_on_resume(ap); 4131 ata_acpi_on_resume(ap);
4136 4132
4137 /* report result */ 4133 /* update the flags */
4138 spin_lock_irqsave(ap->lock, flags); 4134 spin_lock_irqsave(ap->lock, flags);
4139 ap->pflags &= ~(ATA_PFLAG_PM_PENDING | ATA_PFLAG_SUSPENDED); 4135 ap->pflags &= ~(ATA_PFLAG_PM_PENDING | ATA_PFLAG_SUSPENDED);
4140 if (ap->pm_result) {
4141 *ap->pm_result = rc;
4142 ap->pm_result = NULL;
4143 }
4144 spin_unlock_irqrestore(ap->lock, flags); 4136 spin_unlock_irqrestore(ap->lock, flags);
4145} 4137}
4146#endif /* CONFIG_PM */ 4138#endif /* CONFIG_PM */
diff --git a/drivers/ata/libata-zpodd.c b/drivers/ata/libata-zpodd.c
index 88949c6d55dd..f3a65a3140d3 100644
--- a/drivers/ata/libata-zpodd.c
+++ b/drivers/ata/libata-zpodd.c
@@ -85,21 +85,6 @@ static enum odd_mech_type zpodd_get_mech_type(struct ata_device *dev)
85 return ODD_MECH_TYPE_UNSUPPORTED; 85 return ODD_MECH_TYPE_UNSUPPORTED;
86} 86}
87 87
88static bool odd_can_poweroff(struct ata_device *ata_dev)
89{
90 acpi_handle handle;
91 struct acpi_device *acpi_dev;
92
93 handle = ata_dev_acpi_handle(ata_dev);
94 if (!handle)
95 return false;
96
97 if (acpi_bus_get_device(handle, &acpi_dev))
98 return false;
99
100 return acpi_device_can_poweroff(acpi_dev);
101}
102
103/* Test if ODD is zero power ready by sense code */ 88/* Test if ODD is zero power ready by sense code */
104static bool zpready(struct ata_device *dev) 89static bool zpready(struct ata_device *dev)
105{ 90{
@@ -267,13 +252,11 @@ static void ata_acpi_remove_pm_notifier(struct ata_device *dev)
267 252
268void zpodd_init(struct ata_device *dev) 253void zpodd_init(struct ata_device *dev)
269{ 254{
255 struct acpi_device *adev = ACPI_COMPANION(&dev->tdev);
270 enum odd_mech_type mech_type; 256 enum odd_mech_type mech_type;
271 struct zpodd *zpodd; 257 struct zpodd *zpodd;
272 258
273 if (dev->zpodd) 259 if (dev->zpodd || !adev || !acpi_device_can_poweroff(adev))
274 return;
275
276 if (!odd_can_poweroff(dev))
277 return; 260 return;
278 261
279 mech_type = zpodd_get_mech_type(dev); 262 mech_type = zpodd_get_mech_type(dev);
diff --git a/drivers/ata/pata_acpi.c b/drivers/ata/pata_acpi.c
index 62c9ac80c6e9..5108b8744dce 100644
--- a/drivers/ata/pata_acpi.c
+++ b/drivers/ata/pata_acpi.c
@@ -7,7 +7,6 @@
7#include <linux/kernel.h> 7#include <linux/kernel.h>
8#include <linux/module.h> 8#include <linux/module.h>
9#include <linux/pci.h> 9#include <linux/pci.h>
10#include <linux/init.h>
11#include <linux/blkdev.h> 10#include <linux/blkdev.h>
12#include <linux/delay.h> 11#include <linux/delay.h>
13#include <linux/device.h> 12#include <linux/device.h>
diff --git a/drivers/ata/pata_amd.c b/drivers/ata/pata_amd.c
index d23e2b3ca0b6..1206fa6b62ca 100644
--- a/drivers/ata/pata_amd.c
+++ b/drivers/ata/pata_amd.c
@@ -17,7 +17,6 @@
17#include <linux/kernel.h> 17#include <linux/kernel.h>
18#include <linux/module.h> 18#include <linux/module.h>
19#include <linux/pci.h> 19#include <linux/pci.h>
20#include <linux/init.h>
21#include <linux/blkdev.h> 20#include <linux/blkdev.h>
22#include <linux/delay.h> 21#include <linux/delay.h>
23#include <scsi/scsi_host.h> 22#include <scsi/scsi_host.h>
diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
index 73492dd4a4bc..6fac524c2f50 100644
--- a/drivers/ata/pata_arasan_cf.c
+++ b/drivers/ata/pata_arasan_cf.c
@@ -356,7 +356,7 @@ static void cf_exit(struct arasan_cf_dev *acdev)
356 356
357static void dma_callback(void *dev) 357static void dma_callback(void *dev)
358{ 358{
359 struct arasan_cf_dev *acdev = (struct arasan_cf_dev *) dev; 359 struct arasan_cf_dev *acdev = dev;
360 360
361 complete(&acdev->dma_completion); 361 complete(&acdev->dma_completion);
362} 362}
diff --git a/drivers/ata/pata_artop.c b/drivers/ata/pata_artop.c
index 1581dee2967a..3aa4e655e3c6 100644
--- a/drivers/ata/pata_artop.c
+++ b/drivers/ata/pata_artop.c
@@ -19,7 +19,6 @@
19#include <linux/kernel.h> 19#include <linux/kernel.h>
20#include <linux/module.h> 20#include <linux/module.h>
21#include <linux/pci.h> 21#include <linux/pci.h>
22#include <linux/init.h>
23#include <linux/blkdev.h> 22#include <linux/blkdev.h>
24#include <linux/delay.h> 23#include <linux/delay.h>
25#include <linux/device.h> 24#include <linux/device.h>
diff --git a/drivers/ata/pata_at91.c b/drivers/ata/pata_at91.c
index d63ee8f41a4f..e9c87274a781 100644
--- a/drivers/ata/pata_at91.c
+++ b/drivers/ata/pata_at91.c
@@ -18,7 +18,6 @@
18 18
19#include <linux/kernel.h> 19#include <linux/kernel.h>
20#include <linux/module.h> 20#include <linux/module.h>
21#include <linux/init.h>
22#include <linux/blkdev.h> 21#include <linux/blkdev.h>
23#include <linux/gfp.h> 22#include <linux/gfp.h>
24#include <scsi/scsi_host.h> 23#include <scsi/scsi_host.h>
diff --git a/drivers/ata/pata_atiixp.c b/drivers/ata/pata_atiixp.c
index 24e51056ac26..30fa4ca4cef6 100644
--- a/drivers/ata/pata_atiixp.c
+++ b/drivers/ata/pata_atiixp.c
@@ -15,7 +15,6 @@
15#include <linux/kernel.h> 15#include <linux/kernel.h>
16#include <linux/module.h> 16#include <linux/module.h>
17#include <linux/pci.h> 17#include <linux/pci.h>
18#include <linux/init.h>
19#include <linux/blkdev.h> 18#include <linux/blkdev.h>
20#include <linux/delay.h> 19#include <linux/delay.h>
21#include <scsi/scsi_host.h> 20#include <scsi/scsi_host.h>
diff --git a/drivers/ata/pata_atp867x.c b/drivers/ata/pata_atp867x.c
index 2ca5026f2c15..7e73a0f1e323 100644
--- a/drivers/ata/pata_atp867x.c
+++ b/drivers/ata/pata_atp867x.c
@@ -29,7 +29,6 @@
29#include <linux/kernel.h> 29#include <linux/kernel.h>
30#include <linux/module.h> 30#include <linux/module.h>
31#include <linux/pci.h> 31#include <linux/pci.h>
32#include <linux/init.h>
33#include <linux/blkdev.h> 32#include <linux/blkdev.h>
34#include <linux/delay.h> 33#include <linux/delay.h>
35#include <linux/device.h> 34#include <linux/device.h>
diff --git a/drivers/ata/pata_cmd640.c b/drivers/ata/pata_cmd640.c
index 8fb69e5ca1b7..57f1be64dbf2 100644
--- a/drivers/ata/pata_cmd640.c
+++ b/drivers/ata/pata_cmd640.c
@@ -15,7 +15,6 @@
15#include <linux/kernel.h> 15#include <linux/kernel.h>
16#include <linux/module.h> 16#include <linux/module.h>
17#include <linux/pci.h> 17#include <linux/pci.h>
18#include <linux/init.h>
19#include <linux/blkdev.h> 18#include <linux/blkdev.h>
20#include <linux/delay.h> 19#include <linux/delay.h>
21#include <linux/gfp.h> 20#include <linux/gfp.h>
diff --git a/drivers/ata/pata_cmd64x.c b/drivers/ata/pata_cmd64x.c
index 1275a8d4dedc..6bca3505b9e9 100644
--- a/drivers/ata/pata_cmd64x.c
+++ b/drivers/ata/pata_cmd64x.c
@@ -26,7 +26,6 @@
26#include <linux/kernel.h> 26#include <linux/kernel.h>
27#include <linux/module.h> 27#include <linux/module.h>
28#include <linux/pci.h> 28#include <linux/pci.h>
29#include <linux/init.h>
30#include <linux/blkdev.h> 29#include <linux/blkdev.h>
31#include <linux/delay.h> 30#include <linux/delay.h>
32#include <scsi/scsi_host.h> 31#include <scsi/scsi_host.h>
diff --git a/drivers/ata/pata_cs5520.c b/drivers/ata/pata_cs5520.c
index f10baabbf5db..bcde4b786807 100644
--- a/drivers/ata/pata_cs5520.c
+++ b/drivers/ata/pata_cs5520.c
@@ -34,7 +34,6 @@
34#include <linux/kernel.h> 34#include <linux/kernel.h>
35#include <linux/module.h> 35#include <linux/module.h>
36#include <linux/pci.h> 36#include <linux/pci.h>
37#include <linux/init.h>
38#include <linux/blkdev.h> 37#include <linux/blkdev.h>
39#include <linux/delay.h> 38#include <linux/delay.h>
40#include <scsi/scsi_host.h> 39#include <scsi/scsi_host.h>
diff --git a/drivers/ata/pata_cs5530.c b/drivers/ata/pata_cs5530.c
index f07f2296acdc..8afe854a5a50 100644
--- a/drivers/ata/pata_cs5530.c
+++ b/drivers/ata/pata_cs5530.c
@@ -26,7 +26,6 @@
26#include <linux/kernel.h> 26#include <linux/kernel.h>
27#include <linux/module.h> 27#include <linux/module.h>
28#include <linux/pci.h> 28#include <linux/pci.h>
29#include <linux/init.h>
30#include <linux/blkdev.h> 29#include <linux/blkdev.h>
31#include <linux/delay.h> 30#include <linux/delay.h>
32#include <scsi/scsi_host.h> 31#include <scsi/scsi_host.h>
diff --git a/drivers/ata/pata_cs5535.c b/drivers/ata/pata_cs5535.c
index 997e16a3a63f..2c0986fa4bb2 100644
--- a/drivers/ata/pata_cs5535.c
+++ b/drivers/ata/pata_cs5535.c
@@ -31,7 +31,6 @@
31#include <linux/kernel.h> 31#include <linux/kernel.h>
32#include <linux/module.h> 32#include <linux/module.h>
33#include <linux/pci.h> 33#include <linux/pci.h>
34#include <linux/init.h>
35#include <linux/blkdev.h> 34#include <linux/blkdev.h>
36#include <linux/delay.h> 35#include <linux/delay.h>
37#include <scsi/scsi_host.h> 36#include <scsi/scsi_host.h>
diff --git a/drivers/ata/pata_cs5536.c b/drivers/ata/pata_cs5536.c
index 0448860a2077..32ddcae5a360 100644
--- a/drivers/ata/pata_cs5536.c
+++ b/drivers/ata/pata_cs5536.c
@@ -33,7 +33,6 @@
33#include <linux/kernel.h> 33#include <linux/kernel.h>
34#include <linux/module.h> 34#include <linux/module.h>
35#include <linux/pci.h> 35#include <linux/pci.h>
36#include <linux/init.h>
37#include <linux/blkdev.h> 36#include <linux/blkdev.h>
38#include <linux/delay.h> 37#include <linux/delay.h>
39#include <linux/libata.h> 38#include <linux/libata.h>
diff --git a/drivers/ata/pata_cypress.c b/drivers/ata/pata_cypress.c
index 810bc9964dde..3435bd6a5cc9 100644
--- a/drivers/ata/pata_cypress.c
+++ b/drivers/ata/pata_cypress.c
@@ -11,7 +11,6 @@
11#include <linux/kernel.h> 11#include <linux/kernel.h>
12#include <linux/module.h> 12#include <linux/module.h>
13#include <linux/pci.h> 13#include <linux/pci.h>
14#include <linux/init.h>
15#include <linux/blkdev.h> 14#include <linux/blkdev.h>
16#include <linux/delay.h> 15#include <linux/delay.h>
17#include <scsi/scsi_host.h> 16#include <scsi/scsi_host.h>
diff --git a/drivers/ata/pata_efar.c b/drivers/ata/pata_efar.c
index 3c12fd7acd41..f440892225f4 100644
--- a/drivers/ata/pata_efar.c
+++ b/drivers/ata/pata_efar.c
@@ -14,7 +14,6 @@
14#include <linux/kernel.h> 14#include <linux/kernel.h>
15#include <linux/module.h> 15#include <linux/module.h>
16#include <linux/pci.h> 16#include <linux/pci.h>
17#include <linux/init.h>
18#include <linux/blkdev.h> 17#include <linux/blkdev.h>
19#include <linux/delay.h> 18#include <linux/delay.h>
20#include <linux/device.h> 19#include <linux/device.h>
diff --git a/drivers/ata/pata_ep93xx.c b/drivers/ata/pata_ep93xx.c
index 980b88e109fc..cad9d45749c4 100644
--- a/drivers/ata/pata_ep93xx.c
+++ b/drivers/ata/pata_ep93xx.c
@@ -34,7 +34,6 @@
34#include <linux/err.h> 34#include <linux/err.h>
35#include <linux/kernel.h> 35#include <linux/kernel.h>
36#include <linux/module.h> 36#include <linux/module.h>
37#include <linux/init.h>
38#include <linux/blkdev.h> 37#include <linux/blkdev.h>
39#include <scsi/scsi_host.h> 38#include <scsi/scsi_host.h>
40#include <linux/ata.h> 39#include <linux/ata.h>
diff --git a/drivers/ata/pata_hpt366.c b/drivers/ata/pata_hpt366.c
index 35b521348d31..8e76f79689d3 100644
--- a/drivers/ata/pata_hpt366.c
+++ b/drivers/ata/pata_hpt366.c
@@ -19,7 +19,6 @@
19#include <linux/kernel.h> 19#include <linux/kernel.h>
20#include <linux/module.h> 20#include <linux/module.h>
21#include <linux/pci.h> 21#include <linux/pci.h>
22#include <linux/init.h>
23#include <linux/blkdev.h> 22#include <linux/blkdev.h>
24#include <linux/delay.h> 23#include <linux/delay.h>
25#include <scsi/scsi_host.h> 24#include <scsi/scsi_host.h>
diff --git a/drivers/ata/pata_hpt37x.c b/drivers/ata/pata_hpt37x.c
index a9d74eff5fc4..3ba843f5cdc0 100644
--- a/drivers/ata/pata_hpt37x.c
+++ b/drivers/ata/pata_hpt37x.c
@@ -19,7 +19,6 @@
19#include <linux/kernel.h> 19#include <linux/kernel.h>
20#include <linux/module.h> 20#include <linux/module.h>
21#include <linux/pci.h> 21#include <linux/pci.h>
22#include <linux/init.h>
23#include <linux/blkdev.h> 22#include <linux/blkdev.h>
24#include <linux/delay.h> 23#include <linux/delay.h>
25#include <scsi/scsi_host.h> 24#include <scsi/scsi_host.h>
diff --git a/drivers/ata/pata_hpt3x2n.c b/drivers/ata/pata_hpt3x2n.c
index 4be0398c153d..b93c0f0729e7 100644
--- a/drivers/ata/pata_hpt3x2n.c
+++ b/drivers/ata/pata_hpt3x2n.c
@@ -20,7 +20,6 @@
20#include <linux/kernel.h> 20#include <linux/kernel.h>
21#include <linux/module.h> 21#include <linux/module.h>
22#include <linux/pci.h> 22#include <linux/pci.h>
23#include <linux/init.h>
24#include <linux/blkdev.h> 23#include <linux/blkdev.h>
25#include <linux/delay.h> 24#include <linux/delay.h>
26#include <scsi/scsi_host.h> 25#include <scsi/scsi_host.h>
diff --git a/drivers/ata/pata_hpt3x3.c b/drivers/ata/pata_hpt3x3.c
index 85cf2861e0b7..255c5aaff3a8 100644
--- a/drivers/ata/pata_hpt3x3.c
+++ b/drivers/ata/pata_hpt3x3.c
@@ -16,7 +16,6 @@
16#include <linux/kernel.h> 16#include <linux/kernel.h>
17#include <linux/module.h> 17#include <linux/module.h>
18#include <linux/pci.h> 18#include <linux/pci.h>
19#include <linux/init.h>
20#include <linux/blkdev.h> 19#include <linux/blkdev.h>
21#include <linux/delay.h> 20#include <linux/delay.h>
22#include <scsi/scsi_host.h> 21#include <scsi/scsi_host.h>
diff --git a/drivers/ata/pata_imx.c b/drivers/ata/pata_imx.c
index b0b18ec5465f..e0872db913d6 100644
--- a/drivers/ata/pata_imx.c
+++ b/drivers/ata/pata_imx.c
@@ -15,7 +15,6 @@
15 */ 15 */
16#include <linux/kernel.h> 16#include <linux/kernel.h>
17#include <linux/module.h> 17#include <linux/module.h>
18#include <linux/init.h>
19#include <linux/blkdev.h> 18#include <linux/blkdev.h>
20#include <scsi/scsi_host.h> 19#include <scsi/scsi_host.h>
21#include <linux/ata.h> 20#include <linux/ata.h>
@@ -100,13 +99,9 @@ static int pata_imx_probe(struct platform_device *pdev)
100 struct resource *io_res; 99 struct resource *io_res;
101 int ret; 100 int ret;
102 101
103 io_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
104 if (io_res == NULL)
105 return -EINVAL;
106
107 irq = platform_get_irq(pdev, 0); 102 irq = platform_get_irq(pdev, 0);
108 if (irq <= 0) 103 if (irq < 0)
109 return -EINVAL; 104 return irq;
110 105
111 priv = devm_kzalloc(&pdev->dev, 106 priv = devm_kzalloc(&pdev->dev,
112 sizeof(struct pata_imx_priv), GFP_KERNEL); 107 sizeof(struct pata_imx_priv), GFP_KERNEL);
@@ -136,11 +131,10 @@ static int pata_imx_probe(struct platform_device *pdev)
136 ap->pio_mask = ATA_PIO0; 131 ap->pio_mask = ATA_PIO0;
137 ap->flags |= ATA_FLAG_SLAVE_POSS; 132 ap->flags |= ATA_FLAG_SLAVE_POSS;
138 133
139 priv->host_regs = devm_ioremap(&pdev->dev, io_res->start, 134 io_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
140 resource_size(io_res)); 135 priv->host_regs = devm_ioremap_resource(&pdev->dev, io_res);
141 if (!priv->host_regs) { 136 if (IS_ERR(priv->host_regs)) {
142 dev_err(&pdev->dev, "failed to map IO/CTL base\n"); 137 ret = PTR_ERR(priv->host_regs);
143 ret = -EBUSY;
144 goto err; 138 goto err;
145 } 139 }
146 140
diff --git a/drivers/ata/pata_it8213.c b/drivers/ata/pata_it8213.c
index 2a8dd9527ecc..81369d187a5c 100644
--- a/drivers/ata/pata_it8213.c
+++ b/drivers/ata/pata_it8213.c
@@ -10,7 +10,6 @@
10#include <linux/kernel.h> 10#include <linux/kernel.h>
11#include <linux/module.h> 11#include <linux/module.h>
12#include <linux/pci.h> 12#include <linux/pci.h>
13#include <linux/init.h>
14#include <linux/blkdev.h> 13#include <linux/blkdev.h>
15#include <linux/delay.h> 14#include <linux/delay.h>
16#include <linux/device.h> 15#include <linux/device.h>
diff --git a/drivers/ata/pata_it821x.c b/drivers/ata/pata_it821x.c
index 581e04d80367..dc3d7877f29d 100644
--- a/drivers/ata/pata_it821x.c
+++ b/drivers/ata/pata_it821x.c
@@ -72,7 +72,6 @@
72#include <linux/kernel.h> 72#include <linux/kernel.h>
73#include <linux/module.h> 73#include <linux/module.h>
74#include <linux/pci.h> 74#include <linux/pci.h>
75#include <linux/init.h>
76#include <linux/blkdev.h> 75#include <linux/blkdev.h>
77#include <linux/delay.h> 76#include <linux/delay.h>
78#include <linux/slab.h> 77#include <linux/slab.h>
diff --git a/drivers/ata/pata_jmicron.c b/drivers/ata/pata_jmicron.c
index 76e739b031b6..b1cfa0258fd3 100644
--- a/drivers/ata/pata_jmicron.c
+++ b/drivers/ata/pata_jmicron.c
@@ -10,7 +10,6 @@
10#include <linux/kernel.h> 10#include <linux/kernel.h>
11#include <linux/module.h> 11#include <linux/module.h>
12#include <linux/pci.h> 12#include <linux/pci.h>
13#include <linux/init.h>
14#include <linux/blkdev.h> 13#include <linux/blkdev.h>
15#include <linux/delay.h> 14#include <linux/delay.h>
16#include <linux/device.h> 15#include <linux/device.h>
diff --git a/drivers/ata/pata_legacy.c b/drivers/ata/pata_legacy.c
index be816428b430..bce2a8ca4678 100644
--- a/drivers/ata/pata_legacy.c
+++ b/drivers/ata/pata_legacy.c
@@ -916,7 +916,6 @@ static __init int probe_chip_type(struct legacy_probe *probe)
916 local_irq_restore(flags); 916 local_irq_restore(flags);
917 return BIOS; 917 return BIOS;
918 } 918 }
919 local_irq_restore(flags);
920 } 919 }
921 920
922 if (ht6560a & mask) 921 if (ht6560a & mask)
diff --git a/drivers/ata/pata_marvell.c b/drivers/ata/pata_marvell.c
index a4f5e781c8c2..6bad3df3a13c 100644
--- a/drivers/ata/pata_marvell.c
+++ b/drivers/ata/pata_marvell.c
@@ -11,7 +11,6 @@
11#include <linux/kernel.h> 11#include <linux/kernel.h>
12#include <linux/module.h> 12#include <linux/module.h>
13#include <linux/pci.h> 13#include <linux/pci.h>
14#include <linux/init.h>
15#include <linux/blkdev.h> 14#include <linux/blkdev.h>
16#include <linux/delay.h> 15#include <linux/delay.h>
17#include <linux/device.h> 16#include <linux/device.h>
diff --git a/drivers/ata/pata_mpiix.c b/drivers/ata/pata_mpiix.c
index 1f5f28bb0bb8..f39a5379e816 100644
--- a/drivers/ata/pata_mpiix.c
+++ b/drivers/ata/pata_mpiix.c
@@ -28,7 +28,6 @@
28#include <linux/kernel.h> 28#include <linux/kernel.h>
29#include <linux/module.h> 29#include <linux/module.h>
30#include <linux/pci.h> 30#include <linux/pci.h>
31#include <linux/init.h>
32#include <linux/blkdev.h> 31#include <linux/blkdev.h>
33#include <linux/delay.h> 32#include <linux/delay.h>
34#include <scsi/scsi_host.h> 33#include <scsi/scsi_host.h>
diff --git a/drivers/ata/pata_netcell.c b/drivers/ata/pata_netcell.c
index ad1a0febd620..e3b97093ef9a 100644
--- a/drivers/ata/pata_netcell.c
+++ b/drivers/ata/pata_netcell.c
@@ -7,7 +7,6 @@
7#include <linux/kernel.h> 7#include <linux/kernel.h>
8#include <linux/module.h> 8#include <linux/module.h>
9#include <linux/pci.h> 9#include <linux/pci.h>
10#include <linux/init.h>
11#include <linux/blkdev.h> 10#include <linux/blkdev.h>
12#include <linux/delay.h> 11#include <linux/delay.h>
13#include <linux/device.h> 12#include <linux/device.h>
diff --git a/drivers/ata/pata_ninja32.c b/drivers/ata/pata_ninja32.c
index 9513e071040d..56201a69af12 100644
--- a/drivers/ata/pata_ninja32.c
+++ b/drivers/ata/pata_ninja32.c
@@ -37,7 +37,6 @@
37#include <linux/kernel.h> 37#include <linux/kernel.h>
38#include <linux/module.h> 38#include <linux/module.h>
39#include <linux/pci.h> 39#include <linux/pci.h>
40#include <linux/init.h>
41#include <linux/blkdev.h> 40#include <linux/blkdev.h>
42#include <linux/delay.h> 41#include <linux/delay.h>
43#include <scsi/scsi_host.h> 42#include <scsi/scsi_host.h>
diff --git a/drivers/ata/pata_ns87410.c b/drivers/ata/pata_ns87410.c
index 0c424dae56e7..6154c3ee11a5 100644
--- a/drivers/ata/pata_ns87410.c
+++ b/drivers/ata/pata_ns87410.c
@@ -20,7 +20,6 @@
20#include <linux/kernel.h> 20#include <linux/kernel.h>
21#include <linux/module.h> 21#include <linux/module.h>
22#include <linux/pci.h> 22#include <linux/pci.h>
23#include <linux/init.h>
24#include <linux/blkdev.h> 23#include <linux/blkdev.h>
25#include <linux/delay.h> 24#include <linux/delay.h>
26#include <scsi/scsi_host.h> 25#include <scsi/scsi_host.h>
diff --git a/drivers/ata/pata_ns87415.c b/drivers/ata/pata_ns87415.c
index 16dc3a63a23d..d44df7ccfe43 100644
--- a/drivers/ata/pata_ns87415.c
+++ b/drivers/ata/pata_ns87415.c
@@ -25,7 +25,6 @@
25#include <linux/kernel.h> 25#include <linux/kernel.h>
26#include <linux/module.h> 26#include <linux/module.h>
27#include <linux/pci.h> 27#include <linux/pci.h>
28#include <linux/init.h>
29#include <linux/blkdev.h> 28#include <linux/blkdev.h>
30#include <linux/delay.h> 29#include <linux/delay.h>
31#include <linux/device.h> 30#include <linux/device.h>
diff --git a/drivers/ata/pata_oldpiix.c b/drivers/ata/pata_oldpiix.c
index d77b2e1054ef..319b64491b7b 100644
--- a/drivers/ata/pata_oldpiix.c
+++ b/drivers/ata/pata_oldpiix.c
@@ -16,7 +16,6 @@
16#include <linux/kernel.h> 16#include <linux/kernel.h>
17#include <linux/module.h> 17#include <linux/module.h>
18#include <linux/pci.h> 18#include <linux/pci.h>
19#include <linux/init.h>
20#include <linux/blkdev.h> 19#include <linux/blkdev.h>
21#include <linux/delay.h> 20#include <linux/delay.h>
22#include <linux/device.h> 21#include <linux/device.h>
diff --git a/drivers/ata/pata_opti.c b/drivers/ata/pata_opti.c
index 4ea70cd22aee..fb042e0519d0 100644
--- a/drivers/ata/pata_opti.c
+++ b/drivers/ata/pata_opti.c
@@ -26,7 +26,6 @@
26#include <linux/kernel.h> 26#include <linux/kernel.h>
27#include <linux/module.h> 27#include <linux/module.h>
28#include <linux/pci.h> 28#include <linux/pci.h>
29#include <linux/init.h>
30#include <linux/blkdev.h> 29#include <linux/blkdev.h>
31#include <linux/delay.h> 30#include <linux/delay.h>
32#include <scsi/scsi_host.h> 31#include <scsi/scsi_host.h>
diff --git a/drivers/ata/pata_optidma.c b/drivers/ata/pata_optidma.c
index 78ede3fd1875..bb71ea214b99 100644
--- a/drivers/ata/pata_optidma.c
+++ b/drivers/ata/pata_optidma.c
@@ -25,7 +25,6 @@
25#include <linux/kernel.h> 25#include <linux/kernel.h>
26#include <linux/module.h> 26#include <linux/module.h>
27#include <linux/pci.h> 27#include <linux/pci.h>
28#include <linux/init.h>
29#include <linux/blkdev.h> 28#include <linux/blkdev.h>
30#include <linux/delay.h> 29#include <linux/delay.h>
31#include <scsi/scsi_host.h> 30#include <scsi/scsi_host.h>
diff --git a/drivers/ata/pata_pcmcia.c b/drivers/ata/pata_pcmcia.c
index 40254f4df584..bcc4b968c049 100644
--- a/drivers/ata/pata_pcmcia.c
+++ b/drivers/ata/pata_pcmcia.c
@@ -26,7 +26,6 @@
26 26
27#include <linux/kernel.h> 27#include <linux/kernel.h>
28#include <linux/module.h> 28#include <linux/module.h>
29#include <linux/init.h>
30#include <linux/blkdev.h> 29#include <linux/blkdev.h>
31#include <linux/delay.h> 30#include <linux/delay.h>
32#include <linux/slab.h> 31#include <linux/slab.h>
diff --git a/drivers/ata/pata_pdc2027x.c b/drivers/ata/pata_pdc2027x.c
index 9d874c85d64d..1151f23177bb 100644
--- a/drivers/ata/pata_pdc2027x.c
+++ b/drivers/ata/pata_pdc2027x.c
@@ -25,7 +25,6 @@
25#include <linux/kernel.h> 25#include <linux/kernel.h>
26#include <linux/module.h> 26#include <linux/module.h>
27#include <linux/pci.h> 27#include <linux/pci.h>
28#include <linux/init.h>
29#include <linux/blkdev.h> 28#include <linux/blkdev.h>
30#include <linux/delay.h> 29#include <linux/delay.h>
31#include <linux/device.h> 30#include <linux/device.h>
diff --git a/drivers/ata/pata_pdc202xx_old.c b/drivers/ata/pata_pdc202xx_old.c
index c34fc50070a6..defa050e1784 100644
--- a/drivers/ata/pata_pdc202xx_old.c
+++ b/drivers/ata/pata_pdc202xx_old.c
@@ -15,7 +15,6 @@
15#include <linux/kernel.h> 15#include <linux/kernel.h>
16#include <linux/module.h> 16#include <linux/module.h>
17#include <linux/pci.h> 17#include <linux/pci.h>
18#include <linux/init.h>
19#include <linux/blkdev.h> 18#include <linux/blkdev.h>
20#include <linux/delay.h> 19#include <linux/delay.h>
21#include <scsi/scsi_host.h> 20#include <scsi/scsi_host.h>
diff --git a/drivers/ata/pata_piccolo.c b/drivers/ata/pata_piccolo.c
index 2beb6b5045f8..0b46be117051 100644
--- a/drivers/ata/pata_piccolo.c
+++ b/drivers/ata/pata_piccolo.c
@@ -18,7 +18,6 @@
18#include <linux/kernel.h> 18#include <linux/kernel.h>
19#include <linux/module.h> 19#include <linux/module.h>
20#include <linux/pci.h> 20#include <linux/pci.h>
21#include <linux/init.h>
22#include <linux/blkdev.h> 21#include <linux/blkdev.h>
23#include <linux/delay.h> 22#include <linux/delay.h>
24#include <scsi/scsi_host.h> 23#include <scsi/scsi_host.h>
diff --git a/drivers/ata/pata_platform.c b/drivers/ata/pata_platform.c
index 02794885de10..a5579b55e332 100644
--- a/drivers/ata/pata_platform.c
+++ b/drivers/ata/pata_platform.c
@@ -13,7 +13,6 @@
13 */ 13 */
14#include <linux/kernel.h> 14#include <linux/kernel.h>
15#include <linux/module.h> 15#include <linux/module.h>
16#include <linux/init.h>
17#include <linux/blkdev.h> 16#include <linux/blkdev.h>
18#include <scsi/scsi_host.h> 17#include <scsi/scsi_host.h>
19#include <linux/ata.h> 18#include <linux/ata.h>
diff --git a/drivers/ata/pata_pxa.c b/drivers/ata/pata_pxa.c
index a6f05acad61e..73259bfda1e3 100644
--- a/drivers/ata/pata_pxa.c
+++ b/drivers/ata/pata_pxa.c
@@ -20,7 +20,6 @@
20 20
21#include <linux/kernel.h> 21#include <linux/kernel.h>
22#include <linux/module.h> 22#include <linux/module.h>
23#include <linux/init.h>
24#include <linux/blkdev.h> 23#include <linux/blkdev.h>
25#include <linux/ata.h> 24#include <linux/ata.h>
26#include <linux/libata.h> 25#include <linux/libata.h>
diff --git a/drivers/ata/pata_radisys.c b/drivers/ata/pata_radisys.c
index f582ba180a7d..be3f10240dca 100644
--- a/drivers/ata/pata_radisys.c
+++ b/drivers/ata/pata_radisys.c
@@ -15,7 +15,6 @@
15#include <linux/kernel.h> 15#include <linux/kernel.h>
16#include <linux/module.h> 16#include <linux/module.h>
17#include <linux/pci.h> 17#include <linux/pci.h>
18#include <linux/init.h>
19#include <linux/blkdev.h> 18#include <linux/blkdev.h>
20#include <linux/delay.h> 19#include <linux/delay.h>
21#include <linux/device.h> 20#include <linux/device.h>
diff --git a/drivers/ata/pata_rdc.c b/drivers/ata/pata_rdc.c
index 79a970f05a2e..521b2137ea3e 100644
--- a/drivers/ata/pata_rdc.c
+++ b/drivers/ata/pata_rdc.c
@@ -24,7 +24,6 @@
24#include <linux/kernel.h> 24#include <linux/kernel.h>
25#include <linux/module.h> 25#include <linux/module.h>
26#include <linux/pci.h> 26#include <linux/pci.h>
27#include <linux/init.h>
28#include <linux/blkdev.h> 27#include <linux/blkdev.h>
29#include <linux/delay.h> 28#include <linux/delay.h>
30#include <linux/device.h> 29#include <linux/device.h>
diff --git a/drivers/ata/pata_rz1000.c b/drivers/ata/pata_rz1000.c
index 040b093617a4..caedc90855b2 100644
--- a/drivers/ata/pata_rz1000.c
+++ b/drivers/ata/pata_rz1000.c
@@ -14,7 +14,6 @@
14#include <linux/kernel.h> 14#include <linux/kernel.h>
15#include <linux/module.h> 15#include <linux/module.h>
16#include <linux/pci.h> 16#include <linux/pci.h>
17#include <linux/init.h>
18#include <linux/blkdev.h> 17#include <linux/blkdev.h>
19#include <linux/delay.h> 18#include <linux/delay.h>
20#include <scsi/scsi_host.h> 19#include <scsi/scsi_host.h>
diff --git a/drivers/ata/pata_sc1200.c b/drivers/ata/pata_sc1200.c
index ce2f828c17b3..96a232fffae6 100644
--- a/drivers/ata/pata_sc1200.c
+++ b/drivers/ata/pata_sc1200.c
@@ -32,7 +32,6 @@
32#include <linux/kernel.h> 32#include <linux/kernel.h>
33#include <linux/module.h> 33#include <linux/module.h>
34#include <linux/pci.h> 34#include <linux/pci.h>
35#include <linux/init.h>
36#include <linux/blkdev.h> 35#include <linux/blkdev.h>
37#include <linux/delay.h> 36#include <linux/delay.h>
38#include <scsi/scsi_host.h> 37#include <scsi/scsi_host.h>
diff --git a/drivers/ata/pata_scc.c b/drivers/ata/pata_scc.c
index f35f15f4d83e..f1f5b5ae3382 100644
--- a/drivers/ata/pata_scc.c
+++ b/drivers/ata/pata_scc.c
@@ -35,7 +35,6 @@
35#include <linux/kernel.h> 35#include <linux/kernel.h>
36#include <linux/module.h> 36#include <linux/module.h>
37#include <linux/pci.h> 37#include <linux/pci.h>
38#include <linux/init.h>
39#include <linux/blkdev.h> 38#include <linux/blkdev.h>
40#include <linux/delay.h> 39#include <linux/delay.h>
41#include <linux/device.h> 40#include <linux/device.h>
diff --git a/drivers/ata/pata_sch.c b/drivers/ata/pata_sch.c
index d3830c45a369..5a1cde0ea360 100644
--- a/drivers/ata/pata_sch.c
+++ b/drivers/ata/pata_sch.c
@@ -27,7 +27,6 @@
27#include <linux/kernel.h> 27#include <linux/kernel.h>
28#include <linux/module.h> 28#include <linux/module.h>
29#include <linux/pci.h> 29#include <linux/pci.h>
30#include <linux/init.h>
31#include <linux/blkdev.h> 30#include <linux/blkdev.h>
32#include <linux/delay.h> 31#include <linux/delay.h>
33#include <linux/device.h> 32#include <linux/device.h>
diff --git a/drivers/ata/pata_serverworks.c b/drivers/ata/pata_serverworks.c
index 96c6a79ef606..e27f31fe1b67 100644
--- a/drivers/ata/pata_serverworks.c
+++ b/drivers/ata/pata_serverworks.c
@@ -34,7 +34,6 @@
34#include <linux/kernel.h> 34#include <linux/kernel.h>
35#include <linux/module.h> 35#include <linux/module.h>
36#include <linux/pci.h> 36#include <linux/pci.h>
37#include <linux/init.h>
38#include <linux/blkdev.h> 37#include <linux/blkdev.h>
39#include <linux/delay.h> 38#include <linux/delay.h>
40#include <scsi/scsi_host.h> 39#include <scsi/scsi_host.h>
diff --git a/drivers/ata/pata_sil680.c b/drivers/ata/pata_sil680.c
index c4b0b073ba8e..73fe362d9716 100644
--- a/drivers/ata/pata_sil680.c
+++ b/drivers/ata/pata_sil680.c
@@ -25,7 +25,6 @@
25#include <linux/kernel.h> 25#include <linux/kernel.h>
26#include <linux/module.h> 26#include <linux/module.h>
27#include <linux/pci.h> 27#include <linux/pci.h>
28#include <linux/init.h>
29#include <linux/blkdev.h> 28#include <linux/blkdev.h>
30#include <linux/delay.h> 29#include <linux/delay.h>
31#include <scsi/scsi_host.h> 30#include <scsi/scsi_host.h>
diff --git a/drivers/ata/pata_sis.c b/drivers/ata/pata_sis.c
index 1e8363640bf5..78d913aa93c8 100644
--- a/drivers/ata/pata_sis.c
+++ b/drivers/ata/pata_sis.c
@@ -26,7 +26,6 @@
26#include <linux/kernel.h> 26#include <linux/kernel.h>
27#include <linux/module.h> 27#include <linux/module.h>
28#include <linux/pci.h> 28#include <linux/pci.h>
29#include <linux/init.h>
30#include <linux/blkdev.h> 29#include <linux/blkdev.h>
31#include <linux/delay.h> 30#include <linux/delay.h>
32#include <linux/device.h> 31#include <linux/device.h>
diff --git a/drivers/ata/pata_sl82c105.c b/drivers/ata/pata_sl82c105.c
index 6816911ac422..900f0e4a1faf 100644
--- a/drivers/ata/pata_sl82c105.c
+++ b/drivers/ata/pata_sl82c105.c
@@ -19,7 +19,6 @@
19#include <linux/kernel.h> 19#include <linux/kernel.h>
20#include <linux/module.h> 20#include <linux/module.h>
21#include <linux/pci.h> 21#include <linux/pci.h>
22#include <linux/init.h>
23#include <linux/blkdev.h> 22#include <linux/blkdev.h>
24#include <linux/delay.h> 23#include <linux/delay.h>
25#include <scsi/scsi_host.h> 24#include <scsi/scsi_host.h>
diff --git a/drivers/ata/pata_triflex.c b/drivers/ata/pata_triflex.c
index 94473da68c02..7bc78e264f9e 100644
--- a/drivers/ata/pata_triflex.c
+++ b/drivers/ata/pata_triflex.c
@@ -36,7 +36,6 @@
36#include <linux/kernel.h> 36#include <linux/kernel.h>
37#include <linux/module.h> 37#include <linux/module.h>
38#include <linux/pci.h> 38#include <linux/pci.h>
39#include <linux/init.h>
40#include <linux/blkdev.h> 39#include <linux/blkdev.h>
41#include <linux/delay.h> 40#include <linux/delay.h>
42#include <scsi/scsi_host.h> 41#include <scsi/scsi_host.h>
diff --git a/drivers/ata/pata_via.c b/drivers/ata/pata_via.c
index c3ab9a6c3965..f6c9632bdff6 100644
--- a/drivers/ata/pata_via.c
+++ b/drivers/ata/pata_via.c
@@ -55,7 +55,6 @@
55#include <linux/kernel.h> 55#include <linux/kernel.h>
56#include <linux/module.h> 56#include <linux/module.h>
57#include <linux/pci.h> 57#include <linux/pci.h>
58#include <linux/init.h>
59#include <linux/blkdev.h> 58#include <linux/blkdev.h>
60#include <linux/delay.h> 59#include <linux/delay.h>
61#include <linux/gfp.h> 60#include <linux/gfp.h>
diff --git a/drivers/ata/pdc_adma.c b/drivers/ata/pdc_adma.c
index 8ea6e6afd041..f10631beffa8 100644
--- a/drivers/ata/pdc_adma.c
+++ b/drivers/ata/pdc_adma.c
@@ -36,7 +36,6 @@
36#include <linux/module.h> 36#include <linux/module.h>
37#include <linux/gfp.h> 37#include <linux/gfp.h>
38#include <linux/pci.h> 38#include <linux/pci.h>
39#include <linux/init.h>
40#include <linux/blkdev.h> 39#include <linux/blkdev.h>
41#include <linux/delay.h> 40#include <linux/delay.h>
42#include <linux/interrupt.h> 41#include <linux/interrupt.h>
diff --git a/drivers/ata/sata_dwc_460ex.c b/drivers/ata/sata_dwc_460ex.c
index 523524b68022..0bb2cabd2197 100644
--- a/drivers/ata/sata_dwc_460ex.c
+++ b/drivers/ata/sata_dwc_460ex.c
@@ -29,7 +29,6 @@
29 29
30#include <linux/kernel.h> 30#include <linux/kernel.h>
31#include <linux/module.h> 31#include <linux/module.h>
32#include <linux/init.h>
33#include <linux/device.h> 32#include <linux/device.h>
34#include <linux/of_address.h> 33#include <linux/of_address.h>
35#include <linux/of_irq.h> 34#include <linux/of_irq.h>
@@ -462,8 +461,7 @@ static irqreturn_t dma_dwc_interrupt(int irq, void *hsdev_instance)
462 int chan; 461 int chan;
463 u32 tfr_reg, err_reg; 462 u32 tfr_reg, err_reg;
464 unsigned long flags; 463 unsigned long flags;
465 struct sata_dwc_device *hsdev = 464 struct sata_dwc_device *hsdev = hsdev_instance;
466 (struct sata_dwc_device *)hsdev_instance;
467 struct ata_host *host = (struct ata_host *)hsdev->host; 465 struct ata_host *host = (struct ata_host *)hsdev->host;
468 struct ata_port *ap; 466 struct ata_port *ap;
469 struct sata_dwc_device_port *hsdevp; 467 struct sata_dwc_device_port *hsdevp;
diff --git a/drivers/ata/sata_highbank.c b/drivers/ata/sata_highbank.c
index 870b11eadc6d..65965cf5af06 100644
--- a/drivers/ata/sata_highbank.c
+++ b/drivers/ata/sata_highbank.c
@@ -19,7 +19,6 @@
19#include <linux/kernel.h> 19#include <linux/kernel.h>
20#include <linux/gfp.h> 20#include <linux/gfp.h>
21#include <linux/module.h> 21#include <linux/module.h>
22#include <linux/init.h>
23#include <linux/types.h> 22#include <linux/types.h>
24#include <linux/err.h> 23#include <linux/err.h>
25#include <linux/io.h> 24#include <linux/io.h>
@@ -142,7 +141,7 @@ static ssize_t ecx_transmit_led_message(struct ata_port *ap, u32 state,
142 ssize_t size) 141 ssize_t size)
143{ 142{
144 struct ahci_host_priv *hpriv = ap->host->private_data; 143 struct ahci_host_priv *hpriv = ap->host->private_data;
145 struct ecx_plat_data *pdata = (struct ecx_plat_data *) hpriv->plat_data; 144 struct ecx_plat_data *pdata = hpriv->plat_data;
146 struct ahci_port_priv *pp = ap->private_data; 145 struct ahci_port_priv *pp = ap->private_data;
147 unsigned long flags; 146 unsigned long flags;
148 int pmp, i; 147 int pmp, i;
@@ -403,6 +402,7 @@ static int ahci_highbank_hardreset(struct ata_link *link, unsigned int *class,
403 static const unsigned long timing[] = { 5, 100, 500}; 402 static const unsigned long timing[] = { 5, 100, 500};
404 struct ata_port *ap = link->ap; 403 struct ata_port *ap = link->ap;
405 struct ahci_port_priv *pp = ap->private_data; 404 struct ahci_port_priv *pp = ap->private_data;
405 struct ahci_host_priv *hpriv = ap->host->private_data;
406 u8 *d2h_fis = pp->rx_fis + RX_FIS_D2H_REG; 406 u8 *d2h_fis = pp->rx_fis + RX_FIS_D2H_REG;
407 struct ata_taskfile tf; 407 struct ata_taskfile tf;
408 bool online; 408 bool online;
@@ -431,7 +431,7 @@ static int ahci_highbank_hardreset(struct ata_link *link, unsigned int *class,
431 break; 431 break;
432 } while (!online && retry--); 432 } while (!online && retry--);
433 433
434 ahci_start_engine(ap); 434 hpriv->start_engine(ap);
435 435
436 if (online) 436 if (online)
437 *class = ahci_dev_classify(ap); 437 *class = ahci_dev_classify(ap);
diff --git a/drivers/ata/sata_nv.c b/drivers/ata/sata_nv.c
index d74def823d3e..ba5f27120332 100644
--- a/drivers/ata/sata_nv.c
+++ b/drivers/ata/sata_nv.c
@@ -40,7 +40,6 @@
40#include <linux/module.h> 40#include <linux/module.h>
41#include <linux/gfp.h> 41#include <linux/gfp.h>
42#include <linux/pci.h> 42#include <linux/pci.h>
43#include <linux/init.h>
44#include <linux/blkdev.h> 43#include <linux/blkdev.h>
45#include <linux/delay.h> 44#include <linux/delay.h>
46#include <linux/interrupt.h> 45#include <linux/interrupt.h>
diff --git a/drivers/ata/sata_promise.c b/drivers/ata/sata_promise.c
index 97f4acb54ad6..3638887476f6 100644
--- a/drivers/ata/sata_promise.c
+++ b/drivers/ata/sata_promise.c
@@ -35,7 +35,6 @@
35#include <linux/module.h> 35#include <linux/module.h>
36#include <linux/gfp.h> 36#include <linux/gfp.h>
37#include <linux/pci.h> 37#include <linux/pci.h>
38#include <linux/init.h>
39#include <linux/blkdev.h> 38#include <linux/blkdev.h>
40#include <linux/delay.h> 39#include <linux/delay.h>
41#include <linux/interrupt.h> 40#include <linux/interrupt.h>
diff --git a/drivers/ata/sata_qstor.c b/drivers/ata/sata_qstor.c
index 3b0dd57984e1..9a6bd4cd29a0 100644
--- a/drivers/ata/sata_qstor.c
+++ b/drivers/ata/sata_qstor.c
@@ -31,7 +31,6 @@
31#include <linux/module.h> 31#include <linux/module.h>
32#include <linux/gfp.h> 32#include <linux/gfp.h>
33#include <linux/pci.h> 33#include <linux/pci.h>
34#include <linux/init.h>
35#include <linux/blkdev.h> 34#include <linux/blkdev.h>
36#include <linux/delay.h> 35#include <linux/delay.h>
37#include <linux/interrupt.h> 36#include <linux/interrupt.h>
diff --git a/drivers/ata/sata_sil.c b/drivers/ata/sata_sil.c
index b7695e804635..3062f8605b29 100644
--- a/drivers/ata/sata_sil.c
+++ b/drivers/ata/sata_sil.c
@@ -37,7 +37,6 @@
37#include <linux/kernel.h> 37#include <linux/kernel.h>
38#include <linux/module.h> 38#include <linux/module.h>
39#include <linux/pci.h> 39#include <linux/pci.h>
40#include <linux/init.h>
41#include <linux/blkdev.h> 40#include <linux/blkdev.h>
42#include <linux/delay.h> 41#include <linux/delay.h>
43#include <linux/interrupt.h> 42#include <linux/interrupt.h>
diff --git a/drivers/ata/sata_sis.c b/drivers/ata/sata_sis.c
index 1ad2f62d34b9..b513428171b3 100644
--- a/drivers/ata/sata_sis.c
+++ b/drivers/ata/sata_sis.c
@@ -33,7 +33,6 @@
33#include <linux/kernel.h> 33#include <linux/kernel.h>
34#include <linux/module.h> 34#include <linux/module.h>
35#include <linux/pci.h> 35#include <linux/pci.h>
36#include <linux/init.h>
37#include <linux/blkdev.h> 36#include <linux/blkdev.h>
38#include <linux/delay.h> 37#include <linux/delay.h>
39#include <linux/interrupt.h> 38#include <linux/interrupt.h>
diff --git a/drivers/ata/sata_svw.c b/drivers/ata/sata_svw.c
index dc4f70179e7d..c630fa812624 100644
--- a/drivers/ata/sata_svw.c
+++ b/drivers/ata/sata_svw.c
@@ -39,7 +39,6 @@
39#include <linux/kernel.h> 39#include <linux/kernel.h>
40#include <linux/module.h> 40#include <linux/module.h>
41#include <linux/pci.h> 41#include <linux/pci.h>
42#include <linux/init.h>
43#include <linux/blkdev.h> 42#include <linux/blkdev.h>
44#include <linux/delay.h> 43#include <linux/delay.h>
45#include <linux/interrupt.h> 44#include <linux/interrupt.h>
diff --git a/drivers/ata/sata_sx4.c b/drivers/ata/sata_sx4.c
index 9947010afc0f..39b5de60a1f9 100644
--- a/drivers/ata/sata_sx4.c
+++ b/drivers/ata/sata_sx4.c
@@ -82,7 +82,6 @@
82#include <linux/module.h> 82#include <linux/module.h>
83#include <linux/pci.h> 83#include <linux/pci.h>
84#include <linux/slab.h> 84#include <linux/slab.h>
85#include <linux/init.h>
86#include <linux/blkdev.h> 85#include <linux/blkdev.h>
87#include <linux/delay.h> 86#include <linux/delay.h>
88#include <linux/interrupt.h> 87#include <linux/interrupt.h>
@@ -1021,8 +1020,7 @@ static void pdc20621_get_from_dimm(struct ata_host *host, void *psource,
1021 idx++; 1020 idx++;
1022 dist = ((long) (window_size - (offset + size))) >= 0 ? size : 1021 dist = ((long) (window_size - (offset + size))) >= 0 ? size :
1023 (long) (window_size - offset); 1022 (long) (window_size - offset);
1024 memcpy_fromio((char *) psource, (char *) (dimm_mmio + offset / 4), 1023 memcpy_fromio(psource, dimm_mmio + offset / 4, dist);
1025 dist);
1026 1024
1027 psource += dist; 1025 psource += dist;
1028 size -= dist; 1026 size -= dist;
@@ -1031,8 +1029,7 @@ static void pdc20621_get_from_dimm(struct ata_host *host, void *psource,
1031 readl(mmio + PDC_GENERAL_CTLR); 1029 readl(mmio + PDC_GENERAL_CTLR);
1032 writel(((idx) << page_mask), mmio + PDC_DIMM_WINDOW_CTLR); 1030 writel(((idx) << page_mask), mmio + PDC_DIMM_WINDOW_CTLR);
1033 readl(mmio + PDC_DIMM_WINDOW_CTLR); 1031 readl(mmio + PDC_DIMM_WINDOW_CTLR);
1034 memcpy_fromio((char *) psource, (char *) (dimm_mmio), 1032 memcpy_fromio(psource, dimm_mmio, window_size / 4);
1035 window_size / 4);
1036 psource += window_size; 1033 psource += window_size;
1037 size -= window_size; 1034 size -= window_size;
1038 idx++; 1035 idx++;
@@ -1043,8 +1040,7 @@ static void pdc20621_get_from_dimm(struct ata_host *host, void *psource,
1043 readl(mmio + PDC_GENERAL_CTLR); 1040 readl(mmio + PDC_GENERAL_CTLR);
1044 writel(((idx) << page_mask), mmio + PDC_DIMM_WINDOW_CTLR); 1041 writel(((idx) << page_mask), mmio + PDC_DIMM_WINDOW_CTLR);
1045 readl(mmio + PDC_DIMM_WINDOW_CTLR); 1042 readl(mmio + PDC_DIMM_WINDOW_CTLR);
1046 memcpy_fromio((char *) psource, (char *) (dimm_mmio), 1043 memcpy_fromio(psource, dimm_mmio, size / 4);
1047 size / 4);
1048 } 1044 }
1049} 1045}
1050#endif 1046#endif
diff --git a/drivers/ata/sata_uli.c b/drivers/ata/sata_uli.c
index 6d6489118873..08f98c3ed5c8 100644
--- a/drivers/ata/sata_uli.c
+++ b/drivers/ata/sata_uli.c
@@ -28,7 +28,6 @@
28#include <linux/module.h> 28#include <linux/module.h>
29#include <linux/gfp.h> 29#include <linux/gfp.h>
30#include <linux/pci.h> 30#include <linux/pci.h>
31#include <linux/init.h>
32#include <linux/blkdev.h> 31#include <linux/blkdev.h>
33#include <linux/delay.h> 32#include <linux/delay.h>
34#include <linux/interrupt.h> 33#include <linux/interrupt.h>
diff --git a/drivers/ata/sata_via.c b/drivers/ata/sata_via.c
index 87f056e54a9d..f72e84228c5c 100644
--- a/drivers/ata/sata_via.c
+++ b/drivers/ata/sata_via.c
@@ -36,7 +36,6 @@
36#include <linux/kernel.h> 36#include <linux/kernel.h>
37#include <linux/module.h> 37#include <linux/module.h>
38#include <linux/pci.h> 38#include <linux/pci.h>
39#include <linux/init.h>
40#include <linux/blkdev.h> 39#include <linux/blkdev.h>
41#include <linux/delay.h> 40#include <linux/delay.h>
42#include <linux/device.h> 41#include <linux/device.h>
diff --git a/drivers/ata/sata_vsc.c b/drivers/ata/sata_vsc.c
index 44f304b3de63..29e847aac34b 100644
--- a/drivers/ata/sata_vsc.c
+++ b/drivers/ata/sata_vsc.c
@@ -37,7 +37,6 @@
37#include <linux/kernel.h> 37#include <linux/kernel.h>
38#include <linux/module.h> 38#include <linux/module.h>
39#include <linux/pci.h> 39#include <linux/pci.h>
40#include <linux/init.h>
41#include <linux/blkdev.h> 40#include <linux/blkdev.h>
42#include <linux/delay.h> 41#include <linux/delay.h>
43#include <linux/interrupt.h> 42#include <linux/interrupt.h>
diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
index 8a97ddfa6122..c30df50e4440 100644
--- a/drivers/base/firmware_class.c
+++ b/drivers/base/firmware_class.c
@@ -1580,6 +1580,7 @@ static int fw_pm_notify(struct notifier_block *notify_block,
1580 switch (mode) { 1580 switch (mode) {
1581 case PM_HIBERNATION_PREPARE: 1581 case PM_HIBERNATION_PREPARE:
1582 case PM_SUSPEND_PREPARE: 1582 case PM_SUSPEND_PREPARE:
1583 case PM_RESTORE_PREPARE:
1583 kill_requests_without_uevent(); 1584 kill_requests_without_uevent();
1584 device_cache_fw_images(); 1585 device_cache_fw_images();
1585 break; 1586 break;
diff --git a/drivers/block/aoe/aoecmd.c b/drivers/block/aoe/aoecmd.c
index 8184451b57c0..422b7d84f686 100644
--- a/drivers/block/aoe/aoecmd.c
+++ b/drivers/block/aoe/aoecmd.c
@@ -874,7 +874,7 @@ bio_pageinc(struct bio *bio)
874 /* Non-zero page count for non-head members of 874 /* Non-zero page count for non-head members of
875 * compound pages is no longer allowed by the kernel. 875 * compound pages is no longer allowed by the kernel.
876 */ 876 */
877 page = compound_trans_head(bv.bv_page); 877 page = compound_head(bv.bv_page);
878 atomic_inc(&page->_count); 878 atomic_inc(&page->_count);
879 } 879 }
880} 880}
@@ -887,7 +887,7 @@ bio_pagedec(struct bio *bio)
887 struct bvec_iter iter; 887 struct bvec_iter iter;
888 888
889 bio_for_each_segment(bv, bio, iter) { 889 bio_for_each_segment(bv, bio, iter) {
890 page = compound_trans_head(bv.bv_page); 890 page = compound_head(bv.bv_page);
891 atomic_dec(&page->_count); 891 atomic_dec(&page->_count);
892 } 892 }
893} 893}
diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index 2023043ce7c0..8f5565bf34cd 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -961,17 +961,31 @@ static void empty(void)
961{ 961{
962} 962}
963 963
964static DECLARE_WORK(floppy_work, NULL); 964static void (*floppy_work_fn)(void);
965
966static void floppy_work_workfn(struct work_struct *work)
967{
968 floppy_work_fn();
969}
970
971static DECLARE_WORK(floppy_work, floppy_work_workfn);
965 972
966static void schedule_bh(void (*handler)(void)) 973static void schedule_bh(void (*handler)(void))
967{ 974{
968 WARN_ON(work_pending(&floppy_work)); 975 WARN_ON(work_pending(&floppy_work));
969 976
970 PREPARE_WORK(&floppy_work, (work_func_t)handler); 977 floppy_work_fn = handler;
971 queue_work(floppy_wq, &floppy_work); 978 queue_work(floppy_wq, &floppy_work);
972} 979}
973 980
974static DECLARE_DELAYED_WORK(fd_timer, NULL); 981static void (*fd_timer_fn)(void) = NULL;
982
983static void fd_timer_workfn(struct work_struct *work)
984{
985 fd_timer_fn();
986}
987
988static DECLARE_DELAYED_WORK(fd_timer, fd_timer_workfn);
975 989
976static void cancel_activity(void) 990static void cancel_activity(void)
977{ 991{
@@ -982,7 +996,7 @@ static void cancel_activity(void)
982 996
983/* this function makes sure that the disk stays in the drive during the 997/* this function makes sure that the disk stays in the drive during the
984 * transfer */ 998 * transfer */
985static void fd_watchdog(struct work_struct *arg) 999static void fd_watchdog(void)
986{ 1000{
987 debug_dcl(DP->flags, "calling disk change from watchdog\n"); 1001 debug_dcl(DP->flags, "calling disk change from watchdog\n");
988 1002
@@ -993,7 +1007,7 @@ static void fd_watchdog(struct work_struct *arg)
993 reset_fdc(); 1007 reset_fdc();
994 } else { 1008 } else {
995 cancel_delayed_work(&fd_timer); 1009 cancel_delayed_work(&fd_timer);
996 PREPARE_DELAYED_WORK(&fd_timer, fd_watchdog); 1010 fd_timer_fn = fd_watchdog;
997 queue_delayed_work(floppy_wq, &fd_timer, HZ / 10); 1011 queue_delayed_work(floppy_wq, &fd_timer, HZ / 10);
998 } 1012 }
999} 1013}
@@ -1005,7 +1019,8 @@ static void main_command_interrupt(void)
1005} 1019}
1006 1020
1007/* waits for a delay (spinup or select) to pass */ 1021/* waits for a delay (spinup or select) to pass */
1008static int fd_wait_for_completion(unsigned long expires, work_func_t function) 1022static int fd_wait_for_completion(unsigned long expires,
1023 void (*function)(void))
1009{ 1024{
1010 if (FDCS->reset) { 1025 if (FDCS->reset) {
1011 reset_fdc(); /* do the reset during sleep to win time 1026 reset_fdc(); /* do the reset during sleep to win time
@@ -1016,7 +1031,7 @@ static int fd_wait_for_completion(unsigned long expires, work_func_t function)
1016 1031
1017 if (time_before(jiffies, expires)) { 1032 if (time_before(jiffies, expires)) {
1018 cancel_delayed_work(&fd_timer); 1033 cancel_delayed_work(&fd_timer);
1019 PREPARE_DELAYED_WORK(&fd_timer, function); 1034 fd_timer_fn = function;
1020 queue_delayed_work(floppy_wq, &fd_timer, expires - jiffies); 1035 queue_delayed_work(floppy_wq, &fd_timer, expires - jiffies);
1021 return 1; 1036 return 1;
1022 } 1037 }
@@ -1334,8 +1349,7 @@ static int fdc_dtr(void)
1334 * Pause 5 msec to avoid trouble. (Needs to be 2 jiffies) 1349 * Pause 5 msec to avoid trouble. (Needs to be 2 jiffies)
1335 */ 1350 */
1336 FDCS->dtr = raw_cmd->rate & 3; 1351 FDCS->dtr = raw_cmd->rate & 3;
1337 return fd_wait_for_completion(jiffies + 2UL * HZ / 100, 1352 return fd_wait_for_completion(jiffies + 2UL * HZ / 100, floppy_ready);
1338 (work_func_t)floppy_ready);
1339} /* fdc_dtr */ 1353} /* fdc_dtr */
1340 1354
1341static void tell_sector(void) 1355static void tell_sector(void)
@@ -1440,7 +1454,7 @@ static void setup_rw_floppy(void)
1440 int flags; 1454 int flags;
1441 int dflags; 1455 int dflags;
1442 unsigned long ready_date; 1456 unsigned long ready_date;
1443 work_func_t function; 1457 void (*function)(void);
1444 1458
1445 flags = raw_cmd->flags; 1459 flags = raw_cmd->flags;
1446 if (flags & (FD_RAW_READ | FD_RAW_WRITE)) 1460 if (flags & (FD_RAW_READ | FD_RAW_WRITE))
@@ -1454,9 +1468,9 @@ static void setup_rw_floppy(void)
1454 */ 1468 */
1455 if (time_after(ready_date, jiffies + DP->select_delay)) { 1469 if (time_after(ready_date, jiffies + DP->select_delay)) {
1456 ready_date -= DP->select_delay; 1470 ready_date -= DP->select_delay;
1457 function = (work_func_t)floppy_start; 1471 function = floppy_start;
1458 } else 1472 } else
1459 function = (work_func_t)setup_rw_floppy; 1473 function = setup_rw_floppy;
1460 1474
1461 /* wait until the floppy is spinning fast enough */ 1475 /* wait until the floppy is spinning fast enough */
1462 if (fd_wait_for_completion(ready_date, function)) 1476 if (fd_wait_for_completion(ready_date, function))
@@ -1486,7 +1500,7 @@ static void setup_rw_floppy(void)
1486 inr = result(); 1500 inr = result();
1487 cont->interrupt(); 1501 cont->interrupt();
1488 } else if (flags & FD_RAW_NEED_DISK) 1502 } else if (flags & FD_RAW_NEED_DISK)
1489 fd_watchdog(NULL); 1503 fd_watchdog();
1490} 1504}
1491 1505
1492static int blind_seek; 1506static int blind_seek;
@@ -1863,7 +1877,7 @@ static int start_motor(void (*function)(void))
1863 1877
1864 /* wait_for_completion also schedules reset if needed. */ 1878 /* wait_for_completion also schedules reset if needed. */
1865 return fd_wait_for_completion(DRS->select_date + DP->select_delay, 1879 return fd_wait_for_completion(DRS->select_date + DP->select_delay,
1866 (work_func_t)function); 1880 function);
1867} 1881}
1868 1882
1869static void floppy_ready(void) 1883static void floppy_ready(void)
diff --git a/drivers/block/mtip32xx/mtip32xx.c b/drivers/block/mtip32xx/mtip32xx.c
index 516026954be6..d777bb7cea93 100644
--- a/drivers/block/mtip32xx/mtip32xx.c
+++ b/drivers/block/mtip32xx/mtip32xx.c
@@ -4498,7 +4498,7 @@ static int mtip_pci_probe(struct pci_dev *pdev,
4498 } 4498 }
4499 dev_info(&pdev->dev, "NUMA node %d (closest: %d,%d, probe on %d:%d)\n", 4499 dev_info(&pdev->dev, "NUMA node %d (closest: %d,%d, probe on %d:%d)\n",
4500 my_node, pcibus_to_node(pdev->bus), dev_to_node(&pdev->dev), 4500 my_node, pcibus_to_node(pdev->bus), dev_to_node(&pdev->dev),
4501 cpu_to_node(smp_processor_id()), smp_processor_id()); 4501 cpu_to_node(raw_smp_processor_id()), raw_smp_processor_id());
4502 4502
4503 dd = kzalloc_node(sizeof(struct driver_data), GFP_KERNEL, my_node); 4503 dd = kzalloc_node(sizeof(struct driver_data), GFP_KERNEL, my_node);
4504 if (dd == NULL) { 4504 if (dd == NULL) {
diff --git a/drivers/block/mtip32xx/mtip32xx.h b/drivers/block/mtip32xx/mtip32xx.h
index b52e9a6d6aad..54174cb32feb 100644
--- a/drivers/block/mtip32xx/mtip32xx.h
+++ b/drivers/block/mtip32xx/mtip32xx.h
@@ -53,7 +53,7 @@
53#define MTIP_FTL_REBUILD_TIMEOUT_MS 2400000 53#define MTIP_FTL_REBUILD_TIMEOUT_MS 2400000
54 54
55/* unaligned IO handling */ 55/* unaligned IO handling */
56#define MTIP_MAX_UNALIGNED_SLOTS 8 56#define MTIP_MAX_UNALIGNED_SLOTS 2
57 57
58/* Macro to extract the tag bit number from a tag value. */ 58/* Macro to extract the tag bit number from a tag value. */
59#define MTIP_TAG_BIT(tag) (tag & 0x1F) 59#define MTIP_TAG_BIT(tag) (tag & 0x1F)
diff --git a/drivers/block/nvme-core.c b/drivers/block/nvme-core.c
index 51824d1f23ea..8459e4e7c719 100644
--- a/drivers/block/nvme-core.c
+++ b/drivers/block/nvme-core.c
@@ -993,7 +993,7 @@ static void nvme_abort_cmd(int cmdid, struct nvme_queue *nvmeq)
993 dev_warn(&dev->pci_dev->dev, 993 dev_warn(&dev->pci_dev->dev,
994 "I/O %d QID %d timeout, reset controller\n", cmdid, 994 "I/O %d QID %d timeout, reset controller\n", cmdid,
995 nvmeq->qid); 995 nvmeq->qid);
996 PREPARE_WORK(&dev->reset_work, nvme_reset_failed_dev); 996 dev->reset_workfn = nvme_reset_failed_dev;
997 queue_work(nvme_workq, &dev->reset_work); 997 queue_work(nvme_workq, &dev->reset_work);
998 return; 998 return;
999 } 999 }
@@ -1696,8 +1696,7 @@ static int nvme_kthread(void *data)
1696 list_del_init(&dev->node); 1696 list_del_init(&dev->node);
1697 dev_warn(&dev->pci_dev->dev, 1697 dev_warn(&dev->pci_dev->dev,
1698 "Failed status, reset controller\n"); 1698 "Failed status, reset controller\n");
1699 PREPARE_WORK(&dev->reset_work, 1699 dev->reset_workfn = nvme_reset_failed_dev;
1700 nvme_reset_failed_dev);
1701 queue_work(nvme_workq, &dev->reset_work); 1700 queue_work(nvme_workq, &dev->reset_work);
1702 continue; 1701 continue;
1703 } 1702 }
@@ -2406,7 +2405,7 @@ static int nvme_dev_resume(struct nvme_dev *dev)
2406 return ret; 2405 return ret;
2407 if (ret == -EBUSY) { 2406 if (ret == -EBUSY) {
2408 spin_lock(&dev_list_lock); 2407 spin_lock(&dev_list_lock);
2409 PREPARE_WORK(&dev->reset_work, nvme_remove_disks); 2408 dev->reset_workfn = nvme_remove_disks;
2410 queue_work(nvme_workq, &dev->reset_work); 2409 queue_work(nvme_workq, &dev->reset_work);
2411 spin_unlock(&dev_list_lock); 2410 spin_unlock(&dev_list_lock);
2412 } 2411 }
@@ -2435,6 +2434,12 @@ static void nvme_reset_failed_dev(struct work_struct *ws)
2435 nvme_dev_reset(dev); 2434 nvme_dev_reset(dev);
2436} 2435}
2437 2436
2437static void nvme_reset_workfn(struct work_struct *work)
2438{
2439 struct nvme_dev *dev = container_of(work, struct nvme_dev, reset_work);
2440 dev->reset_workfn(work);
2441}
2442
2438static int nvme_probe(struct pci_dev *pdev, const struct pci_device_id *id) 2443static int nvme_probe(struct pci_dev *pdev, const struct pci_device_id *id)
2439{ 2444{
2440 int result = -ENOMEM; 2445 int result = -ENOMEM;
@@ -2453,7 +2458,8 @@ static int nvme_probe(struct pci_dev *pdev, const struct pci_device_id *id)
2453 goto free; 2458 goto free;
2454 2459
2455 INIT_LIST_HEAD(&dev->namespaces); 2460 INIT_LIST_HEAD(&dev->namespaces);
2456 INIT_WORK(&dev->reset_work, nvme_reset_failed_dev); 2461 dev->reset_workfn = nvme_reset_failed_dev;
2462 INIT_WORK(&dev->reset_work, nvme_reset_workfn);
2457 dev->pci_dev = pdev; 2463 dev->pci_dev = pdev;
2458 pci_set_drvdata(pdev, dev); 2464 pci_set_drvdata(pdev, dev);
2459 result = nvme_set_instance(dev); 2465 result = nvme_set_instance(dev);
@@ -2553,7 +2559,7 @@ static int nvme_resume(struct device *dev)
2553 struct nvme_dev *ndev = pci_get_drvdata(pdev); 2559 struct nvme_dev *ndev = pci_get_drvdata(pdev);
2554 2560
2555 if (nvme_dev_resume(ndev) && !work_busy(&ndev->reset_work)) { 2561 if (nvme_dev_resume(ndev) && !work_busy(&ndev->reset_work)) {
2556 PREPARE_WORK(&ndev->reset_work, nvme_reset_failed_dev); 2562 ndev->reset_workfn = nvme_reset_failed_dev;
2557 queue_work(nvme_workq, &ndev->reset_work); 2563 queue_work(nvme_workq, &ndev->reset_work);
2558 } 2564 }
2559 return 0; 2565 return 0;
diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index b365e0dfccb6..34898d53395b 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -2109,7 +2109,6 @@ static void rbd_img_obj_callback(struct rbd_obj_request *obj_request)
2109 rbd_assert(img_request->obj_request_count > 0); 2109 rbd_assert(img_request->obj_request_count > 0);
2110 rbd_assert(which != BAD_WHICH); 2110 rbd_assert(which != BAD_WHICH);
2111 rbd_assert(which < img_request->obj_request_count); 2111 rbd_assert(which < img_request->obj_request_count);
2112 rbd_assert(which >= img_request->next_completion);
2113 2112
2114 spin_lock_irq(&img_request->completion_lock); 2113 spin_lock_irq(&img_request->completion_lock);
2115 if (which != img_request->next_completion) 2114 if (which != img_request->next_completion)
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index 011e55d820b1..51c557cfd92b 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -612,6 +612,8 @@ static ssize_t disksize_store(struct device *dev,
612 612
613 disksize = PAGE_ALIGN(disksize); 613 disksize = PAGE_ALIGN(disksize);
614 meta = zram_meta_alloc(disksize); 614 meta = zram_meta_alloc(disksize);
615 if (!meta)
616 return -ENOMEM;
615 down_write(&zram->init_lock); 617 down_write(&zram->init_lock);
616 if (zram->init_done) { 618 if (zram->init_done) {
617 up_write(&zram->init_lock); 619 up_write(&zram->init_lock);
diff --git a/drivers/clk/at91/clk-master.c b/drivers/clk/at91/clk-master.c
index bd313f7816a8..c1af80bcdf20 100644
--- a/drivers/clk/at91/clk-master.c
+++ b/drivers/clk/at91/clk-master.c
@@ -242,7 +242,7 @@ of_at91_clk_master_setup(struct device_node *np, struct at91_pmc *pmc,
242 242
243 irq = irq_of_parse_and_map(np, 0); 243 irq = irq_of_parse_and_map(np, 0);
244 if (!irq) 244 if (!irq)
245 return; 245 goto out_free_characteristics;
246 246
247 clk = at91_clk_register_master(pmc, irq, name, num_parents, 247 clk = at91_clk_register_master(pmc, irq, name, num_parents,
248 parent_names, layout, 248 parent_names, layout,
diff --git a/drivers/clk/clk-nomadik.c b/drivers/clk/clk-nomadik.c
index 6a934a5296bd..05e04ce0f148 100644
--- a/drivers/clk/clk-nomadik.c
+++ b/drivers/clk/clk-nomadik.c
@@ -494,6 +494,9 @@ static const struct file_operations nomadik_src_clk_debugfs_ops = {
494 494
495static int __init nomadik_src_clk_init_debugfs(void) 495static int __init nomadik_src_clk_init_debugfs(void)
496{ 496{
497 /* Vital for multiplatform */
498 if (!src_base)
499 return -ENODEV;
497 src_pcksr0_boot = readl(src_base + SRC_PCKSR0); 500 src_pcksr0_boot = readl(src_base + SRC_PCKSR0);
498 src_pcksr1_boot = readl(src_base + SRC_PCKSR1); 501 src_pcksr1_boot = readl(src_base + SRC_PCKSR1);
499 debugfs_create_file("nomadik-src-clk", S_IFREG | S_IRUGO, 502 debugfs_create_file("nomadik-src-clk", S_IFREG | S_IRUGO,
diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 5517944495d8..c42e608af6bb 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -2226,24 +2226,25 @@ EXPORT_SYMBOL_GPL(devm_clk_unregister);
2226 */ 2226 */
2227int __clk_get(struct clk *clk) 2227int __clk_get(struct clk *clk)
2228{ 2228{
2229 if (clk && !try_module_get(clk->owner)) 2229 if (clk) {
2230 return 0; 2230 if (!try_module_get(clk->owner))
2231 return 0;
2231 2232
2232 kref_get(&clk->ref); 2233 kref_get(&clk->ref);
2234 }
2233 return 1; 2235 return 1;
2234} 2236}
2235 2237
2236void __clk_put(struct clk *clk) 2238void __clk_put(struct clk *clk)
2237{ 2239{
2238 if (WARN_ON_ONCE(IS_ERR(clk))) 2240 if (!clk || WARN_ON_ONCE(IS_ERR(clk)))
2239 return; 2241 return;
2240 2242
2241 clk_prepare_lock(); 2243 clk_prepare_lock();
2242 kref_put(&clk->ref, __clk_release); 2244 kref_put(&clk->ref, __clk_release);
2243 clk_prepare_unlock(); 2245 clk_prepare_unlock();
2244 2246
2245 if (clk) 2247 module_put(clk->owner);
2246 module_put(clk->owner);
2247} 2248}
2248 2249
2249/*** clk rate change notifiers ***/ 2250/*** clk rate change notifiers ***/
diff --git a/drivers/clk/keystone/gate.c b/drivers/clk/keystone/gate.c
index 17a598398a53..86f1e362eafb 100644
--- a/drivers/clk/keystone/gate.c
+++ b/drivers/clk/keystone/gate.c
@@ -179,6 +179,7 @@ static struct clk *clk_register_psc(struct device *dev,
179 179
180 init.name = name; 180 init.name = name;
181 init.ops = &clk_psc_ops; 181 init.ops = &clk_psc_ops;
182 init.flags = 0;
182 init.parent_names = (parent_name ? &parent_name : NULL); 183 init.parent_names = (parent_name ? &parent_name : NULL);
183 init.num_parents = (parent_name ? 1 : 0); 184 init.num_parents = (parent_name ? 1 : 0);
184 185
diff --git a/drivers/clk/mvebu/armada-370.c b/drivers/clk/mvebu/armada-370.c
index 81a202d12a7a..bef198a83863 100644
--- a/drivers/clk/mvebu/armada-370.c
+++ b/drivers/clk/mvebu/armada-370.c
@@ -141,13 +141,6 @@ static const struct coreclk_soc_desc a370_coreclks = {
141 .num_ratios = ARRAY_SIZE(a370_coreclk_ratios), 141 .num_ratios = ARRAY_SIZE(a370_coreclk_ratios),
142}; 142};
143 143
144static void __init a370_coreclk_init(struct device_node *np)
145{
146 mvebu_coreclk_setup(np, &a370_coreclks);
147}
148CLK_OF_DECLARE(a370_core_clk, "marvell,armada-370-core-clock",
149 a370_coreclk_init);
150
151/* 144/*
152 * Clock Gating Control 145 * Clock Gating Control
153 */ 146 */
@@ -168,9 +161,15 @@ static const struct clk_gating_soc_desc a370_gating_desc[] __initconst = {
168 { } 161 { }
169}; 162};
170 163
171static void __init a370_clk_gating_init(struct device_node *np) 164static void __init a370_clk_init(struct device_node *np)
172{ 165{
173 mvebu_clk_gating_setup(np, a370_gating_desc); 166 struct device_node *cgnp =
167 of_find_compatible_node(NULL, NULL, "marvell,armada-370-gating-clock");
168
169 mvebu_coreclk_setup(np, &a370_coreclks);
170
171 if (cgnp)
172 mvebu_clk_gating_setup(cgnp, a370_gating_desc);
174} 173}
175CLK_OF_DECLARE(a370_clk_gating, "marvell,armada-370-gating-clock", 174CLK_OF_DECLARE(a370_clk, "marvell,armada-370-core-clock", a370_clk_init);
176 a370_clk_gating_init); 175
diff --git a/drivers/clk/mvebu/armada-xp.c b/drivers/clk/mvebu/armada-xp.c
index 9922c4475aa8..b3094315a3c0 100644
--- a/drivers/clk/mvebu/armada-xp.c
+++ b/drivers/clk/mvebu/armada-xp.c
@@ -158,13 +158,6 @@ static const struct coreclk_soc_desc axp_coreclks = {
158 .num_ratios = ARRAY_SIZE(axp_coreclk_ratios), 158 .num_ratios = ARRAY_SIZE(axp_coreclk_ratios),
159}; 159};
160 160
161static void __init axp_coreclk_init(struct device_node *np)
162{
163 mvebu_coreclk_setup(np, &axp_coreclks);
164}
165CLK_OF_DECLARE(axp_core_clk, "marvell,armada-xp-core-clock",
166 axp_coreclk_init);
167
168/* 161/*
169 * Clock Gating Control 162 * Clock Gating Control
170 */ 163 */
@@ -202,9 +195,14 @@ static const struct clk_gating_soc_desc axp_gating_desc[] __initconst = {
202 { } 195 { }
203}; 196};
204 197
205static void __init axp_clk_gating_init(struct device_node *np) 198static void __init axp_clk_init(struct device_node *np)
206{ 199{
207 mvebu_clk_gating_setup(np, axp_gating_desc); 200 struct device_node *cgnp =
201 of_find_compatible_node(NULL, NULL, "marvell,armada-xp-gating-clock");
202
203 mvebu_coreclk_setup(np, &axp_coreclks);
204
205 if (cgnp)
206 mvebu_clk_gating_setup(cgnp, axp_gating_desc);
208} 207}
209CLK_OF_DECLARE(axp_clk_gating, "marvell,armada-xp-gating-clock", 208CLK_OF_DECLARE(axp_clk, "marvell,armada-xp-core-clock", axp_clk_init);
210 axp_clk_gating_init);
diff --git a/drivers/clk/mvebu/dove.c b/drivers/clk/mvebu/dove.c
index 38aee1e3f242..b8c2424ac926 100644
--- a/drivers/clk/mvebu/dove.c
+++ b/drivers/clk/mvebu/dove.c
@@ -154,12 +154,6 @@ static const struct coreclk_soc_desc dove_coreclks = {
154 .num_ratios = ARRAY_SIZE(dove_coreclk_ratios), 154 .num_ratios = ARRAY_SIZE(dove_coreclk_ratios),
155}; 155};
156 156
157static void __init dove_coreclk_init(struct device_node *np)
158{
159 mvebu_coreclk_setup(np, &dove_coreclks);
160}
161CLK_OF_DECLARE(dove_core_clk, "marvell,dove-core-clock", dove_coreclk_init);
162
163/* 157/*
164 * Clock Gating Control 158 * Clock Gating Control
165 */ 159 */
@@ -186,9 +180,14 @@ static const struct clk_gating_soc_desc dove_gating_desc[] __initconst = {
186 { } 180 { }
187}; 181};
188 182
189static void __init dove_clk_gating_init(struct device_node *np) 183static void __init dove_clk_init(struct device_node *np)
190{ 184{
191 mvebu_clk_gating_setup(np, dove_gating_desc); 185 struct device_node *cgnp =
186 of_find_compatible_node(NULL, NULL, "marvell,dove-gating-clock");
187
188 mvebu_coreclk_setup(np, &dove_coreclks);
189
190 if (cgnp)
191 mvebu_clk_gating_setup(cgnp, dove_gating_desc);
192} 192}
193CLK_OF_DECLARE(dove_clk_gating, "marvell,dove-gating-clock", 193CLK_OF_DECLARE(dove_clk, "marvell,dove-core-clock", dove_clk_init);
194 dove_clk_gating_init);
diff --git a/drivers/clk/mvebu/kirkwood.c b/drivers/clk/mvebu/kirkwood.c
index 2636a55f29f9..ddb666a86500 100644
--- a/drivers/clk/mvebu/kirkwood.c
+++ b/drivers/clk/mvebu/kirkwood.c
@@ -193,13 +193,6 @@ static const struct coreclk_soc_desc kirkwood_coreclks = {
193 .num_ratios = ARRAY_SIZE(kirkwood_coreclk_ratios), 193 .num_ratios = ARRAY_SIZE(kirkwood_coreclk_ratios),
194}; 194};
195 195
196static void __init kirkwood_coreclk_init(struct device_node *np)
197{
198 mvebu_coreclk_setup(np, &kirkwood_coreclks);
199}
200CLK_OF_DECLARE(kirkwood_core_clk, "marvell,kirkwood-core-clock",
201 kirkwood_coreclk_init);
202
203static const struct coreclk_soc_desc mv88f6180_coreclks = { 196static const struct coreclk_soc_desc mv88f6180_coreclks = {
204 .get_tclk_freq = kirkwood_get_tclk_freq, 197 .get_tclk_freq = kirkwood_get_tclk_freq,
205 .get_cpu_freq = mv88f6180_get_cpu_freq, 198 .get_cpu_freq = mv88f6180_get_cpu_freq,
@@ -208,13 +201,6 @@ static const struct coreclk_soc_desc mv88f6180_coreclks = {
208 .num_ratios = ARRAY_SIZE(kirkwood_coreclk_ratios), 201 .num_ratios = ARRAY_SIZE(kirkwood_coreclk_ratios),
209}; 202};
210 203
211static void __init mv88f6180_coreclk_init(struct device_node *np)
212{
213 mvebu_coreclk_setup(np, &mv88f6180_coreclks);
214}
215CLK_OF_DECLARE(mv88f6180_core_clk, "marvell,mv88f6180-core-clock",
216 mv88f6180_coreclk_init);
217
218/* 204/*
219 * Clock Gating Control 205 * Clock Gating Control
220 */ 206 */
@@ -239,9 +225,21 @@ static const struct clk_gating_soc_desc kirkwood_gating_desc[] __initconst = {
239 { } 225 { }
240}; 226};
241 227
242static void __init kirkwood_clk_gating_init(struct device_node *np) 228static void __init kirkwood_clk_init(struct device_node *np)
243{ 229{
244 mvebu_clk_gating_setup(np, kirkwood_gating_desc); 230 struct device_node *cgnp =
231 of_find_compatible_node(NULL, NULL, "marvell,kirkwood-gating-clock");
232
233
234 if (of_device_is_compatible(np, "marvell,mv88f6180-core-clock"))
235 mvebu_coreclk_setup(np, &mv88f6180_coreclks);
236 else
237 mvebu_coreclk_setup(np, &kirkwood_coreclks);
238
239 if (cgnp)
240 mvebu_clk_gating_setup(cgnp, kirkwood_gating_desc);
245} 241}
246CLK_OF_DECLARE(kirkwood_clk_gating, "marvell,kirkwood-gating-clock", 242CLK_OF_DECLARE(kirkwood_clk, "marvell,kirkwood-core-clock",
247 kirkwood_clk_gating_init); 243 kirkwood_clk_init);
244CLK_OF_DECLARE(mv88f6180_clk, "marvell,mv88f6180-core-clock",
245 kirkwood_clk_init);
diff --git a/drivers/clk/shmobile/clk-rcar-gen2.c b/drivers/clk/shmobile/clk-rcar-gen2.c
index a59ec217a124..99c27b1c625b 100644
--- a/drivers/clk/shmobile/clk-rcar-gen2.c
+++ b/drivers/clk/shmobile/clk-rcar-gen2.c
@@ -26,6 +26,8 @@ struct rcar_gen2_cpg {
26 void __iomem *reg; 26 void __iomem *reg;
27}; 27};
28 28
29#define CPG_FRQCRB 0x00000004
30#define CPG_FRQCRB_KICK BIT(31)
29#define CPG_SDCKCR 0x00000074 31#define CPG_SDCKCR 0x00000074
30#define CPG_PLL0CR 0x000000d8 32#define CPG_PLL0CR 0x000000d8
31#define CPG_FRQCRC 0x000000e0 33#define CPG_FRQCRC 0x000000e0
@@ -45,6 +47,7 @@ struct rcar_gen2_cpg {
45struct cpg_z_clk { 47struct cpg_z_clk {
46 struct clk_hw hw; 48 struct clk_hw hw;
47 void __iomem *reg; 49 void __iomem *reg;
50 void __iomem *kick_reg;
48}; 51};
49 52
50#define to_z_clk(_hw) container_of(_hw, struct cpg_z_clk, hw) 53#define to_z_clk(_hw) container_of(_hw, struct cpg_z_clk, hw)
@@ -83,17 +86,45 @@ static int cpg_z_clk_set_rate(struct clk_hw *hw, unsigned long rate,
83{ 86{
84 struct cpg_z_clk *zclk = to_z_clk(hw); 87 struct cpg_z_clk *zclk = to_z_clk(hw);
85 unsigned int mult; 88 unsigned int mult;
86 u32 val; 89 u32 val, kick;
90 unsigned int i;
87 91
88 mult = div_u64((u64)rate * 32, parent_rate); 92 mult = div_u64((u64)rate * 32, parent_rate);
89 mult = clamp(mult, 1U, 32U); 93 mult = clamp(mult, 1U, 32U);
90 94
95 if (clk_readl(zclk->kick_reg) & CPG_FRQCRB_KICK)
96 return -EBUSY;
97
91 val = clk_readl(zclk->reg); 98 val = clk_readl(zclk->reg);
92 val &= ~CPG_FRQCRC_ZFC_MASK; 99 val &= ~CPG_FRQCRC_ZFC_MASK;
93 val |= (32 - mult) << CPG_FRQCRC_ZFC_SHIFT; 100 val |= (32 - mult) << CPG_FRQCRC_ZFC_SHIFT;
94 clk_writel(val, zclk->reg); 101 clk_writel(val, zclk->reg);
95 102
96 return 0; 103 /*
104 * Set KICK bit in FRQCRB to update hardware setting and wait for
105 * clock change completion.
106 */
107 kick = clk_readl(zclk->kick_reg);
108 kick |= CPG_FRQCRB_KICK;
109 clk_writel(kick, zclk->kick_reg);
110
111 /*
112 * Note: There is no HW information about the worst case latency.
113 *
114 * Using experimental measurements, it seems that no more than
115 * ~10 iterations are needed, independently of the CPU rate.
116 * Since this value might be dependant of external xtal rate, pll1
117 * rate or even the other emulation clocks rate, use 1000 as a
118 * "super" safe value.
119 */
120 for (i = 1000; i; i--) {
121 if (!(clk_readl(zclk->kick_reg) & CPG_FRQCRB_KICK))
122 return 0;
123
124 cpu_relax();
125 }
126
127 return -ETIMEDOUT;
97} 128}
98 129
99static const struct clk_ops cpg_z_clk_ops = { 130static const struct clk_ops cpg_z_clk_ops = {
@@ -120,6 +151,7 @@ static struct clk * __init cpg_z_clk_register(struct rcar_gen2_cpg *cpg)
120 init.num_parents = 1; 151 init.num_parents = 1;
121 152
122 zclk->reg = cpg->reg + CPG_FRQCRC; 153 zclk->reg = cpg->reg + CPG_FRQCRC;
154 zclk->kick_reg = cpg->reg + CPG_FRQCRB;
123 zclk->hw.init = &init; 155 zclk->hw.init = &init;
124 156
125 clk = clk_register(NULL, &zclk->hw); 157 clk = clk_register(NULL, &zclk->hw);
@@ -186,7 +218,7 @@ rcar_gen2_cpg_register_clock(struct device_node *np, struct rcar_gen2_cpg *cpg,
186 const char *name) 218 const char *name)
187{ 219{
188 const struct clk_div_table *table = NULL; 220 const struct clk_div_table *table = NULL;
189 const char *parent_name = "main"; 221 const char *parent_name;
190 unsigned int shift; 222 unsigned int shift;
191 unsigned int mult = 1; 223 unsigned int mult = 1;
192 unsigned int div = 1; 224 unsigned int div = 1;
@@ -201,23 +233,31 @@ rcar_gen2_cpg_register_clock(struct device_node *np, struct rcar_gen2_cpg *cpg,
201 * the multiplier value. 233 * the multiplier value.
202 */ 234 */
203 u32 value = clk_readl(cpg->reg + CPG_PLL0CR); 235 u32 value = clk_readl(cpg->reg + CPG_PLL0CR);
236 parent_name = "main";
204 mult = ((value >> 24) & ((1 << 7) - 1)) + 1; 237 mult = ((value >> 24) & ((1 << 7) - 1)) + 1;
205 } else if (!strcmp(name, "pll1")) { 238 } else if (!strcmp(name, "pll1")) {
239 parent_name = "main";
206 mult = config->pll1_mult / 2; 240 mult = config->pll1_mult / 2;
207 } else if (!strcmp(name, "pll3")) { 241 } else if (!strcmp(name, "pll3")) {
242 parent_name = "main";
208 mult = config->pll3_mult; 243 mult = config->pll3_mult;
209 } else if (!strcmp(name, "lb")) { 244 } else if (!strcmp(name, "lb")) {
245 parent_name = "pll1_div2";
210 div = cpg_mode & BIT(18) ? 36 : 24; 246 div = cpg_mode & BIT(18) ? 36 : 24;
211 } else if (!strcmp(name, "qspi")) { 247 } else if (!strcmp(name, "qspi")) {
248 parent_name = "pll1_div2";
212 div = (cpg_mode & (BIT(3) | BIT(2) | BIT(1))) == BIT(2) 249 div = (cpg_mode & (BIT(3) | BIT(2) | BIT(1))) == BIT(2)
213 ? 16 : 20; 250 ? 8 : 10;
214 } else if (!strcmp(name, "sdh")) { 251 } else if (!strcmp(name, "sdh")) {
252 parent_name = "pll1_div2";
215 table = cpg_sdh_div_table; 253 table = cpg_sdh_div_table;
216 shift = 8; 254 shift = 8;
217 } else if (!strcmp(name, "sd0")) { 255 } else if (!strcmp(name, "sd0")) {
256 parent_name = "pll1_div2";
218 table = cpg_sd01_div_table; 257 table = cpg_sd01_div_table;
219 shift = 4; 258 shift = 4;
220 } else if (!strcmp(name, "sd1")) { 259 } else if (!strcmp(name, "sd1")) {
260 parent_name = "pll1_div2";
221 table = cpg_sd01_div_table; 261 table = cpg_sd01_div_table;
222 shift = 0; 262 shift = 0;
223 } else if (!strcmp(name, "z")) { 263 } else if (!strcmp(name, "z")) {
diff --git a/drivers/clk/tegra/clk-divider.c b/drivers/clk/tegra/clk-divider.c
index 4d75b1f37e3a..290f9c1a3749 100644
--- a/drivers/clk/tegra/clk-divider.c
+++ b/drivers/clk/tegra/clk-divider.c
@@ -59,7 +59,7 @@ static int get_div(struct tegra_clk_frac_div *divider, unsigned long rate,
59 return 0; 59 return 0;
60 60
61 if (divider_ux1 > get_max_div(divider)) 61 if (divider_ux1 > get_max_div(divider))
62 return -EINVAL; 62 return get_max_div(divider);
63 63
64 return divider_ux1; 64 return divider_ux1;
65} 65}
diff --git a/drivers/clk/tegra/clk-id.h b/drivers/clk/tegra/clk-id.h
index cf0c323f2c36..c39613c519af 100644
--- a/drivers/clk/tegra/clk-id.h
+++ b/drivers/clk/tegra/clk-id.h
@@ -180,9 +180,13 @@ enum clk_id {
180 tegra_clk_sbc6_8, 180 tegra_clk_sbc6_8,
181 tegra_clk_sclk, 181 tegra_clk_sclk,
182 tegra_clk_sdmmc1, 182 tegra_clk_sdmmc1,
183 tegra_clk_sdmmc1_8,
183 tegra_clk_sdmmc2, 184 tegra_clk_sdmmc2,
185 tegra_clk_sdmmc2_8,
184 tegra_clk_sdmmc3, 186 tegra_clk_sdmmc3,
187 tegra_clk_sdmmc3_8,
185 tegra_clk_sdmmc4, 188 tegra_clk_sdmmc4,
189 tegra_clk_sdmmc4_8,
186 tegra_clk_se, 190 tegra_clk_se,
187 tegra_clk_soc_therm, 191 tegra_clk_soc_therm,
188 tegra_clk_sor0, 192 tegra_clk_sor0,
diff --git a/drivers/clk/tegra/clk-tegra-periph.c b/drivers/clk/tegra/clk-tegra-periph.c
index 5c35885f4a7c..1fa5c3f33b20 100644
--- a/drivers/clk/tegra/clk-tegra-periph.c
+++ b/drivers/clk/tegra/clk-tegra-periph.c
@@ -371,9 +371,7 @@ static const char *mux_pllp3_pllc_clkm[] = {
371static const char *mux_pllm_pllc_pllp_plla_pllc2_c3_clkm[] = { 371static const char *mux_pllm_pllc_pllp_plla_pllc2_c3_clkm[] = {
372 "pll_m", "pll_c", "pll_p", "pll_a", "pll_c2", "pll_c3", "clk_m" 372 "pll_m", "pll_c", "pll_p", "pll_a", "pll_c2", "pll_c3", "clk_m"
373}; 373};
374static u32 mux_pllm_pllc_pllp_plla_pllc2_c3_clkm_idx[] = { 374#define mux_pllm_pllc_pllp_plla_pllc2_c3_clkm_idx NULL
375 [0] = 0, [1] = 1, [2] = 2, [3] = 3, [4] = 4, [5] = 6,
376};
377 375
378static const char *mux_pllm_pllc2_c_c3_pllp_plla_pllc4[] = { 376static const char *mux_pllm_pllc2_c_c3_pllp_plla_pllc4[] = {
379 "pll_m", "pll_c2", "pll_c", "pll_c3", "pll_p", "pll_a_out0", "pll_c4", 377 "pll_m", "pll_c2", "pll_c", "pll_c3", "pll_p", "pll_a_out0", "pll_c4",
@@ -465,6 +463,10 @@ static struct tegra_periph_init_data periph_clks[] = {
465 MUX("adx1", mux_plla_pllc_pllp_clkm, CLK_SOURCE_ADX1, 180, TEGRA_PERIPH_ON_APB, tegra_clk_adx1), 463 MUX("adx1", mux_plla_pllc_pllp_clkm, CLK_SOURCE_ADX1, 180, TEGRA_PERIPH_ON_APB, tegra_clk_adx1),
466 MUX("amx1", mux_plla_pllc_pllp_clkm, CLK_SOURCE_AMX1, 185, TEGRA_PERIPH_ON_APB, tegra_clk_amx1), 464 MUX("amx1", mux_plla_pllc_pllp_clkm, CLK_SOURCE_AMX1, 185, TEGRA_PERIPH_ON_APB, tegra_clk_amx1),
467 MUX("vi_sensor2", mux_pllm_pllc2_c_c3_pllp_plla, CLK_SOURCE_VI_SENSOR2, 20, TEGRA_PERIPH_NO_RESET, tegra_clk_vi_sensor2), 465 MUX("vi_sensor2", mux_pllm_pllc2_c_c3_pllp_plla, CLK_SOURCE_VI_SENSOR2, 20, TEGRA_PERIPH_NO_RESET, tegra_clk_vi_sensor2),
466 MUX8("sdmmc1", mux_pllp_pllc2_c_c3_pllm_clkm, CLK_SOURCE_SDMMC1, 14, 0, tegra_clk_sdmmc1_8),
467 MUX8("sdmmc2", mux_pllp_pllc2_c_c3_pllm_clkm, CLK_SOURCE_SDMMC2, 9, 0, tegra_clk_sdmmc2_8),
468 MUX8("sdmmc3", mux_pllp_pllc2_c_c3_pllm_clkm, CLK_SOURCE_SDMMC3, 69, 0, tegra_clk_sdmmc3_8),
469 MUX8("sdmmc4", mux_pllp_pllc2_c_c3_pllm_clkm, CLK_SOURCE_SDMMC4, 15, 0, tegra_clk_sdmmc4_8),
468 MUX8("sbc1", mux_pllp_pllc2_c_c3_pllm_clkm, CLK_SOURCE_SBC1, 41, TEGRA_PERIPH_ON_APB, tegra_clk_sbc1_8), 470 MUX8("sbc1", mux_pllp_pllc2_c_c3_pllm_clkm, CLK_SOURCE_SBC1, 41, TEGRA_PERIPH_ON_APB, tegra_clk_sbc1_8),
469 MUX8("sbc2", mux_pllp_pllc2_c_c3_pllm_clkm, CLK_SOURCE_SBC2, 44, TEGRA_PERIPH_ON_APB, tegra_clk_sbc2_8), 471 MUX8("sbc2", mux_pllp_pllc2_c_c3_pllm_clkm, CLK_SOURCE_SBC2, 44, TEGRA_PERIPH_ON_APB, tegra_clk_sbc2_8),
470 MUX8("sbc3", mux_pllp_pllc2_c_c3_pllm_clkm, CLK_SOURCE_SBC3, 46, TEGRA_PERIPH_ON_APB, tegra_clk_sbc3_8), 472 MUX8("sbc3", mux_pllp_pllc2_c_c3_pllm_clkm, CLK_SOURCE_SBC3, 46, TEGRA_PERIPH_ON_APB, tegra_clk_sbc3_8),
@@ -492,7 +494,7 @@ static struct tegra_periph_init_data periph_clks[] = {
492 UART("uartb", mux_pllp_pllc_pllm_clkm, CLK_SOURCE_UARTB, 7, tegra_clk_uartb), 494 UART("uartb", mux_pllp_pllc_pllm_clkm, CLK_SOURCE_UARTB, 7, tegra_clk_uartb),
493 UART("uartc", mux_pllp_pllc_pllm_clkm, CLK_SOURCE_UARTC, 55, tegra_clk_uartc), 495 UART("uartc", mux_pllp_pllc_pllm_clkm, CLK_SOURCE_UARTC, 55, tegra_clk_uartc),
494 UART("uartd", mux_pllp_pllc_pllm_clkm, CLK_SOURCE_UARTD, 65, tegra_clk_uartd), 496 UART("uartd", mux_pllp_pllc_pllm_clkm, CLK_SOURCE_UARTD, 65, tegra_clk_uartd),
495 UART("uarte", mux_pllp_pllc_pllm_clkm, CLK_SOURCE_UARTE, 65, tegra_clk_uarte), 497 UART("uarte", mux_pllp_pllc_pllm_clkm, CLK_SOURCE_UARTE, 66, tegra_clk_uarte),
496 XUSB("xusb_host_src", mux_clkm_pllp_pllc_pllre, CLK_SOURCE_XUSB_HOST_SRC, 143, TEGRA_PERIPH_ON_APB | TEGRA_PERIPH_NO_RESET, tegra_clk_xusb_host_src), 498 XUSB("xusb_host_src", mux_clkm_pllp_pllc_pllre, CLK_SOURCE_XUSB_HOST_SRC, 143, TEGRA_PERIPH_ON_APB | TEGRA_PERIPH_NO_RESET, tegra_clk_xusb_host_src),
497 XUSB("xusb_falcon_src", mux_clkm_pllp_pllc_pllre, CLK_SOURCE_XUSB_FALCON_SRC, 143, TEGRA_PERIPH_NO_RESET, tegra_clk_xusb_falcon_src), 499 XUSB("xusb_falcon_src", mux_clkm_pllp_pllc_pllre, CLK_SOURCE_XUSB_FALCON_SRC, 143, TEGRA_PERIPH_NO_RESET, tegra_clk_xusb_falcon_src),
498 XUSB("xusb_fs_src", mux_clkm_48M_pllp_480M, CLK_SOURCE_XUSB_FS_SRC, 143, TEGRA_PERIPH_NO_RESET, tegra_clk_xusb_fs_src), 500 XUSB("xusb_fs_src", mux_clkm_48M_pllp_480M, CLK_SOURCE_XUSB_FS_SRC, 143, TEGRA_PERIPH_NO_RESET, tegra_clk_xusb_fs_src),
diff --git a/drivers/clk/tegra/clk-tegra-super-gen4.c b/drivers/clk/tegra/clk-tegra-super-gen4.c
index 05dce4aa2c11..feb3201c85ce 100644
--- a/drivers/clk/tegra/clk-tegra-super-gen4.c
+++ b/drivers/clk/tegra/clk-tegra-super-gen4.c
@@ -120,7 +120,7 @@ void __init tegra_super_clk_gen4_init(void __iomem *clk_base,
120 ARRAY_SIZE(cclk_lp_parents), 120 ARRAY_SIZE(cclk_lp_parents),
121 CLK_SET_RATE_PARENT, 121 CLK_SET_RATE_PARENT,
122 clk_base + CCLKLP_BURST_POLICY, 122 clk_base + CCLKLP_BURST_POLICY,
123 0, 4, 8, 9, NULL); 123 TEGRA_DIVIDER_2, 4, 8, 9, NULL);
124 *dt_clk = clk; 124 *dt_clk = clk;
125 } 125 }
126 126
diff --git a/drivers/clk/tegra/clk-tegra114.c b/drivers/clk/tegra/clk-tegra114.c
index 90d9d25f2228..80431f0fb268 100644
--- a/drivers/clk/tegra/clk-tegra114.c
+++ b/drivers/clk/tegra/clk-tegra114.c
@@ -682,12 +682,12 @@ static struct tegra_clk tegra114_clks[tegra_clk_max] __initdata = {
682 [tegra_clk_timer] = { .dt_id = TEGRA114_CLK_TIMER, .present = true }, 682 [tegra_clk_timer] = { .dt_id = TEGRA114_CLK_TIMER, .present = true },
683 [tegra_clk_uarta] = { .dt_id = TEGRA114_CLK_UARTA, .present = true }, 683 [tegra_clk_uarta] = { .dt_id = TEGRA114_CLK_UARTA, .present = true },
684 [tegra_clk_uartd] = { .dt_id = TEGRA114_CLK_UARTD, .present = true }, 684 [tegra_clk_uartd] = { .dt_id = TEGRA114_CLK_UARTD, .present = true },
685 [tegra_clk_sdmmc2] = { .dt_id = TEGRA114_CLK_SDMMC2, .present = true }, 685 [tegra_clk_sdmmc2_8] = { .dt_id = TEGRA114_CLK_SDMMC2, .present = true },
686 [tegra_clk_i2s1] = { .dt_id = TEGRA114_CLK_I2S1, .present = true }, 686 [tegra_clk_i2s1] = { .dt_id = TEGRA114_CLK_I2S1, .present = true },
687 [tegra_clk_i2c1] = { .dt_id = TEGRA114_CLK_I2C1, .present = true }, 687 [tegra_clk_i2c1] = { .dt_id = TEGRA114_CLK_I2C1, .present = true },
688 [tegra_clk_ndflash] = { .dt_id = TEGRA114_CLK_NDFLASH, .present = true }, 688 [tegra_clk_ndflash] = { .dt_id = TEGRA114_CLK_NDFLASH, .present = true },
689 [tegra_clk_sdmmc1] = { .dt_id = TEGRA114_CLK_SDMMC1, .present = true }, 689 [tegra_clk_sdmmc1_8] = { .dt_id = TEGRA114_CLK_SDMMC1, .present = true },
690 [tegra_clk_sdmmc4] = { .dt_id = TEGRA114_CLK_SDMMC4, .present = true }, 690 [tegra_clk_sdmmc4_8] = { .dt_id = TEGRA114_CLK_SDMMC4, .present = true },
691 [tegra_clk_pwm] = { .dt_id = TEGRA114_CLK_PWM, .present = true }, 691 [tegra_clk_pwm] = { .dt_id = TEGRA114_CLK_PWM, .present = true },
692 [tegra_clk_i2s0] = { .dt_id = TEGRA114_CLK_I2S0, .present = true }, 692 [tegra_clk_i2s0] = { .dt_id = TEGRA114_CLK_I2S0, .present = true },
693 [tegra_clk_i2s2] = { .dt_id = TEGRA114_CLK_I2S2, .present = true }, 693 [tegra_clk_i2s2] = { .dt_id = TEGRA114_CLK_I2S2, .present = true },
@@ -723,7 +723,7 @@ static struct tegra_clk tegra114_clks[tegra_clk_max] __initdata = {
723 [tegra_clk_bsev] = { .dt_id = TEGRA114_CLK_BSEV, .present = true }, 723 [tegra_clk_bsev] = { .dt_id = TEGRA114_CLK_BSEV, .present = true },
724 [tegra_clk_i2c3] = { .dt_id = TEGRA114_CLK_I2C3, .present = true }, 724 [tegra_clk_i2c3] = { .dt_id = TEGRA114_CLK_I2C3, .present = true },
725 [tegra_clk_sbc4_8] = { .dt_id = TEGRA114_CLK_SBC4, .present = true }, 725 [tegra_clk_sbc4_8] = { .dt_id = TEGRA114_CLK_SBC4, .present = true },
726 [tegra_clk_sdmmc3] = { .dt_id = TEGRA114_CLK_SDMMC3, .present = true }, 726 [tegra_clk_sdmmc3_8] = { .dt_id = TEGRA114_CLK_SDMMC3, .present = true },
727 [tegra_clk_owr] = { .dt_id = TEGRA114_CLK_OWR, .present = true }, 727 [tegra_clk_owr] = { .dt_id = TEGRA114_CLK_OWR, .present = true },
728 [tegra_clk_csite] = { .dt_id = TEGRA114_CLK_CSITE, .present = true }, 728 [tegra_clk_csite] = { .dt_id = TEGRA114_CLK_CSITE, .present = true },
729 [tegra_clk_la] = { .dt_id = TEGRA114_CLK_LA, .present = true }, 729 [tegra_clk_la] = { .dt_id = TEGRA114_CLK_LA, .present = true },
diff --git a/drivers/clk/tegra/clk-tegra124.c b/drivers/clk/tegra/clk-tegra124.c
index aff86b5bc745..166e02f16c8a 100644
--- a/drivers/clk/tegra/clk-tegra124.c
+++ b/drivers/clk/tegra/clk-tegra124.c
@@ -516,11 +516,11 @@ static struct div_nmp pllp_nmp = {
516}; 516};
517 517
518static struct tegra_clk_pll_freq_table pll_p_freq_table[] = { 518static struct tegra_clk_pll_freq_table pll_p_freq_table[] = {
519 {12000000, 216000000, 432, 12, 1, 8}, 519 {12000000, 408000000, 408, 12, 0, 8},
520 {13000000, 216000000, 432, 13, 1, 8}, 520 {13000000, 408000000, 408, 13, 0, 8},
521 {16800000, 216000000, 360, 14, 1, 8}, 521 {16800000, 408000000, 340, 14, 0, 8},
522 {19200000, 216000000, 360, 16, 1, 8}, 522 {19200000, 408000000, 340, 16, 0, 8},
523 {26000000, 216000000, 432, 26, 1, 8}, 523 {26000000, 408000000, 408, 26, 0, 8},
524 {0, 0, 0, 0, 0, 0}, 524 {0, 0, 0, 0, 0, 0},
525}; 525};
526 526
@@ -570,6 +570,15 @@ static struct tegra_clk_pll_params pll_a_params = {
570 .flags = TEGRA_PLL_HAS_CPCON | TEGRA_PLL_USE_LOCK, 570 .flags = TEGRA_PLL_HAS_CPCON | TEGRA_PLL_USE_LOCK,
571}; 571};
572 572
573static struct div_nmp plld_nmp = {
574 .divm_shift = 0,
575 .divm_width = 5,
576 .divn_shift = 8,
577 .divn_width = 11,
578 .divp_shift = 20,
579 .divp_width = 3,
580};
581
573static struct tegra_clk_pll_freq_table pll_d_freq_table[] = { 582static struct tegra_clk_pll_freq_table pll_d_freq_table[] = {
574 {12000000, 216000000, 864, 12, 4, 12}, 583 {12000000, 216000000, 864, 12, 4, 12},
575 {13000000, 216000000, 864, 13, 4, 12}, 584 {13000000, 216000000, 864, 13, 4, 12},
@@ -603,19 +612,18 @@ static struct tegra_clk_pll_params pll_d_params = {
603 .lock_mask = PLL_BASE_LOCK, 612 .lock_mask = PLL_BASE_LOCK,
604 .lock_enable_bit_idx = PLLDU_MISC_LOCK_ENABLE, 613 .lock_enable_bit_idx = PLLDU_MISC_LOCK_ENABLE,
605 .lock_delay = 1000, 614 .lock_delay = 1000,
606 .div_nmp = &pllp_nmp, 615 .div_nmp = &plld_nmp,
607 .freq_table = pll_d_freq_table, 616 .freq_table = pll_d_freq_table,
608 .flags = TEGRA_PLL_HAS_CPCON | TEGRA_PLL_SET_LFCON | 617 .flags = TEGRA_PLL_HAS_CPCON | TEGRA_PLL_SET_LFCON |
609 TEGRA_PLL_USE_LOCK, 618 TEGRA_PLL_USE_LOCK,
610}; 619};
611 620
612static struct tegra_clk_pll_freq_table tegra124_pll_d2_freq_table[] = { 621static struct tegra_clk_pll_freq_table tegra124_pll_d2_freq_table[] = {
613 { 12000000, 148500000, 99, 1, 8}, 622 { 12000000, 594000000, 99, 1, 2},
614 { 12000000, 594000000, 99, 1, 1}, 623 { 13000000, 594000000, 91, 1, 2}, /* actual: 591.5 MHz */
615 { 13000000, 594000000, 91, 1, 1}, /* actual: 591.5 MHz */ 624 { 16800000, 594000000, 71, 1, 2}, /* actual: 596.4 MHz */
616 { 16800000, 594000000, 71, 1, 1}, /* actual: 596.4 MHz */ 625 { 19200000, 594000000, 62, 1, 2}, /* actual: 595.2 MHz */
617 { 19200000, 594000000, 62, 1, 1}, /* actual: 595.2 MHz */ 626 { 26000000, 594000000, 91, 2, 2}, /* actual: 591.5 MHz */
618 { 26000000, 594000000, 91, 2, 1}, /* actual: 591.5 MHz */
619 { 0, 0, 0, 0, 0, 0 }, 627 { 0, 0, 0, 0, 0, 0 },
620}; 628};
621 629
@@ -753,21 +761,19 @@ static struct tegra_clk tegra124_clks[tegra_clk_max] __initdata = {
753 [tegra_clk_rtc] = { .dt_id = TEGRA124_CLK_RTC, .present = true }, 761 [tegra_clk_rtc] = { .dt_id = TEGRA124_CLK_RTC, .present = true },
754 [tegra_clk_timer] = { .dt_id = TEGRA124_CLK_TIMER, .present = true }, 762 [tegra_clk_timer] = { .dt_id = TEGRA124_CLK_TIMER, .present = true },
755 [tegra_clk_uarta] = { .dt_id = TEGRA124_CLK_UARTA, .present = true }, 763 [tegra_clk_uarta] = { .dt_id = TEGRA124_CLK_UARTA, .present = true },
756 [tegra_clk_sdmmc2] = { .dt_id = TEGRA124_CLK_SDMMC2, .present = true }, 764 [tegra_clk_sdmmc2_8] = { .dt_id = TEGRA124_CLK_SDMMC2, .present = true },
757 [tegra_clk_i2s1] = { .dt_id = TEGRA124_CLK_I2S1, .present = true }, 765 [tegra_clk_i2s1] = { .dt_id = TEGRA124_CLK_I2S1, .present = true },
758 [tegra_clk_i2c1] = { .dt_id = TEGRA124_CLK_I2C1, .present = true }, 766 [tegra_clk_i2c1] = { .dt_id = TEGRA124_CLK_I2C1, .present = true },
759 [tegra_clk_ndflash] = { .dt_id = TEGRA124_CLK_NDFLASH, .present = true }, 767 [tegra_clk_ndflash] = { .dt_id = TEGRA124_CLK_NDFLASH, .present = true },
760 [tegra_clk_sdmmc1] = { .dt_id = TEGRA124_CLK_SDMMC1, .present = true }, 768 [tegra_clk_sdmmc1_8] = { .dt_id = TEGRA124_CLK_SDMMC1, .present = true },
761 [tegra_clk_sdmmc4] = { .dt_id = TEGRA124_CLK_SDMMC4, .present = true }, 769 [tegra_clk_sdmmc4_8] = { .dt_id = TEGRA124_CLK_SDMMC4, .present = true },
762 [tegra_clk_pwm] = { .dt_id = TEGRA124_CLK_PWM, .present = true }, 770 [tegra_clk_pwm] = { .dt_id = TEGRA124_CLK_PWM, .present = true },
763 [tegra_clk_i2s2] = { .dt_id = TEGRA124_CLK_I2S2, .present = true }, 771 [tegra_clk_i2s2] = { .dt_id = TEGRA124_CLK_I2S2, .present = true },
764 [tegra_clk_gr2d] = { .dt_id = TEGRA124_CLK_GR_2D, .present = true },
765 [tegra_clk_usbd] = { .dt_id = TEGRA124_CLK_USBD, .present = true }, 772 [tegra_clk_usbd] = { .dt_id = TEGRA124_CLK_USBD, .present = true },
766 [tegra_clk_isp_8] = { .dt_id = TEGRA124_CLK_ISP, .present = true }, 773 [tegra_clk_isp_8] = { .dt_id = TEGRA124_CLK_ISP, .present = true },
767 [tegra_clk_gr3d] = { .dt_id = TEGRA124_CLK_GR_3D, .present = true },
768 [tegra_clk_disp2] = { .dt_id = TEGRA124_CLK_DISP2, .present = true }, 774 [tegra_clk_disp2] = { .dt_id = TEGRA124_CLK_DISP2, .present = true },
769 [tegra_clk_disp1] = { .dt_id = TEGRA124_CLK_DISP1, .present = true }, 775 [tegra_clk_disp1] = { .dt_id = TEGRA124_CLK_DISP1, .present = true },
770 [tegra_clk_host1x] = { .dt_id = TEGRA124_CLK_HOST1X, .present = true }, 776 [tegra_clk_host1x_8] = { .dt_id = TEGRA124_CLK_HOST1X, .present = true },
771 [tegra_clk_vcp] = { .dt_id = TEGRA124_CLK_VCP, .present = true }, 777 [tegra_clk_vcp] = { .dt_id = TEGRA124_CLK_VCP, .present = true },
772 [tegra_clk_i2s0] = { .dt_id = TEGRA124_CLK_I2S0, .present = true }, 778 [tegra_clk_i2s0] = { .dt_id = TEGRA124_CLK_I2S0, .present = true },
773 [tegra_clk_apbdma] = { .dt_id = TEGRA124_CLK_APBDMA, .present = true }, 779 [tegra_clk_apbdma] = { .dt_id = TEGRA124_CLK_APBDMA, .present = true },
@@ -794,7 +800,7 @@ static struct tegra_clk tegra124_clks[tegra_clk_max] __initdata = {
794 [tegra_clk_uartd] = { .dt_id = TEGRA124_CLK_UARTD, .present = true }, 800 [tegra_clk_uartd] = { .dt_id = TEGRA124_CLK_UARTD, .present = true },
795 [tegra_clk_i2c3] = { .dt_id = TEGRA124_CLK_I2C3, .present = true }, 801 [tegra_clk_i2c3] = { .dt_id = TEGRA124_CLK_I2C3, .present = true },
796 [tegra_clk_sbc4] = { .dt_id = TEGRA124_CLK_SBC4, .present = true }, 802 [tegra_clk_sbc4] = { .dt_id = TEGRA124_CLK_SBC4, .present = true },
797 [tegra_clk_sdmmc3] = { .dt_id = TEGRA124_CLK_SDMMC3, .present = true }, 803 [tegra_clk_sdmmc3_8] = { .dt_id = TEGRA124_CLK_SDMMC3, .present = true },
798 [tegra_clk_pcie] = { .dt_id = TEGRA124_CLK_PCIE, .present = true }, 804 [tegra_clk_pcie] = { .dt_id = TEGRA124_CLK_PCIE, .present = true },
799 [tegra_clk_owr] = { .dt_id = TEGRA124_CLK_OWR, .present = true }, 805 [tegra_clk_owr] = { .dt_id = TEGRA124_CLK_OWR, .present = true },
800 [tegra_clk_afi] = { .dt_id = TEGRA124_CLK_AFI, .present = true }, 806 [tegra_clk_afi] = { .dt_id = TEGRA124_CLK_AFI, .present = true },
@@ -1286,9 +1292,9 @@ static void __init tegra124_pll_init(void __iomem *clk_base,
1286 clk_register_clkdev(clk, "pll_d2", NULL); 1292 clk_register_clkdev(clk, "pll_d2", NULL);
1287 clks[TEGRA124_CLK_PLL_D2] = clk; 1293 clks[TEGRA124_CLK_PLL_D2] = clk;
1288 1294
1289 /* PLLD2_OUT0 ?? */ 1295 /* PLLD2_OUT0 */
1290 clk = clk_register_fixed_factor(NULL, "pll_d2_out0", "pll_d2", 1296 clk = clk_register_fixed_factor(NULL, "pll_d2_out0", "pll_d2",
1291 CLK_SET_RATE_PARENT, 1, 2); 1297 CLK_SET_RATE_PARENT, 1, 1);
1292 clk_register_clkdev(clk, "pll_d2_out0", NULL); 1298 clk_register_clkdev(clk, "pll_d2_out0", NULL);
1293 clks[TEGRA124_CLK_PLL_D2_OUT0] = clk; 1299 clks[TEGRA124_CLK_PLL_D2_OUT0] = clk;
1294 1300
diff --git a/drivers/clk/tegra/clk-tegra20.c b/drivers/clk/tegra/clk-tegra20.c
index dbace152b2fa..dace2b1b5ae6 100644
--- a/drivers/clk/tegra/clk-tegra20.c
+++ b/drivers/clk/tegra/clk-tegra20.c
@@ -574,6 +574,8 @@ static struct tegra_clk tegra20_clks[tegra_clk_max] __initdata = {
574 [tegra_clk_tvdac] = { .dt_id = TEGRA20_CLK_TVDAC, .present = true }, 574 [tegra_clk_tvdac] = { .dt_id = TEGRA20_CLK_TVDAC, .present = true },
575 [tegra_clk_vi_sensor] = { .dt_id = TEGRA20_CLK_VI_SENSOR, .present = true }, 575 [tegra_clk_vi_sensor] = { .dt_id = TEGRA20_CLK_VI_SENSOR, .present = true },
576 [tegra_clk_afi] = { .dt_id = TEGRA20_CLK_AFI, .present = true }, 576 [tegra_clk_afi] = { .dt_id = TEGRA20_CLK_AFI, .present = true },
577 [tegra_clk_fuse] = { .dt_id = TEGRA20_CLK_FUSE, .present = true },
578 [tegra_clk_kfuse] = { .dt_id = TEGRA20_CLK_KFUSE, .present = true },
577}; 579};
578 580
579static unsigned long tegra20_clk_measure_input_freq(void) 581static unsigned long tegra20_clk_measure_input_freq(void)
diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig
index cd6950fd8caf..52e9329e3c51 100644
--- a/drivers/clocksource/Kconfig
+++ b/drivers/clocksource/Kconfig
@@ -140,3 +140,51 @@ config VF_PIT_TIMER
140 bool 140 bool
141 help 141 help
142 Support for Period Interrupt Timer on Freescale Vybrid Family SoCs. 142 Support for Period Interrupt Timer on Freescale Vybrid Family SoCs.
143
144config SYS_SUPPORTS_SH_CMT
145 bool
146
147config SYS_SUPPORTS_SH_MTU2
148 bool
149
150config SYS_SUPPORTS_SH_TMU
151 bool
152
153config SYS_SUPPORTS_EM_STI
154 bool
155
156config SH_TIMER_CMT
157 bool "Renesas CMT timer driver" if COMPILE_TEST
158 depends on GENERIC_CLOCKEVENTS
159 default SYS_SUPPORTS_SH_CMT
160 help
161 This enables build of a clocksource and clockevent driver for
162 the Compare Match Timer (CMT) hardware available in 16/32/48-bit
163 variants on a wide range of Mobile and Automotive SoCs from Renesas.
164
165config SH_TIMER_MTU2
166 bool "Renesas MTU2 timer driver" if COMPILE_TEST
167 depends on GENERIC_CLOCKEVENTS
168 default SYS_SUPPORTS_SH_MTU2
169 help
170 This enables build of a clockevent driver for the Multi-Function
171 Timer Pulse Unit 2 (TMU2) hardware available on SoCs from Renesas.
172 This hardware comes with 16 bit-timer registers.
173
174config SH_TIMER_TMU
175 bool "Renesas TMU timer driver" if COMPILE_TEST
176 depends on GENERIC_CLOCKEVENTS
177 default SYS_SUPPORTS_SH_TMU
178 help
179 This enables build of a clocksource and clockevent driver for
180 the 32-bit Timer Unit (TMU) hardware available on a wide range
181 SoCs from Renesas.
182
183config EM_TIMER_STI
184 bool "Renesas STI timer driver" if COMPILE_TEST
185 depends on GENERIC_CLOCKEVENTS
186 default SYS_SUPPORTS_EM_STI
187 help
188 This enables build of a clocksource and clockevent driver for
189 the 48-bit System Timer (STI) hardware available on a SoCs
190 such as EMEV2 from former NEC Electronics.
diff --git a/drivers/clocksource/Makefile b/drivers/clocksource/Makefile
index c7ca50a9c232..aed3488d9426 100644
--- a/drivers/clocksource/Makefile
+++ b/drivers/clocksource/Makefile
@@ -21,6 +21,7 @@ obj-$(CONFIG_ARCH_MARCO) += timer-marco.o
21obj-$(CONFIG_ARCH_MOXART) += moxart_timer.o 21obj-$(CONFIG_ARCH_MOXART) += moxart_timer.o
22obj-$(CONFIG_ARCH_MXS) += mxs_timer.o 22obj-$(CONFIG_ARCH_MXS) += mxs_timer.o
23obj-$(CONFIG_ARCH_PRIMA2) += timer-prima2.o 23obj-$(CONFIG_ARCH_PRIMA2) += timer-prima2.o
24obj-$(CONFIG_ARCH_U300) += timer-u300.o
24obj-$(CONFIG_SUN4I_TIMER) += sun4i_timer.o 25obj-$(CONFIG_SUN4I_TIMER) += sun4i_timer.o
25obj-$(CONFIG_SUN5I_HSTIMER) += timer-sun5i.o 26obj-$(CONFIG_SUN5I_HSTIMER) += timer-sun5i.o
26obj-$(CONFIG_ARCH_TEGRA) += tegra20_timer.o 27obj-$(CONFIG_ARCH_TEGRA) += tegra20_timer.o
@@ -37,3 +38,4 @@ obj-$(CONFIG_ARM_ARCH_TIMER) += arm_arch_timer.o
37obj-$(CONFIG_ARM_GLOBAL_TIMER) += arm_global_timer.o 38obj-$(CONFIG_ARM_GLOBAL_TIMER) += arm_global_timer.o
38obj-$(CONFIG_CLKSRC_METAG_GENERIC) += metag_generic.o 39obj-$(CONFIG_CLKSRC_METAG_GENERIC) += metag_generic.o
39obj-$(CONFIG_ARCH_HAS_TICK_BROADCAST) += dummy_timer.o 40obj-$(CONFIG_ARCH_HAS_TICK_BROADCAST) += dummy_timer.o
41obj-$(CONFIG_ARCH_KEYSTONE) += timer-keystone.o
diff --git a/drivers/clocksource/arm_arch_timer.c b/drivers/clocksource/arm_arch_timer.c
index 95fb944e15ee..57e823c44d2a 100644
--- a/drivers/clocksource/arm_arch_timer.c
+++ b/drivers/clocksource/arm_arch_timer.c
@@ -277,6 +277,7 @@ static void __arch_timer_setup(unsigned type,
277 clk->set_next_event = arch_timer_set_next_event_phys; 277 clk->set_next_event = arch_timer_set_next_event_phys;
278 } 278 }
279 } else { 279 } else {
280 clk->features |= CLOCK_EVT_FEAT_DYNIRQ;
280 clk->name = "arch_mem_timer"; 281 clk->name = "arch_mem_timer";
281 clk->rating = 400; 282 clk->rating = 400;
282 clk->cpumask = cpu_all_mask; 283 clk->cpumask = cpu_all_mask;
diff --git a/drivers/clocksource/cadence_ttc_timer.c b/drivers/clocksource/cadence_ttc_timer.c
index 63f176de0d02..49fbe2847c84 100644
--- a/drivers/clocksource/cadence_ttc_timer.c
+++ b/drivers/clocksource/cadence_ttc_timer.c
@@ -16,6 +16,7 @@
16 */ 16 */
17 17
18#include <linux/clk.h> 18#include <linux/clk.h>
19#include <linux/clk-provider.h>
19#include <linux/interrupt.h> 20#include <linux/interrupt.h>
20#include <linux/clockchips.h> 21#include <linux/clockchips.h>
21#include <linux/of_address.h> 22#include <linux/of_address.h>
@@ -52,6 +53,8 @@
52#define TTC_CNT_CNTRL_DISABLE_MASK 0x1 53#define TTC_CNT_CNTRL_DISABLE_MASK 0x1
53 54
54#define TTC_CLK_CNTRL_CSRC_MASK (1 << 5) /* clock source */ 55#define TTC_CLK_CNTRL_CSRC_MASK (1 << 5) /* clock source */
56#define TTC_CLK_CNTRL_PSV_MASK 0x1e
57#define TTC_CLK_CNTRL_PSV_SHIFT 1
55 58
56/* 59/*
57 * Setup the timers to use pre-scaling, using a fixed value for now that will 60 * Setup the timers to use pre-scaling, using a fixed value for now that will
@@ -63,6 +66,8 @@
63#define CLK_CNTRL_PRESCALE_EN 1 66#define CLK_CNTRL_PRESCALE_EN 1
64#define CNT_CNTRL_RESET (1 << 4) 67#define CNT_CNTRL_RESET (1 << 4)
65 68
69#define MAX_F_ERR 50
70
66/** 71/**
67 * struct ttc_timer - This definition defines local timer structure 72 * struct ttc_timer - This definition defines local timer structure
68 * 73 *
@@ -82,6 +87,8 @@ struct ttc_timer {
82 container_of(x, struct ttc_timer, clk_rate_change_nb) 87 container_of(x, struct ttc_timer, clk_rate_change_nb)
83 88
84struct ttc_timer_clocksource { 89struct ttc_timer_clocksource {
90 u32 scale_clk_ctrl_reg_old;
91 u32 scale_clk_ctrl_reg_new;
85 struct ttc_timer ttc; 92 struct ttc_timer ttc;
86 struct clocksource cs; 93 struct clocksource cs;
87}; 94};
@@ -229,32 +236,89 @@ static int ttc_rate_change_clocksource_cb(struct notifier_block *nb,
229 struct ttc_timer_clocksource, ttc); 236 struct ttc_timer_clocksource, ttc);
230 237
231 switch (event) { 238 switch (event) {
232 case POST_RATE_CHANGE: 239 case PRE_RATE_CHANGE:
240 {
241 u32 psv;
242 unsigned long factor, rate_low, rate_high;
243
244 if (ndata->new_rate > ndata->old_rate) {
245 factor = DIV_ROUND_CLOSEST(ndata->new_rate,
246 ndata->old_rate);
247 rate_low = ndata->old_rate;
248 rate_high = ndata->new_rate;
249 } else {
250 factor = DIV_ROUND_CLOSEST(ndata->old_rate,
251 ndata->new_rate);
252 rate_low = ndata->new_rate;
253 rate_high = ndata->old_rate;
254 }
255
256 if (!is_power_of_2(factor))
257 return NOTIFY_BAD;
258
259 if (abs(rate_high - (factor * rate_low)) > MAX_F_ERR)
260 return NOTIFY_BAD;
261
262 factor = __ilog2_u32(factor);
263
233 /* 264 /*
234 * Do whatever is necessary to maintain a proper time base 265 * store timer clock ctrl register so we can restore it in case
235 * 266 * of an abort.
236 * I cannot find a way to adjust the currently used clocksource
237 * to the new frequency. __clocksource_updatefreq_hz() sounds
238 * good, but does not work. Not sure what's that missing.
239 *
240 * This approach works, but triggers two clocksource switches.
241 * The first after unregister to clocksource jiffies. And
242 * another one after the register to the newly registered timer.
243 *
244 * Alternatively we could 'waste' another HW timer to ping pong
245 * between clock sources. That would also use one register and
246 * one unregister call, but only trigger one clocksource switch
247 * for the cost of another HW timer used by the OS.
248 */ 267 */
249 clocksource_unregister(&ttccs->cs); 268 ttccs->scale_clk_ctrl_reg_old =
250 clocksource_register_hz(&ttccs->cs, 269 __raw_readl(ttccs->ttc.base_addr +
251 ndata->new_rate / PRESCALE); 270 TTC_CLK_CNTRL_OFFSET);
252 /* fall through */ 271
253 case PRE_RATE_CHANGE: 272 psv = (ttccs->scale_clk_ctrl_reg_old &
273 TTC_CLK_CNTRL_PSV_MASK) >>
274 TTC_CLK_CNTRL_PSV_SHIFT;
275 if (ndata->new_rate < ndata->old_rate)
276 psv -= factor;
277 else
278 psv += factor;
279
280 /* prescaler within legal range? */
281 if (psv & ~(TTC_CLK_CNTRL_PSV_MASK >> TTC_CLK_CNTRL_PSV_SHIFT))
282 return NOTIFY_BAD;
283
284 ttccs->scale_clk_ctrl_reg_new = ttccs->scale_clk_ctrl_reg_old &
285 ~TTC_CLK_CNTRL_PSV_MASK;
286 ttccs->scale_clk_ctrl_reg_new |= psv << TTC_CLK_CNTRL_PSV_SHIFT;
287
288
289 /* scale down: adjust divider in post-change notification */
290 if (ndata->new_rate < ndata->old_rate)
291 return NOTIFY_DONE;
292
293 /* scale up: adjust divider now - before frequency change */
294 __raw_writel(ttccs->scale_clk_ctrl_reg_new,
295 ttccs->ttc.base_addr + TTC_CLK_CNTRL_OFFSET);
296 break;
297 }
298 case POST_RATE_CHANGE:
299 /* scale up: pre-change notification did the adjustment */
300 if (ndata->new_rate > ndata->old_rate)
301 return NOTIFY_OK;
302
303 /* scale down: adjust divider now - after frequency change */
304 __raw_writel(ttccs->scale_clk_ctrl_reg_new,
305 ttccs->ttc.base_addr + TTC_CLK_CNTRL_OFFSET);
306 break;
307
254 case ABORT_RATE_CHANGE: 308 case ABORT_RATE_CHANGE:
309 /* we have to undo the adjustment in case we scale up */
310 if (ndata->new_rate < ndata->old_rate)
311 return NOTIFY_OK;
312
313 /* restore original register value */
314 __raw_writel(ttccs->scale_clk_ctrl_reg_old,
315 ttccs->ttc.base_addr + TTC_CLK_CNTRL_OFFSET);
316 /* fall through */
255 default: 317 default:
256 return NOTIFY_DONE; 318 return NOTIFY_DONE;
257 } 319 }
320
321 return NOTIFY_DONE;
258} 322}
259 323
260static void __init ttc_setup_clocksource(struct clk *clk, void __iomem *base) 324static void __init ttc_setup_clocksource(struct clk *clk, void __iomem *base)
@@ -321,25 +385,12 @@ static int ttc_rate_change_clockevent_cb(struct notifier_block *nb,
321 385
322 switch (event) { 386 switch (event) {
323 case POST_RATE_CHANGE: 387 case POST_RATE_CHANGE:
324 {
325 unsigned long flags;
326
327 /*
328 * clockevents_update_freq should be called with IRQ disabled on
329 * the CPU the timer provides events for. The timer we use is
330 * common to both CPUs, not sure if we need to run on both
331 * cores.
332 */
333 local_irq_save(flags);
334 clockevents_update_freq(&ttcce->ce,
335 ndata->new_rate / PRESCALE);
336 local_irq_restore(flags);
337
338 /* update cached frequency */ 388 /* update cached frequency */
339 ttc->freq = ndata->new_rate; 389 ttc->freq = ndata->new_rate;
340 390
391 clockevents_update_freq(&ttcce->ce, ndata->new_rate / PRESCALE);
392
341 /* fall through */ 393 /* fall through */
342 }
343 case PRE_RATE_CHANGE: 394 case PRE_RATE_CHANGE:
344 case ABORT_RATE_CHANGE: 395 case ABORT_RATE_CHANGE:
345 default: 396 default:
diff --git a/drivers/clocksource/exynos_mct.c b/drivers/clocksource/exynos_mct.c
index 48f76bc05da0..c2e390efbdca 100644
--- a/drivers/clocksource/exynos_mct.c
+++ b/drivers/clocksource/exynos_mct.c
@@ -410,7 +410,7 @@ static int exynos4_local_timer_setup(struct clock_event_device *evt)
410 mevt = container_of(evt, struct mct_clock_event_device, evt); 410 mevt = container_of(evt, struct mct_clock_event_device, evt);
411 411
412 mevt->base = EXYNOS4_MCT_L_BASE(cpu); 412 mevt->base = EXYNOS4_MCT_L_BASE(cpu);
413 sprintf(mevt->name, "mct_tick%d", cpu); 413 snprintf(mevt->name, sizeof(mevt->name), "mct_tick%d", cpu);
414 414
415 evt->name = mevt->name; 415 evt->name = mevt->name;
416 evt->cpumask = cpumask_of(cpu); 416 evt->cpumask = cpumask_of(cpu);
diff --git a/drivers/clocksource/sun4i_timer.c b/drivers/clocksource/sun4i_timer.c
index bf497afba9ad..efb17c3ee120 100644
--- a/drivers/clocksource/sun4i_timer.c
+++ b/drivers/clocksource/sun4i_timer.c
@@ -196,5 +196,5 @@ static void __init sun4i_timer_init(struct device_node *node)
196 clockevents_config_and_register(&sun4i_clockevent, rate, 196 clockevents_config_and_register(&sun4i_clockevent, rate,
197 TIMER_SYNC_TICKS, 0xffffffff); 197 TIMER_SYNC_TICKS, 0xffffffff);
198} 198}
199CLOCKSOURCE_OF_DECLARE(sun4i, "allwinner,sun4i-timer", 199CLOCKSOURCE_OF_DECLARE(sun4i, "allwinner,sun4i-a10-timer",
200 sun4i_timer_init); 200 sun4i_timer_init);
diff --git a/drivers/clocksource/time-armada-370-xp.c b/drivers/clocksource/time-armada-370-xp.c
index ee8691b89944..0451e62fac7a 100644
--- a/drivers/clocksource/time-armada-370-xp.c
+++ b/drivers/clocksource/time-armada-370-xp.c
@@ -85,12 +85,6 @@ static u32 ticks_per_jiffy;
85 85
86static struct clock_event_device __percpu *armada_370_xp_evt; 86static struct clock_event_device __percpu *armada_370_xp_evt;
87 87
88static void timer_ctrl_clrset(u32 clr, u32 set)
89{
90 writel((readl(timer_base + TIMER_CTRL_OFF) & ~clr) | set,
91 timer_base + TIMER_CTRL_OFF);
92}
93
94static void local_timer_ctrl_clrset(u32 clr, u32 set) 88static void local_timer_ctrl_clrset(u32 clr, u32 set)
95{ 89{
96 writel((readl(local_base + TIMER_CTRL_OFF) & ~clr) | set, 90 writel((readl(local_base + TIMER_CTRL_OFF) & ~clr) | set,
@@ -245,7 +239,7 @@ static void __init armada_370_xp_timer_common_init(struct device_node *np)
245 clr = TIMER0_25MHZ; 239 clr = TIMER0_25MHZ;
246 enable_mask = TIMER0_EN | TIMER0_DIV(TIMER_DIVIDER_SHIFT); 240 enable_mask = TIMER0_EN | TIMER0_DIV(TIMER_DIVIDER_SHIFT);
247 } 241 }
248 timer_ctrl_clrset(clr, set); 242 atomic_io_modify(timer_base + TIMER_CTRL_OFF, clr | set, set);
249 local_timer_ctrl_clrset(clr, set); 243 local_timer_ctrl_clrset(clr, set);
250 244
251 /* 245 /*
@@ -263,7 +257,9 @@ static void __init armada_370_xp_timer_common_init(struct device_node *np)
263 writel(0xffffffff, timer_base + TIMER0_VAL_OFF); 257 writel(0xffffffff, timer_base + TIMER0_VAL_OFF);
264 writel(0xffffffff, timer_base + TIMER0_RELOAD_OFF); 258 writel(0xffffffff, timer_base + TIMER0_RELOAD_OFF);
265 259
266 timer_ctrl_clrset(0, TIMER0_RELOAD_EN | enable_mask); 260 atomic_io_modify(timer_base + TIMER_CTRL_OFF,
261 TIMER0_RELOAD_EN | enable_mask,
262 TIMER0_RELOAD_EN | enable_mask);
267 263
268 /* 264 /*
269 * Set scale and timer for sched_clock. 265 * Set scale and timer for sched_clock.
diff --git a/drivers/clocksource/time-orion.c b/drivers/clocksource/time-orion.c
index 20066222f3f2..0b3ce0399c51 100644
--- a/drivers/clocksource/time-orion.c
+++ b/drivers/clocksource/time-orion.c
@@ -35,20 +35,6 @@
35#define ORION_ONESHOT_MAX 0xfffffffe 35#define ORION_ONESHOT_MAX 0xfffffffe
36 36
37static void __iomem *timer_base; 37static void __iomem *timer_base;
38static DEFINE_SPINLOCK(timer_ctrl_lock);
39
40/*
41 * Thread-safe access to TIMER_CTRL register
42 * (shared with watchdog timer)
43 */
44void orion_timer_ctrl_clrset(u32 clr, u32 set)
45{
46 spin_lock(&timer_ctrl_lock);
47 writel((readl(timer_base + TIMER_CTRL) & ~clr) | set,
48 timer_base + TIMER_CTRL);
49 spin_unlock(&timer_ctrl_lock);
50}
51EXPORT_SYMBOL(orion_timer_ctrl_clrset);
52 38
53/* 39/*
54 * Free-running clocksource handling. 40 * Free-running clocksource handling.
@@ -68,7 +54,8 @@ static int orion_clkevt_next_event(unsigned long delta,
68{ 54{
69 /* setup and enable one-shot timer */ 55 /* setup and enable one-shot timer */
70 writel(delta, timer_base + TIMER1_VAL); 56 writel(delta, timer_base + TIMER1_VAL);
71 orion_timer_ctrl_clrset(TIMER1_RELOAD_EN, TIMER1_EN); 57 atomic_io_modify(timer_base + TIMER_CTRL,
58 TIMER1_RELOAD_EN | TIMER1_EN, TIMER1_EN);
72 59
73 return 0; 60 return 0;
74} 61}
@@ -80,10 +67,13 @@ static void orion_clkevt_mode(enum clock_event_mode mode,
80 /* setup and enable periodic timer at 1/HZ intervals */ 67 /* setup and enable periodic timer at 1/HZ intervals */
81 writel(ticks_per_jiffy - 1, timer_base + TIMER1_RELOAD); 68 writel(ticks_per_jiffy - 1, timer_base + TIMER1_RELOAD);
82 writel(ticks_per_jiffy - 1, timer_base + TIMER1_VAL); 69 writel(ticks_per_jiffy - 1, timer_base + TIMER1_VAL);
83 orion_timer_ctrl_clrset(0, TIMER1_RELOAD_EN | TIMER1_EN); 70 atomic_io_modify(timer_base + TIMER_CTRL,
71 TIMER1_RELOAD_EN | TIMER1_EN,
72 TIMER1_RELOAD_EN | TIMER1_EN);
84 } else { 73 } else {
85 /* disable timer */ 74 /* disable timer */
86 orion_timer_ctrl_clrset(TIMER1_RELOAD_EN | TIMER1_EN, 0); 75 atomic_io_modify(timer_base + TIMER_CTRL,
76 TIMER1_RELOAD_EN | TIMER1_EN, 0);
87 } 77 }
88} 78}
89 79
@@ -131,7 +121,9 @@ static void __init orion_timer_init(struct device_node *np)
131 /* setup timer0 as free-running clocksource */ 121 /* setup timer0 as free-running clocksource */
132 writel(~0, timer_base + TIMER0_VAL); 122 writel(~0, timer_base + TIMER0_VAL);
133 writel(~0, timer_base + TIMER0_RELOAD); 123 writel(~0, timer_base + TIMER0_RELOAD);
134 orion_timer_ctrl_clrset(0, TIMER0_RELOAD_EN | TIMER0_EN); 124 atomic_io_modify(timer_base + TIMER_CTRL,
125 TIMER0_RELOAD_EN | TIMER0_EN,
126 TIMER0_RELOAD_EN | TIMER0_EN);
135 clocksource_mmio_init(timer_base + TIMER0_VAL, "orion_clocksource", 127 clocksource_mmio_init(timer_base + TIMER0_VAL, "orion_clocksource",
136 clk_get_rate(clk), 300, 32, 128 clk_get_rate(clk), 300, 32,
137 clocksource_mmio_readl_down); 129 clocksource_mmio_readl_down);
diff --git a/drivers/clocksource/timer-keystone.c b/drivers/clocksource/timer-keystone.c
new file mode 100644
index 000000000000..0250354f7e55
--- /dev/null
+++ b/drivers/clocksource/timer-keystone.c
@@ -0,0 +1,241 @@
1/*
2 * Keystone broadcast clock-event
3 *
4 * Copyright 2013 Texas Instruments, Inc.
5 *
6 * Author: Ivan Khoronzhuk <ivan.khoronzhuk@ti.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 version 2 as
10 * published by the Free Software Foundation.
11 *
12 */
13
14#include <linux/clk.h>
15#include <linux/clockchips.h>
16#include <linux/clocksource.h>
17#include <linux/interrupt.h>
18#include <linux/of_address.h>
19#include <linux/of_irq.h>
20
21#define TIMER_NAME "timer-keystone"
22
23/* Timer register offsets */
24#define TIM12 0x10
25#define TIM34 0x14
26#define PRD12 0x18
27#define PRD34 0x1c
28#define TCR 0x20
29#define TGCR 0x24
30#define INTCTLSTAT 0x44
31
32/* Timer register bitfields */
33#define TCR_ENAMODE_MASK 0xC0
34#define TCR_ENAMODE_ONESHOT_MASK 0x40
35#define TCR_ENAMODE_PERIODIC_MASK 0x80
36
37#define TGCR_TIM_UNRESET_MASK 0x03
38#define INTCTLSTAT_ENINT_MASK 0x01
39
40/**
41 * struct keystone_timer: holds timer's data
42 * @base: timer memory base address
43 * @hz_period: cycles per HZ period
44 * @event_dev: event device based on timer
45 */
46static struct keystone_timer {
47 void __iomem *base;
48 unsigned long hz_period;
49 struct clock_event_device event_dev;
50} timer;
51
52static inline u32 keystone_timer_readl(unsigned long rg)
53{
54 return readl_relaxed(timer.base + rg);
55}
56
57static inline void keystone_timer_writel(u32 val, unsigned long rg)
58{
59 writel_relaxed(val, timer.base + rg);
60}
61
62/**
63 * keystone_timer_barrier: write memory barrier
64 * use explicit barrier to avoid using readl/writel non relaxed function
65 * variants, because in our case non relaxed variants hide the true places
66 * where barrier is needed.
67 */
68static inline void keystone_timer_barrier(void)
69{
70 __iowmb();
71}
72
73/**
74 * keystone_timer_config: configures timer to work in oneshot/periodic modes.
75 * @ mode: mode to configure
76 * @ period: cycles number to configure for
77 */
78static int keystone_timer_config(u64 period, enum clock_event_mode mode)
79{
80 u32 tcr;
81 u32 off;
82
83 tcr = keystone_timer_readl(TCR);
84 off = tcr & ~(TCR_ENAMODE_MASK);
85
86 /* set enable mode */
87 switch (mode) {
88 case CLOCK_EVT_MODE_ONESHOT:
89 tcr |= TCR_ENAMODE_ONESHOT_MASK;
90 break;
91 case CLOCK_EVT_MODE_PERIODIC:
92 tcr |= TCR_ENAMODE_PERIODIC_MASK;
93 break;
94 default:
95 return -1;
96 }
97
98 /* disable timer */
99 keystone_timer_writel(off, TCR);
100 /* here we have to be sure the timer has been disabled */
101 keystone_timer_barrier();
102
103 /* reset counter to zero, set new period */
104 keystone_timer_writel(0, TIM12);
105 keystone_timer_writel(0, TIM34);
106 keystone_timer_writel(period & 0xffffffff, PRD12);
107 keystone_timer_writel(period >> 32, PRD34);
108
109 /*
110 * enable timer
111 * here we have to be sure that CNTLO, CNTHI, PRDLO, PRDHI registers
112 * have been written.
113 */
114 keystone_timer_barrier();
115 keystone_timer_writel(tcr, TCR);
116 return 0;
117}
118
119static void keystone_timer_disable(void)
120{
121 u32 tcr;
122
123 tcr = keystone_timer_readl(TCR);
124
125 /* disable timer */
126 tcr &= ~(TCR_ENAMODE_MASK);
127 keystone_timer_writel(tcr, TCR);
128}
129
130static irqreturn_t keystone_timer_interrupt(int irq, void *dev_id)
131{
132 struct clock_event_device *evt = dev_id;
133
134 evt->event_handler(evt);
135 return IRQ_HANDLED;
136}
137
138static int keystone_set_next_event(unsigned long cycles,
139 struct clock_event_device *evt)
140{
141 return keystone_timer_config(cycles, evt->mode);
142}
143
144static void keystone_set_mode(enum clock_event_mode mode,
145 struct clock_event_device *evt)
146{
147 switch (mode) {
148 case CLOCK_EVT_MODE_PERIODIC:
149 keystone_timer_config(timer.hz_period, CLOCK_EVT_MODE_PERIODIC);
150 break;
151 case CLOCK_EVT_MODE_UNUSED:
152 case CLOCK_EVT_MODE_SHUTDOWN:
153 case CLOCK_EVT_MODE_ONESHOT:
154 keystone_timer_disable();
155 break;
156 default:
157 break;
158 }
159}
160
161static void __init keystone_timer_init(struct device_node *np)
162{
163 struct clock_event_device *event_dev = &timer.event_dev;
164 unsigned long rate;
165 struct clk *clk;
166 int irq, error;
167
168 irq = irq_of_parse_and_map(np, 0);
169 if (irq == NO_IRQ) {
170 pr_err("%s: failed to map interrupts\n", __func__);
171 return;
172 }
173
174 timer.base = of_iomap(np, 0);
175 if (!timer.base) {
176 pr_err("%s: failed to map registers\n", __func__);
177 return;
178 }
179
180 clk = of_clk_get(np, 0);
181 if (IS_ERR(clk)) {
182 pr_err("%s: failed to get clock\n", __func__);
183 iounmap(timer.base);
184 return;
185 }
186
187 error = clk_prepare_enable(clk);
188 if (error) {
189 pr_err("%s: failed to enable clock\n", __func__);
190 goto err;
191 }
192
193 rate = clk_get_rate(clk);
194
195 /* disable, use internal clock source */
196 keystone_timer_writel(0, TCR);
197 /* here we have to be sure the timer has been disabled */
198 keystone_timer_barrier();
199
200 /* reset timer as 64-bit, no pre-scaler, plus features are disabled */
201 keystone_timer_writel(0, TGCR);
202
203 /* unreset timer */
204 keystone_timer_writel(TGCR_TIM_UNRESET_MASK, TGCR);
205
206 /* init counter to zero */
207 keystone_timer_writel(0, TIM12);
208 keystone_timer_writel(0, TIM34);
209
210 timer.hz_period = DIV_ROUND_UP(rate, HZ);
211
212 /* enable timer interrupts */
213 keystone_timer_writel(INTCTLSTAT_ENINT_MASK, INTCTLSTAT);
214
215 error = request_irq(irq, keystone_timer_interrupt, IRQF_TIMER,
216 TIMER_NAME, event_dev);
217 if (error) {
218 pr_err("%s: failed to setup irq\n", __func__);
219 goto err;
220 }
221
222 /* setup clockevent */
223 event_dev->features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT;
224 event_dev->set_next_event = keystone_set_next_event;
225 event_dev->set_mode = keystone_set_mode;
226 event_dev->cpumask = cpu_all_mask;
227 event_dev->owner = THIS_MODULE;
228 event_dev->name = TIMER_NAME;
229 event_dev->irq = irq;
230
231 clockevents_config_and_register(event_dev, rate, 1, ULONG_MAX);
232
233 pr_info("keystone timer clock @%lu Hz\n", rate);
234 return;
235err:
236 clk_put(clk);
237 iounmap(timer.base);
238}
239
240CLOCKSOURCE_OF_DECLARE(keystone_timer, "ti,keystone-timer",
241 keystone_timer_init);
diff --git a/drivers/clocksource/timer-u300.c b/drivers/clocksource/timer-u300.c
new file mode 100644
index 000000000000..e63d469661fd
--- /dev/null
+++ b/drivers/clocksource/timer-u300.c
@@ -0,0 +1,447 @@
1/*
2 * Copyright (C) 2007-2009 ST-Ericsson AB
3 * License terms: GNU General Public License (GPL) version 2
4 * Timer COH 901 328, runs the OS timer interrupt.
5 * Author: Linus Walleij <linus.walleij@stericsson.com>
6 */
7#include <linux/interrupt.h>
8#include <linux/time.h>
9#include <linux/timex.h>
10#include <linux/clockchips.h>
11#include <linux/clocksource.h>
12#include <linux/types.h>
13#include <linux/io.h>
14#include <linux/clk.h>
15#include <linux/err.h>
16#include <linux/irq.h>
17#include <linux/delay.h>
18#include <linux/of_address.h>
19#include <linux/of_irq.h>
20#include <linux/sched_clock.h>
21
22/* Generic stuff */
23#include <asm/mach/map.h>
24#include <asm/mach/time.h>
25
26/*
27 * APP side special timer registers
28 * This timer contains four timers which can fire an interrupt each.
29 * OS (operating system) timer @ 32768 Hz
30 * DD (device driver) timer @ 1 kHz
31 * GP1 (general purpose 1) timer @ 1MHz
32 * GP2 (general purpose 2) timer @ 1MHz
33 */
34
35/* Reset OS Timer 32bit (-/W) */
36#define U300_TIMER_APP_ROST (0x0000)
37#define U300_TIMER_APP_ROST_TIMER_RESET (0x00000000)
38/* Enable OS Timer 32bit (-/W) */
39#define U300_TIMER_APP_EOST (0x0004)
40#define U300_TIMER_APP_EOST_TIMER_ENABLE (0x00000000)
41/* Disable OS Timer 32bit (-/W) */
42#define U300_TIMER_APP_DOST (0x0008)
43#define U300_TIMER_APP_DOST_TIMER_DISABLE (0x00000000)
44/* OS Timer Mode Register 32bit (-/W) */
45#define U300_TIMER_APP_SOSTM (0x000c)
46#define U300_TIMER_APP_SOSTM_MODE_CONTINUOUS (0x00000000)
47#define U300_TIMER_APP_SOSTM_MODE_ONE_SHOT (0x00000001)
48/* OS Timer Status Register 32bit (R/-) */
49#define U300_TIMER_APP_OSTS (0x0010)
50#define U300_TIMER_APP_OSTS_TIMER_STATE_MASK (0x0000000F)
51#define U300_TIMER_APP_OSTS_TIMER_STATE_IDLE (0x00000001)
52#define U300_TIMER_APP_OSTS_TIMER_STATE_ACTIVE (0x00000002)
53#define U300_TIMER_APP_OSTS_ENABLE_IND (0x00000010)
54#define U300_TIMER_APP_OSTS_MODE_MASK (0x00000020)
55#define U300_TIMER_APP_OSTS_MODE_CONTINUOUS (0x00000000)
56#define U300_TIMER_APP_OSTS_MODE_ONE_SHOT (0x00000020)
57#define U300_TIMER_APP_OSTS_IRQ_ENABLED_IND (0x00000040)
58#define U300_TIMER_APP_OSTS_IRQ_PENDING_IND (0x00000080)
59/* OS Timer Current Count Register 32bit (R/-) */
60#define U300_TIMER_APP_OSTCC (0x0014)
61/* OS Timer Terminal Count Register 32bit (R/W) */
62#define U300_TIMER_APP_OSTTC (0x0018)
63/* OS Timer Interrupt Enable Register 32bit (-/W) */
64#define U300_TIMER_APP_OSTIE (0x001c)
65#define U300_TIMER_APP_OSTIE_IRQ_DISABLE (0x00000000)
66#define U300_TIMER_APP_OSTIE_IRQ_ENABLE (0x00000001)
67/* OS Timer Interrupt Acknowledge Register 32bit (-/W) */
68#define U300_TIMER_APP_OSTIA (0x0020)
69#define U300_TIMER_APP_OSTIA_IRQ_ACK (0x00000080)
70
71/* Reset DD Timer 32bit (-/W) */
72#define U300_TIMER_APP_RDDT (0x0040)
73#define U300_TIMER_APP_RDDT_TIMER_RESET (0x00000000)
74/* Enable DD Timer 32bit (-/W) */
75#define U300_TIMER_APP_EDDT (0x0044)
76#define U300_TIMER_APP_EDDT_TIMER_ENABLE (0x00000000)
77/* Disable DD Timer 32bit (-/W) */
78#define U300_TIMER_APP_DDDT (0x0048)
79#define U300_TIMER_APP_DDDT_TIMER_DISABLE (0x00000000)
80/* DD Timer Mode Register 32bit (-/W) */
81#define U300_TIMER_APP_SDDTM (0x004c)
82#define U300_TIMER_APP_SDDTM_MODE_CONTINUOUS (0x00000000)
83#define U300_TIMER_APP_SDDTM_MODE_ONE_SHOT (0x00000001)
84/* DD Timer Status Register 32bit (R/-) */
85#define U300_TIMER_APP_DDTS (0x0050)
86#define U300_TIMER_APP_DDTS_TIMER_STATE_MASK (0x0000000F)
87#define U300_TIMER_APP_DDTS_TIMER_STATE_IDLE (0x00000001)
88#define U300_TIMER_APP_DDTS_TIMER_STATE_ACTIVE (0x00000002)
89#define U300_TIMER_APP_DDTS_ENABLE_IND (0x00000010)
90#define U300_TIMER_APP_DDTS_MODE_MASK (0x00000020)
91#define U300_TIMER_APP_DDTS_MODE_CONTINUOUS (0x00000000)
92#define U300_TIMER_APP_DDTS_MODE_ONE_SHOT (0x00000020)
93#define U300_TIMER_APP_DDTS_IRQ_ENABLED_IND (0x00000040)
94#define U300_TIMER_APP_DDTS_IRQ_PENDING_IND (0x00000080)
95/* DD Timer Current Count Register 32bit (R/-) */
96#define U300_TIMER_APP_DDTCC (0x0054)
97/* DD Timer Terminal Count Register 32bit (R/W) */
98#define U300_TIMER_APP_DDTTC (0x0058)
99/* DD Timer Interrupt Enable Register 32bit (-/W) */
100#define U300_TIMER_APP_DDTIE (0x005c)
101#define U300_TIMER_APP_DDTIE_IRQ_DISABLE (0x00000000)
102#define U300_TIMER_APP_DDTIE_IRQ_ENABLE (0x00000001)
103/* DD Timer Interrupt Acknowledge Register 32bit (-/W) */
104#define U300_TIMER_APP_DDTIA (0x0060)
105#define U300_TIMER_APP_DDTIA_IRQ_ACK (0x00000080)
106
107/* Reset GP1 Timer 32bit (-/W) */
108#define U300_TIMER_APP_RGPT1 (0x0080)
109#define U300_TIMER_APP_RGPT1_TIMER_RESET (0x00000000)
110/* Enable GP1 Timer 32bit (-/W) */
111#define U300_TIMER_APP_EGPT1 (0x0084)
112#define U300_TIMER_APP_EGPT1_TIMER_ENABLE (0x00000000)
113/* Disable GP1 Timer 32bit (-/W) */
114#define U300_TIMER_APP_DGPT1 (0x0088)
115#define U300_TIMER_APP_DGPT1_TIMER_DISABLE (0x00000000)
116/* GP1 Timer Mode Register 32bit (-/W) */
117#define U300_TIMER_APP_SGPT1M (0x008c)
118#define U300_TIMER_APP_SGPT1M_MODE_CONTINUOUS (0x00000000)
119#define U300_TIMER_APP_SGPT1M_MODE_ONE_SHOT (0x00000001)
120/* GP1 Timer Status Register 32bit (R/-) */
121#define U300_TIMER_APP_GPT1S (0x0090)
122#define U300_TIMER_APP_GPT1S_TIMER_STATE_MASK (0x0000000F)
123#define U300_TIMER_APP_GPT1S_TIMER_STATE_IDLE (0x00000001)
124#define U300_TIMER_APP_GPT1S_TIMER_STATE_ACTIVE (0x00000002)
125#define U300_TIMER_APP_GPT1S_ENABLE_IND (0x00000010)
126#define U300_TIMER_APP_GPT1S_MODE_MASK (0x00000020)
127#define U300_TIMER_APP_GPT1S_MODE_CONTINUOUS (0x00000000)
128#define U300_TIMER_APP_GPT1S_MODE_ONE_SHOT (0x00000020)
129#define U300_TIMER_APP_GPT1S_IRQ_ENABLED_IND (0x00000040)
130#define U300_TIMER_APP_GPT1S_IRQ_PENDING_IND (0x00000080)
131/* GP1 Timer Current Count Register 32bit (R/-) */
132#define U300_TIMER_APP_GPT1CC (0x0094)
133/* GP1 Timer Terminal Count Register 32bit (R/W) */
134#define U300_TIMER_APP_GPT1TC (0x0098)
135/* GP1 Timer Interrupt Enable Register 32bit (-/W) */
136#define U300_TIMER_APP_GPT1IE (0x009c)
137#define U300_TIMER_APP_GPT1IE_IRQ_DISABLE (0x00000000)
138#define U300_TIMER_APP_GPT1IE_IRQ_ENABLE (0x00000001)
139/* GP1 Timer Interrupt Acknowledge Register 32bit (-/W) */
140#define U300_TIMER_APP_GPT1IA (0x00a0)
141#define U300_TIMER_APP_GPT1IA_IRQ_ACK (0x00000080)
142
143/* Reset GP2 Timer 32bit (-/W) */
144#define U300_TIMER_APP_RGPT2 (0x00c0)
145#define U300_TIMER_APP_RGPT2_TIMER_RESET (0x00000000)
146/* Enable GP2 Timer 32bit (-/W) */
147#define U300_TIMER_APP_EGPT2 (0x00c4)
148#define U300_TIMER_APP_EGPT2_TIMER_ENABLE (0x00000000)
149/* Disable GP2 Timer 32bit (-/W) */
150#define U300_TIMER_APP_DGPT2 (0x00c8)
151#define U300_TIMER_APP_DGPT2_TIMER_DISABLE (0x00000000)
152/* GP2 Timer Mode Register 32bit (-/W) */
153#define U300_TIMER_APP_SGPT2M (0x00cc)
154#define U300_TIMER_APP_SGPT2M_MODE_CONTINUOUS (0x00000000)
155#define U300_TIMER_APP_SGPT2M_MODE_ONE_SHOT (0x00000001)
156/* GP2 Timer Status Register 32bit (R/-) */
157#define U300_TIMER_APP_GPT2S (0x00d0)
158#define U300_TIMER_APP_GPT2S_TIMER_STATE_MASK (0x0000000F)
159#define U300_TIMER_APP_GPT2S_TIMER_STATE_IDLE (0x00000001)
160#define U300_TIMER_APP_GPT2S_TIMER_STATE_ACTIVE (0x00000002)
161#define U300_TIMER_APP_GPT2S_ENABLE_IND (0x00000010)
162#define U300_TIMER_APP_GPT2S_MODE_MASK (0x00000020)
163#define U300_TIMER_APP_GPT2S_MODE_CONTINUOUS (0x00000000)
164#define U300_TIMER_APP_GPT2S_MODE_ONE_SHOT (0x00000020)
165#define U300_TIMER_APP_GPT2S_IRQ_ENABLED_IND (0x00000040)
166#define U300_TIMER_APP_GPT2S_IRQ_PENDING_IND (0x00000080)
167/* GP2 Timer Current Count Register 32bit (R/-) */
168#define U300_TIMER_APP_GPT2CC (0x00d4)
169/* GP2 Timer Terminal Count Register 32bit (R/W) */
170#define U300_TIMER_APP_GPT2TC (0x00d8)
171/* GP2 Timer Interrupt Enable Register 32bit (-/W) */
172#define U300_TIMER_APP_GPT2IE (0x00dc)
173#define U300_TIMER_APP_GPT2IE_IRQ_DISABLE (0x00000000)
174#define U300_TIMER_APP_GPT2IE_IRQ_ENABLE (0x00000001)
175/* GP2 Timer Interrupt Acknowledge Register 32bit (-/W) */
176#define U300_TIMER_APP_GPT2IA (0x00e0)
177#define U300_TIMER_APP_GPT2IA_IRQ_ACK (0x00000080)
178
179/* Clock request control register - all four timers */
180#define U300_TIMER_APP_CRC (0x100)
181#define U300_TIMER_APP_CRC_CLOCK_REQUEST_ENABLE (0x00000001)
182
183static void __iomem *u300_timer_base;
184
185struct u300_clockevent_data {
186 struct clock_event_device cevd;
187 unsigned ticks_per_jiffy;
188};
189
190/*
191 * The u300_set_mode() function is always called first, if we
192 * have oneshot timer active, the oneshot scheduling function
193 * u300_set_next_event() is called immediately after.
194 */
195static void u300_set_mode(enum clock_event_mode mode,
196 struct clock_event_device *evt)
197{
198 struct u300_clockevent_data *cevdata =
199 container_of(evt, struct u300_clockevent_data, cevd);
200
201 switch (mode) {
202 case CLOCK_EVT_MODE_PERIODIC:
203 /* Disable interrupts on GPT1 */
204 writel(U300_TIMER_APP_GPT1IE_IRQ_DISABLE,
205 u300_timer_base + U300_TIMER_APP_GPT1IE);
206 /* Disable GP1 while we're reprogramming it. */
207 writel(U300_TIMER_APP_DGPT1_TIMER_DISABLE,
208 u300_timer_base + U300_TIMER_APP_DGPT1);
209 /*
210 * Set the periodic mode to a certain number of ticks per
211 * jiffy.
212 */
213 writel(cevdata->ticks_per_jiffy,
214 u300_timer_base + U300_TIMER_APP_GPT1TC);
215 /*
216 * Set continuous mode, so the timer keeps triggering
217 * interrupts.
218 */
219 writel(U300_TIMER_APP_SGPT1M_MODE_CONTINUOUS,
220 u300_timer_base + U300_TIMER_APP_SGPT1M);
221 /* Enable timer interrupts */
222 writel(U300_TIMER_APP_GPT1IE_IRQ_ENABLE,
223 u300_timer_base + U300_TIMER_APP_GPT1IE);
224 /* Then enable the OS timer again */
225 writel(U300_TIMER_APP_EGPT1_TIMER_ENABLE,
226 u300_timer_base + U300_TIMER_APP_EGPT1);
227 break;
228 case CLOCK_EVT_MODE_ONESHOT:
229 /* Just break; here? */
230 /*
231 * The actual event will be programmed by the next event hook,
232 * so we just set a dummy value somewhere at the end of the
233 * universe here.
234 */
235 /* Disable interrupts on GPT1 */
236 writel(U300_TIMER_APP_GPT1IE_IRQ_DISABLE,
237 u300_timer_base + U300_TIMER_APP_GPT1IE);
238 /* Disable GP1 while we're reprogramming it. */
239 writel(U300_TIMER_APP_DGPT1_TIMER_DISABLE,
240 u300_timer_base + U300_TIMER_APP_DGPT1);
241 /*
242 * Expire far in the future, u300_set_next_event() will be
243 * called soon...
244 */
245 writel(0xFFFFFFFF, u300_timer_base + U300_TIMER_APP_GPT1TC);
246 /* We run one shot per tick here! */
247 writel(U300_TIMER_APP_SGPT1M_MODE_ONE_SHOT,
248 u300_timer_base + U300_TIMER_APP_SGPT1M);
249 /* Enable interrupts for this timer */
250 writel(U300_TIMER_APP_GPT1IE_IRQ_ENABLE,
251 u300_timer_base + U300_TIMER_APP_GPT1IE);
252 /* Enable timer */
253 writel(U300_TIMER_APP_EGPT1_TIMER_ENABLE,
254 u300_timer_base + U300_TIMER_APP_EGPT1);
255 break;
256 case CLOCK_EVT_MODE_UNUSED:
257 case CLOCK_EVT_MODE_SHUTDOWN:
258 /* Disable interrupts on GP1 */
259 writel(U300_TIMER_APP_GPT1IE_IRQ_DISABLE,
260 u300_timer_base + U300_TIMER_APP_GPT1IE);
261 /* Disable GP1 */
262 writel(U300_TIMER_APP_DGPT1_TIMER_DISABLE,
263 u300_timer_base + U300_TIMER_APP_DGPT1);
264 break;
265 case CLOCK_EVT_MODE_RESUME:
266 /* Ignore this call */
267 break;
268 }
269}
270
271/*
272 * The app timer in one shot mode obviously has to be reprogrammed
273 * in EXACTLY this sequence to work properly. Do NOT try to e.g. replace
274 * the interrupt disable + timer disable commands with a reset command,
275 * it will fail miserably. Apparently (and I found this the hard way)
276 * the timer is very sensitive to the instruction order, though you don't
277 * get that impression from the data sheet.
278 */
279static int u300_set_next_event(unsigned long cycles,
280 struct clock_event_device *evt)
281
282{
283 /* Disable interrupts on GPT1 */
284 writel(U300_TIMER_APP_GPT1IE_IRQ_DISABLE,
285 u300_timer_base + U300_TIMER_APP_GPT1IE);
286 /* Disable GP1 while we're reprogramming it. */
287 writel(U300_TIMER_APP_DGPT1_TIMER_DISABLE,
288 u300_timer_base + U300_TIMER_APP_DGPT1);
289 /* Reset the General Purpose timer 1. */
290 writel(U300_TIMER_APP_RGPT1_TIMER_RESET,
291 u300_timer_base + U300_TIMER_APP_RGPT1);
292 /* IRQ in n * cycles */
293 writel(cycles, u300_timer_base + U300_TIMER_APP_GPT1TC);
294 /*
295 * We run one shot per tick here! (This is necessary to reconfigure,
296 * the timer will tilt if you don't!)
297 */
298 writel(U300_TIMER_APP_SGPT1M_MODE_ONE_SHOT,
299 u300_timer_base + U300_TIMER_APP_SGPT1M);
300 /* Enable timer interrupts */
301 writel(U300_TIMER_APP_GPT1IE_IRQ_ENABLE,
302 u300_timer_base + U300_TIMER_APP_GPT1IE);
303 /* Then enable the OS timer again */
304 writel(U300_TIMER_APP_EGPT1_TIMER_ENABLE,
305 u300_timer_base + U300_TIMER_APP_EGPT1);
306 return 0;
307}
308
309static struct u300_clockevent_data u300_clockevent_data = {
310 /* Use general purpose timer 1 as clock event */
311 .cevd = {
312 .name = "GPT1",
313 /* Reasonably fast and accurate clock event */
314 .rating = 300,
315 .features = CLOCK_EVT_FEAT_PERIODIC |
316 CLOCK_EVT_FEAT_ONESHOT,
317 .set_next_event = u300_set_next_event,
318 .set_mode = u300_set_mode,
319 },
320};
321
322/* Clock event timer interrupt handler */
323static irqreturn_t u300_timer_interrupt(int irq, void *dev_id)
324{
325 struct clock_event_device *evt = &u300_clockevent_data.cevd;
326 /* ACK/Clear timer IRQ for the APP GPT1 Timer */
327
328 writel(U300_TIMER_APP_GPT1IA_IRQ_ACK,
329 u300_timer_base + U300_TIMER_APP_GPT1IA);
330 evt->event_handler(evt);
331 return IRQ_HANDLED;
332}
333
334static struct irqaction u300_timer_irq = {
335 .name = "U300 Timer Tick",
336 .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
337 .handler = u300_timer_interrupt,
338};
339
340/*
341 * Override the global weak sched_clock symbol with this
342 * local implementation which uses the clocksource to get some
343 * better resolution when scheduling the kernel. We accept that
344 * this wraps around for now, since it is just a relative time
345 * stamp. (Inspired by OMAP implementation.)
346 */
347
348static u64 notrace u300_read_sched_clock(void)
349{
350 return readl(u300_timer_base + U300_TIMER_APP_GPT2CC);
351}
352
353static unsigned long u300_read_current_timer(void)
354{
355 return readl(u300_timer_base + U300_TIMER_APP_GPT2CC);
356}
357
358static struct delay_timer u300_delay_timer;
359
360/*
361 * This sets up the system timers, clock source and clock event.
362 */
363static void __init u300_timer_init_of(struct device_node *np)
364{
365 unsigned int irq;
366 struct clk *clk;
367 unsigned long rate;
368
369 u300_timer_base = of_iomap(np, 0);
370 if (!u300_timer_base)
371 panic("could not ioremap system timer\n");
372
373 /* Get the IRQ for the GP1 timer */
374 irq = irq_of_parse_and_map(np, 2);
375 if (!irq)
376 panic("no IRQ for system timer\n");
377
378 pr_info("U300 GP1 timer @ base: %p, IRQ: %u\n", u300_timer_base, irq);
379
380 /* Clock the interrupt controller */
381 clk = of_clk_get(np, 0);
382 BUG_ON(IS_ERR(clk));
383 clk_prepare_enable(clk);
384 rate = clk_get_rate(clk);
385
386 u300_clockevent_data.ticks_per_jiffy = DIV_ROUND_CLOSEST(rate, HZ);
387
388 sched_clock_register(u300_read_sched_clock, 32, rate);
389
390 u300_delay_timer.read_current_timer = &u300_read_current_timer;
391 u300_delay_timer.freq = rate;
392 register_current_timer_delay(&u300_delay_timer);
393
394 /*
395 * Disable the "OS" and "DD" timers - these are designed for Symbian!
396 * Example usage in cnh1601578 cpu subsystem pd_timer_app.c
397 */
398 writel(U300_TIMER_APP_CRC_CLOCK_REQUEST_ENABLE,
399 u300_timer_base + U300_TIMER_APP_CRC);
400 writel(U300_TIMER_APP_ROST_TIMER_RESET,
401 u300_timer_base + U300_TIMER_APP_ROST);
402 writel(U300_TIMER_APP_DOST_TIMER_DISABLE,
403 u300_timer_base + U300_TIMER_APP_DOST);
404 writel(U300_TIMER_APP_RDDT_TIMER_RESET,
405 u300_timer_base + U300_TIMER_APP_RDDT);
406 writel(U300_TIMER_APP_DDDT_TIMER_DISABLE,
407 u300_timer_base + U300_TIMER_APP_DDDT);
408
409 /* Reset the General Purpose timer 1. */
410 writel(U300_TIMER_APP_RGPT1_TIMER_RESET,
411 u300_timer_base + U300_TIMER_APP_RGPT1);
412
413 /* Set up the IRQ handler */
414 setup_irq(irq, &u300_timer_irq);
415
416 /* Reset the General Purpose timer 2 */
417 writel(U300_TIMER_APP_RGPT2_TIMER_RESET,
418 u300_timer_base + U300_TIMER_APP_RGPT2);
419 /* Set this timer to run around forever */
420 writel(0xFFFFFFFFU, u300_timer_base + U300_TIMER_APP_GPT2TC);
421 /* Set continuous mode so it wraps around */
422 writel(U300_TIMER_APP_SGPT2M_MODE_CONTINUOUS,
423 u300_timer_base + U300_TIMER_APP_SGPT2M);
424 /* Disable timer interrupts */
425 writel(U300_TIMER_APP_GPT2IE_IRQ_DISABLE,
426 u300_timer_base + U300_TIMER_APP_GPT2IE);
427 /* Then enable the GP2 timer to use as a free running us counter */
428 writel(U300_TIMER_APP_EGPT2_TIMER_ENABLE,
429 u300_timer_base + U300_TIMER_APP_EGPT2);
430
431 /* Use general purpose timer 2 as clock source */
432 if (clocksource_mmio_init(u300_timer_base + U300_TIMER_APP_GPT2CC,
433 "GPT2", rate, 300, 32, clocksource_mmio_readl_up))
434 pr_err("timer: failed to initialize U300 clock source\n");
435
436 /* Configure and register the clockevent */
437 clockevents_config_and_register(&u300_clockevent_data.cevd, rate,
438 1, 0xffffffff);
439
440 /*
441 * TODO: init and register the rest of the timers too, they can be
442 * used by hrtimers!
443 */
444}
445
446CLOCKSOURCE_OF_DECLARE(u300_timer, "stericsson,u300-apptimer",
447 u300_timer_init_of);
diff --git a/drivers/clocksource/vf_pit_timer.c b/drivers/clocksource/vf_pit_timer.c
index 02821b06a39e..a918bc481c52 100644
--- a/drivers/clocksource/vf_pit_timer.c
+++ b/drivers/clocksource/vf_pit_timer.c
@@ -54,7 +54,7 @@ static inline void pit_irq_acknowledge(void)
54 54
55static u64 pit_read_sched_clock(void) 55static u64 pit_read_sched_clock(void)
56{ 56{
57 return __raw_readl(clksrc_base + PITCVAL); 57 return ~__raw_readl(clksrc_base + PITCVAL);
58} 58}
59 59
60static int __init pit_clocksource_init(unsigned long rate) 60static int __init pit_clocksource_init(unsigned long rate)
diff --git a/drivers/cpufreq/Kconfig b/drivers/cpufreq/Kconfig
index 4b029c0944af..1fbe11f2a146 100644
--- a/drivers/cpufreq/Kconfig
+++ b/drivers/cpufreq/Kconfig
@@ -200,7 +200,7 @@ source "drivers/cpufreq/Kconfig.x86"
200endmenu 200endmenu
201 201
202menu "ARM CPU frequency scaling drivers" 202menu "ARM CPU frequency scaling drivers"
203depends on ARM 203depends on ARM || ARM64
204source "drivers/cpufreq/Kconfig.arm" 204source "drivers/cpufreq/Kconfig.arm"
205endmenu 205endmenu
206 206
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index cb003a6b72c8..199b52b7c3e1 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -1109,12 +1109,27 @@ static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif,
1109 goto err_set_policy_cpu; 1109 goto err_set_policy_cpu;
1110 } 1110 }
1111 1111
1112 /* related cpus should atleast have policy->cpus */
1113 cpumask_or(policy->related_cpus, policy->related_cpus, policy->cpus);
1114
1115 /*
1116 * affected cpus must always be the one, which are online. We aren't
1117 * managing offline cpus here.
1118 */
1119 cpumask_and(policy->cpus, policy->cpus, cpu_online_mask);
1120
1121 if (!frozen) {
1122 policy->user_policy.min = policy->min;
1123 policy->user_policy.max = policy->max;
1124 }
1125
1126 down_write(&policy->rwsem);
1112 write_lock_irqsave(&cpufreq_driver_lock, flags); 1127 write_lock_irqsave(&cpufreq_driver_lock, flags);
1113 for_each_cpu(j, policy->cpus) 1128 for_each_cpu(j, policy->cpus)
1114 per_cpu(cpufreq_cpu_data, j) = policy; 1129 per_cpu(cpufreq_cpu_data, j) = policy;
1115 write_unlock_irqrestore(&cpufreq_driver_lock, flags); 1130 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
1116 1131
1117 if (cpufreq_driver->get) { 1132 if (cpufreq_driver->get && !cpufreq_driver->setpolicy) {
1118 policy->cur = cpufreq_driver->get(policy->cpu); 1133 policy->cur = cpufreq_driver->get(policy->cpu);
1119 if (!policy->cur) { 1134 if (!policy->cur) {
1120 pr_err("%s: ->get() failed\n", __func__); 1135 pr_err("%s: ->get() failed\n", __func__);
@@ -1162,20 +1177,6 @@ static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif,
1162 } 1177 }
1163 } 1178 }
1164 1179
1165 /* related cpus should atleast have policy->cpus */
1166 cpumask_or(policy->related_cpus, policy->related_cpus, policy->cpus);
1167
1168 /*
1169 * affected cpus must always be the one, which are online. We aren't
1170 * managing offline cpus here.
1171 */
1172 cpumask_and(policy->cpus, policy->cpus, cpu_online_mask);
1173
1174 if (!frozen) {
1175 policy->user_policy.min = policy->min;
1176 policy->user_policy.max = policy->max;
1177 }
1178
1179 blocking_notifier_call_chain(&cpufreq_policy_notifier_list, 1180 blocking_notifier_call_chain(&cpufreq_policy_notifier_list,
1180 CPUFREQ_START, policy); 1181 CPUFREQ_START, policy);
1181 1182
@@ -1206,6 +1207,7 @@ static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif,
1206 policy->user_policy.policy = policy->policy; 1207 policy->user_policy.policy = policy->policy;
1207 policy->user_policy.governor = policy->governor; 1208 policy->user_policy.governor = policy->governor;
1208 } 1209 }
1210 up_write(&policy->rwsem);
1209 1211
1210 kobject_uevent(&policy->kobj, KOBJ_ADD); 1212 kobject_uevent(&policy->kobj, KOBJ_ADD);
1211 up_read(&cpufreq_rwsem); 1213 up_read(&cpufreq_rwsem);
@@ -1546,23 +1548,16 @@ static unsigned int __cpufreq_get(unsigned int cpu)
1546 */ 1548 */
1547unsigned int cpufreq_get(unsigned int cpu) 1549unsigned int cpufreq_get(unsigned int cpu)
1548{ 1550{
1549 struct cpufreq_policy *policy = per_cpu(cpufreq_cpu_data, cpu); 1551 struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
1550 unsigned int ret_freq = 0; 1552 unsigned int ret_freq = 0;
1551 1553
1552 if (cpufreq_disabled() || !cpufreq_driver) 1554 if (policy) {
1553 return -ENOENT; 1555 down_read(&policy->rwsem);
1554 1556 ret_freq = __cpufreq_get(cpu);
1555 BUG_ON(!policy); 1557 up_read(&policy->rwsem);
1556
1557 if (!down_read_trylock(&cpufreq_rwsem))
1558 return 0;
1559
1560 down_read(&policy->rwsem);
1561
1562 ret_freq = __cpufreq_get(cpu);
1563 1558
1564 up_read(&policy->rwsem); 1559 cpufreq_cpu_put(policy);
1565 up_read(&cpufreq_rwsem); 1560 }
1566 1561
1567 return ret_freq; 1562 return ret_freq;
1568} 1563}
@@ -2148,7 +2143,7 @@ int cpufreq_update_policy(unsigned int cpu)
2148 * BIOS might change freq behind our back 2143 * BIOS might change freq behind our back
2149 * -> ask driver for current freq and notify governors about a change 2144 * -> ask driver for current freq and notify governors about a change
2150 */ 2145 */
2151 if (cpufreq_driver->get) { 2146 if (cpufreq_driver->get && !cpufreq_driver->setpolicy) {
2152 new_policy.cur = cpufreq_driver->get(cpu); 2147 new_policy.cur = cpufreq_driver->get(cpu);
2153 if (!policy->cur) { 2148 if (!policy->cur) {
2154 pr_debug("Driver did not initialize current freq"); 2149 pr_debug("Driver did not initialize current freq");
diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
index 5793e1447fb1..79911a27a48a 100644
--- a/drivers/cpufreq/cpufreq_stats.c
+++ b/drivers/cpufreq/cpufreq_stats.c
@@ -13,7 +13,7 @@
13#include <linux/cpufreq.h> 13#include <linux/cpufreq.h>
14#include <linux/module.h> 14#include <linux/module.h>
15#include <linux/slab.h> 15#include <linux/slab.h>
16#include <asm/cputime.h> 16#include <linux/cputime.h>
17 17
18static spinlock_t cpufreq_stats_lock; 18static spinlock_t cpufreq_stats_lock;
19 19
diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
index e90816105921..2cd36b9297f3 100644
--- a/drivers/cpufreq/intel_pstate.c
+++ b/drivers/cpufreq/intel_pstate.c
@@ -39,9 +39,10 @@
39#define BYT_TURBO_RATIOS 0x66c 39#define BYT_TURBO_RATIOS 0x66c
40 40
41 41
42#define FRAC_BITS 8 42#define FRAC_BITS 6
43#define int_tofp(X) ((int64_t)(X) << FRAC_BITS) 43#define int_tofp(X) ((int64_t)(X) << FRAC_BITS)
44#define fp_toint(X) ((X) >> FRAC_BITS) 44#define fp_toint(X) ((X) >> FRAC_BITS)
45#define FP_ROUNDUP(X) ((X) += 1 << FRAC_BITS)
45 46
46static inline int32_t mul_fp(int32_t x, int32_t y) 47static inline int32_t mul_fp(int32_t x, int32_t y)
47{ 48{
@@ -556,18 +557,20 @@ static void intel_pstate_get_cpu_pstates(struct cpudata *cpu)
556static inline void intel_pstate_calc_busy(struct cpudata *cpu, 557static inline void intel_pstate_calc_busy(struct cpudata *cpu,
557 struct sample *sample) 558 struct sample *sample)
558{ 559{
559 u64 core_pct; 560 int32_t core_pct;
560 u64 c0_pct; 561 int32_t c0_pct;
561 562
562 core_pct = div64_u64(sample->aperf * 100, sample->mperf); 563 core_pct = div_fp(int_tofp((sample->aperf)),
564 int_tofp((sample->mperf)));
565 core_pct = mul_fp(core_pct, int_tofp(100));
566 FP_ROUNDUP(core_pct);
567
568 c0_pct = div_fp(int_tofp(sample->mperf), int_tofp(sample->tsc));
563 569
564 c0_pct = div64_u64(sample->mperf * 100, sample->tsc);
565 sample->freq = fp_toint( 570 sample->freq = fp_toint(
566 mul_fp(int_tofp(cpu->pstate.max_pstate), 571 mul_fp(int_tofp(cpu->pstate.max_pstate * 1000), core_pct));
567 int_tofp(core_pct * 1000)));
568 572
569 sample->core_pct_busy = mul_fp(int_tofp(core_pct), 573 sample->core_pct_busy = mul_fp(core_pct, c0_pct);
570 div_fp(int_tofp(c0_pct + 1), int_tofp(100)));
571} 574}
572 575
573static inline void intel_pstate_sample(struct cpudata *cpu) 576static inline void intel_pstate_sample(struct cpudata *cpu)
@@ -579,6 +582,10 @@ static inline void intel_pstate_sample(struct cpudata *cpu)
579 rdmsrl(MSR_IA32_MPERF, mperf); 582 rdmsrl(MSR_IA32_MPERF, mperf);
580 tsc = native_read_tsc(); 583 tsc = native_read_tsc();
581 584
585 aperf = aperf >> FRAC_BITS;
586 mperf = mperf >> FRAC_BITS;
587 tsc = tsc >> FRAC_BITS;
588
582 cpu->sample_ptr = (cpu->sample_ptr + 1) % SAMPLE_COUNT; 589 cpu->sample_ptr = (cpu->sample_ptr + 1) % SAMPLE_COUNT;
583 cpu->samples[cpu->sample_ptr].aperf = aperf; 590 cpu->samples[cpu->sample_ptr].aperf = aperf;
584 cpu->samples[cpu->sample_ptr].mperf = mperf; 591 cpu->samples[cpu->sample_ptr].mperf = mperf;
@@ -610,7 +617,8 @@ static inline int32_t intel_pstate_get_scaled_busy(struct cpudata *cpu)
610 core_busy = cpu->samples[cpu->sample_ptr].core_pct_busy; 617 core_busy = cpu->samples[cpu->sample_ptr].core_pct_busy;
611 max_pstate = int_tofp(cpu->pstate.max_pstate); 618 max_pstate = int_tofp(cpu->pstate.max_pstate);
612 current_pstate = int_tofp(cpu->pstate.current_pstate); 619 current_pstate = int_tofp(cpu->pstate.current_pstate);
613 return mul_fp(core_busy, div_fp(max_pstate, current_pstate)); 620 core_busy = mul_fp(core_busy, div_fp(max_pstate, current_pstate));
621 return FP_ROUNDUP(core_busy);
614} 622}
615 623
616static inline void intel_pstate_adjust_busy_pstate(struct cpudata *cpu) 624static inline void intel_pstate_adjust_busy_pstate(struct cpudata *cpu)
diff --git a/drivers/cpuidle/cpuidle-powernv.c b/drivers/cpuidle/cpuidle-powernv.c
index 78fd174c57e8..f48607cd2540 100644
--- a/drivers/cpuidle/cpuidle-powernv.c
+++ b/drivers/cpuidle/cpuidle-powernv.c
@@ -14,6 +14,7 @@
14 14
15#include <asm/machdep.h> 15#include <asm/machdep.h>
16#include <asm/firmware.h> 16#include <asm/firmware.h>
17#include <asm/runlatch.h>
17 18
18struct cpuidle_driver powernv_idle_driver = { 19struct cpuidle_driver powernv_idle_driver = {
19 .name = "powernv_idle", 20 .name = "powernv_idle",
@@ -30,12 +31,14 @@ static int snooze_loop(struct cpuidle_device *dev,
30 local_irq_enable(); 31 local_irq_enable();
31 set_thread_flag(TIF_POLLING_NRFLAG); 32 set_thread_flag(TIF_POLLING_NRFLAG);
32 33
34 ppc64_runlatch_off();
33 while (!need_resched()) { 35 while (!need_resched()) {
34 HMT_low(); 36 HMT_low();
35 HMT_very_low(); 37 HMT_very_low();
36 } 38 }
37 39
38 HMT_medium(); 40 HMT_medium();
41 ppc64_runlatch_on();
39 clear_thread_flag(TIF_POLLING_NRFLAG); 42 clear_thread_flag(TIF_POLLING_NRFLAG);
40 smp_mb(); 43 smp_mb();
41 return index; 44 return index;
@@ -45,7 +48,9 @@ static int nap_loop(struct cpuidle_device *dev,
45 struct cpuidle_driver *drv, 48 struct cpuidle_driver *drv,
46 int index) 49 int index)
47{ 50{
51 ppc64_runlatch_off();
48 power7_idle(); 52 power7_idle();
53 ppc64_runlatch_on();
49 return index; 54 return index;
50} 55}
51 56
diff --git a/drivers/cpuidle/cpuidle-pseries.c b/drivers/cpuidle/cpuidle-pseries.c
index 7ab564aa0b1c..6f7b01956885 100644
--- a/drivers/cpuidle/cpuidle-pseries.c
+++ b/drivers/cpuidle/cpuidle-pseries.c
@@ -17,6 +17,7 @@
17#include <asm/reg.h> 17#include <asm/reg.h>
18#include <asm/machdep.h> 18#include <asm/machdep.h>
19#include <asm/firmware.h> 19#include <asm/firmware.h>
20#include <asm/runlatch.h>
20#include <asm/plpar_wrappers.h> 21#include <asm/plpar_wrappers.h>
21 22
22struct cpuidle_driver pseries_idle_driver = { 23struct cpuidle_driver pseries_idle_driver = {
@@ -29,6 +30,7 @@ static struct cpuidle_state *cpuidle_state_table;
29 30
30static inline void idle_loop_prolog(unsigned long *in_purr) 31static inline void idle_loop_prolog(unsigned long *in_purr)
31{ 32{
33 ppc64_runlatch_off();
32 *in_purr = mfspr(SPRN_PURR); 34 *in_purr = mfspr(SPRN_PURR);
33 /* 35 /*
34 * Indicate to the HV that we are idle. Now would be 36 * Indicate to the HV that we are idle. Now would be
@@ -45,6 +47,10 @@ static inline void idle_loop_epilog(unsigned long in_purr)
45 wait_cycles += mfspr(SPRN_PURR) - in_purr; 47 wait_cycles += mfspr(SPRN_PURR) - in_purr;
46 get_lppaca()->wait_state_cycles = cpu_to_be64(wait_cycles); 48 get_lppaca()->wait_state_cycles = cpu_to_be64(wait_cycles);
47 get_lppaca()->idle = 0; 49 get_lppaca()->idle = 0;
50
51 if (irqs_disabled())
52 local_irq_enable();
53 ppc64_runlatch_on();
48} 54}
49 55
50static int snooze_loop(struct cpuidle_device *dev, 56static int snooze_loop(struct cpuidle_device *dev,
diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c
index a55e68f2cfc8..09d05ab262be 100644
--- a/drivers/cpuidle/cpuidle.c
+++ b/drivers/cpuidle/cpuidle.c
@@ -140,12 +140,14 @@ int cpuidle_idle_call(void)
140 return 0; 140 return 0;
141 } 141 }
142 142
143 trace_cpu_idle_rcuidle(next_state, dev->cpu);
144
145 broadcast = !!(drv->states[next_state].flags & CPUIDLE_FLAG_TIMER_STOP); 143 broadcast = !!(drv->states[next_state].flags & CPUIDLE_FLAG_TIMER_STOP);
146 144
147 if (broadcast) 145 if (broadcast &&
148 clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &dev->cpu); 146 clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &dev->cpu))
147 return -EBUSY;
148
149
150 trace_cpu_idle_rcuidle(next_state, dev->cpu);
149 151
150 if (cpuidle_state_is_coupled(dev, drv, next_state)) 152 if (cpuidle_state_is_coupled(dev, drv, next_state))
151 entered_state = cpuidle_enter_state_coupled(dev, drv, 153 entered_state = cpuidle_enter_state_coupled(dev, drv,
@@ -153,11 +155,11 @@ int cpuidle_idle_call(void)
153 else 155 else
154 entered_state = cpuidle_enter_state(dev, drv, next_state); 156 entered_state = cpuidle_enter_state(dev, drv, next_state);
155 157
158 trace_cpu_idle_rcuidle(PWR_EVENT_EXIT, dev->cpu);
159
156 if (broadcast) 160 if (broadcast)
157 clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_EXIT, &dev->cpu); 161 clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_EXIT, &dev->cpu);
158 162
159 trace_cpu_idle_rcuidle(PWR_EVENT_EXIT, dev->cpu);
160
161 /* give the governor an opportunity to reflect on the outcome */ 163 /* give the governor an opportunity to reflect on the outcome */
162 if (cpuidle_curr_governor->reflect) 164 if (cpuidle_curr_governor->reflect)
163 cpuidle_curr_governor->reflect(dev, entered_state); 165 cpuidle_curr_governor->reflect(dev, entered_state);
diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c
index 4e7918339b12..19041cefabb1 100644
--- a/drivers/dma/imx-sdma.c
+++ b/drivers/dma/imx-sdma.c
@@ -449,6 +449,7 @@ static const struct of_device_id sdma_dt_ids[] = {
449 { .compatible = "fsl,imx51-sdma", .data = &sdma_imx51, }, 449 { .compatible = "fsl,imx51-sdma", .data = &sdma_imx51, },
450 { .compatible = "fsl,imx35-sdma", .data = &sdma_imx35, }, 450 { .compatible = "fsl,imx35-sdma", .data = &sdma_imx35, },
451 { .compatible = "fsl,imx31-sdma", .data = &sdma_imx31, }, 451 { .compatible = "fsl,imx31-sdma", .data = &sdma_imx31, },
452 { .compatible = "fsl,imx25-sdma", .data = &sdma_imx25, },
452 { /* sentinel */ } 453 { /* sentinel */ }
453}; 454};
454MODULE_DEVICE_TABLE(of, sdma_dt_ids); 455MODULE_DEVICE_TABLE(of, sdma_dt_ids);
diff --git a/drivers/dma/ioat/dma.c b/drivers/dma/ioat/dma.c
index 87529181efcc..4e3549a16132 100644
--- a/drivers/dma/ioat/dma.c
+++ b/drivers/dma/ioat/dma.c
@@ -77,7 +77,8 @@ static irqreturn_t ioat_dma_do_interrupt(int irq, void *data)
77 attnstatus = readl(instance->reg_base + IOAT_ATTNSTATUS_OFFSET); 77 attnstatus = readl(instance->reg_base + IOAT_ATTNSTATUS_OFFSET);
78 for_each_set_bit(bit, &attnstatus, BITS_PER_LONG) { 78 for_each_set_bit(bit, &attnstatus, BITS_PER_LONG) {
79 chan = ioat_chan_by_index(instance, bit); 79 chan = ioat_chan_by_index(instance, bit);
80 tasklet_schedule(&chan->cleanup_task); 80 if (test_bit(IOAT_RUN, &chan->state))
81 tasklet_schedule(&chan->cleanup_task);
81 } 82 }
82 83
83 writeb(intrctrl, instance->reg_base + IOAT_INTRCTRL_OFFSET); 84 writeb(intrctrl, instance->reg_base + IOAT_INTRCTRL_OFFSET);
@@ -93,7 +94,8 @@ static irqreturn_t ioat_dma_do_interrupt_msix(int irq, void *data)
93{ 94{
94 struct ioat_chan_common *chan = data; 95 struct ioat_chan_common *chan = data;
95 96
96 tasklet_schedule(&chan->cleanup_task); 97 if (test_bit(IOAT_RUN, &chan->state))
98 tasklet_schedule(&chan->cleanup_task);
97 99
98 return IRQ_HANDLED; 100 return IRQ_HANDLED;
99} 101}
@@ -116,7 +118,6 @@ void ioat_init_channel(struct ioatdma_device *device, struct ioat_chan_common *c
116 chan->timer.function = device->timer_fn; 118 chan->timer.function = device->timer_fn;
117 chan->timer.data = data; 119 chan->timer.data = data;
118 tasklet_init(&chan->cleanup_task, device->cleanup_fn, data); 120 tasklet_init(&chan->cleanup_task, device->cleanup_fn, data);
119 tasklet_disable(&chan->cleanup_task);
120} 121}
121 122
122/** 123/**
@@ -354,13 +355,49 @@ static int ioat1_dma_alloc_chan_resources(struct dma_chan *c)
354 writel(((u64) chan->completion_dma) >> 32, 355 writel(((u64) chan->completion_dma) >> 32,
355 chan->reg_base + IOAT_CHANCMP_OFFSET_HIGH); 356 chan->reg_base + IOAT_CHANCMP_OFFSET_HIGH);
356 357
357 tasklet_enable(&chan->cleanup_task); 358 set_bit(IOAT_RUN, &chan->state);
358 ioat1_dma_start_null_desc(ioat); /* give chain to dma device */ 359 ioat1_dma_start_null_desc(ioat); /* give chain to dma device */
359 dev_dbg(to_dev(chan), "%s: allocated %d descriptors\n", 360 dev_dbg(to_dev(chan), "%s: allocated %d descriptors\n",
360 __func__, ioat->desccount); 361 __func__, ioat->desccount);
361 return ioat->desccount; 362 return ioat->desccount;
362} 363}
363 364
365void ioat_stop(struct ioat_chan_common *chan)
366{
367 struct ioatdma_device *device = chan->device;
368 struct pci_dev *pdev = device->pdev;
369 int chan_id = chan_num(chan);
370 struct msix_entry *msix;
371
372 /* 1/ stop irq from firing tasklets
373 * 2/ stop the tasklet from re-arming irqs
374 */
375 clear_bit(IOAT_RUN, &chan->state);
376
377 /* flush inflight interrupts */
378 switch (device->irq_mode) {
379 case IOAT_MSIX:
380 msix = &device->msix_entries[chan_id];
381 synchronize_irq(msix->vector);
382 break;
383 case IOAT_MSI:
384 case IOAT_INTX:
385 synchronize_irq(pdev->irq);
386 break;
387 default:
388 break;
389 }
390
391 /* flush inflight timers */
392 del_timer_sync(&chan->timer);
393
394 /* flush inflight tasklet runs */
395 tasklet_kill(&chan->cleanup_task);
396
397 /* final cleanup now that everything is quiesced and can't re-arm */
398 device->cleanup_fn((unsigned long) &chan->common);
399}
400
364/** 401/**
365 * ioat1_dma_free_chan_resources - release all the descriptors 402 * ioat1_dma_free_chan_resources - release all the descriptors
366 * @chan: the channel to be cleaned 403 * @chan: the channel to be cleaned
@@ -379,9 +416,7 @@ static void ioat1_dma_free_chan_resources(struct dma_chan *c)
379 if (ioat->desccount == 0) 416 if (ioat->desccount == 0)
380 return; 417 return;
381 418
382 tasklet_disable(&chan->cleanup_task); 419 ioat_stop(chan);
383 del_timer_sync(&chan->timer);
384 ioat1_cleanup(ioat);
385 420
386 /* Delay 100ms after reset to allow internal DMA logic to quiesce 421 /* Delay 100ms after reset to allow internal DMA logic to quiesce
387 * before removing DMA descriptor resources. 422 * before removing DMA descriptor resources.
@@ -526,8 +561,11 @@ ioat1_dma_prep_memcpy(struct dma_chan *c, dma_addr_t dma_dest,
526static void ioat1_cleanup_event(unsigned long data) 561static void ioat1_cleanup_event(unsigned long data)
527{ 562{
528 struct ioat_dma_chan *ioat = to_ioat_chan((void *) data); 563 struct ioat_dma_chan *ioat = to_ioat_chan((void *) data);
564 struct ioat_chan_common *chan = &ioat->base;
529 565
530 ioat1_cleanup(ioat); 566 ioat1_cleanup(ioat);
567 if (!test_bit(IOAT_RUN, &chan->state))
568 return;
531 writew(IOAT_CHANCTRL_RUN, ioat->base.reg_base + IOAT_CHANCTRL_OFFSET); 569 writew(IOAT_CHANCTRL_RUN, ioat->base.reg_base + IOAT_CHANCTRL_OFFSET);
532} 570}
533 571
diff --git a/drivers/dma/ioat/dma.h b/drivers/dma/ioat/dma.h
index 11fb877ddca9..e982f00a9843 100644
--- a/drivers/dma/ioat/dma.h
+++ b/drivers/dma/ioat/dma.h
@@ -356,6 +356,7 @@ bool ioat_cleanup_preamble(struct ioat_chan_common *chan,
356void ioat_kobject_add(struct ioatdma_device *device, struct kobj_type *type); 356void ioat_kobject_add(struct ioatdma_device *device, struct kobj_type *type);
357void ioat_kobject_del(struct ioatdma_device *device); 357void ioat_kobject_del(struct ioatdma_device *device);
358int ioat_dma_setup_interrupts(struct ioatdma_device *device); 358int ioat_dma_setup_interrupts(struct ioatdma_device *device);
359void ioat_stop(struct ioat_chan_common *chan);
359extern const struct sysfs_ops ioat_sysfs_ops; 360extern const struct sysfs_ops ioat_sysfs_ops;
360extern struct ioat_sysfs_entry ioat_version_attr; 361extern struct ioat_sysfs_entry ioat_version_attr;
361extern struct ioat_sysfs_entry ioat_cap_attr; 362extern struct ioat_sysfs_entry ioat_cap_attr;
diff --git a/drivers/dma/ioat/dma_v2.c b/drivers/dma/ioat/dma_v2.c
index 5d3affe7e976..8d1058085eeb 100644
--- a/drivers/dma/ioat/dma_v2.c
+++ b/drivers/dma/ioat/dma_v2.c
@@ -190,8 +190,11 @@ static void ioat2_cleanup(struct ioat2_dma_chan *ioat)
190void ioat2_cleanup_event(unsigned long data) 190void ioat2_cleanup_event(unsigned long data)
191{ 191{
192 struct ioat2_dma_chan *ioat = to_ioat2_chan((void *) data); 192 struct ioat2_dma_chan *ioat = to_ioat2_chan((void *) data);
193 struct ioat_chan_common *chan = &ioat->base;
193 194
194 ioat2_cleanup(ioat); 195 ioat2_cleanup(ioat);
196 if (!test_bit(IOAT_RUN, &chan->state))
197 return;
195 writew(IOAT_CHANCTRL_RUN, ioat->base.reg_base + IOAT_CHANCTRL_OFFSET); 198 writew(IOAT_CHANCTRL_RUN, ioat->base.reg_base + IOAT_CHANCTRL_OFFSET);
196} 199}
197 200
@@ -553,10 +556,10 @@ int ioat2_alloc_chan_resources(struct dma_chan *c)
553 ioat->issued = 0; 556 ioat->issued = 0;
554 ioat->tail = 0; 557 ioat->tail = 0;
555 ioat->alloc_order = order; 558 ioat->alloc_order = order;
559 set_bit(IOAT_RUN, &chan->state);
556 spin_unlock_bh(&ioat->prep_lock); 560 spin_unlock_bh(&ioat->prep_lock);
557 spin_unlock_bh(&chan->cleanup_lock); 561 spin_unlock_bh(&chan->cleanup_lock);
558 562
559 tasklet_enable(&chan->cleanup_task);
560 ioat2_start_null_desc(ioat); 563 ioat2_start_null_desc(ioat);
561 564
562 /* check that we got off the ground */ 565 /* check that we got off the ground */
@@ -566,7 +569,6 @@ int ioat2_alloc_chan_resources(struct dma_chan *c)
566 } while (i++ < 20 && !is_ioat_active(status) && !is_ioat_idle(status)); 569 } while (i++ < 20 && !is_ioat_active(status) && !is_ioat_idle(status));
567 570
568 if (is_ioat_active(status) || is_ioat_idle(status)) { 571 if (is_ioat_active(status) || is_ioat_idle(status)) {
569 set_bit(IOAT_RUN, &chan->state);
570 return 1 << ioat->alloc_order; 572 return 1 << ioat->alloc_order;
571 } else { 573 } else {
572 u32 chanerr = readl(chan->reg_base + IOAT_CHANERR_OFFSET); 574 u32 chanerr = readl(chan->reg_base + IOAT_CHANERR_OFFSET);
@@ -809,11 +811,8 @@ void ioat2_free_chan_resources(struct dma_chan *c)
809 if (!ioat->ring) 811 if (!ioat->ring)
810 return; 812 return;
811 813
812 tasklet_disable(&chan->cleanup_task); 814 ioat_stop(chan);
813 del_timer_sync(&chan->timer);
814 device->cleanup_fn((unsigned long) c);
815 device->reset_hw(chan); 815 device->reset_hw(chan);
816 clear_bit(IOAT_RUN, &chan->state);
817 816
818 spin_lock_bh(&chan->cleanup_lock); 817 spin_lock_bh(&chan->cleanup_lock);
819 spin_lock_bh(&ioat->prep_lock); 818 spin_lock_bh(&ioat->prep_lock);
diff --git a/drivers/dma/ioat/dma_v3.c b/drivers/dma/ioat/dma_v3.c
index 820817e97e62..b9b38a1cf92f 100644
--- a/drivers/dma/ioat/dma_v3.c
+++ b/drivers/dma/ioat/dma_v3.c
@@ -464,8 +464,11 @@ static void ioat3_cleanup(struct ioat2_dma_chan *ioat)
464static void ioat3_cleanup_event(unsigned long data) 464static void ioat3_cleanup_event(unsigned long data)
465{ 465{
466 struct ioat2_dma_chan *ioat = to_ioat2_chan((void *) data); 466 struct ioat2_dma_chan *ioat = to_ioat2_chan((void *) data);
467 struct ioat_chan_common *chan = &ioat->base;
467 468
468 ioat3_cleanup(ioat); 469 ioat3_cleanup(ioat);
470 if (!test_bit(IOAT_RUN, &chan->state))
471 return;
469 writew(IOAT_CHANCTRL_RUN, ioat->base.reg_base + IOAT_CHANCTRL_OFFSET); 472 writew(IOAT_CHANCTRL_RUN, ioat->base.reg_base + IOAT_CHANCTRL_OFFSET);
470} 473}
471 474
diff --git a/drivers/dma/ste_dma40.c b/drivers/dma/ste_dma40.c
index 00a2de957b23..bf18c786ed40 100644
--- a/drivers/dma/ste_dma40.c
+++ b/drivers/dma/ste_dma40.c
@@ -1641,6 +1641,7 @@ static void dma_tasklet(unsigned long data)
1641 struct d40_chan *d40c = (struct d40_chan *) data; 1641 struct d40_chan *d40c = (struct d40_chan *) data;
1642 struct d40_desc *d40d; 1642 struct d40_desc *d40d;
1643 unsigned long flags; 1643 unsigned long flags;
1644 bool callback_active;
1644 dma_async_tx_callback callback; 1645 dma_async_tx_callback callback;
1645 void *callback_param; 1646 void *callback_param;
1646 1647
@@ -1668,6 +1669,7 @@ static void dma_tasklet(unsigned long data)
1668 } 1669 }
1669 1670
1670 /* Callback to client */ 1671 /* Callback to client */
1672 callback_active = !!(d40d->txd.flags & DMA_PREP_INTERRUPT);
1671 callback = d40d->txd.callback; 1673 callback = d40d->txd.callback;
1672 callback_param = d40d->txd.callback_param; 1674 callback_param = d40d->txd.callback_param;
1673 1675
@@ -1690,7 +1692,7 @@ static void dma_tasklet(unsigned long data)
1690 1692
1691 spin_unlock_irqrestore(&d40c->lock, flags); 1693 spin_unlock_irqrestore(&d40c->lock, flags);
1692 1694
1693 if (callback && (d40d->txd.flags & DMA_PREP_INTERRUPT)) 1695 if (callback_active && callback)
1694 callback(callback_param); 1696 callback(callback_param);
1695 1697
1696 return; 1698 return;
diff --git a/drivers/edac/i7300_edac.c b/drivers/edac/i7300_edac.c
index d63f4798f7d0..57e96a3350f0 100644
--- a/drivers/edac/i7300_edac.c
+++ b/drivers/edac/i7300_edac.c
@@ -943,33 +943,35 @@ static int i7300_get_devices(struct mem_ctl_info *mci)
943 943
944 /* Attempt to 'get' the MCH register we want */ 944 /* Attempt to 'get' the MCH register we want */
945 pdev = NULL; 945 pdev = NULL;
946 while (!pvt->pci_dev_16_1_fsb_addr_map || 946 while ((pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
947 !pvt->pci_dev_16_2_fsb_err_regs) { 947 PCI_DEVICE_ID_INTEL_I7300_MCH_ERR,
948 pdev = pci_get_device(PCI_VENDOR_ID_INTEL, 948 pdev))) {
949 PCI_DEVICE_ID_INTEL_I7300_MCH_ERR, pdev);
950 if (!pdev) {
951 /* End of list, leave */
952 i7300_printk(KERN_ERR,
953 "'system address,Process Bus' "
954 "device not found:"
955 "vendor 0x%x device 0x%x ERR funcs "
956 "(broken BIOS?)\n",
957 PCI_VENDOR_ID_INTEL,
958 PCI_DEVICE_ID_INTEL_I7300_MCH_ERR);
959 goto error;
960 }
961
962 /* Store device 16 funcs 1 and 2 */ 949 /* Store device 16 funcs 1 and 2 */
963 switch (PCI_FUNC(pdev->devfn)) { 950 switch (PCI_FUNC(pdev->devfn)) {
964 case 1: 951 case 1:
965 pvt->pci_dev_16_1_fsb_addr_map = pdev; 952 if (!pvt->pci_dev_16_1_fsb_addr_map)
953 pvt->pci_dev_16_1_fsb_addr_map =
954 pci_dev_get(pdev);
966 break; 955 break;
967 case 2: 956 case 2:
968 pvt->pci_dev_16_2_fsb_err_regs = pdev; 957 if (!pvt->pci_dev_16_2_fsb_err_regs)
958 pvt->pci_dev_16_2_fsb_err_regs =
959 pci_dev_get(pdev);
969 break; 960 break;
970 } 961 }
971 } 962 }
972 963
964 if (!pvt->pci_dev_16_1_fsb_addr_map ||
965 !pvt->pci_dev_16_2_fsb_err_regs) {
966 /* At least one device was not found */
967 i7300_printk(KERN_ERR,
968 "'system address,Process Bus' device not found:"
969 "vendor 0x%x device 0x%x ERR funcs (broken BIOS?)\n",
970 PCI_VENDOR_ID_INTEL,
971 PCI_DEVICE_ID_INTEL_I7300_MCH_ERR);
972 goto error;
973 }
974
973 edac_dbg(1, "System Address, processor bus- PCI Bus ID: %s %x:%x\n", 975 edac_dbg(1, "System Address, processor bus- PCI Bus ID: %s %x:%x\n",
974 pci_name(pvt->pci_dev_16_0_fsb_ctlr), 976 pci_name(pvt->pci_dev_16_0_fsb_ctlr),
975 pvt->pci_dev_16_0_fsb_ctlr->vendor, 977 pvt->pci_dev_16_0_fsb_ctlr->vendor,
diff --git a/drivers/edac/i7core_edac.c b/drivers/edac/i7core_edac.c
index 87533ca7752e..d871275196f6 100644
--- a/drivers/edac/i7core_edac.c
+++ b/drivers/edac/i7core_edac.c
@@ -1334,14 +1334,19 @@ static int i7core_get_onedevice(struct pci_dev **prev,
1334 * is at addr 8086:2c40, instead of 8086:2c41. So, we need 1334 * is at addr 8086:2c40, instead of 8086:2c41. So, we need
1335 * to probe for the alternate address in case of failure 1335 * to probe for the alternate address in case of failure
1336 */ 1336 */
1337 if (dev_descr->dev_id == PCI_DEVICE_ID_INTEL_I7_NONCORE && !pdev) 1337 if (dev_descr->dev_id == PCI_DEVICE_ID_INTEL_I7_NONCORE && !pdev) {
1338 pci_dev_get(*prev); /* pci_get_device will put it */
1338 pdev = pci_get_device(PCI_VENDOR_ID_INTEL, 1339 pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
1339 PCI_DEVICE_ID_INTEL_I7_NONCORE_ALT, *prev); 1340 PCI_DEVICE_ID_INTEL_I7_NONCORE_ALT, *prev);
1341 }
1340 1342
1341 if (dev_descr->dev_id == PCI_DEVICE_ID_INTEL_LYNNFIELD_NONCORE && !pdev) 1343 if (dev_descr->dev_id == PCI_DEVICE_ID_INTEL_LYNNFIELD_NONCORE &&
1344 !pdev) {
1345 pci_dev_get(*prev); /* pci_get_device will put it */
1342 pdev = pci_get_device(PCI_VENDOR_ID_INTEL, 1346 pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
1343 PCI_DEVICE_ID_INTEL_LYNNFIELD_NONCORE_ALT, 1347 PCI_DEVICE_ID_INTEL_LYNNFIELD_NONCORE_ALT,
1344 *prev); 1348 *prev);
1349 }
1345 1350
1346 if (!pdev) { 1351 if (!pdev) {
1347 if (*prev) { 1352 if (*prev) {
diff --git a/drivers/extcon/extcon-arizona.c b/drivers/extcon/extcon-arizona.c
index c20602f601ee..98a14f6143a7 100644
--- a/drivers/extcon/extcon-arizona.c
+++ b/drivers/extcon/extcon-arizona.c
@@ -222,27 +222,19 @@ static void arizona_extcon_pulse_micbias(struct arizona_extcon_info *info)
222 struct snd_soc_dapm_context *dapm = arizona->dapm; 222 struct snd_soc_dapm_context *dapm = arizona->dapm;
223 int ret; 223 int ret;
224 224
225 mutex_lock(&dapm->card->dapm_mutex);
226
227 ret = snd_soc_dapm_force_enable_pin(dapm, widget); 225 ret = snd_soc_dapm_force_enable_pin(dapm, widget);
228 if (ret != 0) 226 if (ret != 0)
229 dev_warn(arizona->dev, "Failed to enable %s: %d\n", 227 dev_warn(arizona->dev, "Failed to enable %s: %d\n",
230 widget, ret); 228 widget, ret);
231 229
232 mutex_unlock(&dapm->card->dapm_mutex);
233
234 snd_soc_dapm_sync(dapm); 230 snd_soc_dapm_sync(dapm);
235 231
236 if (!arizona->pdata.micd_force_micbias) { 232 if (!arizona->pdata.micd_force_micbias) {
237 mutex_lock(&dapm->card->dapm_mutex);
238
239 ret = snd_soc_dapm_disable_pin(arizona->dapm, widget); 233 ret = snd_soc_dapm_disable_pin(arizona->dapm, widget);
240 if (ret != 0) 234 if (ret != 0)
241 dev_warn(arizona->dev, "Failed to disable %s: %d\n", 235 dev_warn(arizona->dev, "Failed to disable %s: %d\n",
242 widget, ret); 236 widget, ret);
243 237
244 mutex_unlock(&dapm->card->dapm_mutex);
245
246 snd_soc_dapm_sync(dapm); 238 snd_soc_dapm_sync(dapm);
247 } 239 }
248} 240}
@@ -304,16 +296,12 @@ static void arizona_stop_mic(struct arizona_extcon_info *info)
304 ARIZONA_MICD_ENA, 0, 296 ARIZONA_MICD_ENA, 0,
305 &change); 297 &change);
306 298
307 mutex_lock(&dapm->card->dapm_mutex);
308
309 ret = snd_soc_dapm_disable_pin(dapm, widget); 299 ret = snd_soc_dapm_disable_pin(dapm, widget);
310 if (ret != 0) 300 if (ret != 0)
311 dev_warn(arizona->dev, 301 dev_warn(arizona->dev,
312 "Failed to disable %s: %d\n", 302 "Failed to disable %s: %d\n",
313 widget, ret); 303 widget, ret);
314 304
315 mutex_unlock(&dapm->card->dapm_mutex);
316
317 snd_soc_dapm_sync(dapm); 305 snd_soc_dapm_sync(dapm);
318 306
319 if (info->micd_reva) { 307 if (info->micd_reva) {
diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
index de4aa409abe2..2c6d5e118ac1 100644
--- a/drivers/firewire/core-device.c
+++ b/drivers/firewire/core-device.c
@@ -916,7 +916,7 @@ static int lookup_existing_device(struct device *dev, void *data)
916 old->config_rom_retries = 0; 916 old->config_rom_retries = 0;
917 fw_notice(card, "rediscovered device %s\n", dev_name(dev)); 917 fw_notice(card, "rediscovered device %s\n", dev_name(dev));
918 918
919 PREPARE_DELAYED_WORK(&old->work, fw_device_update); 919 old->workfn = fw_device_update;
920 fw_schedule_device_work(old, 0); 920 fw_schedule_device_work(old, 0);
921 921
922 if (current_node == card->root_node) 922 if (current_node == card->root_node)
@@ -1075,7 +1075,7 @@ static void fw_device_init(struct work_struct *work)
1075 if (atomic_cmpxchg(&device->state, 1075 if (atomic_cmpxchg(&device->state,
1076 FW_DEVICE_INITIALIZING, 1076 FW_DEVICE_INITIALIZING,
1077 FW_DEVICE_RUNNING) == FW_DEVICE_GONE) { 1077 FW_DEVICE_RUNNING) == FW_DEVICE_GONE) {
1078 PREPARE_DELAYED_WORK(&device->work, fw_device_shutdown); 1078 device->workfn = fw_device_shutdown;
1079 fw_schedule_device_work(device, SHUTDOWN_DELAY); 1079 fw_schedule_device_work(device, SHUTDOWN_DELAY);
1080 } else { 1080 } else {
1081 fw_notice(card, "created device %s: GUID %08x%08x, S%d00\n", 1081 fw_notice(card, "created device %s: GUID %08x%08x, S%d00\n",
@@ -1196,13 +1196,20 @@ static void fw_device_refresh(struct work_struct *work)
1196 dev_name(&device->device), fw_rcode_string(ret)); 1196 dev_name(&device->device), fw_rcode_string(ret));
1197 gone: 1197 gone:
1198 atomic_set(&device->state, FW_DEVICE_GONE); 1198 atomic_set(&device->state, FW_DEVICE_GONE);
1199 PREPARE_DELAYED_WORK(&device->work, fw_device_shutdown); 1199 device->workfn = fw_device_shutdown;
1200 fw_schedule_device_work(device, SHUTDOWN_DELAY); 1200 fw_schedule_device_work(device, SHUTDOWN_DELAY);
1201 out: 1201 out:
1202 if (node_id == card->root_node->node_id) 1202 if (node_id == card->root_node->node_id)
1203 fw_schedule_bm_work(card, 0); 1203 fw_schedule_bm_work(card, 0);
1204} 1204}
1205 1205
1206static void fw_device_workfn(struct work_struct *work)
1207{
1208 struct fw_device *device = container_of(to_delayed_work(work),
1209 struct fw_device, work);
1210 device->workfn(work);
1211}
1212
1206void fw_node_event(struct fw_card *card, struct fw_node *node, int event) 1213void fw_node_event(struct fw_card *card, struct fw_node *node, int event)
1207{ 1214{
1208 struct fw_device *device; 1215 struct fw_device *device;
@@ -1252,7 +1259,8 @@ void fw_node_event(struct fw_card *card, struct fw_node *node, int event)
1252 * power-up after getting plugged in. We schedule the 1259 * power-up after getting plugged in. We schedule the
1253 * first config rom scan half a second after bus reset. 1260 * first config rom scan half a second after bus reset.
1254 */ 1261 */
1255 INIT_DELAYED_WORK(&device->work, fw_device_init); 1262 device->workfn = fw_device_init;
1263 INIT_DELAYED_WORK(&device->work, fw_device_workfn);
1256 fw_schedule_device_work(device, INITIAL_DELAY); 1264 fw_schedule_device_work(device, INITIAL_DELAY);
1257 break; 1265 break;
1258 1266
@@ -1268,7 +1276,7 @@ void fw_node_event(struct fw_card *card, struct fw_node *node, int event)
1268 if (atomic_cmpxchg(&device->state, 1276 if (atomic_cmpxchg(&device->state,
1269 FW_DEVICE_RUNNING, 1277 FW_DEVICE_RUNNING,
1270 FW_DEVICE_INITIALIZING) == FW_DEVICE_RUNNING) { 1278 FW_DEVICE_INITIALIZING) == FW_DEVICE_RUNNING) {
1271 PREPARE_DELAYED_WORK(&device->work, fw_device_refresh); 1279 device->workfn = fw_device_refresh;
1272 fw_schedule_device_work(device, 1280 fw_schedule_device_work(device,
1273 device->is_local ? 0 : INITIAL_DELAY); 1281 device->is_local ? 0 : INITIAL_DELAY);
1274 } 1282 }
@@ -1283,7 +1291,7 @@ void fw_node_event(struct fw_card *card, struct fw_node *node, int event)
1283 smp_wmb(); /* update node_id before generation */ 1291 smp_wmb(); /* update node_id before generation */
1284 device->generation = card->generation; 1292 device->generation = card->generation;
1285 if (atomic_read(&device->state) == FW_DEVICE_RUNNING) { 1293 if (atomic_read(&device->state) == FW_DEVICE_RUNNING) {
1286 PREPARE_DELAYED_WORK(&device->work, fw_device_update); 1294 device->workfn = fw_device_update;
1287 fw_schedule_device_work(device, 0); 1295 fw_schedule_device_work(device, 0);
1288 } 1296 }
1289 break; 1297 break;
@@ -1308,7 +1316,7 @@ void fw_node_event(struct fw_card *card, struct fw_node *node, int event)
1308 device = node->data; 1316 device = node->data;
1309 if (atomic_xchg(&device->state, 1317 if (atomic_xchg(&device->state,
1310 FW_DEVICE_GONE) == FW_DEVICE_RUNNING) { 1318 FW_DEVICE_GONE) == FW_DEVICE_RUNNING) {
1311 PREPARE_DELAYED_WORK(&device->work, fw_device_shutdown); 1319 device->workfn = fw_device_shutdown;
1312 fw_schedule_device_work(device, 1320 fw_schedule_device_work(device,
1313 list_empty(&card->link) ? 0 : SHUTDOWN_DELAY); 1321 list_empty(&card->link) ? 0 : SHUTDOWN_DELAY);
1314 } 1322 }
diff --git a/drivers/firewire/net.c b/drivers/firewire/net.c
index 6b895986dc22..4af0a7bad7f2 100644
--- a/drivers/firewire/net.c
+++ b/drivers/firewire/net.c
@@ -929,8 +929,6 @@ static void fwnet_write_complete(struct fw_card *card, int rcode,
929 if (rcode == RCODE_COMPLETE) { 929 if (rcode == RCODE_COMPLETE) {
930 fwnet_transmit_packet_done(ptask); 930 fwnet_transmit_packet_done(ptask);
931 } else { 931 } else {
932 fwnet_transmit_packet_failed(ptask);
933
934 if (printk_timed_ratelimit(&j, 1000) || rcode != last_rcode) { 932 if (printk_timed_ratelimit(&j, 1000) || rcode != last_rcode) {
935 dev_err(&ptask->dev->netdev->dev, 933 dev_err(&ptask->dev->netdev->dev,
936 "fwnet_write_complete failed: %x (skipped %d)\n", 934 "fwnet_write_complete failed: %x (skipped %d)\n",
@@ -938,8 +936,10 @@ static void fwnet_write_complete(struct fw_card *card, int rcode,
938 936
939 errors_skipped = 0; 937 errors_skipped = 0;
940 last_rcode = rcode; 938 last_rcode = rcode;
941 } else 939 } else {
942 errors_skipped++; 940 errors_skipped++;
941 }
942 fwnet_transmit_packet_failed(ptask);
943 } 943 }
944} 944}
945 945
diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c
index 6f74d8d3f700..8db663219560 100644
--- a/drivers/firewire/ohci.c
+++ b/drivers/firewire/ohci.c
@@ -290,7 +290,6 @@ static char ohci_driver_name[] = KBUILD_MODNAME;
290#define QUIRK_NO_MSI 0x10 290#define QUIRK_NO_MSI 0x10
291#define QUIRK_TI_SLLZ059 0x20 291#define QUIRK_TI_SLLZ059 0x20
292#define QUIRK_IR_WAKE 0x40 292#define QUIRK_IR_WAKE 0x40
293#define QUIRK_PHY_LCTRL_TIMEOUT 0x80
294 293
295/* In case of multiple matches in ohci_quirks[], only the first one is used. */ 294/* In case of multiple matches in ohci_quirks[], only the first one is used. */
296static const struct { 295static const struct {
@@ -303,10 +302,7 @@ static const struct {
303 QUIRK_BE_HEADERS}, 302 QUIRK_BE_HEADERS},
304 303
305 {PCI_VENDOR_ID_ATT, PCI_DEVICE_ID_AGERE_FW643, 6, 304 {PCI_VENDOR_ID_ATT, PCI_DEVICE_ID_AGERE_FW643, 6,
306 QUIRK_PHY_LCTRL_TIMEOUT | QUIRK_NO_MSI}, 305 QUIRK_NO_MSI},
307
308 {PCI_VENDOR_ID_ATT, PCI_ANY_ID, PCI_ANY_ID,
309 QUIRK_PHY_LCTRL_TIMEOUT},
310 306
311 {PCI_VENDOR_ID_CREATIVE, PCI_DEVICE_ID_CREATIVE_SB1394, PCI_ANY_ID, 307 {PCI_VENDOR_ID_CREATIVE, PCI_DEVICE_ID_CREATIVE_SB1394, PCI_ANY_ID,
312 QUIRK_RESET_PACKET}, 308 QUIRK_RESET_PACKET},
@@ -353,7 +349,6 @@ MODULE_PARM_DESC(quirks, "Chip quirks (default = 0"
353 ", disable MSI = " __stringify(QUIRK_NO_MSI) 349 ", disable MSI = " __stringify(QUIRK_NO_MSI)
354 ", TI SLLZ059 erratum = " __stringify(QUIRK_TI_SLLZ059) 350 ", TI SLLZ059 erratum = " __stringify(QUIRK_TI_SLLZ059)
355 ", IR wake unreliable = " __stringify(QUIRK_IR_WAKE) 351 ", IR wake unreliable = " __stringify(QUIRK_IR_WAKE)
356 ", phy LCtrl timeout = " __stringify(QUIRK_PHY_LCTRL_TIMEOUT)
357 ")"); 352 ")");
358 353
359#define OHCI_PARAM_DEBUG_AT_AR 1 354#define OHCI_PARAM_DEBUG_AT_AR 1
@@ -2299,9 +2294,6 @@ static int ohci_enable(struct fw_card *card,
2299 * TI TSB82AA2 + TSB81BA3(A) cards signal LPS enabled early but 2294 * TI TSB82AA2 + TSB81BA3(A) cards signal LPS enabled early but
2300 * cannot actually use the phy at that time. These need tens of 2295 * cannot actually use the phy at that time. These need tens of
2301 * millisecods pause between LPS write and first phy access too. 2296 * millisecods pause between LPS write and first phy access too.
2302 *
2303 * But do not wait for 50msec on Agere/LSI cards. Their phy
2304 * arbitration state machine may time out during such a long wait.
2305 */ 2297 */
2306 2298
2307 reg_write(ohci, OHCI1394_HCControlSet, 2299 reg_write(ohci, OHCI1394_HCControlSet,
@@ -2309,11 +2301,8 @@ static int ohci_enable(struct fw_card *card,
2309 OHCI1394_HCControl_postedWriteEnable); 2301 OHCI1394_HCControl_postedWriteEnable);
2310 flush_writes(ohci); 2302 flush_writes(ohci);
2311 2303
2312 if (!(ohci->quirks & QUIRK_PHY_LCTRL_TIMEOUT)) 2304 for (lps = 0, i = 0; !lps && i < 3; i++) {
2313 msleep(50); 2305 msleep(50);
2314
2315 for (lps = 0, i = 0; !lps && i < 150; i++) {
2316 msleep(1);
2317 lps = reg_read(ohci, OHCI1394_HCControlSet) & 2306 lps = reg_read(ohci, OHCI1394_HCControlSet) &
2318 OHCI1394_HCControl_LPS; 2307 OHCI1394_HCControl_LPS;
2319 } 2308 }
diff --git a/drivers/firewire/sbp2.c b/drivers/firewire/sbp2.c
index 281029daf98c..7aef911fdc71 100644
--- a/drivers/firewire/sbp2.c
+++ b/drivers/firewire/sbp2.c
@@ -146,6 +146,7 @@ struct sbp2_logical_unit {
146 */ 146 */
147 int generation; 147 int generation;
148 int retries; 148 int retries;
149 work_func_t workfn;
149 struct delayed_work work; 150 struct delayed_work work;
150 bool has_sdev; 151 bool has_sdev;
151 bool blocked; 152 bool blocked;
@@ -864,7 +865,7 @@ static void sbp2_login(struct work_struct *work)
864 /* set appropriate retry limit(s) in BUSY_TIMEOUT register */ 865 /* set appropriate retry limit(s) in BUSY_TIMEOUT register */
865 sbp2_set_busy_timeout(lu); 866 sbp2_set_busy_timeout(lu);
866 867
867 PREPARE_DELAYED_WORK(&lu->work, sbp2_reconnect); 868 lu->workfn = sbp2_reconnect;
868 sbp2_agent_reset(lu); 869 sbp2_agent_reset(lu);
869 870
870 /* This was a re-login. */ 871 /* This was a re-login. */
@@ -918,7 +919,7 @@ static void sbp2_login(struct work_struct *work)
918 * If a bus reset happened, sbp2_update will have requeued 919 * If a bus reset happened, sbp2_update will have requeued
919 * lu->work already. Reset the work from reconnect to login. 920 * lu->work already. Reset the work from reconnect to login.
920 */ 921 */
921 PREPARE_DELAYED_WORK(&lu->work, sbp2_login); 922 lu->workfn = sbp2_login;
922} 923}
923 924
924static void sbp2_reconnect(struct work_struct *work) 925static void sbp2_reconnect(struct work_struct *work)
@@ -952,7 +953,7 @@ static void sbp2_reconnect(struct work_struct *work)
952 lu->retries++ >= 5) { 953 lu->retries++ >= 5) {
953 dev_err(tgt_dev(tgt), "failed to reconnect\n"); 954 dev_err(tgt_dev(tgt), "failed to reconnect\n");
954 lu->retries = 0; 955 lu->retries = 0;
955 PREPARE_DELAYED_WORK(&lu->work, sbp2_login); 956 lu->workfn = sbp2_login;
956 } 957 }
957 sbp2_queue_work(lu, DIV_ROUND_UP(HZ, 5)); 958 sbp2_queue_work(lu, DIV_ROUND_UP(HZ, 5));
958 959
@@ -972,6 +973,13 @@ static void sbp2_reconnect(struct work_struct *work)
972 sbp2_conditionally_unblock(lu); 973 sbp2_conditionally_unblock(lu);
973} 974}
974 975
976static void sbp2_lu_workfn(struct work_struct *work)
977{
978 struct sbp2_logical_unit *lu = container_of(to_delayed_work(work),
979 struct sbp2_logical_unit, work);
980 lu->workfn(work);
981}
982
975static int sbp2_add_logical_unit(struct sbp2_target *tgt, int lun_entry) 983static int sbp2_add_logical_unit(struct sbp2_target *tgt, int lun_entry)
976{ 984{
977 struct sbp2_logical_unit *lu; 985 struct sbp2_logical_unit *lu;
@@ -998,7 +1006,8 @@ static int sbp2_add_logical_unit(struct sbp2_target *tgt, int lun_entry)
998 lu->blocked = false; 1006 lu->blocked = false;
999 ++tgt->dont_block; 1007 ++tgt->dont_block;
1000 INIT_LIST_HEAD(&lu->orb_list); 1008 INIT_LIST_HEAD(&lu->orb_list);
1001 INIT_DELAYED_WORK(&lu->work, sbp2_login); 1009 lu->workfn = sbp2_login;
1010 INIT_DELAYED_WORK(&lu->work, sbp2_lu_workfn);
1002 1011
1003 list_add_tail(&lu->link, &tgt->lu_list); 1012 list_add_tail(&lu->link, &tgt->lu_list);
1004 return 0; 1013 return 0;
diff --git a/drivers/firmware/dcdbas.c b/drivers/firmware/dcdbas.c
index 1b5e8e46226d..7160c43c59fc 100644
--- a/drivers/firmware/dcdbas.c
+++ b/drivers/firmware/dcdbas.c
@@ -584,7 +584,7 @@ static struct platform_driver dcdbas_driver = {
584 .remove = dcdbas_remove, 584 .remove = dcdbas_remove,
585}; 585};
586 586
587static const struct platform_device_info dcdbas_dev_info __initdata = { 587static const struct platform_device_info dcdbas_dev_info __initconst = {
588 .name = DRIVER_NAME, 588 .name = DRIVER_NAME,
589 .id = -1, 589 .id = -1,
590 .dma_mask = DMA_BIT_MASK(32), 590 .dma_mask = DMA_BIT_MASK(32),
diff --git a/drivers/firmware/efi/efi-stub-helper.c b/drivers/firmware/efi/efi-stub-helper.c
index b6bffbfd3be7..ff50aeebf0d9 100644
--- a/drivers/firmware/efi/efi-stub-helper.c
+++ b/drivers/firmware/efi/efi-stub-helper.c
@@ -16,18 +16,6 @@ struct file_info {
16 u64 size; 16 u64 size;
17}; 17};
18 18
19
20
21
22static void efi_char16_printk(efi_system_table_t *sys_table_arg,
23 efi_char16_t *str)
24{
25 struct efi_simple_text_output_protocol *out;
26
27 out = (struct efi_simple_text_output_protocol *)sys_table_arg->con_out;
28 efi_call_phys2(out->output_string, out, str);
29}
30
31static void efi_printk(efi_system_table_t *sys_table_arg, char *str) 19static void efi_printk(efi_system_table_t *sys_table_arg, char *str)
32{ 20{
33 char *s8; 21 char *s8;
@@ -65,20 +53,23 @@ again:
65 * allocation which may be in a new descriptor region. 53 * allocation which may be in a new descriptor region.
66 */ 54 */
67 *map_size += sizeof(*m); 55 *map_size += sizeof(*m);
68 status = efi_call_phys3(sys_table_arg->boottime->allocate_pool, 56 status = efi_call_early(allocate_pool, EFI_LOADER_DATA,
69 EFI_LOADER_DATA, *map_size, (void **)&m); 57 *map_size, (void **)&m);
70 if (status != EFI_SUCCESS) 58 if (status != EFI_SUCCESS)
71 goto fail; 59 goto fail;
72 60
73 status = efi_call_phys5(sys_table_arg->boottime->get_memory_map, 61 *desc_size = 0;
74 map_size, m, &key, desc_size, &desc_version); 62 key = 0;
63 status = efi_call_early(get_memory_map, map_size, m,
64 &key, desc_size, &desc_version);
75 if (status == EFI_BUFFER_TOO_SMALL) { 65 if (status == EFI_BUFFER_TOO_SMALL) {
76 efi_call_phys1(sys_table_arg->boottime->free_pool, m); 66 efi_call_early(free_pool, m);
77 goto again; 67 goto again;
78 } 68 }
79 69
80 if (status != EFI_SUCCESS) 70 if (status != EFI_SUCCESS)
81 efi_call_phys1(sys_table_arg->boottime->free_pool, m); 71 efi_call_early(free_pool, m);
72
82 if (key_ptr && status == EFI_SUCCESS) 73 if (key_ptr && status == EFI_SUCCESS)
83 *key_ptr = key; 74 *key_ptr = key;
84 if (desc_ver && status == EFI_SUCCESS) 75 if (desc_ver && status == EFI_SUCCESS)
@@ -158,7 +149,7 @@ again:
158 if (!max_addr) 149 if (!max_addr)
159 status = EFI_NOT_FOUND; 150 status = EFI_NOT_FOUND;
160 else { 151 else {
161 status = efi_call_phys4(sys_table_arg->boottime->allocate_pages, 152 status = efi_call_early(allocate_pages,
162 EFI_ALLOCATE_ADDRESS, EFI_LOADER_DATA, 153 EFI_ALLOCATE_ADDRESS, EFI_LOADER_DATA,
163 nr_pages, &max_addr); 154 nr_pages, &max_addr);
164 if (status != EFI_SUCCESS) { 155 if (status != EFI_SUCCESS) {
@@ -170,8 +161,7 @@ again:
170 *addr = max_addr; 161 *addr = max_addr;
171 } 162 }
172 163
173 efi_call_phys1(sys_table_arg->boottime->free_pool, map); 164 efi_call_early(free_pool, map);
174
175fail: 165fail:
176 return status; 166 return status;
177} 167}
@@ -231,7 +221,7 @@ static efi_status_t efi_low_alloc(efi_system_table_t *sys_table_arg,
231 if ((start + size) > end) 221 if ((start + size) > end)
232 continue; 222 continue;
233 223
234 status = efi_call_phys4(sys_table_arg->boottime->allocate_pages, 224 status = efi_call_early(allocate_pages,
235 EFI_ALLOCATE_ADDRESS, EFI_LOADER_DATA, 225 EFI_ALLOCATE_ADDRESS, EFI_LOADER_DATA,
236 nr_pages, &start); 226 nr_pages, &start);
237 if (status == EFI_SUCCESS) { 227 if (status == EFI_SUCCESS) {
@@ -243,7 +233,7 @@ static efi_status_t efi_low_alloc(efi_system_table_t *sys_table_arg,
243 if (i == map_size / desc_size) 233 if (i == map_size / desc_size)
244 status = EFI_NOT_FOUND; 234 status = EFI_NOT_FOUND;
245 235
246 efi_call_phys1(sys_table_arg->boottime->free_pool, map); 236 efi_call_early(free_pool, map);
247fail: 237fail:
248 return status; 238 return status;
249} 239}
@@ -257,7 +247,7 @@ static void efi_free(efi_system_table_t *sys_table_arg, unsigned long size,
257 return; 247 return;
258 248
259 nr_pages = round_up(size, EFI_PAGE_SIZE) / EFI_PAGE_SIZE; 249 nr_pages = round_up(size, EFI_PAGE_SIZE) / EFI_PAGE_SIZE;
260 efi_call_phys2(sys_table_arg->boottime->free_pages, addr, nr_pages); 250 efi_call_early(free_pages, addr, nr_pages);
261} 251}
262 252
263 253
@@ -276,9 +266,7 @@ static efi_status_t handle_cmdline_files(efi_system_table_t *sys_table_arg,
276{ 266{
277 struct file_info *files; 267 struct file_info *files;
278 unsigned long file_addr; 268 unsigned long file_addr;
279 efi_guid_t fs_proto = EFI_FILE_SYSTEM_GUID;
280 u64 file_size_total; 269 u64 file_size_total;
281 efi_file_io_interface_t *io;
282 efi_file_handle_t *fh; 270 efi_file_handle_t *fh;
283 efi_status_t status; 271 efi_status_t status;
284 int nr_files; 272 int nr_files;
@@ -319,10 +307,8 @@ static efi_status_t handle_cmdline_files(efi_system_table_t *sys_table_arg,
319 if (!nr_files) 307 if (!nr_files)
320 return EFI_SUCCESS; 308 return EFI_SUCCESS;
321 309
322 status = efi_call_phys3(sys_table_arg->boottime->allocate_pool, 310 status = efi_call_early(allocate_pool, EFI_LOADER_DATA,
323 EFI_LOADER_DATA, 311 nr_files * sizeof(*files), (void **)&files);
324 nr_files * sizeof(*files),
325 (void **)&files);
326 if (status != EFI_SUCCESS) { 312 if (status != EFI_SUCCESS) {
327 efi_printk(sys_table_arg, "Failed to alloc mem for file handle list\n"); 313 efi_printk(sys_table_arg, "Failed to alloc mem for file handle list\n");
328 goto fail; 314 goto fail;
@@ -331,13 +317,8 @@ static efi_status_t handle_cmdline_files(efi_system_table_t *sys_table_arg,
331 str = cmd_line; 317 str = cmd_line;
332 for (i = 0; i < nr_files; i++) { 318 for (i = 0; i < nr_files; i++) {
333 struct file_info *file; 319 struct file_info *file;
334 efi_file_handle_t *h;
335 efi_file_info_t *info;
336 efi_char16_t filename_16[256]; 320 efi_char16_t filename_16[256];
337 unsigned long info_sz;
338 efi_guid_t info_guid = EFI_FILE_INFO_ID;
339 efi_char16_t *p; 321 efi_char16_t *p;
340 u64 file_sz;
341 322
342 str = strstr(str, option_string); 323 str = strstr(str, option_string);
343 if (!str) 324 if (!str)
@@ -368,71 +349,18 @@ static efi_status_t handle_cmdline_files(efi_system_table_t *sys_table_arg,
368 349
369 /* Only open the volume once. */ 350 /* Only open the volume once. */
370 if (!i) { 351 if (!i) {
371 efi_boot_services_t *boottime; 352 status = efi_open_volume(sys_table_arg, image,
372 353 (void **)&fh);
373 boottime = sys_table_arg->boottime; 354 if (status != EFI_SUCCESS)
374
375 status = efi_call_phys3(boottime->handle_protocol,
376 image->device_handle, &fs_proto,
377 (void **)&io);
378 if (status != EFI_SUCCESS) {
379 efi_printk(sys_table_arg, "Failed to handle fs_proto\n");
380 goto free_files;
381 }
382
383 status = efi_call_phys2(io->open_volume, io, &fh);
384 if (status != EFI_SUCCESS) {
385 efi_printk(sys_table_arg, "Failed to open volume\n");
386 goto free_files; 355 goto free_files;
387 }
388 } 356 }
389 357
390 status = efi_call_phys5(fh->open, fh, &h, filename_16, 358 status = efi_file_size(sys_table_arg, fh, filename_16,
391 EFI_FILE_MODE_READ, (u64)0); 359 (void **)&file->handle, &file->size);
392 if (status != EFI_SUCCESS) { 360 if (status != EFI_SUCCESS)
393 efi_printk(sys_table_arg, "Failed to open file: ");
394 efi_char16_printk(sys_table_arg, filename_16);
395 efi_printk(sys_table_arg, "\n");
396 goto close_handles; 361 goto close_handles;
397 }
398 362
399 file->handle = h; 363 file_size_total += file->size;
400
401 info_sz = 0;
402 status = efi_call_phys4(h->get_info, h, &info_guid,
403 &info_sz, NULL);
404 if (status != EFI_BUFFER_TOO_SMALL) {
405 efi_printk(sys_table_arg, "Failed to get file info size\n");
406 goto close_handles;
407 }
408
409grow:
410 status = efi_call_phys3(sys_table_arg->boottime->allocate_pool,
411 EFI_LOADER_DATA, info_sz,
412 (void **)&info);
413 if (status != EFI_SUCCESS) {
414 efi_printk(sys_table_arg, "Failed to alloc mem for file info\n");
415 goto close_handles;
416 }
417
418 status = efi_call_phys4(h->get_info, h, &info_guid,
419 &info_sz, info);
420 if (status == EFI_BUFFER_TOO_SMALL) {
421 efi_call_phys1(sys_table_arg->boottime->free_pool,
422 info);
423 goto grow;
424 }
425
426 file_sz = info->file_size;
427 efi_call_phys1(sys_table_arg->boottime->free_pool, info);
428
429 if (status != EFI_SUCCESS) {
430 efi_printk(sys_table_arg, "Failed to get file info\n");
431 goto close_handles;
432 }
433
434 file->size = file_sz;
435 file_size_total += file_sz;
436 } 364 }
437 365
438 if (file_size_total) { 366 if (file_size_total) {
@@ -468,10 +396,10 @@ grow:
468 chunksize = EFI_READ_CHUNK_SIZE; 396 chunksize = EFI_READ_CHUNK_SIZE;
469 else 397 else
470 chunksize = size; 398 chunksize = size;
471 status = efi_call_phys3(fh->read, 399
472 files[j].handle, 400 status = efi_file_read(fh, files[j].handle,
473 &chunksize, 401 &chunksize,
474 (void *)addr); 402 (void *)addr);
475 if (status != EFI_SUCCESS) { 403 if (status != EFI_SUCCESS) {
476 efi_printk(sys_table_arg, "Failed to read file\n"); 404 efi_printk(sys_table_arg, "Failed to read file\n");
477 goto free_file_total; 405 goto free_file_total;
@@ -480,12 +408,12 @@ grow:
480 size -= chunksize; 408 size -= chunksize;
481 } 409 }
482 410
483 efi_call_phys1(fh->close, files[j].handle); 411 efi_file_close(fh, files[j].handle);
484 } 412 }
485 413
486 } 414 }
487 415
488 efi_call_phys1(sys_table_arg->boottime->free_pool, files); 416 efi_call_early(free_pool, files);
489 417
490 *load_addr = file_addr; 418 *load_addr = file_addr;
491 *load_size = file_size_total; 419 *load_size = file_size_total;
@@ -497,9 +425,9 @@ free_file_total:
497 425
498close_handles: 426close_handles:
499 for (k = j; k < i; k++) 427 for (k = j; k < i; k++)
500 efi_call_phys1(fh->close, files[k].handle); 428 efi_file_close(fh, files[k].handle);
501free_files: 429free_files:
502 efi_call_phys1(sys_table_arg->boottime->free_pool, files); 430 efi_call_early(free_pool, files);
503fail: 431fail:
504 *load_addr = 0; 432 *load_addr = 0;
505 *load_size = 0; 433 *load_size = 0;
@@ -545,7 +473,7 @@ static efi_status_t efi_relocate_kernel(efi_system_table_t *sys_table_arg,
545 * as possible while respecting the required alignment. 473 * as possible while respecting the required alignment.
546 */ 474 */
547 nr_pages = round_up(alloc_size, EFI_PAGE_SIZE) / EFI_PAGE_SIZE; 475 nr_pages = round_up(alloc_size, EFI_PAGE_SIZE) / EFI_PAGE_SIZE;
548 status = efi_call_phys4(sys_table_arg->boottime->allocate_pages, 476 status = efi_call_early(allocate_pages,
549 EFI_ALLOCATE_ADDRESS, EFI_LOADER_DATA, 477 EFI_ALLOCATE_ADDRESS, EFI_LOADER_DATA,
550 nr_pages, &efi_addr); 478 nr_pages, &efi_addr);
551 new_addr = efi_addr; 479 new_addr = efi_addr;
diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
index 4753bac65279..af20f1712337 100644
--- a/drivers/firmware/efi/efi.c
+++ b/drivers/firmware/efi/efi.c
@@ -233,7 +233,7 @@ static __initdata efi_config_table_type_t common_tables[] = {
233 {SAL_SYSTEM_TABLE_GUID, "SALsystab", &efi.sal_systab}, 233 {SAL_SYSTEM_TABLE_GUID, "SALsystab", &efi.sal_systab},
234 {SMBIOS_TABLE_GUID, "SMBIOS", &efi.smbios}, 234 {SMBIOS_TABLE_GUID, "SMBIOS", &efi.smbios},
235 {UGA_IO_PROTOCOL_GUID, "UGA", &efi.uga}, 235 {UGA_IO_PROTOCOL_GUID, "UGA", &efi.uga},
236 {NULL_GUID, NULL, 0}, 236 {NULL_GUID, NULL, NULL},
237}; 237};
238 238
239static __init int match_config_table(efi_guid_t *guid, 239static __init int match_config_table(efi_guid_t *guid,
@@ -313,5 +313,8 @@ int __init efi_config_init(efi_config_table_type_t *arch_tables)
313 } 313 }
314 pr_cont("\n"); 314 pr_cont("\n");
315 early_iounmap(config_tables, efi.systab->nr_tables * sz); 315 early_iounmap(config_tables, efi.systab->nr_tables * sz);
316
317 set_bit(EFI_CONFIG_TABLES, &efi.flags);
318
316 return 0; 319 return 0;
317} 320}
diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
index 3dc248239197..50ea412a25e6 100644
--- a/drivers/firmware/efi/efivars.c
+++ b/drivers/firmware/efi/efivars.c
@@ -227,7 +227,7 @@ efivar_store_raw(struct efivar_entry *entry, const char *buf, size_t count)
227 memcpy(&entry->var, new_var, count); 227 memcpy(&entry->var, new_var, count);
228 228
229 err = efivar_entry_set(entry, new_var->Attributes, 229 err = efivar_entry_set(entry, new_var->Attributes,
230 new_var->DataSize, new_var->Data, false); 230 new_var->DataSize, new_var->Data, NULL);
231 if (err) { 231 if (err) {
232 printk(KERN_WARNING "efivars: set_variable() failed: status=%d\n", err); 232 printk(KERN_WARNING "efivars: set_variable() failed: status=%d\n", err);
233 return -EIO; 233 return -EIO;
diff --git a/drivers/fmc/fmc-write-eeprom.c b/drivers/fmc/fmc-write-eeprom.c
index ee5b47904130..9bb2cbd5c9f2 100644
--- a/drivers/fmc/fmc-write-eeprom.c
+++ b/drivers/fmc/fmc-write-eeprom.c
@@ -27,7 +27,7 @@ FMC_PARAM_BUSID(fwe_drv);
27/* The "file=" is like the generic "gateware=" used elsewhere */ 27/* The "file=" is like the generic "gateware=" used elsewhere */
28static char *fwe_file[FMC_MAX_CARDS]; 28static char *fwe_file[FMC_MAX_CARDS];
29static int fwe_file_n; 29static int fwe_file_n;
30module_param_array_named(file, fwe_file, charp, &fwe_file_n, 444); 30module_param_array_named(file, fwe_file, charp, &fwe_file_n, 0444);
31 31
32static int fwe_run_tlv(struct fmc_device *fmc, const struct firmware *fw, 32static int fwe_run_tlv(struct fmc_device *fmc, const struct firmware *fw,
33 int write) 33 int write)
diff --git a/drivers/gpu/drm/armada/armada_drv.c b/drivers/gpu/drm/armada/armada_drv.c
index acf3a36c9ebc..32982da82694 100644
--- a/drivers/gpu/drm/armada/armada_drv.c
+++ b/drivers/gpu/drm/armada/armada_drv.c
@@ -68,15 +68,7 @@ void __armada_drm_queue_unref_work(struct drm_device *dev,
68{ 68{
69 struct armada_private *priv = dev->dev_private; 69 struct armada_private *priv = dev->dev_private;
70 70
71 /* 71 WARN_ON(!kfifo_put(&priv->fb_unref, fb));
72 * Yes, we really must jump through these hoops just to store a
73 * _pointer_ to something into the kfifo. This is utterly insane
74 * and idiotic, because it kfifo requires the _data_ pointed to by
75 * the pointer const, not the pointer itself. Not only that, but
76 * you have to pass a pointer _to_ the pointer you want stored.
77 */
78 const struct drm_framebuffer *silly_api_alert = fb;
79 WARN_ON(!kfifo_put(&priv->fb_unref, &silly_api_alert));
80 schedule_work(&priv->fb_unref_work); 72 schedule_work(&priv->fb_unref_work);
81} 73}
82 74
diff --git a/drivers/gpu/drm/bochs/Kconfig b/drivers/gpu/drm/bochs/Kconfig
index c8fcf12019f0..5f8b0c2b9a44 100644
--- a/drivers/gpu/drm/bochs/Kconfig
+++ b/drivers/gpu/drm/bochs/Kconfig
@@ -2,6 +2,7 @@ config DRM_BOCHS
2 tristate "DRM Support for bochs dispi vga interface (qemu stdvga)" 2 tristate "DRM Support for bochs dispi vga interface (qemu stdvga)"
3 depends on DRM && PCI 3 depends on DRM && PCI
4 select DRM_KMS_HELPER 4 select DRM_KMS_HELPER
5 select DRM_KMS_FB_HELPER
5 select FB_SYS_FILLRECT 6 select FB_SYS_FILLRECT
6 select FB_SYS_COPYAREA 7 select FB_SYS_COPYAREA
7 select FB_SYS_IMAGEBLIT 8 select FB_SYS_IMAGEBLIT
diff --git a/drivers/gpu/drm/drm_cache.c b/drivers/gpu/drm/drm_cache.c
index bb8f58012189..534cb89b160d 100644
--- a/drivers/gpu/drm/drm_cache.c
+++ b/drivers/gpu/drm/drm_cache.c
@@ -32,6 +32,12 @@
32#include <drm/drmP.h> 32#include <drm/drmP.h>
33 33
34#if defined(CONFIG_X86) 34#if defined(CONFIG_X86)
35
36/*
37 * clflushopt is an unordered instruction which needs fencing with mfence or
38 * sfence to avoid ordering issues. For drm_clflush_page this fencing happens
39 * in the caller.
40 */
35static void 41static void
36drm_clflush_page(struct page *page) 42drm_clflush_page(struct page *page)
37{ 43{
@@ -44,7 +50,7 @@ drm_clflush_page(struct page *page)
44 50
45 page_virtual = kmap_atomic(page); 51 page_virtual = kmap_atomic(page);
46 for (i = 0; i < PAGE_SIZE; i += size) 52 for (i = 0; i < PAGE_SIZE; i += size)
47 clflush(page_virtual + i); 53 clflushopt(page_virtual + i);
48 kunmap_atomic(page_virtual); 54 kunmap_atomic(page_virtual);
49} 55}
50 56
@@ -133,7 +139,7 @@ drm_clflush_virt_range(char *addr, unsigned long length)
133 mb(); 139 mb();
134 for (; addr < end; addr += boot_cpu_data.x86_clflush_size) 140 for (; addr < end; addr += boot_cpu_data.x86_clflush_size)
135 clflush(addr); 141 clflush(addr);
136 clflush(end - 1); 142 clflushopt(end - 1);
137 mb(); 143 mb();
138 return; 144 return;
139 } 145 }
diff --git a/drivers/gpu/drm/drm_pci.c b/drivers/gpu/drm/drm_pci.c
index 5736aaa7e86c..f7af69bcf3f4 100644
--- a/drivers/gpu/drm/drm_pci.c
+++ b/drivers/gpu/drm/drm_pci.c
@@ -468,8 +468,8 @@ void drm_pci_exit(struct drm_driver *driver, struct pci_driver *pdriver)
468 } else { 468 } else {
469 list_for_each_entry_safe(dev, tmp, &driver->legacy_dev_list, 469 list_for_each_entry_safe(dev, tmp, &driver->legacy_dev_list,
470 legacy_dev_list) { 470 legacy_dev_list) {
471 drm_put_dev(dev);
472 list_del(&dev->legacy_dev_list); 471 list_del(&dev->legacy_dev_list);
472 drm_put_dev(dev);
473 } 473 }
474 } 474 }
475 DRM_INFO("Module unloaded\n"); 475 DRM_INFO("Module unloaded\n");
diff --git a/drivers/gpu/drm/exynos/exynos_drm_drv.c b/drivers/gpu/drm/exynos/exynos_drm_drv.c
index 215131ab1dd2..c204b4e3356e 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_drv.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_drv.c
@@ -172,20 +172,24 @@ static int exynos_drm_open(struct drm_device *dev, struct drm_file *file)
172 172
173 ret = exynos_drm_subdrv_open(dev, file); 173 ret = exynos_drm_subdrv_open(dev, file);
174 if (ret) 174 if (ret)
175 goto out; 175 goto err_file_priv_free;
176 176
177 anon_filp = anon_inode_getfile("exynos_gem", &exynos_drm_gem_fops, 177 anon_filp = anon_inode_getfile("exynos_gem", &exynos_drm_gem_fops,
178 NULL, 0); 178 NULL, 0);
179 if (IS_ERR(anon_filp)) { 179 if (IS_ERR(anon_filp)) {
180 ret = PTR_ERR(anon_filp); 180 ret = PTR_ERR(anon_filp);
181 goto out; 181 goto err_subdrv_close;
182 } 182 }
183 183
184 anon_filp->f_mode = FMODE_READ | FMODE_WRITE; 184 anon_filp->f_mode = FMODE_READ | FMODE_WRITE;
185 file_priv->anon_filp = anon_filp; 185 file_priv->anon_filp = anon_filp;
186 186
187 return ret; 187 return ret;
188out: 188
189err_subdrv_close:
190 exynos_drm_subdrv_close(dev, file);
191
192err_file_priv_free:
189 kfree(file_priv); 193 kfree(file_priv);
190 file->driver_priv = NULL; 194 file->driver_priv = NULL;
191 return ret; 195 return ret;
diff --git a/drivers/gpu/drm/gma500/mmu.c b/drivers/gpu/drm/gma500/mmu.c
index 49bac41beefb..c3e67ba94446 100644
--- a/drivers/gpu/drm/gma500/mmu.c
+++ b/drivers/gpu/drm/gma500/mmu.c
@@ -520,7 +520,7 @@ struct psb_mmu_driver *psb_mmu_driver_init(uint8_t __iomem * registers,
520 520
521 driver->has_clflush = 0; 521 driver->has_clflush = 0;
522 522
523 if (boot_cpu_has(X86_FEATURE_CLFLSH)) { 523 if (boot_cpu_has(X86_FEATURE_CLFLUSH)) {
524 uint32_t tfms, misc, cap0, cap4, clflush_size; 524 uint32_t tfms, misc, cap0, cap4, clflush_size;
525 525
526 /* 526 /*
diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c
index 04f1f02c4019..ec7bb0fc71bc 100644
--- a/drivers/gpu/drm/i915/i915_drv.c
+++ b/drivers/gpu/drm/i915/i915_drv.c
@@ -403,7 +403,7 @@ MODULE_DEVICE_TABLE(pci, pciidlist);
403void intel_detect_pch(struct drm_device *dev) 403void intel_detect_pch(struct drm_device *dev)
404{ 404{
405 struct drm_i915_private *dev_priv = dev->dev_private; 405 struct drm_i915_private *dev_priv = dev->dev_private;
406 struct pci_dev *pch; 406 struct pci_dev *pch = NULL;
407 407
408 /* In all current cases, num_pipes is equivalent to the PCH_NOP setting 408 /* In all current cases, num_pipes is equivalent to the PCH_NOP setting
409 * (which really amounts to a PCH but no South Display). 409 * (which really amounts to a PCH but no South Display).
@@ -424,12 +424,9 @@ void intel_detect_pch(struct drm_device *dev)
424 * all the ISA bridge devices and check for the first match, instead 424 * all the ISA bridge devices and check for the first match, instead
425 * of only checking the first one. 425 * of only checking the first one.
426 */ 426 */
427 pch = pci_get_class(PCI_CLASS_BRIDGE_ISA << 8, NULL); 427 while ((pch = pci_get_class(PCI_CLASS_BRIDGE_ISA << 8, pch))) {
428 while (pch) {
429 struct pci_dev *curr = pch;
430 if (pch->vendor == PCI_VENDOR_ID_INTEL) { 428 if (pch->vendor == PCI_VENDOR_ID_INTEL) {
431 unsigned short id; 429 unsigned short id = pch->device & INTEL_PCH_DEVICE_ID_MASK;
432 id = pch->device & INTEL_PCH_DEVICE_ID_MASK;
433 dev_priv->pch_id = id; 430 dev_priv->pch_id = id;
434 431
435 if (id == INTEL_PCH_IBX_DEVICE_ID_TYPE) { 432 if (id == INTEL_PCH_IBX_DEVICE_ID_TYPE) {
@@ -461,18 +458,16 @@ void intel_detect_pch(struct drm_device *dev)
461 DRM_DEBUG_KMS("Found LynxPoint LP PCH\n"); 458 DRM_DEBUG_KMS("Found LynxPoint LP PCH\n");
462 WARN_ON(!IS_HASWELL(dev)); 459 WARN_ON(!IS_HASWELL(dev));
463 WARN_ON(!IS_ULT(dev)); 460 WARN_ON(!IS_ULT(dev));
464 } else { 461 } else
465 goto check_next; 462 continue;
466 } 463
467 pci_dev_put(pch);
468 break; 464 break;
469 } 465 }
470check_next:
471 pch = pci_get_class(PCI_CLASS_BRIDGE_ISA << 8, curr);
472 pci_dev_put(curr);
473 } 466 }
474 if (!pch) 467 if (!pch)
475 DRM_DEBUG_KMS("No PCH found?\n"); 468 DRM_DEBUG_KMS("No PCH found.\n");
469
470 pci_dev_put(pch);
476} 471}
477 472
478bool i915_semaphore_is_enabled(struct drm_device *dev) 473bool i915_semaphore_is_enabled(struct drm_device *dev)
diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c b/drivers/gpu/drm/i915/i915_gem_gtt.c
index 40a2b36b276b..d278be110805 100644
--- a/drivers/gpu/drm/i915/i915_gem_gtt.c
+++ b/drivers/gpu/drm/i915/i915_gem_gtt.c
@@ -842,7 +842,7 @@ void i915_gem_suspend_gtt_mappings(struct drm_device *dev)
842 dev_priv->gtt.base.clear_range(&dev_priv->gtt.base, 842 dev_priv->gtt.base.clear_range(&dev_priv->gtt.base,
843 dev_priv->gtt.base.start / PAGE_SIZE, 843 dev_priv->gtt.base.start / PAGE_SIZE,
844 dev_priv->gtt.base.total / PAGE_SIZE, 844 dev_priv->gtt.base.total / PAGE_SIZE,
845 false); 845 true);
846} 846}
847 847
848void i915_gem_restore_gtt_mappings(struct drm_device *dev) 848void i915_gem_restore_gtt_mappings(struct drm_device *dev)
diff --git a/drivers/gpu/drm/i915/i915_gem_stolen.c b/drivers/gpu/drm/i915/i915_gem_stolen.c
index 1a24e84f2315..28d24caa49f3 100644
--- a/drivers/gpu/drm/i915/i915_gem_stolen.c
+++ b/drivers/gpu/drm/i915/i915_gem_stolen.c
@@ -82,9 +82,22 @@ static unsigned long i915_stolen_to_physical(struct drm_device *dev)
82 r = devm_request_mem_region(dev->dev, base, dev_priv->gtt.stolen_size, 82 r = devm_request_mem_region(dev->dev, base, dev_priv->gtt.stolen_size,
83 "Graphics Stolen Memory"); 83 "Graphics Stolen Memory");
84 if (r == NULL) { 84 if (r == NULL) {
85 DRM_ERROR("conflict detected with stolen region: [0x%08x - 0x%08x]\n", 85 /*
86 base, base + (uint32_t)dev_priv->gtt.stolen_size); 86 * One more attempt but this time requesting region from
87 base = 0; 87 * base + 1, as we have seen that this resolves the region
88 * conflict with the PCI Bus.
89 * This is a BIOS w/a: Some BIOS wrap stolen in the root
90 * PCI bus, but have an off-by-one error. Hence retry the
91 * reservation starting from 1 instead of 0.
92 */
93 r = devm_request_mem_region(dev->dev, base + 1,
94 dev_priv->gtt.stolen_size - 1,
95 "Graphics Stolen Memory");
96 if (r == NULL) {
97 DRM_ERROR("conflict detected with stolen region: [0x%08x - 0x%08x]\n",
98 base, base + (uint32_t)dev_priv->gtt.stolen_size);
99 base = 0;
100 }
88 } 101 }
89 102
90 return base; 103 return base;
@@ -201,6 +214,13 @@ int i915_gem_init_stolen(struct drm_device *dev)
201 struct drm_i915_private *dev_priv = dev->dev_private; 214 struct drm_i915_private *dev_priv = dev->dev_private;
202 int bios_reserved = 0; 215 int bios_reserved = 0;
203 216
217#ifdef CONFIG_INTEL_IOMMU
218 if (intel_iommu_gfx_mapped) {
219 DRM_INFO("DMAR active, disabling use of stolen memory\n");
220 return 0;
221 }
222#endif
223
204 if (dev_priv->gtt.stolen_size == 0) 224 if (dev_priv->gtt.stolen_size == 0)
205 return 0; 225 return 0;
206 226
diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
index 9fec71175571..d554169ac592 100644
--- a/drivers/gpu/drm/i915/i915_irq.c
+++ b/drivers/gpu/drm/i915/i915_irq.c
@@ -618,33 +618,25 @@ static u32 gm45_get_vblank_counter(struct drm_device *dev, int pipe)
618 618
619/* raw reads, only for fast reads of display block, no need for forcewake etc. */ 619/* raw reads, only for fast reads of display block, no need for forcewake etc. */
620#define __raw_i915_read32(dev_priv__, reg__) readl((dev_priv__)->regs + (reg__)) 620#define __raw_i915_read32(dev_priv__, reg__) readl((dev_priv__)->regs + (reg__))
621#define __raw_i915_read16(dev_priv__, reg__) readw((dev_priv__)->regs + (reg__))
622 621
623static bool ilk_pipe_in_vblank_locked(struct drm_device *dev, enum pipe pipe) 622static bool ilk_pipe_in_vblank_locked(struct drm_device *dev, enum pipe pipe)
624{ 623{
625 struct drm_i915_private *dev_priv = dev->dev_private; 624 struct drm_i915_private *dev_priv = dev->dev_private;
626 uint32_t status; 625 uint32_t status;
627 626 int reg;
628 if (INTEL_INFO(dev)->gen < 7) { 627
629 status = pipe == PIPE_A ? 628 if (INTEL_INFO(dev)->gen >= 8) {
630 DE_PIPEA_VBLANK : 629 status = GEN8_PIPE_VBLANK;
631 DE_PIPEB_VBLANK; 630 reg = GEN8_DE_PIPE_ISR(pipe);
631 } else if (INTEL_INFO(dev)->gen >= 7) {
632 status = DE_PIPE_VBLANK_IVB(pipe);
633 reg = DEISR;
632 } else { 634 } else {
633 switch (pipe) { 635 status = DE_PIPE_VBLANK(pipe);
634 default: 636 reg = DEISR;
635 case PIPE_A:
636 status = DE_PIPEA_VBLANK_IVB;
637 break;
638 case PIPE_B:
639 status = DE_PIPEB_VBLANK_IVB;
640 break;
641 case PIPE_C:
642 status = DE_PIPEC_VBLANK_IVB;
643 break;
644 }
645 } 637 }
646 638
647 return __raw_i915_read32(dev_priv, DEISR) & status; 639 return __raw_i915_read32(dev_priv, reg) & status;
648} 640}
649 641
650static int i915_get_crtc_scanoutpos(struct drm_device *dev, int pipe, 642static int i915_get_crtc_scanoutpos(struct drm_device *dev, int pipe,
@@ -702,7 +694,28 @@ static int i915_get_crtc_scanoutpos(struct drm_device *dev, int pipe,
702 else 694 else
703 position = __raw_i915_read32(dev_priv, PIPEDSL(pipe)) & DSL_LINEMASK_GEN3; 695 position = __raw_i915_read32(dev_priv, PIPEDSL(pipe)) & DSL_LINEMASK_GEN3;
704 696
705 if (HAS_PCH_SPLIT(dev)) { 697 if (HAS_DDI(dev)) {
698 /*
699 * On HSW HDMI outputs there seems to be a 2 line
700 * difference, whereas eDP has the normal 1 line
701 * difference that earlier platforms have. External
702 * DP is unknown. For now just check for the 2 line
703 * difference case on all output types on HSW+.
704 *
705 * This might misinterpret the scanline counter being
706 * one line too far along on eDP, but that's less
707 * dangerous than the alternative since that would lead
708 * the vblank timestamp code astray when it sees a
709 * scanline count before vblank_start during a vblank
710 * interrupt.
711 */
712 in_vbl = ilk_pipe_in_vblank_locked(dev, pipe);
713 if ((in_vbl && (position == vbl_start - 2 ||
714 position == vbl_start - 1)) ||
715 (!in_vbl && (position == vbl_end - 2 ||
716 position == vbl_end - 1)))
717 position = (position + 2) % vtotal;
718 } else if (HAS_PCH_SPLIT(dev)) {
706 /* 719 /*
707 * The scanline counter increments at the leading edge 720 * The scanline counter increments at the leading edge
708 * of hsync, ie. it completely misses the active portion 721 * of hsync, ie. it completely misses the active portion
@@ -2769,10 +2782,9 @@ static void ibx_irq_postinstall(struct drm_device *dev)
2769 return; 2782 return;
2770 2783
2771 if (HAS_PCH_IBX(dev)) { 2784 if (HAS_PCH_IBX(dev)) {
2772 mask = SDE_GMBUS | SDE_AUX_MASK | SDE_TRANSB_FIFO_UNDER | 2785 mask = SDE_GMBUS | SDE_AUX_MASK | SDE_POISON;
2773 SDE_TRANSA_FIFO_UNDER | SDE_POISON;
2774 } else { 2786 } else {
2775 mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT | SDE_ERROR_CPT; 2787 mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT;
2776 2788
2777 I915_WRITE(SERR_INT, I915_READ(SERR_INT)); 2789 I915_WRITE(SERR_INT, I915_READ(SERR_INT));
2778 } 2790 }
@@ -2832,20 +2844,19 @@ static int ironlake_irq_postinstall(struct drm_device *dev)
2832 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE_IVB | 2844 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE_IVB |
2833 DE_PCH_EVENT_IVB | DE_PLANEC_FLIP_DONE_IVB | 2845 DE_PCH_EVENT_IVB | DE_PLANEC_FLIP_DONE_IVB |
2834 DE_PLANEB_FLIP_DONE_IVB | 2846 DE_PLANEB_FLIP_DONE_IVB |
2835 DE_PLANEA_FLIP_DONE_IVB | DE_AUX_CHANNEL_A_IVB | 2847 DE_PLANEA_FLIP_DONE_IVB | DE_AUX_CHANNEL_A_IVB);
2836 DE_ERR_INT_IVB);
2837 extra_mask = (DE_PIPEC_VBLANK_IVB | DE_PIPEB_VBLANK_IVB | 2848 extra_mask = (DE_PIPEC_VBLANK_IVB | DE_PIPEB_VBLANK_IVB |
2838 DE_PIPEA_VBLANK_IVB); 2849 DE_PIPEA_VBLANK_IVB | DE_ERR_INT_IVB);
2839 2850
2840 I915_WRITE(GEN7_ERR_INT, I915_READ(GEN7_ERR_INT)); 2851 I915_WRITE(GEN7_ERR_INT, I915_READ(GEN7_ERR_INT));
2841 } else { 2852 } else {
2842 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT | 2853 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT |
2843 DE_PLANEA_FLIP_DONE | DE_PLANEB_FLIP_DONE | 2854 DE_PLANEA_FLIP_DONE | DE_PLANEB_FLIP_DONE |
2844 DE_AUX_CHANNEL_A | 2855 DE_AUX_CHANNEL_A |
2845 DE_PIPEB_FIFO_UNDERRUN | DE_PIPEA_FIFO_UNDERRUN |
2846 DE_PIPEB_CRC_DONE | DE_PIPEA_CRC_DONE | 2856 DE_PIPEB_CRC_DONE | DE_PIPEA_CRC_DONE |
2847 DE_POISON); 2857 DE_POISON);
2848 extra_mask = DE_PIPEA_VBLANK | DE_PIPEB_VBLANK | DE_PCU_EVENT; 2858 extra_mask = DE_PIPEA_VBLANK | DE_PIPEB_VBLANK | DE_PCU_EVENT |
2859 DE_PIPEB_FIFO_UNDERRUN | DE_PIPEA_FIFO_UNDERRUN;
2849 } 2860 }
2850 2861
2851 dev_priv->irq_mask = ~display_mask; 2862 dev_priv->irq_mask = ~display_mask;
@@ -2961,9 +2972,9 @@ static void gen8_de_irq_postinstall(struct drm_i915_private *dev_priv)
2961 struct drm_device *dev = dev_priv->dev; 2972 struct drm_device *dev = dev_priv->dev;
2962 uint32_t de_pipe_masked = GEN8_PIPE_FLIP_DONE | 2973 uint32_t de_pipe_masked = GEN8_PIPE_FLIP_DONE |
2963 GEN8_PIPE_CDCLK_CRC_DONE | 2974 GEN8_PIPE_CDCLK_CRC_DONE |
2964 GEN8_PIPE_FIFO_UNDERRUN |
2965 GEN8_DE_PIPE_IRQ_FAULT_ERRORS; 2975 GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
2966 uint32_t de_pipe_enables = de_pipe_masked | GEN8_PIPE_VBLANK; 2976 uint32_t de_pipe_enables = de_pipe_masked | GEN8_PIPE_VBLANK |
2977 GEN8_PIPE_FIFO_UNDERRUN;
2967 int pipe; 2978 int pipe;
2968 dev_priv->de_irq_mask[PIPE_A] = ~de_pipe_masked; 2979 dev_priv->de_irq_mask[PIPE_A] = ~de_pipe_masked;
2969 dev_priv->de_irq_mask[PIPE_B] = ~de_pipe_masked; 2980 dev_priv->de_irq_mask[PIPE_B] = ~de_pipe_masked;
diff --git a/drivers/gpu/drm/i915/intel_ddi.c b/drivers/gpu/drm/i915/intel_ddi.c
index e06b9e017d6b..234ac5f7bc5a 100644
--- a/drivers/gpu/drm/i915/intel_ddi.c
+++ b/drivers/gpu/drm/i915/intel_ddi.c
@@ -1244,6 +1244,7 @@ static void intel_ddi_post_disable(struct intel_encoder *intel_encoder)
1244 if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) { 1244 if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) {
1245 struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 1245 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
1246 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF); 1246 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
1247 ironlake_edp_panel_vdd_on(intel_dp);
1247 ironlake_edp_panel_off(intel_dp); 1248 ironlake_edp_panel_off(intel_dp);
1248 } 1249 }
1249 1250
diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
index 4c1672809493..9b8a7c7ea7fc 100644
--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -1092,12 +1092,12 @@ static void assert_cursor(struct drm_i915_private *dev_priv,
1092 struct drm_device *dev = dev_priv->dev; 1092 struct drm_device *dev = dev_priv->dev;
1093 bool cur_state; 1093 bool cur_state;
1094 1094
1095 if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev)) 1095 if (IS_845G(dev) || IS_I865G(dev))
1096 cur_state = I915_READ(CURCNTR_IVB(pipe)) & CURSOR_MODE;
1097 else if (IS_845G(dev) || IS_I865G(dev))
1098 cur_state = I915_READ(_CURACNTR) & CURSOR_ENABLE; 1096 cur_state = I915_READ(_CURACNTR) & CURSOR_ENABLE;
1099 else 1097 else if (INTEL_INFO(dev)->gen <= 6 || IS_VALLEYVIEW(dev))
1100 cur_state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE; 1098 cur_state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE;
1099 else
1100 cur_state = I915_READ(CURCNTR_IVB(pipe)) & CURSOR_MODE;
1101 1101
1102 WARN(cur_state != state, 1102 WARN(cur_state != state,
1103 "cursor on pipe %c assertion failure (expected %s, current %s)\n", 1103 "cursor on pipe %c assertion failure (expected %s, current %s)\n",
diff --git a/drivers/gpu/drm/i915/intel_dp.c b/drivers/gpu/drm/i915/intel_dp.c
index 57552eb386b0..2688f6d64bb9 100644
--- a/drivers/gpu/drm/i915/intel_dp.c
+++ b/drivers/gpu/drm/i915/intel_dp.c
@@ -1249,17 +1249,24 @@ void ironlake_edp_panel_off(struct intel_dp *intel_dp)
1249 1249
1250 DRM_DEBUG_KMS("Turn eDP power off\n"); 1250 DRM_DEBUG_KMS("Turn eDP power off\n");
1251 1251
1252 WARN(!intel_dp->want_panel_vdd, "Need VDD to turn off panel\n");
1253
1252 pp = ironlake_get_pp_control(intel_dp); 1254 pp = ironlake_get_pp_control(intel_dp);
1253 /* We need to switch off panel power _and_ force vdd, for otherwise some 1255 /* We need to switch off panel power _and_ force vdd, for otherwise some
1254 * panels get very unhappy and cease to work. */ 1256 * panels get very unhappy and cease to work. */
1255 pp &= ~(POWER_TARGET_ON | PANEL_POWER_RESET | EDP_BLC_ENABLE); 1257 pp &= ~(POWER_TARGET_ON | EDP_FORCE_VDD | PANEL_POWER_RESET | EDP_BLC_ENABLE);
1256 1258
1257 pp_ctrl_reg = _pp_ctrl_reg(intel_dp); 1259 pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
1258 1260
1259 I915_WRITE(pp_ctrl_reg, pp); 1261 I915_WRITE(pp_ctrl_reg, pp);
1260 POSTING_READ(pp_ctrl_reg); 1262 POSTING_READ(pp_ctrl_reg);
1261 1263
1264 intel_dp->want_panel_vdd = false;
1265
1262 ironlake_wait_panel_off(intel_dp); 1266 ironlake_wait_panel_off(intel_dp);
1267
1268 /* We got a reference when we enabled the VDD. */
1269 intel_runtime_pm_put(dev_priv);
1263} 1270}
1264 1271
1265void ironlake_edp_backlight_on(struct intel_dp *intel_dp) 1272void ironlake_edp_backlight_on(struct intel_dp *intel_dp)
@@ -1639,7 +1646,7 @@ static void intel_edp_psr_enable_source(struct intel_dp *intel_dp)
1639 val |= EDP_PSR_LINK_DISABLE; 1646 val |= EDP_PSR_LINK_DISABLE;
1640 1647
1641 I915_WRITE(EDP_PSR_CTL(dev), val | 1648 I915_WRITE(EDP_PSR_CTL(dev), val |
1642 IS_BROADWELL(dev) ? 0 : link_entry_time | 1649 (IS_BROADWELL(dev) ? 0 : link_entry_time) |
1643 max_sleep_time << EDP_PSR_MAX_SLEEP_TIME_SHIFT | 1650 max_sleep_time << EDP_PSR_MAX_SLEEP_TIME_SHIFT |
1644 idle_frames << EDP_PSR_IDLE_FRAME_SHIFT | 1651 idle_frames << EDP_PSR_IDLE_FRAME_SHIFT |
1645 EDP_PSR_ENABLE); 1652 EDP_PSR_ENABLE);
@@ -1784,6 +1791,7 @@ static void intel_disable_dp(struct intel_encoder *encoder)
1784 1791
1785 /* Make sure the panel is off before trying to change the mode. But also 1792 /* Make sure the panel is off before trying to change the mode. But also
1786 * ensure that we have vdd while we switch off the panel. */ 1793 * ensure that we have vdd while we switch off the panel. */
1794 ironlake_edp_panel_vdd_on(intel_dp);
1787 ironlake_edp_backlight_off(intel_dp); 1795 ironlake_edp_backlight_off(intel_dp);
1788 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF); 1796 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
1789 ironlake_edp_panel_off(intel_dp); 1797 ironlake_edp_panel_off(intel_dp);
diff --git a/drivers/gpu/drm/i915/intel_hdmi.c b/drivers/gpu/drm/i915/intel_hdmi.c
index 6db0d9d17f47..ee3181ebcc92 100644
--- a/drivers/gpu/drm/i915/intel_hdmi.c
+++ b/drivers/gpu/drm/i915/intel_hdmi.c
@@ -845,7 +845,7 @@ static int hdmi_portclock_limit(struct intel_hdmi *hdmi)
845{ 845{
846 struct drm_device *dev = intel_hdmi_to_dev(hdmi); 846 struct drm_device *dev = intel_hdmi_to_dev(hdmi);
847 847
848 if (IS_G4X(dev)) 848 if (!hdmi->has_hdmi_sink || IS_G4X(dev))
849 return 165000; 849 return 165000;
850 else if (IS_HASWELL(dev) || INTEL_INFO(dev)->gen >= 8) 850 else if (IS_HASWELL(dev) || INTEL_INFO(dev)->gen >= 8)
851 return 300000; 851 return 300000;
@@ -899,8 +899,8 @@ bool intel_hdmi_compute_config(struct intel_encoder *encoder,
899 * outputs. We also need to check that the higher clock still fits 899 * outputs. We also need to check that the higher clock still fits
900 * within limits. 900 * within limits.
901 */ 901 */
902 if (pipe_config->pipe_bpp > 8*3 && clock_12bpc <= portclock_limit 902 if (pipe_config->pipe_bpp > 8*3 && intel_hdmi->has_hdmi_sink &&
903 && HAS_PCH_SPLIT(dev)) { 903 clock_12bpc <= portclock_limit && HAS_PCH_SPLIT(dev)) {
904 DRM_DEBUG_KMS("picking bpc to 12 for HDMI output\n"); 904 DRM_DEBUG_KMS("picking bpc to 12 for HDMI output\n");
905 desired_bpp = 12*3; 905 desired_bpp = 12*3;
906 906
diff --git a/drivers/gpu/drm/i915/intel_panel.c b/drivers/gpu/drm/i915/intel_panel.c
index 350de359123a..079ea38f14d9 100644
--- a/drivers/gpu/drm/i915/intel_panel.c
+++ b/drivers/gpu/drm/i915/intel_panel.c
@@ -698,7 +698,7 @@ static void i9xx_enable_backlight(struct intel_connector *connector)
698 freq /= 0xff; 698 freq /= 0xff;
699 699
700 ctl = freq << 17; 700 ctl = freq << 17;
701 if (IS_GEN2(dev) && panel->backlight.combination_mode) 701 if (panel->backlight.combination_mode)
702 ctl |= BLM_LEGACY_MODE; 702 ctl |= BLM_LEGACY_MODE;
703 if (IS_PINEVIEW(dev) && panel->backlight.active_low_pwm) 703 if (IS_PINEVIEW(dev) && panel->backlight.active_low_pwm)
704 ctl |= BLM_POLARITY_PNV; 704 ctl |= BLM_POLARITY_PNV;
@@ -979,7 +979,7 @@ static int i9xx_setup_backlight(struct intel_connector *connector)
979 979
980 ctl = I915_READ(BLC_PWM_CTL); 980 ctl = I915_READ(BLC_PWM_CTL);
981 981
982 if (IS_GEN2(dev)) 982 if (IS_GEN2(dev) || IS_I915GM(dev) || IS_I945GM(dev))
983 panel->backlight.combination_mode = ctl & BLM_LEGACY_MODE; 983 panel->backlight.combination_mode = ctl & BLM_LEGACY_MODE;
984 984
985 if (IS_PINEVIEW(dev)) 985 if (IS_PINEVIEW(dev))
diff --git a/drivers/gpu/drm/i915/intel_pm.c b/drivers/gpu/drm/i915/intel_pm.c
index d77cc81900f9..e1fc35a72656 100644
--- a/drivers/gpu/drm/i915/intel_pm.c
+++ b/drivers/gpu/drm/i915/intel_pm.c
@@ -3493,6 +3493,8 @@ static void valleyview_setup_pctx(struct drm_device *dev)
3493 u32 pcbr; 3493 u32 pcbr;
3494 int pctx_size = 24*1024; 3494 int pctx_size = 24*1024;
3495 3495
3496 WARN_ON(!mutex_is_locked(&dev->struct_mutex));
3497
3496 pcbr = I915_READ(VLV_PCBR); 3498 pcbr = I915_READ(VLV_PCBR);
3497 if (pcbr) { 3499 if (pcbr) {
3498 /* BIOS set it up already, grab the pre-alloc'd space */ 3500 /* BIOS set it up already, grab the pre-alloc'd space */
@@ -3542,8 +3544,6 @@ static void valleyview_enable_rps(struct drm_device *dev)
3542 I915_WRITE(GTFIFODBG, gtfifodbg); 3544 I915_WRITE(GTFIFODBG, gtfifodbg);
3543 } 3545 }
3544 3546
3545 valleyview_setup_pctx(dev);
3546
3547 /* If VLV, Forcewake all wells, else re-direct to regular path */ 3547 /* If VLV, Forcewake all wells, else re-direct to regular path */
3548 gen6_gt_force_wake_get(dev_priv, FORCEWAKE_ALL); 3548 gen6_gt_force_wake_get(dev_priv, FORCEWAKE_ALL);
3549 3549
@@ -4395,6 +4395,8 @@ void intel_enable_gt_powersave(struct drm_device *dev)
4395 ironlake_enable_rc6(dev); 4395 ironlake_enable_rc6(dev);
4396 intel_init_emon(dev); 4396 intel_init_emon(dev);
4397 } else if (IS_GEN6(dev) || IS_GEN7(dev)) { 4397 } else if (IS_GEN6(dev) || IS_GEN7(dev)) {
4398 if (IS_VALLEYVIEW(dev))
4399 valleyview_setup_pctx(dev);
4398 /* 4400 /*
4399 * PCU communication is slow and this doesn't need to be 4401 * PCU communication is slow and this doesn't need to be
4400 * done at any specific time, so do this out of our fast path 4402 * done at any specific time, so do this out of our fast path
diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.c b/drivers/gpu/drm/nouveau/nouveau_drm.c
index 89c484d8ac26..4ee702ac8907 100644
--- a/drivers/gpu/drm/nouveau/nouveau_drm.c
+++ b/drivers/gpu/drm/nouveau/nouveau_drm.c
@@ -866,13 +866,16 @@ static int nouveau_pmops_runtime_suspend(struct device *dev)
866 struct drm_device *drm_dev = pci_get_drvdata(pdev); 866 struct drm_device *drm_dev = pci_get_drvdata(pdev);
867 int ret; 867 int ret;
868 868
869 if (nouveau_runtime_pm == 0) 869 if (nouveau_runtime_pm == 0) {
870 return -EINVAL; 870 pm_runtime_forbid(dev);
871 return -EBUSY;
872 }
871 873
872 /* are we optimus enabled? */ 874 /* are we optimus enabled? */
873 if (nouveau_runtime_pm == -1 && !nouveau_is_optimus() && !nouveau_is_v1_dsm()) { 875 if (nouveau_runtime_pm == -1 && !nouveau_is_optimus() && !nouveau_is_v1_dsm()) {
874 DRM_DEBUG_DRIVER("failing to power off - not optimus\n"); 876 DRM_DEBUG_DRIVER("failing to power off - not optimus\n");
875 return -EINVAL; 877 pm_runtime_forbid(dev);
878 return -EBUSY;
876 } 879 }
877 880
878 nv_debug_level(SILENT); 881 nv_debug_level(SILENT);
@@ -923,12 +926,15 @@ static int nouveau_pmops_runtime_idle(struct device *dev)
923 struct nouveau_drm *drm = nouveau_drm(drm_dev); 926 struct nouveau_drm *drm = nouveau_drm(drm_dev);
924 struct drm_crtc *crtc; 927 struct drm_crtc *crtc;
925 928
926 if (nouveau_runtime_pm == 0) 929 if (nouveau_runtime_pm == 0) {
930 pm_runtime_forbid(dev);
927 return -EBUSY; 931 return -EBUSY;
932 }
928 933
929 /* are we optimus enabled? */ 934 /* are we optimus enabled? */
930 if (nouveau_runtime_pm == -1 && !nouveau_is_optimus() && !nouveau_is_v1_dsm()) { 935 if (nouveau_runtime_pm == -1 && !nouveau_is_optimus() && !nouveau_is_v1_dsm()) {
931 DRM_DEBUG_DRIVER("failing to power off - not optimus\n"); 936 DRM_DEBUG_DRIVER("failing to power off - not optimus\n");
937 pm_runtime_forbid(dev);
932 return -EBUSY; 938 return -EBUSY;
933 } 939 }
934 940
diff --git a/drivers/gpu/drm/radeon/atombios_crtc.c b/drivers/gpu/drm/radeon/atombios_crtc.c
index 0d19f4f94d5a..daa4dd375ab1 100644
--- a/drivers/gpu/drm/radeon/atombios_crtc.c
+++ b/drivers/gpu/drm/radeon/atombios_crtc.c
@@ -1774,6 +1774,20 @@ static int radeon_atom_pick_pll(struct drm_crtc *crtc)
1774 return ATOM_PPLL1; 1774 return ATOM_PPLL1;
1775 DRM_ERROR("unable to allocate a PPLL\n"); 1775 DRM_ERROR("unable to allocate a PPLL\n");
1776 return ATOM_PPLL_INVALID; 1776 return ATOM_PPLL_INVALID;
1777 } else if (ASIC_IS_DCE41(rdev)) {
1778 /* Don't share PLLs on DCE4.1 chips */
1779 if (ENCODER_MODE_IS_DP(atombios_get_encoder_mode(radeon_crtc->encoder))) {
1780 if (rdev->clock.dp_extclk)
1781 /* skip PPLL programming if using ext clock */
1782 return ATOM_PPLL_INVALID;
1783 }
1784 pll_in_use = radeon_get_pll_use_mask(crtc);
1785 if (!(pll_in_use & (1 << ATOM_PPLL1)))
1786 return ATOM_PPLL1;
1787 if (!(pll_in_use & (1 << ATOM_PPLL2)))
1788 return ATOM_PPLL2;
1789 DRM_ERROR("unable to allocate a PPLL\n");
1790 return ATOM_PPLL_INVALID;
1777 } else if (ASIC_IS_DCE4(rdev)) { 1791 } else if (ASIC_IS_DCE4(rdev)) {
1778 /* in DP mode, the DP ref clock can come from PPLL, DCPLL, or ext clock, 1792 /* in DP mode, the DP ref clock can come from PPLL, DCPLL, or ext clock,
1779 * depending on the asic: 1793 * depending on the asic:
@@ -1801,7 +1815,7 @@ static int radeon_atom_pick_pll(struct drm_crtc *crtc)
1801 if (pll != ATOM_PPLL_INVALID) 1815 if (pll != ATOM_PPLL_INVALID)
1802 return pll; 1816 return pll;
1803 } 1817 }
1804 } else if (!ASIC_IS_DCE41(rdev)) { /* Don't share PLLs on DCE4.1 chips */ 1818 } else {
1805 /* use the same PPLL for all monitors with the same clock */ 1819 /* use the same PPLL for all monitors with the same clock */
1806 pll = radeon_get_shared_nondp_ppll(crtc); 1820 pll = radeon_get_shared_nondp_ppll(crtc);
1807 if (pll != ATOM_PPLL_INVALID) 1821 if (pll != ATOM_PPLL_INVALID)
diff --git a/drivers/gpu/drm/radeon/atombios_encoders.c b/drivers/gpu/drm/radeon/atombios_encoders.c
index 2cec2ab02f80..607dc14d195e 100644
--- a/drivers/gpu/drm/radeon/atombios_encoders.c
+++ b/drivers/gpu/drm/radeon/atombios_encoders.c
@@ -1314,7 +1314,7 @@ atombios_dig_transmitter_setup(struct drm_encoder *encoder, int action, uint8_t
1314 } 1314 }
1315 if (is_dp) 1315 if (is_dp)
1316 args.v5.ucLaneNum = dp_lane_count; 1316 args.v5.ucLaneNum = dp_lane_count;
1317 else if (radeon_encoder->pixel_clock > 165000) 1317 else if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock))
1318 args.v5.ucLaneNum = 8; 1318 args.v5.ucLaneNum = 8;
1319 else 1319 else
1320 args.v5.ucLaneNum = 4; 1320 args.v5.ucLaneNum = 4;
diff --git a/drivers/gpu/drm/radeon/cik.c b/drivers/gpu/drm/radeon/cik.c
index e6419ca7cd37..bbb17841a9e5 100644
--- a/drivers/gpu/drm/radeon/cik.c
+++ b/drivers/gpu/drm/radeon/cik.c
@@ -3046,7 +3046,7 @@ static u32 cik_create_bitmask(u32 bit_width)
3046} 3046}
3047 3047
3048/** 3048/**
3049 * cik_select_se_sh - select which SE, SH to address 3049 * cik_get_rb_disabled - computes the mask of disabled RBs
3050 * 3050 *
3051 * @rdev: radeon_device pointer 3051 * @rdev: radeon_device pointer
3052 * @max_rb_num: max RBs (render backends) for the asic 3052 * @max_rb_num: max RBs (render backends) for the asic
@@ -4134,8 +4134,11 @@ static void cik_cp_compute_enable(struct radeon_device *rdev, bool enable)
4134{ 4134{
4135 if (enable) 4135 if (enable)
4136 WREG32(CP_MEC_CNTL, 0); 4136 WREG32(CP_MEC_CNTL, 0);
4137 else 4137 else {
4138 WREG32(CP_MEC_CNTL, (MEC_ME1_HALT | MEC_ME2_HALT)); 4138 WREG32(CP_MEC_CNTL, (MEC_ME1_HALT | MEC_ME2_HALT));
4139 rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX].ready = false;
4140 rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX].ready = false;
4141 }
4139 udelay(50); 4142 udelay(50);
4140} 4143}
4141 4144
@@ -7902,7 +7905,8 @@ int cik_resume(struct radeon_device *rdev)
7902 /* init golden registers */ 7905 /* init golden registers */
7903 cik_init_golden_registers(rdev); 7906 cik_init_golden_registers(rdev);
7904 7907
7905 radeon_pm_resume(rdev); 7908 if (rdev->pm.pm_method == PM_METHOD_DPM)
7909 radeon_pm_resume(rdev);
7906 7910
7907 rdev->accel_working = true; 7911 rdev->accel_working = true;
7908 r = cik_startup(rdev); 7912 r = cik_startup(rdev);
diff --git a/drivers/gpu/drm/radeon/cik_sdma.c b/drivers/gpu/drm/radeon/cik_sdma.c
index 1ecb3f1070e3..94626ea90fa5 100644
--- a/drivers/gpu/drm/radeon/cik_sdma.c
+++ b/drivers/gpu/drm/radeon/cik_sdma.c
@@ -264,6 +264,8 @@ static void cik_sdma_gfx_stop(struct radeon_device *rdev)
264 WREG32(SDMA0_GFX_RB_CNTL + reg_offset, rb_cntl); 264 WREG32(SDMA0_GFX_RB_CNTL + reg_offset, rb_cntl);
265 WREG32(SDMA0_GFX_IB_CNTL + reg_offset, 0); 265 WREG32(SDMA0_GFX_IB_CNTL + reg_offset, 0);
266 } 266 }
267 rdev->ring[R600_RING_TYPE_DMA_INDEX].ready = false;
268 rdev->ring[CAYMAN_RING_TYPE_DMA1_INDEX].ready = false;
267} 269}
268 270
269/** 271/**
@@ -291,6 +293,11 @@ void cik_sdma_enable(struct radeon_device *rdev, bool enable)
291 u32 me_cntl, reg_offset; 293 u32 me_cntl, reg_offset;
292 int i; 294 int i;
293 295
296 if (enable == false) {
297 cik_sdma_gfx_stop(rdev);
298 cik_sdma_rlc_stop(rdev);
299 }
300
294 for (i = 0; i < 2; i++) { 301 for (i = 0; i < 2; i++) {
295 if (i == 0) 302 if (i == 0)
296 reg_offset = SDMA0_REGISTER_OFFSET; 303 reg_offset = SDMA0_REGISTER_OFFSET;
@@ -420,10 +427,6 @@ static int cik_sdma_load_microcode(struct radeon_device *rdev)
420 if (!rdev->sdma_fw) 427 if (!rdev->sdma_fw)
421 return -EINVAL; 428 return -EINVAL;
422 429
423 /* stop the gfx rings and rlc compute queues */
424 cik_sdma_gfx_stop(rdev);
425 cik_sdma_rlc_stop(rdev);
426
427 /* halt the MEs */ 430 /* halt the MEs */
428 cik_sdma_enable(rdev, false); 431 cik_sdma_enable(rdev, false);
429 432
@@ -492,9 +495,6 @@ int cik_sdma_resume(struct radeon_device *rdev)
492 */ 495 */
493void cik_sdma_fini(struct radeon_device *rdev) 496void cik_sdma_fini(struct radeon_device *rdev)
494{ 497{
495 /* stop the gfx rings and rlc compute queues */
496 cik_sdma_gfx_stop(rdev);
497 cik_sdma_rlc_stop(rdev);
498 /* halt the MEs */ 498 /* halt the MEs */
499 cik_sdma_enable(rdev, false); 499 cik_sdma_enable(rdev, false);
500 radeon_ring_fini(rdev, &rdev->ring[R600_RING_TYPE_DMA_INDEX]); 500 radeon_ring_fini(rdev, &rdev->ring[R600_RING_TYPE_DMA_INDEX]);
diff --git a/drivers/gpu/drm/radeon/dce6_afmt.c b/drivers/gpu/drm/radeon/dce6_afmt.c
index 713a5d359901..94e858751994 100644
--- a/drivers/gpu/drm/radeon/dce6_afmt.c
+++ b/drivers/gpu/drm/radeon/dce6_afmt.c
@@ -278,13 +278,15 @@ static int dce6_audio_chipset_supported(struct radeon_device *rdev)
278 return !ASIC_IS_NODCE(rdev); 278 return !ASIC_IS_NODCE(rdev);
279} 279}
280 280
281static void dce6_audio_enable(struct radeon_device *rdev, 281void dce6_audio_enable(struct radeon_device *rdev,
282 struct r600_audio_pin *pin, 282 struct r600_audio_pin *pin,
283 bool enable) 283 bool enable)
284{ 284{
285 if (!pin)
286 return;
287
285 WREG32_ENDPOINT(pin->offset, AZ_F0_CODEC_PIN_CONTROL_HOTPLUG_CONTROL, 288 WREG32_ENDPOINT(pin->offset, AZ_F0_CODEC_PIN_CONTROL_HOTPLUG_CONTROL,
286 AUDIO_ENABLED); 289 enable ? AUDIO_ENABLED : 0);
287 DRM_INFO("%s audio %d support\n", enable ? "Enabling" : "Disabling", pin->id);
288} 290}
289 291
290static const u32 pin_offsets[7] = 292static const u32 pin_offsets[7] =
@@ -323,7 +325,8 @@ int dce6_audio_init(struct radeon_device *rdev)
323 rdev->audio.pin[i].connected = false; 325 rdev->audio.pin[i].connected = false;
324 rdev->audio.pin[i].offset = pin_offsets[i]; 326 rdev->audio.pin[i].offset = pin_offsets[i];
325 rdev->audio.pin[i].id = i; 327 rdev->audio.pin[i].id = i;
326 dce6_audio_enable(rdev, &rdev->audio.pin[i], true); 328 /* disable audio. it will be set up later */
329 dce6_audio_enable(rdev, &rdev->audio.pin[i], false);
327 } 330 }
328 331
329 return 0; 332 return 0;
diff --git a/drivers/gpu/drm/radeon/evergreen.c b/drivers/gpu/drm/radeon/evergreen.c
index 5623e7542d99..27b0ff16082e 100644
--- a/drivers/gpu/drm/radeon/evergreen.c
+++ b/drivers/gpu/drm/radeon/evergreen.c
@@ -5299,7 +5299,8 @@ int evergreen_resume(struct radeon_device *rdev)
5299 /* init golden registers */ 5299 /* init golden registers */
5300 evergreen_init_golden_registers(rdev); 5300 evergreen_init_golden_registers(rdev);
5301 5301
5302 radeon_pm_resume(rdev); 5302 if (rdev->pm.pm_method == PM_METHOD_DPM)
5303 radeon_pm_resume(rdev);
5303 5304
5304 rdev->accel_working = true; 5305 rdev->accel_working = true;
5305 r = evergreen_startup(rdev); 5306 r = evergreen_startup(rdev);
@@ -5475,9 +5476,9 @@ void evergreen_fini(struct radeon_device *rdev)
5475 radeon_wb_fini(rdev); 5476 radeon_wb_fini(rdev);
5476 radeon_ib_pool_fini(rdev); 5477 radeon_ib_pool_fini(rdev);
5477 radeon_irq_kms_fini(rdev); 5478 radeon_irq_kms_fini(rdev);
5478 evergreen_pcie_gart_fini(rdev);
5479 uvd_v1_0_fini(rdev); 5479 uvd_v1_0_fini(rdev);
5480 radeon_uvd_fini(rdev); 5480 radeon_uvd_fini(rdev);
5481 evergreen_pcie_gart_fini(rdev);
5481 r600_vram_scratch_fini(rdev); 5482 r600_vram_scratch_fini(rdev);
5482 radeon_gem_fini(rdev); 5483 radeon_gem_fini(rdev);
5483 radeon_fence_driver_fini(rdev); 5484 radeon_fence_driver_fini(rdev);
diff --git a/drivers/gpu/drm/radeon/evergreen_hdmi.c b/drivers/gpu/drm/radeon/evergreen_hdmi.c
index 0c6d5cef4cf1..05b0c95813fd 100644
--- a/drivers/gpu/drm/radeon/evergreen_hdmi.c
+++ b/drivers/gpu/drm/radeon/evergreen_hdmi.c
@@ -306,6 +306,15 @@ void evergreen_hdmi_setmode(struct drm_encoder *encoder, struct drm_display_mode
306 return; 306 return;
307 offset = dig->afmt->offset; 307 offset = dig->afmt->offset;
308 308
309 /* disable audio prior to setting up hw */
310 if (ASIC_IS_DCE6(rdev)) {
311 dig->afmt->pin = dce6_audio_get_pin(rdev);
312 dce6_audio_enable(rdev, dig->afmt->pin, false);
313 } else {
314 dig->afmt->pin = r600_audio_get_pin(rdev);
315 r600_audio_enable(rdev, dig->afmt->pin, false);
316 }
317
309 evergreen_audio_set_dto(encoder, mode->clock); 318 evergreen_audio_set_dto(encoder, mode->clock);
310 319
311 WREG32(HDMI_VBI_PACKET_CONTROL + offset, 320 WREG32(HDMI_VBI_PACKET_CONTROL + offset,
@@ -409,12 +418,16 @@ void evergreen_hdmi_setmode(struct drm_encoder *encoder, struct drm_display_mode
409 WREG32(AFMT_RAMP_CONTROL1 + offset, 0x007FFFFF); 418 WREG32(AFMT_RAMP_CONTROL1 + offset, 0x007FFFFF);
410 WREG32(AFMT_RAMP_CONTROL2 + offset, 0x00000001); 419 WREG32(AFMT_RAMP_CONTROL2 + offset, 0x00000001);
411 WREG32(AFMT_RAMP_CONTROL3 + offset, 0x00000001); 420 WREG32(AFMT_RAMP_CONTROL3 + offset, 0x00000001);
421
422 /* enable audio after to setting up hw */
423 if (ASIC_IS_DCE6(rdev))
424 dce6_audio_enable(rdev, dig->afmt->pin, true);
425 else
426 r600_audio_enable(rdev, dig->afmt->pin, true);
412} 427}
413 428
414void evergreen_hdmi_enable(struct drm_encoder *encoder, bool enable) 429void evergreen_hdmi_enable(struct drm_encoder *encoder, bool enable)
415{ 430{
416 struct drm_device *dev = encoder->dev;
417 struct radeon_device *rdev = dev->dev_private;
418 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 431 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
419 struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv; 432 struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
420 433
@@ -427,15 +440,6 @@ void evergreen_hdmi_enable(struct drm_encoder *encoder, bool enable)
427 if (!enable && !dig->afmt->enabled) 440 if (!enable && !dig->afmt->enabled)
428 return; 441 return;
429 442
430 if (enable) {
431 if (ASIC_IS_DCE6(rdev))
432 dig->afmt->pin = dce6_audio_get_pin(rdev);
433 else
434 dig->afmt->pin = r600_audio_get_pin(rdev);
435 } else {
436 dig->afmt->pin = NULL;
437 }
438
439 dig->afmt->enabled = enable; 443 dig->afmt->enabled = enable;
440 444
441 DRM_DEBUG("%sabling HDMI interface @ 0x%04X for encoder 0x%x\n", 445 DRM_DEBUG("%sabling HDMI interface @ 0x%04X for encoder 0x%x\n",
diff --git a/drivers/gpu/drm/radeon/evergreen_smc.h b/drivers/gpu/drm/radeon/evergreen_smc.h
index 76ada8cfe902..3a03ba37d043 100644
--- a/drivers/gpu/drm/radeon/evergreen_smc.h
+++ b/drivers/gpu/drm/radeon/evergreen_smc.h
@@ -57,7 +57,7 @@ typedef struct SMC_Evergreen_MCRegisters SMC_Evergreen_MCRegisters;
57 57
58#define EVERGREEN_SMC_FIRMWARE_HEADER_LOCATION 0x100 58#define EVERGREEN_SMC_FIRMWARE_HEADER_LOCATION 0x100
59 59
60#define EVERGREEN_SMC_FIRMWARE_HEADER_softRegisters 0x0 60#define EVERGREEN_SMC_FIRMWARE_HEADER_softRegisters 0x8
61#define EVERGREEN_SMC_FIRMWARE_HEADER_stateTable 0xC 61#define EVERGREEN_SMC_FIRMWARE_HEADER_stateTable 0xC
62#define EVERGREEN_SMC_FIRMWARE_HEADER_mcRegisterTable 0x20 62#define EVERGREEN_SMC_FIRMWARE_HEADER_mcRegisterTable 0x20
63 63
diff --git a/drivers/gpu/drm/radeon/ni.c b/drivers/gpu/drm/radeon/ni.c
index ea932ac66fc6..bf6300cfd62d 100644
--- a/drivers/gpu/drm/radeon/ni.c
+++ b/drivers/gpu/drm/radeon/ni.c
@@ -2105,7 +2105,8 @@ int cayman_resume(struct radeon_device *rdev)
2105 /* init golden registers */ 2105 /* init golden registers */
2106 ni_init_golden_registers(rdev); 2106 ni_init_golden_registers(rdev);
2107 2107
2108 radeon_pm_resume(rdev); 2108 if (rdev->pm.pm_method == PM_METHOD_DPM)
2109 radeon_pm_resume(rdev);
2109 2110
2110 rdev->accel_working = true; 2111 rdev->accel_working = true;
2111 r = cayman_startup(rdev); 2112 r = cayman_startup(rdev);
diff --git a/drivers/gpu/drm/radeon/r100.c b/drivers/gpu/drm/radeon/r100.c
index ef024ce3f7cc..3cc78bb66042 100644
--- a/drivers/gpu/drm/radeon/r100.c
+++ b/drivers/gpu/drm/radeon/r100.c
@@ -3942,8 +3942,6 @@ int r100_resume(struct radeon_device *rdev)
3942 /* Initialize surface registers */ 3942 /* Initialize surface registers */
3943 radeon_surface_init(rdev); 3943 radeon_surface_init(rdev);
3944 3944
3945 radeon_pm_resume(rdev);
3946
3947 rdev->accel_working = true; 3945 rdev->accel_working = true;
3948 r = r100_startup(rdev); 3946 r = r100_startup(rdev);
3949 if (r) { 3947 if (r) {
diff --git a/drivers/gpu/drm/radeon/r300.c b/drivers/gpu/drm/radeon/r300.c
index 7c63ef840e86..0b658b34b33a 100644
--- a/drivers/gpu/drm/radeon/r300.c
+++ b/drivers/gpu/drm/radeon/r300.c
@@ -1430,8 +1430,6 @@ int r300_resume(struct radeon_device *rdev)
1430 /* Initialize surface registers */ 1430 /* Initialize surface registers */
1431 radeon_surface_init(rdev); 1431 radeon_surface_init(rdev);
1432 1432
1433 radeon_pm_resume(rdev);
1434
1435 rdev->accel_working = true; 1433 rdev->accel_working = true;
1436 r = r300_startup(rdev); 1434 r = r300_startup(rdev);
1437 if (r) { 1435 if (r) {
diff --git a/drivers/gpu/drm/radeon/r420.c b/drivers/gpu/drm/radeon/r420.c
index 3768aab2710b..802b19220a21 100644
--- a/drivers/gpu/drm/radeon/r420.c
+++ b/drivers/gpu/drm/radeon/r420.c
@@ -325,8 +325,6 @@ int r420_resume(struct radeon_device *rdev)
325 /* Initialize surface registers */ 325 /* Initialize surface registers */
326 radeon_surface_init(rdev); 326 radeon_surface_init(rdev);
327 327
328 radeon_pm_resume(rdev);
329
330 rdev->accel_working = true; 328 rdev->accel_working = true;
331 r = r420_startup(rdev); 329 r = r420_startup(rdev);
332 if (r) { 330 if (r) {
diff --git a/drivers/gpu/drm/radeon/r520.c b/drivers/gpu/drm/radeon/r520.c
index e209eb75024f..98d6053c36c6 100644
--- a/drivers/gpu/drm/radeon/r520.c
+++ b/drivers/gpu/drm/radeon/r520.c
@@ -240,8 +240,6 @@ int r520_resume(struct radeon_device *rdev)
240 /* Initialize surface registers */ 240 /* Initialize surface registers */
241 radeon_surface_init(rdev); 241 radeon_surface_init(rdev);
242 242
243 radeon_pm_resume(rdev);
244
245 rdev->accel_working = true; 243 rdev->accel_working = true;
246 r = r520_startup(rdev); 244 r = r520_startup(rdev);
247 if (r) { 245 if (r) {
diff --git a/drivers/gpu/drm/radeon/r600.c b/drivers/gpu/drm/radeon/r600.c
index cdbc4171fe73..647ef4079217 100644
--- a/drivers/gpu/drm/radeon/r600.c
+++ b/drivers/gpu/drm/radeon/r600.c
@@ -2968,7 +2968,8 @@ int r600_resume(struct radeon_device *rdev)
2968 /* post card */ 2968 /* post card */
2969 atom_asic_init(rdev->mode_info.atom_context); 2969 atom_asic_init(rdev->mode_info.atom_context);
2970 2970
2971 radeon_pm_resume(rdev); 2971 if (rdev->pm.pm_method == PM_METHOD_DPM)
2972 radeon_pm_resume(rdev);
2972 2973
2973 rdev->accel_working = true; 2974 rdev->accel_working = true;
2974 r = r600_startup(rdev); 2975 r = r600_startup(rdev);
diff --git a/drivers/gpu/drm/radeon/r600_audio.c b/drivers/gpu/drm/radeon/r600_audio.c
index 47fc2b886979..bffac10c4296 100644
--- a/drivers/gpu/drm/radeon/r600_audio.c
+++ b/drivers/gpu/drm/radeon/r600_audio.c
@@ -142,12 +142,15 @@ void r600_audio_update_hdmi(struct work_struct *work)
142} 142}
143 143
144/* enable the audio stream */ 144/* enable the audio stream */
145static void r600_audio_enable(struct radeon_device *rdev, 145void r600_audio_enable(struct radeon_device *rdev,
146 struct r600_audio_pin *pin, 146 struct r600_audio_pin *pin,
147 bool enable) 147 bool enable)
148{ 148{
149 u32 value = 0; 149 u32 value = 0;
150 150
151 if (!pin)
152 return;
153
151 if (ASIC_IS_DCE4(rdev)) { 154 if (ASIC_IS_DCE4(rdev)) {
152 if (enable) { 155 if (enable) {
153 value |= 0x81000000; /* Required to enable audio */ 156 value |= 0x81000000; /* Required to enable audio */
@@ -158,7 +161,6 @@ static void r600_audio_enable(struct radeon_device *rdev,
158 WREG32_P(R600_AUDIO_ENABLE, 161 WREG32_P(R600_AUDIO_ENABLE,
159 enable ? 0x81000000 : 0x0, ~0x81000000); 162 enable ? 0x81000000 : 0x0, ~0x81000000);
160 } 163 }
161 DRM_INFO("%s audio %d support\n", enable ? "Enabling" : "Disabling", pin->id);
162} 164}
163 165
164/* 166/*
@@ -178,8 +180,8 @@ int r600_audio_init(struct radeon_device *rdev)
178 rdev->audio.pin[0].status_bits = 0; 180 rdev->audio.pin[0].status_bits = 0;
179 rdev->audio.pin[0].category_code = 0; 181 rdev->audio.pin[0].category_code = 0;
180 rdev->audio.pin[0].id = 0; 182 rdev->audio.pin[0].id = 0;
181 183 /* disable audio. it will be set up later */
182 r600_audio_enable(rdev, &rdev->audio.pin[0], true); 184 r600_audio_enable(rdev, &rdev->audio.pin[0], false);
183 185
184 return 0; 186 return 0;
185} 187}
diff --git a/drivers/gpu/drm/radeon/r600_hdmi.c b/drivers/gpu/drm/radeon/r600_hdmi.c
index 3016fc14f502..85a2bb28aed2 100644
--- a/drivers/gpu/drm/radeon/r600_hdmi.c
+++ b/drivers/gpu/drm/radeon/r600_hdmi.c
@@ -329,9 +329,6 @@ static void dce3_2_afmt_write_speaker_allocation(struct drm_encoder *encoder)
329 u8 *sadb; 329 u8 *sadb;
330 int sad_count; 330 int sad_count;
331 331
332 /* XXX: setting this register causes hangs on some asics */
333 return;
334
335 list_for_each_entry(connector, &encoder->dev->mode_config.connector_list, head) { 332 list_for_each_entry(connector, &encoder->dev->mode_config.connector_list, head) {
336 if (connector->encoder == encoder) { 333 if (connector->encoder == encoder) {
337 radeon_connector = to_radeon_connector(connector); 334 radeon_connector = to_radeon_connector(connector);
@@ -460,6 +457,10 @@ void r600_hdmi_setmode(struct drm_encoder *encoder, struct drm_display_mode *mod
460 return; 457 return;
461 offset = dig->afmt->offset; 458 offset = dig->afmt->offset;
462 459
460 /* disable audio prior to setting up hw */
461 dig->afmt->pin = r600_audio_get_pin(rdev);
462 r600_audio_enable(rdev, dig->afmt->pin, false);
463
463 r600_audio_set_dto(encoder, mode->clock); 464 r600_audio_set_dto(encoder, mode->clock);
464 465
465 WREG32(HDMI0_VBI_PACKET_CONTROL + offset, 466 WREG32(HDMI0_VBI_PACKET_CONTROL + offset,
@@ -531,6 +532,9 @@ void r600_hdmi_setmode(struct drm_encoder *encoder, struct drm_display_mode *mod
531 WREG32(HDMI0_RAMP_CONTROL3 + offset, 0x00000001); 532 WREG32(HDMI0_RAMP_CONTROL3 + offset, 0x00000001);
532 533
533 r600_hdmi_audio_workaround(encoder); 534 r600_hdmi_audio_workaround(encoder);
535
536 /* enable audio after to setting up hw */
537 r600_audio_enable(rdev, dig->afmt->pin, true);
534} 538}
535 539
536/* 540/*
@@ -651,11 +655,6 @@ void r600_hdmi_enable(struct drm_encoder *encoder, bool enable)
651 if (!enable && !dig->afmt->enabled) 655 if (!enable && !dig->afmt->enabled)
652 return; 656 return;
653 657
654 if (enable)
655 dig->afmt->pin = r600_audio_get_pin(rdev);
656 else
657 dig->afmt->pin = NULL;
658
659 /* Older chipsets require setting HDMI and routing manually */ 658 /* Older chipsets require setting HDMI and routing manually */
660 if (!ASIC_IS_DCE3(rdev)) { 659 if (!ASIC_IS_DCE3(rdev)) {
661 if (enable) 660 if (enable)
diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
index 024db37b1832..e887d027b6d0 100644
--- a/drivers/gpu/drm/radeon/radeon.h
+++ b/drivers/gpu/drm/radeon/radeon.h
@@ -2747,6 +2747,12 @@ int radeon_vm_bo_rmv(struct radeon_device *rdev,
2747void r600_audio_update_hdmi(struct work_struct *work); 2747void r600_audio_update_hdmi(struct work_struct *work);
2748struct r600_audio_pin *r600_audio_get_pin(struct radeon_device *rdev); 2748struct r600_audio_pin *r600_audio_get_pin(struct radeon_device *rdev);
2749struct r600_audio_pin *dce6_audio_get_pin(struct radeon_device *rdev); 2749struct r600_audio_pin *dce6_audio_get_pin(struct radeon_device *rdev);
2750void r600_audio_enable(struct radeon_device *rdev,
2751 struct r600_audio_pin *pin,
2752 bool enable);
2753void dce6_audio_enable(struct radeon_device *rdev,
2754 struct r600_audio_pin *pin,
2755 bool enable);
2750 2756
2751/* 2757/*
2752 * R600 vram scratch functions 2758 * R600 vram scratch functions
diff --git a/drivers/gpu/drm/radeon/radeon_atpx_handler.c b/drivers/gpu/drm/radeon/radeon_atpx_handler.c
index 485848f889f5..fa9a9c02751e 100644
--- a/drivers/gpu/drm/radeon/radeon_atpx_handler.c
+++ b/drivers/gpu/drm/radeon/radeon_atpx_handler.c
@@ -219,7 +219,8 @@ static int radeon_atpx_verify_interface(struct radeon_atpx *atpx)
219 memcpy(&output, info->buffer.pointer, size); 219 memcpy(&output, info->buffer.pointer, size);
220 220
221 /* TODO: check version? */ 221 /* TODO: check version? */
222 printk("ATPX version %u\n", output.version); 222 printk("ATPX version %u, functions 0x%08x\n",
223 output.version, output.function_bits);
223 224
224 radeon_atpx_parse_functions(&atpx->functions, output.function_bits); 225 radeon_atpx_parse_functions(&atpx->functions, output.function_bits);
225 226
diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
index b012cbbc3ed5..044bc98fb459 100644
--- a/drivers/gpu/drm/radeon/radeon_device.c
+++ b/drivers/gpu/drm/radeon/radeon_device.c
@@ -1521,13 +1521,16 @@ int radeon_resume_kms(struct drm_device *dev, bool resume, bool fbcon)
1521 if (r) 1521 if (r)
1522 DRM_ERROR("ib ring test failed (%d).\n", r); 1522 DRM_ERROR("ib ring test failed (%d).\n", r);
1523 1523
1524 if (rdev->pm.dpm_enabled) { 1524 if ((rdev->pm.pm_method == PM_METHOD_DPM) && rdev->pm.dpm_enabled) {
1525 /* do dpm late init */ 1525 /* do dpm late init */
1526 r = radeon_pm_late_init(rdev); 1526 r = radeon_pm_late_init(rdev);
1527 if (r) { 1527 if (r) {
1528 rdev->pm.dpm_enabled = false; 1528 rdev->pm.dpm_enabled = false;
1529 DRM_ERROR("radeon_pm_late_init failed, disabling dpm\n"); 1529 DRM_ERROR("radeon_pm_late_init failed, disabling dpm\n");
1530 } 1530 }
1531 } else {
1532 /* resume old pm late */
1533 radeon_pm_resume(rdev);
1531 } 1534 }
1532 1535
1533 radeon_restore_bios_scratch_regs(rdev); 1536 radeon_restore_bios_scratch_regs(rdev);
diff --git a/drivers/gpu/drm/radeon/radeon_drv.c b/drivers/gpu/drm/radeon/radeon_drv.c
index 84a1bbb75f91..f633c2782170 100644
--- a/drivers/gpu/drm/radeon/radeon_drv.c
+++ b/drivers/gpu/drm/radeon/radeon_drv.c
@@ -403,11 +403,15 @@ static int radeon_pmops_runtime_suspend(struct device *dev)
403 struct drm_device *drm_dev = pci_get_drvdata(pdev); 403 struct drm_device *drm_dev = pci_get_drvdata(pdev);
404 int ret; 404 int ret;
405 405
406 if (radeon_runtime_pm == 0) 406 if (radeon_runtime_pm == 0) {
407 return -EINVAL; 407 pm_runtime_forbid(dev);
408 return -EBUSY;
409 }
408 410
409 if (radeon_runtime_pm == -1 && !radeon_is_px()) 411 if (radeon_runtime_pm == -1 && !radeon_is_px()) {
410 return -EINVAL; 412 pm_runtime_forbid(dev);
413 return -EBUSY;
414 }
411 415
412 drm_dev->switch_power_state = DRM_SWITCH_POWER_CHANGING; 416 drm_dev->switch_power_state = DRM_SWITCH_POWER_CHANGING;
413 drm_kms_helper_poll_disable(drm_dev); 417 drm_kms_helper_poll_disable(drm_dev);
@@ -456,12 +460,15 @@ static int radeon_pmops_runtime_idle(struct device *dev)
456 struct drm_device *drm_dev = pci_get_drvdata(pdev); 460 struct drm_device *drm_dev = pci_get_drvdata(pdev);
457 struct drm_crtc *crtc; 461 struct drm_crtc *crtc;
458 462
459 if (radeon_runtime_pm == 0) 463 if (radeon_runtime_pm == 0) {
464 pm_runtime_forbid(dev);
460 return -EBUSY; 465 return -EBUSY;
466 }
461 467
462 /* are we PX enabled? */ 468 /* are we PX enabled? */
463 if (radeon_runtime_pm == -1 && !radeon_is_px()) { 469 if (radeon_runtime_pm == -1 && !radeon_is_px()) {
464 DRM_DEBUG_DRIVER("failing to power off - not px\n"); 470 DRM_DEBUG_DRIVER("failing to power off - not px\n");
471 pm_runtime_forbid(dev);
465 return -EBUSY; 472 return -EBUSY;
466 } 473 }
467 474
diff --git a/drivers/gpu/drm/radeon/radeon_kms.c b/drivers/gpu/drm/radeon/radeon_kms.c
index 114d1672d616..66ed3ea71440 100644
--- a/drivers/gpu/drm/radeon/radeon_kms.c
+++ b/drivers/gpu/drm/radeon/radeon_kms.c
@@ -33,6 +33,13 @@
33#include <linux/vga_switcheroo.h> 33#include <linux/vga_switcheroo.h>
34#include <linux/slab.h> 34#include <linux/slab.h>
35#include <linux/pm_runtime.h> 35#include <linux/pm_runtime.h>
36
37#if defined(CONFIG_VGA_SWITCHEROO)
38bool radeon_is_px(void);
39#else
40static inline bool radeon_is_px(void) { return false; }
41#endif
42
36/** 43/**
37 * radeon_driver_unload_kms - Main unload function for KMS. 44 * radeon_driver_unload_kms - Main unload function for KMS.
38 * 45 *
@@ -130,7 +137,8 @@ int radeon_driver_load_kms(struct drm_device *dev, unsigned long flags)
130 "Error during ACPI methods call\n"); 137 "Error during ACPI methods call\n");
131 } 138 }
132 139
133 if (radeon_runtime_pm != 0) { 140 if ((radeon_runtime_pm == 1) ||
141 ((radeon_runtime_pm == -1) && radeon_is_px())) {
134 pm_runtime_use_autosuspend(dev->dev); 142 pm_runtime_use_autosuspend(dev->dev);
135 pm_runtime_set_autosuspend_delay(dev->dev, 5000); 143 pm_runtime_set_autosuspend_delay(dev->dev, 5000);
136 pm_runtime_set_active(dev->dev); 144 pm_runtime_set_active(dev->dev);
@@ -537,6 +545,10 @@ int radeon_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv)
537 545
538 radeon_vm_init(rdev, &fpriv->vm); 546 radeon_vm_init(rdev, &fpriv->vm);
539 547
548 r = radeon_bo_reserve(rdev->ring_tmp_bo.bo, false);
549 if (r)
550 return r;
551
540 /* map the ib pool buffer read only into 552 /* map the ib pool buffer read only into
541 * virtual address space */ 553 * virtual address space */
542 bo_va = radeon_vm_bo_add(rdev, &fpriv->vm, 554 bo_va = radeon_vm_bo_add(rdev, &fpriv->vm,
@@ -544,6 +556,8 @@ int radeon_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv)
544 r = radeon_vm_bo_set_addr(rdev, bo_va, RADEON_VA_IB_OFFSET, 556 r = radeon_vm_bo_set_addr(rdev, bo_va, RADEON_VA_IB_OFFSET,
545 RADEON_VM_PAGE_READABLE | 557 RADEON_VM_PAGE_READABLE |
546 RADEON_VM_PAGE_SNOOPED); 558 RADEON_VM_PAGE_SNOOPED);
559
560 radeon_bo_unreserve(rdev->ring_tmp_bo.bo);
547 if (r) { 561 if (r) {
548 radeon_vm_fini(rdev, &fpriv->vm); 562 radeon_vm_fini(rdev, &fpriv->vm);
549 kfree(fpriv); 563 kfree(fpriv);
diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
index 77f5b0c3edb8..040a2a10ea17 100644
--- a/drivers/gpu/drm/radeon/radeon_ttm.c
+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
@@ -714,6 +714,9 @@ int radeon_ttm_init(struct radeon_device *rdev)
714 DRM_ERROR("Failed initializing VRAM heap.\n"); 714 DRM_ERROR("Failed initializing VRAM heap.\n");
715 return r; 715 return r;
716 } 716 }
717 /* Change the size here instead of the init above so only lpfn is affected */
718 radeon_ttm_set_active_vram_size(rdev, rdev->mc.visible_vram_size);
719
717 r = radeon_bo_create(rdev, 256 * 1024, PAGE_SIZE, true, 720 r = radeon_bo_create(rdev, 256 * 1024, PAGE_SIZE, true,
718 RADEON_GEM_DOMAIN_VRAM, 721 RADEON_GEM_DOMAIN_VRAM,
719 NULL, &rdev->stollen_vga_memory); 722 NULL, &rdev->stollen_vga_memory);
@@ -935,7 +938,7 @@ static ssize_t radeon_ttm_gtt_read(struct file *f, char __user *buf,
935 while (size) { 938 while (size) {
936 loff_t p = *pos / PAGE_SIZE; 939 loff_t p = *pos / PAGE_SIZE;
937 unsigned off = *pos & ~PAGE_MASK; 940 unsigned off = *pos & ~PAGE_MASK;
938 ssize_t cur_size = min(size, PAGE_SIZE - off); 941 size_t cur_size = min_t(size_t, size, PAGE_SIZE - off);
939 struct page *page; 942 struct page *page;
940 void *ptr; 943 void *ptr;
941 944
diff --git a/drivers/gpu/drm/radeon/radeon_uvd.c b/drivers/gpu/drm/radeon/radeon_uvd.c
index 6781fee1eaad..3e6804b2b2ef 100644
--- a/drivers/gpu/drm/radeon/radeon_uvd.c
+++ b/drivers/gpu/drm/radeon/radeon_uvd.c
@@ -171,6 +171,8 @@ void radeon_uvd_fini(struct radeon_device *rdev)
171 171
172 radeon_bo_unref(&rdev->uvd.vcpu_bo); 172 radeon_bo_unref(&rdev->uvd.vcpu_bo);
173 173
174 radeon_ring_fini(rdev, &rdev->ring[R600_RING_TYPE_UVD_INDEX]);
175
174 release_firmware(rdev->uvd_fw); 176 release_firmware(rdev->uvd_fw);
175} 177}
176 178
diff --git a/drivers/gpu/drm/radeon/rs400.c b/drivers/gpu/drm/radeon/rs400.c
index b5c2369cda2f..130d5cc50d43 100644
--- a/drivers/gpu/drm/radeon/rs400.c
+++ b/drivers/gpu/drm/radeon/rs400.c
@@ -474,8 +474,6 @@ int rs400_resume(struct radeon_device *rdev)
474 /* Initialize surface registers */ 474 /* Initialize surface registers */
475 radeon_surface_init(rdev); 475 radeon_surface_init(rdev);
476 476
477 radeon_pm_resume(rdev);
478
479 rdev->accel_working = true; 477 rdev->accel_working = true;
480 r = rs400_startup(rdev); 478 r = rs400_startup(rdev);
481 if (r) { 479 if (r) {
diff --git a/drivers/gpu/drm/radeon/rs600.c b/drivers/gpu/drm/radeon/rs600.c
index fdcde7693032..72d3616de08e 100644
--- a/drivers/gpu/drm/radeon/rs600.c
+++ b/drivers/gpu/drm/radeon/rs600.c
@@ -1048,8 +1048,6 @@ int rs600_resume(struct radeon_device *rdev)
1048 /* Initialize surface registers */ 1048 /* Initialize surface registers */
1049 radeon_surface_init(rdev); 1049 radeon_surface_init(rdev);
1050 1050
1051 radeon_pm_resume(rdev);
1052
1053 rdev->accel_working = true; 1051 rdev->accel_working = true;
1054 r = rs600_startup(rdev); 1052 r = rs600_startup(rdev);
1055 if (r) { 1053 if (r) {
diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
index 35950738bd5e..3462b64369bf 100644
--- a/drivers/gpu/drm/radeon/rs690.c
+++ b/drivers/gpu/drm/radeon/rs690.c
@@ -756,8 +756,6 @@ int rs690_resume(struct radeon_device *rdev)
756 /* Initialize surface registers */ 756 /* Initialize surface registers */
757 radeon_surface_init(rdev); 757 radeon_surface_init(rdev);
758 758
759 radeon_pm_resume(rdev);
760
761 rdev->accel_working = true; 759 rdev->accel_working = true;
762 r = rs690_startup(rdev); 760 r = rs690_startup(rdev);
763 if (r) { 761 if (r) {
diff --git a/drivers/gpu/drm/radeon/rv515.c b/drivers/gpu/drm/radeon/rv515.c
index 98e8138ff779..237dd29d9f1c 100644
--- a/drivers/gpu/drm/radeon/rv515.c
+++ b/drivers/gpu/drm/radeon/rv515.c
@@ -586,8 +586,6 @@ int rv515_resume(struct radeon_device *rdev)
586 /* Initialize surface registers */ 586 /* Initialize surface registers */
587 radeon_surface_init(rdev); 587 radeon_surface_init(rdev);
588 588
589 radeon_pm_resume(rdev);
590
591 rdev->accel_working = true; 589 rdev->accel_working = true;
592 r = rv515_startup(rdev); 590 r = rv515_startup(rdev);
593 if (r) { 591 if (r) {
diff --git a/drivers/gpu/drm/radeon/rv770.c b/drivers/gpu/drm/radeon/rv770.c
index 6c772e58c784..fef310773aad 100644
--- a/drivers/gpu/drm/radeon/rv770.c
+++ b/drivers/gpu/drm/radeon/rv770.c
@@ -1811,7 +1811,8 @@ int rv770_resume(struct radeon_device *rdev)
1811 /* init golden registers */ 1811 /* init golden registers */
1812 rv770_init_golden_registers(rdev); 1812 rv770_init_golden_registers(rdev);
1813 1813
1814 radeon_pm_resume(rdev); 1814 if (rdev->pm.pm_method == PM_METHOD_DPM)
1815 radeon_pm_resume(rdev);
1815 1816
1816 rdev->accel_working = true; 1817 rdev->accel_working = true;
1817 r = rv770_startup(rdev); 1818 r = rv770_startup(rdev);
@@ -1955,9 +1956,9 @@ void rv770_fini(struct radeon_device *rdev)
1955 radeon_wb_fini(rdev); 1956 radeon_wb_fini(rdev);
1956 radeon_ib_pool_fini(rdev); 1957 radeon_ib_pool_fini(rdev);
1957 radeon_irq_kms_fini(rdev); 1958 radeon_irq_kms_fini(rdev);
1958 rv770_pcie_gart_fini(rdev);
1959 uvd_v1_0_fini(rdev); 1959 uvd_v1_0_fini(rdev);
1960 radeon_uvd_fini(rdev); 1960 radeon_uvd_fini(rdev);
1961 rv770_pcie_gart_fini(rdev);
1961 r600_vram_scratch_fini(rdev); 1962 r600_vram_scratch_fini(rdev);
1962 radeon_gem_fini(rdev); 1963 radeon_gem_fini(rdev);
1963 radeon_fence_driver_fini(rdev); 1964 radeon_fence_driver_fini(rdev);
diff --git a/drivers/gpu/drm/radeon/si.c b/drivers/gpu/drm/radeon/si.c
index 83578324e5d1..9a124d0608b3 100644
--- a/drivers/gpu/drm/radeon/si.c
+++ b/drivers/gpu/drm/radeon/si.c
@@ -6618,7 +6618,8 @@ int si_resume(struct radeon_device *rdev)
6618 /* init golden registers */ 6618 /* init golden registers */
6619 si_init_golden_registers(rdev); 6619 si_init_golden_registers(rdev);
6620 6620
6621 radeon_pm_resume(rdev); 6621 if (rdev->pm.pm_method == PM_METHOD_DPM)
6622 radeon_pm_resume(rdev);
6622 6623
6623 rdev->accel_working = true; 6624 rdev->accel_working = true;
6624 r = si_startup(rdev); 6625 r = si_startup(rdev);
diff --git a/drivers/gpu/drm/tegra/drm.c b/drivers/gpu/drm/tegra/drm.c
index 88a529008ce0..c71594754f46 100644
--- a/drivers/gpu/drm/tegra/drm.c
+++ b/drivers/gpu/drm/tegra/drm.c
@@ -104,7 +104,7 @@ static void tegra_drm_context_free(struct tegra_drm_context *context)
104 104
105static void tegra_drm_lastclose(struct drm_device *drm) 105static void tegra_drm_lastclose(struct drm_device *drm)
106{ 106{
107#ifdef CONFIG_TEGRA_DRM_FBDEV 107#ifdef CONFIG_DRM_TEGRA_FBDEV
108 struct tegra_drm *tegra = drm->dev_private; 108 struct tegra_drm *tegra = drm->dev_private;
109 109
110 tegra_fbdev_restore_mode(tegra->fbdev); 110 tegra_fbdev_restore_mode(tegra->fbdev);
diff --git a/drivers/gpu/drm/tegra/rgb.c b/drivers/gpu/drm/tegra/rgb.c
index 338f7f6561d7..0266fb40479e 100644
--- a/drivers/gpu/drm/tegra/rgb.c
+++ b/drivers/gpu/drm/tegra/rgb.c
@@ -15,6 +15,7 @@
15struct tegra_rgb { 15struct tegra_rgb {
16 struct tegra_output output; 16 struct tegra_output output;
17 struct tegra_dc *dc; 17 struct tegra_dc *dc;
18 bool enabled;
18 19
19 struct clk *clk_parent; 20 struct clk *clk_parent;
20 struct clk *clk; 21 struct clk *clk;
@@ -89,6 +90,9 @@ static int tegra_output_rgb_enable(struct tegra_output *output)
89 struct tegra_rgb *rgb = to_rgb(output); 90 struct tegra_rgb *rgb = to_rgb(output);
90 unsigned long value; 91 unsigned long value;
91 92
93 if (rgb->enabled)
94 return 0;
95
92 tegra_dc_write_regs(rgb->dc, rgb_enable, ARRAY_SIZE(rgb_enable)); 96 tegra_dc_write_regs(rgb->dc, rgb_enable, ARRAY_SIZE(rgb_enable));
93 97
94 value = DE_SELECT_ACTIVE | DE_CONTROL_NORMAL; 98 value = DE_SELECT_ACTIVE | DE_CONTROL_NORMAL;
@@ -122,6 +126,8 @@ static int tegra_output_rgb_enable(struct tegra_output *output)
122 tegra_dc_writel(rgb->dc, GENERAL_ACT_REQ << 8, DC_CMD_STATE_CONTROL); 126 tegra_dc_writel(rgb->dc, GENERAL_ACT_REQ << 8, DC_CMD_STATE_CONTROL);
123 tegra_dc_writel(rgb->dc, GENERAL_ACT_REQ, DC_CMD_STATE_CONTROL); 127 tegra_dc_writel(rgb->dc, GENERAL_ACT_REQ, DC_CMD_STATE_CONTROL);
124 128
129 rgb->enabled = true;
130
125 return 0; 131 return 0;
126} 132}
127 133
@@ -130,6 +136,9 @@ static int tegra_output_rgb_disable(struct tegra_output *output)
130 struct tegra_rgb *rgb = to_rgb(output); 136 struct tegra_rgb *rgb = to_rgb(output);
131 unsigned long value; 137 unsigned long value;
132 138
139 if (!rgb->enabled)
140 return 0;
141
133 value = tegra_dc_readl(rgb->dc, DC_CMD_DISPLAY_POWER_CONTROL); 142 value = tegra_dc_readl(rgb->dc, DC_CMD_DISPLAY_POWER_CONTROL);
134 value &= ~(PW0_ENABLE | PW1_ENABLE | PW2_ENABLE | PW3_ENABLE | 143 value &= ~(PW0_ENABLE | PW1_ENABLE | PW2_ENABLE | PW3_ENABLE |
135 PW4_ENABLE | PM0_ENABLE | PM1_ENABLE); 144 PW4_ENABLE | PM0_ENABLE | PM1_ENABLE);
@@ -144,6 +153,8 @@ static int tegra_output_rgb_disable(struct tegra_output *output)
144 153
145 tegra_dc_write_regs(rgb->dc, rgb_disable, ARRAY_SIZE(rgb_disable)); 154 tegra_dc_write_regs(rgb->dc, rgb_disable, ARRAY_SIZE(rgb_disable));
146 155
156 rgb->enabled = false;
157
147 return 0; 158 return 0;
148} 159}
149 160
diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index a06651309388..214b7992a3aa 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -351,9 +351,11 @@ static int ttm_bo_handle_move_mem(struct ttm_buffer_object *bo,
351 351
352moved: 352moved:
353 if (bo->evicted) { 353 if (bo->evicted) {
354 ret = bdev->driver->invalidate_caches(bdev, bo->mem.placement); 354 if (bdev->driver->invalidate_caches) {
355 if (ret) 355 ret = bdev->driver->invalidate_caches(bdev, bo->mem.placement);
356 pr_err("Can not flush read caches\n"); 356 if (ret)
357 pr_err("Can not flush read caches\n");
358 }
357 bo->evicted = false; 359 bo->evicted = false;
358 } 360 }
359 361
diff --git a/drivers/gpu/drm/ttm/ttm_bo_vm.c b/drivers/gpu/drm/ttm/ttm_bo_vm.c
index 801231c9ae48..0ce48e5a9cb4 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_vm.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_vm.c
@@ -339,11 +339,13 @@ int ttm_bo_mmap(struct file *filp, struct vm_area_struct *vma,
339 vma->vm_private_data = bo; 339 vma->vm_private_data = bo;
340 340
341 /* 341 /*
342 * PFNMAP is faster than MIXEDMAP due to reduced page 342 * We'd like to use VM_PFNMAP on shared mappings, where
343 * administration. So use MIXEDMAP only if private VMA, where 343 * (vma->vm_flags & VM_SHARED) != 0, for performance reasons,
344 * we need to support COW. 344 * but for some reason VM_PFNMAP + x86 PAT + write-combine is very
345 * bad for performance. Until that has been sorted out, use
346 * VM_MIXEDMAP on all mappings. See freedesktop.org bug #75719
345 */ 347 */
346 vma->vm_flags |= (vma->vm_flags & VM_SHARED) ? VM_PFNMAP : VM_MIXEDMAP; 348 vma->vm_flags |= VM_MIXEDMAP;
347 vma->vm_flags |= VM_IO | VM_DONTEXPAND | VM_DONTDUMP; 349 vma->vm_flags |= VM_IO | VM_DONTEXPAND | VM_DONTDUMP;
348 return 0; 350 return 0;
349out_unref: 351out_unref:
@@ -359,7 +361,7 @@ int ttm_fbdev_mmap(struct vm_area_struct *vma, struct ttm_buffer_object *bo)
359 361
360 vma->vm_ops = &ttm_bo_vm_ops; 362 vma->vm_ops = &ttm_bo_vm_ops;
361 vma->vm_private_data = ttm_bo_reference(bo); 363 vma->vm_private_data = ttm_bo_reference(bo);
362 vma->vm_flags |= (vma->vm_flags & VM_SHARED) ? VM_PFNMAP : VM_MIXEDMAP; 364 vma->vm_flags |= VM_MIXEDMAP;
363 vma->vm_flags |= VM_IO | VM_DONTEXPAND; 365 vma->vm_flags |= VM_IO | VM_DONTEXPAND;
364 return 0; 366 return 0;
365} 367}
diff --git a/drivers/gpu/drm/udl/udl_gem.c b/drivers/gpu/drm/udl/udl_gem.c
index 8d67b943ac05..0394811251bd 100644
--- a/drivers/gpu/drm/udl/udl_gem.c
+++ b/drivers/gpu/drm/udl/udl_gem.c
@@ -177,8 +177,10 @@ void udl_gem_free_object(struct drm_gem_object *gem_obj)
177 if (obj->vmapping) 177 if (obj->vmapping)
178 udl_gem_vunmap(obj); 178 udl_gem_vunmap(obj);
179 179
180 if (gem_obj->import_attach) 180 if (gem_obj->import_attach) {
181 drm_prime_gem_destroy(gem_obj, obj->sg); 181 drm_prime_gem_destroy(gem_obj, obj->sg);
182 put_device(gem_obj->dev->dev);
183 }
182 184
183 if (obj->pages) 185 if (obj->pages)
184 udl_gem_put_pages(obj); 186 udl_gem_put_pages(obj);
@@ -256,9 +258,12 @@ struct drm_gem_object *udl_gem_prime_import(struct drm_device *dev,
256 int ret; 258 int ret;
257 259
258 /* need to attach */ 260 /* need to attach */
261 get_device(dev->dev);
259 attach = dma_buf_attach(dma_buf, dev->dev); 262 attach = dma_buf_attach(dma_buf, dev->dev);
260 if (IS_ERR(attach)) 263 if (IS_ERR(attach)) {
264 put_device(dev->dev);
261 return ERR_CAST(attach); 265 return ERR_CAST(attach);
266 }
262 267
263 get_dma_buf(dma_buf); 268 get_dma_buf(dma_buf);
264 269
@@ -282,6 +287,6 @@ fail_unmap:
282fail_detach: 287fail_detach:
283 dma_buf_detach(dma_buf, attach); 288 dma_buf_detach(dma_buf, attach);
284 dma_buf_put(dma_buf); 289 dma_buf_put(dma_buf);
285 290 put_device(dev->dev);
286 return ERR_PTR(ret); 291 return ERR_PTR(ret);
287} 292}
diff --git a/drivers/gpu/drm/vmwgfx/svga3d_reg.h b/drivers/gpu/drm/vmwgfx/svga3d_reg.h
index bb594c11605e..f58dc7dd15c5 100644
--- a/drivers/gpu/drm/vmwgfx/svga3d_reg.h
+++ b/drivers/gpu/drm/vmwgfx/svga3d_reg.h
@@ -261,12 +261,7 @@ typedef enum SVGA3dSurfaceFormat {
261 /* Planar video formats. */ 261 /* Planar video formats. */
262 SVGA3D_YV12 = 121, 262 SVGA3D_YV12 = 121,
263 263
264 /* Shader constant formats. */ 264 SVGA3D_FORMAT_MAX = 122,
265 SVGA3D_SURFACE_SHADERCONST_FLOAT = 122,
266 SVGA3D_SURFACE_SHADERCONST_INT = 123,
267 SVGA3D_SURFACE_SHADERCONST_BOOL = 124,
268
269 SVGA3D_FORMAT_MAX = 125,
270} SVGA3dSurfaceFormat; 265} SVGA3dSurfaceFormat;
271 266
272typedef uint32 SVGA3dColor; /* a, r, g, b */ 267typedef uint32 SVGA3dColor; /* a, r, g, b */
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
index 9e4be1725985..07831554dad7 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
@@ -40,7 +40,7 @@
40#include <drm/ttm/ttm_module.h> 40#include <drm/ttm/ttm_module.h>
41#include "vmwgfx_fence.h" 41#include "vmwgfx_fence.h"
42 42
43#define VMWGFX_DRIVER_DATE "20121114" 43#define VMWGFX_DRIVER_DATE "20140228"
44#define VMWGFX_DRIVER_MAJOR 2 44#define VMWGFX_DRIVER_MAJOR 2
45#define VMWGFX_DRIVER_MINOR 5 45#define VMWGFX_DRIVER_MINOR 5
46#define VMWGFX_DRIVER_PATCHLEVEL 0 46#define VMWGFX_DRIVER_PATCHLEVEL 0
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_mob.c b/drivers/gpu/drm/vmwgfx/vmwgfx_mob.c
index d4a5a19cb8c3..04a64b8cd3cd 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_mob.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_mob.c
@@ -188,18 +188,20 @@ static void vmw_takedown_otable_base(struct vmw_private *dev_priv,
188 188
189 bo = otable->page_table->pt_bo; 189 bo = otable->page_table->pt_bo;
190 cmd = vmw_fifo_reserve(dev_priv, sizeof(*cmd)); 190 cmd = vmw_fifo_reserve(dev_priv, sizeof(*cmd));
191 if (unlikely(cmd == NULL)) 191 if (unlikely(cmd == NULL)) {
192 DRM_ERROR("Failed reserving FIFO space for OTable setup.\n"); 192 DRM_ERROR("Failed reserving FIFO space for OTable "
193 193 "takedown.\n");
194 memset(cmd, 0, sizeof(*cmd)); 194 } else {
195 cmd->header.id = SVGA_3D_CMD_SET_OTABLE_BASE; 195 memset(cmd, 0, sizeof(*cmd));
196 cmd->header.size = sizeof(cmd->body); 196 cmd->header.id = SVGA_3D_CMD_SET_OTABLE_BASE;
197 cmd->body.type = type; 197 cmd->header.size = sizeof(cmd->body);
198 cmd->body.baseAddress = 0; 198 cmd->body.type = type;
199 cmd->body.sizeInBytes = 0; 199 cmd->body.baseAddress = 0;
200 cmd->body.validSizeInBytes = 0; 200 cmd->body.sizeInBytes = 0;
201 cmd->body.ptDepth = SVGA3D_MOBFMT_INVALID; 201 cmd->body.validSizeInBytes = 0;
202 vmw_fifo_commit(dev_priv, sizeof(*cmd)); 202 cmd->body.ptDepth = SVGA3D_MOBFMT_INVALID;
203 vmw_fifo_commit(dev_priv, sizeof(*cmd));
204 }
203 205
204 if (bo) { 206 if (bo) {
205 int ret; 207 int ret;
@@ -562,11 +564,12 @@ void vmw_mob_unbind(struct vmw_private *dev_priv,
562 if (unlikely(cmd == NULL)) { 564 if (unlikely(cmd == NULL)) {
563 DRM_ERROR("Failed reserving FIFO space for Memory " 565 DRM_ERROR("Failed reserving FIFO space for Memory "
564 "Object unbinding.\n"); 566 "Object unbinding.\n");
567 } else {
568 cmd->header.id = SVGA_3D_CMD_DESTROY_GB_MOB;
569 cmd->header.size = sizeof(cmd->body);
570 cmd->body.mobid = mob->id;
571 vmw_fifo_commit(dev_priv, sizeof(*cmd));
565 } 572 }
566 cmd->header.id = SVGA_3D_CMD_DESTROY_GB_MOB;
567 cmd->header.size = sizeof(cmd->body);
568 cmd->body.mobid = mob->id;
569 vmw_fifo_commit(dev_priv, sizeof(*cmd));
570 if (bo) { 573 if (bo) {
571 vmw_fence_single_bo(bo, NULL); 574 vmw_fence_single_bo(bo, NULL);
572 ttm_bo_unreserve(bo); 575 ttm_bo_unreserve(bo);
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c b/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c
index 2aa4bc6a4d60..9757b57f8388 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c
@@ -427,8 +427,7 @@ int vmw_dmabuf_init(struct vmw_private *dev_priv,
427 INIT_LIST_HEAD(&vmw_bo->res_list); 427 INIT_LIST_HEAD(&vmw_bo->res_list);
428 428
429 ret = ttm_bo_init(bdev, &vmw_bo->base, size, 429 ret = ttm_bo_init(bdev, &vmw_bo->base, size,
430 (user) ? ttm_bo_type_device : 430 ttm_bo_type_device, placement,
431 ttm_bo_type_kernel, placement,
432 0, interruptible, 431 0, interruptible,
433 NULL, acc_size, NULL, bo_free); 432 NULL, acc_size, NULL, bo_free);
434 return ret; 433 return ret;
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c b/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c
index 82468d902915..e7af580ab977 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c
@@ -830,6 +830,24 @@ int vmw_surface_define_ioctl(struct drm_device *dev, void *data,
830 if (unlikely(ret != 0)) 830 if (unlikely(ret != 0))
831 goto out_unlock; 831 goto out_unlock;
832 832
833 /*
834 * A gb-aware client referencing a shared surface will
835 * expect a backup buffer to be present.
836 */
837 if (dev_priv->has_mob && req->shareable) {
838 uint32_t backup_handle;
839
840 ret = vmw_user_dmabuf_alloc(dev_priv, tfile,
841 res->backup_size,
842 true,
843 &backup_handle,
844 &res->backup);
845 if (unlikely(ret != 0)) {
846 vmw_resource_unreference(&res);
847 goto out_unlock;
848 }
849 }
850
833 tmp = vmw_resource_reference(&srf->res); 851 tmp = vmw_resource_reference(&srf->res);
834 ret = ttm_prime_object_init(tfile, res->backup_size, &user_srf->prime, 852 ret = ttm_prime_object_init(tfile, res->backup_size, &user_srf->prime,
835 req->shareable, VMW_RES_SURFACE, 853 req->shareable, VMW_RES_SURFACE,
diff --git a/drivers/gpu/host1x/job.c b/drivers/gpu/host1x/job.c
index 1146e3bba6e1..112f27e51bc7 100644
--- a/drivers/gpu/host1x/job.c
+++ b/drivers/gpu/host1x/job.c
@@ -538,7 +538,7 @@ int host1x_job_pin(struct host1x_job *job, struct device *dev)
538 538
539 g->base = job->gather_addr_phys[i]; 539 g->base = job->gather_addr_phys[i];
540 540
541 for (j = 0; j < job->num_gathers; j++) 541 for (j = i + 1; j < job->num_gathers; j++)
542 if (job->gathers[j].bo == g->bo) 542 if (job->gathers[j].bo == g->bo)
543 job->gathers[j].handled = true; 543 job->gathers[j].handled = true;
544 544
diff --git a/drivers/hid/hid-lg4ff.c b/drivers/hid/hid-lg4ff.c
index befe0e336471..24883b4d1a49 100644
--- a/drivers/hid/hid-lg4ff.c
+++ b/drivers/hid/hid-lg4ff.c
@@ -43,6 +43,7 @@
43#define G25_REV_MIN 0x22 43#define G25_REV_MIN 0x22
44#define G27_REV_MAJ 0x12 44#define G27_REV_MAJ 0x12
45#define G27_REV_MIN 0x38 45#define G27_REV_MIN 0x38
46#define G27_2_REV_MIN 0x39
46 47
47#define to_hid_device(pdev) container_of(pdev, struct hid_device, dev) 48#define to_hid_device(pdev) container_of(pdev, struct hid_device, dev)
48 49
@@ -130,6 +131,7 @@ static const struct lg4ff_usb_revision lg4ff_revs[] = {
130 {DFP_REV_MAJ, DFP_REV_MIN, &native_dfp}, /* Driving Force Pro */ 131 {DFP_REV_MAJ, DFP_REV_MIN, &native_dfp}, /* Driving Force Pro */
131 {G25_REV_MAJ, G25_REV_MIN, &native_g25}, /* G25 */ 132 {G25_REV_MAJ, G25_REV_MIN, &native_g25}, /* G25 */
132 {G27_REV_MAJ, G27_REV_MIN, &native_g27}, /* G27 */ 133 {G27_REV_MAJ, G27_REV_MIN, &native_g27}, /* G27 */
134 {G27_REV_MAJ, G27_2_REV_MIN, &native_g27}, /* G27 v2 */
133}; 135};
134 136
135/* Recalculates X axis value accordingly to currently selected range */ 137/* Recalculates X axis value accordingly to currently selected range */
diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c
index 12354055d474..2f19b15f47f2 100644
--- a/drivers/hid/hid-sony.c
+++ b/drivers/hid/hid-sony.c
@@ -42,6 +42,7 @@
42#define DUALSHOCK4_CONTROLLER_BT BIT(6) 42#define DUALSHOCK4_CONTROLLER_BT BIT(6)
43 43
44#define SONY_LED_SUPPORT (SIXAXIS_CONTROLLER_USB | BUZZ_CONTROLLER | DUALSHOCK4_CONTROLLER_USB) 44#define SONY_LED_SUPPORT (SIXAXIS_CONTROLLER_USB | BUZZ_CONTROLLER | DUALSHOCK4_CONTROLLER_USB)
45#define SONY_FF_SUPPORT (SIXAXIS_CONTROLLER_USB | DUALSHOCK4_CONTROLLER_USB)
45 46
46#define MAX_LEDS 4 47#define MAX_LEDS 4
47 48
@@ -499,6 +500,7 @@ struct sony_sc {
499 __u8 right; 500 __u8 right;
500#endif 501#endif
501 502
503 __u8 worker_initialized;
502 __u8 led_state[MAX_LEDS]; 504 __u8 led_state[MAX_LEDS];
503 __u8 led_count; 505 __u8 led_count;
504}; 506};
@@ -993,22 +995,11 @@ static int sony_init_ff(struct hid_device *hdev)
993 return input_ff_create_memless(input_dev, NULL, sony_play_effect); 995 return input_ff_create_memless(input_dev, NULL, sony_play_effect);
994} 996}
995 997
996static void sony_destroy_ff(struct hid_device *hdev)
997{
998 struct sony_sc *sc = hid_get_drvdata(hdev);
999
1000 cancel_work_sync(&sc->state_worker);
1001}
1002
1003#else 998#else
1004static int sony_init_ff(struct hid_device *hdev) 999static int sony_init_ff(struct hid_device *hdev)
1005{ 1000{
1006 return 0; 1001 return 0;
1007} 1002}
1008
1009static void sony_destroy_ff(struct hid_device *hdev)
1010{
1011}
1012#endif 1003#endif
1013 1004
1014static int sony_set_output_report(struct sony_sc *sc, int req_id, int req_size) 1005static int sony_set_output_report(struct sony_sc *sc, int req_id, int req_size)
@@ -1077,6 +1068,8 @@ static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id)
1077 if (sc->quirks & SIXAXIS_CONTROLLER_USB) { 1068 if (sc->quirks & SIXAXIS_CONTROLLER_USB) {
1078 hdev->hid_output_raw_report = sixaxis_usb_output_raw_report; 1069 hdev->hid_output_raw_report = sixaxis_usb_output_raw_report;
1079 ret = sixaxis_set_operational_usb(hdev); 1070 ret = sixaxis_set_operational_usb(hdev);
1071
1072 sc->worker_initialized = 1;
1080 INIT_WORK(&sc->state_worker, sixaxis_state_worker); 1073 INIT_WORK(&sc->state_worker, sixaxis_state_worker);
1081 } 1074 }
1082 else if (sc->quirks & SIXAXIS_CONTROLLER_BT) 1075 else if (sc->quirks & SIXAXIS_CONTROLLER_BT)
@@ -1087,6 +1080,7 @@ static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id)
1087 if (ret < 0) 1080 if (ret < 0)
1088 goto err_stop; 1081 goto err_stop;
1089 1082
1083 sc->worker_initialized = 1;
1090 INIT_WORK(&sc->state_worker, dualshock4_state_worker); 1084 INIT_WORK(&sc->state_worker, dualshock4_state_worker);
1091 } else { 1085 } else {
1092 ret = 0; 1086 ret = 0;
@@ -1101,9 +1095,11 @@ static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id)
1101 goto err_stop; 1095 goto err_stop;
1102 } 1096 }
1103 1097
1104 ret = sony_init_ff(hdev); 1098 if (sc->quirks & SONY_FF_SUPPORT) {
1105 if (ret < 0) 1099 ret = sony_init_ff(hdev);
1106 goto err_stop; 1100 if (ret < 0)
1101 goto err_stop;
1102 }
1107 1103
1108 return 0; 1104 return 0;
1109err_stop: 1105err_stop:
@@ -1120,7 +1116,8 @@ static void sony_remove(struct hid_device *hdev)
1120 if (sc->quirks & SONY_LED_SUPPORT) 1116 if (sc->quirks & SONY_LED_SUPPORT)
1121 sony_leds_remove(hdev); 1117 sony_leds_remove(hdev);
1122 1118
1123 sony_destroy_ff(hdev); 1119 if (sc->worker_initialized)
1120 cancel_work_sync(&sc->state_worker);
1124 1121
1125 hid_hw_stop(hdev); 1122 hid_hw_stop(hdev);
1126} 1123}
diff --git a/drivers/hid/hidraw.c b/drivers/hid/hidraw.c
index cb0137b3718d..ab24ce2eb28f 100644
--- a/drivers/hid/hidraw.c
+++ b/drivers/hid/hidraw.c
@@ -320,13 +320,13 @@ static void drop_ref(struct hidraw *hidraw, int exists_bit)
320 hid_hw_close(hidraw->hid); 320 hid_hw_close(hidraw->hid);
321 wake_up_interruptible(&hidraw->wait); 321 wake_up_interruptible(&hidraw->wait);
322 } 322 }
323 device_destroy(hidraw_class,
324 MKDEV(hidraw_major, hidraw->minor));
323 } else { 325 } else {
324 --hidraw->open; 326 --hidraw->open;
325 } 327 }
326 if (!hidraw->open) { 328 if (!hidraw->open) {
327 if (!hidraw->exist) { 329 if (!hidraw->exist) {
328 device_destroy(hidraw_class,
329 MKDEV(hidraw_major, hidraw->minor));
330 hidraw_table[hidraw->minor] = NULL; 330 hidraw_table[hidraw->minor] = NULL;
331 kfree(hidraw); 331 kfree(hidraw);
332 } else { 332 } else {
diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
index 077bb1bdac34..3f0a95290e14 100644
--- a/drivers/hv/vmbus_drv.c
+++ b/drivers/hv/vmbus_drv.c
@@ -25,7 +25,6 @@
25#include <linux/init.h> 25#include <linux/init.h>
26#include <linux/module.h> 26#include <linux/module.h>
27#include <linux/device.h> 27#include <linux/device.h>
28#include <linux/irq.h>
29#include <linux/interrupt.h> 28#include <linux/interrupt.h>
30#include <linux/sysctl.h> 29#include <linux/sysctl.h>
31#include <linux/slab.h> 30#include <linux/slab.h>
@@ -558,9 +557,6 @@ static struct bus_type hv_bus = {
558 .dev_groups = vmbus_groups, 557 .dev_groups = vmbus_groups,
559}; 558};
560 559
561static const char *driver_name = "hyperv";
562
563
564struct onmessage_work_context { 560struct onmessage_work_context {
565 struct work_struct work; 561 struct work_struct work;
566 struct hv_message msg; 562 struct hv_message msg;
@@ -619,7 +615,7 @@ static void vmbus_on_msg_dpc(unsigned long data)
619 } 615 }
620} 616}
621 617
622static irqreturn_t vmbus_isr(int irq, void *dev_id) 618static void vmbus_isr(void)
623{ 619{
624 int cpu = smp_processor_id(); 620 int cpu = smp_processor_id();
625 void *page_addr; 621 void *page_addr;
@@ -629,7 +625,7 @@ static irqreturn_t vmbus_isr(int irq, void *dev_id)
629 625
630 page_addr = hv_context.synic_event_page[cpu]; 626 page_addr = hv_context.synic_event_page[cpu];
631 if (page_addr == NULL) 627 if (page_addr == NULL)
632 return IRQ_NONE; 628 return;
633 629
634 event = (union hv_synic_event_flags *)page_addr + 630 event = (union hv_synic_event_flags *)page_addr +
635 VMBUS_MESSAGE_SINT; 631 VMBUS_MESSAGE_SINT;
@@ -665,28 +661,8 @@ static irqreturn_t vmbus_isr(int irq, void *dev_id)
665 msg = (struct hv_message *)page_addr + VMBUS_MESSAGE_SINT; 661 msg = (struct hv_message *)page_addr + VMBUS_MESSAGE_SINT;
666 662
667 /* Check if there are actual msgs to be processed */ 663 /* Check if there are actual msgs to be processed */
668 if (msg->header.message_type != HVMSG_NONE) { 664 if (msg->header.message_type != HVMSG_NONE)
669 handled = true;
670 tasklet_schedule(&msg_dpc); 665 tasklet_schedule(&msg_dpc);
671 }
672
673 if (handled)
674 return IRQ_HANDLED;
675 else
676 return IRQ_NONE;
677}
678
679/*
680 * vmbus interrupt flow handler:
681 * vmbus interrupts can concurrently occur on multiple CPUs and
682 * can be handled concurrently.
683 */
684
685static void vmbus_flow_handler(unsigned int irq, struct irq_desc *desc)
686{
687 kstat_incr_irqs_this_cpu(irq, desc);
688
689 desc->action->handler(irq, desc->action->dev_id);
690} 666}
691 667
692/* 668/*
@@ -715,25 +691,7 @@ static int vmbus_bus_init(int irq)
715 if (ret) 691 if (ret)
716 goto err_cleanup; 692 goto err_cleanup;
717 693
718 ret = request_irq(irq, vmbus_isr, 0, driver_name, hv_acpi_dev); 694 hv_setup_vmbus_irq(vmbus_isr);
719
720 if (ret != 0) {
721 pr_err("Unable to request IRQ %d\n",
722 irq);
723 goto err_unregister;
724 }
725
726 /*
727 * Vmbus interrupts can be handled concurrently on
728 * different CPUs. Establish an appropriate interrupt flow
729 * handler that can support this model.
730 */
731 irq_set_handler(irq, vmbus_flow_handler);
732
733 /*
734 * Register our interrupt handler.
735 */
736 hv_register_vmbus_handler(irq, vmbus_isr);
737 695
738 ret = hv_synic_alloc(); 696 ret = hv_synic_alloc();
739 if (ret) 697 if (ret)
@@ -753,9 +711,8 @@ static int vmbus_bus_init(int irq)
753 711
754err_alloc: 712err_alloc:
755 hv_synic_free(); 713 hv_synic_free();
756 free_irq(irq, hv_acpi_dev); 714 hv_remove_vmbus_irq();
757 715
758err_unregister:
759 bus_unregister(&hv_bus); 716 bus_unregister(&hv_bus);
760 717
761err_cleanup: 718err_cleanup:
@@ -947,7 +904,6 @@ static int __init hv_acpi_init(void)
947 /* 904 /*
948 * Get irq resources first. 905 * Get irq resources first.
949 */ 906 */
950
951 ret = acpi_bus_register_driver(&vmbus_acpi_driver); 907 ret = acpi_bus_register_driver(&vmbus_acpi_driver);
952 908
953 if (ret) 909 if (ret)
@@ -978,8 +934,7 @@ cleanup:
978 934
979static void __exit vmbus_exit(void) 935static void __exit vmbus_exit(void)
980{ 936{
981 937 hv_remove_vmbus_irq();
982 free_irq(irq, hv_acpi_dev);
983 vmbus_free_channels(); 938 vmbus_free_channels();
984 bus_unregister(&hv_bus); 939 bus_unregister(&hv_bus);
985 hv_cleanup(); 940 hv_cleanup();
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index f5ed03164d86..de17c5593d97 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -387,7 +387,7 @@ config I2C_CBUS_GPIO
387 387
388config I2C_CPM 388config I2C_CPM
389 tristate "Freescale CPM1 or CPM2 (MPC8xx/826x)" 389 tristate "Freescale CPM1 or CPM2 (MPC8xx/826x)"
390 depends on (CPM1 || CPM2) && OF_I2C 390 depends on CPM1 || CPM2
391 help 391 help
392 This supports the use of the I2C interface on Freescale 392 This supports the use of the I2C interface on Freescale
393 processors with CPM1 or CPM2. 393 processors with CPM1 or CPM2.
diff --git a/drivers/i2c/busses/i2c-cpm.c b/drivers/i2c/busses/i2c-cpm.c
index be7f0a20d634..f3b89a4698b6 100644
--- a/drivers/i2c/busses/i2c-cpm.c
+++ b/drivers/i2c/busses/i2c-cpm.c
@@ -39,7 +39,9 @@
39#include <linux/i2c.h> 39#include <linux/i2c.h>
40#include <linux/io.h> 40#include <linux/io.h>
41#include <linux/dma-mapping.h> 41#include <linux/dma-mapping.h>
42#include <linux/of_address.h>
42#include <linux/of_device.h> 43#include <linux/of_device.h>
44#include <linux/of_irq.h>
43#include <linux/of_platform.h> 45#include <linux/of_platform.h>
44#include <sysdev/fsl_soc.h> 46#include <sysdev/fsl_soc.h>
45#include <asm/cpm.h> 47#include <asm/cpm.h>
diff --git a/drivers/iio/gyro/Kconfig b/drivers/iio/gyro/Kconfig
index 41c64a43bcab..ac2d69e34c8c 100644
--- a/drivers/iio/gyro/Kconfig
+++ b/drivers/iio/gyro/Kconfig
@@ -70,7 +70,7 @@ config IIO_ST_GYRO_3AXIS
70 select IIO_TRIGGERED_BUFFER if (IIO_BUFFER) 70 select IIO_TRIGGERED_BUFFER if (IIO_BUFFER)
71 help 71 help
72 Say yes here to build support for STMicroelectronics gyroscopes: 72 Say yes here to build support for STMicroelectronics gyroscopes:
73 L3G4200D, LSM330DL, L3GD20, L3GD20H, LSM330DLC, L3G4IS, LSM330. 73 L3G4200D, LSM330DL, L3GD20, LSM330DLC, L3G4IS, LSM330.
74 74
75 This driver can also be built as a module. If so, these modules 75 This driver can also be built as a module. If so, these modules
76 will be created: 76 will be created:
diff --git a/drivers/iio/gyro/st_gyro.h b/drivers/iio/gyro/st_gyro.h
index f8f2bf84a5a2..c197360c450b 100644
--- a/drivers/iio/gyro/st_gyro.h
+++ b/drivers/iio/gyro/st_gyro.h
@@ -19,7 +19,6 @@
19#define LSM330DL_GYRO_DEV_NAME "lsm330dl_gyro" 19#define LSM330DL_GYRO_DEV_NAME "lsm330dl_gyro"
20#define LSM330DLC_GYRO_DEV_NAME "lsm330dlc_gyro" 20#define LSM330DLC_GYRO_DEV_NAME "lsm330dlc_gyro"
21#define L3GD20_GYRO_DEV_NAME "l3gd20" 21#define L3GD20_GYRO_DEV_NAME "l3gd20"
22#define L3GD20H_GYRO_DEV_NAME "l3gd20h"
23#define L3G4IS_GYRO_DEV_NAME "l3g4is_ui" 22#define L3G4IS_GYRO_DEV_NAME "l3g4is_ui"
24#define LSM330_GYRO_DEV_NAME "lsm330_gyro" 23#define LSM330_GYRO_DEV_NAME "lsm330_gyro"
25 24
diff --git a/drivers/iio/gyro/st_gyro_core.c b/drivers/iio/gyro/st_gyro_core.c
index d53d91adfb55..a8e174a47bc4 100644
--- a/drivers/iio/gyro/st_gyro_core.c
+++ b/drivers/iio/gyro/st_gyro_core.c
@@ -167,11 +167,10 @@ static const struct st_sensors st_gyro_sensors[] = {
167 .wai = ST_GYRO_2_WAI_EXP, 167 .wai = ST_GYRO_2_WAI_EXP,
168 .sensors_supported = { 168 .sensors_supported = {
169 [0] = L3GD20_GYRO_DEV_NAME, 169 [0] = L3GD20_GYRO_DEV_NAME,
170 [1] = L3GD20H_GYRO_DEV_NAME, 170 [1] = LSM330D_GYRO_DEV_NAME,
171 [2] = LSM330D_GYRO_DEV_NAME, 171 [2] = LSM330DLC_GYRO_DEV_NAME,
172 [3] = LSM330DLC_GYRO_DEV_NAME, 172 [3] = L3G4IS_GYRO_DEV_NAME,
173 [4] = L3G4IS_GYRO_DEV_NAME, 173 [4] = LSM330_GYRO_DEV_NAME,
174 [5] = LSM330_GYRO_DEV_NAME,
175 }, 174 },
176 .ch = (struct iio_chan_spec *)st_gyro_16bit_channels, 175 .ch = (struct iio_chan_spec *)st_gyro_16bit_channels,
177 .odr = { 176 .odr = {
diff --git a/drivers/iio/gyro/st_gyro_i2c.c b/drivers/iio/gyro/st_gyro_i2c.c
index 16b8b8d70bf1..23c12f361b05 100644
--- a/drivers/iio/gyro/st_gyro_i2c.c
+++ b/drivers/iio/gyro/st_gyro_i2c.c
@@ -55,7 +55,6 @@ static const struct i2c_device_id st_gyro_id_table[] = {
55 { LSM330DL_GYRO_DEV_NAME }, 55 { LSM330DL_GYRO_DEV_NAME },
56 { LSM330DLC_GYRO_DEV_NAME }, 56 { LSM330DLC_GYRO_DEV_NAME },
57 { L3GD20_GYRO_DEV_NAME }, 57 { L3GD20_GYRO_DEV_NAME },
58 { L3GD20H_GYRO_DEV_NAME },
59 { L3G4IS_GYRO_DEV_NAME }, 58 { L3G4IS_GYRO_DEV_NAME },
60 { LSM330_GYRO_DEV_NAME }, 59 { LSM330_GYRO_DEV_NAME },
61 {}, 60 {},
diff --git a/drivers/iio/gyro/st_gyro_spi.c b/drivers/iio/gyro/st_gyro_spi.c
index 94763e25caf9..b4ad3be26687 100644
--- a/drivers/iio/gyro/st_gyro_spi.c
+++ b/drivers/iio/gyro/st_gyro_spi.c
@@ -54,7 +54,6 @@ static const struct spi_device_id st_gyro_id_table[] = {
54 { LSM330DL_GYRO_DEV_NAME }, 54 { LSM330DL_GYRO_DEV_NAME },
55 { LSM330DLC_GYRO_DEV_NAME }, 55 { LSM330DLC_GYRO_DEV_NAME },
56 { L3GD20_GYRO_DEV_NAME }, 56 { L3GD20_GYRO_DEV_NAME },
57 { L3GD20H_GYRO_DEV_NAME },
58 { L3G4IS_GYRO_DEV_NAME }, 57 { L3G4IS_GYRO_DEV_NAME },
59 { LSM330_GYRO_DEV_NAME }, 58 { LSM330_GYRO_DEV_NAME },
60 {}, 59 {},
diff --git a/drivers/iio/light/cm32181.c b/drivers/iio/light/cm32181.c
index f17b4e6183c6..47a6dbac2d0c 100644
--- a/drivers/iio/light/cm32181.c
+++ b/drivers/iio/light/cm32181.c
@@ -103,13 +103,13 @@ static int cm32181_reg_init(struct cm32181_chip *cm32181)
103/** 103/**
104 * cm32181_read_als_it() - Get sensor integration time (ms) 104 * cm32181_read_als_it() - Get sensor integration time (ms)
105 * @cm32181: pointer of struct cm32181 105 * @cm32181: pointer of struct cm32181
106 * @val: pointer of int to load the als_it value. 106 * @val2: pointer of int to load the als_it value.
107 * 107 *
108 * Report the current integartion time by millisecond. 108 * Report the current integartion time by millisecond.
109 * 109 *
110 * Return: IIO_VAL_INT for success, otherwise -EINVAL. 110 * Return: IIO_VAL_INT_PLUS_MICRO for success, otherwise -EINVAL.
111 */ 111 */
112static int cm32181_read_als_it(struct cm32181_chip *cm32181, int *val) 112static int cm32181_read_als_it(struct cm32181_chip *cm32181, int *val2)
113{ 113{
114 u16 als_it; 114 u16 als_it;
115 int i; 115 int i;
@@ -119,8 +119,8 @@ static int cm32181_read_als_it(struct cm32181_chip *cm32181, int *val)
119 als_it >>= CM32181_CMD_ALS_IT_SHIFT; 119 als_it >>= CM32181_CMD_ALS_IT_SHIFT;
120 for (i = 0; i < ARRAY_SIZE(als_it_bits); i++) { 120 for (i = 0; i < ARRAY_SIZE(als_it_bits); i++) {
121 if (als_it == als_it_bits[i]) { 121 if (als_it == als_it_bits[i]) {
122 *val = als_it_value[i]; 122 *val2 = als_it_value[i];
123 return IIO_VAL_INT; 123 return IIO_VAL_INT_PLUS_MICRO;
124 } 124 }
125 } 125 }
126 126
@@ -221,7 +221,7 @@ static int cm32181_read_raw(struct iio_dev *indio_dev,
221 *val = cm32181->calibscale; 221 *val = cm32181->calibscale;
222 return IIO_VAL_INT; 222 return IIO_VAL_INT;
223 case IIO_CHAN_INFO_INT_TIME: 223 case IIO_CHAN_INFO_INT_TIME:
224 ret = cm32181_read_als_it(cm32181, val); 224 ret = cm32181_read_als_it(cm32181, val2);
225 return ret; 225 return ret;
226 } 226 }
227 227
@@ -240,7 +240,7 @@ static int cm32181_write_raw(struct iio_dev *indio_dev,
240 cm32181->calibscale = val; 240 cm32181->calibscale = val;
241 return val; 241 return val;
242 case IIO_CHAN_INFO_INT_TIME: 242 case IIO_CHAN_INFO_INT_TIME:
243 ret = cm32181_write_als_it(cm32181, val); 243 ret = cm32181_write_als_it(cm32181, val2);
244 return ret; 244 return ret;
245 } 245 }
246 246
@@ -264,7 +264,7 @@ static ssize_t cm32181_get_it_available(struct device *dev,
264 264
265 n = ARRAY_SIZE(als_it_value); 265 n = ARRAY_SIZE(als_it_value);
266 for (i = 0, len = 0; i < n; i++) 266 for (i = 0, len = 0; i < n; i++)
267 len += sprintf(buf + len, "%d ", als_it_value[i]); 267 len += sprintf(buf + len, "0.%06u ", als_it_value[i]);
268 return len + sprintf(buf + len, "\n"); 268 return len + sprintf(buf + len, "\n");
269} 269}
270 270
diff --git a/drivers/iio/light/cm36651.c b/drivers/iio/light/cm36651.c
index 0a142af83e25..a45e07492db3 100644
--- a/drivers/iio/light/cm36651.c
+++ b/drivers/iio/light/cm36651.c
@@ -50,10 +50,10 @@
50#define CM36651_CS_CONF2_DEFAULT_BIT 0x08 50#define CM36651_CS_CONF2_DEFAULT_BIT 0x08
51 51
52/* CS_CONF3 channel integration time */ 52/* CS_CONF3 channel integration time */
53#define CM36651_CS_IT1 0x00 /* Integration time 80000 usec */ 53#define CM36651_CS_IT1 0x00 /* Integration time 80 msec */
54#define CM36651_CS_IT2 0x40 /* Integration time 160000 usec */ 54#define CM36651_CS_IT2 0x40 /* Integration time 160 msec */
55#define CM36651_CS_IT3 0x80 /* Integration time 320000 usec */ 55#define CM36651_CS_IT3 0x80 /* Integration time 320 msec */
56#define CM36651_CS_IT4 0xC0 /* Integration time 640000 usec */ 56#define CM36651_CS_IT4 0xC0 /* Integration time 640 msec */
57 57
58/* PS_CONF1 command code */ 58/* PS_CONF1 command code */
59#define CM36651_PS_ENABLE 0x00 59#define CM36651_PS_ENABLE 0x00
@@ -64,10 +64,10 @@
64#define CM36651_PS_PERS4 0x0C 64#define CM36651_PS_PERS4 0x0C
65 65
66/* PS_CONF1 command code: integration time */ 66/* PS_CONF1 command code: integration time */
67#define CM36651_PS_IT1 0x00 /* Integration time 320 usec */ 67#define CM36651_PS_IT1 0x00 /* Integration time 0.32 msec */
68#define CM36651_PS_IT2 0x10 /* Integration time 420 usec */ 68#define CM36651_PS_IT2 0x10 /* Integration time 0.42 msec */
69#define CM36651_PS_IT3 0x20 /* Integration time 520 usec */ 69#define CM36651_PS_IT3 0x20 /* Integration time 0.52 msec */
70#define CM36651_PS_IT4 0x30 /* Integration time 640 usec */ 70#define CM36651_PS_IT4 0x30 /* Integration time 0.64 msec */
71 71
72/* PS_CONF1 command code: duty ratio */ 72/* PS_CONF1 command code: duty ratio */
73#define CM36651_PS_DR1 0x00 /* Duty ratio 1/80 */ 73#define CM36651_PS_DR1 0x00 /* Duty ratio 1/80 */
@@ -93,8 +93,8 @@
93#define CM36651_CLOSE_PROXIMITY 0x32 93#define CM36651_CLOSE_PROXIMITY 0x32
94#define CM36651_FAR_PROXIMITY 0x33 94#define CM36651_FAR_PROXIMITY 0x33
95 95
96#define CM36651_CS_INT_TIME_AVAIL "80000 160000 320000 640000" 96#define CM36651_CS_INT_TIME_AVAIL "0.08 0.16 0.32 0.64"
97#define CM36651_PS_INT_TIME_AVAIL "320 420 520 640" 97#define CM36651_PS_INT_TIME_AVAIL "0.000320 0.000420 0.000520 0.000640"
98 98
99enum cm36651_operation_mode { 99enum cm36651_operation_mode {
100 CM36651_LIGHT_EN, 100 CM36651_LIGHT_EN,
@@ -356,30 +356,30 @@ static int cm36651_read_channel(struct cm36651_data *cm36651,
356} 356}
357 357
358static int cm36651_read_int_time(struct cm36651_data *cm36651, 358static int cm36651_read_int_time(struct cm36651_data *cm36651,
359 struct iio_chan_spec const *chan, int *val) 359 struct iio_chan_spec const *chan, int *val2)
360{ 360{
361 switch (chan->type) { 361 switch (chan->type) {
362 case IIO_LIGHT: 362 case IIO_LIGHT:
363 if (cm36651->cs_int_time[chan->address] == CM36651_CS_IT1) 363 if (cm36651->cs_int_time[chan->address] == CM36651_CS_IT1)
364 *val = 80000; 364 *val2 = 80000;
365 else if (cm36651->cs_int_time[chan->address] == CM36651_CS_IT2) 365 else if (cm36651->cs_int_time[chan->address] == CM36651_CS_IT2)
366 *val = 160000; 366 *val2 = 160000;
367 else if (cm36651->cs_int_time[chan->address] == CM36651_CS_IT3) 367 else if (cm36651->cs_int_time[chan->address] == CM36651_CS_IT3)
368 *val = 320000; 368 *val2 = 320000;
369 else if (cm36651->cs_int_time[chan->address] == CM36651_CS_IT4) 369 else if (cm36651->cs_int_time[chan->address] == CM36651_CS_IT4)
370 *val = 640000; 370 *val2 = 640000;
371 else 371 else
372 return -EINVAL; 372 return -EINVAL;
373 break; 373 break;
374 case IIO_PROXIMITY: 374 case IIO_PROXIMITY:
375 if (cm36651->ps_int_time == CM36651_PS_IT1) 375 if (cm36651->ps_int_time == CM36651_PS_IT1)
376 *val = 320; 376 *val2 = 320;
377 else if (cm36651->ps_int_time == CM36651_PS_IT2) 377 else if (cm36651->ps_int_time == CM36651_PS_IT2)
378 *val = 420; 378 *val2 = 420;
379 else if (cm36651->ps_int_time == CM36651_PS_IT3) 379 else if (cm36651->ps_int_time == CM36651_PS_IT3)
380 *val = 520; 380 *val2 = 520;
381 else if (cm36651->ps_int_time == CM36651_PS_IT4) 381 else if (cm36651->ps_int_time == CM36651_PS_IT4)
382 *val = 640; 382 *val2 = 640;
383 else 383 else
384 return -EINVAL; 384 return -EINVAL;
385 break; 385 break;
@@ -387,7 +387,7 @@ static int cm36651_read_int_time(struct cm36651_data *cm36651,
387 return -EINVAL; 387 return -EINVAL;
388 } 388 }
389 389
390 return IIO_VAL_INT; 390 return IIO_VAL_INT_PLUS_MICRO;
391} 391}
392 392
393static int cm36651_write_int_time(struct cm36651_data *cm36651, 393static int cm36651_write_int_time(struct cm36651_data *cm36651,
@@ -459,7 +459,8 @@ static int cm36651_read_raw(struct iio_dev *indio_dev,
459 ret = cm36651_read_channel(cm36651, chan, val); 459 ret = cm36651_read_channel(cm36651, chan, val);
460 break; 460 break;
461 case IIO_CHAN_INFO_INT_TIME: 461 case IIO_CHAN_INFO_INT_TIME:
462 ret = cm36651_read_int_time(cm36651, chan, val); 462 *val = 0;
463 ret = cm36651_read_int_time(cm36651, chan, val2);
463 break; 464 break;
464 default: 465 default:
465 ret = -EINVAL; 466 ret = -EINVAL;
@@ -479,7 +480,7 @@ static int cm36651_write_raw(struct iio_dev *indio_dev,
479 int ret = -EINVAL; 480 int ret = -EINVAL;
480 481
481 if (mask == IIO_CHAN_INFO_INT_TIME) { 482 if (mask == IIO_CHAN_INFO_INT_TIME) {
482 ret = cm36651_write_int_time(cm36651, chan, val); 483 ret = cm36651_write_int_time(cm36651, chan, val2);
483 if (ret < 0) 484 if (ret < 0)
484 dev_err(&client->dev, "Integration time write failed\n"); 485 dev_err(&client->dev, "Integration time write failed\n");
485 } 486 }
diff --git a/drivers/infiniband/hw/mlx4/main.c b/drivers/infiniband/hw/mlx4/main.c
index e81c5547e647..f9c12e92fdd6 100644
--- a/drivers/infiniband/hw/mlx4/main.c
+++ b/drivers/infiniband/hw/mlx4/main.c
@@ -53,8 +53,8 @@
53#include "user.h" 53#include "user.h"
54 54
55#define DRV_NAME MLX4_IB_DRV_NAME 55#define DRV_NAME MLX4_IB_DRV_NAME
56#define DRV_VERSION "1.0" 56#define DRV_VERSION "2.2-1"
57#define DRV_RELDATE "April 4, 2008" 57#define DRV_RELDATE "Feb 2014"
58 58
59#define MLX4_IB_FLOW_MAX_PRIO 0xFFF 59#define MLX4_IB_FLOW_MAX_PRIO 0xFFF
60#define MLX4_IB_FLOW_QPN_MASK 0xFFFFFF 60#define MLX4_IB_FLOW_QPN_MASK 0xFFFFFF
diff --git a/drivers/infiniband/hw/mlx5/main.c b/drivers/infiniband/hw/mlx5/main.c
index aa03e732b6a8..bf900579ac08 100644
--- a/drivers/infiniband/hw/mlx5/main.c
+++ b/drivers/infiniband/hw/mlx5/main.c
@@ -46,8 +46,8 @@
46#include "mlx5_ib.h" 46#include "mlx5_ib.h"
47 47
48#define DRIVER_NAME "mlx5_ib" 48#define DRIVER_NAME "mlx5_ib"
49#define DRIVER_VERSION "1.0" 49#define DRIVER_VERSION "2.2-1"
50#define DRIVER_RELDATE "June 2013" 50#define DRIVER_RELDATE "Feb 2014"
51 51
52MODULE_AUTHOR("Eli Cohen <eli@mellanox.com>"); 52MODULE_AUTHOR("Eli Cohen <eli@mellanox.com>");
53MODULE_DESCRIPTION("Mellanox Connect-IB HCA IB driver"); 53MODULE_DESCRIPTION("Mellanox Connect-IB HCA IB driver");
diff --git a/drivers/infiniband/ulp/isert/ib_isert.c b/drivers/infiniband/ulp/isert/ib_isert.c
index d18d08a076e8..8ee228e9ab5a 100644
--- a/drivers/infiniband/ulp/isert/ib_isert.c
+++ b/drivers/infiniband/ulp/isert/ib_isert.c
@@ -492,12 +492,11 @@ isert_connect_request(struct rdma_cm_id *cma_id, struct rdma_cm_event *event)
492 isert_conn->state = ISER_CONN_INIT; 492 isert_conn->state = ISER_CONN_INIT;
493 INIT_LIST_HEAD(&isert_conn->conn_accept_node); 493 INIT_LIST_HEAD(&isert_conn->conn_accept_node);
494 init_completion(&isert_conn->conn_login_comp); 494 init_completion(&isert_conn->conn_login_comp);
495 init_waitqueue_head(&isert_conn->conn_wait); 495 init_completion(&isert_conn->conn_wait);
496 init_waitqueue_head(&isert_conn->conn_wait_comp_err); 496 init_completion(&isert_conn->conn_wait_comp_err);
497 kref_init(&isert_conn->conn_kref); 497 kref_init(&isert_conn->conn_kref);
498 kref_get(&isert_conn->conn_kref); 498 kref_get(&isert_conn->conn_kref);
499 mutex_init(&isert_conn->conn_mutex); 499 mutex_init(&isert_conn->conn_mutex);
500 mutex_init(&isert_conn->conn_comp_mutex);
501 spin_lock_init(&isert_conn->conn_lock); 500 spin_lock_init(&isert_conn->conn_lock);
502 501
503 cma_id->context = isert_conn; 502 cma_id->context = isert_conn;
@@ -688,11 +687,11 @@ isert_disconnect_work(struct work_struct *work)
688 687
689 pr_debug("isert_disconnect_work(): >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n"); 688 pr_debug("isert_disconnect_work(): >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
690 mutex_lock(&isert_conn->conn_mutex); 689 mutex_lock(&isert_conn->conn_mutex);
691 isert_conn->state = ISER_CONN_DOWN; 690 if (isert_conn->state == ISER_CONN_UP)
691 isert_conn->state = ISER_CONN_TERMINATING;
692 692
693 if (isert_conn->post_recv_buf_count == 0 && 693 if (isert_conn->post_recv_buf_count == 0 &&
694 atomic_read(&isert_conn->post_send_buf_count) == 0) { 694 atomic_read(&isert_conn->post_send_buf_count) == 0) {
695 pr_debug("Calling wake_up(&isert_conn->conn_wait);\n");
696 mutex_unlock(&isert_conn->conn_mutex); 695 mutex_unlock(&isert_conn->conn_mutex);
697 goto wake_up; 696 goto wake_up;
698 } 697 }
@@ -712,7 +711,7 @@ isert_disconnect_work(struct work_struct *work)
712 mutex_unlock(&isert_conn->conn_mutex); 711 mutex_unlock(&isert_conn->conn_mutex);
713 712
714wake_up: 713wake_up:
715 wake_up(&isert_conn->conn_wait); 714 complete(&isert_conn->conn_wait);
716 isert_put_conn(isert_conn); 715 isert_put_conn(isert_conn);
717} 716}
718 717
@@ -888,16 +887,17 @@ isert_init_send_wr(struct isert_conn *isert_conn, struct isert_cmd *isert_cmd,
888 * Coalesce send completion interrupts by only setting IB_SEND_SIGNALED 887 * Coalesce send completion interrupts by only setting IB_SEND_SIGNALED
889 * bit for every ISERT_COMP_BATCH_COUNT number of ib_post_send() calls. 888 * bit for every ISERT_COMP_BATCH_COUNT number of ib_post_send() calls.
890 */ 889 */
891 mutex_lock(&isert_conn->conn_comp_mutex); 890 mutex_lock(&isert_conn->conn_mutex);
892 if (coalesce && 891 if (coalesce && isert_conn->state == ISER_CONN_UP &&
893 ++isert_conn->conn_comp_batch < ISERT_COMP_BATCH_COUNT) { 892 ++isert_conn->conn_comp_batch < ISERT_COMP_BATCH_COUNT) {
893 tx_desc->llnode_active = true;
894 llist_add(&tx_desc->comp_llnode, &isert_conn->conn_comp_llist); 894 llist_add(&tx_desc->comp_llnode, &isert_conn->conn_comp_llist);
895 mutex_unlock(&isert_conn->conn_comp_mutex); 895 mutex_unlock(&isert_conn->conn_mutex);
896 return; 896 return;
897 } 897 }
898 isert_conn->conn_comp_batch = 0; 898 isert_conn->conn_comp_batch = 0;
899 tx_desc->comp_llnode_batch = llist_del_all(&isert_conn->conn_comp_llist); 899 tx_desc->comp_llnode_batch = llist_del_all(&isert_conn->conn_comp_llist);
900 mutex_unlock(&isert_conn->conn_comp_mutex); 900 mutex_unlock(&isert_conn->conn_mutex);
901 901
902 send_wr->send_flags = IB_SEND_SIGNALED; 902 send_wr->send_flags = IB_SEND_SIGNALED;
903} 903}
@@ -1464,7 +1464,7 @@ isert_put_cmd(struct isert_cmd *isert_cmd)
1464 case ISCSI_OP_SCSI_CMD: 1464 case ISCSI_OP_SCSI_CMD:
1465 spin_lock_bh(&conn->cmd_lock); 1465 spin_lock_bh(&conn->cmd_lock);
1466 if (!list_empty(&cmd->i_conn_node)) 1466 if (!list_empty(&cmd->i_conn_node))
1467 list_del(&cmd->i_conn_node); 1467 list_del_init(&cmd->i_conn_node);
1468 spin_unlock_bh(&conn->cmd_lock); 1468 spin_unlock_bh(&conn->cmd_lock);
1469 1469
1470 if (cmd->data_direction == DMA_TO_DEVICE) 1470 if (cmd->data_direction == DMA_TO_DEVICE)
@@ -1476,7 +1476,7 @@ isert_put_cmd(struct isert_cmd *isert_cmd)
1476 case ISCSI_OP_SCSI_TMFUNC: 1476 case ISCSI_OP_SCSI_TMFUNC:
1477 spin_lock_bh(&conn->cmd_lock); 1477 spin_lock_bh(&conn->cmd_lock);
1478 if (!list_empty(&cmd->i_conn_node)) 1478 if (!list_empty(&cmd->i_conn_node))
1479 list_del(&cmd->i_conn_node); 1479 list_del_init(&cmd->i_conn_node);
1480 spin_unlock_bh(&conn->cmd_lock); 1480 spin_unlock_bh(&conn->cmd_lock);
1481 1481
1482 transport_generic_free_cmd(&cmd->se_cmd, 0); 1482 transport_generic_free_cmd(&cmd->se_cmd, 0);
@@ -1486,7 +1486,7 @@ isert_put_cmd(struct isert_cmd *isert_cmd)
1486 case ISCSI_OP_TEXT: 1486 case ISCSI_OP_TEXT:
1487 spin_lock_bh(&conn->cmd_lock); 1487 spin_lock_bh(&conn->cmd_lock);
1488 if (!list_empty(&cmd->i_conn_node)) 1488 if (!list_empty(&cmd->i_conn_node))
1489 list_del(&cmd->i_conn_node); 1489 list_del_init(&cmd->i_conn_node);
1490 spin_unlock_bh(&conn->cmd_lock); 1490 spin_unlock_bh(&conn->cmd_lock);
1491 1491
1492 /* 1492 /*
@@ -1549,6 +1549,7 @@ isert_completion_rdma_read(struct iser_tx_desc *tx_desc,
1549 iscsit_stop_dataout_timer(cmd); 1549 iscsit_stop_dataout_timer(cmd);
1550 device->unreg_rdma_mem(isert_cmd, isert_conn); 1550 device->unreg_rdma_mem(isert_cmd, isert_conn);
1551 cmd->write_data_done = wr->cur_rdma_length; 1551 cmd->write_data_done = wr->cur_rdma_length;
1552 wr->send_wr_num = 0;
1552 1553
1553 pr_debug("Cmd: %p RDMA_READ comp calling execute_cmd\n", isert_cmd); 1554 pr_debug("Cmd: %p RDMA_READ comp calling execute_cmd\n", isert_cmd);
1554 spin_lock_bh(&cmd->istate_lock); 1555 spin_lock_bh(&cmd->istate_lock);
@@ -1589,7 +1590,7 @@ isert_do_control_comp(struct work_struct *work)
1589 pr_debug("Calling iscsit_logout_post_handler >>>>>>>>>>>>>>\n"); 1590 pr_debug("Calling iscsit_logout_post_handler >>>>>>>>>>>>>>\n");
1590 /* 1591 /*
1591 * Call atomic_dec(&isert_conn->post_send_buf_count) 1592 * Call atomic_dec(&isert_conn->post_send_buf_count)
1592 * from isert_free_conn() 1593 * from isert_wait_conn()
1593 */ 1594 */
1594 isert_conn->logout_posted = true; 1595 isert_conn->logout_posted = true;
1595 iscsit_logout_post_handler(cmd, cmd->conn); 1596 iscsit_logout_post_handler(cmd, cmd->conn);
@@ -1613,6 +1614,7 @@ isert_response_completion(struct iser_tx_desc *tx_desc,
1613 struct ib_device *ib_dev) 1614 struct ib_device *ib_dev)
1614{ 1615{
1615 struct iscsi_cmd *cmd = isert_cmd->iscsi_cmd; 1616 struct iscsi_cmd *cmd = isert_cmd->iscsi_cmd;
1617 struct isert_rdma_wr *wr = &isert_cmd->rdma_wr;
1616 1618
1617 if (cmd->i_state == ISTATE_SEND_TASKMGTRSP || 1619 if (cmd->i_state == ISTATE_SEND_TASKMGTRSP ||
1618 cmd->i_state == ISTATE_SEND_LOGOUTRSP || 1620 cmd->i_state == ISTATE_SEND_LOGOUTRSP ||
@@ -1624,7 +1626,7 @@ isert_response_completion(struct iser_tx_desc *tx_desc,
1624 queue_work(isert_comp_wq, &isert_cmd->comp_work); 1626 queue_work(isert_comp_wq, &isert_cmd->comp_work);
1625 return; 1627 return;
1626 } 1628 }
1627 atomic_dec(&isert_conn->post_send_buf_count); 1629 atomic_sub(wr->send_wr_num + 1, &isert_conn->post_send_buf_count);
1628 1630
1629 cmd->i_state = ISTATE_SENT_STATUS; 1631 cmd->i_state = ISTATE_SENT_STATUS;
1630 isert_completion_put(tx_desc, isert_cmd, ib_dev); 1632 isert_completion_put(tx_desc, isert_cmd, ib_dev);
@@ -1662,7 +1664,7 @@ __isert_send_completion(struct iser_tx_desc *tx_desc,
1662 case ISER_IB_RDMA_READ: 1664 case ISER_IB_RDMA_READ:
1663 pr_debug("isert_send_completion: Got ISER_IB_RDMA_READ:\n"); 1665 pr_debug("isert_send_completion: Got ISER_IB_RDMA_READ:\n");
1664 1666
1665 atomic_dec(&isert_conn->post_send_buf_count); 1667 atomic_sub(wr->send_wr_num, &isert_conn->post_send_buf_count);
1666 isert_completion_rdma_read(tx_desc, isert_cmd); 1668 isert_completion_rdma_read(tx_desc, isert_cmd);
1667 break; 1669 break;
1668 default: 1670 default:
@@ -1691,31 +1693,76 @@ isert_send_completion(struct iser_tx_desc *tx_desc,
1691} 1693}
1692 1694
1693static void 1695static void
1694isert_cq_comp_err(struct iser_tx_desc *tx_desc, struct isert_conn *isert_conn) 1696isert_cq_drain_comp_llist(struct isert_conn *isert_conn, struct ib_device *ib_dev)
1697{
1698 struct llist_node *llnode;
1699 struct isert_rdma_wr *wr;
1700 struct iser_tx_desc *t;
1701
1702 mutex_lock(&isert_conn->conn_mutex);
1703 llnode = llist_del_all(&isert_conn->conn_comp_llist);
1704 isert_conn->conn_comp_batch = 0;
1705 mutex_unlock(&isert_conn->conn_mutex);
1706
1707 while (llnode) {
1708 t = llist_entry(llnode, struct iser_tx_desc, comp_llnode);
1709 llnode = llist_next(llnode);
1710 wr = &t->isert_cmd->rdma_wr;
1711
1712 atomic_sub(wr->send_wr_num + 1, &isert_conn->post_send_buf_count);
1713 isert_completion_put(t, t->isert_cmd, ib_dev);
1714 }
1715}
1716
1717static void
1718isert_cq_tx_comp_err(struct iser_tx_desc *tx_desc, struct isert_conn *isert_conn)
1695{ 1719{
1696 struct ib_device *ib_dev = isert_conn->conn_cm_id->device; 1720 struct ib_device *ib_dev = isert_conn->conn_cm_id->device;
1721 struct isert_cmd *isert_cmd = tx_desc->isert_cmd;
1722 struct llist_node *llnode = tx_desc->comp_llnode_batch;
1723 struct isert_rdma_wr *wr;
1724 struct iser_tx_desc *t;
1697 1725
1698 if (tx_desc) { 1726 while (llnode) {
1699 struct isert_cmd *isert_cmd = tx_desc->isert_cmd; 1727 t = llist_entry(llnode, struct iser_tx_desc, comp_llnode);
1728 llnode = llist_next(llnode);
1729 wr = &t->isert_cmd->rdma_wr;
1700 1730
1701 if (!isert_cmd) 1731 atomic_sub(wr->send_wr_num + 1, &isert_conn->post_send_buf_count);
1702 isert_unmap_tx_desc(tx_desc, ib_dev); 1732 isert_completion_put(t, t->isert_cmd, ib_dev);
1703 else
1704 isert_completion_put(tx_desc, isert_cmd, ib_dev);
1705 } 1733 }
1734 tx_desc->comp_llnode_batch = NULL;
1706 1735
1707 if (isert_conn->post_recv_buf_count == 0 && 1736 if (!isert_cmd)
1708 atomic_read(&isert_conn->post_send_buf_count) == 0) { 1737 isert_unmap_tx_desc(tx_desc, ib_dev);
1709 pr_debug("isert_cq_comp_err >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n"); 1738 else
1710 pr_debug("Calling wake_up from isert_cq_comp_err\n"); 1739 isert_completion_put(tx_desc, isert_cmd, ib_dev);
1740}
1711 1741
1712 mutex_lock(&isert_conn->conn_mutex); 1742static void
1713 if (isert_conn->state != ISER_CONN_DOWN) 1743isert_cq_rx_comp_err(struct isert_conn *isert_conn)
1714 isert_conn->state = ISER_CONN_TERMINATING; 1744{
1715 mutex_unlock(&isert_conn->conn_mutex); 1745 struct ib_device *ib_dev = isert_conn->conn_cm_id->device;
1746 struct iscsi_conn *conn = isert_conn->conn;
1716 1747
1717 wake_up(&isert_conn->conn_wait_comp_err); 1748 if (isert_conn->post_recv_buf_count)
1749 return;
1750
1751 isert_cq_drain_comp_llist(isert_conn, ib_dev);
1752
1753 if (conn->sess) {
1754 target_sess_cmd_list_set_waiting(conn->sess->se_sess);
1755 target_wait_for_sess_cmds(conn->sess->se_sess);
1718 } 1756 }
1757
1758 while (atomic_read(&isert_conn->post_send_buf_count))
1759 msleep(3000);
1760
1761 mutex_lock(&isert_conn->conn_mutex);
1762 isert_conn->state = ISER_CONN_DOWN;
1763 mutex_unlock(&isert_conn->conn_mutex);
1764
1765 complete(&isert_conn->conn_wait_comp_err);
1719} 1766}
1720 1767
1721static void 1768static void
@@ -1740,8 +1787,14 @@ isert_cq_tx_work(struct work_struct *work)
1740 pr_debug("TX wc.status != IB_WC_SUCCESS >>>>>>>>>>>>>>\n"); 1787 pr_debug("TX wc.status != IB_WC_SUCCESS >>>>>>>>>>>>>>\n");
1741 pr_debug("TX wc.status: 0x%08x\n", wc.status); 1788 pr_debug("TX wc.status: 0x%08x\n", wc.status);
1742 pr_debug("TX wc.vendor_err: 0x%08x\n", wc.vendor_err); 1789 pr_debug("TX wc.vendor_err: 0x%08x\n", wc.vendor_err);
1743 atomic_dec(&isert_conn->post_send_buf_count); 1790
1744 isert_cq_comp_err(tx_desc, isert_conn); 1791 if (wc.wr_id != ISER_FASTREG_LI_WRID) {
1792 if (tx_desc->llnode_active)
1793 continue;
1794
1795 atomic_dec(&isert_conn->post_send_buf_count);
1796 isert_cq_tx_comp_err(tx_desc, isert_conn);
1797 }
1745 } 1798 }
1746 } 1799 }
1747 1800
@@ -1784,7 +1837,7 @@ isert_cq_rx_work(struct work_struct *work)
1784 wc.vendor_err); 1837 wc.vendor_err);
1785 } 1838 }
1786 isert_conn->post_recv_buf_count--; 1839 isert_conn->post_recv_buf_count--;
1787 isert_cq_comp_err(NULL, isert_conn); 1840 isert_cq_rx_comp_err(isert_conn);
1788 } 1841 }
1789 } 1842 }
1790 1843
@@ -2202,6 +2255,7 @@ isert_fast_reg_mr(struct fast_reg_descriptor *fr_desc,
2202 2255
2203 if (!fr_desc->valid) { 2256 if (!fr_desc->valid) {
2204 memset(&inv_wr, 0, sizeof(inv_wr)); 2257 memset(&inv_wr, 0, sizeof(inv_wr));
2258 inv_wr.wr_id = ISER_FASTREG_LI_WRID;
2205 inv_wr.opcode = IB_WR_LOCAL_INV; 2259 inv_wr.opcode = IB_WR_LOCAL_INV;
2206 inv_wr.ex.invalidate_rkey = fr_desc->data_mr->rkey; 2260 inv_wr.ex.invalidate_rkey = fr_desc->data_mr->rkey;
2207 wr = &inv_wr; 2261 wr = &inv_wr;
@@ -2212,6 +2266,7 @@ isert_fast_reg_mr(struct fast_reg_descriptor *fr_desc,
2212 2266
2213 /* Prepare FASTREG WR */ 2267 /* Prepare FASTREG WR */
2214 memset(&fr_wr, 0, sizeof(fr_wr)); 2268 memset(&fr_wr, 0, sizeof(fr_wr));
2269 fr_wr.wr_id = ISER_FASTREG_LI_WRID;
2215 fr_wr.opcode = IB_WR_FAST_REG_MR; 2270 fr_wr.opcode = IB_WR_FAST_REG_MR;
2216 fr_wr.wr.fast_reg.iova_start = 2271 fr_wr.wr.fast_reg.iova_start =
2217 fr_desc->data_frpl->page_list[0] + page_off; 2272 fr_desc->data_frpl->page_list[0] + page_off;
@@ -2377,12 +2432,12 @@ isert_put_datain(struct iscsi_conn *conn, struct iscsi_cmd *cmd)
2377 isert_init_send_wr(isert_conn, isert_cmd, 2432 isert_init_send_wr(isert_conn, isert_cmd,
2378 &isert_cmd->tx_desc.send_wr, true); 2433 &isert_cmd->tx_desc.send_wr, true);
2379 2434
2380 atomic_inc(&isert_conn->post_send_buf_count); 2435 atomic_add(wr->send_wr_num + 1, &isert_conn->post_send_buf_count);
2381 2436
2382 rc = ib_post_send(isert_conn->conn_qp, wr->send_wr, &wr_failed); 2437 rc = ib_post_send(isert_conn->conn_qp, wr->send_wr, &wr_failed);
2383 if (rc) { 2438 if (rc) {
2384 pr_warn("ib_post_send() failed for IB_WR_RDMA_WRITE\n"); 2439 pr_warn("ib_post_send() failed for IB_WR_RDMA_WRITE\n");
2385 atomic_dec(&isert_conn->post_send_buf_count); 2440 atomic_sub(wr->send_wr_num + 1, &isert_conn->post_send_buf_count);
2386 } 2441 }
2387 pr_debug("Cmd: %p posted RDMA_WRITE + Response for iSER Data READ\n", 2442 pr_debug("Cmd: %p posted RDMA_WRITE + Response for iSER Data READ\n",
2388 isert_cmd); 2443 isert_cmd);
@@ -2410,12 +2465,12 @@ isert_get_dataout(struct iscsi_conn *conn, struct iscsi_cmd *cmd, bool recovery)
2410 return rc; 2465 return rc;
2411 } 2466 }
2412 2467
2413 atomic_inc(&isert_conn->post_send_buf_count); 2468 atomic_add(wr->send_wr_num, &isert_conn->post_send_buf_count);
2414 2469
2415 rc = ib_post_send(isert_conn->conn_qp, wr->send_wr, &wr_failed); 2470 rc = ib_post_send(isert_conn->conn_qp, wr->send_wr, &wr_failed);
2416 if (rc) { 2471 if (rc) {
2417 pr_warn("ib_post_send() failed for IB_WR_RDMA_READ\n"); 2472 pr_warn("ib_post_send() failed for IB_WR_RDMA_READ\n");
2418 atomic_dec(&isert_conn->post_send_buf_count); 2473 atomic_sub(wr->send_wr_num, &isert_conn->post_send_buf_count);
2419 } 2474 }
2420 pr_debug("Cmd: %p posted RDMA_READ memory for ISER Data WRITE\n", 2475 pr_debug("Cmd: %p posted RDMA_READ memory for ISER Data WRITE\n",
2421 isert_cmd); 2476 isert_cmd);
@@ -2702,22 +2757,11 @@ isert_free_np(struct iscsi_np *np)
2702 kfree(isert_np); 2757 kfree(isert_np);
2703} 2758}
2704 2759
2705static int isert_check_state(struct isert_conn *isert_conn, int state) 2760static void isert_wait_conn(struct iscsi_conn *conn)
2706{
2707 int ret;
2708
2709 mutex_lock(&isert_conn->conn_mutex);
2710 ret = (isert_conn->state == state);
2711 mutex_unlock(&isert_conn->conn_mutex);
2712
2713 return ret;
2714}
2715
2716static void isert_free_conn(struct iscsi_conn *conn)
2717{ 2761{
2718 struct isert_conn *isert_conn = conn->context; 2762 struct isert_conn *isert_conn = conn->context;
2719 2763
2720 pr_debug("isert_free_conn: Starting \n"); 2764 pr_debug("isert_wait_conn: Starting \n");
2721 /* 2765 /*
2722 * Decrement post_send_buf_count for special case when called 2766 * Decrement post_send_buf_count for special case when called
2723 * from isert_do_control_comp() -> iscsit_logout_post_handler() 2767 * from isert_do_control_comp() -> iscsit_logout_post_handler()
@@ -2727,38 +2771,29 @@ static void isert_free_conn(struct iscsi_conn *conn)
2727 atomic_dec(&isert_conn->post_send_buf_count); 2771 atomic_dec(&isert_conn->post_send_buf_count);
2728 2772
2729 if (isert_conn->conn_cm_id && isert_conn->state != ISER_CONN_DOWN) { 2773 if (isert_conn->conn_cm_id && isert_conn->state != ISER_CONN_DOWN) {
2730 pr_debug("Calling rdma_disconnect from isert_free_conn\n"); 2774 pr_debug("Calling rdma_disconnect from isert_wait_conn\n");
2731 rdma_disconnect(isert_conn->conn_cm_id); 2775 rdma_disconnect(isert_conn->conn_cm_id);
2732 } 2776 }
2733 /* 2777 /*
2734 * Only wait for conn_wait_comp_err if the isert_conn made it 2778 * Only wait for conn_wait_comp_err if the isert_conn made it
2735 * into full feature phase.. 2779 * into full feature phase..
2736 */ 2780 */
2737 if (isert_conn->state == ISER_CONN_UP) {
2738 pr_debug("isert_free_conn: Before wait_event comp_err %d\n",
2739 isert_conn->state);
2740 mutex_unlock(&isert_conn->conn_mutex);
2741
2742 wait_event(isert_conn->conn_wait_comp_err,
2743 (isert_check_state(isert_conn, ISER_CONN_TERMINATING)));
2744
2745 wait_event(isert_conn->conn_wait,
2746 (isert_check_state(isert_conn, ISER_CONN_DOWN)));
2747
2748 isert_put_conn(isert_conn);
2749 return;
2750 }
2751 if (isert_conn->state == ISER_CONN_INIT) { 2781 if (isert_conn->state == ISER_CONN_INIT) {
2752 mutex_unlock(&isert_conn->conn_mutex); 2782 mutex_unlock(&isert_conn->conn_mutex);
2753 isert_put_conn(isert_conn);
2754 return; 2783 return;
2755 } 2784 }
2756 pr_debug("isert_free_conn: wait_event conn_wait %d\n", 2785 if (isert_conn->state == ISER_CONN_UP)
2757 isert_conn->state); 2786 isert_conn->state = ISER_CONN_TERMINATING;
2758 mutex_unlock(&isert_conn->conn_mutex); 2787 mutex_unlock(&isert_conn->conn_mutex);
2759 2788
2760 wait_event(isert_conn->conn_wait, 2789 wait_for_completion(&isert_conn->conn_wait_comp_err);
2761 (isert_check_state(isert_conn, ISER_CONN_DOWN))); 2790
2791 wait_for_completion(&isert_conn->conn_wait);
2792}
2793
2794static void isert_free_conn(struct iscsi_conn *conn)
2795{
2796 struct isert_conn *isert_conn = conn->context;
2762 2797
2763 isert_put_conn(isert_conn); 2798 isert_put_conn(isert_conn);
2764} 2799}
@@ -2771,6 +2806,7 @@ static struct iscsit_transport iser_target_transport = {
2771 .iscsit_setup_np = isert_setup_np, 2806 .iscsit_setup_np = isert_setup_np,
2772 .iscsit_accept_np = isert_accept_np, 2807 .iscsit_accept_np = isert_accept_np,
2773 .iscsit_free_np = isert_free_np, 2808 .iscsit_free_np = isert_free_np,
2809 .iscsit_wait_conn = isert_wait_conn,
2774 .iscsit_free_conn = isert_free_conn, 2810 .iscsit_free_conn = isert_free_conn,
2775 .iscsit_get_login_rx = isert_get_login_rx, 2811 .iscsit_get_login_rx = isert_get_login_rx,
2776 .iscsit_put_login_tx = isert_put_login_tx, 2812 .iscsit_put_login_tx = isert_put_login_tx,
diff --git a/drivers/infiniband/ulp/isert/ib_isert.h b/drivers/infiniband/ulp/isert/ib_isert.h
index 708a069002f3..f6ae7f5dd408 100644
--- a/drivers/infiniband/ulp/isert/ib_isert.h
+++ b/drivers/infiniband/ulp/isert/ib_isert.h
@@ -6,6 +6,7 @@
6 6
7#define ISERT_RDMA_LISTEN_BACKLOG 10 7#define ISERT_RDMA_LISTEN_BACKLOG 10
8#define ISCSI_ISER_SG_TABLESIZE 256 8#define ISCSI_ISER_SG_TABLESIZE 256
9#define ISER_FASTREG_LI_WRID 0xffffffffffffffffULL
9 10
10enum isert_desc_type { 11enum isert_desc_type {
11 ISCSI_TX_CONTROL, 12 ISCSI_TX_CONTROL,
@@ -45,6 +46,7 @@ struct iser_tx_desc {
45 struct isert_cmd *isert_cmd; 46 struct isert_cmd *isert_cmd;
46 struct llist_node *comp_llnode_batch; 47 struct llist_node *comp_llnode_batch;
47 struct llist_node comp_llnode; 48 struct llist_node comp_llnode;
49 bool llnode_active;
48 struct ib_send_wr send_wr; 50 struct ib_send_wr send_wr;
49} __packed; 51} __packed;
50 52
@@ -116,8 +118,8 @@ struct isert_conn {
116 struct isert_device *conn_device; 118 struct isert_device *conn_device;
117 struct work_struct conn_logout_work; 119 struct work_struct conn_logout_work;
118 struct mutex conn_mutex; 120 struct mutex conn_mutex;
119 wait_queue_head_t conn_wait; 121 struct completion conn_wait;
120 wait_queue_head_t conn_wait_comp_err; 122 struct completion conn_wait_comp_err;
121 struct kref conn_kref; 123 struct kref conn_kref;
122 struct list_head conn_fr_pool; 124 struct list_head conn_fr_pool;
123 int conn_fr_pool_size; 125 int conn_fr_pool_size;
@@ -126,7 +128,6 @@ struct isert_conn {
126#define ISERT_COMP_BATCH_COUNT 8 128#define ISERT_COMP_BATCH_COUNT 8
127 int conn_comp_batch; 129 int conn_comp_batch;
128 struct llist_head conn_comp_llist; 130 struct llist_head conn_comp_llist;
129 struct mutex conn_comp_mutex;
130}; 131};
131 132
132#define ISERT_MAX_CQ 64 133#define ISERT_MAX_CQ 64
diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c
index a06e12552886..ce953d895f5b 100644
--- a/drivers/input/evdev.c
+++ b/drivers/input/evdev.c
@@ -954,11 +954,13 @@ static long evdev_do_ioctl(struct file *file, unsigned int cmd,
954 return -EFAULT; 954 return -EFAULT;
955 955
956 error = input_ff_upload(dev, &effect, file); 956 error = input_ff_upload(dev, &effect, file);
957 if (error)
958 return error;
957 959
958 if (put_user(effect.id, &(((struct ff_effect __user *)p)->id))) 960 if (put_user(effect.id, &(((struct ff_effect __user *)p)->id)))
959 return -EFAULT; 961 return -EFAULT;
960 962
961 return error; 963 return 0;
962 } 964 }
963 965
964 /* Multi-number variable-length handlers */ 966 /* Multi-number variable-length handlers */
diff --git a/drivers/input/keyboard/adp5588-keys.c b/drivers/input/keyboard/adp5588-keys.c
index bb3b57bea8ba..5ef7fcf0e250 100644
--- a/drivers/input/keyboard/adp5588-keys.c
+++ b/drivers/input/keyboard/adp5588-keys.c
@@ -76,8 +76,18 @@ static int adp5588_gpio_get_value(struct gpio_chip *chip, unsigned off)
76 struct adp5588_kpad *kpad = container_of(chip, struct adp5588_kpad, gc); 76 struct adp5588_kpad *kpad = container_of(chip, struct adp5588_kpad, gc);
77 unsigned int bank = ADP5588_BANK(kpad->gpiomap[off]); 77 unsigned int bank = ADP5588_BANK(kpad->gpiomap[off]);
78 unsigned int bit = ADP5588_BIT(kpad->gpiomap[off]); 78 unsigned int bit = ADP5588_BIT(kpad->gpiomap[off]);
79 int val;
79 80
80 return !!(adp5588_read(kpad->client, GPIO_DAT_STAT1 + bank) & bit); 81 mutex_lock(&kpad->gpio_lock);
82
83 if (kpad->dir[bank] & bit)
84 val = kpad->dat_out[bank];
85 else
86 val = adp5588_read(kpad->client, GPIO_DAT_STAT1 + bank);
87
88 mutex_unlock(&kpad->gpio_lock);
89
90 return !!(val & bit);
81} 91}
82 92
83static void adp5588_gpio_set_value(struct gpio_chip *chip, 93static void adp5588_gpio_set_value(struct gpio_chip *chip,
diff --git a/drivers/input/misc/arizona-haptics.c b/drivers/input/misc/arizona-haptics.c
index 7a04f54ef961..ef2e281b0a43 100644
--- a/drivers/input/misc/arizona-haptics.c
+++ b/drivers/input/misc/arizona-haptics.c
@@ -37,7 +37,6 @@ static void arizona_haptics_work(struct work_struct *work)
37 struct arizona_haptics, 37 struct arizona_haptics,
38 work); 38 work);
39 struct arizona *arizona = haptics->arizona; 39 struct arizona *arizona = haptics->arizona;
40 struct mutex *dapm_mutex = &arizona->dapm->card->dapm_mutex;
41 int ret; 40 int ret;
42 41
43 if (!haptics->arizona->dapm) { 42 if (!haptics->arizona->dapm) {
@@ -67,13 +66,10 @@ static void arizona_haptics_work(struct work_struct *work)
67 return; 66 return;
68 } 67 }
69 68
70 mutex_lock_nested(dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
71
72 ret = snd_soc_dapm_enable_pin(arizona->dapm, "HAPTICS"); 69 ret = snd_soc_dapm_enable_pin(arizona->dapm, "HAPTICS");
73 if (ret != 0) { 70 if (ret != 0) {
74 dev_err(arizona->dev, "Failed to start HAPTICS: %d\n", 71 dev_err(arizona->dev, "Failed to start HAPTICS: %d\n",
75 ret); 72 ret);
76 mutex_unlock(dapm_mutex);
77 return; 73 return;
78 } 74 }
79 75
@@ -81,21 +77,14 @@ static void arizona_haptics_work(struct work_struct *work)
81 if (ret != 0) { 77 if (ret != 0) {
82 dev_err(arizona->dev, "Failed to sync DAPM: %d\n", 78 dev_err(arizona->dev, "Failed to sync DAPM: %d\n",
83 ret); 79 ret);
84 mutex_unlock(dapm_mutex);
85 return; 80 return;
86 } 81 }
87
88 mutex_unlock(dapm_mutex);
89
90 } else { 82 } else {
91 /* This disable sequence will be a noop if already enabled */ 83 /* This disable sequence will be a noop if already enabled */
92 mutex_lock_nested(dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
93
94 ret = snd_soc_dapm_disable_pin(arizona->dapm, "HAPTICS"); 84 ret = snd_soc_dapm_disable_pin(arizona->dapm, "HAPTICS");
95 if (ret != 0) { 85 if (ret != 0) {
96 dev_err(arizona->dev, "Failed to disable HAPTICS: %d\n", 86 dev_err(arizona->dev, "Failed to disable HAPTICS: %d\n",
97 ret); 87 ret);
98 mutex_unlock(dapm_mutex);
99 return; 88 return;
100 } 89 }
101 90
@@ -103,12 +92,9 @@ static void arizona_haptics_work(struct work_struct *work)
103 if (ret != 0) { 92 if (ret != 0) {
104 dev_err(arizona->dev, "Failed to sync DAPM: %d\n", 93 dev_err(arizona->dev, "Failed to sync DAPM: %d\n",
105 ret); 94 ret);
106 mutex_unlock(dapm_mutex);
107 return; 95 return;
108 } 96 }
109 97
110 mutex_unlock(dapm_mutex);
111
112 ret = regmap_update_bits(arizona->regmap, 98 ret = regmap_update_bits(arizona->regmap,
113 ARIZONA_HAPTICS_CONTROL_1, 99 ARIZONA_HAPTICS_CONTROL_1,
114 ARIZONA_HAP_CTRL_MASK, 100 ARIZONA_HAP_CTRL_MASK,
@@ -155,16 +141,11 @@ static int arizona_haptics_play(struct input_dev *input, void *data,
155static void arizona_haptics_close(struct input_dev *input) 141static void arizona_haptics_close(struct input_dev *input)
156{ 142{
157 struct arizona_haptics *haptics = input_get_drvdata(input); 143 struct arizona_haptics *haptics = input_get_drvdata(input);
158 struct mutex *dapm_mutex = &haptics->arizona->dapm->card->dapm_mutex;
159 144
160 cancel_work_sync(&haptics->work); 145 cancel_work_sync(&haptics->work);
161 146
162 mutex_lock_nested(dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
163
164 if (haptics->arizona->dapm) 147 if (haptics->arizona->dapm)
165 snd_soc_dapm_disable_pin(haptics->arizona->dapm, "HAPTICS"); 148 snd_soc_dapm_disable_pin(haptics->arizona->dapm, "HAPTICS");
166
167 mutex_unlock(dapm_mutex);
168} 149}
169 150
170static int arizona_haptics_probe(struct platform_device *pdev) 151static int arizona_haptics_probe(struct platform_device *pdev)
diff --git a/drivers/input/misc/da9052_onkey.c b/drivers/input/misc/da9052_onkey.c
index 1f695f229ea8..184c8f21ab59 100644
--- a/drivers/input/misc/da9052_onkey.c
+++ b/drivers/input/misc/da9052_onkey.c
@@ -27,29 +27,32 @@ struct da9052_onkey {
27 27
28static void da9052_onkey_query(struct da9052_onkey *onkey) 28static void da9052_onkey_query(struct da9052_onkey *onkey)
29{ 29{
30 int key_stat; 30 int ret;
31 31
32 key_stat = da9052_reg_read(onkey->da9052, DA9052_EVENT_B_REG); 32 ret = da9052_reg_read(onkey->da9052, DA9052_STATUS_A_REG);
33 if (key_stat < 0) { 33 if (ret < 0) {
34 dev_err(onkey->da9052->dev, 34 dev_err(onkey->da9052->dev,
35 "Failed to read onkey event %d\n", key_stat); 35 "Failed to read onkey event err=%d\n", ret);
36 } else { 36 } else {
37 /* 37 /*
38 * Since interrupt for deassertion of ONKEY pin is not 38 * Since interrupt for deassertion of ONKEY pin is not
39 * generated, onkey event state determines the onkey 39 * generated, onkey event state determines the onkey
40 * button state. 40 * button state.
41 */ 41 */
42 key_stat &= DA9052_EVENTB_ENONKEY; 42 bool pressed = !(ret & DA9052_STATUSA_NONKEY);
43 input_report_key(onkey->input, KEY_POWER, key_stat); 43
44 input_report_key(onkey->input, KEY_POWER, pressed);
44 input_sync(onkey->input); 45 input_sync(onkey->input);
45 }
46 46
47 /* 47 /*
48 * Interrupt is generated only when the ONKEY pin is asserted. 48 * Interrupt is generated only when the ONKEY pin
49 * Hence the deassertion of the pin is simulated through work queue. 49 * is asserted. Hence the deassertion of the pin
50 */ 50 * is simulated through work queue.
51 if (key_stat) 51 */
52 schedule_delayed_work(&onkey->work, msecs_to_jiffies(50)); 52 if (pressed)
53 schedule_delayed_work(&onkey->work,
54 msecs_to_jiffies(50));
55 }
53} 56}
54 57
55static void da9052_onkey_work(struct work_struct *work) 58static void da9052_onkey_work(struct work_struct *work)
diff --git a/drivers/input/mouse/cypress_ps2.c b/drivers/input/mouse/cypress_ps2.c
index 87095e2f5153..8af34ffe208b 100644
--- a/drivers/input/mouse/cypress_ps2.c
+++ b/drivers/input/mouse/cypress_ps2.c
@@ -409,7 +409,6 @@ static int cypress_set_input_params(struct input_dev *input,
409 __clear_bit(REL_X, input->relbit); 409 __clear_bit(REL_X, input->relbit);
410 __clear_bit(REL_Y, input->relbit); 410 __clear_bit(REL_Y, input->relbit);
411 411
412 __set_bit(INPUT_PROP_BUTTONPAD, input->propbit);
413 __set_bit(EV_KEY, input->evbit); 412 __set_bit(EV_KEY, input->evbit);
414 __set_bit(BTN_LEFT, input->keybit); 413 __set_bit(BTN_LEFT, input->keybit);
415 __set_bit(BTN_RIGHT, input->keybit); 414 __set_bit(BTN_RIGHT, input->keybit);
diff --git a/drivers/input/mouse/synaptics.c b/drivers/input/mouse/synaptics.c
index 26386f9d2569..d8d49d10f9bb 100644
--- a/drivers/input/mouse/synaptics.c
+++ b/drivers/input/mouse/synaptics.c
@@ -265,11 +265,22 @@ static int synaptics_identify(struct psmouse *psmouse)
265 * Read touchpad resolution and maximum reported coordinates 265 * Read touchpad resolution and maximum reported coordinates
266 * Resolution is left zero if touchpad does not support the query 266 * Resolution is left zero if touchpad does not support the query
267 */ 267 */
268
269static const int *quirk_min_max;
270
268static int synaptics_resolution(struct psmouse *psmouse) 271static int synaptics_resolution(struct psmouse *psmouse)
269{ 272{
270 struct synaptics_data *priv = psmouse->private; 273 struct synaptics_data *priv = psmouse->private;
271 unsigned char resp[3]; 274 unsigned char resp[3];
272 275
276 if (quirk_min_max) {
277 priv->x_min = quirk_min_max[0];
278 priv->x_max = quirk_min_max[1];
279 priv->y_min = quirk_min_max[2];
280 priv->y_max = quirk_min_max[3];
281 return 0;
282 }
283
273 if (SYN_ID_MAJOR(priv->identity) < 4) 284 if (SYN_ID_MAJOR(priv->identity) < 4)
274 return 0; 285 return 0;
275 286
@@ -1485,10 +1496,54 @@ static const struct dmi_system_id olpc_dmi_table[] __initconst = {
1485 { } 1496 { }
1486}; 1497};
1487 1498
1499static const struct dmi_system_id min_max_dmi_table[] __initconst = {
1500#if defined(CONFIG_DMI)
1501 {
1502 /* Lenovo ThinkPad Helix */
1503 .matches = {
1504 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
1505 DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad Helix"),
1506 },
1507 .driver_data = (int []){1024, 5052, 2258, 4832},
1508 },
1509 {
1510 /* Lenovo ThinkPad X240 */
1511 .matches = {
1512 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
1513 DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad X240"),
1514 },
1515 .driver_data = (int []){1232, 5710, 1156, 4696},
1516 },
1517 {
1518 /* Lenovo ThinkPad T440s */
1519 .matches = {
1520 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
1521 DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad T440"),
1522 },
1523 .driver_data = (int []){1024, 5112, 2024, 4832},
1524 },
1525 {
1526 /* Lenovo ThinkPad T540p */
1527 .matches = {
1528 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
1529 DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad T540"),
1530 },
1531 .driver_data = (int []){1024, 5056, 2058, 4832},
1532 },
1533#endif
1534 { }
1535};
1536
1488void __init synaptics_module_init(void) 1537void __init synaptics_module_init(void)
1489{ 1538{
1539 const struct dmi_system_id *min_max_dmi;
1540
1490 impaired_toshiba_kbc = dmi_check_system(toshiba_dmi_table); 1541 impaired_toshiba_kbc = dmi_check_system(toshiba_dmi_table);
1491 broken_olpc_ec = dmi_check_system(olpc_dmi_table); 1542 broken_olpc_ec = dmi_check_system(olpc_dmi_table);
1543
1544 min_max_dmi = dmi_first_match(min_max_dmi_table);
1545 if (min_max_dmi)
1546 quirk_min_max = min_max_dmi->driver_data;
1492} 1547}
1493 1548
1494static int __synaptics_init(struct psmouse *psmouse, bool absolute_mode) 1549static int __synaptics_init(struct psmouse *psmouse, bool absolute_mode)
diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
index 4c842c320c2e..b604564dec5c 100644
--- a/drivers/input/mousedev.c
+++ b/drivers/input/mousedev.c
@@ -67,7 +67,6 @@ struct mousedev {
67 struct device dev; 67 struct device dev;
68 struct cdev cdev; 68 struct cdev cdev;
69 bool exist; 69 bool exist;
70 bool is_mixdev;
71 70
72 struct list_head mixdev_node; 71 struct list_head mixdev_node;
73 bool opened_by_mixdev; 72 bool opened_by_mixdev;
@@ -77,6 +76,9 @@ struct mousedev {
77 int old_x[4], old_y[4]; 76 int old_x[4], old_y[4];
78 int frac_dx, frac_dy; 77 int frac_dx, frac_dy;
79 unsigned long touch; 78 unsigned long touch;
79
80 int (*open_device)(struct mousedev *mousedev);
81 void (*close_device)(struct mousedev *mousedev);
80}; 82};
81 83
82enum mousedev_emul { 84enum mousedev_emul {
@@ -116,9 +118,6 @@ static unsigned char mousedev_imex_seq[] = { 0xf3, 200, 0xf3, 200, 0xf3, 80 };
116static struct mousedev *mousedev_mix; 118static struct mousedev *mousedev_mix;
117static LIST_HEAD(mousedev_mix_list); 119static LIST_HEAD(mousedev_mix_list);
118 120
119static void mixdev_open_devices(void);
120static void mixdev_close_devices(void);
121
122#define fx(i) (mousedev->old_x[(mousedev->pkt_count - (i)) & 03]) 121#define fx(i) (mousedev->old_x[(mousedev->pkt_count - (i)) & 03])
123#define fy(i) (mousedev->old_y[(mousedev->pkt_count - (i)) & 03]) 122#define fy(i) (mousedev->old_y[(mousedev->pkt_count - (i)) & 03])
124 123
@@ -428,9 +427,7 @@ static int mousedev_open_device(struct mousedev *mousedev)
428 if (retval) 427 if (retval)
429 return retval; 428 return retval;
430 429
431 if (mousedev->is_mixdev) 430 if (!mousedev->exist)
432 mixdev_open_devices();
433 else if (!mousedev->exist)
434 retval = -ENODEV; 431 retval = -ENODEV;
435 else if (!mousedev->open++) { 432 else if (!mousedev->open++) {
436 retval = input_open_device(&mousedev->handle); 433 retval = input_open_device(&mousedev->handle);
@@ -446,9 +443,7 @@ static void mousedev_close_device(struct mousedev *mousedev)
446{ 443{
447 mutex_lock(&mousedev->mutex); 444 mutex_lock(&mousedev->mutex);
448 445
449 if (mousedev->is_mixdev) 446 if (mousedev->exist && !--mousedev->open)
450 mixdev_close_devices();
451 else if (mousedev->exist && !--mousedev->open)
452 input_close_device(&mousedev->handle); 447 input_close_device(&mousedev->handle);
453 448
454 mutex_unlock(&mousedev->mutex); 449 mutex_unlock(&mousedev->mutex);
@@ -459,21 +454,29 @@ static void mousedev_close_device(struct mousedev *mousedev)
459 * stream. Note that this function is called with mousedev_mix->mutex 454 * stream. Note that this function is called with mousedev_mix->mutex
460 * held. 455 * held.
461 */ 456 */
462static void mixdev_open_devices(void) 457static int mixdev_open_devices(struct mousedev *mixdev)
463{ 458{
464 struct mousedev *mousedev; 459 int error;
460
461 error = mutex_lock_interruptible(&mixdev->mutex);
462 if (error)
463 return error;
465 464
466 if (mousedev_mix->open++) 465 if (!mixdev->open++) {
467 return; 466 struct mousedev *mousedev;
468 467
469 list_for_each_entry(mousedev, &mousedev_mix_list, mixdev_node) { 468 list_for_each_entry(mousedev, &mousedev_mix_list, mixdev_node) {
470 if (!mousedev->opened_by_mixdev) { 469 if (!mousedev->opened_by_mixdev) {
471 if (mousedev_open_device(mousedev)) 470 if (mousedev_open_device(mousedev))
472 continue; 471 continue;
473 472
474 mousedev->opened_by_mixdev = true; 473 mousedev->opened_by_mixdev = true;
474 }
475 } 475 }
476 } 476 }
477
478 mutex_unlock(&mixdev->mutex);
479 return 0;
477} 480}
478 481
479/* 482/*
@@ -481,19 +484,22 @@ static void mixdev_open_devices(void)
481 * device. Note that this function is called with mousedev_mix->mutex 484 * device. Note that this function is called with mousedev_mix->mutex
482 * held. 485 * held.
483 */ 486 */
484static void mixdev_close_devices(void) 487static void mixdev_close_devices(struct mousedev *mixdev)
485{ 488{
486 struct mousedev *mousedev; 489 mutex_lock(&mixdev->mutex);
487 490
488 if (--mousedev_mix->open) 491 if (!--mixdev->open) {
489 return; 492 struct mousedev *mousedev;
490 493
491 list_for_each_entry(mousedev, &mousedev_mix_list, mixdev_node) { 494 list_for_each_entry(mousedev, &mousedev_mix_list, mixdev_node) {
492 if (mousedev->opened_by_mixdev) { 495 if (mousedev->opened_by_mixdev) {
493 mousedev->opened_by_mixdev = false; 496 mousedev->opened_by_mixdev = false;
494 mousedev_close_device(mousedev); 497 mousedev_close_device(mousedev);
498 }
495 } 499 }
496 } 500 }
501
502 mutex_unlock(&mixdev->mutex);
497} 503}
498 504
499 505
@@ -522,7 +528,7 @@ static int mousedev_release(struct inode *inode, struct file *file)
522 mousedev_detach_client(mousedev, client); 528 mousedev_detach_client(mousedev, client);
523 kfree(client); 529 kfree(client);
524 530
525 mousedev_close_device(mousedev); 531 mousedev->close_device(mousedev);
526 532
527 return 0; 533 return 0;
528} 534}
@@ -550,7 +556,7 @@ static int mousedev_open(struct inode *inode, struct file *file)
550 client->mousedev = mousedev; 556 client->mousedev = mousedev;
551 mousedev_attach_client(mousedev, client); 557 mousedev_attach_client(mousedev, client);
552 558
553 error = mousedev_open_device(mousedev); 559 error = mousedev->open_device(mousedev);
554 if (error) 560 if (error)
555 goto err_free_client; 561 goto err_free_client;
556 562
@@ -861,16 +867,21 @@ static struct mousedev *mousedev_create(struct input_dev *dev,
861 867
862 if (mixdev) { 868 if (mixdev) {
863 dev_set_name(&mousedev->dev, "mice"); 869 dev_set_name(&mousedev->dev, "mice");
870
871 mousedev->open_device = mixdev_open_devices;
872 mousedev->close_device = mixdev_close_devices;
864 } else { 873 } else {
865 int dev_no = minor; 874 int dev_no = minor;
866 /* Normalize device number if it falls into legacy range */ 875 /* Normalize device number if it falls into legacy range */
867 if (dev_no < MOUSEDEV_MINOR_BASE + MOUSEDEV_MINORS) 876 if (dev_no < MOUSEDEV_MINOR_BASE + MOUSEDEV_MINORS)
868 dev_no -= MOUSEDEV_MINOR_BASE; 877 dev_no -= MOUSEDEV_MINOR_BASE;
869 dev_set_name(&mousedev->dev, "mouse%d", dev_no); 878 dev_set_name(&mousedev->dev, "mouse%d", dev_no);
879
880 mousedev->open_device = mousedev_open_device;
881 mousedev->close_device = mousedev_close_device;
870 } 882 }
871 883
872 mousedev->exist = true; 884 mousedev->exist = true;
873 mousedev->is_mixdev = mixdev;
874 mousedev->handle.dev = input_get_device(dev); 885 mousedev->handle.dev = input_get_device(dev);
875 mousedev->handle.name = dev_name(&mousedev->dev); 886 mousedev->handle.name = dev_name(&mousedev->dev);
876 mousedev->handle.handler = handler; 887 mousedev->handle.handler = handler;
@@ -919,7 +930,7 @@ static void mousedev_destroy(struct mousedev *mousedev)
919 device_del(&mousedev->dev); 930 device_del(&mousedev->dev);
920 mousedev_cleanup(mousedev); 931 mousedev_cleanup(mousedev);
921 input_free_minor(MINOR(mousedev->dev.devt)); 932 input_free_minor(MINOR(mousedev->dev.devt));
922 if (!mousedev->is_mixdev) 933 if (mousedev != mousedev_mix)
923 input_unregister_handle(&mousedev->handle); 934 input_unregister_handle(&mousedev->handle);
924 put_device(&mousedev->dev); 935 put_device(&mousedev->dev);
925} 936}
diff --git a/drivers/iommu/omap-iommu-debug.c b/drivers/iommu/omap-iommu-debug.c
index d97fbe4fb9b1..80fffba7f12d 100644
--- a/drivers/iommu/omap-iommu-debug.c
+++ b/drivers/iommu/omap-iommu-debug.c
@@ -354,8 +354,8 @@ DEBUG_FOPS(mem);
354 return -ENOMEM; \ 354 return -ENOMEM; \
355 } 355 }
356 356
357#define DEBUG_ADD_FILE(name) __DEBUG_ADD_FILE(name, 600) 357#define DEBUG_ADD_FILE(name) __DEBUG_ADD_FILE(name, 0600)
358#define DEBUG_ADD_FILE_RO(name) __DEBUG_ADD_FILE(name, 400) 358#define DEBUG_ADD_FILE_RO(name) __DEBUG_ADD_FILE(name, 0400)
359 359
360static int iommu_debug_register(struct device *dev, void *data) 360static int iommu_debug_register(struct device *dev, void *data)
361{ 361{
diff --git a/drivers/irqchip/Makefile b/drivers/irqchip/Makefile
index 5194afb39e78..1c0c151d108c 100644
--- a/drivers/irqchip/Makefile
+++ b/drivers/irqchip/Makefile
@@ -12,6 +12,7 @@ obj-$(CONFIG_METAG_PERFCOUNTER_IRQS) += irq-metag.o
12obj-$(CONFIG_ARCH_MOXART) += irq-moxart.o 12obj-$(CONFIG_ARCH_MOXART) += irq-moxart.o
13obj-$(CONFIG_ORION_IRQCHIP) += irq-orion.o 13obj-$(CONFIG_ORION_IRQCHIP) += irq-orion.o
14obj-$(CONFIG_ARCH_SUNXI) += irq-sun4i.o 14obj-$(CONFIG_ARCH_SUNXI) += irq-sun4i.o
15obj-$(CONFIG_ARCH_SUNXI) += irq-sunxi-nmi.o
15obj-$(CONFIG_ARCH_SPEAR3XX) += spear-shirq.o 16obj-$(CONFIG_ARCH_SPEAR3XX) += spear-shirq.o
16obj-$(CONFIG_ARM_GIC) += irq-gic.o 17obj-$(CONFIG_ARM_GIC) += irq-gic.o
17obj-$(CONFIG_ARM_NVIC) += irq-nvic.o 18obj-$(CONFIG_ARM_NVIC) += irq-nvic.o
diff --git a/drivers/irqchip/irq-armada-370-xp.c b/drivers/irqchip/irq-armada-370-xp.c
index 540956465ed2..41be897df8d5 100644
--- a/drivers/irqchip/irq-armada-370-xp.c
+++ b/drivers/irqchip/irq-armada-370-xp.c
@@ -18,6 +18,7 @@
18#include <linux/init.h> 18#include <linux/init.h>
19#include <linux/irq.h> 19#include <linux/irq.h>
20#include <linux/interrupt.h> 20#include <linux/interrupt.h>
21#include <linux/irqchip/chained_irq.h>
21#include <linux/io.h> 22#include <linux/io.h>
22#include <linux/of_address.h> 23#include <linux/of_address.h>
23#include <linux/of_irq.h> 24#include <linux/of_irq.h>
@@ -42,6 +43,7 @@
42#define ARMADA_370_XP_INT_SOURCE_CTL(irq) (0x100 + irq*4) 43#define ARMADA_370_XP_INT_SOURCE_CTL(irq) (0x100 + irq*4)
43 44
44#define ARMADA_370_XP_CPU_INTACK_OFFS (0x44) 45#define ARMADA_370_XP_CPU_INTACK_OFFS (0x44)
46#define ARMADA_375_PPI_CAUSE (0x10)
45 47
46#define ARMADA_370_XP_SW_TRIG_INT_OFFS (0x4) 48#define ARMADA_370_XP_SW_TRIG_INT_OFFS (0x4)
47#define ARMADA_370_XP_IN_DRBEL_MSK_OFFS (0xc) 49#define ARMADA_370_XP_IN_DRBEL_MSK_OFFS (0xc)
@@ -352,7 +354,63 @@ static struct irq_domain_ops armada_370_xp_mpic_irq_ops = {
352 .xlate = irq_domain_xlate_onecell, 354 .xlate = irq_domain_xlate_onecell,
353}; 355};
354 356
355static asmlinkage void __exception_irq_entry 357#ifdef CONFIG_PCI_MSI
358static void armada_370_xp_handle_msi_irq(struct pt_regs *regs, bool is_chained)
359{
360 u32 msimask, msinr;
361
362 msimask = readl_relaxed(per_cpu_int_base +
363 ARMADA_370_XP_IN_DRBEL_CAUSE_OFFS)
364 & PCI_MSI_DOORBELL_MASK;
365
366 writel(~msimask, per_cpu_int_base +
367 ARMADA_370_XP_IN_DRBEL_CAUSE_OFFS);
368
369 for (msinr = PCI_MSI_DOORBELL_START;
370 msinr < PCI_MSI_DOORBELL_END; msinr++) {
371 int irq;
372
373 if (!(msimask & BIT(msinr)))
374 continue;
375
376 irq = irq_find_mapping(armada_370_xp_msi_domain,
377 msinr - 16);
378
379 if (is_chained)
380 generic_handle_irq(irq);
381 else
382 handle_IRQ(irq, regs);
383 }
384}
385#else
386static void armada_370_xp_handle_msi_irq(struct pt_regs *r, bool b) {}
387#endif
388
389static void armada_370_xp_mpic_handle_cascade_irq(unsigned int irq,
390 struct irq_desc *desc)
391{
392 struct irq_chip *chip = irq_get_chip(irq);
393 unsigned long irqmap, irqn;
394 unsigned int cascade_irq;
395
396 chained_irq_enter(chip, desc);
397
398 irqmap = readl_relaxed(per_cpu_int_base + ARMADA_375_PPI_CAUSE);
399
400 if (irqmap & BIT(0)) {
401 armada_370_xp_handle_msi_irq(NULL, true);
402 irqmap &= ~BIT(0);
403 }
404
405 for_each_set_bit(irqn, &irqmap, BITS_PER_LONG) {
406 cascade_irq = irq_find_mapping(armada_370_xp_mpic_domain, irqn);
407 generic_handle_irq(cascade_irq);
408 }
409
410 chained_irq_exit(chip, desc);
411}
412
413static void __exception_irq_entry
356armada_370_xp_handle_irq(struct pt_regs *regs) 414armada_370_xp_handle_irq(struct pt_regs *regs)
357{ 415{
358 u32 irqstat, irqnr; 416 u32 irqstat, irqnr;
@@ -372,31 +430,9 @@ armada_370_xp_handle_irq(struct pt_regs *regs)
372 continue; 430 continue;
373 } 431 }
374 432
375#ifdef CONFIG_PCI_MSI
376 /* MSI handling */ 433 /* MSI handling */
377 if (irqnr == 1) { 434 if (irqnr == 1)
378 u32 msimask, msinr; 435 armada_370_xp_handle_msi_irq(regs, false);
379
380 msimask = readl_relaxed(per_cpu_int_base +
381 ARMADA_370_XP_IN_DRBEL_CAUSE_OFFS)
382 & PCI_MSI_DOORBELL_MASK;
383
384 writel(~msimask, per_cpu_int_base +
385 ARMADA_370_XP_IN_DRBEL_CAUSE_OFFS);
386
387 for (msinr = PCI_MSI_DOORBELL_START;
388 msinr < PCI_MSI_DOORBELL_END; msinr++) {
389 int irq;
390
391 if (!(msimask & BIT(msinr)))
392 continue;
393
394 irq = irq_find_mapping(armada_370_xp_msi_domain,
395 msinr - 16);
396 handle_IRQ(irq, regs);
397 }
398 }
399#endif
400 436
401#ifdef CONFIG_SMP 437#ifdef CONFIG_SMP
402 /* IPI Handling */ 438 /* IPI Handling */
@@ -427,6 +463,7 @@ static int __init armada_370_xp_mpic_of_init(struct device_node *node,
427 struct device_node *parent) 463 struct device_node *parent)
428{ 464{
429 struct resource main_int_res, per_cpu_int_res; 465 struct resource main_int_res, per_cpu_int_res;
466 int parent_irq;
430 u32 control; 467 u32 control;
431 468
432 BUG_ON(of_address_to_resource(node, 0, &main_int_res)); 469 BUG_ON(of_address_to_resource(node, 0, &main_int_res));
@@ -455,8 +492,6 @@ static int __init armada_370_xp_mpic_of_init(struct device_node *node,
455 492
456 BUG_ON(!armada_370_xp_mpic_domain); 493 BUG_ON(!armada_370_xp_mpic_domain);
457 494
458 irq_set_default_host(armada_370_xp_mpic_domain);
459
460#ifdef CONFIG_SMP 495#ifdef CONFIG_SMP
461 armada_xp_mpic_smp_cpu_init(); 496 armada_xp_mpic_smp_cpu_init();
462 497
@@ -472,7 +507,14 @@ static int __init armada_370_xp_mpic_of_init(struct device_node *node,
472 507
473 armada_370_xp_msi_init(node, main_int_res.start); 508 armada_370_xp_msi_init(node, main_int_res.start);
474 509
475 set_handle_irq(armada_370_xp_handle_irq); 510 parent_irq = irq_of_parse_and_map(node, 0);
511 if (parent_irq <= 0) {
512 irq_set_default_host(armada_370_xp_mpic_domain);
513 set_handle_irq(armada_370_xp_handle_irq);
514 } else {
515 irq_set_chained_handler(parent_irq,
516 armada_370_xp_mpic_handle_cascade_irq);
517 }
476 518
477 return 0; 519 return 0;
478} 520}
diff --git a/drivers/irqchip/irq-bcm2835.c b/drivers/irqchip/irq-bcm2835.c
index 1693b8e7f26a..5916d6cdafa1 100644
--- a/drivers/irqchip/irq-bcm2835.c
+++ b/drivers/irqchip/irq-bcm2835.c
@@ -95,7 +95,7 @@ struct armctrl_ic {
95}; 95};
96 96
97static struct armctrl_ic intc __read_mostly; 97static struct armctrl_ic intc __read_mostly;
98static asmlinkage void __exception_irq_entry bcm2835_handle_irq( 98static void __exception_irq_entry bcm2835_handle_irq(
99 struct pt_regs *regs); 99 struct pt_regs *regs);
100 100
101static void armctrl_mask_irq(struct irq_data *d) 101static void armctrl_mask_irq(struct irq_data *d)
@@ -196,7 +196,7 @@ static void armctrl_handle_shortcut(int bank, struct pt_regs *regs,
196 handle_IRQ(irq_linear_revmap(intc.domain, irq), regs); 196 handle_IRQ(irq_linear_revmap(intc.domain, irq), regs);
197} 197}
198 198
199static asmlinkage void __exception_irq_entry bcm2835_handle_irq( 199static void __exception_irq_entry bcm2835_handle_irq(
200 struct pt_regs *regs) 200 struct pt_regs *regs)
201{ 201{
202 u32 stat, irq; 202 u32 stat, irq;
diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
index 341c6016812d..531769b2433a 100644
--- a/drivers/irqchip/irq-gic.c
+++ b/drivers/irqchip/irq-gic.c
@@ -50,7 +50,7 @@
50 50
51union gic_base { 51union gic_base {
52 void __iomem *common_base; 52 void __iomem *common_base;
53 void __percpu __iomem **percpu_base; 53 void __percpu * __iomem *percpu_base;
54}; 54};
55 55
56struct gic_chip_data { 56struct gic_chip_data {
@@ -279,7 +279,7 @@ static int gic_set_wake(struct irq_data *d, unsigned int on)
279#define gic_set_wake NULL 279#define gic_set_wake NULL
280#endif 280#endif
281 281
282static asmlinkage void __exception_irq_entry gic_handle_irq(struct pt_regs *regs) 282static void __exception_irq_entry gic_handle_irq(struct pt_regs *regs)
283{ 283{
284 u32 irqstat, irqnr; 284 u32 irqstat, irqnr;
285 struct gic_chip_data *gic = &gic_data[0]; 285 struct gic_chip_data *gic = &gic_data[0];
@@ -648,7 +648,7 @@ static void __init gic_pm_init(struct gic_chip_data *gic)
648#endif 648#endif
649 649
650#ifdef CONFIG_SMP 650#ifdef CONFIG_SMP
651void gic_raise_softirq(const struct cpumask *mask, unsigned int irq) 651static void gic_raise_softirq(const struct cpumask *mask, unsigned int irq)
652{ 652{
653 int cpu; 653 int cpu;
654 unsigned long flags, map = 0; 654 unsigned long flags, map = 0;
@@ -869,7 +869,7 @@ static struct notifier_block gic_cpu_notifier = {
869}; 869};
870#endif 870#endif
871 871
872const struct irq_domain_ops gic_irq_domain_ops = { 872static const struct irq_domain_ops gic_irq_domain_ops = {
873 .map = gic_irq_domain_map, 873 .map = gic_irq_domain_map,
874 .xlate = gic_irq_domain_xlate, 874 .xlate = gic_irq_domain_xlate,
875}; 875};
@@ -974,7 +974,8 @@ void __init gic_init_bases(unsigned int gic_nr, int irq_start,
974#ifdef CONFIG_OF 974#ifdef CONFIG_OF
975static int gic_cnt __initdata; 975static int gic_cnt __initdata;
976 976
977int __init gic_of_init(struct device_node *node, struct device_node *parent) 977static int __init
978gic_of_init(struct device_node *node, struct device_node *parent)
978{ 979{
979 void __iomem *cpu_base; 980 void __iomem *cpu_base;
980 void __iomem *dist_base; 981 void __iomem *dist_base;
diff --git a/drivers/irqchip/irq-metag-ext.c b/drivers/irqchip/irq-metag-ext.c
index 92c41ab4dbfd..2cb474ad8809 100644
--- a/drivers/irqchip/irq-metag-ext.c
+++ b/drivers/irqchip/irq-metag-ext.c
@@ -515,7 +515,7 @@ static int meta_intc_set_affinity(struct irq_data *data,
515 * one cpu (the interrupt code doesn't support it), so we just 515 * one cpu (the interrupt code doesn't support it), so we just
516 * pick the first cpu we find in 'cpumask'. 516 * pick the first cpu we find in 'cpumask'.
517 */ 517 */
518 cpu = cpumask_any(cpumask); 518 cpu = cpumask_any_and(cpumask, cpu_online_mask);
519 thread = cpu_2_hwthread_id[cpu]; 519 thread = cpu_2_hwthread_id[cpu];
520 520
521 metag_out32(TBI_TRIG_VEC(TBID_SIGNUM_TR2(thread)), vec_addr); 521 metag_out32(TBI_TRIG_VEC(TBID_SIGNUM_TR2(thread)), vec_addr);
diff --git a/drivers/irqchip/irq-metag.c b/drivers/irqchip/irq-metag.c
index 8e94d7a3b20d..c16c186d97d3 100644
--- a/drivers/irqchip/irq-metag.c
+++ b/drivers/irqchip/irq-metag.c
@@ -201,7 +201,7 @@ static int metag_internal_irq_set_affinity(struct irq_data *data,
201 * one cpu (the interrupt code doesn't support it), so we just 201 * one cpu (the interrupt code doesn't support it), so we just
202 * pick the first cpu we find in 'cpumask'. 202 * pick the first cpu we find in 'cpumask'.
203 */ 203 */
204 cpu = cpumask_any(cpumask); 204 cpu = cpumask_any_and(cpumask, cpu_online_mask);
205 thread = cpu_2_hwthread_id[cpu]; 205 thread = cpu_2_hwthread_id[cpu];
206 206
207 metag_out32(TBI_TRIG_VEC(TBID_SIGNUM_TR1(thread)), 207 metag_out32(TBI_TRIG_VEC(TBID_SIGNUM_TR1(thread)),
diff --git a/drivers/irqchip/irq-mmp.c b/drivers/irqchip/irq-mmp.c
index 2cb7cd0bc2f5..3c8827fe83f3 100644
--- a/drivers/irqchip/irq-mmp.c
+++ b/drivers/irqchip/irq-mmp.c
@@ -194,8 +194,7 @@ static struct mmp_intc_conf mmp2_conf = {
194 .conf_mask = 0x7f, 194 .conf_mask = 0x7f,
195}; 195};
196 196
197static asmlinkage void __exception_irq_entry 197static void __exception_irq_entry mmp_handle_irq(struct pt_regs *regs)
198mmp_handle_irq(struct pt_regs *regs)
199{ 198{
200 int irq, hwirq; 199 int irq, hwirq;
201 200
@@ -207,8 +206,7 @@ mmp_handle_irq(struct pt_regs *regs)
207 handle_IRQ(irq, regs); 206 handle_IRQ(irq, regs);
208} 207}
209 208
210static asmlinkage void __exception_irq_entry 209static void __exception_irq_entry mmp2_handle_irq(struct pt_regs *regs)
211mmp2_handle_irq(struct pt_regs *regs)
212{ 210{
213 int irq, hwirq; 211 int irq, hwirq;
214 212
diff --git a/drivers/irqchip/irq-moxart.c b/drivers/irqchip/irq-moxart.c
index 5552fc2bf28a..00b3cc908f76 100644
--- a/drivers/irqchip/irq-moxart.c
+++ b/drivers/irqchip/irq-moxart.c
@@ -44,7 +44,7 @@ struct moxart_irq_data {
44 44
45static struct moxart_irq_data intc; 45static struct moxart_irq_data intc;
46 46
47static asmlinkage void __exception_irq_entry handle_irq(struct pt_regs *regs) 47static void __exception_irq_entry handle_irq(struct pt_regs *regs)
48{ 48{
49 u32 irqstat; 49 u32 irqstat;
50 int hwirq; 50 int hwirq;
diff --git a/drivers/irqchip/irq-orion.c b/drivers/irqchip/irq-orion.c
index 8e41be62812e..e25f246cd2fb 100644
--- a/drivers/irqchip/irq-orion.c
+++ b/drivers/irqchip/irq-orion.c
@@ -30,7 +30,7 @@
30 30
31static struct irq_domain *orion_irq_domain; 31static struct irq_domain *orion_irq_domain;
32 32
33static asmlinkage void 33static void
34__exception_irq_entry orion_handle_irq(struct pt_regs *regs) 34__exception_irq_entry orion_handle_irq(struct pt_regs *regs)
35{ 35{
36 struct irq_domain_chip_generic *dgc = orion_irq_domain->gc; 36 struct irq_domain_chip_generic *dgc = orion_irq_domain->gc;
diff --git a/drivers/irqchip/irq-sirfsoc.c b/drivers/irqchip/irq-sirfsoc.c
index 3a070c587ed9..581eefe331ae 100644
--- a/drivers/irqchip/irq-sirfsoc.c
+++ b/drivers/irqchip/irq-sirfsoc.c
@@ -47,7 +47,7 @@ sirfsoc_alloc_gc(void __iomem *base, unsigned int irq_start, unsigned int num)
47 ct->regs.mask = SIRFSOC_INT_RISC_MASK0; 47 ct->regs.mask = SIRFSOC_INT_RISC_MASK0;
48} 48}
49 49
50static asmlinkage void __exception_irq_entry sirfsoc_handle_irq(struct pt_regs *regs) 50static void __exception_irq_entry sirfsoc_handle_irq(struct pt_regs *regs)
51{ 51{
52 void __iomem *base = sirfsoc_irqdomain->host_data; 52 void __iomem *base = sirfsoc_irqdomain->host_data;
53 u32 irqstat, irqnr; 53 u32 irqstat, irqnr;
diff --git a/drivers/irqchip/irq-sun4i.c b/drivers/irqchip/irq-sun4i.c
index a5438d889245..6fcef4a95a18 100644
--- a/drivers/irqchip/irq-sun4i.c
+++ b/drivers/irqchip/irq-sun4i.c
@@ -36,18 +36,16 @@
36static void __iomem *sun4i_irq_base; 36static void __iomem *sun4i_irq_base;
37static struct irq_domain *sun4i_irq_domain; 37static struct irq_domain *sun4i_irq_domain;
38 38
39static asmlinkage void __exception_irq_entry sun4i_handle_irq(struct pt_regs *regs); 39static void __exception_irq_entry sun4i_handle_irq(struct pt_regs *regs);
40 40
41static void sun4i_irq_ack(struct irq_data *irqd) 41static void sun4i_irq_ack(struct irq_data *irqd)
42{ 42{
43 unsigned int irq = irqd_to_hwirq(irqd); 43 unsigned int irq = irqd_to_hwirq(irqd);
44 unsigned int irq_off = irq % 32;
45 int reg = irq / 32;
46 u32 val;
47 44
48 val = readl(sun4i_irq_base + SUN4I_IRQ_PENDING_REG(reg)); 45 if (irq != 0)
49 writel(val | (1 << irq_off), 46 return; /* Only IRQ 0 / the ENMI needs to be acked */
50 sun4i_irq_base + SUN4I_IRQ_PENDING_REG(reg)); 47
48 writel(BIT(0), sun4i_irq_base + SUN4I_IRQ_PENDING_REG(0));
51} 49}
52 50
53static void sun4i_irq_mask(struct irq_data *irqd) 51static void sun4i_irq_mask(struct irq_data *irqd)
@@ -76,16 +74,16 @@ static void sun4i_irq_unmask(struct irq_data *irqd)
76 74
77static struct irq_chip sun4i_irq_chip = { 75static struct irq_chip sun4i_irq_chip = {
78 .name = "sun4i_irq", 76 .name = "sun4i_irq",
79 .irq_ack = sun4i_irq_ack, 77 .irq_eoi = sun4i_irq_ack,
80 .irq_mask = sun4i_irq_mask, 78 .irq_mask = sun4i_irq_mask,
81 .irq_unmask = sun4i_irq_unmask, 79 .irq_unmask = sun4i_irq_unmask,
80 .flags = IRQCHIP_EOI_THREADED | IRQCHIP_EOI_IF_HANDLED,
82}; 81};
83 82
84static int sun4i_irq_map(struct irq_domain *d, unsigned int virq, 83static int sun4i_irq_map(struct irq_domain *d, unsigned int virq,
85 irq_hw_number_t hw) 84 irq_hw_number_t hw)
86{ 85{
87 irq_set_chip_and_handler(virq, &sun4i_irq_chip, 86 irq_set_chip_and_handler(virq, &sun4i_irq_chip, handle_fasteoi_irq);
88 handle_level_irq);
89 set_irq_flags(virq, IRQF_VALID | IRQF_PROBE); 87 set_irq_flags(virq, IRQF_VALID | IRQF_PROBE);
90 88
91 return 0; 89 return 0;
@@ -109,7 +107,7 @@ static int __init sun4i_of_init(struct device_node *node,
109 writel(0, sun4i_irq_base + SUN4I_IRQ_ENABLE_REG(1)); 107 writel(0, sun4i_irq_base + SUN4I_IRQ_ENABLE_REG(1));
110 writel(0, sun4i_irq_base + SUN4I_IRQ_ENABLE_REG(2)); 108 writel(0, sun4i_irq_base + SUN4I_IRQ_ENABLE_REG(2));
111 109
112 /* Mask all the interrupts */ 110 /* Unmask all the interrupts, ENABLE_REG(x) is used for masking */
113 writel(0, sun4i_irq_base + SUN4I_IRQ_MASK_REG(0)); 111 writel(0, sun4i_irq_base + SUN4I_IRQ_MASK_REG(0));
114 writel(0, sun4i_irq_base + SUN4I_IRQ_MASK_REG(1)); 112 writel(0, sun4i_irq_base + SUN4I_IRQ_MASK_REG(1));
115 writel(0, sun4i_irq_base + SUN4I_IRQ_MASK_REG(2)); 113 writel(0, sun4i_irq_base + SUN4I_IRQ_MASK_REG(2));
@@ -134,16 +132,30 @@ static int __init sun4i_of_init(struct device_node *node,
134 132
135 return 0; 133 return 0;
136} 134}
137IRQCHIP_DECLARE(allwinner_sun4i_ic, "allwinner,sun4i-ic", sun4i_of_init); 135IRQCHIP_DECLARE(allwinner_sun4i_ic, "allwinner,sun4i-a10-ic", sun4i_of_init);
138 136
139static asmlinkage void __exception_irq_entry sun4i_handle_irq(struct pt_regs *regs) 137static void __exception_irq_entry sun4i_handle_irq(struct pt_regs *regs)
140{ 138{
141 u32 irq, hwirq; 139 u32 irq, hwirq;
142 140
141 /*
142 * hwirq == 0 can mean one of 3 things:
143 * 1) no more irqs pending
144 * 2) irq 0 pending
145 * 3) spurious irq
146 * So if we immediately get a reading of 0, check the irq-pending reg
147 * to differentiate between 2 and 3. We only do this once to avoid
148 * the extra check in the common case of 1 hapening after having
149 * read the vector-reg once.
150 */
143 hwirq = readl(sun4i_irq_base + SUN4I_IRQ_VECTOR_REG) >> 2; 151 hwirq = readl(sun4i_irq_base + SUN4I_IRQ_VECTOR_REG) >> 2;
144 while (hwirq != 0) { 152 if (hwirq == 0 &&
153 !(readl(sun4i_irq_base + SUN4I_IRQ_PENDING_REG(0)) & BIT(0)))
154 return;
155
156 do {
145 irq = irq_find_mapping(sun4i_irq_domain, hwirq); 157 irq = irq_find_mapping(sun4i_irq_domain, hwirq);
146 handle_IRQ(irq, regs); 158 handle_IRQ(irq, regs);
147 hwirq = readl(sun4i_irq_base + SUN4I_IRQ_VECTOR_REG) >> 2; 159 hwirq = readl(sun4i_irq_base + SUN4I_IRQ_VECTOR_REG) >> 2;
148 } 160 } while (hwirq != 0);
149} 161}
diff --git a/drivers/irqchip/irq-sunxi-nmi.c b/drivers/irqchip/irq-sunxi-nmi.c
new file mode 100644
index 000000000000..12f547a44ae4
--- /dev/null
+++ b/drivers/irqchip/irq-sunxi-nmi.c
@@ -0,0 +1,208 @@
1/*
2 * Allwinner A20/A31 SoCs NMI IRQ chip driver.
3 *
4 * Carlo Caione <carlo.caione@gmail.com>
5 *
6 * This file is licensed under the terms of the GNU General Public
7 * License version 2. This program is licensed "as is" without any
8 * warranty of any kind, whether express or implied.
9 */
10
11#include <linux/bitops.h>
12#include <linux/device.h>
13#include <linux/io.h>
14#include <linux/irq.h>
15#include <linux/interrupt.h>
16#include <linux/irqdomain.h>
17#include <linux/of_irq.h>
18#include <linux/of_address.h>
19#include <linux/of_platform.h>
20#include <linux/irqchip/chained_irq.h>
21#include "irqchip.h"
22
23#define SUNXI_NMI_SRC_TYPE_MASK 0x00000003
24
25enum {
26 SUNXI_SRC_TYPE_LEVEL_LOW = 0,
27 SUNXI_SRC_TYPE_EDGE_FALLING,
28 SUNXI_SRC_TYPE_LEVEL_HIGH,
29 SUNXI_SRC_TYPE_EDGE_RISING,
30};
31
32struct sunxi_sc_nmi_reg_offs {
33 u32 ctrl;
34 u32 pend;
35 u32 enable;
36};
37
38static struct sunxi_sc_nmi_reg_offs sun7i_reg_offs = {
39 .ctrl = 0x00,
40 .pend = 0x04,
41 .enable = 0x08,
42};
43
44static struct sunxi_sc_nmi_reg_offs sun6i_reg_offs = {
45 .ctrl = 0x00,
46 .pend = 0x04,
47 .enable = 0x34,
48};
49
50static inline void sunxi_sc_nmi_write(struct irq_chip_generic *gc, u32 off,
51 u32 val)
52{
53 irq_reg_writel(val, gc->reg_base + off);
54}
55
56static inline u32 sunxi_sc_nmi_read(struct irq_chip_generic *gc, u32 off)
57{
58 return irq_reg_readl(gc->reg_base + off);
59}
60
61static void sunxi_sc_nmi_handle_irq(unsigned int irq, struct irq_desc *desc)
62{
63 struct irq_domain *domain = irq_desc_get_handler_data(desc);
64 struct irq_chip *chip = irq_get_chip(irq);
65 unsigned int virq = irq_find_mapping(domain, 0);
66
67 chained_irq_enter(chip, desc);
68 generic_handle_irq(virq);
69 chained_irq_exit(chip, desc);
70}
71
72static int sunxi_sc_nmi_set_type(struct irq_data *data, unsigned int flow_type)
73{
74 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(data);
75 struct irq_chip_type *ct = gc->chip_types;
76 u32 src_type_reg;
77 u32 ctrl_off = ct->regs.type;
78 unsigned int src_type;
79 unsigned int i;
80
81 irq_gc_lock(gc);
82
83 switch (flow_type & IRQF_TRIGGER_MASK) {
84 case IRQ_TYPE_EDGE_FALLING:
85 src_type = SUNXI_SRC_TYPE_EDGE_FALLING;
86 break;
87 case IRQ_TYPE_EDGE_RISING:
88 src_type = SUNXI_SRC_TYPE_EDGE_RISING;
89 break;
90 case IRQ_TYPE_LEVEL_HIGH:
91 src_type = SUNXI_SRC_TYPE_LEVEL_HIGH;
92 break;
93 case IRQ_TYPE_NONE:
94 case IRQ_TYPE_LEVEL_LOW:
95 src_type = SUNXI_SRC_TYPE_LEVEL_LOW;
96 break;
97 default:
98 irq_gc_unlock(gc);
99 pr_err("%s: Cannot assign multiple trigger modes to IRQ %d.\n",
100 __func__, data->irq);
101 return -EBADR;
102 }
103
104 irqd_set_trigger_type(data, flow_type);
105 irq_setup_alt_chip(data, flow_type);
106
107 for (i = 0; i <= gc->num_ct; i++, ct++)
108 if (ct->type & flow_type)
109 ctrl_off = ct->regs.type;
110
111 src_type_reg = sunxi_sc_nmi_read(gc, ctrl_off);
112 src_type_reg &= ~SUNXI_NMI_SRC_TYPE_MASK;
113 src_type_reg |= src_type;
114 sunxi_sc_nmi_write(gc, ctrl_off, src_type_reg);
115
116 irq_gc_unlock(gc);
117
118 return IRQ_SET_MASK_OK;
119}
120
121static int __init sunxi_sc_nmi_irq_init(struct device_node *node,
122 struct sunxi_sc_nmi_reg_offs *reg_offs)
123{
124 struct irq_domain *domain;
125 struct irq_chip_generic *gc;
126 unsigned int irq;
127 unsigned int clr = IRQ_NOREQUEST | IRQ_NOPROBE | IRQ_NOAUTOEN;
128 int ret;
129
130
131 domain = irq_domain_add_linear(node, 1, &irq_generic_chip_ops, NULL);
132 if (!domain) {
133 pr_err("%s: Could not register interrupt domain.\n", node->name);
134 return -ENOMEM;
135 }
136
137 ret = irq_alloc_domain_generic_chips(domain, 1, 2, node->name,
138 handle_fasteoi_irq, clr, 0,
139 IRQ_GC_INIT_MASK_CACHE);
140 if (ret) {
141 pr_err("%s: Could not allocate generic interrupt chip.\n",
142 node->name);
143 goto fail_irqd_remove;
144 }
145
146 irq = irq_of_parse_and_map(node, 0);
147 if (irq <= 0) {
148 pr_err("%s: unable to parse irq\n", node->name);
149 ret = -EINVAL;
150 goto fail_irqd_remove;
151 }
152
153 gc = irq_get_domain_generic_chip(domain, 0);
154 gc->reg_base = of_iomap(node, 0);
155 if (!gc->reg_base) {
156 pr_err("%s: unable to map resource\n", node->name);
157 ret = -ENOMEM;
158 goto fail_irqd_remove;
159 }
160
161 gc->chip_types[0].type = IRQ_TYPE_LEVEL_MASK;
162 gc->chip_types[0].chip.irq_mask = irq_gc_mask_clr_bit;
163 gc->chip_types[0].chip.irq_unmask = irq_gc_mask_set_bit;
164 gc->chip_types[0].chip.irq_eoi = irq_gc_ack_set_bit;
165 gc->chip_types[0].chip.irq_set_type = sunxi_sc_nmi_set_type;
166 gc->chip_types[0].chip.flags = IRQCHIP_EOI_THREADED | IRQCHIP_EOI_IF_HANDLED;
167 gc->chip_types[0].regs.ack = reg_offs->pend;
168 gc->chip_types[0].regs.mask = reg_offs->enable;
169 gc->chip_types[0].regs.type = reg_offs->ctrl;
170
171 gc->chip_types[1].type = IRQ_TYPE_EDGE_BOTH;
172 gc->chip_types[1].chip.name = gc->chip_types[0].chip.name;
173 gc->chip_types[1].chip.irq_ack = irq_gc_ack_set_bit;
174 gc->chip_types[1].chip.irq_mask = irq_gc_mask_clr_bit;
175 gc->chip_types[1].chip.irq_unmask = irq_gc_mask_set_bit;
176 gc->chip_types[1].chip.irq_set_type = sunxi_sc_nmi_set_type;
177 gc->chip_types[1].regs.ack = reg_offs->pend;
178 gc->chip_types[1].regs.mask = reg_offs->enable;
179 gc->chip_types[1].regs.type = reg_offs->ctrl;
180 gc->chip_types[1].handler = handle_edge_irq;
181
182 sunxi_sc_nmi_write(gc, reg_offs->enable, 0);
183 sunxi_sc_nmi_write(gc, reg_offs->pend, 0x1);
184
185 irq_set_handler_data(irq, domain);
186 irq_set_chained_handler(irq, sunxi_sc_nmi_handle_irq);
187
188 return 0;
189
190fail_irqd_remove:
191 irq_domain_remove(domain);
192
193 return ret;
194}
195
196static int __init sun6i_sc_nmi_irq_init(struct device_node *node,
197 struct device_node *parent)
198{
199 return sunxi_sc_nmi_irq_init(node, &sun6i_reg_offs);
200}
201IRQCHIP_DECLARE(sun6i_sc_nmi, "allwinner,sun6i-a31-sc-nmi", sun6i_sc_nmi_irq_init);
202
203static int __init sun7i_sc_nmi_irq_init(struct device_node *node,
204 struct device_node *parent)
205{
206 return sunxi_sc_nmi_irq_init(node, &sun7i_reg_offs);
207}
208IRQCHIP_DECLARE(sun7i_sc_nmi, "allwinner,sun7i-a20-sc-nmi", sun7i_sc_nmi_irq_init);
diff --git a/drivers/irqchip/irq-vic.c b/drivers/irqchip/irq-vic.c
index 8e21ae0bab46..473f09a74d4d 100644
--- a/drivers/irqchip/irq-vic.c
+++ b/drivers/irqchip/irq-vic.c
@@ -228,7 +228,7 @@ static int handle_one_vic(struct vic_device *vic, struct pt_regs *regs)
228 * Keep iterating over all registered VIC's until there are no pending 228 * Keep iterating over all registered VIC's until there are no pending
229 * interrupts. 229 * interrupts.
230 */ 230 */
231static asmlinkage void __exception_irq_entry vic_handle_irq(struct pt_regs *regs) 231static void __exception_irq_entry vic_handle_irq(struct pt_regs *regs)
232{ 232{
233 int i, handled; 233 int i, handled;
234 234
diff --git a/drivers/irqchip/irq-vt8500.c b/drivers/irqchip/irq-vt8500.c
index 1846e7d66681..eb6e91efdec8 100644
--- a/drivers/irqchip/irq-vt8500.c
+++ b/drivers/irqchip/irq-vt8500.c
@@ -178,8 +178,7 @@ static struct irq_domain_ops vt8500_irq_domain_ops = {
178 .xlate = irq_domain_xlate_onecell, 178 .xlate = irq_domain_xlate_onecell,
179}; 179};
180 180
181static asmlinkage 181static void __exception_irq_entry vt8500_handle_irq(struct pt_regs *regs)
182void __exception_irq_entry vt8500_handle_irq(struct pt_regs *regs)
183{ 182{
184 u32 stat, i; 183 u32 stat, i;
185 int irqnr, virq; 184 int irqnr, virq;
diff --git a/drivers/irqchip/irq-xtensa-mx.c b/drivers/irqchip/irq-xtensa-mx.c
index f693f1bc1348..e1c2f9632893 100644
--- a/drivers/irqchip/irq-xtensa-mx.c
+++ b/drivers/irqchip/irq-xtensa-mx.c
@@ -122,7 +122,7 @@ static int xtensa_mx_irq_retrigger(struct irq_data *d)
122static int xtensa_mx_irq_set_affinity(struct irq_data *d, 122static int xtensa_mx_irq_set_affinity(struct irq_data *d,
123 const struct cpumask *dest, bool force) 123 const struct cpumask *dest, bool force)
124{ 124{
125 unsigned mask = 1u << cpumask_any(dest); 125 unsigned mask = 1u << cpumask_any_and(dest, cpu_online_mask);
126 126
127 set_er(mask, MIROUT(d->hwirq - HW_IRQ_MX_BASE)); 127 set_er(mask, MIROUT(d->hwirq - HW_IRQ_MX_BASE));
128 return 0; 128 return 0;
diff --git a/drivers/irqchip/irq-zevio.c b/drivers/irqchip/irq-zevio.c
index 8ed04c4a43ee..ceb3a4318f73 100644
--- a/drivers/irqchip/irq-zevio.c
+++ b/drivers/irqchip/irq-zevio.c
@@ -50,7 +50,7 @@ static void zevio_irq_ack(struct irq_data *irqd)
50 readl(gc->reg_base + regs->ack); 50 readl(gc->reg_base + regs->ack);
51} 51}
52 52
53static asmlinkage void __exception_irq_entry zevio_handle_irq(struct pt_regs *regs) 53static void __exception_irq_entry zevio_handle_irq(struct pt_regs *regs)
54{ 54{
55 int irqnr; 55 int irqnr;
56 56
diff --git a/drivers/irqchip/irqchip.c b/drivers/irqchip/irqchip.c
index f496afce29de..cad3e2495552 100644
--- a/drivers/irqchip/irqchip.c
+++ b/drivers/irqchip/irqchip.c
@@ -10,8 +10,7 @@
10 10
11#include <linux/init.h> 11#include <linux/init.h>
12#include <linux/of_irq.h> 12#include <linux/of_irq.h>
13 13#include <linux/irqchip.h>
14#include "irqchip.h"
15 14
16/* 15/*
17 * This special of_device_id is the sentinel at the end of the 16 * This special of_device_id is the sentinel at the end of the
diff --git a/drivers/isdn/capi/Kconfig b/drivers/isdn/capi/Kconfig
index f04686580040..9816c51eb5c2 100644
--- a/drivers/isdn/capi/Kconfig
+++ b/drivers/isdn/capi/Kconfig
@@ -16,9 +16,17 @@ config CAPI_TRACE
16 This will increase the size of the kernelcapi module by 20 KB. 16 This will increase the size of the kernelcapi module by 20 KB.
17 If unsure, say Y. 17 If unsure, say Y.
18 18
19config ISDN_CAPI_CAPI20
20 tristate "CAPI2.0 /dev/capi support"
21 help
22 This option will provide the CAPI 2.0 interface to userspace
23 applications via /dev/capi20. Applications should use the
24 standardized libcapi20 to access this functionality. You should say
25 Y/M here.
26
19config ISDN_CAPI_MIDDLEWARE 27config ISDN_CAPI_MIDDLEWARE
20 bool "CAPI2.0 Middleware support" 28 bool "CAPI2.0 Middleware support"
21 depends on TTY 29 depends on ISDN_CAPI_CAPI20 && TTY
22 help 30 help
23 This option will enhance the capabilities of the /dev/capi20 31 This option will enhance the capabilities of the /dev/capi20
24 interface. It will provide a means of moving a data connection, 32 interface. It will provide a means of moving a data connection,
@@ -26,14 +34,6 @@ config ISDN_CAPI_MIDDLEWARE
26 device. If you want to use pppd with pppdcapiplugin to dial up to 34 device. If you want to use pppd with pppdcapiplugin to dial up to
27 your ISP, say Y here. 35 your ISP, say Y here.
28 36
29config ISDN_CAPI_CAPI20
30 tristate "CAPI2.0 /dev/capi support"
31 help
32 This option will provide the CAPI 2.0 interface to userspace
33 applications via /dev/capi20. Applications should use the
34 standardized libcapi20 to access this functionality. You should say
35 Y/M here.
36
37config ISDN_CAPI_CAPIDRV 37config ISDN_CAPI_CAPIDRV
38 tristate "CAPI2.0 capidrv interface support" 38 tristate "CAPI2.0 capidrv interface support"
39 depends on ISDN_I4L 39 depends on ISDN_I4L
diff --git a/drivers/md/Kconfig b/drivers/md/Kconfig
index 9a06fe883766..95ad936e6048 100644
--- a/drivers/md/Kconfig
+++ b/drivers/md/Kconfig
@@ -254,16 +254,6 @@ config DM_THIN_PROVISIONING
254 ---help--- 254 ---help---
255 Provides thin provisioning and snapshots that share a data store. 255 Provides thin provisioning and snapshots that share a data store.
256 256
257config DM_DEBUG_BLOCK_STACK_TRACING
258 boolean "Keep stack trace of persistent data block lock holders"
259 depends on STACKTRACE_SUPPORT && DM_PERSISTENT_DATA
260 select STACKTRACE
261 ---help---
262 Enable this for messages that may help debug problems with the
263 block manager locking used by thin provisioning and caching.
264
265 If unsure, say N.
266
267config DM_CACHE 257config DM_CACHE
268 tristate "Cache target (EXPERIMENTAL)" 258 tristate "Cache target (EXPERIMENTAL)"
269 depends on BLK_DEV_DM 259 depends on BLK_DEV_DM
diff --git a/drivers/md/dm-cache-policy-mq.c b/drivers/md/dm-cache-policy-mq.c
index 1e018e986610..0e385e40909e 100644
--- a/drivers/md/dm-cache-policy-mq.c
+++ b/drivers/md/dm-cache-policy-mq.c
@@ -872,7 +872,7 @@ static void mq_destroy(struct dm_cache_policy *p)
872{ 872{
873 struct mq_policy *mq = to_mq_policy(p); 873 struct mq_policy *mq = to_mq_policy(p);
874 874
875 kfree(mq->table); 875 vfree(mq->table);
876 epool_exit(&mq->cache_pool); 876 epool_exit(&mq->cache_pool);
877 epool_exit(&mq->pre_cache_pool); 877 epool_exit(&mq->pre_cache_pool);
878 kfree(mq); 878 kfree(mq);
@@ -1245,7 +1245,7 @@ static struct dm_cache_policy *mq_create(dm_cblock_t cache_size,
1245 1245
1246 mq->nr_buckets = next_power(from_cblock(cache_size) / 2, 16); 1246 mq->nr_buckets = next_power(from_cblock(cache_size) / 2, 16);
1247 mq->hash_bits = ffs(mq->nr_buckets) - 1; 1247 mq->hash_bits = ffs(mq->nr_buckets) - 1;
1248 mq->table = kzalloc(sizeof(*mq->table) * mq->nr_buckets, GFP_KERNEL); 1248 mq->table = vzalloc(sizeof(*mq->table) * mq->nr_buckets);
1249 if (!mq->table) 1249 if (!mq->table)
1250 goto bad_alloc_table; 1250 goto bad_alloc_table;
1251 1251
diff --git a/drivers/md/dm-cache-target.c b/drivers/md/dm-cache-target.c
index ffd472e015ca..074b9c8e4cf0 100644
--- a/drivers/md/dm-cache-target.c
+++ b/drivers/md/dm-cache-target.c
@@ -289,6 +289,7 @@ struct per_bio_data {
289 bool tick:1; 289 bool tick:1;
290 unsigned req_nr:2; 290 unsigned req_nr:2;
291 struct dm_deferred_entry *all_io_entry; 291 struct dm_deferred_entry *all_io_entry;
292 struct dm_hook_info hook_info;
292 293
293 /* 294 /*
294 * writethrough fields. These MUST remain at the end of this 295 * writethrough fields. These MUST remain at the end of this
@@ -297,7 +298,6 @@ struct per_bio_data {
297 */ 298 */
298 struct cache *cache; 299 struct cache *cache;
299 dm_cblock_t cblock; 300 dm_cblock_t cblock;
300 struct dm_hook_info hook_info;
301 struct dm_bio_details bio_details; 301 struct dm_bio_details bio_details;
302}; 302};
303 303
@@ -671,15 +671,16 @@ static void remap_to_cache(struct cache *cache, struct bio *bio,
671 dm_cblock_t cblock) 671 dm_cblock_t cblock)
672{ 672{
673 sector_t bi_sector = bio->bi_iter.bi_sector; 673 sector_t bi_sector = bio->bi_iter.bi_sector;
674 sector_t block = from_cblock(cblock);
674 675
675 bio->bi_bdev = cache->cache_dev->bdev; 676 bio->bi_bdev = cache->cache_dev->bdev;
676 if (!block_size_is_power_of_two(cache)) 677 if (!block_size_is_power_of_two(cache))
677 bio->bi_iter.bi_sector = 678 bio->bi_iter.bi_sector =
678 (from_cblock(cblock) * cache->sectors_per_block) + 679 (block * cache->sectors_per_block) +
679 sector_div(bi_sector, cache->sectors_per_block); 680 sector_div(bi_sector, cache->sectors_per_block);
680 else 681 else
681 bio->bi_iter.bi_sector = 682 bio->bi_iter.bi_sector =
682 (from_cblock(cblock) << cache->sectors_per_block_shift) | 683 (block << cache->sectors_per_block_shift) |
683 (bi_sector & (cache->sectors_per_block - 1)); 684 (bi_sector & (cache->sectors_per_block - 1));
684} 685}
685 686
@@ -978,12 +979,13 @@ static void issue_copy_real(struct dm_cache_migration *mg)
978 int r; 979 int r;
979 struct dm_io_region o_region, c_region; 980 struct dm_io_region o_region, c_region;
980 struct cache *cache = mg->cache; 981 struct cache *cache = mg->cache;
982 sector_t cblock = from_cblock(mg->cblock);
981 983
982 o_region.bdev = cache->origin_dev->bdev; 984 o_region.bdev = cache->origin_dev->bdev;
983 o_region.count = cache->sectors_per_block; 985 o_region.count = cache->sectors_per_block;
984 986
985 c_region.bdev = cache->cache_dev->bdev; 987 c_region.bdev = cache->cache_dev->bdev;
986 c_region.sector = from_cblock(mg->cblock) * cache->sectors_per_block; 988 c_region.sector = cblock * cache->sectors_per_block;
987 c_region.count = cache->sectors_per_block; 989 c_region.count = cache->sectors_per_block;
988 990
989 if (mg->writeback || mg->demote) { 991 if (mg->writeback || mg->demote) {
@@ -1010,13 +1012,15 @@ static void overwrite_endio(struct bio *bio, int err)
1010 struct per_bio_data *pb = get_per_bio_data(bio, pb_data_size); 1012 struct per_bio_data *pb = get_per_bio_data(bio, pb_data_size);
1011 unsigned long flags; 1013 unsigned long flags;
1012 1014
1015 dm_unhook_bio(&pb->hook_info, bio);
1016
1013 if (err) 1017 if (err)
1014 mg->err = true; 1018 mg->err = true;
1015 1019
1020 mg->requeue_holder = false;
1021
1016 spin_lock_irqsave(&cache->lock, flags); 1022 spin_lock_irqsave(&cache->lock, flags);
1017 list_add_tail(&mg->list, &cache->completed_migrations); 1023 list_add_tail(&mg->list, &cache->completed_migrations);
1018 dm_unhook_bio(&pb->hook_info, bio);
1019 mg->requeue_holder = false;
1020 spin_unlock_irqrestore(&cache->lock, flags); 1024 spin_unlock_irqrestore(&cache->lock, flags);
1021 1025
1022 wake_worker(cache); 1026 wake_worker(cache);
@@ -2461,20 +2465,18 @@ static int cache_map(struct dm_target *ti, struct bio *bio)
2461 bool discarded_block; 2465 bool discarded_block;
2462 struct dm_bio_prison_cell *cell; 2466 struct dm_bio_prison_cell *cell;
2463 struct policy_result lookup_result; 2467 struct policy_result lookup_result;
2464 struct per_bio_data *pb; 2468 struct per_bio_data *pb = init_per_bio_data(bio, pb_data_size);
2465 2469
2466 if (from_oblock(block) > from_oblock(cache->origin_blocks)) { 2470 if (unlikely(from_oblock(block) >= from_oblock(cache->origin_blocks))) {
2467 /* 2471 /*
2468 * This can only occur if the io goes to a partial block at 2472 * This can only occur if the io goes to a partial block at
2469 * the end of the origin device. We don't cache these. 2473 * the end of the origin device. We don't cache these.
2470 * Just remap to the origin and carry on. 2474 * Just remap to the origin and carry on.
2471 */ 2475 */
2472 remap_to_origin_clear_discard(cache, bio, block); 2476 remap_to_origin(cache, bio);
2473 return DM_MAPIO_REMAPPED; 2477 return DM_MAPIO_REMAPPED;
2474 } 2478 }
2475 2479
2476 pb = init_per_bio_data(bio, pb_data_size);
2477
2478 if (bio->bi_rw & (REQ_FLUSH | REQ_FUA | REQ_DISCARD)) { 2480 if (bio->bi_rw & (REQ_FLUSH | REQ_FUA | REQ_DISCARD)) {
2479 defer_bio(cache, bio); 2481 defer_bio(cache, bio);
2480 return DM_MAPIO_SUBMITTED; 2482 return DM_MAPIO_SUBMITTED;
diff --git a/drivers/md/dm-io.c b/drivers/md/dm-io.c
index b2b8a10e8427..3842ac738f98 100644
--- a/drivers/md/dm-io.c
+++ b/drivers/md/dm-io.c
@@ -201,29 +201,28 @@ static void list_dp_init(struct dpages *dp, struct page_list *pl, unsigned offse
201/* 201/*
202 * Functions for getting the pages from a bvec. 202 * Functions for getting the pages from a bvec.
203 */ 203 */
204static void bio_get_page(struct dpages *dp, 204static void bio_get_page(struct dpages *dp, struct page **p,
205 struct page **p, unsigned long *len, unsigned *offset) 205 unsigned long *len, unsigned *offset)
206{ 206{
207 struct bio *bio = dp->context_ptr; 207 struct bio_vec *bvec = dp->context_ptr;
208 struct bio_vec bvec = bio_iovec(bio); 208 *p = bvec->bv_page;
209 *p = bvec.bv_page; 209 *len = bvec->bv_len - dp->context_u;
210 *len = bvec.bv_len; 210 *offset = bvec->bv_offset + dp->context_u;
211 *offset = bvec.bv_offset;
212} 211}
213 212
214static void bio_next_page(struct dpages *dp) 213static void bio_next_page(struct dpages *dp)
215{ 214{
216 struct bio *bio = dp->context_ptr; 215 struct bio_vec *bvec = dp->context_ptr;
217 struct bio_vec bvec = bio_iovec(bio); 216 dp->context_ptr = bvec + 1;
218 217 dp->context_u = 0;
219 bio_advance(bio, bvec.bv_len);
220} 218}
221 219
222static void bio_dp_init(struct dpages *dp, struct bio *bio) 220static void bio_dp_init(struct dpages *dp, struct bio *bio)
223{ 221{
224 dp->get_page = bio_get_page; 222 dp->get_page = bio_get_page;
225 dp->next_page = bio_next_page; 223 dp->next_page = bio_next_page;
226 dp->context_ptr = bio; 224 dp->context_ptr = __bvec_iter_bvec(bio->bi_io_vec, bio->bi_iter);
225 dp->context_u = bio->bi_iter.bi_bvec_done;
227} 226}
228 227
229/* 228/*
diff --git a/drivers/md/dm-mpath.c b/drivers/md/dm-mpath.c
index 6eb9dc9ef8f3..422a9fdeb53e 100644
--- a/drivers/md/dm-mpath.c
+++ b/drivers/md/dm-mpath.c
@@ -1626,8 +1626,11 @@ static int multipath_ioctl(struct dm_target *ti, unsigned int cmd,
1626 /* 1626 /*
1627 * Only pass ioctls through if the device sizes match exactly. 1627 * Only pass ioctls through if the device sizes match exactly.
1628 */ 1628 */
1629 if (!r && ti->len != i_size_read(bdev->bd_inode) >> SECTOR_SHIFT) 1629 if (!bdev || ti->len != i_size_read(bdev->bd_inode) >> SECTOR_SHIFT) {
1630 r = scsi_verify_blk_ioctl(NULL, cmd); 1630 int err = scsi_verify_blk_ioctl(NULL, cmd);
1631 if (err)
1632 r = err;
1633 }
1631 1634
1632 if (r == -ENOTCONN && !fatal_signal_pending(current)) 1635 if (r == -ENOTCONN && !fatal_signal_pending(current))
1633 queue_work(kmultipathd, &m->process_queued_ios); 1636 queue_work(kmultipathd, &m->process_queued_ios);
diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
index f284e0bfb25f..7dfdb5c746d6 100644
--- a/drivers/md/dm-raid1.c
+++ b/drivers/md/dm-raid1.c
@@ -1244,6 +1244,9 @@ static int mirror_end_io(struct dm_target *ti, struct bio *bio, int error)
1244 1244
1245 dm_bio_restore(bd, bio); 1245 dm_bio_restore(bd, bio);
1246 bio_record->details.bi_bdev = NULL; 1246 bio_record->details.bi_bdev = NULL;
1247
1248 atomic_inc(&bio->bi_remaining);
1249
1247 queue_bio(ms, bio, rw); 1250 queue_bio(ms, bio, rw);
1248 return DM_ENDIO_INCOMPLETE; 1251 return DM_ENDIO_INCOMPLETE;
1249 } 1252 }
diff --git a/drivers/md/dm-snap-persistent.c b/drivers/md/dm-snap-persistent.c
index afc3d017de4c..d6e88178d22c 100644
--- a/drivers/md/dm-snap-persistent.c
+++ b/drivers/md/dm-snap-persistent.c
@@ -546,6 +546,9 @@ static int read_exceptions(struct pstore *ps,
546 r = insert_exceptions(ps, area, callback, callback_context, 546 r = insert_exceptions(ps, area, callback, callback_context,
547 &full); 547 &full);
548 548
549 if (!full)
550 memcpy(ps->area, area, ps->store->chunk_size << SECTOR_SHIFT);
551
549 dm_bufio_release(bp); 552 dm_bufio_release(bp);
550 553
551 dm_bufio_forget(client, chunk); 554 dm_bufio_forget(client, chunk);
diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
index 7da347665552..fb9efc829182 100644
--- a/drivers/md/dm-thin-metadata.c
+++ b/drivers/md/dm-thin-metadata.c
@@ -76,7 +76,7 @@
76 76
77#define THIN_SUPERBLOCK_MAGIC 27022010 77#define THIN_SUPERBLOCK_MAGIC 27022010
78#define THIN_SUPERBLOCK_LOCATION 0 78#define THIN_SUPERBLOCK_LOCATION 0
79#define THIN_VERSION 1 79#define THIN_VERSION 2
80#define THIN_METADATA_CACHE_SIZE 64 80#define THIN_METADATA_CACHE_SIZE 64
81#define SECTOR_TO_BLOCK_SHIFT 3 81#define SECTOR_TO_BLOCK_SHIFT 3
82 82
@@ -483,7 +483,7 @@ static int __write_initial_superblock(struct dm_pool_metadata *pmd)
483 483
484 disk_super->data_mapping_root = cpu_to_le64(pmd->root); 484 disk_super->data_mapping_root = cpu_to_le64(pmd->root);
485 disk_super->device_details_root = cpu_to_le64(pmd->details_root); 485 disk_super->device_details_root = cpu_to_le64(pmd->details_root);
486 disk_super->metadata_block_size = cpu_to_le32(THIN_METADATA_BLOCK_SIZE >> SECTOR_SHIFT); 486 disk_super->metadata_block_size = cpu_to_le32(THIN_METADATA_BLOCK_SIZE);
487 disk_super->metadata_nr_blocks = cpu_to_le64(bdev_size >> SECTOR_TO_BLOCK_SHIFT); 487 disk_super->metadata_nr_blocks = cpu_to_le64(bdev_size >> SECTOR_TO_BLOCK_SHIFT);
488 disk_super->data_block_size = cpu_to_le32(pmd->data_block_size); 488 disk_super->data_block_size = cpu_to_le32(pmd->data_block_size);
489 489
@@ -651,7 +651,7 @@ static int __create_persistent_data_objects(struct dm_pool_metadata *pmd, bool f
651{ 651{
652 int r; 652 int r;
653 653
654 pmd->bm = dm_block_manager_create(pmd->bdev, THIN_METADATA_BLOCK_SIZE, 654 pmd->bm = dm_block_manager_create(pmd->bdev, THIN_METADATA_BLOCK_SIZE << SECTOR_SHIFT,
655 THIN_METADATA_CACHE_SIZE, 655 THIN_METADATA_CACHE_SIZE,
656 THIN_MAX_CONCURRENT_LOCKS); 656 THIN_MAX_CONCURRENT_LOCKS);
657 if (IS_ERR(pmd->bm)) { 657 if (IS_ERR(pmd->bm)) {
@@ -1489,6 +1489,23 @@ bool dm_thin_changed_this_transaction(struct dm_thin_device *td)
1489 return r; 1489 return r;
1490} 1490}
1491 1491
1492bool dm_pool_changed_this_transaction(struct dm_pool_metadata *pmd)
1493{
1494 bool r = false;
1495 struct dm_thin_device *td, *tmp;
1496
1497 down_read(&pmd->root_lock);
1498 list_for_each_entry_safe(td, tmp, &pmd->thin_devices, list) {
1499 if (td->changed) {
1500 r = td->changed;
1501 break;
1502 }
1503 }
1504 up_read(&pmd->root_lock);
1505
1506 return r;
1507}
1508
1492bool dm_thin_aborted_changes(struct dm_thin_device *td) 1509bool dm_thin_aborted_changes(struct dm_thin_device *td)
1493{ 1510{
1494 bool r; 1511 bool r;
@@ -1738,3 +1755,38 @@ int dm_pool_register_metadata_threshold(struct dm_pool_metadata *pmd,
1738 1755
1739 return r; 1756 return r;
1740} 1757}
1758
1759int dm_pool_metadata_set_needs_check(struct dm_pool_metadata *pmd)
1760{
1761 int r;
1762 struct dm_block *sblock;
1763 struct thin_disk_superblock *disk_super;
1764
1765 down_write(&pmd->root_lock);
1766 pmd->flags |= THIN_METADATA_NEEDS_CHECK_FLAG;
1767
1768 r = superblock_lock(pmd, &sblock);
1769 if (r) {
1770 DMERR("couldn't read superblock");
1771 goto out;
1772 }
1773
1774 disk_super = dm_block_data(sblock);
1775 disk_super->flags = cpu_to_le32(pmd->flags);
1776
1777 dm_bm_unlock(sblock);
1778out:
1779 up_write(&pmd->root_lock);
1780 return r;
1781}
1782
1783bool dm_pool_metadata_needs_check(struct dm_pool_metadata *pmd)
1784{
1785 bool needs_check;
1786
1787 down_read(&pmd->root_lock);
1788 needs_check = pmd->flags & THIN_METADATA_NEEDS_CHECK_FLAG;
1789 up_read(&pmd->root_lock);
1790
1791 return needs_check;
1792}
diff --git a/drivers/md/dm-thin-metadata.h b/drivers/md/dm-thin-metadata.h
index 9a368567632f..e3c857db195a 100644
--- a/drivers/md/dm-thin-metadata.h
+++ b/drivers/md/dm-thin-metadata.h
@@ -9,16 +9,14 @@
9 9
10#include "persistent-data/dm-block-manager.h" 10#include "persistent-data/dm-block-manager.h"
11#include "persistent-data/dm-space-map.h" 11#include "persistent-data/dm-space-map.h"
12#include "persistent-data/dm-space-map-metadata.h"
12 13
13#define THIN_METADATA_BLOCK_SIZE 4096 14#define THIN_METADATA_BLOCK_SIZE DM_SM_METADATA_BLOCK_SIZE
14 15
15/* 16/*
16 * The metadata device is currently limited in size. 17 * The metadata device is currently limited in size.
17 *
18 * We have one block of index, which can hold 255 index entries. Each
19 * index entry contains allocation info about 16k metadata blocks.
20 */ 18 */
21#define THIN_METADATA_MAX_SECTORS (255 * (1 << 14) * (THIN_METADATA_BLOCK_SIZE / (1 << SECTOR_SHIFT))) 19#define THIN_METADATA_MAX_SECTORS DM_SM_METADATA_MAX_SECTORS
22 20
23/* 21/*
24 * A metadata device larger than 16GB triggers a warning. 22 * A metadata device larger than 16GB triggers a warning.
@@ -27,6 +25,11 @@
27 25
28/*----------------------------------------------------------------*/ 26/*----------------------------------------------------------------*/
29 27
28/*
29 * Thin metadata superblock flags.
30 */
31#define THIN_METADATA_NEEDS_CHECK_FLAG (1 << 0)
32
30struct dm_pool_metadata; 33struct dm_pool_metadata;
31struct dm_thin_device; 34struct dm_thin_device;
32 35
@@ -161,6 +164,8 @@ int dm_thin_remove_block(struct dm_thin_device *td, dm_block_t block);
161 */ 164 */
162bool dm_thin_changed_this_transaction(struct dm_thin_device *td); 165bool dm_thin_changed_this_transaction(struct dm_thin_device *td);
163 166
167bool dm_pool_changed_this_transaction(struct dm_pool_metadata *pmd);
168
164bool dm_thin_aborted_changes(struct dm_thin_device *td); 169bool dm_thin_aborted_changes(struct dm_thin_device *td);
165 170
166int dm_thin_get_highest_mapped_block(struct dm_thin_device *td, 171int dm_thin_get_highest_mapped_block(struct dm_thin_device *td,
@@ -202,6 +207,12 @@ int dm_pool_register_metadata_threshold(struct dm_pool_metadata *pmd,
202 dm_sm_threshold_fn fn, 207 dm_sm_threshold_fn fn,
203 void *context); 208 void *context);
204 209
210/*
211 * Updates the superblock immediately.
212 */
213int dm_pool_metadata_set_needs_check(struct dm_pool_metadata *pmd);
214bool dm_pool_metadata_needs_check(struct dm_pool_metadata *pmd);
215
205/*----------------------------------------------------------------*/ 216/*----------------------------------------------------------------*/
206 217
207#endif 218#endif
diff --git a/drivers/md/dm-thin.c b/drivers/md/dm-thin.c
index faaf944597ab..be70d38745f7 100644
--- a/drivers/md/dm-thin.c
+++ b/drivers/md/dm-thin.c
@@ -130,10 +130,11 @@ static void build_virtual_key(struct dm_thin_device *td, dm_block_t b,
130struct dm_thin_new_mapping; 130struct dm_thin_new_mapping;
131 131
132/* 132/*
133 * The pool runs in 3 modes. Ordered in degraded order for comparisons. 133 * The pool runs in 4 modes. Ordered in degraded order for comparisons.
134 */ 134 */
135enum pool_mode { 135enum pool_mode {
136 PM_WRITE, /* metadata may be changed */ 136 PM_WRITE, /* metadata may be changed */
137 PM_OUT_OF_DATA_SPACE, /* metadata may be changed, though data may not be allocated */
137 PM_READ_ONLY, /* metadata may not be changed */ 138 PM_READ_ONLY, /* metadata may not be changed */
138 PM_FAIL, /* all I/O fails */ 139 PM_FAIL, /* all I/O fails */
139}; 140};
@@ -198,7 +199,6 @@ struct pool {
198}; 199};
199 200
200static enum pool_mode get_pool_mode(struct pool *pool); 201static enum pool_mode get_pool_mode(struct pool *pool);
201static void out_of_data_space(struct pool *pool);
202static void metadata_operation_failed(struct pool *pool, const char *op, int r); 202static void metadata_operation_failed(struct pool *pool, const char *op, int r);
203 203
204/* 204/*
@@ -226,6 +226,7 @@ struct thin_c {
226 226
227 struct pool *pool; 227 struct pool *pool;
228 struct dm_thin_device *td; 228 struct dm_thin_device *td;
229 bool requeue_mode:1;
229}; 230};
230 231
231/*----------------------------------------------------------------*/ 232/*----------------------------------------------------------------*/
@@ -369,14 +370,18 @@ struct dm_thin_endio_hook {
369 struct dm_thin_new_mapping *overwrite_mapping; 370 struct dm_thin_new_mapping *overwrite_mapping;
370}; 371};
371 372
372static void __requeue_bio_list(struct thin_c *tc, struct bio_list *master) 373static void requeue_bio_list(struct thin_c *tc, struct bio_list *master)
373{ 374{
374 struct bio *bio; 375 struct bio *bio;
375 struct bio_list bios; 376 struct bio_list bios;
377 unsigned long flags;
376 378
377 bio_list_init(&bios); 379 bio_list_init(&bios);
380
381 spin_lock_irqsave(&tc->pool->lock, flags);
378 bio_list_merge(&bios, master); 382 bio_list_merge(&bios, master);
379 bio_list_init(master); 383 bio_list_init(master);
384 spin_unlock_irqrestore(&tc->pool->lock, flags);
380 385
381 while ((bio = bio_list_pop(&bios))) { 386 while ((bio = bio_list_pop(&bios))) {
382 struct dm_thin_endio_hook *h = dm_per_bio_data(bio, sizeof(struct dm_thin_endio_hook)); 387 struct dm_thin_endio_hook *h = dm_per_bio_data(bio, sizeof(struct dm_thin_endio_hook));
@@ -391,12 +396,26 @@ static void __requeue_bio_list(struct thin_c *tc, struct bio_list *master)
391static void requeue_io(struct thin_c *tc) 396static void requeue_io(struct thin_c *tc)
392{ 397{
393 struct pool *pool = tc->pool; 398 struct pool *pool = tc->pool;
399
400 requeue_bio_list(tc, &pool->deferred_bios);
401 requeue_bio_list(tc, &pool->retry_on_resume_list);
402}
403
404static void error_retry_list(struct pool *pool)
405{
406 struct bio *bio;
394 unsigned long flags; 407 unsigned long flags;
408 struct bio_list bios;
409
410 bio_list_init(&bios);
395 411
396 spin_lock_irqsave(&pool->lock, flags); 412 spin_lock_irqsave(&pool->lock, flags);
397 __requeue_bio_list(tc, &pool->deferred_bios); 413 bio_list_merge(&bios, &pool->retry_on_resume_list);
398 __requeue_bio_list(tc, &pool->retry_on_resume_list); 414 bio_list_init(&pool->retry_on_resume_list);
399 spin_unlock_irqrestore(&pool->lock, flags); 415 spin_unlock_irqrestore(&pool->lock, flags);
416
417 while ((bio = bio_list_pop(&bios)))
418 bio_io_error(bio);
400} 419}
401 420
402/* 421/*
@@ -925,13 +944,15 @@ static void check_low_water_mark(struct pool *pool, dm_block_t free_blocks)
925 } 944 }
926} 945}
927 946
947static void set_pool_mode(struct pool *pool, enum pool_mode new_mode);
948
928static int alloc_data_block(struct thin_c *tc, dm_block_t *result) 949static int alloc_data_block(struct thin_c *tc, dm_block_t *result)
929{ 950{
930 int r; 951 int r;
931 dm_block_t free_blocks; 952 dm_block_t free_blocks;
932 struct pool *pool = tc->pool; 953 struct pool *pool = tc->pool;
933 954
934 if (get_pool_mode(pool) != PM_WRITE) 955 if (WARN_ON(get_pool_mode(pool) != PM_WRITE))
935 return -EINVAL; 956 return -EINVAL;
936 957
937 r = dm_pool_get_free_block_count(pool->pmd, &free_blocks); 958 r = dm_pool_get_free_block_count(pool->pmd, &free_blocks);
@@ -958,7 +979,7 @@ static int alloc_data_block(struct thin_c *tc, dm_block_t *result)
958 } 979 }
959 980
960 if (!free_blocks) { 981 if (!free_blocks) {
961 out_of_data_space(pool); 982 set_pool_mode(pool, PM_OUT_OF_DATA_SPACE);
962 return -ENOSPC; 983 return -ENOSPC;
963 } 984 }
964 } 985 }
@@ -988,15 +1009,32 @@ static void retry_on_resume(struct bio *bio)
988 spin_unlock_irqrestore(&pool->lock, flags); 1009 spin_unlock_irqrestore(&pool->lock, flags);
989} 1010}
990 1011
991static void handle_unserviceable_bio(struct pool *pool, struct bio *bio) 1012static bool should_error_unserviceable_bio(struct pool *pool)
992{ 1013{
993 /* 1014 enum pool_mode m = get_pool_mode(pool);
994 * When pool is read-only, no cell locking is needed because
995 * nothing is changing.
996 */
997 WARN_ON_ONCE(get_pool_mode(pool) != PM_READ_ONLY);
998 1015
999 if (pool->pf.error_if_no_space) 1016 switch (m) {
1017 case PM_WRITE:
1018 /* Shouldn't get here */
1019 DMERR_LIMIT("bio unserviceable, yet pool is in PM_WRITE mode");
1020 return true;
1021
1022 case PM_OUT_OF_DATA_SPACE:
1023 return pool->pf.error_if_no_space;
1024
1025 case PM_READ_ONLY:
1026 case PM_FAIL:
1027 return true;
1028 default:
1029 /* Shouldn't get here */
1030 DMERR_LIMIT("bio unserviceable, yet pool has an unknown mode");
1031 return true;
1032 }
1033}
1034
1035static void handle_unserviceable_bio(struct pool *pool, struct bio *bio)
1036{
1037 if (should_error_unserviceable_bio(pool))
1000 bio_io_error(bio); 1038 bio_io_error(bio);
1001 else 1039 else
1002 retry_on_resume(bio); 1040 retry_on_resume(bio);
@@ -1007,11 +1045,20 @@ static void retry_bios_on_resume(struct pool *pool, struct dm_bio_prison_cell *c
1007 struct bio *bio; 1045 struct bio *bio;
1008 struct bio_list bios; 1046 struct bio_list bios;
1009 1047
1048 if (should_error_unserviceable_bio(pool)) {
1049 cell_error(pool, cell);
1050 return;
1051 }
1052
1010 bio_list_init(&bios); 1053 bio_list_init(&bios);
1011 cell_release(pool, cell, &bios); 1054 cell_release(pool, cell, &bios);
1012 1055
1013 while ((bio = bio_list_pop(&bios))) 1056 if (should_error_unserviceable_bio(pool))
1014 handle_unserviceable_bio(pool, bio); 1057 while ((bio = bio_list_pop(&bios)))
1058 bio_io_error(bio);
1059 else
1060 while ((bio = bio_list_pop(&bios)))
1061 retry_on_resume(bio);
1015} 1062}
1016 1063
1017static void process_discard(struct thin_c *tc, struct bio *bio) 1064static void process_discard(struct thin_c *tc, struct bio *bio)
@@ -1296,6 +1343,11 @@ static void process_bio_read_only(struct thin_c *tc, struct bio *bio)
1296 } 1343 }
1297} 1344}
1298 1345
1346static void process_bio_success(struct thin_c *tc, struct bio *bio)
1347{
1348 bio_endio(bio, 0);
1349}
1350
1299static void process_bio_fail(struct thin_c *tc, struct bio *bio) 1351static void process_bio_fail(struct thin_c *tc, struct bio *bio)
1300{ 1352{
1301 bio_io_error(bio); 1353 bio_io_error(bio);
@@ -1328,6 +1380,11 @@ static void process_deferred_bios(struct pool *pool)
1328 struct dm_thin_endio_hook *h = dm_per_bio_data(bio, sizeof(struct dm_thin_endio_hook)); 1380 struct dm_thin_endio_hook *h = dm_per_bio_data(bio, sizeof(struct dm_thin_endio_hook));
1329 struct thin_c *tc = h->tc; 1381 struct thin_c *tc = h->tc;
1330 1382
1383 if (tc->requeue_mode) {
1384 bio_endio(bio, DM_ENDIO_REQUEUE);
1385 continue;
1386 }
1387
1331 /* 1388 /*
1332 * If we've got no free new_mapping structs, and processing 1389 * If we've got no free new_mapping structs, and processing
1333 * this bio might require one, we pause until there are some 1390 * this bio might require one, we pause until there are some
@@ -1357,7 +1414,8 @@ static void process_deferred_bios(struct pool *pool)
1357 bio_list_init(&pool->deferred_flush_bios); 1414 bio_list_init(&pool->deferred_flush_bios);
1358 spin_unlock_irqrestore(&pool->lock, flags); 1415 spin_unlock_irqrestore(&pool->lock, flags);
1359 1416
1360 if (bio_list_empty(&bios) && !need_commit_due_to_time(pool)) 1417 if (bio_list_empty(&bios) &&
1418 !(dm_pool_changed_this_transaction(pool->pmd) && need_commit_due_to_time(pool)))
1361 return; 1419 return;
1362 1420
1363 if (commit(pool)) { 1421 if (commit(pool)) {
@@ -1393,51 +1451,134 @@ static void do_waker(struct work_struct *ws)
1393 1451
1394/*----------------------------------------------------------------*/ 1452/*----------------------------------------------------------------*/
1395 1453
1454struct noflush_work {
1455 struct work_struct worker;
1456 struct thin_c *tc;
1457
1458 atomic_t complete;
1459 wait_queue_head_t wait;
1460};
1461
1462static void complete_noflush_work(struct noflush_work *w)
1463{
1464 atomic_set(&w->complete, 1);
1465 wake_up(&w->wait);
1466}
1467
1468static void do_noflush_start(struct work_struct *ws)
1469{
1470 struct noflush_work *w = container_of(ws, struct noflush_work, worker);
1471 w->tc->requeue_mode = true;
1472 requeue_io(w->tc);
1473 complete_noflush_work(w);
1474}
1475
1476static void do_noflush_stop(struct work_struct *ws)
1477{
1478 struct noflush_work *w = container_of(ws, struct noflush_work, worker);
1479 w->tc->requeue_mode = false;
1480 complete_noflush_work(w);
1481}
1482
1483static void noflush_work(struct thin_c *tc, void (*fn)(struct work_struct *))
1484{
1485 struct noflush_work w;
1486
1487 INIT_WORK(&w.worker, fn);
1488 w.tc = tc;
1489 atomic_set(&w.complete, 0);
1490 init_waitqueue_head(&w.wait);
1491
1492 queue_work(tc->pool->wq, &w.worker);
1493
1494 wait_event(w.wait, atomic_read(&w.complete));
1495}
1496
1497/*----------------------------------------------------------------*/
1498
1396static enum pool_mode get_pool_mode(struct pool *pool) 1499static enum pool_mode get_pool_mode(struct pool *pool)
1397{ 1500{
1398 return pool->pf.mode; 1501 return pool->pf.mode;
1399} 1502}
1400 1503
1504static void notify_of_pool_mode_change(struct pool *pool, const char *new_mode)
1505{
1506 dm_table_event(pool->ti->table);
1507 DMINFO("%s: switching pool to %s mode",
1508 dm_device_name(pool->pool_md), new_mode);
1509}
1510
1401static void set_pool_mode(struct pool *pool, enum pool_mode new_mode) 1511static void set_pool_mode(struct pool *pool, enum pool_mode new_mode)
1402{ 1512{
1403 int r; 1513 struct pool_c *pt = pool->ti->private;
1404 enum pool_mode old_mode = pool->pf.mode; 1514 bool needs_check = dm_pool_metadata_needs_check(pool->pmd);
1515 enum pool_mode old_mode = get_pool_mode(pool);
1516
1517 /*
1518 * Never allow the pool to transition to PM_WRITE mode if user
1519 * intervention is required to verify metadata and data consistency.
1520 */
1521 if (new_mode == PM_WRITE && needs_check) {
1522 DMERR("%s: unable to switch pool to write mode until repaired.",
1523 dm_device_name(pool->pool_md));
1524 if (old_mode != new_mode)
1525 new_mode = old_mode;
1526 else
1527 new_mode = PM_READ_ONLY;
1528 }
1529 /*
1530 * If we were in PM_FAIL mode, rollback of metadata failed. We're
1531 * not going to recover without a thin_repair. So we never let the
1532 * pool move out of the old mode.
1533 */
1534 if (old_mode == PM_FAIL)
1535 new_mode = old_mode;
1405 1536
1406 switch (new_mode) { 1537 switch (new_mode) {
1407 case PM_FAIL: 1538 case PM_FAIL:
1408 if (old_mode != new_mode) 1539 if (old_mode != new_mode)
1409 DMERR("%s: switching pool to failure mode", 1540 notify_of_pool_mode_change(pool, "failure");
1410 dm_device_name(pool->pool_md));
1411 dm_pool_metadata_read_only(pool->pmd); 1541 dm_pool_metadata_read_only(pool->pmd);
1412 pool->process_bio = process_bio_fail; 1542 pool->process_bio = process_bio_fail;
1413 pool->process_discard = process_bio_fail; 1543 pool->process_discard = process_bio_fail;
1414 pool->process_prepared_mapping = process_prepared_mapping_fail; 1544 pool->process_prepared_mapping = process_prepared_mapping_fail;
1415 pool->process_prepared_discard = process_prepared_discard_fail; 1545 pool->process_prepared_discard = process_prepared_discard_fail;
1546
1547 error_retry_list(pool);
1416 break; 1548 break;
1417 1549
1418 case PM_READ_ONLY: 1550 case PM_READ_ONLY:
1419 if (old_mode != new_mode) 1551 if (old_mode != new_mode)
1420 DMERR("%s: switching pool to read-only mode", 1552 notify_of_pool_mode_change(pool, "read-only");
1421 dm_device_name(pool->pool_md)); 1553 dm_pool_metadata_read_only(pool->pmd);
1422 r = dm_pool_abort_metadata(pool->pmd); 1554 pool->process_bio = process_bio_read_only;
1423 if (r) { 1555 pool->process_discard = process_bio_success;
1424 DMERR("%s: aborting transaction failed", 1556 pool->process_prepared_mapping = process_prepared_mapping_fail;
1425 dm_device_name(pool->pool_md)); 1557 pool->process_prepared_discard = process_prepared_discard_passdown;
1426 new_mode = PM_FAIL; 1558
1427 set_pool_mode(pool, new_mode); 1559 error_retry_list(pool);
1428 } else { 1560 break;
1429 dm_pool_metadata_read_only(pool->pmd); 1561
1430 pool->process_bio = process_bio_read_only; 1562 case PM_OUT_OF_DATA_SPACE:
1431 pool->process_discard = process_discard; 1563 /*
1432 pool->process_prepared_mapping = process_prepared_mapping_fail; 1564 * Ideally we'd never hit this state; the low water mark
1433 pool->process_prepared_discard = process_prepared_discard_passdown; 1565 * would trigger userland to extend the pool before we
1434 } 1566 * completely run out of data space. However, many small
1567 * IOs to unprovisioned space can consume data space at an
1568 * alarming rate. Adjust your low water mark if you're
1569 * frequently seeing this mode.
1570 */
1571 if (old_mode != new_mode)
1572 notify_of_pool_mode_change(pool, "out-of-data-space");
1573 pool->process_bio = process_bio_read_only;
1574 pool->process_discard = process_discard;
1575 pool->process_prepared_mapping = process_prepared_mapping;
1576 pool->process_prepared_discard = process_prepared_discard_passdown;
1435 break; 1577 break;
1436 1578
1437 case PM_WRITE: 1579 case PM_WRITE:
1438 if (old_mode != new_mode) 1580 if (old_mode != new_mode)
1439 DMINFO("%s: switching pool to write mode", 1581 notify_of_pool_mode_change(pool, "write");
1440 dm_device_name(pool->pool_md));
1441 dm_pool_metadata_read_write(pool->pmd); 1582 dm_pool_metadata_read_write(pool->pmd);
1442 pool->process_bio = process_bio; 1583 pool->process_bio = process_bio;
1443 pool->process_discard = process_discard; 1584 pool->process_discard = process_discard;
@@ -1447,32 +1588,35 @@ static void set_pool_mode(struct pool *pool, enum pool_mode new_mode)
1447 } 1588 }
1448 1589
1449 pool->pf.mode = new_mode; 1590 pool->pf.mode = new_mode;
1591 /*
1592 * The pool mode may have changed, sync it so bind_control_target()
1593 * doesn't cause an unexpected mode transition on resume.
1594 */
1595 pt->adjusted_pf.mode = new_mode;
1450} 1596}
1451 1597
1452/* 1598static void abort_transaction(struct pool *pool)
1453 * Rather than calling set_pool_mode directly, use these which describe the
1454 * reason for mode degradation.
1455 */
1456static void out_of_data_space(struct pool *pool)
1457{ 1599{
1458 DMERR_LIMIT("%s: no free data space available.", 1600 const char *dev_name = dm_device_name(pool->pool_md);
1459 dm_device_name(pool->pool_md)); 1601
1460 set_pool_mode(pool, PM_READ_ONLY); 1602 DMERR_LIMIT("%s: aborting current metadata transaction", dev_name);
1603 if (dm_pool_abort_metadata(pool->pmd)) {
1604 DMERR("%s: failed to abort metadata transaction", dev_name);
1605 set_pool_mode(pool, PM_FAIL);
1606 }
1607
1608 if (dm_pool_metadata_set_needs_check(pool->pmd)) {
1609 DMERR("%s: failed to set 'needs_check' flag in metadata", dev_name);
1610 set_pool_mode(pool, PM_FAIL);
1611 }
1461} 1612}
1462 1613
1463static void metadata_operation_failed(struct pool *pool, const char *op, int r) 1614static void metadata_operation_failed(struct pool *pool, const char *op, int r)
1464{ 1615{
1465 dm_block_t free_blocks;
1466
1467 DMERR_LIMIT("%s: metadata operation '%s' failed: error = %d", 1616 DMERR_LIMIT("%s: metadata operation '%s' failed: error = %d",
1468 dm_device_name(pool->pool_md), op, r); 1617 dm_device_name(pool->pool_md), op, r);
1469 1618
1470 if (r == -ENOSPC && 1619 abort_transaction(pool);
1471 !dm_pool_get_free_metadata_block_count(pool->pmd, &free_blocks) &&
1472 !free_blocks)
1473 DMERR_LIMIT("%s: no free metadata space available.",
1474 dm_device_name(pool->pool_md));
1475
1476 set_pool_mode(pool, PM_READ_ONLY); 1620 set_pool_mode(pool, PM_READ_ONLY);
1477} 1621}
1478 1622
@@ -1523,6 +1667,11 @@ static int thin_bio_map(struct dm_target *ti, struct bio *bio)
1523 1667
1524 thin_hook_bio(tc, bio); 1668 thin_hook_bio(tc, bio);
1525 1669
1670 if (tc->requeue_mode) {
1671 bio_endio(bio, DM_ENDIO_REQUEUE);
1672 return DM_MAPIO_SUBMITTED;
1673 }
1674
1526 if (get_pool_mode(tc->pool) == PM_FAIL) { 1675 if (get_pool_mode(tc->pool) == PM_FAIL) {
1527 bio_io_error(bio); 1676 bio_io_error(bio);
1528 return DM_MAPIO_SUBMITTED; 1677 return DM_MAPIO_SUBMITTED;
@@ -1686,7 +1835,7 @@ static int bind_control_target(struct pool *pool, struct dm_target *ti)
1686 /* 1835 /*
1687 * We want to make sure that a pool in PM_FAIL mode is never upgraded. 1836 * We want to make sure that a pool in PM_FAIL mode is never upgraded.
1688 */ 1837 */
1689 enum pool_mode old_mode = pool->pf.mode; 1838 enum pool_mode old_mode = get_pool_mode(pool);
1690 enum pool_mode new_mode = pt->adjusted_pf.mode; 1839 enum pool_mode new_mode = pt->adjusted_pf.mode;
1691 1840
1692 /* 1841 /*
@@ -1700,16 +1849,6 @@ static int bind_control_target(struct pool *pool, struct dm_target *ti)
1700 pool->pf = pt->adjusted_pf; 1849 pool->pf = pt->adjusted_pf;
1701 pool->low_water_blocks = pt->low_water_blocks; 1850 pool->low_water_blocks = pt->low_water_blocks;
1702 1851
1703 /*
1704 * If we were in PM_FAIL mode, rollback of metadata failed. We're
1705 * not going to recover without a thin_repair. So we never let the
1706 * pool move out of the old mode. On the other hand a PM_READ_ONLY
1707 * may have been due to a lack of metadata or data space, and may
1708 * now work (ie. if the underlying devices have been resized).
1709 */
1710 if (old_mode == PM_FAIL)
1711 new_mode = old_mode;
1712
1713 set_pool_mode(pool, new_mode); 1852 set_pool_mode(pool, new_mode);
1714 1853
1715 return 0; 1854 return 0;
@@ -1999,16 +2138,27 @@ static void metadata_low_callback(void *context)
1999 dm_table_event(pool->ti->table); 2138 dm_table_event(pool->ti->table);
2000} 2139}
2001 2140
2002static sector_t get_metadata_dev_size(struct block_device *bdev) 2141static sector_t get_dev_size(struct block_device *bdev)
2142{
2143 return i_size_read(bdev->bd_inode) >> SECTOR_SHIFT;
2144}
2145
2146static void warn_if_metadata_device_too_big(struct block_device *bdev)
2003{ 2147{
2004 sector_t metadata_dev_size = i_size_read(bdev->bd_inode) >> SECTOR_SHIFT; 2148 sector_t metadata_dev_size = get_dev_size(bdev);
2005 char buffer[BDEVNAME_SIZE]; 2149 char buffer[BDEVNAME_SIZE];
2006 2150
2007 if (metadata_dev_size > THIN_METADATA_MAX_SECTORS_WARNING) { 2151 if (metadata_dev_size > THIN_METADATA_MAX_SECTORS_WARNING)
2008 DMWARN("Metadata device %s is larger than %u sectors: excess space will not be used.", 2152 DMWARN("Metadata device %s is larger than %u sectors: excess space will not be used.",
2009 bdevname(bdev, buffer), THIN_METADATA_MAX_SECTORS); 2153 bdevname(bdev, buffer), THIN_METADATA_MAX_SECTORS);
2010 metadata_dev_size = THIN_METADATA_MAX_SECTORS_WARNING; 2154}
2011 } 2155
2156static sector_t get_metadata_dev_size(struct block_device *bdev)
2157{
2158 sector_t metadata_dev_size = get_dev_size(bdev);
2159
2160 if (metadata_dev_size > THIN_METADATA_MAX_SECTORS)
2161 metadata_dev_size = THIN_METADATA_MAX_SECTORS;
2012 2162
2013 return metadata_dev_size; 2163 return metadata_dev_size;
2014} 2164}
@@ -2017,7 +2167,7 @@ static dm_block_t get_metadata_dev_size_in_blocks(struct block_device *bdev)
2017{ 2167{
2018 sector_t metadata_dev_size = get_metadata_dev_size(bdev); 2168 sector_t metadata_dev_size = get_metadata_dev_size(bdev);
2019 2169
2020 sector_div(metadata_dev_size, THIN_METADATA_BLOCK_SIZE >> SECTOR_SHIFT); 2170 sector_div(metadata_dev_size, THIN_METADATA_BLOCK_SIZE);
2021 2171
2022 return metadata_dev_size; 2172 return metadata_dev_size;
2023} 2173}
@@ -2095,12 +2245,7 @@ static int pool_ctr(struct dm_target *ti, unsigned argc, char **argv)
2095 ti->error = "Error opening metadata block device"; 2245 ti->error = "Error opening metadata block device";
2096 goto out_unlock; 2246 goto out_unlock;
2097 } 2247 }
2098 2248 warn_if_metadata_device_too_big(metadata_dev->bdev);
2099 /*
2100 * Run for the side-effect of possibly issuing a warning if the
2101 * device is too big.
2102 */
2103 (void) get_metadata_dev_size(metadata_dev->bdev);
2104 2249
2105 r = dm_get_device(ti, argv[1], FMODE_READ | FMODE_WRITE, &data_dev); 2250 r = dm_get_device(ti, argv[1], FMODE_READ | FMODE_WRITE, &data_dev);
2106 if (r) { 2251 if (r) {
@@ -2246,6 +2391,12 @@ static int maybe_resize_data_dev(struct dm_target *ti, bool *need_commit)
2246 return -EINVAL; 2391 return -EINVAL;
2247 2392
2248 } else if (data_size > sb_data_size) { 2393 } else if (data_size > sb_data_size) {
2394 if (dm_pool_metadata_needs_check(pool->pmd)) {
2395 DMERR("%s: unable to grow the data device until repaired.",
2396 dm_device_name(pool->pool_md));
2397 return 0;
2398 }
2399
2249 if (sb_data_size) 2400 if (sb_data_size)
2250 DMINFO("%s: growing the data device from %llu to %llu blocks", 2401 DMINFO("%s: growing the data device from %llu to %llu blocks",
2251 dm_device_name(pool->pool_md), 2402 dm_device_name(pool->pool_md),
@@ -2287,6 +2438,13 @@ static int maybe_resize_metadata_dev(struct dm_target *ti, bool *need_commit)
2287 return -EINVAL; 2438 return -EINVAL;
2288 2439
2289 } else if (metadata_dev_size > sb_metadata_dev_size) { 2440 } else if (metadata_dev_size > sb_metadata_dev_size) {
2441 if (dm_pool_metadata_needs_check(pool->pmd)) {
2442 DMERR("%s: unable to grow the metadata device until repaired.",
2443 dm_device_name(pool->pool_md));
2444 return 0;
2445 }
2446
2447 warn_if_metadata_device_too_big(pool->md_dev);
2290 DMINFO("%s: growing the metadata device from %llu to %llu blocks", 2448 DMINFO("%s: growing the metadata device from %llu to %llu blocks",
2291 dm_device_name(pool->pool_md), 2449 dm_device_name(pool->pool_md),
2292 sb_metadata_dev_size, metadata_dev_size); 2450 sb_metadata_dev_size, metadata_dev_size);
@@ -2673,7 +2831,9 @@ static void pool_status(struct dm_target *ti, status_type_t type,
2673 else 2831 else
2674 DMEMIT("- "); 2832 DMEMIT("- ");
2675 2833
2676 if (pool->pf.mode == PM_READ_ONLY) 2834 if (pool->pf.mode == PM_OUT_OF_DATA_SPACE)
2835 DMEMIT("out_of_data_space ");
2836 else if (pool->pf.mode == PM_READ_ONLY)
2677 DMEMIT("ro "); 2837 DMEMIT("ro ");
2678 else 2838 else
2679 DMEMIT("rw "); 2839 DMEMIT("rw ");
@@ -2787,7 +2947,7 @@ static struct target_type pool_target = {
2787 .name = "thin-pool", 2947 .name = "thin-pool",
2788 .features = DM_TARGET_SINGLETON | DM_TARGET_ALWAYS_WRITEABLE | 2948 .features = DM_TARGET_SINGLETON | DM_TARGET_ALWAYS_WRITEABLE |
2789 DM_TARGET_IMMUTABLE, 2949 DM_TARGET_IMMUTABLE,
2790 .version = {1, 10, 0}, 2950 .version = {1, 11, 0},
2791 .module = THIS_MODULE, 2951 .module = THIS_MODULE,
2792 .ctr = pool_ctr, 2952 .ctr = pool_ctr,
2793 .dtr = pool_dtr, 2953 .dtr = pool_dtr,
@@ -2894,6 +3054,7 @@ static int thin_ctr(struct dm_target *ti, unsigned argc, char **argv)
2894 3054
2895 if (get_pool_mode(tc->pool) == PM_FAIL) { 3055 if (get_pool_mode(tc->pool) == PM_FAIL) {
2896 ti->error = "Couldn't open thin device, Pool is in fail mode"; 3056 ti->error = "Couldn't open thin device, Pool is in fail mode";
3057 r = -EINVAL;
2897 goto bad_thin_open; 3058 goto bad_thin_open;
2898 } 3059 }
2899 3060
@@ -2905,7 +3066,7 @@ static int thin_ctr(struct dm_target *ti, unsigned argc, char **argv)
2905 3066
2906 r = dm_set_target_max_io_len(ti, tc->pool->sectors_per_block); 3067 r = dm_set_target_max_io_len(ti, tc->pool->sectors_per_block);
2907 if (r) 3068 if (r)
2908 goto bad_thin_open; 3069 goto bad_target_max_io_len;
2909 3070
2910 ti->num_flush_bios = 1; 3071 ti->num_flush_bios = 1;
2911 ti->flush_supported = true; 3072 ti->flush_supported = true;
@@ -2926,6 +3087,8 @@ static int thin_ctr(struct dm_target *ti, unsigned argc, char **argv)
2926 3087
2927 return 0; 3088 return 0;
2928 3089
3090bad_target_max_io_len:
3091 dm_pool_close_thin_device(tc->td);
2929bad_thin_open: 3092bad_thin_open:
2930 __pool_dec(tc->pool); 3093 __pool_dec(tc->pool);
2931bad_pool_lookup: 3094bad_pool_lookup:
@@ -2986,10 +3149,23 @@ static int thin_endio(struct dm_target *ti, struct bio *bio, int err)
2986 return 0; 3149 return 0;
2987} 3150}
2988 3151
2989static void thin_postsuspend(struct dm_target *ti) 3152static void thin_presuspend(struct dm_target *ti)
2990{ 3153{
3154 struct thin_c *tc = ti->private;
3155
2991 if (dm_noflush_suspending(ti)) 3156 if (dm_noflush_suspending(ti))
2992 requeue_io((struct thin_c *)ti->private); 3157 noflush_work(tc, do_noflush_start);
3158}
3159
3160static void thin_postsuspend(struct dm_target *ti)
3161{
3162 struct thin_c *tc = ti->private;
3163
3164 /*
3165 * The dm_noflush_suspending flag has been cleared by now, so
3166 * unfortunately we must always run this.
3167 */
3168 noflush_work(tc, do_noflush_stop);
2993} 3169}
2994 3170
2995/* 3171/*
@@ -3074,12 +3250,13 @@ static int thin_iterate_devices(struct dm_target *ti,
3074 3250
3075static struct target_type thin_target = { 3251static struct target_type thin_target = {
3076 .name = "thin", 3252 .name = "thin",
3077 .version = {1, 10, 0}, 3253 .version = {1, 11, 0},
3078 .module = THIS_MODULE, 3254 .module = THIS_MODULE,
3079 .ctr = thin_ctr, 3255 .ctr = thin_ctr,
3080 .dtr = thin_dtr, 3256 .dtr = thin_dtr,
3081 .map = thin_map, 3257 .map = thin_map,
3082 .end_io = thin_endio, 3258 .end_io = thin_endio,
3259 .presuspend = thin_presuspend,
3083 .postsuspend = thin_postsuspend, 3260 .postsuspend = thin_postsuspend,
3084 .status = thin_status, 3261 .status = thin_status,
3085 .iterate_devices = thin_iterate_devices, 3262 .iterate_devices = thin_iterate_devices,
diff --git a/drivers/md/persistent-data/Kconfig b/drivers/md/persistent-data/Kconfig
index 19b268795415..0c2dec7aec20 100644
--- a/drivers/md/persistent-data/Kconfig
+++ b/drivers/md/persistent-data/Kconfig
@@ -6,3 +6,13 @@ config DM_PERSISTENT_DATA
6 ---help--- 6 ---help---
7 Library providing immutable on-disk data structure support for 7 Library providing immutable on-disk data structure support for
8 device-mapper targets such as the thin provisioning target. 8 device-mapper targets such as the thin provisioning target.
9
10config DM_DEBUG_BLOCK_STACK_TRACING
11 boolean "Keep stack trace of persistent data block lock holders"
12 depends on STACKTRACE_SUPPORT && DM_PERSISTENT_DATA
13 select STACKTRACE
14 ---help---
15 Enable this for messages that may help debug problems with the
16 block manager locking used by thin provisioning and caching.
17
18 If unsure, say N.
diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
index 536782e3bcb7..786b689bdfc7 100644
--- a/drivers/md/persistent-data/dm-space-map-metadata.c
+++ b/drivers/md/persistent-data/dm-space-map-metadata.c
@@ -91,6 +91,69 @@ struct block_op {
91 dm_block_t block; 91 dm_block_t block;
92}; 92};
93 93
94struct bop_ring_buffer {
95 unsigned begin;
96 unsigned end;
97 struct block_op bops[MAX_RECURSIVE_ALLOCATIONS + 1];
98};
99
100static void brb_init(struct bop_ring_buffer *brb)
101{
102 brb->begin = 0;
103 brb->end = 0;
104}
105
106static bool brb_empty(struct bop_ring_buffer *brb)
107{
108 return brb->begin == brb->end;
109}
110
111static unsigned brb_next(struct bop_ring_buffer *brb, unsigned old)
112{
113 unsigned r = old + 1;
114 return (r >= (sizeof(brb->bops) / sizeof(*brb->bops))) ? 0 : r;
115}
116
117static int brb_push(struct bop_ring_buffer *brb,
118 enum block_op_type type, dm_block_t b)
119{
120 struct block_op *bop;
121 unsigned next = brb_next(brb, brb->end);
122
123 /*
124 * We don't allow the last bop to be filled, this way we can
125 * differentiate between full and empty.
126 */
127 if (next == brb->begin)
128 return -ENOMEM;
129
130 bop = brb->bops + brb->end;
131 bop->type = type;
132 bop->block = b;
133
134 brb->end = next;
135
136 return 0;
137}
138
139static int brb_pop(struct bop_ring_buffer *brb, struct block_op *result)
140{
141 struct block_op *bop;
142
143 if (brb_empty(brb))
144 return -ENODATA;
145
146 bop = brb->bops + brb->begin;
147 result->type = bop->type;
148 result->block = bop->block;
149
150 brb->begin = brb_next(brb, brb->begin);
151
152 return 0;
153}
154
155/*----------------------------------------------------------------*/
156
94struct sm_metadata { 157struct sm_metadata {
95 struct dm_space_map sm; 158 struct dm_space_map sm;
96 159
@@ -101,25 +164,20 @@ struct sm_metadata {
101 164
102 unsigned recursion_count; 165 unsigned recursion_count;
103 unsigned allocated_this_transaction; 166 unsigned allocated_this_transaction;
104 unsigned nr_uncommitted; 167 struct bop_ring_buffer uncommitted;
105 struct block_op uncommitted[MAX_RECURSIVE_ALLOCATIONS];
106 168
107 struct threshold threshold; 169 struct threshold threshold;
108}; 170};
109 171
110static int add_bop(struct sm_metadata *smm, enum block_op_type type, dm_block_t b) 172static int add_bop(struct sm_metadata *smm, enum block_op_type type, dm_block_t b)
111{ 173{
112 struct block_op *op; 174 int r = brb_push(&smm->uncommitted, type, b);
113 175
114 if (smm->nr_uncommitted == MAX_RECURSIVE_ALLOCATIONS) { 176 if (r) {
115 DMERR("too many recursive allocations"); 177 DMERR("too many recursive allocations");
116 return -ENOMEM; 178 return -ENOMEM;
117 } 179 }
118 180
119 op = smm->uncommitted + smm->nr_uncommitted++;
120 op->type = type;
121 op->block = b;
122
123 return 0; 181 return 0;
124} 182}
125 183
@@ -158,11 +216,17 @@ static int out(struct sm_metadata *smm)
158 return -ENOMEM; 216 return -ENOMEM;
159 } 217 }
160 218
161 if (smm->recursion_count == 1 && smm->nr_uncommitted) { 219 if (smm->recursion_count == 1) {
162 while (smm->nr_uncommitted && !r) { 220 while (!brb_empty(&smm->uncommitted)) {
163 smm->nr_uncommitted--; 221 struct block_op bop;
164 r = commit_bop(smm, smm->uncommitted + 222
165 smm->nr_uncommitted); 223 r = brb_pop(&smm->uncommitted, &bop);
224 if (r) {
225 DMERR("bug in bop ring buffer");
226 break;
227 }
228
229 r = commit_bop(smm, &bop);
166 if (r) 230 if (r)
167 break; 231 break;
168 } 232 }
@@ -217,7 +281,8 @@ static int sm_metadata_get_nr_free(struct dm_space_map *sm, dm_block_t *count)
217static int sm_metadata_get_count(struct dm_space_map *sm, dm_block_t b, 281static int sm_metadata_get_count(struct dm_space_map *sm, dm_block_t b,
218 uint32_t *result) 282 uint32_t *result)
219{ 283{
220 int r, i; 284 int r;
285 unsigned i;
221 struct sm_metadata *smm = container_of(sm, struct sm_metadata, sm); 286 struct sm_metadata *smm = container_of(sm, struct sm_metadata, sm);
222 unsigned adjustment = 0; 287 unsigned adjustment = 0;
223 288
@@ -225,8 +290,10 @@ static int sm_metadata_get_count(struct dm_space_map *sm, dm_block_t b,
225 * We may have some uncommitted adjustments to add. This list 290 * We may have some uncommitted adjustments to add. This list
226 * should always be really short. 291 * should always be really short.
227 */ 292 */
228 for (i = 0; i < smm->nr_uncommitted; i++) { 293 for (i = smm->uncommitted.begin;
229 struct block_op *op = smm->uncommitted + i; 294 i != smm->uncommitted.end;
295 i = brb_next(&smm->uncommitted, i)) {
296 struct block_op *op = smm->uncommitted.bops + i;
230 297
231 if (op->block != b) 298 if (op->block != b)
232 continue; 299 continue;
@@ -254,7 +321,8 @@ static int sm_metadata_get_count(struct dm_space_map *sm, dm_block_t b,
254static int sm_metadata_count_is_more_than_one(struct dm_space_map *sm, 321static int sm_metadata_count_is_more_than_one(struct dm_space_map *sm,
255 dm_block_t b, int *result) 322 dm_block_t b, int *result)
256{ 323{
257 int r, i, adjustment = 0; 324 int r, adjustment = 0;
325 unsigned i;
258 struct sm_metadata *smm = container_of(sm, struct sm_metadata, sm); 326 struct sm_metadata *smm = container_of(sm, struct sm_metadata, sm);
259 uint32_t rc; 327 uint32_t rc;
260 328
@@ -262,8 +330,11 @@ static int sm_metadata_count_is_more_than_one(struct dm_space_map *sm,
262 * We may have some uncommitted adjustments to add. This list 330 * We may have some uncommitted adjustments to add. This list
263 * should always be really short. 331 * should always be really short.
264 */ 332 */
265 for (i = 0; i < smm->nr_uncommitted; i++) { 333 for (i = smm->uncommitted.begin;
266 struct block_op *op = smm->uncommitted + i; 334 i != smm->uncommitted.end;
335 i = brb_next(&smm->uncommitted, i)) {
336
337 struct block_op *op = smm->uncommitted.bops + i;
267 338
268 if (op->block != b) 339 if (op->block != b)
269 continue; 340 continue;
@@ -671,7 +742,7 @@ int dm_sm_metadata_create(struct dm_space_map *sm,
671 smm->begin = superblock + 1; 742 smm->begin = superblock + 1;
672 smm->recursion_count = 0; 743 smm->recursion_count = 0;
673 smm->allocated_this_transaction = 0; 744 smm->allocated_this_transaction = 0;
674 smm->nr_uncommitted = 0; 745 brb_init(&smm->uncommitted);
675 threshold_init(&smm->threshold); 746 threshold_init(&smm->threshold);
676 747
677 memcpy(&smm->sm, &bootstrap_ops, sizeof(smm->sm)); 748 memcpy(&smm->sm, &bootstrap_ops, sizeof(smm->sm));
@@ -680,6 +751,8 @@ int dm_sm_metadata_create(struct dm_space_map *sm,
680 if (r) 751 if (r)
681 return r; 752 return r;
682 753
754 if (nr_blocks > DM_SM_METADATA_MAX_BLOCKS)
755 nr_blocks = DM_SM_METADATA_MAX_BLOCKS;
683 r = sm_ll_extend(&smm->ll, nr_blocks); 756 r = sm_ll_extend(&smm->ll, nr_blocks);
684 if (r) 757 if (r)
685 return r; 758 return r;
@@ -713,7 +786,7 @@ int dm_sm_metadata_open(struct dm_space_map *sm,
713 smm->begin = 0; 786 smm->begin = 0;
714 smm->recursion_count = 0; 787 smm->recursion_count = 0;
715 smm->allocated_this_transaction = 0; 788 smm->allocated_this_transaction = 0;
716 smm->nr_uncommitted = 0; 789 brb_init(&smm->uncommitted);
717 threshold_init(&smm->threshold); 790 threshold_init(&smm->threshold);
718 791
719 memcpy(&smm->old_ll, &smm->ll, sizeof(smm->old_ll)); 792 memcpy(&smm->old_ll, &smm->ll, sizeof(smm->old_ll));
diff --git a/drivers/md/persistent-data/dm-space-map-metadata.h b/drivers/md/persistent-data/dm-space-map-metadata.h
index 39bba0801cf2..64df923974d8 100644
--- a/drivers/md/persistent-data/dm-space-map-metadata.h
+++ b/drivers/md/persistent-data/dm-space-map-metadata.h
@@ -9,6 +9,17 @@
9 9
10#include "dm-transaction-manager.h" 10#include "dm-transaction-manager.h"
11 11
12#define DM_SM_METADATA_BLOCK_SIZE (4096 >> SECTOR_SHIFT)
13
14/*
15 * The metadata device is currently limited in size.
16 *
17 * We have one block of index, which can hold 255 index entries. Each
18 * index entry contains allocation info about ~16k metadata blocks.
19 */
20#define DM_SM_METADATA_MAX_BLOCKS (255 * ((1 << 14) - 64))
21#define DM_SM_METADATA_MAX_SECTORS (DM_SM_METADATA_MAX_BLOCKS * DM_SM_METADATA_BLOCK_SIZE)
22
12/* 23/*
13 * Unfortunately we have to use two-phase construction due to the cycle 24 * Unfortunately we have to use two-phase construction due to the cycle
14 * between the tm and sm. 25 * between the tm and sm.
diff --git a/drivers/misc/sgi-xp/xpc_uv.c b/drivers/misc/sgi-xp/xpc_uv.c
index b9e2000969f0..95c894482fdd 100644
--- a/drivers/misc/sgi-xp/xpc_uv.c
+++ b/drivers/misc/sgi-xp/xpc_uv.c
@@ -240,7 +240,7 @@ xpc_create_gru_mq_uv(unsigned int mq_size, int cpu, char *irq_name,
240 240
241 nid = cpu_to_node(cpu); 241 nid = cpu_to_node(cpu);
242 page = alloc_pages_exact_node(nid, 242 page = alloc_pages_exact_node(nid,
243 GFP_KERNEL | __GFP_ZERO | GFP_THISNODE, 243 GFP_KERNEL | __GFP_ZERO | __GFP_THISNODE,
244 pg_order); 244 pg_order);
245 if (page == NULL) { 245 if (page == NULL) {
246 dev_err(xpc_part, "xpc_create_gru_mq_uv() failed to alloc %d " 246 dev_err(xpc_part, "xpc_create_gru_mq_uv() failed to alloc %d "
diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c
index 55cd110a49c4..c204b7d1532c 100644
--- a/drivers/mmc/host/dw_mmc.c
+++ b/drivers/mmc/host/dw_mmc.c
@@ -2607,7 +2607,7 @@ int dw_mci_probe(struct dw_mci *host)
2607 2607
2608 tasklet_init(&host->tasklet, dw_mci_tasklet_func, (unsigned long)host); 2608 tasklet_init(&host->tasklet, dw_mci_tasklet_func, (unsigned long)host);
2609 host->card_workqueue = alloc_workqueue("dw-mci-card", 2609 host->card_workqueue = alloc_workqueue("dw-mci-card",
2610 WQ_MEM_RECLAIM | WQ_NON_REENTRANT, 1); 2610 WQ_MEM_RECLAIM, 1);
2611 if (!host->card_workqueue) { 2611 if (!host->card_workqueue) {
2612 ret = -ENOMEM; 2612 ret = -ENOMEM;
2613 goto err_dmaunmap; 2613 goto err_dmaunmap;
diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index 59eba5d2c685..9715a7ba164a 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -1584,7 +1584,7 @@ read_retry:
1584 } 1584 }
1585 1585
1586 if (mtd->ecc_stats.failed - ecc_failures) { 1586 if (mtd->ecc_stats.failed - ecc_failures) {
1587 if (retry_mode + 1 <= chip->read_retries) { 1587 if (retry_mode + 1 < chip->read_retries) {
1588 retry_mode++; 1588 retry_mode++;
1589 ret = nand_setup_read_retry(mtd, 1589 ret = nand_setup_read_retry(mtd,
1590 retry_mode); 1590 retry_mode);
diff --git a/drivers/mtd/nand/omap2.c b/drivers/mtd/nand/omap2.c
index ef4190a02b7b..bf642ceef681 100644
--- a/drivers/mtd/nand/omap2.c
+++ b/drivers/mtd/nand/omap2.c
@@ -1633,6 +1633,7 @@ static int omap_nand_probe(struct platform_device *pdev)
1633 int i; 1633 int i;
1634 dma_cap_mask_t mask; 1634 dma_cap_mask_t mask;
1635 unsigned sig; 1635 unsigned sig;
1636 unsigned oob_index;
1636 struct resource *res; 1637 struct resource *res;
1637 struct mtd_part_parser_data ppdata = {}; 1638 struct mtd_part_parser_data ppdata = {};
1638 1639
@@ -1826,11 +1827,14 @@ static int omap_nand_probe(struct platform_device *pdev)
1826 (mtd->writesize / 1827 (mtd->writesize /
1827 nand_chip->ecc.size); 1828 nand_chip->ecc.size);
1828 if (nand_chip->options & NAND_BUSWIDTH_16) 1829 if (nand_chip->options & NAND_BUSWIDTH_16)
1829 ecclayout->eccpos[0] = BADBLOCK_MARKER_LENGTH; 1830 oob_index = BADBLOCK_MARKER_LENGTH;
1830 else 1831 else
1831 ecclayout->eccpos[0] = 1; 1832 oob_index = 1;
1832 ecclayout->oobfree->offset = ecclayout->eccpos[0] + 1833 for (i = 0; i < ecclayout->eccbytes; i++, oob_index++)
1833 ecclayout->eccbytes; 1834 ecclayout->eccpos[i] = oob_index;
1835 /* no reserved-marker in ecclayout for this ecc-scheme */
1836 ecclayout->oobfree->offset =
1837 ecclayout->eccpos[ecclayout->eccbytes - 1] + 1;
1834 break; 1838 break;
1835 1839
1836 case OMAP_ECC_BCH4_CODE_HW_DETECTION_SW: 1840 case OMAP_ECC_BCH4_CODE_HW_DETECTION_SW:
@@ -1847,9 +1851,15 @@ static int omap_nand_probe(struct platform_device *pdev)
1847 ecclayout->eccbytes = nand_chip->ecc.bytes * 1851 ecclayout->eccbytes = nand_chip->ecc.bytes *
1848 (mtd->writesize / 1852 (mtd->writesize /
1849 nand_chip->ecc.size); 1853 nand_chip->ecc.size);
1850 ecclayout->eccpos[0] = BADBLOCK_MARKER_LENGTH; 1854 oob_index = BADBLOCK_MARKER_LENGTH;
1851 ecclayout->oobfree->offset = ecclayout->eccpos[0] + 1855 for (i = 0; i < ecclayout->eccbytes; i++, oob_index++) {
1852 ecclayout->eccbytes; 1856 ecclayout->eccpos[i] = oob_index;
1857 if (((i + 1) % nand_chip->ecc.bytes) == 0)
1858 oob_index++;
1859 }
1860 /* include reserved-marker in ecclayout->oobfree calculation */
1861 ecclayout->oobfree->offset = 1 +
1862 ecclayout->eccpos[ecclayout->eccbytes - 1] + 1;
1853 /* software bch library is used for locating errors */ 1863 /* software bch library is used for locating errors */
1854 nand_chip->ecc.priv = nand_bch_init(mtd, 1864 nand_chip->ecc.priv = nand_bch_init(mtd,
1855 nand_chip->ecc.size, 1865 nand_chip->ecc.size,
@@ -1883,9 +1893,12 @@ static int omap_nand_probe(struct platform_device *pdev)
1883 ecclayout->eccbytes = nand_chip->ecc.bytes * 1893 ecclayout->eccbytes = nand_chip->ecc.bytes *
1884 (mtd->writesize / 1894 (mtd->writesize /
1885 nand_chip->ecc.size); 1895 nand_chip->ecc.size);
1886 ecclayout->eccpos[0] = BADBLOCK_MARKER_LENGTH; 1896 oob_index = BADBLOCK_MARKER_LENGTH;
1887 ecclayout->oobfree->offset = ecclayout->eccpos[0] + 1897 for (i = 0; i < ecclayout->eccbytes; i++, oob_index++)
1888 ecclayout->eccbytes; 1898 ecclayout->eccpos[i] = oob_index;
1899 /* reserved marker already included in ecclayout->eccbytes */
1900 ecclayout->oobfree->offset =
1901 ecclayout->eccpos[ecclayout->eccbytes - 1] + 1;
1889 /* This ECC scheme requires ELM H/W block */ 1902 /* This ECC scheme requires ELM H/W block */
1890 if (is_elm_present(info, pdata->elm_of_node, BCH4_ECC) < 0) { 1903 if (is_elm_present(info, pdata->elm_of_node, BCH4_ECC) < 0) {
1891 pr_err("nand: error: could not initialize ELM\n"); 1904 pr_err("nand: error: could not initialize ELM\n");
@@ -1913,9 +1926,15 @@ static int omap_nand_probe(struct platform_device *pdev)
1913 ecclayout->eccbytes = nand_chip->ecc.bytes * 1926 ecclayout->eccbytes = nand_chip->ecc.bytes *
1914 (mtd->writesize / 1927 (mtd->writesize /
1915 nand_chip->ecc.size); 1928 nand_chip->ecc.size);
1916 ecclayout->eccpos[0] = BADBLOCK_MARKER_LENGTH; 1929 oob_index = BADBLOCK_MARKER_LENGTH;
1917 ecclayout->oobfree->offset = ecclayout->eccpos[0] + 1930 for (i = 0; i < ecclayout->eccbytes; i++, oob_index++) {
1918 ecclayout->eccbytes; 1931 ecclayout->eccpos[i] = oob_index;
1932 if (((i + 1) % nand_chip->ecc.bytes) == 0)
1933 oob_index++;
1934 }
1935 /* include reserved-marker in ecclayout->oobfree calculation */
1936 ecclayout->oobfree->offset = 1 +
1937 ecclayout->eccpos[ecclayout->eccbytes - 1] + 1;
1919 /* software bch library is used for locating errors */ 1938 /* software bch library is used for locating errors */
1920 nand_chip->ecc.priv = nand_bch_init(mtd, 1939 nand_chip->ecc.priv = nand_bch_init(mtd,
1921 nand_chip->ecc.size, 1940 nand_chip->ecc.size,
@@ -1956,9 +1975,12 @@ static int omap_nand_probe(struct platform_device *pdev)
1956 ecclayout->eccbytes = nand_chip->ecc.bytes * 1975 ecclayout->eccbytes = nand_chip->ecc.bytes *
1957 (mtd->writesize / 1976 (mtd->writesize /
1958 nand_chip->ecc.size); 1977 nand_chip->ecc.size);
1959 ecclayout->eccpos[0] = BADBLOCK_MARKER_LENGTH; 1978 oob_index = BADBLOCK_MARKER_LENGTH;
1960 ecclayout->oobfree->offset = ecclayout->eccpos[0] + 1979 for (i = 0; i < ecclayout->eccbytes; i++, oob_index++)
1961 ecclayout->eccbytes; 1980 ecclayout->eccpos[i] = oob_index;
1981 /* reserved marker already included in ecclayout->eccbytes */
1982 ecclayout->oobfree->offset =
1983 ecclayout->eccpos[ecclayout->eccbytes - 1] + 1;
1962 break; 1984 break;
1963#else 1985#else
1964 pr_err("nand: error: CONFIG_MTD_NAND_OMAP_BCH not enabled\n"); 1986 pr_err("nand: error: CONFIG_MTD_NAND_OMAP_BCH not enabled\n");
@@ -1972,11 +1994,8 @@ static int omap_nand_probe(struct platform_device *pdev)
1972 goto return_error; 1994 goto return_error;
1973 } 1995 }
1974 1996
1975 /* populate remaining ECC layout data */ 1997 /* all OOB bytes from oobfree->offset till end off OOB are free */
1976 ecclayout->oobfree->length = mtd->oobsize - (BADBLOCK_MARKER_LENGTH + 1998 ecclayout->oobfree->length = mtd->oobsize - ecclayout->oobfree->offset;
1977 ecclayout->eccbytes);
1978 for (i = 1; i < ecclayout->eccbytes; i++)
1979 ecclayout->eccpos[i] = ecclayout->eccpos[0] + i;
1980 /* check if NAND device's OOB is enough to store ECC signatures */ 1999 /* check if NAND device's OOB is enough to store ECC signatures */
1981 if (mtd->oobsize < (ecclayout->eccbytes + BADBLOCK_MARKER_LENGTH)) { 2000 if (mtd->oobsize < (ecclayout->eccbytes + BADBLOCK_MARKER_LENGTH)) {
1982 pr_err("not enough OOB bytes required = %d, available=%d\n", 2001 pr_err("not enough OOB bytes required = %d, available=%d\n",
diff --git a/drivers/mtd/ubi/fastmap.c b/drivers/mtd/ubi/fastmap.c
index ead861307b3c..c5dad652614d 100644
--- a/drivers/mtd/ubi/fastmap.c
+++ b/drivers/mtd/ubi/fastmap.c
@@ -463,8 +463,8 @@ static int scan_pool(struct ubi_device *ubi, struct ubi_attach_info *ai,
463 } 463 }
464 } 464 }
465 if (found_orphan) { 465 if (found_orphan) {
466 kmem_cache_free(ai->aeb_slab_cache, tmp_aeb);
467 list_del(&tmp_aeb->u.list); 466 list_del(&tmp_aeb->u.list);
467 kmem_cache_free(ai->aeb_slab_cache, tmp_aeb);
468 } 468 }
469 469
470 new_aeb = kmem_cache_alloc(ai->aeb_slab_cache, 470 new_aeb = kmem_cache_alloc(ai->aeb_slab_cache,
@@ -846,16 +846,16 @@ fail_bad:
846 ret = UBI_BAD_FASTMAP; 846 ret = UBI_BAD_FASTMAP;
847fail: 847fail:
848 list_for_each_entry_safe(tmp_aeb, _tmp_aeb, &used, u.list) { 848 list_for_each_entry_safe(tmp_aeb, _tmp_aeb, &used, u.list) {
849 kmem_cache_free(ai->aeb_slab_cache, tmp_aeb);
850 list_del(&tmp_aeb->u.list); 849 list_del(&tmp_aeb->u.list);
850 kmem_cache_free(ai->aeb_slab_cache, tmp_aeb);
851 } 851 }
852 list_for_each_entry_safe(tmp_aeb, _tmp_aeb, &eba_orphans, u.list) { 852 list_for_each_entry_safe(tmp_aeb, _tmp_aeb, &eba_orphans, u.list) {
853 kmem_cache_free(ai->aeb_slab_cache, tmp_aeb);
854 list_del(&tmp_aeb->u.list); 853 list_del(&tmp_aeb->u.list);
854 kmem_cache_free(ai->aeb_slab_cache, tmp_aeb);
855 } 855 }
856 list_for_each_entry_safe(tmp_aeb, _tmp_aeb, &free, u.list) { 856 list_for_each_entry_safe(tmp_aeb, _tmp_aeb, &free, u.list) {
857 kmem_cache_free(ai->aeb_slab_cache, tmp_aeb);
858 list_del(&tmp_aeb->u.list); 857 list_del(&tmp_aeb->u.list);
858 kmem_cache_free(ai->aeb_slab_cache, tmp_aeb);
859 } 859 }
860 860
861 return ret; 861 return ret;
diff --git a/drivers/net/bonding/bond_3ad.c b/drivers/net/bonding/bond_3ad.c
index 6d20fbde8d43..dcde56057fe1 100644
--- a/drivers/net/bonding/bond_3ad.c
+++ b/drivers/net/bonding/bond_3ad.c
@@ -181,7 +181,7 @@ static inline int __agg_has_partner(struct aggregator *agg)
181 */ 181 */
182static inline void __disable_port(struct port *port) 182static inline void __disable_port(struct port *port)
183{ 183{
184 bond_set_slave_inactive_flags(port->slave); 184 bond_set_slave_inactive_flags(port->slave, BOND_SLAVE_NOTIFY_LATER);
185} 185}
186 186
187/** 187/**
@@ -193,7 +193,7 @@ static inline void __enable_port(struct port *port)
193 struct slave *slave = port->slave; 193 struct slave *slave = port->slave;
194 194
195 if ((slave->link == BOND_LINK_UP) && IS_UP(slave->dev)) 195 if ((slave->link == BOND_LINK_UP) && IS_UP(slave->dev))
196 bond_set_slave_active_flags(slave); 196 bond_set_slave_active_flags(slave, BOND_SLAVE_NOTIFY_LATER);
197} 197}
198 198
199/** 199/**
@@ -2062,6 +2062,7 @@ void bond_3ad_state_machine_handler(struct work_struct *work)
2062 struct list_head *iter; 2062 struct list_head *iter;
2063 struct slave *slave; 2063 struct slave *slave;
2064 struct port *port; 2064 struct port *port;
2065 bool should_notify_rtnl = BOND_SLAVE_NOTIFY_LATER;
2065 2066
2066 read_lock(&bond->lock); 2067 read_lock(&bond->lock);
2067 rcu_read_lock(); 2068 rcu_read_lock();
@@ -2119,8 +2120,19 @@ void bond_3ad_state_machine_handler(struct work_struct *work)
2119 } 2120 }
2120 2121
2121re_arm: 2122re_arm:
2123 bond_for_each_slave_rcu(bond, slave, iter) {
2124 if (slave->should_notify) {
2125 should_notify_rtnl = BOND_SLAVE_NOTIFY_NOW;
2126 break;
2127 }
2128 }
2122 rcu_read_unlock(); 2129 rcu_read_unlock();
2123 read_unlock(&bond->lock); 2130 read_unlock(&bond->lock);
2131
2132 if (should_notify_rtnl && rtnl_trylock()) {
2133 bond_slave_state_notify(bond);
2134 rtnl_unlock();
2135 }
2124 queue_delayed_work(bond->wq, &bond->ad_work, ad_delta_in_ticks); 2136 queue_delayed_work(bond->wq, &bond->ad_work, ad_delta_in_ticks);
2125} 2137}
2126 2138
diff --git a/drivers/net/bonding/bond_alb.c b/drivers/net/bonding/bond_alb.c
index a2c47476804d..e8f133e926aa 100644
--- a/drivers/net/bonding/bond_alb.c
+++ b/drivers/net/bonding/bond_alb.c
@@ -730,7 +730,7 @@ static struct slave *rlb_choose_channel(struct sk_buff *skb, struct bonding *bon
730 client_info->ntt = 0; 730 client_info->ntt = 0;
731 } 731 }
732 732
733 if (!vlan_get_tag(skb, &client_info->vlan_id)) 733 if (vlan_get_tag(skb, &client_info->vlan_id))
734 client_info->vlan_id = 0; 734 client_info->vlan_id = 0;
735 735
736 if (!client_info->assigned) { 736 if (!client_info->assigned) {
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index 1c6104d3501d..e5628fc725c3 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -829,21 +829,25 @@ void bond_change_active_slave(struct bonding *bond, struct slave *new_active)
829 if (bond_is_lb(bond)) { 829 if (bond_is_lb(bond)) {
830 bond_alb_handle_active_change(bond, new_active); 830 bond_alb_handle_active_change(bond, new_active);
831 if (old_active) 831 if (old_active)
832 bond_set_slave_inactive_flags(old_active); 832 bond_set_slave_inactive_flags(old_active,
833 BOND_SLAVE_NOTIFY_NOW);
833 if (new_active) 834 if (new_active)
834 bond_set_slave_active_flags(new_active); 835 bond_set_slave_active_flags(new_active,
836 BOND_SLAVE_NOTIFY_NOW);
835 } else { 837 } else {
836 rcu_assign_pointer(bond->curr_active_slave, new_active); 838 rcu_assign_pointer(bond->curr_active_slave, new_active);
837 } 839 }
838 840
839 if (bond->params.mode == BOND_MODE_ACTIVEBACKUP) { 841 if (bond->params.mode == BOND_MODE_ACTIVEBACKUP) {
840 if (old_active) 842 if (old_active)
841 bond_set_slave_inactive_flags(old_active); 843 bond_set_slave_inactive_flags(old_active,
844 BOND_SLAVE_NOTIFY_NOW);
842 845
843 if (new_active) { 846 if (new_active) {
844 bool should_notify_peers = false; 847 bool should_notify_peers = false;
845 848
846 bond_set_slave_active_flags(new_active); 849 bond_set_slave_active_flags(new_active,
850 BOND_SLAVE_NOTIFY_NOW);
847 851
848 if (bond->params.fail_over_mac) 852 if (bond->params.fail_over_mac)
849 bond_do_fail_over_mac(bond, new_active, 853 bond_do_fail_over_mac(bond, new_active,
@@ -1193,6 +1197,11 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
1193 return -EBUSY; 1197 return -EBUSY;
1194 } 1198 }
1195 1199
1200 if (bond_dev == slave_dev) {
1201 pr_err("%s: cannot enslave bond to itself.\n", bond_dev->name);
1202 return -EPERM;
1203 }
1204
1196 /* vlan challenged mutual exclusion */ 1205 /* vlan challenged mutual exclusion */
1197 /* no need to lock since we're protected by rtnl_lock */ 1206 /* no need to lock since we're protected by rtnl_lock */
1198 if (slave_dev->features & NETIF_F_VLAN_CHALLENGED) { 1207 if (slave_dev->features & NETIF_F_VLAN_CHALLENGED) {
@@ -1463,14 +1472,15 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
1463 1472
1464 switch (bond->params.mode) { 1473 switch (bond->params.mode) {
1465 case BOND_MODE_ACTIVEBACKUP: 1474 case BOND_MODE_ACTIVEBACKUP:
1466 bond_set_slave_inactive_flags(new_slave); 1475 bond_set_slave_inactive_flags(new_slave,
1476 BOND_SLAVE_NOTIFY_NOW);
1467 break; 1477 break;
1468 case BOND_MODE_8023AD: 1478 case BOND_MODE_8023AD:
1469 /* in 802.3ad mode, the internal mechanism 1479 /* in 802.3ad mode, the internal mechanism
1470 * will activate the slaves in the selected 1480 * will activate the slaves in the selected
1471 * aggregator 1481 * aggregator
1472 */ 1482 */
1473 bond_set_slave_inactive_flags(new_slave); 1483 bond_set_slave_inactive_flags(new_slave, BOND_SLAVE_NOTIFY_NOW);
1474 /* if this is the first slave */ 1484 /* if this is the first slave */
1475 if (!prev_slave) { 1485 if (!prev_slave) {
1476 SLAVE_AD_INFO(new_slave).id = 1; 1486 SLAVE_AD_INFO(new_slave).id = 1;
@@ -1488,7 +1498,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
1488 case BOND_MODE_TLB: 1498 case BOND_MODE_TLB:
1489 case BOND_MODE_ALB: 1499 case BOND_MODE_ALB:
1490 bond_set_active_slave(new_slave); 1500 bond_set_active_slave(new_slave);
1491 bond_set_slave_inactive_flags(new_slave); 1501 bond_set_slave_inactive_flags(new_slave, BOND_SLAVE_NOTIFY_NOW);
1492 break; 1502 break;
1493 default: 1503 default:
1494 pr_debug("This slave is always active in trunk mode\n"); 1504 pr_debug("This slave is always active in trunk mode\n");
@@ -1654,9 +1664,6 @@ static int __bond_release_one(struct net_device *bond_dev,
1654 return -EINVAL; 1664 return -EINVAL;
1655 } 1665 }
1656 1666
1657 /* release the slave from its bond */
1658 bond->slave_cnt--;
1659
1660 bond_sysfs_slave_del(slave); 1667 bond_sysfs_slave_del(slave);
1661 1668
1662 bond_upper_dev_unlink(bond_dev, slave_dev); 1669 bond_upper_dev_unlink(bond_dev, slave_dev);
@@ -1738,6 +1745,7 @@ static int __bond_release_one(struct net_device *bond_dev,
1738 1745
1739 unblock_netpoll_tx(); 1746 unblock_netpoll_tx();
1740 synchronize_rcu(); 1747 synchronize_rcu();
1748 bond->slave_cnt--;
1741 1749
1742 if (!bond_has_slaves(bond)) { 1750 if (!bond_has_slaves(bond)) {
1743 call_netdevice_notifiers(NETDEV_CHANGEADDR, bond->dev); 1751 call_netdevice_notifiers(NETDEV_CHANGEADDR, bond->dev);
@@ -2015,7 +2023,8 @@ static void bond_miimon_commit(struct bonding *bond)
2015 2023
2016 if (bond->params.mode == BOND_MODE_ACTIVEBACKUP || 2024 if (bond->params.mode == BOND_MODE_ACTIVEBACKUP ||
2017 bond->params.mode == BOND_MODE_8023AD) 2025 bond->params.mode == BOND_MODE_8023AD)
2018 bond_set_slave_inactive_flags(slave); 2026 bond_set_slave_inactive_flags(slave,
2027 BOND_SLAVE_NOTIFY_NOW);
2019 2028
2020 pr_info("%s: link status definitely down for interface %s, disabling it\n", 2029 pr_info("%s: link status definitely down for interface %s, disabling it\n",
2021 bond->dev->name, slave->dev->name); 2030 bond->dev->name, slave->dev->name);
@@ -2562,7 +2571,8 @@ static void bond_ab_arp_commit(struct bonding *bond)
2562 slave->link = BOND_LINK_UP; 2571 slave->link = BOND_LINK_UP;
2563 if (bond->current_arp_slave) { 2572 if (bond->current_arp_slave) {
2564 bond_set_slave_inactive_flags( 2573 bond_set_slave_inactive_flags(
2565 bond->current_arp_slave); 2574 bond->current_arp_slave,
2575 BOND_SLAVE_NOTIFY_NOW);
2566 bond->current_arp_slave = NULL; 2576 bond->current_arp_slave = NULL;
2567 } 2577 }
2568 2578
@@ -2582,7 +2592,8 @@ static void bond_ab_arp_commit(struct bonding *bond)
2582 slave->link_failure_count++; 2592 slave->link_failure_count++;
2583 2593
2584 slave->link = BOND_LINK_DOWN; 2594 slave->link = BOND_LINK_DOWN;
2585 bond_set_slave_inactive_flags(slave); 2595 bond_set_slave_inactive_flags(slave,
2596 BOND_SLAVE_NOTIFY_NOW);
2586 2597
2587 pr_info("%s: link status definitely down for interface %s, disabling it\n", 2598 pr_info("%s: link status definitely down for interface %s, disabling it\n",
2588 bond->dev->name, slave->dev->name); 2599 bond->dev->name, slave->dev->name);
@@ -2615,17 +2626,17 @@ do_failover:
2615 2626
2616/* 2627/*
2617 * Send ARP probes for active-backup mode ARP monitor. 2628 * Send ARP probes for active-backup mode ARP monitor.
2629 *
2630 * Called with rcu_read_lock hold.
2618 */ 2631 */
2619static bool bond_ab_arp_probe(struct bonding *bond) 2632static bool bond_ab_arp_probe(struct bonding *bond)
2620{ 2633{
2621 struct slave *slave, *before = NULL, *new_slave = NULL, 2634 struct slave *slave, *before = NULL, *new_slave = NULL,
2622 *curr_arp_slave, *curr_active_slave; 2635 *curr_arp_slave = rcu_dereference(bond->current_arp_slave),
2636 *curr_active_slave = rcu_dereference(bond->curr_active_slave);
2623 struct list_head *iter; 2637 struct list_head *iter;
2624 bool found = false; 2638 bool found = false;
2625 2639 bool should_notify_rtnl = BOND_SLAVE_NOTIFY_LATER;
2626 rcu_read_lock();
2627 curr_arp_slave = rcu_dereference(bond->current_arp_slave);
2628 curr_active_slave = rcu_dereference(bond->curr_active_slave);
2629 2640
2630 if (curr_arp_slave && curr_active_slave) 2641 if (curr_arp_slave && curr_active_slave)
2631 pr_info("PROBE: c_arp %s && cas %s BAD\n", 2642 pr_info("PROBE: c_arp %s && cas %s BAD\n",
@@ -2634,32 +2645,23 @@ static bool bond_ab_arp_probe(struct bonding *bond)
2634 2645
2635 if (curr_active_slave) { 2646 if (curr_active_slave) {
2636 bond_arp_send_all(bond, curr_active_slave); 2647 bond_arp_send_all(bond, curr_active_slave);
2637 rcu_read_unlock(); 2648 return should_notify_rtnl;
2638 return true;
2639 } 2649 }
2640 rcu_read_unlock();
2641 2650
2642 /* if we don't have a curr_active_slave, search for the next available 2651 /* if we don't have a curr_active_slave, search for the next available
2643 * backup slave from the current_arp_slave and make it the candidate 2652 * backup slave from the current_arp_slave and make it the candidate
2644 * for becoming the curr_active_slave 2653 * for becoming the curr_active_slave
2645 */ 2654 */
2646 2655
2647 if (!rtnl_trylock())
2648 return false;
2649 /* curr_arp_slave might have gone away */
2650 curr_arp_slave = ACCESS_ONCE(bond->current_arp_slave);
2651
2652 if (!curr_arp_slave) { 2656 if (!curr_arp_slave) {
2653 curr_arp_slave = bond_first_slave(bond); 2657 curr_arp_slave = bond_first_slave_rcu(bond);
2654 if (!curr_arp_slave) { 2658 if (!curr_arp_slave)
2655 rtnl_unlock(); 2659 return should_notify_rtnl;
2656 return true;
2657 }
2658 } 2660 }
2659 2661
2660 bond_set_slave_inactive_flags(curr_arp_slave); 2662 bond_set_slave_inactive_flags(curr_arp_slave, BOND_SLAVE_NOTIFY_LATER);
2661 2663
2662 bond_for_each_slave(bond, slave, iter) { 2664 bond_for_each_slave_rcu(bond, slave, iter) {
2663 if (!found && !before && IS_UP(slave->dev)) 2665 if (!found && !before && IS_UP(slave->dev))
2664 before = slave; 2666 before = slave;
2665 2667
@@ -2677,7 +2679,8 @@ static bool bond_ab_arp_probe(struct bonding *bond)
2677 if (slave->link_failure_count < UINT_MAX) 2679 if (slave->link_failure_count < UINT_MAX)
2678 slave->link_failure_count++; 2680 slave->link_failure_count++;
2679 2681
2680 bond_set_slave_inactive_flags(slave); 2682 bond_set_slave_inactive_flags(slave,
2683 BOND_SLAVE_NOTIFY_LATER);
2681 2684
2682 pr_info("%s: backup interface %s is now down.\n", 2685 pr_info("%s: backup interface %s is now down.\n",
2683 bond->dev->name, slave->dev->name); 2686 bond->dev->name, slave->dev->name);
@@ -2689,26 +2692,31 @@ static bool bond_ab_arp_probe(struct bonding *bond)
2689 if (!new_slave && before) 2692 if (!new_slave && before)
2690 new_slave = before; 2693 new_slave = before;
2691 2694
2692 if (!new_slave) { 2695 if (!new_slave)
2693 rtnl_unlock(); 2696 goto check_state;
2694 return true;
2695 }
2696 2697
2697 new_slave->link = BOND_LINK_BACK; 2698 new_slave->link = BOND_LINK_BACK;
2698 bond_set_slave_active_flags(new_slave); 2699 bond_set_slave_active_flags(new_slave, BOND_SLAVE_NOTIFY_LATER);
2699 bond_arp_send_all(bond, new_slave); 2700 bond_arp_send_all(bond, new_slave);
2700 new_slave->jiffies = jiffies; 2701 new_slave->jiffies = jiffies;
2701 rcu_assign_pointer(bond->current_arp_slave, new_slave); 2702 rcu_assign_pointer(bond->current_arp_slave, new_slave);
2702 rtnl_unlock();
2703 2703
2704 return true; 2704check_state:
2705 bond_for_each_slave_rcu(bond, slave, iter) {
2706 if (slave->should_notify) {
2707 should_notify_rtnl = BOND_SLAVE_NOTIFY_NOW;
2708 break;
2709 }
2710 }
2711 return should_notify_rtnl;
2705} 2712}
2706 2713
2707static void bond_activebackup_arp_mon(struct work_struct *work) 2714static void bond_activebackup_arp_mon(struct work_struct *work)
2708{ 2715{
2709 struct bonding *bond = container_of(work, struct bonding, 2716 struct bonding *bond = container_of(work, struct bonding,
2710 arp_work.work); 2717 arp_work.work);
2711 bool should_notify_peers = false, should_commit = false; 2718 bool should_notify_peers = false;
2719 bool should_notify_rtnl = false;
2712 int delta_in_ticks; 2720 int delta_in_ticks;
2713 2721
2714 delta_in_ticks = msecs_to_jiffies(bond->params.arp_interval); 2722 delta_in_ticks = msecs_to_jiffies(bond->params.arp_interval);
@@ -2717,11 +2725,12 @@ static void bond_activebackup_arp_mon(struct work_struct *work)
2717 goto re_arm; 2725 goto re_arm;
2718 2726
2719 rcu_read_lock(); 2727 rcu_read_lock();
2728
2720 should_notify_peers = bond_should_notify_peers(bond); 2729 should_notify_peers = bond_should_notify_peers(bond);
2721 should_commit = bond_ab_arp_inspect(bond);
2722 rcu_read_unlock();
2723 2730
2724 if (should_commit) { 2731 if (bond_ab_arp_inspect(bond)) {
2732 rcu_read_unlock();
2733
2725 /* Race avoidance with bond_close flush of workqueue */ 2734 /* Race avoidance with bond_close flush of workqueue */
2726 if (!rtnl_trylock()) { 2735 if (!rtnl_trylock()) {
2727 delta_in_ticks = 1; 2736 delta_in_ticks = 1;
@@ -2730,23 +2739,28 @@ static void bond_activebackup_arp_mon(struct work_struct *work)
2730 } 2739 }
2731 2740
2732 bond_ab_arp_commit(bond); 2741 bond_ab_arp_commit(bond);
2742
2733 rtnl_unlock(); 2743 rtnl_unlock();
2744 rcu_read_lock();
2734 } 2745 }
2735 2746
2736 if (!bond_ab_arp_probe(bond)) { 2747 should_notify_rtnl = bond_ab_arp_probe(bond);
2737 /* rtnl locking failed, re-arm */ 2748 rcu_read_unlock();
2738 delta_in_ticks = 1;
2739 should_notify_peers = false;
2740 }
2741 2749
2742re_arm: 2750re_arm:
2743 if (bond->params.arp_interval) 2751 if (bond->params.arp_interval)
2744 queue_delayed_work(bond->wq, &bond->arp_work, delta_in_ticks); 2752 queue_delayed_work(bond->wq, &bond->arp_work, delta_in_ticks);
2745 2753
2746 if (should_notify_peers) { 2754 if (should_notify_peers || should_notify_rtnl) {
2747 if (!rtnl_trylock()) 2755 if (!rtnl_trylock())
2748 return; 2756 return;
2749 call_netdevice_notifiers(NETDEV_NOTIFY_PEERS, bond->dev); 2757
2758 if (should_notify_peers)
2759 call_netdevice_notifiers(NETDEV_NOTIFY_PEERS,
2760 bond->dev);
2761 if (should_notify_rtnl)
2762 bond_slave_state_notify(bond);
2763
2750 rtnl_unlock(); 2764 rtnl_unlock();
2751 } 2765 }
2752} 2766}
@@ -3046,9 +3060,11 @@ static int bond_open(struct net_device *bond_dev)
3046 bond_for_each_slave(bond, slave, iter) { 3060 bond_for_each_slave(bond, slave, iter) {
3047 if ((bond->params.mode == BOND_MODE_ACTIVEBACKUP) 3061 if ((bond->params.mode == BOND_MODE_ACTIVEBACKUP)
3048 && (slave != bond->curr_active_slave)) { 3062 && (slave != bond->curr_active_slave)) {
3049 bond_set_slave_inactive_flags(slave); 3063 bond_set_slave_inactive_flags(slave,
3064 BOND_SLAVE_NOTIFY_NOW);
3050 } else { 3065 } else {
3051 bond_set_slave_active_flags(slave); 3066 bond_set_slave_active_flags(slave,
3067 BOND_SLAVE_NOTIFY_NOW);
3052 } 3068 }
3053 } 3069 }
3054 read_unlock(&bond->curr_slave_lock); 3070 read_unlock(&bond->curr_slave_lock);
diff --git a/drivers/net/bonding/bond_options.c b/drivers/net/bonding/bond_options.c
index c37878432717..298c26509095 100644
--- a/drivers/net/bonding/bond_options.c
+++ b/drivers/net/bonding/bond_options.c
@@ -121,6 +121,7 @@ static struct bond_opt_value bond_resend_igmp_tbl[] = {
121static struct bond_opt_value bond_lp_interval_tbl[] = { 121static struct bond_opt_value bond_lp_interval_tbl[] = {
122 { "minval", 1, BOND_VALFLAG_MIN | BOND_VALFLAG_DEFAULT}, 122 { "minval", 1, BOND_VALFLAG_MIN | BOND_VALFLAG_DEFAULT},
123 { "maxval", INT_MAX, BOND_VALFLAG_MAX}, 123 { "maxval", INT_MAX, BOND_VALFLAG_MAX},
124 { NULL, -1, 0},
124}; 125};
125 126
126static struct bond_option bond_opts[] = { 127static struct bond_option bond_opts[] = {
diff --git a/drivers/net/bonding/bonding.h b/drivers/net/bonding/bonding.h
index 86ccfb9f71cc..2b0fdec695f7 100644
--- a/drivers/net/bonding/bonding.h
+++ b/drivers/net/bonding/bonding.h
@@ -195,7 +195,8 @@ struct slave {
195 s8 new_link; 195 s8 new_link;
196 u8 backup:1, /* indicates backup slave. Value corresponds with 196 u8 backup:1, /* indicates backup slave. Value corresponds with
197 BOND_STATE_ACTIVE and BOND_STATE_BACKUP */ 197 BOND_STATE_ACTIVE and BOND_STATE_BACKUP */
198 inactive:1; /* indicates inactive slave */ 198 inactive:1, /* indicates inactive slave */
199 should_notify:1; /* indicateds whether the state changed */
199 u8 duplex; 200 u8 duplex;
200 u32 original_mtu; 201 u32 original_mtu;
201 u32 link_failure_count; 202 u32 link_failure_count;
@@ -303,6 +304,24 @@ static inline void bond_set_backup_slave(struct slave *slave)
303 } 304 }
304} 305}
305 306
307static inline void bond_set_slave_state(struct slave *slave,
308 int slave_state, bool notify)
309{
310 if (slave->backup == slave_state)
311 return;
312
313 slave->backup = slave_state;
314 if (notify) {
315 rtmsg_ifinfo(RTM_NEWLINK, slave->dev, 0, GFP_KERNEL);
316 slave->should_notify = 0;
317 } else {
318 if (slave->should_notify)
319 slave->should_notify = 0;
320 else
321 slave->should_notify = 1;
322 }
323}
324
306static inline void bond_slave_state_change(struct bonding *bond) 325static inline void bond_slave_state_change(struct bonding *bond)
307{ 326{
308 struct list_head *iter; 327 struct list_head *iter;
@@ -316,6 +335,19 @@ static inline void bond_slave_state_change(struct bonding *bond)
316 } 335 }
317} 336}
318 337
338static inline void bond_slave_state_notify(struct bonding *bond)
339{
340 struct list_head *iter;
341 struct slave *tmp;
342
343 bond_for_each_slave(bond, tmp, iter) {
344 if (tmp->should_notify) {
345 rtmsg_ifinfo(RTM_NEWLINK, tmp->dev, 0, GFP_KERNEL);
346 tmp->should_notify = 0;
347 }
348 }
349}
350
319static inline int bond_slave_state(struct slave *slave) 351static inline int bond_slave_state(struct slave *slave)
320{ 352{
321 return slave->backup; 353 return slave->backup;
@@ -343,6 +375,9 @@ static inline bool bond_is_active_slave(struct slave *slave)
343#define BOND_ARP_VALIDATE_ALL (BOND_ARP_VALIDATE_ACTIVE | \ 375#define BOND_ARP_VALIDATE_ALL (BOND_ARP_VALIDATE_ACTIVE | \
344 BOND_ARP_VALIDATE_BACKUP) 376 BOND_ARP_VALIDATE_BACKUP)
345 377
378#define BOND_SLAVE_NOTIFY_NOW true
379#define BOND_SLAVE_NOTIFY_LATER false
380
346static inline int slave_do_arp_validate(struct bonding *bond, 381static inline int slave_do_arp_validate(struct bonding *bond,
347 struct slave *slave) 382 struct slave *slave)
348{ 383{
@@ -394,17 +429,19 @@ static inline void bond_netpoll_send_skb(const struct slave *slave,
394} 429}
395#endif 430#endif
396 431
397static inline void bond_set_slave_inactive_flags(struct slave *slave) 432static inline void bond_set_slave_inactive_flags(struct slave *slave,
433 bool notify)
398{ 434{
399 if (!bond_is_lb(slave->bond)) 435 if (!bond_is_lb(slave->bond))
400 bond_set_backup_slave(slave); 436 bond_set_slave_state(slave, BOND_STATE_BACKUP, notify);
401 if (!slave->bond->params.all_slaves_active) 437 if (!slave->bond->params.all_slaves_active)
402 slave->inactive = 1; 438 slave->inactive = 1;
403} 439}
404 440
405static inline void bond_set_slave_active_flags(struct slave *slave) 441static inline void bond_set_slave_active_flags(struct slave *slave,
442 bool notify)
406{ 443{
407 bond_set_active_slave(slave); 444 bond_set_slave_state(slave, BOND_STATE_ACTIVE, notify);
408 slave->inactive = 0; 445 slave->inactive = 0;
409} 446}
410 447
diff --git a/drivers/net/can/flexcan.c b/drivers/net/can/flexcan.c
index 320bef2dba42..61376abdab39 100644
--- a/drivers/net/can/flexcan.c
+++ b/drivers/net/can/flexcan.c
@@ -144,6 +144,8 @@
144 144
145#define FLEXCAN_MB_CODE_MASK (0xf0ffffff) 145#define FLEXCAN_MB_CODE_MASK (0xf0ffffff)
146 146
147#define FLEXCAN_TIMEOUT_US (50)
148
147/* 149/*
148 * FLEXCAN hardware feature flags 150 * FLEXCAN hardware feature flags
149 * 151 *
@@ -262,6 +264,22 @@ static inline void flexcan_write(u32 val, void __iomem *addr)
262} 264}
263#endif 265#endif
264 266
267static inline int flexcan_transceiver_enable(const struct flexcan_priv *priv)
268{
269 if (!priv->reg_xceiver)
270 return 0;
271
272 return regulator_enable(priv->reg_xceiver);
273}
274
275static inline int flexcan_transceiver_disable(const struct flexcan_priv *priv)
276{
277 if (!priv->reg_xceiver)
278 return 0;
279
280 return regulator_disable(priv->reg_xceiver);
281}
282
265static inline int flexcan_has_and_handle_berr(const struct flexcan_priv *priv, 283static inline int flexcan_has_and_handle_berr(const struct flexcan_priv *priv,
266 u32 reg_esr) 284 u32 reg_esr)
267{ 285{
@@ -269,26 +287,95 @@ static inline int flexcan_has_and_handle_berr(const struct flexcan_priv *priv,
269 (reg_esr & FLEXCAN_ESR_ERR_BUS); 287 (reg_esr & FLEXCAN_ESR_ERR_BUS);
270} 288}
271 289
272static inline void flexcan_chip_enable(struct flexcan_priv *priv) 290static int flexcan_chip_enable(struct flexcan_priv *priv)
273{ 291{
274 struct flexcan_regs __iomem *regs = priv->base; 292 struct flexcan_regs __iomem *regs = priv->base;
293 unsigned int timeout = FLEXCAN_TIMEOUT_US / 10;
275 u32 reg; 294 u32 reg;
276 295
277 reg = flexcan_read(&regs->mcr); 296 reg = flexcan_read(&regs->mcr);
278 reg &= ~FLEXCAN_MCR_MDIS; 297 reg &= ~FLEXCAN_MCR_MDIS;
279 flexcan_write(reg, &regs->mcr); 298 flexcan_write(reg, &regs->mcr);
280 299
281 udelay(10); 300 while (timeout-- && (flexcan_read(&regs->mcr) & FLEXCAN_MCR_LPM_ACK))
301 usleep_range(10, 20);
302
303 if (flexcan_read(&regs->mcr) & FLEXCAN_MCR_LPM_ACK)
304 return -ETIMEDOUT;
305
306 return 0;
282} 307}
283 308
284static inline void flexcan_chip_disable(struct flexcan_priv *priv) 309static int flexcan_chip_disable(struct flexcan_priv *priv)
285{ 310{
286 struct flexcan_regs __iomem *regs = priv->base; 311 struct flexcan_regs __iomem *regs = priv->base;
312 unsigned int timeout = FLEXCAN_TIMEOUT_US / 10;
287 u32 reg; 313 u32 reg;
288 314
289 reg = flexcan_read(&regs->mcr); 315 reg = flexcan_read(&regs->mcr);
290 reg |= FLEXCAN_MCR_MDIS; 316 reg |= FLEXCAN_MCR_MDIS;
291 flexcan_write(reg, &regs->mcr); 317 flexcan_write(reg, &regs->mcr);
318
319 while (timeout-- && !(flexcan_read(&regs->mcr) & FLEXCAN_MCR_LPM_ACK))
320 usleep_range(10, 20);
321
322 if (!(flexcan_read(&regs->mcr) & FLEXCAN_MCR_LPM_ACK))
323 return -ETIMEDOUT;
324
325 return 0;
326}
327
328static int flexcan_chip_freeze(struct flexcan_priv *priv)
329{
330 struct flexcan_regs __iomem *regs = priv->base;
331 unsigned int timeout = 1000 * 1000 * 10 / priv->can.bittiming.bitrate;
332 u32 reg;
333
334 reg = flexcan_read(&regs->mcr);
335 reg |= FLEXCAN_MCR_HALT;
336 flexcan_write(reg, &regs->mcr);
337
338 while (timeout-- && !(flexcan_read(&regs->mcr) & FLEXCAN_MCR_FRZ_ACK))
339 usleep_range(100, 200);
340
341 if (!(flexcan_read(&regs->mcr) & FLEXCAN_MCR_FRZ_ACK))
342 return -ETIMEDOUT;
343
344 return 0;
345}
346
347static int flexcan_chip_unfreeze(struct flexcan_priv *priv)
348{
349 struct flexcan_regs __iomem *regs = priv->base;
350 unsigned int timeout = FLEXCAN_TIMEOUT_US / 10;
351 u32 reg;
352
353 reg = flexcan_read(&regs->mcr);
354 reg &= ~FLEXCAN_MCR_HALT;
355 flexcan_write(reg, &regs->mcr);
356
357 while (timeout-- && (flexcan_read(&regs->mcr) & FLEXCAN_MCR_FRZ_ACK))
358 usleep_range(10, 20);
359
360 if (flexcan_read(&regs->mcr) & FLEXCAN_MCR_FRZ_ACK)
361 return -ETIMEDOUT;
362
363 return 0;
364}
365
366static int flexcan_chip_softreset(struct flexcan_priv *priv)
367{
368 struct flexcan_regs __iomem *regs = priv->base;
369 unsigned int timeout = FLEXCAN_TIMEOUT_US / 10;
370
371 flexcan_write(FLEXCAN_MCR_SOFTRST, &regs->mcr);
372 while (timeout-- && (flexcan_read(&regs->mcr) & FLEXCAN_MCR_SOFTRST))
373 usleep_range(10, 20);
374
375 if (flexcan_read(&regs->mcr) & FLEXCAN_MCR_SOFTRST)
376 return -ETIMEDOUT;
377
378 return 0;
292} 379}
293 380
294static int flexcan_get_berr_counter(const struct net_device *dev, 381static int flexcan_get_berr_counter(const struct net_device *dev,
@@ -709,19 +796,14 @@ static int flexcan_chip_start(struct net_device *dev)
709 u32 reg_mcr, reg_ctrl; 796 u32 reg_mcr, reg_ctrl;
710 797
711 /* enable module */ 798 /* enable module */
712 flexcan_chip_enable(priv); 799 err = flexcan_chip_enable(priv);
800 if (err)
801 return err;
713 802
714 /* soft reset */ 803 /* soft reset */
715 flexcan_write(FLEXCAN_MCR_SOFTRST, &regs->mcr); 804 err = flexcan_chip_softreset(priv);
716 udelay(10); 805 if (err)
717 806 goto out_chip_disable;
718 reg_mcr = flexcan_read(&regs->mcr);
719 if (reg_mcr & FLEXCAN_MCR_SOFTRST) {
720 netdev_err(dev, "Failed to softreset can module (mcr=0x%08x)\n",
721 reg_mcr);
722 err = -ENODEV;
723 goto out;
724 }
725 807
726 flexcan_set_bittiming(dev); 808 flexcan_set_bittiming(dev);
727 809
@@ -788,16 +870,14 @@ static int flexcan_chip_start(struct net_device *dev)
788 if (priv->devtype_data->features & FLEXCAN_HAS_V10_FEATURES) 870 if (priv->devtype_data->features & FLEXCAN_HAS_V10_FEATURES)
789 flexcan_write(0x0, &regs->rxfgmask); 871 flexcan_write(0x0, &regs->rxfgmask);
790 872
791 if (priv->reg_xceiver) { 873 err = flexcan_transceiver_enable(priv);
792 err = regulator_enable(priv->reg_xceiver); 874 if (err)
793 if (err) 875 goto out_chip_disable;
794 goto out;
795 }
796 876
797 /* synchronize with the can bus */ 877 /* synchronize with the can bus */
798 reg_mcr = flexcan_read(&regs->mcr); 878 err = flexcan_chip_unfreeze(priv);
799 reg_mcr &= ~FLEXCAN_MCR_HALT; 879 if (err)
800 flexcan_write(reg_mcr, &regs->mcr); 880 goto out_transceiver_disable;
801 881
802 priv->can.state = CAN_STATE_ERROR_ACTIVE; 882 priv->can.state = CAN_STATE_ERROR_ACTIVE;
803 883
@@ -810,7 +890,9 @@ static int flexcan_chip_start(struct net_device *dev)
810 890
811 return 0; 891 return 0;
812 892
813 out: 893 out_transceiver_disable:
894 flexcan_transceiver_disable(priv);
895 out_chip_disable:
814 flexcan_chip_disable(priv); 896 flexcan_chip_disable(priv);
815 return err; 897 return err;
816} 898}
@@ -825,18 +907,17 @@ static void flexcan_chip_stop(struct net_device *dev)
825{ 907{
826 struct flexcan_priv *priv = netdev_priv(dev); 908 struct flexcan_priv *priv = netdev_priv(dev);
827 struct flexcan_regs __iomem *regs = priv->base; 909 struct flexcan_regs __iomem *regs = priv->base;
828 u32 reg; 910
911 /* freeze + disable module */
912 flexcan_chip_freeze(priv);
913 flexcan_chip_disable(priv);
829 914
830 /* Disable all interrupts */ 915 /* Disable all interrupts */
831 flexcan_write(0, &regs->imask1); 916 flexcan_write(0, &regs->imask1);
917 flexcan_write(priv->reg_ctrl_default & ~FLEXCAN_CTRL_ERR_ALL,
918 &regs->ctrl);
832 919
833 /* Disable + halt module */ 920 flexcan_transceiver_disable(priv);
834 reg = flexcan_read(&regs->mcr);
835 reg |= FLEXCAN_MCR_MDIS | FLEXCAN_MCR_HALT;
836 flexcan_write(reg, &regs->mcr);
837
838 if (priv->reg_xceiver)
839 regulator_disable(priv->reg_xceiver);
840 priv->can.state = CAN_STATE_STOPPED; 921 priv->can.state = CAN_STATE_STOPPED;
841 922
842 return; 923 return;
@@ -866,7 +947,7 @@ static int flexcan_open(struct net_device *dev)
866 /* start chip and queuing */ 947 /* start chip and queuing */
867 err = flexcan_chip_start(dev); 948 err = flexcan_chip_start(dev);
868 if (err) 949 if (err)
869 goto out_close; 950 goto out_free_irq;
870 951
871 can_led_event(dev, CAN_LED_EVENT_OPEN); 952 can_led_event(dev, CAN_LED_EVENT_OPEN);
872 953
@@ -875,6 +956,8 @@ static int flexcan_open(struct net_device *dev)
875 956
876 return 0; 957 return 0;
877 958
959 out_free_irq:
960 free_irq(dev->irq, dev);
878 out_close: 961 out_close:
879 close_candev(dev); 962 close_candev(dev);
880 out_disable_per: 963 out_disable_per:
@@ -945,12 +1028,16 @@ static int register_flexcandev(struct net_device *dev)
945 goto out_disable_ipg; 1028 goto out_disable_ipg;
946 1029
947 /* select "bus clock", chip must be disabled */ 1030 /* select "bus clock", chip must be disabled */
948 flexcan_chip_disable(priv); 1031 err = flexcan_chip_disable(priv);
1032 if (err)
1033 goto out_disable_per;
949 reg = flexcan_read(&regs->ctrl); 1034 reg = flexcan_read(&regs->ctrl);
950 reg |= FLEXCAN_CTRL_CLK_SRC; 1035 reg |= FLEXCAN_CTRL_CLK_SRC;
951 flexcan_write(reg, &regs->ctrl); 1036 flexcan_write(reg, &regs->ctrl);
952 1037
953 flexcan_chip_enable(priv); 1038 err = flexcan_chip_enable(priv);
1039 if (err)
1040 goto out_chip_disable;
954 1041
955 /* set freeze, halt and activate FIFO, restrict register access */ 1042 /* set freeze, halt and activate FIFO, restrict register access */
956 reg = flexcan_read(&regs->mcr); 1043 reg = flexcan_read(&regs->mcr);
@@ -967,14 +1054,15 @@ static int register_flexcandev(struct net_device *dev)
967 if (!(reg & FLEXCAN_MCR_FEN)) { 1054 if (!(reg & FLEXCAN_MCR_FEN)) {
968 netdev_err(dev, "Could not enable RX FIFO, unsupported core\n"); 1055 netdev_err(dev, "Could not enable RX FIFO, unsupported core\n");
969 err = -ENODEV; 1056 err = -ENODEV;
970 goto out_disable_per; 1057 goto out_chip_disable;
971 } 1058 }
972 1059
973 err = register_candev(dev); 1060 err = register_candev(dev);
974 1061
975 out_disable_per:
976 /* disable core and turn off clocks */ 1062 /* disable core and turn off clocks */
1063 out_chip_disable:
977 flexcan_chip_disable(priv); 1064 flexcan_chip_disable(priv);
1065 out_disable_per:
978 clk_disable_unprepare(priv->clk_per); 1066 clk_disable_unprepare(priv->clk_per);
979 out_disable_ipg: 1067 out_disable_ipg:
980 clk_disable_unprepare(priv->clk_ipg); 1068 clk_disable_unprepare(priv->clk_ipg);
@@ -1104,9 +1192,10 @@ static int flexcan_probe(struct platform_device *pdev)
1104static int flexcan_remove(struct platform_device *pdev) 1192static int flexcan_remove(struct platform_device *pdev)
1105{ 1193{
1106 struct net_device *dev = platform_get_drvdata(pdev); 1194 struct net_device *dev = platform_get_drvdata(pdev);
1195 struct flexcan_priv *priv = netdev_priv(dev);
1107 1196
1108 unregister_flexcandev(dev); 1197 unregister_flexcandev(dev);
1109 1198 netif_napi_del(&priv->napi);
1110 free_candev(dev); 1199 free_candev(dev);
1111 1200
1112 return 0; 1201 return 0;
@@ -1117,8 +1206,11 @@ static int flexcan_suspend(struct device *device)
1117{ 1206{
1118 struct net_device *dev = dev_get_drvdata(device); 1207 struct net_device *dev = dev_get_drvdata(device);
1119 struct flexcan_priv *priv = netdev_priv(dev); 1208 struct flexcan_priv *priv = netdev_priv(dev);
1209 int err;
1120 1210
1121 flexcan_chip_disable(priv); 1211 err = flexcan_chip_disable(priv);
1212 if (err)
1213 return err;
1122 1214
1123 if (netif_running(dev)) { 1215 if (netif_running(dev)) {
1124 netif_stop_queue(dev); 1216 netif_stop_queue(dev);
@@ -1139,9 +1231,7 @@ static int flexcan_resume(struct device *device)
1139 netif_device_attach(dev); 1231 netif_device_attach(dev);
1140 netif_start_queue(dev); 1232 netif_start_queue(dev);
1141 } 1233 }
1142 flexcan_chip_enable(priv); 1234 return flexcan_chip_enable(priv);
1143
1144 return 0;
1145} 1235}
1146#endif /* CONFIG_PM_SLEEP */ 1236#endif /* CONFIG_PM_SLEEP */
1147 1237
diff --git a/drivers/net/ethernet/atheros/alx/main.c b/drivers/net/ethernet/atheros/alx/main.c
index 2e45f6ec1bf0..380d24922049 100644
--- a/drivers/net/ethernet/atheros/alx/main.c
+++ b/drivers/net/ethernet/atheros/alx/main.c
@@ -1248,19 +1248,13 @@ static int alx_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1248 * shared register for the high 32 bits, so only a single, aligned, 1248 * shared register for the high 32 bits, so only a single, aligned,
1249 * 4 GB physical address range can be used for descriptors. 1249 * 4 GB physical address range can be used for descriptors.
1250 */ 1250 */
1251 if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) && 1251 if (!dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64))) {
1252 !dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) {
1253 dev_dbg(&pdev->dev, "DMA to 64-BIT addresses\n"); 1252 dev_dbg(&pdev->dev, "DMA to 64-BIT addresses\n");
1254 } else { 1253 } else {
1255 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32)); 1254 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
1256 if (err) { 1255 if (err) {
1257 err = dma_set_coherent_mask(&pdev->dev, 1256 dev_err(&pdev->dev, "No usable DMA config, aborting\n");
1258 DMA_BIT_MASK(32)); 1257 goto out_pci_disable;
1259 if (err) {
1260 dev_err(&pdev->dev,
1261 "No usable DMA config, aborting\n");
1262 goto out_pci_disable;
1263 }
1264 } 1258 }
1265 } 1259 }
1266 1260
diff --git a/drivers/net/ethernet/atheros/atl1e/atl1e_main.c b/drivers/net/ethernet/atheros/atl1e/atl1e_main.c
index d5c2d3e912e5..422aab27ea1b 100644
--- a/drivers/net/ethernet/atheros/atl1e/atl1e_main.c
+++ b/drivers/net/ethernet/atheros/atl1e/atl1e_main.c
@@ -2436,7 +2436,7 @@ err_reset:
2436err_register: 2436err_register:
2437err_sw_init: 2437err_sw_init:
2438err_eeprom: 2438err_eeprom:
2439 iounmap(adapter->hw.hw_addr); 2439 pci_iounmap(pdev, adapter->hw.hw_addr);
2440err_init_netdev: 2440err_init_netdev:
2441err_ioremap: 2441err_ioremap:
2442 free_netdev(netdev); 2442 free_netdev(netdev);
@@ -2474,7 +2474,7 @@ static void atl1e_remove(struct pci_dev *pdev)
2474 unregister_netdev(netdev); 2474 unregister_netdev(netdev);
2475 atl1e_free_ring_resources(adapter); 2475 atl1e_free_ring_resources(adapter);
2476 atl1e_force_ps(&adapter->hw); 2476 atl1e_force_ps(&adapter->hw);
2477 iounmap(adapter->hw.hw_addr); 2477 pci_iounmap(pdev, adapter->hw.hw_addr);
2478 pci_release_regions(pdev); 2478 pci_release_regions(pdev);
2479 free_netdev(netdev); 2479 free_netdev(netdev);
2480 pci_disable_device(pdev); 2480 pci_disable_device(pdev);
diff --git a/drivers/net/ethernet/broadcom/b44.c b/drivers/net/ethernet/broadcom/b44.c
index 1f7b5aa114fa..8a7bf7dad898 100644
--- a/drivers/net/ethernet/broadcom/b44.c
+++ b/drivers/net/ethernet/broadcom/b44.c
@@ -1484,6 +1484,10 @@ static int b44_open(struct net_device *dev)
1484 add_timer(&bp->timer); 1484 add_timer(&bp->timer);
1485 1485
1486 b44_enable_ints(bp); 1486 b44_enable_ints(bp);
1487
1488 if (bp->flags & B44_FLAG_EXTERNAL_PHY)
1489 phy_start(bp->phydev);
1490
1487 netif_start_queue(dev); 1491 netif_start_queue(dev);
1488out: 1492out:
1489 return err; 1493 return err;
@@ -1646,6 +1650,9 @@ static int b44_close(struct net_device *dev)
1646 1650
1647 netif_stop_queue(dev); 1651 netif_stop_queue(dev);
1648 1652
1653 if (bp->flags & B44_FLAG_EXTERNAL_PHY)
1654 phy_stop(bp->phydev);
1655
1649 napi_disable(&bp->napi); 1656 napi_disable(&bp->napi);
1650 1657
1651 del_timer_sync(&bp->timer); 1658 del_timer_sync(&bp->timer);
@@ -2222,7 +2229,12 @@ static void b44_adjust_link(struct net_device *dev)
2222 } 2229 }
2223 2230
2224 if (status_changed) { 2231 if (status_changed) {
2225 b44_check_phy(bp); 2232 u32 val = br32(bp, B44_TX_CTRL);
2233 if (bp->flags & B44_FLAG_FULL_DUPLEX)
2234 val |= TX_CTRL_DUPLEX;
2235 else
2236 val &= ~TX_CTRL_DUPLEX;
2237 bw32(bp, B44_TX_CTRL, val);
2226 phy_print_status(phydev); 2238 phy_print_status(phydev);
2227 } 2239 }
2228} 2240}
diff --git a/drivers/net/ethernet/broadcom/bnx2.c b/drivers/net/ethernet/broadcom/bnx2.c
index cda25ac45b47..6c9e1c9bdeb8 100644
--- a/drivers/net/ethernet/broadcom/bnx2.c
+++ b/drivers/net/ethernet/broadcom/bnx2.c
@@ -2507,6 +2507,7 @@ bnx2_fw_sync(struct bnx2 *bp, u32 msg_data, int ack, int silent)
2507 2507
2508 bp->fw_wr_seq++; 2508 bp->fw_wr_seq++;
2509 msg_data |= bp->fw_wr_seq; 2509 msg_data |= bp->fw_wr_seq;
2510 bp->fw_last_msg = msg_data;
2510 2511
2511 bnx2_shmem_wr(bp, BNX2_DRV_MB, msg_data); 2512 bnx2_shmem_wr(bp, BNX2_DRV_MB, msg_data);
2512 2513
@@ -4000,8 +4001,23 @@ bnx2_setup_wol(struct bnx2 *bp)
4000 wol_msg = BNX2_DRV_MSG_CODE_SUSPEND_NO_WOL; 4001 wol_msg = BNX2_DRV_MSG_CODE_SUSPEND_NO_WOL;
4001 } 4002 }
4002 4003
4003 if (!(bp->flags & BNX2_FLAG_NO_WOL)) 4004 if (!(bp->flags & BNX2_FLAG_NO_WOL)) {
4004 bnx2_fw_sync(bp, BNX2_DRV_MSG_DATA_WAIT3 | wol_msg, 1, 0); 4005 u32 val;
4006
4007 wol_msg |= BNX2_DRV_MSG_DATA_WAIT3;
4008 if (bp->fw_last_msg || BNX2_CHIP(bp) != BNX2_CHIP_5709) {
4009 bnx2_fw_sync(bp, wol_msg, 1, 0);
4010 return;
4011 }
4012 /* Tell firmware not to power down the PHY yet, otherwise
4013 * the chip will take a long time to respond to MMIO reads.
4014 */
4015 val = bnx2_shmem_rd(bp, BNX2_PORT_FEATURE);
4016 bnx2_shmem_wr(bp, BNX2_PORT_FEATURE,
4017 val | BNX2_PORT_FEATURE_ASF_ENABLED);
4018 bnx2_fw_sync(bp, wol_msg, 1, 0);
4019 bnx2_shmem_wr(bp, BNX2_PORT_FEATURE, val);
4020 }
4005 4021
4006} 4022}
4007 4023
@@ -4033,9 +4049,22 @@ bnx2_set_power_state(struct bnx2 *bp, pci_power_t state)
4033 4049
4034 if (bp->wol) 4050 if (bp->wol)
4035 pci_set_power_state(bp->pdev, PCI_D3hot); 4051 pci_set_power_state(bp->pdev, PCI_D3hot);
4036 } else { 4052 break;
4037 pci_set_power_state(bp->pdev, PCI_D3hot); 4053
4054 }
4055 if (!bp->fw_last_msg && BNX2_CHIP(bp) == BNX2_CHIP_5709) {
4056 u32 val;
4057
4058 /* Tell firmware not to power down the PHY yet,
4059 * otherwise the other port may not respond to
4060 * MMIO reads.
4061 */
4062 val = bnx2_shmem_rd(bp, BNX2_BC_STATE_CONDITION);
4063 val &= ~BNX2_CONDITION_PM_STATE_MASK;
4064 val |= BNX2_CONDITION_PM_STATE_UNPREP;
4065 bnx2_shmem_wr(bp, BNX2_BC_STATE_CONDITION, val);
4038 } 4066 }
4067 pci_set_power_state(bp->pdev, PCI_D3hot);
4039 4068
4040 /* No more memory access after this point until 4069 /* No more memory access after this point until
4041 * device is brought back to D0. 4070 * device is brought back to D0.
diff --git a/drivers/net/ethernet/broadcom/bnx2.h b/drivers/net/ethernet/broadcom/bnx2.h
index f1cf2c44e7ed..e341bc366fa5 100644
--- a/drivers/net/ethernet/broadcom/bnx2.h
+++ b/drivers/net/ethernet/broadcom/bnx2.h
@@ -6900,6 +6900,7 @@ struct bnx2 {
6900 6900
6901 u16 fw_wr_seq; 6901 u16 fw_wr_seq;
6902 u16 fw_drv_pulse_wr_seq; 6902 u16 fw_drv_pulse_wr_seq;
6903 u32 fw_last_msg;
6903 6904
6904 int rx_max_ring; 6905 int rx_max_ring;
6905 int rx_ring_size; 6906 int rx_ring_size;
@@ -7406,6 +7407,10 @@ struct bnx2_rv2p_fw_file {
7406#define BNX2_CONDITION_MFW_RUN_NCSI 0x00006000 7407#define BNX2_CONDITION_MFW_RUN_NCSI 0x00006000
7407#define BNX2_CONDITION_MFW_RUN_NONE 0x0000e000 7408#define BNX2_CONDITION_MFW_RUN_NONE 0x0000e000
7408#define BNX2_CONDITION_MFW_RUN_MASK 0x0000e000 7409#define BNX2_CONDITION_MFW_RUN_MASK 0x0000e000
7410#define BNX2_CONDITION_PM_STATE_MASK 0x00030000
7411#define BNX2_CONDITION_PM_STATE_FULL 0x00030000
7412#define BNX2_CONDITION_PM_STATE_PREP 0x00020000
7413#define BNX2_CONDITION_PM_STATE_UNPREP 0x00010000
7409 7414
7410#define BNX2_BC_STATE_DEBUG_CMD 0x1dc 7415#define BNX2_BC_STATE_DEBUG_CMD 0x1dc
7411#define BNX2_BC_STATE_BC_DBG_CMD_SIGNATURE 0x42440000 7416#define BNX2_BC_STATE_BC_DBG_CMD_SIGNATURE 0x42440000
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
index 66c0df78c3ff..dbcff509dc3f 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
@@ -3875,7 +3875,9 @@ netdev_tx_t bnx2x_start_xmit(struct sk_buff *skb, struct net_device *dev)
3875 xmit_type); 3875 xmit_type);
3876 } 3876 }
3877 3877
3878 /* Add the macs to the parsing BD this is a vf */ 3878 /* Add the macs to the parsing BD if this is a vf or if
3879 * Tx Switching is enabled.
3880 */
3879 if (IS_VF(bp)) { 3881 if (IS_VF(bp)) {
3880 /* override GRE parameters in BD */ 3882 /* override GRE parameters in BD */
3881 bnx2x_set_fw_mac_addr(&pbd_e2->data.mac_addr.src_hi, 3883 bnx2x_set_fw_mac_addr(&pbd_e2->data.mac_addr.src_hi,
@@ -3887,6 +3889,11 @@ netdev_tx_t bnx2x_start_xmit(struct sk_buff *skb, struct net_device *dev)
3887 &pbd_e2->data.mac_addr.dst_mid, 3889 &pbd_e2->data.mac_addr.dst_mid,
3888 &pbd_e2->data.mac_addr.dst_lo, 3890 &pbd_e2->data.mac_addr.dst_lo,
3889 eth->h_dest); 3891 eth->h_dest);
3892 } else if (bp->flags & TX_SWITCHING) {
3893 bnx2x_set_fw_mac_addr(&pbd_e2->data.mac_addr.dst_hi,
3894 &pbd_e2->data.mac_addr.dst_mid,
3895 &pbd_e2->data.mac_addr.dst_lo,
3896 eth->h_dest);
3890 } 3897 }
3891 3898
3892 SET_FLAG(pbd_e2_parsing_data, 3899 SET_FLAG(pbd_e2_parsing_data,
diff --git a/drivers/net/ethernet/broadcom/cnic.c b/drivers/net/ethernet/broadcom/cnic.c
index fcf9105a5476..09f3fefcbf9c 100644
--- a/drivers/net/ethernet/broadcom/cnic.c
+++ b/drivers/net/ethernet/broadcom/cnic.c
@@ -1,6 +1,6 @@
1/* cnic.c: Broadcom CNIC core network driver. 1/* cnic.c: Broadcom CNIC core network driver.
2 * 2 *
3 * Copyright (c) 2006-2013 Broadcom Corporation 3 * Copyright (c) 2006-2014 Broadcom Corporation
4 * 4 *
5 * This program is free software; you can redistribute it and/or modify 5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by 6 * it under the terms of the GNU General Public License as published by
@@ -342,7 +342,7 @@ static int cnic_send_nlmsg(struct cnic_local *cp, u32 type,
342 while (retry < 3) { 342 while (retry < 3) {
343 rc = 0; 343 rc = 0;
344 rcu_read_lock(); 344 rcu_read_lock();
345 ulp_ops = rcu_dereference(cnic_ulp_tbl[CNIC_ULP_ISCSI]); 345 ulp_ops = rcu_dereference(cp->ulp_ops[CNIC_ULP_ISCSI]);
346 if (ulp_ops) 346 if (ulp_ops)
347 rc = ulp_ops->iscsi_nl_send_msg( 347 rc = ulp_ops->iscsi_nl_send_msg(
348 cp->ulp_handle[CNIC_ULP_ISCSI], 348 cp->ulp_handle[CNIC_ULP_ISCSI],
@@ -726,7 +726,7 @@ static void cnic_free_dma(struct cnic_dev *dev, struct cnic_dma *dma)
726 726
727 for (i = 0; i < dma->num_pages; i++) { 727 for (i = 0; i < dma->num_pages; i++) {
728 if (dma->pg_arr[i]) { 728 if (dma->pg_arr[i]) {
729 dma_free_coherent(&dev->pcidev->dev, BNX2_PAGE_SIZE, 729 dma_free_coherent(&dev->pcidev->dev, CNIC_PAGE_SIZE,
730 dma->pg_arr[i], dma->pg_map_arr[i]); 730 dma->pg_arr[i], dma->pg_map_arr[i]);
731 dma->pg_arr[i] = NULL; 731 dma->pg_arr[i] = NULL;
732 } 732 }
@@ -785,7 +785,7 @@ static int cnic_alloc_dma(struct cnic_dev *dev, struct cnic_dma *dma,
785 785
786 for (i = 0; i < pages; i++) { 786 for (i = 0; i < pages; i++) {
787 dma->pg_arr[i] = dma_alloc_coherent(&dev->pcidev->dev, 787 dma->pg_arr[i] = dma_alloc_coherent(&dev->pcidev->dev,
788 BNX2_PAGE_SIZE, 788 CNIC_PAGE_SIZE,
789 &dma->pg_map_arr[i], 789 &dma->pg_map_arr[i],
790 GFP_ATOMIC); 790 GFP_ATOMIC);
791 if (dma->pg_arr[i] == NULL) 791 if (dma->pg_arr[i] == NULL)
@@ -794,8 +794,8 @@ static int cnic_alloc_dma(struct cnic_dev *dev, struct cnic_dma *dma,
794 if (!use_pg_tbl) 794 if (!use_pg_tbl)
795 return 0; 795 return 0;
796 796
797 dma->pgtbl_size = ((pages * 8) + BNX2_PAGE_SIZE - 1) & 797 dma->pgtbl_size = ((pages * 8) + CNIC_PAGE_SIZE - 1) &
798 ~(BNX2_PAGE_SIZE - 1); 798 ~(CNIC_PAGE_SIZE - 1);
799 dma->pgtbl = dma_alloc_coherent(&dev->pcidev->dev, dma->pgtbl_size, 799 dma->pgtbl = dma_alloc_coherent(&dev->pcidev->dev, dma->pgtbl_size,
800 &dma->pgtbl_map, GFP_ATOMIC); 800 &dma->pgtbl_map, GFP_ATOMIC);
801 if (dma->pgtbl == NULL) 801 if (dma->pgtbl == NULL)
@@ -900,8 +900,8 @@ static int cnic_alloc_context(struct cnic_dev *dev)
900 if (BNX2_CHIP(cp) == BNX2_CHIP_5709) { 900 if (BNX2_CHIP(cp) == BNX2_CHIP_5709) {
901 int i, k, arr_size; 901 int i, k, arr_size;
902 902
903 cp->ctx_blk_size = BNX2_PAGE_SIZE; 903 cp->ctx_blk_size = CNIC_PAGE_SIZE;
904 cp->cids_per_blk = BNX2_PAGE_SIZE / 128; 904 cp->cids_per_blk = CNIC_PAGE_SIZE / 128;
905 arr_size = BNX2_MAX_CID / cp->cids_per_blk * 905 arr_size = BNX2_MAX_CID / cp->cids_per_blk *
906 sizeof(struct cnic_ctx); 906 sizeof(struct cnic_ctx);
907 cp->ctx_arr = kzalloc(arr_size, GFP_KERNEL); 907 cp->ctx_arr = kzalloc(arr_size, GFP_KERNEL);
@@ -933,7 +933,7 @@ static int cnic_alloc_context(struct cnic_dev *dev)
933 for (i = 0; i < cp->ctx_blks; i++) { 933 for (i = 0; i < cp->ctx_blks; i++) {
934 cp->ctx_arr[i].ctx = 934 cp->ctx_arr[i].ctx =
935 dma_alloc_coherent(&dev->pcidev->dev, 935 dma_alloc_coherent(&dev->pcidev->dev,
936 BNX2_PAGE_SIZE, 936 CNIC_PAGE_SIZE,
937 &cp->ctx_arr[i].mapping, 937 &cp->ctx_arr[i].mapping,
938 GFP_KERNEL); 938 GFP_KERNEL);
939 if (cp->ctx_arr[i].ctx == NULL) 939 if (cp->ctx_arr[i].ctx == NULL)
@@ -1013,7 +1013,7 @@ static int __cnic_alloc_uio_rings(struct cnic_uio_dev *udev, int pages)
1013 if (udev->l2_ring) 1013 if (udev->l2_ring)
1014 return 0; 1014 return 0;
1015 1015
1016 udev->l2_ring_size = pages * BNX2_PAGE_SIZE; 1016 udev->l2_ring_size = pages * CNIC_PAGE_SIZE;
1017 udev->l2_ring = dma_alloc_coherent(&udev->pdev->dev, udev->l2_ring_size, 1017 udev->l2_ring = dma_alloc_coherent(&udev->pdev->dev, udev->l2_ring_size,
1018 &udev->l2_ring_map, 1018 &udev->l2_ring_map,
1019 GFP_KERNEL | __GFP_COMP); 1019 GFP_KERNEL | __GFP_COMP);
@@ -1021,7 +1021,7 @@ static int __cnic_alloc_uio_rings(struct cnic_uio_dev *udev, int pages)
1021 return -ENOMEM; 1021 return -ENOMEM;
1022 1022
1023 udev->l2_buf_size = (cp->l2_rx_ring_size + 1) * cp->l2_single_buf_size; 1023 udev->l2_buf_size = (cp->l2_rx_ring_size + 1) * cp->l2_single_buf_size;
1024 udev->l2_buf_size = PAGE_ALIGN(udev->l2_buf_size); 1024 udev->l2_buf_size = CNIC_PAGE_ALIGN(udev->l2_buf_size);
1025 udev->l2_buf = dma_alloc_coherent(&udev->pdev->dev, udev->l2_buf_size, 1025 udev->l2_buf = dma_alloc_coherent(&udev->pdev->dev, udev->l2_buf_size,
1026 &udev->l2_buf_map, 1026 &udev->l2_buf_map,
1027 GFP_KERNEL | __GFP_COMP); 1027 GFP_KERNEL | __GFP_COMP);
@@ -1102,7 +1102,7 @@ static int cnic_init_uio(struct cnic_dev *dev)
1102 uinfo->mem[0].size = MB_GET_CID_ADDR(TX_TSS_CID + 1102 uinfo->mem[0].size = MB_GET_CID_ADDR(TX_TSS_CID +
1103 TX_MAX_TSS_RINGS + 1); 1103 TX_MAX_TSS_RINGS + 1);
1104 uinfo->mem[1].addr = (unsigned long) cp->status_blk.gen & 1104 uinfo->mem[1].addr = (unsigned long) cp->status_blk.gen &
1105 PAGE_MASK; 1105 CNIC_PAGE_MASK;
1106 if (cp->ethdev->drv_state & CNIC_DRV_STATE_USING_MSIX) 1106 if (cp->ethdev->drv_state & CNIC_DRV_STATE_USING_MSIX)
1107 uinfo->mem[1].size = BNX2_SBLK_MSIX_ALIGN_SIZE * 9; 1107 uinfo->mem[1].size = BNX2_SBLK_MSIX_ALIGN_SIZE * 9;
1108 else 1108 else
@@ -1113,7 +1113,7 @@ static int cnic_init_uio(struct cnic_dev *dev)
1113 uinfo->mem[0].size = pci_resource_len(dev->pcidev, 0); 1113 uinfo->mem[0].size = pci_resource_len(dev->pcidev, 0);
1114 1114
1115 uinfo->mem[1].addr = (unsigned long) cp->bnx2x_def_status_blk & 1115 uinfo->mem[1].addr = (unsigned long) cp->bnx2x_def_status_blk &
1116 PAGE_MASK; 1116 CNIC_PAGE_MASK;
1117 uinfo->mem[1].size = sizeof(*cp->bnx2x_def_status_blk); 1117 uinfo->mem[1].size = sizeof(*cp->bnx2x_def_status_blk);
1118 1118
1119 uinfo->name = "bnx2x_cnic"; 1119 uinfo->name = "bnx2x_cnic";
@@ -1267,14 +1267,14 @@ static int cnic_alloc_bnx2x_resc(struct cnic_dev *dev)
1267 for (i = MAX_ISCSI_TBL_SZ; i < cp->max_cid_space; i++) 1267 for (i = MAX_ISCSI_TBL_SZ; i < cp->max_cid_space; i++)
1268 cp->ctx_tbl[i].ulp_proto_id = CNIC_ULP_FCOE; 1268 cp->ctx_tbl[i].ulp_proto_id = CNIC_ULP_FCOE;
1269 1269
1270 pages = PAGE_ALIGN(cp->max_cid_space * CNIC_KWQ16_DATA_SIZE) / 1270 pages = CNIC_PAGE_ALIGN(cp->max_cid_space * CNIC_KWQ16_DATA_SIZE) /
1271 PAGE_SIZE; 1271 CNIC_PAGE_SIZE;
1272 1272
1273 ret = cnic_alloc_dma(dev, kwq_16_dma, pages, 0); 1273 ret = cnic_alloc_dma(dev, kwq_16_dma, pages, 0);
1274 if (ret) 1274 if (ret)
1275 return -ENOMEM; 1275 return -ENOMEM;
1276 1276
1277 n = PAGE_SIZE / CNIC_KWQ16_DATA_SIZE; 1277 n = CNIC_PAGE_SIZE / CNIC_KWQ16_DATA_SIZE;
1278 for (i = 0, j = 0; i < cp->max_cid_space; i++) { 1278 for (i = 0, j = 0; i < cp->max_cid_space; i++) {
1279 long off = CNIC_KWQ16_DATA_SIZE * (i % n); 1279 long off = CNIC_KWQ16_DATA_SIZE * (i % n);
1280 1280
@@ -1296,7 +1296,7 @@ static int cnic_alloc_bnx2x_resc(struct cnic_dev *dev)
1296 goto error; 1296 goto error;
1297 } 1297 }
1298 1298
1299 pages = PAGE_ALIGN(BNX2X_ISCSI_GLB_BUF_SIZE) / PAGE_SIZE; 1299 pages = CNIC_PAGE_ALIGN(BNX2X_ISCSI_GLB_BUF_SIZE) / CNIC_PAGE_SIZE;
1300 ret = cnic_alloc_dma(dev, &cp->gbl_buf_info, pages, 0); 1300 ret = cnic_alloc_dma(dev, &cp->gbl_buf_info, pages, 0);
1301 if (ret) 1301 if (ret)
1302 goto error; 1302 goto error;
@@ -1466,8 +1466,8 @@ static int cnic_bnx2x_iscsi_init1(struct cnic_dev *dev, struct kwqe *kwqe)
1466 cp->r2tq_size = cp->num_iscsi_tasks * BNX2X_ISCSI_MAX_PENDING_R2TS * 1466 cp->r2tq_size = cp->num_iscsi_tasks * BNX2X_ISCSI_MAX_PENDING_R2TS *
1467 BNX2X_ISCSI_R2TQE_SIZE; 1467 BNX2X_ISCSI_R2TQE_SIZE;
1468 cp->hq_size = cp->num_ccells * BNX2X_ISCSI_HQ_BD_SIZE; 1468 cp->hq_size = cp->num_ccells * BNX2X_ISCSI_HQ_BD_SIZE;
1469 pages = PAGE_ALIGN(cp->hq_size) / PAGE_SIZE; 1469 pages = CNIC_PAGE_ALIGN(cp->hq_size) / CNIC_PAGE_SIZE;
1470 hq_bds = pages * (PAGE_SIZE / BNX2X_ISCSI_HQ_BD_SIZE); 1470 hq_bds = pages * (CNIC_PAGE_SIZE / BNX2X_ISCSI_HQ_BD_SIZE);
1471 cp->num_cqs = req1->num_cqs; 1471 cp->num_cqs = req1->num_cqs;
1472 1472
1473 if (!dev->max_iscsi_conn) 1473 if (!dev->max_iscsi_conn)
@@ -1477,9 +1477,9 @@ static int cnic_bnx2x_iscsi_init1(struct cnic_dev *dev, struct kwqe *kwqe)
1477 CNIC_WR16(dev, BAR_TSTRORM_INTMEM + TSTORM_ISCSI_RQ_SIZE_OFFSET(pfid), 1477 CNIC_WR16(dev, BAR_TSTRORM_INTMEM + TSTORM_ISCSI_RQ_SIZE_OFFSET(pfid),
1478 req1->rq_num_wqes); 1478 req1->rq_num_wqes);
1479 CNIC_WR16(dev, BAR_TSTRORM_INTMEM + TSTORM_ISCSI_PAGE_SIZE_OFFSET(pfid), 1479 CNIC_WR16(dev, BAR_TSTRORM_INTMEM + TSTORM_ISCSI_PAGE_SIZE_OFFSET(pfid),
1480 PAGE_SIZE); 1480 CNIC_PAGE_SIZE);
1481 CNIC_WR8(dev, BAR_TSTRORM_INTMEM + 1481 CNIC_WR8(dev, BAR_TSTRORM_INTMEM +
1482 TSTORM_ISCSI_PAGE_SIZE_LOG_OFFSET(pfid), PAGE_SHIFT); 1482 TSTORM_ISCSI_PAGE_SIZE_LOG_OFFSET(pfid), CNIC_PAGE_BITS);
1483 CNIC_WR16(dev, BAR_TSTRORM_INTMEM + 1483 CNIC_WR16(dev, BAR_TSTRORM_INTMEM +
1484 TSTORM_ISCSI_NUM_OF_TASKS_OFFSET(pfid), 1484 TSTORM_ISCSI_NUM_OF_TASKS_OFFSET(pfid),
1485 req1->num_tasks_per_conn); 1485 req1->num_tasks_per_conn);
@@ -1489,9 +1489,9 @@ static int cnic_bnx2x_iscsi_init1(struct cnic_dev *dev, struct kwqe *kwqe)
1489 USTORM_ISCSI_RQ_BUFFER_SIZE_OFFSET(pfid), 1489 USTORM_ISCSI_RQ_BUFFER_SIZE_OFFSET(pfid),
1490 req1->rq_buffer_size); 1490 req1->rq_buffer_size);
1491 CNIC_WR16(dev, BAR_USTRORM_INTMEM + USTORM_ISCSI_PAGE_SIZE_OFFSET(pfid), 1491 CNIC_WR16(dev, BAR_USTRORM_INTMEM + USTORM_ISCSI_PAGE_SIZE_OFFSET(pfid),
1492 PAGE_SIZE); 1492 CNIC_PAGE_SIZE);
1493 CNIC_WR8(dev, BAR_USTRORM_INTMEM + 1493 CNIC_WR8(dev, BAR_USTRORM_INTMEM +
1494 USTORM_ISCSI_PAGE_SIZE_LOG_OFFSET(pfid), PAGE_SHIFT); 1494 USTORM_ISCSI_PAGE_SIZE_LOG_OFFSET(pfid), CNIC_PAGE_BITS);
1495 CNIC_WR16(dev, BAR_USTRORM_INTMEM + 1495 CNIC_WR16(dev, BAR_USTRORM_INTMEM +
1496 USTORM_ISCSI_NUM_OF_TASKS_OFFSET(pfid), 1496 USTORM_ISCSI_NUM_OF_TASKS_OFFSET(pfid),
1497 req1->num_tasks_per_conn); 1497 req1->num_tasks_per_conn);
@@ -1504,9 +1504,9 @@ static int cnic_bnx2x_iscsi_init1(struct cnic_dev *dev, struct kwqe *kwqe)
1504 1504
1505 /* init Xstorm RAM */ 1505 /* init Xstorm RAM */
1506 CNIC_WR16(dev, BAR_XSTRORM_INTMEM + XSTORM_ISCSI_PAGE_SIZE_OFFSET(pfid), 1506 CNIC_WR16(dev, BAR_XSTRORM_INTMEM + XSTORM_ISCSI_PAGE_SIZE_OFFSET(pfid),
1507 PAGE_SIZE); 1507 CNIC_PAGE_SIZE);
1508 CNIC_WR8(dev, BAR_XSTRORM_INTMEM + 1508 CNIC_WR8(dev, BAR_XSTRORM_INTMEM +
1509 XSTORM_ISCSI_PAGE_SIZE_LOG_OFFSET(pfid), PAGE_SHIFT); 1509 XSTORM_ISCSI_PAGE_SIZE_LOG_OFFSET(pfid), CNIC_PAGE_BITS);
1510 CNIC_WR16(dev, BAR_XSTRORM_INTMEM + 1510 CNIC_WR16(dev, BAR_XSTRORM_INTMEM +
1511 XSTORM_ISCSI_NUM_OF_TASKS_OFFSET(pfid), 1511 XSTORM_ISCSI_NUM_OF_TASKS_OFFSET(pfid),
1512 req1->num_tasks_per_conn); 1512 req1->num_tasks_per_conn);
@@ -1519,9 +1519,9 @@ static int cnic_bnx2x_iscsi_init1(struct cnic_dev *dev, struct kwqe *kwqe)
1519 1519
1520 /* init Cstorm RAM */ 1520 /* init Cstorm RAM */
1521 CNIC_WR16(dev, BAR_CSTRORM_INTMEM + CSTORM_ISCSI_PAGE_SIZE_OFFSET(pfid), 1521 CNIC_WR16(dev, BAR_CSTRORM_INTMEM + CSTORM_ISCSI_PAGE_SIZE_OFFSET(pfid),
1522 PAGE_SIZE); 1522 CNIC_PAGE_SIZE);
1523 CNIC_WR8(dev, BAR_CSTRORM_INTMEM + 1523 CNIC_WR8(dev, BAR_CSTRORM_INTMEM +
1524 CSTORM_ISCSI_PAGE_SIZE_LOG_OFFSET(pfid), PAGE_SHIFT); 1524 CSTORM_ISCSI_PAGE_SIZE_LOG_OFFSET(pfid), CNIC_PAGE_BITS);
1525 CNIC_WR16(dev, BAR_CSTRORM_INTMEM + 1525 CNIC_WR16(dev, BAR_CSTRORM_INTMEM +
1526 CSTORM_ISCSI_NUM_OF_TASKS_OFFSET(pfid), 1526 CSTORM_ISCSI_NUM_OF_TASKS_OFFSET(pfid),
1527 req1->num_tasks_per_conn); 1527 req1->num_tasks_per_conn);
@@ -1623,18 +1623,18 @@ static int cnic_alloc_bnx2x_conn_resc(struct cnic_dev *dev, u32 l5_cid)
1623 } 1623 }
1624 1624
1625 ctx->cid = cid; 1625 ctx->cid = cid;
1626 pages = PAGE_ALIGN(cp->task_array_size) / PAGE_SIZE; 1626 pages = CNIC_PAGE_ALIGN(cp->task_array_size) / CNIC_PAGE_SIZE;
1627 1627
1628 ret = cnic_alloc_dma(dev, &iscsi->task_array_info, pages, 1); 1628 ret = cnic_alloc_dma(dev, &iscsi->task_array_info, pages, 1);
1629 if (ret) 1629 if (ret)
1630 goto error; 1630 goto error;
1631 1631
1632 pages = PAGE_ALIGN(cp->r2tq_size) / PAGE_SIZE; 1632 pages = CNIC_PAGE_ALIGN(cp->r2tq_size) / CNIC_PAGE_SIZE;
1633 ret = cnic_alloc_dma(dev, &iscsi->r2tq_info, pages, 1); 1633 ret = cnic_alloc_dma(dev, &iscsi->r2tq_info, pages, 1);
1634 if (ret) 1634 if (ret)
1635 goto error; 1635 goto error;
1636 1636
1637 pages = PAGE_ALIGN(cp->hq_size) / PAGE_SIZE; 1637 pages = CNIC_PAGE_ALIGN(cp->hq_size) / CNIC_PAGE_SIZE;
1638 ret = cnic_alloc_dma(dev, &iscsi->hq_info, pages, 1); 1638 ret = cnic_alloc_dma(dev, &iscsi->hq_info, pages, 1);
1639 if (ret) 1639 if (ret)
1640 goto error; 1640 goto error;
@@ -1760,7 +1760,7 @@ static int cnic_setup_bnx2x_ctx(struct cnic_dev *dev, struct kwqe *wqes[],
1760 ictx->tstorm_st_context.iscsi.hdr_bytes_2_fetch = ISCSI_HEADER_SIZE; 1760 ictx->tstorm_st_context.iscsi.hdr_bytes_2_fetch = ISCSI_HEADER_SIZE;
1761 /* TSTORM requires the base address of RQ DB & not PTE */ 1761 /* TSTORM requires the base address of RQ DB & not PTE */
1762 ictx->tstorm_st_context.iscsi.rq_db_phy_addr.lo = 1762 ictx->tstorm_st_context.iscsi.rq_db_phy_addr.lo =
1763 req2->rq_page_table_addr_lo & PAGE_MASK; 1763 req2->rq_page_table_addr_lo & CNIC_PAGE_MASK;
1764 ictx->tstorm_st_context.iscsi.rq_db_phy_addr.hi = 1764 ictx->tstorm_st_context.iscsi.rq_db_phy_addr.hi =
1765 req2->rq_page_table_addr_hi; 1765 req2->rq_page_table_addr_hi;
1766 ictx->tstorm_st_context.iscsi.iscsi_conn_id = req1->iscsi_conn_id; 1766 ictx->tstorm_st_context.iscsi.iscsi_conn_id = req1->iscsi_conn_id;
@@ -1842,7 +1842,7 @@ static int cnic_setup_bnx2x_ctx(struct cnic_dev *dev, struct kwqe *wqes[],
1842 /* CSTORM and USTORM initialization is different, CSTORM requires 1842 /* CSTORM and USTORM initialization is different, CSTORM requires
1843 * CQ DB base & not PTE addr */ 1843 * CQ DB base & not PTE addr */
1844 ictx->cstorm_st_context.cq_db_base.lo = 1844 ictx->cstorm_st_context.cq_db_base.lo =
1845 req1->cq_page_table_addr_lo & PAGE_MASK; 1845 req1->cq_page_table_addr_lo & CNIC_PAGE_MASK;
1846 ictx->cstorm_st_context.cq_db_base.hi = req1->cq_page_table_addr_hi; 1846 ictx->cstorm_st_context.cq_db_base.hi = req1->cq_page_table_addr_hi;
1847 ictx->cstorm_st_context.iscsi_conn_id = req1->iscsi_conn_id; 1847 ictx->cstorm_st_context.iscsi_conn_id = req1->iscsi_conn_id;
1848 ictx->cstorm_st_context.cq_proc_en_bit_map = (1 << cp->num_cqs) - 1; 1848 ictx->cstorm_st_context.cq_proc_en_bit_map = (1 << cp->num_cqs) - 1;
@@ -2911,7 +2911,7 @@ static int cnic_l2_completion(struct cnic_local *cp)
2911 u16 hw_cons, sw_cons; 2911 u16 hw_cons, sw_cons;
2912 struct cnic_uio_dev *udev = cp->udev; 2912 struct cnic_uio_dev *udev = cp->udev;
2913 union eth_rx_cqe *cqe, *cqe_ring = (union eth_rx_cqe *) 2913 union eth_rx_cqe *cqe, *cqe_ring = (union eth_rx_cqe *)
2914 (udev->l2_ring + (2 * BNX2_PAGE_SIZE)); 2914 (udev->l2_ring + (2 * CNIC_PAGE_SIZE));
2915 u32 cmd; 2915 u32 cmd;
2916 int comp = 0; 2916 int comp = 0;
2917 2917
@@ -3244,7 +3244,8 @@ static int cnic_copy_ulp_stats(struct cnic_dev *dev, int ulp_type)
3244 int rc; 3244 int rc;
3245 3245
3246 mutex_lock(&cnic_lock); 3246 mutex_lock(&cnic_lock);
3247 ulp_ops = cnic_ulp_tbl_prot(ulp_type); 3247 ulp_ops = rcu_dereference_protected(cp->ulp_ops[ulp_type],
3248 lockdep_is_held(&cnic_lock));
3248 if (ulp_ops && ulp_ops->cnic_get_stats) 3249 if (ulp_ops && ulp_ops->cnic_get_stats)
3249 rc = ulp_ops->cnic_get_stats(cp->ulp_handle[ulp_type]); 3250 rc = ulp_ops->cnic_get_stats(cp->ulp_handle[ulp_type]);
3250 else 3251 else
@@ -4384,7 +4385,7 @@ static int cnic_setup_5709_context(struct cnic_dev *dev, int valid)
4384 u32 idx = cp->ctx_arr[i].cid / cp->cids_per_blk; 4385 u32 idx = cp->ctx_arr[i].cid / cp->cids_per_blk;
4385 u32 val; 4386 u32 val;
4386 4387
4387 memset(cp->ctx_arr[i].ctx, 0, BNX2_PAGE_SIZE); 4388 memset(cp->ctx_arr[i].ctx, 0, CNIC_PAGE_SIZE);
4388 4389
4389 CNIC_WR(dev, BNX2_CTX_HOST_PAGE_TBL_DATA0, 4390 CNIC_WR(dev, BNX2_CTX_HOST_PAGE_TBL_DATA0,
4390 (cp->ctx_arr[i].mapping & 0xffffffff) | valid_bit); 4391 (cp->ctx_arr[i].mapping & 0xffffffff) | valid_bit);
@@ -4628,7 +4629,7 @@ static void cnic_init_bnx2_rx_ring(struct cnic_dev *dev)
4628 val = BNX2_L2CTX_L2_STATUSB_NUM(sb_id); 4629 val = BNX2_L2CTX_L2_STATUSB_NUM(sb_id);
4629 cnic_ctx_wr(dev, cid_addr, BNX2_L2CTX_HOST_BDIDX, val); 4630 cnic_ctx_wr(dev, cid_addr, BNX2_L2CTX_HOST_BDIDX, val);
4630 4631
4631 rxbd = udev->l2_ring + BNX2_PAGE_SIZE; 4632 rxbd = udev->l2_ring + CNIC_PAGE_SIZE;
4632 for (i = 0; i < BNX2_MAX_RX_DESC_CNT; i++, rxbd++) { 4633 for (i = 0; i < BNX2_MAX_RX_DESC_CNT; i++, rxbd++) {
4633 dma_addr_t buf_map; 4634 dma_addr_t buf_map;
4634 int n = (i % cp->l2_rx_ring_size) + 1; 4635 int n = (i % cp->l2_rx_ring_size) + 1;
@@ -4639,11 +4640,11 @@ static void cnic_init_bnx2_rx_ring(struct cnic_dev *dev)
4639 rxbd->rx_bd_haddr_hi = (u64) buf_map >> 32; 4640 rxbd->rx_bd_haddr_hi = (u64) buf_map >> 32;
4640 rxbd->rx_bd_haddr_lo = (u64) buf_map & 0xffffffff; 4641 rxbd->rx_bd_haddr_lo = (u64) buf_map & 0xffffffff;
4641 } 4642 }
4642 val = (u64) (ring_map + BNX2_PAGE_SIZE) >> 32; 4643 val = (u64) (ring_map + CNIC_PAGE_SIZE) >> 32;
4643 cnic_ctx_wr(dev, cid_addr, BNX2_L2CTX_NX_BDHADDR_HI, val); 4644 cnic_ctx_wr(dev, cid_addr, BNX2_L2CTX_NX_BDHADDR_HI, val);
4644 rxbd->rx_bd_haddr_hi = val; 4645 rxbd->rx_bd_haddr_hi = val;
4645 4646
4646 val = (u64) (ring_map + BNX2_PAGE_SIZE) & 0xffffffff; 4647 val = (u64) (ring_map + CNIC_PAGE_SIZE) & 0xffffffff;
4647 cnic_ctx_wr(dev, cid_addr, BNX2_L2CTX_NX_BDHADDR_LO, val); 4648 cnic_ctx_wr(dev, cid_addr, BNX2_L2CTX_NX_BDHADDR_LO, val);
4648 rxbd->rx_bd_haddr_lo = val; 4649 rxbd->rx_bd_haddr_lo = val;
4649 4650
@@ -4709,10 +4710,10 @@ static int cnic_start_bnx2_hw(struct cnic_dev *dev)
4709 4710
4710 val = CNIC_RD(dev, BNX2_MQ_CONFIG); 4711 val = CNIC_RD(dev, BNX2_MQ_CONFIG);
4711 val &= ~BNX2_MQ_CONFIG_KNL_BYP_BLK_SIZE; 4712 val &= ~BNX2_MQ_CONFIG_KNL_BYP_BLK_SIZE;
4712 if (BNX2_PAGE_BITS > 12) 4713 if (CNIC_PAGE_BITS > 12)
4713 val |= (12 - 8) << 4; 4714 val |= (12 - 8) << 4;
4714 else 4715 else
4715 val |= (BNX2_PAGE_BITS - 8) << 4; 4716 val |= (CNIC_PAGE_BITS - 8) << 4;
4716 4717
4717 CNIC_WR(dev, BNX2_MQ_CONFIG, val); 4718 CNIC_WR(dev, BNX2_MQ_CONFIG, val);
4718 4719
@@ -4742,13 +4743,13 @@ static int cnic_start_bnx2_hw(struct cnic_dev *dev)
4742 4743
4743 /* Initialize the kernel work queue context. */ 4744 /* Initialize the kernel work queue context. */
4744 val = KRNLQ_TYPE_TYPE_KRNLQ | KRNLQ_SIZE_TYPE_SIZE | 4745 val = KRNLQ_TYPE_TYPE_KRNLQ | KRNLQ_SIZE_TYPE_SIZE |
4745 (BNX2_PAGE_BITS - 8) | KRNLQ_FLAGS_QE_SELF_SEQ; 4746 (CNIC_PAGE_BITS - 8) | KRNLQ_FLAGS_QE_SELF_SEQ;
4746 cnic_ctx_wr(dev, kwq_cid_addr, L5_KRNLQ_TYPE, val); 4747 cnic_ctx_wr(dev, kwq_cid_addr, L5_KRNLQ_TYPE, val);
4747 4748
4748 val = (BNX2_PAGE_SIZE / sizeof(struct kwqe) - 1) << 16; 4749 val = (CNIC_PAGE_SIZE / sizeof(struct kwqe) - 1) << 16;
4749 cnic_ctx_wr(dev, kwq_cid_addr, L5_KRNLQ_QE_SELF_SEQ_MAX, val); 4750 cnic_ctx_wr(dev, kwq_cid_addr, L5_KRNLQ_QE_SELF_SEQ_MAX, val);
4750 4751
4751 val = ((BNX2_PAGE_SIZE / sizeof(struct kwqe)) << 16) | KWQ_PAGE_CNT; 4752 val = ((CNIC_PAGE_SIZE / sizeof(struct kwqe)) << 16) | KWQ_PAGE_CNT;
4752 cnic_ctx_wr(dev, kwq_cid_addr, L5_KRNLQ_PGTBL_NPAGES, val); 4753 cnic_ctx_wr(dev, kwq_cid_addr, L5_KRNLQ_PGTBL_NPAGES, val);
4753 4754
4754 val = (u32) ((u64) cp->kwq_info.pgtbl_map >> 32); 4755 val = (u32) ((u64) cp->kwq_info.pgtbl_map >> 32);
@@ -4768,13 +4769,13 @@ static int cnic_start_bnx2_hw(struct cnic_dev *dev)
4768 4769
4769 /* Initialize the kernel complete queue context. */ 4770 /* Initialize the kernel complete queue context. */
4770 val = KRNLQ_TYPE_TYPE_KRNLQ | KRNLQ_SIZE_TYPE_SIZE | 4771 val = KRNLQ_TYPE_TYPE_KRNLQ | KRNLQ_SIZE_TYPE_SIZE |
4771 (BNX2_PAGE_BITS - 8) | KRNLQ_FLAGS_QE_SELF_SEQ; 4772 (CNIC_PAGE_BITS - 8) | KRNLQ_FLAGS_QE_SELF_SEQ;
4772 cnic_ctx_wr(dev, kcq_cid_addr, L5_KRNLQ_TYPE, val); 4773 cnic_ctx_wr(dev, kcq_cid_addr, L5_KRNLQ_TYPE, val);
4773 4774
4774 val = (BNX2_PAGE_SIZE / sizeof(struct kcqe) - 1) << 16; 4775 val = (CNIC_PAGE_SIZE / sizeof(struct kcqe) - 1) << 16;
4775 cnic_ctx_wr(dev, kcq_cid_addr, L5_KRNLQ_QE_SELF_SEQ_MAX, val); 4776 cnic_ctx_wr(dev, kcq_cid_addr, L5_KRNLQ_QE_SELF_SEQ_MAX, val);
4776 4777
4777 val = ((BNX2_PAGE_SIZE / sizeof(struct kcqe)) << 16) | KCQ_PAGE_CNT; 4778 val = ((CNIC_PAGE_SIZE / sizeof(struct kcqe)) << 16) | KCQ_PAGE_CNT;
4778 cnic_ctx_wr(dev, kcq_cid_addr, L5_KRNLQ_PGTBL_NPAGES, val); 4779 cnic_ctx_wr(dev, kcq_cid_addr, L5_KRNLQ_PGTBL_NPAGES, val);
4779 4780
4780 val = (u32) ((u64) cp->kcq1.dma.pgtbl_map >> 32); 4781 val = (u32) ((u64) cp->kcq1.dma.pgtbl_map >> 32);
@@ -4918,7 +4919,7 @@ static void cnic_init_bnx2x_tx_ring(struct cnic_dev *dev,
4918 u32 cli = cp->ethdev->iscsi_l2_client_id; 4919 u32 cli = cp->ethdev->iscsi_l2_client_id;
4919 u32 val; 4920 u32 val;
4920 4921
4921 memset(txbd, 0, BNX2_PAGE_SIZE); 4922 memset(txbd, 0, CNIC_PAGE_SIZE);
4922 4923
4923 buf_map = udev->l2_buf_map; 4924 buf_map = udev->l2_buf_map;
4924 for (i = 0; i < BNX2_MAX_TX_DESC_CNT; i += 3, txbd += 3) { 4925 for (i = 0; i < BNX2_MAX_TX_DESC_CNT; i += 3, txbd += 3) {
@@ -4978,9 +4979,9 @@ static void cnic_init_bnx2x_rx_ring(struct cnic_dev *dev,
4978 struct bnx2x *bp = netdev_priv(dev->netdev); 4979 struct bnx2x *bp = netdev_priv(dev->netdev);
4979 struct cnic_uio_dev *udev = cp->udev; 4980 struct cnic_uio_dev *udev = cp->udev;
4980 struct eth_rx_bd *rxbd = (struct eth_rx_bd *) (udev->l2_ring + 4981 struct eth_rx_bd *rxbd = (struct eth_rx_bd *) (udev->l2_ring +
4981 BNX2_PAGE_SIZE); 4982 CNIC_PAGE_SIZE);
4982 struct eth_rx_cqe_next_page *rxcqe = (struct eth_rx_cqe_next_page *) 4983 struct eth_rx_cqe_next_page *rxcqe = (struct eth_rx_cqe_next_page *)
4983 (udev->l2_ring + (2 * BNX2_PAGE_SIZE)); 4984 (udev->l2_ring + (2 * CNIC_PAGE_SIZE));
4984 struct host_sp_status_block *sb = cp->bnx2x_def_status_blk; 4985 struct host_sp_status_block *sb = cp->bnx2x_def_status_blk;
4985 int i; 4986 int i;
4986 u32 cli = cp->ethdev->iscsi_l2_client_id; 4987 u32 cli = cp->ethdev->iscsi_l2_client_id;
@@ -5004,20 +5005,20 @@ static void cnic_init_bnx2x_rx_ring(struct cnic_dev *dev,
5004 rxbd->addr_lo = cpu_to_le32(buf_map & 0xffffffff); 5005 rxbd->addr_lo = cpu_to_le32(buf_map & 0xffffffff);
5005 } 5006 }
5006 5007
5007 val = (u64) (ring_map + BNX2_PAGE_SIZE) >> 32; 5008 val = (u64) (ring_map + CNIC_PAGE_SIZE) >> 32;
5008 rxbd->addr_hi = cpu_to_le32(val); 5009 rxbd->addr_hi = cpu_to_le32(val);
5009 data->rx.bd_page_base.hi = cpu_to_le32(val); 5010 data->rx.bd_page_base.hi = cpu_to_le32(val);
5010 5011
5011 val = (u64) (ring_map + BNX2_PAGE_SIZE) & 0xffffffff; 5012 val = (u64) (ring_map + CNIC_PAGE_SIZE) & 0xffffffff;
5012 rxbd->addr_lo = cpu_to_le32(val); 5013 rxbd->addr_lo = cpu_to_le32(val);
5013 data->rx.bd_page_base.lo = cpu_to_le32(val); 5014 data->rx.bd_page_base.lo = cpu_to_le32(val);
5014 5015
5015 rxcqe += BNX2X_MAX_RCQ_DESC_CNT; 5016 rxcqe += BNX2X_MAX_RCQ_DESC_CNT;
5016 val = (u64) (ring_map + (2 * BNX2_PAGE_SIZE)) >> 32; 5017 val = (u64) (ring_map + (2 * CNIC_PAGE_SIZE)) >> 32;
5017 rxcqe->addr_hi = cpu_to_le32(val); 5018 rxcqe->addr_hi = cpu_to_le32(val);
5018 data->rx.cqe_page_base.hi = cpu_to_le32(val); 5019 data->rx.cqe_page_base.hi = cpu_to_le32(val);
5019 5020
5020 val = (u64) (ring_map + (2 * BNX2_PAGE_SIZE)) & 0xffffffff; 5021 val = (u64) (ring_map + (2 * CNIC_PAGE_SIZE)) & 0xffffffff;
5021 rxcqe->addr_lo = cpu_to_le32(val); 5022 rxcqe->addr_lo = cpu_to_le32(val);
5022 data->rx.cqe_page_base.lo = cpu_to_le32(val); 5023 data->rx.cqe_page_base.lo = cpu_to_le32(val);
5023 5024
@@ -5265,8 +5266,8 @@ static void cnic_shutdown_rings(struct cnic_dev *dev)
5265 msleep(10); 5266 msleep(10);
5266 } 5267 }
5267 clear_bit(CNIC_LCL_FL_RINGS_INITED, &cp->cnic_local_flags); 5268 clear_bit(CNIC_LCL_FL_RINGS_INITED, &cp->cnic_local_flags);
5268 rx_ring = udev->l2_ring + BNX2_PAGE_SIZE; 5269 rx_ring = udev->l2_ring + CNIC_PAGE_SIZE;
5269 memset(rx_ring, 0, BNX2_PAGE_SIZE); 5270 memset(rx_ring, 0, CNIC_PAGE_SIZE);
5270} 5271}
5271 5272
5272static int cnic_register_netdev(struct cnic_dev *dev) 5273static int cnic_register_netdev(struct cnic_dev *dev)
diff --git a/drivers/net/ethernet/broadcom/cnic.h b/drivers/net/ethernet/broadcom/cnic.h
index 0d6b13f854d9..d535ae4228b4 100644
--- a/drivers/net/ethernet/broadcom/cnic.h
+++ b/drivers/net/ethernet/broadcom/cnic.h
@@ -1,6 +1,6 @@
1/* cnic.h: Broadcom CNIC core network driver. 1/* cnic.h: Broadcom CNIC core network driver.
2 * 2 *
3 * Copyright (c) 2006-2013 Broadcom Corporation 3 * Copyright (c) 2006-2014 Broadcom Corporation
4 * 4 *
5 * This program is free software; you can redistribute it and/or modify 5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by 6 * it under the terms of the GNU General Public License as published by
diff --git a/drivers/net/ethernet/broadcom/cnic_defs.h b/drivers/net/ethernet/broadcom/cnic_defs.h
index 95a8e4b11c9f..dcbca6997e8f 100644
--- a/drivers/net/ethernet/broadcom/cnic_defs.h
+++ b/drivers/net/ethernet/broadcom/cnic_defs.h
@@ -1,7 +1,7 @@
1 1
2/* cnic.c: Broadcom CNIC core network driver. 2/* cnic.c: Broadcom CNIC core network driver.
3 * 3 *
4 * Copyright (c) 2006-2013 Broadcom Corporation 4 * Copyright (c) 2006-2014 Broadcom Corporation
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
diff --git a/drivers/net/ethernet/broadcom/cnic_if.h b/drivers/net/ethernet/broadcom/cnic_if.h
index 8cf6b1926069..5f4d5573a73d 100644
--- a/drivers/net/ethernet/broadcom/cnic_if.h
+++ b/drivers/net/ethernet/broadcom/cnic_if.h
@@ -1,6 +1,6 @@
1/* cnic_if.h: Broadcom CNIC core network driver. 1/* cnic_if.h: Broadcom CNIC core network driver.
2 * 2 *
3 * Copyright (c) 2006-2013 Broadcom Corporation 3 * Copyright (c) 2006-2014 Broadcom Corporation
4 * 4 *
5 * This program is free software; you can redistribute it and/or modify 5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by 6 * it under the terms of the GNU General Public License as published by
@@ -14,8 +14,8 @@
14 14
15#include "bnx2x/bnx2x_mfw_req.h" 15#include "bnx2x/bnx2x_mfw_req.h"
16 16
17#define CNIC_MODULE_VERSION "2.5.19" 17#define CNIC_MODULE_VERSION "2.5.20"
18#define CNIC_MODULE_RELDATE "December 19, 2013" 18#define CNIC_MODULE_RELDATE "March 14, 2014"
19 19
20#define CNIC_ULP_RDMA 0 20#define CNIC_ULP_RDMA 0
21#define CNIC_ULP_ISCSI 1 21#define CNIC_ULP_ISCSI 1
@@ -24,6 +24,16 @@
24#define MAX_CNIC_ULP_TYPE_EXT 3 24#define MAX_CNIC_ULP_TYPE_EXT 3
25#define MAX_CNIC_ULP_TYPE 4 25#define MAX_CNIC_ULP_TYPE 4
26 26
27/* Use CPU native page size up to 16K for cnic ring sizes. */
28#if (PAGE_SHIFT > 14)
29#define CNIC_PAGE_BITS 14
30#else
31#define CNIC_PAGE_BITS PAGE_SHIFT
32#endif
33#define CNIC_PAGE_SIZE (1 << (CNIC_PAGE_BITS))
34#define CNIC_PAGE_ALIGN(addr) ALIGN(addr, CNIC_PAGE_SIZE)
35#define CNIC_PAGE_MASK (~((CNIC_PAGE_SIZE) - 1))
36
27struct kwqe { 37struct kwqe {
28 u32 kwqe_op_flag; 38 u32 kwqe_op_flag;
29 39
diff --git a/drivers/net/ethernet/broadcom/tg3.c b/drivers/net/ethernet/broadcom/tg3.c
index 3167ed6593b0..70a225c8df5c 100644
--- a/drivers/net/ethernet/broadcom/tg3.c
+++ b/drivers/net/ethernet/broadcom/tg3.c
@@ -6843,8 +6843,7 @@ static int tg3_rx(struct tg3_napi *tnapi, int budget)
6843 6843
6844 work_mask |= opaque_key; 6844 work_mask |= opaque_key;
6845 6845
6846 if ((desc->err_vlan & RXD_ERR_MASK) != 0 && 6846 if (desc->err_vlan & RXD_ERR_MASK) {
6847 (desc->err_vlan != RXD_ERR_ODD_NIBBLE_RCVD_MII)) {
6848 drop_it: 6847 drop_it:
6849 tg3_recycle_rx(tnapi, tpr, opaque_key, 6848 tg3_recycle_rx(tnapi, tpr, opaque_key,
6850 desc_idx, *post_ptr); 6849 desc_idx, *post_ptr);
@@ -17650,8 +17649,6 @@ static int tg3_init_one(struct pci_dev *pdev,
17650 17649
17651 tg3_init_bufmgr_config(tp); 17650 tg3_init_bufmgr_config(tp);
17652 17651
17653 features |= NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX;
17654
17655 /* 5700 B0 chips do not support checksumming correctly due 17652 /* 5700 B0 chips do not support checksumming correctly due
17656 * to hardware bugs. 17653 * to hardware bugs.
17657 */ 17654 */
@@ -17683,7 +17680,8 @@ static int tg3_init_one(struct pci_dev *pdev,
17683 features |= NETIF_F_TSO_ECN; 17680 features |= NETIF_F_TSO_ECN;
17684 } 17681 }
17685 17682
17686 dev->features |= features; 17683 dev->features |= features | NETIF_F_HW_VLAN_CTAG_TX |
17684 NETIF_F_HW_VLAN_CTAG_RX;
17687 dev->vlan_features |= features; 17685 dev->vlan_features |= features;
17688 17686
17689 /* 17687 /*
diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
index ef472385bce4..04321e5a356e 100644
--- a/drivers/net/ethernet/broadcom/tg3.h
+++ b/drivers/net/ethernet/broadcom/tg3.h
@@ -2608,7 +2608,11 @@ struct tg3_rx_buffer_desc {
2608#define RXD_ERR_TOO_SMALL 0x00400000 2608#define RXD_ERR_TOO_SMALL 0x00400000
2609#define RXD_ERR_NO_RESOURCES 0x00800000 2609#define RXD_ERR_NO_RESOURCES 0x00800000
2610#define RXD_ERR_HUGE_FRAME 0x01000000 2610#define RXD_ERR_HUGE_FRAME 0x01000000
2611#define RXD_ERR_MASK 0xffff0000 2611
2612#define RXD_ERR_MASK (RXD_ERR_BAD_CRC | RXD_ERR_COLLISION | \
2613 RXD_ERR_LINK_LOST | RXD_ERR_PHY_DECODE | \
2614 RXD_ERR_MAC_ABRT | RXD_ERR_TOO_SMALL | \
2615 RXD_ERR_NO_RESOURCES | RXD_ERR_HUGE_FRAME)
2612 2616
2613 u32 reserved; 2617 u32 reserved;
2614 u32 opaque; 2618 u32 opaque;
diff --git a/drivers/net/ethernet/brocade/bna/bfa_ioc.c b/drivers/net/ethernet/brocade/bna/bfa_ioc.c
index 1803c3959044..354ae9792bad 100644
--- a/drivers/net/ethernet/brocade/bna/bfa_ioc.c
+++ b/drivers/net/ethernet/brocade/bna/bfa_ioc.c
@@ -1704,7 +1704,7 @@ bfa_flash_sem_get(void __iomem *bar)
1704 while (!bfa_raw_sem_get(bar)) { 1704 while (!bfa_raw_sem_get(bar)) {
1705 if (--n <= 0) 1705 if (--n <= 0)
1706 return BFA_STATUS_BADFLASH; 1706 return BFA_STATUS_BADFLASH;
1707 udelay(10000); 1707 mdelay(10);
1708 } 1708 }
1709 return BFA_STATUS_OK; 1709 return BFA_STATUS_OK;
1710} 1710}
diff --git a/drivers/net/ethernet/brocade/bna/bnad.c b/drivers/net/ethernet/brocade/bna/bnad.c
index cf64f3d0b60d..4ad1187e82fb 100644
--- a/drivers/net/ethernet/brocade/bna/bnad.c
+++ b/drivers/net/ethernet/brocade/bna/bnad.c
@@ -707,7 +707,8 @@ bnad_cq_process(struct bnad *bnad, struct bna_ccb *ccb, int budget)
707 else 707 else
708 skb_checksum_none_assert(skb); 708 skb_checksum_none_assert(skb);
709 709
710 if (flags & BNA_CQ_EF_VLAN) 710 if ((flags & BNA_CQ_EF_VLAN) &&
711 (bnad->netdev->features & NETIF_F_HW_VLAN_CTAG_RX))
711 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), ntohs(cmpl->vlan_tag)); 712 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), ntohs(cmpl->vlan_tag));
712 713
713 if (BNAD_RXBUF_IS_SK_BUFF(unmap_q->type)) 714 if (BNAD_RXBUF_IS_SK_BUFF(unmap_q->type))
@@ -2094,7 +2095,9 @@ bnad_init_rx_config(struct bnad *bnad, struct bna_rx_config *rx_config)
2094 rx_config->q1_buf_size = BFI_SMALL_RXBUF_SIZE; 2095 rx_config->q1_buf_size = BFI_SMALL_RXBUF_SIZE;
2095 } 2096 }
2096 2097
2097 rx_config->vlan_strip_status = BNA_STATUS_T_ENABLED; 2098 rx_config->vlan_strip_status =
2099 (bnad->netdev->features & NETIF_F_HW_VLAN_CTAG_RX) ?
2100 BNA_STATUS_T_ENABLED : BNA_STATUS_T_DISABLED;
2098} 2101}
2099 2102
2100static void 2103static void
@@ -3245,11 +3248,6 @@ bnad_set_rx_mode(struct net_device *netdev)
3245 BNA_RXMODE_ALLMULTI; 3248 BNA_RXMODE_ALLMULTI;
3246 bna_rx_mode_set(bnad->rx_info[0].rx, new_mode, mode_mask, NULL); 3249 bna_rx_mode_set(bnad->rx_info[0].rx, new_mode, mode_mask, NULL);
3247 3250
3248 if (bnad->cfg_flags & BNAD_CF_PROMISC)
3249 bna_rx_vlan_strip_disable(bnad->rx_info[0].rx);
3250 else
3251 bna_rx_vlan_strip_enable(bnad->rx_info[0].rx);
3252
3253 spin_unlock_irqrestore(&bnad->bna_lock, flags); 3251 spin_unlock_irqrestore(&bnad->bna_lock, flags);
3254} 3252}
3255 3253
@@ -3374,6 +3372,27 @@ bnad_vlan_rx_kill_vid(struct net_device *netdev, __be16 proto, u16 vid)
3374 return 0; 3372 return 0;
3375} 3373}
3376 3374
3375static int bnad_set_features(struct net_device *dev, netdev_features_t features)
3376{
3377 struct bnad *bnad = netdev_priv(dev);
3378 netdev_features_t changed = features ^ dev->features;
3379
3380 if ((changed & NETIF_F_HW_VLAN_CTAG_RX) && netif_running(dev)) {
3381 unsigned long flags;
3382
3383 spin_lock_irqsave(&bnad->bna_lock, flags);
3384
3385 if (features & NETIF_F_HW_VLAN_CTAG_RX)
3386 bna_rx_vlan_strip_enable(bnad->rx_info[0].rx);
3387 else
3388 bna_rx_vlan_strip_disable(bnad->rx_info[0].rx);
3389
3390 spin_unlock_irqrestore(&bnad->bna_lock, flags);
3391 }
3392
3393 return 0;
3394}
3395
3377#ifdef CONFIG_NET_POLL_CONTROLLER 3396#ifdef CONFIG_NET_POLL_CONTROLLER
3378static void 3397static void
3379bnad_netpoll(struct net_device *netdev) 3398bnad_netpoll(struct net_device *netdev)
@@ -3421,6 +3440,7 @@ static const struct net_device_ops bnad_netdev_ops = {
3421 .ndo_change_mtu = bnad_change_mtu, 3440 .ndo_change_mtu = bnad_change_mtu,
3422 .ndo_vlan_rx_add_vid = bnad_vlan_rx_add_vid, 3441 .ndo_vlan_rx_add_vid = bnad_vlan_rx_add_vid,
3423 .ndo_vlan_rx_kill_vid = bnad_vlan_rx_kill_vid, 3442 .ndo_vlan_rx_kill_vid = bnad_vlan_rx_kill_vid,
3443 .ndo_set_features = bnad_set_features,
3424#ifdef CONFIG_NET_POLL_CONTROLLER 3444#ifdef CONFIG_NET_POLL_CONTROLLER
3425 .ndo_poll_controller = bnad_netpoll 3445 .ndo_poll_controller = bnad_netpoll
3426#endif 3446#endif
@@ -3433,14 +3453,14 @@ bnad_netdev_init(struct bnad *bnad, bool using_dac)
3433 3453
3434 netdev->hw_features = NETIF_F_SG | NETIF_F_RXCSUM | 3454 netdev->hw_features = NETIF_F_SG | NETIF_F_RXCSUM |
3435 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | 3455 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
3436 NETIF_F_TSO | NETIF_F_TSO6 | NETIF_F_HW_VLAN_CTAG_TX; 3456 NETIF_F_TSO | NETIF_F_TSO6 | NETIF_F_HW_VLAN_CTAG_TX |
3457 NETIF_F_HW_VLAN_CTAG_RX;
3437 3458
3438 netdev->vlan_features = NETIF_F_SG | NETIF_F_HIGHDMA | 3459 netdev->vlan_features = NETIF_F_SG | NETIF_F_HIGHDMA |
3439 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | 3460 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
3440 NETIF_F_TSO | NETIF_F_TSO6; 3461 NETIF_F_TSO | NETIF_F_TSO6;
3441 3462
3442 netdev->features |= netdev->hw_features | 3463 netdev->features |= netdev->hw_features | NETIF_F_HW_VLAN_CTAG_FILTER;
3443 NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_CTAG_FILTER;
3444 3464
3445 if (using_dac) 3465 if (using_dac)
3446 netdev->features |= NETIF_F_HIGHDMA; 3466 netdev->features |= NETIF_F_HIGHDMA;
diff --git a/drivers/net/ethernet/cadence/macb.c b/drivers/net/ethernet/cadence/macb.c
index 3190d38e16fb..d0c38e01e99f 100644
--- a/drivers/net/ethernet/cadence/macb.c
+++ b/drivers/net/ethernet/cadence/macb.c
@@ -632,11 +632,16 @@ static void gem_rx_refill(struct macb *bp)
632 "Unable to allocate sk_buff\n"); 632 "Unable to allocate sk_buff\n");
633 break; 633 break;
634 } 634 }
635 bp->rx_skbuff[entry] = skb;
636 635
637 /* now fill corresponding descriptor entry */ 636 /* now fill corresponding descriptor entry */
638 paddr = dma_map_single(&bp->pdev->dev, skb->data, 637 paddr = dma_map_single(&bp->pdev->dev, skb->data,
639 bp->rx_buffer_size, DMA_FROM_DEVICE); 638 bp->rx_buffer_size, DMA_FROM_DEVICE);
639 if (dma_mapping_error(&bp->pdev->dev, paddr)) {
640 dev_kfree_skb(skb);
641 break;
642 }
643
644 bp->rx_skbuff[entry] = skb;
640 645
641 if (entry == RX_RING_SIZE - 1) 646 if (entry == RX_RING_SIZE - 1)
642 paddr |= MACB_BIT(RX_WRAP); 647 paddr |= MACB_BIT(RX_WRAP);
@@ -725,7 +730,7 @@ static int gem_rx(struct macb *bp, int budget)
725 skb_put(skb, len); 730 skb_put(skb, len);
726 addr = MACB_BF(RX_WADDR, MACB_BFEXT(RX_WADDR, addr)); 731 addr = MACB_BF(RX_WADDR, MACB_BFEXT(RX_WADDR, addr));
727 dma_unmap_single(&bp->pdev->dev, addr, 732 dma_unmap_single(&bp->pdev->dev, addr,
728 len, DMA_FROM_DEVICE); 733 bp->rx_buffer_size, DMA_FROM_DEVICE);
729 734
730 skb->protocol = eth_type_trans(skb, bp->dev); 735 skb->protocol = eth_type_trans(skb, bp->dev);
731 skb_checksum_none_assert(skb); 736 skb_checksum_none_assert(skb);
@@ -1036,11 +1041,15 @@ static int macb_start_xmit(struct sk_buff *skb, struct net_device *dev)
1036 } 1041 }
1037 1042
1038 entry = macb_tx_ring_wrap(bp->tx_head); 1043 entry = macb_tx_ring_wrap(bp->tx_head);
1039 bp->tx_head++;
1040 netdev_vdbg(bp->dev, "Allocated ring entry %u\n", entry); 1044 netdev_vdbg(bp->dev, "Allocated ring entry %u\n", entry);
1041 mapping = dma_map_single(&bp->pdev->dev, skb->data, 1045 mapping = dma_map_single(&bp->pdev->dev, skb->data,
1042 len, DMA_TO_DEVICE); 1046 len, DMA_TO_DEVICE);
1047 if (dma_mapping_error(&bp->pdev->dev, mapping)) {
1048 kfree_skb(skb);
1049 goto unlock;
1050 }
1043 1051
1052 bp->tx_head++;
1044 tx_skb = &bp->tx_skb[entry]; 1053 tx_skb = &bp->tx_skb[entry];
1045 tx_skb->skb = skb; 1054 tx_skb->skb = skb;
1046 tx_skb->mapping = mapping; 1055 tx_skb->mapping = mapping;
@@ -1066,6 +1075,7 @@ static int macb_start_xmit(struct sk_buff *skb, struct net_device *dev)
1066 if (CIRC_SPACE(bp->tx_head, bp->tx_tail, TX_RING_SIZE) < 1) 1075 if (CIRC_SPACE(bp->tx_head, bp->tx_tail, TX_RING_SIZE) < 1)
1067 netif_stop_queue(dev); 1076 netif_stop_queue(dev);
1068 1077
1078unlock:
1069 spin_unlock_irqrestore(&bp->lock, flags); 1079 spin_unlock_irqrestore(&bp->lock, flags);
1070 1080
1071 return NETDEV_TX_OK; 1081 return NETDEV_TX_OK;
diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
index 43ab35fea48d..34e2488767d9 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
@@ -6179,6 +6179,7 @@ static struct pci_driver cxgb4_driver = {
6179 .id_table = cxgb4_pci_tbl, 6179 .id_table = cxgb4_pci_tbl,
6180 .probe = init_one, 6180 .probe = init_one,
6181 .remove = remove_one, 6181 .remove = remove_one,
6182 .shutdown = remove_one,
6182 .err_handler = &cxgb4_eeh, 6183 .err_handler = &cxgb4_eeh,
6183}; 6184};
6184 6185
diff --git a/drivers/net/ethernet/emulex/benet/be.h b/drivers/net/ethernet/emulex/benet/be.h
index 8d09615da585..05529e273050 100644
--- a/drivers/net/ethernet/emulex/benet/be.h
+++ b/drivers/net/ethernet/emulex/benet/be.h
@@ -350,11 +350,13 @@ struct be_drv_stats {
350 u32 roce_drops_crc; 350 u32 roce_drops_crc;
351}; 351};
352 352
353/* A vlan-id of 0xFFFF must be used to clear transparent vlan-tagging */
354#define BE_RESET_VLAN_TAG_ID 0xFFFF
355
353struct be_vf_cfg { 356struct be_vf_cfg {
354 unsigned char mac_addr[ETH_ALEN]; 357 unsigned char mac_addr[ETH_ALEN];
355 int if_handle; 358 int if_handle;
356 int pmac_id; 359 int pmac_id;
357 u16 def_vid;
358 u16 vlan_tag; 360 u16 vlan_tag;
359 u32 tx_rate; 361 u32 tx_rate;
360}; 362};
diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
index 04ac9c6a0d39..36c80612e21a 100644
--- a/drivers/net/ethernet/emulex/benet/be_main.c
+++ b/drivers/net/ethernet/emulex/benet/be_main.c
@@ -913,24 +913,14 @@ static int be_ipv6_tx_stall_chk(struct be_adapter *adapter,
913 return BE3_chip(adapter) && be_ipv6_exthdr_check(skb); 913 return BE3_chip(adapter) && be_ipv6_exthdr_check(skb);
914} 914}
915 915
916static struct sk_buff *be_xmit_workarounds(struct be_adapter *adapter, 916static struct sk_buff *be_lancer_xmit_workarounds(struct be_adapter *adapter,
917 struct sk_buff *skb, 917 struct sk_buff *skb,
918 bool *skip_hw_vlan) 918 bool *skip_hw_vlan)
919{ 919{
920 struct vlan_ethhdr *veh = (struct vlan_ethhdr *)skb->data; 920 struct vlan_ethhdr *veh = (struct vlan_ethhdr *)skb->data;
921 unsigned int eth_hdr_len; 921 unsigned int eth_hdr_len;
922 struct iphdr *ip; 922 struct iphdr *ip;
923 923
924 /* Lancer, SH-R ASICs have a bug wherein Packets that are 32 bytes or less
925 * may cause a transmit stall on that port. So the work-around is to
926 * pad short packets (<= 32 bytes) to a 36-byte length.
927 */
928 if (unlikely(!BEx_chip(adapter) && skb->len <= 32)) {
929 if (skb_padto(skb, 36))
930 goto tx_drop;
931 skb->len = 36;
932 }
933
934 /* For padded packets, BE HW modifies tot_len field in IP header 924 /* For padded packets, BE HW modifies tot_len field in IP header
935 * incorrecly when VLAN tag is inserted by HW. 925 * incorrecly when VLAN tag is inserted by HW.
936 * For padded packets, Lancer computes incorrect checksum. 926 * For padded packets, Lancer computes incorrect checksum.
@@ -959,7 +949,7 @@ static struct sk_buff *be_xmit_workarounds(struct be_adapter *adapter,
959 vlan_tx_tag_present(skb)) { 949 vlan_tx_tag_present(skb)) {
960 skb = be_insert_vlan_in_pkt(adapter, skb, skip_hw_vlan); 950 skb = be_insert_vlan_in_pkt(adapter, skb, skip_hw_vlan);
961 if (unlikely(!skb)) 951 if (unlikely(!skb))
962 goto tx_drop; 952 goto err;
963 } 953 }
964 954
965 /* HW may lockup when VLAN HW tagging is requested on 955 /* HW may lockup when VLAN HW tagging is requested on
@@ -981,15 +971,39 @@ static struct sk_buff *be_xmit_workarounds(struct be_adapter *adapter,
981 be_vlan_tag_tx_chk(adapter, skb)) { 971 be_vlan_tag_tx_chk(adapter, skb)) {
982 skb = be_insert_vlan_in_pkt(adapter, skb, skip_hw_vlan); 972 skb = be_insert_vlan_in_pkt(adapter, skb, skip_hw_vlan);
983 if (unlikely(!skb)) 973 if (unlikely(!skb))
984 goto tx_drop; 974 goto err;
985 } 975 }
986 976
987 return skb; 977 return skb;
988tx_drop: 978tx_drop:
989 dev_kfree_skb_any(skb); 979 dev_kfree_skb_any(skb);
980err:
990 return NULL; 981 return NULL;
991} 982}
992 983
984static struct sk_buff *be_xmit_workarounds(struct be_adapter *adapter,
985 struct sk_buff *skb,
986 bool *skip_hw_vlan)
987{
988 /* Lancer, SH-R ASICs have a bug wherein Packets that are 32 bytes or
989 * less may cause a transmit stall on that port. So the work-around is
990 * to pad short packets (<= 32 bytes) to a 36-byte length.
991 */
992 if (unlikely(!BEx_chip(adapter) && skb->len <= 32)) {
993 if (skb_padto(skb, 36))
994 return NULL;
995 skb->len = 36;
996 }
997
998 if (BEx_chip(adapter) || lancer_chip(adapter)) {
999 skb = be_lancer_xmit_workarounds(adapter, skb, skip_hw_vlan);
1000 if (!skb)
1001 return NULL;
1002 }
1003
1004 return skb;
1005}
1006
993static netdev_tx_t be_xmit(struct sk_buff *skb, struct net_device *netdev) 1007static netdev_tx_t be_xmit(struct sk_buff *skb, struct net_device *netdev)
994{ 1008{
995 struct be_adapter *adapter = netdev_priv(netdev); 1009 struct be_adapter *adapter = netdev_priv(netdev);
@@ -1157,6 +1171,14 @@ ret:
1157 return status; 1171 return status;
1158} 1172}
1159 1173
1174static void be_clear_promisc(struct be_adapter *adapter)
1175{
1176 adapter->promiscuous = false;
1177 adapter->flags &= ~BE_FLAGS_VLAN_PROMISC;
1178
1179 be_cmd_rx_filter(adapter, IFF_PROMISC, OFF);
1180}
1181
1160static void be_set_rx_mode(struct net_device *netdev) 1182static void be_set_rx_mode(struct net_device *netdev)
1161{ 1183{
1162 struct be_adapter *adapter = netdev_priv(netdev); 1184 struct be_adapter *adapter = netdev_priv(netdev);
@@ -1170,9 +1192,7 @@ static void be_set_rx_mode(struct net_device *netdev)
1170 1192
1171 /* BE was previously in promiscuous mode; disable it */ 1193 /* BE was previously in promiscuous mode; disable it */
1172 if (adapter->promiscuous) { 1194 if (adapter->promiscuous) {
1173 adapter->promiscuous = false; 1195 be_clear_promisc(adapter);
1174 be_cmd_rx_filter(adapter, IFF_PROMISC, OFF);
1175
1176 if (adapter->vlans_added) 1196 if (adapter->vlans_added)
1177 be_vid_config(adapter); 1197 be_vid_config(adapter);
1178 } 1198 }
@@ -1287,24 +1307,20 @@ static int be_set_vf_vlan(struct net_device *netdev,
1287 1307
1288 if (vlan || qos) { 1308 if (vlan || qos) {
1289 vlan |= qos << VLAN_PRIO_SHIFT; 1309 vlan |= qos << VLAN_PRIO_SHIFT;
1290 if (vf_cfg->vlan_tag != vlan) { 1310 if (vf_cfg->vlan_tag != vlan)
1291 /* If this is new value, program it. Else skip. */
1292 vf_cfg->vlan_tag = vlan;
1293 status = be_cmd_set_hsw_config(adapter, vlan, vf + 1, 1311 status = be_cmd_set_hsw_config(adapter, vlan, vf + 1,
1294 vf_cfg->if_handle, 0); 1312 vf_cfg->if_handle, 0);
1295 }
1296 } else { 1313 } else {
1297 /* Reset Transparent Vlan Tagging. */ 1314 /* Reset Transparent Vlan Tagging. */
1298 vf_cfg->vlan_tag = 0; 1315 status = be_cmd_set_hsw_config(adapter, BE_RESET_VLAN_TAG_ID,
1299 vlan = vf_cfg->def_vid; 1316 vf + 1, vf_cfg->if_handle, 0);
1300 status = be_cmd_set_hsw_config(adapter, vlan, vf + 1,
1301 vf_cfg->if_handle, 0);
1302 } 1317 }
1303 1318
1304 1319 if (!status)
1305 if (status) 1320 vf_cfg->vlan_tag = vlan;
1321 else
1306 dev_info(&adapter->pdev->dev, 1322 dev_info(&adapter->pdev->dev,
1307 "VLAN %d config on VF %d failed\n", vlan, vf); 1323 "VLAN %d config on VF %d failed\n", vlan, vf);
1308 return status; 1324 return status;
1309} 1325}
1310 1326
@@ -3013,11 +3029,11 @@ static int be_vf_setup_init(struct be_adapter *adapter)
3013 3029
3014static int be_vf_setup(struct be_adapter *adapter) 3030static int be_vf_setup(struct be_adapter *adapter)
3015{ 3031{
3032 struct device *dev = &adapter->pdev->dev;
3016 struct be_vf_cfg *vf_cfg; 3033 struct be_vf_cfg *vf_cfg;
3017 u16 def_vlan, lnk_speed;
3018 int status, old_vfs, vf; 3034 int status, old_vfs, vf;
3019 struct device *dev = &adapter->pdev->dev;
3020 u32 privileges; 3035 u32 privileges;
3036 u16 lnk_speed;
3021 3037
3022 old_vfs = pci_num_vf(adapter->pdev); 3038 old_vfs = pci_num_vf(adapter->pdev);
3023 if (old_vfs) { 3039 if (old_vfs) {
@@ -3084,12 +3100,6 @@ static int be_vf_setup(struct be_adapter *adapter)
3084 if (!status) 3100 if (!status)
3085 vf_cfg->tx_rate = lnk_speed; 3101 vf_cfg->tx_rate = lnk_speed;
3086 3102
3087 status = be_cmd_get_hsw_config(adapter, &def_vlan,
3088 vf + 1, vf_cfg->if_handle, NULL);
3089 if (status)
3090 goto err;
3091 vf_cfg->def_vid = def_vlan;
3092
3093 if (!old_vfs) 3103 if (!old_vfs)
3094 be_cmd_enable_vf(adapter, vf + 1); 3104 be_cmd_enable_vf(adapter, vf + 1);
3095 } 3105 }
diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c
index 903362a7b584..03a351300013 100644
--- a/drivers/net/ethernet/freescale/fec_main.c
+++ b/drivers/net/ethernet/freescale/fec_main.c
@@ -389,12 +389,6 @@ fec_enet_start_xmit(struct sk_buff *skb, struct net_device *ndev)
389 netdev_err(ndev, "Tx DMA memory map failed\n"); 389 netdev_err(ndev, "Tx DMA memory map failed\n");
390 return NETDEV_TX_OK; 390 return NETDEV_TX_OK;
391 } 391 }
392 /* Send it on its way. Tell FEC it's ready, interrupt when done,
393 * it's the last BD of the frame, and to put the CRC on the end.
394 */
395 status |= (BD_ENET_TX_READY | BD_ENET_TX_INTR
396 | BD_ENET_TX_LAST | BD_ENET_TX_TC);
397 bdp->cbd_sc = status;
398 392
399 if (fep->bufdesc_ex) { 393 if (fep->bufdesc_ex) {
400 394
@@ -416,6 +410,13 @@ fec_enet_start_xmit(struct sk_buff *skb, struct net_device *ndev)
416 } 410 }
417 } 411 }
418 412
413 /* Send it on its way. Tell FEC it's ready, interrupt when done,
414 * it's the last BD of the frame, and to put the CRC on the end.
415 */
416 status |= (BD_ENET_TX_READY | BD_ENET_TX_INTR
417 | BD_ENET_TX_LAST | BD_ENET_TX_TC);
418 bdp->cbd_sc = status;
419
419 bdp_pre = fec_enet_get_prevdesc(bdp, fep); 420 bdp_pre = fec_enet_get_prevdesc(bdp, fep);
420 if ((id_entry->driver_data & FEC_QUIRK_ERR006358) && 421 if ((id_entry->driver_data & FEC_QUIRK_ERR006358) &&
421 !(bdp_pre->cbd_sc & BD_ENET_TX_READY)) { 422 !(bdp_pre->cbd_sc & BD_ENET_TX_READY)) {
@@ -527,13 +528,6 @@ fec_restart(struct net_device *ndev, int duplex)
527 /* Clear any outstanding interrupt. */ 528 /* Clear any outstanding interrupt. */
528 writel(0xffc00000, fep->hwp + FEC_IEVENT); 529 writel(0xffc00000, fep->hwp + FEC_IEVENT);
529 530
530 /* Setup multicast filter. */
531 set_multicast_list(ndev);
532#ifndef CONFIG_M5272
533 writel(0, fep->hwp + FEC_HASH_TABLE_HIGH);
534 writel(0, fep->hwp + FEC_HASH_TABLE_LOW);
535#endif
536
537 /* Set maximum receive buffer size. */ 531 /* Set maximum receive buffer size. */
538 writel(PKT_MAXBLR_SIZE, fep->hwp + FEC_R_BUFF_SIZE); 532 writel(PKT_MAXBLR_SIZE, fep->hwp + FEC_R_BUFF_SIZE);
539 533
@@ -654,6 +648,13 @@ fec_restart(struct net_device *ndev, int duplex)
654 648
655 writel(rcntl, fep->hwp + FEC_R_CNTRL); 649 writel(rcntl, fep->hwp + FEC_R_CNTRL);
656 650
651 /* Setup multicast filter. */
652 set_multicast_list(ndev);
653#ifndef CONFIG_M5272
654 writel(0, fep->hwp + FEC_HASH_TABLE_HIGH);
655 writel(0, fep->hwp + FEC_HASH_TABLE_LOW);
656#endif
657
657 if (id_entry->driver_data & FEC_QUIRK_ENET_MAC) { 658 if (id_entry->driver_data & FEC_QUIRK_ENET_MAC) {
658 /* enable ENET endian swap */ 659 /* enable ENET endian swap */
659 ecntl |= (1 << 8); 660 ecntl |= (1 << 8);
diff --git a/drivers/net/ethernet/ibm/ibmveth.c b/drivers/net/ethernet/ibm/ibmveth.c
index 4be971590461..1fc8334fc181 100644
--- a/drivers/net/ethernet/ibm/ibmveth.c
+++ b/drivers/net/ethernet/ibm/ibmveth.c
@@ -522,10 +522,21 @@ retry:
522 return rc; 522 return rc;
523} 523}
524 524
525static u64 ibmveth_encode_mac_addr(u8 *mac)
526{
527 int i;
528 u64 encoded = 0;
529
530 for (i = 0; i < ETH_ALEN; i++)
531 encoded = (encoded << 8) | mac[i];
532
533 return encoded;
534}
535
525static int ibmveth_open(struct net_device *netdev) 536static int ibmveth_open(struct net_device *netdev)
526{ 537{
527 struct ibmveth_adapter *adapter = netdev_priv(netdev); 538 struct ibmveth_adapter *adapter = netdev_priv(netdev);
528 u64 mac_address = 0; 539 u64 mac_address;
529 int rxq_entries = 1; 540 int rxq_entries = 1;
530 unsigned long lpar_rc; 541 unsigned long lpar_rc;
531 int rc; 542 int rc;
@@ -579,8 +590,7 @@ static int ibmveth_open(struct net_device *netdev)
579 adapter->rx_queue.num_slots = rxq_entries; 590 adapter->rx_queue.num_slots = rxq_entries;
580 adapter->rx_queue.toggle = 1; 591 adapter->rx_queue.toggle = 1;
581 592
582 memcpy(&mac_address, netdev->dev_addr, netdev->addr_len); 593 mac_address = ibmveth_encode_mac_addr(netdev->dev_addr);
583 mac_address = mac_address >> 16;
584 594
585 rxq_desc.fields.flags_len = IBMVETH_BUF_VALID | 595 rxq_desc.fields.flags_len = IBMVETH_BUF_VALID |
586 adapter->rx_queue.queue_len; 596 adapter->rx_queue.queue_len;
@@ -1183,8 +1193,8 @@ static void ibmveth_set_multicast_list(struct net_device *netdev)
1183 /* add the addresses to the filter table */ 1193 /* add the addresses to the filter table */
1184 netdev_for_each_mc_addr(ha, netdev) { 1194 netdev_for_each_mc_addr(ha, netdev) {
1185 /* add the multicast address to the filter table */ 1195 /* add the multicast address to the filter table */
1186 unsigned long mcast_addr = 0; 1196 u64 mcast_addr;
1187 memcpy(((char *)&mcast_addr)+2, ha->addr, ETH_ALEN); 1197 mcast_addr = ibmveth_encode_mac_addr(ha->addr);
1188 lpar_rc = h_multicast_ctrl(adapter->vdev->unit_address, 1198 lpar_rc = h_multicast_ctrl(adapter->vdev->unit_address,
1189 IbmVethMcastAddFilter, 1199 IbmVethMcastAddFilter,
1190 mcast_addr); 1200 mcast_addr);
@@ -1372,9 +1382,6 @@ static int ibmveth_probe(struct vio_dev *dev, const struct vio_device_id *id)
1372 1382
1373 netif_napi_add(netdev, &adapter->napi, ibmveth_poll, 16); 1383 netif_napi_add(netdev, &adapter->napi, ibmveth_poll, 16);
1374 1384
1375 adapter->mac_addr = 0;
1376 memcpy(&adapter->mac_addr, mac_addr_p, ETH_ALEN);
1377
1378 netdev->irq = dev->irq; 1385 netdev->irq = dev->irq;
1379 netdev->netdev_ops = &ibmveth_netdev_ops; 1386 netdev->netdev_ops = &ibmveth_netdev_ops;
1380 netdev->ethtool_ops = &netdev_ethtool_ops; 1387 netdev->ethtool_ops = &netdev_ethtool_ops;
@@ -1383,7 +1390,7 @@ static int ibmveth_probe(struct vio_dev *dev, const struct vio_device_id *id)
1383 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM; 1390 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
1384 netdev->features |= netdev->hw_features; 1391 netdev->features |= netdev->hw_features;
1385 1392
1386 memcpy(netdev->dev_addr, &adapter->mac_addr, netdev->addr_len); 1393 memcpy(netdev->dev_addr, mac_addr_p, ETH_ALEN);
1387 1394
1388 for (i = 0; i < IBMVETH_NUM_BUFF_POOLS; i++) { 1395 for (i = 0; i < IBMVETH_NUM_BUFF_POOLS; i++) {
1389 struct kobject *kobj = &adapter->rx_buff_pool[i].kobj; 1396 struct kobject *kobj = &adapter->rx_buff_pool[i].kobj;
diff --git a/drivers/net/ethernet/ibm/ibmveth.h b/drivers/net/ethernet/ibm/ibmveth.h
index 451ba7949e15..1f37499d4398 100644
--- a/drivers/net/ethernet/ibm/ibmveth.h
+++ b/drivers/net/ethernet/ibm/ibmveth.h
@@ -138,7 +138,6 @@ struct ibmveth_adapter {
138 struct napi_struct napi; 138 struct napi_struct napi;
139 struct net_device_stats stats; 139 struct net_device_stats stats;
140 unsigned int mcastFilterSize; 140 unsigned int mcastFilterSize;
141 unsigned long mac_addr;
142 void * buffer_list_addr; 141 void * buffer_list_addr;
143 void * filter_list_addr; 142 void * filter_list_addr;
144 dma_addr_t buffer_list_dma; 143 dma_addr_t buffer_list_dma;
diff --git a/drivers/net/ethernet/marvell/mvneta.c b/drivers/net/ethernet/marvell/mvneta.c
index f418f4f20f94..8d76fca7fde7 100644
--- a/drivers/net/ethernet/marvell/mvneta.c
+++ b/drivers/net/ethernet/marvell/mvneta.c
@@ -22,6 +22,7 @@
22#include <linux/interrupt.h> 22#include <linux/interrupt.h>
23#include <net/ip.h> 23#include <net/ip.h>
24#include <net/ipv6.h> 24#include <net/ipv6.h>
25#include <linux/io.h>
25#include <linux/of.h> 26#include <linux/of.h>
26#include <linux/of_irq.h> 27#include <linux/of_irq.h>
27#include <linux/of_mdio.h> 28#include <linux/of_mdio.h>
@@ -88,8 +89,9 @@
88#define MVNETA_TX_IN_PRGRS BIT(1) 89#define MVNETA_TX_IN_PRGRS BIT(1)
89#define MVNETA_TX_FIFO_EMPTY BIT(8) 90#define MVNETA_TX_FIFO_EMPTY BIT(8)
90#define MVNETA_RX_MIN_FRAME_SIZE 0x247c 91#define MVNETA_RX_MIN_FRAME_SIZE 0x247c
91#define MVNETA_SGMII_SERDES_CFG 0x24A0 92#define MVNETA_SERDES_CFG 0x24A0
92#define MVNETA_SGMII_SERDES_PROTO 0x0cc7 93#define MVNETA_SGMII_SERDES_PROTO 0x0cc7
94#define MVNETA_RGMII_SERDES_PROTO 0x0667
93#define MVNETA_TYPE_PRIO 0x24bc 95#define MVNETA_TYPE_PRIO 0x24bc
94#define MVNETA_FORCE_UNI BIT(21) 96#define MVNETA_FORCE_UNI BIT(21)
95#define MVNETA_TXQ_CMD_1 0x24e4 97#define MVNETA_TXQ_CMD_1 0x24e4
@@ -161,7 +163,7 @@
161#define MVNETA_GMAC_MAX_RX_SIZE_MASK 0x7ffc 163#define MVNETA_GMAC_MAX_RX_SIZE_MASK 0x7ffc
162#define MVNETA_GMAC0_PORT_ENABLE BIT(0) 164#define MVNETA_GMAC0_PORT_ENABLE BIT(0)
163#define MVNETA_GMAC_CTRL_2 0x2c08 165#define MVNETA_GMAC_CTRL_2 0x2c08
164#define MVNETA_GMAC2_PSC_ENABLE BIT(3) 166#define MVNETA_GMAC2_PCS_ENABLE BIT(3)
165#define MVNETA_GMAC2_PORT_RGMII BIT(4) 167#define MVNETA_GMAC2_PORT_RGMII BIT(4)
166#define MVNETA_GMAC2_PORT_RESET BIT(6) 168#define MVNETA_GMAC2_PORT_RESET BIT(6)
167#define MVNETA_GMAC_STATUS 0x2c10 169#define MVNETA_GMAC_STATUS 0x2c10
@@ -710,35 +712,6 @@ static void mvneta_rxq_bm_disable(struct mvneta_port *pp,
710 mvreg_write(pp, MVNETA_RXQ_CONFIG_REG(rxq->id), val); 712 mvreg_write(pp, MVNETA_RXQ_CONFIG_REG(rxq->id), val);
711} 713}
712 714
713
714
715/* Sets the RGMII Enable bit (RGMIIEn) in port MAC control register */
716static void mvneta_gmac_rgmii_set(struct mvneta_port *pp, int enable)
717{
718 u32 val;
719
720 val = mvreg_read(pp, MVNETA_GMAC_CTRL_2);
721
722 if (enable)
723 val |= MVNETA_GMAC2_PORT_RGMII;
724 else
725 val &= ~MVNETA_GMAC2_PORT_RGMII;
726
727 mvreg_write(pp, MVNETA_GMAC_CTRL_2, val);
728}
729
730/* Config SGMII port */
731static void mvneta_port_sgmii_config(struct mvneta_port *pp)
732{
733 u32 val;
734
735 val = mvreg_read(pp, MVNETA_GMAC_CTRL_2);
736 val |= MVNETA_GMAC2_PSC_ENABLE;
737 mvreg_write(pp, MVNETA_GMAC_CTRL_2, val);
738
739 mvreg_write(pp, MVNETA_SGMII_SERDES_CFG, MVNETA_SGMII_SERDES_PROTO);
740}
741
742/* Start the Ethernet port RX and TX activity */ 715/* Start the Ethernet port RX and TX activity */
743static void mvneta_port_up(struct mvneta_port *pp) 716static void mvneta_port_up(struct mvneta_port *pp)
744{ 717{
@@ -2756,12 +2729,15 @@ static void mvneta_port_power_up(struct mvneta_port *pp, int phy_mode)
2756 mvreg_write(pp, MVNETA_UNIT_INTR_CAUSE, 0); 2729 mvreg_write(pp, MVNETA_UNIT_INTR_CAUSE, 0);
2757 2730
2758 if (phy_mode == PHY_INTERFACE_MODE_SGMII) 2731 if (phy_mode == PHY_INTERFACE_MODE_SGMII)
2759 mvneta_port_sgmii_config(pp); 2732 mvreg_write(pp, MVNETA_SERDES_CFG, MVNETA_SGMII_SERDES_PROTO);
2733 else
2734 mvreg_write(pp, MVNETA_SERDES_CFG, MVNETA_RGMII_SERDES_PROTO);
2735
2736 val = mvreg_read(pp, MVNETA_GMAC_CTRL_2);
2760 2737
2761 mvneta_gmac_rgmii_set(pp, 1); 2738 val |= MVNETA_GMAC2_PCS_ENABLE | MVNETA_GMAC2_PORT_RGMII;
2762 2739
2763 /* Cancel Port Reset */ 2740 /* Cancel Port Reset */
2764 val = mvreg_read(pp, MVNETA_GMAC_CTRL_2);
2765 val &= ~MVNETA_GMAC2_PORT_RESET; 2741 val &= ~MVNETA_GMAC2_PORT_RESET;
2766 mvreg_write(pp, MVNETA_GMAC_CTRL_2, val); 2742 mvreg_write(pp, MVNETA_GMAC_CTRL_2, val);
2767 2743
@@ -2774,6 +2750,7 @@ static void mvneta_port_power_up(struct mvneta_port *pp, int phy_mode)
2774static int mvneta_probe(struct platform_device *pdev) 2750static int mvneta_probe(struct platform_device *pdev)
2775{ 2751{
2776 const struct mbus_dram_target_info *dram_target_info; 2752 const struct mbus_dram_target_info *dram_target_info;
2753 struct resource *res;
2777 struct device_node *dn = pdev->dev.of_node; 2754 struct device_node *dn = pdev->dev.of_node;
2778 struct device_node *phy_node; 2755 struct device_node *phy_node;
2779 u32 phy_addr; 2756 u32 phy_addr;
@@ -2838,9 +2815,15 @@ static int mvneta_probe(struct platform_device *pdev)
2838 2815
2839 clk_prepare_enable(pp->clk); 2816 clk_prepare_enable(pp->clk);
2840 2817
2841 pp->base = of_iomap(dn, 0); 2818 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
2819 if (!res) {
2820 err = -ENODEV;
2821 goto err_clk;
2822 }
2823
2824 pp->base = devm_ioremap_resource(&pdev->dev, res);
2842 if (pp->base == NULL) { 2825 if (pp->base == NULL) {
2843 err = -ENOMEM; 2826 err = PTR_ERR(pp->base);
2844 goto err_clk; 2827 goto err_clk;
2845 } 2828 }
2846 2829
@@ -2848,7 +2831,7 @@ static int mvneta_probe(struct platform_device *pdev)
2848 pp->stats = alloc_percpu(struct mvneta_pcpu_stats); 2831 pp->stats = alloc_percpu(struct mvneta_pcpu_stats);
2849 if (!pp->stats) { 2832 if (!pp->stats) {
2850 err = -ENOMEM; 2833 err = -ENOMEM;
2851 goto err_unmap; 2834 goto err_clk;
2852 } 2835 }
2853 2836
2854 for_each_possible_cpu(cpu) { 2837 for_each_possible_cpu(cpu) {
@@ -2913,8 +2896,6 @@ err_deinit:
2913 mvneta_deinit(pp); 2896 mvneta_deinit(pp);
2914err_free_stats: 2897err_free_stats:
2915 free_percpu(pp->stats); 2898 free_percpu(pp->stats);
2916err_unmap:
2917 iounmap(pp->base);
2918err_clk: 2899err_clk:
2919 clk_disable_unprepare(pp->clk); 2900 clk_disable_unprepare(pp->clk);
2920err_free_irq: 2901err_free_irq:
@@ -2934,7 +2915,6 @@ static int mvneta_remove(struct platform_device *pdev)
2934 mvneta_deinit(pp); 2915 mvneta_deinit(pp);
2935 clk_disable_unprepare(pp->clk); 2916 clk_disable_unprepare(pp->clk);
2936 free_percpu(pp->stats); 2917 free_percpu(pp->stats);
2937 iounmap(pp->base);
2938 irq_dispose_mapping(dev->irq); 2918 irq_dispose_mapping(dev->irq);
2939 free_netdev(dev); 2919 free_netdev(dev);
2940 2920
diff --git a/drivers/net/ethernet/mellanox/mlx4/en_netdev.c b/drivers/net/ethernet/mellanox/mlx4/en_netdev.c
index fad45316200a..84a96f70dfb5 100644
--- a/drivers/net/ethernet/mellanox/mlx4/en_netdev.c
+++ b/drivers/net/ethernet/mellanox/mlx4/en_netdev.c
@@ -742,6 +742,14 @@ static int mlx4_en_replace_mac(struct mlx4_en_priv *priv, int qpn,
742 err = mlx4_en_uc_steer_add(priv, new_mac, 742 err = mlx4_en_uc_steer_add(priv, new_mac,
743 &qpn, 743 &qpn,
744 &entry->reg_id); 744 &entry->reg_id);
745 if (err)
746 return err;
747 if (priv->tunnel_reg_id) {
748 mlx4_flow_detach(priv->mdev->dev, priv->tunnel_reg_id);
749 priv->tunnel_reg_id = 0;
750 }
751 err = mlx4_en_tunnel_steer_add(priv, new_mac, qpn,
752 &priv->tunnel_reg_id);
745 return err; 753 return err;
746 } 754 }
747 } 755 }
@@ -1792,6 +1800,8 @@ void mlx4_en_stop_port(struct net_device *dev, int detach)
1792 mc_list[5] = priv->port; 1800 mc_list[5] = priv->port;
1793 mlx4_multicast_detach(mdev->dev, &priv->rss_map.indir_qp, 1801 mlx4_multicast_detach(mdev->dev, &priv->rss_map.indir_qp,
1794 mc_list, MLX4_PROT_ETH, mclist->reg_id); 1802 mc_list, MLX4_PROT_ETH, mclist->reg_id);
1803 if (mclist->tunnel_reg_id)
1804 mlx4_flow_detach(mdev->dev, mclist->tunnel_reg_id);
1795 } 1805 }
1796 mlx4_en_clear_list(dev); 1806 mlx4_en_clear_list(dev);
1797 list_for_each_entry_safe(mclist, tmp, &priv->curr_list, list) { 1807 list_for_each_entry_safe(mclist, tmp, &priv->curr_list, list) {
diff --git a/drivers/net/ethernet/mellanox/mlx4/fw.c b/drivers/net/ethernet/mellanox/mlx4/fw.c
index 91b69ff4b4a2..7e2995ecea6f 100644
--- a/drivers/net/ethernet/mellanox/mlx4/fw.c
+++ b/drivers/net/ethernet/mellanox/mlx4/fw.c
@@ -129,13 +129,14 @@ static void dump_dev_cap_flags2(struct mlx4_dev *dev, u64 flags)
129 [0] = "RSS support", 129 [0] = "RSS support",
130 [1] = "RSS Toeplitz Hash Function support", 130 [1] = "RSS Toeplitz Hash Function support",
131 [2] = "RSS XOR Hash Function support", 131 [2] = "RSS XOR Hash Function support",
132 [3] = "Device manage flow steering support", 132 [3] = "Device managed flow steering support",
133 [4] = "Automatic MAC reassignment support", 133 [4] = "Automatic MAC reassignment support",
134 [5] = "Time stamping support", 134 [5] = "Time stamping support",
135 [6] = "VST (control vlan insertion/stripping) support", 135 [6] = "VST (control vlan insertion/stripping) support",
136 [7] = "FSM (MAC anti-spoofing) support", 136 [7] = "FSM (MAC anti-spoofing) support",
137 [8] = "Dynamic QP updates support", 137 [8] = "Dynamic QP updates support",
138 [9] = "TCP/IP offloads/flow-steering for VXLAN support" 138 [9] = "Device managed flow steering IPoIB support",
139 [10] = "TCP/IP offloads/flow-steering for VXLAN support"
139 }; 140 };
140 int i; 141 int i;
141 142
@@ -859,7 +860,7 @@ int mlx4_QUERY_DEV_CAP_wrapper(struct mlx4_dev *dev, int slave,
859 MLX4_PUT(outbox->buf, field, QUERY_DEV_CAP_CQ_TS_SUPPORT_OFFSET); 860 MLX4_PUT(outbox->buf, field, QUERY_DEV_CAP_CQ_TS_SUPPORT_OFFSET);
860 861
861 /* For guests, disable vxlan tunneling */ 862 /* For guests, disable vxlan tunneling */
862 MLX4_GET(field, outbox, QUERY_DEV_CAP_VXLAN); 863 MLX4_GET(field, outbox->buf, QUERY_DEV_CAP_VXLAN);
863 field &= 0xf7; 864 field &= 0xf7;
864 MLX4_PUT(outbox->buf, field, QUERY_DEV_CAP_VXLAN); 865 MLX4_PUT(outbox->buf, field, QUERY_DEV_CAP_VXLAN);
865 866
@@ -869,7 +870,7 @@ int mlx4_QUERY_DEV_CAP_wrapper(struct mlx4_dev *dev, int slave,
869 MLX4_PUT(outbox->buf, field, QUERY_DEV_CAP_BF_OFFSET); 870 MLX4_PUT(outbox->buf, field, QUERY_DEV_CAP_BF_OFFSET);
870 871
871 /* For guests, disable mw type 2 */ 872 /* For guests, disable mw type 2 */
872 MLX4_GET(bmme_flags, outbox, QUERY_DEV_CAP_BMME_FLAGS_OFFSET); 873 MLX4_GET(bmme_flags, outbox->buf, QUERY_DEV_CAP_BMME_FLAGS_OFFSET);
873 bmme_flags &= ~MLX4_BMME_FLAG_TYPE_2_WIN; 874 bmme_flags &= ~MLX4_BMME_FLAG_TYPE_2_WIN;
874 MLX4_PUT(outbox->buf, bmme_flags, QUERY_DEV_CAP_BMME_FLAGS_OFFSET); 875 MLX4_PUT(outbox->buf, bmme_flags, QUERY_DEV_CAP_BMME_FLAGS_OFFSET);
875 876
@@ -883,7 +884,7 @@ int mlx4_QUERY_DEV_CAP_wrapper(struct mlx4_dev *dev, int slave,
883 } 884 }
884 885
885 /* turn off ipoib managed steering for guests */ 886 /* turn off ipoib managed steering for guests */
886 MLX4_GET(field, outbox, QUERY_DEV_CAP_FLOW_STEERING_IPOIB_OFFSET); 887 MLX4_GET(field, outbox->buf, QUERY_DEV_CAP_FLOW_STEERING_IPOIB_OFFSET);
887 field &= ~0x80; 888 field &= ~0x80;
888 MLX4_PUT(outbox->buf, field, QUERY_DEV_CAP_FLOW_STEERING_IPOIB_OFFSET); 889 MLX4_PUT(outbox->buf, field, QUERY_DEV_CAP_FLOW_STEERING_IPOIB_OFFSET);
889 890
diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c b/drivers/net/ethernet/mellanox/mlx4/main.c
index d711158b0d4b..d413e60071d4 100644
--- a/drivers/net/ethernet/mellanox/mlx4/main.c
+++ b/drivers/net/ethernet/mellanox/mlx4/main.c
@@ -150,6 +150,8 @@ struct mlx4_port_config {
150 struct pci_dev *pdev; 150 struct pci_dev *pdev;
151}; 151};
152 152
153static atomic_t pf_loading = ATOMIC_INIT(0);
154
153int mlx4_check_port_params(struct mlx4_dev *dev, 155int mlx4_check_port_params(struct mlx4_dev *dev,
154 enum mlx4_port_type *port_type) 156 enum mlx4_port_type *port_type)
155{ 157{
@@ -749,7 +751,7 @@ static void mlx4_request_modules(struct mlx4_dev *dev)
749 has_eth_port = true; 751 has_eth_port = true;
750 } 752 }
751 753
752 if (has_ib_port) 754 if (has_ib_port || (dev->caps.flags & MLX4_DEV_CAP_FLAG_IBOE))
753 request_module_nowait(IB_DRV_NAME); 755 request_module_nowait(IB_DRV_NAME);
754 if (has_eth_port) 756 if (has_eth_port)
755 request_module_nowait(EN_DRV_NAME); 757 request_module_nowait(EN_DRV_NAME);
@@ -1407,6 +1409,11 @@ static int mlx4_init_slave(struct mlx4_dev *dev)
1407 u32 slave_read; 1409 u32 slave_read;
1408 u32 cmd_channel_ver; 1410 u32 cmd_channel_ver;
1409 1411
1412 if (atomic_read(&pf_loading)) {
1413 mlx4_warn(dev, "PF is not ready. Deferring probe\n");
1414 return -EPROBE_DEFER;
1415 }
1416
1410 mutex_lock(&priv->cmd.slave_cmd_mutex); 1417 mutex_lock(&priv->cmd.slave_cmd_mutex);
1411 priv->cmd.max_cmds = 1; 1418 priv->cmd.max_cmds = 1;
1412 mlx4_warn(dev, "Sending reset\n"); 1419 mlx4_warn(dev, "Sending reset\n");
@@ -2319,7 +2326,11 @@ static int __mlx4_init_one(struct pci_dev *pdev, int pci_dev_data)
2319 2326
2320 if (num_vfs) { 2327 if (num_vfs) {
2321 mlx4_warn(dev, "Enabling SR-IOV with %d VFs\n", num_vfs); 2328 mlx4_warn(dev, "Enabling SR-IOV with %d VFs\n", num_vfs);
2329
2330 atomic_inc(&pf_loading);
2322 err = pci_enable_sriov(pdev, num_vfs); 2331 err = pci_enable_sriov(pdev, num_vfs);
2332 atomic_dec(&pf_loading);
2333
2323 if (err) { 2334 if (err) {
2324 mlx4_err(dev, "Failed to enable SR-IOV, continuing without SR-IOV (err = %d).\n", 2335 mlx4_err(dev, "Failed to enable SR-IOV, continuing without SR-IOV (err = %d).\n",
2325 err); 2336 err);
@@ -2670,7 +2681,11 @@ static pci_ers_result_t mlx4_pci_err_detected(struct pci_dev *pdev,
2670 2681
2671static pci_ers_result_t mlx4_pci_slot_reset(struct pci_dev *pdev) 2682static pci_ers_result_t mlx4_pci_slot_reset(struct pci_dev *pdev)
2672{ 2683{
2673 int ret = __mlx4_init_one(pdev, 0); 2684 const struct pci_device_id *id;
2685 int ret;
2686
2687 id = pci_match_id(mlx4_pci_table, pdev);
2688 ret = __mlx4_init_one(pdev, id->driver_data);
2674 2689
2675 return ret ? PCI_ERS_RESULT_DISCONNECT : PCI_ERS_RESULT_RECOVERED; 2690 return ret ? PCI_ERS_RESULT_DISCONNECT : PCI_ERS_RESULT_RECOVERED;
2676} 2691}
@@ -2684,6 +2699,7 @@ static struct pci_driver mlx4_driver = {
2684 .name = DRV_NAME, 2699 .name = DRV_NAME,
2685 .id_table = mlx4_pci_table, 2700 .id_table = mlx4_pci_table,
2686 .probe = mlx4_init_one, 2701 .probe = mlx4_init_one,
2702 .shutdown = mlx4_remove_one,
2687 .remove = mlx4_remove_one, 2703 .remove = mlx4_remove_one,
2688 .err_handler = &mlx4_err_handler, 2704 .err_handler = &mlx4_err_handler,
2689}; 2705};
diff --git a/drivers/net/ethernet/mellanox/mlx4/mlx4.h b/drivers/net/ethernet/mellanox/mlx4/mlx4.h
index 6b65f7795215..7aec6c833973 100644
--- a/drivers/net/ethernet/mellanox/mlx4/mlx4.h
+++ b/drivers/net/ethernet/mellanox/mlx4/mlx4.h
@@ -51,8 +51,8 @@
51 51
52#define DRV_NAME "mlx4_core" 52#define DRV_NAME "mlx4_core"
53#define PFX DRV_NAME ": " 53#define PFX DRV_NAME ": "
54#define DRV_VERSION "1.1" 54#define DRV_VERSION "2.2-1"
55#define DRV_RELDATE "Dec, 2011" 55#define DRV_RELDATE "Feb, 2014"
56 56
57#define MLX4_FS_UDP_UC_EN (1 << 1) 57#define MLX4_FS_UDP_UC_EN (1 << 1)
58#define MLX4_FS_TCP_UC_EN (1 << 2) 58#define MLX4_FS_TCP_UC_EN (1 << 2)
diff --git a/drivers/net/ethernet/mellanox/mlx4/mlx4_en.h b/drivers/net/ethernet/mellanox/mlx4/mlx4_en.h
index 9ca223bc90fc..b57e8c87a34e 100644
--- a/drivers/net/ethernet/mellanox/mlx4/mlx4_en.h
+++ b/drivers/net/ethernet/mellanox/mlx4/mlx4_en.h
@@ -57,8 +57,8 @@
57#include "en_port.h" 57#include "en_port.h"
58 58
59#define DRV_NAME "mlx4_en" 59#define DRV_NAME "mlx4_en"
60#define DRV_VERSION "2.0" 60#define DRV_VERSION "2.2-1"
61#define DRV_RELDATE "Dec 2011" 61#define DRV_RELDATE "Feb 2014"
62 62
63#define MLX4_EN_MSG_LEVEL (NETIF_MSG_LINK | NETIF_MSG_IFDOWN) 63#define MLX4_EN_MSG_LEVEL (NETIF_MSG_LINK | NETIF_MSG_IFDOWN)
64 64
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/main.c b/drivers/net/ethernet/mellanox/mlx5/core/main.c
index a064f06e0cb8..23b7e2d35a93 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/main.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/main.c
@@ -46,8 +46,8 @@
46#include "mlx5_core.h" 46#include "mlx5_core.h"
47 47
48#define DRIVER_NAME "mlx5_core" 48#define DRIVER_NAME "mlx5_core"
49#define DRIVER_VERSION "1.0" 49#define DRIVER_VERSION "2.2-1"
50#define DRIVER_RELDATE "June 2013" 50#define DRIVER_RELDATE "Feb 2014"
51 51
52MODULE_AUTHOR("Eli Cohen <eli@mellanox.com>"); 52MODULE_AUTHOR("Eli Cohen <eli@mellanox.com>");
53MODULE_DESCRIPTION("Mellanox ConnectX-IB HCA core library"); 53MODULE_DESCRIPTION("Mellanox ConnectX-IB HCA core library");
diff --git a/drivers/net/ethernet/micrel/ks8851.c b/drivers/net/ethernet/micrel/ks8851.c
index 727b546a9eb8..e0c92e0e5e1d 100644
--- a/drivers/net/ethernet/micrel/ks8851.c
+++ b/drivers/net/ethernet/micrel/ks8851.c
@@ -23,6 +23,7 @@
23#include <linux/crc32.h> 23#include <linux/crc32.h>
24#include <linux/mii.h> 24#include <linux/mii.h>
25#include <linux/eeprom_93cx6.h> 25#include <linux/eeprom_93cx6.h>
26#include <linux/regulator/consumer.h>
26 27
27#include <linux/spi/spi.h> 28#include <linux/spi/spi.h>
28 29
@@ -83,6 +84,7 @@ union ks8851_tx_hdr {
83 * @rc_rxqcr: Cached copy of KS_RXQCR. 84 * @rc_rxqcr: Cached copy of KS_RXQCR.
84 * @eeprom_size: Companion eeprom size in Bytes, 0 if no eeprom 85 * @eeprom_size: Companion eeprom size in Bytes, 0 if no eeprom
85 * @eeprom: 93CX6 EEPROM state for accessing on-board EEPROM. 86 * @eeprom: 93CX6 EEPROM state for accessing on-board EEPROM.
87 * @vdd_reg: Optional regulator supplying the chip
86 * 88 *
87 * The @lock ensures that the chip is protected when certain operations are 89 * The @lock ensures that the chip is protected when certain operations are
88 * in progress. When the read or write packet transfer is in progress, most 90 * in progress. When the read or write packet transfer is in progress, most
@@ -130,6 +132,7 @@ struct ks8851_net {
130 struct spi_transfer spi_xfer2[2]; 132 struct spi_transfer spi_xfer2[2];
131 133
132 struct eeprom_93cx6 eeprom; 134 struct eeprom_93cx6 eeprom;
135 struct regulator *vdd_reg;
133}; 136};
134 137
135static int msg_enable; 138static int msg_enable;
@@ -1414,6 +1417,21 @@ static int ks8851_probe(struct spi_device *spi)
1414 ks->spidev = spi; 1417 ks->spidev = spi;
1415 ks->tx_space = 6144; 1418 ks->tx_space = 6144;
1416 1419
1420 ks->vdd_reg = regulator_get_optional(&spi->dev, "vdd");
1421 if (IS_ERR(ks->vdd_reg)) {
1422 ret = PTR_ERR(ks->vdd_reg);
1423 if (ret == -EPROBE_DEFER)
1424 goto err_reg;
1425 } else {
1426 ret = regulator_enable(ks->vdd_reg);
1427 if (ret) {
1428 dev_err(&spi->dev, "regulator enable fail: %d\n",
1429 ret);
1430 goto err_reg_en;
1431 }
1432 }
1433
1434
1417 mutex_init(&ks->lock); 1435 mutex_init(&ks->lock);
1418 spin_lock_init(&ks->statelock); 1436 spin_lock_init(&ks->statelock);
1419 1437
@@ -1508,8 +1526,14 @@ static int ks8851_probe(struct spi_device *spi)
1508err_netdev: 1526err_netdev:
1509 free_irq(ndev->irq, ks); 1527 free_irq(ndev->irq, ks);
1510 1528
1511err_id:
1512err_irq: 1529err_irq:
1530err_id:
1531 if (!IS_ERR(ks->vdd_reg))
1532 regulator_disable(ks->vdd_reg);
1533err_reg_en:
1534 if (!IS_ERR(ks->vdd_reg))
1535 regulator_put(ks->vdd_reg);
1536err_reg:
1513 free_netdev(ndev); 1537 free_netdev(ndev);
1514 return ret; 1538 return ret;
1515} 1539}
@@ -1523,6 +1547,10 @@ static int ks8851_remove(struct spi_device *spi)
1523 1547
1524 unregister_netdev(priv->netdev); 1548 unregister_netdev(priv->netdev);
1525 free_irq(spi->irq, priv); 1549 free_irq(spi->irq, priv);
1550 if (!IS_ERR(priv->vdd_reg)) {
1551 regulator_disable(priv->vdd_reg);
1552 regulator_put(priv->vdd_reg);
1553 }
1526 free_netdev(priv->netdev); 1554 free_netdev(priv->netdev);
1527 1555
1528 return 0; 1556 return 0;
diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_hw.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_hw.c
index 4146664d4d6a..27c4f131863b 100644
--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_hw.c
+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_hw.c
@@ -340,6 +340,7 @@ int qlcnic_83xx_setup_intr(struct qlcnic_adapter *adapter)
340 if (qlcnic_sriov_vf_check(adapter)) 340 if (qlcnic_sriov_vf_check(adapter))
341 return -EINVAL; 341 return -EINVAL;
342 num_msix = 1; 342 num_msix = 1;
343 adapter->drv_sds_rings = QLCNIC_SINGLE_RING;
343 adapter->drv_tx_rings = QLCNIC_SINGLE_RING; 344 adapter->drv_tx_rings = QLCNIC_SINGLE_RING;
344 } 345 }
345 } 346 }
diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_dcb.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_dcb.c
index 77f1bce432d2..7d4f54912bad 100644
--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_dcb.c
+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_dcb.c
@@ -807,7 +807,7 @@ qlcnic_dcb_get_pg_tc_cfg_tx(struct net_device *netdev, int tc, u8 *prio,
807 !type->tc_param_valid) 807 !type->tc_param_valid)
808 return; 808 return;
809 809
810 if (tc < 0 || (tc > QLC_DCB_MAX_TC)) 810 if (tc < 0 || (tc >= QLC_DCB_MAX_TC))
811 return; 811 return;
812 812
813 tc_cfg = &type->tc_cfg[tc]; 813 tc_cfg = &type->tc_cfg[tc];
@@ -843,7 +843,7 @@ static void qlcnic_dcb_get_pg_bwg_cfg_tx(struct net_device *netdev, int pgid,
843 !type->tc_param_valid) 843 !type->tc_param_valid)
844 return; 844 return;
845 845
846 if (pgid < 0 || pgid > QLC_DCB_MAX_PG) 846 if (pgid < 0 || pgid >= QLC_DCB_MAX_PG)
847 return; 847 return;
848 848
849 pgcfg = &type->pg_cfg[pgid]; 849 pgcfg = &type->pg_cfg[pgid];
diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c
index ba78c7481fa3..1222865cfb73 100644
--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c
+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c
@@ -816,9 +816,10 @@ static int qlcnic_82xx_setup_intr(struct qlcnic_adapter *adapter)
816 816
817 if (!(adapter->flags & QLCNIC_MSIX_ENABLED)) { 817 if (!(adapter->flags & QLCNIC_MSIX_ENABLED)) {
818 qlcnic_disable_multi_tx(adapter); 818 qlcnic_disable_multi_tx(adapter);
819 adapter->drv_sds_rings = QLCNIC_SINGLE_RING;
819 820
820 err = qlcnic_enable_msi_legacy(adapter); 821 err = qlcnic_enable_msi_legacy(adapter);
821 if (!err) 822 if (err)
822 return err; 823 return err;
823 } 824 }
824 } 825 }
@@ -3863,7 +3864,7 @@ int qlcnic_validate_rings(struct qlcnic_adapter *adapter, __u32 ring_cnt,
3863 strcpy(buf, "Tx"); 3864 strcpy(buf, "Tx");
3864 } 3865 }
3865 3866
3866 if (!qlcnic_use_msi_x && !qlcnic_use_msi) { 3867 if (!QLCNIC_IS_MSI_FAMILY(adapter)) {
3867 netdev_err(netdev, "No RSS/TSS support in INT-x mode\n"); 3868 netdev_err(netdev, "No RSS/TSS support in INT-x mode\n");
3868 return -EINVAL; 3869 return -EINVAL;
3869 } 3870 }
diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_sriov_pf.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_sriov_pf.c
index 09acf15c3a56..e5277a632671 100644
--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_sriov_pf.c
+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_sriov_pf.c
@@ -13,8 +13,6 @@
13#define QLC_VF_MIN_TX_RATE 100 13#define QLC_VF_MIN_TX_RATE 100
14#define QLC_VF_MAX_TX_RATE 9999 14#define QLC_VF_MAX_TX_RATE 9999
15#define QLC_MAC_OPCODE_MASK 0x7 15#define QLC_MAC_OPCODE_MASK 0x7
16#define QLC_MAC_STAR_ADD 6
17#define QLC_MAC_STAR_DEL 7
18#define QLC_VF_FLOOD_BIT BIT_16 16#define QLC_VF_FLOOD_BIT BIT_16
19#define QLC_FLOOD_MODE 0x5 17#define QLC_FLOOD_MODE 0x5
20 18
@@ -1206,13 +1204,6 @@ static int qlcnic_sriov_validate_cfg_macvlan(struct qlcnic_adapter *adapter,
1206 struct qlcnic_vport *vp = vf->vp; 1204 struct qlcnic_vport *vp = vf->vp;
1207 u8 op, new_op; 1205 u8 op, new_op;
1208 1206
1209 if (((cmd->req.arg[1] & QLC_MAC_OPCODE_MASK) == QLC_MAC_STAR_ADD) ||
1210 ((cmd->req.arg[1] & QLC_MAC_OPCODE_MASK) == QLC_MAC_STAR_DEL)) {
1211 netdev_err(adapter->netdev, "MAC + any VLAN filter not allowed from VF %d\n",
1212 vf->pci_func);
1213 return -EINVAL;
1214 }
1215
1216 if (!(cmd->req.arg[1] & BIT_8)) 1207 if (!(cmd->req.arg[1] & BIT_8))
1217 return -EINVAL; 1208 return -EINVAL;
1218 1209
diff --git a/drivers/net/ethernet/qlogic/qlge/qlge_main.c b/drivers/net/ethernet/qlogic/qlge/qlge_main.c
index ce2cfddbed50..656c65ddadb4 100644
--- a/drivers/net/ethernet/qlogic/qlge/qlge_main.c
+++ b/drivers/net/ethernet/qlogic/qlge/qlge_main.c
@@ -4765,7 +4765,9 @@ static int qlge_probe(struct pci_dev *pdev,
4765 ndev->features = ndev->hw_features; 4765 ndev->features = ndev->hw_features;
4766 ndev->vlan_features = ndev->hw_features; 4766 ndev->vlan_features = ndev->hw_features;
4767 /* vlan gets same features (except vlan filter) */ 4767 /* vlan gets same features (except vlan filter) */
4768 ndev->vlan_features &= ~NETIF_F_HW_VLAN_CTAG_FILTER; 4768 ndev->vlan_features &= ~(NETIF_F_HW_VLAN_CTAG_FILTER |
4769 NETIF_F_HW_VLAN_CTAG_TX |
4770 NETIF_F_HW_VLAN_CTAG_RX);
4769 4771
4770 if (test_bit(QL_DMA64, &qdev->flags)) 4772 if (test_bit(QL_DMA64, &qdev->flags))
4771 ndev->features |= NETIF_F_HIGHDMA; 4773 ndev->features |= NETIF_F_HIGHDMA;
diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
index 91a67ae8f17b..3ff7bc3e7a23 100644
--- a/drivers/net/ethernet/realtek/r8169.c
+++ b/drivers/net/ethernet/realtek/r8169.c
@@ -209,7 +209,7 @@ static const struct {
209 [RTL_GIGA_MAC_VER_16] = 209 [RTL_GIGA_MAC_VER_16] =
210 _R("RTL8101e", RTL_TD_0, NULL, JUMBO_1K, true), 210 _R("RTL8101e", RTL_TD_0, NULL, JUMBO_1K, true),
211 [RTL_GIGA_MAC_VER_17] = 211 [RTL_GIGA_MAC_VER_17] =
212 _R("RTL8168b/8111b", RTL_TD_1, NULL, JUMBO_4K, false), 212 _R("RTL8168b/8111b", RTL_TD_0, NULL, JUMBO_4K, false),
213 [RTL_GIGA_MAC_VER_18] = 213 [RTL_GIGA_MAC_VER_18] =
214 _R("RTL8168cp/8111cp", RTL_TD_1, NULL, JUMBO_6K, false), 214 _R("RTL8168cp/8111cp", RTL_TD_1, NULL, JUMBO_6K, false),
215 [RTL_GIGA_MAC_VER_19] = 215 [RTL_GIGA_MAC_VER_19] =
@@ -7118,6 +7118,8 @@ rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
7118 } 7118 }
7119 7119
7120 mutex_init(&tp->wk.mutex); 7120 mutex_init(&tp->wk.mutex);
7121 u64_stats_init(&tp->rx_stats.syncp);
7122 u64_stats_init(&tp->tx_stats.syncp);
7121 7123
7122 /* Get MAC address */ 7124 /* Get MAC address */
7123 for (i = 0; i < ETH_ALEN; i++) 7125 for (i = 0; i < ETH_ALEN; i++)
diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
index eb75fbd11a01..d7a36829649a 100644
--- a/drivers/net/ethernet/sfc/ptp.c
+++ b/drivers/net/ethernet/sfc/ptp.c
@@ -1668,6 +1668,13 @@ void efx_ptp_event(struct efx_nic *efx, efx_qword_t *ev)
1668 struct efx_ptp_data *ptp = efx->ptp_data; 1668 struct efx_ptp_data *ptp = efx->ptp_data;
1669 int code = EFX_QWORD_FIELD(*ev, MCDI_EVENT_CODE); 1669 int code = EFX_QWORD_FIELD(*ev, MCDI_EVENT_CODE);
1670 1670
1671 if (!ptp) {
1672 if (net_ratelimit())
1673 netif_warn(efx, drv, efx->net_dev,
1674 "Received PTP event but PTP not set up\n");
1675 return;
1676 }
1677
1671 if (!ptp->enabled) 1678 if (!ptp->enabled)
1672 return; 1679 return;
1673 1680
diff --git a/drivers/net/ethernet/stmicro/stmmac/chain_mode.c b/drivers/net/ethernet/stmicro/stmmac/chain_mode.c
index 72d282bf33a5..c553f6b5a913 100644
--- a/drivers/net/ethernet/stmicro/stmmac/chain_mode.c
+++ b/drivers/net/ethernet/stmicro/stmmac/chain_mode.c
@@ -151,7 +151,7 @@ static void stmmac_clean_desc3(void *priv_ptr, struct dma_desc *p)
151 sizeof(struct dma_desc))); 151 sizeof(struct dma_desc)));
152} 152}
153 153
154const struct stmmac_chain_mode_ops chain_mode_ops = { 154const struct stmmac_mode_ops chain_mode_ops = {
155 .init = stmmac_init_dma_chain, 155 .init = stmmac_init_dma_chain,
156 .is_jumbo_frm = stmmac_is_jumbo_frm, 156 .is_jumbo_frm = stmmac_is_jumbo_frm,
157 .jumbo_frm = stmmac_jumbo_frm, 157 .jumbo_frm = stmmac_jumbo_frm,
diff --git a/drivers/net/ethernet/stmicro/stmmac/common.h b/drivers/net/ethernet/stmicro/stmmac/common.h
index 7834a3993946..74610f3aca9e 100644
--- a/drivers/net/ethernet/stmicro/stmmac/common.h
+++ b/drivers/net/ethernet/stmicro/stmmac/common.h
@@ -419,20 +419,13 @@ struct mii_regs {
419 unsigned int data; /* MII Data */ 419 unsigned int data; /* MII Data */
420}; 420};
421 421
422struct stmmac_ring_mode_ops { 422struct stmmac_mode_ops {
423 unsigned int (*is_jumbo_frm) (int len, int ehn_desc);
424 unsigned int (*jumbo_frm) (void *priv, struct sk_buff *skb, int csum);
425 void (*refill_desc3) (void *priv, struct dma_desc *p);
426 void (*init_desc3) (struct dma_desc *p);
427 void (*clean_desc3) (void *priv, struct dma_desc *p);
428 int (*set_16kib_bfsize) (int mtu);
429};
430
431struct stmmac_chain_mode_ops {
432 void (*init) (void *des, dma_addr_t phy_addr, unsigned int size, 423 void (*init) (void *des, dma_addr_t phy_addr, unsigned int size,
433 unsigned int extend_desc); 424 unsigned int extend_desc);
434 unsigned int (*is_jumbo_frm) (int len, int ehn_desc); 425 unsigned int (*is_jumbo_frm) (int len, int ehn_desc);
435 unsigned int (*jumbo_frm) (void *priv, struct sk_buff *skb, int csum); 426 unsigned int (*jumbo_frm) (void *priv, struct sk_buff *skb, int csum);
427 int (*set_16kib_bfsize)(int mtu);
428 void (*init_desc3)(struct dma_desc *p);
436 void (*refill_desc3) (void *priv, struct dma_desc *p); 429 void (*refill_desc3) (void *priv, struct dma_desc *p);
437 void (*clean_desc3) (void *priv, struct dma_desc *p); 430 void (*clean_desc3) (void *priv, struct dma_desc *p);
438}; 431};
@@ -441,8 +434,7 @@ struct mac_device_info {
441 const struct stmmac_ops *mac; 434 const struct stmmac_ops *mac;
442 const struct stmmac_desc_ops *desc; 435 const struct stmmac_desc_ops *desc;
443 const struct stmmac_dma_ops *dma; 436 const struct stmmac_dma_ops *dma;
444 const struct stmmac_ring_mode_ops *ring; 437 const struct stmmac_mode_ops *mode;
445 const struct stmmac_chain_mode_ops *chain;
446 const struct stmmac_hwtimestamp *ptp; 438 const struct stmmac_hwtimestamp *ptp;
447 struct mii_regs mii; /* MII register Addresses */ 439 struct mii_regs mii; /* MII register Addresses */
448 struct mac_link link; 440 struct mac_link link;
@@ -460,7 +452,7 @@ void stmmac_get_mac_addr(void __iomem *ioaddr, unsigned char *addr,
460void stmmac_set_mac(void __iomem *ioaddr, bool enable); 452void stmmac_set_mac(void __iomem *ioaddr, bool enable);
461 453
462void dwmac_dma_flush_tx_fifo(void __iomem *ioaddr); 454void dwmac_dma_flush_tx_fifo(void __iomem *ioaddr);
463extern const struct stmmac_ring_mode_ops ring_mode_ops; 455extern const struct stmmac_mode_ops ring_mode_ops;
464extern const struct stmmac_chain_mode_ops chain_mode_ops; 456extern const struct stmmac_mode_ops chain_mode_ops;
465 457
466#endif /* __COMMON_H__ */ 458#endif /* __COMMON_H__ */
diff --git a/drivers/net/ethernet/stmicro/stmmac/ring_mode.c b/drivers/net/ethernet/stmicro/stmmac/ring_mode.c
index a96c7c2f5f3f..650a4be6bce5 100644
--- a/drivers/net/ethernet/stmicro/stmmac/ring_mode.c
+++ b/drivers/net/ethernet/stmicro/stmmac/ring_mode.c
@@ -100,10 +100,9 @@ static void stmmac_refill_desc3(void *priv_ptr, struct dma_desc *p)
100{ 100{
101 struct stmmac_priv *priv = (struct stmmac_priv *)priv_ptr; 101 struct stmmac_priv *priv = (struct stmmac_priv *)priv_ptr;
102 102
103 if (unlikely(priv->plat->has_gmac)) 103 /* Fill DES3 in case of RING mode */
104 /* Fill DES3 in case of RING mode */ 104 if (priv->dma_buf_sz >= BUF_SIZE_8KiB)
105 if (priv->dma_buf_sz >= BUF_SIZE_8KiB) 105 p->des3 = p->des2 + BUF_SIZE_8KiB;
106 p->des3 = p->des2 + BUF_SIZE_8KiB;
107} 106}
108 107
109/* In ring mode we need to fill the desc3 because it is used as buffer */ 108/* In ring mode we need to fill the desc3 because it is used as buffer */
@@ -126,7 +125,7 @@ static int stmmac_set_16kib_bfsize(int mtu)
126 return ret; 125 return ret;
127} 126}
128 127
129const struct stmmac_ring_mode_ops ring_mode_ops = { 128const struct stmmac_mode_ops ring_mode_ops = {
130 .is_jumbo_frm = stmmac_is_jumbo_frm, 129 .is_jumbo_frm = stmmac_is_jumbo_frm,
131 .jumbo_frm = stmmac_jumbo_frm, 130 .jumbo_frm = stmmac_jumbo_frm,
132 .refill_desc3 = stmmac_refill_desc3, 131 .refill_desc3 = stmmac_refill_desc3,
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index a2e7d2c96e36..8543e1cfd55e 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -92,8 +92,8 @@ static int tc = TC_DEFAULT;
92module_param(tc, int, S_IRUGO | S_IWUSR); 92module_param(tc, int, S_IRUGO | S_IWUSR);
93MODULE_PARM_DESC(tc, "DMA threshold control value"); 93MODULE_PARM_DESC(tc, "DMA threshold control value");
94 94
95#define DMA_BUFFER_SIZE BUF_SIZE_4KiB 95#define DEFAULT_BUFSIZE 1536
96static int buf_sz = DMA_BUFFER_SIZE; 96static int buf_sz = DEFAULT_BUFSIZE;
97module_param(buf_sz, int, S_IRUGO | S_IWUSR); 97module_param(buf_sz, int, S_IRUGO | S_IWUSR);
98MODULE_PARM_DESC(buf_sz, "DMA buffer size"); 98MODULE_PARM_DESC(buf_sz, "DMA buffer size");
99 99
@@ -136,8 +136,8 @@ static void stmmac_verify_args(void)
136 dma_rxsize = DMA_RX_SIZE; 136 dma_rxsize = DMA_RX_SIZE;
137 if (unlikely(dma_txsize < 0)) 137 if (unlikely(dma_txsize < 0))
138 dma_txsize = DMA_TX_SIZE; 138 dma_txsize = DMA_TX_SIZE;
139 if (unlikely((buf_sz < DMA_BUFFER_SIZE) || (buf_sz > BUF_SIZE_16KiB))) 139 if (unlikely((buf_sz < DEFAULT_BUFSIZE) || (buf_sz > BUF_SIZE_16KiB)))
140 buf_sz = DMA_BUFFER_SIZE; 140 buf_sz = DEFAULT_BUFSIZE;
141 if (unlikely(flow_ctrl > 1)) 141 if (unlikely(flow_ctrl > 1))
142 flow_ctrl = FLOW_AUTO; 142 flow_ctrl = FLOW_AUTO;
143 else if (likely(flow_ctrl < 0)) 143 else if (likely(flow_ctrl < 0))
@@ -286,10 +286,25 @@ bool stmmac_eee_init(struct stmmac_priv *priv)
286 286
287 /* MAC core supports the EEE feature. */ 287 /* MAC core supports the EEE feature. */
288 if (priv->dma_cap.eee) { 288 if (priv->dma_cap.eee) {
289 int tx_lpi_timer = priv->tx_lpi_timer;
290
289 /* Check if the PHY supports EEE */ 291 /* Check if the PHY supports EEE */
290 if (phy_init_eee(priv->phydev, 1)) 292 if (phy_init_eee(priv->phydev, 1)) {
293 /* To manage at run-time if the EEE cannot be supported
294 * anymore (for example because the lp caps have been
295 * changed).
296 * In that case the driver disable own timers.
297 */
298 if (priv->eee_active) {
299 pr_debug("stmmac: disable EEE\n");
300 del_timer_sync(&priv->eee_ctrl_timer);
301 priv->hw->mac->set_eee_timer(priv->ioaddr, 0,
302 tx_lpi_timer);
303 }
304 priv->eee_active = 0;
291 goto out; 305 goto out;
292 306 }
307 /* Activate the EEE and start timers */
293 if (!priv->eee_active) { 308 if (!priv->eee_active) {
294 priv->eee_active = 1; 309 priv->eee_active = 1;
295 init_timer(&priv->eee_ctrl_timer); 310 init_timer(&priv->eee_ctrl_timer);
@@ -300,13 +315,13 @@ bool stmmac_eee_init(struct stmmac_priv *priv)
300 315
301 priv->hw->mac->set_eee_timer(priv->ioaddr, 316 priv->hw->mac->set_eee_timer(priv->ioaddr,
302 STMMAC_DEFAULT_LIT_LS, 317 STMMAC_DEFAULT_LIT_LS,
303 priv->tx_lpi_timer); 318 tx_lpi_timer);
304 } else 319 } else
305 /* Set HW EEE according to the speed */ 320 /* Set HW EEE according to the speed */
306 priv->hw->mac->set_eee_pls(priv->ioaddr, 321 priv->hw->mac->set_eee_pls(priv->ioaddr,
307 priv->phydev->link); 322 priv->phydev->link);
308 323
309 pr_info("stmmac: Energy-Efficient Ethernet initialized\n"); 324 pr_debug("stmmac: Energy-Efficient Ethernet initialized\n");
310 325
311 ret = true; 326 ret = true;
312 } 327 }
@@ -886,10 +901,10 @@ static int stmmac_set_bfsize(int mtu, int bufsize)
886 ret = BUF_SIZE_8KiB; 901 ret = BUF_SIZE_8KiB;
887 else if (mtu >= BUF_SIZE_2KiB) 902 else if (mtu >= BUF_SIZE_2KiB)
888 ret = BUF_SIZE_4KiB; 903 ret = BUF_SIZE_4KiB;
889 else if (mtu >= DMA_BUFFER_SIZE) 904 else if (mtu > DEFAULT_BUFSIZE)
890 ret = BUF_SIZE_2KiB; 905 ret = BUF_SIZE_2KiB;
891 else 906 else
892 ret = DMA_BUFFER_SIZE; 907 ret = DEFAULT_BUFSIZE;
893 908
894 return ret; 909 return ret;
895} 910}
@@ -951,9 +966,9 @@ static int stmmac_init_rx_buffers(struct stmmac_priv *priv, struct dma_desc *p,
951 966
952 p->des2 = priv->rx_skbuff_dma[i]; 967 p->des2 = priv->rx_skbuff_dma[i];
953 968
954 if ((priv->mode == STMMAC_RING_MODE) && 969 if ((priv->hw->mode->init_desc3) &&
955 (priv->dma_buf_sz == BUF_SIZE_16KiB)) 970 (priv->dma_buf_sz == BUF_SIZE_16KiB))
956 priv->hw->ring->init_desc3(p); 971 priv->hw->mode->init_desc3(p);
957 972
958 return 0; 973 return 0;
959} 974}
@@ -984,11 +999,8 @@ static int init_dma_desc_rings(struct net_device *dev)
984 unsigned int bfsize = 0; 999 unsigned int bfsize = 0;
985 int ret = -ENOMEM; 1000 int ret = -ENOMEM;
986 1001
987 /* Set the max buffer size according to the DESC mode 1002 if (priv->hw->mode->set_16kib_bfsize)
988 * and the MTU. Note that RING mode allows 16KiB bsize. 1003 bfsize = priv->hw->mode->set_16kib_bfsize(dev->mtu);
989 */
990 if (priv->mode == STMMAC_RING_MODE)
991 bfsize = priv->hw->ring->set_16kib_bfsize(dev->mtu);
992 1004
993 if (bfsize < BUF_SIZE_16KiB) 1005 if (bfsize < BUF_SIZE_16KiB)
994 bfsize = stmmac_set_bfsize(dev->mtu, priv->dma_buf_sz); 1006 bfsize = stmmac_set_bfsize(dev->mtu, priv->dma_buf_sz);
@@ -1029,15 +1041,15 @@ static int init_dma_desc_rings(struct net_device *dev)
1029 /* Setup the chained descriptor addresses */ 1041 /* Setup the chained descriptor addresses */
1030 if (priv->mode == STMMAC_CHAIN_MODE) { 1042 if (priv->mode == STMMAC_CHAIN_MODE) {
1031 if (priv->extend_desc) { 1043 if (priv->extend_desc) {
1032 priv->hw->chain->init(priv->dma_erx, priv->dma_rx_phy, 1044 priv->hw->mode->init(priv->dma_erx, priv->dma_rx_phy,
1033 rxsize, 1); 1045 rxsize, 1);
1034 priv->hw->chain->init(priv->dma_etx, priv->dma_tx_phy, 1046 priv->hw->mode->init(priv->dma_etx, priv->dma_tx_phy,
1035 txsize, 1); 1047 txsize, 1);
1036 } else { 1048 } else {
1037 priv->hw->chain->init(priv->dma_rx, priv->dma_rx_phy, 1049 priv->hw->mode->init(priv->dma_rx, priv->dma_rx_phy,
1038 rxsize, 0); 1050 rxsize, 0);
1039 priv->hw->chain->init(priv->dma_tx, priv->dma_tx_phy, 1051 priv->hw->mode->init(priv->dma_tx, priv->dma_tx_phy,
1040 txsize, 0); 1052 txsize, 0);
1041 } 1053 }
1042 } 1054 }
1043 1055
@@ -1288,7 +1300,7 @@ static void stmmac_tx_clean(struct stmmac_priv *priv)
1288 DMA_TO_DEVICE); 1300 DMA_TO_DEVICE);
1289 priv->tx_skbuff_dma[entry] = 0; 1301 priv->tx_skbuff_dma[entry] = 0;
1290 } 1302 }
1291 priv->hw->ring->clean_desc3(priv, p); 1303 priv->hw->mode->clean_desc3(priv, p);
1292 1304
1293 if (likely(skb != NULL)) { 1305 if (likely(skb != NULL)) {
1294 dev_kfree_skb(skb); 1306 dev_kfree_skb(skb);
@@ -1705,7 +1717,7 @@ static int stmmac_open(struct net_device *dev)
1705 priv->dma_rx_size = STMMAC_ALIGN(dma_rxsize); 1717 priv->dma_rx_size = STMMAC_ALIGN(dma_rxsize);
1706 priv->dma_buf_sz = STMMAC_ALIGN(buf_sz); 1718 priv->dma_buf_sz = STMMAC_ALIGN(buf_sz);
1707 1719
1708 alloc_dma_desc_resources(priv); 1720 ret = alloc_dma_desc_resources(priv);
1709 if (ret < 0) { 1721 if (ret < 0) {
1710 pr_err("%s: DMA descriptors allocation failed\n", __func__); 1722 pr_err("%s: DMA descriptors allocation failed\n", __func__);
1711 goto dma_desc_error; 1723 goto dma_desc_error;
@@ -1844,6 +1856,7 @@ static netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev)
1844 int nfrags = skb_shinfo(skb)->nr_frags; 1856 int nfrags = skb_shinfo(skb)->nr_frags;
1845 struct dma_desc *desc, *first; 1857 struct dma_desc *desc, *first;
1846 unsigned int nopaged_len = skb_headlen(skb); 1858 unsigned int nopaged_len = skb_headlen(skb);
1859 unsigned int enh_desc = priv->plat->enh_desc;
1847 1860
1848 if (unlikely(stmmac_tx_avail(priv) < nfrags + 1)) { 1861 if (unlikely(stmmac_tx_avail(priv) < nfrags + 1)) {
1849 if (!netif_queue_stopped(dev)) { 1862 if (!netif_queue_stopped(dev)) {
@@ -1871,27 +1884,19 @@ static netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev)
1871 first = desc; 1884 first = desc;
1872 1885
1873 /* To program the descriptors according to the size of the frame */ 1886 /* To program the descriptors according to the size of the frame */
1874 if (priv->mode == STMMAC_RING_MODE) { 1887 if (enh_desc)
1875 is_jumbo = priv->hw->ring->is_jumbo_frm(skb->len, 1888 is_jumbo = priv->hw->mode->is_jumbo_frm(skb->len, enh_desc);
1876 priv->plat->enh_desc); 1889
1877 if (unlikely(is_jumbo))
1878 entry = priv->hw->ring->jumbo_frm(priv, skb,
1879 csum_insertion);
1880 } else {
1881 is_jumbo = priv->hw->chain->is_jumbo_frm(skb->len,
1882 priv->plat->enh_desc);
1883 if (unlikely(is_jumbo))
1884 entry = priv->hw->chain->jumbo_frm(priv, skb,
1885 csum_insertion);
1886 }
1887 if (likely(!is_jumbo)) { 1890 if (likely(!is_jumbo)) {
1888 desc->des2 = dma_map_single(priv->device, skb->data, 1891 desc->des2 = dma_map_single(priv->device, skb->data,
1889 nopaged_len, DMA_TO_DEVICE); 1892 nopaged_len, DMA_TO_DEVICE);
1890 priv->tx_skbuff_dma[entry] = desc->des2; 1893 priv->tx_skbuff_dma[entry] = desc->des2;
1891 priv->hw->desc->prepare_tx_desc(desc, 1, nopaged_len, 1894 priv->hw->desc->prepare_tx_desc(desc, 1, nopaged_len,
1892 csum_insertion, priv->mode); 1895 csum_insertion, priv->mode);
1893 } else 1896 } else {
1894 desc = first; 1897 desc = first;
1898 entry = priv->hw->mode->jumbo_frm(priv, skb, csum_insertion);
1899 }
1895 1900
1896 for (i = 0; i < nfrags; i++) { 1901 for (i = 0; i < nfrags; i++) {
1897 const skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; 1902 const skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
@@ -2029,7 +2034,7 @@ static inline void stmmac_rx_refill(struct stmmac_priv *priv)
2029 2034
2030 p->des2 = priv->rx_skbuff_dma[entry]; 2035 p->des2 = priv->rx_skbuff_dma[entry];
2031 2036
2032 priv->hw->ring->refill_desc3(priv, p); 2037 priv->hw->mode->refill_desc3(priv, p);
2033 2038
2034 if (netif_msg_rx_status(priv)) 2039 if (netif_msg_rx_status(priv))
2035 pr_debug("\trefill entry #%d\n", entry); 2040 pr_debug("\trefill entry #%d\n", entry);
@@ -2633,11 +2638,11 @@ static int stmmac_hw_init(struct stmmac_priv *priv)
2633 2638
2634 /* To use the chained or ring mode */ 2639 /* To use the chained or ring mode */
2635 if (chain_mode) { 2640 if (chain_mode) {
2636 priv->hw->chain = &chain_mode_ops; 2641 priv->hw->mode = &chain_mode_ops;
2637 pr_info(" Chain mode enabled\n"); 2642 pr_info(" Chain mode enabled\n");
2638 priv->mode = STMMAC_CHAIN_MODE; 2643 priv->mode = STMMAC_CHAIN_MODE;
2639 } else { 2644 } else {
2640 priv->hw->ring = &ring_mode_ops; 2645 priv->hw->mode = &ring_mode_ops;
2641 pr_info(" Ring mode enabled\n"); 2646 pr_info(" Ring mode enabled\n");
2642 priv->mode = STMMAC_RING_MODE; 2647 priv->mode = STMMAC_RING_MODE;
2643 } 2648 }
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
index c61bc72b8e90..8fb32a80f1c1 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
@@ -36,7 +36,7 @@ static const struct of_device_id stmmac_dt_ids[] = {
36#ifdef CONFIG_DWMAC_STI 36#ifdef CONFIG_DWMAC_STI
37 { .compatible = "st,stih415-dwmac", .data = &sti_gmac_data}, 37 { .compatible = "st,stih415-dwmac", .data = &sti_gmac_data},
38 { .compatible = "st,stih416-dwmac", .data = &sti_gmac_data}, 38 { .compatible = "st,stih416-dwmac", .data = &sti_gmac_data},
39 { .compatible = "st,stih127-dwmac", .data = &sti_gmac_data}, 39 { .compatible = "st,stid127-dwmac", .data = &sti_gmac_data},
40#endif 40#endif
41 /* SoC specific glue layers should come before generic bindings */ 41 /* SoC specific glue layers should come before generic bindings */
42 { .compatible = "st,spear600-gmac"}, 42 { .compatible = "st,spear600-gmac"},
diff --git a/drivers/net/ethernet/ti/cpsw.c b/drivers/net/ethernet/ti/cpsw.c
index 651087b5c8da..7d6d8ec676c8 100644
--- a/drivers/net/ethernet/ti/cpsw.c
+++ b/drivers/net/ethernet/ti/cpsw.c
@@ -1164,11 +1164,17 @@ static void cpsw_init_host_port(struct cpsw_priv *priv)
1164 1164
1165static void cpsw_slave_stop(struct cpsw_slave *slave, struct cpsw_priv *priv) 1165static void cpsw_slave_stop(struct cpsw_slave *slave, struct cpsw_priv *priv)
1166{ 1166{
1167 u32 slave_port;
1168
1169 slave_port = cpsw_get_slave_port(priv, slave->slave_num);
1170
1167 if (!slave->phy) 1171 if (!slave->phy)
1168 return; 1172 return;
1169 phy_stop(slave->phy); 1173 phy_stop(slave->phy);
1170 phy_disconnect(slave->phy); 1174 phy_disconnect(slave->phy);
1171 slave->phy = NULL; 1175 slave->phy = NULL;
1176 cpsw_ale_control_set(priv->ale, slave_port,
1177 ALE_PORT_STATE, ALE_PORT_STATE_DISABLE);
1172} 1178}
1173 1179
1174static int cpsw_ndo_open(struct net_device *ndev) 1180static int cpsw_ndo_open(struct net_device *ndev)
@@ -2223,10 +2229,6 @@ static int cpsw_probe(struct platform_device *pdev)
2223 goto clean_ale_ret; 2229 goto clean_ale_ret;
2224 } 2230 }
2225 2231
2226 if (cpts_register(&pdev->dev, priv->cpts,
2227 data->cpts_clock_mult, data->cpts_clock_shift))
2228 dev_err(priv->dev, "error registering cpts device\n");
2229
2230 cpsw_notice(priv, probe, "initialized device (regs %pa, irq %d)\n", 2232 cpsw_notice(priv, probe, "initialized device (regs %pa, irq %d)\n",
2231 &ss_res->start, ndev->irq); 2233 &ss_res->start, ndev->irq);
2232 2234
diff --git a/drivers/net/ethernet/ti/davinci_cpdma.c b/drivers/net/ethernet/ti/davinci_cpdma.c
index 364d0c7952c0..88ef27067bf2 100644
--- a/drivers/net/ethernet/ti/davinci_cpdma.c
+++ b/drivers/net/ethernet/ti/davinci_cpdma.c
@@ -355,7 +355,7 @@ int cpdma_ctlr_stop(struct cpdma_ctlr *ctlr)
355 int i; 355 int i;
356 356
357 spin_lock_irqsave(&ctlr->lock, flags); 357 spin_lock_irqsave(&ctlr->lock, flags);
358 if (ctlr->state != CPDMA_STATE_ACTIVE) { 358 if (ctlr->state == CPDMA_STATE_TEARDOWN) {
359 spin_unlock_irqrestore(&ctlr->lock, flags); 359 spin_unlock_irqrestore(&ctlr->lock, flags);
360 return -EINVAL; 360 return -EINVAL;
361 } 361 }
@@ -891,7 +891,7 @@ int cpdma_chan_stop(struct cpdma_chan *chan)
891 unsigned timeout; 891 unsigned timeout;
892 892
893 spin_lock_irqsave(&chan->lock, flags); 893 spin_lock_irqsave(&chan->lock, flags);
894 if (chan->state != CPDMA_STATE_ACTIVE) { 894 if (chan->state == CPDMA_STATE_TEARDOWN) {
895 spin_unlock_irqrestore(&chan->lock, flags); 895 spin_unlock_irqrestore(&chan->lock, flags);
896 return -EINVAL; 896 return -EINVAL;
897 } 897 }
diff --git a/drivers/net/ethernet/ti/davinci_emac.c b/drivers/net/ethernet/ti/davinci_emac.c
index cd9b164a0434..8f0e69ce07ca 100644
--- a/drivers/net/ethernet/ti/davinci_emac.c
+++ b/drivers/net/ethernet/ti/davinci_emac.c
@@ -1532,9 +1532,9 @@ static int emac_dev_open(struct net_device *ndev)
1532 struct device *emac_dev = &ndev->dev; 1532 struct device *emac_dev = &ndev->dev;
1533 u32 cnt; 1533 u32 cnt;
1534 struct resource *res; 1534 struct resource *res;
1535 int ret; 1535 int q, m, ret;
1536 int res_num = 0, irq_num = 0;
1536 int i = 0; 1537 int i = 0;
1537 int k = 0;
1538 struct emac_priv *priv = netdev_priv(ndev); 1538 struct emac_priv *priv = netdev_priv(ndev);
1539 1539
1540 pm_runtime_get(&priv->pdev->dev); 1540 pm_runtime_get(&priv->pdev->dev);
@@ -1564,15 +1564,24 @@ static int emac_dev_open(struct net_device *ndev)
1564 } 1564 }
1565 1565
1566 /* Request IRQ */ 1566 /* Request IRQ */
1567 while ((res = platform_get_resource(priv->pdev, IORESOURCE_IRQ,
1568 res_num))) {
1569 for (irq_num = res->start; irq_num <= res->end; irq_num++) {
1570 dev_err(emac_dev, "Request IRQ %d\n", irq_num);
1571 if (request_irq(irq_num, emac_irq, 0, ndev->name,
1572 ndev)) {
1573 dev_err(emac_dev,
1574 "DaVinci EMAC: request_irq() failed\n");
1575 ret = -EBUSY;
1567 1576
1568 while ((res = platform_get_resource(priv->pdev, IORESOURCE_IRQ, k))) {
1569 for (i = res->start; i <= res->end; i++) {
1570 if (devm_request_irq(&priv->pdev->dev, i, emac_irq,
1571 0, ndev->name, ndev))
1572 goto rollback; 1577 goto rollback;
1578 }
1573 } 1579 }
1574 k++; 1580 res_num++;
1575 } 1581 }
1582 /* prepare counters for rollback in case of an error */
1583 res_num--;
1584 irq_num--;
1576 1585
1577 /* Start/Enable EMAC hardware */ 1586 /* Start/Enable EMAC hardware */
1578 emac_hw_enable(priv); 1587 emac_hw_enable(priv);
@@ -1639,11 +1648,23 @@ static int emac_dev_open(struct net_device *ndev)
1639 1648
1640 return 0; 1649 return 0;
1641 1650
1642rollback:
1643
1644 dev_err(emac_dev, "DaVinci EMAC: devm_request_irq() failed");
1645 ret = -EBUSY;
1646err: 1651err:
1652 emac_int_disable(priv);
1653 napi_disable(&priv->napi);
1654
1655rollback:
1656 for (q = res_num; q >= 0; q--) {
1657 res = platform_get_resource(priv->pdev, IORESOURCE_IRQ, q);
1658 /* at the first iteration, irq_num is already set to the
1659 * right value
1660 */
1661 if (q != res_num)
1662 irq_num = res->end;
1663
1664 for (m = irq_num; m >= res->start; m--)
1665 free_irq(m, ndev);
1666 }
1667 cpdma_ctlr_stop(priv->dma);
1647 pm_runtime_put(&priv->pdev->dev); 1668 pm_runtime_put(&priv->pdev->dev);
1648 return ret; 1669 return ret;
1649} 1670}
@@ -1659,6 +1680,9 @@ err:
1659 */ 1680 */
1660static int emac_dev_stop(struct net_device *ndev) 1681static int emac_dev_stop(struct net_device *ndev)
1661{ 1682{
1683 struct resource *res;
1684 int i = 0;
1685 int irq_num;
1662 struct emac_priv *priv = netdev_priv(ndev); 1686 struct emac_priv *priv = netdev_priv(ndev);
1663 struct device *emac_dev = &ndev->dev; 1687 struct device *emac_dev = &ndev->dev;
1664 1688
@@ -1674,6 +1698,13 @@ static int emac_dev_stop(struct net_device *ndev)
1674 if (priv->phydev) 1698 if (priv->phydev)
1675 phy_disconnect(priv->phydev); 1699 phy_disconnect(priv->phydev);
1676 1700
1701 /* Free IRQ */
1702 while ((res = platform_get_resource(priv->pdev, IORESOURCE_IRQ, i))) {
1703 for (irq_num = res->start; irq_num <= res->end; irq_num++)
1704 free_irq(irq_num, priv->ndev);
1705 i++;
1706 }
1707
1677 if (netif_msg_drv(priv)) 1708 if (netif_msg_drv(priv))
1678 dev_notice(emac_dev, "DaVinci EMAC: %s stopped\n", ndev->name); 1709 dev_notice(emac_dev, "DaVinci EMAC: %s stopped\n", ndev->name);
1679 1710
diff --git a/drivers/net/ethernet/via/via-rhine.c b/drivers/net/ethernet/via/via-rhine.c
index ef312bc6b865..6ac20a6738f4 100644
--- a/drivers/net/ethernet/via/via-rhine.c
+++ b/drivers/net/ethernet/via/via-rhine.c
@@ -923,7 +923,7 @@ static int rhine_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
923 if (rc) { 923 if (rc) {
924 dev_err(&pdev->dev, 924 dev_err(&pdev->dev,
925 "32-bit PCI DMA addresses not supported by the card!?\n"); 925 "32-bit PCI DMA addresses not supported by the card!?\n");
926 goto err_out; 926 goto err_out_pci_disable;
927 } 927 }
928 928
929 /* sanity check */ 929 /* sanity check */
@@ -931,7 +931,7 @@ static int rhine_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
931 (pci_resource_len(pdev, 1) < io_size)) { 931 (pci_resource_len(pdev, 1) < io_size)) {
932 rc = -EIO; 932 rc = -EIO;
933 dev_err(&pdev->dev, "Insufficient PCI resources, aborting\n"); 933 dev_err(&pdev->dev, "Insufficient PCI resources, aborting\n");
934 goto err_out; 934 goto err_out_pci_disable;
935 } 935 }
936 936
937 pioaddr = pci_resource_start(pdev, 0); 937 pioaddr = pci_resource_start(pdev, 0);
@@ -942,7 +942,7 @@ static int rhine_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
942 dev = alloc_etherdev(sizeof(struct rhine_private)); 942 dev = alloc_etherdev(sizeof(struct rhine_private));
943 if (!dev) { 943 if (!dev) {
944 rc = -ENOMEM; 944 rc = -ENOMEM;
945 goto err_out; 945 goto err_out_pci_disable;
946 } 946 }
947 SET_NETDEV_DEV(dev, &pdev->dev); 947 SET_NETDEV_DEV(dev, &pdev->dev);
948 948
@@ -1084,6 +1084,8 @@ err_out_free_res:
1084 pci_release_regions(pdev); 1084 pci_release_regions(pdev);
1085err_out_free_netdev: 1085err_out_free_netdev:
1086 free_netdev(dev); 1086 free_netdev(dev);
1087err_out_pci_disable:
1088 pci_disable_device(pdev);
1087err_out: 1089err_out:
1088 return rc; 1090 return rc;
1089} 1091}
diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c
index 7141a1937360..d6fce9750b95 100644
--- a/drivers/net/hyperv/netvsc_drv.c
+++ b/drivers/net/hyperv/netvsc_drv.c
@@ -442,6 +442,8 @@ static int netvsc_probe(struct hv_device *dev,
442 if (!net) 442 if (!net)
443 return -ENOMEM; 443 return -ENOMEM;
444 444
445 netif_carrier_off(net);
446
445 net_device_ctx = netdev_priv(net); 447 net_device_ctx = netdev_priv(net);
446 net_device_ctx->device_ctx = dev; 448 net_device_ctx->device_ctx = dev;
447 hv_set_drvdata(dev, net); 449 hv_set_drvdata(dev, net);
@@ -473,6 +475,8 @@ static int netvsc_probe(struct hv_device *dev,
473 pr_err("Unable to register netdev.\n"); 475 pr_err("Unable to register netdev.\n");
474 rndis_filter_device_remove(dev); 476 rndis_filter_device_remove(dev);
475 free_netdev(net); 477 free_netdev(net);
478 } else {
479 schedule_delayed_work(&net_device_ctx->dwork, 0);
476 } 480 }
477 481
478 return ret; 482 return ret;
diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
index 1084e5de3ceb..b54fd257652b 100644
--- a/drivers/net/hyperv/rndis_filter.c
+++ b/drivers/net/hyperv/rndis_filter.c
@@ -243,6 +243,22 @@ static int rndis_filter_send_request(struct rndis_device *dev,
243 return ret; 243 return ret;
244} 244}
245 245
246static void rndis_set_link_state(struct rndis_device *rdev,
247 struct rndis_request *request)
248{
249 u32 link_status;
250 struct rndis_query_complete *query_complete;
251
252 query_complete = &request->response_msg.msg.query_complete;
253
254 if (query_complete->status == RNDIS_STATUS_SUCCESS &&
255 query_complete->info_buflen == sizeof(u32)) {
256 memcpy(&link_status, (void *)((unsigned long)query_complete +
257 query_complete->info_buf_offset), sizeof(u32));
258 rdev->link_state = link_status != 0;
259 }
260}
261
246static void rndis_filter_receive_response(struct rndis_device *dev, 262static void rndis_filter_receive_response(struct rndis_device *dev,
247 struct rndis_message *resp) 263 struct rndis_message *resp)
248{ 264{
@@ -272,6 +288,10 @@ static void rndis_filter_receive_response(struct rndis_device *dev,
272 sizeof(struct rndis_message) + RNDIS_EXT_LEN) { 288 sizeof(struct rndis_message) + RNDIS_EXT_LEN) {
273 memcpy(&request->response_msg, resp, 289 memcpy(&request->response_msg, resp,
274 resp->msg_len); 290 resp->msg_len);
291 if (request->request_msg.ndis_msg_type ==
292 RNDIS_MSG_QUERY && request->request_msg.msg.
293 query_req.oid == RNDIS_OID_GEN_MEDIA_CONNECT_STATUS)
294 rndis_set_link_state(dev, request);
275 } else { 295 } else {
276 netdev_err(ndev, 296 netdev_err(ndev,
277 "rndis response buffer overflow " 297 "rndis response buffer overflow "
@@ -620,7 +640,6 @@ static int rndis_filter_query_device_link_status(struct rndis_device *dev)
620 ret = rndis_filter_query_device(dev, 640 ret = rndis_filter_query_device(dev,
621 RNDIS_OID_GEN_MEDIA_CONNECT_STATUS, 641 RNDIS_OID_GEN_MEDIA_CONNECT_STATUS,
622 &link_status, &size); 642 &link_status, &size);
623 dev->link_state = (link_status != 0) ? true : false;
624 643
625 return ret; 644 return ret;
626} 645}
diff --git a/drivers/net/ieee802154/at86rf230.c b/drivers/net/ieee802154/at86rf230.c
index ab31544bc254..a30258aad139 100644
--- a/drivers/net/ieee802154/at86rf230.c
+++ b/drivers/net/ieee802154/at86rf230.c
@@ -546,12 +546,12 @@ at86rf230_xmit(struct ieee802154_dev *dev, struct sk_buff *skb)
546 int rc; 546 int rc;
547 unsigned long flags; 547 unsigned long flags;
548 548
549 spin_lock(&lp->lock); 549 spin_lock_irqsave(&lp->lock, flags);
550 if (lp->irq_busy) { 550 if (lp->irq_busy) {
551 spin_unlock(&lp->lock); 551 spin_unlock_irqrestore(&lp->lock, flags);
552 return -EBUSY; 552 return -EBUSY;
553 } 553 }
554 spin_unlock(&lp->lock); 554 spin_unlock_irqrestore(&lp->lock, flags);
555 555
556 might_sleep(); 556 might_sleep();
557 557
@@ -725,10 +725,11 @@ static void at86rf230_irqwork_level(struct work_struct *work)
725static irqreturn_t at86rf230_isr(int irq, void *data) 725static irqreturn_t at86rf230_isr(int irq, void *data)
726{ 726{
727 struct at86rf230_local *lp = data; 727 struct at86rf230_local *lp = data;
728 unsigned long flags;
728 729
729 spin_lock(&lp->lock); 730 spin_lock_irqsave(&lp->lock, flags);
730 lp->irq_busy = 1; 731 lp->irq_busy = 1;
731 spin_unlock(&lp->lock); 732 spin_unlock_irqrestore(&lp->lock, flags);
732 733
733 schedule_work(&lp->irqwork); 734 schedule_work(&lp->irqwork);
734 735
diff --git a/drivers/net/ifb.c b/drivers/net/ifb.c
index c14d39bf32d0..d7b2e947184b 100644
--- a/drivers/net/ifb.c
+++ b/drivers/net/ifb.c
@@ -180,7 +180,8 @@ static void ifb_setup(struct net_device *dev)
180 dev->tx_queue_len = TX_Q_LIMIT; 180 dev->tx_queue_len = TX_Q_LIMIT;
181 181
182 dev->features |= IFB_FEATURES; 182 dev->features |= IFB_FEATURES;
183 dev->vlan_features |= IFB_FEATURES; 183 dev->vlan_features |= IFB_FEATURES & ~(NETIF_F_HW_VLAN_CTAG_TX |
184 NETIF_F_HW_VLAN_STAG_TX);
184 185
185 dev->flags |= IFF_NOARP; 186 dev->flags |= IFF_NOARP;
186 dev->flags &= ~IFF_MULTICAST; 187 dev->flags &= ~IFF_MULTICAST;
diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
index a5d21893670d..1831fb7cd017 100644
--- a/drivers/net/macvlan.c
+++ b/drivers/net/macvlan.c
@@ -506,6 +506,9 @@ static int macvlan_change_mtu(struct net_device *dev, int new_mtu)
506static struct lock_class_key macvlan_netdev_xmit_lock_key; 506static struct lock_class_key macvlan_netdev_xmit_lock_key;
507static struct lock_class_key macvlan_netdev_addr_lock_key; 507static struct lock_class_key macvlan_netdev_addr_lock_key;
508 508
509#define ALWAYS_ON_FEATURES \
510 (NETIF_F_SG | NETIF_F_GEN_CSUM | NETIF_F_GSO_SOFTWARE | NETIF_F_LLTX)
511
509#define MACVLAN_FEATURES \ 512#define MACVLAN_FEATURES \
510 (NETIF_F_SG | NETIF_F_ALL_CSUM | NETIF_F_HIGHDMA | NETIF_F_FRAGLIST | \ 513 (NETIF_F_SG | NETIF_F_ALL_CSUM | NETIF_F_HIGHDMA | NETIF_F_FRAGLIST | \
511 NETIF_F_GSO | NETIF_F_TSO | NETIF_F_UFO | NETIF_F_GSO_ROBUST | \ 514 NETIF_F_GSO | NETIF_F_TSO | NETIF_F_UFO | NETIF_F_GSO_ROBUST | \
@@ -539,7 +542,7 @@ static int macvlan_init(struct net_device *dev)
539 dev->state = (dev->state & ~MACVLAN_STATE_MASK) | 542 dev->state = (dev->state & ~MACVLAN_STATE_MASK) |
540 (lowerdev->state & MACVLAN_STATE_MASK); 543 (lowerdev->state & MACVLAN_STATE_MASK);
541 dev->features = lowerdev->features & MACVLAN_FEATURES; 544 dev->features = lowerdev->features & MACVLAN_FEATURES;
542 dev->features |= NETIF_F_LLTX; 545 dev->features |= ALWAYS_ON_FEATURES;
543 dev->gso_max_size = lowerdev->gso_max_size; 546 dev->gso_max_size = lowerdev->gso_max_size;
544 dev->iflink = lowerdev->ifindex; 547 dev->iflink = lowerdev->ifindex;
545 dev->hard_header_len = lowerdev->hard_header_len; 548 dev->hard_header_len = lowerdev->hard_header_len;
@@ -699,7 +702,7 @@ static netdev_features_t macvlan_fix_features(struct net_device *dev,
699 features = netdev_increment_features(vlan->lowerdev->features, 702 features = netdev_increment_features(vlan->lowerdev->features,
700 features, 703 features,
701 mask); 704 mask);
702 features |= NETIF_F_LLTX; 705 features |= ALWAYS_ON_FEATURES;
703 706
704 return features; 707 return features;
705} 708}
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index 19c9eca0ef26..76d96b9ebcdb 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -164,9 +164,9 @@ static const struct phy_setting settings[] = {
164 * of that setting. Returns the index of the last setting if 164 * of that setting. Returns the index of the last setting if
165 * none of the others match. 165 * none of the others match.
166 */ 166 */
167static inline int phy_find_setting(int speed, int duplex) 167static inline unsigned int phy_find_setting(int speed, int duplex)
168{ 168{
169 int idx = 0; 169 unsigned int idx = 0;
170 170
171 while (idx < ARRAY_SIZE(settings) && 171 while (idx < ARRAY_SIZE(settings) &&
172 (settings[idx].speed != speed || settings[idx].duplex != duplex)) 172 (settings[idx].speed != speed || settings[idx].duplex != duplex))
@@ -185,7 +185,7 @@ static inline int phy_find_setting(int speed, int duplex)
185 * the mask in features. Returns the index of the last setting 185 * the mask in features. Returns the index of the last setting
186 * if nothing else matches. 186 * if nothing else matches.
187 */ 187 */
188static inline int phy_find_valid(int idx, u32 features) 188static inline unsigned int phy_find_valid(unsigned int idx, u32 features)
189{ 189{
190 while (idx < MAX_NUM_SETTINGS && !(settings[idx].setting & features)) 190 while (idx < MAX_NUM_SETTINGS && !(settings[idx].setting & features))
191 idx++; 191 idx++;
@@ -204,7 +204,7 @@ static inline int phy_find_valid(int idx, u32 features)
204static void phy_sanitize_settings(struct phy_device *phydev) 204static void phy_sanitize_settings(struct phy_device *phydev)
205{ 205{
206 u32 features = phydev->supported; 206 u32 features = phydev->supported;
207 int idx; 207 unsigned int idx;
208 208
209 /* Sanitize settings based on PHY capabilities */ 209 /* Sanitize settings based on PHY capabilities */
210 if ((features & SUPPORTED_Autoneg) == 0) 210 if ((features & SUPPORTED_Autoneg) == 0)
@@ -954,7 +954,8 @@ int phy_init_eee(struct phy_device *phydev, bool clk_stop_enable)
954 (phydev->interface == PHY_INTERFACE_MODE_RGMII))) { 954 (phydev->interface == PHY_INTERFACE_MODE_RGMII))) {
955 int eee_lp, eee_cap, eee_adv; 955 int eee_lp, eee_cap, eee_adv;
956 u32 lp, cap, adv; 956 u32 lp, cap, adv;
957 int idx, status; 957 int status;
958 unsigned int idx;
958 959
959 /* Read phy status to properly get the right settings */ 960 /* Read phy status to properly get the right settings */
960 status = phy_read_status(phydev); 961 status = phy_read_status(phydev);
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 82514e72b3d8..2f6989b1e0dc 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -683,10 +683,9 @@ EXPORT_SYMBOL(phy_detach);
683int phy_suspend(struct phy_device *phydev) 683int phy_suspend(struct phy_device *phydev)
684{ 684{
685 struct phy_driver *phydrv = to_phy_driver(phydev->dev.driver); 685 struct phy_driver *phydrv = to_phy_driver(phydev->dev.driver);
686 struct ethtool_wolinfo wol; 686 struct ethtool_wolinfo wol = { .cmd = ETHTOOL_GWOL };
687 687
688 /* If the device has WOL enabled, we cannot suspend the PHY */ 688 /* If the device has WOL enabled, we cannot suspend the PHY */
689 wol.cmd = ETHTOOL_GWOL;
690 phy_ethtool_get_wol(phydev, &wol); 689 phy_ethtool_get_wol(phydev, &wol);
691 if (wol.wolopts) 690 if (wol.wolopts)
692 return -EBUSY; 691 return -EBUSY;
@@ -916,6 +915,8 @@ int genphy_read_status(struct phy_device *phydev)
916 int err; 915 int err;
917 int lpa; 916 int lpa;
918 int lpagb = 0; 917 int lpagb = 0;
918 int common_adv;
919 int common_adv_gb = 0;
919 920
920 /* Update the link, but return if there was an error */ 921 /* Update the link, but return if there was an error */
921 err = genphy_update_link(phydev); 922 err = genphy_update_link(phydev);
@@ -937,7 +938,7 @@ int genphy_read_status(struct phy_device *phydev)
937 938
938 phydev->lp_advertising = 939 phydev->lp_advertising =
939 mii_stat1000_to_ethtool_lpa_t(lpagb); 940 mii_stat1000_to_ethtool_lpa_t(lpagb);
940 lpagb &= adv << 2; 941 common_adv_gb = lpagb & adv << 2;
941 } 942 }
942 943
943 lpa = phy_read(phydev, MII_LPA); 944 lpa = phy_read(phydev, MII_LPA);
@@ -950,25 +951,25 @@ int genphy_read_status(struct phy_device *phydev)
950 if (adv < 0) 951 if (adv < 0)
951 return adv; 952 return adv;
952 953
953 lpa &= adv; 954 common_adv = lpa & adv;
954 955
955 phydev->speed = SPEED_10; 956 phydev->speed = SPEED_10;
956 phydev->duplex = DUPLEX_HALF; 957 phydev->duplex = DUPLEX_HALF;
957 phydev->pause = 0; 958 phydev->pause = 0;
958 phydev->asym_pause = 0; 959 phydev->asym_pause = 0;
959 960
960 if (lpagb & (LPA_1000FULL | LPA_1000HALF)) { 961 if (common_adv_gb & (LPA_1000FULL | LPA_1000HALF)) {
961 phydev->speed = SPEED_1000; 962 phydev->speed = SPEED_1000;
962 963
963 if (lpagb & LPA_1000FULL) 964 if (common_adv_gb & LPA_1000FULL)
964 phydev->duplex = DUPLEX_FULL; 965 phydev->duplex = DUPLEX_FULL;
965 } else if (lpa & (LPA_100FULL | LPA_100HALF)) { 966 } else if (common_adv & (LPA_100FULL | LPA_100HALF)) {
966 phydev->speed = SPEED_100; 967 phydev->speed = SPEED_100;
967 968
968 if (lpa & LPA_100FULL) 969 if (common_adv & LPA_100FULL)
969 phydev->duplex = DUPLEX_FULL; 970 phydev->duplex = DUPLEX_FULL;
970 } else 971 } else
971 if (lpa & LPA_10FULL) 972 if (common_adv & LPA_10FULL)
972 phydev->duplex = DUPLEX_FULL; 973 phydev->duplex = DUPLEX_FULL;
973 974
974 if (phydev->duplex == DUPLEX_FULL) { 975 if (phydev->duplex == DUPLEX_FULL) {
diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index 8fe9cb7d0f72..26f8635b027d 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -1686,7 +1686,9 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
1686 TUN_USER_FEATURES | NETIF_F_HW_VLAN_CTAG_TX | 1686 TUN_USER_FEATURES | NETIF_F_HW_VLAN_CTAG_TX |
1687 NETIF_F_HW_VLAN_STAG_TX; 1687 NETIF_F_HW_VLAN_STAG_TX;
1688 dev->features = dev->hw_features; 1688 dev->features = dev->hw_features;
1689 dev->vlan_features = dev->features; 1689 dev->vlan_features = dev->features &
1690 ~(NETIF_F_HW_VLAN_CTAG_TX |
1691 NETIF_F_HW_VLAN_STAG_TX);
1690 1692
1691 INIT_LIST_HEAD(&tun->disabled); 1693 INIT_LIST_HEAD(&tun->disabled);
1692 err = tun_attach(tun, file, false); 1694 err = tun_attach(tun, file, false);
diff --git a/drivers/net/usb/Makefile b/drivers/net/usb/Makefile
index 433f0a00c683..e2797f1e1b31 100644
--- a/drivers/net/usb/Makefile
+++ b/drivers/net/usb/Makefile
@@ -11,7 +11,7 @@ obj-$(CONFIG_USB_HSO) += hso.o
11obj-$(CONFIG_USB_NET_AX8817X) += asix.o 11obj-$(CONFIG_USB_NET_AX8817X) += asix.o
12asix-y := asix_devices.o asix_common.o ax88172a.o 12asix-y := asix_devices.o asix_common.o ax88172a.o
13obj-$(CONFIG_USB_NET_AX88179_178A) += ax88179_178a.o 13obj-$(CONFIG_USB_NET_AX88179_178A) += ax88179_178a.o
14obj-$(CONFIG_USB_NET_CDCETHER) += cdc_ether.o r815x.o 14obj-$(CONFIG_USB_NET_CDCETHER) += cdc_ether.o
15obj-$(CONFIG_USB_NET_CDC_EEM) += cdc_eem.o 15obj-$(CONFIG_USB_NET_CDC_EEM) += cdc_eem.o
16obj-$(CONFIG_USB_NET_DM9601) += dm9601.o 16obj-$(CONFIG_USB_NET_DM9601) += dm9601.o
17obj-$(CONFIG_USB_NET_SR9700) += sr9700.o 17obj-$(CONFIG_USB_NET_SR9700) += sr9700.o
diff --git a/drivers/net/usb/ax88179_178a.c b/drivers/net/usb/ax88179_178a.c
index 955df81a4358..054e59ca6946 100644
--- a/drivers/net/usb/ax88179_178a.c
+++ b/drivers/net/usb/ax88179_178a.c
@@ -1029,20 +1029,12 @@ static int ax88179_bind(struct usbnet *dev, struct usb_interface *intf)
1029 dev->mii.phy_id = 0x03; 1029 dev->mii.phy_id = 0x03;
1030 dev->mii.supports_gmii = 1; 1030 dev->mii.supports_gmii = 1;
1031 1031
1032 if (usb_device_no_sg_constraint(dev->udev))
1033 dev->can_dma_sg = 1;
1034
1035 dev->net->features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | 1032 dev->net->features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
1036 NETIF_F_RXCSUM; 1033 NETIF_F_RXCSUM;
1037 1034
1038 dev->net->hw_features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | 1035 dev->net->hw_features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
1039 NETIF_F_RXCSUM; 1036 NETIF_F_RXCSUM;
1040 1037
1041 if (dev->can_dma_sg) {
1042 dev->net->features |= NETIF_F_SG | NETIF_F_TSO;
1043 dev->net->hw_features |= NETIF_F_SG | NETIF_F_TSO;
1044 }
1045
1046 /* Enable checksum offload */ 1038 /* Enable checksum offload */
1047 *tmp = AX_RXCOE_IP | AX_RXCOE_TCP | AX_RXCOE_UDP | 1039 *tmp = AX_RXCOE_IP | AX_RXCOE_TCP | AX_RXCOE_UDP |
1048 AX_RXCOE_TCPV6 | AX_RXCOE_UDPV6; 1040 AX_RXCOE_TCPV6 | AX_RXCOE_UDPV6;
@@ -1395,6 +1387,19 @@ static const struct driver_info ax88178a_info = {
1395 .tx_fixup = ax88179_tx_fixup, 1387 .tx_fixup = ax88179_tx_fixup,
1396}; 1388};
1397 1389
1390static const struct driver_info dlink_dub1312_info = {
1391 .description = "D-Link DUB-1312 USB 3.0 to Gigabit Ethernet Adapter",
1392 .bind = ax88179_bind,
1393 .unbind = ax88179_unbind,
1394 .status = ax88179_status,
1395 .link_reset = ax88179_link_reset,
1396 .reset = ax88179_reset,
1397 .stop = ax88179_stop,
1398 .flags = FLAG_ETHER | FLAG_FRAMING_AX,
1399 .rx_fixup = ax88179_rx_fixup,
1400 .tx_fixup = ax88179_tx_fixup,
1401};
1402
1398static const struct driver_info sitecom_info = { 1403static const struct driver_info sitecom_info = {
1399 .description = "Sitecom USB 3.0 to Gigabit Adapter", 1404 .description = "Sitecom USB 3.0 to Gigabit Adapter",
1400 .bind = ax88179_bind, 1405 .bind = ax88179_bind,
@@ -1421,6 +1426,19 @@ static const struct driver_info samsung_info = {
1421 .tx_fixup = ax88179_tx_fixup, 1426 .tx_fixup = ax88179_tx_fixup,
1422}; 1427};
1423 1428
1429static const struct driver_info lenovo_info = {
1430 .description = "Lenovo OneLinkDock Gigabit LAN",
1431 .bind = ax88179_bind,
1432 .unbind = ax88179_unbind,
1433 .status = ax88179_status,
1434 .link_reset = ax88179_link_reset,
1435 .reset = ax88179_reset,
1436 .stop = ax88179_stop,
1437 .flags = FLAG_ETHER | FLAG_FRAMING_AX,
1438 .rx_fixup = ax88179_rx_fixup,
1439 .tx_fixup = ax88179_tx_fixup,
1440};
1441
1424static const struct usb_device_id products[] = { 1442static const struct usb_device_id products[] = {
1425{ 1443{
1426 /* ASIX AX88179 10/100/1000 */ 1444 /* ASIX AX88179 10/100/1000 */
@@ -1431,6 +1449,10 @@ static const struct usb_device_id products[] = {
1431 USB_DEVICE(0x0b95, 0x178a), 1449 USB_DEVICE(0x0b95, 0x178a),
1432 .driver_info = (unsigned long)&ax88178a_info, 1450 .driver_info = (unsigned long)&ax88178a_info,
1433}, { 1451}, {
1452 /* D-Link DUB-1312 USB 3.0 to Gigabit Ethernet Adapter */
1453 USB_DEVICE(0x2001, 0x4a00),
1454 .driver_info = (unsigned long)&dlink_dub1312_info,
1455}, {
1434 /* Sitecom USB 3.0 to Gigabit Adapter */ 1456 /* Sitecom USB 3.0 to Gigabit Adapter */
1435 USB_DEVICE(0x0df6, 0x0072), 1457 USB_DEVICE(0x0df6, 0x0072),
1436 .driver_info = (unsigned long)&sitecom_info, 1458 .driver_info = (unsigned long)&sitecom_info,
@@ -1438,6 +1460,10 @@ static const struct usb_device_id products[] = {
1438 /* Samsung USB Ethernet Adapter */ 1460 /* Samsung USB Ethernet Adapter */
1439 USB_DEVICE(0x04e8, 0xa100), 1461 USB_DEVICE(0x04e8, 0xa100),
1440 .driver_info = (unsigned long)&samsung_info, 1462 .driver_info = (unsigned long)&samsung_info,
1463}, {
1464 /* Lenovo OneLinkDock Gigabit LAN */
1465 USB_DEVICE(0x17ef, 0x304b),
1466 .driver_info = (unsigned long)&lenovo_info,
1441}, 1467},
1442 { }, 1468 { },
1443}; 1469};
diff --git a/drivers/net/usb/cdc_ether.c b/drivers/net/usb/cdc_ether.c
index 42e176912c8e..bd363b27e854 100644
--- a/drivers/net/usb/cdc_ether.c
+++ b/drivers/net/usb/cdc_ether.c
@@ -652,6 +652,13 @@ static const struct usb_device_id products[] = {
652 .driver_info = 0, 652 .driver_info = 0,
653}, 653},
654 654
655/* Samsung USB Ethernet Adapters */
656{
657 USB_DEVICE_AND_INTERFACE_INFO(SAMSUNG_VENDOR_ID, 0xa101, USB_CLASS_COMM,
658 USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
659 .driver_info = 0,
660},
661
655/* WHITELIST!!! 662/* WHITELIST!!!
656 * 663 *
657 * CDC Ether uses two interfaces, not necessarily consecutive. 664 * CDC Ether uses two interfaces, not necessarily consecutive.
diff --git a/drivers/net/usb/cdc_ncm.c b/drivers/net/usb/cdc_ncm.c
index dbff290ed0e4..d350d2795e10 100644
--- a/drivers/net/usb/cdc_ncm.c
+++ b/drivers/net/usb/cdc_ncm.c
@@ -68,7 +68,6 @@ static struct usb_driver cdc_ncm_driver;
68static int cdc_ncm_setup(struct usbnet *dev) 68static int cdc_ncm_setup(struct usbnet *dev)
69{ 69{
70 struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; 70 struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0];
71 struct usb_cdc_ncm_ntb_parameters ncm_parm;
72 u32 val; 71 u32 val;
73 u8 flags; 72 u8 flags;
74 u8 iface_no; 73 u8 iface_no;
@@ -82,22 +81,22 @@ static int cdc_ncm_setup(struct usbnet *dev)
82 err = usbnet_read_cmd(dev, USB_CDC_GET_NTB_PARAMETERS, 81 err = usbnet_read_cmd(dev, USB_CDC_GET_NTB_PARAMETERS,
83 USB_TYPE_CLASS | USB_DIR_IN 82 USB_TYPE_CLASS | USB_DIR_IN
84 |USB_RECIP_INTERFACE, 83 |USB_RECIP_INTERFACE,
85 0, iface_no, &ncm_parm, 84 0, iface_no, &ctx->ncm_parm,
86 sizeof(ncm_parm)); 85 sizeof(ctx->ncm_parm));
87 if (err < 0) { 86 if (err < 0) {
88 dev_err(&dev->intf->dev, "failed GET_NTB_PARAMETERS\n"); 87 dev_err(&dev->intf->dev, "failed GET_NTB_PARAMETERS\n");
89 return err; /* GET_NTB_PARAMETERS is required */ 88 return err; /* GET_NTB_PARAMETERS is required */
90 } 89 }
91 90
92 /* read correct set of parameters according to device mode */ 91 /* read correct set of parameters according to device mode */
93 ctx->rx_max = le32_to_cpu(ncm_parm.dwNtbInMaxSize); 92 ctx->rx_max = le32_to_cpu(ctx->ncm_parm.dwNtbInMaxSize);
94 ctx->tx_max = le32_to_cpu(ncm_parm.dwNtbOutMaxSize); 93 ctx->tx_max = le32_to_cpu(ctx->ncm_parm.dwNtbOutMaxSize);
95 ctx->tx_remainder = le16_to_cpu(ncm_parm.wNdpOutPayloadRemainder); 94 ctx->tx_remainder = le16_to_cpu(ctx->ncm_parm.wNdpOutPayloadRemainder);
96 ctx->tx_modulus = le16_to_cpu(ncm_parm.wNdpOutDivisor); 95 ctx->tx_modulus = le16_to_cpu(ctx->ncm_parm.wNdpOutDivisor);
97 ctx->tx_ndp_modulus = le16_to_cpu(ncm_parm.wNdpOutAlignment); 96 ctx->tx_ndp_modulus = le16_to_cpu(ctx->ncm_parm.wNdpOutAlignment);
98 /* devices prior to NCM Errata shall set this field to zero */ 97 /* devices prior to NCM Errata shall set this field to zero */
99 ctx->tx_max_datagrams = le16_to_cpu(ncm_parm.wNtbOutMaxDatagrams); 98 ctx->tx_max_datagrams = le16_to_cpu(ctx->ncm_parm.wNtbOutMaxDatagrams);
100 ntb_fmt_supported = le16_to_cpu(ncm_parm.bmNtbFormatsSupported); 99 ntb_fmt_supported = le16_to_cpu(ctx->ncm_parm.bmNtbFormatsSupported);
101 100
102 /* there are some minor differences in NCM and MBIM defaults */ 101 /* there are some minor differences in NCM and MBIM defaults */
103 if (cdc_ncm_comm_intf_is_mbim(ctx->control->cur_altsetting)) { 102 if (cdc_ncm_comm_intf_is_mbim(ctx->control->cur_altsetting)) {
@@ -146,7 +145,7 @@ static int cdc_ncm_setup(struct usbnet *dev)
146 } 145 }
147 146
148 /* inform device about NTB input size changes */ 147 /* inform device about NTB input size changes */
149 if (ctx->rx_max != le32_to_cpu(ncm_parm.dwNtbInMaxSize)) { 148 if (ctx->rx_max != le32_to_cpu(ctx->ncm_parm.dwNtbInMaxSize)) {
150 __le32 dwNtbInMaxSize = cpu_to_le32(ctx->rx_max); 149 __le32 dwNtbInMaxSize = cpu_to_le32(ctx->rx_max);
151 150
152 err = usbnet_write_cmd(dev, USB_CDC_SET_NTB_INPUT_SIZE, 151 err = usbnet_write_cmd(dev, USB_CDC_SET_NTB_INPUT_SIZE,
@@ -162,14 +161,6 @@ static int cdc_ncm_setup(struct usbnet *dev)
162 dev_dbg(&dev->intf->dev, "Using default maximum transmit length=%d\n", 161 dev_dbg(&dev->intf->dev, "Using default maximum transmit length=%d\n",
163 CDC_NCM_NTB_MAX_SIZE_TX); 162 CDC_NCM_NTB_MAX_SIZE_TX);
164 ctx->tx_max = CDC_NCM_NTB_MAX_SIZE_TX; 163 ctx->tx_max = CDC_NCM_NTB_MAX_SIZE_TX;
165
166 /* Adding a pad byte here simplifies the handling in
167 * cdc_ncm_fill_tx_frame, by making tx_max always
168 * represent the real skb max size.
169 */
170 if (ctx->tx_max % usb_maxpacket(dev->udev, dev->out, 1) == 0)
171 ctx->tx_max++;
172
173 } 164 }
174 165
175 /* 166 /*
@@ -439,6 +430,10 @@ advance:
439 goto error2; 430 goto error2;
440 } 431 }
441 432
433 /* initialize data interface */
434 if (cdc_ncm_setup(dev))
435 goto error2;
436
442 /* configure data interface */ 437 /* configure data interface */
443 temp = usb_set_interface(dev->udev, iface_no, data_altsetting); 438 temp = usb_set_interface(dev->udev, iface_no, data_altsetting);
444 if (temp) { 439 if (temp) {
@@ -453,12 +448,6 @@ advance:
453 goto error2; 448 goto error2;
454 } 449 }
455 450
456 /* initialize data interface */
457 if (cdc_ncm_setup(dev)) {
458 dev_dbg(&intf->dev, "cdc_ncm_setup() failed\n");
459 goto error2;
460 }
461
462 usb_set_intfdata(ctx->data, dev); 451 usb_set_intfdata(ctx->data, dev);
463 usb_set_intfdata(ctx->control, dev); 452 usb_set_intfdata(ctx->control, dev);
464 453
@@ -475,6 +464,15 @@ advance:
475 dev->hard_mtu = ctx->tx_max; 464 dev->hard_mtu = ctx->tx_max;
476 dev->rx_urb_size = ctx->rx_max; 465 dev->rx_urb_size = ctx->rx_max;
477 466
467 /* cdc_ncm_setup will override dwNtbOutMaxSize if it is
468 * outside the sane range. Adding a pad byte here if necessary
469 * simplifies the handling in cdc_ncm_fill_tx_frame, making
470 * tx_max always represent the real skb max size.
471 */
472 if (ctx->tx_max != le32_to_cpu(ctx->ncm_parm.dwNtbOutMaxSize) &&
473 ctx->tx_max % usb_maxpacket(dev->udev, dev->out, 1) == 0)
474 ctx->tx_max++;
475
478 return 0; 476 return 0;
479 477
480error2: 478error2:
diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
index d89dbe395ad2..adb12f349a61 100644
--- a/drivers/net/usb/r8152.c
+++ b/drivers/net/usb/r8152.c
@@ -449,9 +449,6 @@ enum rtl8152_flags {
449#define MCU_TYPE_PLA 0x0100 449#define MCU_TYPE_PLA 0x0100
450#define MCU_TYPE_USB 0x0000 450#define MCU_TYPE_USB 0x0000
451 451
452#define REALTEK_USB_DEVICE(vend, prod) \
453 USB_DEVICE_INTERFACE_CLASS(vend, prod, USB_CLASS_VENDOR_SPEC)
454
455struct rx_desc { 452struct rx_desc {
456 __le32 opts1; 453 __le32 opts1;
457#define RX_LEN_MASK 0x7fff 454#define RX_LEN_MASK 0x7fff
@@ -2739,6 +2736,12 @@ static int rtl8152_probe(struct usb_interface *intf,
2739 struct net_device *netdev; 2736 struct net_device *netdev;
2740 int ret; 2737 int ret;
2741 2738
2739 if (udev->actconfig->desc.bConfigurationValue != 1) {
2740 usb_driver_set_configuration(udev, 1);
2741 return -ENODEV;
2742 }
2743
2744 usb_reset_device(udev);
2742 netdev = alloc_etherdev(sizeof(struct r8152)); 2745 netdev = alloc_etherdev(sizeof(struct r8152));
2743 if (!netdev) { 2746 if (!netdev) {
2744 dev_err(&intf->dev, "Out of memory\n"); 2747 dev_err(&intf->dev, "Out of memory\n");
@@ -2819,9 +2822,9 @@ static void rtl8152_disconnect(struct usb_interface *intf)
2819 2822
2820/* table of devices that work with this driver */ 2823/* table of devices that work with this driver */
2821static struct usb_device_id rtl8152_table[] = { 2824static struct usb_device_id rtl8152_table[] = {
2822 {REALTEK_USB_DEVICE(VENDOR_ID_REALTEK, PRODUCT_ID_RTL8152)}, 2825 {USB_DEVICE(VENDOR_ID_REALTEK, PRODUCT_ID_RTL8152)},
2823 {REALTEK_USB_DEVICE(VENDOR_ID_REALTEK, PRODUCT_ID_RTL8153)}, 2826 {USB_DEVICE(VENDOR_ID_REALTEK, PRODUCT_ID_RTL8153)},
2824 {REALTEK_USB_DEVICE(VENDOR_ID_SAMSUNG, PRODUCT_ID_SAMSUNG)}, 2827 {USB_DEVICE(VENDOR_ID_SAMSUNG, PRODUCT_ID_SAMSUNG)},
2825 {} 2828 {}
2826}; 2829};
2827 2830
diff --git a/drivers/net/usb/r815x.c b/drivers/net/usb/r815x.c
deleted file mode 100644
index f0a8791b7636..000000000000
--- a/drivers/net/usb/r815x.c
+++ /dev/null
@@ -1,248 +0,0 @@
1#include <linux/module.h>
2#include <linux/netdevice.h>
3#include <linux/mii.h>
4#include <linux/usb.h>
5#include <linux/usb/cdc.h>
6#include <linux/usb/usbnet.h>
7
8#define RTL815x_REQT_READ 0xc0
9#define RTL815x_REQT_WRITE 0x40
10#define RTL815x_REQ_GET_REGS 0x05
11#define RTL815x_REQ_SET_REGS 0x05
12
13#define MCU_TYPE_PLA 0x0100
14#define OCP_BASE 0xe86c
15#define BASE_MII 0xa400
16
17#define BYTE_EN_DWORD 0xff
18#define BYTE_EN_WORD 0x33
19#define BYTE_EN_BYTE 0x11
20
21#define R815x_PHY_ID 32
22#define REALTEK_VENDOR_ID 0x0bda
23
24
25static int pla_read_word(struct usb_device *udev, u16 index)
26{
27 int ret;
28 u8 shift = index & 2;
29 __le32 *tmp;
30
31 tmp = kmalloc(sizeof(*tmp), GFP_KERNEL);
32 if (!tmp)
33 return -ENOMEM;
34
35 index &= ~3;
36
37 ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
38 RTL815x_REQ_GET_REGS, RTL815x_REQT_READ,
39 index, MCU_TYPE_PLA, tmp, sizeof(*tmp), 500);
40 if (ret < 0)
41 goto out2;
42
43 ret = __le32_to_cpu(*tmp);
44 ret >>= (shift * 8);
45 ret &= 0xffff;
46
47out2:
48 kfree(tmp);
49 return ret;
50}
51
52static int pla_write_word(struct usb_device *udev, u16 index, u32 data)
53{
54 __le32 *tmp;
55 u32 mask = 0xffff;
56 u16 byen = BYTE_EN_WORD;
57 u8 shift = index & 2;
58 int ret;
59
60 tmp = kmalloc(sizeof(*tmp), GFP_KERNEL);
61 if (!tmp)
62 return -ENOMEM;
63
64 data &= mask;
65
66 if (shift) {
67 byen <<= shift;
68 mask <<= (shift * 8);
69 data <<= (shift * 8);
70 index &= ~3;
71 }
72
73 ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
74 RTL815x_REQ_GET_REGS, RTL815x_REQT_READ,
75 index, MCU_TYPE_PLA, tmp, sizeof(*tmp), 500);
76 if (ret < 0)
77 goto out3;
78
79 data |= __le32_to_cpu(*tmp) & ~mask;
80 *tmp = __cpu_to_le32(data);
81
82 ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
83 RTL815x_REQ_SET_REGS, RTL815x_REQT_WRITE,
84 index, MCU_TYPE_PLA | byen, tmp, sizeof(*tmp),
85 500);
86
87out3:
88 kfree(tmp);
89 return ret;
90}
91
92static int ocp_reg_read(struct usbnet *dev, u16 addr)
93{
94 u16 ocp_base, ocp_index;
95 int ret;
96
97 ocp_base = addr & 0xf000;
98 ret = pla_write_word(dev->udev, OCP_BASE, ocp_base);
99 if (ret < 0)
100 goto out;
101
102 ocp_index = (addr & 0x0fff) | 0xb000;
103 ret = pla_read_word(dev->udev, ocp_index);
104
105out:
106 return ret;
107}
108
109static int ocp_reg_write(struct usbnet *dev, u16 addr, u16 data)
110{
111 u16 ocp_base, ocp_index;
112 int ret;
113
114 ocp_base = addr & 0xf000;
115 ret = pla_write_word(dev->udev, OCP_BASE, ocp_base);
116 if (ret < 0)
117 goto out1;
118
119 ocp_index = (addr & 0x0fff) | 0xb000;
120 ret = pla_write_word(dev->udev, ocp_index, data);
121
122out1:
123 return ret;
124}
125
126static int r815x_mdio_read(struct net_device *netdev, int phy_id, int reg)
127{
128 struct usbnet *dev = netdev_priv(netdev);
129 int ret;
130
131 if (phy_id != R815x_PHY_ID)
132 return -EINVAL;
133
134 if (usb_autopm_get_interface(dev->intf) < 0)
135 return -ENODEV;
136
137 ret = ocp_reg_read(dev, BASE_MII + reg * 2);
138
139 usb_autopm_put_interface(dev->intf);
140 return ret;
141}
142
143static
144void r815x_mdio_write(struct net_device *netdev, int phy_id, int reg, int val)
145{
146 struct usbnet *dev = netdev_priv(netdev);
147
148 if (phy_id != R815x_PHY_ID)
149 return;
150
151 if (usb_autopm_get_interface(dev->intf) < 0)
152 return;
153
154 ocp_reg_write(dev, BASE_MII + reg * 2, val);
155
156 usb_autopm_put_interface(dev->intf);
157}
158
159static int r8153_bind(struct usbnet *dev, struct usb_interface *intf)
160{
161 int status;
162
163 status = usbnet_cdc_bind(dev, intf);
164 if (status < 0)
165 return status;
166
167 dev->mii.dev = dev->net;
168 dev->mii.mdio_read = r815x_mdio_read;
169 dev->mii.mdio_write = r815x_mdio_write;
170 dev->mii.phy_id_mask = 0x3f;
171 dev->mii.reg_num_mask = 0x1f;
172 dev->mii.phy_id = R815x_PHY_ID;
173 dev->mii.supports_gmii = 1;
174
175 return status;
176}
177
178static int r8152_bind(struct usbnet *dev, struct usb_interface *intf)
179{
180 int status;
181
182 status = usbnet_cdc_bind(dev, intf);
183 if (status < 0)
184 return status;
185
186 dev->mii.dev = dev->net;
187 dev->mii.mdio_read = r815x_mdio_read;
188 dev->mii.mdio_write = r815x_mdio_write;
189 dev->mii.phy_id_mask = 0x3f;
190 dev->mii.reg_num_mask = 0x1f;
191 dev->mii.phy_id = R815x_PHY_ID;
192 dev->mii.supports_gmii = 0;
193
194 return status;
195}
196
197static const struct driver_info r8152_info = {
198 .description = "RTL8152 ECM Device",
199 .flags = FLAG_ETHER | FLAG_POINTTOPOINT,
200 .bind = r8152_bind,
201 .unbind = usbnet_cdc_unbind,
202 .status = usbnet_cdc_status,
203 .manage_power = usbnet_manage_power,
204};
205
206static const struct driver_info r8153_info = {
207 .description = "RTL8153 ECM Device",
208 .flags = FLAG_ETHER | FLAG_POINTTOPOINT,
209 .bind = r8153_bind,
210 .unbind = usbnet_cdc_unbind,
211 .status = usbnet_cdc_status,
212 .manage_power = usbnet_manage_power,
213};
214
215static const struct usb_device_id products[] = {
216{
217 USB_DEVICE_AND_INTERFACE_INFO(REALTEK_VENDOR_ID, 0x8152, USB_CLASS_COMM,
218 USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
219 .driver_info = (unsigned long) &r8152_info,
220},
221
222{
223 USB_DEVICE_AND_INTERFACE_INFO(REALTEK_VENDOR_ID, 0x8153, USB_CLASS_COMM,
224 USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
225 .driver_info = (unsigned long) &r8153_info,
226},
227
228 { }, /* END */
229};
230MODULE_DEVICE_TABLE(usb, products);
231
232static struct usb_driver r815x_driver = {
233 .name = "r815x",
234 .id_table = products,
235 .probe = usbnet_probe,
236 .disconnect = usbnet_disconnect,
237 .suspend = usbnet_suspend,
238 .resume = usbnet_resume,
239 .reset_resume = usbnet_resume,
240 .supports_autosuspend = 1,
241 .disable_hub_initiated_lpm = 1,
242};
243
244module_usb_driver(r815x_driver);
245
246MODULE_AUTHOR("Hayes Wang");
247MODULE_DESCRIPTION("Realtek USB ECM device");
248MODULE_LICENSE("GPL");
diff --git a/drivers/net/usb/usbnet.c b/drivers/net/usb/usbnet.c
index dd10d5817d2a..f9e96c427558 100644
--- a/drivers/net/usb/usbnet.c
+++ b/drivers/net/usb/usbnet.c
@@ -752,14 +752,12 @@ EXPORT_SYMBOL_GPL(usbnet_unlink_rx_urbs);
752// precondition: never called in_interrupt 752// precondition: never called in_interrupt
753static void usbnet_terminate_urbs(struct usbnet *dev) 753static void usbnet_terminate_urbs(struct usbnet *dev)
754{ 754{
755 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(unlink_wakeup);
756 DECLARE_WAITQUEUE(wait, current); 755 DECLARE_WAITQUEUE(wait, current);
757 int temp; 756 int temp;
758 757
759 /* ensure there are no more active urbs */ 758 /* ensure there are no more active urbs */
760 add_wait_queue(&unlink_wakeup, &wait); 759 add_wait_queue(&dev->wait, &wait);
761 set_current_state(TASK_UNINTERRUPTIBLE); 760 set_current_state(TASK_UNINTERRUPTIBLE);
762 dev->wait = &unlink_wakeup;
763 temp = unlink_urbs(dev, &dev->txq) + 761 temp = unlink_urbs(dev, &dev->txq) +
764 unlink_urbs(dev, &dev->rxq); 762 unlink_urbs(dev, &dev->rxq);
765 763
@@ -773,15 +771,14 @@ static void usbnet_terminate_urbs(struct usbnet *dev)
773 "waited for %d urb completions\n", temp); 771 "waited for %d urb completions\n", temp);
774 } 772 }
775 set_current_state(TASK_RUNNING); 773 set_current_state(TASK_RUNNING);
776 dev->wait = NULL; 774 remove_wait_queue(&dev->wait, &wait);
777 remove_wait_queue(&unlink_wakeup, &wait);
778} 775}
779 776
780int usbnet_stop (struct net_device *net) 777int usbnet_stop (struct net_device *net)
781{ 778{
782 struct usbnet *dev = netdev_priv(net); 779 struct usbnet *dev = netdev_priv(net);
783 struct driver_info *info = dev->driver_info; 780 struct driver_info *info = dev->driver_info;
784 int retval; 781 int retval, pm;
785 782
786 clear_bit(EVENT_DEV_OPEN, &dev->flags); 783 clear_bit(EVENT_DEV_OPEN, &dev->flags);
787 netif_stop_queue (net); 784 netif_stop_queue (net);
@@ -791,6 +788,8 @@ int usbnet_stop (struct net_device *net)
791 net->stats.rx_packets, net->stats.tx_packets, 788 net->stats.rx_packets, net->stats.tx_packets,
792 net->stats.rx_errors, net->stats.tx_errors); 789 net->stats.rx_errors, net->stats.tx_errors);
793 790
791 /* to not race resume */
792 pm = usb_autopm_get_interface(dev->intf);
794 /* allow minidriver to stop correctly (wireless devices to turn off 793 /* allow minidriver to stop correctly (wireless devices to turn off
795 * radio etc) */ 794 * radio etc) */
796 if (info->stop) { 795 if (info->stop) {
@@ -817,6 +816,9 @@ int usbnet_stop (struct net_device *net)
817 dev->flags = 0; 816 dev->flags = 0;
818 del_timer_sync (&dev->delay); 817 del_timer_sync (&dev->delay);
819 tasklet_kill (&dev->bh); 818 tasklet_kill (&dev->bh);
819 if (!pm)
820 usb_autopm_put_interface(dev->intf);
821
820 if (info->manage_power && 822 if (info->manage_power &&
821 !test_and_clear_bit(EVENT_NO_RUNTIME_PM, &dev->flags)) 823 !test_and_clear_bit(EVENT_NO_RUNTIME_PM, &dev->flags))
822 info->manage_power(dev, 0); 824 info->manage_power(dev, 0);
@@ -1437,11 +1439,12 @@ static void usbnet_bh (unsigned long param)
1437 /* restart RX again after disabling due to high error rate */ 1439 /* restart RX again after disabling due to high error rate */
1438 clear_bit(EVENT_RX_KILL, &dev->flags); 1440 clear_bit(EVENT_RX_KILL, &dev->flags);
1439 1441
1440 // waiting for all pending urbs to complete? 1442 /* waiting for all pending urbs to complete?
1441 if (dev->wait) { 1443 * only then can we forgo submitting anew
1442 if ((dev->txq.qlen + dev->rxq.qlen + dev->done.qlen) == 0) { 1444 */
1443 wake_up (dev->wait); 1445 if (waitqueue_active(&dev->wait)) {
1444 } 1446 if (dev->txq.qlen + dev->rxq.qlen + dev->done.qlen == 0)
1447 wake_up_all(&dev->wait);
1445 1448
1446 // or are we maybe short a few urbs? 1449 // or are we maybe short a few urbs?
1447 } else if (netif_running (dev->net) && 1450 } else if (netif_running (dev->net) &&
@@ -1580,6 +1583,7 @@ usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod)
1580 dev->driver_name = name; 1583 dev->driver_name = name;
1581 dev->msg_enable = netif_msg_init (msg_level, NETIF_MSG_DRV 1584 dev->msg_enable = netif_msg_init (msg_level, NETIF_MSG_DRV
1582 | NETIF_MSG_PROBE | NETIF_MSG_LINK); 1585 | NETIF_MSG_PROBE | NETIF_MSG_LINK);
1586 init_waitqueue_head(&dev->wait);
1583 skb_queue_head_init (&dev->rxq); 1587 skb_queue_head_init (&dev->rxq);
1584 skb_queue_head_init (&dev->txq); 1588 skb_queue_head_init (&dev->txq);
1585 skb_queue_head_init (&dev->done); 1589 skb_queue_head_init (&dev->done);
@@ -1791,9 +1795,10 @@ int usbnet_resume (struct usb_interface *intf)
1791 spin_unlock_irq(&dev->txq.lock); 1795 spin_unlock_irq(&dev->txq.lock);
1792 1796
1793 if (test_bit(EVENT_DEV_OPEN, &dev->flags)) { 1797 if (test_bit(EVENT_DEV_OPEN, &dev->flags)) {
1794 /* handle remote wakeup ASAP */ 1798 /* handle remote wakeup ASAP
1795 if (!dev->wait && 1799 * we cannot race against stop
1796 netif_device_present(dev->net) && 1800 */
1801 if (netif_device_present(dev->net) &&
1797 !timer_pending(&dev->delay) && 1802 !timer_pending(&dev->delay) &&
1798 !test_bit(EVENT_RX_HALT, &dev->flags)) 1803 !test_bit(EVENT_RX_HALT, &dev->flags))
1799 rx_alloc_submit(dev, GFP_NOIO); 1804 rx_alloc_submit(dev, GFP_NOIO);
diff --git a/drivers/net/veth.c b/drivers/net/veth.c
index 2ec2041b62d4..c0e7c64765ab 100644
--- a/drivers/net/veth.c
+++ b/drivers/net/veth.c
@@ -285,7 +285,11 @@ static void veth_setup(struct net_device *dev)
285 dev->ethtool_ops = &veth_ethtool_ops; 285 dev->ethtool_ops = &veth_ethtool_ops;
286 dev->features |= NETIF_F_LLTX; 286 dev->features |= NETIF_F_LLTX;
287 dev->features |= VETH_FEATURES; 287 dev->features |= VETH_FEATURES;
288 dev->vlan_features = dev->features; 288 dev->vlan_features = dev->features &
289 ~(NETIF_F_HW_VLAN_CTAG_TX |
290 NETIF_F_HW_VLAN_STAG_TX |
291 NETIF_F_HW_VLAN_CTAG_RX |
292 NETIF_F_HW_VLAN_STAG_RX);
289 dev->destructor = veth_dev_free; 293 dev->destructor = veth_dev_free;
290 294
291 dev->hw_features = VETH_FEATURES; 295 dev->hw_features = VETH_FEATURES;
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index d75f8edf4fb3..841b60831df1 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -671,8 +671,7 @@ static bool try_fill_recv(struct receive_queue *rq, gfp_t gfp)
671 if (err) 671 if (err)
672 break; 672 break;
673 } while (rq->vq->num_free); 673 } while (rq->vq->num_free);
674 if (unlikely(!virtqueue_kick(rq->vq))) 674 virtqueue_kick(rq->vq);
675 return false;
676 return !oom; 675 return !oom;
677} 676}
678 677
@@ -877,7 +876,7 @@ static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev)
877 err = xmit_skb(sq, skb); 876 err = xmit_skb(sq, skb);
878 877
879 /* This should not happen! */ 878 /* This should not happen! */
880 if (unlikely(err) || unlikely(!virtqueue_kick(sq->vq))) { 879 if (unlikely(err)) {
881 dev->stats.tx_fifo_errors++; 880 dev->stats.tx_fifo_errors++;
882 if (net_ratelimit()) 881 if (net_ratelimit())
883 dev_warn(&dev->dev, 882 dev_warn(&dev->dev,
@@ -886,6 +885,7 @@ static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev)
886 kfree_skb(skb); 885 kfree_skb(skb);
887 return NETDEV_TX_OK; 886 return NETDEV_TX_OK;
888 } 887 }
888 virtqueue_kick(sq->vq);
889 889
890 /* Don't wait up for transmitted skbs to be freed. */ 890 /* Don't wait up for transmitted skbs to be freed. */
891 skb_orphan(skb); 891 skb_orphan(skb);
@@ -1711,7 +1711,8 @@ static int virtnet_probe(struct virtio_device *vdev)
1711 /* If we can receive ANY GSO packets, we must allocate large ones. */ 1711 /* If we can receive ANY GSO packets, we must allocate large ones. */
1712 if (virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_TSO4) || 1712 if (virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_TSO4) ||
1713 virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_TSO6) || 1713 virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_TSO6) ||
1714 virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_ECN)) 1714 virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_ECN) ||
1715 virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_UFO))
1715 vi->big_packets = true; 1716 vi->big_packets = true;
1716 1717
1717 if (virtio_has_feature(vdev, VIRTIO_NET_F_MRG_RXBUF)) 1718 if (virtio_has_feature(vdev, VIRTIO_NET_F_MRG_RXBUF))
diff --git a/drivers/net/vmxnet3/vmxnet3_drv.c b/drivers/net/vmxnet3/vmxnet3_drv.c
index 3be786faaaec..0fa3b44f7342 100644
--- a/drivers/net/vmxnet3/vmxnet3_drv.c
+++ b/drivers/net/vmxnet3/vmxnet3_drv.c
@@ -1762,11 +1762,20 @@ vmxnet3_netpoll(struct net_device *netdev)
1762{ 1762{
1763 struct vmxnet3_adapter *adapter = netdev_priv(netdev); 1763 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
1764 1764
1765 if (adapter->intr.mask_mode == VMXNET3_IMM_ACTIVE) 1765 switch (adapter->intr.type) {
1766 vmxnet3_disable_all_intrs(adapter); 1766#ifdef CONFIG_PCI_MSI
1767 1767 case VMXNET3_IT_MSIX: {
1768 vmxnet3_do_poll(adapter, adapter->rx_queue[0].rx_ring[0].size); 1768 int i;
1769 vmxnet3_enable_all_intrs(adapter); 1769 for (i = 0; i < adapter->num_rx_queues; i++)
1770 vmxnet3_msix_rx(0, &adapter->rx_queue[i]);
1771 break;
1772 }
1773#endif
1774 case VMXNET3_IT_MSI:
1775 default:
1776 vmxnet3_intr(0, adapter->netdev);
1777 break;
1778 }
1770 1779
1771} 1780}
1772#endif /* CONFIG_NET_POLL_CONTROLLER */ 1781#endif /* CONFIG_NET_POLL_CONTROLLER */
diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
index b0f705c2378f..1236812c7be6 100644
--- a/drivers/net/vxlan.c
+++ b/drivers/net/vxlan.c
@@ -1318,6 +1318,9 @@ static int arp_reduce(struct net_device *dev, struct sk_buff *skb)
1318 1318
1319 neigh_release(n); 1319 neigh_release(n);
1320 1320
1321 if (reply == NULL)
1322 goto out;
1323
1321 skb_reset_mac_header(reply); 1324 skb_reset_mac_header(reply);
1322 __skb_pull(reply, skb_network_offset(reply)); 1325 __skb_pull(reply, skb_network_offset(reply));
1323 reply->ip_summed = CHECKSUM_UNNECESSARY; 1326 reply->ip_summed = CHECKSUM_UNNECESSARY;
@@ -1339,15 +1342,103 @@ out:
1339} 1342}
1340 1343
1341#if IS_ENABLED(CONFIG_IPV6) 1344#if IS_ENABLED(CONFIG_IPV6)
1345
1346static struct sk_buff *vxlan_na_create(struct sk_buff *request,
1347 struct neighbour *n, bool isrouter)
1348{
1349 struct net_device *dev = request->dev;
1350 struct sk_buff *reply;
1351 struct nd_msg *ns, *na;
1352 struct ipv6hdr *pip6;
1353 u8 *daddr;
1354 int na_olen = 8; /* opt hdr + ETH_ALEN for target */
1355 int ns_olen;
1356 int i, len;
1357
1358 if (dev == NULL)
1359 return NULL;
1360
1361 len = LL_RESERVED_SPACE(dev) + sizeof(struct ipv6hdr) +
1362 sizeof(*na) + na_olen + dev->needed_tailroom;
1363 reply = alloc_skb(len, GFP_ATOMIC);
1364 if (reply == NULL)
1365 return NULL;
1366
1367 reply->protocol = htons(ETH_P_IPV6);
1368 reply->dev = dev;
1369 skb_reserve(reply, LL_RESERVED_SPACE(request->dev));
1370 skb_push(reply, sizeof(struct ethhdr));
1371 skb_set_mac_header(reply, 0);
1372
1373 ns = (struct nd_msg *)skb_transport_header(request);
1374
1375 daddr = eth_hdr(request)->h_source;
1376 ns_olen = request->len - skb_transport_offset(request) - sizeof(*ns);
1377 for (i = 0; i < ns_olen-1; i += (ns->opt[i+1]<<3)) {
1378 if (ns->opt[i] == ND_OPT_SOURCE_LL_ADDR) {
1379 daddr = ns->opt + i + sizeof(struct nd_opt_hdr);
1380 break;
1381 }
1382 }
1383
1384 /* Ethernet header */
1385 ether_addr_copy(eth_hdr(reply)->h_dest, daddr);
1386 ether_addr_copy(eth_hdr(reply)->h_source, n->ha);
1387 eth_hdr(reply)->h_proto = htons(ETH_P_IPV6);
1388 reply->protocol = htons(ETH_P_IPV6);
1389
1390 skb_pull(reply, sizeof(struct ethhdr));
1391 skb_set_network_header(reply, 0);
1392 skb_put(reply, sizeof(struct ipv6hdr));
1393
1394 /* IPv6 header */
1395
1396 pip6 = ipv6_hdr(reply);
1397 memset(pip6, 0, sizeof(struct ipv6hdr));
1398 pip6->version = 6;
1399 pip6->priority = ipv6_hdr(request)->priority;
1400 pip6->nexthdr = IPPROTO_ICMPV6;
1401 pip6->hop_limit = 255;
1402 pip6->daddr = ipv6_hdr(request)->saddr;
1403 pip6->saddr = *(struct in6_addr *)n->primary_key;
1404
1405 skb_pull(reply, sizeof(struct ipv6hdr));
1406 skb_set_transport_header(reply, 0);
1407
1408 na = (struct nd_msg *)skb_put(reply, sizeof(*na) + na_olen);
1409
1410 /* Neighbor Advertisement */
1411 memset(na, 0, sizeof(*na)+na_olen);
1412 na->icmph.icmp6_type = NDISC_NEIGHBOUR_ADVERTISEMENT;
1413 na->icmph.icmp6_router = isrouter;
1414 na->icmph.icmp6_override = 1;
1415 na->icmph.icmp6_solicited = 1;
1416 na->target = ns->target;
1417 ether_addr_copy(&na->opt[2], n->ha);
1418 na->opt[0] = ND_OPT_TARGET_LL_ADDR;
1419 na->opt[1] = na_olen >> 3;
1420
1421 na->icmph.icmp6_cksum = csum_ipv6_magic(&pip6->saddr,
1422 &pip6->daddr, sizeof(*na)+na_olen, IPPROTO_ICMPV6,
1423 csum_partial(na, sizeof(*na)+na_olen, 0));
1424
1425 pip6->payload_len = htons(sizeof(*na)+na_olen);
1426
1427 skb_push(reply, sizeof(struct ipv6hdr));
1428
1429 reply->ip_summed = CHECKSUM_UNNECESSARY;
1430
1431 return reply;
1432}
1433
1342static int neigh_reduce(struct net_device *dev, struct sk_buff *skb) 1434static int neigh_reduce(struct net_device *dev, struct sk_buff *skb)
1343{ 1435{
1344 struct vxlan_dev *vxlan = netdev_priv(dev); 1436 struct vxlan_dev *vxlan = netdev_priv(dev);
1345 struct neighbour *n; 1437 struct nd_msg *msg;
1346 union vxlan_addr ipa;
1347 const struct ipv6hdr *iphdr; 1438 const struct ipv6hdr *iphdr;
1348 const struct in6_addr *saddr, *daddr; 1439 const struct in6_addr *saddr, *daddr;
1349 struct nd_msg *msg; 1440 struct neighbour *n;
1350 struct inet6_dev *in6_dev = NULL; 1441 struct inet6_dev *in6_dev;
1351 1442
1352 in6_dev = __in6_dev_get(dev); 1443 in6_dev = __in6_dev_get(dev);
1353 if (!in6_dev) 1444 if (!in6_dev)
@@ -1360,19 +1451,20 @@ static int neigh_reduce(struct net_device *dev, struct sk_buff *skb)
1360 saddr = &iphdr->saddr; 1451 saddr = &iphdr->saddr;
1361 daddr = &iphdr->daddr; 1452 daddr = &iphdr->daddr;
1362 1453
1363 if (ipv6_addr_loopback(daddr) ||
1364 ipv6_addr_is_multicast(daddr))
1365 goto out;
1366
1367 msg = (struct nd_msg *)skb_transport_header(skb); 1454 msg = (struct nd_msg *)skb_transport_header(skb);
1368 if (msg->icmph.icmp6_code != 0 || 1455 if (msg->icmph.icmp6_code != 0 ||
1369 msg->icmph.icmp6_type != NDISC_NEIGHBOUR_SOLICITATION) 1456 msg->icmph.icmp6_type != NDISC_NEIGHBOUR_SOLICITATION)
1370 goto out; 1457 goto out;
1371 1458
1372 n = neigh_lookup(ipv6_stub->nd_tbl, daddr, dev); 1459 if (ipv6_addr_loopback(daddr) ||
1460 ipv6_addr_is_multicast(&msg->target))
1461 goto out;
1462
1463 n = neigh_lookup(ipv6_stub->nd_tbl, &msg->target, dev);
1373 1464
1374 if (n) { 1465 if (n) {
1375 struct vxlan_fdb *f; 1466 struct vxlan_fdb *f;
1467 struct sk_buff *reply;
1376 1468
1377 if (!(n->nud_state & NUD_CONNECTED)) { 1469 if (!(n->nud_state & NUD_CONNECTED)) {
1378 neigh_release(n); 1470 neigh_release(n);
@@ -1386,13 +1478,23 @@ static int neigh_reduce(struct net_device *dev, struct sk_buff *skb)
1386 goto out; 1478 goto out;
1387 } 1479 }
1388 1480
1389 ipv6_stub->ndisc_send_na(dev, n, saddr, &msg->target, 1481 reply = vxlan_na_create(skb, n,
1390 !!in6_dev->cnf.forwarding, 1482 !!(f ? f->flags & NTF_ROUTER : 0));
1391 true, false, false); 1483
1392 neigh_release(n); 1484 neigh_release(n);
1485
1486 if (reply == NULL)
1487 goto out;
1488
1489 if (netif_rx_ni(reply) == NET_RX_DROP)
1490 dev->stats.rx_dropped++;
1491
1393 } else if (vxlan->flags & VXLAN_F_L3MISS) { 1492 } else if (vxlan->flags & VXLAN_F_L3MISS) {
1394 ipa.sin6.sin6_addr = *daddr; 1493 union vxlan_addr ipa = {
1395 ipa.sa.sa_family = AF_INET6; 1494 .sin6.sin6_addr = msg->target,
1495 .sa.sa_family = AF_INET6,
1496 };
1497
1396 vxlan_ip_miss(dev, &ipa); 1498 vxlan_ip_miss(dev, &ipa);
1397 } 1499 }
1398 1500
diff --git a/drivers/net/wireless/ath/ath9k/ar9462_2p0_initvals.h b/drivers/net/wireless/ath/ath9k/ar9462_2p0_initvals.h
index 1cc13569b17b..1b6b4d0cfa97 100644
--- a/drivers/net/wireless/ath/ath9k/ar9462_2p0_initvals.h
+++ b/drivers/net/wireless/ath/ath9k/ar9462_2p0_initvals.h
@@ -57,7 +57,7 @@ static const u32 ar9462_2p0_baseband_postamble[][5] = {
57 {0x00009e14, 0x37b95d5e, 0x37b9605e, 0x3236605e, 0x32365a5e}, 57 {0x00009e14, 0x37b95d5e, 0x37b9605e, 0x3236605e, 0x32365a5e},
58 {0x00009e18, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, 58 {0x00009e18, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
59 {0x00009e1c, 0x0001cf9c, 0x0001cf9c, 0x00021f9c, 0x00021f9c}, 59 {0x00009e1c, 0x0001cf9c, 0x0001cf9c, 0x00021f9c, 0x00021f9c},
60 {0x00009e20, 0x000003b5, 0x000003b5, 0x000003ce, 0x000003ce}, 60 {0x00009e20, 0x000003a5, 0x000003a5, 0x000003a5, 0x000003a5},
61 {0x00009e2c, 0x0000001c, 0x0000001c, 0x00000021, 0x00000021}, 61 {0x00009e2c, 0x0000001c, 0x0000001c, 0x00000021, 0x00000021},
62 {0x00009e3c, 0xcf946220, 0xcf946220, 0xcfd5c782, 0xcfd5c282}, 62 {0x00009e3c, 0xcf946220, 0xcf946220, 0xcfd5c782, 0xcfd5c282},
63 {0x00009e44, 0x62321e27, 0x62321e27, 0xfe291e27, 0xfe291e27}, 63 {0x00009e44, 0x62321e27, 0x62321e27, 0xfe291e27, 0xfe291e27},
@@ -96,7 +96,7 @@ static const u32 ar9462_2p0_baseband_postamble[][5] = {
96 {0x0000ae04, 0x001c0000, 0x001c0000, 0x001c0000, 0x00100000}, 96 {0x0000ae04, 0x001c0000, 0x001c0000, 0x001c0000, 0x00100000},
97 {0x0000ae18, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, 97 {0x0000ae18, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
98 {0x0000ae1c, 0x0000019c, 0x0000019c, 0x0000019c, 0x0000019c}, 98 {0x0000ae1c, 0x0000019c, 0x0000019c, 0x0000019c, 0x0000019c},
99 {0x0000ae20, 0x000001b5, 0x000001b5, 0x000001ce, 0x000001ce}, 99 {0x0000ae20, 0x000001a6, 0x000001a6, 0x000001aa, 0x000001aa},
100 {0x0000b284, 0x00000000, 0x00000000, 0x00000550, 0x00000550}, 100 {0x0000b284, 0x00000000, 0x00000000, 0x00000550, 0x00000550},
101}; 101};
102 102
diff --git a/drivers/net/wireless/ath/ath9k/hw.c b/drivers/net/wireless/ath/ath9k/hw.c
index 11eab9f01fd8..9078a6c5a74e 100644
--- a/drivers/net/wireless/ath/ath9k/hw.c
+++ b/drivers/net/wireless/ath/ath9k/hw.c
@@ -1534,7 +1534,7 @@ EXPORT_SYMBOL(ath9k_hw_check_nav);
1534bool ath9k_hw_check_alive(struct ath_hw *ah) 1534bool ath9k_hw_check_alive(struct ath_hw *ah)
1535{ 1535{
1536 int count = 50; 1536 int count = 50;
1537 u32 reg; 1537 u32 reg, last_val;
1538 1538
1539 if (AR_SREV_9300(ah)) 1539 if (AR_SREV_9300(ah))
1540 return !ath9k_hw_detect_mac_hang(ah); 1540 return !ath9k_hw_detect_mac_hang(ah);
@@ -1542,9 +1542,14 @@ bool ath9k_hw_check_alive(struct ath_hw *ah)
1542 if (AR_SREV_9285_12_OR_LATER(ah)) 1542 if (AR_SREV_9285_12_OR_LATER(ah))
1543 return true; 1543 return true;
1544 1544
1545 last_val = REG_READ(ah, AR_OBS_BUS_1);
1545 do { 1546 do {
1546 reg = REG_READ(ah, AR_OBS_BUS_1); 1547 reg = REG_READ(ah, AR_OBS_BUS_1);
1548 if (reg != last_val)
1549 return true;
1547 1550
1551 udelay(1);
1552 last_val = reg;
1548 if ((reg & 0x7E7FFFEF) == 0x00702400) 1553 if ((reg & 0x7E7FFFEF) == 0x00702400)
1549 continue; 1554 continue;
1550 1555
diff --git a/drivers/net/wireless/ath/ath9k/recv.c b/drivers/net/wireless/ath/ath9k/recv.c
index a0ebdd000fc2..82e340d3ec60 100644
--- a/drivers/net/wireless/ath/ath9k/recv.c
+++ b/drivers/net/wireless/ath/ath9k/recv.c
@@ -732,11 +732,18 @@ static struct ath_rxbuf *ath_get_next_rx_buf(struct ath_softc *sc,
732 return NULL; 732 return NULL;
733 733
734 /* 734 /*
735 * mark descriptor as zero-length and set the 'more' 735 * Re-check previous descriptor, in case it has been filled
736 * flag to ensure that both buffers get discarded 736 * in the mean time.
737 */ 737 */
738 rs->rs_datalen = 0; 738 ret = ath9k_hw_rxprocdesc(ah, ds, rs);
739 rs->rs_more = true; 739 if (ret == -EINPROGRESS) {
740 /*
741 * mark descriptor as zero-length and set the 'more'
742 * flag to ensure that both buffers get discarded
743 */
744 rs->rs_datalen = 0;
745 rs->rs_more = true;
746 }
740 } 747 }
741 748
742 list_del(&bf->list); 749 list_del(&bf->list);
@@ -985,32 +992,32 @@ static int ath9k_rx_skb_preprocess(struct ath_softc *sc,
985 struct ath_common *common = ath9k_hw_common(ah); 992 struct ath_common *common = ath9k_hw_common(ah);
986 struct ieee80211_hdr *hdr; 993 struct ieee80211_hdr *hdr;
987 bool discard_current = sc->rx.discard_next; 994 bool discard_current = sc->rx.discard_next;
988 int ret = 0;
989 995
990 /* 996 /*
991 * Discard corrupt descriptors which are marked in 997 * Discard corrupt descriptors which are marked in
992 * ath_get_next_rx_buf(). 998 * ath_get_next_rx_buf().
993 */ 999 */
994 sc->rx.discard_next = rx_stats->rs_more;
995 if (discard_current) 1000 if (discard_current)
996 return -EINVAL; 1001 goto corrupt;
1002
1003 sc->rx.discard_next = false;
997 1004
998 /* 1005 /*
999 * Discard zero-length packets. 1006 * Discard zero-length packets.
1000 */ 1007 */
1001 if (!rx_stats->rs_datalen) { 1008 if (!rx_stats->rs_datalen) {
1002 RX_STAT_INC(rx_len_err); 1009 RX_STAT_INC(rx_len_err);
1003 return -EINVAL; 1010 goto corrupt;
1004 } 1011 }
1005 1012
1006 /* 1013 /*
1007 * rs_status follows rs_datalen so if rs_datalen is too large 1014 * rs_status follows rs_datalen so if rs_datalen is too large
1008 * we can take a hint that hardware corrupted it, so ignore 1015 * we can take a hint that hardware corrupted it, so ignore
1009 * those frames. 1016 * those frames.
1010 */ 1017 */
1011 if (rx_stats->rs_datalen > (common->rx_bufsize - ah->caps.rx_status_len)) { 1018 if (rx_stats->rs_datalen > (common->rx_bufsize - ah->caps.rx_status_len)) {
1012 RX_STAT_INC(rx_len_err); 1019 RX_STAT_INC(rx_len_err);
1013 return -EINVAL; 1020 goto corrupt;
1014 } 1021 }
1015 1022
1016 /* Only use status info from the last fragment */ 1023 /* Only use status info from the last fragment */
@@ -1024,10 +1031,8 @@ static int ath9k_rx_skb_preprocess(struct ath_softc *sc,
1024 * This is different from the other corrupt descriptor 1031 * This is different from the other corrupt descriptor
1025 * condition handled above. 1032 * condition handled above.
1026 */ 1033 */
1027 if (rx_stats->rs_status & ATH9K_RXERR_CORRUPT_DESC) { 1034 if (rx_stats->rs_status & ATH9K_RXERR_CORRUPT_DESC)
1028 ret = -EINVAL; 1035 goto corrupt;
1029 goto exit;
1030 }
1031 1036
1032 hdr = (struct ieee80211_hdr *) (skb->data + ah->caps.rx_status_len); 1037 hdr = (struct ieee80211_hdr *) (skb->data + ah->caps.rx_status_len);
1033 1038
@@ -1043,18 +1048,15 @@ static int ath9k_rx_skb_preprocess(struct ath_softc *sc,
1043 if (ath_process_fft(sc, hdr, rx_stats, rx_status->mactime)) 1048 if (ath_process_fft(sc, hdr, rx_stats, rx_status->mactime))
1044 RX_STAT_INC(rx_spectral); 1049 RX_STAT_INC(rx_spectral);
1045 1050
1046 ret = -EINVAL; 1051 return -EINVAL;
1047 goto exit;
1048 } 1052 }
1049 1053
1050 /* 1054 /*
1051 * everything but the rate is checked here, the rate check is done 1055 * everything but the rate is checked here, the rate check is done
1052 * separately to avoid doing two lookups for a rate for each frame. 1056 * separately to avoid doing two lookups for a rate for each frame.
1053 */ 1057 */
1054 if (!ath9k_rx_accept(common, hdr, rx_status, rx_stats, decrypt_error)) { 1058 if (!ath9k_rx_accept(common, hdr, rx_status, rx_stats, decrypt_error))
1055 ret = -EINVAL; 1059 return -EINVAL;
1056 goto exit;
1057 }
1058 1060
1059 if (ath_is_mybeacon(common, hdr)) { 1061 if (ath_is_mybeacon(common, hdr)) {
1060 RX_STAT_INC(rx_beacons); 1062 RX_STAT_INC(rx_beacons);
@@ -1064,15 +1066,11 @@ static int ath9k_rx_skb_preprocess(struct ath_softc *sc,
1064 /* 1066 /*
1065 * This shouldn't happen, but have a safety check anyway. 1067 * This shouldn't happen, but have a safety check anyway.
1066 */ 1068 */
1067 if (WARN_ON(!ah->curchan)) { 1069 if (WARN_ON(!ah->curchan))
1068 ret = -EINVAL; 1070 return -EINVAL;
1069 goto exit;
1070 }
1071 1071
1072 if (ath9k_process_rate(common, hw, rx_stats, rx_status)) { 1072 if (ath9k_process_rate(common, hw, rx_stats, rx_status))
1073 ret =-EINVAL; 1073 return -EINVAL;
1074 goto exit;
1075 }
1076 1074
1077 ath9k_process_rssi(common, hw, rx_stats, rx_status); 1075 ath9k_process_rssi(common, hw, rx_stats, rx_status);
1078 1076
@@ -1087,9 +1085,11 @@ static int ath9k_rx_skb_preprocess(struct ath_softc *sc,
1087 sc->rx.num_pkts++; 1085 sc->rx.num_pkts++;
1088#endif 1086#endif
1089 1087
1090exit: 1088 return 0;
1091 sc->rx.discard_next = false; 1089
1092 return ret; 1090corrupt:
1091 sc->rx.discard_next = rx_stats->rs_more;
1092 return -EINVAL;
1093} 1093}
1094 1094
1095static void ath9k_rx_skb_postprocess(struct ath_common *common, 1095static void ath9k_rx_skb_postprocess(struct ath_common *common,
diff --git a/drivers/net/wireless/ath/ath9k/xmit.c b/drivers/net/wireless/ath/ath9k/xmit.c
index 0a75e2f68c9d..55897d508a76 100644
--- a/drivers/net/wireless/ath/ath9k/xmit.c
+++ b/drivers/net/wireless/ath/ath9k/xmit.c
@@ -1444,14 +1444,16 @@ void ath_tx_aggr_sleep(struct ieee80211_sta *sta, struct ath_softc *sc,
1444 for (tidno = 0, tid = &an->tid[tidno]; 1444 for (tidno = 0, tid = &an->tid[tidno];
1445 tidno < IEEE80211_NUM_TIDS; tidno++, tid++) { 1445 tidno < IEEE80211_NUM_TIDS; tidno++, tid++) {
1446 1446
1447 if (!tid->sched)
1448 continue;
1449
1450 ac = tid->ac; 1447 ac = tid->ac;
1451 txq = ac->txq; 1448 txq = ac->txq;
1452 1449
1453 ath_txq_lock(sc, txq); 1450 ath_txq_lock(sc, txq);
1454 1451
1452 if (!tid->sched) {
1453 ath_txq_unlock(sc, txq);
1454 continue;
1455 }
1456
1455 buffered = ath_tid_has_buffered(tid); 1457 buffered = ath_tid_has_buffered(tid);
1456 1458
1457 tid->sched = false; 1459 tid->sched = false;
@@ -2061,7 +2063,7 @@ static struct ath_buf *ath_tx_setup_buffer(struct ath_softc *sc,
2061 2063
2062 ATH_TXBUF_RESET(bf); 2064 ATH_TXBUF_RESET(bf);
2063 2065
2064 if (tid) { 2066 if (tid && ieee80211_is_data_present(hdr->frame_control)) {
2065 fragno = le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_FRAG; 2067 fragno = le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_FRAG;
2066 seqno = tid->seq_next; 2068 seqno = tid->seq_next;
2067 hdr->seq_ctrl = cpu_to_le16(tid->seq_next << IEEE80211_SEQ_SEQ_SHIFT); 2069 hdr->seq_ctrl = cpu_to_le16(tid->seq_next << IEEE80211_SEQ_SEQ_SHIFT);
@@ -2184,14 +2186,15 @@ int ath_tx_start(struct ieee80211_hw *hw, struct sk_buff *skb,
2184 txq->stopped = true; 2186 txq->stopped = true;
2185 } 2187 }
2186 2188
2189 if (txctl->an && ieee80211_is_data_present(hdr->frame_control))
2190 tid = ath_get_skb_tid(sc, txctl->an, skb);
2191
2187 if (info->flags & IEEE80211_TX_CTL_PS_RESPONSE) { 2192 if (info->flags & IEEE80211_TX_CTL_PS_RESPONSE) {
2188 ath_txq_unlock(sc, txq); 2193 ath_txq_unlock(sc, txq);
2189 txq = sc->tx.uapsdq; 2194 txq = sc->tx.uapsdq;
2190 ath_txq_lock(sc, txq); 2195 ath_txq_lock(sc, txq);
2191 } else if (txctl->an && 2196 } else if (txctl->an &&
2192 ieee80211_is_data_present(hdr->frame_control)) { 2197 ieee80211_is_data_present(hdr->frame_control)) {
2193 tid = ath_get_skb_tid(sc, txctl->an, skb);
2194
2195 WARN_ON(tid->ac->txq != txctl->txq); 2198 WARN_ON(tid->ac->txq != txctl->txq);
2196 2199
2197 if (info->flags & IEEE80211_TX_CTL_CLEAR_PS_FILT) 2200 if (info->flags & IEEE80211_TX_CTL_CLEAR_PS_FILT)
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/dhd_sdio.c b/drivers/net/wireless/brcm80211/brcmfmac/dhd_sdio.c
index 3e991897d7ca..ddaa9efd053d 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/dhd_sdio.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/dhd_sdio.c
@@ -457,7 +457,6 @@ struct brcmf_sdio {
457 457
458 u8 tx_hdrlen; /* sdio bus header length for tx packet */ 458 u8 tx_hdrlen; /* sdio bus header length for tx packet */
459 bool txglom; /* host tx glomming enable flag */ 459 bool txglom; /* host tx glomming enable flag */
460 struct sk_buff *txglom_sgpad; /* scatter-gather padding buffer */
461 u16 head_align; /* buffer pointer alignment */ 460 u16 head_align; /* buffer pointer alignment */
462 u16 sgentry_align; /* scatter-gather buffer alignment */ 461 u16 sgentry_align; /* scatter-gather buffer alignment */
463}; 462};
@@ -1944,19 +1943,21 @@ static int brcmf_sdio_txpkt_prep_sg(struct brcmf_sdio *bus,
1944 if (lastfrm && chain_pad) 1943 if (lastfrm && chain_pad)
1945 tail_pad += blksize - chain_pad; 1944 tail_pad += blksize - chain_pad;
1946 if (skb_tailroom(pkt) < tail_pad && pkt->len > blksize) { 1945 if (skb_tailroom(pkt) < tail_pad && pkt->len > blksize) {
1947 pkt_pad = bus->txglom_sgpad; 1946 pkt_pad = brcmu_pkt_buf_get_skb(tail_pad + tail_chop +
1948 if (pkt_pad == NULL) 1947 bus->head_align);
1949 brcmu_pkt_buf_get_skb(tail_pad + tail_chop);
1950 if (pkt_pad == NULL) 1948 if (pkt_pad == NULL)
1951 return -ENOMEM; 1949 return -ENOMEM;
1952 ret = brcmf_sdio_txpkt_hdalign(bus, pkt_pad); 1950 ret = brcmf_sdio_txpkt_hdalign(bus, pkt_pad);
1953 if (unlikely(ret < 0)) 1951 if (unlikely(ret < 0)) {
1952 kfree_skb(pkt_pad);
1954 return ret; 1953 return ret;
1954 }
1955 memcpy(pkt_pad->data, 1955 memcpy(pkt_pad->data,
1956 pkt->data + pkt->len - tail_chop, 1956 pkt->data + pkt->len - tail_chop,
1957 tail_chop); 1957 tail_chop);
1958 *(u32 *)(pkt_pad->cb) = ALIGN_SKB_FLAG + tail_chop; 1958 *(u32 *)(pkt_pad->cb) = ALIGN_SKB_FLAG + tail_chop;
1959 skb_trim(pkt, pkt->len - tail_chop); 1959 skb_trim(pkt, pkt->len - tail_chop);
1960 skb_trim(pkt_pad, tail_pad + tail_chop);
1960 __skb_queue_after(pktq, pkt, pkt_pad); 1961 __skb_queue_after(pktq, pkt, pkt_pad);
1961 } else { 1962 } else {
1962 ntail = pkt->data_len + tail_pad - 1963 ntail = pkt->data_len + tail_pad -
@@ -2011,7 +2012,7 @@ brcmf_sdio_txpkt_prep(struct brcmf_sdio *bus, struct sk_buff_head *pktq,
2011 return ret; 2012 return ret;
2012 head_pad = (u16)ret; 2013 head_pad = (u16)ret;
2013 if (head_pad) 2014 if (head_pad)
2014 memset(pkt_next->data, 0, head_pad + bus->tx_hdrlen); 2015 memset(pkt_next->data + bus->tx_hdrlen, 0, head_pad);
2015 2016
2016 total_len += pkt_next->len; 2017 total_len += pkt_next->len;
2017 2018
@@ -3486,10 +3487,6 @@ static int brcmf_sdio_bus_preinit(struct device *dev)
3486 bus->txglom = false; 3487 bus->txglom = false;
3487 value = 1; 3488 value = 1;
3488 pad_size = bus->sdiodev->func[2]->cur_blksize << 1; 3489 pad_size = bus->sdiodev->func[2]->cur_blksize << 1;
3489 bus->txglom_sgpad = brcmu_pkt_buf_get_skb(pad_size);
3490 if (!bus->txglom_sgpad)
3491 brcmf_err("allocating txglom padding skb failed, reduced performance\n");
3492
3493 err = brcmf_iovar_data_set(bus->sdiodev->dev, "bus:rxglom", 3490 err = brcmf_iovar_data_set(bus->sdiodev->dev, "bus:rxglom",
3494 &value, sizeof(u32)); 3491 &value, sizeof(u32));
3495 if (err < 0) { 3492 if (err < 0) {
@@ -4053,7 +4050,6 @@ void brcmf_sdio_remove(struct brcmf_sdio *bus)
4053 brcmf_sdio_chip_detach(&bus->ci); 4050 brcmf_sdio_chip_detach(&bus->ci);
4054 } 4051 }
4055 4052
4056 brcmu_pkt_buf_free_skb(bus->txglom_sgpad);
4057 kfree(bus->rxbuf); 4053 kfree(bus->rxbuf);
4058 kfree(bus->hdrbuf); 4054 kfree(bus->hdrbuf);
4059 kfree(bus); 4055 kfree(bus);
diff --git a/drivers/net/wireless/hostap/hostap_ap.c b/drivers/net/wireless/hostap/hostap_ap.c
index d36e252d2ccb..596525528f50 100644
--- a/drivers/net/wireless/hostap/hostap_ap.c
+++ b/drivers/net/wireless/hostap/hostap_ap.c
@@ -147,7 +147,7 @@ static void ap_free_sta(struct ap_data *ap, struct sta_info *sta)
147 147
148 if (!sta->ap && sta->u.sta.challenge) 148 if (!sta->ap && sta->u.sta.challenge)
149 kfree(sta->u.sta.challenge); 149 kfree(sta->u.sta.challenge);
150 del_timer(&sta->timer); 150 del_timer_sync(&sta->timer);
151#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */ 151#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
152 152
153 kfree(sta); 153 kfree(sta);
diff --git a/drivers/net/wireless/iwlwifi/dvm/sta.c b/drivers/net/wireless/iwlwifi/dvm/sta.c
index c0d070c5df5e..9cdd91cdf661 100644
--- a/drivers/net/wireless/iwlwifi/dvm/sta.c
+++ b/drivers/net/wireless/iwlwifi/dvm/sta.c
@@ -590,6 +590,7 @@ void iwl_deactivate_station(struct iwl_priv *priv, const u8 sta_id,
590 sizeof(priv->tid_data[sta_id][tid])); 590 sizeof(priv->tid_data[sta_id][tid]));
591 591
592 priv->stations[sta_id].used &= ~IWL_STA_DRIVER_ACTIVE; 592 priv->stations[sta_id].used &= ~IWL_STA_DRIVER_ACTIVE;
593 priv->stations[sta_id].used &= ~IWL_STA_UCODE_INPROGRESS;
593 594
594 priv->num_stations--; 595 priv->num_stations--;
595 596
diff --git a/drivers/net/wireless/iwlwifi/dvm/tx.c b/drivers/net/wireless/iwlwifi/dvm/tx.c
index a6839dfcb82d..398dd096674c 100644
--- a/drivers/net/wireless/iwlwifi/dvm/tx.c
+++ b/drivers/net/wireless/iwlwifi/dvm/tx.c
@@ -1291,8 +1291,6 @@ int iwlagn_rx_reply_compressed_ba(struct iwl_priv *priv,
1291 struct iwl_compressed_ba_resp *ba_resp = (void *)pkt->data; 1291 struct iwl_compressed_ba_resp *ba_resp = (void *)pkt->data;
1292 struct iwl_ht_agg *agg; 1292 struct iwl_ht_agg *agg;
1293 struct sk_buff_head reclaimed_skbs; 1293 struct sk_buff_head reclaimed_skbs;
1294 struct ieee80211_tx_info *info;
1295 struct ieee80211_hdr *hdr;
1296 struct sk_buff *skb; 1294 struct sk_buff *skb;
1297 int sta_id; 1295 int sta_id;
1298 int tid; 1296 int tid;
@@ -1379,22 +1377,28 @@ int iwlagn_rx_reply_compressed_ba(struct iwl_priv *priv,
1379 freed = 0; 1377 freed = 0;
1380 1378
1381 skb_queue_walk(&reclaimed_skbs, skb) { 1379 skb_queue_walk(&reclaimed_skbs, skb) {
1382 hdr = (struct ieee80211_hdr *)skb->data; 1380 struct ieee80211_hdr *hdr = (void *)skb->data;
1381 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1383 1382
1384 if (ieee80211_is_data_qos(hdr->frame_control)) 1383 if (ieee80211_is_data_qos(hdr->frame_control))
1385 freed++; 1384 freed++;
1386 else 1385 else
1387 WARN_ON_ONCE(1); 1386 WARN_ON_ONCE(1);
1388 1387
1389 info = IEEE80211_SKB_CB(skb);
1390 iwl_trans_free_tx_cmd(priv->trans, info->driver_data[1]); 1388 iwl_trans_free_tx_cmd(priv->trans, info->driver_data[1]);
1391 1389
1390 memset(&info->status, 0, sizeof(info->status));
1391 /* Packet was transmitted successfully, failures come as single
1392 * frames because before failing a frame the firmware transmits
1393 * it without aggregation at least once.
1394 */
1395 info->flags |= IEEE80211_TX_STAT_ACK;
1396
1392 if (freed == 1) { 1397 if (freed == 1) {
1393 /* this is the first skb we deliver in this batch */ 1398 /* this is the first skb we deliver in this batch */
1394 /* put the rate scaling data there */ 1399 /* put the rate scaling data there */
1395 info = IEEE80211_SKB_CB(skb); 1400 info = IEEE80211_SKB_CB(skb);
1396 memset(&info->status, 0, sizeof(info->status)); 1401 memset(&info->status, 0, sizeof(info->status));
1397 info->flags |= IEEE80211_TX_STAT_ACK;
1398 info->flags |= IEEE80211_TX_STAT_AMPDU; 1402 info->flags |= IEEE80211_TX_STAT_AMPDU;
1399 info->status.ampdu_ack_len = ba_resp->txed_2_done; 1403 info->status.ampdu_ack_len = ba_resp->txed_2_done;
1400 info->status.ampdu_len = ba_resp->txed; 1404 info->status.ampdu_len = ba_resp->txed;
diff --git a/drivers/net/wireless/iwlwifi/mvm/bt-coex.c b/drivers/net/wireless/iwlwifi/mvm/bt-coex.c
index 76cde6ce6551..18a895a949d4 100644
--- a/drivers/net/wireless/iwlwifi/mvm/bt-coex.c
+++ b/drivers/net/wireless/iwlwifi/mvm/bt-coex.c
@@ -872,8 +872,11 @@ void iwl_mvm_bt_rssi_event(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
872 872
873 lockdep_assert_held(&mvm->mutex); 873 lockdep_assert_held(&mvm->mutex);
874 874
875 /* Rssi update while not associated ?! */ 875 /*
876 if (WARN_ON_ONCE(mvmvif->ap_sta_id == IWL_MVM_STATION_COUNT)) 876 * Rssi update while not associated - can happen since the statistics
877 * are handled asynchronously
878 */
879 if (mvmvif->ap_sta_id == IWL_MVM_STATION_COUNT)
877 return; 880 return;
878 881
879 /* No BT - reports should be disabled */ 882 /* No BT - reports should be disabled */
diff --git a/drivers/net/wireless/iwlwifi/mvm/mvm.h b/drivers/net/wireless/iwlwifi/mvm/mvm.h
index e4ead86f06d6..2b0ba1fc3c82 100644
--- a/drivers/net/wireless/iwlwifi/mvm/mvm.h
+++ b/drivers/net/wireless/iwlwifi/mvm/mvm.h
@@ -152,7 +152,7 @@ enum iwl_power_scheme {
152 IWL_POWER_SCHEME_LP 152 IWL_POWER_SCHEME_LP
153}; 153};
154 154
155#define IWL_CONN_MAX_LISTEN_INTERVAL 70 155#define IWL_CONN_MAX_LISTEN_INTERVAL 10
156#define IWL_UAPSD_AC_INFO (IEEE80211_WMM_IE_STA_QOSINFO_AC_VO |\ 156#define IWL_UAPSD_AC_INFO (IEEE80211_WMM_IE_STA_QOSINFO_AC_VO |\
157 IEEE80211_WMM_IE_STA_QOSINFO_AC_VI |\ 157 IEEE80211_WMM_IE_STA_QOSINFO_AC_VI |\
158 IEEE80211_WMM_IE_STA_QOSINFO_AC_BK |\ 158 IEEE80211_WMM_IE_STA_QOSINFO_AC_BK |\
diff --git a/drivers/net/wireless/iwlwifi/mvm/tx.c b/drivers/net/wireless/iwlwifi/mvm/tx.c
index 4df12fa9d336..76ee486039d7 100644
--- a/drivers/net/wireless/iwlwifi/mvm/tx.c
+++ b/drivers/net/wireless/iwlwifi/mvm/tx.c
@@ -822,16 +822,12 @@ int iwl_mvm_rx_ba_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb,
822 struct iwl_mvm_ba_notif *ba_notif = (void *)pkt->data; 822 struct iwl_mvm_ba_notif *ba_notif = (void *)pkt->data;
823 struct sk_buff_head reclaimed_skbs; 823 struct sk_buff_head reclaimed_skbs;
824 struct iwl_mvm_tid_data *tid_data; 824 struct iwl_mvm_tid_data *tid_data;
825 struct ieee80211_tx_info *info;
826 struct ieee80211_sta *sta; 825 struct ieee80211_sta *sta;
827 struct iwl_mvm_sta *mvmsta; 826 struct iwl_mvm_sta *mvmsta;
828 struct ieee80211_hdr *hdr;
829 struct sk_buff *skb; 827 struct sk_buff *skb;
830 int sta_id, tid, freed; 828 int sta_id, tid, freed;
831
832 /* "flow" corresponds to Tx queue */ 829 /* "flow" corresponds to Tx queue */
833 u16 scd_flow = le16_to_cpu(ba_notif->scd_flow); 830 u16 scd_flow = le16_to_cpu(ba_notif->scd_flow);
834
835 /* "ssn" is start of block-ack Tx window, corresponds to index 831 /* "ssn" is start of block-ack Tx window, corresponds to index
836 * (in Tx queue's circular buffer) of first TFD/frame in window */ 832 * (in Tx queue's circular buffer) of first TFD/frame in window */
837 u16 ba_resp_scd_ssn = le16_to_cpu(ba_notif->scd_ssn); 833 u16 ba_resp_scd_ssn = le16_to_cpu(ba_notif->scd_ssn);
@@ -888,22 +884,26 @@ int iwl_mvm_rx_ba_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb,
888 freed = 0; 884 freed = 0;
889 885
890 skb_queue_walk(&reclaimed_skbs, skb) { 886 skb_queue_walk(&reclaimed_skbs, skb) {
891 hdr = (struct ieee80211_hdr *)skb->data; 887 struct ieee80211_hdr *hdr = (void *)skb->data;
888 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
892 889
893 if (ieee80211_is_data_qos(hdr->frame_control)) 890 if (ieee80211_is_data_qos(hdr->frame_control))
894 freed++; 891 freed++;
895 else 892 else
896 WARN_ON_ONCE(1); 893 WARN_ON_ONCE(1);
897 894
898 info = IEEE80211_SKB_CB(skb);
899 iwl_trans_free_tx_cmd(mvm->trans, info->driver_data[1]); 895 iwl_trans_free_tx_cmd(mvm->trans, info->driver_data[1]);
900 896
897 memset(&info->status, 0, sizeof(info->status));
898 /* Packet was transmitted successfully, failures come as single
899 * frames because before failing a frame the firmware transmits
900 * it without aggregation at least once.
901 */
902 info->flags |= IEEE80211_TX_STAT_ACK;
903
901 if (freed == 1) { 904 if (freed == 1) {
902 /* this is the first skb we deliver in this batch */ 905 /* this is the first skb we deliver in this batch */
903 /* put the rate scaling data there */ 906 /* put the rate scaling data there */
904 info = IEEE80211_SKB_CB(skb);
905 memset(&info->status, 0, sizeof(info->status));
906 info->flags |= IEEE80211_TX_STAT_ACK;
907 info->flags |= IEEE80211_TX_STAT_AMPDU; 907 info->flags |= IEEE80211_TX_STAT_AMPDU;
908 info->status.ampdu_ack_len = ba_notif->txed_2_done; 908 info->status.ampdu_ack_len = ba_notif->txed_2_done;
909 info->status.ampdu_len = ba_notif->txed; 909 info->status.ampdu_len = ba_notif->txed;
diff --git a/drivers/net/wireless/iwlwifi/pcie/drv.c b/drivers/net/wireless/iwlwifi/pcie/drv.c
index f47bcbe2945a..3872ead75488 100644
--- a/drivers/net/wireless/iwlwifi/pcie/drv.c
+++ b/drivers/net/wireless/iwlwifi/pcie/drv.c
@@ -359,13 +359,12 @@ static DEFINE_PCI_DEVICE_TABLE(iwl_hw_card_ids) = {
359/* 7265 Series */ 359/* 7265 Series */
360 {IWL_PCI_DEVICE(0x095A, 0x5010, iwl7265_2ac_cfg)}, 360 {IWL_PCI_DEVICE(0x095A, 0x5010, iwl7265_2ac_cfg)},
361 {IWL_PCI_DEVICE(0x095A, 0x5110, iwl7265_2ac_cfg)}, 361 {IWL_PCI_DEVICE(0x095A, 0x5110, iwl7265_2ac_cfg)},
362 {IWL_PCI_DEVICE(0x095A, 0x5112, iwl7265_2ac_cfg)},
363 {IWL_PCI_DEVICE(0x095A, 0x5100, iwl7265_2ac_cfg)}, 362 {IWL_PCI_DEVICE(0x095A, 0x5100, iwl7265_2ac_cfg)},
364 {IWL_PCI_DEVICE(0x095A, 0x510A, iwl7265_2ac_cfg)},
365 {IWL_PCI_DEVICE(0x095B, 0x5310, iwl7265_2ac_cfg)}, 363 {IWL_PCI_DEVICE(0x095B, 0x5310, iwl7265_2ac_cfg)},
366 {IWL_PCI_DEVICE(0x095B, 0x5302, iwl7265_2ac_cfg)}, 364 {IWL_PCI_DEVICE(0x095B, 0x5302, iwl7265_n_cfg)},
367 {IWL_PCI_DEVICE(0x095B, 0x5210, iwl7265_2ac_cfg)}, 365 {IWL_PCI_DEVICE(0x095B, 0x5210, iwl7265_2ac_cfg)},
368 {IWL_PCI_DEVICE(0x095A, 0x5012, iwl7265_2ac_cfg)}, 366 {IWL_PCI_DEVICE(0x095A, 0x5012, iwl7265_2ac_cfg)},
367 {IWL_PCI_DEVICE(0x095A, 0x5412, iwl7265_2ac_cfg)},
369 {IWL_PCI_DEVICE(0x095A, 0x5410, iwl7265_2ac_cfg)}, 368 {IWL_PCI_DEVICE(0x095A, 0x5410, iwl7265_2ac_cfg)},
370 {IWL_PCI_DEVICE(0x095A, 0x5400, iwl7265_2ac_cfg)}, 369 {IWL_PCI_DEVICE(0x095A, 0x5400, iwl7265_2ac_cfg)},
371 {IWL_PCI_DEVICE(0x095A, 0x1010, iwl7265_2ac_cfg)}, 370 {IWL_PCI_DEVICE(0x095A, 0x1010, iwl7265_2ac_cfg)},
diff --git a/drivers/net/wireless/libertas/cfg.c b/drivers/net/wireless/libertas/cfg.c
index 32f75007a825..cb6d189bc3e6 100644
--- a/drivers/net/wireless/libertas/cfg.c
+++ b/drivers/net/wireless/libertas/cfg.c
@@ -621,7 +621,7 @@ static int lbs_ret_scan(struct lbs_private *priv, unsigned long dummy,
621 id = *pos++; 621 id = *pos++;
622 elen = *pos++; 622 elen = *pos++;
623 left -= 2; 623 left -= 2;
624 if (elen > left || elen == 0) { 624 if (elen > left) {
625 lbs_deb_scan("scan response: invalid IE fmt\n"); 625 lbs_deb_scan("scan response: invalid IE fmt\n");
626 goto done; 626 goto done;
627 } 627 }
diff --git a/drivers/net/wireless/mwifiex/11ac.c b/drivers/net/wireless/mwifiex/11ac.c
index 5e0eec4d71c7..5d9a8084665d 100644
--- a/drivers/net/wireless/mwifiex/11ac.c
+++ b/drivers/net/wireless/mwifiex/11ac.c
@@ -189,8 +189,7 @@ int mwifiex_cmd_append_11ac_tlv(struct mwifiex_private *priv,
189 vht_cap->header.len = 189 vht_cap->header.len =
190 cpu_to_le16(sizeof(struct ieee80211_vht_cap)); 190 cpu_to_le16(sizeof(struct ieee80211_vht_cap));
191 memcpy((u8 *)vht_cap + sizeof(struct mwifiex_ie_types_header), 191 memcpy((u8 *)vht_cap + sizeof(struct mwifiex_ie_types_header),
192 (u8 *)bss_desc->bcn_vht_cap + 192 (u8 *)bss_desc->bcn_vht_cap,
193 sizeof(struct ieee_types_header),
194 le16_to_cpu(vht_cap->header.len)); 193 le16_to_cpu(vht_cap->header.len));
195 194
196 mwifiex_fill_vht_cap_tlv(priv, vht_cap, bss_desc->bss_band); 195 mwifiex_fill_vht_cap_tlv(priv, vht_cap, bss_desc->bss_band);
diff --git a/drivers/net/wireless/mwifiex/11n.c b/drivers/net/wireless/mwifiex/11n.c
index 6261f8c53d44..7db1a89fdd95 100644
--- a/drivers/net/wireless/mwifiex/11n.c
+++ b/drivers/net/wireless/mwifiex/11n.c
@@ -308,8 +308,7 @@ mwifiex_cmd_append_11n_tlv(struct mwifiex_private *priv,
308 ht_cap->header.len = 308 ht_cap->header.len =
309 cpu_to_le16(sizeof(struct ieee80211_ht_cap)); 309 cpu_to_le16(sizeof(struct ieee80211_ht_cap));
310 memcpy((u8 *) ht_cap + sizeof(struct mwifiex_ie_types_header), 310 memcpy((u8 *) ht_cap + sizeof(struct mwifiex_ie_types_header),
311 (u8 *) bss_desc->bcn_ht_cap + 311 (u8 *)bss_desc->bcn_ht_cap,
312 sizeof(struct ieee_types_header),
313 le16_to_cpu(ht_cap->header.len)); 312 le16_to_cpu(ht_cap->header.len));
314 313
315 mwifiex_fill_cap_info(priv, radio_type, ht_cap); 314 mwifiex_fill_cap_info(priv, radio_type, ht_cap);
diff --git a/drivers/net/wireless/mwifiex/pcie.c b/drivers/net/wireless/mwifiex/pcie.c
index 03688aa14e8a..7fe7b53fb17a 100644
--- a/drivers/net/wireless/mwifiex/pcie.c
+++ b/drivers/net/wireless/mwifiex/pcie.c
@@ -1211,6 +1211,12 @@ static int mwifiex_pcie_process_recv_data(struct mwifiex_adapter *adapter)
1211 rd_index = card->rxbd_rdptr & reg->rx_mask; 1211 rd_index = card->rxbd_rdptr & reg->rx_mask;
1212 skb_data = card->rx_buf_list[rd_index]; 1212 skb_data = card->rx_buf_list[rd_index];
1213 1213
1214 /* If skb allocation was failed earlier for Rx packet,
1215 * rx_buf_list[rd_index] would have been left with a NULL.
1216 */
1217 if (!skb_data)
1218 return -ENOMEM;
1219
1214 MWIFIEX_SKB_PACB(skb_data, &buf_pa); 1220 MWIFIEX_SKB_PACB(skb_data, &buf_pa);
1215 pci_unmap_single(card->dev, buf_pa, MWIFIEX_RX_DATA_BUF_SIZE, 1221 pci_unmap_single(card->dev, buf_pa, MWIFIEX_RX_DATA_BUF_SIZE,
1216 PCI_DMA_FROMDEVICE); 1222 PCI_DMA_FROMDEVICE);
@@ -1525,6 +1531,14 @@ static int mwifiex_pcie_process_cmd_complete(struct mwifiex_adapter *adapter)
1525 if (adapter->ps_state == PS_STATE_SLEEP_CFM) { 1531 if (adapter->ps_state == PS_STATE_SLEEP_CFM) {
1526 mwifiex_process_sleep_confirm_resp(adapter, skb->data, 1532 mwifiex_process_sleep_confirm_resp(adapter, skb->data,
1527 skb->len); 1533 skb->len);
1534 mwifiex_pcie_enable_host_int(adapter);
1535 if (mwifiex_write_reg(adapter,
1536 PCIE_CPU_INT_EVENT,
1537 CPU_INTR_SLEEP_CFM_DONE)) {
1538 dev_warn(adapter->dev,
1539 "Write register failed\n");
1540 return -1;
1541 }
1528 while (reg->sleep_cookie && (count++ < 10) && 1542 while (reg->sleep_cookie && (count++ < 10) &&
1529 mwifiex_pcie_ok_to_access_hw(adapter)) 1543 mwifiex_pcie_ok_to_access_hw(adapter))
1530 usleep_range(50, 60); 1544 usleep_range(50, 60);
@@ -1993,23 +2007,9 @@ static void mwifiex_interrupt_status(struct mwifiex_adapter *adapter)
1993 adapter->int_status |= pcie_ireg; 2007 adapter->int_status |= pcie_ireg;
1994 spin_unlock_irqrestore(&adapter->int_lock, flags); 2008 spin_unlock_irqrestore(&adapter->int_lock, flags);
1995 2009
1996 if (pcie_ireg & HOST_INTR_CMD_DONE) { 2010 if (!adapter->pps_uapsd_mode &&
1997 if ((adapter->ps_state == PS_STATE_SLEEP_CFM) || 2011 adapter->ps_state == PS_STATE_SLEEP &&
1998 (adapter->ps_state == PS_STATE_SLEEP)) { 2012 mwifiex_pcie_ok_to_access_hw(adapter)) {
1999 mwifiex_pcie_enable_host_int(adapter);
2000 if (mwifiex_write_reg(adapter,
2001 PCIE_CPU_INT_EVENT,
2002 CPU_INTR_SLEEP_CFM_DONE)
2003 ) {
2004 dev_warn(adapter->dev,
2005 "Write register failed\n");
2006 return;
2007
2008 }
2009 }
2010 } else if (!adapter->pps_uapsd_mode &&
2011 adapter->ps_state == PS_STATE_SLEEP &&
2012 mwifiex_pcie_ok_to_access_hw(adapter)) {
2013 /* Potentially for PCIe we could get other 2013 /* Potentially for PCIe we could get other
2014 * interrupts like shared. Don't change power 2014 * interrupts like shared. Don't change power
2015 * state until cookie is set */ 2015 * state until cookie is set */
diff --git a/drivers/net/wireless/mwifiex/scan.c b/drivers/net/wireless/mwifiex/scan.c
index 0a8a26e10f01..668547c2de84 100644
--- a/drivers/net/wireless/mwifiex/scan.c
+++ b/drivers/net/wireless/mwifiex/scan.c
@@ -2101,12 +2101,12 @@ mwifiex_save_curr_bcn(struct mwifiex_private *priv)
2101 curr_bss->ht_info_offset); 2101 curr_bss->ht_info_offset);
2102 2102
2103 if (curr_bss->bcn_vht_cap) 2103 if (curr_bss->bcn_vht_cap)
2104 curr_bss->bcn_ht_cap = (void *)(curr_bss->beacon_buf + 2104 curr_bss->bcn_vht_cap = (void *)(curr_bss->beacon_buf +
2105 curr_bss->vht_cap_offset); 2105 curr_bss->vht_cap_offset);
2106 2106
2107 if (curr_bss->bcn_vht_oper) 2107 if (curr_bss->bcn_vht_oper)
2108 curr_bss->bcn_ht_oper = (void *)(curr_bss->beacon_buf + 2108 curr_bss->bcn_vht_oper = (void *)(curr_bss->beacon_buf +
2109 curr_bss->vht_info_offset); 2109 curr_bss->vht_info_offset);
2110 2110
2111 if (curr_bss->bcn_bss_co_2040) 2111 if (curr_bss->bcn_bss_co_2040)
2112 curr_bss->bcn_bss_co_2040 = 2112 curr_bss->bcn_bss_co_2040 =
diff --git a/drivers/net/wireless/mwifiex/usb.c b/drivers/net/wireless/mwifiex/usb.c
index e8ebbd4bc3cd..208748804a55 100644
--- a/drivers/net/wireless/mwifiex/usb.c
+++ b/drivers/net/wireless/mwifiex/usb.c
@@ -22,8 +22,6 @@
22 22
23#define USB_VERSION "1.0" 23#define USB_VERSION "1.0"
24 24
25static const char usbdriver_name[] = "usb8xxx";
26
27static struct mwifiex_if_ops usb_ops; 25static struct mwifiex_if_ops usb_ops;
28static struct semaphore add_remove_card_sem; 26static struct semaphore add_remove_card_sem;
29static struct usb_card_rec *usb_card; 27static struct usb_card_rec *usb_card;
@@ -527,13 +525,6 @@ static int mwifiex_usb_resume(struct usb_interface *intf)
527 MWIFIEX_BSS_ROLE_ANY), 525 MWIFIEX_BSS_ROLE_ANY),
528 MWIFIEX_ASYNC_CMD); 526 MWIFIEX_ASYNC_CMD);
529 527
530#ifdef CONFIG_PM
531 /* Resume handler may be called due to remote wakeup,
532 * force to exit suspend anyway
533 */
534 usb_disable_autosuspend(card->udev);
535#endif /* CONFIG_PM */
536
537 return 0; 528 return 0;
538} 529}
539 530
@@ -567,13 +558,12 @@ static void mwifiex_usb_disconnect(struct usb_interface *intf)
567} 558}
568 559
569static struct usb_driver mwifiex_usb_driver = { 560static struct usb_driver mwifiex_usb_driver = {
570 .name = usbdriver_name, 561 .name = "mwifiex_usb",
571 .probe = mwifiex_usb_probe, 562 .probe = mwifiex_usb_probe,
572 .disconnect = mwifiex_usb_disconnect, 563 .disconnect = mwifiex_usb_disconnect,
573 .id_table = mwifiex_usb_table, 564 .id_table = mwifiex_usb_table,
574 .suspend = mwifiex_usb_suspend, 565 .suspend = mwifiex_usb_suspend,
575 .resume = mwifiex_usb_resume, 566 .resume = mwifiex_usb_resume,
576 .supports_autosuspend = 1,
577}; 567};
578 568
579static int mwifiex_usb_tx_init(struct mwifiex_adapter *adapter) 569static int mwifiex_usb_tx_init(struct mwifiex_adapter *adapter)
diff --git a/drivers/net/wireless/mwifiex/wmm.c b/drivers/net/wireless/mwifiex/wmm.c
index 13eaeed03898..981cf6e7c73b 100644
--- a/drivers/net/wireless/mwifiex/wmm.c
+++ b/drivers/net/wireless/mwifiex/wmm.c
@@ -559,7 +559,8 @@ mwifiex_clean_txrx(struct mwifiex_private *priv)
559 mwifiex_wmm_delete_all_ralist(priv); 559 mwifiex_wmm_delete_all_ralist(priv);
560 memcpy(tos_to_tid, ac_to_tid, sizeof(tos_to_tid)); 560 memcpy(tos_to_tid, ac_to_tid, sizeof(tos_to_tid));
561 561
562 if (priv->adapter->if_ops.clean_pcie_ring) 562 if (priv->adapter->if_ops.clean_pcie_ring &&
563 !priv->adapter->surprise_removed)
563 priv->adapter->if_ops.clean_pcie_ring(priv->adapter); 564 priv->adapter->if_ops.clean_pcie_ring(priv->adapter);
564 spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, flags); 565 spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, flags);
565} 566}
diff --git a/drivers/net/wireless/rt2x00/rt2800lib.c b/drivers/net/wireless/rt2x00/rt2800lib.c
index 7f8b5d156c8c..41d4a8167dc3 100644
--- a/drivers/net/wireless/rt2x00/rt2800lib.c
+++ b/drivers/net/wireless/rt2x00/rt2800lib.c
@@ -5460,14 +5460,15 @@ static void rt2800_init_bbp_53xx(struct rt2x00_dev *rt2x00dev)
5460 5460
5461 rt2800_bbp_write(rt2x00dev, 68, 0x0b); 5461 rt2800_bbp_write(rt2x00dev, 68, 0x0b);
5462 5462
5463 rt2800_bbp_write(rt2x00dev, 69, 0x0d); 5463 rt2800_bbp_write(rt2x00dev, 69, 0x12);
5464 rt2800_bbp_write(rt2x00dev, 70, 0x06);
5465 rt2800_bbp_write(rt2x00dev, 73, 0x13); 5464 rt2800_bbp_write(rt2x00dev, 73, 0x13);
5466 rt2800_bbp_write(rt2x00dev, 75, 0x46); 5465 rt2800_bbp_write(rt2x00dev, 75, 0x46);
5467 rt2800_bbp_write(rt2x00dev, 76, 0x28); 5466 rt2800_bbp_write(rt2x00dev, 76, 0x28);
5468 5467
5469 rt2800_bbp_write(rt2x00dev, 77, 0x59); 5468 rt2800_bbp_write(rt2x00dev, 77, 0x59);
5470 5469
5470 rt2800_bbp_write(rt2x00dev, 70, 0x0a);
5471
5471 rt2800_bbp_write(rt2x00dev, 79, 0x13); 5472 rt2800_bbp_write(rt2x00dev, 79, 0x13);
5472 rt2800_bbp_write(rt2x00dev, 80, 0x05); 5473 rt2800_bbp_write(rt2x00dev, 80, 0x05);
5473 rt2800_bbp_write(rt2x00dev, 81, 0x33); 5474 rt2800_bbp_write(rt2x00dev, 81, 0x33);
@@ -5510,7 +5511,6 @@ static void rt2800_init_bbp_53xx(struct rt2x00_dev *rt2x00dev)
5510 if (rt2x00_rt(rt2x00dev, RT5392)) { 5511 if (rt2x00_rt(rt2x00dev, RT5392)) {
5511 rt2800_bbp_write(rt2x00dev, 134, 0xd0); 5512 rt2800_bbp_write(rt2x00dev, 134, 0xd0);
5512 rt2800_bbp_write(rt2x00dev, 135, 0xf6); 5513 rt2800_bbp_write(rt2x00dev, 135, 0xf6);
5513 rt2800_bbp_write(rt2x00dev, 148, 0x84);
5514 } 5514 }
5515 5515
5516 rt2800_disable_unused_dac_adc(rt2x00dev); 5516 rt2800_disable_unused_dac_adc(rt2x00dev);
diff --git a/drivers/net/wireless/rt2x00/rt2800usb.c b/drivers/net/wireless/rt2x00/rt2800usb.c
index caddc1b427a9..42a2e06512f2 100644
--- a/drivers/net/wireless/rt2x00/rt2800usb.c
+++ b/drivers/net/wireless/rt2x00/rt2800usb.c
@@ -764,7 +764,7 @@ static int rt2800usb_probe_hw(struct rt2x00_dev *rt2x00dev)
764 /* 764 /*
765 * Overwrite TX done handler 765 * Overwrite TX done handler
766 */ 766 */
767 PREPARE_WORK(&rt2x00dev->txdone_work, rt2800usb_work_txdone); 767 INIT_WORK(&rt2x00dev->txdone_work, rt2800usb_work_txdone);
768 768
769 return 0; 769 return 0;
770} 770}
diff --git a/drivers/net/wireless/ti/wl1251/rx.c b/drivers/net/wireless/ti/wl1251/rx.c
index 123c4bb50e0a..cde0eaf99714 100644
--- a/drivers/net/wireless/ti/wl1251/rx.c
+++ b/drivers/net/wireless/ti/wl1251/rx.c
@@ -180,7 +180,7 @@ static void wl1251_rx_body(struct wl1251 *wl,
180 wl1251_mem_read(wl, rx_packet_ring_addr, rx_buffer, length); 180 wl1251_mem_read(wl, rx_packet_ring_addr, rx_buffer, length);
181 181
182 /* The actual length doesn't include the target's alignment */ 182 /* The actual length doesn't include the target's alignment */
183 skb->len = desc->length - PLCP_HEADER_LENGTH; 183 skb_trim(skb, desc->length - PLCP_HEADER_LENGTH);
184 184
185 fc = (u16 *)skb->data; 185 fc = (u16 *)skb->data;
186 186
diff --git a/drivers/net/xen-netback/interface.c b/drivers/net/xen-netback/interface.c
index 7669d49a67e2..301cc037fda8 100644
--- a/drivers/net/xen-netback/interface.c
+++ b/drivers/net/xen-netback/interface.c
@@ -132,8 +132,7 @@ static int xenvif_start_xmit(struct sk_buff *skb, struct net_device *dev)
132 /* If the skb is GSO then we'll also need an extra slot for the 132 /* If the skb is GSO then we'll also need an extra slot for the
133 * metadata. 133 * metadata.
134 */ 134 */
135 if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV4 || 135 if (skb_is_gso(skb))
136 skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6)
137 min_slots_needed++; 136 min_slots_needed++;
138 137
139 /* If the skb can't possibly fit in the remaining slots 138 /* If the skb can't possibly fit in the remaining slots
diff --git a/drivers/net/xen-netback/netback.c b/drivers/net/xen-netback/netback.c
index e5284bca2d90..438d0c09b7e6 100644
--- a/drivers/net/xen-netback/netback.c
+++ b/drivers/net/xen-netback/netback.c
@@ -240,7 +240,7 @@ static void xenvif_gop_frag_copy(struct xenvif *vif, struct sk_buff *skb,
240 struct gnttab_copy *copy_gop; 240 struct gnttab_copy *copy_gop;
241 struct xenvif_rx_meta *meta; 241 struct xenvif_rx_meta *meta;
242 unsigned long bytes; 242 unsigned long bytes;
243 int gso_type; 243 int gso_type = XEN_NETIF_GSO_TYPE_NONE;
244 244
245 /* Data must not cross a page boundary. */ 245 /* Data must not cross a page boundary. */
246 BUG_ON(size + offset > PAGE_SIZE<<compound_order(page)); 246 BUG_ON(size + offset > PAGE_SIZE<<compound_order(page));
@@ -299,12 +299,12 @@ static void xenvif_gop_frag_copy(struct xenvif *vif, struct sk_buff *skb,
299 } 299 }
300 300
301 /* Leave a gap for the GSO descriptor. */ 301 /* Leave a gap for the GSO descriptor. */
302 if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV4) 302 if (skb_is_gso(skb)) {
303 gso_type = XEN_NETIF_GSO_TYPE_TCPV4; 303 if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV4)
304 else if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6) 304 gso_type = XEN_NETIF_GSO_TYPE_TCPV4;
305 gso_type = XEN_NETIF_GSO_TYPE_TCPV6; 305 else if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6)
306 else 306 gso_type = XEN_NETIF_GSO_TYPE_TCPV6;
307 gso_type = XEN_NETIF_GSO_TYPE_NONE; 307 }
308 308
309 if (*head && ((1 << gso_type) & vif->gso_mask)) 309 if (*head && ((1 << gso_type) & vif->gso_mask))
310 vif->rx.req_cons++; 310 vif->rx.req_cons++;
@@ -338,19 +338,15 @@ static int xenvif_gop_skb(struct sk_buff *skb,
338 int head = 1; 338 int head = 1;
339 int old_meta_prod; 339 int old_meta_prod;
340 int gso_type; 340 int gso_type;
341 int gso_size;
342 341
343 old_meta_prod = npo->meta_prod; 342 old_meta_prod = npo->meta_prod;
344 343
345 if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV4) { 344 gso_type = XEN_NETIF_GSO_TYPE_NONE;
346 gso_type = XEN_NETIF_GSO_TYPE_TCPV4; 345 if (skb_is_gso(skb)) {
347 gso_size = skb_shinfo(skb)->gso_size; 346 if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV4)
348 } else if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6) { 347 gso_type = XEN_NETIF_GSO_TYPE_TCPV4;
349 gso_type = XEN_NETIF_GSO_TYPE_TCPV6; 348 else if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6)
350 gso_size = skb_shinfo(skb)->gso_size; 349 gso_type = XEN_NETIF_GSO_TYPE_TCPV6;
351 } else {
352 gso_type = XEN_NETIF_GSO_TYPE_NONE;
353 gso_size = 0;
354 } 350 }
355 351
356 /* Set up a GSO prefix descriptor, if necessary */ 352 /* Set up a GSO prefix descriptor, if necessary */
@@ -358,7 +354,7 @@ static int xenvif_gop_skb(struct sk_buff *skb,
358 req = RING_GET_REQUEST(&vif->rx, vif->rx.req_cons++); 354 req = RING_GET_REQUEST(&vif->rx, vif->rx.req_cons++);
359 meta = npo->meta + npo->meta_prod++; 355 meta = npo->meta + npo->meta_prod++;
360 meta->gso_type = gso_type; 356 meta->gso_type = gso_type;
361 meta->gso_size = gso_size; 357 meta->gso_size = skb_shinfo(skb)->gso_size;
362 meta->size = 0; 358 meta->size = 0;
363 meta->id = req->id; 359 meta->id = req->id;
364 } 360 }
@@ -368,7 +364,7 @@ static int xenvif_gop_skb(struct sk_buff *skb,
368 364
369 if ((1 << gso_type) & vif->gso_mask) { 365 if ((1 << gso_type) & vif->gso_mask) {
370 meta->gso_type = gso_type; 366 meta->gso_type = gso_type;
371 meta->gso_size = gso_size; 367 meta->gso_size = skb_shinfo(skb)->gso_size;
372 } else { 368 } else {
373 meta->gso_type = XEN_NETIF_GSO_TYPE_NONE; 369 meta->gso_type = XEN_NETIF_GSO_TYPE_NONE;
374 meta->gso_size = 0; 370 meta->gso_size = 0;
@@ -500,8 +496,9 @@ static void xenvif_rx_action(struct xenvif *vif)
500 size = skb_frag_size(&skb_shinfo(skb)->frags[i]); 496 size = skb_frag_size(&skb_shinfo(skb)->frags[i]);
501 max_slots_needed += DIV_ROUND_UP(size, PAGE_SIZE); 497 max_slots_needed += DIV_ROUND_UP(size, PAGE_SIZE);
502 } 498 }
503 if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV4 || 499 if (skb_is_gso(skb) &&
504 skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6) 500 (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV4 ||
501 skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6))
505 max_slots_needed++; 502 max_slots_needed++;
506 503
507 /* If the skb may not fit then bail out now */ 504 /* If the skb may not fit then bail out now */
diff --git a/drivers/net/xen-netfront.c b/drivers/net/xen-netfront.c
index f9daa9e183f2..e30d80033cbc 100644
--- a/drivers/net/xen-netfront.c
+++ b/drivers/net/xen-netfront.c
@@ -907,6 +907,7 @@ static int handle_incoming_queue(struct net_device *dev,
907 907
908 /* Ethernet work: Delayed to here as it peeks the header. */ 908 /* Ethernet work: Delayed to here as it peeks the header. */
909 skb->protocol = eth_type_trans(skb, dev); 909 skb->protocol = eth_type_trans(skb, dev);
910 skb_reset_network_header(skb);
910 911
911 if (checksum_setup(dev, skb)) { 912 if (checksum_setup(dev, skb)) {
912 kfree_skb(skb); 913 kfree_skb(skb);
diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c
index 00660cc502c5..38901665c770 100644
--- a/drivers/pci/bus.c
+++ b/drivers/pci/bus.c
@@ -162,8 +162,6 @@ static int pci_bus_alloc_from_region(struct pci_bus *bus, struct resource *res,
162 162
163 avail = *r; 163 avail = *r;
164 pci_clip_resource_to_region(bus, &avail, region); 164 pci_clip_resource_to_region(bus, &avail, region);
165 if (!resource_size(&avail))
166 continue;
167 165
168 /* 166 /*
169 * "min" is typically PCIBIOS_MIN_IO or PCIBIOS_MIN_MEM to 167 * "min" is typically PCIBIOS_MIN_IO or PCIBIOS_MIN_MEM to
diff --git a/drivers/pci/host/pcie-designware.c b/drivers/pci/host/pcie-designware.c
index 17ce88f79d2b..2e48ecf09e2c 100644
--- a/drivers/pci/host/pcie-designware.c
+++ b/drivers/pci/host/pcie-designware.c
@@ -294,14 +294,12 @@ no_valid_irq:
294static void clear_irq(unsigned int irq) 294static void clear_irq(unsigned int irq)
295{ 295{
296 unsigned int pos, nvec; 296 unsigned int pos, nvec;
297 struct irq_desc *desc;
298 struct msi_desc *msi; 297 struct msi_desc *msi;
299 struct pcie_port *pp; 298 struct pcie_port *pp;
300 struct irq_data *data = irq_get_irq_data(irq); 299 struct irq_data *data = irq_get_irq_data(irq);
301 300
302 /* get the port structure */ 301 /* get the port structure */
303 desc = irq_to_desc(irq); 302 msi = irq_data_get_msi(data);
304 msi = irq_desc_get_msi_desc(desc);
305 pp = sys_to_pcie(msi->dev->bus->sysdata); 303 pp = sys_to_pcie(msi->dev->bus->sysdata);
306 if (!pp) { 304 if (!pp) {
307 BUG(); 305 BUG();
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 6b05f6134b68..fdbc294821e6 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -1192,6 +1192,9 @@ static int do_pci_enable_device(struct pci_dev *dev, int bars)
1192 return err; 1192 return err;
1193 pci_fixup_device(pci_fixup_enable, dev); 1193 pci_fixup_device(pci_fixup_enable, dev);
1194 1194
1195 if (dev->msi_enabled || dev->msix_enabled)
1196 return 0;
1197
1195 pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin); 1198 pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin);
1196 if (pin) { 1199 if (pin) {
1197 pci_read_config_word(dev, PCI_COMMAND, &cmd); 1200 pci_read_config_word(dev, PCI_COMMAND, &cmd);
diff --git a/drivers/pinctrl/Kconfig b/drivers/pinctrl/Kconfig
index be361b7cd30f..1e4e69384baa 100644
--- a/drivers/pinctrl/Kconfig
+++ b/drivers/pinctrl/Kconfig
@@ -217,7 +217,7 @@ config PINCTRL_IMX28
217 select PINCTRL_MXS 217 select PINCTRL_MXS
218 218
219config PINCTRL_MSM 219config PINCTRL_MSM
220 tristate 220 bool
221 select PINMUX 221 select PINMUX
222 select PINCONF 222 select PINCONF
223 select GENERIC_PINCONF 223 select GENERIC_PINCONF
diff --git a/drivers/pinctrl/pinctrl-capri.c b/drivers/pinctrl/pinctrl-capri.c
index 4669c53f99b0..eb2500212147 100644
--- a/drivers/pinctrl/pinctrl-capri.c
+++ b/drivers/pinctrl/pinctrl-capri.c
@@ -1435,7 +1435,7 @@ int __init capri_pinctrl_probe(struct platform_device *pdev)
1435} 1435}
1436 1436
1437static struct of_device_id capri_pinctrl_of_match[] = { 1437static struct of_device_id capri_pinctrl_of_match[] = {
1438 { .compatible = "brcm,capri-pinctrl", }, 1438 { .compatible = "brcm,bcm11351-pinctrl", },
1439 { }, 1439 { },
1440}; 1440};
1441 1441
diff --git a/drivers/pinctrl/pinctrl-sunxi.c b/drivers/pinctrl/pinctrl-sunxi.c
index 9ccf681dad2f..f9fabe9bf47d 100644
--- a/drivers/pinctrl/pinctrl-sunxi.c
+++ b/drivers/pinctrl/pinctrl-sunxi.c
@@ -14,6 +14,7 @@
14#include <linux/clk.h> 14#include <linux/clk.h>
15#include <linux/gpio.h> 15#include <linux/gpio.h>
16#include <linux/irqdomain.h> 16#include <linux/irqdomain.h>
17#include <linux/irqchip/chained_irq.h>
17#include <linux/module.h> 18#include <linux/module.h>
18#include <linux/of.h> 19#include <linux/of.h>
19#include <linux/of_address.h> 20#include <linux/of_address.h>
@@ -584,7 +585,7 @@ static int sunxi_pinctrl_irq_set_type(struct irq_data *d,
584 spin_lock_irqsave(&pctl->lock, flags); 585 spin_lock_irqsave(&pctl->lock, flags);
585 586
586 regval = readl(pctl->membase + reg); 587 regval = readl(pctl->membase + reg);
587 regval &= ~IRQ_CFG_IRQ_MASK; 588 regval &= ~(IRQ_CFG_IRQ_MASK << index);
588 writel(regval | (mode << index), pctl->membase + reg); 589 writel(regval | (mode << index), pctl->membase + reg);
589 590
590 spin_unlock_irqrestore(&pctl->lock, flags); 591 spin_unlock_irqrestore(&pctl->lock, flags);
@@ -665,6 +666,7 @@ static struct irq_chip sunxi_pinctrl_irq_chip = {
665 666
666static void sunxi_pinctrl_irq_handler(unsigned irq, struct irq_desc *desc) 667static void sunxi_pinctrl_irq_handler(unsigned irq, struct irq_desc *desc)
667{ 668{
669 struct irq_chip *chip = irq_get_chip(irq);
668 struct sunxi_pinctrl *pctl = irq_get_handler_data(irq); 670 struct sunxi_pinctrl *pctl = irq_get_handler_data(irq);
669 const unsigned long reg = readl(pctl->membase + IRQ_STATUS_REG); 671 const unsigned long reg = readl(pctl->membase + IRQ_STATUS_REG);
670 672
@@ -674,10 +676,12 @@ static void sunxi_pinctrl_irq_handler(unsigned irq, struct irq_desc *desc)
674 if (reg) { 676 if (reg) {
675 int irqoffset; 677 int irqoffset;
676 678
679 chained_irq_enter(chip, desc);
677 for_each_set_bit(irqoffset, &reg, SUNXI_IRQ_NUMBER) { 680 for_each_set_bit(irqoffset, &reg, SUNXI_IRQ_NUMBER) {
678 int pin_irq = irq_find_mapping(pctl->domain, irqoffset); 681 int pin_irq = irq_find_mapping(pctl->domain, irqoffset);
679 generic_handle_irq(pin_irq); 682 generic_handle_irq(pin_irq);
680 } 683 }
684 chained_irq_exit(chip, desc);
681 } 685 }
682} 686}
683 687
diff --git a/drivers/pinctrl/pinctrl-sunxi.h b/drivers/pinctrl/pinctrl-sunxi.h
index 01c494f8a14f..552b0e97077a 100644
--- a/drivers/pinctrl/pinctrl-sunxi.h
+++ b/drivers/pinctrl/pinctrl-sunxi.h
@@ -511,7 +511,7 @@ static inline u32 sunxi_pull_offset(u16 pin)
511 511
512static inline u32 sunxi_irq_cfg_reg(u16 irq) 512static inline u32 sunxi_irq_cfg_reg(u16 irq)
513{ 513{
514 u8 reg = irq / IRQ_CFG_IRQ_PER_REG; 514 u8 reg = irq / IRQ_CFG_IRQ_PER_REG * 0x04;
515 return reg + IRQ_CFG_REG; 515 return reg + IRQ_CFG_REG;
516} 516}
517 517
@@ -523,7 +523,7 @@ static inline u32 sunxi_irq_cfg_offset(u16 irq)
523 523
524static inline u32 sunxi_irq_ctrl_reg(u16 irq) 524static inline u32 sunxi_irq_ctrl_reg(u16 irq)
525{ 525{
526 u8 reg = irq / IRQ_CTRL_IRQ_PER_REG; 526 u8 reg = irq / IRQ_CTRL_IRQ_PER_REG * 0x04;
527 return reg + IRQ_CTRL_REG; 527 return reg + IRQ_CTRL_REG;
528} 528}
529 529
@@ -535,7 +535,7 @@ static inline u32 sunxi_irq_ctrl_offset(u16 irq)
535 535
536static inline u32 sunxi_irq_status_reg(u16 irq) 536static inline u32 sunxi_irq_status_reg(u16 irq)
537{ 537{
538 u8 reg = irq / IRQ_STATUS_IRQ_PER_REG; 538 u8 reg = irq / IRQ_STATUS_IRQ_PER_REG * 0x04;
539 return reg + IRQ_STATUS_REG; 539 return reg + IRQ_STATUS_REG;
540} 540}
541 541
diff --git a/drivers/pinctrl/sh-pfc/pfc-r8a7791.c b/drivers/pinctrl/sh-pfc/pfc-r8a7791.c
index 77d103fe39d9..567d6918d50b 100644
--- a/drivers/pinctrl/sh-pfc/pfc-r8a7791.c
+++ b/drivers/pinctrl/sh-pfc/pfc-r8a7791.c
@@ -89,7 +89,8 @@ enum {
89 89
90 /* GPSR6 */ 90 /* GPSR6 */
91 FN_IP13_10, FN_IP13_11, FN_IP13_12, FN_IP13_13, FN_IP13_14, 91 FN_IP13_10, FN_IP13_11, FN_IP13_12, FN_IP13_13, FN_IP13_14,
92 FN_IP13_15, FN_IP13_18_16, FN_IP13_21_19, FN_IP13_22, FN_IP13_24_23, 92 FN_IP13_15, FN_IP13_18_16, FN_IP13_21_19,
93 FN_IP13_22, FN_IP13_24_23, FN_SD1_CLK,
93 FN_IP13_25, FN_IP13_26, FN_IP13_27, FN_IP13_30_28, FN_IP14_1_0, 94 FN_IP13_25, FN_IP13_26, FN_IP13_27, FN_IP13_30_28, FN_IP14_1_0,
94 FN_IP14_2, FN_IP14_3, FN_IP14_4, FN_IP14_5, FN_IP14_6, FN_IP14_7, 95 FN_IP14_2, FN_IP14_3, FN_IP14_4, FN_IP14_5, FN_IP14_6, FN_IP14_7,
95 FN_IP14_10_8, FN_IP14_13_11, FN_IP14_16_14, FN_IP14_19_17, 96 FN_IP14_10_8, FN_IP14_13_11, FN_IP14_16_14, FN_IP14_19_17,
@@ -788,6 +789,7 @@ static const u16 pinmux_data[] = {
788 PINMUX_DATA(USB1_PWEN_MARK, FN_USB1_PWEN), 789 PINMUX_DATA(USB1_PWEN_MARK, FN_USB1_PWEN),
789 PINMUX_DATA(USB1_OVC_MARK, FN_USB1_OVC), 790 PINMUX_DATA(USB1_OVC_MARK, FN_USB1_OVC),
790 PINMUX_DATA(DU0_DOTCLKIN_MARK, FN_DU0_DOTCLKIN), 791 PINMUX_DATA(DU0_DOTCLKIN_MARK, FN_DU0_DOTCLKIN),
792 PINMUX_DATA(SD1_CLK_MARK, FN_SD1_CLK),
791 793
792 /* IPSR0 */ 794 /* IPSR0 */
793 PINMUX_IPSR_DATA(IP0_0, D0), 795 PINMUX_IPSR_DATA(IP0_0, D0),
@@ -3825,7 +3827,7 @@ static const struct pinmux_cfg_reg pinmux_config_regs[] = {
3825 GP_6_11_FN, FN_IP13_25, 3827 GP_6_11_FN, FN_IP13_25,
3826 GP_6_10_FN, FN_IP13_24_23, 3828 GP_6_10_FN, FN_IP13_24_23,
3827 GP_6_9_FN, FN_IP13_22, 3829 GP_6_9_FN, FN_IP13_22,
3828 0, 0, 3830 GP_6_8_FN, FN_SD1_CLK,
3829 GP_6_7_FN, FN_IP13_21_19, 3831 GP_6_7_FN, FN_IP13_21_19,
3830 GP_6_6_FN, FN_IP13_18_16, 3832 GP_6_6_FN, FN_IP13_18_16,
3831 GP_6_5_FN, FN_IP13_15, 3833 GP_6_5_FN, FN_IP13_15,
diff --git a/drivers/pinctrl/sirf/pinctrl-sirf.c b/drivers/pinctrl/sirf/pinctrl-sirf.c
index a0d6152701cd..617a4916b50f 100644
--- a/drivers/pinctrl/sirf/pinctrl-sirf.c
+++ b/drivers/pinctrl/sirf/pinctrl-sirf.c
@@ -598,7 +598,7 @@ static unsigned int sirfsoc_gpio_irq_startup(struct irq_data *d)
598{ 598{
599 struct sirfsoc_gpio_bank *bank = irq_data_get_irq_chip_data(d); 599 struct sirfsoc_gpio_bank *bank = irq_data_get_irq_chip_data(d);
600 600
601 if (gpio_lock_as_irq(&bank->chip.gc, d->hwirq)) 601 if (gpio_lock_as_irq(&bank->chip.gc, d->hwirq % SIRFSOC_GPIO_BANK_SIZE))
602 dev_err(bank->chip.gc.dev, 602 dev_err(bank->chip.gc.dev,
603 "unable to lock HW IRQ %lu for IRQ\n", 603 "unable to lock HW IRQ %lu for IRQ\n",
604 d->hwirq); 604 d->hwirq);
@@ -611,7 +611,7 @@ static void sirfsoc_gpio_irq_shutdown(struct irq_data *d)
611 struct sirfsoc_gpio_bank *bank = irq_data_get_irq_chip_data(d); 611 struct sirfsoc_gpio_bank *bank = irq_data_get_irq_chip_data(d);
612 612
613 sirfsoc_gpio_irq_mask(d); 613 sirfsoc_gpio_irq_mask(d);
614 gpio_unlock_as_irq(&bank->chip.gc, d->hwirq); 614 gpio_unlock_as_irq(&bank->chip.gc, d->hwirq % SIRFSOC_GPIO_BANK_SIZE);
615} 615}
616 616
617static struct irq_chip sirfsoc_irq_chip = { 617static struct irq_chip sirfsoc_irq_chip = {
diff --git a/drivers/pnp/pnpacpi/rsparser.c b/drivers/pnp/pnpacpi/rsparser.c
index 167f3d00c916..66977ebf13b3 100644
--- a/drivers/pnp/pnpacpi/rsparser.c
+++ b/drivers/pnp/pnpacpi/rsparser.c
@@ -183,9 +183,7 @@ static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res,
183 struct resource r = {0}; 183 struct resource r = {0};
184 int i, flags; 184 int i, flags;
185 185
186 if (acpi_dev_resource_memory(res, &r) 186 if (acpi_dev_resource_address_space(res, &r)
187 || acpi_dev_resource_io(res, &r)
188 || acpi_dev_resource_address_space(res, &r)
189 || acpi_dev_resource_ext_address_space(res, &r)) { 187 || acpi_dev_resource_ext_address_space(res, &r)) {
190 pnp_add_resource(dev, &r); 188 pnp_add_resource(dev, &r);
191 return AE_OK; 189 return AE_OK;
@@ -217,6 +215,17 @@ static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res,
217 } 215 }
218 216
219 switch (res->type) { 217 switch (res->type) {
218 case ACPI_RESOURCE_TYPE_MEMORY24:
219 case ACPI_RESOURCE_TYPE_MEMORY32:
220 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
221 if (acpi_dev_resource_memory(res, &r))
222 pnp_add_resource(dev, &r);
223 break;
224 case ACPI_RESOURCE_TYPE_IO:
225 case ACPI_RESOURCE_TYPE_FIXED_IO:
226 if (acpi_dev_resource_io(res, &r))
227 pnp_add_resource(dev, &r);
228 break;
220 case ACPI_RESOURCE_TYPE_DMA: 229 case ACPI_RESOURCE_TYPE_DMA:
221 dma = &res->data.dma; 230 dma = &res->data.dma;
222 if (dma->channel_count > 0 && dma->channels[0] != (u8) -1) 231 if (dma->channel_count > 0 && dma->channels[0] != (u8) -1)
diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
index 769d265b221b..deb7f4bcdb7b 100644
--- a/drivers/pnp/pnpbios/bioscalls.c
+++ b/drivers/pnp/pnpbios/bioscalls.c
@@ -21,7 +21,7 @@
21 21
22#include "pnpbios.h" 22#include "pnpbios.h"
23 23
24static struct { 24__visible struct {
25 u16 offset; 25 u16 offset;
26 u16 segment; 26 u16 segment;
27} pnp_bios_callpoint; 27} pnp_bios_callpoint;
@@ -41,6 +41,7 @@ asmlinkage void pnp_bios_callfunc(void);
41 41
42__asm__(".text \n" 42__asm__(".text \n"
43 __ALIGN_STR "\n" 43 __ALIGN_STR "\n"
44 ".globl pnp_bios_callfunc\n"
44 "pnp_bios_callfunc:\n" 45 "pnp_bios_callfunc:\n"
45 " pushl %edx \n" 46 " pushl %edx \n"
46 " pushl %ecx \n" 47 " pushl %ecx \n"
@@ -66,9 +67,9 @@ static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
66 * after PnP BIOS oopses. 67 * after PnP BIOS oopses.
67 */ 68 */
68 69
69u32 pnp_bios_fault_esp; 70__visible u32 pnp_bios_fault_esp;
70u32 pnp_bios_fault_eip; 71__visible u32 pnp_bios_fault_eip;
71u32 pnp_bios_is_utter_crap = 0; 72__visible u32 pnp_bios_is_utter_crap = 0;
72 73
73static spinlock_t pnp_bios_lock; 74static spinlock_t pnp_bios_lock;
74 75
diff --git a/drivers/ps3/ps3-vuart.c b/drivers/ps3/ps3-vuart.c
index fb7300837fee..bc1e5139ba29 100644
--- a/drivers/ps3/ps3-vuart.c
+++ b/drivers/ps3/ps3-vuart.c
@@ -699,8 +699,6 @@ int ps3_vuart_read_async(struct ps3_system_bus_device *dev, unsigned int bytes)
699 699
700 BUG_ON(!bytes); 700 BUG_ON(!bytes);
701 701
702 PREPARE_WORK(&priv->rx_list.work.work, ps3_vuart_work);
703
704 spin_lock_irqsave(&priv->rx_list.lock, flags); 702 spin_lock_irqsave(&priv->rx_list.lock, flags);
705 if (priv->rx_list.bytes_held >= bytes) { 703 if (priv->rx_list.bytes_held >= bytes) {
706 dev_dbg(&dev->core, "%s:%d: schedule_work %xh bytes\n", 704 dev_dbg(&dev->core, "%s:%d: schedule_work %xh bytes\n",
@@ -1052,7 +1050,7 @@ static int ps3_vuart_probe(struct ps3_system_bus_device *dev)
1052 INIT_LIST_HEAD(&priv->rx_list.head); 1050 INIT_LIST_HEAD(&priv->rx_list.head);
1053 spin_lock_init(&priv->rx_list.lock); 1051 spin_lock_init(&priv->rx_list.lock);
1054 1052
1055 INIT_WORK(&priv->rx_list.work.work, NULL); 1053 INIT_WORK(&priv->rx_list.work.work, ps3_vuart_work);
1056 priv->rx_list.work.trigger = 0; 1054 priv->rx_list.work.trigger = 0;
1057 priv->rx_list.work.dev = dev; 1055 priv->rx_list.work.dev = dev;
1058 1056
diff --git a/drivers/pwm/pwm-lp3943.c b/drivers/pwm/pwm-lp3943.c
index 8a843a04c224..a40b9c34e9ff 100644
--- a/drivers/pwm/pwm-lp3943.c
+++ b/drivers/pwm/pwm-lp3943.c
@@ -52,8 +52,10 @@ lp3943_pwm_request_map(struct lp3943_pwm *lp3943_pwm, int hwpwm)
52 offset = pwm_map->output[i]; 52 offset = pwm_map->output[i];
53 53
54 /* Return an error if the pin is already assigned */ 54 /* Return an error if the pin is already assigned */
55 if (test_and_set_bit(offset, &lp3943->pin_used)) 55 if (test_and_set_bit(offset, &lp3943->pin_used)) {
56 kfree(pwm_map);
56 return ERR_PTR(-EBUSY); 57 return ERR_PTR(-EBUSY);
58 }
57 } 59 }
58 60
59 return pwm_map; 61 return pwm_map;
diff --git a/drivers/rapidio/devices/tsi721.h b/drivers/rapidio/devices/tsi721.h
index b4b0d83f9ef6..7061ac0ad428 100644
--- a/drivers/rapidio/devices/tsi721.h
+++ b/drivers/rapidio/devices/tsi721.h
@@ -678,6 +678,7 @@ struct tsi721_bdma_chan {
678 struct list_head free_list; 678 struct list_head free_list;
679 dma_cookie_t completed_cookie; 679 dma_cookie_t completed_cookie;
680 struct tasklet_struct tasklet; 680 struct tasklet_struct tasklet;
681 bool active;
681}; 682};
682 683
683#endif /* CONFIG_RAPIDIO_DMA_ENGINE */ 684#endif /* CONFIG_RAPIDIO_DMA_ENGINE */
diff --git a/drivers/rapidio/devices/tsi721_dma.c b/drivers/rapidio/devices/tsi721_dma.c
index 502663f5f7c6..91245f5dbe81 100644
--- a/drivers/rapidio/devices/tsi721_dma.c
+++ b/drivers/rapidio/devices/tsi721_dma.c
@@ -206,8 +206,8 @@ void tsi721_bdma_handler(struct tsi721_bdma_chan *bdma_chan)
206{ 206{
207 /* Disable BDMA channel interrupts */ 207 /* Disable BDMA channel interrupts */
208 iowrite32(0, bdma_chan->regs + TSI721_DMAC_INTE); 208 iowrite32(0, bdma_chan->regs + TSI721_DMAC_INTE);
209 209 if (bdma_chan->active)
210 tasklet_schedule(&bdma_chan->tasklet); 210 tasklet_schedule(&bdma_chan->tasklet);
211} 211}
212 212
213#ifdef CONFIG_PCI_MSI 213#ifdef CONFIG_PCI_MSI
@@ -562,7 +562,7 @@ static int tsi721_alloc_chan_resources(struct dma_chan *dchan)
562 } 562 }
563#endif /* CONFIG_PCI_MSI */ 563#endif /* CONFIG_PCI_MSI */
564 564
565 tasklet_enable(&bdma_chan->tasklet); 565 bdma_chan->active = true;
566 tsi721_bdma_interrupt_enable(bdma_chan, 1); 566 tsi721_bdma_interrupt_enable(bdma_chan, 1);
567 567
568 return bdma_chan->bd_num - 1; 568 return bdma_chan->bd_num - 1;
@@ -576,9 +576,7 @@ err_out:
576static void tsi721_free_chan_resources(struct dma_chan *dchan) 576static void tsi721_free_chan_resources(struct dma_chan *dchan)
577{ 577{
578 struct tsi721_bdma_chan *bdma_chan = to_tsi721_chan(dchan); 578 struct tsi721_bdma_chan *bdma_chan = to_tsi721_chan(dchan);
579#ifdef CONFIG_PCI_MSI
580 struct tsi721_device *priv = to_tsi721(dchan->device); 579 struct tsi721_device *priv = to_tsi721(dchan->device);
581#endif
582 LIST_HEAD(list); 580 LIST_HEAD(list);
583 581
584 dev_dbg(dchan->device->dev, "%s: Entry\n", __func__); 582 dev_dbg(dchan->device->dev, "%s: Entry\n", __func__);
@@ -589,14 +587,25 @@ static void tsi721_free_chan_resources(struct dma_chan *dchan)
589 BUG_ON(!list_empty(&bdma_chan->active_list)); 587 BUG_ON(!list_empty(&bdma_chan->active_list));
590 BUG_ON(!list_empty(&bdma_chan->queue)); 588 BUG_ON(!list_empty(&bdma_chan->queue));
591 589
592 tasklet_disable(&bdma_chan->tasklet); 590 tsi721_bdma_interrupt_enable(bdma_chan, 0);
591 bdma_chan->active = false;
592
593#ifdef CONFIG_PCI_MSI
594 if (priv->flags & TSI721_USING_MSIX) {
595 synchronize_irq(priv->msix[TSI721_VECT_DMA0_DONE +
596 bdma_chan->id].vector);
597 synchronize_irq(priv->msix[TSI721_VECT_DMA0_INT +
598 bdma_chan->id].vector);
599 } else
600#endif
601 synchronize_irq(priv->pdev->irq);
602
603 tasklet_kill(&bdma_chan->tasklet);
593 604
594 spin_lock_bh(&bdma_chan->lock); 605 spin_lock_bh(&bdma_chan->lock);
595 list_splice_init(&bdma_chan->free_list, &list); 606 list_splice_init(&bdma_chan->free_list, &list);
596 spin_unlock_bh(&bdma_chan->lock); 607 spin_unlock_bh(&bdma_chan->lock);
597 608
598 tsi721_bdma_interrupt_enable(bdma_chan, 0);
599
600#ifdef CONFIG_PCI_MSI 609#ifdef CONFIG_PCI_MSI
601 if (priv->flags & TSI721_USING_MSIX) { 610 if (priv->flags & TSI721_USING_MSIX) {
602 free_irq(priv->msix[TSI721_VECT_DMA0_DONE + 611 free_irq(priv->msix[TSI721_VECT_DMA0_DONE +
@@ -790,6 +799,7 @@ int tsi721_register_dma(struct tsi721_device *priv)
790 bdma_chan->dchan.cookie = 1; 799 bdma_chan->dchan.cookie = 1;
791 bdma_chan->dchan.chan_id = i; 800 bdma_chan->dchan.chan_id = i;
792 bdma_chan->id = i; 801 bdma_chan->id = i;
802 bdma_chan->active = false;
793 803
794 spin_lock_init(&bdma_chan->lock); 804 spin_lock_init(&bdma_chan->lock);
795 805
@@ -799,7 +809,6 @@ int tsi721_register_dma(struct tsi721_device *priv)
799 809
800 tasklet_init(&bdma_chan->tasklet, tsi721_dma_tasklet, 810 tasklet_init(&bdma_chan->tasklet, tsi721_dma_tasklet,
801 (unsigned long)bdma_chan); 811 (unsigned long)bdma_chan);
802 tasklet_disable(&bdma_chan->tasklet);
803 list_add_tail(&bdma_chan->dchan.device_node, 812 list_add_tail(&bdma_chan->dchan.device_node,
804 &mport->dma.channels); 813 &mport->dma.channels);
805 } 814 }
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index d1ac4caaf1b0..afca1bc24f26 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -953,6 +953,8 @@ static int machine_constraints_current(struct regulator_dev *rdev,
953 return 0; 953 return 0;
954} 954}
955 955
956static int _regulator_do_enable(struct regulator_dev *rdev);
957
956/** 958/**
957 * set_machine_constraints - sets regulator constraints 959 * set_machine_constraints - sets regulator constraints
958 * @rdev: regulator source 960 * @rdev: regulator source
@@ -1013,10 +1015,9 @@ static int set_machine_constraints(struct regulator_dev *rdev,
1013 /* If the constraints say the regulator should be on at this point 1015 /* If the constraints say the regulator should be on at this point
1014 * and we have control then make sure it is enabled. 1016 * and we have control then make sure it is enabled.
1015 */ 1017 */
1016 if ((rdev->constraints->always_on || rdev->constraints->boot_on) && 1018 if (rdev->constraints->always_on || rdev->constraints->boot_on) {
1017 ops->enable) { 1019 ret = _regulator_do_enable(rdev);
1018 ret = ops->enable(rdev); 1020 if (ret < 0 && ret != -EINVAL) {
1019 if (ret < 0) {
1020 rdev_err(rdev, "failed to enable\n"); 1021 rdev_err(rdev, "failed to enable\n");
1021 goto out; 1022 goto out;
1022 } 1023 }
@@ -1907,8 +1908,6 @@ static int _regulator_do_disable(struct regulator_dev *rdev)
1907 1908
1908 trace_regulator_disable_complete(rdev_get_name(rdev)); 1909 trace_regulator_disable_complete(rdev_get_name(rdev));
1909 1910
1910 _notifier_call_chain(rdev, REGULATOR_EVENT_DISABLE,
1911 NULL);
1912 return 0; 1911 return 0;
1913} 1912}
1914 1913
@@ -1932,6 +1931,8 @@ static int _regulator_disable(struct regulator_dev *rdev)
1932 rdev_err(rdev, "failed to disable\n"); 1931 rdev_err(rdev, "failed to disable\n");
1933 return ret; 1932 return ret;
1934 } 1933 }
1934 _notifier_call_chain(rdev, REGULATOR_EVENT_DISABLE,
1935 NULL);
1935 } 1936 }
1936 1937
1937 rdev->use_count = 0; 1938 rdev->use_count = 0;
@@ -1984,20 +1985,16 @@ static int _regulator_force_disable(struct regulator_dev *rdev)
1984{ 1985{
1985 int ret = 0; 1986 int ret = 0;
1986 1987
1987 /* force disable */ 1988 ret = _regulator_do_disable(rdev);
1988 if (rdev->desc->ops->disable) { 1989 if (ret < 0) {
1989 /* ah well, who wants to live forever... */ 1990 rdev_err(rdev, "failed to force disable\n");
1990 ret = rdev->desc->ops->disable(rdev); 1991 return ret;
1991 if (ret < 0) {
1992 rdev_err(rdev, "failed to force disable\n");
1993 return ret;
1994 }
1995 /* notify other consumers that power has been forced off */
1996 _notifier_call_chain(rdev, REGULATOR_EVENT_FORCE_DISABLE |
1997 REGULATOR_EVENT_DISABLE, NULL);
1998 } 1992 }
1999 1993
2000 return ret; 1994 _notifier_call_chain(rdev, REGULATOR_EVENT_FORCE_DISABLE |
1995 REGULATOR_EVENT_DISABLE, NULL);
1996
1997 return 0;
2001} 1998}
2002 1999
2003/** 2000/**
@@ -3630,23 +3627,18 @@ int regulator_suspend_finish(void)
3630 3627
3631 mutex_lock(&regulator_list_mutex); 3628 mutex_lock(&regulator_list_mutex);
3632 list_for_each_entry(rdev, &regulator_list, list) { 3629 list_for_each_entry(rdev, &regulator_list, list) {
3633 struct regulator_ops *ops = rdev->desc->ops;
3634
3635 mutex_lock(&rdev->mutex); 3630 mutex_lock(&rdev->mutex);
3636 if ((rdev->use_count > 0 || rdev->constraints->always_on) && 3631 if (rdev->use_count > 0 || rdev->constraints->always_on) {
3637 ops->enable) { 3632 error = _regulator_do_enable(rdev);
3638 error = ops->enable(rdev);
3639 if (error) 3633 if (error)
3640 ret = error; 3634 ret = error;
3641 } else { 3635 } else {
3642 if (!have_full_constraints()) 3636 if (!have_full_constraints())
3643 goto unlock; 3637 goto unlock;
3644 if (!ops->disable)
3645 goto unlock;
3646 if (!_regulator_is_enabled(rdev)) 3638 if (!_regulator_is_enabled(rdev))
3647 goto unlock; 3639 goto unlock;
3648 3640
3649 error = ops->disable(rdev); 3641 error = _regulator_do_disable(rdev);
3650 if (error) 3642 if (error)
3651 ret = error; 3643 ret = error;
3652 } 3644 }
@@ -3820,7 +3812,7 @@ static int __init regulator_init_complete(void)
3820 ops = rdev->desc->ops; 3812 ops = rdev->desc->ops;
3821 c = rdev->constraints; 3813 c = rdev->constraints;
3822 3814
3823 if (!ops->disable || (c && c->always_on)) 3815 if (c && c->always_on)
3824 continue; 3816 continue;
3825 3817
3826 mutex_lock(&rdev->mutex); 3818 mutex_lock(&rdev->mutex);
@@ -3841,7 +3833,7 @@ static int __init regulator_init_complete(void)
3841 /* We log since this may kill the system if it 3833 /* We log since this may kill the system if it
3842 * goes wrong. */ 3834 * goes wrong. */
3843 rdev_info(rdev, "disabling\n"); 3835 rdev_info(rdev, "disabling\n");
3844 ret = ops->disable(rdev); 3836 ret = _regulator_do_disable(rdev);
3845 if (ret != 0) 3837 if (ret != 0)
3846 rdev_err(rdev, "couldn't disable: %d\n", ret); 3838 rdev_err(rdev, "couldn't disable: %d\n", ret);
3847 } else { 3839 } else {
diff --git a/drivers/rtc/rtc-s3c.c b/drivers/rtc/rtc-s3c.c
index 7afd373b9595..c4cde9c08f1f 100644
--- a/drivers/rtc/rtc-s3c.c
+++ b/drivers/rtc/rtc-s3c.c
@@ -580,10 +580,12 @@ static int s3c_rtc_suspend(struct device *dev)
580 580
581 clk_enable(rtc_clk); 581 clk_enable(rtc_clk);
582 /* save TICNT for anyone using periodic interrupts */ 582 /* save TICNT for anyone using periodic interrupts */
583 ticnt_save = readb(s3c_rtc_base + S3C2410_TICNT);
584 if (s3c_rtc_cpu_type == TYPE_S3C64XX) { 583 if (s3c_rtc_cpu_type == TYPE_S3C64XX) {
585 ticnt_en_save = readw(s3c_rtc_base + S3C2410_RTCCON); 584 ticnt_en_save = readw(s3c_rtc_base + S3C2410_RTCCON);
586 ticnt_en_save &= S3C64XX_RTCCON_TICEN; 585 ticnt_en_save &= S3C64XX_RTCCON_TICEN;
586 ticnt_save = readl(s3c_rtc_base + S3C2410_TICNT);
587 } else {
588 ticnt_save = readb(s3c_rtc_base + S3C2410_TICNT);
587 } 589 }
588 s3c_rtc_enable(pdev, 0); 590 s3c_rtc_enable(pdev, 0);
589 591
@@ -605,10 +607,15 @@ static int s3c_rtc_resume(struct device *dev)
605 607
606 clk_enable(rtc_clk); 608 clk_enable(rtc_clk);
607 s3c_rtc_enable(pdev, 1); 609 s3c_rtc_enable(pdev, 1);
608 writeb(ticnt_save, s3c_rtc_base + S3C2410_TICNT); 610 if (s3c_rtc_cpu_type == TYPE_S3C64XX) {
609 if (s3c_rtc_cpu_type == TYPE_S3C64XX && ticnt_en_save) { 611 writel(ticnt_save, s3c_rtc_base + S3C2410_TICNT);
610 tmp = readw(s3c_rtc_base + S3C2410_RTCCON); 612 if (ticnt_en_save) {
611 writew(tmp | ticnt_en_save, s3c_rtc_base + S3C2410_RTCCON); 613 tmp = readw(s3c_rtc_base + S3C2410_RTCCON);
614 writew(tmp | ticnt_en_save,
615 s3c_rtc_base + S3C2410_RTCCON);
616 }
617 } else {
618 writeb(ticnt_save, s3c_rtc_base + S3C2410_TICNT);
612 } 619 }
613 620
614 if (device_may_wakeup(dev) && wake_en) { 621 if (device_may_wakeup(dev) && wake_en) {
diff --git a/drivers/s390/char/con3215.c b/drivers/s390/char/con3215.c
index eb5d22795c47..5af7f0bd6125 100644
--- a/drivers/s390/char/con3215.c
+++ b/drivers/s390/char/con3215.c
@@ -922,7 +922,7 @@ static int __init con3215_init(void)
922 raw3215_freelist = req; 922 raw3215_freelist = req;
923 } 923 }
924 924
925 cdev = ccw_device_probe_console(); 925 cdev = ccw_device_create_console(&raw3215_ccw_driver);
926 if (IS_ERR(cdev)) 926 if (IS_ERR(cdev))
927 return -ENODEV; 927 return -ENODEV;
928 928
@@ -932,6 +932,12 @@ static int __init con3215_init(void)
932 cdev->handler = raw3215_irq; 932 cdev->handler = raw3215_irq;
933 933
934 raw->flags |= RAW3215_FIXED; 934 raw->flags |= RAW3215_FIXED;
935 if (ccw_device_enable_console(cdev)) {
936 ccw_device_destroy_console(cdev);
937 raw3215_free_info(raw);
938 raw3215[0] = NULL;
939 return -ENODEV;
940 }
935 941
936 /* Request the console irq */ 942 /* Request the console irq */
937 if (raw3215_startup(raw) != 0) { 943 if (raw3215_startup(raw) != 0) {
diff --git a/drivers/s390/char/con3270.c b/drivers/s390/char/con3270.c
index 699fd3e363df..75ffe9980c3e 100644
--- a/drivers/s390/char/con3270.c
+++ b/drivers/s390/char/con3270.c
@@ -7,6 +7,7 @@
7 * Copyright IBM Corp. 2003, 2009 7 * Copyright IBM Corp. 2003, 2009
8 */ 8 */
9 9
10#include <linux/module.h>
10#include <linux/console.h> 11#include <linux/console.h>
11#include <linux/init.h> 12#include <linux/init.h>
12#include <linux/interrupt.h> 13#include <linux/interrupt.h>
@@ -30,6 +31,9 @@
30 31
31static struct raw3270_fn con3270_fn; 32static struct raw3270_fn con3270_fn;
32 33
34static bool auto_update = 1;
35module_param(auto_update, bool, 0);
36
33/* 37/*
34 * Main 3270 console view data structure. 38 * Main 3270 console view data structure.
35 */ 39 */
@@ -204,6 +208,8 @@ con3270_update(struct con3270 *cp)
204 struct string *s, *n; 208 struct string *s, *n;
205 int rc; 209 int rc;
206 210
211 if (!auto_update && !raw3270_view_active(&cp->view))
212 return;
207 if (cp->view.dev) 213 if (cp->view.dev)
208 raw3270_activate_view(&cp->view); 214 raw3270_activate_view(&cp->view);
209 215
@@ -529,6 +535,7 @@ con3270_flush(void)
529 if (!cp->view.dev) 535 if (!cp->view.dev)
530 return; 536 return;
531 raw3270_pm_unfreeze(&cp->view); 537 raw3270_pm_unfreeze(&cp->view);
538 raw3270_activate_view(&cp->view);
532 spin_lock_irqsave(&cp->view.lock, flags); 539 spin_lock_irqsave(&cp->view.lock, flags);
533 con3270_wait_write(cp); 540 con3270_wait_write(cp);
534 cp->nr_up = 0; 541 cp->nr_up = 0;
@@ -576,7 +583,6 @@ static struct console con3270 = {
576static int __init 583static int __init
577con3270_init(void) 584con3270_init(void)
578{ 585{
579 struct ccw_device *cdev;
580 struct raw3270 *rp; 586 struct raw3270 *rp;
581 void *cbuf; 587 void *cbuf;
582 int i; 588 int i;
@@ -591,10 +597,7 @@ con3270_init(void)
591 cpcmd("TERM AUTOCR OFF", NULL, 0, NULL); 597 cpcmd("TERM AUTOCR OFF", NULL, 0, NULL);
592 } 598 }
593 599
594 cdev = ccw_device_probe_console(); 600 rp = raw3270_setup_console();
595 if (IS_ERR(cdev))
596 return -ENODEV;
597 rp = raw3270_setup_console(cdev);
598 if (IS_ERR(rp)) 601 if (IS_ERR(rp))
599 return PTR_ERR(rp); 602 return PTR_ERR(rp);
600 603
diff --git a/drivers/s390/char/raw3270.c b/drivers/s390/char/raw3270.c
index 2cdec21e8924..9f849df4381e 100644
--- a/drivers/s390/char/raw3270.c
+++ b/drivers/s390/char/raw3270.c
@@ -276,6 +276,15 @@ __raw3270_start(struct raw3270 *rp, struct raw3270_view *view,
276} 276}
277 277
278int 278int
279raw3270_view_active(struct raw3270_view *view)
280{
281 struct raw3270 *rp = view->dev;
282
283 return rp && rp->view == view &&
284 !test_bit(RAW3270_FLAGS_FROZEN, &rp->flags);
285}
286
287int
279raw3270_start(struct raw3270_view *view, struct raw3270_request *rq) 288raw3270_start(struct raw3270_view *view, struct raw3270_request *rq)
280{ 289{
281 unsigned long flags; 290 unsigned long flags;
@@ -776,22 +785,37 @@ raw3270_setup_device(struct ccw_device *cdev, struct raw3270 *rp, char *ascebc)
776} 785}
777 786
778#ifdef CONFIG_TN3270_CONSOLE 787#ifdef CONFIG_TN3270_CONSOLE
788/* Tentative definition - see below for actual definition. */
789static struct ccw_driver raw3270_ccw_driver;
790
779/* 791/*
780 * Setup 3270 device configured as console. 792 * Setup 3270 device configured as console.
781 */ 793 */
782struct raw3270 __init *raw3270_setup_console(struct ccw_device *cdev) 794struct raw3270 __init *raw3270_setup_console(void)
783{ 795{
796 struct ccw_device *cdev;
784 unsigned long flags; 797 unsigned long flags;
785 struct raw3270 *rp; 798 struct raw3270 *rp;
786 char *ascebc; 799 char *ascebc;
787 int rc; 800 int rc;
788 801
802 cdev = ccw_device_create_console(&raw3270_ccw_driver);
803 if (IS_ERR(cdev))
804 return ERR_CAST(cdev);
805
789 rp = kzalloc(sizeof(struct raw3270), GFP_KERNEL | GFP_DMA); 806 rp = kzalloc(sizeof(struct raw3270), GFP_KERNEL | GFP_DMA);
790 ascebc = kzalloc(256, GFP_KERNEL); 807 ascebc = kzalloc(256, GFP_KERNEL);
791 rc = raw3270_setup_device(cdev, rp, ascebc); 808 rc = raw3270_setup_device(cdev, rp, ascebc);
792 if (rc) 809 if (rc)
793 return ERR_PTR(rc); 810 return ERR_PTR(rc);
794 set_bit(RAW3270_FLAGS_CONSOLE, &rp->flags); 811 set_bit(RAW3270_FLAGS_CONSOLE, &rp->flags);
812
813 rc = ccw_device_enable_console(cdev);
814 if (rc) {
815 ccw_device_destroy_console(cdev);
816 return ERR_PTR(rc);
817 }
818
795 spin_lock_irqsave(get_ccwdev_lock(rp->cdev), flags); 819 spin_lock_irqsave(get_ccwdev_lock(rp->cdev), flags);
796 do { 820 do {
797 __raw3270_reset_device(rp); 821 __raw3270_reset_device(rp);
diff --git a/drivers/s390/char/raw3270.h b/drivers/s390/char/raw3270.h
index 7b73ff8c1bd7..e1e41c2861fb 100644
--- a/drivers/s390/char/raw3270.h
+++ b/drivers/s390/char/raw3270.h
@@ -173,6 +173,7 @@ int raw3270_start_locked(struct raw3270_view *, struct raw3270_request *);
173int raw3270_start_irq(struct raw3270_view *, struct raw3270_request *); 173int raw3270_start_irq(struct raw3270_view *, struct raw3270_request *);
174int raw3270_reset(struct raw3270_view *); 174int raw3270_reset(struct raw3270_view *);
175struct raw3270_view *raw3270_view(struct raw3270_view *); 175struct raw3270_view *raw3270_view(struct raw3270_view *);
176int raw3270_view_active(struct raw3270_view *);
176 177
177/* Reference count inliner for view structures. */ 178/* Reference count inliner for view structures. */
178static inline void 179static inline void
@@ -190,7 +191,7 @@ raw3270_put_view(struct raw3270_view *view)
190 wake_up(&raw3270_wait_queue); 191 wake_up(&raw3270_wait_queue);
191} 192}
192 193
193struct raw3270 *raw3270_setup_console(struct ccw_device *cdev); 194struct raw3270 *raw3270_setup_console(void);
194void raw3270_wait_cons_dev(struct raw3270 *); 195void raw3270_wait_cons_dev(struct raw3270 *);
195 196
196/* Notifier for device addition/removal */ 197/* Notifier for device addition/removal */
diff --git a/drivers/s390/char/sclp_early.c b/drivers/s390/char/sclp_early.c
index 82f2c389b4d1..14196ea0fdf3 100644
--- a/drivers/s390/char/sclp_early.c
+++ b/drivers/s390/char/sclp_early.c
@@ -20,7 +20,9 @@ struct read_info_sccb {
20 struct sccb_header header; /* 0-7 */ 20 struct sccb_header header; /* 0-7 */
21 u16 rnmax; /* 8-9 */ 21 u16 rnmax; /* 8-9 */
22 u8 rnsize; /* 10 */ 22 u8 rnsize; /* 10 */
23 u8 _reserved0[24 - 11]; /* 11-15 */ 23 u8 _reserved0[16 - 11]; /* 11-15 */
24 u16 ncpurl; /* 16-17 */
25 u8 _reserved7[24 - 18]; /* 18-23 */
24 u8 loadparm[8]; /* 24-31 */ 26 u8 loadparm[8]; /* 24-31 */
25 u8 _reserved1[48 - 32]; /* 32-47 */ 27 u8 _reserved1[48 - 32]; /* 32-47 */
26 u64 facilities; /* 48-55 */ 28 u64 facilities; /* 48-55 */
@@ -32,13 +34,16 @@ struct read_info_sccb {
32 u8 _reserved4[100 - 92]; /* 92-99 */ 34 u8 _reserved4[100 - 92]; /* 92-99 */
33 u32 rnsize2; /* 100-103 */ 35 u32 rnsize2; /* 100-103 */
34 u64 rnmax2; /* 104-111 */ 36 u64 rnmax2; /* 104-111 */
35 u8 _reserved5[4096 - 112]; /* 112-4095 */ 37 u8 _reserved5[120 - 112]; /* 112-119 */
38 u16 hcpua; /* 120-121 */
39 u8 _reserved6[4096 - 122]; /* 122-4095 */
36} __packed __aligned(PAGE_SIZE); 40} __packed __aligned(PAGE_SIZE);
37 41
38static char sccb_early[PAGE_SIZE] __aligned(PAGE_SIZE) __initdata; 42static char sccb_early[PAGE_SIZE] __aligned(PAGE_SIZE) __initdata;
39static unsigned int sclp_con_has_vt220 __initdata; 43static unsigned int sclp_con_has_vt220 __initdata;
40static unsigned int sclp_con_has_linemode __initdata; 44static unsigned int sclp_con_has_linemode __initdata;
41static unsigned long sclp_hsa_size; 45static unsigned long sclp_hsa_size;
46static unsigned int sclp_max_cpu;
42static struct sclp_ipl_info sclp_ipl_info; 47static struct sclp_ipl_info sclp_ipl_info;
43 48
44u64 sclp_facilities; 49u64 sclp_facilities;
@@ -102,6 +107,15 @@ static void __init sclp_facilities_detect(struct read_info_sccb *sccb)
102 sclp_rzm = sccb->rnsize ? sccb->rnsize : sccb->rnsize2; 107 sclp_rzm = sccb->rnsize ? sccb->rnsize : sccb->rnsize2;
103 sclp_rzm <<= 20; 108 sclp_rzm <<= 20;
104 109
110 if (!sccb->hcpua) {
111 if (MACHINE_IS_VM)
112 sclp_max_cpu = 64;
113 else
114 sclp_max_cpu = sccb->ncpurl;
115 } else {
116 sclp_max_cpu = sccb->hcpua + 1;
117 }
118
105 /* Save IPL information */ 119 /* Save IPL information */
106 sclp_ipl_info.is_valid = 1; 120 sclp_ipl_info.is_valid = 1;
107 if (sccb->flags & 0x2) 121 if (sccb->flags & 0x2)
@@ -129,6 +143,11 @@ unsigned long long sclp_get_rzm(void)
129 return sclp_rzm; 143 return sclp_rzm;
130} 144}
131 145
146unsigned int sclp_get_max_cpu(void)
147{
148 return sclp_max_cpu;
149}
150
132/* 151/*
133 * This function will be called after sclp_facilities_detect(), which gets 152 * This function will be called after sclp_facilities_detect(), which gets
134 * called from early.c code. The sclp_facilities_detect() function retrieves 153 * called from early.c code. The sclp_facilities_detect() function retrieves
@@ -184,9 +203,9 @@ static long __init sclp_hsa_size_init(struct sdias_sccb *sccb)
184 sccb_init_eq_size(sccb); 203 sccb_init_eq_size(sccb);
185 if (sclp_cmd_early(SCLP_CMDW_WRITE_EVENT_DATA, sccb)) 204 if (sclp_cmd_early(SCLP_CMDW_WRITE_EVENT_DATA, sccb))
186 return -EIO; 205 return -EIO;
187 if (sccb->evbuf.blk_cnt != 0) 206 if (sccb->evbuf.blk_cnt == 0)
188 return (sccb->evbuf.blk_cnt - 1) * PAGE_SIZE; 207 return 0;
189 return 0; 208 return (sccb->evbuf.blk_cnt - 1) * PAGE_SIZE;
190} 209}
191 210
192static long __init sclp_hsa_copy_wait(struct sccb_header *sccb) 211static long __init sclp_hsa_copy_wait(struct sccb_header *sccb)
@@ -195,6 +214,8 @@ static long __init sclp_hsa_copy_wait(struct sccb_header *sccb)
195 sccb->length = PAGE_SIZE; 214 sccb->length = PAGE_SIZE;
196 if (sclp_cmd_early(SCLP_CMDW_READ_EVENT_DATA, sccb)) 215 if (sclp_cmd_early(SCLP_CMDW_READ_EVENT_DATA, sccb))
197 return -EIO; 216 return -EIO;
217 if (((struct sdias_sccb *) sccb)->evbuf.blk_cnt == 0)
218 return 0;
198 return (((struct sdias_sccb *) sccb)->evbuf.blk_cnt - 1) * PAGE_SIZE; 219 return (((struct sdias_sccb *) sccb)->evbuf.blk_cnt - 1) * PAGE_SIZE;
199} 220}
200 221
diff --git a/drivers/s390/cio/airq.c b/drivers/s390/cio/airq.c
index f055df0b167f..445564c790f6 100644
--- a/drivers/s390/cio/airq.c
+++ b/drivers/s390/cio/airq.c
@@ -186,55 +186,71 @@ void airq_iv_release(struct airq_iv *iv)
186EXPORT_SYMBOL(airq_iv_release); 186EXPORT_SYMBOL(airq_iv_release);
187 187
188/** 188/**
189 * airq_iv_alloc_bit - allocate an irq bit from an interrupt vector 189 * airq_iv_alloc - allocate irq bits from an interrupt vector
190 * @iv: pointer to an interrupt vector structure 190 * @iv: pointer to an interrupt vector structure
191 * @num: number of consecutive irq bits to allocate
191 * 192 *
192 * Returns the bit number of the allocated irq, or -1UL if no bit 193 * Returns the bit number of the first irq in the allocated block of irqs,
193 * is available or the AIRQ_IV_ALLOC flag has not been specified 194 * or -1UL if no bit is available or the AIRQ_IV_ALLOC flag has not been
195 * specified
194 */ 196 */
195unsigned long airq_iv_alloc_bit(struct airq_iv *iv) 197unsigned long airq_iv_alloc(struct airq_iv *iv, unsigned long num)
196{ 198{
197 unsigned long bit; 199 unsigned long bit, i;
198 200
199 if (!iv->avail) 201 if (!iv->avail || num == 0)
200 return -1UL; 202 return -1UL;
201 spin_lock(&iv->lock); 203 spin_lock(&iv->lock);
202 bit = find_first_bit_inv(iv->avail, iv->bits); 204 bit = find_first_bit_inv(iv->avail, iv->bits);
203 if (bit < iv->bits) { 205 while (bit + num <= iv->bits) {
204 clear_bit_inv(bit, iv->avail); 206 for (i = 1; i < num; i++)
205 if (bit >= iv->end) 207 if (!test_bit_inv(bit + i, iv->avail))
206 iv->end = bit + 1; 208 break;
207 } else 209 if (i >= num) {
210 /* Found a suitable block of irqs */
211 for (i = 0; i < num; i++)
212 clear_bit_inv(bit + i, iv->avail);
213 if (bit + num >= iv->end)
214 iv->end = bit + num + 1;
215 break;
216 }
217 bit = find_next_bit_inv(iv->avail, iv->bits, bit + i + 1);
218 }
219 if (bit + num > iv->bits)
208 bit = -1UL; 220 bit = -1UL;
209 spin_unlock(&iv->lock); 221 spin_unlock(&iv->lock);
210 return bit; 222 return bit;
211 223
212} 224}
213EXPORT_SYMBOL(airq_iv_alloc_bit); 225EXPORT_SYMBOL(airq_iv_alloc);
214 226
215/** 227/**
216 * airq_iv_free_bit - free an irq bit of an interrupt vector 228 * airq_iv_free - free irq bits of an interrupt vector
217 * @iv: pointer to interrupt vector structure 229 * @iv: pointer to interrupt vector structure
218 * @bit: number of the irq bit to free 230 * @bit: number of the first irq bit to free
231 * @num: number of consecutive irq bits to free
219 */ 232 */
220void airq_iv_free_bit(struct airq_iv *iv, unsigned long bit) 233void airq_iv_free(struct airq_iv *iv, unsigned long bit, unsigned long num)
221{ 234{
222 if (!iv->avail) 235 unsigned long i;
236
237 if (!iv->avail || num == 0)
223 return; 238 return;
224 spin_lock(&iv->lock); 239 spin_lock(&iv->lock);
225 /* Clear (possibly left over) interrupt bit */ 240 for (i = 0; i < num; i++) {
226 clear_bit_inv(bit, iv->vector); 241 /* Clear (possibly left over) interrupt bit */
227 /* Make the bit position available again */ 242 clear_bit_inv(bit + i, iv->vector);
228 set_bit_inv(bit, iv->avail); 243 /* Make the bit positions available again */
229 if (bit == iv->end - 1) { 244 set_bit_inv(bit + i, iv->avail);
245 }
246 if (bit + num >= iv->end) {
230 /* Find new end of bit-field */ 247 /* Find new end of bit-field */
231 while (--iv->end > 0) 248 while (iv->end > 0 && !test_bit_inv(iv->end - 1, iv->avail))
232 if (!test_bit_inv(iv->end - 1, iv->avail)) 249 iv->end--;
233 break;
234 } 250 }
235 spin_unlock(&iv->lock); 251 spin_unlock(&iv->lock);
236} 252}
237EXPORT_SYMBOL(airq_iv_free_bit); 253EXPORT_SYMBOL(airq_iv_free);
238 254
239/** 255/**
240 * airq_iv_scan - scan interrupt vector for non-zero bits 256 * airq_iv_scan - scan interrupt vector for non-zero bits
diff --git a/drivers/s390/cio/chsc.c b/drivers/s390/cio/chsc.c
index f6b9188c5af5..9f0ea6cb6922 100644
--- a/drivers/s390/cio/chsc.c
+++ b/drivers/s390/cio/chsc.c
@@ -610,6 +610,7 @@ void chsc_chp_online(struct chp_id chpid)
610 css_wait_for_slow_path(); 610 css_wait_for_slow_path();
611 for_each_subchannel_staged(__s390_process_res_acc, NULL, 611 for_each_subchannel_staged(__s390_process_res_acc, NULL,
612 &link); 612 &link);
613 css_schedule_reprobe();
613 } 614 }
614} 615}
615 616
diff --git a/drivers/s390/cio/chsc_sch.c b/drivers/s390/cio/chsc_sch.c
index 7b29d0be0ca3..1d3661af7bd8 100644
--- a/drivers/s390/cio/chsc_sch.c
+++ b/drivers/s390/cio/chsc_sch.c
@@ -173,8 +173,7 @@ static struct css_driver chsc_subchannel_driver = {
173 173
174static int __init chsc_init_dbfs(void) 174static int __init chsc_init_dbfs(void)
175{ 175{
176 chsc_debug_msg_id = debug_register("chsc_msg", 16, 1, 176 chsc_debug_msg_id = debug_register("chsc_msg", 8, 1, 4 * sizeof(long));
177 16 * sizeof(long));
178 if (!chsc_debug_msg_id) 177 if (!chsc_debug_msg_id)
179 goto out; 178 goto out;
180 debug_register_view(chsc_debug_msg_id, &debug_sprintf_view); 179 debug_register_view(chsc_debug_msg_id, &debug_sprintf_view);
diff --git a/drivers/s390/cio/cio.c b/drivers/s390/cio/cio.c
index 8ee88c4ebd83..9e058c4657a3 100644
--- a/drivers/s390/cio/cio.c
+++ b/drivers/s390/cio/cio.c
@@ -18,6 +18,7 @@
18#include <linux/device.h> 18#include <linux/device.h>
19#include <linux/kernel_stat.h> 19#include <linux/kernel_stat.h>
20#include <linux/interrupt.h> 20#include <linux/interrupt.h>
21#include <linux/irq.h>
21#include <asm/cio.h> 22#include <asm/cio.h>
22#include <asm/delay.h> 23#include <asm/delay.h>
23#include <asm/irq.h> 24#include <asm/irq.h>
@@ -28,7 +29,7 @@
28#include <asm/chpid.h> 29#include <asm/chpid.h>
29#include <asm/airq.h> 30#include <asm/airq.h>
30#include <asm/isc.h> 31#include <asm/isc.h>
31#include <asm/cputime.h> 32#include <linux/cputime.h>
32#include <asm/fcx.h> 33#include <asm/fcx.h>
33#include <asm/nmi.h> 34#include <asm/nmi.h>
34#include <asm/crw.h> 35#include <asm/crw.h>
@@ -54,7 +55,7 @@ debug_info_t *cio_debug_crw_id;
54 */ 55 */
55static int __init cio_debug_init(void) 56static int __init cio_debug_init(void)
56{ 57{
57 cio_debug_msg_id = debug_register("cio_msg", 16, 1, 16 * sizeof(long)); 58 cio_debug_msg_id = debug_register("cio_msg", 16, 1, 11 * sizeof(long));
58 if (!cio_debug_msg_id) 59 if (!cio_debug_msg_id)
59 goto out_unregister; 60 goto out_unregister;
60 debug_register_view(cio_debug_msg_id, &debug_sprintf_view); 61 debug_register_view(cio_debug_msg_id, &debug_sprintf_view);
@@ -64,7 +65,7 @@ static int __init cio_debug_init(void)
64 goto out_unregister; 65 goto out_unregister;
65 debug_register_view(cio_debug_trace_id, &debug_hex_ascii_view); 66 debug_register_view(cio_debug_trace_id, &debug_hex_ascii_view);
66 debug_set_level(cio_debug_trace_id, 2); 67 debug_set_level(cio_debug_trace_id, 2);
67 cio_debug_crw_id = debug_register("cio_crw", 16, 1, 16 * sizeof(long)); 68 cio_debug_crw_id = debug_register("cio_crw", 8, 1, 8 * sizeof(long));
68 if (!cio_debug_crw_id) 69 if (!cio_debug_crw_id)
69 goto out_unregister; 70 goto out_unregister;
70 debug_register_view(cio_debug_crw_id, &debug_sprintf_view); 71 debug_register_view(cio_debug_crw_id, &debug_sprintf_view);
@@ -584,8 +585,6 @@ static irqreturn_t do_cio_interrupt(int irq, void *dummy)
584 return IRQ_HANDLED; 585 return IRQ_HANDLED;
585} 586}
586 587
587static struct irq_desc *irq_desc_io;
588
589static struct irqaction io_interrupt = { 588static struct irqaction io_interrupt = {
590 .name = "IO", 589 .name = "IO",
591 .handler = do_cio_interrupt, 590 .handler = do_cio_interrupt,
@@ -596,7 +595,6 @@ void __init init_cio_interrupts(void)
596 irq_set_chip_and_handler(IO_INTERRUPT, 595 irq_set_chip_and_handler(IO_INTERRUPT,
597 &dummy_irq_chip, handle_percpu_irq); 596 &dummy_irq_chip, handle_percpu_irq);
598 setup_irq(IO_INTERRUPT, &io_interrupt); 597 setup_irq(IO_INTERRUPT, &io_interrupt);
599 irq_desc_io = irq_to_desc(IO_INTERRUPT);
600} 598}
601 599
602#ifdef CONFIG_CCW_CONSOLE 600#ifdef CONFIG_CCW_CONSOLE
@@ -623,7 +621,7 @@ void cio_tsch(struct subchannel *sch)
623 local_bh_disable(); 621 local_bh_disable();
624 irq_enter(); 622 irq_enter();
625 } 623 }
626 kstat_incr_irqs_this_cpu(IO_INTERRUPT, irq_desc_io); 624 kstat_incr_irq_this_cpu(IO_INTERRUPT);
627 if (sch->driver && sch->driver->irq) 625 if (sch->driver && sch->driver->irq)
628 sch->driver->irq(sch); 626 sch->driver->irq(sch);
629 else 627 else
diff --git a/drivers/s390/cio/device.c b/drivers/s390/cio/device.c
index e9d783563cbb..d8d9b5b5cc56 100644
--- a/drivers/s390/cio/device.c
+++ b/drivers/s390/cio/device.c
@@ -1571,12 +1571,27 @@ out:
1571 return rc; 1571 return rc;
1572} 1572}
1573 1573
1574static void ccw_device_set_int_class(struct ccw_device *cdev)
1575{
1576 struct ccw_driver *cdrv = cdev->drv;
1577
1578 /* Note: we interpret class 0 in this context as an uninitialized
1579 * field since it translates to a non-I/O interrupt class. */
1580 if (cdrv->int_class != 0)
1581 cdev->private->int_class = cdrv->int_class;
1582 else
1583 cdev->private->int_class = IRQIO_CIO;
1584}
1585
1574#ifdef CONFIG_CCW_CONSOLE 1586#ifdef CONFIG_CCW_CONSOLE
1575static int ccw_device_console_enable(struct ccw_device *cdev, 1587int __init ccw_device_enable_console(struct ccw_device *cdev)
1576 struct subchannel *sch)
1577{ 1588{
1589 struct subchannel *sch = to_subchannel(cdev->dev.parent);
1578 int rc; 1590 int rc;
1579 1591
1592 if (!cdev->drv || !cdev->handler)
1593 return -EINVAL;
1594
1580 io_subchannel_init_fields(sch); 1595 io_subchannel_init_fields(sch);
1581 rc = cio_commit_config(sch); 1596 rc = cio_commit_config(sch);
1582 if (rc) 1597 if (rc)
@@ -1609,12 +1624,11 @@ out_unlock:
1609 return rc; 1624 return rc;
1610} 1625}
1611 1626
1612struct ccw_device *ccw_device_probe_console(void) 1627struct ccw_device * __init ccw_device_create_console(struct ccw_driver *drv)
1613{ 1628{
1614 struct io_subchannel_private *io_priv; 1629 struct io_subchannel_private *io_priv;
1615 struct ccw_device *cdev; 1630 struct ccw_device *cdev;
1616 struct subchannel *sch; 1631 struct subchannel *sch;
1617 int ret;
1618 1632
1619 sch = cio_probe_console(); 1633 sch = cio_probe_console();
1620 if (IS_ERR(sch)) 1634 if (IS_ERR(sch))
@@ -1631,18 +1645,23 @@ struct ccw_device *ccw_device_probe_console(void)
1631 kfree(io_priv); 1645 kfree(io_priv);
1632 return cdev; 1646 return cdev;
1633 } 1647 }
1648 cdev->drv = drv;
1634 set_io_private(sch, io_priv); 1649 set_io_private(sch, io_priv);
1635 ret = ccw_device_console_enable(cdev, sch); 1650 ccw_device_set_int_class(cdev);
1636 if (ret) {
1637 set_io_private(sch, NULL);
1638 put_device(&sch->dev);
1639 put_device(&cdev->dev);
1640 kfree(io_priv);
1641 return ERR_PTR(ret);
1642 }
1643 return cdev; 1651 return cdev;
1644} 1652}
1645 1653
1654void __init ccw_device_destroy_console(struct ccw_device *cdev)
1655{
1656 struct subchannel *sch = to_subchannel(cdev->dev.parent);
1657 struct io_subchannel_private *io_priv = to_io_private(sch);
1658
1659 set_io_private(sch, NULL);
1660 put_device(&sch->dev);
1661 put_device(&cdev->dev);
1662 kfree(io_priv);
1663}
1664
1646/** 1665/**
1647 * ccw_device_wait_idle() - busy wait for device to become idle 1666 * ccw_device_wait_idle() - busy wait for device to become idle
1648 * @cdev: ccw device 1667 * @cdev: ccw device
@@ -1726,15 +1745,8 @@ ccw_device_probe (struct device *dev)
1726 int ret; 1745 int ret;
1727 1746
1728 cdev->drv = cdrv; /* to let the driver call _set_online */ 1747 cdev->drv = cdrv; /* to let the driver call _set_online */
1729 /* Note: we interpret class 0 in this context as an uninitialized 1748 ccw_device_set_int_class(cdev);
1730 * field since it translates to a non-I/O interrupt class. */
1731 if (cdrv->int_class != 0)
1732 cdev->private->int_class = cdrv->int_class;
1733 else
1734 cdev->private->int_class = IRQIO_CIO;
1735
1736 ret = cdrv->probe ? cdrv->probe(cdev) : -ENODEV; 1749 ret = cdrv->probe ? cdrv->probe(cdev) : -ENODEV;
1737
1738 if (ret) { 1750 if (ret) {
1739 cdev->drv = NULL; 1751 cdev->drv = NULL;
1740 cdev->private->int_class = IRQIO_CIO; 1752 cdev->private->int_class = IRQIO_CIO;
diff --git a/drivers/s390/crypto/zcrypt_msgtype6.c b/drivers/s390/crypto/zcrypt_msgtype6.c
index dc542e0a3055..0bc91e46395a 100644
--- a/drivers/s390/crypto/zcrypt_msgtype6.c
+++ b/drivers/s390/crypto/zcrypt_msgtype6.c
@@ -311,7 +311,7 @@ static int XCRB_msg_to_type6CPRB_msgX(struct zcrypt_device *zdev,
311 } __packed * msg = ap_msg->message; 311 } __packed * msg = ap_msg->message;
312 312
313 int rcblen = CEIL4(xcRB->request_control_blk_length); 313 int rcblen = CEIL4(xcRB->request_control_blk_length);
314 int replylen; 314 int replylen, req_sumlen, resp_sumlen;
315 char *req_data = ap_msg->message + sizeof(struct type6_hdr) + rcblen; 315 char *req_data = ap_msg->message + sizeof(struct type6_hdr) + rcblen;
316 char *function_code; 316 char *function_code;
317 317
@@ -321,12 +321,34 @@ static int XCRB_msg_to_type6CPRB_msgX(struct zcrypt_device *zdev,
321 xcRB->request_data_length; 321 xcRB->request_data_length;
322 if (ap_msg->length > MSGTYPE06_MAX_MSG_SIZE) 322 if (ap_msg->length > MSGTYPE06_MAX_MSG_SIZE)
323 return -EINVAL; 323 return -EINVAL;
324
325 /* Overflow check
326 sum must be greater (or equal) than the largest operand */
327 req_sumlen = CEIL4(xcRB->request_control_blk_length) +
328 xcRB->request_data_length;
329 if ((CEIL4(xcRB->request_control_blk_length) <=
330 xcRB->request_data_length) ?
331 (req_sumlen < xcRB->request_data_length) :
332 (req_sumlen < CEIL4(xcRB->request_control_blk_length))) {
333 return -EINVAL;
334 }
335
324 replylen = sizeof(struct type86_fmt2_msg) + 336 replylen = sizeof(struct type86_fmt2_msg) +
325 CEIL4(xcRB->reply_control_blk_length) + 337 CEIL4(xcRB->reply_control_blk_length) +
326 xcRB->reply_data_length; 338 xcRB->reply_data_length;
327 if (replylen > MSGTYPE06_MAX_MSG_SIZE) 339 if (replylen > MSGTYPE06_MAX_MSG_SIZE)
328 return -EINVAL; 340 return -EINVAL;
329 341
342 /* Overflow check
343 sum must be greater (or equal) than the largest operand */
344 resp_sumlen = CEIL4(xcRB->reply_control_blk_length) +
345 xcRB->reply_data_length;
346 if ((CEIL4(xcRB->reply_control_blk_length) <= xcRB->reply_data_length) ?
347 (resp_sumlen < xcRB->reply_data_length) :
348 (resp_sumlen < CEIL4(xcRB->reply_control_blk_length))) {
349 return -EINVAL;
350 }
351
330 /* prepare type6 header */ 352 /* prepare type6 header */
331 msg->hdr = static_type6_hdrX; 353 msg->hdr = static_type6_hdrX;
332 memcpy(msg->hdr.agent_id , &(xcRB->agent_ID), sizeof(xcRB->agent_ID)); 354 memcpy(msg->hdr.agent_id , &(xcRB->agent_ID), sizeof(xcRB->agent_ID));
diff --git a/drivers/s390/net/qeth_core_main.c b/drivers/s390/net/qeth_core_main.c
index c3a83df07894..a0aff2eb247c 100644
--- a/drivers/s390/net/qeth_core_main.c
+++ b/drivers/s390/net/qeth_core_main.c
@@ -33,8 +33,8 @@ struct qeth_dbf_info qeth_dbf[QETH_DBF_INFOS] = {
33 /* N P A M L V H */ 33 /* N P A M L V H */
34 [QETH_DBF_SETUP] = {"qeth_setup", 34 [QETH_DBF_SETUP] = {"qeth_setup",
35 8, 1, 8, 5, &debug_hex_ascii_view, NULL}, 35 8, 1, 8, 5, &debug_hex_ascii_view, NULL},
36 [QETH_DBF_MSG] = {"qeth_msg", 36 [QETH_DBF_MSG] = {"qeth_msg", 8, 1, 11 * sizeof(long), 3,
37 8, 1, 128, 3, &debug_sprintf_view, NULL}, 37 &debug_sprintf_view, NULL},
38 [QETH_DBF_CTRL] = {"qeth_control", 38 [QETH_DBF_CTRL] = {"qeth_control",
39 8, 1, QETH_DBF_CTRL_LEN, 5, &debug_hex_ascii_view, NULL}, 39 8, 1, QETH_DBF_CTRL_LEN, 5, &debug_hex_ascii_view, NULL},
40}; 40};
@@ -1660,7 +1660,6 @@ int qeth_qdio_clear_card(struct qeth_card *card, int use_halt)
1660 QDIO_FLAG_CLEANUP_USING_CLEAR); 1660 QDIO_FLAG_CLEANUP_USING_CLEAR);
1661 if (rc) 1661 if (rc)
1662 QETH_CARD_TEXT_(card, 3, "1err%d", rc); 1662 QETH_CARD_TEXT_(card, 3, "1err%d", rc);
1663 qdio_free(CARD_DDEV(card));
1664 atomic_set(&card->qdio.state, QETH_QDIO_ALLOCATED); 1663 atomic_set(&card->qdio.state, QETH_QDIO_ALLOCATED);
1665 break; 1664 break;
1666 case QETH_QDIO_CLEANING: 1665 case QETH_QDIO_CLEANING:
@@ -2605,6 +2604,7 @@ static int qeth_mpc_initialize(struct qeth_card *card)
2605 return 0; 2604 return 0;
2606out_qdio: 2605out_qdio:
2607 qeth_qdio_clear_card(card, card->info.type != QETH_CARD_TYPE_IQD); 2606 qeth_qdio_clear_card(card, card->info.type != QETH_CARD_TYPE_IQD);
2607 qdio_free(CARD_DDEV(card));
2608 return rc; 2608 return rc;
2609} 2609}
2610 2610
@@ -4906,9 +4906,11 @@ retry:
4906 if (retries < 3) 4906 if (retries < 3)
4907 QETH_DBF_MESSAGE(2, "%s Retrying to do IDX activates.\n", 4907 QETH_DBF_MESSAGE(2, "%s Retrying to do IDX activates.\n",
4908 dev_name(&card->gdev->dev)); 4908 dev_name(&card->gdev->dev));
4909 rc = qeth_qdio_clear_card(card, card->info.type != QETH_CARD_TYPE_IQD);
4909 ccw_device_set_offline(CARD_DDEV(card)); 4910 ccw_device_set_offline(CARD_DDEV(card));
4910 ccw_device_set_offline(CARD_WDEV(card)); 4911 ccw_device_set_offline(CARD_WDEV(card));
4911 ccw_device_set_offline(CARD_RDEV(card)); 4912 ccw_device_set_offline(CARD_RDEV(card));
4913 qdio_free(CARD_DDEV(card));
4912 rc = ccw_device_set_online(CARD_RDEV(card)); 4914 rc = ccw_device_set_online(CARD_RDEV(card));
4913 if (rc) 4915 if (rc)
4914 goto retriable; 4916 goto retriable;
@@ -4918,7 +4920,6 @@ retry:
4918 rc = ccw_device_set_online(CARD_DDEV(card)); 4920 rc = ccw_device_set_online(CARD_DDEV(card));
4919 if (rc) 4921 if (rc)
4920 goto retriable; 4922 goto retriable;
4921 rc = qeth_qdio_clear_card(card, card->info.type != QETH_CARD_TYPE_IQD);
4922retriable: 4923retriable:
4923 if (rc == -ERESTARTSYS) { 4924 if (rc == -ERESTARTSYS) {
4924 QETH_DBF_TEXT(SETUP, 2, "break1"); 4925 QETH_DBF_TEXT(SETUP, 2, "break1");
diff --git a/drivers/s390/net/qeth_l2_main.c b/drivers/s390/net/qeth_l2_main.c
index 0710550093ce..908d82529ee9 100644
--- a/drivers/s390/net/qeth_l2_main.c
+++ b/drivers/s390/net/qeth_l2_main.c
@@ -1091,6 +1091,7 @@ out_remove:
1091 ccw_device_set_offline(CARD_DDEV(card)); 1091 ccw_device_set_offline(CARD_DDEV(card));
1092 ccw_device_set_offline(CARD_WDEV(card)); 1092 ccw_device_set_offline(CARD_WDEV(card));
1093 ccw_device_set_offline(CARD_RDEV(card)); 1093 ccw_device_set_offline(CARD_RDEV(card));
1094 qdio_free(CARD_DDEV(card));
1094 if (recover_flag == CARD_STATE_RECOVER) 1095 if (recover_flag == CARD_STATE_RECOVER)
1095 card->state = CARD_STATE_RECOVER; 1096 card->state = CARD_STATE_RECOVER;
1096 else 1097 else
@@ -1132,6 +1133,7 @@ static int __qeth_l2_set_offline(struct ccwgroup_device *cgdev,
1132 rc = (rc2) ? rc2 : rc3; 1133 rc = (rc2) ? rc2 : rc3;
1133 if (rc) 1134 if (rc)
1134 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc); 1135 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
1136 qdio_free(CARD_DDEV(card));
1135 if (recover_flag == CARD_STATE_UP) 1137 if (recover_flag == CARD_STATE_UP)
1136 card->state = CARD_STATE_RECOVER; 1138 card->state = CARD_STATE_RECOVER;
1137 /* let user_space know that device is offline */ 1139 /* let user_space know that device is offline */
@@ -1194,6 +1196,7 @@ static void qeth_l2_shutdown(struct ccwgroup_device *gdev)
1194 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM); 1196 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
1195 qeth_qdio_clear_card(card, 0); 1197 qeth_qdio_clear_card(card, 0);
1196 qeth_clear_qdio_buffers(card); 1198 qeth_clear_qdio_buffers(card);
1199 qdio_free(CARD_DDEV(card));
1197} 1200}
1198 1201
1199static int qeth_l2_pm_suspend(struct ccwgroup_device *gdev) 1202static int qeth_l2_pm_suspend(struct ccwgroup_device *gdev)
diff --git a/drivers/s390/net/qeth_l3_main.c b/drivers/s390/net/qeth_l3_main.c
index 0f430424c3b8..3524d34ff694 100644
--- a/drivers/s390/net/qeth_l3_main.c
+++ b/drivers/s390/net/qeth_l3_main.c
@@ -3447,6 +3447,7 @@ out_remove:
3447 ccw_device_set_offline(CARD_DDEV(card)); 3447 ccw_device_set_offline(CARD_DDEV(card));
3448 ccw_device_set_offline(CARD_WDEV(card)); 3448 ccw_device_set_offline(CARD_WDEV(card));
3449 ccw_device_set_offline(CARD_RDEV(card)); 3449 ccw_device_set_offline(CARD_RDEV(card));
3450 qdio_free(CARD_DDEV(card));
3450 if (recover_flag == CARD_STATE_RECOVER) 3451 if (recover_flag == CARD_STATE_RECOVER)
3451 card->state = CARD_STATE_RECOVER; 3452 card->state = CARD_STATE_RECOVER;
3452 else 3453 else
@@ -3493,6 +3494,7 @@ static int __qeth_l3_set_offline(struct ccwgroup_device *cgdev,
3493 rc = (rc2) ? rc2 : rc3; 3494 rc = (rc2) ? rc2 : rc3;
3494 if (rc) 3495 if (rc)
3495 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc); 3496 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
3497 qdio_free(CARD_DDEV(card));
3496 if (recover_flag == CARD_STATE_UP) 3498 if (recover_flag == CARD_STATE_UP)
3497 card->state = CARD_STATE_RECOVER; 3499 card->state = CARD_STATE_RECOVER;
3498 /* let user_space know that device is offline */ 3500 /* let user_space know that device is offline */
@@ -3545,6 +3547,7 @@ static void qeth_l3_shutdown(struct ccwgroup_device *gdev)
3545 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM); 3547 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
3546 qeth_qdio_clear_card(card, 0); 3548 qeth_qdio_clear_card(card, 0);
3547 qeth_clear_qdio_buffers(card); 3549 qeth_clear_qdio_buffers(card);
3550 qdio_free(CARD_DDEV(card));
3548} 3551}
3549 3552
3550static int qeth_l3_pm_suspend(struct ccwgroup_device *gdev) 3553static int qeth_l3_pm_suspend(struct ccwgroup_device *gdev)
diff --git a/drivers/scsi/atari_scsi.c b/drivers/scsi/atari_scsi.c
index a3e6c8a3ff0f..296c936cc03c 100644
--- a/drivers/scsi/atari_scsi.c
+++ b/drivers/scsi/atari_scsi.c
@@ -90,6 +90,7 @@
90#include <linux/init.h> 90#include <linux/init.h>
91#include <linux/nvram.h> 91#include <linux/nvram.h>
92#include <linux/bitops.h> 92#include <linux/bitops.h>
93#include <linux/wait.h>
93 94
94#include <asm/setup.h> 95#include <asm/setup.h>
95#include <asm/atarihw.h> 96#include <asm/atarihw.h>
@@ -549,8 +550,10 @@ static void falcon_get_lock(void)
549 550
550 local_irq_save(flags); 551 local_irq_save(flags);
551 552
552 while (!in_irq() && falcon_got_lock && stdma_others_waiting()) 553 wait_event_cmd(falcon_fairness_wait,
553 sleep_on(&falcon_fairness_wait); 554 in_interrupt() || !falcon_got_lock || !stdma_others_waiting(),
555 local_irq_restore(flags),
556 local_irq_save(flags));
554 557
555 while (!falcon_got_lock) { 558 while (!falcon_got_lock) {
556 if (in_irq()) 559 if (in_irq())
@@ -562,7 +565,10 @@ static void falcon_get_lock(void)
562 falcon_trying_lock = 0; 565 falcon_trying_lock = 0;
563 wake_up(&falcon_try_wait); 566 wake_up(&falcon_try_wait);
564 } else { 567 } else {
565 sleep_on(&falcon_try_wait); 568 wait_event_cmd(falcon_try_wait,
569 falcon_got_lock && !falcon_trying_lock,
570 local_irq_restore(flags),
571 local_irq_save(flags));
566 } 572 }
567 } 573 }
568 574
diff --git a/drivers/scsi/be2iscsi/be_main.c b/drivers/scsi/be2iscsi/be_main.c
index 1f375051483a..5642a9b250c2 100644
--- a/drivers/scsi/be2iscsi/be_main.c
+++ b/drivers/scsi/be2iscsi/be_main.c
@@ -325,7 +325,7 @@ static int beiscsi_eh_device_reset(struct scsi_cmnd *sc)
325 if (!abrt_task->sc || abrt_task->state == ISCSI_TASK_FREE) 325 if (!abrt_task->sc || abrt_task->state == ISCSI_TASK_FREE)
326 continue; 326 continue;
327 327
328 if (abrt_task->sc->device->lun != abrt_task->sc->device->lun) 328 if (sc->device->lun != abrt_task->sc->device->lun)
329 continue; 329 continue;
330 330
331 /* Invalidate WRB Posted for this Task */ 331 /* Invalidate WRB Posted for this Task */
diff --git a/drivers/scsi/bnx2fc/bnx2fc_io.c b/drivers/scsi/bnx2fc/bnx2fc_io.c
index ed880891cb7c..e9279a8c1e1c 100644
--- a/drivers/scsi/bnx2fc/bnx2fc_io.c
+++ b/drivers/scsi/bnx2fc/bnx2fc_io.c
@@ -594,13 +594,13 @@ static void bnx2fc_free_mp_resc(struct bnx2fc_cmd *io_req)
594 mp_req->mp_resp_bd = NULL; 594 mp_req->mp_resp_bd = NULL;
595 } 595 }
596 if (mp_req->req_buf) { 596 if (mp_req->req_buf) {
597 dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE, 597 dma_free_coherent(&hba->pcidev->dev, CNIC_PAGE_SIZE,
598 mp_req->req_buf, 598 mp_req->req_buf,
599 mp_req->req_buf_dma); 599 mp_req->req_buf_dma);
600 mp_req->req_buf = NULL; 600 mp_req->req_buf = NULL;
601 } 601 }
602 if (mp_req->resp_buf) { 602 if (mp_req->resp_buf) {
603 dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE, 603 dma_free_coherent(&hba->pcidev->dev, CNIC_PAGE_SIZE,
604 mp_req->resp_buf, 604 mp_req->resp_buf,
605 mp_req->resp_buf_dma); 605 mp_req->resp_buf_dma);
606 mp_req->resp_buf = NULL; 606 mp_req->resp_buf = NULL;
@@ -622,7 +622,7 @@ int bnx2fc_init_mp_req(struct bnx2fc_cmd *io_req)
622 622
623 mp_req->req_len = sizeof(struct fcp_cmnd); 623 mp_req->req_len = sizeof(struct fcp_cmnd);
624 io_req->data_xfer_len = mp_req->req_len; 624 io_req->data_xfer_len = mp_req->req_len;
625 mp_req->req_buf = dma_alloc_coherent(&hba->pcidev->dev, PAGE_SIZE, 625 mp_req->req_buf = dma_alloc_coherent(&hba->pcidev->dev, CNIC_PAGE_SIZE,
626 &mp_req->req_buf_dma, 626 &mp_req->req_buf_dma,
627 GFP_ATOMIC); 627 GFP_ATOMIC);
628 if (!mp_req->req_buf) { 628 if (!mp_req->req_buf) {
@@ -631,7 +631,7 @@ int bnx2fc_init_mp_req(struct bnx2fc_cmd *io_req)
631 return FAILED; 631 return FAILED;
632 } 632 }
633 633
634 mp_req->resp_buf = dma_alloc_coherent(&hba->pcidev->dev, PAGE_SIZE, 634 mp_req->resp_buf = dma_alloc_coherent(&hba->pcidev->dev, CNIC_PAGE_SIZE,
635 &mp_req->resp_buf_dma, 635 &mp_req->resp_buf_dma,
636 GFP_ATOMIC); 636 GFP_ATOMIC);
637 if (!mp_req->resp_buf) { 637 if (!mp_req->resp_buf) {
@@ -639,8 +639,8 @@ int bnx2fc_init_mp_req(struct bnx2fc_cmd *io_req)
639 bnx2fc_free_mp_resc(io_req); 639 bnx2fc_free_mp_resc(io_req);
640 return FAILED; 640 return FAILED;
641 } 641 }
642 memset(mp_req->req_buf, 0, PAGE_SIZE); 642 memset(mp_req->req_buf, 0, CNIC_PAGE_SIZE);
643 memset(mp_req->resp_buf, 0, PAGE_SIZE); 643 memset(mp_req->resp_buf, 0, CNIC_PAGE_SIZE);
644 644
645 /* Allocate and map mp_req_bd and mp_resp_bd */ 645 /* Allocate and map mp_req_bd and mp_resp_bd */
646 sz = sizeof(struct fcoe_bd_ctx); 646 sz = sizeof(struct fcoe_bd_ctx);
@@ -665,7 +665,7 @@ int bnx2fc_init_mp_req(struct bnx2fc_cmd *io_req)
665 mp_req_bd = mp_req->mp_req_bd; 665 mp_req_bd = mp_req->mp_req_bd;
666 mp_req_bd->buf_addr_lo = (u32)addr & 0xffffffff; 666 mp_req_bd->buf_addr_lo = (u32)addr & 0xffffffff;
667 mp_req_bd->buf_addr_hi = (u32)((u64)addr >> 32); 667 mp_req_bd->buf_addr_hi = (u32)((u64)addr >> 32);
668 mp_req_bd->buf_len = PAGE_SIZE; 668 mp_req_bd->buf_len = CNIC_PAGE_SIZE;
669 mp_req_bd->flags = 0; 669 mp_req_bd->flags = 0;
670 670
671 /* 671 /*
@@ -677,7 +677,7 @@ int bnx2fc_init_mp_req(struct bnx2fc_cmd *io_req)
677 addr = mp_req->resp_buf_dma; 677 addr = mp_req->resp_buf_dma;
678 mp_resp_bd->buf_addr_lo = (u32)addr & 0xffffffff; 678 mp_resp_bd->buf_addr_lo = (u32)addr & 0xffffffff;
679 mp_resp_bd->buf_addr_hi = (u32)((u64)addr >> 32); 679 mp_resp_bd->buf_addr_hi = (u32)((u64)addr >> 32);
680 mp_resp_bd->buf_len = PAGE_SIZE; 680 mp_resp_bd->buf_len = CNIC_PAGE_SIZE;
681 mp_resp_bd->flags = 0; 681 mp_resp_bd->flags = 0;
682 682
683 return SUCCESS; 683 return SUCCESS;
diff --git a/drivers/scsi/bnx2fc/bnx2fc_tgt.c b/drivers/scsi/bnx2fc/bnx2fc_tgt.c
index 4d93177dfb53..d9bae5672273 100644
--- a/drivers/scsi/bnx2fc/bnx2fc_tgt.c
+++ b/drivers/scsi/bnx2fc/bnx2fc_tgt.c
@@ -673,7 +673,8 @@ static int bnx2fc_alloc_session_resc(struct bnx2fc_hba *hba,
673 673
674 /* Allocate and map SQ */ 674 /* Allocate and map SQ */
675 tgt->sq_mem_size = tgt->max_sqes * BNX2FC_SQ_WQE_SIZE; 675 tgt->sq_mem_size = tgt->max_sqes * BNX2FC_SQ_WQE_SIZE;
676 tgt->sq_mem_size = (tgt->sq_mem_size + (PAGE_SIZE - 1)) & PAGE_MASK; 676 tgt->sq_mem_size = (tgt->sq_mem_size + (CNIC_PAGE_SIZE - 1)) &
677 CNIC_PAGE_MASK;
677 678
678 tgt->sq = dma_alloc_coherent(&hba->pcidev->dev, tgt->sq_mem_size, 679 tgt->sq = dma_alloc_coherent(&hba->pcidev->dev, tgt->sq_mem_size,
679 &tgt->sq_dma, GFP_KERNEL); 680 &tgt->sq_dma, GFP_KERNEL);
@@ -686,7 +687,8 @@ static int bnx2fc_alloc_session_resc(struct bnx2fc_hba *hba,
686 687
687 /* Allocate and map CQ */ 688 /* Allocate and map CQ */
688 tgt->cq_mem_size = tgt->max_cqes * BNX2FC_CQ_WQE_SIZE; 689 tgt->cq_mem_size = tgt->max_cqes * BNX2FC_CQ_WQE_SIZE;
689 tgt->cq_mem_size = (tgt->cq_mem_size + (PAGE_SIZE - 1)) & PAGE_MASK; 690 tgt->cq_mem_size = (tgt->cq_mem_size + (CNIC_PAGE_SIZE - 1)) &
691 CNIC_PAGE_MASK;
690 692
691 tgt->cq = dma_alloc_coherent(&hba->pcidev->dev, tgt->cq_mem_size, 693 tgt->cq = dma_alloc_coherent(&hba->pcidev->dev, tgt->cq_mem_size,
692 &tgt->cq_dma, GFP_KERNEL); 694 &tgt->cq_dma, GFP_KERNEL);
@@ -699,7 +701,8 @@ static int bnx2fc_alloc_session_resc(struct bnx2fc_hba *hba,
699 701
700 /* Allocate and map RQ and RQ PBL */ 702 /* Allocate and map RQ and RQ PBL */
701 tgt->rq_mem_size = tgt->max_rqes * BNX2FC_RQ_WQE_SIZE; 703 tgt->rq_mem_size = tgt->max_rqes * BNX2FC_RQ_WQE_SIZE;
702 tgt->rq_mem_size = (tgt->rq_mem_size + (PAGE_SIZE - 1)) & PAGE_MASK; 704 tgt->rq_mem_size = (tgt->rq_mem_size + (CNIC_PAGE_SIZE - 1)) &
705 CNIC_PAGE_MASK;
703 706
704 tgt->rq = dma_alloc_coherent(&hba->pcidev->dev, tgt->rq_mem_size, 707 tgt->rq = dma_alloc_coherent(&hba->pcidev->dev, tgt->rq_mem_size,
705 &tgt->rq_dma, GFP_KERNEL); 708 &tgt->rq_dma, GFP_KERNEL);
@@ -710,8 +713,9 @@ static int bnx2fc_alloc_session_resc(struct bnx2fc_hba *hba,
710 } 713 }
711 memset(tgt->rq, 0, tgt->rq_mem_size); 714 memset(tgt->rq, 0, tgt->rq_mem_size);
712 715
713 tgt->rq_pbl_size = (tgt->rq_mem_size / PAGE_SIZE) * sizeof(void *); 716 tgt->rq_pbl_size = (tgt->rq_mem_size / CNIC_PAGE_SIZE) * sizeof(void *);
714 tgt->rq_pbl_size = (tgt->rq_pbl_size + (PAGE_SIZE - 1)) & PAGE_MASK; 717 tgt->rq_pbl_size = (tgt->rq_pbl_size + (CNIC_PAGE_SIZE - 1)) &
718 CNIC_PAGE_MASK;
715 719
716 tgt->rq_pbl = dma_alloc_coherent(&hba->pcidev->dev, tgt->rq_pbl_size, 720 tgt->rq_pbl = dma_alloc_coherent(&hba->pcidev->dev, tgt->rq_pbl_size,
717 &tgt->rq_pbl_dma, GFP_KERNEL); 721 &tgt->rq_pbl_dma, GFP_KERNEL);
@@ -722,7 +726,7 @@ static int bnx2fc_alloc_session_resc(struct bnx2fc_hba *hba,
722 } 726 }
723 727
724 memset(tgt->rq_pbl, 0, tgt->rq_pbl_size); 728 memset(tgt->rq_pbl, 0, tgt->rq_pbl_size);
725 num_pages = tgt->rq_mem_size / PAGE_SIZE; 729 num_pages = tgt->rq_mem_size / CNIC_PAGE_SIZE;
726 page = tgt->rq_dma; 730 page = tgt->rq_dma;
727 pbl = (u32 *)tgt->rq_pbl; 731 pbl = (u32 *)tgt->rq_pbl;
728 732
@@ -731,13 +735,13 @@ static int bnx2fc_alloc_session_resc(struct bnx2fc_hba *hba,
731 pbl++; 735 pbl++;
732 *pbl = (u32)((u64)page >> 32); 736 *pbl = (u32)((u64)page >> 32);
733 pbl++; 737 pbl++;
734 page += PAGE_SIZE; 738 page += CNIC_PAGE_SIZE;
735 } 739 }
736 740
737 /* Allocate and map XFERQ */ 741 /* Allocate and map XFERQ */
738 tgt->xferq_mem_size = tgt->max_sqes * BNX2FC_XFERQ_WQE_SIZE; 742 tgt->xferq_mem_size = tgt->max_sqes * BNX2FC_XFERQ_WQE_SIZE;
739 tgt->xferq_mem_size = (tgt->xferq_mem_size + (PAGE_SIZE - 1)) & 743 tgt->xferq_mem_size = (tgt->xferq_mem_size + (CNIC_PAGE_SIZE - 1)) &
740 PAGE_MASK; 744 CNIC_PAGE_MASK;
741 745
742 tgt->xferq = dma_alloc_coherent(&hba->pcidev->dev, tgt->xferq_mem_size, 746 tgt->xferq = dma_alloc_coherent(&hba->pcidev->dev, tgt->xferq_mem_size,
743 &tgt->xferq_dma, GFP_KERNEL); 747 &tgt->xferq_dma, GFP_KERNEL);
@@ -750,8 +754,8 @@ static int bnx2fc_alloc_session_resc(struct bnx2fc_hba *hba,
750 754
751 /* Allocate and map CONFQ & CONFQ PBL */ 755 /* Allocate and map CONFQ & CONFQ PBL */
752 tgt->confq_mem_size = tgt->max_sqes * BNX2FC_CONFQ_WQE_SIZE; 756 tgt->confq_mem_size = tgt->max_sqes * BNX2FC_CONFQ_WQE_SIZE;
753 tgt->confq_mem_size = (tgt->confq_mem_size + (PAGE_SIZE - 1)) & 757 tgt->confq_mem_size = (tgt->confq_mem_size + (CNIC_PAGE_SIZE - 1)) &
754 PAGE_MASK; 758 CNIC_PAGE_MASK;
755 759
756 tgt->confq = dma_alloc_coherent(&hba->pcidev->dev, tgt->confq_mem_size, 760 tgt->confq = dma_alloc_coherent(&hba->pcidev->dev, tgt->confq_mem_size,
757 &tgt->confq_dma, GFP_KERNEL); 761 &tgt->confq_dma, GFP_KERNEL);
@@ -763,9 +767,9 @@ static int bnx2fc_alloc_session_resc(struct bnx2fc_hba *hba,
763 memset(tgt->confq, 0, tgt->confq_mem_size); 767 memset(tgt->confq, 0, tgt->confq_mem_size);
764 768
765 tgt->confq_pbl_size = 769 tgt->confq_pbl_size =
766 (tgt->confq_mem_size / PAGE_SIZE) * sizeof(void *); 770 (tgt->confq_mem_size / CNIC_PAGE_SIZE) * sizeof(void *);
767 tgt->confq_pbl_size = 771 tgt->confq_pbl_size =
768 (tgt->confq_pbl_size + (PAGE_SIZE - 1)) & PAGE_MASK; 772 (tgt->confq_pbl_size + (CNIC_PAGE_SIZE - 1)) & CNIC_PAGE_MASK;
769 773
770 tgt->confq_pbl = dma_alloc_coherent(&hba->pcidev->dev, 774 tgt->confq_pbl = dma_alloc_coherent(&hba->pcidev->dev,
771 tgt->confq_pbl_size, 775 tgt->confq_pbl_size,
@@ -777,7 +781,7 @@ static int bnx2fc_alloc_session_resc(struct bnx2fc_hba *hba,
777 } 781 }
778 782
779 memset(tgt->confq_pbl, 0, tgt->confq_pbl_size); 783 memset(tgt->confq_pbl, 0, tgt->confq_pbl_size);
780 num_pages = tgt->confq_mem_size / PAGE_SIZE; 784 num_pages = tgt->confq_mem_size / CNIC_PAGE_SIZE;
781 page = tgt->confq_dma; 785 page = tgt->confq_dma;
782 pbl = (u32 *)tgt->confq_pbl; 786 pbl = (u32 *)tgt->confq_pbl;
783 787
@@ -786,7 +790,7 @@ static int bnx2fc_alloc_session_resc(struct bnx2fc_hba *hba,
786 pbl++; 790 pbl++;
787 *pbl = (u32)((u64)page >> 32); 791 *pbl = (u32)((u64)page >> 32);
788 pbl++; 792 pbl++;
789 page += PAGE_SIZE; 793 page += CNIC_PAGE_SIZE;
790 } 794 }
791 795
792 /* Allocate and map ConnDB */ 796 /* Allocate and map ConnDB */
@@ -805,8 +809,8 @@ static int bnx2fc_alloc_session_resc(struct bnx2fc_hba *hba,
805 809
806 /* Allocate and map LCQ */ 810 /* Allocate and map LCQ */
807 tgt->lcq_mem_size = (tgt->max_sqes + 8) * BNX2FC_SQ_WQE_SIZE; 811 tgt->lcq_mem_size = (tgt->max_sqes + 8) * BNX2FC_SQ_WQE_SIZE;
808 tgt->lcq_mem_size = (tgt->lcq_mem_size + (PAGE_SIZE - 1)) & 812 tgt->lcq_mem_size = (tgt->lcq_mem_size + (CNIC_PAGE_SIZE - 1)) &
809 PAGE_MASK; 813 CNIC_PAGE_MASK;
810 814
811 tgt->lcq = dma_alloc_coherent(&hba->pcidev->dev, tgt->lcq_mem_size, 815 tgt->lcq = dma_alloc_coherent(&hba->pcidev->dev, tgt->lcq_mem_size,
812 &tgt->lcq_dma, GFP_KERNEL); 816 &tgt->lcq_dma, GFP_KERNEL);
diff --git a/drivers/scsi/bnx2i/bnx2i_hwi.c b/drivers/scsi/bnx2i/bnx2i_hwi.c
index e4cf23df4b4f..b87a1933f880 100644
--- a/drivers/scsi/bnx2i/bnx2i_hwi.c
+++ b/drivers/scsi/bnx2i/bnx2i_hwi.c
@@ -61,7 +61,7 @@ static void bnx2i_adjust_qp_size(struct bnx2i_hba *hba)
61 * yield integral num of page buffers 61 * yield integral num of page buffers
62 */ 62 */
63 /* adjust SQ */ 63 /* adjust SQ */
64 num_elements_per_pg = PAGE_SIZE / BNX2I_SQ_WQE_SIZE; 64 num_elements_per_pg = CNIC_PAGE_SIZE / BNX2I_SQ_WQE_SIZE;
65 if (hba->max_sqes < num_elements_per_pg) 65 if (hba->max_sqes < num_elements_per_pg)
66 hba->max_sqes = num_elements_per_pg; 66 hba->max_sqes = num_elements_per_pg;
67 else if (hba->max_sqes % num_elements_per_pg) 67 else if (hba->max_sqes % num_elements_per_pg)
@@ -69,7 +69,7 @@ static void bnx2i_adjust_qp_size(struct bnx2i_hba *hba)
69 ~(num_elements_per_pg - 1); 69 ~(num_elements_per_pg - 1);
70 70
71 /* adjust CQ */ 71 /* adjust CQ */
72 num_elements_per_pg = PAGE_SIZE / BNX2I_CQE_SIZE; 72 num_elements_per_pg = CNIC_PAGE_SIZE / BNX2I_CQE_SIZE;
73 if (hba->max_cqes < num_elements_per_pg) 73 if (hba->max_cqes < num_elements_per_pg)
74 hba->max_cqes = num_elements_per_pg; 74 hba->max_cqes = num_elements_per_pg;
75 else if (hba->max_cqes % num_elements_per_pg) 75 else if (hba->max_cqes % num_elements_per_pg)
@@ -77,7 +77,7 @@ static void bnx2i_adjust_qp_size(struct bnx2i_hba *hba)
77 ~(num_elements_per_pg - 1); 77 ~(num_elements_per_pg - 1);
78 78
79 /* adjust RQ */ 79 /* adjust RQ */
80 num_elements_per_pg = PAGE_SIZE / BNX2I_RQ_WQE_SIZE; 80 num_elements_per_pg = CNIC_PAGE_SIZE / BNX2I_RQ_WQE_SIZE;
81 if (hba->max_rqes < num_elements_per_pg) 81 if (hba->max_rqes < num_elements_per_pg)
82 hba->max_rqes = num_elements_per_pg; 82 hba->max_rqes = num_elements_per_pg;
83 else if (hba->max_rqes % num_elements_per_pg) 83 else if (hba->max_rqes % num_elements_per_pg)
@@ -959,7 +959,7 @@ static void setup_qp_page_tables(struct bnx2i_endpoint *ep)
959 959
960 /* SQ page table */ 960 /* SQ page table */
961 memset(ep->qp.sq_pgtbl_virt, 0, ep->qp.sq_pgtbl_size); 961 memset(ep->qp.sq_pgtbl_virt, 0, ep->qp.sq_pgtbl_size);
962 num_pages = ep->qp.sq_mem_size / PAGE_SIZE; 962 num_pages = ep->qp.sq_mem_size / CNIC_PAGE_SIZE;
963 page = ep->qp.sq_phys; 963 page = ep->qp.sq_phys;
964 964
965 if (cnic_dev_10g) 965 if (cnic_dev_10g)
@@ -973,7 +973,7 @@ static void setup_qp_page_tables(struct bnx2i_endpoint *ep)
973 ptbl++; 973 ptbl++;
974 *ptbl = (u32) ((u64) page >> 32); 974 *ptbl = (u32) ((u64) page >> 32);
975 ptbl++; 975 ptbl++;
976 page += PAGE_SIZE; 976 page += CNIC_PAGE_SIZE;
977 } else { 977 } else {
978 /* PTE is written in big endian format for 978 /* PTE is written in big endian format for
979 * 5706/5708/5709 devices */ 979 * 5706/5708/5709 devices */
@@ -981,13 +981,13 @@ static void setup_qp_page_tables(struct bnx2i_endpoint *ep)
981 ptbl++; 981 ptbl++;
982 *ptbl = (u32) page; 982 *ptbl = (u32) page;
983 ptbl++; 983 ptbl++;
984 page += PAGE_SIZE; 984 page += CNIC_PAGE_SIZE;
985 } 985 }
986 } 986 }
987 987
988 /* RQ page table */ 988 /* RQ page table */
989 memset(ep->qp.rq_pgtbl_virt, 0, ep->qp.rq_pgtbl_size); 989 memset(ep->qp.rq_pgtbl_virt, 0, ep->qp.rq_pgtbl_size);
990 num_pages = ep->qp.rq_mem_size / PAGE_SIZE; 990 num_pages = ep->qp.rq_mem_size / CNIC_PAGE_SIZE;
991 page = ep->qp.rq_phys; 991 page = ep->qp.rq_phys;
992 992
993 if (cnic_dev_10g) 993 if (cnic_dev_10g)
@@ -1001,7 +1001,7 @@ static void setup_qp_page_tables(struct bnx2i_endpoint *ep)
1001 ptbl++; 1001 ptbl++;
1002 *ptbl = (u32) ((u64) page >> 32); 1002 *ptbl = (u32) ((u64) page >> 32);
1003 ptbl++; 1003 ptbl++;
1004 page += PAGE_SIZE; 1004 page += CNIC_PAGE_SIZE;
1005 } else { 1005 } else {
1006 /* PTE is written in big endian format for 1006 /* PTE is written in big endian format for
1007 * 5706/5708/5709 devices */ 1007 * 5706/5708/5709 devices */
@@ -1009,13 +1009,13 @@ static void setup_qp_page_tables(struct bnx2i_endpoint *ep)
1009 ptbl++; 1009 ptbl++;
1010 *ptbl = (u32) page; 1010 *ptbl = (u32) page;
1011 ptbl++; 1011 ptbl++;
1012 page += PAGE_SIZE; 1012 page += CNIC_PAGE_SIZE;
1013 } 1013 }
1014 } 1014 }
1015 1015
1016 /* CQ page table */ 1016 /* CQ page table */
1017 memset(ep->qp.cq_pgtbl_virt, 0, ep->qp.cq_pgtbl_size); 1017 memset(ep->qp.cq_pgtbl_virt, 0, ep->qp.cq_pgtbl_size);
1018 num_pages = ep->qp.cq_mem_size / PAGE_SIZE; 1018 num_pages = ep->qp.cq_mem_size / CNIC_PAGE_SIZE;
1019 page = ep->qp.cq_phys; 1019 page = ep->qp.cq_phys;
1020 1020
1021 if (cnic_dev_10g) 1021 if (cnic_dev_10g)
@@ -1029,7 +1029,7 @@ static void setup_qp_page_tables(struct bnx2i_endpoint *ep)
1029 ptbl++; 1029 ptbl++;
1030 *ptbl = (u32) ((u64) page >> 32); 1030 *ptbl = (u32) ((u64) page >> 32);
1031 ptbl++; 1031 ptbl++;
1032 page += PAGE_SIZE; 1032 page += CNIC_PAGE_SIZE;
1033 } else { 1033 } else {
1034 /* PTE is written in big endian format for 1034 /* PTE is written in big endian format for
1035 * 5706/5708/5709 devices */ 1035 * 5706/5708/5709 devices */
@@ -1037,7 +1037,7 @@ static void setup_qp_page_tables(struct bnx2i_endpoint *ep)
1037 ptbl++; 1037 ptbl++;
1038 *ptbl = (u32) page; 1038 *ptbl = (u32) page;
1039 ptbl++; 1039 ptbl++;
1040 page += PAGE_SIZE; 1040 page += CNIC_PAGE_SIZE;
1041 } 1041 }
1042 } 1042 }
1043} 1043}
@@ -1064,11 +1064,11 @@ int bnx2i_alloc_qp_resc(struct bnx2i_hba *hba, struct bnx2i_endpoint *ep)
1064 /* Allocate page table memory for SQ which is page aligned */ 1064 /* Allocate page table memory for SQ which is page aligned */
1065 ep->qp.sq_mem_size = hba->max_sqes * BNX2I_SQ_WQE_SIZE; 1065 ep->qp.sq_mem_size = hba->max_sqes * BNX2I_SQ_WQE_SIZE;
1066 ep->qp.sq_mem_size = 1066 ep->qp.sq_mem_size =
1067 (ep->qp.sq_mem_size + (PAGE_SIZE - 1)) & PAGE_MASK; 1067 (ep->qp.sq_mem_size + (CNIC_PAGE_SIZE - 1)) & CNIC_PAGE_MASK;
1068 ep->qp.sq_pgtbl_size = 1068 ep->qp.sq_pgtbl_size =
1069 (ep->qp.sq_mem_size / PAGE_SIZE) * sizeof(void *); 1069 (ep->qp.sq_mem_size / CNIC_PAGE_SIZE) * sizeof(void *);
1070 ep->qp.sq_pgtbl_size = 1070 ep->qp.sq_pgtbl_size =
1071 (ep->qp.sq_pgtbl_size + (PAGE_SIZE - 1)) & PAGE_MASK; 1071 (ep->qp.sq_pgtbl_size + (CNIC_PAGE_SIZE - 1)) & CNIC_PAGE_MASK;
1072 1072
1073 ep->qp.sq_pgtbl_virt = 1073 ep->qp.sq_pgtbl_virt =
1074 dma_alloc_coherent(&hba->pcidev->dev, ep->qp.sq_pgtbl_size, 1074 dma_alloc_coherent(&hba->pcidev->dev, ep->qp.sq_pgtbl_size,
@@ -1101,11 +1101,11 @@ int bnx2i_alloc_qp_resc(struct bnx2i_hba *hba, struct bnx2i_endpoint *ep)
1101 /* Allocate page table memory for CQ which is page aligned */ 1101 /* Allocate page table memory for CQ which is page aligned */
1102 ep->qp.cq_mem_size = hba->max_cqes * BNX2I_CQE_SIZE; 1102 ep->qp.cq_mem_size = hba->max_cqes * BNX2I_CQE_SIZE;
1103 ep->qp.cq_mem_size = 1103 ep->qp.cq_mem_size =
1104 (ep->qp.cq_mem_size + (PAGE_SIZE - 1)) & PAGE_MASK; 1104 (ep->qp.cq_mem_size + (CNIC_PAGE_SIZE - 1)) & CNIC_PAGE_MASK;
1105 ep->qp.cq_pgtbl_size = 1105 ep->qp.cq_pgtbl_size =
1106 (ep->qp.cq_mem_size / PAGE_SIZE) * sizeof(void *); 1106 (ep->qp.cq_mem_size / CNIC_PAGE_SIZE) * sizeof(void *);
1107 ep->qp.cq_pgtbl_size = 1107 ep->qp.cq_pgtbl_size =
1108 (ep->qp.cq_pgtbl_size + (PAGE_SIZE - 1)) & PAGE_MASK; 1108 (ep->qp.cq_pgtbl_size + (CNIC_PAGE_SIZE - 1)) & CNIC_PAGE_MASK;
1109 1109
1110 ep->qp.cq_pgtbl_virt = 1110 ep->qp.cq_pgtbl_virt =
1111 dma_alloc_coherent(&hba->pcidev->dev, ep->qp.cq_pgtbl_size, 1111 dma_alloc_coherent(&hba->pcidev->dev, ep->qp.cq_pgtbl_size,
@@ -1144,11 +1144,11 @@ int bnx2i_alloc_qp_resc(struct bnx2i_hba *hba, struct bnx2i_endpoint *ep)
1144 /* Allocate page table memory for RQ which is page aligned */ 1144 /* Allocate page table memory for RQ which is page aligned */
1145 ep->qp.rq_mem_size = hba->max_rqes * BNX2I_RQ_WQE_SIZE; 1145 ep->qp.rq_mem_size = hba->max_rqes * BNX2I_RQ_WQE_SIZE;
1146 ep->qp.rq_mem_size = 1146 ep->qp.rq_mem_size =
1147 (ep->qp.rq_mem_size + (PAGE_SIZE - 1)) & PAGE_MASK; 1147 (ep->qp.rq_mem_size + (CNIC_PAGE_SIZE - 1)) & CNIC_PAGE_MASK;
1148 ep->qp.rq_pgtbl_size = 1148 ep->qp.rq_pgtbl_size =
1149 (ep->qp.rq_mem_size / PAGE_SIZE) * sizeof(void *); 1149 (ep->qp.rq_mem_size / CNIC_PAGE_SIZE) * sizeof(void *);
1150 ep->qp.rq_pgtbl_size = 1150 ep->qp.rq_pgtbl_size =
1151 (ep->qp.rq_pgtbl_size + (PAGE_SIZE - 1)) & PAGE_MASK; 1151 (ep->qp.rq_pgtbl_size + (CNIC_PAGE_SIZE - 1)) & CNIC_PAGE_MASK;
1152 1152
1153 ep->qp.rq_pgtbl_virt = 1153 ep->qp.rq_pgtbl_virt =
1154 dma_alloc_coherent(&hba->pcidev->dev, ep->qp.rq_pgtbl_size, 1154 dma_alloc_coherent(&hba->pcidev->dev, ep->qp.rq_pgtbl_size,
@@ -1270,7 +1270,7 @@ int bnx2i_send_fw_iscsi_init_msg(struct bnx2i_hba *hba)
1270 bnx2i_adjust_qp_size(hba); 1270 bnx2i_adjust_qp_size(hba);
1271 1271
1272 iscsi_init.flags = 1272 iscsi_init.flags =
1273 ISCSI_PAGE_SIZE_4K << ISCSI_KWQE_INIT1_PAGE_SIZE_SHIFT; 1273 (CNIC_PAGE_BITS - 8) << ISCSI_KWQE_INIT1_PAGE_SIZE_SHIFT;
1274 if (en_tcp_dack) 1274 if (en_tcp_dack)
1275 iscsi_init.flags |= ISCSI_KWQE_INIT1_DELAYED_ACK_ENABLE; 1275 iscsi_init.flags |= ISCSI_KWQE_INIT1_DELAYED_ACK_ENABLE;
1276 iscsi_init.reserved0 = 0; 1276 iscsi_init.reserved0 = 0;
@@ -1288,15 +1288,15 @@ int bnx2i_send_fw_iscsi_init_msg(struct bnx2i_hba *hba)
1288 ((hba->num_ccell & 0xFFFF) | (hba->max_sqes << 16)); 1288 ((hba->num_ccell & 0xFFFF) | (hba->max_sqes << 16));
1289 iscsi_init.num_ccells_per_conn = hba->num_ccell; 1289 iscsi_init.num_ccells_per_conn = hba->num_ccell;
1290 iscsi_init.num_tasks_per_conn = hba->max_sqes; 1290 iscsi_init.num_tasks_per_conn = hba->max_sqes;
1291 iscsi_init.sq_wqes_per_page = PAGE_SIZE / BNX2I_SQ_WQE_SIZE; 1291 iscsi_init.sq_wqes_per_page = CNIC_PAGE_SIZE / BNX2I_SQ_WQE_SIZE;
1292 iscsi_init.sq_num_wqes = hba->max_sqes; 1292 iscsi_init.sq_num_wqes = hba->max_sqes;
1293 iscsi_init.cq_log_wqes_per_page = 1293 iscsi_init.cq_log_wqes_per_page =
1294 (u8) bnx2i_power_of2(PAGE_SIZE / BNX2I_CQE_SIZE); 1294 (u8) bnx2i_power_of2(CNIC_PAGE_SIZE / BNX2I_CQE_SIZE);
1295 iscsi_init.cq_num_wqes = hba->max_cqes; 1295 iscsi_init.cq_num_wqes = hba->max_cqes;
1296 iscsi_init.cq_num_pages = (hba->max_cqes * BNX2I_CQE_SIZE + 1296 iscsi_init.cq_num_pages = (hba->max_cqes * BNX2I_CQE_SIZE +
1297 (PAGE_SIZE - 1)) / PAGE_SIZE; 1297 (CNIC_PAGE_SIZE - 1)) / CNIC_PAGE_SIZE;
1298 iscsi_init.sq_num_pages = (hba->max_sqes * BNX2I_SQ_WQE_SIZE + 1298 iscsi_init.sq_num_pages = (hba->max_sqes * BNX2I_SQ_WQE_SIZE +
1299 (PAGE_SIZE - 1)) / PAGE_SIZE; 1299 (CNIC_PAGE_SIZE - 1)) / CNIC_PAGE_SIZE;
1300 iscsi_init.rq_buffer_size = BNX2I_RQ_WQE_SIZE; 1300 iscsi_init.rq_buffer_size = BNX2I_RQ_WQE_SIZE;
1301 iscsi_init.rq_num_wqes = hba->max_rqes; 1301 iscsi_init.rq_num_wqes = hba->max_rqes;
1302 1302
diff --git a/drivers/scsi/bnx2i/bnx2i_iscsi.c b/drivers/scsi/bnx2i/bnx2i_iscsi.c
index 854dad7d5b03..c8b0aff5bbd4 100644
--- a/drivers/scsi/bnx2i/bnx2i_iscsi.c
+++ b/drivers/scsi/bnx2i/bnx2i_iscsi.c
@@ -525,7 +525,7 @@ static int bnx2i_setup_mp_bdt(struct bnx2i_hba *hba)
525 struct iscsi_bd *mp_bdt; 525 struct iscsi_bd *mp_bdt;
526 u64 addr; 526 u64 addr;
527 527
528 hba->mp_bd_tbl = dma_alloc_coherent(&hba->pcidev->dev, PAGE_SIZE, 528 hba->mp_bd_tbl = dma_alloc_coherent(&hba->pcidev->dev, CNIC_PAGE_SIZE,
529 &hba->mp_bd_dma, GFP_KERNEL); 529 &hba->mp_bd_dma, GFP_KERNEL);
530 if (!hba->mp_bd_tbl) { 530 if (!hba->mp_bd_tbl) {
531 printk(KERN_ERR "unable to allocate Middle Path BDT\n"); 531 printk(KERN_ERR "unable to allocate Middle Path BDT\n");
@@ -533,11 +533,12 @@ static int bnx2i_setup_mp_bdt(struct bnx2i_hba *hba)
533 goto out; 533 goto out;
534 } 534 }
535 535
536 hba->dummy_buffer = dma_alloc_coherent(&hba->pcidev->dev, PAGE_SIZE, 536 hba->dummy_buffer = dma_alloc_coherent(&hba->pcidev->dev,
537 CNIC_PAGE_SIZE,
537 &hba->dummy_buf_dma, GFP_KERNEL); 538 &hba->dummy_buf_dma, GFP_KERNEL);
538 if (!hba->dummy_buffer) { 539 if (!hba->dummy_buffer) {
539 printk(KERN_ERR "unable to alloc Middle Path Dummy Buffer\n"); 540 printk(KERN_ERR "unable to alloc Middle Path Dummy Buffer\n");
540 dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE, 541 dma_free_coherent(&hba->pcidev->dev, CNIC_PAGE_SIZE,
541 hba->mp_bd_tbl, hba->mp_bd_dma); 542 hba->mp_bd_tbl, hba->mp_bd_dma);
542 hba->mp_bd_tbl = NULL; 543 hba->mp_bd_tbl = NULL;
543 rc = -1; 544 rc = -1;
@@ -548,7 +549,7 @@ static int bnx2i_setup_mp_bdt(struct bnx2i_hba *hba)
548 addr = (unsigned long) hba->dummy_buf_dma; 549 addr = (unsigned long) hba->dummy_buf_dma;
549 mp_bdt->buffer_addr_lo = addr & 0xffffffff; 550 mp_bdt->buffer_addr_lo = addr & 0xffffffff;
550 mp_bdt->buffer_addr_hi = addr >> 32; 551 mp_bdt->buffer_addr_hi = addr >> 32;
551 mp_bdt->buffer_length = PAGE_SIZE; 552 mp_bdt->buffer_length = CNIC_PAGE_SIZE;
552 mp_bdt->flags = ISCSI_BD_LAST_IN_BD_CHAIN | 553 mp_bdt->flags = ISCSI_BD_LAST_IN_BD_CHAIN |
553 ISCSI_BD_FIRST_IN_BD_CHAIN; 554 ISCSI_BD_FIRST_IN_BD_CHAIN;
554out: 555out:
@@ -565,12 +566,12 @@ out:
565static void bnx2i_free_mp_bdt(struct bnx2i_hba *hba) 566static void bnx2i_free_mp_bdt(struct bnx2i_hba *hba)
566{ 567{
567 if (hba->mp_bd_tbl) { 568 if (hba->mp_bd_tbl) {
568 dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE, 569 dma_free_coherent(&hba->pcidev->dev, CNIC_PAGE_SIZE,
569 hba->mp_bd_tbl, hba->mp_bd_dma); 570 hba->mp_bd_tbl, hba->mp_bd_dma);
570 hba->mp_bd_tbl = NULL; 571 hba->mp_bd_tbl = NULL;
571 } 572 }
572 if (hba->dummy_buffer) { 573 if (hba->dummy_buffer) {
573 dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE, 574 dma_free_coherent(&hba->pcidev->dev, CNIC_PAGE_SIZE,
574 hba->dummy_buffer, hba->dummy_buf_dma); 575 hba->dummy_buffer, hba->dummy_buf_dma);
575 hba->dummy_buffer = NULL; 576 hba->dummy_buffer = NULL;
576 } 577 }
@@ -934,14 +935,14 @@ static void bnx2i_conn_free_login_resources(struct bnx2i_hba *hba,
934 struct bnx2i_conn *bnx2i_conn) 935 struct bnx2i_conn *bnx2i_conn)
935{ 936{
936 if (bnx2i_conn->gen_pdu.resp_bd_tbl) { 937 if (bnx2i_conn->gen_pdu.resp_bd_tbl) {
937 dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE, 938 dma_free_coherent(&hba->pcidev->dev, CNIC_PAGE_SIZE,
938 bnx2i_conn->gen_pdu.resp_bd_tbl, 939 bnx2i_conn->gen_pdu.resp_bd_tbl,
939 bnx2i_conn->gen_pdu.resp_bd_dma); 940 bnx2i_conn->gen_pdu.resp_bd_dma);
940 bnx2i_conn->gen_pdu.resp_bd_tbl = NULL; 941 bnx2i_conn->gen_pdu.resp_bd_tbl = NULL;
941 } 942 }
942 943
943 if (bnx2i_conn->gen_pdu.req_bd_tbl) { 944 if (bnx2i_conn->gen_pdu.req_bd_tbl) {
944 dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE, 945 dma_free_coherent(&hba->pcidev->dev, CNIC_PAGE_SIZE,
945 bnx2i_conn->gen_pdu.req_bd_tbl, 946 bnx2i_conn->gen_pdu.req_bd_tbl,
946 bnx2i_conn->gen_pdu.req_bd_dma); 947 bnx2i_conn->gen_pdu.req_bd_dma);
947 bnx2i_conn->gen_pdu.req_bd_tbl = NULL; 948 bnx2i_conn->gen_pdu.req_bd_tbl = NULL;
@@ -998,13 +999,13 @@ static int bnx2i_conn_alloc_login_resources(struct bnx2i_hba *hba,
998 bnx2i_conn->gen_pdu.resp_wr_ptr = bnx2i_conn->gen_pdu.resp_buf; 999 bnx2i_conn->gen_pdu.resp_wr_ptr = bnx2i_conn->gen_pdu.resp_buf;
999 1000
1000 bnx2i_conn->gen_pdu.req_bd_tbl = 1001 bnx2i_conn->gen_pdu.req_bd_tbl =
1001 dma_alloc_coherent(&hba->pcidev->dev, PAGE_SIZE, 1002 dma_alloc_coherent(&hba->pcidev->dev, CNIC_PAGE_SIZE,
1002 &bnx2i_conn->gen_pdu.req_bd_dma, GFP_KERNEL); 1003 &bnx2i_conn->gen_pdu.req_bd_dma, GFP_KERNEL);
1003 if (bnx2i_conn->gen_pdu.req_bd_tbl == NULL) 1004 if (bnx2i_conn->gen_pdu.req_bd_tbl == NULL)
1004 goto login_req_bd_tbl_failure; 1005 goto login_req_bd_tbl_failure;
1005 1006
1006 bnx2i_conn->gen_pdu.resp_bd_tbl = 1007 bnx2i_conn->gen_pdu.resp_bd_tbl =
1007 dma_alloc_coherent(&hba->pcidev->dev, PAGE_SIZE, 1008 dma_alloc_coherent(&hba->pcidev->dev, CNIC_PAGE_SIZE,
1008 &bnx2i_conn->gen_pdu.resp_bd_dma, 1009 &bnx2i_conn->gen_pdu.resp_bd_dma,
1009 GFP_KERNEL); 1010 GFP_KERNEL);
1010 if (bnx2i_conn->gen_pdu.resp_bd_tbl == NULL) 1011 if (bnx2i_conn->gen_pdu.resp_bd_tbl == NULL)
@@ -1013,7 +1014,7 @@ static int bnx2i_conn_alloc_login_resources(struct bnx2i_hba *hba,
1013 return 0; 1014 return 0;
1014 1015
1015login_resp_bd_tbl_failure: 1016login_resp_bd_tbl_failure:
1016 dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE, 1017 dma_free_coherent(&hba->pcidev->dev, CNIC_PAGE_SIZE,
1017 bnx2i_conn->gen_pdu.req_bd_tbl, 1018 bnx2i_conn->gen_pdu.req_bd_tbl,
1018 bnx2i_conn->gen_pdu.req_bd_dma); 1019 bnx2i_conn->gen_pdu.req_bd_dma);
1019 bnx2i_conn->gen_pdu.req_bd_tbl = NULL; 1020 bnx2i_conn->gen_pdu.req_bd_tbl = NULL;
diff --git a/drivers/scsi/isci/host.h b/drivers/scsi/isci/host.h
index 4911310a38f5..22a9bb1abae1 100644
--- a/drivers/scsi/isci/host.h
+++ b/drivers/scsi/isci/host.h
@@ -311,9 +311,8 @@ static inline struct Scsi_Host *to_shost(struct isci_host *ihost)
311} 311}
312 312
313#define for_each_isci_host(id, ihost, pdev) \ 313#define for_each_isci_host(id, ihost, pdev) \
314 for (id = 0, ihost = to_pci_info(pdev)->hosts[id]; \ 314 for (id = 0; id < SCI_MAX_CONTROLLERS && \
315 id < ARRAY_SIZE(to_pci_info(pdev)->hosts) && ihost; \ 315 (ihost = to_pci_info(pdev)->hosts[id]); id++)
316 ihost = to_pci_info(pdev)->hosts[++id])
317 316
318static inline void wait_for_start(struct isci_host *ihost) 317static inline void wait_for_start(struct isci_host *ihost)
319{ 318{
diff --git a/drivers/scsi/isci/port_config.c b/drivers/scsi/isci/port_config.c
index 85c77f6b802b..ac879745ef80 100644
--- a/drivers/scsi/isci/port_config.c
+++ b/drivers/scsi/isci/port_config.c
@@ -615,13 +615,6 @@ static void sci_apc_agent_link_up(struct isci_host *ihost,
615 SCIC_SDS_APC_WAIT_LINK_UP_NOTIFICATION); 615 SCIC_SDS_APC_WAIT_LINK_UP_NOTIFICATION);
616 } else { 616 } else {
617 /* the phy is already the part of the port */ 617 /* the phy is already the part of the port */
618 u32 port_state = iport->sm.current_state_id;
619
620 /* if the PORT'S state is resetting then the link up is from
621 * port hard reset in this case, we need to tell the port
622 * that link up is recieved
623 */
624 BUG_ON(port_state != SCI_PORT_RESETTING);
625 port_agent->phy_ready_mask |= 1 << phy_index; 618 port_agent->phy_ready_mask |= 1 << phy_index;
626 sci_port_link_up(iport, iphy); 619 sci_port_link_up(iport, iphy);
627 } 620 }
diff --git a/drivers/scsi/isci/task.c b/drivers/scsi/isci/task.c
index 0d30ca849e8f..5d6fda72d659 100644
--- a/drivers/scsi/isci/task.c
+++ b/drivers/scsi/isci/task.c
@@ -801,7 +801,7 @@ int isci_task_I_T_nexus_reset(struct domain_device *dev)
801 /* XXX: need to cleanup any ireqs targeting this 801 /* XXX: need to cleanup any ireqs targeting this
802 * domain_device 802 * domain_device
803 */ 803 */
804 ret = TMF_RESP_FUNC_COMPLETE; 804 ret = -ENODEV;
805 goto out; 805 goto out;
806 } 806 }
807 807
diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
index d2895836f9fa..766098af4eb7 100644
--- a/drivers/scsi/libsas/sas_ata.c
+++ b/drivers/scsi/libsas/sas_ata.c
@@ -700,46 +700,26 @@ void sas_probe_sata(struct asd_sas_port *port)
700 700
701} 701}
702 702
703static bool sas_ata_flush_pm_eh(struct asd_sas_port *port, const char *func) 703static void sas_ata_flush_pm_eh(struct asd_sas_port *port, const char *func)
704{ 704{
705 struct domain_device *dev, *n; 705 struct domain_device *dev, *n;
706 bool retry = false;
707 706
708 list_for_each_entry_safe(dev, n, &port->dev_list, dev_list_node) { 707 list_for_each_entry_safe(dev, n, &port->dev_list, dev_list_node) {
709 int rc;
710
711 if (!dev_is_sata(dev)) 708 if (!dev_is_sata(dev))
712 continue; 709 continue;
713 710
714 sas_ata_wait_eh(dev); 711 sas_ata_wait_eh(dev);
715 rc = dev->sata_dev.pm_result;
716 if (rc == -EAGAIN)
717 retry = true;
718 else if (rc) {
719 /* since we don't have a
720 * ->port_{suspend|resume} routine in our
721 * ata_port ops, and no entanglements with
722 * acpi, suspend should just be mechanical trip
723 * through eh, catch cases where these
724 * assumptions are invalidated
725 */
726 WARN_ONCE(1, "failed %s %s error: %d\n", func,
727 dev_name(&dev->rphy->dev), rc);
728 }
729 712
730 /* if libata failed to power manage the device, tear it down */ 713 /* if libata failed to power manage the device, tear it down */
731 if (ata_dev_disabled(sas_to_ata_dev(dev))) 714 if (ata_dev_disabled(sas_to_ata_dev(dev)))
732 sas_fail_probe(dev, func, -ENODEV); 715 sas_fail_probe(dev, func, -ENODEV);
733 } 716 }
734
735 return retry;
736} 717}
737 718
738void sas_suspend_sata(struct asd_sas_port *port) 719void sas_suspend_sata(struct asd_sas_port *port)
739{ 720{
740 struct domain_device *dev; 721 struct domain_device *dev;
741 722
742 retry:
743 mutex_lock(&port->ha->disco_mutex); 723 mutex_lock(&port->ha->disco_mutex);
744 list_for_each_entry(dev, &port->dev_list, dev_list_node) { 724 list_for_each_entry(dev, &port->dev_list, dev_list_node) {
745 struct sata_device *sata; 725 struct sata_device *sata;
@@ -751,20 +731,17 @@ void sas_suspend_sata(struct asd_sas_port *port)
751 if (sata->ap->pm_mesg.event == PM_EVENT_SUSPEND) 731 if (sata->ap->pm_mesg.event == PM_EVENT_SUSPEND)
752 continue; 732 continue;
753 733
754 sata->pm_result = -EIO; 734 ata_sas_port_suspend(sata->ap);
755 ata_sas_port_async_suspend(sata->ap, &sata->pm_result);
756 } 735 }
757 mutex_unlock(&port->ha->disco_mutex); 736 mutex_unlock(&port->ha->disco_mutex);
758 737
759 if (sas_ata_flush_pm_eh(port, __func__)) 738 sas_ata_flush_pm_eh(port, __func__);
760 goto retry;
761} 739}
762 740
763void sas_resume_sata(struct asd_sas_port *port) 741void sas_resume_sata(struct asd_sas_port *port)
764{ 742{
765 struct domain_device *dev; 743 struct domain_device *dev;
766 744
767 retry:
768 mutex_lock(&port->ha->disco_mutex); 745 mutex_lock(&port->ha->disco_mutex);
769 list_for_each_entry(dev, &port->dev_list, dev_list_node) { 746 list_for_each_entry(dev, &port->dev_list, dev_list_node) {
770 struct sata_device *sata; 747 struct sata_device *sata;
@@ -776,13 +753,11 @@ void sas_resume_sata(struct asd_sas_port *port)
776 if (sata->ap->pm_mesg.event == PM_EVENT_ON) 753 if (sata->ap->pm_mesg.event == PM_EVENT_ON)
777 continue; 754 continue;
778 755
779 sata->pm_result = -EIO; 756 ata_sas_port_resume(sata->ap);
780 ata_sas_port_async_resume(sata->ap, &sata->pm_result);
781 } 757 }
782 mutex_unlock(&port->ha->disco_mutex); 758 mutex_unlock(&port->ha->disco_mutex);
783 759
784 if (sas_ata_flush_pm_eh(port, __func__)) 760 sas_ata_flush_pm_eh(port, __func__);
785 goto retry;
786} 761}
787 762
788/** 763/**
diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
index e1fe95ef23e1..266724b6b899 100644
--- a/drivers/scsi/qla2xxx/qla_def.h
+++ b/drivers/scsi/qla2xxx/qla_def.h
@@ -2996,8 +2996,7 @@ struct qla_hw_data {
2996 IS_QLA82XX(ha) || IS_QLA83XX(ha) || \ 2996 IS_QLA82XX(ha) || IS_QLA83XX(ha) || \
2997 IS_QLA8044(ha)) 2997 IS_QLA8044(ha))
2998#define IS_MSIX_NACK_CAPABLE(ha) (IS_QLA81XX(ha) || IS_QLA83XX(ha)) 2998#define IS_MSIX_NACK_CAPABLE(ha) (IS_QLA81XX(ha) || IS_QLA83XX(ha))
2999#define IS_NOPOLLING_TYPE(ha) ((IS_QLA25XX(ha) || IS_QLA81XX(ha) || \ 2999#define IS_NOPOLLING_TYPE(ha) (IS_QLA81XX(ha) && (ha)->flags.msix_enabled)
3000 IS_QLA83XX(ha)) && (ha)->flags.msix_enabled)
3001#define IS_FAC_REQUIRED(ha) (IS_QLA81XX(ha) || IS_QLA83XX(ha)) 3000#define IS_FAC_REQUIRED(ha) (IS_QLA81XX(ha) || IS_QLA83XX(ha))
3002#define IS_NOCACHE_VPD_TYPE(ha) (IS_QLA81XX(ha) || IS_QLA83XX(ha)) 3001#define IS_NOCACHE_VPD_TYPE(ha) (IS_QLA81XX(ha) || IS_QLA83XX(ha))
3003#define IS_ALOGIO_CAPABLE(ha) (IS_QLA23XX(ha) || IS_FWI2_CAPABLE(ha)) 3002#define IS_ALOGIO_CAPABLE(ha) (IS_QLA23XX(ha) || IS_FWI2_CAPABLE(ha))
diff --git a/drivers/scsi/qla2xxx/qla_isr.c b/drivers/scsi/qla2xxx/qla_isr.c
index 9bc86b9e86b1..0a1dcb43d18b 100644
--- a/drivers/scsi/qla2xxx/qla_isr.c
+++ b/drivers/scsi/qla2xxx/qla_isr.c
@@ -2880,6 +2880,7 @@ static int
2880qla24xx_enable_msix(struct qla_hw_data *ha, struct rsp_que *rsp) 2880qla24xx_enable_msix(struct qla_hw_data *ha, struct rsp_que *rsp)
2881{ 2881{
2882#define MIN_MSIX_COUNT 2 2882#define MIN_MSIX_COUNT 2
2883#define ATIO_VECTOR 2
2883 int i, ret; 2884 int i, ret;
2884 struct msix_entry *entries; 2885 struct msix_entry *entries;
2885 struct qla_msix_entry *qentry; 2886 struct qla_msix_entry *qentry;
@@ -2936,34 +2937,47 @@ msix_failed:
2936 } 2937 }
2937 2938
2938 /* Enable MSI-X vectors for the base queue */ 2939 /* Enable MSI-X vectors for the base queue */
2939 for (i = 0; i < ha->msix_count; i++) { 2940 for (i = 0; i < 2; i++) {
2940 qentry = &ha->msix_entries[i]; 2941 qentry = &ha->msix_entries[i];
2941 if (QLA_TGT_MODE_ENABLED() && IS_ATIO_MSIX_CAPABLE(ha)) { 2942 if (IS_P3P_TYPE(ha))
2942 ret = request_irq(qentry->vector,
2943 qla83xx_msix_entries[i].handler,
2944 0, qla83xx_msix_entries[i].name, rsp);
2945 } else if (IS_P3P_TYPE(ha)) {
2946 ret = request_irq(qentry->vector, 2943 ret = request_irq(qentry->vector,
2947 qla82xx_msix_entries[i].handler, 2944 qla82xx_msix_entries[i].handler,
2948 0, qla82xx_msix_entries[i].name, rsp); 2945 0, qla82xx_msix_entries[i].name, rsp);
2949 } else { 2946 else
2950 ret = request_irq(qentry->vector, 2947 ret = request_irq(qentry->vector,
2951 msix_entries[i].handler, 2948 msix_entries[i].handler,
2952 0, msix_entries[i].name, rsp); 2949 0, msix_entries[i].name, rsp);
2953 } 2950 if (ret)
2954 if (ret) { 2951 goto msix_register_fail;
2955 ql_log(ql_log_fatal, vha, 0x00cb,
2956 "MSI-X: unable to register handler -- %x/%d.\n",
2957 qentry->vector, ret);
2958 qla24xx_disable_msix(ha);
2959 ha->mqenable = 0;
2960 goto msix_out;
2961 }
2962 qentry->have_irq = 1; 2952 qentry->have_irq = 1;
2963 qentry->rsp = rsp; 2953 qentry->rsp = rsp;
2964 rsp->msix = qentry; 2954 rsp->msix = qentry;
2965 } 2955 }
2966 2956
2957 /*
2958 * If target mode is enable, also request the vector for the ATIO
2959 * queue.
2960 */
2961 if (QLA_TGT_MODE_ENABLED() && IS_ATIO_MSIX_CAPABLE(ha)) {
2962 qentry = &ha->msix_entries[ATIO_VECTOR];
2963 ret = request_irq(qentry->vector,
2964 qla83xx_msix_entries[ATIO_VECTOR].handler,
2965 0, qla83xx_msix_entries[ATIO_VECTOR].name, rsp);
2966 qentry->have_irq = 1;
2967 qentry->rsp = rsp;
2968 rsp->msix = qentry;
2969 }
2970
2971msix_register_fail:
2972 if (ret) {
2973 ql_log(ql_log_fatal, vha, 0x00cb,
2974 "MSI-X: unable to register handler -- %x/%d.\n",
2975 qentry->vector, ret);
2976 qla24xx_disable_msix(ha);
2977 ha->mqenable = 0;
2978 goto msix_out;
2979 }
2980
2967 /* Enable MSI-X vector for response queue update for queue 0 */ 2981 /* Enable MSI-X vector for response queue update for queue 0 */
2968 if (IS_QLA83XX(ha)) { 2982 if (IS_QLA83XX(ha)) {
2969 if (ha->msixbase && ha->mqiobase && 2983 if (ha->msixbase && ha->mqiobase &&
diff --git a/drivers/scsi/qla2xxx/qla_target.c b/drivers/scsi/qla2xxx/qla_target.c
index 2eb97d7e8d12..0cb73074c199 100644
--- a/drivers/scsi/qla2xxx/qla_target.c
+++ b/drivers/scsi/qla2xxx/qla_target.c
@@ -790,17 +790,32 @@ static inline int test_tgt_sess_count(struct qla_tgt *tgt)
790} 790}
791 791
792/* Called by tcm_qla2xxx configfs code */ 792/* Called by tcm_qla2xxx configfs code */
793void qlt_stop_phase1(struct qla_tgt *tgt) 793int qlt_stop_phase1(struct qla_tgt *tgt)
794{ 794{
795 struct scsi_qla_host *vha = tgt->vha; 795 struct scsi_qla_host *vha = tgt->vha;
796 struct qla_hw_data *ha = tgt->ha; 796 struct qla_hw_data *ha = tgt->ha;
797 unsigned long flags; 797 unsigned long flags;
798 798
799 mutex_lock(&qla_tgt_mutex);
800 if (!vha->fc_vport) {
801 struct Scsi_Host *sh = vha->host;
802 struct fc_host_attrs *fc_host = shost_to_fc_host(sh);
803 bool npiv_vports;
804
805 spin_lock_irqsave(sh->host_lock, flags);
806 npiv_vports = (fc_host->npiv_vports_inuse);
807 spin_unlock_irqrestore(sh->host_lock, flags);
808
809 if (npiv_vports) {
810 mutex_unlock(&qla_tgt_mutex);
811 return -EPERM;
812 }
813 }
799 if (tgt->tgt_stop || tgt->tgt_stopped) { 814 if (tgt->tgt_stop || tgt->tgt_stopped) {
800 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04e, 815 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04e,
801 "Already in tgt->tgt_stop or tgt_stopped state\n"); 816 "Already in tgt->tgt_stop or tgt_stopped state\n");
802 dump_stack(); 817 mutex_unlock(&qla_tgt_mutex);
803 return; 818 return -EPERM;
804 } 819 }
805 820
806 ql_dbg(ql_dbg_tgt, vha, 0xe003, "Stopping target for host %ld(%p)\n", 821 ql_dbg(ql_dbg_tgt, vha, 0xe003, "Stopping target for host %ld(%p)\n",
@@ -815,6 +830,7 @@ void qlt_stop_phase1(struct qla_tgt *tgt)
815 qlt_clear_tgt_db(tgt, true); 830 qlt_clear_tgt_db(tgt, true);
816 spin_unlock_irqrestore(&ha->hardware_lock, flags); 831 spin_unlock_irqrestore(&ha->hardware_lock, flags);
817 mutex_unlock(&vha->vha_tgt.tgt_mutex); 832 mutex_unlock(&vha->vha_tgt.tgt_mutex);
833 mutex_unlock(&qla_tgt_mutex);
818 834
819 flush_delayed_work(&tgt->sess_del_work); 835 flush_delayed_work(&tgt->sess_del_work);
820 836
@@ -841,6 +857,7 @@ void qlt_stop_phase1(struct qla_tgt *tgt)
841 857
842 /* Wait for sessions to clear out (just in case) */ 858 /* Wait for sessions to clear out (just in case) */
843 wait_event(tgt->waitQ, test_tgt_sess_count(tgt)); 859 wait_event(tgt->waitQ, test_tgt_sess_count(tgt));
860 return 0;
844} 861}
845EXPORT_SYMBOL(qlt_stop_phase1); 862EXPORT_SYMBOL(qlt_stop_phase1);
846 863
@@ -3185,7 +3202,8 @@ restart:
3185 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf02c, 3202 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf02c,
3186 "SRR cmd %p (se_cmd %p, tag %d, op %x), " 3203 "SRR cmd %p (se_cmd %p, tag %d, op %x), "
3187 "sg_cnt=%d, offset=%d", cmd, &cmd->se_cmd, cmd->tag, 3204 "sg_cnt=%d, offset=%d", cmd, &cmd->se_cmd, cmd->tag,
3188 se_cmd->t_task_cdb[0], cmd->sg_cnt, cmd->offset); 3205 se_cmd->t_task_cdb ? se_cmd->t_task_cdb[0] : 0,
3206 cmd->sg_cnt, cmd->offset);
3189 3207
3190 qlt_handle_srr(vha, sctio, imm); 3208 qlt_handle_srr(vha, sctio, imm);
3191 3209
@@ -4181,6 +4199,9 @@ int qlt_add_target(struct qla_hw_data *ha, struct scsi_qla_host *base_vha)
4181 tgt->datasegs_per_cmd = QLA_TGT_DATASEGS_PER_CMD_24XX; 4199 tgt->datasegs_per_cmd = QLA_TGT_DATASEGS_PER_CMD_24XX;
4182 tgt->datasegs_per_cont = QLA_TGT_DATASEGS_PER_CONT_24XX; 4200 tgt->datasegs_per_cont = QLA_TGT_DATASEGS_PER_CONT_24XX;
4183 4201
4202 if (base_vha->fc_vport)
4203 return 0;
4204
4184 mutex_lock(&qla_tgt_mutex); 4205 mutex_lock(&qla_tgt_mutex);
4185 list_add_tail(&tgt->tgt_list_entry, &qla_tgt_glist); 4206 list_add_tail(&tgt->tgt_list_entry, &qla_tgt_glist);
4186 mutex_unlock(&qla_tgt_mutex); 4207 mutex_unlock(&qla_tgt_mutex);
@@ -4194,6 +4215,10 @@ int qlt_remove_target(struct qla_hw_data *ha, struct scsi_qla_host *vha)
4194 if (!vha->vha_tgt.qla_tgt) 4215 if (!vha->vha_tgt.qla_tgt)
4195 return 0; 4216 return 0;
4196 4217
4218 if (vha->fc_vport) {
4219 qlt_release(vha->vha_tgt.qla_tgt);
4220 return 0;
4221 }
4197 mutex_lock(&qla_tgt_mutex); 4222 mutex_lock(&qla_tgt_mutex);
4198 list_del(&vha->vha_tgt.qla_tgt->tgt_list_entry); 4223 list_del(&vha->vha_tgt.qla_tgt->tgt_list_entry);
4199 mutex_unlock(&qla_tgt_mutex); 4224 mutex_unlock(&qla_tgt_mutex);
@@ -4265,6 +4290,12 @@ int qlt_lport_register(void *target_lport_ptr, u64 phys_wwpn,
4265 spin_unlock_irqrestore(&ha->hardware_lock, flags); 4290 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4266 continue; 4291 continue;
4267 } 4292 }
4293 if (tgt->tgt_stop) {
4294 pr_debug("MODE_TARGET in shutdown on qla2xxx(%d)\n",
4295 host->host_no);
4296 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4297 continue;
4298 }
4268 spin_unlock_irqrestore(&ha->hardware_lock, flags); 4299 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4269 4300
4270 if (!scsi_host_get(host)) { 4301 if (!scsi_host_get(host)) {
@@ -4279,12 +4310,11 @@ int qlt_lport_register(void *target_lport_ptr, u64 phys_wwpn,
4279 scsi_host_put(host); 4310 scsi_host_put(host);
4280 continue; 4311 continue;
4281 } 4312 }
4282 mutex_unlock(&qla_tgt_mutex);
4283
4284 rc = (*callback)(vha, target_lport_ptr, npiv_wwpn, npiv_wwnn); 4313 rc = (*callback)(vha, target_lport_ptr, npiv_wwpn, npiv_wwnn);
4285 if (rc != 0) 4314 if (rc != 0)
4286 scsi_host_put(host); 4315 scsi_host_put(host);
4287 4316
4317 mutex_unlock(&qla_tgt_mutex);
4288 return rc; 4318 return rc;
4289 } 4319 }
4290 mutex_unlock(&qla_tgt_mutex); 4320 mutex_unlock(&qla_tgt_mutex);
diff --git a/drivers/scsi/qla2xxx/qla_target.h b/drivers/scsi/qla2xxx/qla_target.h
index 66e755cdde57..ce33d8c26406 100644
--- a/drivers/scsi/qla2xxx/qla_target.h
+++ b/drivers/scsi/qla2xxx/qla_target.h
@@ -1001,7 +1001,7 @@ extern void qlt_modify_vp_config(struct scsi_qla_host *,
1001extern void qlt_probe_one_stage1(struct scsi_qla_host *, struct qla_hw_data *); 1001extern void qlt_probe_one_stage1(struct scsi_qla_host *, struct qla_hw_data *);
1002extern int qlt_mem_alloc(struct qla_hw_data *); 1002extern int qlt_mem_alloc(struct qla_hw_data *);
1003extern void qlt_mem_free(struct qla_hw_data *); 1003extern void qlt_mem_free(struct qla_hw_data *);
1004extern void qlt_stop_phase1(struct qla_tgt *); 1004extern int qlt_stop_phase1(struct qla_tgt *);
1005extern void qlt_stop_phase2(struct qla_tgt *); 1005extern void qlt_stop_phase2(struct qla_tgt *);
1006extern irqreturn_t qla83xx_msix_atio_q(int, void *); 1006extern irqreturn_t qla83xx_msix_atio_q(int, void *);
1007extern void qlt_83xx_iospace_config(struct qla_hw_data *); 1007extern void qlt_83xx_iospace_config(struct qla_hw_data *);
diff --git a/drivers/scsi/qla2xxx/tcm_qla2xxx.c b/drivers/scsi/qla2xxx/tcm_qla2xxx.c
index 75a141bbe74d..788c4fe2b0c9 100644
--- a/drivers/scsi/qla2xxx/tcm_qla2xxx.c
+++ b/drivers/scsi/qla2xxx/tcm_qla2xxx.c
@@ -182,20 +182,6 @@ static int tcm_qla2xxx_npiv_parse_wwn(
182 return 0; 182 return 0;
183} 183}
184 184
185static ssize_t tcm_qla2xxx_npiv_format_wwn(char *buf, size_t len,
186 u64 wwpn, u64 wwnn)
187{
188 u8 b[8], b2[8];
189
190 put_unaligned_be64(wwpn, b);
191 put_unaligned_be64(wwnn, b2);
192 return snprintf(buf, len,
193 "%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x,"
194 "%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x",
195 b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7],
196 b2[0], b2[1], b2[2], b2[3], b2[4], b2[5], b2[6], b2[7]);
197}
198
199static char *tcm_qla2xxx_npiv_get_fabric_name(void) 185static char *tcm_qla2xxx_npiv_get_fabric_name(void)
200{ 186{
201 return "qla2xxx_npiv"; 187 return "qla2xxx_npiv";
@@ -227,15 +213,6 @@ static char *tcm_qla2xxx_get_fabric_wwn(struct se_portal_group *se_tpg)
227 return lport->lport_naa_name; 213 return lport->lport_naa_name;
228} 214}
229 215
230static char *tcm_qla2xxx_npiv_get_fabric_wwn(struct se_portal_group *se_tpg)
231{
232 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg,
233 struct tcm_qla2xxx_tpg, se_tpg);
234 struct tcm_qla2xxx_lport *lport = tpg->lport;
235
236 return &lport->lport_npiv_name[0];
237}
238
239static u16 tcm_qla2xxx_get_tag(struct se_portal_group *se_tpg) 216static u16 tcm_qla2xxx_get_tag(struct se_portal_group *se_tpg)
240{ 217{
241 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg, 218 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg,
@@ -941,15 +918,41 @@ static ssize_t tcm_qla2xxx_tpg_show_enable(
941 atomic_read(&tpg->lport_tpg_enabled)); 918 atomic_read(&tpg->lport_tpg_enabled));
942} 919}
943 920
921static void tcm_qla2xxx_depend_tpg(struct work_struct *work)
922{
923 struct tcm_qla2xxx_tpg *base_tpg = container_of(work,
924 struct tcm_qla2xxx_tpg, tpg_base_work);
925 struct se_portal_group *se_tpg = &base_tpg->se_tpg;
926 struct scsi_qla_host *base_vha = base_tpg->lport->qla_vha;
927
928 if (!configfs_depend_item(se_tpg->se_tpg_tfo->tf_subsys,
929 &se_tpg->tpg_group.cg_item)) {
930 atomic_set(&base_tpg->lport_tpg_enabled, 1);
931 qlt_enable_vha(base_vha);
932 }
933 complete(&base_tpg->tpg_base_comp);
934}
935
936static void tcm_qla2xxx_undepend_tpg(struct work_struct *work)
937{
938 struct tcm_qla2xxx_tpg *base_tpg = container_of(work,
939 struct tcm_qla2xxx_tpg, tpg_base_work);
940 struct se_portal_group *se_tpg = &base_tpg->se_tpg;
941 struct scsi_qla_host *base_vha = base_tpg->lport->qla_vha;
942
943 if (!qlt_stop_phase1(base_vha->vha_tgt.qla_tgt)) {
944 atomic_set(&base_tpg->lport_tpg_enabled, 0);
945 configfs_undepend_item(se_tpg->se_tpg_tfo->tf_subsys,
946 &se_tpg->tpg_group.cg_item);
947 }
948 complete(&base_tpg->tpg_base_comp);
949}
950
944static ssize_t tcm_qla2xxx_tpg_store_enable( 951static ssize_t tcm_qla2xxx_tpg_store_enable(
945 struct se_portal_group *se_tpg, 952 struct se_portal_group *se_tpg,
946 const char *page, 953 const char *page,
947 size_t count) 954 size_t count)
948{ 955{
949 struct se_wwn *se_wwn = se_tpg->se_tpg_wwn;
950 struct tcm_qla2xxx_lport *lport = container_of(se_wwn,
951 struct tcm_qla2xxx_lport, lport_wwn);
952 struct scsi_qla_host *vha = lport->qla_vha;
953 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg, 956 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg,
954 struct tcm_qla2xxx_tpg, se_tpg); 957 struct tcm_qla2xxx_tpg, se_tpg);
955 unsigned long op; 958 unsigned long op;
@@ -964,19 +967,28 @@ static ssize_t tcm_qla2xxx_tpg_store_enable(
964 pr_err("Illegal value for tpg_enable: %lu\n", op); 967 pr_err("Illegal value for tpg_enable: %lu\n", op);
965 return -EINVAL; 968 return -EINVAL;
966 } 969 }
967
968 if (op) { 970 if (op) {
969 atomic_set(&tpg->lport_tpg_enabled, 1); 971 if (atomic_read(&tpg->lport_tpg_enabled))
970 qlt_enable_vha(vha); 972 return -EEXIST;
973
974 INIT_WORK(&tpg->tpg_base_work, tcm_qla2xxx_depend_tpg);
971 } else { 975 } else {
972 if (!vha->vha_tgt.qla_tgt) { 976 if (!atomic_read(&tpg->lport_tpg_enabled))
973 pr_err("struct qla_hw_data *vha->vha_tgt.qla_tgt is NULL\n"); 977 return count;
974 return -ENODEV; 978
975 } 979 INIT_WORK(&tpg->tpg_base_work, tcm_qla2xxx_undepend_tpg);
976 atomic_set(&tpg->lport_tpg_enabled, 0);
977 qlt_stop_phase1(vha->vha_tgt.qla_tgt);
978 } 980 }
981 init_completion(&tpg->tpg_base_comp);
982 schedule_work(&tpg->tpg_base_work);
983 wait_for_completion(&tpg->tpg_base_comp);
979 984
985 if (op) {
986 if (!atomic_read(&tpg->lport_tpg_enabled))
987 return -ENODEV;
988 } else {
989 if (atomic_read(&tpg->lport_tpg_enabled))
990 return -EPERM;
991 }
980 return count; 992 return count;
981} 993}
982 994
@@ -1053,11 +1065,64 @@ static void tcm_qla2xxx_drop_tpg(struct se_portal_group *se_tpg)
1053 /* 1065 /*
1054 * Clear local TPG=1 pointer for non NPIV mode. 1066 * Clear local TPG=1 pointer for non NPIV mode.
1055 */ 1067 */
1056 lport->tpg_1 = NULL; 1068 lport->tpg_1 = NULL;
1057
1058 kfree(tpg); 1069 kfree(tpg);
1059} 1070}
1060 1071
1072static ssize_t tcm_qla2xxx_npiv_tpg_show_enable(
1073 struct se_portal_group *se_tpg,
1074 char *page)
1075{
1076 return tcm_qla2xxx_tpg_show_enable(se_tpg, page);
1077}
1078
1079static ssize_t tcm_qla2xxx_npiv_tpg_store_enable(
1080 struct se_portal_group *se_tpg,
1081 const char *page,
1082 size_t count)
1083{
1084 struct se_wwn *se_wwn = se_tpg->se_tpg_wwn;
1085 struct tcm_qla2xxx_lport *lport = container_of(se_wwn,
1086 struct tcm_qla2xxx_lport, lport_wwn);
1087 struct scsi_qla_host *vha = lport->qla_vha;
1088 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg,
1089 struct tcm_qla2xxx_tpg, se_tpg);
1090 unsigned long op;
1091 int rc;
1092
1093 rc = kstrtoul(page, 0, &op);
1094 if (rc < 0) {
1095 pr_err("kstrtoul() returned %d\n", rc);
1096 return -EINVAL;
1097 }
1098 if ((op != 1) && (op != 0)) {
1099 pr_err("Illegal value for tpg_enable: %lu\n", op);
1100 return -EINVAL;
1101 }
1102 if (op) {
1103 if (atomic_read(&tpg->lport_tpg_enabled))
1104 return -EEXIST;
1105
1106 atomic_set(&tpg->lport_tpg_enabled, 1);
1107 qlt_enable_vha(vha);
1108 } else {
1109 if (!atomic_read(&tpg->lport_tpg_enabled))
1110 return count;
1111
1112 atomic_set(&tpg->lport_tpg_enabled, 0);
1113 qlt_stop_phase1(vha->vha_tgt.qla_tgt);
1114 }
1115
1116 return count;
1117}
1118
1119TF_TPG_BASE_ATTR(tcm_qla2xxx_npiv, enable, S_IRUGO | S_IWUSR);
1120
1121static struct configfs_attribute *tcm_qla2xxx_npiv_tpg_attrs[] = {
1122 &tcm_qla2xxx_npiv_tpg_enable.attr,
1123 NULL,
1124};
1125
1061static struct se_portal_group *tcm_qla2xxx_npiv_make_tpg( 1126static struct se_portal_group *tcm_qla2xxx_npiv_make_tpg(
1062 struct se_wwn *wwn, 1127 struct se_wwn *wwn,
1063 struct config_group *group, 1128 struct config_group *group,
@@ -1650,6 +1715,9 @@ static int tcm_qla2xxx_lport_register_npiv_cb(struct scsi_qla_host *base_vha,
1650 struct scsi_qla_host *npiv_vha; 1715 struct scsi_qla_host *npiv_vha;
1651 struct tcm_qla2xxx_lport *lport = 1716 struct tcm_qla2xxx_lport *lport =
1652 (struct tcm_qla2xxx_lport *)target_lport_ptr; 1717 (struct tcm_qla2xxx_lport *)target_lport_ptr;
1718 struct tcm_qla2xxx_lport *base_lport =
1719 (struct tcm_qla2xxx_lport *)base_vha->vha_tgt.target_lport_ptr;
1720 struct tcm_qla2xxx_tpg *base_tpg;
1653 struct fc_vport_identifiers vport_id; 1721 struct fc_vport_identifiers vport_id;
1654 1722
1655 if (!qla_tgt_mode_enabled(base_vha)) { 1723 if (!qla_tgt_mode_enabled(base_vha)) {
@@ -1657,6 +1725,13 @@ static int tcm_qla2xxx_lport_register_npiv_cb(struct scsi_qla_host *base_vha,
1657 return -EPERM; 1725 return -EPERM;
1658 } 1726 }
1659 1727
1728 if (!base_lport || !base_lport->tpg_1 ||
1729 !atomic_read(&base_lport->tpg_1->lport_tpg_enabled)) {
1730 pr_err("qla2xxx base_lport or tpg_1 not available\n");
1731 return -EPERM;
1732 }
1733 base_tpg = base_lport->tpg_1;
1734
1660 memset(&vport_id, 0, sizeof(vport_id)); 1735 memset(&vport_id, 0, sizeof(vport_id));
1661 vport_id.port_name = npiv_wwpn; 1736 vport_id.port_name = npiv_wwpn;
1662 vport_id.node_name = npiv_wwnn; 1737 vport_id.node_name = npiv_wwnn;
@@ -1675,7 +1750,6 @@ static int tcm_qla2xxx_lport_register_npiv_cb(struct scsi_qla_host *base_vha,
1675 npiv_vha = (struct scsi_qla_host *)vport->dd_data; 1750 npiv_vha = (struct scsi_qla_host *)vport->dd_data;
1676 npiv_vha->vha_tgt.target_lport_ptr = target_lport_ptr; 1751 npiv_vha->vha_tgt.target_lport_ptr = target_lport_ptr;
1677 lport->qla_vha = npiv_vha; 1752 lport->qla_vha = npiv_vha;
1678
1679 scsi_host_get(npiv_vha->host); 1753 scsi_host_get(npiv_vha->host);
1680 return 0; 1754 return 0;
1681} 1755}
@@ -1714,8 +1788,6 @@ static struct se_wwn *tcm_qla2xxx_npiv_make_lport(
1714 } 1788 }
1715 lport->lport_npiv_wwpn = npiv_wwpn; 1789 lport->lport_npiv_wwpn = npiv_wwpn;
1716 lport->lport_npiv_wwnn = npiv_wwnn; 1790 lport->lport_npiv_wwnn = npiv_wwnn;
1717 tcm_qla2xxx_npiv_format_wwn(&lport->lport_npiv_name[0],
1718 TCM_QLA2XXX_NAMELEN, npiv_wwpn, npiv_wwnn);
1719 sprintf(lport->lport_naa_name, "naa.%016llx", (unsigned long long) npiv_wwpn); 1791 sprintf(lport->lport_naa_name, "naa.%016llx", (unsigned long long) npiv_wwpn);
1720 1792
1721 ret = tcm_qla2xxx_init_lport(lport); 1793 ret = tcm_qla2xxx_init_lport(lport);
@@ -1824,7 +1896,7 @@ static struct target_core_fabric_ops tcm_qla2xxx_ops = {
1824static struct target_core_fabric_ops tcm_qla2xxx_npiv_ops = { 1896static struct target_core_fabric_ops tcm_qla2xxx_npiv_ops = {
1825 .get_fabric_name = tcm_qla2xxx_npiv_get_fabric_name, 1897 .get_fabric_name = tcm_qla2xxx_npiv_get_fabric_name,
1826 .get_fabric_proto_ident = tcm_qla2xxx_get_fabric_proto_ident, 1898 .get_fabric_proto_ident = tcm_qla2xxx_get_fabric_proto_ident,
1827 .tpg_get_wwn = tcm_qla2xxx_npiv_get_fabric_wwn, 1899 .tpg_get_wwn = tcm_qla2xxx_get_fabric_wwn,
1828 .tpg_get_tag = tcm_qla2xxx_get_tag, 1900 .tpg_get_tag = tcm_qla2xxx_get_tag,
1829 .tpg_get_default_depth = tcm_qla2xxx_get_default_depth, 1901 .tpg_get_default_depth = tcm_qla2xxx_get_default_depth,
1830 .tpg_get_pr_transport_id = tcm_qla2xxx_get_pr_transport_id, 1902 .tpg_get_pr_transport_id = tcm_qla2xxx_get_pr_transport_id,
@@ -1935,7 +2007,7 @@ static int tcm_qla2xxx_register_configfs(void)
1935 */ 2007 */
1936 npiv_fabric->tf_cit_tmpl.tfc_wwn_cit.ct_attrs = tcm_qla2xxx_wwn_attrs; 2008 npiv_fabric->tf_cit_tmpl.tfc_wwn_cit.ct_attrs = tcm_qla2xxx_wwn_attrs;
1937 npiv_fabric->tf_cit_tmpl.tfc_tpg_base_cit.ct_attrs = 2009 npiv_fabric->tf_cit_tmpl.tfc_tpg_base_cit.ct_attrs =
1938 tcm_qla2xxx_tpg_attrs; 2010 tcm_qla2xxx_npiv_tpg_attrs;
1939 npiv_fabric->tf_cit_tmpl.tfc_tpg_attrib_cit.ct_attrs = NULL; 2011 npiv_fabric->tf_cit_tmpl.tfc_tpg_attrib_cit.ct_attrs = NULL;
1940 npiv_fabric->tf_cit_tmpl.tfc_tpg_param_cit.ct_attrs = NULL; 2012 npiv_fabric->tf_cit_tmpl.tfc_tpg_param_cit.ct_attrs = NULL;
1941 npiv_fabric->tf_cit_tmpl.tfc_tpg_np_base_cit.ct_attrs = NULL; 2013 npiv_fabric->tf_cit_tmpl.tfc_tpg_np_base_cit.ct_attrs = NULL;
diff --git a/drivers/scsi/qla2xxx/tcm_qla2xxx.h b/drivers/scsi/qla2xxx/tcm_qla2xxx.h
index 275d8b9a7a34..33aaac8c7d59 100644
--- a/drivers/scsi/qla2xxx/tcm_qla2xxx.h
+++ b/drivers/scsi/qla2xxx/tcm_qla2xxx.h
@@ -4,8 +4,6 @@
4#define TCM_QLA2XXX_VERSION "v0.1" 4#define TCM_QLA2XXX_VERSION "v0.1"
5/* length of ASCII WWPNs including pad */ 5/* length of ASCII WWPNs including pad */
6#define TCM_QLA2XXX_NAMELEN 32 6#define TCM_QLA2XXX_NAMELEN 32
7/* lenth of ASCII NPIV 'WWPN+WWNN' including pad */
8#define TCM_QLA2XXX_NPIV_NAMELEN 66
9 7
10#include "qla_target.h" 8#include "qla_target.h"
11 9
@@ -43,6 +41,9 @@ struct tcm_qla2xxx_tpg {
43 struct tcm_qla2xxx_tpg_attrib tpg_attrib; 41 struct tcm_qla2xxx_tpg_attrib tpg_attrib;
44 /* Returned by tcm_qla2xxx_make_tpg() */ 42 /* Returned by tcm_qla2xxx_make_tpg() */
45 struct se_portal_group se_tpg; 43 struct se_portal_group se_tpg;
44 /* Items for dealing with configfs_depend_item */
45 struct completion tpg_base_comp;
46 struct work_struct tpg_base_work;
46}; 47};
47 48
48struct tcm_qla2xxx_fc_loopid { 49struct tcm_qla2xxx_fc_loopid {
@@ -62,8 +63,6 @@ struct tcm_qla2xxx_lport {
62 char lport_name[TCM_QLA2XXX_NAMELEN]; 63 char lport_name[TCM_QLA2XXX_NAMELEN];
63 /* ASCII formatted naa WWPN for VPD page 83 etc */ 64 /* ASCII formatted naa WWPN for VPD page 83 etc */
64 char lport_naa_name[TCM_QLA2XXX_NAMELEN]; 65 char lport_naa_name[TCM_QLA2XXX_NAMELEN];
65 /* ASCII formatted WWPN+WWNN for NPIV FC Target Lport */
66 char lport_npiv_name[TCM_QLA2XXX_NPIV_NAMELEN];
67 /* map for fc_port pointers in 24-bit FC Port ID space */ 66 /* map for fc_port pointers in 24-bit FC Port ID space */
68 struct btree_head32 lport_fcport_map; 67 struct btree_head32 lport_fcport_map;
69 /* vmalloc-ed memory for fc_port pointers for 16-bit FC loop ID */ 68 /* vmalloc-ed memory for fc_port pointers for 16-bit FC loop ID */
diff --git a/drivers/scsi/storvsc_drv.c b/drivers/scsi/storvsc_drv.c
index 17d740427240..9969fa1ef7c4 100644
--- a/drivers/scsi/storvsc_drv.c
+++ b/drivers/scsi/storvsc_drv.c
@@ -1419,6 +1419,9 @@ static void storvsc_device_destroy(struct scsi_device *sdevice)
1419{ 1419{
1420 struct stor_mem_pools *memp = sdevice->hostdata; 1420 struct stor_mem_pools *memp = sdevice->hostdata;
1421 1421
1422 if (!memp)
1423 return;
1424
1422 mempool_destroy(memp->request_mempool); 1425 mempool_destroy(memp->request_mempool);
1423 kmem_cache_destroy(memp->request_pool); 1426 kmem_cache_destroy(memp->request_pool);
1424 kfree(memp); 1427 kfree(memp);
diff --git a/drivers/spi/spi-ath79.c b/drivers/spi/spi-ath79.c
index 31534b51715a..c3b2fb9b6713 100644
--- a/drivers/spi/spi-ath79.c
+++ b/drivers/spi/spi-ath79.c
@@ -132,9 +132,9 @@ static int ath79_spi_setup_cs(struct spi_device *spi)
132 132
133 flags = GPIOF_DIR_OUT; 133 flags = GPIOF_DIR_OUT;
134 if (spi->mode & SPI_CS_HIGH) 134 if (spi->mode & SPI_CS_HIGH)
135 flags |= GPIOF_INIT_HIGH;
136 else
137 flags |= GPIOF_INIT_LOW; 135 flags |= GPIOF_INIT_LOW;
136 else
137 flags |= GPIOF_INIT_HIGH;
138 138
139 status = gpio_request_one(cdata->gpio, flags, 139 status = gpio_request_one(cdata->gpio, flags,
140 dev_name(&spi->dev)); 140 dev_name(&spi->dev));
diff --git a/drivers/spi/spi-atmel.c b/drivers/spi/spi-atmel.c
index b0842f751016..5d7b07f08326 100644
--- a/drivers/spi/spi-atmel.c
+++ b/drivers/spi/spi-atmel.c
@@ -1455,6 +1455,14 @@ static int atmel_spi_suspend(struct device *dev)
1455{ 1455{
1456 struct spi_master *master = dev_get_drvdata(dev); 1456 struct spi_master *master = dev_get_drvdata(dev);
1457 struct atmel_spi *as = spi_master_get_devdata(master); 1457 struct atmel_spi *as = spi_master_get_devdata(master);
1458 int ret;
1459
1460 /* Stop the queue running */
1461 ret = spi_master_suspend(master);
1462 if (ret) {
1463 dev_warn(dev, "cannot suspend master\n");
1464 return ret;
1465 }
1458 1466
1459 clk_disable_unprepare(as->clk); 1467 clk_disable_unprepare(as->clk);
1460 return 0; 1468 return 0;
@@ -1464,9 +1472,16 @@ static int atmel_spi_resume(struct device *dev)
1464{ 1472{
1465 struct spi_master *master = dev_get_drvdata(dev); 1473 struct spi_master *master = dev_get_drvdata(dev);
1466 struct atmel_spi *as = spi_master_get_devdata(master); 1474 struct atmel_spi *as = spi_master_get_devdata(master);
1475 int ret;
1467 1476
1468 clk_prepare_enable(as->clk); 1477 clk_prepare_enable(as->clk);
1469 return 0; 1478
1479 /* Start the queue running */
1480 ret = spi_master_resume(master);
1481 if (ret)
1482 dev_err(dev, "problem starting queue (%d)\n", ret);
1483
1484 return ret;
1470} 1485}
1471 1486
1472static SIMPLE_DEV_PM_OPS(atmel_spi_pm_ops, atmel_spi_suspend, atmel_spi_resume); 1487static SIMPLE_DEV_PM_OPS(atmel_spi_pm_ops, atmel_spi_suspend, atmel_spi_resume);
diff --git a/drivers/spi/spi-coldfire-qspi.c b/drivers/spi/spi-coldfire-qspi.c
index cabed8f9119e..28ae470397a9 100644
--- a/drivers/spi/spi-coldfire-qspi.c
+++ b/drivers/spi/spi-coldfire-qspi.c
@@ -514,7 +514,8 @@ static int mcfqspi_resume(struct device *dev)
514#ifdef CONFIG_PM_RUNTIME 514#ifdef CONFIG_PM_RUNTIME
515static int mcfqspi_runtime_suspend(struct device *dev) 515static int mcfqspi_runtime_suspend(struct device *dev)
516{ 516{
517 struct mcfqspi *mcfqspi = dev_get_drvdata(dev); 517 struct spi_master *master = dev_get_drvdata(dev);
518 struct mcfqspi *mcfqspi = spi_master_get_devdata(master);
518 519
519 clk_disable(mcfqspi->clk); 520 clk_disable(mcfqspi->clk);
520 521
@@ -523,7 +524,8 @@ static int mcfqspi_runtime_suspend(struct device *dev)
523 524
524static int mcfqspi_runtime_resume(struct device *dev) 525static int mcfqspi_runtime_resume(struct device *dev)
525{ 526{
526 struct mcfqspi *mcfqspi = dev_get_drvdata(dev); 527 struct spi_master *master = dev_get_drvdata(dev);
528 struct mcfqspi *mcfqspi = spi_master_get_devdata(master);
527 529
528 clk_enable(mcfqspi->clk); 530 clk_enable(mcfqspi->clk);
529 531
diff --git a/drivers/spi/spi-fsl-dspi.c b/drivers/spi/spi-fsl-dspi.c
index ec79f726672a..a25392065d9b 100644
--- a/drivers/spi/spi-fsl-dspi.c
+++ b/drivers/spi/spi-fsl-dspi.c
@@ -420,7 +420,6 @@ static int dspi_suspend(struct device *dev)
420 420
421static int dspi_resume(struct device *dev) 421static int dspi_resume(struct device *dev)
422{ 422{
423
424 struct spi_master *master = dev_get_drvdata(dev); 423 struct spi_master *master = dev_get_drvdata(dev);
425 struct fsl_dspi *dspi = spi_master_get_devdata(master); 424 struct fsl_dspi *dspi = spi_master_get_devdata(master);
426 425
@@ -504,7 +503,7 @@ static int dspi_probe(struct platform_device *pdev)
504 clk_prepare_enable(dspi->clk); 503 clk_prepare_enable(dspi->clk);
505 504
506 init_waitqueue_head(&dspi->waitq); 505 init_waitqueue_head(&dspi->waitq);
507 platform_set_drvdata(pdev, dspi); 506 platform_set_drvdata(pdev, master);
508 507
509 ret = spi_bitbang_start(&dspi->bitbang); 508 ret = spi_bitbang_start(&dspi->bitbang);
510 if (ret != 0) { 509 if (ret != 0) {
@@ -525,7 +524,8 @@ out_master_put:
525 524
526static int dspi_remove(struct platform_device *pdev) 525static int dspi_remove(struct platform_device *pdev)
527{ 526{
528 struct fsl_dspi *dspi = platform_get_drvdata(pdev); 527 struct spi_master *master = platform_get_drvdata(pdev);
528 struct fsl_dspi *dspi = spi_master_get_devdata(master);
529 529
530 /* Disconnect from the SPI framework */ 530 /* Disconnect from the SPI framework */
531 spi_bitbang_stop(&dspi->bitbang); 531 spi_bitbang_stop(&dspi->bitbang);
diff --git a/drivers/spi/spi-imx.c b/drivers/spi/spi-imx.c
index a5474ef9d2a0..47f15d97e7fa 100644
--- a/drivers/spi/spi-imx.c
+++ b/drivers/spi/spi-imx.c
@@ -948,8 +948,8 @@ static int spi_imx_remove(struct platform_device *pdev)
948 spi_bitbang_stop(&spi_imx->bitbang); 948 spi_bitbang_stop(&spi_imx->bitbang);
949 949
950 writel(0, spi_imx->base + MXC_CSPICTRL); 950 writel(0, spi_imx->base + MXC_CSPICTRL);
951 clk_disable_unprepare(spi_imx->clk_ipg); 951 clk_unprepare(spi_imx->clk_ipg);
952 clk_disable_unprepare(spi_imx->clk_per); 952 clk_unprepare(spi_imx->clk_per);
953 spi_master_put(master); 953 spi_master_put(master);
954 954
955 return 0; 955 return 0;
diff --git a/drivers/spi/spi-topcliff-pch.c b/drivers/spi/spi-topcliff-pch.c
index 2e7f38c7a961..88eb57e858b3 100644
--- a/drivers/spi/spi-topcliff-pch.c
+++ b/drivers/spi/spi-topcliff-pch.c
@@ -915,7 +915,7 @@ static void pch_spi_request_dma(struct pch_spi_data *data, int bpw)
915 /* Set Tx DMA */ 915 /* Set Tx DMA */
916 param = &dma->param_tx; 916 param = &dma->param_tx;
917 param->dma_dev = &dma_dev->dev; 917 param->dma_dev = &dma_dev->dev;
918 param->chan_id = data->master->bus_num * 2; /* Tx = 0, 2 */ 918 param->chan_id = data->ch * 2; /* Tx = 0, 2 */;
919 param->tx_reg = data->io_base_addr + PCH_SPDWR; 919 param->tx_reg = data->io_base_addr + PCH_SPDWR;
920 param->width = width; 920 param->width = width;
921 chan = dma_request_channel(mask, pch_spi_filter, param); 921 chan = dma_request_channel(mask, pch_spi_filter, param);
@@ -930,7 +930,7 @@ static void pch_spi_request_dma(struct pch_spi_data *data, int bpw)
930 /* Set Rx DMA */ 930 /* Set Rx DMA */
931 param = &dma->param_rx; 931 param = &dma->param_rx;
932 param->dma_dev = &dma_dev->dev; 932 param->dma_dev = &dma_dev->dev;
933 param->chan_id = data->master->bus_num * 2 + 1; /* Rx = Tx + 1 */ 933 param->chan_id = data->ch * 2 + 1; /* Rx = Tx + 1 */;
934 param->rx_reg = data->io_base_addr + PCH_SPDRR; 934 param->rx_reg = data->io_base_addr + PCH_SPDRR;
935 param->width = width; 935 param->width = width;
936 chan = dma_request_channel(mask, pch_spi_filter, param); 936 chan = dma_request_channel(mask, pch_spi_filter, param);
@@ -1452,6 +1452,11 @@ static int pch_spi_pd_probe(struct platform_device *plat_dev)
1452 1452
1453 pch_spi_set_master_mode(master); 1453 pch_spi_set_master_mode(master);
1454 1454
1455 if (use_dma) {
1456 dev_info(&plat_dev->dev, "Use DMA for data transfers\n");
1457 pch_alloc_dma_buf(board_dat, data);
1458 }
1459
1455 ret = spi_register_master(master); 1460 ret = spi_register_master(master);
1456 if (ret != 0) { 1461 if (ret != 0) {
1457 dev_err(&plat_dev->dev, 1462 dev_err(&plat_dev->dev,
@@ -1459,14 +1464,10 @@ static int pch_spi_pd_probe(struct platform_device *plat_dev)
1459 goto err_spi_register_master; 1464 goto err_spi_register_master;
1460 } 1465 }
1461 1466
1462 if (use_dma) {
1463 dev_info(&plat_dev->dev, "Use DMA for data transfers\n");
1464 pch_alloc_dma_buf(board_dat, data);
1465 }
1466
1467 return 0; 1467 return 0;
1468 1468
1469err_spi_register_master: 1469err_spi_register_master:
1470 pch_free_dma_buf(board_dat, data);
1470 free_irq(board_dat->pdev->irq, data); 1471 free_irq(board_dat->pdev->irq, data);
1471err_request_irq: 1472err_request_irq:
1472 pch_spi_free_resources(board_dat, data); 1473 pch_spi_free_resources(board_dat, data);
diff --git a/drivers/staging/cxt1e1/linux.c b/drivers/staging/cxt1e1/linux.c
index 4a08e16e42f7..79206cb3fb94 100644
--- a/drivers/staging/cxt1e1/linux.c
+++ b/drivers/staging/cxt1e1/linux.c
@@ -866,6 +866,8 @@ c4_ioctl (struct net_device *ndev, struct ifreq *ifr, int cmd)
866 _IOC_SIZE (iocmd)); 866 _IOC_SIZE (iocmd));
867#endif 867#endif
868 iolen = _IOC_SIZE (iocmd); 868 iolen = _IOC_SIZE (iocmd);
869 if (iolen > sizeof(arg))
870 return -EFAULT;
869 data = ifr->ifr_data + sizeof (iocmd); 871 data = ifr->ifr_data + sizeof (iocmd);
870 if (copy_from_user (&arg, data, iolen)) 872 if (copy_from_user (&arg, data, iolen))
871 return -EFAULT; 873 return -EFAULT;
diff --git a/drivers/staging/fwserial/fwserial.c b/drivers/staging/fwserial/fwserial.c
index 8af136e9c9dc..b22142ee5262 100644
--- a/drivers/staging/fwserial/fwserial.c
+++ b/drivers/staging/fwserial/fwserial.c
@@ -2036,6 +2036,13 @@ static void fwserial_auto_connect(struct work_struct *work)
2036 schedule_delayed_work(&peer->connect, CONNECT_RETRY_DELAY); 2036 schedule_delayed_work(&peer->connect, CONNECT_RETRY_DELAY);
2037} 2037}
2038 2038
2039static void fwserial_peer_workfn(struct work_struct *work)
2040{
2041 struct fwtty_peer *peer = to_peer(work, work);
2042
2043 peer->workfn(work);
2044}
2045
2039/** 2046/**
2040 * fwserial_add_peer - add a newly probed 'serial' unit device as a 'peer' 2047 * fwserial_add_peer - add a newly probed 'serial' unit device as a 'peer'
2041 * @serial: aggregate representing the specific fw_card to add the peer to 2048 * @serial: aggregate representing the specific fw_card to add the peer to
@@ -2100,7 +2107,7 @@ static int fwserial_add_peer(struct fw_serial *serial, struct fw_unit *unit)
2100 peer->port = NULL; 2107 peer->port = NULL;
2101 2108
2102 init_timer(&peer->timer); 2109 init_timer(&peer->timer);
2103 INIT_WORK(&peer->work, NULL); 2110 INIT_WORK(&peer->work, fwserial_peer_workfn);
2104 INIT_DELAYED_WORK(&peer->connect, fwserial_auto_connect); 2111 INIT_DELAYED_WORK(&peer->connect, fwserial_auto_connect);
2105 2112
2106 /* associate peer with specific fw_card */ 2113 /* associate peer with specific fw_card */
@@ -2702,7 +2709,7 @@ static int fwserial_parse_mgmt_write(struct fwtty_peer *peer,
2702 2709
2703 } else { 2710 } else {
2704 peer->work_params.plug_req = pkt->plug_req; 2711 peer->work_params.plug_req = pkt->plug_req;
2705 PREPARE_WORK(&peer->work, fwserial_handle_plug_req); 2712 peer->workfn = fwserial_handle_plug_req;
2706 queue_work(system_unbound_wq, &peer->work); 2713 queue_work(system_unbound_wq, &peer->work);
2707 } 2714 }
2708 break; 2715 break;
@@ -2731,7 +2738,7 @@ static int fwserial_parse_mgmt_write(struct fwtty_peer *peer,
2731 fwtty_err(&peer->unit, "unplug req: busy\n"); 2738 fwtty_err(&peer->unit, "unplug req: busy\n");
2732 rcode = RCODE_CONFLICT_ERROR; 2739 rcode = RCODE_CONFLICT_ERROR;
2733 } else { 2740 } else {
2734 PREPARE_WORK(&peer->work, fwserial_handle_unplug_req); 2741 peer->workfn = fwserial_handle_unplug_req;
2735 queue_work(system_unbound_wq, &peer->work); 2742 queue_work(system_unbound_wq, &peer->work);
2736 } 2743 }
2737 break; 2744 break;
diff --git a/drivers/staging/fwserial/fwserial.h b/drivers/staging/fwserial/fwserial.h
index 54f7f9b9b212..98b853d4acbc 100644
--- a/drivers/staging/fwserial/fwserial.h
+++ b/drivers/staging/fwserial/fwserial.h
@@ -91,6 +91,7 @@ struct fwtty_peer {
91 struct rcu_head rcu; 91 struct rcu_head rcu;
92 92
93 spinlock_t lock; 93 spinlock_t lock;
94 work_func_t workfn;
94 struct work_struct work; 95 struct work_struct work;
95 struct peer_work_params work_params; 96 struct peer_work_params work_params;
96 struct timer_list timer; 97 struct timer_list timer;
diff --git a/drivers/staging/iio/adc/mxs-lradc.c b/drivers/staging/iio/adc/mxs-lradc.c
index 7fc66a6a6e36..514844efac75 100644
--- a/drivers/staging/iio/adc/mxs-lradc.c
+++ b/drivers/staging/iio/adc/mxs-lradc.c
@@ -757,6 +757,7 @@ static void mxs_lradc_finish_touch_event(struct mxs_lradc *lradc, bool valid)
757 } 757 }
758 758
759 /* if it is released, wait for the next touch via IRQ */ 759 /* if it is released, wait for the next touch via IRQ */
760 lradc->cur_plate = LRADC_TOUCH;
760 mxs_lradc_reg_clear(lradc, LRADC_CTRL1_TOUCH_DETECT_IRQ, LRADC_CTRL1); 761 mxs_lradc_reg_clear(lradc, LRADC_CTRL1_TOUCH_DETECT_IRQ, LRADC_CTRL1);
761 mxs_lradc_reg_set(lradc, LRADC_CTRL1_TOUCH_DETECT_IRQ_EN, LRADC_CTRL1); 762 mxs_lradc_reg_set(lradc, LRADC_CTRL1_TOUCH_DETECT_IRQ_EN, LRADC_CTRL1);
762} 763}
diff --git a/drivers/staging/rtl8188eu/os_dep/usb_intf.c b/drivers/staging/rtl8188eu/os_dep/usb_intf.c
index a70dcef1419e..2f40ff5901d6 100644
--- a/drivers/staging/rtl8188eu/os_dep/usb_intf.c
+++ b/drivers/staging/rtl8188eu/os_dep/usb_intf.c
@@ -55,6 +55,7 @@ static struct usb_device_id rtw_usb_id_tbl[] = {
55 /****** 8188EUS ********/ 55 /****** 8188EUS ********/
56 {USB_DEVICE(0x07b8, 0x8179)}, /* Abocom - Abocom */ 56 {USB_DEVICE(0x07b8, 0x8179)}, /* Abocom - Abocom */
57 {USB_DEVICE(0x2001, 0x330F)}, /* DLink DWA-125 REV D1 */ 57 {USB_DEVICE(0x2001, 0x330F)}, /* DLink DWA-125 REV D1 */
58 {USB_DEVICE(0x2001, 0x3310)}, /* Dlink DWA-123 REV D1 */
58 {} /* Terminating entry */ 59 {} /* Terminating entry */
59}; 60};
60 61
diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c
index 7f1a7ce4b771..b83ec378d04f 100644
--- a/drivers/target/iscsi/iscsi_target.c
+++ b/drivers/target/iscsi/iscsi_target.c
@@ -785,7 +785,7 @@ static void iscsit_ack_from_expstatsn(struct iscsi_conn *conn, u32 exp_statsn)
785 spin_unlock_bh(&conn->cmd_lock); 785 spin_unlock_bh(&conn->cmd_lock);
786 786
787 list_for_each_entry_safe(cmd, cmd_p, &ack_list, i_conn_node) { 787 list_for_each_entry_safe(cmd, cmd_p, &ack_list, i_conn_node) {
788 list_del(&cmd->i_conn_node); 788 list_del_init(&cmd->i_conn_node);
789 iscsit_free_cmd(cmd, false); 789 iscsit_free_cmd(cmd, false);
790 } 790 }
791} 791}
@@ -3708,7 +3708,7 @@ iscsit_immediate_queue(struct iscsi_conn *conn, struct iscsi_cmd *cmd, int state
3708 break; 3708 break;
3709 case ISTATE_REMOVE: 3709 case ISTATE_REMOVE:
3710 spin_lock_bh(&conn->cmd_lock); 3710 spin_lock_bh(&conn->cmd_lock);
3711 list_del(&cmd->i_conn_node); 3711 list_del_init(&cmd->i_conn_node);
3712 spin_unlock_bh(&conn->cmd_lock); 3712 spin_unlock_bh(&conn->cmd_lock);
3713 3713
3714 iscsit_free_cmd(cmd, false); 3714 iscsit_free_cmd(cmd, false);
@@ -4151,7 +4151,7 @@ static void iscsit_release_commands_from_conn(struct iscsi_conn *conn)
4151 spin_lock_bh(&conn->cmd_lock); 4151 spin_lock_bh(&conn->cmd_lock);
4152 list_for_each_entry_safe(cmd, cmd_tmp, &conn->conn_cmd_list, i_conn_node) { 4152 list_for_each_entry_safe(cmd, cmd_tmp, &conn->conn_cmd_list, i_conn_node) {
4153 4153
4154 list_del(&cmd->i_conn_node); 4154 list_del_init(&cmd->i_conn_node);
4155 spin_unlock_bh(&conn->cmd_lock); 4155 spin_unlock_bh(&conn->cmd_lock);
4156 4156
4157 iscsit_increment_maxcmdsn(cmd, sess); 4157 iscsit_increment_maxcmdsn(cmd, sess);
@@ -4196,6 +4196,10 @@ int iscsit_close_connection(
4196 iscsit_stop_timers_for_cmds(conn); 4196 iscsit_stop_timers_for_cmds(conn);
4197 iscsit_stop_nopin_response_timer(conn); 4197 iscsit_stop_nopin_response_timer(conn);
4198 iscsit_stop_nopin_timer(conn); 4198 iscsit_stop_nopin_timer(conn);
4199
4200 if (conn->conn_transport->iscsit_wait_conn)
4201 conn->conn_transport->iscsit_wait_conn(conn);
4202
4199 iscsit_free_queue_reqs_for_conn(conn); 4203 iscsit_free_queue_reqs_for_conn(conn);
4200 4204
4201 /* 4205 /*
diff --git a/drivers/target/iscsi/iscsi_target_erl2.c b/drivers/target/iscsi/iscsi_target_erl2.c
index 33be1fb1df32..4ca8fd2a70db 100644
--- a/drivers/target/iscsi/iscsi_target_erl2.c
+++ b/drivers/target/iscsi/iscsi_target_erl2.c
@@ -138,7 +138,7 @@ void iscsit_free_connection_recovery_entires(struct iscsi_session *sess)
138 list_for_each_entry_safe(cmd, cmd_tmp, 138 list_for_each_entry_safe(cmd, cmd_tmp,
139 &cr->conn_recovery_cmd_list, i_conn_node) { 139 &cr->conn_recovery_cmd_list, i_conn_node) {
140 140
141 list_del(&cmd->i_conn_node); 141 list_del_init(&cmd->i_conn_node);
142 cmd->conn = NULL; 142 cmd->conn = NULL;
143 spin_unlock(&cr->conn_recovery_cmd_lock); 143 spin_unlock(&cr->conn_recovery_cmd_lock);
144 iscsit_free_cmd(cmd, true); 144 iscsit_free_cmd(cmd, true);
@@ -160,7 +160,7 @@ void iscsit_free_connection_recovery_entires(struct iscsi_session *sess)
160 list_for_each_entry_safe(cmd, cmd_tmp, 160 list_for_each_entry_safe(cmd, cmd_tmp,
161 &cr->conn_recovery_cmd_list, i_conn_node) { 161 &cr->conn_recovery_cmd_list, i_conn_node) {
162 162
163 list_del(&cmd->i_conn_node); 163 list_del_init(&cmd->i_conn_node);
164 cmd->conn = NULL; 164 cmd->conn = NULL;
165 spin_unlock(&cr->conn_recovery_cmd_lock); 165 spin_unlock(&cr->conn_recovery_cmd_lock);
166 iscsit_free_cmd(cmd, true); 166 iscsit_free_cmd(cmd, true);
@@ -216,7 +216,7 @@ int iscsit_remove_cmd_from_connection_recovery(
216 } 216 }
217 cr = cmd->cr; 217 cr = cmd->cr;
218 218
219 list_del(&cmd->i_conn_node); 219 list_del_init(&cmd->i_conn_node);
220 return --cr->cmd_count; 220 return --cr->cmd_count;
221} 221}
222 222
@@ -297,7 +297,7 @@ int iscsit_discard_unacknowledged_ooo_cmdsns_for_conn(struct iscsi_conn *conn)
297 if (!(cmd->cmd_flags & ICF_OOO_CMDSN)) 297 if (!(cmd->cmd_flags & ICF_OOO_CMDSN))
298 continue; 298 continue;
299 299
300 list_del(&cmd->i_conn_node); 300 list_del_init(&cmd->i_conn_node);
301 301
302 spin_unlock_bh(&conn->cmd_lock); 302 spin_unlock_bh(&conn->cmd_lock);
303 iscsit_free_cmd(cmd, true); 303 iscsit_free_cmd(cmd, true);
@@ -335,7 +335,7 @@ int iscsit_prepare_cmds_for_realligance(struct iscsi_conn *conn)
335 /* 335 /*
336 * Only perform connection recovery on ISCSI_OP_SCSI_CMD or 336 * Only perform connection recovery on ISCSI_OP_SCSI_CMD or
337 * ISCSI_OP_NOOP_OUT opcodes. For all other opcodes call 337 * ISCSI_OP_NOOP_OUT opcodes. For all other opcodes call
338 * list_del(&cmd->i_conn_node); to release the command to the 338 * list_del_init(&cmd->i_conn_node); to release the command to the
339 * session pool and remove it from the connection's list. 339 * session pool and remove it from the connection's list.
340 * 340 *
341 * Also stop the DataOUT timer, which will be restarted after 341 * Also stop the DataOUT timer, which will be restarted after
@@ -351,7 +351,7 @@ int iscsit_prepare_cmds_for_realligance(struct iscsi_conn *conn)
351 " CID: %hu\n", cmd->iscsi_opcode, 351 " CID: %hu\n", cmd->iscsi_opcode,
352 cmd->init_task_tag, cmd->cmd_sn, conn->cid); 352 cmd->init_task_tag, cmd->cmd_sn, conn->cid);
353 353
354 list_del(&cmd->i_conn_node); 354 list_del_init(&cmd->i_conn_node);
355 spin_unlock_bh(&conn->cmd_lock); 355 spin_unlock_bh(&conn->cmd_lock);
356 iscsit_free_cmd(cmd, true); 356 iscsit_free_cmd(cmd, true);
357 spin_lock_bh(&conn->cmd_lock); 357 spin_lock_bh(&conn->cmd_lock);
@@ -371,7 +371,7 @@ int iscsit_prepare_cmds_for_realligance(struct iscsi_conn *conn)
371 */ 371 */
372 if (!(cmd->cmd_flags & ICF_OOO_CMDSN) && !cmd->immediate_cmd && 372 if (!(cmd->cmd_flags & ICF_OOO_CMDSN) && !cmd->immediate_cmd &&
373 iscsi_sna_gte(cmd->cmd_sn, conn->sess->exp_cmd_sn)) { 373 iscsi_sna_gte(cmd->cmd_sn, conn->sess->exp_cmd_sn)) {
374 list_del(&cmd->i_conn_node); 374 list_del_init(&cmd->i_conn_node);
375 spin_unlock_bh(&conn->cmd_lock); 375 spin_unlock_bh(&conn->cmd_lock);
376 iscsit_free_cmd(cmd, true); 376 iscsit_free_cmd(cmd, true);
377 spin_lock_bh(&conn->cmd_lock); 377 spin_lock_bh(&conn->cmd_lock);
@@ -393,7 +393,7 @@ int iscsit_prepare_cmds_for_realligance(struct iscsi_conn *conn)
393 393
394 cmd->sess = conn->sess; 394 cmd->sess = conn->sess;
395 395
396 list_del(&cmd->i_conn_node); 396 list_del_init(&cmd->i_conn_node);
397 spin_unlock_bh(&conn->cmd_lock); 397 spin_unlock_bh(&conn->cmd_lock);
398 398
399 iscsit_free_all_datain_reqs(cmd); 399 iscsit_free_all_datain_reqs(cmd);
diff --git a/drivers/target/iscsi/iscsi_target_tpg.c b/drivers/target/iscsi/iscsi_target_tpg.c
index 39761837608d..44a5471de00f 100644
--- a/drivers/target/iscsi/iscsi_target_tpg.c
+++ b/drivers/target/iscsi/iscsi_target_tpg.c
@@ -137,7 +137,7 @@ struct iscsi_portal_group *iscsit_get_tpg_from_np(
137 list_for_each_entry(tpg, &tiqn->tiqn_tpg_list, tpg_list) { 137 list_for_each_entry(tpg, &tiqn->tiqn_tpg_list, tpg_list) {
138 138
139 spin_lock(&tpg->tpg_state_lock); 139 spin_lock(&tpg->tpg_state_lock);
140 if (tpg->tpg_state == TPG_STATE_FREE) { 140 if (tpg->tpg_state != TPG_STATE_ACTIVE) {
141 spin_unlock(&tpg->tpg_state_lock); 141 spin_unlock(&tpg->tpg_state_lock);
142 continue; 142 continue;
143 } 143 }
diff --git a/drivers/target/target_core_sbc.c b/drivers/target/target_core_sbc.c
index a4489444ffbc..77e6531fb0a1 100644
--- a/drivers/target/target_core_sbc.c
+++ b/drivers/target/target_core_sbc.c
@@ -1074,31 +1074,36 @@ sbc_dif_copy_prot(struct se_cmd *cmd, unsigned int sectors, bool read,
1074 struct scatterlist *psg; 1074 struct scatterlist *psg;
1075 void *paddr, *addr; 1075 void *paddr, *addr;
1076 unsigned int i, len, left; 1076 unsigned int i, len, left;
1077 unsigned int offset = 0; 1077 unsigned int offset = sg_off;
1078 1078
1079 left = sectors * dev->prot_length; 1079 left = sectors * dev->prot_length;
1080 1080
1081 for_each_sg(cmd->t_prot_sg, psg, cmd->t_prot_nents, i) { 1081 for_each_sg(cmd->t_prot_sg, psg, cmd->t_prot_nents, i) {
1082 1082 unsigned int psg_len, copied = 0;
1083 len = min(psg->length, left);
1084 if (offset >= sg->length) {
1085 sg = sg_next(sg);
1086 offset = 0;
1087 sg_off = sg->offset;
1088 }
1089 1083
1090 paddr = kmap_atomic(sg_page(psg)) + psg->offset; 1084 paddr = kmap_atomic(sg_page(psg)) + psg->offset;
1091 addr = kmap_atomic(sg_page(sg)) + sg_off; 1085 psg_len = min(left, psg->length);
1086 while (psg_len) {
1087 len = min(psg_len, sg->length - offset);
1088 addr = kmap_atomic(sg_page(sg)) + sg->offset + offset;
1092 1089
1093 if (read) 1090 if (read)
1094 memcpy(paddr, addr, len); 1091 memcpy(paddr + copied, addr, len);
1095 else 1092 else
1096 memcpy(addr, paddr, len); 1093 memcpy(addr, paddr + copied, len);
1097 1094
1098 left -= len; 1095 left -= len;
1099 offset += len; 1096 offset += len;
1097 copied += len;
1098 psg_len -= len;
1099
1100 if (offset >= sg->length) {
1101 sg = sg_next(sg);
1102 offset = 0;
1103 }
1104 kunmap_atomic(addr);
1105 }
1100 kunmap_atomic(paddr); 1106 kunmap_atomic(paddr);
1101 kunmap_atomic(addr);
1102 } 1107 }
1103} 1108}
1104 1109
@@ -1163,7 +1168,7 @@ sbc_dif_verify_read(struct se_cmd *cmd, sector_t start, unsigned int sectors,
1163{ 1168{
1164 struct se_device *dev = cmd->se_dev; 1169 struct se_device *dev = cmd->se_dev;
1165 struct se_dif_v1_tuple *sdt; 1170 struct se_dif_v1_tuple *sdt;
1166 struct scatterlist *dsg; 1171 struct scatterlist *dsg, *psg = sg;
1167 sector_t sector = start; 1172 sector_t sector = start;
1168 void *daddr, *paddr; 1173 void *daddr, *paddr;
1169 int i, j, offset = sg_off; 1174 int i, j, offset = sg_off;
@@ -1171,14 +1176,14 @@ sbc_dif_verify_read(struct se_cmd *cmd, sector_t start, unsigned int sectors,
1171 1176
1172 for_each_sg(cmd->t_data_sg, dsg, cmd->t_data_nents, i) { 1177 for_each_sg(cmd->t_data_sg, dsg, cmd->t_data_nents, i) {
1173 daddr = kmap_atomic(sg_page(dsg)) + dsg->offset; 1178 daddr = kmap_atomic(sg_page(dsg)) + dsg->offset;
1174 paddr = kmap_atomic(sg_page(sg)) + sg->offset; 1179 paddr = kmap_atomic(sg_page(psg)) + sg->offset;
1175 1180
1176 for (j = 0; j < dsg->length; j += dev->dev_attrib.block_size) { 1181 for (j = 0; j < dsg->length; j += dev->dev_attrib.block_size) {
1177 1182
1178 if (offset >= sg->length) { 1183 if (offset >= psg->length) {
1179 kunmap_atomic(paddr); 1184 kunmap_atomic(paddr);
1180 sg = sg_next(sg); 1185 psg = sg_next(psg);
1181 paddr = kmap_atomic(sg_page(sg)) + sg->offset; 1186 paddr = kmap_atomic(sg_page(psg)) + psg->offset;
1182 offset = 0; 1187 offset = 0;
1183 } 1188 }
1184 1189
diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
index 24b4f65d8777..2956250b7225 100644
--- a/drivers/target/target_core_transport.c
+++ b/drivers/target/target_core_transport.c
@@ -1601,6 +1601,9 @@ void transport_generic_request_failure(struct se_cmd *cmd,
1601 case TCM_CHECK_CONDITION_ABORT_CMD: 1601 case TCM_CHECK_CONDITION_ABORT_CMD:
1602 case TCM_CHECK_CONDITION_UNIT_ATTENTION: 1602 case TCM_CHECK_CONDITION_UNIT_ATTENTION:
1603 case TCM_CHECK_CONDITION_NOT_READY: 1603 case TCM_CHECK_CONDITION_NOT_READY:
1604 case TCM_LOGICAL_BLOCK_GUARD_CHECK_FAILED:
1605 case TCM_LOGICAL_BLOCK_APP_TAG_CHECK_FAILED:
1606 case TCM_LOGICAL_BLOCK_REF_TAG_CHECK_FAILED:
1604 break; 1607 break;
1605 case TCM_OUT_OF_RESOURCES: 1608 case TCM_OUT_OF_RESOURCES:
1606 sense_reason = TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; 1609 sense_reason = TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
diff --git a/drivers/thermal/Kconfig b/drivers/thermal/Kconfig
index 35c066489a19..5f88d767671e 100644
--- a/drivers/thermal/Kconfig
+++ b/drivers/thermal/Kconfig
@@ -136,6 +136,7 @@ config SPEAR_THERMAL
136config RCAR_THERMAL 136config RCAR_THERMAL
137 tristate "Renesas R-Car thermal driver" 137 tristate "Renesas R-Car thermal driver"
138 depends on ARCH_SHMOBILE || COMPILE_TEST 138 depends on ARCH_SHMOBILE || COMPILE_TEST
139 depends on HAS_IOMEM
139 help 140 help
140 Enable this to plug the R-Car thermal sensor driver into the Linux 141 Enable this to plug the R-Car thermal sensor driver into the Linux
141 thermal framework. 142 thermal framework.
@@ -210,8 +211,16 @@ config ACPI_INT3403_THERMAL
210 tristate "ACPI INT3403 thermal driver" 211 tristate "ACPI INT3403 thermal driver"
211 depends on X86 && ACPI 212 depends on X86 && ACPI
212 help 213 help
213 This driver uses ACPI INT3403 device objects. If present, it will 214 Newer laptops and tablets that use ACPI may have thermal sensors
214 register each INT3403 thermal sensor as a thermal zone. 215 outside the core CPU/SOC for thermal safety reasons. These
216 temperature sensors are also exposed for the OS to use via the so
217 called INT3403 ACPI object. This driver will, on devices that have
218 such sensors, expose the temperature information from these sensors
219 to userspace via the normal thermal framework. This means that a wide
220 range of applications and GUI widgets can show this information to
221 the user or use this information for making decisions. For example,
222 the Intel Thermal Daemon can use this information to allow the user
223 to select his laptop to run without turning on the fans.
215 224
216menu "Texas Instruments thermal drivers" 225menu "Texas Instruments thermal drivers"
217source "drivers/thermal/ti-soc-thermal/Kconfig" 226source "drivers/thermal/ti-soc-thermal/Kconfig"
diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index 338a88bf6662..71b0ec0c370d 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -56,10 +56,15 @@ static LIST_HEAD(thermal_governor_list);
56static DEFINE_MUTEX(thermal_list_lock); 56static DEFINE_MUTEX(thermal_list_lock);
57static DEFINE_MUTEX(thermal_governor_lock); 57static DEFINE_MUTEX(thermal_governor_lock);
58 58
59static struct thermal_governor *def_governor;
60
59static struct thermal_governor *__find_governor(const char *name) 61static struct thermal_governor *__find_governor(const char *name)
60{ 62{
61 struct thermal_governor *pos; 63 struct thermal_governor *pos;
62 64
65 if (!name || !name[0])
66 return def_governor;
67
63 list_for_each_entry(pos, &thermal_governor_list, governor_list) 68 list_for_each_entry(pos, &thermal_governor_list, governor_list)
64 if (!strnicmp(name, pos->name, THERMAL_NAME_LENGTH)) 69 if (!strnicmp(name, pos->name, THERMAL_NAME_LENGTH))
65 return pos; 70 return pos;
@@ -82,17 +87,23 @@ int thermal_register_governor(struct thermal_governor *governor)
82 if (__find_governor(governor->name) == NULL) { 87 if (__find_governor(governor->name) == NULL) {
83 err = 0; 88 err = 0;
84 list_add(&governor->governor_list, &thermal_governor_list); 89 list_add(&governor->governor_list, &thermal_governor_list);
90 if (!def_governor && !strncmp(governor->name,
91 DEFAULT_THERMAL_GOVERNOR, THERMAL_NAME_LENGTH))
92 def_governor = governor;
85 } 93 }
86 94
87 mutex_lock(&thermal_list_lock); 95 mutex_lock(&thermal_list_lock);
88 96
89 list_for_each_entry(pos, &thermal_tz_list, node) { 97 list_for_each_entry(pos, &thermal_tz_list, node) {
98 /*
99 * only thermal zones with specified tz->tzp->governor_name
100 * may run with tz->govenor unset
101 */
90 if (pos->governor) 102 if (pos->governor)
91 continue; 103 continue;
92 if (pos->tzp) 104
93 name = pos->tzp->governor_name; 105 name = pos->tzp->governor_name;
94 else 106
95 name = DEFAULT_THERMAL_GOVERNOR;
96 if (!strnicmp(name, governor->name, THERMAL_NAME_LENGTH)) 107 if (!strnicmp(name, governor->name, THERMAL_NAME_LENGTH))
97 pos->governor = governor; 108 pos->governor = governor;
98 } 109 }
@@ -342,8 +353,8 @@ static void monitor_thermal_zone(struct thermal_zone_device *tz)
342static void handle_non_critical_trips(struct thermal_zone_device *tz, 353static void handle_non_critical_trips(struct thermal_zone_device *tz,
343 int trip, enum thermal_trip_type trip_type) 354 int trip, enum thermal_trip_type trip_type)
344{ 355{
345 if (tz->governor) 356 tz->governor ? tz->governor->throttle(tz, trip) :
346 tz->governor->throttle(tz, trip); 357 def_governor->throttle(tz, trip);
347} 358}
348 359
349static void handle_critical_trips(struct thermal_zone_device *tz, 360static void handle_critical_trips(struct thermal_zone_device *tz,
@@ -1107,7 +1118,7 @@ __thermal_cooling_device_register(struct device_node *np,
1107 INIT_LIST_HEAD(&cdev->thermal_instances); 1118 INIT_LIST_HEAD(&cdev->thermal_instances);
1108 cdev->np = np; 1119 cdev->np = np;
1109 cdev->ops = ops; 1120 cdev->ops = ops;
1110 cdev->updated = true; 1121 cdev->updated = false;
1111 cdev->device.class = &thermal_class; 1122 cdev->device.class = &thermal_class;
1112 cdev->devdata = devdata; 1123 cdev->devdata = devdata;
1113 dev_set_name(&cdev->device, "cooling_device%d", cdev->id); 1124 dev_set_name(&cdev->device, "cooling_device%d", cdev->id);
@@ -1533,7 +1544,7 @@ struct thermal_zone_device *thermal_zone_device_register(const char *type,
1533 if (tz->tzp) 1544 if (tz->tzp)
1534 tz->governor = __find_governor(tz->tzp->governor_name); 1545 tz->governor = __find_governor(tz->tzp->governor_name);
1535 else 1546 else
1536 tz->governor = __find_governor(DEFAULT_THERMAL_GOVERNOR); 1547 tz->governor = def_governor;
1537 1548
1538 mutex_unlock(&thermal_governor_lock); 1549 mutex_unlock(&thermal_governor_lock);
1539 1550
diff --git a/drivers/thermal/x86_pkg_temp_thermal.c b/drivers/thermal/x86_pkg_temp_thermal.c
index 972e1c73722a..081fd7e6a9f0 100644
--- a/drivers/thermal/x86_pkg_temp_thermal.c
+++ b/drivers/thermal/x86_pkg_temp_thermal.c
@@ -68,6 +68,10 @@ struct phy_dev_entry {
68 struct thermal_zone_device *tzone; 68 struct thermal_zone_device *tzone;
69}; 69};
70 70
71static const struct thermal_zone_params pkg_temp_tz_params = {
72 .no_hwmon = true,
73};
74
71/* List maintaining number of package instances */ 75/* List maintaining number of package instances */
72static LIST_HEAD(phy_dev_list); 76static LIST_HEAD(phy_dev_list);
73static DEFINE_MUTEX(phy_dev_list_mutex); 77static DEFINE_MUTEX(phy_dev_list_mutex);
@@ -394,7 +398,6 @@ static int pkg_temp_thermal_device_add(unsigned int cpu)
394 int err; 398 int err;
395 u32 tj_max; 399 u32 tj_max;
396 struct phy_dev_entry *phy_dev_entry; 400 struct phy_dev_entry *phy_dev_entry;
397 char buffer[30];
398 int thres_count; 401 int thres_count;
399 u32 eax, ebx, ecx, edx; 402 u32 eax, ebx, ecx, edx;
400 u8 *temp; 403 u8 *temp;
@@ -440,13 +443,11 @@ static int pkg_temp_thermal_device_add(unsigned int cpu)
440 phy_dev_entry->first_cpu = cpu; 443 phy_dev_entry->first_cpu = cpu;
441 phy_dev_entry->tj_max = tj_max; 444 phy_dev_entry->tj_max = tj_max;
442 phy_dev_entry->ref_cnt = 1; 445 phy_dev_entry->ref_cnt = 1;
443 snprintf(buffer, sizeof(buffer), "pkg-temp-%d\n", 446 phy_dev_entry->tzone = thermal_zone_device_register("x86_pkg_temp",
444 phy_dev_entry->phys_proc_id);
445 phy_dev_entry->tzone = thermal_zone_device_register(buffer,
446 thres_count, 447 thres_count,
447 (thres_count == MAX_NUMBER_OF_TRIPS) ? 448 (thres_count == MAX_NUMBER_OF_TRIPS) ?
448 0x03 : 0x01, 449 0x03 : 0x01,
449 phy_dev_entry, &tzone_ops, NULL, 0, 0); 450 phy_dev_entry, &tzone_ops, &pkg_temp_tz_params, 0, 0);
450 if (IS_ERR(phy_dev_entry->tzone)) { 451 if (IS_ERR(phy_dev_entry->tzone)) {
451 err = PTR_ERR(phy_dev_entry->tzone); 452 err = PTR_ERR(phy_dev_entry->tzone);
452 goto err_ret_free; 453 goto err_ret_free;
diff --git a/drivers/tty/serial/sunhv.c b/drivers/tty/serial/sunhv.c
index cf86e729532b..dc697cee248a 100644
--- a/drivers/tty/serial/sunhv.c
+++ b/drivers/tty/serial/sunhv.c
@@ -433,13 +433,10 @@ static void sunhv_console_write_paged(struct console *con, const char *s, unsign
433 unsigned long flags; 433 unsigned long flags;
434 int locked = 1; 434 int locked = 1;
435 435
436 local_irq_save(flags); 436 if (port->sysrq || oops_in_progress)
437 if (port->sysrq) { 437 locked = spin_trylock_irqsave(&port->lock, flags);
438 locked = 0; 438 else
439 } else if (oops_in_progress) { 439 spin_lock_irqsave(&port->lock, flags);
440 locked = spin_trylock(&port->lock);
441 } else
442 spin_lock(&port->lock);
443 440
444 while (n > 0) { 441 while (n > 0) {
445 unsigned long ra = __pa(con_write_page); 442 unsigned long ra = __pa(con_write_page);
@@ -470,8 +467,7 @@ static void sunhv_console_write_paged(struct console *con, const char *s, unsign
470 } 467 }
471 468
472 if (locked) 469 if (locked)
473 spin_unlock(&port->lock); 470 spin_unlock_irqrestore(&port->lock, flags);
474 local_irq_restore(flags);
475} 471}
476 472
477static inline void sunhv_console_putchar(struct uart_port *port, char c) 473static inline void sunhv_console_putchar(struct uart_port *port, char c)
@@ -492,7 +488,10 @@ static void sunhv_console_write_bychar(struct console *con, const char *s, unsig
492 unsigned long flags; 488 unsigned long flags;
493 int i, locked = 1; 489 int i, locked = 1;
494 490
495 local_irq_save(flags); 491 if (port->sysrq || oops_in_progress)
492 locked = spin_trylock_irqsave(&port->lock, flags);
493 else
494 spin_lock_irqsave(&port->lock, flags);
496 if (port->sysrq) { 495 if (port->sysrq) {
497 locked = 0; 496 locked = 0;
498 } else if (oops_in_progress) { 497 } else if (oops_in_progress) {
@@ -507,8 +506,7 @@ static void sunhv_console_write_bychar(struct console *con, const char *s, unsig
507 } 506 }
508 507
509 if (locked) 508 if (locked)
510 spin_unlock(&port->lock); 509 spin_unlock_irqrestore(&port->lock, flags);
511 local_irq_restore(flags);
512} 510}
513 511
514static struct console sunhv_console = { 512static struct console sunhv_console = {
diff --git a/drivers/tty/serial/sunsab.c b/drivers/tty/serial/sunsab.c
index 380fb5355cb2..5faa8e905e98 100644
--- a/drivers/tty/serial/sunsab.c
+++ b/drivers/tty/serial/sunsab.c
@@ -844,20 +844,16 @@ static void sunsab_console_write(struct console *con, const char *s, unsigned n)
844 unsigned long flags; 844 unsigned long flags;
845 int locked = 1; 845 int locked = 1;
846 846
847 local_irq_save(flags); 847 if (up->port.sysrq || oops_in_progress)
848 if (up->port.sysrq) { 848 locked = spin_trylock_irqsave(&up->port.lock, flags);
849 locked = 0; 849 else
850 } else if (oops_in_progress) { 850 spin_lock_irqsave(&up->port.lock, flags);
851 locked = spin_trylock(&up->port.lock);
852 } else
853 spin_lock(&up->port.lock);
854 851
855 uart_console_write(&up->port, s, n, sunsab_console_putchar); 852 uart_console_write(&up->port, s, n, sunsab_console_putchar);
856 sunsab_tec_wait(up); 853 sunsab_tec_wait(up);
857 854
858 if (locked) 855 if (locked)
859 spin_unlock(&up->port.lock); 856 spin_unlock_irqrestore(&up->port.lock, flags);
860 local_irq_restore(flags);
861} 857}
862 858
863static int sunsab_console_setup(struct console *con, char *options) 859static int sunsab_console_setup(struct console *con, char *options)
diff --git a/drivers/tty/serial/sunsu.c b/drivers/tty/serial/sunsu.c
index db79b76f5c8e..9a0f24f83720 100644
--- a/drivers/tty/serial/sunsu.c
+++ b/drivers/tty/serial/sunsu.c
@@ -1295,13 +1295,10 @@ static void sunsu_console_write(struct console *co, const char *s,
1295 unsigned int ier; 1295 unsigned int ier;
1296 int locked = 1; 1296 int locked = 1;
1297 1297
1298 local_irq_save(flags); 1298 if (up->port.sysrq || oops_in_progress)
1299 if (up->port.sysrq) { 1299 locked = spin_trylock_irqsave(&up->port.lock, flags);
1300 locked = 0; 1300 else
1301 } else if (oops_in_progress) { 1301 spin_lock_irqsave(&up->port.lock, flags);
1302 locked = spin_trylock(&up->port.lock);
1303 } else
1304 spin_lock(&up->port.lock);
1305 1302
1306 /* 1303 /*
1307 * First save the UER then disable the interrupts 1304 * First save the UER then disable the interrupts
@@ -1319,8 +1316,7 @@ static void sunsu_console_write(struct console *co, const char *s,
1319 serial_out(up, UART_IER, ier); 1316 serial_out(up, UART_IER, ier);
1320 1317
1321 if (locked) 1318 if (locked)
1322 spin_unlock(&up->port.lock); 1319 spin_unlock_irqrestore(&up->port.lock, flags);
1323 local_irq_restore(flags);
1324} 1320}
1325 1321
1326/* 1322/*
diff --git a/drivers/tty/serial/sunzilog.c b/drivers/tty/serial/sunzilog.c
index 45a8c6aa5837..a2c40ed287d2 100644
--- a/drivers/tty/serial/sunzilog.c
+++ b/drivers/tty/serial/sunzilog.c
@@ -1195,20 +1195,16 @@ sunzilog_console_write(struct console *con, const char *s, unsigned int count)
1195 unsigned long flags; 1195 unsigned long flags;
1196 int locked = 1; 1196 int locked = 1;
1197 1197
1198 local_irq_save(flags); 1198 if (up->port.sysrq || oops_in_progress)
1199 if (up->port.sysrq) { 1199 locked = spin_trylock_irqsave(&up->port.lock, flags);
1200 locked = 0; 1200 else
1201 } else if (oops_in_progress) { 1201 spin_lock_irqsave(&up->port.lock, flags);
1202 locked = spin_trylock(&up->port.lock);
1203 } else
1204 spin_lock(&up->port.lock);
1205 1202
1206 uart_console_write(&up->port, s, count, sunzilog_putchar); 1203 uart_console_write(&up->port, s, count, sunzilog_putchar);
1207 udelay(2); 1204 udelay(2);
1208 1205
1209 if (locked) 1206 if (locked)
1210 spin_unlock(&up->port.lock); 1207 spin_unlock_irqrestore(&up->port.lock, flags);
1211 local_irq_restore(flags);
1212} 1208}
1213 1209
1214static int __init sunzilog_console_setup(struct console *con, char *options) 1210static int __init sunzilog_console_setup(struct console *con, char *options)
diff --git a/drivers/tty/tty_ldsem.c b/drivers/tty/tty_ldsem.c
index d8a55e87877f..0ffb0cbe2823 100644
--- a/drivers/tty/tty_ldsem.c
+++ b/drivers/tty/tty_ldsem.c
@@ -39,17 +39,10 @@
39 lock_acquire(&(l)->dep_map, s, t, r, c, n, i) 39 lock_acquire(&(l)->dep_map, s, t, r, c, n, i)
40# define __rel(l, n, i) \ 40# define __rel(l, n, i) \
41 lock_release(&(l)->dep_map, n, i) 41 lock_release(&(l)->dep_map, n, i)
42# ifdef CONFIG_PROVE_LOCKING 42#define lockdep_acquire(l, s, t, i) __acq(l, s, t, 0, 1, NULL, i)
43# define lockdep_acquire(l, s, t, i) __acq(l, s, t, 0, 2, NULL, i) 43#define lockdep_acquire_nest(l, s, t, n, i) __acq(l, s, t, 0, 1, n, i)
44# define lockdep_acquire_nest(l, s, t, n, i) __acq(l, s, t, 0, 2, n, i) 44#define lockdep_acquire_read(l, s, t, i) __acq(l, s, t, 1, 1, NULL, i)
45# define lockdep_acquire_read(l, s, t, i) __acq(l, s, t, 1, 2, NULL, i) 45#define lockdep_release(l, n, i) __rel(l, n, i)
46# define lockdep_release(l, n, i) __rel(l, n, i)
47# else
48# define lockdep_acquire(l, s, t, i) __acq(l, s, t, 0, 1, NULL, i)
49# define lockdep_acquire_nest(l, s, t, n, i) __acq(l, s, t, 0, 1, n, i)
50# define lockdep_acquire_read(l, s, t, i) __acq(l, s, t, 1, 1, NULL, i)
51# define lockdep_release(l, n, i) __rel(l, n, i)
52# endif
53#else 46#else
54# define lockdep_acquire(l, s, t, i) do { } while (0) 47# define lockdep_acquire(l, s, t, i) do { } while (0)
55# define lockdep_acquire_nest(l, s, t, n, i) do { } while (0) 48# define lockdep_acquire_nest(l, s, t, n, i) do { } while (0)
diff --git a/drivers/usb/core/config.c b/drivers/usb/core/config.c
index 8d72f0c65937..062967c90b2a 100644
--- a/drivers/usb/core/config.c
+++ b/drivers/usb/core/config.c
@@ -717,6 +717,10 @@ int usb_get_configuration(struct usb_device *dev)
717 result = -ENOMEM; 717 result = -ENOMEM;
718 goto err; 718 goto err;
719 } 719 }
720
721 if (dev->quirks & USB_QUIRK_DELAY_INIT)
722 msleep(100);
723
720 result = usb_get_descriptor(dev, USB_DT_CONFIG, cfgno, 724 result = usb_get_descriptor(dev, USB_DT_CONFIG, cfgno,
721 bigbuffer, length); 725 bigbuffer, length);
722 if (result < 0) { 726 if (result < 0) {
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 64ea21971be2..5cbf78d0be25 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -1040,7 +1040,7 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type)
1040 */ 1040 */
1041 if (type == HUB_INIT) { 1041 if (type == HUB_INIT) {
1042 delay = hub_power_on(hub, false); 1042 delay = hub_power_on(hub, false);
1043 PREPARE_DELAYED_WORK(&hub->init_work, hub_init_func2); 1043 INIT_DELAYED_WORK(&hub->init_work, hub_init_func2);
1044 schedule_delayed_work(&hub->init_work, 1044 schedule_delayed_work(&hub->init_work,
1045 msecs_to_jiffies(delay)); 1045 msecs_to_jiffies(delay));
1046 1046
@@ -1194,7 +1194,7 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type)
1194 1194
1195 /* Don't do a long sleep inside a workqueue routine */ 1195 /* Don't do a long sleep inside a workqueue routine */
1196 if (type == HUB_INIT2) { 1196 if (type == HUB_INIT2) {
1197 PREPARE_DELAYED_WORK(&hub->init_work, hub_init_func3); 1197 INIT_DELAYED_WORK(&hub->init_work, hub_init_func3);
1198 schedule_delayed_work(&hub->init_work, 1198 schedule_delayed_work(&hub->init_work,
1199 msecs_to_jiffies(delay)); 1199 msecs_to_jiffies(delay));
1200 return; /* Continues at init3: below */ 1200 return; /* Continues at init3: below */
diff --git a/drivers/usb/core/quirks.c b/drivers/usb/core/quirks.c
index 8f37063c0a49..739ee8e8bdfd 100644
--- a/drivers/usb/core/quirks.c
+++ b/drivers/usb/core/quirks.c
@@ -47,6 +47,10 @@ static const struct usb_device_id usb_quirk_list[] = {
47 /* Microsoft LifeCam-VX700 v2.0 */ 47 /* Microsoft LifeCam-VX700 v2.0 */
48 { USB_DEVICE(0x045e, 0x0770), .driver_info = USB_QUIRK_RESET_RESUME }, 48 { USB_DEVICE(0x045e, 0x0770), .driver_info = USB_QUIRK_RESET_RESUME },
49 49
50 /* Logitech HD Pro Webcams C920 and C930e */
51 { USB_DEVICE(0x046d, 0x082d), .driver_info = USB_QUIRK_DELAY_INIT },
52 { USB_DEVICE(0x046d, 0x0843), .driver_info = USB_QUIRK_DELAY_INIT },
53
50 /* Logitech Quickcam Fusion */ 54 /* Logitech Quickcam Fusion */
51 { USB_DEVICE(0x046d, 0x08c1), .driver_info = USB_QUIRK_RESET_RESUME }, 55 { USB_DEVICE(0x046d, 0x08c1), .driver_info = USB_QUIRK_RESET_RESUME },
52 56
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index 471142725ffe..81cda09b47e3 100644
--- a/drivers/usb/host/ehci-hcd.c
+++ b/drivers/usb/host/ehci-hcd.c
@@ -685,8 +685,15 @@ static irqreturn_t ehci_irq (struct usb_hcd *hcd)
685 struct ehci_hcd *ehci = hcd_to_ehci (hcd); 685 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
686 u32 status, masked_status, pcd_status = 0, cmd; 686 u32 status, masked_status, pcd_status = 0, cmd;
687 int bh; 687 int bh;
688 unsigned long flags;
688 689
689 spin_lock (&ehci->lock); 690 /*
691 * For threadirqs option we use spin_lock_irqsave() variant to prevent
692 * deadlock with ehci hrtimer callback, because hrtimer callbacks run
693 * in interrupt context even when threadirqs is specified. We can go
694 * back to spin_lock() variant when hrtimer callbacks become threaded.
695 */
696 spin_lock_irqsave(&ehci->lock, flags);
690 697
691 status = ehci_readl(ehci, &ehci->regs->status); 698 status = ehci_readl(ehci, &ehci->regs->status);
692 699
@@ -704,7 +711,7 @@ static irqreturn_t ehci_irq (struct usb_hcd *hcd)
704 711
705 /* Shared IRQ? */ 712 /* Shared IRQ? */
706 if (!masked_status || unlikely(ehci->rh_state == EHCI_RH_HALTED)) { 713 if (!masked_status || unlikely(ehci->rh_state == EHCI_RH_HALTED)) {
707 spin_unlock(&ehci->lock); 714 spin_unlock_irqrestore(&ehci->lock, flags);
708 return IRQ_NONE; 715 return IRQ_NONE;
709 } 716 }
710 717
@@ -815,7 +822,7 @@ dead:
815 822
816 if (bh) 823 if (bh)
817 ehci_work (ehci); 824 ehci_work (ehci);
818 spin_unlock (&ehci->lock); 825 spin_unlock_irqrestore(&ehci->lock, flags);
819 if (pcd_status) 826 if (pcd_status)
820 usb_hcd_poll_rh_status(hcd); 827 usb_hcd_poll_rh_status(hcd);
821 return IRQ_HANDLED; 828 return IRQ_HANDLED;
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index 6fe577d46fa2..924a6ccdb622 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -4733,6 +4733,9 @@ int xhci_gen_setup(struct usb_hcd *hcd, xhci_get_quirks_t get_quirks)
4733 /* Accept arbitrarily long scatter-gather lists */ 4733 /* Accept arbitrarily long scatter-gather lists */
4734 hcd->self.sg_tablesize = ~0; 4734 hcd->self.sg_tablesize = ~0;
4735 4735
4736 /* support to build packet from discontinuous buffers */
4737 hcd->self.no_sg_constraint = 1;
4738
4736 /* XHCI controllers don't stop the ep queue on short packets :| */ 4739 /* XHCI controllers don't stop the ep queue on short packets :| */
4737 hcd->self.no_stop_on_short = 1; 4740 hcd->self.no_stop_on_short = 1;
4738 4741
@@ -4757,14 +4760,6 @@ int xhci_gen_setup(struct usb_hcd *hcd, xhci_get_quirks_t get_quirks)
4757 /* xHCI private pointer was set in xhci_pci_probe for the second 4760 /* xHCI private pointer was set in xhci_pci_probe for the second
4758 * registered roothub. 4761 * registered roothub.
4759 */ 4762 */
4760 xhci = hcd_to_xhci(hcd);
4761 /*
4762 * Support arbitrarily aligned sg-list entries on hosts without
4763 * TD fragment rules (which are currently unsupported).
4764 */
4765 if (xhci->hci_version < 0x100)
4766 hcd->self.no_sg_constraint = 1;
4767
4768 return 0; 4763 return 0;
4769 } 4764 }
4770 4765
@@ -4793,9 +4788,6 @@ int xhci_gen_setup(struct usb_hcd *hcd, xhci_get_quirks_t get_quirks)
4793 if (xhci->hci_version > 0x96) 4788 if (xhci->hci_version > 0x96)
4794 xhci->quirks |= XHCI_SPURIOUS_SUCCESS; 4789 xhci->quirks |= XHCI_SPURIOUS_SUCCESS;
4795 4790
4796 if (xhci->hci_version < 0x100)
4797 hcd->self.no_sg_constraint = 1;
4798
4799 /* Make sure the HC is halted. */ 4791 /* Make sure the HC is halted. */
4800 retval = xhci_halt(xhci); 4792 retval = xhci_halt(xhci);
4801 if (retval) 4793 if (retval)
diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index ee1f00f03c43..44ab12986805 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -907,6 +907,8 @@ static const struct usb_device_id id_table_combined[] = {
907 /* Crucible Devices */ 907 /* Crucible Devices */
908 { USB_DEVICE(FTDI_VID, FTDI_CT_COMET_PID) }, 908 { USB_DEVICE(FTDI_VID, FTDI_CT_COMET_PID) },
909 { USB_DEVICE(FTDI_VID, FTDI_Z3X_PID) }, 909 { USB_DEVICE(FTDI_VID, FTDI_Z3X_PID) },
910 /* Cressi Devices */
911 { USB_DEVICE(FTDI_VID, FTDI_CRESSI_PID) },
910 { } /* Terminating entry */ 912 { } /* Terminating entry */
911}; 913};
912 914
diff --git a/drivers/usb/serial/ftdi_sio_ids.h b/drivers/usb/serial/ftdi_sio_ids.h
index 1e2d369df86e..e599fbfcde5f 100644
--- a/drivers/usb/serial/ftdi_sio_ids.h
+++ b/drivers/usb/serial/ftdi_sio_ids.h
@@ -1320,3 +1320,9 @@
1320 * Manufacturer: Smart GSM Team 1320 * Manufacturer: Smart GSM Team
1321 */ 1321 */
1322#define FTDI_Z3X_PID 0x0011 1322#define FTDI_Z3X_PID 0x0011
1323
1324/*
1325 * Product: Cressi PC Interface
1326 * Manufacturer: Cressi
1327 */
1328#define FTDI_CRESSI_PID 0x87d0
diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c
index 4fb7a8f83c8a..54af4e933695 100644
--- a/drivers/vfio/vfio_iommu_type1.c
+++ b/drivers/vfio/vfio_iommu_type1.c
@@ -186,12 +186,12 @@ static bool is_invalid_reserved_pfn(unsigned long pfn)
186 if (pfn_valid(pfn)) { 186 if (pfn_valid(pfn)) {
187 bool reserved; 187 bool reserved;
188 struct page *tail = pfn_to_page(pfn); 188 struct page *tail = pfn_to_page(pfn);
189 struct page *head = compound_trans_head(tail); 189 struct page *head = compound_head(tail);
190 reserved = !!(PageReserved(head)); 190 reserved = !!(PageReserved(head));
191 if (head != tail) { 191 if (head != tail) {
192 /* 192 /*
193 * "head" is not a dangling pointer 193 * "head" is not a dangling pointer
194 * (compound_trans_head takes care of that) 194 * (compound_head takes care of that)
195 * but the hugepage may have been split 195 * but the hugepage may have been split
196 * from under us (and we may not hold a 196 * from under us (and we may not hold a
197 * reference count on the head page so it can 197 * reference count on the head page so it can
diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c
index a0fa5de210cf..e1e22e0f01e8 100644
--- a/drivers/vhost/net.c
+++ b/drivers/vhost/net.c
@@ -505,9 +505,13 @@ static int get_rx_bufs(struct vhost_virtqueue *vq,
505 r = -ENOBUFS; 505 r = -ENOBUFS;
506 goto err; 506 goto err;
507 } 507 }
508 d = vhost_get_vq_desc(vq->dev, vq, vq->iov + seg, 508 r = vhost_get_vq_desc(vq->dev, vq, vq->iov + seg,
509 ARRAY_SIZE(vq->iov) - seg, &out, 509 ARRAY_SIZE(vq->iov) - seg, &out,
510 &in, log, log_num); 510 &in, log, log_num);
511 if (unlikely(r < 0))
512 goto err;
513
514 d = r;
511 if (d == vq->num) { 515 if (d == vq->num) {
512 r = 0; 516 r = 0;
513 goto err; 517 goto err;
@@ -532,6 +536,12 @@ static int get_rx_bufs(struct vhost_virtqueue *vq,
532 *iovcount = seg; 536 *iovcount = seg;
533 if (unlikely(log)) 537 if (unlikely(log))
534 *log_num = nlogs; 538 *log_num = nlogs;
539
540 /* Detect overrun */
541 if (unlikely(datalen > 0)) {
542 r = UIO_MAXIOV + 1;
543 goto err;
544 }
535 return headcount; 545 return headcount;
536err: 546err:
537 vhost_discard_vq_desc(vq, headcount); 547 vhost_discard_vq_desc(vq, headcount);
@@ -587,6 +597,14 @@ static void handle_rx(struct vhost_net *net)
587 /* On error, stop handling until the next kick. */ 597 /* On error, stop handling until the next kick. */
588 if (unlikely(headcount < 0)) 598 if (unlikely(headcount < 0))
589 break; 599 break;
600 /* On overrun, truncate and discard */
601 if (unlikely(headcount > UIO_MAXIOV)) {
602 msg.msg_iovlen = 1;
603 err = sock->ops->recvmsg(NULL, sock, &msg,
604 1, MSG_DONTWAIT | MSG_TRUNC);
605 pr_debug("Discarded rx packet: len %zd\n", sock_len);
606 continue;
607 }
590 /* OK, now we need to know about added descriptors. */ 608 /* OK, now we need to know about added descriptors. */
591 if (!headcount) { 609 if (!headcount) {
592 if (unlikely(vhost_enable_notify(&net->dev, vq))) { 610 if (unlikely(vhost_enable_notify(&net->dev, vq))) {
diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c
index 0a025b8e2a12..e48d4a672580 100644
--- a/drivers/vhost/scsi.c
+++ b/drivers/vhost/scsi.c
@@ -1001,6 +1001,12 @@ vhost_scsi_handle_vq(struct vhost_scsi *vs, struct vhost_virtqueue *vq)
1001 break; 1001 break;
1002 } 1002 }
1003 1003
1004 /* virtio-scsi spec requires byte 0 of the lun to be 1 */
1005 if (unlikely(v_req.lun[0] != 1)) {
1006 vhost_scsi_send_bad_target(vs, vq, head, out);
1007 continue;
1008 }
1009
1004 /* Extract the tpgt */ 1010 /* Extract the tpgt */
1005 target = v_req.lun[1]; 1011 target = v_req.lun[1];
1006 tpg = ACCESS_ONCE(vs_tpg[target]); 1012 tpg = ACCESS_ONCE(vs_tpg[target]);
diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c
index 37d06ea624aa..61a6ac8fa8fc 100644
--- a/drivers/xen/balloon.c
+++ b/drivers/xen/balloon.c
@@ -399,11 +399,25 @@ static enum bp_state decrease_reservation(unsigned long nr_pages, gfp_t gfp)
399 state = BP_EAGAIN; 399 state = BP_EAGAIN;
400 break; 400 break;
401 } 401 }
402 scrub_page(page);
402 403
403 pfn = page_to_pfn(page); 404 frame_list[i] = page_to_pfn(page);
404 frame_list[i] = pfn_to_mfn(pfn); 405 }
405 406
406 scrub_page(page); 407 /*
408 * Ensure that ballooned highmem pages don't have kmaps.
409 *
410 * Do this before changing the p2m as kmap_flush_unused()
411 * reads PTEs to obtain pages (and hence needs the original
412 * p2m entry).
413 */
414 kmap_flush_unused();
415
416 /* Update direct mapping, invalidate P2M, and add to balloon. */
417 for (i = 0; i < nr_pages; i++) {
418 pfn = frame_list[i];
419 frame_list[i] = pfn_to_mfn(pfn);
420 page = pfn_to_page(pfn);
407 421
408#ifdef CONFIG_XEN_HAVE_PVMMU 422#ifdef CONFIG_XEN_HAVE_PVMMU
409 /* 423 /*
@@ -429,11 +443,9 @@ static enum bp_state decrease_reservation(unsigned long nr_pages, gfp_t gfp)
429 } 443 }
430#endif 444#endif
431 445
432 balloon_append(pfn_to_page(pfn)); 446 balloon_append(page);
433 } 447 }
434 448
435 /* Ensure that ballooned highmem pages don't have kmaps. */
436 kmap_flush_unused();
437 flush_tlb_all(); 449 flush_tlb_all();
438 450
439 set_xen_guest_handle(reservation.extent_start, frame_list); 451 set_xen_guest_handle(reservation.extent_start, frame_list);
diff --git a/drivers/xen/events/events_2l.c b/drivers/xen/events/events_2l.c
index d7ff91757307..5db43fc100a4 100644
--- a/drivers/xen/events/events_2l.c
+++ b/drivers/xen/events/events_2l.c
@@ -166,7 +166,6 @@ static void evtchn_2l_handle_events(unsigned cpu)
166 int start_word_idx, start_bit_idx; 166 int start_word_idx, start_bit_idx;
167 int word_idx, bit_idx; 167 int word_idx, bit_idx;
168 int i; 168 int i;
169 struct irq_desc *desc;
170 struct shared_info *s = HYPERVISOR_shared_info; 169 struct shared_info *s = HYPERVISOR_shared_info;
171 struct vcpu_info *vcpu_info = __this_cpu_read(xen_vcpu); 170 struct vcpu_info *vcpu_info = __this_cpu_read(xen_vcpu);
172 171
@@ -176,11 +175,8 @@ static void evtchn_2l_handle_events(unsigned cpu)
176 unsigned int evtchn = evtchn_from_irq(irq); 175 unsigned int evtchn = evtchn_from_irq(irq);
177 word_idx = evtchn / BITS_PER_LONG; 176 word_idx = evtchn / BITS_PER_LONG;
178 bit_idx = evtchn % BITS_PER_LONG; 177 bit_idx = evtchn % BITS_PER_LONG;
179 if (active_evtchns(cpu, s, word_idx) & (1ULL << bit_idx)) { 178 if (active_evtchns(cpu, s, word_idx) & (1ULL << bit_idx))
180 desc = irq_to_desc(irq); 179 generic_handle_irq(irq);
181 if (desc)
182 generic_handle_irq_desc(irq, desc);
183 }
184 } 180 }
185 181
186 /* 182 /*
@@ -245,11 +241,8 @@ static void evtchn_2l_handle_events(unsigned cpu)
245 port = (word_idx * BITS_PER_EVTCHN_WORD) + bit_idx; 241 port = (word_idx * BITS_PER_EVTCHN_WORD) + bit_idx;
246 irq = get_evtchn_to_irq(port); 242 irq = get_evtchn_to_irq(port);
247 243
248 if (irq != -1) { 244 if (irq != -1)
249 desc = irq_to_desc(irq); 245 generic_handle_irq(irq);
250 if (desc)
251 generic_handle_irq_desc(irq, desc);
252 }
253 246
254 bit_idx = (bit_idx + 1) % BITS_PER_EVTCHN_WORD; 247 bit_idx = (bit_idx + 1) % BITS_PER_EVTCHN_WORD;
255 248
diff --git a/drivers/xen/events/events_base.c b/drivers/xen/events/events_base.c
index 793053065629..d5a3de88ac59 100644
--- a/drivers/xen/events/events_base.c
+++ b/drivers/xen/events/events_base.c
@@ -336,9 +336,8 @@ static void bind_evtchn_to_cpu(unsigned int chn, unsigned int cpu)
336 336
337 BUG_ON(irq == -1); 337 BUG_ON(irq == -1);
338#ifdef CONFIG_SMP 338#ifdef CONFIG_SMP
339 cpumask_copy(irq_to_desc(irq)->irq_data.affinity, cpumask_of(cpu)); 339 cpumask_copy(irq_get_irq_data(irq)->affinity, cpumask_of(cpu));
340#endif 340#endif
341
342 xen_evtchn_port_bind_to_cpu(info, cpu); 341 xen_evtchn_port_bind_to_cpu(info, cpu);
343 342
344 info->cpu = cpu; 343 info->cpu = cpu;
@@ -373,10 +372,8 @@ static void xen_irq_init(unsigned irq)
373{ 372{
374 struct irq_info *info; 373 struct irq_info *info;
375#ifdef CONFIG_SMP 374#ifdef CONFIG_SMP
376 struct irq_desc *desc = irq_to_desc(irq);
377
378 /* By default all event channels notify CPU#0. */ 375 /* By default all event channels notify CPU#0. */
379 cpumask_copy(desc->irq_data.affinity, cpumask_of(0)); 376 cpumask_copy(irq_get_irq_data(irq)->affinity, cpumask_of(0));
380#endif 377#endif
381 378
382 info = kzalloc(sizeof(*info), GFP_KERNEL); 379 info = kzalloc(sizeof(*info), GFP_KERNEL);
@@ -495,13 +492,6 @@ static void pirq_query_unmask(int irq)
495 info->u.pirq.flags |= PIRQ_NEEDS_EOI; 492 info->u.pirq.flags |= PIRQ_NEEDS_EOI;
496} 493}
497 494
498static bool probing_irq(int irq)
499{
500 struct irq_desc *desc = irq_to_desc(irq);
501
502 return desc && desc->action == NULL;
503}
504
505static void eoi_pirq(struct irq_data *data) 495static void eoi_pirq(struct irq_data *data)
506{ 496{
507 int evtchn = evtchn_from_irq(data->irq); 497 int evtchn = evtchn_from_irq(data->irq);
@@ -543,8 +533,7 @@ static unsigned int __startup_pirq(unsigned int irq)
543 BIND_PIRQ__WILL_SHARE : 0; 533 BIND_PIRQ__WILL_SHARE : 0;
544 rc = HYPERVISOR_event_channel_op(EVTCHNOP_bind_pirq, &bind_pirq); 534 rc = HYPERVISOR_event_channel_op(EVTCHNOP_bind_pirq, &bind_pirq);
545 if (rc != 0) { 535 if (rc != 0) {
546 if (!probing_irq(irq)) 536 pr_warn("Failed to obtain physical IRQ %d\n", irq);
547 pr_info("Failed to obtain physical IRQ %d\n", irq);
548 return 0; 537 return 0;
549 } 538 }
550 evtchn = bind_pirq.port; 539 evtchn = bind_pirq.port;
@@ -781,17 +770,12 @@ error_irq:
781 770
782int xen_destroy_irq(int irq) 771int xen_destroy_irq(int irq)
783{ 772{
784 struct irq_desc *desc;
785 struct physdev_unmap_pirq unmap_irq; 773 struct physdev_unmap_pirq unmap_irq;
786 struct irq_info *info = info_for_irq(irq); 774 struct irq_info *info = info_for_irq(irq);
787 int rc = -ENOENT; 775 int rc = -ENOENT;
788 776
789 mutex_lock(&irq_mapping_update_lock); 777 mutex_lock(&irq_mapping_update_lock);
790 778
791 desc = irq_to_desc(irq);
792 if (!desc)
793 goto out;
794
795 /* 779 /*
796 * If trying to remove a vector in a MSI group different 780 * If trying to remove a vector in a MSI group different
797 * than the first one skip the PIRQ unmap unless this vector 781 * than the first one skip the PIRQ unmap unless this vector
@@ -1265,6 +1249,7 @@ void xen_evtchn_do_upcall(struct pt_regs *regs)
1265#ifdef CONFIG_X86 1249#ifdef CONFIG_X86
1266 exit_idle(); 1250 exit_idle();
1267#endif 1251#endif
1252 inc_irq_stat(irq_hv_callback_count);
1268 1253
1269 __xen_evtchn_do_upcall(); 1254 __xen_evtchn_do_upcall();
1270 1255
@@ -1353,7 +1338,7 @@ static int rebind_irq_to_cpu(unsigned irq, unsigned tcpu)
1353static int set_affinity_irq(struct irq_data *data, const struct cpumask *dest, 1338static int set_affinity_irq(struct irq_data *data, const struct cpumask *dest,
1354 bool force) 1339 bool force)
1355{ 1340{
1356 unsigned tcpu = cpumask_first(dest); 1341 unsigned tcpu = cpumask_first_and(dest, cpu_online_mask);
1357 1342
1358 return rebind_irq_to_cpu(data->irq, tcpu); 1343 return rebind_irq_to_cpu(data->irq, tcpu);
1359} 1344}
diff --git a/drivers/xen/events/events_fifo.c b/drivers/xen/events/events_fifo.c
index 1de2a191b395..96109a9972b6 100644
--- a/drivers/xen/events/events_fifo.c
+++ b/drivers/xen/events/events_fifo.c
@@ -235,14 +235,10 @@ static uint32_t clear_linked(volatile event_word_t *word)
235static void handle_irq_for_port(unsigned port) 235static void handle_irq_for_port(unsigned port)
236{ 236{
237 int irq; 237 int irq;
238 struct irq_desc *desc;
239 238
240 irq = get_evtchn_to_irq(port); 239 irq = get_evtchn_to_irq(port);
241 if (irq != -1) { 240 if (irq != -1)
242 desc = irq_to_desc(irq); 241 generic_handle_irq(irq);
243 if (desc)
244 generic_handle_irq_desc(irq, desc);
245 }
246} 242}
247 243
248static void consume_one_event(unsigned cpu, 244static void consume_one_event(unsigned cpu,