aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/Makefile2
-rw-r--r--drivers/acpi/acpi_apd.c10
-rw-r--r--drivers/acpi/acpi_lpss.c10
-rw-r--r--drivers/acpi/acpi_platform.c5
-rw-r--r--drivers/acpi/acpica/dsinit.c11
-rw-r--r--drivers/acpi/acpica/dsmethod.c50
-rw-r--r--drivers/acpi/acpica/dswload2.c2
-rw-r--r--drivers/acpi/acpica/evrgnini.c3
-rw-r--r--drivers/acpi/acpica/nsload.c2
-rw-r--r--drivers/acpi/acpica/tbfadt.c10
-rw-r--r--drivers/acpi/apei/ghes.c2
-rw-r--r--drivers/acpi/dptf/int340x_thermal.c4
-rw-r--r--drivers/acpi/nfit/core.c55
-rw-r--r--drivers/acpi/nfit/nfit.h2
-rw-r--r--drivers/acpi/pci_link.c38
-rw-r--r--drivers/acpi/scan.c2
-rw-r--r--drivers/acpi/sleep.c29
-rw-r--r--drivers/android/binder.c35
-rw-r--r--drivers/ata/ahci.c40
-rw-r--r--drivers/ata/libata-scsi.c3
-rw-r--r--drivers/ata/sata_mv.c15
-rw-r--r--drivers/atm/eni.c2
-rw-r--r--drivers/atm/lanai.c1
-rw-r--r--drivers/base/Kconfig6
-rw-r--r--drivers/base/dd.c5
-rw-r--r--drivers/base/power/main.c8
-rw-r--r--drivers/block/DAC960.c4
-rw-r--r--drivers/block/aoe/aoecmd.c41
-rw-r--r--drivers/block/drbd/drbd_main.c2
-rw-r--r--drivers/block/nbd.c4
-rw-r--r--drivers/block/rbd.c50
-rw-r--r--drivers/block/virtio_blk.c10
-rw-r--r--drivers/block/zram/zram_drv.c11
-rw-r--r--drivers/bluetooth/btwilink.c2
-rw-r--r--drivers/bluetooth/hci_bcm.c8
-rw-r--r--drivers/bus/Kconfig1
-rw-r--r--drivers/char/hw_random/core.c6
-rw-r--r--drivers/char/ipmi/Kconfig8
-rw-r--r--drivers/char/ipmi/Makefile1
-rw-r--r--drivers/char/ipmi/bt-bmc.c505
-rw-r--r--drivers/char/ipmi/ipmi_msghandler.c7
-rw-r--r--drivers/char/ppdev.c3
-rw-r--r--drivers/char/tpm/tpm-interface.c3
-rw-r--r--drivers/char/virtio_console.c22
-rw-r--r--drivers/clk/at91/clk-programmable.c2
-rw-r--r--drivers/clk/bcm/Kconfig2
-rw-r--r--drivers/clk/bcm/clk-bcm2835.c11
-rw-r--r--drivers/clk/berlin/bg2.c2
-rw-r--r--drivers/clk/berlin/bg2q.c2
-rw-r--r--drivers/clk/clk-efm32gg.c2
-rw-r--r--drivers/clk/clk-max77686.c1
-rw-r--r--drivers/clk/clk-qoriq.c13
-rw-r--r--drivers/clk/clk-xgene.c10
-rw-r--r--drivers/clk/hisilicon/clk-hi6220.c4
-rw-r--r--drivers/clk/imx/clk-pllv3.c8
-rw-r--r--drivers/clk/mediatek/Kconfig2
-rw-r--r--drivers/clk/mmp/clk-of-mmp2.c2
-rw-r--r--drivers/clk/mmp/clk-of-pxa168.c2
-rw-r--r--drivers/clk/mmp/clk-of-pxa910.c4
-rw-r--r--drivers/clk/mvebu/armada-37xx-periph.c11
-rw-r--r--drivers/clk/rockchip/clk-ddr.c5
-rw-r--r--drivers/clk/samsung/clk-exynos-audss.c1
-rw-r--r--drivers/clk/samsung/clk-exynos-clkout.c22
-rw-r--r--drivers/clk/sunxi-ng/ccu-sun6i-a31.c14
-rw-r--r--drivers/clk/sunxi-ng/ccu-sun8i-a33.c2
-rw-r--r--drivers/clk/sunxi/clk-sunxi.c2
-rw-r--r--drivers/clk/uniphier/clk-uniphier-core.c20
-rw-r--r--drivers/clk/uniphier/clk-uniphier-mio.c2
-rw-r--r--drivers/clk/uniphier/clk-uniphier-mux.c2
-rw-r--r--drivers/clk/uniphier/clk-uniphier.h2
-rw-r--r--drivers/clocksource/Kconfig10
-rw-r--r--drivers/clocksource/Makefile1
-rw-r--r--drivers/clocksource/jcore-pit.c249
-rw-r--r--drivers/clocksource/timer-sun5i.c16
-rw-r--r--drivers/cpufreq/intel_pstate.c38
-rw-r--r--drivers/crypto/caam/caamalg.c11
-rw-r--r--drivers/crypto/caam/ctrl.c5
-rw-r--r--drivers/crypto/chelsio/chcr_algo.h3
-rw-r--r--drivers/crypto/marvell/hash.c11
-rw-r--r--drivers/dax/Kconfig2
-rw-r--r--drivers/dax/dax.c4
-rw-r--r--drivers/dax/pmem.c6
-rw-r--r--drivers/dma/Kconfig1
-rw-r--r--drivers/dma/cppi41.c31
-rw-r--r--drivers/dma/edma.c1
-rw-r--r--drivers/dma/sun6i-dma.c2
-rw-r--r--drivers/extcon/extcon-arizona.c8
-rw-r--r--drivers/extcon/extcon-qcom-spmi-misc.c2
-rw-r--r--drivers/firewire/net.c59
-rw-r--r--drivers/firewire/nosy.c13
-rw-r--r--drivers/firmware/efi/libstub/Makefile5
-rw-r--r--drivers/gpio/Kconfig6
-rw-r--r--drivers/gpio/Makefile2
-rw-r--r--drivers/gpio/gpio-ath79.c1
-rw-r--r--drivers/gpio/gpio-mpc8xxx.c2
-rw-r--r--drivers/gpio/gpio-mvebu.c92
-rw-r--r--drivers/gpio/gpio-mxs.c8
-rw-r--r--drivers/gpio/gpio-pca953x.c4
-rw-r--r--drivers/gpio/gpio-stmpe.c2
-rw-r--r--drivers/gpio/gpio-tc3589x.c2
-rw-r--r--drivers/gpio/gpio-ts4800.c1
-rw-r--r--drivers/gpio/gpiolib-acpi.c7
-rw-r--r--drivers/gpio/gpiolib-of.c14
-rw-r--r--drivers/gpio/gpiolib.c106
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu.h2
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_acp.c5
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_atpx_handler.c16
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c2
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_cgs.c13
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c15
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c3
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c3
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_device.c107
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.c14
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c31
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c1
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c2
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c8
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_object.c5
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c20
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c4
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c7
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c1
-rw-r--r--drivers/gpu/drm/amd/amdgpu/ci_dpm.c4
-rw-r--r--drivers/gpu/drm/amd/amdgpu/cz_dpm.c8
-rw-r--r--drivers/gpu/drm/amd/amdgpu/dce_v10_0.c18
-rw-r--r--drivers/gpu/drm/amd/amdgpu/dce_v11_0.c6
-rw-r--r--drivers/gpu/drm/amd/amdgpu/dce_v6_0.c6
-rw-r--r--drivers/gpu/drm/amd/amdgpu/dce_v8_0.c6
-rw-r--r--drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c31
-rw-r--r--drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c14
-rw-r--r--drivers/gpu/drm/amd/amdgpu/kv_dpm.c2
-rw-r--r--drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c14
-rw-r--r--drivers/gpu/drm/amd/amdgpu/si_dpm.c55
-rw-r--r--drivers/gpu/drm/amd/amdgpu/tonga_ih.c14
-rw-r--r--drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c14
-rw-r--r--drivers/gpu/drm/amd/amdgpu/vce_v3_0.c21
-rw-r--r--drivers/gpu/drm/amd/amdgpu/vi.c4
-rw-r--r--drivers/gpu/drm/amd/include/amd_shared.h2
-rw-r--r--drivers/gpu/drm/amd/powerplay/eventmgr/eventactionchains.c1
-rw-r--r--drivers/gpu/drm/amd/powerplay/hwmgr/cz_hwmgr.c18
-rw-r--r--drivers/gpu/drm/amd/powerplay/hwmgr/hardwaremanager.c2
-rw-r--r--drivers/gpu/drm/amd/powerplay/hwmgr/hwmgr.c8
-rw-r--r--drivers/gpu/drm/amd/powerplay/hwmgr/ppatomctrl.c3
-rw-r--r--drivers/gpu/drm/amd/powerplay/hwmgr/process_pptables_v1_0.c9
-rw-r--r--drivers/gpu/drm/amd/powerplay/hwmgr/smu7_hwmgr.c142
-rw-r--r--drivers/gpu/drm/amd/powerplay/hwmgr/smu7_thermal.c6
-rw-r--r--drivers/gpu/drm/amd/powerplay/smumgr/iceland_smc.c2
-rw-r--r--drivers/gpu/drm/amd/powerplay/smumgr/polaris10_smc.c5
-rw-r--r--drivers/gpu/drm/amd/scheduler/gpu_scheduler.c12
-rw-r--r--drivers/gpu/drm/amd/scheduler/gpu_scheduler.h6
-rw-r--r--drivers/gpu/drm/amd/scheduler/sched_fence.c23
-rw-r--r--drivers/gpu/drm/arc/arcpgu_hdmi.c159
-rw-r--r--drivers/gpu/drm/arm/hdlcd_crtc.c5
-rw-r--r--drivers/gpu/drm/arm/hdlcd_drv.c2
-rw-r--r--drivers/gpu/drm/armada/armada_crtc.c18
-rw-r--r--drivers/gpu/drm/ast/ast_ttm.c6
-rw-r--r--drivers/gpu/drm/cirrus/cirrus_ttm.c7
-rw-r--r--drivers/gpu/drm/drm_atomic.c9
-rw-r--r--drivers/gpu/drm/drm_atomic_helper.c4
-rw-r--r--drivers/gpu/drm/drm_dp_mst_topology.c6
-rw-r--r--drivers/gpu/drm/drm_fb_helper.c68
-rw-r--r--drivers/gpu/drm/drm_info.c4
-rw-r--r--drivers/gpu/drm/drm_ioctl.c10
-rw-r--r--drivers/gpu/drm/etnaviv/etnaviv_buffer.c24
-rw-r--r--drivers/gpu/drm/etnaviv/etnaviv_gem.c7
-rw-r--r--drivers/gpu/drm/etnaviv/etnaviv_mmu.c3
-rw-r--r--drivers/gpu/drm/exynos/exynos_drm_drv.c20
-rw-r--r--drivers/gpu/drm/exynos/exynos_drm_drv.h1
-rw-r--r--drivers/gpu/drm/exynos/exynos_drm_fb.c2
-rw-r--r--drivers/gpu/drm/exynos/exynos_drm_g2d.c3
-rw-r--r--drivers/gpu/drm/exynos/exynos_hdmi.c5
-rw-r--r--drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_crtc.c17
-rw-r--r--drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.c27
-rw-r--r--drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_plane.c10
-rw-r--r--drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_rgb.c39
-rw-r--r--drivers/gpu/drm/i915/i915_drv.c4
-rw-r--r--drivers/gpu/drm/i915/i915_drv.h5
-rw-r--r--drivers/gpu/drm/i915/i915_gem.c35
-rw-r--r--drivers/gpu/drm/i915/i915_gem_execbuffer.c8
-rw-r--r--drivers/gpu/drm/i915/i915_gem_fence.c21
-rw-r--r--drivers/gpu/drm/i915/i915_gem_userptr.c6
-rw-r--r--drivers/gpu/drm/i915/i915_pci.c7
-rw-r--r--drivers/gpu/drm/i915/intel_bios.c152
-rw-r--r--drivers/gpu/drm/i915/intel_device_info.c2
-rw-r--r--drivers/gpu/drm/i915/intel_display.c37
-rw-r--r--drivers/gpu/drm/i915/intel_dp.c85
-rw-r--r--drivers/gpu/drm/i915/intel_fbc.c4
-rw-r--r--drivers/gpu/drm/i915/intel_hdmi.c84
-rw-r--r--drivers/gpu/drm/i915/intel_pm.c24
-rw-r--r--drivers/gpu/drm/i915/intel_runtime_pm.c4
-rw-r--r--drivers/gpu/drm/i915/intel_sprite.c2
-rw-r--r--drivers/gpu/drm/i915/intel_vbt_defs.h3
-rw-r--r--drivers/gpu/drm/imx/imx-drm-core.c6
-rw-r--r--drivers/gpu/drm/imx/ipuv3-crtc.c9
-rw-r--r--drivers/gpu/drm/imx/ipuv3-plane.c28
-rw-r--r--drivers/gpu/drm/mediatek/mtk_disp_ovl.c15
-rw-r--r--drivers/gpu/drm/mediatek/mtk_dpi.c9
-rw-r--r--drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c2
-rw-r--r--drivers/gpu/drm/mediatek/mtk_dsi.c64
-rw-r--r--drivers/gpu/drm/mediatek/mtk_hdmi.c17
-rw-r--r--drivers/gpu/drm/mediatek/mtk_mt8173_hdmi_phy.c42
-rw-r--r--drivers/gpu/drm/mgag200/mgag200_ttm.c7
-rw-r--r--drivers/gpu/drm/msm/dsi/dsi_host.c14
-rw-r--r--drivers/gpu/drm/msm/dsi/pll/dsi_pll_28nm.c1
-rw-r--r--drivers/gpu/drm/msm/dsi/pll/dsi_pll_28nm_8960.c1
-rw-r--r--drivers/gpu/drm/msm/hdmi/hdmi_phy_8996.c1
-rw-r--r--drivers/gpu/drm/msm/hdmi/hdmi_pll_8960.c1
-rw-r--r--drivers/gpu/drm/msm/mdp/mdp5/mdp5_cfg.c4
-rw-r--r--drivers/gpu/drm/msm/mdp/mdp5/mdp5_crtc.c46
-rw-r--r--drivers/gpu/drm/msm/mdp/mdp5/mdp5_plane.c9
-rw-r--r--drivers/gpu/drm/msm/msm_drv.c2
-rw-r--r--drivers/gpu/drm/msm/msm_gem_shrinker.c7
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_acpi.c3
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_ttm.c8
-rw-r--r--drivers/gpu/drm/radeon/ni.c4
-rw-r--r--drivers/gpu/drm/radeon/r600_dpm.c15
-rw-r--r--drivers/gpu/drm/radeon/radeon_atpx_handler.c16
-rw-r--r--drivers/gpu/drm/radeon/radeon_connectors.c17
-rw-r--r--drivers/gpu/drm/radeon/radeon_device.c13
-rw-r--r--drivers/gpu/drm/radeon/radeon_display.c14
-rw-r--r--drivers/gpu/drm/radeon/radeon_dp_auxch.c2
-rw-r--r--drivers/gpu/drm/radeon/radeon_drv.c3
-rw-r--r--drivers/gpu/drm/radeon/radeon_i2c.c3
-rw-r--r--drivers/gpu/drm/radeon/radeon_object.c5
-rw-r--r--drivers/gpu/drm/radeon/radeon_ttm.c3
-rw-r--r--drivers/gpu/drm/radeon/si.c1
-rw-r--r--drivers/gpu/drm/radeon/si_dpm.c53
-rw-r--r--drivers/gpu/drm/radeon/sid.h1
-rw-r--r--drivers/gpu/drm/rcar-du/rcar_du_kms.c12
-rw-r--r--drivers/gpu/drm/sti/sti_drv.c22
-rw-r--r--drivers/gpu/drm/sun4i/sun4i_drv.c4
-rw-r--r--drivers/gpu/drm/sun4i/sun4i_rgb.c20
-rw-r--r--drivers/gpu/drm/udl/udl_main.c16
-rw-r--r--drivers/gpu/drm/via/via_dmablit.c4
-rw-r--r--drivers/gpu/drm/virtio/virtgpu_display.c3
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_drv.c10
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_drv.h2
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c145
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_resource.c6
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_surface.c56
-rw-r--r--drivers/gpu/ipu-v3/ipu-image-convert.c2
-rw-r--r--drivers/hid/hid-cp2112.c115
-rw-r--r--drivers/hid/hid-dr.c83
-rw-r--r--drivers/hid/hid-ids.h4
-rw-r--r--drivers/hid/hid-led.c23
-rw-r--r--drivers/hid/hid-lg.c14
-rw-r--r--drivers/hid/hid-magicmouse.c12
-rw-r--r--drivers/hid/hid-rmi.c10
-rw-r--r--drivers/hid/hid-sensor-custom.c6
-rw-r--r--drivers/hid/hid-sensor-hub.c16
-rw-r--r--drivers/hid/intel-ish-hid/ipc/ipc.c102
-rw-r--r--drivers/hid/intel-ish-hid/ipc/pci-ish.c6
-rw-r--r--drivers/hid/usbhid/hid-quirks.c2
-rw-r--r--drivers/hv/hv_util.c10
-rw-r--r--drivers/hv/vmbus_drv.c2
-rw-r--r--drivers/hwmon/adm9240.c6
-rw-r--r--drivers/hwmon/hwmon.c6
-rw-r--r--drivers/hwmon/max31790.c4
-rw-r--r--drivers/i2c/Kconfig1
-rw-r--r--drivers/i2c/busses/Kconfig12
-rw-r--r--drivers/i2c/busses/i2c-designware-core.c81
-rw-r--r--drivers/i2c/busses/i2c-digicolor.c3
-rw-r--r--drivers/i2c/busses/i2c-i801.c16
-rw-r--r--drivers/i2c/busses/i2c-imx.c11
-rw-r--r--drivers/i2c/busses/i2c-jz4780.c1
-rw-r--r--drivers/i2c/busses/i2c-octeon-core.c4
-rw-r--r--drivers/i2c/busses/i2c-octeon-core.h27
-rw-r--r--drivers/i2c/busses/i2c-rk3x.c2
-rw-r--r--drivers/i2c/busses/i2c-xgene-slimpro.c2
-rw-r--r--drivers/i2c/busses/i2c-xlp9xx.c1
-rw-r--r--drivers/i2c/busses/i2c-xlr.c1
-rw-r--r--drivers/i2c/i2c-core.c13
-rw-r--r--drivers/i2c/muxes/Kconfig1
-rw-r--r--drivers/i2c/muxes/i2c-demux-pinctrl.c22
-rw-r--r--drivers/i2c/muxes/i2c-mux-pca954x.c4
-rw-r--r--drivers/iio/accel/st_accel_core.c12
-rw-r--r--drivers/iio/adc/Kconfig2
-rw-r--r--drivers/iio/chemical/atlas-ph-sensor.c7
-rw-r--r--drivers/iio/common/hid-sensors/hid-sensor-attributes.c56
-rw-r--r--drivers/iio/common/st_sensors/st_sensors_core.c8
-rw-r--r--drivers/iio/orientation/hid-sensor-rotation.c1
-rw-r--r--drivers/iio/temperature/maxim_thermocouple.c18
-rw-r--r--drivers/infiniband/core/addr.c11
-rw-r--r--drivers/infiniband/core/cm.c126
-rw-r--r--drivers/infiniband/core/cma.c75
-rw-r--r--drivers/infiniband/core/umem.c8
-rw-r--r--drivers/infiniband/core/umem_odp.c7
-rw-r--r--drivers/infiniband/core/uverbs_main.c7
-rw-r--r--drivers/infiniband/hw/cxgb4/cq.c17
-rw-r--r--drivers/infiniband/hw/cxgb4/iw_cxgb4.h2
-rw-r--r--drivers/infiniband/hw/cxgb4/mem.c12
-rw-r--r--drivers/infiniband/hw/cxgb4/qp.c20
-rw-r--r--drivers/infiniband/hw/hfi1/affinity.c72
-rw-r--r--drivers/infiniband/hw/hfi1/affinity.h4
-rw-r--r--drivers/infiniband/hw/hfi1/chip.c27
-rw-r--r--drivers/infiniband/hw/hfi1/chip.h3
-rw-r--r--drivers/infiniband/hw/hfi1/driver.c37
-rw-r--r--drivers/infiniband/hw/hfi1/file_ops.c19
-rw-r--r--drivers/infiniband/hw/hfi1/hfi.h89
-rw-r--r--drivers/infiniband/hw/hfi1/init.c104
-rw-r--r--drivers/infiniband/hw/hfi1/pcie.c3
-rw-r--r--drivers/infiniband/hw/hfi1/pio.c13
-rw-r--r--drivers/infiniband/hw/hfi1/rc.c2
-rw-r--r--drivers/infiniband/hw/hfi1/sdma.c19
-rw-r--r--drivers/infiniband/hw/hfi1/sysfs.c25
-rw-r--r--drivers/infiniband/hw/hfi1/trace_rx.h60
-rw-r--r--drivers/infiniband/hw/hfi1/user_sdma.c2
-rw-r--r--drivers/infiniband/hw/mlx4/ah.c5
-rw-r--r--drivers/infiniband/hw/mlx4/cq.c5
-rw-r--r--drivers/infiniband/hw/mlx5/cq.c3
-rw-r--r--drivers/infiniband/hw/mlx5/main.c13
-rw-r--r--drivers/infiniband/hw/mlx5/mlx5_ib.h2
-rw-r--r--drivers/infiniband/hw/mlx5/mr.c6
-rw-r--r--drivers/infiniband/hw/mlx5/qp.c13
-rw-r--r--drivers/infiniband/hw/mthca/mthca_memfree.c2
-rw-r--r--drivers/infiniband/hw/qedr/Kconfig1
-rw-r--r--drivers/infiniband/hw/qib/qib_user_pages.c3
-rw-r--r--drivers/infiniband/hw/usnic/usnic_uiom.c5
-rw-r--r--drivers/infiniband/sw/rdmavt/dma.c3
-rw-r--r--drivers/infiniband/sw/rxe/rxe_net.c8
-rw-r--r--drivers/infiniband/sw/rxe/rxe_qp.c2
-rw-r--r--drivers/infiniband/sw/rxe/rxe_queue.c9
-rw-r--r--drivers/infiniband/sw/rxe/rxe_queue.h2
-rw-r--r--drivers/infiniband/sw/rxe/rxe_req.c21
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib.h20
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_cm.c15
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_ib.c12
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_main.c54
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_multicast.c6
-rw-r--r--drivers/input/misc/arizona-haptics.c13
-rw-r--r--drivers/input/mouse/focaltech.c6
-rw-r--r--drivers/input/mouse/psmouse-base.c4
-rw-r--r--drivers/input/serio/i8042-x86ia64io.h7
-rw-r--r--drivers/iommu/arm-smmu-v3.c25
-rw-r--r--drivers/iommu/arm-smmu.c16
-rw-r--r--drivers/iommu/dmar.c4
-rw-r--r--drivers/iommu/intel-iommu.c27
-rw-r--r--drivers/iommu/intel-svm.c28
-rw-r--r--drivers/ipack/ipack.c2
-rw-r--r--drivers/irqchip/Kconfig4
-rw-r--r--drivers/irqchip/irq-eznps.c6
-rw-r--r--drivers/irqchip/irq-gic-v3-its.c10
-rw-r--r--drivers/irqchip/irq-gic-v3.c2
-rw-r--r--drivers/irqchip/irq-gic.c2
-rw-r--r--drivers/irqchip/irq-jcore-aic.c20
-rw-r--r--drivers/isdn/gigaset/ser-gigaset.c4
-rw-r--r--drivers/isdn/hisax/hfc4s8s_l1.c1
-rw-r--r--drivers/mailbox/pcc.c13
-rw-r--r--drivers/md/dm-raid.c15
-rw-r--r--drivers/md/dm-raid1.c22
-rw-r--r--drivers/md/dm-rq.c7
-rw-r--r--drivers/md/dm-table.c24
-rw-r--r--drivers/md/dm.c4
-rw-r--r--drivers/md/md.c10
-rw-r--r--drivers/md/raid1.c26
-rw-r--r--drivers/md/raid10.c7
-rw-r--r--drivers/md/raid5-cache.c6
-rw-r--r--drivers/media/dvb-frontends/Kconfig5
-rw-r--r--drivers/media/dvb-frontends/Makefile1
-rw-r--r--drivers/media/dvb-frontends/gp8psk-fe.c (renamed from drivers/media/usb/dvb-usb/gp8psk-fe.c)156
-rw-r--r--drivers/media/dvb-frontends/gp8psk-fe.h82
-rw-r--r--drivers/media/i2c/ir-kbd-i2c.c2
-rw-r--r--drivers/media/pci/ivtv/ivtv-udma.c4
-rw-r--r--drivers/media/pci/ivtv/ivtv-yuv.c5
-rw-r--r--drivers/media/platform/omap/omap_vout.c2
-rw-r--r--drivers/media/tuners/tuner-xc2028.c37
-rw-r--r--drivers/media/usb/b2c2/flexcop-usb.c105
-rw-r--r--drivers/media/usb/b2c2/flexcop-usb.h4
-rw-r--r--drivers/media/usb/cpia2/cpia2_usb.c34
-rw-r--r--drivers/media/usb/dvb-usb/Makefile2
-rw-r--r--drivers/media/usb/dvb-usb/af9005.c304
-rw-r--r--drivers/media/usb/dvb-usb/cinergyT2-core.c77
-rw-r--r--drivers/media/usb/dvb-usb/cinergyT2-fe.c100
-rw-r--r--drivers/media/usb/dvb-usb/cxusb.c27
-rw-r--r--drivers/media/usb/dvb-usb/cxusb.h5
-rw-r--r--drivers/media/usb/dvb-usb/dib0700_core.c36
-rw-r--r--drivers/media/usb/dvb-usb/dib0700_devices.c25
-rw-r--r--drivers/media/usb/dvb-usb/dibusb-common.c113
-rw-r--r--drivers/media/usb/dvb-usb/dibusb.h3
-rw-r--r--drivers/media/usb/dvb-usb/digitv.c26
-rw-r--r--drivers/media/usb/dvb-usb/digitv.h5
-rw-r--r--drivers/media/usb/dvb-usb/dtt200u-fe.c128
-rw-r--r--drivers/media/usb/dvb-usb/dtt200u.c104
-rw-r--r--drivers/media/usb/dvb-usb/dtv5100.c10
-rw-r--r--drivers/media/usb/dvb-usb/dvb-usb-init.c1
-rw-r--r--drivers/media/usb/dvb-usb/dvb-usb.h9
-rw-r--r--drivers/media/usb/dvb-usb/dw2102.c2
-rw-r--r--drivers/media/usb/dvb-usb/gp8psk.c132
-rw-r--r--drivers/media/usb/dvb-usb/gp8psk.h63
-rw-r--r--drivers/media/usb/dvb-usb/nova-t-usb2.c25
-rw-r--r--drivers/media/usb/dvb-usb/pctv452e.c136
-rw-r--r--drivers/media/usb/dvb-usb/technisat-usb2.c16
-rw-r--r--drivers/media/usb/s2255/s2255drv.c15
-rw-r--r--drivers/media/usb/stkwebcam/stk-webcam.c16
-rw-r--r--drivers/media/v4l2-core/videobuf-dma-sg.c7
-rw-r--r--drivers/media/v4l2-core/videobuf2-memops.c6
-rw-r--r--drivers/memstick/host/rtsx_usb_ms.c6
-rw-r--r--drivers/mfd/intel-lpss-pci.c31
-rw-r--r--drivers/mfd/intel-lpss.c3
-rw-r--r--drivers/mfd/intel_soc_pmic_bxtwc.c6
-rw-r--r--drivers/mfd/mfd-core.c2
-rw-r--r--drivers/mfd/stmpe.c2
-rw-r--r--drivers/mfd/syscon.c4
-rw-r--r--drivers/mfd/wm8994-core.c16
-rw-r--r--drivers/misc/cxl/api.c11
-rw-r--r--drivers/misc/cxl/context.c3
-rw-r--r--drivers/misc/cxl/cxl.h24
-rw-r--r--drivers/misc/cxl/file.c15
-rw-r--r--drivers/misc/cxl/guest.c3
-rw-r--r--drivers/misc/cxl/main.c42
-rw-r--r--drivers/misc/cxl/pci.c2
-rw-r--r--drivers/misc/cxl/sysfs.c27
-rw-r--r--drivers/misc/genwqe/card_utils.c12
-rw-r--r--drivers/misc/mei/bus-fixup.c2
-rw-r--r--drivers/misc/mei/hw-txe.c6
-rw-r--r--drivers/misc/mic/scif/scif_rma.c3
-rw-r--r--drivers/misc/sgi-gru/grufault.c2
-rw-r--r--drivers/misc/sgi-gru/grumain.c2
-rw-r--r--drivers/misc/vmw_vmci/vmci_doorbell.c8
-rw-r--r--drivers/misc/vmw_vmci/vmci_driver.c2
-rw-r--r--drivers/mmc/card/block.c3
-rw-r--r--drivers/mmc/card/mmc_test.c8
-rw-r--r--drivers/mmc/card/queue.h2
-rw-r--r--drivers/mmc/core/mmc.c15
-rw-r--r--drivers/mmc/host/dw_mmc-pltfm.c5
-rw-r--r--drivers/mmc/host/dw_mmc.c3
-rw-r--r--drivers/mmc/host/mxs-mmc.c4
-rw-r--r--drivers/mmc/host/rtsx_usb_sdmmc.c7
-rw-r--r--drivers/mmc/host/sdhci-esdhc-imx.c23
-rw-r--r--drivers/mmc/host/sdhci-msm.c1
-rw-r--r--drivers/mmc/host/sdhci-of-arasan.c26
-rw-r--r--drivers/mmc/host/sdhci-of-esdhc.c14
-rw-r--r--drivers/mmc/host/sdhci-pci-core.c54
-rw-r--r--drivers/mmc/host/sdhci-pci.h2
-rw-r--r--drivers/mmc/host/sdhci-pxav3.c2
-rw-r--r--drivers/mmc/host/sdhci.c78
-rw-r--r--drivers/mmc/host/sdhci.h3
-rw-r--r--drivers/mtd/nand/gpmi-nand/gpmi-lib.c6
-rw-r--r--drivers/mtd/nand/mtk_ecc.c19
-rw-r--r--drivers/mtd/nand/nand_base.c60
-rw-r--r--drivers/mtd/ubi/eba.c1
-rw-r--r--drivers/mtd/ubi/fastmap.c12
-rw-r--r--drivers/net/can/sja1000/plx_pci.c18
-rw-r--r--drivers/net/can/usb/peak_usb/pcan_ucan.h37
-rw-r--r--drivers/net/can/usb/peak_usb/pcan_usb_core.c8
-rw-r--r--drivers/net/can/usb/peak_usb/pcan_usb_core.h2
-rw-r--r--drivers/net/can/usb/peak_usb/pcan_usb_fd.c104
-rw-r--r--drivers/net/dsa/b53/b53_common.c16
-rw-r--r--drivers/net/dsa/b53/b53_mmap.c1
-rw-r--r--drivers/net/dsa/bcm_sf2.c20
-rw-r--r--drivers/net/ethernet/altera/altera_tse_main.c21
-rw-r--r--drivers/net/ethernet/amd/xgbe/xgbe-main.c4
-rw-r--r--drivers/net/ethernet/apm/xgene/xgene_enet_hw.c12
-rw-r--r--drivers/net/ethernet/apm/xgene/xgene_enet_hw.h2
-rw-r--r--drivers/net/ethernet/apm/xgene/xgene_enet_main.c3
-rw-r--r--drivers/net/ethernet/apm/xgene/xgene_enet_ring2.c12
-rw-r--r--drivers/net/ethernet/arc/emac_main.c7
-rw-r--r--drivers/net/ethernet/aurora/nb8800.c10
-rw-r--r--drivers/net/ethernet/broadcom/bcm63xx_enet.c3
-rw-r--r--drivers/net/ethernet/broadcom/bcmsysport.c17
-rw-r--r--drivers/net/ethernet/broadcom/bgmac.c11
-rw-r--r--drivers/net/ethernet/broadcom/bnx2.c65
-rw-r--r--drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c8
-rw-r--r--drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c7
-rw-r--r--drivers/net/ethernet/broadcom/bnxt/bnxt.c32
-rw-r--r--drivers/net/ethernet/broadcom/bnxt/bnxt_sriov.c4
-rw-r--r--drivers/net/ethernet/broadcom/genet/bcmgenet.c8
-rw-r--r--drivers/net/ethernet/broadcom/genet/bcmmii.c10
-rw-r--r--drivers/net/ethernet/brocade/bna/bnad.c4
-rw-r--r--drivers/net/ethernet/cadence/macb.c11
-rw-r--r--drivers/net/ethernet/cavium/thunder/nic.h64
-rw-r--r--drivers/net/ethernet/cavium/thunder/nic_main.c37
-rw-r--r--drivers/net/ethernet/cavium/thunder/nic_reg.h1
-rw-r--r--drivers/net/ethernet/cavium/thunder/nicvf_ethtool.c105
-rw-r--r--drivers/net/ethernet/cavium/thunder/nicvf_main.c153
-rw-r--r--drivers/net/ethernet/cavium/thunder/nicvf_queues.c118
-rw-r--r--drivers/net/ethernet/cavium/thunder/nicvf_queues.h24
-rw-r--r--drivers/net/ethernet/cavium/thunder/thunder_bgx.c4
-rw-r--r--drivers/net/ethernet/cavium/thunder/thunder_bgx.h2
-rw-r--r--drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c3
-rw-r--r--drivers/net/ethernet/chelsio/cxgb4/cxgb4_uld.c40
-rw-r--r--drivers/net/ethernet/chelsio/cxgb4/sched.c4
-rw-r--r--drivers/net/ethernet/chelsio/cxgb4/sge.c1
-rw-r--r--drivers/net/ethernet/chelsio/cxgb4/t4_hw.c1
-rw-r--r--drivers/net/ethernet/chelsio/cxgb4/t4_pci_id_tbl.h3
-rw-r--r--drivers/net/ethernet/chelsio/cxgb4vf/cxgb4vf_main.c1
-rw-r--r--drivers/net/ethernet/cirrus/ep93xx_eth.c4
-rw-r--r--drivers/net/ethernet/cisco/enic/vnic_rq.c32
-rw-r--r--drivers/net/ethernet/emulex/benet/be_cmds.c3
-rw-r--r--drivers/net/ethernet/emulex/benet/be_main.c1
-rw-r--r--drivers/net/ethernet/ezchip/nps_enet.c1
-rw-r--r--drivers/net/ethernet/freescale/fec.h2
-rw-r--r--drivers/net/ethernet/freescale/fec_main.c43
-rw-r--r--drivers/net/ethernet/freescale/fman/fman_memac.c3
-rw-r--r--drivers/net/ethernet/freescale/fman/fman_tgec.c3
-rw-r--r--drivers/net/ethernet/freescale/fman/mac.c2
-rw-r--r--drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c7
-rw-r--r--drivers/net/ethernet/freescale/gianfar.c8
-rw-r--r--drivers/net/ethernet/freescale/ucc_geth.c23
-rw-r--r--drivers/net/ethernet/hisilicon/hns/hnae.c8
-rw-r--r--drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c1
-rw-r--r--drivers/net/ethernet/hisilicon/hns_mdio.c1
-rw-r--r--drivers/net/ethernet/ibm/ehea/ehea_main.c2
-rw-r--r--drivers/net/ethernet/ibm/ibmveth.c65
-rw-r--r--drivers/net/ethernet/ibm/ibmveth.h1
-rw-r--r--drivers/net/ethernet/ibm/ibmvnic.c56
-rw-r--r--drivers/net/ethernet/ibm/ibmvnic.h3
-rw-r--r--drivers/net/ethernet/intel/i40e/i40e.h1
-rw-r--r--drivers/net/ethernet/intel/i40e/i40e_main.c34
-rw-r--r--drivers/net/ethernet/intel/igb/igb_main.c8
-rw-r--r--drivers/net/ethernet/intel/igbvf/netdev.c8
-rw-r--r--drivers/net/ethernet/intel/ixgbe/ixgbe_main.c20
-rw-r--r--drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c8
-rw-r--r--drivers/net/ethernet/lantiq_etop.c1
-rw-r--r--drivers/net/ethernet/marvell/mv643xx_eth.c25
-rw-r--r--drivers/net/ethernet/marvell/mvneta.c7
-rw-r--r--drivers/net/ethernet/marvell/mvpp2.c2
-rw-r--r--drivers/net/ethernet/marvell/sky2.c13
-rw-r--r--drivers/net/ethernet/mediatek/mtk_eth_soc.c4
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/cmd.c9
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/en_clock.c5
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/en_cq.c10
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/en_netdev.c34
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/en_port.c4
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/en_selftest.c26
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/eq.c62
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/fw.c4
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/main.c15
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/mcg.c7
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/mlx4.h5
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/port.c13
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/resource_tracker.c5
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/Kconfig2
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/alloc.c31
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/cmd.c5
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/en.h9
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/en_main.c67
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/en_rep.c3
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/en_rx.c8
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/en_tc.c5
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/en_tx.c2
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/en_txrx.c4
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/eswitch.c50
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c3
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/fs_core.c11
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/fs_counters.c1
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/health.c76
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/main.c83
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/mlx5_core.h16
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/pagealloc.c26
-rw-r--r--drivers/net/ethernet/mellanox/mlxsw/pci.c10
-rw-r--r--drivers/net/ethernet/mellanox/mlxsw/spectrum.c4
-rw-r--r--drivers/net/ethernet/mellanox/mlxsw/spectrum.h2
-rw-r--r--drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c155
-rw-r--r--drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c14
-rw-r--r--drivers/net/ethernet/mellanox/mlxsw/switchx2.c1
-rw-r--r--drivers/net/ethernet/qlogic/Kconfig3
-rw-r--r--drivers/net/ethernet/qlogic/qed/Makefile2
-rw-r--r--drivers/net/ethernet/qlogic/qed/qed_cxt.c15
-rw-r--r--drivers/net/ethernet/qlogic/qed/qed_dcbx.c2
-rw-r--r--drivers/net/ethernet/qlogic/qed/qed_debug.c53
-rw-r--r--drivers/net/ethernet/qlogic/qed/qed_dev.c19
-rw-r--r--drivers/net/ethernet/qlogic/qed/qed_hsi.h3
-rw-r--r--drivers/net/ethernet/qlogic/qed/qed_ll2.c29
-rw-r--r--drivers/net/ethernet/qlogic/qed/qed_ll2.h20
-rw-r--r--drivers/net/ethernet/qlogic/qed/qed_main.c30
-rw-r--r--drivers/net/ethernet/qlogic/qed/qed_roce.c216
-rw-r--r--drivers/net/ethernet/qlogic/qed/qed_roce.h95
-rw-r--r--drivers/net/ethernet/qlogic/qed/qed_sp.h1
-rw-r--r--drivers/net/ethernet/qlogic/qed/qed_spq.c4
-rw-r--r--drivers/net/ethernet/qlogic/qede/Makefile2
-rw-r--r--drivers/net/ethernet/qlogic/qede/qede.h3
-rw-r--r--drivers/net/ethernet/qlogic/qede/qede_ethtool.c124
-rw-r--r--drivers/net/ethernet/qlogic/qede/qede_main.c17
-rw-r--r--drivers/net/ethernet/qualcomm/emac/emac-mac.c23
-rw-r--r--drivers/net/ethernet/qualcomm/emac/emac-phy.c1
-rw-r--r--drivers/net/ethernet/qualcomm/emac/emac-sgmii.c2
-rw-r--r--drivers/net/ethernet/qualcomm/emac/emac.c5
-rw-r--r--drivers/net/ethernet/realtek/r8169.c3
-rw-r--r--drivers/net/ethernet/renesas/ravb_main.c19
-rw-r--r--drivers/net/ethernet/renesas/sh_eth.c2
-rw-r--r--drivers/net/ethernet/rocker/rocker_main.c2
-rw-r--r--drivers/net/ethernet/rocker/rocker_ofdpa.c4
-rw-r--r--drivers/net/ethernet/sfc/efx.c3
-rw-r--r--drivers/net/ethernet/smsc/smsc911x.c9
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/Kconfig2
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/altr_tse_pcs.c4
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/common.h24
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/descs.h20
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/dwmac-generic.c17
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/dwmac-ipq806x.c25
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/dwmac-lpc18xx.c17
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/dwmac-meson.c23
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/dwmac-meson8b.c32
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c21
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c39
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c23
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c19
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/dwmac-sunxi.c26
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c2
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c102
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.h4
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/dwmac4_dma.c2
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/enh_desc.c28
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/stmmac.h3
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c19
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c43
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/stmmac_main.c111
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c39
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/stmmac_platform.h2
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c22
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h72
-rw-r--r--drivers/net/ethernet/sun/sunbmac.c5
-rw-r--r--drivers/net/ethernet/sun/sunbmac.h2
-rw-r--r--drivers/net/ethernet/sun/sunqe.c11
-rw-r--r--drivers/net/ethernet/sun/sunqe.h4
-rw-r--r--drivers/net/ethernet/synopsys/dwc_eth_qos.c26
-rw-r--r--drivers/net/ethernet/ti/cpmac.c1
-rw-r--r--drivers/net/ethernet/ti/cpsw-phy-sel.c4
-rw-r--r--drivers/net/ethernet/ti/cpsw.c87
-rw-r--r--drivers/net/ethernet/ti/davinci_emac.c20
-rw-r--r--drivers/net/ethernet/toshiba/ps3_gelic_wireless.c2
-rw-r--r--drivers/net/ethernet/xscale/ixp4xx_eth.c3
-rw-r--r--drivers/net/geneve.c61
-rw-r--r--drivers/net/hyperv/netvsc_drv.c30
-rw-r--r--drivers/net/ieee802154/adf7242.c1
-rw-r--r--drivers/net/ipvlan/ipvlan_main.c19
-rw-r--r--drivers/net/irda/irda-usb.c1
-rw-r--r--drivers/net/irda/w83977af_ir.c4
-rw-r--r--drivers/net/macsec.c26
-rw-r--r--drivers/net/macvlan.c34
-rw-r--r--drivers/net/macvtap.c19
-rw-r--r--drivers/net/phy/at803x.c65
-rw-r--r--drivers/net/phy/dp83848.c3
-rw-r--r--drivers/net/phy/fixed_phy.c2
-rw-r--r--drivers/net/phy/micrel.c8
-rw-r--r--drivers/net/phy/phy_device.c18
-rw-r--r--drivers/net/phy/realtek.c20
-rw-r--r--drivers/net/phy/vitesse.c34
-rw-r--r--drivers/net/tun.c10
-rw-r--r--drivers/net/usb/asix_common.c8
-rw-r--r--drivers/net/usb/asix_devices.c6
-rw-r--r--drivers/net/usb/ax88179_178a.c17
-rw-r--r--drivers/net/usb/cdc_ether.c38
-rw-r--r--drivers/net/usb/cdc_mbim.c21
-rw-r--r--drivers/net/usb/cdc_ncm.c14
-rw-r--r--drivers/net/usb/kalmia.c2
-rw-r--r--drivers/net/usb/lan78xx.c1
-rw-r--r--drivers/net/usb/qmi_wwan.c1
-rw-r--r--drivers/net/usb/r8152.c21
-rw-r--r--drivers/net/virtio_net.c54
-rw-r--r--drivers/net/vmxnet3/vmxnet3_drv.c17
-rw-r--r--drivers/net/vrf.c2
-rw-r--r--drivers/net/vxlan.c94
-rw-r--r--drivers/net/wan/Kconfig2
-rw-r--r--drivers/net/wan/slic_ds26522.c8
-rw-r--r--drivers/net/wireless/ath/ath10k/core.h1
-rw-r--r--drivers/net/wireless/ath/ath10k/debug.c75
-rw-r--r--drivers/net/wireless/ath/ath6kl/sdio.c1
-rw-r--r--drivers/net/wireless/ath/ath9k/ar9003_calib.c25
-rw-r--r--drivers/net/wireless/ath/ath9k/hw.h1
-rw-r--r--drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c2
-rw-r--r--drivers/net/wireless/intel/iwlwifi/mvm/d3.c49
-rw-r--r--drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c4
-rw-r--r--drivers/net/wireless/intel/iwlwifi/mvm/mac80211.c3
-rw-r--r--drivers/net/wireless/intel/iwlwifi/mvm/mvm.h1
-rw-r--r--drivers/net/wireless/intel/iwlwifi/mvm/ops.c1
-rw-r--r--drivers/net/wireless/intel/iwlwifi/mvm/rxmq.c3
-rw-r--r--drivers/net/wireless/intel/iwlwifi/mvm/scan.c33
-rw-r--r--drivers/net/wireless/intel/iwlwifi/pcie/drv.c79
-rw-r--r--drivers/net/wireless/intel/iwlwifi/pcie/tx.c8
-rw-r--r--drivers/net/wireless/mac80211_hwsim.c2
-rw-r--r--drivers/net/wireless/marvell/mwifiex/11n_rxreorder.c2
-rw-r--r--drivers/net/wireless/marvell/mwifiex/cfg80211.c13
-rw-r--r--drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h4
-rw-r--r--drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192e.c8
-rw-r--r--drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8723b.c4
-rw-r--r--drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c11
-rw-r--r--drivers/net/wireless/realtek/rtlwifi/core.c2
-rw-r--r--drivers/net/wireless/realtek/rtlwifi/rtl8188ee/sw.c8
-rw-r--r--drivers/net/wireless/realtek/rtlwifi/rtl8192ce/sw.c13
-rw-r--r--drivers/net/wireless/realtek/rtlwifi/rtl8192cu/sw.c12
-rw-r--r--drivers/net/wireless/realtek/rtlwifi/rtl8192de/sw.c6
-rw-r--r--drivers/net/wireless/realtek/rtlwifi/rtl8192ee/sw.c8
-rw-r--r--drivers/net/wireless/realtek/rtlwifi/rtl8192se/sw.c9
-rw-r--r--drivers/net/wireless/realtek/rtlwifi/rtl8723ae/sw.c12
-rw-r--r--drivers/net/wireless/realtek/rtlwifi/rtl8723be/sw.c6
-rw-r--r--drivers/net/wireless/realtek/rtlwifi/rtl8821ae/sw.c18
-rw-r--r--drivers/net/wireless/realtek/rtlwifi/wifi.h2
-rw-r--r--drivers/net/wireless/ti/wlcore/sdio.c1
-rw-r--r--drivers/net/xen-netfront.c4
-rw-r--r--drivers/nfc/mei_phy.c2
-rw-r--r--drivers/ntb/hw/intel/ntb_hw_intel.c15
-rw-r--r--drivers/ntb/ntb_transport.c2
-rw-r--r--drivers/ntb/test/ntb_perf.c8
-rw-r--r--drivers/ntb/test/ntb_pingpong.c2
-rw-r--r--drivers/nvdimm/Kconfig2
-rw-r--r--drivers/nvdimm/bus.c25
-rw-r--r--drivers/nvdimm/namespace_devs.c14
-rw-r--r--drivers/nvdimm/pmem.c8
-rw-r--r--drivers/nvme/host/core.c14
-rw-r--r--drivers/nvme/host/lightnvm.c2
-rw-r--r--drivers/nvme/host/pci.c95
-rw-r--r--drivers/nvme/host/rdma.c42
-rw-r--r--drivers/nvme/host/scsi.c4
-rw-r--r--drivers/nvme/target/admin-cmd.c8
-rw-r--r--drivers/nvme/target/core.c12
-rw-r--r--drivers/nvme/target/discovery.c4
-rw-r--r--drivers/nvme/target/rdma.c18
-rw-r--r--drivers/of/base.c2
-rw-r--r--drivers/of/of_mdio.c21
-rw-r--r--drivers/pci/host/pci-layerscape.c2
-rw-r--r--drivers/pci/host/pcie-designware-plat.c2
-rw-r--r--drivers/pci/host/pcie-designware.c7
-rw-r--r--drivers/pci/host/pcie-qcom.c2
-rw-r--r--drivers/pci/host/pcie-rockchip.c62
-rw-r--r--drivers/pci/msi.c2
-rw-r--r--drivers/pci/pci-mid.c6
-rw-r--r--drivers/pci/pcie/aer/aer_inject.c14
-rw-r--r--drivers/pci/probe.c28
-rw-r--r--drivers/pci/setup-res.c8
-rw-r--r--drivers/pcmcia/soc_common.c2
-rw-r--r--drivers/perf/xgene_pmu.c2
-rw-r--r--drivers/phy/phy-da8xx-usb.c5
-rw-r--r--drivers/phy/phy-rockchip-pcie.c13
-rw-r--r--drivers/phy/phy-sun4i-usb.c2
-rw-r--r--drivers/phy/phy-twl4030-usb.c4
-rw-r--r--drivers/pinctrl/aspeed/pinctrl-aspeed-g5.c102
-rw-r--r--drivers/pinctrl/aspeed/pinctrl-aspeed.c12
-rw-r--r--drivers/pinctrl/bcm/pinctrl-iproc-gpio.c2
-rw-r--r--drivers/pinctrl/bcm/pinctrl-nsp-gpio.c2
-rw-r--r--drivers/pinctrl/freescale/pinctrl-imx.c1
-rw-r--r--drivers/pinctrl/intel/pinctrl-baytrail.c3
-rw-r--r--drivers/pinctrl/intel/pinctrl-cherryview.c17
-rw-r--r--drivers/pinctrl/intel/pinctrl-intel.c25
-rw-r--r--drivers/pinctrl/pinctrl-st.c2
-rw-r--r--drivers/pinctrl/stm32/pinctrl-stm32.c8
-rw-r--r--drivers/platform/goldfish/goldfish_pipe.c3
-rw-r--r--drivers/platform/x86/Kconfig1
-rw-r--r--drivers/platform/x86/ideapad-laptop.c14
-rw-r--r--drivers/platform/x86/intel-hid.c2
-rw-r--r--drivers/platform/x86/intel-vbtn.c2
-rw-r--r--drivers/platform/x86/toshiba-wmi.c26
-rw-r--r--drivers/pwm/pwm-meson.c1
-rw-r--r--drivers/pwm/sysfs.c2
-rw-r--r--drivers/rapidio/devices/rio_mport_cdev.c3
-rw-r--r--drivers/regulator/core.c2
-rw-r--r--drivers/regulator/rk808-regulator.c9
-rw-r--r--drivers/reset/reset-uniphier.c16
-rw-r--r--drivers/rtc/rtc-asm9260.c1
-rw-r--r--drivers/rtc/rtc-cmos.c15
-rw-r--r--drivers/rtc/rtc-omap.c38
-rw-r--r--drivers/s390/block/dasd_eckd.c4
-rw-r--r--drivers/s390/cio/chp.c6
-rw-r--r--drivers/s390/scsi/zfcp_dbf.c2
-rw-r--r--drivers/scsi/NCR5380.c6
-rw-r--r--drivers/scsi/arcmsr/arcmsr_hba.c9
-rw-r--r--drivers/scsi/be2iscsi/be_main.c37
-rw-r--r--drivers/scsi/be2iscsi/be_mgmt.c2
-rw-r--r--drivers/scsi/cxgbi/libcxgbi.c3
-rw-r--r--drivers/scsi/device_handler/scsi_dh_alua.c5
-rw-r--r--drivers/scsi/hpsa.c16
-rw-r--r--drivers/scsi/hpsa.h2
-rw-r--r--drivers/scsi/ipr.c3
-rw-r--r--drivers/scsi/libfc/fc_lport.c2
-rw-r--r--drivers/scsi/libiscsi.c4
-rw-r--r--drivers/scsi/lpfc/lpfc_sli.c14
-rw-r--r--drivers/scsi/megaraid/megaraid_sas.h2
-rw-r--r--drivers/scsi/megaraid/megaraid_sas_base.c13
-rw-r--r--drivers/scsi/mpt3sas/mpt3sas_scsih.c24
-rw-r--r--drivers/scsi/mvsas/mv_sas.c4
-rw-r--r--drivers/scsi/qla2xxx/qla_os.c21
-rw-r--r--drivers/scsi/qlogicpti.h4
-rw-r--r--drivers/scsi/scsi_debug.c1
-rw-r--r--drivers/scsi/scsi_dh.c6
-rw-r--r--drivers/scsi/scsi_scan.c6
-rw-r--r--drivers/scsi/st.c5
-rw-r--r--drivers/scsi/vmw_pvscsi.c5
-rw-r--r--drivers/scsi/vmw_pvscsi.h2
-rw-r--r--drivers/spi/spi-fsl-dspi.c7
-rw-r--r--drivers/spi/spi-fsl-espi.c2
-rw-r--r--drivers/spi/spi.c5
-rw-r--r--drivers/staging/android/ion/ion.c6
-rw-r--r--drivers/staging/android/ion/ion_of.c2
-rw-r--r--drivers/staging/comedi/drivers/ni_tio.c3
-rw-r--r--drivers/staging/greybus/arche-platform.c2
-rw-r--r--drivers/staging/greybus/es2.c3
-rw-r--r--drivers/staging/greybus/gpio.c6
-rw-r--r--drivers/staging/greybus/module.c2
-rw-r--r--drivers/staging/greybus/uart.c2
-rw-r--r--drivers/staging/iio/accel/sca3000_core.c2
-rw-r--r--drivers/staging/iio/impedance-analyzer/ad5933.c17
-rw-r--r--drivers/staging/lustre/lustre/llite/lproc_llite.c34
-rw-r--r--drivers/staging/media/bcm2048/radio-bcm2048.c2
-rw-r--r--drivers/staging/nvec/nvec_ps2.c8
-rw-r--r--drivers/staging/sm750fb/ddk750_reg.h8
-rw-r--r--drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c3
-rw-r--r--drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c3
-rw-r--r--drivers/staging/wilc1000/host_interface.c1
-rw-r--r--drivers/target/iscsi/iscsi_target.c6
-rw-r--r--drivers/target/iscsi/iscsi_target_login.c4
-rw-r--r--drivers/target/target_core_transport.c39
-rw-r--r--drivers/target/target_core_user.c50
-rw-r--r--drivers/target/target_core_xcopy.c34
-rw-r--r--drivers/target/tcm_fc/tfc_cmd.c4
-rw-r--r--drivers/target/tcm_fc/tfc_sess.c42
-rw-r--r--drivers/thermal/intel_pch_thermal.c60
-rw-r--r--drivers/thermal/intel_powerclamp.c9
-rw-r--r--drivers/tty/serial/8250/8250_lpss.c2
-rw-r--r--drivers/tty/serial/8250/8250_port.c3
-rw-r--r--drivers/tty/serial/8250/8250_uniphier.c4
-rw-r--r--drivers/tty/serial/Kconfig1
-rw-r--r--drivers/tty/serial/atmel_serial.c26
-rw-r--r--drivers/tty/serial/fsl_lpuart.c3
-rw-r--r--drivers/tty/serial/pch_uart.c1
-rw-r--r--drivers/tty/serial/sc16is7xx.c8
-rw-r--r--drivers/tty/serial/serial_core.c8
-rw-r--r--drivers/tty/serial/stm32-usart.h2
-rw-r--r--drivers/tty/serial/xilinx_uartps.c2
-rw-r--r--drivers/tty/vt/vt.c7
-rw-r--r--drivers/usb/chipidea/core.c1
-rw-r--r--drivers/usb/chipidea/host.c2
-rw-r--r--drivers/usb/chipidea/udc.c2
-rw-r--r--drivers/usb/class/cdc-acm.c4
-rw-r--r--drivers/usb/dwc2/core.c11
-rw-r--r--drivers/usb/dwc2/core.h7
-rw-r--r--drivers/usb/dwc2/gadget.c53
-rw-r--r--drivers/usb/dwc3/core.c5
-rw-r--r--drivers/usb/dwc3/dwc3-st.c1
-rw-r--r--drivers/usb/dwc3/gadget.c26
-rw-r--r--drivers/usb/gadget/function/f_fs.c115
-rw-r--r--drivers/usb/gadget/function/u_ether.c7
-rw-r--r--drivers/usb/gadget/udc/atmel_usba_udc.c2
-rw-r--r--drivers/usb/host/ehci-platform.c2
-rw-r--r--drivers/usb/host/ohci-at91.c9
-rw-r--r--drivers/usb/host/ohci-hcd.c2
-rw-r--r--drivers/usb/host/pci-quirks.c8
-rw-r--r--drivers/usb/host/xhci-hub.c41
-rw-r--r--drivers/usb/host/xhci-pci.c10
-rw-r--r--drivers/usb/host/xhci.h3
-rw-r--r--drivers/usb/musb/da8xx.c3
-rw-r--r--drivers/usb/musb/musb_core.c152
-rw-r--r--drivers/usb/musb/musb_core.h13
-rw-r--r--drivers/usb/musb/musb_dsps.c58
-rw-r--r--drivers/usb/musb/musb_gadget.c41
-rw-r--r--drivers/usb/musb/omap2430.c17
-rw-r--r--drivers/usb/musb/tusb6010.c6
-rw-r--r--drivers/usb/renesas_usbhs/rcar3.c8
-rw-r--r--drivers/usb/serial/cp210x.c5
-rw-r--r--drivers/usb/serial/ftdi_sio.c5
-rw-r--r--drivers/usb/serial/ftdi_sio_ids.h11
-rw-r--r--drivers/usb/serial/usb-serial.c3
-rw-r--r--drivers/usb/storage/transport.c7
-rw-r--r--drivers/usb/wusbcore/crypto.c61
-rw-r--r--drivers/uwb/lc-rc.c16
-rw-r--r--drivers/uwb/pal.c2
-rw-r--r--drivers/vfio/pci/vfio_pci.c33
-rw-r--r--drivers/vfio/pci/vfio_pci_intrs.c2
-rw-r--r--drivers/vhost/vsock.c2
-rw-r--r--drivers/video/fbdev/amba-clcd-versatile.c4
-rw-r--r--drivers/video/fbdev/pvr2fb.c4
-rw-r--r--drivers/virt/fsl_hypervisor.c4
-rw-r--r--drivers/virtio/config.c12
-rw-r--r--drivers/virtio/virtio_balloon.c2
-rw-r--r--drivers/virtio/virtio_pci_legacy.c16
-rw-r--r--drivers/virtio/virtio_ring.c16
-rw-r--r--drivers/vme/vme.c4
-rw-r--r--drivers/watchdog/Kconfig1
-rw-r--r--drivers/watchdog/wdat_wdt.c4
-rw-r--r--drivers/xen/manage.c45
-rw-r--r--drivers/xen/xenbus/xenbus_dev_frontend.c4
-rw-r--r--drivers/xen/xenbus/xenbus_probe_frontend.c4
873 files changed, 10395 insertions, 5551 deletions
diff --git a/drivers/Makefile b/drivers/Makefile
index f0afdfb3c7df..194d20bee7dc 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -21,7 +21,7 @@ obj-y += video/
21obj-y += idle/ 21obj-y += idle/
22 22
23# IPMI must come before ACPI in order to provide IPMI opregion support 23# IPMI must come before ACPI in order to provide IPMI opregion support
24obj-$(CONFIG_IPMI_HANDLER) += char/ipmi/ 24obj-y += char/ipmi/
25 25
26obj-$(CONFIG_ACPI) += acpi/ 26obj-$(CONFIG_ACPI) += acpi/
27obj-$(CONFIG_SFI) += sfi/ 27obj-$(CONFIG_SFI) += sfi/
diff --git a/drivers/acpi/acpi_apd.c b/drivers/acpi/acpi_apd.c
index d58fbf7f04e6..7dd70927991e 100644
--- a/drivers/acpi/acpi_apd.c
+++ b/drivers/acpi/acpi_apd.c
@@ -122,7 +122,7 @@ static int acpi_apd_create_device(struct acpi_device *adev,
122 int ret; 122 int ret;
123 123
124 if (!dev_desc) { 124 if (!dev_desc) {
125 pdev = acpi_create_platform_device(adev); 125 pdev = acpi_create_platform_device(adev, NULL);
126 return IS_ERR_OR_NULL(pdev) ? PTR_ERR(pdev) : 1; 126 return IS_ERR_OR_NULL(pdev) ? PTR_ERR(pdev) : 1;
127 } 127 }
128 128
@@ -139,14 +139,8 @@ static int acpi_apd_create_device(struct acpi_device *adev,
139 goto err_out; 139 goto err_out;
140 } 140 }
141 141
142 if (dev_desc->properties) {
143 ret = device_add_properties(&adev->dev, dev_desc->properties);
144 if (ret)
145 goto err_out;
146 }
147
148 adev->driver_data = pdata; 142 adev->driver_data = pdata;
149 pdev = acpi_create_platform_device(adev); 143 pdev = acpi_create_platform_device(adev, dev_desc->properties);
150 if (!IS_ERR_OR_NULL(pdev)) 144 if (!IS_ERR_OR_NULL(pdev))
151 return 1; 145 return 1;
152 146
diff --git a/drivers/acpi/acpi_lpss.c b/drivers/acpi/acpi_lpss.c
index 552010288135..373657f7e35a 100644
--- a/drivers/acpi/acpi_lpss.c
+++ b/drivers/acpi/acpi_lpss.c
@@ -395,7 +395,7 @@ static int acpi_lpss_create_device(struct acpi_device *adev,
395 395
396 dev_desc = (const struct lpss_device_desc *)id->driver_data; 396 dev_desc = (const struct lpss_device_desc *)id->driver_data;
397 if (!dev_desc) { 397 if (!dev_desc) {
398 pdev = acpi_create_platform_device(adev); 398 pdev = acpi_create_platform_device(adev, NULL);
399 return IS_ERR_OR_NULL(pdev) ? PTR_ERR(pdev) : 1; 399 return IS_ERR_OR_NULL(pdev) ? PTR_ERR(pdev) : 1;
400 } 400 }
401 pdata = kzalloc(sizeof(*pdata), GFP_KERNEL); 401 pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
@@ -451,14 +451,8 @@ static int acpi_lpss_create_device(struct acpi_device *adev,
451 goto err_out; 451 goto err_out;
452 } 452 }
453 453
454 if (dev_desc->properties) {
455 ret = device_add_properties(&adev->dev, dev_desc->properties);
456 if (ret)
457 goto err_out;
458 }
459
460 adev->driver_data = pdata; 454 adev->driver_data = pdata;
461 pdev = acpi_create_platform_device(adev); 455 pdev = acpi_create_platform_device(adev, dev_desc->properties);
462 if (!IS_ERR_OR_NULL(pdev)) { 456 if (!IS_ERR_OR_NULL(pdev)) {
463 return 1; 457 return 1;
464 } 458 }
diff --git a/drivers/acpi/acpi_platform.c b/drivers/acpi/acpi_platform.c
index b200ae1f3c6f..b4c1a6a51da4 100644
--- a/drivers/acpi/acpi_platform.c
+++ b/drivers/acpi/acpi_platform.c
@@ -50,6 +50,7 @@ static void acpi_platform_fill_resource(struct acpi_device *adev,
50/** 50/**
51 * acpi_create_platform_device - Create platform device for ACPI device node 51 * acpi_create_platform_device - Create platform device for ACPI device node
52 * @adev: ACPI device node to create a platform device for. 52 * @adev: ACPI device node to create a platform device for.
53 * @properties: Optional collection of build-in properties.
53 * 54 *
54 * Check if the given @adev can be represented as a platform device and, if 55 * Check if the given @adev can be represented as a platform device and, if
55 * that's the case, create and register a platform device, populate its common 56 * that's the case, create and register a platform device, populate its common
@@ -57,7 +58,8 @@ static void acpi_platform_fill_resource(struct acpi_device *adev,
57 * 58 *
58 * Name of the platform device will be the same as @adev's. 59 * Name of the platform device will be the same as @adev's.
59 */ 60 */
60struct platform_device *acpi_create_platform_device(struct acpi_device *adev) 61struct platform_device *acpi_create_platform_device(struct acpi_device *adev,
62 struct property_entry *properties)
61{ 63{
62 struct platform_device *pdev = NULL; 64 struct platform_device *pdev = NULL;
63 struct platform_device_info pdevinfo; 65 struct platform_device_info pdevinfo;
@@ -106,6 +108,7 @@ struct platform_device *acpi_create_platform_device(struct acpi_device *adev)
106 pdevinfo.res = resources; 108 pdevinfo.res = resources;
107 pdevinfo.num_res = count; 109 pdevinfo.num_res = count;
108 pdevinfo.fwnode = acpi_fwnode_handle(adev); 110 pdevinfo.fwnode = acpi_fwnode_handle(adev);
111 pdevinfo.properties = properties;
109 112
110 if (acpi_dma_supported(adev)) 113 if (acpi_dma_supported(adev))
111 pdevinfo.dma_mask = DMA_BIT_MASK(32); 114 pdevinfo.dma_mask = DMA_BIT_MASK(32);
diff --git a/drivers/acpi/acpica/dsinit.c b/drivers/acpi/acpica/dsinit.c
index f1e6dcc7a827..54d48b90de2c 100644
--- a/drivers/acpi/acpica/dsinit.c
+++ b/drivers/acpi/acpica/dsinit.c
@@ -46,6 +46,7 @@
46#include "acdispat.h" 46#include "acdispat.h"
47#include "acnamesp.h" 47#include "acnamesp.h"
48#include "actables.h" 48#include "actables.h"
49#include "acinterp.h"
49 50
50#define _COMPONENT ACPI_DISPATCHER 51#define _COMPONENT ACPI_DISPATCHER
51ACPI_MODULE_NAME("dsinit") 52ACPI_MODULE_NAME("dsinit")
@@ -214,23 +215,17 @@ acpi_ds_initialize_objects(u32 table_index,
214 215
215 /* Walk entire namespace from the supplied root */ 216 /* Walk entire namespace from the supplied root */
216 217
217 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
218 if (ACPI_FAILURE(status)) {
219 return_ACPI_STATUS(status);
220 }
221
222 /* 218 /*
223 * We don't use acpi_walk_namespace since we do not want to acquire 219 * We don't use acpi_walk_namespace since we do not want to acquire
224 * the namespace reader lock. 220 * the namespace reader lock.
225 */ 221 */
226 status = 222 status =
227 acpi_ns_walk_namespace(ACPI_TYPE_ANY, start_node, ACPI_UINT32_MAX, 223 acpi_ns_walk_namespace(ACPI_TYPE_ANY, start_node, ACPI_UINT32_MAX,
228 ACPI_NS_WALK_UNLOCK, acpi_ds_init_one_object, 224 0, acpi_ds_init_one_object, NULL, &info,
229 NULL, &info, NULL); 225 NULL);
230 if (ACPI_FAILURE(status)) { 226 if (ACPI_FAILURE(status)) {
231 ACPI_EXCEPTION((AE_INFO, status, "During WalkNamespace")); 227 ACPI_EXCEPTION((AE_INFO, status, "During WalkNamespace"));
232 } 228 }
233 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
234 229
235 status = acpi_get_table_by_index(table_index, &table); 230 status = acpi_get_table_by_index(table_index, &table);
236 if (ACPI_FAILURE(status)) { 231 if (ACPI_FAILURE(status)) {
diff --git a/drivers/acpi/acpica/dsmethod.c b/drivers/acpi/acpica/dsmethod.c
index 32e9ddc0cf2b..2b3210f42a46 100644
--- a/drivers/acpi/acpica/dsmethod.c
+++ b/drivers/acpi/acpica/dsmethod.c
@@ -99,14 +99,11 @@ acpi_ds_auto_serialize_method(struct acpi_namespace_node *node,
99 "Method auto-serialization parse [%4.4s] %p\n", 99 "Method auto-serialization parse [%4.4s] %p\n",
100 acpi_ut_get_node_name(node), node)); 100 acpi_ut_get_node_name(node), node));
101 101
102 acpi_ex_enter_interpreter();
103
104 /* Create/Init a root op for the method parse tree */ 102 /* Create/Init a root op for the method parse tree */
105 103
106 op = acpi_ps_alloc_op(AML_METHOD_OP, obj_desc->method.aml_start); 104 op = acpi_ps_alloc_op(AML_METHOD_OP, obj_desc->method.aml_start);
107 if (!op) { 105 if (!op) {
108 status = AE_NO_MEMORY; 106 return_ACPI_STATUS(AE_NO_MEMORY);
109 goto unlock;
110 } 107 }
111 108
112 acpi_ps_set_name(op, node->name.integer); 109 acpi_ps_set_name(op, node->name.integer);
@@ -118,8 +115,7 @@ acpi_ds_auto_serialize_method(struct acpi_namespace_node *node,
118 acpi_ds_create_walk_state(node->owner_id, NULL, NULL, NULL); 115 acpi_ds_create_walk_state(node->owner_id, NULL, NULL, NULL);
119 if (!walk_state) { 116 if (!walk_state) {
120 acpi_ps_free_op(op); 117 acpi_ps_free_op(op);
121 status = AE_NO_MEMORY; 118 return_ACPI_STATUS(AE_NO_MEMORY);
122 goto unlock;
123 } 119 }
124 120
125 status = acpi_ds_init_aml_walk(walk_state, op, node, 121 status = acpi_ds_init_aml_walk(walk_state, op, node,
@@ -138,8 +134,6 @@ acpi_ds_auto_serialize_method(struct acpi_namespace_node *node,
138 status = acpi_ps_parse_aml(walk_state); 134 status = acpi_ps_parse_aml(walk_state);
139 135
140 acpi_ps_delete_parse_tree(op); 136 acpi_ps_delete_parse_tree(op);
141unlock:
142 acpi_ex_exit_interpreter();
143 return_ACPI_STATUS(status); 137 return_ACPI_STATUS(status);
144} 138}
145 139
@@ -731,26 +725,6 @@ acpi_ds_terminate_control_method(union acpi_operand_object *method_desc,
731 acpi_ds_method_data_delete_all(walk_state); 725 acpi_ds_method_data_delete_all(walk_state);
732 726
733 /* 727 /*
734 * If method is serialized, release the mutex and restore the
735 * current sync level for this thread
736 */
737 if (method_desc->method.mutex) {
738
739 /* Acquisition Depth handles recursive calls */
740
741 method_desc->method.mutex->mutex.acquisition_depth--;
742 if (!method_desc->method.mutex->mutex.acquisition_depth) {
743 walk_state->thread->current_sync_level =
744 method_desc->method.mutex->mutex.
745 original_sync_level;
746
747 acpi_os_release_mutex(method_desc->method.
748 mutex->mutex.os_mutex);
749 method_desc->method.mutex->mutex.thread_id = 0;
750 }
751 }
752
753 /*
754 * Delete any namespace objects created anywhere within the 728 * Delete any namespace objects created anywhere within the
755 * namespace by the execution of this method. Unless: 729 * namespace by the execution of this method. Unless:
756 * 1) This method is a module-level executable code method, in which 730 * 1) This method is a module-level executable code method, in which
@@ -786,6 +760,26 @@ acpi_ds_terminate_control_method(union acpi_operand_object *method_desc,
786 ~ACPI_METHOD_MODIFIED_NAMESPACE; 760 ~ACPI_METHOD_MODIFIED_NAMESPACE;
787 } 761 }
788 } 762 }
763
764 /*
765 * If method is serialized, release the mutex and restore the
766 * current sync level for this thread
767 */
768 if (method_desc->method.mutex) {
769
770 /* Acquisition Depth handles recursive calls */
771
772 method_desc->method.mutex->mutex.acquisition_depth--;
773 if (!method_desc->method.mutex->mutex.acquisition_depth) {
774 walk_state->thread->current_sync_level =
775 method_desc->method.mutex->mutex.
776 original_sync_level;
777
778 acpi_os_release_mutex(method_desc->method.
779 mutex->mutex.os_mutex);
780 method_desc->method.mutex->mutex.thread_id = 0;
781 }
782 }
789 } 783 }
790 784
791 /* Decrement the thread count on the method */ 785 /* Decrement the thread count on the method */
diff --git a/drivers/acpi/acpica/dswload2.c b/drivers/acpi/acpica/dswload2.c
index 028b22a3154e..e36218206bb0 100644
--- a/drivers/acpi/acpica/dswload2.c
+++ b/drivers/acpi/acpica/dswload2.c
@@ -607,11 +607,9 @@ acpi_status acpi_ds_load2_end_op(struct acpi_walk_state *walk_state)
607 } 607 }
608 } 608 }
609 609
610 acpi_ex_exit_interpreter();
611 status = 610 status =
612 acpi_ev_initialize_region 611 acpi_ev_initialize_region
613 (acpi_ns_get_attached_object(node), FALSE); 612 (acpi_ns_get_attached_object(node), FALSE);
614 acpi_ex_enter_interpreter();
615 613
616 if (ACPI_FAILURE(status)) { 614 if (ACPI_FAILURE(status)) {
617 /* 615 /*
diff --git a/drivers/acpi/acpica/evrgnini.c b/drivers/acpi/acpica/evrgnini.c
index 3843f1fc5dbb..75ddd160a716 100644
--- a/drivers/acpi/acpica/evrgnini.c
+++ b/drivers/acpi/acpica/evrgnini.c
@@ -45,6 +45,7 @@
45#include "accommon.h" 45#include "accommon.h"
46#include "acevents.h" 46#include "acevents.h"
47#include "acnamesp.h" 47#include "acnamesp.h"
48#include "acinterp.h"
48 49
49#define _COMPONENT ACPI_EVENTS 50#define _COMPONENT ACPI_EVENTS
50ACPI_MODULE_NAME("evrgnini") 51ACPI_MODULE_NAME("evrgnini")
@@ -597,9 +598,11 @@ acpi_ev_initialize_region(union acpi_operand_object *region_obj,
597 } 598 }
598 } 599 }
599 600
601 acpi_ex_exit_interpreter();
600 status = 602 status =
601 acpi_ev_execute_reg_method(region_obj, 603 acpi_ev_execute_reg_method(region_obj,
602 ACPI_REG_CONNECT); 604 ACPI_REG_CONNECT);
605 acpi_ex_enter_interpreter();
603 606
604 if (acpi_ns_locked) { 607 if (acpi_ns_locked) {
605 status = 608 status =
diff --git a/drivers/acpi/acpica/nsload.c b/drivers/acpi/acpica/nsload.c
index 334d3c5ba617..d1f20143bb11 100644
--- a/drivers/acpi/acpica/nsload.c
+++ b/drivers/acpi/acpica/nsload.c
@@ -137,7 +137,9 @@ unlock:
137 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 137 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
138 "**** Begin Table Object Initialization\n")); 138 "**** Begin Table Object Initialization\n"));
139 139
140 acpi_ex_enter_interpreter();
140 status = acpi_ds_initialize_objects(table_index, node); 141 status = acpi_ds_initialize_objects(table_index, node);
142 acpi_ex_exit_interpreter();
141 143
142 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 144 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
143 "**** Completed Table Object Initialization\n")); 145 "**** Completed Table Object Initialization\n"));
diff --git a/drivers/acpi/acpica/tbfadt.c b/drivers/acpi/acpica/tbfadt.c
index 046c4d0394ee..5fb838e592dc 100644
--- a/drivers/acpi/acpica/tbfadt.c
+++ b/drivers/acpi/acpica/tbfadt.c
@@ -480,19 +480,17 @@ static void acpi_tb_convert_fadt(void)
480 u32 i; 480 u32 i;
481 481
482 /* 482 /*
483 * For ACPI 1.0 FADTs (revision 1), ensure that reserved fields which 483 * For ACPI 1.0 FADTs (revision 1 or 2), ensure that reserved fields which
484 * should be zero are indeed zero. This will workaround BIOSs that 484 * should be zero are indeed zero. This will workaround BIOSs that
485 * inadvertently place values in these fields. 485 * inadvertently place values in these fields.
486 * 486 *
487 * The ACPI 1.0 reserved fields that will be zeroed are the bytes located 487 * The ACPI 1.0 reserved fields that will be zeroed are the bytes located
488 * at offset 45, 55, 95, and the word located at offset 109, 110. 488 * at offset 45, 55, 95, and the word located at offset 109, 110.
489 * 489 *
490 * Note: The FADT revision value is unreliable because of BIOS errors. 490 * Note: The FADT revision value is unreliable. Only the length can be
491 * The table length is instead used as the final word on the version. 491 * trusted.
492 *
493 * Note: FADT revision 3 is the ACPI 2.0 version of the FADT.
494 */ 492 */
495 if (acpi_gbl_FADT.header.length <= ACPI_FADT_V3_SIZE) { 493 if (acpi_gbl_FADT.header.length <= ACPI_FADT_V2_SIZE) {
496 acpi_gbl_FADT.preferred_profile = 0; 494 acpi_gbl_FADT.preferred_profile = 0;
497 acpi_gbl_FADT.pstate_control = 0; 495 acpi_gbl_FADT.pstate_control = 0;
498 acpi_gbl_FADT.cst_control = 0; 496 acpi_gbl_FADT.cst_control = 0;
diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
index f0a029e68d3e..0d099a24f776 100644
--- a/drivers/acpi/apei/ghes.c
+++ b/drivers/acpi/apei/ghes.c
@@ -662,7 +662,7 @@ static int ghes_proc(struct ghes *ghes)
662 ghes_do_proc(ghes, ghes->estatus); 662 ghes_do_proc(ghes, ghes->estatus);
663out: 663out:
664 ghes_clear_estatus(ghes); 664 ghes_clear_estatus(ghes);
665 return 0; 665 return rc;
666} 666}
667 667
668static void ghes_add_timer(struct ghes *ghes) 668static void ghes_add_timer(struct ghes *ghes)
diff --git a/drivers/acpi/dptf/int340x_thermal.c b/drivers/acpi/dptf/int340x_thermal.c
index 33505c651f62..86364097e236 100644
--- a/drivers/acpi/dptf/int340x_thermal.c
+++ b/drivers/acpi/dptf/int340x_thermal.c
@@ -34,11 +34,11 @@ static int int340x_thermal_handler_attach(struct acpi_device *adev,
34 const struct acpi_device_id *id) 34 const struct acpi_device_id *id)
35{ 35{
36 if (IS_ENABLED(CONFIG_INT340X_THERMAL)) 36 if (IS_ENABLED(CONFIG_INT340X_THERMAL))
37 acpi_create_platform_device(adev); 37 acpi_create_platform_device(adev, NULL);
38 /* Intel SoC DTS thermal driver needs INT3401 to set IRQ descriptor */ 38 /* Intel SoC DTS thermal driver needs INT3401 to set IRQ descriptor */
39 else if (IS_ENABLED(CONFIG_INTEL_SOC_DTS_THERMAL) && 39 else if (IS_ENABLED(CONFIG_INTEL_SOC_DTS_THERMAL) &&
40 id->driver_data == INT3401_DEVICE) 40 id->driver_data == INT3401_DEVICE)
41 acpi_create_platform_device(adev); 41 acpi_create_platform_device(adev, NULL);
42 return 1; 42 return 1;
43} 43}
44 44
diff --git a/drivers/acpi/nfit/core.c b/drivers/acpi/nfit/core.c
index 71a7d07c28c9..312c4b4dc363 100644
--- a/drivers/acpi/nfit/core.c
+++ b/drivers/acpi/nfit/core.c
@@ -94,7 +94,7 @@ static struct acpi_device *to_acpi_dev(struct acpi_nfit_desc *acpi_desc)
94 return to_acpi_device(acpi_desc->dev); 94 return to_acpi_device(acpi_desc->dev);
95} 95}
96 96
97static int xlat_status(void *buf, unsigned int cmd, u32 status) 97static int xlat_bus_status(void *buf, unsigned int cmd, u32 status)
98{ 98{
99 struct nd_cmd_clear_error *clear_err; 99 struct nd_cmd_clear_error *clear_err;
100 struct nd_cmd_ars_status *ars_status; 100 struct nd_cmd_ars_status *ars_status;
@@ -113,7 +113,7 @@ static int xlat_status(void *buf, unsigned int cmd, u32 status)
113 flags = ND_ARS_PERSISTENT | ND_ARS_VOLATILE; 113 flags = ND_ARS_PERSISTENT | ND_ARS_VOLATILE;
114 if ((status >> 16 & flags) == 0) 114 if ((status >> 16 & flags) == 0)
115 return -ENOTTY; 115 return -ENOTTY;
116 break; 116 return 0;
117 case ND_CMD_ARS_START: 117 case ND_CMD_ARS_START:
118 /* ARS is in progress */ 118 /* ARS is in progress */
119 if ((status & 0xffff) == NFIT_ARS_START_BUSY) 119 if ((status & 0xffff) == NFIT_ARS_START_BUSY)
@@ -122,7 +122,7 @@ static int xlat_status(void *buf, unsigned int cmd, u32 status)
122 /* Command failed */ 122 /* Command failed */
123 if (status & 0xffff) 123 if (status & 0xffff)
124 return -EIO; 124 return -EIO;
125 break; 125 return 0;
126 case ND_CMD_ARS_STATUS: 126 case ND_CMD_ARS_STATUS:
127 ars_status = buf; 127 ars_status = buf;
128 /* Command failed */ 128 /* Command failed */
@@ -146,7 +146,8 @@ static int xlat_status(void *buf, unsigned int cmd, u32 status)
146 * then just continue with the returned results. 146 * then just continue with the returned results.
147 */ 147 */
148 if (status == NFIT_ARS_STATUS_INTR) { 148 if (status == NFIT_ARS_STATUS_INTR) {
149 if (ars_status->flags & NFIT_ARS_F_OVERFLOW) 149 if (ars_status->out_length >= 40 && (ars_status->flags
150 & NFIT_ARS_F_OVERFLOW))
150 return -ENOSPC; 151 return -ENOSPC;
151 return 0; 152 return 0;
152 } 153 }
@@ -154,7 +155,7 @@ static int xlat_status(void *buf, unsigned int cmd, u32 status)
154 /* Unknown status */ 155 /* Unknown status */
155 if (status >> 16) 156 if (status >> 16)
156 return -EIO; 157 return -EIO;
157 break; 158 return 0;
158 case ND_CMD_CLEAR_ERROR: 159 case ND_CMD_CLEAR_ERROR:
159 clear_err = buf; 160 clear_err = buf;
160 if (status & 0xffff) 161 if (status & 0xffff)
@@ -163,7 +164,7 @@ static int xlat_status(void *buf, unsigned int cmd, u32 status)
163 return -EIO; 164 return -EIO;
164 if (clear_err->length > clear_err->cleared) 165 if (clear_err->length > clear_err->cleared)
165 return clear_err->cleared; 166 return clear_err->cleared;
166 break; 167 return 0;
167 default: 168 default:
168 break; 169 break;
169 } 170 }
@@ -174,9 +175,18 @@ static int xlat_status(void *buf, unsigned int cmd, u32 status)
174 return 0; 175 return 0;
175} 176}
176 177
177static int acpi_nfit_ctl(struct nvdimm_bus_descriptor *nd_desc, 178static int xlat_status(struct nvdimm *nvdimm, void *buf, unsigned int cmd,
178 struct nvdimm *nvdimm, unsigned int cmd, void *buf, 179 u32 status)
179 unsigned int buf_len, int *cmd_rc) 180{
181 if (!nvdimm)
182 return xlat_bus_status(buf, cmd, status);
183 if (status)
184 return -EIO;
185 return 0;
186}
187
188int acpi_nfit_ctl(struct nvdimm_bus_descriptor *nd_desc, struct nvdimm *nvdimm,
189 unsigned int cmd, void *buf, unsigned int buf_len, int *cmd_rc)
180{ 190{
181 struct acpi_nfit_desc *acpi_desc = to_acpi_nfit_desc(nd_desc); 191 struct acpi_nfit_desc *acpi_desc = to_acpi_nfit_desc(nd_desc);
182 union acpi_object in_obj, in_buf, *out_obj; 192 union acpi_object in_obj, in_buf, *out_obj;
@@ -298,7 +308,8 @@ static int acpi_nfit_ctl(struct nvdimm_bus_descriptor *nd_desc,
298 308
299 for (i = 0, offset = 0; i < desc->out_num; i++) { 309 for (i = 0, offset = 0; i < desc->out_num; i++) {
300 u32 out_size = nd_cmd_out_size(nvdimm, cmd, desc, i, buf, 310 u32 out_size = nd_cmd_out_size(nvdimm, cmd, desc, i, buf,
301 (u32 *) out_obj->buffer.pointer); 311 (u32 *) out_obj->buffer.pointer,
312 out_obj->buffer.length - offset);
302 313
303 if (offset + out_size > out_obj->buffer.length) { 314 if (offset + out_size > out_obj->buffer.length) {
304 dev_dbg(dev, "%s:%s output object underflow cmd: %s field: %d\n", 315 dev_dbg(dev, "%s:%s output object underflow cmd: %s field: %d\n",
@@ -333,7 +344,8 @@ static int acpi_nfit_ctl(struct nvdimm_bus_descriptor *nd_desc,
333 */ 344 */
334 rc = buf_len - offset - in_buf.buffer.length; 345 rc = buf_len - offset - in_buf.buffer.length;
335 if (cmd_rc) 346 if (cmd_rc)
336 *cmd_rc = xlat_status(buf, cmd, fw_status); 347 *cmd_rc = xlat_status(nvdimm, buf, cmd,
348 fw_status);
337 } else { 349 } else {
338 dev_err(dev, "%s:%s underrun cmd: %s buf_len: %d out_len: %d\n", 350 dev_err(dev, "%s:%s underrun cmd: %s buf_len: %d out_len: %d\n",
339 __func__, dimm_name, cmd_name, buf_len, 351 __func__, dimm_name, cmd_name, buf_len,
@@ -343,7 +355,7 @@ static int acpi_nfit_ctl(struct nvdimm_bus_descriptor *nd_desc,
343 } else { 355 } else {
344 rc = 0; 356 rc = 0;
345 if (cmd_rc) 357 if (cmd_rc)
346 *cmd_rc = xlat_status(buf, cmd, fw_status); 358 *cmd_rc = xlat_status(nvdimm, buf, cmd, fw_status);
347 } 359 }
348 360
349 out: 361 out:
@@ -351,6 +363,7 @@ static int acpi_nfit_ctl(struct nvdimm_bus_descriptor *nd_desc,
351 363
352 return rc; 364 return rc;
353} 365}
366EXPORT_SYMBOL_GPL(acpi_nfit_ctl);
354 367
355static const char *spa_type_name(u16 type) 368static const char *spa_type_name(u16 type)
356{ 369{
@@ -2001,19 +2014,32 @@ static int ars_get_status(struct acpi_nfit_desc *acpi_desc)
2001 return cmd_rc; 2014 return cmd_rc;
2002} 2015}
2003 2016
2004static int ars_status_process_records(struct nvdimm_bus *nvdimm_bus, 2017static int ars_status_process_records(struct acpi_nfit_desc *acpi_desc,
2005 struct nd_cmd_ars_status *ars_status) 2018 struct nd_cmd_ars_status *ars_status)
2006{ 2019{
2020 struct nvdimm_bus *nvdimm_bus = acpi_desc->nvdimm_bus;
2007 int rc; 2021 int rc;
2008 u32 i; 2022 u32 i;
2009 2023
2024 /*
2025 * First record starts at 44 byte offset from the start of the
2026 * payload.
2027 */
2028 if (ars_status->out_length < 44)
2029 return 0;
2010 for (i = 0; i < ars_status->num_records; i++) { 2030 for (i = 0; i < ars_status->num_records; i++) {
2031 /* only process full records */
2032 if (ars_status->out_length
2033 < 44 + sizeof(struct nd_ars_record) * (i + 1))
2034 break;
2011 rc = nvdimm_bus_add_poison(nvdimm_bus, 2035 rc = nvdimm_bus_add_poison(nvdimm_bus,
2012 ars_status->records[i].err_address, 2036 ars_status->records[i].err_address,
2013 ars_status->records[i].length); 2037 ars_status->records[i].length);
2014 if (rc) 2038 if (rc)
2015 return rc; 2039 return rc;
2016 } 2040 }
2041 if (i < ars_status->num_records)
2042 dev_warn(acpi_desc->dev, "detected truncated ars results\n");
2017 2043
2018 return 0; 2044 return 0;
2019} 2045}
@@ -2266,8 +2292,7 @@ static int acpi_nfit_query_poison(struct acpi_nfit_desc *acpi_desc,
2266 if (rc < 0 && rc != -ENOSPC) 2292 if (rc < 0 && rc != -ENOSPC)
2267 return rc; 2293 return rc;
2268 2294
2269 if (ars_status_process_records(acpi_desc->nvdimm_bus, 2295 if (ars_status_process_records(acpi_desc, acpi_desc->ars_status))
2270 acpi_desc->ars_status))
2271 return -ENOMEM; 2296 return -ENOMEM;
2272 2297
2273 return 0; 2298 return 0;
diff --git a/drivers/acpi/nfit/nfit.h b/drivers/acpi/nfit/nfit.h
index 14296f5267c8..fc29c2e9832e 100644
--- a/drivers/acpi/nfit/nfit.h
+++ b/drivers/acpi/nfit/nfit.h
@@ -240,5 +240,7 @@ const u8 *to_nfit_uuid(enum nfit_uuids id);
240int acpi_nfit_init(struct acpi_nfit_desc *acpi_desc, void *nfit, acpi_size sz); 240int acpi_nfit_init(struct acpi_nfit_desc *acpi_desc, void *nfit, acpi_size sz);
241void __acpi_nfit_notify(struct device *dev, acpi_handle handle, u32 event); 241void __acpi_nfit_notify(struct device *dev, acpi_handle handle, u32 event);
242void __acpi_nvdimm_notify(struct device *dev, u32 event); 242void __acpi_nvdimm_notify(struct device *dev, u32 event);
243int acpi_nfit_ctl(struct nvdimm_bus_descriptor *nd_desc, struct nvdimm *nvdimm,
244 unsigned int cmd, void *buf, unsigned int buf_len, int *cmd_rc);
243void acpi_nfit_desc_init(struct acpi_nfit_desc *acpi_desc, struct device *dev); 245void acpi_nfit_desc_init(struct acpi_nfit_desc *acpi_desc, struct device *dev);
244#endif /* __NFIT_H__ */ 246#endif /* __NFIT_H__ */
diff --git a/drivers/acpi/pci_link.c b/drivers/acpi/pci_link.c
index c983bf733ad3..bc3d914dfc3e 100644
--- a/drivers/acpi/pci_link.c
+++ b/drivers/acpi/pci_link.c
@@ -87,6 +87,7 @@ struct acpi_pci_link {
87 87
88static LIST_HEAD(acpi_link_list); 88static LIST_HEAD(acpi_link_list);
89static DEFINE_MUTEX(acpi_link_lock); 89static DEFINE_MUTEX(acpi_link_lock);
90static int sci_irq = -1, sci_penalty;
90 91
91/* -------------------------------------------------------------------------- 92/* --------------------------------------------------------------------------
92 PCI Link Device Management 93 PCI Link Device Management
@@ -496,25 +497,13 @@ static int acpi_irq_get_penalty(int irq)
496{ 497{
497 int penalty = 0; 498 int penalty = 0;
498 499
499 /* 500 if (irq == sci_irq)
500 * Penalize IRQ used by ACPI SCI. If ACPI SCI pin attributes conflict 501 penalty += sci_penalty;
501 * with PCI IRQ attributes, mark ACPI SCI as ISA_ALWAYS so it won't be
502 * use for PCI IRQs.
503 */
504 if (irq == acpi_gbl_FADT.sci_interrupt) {
505 u32 type = irq_get_trigger_type(irq) & IRQ_TYPE_SENSE_MASK;
506
507 if (type != IRQ_TYPE_LEVEL_LOW)
508 penalty += PIRQ_PENALTY_ISA_ALWAYS;
509 else
510 penalty += PIRQ_PENALTY_PCI_USING;
511 }
512 502
513 if (irq < ACPI_MAX_ISA_IRQS) 503 if (irq < ACPI_MAX_ISA_IRQS)
514 return penalty + acpi_isa_irq_penalty[irq]; 504 return penalty + acpi_isa_irq_penalty[irq];
515 505
516 penalty += acpi_irq_pci_sharing_penalty(irq); 506 return penalty + acpi_irq_pci_sharing_penalty(irq);
517 return penalty;
518} 507}
519 508
520int __init acpi_irq_penalty_init(void) 509int __init acpi_irq_penalty_init(void)
@@ -619,6 +608,10 @@ static int acpi_pci_link_allocate(struct acpi_pci_link *link)
619 acpi_device_bid(link->device)); 608 acpi_device_bid(link->device));
620 return -ENODEV; 609 return -ENODEV;
621 } else { 610 } else {
611 if (link->irq.active < ACPI_MAX_ISA_IRQS)
612 acpi_isa_irq_penalty[link->irq.active] +=
613 PIRQ_PENALTY_PCI_USING;
614
622 printk(KERN_WARNING PREFIX "%s [%s] enabled at IRQ %d\n", 615 printk(KERN_WARNING PREFIX "%s [%s] enabled at IRQ %d\n",
623 acpi_device_name(link->device), 616 acpi_device_name(link->device),
624 acpi_device_bid(link->device), link->irq.active); 617 acpi_device_bid(link->device), link->irq.active);
@@ -849,7 +842,7 @@ static int __init acpi_irq_penalty_update(char *str, int used)
849 continue; 842 continue;
850 843
851 if (used) 844 if (used)
852 new_penalty = acpi_irq_get_penalty(irq) + 845 new_penalty = acpi_isa_irq_penalty[irq] +
853 PIRQ_PENALTY_ISA_USED; 846 PIRQ_PENALTY_ISA_USED;
854 else 847 else
855 new_penalty = 0; 848 new_penalty = 0;
@@ -871,7 +864,7 @@ static int __init acpi_irq_penalty_update(char *str, int used)
871void acpi_penalize_isa_irq(int irq, int active) 864void acpi_penalize_isa_irq(int irq, int active)
872{ 865{
873 if ((irq >= 0) && (irq < ARRAY_SIZE(acpi_isa_irq_penalty))) 866 if ((irq >= 0) && (irq < ARRAY_SIZE(acpi_isa_irq_penalty)))
874 acpi_isa_irq_penalty[irq] = acpi_irq_get_penalty(irq) + 867 acpi_isa_irq_penalty[irq] +=
875 (active ? PIRQ_PENALTY_ISA_USED : PIRQ_PENALTY_PCI_USING); 868 (active ? PIRQ_PENALTY_ISA_USED : PIRQ_PENALTY_PCI_USING);
876} 869}
877 870
@@ -881,6 +874,17 @@ bool acpi_isa_irq_available(int irq)
881 acpi_irq_get_penalty(irq) < PIRQ_PENALTY_ISA_ALWAYS); 874 acpi_irq_get_penalty(irq) < PIRQ_PENALTY_ISA_ALWAYS);
882} 875}
883 876
877void acpi_penalize_sci_irq(int irq, int trigger, int polarity)
878{
879 sci_irq = irq;
880
881 if (trigger == ACPI_MADT_TRIGGER_LEVEL &&
882 polarity == ACPI_MADT_POLARITY_ACTIVE_LOW)
883 sci_penalty = PIRQ_PENALTY_PCI_USING;
884 else
885 sci_penalty = PIRQ_PENALTY_ISA_ALWAYS;
886}
887
884/* 888/*
885 * Over-ride default table to reserve additional IRQs for use by ISA 889 * Over-ride default table to reserve additional IRQs for use by ISA
886 * e.g. acpi_irq_isa=5 890 * e.g. acpi_irq_isa=5
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index 035ac646d8db..3d1856f1f4d0 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -1734,7 +1734,7 @@ static void acpi_default_enumeration(struct acpi_device *device)
1734 &is_spi_i2c_slave); 1734 &is_spi_i2c_slave);
1735 acpi_dev_free_resource_list(&resource_list); 1735 acpi_dev_free_resource_list(&resource_list);
1736 if (!is_spi_i2c_slave) { 1736 if (!is_spi_i2c_slave) {
1737 acpi_create_platform_device(device); 1737 acpi_create_platform_device(device, NULL);
1738 acpi_device_set_enumerated(device); 1738 acpi_device_set_enumerated(device);
1739 } else { 1739 } else {
1740 blocking_notifier_call_chain(&acpi_reconfig_chain, 1740 blocking_notifier_call_chain(&acpi_reconfig_chain,
diff --git a/drivers/acpi/sleep.c b/drivers/acpi/sleep.c
index deb0ff78eba8..54abb26b7366 100644
--- a/drivers/acpi/sleep.c
+++ b/drivers/acpi/sleep.c
@@ -47,32 +47,15 @@ static void acpi_sleep_tts_switch(u32 acpi_state)
47 } 47 }
48} 48}
49 49
50static void acpi_sleep_pts_switch(u32 acpi_state) 50static int tts_notify_reboot(struct notifier_block *this,
51{
52 acpi_status status;
53
54 status = acpi_execute_simple_method(NULL, "\\_PTS", acpi_state);
55 if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
56 /*
57 * OS can't evaluate the _PTS object correctly. Some warning
58 * message will be printed. But it won't break anything.
59 */
60 printk(KERN_NOTICE "Failure in evaluating _PTS object\n");
61 }
62}
63
64static int sleep_notify_reboot(struct notifier_block *this,
65 unsigned long code, void *x) 51 unsigned long code, void *x)
66{ 52{
67 acpi_sleep_tts_switch(ACPI_STATE_S5); 53 acpi_sleep_tts_switch(ACPI_STATE_S5);
68
69 acpi_sleep_pts_switch(ACPI_STATE_S5);
70
71 return NOTIFY_DONE; 54 return NOTIFY_DONE;
72} 55}
73 56
74static struct notifier_block sleep_notifier = { 57static struct notifier_block tts_notifier = {
75 .notifier_call = sleep_notify_reboot, 58 .notifier_call = tts_notify_reboot,
76 .next = NULL, 59 .next = NULL,
77 .priority = 0, 60 .priority = 0,
78}; 61};
@@ -916,9 +899,9 @@ int __init acpi_sleep_init(void)
916 pr_info(PREFIX "(supports%s)\n", supported); 899 pr_info(PREFIX "(supports%s)\n", supported);
917 900
918 /* 901 /*
919 * Register the sleep_notifier to reboot notifier list so that the _TTS 902 * Register the tts_notifier to reboot notifier list so that the _TTS
920 * and _PTS object can also be evaluated when the system enters S5. 903 * object can also be evaluated when the system enters S5.
921 */ 904 */
922 register_reboot_notifier(&sleep_notifier); 905 register_reboot_notifier(&tts_notifier);
923 return 0; 906 return 0;
924} 907}
diff --git a/drivers/android/binder.c b/drivers/android/binder.c
index 562af94bec35..3c71b982bf2a 100644
--- a/drivers/android/binder.c
+++ b/drivers/android/binder.c
@@ -1002,7 +1002,7 @@ static int binder_dec_node(struct binder_node *node, int strong, int internal)
1002 1002
1003 1003
1004static struct binder_ref *binder_get_ref(struct binder_proc *proc, 1004static struct binder_ref *binder_get_ref(struct binder_proc *proc,
1005 uint32_t desc) 1005 u32 desc, bool need_strong_ref)
1006{ 1006{
1007 struct rb_node *n = proc->refs_by_desc.rb_node; 1007 struct rb_node *n = proc->refs_by_desc.rb_node;
1008 struct binder_ref *ref; 1008 struct binder_ref *ref;
@@ -1010,12 +1010,16 @@ static struct binder_ref *binder_get_ref(struct binder_proc *proc,
1010 while (n) { 1010 while (n) {
1011 ref = rb_entry(n, struct binder_ref, rb_node_desc); 1011 ref = rb_entry(n, struct binder_ref, rb_node_desc);
1012 1012
1013 if (desc < ref->desc) 1013 if (desc < ref->desc) {
1014 n = n->rb_left; 1014 n = n->rb_left;
1015 else if (desc > ref->desc) 1015 } else if (desc > ref->desc) {
1016 n = n->rb_right; 1016 n = n->rb_right;
1017 else 1017 } else if (need_strong_ref && !ref->strong) {
1018 binder_user_error("tried to use weak ref as strong ref\n");
1019 return NULL;
1020 } else {
1018 return ref; 1021 return ref;
1022 }
1019 } 1023 }
1020 return NULL; 1024 return NULL;
1021} 1025}
@@ -1285,7 +1289,10 @@ static void binder_transaction_buffer_release(struct binder_proc *proc,
1285 } break; 1289 } break;
1286 case BINDER_TYPE_HANDLE: 1290 case BINDER_TYPE_HANDLE:
1287 case BINDER_TYPE_WEAK_HANDLE: { 1291 case BINDER_TYPE_WEAK_HANDLE: {
1288 struct binder_ref *ref = binder_get_ref(proc, fp->handle); 1292 struct binder_ref *ref;
1293
1294 ref = binder_get_ref(proc, fp->handle,
1295 fp->type == BINDER_TYPE_HANDLE);
1289 1296
1290 if (ref == NULL) { 1297 if (ref == NULL) {
1291 pr_err("transaction release %d bad handle %d\n", 1298 pr_err("transaction release %d bad handle %d\n",
@@ -1380,7 +1387,7 @@ static void binder_transaction(struct binder_proc *proc,
1380 if (tr->target.handle) { 1387 if (tr->target.handle) {
1381 struct binder_ref *ref; 1388 struct binder_ref *ref;
1382 1389
1383 ref = binder_get_ref(proc, tr->target.handle); 1390 ref = binder_get_ref(proc, tr->target.handle, true);
1384 if (ref == NULL) { 1391 if (ref == NULL) {
1385 binder_user_error("%d:%d got transaction to invalid handle\n", 1392 binder_user_error("%d:%d got transaction to invalid handle\n",
1386 proc->pid, thread->pid); 1393 proc->pid, thread->pid);
@@ -1577,7 +1584,9 @@ static void binder_transaction(struct binder_proc *proc,
1577 fp->type = BINDER_TYPE_HANDLE; 1584 fp->type = BINDER_TYPE_HANDLE;
1578 else 1585 else
1579 fp->type = BINDER_TYPE_WEAK_HANDLE; 1586 fp->type = BINDER_TYPE_WEAK_HANDLE;
1587 fp->binder = 0;
1580 fp->handle = ref->desc; 1588 fp->handle = ref->desc;
1589 fp->cookie = 0;
1581 binder_inc_ref(ref, fp->type == BINDER_TYPE_HANDLE, 1590 binder_inc_ref(ref, fp->type == BINDER_TYPE_HANDLE,
1582 &thread->todo); 1591 &thread->todo);
1583 1592
@@ -1589,7 +1598,10 @@ static void binder_transaction(struct binder_proc *proc,
1589 } break; 1598 } break;
1590 case BINDER_TYPE_HANDLE: 1599 case BINDER_TYPE_HANDLE:
1591 case BINDER_TYPE_WEAK_HANDLE: { 1600 case BINDER_TYPE_WEAK_HANDLE: {
1592 struct binder_ref *ref = binder_get_ref(proc, fp->handle); 1601 struct binder_ref *ref;
1602
1603 ref = binder_get_ref(proc, fp->handle,
1604 fp->type == BINDER_TYPE_HANDLE);
1593 1605
1594 if (ref == NULL) { 1606 if (ref == NULL) {
1595 binder_user_error("%d:%d got transaction with invalid handle, %d\n", 1607 binder_user_error("%d:%d got transaction with invalid handle, %d\n",
@@ -1624,7 +1636,9 @@ static void binder_transaction(struct binder_proc *proc,
1624 return_error = BR_FAILED_REPLY; 1636 return_error = BR_FAILED_REPLY;
1625 goto err_binder_get_ref_for_node_failed; 1637 goto err_binder_get_ref_for_node_failed;
1626 } 1638 }
1639 fp->binder = 0;
1627 fp->handle = new_ref->desc; 1640 fp->handle = new_ref->desc;
1641 fp->cookie = 0;
1628 binder_inc_ref(new_ref, fp->type == BINDER_TYPE_HANDLE, NULL); 1642 binder_inc_ref(new_ref, fp->type == BINDER_TYPE_HANDLE, NULL);
1629 trace_binder_transaction_ref_to_ref(t, ref, 1643 trace_binder_transaction_ref_to_ref(t, ref,
1630 new_ref); 1644 new_ref);
@@ -1678,6 +1692,7 @@ static void binder_transaction(struct binder_proc *proc,
1678 binder_debug(BINDER_DEBUG_TRANSACTION, 1692 binder_debug(BINDER_DEBUG_TRANSACTION,
1679 " fd %d -> %d\n", fp->handle, target_fd); 1693 " fd %d -> %d\n", fp->handle, target_fd);
1680 /* TODO: fput? */ 1694 /* TODO: fput? */
1695 fp->binder = 0;
1681 fp->handle = target_fd; 1696 fp->handle = target_fd;
1682 } break; 1697 } break;
1683 1698
@@ -1800,7 +1815,9 @@ static int binder_thread_write(struct binder_proc *proc,
1800 ref->desc); 1815 ref->desc);
1801 } 1816 }
1802 } else 1817 } else
1803 ref = binder_get_ref(proc, target); 1818 ref = binder_get_ref(proc, target,
1819 cmd == BC_ACQUIRE ||
1820 cmd == BC_RELEASE);
1804 if (ref == NULL) { 1821 if (ref == NULL) {
1805 binder_user_error("%d:%d refcount change on invalid ref %d\n", 1822 binder_user_error("%d:%d refcount change on invalid ref %d\n",
1806 proc->pid, thread->pid, target); 1823 proc->pid, thread->pid, target);
@@ -1996,7 +2013,7 @@ static int binder_thread_write(struct binder_proc *proc,
1996 if (get_user(cookie, (binder_uintptr_t __user *)ptr)) 2013 if (get_user(cookie, (binder_uintptr_t __user *)ptr))
1997 return -EFAULT; 2014 return -EFAULT;
1998 ptr += sizeof(binder_uintptr_t); 2015 ptr += sizeof(binder_uintptr_t);
1999 ref = binder_get_ref(proc, target); 2016 ref = binder_get_ref(proc, target, false);
2000 if (ref == NULL) { 2017 if (ref == NULL) {
2001 binder_user_error("%d:%d %s invalid ref %d\n", 2018 binder_user_error("%d:%d %s invalid ref %d\n",
2002 proc->pid, thread->pid, 2019 proc->pid, thread->pid,
diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
index ba5f11cebee2..74f4c662f776 100644
--- a/drivers/ata/ahci.c
+++ b/drivers/ata/ahci.c
@@ -1418,31 +1418,27 @@ static int ahci_init_msi(struct pci_dev *pdev, unsigned int n_ports,
1418 * Message mode could be enforced. In this case assume that advantage 1418 * Message mode could be enforced. In this case assume that advantage
1419 * of multipe MSIs is negated and use single MSI mode instead. 1419 * of multipe MSIs is negated and use single MSI mode instead.
1420 */ 1420 */
1421 nvec = pci_alloc_irq_vectors(pdev, n_ports, INT_MAX, 1421 if (n_ports > 1) {
1422 PCI_IRQ_MSIX | PCI_IRQ_MSI); 1422 nvec = pci_alloc_irq_vectors(pdev, n_ports, INT_MAX,
1423 if (nvec > 0) { 1423 PCI_IRQ_MSIX | PCI_IRQ_MSI);
1424 if (!(readl(hpriv->mmio + HOST_CTL) & HOST_MRSM)) { 1424 if (nvec > 0) {
1425 hpriv->get_irq_vector = ahci_get_irq_vector; 1425 if (!(readl(hpriv->mmio + HOST_CTL) & HOST_MRSM)) {
1426 hpriv->flags |= AHCI_HFLAG_MULTI_MSI; 1426 hpriv->get_irq_vector = ahci_get_irq_vector;
1427 return nvec; 1427 hpriv->flags |= AHCI_HFLAG_MULTI_MSI;
1428 } 1428 return nvec;
1429 }
1429 1430
1430 /* 1431 /*
1431 * Fallback to single MSI mode if the controller enforced MRSM 1432 * Fallback to single MSI mode if the controller
1432 * mode. 1433 * enforced MRSM mode.
1433 */ 1434 */
1434 printk(KERN_INFO "ahci: MRSM is on, fallback to single MSI\n"); 1435 printk(KERN_INFO
1435 pci_free_irq_vectors(pdev); 1436 "ahci: MRSM is on, fallback to single MSI\n");
1437 pci_free_irq_vectors(pdev);
1438 }
1436 } 1439 }
1437 1440
1438 /* 1441 /*
1439 * -ENOSPC indicated we don't have enough vectors. Don't bother trying
1440 * a single vectors for any other error:
1441 */
1442 if (nvec < 0 && nvec != -ENOSPC)
1443 return nvec;
1444
1445 /*
1446 * If the host is not capable of supporting per-port vectors, fall 1442 * If the host is not capable of supporting per-port vectors, fall
1447 * back to single MSI before finally attempting single MSI-X. 1443 * back to single MSI before finally attempting single MSI-X.
1448 */ 1444 */
@@ -1617,7 +1613,7 @@ static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
1617 /* legacy intx interrupts */ 1613 /* legacy intx interrupts */
1618 pci_intx(pdev, 1); 1614 pci_intx(pdev, 1);
1619 } 1615 }
1620 hpriv->irq = pdev->irq; 1616 hpriv->irq = pci_irq_vector(pdev, 0);
1621 1617
1622 if (!(hpriv->cap & HOST_CAP_SSS) || ahci_ignore_sss) 1618 if (!(hpriv->cap & HOST_CAP_SSS) || ahci_ignore_sss)
1623 host->flags |= ATA_HOST_PARALLEL_SCAN; 1619 host->flags |= ATA_HOST_PARALLEL_SCAN;
diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index 9cceb4a875a5..8e575fbdf31d 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -1088,7 +1088,7 @@ static void ata_gen_passthru_sense(struct ata_queued_cmd *qc)
1088 desc[1] = tf->command; /* status */ 1088 desc[1] = tf->command; /* status */
1089 desc[2] = tf->device; 1089 desc[2] = tf->device;
1090 desc[3] = tf->nsect; 1090 desc[3] = tf->nsect;
1091 desc[0] = 0; 1091 desc[7] = 0;
1092 if (tf->flags & ATA_TFLAG_LBA48) { 1092 if (tf->flags & ATA_TFLAG_LBA48) {
1093 desc[8] |= 0x80; 1093 desc[8] |= 0x80;
1094 if (tf->hob_nsect) 1094 if (tf->hob_nsect)
@@ -1159,6 +1159,7 @@ static void ata_scsi_sdev_config(struct scsi_device *sdev)
1159{ 1159{
1160 sdev->use_10_for_rw = 1; 1160 sdev->use_10_for_rw = 1;
1161 sdev->use_10_for_ms = 1; 1161 sdev->use_10_for_ms = 1;
1162 sdev->no_write_same = 1;
1162 1163
1163 /* Schedule policy is determined by ->qc_defer() callback and 1164 /* Schedule policy is determined by ->qc_defer() callback and
1164 * it needs to see every deferred qc. Set dev_blocked to 1 to 1165 * it needs to see every deferred qc. Set dev_blocked to 1 to
diff --git a/drivers/ata/sata_mv.c b/drivers/ata/sata_mv.c
index efc48bf89d51..823e938c9a78 100644
--- a/drivers/ata/sata_mv.c
+++ b/drivers/ata/sata_mv.c
@@ -4090,7 +4090,20 @@ static int mv_platform_probe(struct platform_device *pdev)
4090 4090
4091 /* allocate host */ 4091 /* allocate host */
4092 if (pdev->dev.of_node) { 4092 if (pdev->dev.of_node) {
4093 of_property_read_u32(pdev->dev.of_node, "nr-ports", &n_ports); 4093 rc = of_property_read_u32(pdev->dev.of_node, "nr-ports",
4094 &n_ports);
4095 if (rc) {
4096 dev_err(&pdev->dev,
4097 "error parsing nr-ports property: %d\n", rc);
4098 return rc;
4099 }
4100
4101 if (n_ports <= 0) {
4102 dev_err(&pdev->dev, "nr-ports must be positive: %d\n",
4103 n_ports);
4104 return -EINVAL;
4105 }
4106
4094 irq = irq_of_parse_and_map(pdev->dev.of_node, 0); 4107 irq = irq_of_parse_and_map(pdev->dev.of_node, 0);
4095 } else { 4108 } else {
4096 mv_platform_data = dev_get_platdata(&pdev->dev); 4109 mv_platform_data = dev_get_platdata(&pdev->dev);
diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
index f2aaf9e32a36..40c2d561417b 100644
--- a/drivers/atm/eni.c
+++ b/drivers/atm/eni.c
@@ -1727,7 +1727,7 @@ static int eni_do_init(struct atm_dev *dev)
1727 printk("\n"); 1727 printk("\n");
1728 printk(KERN_ERR DEV_LABEL "(itf %d): can't set up page " 1728 printk(KERN_ERR DEV_LABEL "(itf %d): can't set up page "
1729 "mapping\n",dev->number); 1729 "mapping\n",dev->number);
1730 return error; 1730 return -ENOMEM;
1731 } 1731 }
1732 eni_dev->ioaddr = base; 1732 eni_dev->ioaddr = base;
1733 eni_dev->base_diff = real_base - (unsigned long) base; 1733 eni_dev->base_diff = real_base - (unsigned long) base;
diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
index ce43ae3e87b3..445505d9ea07 100644
--- a/drivers/atm/lanai.c
+++ b/drivers/atm/lanai.c
@@ -2143,6 +2143,7 @@ static int lanai_dev_open(struct atm_dev *atmdev)
2143 lanai->base = (bus_addr_t) ioremap(raw_base, LANAI_MAPPING_SIZE); 2143 lanai->base = (bus_addr_t) ioremap(raw_base, LANAI_MAPPING_SIZE);
2144 if (lanai->base == NULL) { 2144 if (lanai->base == NULL) {
2145 printk(KERN_ERR DEV_LABEL ": couldn't remap I/O space\n"); 2145 printk(KERN_ERR DEV_LABEL ": couldn't remap I/O space\n");
2146 result = -ENOMEM;
2146 goto error_pci; 2147 goto error_pci;
2147 } 2148 }
2148 /* 3.3: Reset lanai and PHY */ 2149 /* 3.3: Reset lanai and PHY */
diff --git a/drivers/base/Kconfig b/drivers/base/Kconfig
index fdf44cac08e6..d02e7c0f5bfd 100644
--- a/drivers/base/Kconfig
+++ b/drivers/base/Kconfig
@@ -213,14 +213,16 @@ config DEBUG_DEVRES
213 If you are unsure about this, Say N here. 213 If you are unsure about this, Say N here.
214 214
215config DEBUG_TEST_DRIVER_REMOVE 215config DEBUG_TEST_DRIVER_REMOVE
216 bool "Test driver remove calls during probe" 216 bool "Test driver remove calls during probe (UNSTABLE)"
217 depends on DEBUG_KERNEL 217 depends on DEBUG_KERNEL
218 help 218 help
219 Say Y here if you want the Driver core to test driver remove functions 219 Say Y here if you want the Driver core to test driver remove functions
220 by calling probe, remove, probe. This tests the remove path without 220 by calling probe, remove, probe. This tests the remove path without
221 having to unbind the driver or unload the driver module. 221 having to unbind the driver or unload the driver module.
222 222
223 If you are unsure about this, say N here. 223 This option is expected to find errors and may render your system
224 unusable. You should say N here unless you are explicitly looking to
225 test this functionality.
224 226
225config SYS_HYPERVISOR 227config SYS_HYPERVISOR
226 bool 228 bool
diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index d22a7260f42b..d76cd97a98b6 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -324,7 +324,8 @@ static int really_probe(struct device *dev, struct device_driver *drv)
324{ 324{
325 int ret = -EPROBE_DEFER; 325 int ret = -EPROBE_DEFER;
326 int local_trigger_count = atomic_read(&deferred_trigger_count); 326 int local_trigger_count = atomic_read(&deferred_trigger_count);
327 bool test_remove = IS_ENABLED(CONFIG_DEBUG_TEST_DRIVER_REMOVE); 327 bool test_remove = IS_ENABLED(CONFIG_DEBUG_TEST_DRIVER_REMOVE) &&
328 !drv->suppress_bind_attrs;
328 329
329 if (defer_all_probes) { 330 if (defer_all_probes) {
330 /* 331 /*
@@ -383,7 +384,7 @@ re_probe:
383 if (test_remove) { 384 if (test_remove) {
384 test_remove = false; 385 test_remove = false;
385 386
386 if (dev->bus && dev->bus->remove) 387 if (dev->bus->remove)
387 dev->bus->remove(dev); 388 dev->bus->remove(dev);
388 else if (drv->remove) 389 else if (drv->remove)
389 drv->remove(dev); 390 drv->remove(dev);
diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
index e44944f4be77..2932a5bd892f 100644
--- a/drivers/base/power/main.c
+++ b/drivers/base/power/main.c
@@ -1027,6 +1027,8 @@ static int __device_suspend_noirq(struct device *dev, pm_message_t state, bool a
1027 TRACE_DEVICE(dev); 1027 TRACE_DEVICE(dev);
1028 TRACE_SUSPEND(0); 1028 TRACE_SUSPEND(0);
1029 1029
1030 dpm_wait_for_children(dev, async);
1031
1030 if (async_error) 1032 if (async_error)
1031 goto Complete; 1033 goto Complete;
1032 1034
@@ -1038,8 +1040,6 @@ static int __device_suspend_noirq(struct device *dev, pm_message_t state, bool a
1038 if (dev->power.syscore || dev->power.direct_complete) 1040 if (dev->power.syscore || dev->power.direct_complete)
1039 goto Complete; 1041 goto Complete;
1040 1042
1041 dpm_wait_for_children(dev, async);
1042
1043 if (dev->pm_domain) { 1043 if (dev->pm_domain) {
1044 info = "noirq power domain "; 1044 info = "noirq power domain ";
1045 callback = pm_noirq_op(&dev->pm_domain->ops, state); 1045 callback = pm_noirq_op(&dev->pm_domain->ops, state);
@@ -1174,6 +1174,8 @@ static int __device_suspend_late(struct device *dev, pm_message_t state, bool as
1174 1174
1175 __pm_runtime_disable(dev, false); 1175 __pm_runtime_disable(dev, false);
1176 1176
1177 dpm_wait_for_children(dev, async);
1178
1177 if (async_error) 1179 if (async_error)
1178 goto Complete; 1180 goto Complete;
1179 1181
@@ -1185,8 +1187,6 @@ static int __device_suspend_late(struct device *dev, pm_message_t state, bool as
1185 if (dev->power.syscore || dev->power.direct_complete) 1187 if (dev->power.syscore || dev->power.direct_complete)
1186 goto Complete; 1188 goto Complete;
1187 1189
1188 dpm_wait_for_children(dev, async);
1189
1190 if (dev->pm_domain) { 1190 if (dev->pm_domain) {
1191 info = "late power domain "; 1191 info = "late power domain ";
1192 callback = pm_late_early_op(&dev->pm_domain->ops, state); 1192 callback = pm_late_early_op(&dev->pm_domain->ops, state);
diff --git a/drivers/block/DAC960.c b/drivers/block/DAC960.c
index 811e11c82f32..0809cda93cc0 100644
--- a/drivers/block/DAC960.c
+++ b/drivers/block/DAC960.c
@@ -2954,7 +2954,7 @@ DAC960_DetectController(struct pci_dev *PCI_Device,
2954 case DAC960_PD_Controller: 2954 case DAC960_PD_Controller:
2955 if (!request_region(Controller->IO_Address, 0x80, 2955 if (!request_region(Controller->IO_Address, 0x80,
2956 Controller->FullModelName)) { 2956 Controller->FullModelName)) {
2957 DAC960_Error("IO port 0x%d busy for Controller at\n", 2957 DAC960_Error("IO port 0x%lx busy for Controller at\n",
2958 Controller, Controller->IO_Address); 2958 Controller, Controller->IO_Address);
2959 goto Failure; 2959 goto Failure;
2960 } 2960 }
@@ -2990,7 +2990,7 @@ DAC960_DetectController(struct pci_dev *PCI_Device,
2990 case DAC960_P_Controller: 2990 case DAC960_P_Controller:
2991 if (!request_region(Controller->IO_Address, 0x80, 2991 if (!request_region(Controller->IO_Address, 0x80,
2992 Controller->FullModelName)){ 2992 Controller->FullModelName)){
2993 DAC960_Error("IO port 0x%d busy for Controller at\n", 2993 DAC960_Error("IO port 0x%lx busy for Controller at\n",
2994 Controller, Controller->IO_Address); 2994 Controller, Controller->IO_Address);
2995 goto Failure; 2995 goto Failure;
2996 } 2996 }
diff --git a/drivers/block/aoe/aoecmd.c b/drivers/block/aoe/aoecmd.c
index ab19adb07a12..3c606c09fd5a 100644
--- a/drivers/block/aoe/aoecmd.c
+++ b/drivers/block/aoe/aoecmd.c
@@ -853,45 +853,6 @@ rqbiocnt(struct request *r)
853 return n; 853 return n;
854} 854}
855 855
856/* This can be removed if we are certain that no users of the block
857 * layer will ever use zero-count pages in bios. Otherwise we have to
858 * protect against the put_page sometimes done by the network layer.
859 *
860 * See http://oss.sgi.com/archives/xfs/2007-01/msg00594.html for
861 * discussion.
862 *
863 * We cannot use get_page in the workaround, because it insists on a
864 * positive page count as a precondition. So we use _refcount directly.
865 */
866static void
867bio_pageinc(struct bio *bio)
868{
869 struct bio_vec bv;
870 struct page *page;
871 struct bvec_iter iter;
872
873 bio_for_each_segment(bv, bio, iter) {
874 /* Non-zero page count for non-head members of
875 * compound pages is no longer allowed by the kernel.
876 */
877 page = compound_head(bv.bv_page);
878 page_ref_inc(page);
879 }
880}
881
882static void
883bio_pagedec(struct bio *bio)
884{
885 struct page *page;
886 struct bio_vec bv;
887 struct bvec_iter iter;
888
889 bio_for_each_segment(bv, bio, iter) {
890 page = compound_head(bv.bv_page);
891 page_ref_dec(page);
892 }
893}
894
895static void 856static void
896bufinit(struct buf *buf, struct request *rq, struct bio *bio) 857bufinit(struct buf *buf, struct request *rq, struct bio *bio)
897{ 858{
@@ -899,7 +860,6 @@ bufinit(struct buf *buf, struct request *rq, struct bio *bio)
899 buf->rq = rq; 860 buf->rq = rq;
900 buf->bio = bio; 861 buf->bio = bio;
901 buf->iter = bio->bi_iter; 862 buf->iter = bio->bi_iter;
902 bio_pageinc(bio);
903} 863}
904 864
905static struct buf * 865static struct buf *
@@ -1127,7 +1087,6 @@ aoe_end_buf(struct aoedev *d, struct buf *buf)
1127 if (buf == d->ip.buf) 1087 if (buf == d->ip.buf)
1128 d->ip.buf = NULL; 1088 d->ip.buf = NULL;
1129 rq = buf->rq; 1089 rq = buf->rq;
1130 bio_pagedec(buf->bio);
1131 mempool_free(buf, d->bufpool); 1090 mempool_free(buf, d->bufpool);
1132 n = (unsigned long) rq->special; 1091 n = (unsigned long) rq->special;
1133 rq->special = (void *) --n; 1092 rq->special = (void *) --n;
diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
index 100be556e613..83482721bc01 100644
--- a/drivers/block/drbd/drbd_main.c
+++ b/drivers/block/drbd/drbd_main.c
@@ -1871,7 +1871,7 @@ int drbd_send(struct drbd_connection *connection, struct socket *sock,
1871 drbd_update_congested(connection); 1871 drbd_update_congested(connection);
1872 } 1872 }
1873 do { 1873 do {
1874 rv = kernel_sendmsg(sock, &msg, &iov, 1, size); 1874 rv = kernel_sendmsg(sock, &msg, &iov, 1, iov.iov_len);
1875 if (rv == -EAGAIN) { 1875 if (rv == -EAGAIN) {
1876 if (we_should_drop_the_connection(connection, sock)) 1876 if (we_should_drop_the_connection(connection, sock))
1877 break; 1877 break;
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index ba405b55329f..7a1048755914 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -164,7 +164,7 @@ static void sock_shutdown(struct nbd_device *nbd)
164 spin_lock(&nbd->sock_lock); 164 spin_lock(&nbd->sock_lock);
165 165
166 if (!nbd->sock) { 166 if (!nbd->sock) {
167 spin_unlock_irq(&nbd->sock_lock); 167 spin_unlock(&nbd->sock_lock);
168 return; 168 return;
169 } 169 }
170 170
@@ -599,7 +599,7 @@ static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *nbd,
599 return -EINVAL; 599 return -EINVAL;
600 600
601 sreq = blk_mq_alloc_request(bdev_get_queue(bdev), WRITE, 0); 601 sreq = blk_mq_alloc_request(bdev_get_queue(bdev), WRITE, 0);
602 if (!sreq) 602 if (IS_ERR(sreq))
603 return -ENOMEM; 603 return -ENOMEM;
604 604
605 mutex_unlock(&nbd->tx_lock); 605 mutex_unlock(&nbd->tx_lock);
diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index abb71628ab61..7b274ff4632c 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -415,15 +415,15 @@ struct rbd_device {
415}; 415};
416 416
417/* 417/*
418 * Flag bits for rbd_dev->flags. If atomicity is required, 418 * Flag bits for rbd_dev->flags:
419 * rbd_dev->lock is used to protect access. 419 * - REMOVING (which is coupled with rbd_dev->open_count) is protected
420 * 420 * by rbd_dev->lock
421 * Currently, only the "removing" flag (which is coupled with the 421 * - BLACKLISTED is protected by rbd_dev->lock_rwsem
422 * "open_count" field) requires atomic access.
423 */ 422 */
424enum rbd_dev_flags { 423enum rbd_dev_flags {
425 RBD_DEV_FLAG_EXISTS, /* mapped snapshot has not been deleted */ 424 RBD_DEV_FLAG_EXISTS, /* mapped snapshot has not been deleted */
426 RBD_DEV_FLAG_REMOVING, /* this mapping is being removed */ 425 RBD_DEV_FLAG_REMOVING, /* this mapping is being removed */
426 RBD_DEV_FLAG_BLACKLISTED, /* our ceph_client is blacklisted */
427}; 427};
428 428
429static DEFINE_MUTEX(client_mutex); /* Serialize client creation */ 429static DEFINE_MUTEX(client_mutex); /* Serialize client creation */
@@ -3926,6 +3926,7 @@ static void rbd_reregister_watch(struct work_struct *work)
3926 struct rbd_device *rbd_dev = container_of(to_delayed_work(work), 3926 struct rbd_device *rbd_dev = container_of(to_delayed_work(work),
3927 struct rbd_device, watch_dwork); 3927 struct rbd_device, watch_dwork);
3928 bool was_lock_owner = false; 3928 bool was_lock_owner = false;
3929 bool need_to_wake = false;
3929 int ret; 3930 int ret;
3930 3931
3931 dout("%s rbd_dev %p\n", __func__, rbd_dev); 3932 dout("%s rbd_dev %p\n", __func__, rbd_dev);
@@ -3935,19 +3936,27 @@ static void rbd_reregister_watch(struct work_struct *work)
3935 was_lock_owner = rbd_release_lock(rbd_dev); 3936 was_lock_owner = rbd_release_lock(rbd_dev);
3936 3937
3937 mutex_lock(&rbd_dev->watch_mutex); 3938 mutex_lock(&rbd_dev->watch_mutex);
3938 if (rbd_dev->watch_state != RBD_WATCH_STATE_ERROR) 3939 if (rbd_dev->watch_state != RBD_WATCH_STATE_ERROR) {
3939 goto fail_unlock; 3940 mutex_unlock(&rbd_dev->watch_mutex);
3941 goto out;
3942 }
3940 3943
3941 ret = __rbd_register_watch(rbd_dev); 3944 ret = __rbd_register_watch(rbd_dev);
3942 if (ret) { 3945 if (ret) {
3943 rbd_warn(rbd_dev, "failed to reregister watch: %d", ret); 3946 rbd_warn(rbd_dev, "failed to reregister watch: %d", ret);
3944 if (ret != -EBLACKLISTED) 3947 if (ret == -EBLACKLISTED || ret == -ENOENT) {
3948 set_bit(RBD_DEV_FLAG_BLACKLISTED, &rbd_dev->flags);
3949 need_to_wake = true;
3950 } else {
3945 queue_delayed_work(rbd_dev->task_wq, 3951 queue_delayed_work(rbd_dev->task_wq,
3946 &rbd_dev->watch_dwork, 3952 &rbd_dev->watch_dwork,
3947 RBD_RETRY_DELAY); 3953 RBD_RETRY_DELAY);
3948 goto fail_unlock; 3954 }
3955 mutex_unlock(&rbd_dev->watch_mutex);
3956 goto out;
3949 } 3957 }
3950 3958
3959 need_to_wake = true;
3951 rbd_dev->watch_state = RBD_WATCH_STATE_REGISTERED; 3960 rbd_dev->watch_state = RBD_WATCH_STATE_REGISTERED;
3952 rbd_dev->watch_cookie = rbd_dev->watch_handle->linger_id; 3961 rbd_dev->watch_cookie = rbd_dev->watch_handle->linger_id;
3953 mutex_unlock(&rbd_dev->watch_mutex); 3962 mutex_unlock(&rbd_dev->watch_mutex);
@@ -3963,13 +3972,10 @@ static void rbd_reregister_watch(struct work_struct *work)
3963 ret); 3972 ret);
3964 } 3973 }
3965 3974
3975out:
3966 up_write(&rbd_dev->lock_rwsem); 3976 up_write(&rbd_dev->lock_rwsem);
3967 wake_requests(rbd_dev, true); 3977 if (need_to_wake)
3968 return; 3978 wake_requests(rbd_dev, true);
3969
3970fail_unlock:
3971 mutex_unlock(&rbd_dev->watch_mutex);
3972 up_write(&rbd_dev->lock_rwsem);
3973} 3979}
3974 3980
3975/* 3981/*
@@ -4074,7 +4080,9 @@ static void rbd_wait_state_locked(struct rbd_device *rbd_dev)
4074 up_read(&rbd_dev->lock_rwsem); 4080 up_read(&rbd_dev->lock_rwsem);
4075 schedule(); 4081 schedule();
4076 down_read(&rbd_dev->lock_rwsem); 4082 down_read(&rbd_dev->lock_rwsem);
4077 } while (rbd_dev->lock_state != RBD_LOCK_STATE_LOCKED); 4083 } while (rbd_dev->lock_state != RBD_LOCK_STATE_LOCKED &&
4084 !test_bit(RBD_DEV_FLAG_BLACKLISTED, &rbd_dev->flags));
4085
4078 finish_wait(&rbd_dev->lock_waitq, &wait); 4086 finish_wait(&rbd_dev->lock_waitq, &wait);
4079} 4087}
4080 4088
@@ -4166,8 +4174,16 @@ static void rbd_queue_workfn(struct work_struct *work)
4166 4174
4167 if (must_be_locked) { 4175 if (must_be_locked) {
4168 down_read(&rbd_dev->lock_rwsem); 4176 down_read(&rbd_dev->lock_rwsem);
4169 if (rbd_dev->lock_state != RBD_LOCK_STATE_LOCKED) 4177 if (rbd_dev->lock_state != RBD_LOCK_STATE_LOCKED &&
4178 !test_bit(RBD_DEV_FLAG_BLACKLISTED, &rbd_dev->flags))
4170 rbd_wait_state_locked(rbd_dev); 4179 rbd_wait_state_locked(rbd_dev);
4180
4181 WARN_ON((rbd_dev->lock_state == RBD_LOCK_STATE_LOCKED) ^
4182 !test_bit(RBD_DEV_FLAG_BLACKLISTED, &rbd_dev->flags));
4183 if (test_bit(RBD_DEV_FLAG_BLACKLISTED, &rbd_dev->flags)) {
4184 result = -EBLACKLISTED;
4185 goto err_unlock;
4186 }
4171 } 4187 }
4172 4188
4173 img_request = rbd_img_request_create(rbd_dev, offset, length, op_type, 4189 img_request = rbd_img_request_create(rbd_dev, offset, length, op_type,
diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index 2dc5c96c186a..5545a679abd8 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -376,7 +376,7 @@ static void virtblk_config_changed(struct virtio_device *vdev)
376 376
377static int init_vq(struct virtio_blk *vblk) 377static int init_vq(struct virtio_blk *vblk)
378{ 378{
379 int err = 0; 379 int err;
380 int i; 380 int i;
381 vq_callback_t **callbacks; 381 vq_callback_t **callbacks;
382 const char **names; 382 const char **names;
@@ -390,13 +390,13 @@ static int init_vq(struct virtio_blk *vblk)
390 if (err) 390 if (err)
391 num_vqs = 1; 391 num_vqs = 1;
392 392
393 vblk->vqs = kmalloc(sizeof(*vblk->vqs) * num_vqs, GFP_KERNEL); 393 vblk->vqs = kmalloc_array(num_vqs, sizeof(*vblk->vqs), GFP_KERNEL);
394 if (!vblk->vqs) 394 if (!vblk->vqs)
395 return -ENOMEM; 395 return -ENOMEM;
396 396
397 names = kmalloc(sizeof(*names) * num_vqs, GFP_KERNEL); 397 names = kmalloc_array(num_vqs, sizeof(*names), GFP_KERNEL);
398 callbacks = kmalloc(sizeof(*callbacks) * num_vqs, GFP_KERNEL); 398 callbacks = kmalloc_array(num_vqs, sizeof(*callbacks), GFP_KERNEL);
399 vqs = kmalloc(sizeof(*vqs) * num_vqs, GFP_KERNEL); 399 vqs = kmalloc_array(num_vqs, sizeof(*vqs), GFP_KERNEL);
400 if (!names || !callbacks || !vqs) { 400 if (!names || !callbacks || !vqs) {
401 err = -ENOMEM; 401 err = -ENOMEM;
402 goto out; 402 goto out;
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index 04365b17ee67..5497f7fc44d0 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -1403,7 +1403,8 @@ static ssize_t hot_remove_store(struct class *class,
1403 zram = idr_find(&zram_index_idr, dev_id); 1403 zram = idr_find(&zram_index_idr, dev_id);
1404 if (zram) { 1404 if (zram) {
1405 ret = zram_remove(zram); 1405 ret = zram_remove(zram);
1406 idr_remove(&zram_index_idr, dev_id); 1406 if (!ret)
1407 idr_remove(&zram_index_idr, dev_id);
1407 } else { 1408 } else {
1408 ret = -ENODEV; 1409 ret = -ENODEV;
1409 } 1410 }
@@ -1412,8 +1413,14 @@ static ssize_t hot_remove_store(struct class *class,
1412 return ret ? ret : count; 1413 return ret ? ret : count;
1413} 1414}
1414 1415
1416/*
1417 * NOTE: hot_add attribute is not the usual read-only sysfs attribute. In a
1418 * sense that reading from this file does alter the state of your system -- it
1419 * creates a new un-initialized zram device and returns back this device's
1420 * device_id (or an error code if it fails to create a new device).
1421 */
1415static struct class_attribute zram_control_class_attrs[] = { 1422static struct class_attribute zram_control_class_attrs[] = {
1416 __ATTR_RO(hot_add), 1423 __ATTR(hot_add, 0400, hot_add_show, NULL),
1417 __ATTR_WO(hot_remove), 1424 __ATTR_WO(hot_remove),
1418 __ATTR_NULL, 1425 __ATTR_NULL,
1419}; 1426};
diff --git a/drivers/bluetooth/btwilink.c b/drivers/bluetooth/btwilink.c
index ef51c9c864c5..b6bb58c41df5 100644
--- a/drivers/bluetooth/btwilink.c
+++ b/drivers/bluetooth/btwilink.c
@@ -310,7 +310,7 @@ static int bt_ti_probe(struct platform_device *pdev)
310 BT_DBG("HCI device registered (hdev %p)", hdev); 310 BT_DBG("HCI device registered (hdev %p)", hdev);
311 311
312 dev_set_drvdata(&pdev->dev, hst); 312 dev_set_drvdata(&pdev->dev, hst);
313 return err; 313 return 0;
314} 314}
315 315
316static int bt_ti_remove(struct platform_device *pdev) 316static int bt_ti_remove(struct platform_device *pdev)
diff --git a/drivers/bluetooth/hci_bcm.c b/drivers/bluetooth/hci_bcm.c
index 5ccb90ef0146..8f6c23c20c52 100644
--- a/drivers/bluetooth/hci_bcm.c
+++ b/drivers/bluetooth/hci_bcm.c
@@ -643,6 +643,14 @@ static const struct dmi_system_id bcm_wrong_irq_dmi_table[] = {
643 }, 643 },
644 .driver_data = &acpi_active_low, 644 .driver_data = &acpi_active_low,
645 }, 645 },
646 { /* Handle ThinkPad 8 tablets with BCM2E55 chipset ACPI ID */
647 .ident = "Lenovo ThinkPad 8",
648 .matches = {
649 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "LENOVO"),
650 DMI_EXACT_MATCH(DMI_PRODUCT_VERSION, "ThinkPad 8"),
651 },
652 .driver_data = &acpi_active_low,
653 },
646 { } 654 { }
647}; 655};
648 656
diff --git a/drivers/bus/Kconfig b/drivers/bus/Kconfig
index 7010dcac9328..78751057164a 100644
--- a/drivers/bus/Kconfig
+++ b/drivers/bus/Kconfig
@@ -111,6 +111,7 @@ config OMAP_OCP2SCP
111config QCOM_EBI2 111config QCOM_EBI2
112 bool "Qualcomm External Bus Interface 2 (EBI2)" 112 bool "Qualcomm External Bus Interface 2 (EBI2)"
113 depends on HAS_IOMEM 113 depends on HAS_IOMEM
114 depends on ARCH_QCOM || COMPILE_TEST
114 help 115 help
115 Say y here to enable support for the Qualcomm External Bus 116 Say y here to enable support for the Qualcomm External Bus
116 Interface 2, which can be used to connect things like NAND Flash, 117 Interface 2, which can be used to connect things like NAND Flash,
diff --git a/drivers/char/hw_random/core.c b/drivers/char/hw_random/core.c
index 482794526e8c..d2d2c89de5b4 100644
--- a/drivers/char/hw_random/core.c
+++ b/drivers/char/hw_random/core.c
@@ -84,14 +84,14 @@ static size_t rng_buffer_size(void)
84 84
85static void add_early_randomness(struct hwrng *rng) 85static void add_early_randomness(struct hwrng *rng)
86{ 86{
87 unsigned char bytes[16];
88 int bytes_read; 87 int bytes_read;
88 size_t size = min_t(size_t, 16, rng_buffer_size());
89 89
90 mutex_lock(&reading_mutex); 90 mutex_lock(&reading_mutex);
91 bytes_read = rng_get_data(rng, bytes, sizeof(bytes), 1); 91 bytes_read = rng_get_data(rng, rng_buffer, size, 1);
92 mutex_unlock(&reading_mutex); 92 mutex_unlock(&reading_mutex);
93 if (bytes_read > 0) 93 if (bytes_read > 0)
94 add_device_randomness(bytes, bytes_read); 94 add_device_randomness(rng_buffer, bytes_read);
95} 95}
96 96
97static inline void cleanup_rng(struct kref *kref) 97static inline void cleanup_rng(struct kref *kref)
diff --git a/drivers/char/ipmi/Kconfig b/drivers/char/ipmi/Kconfig
index 5a9350b1069a..7f816655cbbf 100644
--- a/drivers/char/ipmi/Kconfig
+++ b/drivers/char/ipmi/Kconfig
@@ -76,3 +76,11 @@ config IPMI_POWEROFF
76 the IPMI management controller is capable of this. 76 the IPMI management controller is capable of this.
77 77
78endif # IPMI_HANDLER 78endif # IPMI_HANDLER
79
80config ASPEED_BT_IPMI_BMC
81 depends on ARCH_ASPEED
82 tristate "BT IPMI bmc driver"
83 help
84 Provides a driver for the BT (Block Transfer) IPMI interface
85 found on Aspeed SOCs (AST2400 and AST2500). The driver
86 implements the BMC side of the BT interface.
diff --git a/drivers/char/ipmi/Makefile b/drivers/char/ipmi/Makefile
index f3ffde1f5f1f..0d98cd91def1 100644
--- a/drivers/char/ipmi/Makefile
+++ b/drivers/char/ipmi/Makefile
@@ -11,3 +11,4 @@ obj-$(CONFIG_IPMI_SSIF) += ipmi_ssif.o
11obj-$(CONFIG_IPMI_POWERNV) += ipmi_powernv.o 11obj-$(CONFIG_IPMI_POWERNV) += ipmi_powernv.o
12obj-$(CONFIG_IPMI_WATCHDOG) += ipmi_watchdog.o 12obj-$(CONFIG_IPMI_WATCHDOG) += ipmi_watchdog.o
13obj-$(CONFIG_IPMI_POWEROFF) += ipmi_poweroff.o 13obj-$(CONFIG_IPMI_POWEROFF) += ipmi_poweroff.o
14obj-$(CONFIG_ASPEED_BT_IPMI_BMC) += bt-bmc.o
diff --git a/drivers/char/ipmi/bt-bmc.c b/drivers/char/ipmi/bt-bmc.c
new file mode 100644
index 000000000000..fc9e8891eae3
--- /dev/null
+++ b/drivers/char/ipmi/bt-bmc.c
@@ -0,0 +1,505 @@
1/*
2 * Copyright (c) 2015-2016, IBM Corporation.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
8 */
9
10#include <linux/atomic.h>
11#include <linux/bt-bmc.h>
12#include <linux/errno.h>
13#include <linux/interrupt.h>
14#include <linux/io.h>
15#include <linux/miscdevice.h>
16#include <linux/module.h>
17#include <linux/platform_device.h>
18#include <linux/poll.h>
19#include <linux/sched.h>
20#include <linux/timer.h>
21
22/*
23 * This is a BMC device used to communicate to the host
24 */
25#define DEVICE_NAME "ipmi-bt-host"
26
27#define BT_IO_BASE 0xe4
28#define BT_IRQ 10
29
30#define BT_CR0 0x0
31#define BT_CR0_IO_BASE 16
32#define BT_CR0_IRQ 12
33#define BT_CR0_EN_CLR_SLV_RDP 0x8
34#define BT_CR0_EN_CLR_SLV_WRP 0x4
35#define BT_CR0_ENABLE_IBT 0x1
36#define BT_CR1 0x4
37#define BT_CR1_IRQ_H2B 0x01
38#define BT_CR1_IRQ_HBUSY 0x40
39#define BT_CR2 0x8
40#define BT_CR2_IRQ_H2B 0x01
41#define BT_CR2_IRQ_HBUSY 0x40
42#define BT_CR3 0xc
43#define BT_CTRL 0x10
44#define BT_CTRL_B_BUSY 0x80
45#define BT_CTRL_H_BUSY 0x40
46#define BT_CTRL_OEM0 0x20
47#define BT_CTRL_SMS_ATN 0x10
48#define BT_CTRL_B2H_ATN 0x08
49#define BT_CTRL_H2B_ATN 0x04
50#define BT_CTRL_CLR_RD_PTR 0x02
51#define BT_CTRL_CLR_WR_PTR 0x01
52#define BT_BMC2HOST 0x14
53#define BT_INTMASK 0x18
54#define BT_INTMASK_B2H_IRQEN 0x01
55#define BT_INTMASK_B2H_IRQ 0x02
56#define BT_INTMASK_BMC_HWRST 0x80
57
58#define BT_BMC_BUFFER_SIZE 256
59
60struct bt_bmc {
61 struct device dev;
62 struct miscdevice miscdev;
63 void __iomem *base;
64 int irq;
65 wait_queue_head_t queue;
66 struct timer_list poll_timer;
67 struct mutex mutex;
68};
69
70static atomic_t open_count = ATOMIC_INIT(0);
71
72static u8 bt_inb(struct bt_bmc *bt_bmc, int reg)
73{
74 return ioread8(bt_bmc->base + reg);
75}
76
77static void bt_outb(struct bt_bmc *bt_bmc, u8 data, int reg)
78{
79 iowrite8(data, bt_bmc->base + reg);
80}
81
82static void clr_rd_ptr(struct bt_bmc *bt_bmc)
83{
84 bt_outb(bt_bmc, BT_CTRL_CLR_RD_PTR, BT_CTRL);
85}
86
87static void clr_wr_ptr(struct bt_bmc *bt_bmc)
88{
89 bt_outb(bt_bmc, BT_CTRL_CLR_WR_PTR, BT_CTRL);
90}
91
92static void clr_h2b_atn(struct bt_bmc *bt_bmc)
93{
94 bt_outb(bt_bmc, BT_CTRL_H2B_ATN, BT_CTRL);
95}
96
97static void set_b_busy(struct bt_bmc *bt_bmc)
98{
99 if (!(bt_inb(bt_bmc, BT_CTRL) & BT_CTRL_B_BUSY))
100 bt_outb(bt_bmc, BT_CTRL_B_BUSY, BT_CTRL);
101}
102
103static void clr_b_busy(struct bt_bmc *bt_bmc)
104{
105 if (bt_inb(bt_bmc, BT_CTRL) & BT_CTRL_B_BUSY)
106 bt_outb(bt_bmc, BT_CTRL_B_BUSY, BT_CTRL);
107}
108
109static void set_b2h_atn(struct bt_bmc *bt_bmc)
110{
111 bt_outb(bt_bmc, BT_CTRL_B2H_ATN, BT_CTRL);
112}
113
114static u8 bt_read(struct bt_bmc *bt_bmc)
115{
116 return bt_inb(bt_bmc, BT_BMC2HOST);
117}
118
119static ssize_t bt_readn(struct bt_bmc *bt_bmc, u8 *buf, size_t n)
120{
121 int i;
122
123 for (i = 0; i < n; i++)
124 buf[i] = bt_read(bt_bmc);
125 return n;
126}
127
128static void bt_write(struct bt_bmc *bt_bmc, u8 c)
129{
130 bt_outb(bt_bmc, c, BT_BMC2HOST);
131}
132
133static ssize_t bt_writen(struct bt_bmc *bt_bmc, u8 *buf, size_t n)
134{
135 int i;
136
137 for (i = 0; i < n; i++)
138 bt_write(bt_bmc, buf[i]);
139 return n;
140}
141
142static void set_sms_atn(struct bt_bmc *bt_bmc)
143{
144 bt_outb(bt_bmc, BT_CTRL_SMS_ATN, BT_CTRL);
145}
146
147static struct bt_bmc *file_bt_bmc(struct file *file)
148{
149 return container_of(file->private_data, struct bt_bmc, miscdev);
150}
151
152static int bt_bmc_open(struct inode *inode, struct file *file)
153{
154 struct bt_bmc *bt_bmc = file_bt_bmc(file);
155
156 if (atomic_inc_return(&open_count) == 1) {
157 clr_b_busy(bt_bmc);
158 return 0;
159 }
160
161 atomic_dec(&open_count);
162 return -EBUSY;
163}
164
165/*
166 * The BT (Block Transfer) interface means that entire messages are
167 * buffered by the host before a notification is sent to the BMC that
168 * there is data to be read. The first byte is the length and the
169 * message data follows. The read operation just tries to capture the
170 * whole before returning it to userspace.
171 *
172 * BT Message format :
173 *
174 * Byte 1 Byte 2 Byte 3 Byte 4 Byte 5:N
175 * Length NetFn/LUN Seq Cmd Data
176 *
177 */
178static ssize_t bt_bmc_read(struct file *file, char __user *buf,
179 size_t count, loff_t *ppos)
180{
181 struct bt_bmc *bt_bmc = file_bt_bmc(file);
182 u8 len;
183 int len_byte = 1;
184 u8 kbuffer[BT_BMC_BUFFER_SIZE];
185 ssize_t ret = 0;
186 ssize_t nread;
187
188 if (!access_ok(VERIFY_WRITE, buf, count))
189 return -EFAULT;
190
191 WARN_ON(*ppos);
192
193 if (wait_event_interruptible(bt_bmc->queue,
194 bt_inb(bt_bmc, BT_CTRL) & BT_CTRL_H2B_ATN))
195 return -ERESTARTSYS;
196
197 mutex_lock(&bt_bmc->mutex);
198
199 if (unlikely(!(bt_inb(bt_bmc, BT_CTRL) & BT_CTRL_H2B_ATN))) {
200 ret = -EIO;
201 goto out_unlock;
202 }
203
204 set_b_busy(bt_bmc);
205 clr_h2b_atn(bt_bmc);
206 clr_rd_ptr(bt_bmc);
207
208 /*
209 * The BT frames start with the message length, which does not
210 * include the length byte.
211 */
212 kbuffer[0] = bt_read(bt_bmc);
213 len = kbuffer[0];
214
215 /* We pass the length back to userspace as well */
216 if (len + 1 > count)
217 len = count - 1;
218
219 while (len) {
220 nread = min_t(ssize_t, len, sizeof(kbuffer) - len_byte);
221
222 bt_readn(bt_bmc, kbuffer + len_byte, nread);
223
224 if (copy_to_user(buf, kbuffer, nread + len_byte)) {
225 ret = -EFAULT;
226 break;
227 }
228 len -= nread;
229 buf += nread + len_byte;
230 ret += nread + len_byte;
231 len_byte = 0;
232 }
233
234 clr_b_busy(bt_bmc);
235
236out_unlock:
237 mutex_unlock(&bt_bmc->mutex);
238 return ret;
239}
240
241/*
242 * BT Message response format :
243 *
244 * Byte 1 Byte 2 Byte 3 Byte 4 Byte 5 Byte 6:N
245 * Length NetFn/LUN Seq Cmd Code Data
246 */
247static ssize_t bt_bmc_write(struct file *file, const char __user *buf,
248 size_t count, loff_t *ppos)
249{
250 struct bt_bmc *bt_bmc = file_bt_bmc(file);
251 u8 kbuffer[BT_BMC_BUFFER_SIZE];
252 ssize_t ret = 0;
253 ssize_t nwritten;
254
255 /*
256 * send a minimum response size
257 */
258 if (count < 5)
259 return -EINVAL;
260
261 if (!access_ok(VERIFY_READ, buf, count))
262 return -EFAULT;
263
264 WARN_ON(*ppos);
265
266 /*
267 * There's no interrupt for clearing bmc busy so we have to
268 * poll
269 */
270 if (wait_event_interruptible(bt_bmc->queue,
271 !(bt_inb(bt_bmc, BT_CTRL) &
272 (BT_CTRL_H_BUSY | BT_CTRL_B2H_ATN))))
273 return -ERESTARTSYS;
274
275 mutex_lock(&bt_bmc->mutex);
276
277 if (unlikely(bt_inb(bt_bmc, BT_CTRL) &
278 (BT_CTRL_H_BUSY | BT_CTRL_B2H_ATN))) {
279 ret = -EIO;
280 goto out_unlock;
281 }
282
283 clr_wr_ptr(bt_bmc);
284
285 while (count) {
286 nwritten = min_t(ssize_t, count, sizeof(kbuffer));
287 if (copy_from_user(&kbuffer, buf, nwritten)) {
288 ret = -EFAULT;
289 break;
290 }
291
292 bt_writen(bt_bmc, kbuffer, nwritten);
293
294 count -= nwritten;
295 buf += nwritten;
296 ret += nwritten;
297 }
298
299 set_b2h_atn(bt_bmc);
300
301out_unlock:
302 mutex_unlock(&bt_bmc->mutex);
303 return ret;
304}
305
306static long bt_bmc_ioctl(struct file *file, unsigned int cmd,
307 unsigned long param)
308{
309 struct bt_bmc *bt_bmc = file_bt_bmc(file);
310
311 switch (cmd) {
312 case BT_BMC_IOCTL_SMS_ATN:
313 set_sms_atn(bt_bmc);
314 return 0;
315 }
316 return -EINVAL;
317}
318
319static int bt_bmc_release(struct inode *inode, struct file *file)
320{
321 struct bt_bmc *bt_bmc = file_bt_bmc(file);
322
323 atomic_dec(&open_count);
324 set_b_busy(bt_bmc);
325 return 0;
326}
327
328static unsigned int bt_bmc_poll(struct file *file, poll_table *wait)
329{
330 struct bt_bmc *bt_bmc = file_bt_bmc(file);
331 unsigned int mask = 0;
332 u8 ctrl;
333
334 poll_wait(file, &bt_bmc->queue, wait);
335
336 ctrl = bt_inb(bt_bmc, BT_CTRL);
337
338 if (ctrl & BT_CTRL_H2B_ATN)
339 mask |= POLLIN;
340
341 if (!(ctrl & (BT_CTRL_H_BUSY | BT_CTRL_B2H_ATN)))
342 mask |= POLLOUT;
343
344 return mask;
345}
346
347static const struct file_operations bt_bmc_fops = {
348 .owner = THIS_MODULE,
349 .open = bt_bmc_open,
350 .read = bt_bmc_read,
351 .write = bt_bmc_write,
352 .release = bt_bmc_release,
353 .poll = bt_bmc_poll,
354 .unlocked_ioctl = bt_bmc_ioctl,
355};
356
357static void poll_timer(unsigned long data)
358{
359 struct bt_bmc *bt_bmc = (void *)data;
360
361 bt_bmc->poll_timer.expires += msecs_to_jiffies(500);
362 wake_up(&bt_bmc->queue);
363 add_timer(&bt_bmc->poll_timer);
364}
365
366static irqreturn_t bt_bmc_irq(int irq, void *arg)
367{
368 struct bt_bmc *bt_bmc = arg;
369 u32 reg;
370
371 reg = ioread32(bt_bmc->base + BT_CR2);
372 reg &= BT_CR2_IRQ_H2B | BT_CR2_IRQ_HBUSY;
373 if (!reg)
374 return IRQ_NONE;
375
376 /* ack pending IRQs */
377 iowrite32(reg, bt_bmc->base + BT_CR2);
378
379 wake_up(&bt_bmc->queue);
380 return IRQ_HANDLED;
381}
382
383static int bt_bmc_config_irq(struct bt_bmc *bt_bmc,
384 struct platform_device *pdev)
385{
386 struct device *dev = &pdev->dev;
387 u32 reg;
388 int rc;
389
390 bt_bmc->irq = platform_get_irq(pdev, 0);
391 if (!bt_bmc->irq)
392 return -ENODEV;
393
394 rc = devm_request_irq(dev, bt_bmc->irq, bt_bmc_irq, IRQF_SHARED,
395 DEVICE_NAME, bt_bmc);
396 if (rc < 0) {
397 dev_warn(dev, "Unable to request IRQ %d\n", bt_bmc->irq);
398 bt_bmc->irq = 0;
399 return rc;
400 }
401
402 /*
403 * Configure IRQs on the bmc clearing the H2B and HBUSY bits;
404 * H2B will be asserted when the bmc has data for us; HBUSY
405 * will be cleared (along with B2H) when we can write the next
406 * message to the BT buffer
407 */
408 reg = ioread32(bt_bmc->base + BT_CR1);
409 reg |= BT_CR1_IRQ_H2B | BT_CR1_IRQ_HBUSY;
410 iowrite32(reg, bt_bmc->base + BT_CR1);
411
412 return 0;
413}
414
415static int bt_bmc_probe(struct platform_device *pdev)
416{
417 struct bt_bmc *bt_bmc;
418 struct device *dev;
419 struct resource *res;
420 int rc;
421
422 if (!pdev || !pdev->dev.of_node)
423 return -ENODEV;
424
425 dev = &pdev->dev;
426 dev_info(dev, "Found bt bmc device\n");
427
428 bt_bmc = devm_kzalloc(dev, sizeof(*bt_bmc), GFP_KERNEL);
429 if (!bt_bmc)
430 return -ENOMEM;
431
432 dev_set_drvdata(&pdev->dev, bt_bmc);
433
434 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
435 bt_bmc->base = devm_ioremap_resource(&pdev->dev, res);
436 if (IS_ERR(bt_bmc->base))
437 return PTR_ERR(bt_bmc->base);
438
439 mutex_init(&bt_bmc->mutex);
440 init_waitqueue_head(&bt_bmc->queue);
441
442 bt_bmc->miscdev.minor = MISC_DYNAMIC_MINOR,
443 bt_bmc->miscdev.name = DEVICE_NAME,
444 bt_bmc->miscdev.fops = &bt_bmc_fops,
445 bt_bmc->miscdev.parent = dev;
446 rc = misc_register(&bt_bmc->miscdev);
447 if (rc) {
448 dev_err(dev, "Unable to register misc device\n");
449 return rc;
450 }
451
452 bt_bmc_config_irq(bt_bmc, pdev);
453
454 if (bt_bmc->irq) {
455 dev_info(dev, "Using IRQ %d\n", bt_bmc->irq);
456 } else {
457 dev_info(dev, "No IRQ; using timer\n");
458 setup_timer(&bt_bmc->poll_timer, poll_timer,
459 (unsigned long)bt_bmc);
460 bt_bmc->poll_timer.expires = jiffies + msecs_to_jiffies(10);
461 add_timer(&bt_bmc->poll_timer);
462 }
463
464 iowrite32((BT_IO_BASE << BT_CR0_IO_BASE) |
465 (BT_IRQ << BT_CR0_IRQ) |
466 BT_CR0_EN_CLR_SLV_RDP |
467 BT_CR0_EN_CLR_SLV_WRP |
468 BT_CR0_ENABLE_IBT,
469 bt_bmc->base + BT_CR0);
470
471 clr_b_busy(bt_bmc);
472
473 return 0;
474}
475
476static int bt_bmc_remove(struct platform_device *pdev)
477{
478 struct bt_bmc *bt_bmc = dev_get_drvdata(&pdev->dev);
479
480 misc_deregister(&bt_bmc->miscdev);
481 if (!bt_bmc->irq)
482 del_timer_sync(&bt_bmc->poll_timer);
483 return 0;
484}
485
486static const struct of_device_id bt_bmc_match[] = {
487 { .compatible = "aspeed,ast2400-ibt-bmc" },
488 { },
489};
490
491static struct platform_driver bt_bmc_driver = {
492 .driver = {
493 .name = DEVICE_NAME,
494 .of_match_table = bt_bmc_match,
495 },
496 .probe = bt_bmc_probe,
497 .remove = bt_bmc_remove,
498};
499
500module_platform_driver(bt_bmc_driver);
501
502MODULE_DEVICE_TABLE(of, bt_bmc_match);
503MODULE_LICENSE("GPL");
504MODULE_AUTHOR("Alistair Popple <alistair@popple.id.au>");
505MODULE_DESCRIPTION("Linux device interface to the IPMI BT interface");
diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
index d8619998cfb5..fcdd886819f5 100644
--- a/drivers/char/ipmi/ipmi_msghandler.c
+++ b/drivers/char/ipmi/ipmi_msghandler.c
@@ -2891,11 +2891,11 @@ int ipmi_register_smi(const struct ipmi_smi_handlers *handlers,
2891 intf->curr_channel = IPMI_MAX_CHANNELS; 2891 intf->curr_channel = IPMI_MAX_CHANNELS;
2892 } 2892 }
2893 2893
2894 rv = ipmi_bmc_register(intf, i);
2895
2894 if (rv == 0) 2896 if (rv == 0)
2895 rv = add_proc_entries(intf, i); 2897 rv = add_proc_entries(intf, i);
2896 2898
2897 rv = ipmi_bmc_register(intf, i);
2898
2899 out: 2899 out:
2900 if (rv) { 2900 if (rv) {
2901 if (intf->proc_dir) 2901 if (intf->proc_dir)
@@ -2982,8 +2982,6 @@ int ipmi_unregister_smi(ipmi_smi_t intf)
2982 int intf_num = intf->intf_num; 2982 int intf_num = intf->intf_num;
2983 ipmi_user_t user; 2983 ipmi_user_t user;
2984 2984
2985 ipmi_bmc_unregister(intf);
2986
2987 mutex_lock(&smi_watchers_mutex); 2985 mutex_lock(&smi_watchers_mutex);
2988 mutex_lock(&ipmi_interfaces_mutex); 2986 mutex_lock(&ipmi_interfaces_mutex);
2989 intf->intf_num = -1; 2987 intf->intf_num = -1;
@@ -3007,6 +3005,7 @@ int ipmi_unregister_smi(ipmi_smi_t intf)
3007 mutex_unlock(&ipmi_interfaces_mutex); 3005 mutex_unlock(&ipmi_interfaces_mutex);
3008 3006
3009 remove_proc_entries(intf); 3007 remove_proc_entries(intf);
3008 ipmi_bmc_unregister(intf);
3010 3009
3011 /* 3010 /*
3012 * Call all the watcher interfaces to tell them that 3011 * Call all the watcher interfaces to tell them that
diff --git a/drivers/char/ppdev.c b/drivers/char/ppdev.c
index d23368874710..6af1ce04b3da 100644
--- a/drivers/char/ppdev.c
+++ b/drivers/char/ppdev.c
@@ -748,10 +748,7 @@ static int pp_release(struct inode *inode, struct file *file)
748 } 748 }
749 749
750 if (pp->pdev) { 750 if (pp->pdev) {
751 const char *name = pp->pdev->name;
752
753 parport_unregister_device(pp->pdev); 751 parport_unregister_device(pp->pdev);
754 kfree(name);
755 pp->pdev = NULL; 752 pp->pdev = NULL;
756 pr_debug(CHRDEV "%x: unregistered pardevice\n", minor); 753 pr_debug(CHRDEV "%x: unregistered pardevice\n", minor);
757 } 754 }
diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
index 8de61876f633..3a9149cf0110 100644
--- a/drivers/char/tpm/tpm-interface.c
+++ b/drivers/char/tpm/tpm-interface.c
@@ -813,9 +813,6 @@ int tpm_do_selftest(struct tpm_chip *chip)
813 continue; 813 continue;
814 } 814 }
815 815
816 if (rc < TPM_HEADER_SIZE)
817 return -EFAULT;
818
819 if (rc == TPM_ERR_DISABLED || rc == TPM_ERR_DEACTIVATED) { 816 if (rc == TPM_ERR_DISABLED || rc == TPM_ERR_DEACTIVATED) {
820 dev_info(&chip->dev, 817 dev_info(&chip->dev,
821 "TPM is disabled/deactivated (0x%X)\n", rc); 818 "TPM is disabled/deactivated (0x%X)\n", rc);
diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
index d433b1db1fdd..5649234b7316 100644
--- a/drivers/char/virtio_console.c
+++ b/drivers/char/virtio_console.c
@@ -1539,19 +1539,29 @@ static void remove_port_data(struct port *port)
1539 spin_lock_irq(&port->inbuf_lock); 1539 spin_lock_irq(&port->inbuf_lock);
1540 /* Remove unused data this port might have received. */ 1540 /* Remove unused data this port might have received. */
1541 discard_port_data(port); 1541 discard_port_data(port);
1542 spin_unlock_irq(&port->inbuf_lock);
1542 1543
1543 /* Remove buffers we queued up for the Host to send us data in. */ 1544 /* Remove buffers we queued up for the Host to send us data in. */
1544 while ((buf = virtqueue_detach_unused_buf(port->in_vq))) 1545 do {
1545 free_buf(buf, true); 1546 spin_lock_irq(&port->inbuf_lock);
1546 spin_unlock_irq(&port->inbuf_lock); 1547 buf = virtqueue_detach_unused_buf(port->in_vq);
1548 spin_unlock_irq(&port->inbuf_lock);
1549 if (buf)
1550 free_buf(buf, true);
1551 } while (buf);
1547 1552
1548 spin_lock_irq(&port->outvq_lock); 1553 spin_lock_irq(&port->outvq_lock);
1549 reclaim_consumed_buffers(port); 1554 reclaim_consumed_buffers(port);
1555 spin_unlock_irq(&port->outvq_lock);
1550 1556
1551 /* Free pending buffers from the out-queue. */ 1557 /* Free pending buffers from the out-queue. */
1552 while ((buf = virtqueue_detach_unused_buf(port->out_vq))) 1558 do {
1553 free_buf(buf, true); 1559 spin_lock_irq(&port->outvq_lock);
1554 spin_unlock_irq(&port->outvq_lock); 1560 buf = virtqueue_detach_unused_buf(port->out_vq);
1561 spin_unlock_irq(&port->outvq_lock);
1562 if (buf)
1563 free_buf(buf, true);
1564 } while (buf);
1555} 1565}
1556 1566
1557/* 1567/*
diff --git a/drivers/clk/at91/clk-programmable.c b/drivers/clk/at91/clk-programmable.c
index 190122e64a3a..85a449cf61e3 100644
--- a/drivers/clk/at91/clk-programmable.c
+++ b/drivers/clk/at91/clk-programmable.c
@@ -203,7 +203,7 @@ at91_clk_register_programmable(struct regmap *regmap,
203 ret = clk_hw_register(NULL, &prog->hw); 203 ret = clk_hw_register(NULL, &prog->hw);
204 if (ret) { 204 if (ret) {
205 kfree(prog); 205 kfree(prog);
206 hw = &prog->hw; 206 hw = ERR_PTR(ret);
207 } 207 }
208 208
209 return hw; 209 return hw;
diff --git a/drivers/clk/bcm/Kconfig b/drivers/clk/bcm/Kconfig
index f21e9b7afd1a..e3eed5a78404 100644
--- a/drivers/clk/bcm/Kconfig
+++ b/drivers/clk/bcm/Kconfig
@@ -20,7 +20,7 @@ config CLK_BCM_KONA
20 20
21config COMMON_CLK_IPROC 21config COMMON_CLK_IPROC
22 bool "Broadcom iProc clock support" 22 bool "Broadcom iProc clock support"
23 depends on ARCH_BCM_IPROC || COMPILE_TEST 23 depends on ARCH_BCM_IPROC || ARCH_BCM_63XX || COMPILE_TEST
24 depends on COMMON_CLK 24 depends on COMMON_CLK
25 default ARCH_BCM_IPROC 25 default ARCH_BCM_IPROC
26 help 26 help
diff --git a/drivers/clk/bcm/clk-bcm2835.c b/drivers/clk/bcm/clk-bcm2835.c
index b68bf573dcfb..8c7763fd9efc 100644
--- a/drivers/clk/bcm/clk-bcm2835.c
+++ b/drivers/clk/bcm/clk-bcm2835.c
@@ -502,8 +502,12 @@ static long bcm2835_pll_rate_from_divisors(unsigned long parent_rate,
502static long bcm2835_pll_round_rate(struct clk_hw *hw, unsigned long rate, 502static long bcm2835_pll_round_rate(struct clk_hw *hw, unsigned long rate,
503 unsigned long *parent_rate) 503 unsigned long *parent_rate)
504{ 504{
505 struct bcm2835_pll *pll = container_of(hw, struct bcm2835_pll, hw);
506 const struct bcm2835_pll_data *data = pll->data;
505 u32 ndiv, fdiv; 507 u32 ndiv, fdiv;
506 508
509 rate = clamp(rate, data->min_rate, data->max_rate);
510
507 bcm2835_pll_choose_ndiv_and_fdiv(rate, *parent_rate, &ndiv, &fdiv); 511 bcm2835_pll_choose_ndiv_and_fdiv(rate, *parent_rate, &ndiv, &fdiv);
508 512
509 return bcm2835_pll_rate_from_divisors(*parent_rate, ndiv, fdiv, 1); 513 return bcm2835_pll_rate_from_divisors(*parent_rate, ndiv, fdiv, 1);
@@ -608,13 +612,6 @@ static int bcm2835_pll_set_rate(struct clk_hw *hw,
608 u32 ana[4]; 612 u32 ana[4];
609 int i; 613 int i;
610 614
611 if (rate < data->min_rate || rate > data->max_rate) {
612 dev_err(cprman->dev, "%s: rate out of spec: %lu vs (%lu, %lu)\n",
613 clk_hw_get_name(hw), rate,
614 data->min_rate, data->max_rate);
615 return -EINVAL;
616 }
617
618 if (rate > data->max_fb_rate) { 615 if (rate > data->max_fb_rate) {
619 use_fb_prediv = true; 616 use_fb_prediv = true;
620 rate /= 2; 617 rate /= 2;
diff --git a/drivers/clk/berlin/bg2.c b/drivers/clk/berlin/bg2.c
index edf3b96b3b73..1d99292e2039 100644
--- a/drivers/clk/berlin/bg2.c
+++ b/drivers/clk/berlin/bg2.c
@@ -685,7 +685,7 @@ static void __init berlin2_clock_setup(struct device_node *np)
685 } 685 }
686 686
687 /* register clk-provider */ 687 /* register clk-provider */
688 of_clk_add_hw_provider(np, of_clk_hw_onecell_get, &clk_data); 688 of_clk_add_hw_provider(np, of_clk_hw_onecell_get, clk_data);
689 689
690 return; 690 return;
691 691
diff --git a/drivers/clk/berlin/bg2q.c b/drivers/clk/berlin/bg2q.c
index 0718e831475f..3b784b593afd 100644
--- a/drivers/clk/berlin/bg2q.c
+++ b/drivers/clk/berlin/bg2q.c
@@ -382,7 +382,7 @@ static void __init berlin2q_clock_setup(struct device_node *np)
382 } 382 }
383 383
384 /* register clk-provider */ 384 /* register clk-provider */
385 of_clk_add_hw_provider(np, of_clk_hw_onecell_get, &clk_data); 385 of_clk_add_hw_provider(np, of_clk_hw_onecell_get, clk_data);
386 386
387 return; 387 return;
388 388
diff --git a/drivers/clk/clk-efm32gg.c b/drivers/clk/clk-efm32gg.c
index 8802a2dd56ac..f674778fb3ac 100644
--- a/drivers/clk/clk-efm32gg.c
+++ b/drivers/clk/clk-efm32gg.c
@@ -82,6 +82,6 @@ static void __init efm32gg_cmu_init(struct device_node *np)
82 hws[clk_HFPERCLKDAC0] = clk_hw_register_gate(NULL, "HFPERCLK.DAC0", 82 hws[clk_HFPERCLKDAC0] = clk_hw_register_gate(NULL, "HFPERCLK.DAC0",
83 "HFXO", 0, base + CMU_HFPERCLKEN0, 17, 0, NULL); 83 "HFXO", 0, base + CMU_HFPERCLKEN0, 17, 0, NULL);
84 84
85 of_clk_add_hw_provider(np, of_clk_hw_onecell_get, &clk_data); 85 of_clk_add_hw_provider(np, of_clk_hw_onecell_get, clk_data);
86} 86}
87CLK_OF_DECLARE(efm32ggcmu, "efm32gg,cmu", efm32gg_cmu_init); 87CLK_OF_DECLARE(efm32ggcmu, "efm32gg,cmu", efm32gg_cmu_init);
diff --git a/drivers/clk/clk-max77686.c b/drivers/clk/clk-max77686.c
index b637f5979023..eb953d3b0b69 100644
--- a/drivers/clk/clk-max77686.c
+++ b/drivers/clk/clk-max77686.c
@@ -216,6 +216,7 @@ static int max77686_clk_probe(struct platform_device *pdev)
216 return -EINVAL; 216 return -EINVAL;
217 } 217 }
218 218
219 drv_data->num_clks = num_clks;
219 drv_data->max_clk_data = devm_kcalloc(dev, num_clks, 220 drv_data->max_clk_data = devm_kcalloc(dev, num_clks,
220 sizeof(*drv_data->max_clk_data), 221 sizeof(*drv_data->max_clk_data),
221 GFP_KERNEL); 222 GFP_KERNEL);
diff --git a/drivers/clk/clk-qoriq.c b/drivers/clk/clk-qoriq.c
index 20b105584f82..80ae2a51452d 100644
--- a/drivers/clk/clk-qoriq.c
+++ b/drivers/clk/clk-qoriq.c
@@ -700,6 +700,7 @@ static struct clk * __init create_mux_common(struct clockgen *cg,
700 struct mux_hwclock *hwc, 700 struct mux_hwclock *hwc,
701 const struct clk_ops *ops, 701 const struct clk_ops *ops,
702 unsigned long min_rate, 702 unsigned long min_rate,
703 unsigned long max_rate,
703 unsigned long pct80_rate, 704 unsigned long pct80_rate,
704 const char *fmt, int idx) 705 const char *fmt, int idx)
705{ 706{
@@ -728,6 +729,8 @@ static struct clk * __init create_mux_common(struct clockgen *cg,
728 continue; 729 continue;
729 if (rate < min_rate) 730 if (rate < min_rate)
730 continue; 731 continue;
732 if (rate > max_rate)
733 continue;
731 734
732 parent_names[j] = div->name; 735 parent_names[j] = div->name;
733 hwc->parent_to_clksel[j] = i; 736 hwc->parent_to_clksel[j] = i;
@@ -759,7 +762,7 @@ static struct clk * __init create_one_cmux(struct clockgen *cg, int idx)
759 struct mux_hwclock *hwc; 762 struct mux_hwclock *hwc;
760 const struct clockgen_pll_div *div; 763 const struct clockgen_pll_div *div;
761 unsigned long plat_rate, min_rate; 764 unsigned long plat_rate, min_rate;
762 u64 pct80_rate; 765 u64 max_rate, pct80_rate;
763 u32 clksel; 766 u32 clksel;
764 767
765 hwc = kzalloc(sizeof(*hwc), GFP_KERNEL); 768 hwc = kzalloc(sizeof(*hwc), GFP_KERNEL);
@@ -787,8 +790,8 @@ static struct clk * __init create_one_cmux(struct clockgen *cg, int idx)
787 return NULL; 790 return NULL;
788 } 791 }
789 792
790 pct80_rate = clk_get_rate(div->clk); 793 max_rate = clk_get_rate(div->clk);
791 pct80_rate *= 8; 794 pct80_rate = max_rate * 8;
792 do_div(pct80_rate, 10); 795 do_div(pct80_rate, 10);
793 796
794 plat_rate = clk_get_rate(cg->pll[PLATFORM_PLL].div[PLL_DIV1].clk); 797 plat_rate = clk_get_rate(cg->pll[PLATFORM_PLL].div[PLL_DIV1].clk);
@@ -798,7 +801,7 @@ static struct clk * __init create_one_cmux(struct clockgen *cg, int idx)
798 else 801 else
799 min_rate = plat_rate / 2; 802 min_rate = plat_rate / 2;
800 803
801 return create_mux_common(cg, hwc, &cmux_ops, min_rate, 804 return create_mux_common(cg, hwc, &cmux_ops, min_rate, max_rate,
802 pct80_rate, "cg-cmux%d", idx); 805 pct80_rate, "cg-cmux%d", idx);
803} 806}
804 807
@@ -813,7 +816,7 @@ static struct clk * __init create_one_hwaccel(struct clockgen *cg, int idx)
813 hwc->reg = cg->regs + 0x20 * idx + 0x10; 816 hwc->reg = cg->regs + 0x20 * idx + 0x10;
814 hwc->info = cg->info.hwaccel[idx]; 817 hwc->info = cg->info.hwaccel[idx];
815 818
816 return create_mux_common(cg, hwc, &hwaccel_ops, 0, 0, 819 return create_mux_common(cg, hwc, &hwaccel_ops, 0, ULONG_MAX, 0,
817 "cg-hwaccel%d", idx); 820 "cg-hwaccel%d", idx);
818} 821}
819 822
diff --git a/drivers/clk/clk-xgene.c b/drivers/clk/clk-xgene.c
index 5daddf5ecc4b..bc37030e38ba 100644
--- a/drivers/clk/clk-xgene.c
+++ b/drivers/clk/clk-xgene.c
@@ -463,22 +463,20 @@ static int xgene_clk_enable(struct clk_hw *hw)
463 struct xgene_clk *pclk = to_xgene_clk(hw); 463 struct xgene_clk *pclk = to_xgene_clk(hw);
464 unsigned long flags = 0; 464 unsigned long flags = 0;
465 u32 data; 465 u32 data;
466 phys_addr_t reg;
467 466
468 if (pclk->lock) 467 if (pclk->lock)
469 spin_lock_irqsave(pclk->lock, flags); 468 spin_lock_irqsave(pclk->lock, flags);
470 469
471 if (pclk->param.csr_reg != NULL) { 470 if (pclk->param.csr_reg != NULL) {
472 pr_debug("%s clock enabled\n", clk_hw_get_name(hw)); 471 pr_debug("%s clock enabled\n", clk_hw_get_name(hw));
473 reg = __pa(pclk->param.csr_reg);
474 /* First enable the clock */ 472 /* First enable the clock */
475 data = xgene_clk_read(pclk->param.csr_reg + 473 data = xgene_clk_read(pclk->param.csr_reg +
476 pclk->param.reg_clk_offset); 474 pclk->param.reg_clk_offset);
477 data |= pclk->param.reg_clk_mask; 475 data |= pclk->param.reg_clk_mask;
478 xgene_clk_write(data, pclk->param.csr_reg + 476 xgene_clk_write(data, pclk->param.csr_reg +
479 pclk->param.reg_clk_offset); 477 pclk->param.reg_clk_offset);
480 pr_debug("%s clock PADDR base %pa clk offset 0x%08X mask 0x%08X value 0x%08X\n", 478 pr_debug("%s clk offset 0x%08X mask 0x%08X value 0x%08X\n",
481 clk_hw_get_name(hw), &reg, 479 clk_hw_get_name(hw),
482 pclk->param.reg_clk_offset, pclk->param.reg_clk_mask, 480 pclk->param.reg_clk_offset, pclk->param.reg_clk_mask,
483 data); 481 data);
484 482
@@ -488,8 +486,8 @@ static int xgene_clk_enable(struct clk_hw *hw)
488 data &= ~pclk->param.reg_csr_mask; 486 data &= ~pclk->param.reg_csr_mask;
489 xgene_clk_write(data, pclk->param.csr_reg + 487 xgene_clk_write(data, pclk->param.csr_reg +
490 pclk->param.reg_csr_offset); 488 pclk->param.reg_csr_offset);
491 pr_debug("%s CSR RESET PADDR base %pa csr offset 0x%08X mask 0x%08X value 0x%08X\n", 489 pr_debug("%s csr offset 0x%08X mask 0x%08X value 0x%08X\n",
492 clk_hw_get_name(hw), &reg, 490 clk_hw_get_name(hw),
493 pclk->param.reg_csr_offset, pclk->param.reg_csr_mask, 491 pclk->param.reg_csr_offset, pclk->param.reg_csr_mask,
494 data); 492 data);
495 } 493 }
diff --git a/drivers/clk/hisilicon/clk-hi6220.c b/drivers/clk/hisilicon/clk-hi6220.c
index fe364e63f8de..c0e8e1f196aa 100644
--- a/drivers/clk/hisilicon/clk-hi6220.c
+++ b/drivers/clk/hisilicon/clk-hi6220.c
@@ -195,7 +195,7 @@ static void __init hi6220_clk_sys_init(struct device_node *np)
195 hi6220_clk_register_divider(hi6220_div_clks_sys, 195 hi6220_clk_register_divider(hi6220_div_clks_sys,
196 ARRAY_SIZE(hi6220_div_clks_sys), clk_data); 196 ARRAY_SIZE(hi6220_div_clks_sys), clk_data);
197} 197}
198CLK_OF_DECLARE(hi6220_clk_sys, "hisilicon,hi6220-sysctrl", hi6220_clk_sys_init); 198CLK_OF_DECLARE_DRIVER(hi6220_clk_sys, "hisilicon,hi6220-sysctrl", hi6220_clk_sys_init);
199 199
200 200
201/* clocks in media controller */ 201/* clocks in media controller */
@@ -252,7 +252,7 @@ static void __init hi6220_clk_media_init(struct device_node *np)
252 hi6220_clk_register_divider(hi6220_div_clks_media, 252 hi6220_clk_register_divider(hi6220_div_clks_media,
253 ARRAY_SIZE(hi6220_div_clks_media), clk_data); 253 ARRAY_SIZE(hi6220_div_clks_media), clk_data);
254} 254}
255CLK_OF_DECLARE(hi6220_clk_media, "hisilicon,hi6220-mediactrl", hi6220_clk_media_init); 255CLK_OF_DECLARE_DRIVER(hi6220_clk_media, "hisilicon,hi6220-mediactrl", hi6220_clk_media_init);
256 256
257 257
258/* clocks in pmctrl */ 258/* clocks in pmctrl */
diff --git a/drivers/clk/imx/clk-pllv3.c b/drivers/clk/imx/clk-pllv3.c
index 19f9b622981a..7a6acc3e4a92 100644
--- a/drivers/clk/imx/clk-pllv3.c
+++ b/drivers/clk/imx/clk-pllv3.c
@@ -223,7 +223,7 @@ static unsigned long clk_pllv3_av_recalc_rate(struct clk_hw *hw,
223 temp64 *= mfn; 223 temp64 *= mfn;
224 do_div(temp64, mfd); 224 do_div(temp64, mfd);
225 225
226 return (parent_rate * div) + (u32)temp64; 226 return parent_rate * div + (unsigned long)temp64;
227} 227}
228 228
229static long clk_pllv3_av_round_rate(struct clk_hw *hw, unsigned long rate, 229static long clk_pllv3_av_round_rate(struct clk_hw *hw, unsigned long rate,
@@ -247,7 +247,11 @@ static long clk_pllv3_av_round_rate(struct clk_hw *hw, unsigned long rate,
247 do_div(temp64, parent_rate); 247 do_div(temp64, parent_rate);
248 mfn = temp64; 248 mfn = temp64;
249 249
250 return parent_rate * div + parent_rate * mfn / mfd; 250 temp64 = (u64)parent_rate;
251 temp64 *= mfn;
252 do_div(temp64, mfd);
253
254 return parent_rate * div + (unsigned long)temp64;
251} 255}
252 256
253static int clk_pllv3_av_set_rate(struct clk_hw *hw, unsigned long rate, 257static int clk_pllv3_av_set_rate(struct clk_hw *hw, unsigned long rate,
diff --git a/drivers/clk/mediatek/Kconfig b/drivers/clk/mediatek/Kconfig
index 380c372d528e..f042bd2a6a99 100644
--- a/drivers/clk/mediatek/Kconfig
+++ b/drivers/clk/mediatek/Kconfig
@@ -8,6 +8,7 @@ config COMMON_CLK_MEDIATEK
8 8
9config COMMON_CLK_MT8135 9config COMMON_CLK_MT8135
10 bool "Clock driver for Mediatek MT8135" 10 bool "Clock driver for Mediatek MT8135"
11 depends on ARCH_MEDIATEK || COMPILE_TEST
11 select COMMON_CLK_MEDIATEK 12 select COMMON_CLK_MEDIATEK
12 default ARCH_MEDIATEK 13 default ARCH_MEDIATEK
13 ---help--- 14 ---help---
@@ -15,6 +16,7 @@ config COMMON_CLK_MT8135
15 16
16config COMMON_CLK_MT8173 17config COMMON_CLK_MT8173
17 bool "Clock driver for Mediatek MT8173" 18 bool "Clock driver for Mediatek MT8173"
19 depends on ARCH_MEDIATEK || COMPILE_TEST
18 select COMMON_CLK_MEDIATEK 20 select COMMON_CLK_MEDIATEK
19 default ARCH_MEDIATEK 21 default ARCH_MEDIATEK
20 ---help--- 22 ---help---
diff --git a/drivers/clk/mmp/clk-of-mmp2.c b/drivers/clk/mmp/clk-of-mmp2.c
index 3a51fff1b0e7..9adaf48aea23 100644
--- a/drivers/clk/mmp/clk-of-mmp2.c
+++ b/drivers/clk/mmp/clk-of-mmp2.c
@@ -313,7 +313,7 @@ static void __init mmp2_clk_init(struct device_node *np)
313 } 313 }
314 314
315 pxa_unit->apmu_base = of_iomap(np, 1); 315 pxa_unit->apmu_base = of_iomap(np, 1);
316 if (!pxa_unit->mpmu_base) { 316 if (!pxa_unit->apmu_base) {
317 pr_err("failed to map apmu registers\n"); 317 pr_err("failed to map apmu registers\n");
318 return; 318 return;
319 } 319 }
diff --git a/drivers/clk/mmp/clk-of-pxa168.c b/drivers/clk/mmp/clk-of-pxa168.c
index 87f2317b2a00..f110c02e83cb 100644
--- a/drivers/clk/mmp/clk-of-pxa168.c
+++ b/drivers/clk/mmp/clk-of-pxa168.c
@@ -262,7 +262,7 @@ static void __init pxa168_clk_init(struct device_node *np)
262 } 262 }
263 263
264 pxa_unit->apmu_base = of_iomap(np, 1); 264 pxa_unit->apmu_base = of_iomap(np, 1);
265 if (!pxa_unit->mpmu_base) { 265 if (!pxa_unit->apmu_base) {
266 pr_err("failed to map apmu registers\n"); 266 pr_err("failed to map apmu registers\n");
267 return; 267 return;
268 } 268 }
diff --git a/drivers/clk/mmp/clk-of-pxa910.c b/drivers/clk/mmp/clk-of-pxa910.c
index e22a67f76d93..64d1ef49caeb 100644
--- a/drivers/clk/mmp/clk-of-pxa910.c
+++ b/drivers/clk/mmp/clk-of-pxa910.c
@@ -282,7 +282,7 @@ static void __init pxa910_clk_init(struct device_node *np)
282 } 282 }
283 283
284 pxa_unit->apmu_base = of_iomap(np, 1); 284 pxa_unit->apmu_base = of_iomap(np, 1);
285 if (!pxa_unit->mpmu_base) { 285 if (!pxa_unit->apmu_base) {
286 pr_err("failed to map apmu registers\n"); 286 pr_err("failed to map apmu registers\n");
287 return; 287 return;
288 } 288 }
@@ -294,7 +294,7 @@ static void __init pxa910_clk_init(struct device_node *np)
294 } 294 }
295 295
296 pxa_unit->apbcp_base = of_iomap(np, 3); 296 pxa_unit->apbcp_base = of_iomap(np, 3);
297 if (!pxa_unit->mpmu_base) { 297 if (!pxa_unit->apbcp_base) {
298 pr_err("failed to map apbcp registers\n"); 298 pr_err("failed to map apbcp registers\n");
299 return; 299 return;
300 } 300 }
diff --git a/drivers/clk/mvebu/armada-37xx-periph.c b/drivers/clk/mvebu/armada-37xx-periph.c
index 45905fc0d75b..cecb0fdfaef6 100644
--- a/drivers/clk/mvebu/armada-37xx-periph.c
+++ b/drivers/clk/mvebu/armada-37xx-periph.c
@@ -305,7 +305,7 @@ static const struct of_device_id armada_3700_periph_clock_of_match[] = {
305}; 305};
306static int armada_3700_add_composite_clk(const struct clk_periph_data *data, 306static int armada_3700_add_composite_clk(const struct clk_periph_data *data,
307 void __iomem *reg, spinlock_t *lock, 307 void __iomem *reg, spinlock_t *lock,
308 struct device *dev, struct clk_hw *hw) 308 struct device *dev, struct clk_hw **hw)
309{ 309{
310 const struct clk_ops *mux_ops = NULL, *gate_ops = NULL, 310 const struct clk_ops *mux_ops = NULL, *gate_ops = NULL,
311 *rate_ops = NULL; 311 *rate_ops = NULL;
@@ -329,6 +329,7 @@ static int armada_3700_add_composite_clk(const struct clk_periph_data *data,
329 gate->lock = lock; 329 gate->lock = lock;
330 gate_ops = gate_hw->init->ops; 330 gate_ops = gate_hw->init->ops;
331 gate->reg = reg + (u64)gate->reg; 331 gate->reg = reg + (u64)gate->reg;
332 gate->flags = CLK_GATE_SET_TO_DISABLE;
332 } 333 }
333 334
334 if (data->rate_hw) { 335 if (data->rate_hw) {
@@ -353,13 +354,13 @@ static int armada_3700_add_composite_clk(const struct clk_periph_data *data,
353 } 354 }
354 } 355 }
355 356
356 hw = clk_hw_register_composite(dev, data->name, data->parent_names, 357 *hw = clk_hw_register_composite(dev, data->name, data->parent_names,
357 data->num_parents, mux_hw, 358 data->num_parents, mux_hw,
358 mux_ops, rate_hw, rate_ops, 359 mux_ops, rate_hw, rate_ops,
359 gate_hw, gate_ops, CLK_IGNORE_UNUSED); 360 gate_hw, gate_ops, CLK_IGNORE_UNUSED);
360 361
361 if (IS_ERR(hw)) 362 if (IS_ERR(*hw))
362 return PTR_ERR(hw); 363 return PTR_ERR(*hw);
363 364
364 return 0; 365 return 0;
365} 366}
@@ -400,7 +401,7 @@ static int armada_3700_periph_clock_probe(struct platform_device *pdev)
400 spin_lock_init(&driver_data->lock); 401 spin_lock_init(&driver_data->lock);
401 402
402 for (i = 0; i < num_periph; i++) { 403 for (i = 0; i < num_periph; i++) {
403 struct clk_hw *hw = driver_data->hw_data->hws[i]; 404 struct clk_hw **hw = &driver_data->hw_data->hws[i];
404 405
405 if (armada_3700_add_composite_clk(&data[i], reg, 406 if (armada_3700_add_composite_clk(&data[i], reg,
406 &driver_data->lock, dev, hw)) 407 &driver_data->lock, dev, hw))
diff --git a/drivers/clk/rockchip/clk-ddr.c b/drivers/clk/rockchip/clk-ddr.c
index 8feba93672c5..e8075359366b 100644
--- a/drivers/clk/rockchip/clk-ddr.c
+++ b/drivers/clk/rockchip/clk-ddr.c
@@ -144,11 +144,8 @@ struct clk *rockchip_clk_register_ddrclk(const char *name, int flags,
144 ddrclk->ddr_flag = ddr_flag; 144 ddrclk->ddr_flag = ddr_flag;
145 145
146 clk = clk_register(NULL, &ddrclk->hw); 146 clk = clk_register(NULL, &ddrclk->hw);
147 if (IS_ERR(clk)) { 147 if (IS_ERR(clk))
148 pr_err("%s: could not register ddrclk %s\n", __func__, name);
149 kfree(ddrclk); 148 kfree(ddrclk);
150 return NULL;
151 }
152 149
153 return clk; 150 return clk;
154} 151}
diff --git a/drivers/clk/samsung/clk-exynos-audss.c b/drivers/clk/samsung/clk-exynos-audss.c
index 51d152f735cc..17e68a724945 100644
--- a/drivers/clk/samsung/clk-exynos-audss.c
+++ b/drivers/clk/samsung/clk-exynos-audss.c
@@ -106,6 +106,7 @@ static const struct of_device_id exynos_audss_clk_of_match[] = {
106 }, 106 },
107 { }, 107 { },
108}; 108};
109MODULE_DEVICE_TABLE(of, exynos_audss_clk_of_match);
109 110
110static void exynos_audss_clk_teardown(void) 111static void exynos_audss_clk_teardown(void)
111{ 112{
diff --git a/drivers/clk/samsung/clk-exynos-clkout.c b/drivers/clk/samsung/clk-exynos-clkout.c
index 96fab6cfb202..6c6afb87b4ce 100644
--- a/drivers/clk/samsung/clk-exynos-clkout.c
+++ b/drivers/clk/samsung/clk-exynos-clkout.c
@@ -132,28 +132,34 @@ free_clkout:
132 pr_err("%s: failed to register clkout clock\n", __func__); 132 pr_err("%s: failed to register clkout clock\n", __func__);
133} 133}
134 134
135/*
136 * We use CLK_OF_DECLARE_DRIVER initialization method to avoid setting
137 * the OF_POPULATED flag on the pmu device tree node, so later the
138 * Exynos PMU platform device can be properly probed with PMU driver.
139 */
140
135static void __init exynos4_clkout_init(struct device_node *node) 141static void __init exynos4_clkout_init(struct device_node *node)
136{ 142{
137 exynos_clkout_init(node, EXYNOS4_CLKOUT_MUX_MASK); 143 exynos_clkout_init(node, EXYNOS4_CLKOUT_MUX_MASK);
138} 144}
139CLK_OF_DECLARE(exynos4210_clkout, "samsung,exynos4210-pmu", 145CLK_OF_DECLARE_DRIVER(exynos4210_clkout, "samsung,exynos4210-pmu",
140 exynos4_clkout_init); 146 exynos4_clkout_init);
141CLK_OF_DECLARE(exynos4212_clkout, "samsung,exynos4212-pmu", 147CLK_OF_DECLARE_DRIVER(exynos4212_clkout, "samsung,exynos4212-pmu",
142 exynos4_clkout_init); 148 exynos4_clkout_init);
143CLK_OF_DECLARE(exynos4412_clkout, "samsung,exynos4412-pmu", 149CLK_OF_DECLARE_DRIVER(exynos4412_clkout, "samsung,exynos4412-pmu",
144 exynos4_clkout_init); 150 exynos4_clkout_init);
145CLK_OF_DECLARE(exynos3250_clkout, "samsung,exynos3250-pmu", 151CLK_OF_DECLARE_DRIVER(exynos3250_clkout, "samsung,exynos3250-pmu",
146 exynos4_clkout_init); 152 exynos4_clkout_init);
147 153
148static void __init exynos5_clkout_init(struct device_node *node) 154static void __init exynos5_clkout_init(struct device_node *node)
149{ 155{
150 exynos_clkout_init(node, EXYNOS5_CLKOUT_MUX_MASK); 156 exynos_clkout_init(node, EXYNOS5_CLKOUT_MUX_MASK);
151} 157}
152CLK_OF_DECLARE(exynos5250_clkout, "samsung,exynos5250-pmu", 158CLK_OF_DECLARE_DRIVER(exynos5250_clkout, "samsung,exynos5250-pmu",
153 exynos5_clkout_init); 159 exynos5_clkout_init);
154CLK_OF_DECLARE(exynos5410_clkout, "samsung,exynos5410-pmu", 160CLK_OF_DECLARE_DRIVER(exynos5410_clkout, "samsung,exynos5410-pmu",
155 exynos5_clkout_init); 161 exynos5_clkout_init);
156CLK_OF_DECLARE(exynos5420_clkout, "samsung,exynos5420-pmu", 162CLK_OF_DECLARE_DRIVER(exynos5420_clkout, "samsung,exynos5420-pmu",
157 exynos5_clkout_init); 163 exynos5_clkout_init);
158CLK_OF_DECLARE(exynos5433_clkout, "samsung,exynos5433-pmu", 164CLK_OF_DECLARE_DRIVER(exynos5433_clkout, "samsung,exynos5433-pmu",
159 exynos5_clkout_init); 165 exynos5_clkout_init);
diff --git a/drivers/clk/sunxi-ng/ccu-sun6i-a31.c b/drivers/clk/sunxi-ng/ccu-sun6i-a31.c
index 79596463e0d9..fc75a335a7ce 100644
--- a/drivers/clk/sunxi-ng/ccu-sun6i-a31.c
+++ b/drivers/clk/sunxi-ng/ccu-sun6i-a31.c
@@ -143,7 +143,7 @@ static SUNXI_CCU_NKM_WITH_MUX_GATE_LOCK(pll_mipi_clk, "pll-mipi",
143 4, 2, /* K */ 143 4, 2, /* K */
144 0, 4, /* M */ 144 0, 4, /* M */
145 21, 0, /* mux */ 145 21, 0, /* mux */
146 BIT(31), /* gate */ 146 BIT(31) | BIT(23) | BIT(22), /* gate */
147 BIT(28), /* lock */ 147 BIT(28), /* lock */
148 CLK_SET_RATE_UNGATE); 148 CLK_SET_RATE_UNGATE);
149 149
@@ -191,6 +191,8 @@ static struct clk_div_table axi_div_table[] = {
191static SUNXI_CCU_DIV_TABLE(axi_clk, "axi", "cpu", 191static SUNXI_CCU_DIV_TABLE(axi_clk, "axi", "cpu",
192 0x050, 0, 3, axi_div_table, 0); 192 0x050, 0, 3, axi_div_table, 0);
193 193
194#define SUN6I_A31_AHB1_REG 0x054
195
194static const char * const ahb1_parents[] = { "osc32k", "osc24M", 196static const char * const ahb1_parents[] = { "osc32k", "osc24M",
195 "axi", "pll-periph" }; 197 "axi", "pll-periph" };
196 198
@@ -1230,6 +1232,16 @@ static void __init sun6i_a31_ccu_setup(struct device_node *node)
1230 val &= BIT(16); 1232 val &= BIT(16);
1231 writel(val, reg + SUN6I_A31_PLL_MIPI_REG); 1233 writel(val, reg + SUN6I_A31_PLL_MIPI_REG);
1232 1234
1235 /* Force AHB1 to PLL6 / 3 */
1236 val = readl(reg + SUN6I_A31_AHB1_REG);
1237 /* set PLL6 pre-div = 3 */
1238 val &= ~GENMASK(7, 6);
1239 val |= 0x2 << 6;
1240 /* select PLL6 / pre-div */
1241 val &= ~GENMASK(13, 12);
1242 val |= 0x3 << 12;
1243 writel(val, reg + SUN6I_A31_AHB1_REG);
1244
1233 sunxi_ccu_probe(node, reg, &sun6i_a31_ccu_desc); 1245 sunxi_ccu_probe(node, reg, &sun6i_a31_ccu_desc);
1234 1246
1235 ccu_mux_notifier_register(pll_cpu_clk.common.hw.clk, 1247 ccu_mux_notifier_register(pll_cpu_clk.common.hw.clk,
diff --git a/drivers/clk/sunxi-ng/ccu-sun8i-a33.c b/drivers/clk/sunxi-ng/ccu-sun8i-a33.c
index 96b40ca57697..9bd1f78a0547 100644
--- a/drivers/clk/sunxi-ng/ccu-sun8i-a33.c
+++ b/drivers/clk/sunxi-ng/ccu-sun8i-a33.c
@@ -131,7 +131,7 @@ static SUNXI_CCU_NKM_WITH_GATE_LOCK(pll_mipi_clk, "pll-mipi",
131 8, 4, /* N */ 131 8, 4, /* N */
132 4, 2, /* K */ 132 4, 2, /* K */
133 0, 4, /* M */ 133 0, 4, /* M */
134 BIT(31), /* gate */ 134 BIT(31) | BIT(23) | BIT(22), /* gate */
135 BIT(28), /* lock */ 135 BIT(28), /* lock */
136 CLK_SET_RATE_UNGATE); 136 CLK_SET_RATE_UNGATE);
137 137
diff --git a/drivers/clk/sunxi/clk-sunxi.c b/drivers/clk/sunxi/clk-sunxi.c
index 838b22aa8b67..f2c9274b8bd5 100644
--- a/drivers/clk/sunxi/clk-sunxi.c
+++ b/drivers/clk/sunxi/clk-sunxi.c
@@ -373,7 +373,7 @@ static void sun4i_get_apb1_factors(struct factors_request *req)
373 else 373 else
374 calcp = 3; 374 calcp = 3;
375 375
376 calcm = (req->parent_rate >> calcp) - 1; 376 calcm = (div >> calcp) - 1;
377 377
378 req->rate = (req->parent_rate >> calcp) / (calcm + 1); 378 req->rate = (req->parent_rate >> calcp) / (calcm + 1);
379 req->m = calcm; 379 req->m = calcm;
diff --git a/drivers/clk/uniphier/clk-uniphier-core.c b/drivers/clk/uniphier/clk-uniphier-core.c
index 5ffb898d0839..26c53f7963a4 100644
--- a/drivers/clk/uniphier/clk-uniphier-core.c
+++ b/drivers/clk/uniphier/clk-uniphier-core.c
@@ -79,7 +79,7 @@ static int uniphier_clk_probe(struct platform_device *pdev)
79 hw_data->num = clk_num; 79 hw_data->num = clk_num;
80 80
81 /* avoid returning NULL for unused idx */ 81 /* avoid returning NULL for unused idx */
82 for (; clk_num >= 0; clk_num--) 82 while (--clk_num >= 0)
83 hw_data->hws[clk_num] = ERR_PTR(-EINVAL); 83 hw_data->hws[clk_num] = ERR_PTR(-EINVAL);
84 84
85 for (p = data; p->name; p++) { 85 for (p = data; p->name; p++) {
@@ -111,6 +111,10 @@ static int uniphier_clk_remove(struct platform_device *pdev)
111static const struct of_device_id uniphier_clk_match[] = { 111static const struct of_device_id uniphier_clk_match[] = {
112 /* System clock */ 112 /* System clock */
113 { 113 {
114 .compatible = "socionext,uniphier-sld3-clock",
115 .data = uniphier_sld3_sys_clk_data,
116 },
117 {
114 .compatible = "socionext,uniphier-ld4-clock", 118 .compatible = "socionext,uniphier-ld4-clock",
115 .data = uniphier_ld4_sys_clk_data, 119 .data = uniphier_ld4_sys_clk_data,
116 }, 120 },
@@ -138,7 +142,7 @@ static const struct of_device_id uniphier_clk_match[] = {
138 .compatible = "socionext,uniphier-ld20-clock", 142 .compatible = "socionext,uniphier-ld20-clock",
139 .data = uniphier_ld20_sys_clk_data, 143 .data = uniphier_ld20_sys_clk_data,
140 }, 144 },
141 /* Media I/O clock */ 145 /* Media I/O clock, SD clock */
142 { 146 {
143 .compatible = "socionext,uniphier-sld3-mio-clock", 147 .compatible = "socionext,uniphier-sld3-mio-clock",
144 .data = uniphier_sld3_mio_clk_data, 148 .data = uniphier_sld3_mio_clk_data,
@@ -156,20 +160,20 @@ static const struct of_device_id uniphier_clk_match[] = {
156 .data = uniphier_sld3_mio_clk_data, 160 .data = uniphier_sld3_mio_clk_data,
157 }, 161 },
158 { 162 {
159 .compatible = "socionext,uniphier-pro5-mio-clock", 163 .compatible = "socionext,uniphier-pro5-sd-clock",
160 .data = uniphier_pro5_mio_clk_data, 164 .data = uniphier_pro5_sd_clk_data,
161 }, 165 },
162 { 166 {
163 .compatible = "socionext,uniphier-pxs2-mio-clock", 167 .compatible = "socionext,uniphier-pxs2-sd-clock",
164 .data = uniphier_pro5_mio_clk_data, 168 .data = uniphier_pro5_sd_clk_data,
165 }, 169 },
166 { 170 {
167 .compatible = "socionext,uniphier-ld11-mio-clock", 171 .compatible = "socionext,uniphier-ld11-mio-clock",
168 .data = uniphier_sld3_mio_clk_data, 172 .data = uniphier_sld3_mio_clk_data,
169 }, 173 },
170 { 174 {
171 .compatible = "socionext,uniphier-ld20-mio-clock", 175 .compatible = "socionext,uniphier-ld20-sd-clock",
172 .data = uniphier_pro5_mio_clk_data, 176 .data = uniphier_pro5_sd_clk_data,
173 }, 177 },
174 /* Peripheral clock */ 178 /* Peripheral clock */
175 { 179 {
diff --git a/drivers/clk/uniphier/clk-uniphier-mio.c b/drivers/clk/uniphier/clk-uniphier-mio.c
index 6aa7ec768d0b..218d20f099ce 100644
--- a/drivers/clk/uniphier/clk-uniphier-mio.c
+++ b/drivers/clk/uniphier/clk-uniphier-mio.c
@@ -93,7 +93,7 @@ const struct uniphier_clk_data uniphier_sld3_mio_clk_data[] = {
93 { /* sentinel */ } 93 { /* sentinel */ }
94}; 94};
95 95
96const struct uniphier_clk_data uniphier_pro5_mio_clk_data[] = { 96const struct uniphier_clk_data uniphier_pro5_sd_clk_data[] = {
97 UNIPHIER_MIO_CLK_SD_FIXED, 97 UNIPHIER_MIO_CLK_SD_FIXED,
98 UNIPHIER_MIO_CLK_SD(0, 0), 98 UNIPHIER_MIO_CLK_SD(0, 0),
99 UNIPHIER_MIO_CLK_SD(1, 1), 99 UNIPHIER_MIO_CLK_SD(1, 1),
diff --git a/drivers/clk/uniphier/clk-uniphier-mux.c b/drivers/clk/uniphier/clk-uniphier-mux.c
index 15a2f2cbe0d9..2c243a894f3b 100644
--- a/drivers/clk/uniphier/clk-uniphier-mux.c
+++ b/drivers/clk/uniphier/clk-uniphier-mux.c
@@ -42,7 +42,7 @@ static u8 uniphier_clk_mux_get_parent(struct clk_hw *hw)
42 struct uniphier_clk_mux *mux = to_uniphier_clk_mux(hw); 42 struct uniphier_clk_mux *mux = to_uniphier_clk_mux(hw);
43 int num_parents = clk_hw_get_num_parents(hw); 43 int num_parents = clk_hw_get_num_parents(hw);
44 int ret; 44 int ret;
45 u32 val; 45 unsigned int val;
46 u8 i; 46 u8 i;
47 47
48 ret = regmap_read(mux->regmap, mux->reg, &val); 48 ret = regmap_read(mux->regmap, mux->reg, &val);
diff --git a/drivers/clk/uniphier/clk-uniphier.h b/drivers/clk/uniphier/clk-uniphier.h
index 3ae184062388..0244dba1f4cf 100644
--- a/drivers/clk/uniphier/clk-uniphier.h
+++ b/drivers/clk/uniphier/clk-uniphier.h
@@ -115,7 +115,7 @@ extern const struct uniphier_clk_data uniphier_pxs2_sys_clk_data[];
115extern const struct uniphier_clk_data uniphier_ld11_sys_clk_data[]; 115extern const struct uniphier_clk_data uniphier_ld11_sys_clk_data[];
116extern const struct uniphier_clk_data uniphier_ld20_sys_clk_data[]; 116extern const struct uniphier_clk_data uniphier_ld20_sys_clk_data[];
117extern const struct uniphier_clk_data uniphier_sld3_mio_clk_data[]; 117extern const struct uniphier_clk_data uniphier_sld3_mio_clk_data[];
118extern const struct uniphier_clk_data uniphier_pro5_mio_clk_data[]; 118extern const struct uniphier_clk_data uniphier_pro5_sd_clk_data[];
119extern const struct uniphier_clk_data uniphier_ld4_peri_clk_data[]; 119extern const struct uniphier_clk_data uniphier_ld4_peri_clk_data[];
120extern const struct uniphier_clk_data uniphier_pro4_peri_clk_data[]; 120extern const struct uniphier_clk_data uniphier_pro4_peri_clk_data[];
121 121
diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig
index 245190839359..e2c6e43cf8ca 100644
--- a/drivers/clocksource/Kconfig
+++ b/drivers/clocksource/Kconfig
@@ -417,6 +417,16 @@ config SYS_SUPPORTS_SH_TMU
417config SYS_SUPPORTS_EM_STI 417config SYS_SUPPORTS_EM_STI
418 bool 418 bool
419 419
420config CLKSRC_JCORE_PIT
421 bool "J-Core PIT timer driver" if COMPILE_TEST
422 depends on OF
423 depends on GENERIC_CLOCKEVENTS
424 depends on HAS_IOMEM
425 select CLKSRC_MMIO
426 help
427 This enables build of clocksource and clockevent driver for
428 the integrated PIT in the J-Core synthesizable, open source SoC.
429
420config SH_TIMER_CMT 430config SH_TIMER_CMT
421 bool "Renesas CMT timer driver" if COMPILE_TEST 431 bool "Renesas CMT timer driver" if COMPILE_TEST
422 depends on GENERIC_CLOCKEVENTS 432 depends on GENERIC_CLOCKEVENTS
diff --git a/drivers/clocksource/Makefile b/drivers/clocksource/Makefile
index fd9d6df0bbc0..cf87f407f1ad 100644
--- a/drivers/clocksource/Makefile
+++ b/drivers/clocksource/Makefile
@@ -5,6 +5,7 @@ obj-$(CONFIG_ATMEL_TCB_CLKSRC) += tcb_clksrc.o
5obj-$(CONFIG_X86_PM_TIMER) += acpi_pm.o 5obj-$(CONFIG_X86_PM_TIMER) += acpi_pm.o
6obj-$(CONFIG_SCx200HR_TIMER) += scx200_hrt.o 6obj-$(CONFIG_SCx200HR_TIMER) += scx200_hrt.o
7obj-$(CONFIG_CS5535_CLOCK_EVENT_SRC) += cs5535-clockevt.o 7obj-$(CONFIG_CS5535_CLOCK_EVENT_SRC) += cs5535-clockevt.o
8obj-$(CONFIG_CLKSRC_JCORE_PIT) += jcore-pit.o
8obj-$(CONFIG_SH_TIMER_CMT) += sh_cmt.o 9obj-$(CONFIG_SH_TIMER_CMT) += sh_cmt.o
9obj-$(CONFIG_SH_TIMER_MTU2) += sh_mtu2.o 10obj-$(CONFIG_SH_TIMER_MTU2) += sh_mtu2.o
10obj-$(CONFIG_SH_TIMER_TMU) += sh_tmu.o 11obj-$(CONFIG_SH_TIMER_TMU) += sh_tmu.o
diff --git a/drivers/clocksource/jcore-pit.c b/drivers/clocksource/jcore-pit.c
new file mode 100644
index 000000000000..54e1665aa03c
--- /dev/null
+++ b/drivers/clocksource/jcore-pit.c
@@ -0,0 +1,249 @@
1/*
2 * J-Core SoC PIT/clocksource driver
3 *
4 * Copyright (C) 2015-2016 Smart Energy Instruments, Inc.
5 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file "COPYING" in the main directory of this archive
8 * for more details.
9 */
10
11#include <linux/kernel.h>
12#include <linux/slab.h>
13#include <linux/interrupt.h>
14#include <linux/clockchips.h>
15#include <linux/clocksource.h>
16#include <linux/sched_clock.h>
17#include <linux/cpu.h>
18#include <linux/cpuhotplug.h>
19#include <linux/of_address.h>
20#include <linux/of_irq.h>
21
22#define PIT_IRQ_SHIFT 12
23#define PIT_PRIO_SHIFT 20
24#define PIT_ENABLE_SHIFT 26
25#define PIT_PRIO_MASK 0xf
26
27#define REG_PITEN 0x00
28#define REG_THROT 0x10
29#define REG_COUNT 0x14
30#define REG_BUSPD 0x18
31#define REG_SECHI 0x20
32#define REG_SECLO 0x24
33#define REG_NSEC 0x28
34
35struct jcore_pit {
36 struct clock_event_device ced;
37 void __iomem *base;
38 unsigned long periodic_delta;
39 u32 enable_val;
40};
41
42static void __iomem *jcore_pit_base;
43static struct jcore_pit __percpu *jcore_pit_percpu;
44
45static notrace u64 jcore_sched_clock_read(void)
46{
47 u32 seclo, nsec, seclo0;
48 __iomem void *base = jcore_pit_base;
49
50 seclo = readl(base + REG_SECLO);
51 do {
52 seclo0 = seclo;
53 nsec = readl(base + REG_NSEC);
54 seclo = readl(base + REG_SECLO);
55 } while (seclo0 != seclo);
56
57 return seclo * NSEC_PER_SEC + nsec;
58}
59
60static cycle_t jcore_clocksource_read(struct clocksource *cs)
61{
62 return jcore_sched_clock_read();
63}
64
65static int jcore_pit_disable(struct jcore_pit *pit)
66{
67 writel(0, pit->base + REG_PITEN);
68 return 0;
69}
70
71static int jcore_pit_set(unsigned long delta, struct jcore_pit *pit)
72{
73 jcore_pit_disable(pit);
74 writel(delta, pit->base + REG_THROT);
75 writel(pit->enable_val, pit->base + REG_PITEN);
76 return 0;
77}
78
79static int jcore_pit_set_state_shutdown(struct clock_event_device *ced)
80{
81 struct jcore_pit *pit = container_of(ced, struct jcore_pit, ced);
82
83 return jcore_pit_disable(pit);
84}
85
86static int jcore_pit_set_state_oneshot(struct clock_event_device *ced)
87{
88 struct jcore_pit *pit = container_of(ced, struct jcore_pit, ced);
89
90 return jcore_pit_disable(pit);
91}
92
93static int jcore_pit_set_state_periodic(struct clock_event_device *ced)
94{
95 struct jcore_pit *pit = container_of(ced, struct jcore_pit, ced);
96
97 return jcore_pit_set(pit->periodic_delta, pit);
98}
99
100static int jcore_pit_set_next_event(unsigned long delta,
101 struct clock_event_device *ced)
102{
103 struct jcore_pit *pit = container_of(ced, struct jcore_pit, ced);
104
105 return jcore_pit_set(delta, pit);
106}
107
108static int jcore_pit_local_init(unsigned cpu)
109{
110 struct jcore_pit *pit = this_cpu_ptr(jcore_pit_percpu);
111 unsigned buspd, freq;
112
113 pr_info("Local J-Core PIT init on cpu %u\n", cpu);
114
115 buspd = readl(pit->base + REG_BUSPD);
116 freq = DIV_ROUND_CLOSEST(NSEC_PER_SEC, buspd);
117 pit->periodic_delta = DIV_ROUND_CLOSEST(NSEC_PER_SEC, HZ * buspd);
118
119 clockevents_config_and_register(&pit->ced, freq, 1, ULONG_MAX);
120
121 return 0;
122}
123
124static irqreturn_t jcore_timer_interrupt(int irq, void *dev_id)
125{
126 struct jcore_pit *pit = this_cpu_ptr(dev_id);
127
128 if (clockevent_state_oneshot(&pit->ced))
129 jcore_pit_disable(pit);
130
131 pit->ced.event_handler(&pit->ced);
132
133 return IRQ_HANDLED;
134}
135
136static int __init jcore_pit_init(struct device_node *node)
137{
138 int err;
139 unsigned pit_irq, cpu;
140 unsigned long hwirq;
141 u32 irqprio, enable_val;
142
143 jcore_pit_base = of_iomap(node, 0);
144 if (!jcore_pit_base) {
145 pr_err("Error: Cannot map base address for J-Core PIT\n");
146 return -ENXIO;
147 }
148
149 pit_irq = irq_of_parse_and_map(node, 0);
150 if (!pit_irq) {
151 pr_err("Error: J-Core PIT has no IRQ\n");
152 return -ENXIO;
153 }
154
155 pr_info("Initializing J-Core PIT at %p IRQ %d\n",
156 jcore_pit_base, pit_irq);
157
158 err = clocksource_mmio_init(jcore_pit_base, "jcore_pit_cs",
159 NSEC_PER_SEC, 400, 32,
160 jcore_clocksource_read);
161 if (err) {
162 pr_err("Error registering clocksource device: %d\n", err);
163 return err;
164 }
165
166 sched_clock_register(jcore_sched_clock_read, 32, NSEC_PER_SEC);
167
168 jcore_pit_percpu = alloc_percpu(struct jcore_pit);
169 if (!jcore_pit_percpu) {
170 pr_err("Failed to allocate memory for clock event device\n");
171 return -ENOMEM;
172 }
173
174 err = request_irq(pit_irq, jcore_timer_interrupt,
175 IRQF_TIMER | IRQF_PERCPU,
176 "jcore_pit", jcore_pit_percpu);
177 if (err) {
178 pr_err("pit irq request failed: %d\n", err);
179 free_percpu(jcore_pit_percpu);
180 return err;
181 }
182
183 /*
184 * The J-Core PIT is not hard-wired to a particular IRQ, but
185 * integrated with the interrupt controller such that the IRQ it
186 * generates is programmable, as follows:
187 *
188 * The bit layout of the PIT enable register is:
189 *
190 * .....e..ppppiiiiiiii............
191 *
192 * where the .'s indicate unrelated/unused bits, e is enable,
193 * p is priority, and i is hard irq number.
194 *
195 * For the PIT included in AIC1 (obsolete but still in use),
196 * any hard irq (trap number) can be programmed via the 8
197 * iiiiiiii bits, and a priority (0-15) is programmable
198 * separately in the pppp bits.
199 *
200 * For the PIT included in AIC2 (current), the programming
201 * interface is equivalent modulo interrupt mapping. This is
202 * why a different compatible tag was not used. However only
203 * traps 64-127 (the ones actually intended to be used for
204 * interrupts, rather than syscalls/exceptions/etc.) can be
205 * programmed (the high 2 bits of i are ignored) and the
206 * priority pppp is <<2'd and or'd onto the irq number. This
207 * choice seems to have been made on the hardware engineering
208 * side under an assumption that preserving old AIC1 priority
209 * mappings was important. Future models will likely ignore
210 * the pppp field.
211 */
212 hwirq = irq_get_irq_data(pit_irq)->hwirq;
213 irqprio = (hwirq >> 2) & PIT_PRIO_MASK;
214 enable_val = (1U << PIT_ENABLE_SHIFT)
215 | (hwirq << PIT_IRQ_SHIFT)
216 | (irqprio << PIT_PRIO_SHIFT);
217
218 for_each_present_cpu(cpu) {
219 struct jcore_pit *pit = per_cpu_ptr(jcore_pit_percpu, cpu);
220
221 pit->base = of_iomap(node, cpu);
222 if (!pit->base) {
223 pr_err("Unable to map PIT for cpu %u\n", cpu);
224 continue;
225 }
226
227 pit->ced.name = "jcore_pit";
228 pit->ced.features = CLOCK_EVT_FEAT_PERIODIC
229 | CLOCK_EVT_FEAT_ONESHOT
230 | CLOCK_EVT_FEAT_PERCPU;
231 pit->ced.cpumask = cpumask_of(cpu);
232 pit->ced.rating = 400;
233 pit->ced.irq = pit_irq;
234 pit->ced.set_state_shutdown = jcore_pit_set_state_shutdown;
235 pit->ced.set_state_periodic = jcore_pit_set_state_periodic;
236 pit->ced.set_state_oneshot = jcore_pit_set_state_oneshot;
237 pit->ced.set_next_event = jcore_pit_set_next_event;
238
239 pit->enable_val = enable_val;
240 }
241
242 cpuhp_setup_state(CPUHP_AP_JCORE_TIMER_STARTING,
243 "AP_JCORE_TIMER_STARTING",
244 jcore_pit_local_init, NULL);
245
246 return 0;
247}
248
249CLOCKSOURCE_OF_DECLARE(jcore_pit, "jcore,pit", jcore_pit_init);
diff --git a/drivers/clocksource/timer-sun5i.c b/drivers/clocksource/timer-sun5i.c
index c184eb84101e..4f87f3e76d83 100644
--- a/drivers/clocksource/timer-sun5i.c
+++ b/drivers/clocksource/timer-sun5i.c
@@ -152,6 +152,13 @@ static irqreturn_t sun5i_timer_interrupt(int irq, void *dev_id)
152 return IRQ_HANDLED; 152 return IRQ_HANDLED;
153} 153}
154 154
155static cycle_t sun5i_clksrc_read(struct clocksource *clksrc)
156{
157 struct sun5i_timer_clksrc *cs = to_sun5i_timer_clksrc(clksrc);
158
159 return ~readl(cs->timer.base + TIMER_CNTVAL_LO_REG(1));
160}
161
155static int sun5i_rate_cb_clksrc(struct notifier_block *nb, 162static int sun5i_rate_cb_clksrc(struct notifier_block *nb,
156 unsigned long event, void *data) 163 unsigned long event, void *data)
157{ 164{
@@ -210,8 +217,13 @@ static int __init sun5i_setup_clocksource(struct device_node *node,
210 writel(TIMER_CTL_ENABLE | TIMER_CTL_RELOAD, 217 writel(TIMER_CTL_ENABLE | TIMER_CTL_RELOAD,
211 base + TIMER_CTL_REG(1)); 218 base + TIMER_CTL_REG(1));
212 219
213 ret = clocksource_mmio_init(base + TIMER_CNTVAL_LO_REG(1), node->name, 220 cs->clksrc.name = node->name;
214 rate, 340, 32, clocksource_mmio_readl_down); 221 cs->clksrc.rating = 340;
222 cs->clksrc.read = sun5i_clksrc_read;
223 cs->clksrc.mask = CLOCKSOURCE_MASK(32);
224 cs->clksrc.flags = CLOCK_SOURCE_IS_CONTINUOUS;
225
226 ret = clocksource_register_hz(&cs->clksrc, rate);
215 if (ret) { 227 if (ret) {
216 pr_err("Couldn't register clock source.\n"); 228 pr_err("Couldn't register clock source.\n");
217 goto err_remove_notifier; 229 goto err_remove_notifier;
diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
index f535f8123258..4737520ec823 100644
--- a/drivers/cpufreq/intel_pstate.c
+++ b/drivers/cpufreq/intel_pstate.c
@@ -179,6 +179,7 @@ struct _pid {
179/** 179/**
180 * struct cpudata - Per CPU instance data storage 180 * struct cpudata - Per CPU instance data storage
181 * @cpu: CPU number for this instance data 181 * @cpu: CPU number for this instance data
182 * @policy: CPUFreq policy value
182 * @update_util: CPUFreq utility callback information 183 * @update_util: CPUFreq utility callback information
183 * @update_util_set: CPUFreq utility callback is set 184 * @update_util_set: CPUFreq utility callback is set
184 * @iowait_boost: iowait-related boost fraction 185 * @iowait_boost: iowait-related boost fraction
@@ -201,6 +202,7 @@ struct _pid {
201struct cpudata { 202struct cpudata {
202 int cpu; 203 int cpu;
203 204
205 unsigned int policy;
204 struct update_util_data update_util; 206 struct update_util_data update_util;
205 bool update_util_set; 207 bool update_util_set;
206 208
@@ -1142,10 +1144,8 @@ static void intel_pstate_get_min_max(struct cpudata *cpu, int *min, int *max)
1142 *min = clamp_t(int, min_perf, cpu->pstate.min_pstate, max_perf); 1144 *min = clamp_t(int, min_perf, cpu->pstate.min_pstate, max_perf);
1143} 1145}
1144 1146
1145static void intel_pstate_set_min_pstate(struct cpudata *cpu) 1147static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate)
1146{ 1148{
1147 int pstate = cpu->pstate.min_pstate;
1148
1149 trace_cpu_frequency(pstate * cpu->pstate.scaling, cpu->cpu); 1149 trace_cpu_frequency(pstate * cpu->pstate.scaling, cpu->cpu);
1150 cpu->pstate.current_pstate = pstate; 1150 cpu->pstate.current_pstate = pstate;
1151 /* 1151 /*
@@ -1157,6 +1157,20 @@ static void intel_pstate_set_min_pstate(struct cpudata *cpu)
1157 pstate_funcs.get_val(cpu, pstate)); 1157 pstate_funcs.get_val(cpu, pstate));
1158} 1158}
1159 1159
1160static void intel_pstate_set_min_pstate(struct cpudata *cpu)
1161{
1162 intel_pstate_set_pstate(cpu, cpu->pstate.min_pstate);
1163}
1164
1165static void intel_pstate_max_within_limits(struct cpudata *cpu)
1166{
1167 int min_pstate, max_pstate;
1168
1169 update_turbo_state();
1170 intel_pstate_get_min_max(cpu, &min_pstate, &max_pstate);
1171 intel_pstate_set_pstate(cpu, max_pstate);
1172}
1173
1160static void intel_pstate_get_cpu_pstates(struct cpudata *cpu) 1174static void intel_pstate_get_cpu_pstates(struct cpudata *cpu)
1161{ 1175{
1162 cpu->pstate.min_pstate = pstate_funcs.get_min(); 1176 cpu->pstate.min_pstate = pstate_funcs.get_min();
@@ -1325,7 +1339,8 @@ static inline void intel_pstate_adjust_busy_pstate(struct cpudata *cpu)
1325 1339
1326 from = cpu->pstate.current_pstate; 1340 from = cpu->pstate.current_pstate;
1327 1341
1328 target_pstate = pstate_funcs.get_target_pstate(cpu); 1342 target_pstate = cpu->policy == CPUFREQ_POLICY_PERFORMANCE ?
1343 cpu->pstate.turbo_pstate : pstate_funcs.get_target_pstate(cpu);
1329 1344
1330 intel_pstate_update_pstate(cpu, target_pstate); 1345 intel_pstate_update_pstate(cpu, target_pstate);
1331 1346
@@ -1491,7 +1506,9 @@ static int intel_pstate_set_policy(struct cpufreq_policy *policy)
1491 pr_debug("set_policy cpuinfo.max %u policy->max %u\n", 1506 pr_debug("set_policy cpuinfo.max %u policy->max %u\n",
1492 policy->cpuinfo.max_freq, policy->max); 1507 policy->cpuinfo.max_freq, policy->max);
1493 1508
1494 cpu = all_cpu_data[0]; 1509 cpu = all_cpu_data[policy->cpu];
1510 cpu->policy = policy->policy;
1511
1495 if (cpu->pstate.max_pstate_physical > cpu->pstate.max_pstate && 1512 if (cpu->pstate.max_pstate_physical > cpu->pstate.max_pstate &&
1496 policy->max < policy->cpuinfo.max_freq && 1513 policy->max < policy->cpuinfo.max_freq &&
1497 policy->max > cpu->pstate.max_pstate * cpu->pstate.scaling) { 1514 policy->max > cpu->pstate.max_pstate * cpu->pstate.scaling) {
@@ -1499,7 +1516,7 @@ static int intel_pstate_set_policy(struct cpufreq_policy *policy)
1499 policy->max = policy->cpuinfo.max_freq; 1516 policy->max = policy->cpuinfo.max_freq;
1500 } 1517 }
1501 1518
1502 if (policy->policy == CPUFREQ_POLICY_PERFORMANCE) { 1519 if (cpu->policy == CPUFREQ_POLICY_PERFORMANCE) {
1503 limits = &performance_limits; 1520 limits = &performance_limits;
1504 if (policy->max >= policy->cpuinfo.max_freq) { 1521 if (policy->max >= policy->cpuinfo.max_freq) {
1505 pr_debug("set performance\n"); 1522 pr_debug("set performance\n");
@@ -1535,6 +1552,15 @@ static int intel_pstate_set_policy(struct cpufreq_policy *policy)
1535 limits->max_perf = round_up(limits->max_perf, FRAC_BITS); 1552 limits->max_perf = round_up(limits->max_perf, FRAC_BITS);
1536 1553
1537 out: 1554 out:
1555 if (cpu->policy == CPUFREQ_POLICY_PERFORMANCE) {
1556 /*
1557 * NOHZ_FULL CPUs need this as the governor callback may not
1558 * be invoked on them.
1559 */
1560 intel_pstate_clear_update_util_hook(policy->cpu);
1561 intel_pstate_max_within_limits(cpu);
1562 }
1563
1538 intel_pstate_set_update_util_hook(policy->cpu); 1564 intel_pstate_set_update_util_hook(policy->cpu);
1539 1565
1540 intel_pstate_hwp_set_policy(policy); 1566 intel_pstate_hwp_set_policy(policy);
diff --git a/drivers/crypto/caam/caamalg.c b/drivers/crypto/caam/caamalg.c
index 156aad167cd6..954a64c7757b 100644
--- a/drivers/crypto/caam/caamalg.c
+++ b/drivers/crypto/caam/caamalg.c
@@ -137,7 +137,7 @@ static void dbg_dump_sg(const char *level, const char *prefix_str,
137 } 137 }
138 138
139 buf = it_page + it->offset; 139 buf = it_page + it->offset;
140 len = min(tlen, it->length); 140 len = min_t(size_t, tlen, it->length);
141 print_hex_dump(level, prefix_str, prefix_type, rowsize, 141 print_hex_dump(level, prefix_str, prefix_type, rowsize,
142 groupsize, buf, len, ascii); 142 groupsize, buf, len, ascii);
143 tlen -= len; 143 tlen -= len;
@@ -4583,6 +4583,15 @@ static int __init caam_algapi_init(void)
4583 if (!aes_inst && (alg_sel == OP_ALG_ALGSEL_AES)) 4583 if (!aes_inst && (alg_sel == OP_ALG_ALGSEL_AES))
4584 continue; 4584 continue;
4585 4585
4586 /*
4587 * Check support for AES modes not available
4588 * on LP devices.
4589 */
4590 if ((cha_vid & CHA_ID_LS_AES_MASK) == CHA_ID_LS_AES_LP)
4591 if ((alg->class1_alg_type & OP_ALG_AAI_MASK) ==
4592 OP_ALG_AAI_XTS)
4593 continue;
4594
4586 t_alg = caam_alg_alloc(alg); 4595 t_alg = caam_alg_alloc(alg);
4587 if (IS_ERR(t_alg)) { 4596 if (IS_ERR(t_alg)) {
4588 err = PTR_ERR(t_alg); 4597 err = PTR_ERR(t_alg);
diff --git a/drivers/crypto/caam/ctrl.c b/drivers/crypto/caam/ctrl.c
index 72ff19658985..e483b78c6343 100644
--- a/drivers/crypto/caam/ctrl.c
+++ b/drivers/crypto/caam/ctrl.c
@@ -558,8 +558,9 @@ static int caam_probe(struct platform_device *pdev)
558 * Enable DECO watchdogs and, if this is a PHYS_ADDR_T_64BIT kernel, 558 * Enable DECO watchdogs and, if this is a PHYS_ADDR_T_64BIT kernel,
559 * long pointers in master configuration register 559 * long pointers in master configuration register
560 */ 560 */
561 clrsetbits_32(&ctrl->mcr, MCFGR_AWCACHE_MASK, MCFGR_AWCACHE_CACH | 561 clrsetbits_32(&ctrl->mcr, MCFGR_AWCACHE_MASK | MCFGR_LONG_PTR,
562 MCFGR_AWCACHE_BUFF | MCFGR_WDENABLE | MCFGR_LARGE_BURST | 562 MCFGR_AWCACHE_CACH | MCFGR_AWCACHE_BUFF |
563 MCFGR_WDENABLE | MCFGR_LARGE_BURST |
563 (sizeof(dma_addr_t) == sizeof(u64) ? MCFGR_LONG_PTR : 0)); 564 (sizeof(dma_addr_t) == sizeof(u64) ? MCFGR_LONG_PTR : 0));
564 565
565 /* 566 /*
diff --git a/drivers/crypto/chelsio/chcr_algo.h b/drivers/crypto/chelsio/chcr_algo.h
index ec64fbcdeb49..199b0bb69b89 100644
--- a/drivers/crypto/chelsio/chcr_algo.h
+++ b/drivers/crypto/chelsio/chcr_algo.h
@@ -422,7 +422,7 @@ static inline void get_aes_decrypt_key(unsigned char *dec_key,
422{ 422{
423 u32 temp; 423 u32 temp;
424 u32 w_ring[MAX_NK]; 424 u32 w_ring[MAX_NK];
425 int i, j, k = 0; 425 int i, j, k;
426 u8 nr, nk; 426 u8 nr, nk;
427 427
428 switch (keylength) { 428 switch (keylength) {
@@ -460,6 +460,7 @@ static inline void get_aes_decrypt_key(unsigned char *dec_key,
460 temp = w_ring[i % nk]; 460 temp = w_ring[i % nk];
461 i++; 461 i++;
462 } 462 }
463 i--;
463 for (k = 0, j = i % nk; k < nk; k++) { 464 for (k = 0, j = i % nk; k < nk; k++) {
464 *((u32 *)dec_key + k) = htonl(w_ring[j]); 465 *((u32 *)dec_key + k) = htonl(w_ring[j]);
465 j--; 466 j--;
diff --git a/drivers/crypto/marvell/hash.c b/drivers/crypto/marvell/hash.c
index 9f284682c091..77712b375b84 100644
--- a/drivers/crypto/marvell/hash.c
+++ b/drivers/crypto/marvell/hash.c
@@ -168,12 +168,11 @@ static void mv_cesa_ahash_std_step(struct ahash_request *req)
168 mv_cesa_adjust_op(engine, &creq->op_tmpl); 168 mv_cesa_adjust_op(engine, &creq->op_tmpl);
169 memcpy_toio(engine->sram, &creq->op_tmpl, sizeof(creq->op_tmpl)); 169 memcpy_toio(engine->sram, &creq->op_tmpl, sizeof(creq->op_tmpl));
170 170
171 digsize = crypto_ahash_digestsize(crypto_ahash_reqtfm(req)); 171 if (!sreq->offset) {
172 for (i = 0; i < digsize / 4; i++) 172 digsize = crypto_ahash_digestsize(crypto_ahash_reqtfm(req));
173 writel_relaxed(creq->state[i], engine->regs + CESA_IVDIG(i)); 173 for (i = 0; i < digsize / 4; i++)
174 174 writel_relaxed(creq->state[i], engine->regs + CESA_IVDIG(i));
175 mv_cesa_adjust_op(engine, &creq->op_tmpl); 175 }
176 memcpy_toio(engine->sram, &creq->op_tmpl, sizeof(creq->op_tmpl));
177 176
178 if (creq->cache_ptr) 177 if (creq->cache_ptr)
179 memcpy_toio(engine->sram + CESA_SA_DATA_SRAM_OFFSET, 178 memcpy_toio(engine->sram + CESA_SA_DATA_SRAM_OFFSET,
diff --git a/drivers/dax/Kconfig b/drivers/dax/Kconfig
index daadd20aa936..3e2ab3b14eea 100644
--- a/drivers/dax/Kconfig
+++ b/drivers/dax/Kconfig
@@ -14,7 +14,7 @@ if DEV_DAX
14 14
15config DEV_DAX_PMEM 15config DEV_DAX_PMEM
16 tristate "PMEM DAX: direct access to persistent memory" 16 tristate "PMEM DAX: direct access to persistent memory"
17 depends on NVDIMM_DAX 17 depends on LIBNVDIMM && NVDIMM_DAX
18 default DEV_DAX 18 default DEV_DAX
19 help 19 help
20 Support raw access to persistent memory. Note that this 20 Support raw access to persistent memory. Note that this
diff --git a/drivers/dax/dax.c b/drivers/dax/dax.c
index 0e499bfca41c..286447a83dab 100644
--- a/drivers/dax/dax.c
+++ b/drivers/dax/dax.c
@@ -270,8 +270,8 @@ static int check_vma(struct dax_dev *dax_dev, struct vm_area_struct *vma,
270 if (!dax_dev->alive) 270 if (!dax_dev->alive)
271 return -ENXIO; 271 return -ENXIO;
272 272
273 /* prevent private / writable mappings from being established */ 273 /* prevent private mappings from being established */
274 if ((vma->vm_flags & (VM_NORESERVE|VM_SHARED|VM_WRITE)) == VM_WRITE) { 274 if ((vma->vm_flags & VM_MAYSHARE) != VM_MAYSHARE) {
275 dev_info(dev, "%s: %s: fail, attempted private mapping\n", 275 dev_info(dev, "%s: %s: fail, attempted private mapping\n",
276 current->comm, func); 276 current->comm, func);
277 return -EINVAL; 277 return -EINVAL;
diff --git a/drivers/dax/pmem.c b/drivers/dax/pmem.c
index 9630d8837ba9..73c6ce93a0d9 100644
--- a/drivers/dax/pmem.c
+++ b/drivers/dax/pmem.c
@@ -44,7 +44,6 @@ static void dax_pmem_percpu_exit(void *data)
44 44
45 dev_dbg(dax_pmem->dev, "%s\n", __func__); 45 dev_dbg(dax_pmem->dev, "%s\n", __func__);
46 percpu_ref_exit(ref); 46 percpu_ref_exit(ref);
47 wait_for_completion(&dax_pmem->cmp);
48} 47}
49 48
50static void dax_pmem_percpu_kill(void *data) 49static void dax_pmem_percpu_kill(void *data)
@@ -54,6 +53,7 @@ static void dax_pmem_percpu_kill(void *data)
54 53
55 dev_dbg(dax_pmem->dev, "%s\n", __func__); 54 dev_dbg(dax_pmem->dev, "%s\n", __func__);
56 percpu_ref_kill(ref); 55 percpu_ref_kill(ref);
56 wait_for_completion(&dax_pmem->cmp);
57} 57}
58 58
59static int dax_pmem_probe(struct device *dev) 59static int dax_pmem_probe(struct device *dev)
@@ -78,7 +78,9 @@ static int dax_pmem_probe(struct device *dev)
78 nsio = to_nd_namespace_io(&ndns->dev); 78 nsio = to_nd_namespace_io(&ndns->dev);
79 79
80 /* parse the 'pfn' info block via ->rw_bytes */ 80 /* parse the 'pfn' info block via ->rw_bytes */
81 devm_nsio_enable(dev, nsio); 81 rc = devm_nsio_enable(dev, nsio);
82 if (rc)
83 return rc;
82 altmap = nvdimm_setup_pfn(nd_pfn, &res, &__altmap); 84 altmap = nvdimm_setup_pfn(nd_pfn, &res, &__altmap);
83 if (IS_ERR(altmap)) 85 if (IS_ERR(altmap))
84 return PTR_ERR(altmap); 86 return PTR_ERR(altmap);
diff --git a/drivers/dma/Kconfig b/drivers/dma/Kconfig
index af63a6bcf564..141aefbe37ec 100644
--- a/drivers/dma/Kconfig
+++ b/drivers/dma/Kconfig
@@ -306,6 +306,7 @@ config MMP_TDMA
306 depends on ARCH_MMP || COMPILE_TEST 306 depends on ARCH_MMP || COMPILE_TEST
307 select DMA_ENGINE 307 select DMA_ENGINE
308 select MMP_SRAM if ARCH_MMP 308 select MMP_SRAM if ARCH_MMP
309 select GENERIC_ALLOCATOR
309 help 310 help
310 Support the MMP Two-Channel DMA engine. 311 Support the MMP Two-Channel DMA engine.
311 This engine used for MMP Audio DMA and pxa910 SQU. 312 This engine used for MMP Audio DMA and pxa910 SQU.
diff --git a/drivers/dma/cppi41.c b/drivers/dma/cppi41.c
index bac5f023013b..d5ba43a87a68 100644
--- a/drivers/dma/cppi41.c
+++ b/drivers/dma/cppi41.c
@@ -317,6 +317,12 @@ static irqreturn_t cppi41_irq(int irq, void *data)
317 317
318 while (val) { 318 while (val) {
319 u32 desc, len; 319 u32 desc, len;
320 int error;
321
322 error = pm_runtime_get(cdd->ddev.dev);
323 if (error < 0)
324 dev_err(cdd->ddev.dev, "%s pm runtime get: %i\n",
325 __func__, error);
320 326
321 q_num = __fls(val); 327 q_num = __fls(val);
322 val &= ~(1 << q_num); 328 val &= ~(1 << q_num);
@@ -338,7 +344,6 @@ static irqreturn_t cppi41_irq(int irq, void *data)
338 dma_cookie_complete(&c->txd); 344 dma_cookie_complete(&c->txd);
339 dmaengine_desc_get_callback_invoke(&c->txd, NULL); 345 dmaengine_desc_get_callback_invoke(&c->txd, NULL);
340 346
341 /* Paired with cppi41_dma_issue_pending */
342 pm_runtime_mark_last_busy(cdd->ddev.dev); 347 pm_runtime_mark_last_busy(cdd->ddev.dev);
343 pm_runtime_put_autosuspend(cdd->ddev.dev); 348 pm_runtime_put_autosuspend(cdd->ddev.dev);
344 } 349 }
@@ -362,8 +367,13 @@ static int cppi41_dma_alloc_chan_resources(struct dma_chan *chan)
362 int error; 367 int error;
363 368
364 error = pm_runtime_get_sync(cdd->ddev.dev); 369 error = pm_runtime_get_sync(cdd->ddev.dev);
365 if (error < 0) 370 if (error < 0) {
371 dev_err(cdd->ddev.dev, "%s pm runtime get: %i\n",
372 __func__, error);
373 pm_runtime_put_noidle(cdd->ddev.dev);
374
366 return error; 375 return error;
376 }
367 377
368 dma_cookie_init(chan); 378 dma_cookie_init(chan);
369 dma_async_tx_descriptor_init(&c->txd, chan); 379 dma_async_tx_descriptor_init(&c->txd, chan);
@@ -385,8 +395,11 @@ static void cppi41_dma_free_chan_resources(struct dma_chan *chan)
385 int error; 395 int error;
386 396
387 error = pm_runtime_get_sync(cdd->ddev.dev); 397 error = pm_runtime_get_sync(cdd->ddev.dev);
388 if (error < 0) 398 if (error < 0) {
399 pm_runtime_put_noidle(cdd->ddev.dev);
400
389 return; 401 return;
402 }
390 403
391 WARN_ON(!list_empty(&cdd->pending)); 404 WARN_ON(!list_empty(&cdd->pending));
392 405
@@ -460,9 +473,9 @@ static void cppi41_dma_issue_pending(struct dma_chan *chan)
460 struct cppi41_dd *cdd = c->cdd; 473 struct cppi41_dd *cdd = c->cdd;
461 int error; 474 int error;
462 475
463 /* PM runtime paired with dmaengine_desc_get_callback_invoke */
464 error = pm_runtime_get(cdd->ddev.dev); 476 error = pm_runtime_get(cdd->ddev.dev);
465 if ((error != -EINPROGRESS) && error < 0) { 477 if ((error != -EINPROGRESS) && error < 0) {
478 pm_runtime_put_noidle(cdd->ddev.dev);
466 dev_err(cdd->ddev.dev, "Failed to pm_runtime_get: %i\n", 479 dev_err(cdd->ddev.dev, "Failed to pm_runtime_get: %i\n",
467 error); 480 error);
468 481
@@ -473,6 +486,9 @@ static void cppi41_dma_issue_pending(struct dma_chan *chan)
473 push_desc_queue(c); 486 push_desc_queue(c);
474 else 487 else
475 pending_desc(c); 488 pending_desc(c);
489
490 pm_runtime_mark_last_busy(cdd->ddev.dev);
491 pm_runtime_put_autosuspend(cdd->ddev.dev);
476} 492}
477 493
478static u32 get_host_pd0(u32 length) 494static u32 get_host_pd0(u32 length)
@@ -1059,8 +1075,8 @@ err_chans:
1059 deinit_cppi41(dev, cdd); 1075 deinit_cppi41(dev, cdd);
1060err_init_cppi: 1076err_init_cppi:
1061 pm_runtime_dont_use_autosuspend(dev); 1077 pm_runtime_dont_use_autosuspend(dev);
1062 pm_runtime_put_sync(dev);
1063err_get_sync: 1078err_get_sync:
1079 pm_runtime_put_sync(dev);
1064 pm_runtime_disable(dev); 1080 pm_runtime_disable(dev);
1065 iounmap(cdd->usbss_mem); 1081 iounmap(cdd->usbss_mem);
1066 iounmap(cdd->ctrl_mem); 1082 iounmap(cdd->ctrl_mem);
@@ -1072,7 +1088,12 @@ err_get_sync:
1072static int cppi41_dma_remove(struct platform_device *pdev) 1088static int cppi41_dma_remove(struct platform_device *pdev)
1073{ 1089{
1074 struct cppi41_dd *cdd = platform_get_drvdata(pdev); 1090 struct cppi41_dd *cdd = platform_get_drvdata(pdev);
1091 int error;
1075 1092
1093 error = pm_runtime_get_sync(&pdev->dev);
1094 if (error < 0)
1095 dev_err(&pdev->dev, "%s could not pm_runtime_get: %i\n",
1096 __func__, error);
1076 of_dma_controller_free(pdev->dev.of_node); 1097 of_dma_controller_free(pdev->dev.of_node);
1077 dma_async_device_unregister(&cdd->ddev); 1098 dma_async_device_unregister(&cdd->ddev);
1078 1099
diff --git a/drivers/dma/edma.c b/drivers/dma/edma.c
index e18a58068bca..77242b37ef87 100644
--- a/drivers/dma/edma.c
+++ b/drivers/dma/edma.c
@@ -1628,6 +1628,7 @@ static int edma_alloc_chan_resources(struct dma_chan *chan)
1628 if (echan->slot[0] < 0) { 1628 if (echan->slot[0] < 0) {
1629 dev_err(dev, "Entry slot allocation failed for channel %u\n", 1629 dev_err(dev, "Entry slot allocation failed for channel %u\n",
1630 EDMA_CHAN_SLOT(echan->ch_num)); 1630 EDMA_CHAN_SLOT(echan->ch_num));
1631 ret = echan->slot[0];
1631 goto err_slot; 1632 goto err_slot;
1632 } 1633 }
1633 1634
diff --git a/drivers/dma/sun6i-dma.c b/drivers/dma/sun6i-dma.c
index 83461994e418..a2358780ab2c 100644
--- a/drivers/dma/sun6i-dma.c
+++ b/drivers/dma/sun6i-dma.c
@@ -578,7 +578,7 @@ static struct dma_async_tx_descriptor *sun6i_dma_prep_dma_memcpy(
578 578
579 burst = convert_burst(8); 579 burst = convert_burst(8);
580 width = convert_buswidth(DMA_SLAVE_BUSWIDTH_4_BYTES); 580 width = convert_buswidth(DMA_SLAVE_BUSWIDTH_4_BYTES);
581 v_lli->cfg |= DMA_CHAN_CFG_SRC_DRQ(DRQ_SDRAM) | 581 v_lli->cfg = DMA_CHAN_CFG_SRC_DRQ(DRQ_SDRAM) |
582 DMA_CHAN_CFG_DST_DRQ(DRQ_SDRAM) | 582 DMA_CHAN_CFG_DST_DRQ(DRQ_SDRAM) |
583 DMA_CHAN_CFG_DST_LINEAR_MODE | 583 DMA_CHAN_CFG_DST_LINEAR_MODE |
584 DMA_CHAN_CFG_SRC_LINEAR_MODE | 584 DMA_CHAN_CFG_SRC_LINEAR_MODE |
diff --git a/drivers/extcon/extcon-arizona.c b/drivers/extcon/extcon-arizona.c
index 56e6c4c7c60d..d836d4ce5ee4 100644
--- a/drivers/extcon/extcon-arizona.c
+++ b/drivers/extcon/extcon-arizona.c
@@ -274,9 +274,10 @@ static void arizona_extcon_pulse_micbias(struct arizona_extcon_info *info)
274 struct arizona *arizona = info->arizona; 274 struct arizona *arizona = info->arizona;
275 const char *widget = arizona_extcon_get_micbias(info); 275 const char *widget = arizona_extcon_get_micbias(info);
276 struct snd_soc_dapm_context *dapm = arizona->dapm; 276 struct snd_soc_dapm_context *dapm = arizona->dapm;
277 struct snd_soc_component *component = snd_soc_dapm_to_component(dapm);
277 int ret; 278 int ret;
278 279
279 ret = snd_soc_dapm_force_enable_pin(dapm, widget); 280 ret = snd_soc_component_force_enable_pin(component, widget);
280 if (ret != 0) 281 if (ret != 0)
281 dev_warn(arizona->dev, "Failed to enable %s: %d\n", 282 dev_warn(arizona->dev, "Failed to enable %s: %d\n",
282 widget, ret); 283 widget, ret);
@@ -284,7 +285,7 @@ static void arizona_extcon_pulse_micbias(struct arizona_extcon_info *info)
284 snd_soc_dapm_sync(dapm); 285 snd_soc_dapm_sync(dapm);
285 286
286 if (!arizona->pdata.micd_force_micbias) { 287 if (!arizona->pdata.micd_force_micbias) {
287 ret = snd_soc_dapm_disable_pin(arizona->dapm, widget); 288 ret = snd_soc_component_disable_pin(component, widget);
288 if (ret != 0) 289 if (ret != 0)
289 dev_warn(arizona->dev, "Failed to disable %s: %d\n", 290 dev_warn(arizona->dev, "Failed to disable %s: %d\n",
290 widget, ret); 291 widget, ret);
@@ -349,6 +350,7 @@ static void arizona_stop_mic(struct arizona_extcon_info *info)
349 struct arizona *arizona = info->arizona; 350 struct arizona *arizona = info->arizona;
350 const char *widget = arizona_extcon_get_micbias(info); 351 const char *widget = arizona_extcon_get_micbias(info);
351 struct snd_soc_dapm_context *dapm = arizona->dapm; 352 struct snd_soc_dapm_context *dapm = arizona->dapm;
353 struct snd_soc_component *component = snd_soc_dapm_to_component(dapm);
352 bool change; 354 bool change;
353 int ret; 355 int ret;
354 356
@@ -356,7 +358,7 @@ static void arizona_stop_mic(struct arizona_extcon_info *info)
356 ARIZONA_MICD_ENA, 0, 358 ARIZONA_MICD_ENA, 0,
357 &change); 359 &change);
358 360
359 ret = snd_soc_dapm_disable_pin(dapm, widget); 361 ret = snd_soc_component_disable_pin(component, widget);
360 if (ret != 0) 362 if (ret != 0)
361 dev_warn(arizona->dev, 363 dev_warn(arizona->dev,
362 "Failed to disable %s: %d\n", 364 "Failed to disable %s: %d\n",
diff --git a/drivers/extcon/extcon-qcom-spmi-misc.c b/drivers/extcon/extcon-qcom-spmi-misc.c
index ca957a5f4291..b8cde096a808 100644
--- a/drivers/extcon/extcon-qcom-spmi-misc.c
+++ b/drivers/extcon/extcon-qcom-spmi-misc.c
@@ -51,7 +51,7 @@ static void qcom_usb_extcon_detect_cable(struct work_struct *work)
51 if (ret) 51 if (ret)
52 return; 52 return;
53 53
54 extcon_set_state(info->edev, EXTCON_USB_HOST, !id); 54 extcon_set_state_sync(info->edev, EXTCON_USB_HOST, !id);
55} 55}
56 56
57static irqreturn_t qcom_usb_irq_handler(int irq, void *dev_id) 57static irqreturn_t qcom_usb_irq_handler(int irq, void *dev_id)
diff --git a/drivers/firewire/net.c b/drivers/firewire/net.c
index 309311b1faae..15475892af0c 100644
--- a/drivers/firewire/net.c
+++ b/drivers/firewire/net.c
@@ -73,13 +73,13 @@ struct rfc2734_header {
73 73
74#define fwnet_get_hdr_lf(h) (((h)->w0 & 0xc0000000) >> 30) 74#define fwnet_get_hdr_lf(h) (((h)->w0 & 0xc0000000) >> 30)
75#define fwnet_get_hdr_ether_type(h) (((h)->w0 & 0x0000ffff)) 75#define fwnet_get_hdr_ether_type(h) (((h)->w0 & 0x0000ffff))
76#define fwnet_get_hdr_dg_size(h) (((h)->w0 & 0x0fff0000) >> 16) 76#define fwnet_get_hdr_dg_size(h) ((((h)->w0 & 0x0fff0000) >> 16) + 1)
77#define fwnet_get_hdr_fg_off(h) (((h)->w0 & 0x00000fff)) 77#define fwnet_get_hdr_fg_off(h) (((h)->w0 & 0x00000fff))
78#define fwnet_get_hdr_dgl(h) (((h)->w1 & 0xffff0000) >> 16) 78#define fwnet_get_hdr_dgl(h) (((h)->w1 & 0xffff0000) >> 16)
79 79
80#define fwnet_set_hdr_lf(lf) ((lf) << 30) 80#define fwnet_set_hdr_lf(lf) ((lf) << 30)
81#define fwnet_set_hdr_ether_type(et) (et) 81#define fwnet_set_hdr_ether_type(et) (et)
82#define fwnet_set_hdr_dg_size(dgs) ((dgs) << 16) 82#define fwnet_set_hdr_dg_size(dgs) (((dgs) - 1) << 16)
83#define fwnet_set_hdr_fg_off(fgo) (fgo) 83#define fwnet_set_hdr_fg_off(fgo) (fgo)
84 84
85#define fwnet_set_hdr_dgl(dgl) ((dgl) << 16) 85#define fwnet_set_hdr_dgl(dgl) ((dgl) << 16)
@@ -578,6 +578,9 @@ static int fwnet_incoming_packet(struct fwnet_device *dev, __be32 *buf, int len,
578 int retval; 578 int retval;
579 u16 ether_type; 579 u16 ether_type;
580 580
581 if (len <= RFC2374_UNFRAG_HDR_SIZE)
582 return 0;
583
581 hdr.w0 = be32_to_cpu(buf[0]); 584 hdr.w0 = be32_to_cpu(buf[0]);
582 lf = fwnet_get_hdr_lf(&hdr); 585 lf = fwnet_get_hdr_lf(&hdr);
583 if (lf == RFC2374_HDR_UNFRAG) { 586 if (lf == RFC2374_HDR_UNFRAG) {
@@ -602,7 +605,12 @@ static int fwnet_incoming_packet(struct fwnet_device *dev, __be32 *buf, int len,
602 return fwnet_finish_incoming_packet(net, skb, source_node_id, 605 return fwnet_finish_incoming_packet(net, skb, source_node_id,
603 is_broadcast, ether_type); 606 is_broadcast, ether_type);
604 } 607 }
608
605 /* A datagram fragment has been received, now the fun begins. */ 609 /* A datagram fragment has been received, now the fun begins. */
610
611 if (len <= RFC2374_FRAG_HDR_SIZE)
612 return 0;
613
606 hdr.w1 = ntohl(buf[1]); 614 hdr.w1 = ntohl(buf[1]);
607 buf += 2; 615 buf += 2;
608 len -= RFC2374_FRAG_HDR_SIZE; 616 len -= RFC2374_FRAG_HDR_SIZE;
@@ -614,7 +622,10 @@ static int fwnet_incoming_packet(struct fwnet_device *dev, __be32 *buf, int len,
614 fg_off = fwnet_get_hdr_fg_off(&hdr); 622 fg_off = fwnet_get_hdr_fg_off(&hdr);
615 } 623 }
616 datagram_label = fwnet_get_hdr_dgl(&hdr); 624 datagram_label = fwnet_get_hdr_dgl(&hdr);
617 dg_size = fwnet_get_hdr_dg_size(&hdr); /* ??? + 1 */ 625 dg_size = fwnet_get_hdr_dg_size(&hdr);
626
627 if (fg_off + len > dg_size)
628 return 0;
618 629
619 spin_lock_irqsave(&dev->lock, flags); 630 spin_lock_irqsave(&dev->lock, flags);
620 631
@@ -722,6 +733,22 @@ static void fwnet_receive_packet(struct fw_card *card, struct fw_request *r,
722 fw_send_response(card, r, rcode); 733 fw_send_response(card, r, rcode);
723} 734}
724 735
736static int gasp_source_id(__be32 *p)
737{
738 return be32_to_cpu(p[0]) >> 16;
739}
740
741static u32 gasp_specifier_id(__be32 *p)
742{
743 return (be32_to_cpu(p[0]) & 0xffff) << 8 |
744 (be32_to_cpu(p[1]) & 0xff000000) >> 24;
745}
746
747static u32 gasp_version(__be32 *p)
748{
749 return be32_to_cpu(p[1]) & 0xffffff;
750}
751
725static void fwnet_receive_broadcast(struct fw_iso_context *context, 752static void fwnet_receive_broadcast(struct fw_iso_context *context,
726 u32 cycle, size_t header_length, void *header, void *data) 753 u32 cycle, size_t header_length, void *header, void *data)
727{ 754{
@@ -731,9 +758,6 @@ static void fwnet_receive_broadcast(struct fw_iso_context *context,
731 __be32 *buf_ptr; 758 __be32 *buf_ptr;
732 int retval; 759 int retval;
733 u32 length; 760 u32 length;
734 u16 source_node_id;
735 u32 specifier_id;
736 u32 ver;
737 unsigned long offset; 761 unsigned long offset;
738 unsigned long flags; 762 unsigned long flags;
739 763
@@ -750,22 +774,17 @@ static void fwnet_receive_broadcast(struct fw_iso_context *context,
750 774
751 spin_unlock_irqrestore(&dev->lock, flags); 775 spin_unlock_irqrestore(&dev->lock, flags);
752 776
753 specifier_id = (be32_to_cpu(buf_ptr[0]) & 0xffff) << 8 777 if (length > IEEE1394_GASP_HDR_SIZE &&
754 | (be32_to_cpu(buf_ptr[1]) & 0xff000000) >> 24; 778 gasp_specifier_id(buf_ptr) == IANA_SPECIFIER_ID &&
755 ver = be32_to_cpu(buf_ptr[1]) & 0xffffff; 779 (gasp_version(buf_ptr) == RFC2734_SW_VERSION
756 source_node_id = be32_to_cpu(buf_ptr[0]) >> 16;
757
758 if (specifier_id == IANA_SPECIFIER_ID &&
759 (ver == RFC2734_SW_VERSION
760#if IS_ENABLED(CONFIG_IPV6) 780#if IS_ENABLED(CONFIG_IPV6)
761 || ver == RFC3146_SW_VERSION 781 || gasp_version(buf_ptr) == RFC3146_SW_VERSION
762#endif 782#endif
763 )) { 783 ))
764 buf_ptr += 2; 784 fwnet_incoming_packet(dev, buf_ptr + 2,
765 length -= IEEE1394_GASP_HDR_SIZE; 785 length - IEEE1394_GASP_HDR_SIZE,
766 fwnet_incoming_packet(dev, buf_ptr, length, source_node_id, 786 gasp_source_id(buf_ptr),
767 context->card->generation, true); 787 context->card->generation, true);
768 }
769 788
770 packet.payload_length = dev->rcv_buffer_size; 789 packet.payload_length = dev->rcv_buffer_size;
771 packet.interrupt = 1; 790 packet.interrupt = 1;
diff --git a/drivers/firewire/nosy.c b/drivers/firewire/nosy.c
index 631c977b0da5..180f0a96528c 100644
--- a/drivers/firewire/nosy.c
+++ b/drivers/firewire/nosy.c
@@ -566,6 +566,11 @@ add_card(struct pci_dev *dev, const struct pci_device_id *unused)
566 566
567 lynx->registers = ioremap_nocache(pci_resource_start(dev, 0), 567 lynx->registers = ioremap_nocache(pci_resource_start(dev, 0),
568 PCILYNX_MAX_REGISTER); 568 PCILYNX_MAX_REGISTER);
569 if (lynx->registers == NULL) {
570 dev_err(&dev->dev, "Failed to map registers\n");
571 ret = -ENOMEM;
572 goto fail_deallocate_lynx;
573 }
569 574
570 lynx->rcv_start_pcl = pci_alloc_consistent(lynx->pci_device, 575 lynx->rcv_start_pcl = pci_alloc_consistent(lynx->pci_device,
571 sizeof(struct pcl), &lynx->rcv_start_pcl_bus); 576 sizeof(struct pcl), &lynx->rcv_start_pcl_bus);
@@ -578,7 +583,7 @@ add_card(struct pci_dev *dev, const struct pci_device_id *unused)
578 lynx->rcv_buffer == NULL) { 583 lynx->rcv_buffer == NULL) {
579 dev_err(&dev->dev, "Failed to allocate receive buffer\n"); 584 dev_err(&dev->dev, "Failed to allocate receive buffer\n");
580 ret = -ENOMEM; 585 ret = -ENOMEM;
581 goto fail_deallocate; 586 goto fail_deallocate_buffers;
582 } 587 }
583 lynx->rcv_start_pcl->next = cpu_to_le32(lynx->rcv_pcl_bus); 588 lynx->rcv_start_pcl->next = cpu_to_le32(lynx->rcv_pcl_bus);
584 lynx->rcv_pcl->next = cpu_to_le32(PCL_NEXT_INVALID); 589 lynx->rcv_pcl->next = cpu_to_le32(PCL_NEXT_INVALID);
@@ -641,7 +646,7 @@ add_card(struct pci_dev *dev, const struct pci_device_id *unused)
641 dev_err(&dev->dev, 646 dev_err(&dev->dev,
642 "Failed to allocate shared interrupt %d\n", dev->irq); 647 "Failed to allocate shared interrupt %d\n", dev->irq);
643 ret = -EIO; 648 ret = -EIO;
644 goto fail_deallocate; 649 goto fail_deallocate_buffers;
645 } 650 }
646 651
647 lynx->misc.parent = &dev->dev; 652 lynx->misc.parent = &dev->dev;
@@ -668,7 +673,7 @@ fail_free_irq:
668 reg_write(lynx, PCI_INT_ENABLE, 0); 673 reg_write(lynx, PCI_INT_ENABLE, 0);
669 free_irq(lynx->pci_device->irq, lynx); 674 free_irq(lynx->pci_device->irq, lynx);
670 675
671fail_deallocate: 676fail_deallocate_buffers:
672 if (lynx->rcv_start_pcl) 677 if (lynx->rcv_start_pcl)
673 pci_free_consistent(lynx->pci_device, sizeof(struct pcl), 678 pci_free_consistent(lynx->pci_device, sizeof(struct pcl),
674 lynx->rcv_start_pcl, lynx->rcv_start_pcl_bus); 679 lynx->rcv_start_pcl, lynx->rcv_start_pcl_bus);
@@ -679,6 +684,8 @@ fail_deallocate:
679 pci_free_consistent(lynx->pci_device, PAGE_SIZE, 684 pci_free_consistent(lynx->pci_device, PAGE_SIZE,
680 lynx->rcv_buffer, lynx->rcv_buffer_bus); 685 lynx->rcv_buffer, lynx->rcv_buffer_bus);
681 iounmap(lynx->registers); 686 iounmap(lynx->registers);
687
688fail_deallocate_lynx:
682 kfree(lynx); 689 kfree(lynx);
683 690
684fail_disable: 691fail_disable:
diff --git a/drivers/firmware/efi/libstub/Makefile b/drivers/firmware/efi/libstub/Makefile
index c06945160a41..5e23e2d305e7 100644
--- a/drivers/firmware/efi/libstub/Makefile
+++ b/drivers/firmware/efi/libstub/Makefile
@@ -11,7 +11,7 @@ cflags-$(CONFIG_X86) += -m$(BITS) -D__KERNEL__ $(LINUX_INCLUDE) -O2 \
11 -mno-mmx -mno-sse 11 -mno-mmx -mno-sse
12 12
13cflags-$(CONFIG_ARM64) := $(subst -pg,,$(KBUILD_CFLAGS)) 13cflags-$(CONFIG_ARM64) := $(subst -pg,,$(KBUILD_CFLAGS))
14cflags-$(CONFIG_ARM) := $(subst -pg,,$(KBUILD_CFLAGS)) \ 14cflags-$(CONFIG_ARM) := $(subst -pg,,$(KBUILD_CFLAGS)) -g0 \
15 -fno-builtin -fpic -mno-single-pic-base 15 -fno-builtin -fpic -mno-single-pic-base
16 16
17cflags-$(CONFIG_EFI_ARMSTUB) += -I$(srctree)/scripts/dtc/libfdt 17cflags-$(CONFIG_EFI_ARMSTUB) += -I$(srctree)/scripts/dtc/libfdt
@@ -79,5 +79,6 @@ quiet_cmd_stubcopy = STUBCPY $@
79# decompressor. So move our .data to .data.efistub, which is preserved 79# decompressor. So move our .data to .data.efistub, which is preserved
80# explicitly by the decompressor linker script. 80# explicitly by the decompressor linker script.
81# 81#
82STUBCOPY_FLAGS-$(CONFIG_ARM) += --rename-section .data=.data.efistub 82STUBCOPY_FLAGS-$(CONFIG_ARM) += --rename-section .data=.data.efistub \
83 -R ___ksymtab+sort -R ___kcrctab+sort
83STUBCOPY_RELOC-$(CONFIG_ARM) := R_ARM_ABS 84STUBCOPY_RELOC-$(CONFIG_ARM) := R_ARM_ABS
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index 26ee00f6bd58..ed37e5908b91 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -22,10 +22,6 @@ menuconfig GPIOLIB
22 22
23if GPIOLIB 23if GPIOLIB
24 24
25config GPIO_DEVRES
26 def_bool y
27 depends on HAS_IOMEM
28
29config OF_GPIO 25config OF_GPIO
30 def_bool y 26 def_bool y
31 depends on OF 27 depends on OF
@@ -284,7 +280,7 @@ config GPIO_MM_LANTIQ
284 280
285config GPIO_MOCKUP 281config GPIO_MOCKUP
286 tristate "GPIO Testing Driver" 282 tristate "GPIO Testing Driver"
287 depends on GPIOLIB 283 depends on GPIOLIB && SYSFS
288 select GPIO_SYSFS 284 select GPIO_SYSFS
289 help 285 help
290 This enables GPIO Testing driver, which provides a way to test GPIO 286 This enables GPIO Testing driver, which provides a way to test GPIO
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index ab28a2daeacc..d074c2299393 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -2,7 +2,7 @@
2 2
3ccflags-$(CONFIG_DEBUG_GPIO) += -DDEBUG 3ccflags-$(CONFIG_DEBUG_GPIO) += -DDEBUG
4 4
5obj-$(CONFIG_GPIO_DEVRES) += devres.o 5obj-$(CONFIG_GPIOLIB) += devres.o
6obj-$(CONFIG_GPIOLIB) += gpiolib.o 6obj-$(CONFIG_GPIOLIB) += gpiolib.o
7obj-$(CONFIG_GPIOLIB) += gpiolib-legacy.o 7obj-$(CONFIG_GPIOLIB) += gpiolib-legacy.o
8obj-$(CONFIG_OF_GPIO) += gpiolib-of.o 8obj-$(CONFIG_OF_GPIO) += gpiolib-of.o
diff --git a/drivers/gpio/gpio-ath79.c b/drivers/gpio/gpio-ath79.c
index 9457e2022bf6..dc37dbe4b46d 100644
--- a/drivers/gpio/gpio-ath79.c
+++ b/drivers/gpio/gpio-ath79.c
@@ -219,6 +219,7 @@ static const struct of_device_id ath79_gpio_of_match[] = {
219 { .compatible = "qca,ar9340-gpio" }, 219 { .compatible = "qca,ar9340-gpio" },
220 {}, 220 {},
221}; 221};
222MODULE_DEVICE_TABLE(of, ath79_gpio_of_match);
222 223
223static int ath79_gpio_probe(struct platform_device *pdev) 224static int ath79_gpio_probe(struct platform_device *pdev)
224{ 225{
diff --git a/drivers/gpio/gpio-mpc8xxx.c b/drivers/gpio/gpio-mpc8xxx.c
index 425501c39527..793518a30afe 100644
--- a/drivers/gpio/gpio-mpc8xxx.c
+++ b/drivers/gpio/gpio-mpc8xxx.c
@@ -239,7 +239,7 @@ static int mpc8xxx_gpio_irq_map(struct irq_domain *h, unsigned int irq,
239 irq_hw_number_t hwirq) 239 irq_hw_number_t hwirq)
240{ 240{
241 irq_set_chip_data(irq, h->host_data); 241 irq_set_chip_data(irq, h->host_data);
242 irq_set_chip_and_handler(irq, &mpc8xxx_irq_chip, handle_level_irq); 242 irq_set_chip_and_handler(irq, &mpc8xxx_irq_chip, handle_edge_irq);
243 243
244 return 0; 244 return 0;
245} 245}
diff --git a/drivers/gpio/gpio-mvebu.c b/drivers/gpio/gpio-mvebu.c
index cd5dc27320a2..1ed6132b993c 100644
--- a/drivers/gpio/gpio-mvebu.c
+++ b/drivers/gpio/gpio-mvebu.c
@@ -293,10 +293,10 @@ static void mvebu_gpio_irq_ack(struct irq_data *d)
293{ 293{
294 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); 294 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
295 struct mvebu_gpio_chip *mvchip = gc->private; 295 struct mvebu_gpio_chip *mvchip = gc->private;
296 u32 mask = ~(1 << (d->irq - gc->irq_base)); 296 u32 mask = d->mask;
297 297
298 irq_gc_lock(gc); 298 irq_gc_lock(gc);
299 writel_relaxed(mask, mvebu_gpioreg_edge_cause(mvchip)); 299 writel_relaxed(~mask, mvebu_gpioreg_edge_cause(mvchip));
300 irq_gc_unlock(gc); 300 irq_gc_unlock(gc);
301} 301}
302 302
@@ -305,7 +305,7 @@ static void mvebu_gpio_edge_irq_mask(struct irq_data *d)
305 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); 305 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
306 struct mvebu_gpio_chip *mvchip = gc->private; 306 struct mvebu_gpio_chip *mvchip = gc->private;
307 struct irq_chip_type *ct = irq_data_get_chip_type(d); 307 struct irq_chip_type *ct = irq_data_get_chip_type(d);
308 u32 mask = 1 << (d->irq - gc->irq_base); 308 u32 mask = d->mask;
309 309
310 irq_gc_lock(gc); 310 irq_gc_lock(gc);
311 ct->mask_cache_priv &= ~mask; 311 ct->mask_cache_priv &= ~mask;
@@ -319,8 +319,7 @@ static void mvebu_gpio_edge_irq_unmask(struct irq_data *d)
319 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); 319 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
320 struct mvebu_gpio_chip *mvchip = gc->private; 320 struct mvebu_gpio_chip *mvchip = gc->private;
321 struct irq_chip_type *ct = irq_data_get_chip_type(d); 321 struct irq_chip_type *ct = irq_data_get_chip_type(d);
322 322 u32 mask = d->mask;
323 u32 mask = 1 << (d->irq - gc->irq_base);
324 323
325 irq_gc_lock(gc); 324 irq_gc_lock(gc);
326 ct->mask_cache_priv |= mask; 325 ct->mask_cache_priv |= mask;
@@ -333,8 +332,7 @@ static void mvebu_gpio_level_irq_mask(struct irq_data *d)
333 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); 332 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
334 struct mvebu_gpio_chip *mvchip = gc->private; 333 struct mvebu_gpio_chip *mvchip = gc->private;
335 struct irq_chip_type *ct = irq_data_get_chip_type(d); 334 struct irq_chip_type *ct = irq_data_get_chip_type(d);
336 335 u32 mask = d->mask;
337 u32 mask = 1 << (d->irq - gc->irq_base);
338 336
339 irq_gc_lock(gc); 337 irq_gc_lock(gc);
340 ct->mask_cache_priv &= ~mask; 338 ct->mask_cache_priv &= ~mask;
@@ -347,8 +345,7 @@ static void mvebu_gpio_level_irq_unmask(struct irq_data *d)
347 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); 345 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
348 struct mvebu_gpio_chip *mvchip = gc->private; 346 struct mvebu_gpio_chip *mvchip = gc->private;
349 struct irq_chip_type *ct = irq_data_get_chip_type(d); 347 struct irq_chip_type *ct = irq_data_get_chip_type(d);
350 348 u32 mask = d->mask;
351 u32 mask = 1 << (d->irq - gc->irq_base);
352 349
353 irq_gc_lock(gc); 350 irq_gc_lock(gc);
354 ct->mask_cache_priv |= mask; 351 ct->mask_cache_priv |= mask;
@@ -462,7 +459,7 @@ static void mvebu_gpio_irq_handler(struct irq_desc *desc)
462 for (i = 0; i < mvchip->chip.ngpio; i++) { 459 for (i = 0; i < mvchip->chip.ngpio; i++) {
463 int irq; 460 int irq;
464 461
465 irq = mvchip->irqbase + i; 462 irq = irq_find_mapping(mvchip->domain, i);
466 463
467 if (!(cause & (1 << i))) 464 if (!(cause & (1 << i)))
468 continue; 465 continue;
@@ -655,6 +652,7 @@ static int mvebu_gpio_probe(struct platform_device *pdev)
655 struct irq_chip_type *ct; 652 struct irq_chip_type *ct;
656 struct clk *clk; 653 struct clk *clk;
657 unsigned int ngpios; 654 unsigned int ngpios;
655 bool have_irqs;
658 int soc_variant; 656 int soc_variant;
659 int i, cpu, id; 657 int i, cpu, id;
660 int err; 658 int err;
@@ -665,6 +663,9 @@ static int mvebu_gpio_probe(struct platform_device *pdev)
665 else 663 else
666 soc_variant = MVEBU_GPIO_SOC_VARIANT_ORION; 664 soc_variant = MVEBU_GPIO_SOC_VARIANT_ORION;
667 665
666 /* Some gpio controllers do not provide irq support */
667 have_irqs = of_irq_count(np) != 0;
668
668 mvchip = devm_kzalloc(&pdev->dev, sizeof(struct mvebu_gpio_chip), 669 mvchip = devm_kzalloc(&pdev->dev, sizeof(struct mvebu_gpio_chip),
669 GFP_KERNEL); 670 GFP_KERNEL);
670 if (!mvchip) 671 if (!mvchip)
@@ -697,7 +698,8 @@ static int mvebu_gpio_probe(struct platform_device *pdev)
697 mvchip->chip.get = mvebu_gpio_get; 698 mvchip->chip.get = mvebu_gpio_get;
698 mvchip->chip.direction_output = mvebu_gpio_direction_output; 699 mvchip->chip.direction_output = mvebu_gpio_direction_output;
699 mvchip->chip.set = mvebu_gpio_set; 700 mvchip->chip.set = mvebu_gpio_set;
700 mvchip->chip.to_irq = mvebu_gpio_to_irq; 701 if (have_irqs)
702 mvchip->chip.to_irq = mvebu_gpio_to_irq;
701 mvchip->chip.base = id * MVEBU_MAX_GPIO_PER_BANK; 703 mvchip->chip.base = id * MVEBU_MAX_GPIO_PER_BANK;
702 mvchip->chip.ngpio = ngpios; 704 mvchip->chip.ngpio = ngpios;
703 mvchip->chip.can_sleep = false; 705 mvchip->chip.can_sleep = false;
@@ -758,34 +760,30 @@ static int mvebu_gpio_probe(struct platform_device *pdev)
758 devm_gpiochip_add_data(&pdev->dev, &mvchip->chip, mvchip); 760 devm_gpiochip_add_data(&pdev->dev, &mvchip->chip, mvchip);
759 761
760 /* Some gpio controllers do not provide irq support */ 762 /* Some gpio controllers do not provide irq support */
761 if (!of_irq_count(np)) 763 if (!have_irqs)
762 return 0; 764 return 0;
763 765
764 /* Setup the interrupt handlers. Each chip can have up to 4 766 mvchip->domain =
765 * interrupt handlers, with each handler dealing with 8 GPIO 767 irq_domain_add_linear(np, ngpios, &irq_generic_chip_ops, NULL);
766 * pins. */ 768 if (!mvchip->domain) {
767 for (i = 0; i < 4; i++) { 769 dev_err(&pdev->dev, "couldn't allocate irq domain %s (DT).\n",
768 int irq = platform_get_irq(pdev, i); 770 mvchip->chip.label);
769 771 return -ENODEV;
770 if (irq < 0)
771 continue;
772 irq_set_chained_handler_and_data(irq, mvebu_gpio_irq_handler,
773 mvchip);
774 }
775
776 mvchip->irqbase = irq_alloc_descs(-1, 0, ngpios, -1);
777 if (mvchip->irqbase < 0) {
778 dev_err(&pdev->dev, "no irqs\n");
779 return mvchip->irqbase;
780 } 772 }
781 773
782 gc = irq_alloc_generic_chip("mvebu_gpio_irq", 2, mvchip->irqbase, 774 err = irq_alloc_domain_generic_chips(
783 mvchip->membase, handle_level_irq); 775 mvchip->domain, ngpios, 2, np->name, handle_level_irq,
784 if (!gc) { 776 IRQ_NOREQUEST | IRQ_NOPROBE | IRQ_LEVEL, 0, 0);
785 dev_err(&pdev->dev, "Cannot allocate generic irq_chip\n"); 777 if (err) {
786 return -ENOMEM; 778 dev_err(&pdev->dev, "couldn't allocate irq chips %s (DT).\n",
779 mvchip->chip.label);
780 goto err_domain;
787 } 781 }
788 782
783 /* NOTE: The common accessors cannot be used because of the percpu
784 * access to the mask registers
785 */
786 gc = irq_get_domain_generic_chip(mvchip->domain, 0);
789 gc->private = mvchip; 787 gc->private = mvchip;
790 ct = &gc->chip_types[0]; 788 ct = &gc->chip_types[0];
791 ct->type = IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW; 789 ct->type = IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW;
@@ -803,27 +801,23 @@ static int mvebu_gpio_probe(struct platform_device *pdev)
803 ct->handler = handle_edge_irq; 801 ct->handler = handle_edge_irq;
804 ct->chip.name = mvchip->chip.label; 802 ct->chip.name = mvchip->chip.label;
805 803
806 irq_setup_generic_chip(gc, IRQ_MSK(ngpios), 0, 804 /* Setup the interrupt handlers. Each chip can have up to 4
807 IRQ_NOREQUEST, IRQ_LEVEL | IRQ_NOPROBE); 805 * interrupt handlers, with each handler dealing with 8 GPIO
806 * pins.
807 */
808 for (i = 0; i < 4; i++) {
809 int irq = platform_get_irq(pdev, i);
808 810
809 /* Setup irq domain on top of the generic chip. */ 811 if (irq < 0)
810 mvchip->domain = irq_domain_add_simple(np, mvchip->chip.ngpio, 812 continue;
811 mvchip->irqbase, 813 irq_set_chained_handler_and_data(irq, mvebu_gpio_irq_handler,
812 &irq_domain_simple_ops, 814 mvchip);
813 mvchip);
814 if (!mvchip->domain) {
815 dev_err(&pdev->dev, "couldn't allocate irq domain %s (DT).\n",
816 mvchip->chip.label);
817 err = -ENODEV;
818 goto err_generic_chip;
819 } 815 }
820 816
821 return 0; 817 return 0;
822 818
823err_generic_chip: 819err_domain:
824 irq_remove_generic_chip(gc, IRQ_MSK(ngpios), IRQ_NOREQUEST, 820 irq_domain_remove(mvchip->domain);
825 IRQ_LEVEL | IRQ_NOPROBE);
826 kfree(gc);
827 821
828 return err; 822 return err;
829} 823}
diff --git a/drivers/gpio/gpio-mxs.c b/drivers/gpio/gpio-mxs.c
index b9daa0bf32a4..ee1724806f46 100644
--- a/drivers/gpio/gpio-mxs.c
+++ b/drivers/gpio/gpio-mxs.c
@@ -308,8 +308,10 @@ static int mxs_gpio_probe(struct platform_device *pdev)
308 writel(~0U, port->base + PINCTRL_IRQSTAT(port) + MXS_CLR); 308 writel(~0U, port->base + PINCTRL_IRQSTAT(port) + MXS_CLR);
309 309
310 irq_base = irq_alloc_descs(-1, 0, 32, numa_node_id()); 310 irq_base = irq_alloc_descs(-1, 0, 32, numa_node_id());
311 if (irq_base < 0) 311 if (irq_base < 0) {
312 return irq_base; 312 err = irq_base;
313 goto out_iounmap;
314 }
313 315
314 port->domain = irq_domain_add_legacy(np, 32, irq_base, 0, 316 port->domain = irq_domain_add_legacy(np, 32, irq_base, 0,
315 &irq_domain_simple_ops, NULL); 317 &irq_domain_simple_ops, NULL);
@@ -349,6 +351,8 @@ out_irqdomain_remove:
349 irq_domain_remove(port->domain); 351 irq_domain_remove(port->domain);
350out_irqdesc_free: 352out_irqdesc_free:
351 irq_free_descs(irq_base, 32); 353 irq_free_descs(irq_base, 32);
354out_iounmap:
355 iounmap(port->base);
352 return err; 356 return err;
353} 357}
354 358
diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c
index e422568e14ad..fe731f094257 100644
--- a/drivers/gpio/gpio-pca953x.c
+++ b/drivers/gpio/gpio-pca953x.c
@@ -372,14 +372,15 @@ static void pca953x_gpio_set_multiple(struct gpio_chip *gc,
372 372
373 bank_shift = fls((chip->gpio_chip.ngpio - 1) / BANK_SZ); 373 bank_shift = fls((chip->gpio_chip.ngpio - 1) / BANK_SZ);
374 374
375 memcpy(reg_val, chip->reg_output, NBANK(chip));
376 mutex_lock(&chip->i2c_lock); 375 mutex_lock(&chip->i2c_lock);
376 memcpy(reg_val, chip->reg_output, NBANK(chip));
377 for (bank = 0; bank < NBANK(chip); bank++) { 377 for (bank = 0; bank < NBANK(chip); bank++) {
378 bank_mask = mask[bank / sizeof(*mask)] >> 378 bank_mask = mask[bank / sizeof(*mask)] >>
379 ((bank % sizeof(*mask)) * 8); 379 ((bank % sizeof(*mask)) * 8);
380 if (bank_mask) { 380 if (bank_mask) {
381 bank_val = bits[bank / sizeof(*bits)] >> 381 bank_val = bits[bank / sizeof(*bits)] >>
382 ((bank % sizeof(*bits)) * 8); 382 ((bank % sizeof(*bits)) * 8);
383 bank_val &= bank_mask;
383 reg_val[bank] = (reg_val[bank] & ~bank_mask) | bank_val; 384 reg_val[bank] = (reg_val[bank] & ~bank_mask) | bank_val;
384 } 385 }
385 } 386 }
@@ -607,7 +608,6 @@ static int pca953x_irq_setup(struct pca953x_chip *chip,
607 608
608 if (client->irq && irq_base != -1 609 if (client->irq && irq_base != -1
609 && (chip->driver_data & PCA_INT)) { 610 && (chip->driver_data & PCA_INT)) {
610
611 ret = pca953x_read_regs(chip, 611 ret = pca953x_read_regs(chip,
612 chip->regs->input, chip->irq_stat); 612 chip->regs->input, chip->irq_stat);
613 if (ret) 613 if (ret)
diff --git a/drivers/gpio/gpio-stmpe.c b/drivers/gpio/gpio-stmpe.c
index e7d422a6b90b..5b0042776ec7 100644
--- a/drivers/gpio/gpio-stmpe.c
+++ b/drivers/gpio/gpio-stmpe.c
@@ -409,7 +409,7 @@ static irqreturn_t stmpe_gpio_irq(int irq, void *dev)
409 * 801/1801/1600, bits are cleared when read. 409 * 801/1801/1600, bits are cleared when read.
410 * Edge detect register is not present on 801/1600/1801 410 * Edge detect register is not present on 801/1600/1801
411 */ 411 */
412 if (stmpe->partnum != STMPE801 || stmpe->partnum != STMPE1600 || 412 if (stmpe->partnum != STMPE801 && stmpe->partnum != STMPE1600 &&
413 stmpe->partnum != STMPE1801) { 413 stmpe->partnum != STMPE1801) {
414 stmpe_reg_write(stmpe, statmsbreg + i, status[i]); 414 stmpe_reg_write(stmpe, statmsbreg + i, status[i]);
415 stmpe_reg_write(stmpe, 415 stmpe_reg_write(stmpe,
diff --git a/drivers/gpio/gpio-tc3589x.c b/drivers/gpio/gpio-tc3589x.c
index 5a5a6cb00eea..d6e21f1a70a9 100644
--- a/drivers/gpio/gpio-tc3589x.c
+++ b/drivers/gpio/gpio-tc3589x.c
@@ -97,7 +97,7 @@ static int tc3589x_gpio_get_direction(struct gpio_chip *chip,
97 if (ret < 0) 97 if (ret < 0)
98 return ret; 98 return ret;
99 99
100 return !!(ret & BIT(pos)); 100 return !(ret & BIT(pos));
101} 101}
102 102
103static int tc3589x_gpio_set_single_ended(struct gpio_chip *chip, 103static int tc3589x_gpio_set_single_ended(struct gpio_chip *chip,
diff --git a/drivers/gpio/gpio-ts4800.c b/drivers/gpio/gpio-ts4800.c
index 99256115bea5..c2a80b4cbf32 100644
--- a/drivers/gpio/gpio-ts4800.c
+++ b/drivers/gpio/gpio-ts4800.c
@@ -66,6 +66,7 @@ static const struct of_device_id ts4800_gpio_of_match[] = {
66 { .compatible = "technologic,ts4800-gpio", }, 66 { .compatible = "technologic,ts4800-gpio", },
67 {}, 67 {},
68}; 68};
69MODULE_DEVICE_TABLE(of, ts4800_gpio_of_match);
69 70
70static struct platform_driver ts4800_gpio_driver = { 71static struct platform_driver ts4800_gpio_driver = {
71 .driver = { 72 .driver = {
diff --git a/drivers/gpio/gpiolib-acpi.c b/drivers/gpio/gpiolib-acpi.c
index 58ece201b8e6..72a4b326fd0d 100644
--- a/drivers/gpio/gpiolib-acpi.c
+++ b/drivers/gpio/gpiolib-acpi.c
@@ -653,14 +653,17 @@ int acpi_dev_gpio_irq_get(struct acpi_device *adev, int index)
653{ 653{
654 int idx, i; 654 int idx, i;
655 unsigned int irq_flags; 655 unsigned int irq_flags;
656 int ret = -ENOENT;
656 657
657 for (i = 0, idx = 0; idx <= index; i++) { 658 for (i = 0, idx = 0; idx <= index; i++) {
658 struct acpi_gpio_info info; 659 struct acpi_gpio_info info;
659 struct gpio_desc *desc; 660 struct gpio_desc *desc;
660 661
661 desc = acpi_get_gpiod_by_index(adev, NULL, i, &info); 662 desc = acpi_get_gpiod_by_index(adev, NULL, i, &info);
662 if (IS_ERR(desc)) 663 if (IS_ERR(desc)) {
664 ret = PTR_ERR(desc);
663 break; 665 break;
666 }
664 if (info.gpioint && idx++ == index) { 667 if (info.gpioint && idx++ == index) {
665 int irq = gpiod_to_irq(desc); 668 int irq = gpiod_to_irq(desc);
666 669
@@ -679,7 +682,7 @@ int acpi_dev_gpio_irq_get(struct acpi_device *adev, int index)
679 } 682 }
680 683
681 } 684 }
682 return -ENOENT; 685 return ret;
683} 686}
684EXPORT_SYMBOL_GPL(acpi_dev_gpio_irq_get); 687EXPORT_SYMBOL_GPL(acpi_dev_gpio_irq_get);
685 688
diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
index ecad3f0e3b77..193f15d50bba 100644
--- a/drivers/gpio/gpiolib-of.c
+++ b/drivers/gpio/gpiolib-of.c
@@ -26,14 +26,18 @@
26 26
27#include "gpiolib.h" 27#include "gpiolib.h"
28 28
29static int of_gpiochip_match_node(struct gpio_chip *chip, void *data) 29static int of_gpiochip_match_node_and_xlate(struct gpio_chip *chip, void *data)
30{ 30{
31 return chip->gpiodev->dev.of_node == data; 31 struct of_phandle_args *gpiospec = data;
32
33 return chip->gpiodev->dev.of_node == gpiospec->np &&
34 chip->of_xlate(chip, gpiospec, NULL) >= 0;
32} 35}
33 36
34static struct gpio_chip *of_find_gpiochip_by_node(struct device_node *np) 37static struct gpio_chip *of_find_gpiochip_by_xlate(
38 struct of_phandle_args *gpiospec)
35{ 39{
36 return gpiochip_find(np, of_gpiochip_match_node); 40 return gpiochip_find(gpiospec, of_gpiochip_match_node_and_xlate);
37} 41}
38 42
39static struct gpio_desc *of_xlate_and_get_gpiod_flags(struct gpio_chip *chip, 43static struct gpio_desc *of_xlate_and_get_gpiod_flags(struct gpio_chip *chip,
@@ -79,7 +83,7 @@ struct gpio_desc *of_get_named_gpiod_flags(struct device_node *np,
79 return ERR_PTR(ret); 83 return ERR_PTR(ret);
80 } 84 }
81 85
82 chip = of_find_gpiochip_by_node(gpiospec.np); 86 chip = of_find_gpiochip_by_xlate(&gpiospec);
83 if (!chip) { 87 if (!chip) {
84 desc = ERR_PTR(-EPROBE_DEFER); 88 desc = ERR_PTR(-EPROBE_DEFER);
85 goto out; 89 goto out;
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index f0fc3a0d37c8..868128a676ba 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -21,6 +21,7 @@
21#include <linux/uaccess.h> 21#include <linux/uaccess.h>
22#include <linux/compat.h> 22#include <linux/compat.h>
23#include <linux/anon_inodes.h> 23#include <linux/anon_inodes.h>
24#include <linux/file.h>
24#include <linux/kfifo.h> 25#include <linux/kfifo.h>
25#include <linux/poll.h> 26#include <linux/poll.h>
26#include <linux/timekeeping.h> 27#include <linux/timekeeping.h>
@@ -333,6 +334,13 @@ struct linehandle_state {
333 u32 numdescs; 334 u32 numdescs;
334}; 335};
335 336
337#define GPIOHANDLE_REQUEST_VALID_FLAGS \
338 (GPIOHANDLE_REQUEST_INPUT | \
339 GPIOHANDLE_REQUEST_OUTPUT | \
340 GPIOHANDLE_REQUEST_ACTIVE_LOW | \
341 GPIOHANDLE_REQUEST_OPEN_DRAIN | \
342 GPIOHANDLE_REQUEST_OPEN_SOURCE)
343
336static long linehandle_ioctl(struct file *filep, unsigned int cmd, 344static long linehandle_ioctl(struct file *filep, unsigned int cmd,
337 unsigned long arg) 345 unsigned long arg)
338{ 346{
@@ -344,6 +352,8 @@ static long linehandle_ioctl(struct file *filep, unsigned int cmd,
344 if (cmd == GPIOHANDLE_GET_LINE_VALUES_IOCTL) { 352 if (cmd == GPIOHANDLE_GET_LINE_VALUES_IOCTL) {
345 int val; 353 int val;
346 354
355 memset(&ghd, 0, sizeof(ghd));
356
347 /* TODO: check if descriptors are really input */ 357 /* TODO: check if descriptors are really input */
348 for (i = 0; i < lh->numdescs; i++) { 358 for (i = 0; i < lh->numdescs; i++) {
349 val = gpiod_get_value_cansleep(lh->descs[i]); 359 val = gpiod_get_value_cansleep(lh->descs[i]);
@@ -414,6 +424,7 @@ static int linehandle_create(struct gpio_device *gdev, void __user *ip)
414{ 424{
415 struct gpiohandle_request handlereq; 425 struct gpiohandle_request handlereq;
416 struct linehandle_state *lh; 426 struct linehandle_state *lh;
427 struct file *file;
417 int fd, i, ret; 428 int fd, i, ret;
418 429
419 if (copy_from_user(&handlereq, ip, sizeof(handlereq))) 430 if (copy_from_user(&handlereq, ip, sizeof(handlereq)))
@@ -444,6 +455,17 @@ static int linehandle_create(struct gpio_device *gdev, void __user *ip)
444 u32 lflags = handlereq.flags; 455 u32 lflags = handlereq.flags;
445 struct gpio_desc *desc; 456 struct gpio_desc *desc;
446 457
458 if (offset >= gdev->ngpio) {
459 ret = -EINVAL;
460 goto out_free_descs;
461 }
462
463 /* Return an error if a unknown flag is set */
464 if (lflags & ~GPIOHANDLE_REQUEST_VALID_FLAGS) {
465 ret = -EINVAL;
466 goto out_free_descs;
467 }
468
447 desc = &gdev->descs[offset]; 469 desc = &gdev->descs[offset];
448 ret = gpiod_request(desc, lh->label); 470 ret = gpiod_request(desc, lh->label);
449 if (ret) 471 if (ret)
@@ -479,26 +501,41 @@ static int linehandle_create(struct gpio_device *gdev, void __user *ip)
479 i--; 501 i--;
480 lh->numdescs = handlereq.lines; 502 lh->numdescs = handlereq.lines;
481 503
482 fd = anon_inode_getfd("gpio-linehandle", 504 fd = get_unused_fd_flags(O_RDONLY | O_CLOEXEC);
483 &linehandle_fileops,
484 lh,
485 O_RDONLY | O_CLOEXEC);
486 if (fd < 0) { 505 if (fd < 0) {
487 ret = fd; 506 ret = fd;
488 goto out_free_descs; 507 goto out_free_descs;
489 } 508 }
490 509
510 file = anon_inode_getfile("gpio-linehandle",
511 &linehandle_fileops,
512 lh,
513 O_RDONLY | O_CLOEXEC);
514 if (IS_ERR(file)) {
515 ret = PTR_ERR(file);
516 goto out_put_unused_fd;
517 }
518
491 handlereq.fd = fd; 519 handlereq.fd = fd;
492 if (copy_to_user(ip, &handlereq, sizeof(handlereq))) { 520 if (copy_to_user(ip, &handlereq, sizeof(handlereq))) {
493 ret = -EFAULT; 521 /*
494 goto out_free_descs; 522 * fput() will trigger the release() callback, so do not go onto
523 * the regular error cleanup path here.
524 */
525 fput(file);
526 put_unused_fd(fd);
527 return -EFAULT;
495 } 528 }
496 529
530 fd_install(fd, file);
531
497 dev_dbg(&gdev->dev, "registered chardev handle for %d lines\n", 532 dev_dbg(&gdev->dev, "registered chardev handle for %d lines\n",
498 lh->numdescs); 533 lh->numdescs);
499 534
500 return 0; 535 return 0;
501 536
537out_put_unused_fd:
538 put_unused_fd(fd);
502out_free_descs: 539out_free_descs:
503 for (; i >= 0; i--) 540 for (; i >= 0; i--)
504 gpiod_free(lh->descs[i]); 541 gpiod_free(lh->descs[i]);
@@ -536,6 +573,10 @@ struct lineevent_state {
536 struct mutex read_lock; 573 struct mutex read_lock;
537}; 574};
538 575
576#define GPIOEVENT_REQUEST_VALID_FLAGS \
577 (GPIOEVENT_REQUEST_RISING_EDGE | \
578 GPIOEVENT_REQUEST_FALLING_EDGE)
579
539static unsigned int lineevent_poll(struct file *filep, 580static unsigned int lineevent_poll(struct file *filep,
540 struct poll_table_struct *wait) 581 struct poll_table_struct *wait)
541{ 582{
@@ -623,6 +664,8 @@ static long lineevent_ioctl(struct file *filep, unsigned int cmd,
623 if (cmd == GPIOHANDLE_GET_LINE_VALUES_IOCTL) { 664 if (cmd == GPIOHANDLE_GET_LINE_VALUES_IOCTL) {
624 int val; 665 int val;
625 666
667 memset(&ghd, 0, sizeof(ghd));
668
626 val = gpiod_get_value_cansleep(le->desc); 669 val = gpiod_get_value_cansleep(le->desc);
627 if (val < 0) 670 if (val < 0)
628 return val; 671 return val;
@@ -695,6 +738,7 @@ static int lineevent_create(struct gpio_device *gdev, void __user *ip)
695 struct gpioevent_request eventreq; 738 struct gpioevent_request eventreq;
696 struct lineevent_state *le; 739 struct lineevent_state *le;
697 struct gpio_desc *desc; 740 struct gpio_desc *desc;
741 struct file *file;
698 u32 offset; 742 u32 offset;
699 u32 lflags; 743 u32 lflags;
700 u32 eflags; 744 u32 eflags;
@@ -726,6 +770,18 @@ static int lineevent_create(struct gpio_device *gdev, void __user *ip)
726 lflags = eventreq.handleflags; 770 lflags = eventreq.handleflags;
727 eflags = eventreq.eventflags; 771 eflags = eventreq.eventflags;
728 772
773 if (offset >= gdev->ngpio) {
774 ret = -EINVAL;
775 goto out_free_label;
776 }
777
778 /* Return an error if a unknown flag is set */
779 if ((lflags & ~GPIOHANDLE_REQUEST_VALID_FLAGS) ||
780 (eflags & ~GPIOEVENT_REQUEST_VALID_FLAGS)) {
781 ret = -EINVAL;
782 goto out_free_label;
783 }
784
729 /* This is just wrong: we don't look for events on output lines */ 785 /* This is just wrong: we don't look for events on output lines */
730 if (lflags & GPIOHANDLE_REQUEST_OUTPUT) { 786 if (lflags & GPIOHANDLE_REQUEST_OUTPUT) {
731 ret = -EINVAL; 787 ret = -EINVAL;
@@ -777,23 +833,38 @@ static int lineevent_create(struct gpio_device *gdev, void __user *ip)
777 if (ret) 833 if (ret)
778 goto out_free_desc; 834 goto out_free_desc;
779 835
780 fd = anon_inode_getfd("gpio-event", 836 fd = get_unused_fd_flags(O_RDONLY | O_CLOEXEC);
781 &lineevent_fileops,
782 le,
783 O_RDONLY | O_CLOEXEC);
784 if (fd < 0) { 837 if (fd < 0) {
785 ret = fd; 838 ret = fd;
786 goto out_free_irq; 839 goto out_free_irq;
787 } 840 }
788 841
842 file = anon_inode_getfile("gpio-event",
843 &lineevent_fileops,
844 le,
845 O_RDONLY | O_CLOEXEC);
846 if (IS_ERR(file)) {
847 ret = PTR_ERR(file);
848 goto out_put_unused_fd;
849 }
850
789 eventreq.fd = fd; 851 eventreq.fd = fd;
790 if (copy_to_user(ip, &eventreq, sizeof(eventreq))) { 852 if (copy_to_user(ip, &eventreq, sizeof(eventreq))) {
791 ret = -EFAULT; 853 /*
792 goto out_free_irq; 854 * fput() will trigger the release() callback, so do not go onto
855 * the regular error cleanup path here.
856 */
857 fput(file);
858 put_unused_fd(fd);
859 return -EFAULT;
793 } 860 }
794 861
862 fd_install(fd, file);
863
795 return 0; 864 return 0;
796 865
866out_put_unused_fd:
867 put_unused_fd(fd);
797out_free_irq: 868out_free_irq:
798 free_irq(le->irq, le); 869 free_irq(le->irq, le);
799out_free_desc: 870out_free_desc:
@@ -823,6 +894,8 @@ static long gpio_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
823 if (cmd == GPIO_GET_CHIPINFO_IOCTL) { 894 if (cmd == GPIO_GET_CHIPINFO_IOCTL) {
824 struct gpiochip_info chipinfo; 895 struct gpiochip_info chipinfo;
825 896
897 memset(&chipinfo, 0, sizeof(chipinfo));
898
826 strncpy(chipinfo.name, dev_name(&gdev->dev), 899 strncpy(chipinfo.name, dev_name(&gdev->dev),
827 sizeof(chipinfo.name)); 900 sizeof(chipinfo.name));
828 chipinfo.name[sizeof(chipinfo.name)-1] = '\0'; 901 chipinfo.name[sizeof(chipinfo.name)-1] = '\0';
@@ -839,7 +912,7 @@ static long gpio_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
839 912
840 if (copy_from_user(&lineinfo, ip, sizeof(lineinfo))) 913 if (copy_from_user(&lineinfo, ip, sizeof(lineinfo)))
841 return -EFAULT; 914 return -EFAULT;
842 if (lineinfo.line_offset > gdev->ngpio) 915 if (lineinfo.line_offset >= gdev->ngpio)
843 return -EINVAL; 916 return -EINVAL;
844 917
845 desc = &gdev->descs[lineinfo.line_offset]; 918 desc = &gdev->descs[lineinfo.line_offset];
@@ -2664,8 +2737,11 @@ int gpiochip_lock_as_irq(struct gpio_chip *chip, unsigned int offset)
2664 if (IS_ERR(desc)) 2737 if (IS_ERR(desc))
2665 return PTR_ERR(desc); 2738 return PTR_ERR(desc);
2666 2739
2667 /* Flush direction if something changed behind our back */ 2740 /*
2668 if (chip->get_direction) { 2741 * If it's fast: flush the direction setting if something changed
2742 * behind our back
2743 */
2744 if (!chip->can_sleep && chip->get_direction) {
2669 int dir = chip->get_direction(chip, offset); 2745 int dir = chip->get_direction(chip, offset);
2670 2746
2671 if (dir) 2747 if (dir)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index 039b57e4644c..05c2850c04b0 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -459,6 +459,7 @@ struct amdgpu_bo {
459 u64 metadata_flags; 459 u64 metadata_flags;
460 void *metadata; 460 void *metadata;
461 u32 metadata_size; 461 u32 metadata_size;
462 unsigned prime_shared_count;
462 /* list of all virtual address to which this bo 463 /* list of all virtual address to which this bo
463 * is associated to 464 * is associated to
464 */ 465 */
@@ -2471,6 +2472,7 @@ void amdgpu_driver_postclose_kms(struct drm_device *dev,
2471 struct drm_file *file_priv); 2472 struct drm_file *file_priv);
2472void amdgpu_driver_preclose_kms(struct drm_device *dev, 2473void amdgpu_driver_preclose_kms(struct drm_device *dev,
2473 struct drm_file *file_priv); 2474 struct drm_file *file_priv);
2475int amdgpu_suspend(struct amdgpu_device *adev);
2474int amdgpu_device_suspend(struct drm_device *dev, bool suspend, bool fbcon); 2476int amdgpu_device_suspend(struct drm_device *dev, bool suspend, bool fbcon);
2475int amdgpu_device_resume(struct drm_device *dev, bool resume, bool fbcon); 2477int amdgpu_device_resume(struct drm_device *dev, bool resume, bool fbcon);
2476u32 amdgpu_get_vblank_counter_kms(struct drm_device *dev, unsigned int pipe); 2478u32 amdgpu_get_vblank_counter_kms(struct drm_device *dev, unsigned int pipe);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_acp.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_acp.c
index 892d60fb225b..2057683f7b59 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_acp.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_acp.c
@@ -395,9 +395,12 @@ static int acp_hw_fini(void *handle)
395{ 395{
396 int i, ret; 396 int i, ret;
397 struct device *dev; 397 struct device *dev;
398
399 struct amdgpu_device *adev = (struct amdgpu_device *)handle; 398 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
400 399
400 /* return early if no ACP */
401 if (!adev->acp.acp_genpd)
402 return 0;
403
401 for (i = 0; i < ACP_DEVS ; i++) { 404 for (i = 0; i < ACP_DEVS ; i++) {
402 dev = get_mfd_cell_dev(adev->acp.acp_cell[i].name, i); 405 dev = get_mfd_cell_dev(adev->acp.acp_cell[i].name, i);
403 ret = pm_genpd_remove_device(&adev->acp.acp_genpd->gpd, dev); 406 ret = pm_genpd_remove_device(&adev->acp.acp_genpd->gpd, dev);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_atpx_handler.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_atpx_handler.c
index dae35a96a694..6c343a933182 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_atpx_handler.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_atpx_handler.c
@@ -34,6 +34,7 @@ struct amdgpu_atpx {
34 34
35static struct amdgpu_atpx_priv { 35static struct amdgpu_atpx_priv {
36 bool atpx_detected; 36 bool atpx_detected;
37 bool bridge_pm_usable;
37 /* handle for device - and atpx */ 38 /* handle for device - and atpx */
38 acpi_handle dhandle; 39 acpi_handle dhandle;
39 acpi_handle other_handle; 40 acpi_handle other_handle;
@@ -205,7 +206,11 @@ static int amdgpu_atpx_validate(struct amdgpu_atpx *atpx)
205 atpx->is_hybrid = false; 206 atpx->is_hybrid = false;
206 if (valid_bits & ATPX_MS_HYBRID_GFX_SUPPORTED) { 207 if (valid_bits & ATPX_MS_HYBRID_GFX_SUPPORTED) {
207 printk("ATPX Hybrid Graphics\n"); 208 printk("ATPX Hybrid Graphics\n");
208 atpx->functions.power_cntl = false; 209 /*
210 * Disable legacy PM methods only when pcie port PM is usable,
211 * otherwise the device might fail to power off or power on.
212 */
213 atpx->functions.power_cntl = !amdgpu_atpx_priv.bridge_pm_usable;
209 atpx->is_hybrid = true; 214 atpx->is_hybrid = true;
210 } 215 }
211 216
@@ -555,17 +560,25 @@ static bool amdgpu_atpx_detect(void)
555 struct pci_dev *pdev = NULL; 560 struct pci_dev *pdev = NULL;
556 bool has_atpx = false; 561 bool has_atpx = false;
557 int vga_count = 0; 562 int vga_count = 0;
563 bool d3_supported = false;
564 struct pci_dev *parent_pdev;
558 565
559 while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_VGA << 8, pdev)) != NULL) { 566 while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_VGA << 8, pdev)) != NULL) {
560 vga_count++; 567 vga_count++;
561 568
562 has_atpx |= (amdgpu_atpx_pci_probe_handle(pdev) == true); 569 has_atpx |= (amdgpu_atpx_pci_probe_handle(pdev) == true);
570
571 parent_pdev = pci_upstream_bridge(pdev);
572 d3_supported |= parent_pdev && parent_pdev->bridge_d3;
563 } 573 }
564 574
565 while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_OTHER << 8, pdev)) != NULL) { 575 while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_OTHER << 8, pdev)) != NULL) {
566 vga_count++; 576 vga_count++;
567 577
568 has_atpx |= (amdgpu_atpx_pci_probe_handle(pdev) == true); 578 has_atpx |= (amdgpu_atpx_pci_probe_handle(pdev) == true);
579
580 parent_pdev = pci_upstream_bridge(pdev);
581 d3_supported |= parent_pdev && parent_pdev->bridge_d3;
569 } 582 }
570 583
571 if (has_atpx && vga_count == 2) { 584 if (has_atpx && vga_count == 2) {
@@ -573,6 +586,7 @@ static bool amdgpu_atpx_detect(void)
573 printk(KERN_INFO "vga_switcheroo: detected switching method %s handle\n", 586 printk(KERN_INFO "vga_switcheroo: detected switching method %s handle\n",
574 acpi_method_name); 587 acpi_method_name);
575 amdgpu_atpx_priv.atpx_detected = true; 588 amdgpu_atpx_priv.atpx_detected = true;
589 amdgpu_atpx_priv.bridge_pm_usable = d3_supported;
576 amdgpu_atpx_init(); 590 amdgpu_atpx_init();
577 return true; 591 return true;
578 } 592 }
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
index 651115dcce12..c02db01f6583 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
@@ -132,7 +132,7 @@ static int amdgpu_bo_list_set(struct amdgpu_device *adev,
132 entry->priority = min(info[i].bo_priority, 132 entry->priority = min(info[i].bo_priority,
133 AMDGPU_BO_LIST_MAX_PRIORITY); 133 AMDGPU_BO_LIST_MAX_PRIORITY);
134 entry->tv.bo = &entry->robj->tbo; 134 entry->tv.bo = &entry->robj->tbo;
135 entry->tv.shared = true; 135 entry->tv.shared = !entry->robj->prime_shared_count;
136 136
137 if (entry->robj->prefered_domains == AMDGPU_GEM_DOMAIN_GDS) 137 if (entry->robj->prefered_domains == AMDGPU_GEM_DOMAIN_GDS)
138 gds_obj = entry->robj; 138 gds_obj = entry->robj;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cgs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cgs.c
index 7a8bfa34682f..662976292535 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cgs.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cgs.c
@@ -795,10 +795,19 @@ static int amdgpu_cgs_get_firmware_info(struct cgs_device *cgs_device,
795 if (!adev->pm.fw) { 795 if (!adev->pm.fw) {
796 switch (adev->asic_type) { 796 switch (adev->asic_type) {
797 case CHIP_TOPAZ: 797 case CHIP_TOPAZ:
798 strcpy(fw_name, "amdgpu/topaz_smc.bin"); 798 if (((adev->pdev->device == 0x6900) && (adev->pdev->revision == 0x81)) ||
799 ((adev->pdev->device == 0x6900) && (adev->pdev->revision == 0x83)) ||
800 ((adev->pdev->device == 0x6907) && (adev->pdev->revision == 0x87)))
801 strcpy(fw_name, "amdgpu/topaz_k_smc.bin");
802 else
803 strcpy(fw_name, "amdgpu/topaz_smc.bin");
799 break; 804 break;
800 case CHIP_TONGA: 805 case CHIP_TONGA:
801 strcpy(fw_name, "amdgpu/tonga_smc.bin"); 806 if (((adev->pdev->device == 0x6939) && (adev->pdev->revision == 0xf1)) ||
807 ((adev->pdev->device == 0x6938) && (adev->pdev->revision == 0xf1)))
808 strcpy(fw_name, "amdgpu/tonga_k_smc.bin");
809 else
810 strcpy(fw_name, "amdgpu/tonga_smc.bin");
802 break; 811 break;
803 case CHIP_FIJI: 812 case CHIP_FIJI:
804 strcpy(fw_name, "amdgpu/fiji_smc.bin"); 813 strcpy(fw_name, "amdgpu/fiji_smc.bin");
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c
index 2e3a0543760d..086aa5c9c634 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c
@@ -765,14 +765,20 @@ amdgpu_connector_lvds_detect(struct drm_connector *connector, bool force)
765 return ret; 765 return ret;
766} 766}
767 767
768static void amdgpu_connector_destroy(struct drm_connector *connector) 768static void amdgpu_connector_unregister(struct drm_connector *connector)
769{ 769{
770 struct amdgpu_connector *amdgpu_connector = to_amdgpu_connector(connector); 770 struct amdgpu_connector *amdgpu_connector = to_amdgpu_connector(connector);
771 771
772 if (amdgpu_connector->ddc_bus->has_aux) { 772 if (amdgpu_connector->ddc_bus && amdgpu_connector->ddc_bus->has_aux) {
773 drm_dp_aux_unregister(&amdgpu_connector->ddc_bus->aux); 773 drm_dp_aux_unregister(&amdgpu_connector->ddc_bus->aux);
774 amdgpu_connector->ddc_bus->has_aux = false; 774 amdgpu_connector->ddc_bus->has_aux = false;
775 } 775 }
776}
777
778static void amdgpu_connector_destroy(struct drm_connector *connector)
779{
780 struct amdgpu_connector *amdgpu_connector = to_amdgpu_connector(connector);
781
776 amdgpu_connector_free_edid(connector); 782 amdgpu_connector_free_edid(connector);
777 kfree(amdgpu_connector->con_priv); 783 kfree(amdgpu_connector->con_priv);
778 drm_connector_unregister(connector); 784 drm_connector_unregister(connector);
@@ -826,6 +832,7 @@ static const struct drm_connector_funcs amdgpu_connector_lvds_funcs = {
826 .dpms = drm_helper_connector_dpms, 832 .dpms = drm_helper_connector_dpms,
827 .detect = amdgpu_connector_lvds_detect, 833 .detect = amdgpu_connector_lvds_detect,
828 .fill_modes = drm_helper_probe_single_connector_modes, 834 .fill_modes = drm_helper_probe_single_connector_modes,
835 .early_unregister = amdgpu_connector_unregister,
829 .destroy = amdgpu_connector_destroy, 836 .destroy = amdgpu_connector_destroy,
830 .set_property = amdgpu_connector_set_lcd_property, 837 .set_property = amdgpu_connector_set_lcd_property,
831}; 838};
@@ -936,6 +943,7 @@ static const struct drm_connector_funcs amdgpu_connector_vga_funcs = {
936 .dpms = drm_helper_connector_dpms, 943 .dpms = drm_helper_connector_dpms,
937 .detect = amdgpu_connector_vga_detect, 944 .detect = amdgpu_connector_vga_detect,
938 .fill_modes = drm_helper_probe_single_connector_modes, 945 .fill_modes = drm_helper_probe_single_connector_modes,
946 .early_unregister = amdgpu_connector_unregister,
939 .destroy = amdgpu_connector_destroy, 947 .destroy = amdgpu_connector_destroy,
940 .set_property = amdgpu_connector_set_property, 948 .set_property = amdgpu_connector_set_property,
941}; 949};
@@ -1203,6 +1211,7 @@ static const struct drm_connector_funcs amdgpu_connector_dvi_funcs = {
1203 .detect = amdgpu_connector_dvi_detect, 1211 .detect = amdgpu_connector_dvi_detect,
1204 .fill_modes = drm_helper_probe_single_connector_modes, 1212 .fill_modes = drm_helper_probe_single_connector_modes,
1205 .set_property = amdgpu_connector_set_property, 1213 .set_property = amdgpu_connector_set_property,
1214 .early_unregister = amdgpu_connector_unregister,
1206 .destroy = amdgpu_connector_destroy, 1215 .destroy = amdgpu_connector_destroy,
1207 .force = amdgpu_connector_dvi_force, 1216 .force = amdgpu_connector_dvi_force,
1208}; 1217};
@@ -1493,6 +1502,7 @@ static const struct drm_connector_funcs amdgpu_connector_dp_funcs = {
1493 .detect = amdgpu_connector_dp_detect, 1502 .detect = amdgpu_connector_dp_detect,
1494 .fill_modes = drm_helper_probe_single_connector_modes, 1503 .fill_modes = drm_helper_probe_single_connector_modes,
1495 .set_property = amdgpu_connector_set_property, 1504 .set_property = amdgpu_connector_set_property,
1505 .early_unregister = amdgpu_connector_unregister,
1496 .destroy = amdgpu_connector_destroy, 1506 .destroy = amdgpu_connector_destroy,
1497 .force = amdgpu_connector_dvi_force, 1507 .force = amdgpu_connector_dvi_force,
1498}; 1508};
@@ -1502,6 +1512,7 @@ static const struct drm_connector_funcs amdgpu_connector_edp_funcs = {
1502 .detect = amdgpu_connector_dp_detect, 1512 .detect = amdgpu_connector_dp_detect,
1503 .fill_modes = drm_helper_probe_single_connector_modes, 1513 .fill_modes = drm_helper_probe_single_connector_modes,
1504 .set_property = amdgpu_connector_set_lcd_property, 1514 .set_property = amdgpu_connector_set_lcd_property,
1515 .early_unregister = amdgpu_connector_unregister,
1505 .destroy = amdgpu_connector_destroy, 1516 .destroy = amdgpu_connector_destroy,
1506 .force = amdgpu_connector_dvi_force, 1517 .force = amdgpu_connector_dvi_force,
1507}; 1518};
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
index b0f6e6957536..82dc8d20e28a 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
@@ -519,7 +519,8 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
519 r = ttm_eu_reserve_buffers(&p->ticket, &p->validated, true, 519 r = ttm_eu_reserve_buffers(&p->ticket, &p->validated, true,
520 &duplicates); 520 &duplicates);
521 if (unlikely(r != 0)) { 521 if (unlikely(r != 0)) {
522 DRM_ERROR("ttm_eu_reserve_buffers failed.\n"); 522 if (r != -ERESTARTSYS)
523 DRM_ERROR("ttm_eu_reserve_buffers failed.\n");
523 goto error_free_pages; 524 goto error_free_pages;
524 } 525 }
525 526
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
index e203e5561107..a5e2fcbef0f0 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
@@ -43,6 +43,9 @@ static int amdgpu_ctx_init(struct amdgpu_device *adev, struct amdgpu_ctx *ctx)
43 ctx->rings[i].sequence = 1; 43 ctx->rings[i].sequence = 1;
44 ctx->rings[i].fences = &ctx->fences[amdgpu_sched_jobs * i]; 44 ctx->rings[i].fences = &ctx->fences[amdgpu_sched_jobs * i];
45 } 45 }
46
47 ctx->reset_counter = atomic_read(&adev->gpu_reset_counter);
48
46 /* create context entity for each ring */ 49 /* create context entity for each ring */
47 for (i = 0; i < adev->num_rings; i++) { 50 for (i = 0; i < adev->num_rings; i++) {
48 struct amdgpu_ring *ring = adev->rings[i]; 51 struct amdgpu_ring *ring = adev->rings[i];
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index 7dbe85d67d26..e41d4baebf86 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -658,12 +658,10 @@ static bool amdgpu_vpost_needed(struct amdgpu_device *adev)
658 return false; 658 return false;
659 659
660 if (amdgpu_passthrough(adev)) { 660 if (amdgpu_passthrough(adev)) {
661 /* for FIJI: In whole GPU pass-through virtualization case 661 /* for FIJI: In whole GPU pass-through virtualization case, after VM reboot
662 * old smc fw won't clear some registers (e.g. MEM_SIZE, BIOS_SCRATCH) 662 * some old smc fw still need driver do vPost otherwise gpu hang, while
663 * so amdgpu_card_posted return false and driver will incorrectly skip vPost. 663 * those smc fw version above 22.15 doesn't have this flaw, so we force
664 * but if we force vPost do in pass-through case, the driver reload will hang. 664 * vpost executed for smc version below 22.15
665 * whether doing vPost depends on amdgpu_card_posted if smc version is above
666 * 00160e00 for FIJI.
667 */ 665 */
668 if (adev->asic_type == CHIP_FIJI) { 666 if (adev->asic_type == CHIP_FIJI) {
669 int err; 667 int err;
@@ -674,22 +672,11 @@ static bool amdgpu_vpost_needed(struct amdgpu_device *adev)
674 return true; 672 return true;
675 673
676 fw_ver = *((uint32_t *)adev->pm.fw->data + 69); 674 fw_ver = *((uint32_t *)adev->pm.fw->data + 69);
677 if (fw_ver >= 0x00160e00) 675 if (fw_ver < 0x00160e00)
678 return !amdgpu_card_posted(adev); 676 return true;
679 } 677 }
680 } else {
681 /* in bare-metal case, amdgpu_card_posted return false
682 * after system reboot/boot, and return true if driver
683 * reloaded.
684 * we shouldn't do vPost after driver reload otherwise GPU
685 * could hang.
686 */
687 if (amdgpu_card_posted(adev))
688 return false;
689 } 678 }
690 679 return !amdgpu_card_posted(adev);
691 /* we assume vPost is neede for all other cases */
692 return true;
693} 680}
694 681
695/** 682/**
@@ -1408,16 +1395,6 @@ static int amdgpu_late_init(struct amdgpu_device *adev)
1408 for (i = 0; i < adev->num_ip_blocks; i++) { 1395 for (i = 0; i < adev->num_ip_blocks; i++) {
1409 if (!adev->ip_block_status[i].valid) 1396 if (!adev->ip_block_status[i].valid)
1410 continue; 1397 continue;
1411 if (adev->ip_blocks[i].type == AMD_IP_BLOCK_TYPE_UVD ||
1412 adev->ip_blocks[i].type == AMD_IP_BLOCK_TYPE_VCE)
1413 continue;
1414 /* enable clockgating to save power */
1415 r = adev->ip_blocks[i].funcs->set_clockgating_state((void *)adev,
1416 AMD_CG_STATE_GATE);
1417 if (r) {
1418 DRM_ERROR("set_clockgating_state(gate) of IP block <%s> failed %d\n", adev->ip_blocks[i].funcs->name, r);
1419 return r;
1420 }
1421 if (adev->ip_blocks[i].funcs->late_init) { 1398 if (adev->ip_blocks[i].funcs->late_init) {
1422 r = adev->ip_blocks[i].funcs->late_init((void *)adev); 1399 r = adev->ip_blocks[i].funcs->late_init((void *)adev);
1423 if (r) { 1400 if (r) {
@@ -1426,6 +1403,18 @@ static int amdgpu_late_init(struct amdgpu_device *adev)
1426 } 1403 }
1427 adev->ip_block_status[i].late_initialized = true; 1404 adev->ip_block_status[i].late_initialized = true;
1428 } 1405 }
1406 /* skip CG for VCE/UVD, it's handled specially */
1407 if (adev->ip_blocks[i].type != AMD_IP_BLOCK_TYPE_UVD &&
1408 adev->ip_blocks[i].type != AMD_IP_BLOCK_TYPE_VCE) {
1409 /* enable clockgating to save power */
1410 r = adev->ip_blocks[i].funcs->set_clockgating_state((void *)adev,
1411 AMD_CG_STATE_GATE);
1412 if (r) {
1413 DRM_ERROR("set_clockgating_state(gate) of IP block <%s> failed %d\n",
1414 adev->ip_blocks[i].funcs->name, r);
1415 return r;
1416 }
1417 }
1429 } 1418 }
1430 1419
1431 return 0; 1420 return 0;
@@ -1435,6 +1424,30 @@ static int amdgpu_fini(struct amdgpu_device *adev)
1435{ 1424{
1436 int i, r; 1425 int i, r;
1437 1426
1427 /* need to disable SMC first */
1428 for (i = 0; i < adev->num_ip_blocks; i++) {
1429 if (!adev->ip_block_status[i].hw)
1430 continue;
1431 if (adev->ip_blocks[i].type == AMD_IP_BLOCK_TYPE_SMC) {
1432 /* ungate blocks before hw fini so that we can shutdown the blocks safely */
1433 r = adev->ip_blocks[i].funcs->set_clockgating_state((void *)adev,
1434 AMD_CG_STATE_UNGATE);
1435 if (r) {
1436 DRM_ERROR("set_clockgating_state(ungate) of IP block <%s> failed %d\n",
1437 adev->ip_blocks[i].funcs->name, r);
1438 return r;
1439 }
1440 r = adev->ip_blocks[i].funcs->hw_fini((void *)adev);
1441 /* XXX handle errors */
1442 if (r) {
1443 DRM_DEBUG("hw_fini of IP block <%s> failed %d\n",
1444 adev->ip_blocks[i].funcs->name, r);
1445 }
1446 adev->ip_block_status[i].hw = false;
1447 break;
1448 }
1449 }
1450
1438 for (i = adev->num_ip_blocks - 1; i >= 0; i--) { 1451 for (i = adev->num_ip_blocks - 1; i >= 0; i--) {
1439 if (!adev->ip_block_status[i].hw) 1452 if (!adev->ip_block_status[i].hw)
1440 continue; 1453 continue;
@@ -1480,7 +1493,7 @@ static int amdgpu_fini(struct amdgpu_device *adev)
1480 return 0; 1493 return 0;
1481} 1494}
1482 1495
1483static int amdgpu_suspend(struct amdgpu_device *adev) 1496int amdgpu_suspend(struct amdgpu_device *adev)
1484{ 1497{
1485 int i, r; 1498 int i, r;
1486 1499
@@ -1933,6 +1946,7 @@ int amdgpu_device_suspend(struct drm_device *dev, bool suspend, bool fbcon)
1933 /* evict remaining vram memory */ 1946 /* evict remaining vram memory */
1934 amdgpu_bo_evict_vram(adev); 1947 amdgpu_bo_evict_vram(adev);
1935 1948
1949 amdgpu_atombios_scratch_regs_save(adev);
1936 pci_save_state(dev->pdev); 1950 pci_save_state(dev->pdev);
1937 if (suspend) { 1951 if (suspend) {
1938 /* Shut down the device */ 1952 /* Shut down the device */
@@ -1984,6 +1998,7 @@ int amdgpu_device_resume(struct drm_device *dev, bool resume, bool fbcon)
1984 return r; 1998 return r;
1985 } 1999 }
1986 } 2000 }
2001 amdgpu_atombios_scratch_regs_restore(adev);
1987 2002
1988 /* post card */ 2003 /* post card */
1989 if (!amdgpu_card_posted(adev) || !resume) { 2004 if (!amdgpu_card_posted(adev) || !resume) {
@@ -2073,7 +2088,8 @@ static bool amdgpu_check_soft_reset(struct amdgpu_device *adev)
2073 if (!adev->ip_block_status[i].valid) 2088 if (!adev->ip_block_status[i].valid)
2074 continue; 2089 continue;
2075 if (adev->ip_blocks[i].funcs->check_soft_reset) 2090 if (adev->ip_blocks[i].funcs->check_soft_reset)
2076 adev->ip_blocks[i].funcs->check_soft_reset(adev); 2091 adev->ip_block_status[i].hang =
2092 adev->ip_blocks[i].funcs->check_soft_reset(adev);
2077 if (adev->ip_block_status[i].hang) { 2093 if (adev->ip_block_status[i].hang) {
2078 DRM_INFO("IP block:%d is hang!\n", i); 2094 DRM_INFO("IP block:%d is hang!\n", i);
2079 asic_hang = true; 2095 asic_hang = true;
@@ -2102,12 +2118,20 @@ static int amdgpu_pre_soft_reset(struct amdgpu_device *adev)
2102 2118
2103static bool amdgpu_need_full_reset(struct amdgpu_device *adev) 2119static bool amdgpu_need_full_reset(struct amdgpu_device *adev)
2104{ 2120{
2105 if (adev->ip_block_status[AMD_IP_BLOCK_TYPE_GMC].hang || 2121 int i;
2106 adev->ip_block_status[AMD_IP_BLOCK_TYPE_SMC].hang || 2122
2107 adev->ip_block_status[AMD_IP_BLOCK_TYPE_ACP].hang || 2123 for (i = 0; i < adev->num_ip_blocks; i++) {
2108 adev->ip_block_status[AMD_IP_BLOCK_TYPE_DCE].hang) { 2124 if (!adev->ip_block_status[i].valid)
2109 DRM_INFO("Some block need full reset!\n"); 2125 continue;
2110 return true; 2126 if ((adev->ip_blocks[i].type == AMD_IP_BLOCK_TYPE_GMC) ||
2127 (adev->ip_blocks[i].type == AMD_IP_BLOCK_TYPE_SMC) ||
2128 (adev->ip_blocks[i].type == AMD_IP_BLOCK_TYPE_ACP) ||
2129 (adev->ip_blocks[i].type == AMD_IP_BLOCK_TYPE_DCE)) {
2130 if (adev->ip_block_status[i].hang) {
2131 DRM_INFO("Some block need full reset!\n");
2132 return true;
2133 }
2134 }
2111 } 2135 }
2112 return false; 2136 return false;
2113} 2137}
@@ -2233,8 +2257,6 @@ int amdgpu_gpu_reset(struct amdgpu_device *adev)
2233 } 2257 }
2234 2258
2235 if (need_full_reset) { 2259 if (need_full_reset) {
2236 /* save scratch */
2237 amdgpu_atombios_scratch_regs_save(adev);
2238 r = amdgpu_suspend(adev); 2260 r = amdgpu_suspend(adev);
2239 2261
2240retry: 2262retry:
@@ -2244,8 +2266,9 @@ retry:
2244 amdgpu_display_stop_mc_access(adev, &save); 2266 amdgpu_display_stop_mc_access(adev, &save);
2245 amdgpu_wait_for_idle(adev, AMD_IP_BLOCK_TYPE_GMC); 2267 amdgpu_wait_for_idle(adev, AMD_IP_BLOCK_TYPE_GMC);
2246 } 2268 }
2247 2269 amdgpu_atombios_scratch_regs_save(adev);
2248 r = amdgpu_asic_reset(adev); 2270 r = amdgpu_asic_reset(adev);
2271 amdgpu_atombios_scratch_regs_restore(adev);
2249 /* post card */ 2272 /* post card */
2250 amdgpu_atom_asic_init(adev->mode_info.atom_context); 2273 amdgpu_atom_asic_init(adev->mode_info.atom_context);
2251 2274
@@ -2253,8 +2276,6 @@ retry:
2253 dev_info(adev->dev, "GPU reset succeeded, trying to resume\n"); 2276 dev_info(adev->dev, "GPU reset succeeded, trying to resume\n");
2254 r = amdgpu_resume(adev); 2277 r = amdgpu_resume(adev);
2255 } 2278 }
2256 /* restore scratch */
2257 amdgpu_atombios_scratch_regs_restore(adev);
2258 } 2279 }
2259 if (!r) { 2280 if (!r) {
2260 amdgpu_irq_gpu_reset_resume_helper(adev); 2281 amdgpu_irq_gpu_reset_resume_helper(adev);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.c
index fe36caf1b7d7..14f57d9915e3 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.c
@@ -113,24 +113,26 @@ void amdgpu_dpm_print_ps_status(struct amdgpu_device *adev,
113 printk("\n"); 113 printk("\n");
114} 114}
115 115
116
116u32 amdgpu_dpm_get_vblank_time(struct amdgpu_device *adev) 117u32 amdgpu_dpm_get_vblank_time(struct amdgpu_device *adev)
117{ 118{
118 struct drm_device *dev = adev->ddev; 119 struct drm_device *dev = adev->ddev;
119 struct drm_crtc *crtc; 120 struct drm_crtc *crtc;
120 struct amdgpu_crtc *amdgpu_crtc; 121 struct amdgpu_crtc *amdgpu_crtc;
121 u32 line_time_us, vblank_lines; 122 u32 vblank_in_pixels;
122 u32 vblank_time_us = 0xffffffff; /* if the displays are off, vblank time is max */ 123 u32 vblank_time_us = 0xffffffff; /* if the displays are off, vblank time is max */
123 124
124 if (adev->mode_info.num_crtc && adev->mode_info.mode_config_initialized) { 125 if (adev->mode_info.num_crtc && adev->mode_info.mode_config_initialized) {
125 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { 126 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
126 amdgpu_crtc = to_amdgpu_crtc(crtc); 127 amdgpu_crtc = to_amdgpu_crtc(crtc);
127 if (crtc->enabled && amdgpu_crtc->enabled && amdgpu_crtc->hw_mode.clock) { 128 if (crtc->enabled && amdgpu_crtc->enabled && amdgpu_crtc->hw_mode.clock) {
128 line_time_us = (amdgpu_crtc->hw_mode.crtc_htotal * 1000) / 129 vblank_in_pixels =
129 amdgpu_crtc->hw_mode.clock; 130 amdgpu_crtc->hw_mode.crtc_htotal *
130 vblank_lines = amdgpu_crtc->hw_mode.crtc_vblank_end - 131 (amdgpu_crtc->hw_mode.crtc_vblank_end -
131 amdgpu_crtc->hw_mode.crtc_vdisplay + 132 amdgpu_crtc->hw_mode.crtc_vdisplay +
132 (amdgpu_crtc->v_border * 2); 133 (amdgpu_crtc->v_border * 2));
133 vblank_time_us = vblank_lines * line_time_us; 134
135 vblank_time_us = vblank_in_pixels * 1000 / amdgpu_crtc->hw_mode.clock;
134 break; 136 break;
135 } 137 }
136 } 138 }
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
index 71ed27eb3dde..e0890deccb2f 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
@@ -479,12 +479,15 @@ amdgpu_pci_remove(struct pci_dev *pdev)
479static void 479static void
480amdgpu_pci_shutdown(struct pci_dev *pdev) 480amdgpu_pci_shutdown(struct pci_dev *pdev)
481{ 481{
482 struct drm_device *dev = pci_get_drvdata(pdev);
483 struct amdgpu_device *adev = dev->dev_private;
484
482 /* if we are running in a VM, make sure the device 485 /* if we are running in a VM, make sure the device
483 * torn down properly on reboot/shutdown. 486 * torn down properly on reboot/shutdown.
484 * unfortunately we can't detect certain 487 * unfortunately we can't detect certain
485 * hypervisors so just do this all the time. 488 * hypervisors so just do this all the time.
486 */ 489 */
487 amdgpu_pci_remove(pdev); 490 amdgpu_suspend(adev);
488} 491}
489 492
490static int amdgpu_pmops_suspend(struct device *dev) 493static int amdgpu_pmops_suspend(struct device *dev)
@@ -735,8 +738,20 @@ static struct pci_driver amdgpu_kms_pci_driver = {
735 738
736static int __init amdgpu_init(void) 739static int __init amdgpu_init(void)
737{ 740{
738 amdgpu_sync_init(); 741 int r;
739 amdgpu_fence_slab_init(); 742
743 r = amdgpu_sync_init();
744 if (r)
745 goto error_sync;
746
747 r = amdgpu_fence_slab_init();
748 if (r)
749 goto error_fence;
750
751 r = amd_sched_fence_slab_init();
752 if (r)
753 goto error_sched;
754
740 if (vgacon_text_force()) { 755 if (vgacon_text_force()) {
741 DRM_ERROR("VGACON disables amdgpu kernel modesetting.\n"); 756 DRM_ERROR("VGACON disables amdgpu kernel modesetting.\n");
742 return -EINVAL; 757 return -EINVAL;
@@ -748,6 +763,15 @@ static int __init amdgpu_init(void)
748 amdgpu_register_atpx_handler(); 763 amdgpu_register_atpx_handler();
749 /* let modprobe override vga console setting */ 764 /* let modprobe override vga console setting */
750 return drm_pci_init(driver, pdriver); 765 return drm_pci_init(driver, pdriver);
766
767error_sched:
768 amdgpu_fence_slab_fini();
769
770error_fence:
771 amdgpu_sync_fini();
772
773error_sync:
774 return r;
751} 775}
752 776
753static void __exit amdgpu_exit(void) 777static void __exit amdgpu_exit(void)
@@ -756,6 +780,7 @@ static void __exit amdgpu_exit(void)
756 drm_pci_exit(driver, pdriver); 780 drm_pci_exit(driver, pdriver);
757 amdgpu_unregister_atpx_handler(); 781 amdgpu_unregister_atpx_handler();
758 amdgpu_sync_fini(); 782 amdgpu_sync_fini();
783 amd_sched_fence_slab_fini();
759 amdgpu_fence_slab_fini(); 784 amdgpu_fence_slab_fini();
760} 785}
761 786
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c
index 3a2e42f4b897..77b34ec92632 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c
@@ -68,6 +68,7 @@ int amdgpu_fence_slab_init(void)
68 68
69void amdgpu_fence_slab_fini(void) 69void amdgpu_fence_slab_fini(void)
70{ 70{
71 rcu_barrier();
71 kmem_cache_destroy(amdgpu_fence_slab); 72 kmem_cache_destroy(amdgpu_fence_slab);
72} 73}
73/* 74/*
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c
index 278708f5a744..9fa809876339 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c
@@ -239,6 +239,7 @@ int amdgpu_irq_init(struct amdgpu_device *adev)
239 if (r) { 239 if (r) {
240 adev->irq.installed = false; 240 adev->irq.installed = false;
241 flush_work(&adev->hotplug_work); 241 flush_work(&adev->hotplug_work);
242 cancel_work_sync(&adev->reset_work);
242 return r; 243 return r;
243 } 244 }
244 245
@@ -264,6 +265,7 @@ void amdgpu_irq_fini(struct amdgpu_device *adev)
264 if (adev->irq.msi_enabled) 265 if (adev->irq.msi_enabled)
265 pci_disable_msi(adev->pdev); 266 pci_disable_msi(adev->pdev);
266 flush_work(&adev->hotplug_work); 267 flush_work(&adev->hotplug_work);
268 cancel_work_sync(&adev->reset_work);
267 } 269 }
268 270
269 for (i = 0; i < AMDGPU_MAX_IRQ_SRC_ID; ++i) { 271 for (i = 0; i < AMDGPU_MAX_IRQ_SRC_ID; ++i) {
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
index c2c7fb140338..3938fca1ea8e 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
@@ -99,6 +99,8 @@ int amdgpu_driver_load_kms(struct drm_device *dev, unsigned long flags)
99 99
100 if ((amdgpu_runtime_pm != 0) && 100 if ((amdgpu_runtime_pm != 0) &&
101 amdgpu_has_atpx() && 101 amdgpu_has_atpx() &&
102 (amdgpu_is_atpx_hybrid() ||
103 amdgpu_has_atpx_dgpu_power_cntl()) &&
102 ((flags & AMD_IS_APU) == 0)) 104 ((flags & AMD_IS_APU) == 0))
103 flags |= AMD_IS_PX; 105 flags |= AMD_IS_PX;
104 106
@@ -459,10 +461,8 @@ static int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file
459 /* return all clocks in KHz */ 461 /* return all clocks in KHz */
460 dev_info.gpu_counter_freq = amdgpu_asic_get_xclk(adev) * 10; 462 dev_info.gpu_counter_freq = amdgpu_asic_get_xclk(adev) * 10;
461 if (adev->pm.dpm_enabled) { 463 if (adev->pm.dpm_enabled) {
462 dev_info.max_engine_clock = 464 dev_info.max_engine_clock = amdgpu_dpm_get_sclk(adev, false) * 10;
463 adev->pm.dpm.dyn_state.max_clock_voltage_on_ac.sclk * 10; 465 dev_info.max_memory_clock = amdgpu_dpm_get_mclk(adev, false) * 10;
464 dev_info.max_memory_clock =
465 adev->pm.dpm.dyn_state.max_clock_voltage_on_ac.mclk * 10;
466 } else { 466 } else {
467 dev_info.max_engine_clock = adev->pm.default_sclk * 10; 467 dev_info.max_engine_clock = adev->pm.default_sclk * 10;
468 dev_info.max_memory_clock = adev->pm.default_mclk * 10; 468 dev_info.max_memory_clock = adev->pm.default_mclk * 10;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
index aa074fac0c7f..f3efb1c5dae9 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
@@ -754,6 +754,10 @@ static const char *amdgpu_vram_names[] = {
754 754
755int amdgpu_bo_init(struct amdgpu_device *adev) 755int amdgpu_bo_init(struct amdgpu_device *adev)
756{ 756{
757 /* reserve PAT memory space to WC for VRAM */
758 arch_io_reserve_memtype_wc(adev->mc.aper_base,
759 adev->mc.aper_size);
760
757 /* Add an MTRR for the VRAM */ 761 /* Add an MTRR for the VRAM */
758 adev->mc.vram_mtrr = arch_phys_wc_add(adev->mc.aper_base, 762 adev->mc.vram_mtrr = arch_phys_wc_add(adev->mc.aper_base,
759 adev->mc.aper_size); 763 adev->mc.aper_size);
@@ -769,6 +773,7 @@ void amdgpu_bo_fini(struct amdgpu_device *adev)
769{ 773{
770 amdgpu_ttm_fini(adev); 774 amdgpu_ttm_fini(adev);
771 arch_phys_wc_del(adev->mc.vram_mtrr); 775 arch_phys_wc_del(adev->mc.vram_mtrr);
776 arch_io_free_memtype_wc(adev->mc.aper_base, adev->mc.aper_size);
772} 777}
773 778
774int amdgpu_bo_fbdev_mmap(struct amdgpu_bo *bo, 779int amdgpu_bo_fbdev_mmap(struct amdgpu_bo *bo,
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
index 7700dc22f243..3826d5aea0a6 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
@@ -74,20 +74,36 @@ amdgpu_gem_prime_import_sg_table(struct drm_device *dev,
74 if (ret) 74 if (ret)
75 return ERR_PTR(ret); 75 return ERR_PTR(ret);
76 76
77 bo->prime_shared_count = 1;
77 return &bo->gem_base; 78 return &bo->gem_base;
78} 79}
79 80
80int amdgpu_gem_prime_pin(struct drm_gem_object *obj) 81int amdgpu_gem_prime_pin(struct drm_gem_object *obj)
81{ 82{
82 struct amdgpu_bo *bo = gem_to_amdgpu_bo(obj); 83 struct amdgpu_bo *bo = gem_to_amdgpu_bo(obj);
83 int ret = 0; 84 long ret = 0;
84 85
85 ret = amdgpu_bo_reserve(bo, false); 86 ret = amdgpu_bo_reserve(bo, false);
86 if (unlikely(ret != 0)) 87 if (unlikely(ret != 0))
87 return ret; 88 return ret;
88 89
90 /*
91 * Wait for all shared fences to complete before we switch to future
92 * use of exclusive fence on this prime shared bo.
93 */
94 ret = reservation_object_wait_timeout_rcu(bo->tbo.resv, true, false,
95 MAX_SCHEDULE_TIMEOUT);
96 if (unlikely(ret < 0)) {
97 DRM_DEBUG_PRIME("Fence wait failed: %li\n", ret);
98 amdgpu_bo_unreserve(bo);
99 return ret;
100 }
101
89 /* pin buffer into GTT */ 102 /* pin buffer into GTT */
90 ret = amdgpu_bo_pin(bo, AMDGPU_GEM_DOMAIN_GTT, NULL); 103 ret = amdgpu_bo_pin(bo, AMDGPU_GEM_DOMAIN_GTT, NULL);
104 if (likely(ret == 0))
105 bo->prime_shared_count++;
106
91 amdgpu_bo_unreserve(bo); 107 amdgpu_bo_unreserve(bo);
92 return ret; 108 return ret;
93} 109}
@@ -102,6 +118,8 @@ void amdgpu_gem_prime_unpin(struct drm_gem_object *obj)
102 return; 118 return;
103 119
104 amdgpu_bo_unpin(bo); 120 amdgpu_bo_unpin(bo);
121 if (bo->prime_shared_count)
122 bo->prime_shared_count--;
105 amdgpu_bo_unreserve(bo); 123 amdgpu_bo_unreserve(bo);
106} 124}
107 125
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c
index e1fa8731d1e2..3cb5e903cd62 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c
@@ -345,8 +345,8 @@ static int amdgpu_debugfs_ring_init(struct amdgpu_device *adev,
345 ent = debugfs_create_file(name, 345 ent = debugfs_create_file(name,
346 S_IFREG | S_IRUGO, root, 346 S_IFREG | S_IRUGO, root,
347 ring, &amdgpu_debugfs_ring_fops); 347 ring, &amdgpu_debugfs_ring_fops);
348 if (IS_ERR(ent)) 348 if (!ent)
349 return PTR_ERR(ent); 349 return -ENOMEM;
350 350
351 i_size_write(ent->d_inode, ring->ring_size + 12); 351 i_size_write(ent->d_inode, ring->ring_size + 12);
352 ring->ent = ent; 352 ring->ent = ent;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
index 887483b8b818..dcaf691f56b5 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
@@ -555,10 +555,13 @@ struct amdgpu_ttm_tt {
555int amdgpu_ttm_tt_get_user_pages(struct ttm_tt *ttm, struct page **pages) 555int amdgpu_ttm_tt_get_user_pages(struct ttm_tt *ttm, struct page **pages)
556{ 556{
557 struct amdgpu_ttm_tt *gtt = (void *)ttm; 557 struct amdgpu_ttm_tt *gtt = (void *)ttm;
558 int write = !(gtt->userflags & AMDGPU_GEM_USERPTR_READONLY); 558 unsigned int flags = 0;
559 unsigned pinned = 0; 559 unsigned pinned = 0;
560 int r; 560 int r;
561 561
562 if (!(gtt->userflags & AMDGPU_GEM_USERPTR_READONLY))
563 flags |= FOLL_WRITE;
564
562 if (gtt->userflags & AMDGPU_GEM_USERPTR_ANONONLY) { 565 if (gtt->userflags & AMDGPU_GEM_USERPTR_ANONONLY) {
563 /* check that we only use anonymous memory 566 /* check that we only use anonymous memory
564 to prevent problems with writeback */ 567 to prevent problems with writeback */
@@ -581,7 +584,7 @@ int amdgpu_ttm_tt_get_user_pages(struct ttm_tt *ttm, struct page **pages)
581 list_add(&guptask.list, &gtt->guptasks); 584 list_add(&guptask.list, &gtt->guptasks);
582 spin_unlock(&gtt->guptasklock); 585 spin_unlock(&gtt->guptasklock);
583 586
584 r = get_user_pages(userptr, num_pages, write, 0, p, NULL); 587 r = get_user_pages(userptr, num_pages, flags, p, NULL);
585 588
586 spin_lock(&gtt->guptasklock); 589 spin_lock(&gtt->guptasklock);
587 list_del(&guptask.list); 590 list_del(&guptask.list);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index 06f24322e7c3..968c4260d7a7 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -1758,5 +1758,6 @@ void amdgpu_vm_manager_fini(struct amdgpu_device *adev)
1758 fence_put(adev->vm_manager.ids[i].first); 1758 fence_put(adev->vm_manager.ids[i].first);
1759 amdgpu_sync_free(&adev->vm_manager.ids[i].active); 1759 amdgpu_sync_free(&adev->vm_manager.ids[i].active);
1760 fence_put(id->flushed_updates); 1760 fence_put(id->flushed_updates);
1761 fence_put(id->last_flush);
1761 } 1762 }
1762} 1763}
diff --git a/drivers/gpu/drm/amd/amdgpu/ci_dpm.c b/drivers/gpu/drm/amd/amdgpu/ci_dpm.c
index 1d8c375a3561..5be788b269e2 100644
--- a/drivers/gpu/drm/amd/amdgpu/ci_dpm.c
+++ b/drivers/gpu/drm/amd/amdgpu/ci_dpm.c
@@ -4075,7 +4075,7 @@ static int ci_enable_uvd_dpm(struct amdgpu_device *adev, bool enable)
4075 pi->dpm_level_enable_mask.mclk_dpm_enable_mask); 4075 pi->dpm_level_enable_mask.mclk_dpm_enable_mask);
4076 } 4076 }
4077 } else { 4077 } else {
4078 if (pi->last_mclk_dpm_enable_mask & 0x1) { 4078 if (pi->uvd_enabled) {
4079 pi->uvd_enabled = false; 4079 pi->uvd_enabled = false;
4080 pi->dpm_level_enable_mask.mclk_dpm_enable_mask |= 1; 4080 pi->dpm_level_enable_mask.mclk_dpm_enable_mask |= 1;
4081 amdgpu_ci_send_msg_to_smc_with_parameter(adev, 4081 amdgpu_ci_send_msg_to_smc_with_parameter(adev,
@@ -6236,6 +6236,8 @@ static int ci_dpm_sw_fini(void *handle)
6236{ 6236{
6237 struct amdgpu_device *adev = (struct amdgpu_device *)handle; 6237 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
6238 6238
6239 flush_work(&adev->pm.dpm.thermal.work);
6240
6239 mutex_lock(&adev->pm.mutex); 6241 mutex_lock(&adev->pm.mutex);
6240 amdgpu_pm_sysfs_fini(adev); 6242 amdgpu_pm_sysfs_fini(adev);
6241 ci_dpm_fini(adev); 6243 ci_dpm_fini(adev);
diff --git a/drivers/gpu/drm/amd/amdgpu/cz_dpm.c b/drivers/gpu/drm/amd/amdgpu/cz_dpm.c
index f80a0834e889..3c082e143730 100644
--- a/drivers/gpu/drm/amd/amdgpu/cz_dpm.c
+++ b/drivers/gpu/drm/amd/amdgpu/cz_dpm.c
@@ -1514,14 +1514,16 @@ static int cz_dpm_set_powergating_state(void *handle,
1514 return 0; 1514 return 0;
1515} 1515}
1516 1516
1517/* borrowed from KV, need future unify */
1518static int cz_dpm_get_temperature(struct amdgpu_device *adev) 1517static int cz_dpm_get_temperature(struct amdgpu_device *adev)
1519{ 1518{
1520 int actual_temp = 0; 1519 int actual_temp = 0;
1521 uint32_t temp = RREG32_SMC(0xC0300E0C); 1520 uint32_t val = RREG32_SMC(ixTHM_TCON_CUR_TMP);
1521 uint32_t temp = REG_GET_FIELD(val, THM_TCON_CUR_TMP, CUR_TEMP);
1522 1522
1523 if (temp) 1523 if (REG_GET_FIELD(val, THM_TCON_CUR_TMP, CUR_TEMP_RANGE_SEL))
1524 actual_temp = 1000 * ((temp / 8) - 49); 1524 actual_temp = 1000 * ((temp / 8) - 49);
1525 else
1526 actual_temp = 1000 * (temp / 8);
1525 1527
1526 return actual_temp; 1528 return actual_temp;
1527} 1529}
diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c b/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c
index 613ebb7ed50f..9260caef74fa 100644
--- a/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c
@@ -3151,10 +3151,6 @@ static int dce_v10_0_hw_fini(void *handle)
3151 3151
3152static int dce_v10_0_suspend(void *handle) 3152static int dce_v10_0_suspend(void *handle)
3153{ 3153{
3154 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
3155
3156 amdgpu_atombios_scratch_regs_save(adev);
3157
3158 return dce_v10_0_hw_fini(handle); 3154 return dce_v10_0_hw_fini(handle);
3159} 3155}
3160 3156
@@ -3165,8 +3161,6 @@ static int dce_v10_0_resume(void *handle)
3165 3161
3166 ret = dce_v10_0_hw_init(handle); 3162 ret = dce_v10_0_hw_init(handle);
3167 3163
3168 amdgpu_atombios_scratch_regs_restore(adev);
3169
3170 /* turn on the BL */ 3164 /* turn on the BL */
3171 if (adev->mode_info.bl_encoder) { 3165 if (adev->mode_info.bl_encoder) {
3172 u8 bl_level = amdgpu_display_backlight_get_level(adev, 3166 u8 bl_level = amdgpu_display_backlight_get_level(adev,
@@ -3188,16 +3182,11 @@ static int dce_v10_0_wait_for_idle(void *handle)
3188 return 0; 3182 return 0;
3189} 3183}
3190 3184
3191static int dce_v10_0_check_soft_reset(void *handle) 3185static bool dce_v10_0_check_soft_reset(void *handle)
3192{ 3186{
3193 struct amdgpu_device *adev = (struct amdgpu_device *)handle; 3187 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
3194 3188
3195 if (dce_v10_0_is_display_hung(adev)) 3189 return dce_v10_0_is_display_hung(adev);
3196 adev->ip_block_status[AMD_IP_BLOCK_TYPE_DCE].hang = true;
3197 else
3198 adev->ip_block_status[AMD_IP_BLOCK_TYPE_DCE].hang = false;
3199
3200 return 0;
3201} 3190}
3202 3191
3203static int dce_v10_0_soft_reset(void *handle) 3192static int dce_v10_0_soft_reset(void *handle)
@@ -3205,9 +3194,6 @@ static int dce_v10_0_soft_reset(void *handle)
3205 u32 srbm_soft_reset = 0, tmp; 3194 u32 srbm_soft_reset = 0, tmp;
3206 struct amdgpu_device *adev = (struct amdgpu_device *)handle; 3195 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
3207 3196
3208 if (!adev->ip_block_status[AMD_IP_BLOCK_TYPE_DCE].hang)
3209 return 0;
3210
3211 if (dce_v10_0_is_display_hung(adev)) 3197 if (dce_v10_0_is_display_hung(adev))
3212 srbm_soft_reset |= SRBM_SOFT_RESET__SOFT_RESET_DC_MASK; 3198 srbm_soft_reset |= SRBM_SOFT_RESET__SOFT_RESET_DC_MASK;
3213 3199
diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c b/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c
index f264b8f17ad1..367739bd1927 100644
--- a/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c
@@ -3215,10 +3215,6 @@ static int dce_v11_0_hw_fini(void *handle)
3215 3215
3216static int dce_v11_0_suspend(void *handle) 3216static int dce_v11_0_suspend(void *handle)
3217{ 3217{
3218 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
3219
3220 amdgpu_atombios_scratch_regs_save(adev);
3221
3222 return dce_v11_0_hw_fini(handle); 3218 return dce_v11_0_hw_fini(handle);
3223} 3219}
3224 3220
@@ -3229,8 +3225,6 @@ static int dce_v11_0_resume(void *handle)
3229 3225
3230 ret = dce_v11_0_hw_init(handle); 3226 ret = dce_v11_0_hw_init(handle);
3231 3227
3232 amdgpu_atombios_scratch_regs_restore(adev);
3233
3234 /* turn on the BL */ 3228 /* turn on the BL */
3235 if (adev->mode_info.bl_encoder) { 3229 if (adev->mode_info.bl_encoder) {
3236 u8 bl_level = amdgpu_display_backlight_get_level(adev, 3230 u8 bl_level = amdgpu_display_backlight_get_level(adev,
diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v6_0.c b/drivers/gpu/drm/amd/amdgpu/dce_v6_0.c
index b948d6cb1399..15f9fc0514b2 100644
--- a/drivers/gpu/drm/amd/amdgpu/dce_v6_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/dce_v6_0.c
@@ -2482,10 +2482,6 @@ static int dce_v6_0_hw_fini(void *handle)
2482 2482
2483static int dce_v6_0_suspend(void *handle) 2483static int dce_v6_0_suspend(void *handle)
2484{ 2484{
2485 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
2486
2487 amdgpu_atombios_scratch_regs_save(adev);
2488
2489 return dce_v6_0_hw_fini(handle); 2485 return dce_v6_0_hw_fini(handle);
2490} 2486}
2491 2487
@@ -2496,8 +2492,6 @@ static int dce_v6_0_resume(void *handle)
2496 2492
2497 ret = dce_v6_0_hw_init(handle); 2493 ret = dce_v6_0_hw_init(handle);
2498 2494
2499 amdgpu_atombios_scratch_regs_restore(adev);
2500
2501 /* turn on the BL */ 2495 /* turn on the BL */
2502 if (adev->mode_info.bl_encoder) { 2496 if (adev->mode_info.bl_encoder) {
2503 u8 bl_level = amdgpu_display_backlight_get_level(adev, 2497 u8 bl_level = amdgpu_display_backlight_get_level(adev,
diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c b/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c
index 5966166ec94c..8c4d808db0f1 100644
--- a/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c
@@ -3033,10 +3033,6 @@ static int dce_v8_0_hw_fini(void *handle)
3033 3033
3034static int dce_v8_0_suspend(void *handle) 3034static int dce_v8_0_suspend(void *handle)
3035{ 3035{
3036 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
3037
3038 amdgpu_atombios_scratch_regs_save(adev);
3039
3040 return dce_v8_0_hw_fini(handle); 3036 return dce_v8_0_hw_fini(handle);
3041} 3037}
3042 3038
@@ -3047,8 +3043,6 @@ static int dce_v8_0_resume(void *handle)
3047 3043
3048 ret = dce_v8_0_hw_init(handle); 3044 ret = dce_v8_0_hw_init(handle);
3049 3045
3050 amdgpu_atombios_scratch_regs_restore(adev);
3051
3052 /* turn on the BL */ 3046 /* turn on the BL */
3053 if (adev->mode_info.bl_encoder) { 3047 if (adev->mode_info.bl_encoder) {
3054 u8 bl_level = amdgpu_display_backlight_get_level(adev, 3048 u8 bl_level = amdgpu_display_backlight_get_level(adev,
diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c b/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
index 6c6ff57b1c95..bb97182dc749 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
@@ -640,7 +640,6 @@ static const u32 stoney_mgcg_cgcg_init[] =
640 mmCP_MEM_SLP_CNTL, 0xffffffff, 0x00020201, 640 mmCP_MEM_SLP_CNTL, 0xffffffff, 0x00020201,
641 mmRLC_MEM_SLP_CNTL, 0xffffffff, 0x00020201, 641 mmRLC_MEM_SLP_CNTL, 0xffffffff, 0x00020201,
642 mmCGTS_SM_CTRL_REG, 0xffffffff, 0x96940200, 642 mmCGTS_SM_CTRL_REG, 0xffffffff, 0x96940200,
643 mmATC_MISC_CG, 0xffffffff, 0x000c0200,
644}; 643};
645 644
646static void gfx_v8_0_set_ring_funcs(struct amdgpu_device *adev); 645static void gfx_v8_0_set_ring_funcs(struct amdgpu_device *adev);
@@ -4087,14 +4086,21 @@ static int gfx_v8_0_rlc_load_microcode(struct amdgpu_device *adev)
4087static int gfx_v8_0_rlc_resume(struct amdgpu_device *adev) 4086static int gfx_v8_0_rlc_resume(struct amdgpu_device *adev)
4088{ 4087{
4089 int r; 4088 int r;
4089 u32 tmp;
4090 4090
4091 gfx_v8_0_rlc_stop(adev); 4091 gfx_v8_0_rlc_stop(adev);
4092 4092
4093 /* disable CG */ 4093 /* disable CG */
4094 WREG32(mmRLC_CGCG_CGLS_CTRL, 0); 4094 tmp = RREG32(mmRLC_CGCG_CGLS_CTRL);
4095 tmp &= ~(RLC_CGCG_CGLS_CTRL__CGCG_EN_MASK |
4096 RLC_CGCG_CGLS_CTRL__CGLS_EN_MASK);
4097 WREG32(mmRLC_CGCG_CGLS_CTRL, tmp);
4095 if (adev->asic_type == CHIP_POLARIS11 || 4098 if (adev->asic_type == CHIP_POLARIS11 ||
4096 adev->asic_type == CHIP_POLARIS10) 4099 adev->asic_type == CHIP_POLARIS10) {
4097 WREG32(mmRLC_CGCG_CGLS_CTRL_3D, 0); 4100 tmp = RREG32(mmRLC_CGCG_CGLS_CTRL_3D);
4101 tmp &= ~0x3;
4102 WREG32(mmRLC_CGCG_CGLS_CTRL_3D, tmp);
4103 }
4098 4104
4099 /* disable PG */ 4105 /* disable PG */
4100 WREG32(mmRLC_PG_CNTL, 0); 4106 WREG32(mmRLC_PG_CNTL, 0);
@@ -5137,7 +5143,7 @@ static int gfx_v8_0_wait_for_idle(void *handle)
5137 return -ETIMEDOUT; 5143 return -ETIMEDOUT;
5138} 5144}
5139 5145
5140static int gfx_v8_0_check_soft_reset(void *handle) 5146static bool gfx_v8_0_check_soft_reset(void *handle)
5141{ 5147{
5142 struct amdgpu_device *adev = (struct amdgpu_device *)handle; 5148 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
5143 u32 grbm_soft_reset = 0, srbm_soft_reset = 0; 5149 u32 grbm_soft_reset = 0, srbm_soft_reset = 0;
@@ -5189,16 +5195,14 @@ static int gfx_v8_0_check_soft_reset(void *handle)
5189 SRBM_SOFT_RESET, SOFT_RESET_SEM, 1); 5195 SRBM_SOFT_RESET, SOFT_RESET_SEM, 1);
5190 5196
5191 if (grbm_soft_reset || srbm_soft_reset) { 5197 if (grbm_soft_reset || srbm_soft_reset) {
5192 adev->ip_block_status[AMD_IP_BLOCK_TYPE_GFX].hang = true;
5193 adev->gfx.grbm_soft_reset = grbm_soft_reset; 5198 adev->gfx.grbm_soft_reset = grbm_soft_reset;
5194 adev->gfx.srbm_soft_reset = srbm_soft_reset; 5199 adev->gfx.srbm_soft_reset = srbm_soft_reset;
5200 return true;
5195 } else { 5201 } else {
5196 adev->ip_block_status[AMD_IP_BLOCK_TYPE_GFX].hang = false;
5197 adev->gfx.grbm_soft_reset = 0; 5202 adev->gfx.grbm_soft_reset = 0;
5198 adev->gfx.srbm_soft_reset = 0; 5203 adev->gfx.srbm_soft_reset = 0;
5204 return false;
5199 } 5205 }
5200
5201 return 0;
5202} 5206}
5203 5207
5204static void gfx_v8_0_inactive_hqd(struct amdgpu_device *adev, 5208static void gfx_v8_0_inactive_hqd(struct amdgpu_device *adev,
@@ -5226,7 +5230,8 @@ static int gfx_v8_0_pre_soft_reset(void *handle)
5226 struct amdgpu_device *adev = (struct amdgpu_device *)handle; 5230 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
5227 u32 grbm_soft_reset = 0, srbm_soft_reset = 0; 5231 u32 grbm_soft_reset = 0, srbm_soft_reset = 0;
5228 5232
5229 if (!adev->ip_block_status[AMD_IP_BLOCK_TYPE_GFX].hang) 5233 if ((!adev->gfx.grbm_soft_reset) &&
5234 (!adev->gfx.srbm_soft_reset))
5230 return 0; 5235 return 0;
5231 5236
5232 grbm_soft_reset = adev->gfx.grbm_soft_reset; 5237 grbm_soft_reset = adev->gfx.grbm_soft_reset;
@@ -5264,7 +5269,8 @@ static int gfx_v8_0_soft_reset(void *handle)
5264 u32 grbm_soft_reset = 0, srbm_soft_reset = 0; 5269 u32 grbm_soft_reset = 0, srbm_soft_reset = 0;
5265 u32 tmp; 5270 u32 tmp;
5266 5271
5267 if (!adev->ip_block_status[AMD_IP_BLOCK_TYPE_GFX].hang) 5272 if ((!adev->gfx.grbm_soft_reset) &&
5273 (!adev->gfx.srbm_soft_reset))
5268 return 0; 5274 return 0;
5269 5275
5270 grbm_soft_reset = adev->gfx.grbm_soft_reset; 5276 grbm_soft_reset = adev->gfx.grbm_soft_reset;
@@ -5334,7 +5340,8 @@ static int gfx_v8_0_post_soft_reset(void *handle)
5334 struct amdgpu_device *adev = (struct amdgpu_device *)handle; 5340 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
5335 u32 grbm_soft_reset = 0, srbm_soft_reset = 0; 5341 u32 grbm_soft_reset = 0, srbm_soft_reset = 0;
5336 5342
5337 if (!adev->ip_block_status[AMD_IP_BLOCK_TYPE_GFX].hang) 5343 if ((!adev->gfx.grbm_soft_reset) &&
5344 (!adev->gfx.srbm_soft_reset))
5338 return 0; 5345 return 0;
5339 5346
5340 grbm_soft_reset = adev->gfx.grbm_soft_reset; 5347 grbm_soft_reset = adev->gfx.grbm_soft_reset;
diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c b/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c
index 1b319f5bc696..a16b2201d52c 100644
--- a/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c
@@ -100,6 +100,7 @@ static const u32 cz_mgcg_cgcg_init[] =
100 100
101static const u32 stoney_mgcg_cgcg_init[] = 101static const u32 stoney_mgcg_cgcg_init[] =
102{ 102{
103 mmATC_MISC_CG, 0xffffffff, 0x000c0200,
103 mmMC_MEM_POWER_LS, 0xffffffff, 0x00000104 104 mmMC_MEM_POWER_LS, 0xffffffff, 0x00000104
104}; 105};
105 106
@@ -1099,7 +1100,7 @@ static int gmc_v8_0_wait_for_idle(void *handle)
1099 1100
1100} 1101}
1101 1102
1102static int gmc_v8_0_check_soft_reset(void *handle) 1103static bool gmc_v8_0_check_soft_reset(void *handle)
1103{ 1104{
1104 u32 srbm_soft_reset = 0; 1105 u32 srbm_soft_reset = 0;
1105 struct amdgpu_device *adev = (struct amdgpu_device *)handle; 1106 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
@@ -1116,20 +1117,19 @@ static int gmc_v8_0_check_soft_reset(void *handle)
1116 SRBM_SOFT_RESET, SOFT_RESET_MC, 1); 1117 SRBM_SOFT_RESET, SOFT_RESET_MC, 1);
1117 } 1118 }
1118 if (srbm_soft_reset) { 1119 if (srbm_soft_reset) {
1119 adev->ip_block_status[AMD_IP_BLOCK_TYPE_GMC].hang = true;
1120 adev->mc.srbm_soft_reset = srbm_soft_reset; 1120 adev->mc.srbm_soft_reset = srbm_soft_reset;
1121 return true;
1121 } else { 1122 } else {
1122 adev->ip_block_status[AMD_IP_BLOCK_TYPE_GMC].hang = false;
1123 adev->mc.srbm_soft_reset = 0; 1123 adev->mc.srbm_soft_reset = 0;
1124 return false;
1124 } 1125 }
1125 return 0;
1126} 1126}
1127 1127
1128static int gmc_v8_0_pre_soft_reset(void *handle) 1128static int gmc_v8_0_pre_soft_reset(void *handle)
1129{ 1129{
1130 struct amdgpu_device *adev = (struct amdgpu_device *)handle; 1130 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1131 1131
1132 if (!adev->ip_block_status[AMD_IP_BLOCK_TYPE_GMC].hang) 1132 if (!adev->mc.srbm_soft_reset)
1133 return 0; 1133 return 0;
1134 1134
1135 gmc_v8_0_mc_stop(adev, &adev->mc.save); 1135 gmc_v8_0_mc_stop(adev, &adev->mc.save);
@@ -1145,7 +1145,7 @@ static int gmc_v8_0_soft_reset(void *handle)
1145 struct amdgpu_device *adev = (struct amdgpu_device *)handle; 1145 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1146 u32 srbm_soft_reset; 1146 u32 srbm_soft_reset;
1147 1147
1148 if (!adev->ip_block_status[AMD_IP_BLOCK_TYPE_GMC].hang) 1148 if (!adev->mc.srbm_soft_reset)
1149 return 0; 1149 return 0;
1150 srbm_soft_reset = adev->mc.srbm_soft_reset; 1150 srbm_soft_reset = adev->mc.srbm_soft_reset;
1151 1151
@@ -1175,7 +1175,7 @@ static int gmc_v8_0_post_soft_reset(void *handle)
1175{ 1175{
1176 struct amdgpu_device *adev = (struct amdgpu_device *)handle; 1176 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1177 1177
1178 if (!adev->ip_block_status[AMD_IP_BLOCK_TYPE_GMC].hang) 1178 if (!adev->mc.srbm_soft_reset)
1179 return 0; 1179 return 0;
1180 1180
1181 gmc_v8_0_mc_resume(adev, &adev->mc.save); 1181 gmc_v8_0_mc_resume(adev, &adev->mc.save);
diff --git a/drivers/gpu/drm/amd/amdgpu/kv_dpm.c b/drivers/gpu/drm/amd/amdgpu/kv_dpm.c
index f8618a3881a8..71d2856222fa 100644
--- a/drivers/gpu/drm/amd/amdgpu/kv_dpm.c
+++ b/drivers/gpu/drm/amd/amdgpu/kv_dpm.c
@@ -3063,6 +3063,8 @@ static int kv_dpm_sw_fini(void *handle)
3063{ 3063{
3064 struct amdgpu_device *adev = (struct amdgpu_device *)handle; 3064 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
3065 3065
3066 flush_work(&adev->pm.dpm.thermal.work);
3067
3066 mutex_lock(&adev->pm.mutex); 3068 mutex_lock(&adev->pm.mutex);
3067 amdgpu_pm_sysfs_fini(adev); 3069 amdgpu_pm_sysfs_fini(adev);
3068 kv_dpm_fini(adev); 3070 kv_dpm_fini(adev);
diff --git a/drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c b/drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c
index f325fd86430b..a9d10941fb53 100644
--- a/drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c
@@ -1268,7 +1268,7 @@ static int sdma_v3_0_wait_for_idle(void *handle)
1268 return -ETIMEDOUT; 1268 return -ETIMEDOUT;
1269} 1269}
1270 1270
1271static int sdma_v3_0_check_soft_reset(void *handle) 1271static bool sdma_v3_0_check_soft_reset(void *handle)
1272{ 1272{
1273 struct amdgpu_device *adev = (struct amdgpu_device *)handle; 1273 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1274 u32 srbm_soft_reset = 0; 1274 u32 srbm_soft_reset = 0;
@@ -1281,14 +1281,12 @@ static int sdma_v3_0_check_soft_reset(void *handle)
1281 } 1281 }
1282 1282
1283 if (srbm_soft_reset) { 1283 if (srbm_soft_reset) {
1284 adev->ip_block_status[AMD_IP_BLOCK_TYPE_SDMA].hang = true;
1285 adev->sdma.srbm_soft_reset = srbm_soft_reset; 1284 adev->sdma.srbm_soft_reset = srbm_soft_reset;
1285 return true;
1286 } else { 1286 } else {
1287 adev->ip_block_status[AMD_IP_BLOCK_TYPE_SDMA].hang = false;
1288 adev->sdma.srbm_soft_reset = 0; 1287 adev->sdma.srbm_soft_reset = 0;
1288 return false;
1289 } 1289 }
1290
1291 return 0;
1292} 1290}
1293 1291
1294static int sdma_v3_0_pre_soft_reset(void *handle) 1292static int sdma_v3_0_pre_soft_reset(void *handle)
@@ -1296,7 +1294,7 @@ static int sdma_v3_0_pre_soft_reset(void *handle)
1296 struct amdgpu_device *adev = (struct amdgpu_device *)handle; 1294 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1297 u32 srbm_soft_reset = 0; 1295 u32 srbm_soft_reset = 0;
1298 1296
1299 if (!adev->ip_block_status[AMD_IP_BLOCK_TYPE_SDMA].hang) 1297 if (!adev->sdma.srbm_soft_reset)
1300 return 0; 1298 return 0;
1301 1299
1302 srbm_soft_reset = adev->sdma.srbm_soft_reset; 1300 srbm_soft_reset = adev->sdma.srbm_soft_reset;
@@ -1315,7 +1313,7 @@ static int sdma_v3_0_post_soft_reset(void *handle)
1315 struct amdgpu_device *adev = (struct amdgpu_device *)handle; 1313 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1316 u32 srbm_soft_reset = 0; 1314 u32 srbm_soft_reset = 0;
1317 1315
1318 if (!adev->ip_block_status[AMD_IP_BLOCK_TYPE_SDMA].hang) 1316 if (!adev->sdma.srbm_soft_reset)
1319 return 0; 1317 return 0;
1320 1318
1321 srbm_soft_reset = adev->sdma.srbm_soft_reset; 1319 srbm_soft_reset = adev->sdma.srbm_soft_reset;
@@ -1335,7 +1333,7 @@ static int sdma_v3_0_soft_reset(void *handle)
1335 u32 srbm_soft_reset = 0; 1333 u32 srbm_soft_reset = 0;
1336 u32 tmp; 1334 u32 tmp;
1337 1335
1338 if (!adev->ip_block_status[AMD_IP_BLOCK_TYPE_SDMA].hang) 1336 if (!adev->sdma.srbm_soft_reset)
1339 return 0; 1337 return 0;
1340 1338
1341 srbm_soft_reset = adev->sdma.srbm_soft_reset; 1339 srbm_soft_reset = adev->sdma.srbm_soft_reset;
diff --git a/drivers/gpu/drm/amd/amdgpu/si_dpm.c b/drivers/gpu/drm/amd/amdgpu/si_dpm.c
index 8bd08925b370..d6f85b1a0b93 100644
--- a/drivers/gpu/drm/amd/amdgpu/si_dpm.c
+++ b/drivers/gpu/drm/amd/amdgpu/si_dpm.c
@@ -3477,6 +3477,49 @@ static void si_apply_state_adjust_rules(struct amdgpu_device *adev,
3477 int i; 3477 int i;
3478 struct si_dpm_quirk *p = si_dpm_quirk_list; 3478 struct si_dpm_quirk *p = si_dpm_quirk_list;
3479 3479
3480 /* limit all SI kickers */
3481 if (adev->asic_type == CHIP_PITCAIRN) {
3482 if ((adev->pdev->revision == 0x81) ||
3483 (adev->pdev->device == 0x6810) ||
3484 (adev->pdev->device == 0x6811) ||
3485 (adev->pdev->device == 0x6816) ||
3486 (adev->pdev->device == 0x6817) ||
3487 (adev->pdev->device == 0x6806))
3488 max_mclk = 120000;
3489 } else if (adev->asic_type == CHIP_VERDE) {
3490 if ((adev->pdev->revision == 0x81) ||
3491 (adev->pdev->revision == 0x83) ||
3492 (adev->pdev->revision == 0x87) ||
3493 (adev->pdev->device == 0x6820) ||
3494 (adev->pdev->device == 0x6821) ||
3495 (adev->pdev->device == 0x6822) ||
3496 (adev->pdev->device == 0x6823) ||
3497 (adev->pdev->device == 0x682A) ||
3498 (adev->pdev->device == 0x682B)) {
3499 max_sclk = 75000;
3500 max_mclk = 80000;
3501 }
3502 } else if (adev->asic_type == CHIP_OLAND) {
3503 if ((adev->pdev->revision == 0xC7) ||
3504 (adev->pdev->revision == 0x80) ||
3505 (adev->pdev->revision == 0x81) ||
3506 (adev->pdev->revision == 0x83) ||
3507 (adev->pdev->device == 0x6604) ||
3508 (adev->pdev->device == 0x6605)) {
3509 max_sclk = 75000;
3510 max_mclk = 80000;
3511 }
3512 } else if (adev->asic_type == CHIP_HAINAN) {
3513 if ((adev->pdev->revision == 0x81) ||
3514 (adev->pdev->revision == 0x83) ||
3515 (adev->pdev->revision == 0xC3) ||
3516 (adev->pdev->device == 0x6664) ||
3517 (adev->pdev->device == 0x6665) ||
3518 (adev->pdev->device == 0x6667)) {
3519 max_sclk = 75000;
3520 max_mclk = 80000;
3521 }
3522 }
3480 /* Apply dpm quirks */ 3523 /* Apply dpm quirks */
3481 while (p && p->chip_device != 0) { 3524 while (p && p->chip_device != 0) {
3482 if (adev->pdev->vendor == p->chip_vendor && 3525 if (adev->pdev->vendor == p->chip_vendor &&
@@ -3489,16 +3532,6 @@ static void si_apply_state_adjust_rules(struct amdgpu_device *adev,
3489 } 3532 }
3490 ++p; 3533 ++p;
3491 } 3534 }
3492 /* limit mclk on all R7 370 parts for stability */
3493 if (adev->pdev->device == 0x6811 &&
3494 adev->pdev->revision == 0x81)
3495 max_mclk = 120000;
3496 /* limit sclk/mclk on Jet parts for stability */
3497 if (adev->pdev->device == 0x6665 &&
3498 adev->pdev->revision == 0xc3) {
3499 max_sclk = 75000;
3500 max_mclk = 80000;
3501 }
3502 3535
3503 if (rps->vce_active) { 3536 if (rps->vce_active) {
3504 rps->evclk = adev->pm.dpm.vce_states[adev->pm.dpm.vce_level].evclk; 3537 rps->evclk = adev->pm.dpm.vce_states[adev->pm.dpm.vce_level].evclk;
@@ -7771,6 +7804,8 @@ static int si_dpm_sw_fini(void *handle)
7771{ 7804{
7772 struct amdgpu_device *adev = (struct amdgpu_device *)handle; 7805 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
7773 7806
7807 flush_work(&adev->pm.dpm.thermal.work);
7808
7774 mutex_lock(&adev->pm.mutex); 7809 mutex_lock(&adev->pm.mutex);
7775 amdgpu_pm_sysfs_fini(adev); 7810 amdgpu_pm_sysfs_fini(adev);
7776 si_dpm_fini(adev); 7811 si_dpm_fini(adev);
diff --git a/drivers/gpu/drm/amd/amdgpu/tonga_ih.c b/drivers/gpu/drm/amd/amdgpu/tonga_ih.c
index d127d59f953a..b4ea229bb449 100644
--- a/drivers/gpu/drm/amd/amdgpu/tonga_ih.c
+++ b/drivers/gpu/drm/amd/amdgpu/tonga_ih.c
@@ -373,7 +373,7 @@ static int tonga_ih_wait_for_idle(void *handle)
373 return -ETIMEDOUT; 373 return -ETIMEDOUT;
374} 374}
375 375
376static int tonga_ih_check_soft_reset(void *handle) 376static bool tonga_ih_check_soft_reset(void *handle)
377{ 377{
378 struct amdgpu_device *adev = (struct amdgpu_device *)handle; 378 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
379 u32 srbm_soft_reset = 0; 379 u32 srbm_soft_reset = 0;
@@ -384,21 +384,19 @@ static int tonga_ih_check_soft_reset(void *handle)
384 SOFT_RESET_IH, 1); 384 SOFT_RESET_IH, 1);
385 385
386 if (srbm_soft_reset) { 386 if (srbm_soft_reset) {
387 adev->ip_block_status[AMD_IP_BLOCK_TYPE_IH].hang = true;
388 adev->irq.srbm_soft_reset = srbm_soft_reset; 387 adev->irq.srbm_soft_reset = srbm_soft_reset;
388 return true;
389 } else { 389 } else {
390 adev->ip_block_status[AMD_IP_BLOCK_TYPE_IH].hang = false;
391 adev->irq.srbm_soft_reset = 0; 390 adev->irq.srbm_soft_reset = 0;
391 return false;
392 } 392 }
393
394 return 0;
395} 393}
396 394
397static int tonga_ih_pre_soft_reset(void *handle) 395static int tonga_ih_pre_soft_reset(void *handle)
398{ 396{
399 struct amdgpu_device *adev = (struct amdgpu_device *)handle; 397 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
400 398
401 if (!adev->ip_block_status[AMD_IP_BLOCK_TYPE_IH].hang) 399 if (!adev->irq.srbm_soft_reset)
402 return 0; 400 return 0;
403 401
404 return tonga_ih_hw_fini(adev); 402 return tonga_ih_hw_fini(adev);
@@ -408,7 +406,7 @@ static int tonga_ih_post_soft_reset(void *handle)
408{ 406{
409 struct amdgpu_device *adev = (struct amdgpu_device *)handle; 407 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
410 408
411 if (!adev->ip_block_status[AMD_IP_BLOCK_TYPE_IH].hang) 409 if (!adev->irq.srbm_soft_reset)
412 return 0; 410 return 0;
413 411
414 return tonga_ih_hw_init(adev); 412 return tonga_ih_hw_init(adev);
@@ -419,7 +417,7 @@ static int tonga_ih_soft_reset(void *handle)
419 struct amdgpu_device *adev = (struct amdgpu_device *)handle; 417 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
420 u32 srbm_soft_reset; 418 u32 srbm_soft_reset;
421 419
422 if (!adev->ip_block_status[AMD_IP_BLOCK_TYPE_IH].hang) 420 if (!adev->irq.srbm_soft_reset)
423 return 0; 421 return 0;
424 srbm_soft_reset = adev->irq.srbm_soft_reset; 422 srbm_soft_reset = adev->irq.srbm_soft_reset;
425 423
diff --git a/drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c b/drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c
index e0fd9f21ed95..ab3df6d75656 100644
--- a/drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c
@@ -770,7 +770,7 @@ static int uvd_v6_0_wait_for_idle(void *handle)
770} 770}
771 771
772#define AMDGPU_UVD_STATUS_BUSY_MASK 0xfd 772#define AMDGPU_UVD_STATUS_BUSY_MASK 0xfd
773static int uvd_v6_0_check_soft_reset(void *handle) 773static bool uvd_v6_0_check_soft_reset(void *handle)
774{ 774{
775 struct amdgpu_device *adev = (struct amdgpu_device *)handle; 775 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
776 u32 srbm_soft_reset = 0; 776 u32 srbm_soft_reset = 0;
@@ -782,19 +782,19 @@ static int uvd_v6_0_check_soft_reset(void *handle)
782 srbm_soft_reset = REG_SET_FIELD(srbm_soft_reset, SRBM_SOFT_RESET, SOFT_RESET_UVD, 1); 782 srbm_soft_reset = REG_SET_FIELD(srbm_soft_reset, SRBM_SOFT_RESET, SOFT_RESET_UVD, 1);
783 783
784 if (srbm_soft_reset) { 784 if (srbm_soft_reset) {
785 adev->ip_block_status[AMD_IP_BLOCK_TYPE_UVD].hang = true;
786 adev->uvd.srbm_soft_reset = srbm_soft_reset; 785 adev->uvd.srbm_soft_reset = srbm_soft_reset;
786 return true;
787 } else { 787 } else {
788 adev->ip_block_status[AMD_IP_BLOCK_TYPE_UVD].hang = false;
789 adev->uvd.srbm_soft_reset = 0; 788 adev->uvd.srbm_soft_reset = 0;
789 return false;
790 } 790 }
791 return 0;
792} 791}
792
793static int uvd_v6_0_pre_soft_reset(void *handle) 793static int uvd_v6_0_pre_soft_reset(void *handle)
794{ 794{
795 struct amdgpu_device *adev = (struct amdgpu_device *)handle; 795 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
796 796
797 if (!adev->ip_block_status[AMD_IP_BLOCK_TYPE_UVD].hang) 797 if (!adev->uvd.srbm_soft_reset)
798 return 0; 798 return 0;
799 799
800 uvd_v6_0_stop(adev); 800 uvd_v6_0_stop(adev);
@@ -806,7 +806,7 @@ static int uvd_v6_0_soft_reset(void *handle)
806 struct amdgpu_device *adev = (struct amdgpu_device *)handle; 806 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
807 u32 srbm_soft_reset; 807 u32 srbm_soft_reset;
808 808
809 if (!adev->ip_block_status[AMD_IP_BLOCK_TYPE_UVD].hang) 809 if (!adev->uvd.srbm_soft_reset)
810 return 0; 810 return 0;
811 srbm_soft_reset = adev->uvd.srbm_soft_reset; 811 srbm_soft_reset = adev->uvd.srbm_soft_reset;
812 812
@@ -836,7 +836,7 @@ static int uvd_v6_0_post_soft_reset(void *handle)
836{ 836{
837 struct amdgpu_device *adev = (struct amdgpu_device *)handle; 837 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
838 838
839 if (!adev->ip_block_status[AMD_IP_BLOCK_TYPE_UVD].hang) 839 if (!adev->uvd.srbm_soft_reset)
840 return 0; 840 return 0;
841 841
842 mdelay(5); 842 mdelay(5);
diff --git a/drivers/gpu/drm/amd/amdgpu/vce_v3_0.c b/drivers/gpu/drm/amd/amdgpu/vce_v3_0.c
index 3f6db4ec0102..6feed726e299 100644
--- a/drivers/gpu/drm/amd/amdgpu/vce_v3_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/vce_v3_0.c
@@ -52,6 +52,8 @@
52#define VCE_V3_0_STACK_SIZE (64 * 1024) 52#define VCE_V3_0_STACK_SIZE (64 * 1024)
53#define VCE_V3_0_DATA_SIZE ((16 * 1024 * AMDGPU_MAX_VCE_HANDLES) + (52 * 1024)) 53#define VCE_V3_0_DATA_SIZE ((16 * 1024 * AMDGPU_MAX_VCE_HANDLES) + (52 * 1024))
54 54
55#define FW_52_8_3 ((52 << 24) | (8 << 16) | (3 << 8))
56
55static void vce_v3_0_mc_resume(struct amdgpu_device *adev, int idx); 57static void vce_v3_0_mc_resume(struct amdgpu_device *adev, int idx);
56static void vce_v3_0_set_ring_funcs(struct amdgpu_device *adev); 58static void vce_v3_0_set_ring_funcs(struct amdgpu_device *adev);
57static void vce_v3_0_set_irq_funcs(struct amdgpu_device *adev); 59static void vce_v3_0_set_irq_funcs(struct amdgpu_device *adev);
@@ -382,6 +384,10 @@ static int vce_v3_0_sw_init(void *handle)
382 if (r) 384 if (r)
383 return r; 385 return r;
384 386
387 /* 52.8.3 required for 3 ring support */
388 if (adev->vce.fw_version < FW_52_8_3)
389 adev->vce.num_rings = 2;
390
385 r = amdgpu_vce_resume(adev); 391 r = amdgpu_vce_resume(adev);
386 if (r) 392 if (r)
387 return r; 393 return r;
@@ -561,7 +567,7 @@ static int vce_v3_0_wait_for_idle(void *handle)
561#define AMDGPU_VCE_STATUS_BUSY_MASK (VCE_STATUS_VCPU_REPORT_AUTO_BUSY_MASK | \ 567#define AMDGPU_VCE_STATUS_BUSY_MASK (VCE_STATUS_VCPU_REPORT_AUTO_BUSY_MASK | \
562 VCE_STATUS_VCPU_REPORT_RB0_BUSY_MASK) 568 VCE_STATUS_VCPU_REPORT_RB0_BUSY_MASK)
563 569
564static int vce_v3_0_check_soft_reset(void *handle) 570static bool vce_v3_0_check_soft_reset(void *handle)
565{ 571{
566 struct amdgpu_device *adev = (struct amdgpu_device *)handle; 572 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
567 u32 srbm_soft_reset = 0; 573 u32 srbm_soft_reset = 0;
@@ -591,16 +597,15 @@ static int vce_v3_0_check_soft_reset(void *handle)
591 srbm_soft_reset = REG_SET_FIELD(srbm_soft_reset, SRBM_SOFT_RESET, SOFT_RESET_VCE1, 1); 597 srbm_soft_reset = REG_SET_FIELD(srbm_soft_reset, SRBM_SOFT_RESET, SOFT_RESET_VCE1, 1);
592 } 598 }
593 WREG32_FIELD(GRBM_GFX_INDEX, INSTANCE_INDEX, 0); 599 WREG32_FIELD(GRBM_GFX_INDEX, INSTANCE_INDEX, 0);
600 mutex_unlock(&adev->grbm_idx_mutex);
594 601
595 if (srbm_soft_reset) { 602 if (srbm_soft_reset) {
596 adev->ip_block_status[AMD_IP_BLOCK_TYPE_VCE].hang = true;
597 adev->vce.srbm_soft_reset = srbm_soft_reset; 603 adev->vce.srbm_soft_reset = srbm_soft_reset;
604 return true;
598 } else { 605 } else {
599 adev->ip_block_status[AMD_IP_BLOCK_TYPE_VCE].hang = false;
600 adev->vce.srbm_soft_reset = 0; 606 adev->vce.srbm_soft_reset = 0;
607 return false;
601 } 608 }
602 mutex_unlock(&adev->grbm_idx_mutex);
603 return 0;
604} 609}
605 610
606static int vce_v3_0_soft_reset(void *handle) 611static int vce_v3_0_soft_reset(void *handle)
@@ -608,7 +613,7 @@ static int vce_v3_0_soft_reset(void *handle)
608 struct amdgpu_device *adev = (struct amdgpu_device *)handle; 613 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
609 u32 srbm_soft_reset; 614 u32 srbm_soft_reset;
610 615
611 if (!adev->ip_block_status[AMD_IP_BLOCK_TYPE_VCE].hang) 616 if (!adev->vce.srbm_soft_reset)
612 return 0; 617 return 0;
613 srbm_soft_reset = adev->vce.srbm_soft_reset; 618 srbm_soft_reset = adev->vce.srbm_soft_reset;
614 619
@@ -638,7 +643,7 @@ static int vce_v3_0_pre_soft_reset(void *handle)
638{ 643{
639 struct amdgpu_device *adev = (struct amdgpu_device *)handle; 644 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
640 645
641 if (!adev->ip_block_status[AMD_IP_BLOCK_TYPE_VCE].hang) 646 if (!adev->vce.srbm_soft_reset)
642 return 0; 647 return 0;
643 648
644 mdelay(5); 649 mdelay(5);
@@ -651,7 +656,7 @@ static int vce_v3_0_post_soft_reset(void *handle)
651{ 656{
652 struct amdgpu_device *adev = (struct amdgpu_device *)handle; 657 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
653 658
654 if (!adev->ip_block_status[AMD_IP_BLOCK_TYPE_VCE].hang) 659 if (!adev->vce.srbm_soft_reset)
655 return 0; 660 return 0;
656 661
657 mdelay(5); 662 mdelay(5);
diff --git a/drivers/gpu/drm/amd/amdgpu/vi.c b/drivers/gpu/drm/amd/amdgpu/vi.c
index c0d9aad7126f..f62f1a74f890 100644
--- a/drivers/gpu/drm/amd/amdgpu/vi.c
+++ b/drivers/gpu/drm/amd/amdgpu/vi.c
@@ -80,7 +80,9 @@
80#include "dce_virtual.h" 80#include "dce_virtual.h"
81 81
82MODULE_FIRMWARE("amdgpu/topaz_smc.bin"); 82MODULE_FIRMWARE("amdgpu/topaz_smc.bin");
83MODULE_FIRMWARE("amdgpu/topaz_k_smc.bin");
83MODULE_FIRMWARE("amdgpu/tonga_smc.bin"); 84MODULE_FIRMWARE("amdgpu/tonga_smc.bin");
85MODULE_FIRMWARE("amdgpu/tonga_k_smc.bin");
84MODULE_FIRMWARE("amdgpu/fiji_smc.bin"); 86MODULE_FIRMWARE("amdgpu/fiji_smc.bin");
85MODULE_FIRMWARE("amdgpu/polaris10_smc.bin"); 87MODULE_FIRMWARE("amdgpu/polaris10_smc.bin");
86MODULE_FIRMWARE("amdgpu/polaris10_smc_sk.bin"); 88MODULE_FIRMWARE("amdgpu/polaris10_smc_sk.bin");
@@ -1651,7 +1653,7 @@ static int vi_common_early_init(void *handle)
1651 AMD_CG_SUPPORT_SDMA_MGCG | 1653 AMD_CG_SUPPORT_SDMA_MGCG |
1652 AMD_CG_SUPPORT_SDMA_LS | 1654 AMD_CG_SUPPORT_SDMA_LS |
1653 AMD_CG_SUPPORT_VCE_MGCG; 1655 AMD_CG_SUPPORT_VCE_MGCG;
1654 adev->pg_flags |= AMD_PG_SUPPORT_GFX_PG | 1656 adev->pg_flags = AMD_PG_SUPPORT_GFX_PG |
1655 AMD_PG_SUPPORT_GFX_SMG | 1657 AMD_PG_SUPPORT_GFX_SMG |
1656 AMD_PG_SUPPORT_GFX_PIPELINE | 1658 AMD_PG_SUPPORT_GFX_PIPELINE |
1657 AMD_PG_SUPPORT_UVD | 1659 AMD_PG_SUPPORT_UVD |
diff --git a/drivers/gpu/drm/amd/include/amd_shared.h b/drivers/gpu/drm/amd/include/amd_shared.h
index c934b78c9e2f..bec8125bceb0 100644
--- a/drivers/gpu/drm/amd/include/amd_shared.h
+++ b/drivers/gpu/drm/amd/include/amd_shared.h
@@ -165,7 +165,7 @@ struct amd_ip_funcs {
165 /* poll for idle */ 165 /* poll for idle */
166 int (*wait_for_idle)(void *handle); 166 int (*wait_for_idle)(void *handle);
167 /* check soft reset the IP block */ 167 /* check soft reset the IP block */
168 int (*check_soft_reset)(void *handle); 168 bool (*check_soft_reset)(void *handle);
169 /* pre soft reset the IP block */ 169 /* pre soft reset the IP block */
170 int (*pre_soft_reset)(void *handle); 170 int (*pre_soft_reset)(void *handle);
171 /* soft reset the IP block */ 171 /* soft reset the IP block */
diff --git a/drivers/gpu/drm/amd/powerplay/eventmgr/eventactionchains.c b/drivers/gpu/drm/amd/powerplay/eventmgr/eventactionchains.c
index 92b117843875..8cee4e0f9fde 100644
--- a/drivers/gpu/drm/amd/powerplay/eventmgr/eventactionchains.c
+++ b/drivers/gpu/drm/amd/powerplay/eventmgr/eventactionchains.c
@@ -49,6 +49,7 @@ static const pem_event_action * const uninitialize_event[] = {
49 uninitialize_display_phy_access_tasks, 49 uninitialize_display_phy_access_tasks,
50 disable_gfx_voltage_island_power_gating_tasks, 50 disable_gfx_voltage_island_power_gating_tasks,
51 disable_gfx_clock_gating_tasks, 51 disable_gfx_clock_gating_tasks,
52 uninitialize_thermal_controller_tasks,
52 set_boot_state_tasks, 53 set_boot_state_tasks,
53 adjust_power_state_tasks, 54 adjust_power_state_tasks,
54 disable_dynamic_state_management_tasks, 55 disable_dynamic_state_management_tasks,
diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/cz_hwmgr.c b/drivers/gpu/drm/amd/powerplay/hwmgr/cz_hwmgr.c
index 7e4fcbbbe086..960424913496 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/cz_hwmgr.c
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/cz_hwmgr.c
@@ -1785,6 +1785,21 @@ static int cz_get_max_high_clocks(struct pp_hwmgr *hwmgr, struct amd_pp_simple_c
1785 return 0; 1785 return 0;
1786} 1786}
1787 1787
1788static int cz_thermal_get_temperature(struct pp_hwmgr *hwmgr)
1789{
1790 int actual_temp = 0;
1791 uint32_t val = cgs_read_ind_register(hwmgr->device,
1792 CGS_IND_REG__SMC, ixTHM_TCON_CUR_TMP);
1793 uint32_t temp = PHM_GET_FIELD(val, THM_TCON_CUR_TMP, CUR_TEMP);
1794
1795 if (PHM_GET_FIELD(val, THM_TCON_CUR_TMP, CUR_TEMP_RANGE_SEL))
1796 actual_temp = ((temp / 8) - 49) * PP_TEMPERATURE_UNITS_PER_CENTIGRADES;
1797 else
1798 actual_temp = (temp / 8) * PP_TEMPERATURE_UNITS_PER_CENTIGRADES;
1799
1800 return actual_temp;
1801}
1802
1788static int cz_read_sensor(struct pp_hwmgr *hwmgr, int idx, int32_t *value) 1803static int cz_read_sensor(struct pp_hwmgr *hwmgr, int idx, int32_t *value)
1789{ 1804{
1790 struct cz_hwmgr *cz_hwmgr = (struct cz_hwmgr *)(hwmgr->backend); 1805 struct cz_hwmgr *cz_hwmgr = (struct cz_hwmgr *)(hwmgr->backend);
@@ -1881,6 +1896,9 @@ static int cz_read_sensor(struct pp_hwmgr *hwmgr, int idx, int32_t *value)
1881 case AMDGPU_PP_SENSOR_VCE_POWER: 1896 case AMDGPU_PP_SENSOR_VCE_POWER:
1882 *value = cz_hwmgr->vce_power_gated ? 0 : 1; 1897 *value = cz_hwmgr->vce_power_gated ? 0 : 1;
1883 return 0; 1898 return 0;
1899 case AMDGPU_PP_SENSOR_GPU_TEMP:
1900 *value = cz_thermal_get_temperature(hwmgr);
1901 return 0;
1884 default: 1902 default:
1885 return -EINVAL; 1903 return -EINVAL;
1886 } 1904 }
diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/hardwaremanager.c b/drivers/gpu/drm/amd/powerplay/hwmgr/hardwaremanager.c
index 14f8c1f4da3d..0723758ed065 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/hardwaremanager.c
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/hardwaremanager.c
@@ -272,7 +272,7 @@ bool phm_check_smc_update_required_for_display_configuration(struct pp_hwmgr *hw
272 PHM_FUNC_CHECK(hwmgr); 272 PHM_FUNC_CHECK(hwmgr);
273 273
274 if (hwmgr->hwmgr_func->check_smc_update_required_for_display_configuration == NULL) 274 if (hwmgr->hwmgr_func->check_smc_update_required_for_display_configuration == NULL)
275 return -EINVAL; 275 return false;
276 276
277 return hwmgr->hwmgr_func->check_smc_update_required_for_display_configuration(hwmgr); 277 return hwmgr->hwmgr_func->check_smc_update_required_for_display_configuration(hwmgr);
278} 278}
diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/hwmgr.c b/drivers/gpu/drm/amd/powerplay/hwmgr/hwmgr.c
index 1167205057b3..e03dcb6ea9c1 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/hwmgr.c
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/hwmgr.c
@@ -710,13 +710,15 @@ int phm_get_voltage_evv_on_sclk(struct pp_hwmgr *hwmgr, uint8_t voltage_type,
710 uint32_t vol; 710 uint32_t vol;
711 int ret = 0; 711 int ret = 0;
712 712
713 if (hwmgr->chip_id < CHIP_POLARIS10) { 713 if (hwmgr->chip_id < CHIP_TONGA) {
714 atomctrl_get_voltage_evv_on_sclk(hwmgr, voltage_type, sclk, id, voltage); 714 ret = atomctrl_get_voltage_evv(hwmgr, id, voltage);
715 } else if (hwmgr->chip_id < CHIP_POLARIS10) {
716 ret = atomctrl_get_voltage_evv_on_sclk(hwmgr, voltage_type, sclk, id, voltage);
715 if (*voltage >= 2000 || *voltage == 0) 717 if (*voltage >= 2000 || *voltage == 0)
716 *voltage = 1150; 718 *voltage = 1150;
717 } else { 719 } else {
718 ret = atomctrl_get_voltage_evv_on_sclk_ai(hwmgr, voltage_type, sclk, id, &vol); 720 ret = atomctrl_get_voltage_evv_on_sclk_ai(hwmgr, voltage_type, sclk, id, &vol);
719 *voltage = (uint16_t)vol/100; 721 *voltage = (uint16_t)(vol/100);
720 } 722 }
721 return ret; 723 return ret;
722} 724}
diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/ppatomctrl.c b/drivers/gpu/drm/amd/powerplay/hwmgr/ppatomctrl.c
index 1126bd4f74dc..0894527d932f 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/ppatomctrl.c
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/ppatomctrl.c
@@ -1320,7 +1320,8 @@ int atomctrl_get_voltage_evv_on_sclk_ai(struct pp_hwmgr *hwmgr, uint8_t voltage_
1320 if (0 != result) 1320 if (0 != result)
1321 return result; 1321 return result;
1322 1322
1323 *voltage = le32_to_cpu(((GET_EVV_VOLTAGE_INFO_OUTPUT_PARAMETER_V1_3 *)(&get_voltage_info_param_space))->ulVoltageLevel); 1323 *voltage = le32_to_cpu(((GET_EVV_VOLTAGE_INFO_OUTPUT_PARAMETER_V1_3 *)
1324 (&get_voltage_info_param_space))->ulVoltageLevel);
1324 1325
1325 return result; 1326 return result;
1326} 1327}
diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/process_pptables_v1_0.c b/drivers/gpu/drm/amd/powerplay/hwmgr/process_pptables_v1_0.c
index 7de701d8a450..4477c55a58e3 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/process_pptables_v1_0.c
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/process_pptables_v1_0.c
@@ -1201,12 +1201,15 @@ static uint32_t make_classification_flags(struct pp_hwmgr *hwmgr,
1201static int ppt_get_num_of_vce_state_table_entries_v1_0(struct pp_hwmgr *hwmgr) 1201static int ppt_get_num_of_vce_state_table_entries_v1_0(struct pp_hwmgr *hwmgr)
1202{ 1202{
1203 const ATOM_Tonga_POWERPLAYTABLE *pp_table = get_powerplay_table(hwmgr); 1203 const ATOM_Tonga_POWERPLAYTABLE *pp_table = get_powerplay_table(hwmgr);
1204 const ATOM_Tonga_VCE_State_Table *vce_state_table = 1204 const ATOM_Tonga_VCE_State_Table *vce_state_table;
1205 (ATOM_Tonga_VCE_State_Table *)(((unsigned long)pp_table) + le16_to_cpu(pp_table->usVCEStateTableOffset));
1206 1205
1207 if (vce_state_table == NULL) 1206
1207 if (pp_table == NULL)
1208 return 0; 1208 return 0;
1209 1209
1210 vce_state_table = (void *)pp_table +
1211 le16_to_cpu(pp_table->usVCEStateTableOffset);
1212
1210 return vce_state_table->ucNumEntries; 1213 return vce_state_table->ucNumEntries;
1211} 1214}
1212 1215
diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/smu7_hwmgr.c b/drivers/gpu/drm/amd/powerplay/hwmgr/smu7_hwmgr.c
index 508245d49d33..08cd0bd3ebe5 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/smu7_hwmgr.c
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/smu7_hwmgr.c
@@ -1030,20 +1030,19 @@ static int smu7_disable_sclk_mclk_dpm(struct pp_hwmgr *hwmgr)
1030 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend); 1030 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
1031 1031
1032 /* disable SCLK dpm */ 1032 /* disable SCLK dpm */
1033 if (!data->sclk_dpm_key_disabled) 1033 if (!data->sclk_dpm_key_disabled) {
1034 PP_ASSERT_WITH_CODE( 1034 PP_ASSERT_WITH_CODE(true == smum_is_dpm_running(hwmgr),
1035 (smum_send_msg_to_smc(hwmgr->smumgr, 1035 "Trying to disable SCLK DPM when DPM is disabled",
1036 PPSMC_MSG_DPM_Disable) == 0), 1036 return 0);
1037 "Failed to disable SCLK DPM!", 1037 smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_DPM_Disable);
1038 return -EINVAL); 1038 }
1039 1039
1040 /* disable MCLK dpm */ 1040 /* disable MCLK dpm */
1041 if (!data->mclk_dpm_key_disabled) { 1041 if (!data->mclk_dpm_key_disabled) {
1042 PP_ASSERT_WITH_CODE( 1042 PP_ASSERT_WITH_CODE(true == smum_is_dpm_running(hwmgr),
1043 (smum_send_msg_to_smc(hwmgr->smumgr, 1043 "Trying to disable MCLK DPM when DPM is disabled",
1044 PPSMC_MSG_MCLKDPM_Disable) == 0), 1044 return 0);
1045 "Failed to disable MCLK DPM!", 1045 smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_MCLKDPM_Disable);
1046 return -EINVAL);
1047 } 1046 }
1048 1047
1049 return 0; 1048 return 0;
@@ -1069,10 +1068,13 @@ static int smu7_stop_dpm(struct pp_hwmgr *hwmgr)
1069 return -EINVAL); 1068 return -EINVAL);
1070 } 1069 }
1071 1070
1072 if (smu7_disable_sclk_mclk_dpm(hwmgr)) { 1071 smu7_disable_sclk_mclk_dpm(hwmgr);
1073 printk(KERN_ERR "Failed to disable Sclk DPM and Mclk DPM!"); 1072
1074 return -EINVAL; 1073 PP_ASSERT_WITH_CODE(true == smum_is_dpm_running(hwmgr),
1075 } 1074 "Trying to disable voltage DPM when DPM is disabled",
1075 return 0);
1076
1077 smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_Voltage_Cntl_Disable);
1076 1078
1077 return 0; 1079 return 0;
1078} 1080}
@@ -1166,8 +1168,8 @@ int smu7_enable_dpm_tasks(struct pp_hwmgr *hwmgr)
1166 1168
1167 tmp_result = (!smum_is_dpm_running(hwmgr)) ? 0 : -1; 1169 tmp_result = (!smum_is_dpm_running(hwmgr)) ? 0 : -1;
1168 PP_ASSERT_WITH_CODE(tmp_result == 0, 1170 PP_ASSERT_WITH_CODE(tmp_result == 0,
1169 "DPM is already running right now, no need to enable DPM!", 1171 "DPM is already running",
1170 return 0); 1172 );
1171 1173
1172 if (smu7_voltage_control(hwmgr)) { 1174 if (smu7_voltage_control(hwmgr)) {
1173 tmp_result = smu7_enable_voltage_control(hwmgr); 1175 tmp_result = smu7_enable_voltage_control(hwmgr);
@@ -1226,7 +1228,7 @@ int smu7_enable_dpm_tasks(struct pp_hwmgr *hwmgr)
1226 PP_ASSERT_WITH_CODE((0 == tmp_result), 1228 PP_ASSERT_WITH_CODE((0 == tmp_result),
1227 "Failed to enable VR hot GPIO interrupt!", result = tmp_result); 1229 "Failed to enable VR hot GPIO interrupt!", result = tmp_result);
1228 1230
1229 smum_send_msg_to_smc(hwmgr->smumgr, (PPSMC_Msg)PPSMC_HasDisplay); 1231 smum_send_msg_to_smc(hwmgr->smumgr, (PPSMC_Msg)PPSMC_NoDisplay);
1230 1232
1231 tmp_result = smu7_enable_sclk_control(hwmgr); 1233 tmp_result = smu7_enable_sclk_control(hwmgr);
1232 PP_ASSERT_WITH_CODE((0 == tmp_result), 1234 PP_ASSERT_WITH_CODE((0 == tmp_result),
@@ -1306,6 +1308,12 @@ int smu7_disable_dpm_tasks(struct pp_hwmgr *hwmgr)
1306 PP_ASSERT_WITH_CODE((tmp_result == 0), 1308 PP_ASSERT_WITH_CODE((tmp_result == 0),
1307 "Failed to disable thermal auto throttle!", result = tmp_result); 1309 "Failed to disable thermal auto throttle!", result = tmp_result);
1308 1310
1311 if (1 == PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, FEATURE_STATUS, AVS_ON)) {
1312 PP_ASSERT_WITH_CODE((0 == smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_DisableAvfs)),
1313 "Failed to disable AVFS!",
1314 return -EINVAL);
1315 }
1316
1309 tmp_result = smu7_stop_dpm(hwmgr); 1317 tmp_result = smu7_stop_dpm(hwmgr);
1310 PP_ASSERT_WITH_CODE((tmp_result == 0), 1318 PP_ASSERT_WITH_CODE((tmp_result == 0),
1311 "Failed to stop DPM!", result = tmp_result); 1319 "Failed to stop DPM!", result = tmp_result);
@@ -1452,17 +1460,17 @@ static int smu7_get_evv_voltages(struct pp_hwmgr *hwmgr)
1452 struct phm_ppt_v1_clock_voltage_dependency_table *sclk_table = NULL; 1460 struct phm_ppt_v1_clock_voltage_dependency_table *sclk_table = NULL;
1453 1461
1454 1462
1455 if (table_info != NULL)
1456 sclk_table = table_info->vdd_dep_on_sclk;
1457
1458 for (i = 0; i < SMU7_MAX_LEAKAGE_COUNT; i++) { 1463 for (i = 0; i < SMU7_MAX_LEAKAGE_COUNT; i++) {
1459 vv_id = ATOM_VIRTUAL_VOLTAGE_ID0 + i; 1464 vv_id = ATOM_VIRTUAL_VOLTAGE_ID0 + i;
1460 1465
1461 if (data->vdd_gfx_control == SMU7_VOLTAGE_CONTROL_BY_SVID2) { 1466 if (data->vdd_gfx_control == SMU7_VOLTAGE_CONTROL_BY_SVID2) {
1462 if (0 == phm_get_sclk_for_voltage_evv(hwmgr, 1467 if ((hwmgr->pp_table_version == PP_TABLE_V1)
1468 && !phm_get_sclk_for_voltage_evv(hwmgr,
1463 table_info->vddgfx_lookup_table, vv_id, &sclk)) { 1469 table_info->vddgfx_lookup_table, vv_id, &sclk)) {
1464 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, 1470 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
1465 PHM_PlatformCaps_ClockStretcher)) { 1471 PHM_PlatformCaps_ClockStretcher)) {
1472 sclk_table = table_info->vdd_dep_on_sclk;
1473
1466 for (j = 1; j < sclk_table->count; j++) { 1474 for (j = 1; j < sclk_table->count; j++) {
1467 if (sclk_table->entries[j].clk == sclk && 1475 if (sclk_table->entries[j].clk == sclk &&
1468 sclk_table->entries[j].cks_enable == 0) { 1476 sclk_table->entries[j].cks_enable == 0) {
@@ -1488,12 +1496,15 @@ static int smu7_get_evv_voltages(struct pp_hwmgr *hwmgr)
1488 } 1496 }
1489 } 1497 }
1490 } else { 1498 } else {
1491
1492 if ((hwmgr->pp_table_version == PP_TABLE_V0) 1499 if ((hwmgr->pp_table_version == PP_TABLE_V0)
1493 || !phm_get_sclk_for_voltage_evv(hwmgr, 1500 || !phm_get_sclk_for_voltage_evv(hwmgr,
1494 table_info->vddc_lookup_table, vv_id, &sclk)) { 1501 table_info->vddc_lookup_table, vv_id, &sclk)) {
1495 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, 1502 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
1496 PHM_PlatformCaps_ClockStretcher)) { 1503 PHM_PlatformCaps_ClockStretcher)) {
1504 if (table_info == NULL)
1505 return -EINVAL;
1506 sclk_table = table_info->vdd_dep_on_sclk;
1507
1497 for (j = 1; j < sclk_table->count; j++) { 1508 for (j = 1; j < sclk_table->count; j++) {
1498 if (sclk_table->entries[j].clk == sclk && 1509 if (sclk_table->entries[j].clk == sclk &&
1499 sclk_table->entries[j].cks_enable == 0) { 1510 sclk_table->entries[j].cks_enable == 0) {
@@ -2117,15 +2128,20 @@ static int smu7_patch_acp_vddc(struct pp_hwmgr *hwmgr,
2117} 2128}
2118 2129
2119static int smu7_patch_limits_vddc(struct pp_hwmgr *hwmgr, 2130static int smu7_patch_limits_vddc(struct pp_hwmgr *hwmgr,
2120 struct phm_clock_and_voltage_limits *tab) 2131 struct phm_clock_and_voltage_limits *tab)
2121{ 2132{
2133 uint32_t vddc, vddci;
2122 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend); 2134 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2123 2135
2124 if (tab) { 2136 if (tab) {
2125 smu7_patch_ppt_v0_with_vdd_leakage(hwmgr, (uint32_t *)&tab->vddc, 2137 vddc = tab->vddc;
2126 &data->vddc_leakage); 2138 smu7_patch_ppt_v0_with_vdd_leakage(hwmgr, &vddc,
2127 smu7_patch_ppt_v0_with_vdd_leakage(hwmgr, (uint32_t *)&tab->vddci, 2139 &data->vddc_leakage);
2128 &data->vddci_leakage); 2140 tab->vddc = vddc;
2141 vddci = tab->vddci;
2142 smu7_patch_ppt_v0_with_vdd_leakage(hwmgr, &vddci,
2143 &data->vddci_leakage);
2144 tab->vddci = vddci;
2129 } 2145 }
2130 2146
2131 return 0; 2147 return 0;
@@ -2968,19 +2984,19 @@ static int smu7_get_pp_table_entry_callback_func_v0(struct pp_hwmgr *hwmgr,
2968 if (!(data->mc_micro_code_feature & DISABLE_MC_LOADMICROCODE) && memory_clock > data->highest_mclk) 2984 if (!(data->mc_micro_code_feature & DISABLE_MC_LOADMICROCODE) && memory_clock > data->highest_mclk)
2969 data->highest_mclk = memory_clock; 2985 data->highest_mclk = memory_clock;
2970 2986
2971 performance_level = &(ps->performance_levels
2972 [ps->performance_level_count++]);
2973
2974 PP_ASSERT_WITH_CODE( 2987 PP_ASSERT_WITH_CODE(
2975 (ps->performance_level_count < smum_get_mac_definition(hwmgr->smumgr, SMU_MAX_LEVELS_GRAPHICS)), 2988 (ps->performance_level_count < smum_get_mac_definition(hwmgr->smumgr, SMU_MAX_LEVELS_GRAPHICS)),
2976 "Performance levels exceeds SMC limit!", 2989 "Performance levels exceeds SMC limit!",
2977 return -EINVAL); 2990 return -EINVAL);
2978 2991
2979 PP_ASSERT_WITH_CODE( 2992 PP_ASSERT_WITH_CODE(
2980 (ps->performance_level_count <= 2993 (ps->performance_level_count <
2981 hwmgr->platform_descriptor.hardwareActivityPerformanceLevels), 2994 hwmgr->platform_descriptor.hardwareActivityPerformanceLevels),
2982 "Performance levels exceeds Driver limit!", 2995 "Performance levels exceeds Driver limit, Skip!",
2983 return -EINVAL); 2996 return 0);
2997
2998 performance_level = &(ps->performance_levels
2999 [ps->performance_level_count++]);
2984 3000
2985 /* Performance levels are arranged from low to high. */ 3001 /* Performance levels are arranged from low to high. */
2986 performance_level->memory_clock = memory_clock; 3002 performance_level->memory_clock = memory_clock;
@@ -3802,13 +3818,15 @@ static inline bool smu7_are_power_levels_equal(const struct smu7_performance_lev
3802 3818
3803int smu7_check_states_equal(struct pp_hwmgr *hwmgr, const struct pp_hw_power_state *pstate1, const struct pp_hw_power_state *pstate2, bool *equal) 3819int smu7_check_states_equal(struct pp_hwmgr *hwmgr, const struct pp_hw_power_state *pstate1, const struct pp_hw_power_state *pstate2, bool *equal)
3804{ 3820{
3805 const struct smu7_power_state *psa = cast_const_phw_smu7_power_state(pstate1); 3821 const struct smu7_power_state *psa;
3806 const struct smu7_power_state *psb = cast_const_phw_smu7_power_state(pstate2); 3822 const struct smu7_power_state *psb;
3807 int i; 3823 int i;
3808 3824
3809 if (pstate1 == NULL || pstate2 == NULL || equal == NULL) 3825 if (pstate1 == NULL || pstate2 == NULL || equal == NULL)
3810 return -EINVAL; 3826 return -EINVAL;
3811 3827
3828 psa = cast_const_phw_smu7_power_state(pstate1);
3829 psb = cast_const_phw_smu7_power_state(pstate2);
3812 /* If the two states don't even have the same number of performance levels they cannot be the same state. */ 3830 /* If the two states don't even have the same number of performance levels they cannot be the same state. */
3813 if (psa->performance_level_count != psb->performance_level_count) { 3831 if (psa->performance_level_count != psb->performance_level_count) {
3814 *equal = false; 3832 *equal = false;
@@ -4213,18 +4231,26 @@ static int smu7_get_sclks(struct pp_hwmgr *hwmgr, struct amd_pp_clocks *clocks)
4213{ 4231{
4214 struct phm_ppt_v1_information *table_info = 4232 struct phm_ppt_v1_information *table_info =
4215 (struct phm_ppt_v1_information *)hwmgr->pptable; 4233 (struct phm_ppt_v1_information *)hwmgr->pptable;
4216 struct phm_ppt_v1_clock_voltage_dependency_table *dep_sclk_table; 4234 struct phm_ppt_v1_clock_voltage_dependency_table *dep_sclk_table = NULL;
4235 struct phm_clock_voltage_dependency_table *sclk_table;
4217 int i; 4236 int i;
4218 4237
4219 if (table_info == NULL) 4238 if (hwmgr->pp_table_version == PP_TABLE_V1) {
4220 return -EINVAL; 4239 if (table_info == NULL || table_info->vdd_dep_on_sclk == NULL)
4221 4240 return -EINVAL;
4222 dep_sclk_table = table_info->vdd_dep_on_sclk; 4241 dep_sclk_table = table_info->vdd_dep_on_sclk;
4223 4242 for (i = 0; i < dep_sclk_table->count; i++) {
4224 for (i = 0; i < dep_sclk_table->count; i++) { 4243 clocks->clock[i] = dep_sclk_table->entries[i].clk;
4225 clocks->clock[i] = dep_sclk_table->entries[i].clk; 4244 clocks->count++;
4226 clocks->count++; 4245 }
4246 } else if (hwmgr->pp_table_version == PP_TABLE_V0) {
4247 sclk_table = hwmgr->dyn_state.vddc_dependency_on_sclk;
4248 for (i = 0; i < sclk_table->count; i++) {
4249 clocks->clock[i] = sclk_table->entries[i].clk;
4250 clocks->count++;
4251 }
4227 } 4252 }
4253
4228 return 0; 4254 return 0;
4229} 4255}
4230 4256
@@ -4246,17 +4272,24 @@ static int smu7_get_mclks(struct pp_hwmgr *hwmgr, struct amd_pp_clocks *clocks)
4246 (struct phm_ppt_v1_information *)hwmgr->pptable; 4272 (struct phm_ppt_v1_information *)hwmgr->pptable;
4247 struct phm_ppt_v1_clock_voltage_dependency_table *dep_mclk_table; 4273 struct phm_ppt_v1_clock_voltage_dependency_table *dep_mclk_table;
4248 int i; 4274 int i;
4275 struct phm_clock_voltage_dependency_table *mclk_table;
4249 4276
4250 if (table_info == NULL) 4277 if (hwmgr->pp_table_version == PP_TABLE_V1) {
4251 return -EINVAL; 4278 if (table_info == NULL)
4252 4279 return -EINVAL;
4253 dep_mclk_table = table_info->vdd_dep_on_mclk; 4280 dep_mclk_table = table_info->vdd_dep_on_mclk;
4254 4281 for (i = 0; i < dep_mclk_table->count; i++) {
4255 for (i = 0; i < dep_mclk_table->count; i++) { 4282 clocks->clock[i] = dep_mclk_table->entries[i].clk;
4256 clocks->clock[i] = dep_mclk_table->entries[i].clk; 4283 clocks->latency[i] = smu7_get_mem_latency(hwmgr,
4257 clocks->latency[i] = smu7_get_mem_latency(hwmgr,
4258 dep_mclk_table->entries[i].clk); 4284 dep_mclk_table->entries[i].clk);
4259 clocks->count++; 4285 clocks->count++;
4286 }
4287 } else if (hwmgr->pp_table_version == PP_TABLE_V0) {
4288 mclk_table = hwmgr->dyn_state.vddc_dependency_on_mclk;
4289 for (i = 0; i < mclk_table->count; i++) {
4290 clocks->clock[i] = mclk_table->entries[i].clk;
4291 clocks->count++;
4292 }
4260 } 4293 }
4261 return 0; 4294 return 0;
4262} 4295}
@@ -4324,6 +4357,7 @@ static const struct pp_hwmgr_func smu7_hwmgr_funcs = {
4324 .set_mclk_od = smu7_set_mclk_od, 4357 .set_mclk_od = smu7_set_mclk_od,
4325 .get_clock_by_type = smu7_get_clock_by_type, 4358 .get_clock_by_type = smu7_get_clock_by_type,
4326 .read_sensor = smu7_read_sensor, 4359 .read_sensor = smu7_read_sensor,
4360 .dynamic_state_management_disable = smu7_disable_dpm_tasks,
4327}; 4361};
4328 4362
4329uint8_t smu7_get_sleep_divider_id_from_clock(uint32_t clock, 4363uint8_t smu7_get_sleep_divider_id_from_clock(uint32_t clock,
diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/smu7_thermal.c b/drivers/gpu/drm/amd/powerplay/hwmgr/smu7_thermal.c
index fb6c6f6106d5..29d0319b22e6 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/smu7_thermal.c
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/smu7_thermal.c
@@ -30,7 +30,7 @@ int smu7_fan_ctrl_get_fan_speed_info(struct pp_hwmgr *hwmgr,
30 struct phm_fan_speed_info *fan_speed_info) 30 struct phm_fan_speed_info *fan_speed_info)
31{ 31{
32 if (hwmgr->thermal_controller.fanInfo.bNoFan) 32 if (hwmgr->thermal_controller.fanInfo.bNoFan)
33 return 0; 33 return -ENODEV;
34 34
35 fan_speed_info->supports_percent_read = true; 35 fan_speed_info->supports_percent_read = true;
36 fan_speed_info->supports_percent_write = true; 36 fan_speed_info->supports_percent_write = true;
@@ -60,7 +60,7 @@ int smu7_fan_ctrl_get_fan_speed_percent(struct pp_hwmgr *hwmgr,
60 uint64_t tmp64; 60 uint64_t tmp64;
61 61
62 if (hwmgr->thermal_controller.fanInfo.bNoFan) 62 if (hwmgr->thermal_controller.fanInfo.bNoFan)
63 return 0; 63 return -ENODEV;
64 64
65 duty100 = PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, 65 duty100 = PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
66 CG_FDO_CTRL1, FMAX_DUTY100); 66 CG_FDO_CTRL1, FMAX_DUTY100);
@@ -89,7 +89,7 @@ int smu7_fan_ctrl_get_fan_speed_rpm(struct pp_hwmgr *hwmgr, uint32_t *speed)
89 if (hwmgr->thermal_controller.fanInfo.bNoFan || 89 if (hwmgr->thermal_controller.fanInfo.bNoFan ||
90 (hwmgr->thermal_controller.fanInfo. 90 (hwmgr->thermal_controller.fanInfo.
91 ucTachometerPulsesPerRevolution == 0)) 91 ucTachometerPulsesPerRevolution == 0))
92 return 0; 92 return -ENODEV;
93 93
94 tach_period = PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC, 94 tach_period = PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
95 CG_TACH_STATUS, TACH_PERIOD); 95 CG_TACH_STATUS, TACH_PERIOD);
diff --git a/drivers/gpu/drm/amd/powerplay/smumgr/iceland_smc.c b/drivers/gpu/drm/amd/powerplay/smumgr/iceland_smc.c
index eda802bc63c8..8c889caba420 100644
--- a/drivers/gpu/drm/amd/powerplay/smumgr/iceland_smc.c
+++ b/drivers/gpu/drm/amd/powerplay/smumgr/iceland_smc.c
@@ -2458,7 +2458,7 @@ static int iceland_set_mc_special_registers(struct pp_hwmgr *hwmgr,
2458 PP_ASSERT_WITH_CODE((j <= SMU71_DISCRETE_MC_REGISTER_ARRAY_SIZE), 2458 PP_ASSERT_WITH_CODE((j <= SMU71_DISCRETE_MC_REGISTER_ARRAY_SIZE),
2459 "Invalid VramInfo table.", return -EINVAL); 2459 "Invalid VramInfo table.", return -EINVAL);
2460 2460
2461 if (!data->is_memory_gddr5) { 2461 if (!data->is_memory_gddr5 && j < SMU71_DISCRETE_MC_REGISTER_ARRAY_SIZE) {
2462 table->mc_reg_address[j].s1 = mmMC_PMG_AUTO_CMD; 2462 table->mc_reg_address[j].s1 = mmMC_PMG_AUTO_CMD;
2463 table->mc_reg_address[j].s0 = mmMC_PMG_AUTO_CMD; 2463 table->mc_reg_address[j].s0 = mmMC_PMG_AUTO_CMD;
2464 for (k = 0; k < table->num_entries; k++) { 2464 for (k = 0; k < table->num_entries; k++) {
diff --git a/drivers/gpu/drm/amd/powerplay/smumgr/polaris10_smc.c b/drivers/gpu/drm/amd/powerplay/smumgr/polaris10_smc.c
index 4ccc0b72324d..71bb2f8dc157 100644
--- a/drivers/gpu/drm/amd/powerplay/smumgr/polaris10_smc.c
+++ b/drivers/gpu/drm/amd/powerplay/smumgr/polaris10_smc.c
@@ -2214,6 +2214,7 @@ uint32_t polaris10_get_mac_definition(uint32_t value)
2214int polaris10_process_firmware_header(struct pp_hwmgr *hwmgr) 2214int polaris10_process_firmware_header(struct pp_hwmgr *hwmgr)
2215{ 2215{
2216 struct polaris10_smumgr *smu_data = (struct polaris10_smumgr *)(hwmgr->smumgr->backend); 2216 struct polaris10_smumgr *smu_data = (struct polaris10_smumgr *)(hwmgr->smumgr->backend);
2217 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2217 uint32_t tmp; 2218 uint32_t tmp;
2218 int result; 2219 int result;
2219 bool error = false; 2220 bool error = false;
@@ -2233,8 +2234,10 @@ int polaris10_process_firmware_header(struct pp_hwmgr *hwmgr)
2233 offsetof(SMU74_Firmware_Header, SoftRegisters), 2234 offsetof(SMU74_Firmware_Header, SoftRegisters),
2234 &tmp, SMC_RAM_END); 2235 &tmp, SMC_RAM_END);
2235 2236
2236 if (!result) 2237 if (!result) {
2238 data->soft_regs_start = tmp;
2237 smu_data->smu7_data.soft_regs_start = tmp; 2239 smu_data->smu7_data.soft_regs_start = tmp;
2240 }
2238 2241
2239 error |= (0 != result); 2242 error |= (0 != result);
2240 2243
diff --git a/drivers/gpu/drm/amd/scheduler/gpu_scheduler.c b/drivers/gpu/drm/amd/scheduler/gpu_scheduler.c
index 963a24d46a93..ffe1f85ce300 100644
--- a/drivers/gpu/drm/amd/scheduler/gpu_scheduler.c
+++ b/drivers/gpu/drm/amd/scheduler/gpu_scheduler.c
@@ -34,9 +34,6 @@ static bool amd_sched_entity_is_ready(struct amd_sched_entity *entity);
34static void amd_sched_wakeup(struct amd_gpu_scheduler *sched); 34static void amd_sched_wakeup(struct amd_gpu_scheduler *sched);
35static void amd_sched_process_job(struct fence *f, struct fence_cb *cb); 35static void amd_sched_process_job(struct fence *f, struct fence_cb *cb);
36 36
37struct kmem_cache *sched_fence_slab;
38atomic_t sched_fence_slab_ref = ATOMIC_INIT(0);
39
40/* Initialize a given run queue struct */ 37/* Initialize a given run queue struct */
41static void amd_sched_rq_init(struct amd_sched_rq *rq) 38static void amd_sched_rq_init(struct amd_sched_rq *rq)
42{ 39{
@@ -618,13 +615,6 @@ int amd_sched_init(struct amd_gpu_scheduler *sched,
618 INIT_LIST_HEAD(&sched->ring_mirror_list); 615 INIT_LIST_HEAD(&sched->ring_mirror_list);
619 spin_lock_init(&sched->job_list_lock); 616 spin_lock_init(&sched->job_list_lock);
620 atomic_set(&sched->hw_rq_count, 0); 617 atomic_set(&sched->hw_rq_count, 0);
621 if (atomic_inc_return(&sched_fence_slab_ref) == 1) {
622 sched_fence_slab = kmem_cache_create(
623 "amd_sched_fence", sizeof(struct amd_sched_fence), 0,
624 SLAB_HWCACHE_ALIGN, NULL);
625 if (!sched_fence_slab)
626 return -ENOMEM;
627 }
628 618
629 /* Each scheduler will run on a seperate kernel thread */ 619 /* Each scheduler will run on a seperate kernel thread */
630 sched->thread = kthread_run(amd_sched_main, sched, sched->name); 620 sched->thread = kthread_run(amd_sched_main, sched, sched->name);
@@ -645,6 +635,4 @@ void amd_sched_fini(struct amd_gpu_scheduler *sched)
645{ 635{
646 if (sched->thread) 636 if (sched->thread)
647 kthread_stop(sched->thread); 637 kthread_stop(sched->thread);
648 if (atomic_dec_and_test(&sched_fence_slab_ref))
649 kmem_cache_destroy(sched_fence_slab);
650} 638}
diff --git a/drivers/gpu/drm/amd/scheduler/gpu_scheduler.h b/drivers/gpu/drm/amd/scheduler/gpu_scheduler.h
index 7cbbbfb502ef..51068e6c3d9a 100644
--- a/drivers/gpu/drm/amd/scheduler/gpu_scheduler.h
+++ b/drivers/gpu/drm/amd/scheduler/gpu_scheduler.h
@@ -30,9 +30,6 @@
30struct amd_gpu_scheduler; 30struct amd_gpu_scheduler;
31struct amd_sched_rq; 31struct amd_sched_rq;
32 32
33extern struct kmem_cache *sched_fence_slab;
34extern atomic_t sched_fence_slab_ref;
35
36/** 33/**
37 * A scheduler entity is a wrapper around a job queue or a group 34 * A scheduler entity is a wrapper around a job queue or a group
38 * of other entities. Entities take turns emitting jobs from their 35 * of other entities. Entities take turns emitting jobs from their
@@ -145,6 +142,9 @@ void amd_sched_entity_fini(struct amd_gpu_scheduler *sched,
145 struct amd_sched_entity *entity); 142 struct amd_sched_entity *entity);
146void amd_sched_entity_push_job(struct amd_sched_job *sched_job); 143void amd_sched_entity_push_job(struct amd_sched_job *sched_job);
147 144
145int amd_sched_fence_slab_init(void);
146void amd_sched_fence_slab_fini(void);
147
148struct amd_sched_fence *amd_sched_fence_create( 148struct amd_sched_fence *amd_sched_fence_create(
149 struct amd_sched_entity *s_entity, void *owner); 149 struct amd_sched_entity *s_entity, void *owner);
150void amd_sched_fence_scheduled(struct amd_sched_fence *fence); 150void amd_sched_fence_scheduled(struct amd_sched_fence *fence);
diff --git a/drivers/gpu/drm/amd/scheduler/sched_fence.c b/drivers/gpu/drm/amd/scheduler/sched_fence.c
index 6b63beaf7574..88fc2d662579 100644
--- a/drivers/gpu/drm/amd/scheduler/sched_fence.c
+++ b/drivers/gpu/drm/amd/scheduler/sched_fence.c
@@ -27,6 +27,25 @@
27#include <drm/drmP.h> 27#include <drm/drmP.h>
28#include "gpu_scheduler.h" 28#include "gpu_scheduler.h"
29 29
30static struct kmem_cache *sched_fence_slab;
31
32int amd_sched_fence_slab_init(void)
33{
34 sched_fence_slab = kmem_cache_create(
35 "amd_sched_fence", sizeof(struct amd_sched_fence), 0,
36 SLAB_HWCACHE_ALIGN, NULL);
37 if (!sched_fence_slab)
38 return -ENOMEM;
39
40 return 0;
41}
42
43void amd_sched_fence_slab_fini(void)
44{
45 rcu_barrier();
46 kmem_cache_destroy(sched_fence_slab);
47}
48
30struct amd_sched_fence *amd_sched_fence_create(struct amd_sched_entity *entity, 49struct amd_sched_fence *amd_sched_fence_create(struct amd_sched_entity *entity,
31 void *owner) 50 void *owner)
32{ 51{
@@ -103,7 +122,7 @@ static void amd_sched_fence_free(struct rcu_head *rcu)
103} 122}
104 123
105/** 124/**
106 * amd_sched_fence_release - callback that fence can be freed 125 * amd_sched_fence_release_scheduled - callback that fence can be freed
107 * 126 *
108 * @fence: fence 127 * @fence: fence
109 * 128 *
@@ -118,7 +137,7 @@ static void amd_sched_fence_release_scheduled(struct fence *f)
118} 137}
119 138
120/** 139/**
121 * amd_sched_fence_release_scheduled - drop extra reference 140 * amd_sched_fence_release_finished - drop extra reference
122 * 141 *
123 * @f: fence 142 * @f: fence
124 * 143 *
diff --git a/drivers/gpu/drm/arc/arcpgu_hdmi.c b/drivers/gpu/drm/arc/arcpgu_hdmi.c
index b7a8b2ac4055..b69c66b4897e 100644
--- a/drivers/gpu/drm/arc/arcpgu_hdmi.c
+++ b/drivers/gpu/drm/arc/arcpgu_hdmi.c
@@ -14,170 +14,45 @@
14 * 14 *
15 */ 15 */
16 16
17#include <drm/drm_crtc_helper.h> 17#include <drm/drm_crtc.h>
18#include <drm/drm_encoder_slave.h> 18#include <drm/drm_encoder_slave.h>
19#include <drm/drm_atomic_helper.h>
20 19
21#include "arcpgu.h" 20#include "arcpgu.h"
22 21
23struct arcpgu_drm_connector {
24 struct drm_connector connector;
25 struct drm_encoder_slave *encoder_slave;
26};
27
28static int arcpgu_drm_connector_get_modes(struct drm_connector *connector)
29{
30 const struct drm_encoder_slave_funcs *sfuncs;
31 struct drm_encoder_slave *slave;
32 struct arcpgu_drm_connector *con =
33 container_of(connector, struct arcpgu_drm_connector, connector);
34
35 slave = con->encoder_slave;
36 if (slave == NULL) {
37 dev_err(connector->dev->dev,
38 "connector_get_modes: cannot find slave encoder for connector\n");
39 return 0;
40 }
41
42 sfuncs = slave->slave_funcs;
43 if (sfuncs->get_modes == NULL)
44 return 0;
45
46 return sfuncs->get_modes(&slave->base, connector);
47}
48
49static enum drm_connector_status
50arcpgu_drm_connector_detect(struct drm_connector *connector, bool force)
51{
52 enum drm_connector_status status = connector_status_unknown;
53 const struct drm_encoder_slave_funcs *sfuncs;
54 struct drm_encoder_slave *slave;
55
56 struct arcpgu_drm_connector *con =
57 container_of(connector, struct arcpgu_drm_connector, connector);
58
59 slave = con->encoder_slave;
60 if (slave == NULL) {
61 dev_err(connector->dev->dev,
62 "connector_detect: cannot find slave encoder for connector\n");
63 return status;
64 }
65
66 sfuncs = slave->slave_funcs;
67 if (sfuncs && sfuncs->detect)
68 return sfuncs->detect(&slave->base, connector);
69
70 dev_err(connector->dev->dev, "connector_detect: could not detect slave funcs\n");
71 return status;
72}
73
74static void arcpgu_drm_connector_destroy(struct drm_connector *connector)
75{
76 drm_connector_unregister(connector);
77 drm_connector_cleanup(connector);
78}
79
80static const struct drm_connector_helper_funcs
81arcpgu_drm_connector_helper_funcs = {
82 .get_modes = arcpgu_drm_connector_get_modes,
83};
84
85static const struct drm_connector_funcs arcpgu_drm_connector_funcs = {
86 .dpms = drm_helper_connector_dpms,
87 .reset = drm_atomic_helper_connector_reset,
88 .detect = arcpgu_drm_connector_detect,
89 .fill_modes = drm_helper_probe_single_connector_modes,
90 .destroy = arcpgu_drm_connector_destroy,
91 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
92 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
93};
94
95static struct drm_encoder_helper_funcs arcpgu_drm_encoder_helper_funcs = {
96 .dpms = drm_i2c_encoder_dpms,
97 .mode_fixup = drm_i2c_encoder_mode_fixup,
98 .mode_set = drm_i2c_encoder_mode_set,
99 .prepare = drm_i2c_encoder_prepare,
100 .commit = drm_i2c_encoder_commit,
101 .detect = drm_i2c_encoder_detect,
102};
103
104static struct drm_encoder_funcs arcpgu_drm_encoder_funcs = { 22static struct drm_encoder_funcs arcpgu_drm_encoder_funcs = {
105 .destroy = drm_encoder_cleanup, 23 .destroy = drm_encoder_cleanup,
106}; 24};
107 25
108int arcpgu_drm_hdmi_init(struct drm_device *drm, struct device_node *np) 26int arcpgu_drm_hdmi_init(struct drm_device *drm, struct device_node *np)
109{ 27{
110 struct arcpgu_drm_connector *arcpgu_connector; 28 struct drm_encoder *encoder;
111 struct drm_i2c_encoder_driver *driver; 29 struct drm_bridge *bridge;
112 struct drm_encoder_slave *encoder; 30
113 struct drm_connector *connector; 31 int ret = 0;
114 struct i2c_client *i2c_slave;
115 int ret;
116 32
117 encoder = devm_kzalloc(drm->dev, sizeof(*encoder), GFP_KERNEL); 33 encoder = devm_kzalloc(drm->dev, sizeof(*encoder), GFP_KERNEL);
118 if (encoder == NULL) 34 if (encoder == NULL)
119 return -ENOMEM; 35 return -ENOMEM;
120 36
121 i2c_slave = of_find_i2c_device_by_node(np); 37 /* Locate drm bridge from the hdmi encoder DT node */
122 if (!i2c_slave || !i2c_get_clientdata(i2c_slave)) { 38 bridge = of_drm_find_bridge(np);
123 dev_err(drm->dev, "failed to find i2c slave encoder\n"); 39 if (!bridge)
124 return -EPROBE_DEFER;
125 }
126
127 if (i2c_slave->dev.driver == NULL) {
128 dev_err(drm->dev, "failed to find i2c slave driver\n");
129 return -EPROBE_DEFER; 40 return -EPROBE_DEFER;
130 }
131 41
132 driver = 42 encoder->possible_crtcs = 1;
133 to_drm_i2c_encoder_driver(to_i2c_driver(i2c_slave->dev.driver)); 43 encoder->possible_clones = 0;
134 ret = driver->encoder_init(i2c_slave, drm, encoder); 44 ret = drm_encoder_init(drm, encoder, &arcpgu_drm_encoder_funcs,
135 if (ret) {
136 dev_err(drm->dev, "failed to initialize i2c encoder slave\n");
137 return ret;
138 }
139
140 encoder->base.possible_crtcs = 1;
141 encoder->base.possible_clones = 0;
142 ret = drm_encoder_init(drm, &encoder->base, &arcpgu_drm_encoder_funcs,
143 DRM_MODE_ENCODER_TMDS, NULL); 45 DRM_MODE_ENCODER_TMDS, NULL);
144 if (ret) 46 if (ret)
145 return ret; 47 return ret;
146 48
147 drm_encoder_helper_add(&encoder->base, 49 /* Link drm_bridge to encoder */
148 &arcpgu_drm_encoder_helper_funcs); 50 bridge->encoder = encoder;
149 51 encoder->bridge = bridge;
150 arcpgu_connector = devm_kzalloc(drm->dev, sizeof(*arcpgu_connector),
151 GFP_KERNEL);
152 if (!arcpgu_connector) {
153 ret = -ENOMEM;
154 goto error_encoder_cleanup;
155 }
156
157 connector = &arcpgu_connector->connector;
158 drm_connector_helper_add(connector, &arcpgu_drm_connector_helper_funcs);
159 ret = drm_connector_init(drm, connector, &arcpgu_drm_connector_funcs,
160 DRM_MODE_CONNECTOR_HDMIA);
161 if (ret < 0) {
162 dev_err(drm->dev, "failed to initialize drm connector\n");
163 goto error_encoder_cleanup;
164 }
165 52
166 ret = drm_mode_connector_attach_encoder(connector, &encoder->base); 53 ret = drm_bridge_attach(drm, bridge);
167 if (ret < 0) { 54 if (ret)
168 dev_err(drm->dev, "could not attach connector to encoder\n"); 55 drm_encoder_cleanup(encoder);
169 drm_connector_unregister(connector);
170 goto error_connector_cleanup;
171 }
172
173 arcpgu_connector->encoder_slave = encoder;
174
175 return 0;
176
177error_connector_cleanup:
178 drm_connector_cleanup(connector);
179 56
180error_encoder_cleanup:
181 drm_encoder_cleanup(&encoder->base);
182 return ret; 57 return ret;
183} 58}
diff --git a/drivers/gpu/drm/arm/hdlcd_crtc.c b/drivers/gpu/drm/arm/hdlcd_crtc.c
index 48019ae22ddb..28341b32067f 100644
--- a/drivers/gpu/drm/arm/hdlcd_crtc.c
+++ b/drivers/gpu/drm/arm/hdlcd_crtc.c
@@ -150,15 +150,14 @@ static void hdlcd_crtc_enable(struct drm_crtc *crtc)
150 clk_prepare_enable(hdlcd->clk); 150 clk_prepare_enable(hdlcd->clk);
151 hdlcd_crtc_mode_set_nofb(crtc); 151 hdlcd_crtc_mode_set_nofb(crtc);
152 hdlcd_write(hdlcd, HDLCD_REG_COMMAND, 1); 152 hdlcd_write(hdlcd, HDLCD_REG_COMMAND, 1);
153 drm_crtc_vblank_on(crtc);
153} 154}
154 155
155static void hdlcd_crtc_disable(struct drm_crtc *crtc) 156static void hdlcd_crtc_disable(struct drm_crtc *crtc)
156{ 157{
157 struct hdlcd_drm_private *hdlcd = crtc_to_hdlcd_priv(crtc); 158 struct hdlcd_drm_private *hdlcd = crtc_to_hdlcd_priv(crtc);
158 159
159 if (!crtc->state->active) 160 drm_crtc_vblank_off(crtc);
160 return;
161
162 hdlcd_write(hdlcd, HDLCD_REG_COMMAND, 0); 161 hdlcd_write(hdlcd, HDLCD_REG_COMMAND, 0);
163 clk_disable_unprepare(hdlcd->clk); 162 clk_disable_unprepare(hdlcd->clk);
164} 163}
diff --git a/drivers/gpu/drm/arm/hdlcd_drv.c b/drivers/gpu/drm/arm/hdlcd_drv.c
index fb6a418ce6be..e138fb51e8ce 100644
--- a/drivers/gpu/drm/arm/hdlcd_drv.c
+++ b/drivers/gpu/drm/arm/hdlcd_drv.c
@@ -375,7 +375,6 @@ static int hdlcd_drm_bind(struct device *dev)
375 375
376err_fbdev: 376err_fbdev:
377 drm_kms_helper_poll_fini(drm); 377 drm_kms_helper_poll_fini(drm);
378 drm_mode_config_cleanup(drm);
379 drm_vblank_cleanup(drm); 378 drm_vblank_cleanup(drm);
380err_vblank: 379err_vblank:
381 pm_runtime_disable(drm->dev); 380 pm_runtime_disable(drm->dev);
@@ -387,6 +386,7 @@ err_unload:
387 drm_irq_uninstall(drm); 386 drm_irq_uninstall(drm);
388 of_reserved_mem_device_release(drm->dev); 387 of_reserved_mem_device_release(drm->dev);
389err_free: 388err_free:
389 drm_mode_config_cleanup(drm);
390 dev_set_drvdata(dev, NULL); 390 dev_set_drvdata(dev, NULL);
391 drm_dev_unref(drm); 391 drm_dev_unref(drm);
392 392
diff --git a/drivers/gpu/drm/armada/armada_crtc.c b/drivers/gpu/drm/armada/armada_crtc.c
index 2f58e9e2a59c..a51f8cbcfe26 100644
--- a/drivers/gpu/drm/armada/armada_crtc.c
+++ b/drivers/gpu/drm/armada/armada_crtc.c
@@ -332,17 +332,19 @@ static void armada_drm_crtc_dpms(struct drm_crtc *crtc, int dpms)
332{ 332{
333 struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc); 333 struct armada_crtc *dcrtc = drm_to_armada_crtc(crtc);
334 334
335 if (dcrtc->dpms != dpms) { 335 if (dpms_blanked(dcrtc->dpms) != dpms_blanked(dpms)) {
336 dcrtc->dpms = dpms;
337 if (!IS_ERR(dcrtc->clk) && !dpms_blanked(dpms))
338 WARN_ON(clk_prepare_enable(dcrtc->clk));
339 armada_drm_crtc_update(dcrtc);
340 if (!IS_ERR(dcrtc->clk) && dpms_blanked(dpms))
341 clk_disable_unprepare(dcrtc->clk);
342 if (dpms_blanked(dpms)) 336 if (dpms_blanked(dpms))
343 armada_drm_vblank_off(dcrtc); 337 armada_drm_vblank_off(dcrtc);
344 else 338 else if (!IS_ERR(dcrtc->clk))
339 WARN_ON(clk_prepare_enable(dcrtc->clk));
340 dcrtc->dpms = dpms;
341 armada_drm_crtc_update(dcrtc);
342 if (!dpms_blanked(dpms))
345 drm_crtc_vblank_on(&dcrtc->crtc); 343 drm_crtc_vblank_on(&dcrtc->crtc);
344 else if (!IS_ERR(dcrtc->clk))
345 clk_disable_unprepare(dcrtc->clk);
346 } else if (dcrtc->dpms != dpms) {
347 dcrtc->dpms = dpms;
346 } 348 }
347} 349}
348 350
diff --git a/drivers/gpu/drm/ast/ast_ttm.c b/drivers/gpu/drm/ast/ast_ttm.c
index 608df4c90520..0743e65cb240 100644
--- a/drivers/gpu/drm/ast/ast_ttm.c
+++ b/drivers/gpu/drm/ast/ast_ttm.c
@@ -267,6 +267,8 @@ int ast_mm_init(struct ast_private *ast)
267 return ret; 267 return ret;
268 } 268 }
269 269
270 arch_io_reserve_memtype_wc(pci_resource_start(dev->pdev, 0),
271 pci_resource_len(dev->pdev, 0));
270 ast->fb_mtrr = arch_phys_wc_add(pci_resource_start(dev->pdev, 0), 272 ast->fb_mtrr = arch_phys_wc_add(pci_resource_start(dev->pdev, 0),
271 pci_resource_len(dev->pdev, 0)); 273 pci_resource_len(dev->pdev, 0));
272 274
@@ -275,11 +277,15 @@ int ast_mm_init(struct ast_private *ast)
275 277
276void ast_mm_fini(struct ast_private *ast) 278void ast_mm_fini(struct ast_private *ast)
277{ 279{
280 struct drm_device *dev = ast->dev;
281
278 ttm_bo_device_release(&ast->ttm.bdev); 282 ttm_bo_device_release(&ast->ttm.bdev);
279 283
280 ast_ttm_global_release(ast); 284 ast_ttm_global_release(ast);
281 285
282 arch_phys_wc_del(ast->fb_mtrr); 286 arch_phys_wc_del(ast->fb_mtrr);
287 arch_io_free_memtype_wc(pci_resource_start(dev->pdev, 0),
288 pci_resource_len(dev->pdev, 0));
283} 289}
284 290
285void ast_ttm_placement(struct ast_bo *bo, int domain) 291void ast_ttm_placement(struct ast_bo *bo, int domain)
diff --git a/drivers/gpu/drm/cirrus/cirrus_ttm.c b/drivers/gpu/drm/cirrus/cirrus_ttm.c
index bb2438dd8733..5e7e63ce7bce 100644
--- a/drivers/gpu/drm/cirrus/cirrus_ttm.c
+++ b/drivers/gpu/drm/cirrus/cirrus_ttm.c
@@ -267,6 +267,9 @@ int cirrus_mm_init(struct cirrus_device *cirrus)
267 return ret; 267 return ret;
268 } 268 }
269 269
270 arch_io_reserve_memtype_wc(pci_resource_start(dev->pdev, 0),
271 pci_resource_len(dev->pdev, 0));
272
270 cirrus->fb_mtrr = arch_phys_wc_add(pci_resource_start(dev->pdev, 0), 273 cirrus->fb_mtrr = arch_phys_wc_add(pci_resource_start(dev->pdev, 0),
271 pci_resource_len(dev->pdev, 0)); 274 pci_resource_len(dev->pdev, 0));
272 275
@@ -276,6 +279,8 @@ int cirrus_mm_init(struct cirrus_device *cirrus)
276 279
277void cirrus_mm_fini(struct cirrus_device *cirrus) 280void cirrus_mm_fini(struct cirrus_device *cirrus)
278{ 281{
282 struct drm_device *dev = cirrus->dev;
283
279 if (!cirrus->mm_inited) 284 if (!cirrus->mm_inited)
280 return; 285 return;
281 286
@@ -285,6 +290,8 @@ void cirrus_mm_fini(struct cirrus_device *cirrus)
285 290
286 arch_phys_wc_del(cirrus->fb_mtrr); 291 arch_phys_wc_del(cirrus->fb_mtrr);
287 cirrus->fb_mtrr = 0; 292 cirrus->fb_mtrr = 0;
293 arch_io_free_memtype_wc(pci_resource_start(dev->pdev, 0),
294 pci_resource_len(dev->pdev, 0));
288} 295}
289 296
290void cirrus_ttm_placement(struct cirrus_bo *bo, int domain) 297void cirrus_ttm_placement(struct cirrus_bo *bo, int domain)
diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
index 23739609427d..e6862a744210 100644
--- a/drivers/gpu/drm/drm_atomic.c
+++ b/drivers/gpu/drm/drm_atomic.c
@@ -420,18 +420,21 @@ drm_atomic_replace_property_blob_from_id(struct drm_crtc *crtc,
420 ssize_t expected_size, 420 ssize_t expected_size,
421 bool *replaced) 421 bool *replaced)
422{ 422{
423 struct drm_device *dev = crtc->dev;
424 struct drm_property_blob *new_blob = NULL; 423 struct drm_property_blob *new_blob = NULL;
425 424
426 if (blob_id != 0) { 425 if (blob_id != 0) {
427 new_blob = drm_property_lookup_blob(dev, blob_id); 426 new_blob = drm_property_lookup_blob(crtc->dev, blob_id);
428 if (new_blob == NULL) 427 if (new_blob == NULL)
429 return -EINVAL; 428 return -EINVAL;
430 if (expected_size > 0 && expected_size != new_blob->length) 429
430 if (expected_size > 0 && expected_size != new_blob->length) {
431 drm_property_unreference_blob(new_blob);
431 return -EINVAL; 432 return -EINVAL;
433 }
432 } 434 }
433 435
434 drm_atomic_replace_property_blob(blob, new_blob, replaced); 436 drm_atomic_replace_property_blob(blob, new_blob, replaced);
437 drm_property_unreference_blob(new_blob);
435 438
436 return 0; 439 return 0;
437} 440}
diff --git a/drivers/gpu/drm/drm_atomic_helper.c b/drivers/gpu/drm/drm_atomic_helper.c
index c3f83476f996..21f992605541 100644
--- a/drivers/gpu/drm/drm_atomic_helper.c
+++ b/drivers/gpu/drm/drm_atomic_helper.c
@@ -594,10 +594,6 @@ drm_atomic_helper_check_planes(struct drm_device *dev,
594 struct drm_plane_state *plane_state; 594 struct drm_plane_state *plane_state;
595 int i, ret = 0; 595 int i, ret = 0;
596 596
597 ret = drm_atomic_normalize_zpos(dev, state);
598 if (ret)
599 return ret;
600
601 for_each_plane_in_state(state, plane, plane_state, i) { 597 for_each_plane_in_state(state, plane, plane_state, i) {
602 const struct drm_plane_helper_funcs *funcs; 598 const struct drm_plane_helper_funcs *funcs;
603 599
diff --git a/drivers/gpu/drm/drm_dp_mst_topology.c b/drivers/gpu/drm/drm_dp_mst_topology.c
index 04e457117980..aa644487749c 100644
--- a/drivers/gpu/drm/drm_dp_mst_topology.c
+++ b/drivers/gpu/drm/drm_dp_mst_topology.c
@@ -914,6 +914,7 @@ static void drm_dp_destroy_port(struct kref *kref)
914 /* no need to clean up vcpi 914 /* no need to clean up vcpi
915 * as if we have no connector we never setup a vcpi */ 915 * as if we have no connector we never setup a vcpi */
916 drm_dp_port_teardown_pdt(port, port->pdt); 916 drm_dp_port_teardown_pdt(port, port->pdt);
917 port->pdt = DP_PEER_DEVICE_NONE;
917 } 918 }
918 kfree(port); 919 kfree(port);
919} 920}
@@ -1159,7 +1160,9 @@ static void drm_dp_add_port(struct drm_dp_mst_branch *mstb,
1159 drm_dp_put_port(port); 1160 drm_dp_put_port(port);
1160 goto out; 1161 goto out;
1161 } 1162 }
1162 if (port->port_num >= DP_MST_LOGICAL_PORT_0) { 1163 if ((port->pdt == DP_PEER_DEVICE_DP_LEGACY_CONV ||
1164 port->pdt == DP_PEER_DEVICE_SST_SINK) &&
1165 port->port_num >= DP_MST_LOGICAL_PORT_0) {
1163 port->cached_edid = drm_get_edid(port->connector, &port->aux.ddc); 1166 port->cached_edid = drm_get_edid(port->connector, &port->aux.ddc);
1164 drm_mode_connector_set_tile_property(port->connector); 1167 drm_mode_connector_set_tile_property(port->connector);
1165 } 1168 }
@@ -2919,6 +2922,7 @@ static void drm_dp_destroy_connector_work(struct work_struct *work)
2919 mgr->cbs->destroy_connector(mgr, port->connector); 2922 mgr->cbs->destroy_connector(mgr, port->connector);
2920 2923
2921 drm_dp_port_teardown_pdt(port, port->pdt); 2924 drm_dp_port_teardown_pdt(port, port->pdt);
2925 port->pdt = DP_PEER_DEVICE_NONE;
2922 2926
2923 if (!port->input && port->vcpi.vcpi > 0) { 2927 if (!port->input && port->vcpi.vcpi > 0) {
2924 drm_dp_mst_reset_vcpi_slots(mgr, port); 2928 drm_dp_mst_reset_vcpi_slots(mgr, port);
diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c
index 03414bde1f15..6c75e62c0b22 100644
--- a/drivers/gpu/drm/drm_fb_helper.c
+++ b/drivers/gpu/drm/drm_fb_helper.c
@@ -131,7 +131,12 @@ int drm_fb_helper_single_add_all_connectors(struct drm_fb_helper *fb_helper)
131 return 0; 131 return 0;
132fail: 132fail:
133 for (i = 0; i < fb_helper->connector_count; i++) { 133 for (i = 0; i < fb_helper->connector_count; i++) {
134 kfree(fb_helper->connector_info[i]); 134 struct drm_fb_helper_connector *fb_helper_connector =
135 fb_helper->connector_info[i];
136
137 drm_connector_unreference(fb_helper_connector->connector);
138
139 kfree(fb_helper_connector);
135 fb_helper->connector_info[i] = NULL; 140 fb_helper->connector_info[i] = NULL;
136 } 141 }
137 fb_helper->connector_count = 0; 142 fb_helper->connector_count = 0;
@@ -603,6 +608,24 @@ int drm_fb_helper_blank(int blank, struct fb_info *info)
603} 608}
604EXPORT_SYMBOL(drm_fb_helper_blank); 609EXPORT_SYMBOL(drm_fb_helper_blank);
605 610
611static void drm_fb_helper_modeset_release(struct drm_fb_helper *helper,
612 struct drm_mode_set *modeset)
613{
614 int i;
615
616 for (i = 0; i < modeset->num_connectors; i++) {
617 drm_connector_unreference(modeset->connectors[i]);
618 modeset->connectors[i] = NULL;
619 }
620 modeset->num_connectors = 0;
621
622 drm_mode_destroy(helper->dev, modeset->mode);
623 modeset->mode = NULL;
624
625 /* FIXME should hold a ref? */
626 modeset->fb = NULL;
627}
628
606static void drm_fb_helper_crtc_free(struct drm_fb_helper *helper) 629static void drm_fb_helper_crtc_free(struct drm_fb_helper *helper)
607{ 630{
608 int i; 631 int i;
@@ -612,10 +635,12 @@ static void drm_fb_helper_crtc_free(struct drm_fb_helper *helper)
612 kfree(helper->connector_info[i]); 635 kfree(helper->connector_info[i]);
613 } 636 }
614 kfree(helper->connector_info); 637 kfree(helper->connector_info);
638
615 for (i = 0; i < helper->crtc_count; i++) { 639 for (i = 0; i < helper->crtc_count; i++) {
616 kfree(helper->crtc_info[i].mode_set.connectors); 640 struct drm_mode_set *modeset = &helper->crtc_info[i].mode_set;
617 if (helper->crtc_info[i].mode_set.mode) 641
618 drm_mode_destroy(helper->dev, helper->crtc_info[i].mode_set.mode); 642 drm_fb_helper_modeset_release(helper, modeset);
643 kfree(modeset->connectors);
619 } 644 }
620 kfree(helper->crtc_info); 645 kfree(helper->crtc_info);
621} 646}
@@ -644,7 +669,9 @@ static void drm_fb_helper_dirty_work(struct work_struct *work)
644 clip->x2 = clip->y2 = 0; 669 clip->x2 = clip->y2 = 0;
645 spin_unlock_irqrestore(&helper->dirty_lock, flags); 670 spin_unlock_irqrestore(&helper->dirty_lock, flags);
646 671
647 helper->fb->funcs->dirty(helper->fb, NULL, 0, 0, &clip_copy, 1); 672 /* call dirty callback only when it has been really touched */
673 if (clip_copy.x1 < clip_copy.x2 && clip_copy.y1 < clip_copy.y2)
674 helper->fb->funcs->dirty(helper->fb, NULL, 0, 0, &clip_copy, 1);
648} 675}
649 676
650/** 677/**
@@ -2088,7 +2115,6 @@ static void drm_setup_crtcs(struct drm_fb_helper *fb_helper)
2088 struct drm_fb_helper_crtc **crtcs; 2115 struct drm_fb_helper_crtc **crtcs;
2089 struct drm_display_mode **modes; 2116 struct drm_display_mode **modes;
2090 struct drm_fb_offset *offsets; 2117 struct drm_fb_offset *offsets;
2091 struct drm_mode_set *modeset;
2092 bool *enabled; 2118 bool *enabled;
2093 int width, height; 2119 int width, height;
2094 int i; 2120 int i;
@@ -2136,45 +2162,35 @@ static void drm_setup_crtcs(struct drm_fb_helper *fb_helper)
2136 2162
2137 /* need to set the modesets up here for use later */ 2163 /* need to set the modesets up here for use later */
2138 /* fill out the connector<->crtc mappings into the modesets */ 2164 /* fill out the connector<->crtc mappings into the modesets */
2139 for (i = 0; i < fb_helper->crtc_count; i++) { 2165 for (i = 0; i < fb_helper->crtc_count; i++)
2140 modeset = &fb_helper->crtc_info[i].mode_set; 2166 drm_fb_helper_modeset_release(fb_helper,
2141 modeset->num_connectors = 0; 2167 &fb_helper->crtc_info[i].mode_set);
2142 modeset->fb = NULL;
2143 }
2144 2168
2145 for (i = 0; i < fb_helper->connector_count; i++) { 2169 for (i = 0; i < fb_helper->connector_count; i++) {
2146 struct drm_display_mode *mode = modes[i]; 2170 struct drm_display_mode *mode = modes[i];
2147 struct drm_fb_helper_crtc *fb_crtc = crtcs[i]; 2171 struct drm_fb_helper_crtc *fb_crtc = crtcs[i];
2148 struct drm_fb_offset *offset = &offsets[i]; 2172 struct drm_fb_offset *offset = &offsets[i];
2149 modeset = &fb_crtc->mode_set; 2173 struct drm_mode_set *modeset = &fb_crtc->mode_set;
2150 2174
2151 if (mode && fb_crtc) { 2175 if (mode && fb_crtc) {
2176 struct drm_connector *connector =
2177 fb_helper->connector_info[i]->connector;
2178
2152 DRM_DEBUG_KMS("desired mode %s set on crtc %d (%d,%d)\n", 2179 DRM_DEBUG_KMS("desired mode %s set on crtc %d (%d,%d)\n",
2153 mode->name, fb_crtc->mode_set.crtc->base.id, offset->x, offset->y); 2180 mode->name, fb_crtc->mode_set.crtc->base.id, offset->x, offset->y);
2181
2154 fb_crtc->desired_mode = mode; 2182 fb_crtc->desired_mode = mode;
2155 fb_crtc->x = offset->x; 2183 fb_crtc->x = offset->x;
2156 fb_crtc->y = offset->y; 2184 fb_crtc->y = offset->y;
2157 if (modeset->mode)
2158 drm_mode_destroy(dev, modeset->mode);
2159 modeset->mode = drm_mode_duplicate(dev, 2185 modeset->mode = drm_mode_duplicate(dev,
2160 fb_crtc->desired_mode); 2186 fb_crtc->desired_mode);
2161 modeset->connectors[modeset->num_connectors++] = fb_helper->connector_info[i]->connector; 2187 drm_connector_reference(connector);
2188 modeset->connectors[modeset->num_connectors++] = connector;
2162 modeset->fb = fb_helper->fb; 2189 modeset->fb = fb_helper->fb;
2163 modeset->x = offset->x; 2190 modeset->x = offset->x;
2164 modeset->y = offset->y; 2191 modeset->y = offset->y;
2165 } 2192 }
2166 } 2193 }
2167
2168 /* Clear out any old modes if there are no more connected outputs. */
2169 for (i = 0; i < fb_helper->crtc_count; i++) {
2170 modeset = &fb_helper->crtc_info[i].mode_set;
2171 if (modeset->num_connectors == 0) {
2172 BUG_ON(modeset->fb);
2173 if (modeset->mode)
2174 drm_mode_destroy(dev, modeset->mode);
2175 modeset->mode = NULL;
2176 }
2177 }
2178out: 2194out:
2179 kfree(crtcs); 2195 kfree(crtcs);
2180 kfree(modes); 2196 kfree(modes);
diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
index 1df2d33d0b40..ffb2ab389d1d 100644
--- a/drivers/gpu/drm/drm_info.c
+++ b/drivers/gpu/drm/drm_info.c
@@ -54,9 +54,6 @@ int drm_name_info(struct seq_file *m, void *data)
54 54
55 mutex_lock(&dev->master_mutex); 55 mutex_lock(&dev->master_mutex);
56 master = dev->master; 56 master = dev->master;
57 if (!master)
58 goto out_unlock;
59
60 seq_printf(m, "%s", dev->driver->name); 57 seq_printf(m, "%s", dev->driver->name);
61 if (dev->dev) 58 if (dev->dev)
62 seq_printf(m, " dev=%s", dev_name(dev->dev)); 59 seq_printf(m, " dev=%s", dev_name(dev->dev));
@@ -65,7 +62,6 @@ int drm_name_info(struct seq_file *m, void *data)
65 if (dev->unique) 62 if (dev->unique)
66 seq_printf(m, " unique=%s", dev->unique); 63 seq_printf(m, " unique=%s", dev->unique);
67 seq_printf(m, "\n"); 64 seq_printf(m, "\n");
68out_unlock:
69 mutex_unlock(&dev->master_mutex); 65 mutex_unlock(&dev->master_mutex);
70 66
71 return 0; 67 return 0;
diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
index 0ad2c47f808f..71c3473476c7 100644
--- a/drivers/gpu/drm/drm_ioctl.c
+++ b/drivers/gpu/drm/drm_ioctl.c
@@ -254,10 +254,12 @@ static int drm_getcap(struct drm_device *dev, void *data, struct drm_file *file_
254 req->value = dev->mode_config.async_page_flip; 254 req->value = dev->mode_config.async_page_flip;
255 break; 255 break;
256 case DRM_CAP_PAGE_FLIP_TARGET: 256 case DRM_CAP_PAGE_FLIP_TARGET:
257 req->value = 1; 257 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
258 drm_for_each_crtc(crtc, dev) { 258 req->value = 1;
259 if (!crtc->funcs->page_flip_target) 259 drm_for_each_crtc(crtc, dev) {
260 req->value = 0; 260 if (!crtc->funcs->page_flip_target)
261 req->value = 0;
262 }
261 } 263 }
262 break; 264 break;
263 case DRM_CAP_CURSOR_WIDTH: 265 case DRM_CAP_CURSOR_WIDTH:
diff --git a/drivers/gpu/drm/etnaviv/etnaviv_buffer.c b/drivers/gpu/drm/etnaviv/etnaviv_buffer.c
index cb86c7e5495c..d9230132dfbc 100644
--- a/drivers/gpu/drm/etnaviv/etnaviv_buffer.c
+++ b/drivers/gpu/drm/etnaviv/etnaviv_buffer.c
@@ -329,20 +329,34 @@ void etnaviv_buffer_queue(struct etnaviv_gpu *gpu, unsigned int event,
329 /* 329 /*
330 * Append a LINK to the submitted command buffer to return to 330 * Append a LINK to the submitted command buffer to return to
331 * the ring buffer. return_target is the ring target address. 331 * the ring buffer. return_target is the ring target address.
332 * We need three dwords: event, wait, link. 332 * We need at most 7 dwords in the return target: 2 cache flush +
333 * 2 semaphore stall + 1 event + 1 wait + 1 link.
333 */ 334 */
334 return_dwords = 3; 335 return_dwords = 7;
335 return_target = etnaviv_buffer_reserve(gpu, buffer, return_dwords); 336 return_target = etnaviv_buffer_reserve(gpu, buffer, return_dwords);
336 CMD_LINK(cmdbuf, return_dwords, return_target); 337 CMD_LINK(cmdbuf, return_dwords, return_target);
337 338
338 /* 339 /*
339 * Append event, wait and link pointing back to the wait 340 * Append a cache flush, stall, event, wait and link pointing back to
340 * command to the ring buffer. 341 * the wait command to the ring buffer.
341 */ 342 */
343 if (gpu->exec_state == ETNA_PIPE_2D) {
344 CMD_LOAD_STATE(buffer, VIVS_GL_FLUSH_CACHE,
345 VIVS_GL_FLUSH_CACHE_PE2D);
346 } else {
347 CMD_LOAD_STATE(buffer, VIVS_GL_FLUSH_CACHE,
348 VIVS_GL_FLUSH_CACHE_DEPTH |
349 VIVS_GL_FLUSH_CACHE_COLOR);
350 CMD_LOAD_STATE(buffer, VIVS_TS_FLUSH_CACHE,
351 VIVS_TS_FLUSH_CACHE_FLUSH);
352 }
353 CMD_SEM(buffer, SYNC_RECIPIENT_FE, SYNC_RECIPIENT_PE);
354 CMD_STALL(buffer, SYNC_RECIPIENT_FE, SYNC_RECIPIENT_PE);
342 CMD_LOAD_STATE(buffer, VIVS_GL_EVENT, VIVS_GL_EVENT_EVENT_ID(event) | 355 CMD_LOAD_STATE(buffer, VIVS_GL_EVENT, VIVS_GL_EVENT_EVENT_ID(event) |
343 VIVS_GL_EVENT_FROM_PE); 356 VIVS_GL_EVENT_FROM_PE);
344 CMD_WAIT(buffer); 357 CMD_WAIT(buffer);
345 CMD_LINK(buffer, 2, return_target + 8); 358 CMD_LINK(buffer, 2, etnaviv_iommu_get_cmdbuf_va(gpu, buffer) +
359 buffer->user_size - 4);
346 360
347 if (drm_debug & DRM_UT_DRIVER) 361 if (drm_debug & DRM_UT_DRIVER)
348 pr_info("stream link to 0x%08x @ 0x%08x %p\n", 362 pr_info("stream link to 0x%08x @ 0x%08x %p\n",
diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gem.c b/drivers/gpu/drm/etnaviv/etnaviv_gem.c
index 5ce3603e6eac..0370b842d9cc 100644
--- a/drivers/gpu/drm/etnaviv/etnaviv_gem.c
+++ b/drivers/gpu/drm/etnaviv/etnaviv_gem.c
@@ -748,19 +748,22 @@ static struct page **etnaviv_gem_userptr_do_get_pages(
748 int ret = 0, pinned, npages = etnaviv_obj->base.size >> PAGE_SHIFT; 748 int ret = 0, pinned, npages = etnaviv_obj->base.size >> PAGE_SHIFT;
749 struct page **pvec; 749 struct page **pvec;
750 uintptr_t ptr; 750 uintptr_t ptr;
751 unsigned int flags = 0;
751 752
752 pvec = drm_malloc_ab(npages, sizeof(struct page *)); 753 pvec = drm_malloc_ab(npages, sizeof(struct page *));
753 if (!pvec) 754 if (!pvec)
754 return ERR_PTR(-ENOMEM); 755 return ERR_PTR(-ENOMEM);
755 756
757 if (!etnaviv_obj->userptr.ro)
758 flags |= FOLL_WRITE;
759
756 pinned = 0; 760 pinned = 0;
757 ptr = etnaviv_obj->userptr.ptr; 761 ptr = etnaviv_obj->userptr.ptr;
758 762
759 down_read(&mm->mmap_sem); 763 down_read(&mm->mmap_sem);
760 while (pinned < npages) { 764 while (pinned < npages) {
761 ret = get_user_pages_remote(task, mm, ptr, npages - pinned, 765 ret = get_user_pages_remote(task, mm, ptr, npages - pinned,
762 !etnaviv_obj->userptr.ro, 0, 766 flags, pvec + pinned, NULL);
763 pvec + pinned, NULL);
764 if (ret < 0) 767 if (ret < 0)
765 break; 768 break;
766 769
diff --git a/drivers/gpu/drm/etnaviv/etnaviv_mmu.c b/drivers/gpu/drm/etnaviv/etnaviv_mmu.c
index d3796ed8d8c5..169ac96e8f08 100644
--- a/drivers/gpu/drm/etnaviv/etnaviv_mmu.c
+++ b/drivers/gpu/drm/etnaviv/etnaviv_mmu.c
@@ -330,7 +330,8 @@ u32 etnaviv_iommu_get_cmdbuf_va(struct etnaviv_gpu *gpu,
330 return (u32)buf->vram_node.start; 330 return (u32)buf->vram_node.start;
331 331
332 mutex_lock(&mmu->lock); 332 mutex_lock(&mmu->lock);
333 ret = etnaviv_iommu_find_iova(mmu, &buf->vram_node, buf->size); 333 ret = etnaviv_iommu_find_iova(mmu, &buf->vram_node,
334 buf->size + SZ_64K);
334 if (ret < 0) { 335 if (ret < 0) {
335 mutex_unlock(&mmu->lock); 336 mutex_unlock(&mmu->lock);
336 return 0; 337 return 0;
diff --git a/drivers/gpu/drm/exynos/exynos_drm_drv.c b/drivers/gpu/drm/exynos/exynos_drm_drv.c
index def78c8c1780..f86e7c846678 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_drv.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_drv.c
@@ -262,6 +262,26 @@ int exynos_atomic_commit(struct drm_device *dev, struct drm_atomic_state *state,
262 return 0; 262 return 0;
263} 263}
264 264
265int exynos_atomic_check(struct drm_device *dev,
266 struct drm_atomic_state *state)
267{
268 int ret;
269
270 ret = drm_atomic_helper_check_modeset(dev, state);
271 if (ret)
272 return ret;
273
274 ret = drm_atomic_normalize_zpos(dev, state);
275 if (ret)
276 return ret;
277
278 ret = drm_atomic_helper_check_planes(dev, state);
279 if (ret)
280 return ret;
281
282 return ret;
283}
284
265static int exynos_drm_open(struct drm_device *dev, struct drm_file *file) 285static int exynos_drm_open(struct drm_device *dev, struct drm_file *file)
266{ 286{
267 struct drm_exynos_file_private *file_priv; 287 struct drm_exynos_file_private *file_priv;
diff --git a/drivers/gpu/drm/exynos/exynos_drm_drv.h b/drivers/gpu/drm/exynos/exynos_drm_drv.h
index d215149e737b..80c4d5b81689 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_drv.h
+++ b/drivers/gpu/drm/exynos/exynos_drm_drv.h
@@ -301,6 +301,7 @@ static inline int exynos_dpi_bind(struct drm_device *dev,
301 301
302int exynos_atomic_commit(struct drm_device *dev, struct drm_atomic_state *state, 302int exynos_atomic_commit(struct drm_device *dev, struct drm_atomic_state *state,
303 bool nonblock); 303 bool nonblock);
304int exynos_atomic_check(struct drm_device *dev, struct drm_atomic_state *state);
304 305
305 306
306extern struct platform_driver fimd_driver; 307extern struct platform_driver fimd_driver;
diff --git a/drivers/gpu/drm/exynos/exynos_drm_fb.c b/drivers/gpu/drm/exynos/exynos_drm_fb.c
index 40ce841eb952..23cce0a3f5fc 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_fb.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_fb.c
@@ -190,7 +190,7 @@ dma_addr_t exynos_drm_fb_dma_addr(struct drm_framebuffer *fb, int index)
190static const struct drm_mode_config_funcs exynos_drm_mode_config_funcs = { 190static const struct drm_mode_config_funcs exynos_drm_mode_config_funcs = {
191 .fb_create = exynos_user_fb_create, 191 .fb_create = exynos_user_fb_create,
192 .output_poll_changed = exynos_drm_output_poll_changed, 192 .output_poll_changed = exynos_drm_output_poll_changed,
193 .atomic_check = drm_atomic_helper_check, 193 .atomic_check = exynos_atomic_check,
194 .atomic_commit = exynos_atomic_commit, 194 .atomic_commit = exynos_atomic_commit,
195}; 195};
196 196
diff --git a/drivers/gpu/drm/exynos/exynos_drm_g2d.c b/drivers/gpu/drm/exynos/exynos_drm_g2d.c
index aa92decf4233..fbd13fabdf2d 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_g2d.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_g2d.c
@@ -488,7 +488,8 @@ static dma_addr_t *g2d_userptr_get_dma_addr(struct drm_device *drm_dev,
488 goto err_free; 488 goto err_free;
489 } 489 }
490 490
491 ret = get_vaddr_frames(start, npages, true, true, g2d_userptr->vec); 491 ret = get_vaddr_frames(start, npages, FOLL_FORCE | FOLL_WRITE,
492 g2d_userptr->vec);
492 if (ret != npages) { 493 if (ret != npages) {
493 DRM_ERROR("failed to get user pages from userptr.\n"); 494 DRM_ERROR("failed to get user pages from userptr.\n");
494 if (ret < 0) 495 if (ret < 0)
diff --git a/drivers/gpu/drm/exynos/exynos_hdmi.c b/drivers/gpu/drm/exynos/exynos_hdmi.c
index e8fb6ef947ee..38eaa63afb31 100644
--- a/drivers/gpu/drm/exynos/exynos_hdmi.c
+++ b/drivers/gpu/drm/exynos/exynos_hdmi.c
@@ -1907,6 +1907,8 @@ err_disable_pm_runtime:
1907err_hdmiphy: 1907err_hdmiphy:
1908 if (hdata->hdmiphy_port) 1908 if (hdata->hdmiphy_port)
1909 put_device(&hdata->hdmiphy_port->dev); 1909 put_device(&hdata->hdmiphy_port->dev);
1910 if (hdata->regs_hdmiphy)
1911 iounmap(hdata->regs_hdmiphy);
1910err_ddc: 1912err_ddc:
1911 put_device(&hdata->ddc_adpt->dev); 1913 put_device(&hdata->ddc_adpt->dev);
1912 1914
@@ -1929,6 +1931,9 @@ static int hdmi_remove(struct platform_device *pdev)
1929 if (hdata->hdmiphy_port) 1931 if (hdata->hdmiphy_port)
1930 put_device(&hdata->hdmiphy_port->dev); 1932 put_device(&hdata->hdmiphy_port->dev);
1931 1933
1934 if (hdata->regs_hdmiphy)
1935 iounmap(hdata->regs_hdmiphy);
1936
1932 put_device(&hdata->ddc_adpt->dev); 1937 put_device(&hdata->ddc_adpt->dev);
1933 1938
1934 return 0; 1939 return 0;
diff --git a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_crtc.c b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_crtc.c
index 3371635cd4d7..deb57435cc89 100644
--- a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_crtc.c
+++ b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_crtc.c
@@ -25,8 +25,13 @@
25static void fsl_dcu_drm_crtc_atomic_flush(struct drm_crtc *crtc, 25static void fsl_dcu_drm_crtc_atomic_flush(struct drm_crtc *crtc,
26 struct drm_crtc_state *old_crtc_state) 26 struct drm_crtc_state *old_crtc_state)
27{ 27{
28 struct drm_device *dev = crtc->dev;
29 struct fsl_dcu_drm_device *fsl_dev = dev->dev_private;
28 struct drm_pending_vblank_event *event = crtc->state->event; 30 struct drm_pending_vblank_event *event = crtc->state->event;
29 31
32 regmap_write(fsl_dev->regmap,
33 DCU_UPDATE_MODE, DCU_UPDATE_MODE_READREG);
34
30 if (event) { 35 if (event) {
31 crtc->state->event = NULL; 36 crtc->state->event = NULL;
32 37
@@ -39,11 +44,15 @@ static void fsl_dcu_drm_crtc_atomic_flush(struct drm_crtc *crtc,
39 } 44 }
40} 45}
41 46
42static void fsl_dcu_drm_disable_crtc(struct drm_crtc *crtc) 47static void fsl_dcu_drm_crtc_atomic_disable(struct drm_crtc *crtc,
48 struct drm_crtc_state *old_crtc_state)
43{ 49{
44 struct drm_device *dev = crtc->dev; 50 struct drm_device *dev = crtc->dev;
45 struct fsl_dcu_drm_device *fsl_dev = dev->dev_private; 51 struct fsl_dcu_drm_device *fsl_dev = dev->dev_private;
46 52
53 /* always disable planes on the CRTC */
54 drm_atomic_helper_disable_planes_on_crtc(old_crtc_state, true);
55
47 drm_crtc_vblank_off(crtc); 56 drm_crtc_vblank_off(crtc);
48 57
49 regmap_update_bits(fsl_dev->regmap, DCU_DCU_MODE, 58 regmap_update_bits(fsl_dev->regmap, DCU_DCU_MODE,
@@ -51,6 +60,7 @@ static void fsl_dcu_drm_disable_crtc(struct drm_crtc *crtc)
51 DCU_MODE_DCU_MODE(DCU_MODE_OFF)); 60 DCU_MODE_DCU_MODE(DCU_MODE_OFF));
52 regmap_write(fsl_dev->regmap, DCU_UPDATE_MODE, 61 regmap_write(fsl_dev->regmap, DCU_UPDATE_MODE,
53 DCU_UPDATE_MODE_READREG); 62 DCU_UPDATE_MODE_READREG);
63 clk_disable_unprepare(fsl_dev->pix_clk);
54} 64}
55 65
56static void fsl_dcu_drm_crtc_enable(struct drm_crtc *crtc) 66static void fsl_dcu_drm_crtc_enable(struct drm_crtc *crtc)
@@ -58,6 +68,7 @@ static void fsl_dcu_drm_crtc_enable(struct drm_crtc *crtc)
58 struct drm_device *dev = crtc->dev; 68 struct drm_device *dev = crtc->dev;
59 struct fsl_dcu_drm_device *fsl_dev = dev->dev_private; 69 struct fsl_dcu_drm_device *fsl_dev = dev->dev_private;
60 70
71 clk_prepare_enable(fsl_dev->pix_clk);
61 regmap_update_bits(fsl_dev->regmap, DCU_DCU_MODE, 72 regmap_update_bits(fsl_dev->regmap, DCU_DCU_MODE,
62 DCU_MODE_DCU_MODE_MASK, 73 DCU_MODE_DCU_MODE_MASK,
63 DCU_MODE_DCU_MODE(DCU_MODE_NORMAL)); 74 DCU_MODE_DCU_MODE(DCU_MODE_NORMAL));
@@ -116,14 +127,12 @@ static void fsl_dcu_drm_crtc_mode_set_nofb(struct drm_crtc *crtc)
116 DCU_THRESHOLD_LS_BF_VS(BF_VS_VAL) | 127 DCU_THRESHOLD_LS_BF_VS(BF_VS_VAL) |
117 DCU_THRESHOLD_OUT_BUF_HIGH(BUF_MAX_VAL) | 128 DCU_THRESHOLD_OUT_BUF_HIGH(BUF_MAX_VAL) |
118 DCU_THRESHOLD_OUT_BUF_LOW(BUF_MIN_VAL)); 129 DCU_THRESHOLD_OUT_BUF_LOW(BUF_MIN_VAL));
119 regmap_write(fsl_dev->regmap, DCU_UPDATE_MODE,
120 DCU_UPDATE_MODE_READREG);
121 return; 130 return;
122} 131}
123 132
124static const struct drm_crtc_helper_funcs fsl_dcu_drm_crtc_helper_funcs = { 133static const struct drm_crtc_helper_funcs fsl_dcu_drm_crtc_helper_funcs = {
134 .atomic_disable = fsl_dcu_drm_crtc_atomic_disable,
125 .atomic_flush = fsl_dcu_drm_crtc_atomic_flush, 135 .atomic_flush = fsl_dcu_drm_crtc_atomic_flush,
126 .disable = fsl_dcu_drm_disable_crtc,
127 .enable = fsl_dcu_drm_crtc_enable, 136 .enable = fsl_dcu_drm_crtc_enable,
128 .mode_set_nofb = fsl_dcu_drm_crtc_mode_set_nofb, 137 .mode_set_nofb = fsl_dcu_drm_crtc_mode_set_nofb,
129}; 138};
diff --git a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.c b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.c
index 0884c45aefe8..cc2fde2ae5ef 100644
--- a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.c
+++ b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.c
@@ -59,8 +59,6 @@ static int fsl_dcu_drm_irq_init(struct drm_device *dev)
59 59
60 regmap_write(fsl_dev->regmap, DCU_INT_STATUS, 0); 60 regmap_write(fsl_dev->regmap, DCU_INT_STATUS, 0);
61 regmap_write(fsl_dev->regmap, DCU_INT_MASK, ~0); 61 regmap_write(fsl_dev->regmap, DCU_INT_MASK, ~0);
62 regmap_write(fsl_dev->regmap, DCU_UPDATE_MODE,
63 DCU_UPDATE_MODE_READREG);
64 62
65 return ret; 63 return ret;
66} 64}
@@ -139,8 +137,6 @@ static irqreturn_t fsl_dcu_drm_irq(int irq, void *arg)
139 drm_handle_vblank(dev, 0); 137 drm_handle_vblank(dev, 0);
140 138
141 regmap_write(fsl_dev->regmap, DCU_INT_STATUS, int_status); 139 regmap_write(fsl_dev->regmap, DCU_INT_STATUS, int_status);
142 regmap_write(fsl_dev->regmap, DCU_UPDATE_MODE,
143 DCU_UPDATE_MODE_READREG);
144 140
145 return IRQ_HANDLED; 141 return IRQ_HANDLED;
146} 142}
@@ -267,12 +263,8 @@ static int fsl_dcu_drm_pm_resume(struct device *dev)
267 return ret; 263 return ret;
268 } 264 }
269 265
270 ret = clk_prepare_enable(fsl_dev->pix_clk); 266 if (fsl_dev->tcon)
271 if (ret < 0) { 267 fsl_tcon_bypass_enable(fsl_dev->tcon);
272 dev_err(dev, "failed to enable pix clk\n");
273 goto disable_dcu_clk;
274 }
275
276 fsl_dcu_drm_init_planes(fsl_dev->drm); 268 fsl_dcu_drm_init_planes(fsl_dev->drm);
277 drm_atomic_helper_resume(fsl_dev->drm, fsl_dev->state); 269 drm_atomic_helper_resume(fsl_dev->drm, fsl_dev->state);
278 270
@@ -284,10 +276,6 @@ static int fsl_dcu_drm_pm_resume(struct device *dev)
284 enable_irq(fsl_dev->irq); 276 enable_irq(fsl_dev->irq);
285 277
286 return 0; 278 return 0;
287
288disable_dcu_clk:
289 clk_disable_unprepare(fsl_dev->clk);
290 return ret;
291} 279}
292#endif 280#endif
293 281
@@ -401,18 +389,12 @@ static int fsl_dcu_drm_probe(struct platform_device *pdev)
401 goto disable_clk; 389 goto disable_clk;
402 } 390 }
403 391
404 ret = clk_prepare_enable(fsl_dev->pix_clk);
405 if (ret < 0) {
406 dev_err(dev, "failed to enable pix clk\n");
407 goto unregister_pix_clk;
408 }
409
410 fsl_dev->tcon = fsl_tcon_init(dev); 392 fsl_dev->tcon = fsl_tcon_init(dev);
411 393
412 drm = drm_dev_alloc(driver, dev); 394 drm = drm_dev_alloc(driver, dev);
413 if (IS_ERR(drm)) { 395 if (IS_ERR(drm)) {
414 ret = PTR_ERR(drm); 396 ret = PTR_ERR(drm);
415 goto disable_pix_clk; 397 goto unregister_pix_clk;
416 } 398 }
417 399
418 fsl_dev->dev = dev; 400 fsl_dev->dev = dev;
@@ -433,8 +415,6 @@ static int fsl_dcu_drm_probe(struct platform_device *pdev)
433 415
434unref: 416unref:
435 drm_dev_unref(drm); 417 drm_dev_unref(drm);
436disable_pix_clk:
437 clk_disable_unprepare(fsl_dev->pix_clk);
438unregister_pix_clk: 418unregister_pix_clk:
439 clk_unregister(fsl_dev->pix_clk); 419 clk_unregister(fsl_dev->pix_clk);
440disable_clk: 420disable_clk:
@@ -447,7 +427,6 @@ static int fsl_dcu_drm_remove(struct platform_device *pdev)
447 struct fsl_dcu_drm_device *fsl_dev = platform_get_drvdata(pdev); 427 struct fsl_dcu_drm_device *fsl_dev = platform_get_drvdata(pdev);
448 428
449 clk_disable_unprepare(fsl_dev->clk); 429 clk_disable_unprepare(fsl_dev->clk);
450 clk_disable_unprepare(fsl_dev->pix_clk);
451 clk_unregister(fsl_dev->pix_clk); 430 clk_unregister(fsl_dev->pix_clk);
452 drm_put_dev(fsl_dev->drm); 431 drm_put_dev(fsl_dev->drm);
453 432
diff --git a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_plane.c b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_plane.c
index a7e5486bd1e9..a99f48847420 100644
--- a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_plane.c
+++ b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_plane.c
@@ -160,11 +160,6 @@ static void fsl_dcu_drm_plane_atomic_update(struct drm_plane *plane,
160 DCU_LAYER_POST_SKIP(0) | 160 DCU_LAYER_POST_SKIP(0) |
161 DCU_LAYER_PRE_SKIP(0)); 161 DCU_LAYER_PRE_SKIP(0));
162 } 162 }
163 regmap_update_bits(fsl_dev->regmap, DCU_DCU_MODE,
164 DCU_MODE_DCU_MODE_MASK,
165 DCU_MODE_DCU_MODE(DCU_MODE_NORMAL));
166 regmap_write(fsl_dev->regmap,
167 DCU_UPDATE_MODE, DCU_UPDATE_MODE_READREG);
168 163
169 return; 164 return;
170} 165}
@@ -211,11 +206,6 @@ void fsl_dcu_drm_init_planes(struct drm_device *dev)
211 for (j = 1; j <= fsl_dev->soc->layer_regs; j++) 206 for (j = 1; j <= fsl_dev->soc->layer_regs; j++)
212 regmap_write(fsl_dev->regmap, DCU_CTRLDESCLN(i, j), 0); 207 regmap_write(fsl_dev->regmap, DCU_CTRLDESCLN(i, j), 0);
213 } 208 }
214 regmap_update_bits(fsl_dev->regmap, DCU_DCU_MODE,
215 DCU_MODE_DCU_MODE_MASK,
216 DCU_MODE_DCU_MODE(DCU_MODE_OFF));
217 regmap_write(fsl_dev->regmap, DCU_UPDATE_MODE,
218 DCU_UPDATE_MODE_READREG);
219} 209}
220 210
221struct drm_plane *fsl_dcu_drm_primary_create_plane(struct drm_device *dev) 211struct drm_plane *fsl_dcu_drm_primary_create_plane(struct drm_device *dev)
diff --git a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_rgb.c b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_rgb.c
index 26edcc899712..e1dd75b18118 100644
--- a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_rgb.c
+++ b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_rgb.c
@@ -20,38 +20,6 @@
20#include "fsl_dcu_drm_drv.h" 20#include "fsl_dcu_drm_drv.h"
21#include "fsl_tcon.h" 21#include "fsl_tcon.h"
22 22
23static int
24fsl_dcu_drm_encoder_atomic_check(struct drm_encoder *encoder,
25 struct drm_crtc_state *crtc_state,
26 struct drm_connector_state *conn_state)
27{
28 return 0;
29}
30
31static void fsl_dcu_drm_encoder_disable(struct drm_encoder *encoder)
32{
33 struct drm_device *dev = encoder->dev;
34 struct fsl_dcu_drm_device *fsl_dev = dev->dev_private;
35
36 if (fsl_dev->tcon)
37 fsl_tcon_bypass_disable(fsl_dev->tcon);
38}
39
40static void fsl_dcu_drm_encoder_enable(struct drm_encoder *encoder)
41{
42 struct drm_device *dev = encoder->dev;
43 struct fsl_dcu_drm_device *fsl_dev = dev->dev_private;
44
45 if (fsl_dev->tcon)
46 fsl_tcon_bypass_enable(fsl_dev->tcon);
47}
48
49static const struct drm_encoder_helper_funcs encoder_helper_funcs = {
50 .atomic_check = fsl_dcu_drm_encoder_atomic_check,
51 .disable = fsl_dcu_drm_encoder_disable,
52 .enable = fsl_dcu_drm_encoder_enable,
53};
54
55static void fsl_dcu_drm_encoder_destroy(struct drm_encoder *encoder) 23static void fsl_dcu_drm_encoder_destroy(struct drm_encoder *encoder)
56{ 24{
57 drm_encoder_cleanup(encoder); 25 drm_encoder_cleanup(encoder);
@@ -68,13 +36,16 @@ int fsl_dcu_drm_encoder_create(struct fsl_dcu_drm_device *fsl_dev,
68 int ret; 36 int ret;
69 37
70 encoder->possible_crtcs = 1; 38 encoder->possible_crtcs = 1;
39
40 /* Use bypass mode for parallel RGB/LVDS encoder */
41 if (fsl_dev->tcon)
42 fsl_tcon_bypass_enable(fsl_dev->tcon);
43
71 ret = drm_encoder_init(fsl_dev->drm, encoder, &encoder_funcs, 44 ret = drm_encoder_init(fsl_dev->drm, encoder, &encoder_funcs,
72 DRM_MODE_ENCODER_LVDS, NULL); 45 DRM_MODE_ENCODER_LVDS, NULL);
73 if (ret < 0) 46 if (ret < 0)
74 return ret; 47 return ret;
75 48
76 drm_encoder_helper_add(encoder, &encoder_helper_funcs);
77
78 return 0; 49 return 0;
79} 50}
80 51
diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c
index bfb2efd8d4d4..18dfdd5c1b3b 100644
--- a/drivers/gpu/drm/i915/i915_drv.c
+++ b/drivers/gpu/drm/i915/i915_drv.c
@@ -1447,8 +1447,6 @@ static int i915_drm_suspend(struct drm_device *dev)
1447 1447
1448 dev_priv->suspend_count++; 1448 dev_priv->suspend_count++;
1449 1449
1450 intel_display_set_init_power(dev_priv, false);
1451
1452 intel_csr_ucode_suspend(dev_priv); 1450 intel_csr_ucode_suspend(dev_priv);
1453 1451
1454out: 1452out:
@@ -1466,6 +1464,8 @@ static int i915_drm_suspend_late(struct drm_device *dev, bool hibernation)
1466 1464
1467 disable_rpm_wakeref_asserts(dev_priv); 1465 disable_rpm_wakeref_asserts(dev_priv);
1468 1466
1467 intel_display_set_init_power(dev_priv, false);
1468
1469 fw_csr = !IS_BROXTON(dev_priv) && 1469 fw_csr = !IS_BROXTON(dev_priv) &&
1470 suspend_to_idle(dev_priv) && dev_priv->csr.dmc_payload; 1470 suspend_to_idle(dev_priv) && dev_priv->csr.dmc_payload;
1471 /* 1471 /*
diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index 8b9ee4e390c0..685e9e065287 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -2883,6 +2883,11 @@ __i915_printk(struct drm_i915_private *dev_priv, const char *level,
2883extern long i915_compat_ioctl(struct file *filp, unsigned int cmd, 2883extern long i915_compat_ioctl(struct file *filp, unsigned int cmd,
2884 unsigned long arg); 2884 unsigned long arg);
2885#endif 2885#endif
2886extern const struct dev_pm_ops i915_pm_ops;
2887
2888extern int i915_driver_load(struct pci_dev *pdev,
2889 const struct pci_device_id *ent);
2890extern void i915_driver_unload(struct drm_device *dev);
2886extern int intel_gpu_reset(struct drm_i915_private *dev_priv, u32 engine_mask); 2891extern int intel_gpu_reset(struct drm_i915_private *dev_priv, u32 engine_mask);
2887extern bool intel_has_gpu_reset(struct drm_i915_private *dev_priv); 2892extern bool intel_has_gpu_reset(struct drm_i915_private *dev_priv);
2888extern void i915_reset(struct drm_i915_private *dev_priv); 2893extern void i915_reset(struct drm_i915_private *dev_priv);
diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index 947e82c2b175..00eb4814b913 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -1806,7 +1806,7 @@ int i915_gem_fault(struct vm_area_struct *area, struct vm_fault *vmf)
1806 /* Use a partial view if it is bigger than available space */ 1806 /* Use a partial view if it is bigger than available space */
1807 chunk_size = MIN_CHUNK_PAGES; 1807 chunk_size = MIN_CHUNK_PAGES;
1808 if (i915_gem_object_is_tiled(obj)) 1808 if (i915_gem_object_is_tiled(obj))
1809 chunk_size = max(chunk_size, tile_row_pages(obj)); 1809 chunk_size = roundup(chunk_size, tile_row_pages(obj));
1810 1810
1811 memset(&view, 0, sizeof(view)); 1811 memset(&view, 0, sizeof(view));
1812 view.type = I915_GGTT_VIEW_PARTIAL; 1812 view.type = I915_GGTT_VIEW_PARTIAL;
@@ -2268,7 +2268,7 @@ i915_gem_object_get_pages_gtt(struct drm_i915_gem_object *obj)
2268 page = shmem_read_mapping_page(mapping, i); 2268 page = shmem_read_mapping_page(mapping, i);
2269 if (IS_ERR(page)) { 2269 if (IS_ERR(page)) {
2270 ret = PTR_ERR(page); 2270 ret = PTR_ERR(page);
2271 goto err_pages; 2271 goto err_sg;
2272 } 2272 }
2273 } 2273 }
2274#ifdef CONFIG_SWIOTLB 2274#ifdef CONFIG_SWIOTLB
@@ -2311,8 +2311,9 @@ i915_gem_object_get_pages_gtt(struct drm_i915_gem_object *obj)
2311 2311
2312 return 0; 2312 return 0;
2313 2313
2314err_pages: 2314err_sg:
2315 sg_mark_end(sg); 2315 sg_mark_end(sg);
2316err_pages:
2316 for_each_sgt_page(page, sgt_iter, st) 2317 for_each_sgt_page(page, sgt_iter, st)
2317 put_page(page); 2318 put_page(page);
2318 sg_free_table(st); 2319 sg_free_table(st);
@@ -3543,15 +3544,27 @@ i915_gem_object_pin_to_display_plane(struct drm_i915_gem_object *obj,
3543 if (view->type == I915_GGTT_VIEW_NORMAL) 3544 if (view->type == I915_GGTT_VIEW_NORMAL)
3544 vma = i915_gem_object_ggtt_pin(obj, view, 0, alignment, 3545 vma = i915_gem_object_ggtt_pin(obj, view, 0, alignment,
3545 PIN_MAPPABLE | PIN_NONBLOCK); 3546 PIN_MAPPABLE | PIN_NONBLOCK);
3546 if (IS_ERR(vma)) 3547 if (IS_ERR(vma)) {
3547 vma = i915_gem_object_ggtt_pin(obj, view, 0, alignment, 0); 3548 struct drm_i915_private *i915 = to_i915(obj->base.dev);
3549 unsigned int flags;
3550
3551 /* Valleyview is definitely limited to scanning out the first
3552 * 512MiB. Lets presume this behaviour was inherited from the
3553 * g4x display engine and that all earlier gen are similarly
3554 * limited. Testing suggests that it is a little more
3555 * complicated than this. For example, Cherryview appears quite
3556 * happy to scanout from anywhere within its global aperture.
3557 */
3558 flags = 0;
3559 if (HAS_GMCH_DISPLAY(i915))
3560 flags = PIN_MAPPABLE;
3561 vma = i915_gem_object_ggtt_pin(obj, view, 0, alignment, flags);
3562 }
3548 if (IS_ERR(vma)) 3563 if (IS_ERR(vma))
3549 goto err_unpin_display; 3564 goto err_unpin_display;
3550 3565
3551 vma->display_alignment = max_t(u64, vma->display_alignment, alignment); 3566 vma->display_alignment = max_t(u64, vma->display_alignment, alignment);
3552 3567
3553 WARN_ON(obj->pin_display > i915_vma_pin_count(vma));
3554
3555 i915_gem_object_flush_cpu_write_domain(obj); 3568 i915_gem_object_flush_cpu_write_domain(obj);
3556 3569
3557 old_write_domain = obj->base.write_domain; 3570 old_write_domain = obj->base.write_domain;
@@ -3588,7 +3601,6 @@ i915_gem_object_unpin_from_display_plane(struct i915_vma *vma)
3588 list_move_tail(&vma->vm_link, &vma->vm->inactive_list); 3601 list_move_tail(&vma->vm_link, &vma->vm->inactive_list);
3589 3602
3590 i915_vma_unpin(vma); 3603 i915_vma_unpin(vma);
3591 WARN_ON(vma->obj->pin_display > i915_vma_pin_count(vma));
3592} 3604}
3593 3605
3594/** 3606/**
@@ -3745,7 +3757,12 @@ void __i915_vma_set_map_and_fenceable(struct i915_vma *vma)
3745 mappable = (vma->node.start + fence_size <= 3757 mappable = (vma->node.start + fence_size <=
3746 dev_priv->ggtt.mappable_end); 3758 dev_priv->ggtt.mappable_end);
3747 3759
3748 if (mappable && fenceable) 3760 /*
3761 * Explicitly disable for rotated VMA since the display does not
3762 * need the fence and the VMA is not accessible to other users.
3763 */
3764 if (mappable && fenceable &&
3765 vma->ggtt_view.type != I915_GGTT_VIEW_ROTATED)
3749 vma->flags |= I915_VMA_CAN_FENCE; 3766 vma->flags |= I915_VMA_CAN_FENCE;
3750 else 3767 else
3751 vma->flags &= ~I915_VMA_CAN_FENCE; 3768 vma->flags &= ~I915_VMA_CAN_FENCE;
diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
index 7adb4c77cc7f..a218c2e395e7 100644
--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
@@ -1281,6 +1281,12 @@ i915_gem_validate_context(struct drm_device *dev, struct drm_file *file,
1281 return ctx; 1281 return ctx;
1282} 1282}
1283 1283
1284static bool gpu_write_needs_clflush(struct drm_i915_gem_object *obj)
1285{
1286 return !(obj->cache_level == I915_CACHE_NONE ||
1287 obj->cache_level == I915_CACHE_WT);
1288}
1289
1284void i915_vma_move_to_active(struct i915_vma *vma, 1290void i915_vma_move_to_active(struct i915_vma *vma,
1285 struct drm_i915_gem_request *req, 1291 struct drm_i915_gem_request *req,
1286 unsigned int flags) 1292 unsigned int flags)
@@ -1311,6 +1317,8 @@ void i915_vma_move_to_active(struct i915_vma *vma,
1311 1317
1312 /* update for the implicit flush after a batch */ 1318 /* update for the implicit flush after a batch */
1313 obj->base.write_domain &= ~I915_GEM_GPU_DOMAINS; 1319 obj->base.write_domain &= ~I915_GEM_GPU_DOMAINS;
1320 if (!obj->cache_dirty && gpu_write_needs_clflush(obj))
1321 obj->cache_dirty = true;
1314 } 1322 }
1315 1323
1316 if (flags & EXEC_OBJECT_NEEDS_FENCE) 1324 if (flags & EXEC_OBJECT_NEEDS_FENCE)
diff --git a/drivers/gpu/drm/i915/i915_gem_fence.c b/drivers/gpu/drm/i915/i915_gem_fence.c
index 8df1fa7234e8..2c7ba0ee127c 100644
--- a/drivers/gpu/drm/i915/i915_gem_fence.c
+++ b/drivers/gpu/drm/i915/i915_gem_fence.c
@@ -290,6 +290,8 @@ i915_vma_put_fence(struct i915_vma *vma)
290{ 290{
291 struct drm_i915_fence_reg *fence = vma->fence; 291 struct drm_i915_fence_reg *fence = vma->fence;
292 292
293 assert_rpm_wakelock_held(to_i915(vma->vm->dev));
294
293 if (!fence) 295 if (!fence)
294 return 0; 296 return 0;
295 297
@@ -341,6 +343,8 @@ i915_vma_get_fence(struct i915_vma *vma)
341 struct drm_i915_fence_reg *fence; 343 struct drm_i915_fence_reg *fence;
342 struct i915_vma *set = i915_gem_object_is_tiled(vma->obj) ? vma : NULL; 344 struct i915_vma *set = i915_gem_object_is_tiled(vma->obj) ? vma : NULL;
343 345
346 assert_rpm_wakelock_held(to_i915(vma->vm->dev));
347
344 /* Just update our place in the LRU if our fence is getting reused. */ 348 /* Just update our place in the LRU if our fence is getting reused. */
345 if (vma->fence) { 349 if (vma->fence) {
346 fence = vma->fence; 350 fence = vma->fence;
@@ -371,6 +375,12 @@ void i915_gem_restore_fences(struct drm_device *dev)
371 struct drm_i915_private *dev_priv = to_i915(dev); 375 struct drm_i915_private *dev_priv = to_i915(dev);
372 int i; 376 int i;
373 377
378 /* Note that this may be called outside of struct_mutex, by
379 * runtime suspend/resume. The barrier we require is enforced by
380 * rpm itself - all access to fences/GTT are only within an rpm
381 * wakeref, and to acquire that wakeref you must pass through here.
382 */
383
374 for (i = 0; i < dev_priv->num_fence_regs; i++) { 384 for (i = 0; i < dev_priv->num_fence_regs; i++) {
375 struct drm_i915_fence_reg *reg = &dev_priv->fence_regs[i]; 385 struct drm_i915_fence_reg *reg = &dev_priv->fence_regs[i];
376 struct i915_vma *vma = reg->vma; 386 struct i915_vma *vma = reg->vma;
@@ -379,10 +389,17 @@ void i915_gem_restore_fences(struct drm_device *dev)
379 * Commit delayed tiling changes if we have an object still 389 * Commit delayed tiling changes if we have an object still
380 * attached to the fence, otherwise just clear the fence. 390 * attached to the fence, otherwise just clear the fence.
381 */ 391 */
382 if (vma && !i915_gem_object_is_tiled(vma->obj)) 392 if (vma && !i915_gem_object_is_tiled(vma->obj)) {
393 GEM_BUG_ON(!reg->dirty);
394 GEM_BUG_ON(vma->obj->fault_mappable);
395
396 list_move(&reg->link, &dev_priv->mm.fence_list);
397 vma->fence = NULL;
383 vma = NULL; 398 vma = NULL;
399 }
384 400
385 fence_update(reg, vma); 401 fence_write(reg, vma);
402 reg->vma = vma;
386 } 403 }
387} 404}
388 405
diff --git a/drivers/gpu/drm/i915/i915_gem_userptr.c b/drivers/gpu/drm/i915/i915_gem_userptr.c
index e537930c64b5..c6f780f5abc9 100644
--- a/drivers/gpu/drm/i915/i915_gem_userptr.c
+++ b/drivers/gpu/drm/i915/i915_gem_userptr.c
@@ -508,6 +508,10 @@ __i915_gem_userptr_get_pages_worker(struct work_struct *_work)
508 pvec = drm_malloc_gfp(npages, sizeof(struct page *), GFP_TEMPORARY); 508 pvec = drm_malloc_gfp(npages, sizeof(struct page *), GFP_TEMPORARY);
509 if (pvec != NULL) { 509 if (pvec != NULL) {
510 struct mm_struct *mm = obj->userptr.mm->mm; 510 struct mm_struct *mm = obj->userptr.mm->mm;
511 unsigned int flags = 0;
512
513 if (!obj->userptr.read_only)
514 flags |= FOLL_WRITE;
511 515
512 ret = -EFAULT; 516 ret = -EFAULT;
513 if (atomic_inc_not_zero(&mm->mm_users)) { 517 if (atomic_inc_not_zero(&mm->mm_users)) {
@@ -517,7 +521,7 @@ __i915_gem_userptr_get_pages_worker(struct work_struct *_work)
517 (work->task, mm, 521 (work->task, mm,
518 obj->userptr.ptr + pinned * PAGE_SIZE, 522 obj->userptr.ptr + pinned * PAGE_SIZE,
519 npages - pinned, 523 npages - pinned,
520 !obj->userptr.read_only, 0, 524 flags,
521 pvec + pinned, NULL); 525 pvec + pinned, NULL);
522 if (ret < 0) 526 if (ret < 0)
523 break; 527 break;
diff --git a/drivers/gpu/drm/i915/i915_pci.c b/drivers/gpu/drm/i915/i915_pci.c
index 687c768833b3..31e6edd08dd0 100644
--- a/drivers/gpu/drm/i915/i915_pci.c
+++ b/drivers/gpu/drm/i915/i915_pci.c
@@ -431,9 +431,6 @@ static const struct pci_device_id pciidlist[] = {
431}; 431};
432MODULE_DEVICE_TABLE(pci, pciidlist); 432MODULE_DEVICE_TABLE(pci, pciidlist);
433 433
434extern int i915_driver_load(struct pci_dev *pdev,
435 const struct pci_device_id *ent);
436
437static int i915_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) 434static int i915_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
438{ 435{
439 struct intel_device_info *intel_info = 436 struct intel_device_info *intel_info =
@@ -463,8 +460,6 @@ static int i915_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
463 return i915_driver_load(pdev, ent); 460 return i915_driver_load(pdev, ent);
464} 461}
465 462
466extern void i915_driver_unload(struct drm_device *dev);
467
468static void i915_pci_remove(struct pci_dev *pdev) 463static void i915_pci_remove(struct pci_dev *pdev)
469{ 464{
470 struct drm_device *dev = pci_get_drvdata(pdev); 465 struct drm_device *dev = pci_get_drvdata(pdev);
@@ -473,8 +468,6 @@ static void i915_pci_remove(struct pci_dev *pdev)
473 drm_dev_unref(dev); 468 drm_dev_unref(dev);
474} 469}
475 470
476extern const struct dev_pm_ops i915_pm_ops;
477
478static struct pci_driver i915_pci_driver = { 471static struct pci_driver i915_pci_driver = {
479 .name = DRIVER_NAME, 472 .name = DRIVER_NAME,
480 .id_table = pciidlist, 473 .id_table = pciidlist,
diff --git a/drivers/gpu/drm/i915/intel_bios.c b/drivers/gpu/drm/i915/intel_bios.c
index c6e69e4cfa83..cf2560708e03 100644
--- a/drivers/gpu/drm/i915/intel_bios.c
+++ b/drivers/gpu/drm/i915/intel_bios.c
@@ -1031,6 +1031,77 @@ static u8 translate_iboost(u8 val)
1031 return mapping[val]; 1031 return mapping[val];
1032} 1032}
1033 1033
1034static void sanitize_ddc_pin(struct drm_i915_private *dev_priv,
1035 enum port port)
1036{
1037 const struct ddi_vbt_port_info *info =
1038 &dev_priv->vbt.ddi_port_info[port];
1039 enum port p;
1040
1041 if (!info->alternate_ddc_pin)
1042 return;
1043
1044 for_each_port_masked(p, (1 << port) - 1) {
1045 struct ddi_vbt_port_info *i = &dev_priv->vbt.ddi_port_info[p];
1046
1047 if (info->alternate_ddc_pin != i->alternate_ddc_pin)
1048 continue;
1049
1050 DRM_DEBUG_KMS("port %c trying to use the same DDC pin (0x%x) as port %c, "
1051 "disabling port %c DVI/HDMI support\n",
1052 port_name(p), i->alternate_ddc_pin,
1053 port_name(port), port_name(p));
1054
1055 /*
1056 * If we have multiple ports supposedly sharing the
1057 * pin, then dvi/hdmi couldn't exist on the shared
1058 * port. Otherwise they share the same ddc bin and
1059 * system couldn't communicate with them separately.
1060 *
1061 * Due to parsing the ports in alphabetical order,
1062 * a higher port will always clobber a lower one.
1063 */
1064 i->supports_dvi = false;
1065 i->supports_hdmi = false;
1066 i->alternate_ddc_pin = 0;
1067 }
1068}
1069
1070static void sanitize_aux_ch(struct drm_i915_private *dev_priv,
1071 enum port port)
1072{
1073 const struct ddi_vbt_port_info *info =
1074 &dev_priv->vbt.ddi_port_info[port];
1075 enum port p;
1076
1077 if (!info->alternate_aux_channel)
1078 return;
1079
1080 for_each_port_masked(p, (1 << port) - 1) {
1081 struct ddi_vbt_port_info *i = &dev_priv->vbt.ddi_port_info[p];
1082
1083 if (info->alternate_aux_channel != i->alternate_aux_channel)
1084 continue;
1085
1086 DRM_DEBUG_KMS("port %c trying to use the same AUX CH (0x%x) as port %c, "
1087 "disabling port %c DP support\n",
1088 port_name(p), i->alternate_aux_channel,
1089 port_name(port), port_name(p));
1090
1091 /*
1092 * If we have multiple ports supposedlt sharing the
1093 * aux channel, then DP couldn't exist on the shared
1094 * port. Otherwise they share the same aux channel
1095 * and system couldn't communicate with them separately.
1096 *
1097 * Due to parsing the ports in alphabetical order,
1098 * a higher port will always clobber a lower one.
1099 */
1100 i->supports_dp = false;
1101 i->alternate_aux_channel = 0;
1102 }
1103}
1104
1034static void parse_ddi_port(struct drm_i915_private *dev_priv, enum port port, 1105static void parse_ddi_port(struct drm_i915_private *dev_priv, enum port port,
1035 const struct bdb_header *bdb) 1106 const struct bdb_header *bdb)
1036{ 1107{
@@ -1072,7 +1143,7 @@ static void parse_ddi_port(struct drm_i915_private *dev_priv, enum port port,
1072 if (!child) 1143 if (!child)
1073 return; 1144 return;
1074 1145
1075 aux_channel = child->raw[25]; 1146 aux_channel = child->common.aux_channel;
1076 ddc_pin = child->common.ddc_pin; 1147 ddc_pin = child->common.ddc_pin;
1077 1148
1078 is_dvi = child->common.device_type & DEVICE_TYPE_TMDS_DVI_SIGNALING; 1149 is_dvi = child->common.device_type & DEVICE_TYPE_TMDS_DVI_SIGNALING;
@@ -1105,54 +1176,15 @@ static void parse_ddi_port(struct drm_i915_private *dev_priv, enum port port,
1105 DRM_DEBUG_KMS("Port %c is internal DP\n", port_name(port)); 1176 DRM_DEBUG_KMS("Port %c is internal DP\n", port_name(port));
1106 1177
1107 if (is_dvi) { 1178 if (is_dvi) {
1108 if (port == PORT_E) { 1179 info->alternate_ddc_pin = ddc_pin;
1109 info->alternate_ddc_pin = ddc_pin; 1180
1110 /* if DDIE share ddc pin with other port, then 1181 sanitize_ddc_pin(dev_priv, port);
1111 * dvi/hdmi couldn't exist on the shared port.
1112 * Otherwise they share the same ddc bin and system
1113 * couldn't communicate with them seperately. */
1114 if (ddc_pin == DDC_PIN_B) {
1115 dev_priv->vbt.ddi_port_info[PORT_B].supports_dvi = 0;
1116 dev_priv->vbt.ddi_port_info[PORT_B].supports_hdmi = 0;
1117 } else if (ddc_pin == DDC_PIN_C) {
1118 dev_priv->vbt.ddi_port_info[PORT_C].supports_dvi = 0;
1119 dev_priv->vbt.ddi_port_info[PORT_C].supports_hdmi = 0;
1120 } else if (ddc_pin == DDC_PIN_D) {
1121 dev_priv->vbt.ddi_port_info[PORT_D].supports_dvi = 0;
1122 dev_priv->vbt.ddi_port_info[PORT_D].supports_hdmi = 0;
1123 }
1124 } else if (ddc_pin == DDC_PIN_B && port != PORT_B)
1125 DRM_DEBUG_KMS("Unexpected DDC pin for port B\n");
1126 else if (ddc_pin == DDC_PIN_C && port != PORT_C)
1127 DRM_DEBUG_KMS("Unexpected DDC pin for port C\n");
1128 else if (ddc_pin == DDC_PIN_D && port != PORT_D)
1129 DRM_DEBUG_KMS("Unexpected DDC pin for port D\n");
1130 } 1182 }
1131 1183
1132 if (is_dp) { 1184 if (is_dp) {
1133 if (port == PORT_E) { 1185 info->alternate_aux_channel = aux_channel;
1134 info->alternate_aux_channel = aux_channel; 1186
1135 /* if DDIE share aux channel with other port, then 1187 sanitize_aux_ch(dev_priv, port);
1136 * DP couldn't exist on the shared port. Otherwise
1137 * they share the same aux channel and system
1138 * couldn't communicate with them seperately. */
1139 if (aux_channel == DP_AUX_A)
1140 dev_priv->vbt.ddi_port_info[PORT_A].supports_dp = 0;
1141 else if (aux_channel == DP_AUX_B)
1142 dev_priv->vbt.ddi_port_info[PORT_B].supports_dp = 0;
1143 else if (aux_channel == DP_AUX_C)
1144 dev_priv->vbt.ddi_port_info[PORT_C].supports_dp = 0;
1145 else if (aux_channel == DP_AUX_D)
1146 dev_priv->vbt.ddi_port_info[PORT_D].supports_dp = 0;
1147 }
1148 else if (aux_channel == DP_AUX_A && port != PORT_A)
1149 DRM_DEBUG_KMS("Unexpected AUX channel for port A\n");
1150 else if (aux_channel == DP_AUX_B && port != PORT_B)
1151 DRM_DEBUG_KMS("Unexpected AUX channel for port B\n");
1152 else if (aux_channel == DP_AUX_C && port != PORT_C)
1153 DRM_DEBUG_KMS("Unexpected AUX channel for port C\n");
1154 else if (aux_channel == DP_AUX_D && port != PORT_D)
1155 DRM_DEBUG_KMS("Unexpected AUX channel for port D\n");
1156 } 1188 }
1157 1189
1158 if (bdb->version >= 158) { 1190 if (bdb->version >= 158) {
@@ -1641,7 +1673,8 @@ bool intel_bios_is_port_edp(struct drm_i915_private *dev_priv, enum port port)
1641 return false; 1673 return false;
1642} 1674}
1643 1675
1644bool intel_bios_is_port_dp_dual_mode(struct drm_i915_private *dev_priv, enum port port) 1676static bool child_dev_is_dp_dual_mode(const union child_device_config *p_child,
1677 enum port port)
1645{ 1678{
1646 static const struct { 1679 static const struct {
1647 u16 dp, hdmi; 1680 u16 dp, hdmi;
@@ -1655,22 +1688,35 @@ bool intel_bios_is_port_dp_dual_mode(struct drm_i915_private *dev_priv, enum por
1655 [PORT_D] = { DVO_PORT_DPD, DVO_PORT_HDMID, }, 1688 [PORT_D] = { DVO_PORT_DPD, DVO_PORT_HDMID, },
1656 [PORT_E] = { DVO_PORT_DPE, DVO_PORT_HDMIE, }, 1689 [PORT_E] = { DVO_PORT_DPE, DVO_PORT_HDMIE, },
1657 }; 1690 };
1658 int i;
1659 1691
1660 if (port == PORT_A || port >= ARRAY_SIZE(port_mapping)) 1692 if (port == PORT_A || port >= ARRAY_SIZE(port_mapping))
1661 return false; 1693 return false;
1662 1694
1663 if (!dev_priv->vbt.child_dev_num) 1695 if ((p_child->common.device_type & DEVICE_TYPE_DP_DUAL_MODE_BITS) !=
1696 (DEVICE_TYPE_DP_DUAL_MODE & DEVICE_TYPE_DP_DUAL_MODE_BITS))
1664 return false; 1697 return false;
1665 1698
1699 if (p_child->common.dvo_port == port_mapping[port].dp)
1700 return true;
1701
1702 /* Only accept a HDMI dvo_port as DP++ if it has an AUX channel */
1703 if (p_child->common.dvo_port == port_mapping[port].hdmi &&
1704 p_child->common.aux_channel != 0)
1705 return true;
1706
1707 return false;
1708}
1709
1710bool intel_bios_is_port_dp_dual_mode(struct drm_i915_private *dev_priv,
1711 enum port port)
1712{
1713 int i;
1714
1666 for (i = 0; i < dev_priv->vbt.child_dev_num; i++) { 1715 for (i = 0; i < dev_priv->vbt.child_dev_num; i++) {
1667 const union child_device_config *p_child = 1716 const union child_device_config *p_child =
1668 &dev_priv->vbt.child_dev[i]; 1717 &dev_priv->vbt.child_dev[i];
1669 1718
1670 if ((p_child->common.dvo_port == port_mapping[port].dp || 1719 if (child_dev_is_dp_dual_mode(p_child, port))
1671 p_child->common.dvo_port == port_mapping[port].hdmi) &&
1672 (p_child->common.device_type & DEVICE_TYPE_DP_DUAL_MODE_BITS) ==
1673 (DEVICE_TYPE_DP_DUAL_MODE & DEVICE_TYPE_DP_DUAL_MODE_BITS))
1674 return true; 1720 return true;
1675 } 1721 }
1676 1722
diff --git a/drivers/gpu/drm/i915/intel_device_info.c b/drivers/gpu/drm/i915/intel_device_info.c
index 73b6858600ac..1b20e160bc1f 100644
--- a/drivers/gpu/drm/i915/intel_device_info.c
+++ b/drivers/gpu/drm/i915/intel_device_info.c
@@ -192,7 +192,7 @@ static void broadwell_sseu_info_init(struct drm_i915_private *dev_priv)
192 struct sseu_dev_info *sseu = &mkwrite_device_info(dev_priv)->sseu; 192 struct sseu_dev_info *sseu = &mkwrite_device_info(dev_priv)->sseu;
193 const int s_max = 3, ss_max = 3, eu_max = 8; 193 const int s_max = 3, ss_max = 3, eu_max = 8;
194 int s, ss; 194 int s, ss;
195 u32 fuse2, eu_disable[s_max]; 195 u32 fuse2, eu_disable[3]; /* s_max */
196 196
197 fuse2 = I915_READ(GEN8_FUSE2); 197 fuse2 = I915_READ(GEN8_FUSE2);
198 sseu->slice_mask = (fuse2 & GEN8_F2_S_ENA_MASK) >> GEN8_F2_S_ENA_SHIFT; 198 sseu->slice_mask = (fuse2 & GEN8_F2_S_ENA_MASK) >> GEN8_F2_S_ENA_SHIFT;
diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
index fbcfed63a76e..3cb70d73239b 100644
--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -2978,7 +2978,8 @@ int skl_check_plane_surface(struct intel_plane_state *plane_state)
2978 /* Rotate src coordinates to match rotated GTT view */ 2978 /* Rotate src coordinates to match rotated GTT view */
2979 if (intel_rotation_90_or_270(rotation)) 2979 if (intel_rotation_90_or_270(rotation))
2980 drm_rect_rotate(&plane_state->base.src, 2980 drm_rect_rotate(&plane_state->base.src,
2981 fb->width, fb->height, DRM_ROTATE_270); 2981 fb->width << 16, fb->height << 16,
2982 DRM_ROTATE_270);
2982 2983
2983 /* 2984 /*
2984 * Handle the AUX surface first since 2985 * Handle the AUX surface first since
@@ -10242,6 +10243,29 @@ static void bxt_modeset_commit_cdclk(struct drm_atomic_state *old_state)
10242 bxt_set_cdclk(to_i915(dev), req_cdclk); 10243 bxt_set_cdclk(to_i915(dev), req_cdclk);
10243} 10244}
10244 10245
10246static int bdw_adjust_min_pipe_pixel_rate(struct intel_crtc_state *crtc_state,
10247 int pixel_rate)
10248{
10249 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
10250
10251 /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */
10252 if (IS_BROADWELL(dev_priv) && crtc_state->ips_enabled)
10253 pixel_rate = DIV_ROUND_UP(pixel_rate * 100, 95);
10254
10255 /* BSpec says "Do not use DisplayPort with CDCLK less than
10256 * 432 MHz, audio enabled, port width x4, and link rate
10257 * HBR2 (5.4 GHz), or else there may be audio corruption or
10258 * screen corruption."
10259 */
10260 if (intel_crtc_has_dp_encoder(crtc_state) &&
10261 crtc_state->has_audio &&
10262 crtc_state->port_clock >= 540000 &&
10263 crtc_state->lane_count == 4)
10264 pixel_rate = max(432000, pixel_rate);
10265
10266 return pixel_rate;
10267}
10268
10245/* compute the max rate for new configuration */ 10269/* compute the max rate for new configuration */
10246static int ilk_max_pixel_rate(struct drm_atomic_state *state) 10270static int ilk_max_pixel_rate(struct drm_atomic_state *state)
10247{ 10271{
@@ -10267,9 +10291,9 @@ static int ilk_max_pixel_rate(struct drm_atomic_state *state)
10267 10291
10268 pixel_rate = ilk_pipe_pixel_rate(crtc_state); 10292 pixel_rate = ilk_pipe_pixel_rate(crtc_state);
10269 10293
10270 /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */ 10294 if (IS_BROADWELL(dev_priv) || IS_GEN9(dev_priv))
10271 if (IS_BROADWELL(dev_priv) && crtc_state->ips_enabled) 10295 pixel_rate = bdw_adjust_min_pipe_pixel_rate(crtc_state,
10272 pixel_rate = DIV_ROUND_UP(pixel_rate * 100, 95); 10296 pixel_rate);
10273 10297
10274 intel_state->min_pixclk[i] = pixel_rate; 10298 intel_state->min_pixclk[i] = pixel_rate;
10275 } 10299 }
@@ -12236,7 +12260,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
12236 intel_crtc->reset_count = i915_reset_count(&dev_priv->gpu_error); 12260 intel_crtc->reset_count = i915_reset_count(&dev_priv->gpu_error);
12237 if (i915_reset_in_progress_or_wedged(&dev_priv->gpu_error)) { 12261 if (i915_reset_in_progress_or_wedged(&dev_priv->gpu_error)) {
12238 ret = -EIO; 12262 ret = -EIO;
12239 goto cleanup; 12263 goto unlock;
12240 } 12264 }
12241 12265
12242 atomic_inc(&intel_crtc->unpin_work_count); 12266 atomic_inc(&intel_crtc->unpin_work_count);
@@ -12328,6 +12352,7 @@ cleanup_unpin:
12328 intel_unpin_fb_obj(fb, crtc->primary->state->rotation); 12352 intel_unpin_fb_obj(fb, crtc->primary->state->rotation);
12329cleanup_pending: 12353cleanup_pending:
12330 atomic_dec(&intel_crtc->unpin_work_count); 12354 atomic_dec(&intel_crtc->unpin_work_count);
12355unlock:
12331 mutex_unlock(&dev->struct_mutex); 12356 mutex_unlock(&dev->struct_mutex);
12332cleanup: 12357cleanup:
12333 crtc->primary->fb = old_fb; 12358 crtc->primary->fb = old_fb;
@@ -14310,7 +14335,7 @@ static void intel_atomic_commit_tail(struct drm_atomic_state *state)
14310 14335
14311 for_each_plane_in_state(state, plane, plane_state, i) { 14336 for_each_plane_in_state(state, plane, plane_state, i) {
14312 struct intel_plane_state *intel_plane_state = 14337 struct intel_plane_state *intel_plane_state =
14313 to_intel_plane_state(plane_state); 14338 to_intel_plane_state(plane->state);
14314 14339
14315 if (!intel_plane_state->wait_req) 14340 if (!intel_plane_state->wait_req)
14316 continue; 14341 continue;
diff --git a/drivers/gpu/drm/i915/intel_dp.c b/drivers/gpu/drm/i915/intel_dp.c
index 14a3cf0b7213..bf344d08356a 100644
--- a/drivers/gpu/drm/i915/intel_dp.c
+++ b/drivers/gpu/drm/i915/intel_dp.c
@@ -1108,6 +1108,44 @@ intel_dp_aux_transfer(struct drm_dp_aux *aux, struct drm_dp_aux_msg *msg)
1108 return ret; 1108 return ret;
1109} 1109}
1110 1110
1111static enum port intel_aux_port(struct drm_i915_private *dev_priv,
1112 enum port port)
1113{
1114 const struct ddi_vbt_port_info *info =
1115 &dev_priv->vbt.ddi_port_info[port];
1116 enum port aux_port;
1117
1118 if (!info->alternate_aux_channel) {
1119 DRM_DEBUG_KMS("using AUX %c for port %c (platform default)\n",
1120 port_name(port), port_name(port));
1121 return port;
1122 }
1123
1124 switch (info->alternate_aux_channel) {
1125 case DP_AUX_A:
1126 aux_port = PORT_A;
1127 break;
1128 case DP_AUX_B:
1129 aux_port = PORT_B;
1130 break;
1131 case DP_AUX_C:
1132 aux_port = PORT_C;
1133 break;
1134 case DP_AUX_D:
1135 aux_port = PORT_D;
1136 break;
1137 default:
1138 MISSING_CASE(info->alternate_aux_channel);
1139 aux_port = PORT_A;
1140 break;
1141 }
1142
1143 DRM_DEBUG_KMS("using AUX %c for port %c (VBT)\n",
1144 port_name(aux_port), port_name(port));
1145
1146 return aux_port;
1147}
1148
1111static i915_reg_t g4x_aux_ctl_reg(struct drm_i915_private *dev_priv, 1149static i915_reg_t g4x_aux_ctl_reg(struct drm_i915_private *dev_priv,
1112 enum port port) 1150 enum port port)
1113{ 1151{
@@ -1168,36 +1206,9 @@ static i915_reg_t ilk_aux_data_reg(struct drm_i915_private *dev_priv,
1168 } 1206 }
1169} 1207}
1170 1208
1171/*
1172 * On SKL we don't have Aux for port E so we rely
1173 * on VBT to set a proper alternate aux channel.
1174 */
1175static enum port skl_porte_aux_port(struct drm_i915_private *dev_priv)
1176{
1177 const struct ddi_vbt_port_info *info =
1178 &dev_priv->vbt.ddi_port_info[PORT_E];
1179
1180 switch (info->alternate_aux_channel) {
1181 case DP_AUX_A:
1182 return PORT_A;
1183 case DP_AUX_B:
1184 return PORT_B;
1185 case DP_AUX_C:
1186 return PORT_C;
1187 case DP_AUX_D:
1188 return PORT_D;
1189 default:
1190 MISSING_CASE(info->alternate_aux_channel);
1191 return PORT_A;
1192 }
1193}
1194
1195static i915_reg_t skl_aux_ctl_reg(struct drm_i915_private *dev_priv, 1209static i915_reg_t skl_aux_ctl_reg(struct drm_i915_private *dev_priv,
1196 enum port port) 1210 enum port port)
1197{ 1211{
1198 if (port == PORT_E)
1199 port = skl_porte_aux_port(dev_priv);
1200
1201 switch (port) { 1212 switch (port) {
1202 case PORT_A: 1213 case PORT_A:
1203 case PORT_B: 1214 case PORT_B:
@@ -1213,9 +1224,6 @@ static i915_reg_t skl_aux_ctl_reg(struct drm_i915_private *dev_priv,
1213static i915_reg_t skl_aux_data_reg(struct drm_i915_private *dev_priv, 1224static i915_reg_t skl_aux_data_reg(struct drm_i915_private *dev_priv,
1214 enum port port, int index) 1225 enum port port, int index)
1215{ 1226{
1216 if (port == PORT_E)
1217 port = skl_porte_aux_port(dev_priv);
1218
1219 switch (port) { 1227 switch (port) {
1220 case PORT_A: 1228 case PORT_A:
1221 case PORT_B: 1229 case PORT_B:
@@ -1253,7 +1261,8 @@ static i915_reg_t intel_aux_data_reg(struct drm_i915_private *dev_priv,
1253static void intel_aux_reg_init(struct intel_dp *intel_dp) 1261static void intel_aux_reg_init(struct intel_dp *intel_dp)
1254{ 1262{
1255 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp)); 1263 struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
1256 enum port port = dp_to_dig_port(intel_dp)->port; 1264 enum port port = intel_aux_port(dev_priv,
1265 dp_to_dig_port(intel_dp)->port);
1257 int i; 1266 int i;
1258 1267
1259 intel_dp->aux_ch_ctl_reg = intel_aux_ctl_reg(dev_priv, port); 1268 intel_dp->aux_ch_ctl_reg = intel_aux_ctl_reg(dev_priv, port);
@@ -3551,8 +3560,8 @@ intel_edp_init_dpcd(struct intel_dp *intel_dp)
3551 /* Read the eDP Display control capabilities registers */ 3560 /* Read the eDP Display control capabilities registers */
3552 if ((intel_dp->dpcd[DP_EDP_CONFIGURATION_CAP] & DP_DPCD_DISPLAY_CONTROL_CAPABLE) && 3561 if ((intel_dp->dpcd[DP_EDP_CONFIGURATION_CAP] & DP_DPCD_DISPLAY_CONTROL_CAPABLE) &&
3553 drm_dp_dpcd_read(&intel_dp->aux, DP_EDP_DPCD_REV, 3562 drm_dp_dpcd_read(&intel_dp->aux, DP_EDP_DPCD_REV,
3554 intel_dp->edp_dpcd, sizeof(intel_dp->edp_dpcd) == 3563 intel_dp->edp_dpcd, sizeof(intel_dp->edp_dpcd)) ==
3555 sizeof(intel_dp->edp_dpcd))) 3564 sizeof(intel_dp->edp_dpcd))
3556 DRM_DEBUG_KMS("EDP DPCD : %*ph\n", (int) sizeof(intel_dp->edp_dpcd), 3565 DRM_DEBUG_KMS("EDP DPCD : %*ph\n", (int) sizeof(intel_dp->edp_dpcd),
3557 intel_dp->edp_dpcd); 3566 intel_dp->edp_dpcd);
3558 3567
@@ -4454,21 +4463,11 @@ static enum drm_connector_status
4454intel_dp_detect(struct drm_connector *connector, bool force) 4463intel_dp_detect(struct drm_connector *connector, bool force)
4455{ 4464{
4456 struct intel_dp *intel_dp = intel_attached_dp(connector); 4465 struct intel_dp *intel_dp = intel_attached_dp(connector);
4457 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
4458 struct intel_encoder *intel_encoder = &intel_dig_port->base;
4459 enum drm_connector_status status = connector->status; 4466 enum drm_connector_status status = connector->status;
4460 4467
4461 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", 4468 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
4462 connector->base.id, connector->name); 4469 connector->base.id, connector->name);
4463 4470
4464 if (intel_dp->is_mst) {
4465 /* MST devices are disconnected from a monitor POV */
4466 intel_dp_unset_edid(intel_dp);
4467 if (intel_encoder->type != INTEL_OUTPUT_EDP)
4468 intel_encoder->type = INTEL_OUTPUT_DP;
4469 return connector_status_disconnected;
4470 }
4471
4472 /* If full detect is not performed yet, do a full detect */ 4471 /* If full detect is not performed yet, do a full detect */
4473 if (!intel_dp->detect_done) 4472 if (!intel_dp->detect_done)
4474 status = intel_dp_long_pulse(intel_dp->attached_connector); 4473 status = intel_dp_long_pulse(intel_dp->attached_connector);
diff --git a/drivers/gpu/drm/i915/intel_fbc.c b/drivers/gpu/drm/i915/intel_fbc.c
index faa67624e1ed..c43dd9abce79 100644
--- a/drivers/gpu/drm/i915/intel_fbc.c
+++ b/drivers/gpu/drm/i915/intel_fbc.c
@@ -104,8 +104,10 @@ static int intel_fbc_calculate_cfb_size(struct drm_i915_private *dev_priv,
104 int lines; 104 int lines;
105 105
106 intel_fbc_get_plane_source_size(cache, NULL, &lines); 106 intel_fbc_get_plane_source_size(cache, NULL, &lines);
107 if (INTEL_INFO(dev_priv)->gen >= 7) 107 if (INTEL_GEN(dev_priv) == 7)
108 lines = min(lines, 2048); 108 lines = min(lines, 2048);
109 else if (INTEL_GEN(dev_priv) >= 8)
110 lines = min(lines, 2560);
109 111
110 /* Hardware needs the full buffer stride, not just the active area. */ 112 /* Hardware needs the full buffer stride, not just the active area. */
111 return lines * cache->fb.stride; 113 return lines * cache->fb.stride;
diff --git a/drivers/gpu/drm/i915/intel_hdmi.c b/drivers/gpu/drm/i915/intel_hdmi.c
index f40a35f2913a..13c306173f27 100644
--- a/drivers/gpu/drm/i915/intel_hdmi.c
+++ b/drivers/gpu/drm/i915/intel_hdmi.c
@@ -1799,6 +1799,50 @@ intel_hdmi_add_properties(struct intel_hdmi *intel_hdmi, struct drm_connector *c
1799 intel_hdmi->aspect_ratio = HDMI_PICTURE_ASPECT_NONE; 1799 intel_hdmi->aspect_ratio = HDMI_PICTURE_ASPECT_NONE;
1800} 1800}
1801 1801
1802static u8 intel_hdmi_ddc_pin(struct drm_i915_private *dev_priv,
1803 enum port port)
1804{
1805 const struct ddi_vbt_port_info *info =
1806 &dev_priv->vbt.ddi_port_info[port];
1807 u8 ddc_pin;
1808
1809 if (info->alternate_ddc_pin) {
1810 DRM_DEBUG_KMS("Using DDC pin 0x%x for port %c (VBT)\n",
1811 info->alternate_ddc_pin, port_name(port));
1812 return info->alternate_ddc_pin;
1813 }
1814
1815 switch (port) {
1816 case PORT_B:
1817 if (IS_BROXTON(dev_priv))
1818 ddc_pin = GMBUS_PIN_1_BXT;
1819 else
1820 ddc_pin = GMBUS_PIN_DPB;
1821 break;
1822 case PORT_C:
1823 if (IS_BROXTON(dev_priv))
1824 ddc_pin = GMBUS_PIN_2_BXT;
1825 else
1826 ddc_pin = GMBUS_PIN_DPC;
1827 break;
1828 case PORT_D:
1829 if (IS_CHERRYVIEW(dev_priv))
1830 ddc_pin = GMBUS_PIN_DPD_CHV;
1831 else
1832 ddc_pin = GMBUS_PIN_DPD;
1833 break;
1834 default:
1835 MISSING_CASE(port);
1836 ddc_pin = GMBUS_PIN_DPB;
1837 break;
1838 }
1839
1840 DRM_DEBUG_KMS("Using DDC pin 0x%x for port %c (platform default)\n",
1841 ddc_pin, port_name(port));
1842
1843 return ddc_pin;
1844}
1845
1802void intel_hdmi_init_connector(struct intel_digital_port *intel_dig_port, 1846void intel_hdmi_init_connector(struct intel_digital_port *intel_dig_port,
1803 struct intel_connector *intel_connector) 1847 struct intel_connector *intel_connector)
1804{ 1848{
@@ -1808,7 +1852,6 @@ void intel_hdmi_init_connector(struct intel_digital_port *intel_dig_port,
1808 struct drm_device *dev = intel_encoder->base.dev; 1852 struct drm_device *dev = intel_encoder->base.dev;
1809 struct drm_i915_private *dev_priv = to_i915(dev); 1853 struct drm_i915_private *dev_priv = to_i915(dev);
1810 enum port port = intel_dig_port->port; 1854 enum port port = intel_dig_port->port;
1811 uint8_t alternate_ddc_pin;
1812 1855
1813 DRM_DEBUG_KMS("Adding HDMI connector on port %c\n", 1856 DRM_DEBUG_KMS("Adding HDMI connector on port %c\n",
1814 port_name(port)); 1857 port_name(port));
@@ -1826,12 +1869,10 @@ void intel_hdmi_init_connector(struct intel_digital_port *intel_dig_port,
1826 connector->doublescan_allowed = 0; 1869 connector->doublescan_allowed = 0;
1827 connector->stereo_allowed = 1; 1870 connector->stereo_allowed = 1;
1828 1871
1872 intel_hdmi->ddc_bus = intel_hdmi_ddc_pin(dev_priv, port);
1873
1829 switch (port) { 1874 switch (port) {
1830 case PORT_B: 1875 case PORT_B:
1831 if (IS_BROXTON(dev_priv))
1832 intel_hdmi->ddc_bus = GMBUS_PIN_1_BXT;
1833 else
1834 intel_hdmi->ddc_bus = GMBUS_PIN_DPB;
1835 /* 1876 /*
1836 * On BXT A0/A1, sw needs to activate DDIA HPD logic and 1877 * On BXT A0/A1, sw needs to activate DDIA HPD logic and
1837 * interrupts to check the external panel connection. 1878 * interrupts to check the external panel connection.
@@ -1842,46 +1883,17 @@ void intel_hdmi_init_connector(struct intel_digital_port *intel_dig_port,
1842 intel_encoder->hpd_pin = HPD_PORT_B; 1883 intel_encoder->hpd_pin = HPD_PORT_B;
1843 break; 1884 break;
1844 case PORT_C: 1885 case PORT_C:
1845 if (IS_BROXTON(dev_priv))
1846 intel_hdmi->ddc_bus = GMBUS_PIN_2_BXT;
1847 else
1848 intel_hdmi->ddc_bus = GMBUS_PIN_DPC;
1849 intel_encoder->hpd_pin = HPD_PORT_C; 1886 intel_encoder->hpd_pin = HPD_PORT_C;
1850 break; 1887 break;
1851 case PORT_D: 1888 case PORT_D:
1852 if (WARN_ON(IS_BROXTON(dev_priv)))
1853 intel_hdmi->ddc_bus = GMBUS_PIN_DISABLED;
1854 else if (IS_CHERRYVIEW(dev_priv))
1855 intel_hdmi->ddc_bus = GMBUS_PIN_DPD_CHV;
1856 else
1857 intel_hdmi->ddc_bus = GMBUS_PIN_DPD;
1858 intel_encoder->hpd_pin = HPD_PORT_D; 1889 intel_encoder->hpd_pin = HPD_PORT_D;
1859 break; 1890 break;
1860 case PORT_E: 1891 case PORT_E:
1861 /* On SKL PORT E doesn't have seperate GMBUS pin
1862 * We rely on VBT to set a proper alternate GMBUS pin. */
1863 alternate_ddc_pin =
1864 dev_priv->vbt.ddi_port_info[PORT_E].alternate_ddc_pin;
1865 switch (alternate_ddc_pin) {
1866 case DDC_PIN_B:
1867 intel_hdmi->ddc_bus = GMBUS_PIN_DPB;
1868 break;
1869 case DDC_PIN_C:
1870 intel_hdmi->ddc_bus = GMBUS_PIN_DPC;
1871 break;
1872 case DDC_PIN_D:
1873 intel_hdmi->ddc_bus = GMBUS_PIN_DPD;
1874 break;
1875 default:
1876 MISSING_CASE(alternate_ddc_pin);
1877 }
1878 intel_encoder->hpd_pin = HPD_PORT_E; 1892 intel_encoder->hpd_pin = HPD_PORT_E;
1879 break; 1893 break;
1880 case PORT_A:
1881 intel_encoder->hpd_pin = HPD_PORT_A;
1882 /* Internal port only for eDP. */
1883 default: 1894 default:
1884 BUG(); 1895 MISSING_CASE(port);
1896 return;
1885 } 1897 }
1886 1898
1887 if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) { 1899 if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) {
diff --git a/drivers/gpu/drm/i915/intel_pm.c b/drivers/gpu/drm/i915/intel_pm.c
index a2f751cd187a..db24f898853c 100644
--- a/drivers/gpu/drm/i915/intel_pm.c
+++ b/drivers/gpu/drm/i915/intel_pm.c
@@ -3362,13 +3362,15 @@ skl_allocate_pipe_ddb(struct intel_crtc_state *cstate,
3362 int num_active; 3362 int num_active;
3363 int id, i; 3363 int id, i;
3364 3364
3365 /* Clear the partitioning for disabled planes. */
3366 memset(ddb->plane[pipe], 0, sizeof(ddb->plane[pipe]));
3367 memset(ddb->y_plane[pipe], 0, sizeof(ddb->y_plane[pipe]));
3368
3365 if (WARN_ON(!state)) 3369 if (WARN_ON(!state))
3366 return 0; 3370 return 0;
3367 3371
3368 if (!cstate->base.active) { 3372 if (!cstate->base.active) {
3369 ddb->pipe[pipe].start = ddb->pipe[pipe].end = 0; 3373 ddb->pipe[pipe].start = ddb->pipe[pipe].end = 0;
3370 memset(ddb->plane[pipe], 0, sizeof(ddb->plane[pipe]));
3371 memset(ddb->y_plane[pipe], 0, sizeof(ddb->y_plane[pipe]));
3372 return 0; 3374 return 0;
3373 } 3375 }
3374 3376
@@ -3468,12 +3470,6 @@ skl_allocate_pipe_ddb(struct intel_crtc_state *cstate,
3468 return 0; 3470 return 0;
3469} 3471}
3470 3472
3471static uint32_t skl_pipe_pixel_rate(const struct intel_crtc_state *config)
3472{
3473 /* TODO: Take into account the scalers once we support them */
3474 return config->base.adjusted_mode.crtc_clock;
3475}
3476
3477/* 3473/*
3478 * The max latency should be 257 (max the punit can code is 255 and we add 2us 3474 * The max latency should be 257 (max the punit can code is 255 and we add 2us
3479 * for the read latency) and cpp should always be <= 8, so that 3475 * for the read latency) and cpp should always be <= 8, so that
@@ -3524,7 +3520,7 @@ static uint32_t skl_adjusted_plane_pixel_rate(const struct intel_crtc_state *cst
3524 * Adjusted plane pixel rate is just the pipe's adjusted pixel rate 3520 * Adjusted plane pixel rate is just the pipe's adjusted pixel rate
3525 * with additional adjustments for plane-specific scaling. 3521 * with additional adjustments for plane-specific scaling.
3526 */ 3522 */
3527 adjusted_pixel_rate = skl_pipe_pixel_rate(cstate); 3523 adjusted_pixel_rate = ilk_pipe_pixel_rate(cstate);
3528 downscale_amount = skl_plane_downscale_amount(pstate); 3524 downscale_amount = skl_plane_downscale_amount(pstate);
3529 3525
3530 pixel_rate = adjusted_pixel_rate * downscale_amount >> 16; 3526 pixel_rate = adjusted_pixel_rate * downscale_amount >> 16;
@@ -3736,11 +3732,11 @@ skl_compute_linetime_wm(struct intel_crtc_state *cstate)
3736 if (!cstate->base.active) 3732 if (!cstate->base.active)
3737 return 0; 3733 return 0;
3738 3734
3739 if (WARN_ON(skl_pipe_pixel_rate(cstate) == 0)) 3735 if (WARN_ON(ilk_pipe_pixel_rate(cstate) == 0))
3740 return 0; 3736 return 0;
3741 3737
3742 return DIV_ROUND_UP(8 * cstate->base.adjusted_mode.crtc_htotal * 1000, 3738 return DIV_ROUND_UP(8 * cstate->base.adjusted_mode.crtc_htotal * 1000,
3743 skl_pipe_pixel_rate(cstate)); 3739 ilk_pipe_pixel_rate(cstate));
3744} 3740}
3745 3741
3746static void skl_compute_transition_wm(struct intel_crtc_state *cstate, 3742static void skl_compute_transition_wm(struct intel_crtc_state *cstate,
@@ -4050,6 +4046,12 @@ skl_compute_ddb(struct drm_atomic_state *state)
4050 intel_state->wm_results.dirty_pipes = ~0; 4046 intel_state->wm_results.dirty_pipes = ~0;
4051 } 4047 }
4052 4048
4049 /*
4050 * We're not recomputing for the pipes not included in the commit, so
4051 * make sure we start with the current state.
4052 */
4053 memcpy(ddb, &dev_priv->wm.skl_hw.ddb, sizeof(*ddb));
4054
4053 for_each_intel_crtc_mask(dev, intel_crtc, realloc_pipes) { 4055 for_each_intel_crtc_mask(dev, intel_crtc, realloc_pipes) {
4054 struct intel_crtc_state *cstate; 4056 struct intel_crtc_state *cstate;
4055 4057
diff --git a/drivers/gpu/drm/i915/intel_runtime_pm.c b/drivers/gpu/drm/i915/intel_runtime_pm.c
index 6c11168facd6..a38c2fefe85a 100644
--- a/drivers/gpu/drm/i915/intel_runtime_pm.c
+++ b/drivers/gpu/drm/i915/intel_runtime_pm.c
@@ -1139,7 +1139,9 @@ static void vlv_display_power_well_deinit(struct drm_i915_private *dev_priv)
1139 1139
1140 intel_power_sequencer_reset(dev_priv); 1140 intel_power_sequencer_reset(dev_priv);
1141 1141
1142 intel_hpd_poll_init(dev_priv); 1142 /* Prevent us from re-enabling polling on accident in late suspend */
1143 if (!dev_priv->drm.dev->power.is_suspended)
1144 intel_hpd_poll_init(dev_priv);
1143} 1145}
1144 1146
1145static void vlv_display_power_well_enable(struct drm_i915_private *dev_priv, 1147static void vlv_display_power_well_enable(struct drm_i915_private *dev_priv,
diff --git a/drivers/gpu/drm/i915/intel_sprite.c b/drivers/gpu/drm/i915/intel_sprite.c
index 73a521fdf1bd..dbed12c484c9 100644
--- a/drivers/gpu/drm/i915/intel_sprite.c
+++ b/drivers/gpu/drm/i915/intel_sprite.c
@@ -358,7 +358,7 @@ vlv_update_plane(struct drm_plane *dplane,
358 int plane = intel_plane->plane; 358 int plane = intel_plane->plane;
359 u32 sprctl; 359 u32 sprctl;
360 u32 sprsurf_offset, linear_offset; 360 u32 sprsurf_offset, linear_offset;
361 unsigned int rotation = dplane->state->rotation; 361 unsigned int rotation = plane_state->base.rotation;
362 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey; 362 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
363 int crtc_x = plane_state->base.dst.x1; 363 int crtc_x = plane_state->base.dst.x1;
364 int crtc_y = plane_state->base.dst.y1; 364 int crtc_y = plane_state->base.dst.y1;
diff --git a/drivers/gpu/drm/i915/intel_vbt_defs.h b/drivers/gpu/drm/i915/intel_vbt_defs.h
index 68db9621f1f0..8886cab19f98 100644
--- a/drivers/gpu/drm/i915/intel_vbt_defs.h
+++ b/drivers/gpu/drm/i915/intel_vbt_defs.h
@@ -280,7 +280,8 @@ struct common_child_dev_config {
280 u8 dp_support:1; 280 u8 dp_support:1;
281 u8 tmds_support:1; 281 u8 tmds_support:1;
282 u8 support_reserved:5; 282 u8 support_reserved:5;
283 u8 not_common3[12]; 283 u8 aux_channel;
284 u8 not_common3[11];
284 u8 iboost_level; 285 u8 iboost_level;
285} __packed; 286} __packed;
286 287
diff --git a/drivers/gpu/drm/imx/imx-drm-core.c b/drivers/gpu/drm/imx/imx-drm-core.c
index 98df09c2b388..9672b579f950 100644
--- a/drivers/gpu/drm/imx/imx-drm-core.c
+++ b/drivers/gpu/drm/imx/imx-drm-core.c
@@ -357,8 +357,8 @@ static int imx_drm_bind(struct device *dev)
357 int ret; 357 int ret;
358 358
359 drm = drm_dev_alloc(&imx_drm_driver, dev); 359 drm = drm_dev_alloc(&imx_drm_driver, dev);
360 if (!drm) 360 if (IS_ERR(drm))
361 return -ENOMEM; 361 return PTR_ERR(drm);
362 362
363 imxdrm = devm_kzalloc(dev, sizeof(*imxdrm), GFP_KERNEL); 363 imxdrm = devm_kzalloc(dev, sizeof(*imxdrm), GFP_KERNEL);
364 if (!imxdrm) { 364 if (!imxdrm) {
@@ -436,9 +436,11 @@ static int imx_drm_bind(struct device *dev)
436 436
437err_fbhelper: 437err_fbhelper:
438 drm_kms_helper_poll_fini(drm); 438 drm_kms_helper_poll_fini(drm);
439#if IS_ENABLED(CONFIG_DRM_FBDEV_EMULATION)
439 if (imxdrm->fbhelper) 440 if (imxdrm->fbhelper)
440 drm_fbdev_cma_fini(imxdrm->fbhelper); 441 drm_fbdev_cma_fini(imxdrm->fbhelper);
441err_unbind: 442err_unbind:
443#endif
442 component_unbind_all(drm->dev, drm); 444 component_unbind_all(drm->dev, drm);
443err_vblank: 445err_vblank:
444 drm_vblank_cleanup(drm); 446 drm_vblank_cleanup(drm);
diff --git a/drivers/gpu/drm/imx/ipuv3-crtc.c b/drivers/gpu/drm/imx/ipuv3-crtc.c
index 4e1ae3fc462d..6be515a9fb69 100644
--- a/drivers/gpu/drm/imx/ipuv3-crtc.c
+++ b/drivers/gpu/drm/imx/ipuv3-crtc.c
@@ -68,6 +68,12 @@ static void ipu_crtc_atomic_disable(struct drm_crtc *crtc,
68 68
69 ipu_dc_disable_channel(ipu_crtc->dc); 69 ipu_dc_disable_channel(ipu_crtc->dc);
70 ipu_di_disable(ipu_crtc->di); 70 ipu_di_disable(ipu_crtc->di);
71 /*
72 * Planes must be disabled before DC clock is removed, as otherwise the
73 * attached IDMACs will be left in undefined state, possibly hanging
74 * the IPU or even system.
75 */
76 drm_atomic_helper_disable_planes_on_crtc(old_crtc_state, false);
71 ipu_dc_disable(ipu); 77 ipu_dc_disable(ipu);
72 78
73 spin_lock_irq(&crtc->dev->event_lock); 79 spin_lock_irq(&crtc->dev->event_lock);
@@ -77,9 +83,6 @@ static void ipu_crtc_atomic_disable(struct drm_crtc *crtc,
77 } 83 }
78 spin_unlock_irq(&crtc->dev->event_lock); 84 spin_unlock_irq(&crtc->dev->event_lock);
79 85
80 /* always disable planes on the CRTC */
81 drm_atomic_helper_disable_planes_on_crtc(old_crtc_state, true);
82
83 drm_crtc_vblank_off(crtc); 86 drm_crtc_vblank_off(crtc);
84} 87}
85 88
diff --git a/drivers/gpu/drm/imx/ipuv3-plane.c b/drivers/gpu/drm/imx/ipuv3-plane.c
index ce22d0a0ddc8..d5864ed4d772 100644
--- a/drivers/gpu/drm/imx/ipuv3-plane.c
+++ b/drivers/gpu/drm/imx/ipuv3-plane.c
@@ -103,11 +103,11 @@ drm_plane_state_to_vbo(struct drm_plane_state *state)
103 (state->src_x >> 16) / 2 - eba; 103 (state->src_x >> 16) / 2 - eba;
104} 104}
105 105
106static void ipu_plane_atomic_set_base(struct ipu_plane *ipu_plane, 106static void ipu_plane_atomic_set_base(struct ipu_plane *ipu_plane)
107 struct drm_plane_state *old_state)
108{ 107{
109 struct drm_plane *plane = &ipu_plane->base; 108 struct drm_plane *plane = &ipu_plane->base;
110 struct drm_plane_state *state = plane->state; 109 struct drm_plane_state *state = plane->state;
110 struct drm_crtc_state *crtc_state = state->crtc->state;
111 struct drm_framebuffer *fb = state->fb; 111 struct drm_framebuffer *fb = state->fb;
112 unsigned long eba, ubo, vbo; 112 unsigned long eba, ubo, vbo;
113 int active; 113 int active;
@@ -117,7 +117,7 @@ static void ipu_plane_atomic_set_base(struct ipu_plane *ipu_plane,
117 switch (fb->pixel_format) { 117 switch (fb->pixel_format) {
118 case DRM_FORMAT_YUV420: 118 case DRM_FORMAT_YUV420:
119 case DRM_FORMAT_YVU420: 119 case DRM_FORMAT_YVU420:
120 if (old_state->fb) 120 if (!drm_atomic_crtc_needs_modeset(crtc_state))
121 break; 121 break;
122 122
123 /* 123 /*
@@ -149,7 +149,7 @@ static void ipu_plane_atomic_set_base(struct ipu_plane *ipu_plane,
149 break; 149 break;
150 } 150 }
151 151
152 if (old_state->fb) { 152 if (!drm_atomic_crtc_needs_modeset(crtc_state)) {
153 active = ipu_idmac_get_current_buffer(ipu_plane->ipu_ch); 153 active = ipu_idmac_get_current_buffer(ipu_plane->ipu_ch);
154 ipu_cpmem_set_buffer(ipu_plane->ipu_ch, !active, eba); 154 ipu_cpmem_set_buffer(ipu_plane->ipu_ch, !active, eba);
155 ipu_idmac_select_buffer(ipu_plane->ipu_ch, !active); 155 ipu_idmac_select_buffer(ipu_plane->ipu_ch, !active);
@@ -259,6 +259,7 @@ static int ipu_plane_atomic_check(struct drm_plane *plane,
259 struct drm_framebuffer *fb = state->fb; 259 struct drm_framebuffer *fb = state->fb;
260 struct drm_framebuffer *old_fb = old_state->fb; 260 struct drm_framebuffer *old_fb = old_state->fb;
261 unsigned long eba, ubo, vbo, old_ubo, old_vbo; 261 unsigned long eba, ubo, vbo, old_ubo, old_vbo;
262 int hsub, vsub;
262 263
263 /* Ok to disable */ 264 /* Ok to disable */
264 if (!fb) 265 if (!fb)
@@ -355,7 +356,9 @@ static int ipu_plane_atomic_check(struct drm_plane *plane,
355 if ((ubo > 0xfffff8) || (vbo > 0xfffff8)) 356 if ((ubo > 0xfffff8) || (vbo > 0xfffff8))
356 return -EINVAL; 357 return -EINVAL;
357 358
358 if (old_fb) { 359 if (old_fb &&
360 (old_fb->pixel_format == DRM_FORMAT_YUV420 ||
361 old_fb->pixel_format == DRM_FORMAT_YVU420)) {
359 old_ubo = drm_plane_state_to_ubo(old_state); 362 old_ubo = drm_plane_state_to_ubo(old_state);
360 old_vbo = drm_plane_state_to_vbo(old_state); 363 old_vbo = drm_plane_state_to_vbo(old_state);
361 if (ubo != old_ubo || vbo != old_vbo) 364 if (ubo != old_ubo || vbo != old_vbo)
@@ -370,6 +373,16 @@ static int ipu_plane_atomic_check(struct drm_plane *plane,
370 373
371 if (old_fb && old_fb->pitches[1] != fb->pitches[1]) 374 if (old_fb && old_fb->pitches[1] != fb->pitches[1])
372 crtc_state->mode_changed = true; 375 crtc_state->mode_changed = true;
376
377 /*
378 * The x/y offsets must be even in case of horizontal/vertical
379 * chroma subsampling.
380 */
381 hsub = drm_format_horz_chroma_subsampling(fb->pixel_format);
382 vsub = drm_format_vert_chroma_subsampling(fb->pixel_format);
383 if (((state->src_x >> 16) & (hsub - 1)) ||
384 ((state->src_y >> 16) & (vsub - 1)))
385 return -EINVAL;
373 } 386 }
374 387
375 return 0; 388 return 0;
@@ -392,7 +405,7 @@ static void ipu_plane_atomic_update(struct drm_plane *plane,
392 struct drm_crtc_state *crtc_state = state->crtc->state; 405 struct drm_crtc_state *crtc_state = state->crtc->state;
393 406
394 if (!drm_atomic_crtc_needs_modeset(crtc_state)) { 407 if (!drm_atomic_crtc_needs_modeset(crtc_state)) {
395 ipu_plane_atomic_set_base(ipu_plane, old_state); 408 ipu_plane_atomic_set_base(ipu_plane);
396 return; 409 return;
397 } 410 }
398 } 411 }
@@ -424,6 +437,7 @@ static void ipu_plane_atomic_update(struct drm_plane *plane,
424 ipu_dp_set_global_alpha(ipu_plane->dp, false, 0, false); 437 ipu_dp_set_global_alpha(ipu_plane->dp, false, 0, false);
425 break; 438 break;
426 default: 439 default:
440 ipu_dp_set_global_alpha(ipu_plane->dp, true, 0, true);
427 break; 441 break;
428 } 442 }
429 } 443 }
@@ -437,7 +451,7 @@ static void ipu_plane_atomic_update(struct drm_plane *plane,
437 ipu_cpmem_set_high_priority(ipu_plane->ipu_ch); 451 ipu_cpmem_set_high_priority(ipu_plane->ipu_ch);
438 ipu_idmac_set_double_buffer(ipu_plane->ipu_ch, 1); 452 ipu_idmac_set_double_buffer(ipu_plane->ipu_ch, 1);
439 ipu_cpmem_set_stride(ipu_plane->ipu_ch, state->fb->pitches[0]); 453 ipu_cpmem_set_stride(ipu_plane->ipu_ch, state->fb->pitches[0]);
440 ipu_plane_atomic_set_base(ipu_plane, old_state); 454 ipu_plane_atomic_set_base(ipu_plane);
441 ipu_plane_enable(ipu_plane); 455 ipu_plane_enable(ipu_plane);
442} 456}
443 457
diff --git a/drivers/gpu/drm/mediatek/mtk_disp_ovl.c b/drivers/gpu/drm/mediatek/mtk_disp_ovl.c
index 019b7ca392d7..c70310206ac5 100644
--- a/drivers/gpu/drm/mediatek/mtk_disp_ovl.c
+++ b/drivers/gpu/drm/mediatek/mtk_disp_ovl.c
@@ -80,6 +80,7 @@ static void mtk_ovl_enable_vblank(struct mtk_ddp_comp *comp,
80 ddp_comp); 80 ddp_comp);
81 81
82 priv->crtc = crtc; 82 priv->crtc = crtc;
83 writel(0x0, comp->regs + DISP_REG_OVL_INTSTA);
83 writel_relaxed(OVL_FME_CPL_INT, comp->regs + DISP_REG_OVL_INTEN); 84 writel_relaxed(OVL_FME_CPL_INT, comp->regs + DISP_REG_OVL_INTEN);
84} 85}
85 86
@@ -250,13 +251,6 @@ static int mtk_disp_ovl_probe(struct platform_device *pdev)
250 if (irq < 0) 251 if (irq < 0)
251 return irq; 252 return irq;
252 253
253 ret = devm_request_irq(dev, irq, mtk_disp_ovl_irq_handler,
254 IRQF_TRIGGER_NONE, dev_name(dev), priv);
255 if (ret < 0) {
256 dev_err(dev, "Failed to request irq %d: %d\n", irq, ret);
257 return ret;
258 }
259
260 comp_id = mtk_ddp_comp_get_id(dev->of_node, MTK_DISP_OVL); 254 comp_id = mtk_ddp_comp_get_id(dev->of_node, MTK_DISP_OVL);
261 if (comp_id < 0) { 255 if (comp_id < 0) {
262 dev_err(dev, "Failed to identify by alias: %d\n", comp_id); 256 dev_err(dev, "Failed to identify by alias: %d\n", comp_id);
@@ -272,6 +266,13 @@ static int mtk_disp_ovl_probe(struct platform_device *pdev)
272 266
273 platform_set_drvdata(pdev, priv); 267 platform_set_drvdata(pdev, priv);
274 268
269 ret = devm_request_irq(dev, irq, mtk_disp_ovl_irq_handler,
270 IRQF_TRIGGER_NONE, dev_name(dev), priv);
271 if (ret < 0) {
272 dev_err(dev, "Failed to request irq %d: %d\n", irq, ret);
273 return ret;
274 }
275
275 ret = component_add(dev, &mtk_disp_ovl_component_ops); 276 ret = component_add(dev, &mtk_disp_ovl_component_ops);
276 if (ret) 277 if (ret)
277 dev_err(dev, "Failed to add component: %d\n", ret); 278 dev_err(dev, "Failed to add component: %d\n", ret);
diff --git a/drivers/gpu/drm/mediatek/mtk_dpi.c b/drivers/gpu/drm/mediatek/mtk_dpi.c
index 0186e500d2a5..90fb831ef031 100644
--- a/drivers/gpu/drm/mediatek/mtk_dpi.c
+++ b/drivers/gpu/drm/mediatek/mtk_dpi.c
@@ -432,11 +432,16 @@ static int mtk_dpi_set_display_mode(struct mtk_dpi *dpi,
432 unsigned long pll_rate; 432 unsigned long pll_rate;
433 unsigned int factor; 433 unsigned int factor;
434 434
435 /* let pll_rate can fix the valid range of tvdpll (1G~2GHz) */
435 pix_rate = 1000UL * mode->clock; 436 pix_rate = 1000UL * mode->clock;
436 if (mode->clock <= 74000) 437 if (mode->clock <= 27000)
438 factor = 16 * 3;
439 else if (mode->clock <= 84000)
437 factor = 8 * 3; 440 factor = 8 * 3;
438 else 441 else if (mode->clock <= 167000)
439 factor = 4 * 3; 442 factor = 4 * 3;
443 else
444 factor = 2 * 3;
440 pll_rate = pix_rate * factor; 445 pll_rate = pix_rate * factor;
441 446
442 dev_dbg(dpi->dev, "Want PLL %lu Hz, pixel clock %lu Hz\n", 447 dev_dbg(dpi->dev, "Want PLL %lu Hz, pixel clock %lu Hz\n",
diff --git a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
index df33b3ca6ffd..48cc01fd20c7 100644
--- a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
+++ b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
@@ -123,7 +123,7 @@ static void mtk_od_config(struct mtk_ddp_comp *comp, unsigned int w,
123 unsigned int bpc) 123 unsigned int bpc)
124{ 124{
125 writel(w << 16 | h, comp->regs + DISP_OD_SIZE); 125 writel(w << 16 | h, comp->regs + DISP_OD_SIZE);
126 writel(OD_RELAYMODE, comp->regs + OD_RELAYMODE); 126 writel(OD_RELAYMODE, comp->regs + DISP_OD_CFG);
127 mtk_dither_set(comp, bpc, DISP_OD_CFG); 127 mtk_dither_set(comp, bpc, DISP_OD_CFG);
128} 128}
129 129
diff --git a/drivers/gpu/drm/mediatek/mtk_dsi.c b/drivers/gpu/drm/mediatek/mtk_dsi.c
index 28b2044ed9f2..eaa5a2240c0c 100644
--- a/drivers/gpu/drm/mediatek/mtk_dsi.c
+++ b/drivers/gpu/drm/mediatek/mtk_dsi.c
@@ -86,7 +86,7 @@
86 86
87#define DSI_PHY_TIMECON0 0x110 87#define DSI_PHY_TIMECON0 0x110
88#define LPX (0xff << 0) 88#define LPX (0xff << 0)
89#define HS_PRPR (0xff << 8) 89#define HS_PREP (0xff << 8)
90#define HS_ZERO (0xff << 16) 90#define HS_ZERO (0xff << 16)
91#define HS_TRAIL (0xff << 24) 91#define HS_TRAIL (0xff << 24)
92 92
@@ -102,10 +102,16 @@
102#define CLK_TRAIL (0xff << 24) 102#define CLK_TRAIL (0xff << 24)
103 103
104#define DSI_PHY_TIMECON3 0x11c 104#define DSI_PHY_TIMECON3 0x11c
105#define CLK_HS_PRPR (0xff << 0) 105#define CLK_HS_PREP (0xff << 0)
106#define CLK_HS_POST (0xff << 8) 106#define CLK_HS_POST (0xff << 8)
107#define CLK_HS_EXIT (0xff << 16) 107#define CLK_HS_EXIT (0xff << 16)
108 108
109#define T_LPX 5
110#define T_HS_PREP 6
111#define T_HS_TRAIL 8
112#define T_HS_EXIT 7
113#define T_HS_ZERO 10
114
109#define NS_TO_CYCLE(n, c) ((n) / (c) + (((n) % (c)) ? 1 : 0)) 115#define NS_TO_CYCLE(n, c) ((n) / (c) + (((n) % (c)) ? 1 : 0))
110 116
111struct phy; 117struct phy;
@@ -161,20 +167,18 @@ static void mtk_dsi_mask(struct mtk_dsi *dsi, u32 offset, u32 mask, u32 data)
161static void dsi_phy_timconfig(struct mtk_dsi *dsi) 167static void dsi_phy_timconfig(struct mtk_dsi *dsi)
162{ 168{
163 u32 timcon0, timcon1, timcon2, timcon3; 169 u32 timcon0, timcon1, timcon2, timcon3;
164 unsigned int ui, cycle_time; 170 u32 ui, cycle_time;
165 unsigned int lpx;
166 171
167 ui = 1000 / dsi->data_rate + 0x01; 172 ui = 1000 / dsi->data_rate + 0x01;
168 cycle_time = 8000 / dsi->data_rate + 0x01; 173 cycle_time = 8000 / dsi->data_rate + 0x01;
169 lpx = 5;
170 174
171 timcon0 = (8 << 24) | (0xa << 16) | (0x6 << 8) | lpx; 175 timcon0 = T_LPX | T_HS_PREP << 8 | T_HS_ZERO << 16 | T_HS_TRAIL << 24;
172 timcon1 = (7 << 24) | (5 * lpx << 16) | ((3 * lpx) / 2) << 8 | 176 timcon1 = 4 * T_LPX | (3 * T_LPX / 2) << 8 | 5 * T_LPX << 16 |
173 (4 * lpx); 177 T_HS_EXIT << 24;
174 timcon2 = ((NS_TO_CYCLE(0x64, cycle_time) + 0xa) << 24) | 178 timcon2 = ((NS_TO_CYCLE(0x64, cycle_time) + 0xa) << 24) |
175 (NS_TO_CYCLE(0x150, cycle_time) << 16); 179 (NS_TO_CYCLE(0x150, cycle_time) << 16);
176 timcon3 = (2 * lpx) << 16 | NS_TO_CYCLE(80 + 52 * ui, cycle_time) << 8 | 180 timcon3 = NS_TO_CYCLE(0x40, cycle_time) | (2 * T_LPX) << 16 |
177 NS_TO_CYCLE(0x40, cycle_time); 181 NS_TO_CYCLE(80 + 52 * ui, cycle_time) << 8;
178 182
179 writel(timcon0, dsi->regs + DSI_PHY_TIMECON0); 183 writel(timcon0, dsi->regs + DSI_PHY_TIMECON0);
180 writel(timcon1, dsi->regs + DSI_PHY_TIMECON1); 184 writel(timcon1, dsi->regs + DSI_PHY_TIMECON1);
@@ -202,19 +206,47 @@ static int mtk_dsi_poweron(struct mtk_dsi *dsi)
202{ 206{
203 struct device *dev = dsi->dev; 207 struct device *dev = dsi->dev;
204 int ret; 208 int ret;
209 u64 pixel_clock, total_bits;
210 u32 htotal, htotal_bits, bit_per_pixel, overhead_cycles, overhead_bits;
205 211
206 if (++dsi->refcount != 1) 212 if (++dsi->refcount != 1)
207 return 0; 213 return 0;
208 214
215 switch (dsi->format) {
216 case MIPI_DSI_FMT_RGB565:
217 bit_per_pixel = 16;
218 break;
219 case MIPI_DSI_FMT_RGB666_PACKED:
220 bit_per_pixel = 18;
221 break;
222 case MIPI_DSI_FMT_RGB666:
223 case MIPI_DSI_FMT_RGB888:
224 default:
225 bit_per_pixel = 24;
226 break;
227 }
228
209 /** 229 /**
210 * data_rate = (pixel_clock / 1000) * pixel_dipth * mipi_ratio; 230 * vm.pixelclock is in kHz, pixel_clock unit is Hz, so multiply by 1000
211 * pixel_clock unit is Khz, data_rata unit is MHz, so need divide 1000. 231 * htotal_time = htotal * byte_per_pixel / num_lanes
212 * mipi_ratio is mipi clk coefficient for balance the pixel clk in mipi. 232 * overhead_time = lpx + hs_prepare + hs_zero + hs_trail + hs_exit
213 * we set mipi_ratio is 1.05. 233 * mipi_ratio = (htotal_time + overhead_time) / htotal_time
234 * data_rate = pixel_clock * bit_per_pixel * mipi_ratio / num_lanes;
214 */ 235 */
215 dsi->data_rate = dsi->vm.pixelclock * 3 * 21 / (1 * 1000 * 10); 236 pixel_clock = dsi->vm.pixelclock * 1000;
237 htotal = dsi->vm.hactive + dsi->vm.hback_porch + dsi->vm.hfront_porch +
238 dsi->vm.hsync_len;
239 htotal_bits = htotal * bit_per_pixel;
240
241 overhead_cycles = T_LPX + T_HS_PREP + T_HS_ZERO + T_HS_TRAIL +
242 T_HS_EXIT;
243 overhead_bits = overhead_cycles * dsi->lanes * 8;
244 total_bits = htotal_bits + overhead_bits;
245
246 dsi->data_rate = DIV_ROUND_UP_ULL(pixel_clock * total_bits,
247 htotal * dsi->lanes);
216 248
217 ret = clk_set_rate(dsi->hs_clk, dsi->data_rate * 1000000); 249 ret = clk_set_rate(dsi->hs_clk, dsi->data_rate);
218 if (ret < 0) { 250 if (ret < 0) {
219 dev_err(dev, "Failed to set data rate: %d\n", ret); 251 dev_err(dev, "Failed to set data rate: %d\n", ret);
220 goto err_refcount; 252 goto err_refcount;
diff --git a/drivers/gpu/drm/mediatek/mtk_hdmi.c b/drivers/gpu/drm/mediatek/mtk_hdmi.c
index 71227deef21b..0e8c4d9af340 100644
--- a/drivers/gpu/drm/mediatek/mtk_hdmi.c
+++ b/drivers/gpu/drm/mediatek/mtk_hdmi.c
@@ -1133,12 +1133,6 @@ static int mtk_hdmi_output_set_display_mode(struct mtk_hdmi *hdmi,
1133 phy_power_on(hdmi->phy); 1133 phy_power_on(hdmi->phy);
1134 mtk_hdmi_aud_output_config(hdmi, mode); 1134 mtk_hdmi_aud_output_config(hdmi, mode);
1135 1135
1136 mtk_hdmi_setup_audio_infoframe(hdmi);
1137 mtk_hdmi_setup_avi_infoframe(hdmi, mode);
1138 mtk_hdmi_setup_spd_infoframe(hdmi, "mediatek", "On-chip HDMI");
1139 if (mode->flags & DRM_MODE_FLAG_3D_MASK)
1140 mtk_hdmi_setup_vendor_specific_infoframe(hdmi, mode);
1141
1142 mtk_hdmi_hw_vid_black(hdmi, false); 1136 mtk_hdmi_hw_vid_black(hdmi, false);
1143 mtk_hdmi_hw_aud_unmute(hdmi); 1137 mtk_hdmi_hw_aud_unmute(hdmi);
1144 mtk_hdmi_hw_send_av_unmute(hdmi); 1138 mtk_hdmi_hw_send_av_unmute(hdmi);
@@ -1401,6 +1395,16 @@ static void mtk_hdmi_bridge_pre_enable(struct drm_bridge *bridge)
1401 hdmi->powered = true; 1395 hdmi->powered = true;
1402} 1396}
1403 1397
1398static void mtk_hdmi_send_infoframe(struct mtk_hdmi *hdmi,
1399 struct drm_display_mode *mode)
1400{
1401 mtk_hdmi_setup_audio_infoframe(hdmi);
1402 mtk_hdmi_setup_avi_infoframe(hdmi, mode);
1403 mtk_hdmi_setup_spd_infoframe(hdmi, "mediatek", "On-chip HDMI");
1404 if (mode->flags & DRM_MODE_FLAG_3D_MASK)
1405 mtk_hdmi_setup_vendor_specific_infoframe(hdmi, mode);
1406}
1407
1404static void mtk_hdmi_bridge_enable(struct drm_bridge *bridge) 1408static void mtk_hdmi_bridge_enable(struct drm_bridge *bridge)
1405{ 1409{
1406 struct mtk_hdmi *hdmi = hdmi_ctx_from_bridge(bridge); 1410 struct mtk_hdmi *hdmi = hdmi_ctx_from_bridge(bridge);
@@ -1409,6 +1413,7 @@ static void mtk_hdmi_bridge_enable(struct drm_bridge *bridge)
1409 clk_prepare_enable(hdmi->clk[MTK_HDMI_CLK_HDMI_PLL]); 1413 clk_prepare_enable(hdmi->clk[MTK_HDMI_CLK_HDMI_PLL]);
1410 clk_prepare_enable(hdmi->clk[MTK_HDMI_CLK_HDMI_PIXEL]); 1414 clk_prepare_enable(hdmi->clk[MTK_HDMI_CLK_HDMI_PIXEL]);
1411 phy_power_on(hdmi->phy); 1415 phy_power_on(hdmi->phy);
1416 mtk_hdmi_send_infoframe(hdmi, &hdmi->mode);
1412 1417
1413 hdmi->enabled = true; 1418 hdmi->enabled = true;
1414} 1419}
diff --git a/drivers/gpu/drm/mediatek/mtk_mt8173_hdmi_phy.c b/drivers/gpu/drm/mediatek/mtk_mt8173_hdmi_phy.c
index 8a24754b440f..51cb9cfb6646 100644
--- a/drivers/gpu/drm/mediatek/mtk_mt8173_hdmi_phy.c
+++ b/drivers/gpu/drm/mediatek/mtk_mt8173_hdmi_phy.c
@@ -265,6 +265,9 @@ static int mtk_hdmi_pll_set_rate(struct clk_hw *hw, unsigned long rate,
265 struct mtk_hdmi_phy *hdmi_phy = to_mtk_hdmi_phy(hw); 265 struct mtk_hdmi_phy *hdmi_phy = to_mtk_hdmi_phy(hw);
266 unsigned int pre_div; 266 unsigned int pre_div;
267 unsigned int div; 267 unsigned int div;
268 unsigned int pre_ibias;
269 unsigned int hdmi_ibias;
270 unsigned int imp_en;
268 271
269 dev_dbg(hdmi_phy->dev, "%s: %lu Hz, parent: %lu Hz\n", __func__, 272 dev_dbg(hdmi_phy->dev, "%s: %lu Hz, parent: %lu Hz\n", __func__,
270 rate, parent_rate); 273 rate, parent_rate);
@@ -298,18 +301,31 @@ static int mtk_hdmi_pll_set_rate(struct clk_hw *hw, unsigned long rate,
298 (0x1 << PLL_BR_SHIFT), 301 (0x1 << PLL_BR_SHIFT),
299 RG_HDMITX_PLL_BP | RG_HDMITX_PLL_BC | 302 RG_HDMITX_PLL_BP | RG_HDMITX_PLL_BC |
300 RG_HDMITX_PLL_BR); 303 RG_HDMITX_PLL_BR);
301 mtk_hdmi_phy_clear_bits(hdmi_phy, HDMI_CON3, RG_HDMITX_PRD_IMP_EN); 304 if (rate < 165000000) {
305 mtk_hdmi_phy_clear_bits(hdmi_phy, HDMI_CON3,
306 RG_HDMITX_PRD_IMP_EN);
307 pre_ibias = 0x3;
308 imp_en = 0x0;
309 hdmi_ibias = hdmi_phy->ibias;
310 } else {
311 mtk_hdmi_phy_set_bits(hdmi_phy, HDMI_CON3,
312 RG_HDMITX_PRD_IMP_EN);
313 pre_ibias = 0x6;
314 imp_en = 0xf;
315 hdmi_ibias = hdmi_phy->ibias_up;
316 }
302 mtk_hdmi_phy_mask(hdmi_phy, HDMI_CON4, 317 mtk_hdmi_phy_mask(hdmi_phy, HDMI_CON4,
303 (0x3 << PRD_IBIAS_CLK_SHIFT) | 318 (pre_ibias << PRD_IBIAS_CLK_SHIFT) |
304 (0x3 << PRD_IBIAS_D2_SHIFT) | 319 (pre_ibias << PRD_IBIAS_D2_SHIFT) |
305 (0x3 << PRD_IBIAS_D1_SHIFT) | 320 (pre_ibias << PRD_IBIAS_D1_SHIFT) |
306 (0x3 << PRD_IBIAS_D0_SHIFT), 321 (pre_ibias << PRD_IBIAS_D0_SHIFT),
307 RG_HDMITX_PRD_IBIAS_CLK | 322 RG_HDMITX_PRD_IBIAS_CLK |
308 RG_HDMITX_PRD_IBIAS_D2 | 323 RG_HDMITX_PRD_IBIAS_D2 |
309 RG_HDMITX_PRD_IBIAS_D1 | 324 RG_HDMITX_PRD_IBIAS_D1 |
310 RG_HDMITX_PRD_IBIAS_D0); 325 RG_HDMITX_PRD_IBIAS_D0);
311 mtk_hdmi_phy_mask(hdmi_phy, HDMI_CON3, 326 mtk_hdmi_phy_mask(hdmi_phy, HDMI_CON3,
312 (0x0 << DRV_IMP_EN_SHIFT), RG_HDMITX_DRV_IMP_EN); 327 (imp_en << DRV_IMP_EN_SHIFT),
328 RG_HDMITX_DRV_IMP_EN);
313 mtk_hdmi_phy_mask(hdmi_phy, HDMI_CON6, 329 mtk_hdmi_phy_mask(hdmi_phy, HDMI_CON6,
314 (hdmi_phy->drv_imp_clk << DRV_IMP_CLK_SHIFT) | 330 (hdmi_phy->drv_imp_clk << DRV_IMP_CLK_SHIFT) |
315 (hdmi_phy->drv_imp_d2 << DRV_IMP_D2_SHIFT) | 331 (hdmi_phy->drv_imp_d2 << DRV_IMP_D2_SHIFT) |
@@ -318,12 +334,14 @@ static int mtk_hdmi_pll_set_rate(struct clk_hw *hw, unsigned long rate,
318 RG_HDMITX_DRV_IMP_CLK | RG_HDMITX_DRV_IMP_D2 | 334 RG_HDMITX_DRV_IMP_CLK | RG_HDMITX_DRV_IMP_D2 |
319 RG_HDMITX_DRV_IMP_D1 | RG_HDMITX_DRV_IMP_D0); 335 RG_HDMITX_DRV_IMP_D1 | RG_HDMITX_DRV_IMP_D0);
320 mtk_hdmi_phy_mask(hdmi_phy, HDMI_CON5, 336 mtk_hdmi_phy_mask(hdmi_phy, HDMI_CON5,
321 (hdmi_phy->ibias << DRV_IBIAS_CLK_SHIFT) | 337 (hdmi_ibias << DRV_IBIAS_CLK_SHIFT) |
322 (hdmi_phy->ibias << DRV_IBIAS_D2_SHIFT) | 338 (hdmi_ibias << DRV_IBIAS_D2_SHIFT) |
323 (hdmi_phy->ibias << DRV_IBIAS_D1_SHIFT) | 339 (hdmi_ibias << DRV_IBIAS_D1_SHIFT) |
324 (hdmi_phy->ibias << DRV_IBIAS_D0_SHIFT), 340 (hdmi_ibias << DRV_IBIAS_D0_SHIFT),
325 RG_HDMITX_DRV_IBIAS_CLK | RG_HDMITX_DRV_IBIAS_D2 | 341 RG_HDMITX_DRV_IBIAS_CLK |
326 RG_HDMITX_DRV_IBIAS_D1 | RG_HDMITX_DRV_IBIAS_D0); 342 RG_HDMITX_DRV_IBIAS_D2 |
343 RG_HDMITX_DRV_IBIAS_D1 |
344 RG_HDMITX_DRV_IBIAS_D0);
327 return 0; 345 return 0;
328} 346}
329 347
diff --git a/drivers/gpu/drm/mgag200/mgag200_ttm.c b/drivers/gpu/drm/mgag200/mgag200_ttm.c
index 919b35f2ad24..dcf7d11ac380 100644
--- a/drivers/gpu/drm/mgag200/mgag200_ttm.c
+++ b/drivers/gpu/drm/mgag200/mgag200_ttm.c
@@ -266,6 +266,9 @@ int mgag200_mm_init(struct mga_device *mdev)
266 return ret; 266 return ret;
267 } 267 }
268 268
269 arch_io_reserve_memtype_wc(pci_resource_start(dev->pdev, 0),
270 pci_resource_len(dev->pdev, 0));
271
269 mdev->fb_mtrr = arch_phys_wc_add(pci_resource_start(dev->pdev, 0), 272 mdev->fb_mtrr = arch_phys_wc_add(pci_resource_start(dev->pdev, 0),
270 pci_resource_len(dev->pdev, 0)); 273 pci_resource_len(dev->pdev, 0));
271 274
@@ -274,10 +277,14 @@ int mgag200_mm_init(struct mga_device *mdev)
274 277
275void mgag200_mm_fini(struct mga_device *mdev) 278void mgag200_mm_fini(struct mga_device *mdev)
276{ 279{
280 struct drm_device *dev = mdev->dev;
281
277 ttm_bo_device_release(&mdev->ttm.bdev); 282 ttm_bo_device_release(&mdev->ttm.bdev);
278 283
279 mgag200_ttm_global_release(mdev); 284 mgag200_ttm_global_release(mdev);
280 285
286 arch_io_free_memtype_wc(pci_resource_start(dev->pdev, 0),
287 pci_resource_len(dev->pdev, 0));
281 arch_phys_wc_del(mdev->fb_mtrr); 288 arch_phys_wc_del(mdev->fb_mtrr);
282 mdev->fb_mtrr = 0; 289 mdev->fb_mtrr = 0;
283} 290}
diff --git a/drivers/gpu/drm/msm/dsi/dsi_host.c b/drivers/gpu/drm/msm/dsi/dsi_host.c
index f05ed0e1f3d6..6f240021705b 100644
--- a/drivers/gpu/drm/msm/dsi/dsi_host.c
+++ b/drivers/gpu/drm/msm/dsi/dsi_host.c
@@ -139,6 +139,7 @@ struct msm_dsi_host {
139 139
140 u32 err_work_state; 140 u32 err_work_state;
141 struct work_struct err_work; 141 struct work_struct err_work;
142 struct work_struct hpd_work;
142 struct workqueue_struct *workqueue; 143 struct workqueue_struct *workqueue;
143 144
144 /* DSI 6G TX buffer*/ 145 /* DSI 6G TX buffer*/
@@ -1294,6 +1295,14 @@ static void dsi_sw_reset_restore(struct msm_dsi_host *msm_host)
1294 wmb(); /* make sure dsi controller enabled again */ 1295 wmb(); /* make sure dsi controller enabled again */
1295} 1296}
1296 1297
1298static void dsi_hpd_worker(struct work_struct *work)
1299{
1300 struct msm_dsi_host *msm_host =
1301 container_of(work, struct msm_dsi_host, hpd_work);
1302
1303 drm_helper_hpd_irq_event(msm_host->dev);
1304}
1305
1297static void dsi_err_worker(struct work_struct *work) 1306static void dsi_err_worker(struct work_struct *work)
1298{ 1307{
1299 struct msm_dsi_host *msm_host = 1308 struct msm_dsi_host *msm_host =
@@ -1480,7 +1489,7 @@ static int dsi_host_attach(struct mipi_dsi_host *host,
1480 1489
1481 DBG("id=%d", msm_host->id); 1490 DBG("id=%d", msm_host->id);
1482 if (msm_host->dev) 1491 if (msm_host->dev)
1483 drm_helper_hpd_irq_event(msm_host->dev); 1492 queue_work(msm_host->workqueue, &msm_host->hpd_work);
1484 1493
1485 return 0; 1494 return 0;
1486} 1495}
@@ -1494,7 +1503,7 @@ static int dsi_host_detach(struct mipi_dsi_host *host,
1494 1503
1495 DBG("id=%d", msm_host->id); 1504 DBG("id=%d", msm_host->id);
1496 if (msm_host->dev) 1505 if (msm_host->dev)
1497 drm_helper_hpd_irq_event(msm_host->dev); 1506 queue_work(msm_host->workqueue, &msm_host->hpd_work);
1498 1507
1499 return 0; 1508 return 0;
1500} 1509}
@@ -1748,6 +1757,7 @@ int msm_dsi_host_init(struct msm_dsi *msm_dsi)
1748 /* setup workqueue */ 1757 /* setup workqueue */
1749 msm_host->workqueue = alloc_ordered_workqueue("dsi_drm_work", 0); 1758 msm_host->workqueue = alloc_ordered_workqueue("dsi_drm_work", 0);
1750 INIT_WORK(&msm_host->err_work, dsi_err_worker); 1759 INIT_WORK(&msm_host->err_work, dsi_err_worker);
1760 INIT_WORK(&msm_host->hpd_work, dsi_hpd_worker);
1751 1761
1752 msm_dsi->host = &msm_host->base; 1762 msm_dsi->host = &msm_host->base;
1753 msm_dsi->id = msm_host->id; 1763 msm_dsi->id = msm_host->id;
diff --git a/drivers/gpu/drm/msm/dsi/pll/dsi_pll_28nm.c b/drivers/gpu/drm/msm/dsi/pll/dsi_pll_28nm.c
index 598fdaff0a41..26e3a01a99c2 100644
--- a/drivers/gpu/drm/msm/dsi/pll/dsi_pll_28nm.c
+++ b/drivers/gpu/drm/msm/dsi/pll/dsi_pll_28nm.c
@@ -521,6 +521,7 @@ static int pll_28nm_register(struct dsi_pll_28nm *pll_28nm)
521 .parent_names = (const char *[]){ "xo" }, 521 .parent_names = (const char *[]){ "xo" },
522 .num_parents = 1, 522 .num_parents = 1,
523 .name = vco_name, 523 .name = vco_name,
524 .flags = CLK_IGNORE_UNUSED,
524 .ops = &clk_ops_dsi_pll_28nm_vco, 525 .ops = &clk_ops_dsi_pll_28nm_vco,
525 }; 526 };
526 struct device *dev = &pll_28nm->pdev->dev; 527 struct device *dev = &pll_28nm->pdev->dev;
diff --git a/drivers/gpu/drm/msm/dsi/pll/dsi_pll_28nm_8960.c b/drivers/gpu/drm/msm/dsi/pll/dsi_pll_28nm_8960.c
index 38c90e1eb002..49008451085b 100644
--- a/drivers/gpu/drm/msm/dsi/pll/dsi_pll_28nm_8960.c
+++ b/drivers/gpu/drm/msm/dsi/pll/dsi_pll_28nm_8960.c
@@ -412,6 +412,7 @@ static int pll_28nm_register(struct dsi_pll_28nm *pll_28nm)
412 struct clk_init_data vco_init = { 412 struct clk_init_data vco_init = {
413 .parent_names = (const char *[]){ "pxo" }, 413 .parent_names = (const char *[]){ "pxo" },
414 .num_parents = 1, 414 .num_parents = 1,
415 .flags = CLK_IGNORE_UNUSED,
415 .ops = &clk_ops_dsi_pll_28nm_vco, 416 .ops = &clk_ops_dsi_pll_28nm_vco,
416 }; 417 };
417 struct device *dev = &pll_28nm->pdev->dev; 418 struct device *dev = &pll_28nm->pdev->dev;
diff --git a/drivers/gpu/drm/msm/hdmi/hdmi_phy_8996.c b/drivers/gpu/drm/msm/hdmi/hdmi_phy_8996.c
index aa94a553794f..143eab46ba68 100644
--- a/drivers/gpu/drm/msm/hdmi/hdmi_phy_8996.c
+++ b/drivers/gpu/drm/msm/hdmi/hdmi_phy_8996.c
@@ -702,6 +702,7 @@ static struct clk_init_data pll_init = {
702 .ops = &hdmi_8996_pll_ops, 702 .ops = &hdmi_8996_pll_ops,
703 .parent_names = hdmi_pll_parents, 703 .parent_names = hdmi_pll_parents,
704 .num_parents = ARRAY_SIZE(hdmi_pll_parents), 704 .num_parents = ARRAY_SIZE(hdmi_pll_parents),
705 .flags = CLK_IGNORE_UNUSED,
705}; 706};
706 707
707int msm_hdmi_pll_8996_init(struct platform_device *pdev) 708int msm_hdmi_pll_8996_init(struct platform_device *pdev)
diff --git a/drivers/gpu/drm/msm/hdmi/hdmi_pll_8960.c b/drivers/gpu/drm/msm/hdmi/hdmi_pll_8960.c
index 92da69aa6187..99590758c68b 100644
--- a/drivers/gpu/drm/msm/hdmi/hdmi_pll_8960.c
+++ b/drivers/gpu/drm/msm/hdmi/hdmi_pll_8960.c
@@ -424,6 +424,7 @@ static struct clk_init_data pll_init = {
424 .ops = &hdmi_pll_ops, 424 .ops = &hdmi_pll_ops,
425 .parent_names = hdmi_pll_parents, 425 .parent_names = hdmi_pll_parents,
426 .num_parents = ARRAY_SIZE(hdmi_pll_parents), 426 .num_parents = ARRAY_SIZE(hdmi_pll_parents),
427 .flags = CLK_IGNORE_UNUSED,
427}; 428};
428 429
429int msm_hdmi_pll_8960_init(struct platform_device *pdev) 430int msm_hdmi_pll_8960_init(struct platform_device *pdev)
diff --git a/drivers/gpu/drm/msm/mdp/mdp5/mdp5_cfg.c b/drivers/gpu/drm/msm/mdp/mdp5/mdp5_cfg.c
index ac9e4cde1380..8b4e3004f451 100644
--- a/drivers/gpu/drm/msm/mdp/mdp5/mdp5_cfg.c
+++ b/drivers/gpu/drm/msm/mdp/mdp5/mdp5_cfg.c
@@ -272,7 +272,7 @@ const struct mdp5_cfg_hw msm8x16_config = {
272 .count = 2, 272 .count = 2,
273 .base = { 0x14000, 0x16000 }, 273 .base = { 0x14000, 0x16000 },
274 .caps = MDP_PIPE_CAP_HFLIP | MDP_PIPE_CAP_VFLIP | 274 .caps = MDP_PIPE_CAP_HFLIP | MDP_PIPE_CAP_VFLIP |
275 MDP_PIPE_CAP_SCALE | MDP_PIPE_CAP_DECIMATION, 275 MDP_PIPE_CAP_DECIMATION,
276 }, 276 },
277 .pipe_dma = { 277 .pipe_dma = {
278 .count = 1, 278 .count = 1,
@@ -282,7 +282,7 @@ const struct mdp5_cfg_hw msm8x16_config = {
282 .lm = { 282 .lm = {
283 .count = 2, /* LM0 and LM3 */ 283 .count = 2, /* LM0 and LM3 */
284 .base = { 0x44000, 0x47000 }, 284 .base = { 0x44000, 0x47000 },
285 .nb_stages = 5, 285 .nb_stages = 8,
286 .max_width = 2048, 286 .max_width = 2048,
287 .max_height = 0xFFFF, 287 .max_height = 0xFFFF,
288 }, 288 },
diff --git a/drivers/gpu/drm/msm/mdp/mdp5/mdp5_crtc.c b/drivers/gpu/drm/msm/mdp/mdp5/mdp5_crtc.c
index fa2be7ce9468..c205c360e16d 100644
--- a/drivers/gpu/drm/msm/mdp/mdp5/mdp5_crtc.c
+++ b/drivers/gpu/drm/msm/mdp/mdp5/mdp5_crtc.c
@@ -223,12 +223,7 @@ static void blend_setup(struct drm_crtc *crtc)
223 plane_cnt++; 223 plane_cnt++;
224 } 224 }
225 225
226 /* 226 if (!pstates[STAGE_BASE]) {
227 * If there is no base layer, enable border color.
228 * Although it's not possbile in current blend logic,
229 * put it here as a reminder.
230 */
231 if (!pstates[STAGE_BASE] && plane_cnt) {
232 ctl_blend_flags |= MDP5_CTL_BLEND_OP_FLAG_BORDER_OUT; 227 ctl_blend_flags |= MDP5_CTL_BLEND_OP_FLAG_BORDER_OUT;
233 DBG("Border Color is enabled"); 228 DBG("Border Color is enabled");
234 } 229 }
@@ -365,6 +360,15 @@ static int pstate_cmp(const void *a, const void *b)
365 return pa->state->zpos - pb->state->zpos; 360 return pa->state->zpos - pb->state->zpos;
366} 361}
367 362
363/* is there a helper for this? */
364static bool is_fullscreen(struct drm_crtc_state *cstate,
365 struct drm_plane_state *pstate)
366{
367 return (pstate->crtc_x <= 0) && (pstate->crtc_y <= 0) &&
368 ((pstate->crtc_x + pstate->crtc_w) >= cstate->mode.hdisplay) &&
369 ((pstate->crtc_y + pstate->crtc_h) >= cstate->mode.vdisplay);
370}
371
368static int mdp5_crtc_atomic_check(struct drm_crtc *crtc, 372static int mdp5_crtc_atomic_check(struct drm_crtc *crtc,
369 struct drm_crtc_state *state) 373 struct drm_crtc_state *state)
370{ 374{
@@ -375,21 +379,11 @@ static int mdp5_crtc_atomic_check(struct drm_crtc *crtc,
375 struct plane_state pstates[STAGE_MAX + 1]; 379 struct plane_state pstates[STAGE_MAX + 1];
376 const struct mdp5_cfg_hw *hw_cfg; 380 const struct mdp5_cfg_hw *hw_cfg;
377 const struct drm_plane_state *pstate; 381 const struct drm_plane_state *pstate;
378 int cnt = 0, i; 382 int cnt = 0, base = 0, i;
379 383
380 DBG("%s: check", mdp5_crtc->name); 384 DBG("%s: check", mdp5_crtc->name);
381 385
382 /* verify that there are not too many planes attached to crtc
383 * and that we don't have conflicting mixer stages:
384 */
385 hw_cfg = mdp5_cfg_get_hw_config(mdp5_kms->cfg);
386 drm_atomic_crtc_state_for_each_plane_state(plane, pstate, state) { 386 drm_atomic_crtc_state_for_each_plane_state(plane, pstate, state) {
387 if (cnt >= (hw_cfg->lm.nb_stages)) {
388 dev_err(dev->dev, "too many planes!\n");
389 return -EINVAL;
390 }
391
392
393 pstates[cnt].plane = plane; 387 pstates[cnt].plane = plane;
394 pstates[cnt].state = to_mdp5_plane_state(pstate); 388 pstates[cnt].state = to_mdp5_plane_state(pstate);
395 389
@@ -399,8 +393,24 @@ static int mdp5_crtc_atomic_check(struct drm_crtc *crtc,
399 /* assign a stage based on sorted zpos property */ 393 /* assign a stage based on sorted zpos property */
400 sort(pstates, cnt, sizeof(pstates[0]), pstate_cmp, NULL); 394 sort(pstates, cnt, sizeof(pstates[0]), pstate_cmp, NULL);
401 395
396 /* if the bottom-most layer is not fullscreen, we need to use
397 * it for solid-color:
398 */
399 if ((cnt > 0) && !is_fullscreen(state, &pstates[0].state->base))
400 base++;
401
402 /* verify that there are not too many planes attached to crtc
403 * and that we don't have conflicting mixer stages:
404 */
405 hw_cfg = mdp5_cfg_get_hw_config(mdp5_kms->cfg);
406
407 if ((cnt + base) >= hw_cfg->lm.nb_stages) {
408 dev_err(dev->dev, "too many planes!\n");
409 return -EINVAL;
410 }
411
402 for (i = 0; i < cnt; i++) { 412 for (i = 0; i < cnt; i++) {
403 pstates[i].state->stage = STAGE_BASE + i; 413 pstates[i].state->stage = STAGE_BASE + i + base;
404 DBG("%s: assign pipe %s on stage=%d", mdp5_crtc->name, 414 DBG("%s: assign pipe %s on stage=%d", mdp5_crtc->name,
405 pipe2name(mdp5_plane_pipe(pstates[i].plane)), 415 pipe2name(mdp5_plane_pipe(pstates[i].plane)),
406 pstates[i].state->stage); 416 pstates[i].state->stage);
diff --git a/drivers/gpu/drm/msm/mdp/mdp5/mdp5_plane.c b/drivers/gpu/drm/msm/mdp/mdp5/mdp5_plane.c
index 951c002b05df..83bf997dda03 100644
--- a/drivers/gpu/drm/msm/mdp/mdp5/mdp5_plane.c
+++ b/drivers/gpu/drm/msm/mdp/mdp5/mdp5_plane.c
@@ -292,8 +292,7 @@ static int mdp5_plane_atomic_check(struct drm_plane *plane,
292 format = to_mdp_format(msm_framebuffer_format(state->fb)); 292 format = to_mdp_format(msm_framebuffer_format(state->fb));
293 if (MDP_FORMAT_IS_YUV(format) && 293 if (MDP_FORMAT_IS_YUV(format) &&
294 !pipe_supports_yuv(mdp5_plane->caps)) { 294 !pipe_supports_yuv(mdp5_plane->caps)) {
295 dev_err(plane->dev->dev, 295 DBG("Pipe doesn't support YUV\n");
296 "Pipe doesn't support YUV\n");
297 296
298 return -EINVAL; 297 return -EINVAL;
299 } 298 }
@@ -301,8 +300,7 @@ static int mdp5_plane_atomic_check(struct drm_plane *plane,
301 if (!(mdp5_plane->caps & MDP_PIPE_CAP_SCALE) && 300 if (!(mdp5_plane->caps & MDP_PIPE_CAP_SCALE) &&
302 (((state->src_w >> 16) != state->crtc_w) || 301 (((state->src_w >> 16) != state->crtc_w) ||
303 ((state->src_h >> 16) != state->crtc_h))) { 302 ((state->src_h >> 16) != state->crtc_h))) {
304 dev_err(plane->dev->dev, 303 DBG("Pipe doesn't support scaling (%dx%d -> %dx%d)\n",
305 "Pipe doesn't support scaling (%dx%d -> %dx%d)\n",
306 state->src_w >> 16, state->src_h >> 16, 304 state->src_w >> 16, state->src_h >> 16,
307 state->crtc_w, state->crtc_h); 305 state->crtc_w, state->crtc_h);
308 306
@@ -313,8 +311,7 @@ static int mdp5_plane_atomic_check(struct drm_plane *plane,
313 vflip = !!(state->rotation & DRM_REFLECT_Y); 311 vflip = !!(state->rotation & DRM_REFLECT_Y);
314 if ((vflip && !(mdp5_plane->caps & MDP_PIPE_CAP_VFLIP)) || 312 if ((vflip && !(mdp5_plane->caps & MDP_PIPE_CAP_VFLIP)) ||
315 (hflip && !(mdp5_plane->caps & MDP_PIPE_CAP_HFLIP))) { 313 (hflip && !(mdp5_plane->caps & MDP_PIPE_CAP_HFLIP))) {
316 dev_err(plane->dev->dev, 314 DBG("Pipe doesn't support flip\n");
317 "Pipe doesn't support flip\n");
318 315
319 return -EINVAL; 316 return -EINVAL;
320 } 317 }
diff --git a/drivers/gpu/drm/msm/msm_drv.c b/drivers/gpu/drm/msm/msm_drv.c
index fb5c0b0a7594..46568fc80848 100644
--- a/drivers/gpu/drm/msm/msm_drv.c
+++ b/drivers/gpu/drm/msm/msm_drv.c
@@ -228,7 +228,7 @@ static int msm_drm_uninit(struct device *dev)
228 flush_workqueue(priv->atomic_wq); 228 flush_workqueue(priv->atomic_wq);
229 destroy_workqueue(priv->atomic_wq); 229 destroy_workqueue(priv->atomic_wq);
230 230
231 if (kms) 231 if (kms && kms->funcs)
232 kms->funcs->destroy(kms); 232 kms->funcs->destroy(kms);
233 233
234 if (gpu) { 234 if (gpu) {
diff --git a/drivers/gpu/drm/msm/msm_gem_shrinker.c b/drivers/gpu/drm/msm/msm_gem_shrinker.c
index 283d2841ba58..192b2d3a79cb 100644
--- a/drivers/gpu/drm/msm/msm_gem_shrinker.c
+++ b/drivers/gpu/drm/msm/msm_gem_shrinker.c
@@ -163,6 +163,9 @@ void msm_gem_shrinker_init(struct drm_device *dev)
163void msm_gem_shrinker_cleanup(struct drm_device *dev) 163void msm_gem_shrinker_cleanup(struct drm_device *dev)
164{ 164{
165 struct msm_drm_private *priv = dev->dev_private; 165 struct msm_drm_private *priv = dev->dev_private;
166 WARN_ON(unregister_vmap_purge_notifier(&priv->vmap_notifier)); 166
167 unregister_shrinker(&priv->shrinker); 167 if (priv->shrinker.nr_deferred) {
168 WARN_ON(unregister_vmap_purge_notifier(&priv->vmap_notifier));
169 unregister_shrinker(&priv->shrinker);
170 }
168} 171}
diff --git a/drivers/gpu/drm/nouveau/nouveau_acpi.c b/drivers/gpu/drm/nouveau/nouveau_acpi.c
index dc57b628e074..193573d191e5 100644
--- a/drivers/gpu/drm/nouveau/nouveau_acpi.c
+++ b/drivers/gpu/drm/nouveau/nouveau_acpi.c
@@ -240,7 +240,8 @@ static bool nouveau_pr3_present(struct pci_dev *pdev)
240 if (!parent_adev) 240 if (!parent_adev)
241 return false; 241 return false;
242 242
243 return acpi_has_method(parent_adev->handle, "_PR3"); 243 return parent_adev->power.flags.power_resources &&
244 acpi_has_method(parent_adev->handle, "_PR3");
244} 245}
245 246
246static void nouveau_dsm_pci_probe(struct pci_dev *pdev, acpi_handle *dhandle_out, 247static void nouveau_dsm_pci_probe(struct pci_dev *pdev, acpi_handle *dhandle_out,
diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
index 1825dbc33192..a6dbe8258040 100644
--- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
+++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
@@ -398,6 +398,9 @@ nouveau_ttm_init(struct nouveau_drm *drm)
398 /* VRAM init */ 398 /* VRAM init */
399 drm->gem.vram_available = drm->device.info.ram_user; 399 drm->gem.vram_available = drm->device.info.ram_user;
400 400
401 arch_io_reserve_memtype_wc(device->func->resource_addr(device, 1),
402 device->func->resource_size(device, 1));
403
401 ret = ttm_bo_init_mm(&drm->ttm.bdev, TTM_PL_VRAM, 404 ret = ttm_bo_init_mm(&drm->ttm.bdev, TTM_PL_VRAM,
402 drm->gem.vram_available >> PAGE_SHIFT); 405 drm->gem.vram_available >> PAGE_SHIFT);
403 if (ret) { 406 if (ret) {
@@ -430,6 +433,8 @@ nouveau_ttm_init(struct nouveau_drm *drm)
430void 433void
431nouveau_ttm_fini(struct nouveau_drm *drm) 434nouveau_ttm_fini(struct nouveau_drm *drm)
432{ 435{
436 struct nvkm_device *device = nvxx_device(&drm->device);
437
433 ttm_bo_clean_mm(&drm->ttm.bdev, TTM_PL_VRAM); 438 ttm_bo_clean_mm(&drm->ttm.bdev, TTM_PL_VRAM);
434 ttm_bo_clean_mm(&drm->ttm.bdev, TTM_PL_TT); 439 ttm_bo_clean_mm(&drm->ttm.bdev, TTM_PL_TT);
435 440
@@ -439,4 +444,7 @@ nouveau_ttm_fini(struct nouveau_drm *drm)
439 444
440 arch_phys_wc_del(drm->ttm.mtrr); 445 arch_phys_wc_del(drm->ttm.mtrr);
441 drm->ttm.mtrr = 0; 446 drm->ttm.mtrr = 0;
447 arch_io_free_memtype_wc(device->func->resource_addr(device, 1),
448 device->func->resource_size(device, 1));
449
442} 450}
diff --git a/drivers/gpu/drm/radeon/ni.c b/drivers/gpu/drm/radeon/ni.c
index 103fc8650197..a0d4a0522fdc 100644
--- a/drivers/gpu/drm/radeon/ni.c
+++ b/drivers/gpu/drm/radeon/ni.c
@@ -1396,9 +1396,7 @@ static void cayman_pcie_gart_fini(struct radeon_device *rdev)
1396void cayman_cp_int_cntl_setup(struct radeon_device *rdev, 1396void cayman_cp_int_cntl_setup(struct radeon_device *rdev,
1397 int ring, u32 cp_int_cntl) 1397 int ring, u32 cp_int_cntl)
1398{ 1398{
1399 u32 srbm_gfx_cntl = RREG32(SRBM_GFX_CNTL) & ~3; 1399 WREG32(SRBM_GFX_CNTL, RINGID(ring));
1400
1401 WREG32(SRBM_GFX_CNTL, srbm_gfx_cntl | (ring & 3));
1402 WREG32(CP_INT_CNTL, cp_int_cntl); 1400 WREG32(CP_INT_CNTL, cp_int_cntl);
1403} 1401}
1404 1402
diff --git a/drivers/gpu/drm/radeon/r600_dpm.c b/drivers/gpu/drm/radeon/r600_dpm.c
index 6a4b020dd0b4..5a26eb4545aa 100644
--- a/drivers/gpu/drm/radeon/r600_dpm.c
+++ b/drivers/gpu/drm/radeon/r600_dpm.c
@@ -156,19 +156,20 @@ u32 r600_dpm_get_vblank_time(struct radeon_device *rdev)
156 struct drm_device *dev = rdev->ddev; 156 struct drm_device *dev = rdev->ddev;
157 struct drm_crtc *crtc; 157 struct drm_crtc *crtc;
158 struct radeon_crtc *radeon_crtc; 158 struct radeon_crtc *radeon_crtc;
159 u32 line_time_us, vblank_lines; 159 u32 vblank_in_pixels;
160 u32 vblank_time_us = 0xffffffff; /* if the displays are off, vblank time is max */ 160 u32 vblank_time_us = 0xffffffff; /* if the displays are off, vblank time is max */
161 161
162 if (rdev->num_crtc && rdev->mode_info.mode_config_initialized) { 162 if (rdev->num_crtc && rdev->mode_info.mode_config_initialized) {
163 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { 163 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
164 radeon_crtc = to_radeon_crtc(crtc); 164 radeon_crtc = to_radeon_crtc(crtc);
165 if (crtc->enabled && radeon_crtc->enabled && radeon_crtc->hw_mode.clock) { 165 if (crtc->enabled && radeon_crtc->enabled && radeon_crtc->hw_mode.clock) {
166 line_time_us = (radeon_crtc->hw_mode.crtc_htotal * 1000) / 166 vblank_in_pixels =
167 radeon_crtc->hw_mode.clock; 167 radeon_crtc->hw_mode.crtc_htotal *
168 vblank_lines = radeon_crtc->hw_mode.crtc_vblank_end - 168 (radeon_crtc->hw_mode.crtc_vblank_end -
169 radeon_crtc->hw_mode.crtc_vdisplay + 169 radeon_crtc->hw_mode.crtc_vdisplay +
170 (radeon_crtc->v_border * 2); 170 (radeon_crtc->v_border * 2));
171 vblank_time_us = vblank_lines * line_time_us; 171
172 vblank_time_us = vblank_in_pixels * 1000 / radeon_crtc->hw_mode.clock;
172 break; 173 break;
173 } 174 }
174 } 175 }
diff --git a/drivers/gpu/drm/radeon/radeon_atpx_handler.c b/drivers/gpu/drm/radeon/radeon_atpx_handler.c
index 2fdcd04bc93f..0ae13cd2adda 100644
--- a/drivers/gpu/drm/radeon/radeon_atpx_handler.c
+++ b/drivers/gpu/drm/radeon/radeon_atpx_handler.c
@@ -34,6 +34,7 @@ struct radeon_atpx {
34 34
35static struct radeon_atpx_priv { 35static struct radeon_atpx_priv {
36 bool atpx_detected; 36 bool atpx_detected;
37 bool bridge_pm_usable;
37 /* handle for device - and atpx */ 38 /* handle for device - and atpx */
38 acpi_handle dhandle; 39 acpi_handle dhandle;
39 struct radeon_atpx atpx; 40 struct radeon_atpx atpx;
@@ -203,7 +204,11 @@ static int radeon_atpx_validate(struct radeon_atpx *atpx)
203 atpx->is_hybrid = false; 204 atpx->is_hybrid = false;
204 if (valid_bits & ATPX_MS_HYBRID_GFX_SUPPORTED) { 205 if (valid_bits & ATPX_MS_HYBRID_GFX_SUPPORTED) {
205 printk("ATPX Hybrid Graphics\n"); 206 printk("ATPX Hybrid Graphics\n");
206 atpx->functions.power_cntl = false; 207 /*
208 * Disable legacy PM methods only when pcie port PM is usable,
209 * otherwise the device might fail to power off or power on.
210 */
211 atpx->functions.power_cntl = !radeon_atpx_priv.bridge_pm_usable;
207 atpx->is_hybrid = true; 212 atpx->is_hybrid = true;
208 } 213 }
209 214
@@ -548,11 +553,16 @@ static bool radeon_atpx_detect(void)
548 struct pci_dev *pdev = NULL; 553 struct pci_dev *pdev = NULL;
549 bool has_atpx = false; 554 bool has_atpx = false;
550 int vga_count = 0; 555 int vga_count = 0;
556 bool d3_supported = false;
557 struct pci_dev *parent_pdev;
551 558
552 while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_VGA << 8, pdev)) != NULL) { 559 while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_VGA << 8, pdev)) != NULL) {
553 vga_count++; 560 vga_count++;
554 561
555 has_atpx |= (radeon_atpx_pci_probe_handle(pdev) == true); 562 has_atpx |= (radeon_atpx_pci_probe_handle(pdev) == true);
563
564 parent_pdev = pci_upstream_bridge(pdev);
565 d3_supported |= parent_pdev && parent_pdev->bridge_d3;
556 } 566 }
557 567
558 /* some newer PX laptops mark the dGPU as a non-VGA display device */ 568 /* some newer PX laptops mark the dGPU as a non-VGA display device */
@@ -560,6 +570,9 @@ static bool radeon_atpx_detect(void)
560 vga_count++; 570 vga_count++;
561 571
562 has_atpx |= (radeon_atpx_pci_probe_handle(pdev) == true); 572 has_atpx |= (radeon_atpx_pci_probe_handle(pdev) == true);
573
574 parent_pdev = pci_upstream_bridge(pdev);
575 d3_supported |= parent_pdev && parent_pdev->bridge_d3;
563 } 576 }
564 577
565 if (has_atpx && vga_count == 2) { 578 if (has_atpx && vga_count == 2) {
@@ -567,6 +580,7 @@ static bool radeon_atpx_detect(void)
567 printk(KERN_INFO "vga_switcheroo: detected switching method %s handle\n", 580 printk(KERN_INFO "vga_switcheroo: detected switching method %s handle\n",
568 acpi_method_name); 581 acpi_method_name);
569 radeon_atpx_priv.atpx_detected = true; 582 radeon_atpx_priv.atpx_detected = true;
583 radeon_atpx_priv.bridge_pm_usable = d3_supported;
570 radeon_atpx_init(); 584 radeon_atpx_init();
571 return true; 585 return true;
572 } 586 }
diff --git a/drivers/gpu/drm/radeon/radeon_connectors.c b/drivers/gpu/drm/radeon/radeon_connectors.c
index 50e96d2c593d..27affbde058c 100644
--- a/drivers/gpu/drm/radeon/radeon_connectors.c
+++ b/drivers/gpu/drm/radeon/radeon_connectors.c
@@ -927,6 +927,16 @@ radeon_lvds_detect(struct drm_connector *connector, bool force)
927 return ret; 927 return ret;
928} 928}
929 929
930static void radeon_connector_unregister(struct drm_connector *connector)
931{
932 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
933
934 if (radeon_connector->ddc_bus && radeon_connector->ddc_bus->has_aux) {
935 drm_dp_aux_unregister(&radeon_connector->ddc_bus->aux);
936 radeon_connector->ddc_bus->has_aux = false;
937 }
938}
939
930static void radeon_connector_destroy(struct drm_connector *connector) 940static void radeon_connector_destroy(struct drm_connector *connector)
931{ 941{
932 struct radeon_connector *radeon_connector = to_radeon_connector(connector); 942 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
@@ -984,6 +994,7 @@ static const struct drm_connector_funcs radeon_lvds_connector_funcs = {
984 .dpms = drm_helper_connector_dpms, 994 .dpms = drm_helper_connector_dpms,
985 .detect = radeon_lvds_detect, 995 .detect = radeon_lvds_detect,
986 .fill_modes = drm_helper_probe_single_connector_modes, 996 .fill_modes = drm_helper_probe_single_connector_modes,
997 .early_unregister = radeon_connector_unregister,
987 .destroy = radeon_connector_destroy, 998 .destroy = radeon_connector_destroy,
988 .set_property = radeon_lvds_set_property, 999 .set_property = radeon_lvds_set_property,
989}; 1000};
@@ -1111,6 +1122,7 @@ static const struct drm_connector_funcs radeon_vga_connector_funcs = {
1111 .dpms = drm_helper_connector_dpms, 1122 .dpms = drm_helper_connector_dpms,
1112 .detect = radeon_vga_detect, 1123 .detect = radeon_vga_detect,
1113 .fill_modes = drm_helper_probe_single_connector_modes, 1124 .fill_modes = drm_helper_probe_single_connector_modes,
1125 .early_unregister = radeon_connector_unregister,
1114 .destroy = radeon_connector_destroy, 1126 .destroy = radeon_connector_destroy,
1115 .set_property = radeon_connector_set_property, 1127 .set_property = radeon_connector_set_property,
1116}; 1128};
@@ -1188,6 +1200,7 @@ static const struct drm_connector_funcs radeon_tv_connector_funcs = {
1188 .dpms = drm_helper_connector_dpms, 1200 .dpms = drm_helper_connector_dpms,
1189 .detect = radeon_tv_detect, 1201 .detect = radeon_tv_detect,
1190 .fill_modes = drm_helper_probe_single_connector_modes, 1202 .fill_modes = drm_helper_probe_single_connector_modes,
1203 .early_unregister = radeon_connector_unregister,
1191 .destroy = radeon_connector_destroy, 1204 .destroy = radeon_connector_destroy,
1192 .set_property = radeon_connector_set_property, 1205 .set_property = radeon_connector_set_property,
1193}; 1206};
@@ -1519,6 +1532,7 @@ static const struct drm_connector_funcs radeon_dvi_connector_funcs = {
1519 .detect = radeon_dvi_detect, 1532 .detect = radeon_dvi_detect,
1520 .fill_modes = drm_helper_probe_single_connector_modes, 1533 .fill_modes = drm_helper_probe_single_connector_modes,
1521 .set_property = radeon_connector_set_property, 1534 .set_property = radeon_connector_set_property,
1535 .early_unregister = radeon_connector_unregister,
1522 .destroy = radeon_connector_destroy, 1536 .destroy = radeon_connector_destroy,
1523 .force = radeon_dvi_force, 1537 .force = radeon_dvi_force,
1524}; 1538};
@@ -1832,6 +1846,7 @@ static const struct drm_connector_funcs radeon_dp_connector_funcs = {
1832 .detect = radeon_dp_detect, 1846 .detect = radeon_dp_detect,
1833 .fill_modes = drm_helper_probe_single_connector_modes, 1847 .fill_modes = drm_helper_probe_single_connector_modes,
1834 .set_property = radeon_connector_set_property, 1848 .set_property = radeon_connector_set_property,
1849 .early_unregister = radeon_connector_unregister,
1835 .destroy = radeon_connector_destroy, 1850 .destroy = radeon_connector_destroy,
1836 .force = radeon_dvi_force, 1851 .force = radeon_dvi_force,
1837}; 1852};
@@ -1841,6 +1856,7 @@ static const struct drm_connector_funcs radeon_edp_connector_funcs = {
1841 .detect = radeon_dp_detect, 1856 .detect = radeon_dp_detect,
1842 .fill_modes = drm_helper_probe_single_connector_modes, 1857 .fill_modes = drm_helper_probe_single_connector_modes,
1843 .set_property = radeon_lvds_set_property, 1858 .set_property = radeon_lvds_set_property,
1859 .early_unregister = radeon_connector_unregister,
1844 .destroy = radeon_connector_destroy, 1860 .destroy = radeon_connector_destroy,
1845 .force = radeon_dvi_force, 1861 .force = radeon_dvi_force,
1846}; 1862};
@@ -1850,6 +1866,7 @@ static const struct drm_connector_funcs radeon_lvds_bridge_connector_funcs = {
1850 .detect = radeon_dp_detect, 1866 .detect = radeon_dp_detect,
1851 .fill_modes = drm_helper_probe_single_connector_modes, 1867 .fill_modes = drm_helper_probe_single_connector_modes,
1852 .set_property = radeon_lvds_set_property, 1868 .set_property = radeon_lvds_set_property,
1869 .early_unregister = radeon_connector_unregister,
1853 .destroy = radeon_connector_destroy, 1870 .destroy = radeon_connector_destroy,
1854 .force = radeon_dvi_force, 1871 .force = radeon_dvi_force,
1855}; 1872};
diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
index eb92aef46e3c..621af069a3d2 100644
--- a/drivers/gpu/drm/radeon/radeon_device.c
+++ b/drivers/gpu/drm/radeon/radeon_device.c
@@ -104,6 +104,14 @@ static const char radeon_family_name[][16] = {
104 "LAST", 104 "LAST",
105}; 105};
106 106
107#if defined(CONFIG_VGA_SWITCHEROO)
108bool radeon_has_atpx_dgpu_power_cntl(void);
109bool radeon_is_atpx_hybrid(void);
110#else
111static inline bool radeon_has_atpx_dgpu_power_cntl(void) { return false; }
112static inline bool radeon_is_atpx_hybrid(void) { return false; }
113#endif
114
107#define RADEON_PX_QUIRK_DISABLE_PX (1 << 0) 115#define RADEON_PX_QUIRK_DISABLE_PX (1 << 0)
108#define RADEON_PX_QUIRK_LONG_WAKEUP (1 << 1) 116#define RADEON_PX_QUIRK_LONG_WAKEUP (1 << 1)
109 117
@@ -160,6 +168,11 @@ static void radeon_device_handle_px_quirks(struct radeon_device *rdev)
160 168
161 if (rdev->px_quirk_flags & RADEON_PX_QUIRK_DISABLE_PX) 169 if (rdev->px_quirk_flags & RADEON_PX_QUIRK_DISABLE_PX)
162 rdev->flags &= ~RADEON_IS_PX; 170 rdev->flags &= ~RADEON_IS_PX;
171
172 /* disable PX is the system doesn't support dGPU power control or hybrid gfx */
173 if (!radeon_is_atpx_hybrid() &&
174 !radeon_has_atpx_dgpu_power_cntl())
175 rdev->flags &= ~RADEON_IS_PX;
163} 176}
164 177
165/** 178/**
diff --git a/drivers/gpu/drm/radeon/radeon_display.c b/drivers/gpu/drm/radeon/radeon_display.c
index b8ab30a7dd6d..cdb8cb568c15 100644
--- a/drivers/gpu/drm/radeon/radeon_display.c
+++ b/drivers/gpu/drm/radeon/radeon_display.c
@@ -1675,20 +1675,20 @@ int radeon_modeset_init(struct radeon_device *rdev)
1675 1675
1676void radeon_modeset_fini(struct radeon_device *rdev) 1676void radeon_modeset_fini(struct radeon_device *rdev)
1677{ 1677{
1678 radeon_fbdev_fini(rdev);
1679 kfree(rdev->mode_info.bios_hardcoded_edid);
1680
1681 /* free i2c buses */
1682 radeon_i2c_fini(rdev);
1683
1684 if (rdev->mode_info.mode_config_initialized) { 1678 if (rdev->mode_info.mode_config_initialized) {
1685 radeon_afmt_fini(rdev);
1686 drm_kms_helper_poll_fini(rdev->ddev); 1679 drm_kms_helper_poll_fini(rdev->ddev);
1687 radeon_hpd_fini(rdev); 1680 radeon_hpd_fini(rdev);
1688 drm_crtc_force_disable_all(rdev->ddev); 1681 drm_crtc_force_disable_all(rdev->ddev);
1682 radeon_fbdev_fini(rdev);
1683 radeon_afmt_fini(rdev);
1689 drm_mode_config_cleanup(rdev->ddev); 1684 drm_mode_config_cleanup(rdev->ddev);
1690 rdev->mode_info.mode_config_initialized = false; 1685 rdev->mode_info.mode_config_initialized = false;
1691 } 1686 }
1687
1688 kfree(rdev->mode_info.bios_hardcoded_edid);
1689
1690 /* free i2c buses */
1691 radeon_i2c_fini(rdev);
1692} 1692}
1693 1693
1694static bool is_hdtv_mode(const struct drm_display_mode *mode) 1694static bool is_hdtv_mode(const struct drm_display_mode *mode)
diff --git a/drivers/gpu/drm/radeon/radeon_dp_auxch.c b/drivers/gpu/drm/radeon/radeon_dp_auxch.c
index 2d465648856a..474a8a1886f7 100644
--- a/drivers/gpu/drm/radeon/radeon_dp_auxch.c
+++ b/drivers/gpu/drm/radeon/radeon_dp_auxch.c
@@ -105,7 +105,7 @@ radeon_dp_aux_transfer_native(struct drm_dp_aux *aux, struct drm_dp_aux_msg *msg
105 105
106 tmp &= AUX_HPD_SEL(0x7); 106 tmp &= AUX_HPD_SEL(0x7);
107 tmp |= AUX_HPD_SEL(chan->rec.hpd); 107 tmp |= AUX_HPD_SEL(chan->rec.hpd);
108 tmp |= AUX_EN | AUX_LS_READ_EN | AUX_HPD_DISCON(0x1); 108 tmp |= AUX_EN | AUX_LS_READ_EN;
109 109
110 WREG32(AUX_CONTROL + aux_offset[instance], tmp); 110 WREG32(AUX_CONTROL + aux_offset[instance], tmp);
111 111
diff --git a/drivers/gpu/drm/radeon/radeon_drv.c b/drivers/gpu/drm/radeon/radeon_drv.c
index 91c8f4339566..00ea0002b539 100644
--- a/drivers/gpu/drm/radeon/radeon_drv.c
+++ b/drivers/gpu/drm/radeon/radeon_drv.c
@@ -96,9 +96,10 @@
96 * 2.45.0 - Allow setting shader registers using DMA/COPY packet3 on SI 96 * 2.45.0 - Allow setting shader registers using DMA/COPY packet3 on SI
97 * 2.46.0 - Add PFP_SYNC_ME support on evergreen 97 * 2.46.0 - Add PFP_SYNC_ME support on evergreen
98 * 2.47.0 - Add UVD_NO_OP register support 98 * 2.47.0 - Add UVD_NO_OP register support
99 * 2.48.0 - TA_CS_BC_BASE_ADDR allowed on SI
99 */ 100 */
100#define KMS_DRIVER_MAJOR 2 101#define KMS_DRIVER_MAJOR 2
101#define KMS_DRIVER_MINOR 47 102#define KMS_DRIVER_MINOR 48
102#define KMS_DRIVER_PATCHLEVEL 0 103#define KMS_DRIVER_PATCHLEVEL 0
103int radeon_driver_load_kms(struct drm_device *dev, unsigned long flags); 104int radeon_driver_load_kms(struct drm_device *dev, unsigned long flags);
104int radeon_driver_unload_kms(struct drm_device *dev); 105int radeon_driver_unload_kms(struct drm_device *dev);
diff --git a/drivers/gpu/drm/radeon/radeon_i2c.c b/drivers/gpu/drm/radeon/radeon_i2c.c
index 021aa005623f..29f7817af821 100644
--- a/drivers/gpu/drm/radeon/radeon_i2c.c
+++ b/drivers/gpu/drm/radeon/radeon_i2c.c
@@ -982,9 +982,8 @@ void radeon_i2c_destroy(struct radeon_i2c_chan *i2c)
982{ 982{
983 if (!i2c) 983 if (!i2c)
984 return; 984 return;
985 WARN_ON(i2c->has_aux);
985 i2c_del_adapter(&i2c->adapter); 986 i2c_del_adapter(&i2c->adapter);
986 if (i2c->has_aux)
987 drm_dp_aux_unregister(&i2c->aux);
988 kfree(i2c); 987 kfree(i2c);
989} 988}
990 989
diff --git a/drivers/gpu/drm/radeon/radeon_object.c b/drivers/gpu/drm/radeon/radeon_object.c
index be30861afae9..41b72ce6613f 100644
--- a/drivers/gpu/drm/radeon/radeon_object.c
+++ b/drivers/gpu/drm/radeon/radeon_object.c
@@ -446,6 +446,10 @@ void radeon_bo_force_delete(struct radeon_device *rdev)
446 446
447int radeon_bo_init(struct radeon_device *rdev) 447int radeon_bo_init(struct radeon_device *rdev)
448{ 448{
449 /* reserve PAT memory space to WC for VRAM */
450 arch_io_reserve_memtype_wc(rdev->mc.aper_base,
451 rdev->mc.aper_size);
452
449 /* Add an MTRR for the VRAM */ 453 /* Add an MTRR for the VRAM */
450 if (!rdev->fastfb_working) { 454 if (!rdev->fastfb_working) {
451 rdev->mc.vram_mtrr = arch_phys_wc_add(rdev->mc.aper_base, 455 rdev->mc.vram_mtrr = arch_phys_wc_add(rdev->mc.aper_base,
@@ -463,6 +467,7 @@ void radeon_bo_fini(struct radeon_device *rdev)
463{ 467{
464 radeon_ttm_fini(rdev); 468 radeon_ttm_fini(rdev);
465 arch_phys_wc_del(rdev->mc.vram_mtrr); 469 arch_phys_wc_del(rdev->mc.vram_mtrr);
470 arch_io_free_memtype_wc(rdev->mc.aper_base, rdev->mc.aper_size);
466} 471}
467 472
468/* Returns how many bytes TTM can move per IB. 473/* Returns how many bytes TTM can move per IB.
diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
index 455268214b89..3de5e6e21662 100644
--- a/drivers/gpu/drm/radeon/radeon_ttm.c
+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
@@ -566,7 +566,8 @@ static int radeon_ttm_tt_pin_userptr(struct ttm_tt *ttm)
566 uint64_t userptr = gtt->userptr + pinned * PAGE_SIZE; 566 uint64_t userptr = gtt->userptr + pinned * PAGE_SIZE;
567 struct page **pages = ttm->pages + pinned; 567 struct page **pages = ttm->pages + pinned;
568 568
569 r = get_user_pages(userptr, num_pages, write, 0, pages, NULL); 569 r = get_user_pages(userptr, num_pages, write ? FOLL_WRITE : 0,
570 pages, NULL);
570 if (r < 0) 571 if (r < 0)
571 goto release_pages; 572 goto release_pages;
572 573
diff --git a/drivers/gpu/drm/radeon/si.c b/drivers/gpu/drm/radeon/si.c
index 7ee9aafbdf74..e402be8821c4 100644
--- a/drivers/gpu/drm/radeon/si.c
+++ b/drivers/gpu/drm/radeon/si.c
@@ -4431,6 +4431,7 @@ static bool si_vm_reg_valid(u32 reg)
4431 case SPI_CONFIG_CNTL: 4431 case SPI_CONFIG_CNTL:
4432 case SPI_CONFIG_CNTL_1: 4432 case SPI_CONFIG_CNTL_1:
4433 case TA_CNTL_AUX: 4433 case TA_CNTL_AUX:
4434 case TA_CS_BC_BASE_ADDR:
4434 return true; 4435 return true;
4435 default: 4436 default:
4436 DRM_ERROR("Invalid register 0x%x in CS\n", reg); 4437 DRM_ERROR("Invalid register 0x%x in CS\n", reg);
diff --git a/drivers/gpu/drm/radeon/si_dpm.c b/drivers/gpu/drm/radeon/si_dpm.c
index 89bdf20344ae..c49934527a87 100644
--- a/drivers/gpu/drm/radeon/si_dpm.c
+++ b/drivers/gpu/drm/radeon/si_dpm.c
@@ -2999,6 +2999,49 @@ static void si_apply_state_adjust_rules(struct radeon_device *rdev,
2999 int i; 2999 int i;
3000 struct si_dpm_quirk *p = si_dpm_quirk_list; 3000 struct si_dpm_quirk *p = si_dpm_quirk_list;
3001 3001
3002 /* limit all SI kickers */
3003 if (rdev->family == CHIP_PITCAIRN) {
3004 if ((rdev->pdev->revision == 0x81) ||
3005 (rdev->pdev->device == 0x6810) ||
3006 (rdev->pdev->device == 0x6811) ||
3007 (rdev->pdev->device == 0x6816) ||
3008 (rdev->pdev->device == 0x6817) ||
3009 (rdev->pdev->device == 0x6806))
3010 max_mclk = 120000;
3011 } else if (rdev->family == CHIP_VERDE) {
3012 if ((rdev->pdev->revision == 0x81) ||
3013 (rdev->pdev->revision == 0x83) ||
3014 (rdev->pdev->revision == 0x87) ||
3015 (rdev->pdev->device == 0x6820) ||
3016 (rdev->pdev->device == 0x6821) ||
3017 (rdev->pdev->device == 0x6822) ||
3018 (rdev->pdev->device == 0x6823) ||
3019 (rdev->pdev->device == 0x682A) ||
3020 (rdev->pdev->device == 0x682B)) {
3021 max_sclk = 75000;
3022 max_mclk = 80000;
3023 }
3024 } else if (rdev->family == CHIP_OLAND) {
3025 if ((rdev->pdev->revision == 0xC7) ||
3026 (rdev->pdev->revision == 0x80) ||
3027 (rdev->pdev->revision == 0x81) ||
3028 (rdev->pdev->revision == 0x83) ||
3029 (rdev->pdev->device == 0x6604) ||
3030 (rdev->pdev->device == 0x6605)) {
3031 max_sclk = 75000;
3032 max_mclk = 80000;
3033 }
3034 } else if (rdev->family == CHIP_HAINAN) {
3035 if ((rdev->pdev->revision == 0x81) ||
3036 (rdev->pdev->revision == 0x83) ||
3037 (rdev->pdev->revision == 0xC3) ||
3038 (rdev->pdev->device == 0x6664) ||
3039 (rdev->pdev->device == 0x6665) ||
3040 (rdev->pdev->device == 0x6667)) {
3041 max_sclk = 75000;
3042 max_mclk = 80000;
3043 }
3044 }
3002 /* Apply dpm quirks */ 3045 /* Apply dpm quirks */
3003 while (p && p->chip_device != 0) { 3046 while (p && p->chip_device != 0) {
3004 if (rdev->pdev->vendor == p->chip_vendor && 3047 if (rdev->pdev->vendor == p->chip_vendor &&
@@ -3011,16 +3054,6 @@ static void si_apply_state_adjust_rules(struct radeon_device *rdev,
3011 } 3054 }
3012 ++p; 3055 ++p;
3013 } 3056 }
3014 /* limit mclk on all R7 370 parts for stability */
3015 if (rdev->pdev->device == 0x6811 &&
3016 rdev->pdev->revision == 0x81)
3017 max_mclk = 120000;
3018 /* limit sclk/mclk on Jet parts for stability */
3019 if (rdev->pdev->device == 0x6665 &&
3020 rdev->pdev->revision == 0xc3) {
3021 max_sclk = 75000;
3022 max_mclk = 80000;
3023 }
3024 3057
3025 if (rps->vce_active) { 3058 if (rps->vce_active) {
3026 rps->evclk = rdev->pm.dpm.vce_states[rdev->pm.dpm.vce_level].evclk; 3059 rps->evclk = rdev->pm.dpm.vce_states[rdev->pm.dpm.vce_level].evclk;
diff --git a/drivers/gpu/drm/radeon/sid.h b/drivers/gpu/drm/radeon/sid.h
index eb220eecba78..65a911ddd509 100644
--- a/drivers/gpu/drm/radeon/sid.h
+++ b/drivers/gpu/drm/radeon/sid.h
@@ -1145,6 +1145,7 @@
1145#define SPI_LB_CU_MASK 0x9354 1145#define SPI_LB_CU_MASK 0x9354
1146 1146
1147#define TA_CNTL_AUX 0x9508 1147#define TA_CNTL_AUX 0x9508
1148#define TA_CS_BC_BASE_ADDR 0x950C
1148 1149
1149#define CC_RB_BACKEND_DISABLE 0x98F4 1150#define CC_RB_BACKEND_DISABLE 0x98F4
1150#define BACKEND_DISABLE(x) ((x) << 16) 1151#define BACKEND_DISABLE(x) ((x) << 16)
diff --git a/drivers/gpu/drm/rcar-du/rcar_du_kms.c b/drivers/gpu/drm/rcar-du/rcar_du_kms.c
index bd9c3bb9252c..392c7e6de042 100644
--- a/drivers/gpu/drm/rcar-du/rcar_du_kms.c
+++ b/drivers/gpu/drm/rcar-du/rcar_du_kms.c
@@ -231,8 +231,16 @@ static int rcar_du_atomic_check(struct drm_device *dev,
231 struct rcar_du_device *rcdu = dev->dev_private; 231 struct rcar_du_device *rcdu = dev->dev_private;
232 int ret; 232 int ret;
233 233
234 ret = drm_atomic_helper_check(dev, state); 234 ret = drm_atomic_helper_check_modeset(dev, state);
235 if (ret < 0) 235 if (ret)
236 return ret;
237
238 ret = drm_atomic_normalize_zpos(dev, state);
239 if (ret)
240 return ret;
241
242 ret = drm_atomic_helper_check_planes(dev, state);
243 if (ret)
236 return ret; 244 return ret;
237 245
238 if (rcar_du_has(rcdu, RCAR_DU_FEATURE_VSP1_SOURCE)) 246 if (rcar_du_has(rcdu, RCAR_DU_FEATURE_VSP1_SOURCE))
diff --git a/drivers/gpu/drm/sti/sti_drv.c b/drivers/gpu/drm/sti/sti_drv.c
index 2784919a7366..9df308565f6c 100644
--- a/drivers/gpu/drm/sti/sti_drv.c
+++ b/drivers/gpu/drm/sti/sti_drv.c
@@ -195,6 +195,26 @@ static void sti_atomic_work(struct work_struct *work)
195 sti_atomic_complete(private, private->commit.state); 195 sti_atomic_complete(private, private->commit.state);
196} 196}
197 197
198static int sti_atomic_check(struct drm_device *dev,
199 struct drm_atomic_state *state)
200{
201 int ret;
202
203 ret = drm_atomic_helper_check_modeset(dev, state);
204 if (ret)
205 return ret;
206
207 ret = drm_atomic_normalize_zpos(dev, state);
208 if (ret)
209 return ret;
210
211 ret = drm_atomic_helper_check_planes(dev, state);
212 if (ret)
213 return ret;
214
215 return ret;
216}
217
198static int sti_atomic_commit(struct drm_device *drm, 218static int sti_atomic_commit(struct drm_device *drm,
199 struct drm_atomic_state *state, bool nonblock) 219 struct drm_atomic_state *state, bool nonblock)
200{ 220{
@@ -248,7 +268,7 @@ static void sti_output_poll_changed(struct drm_device *ddev)
248static const struct drm_mode_config_funcs sti_mode_config_funcs = { 268static const struct drm_mode_config_funcs sti_mode_config_funcs = {
249 .fb_create = drm_fb_cma_create, 269 .fb_create = drm_fb_cma_create,
250 .output_poll_changed = sti_output_poll_changed, 270 .output_poll_changed = sti_output_poll_changed,
251 .atomic_check = drm_atomic_helper_check, 271 .atomic_check = sti_atomic_check,
252 .atomic_commit = sti_atomic_commit, 272 .atomic_commit = sti_atomic_commit,
253}; 273};
254 274
diff --git a/drivers/gpu/drm/sun4i/sun4i_drv.c b/drivers/gpu/drm/sun4i/sun4i_drv.c
index 0da9862ad8ed..70e9fd59c5a2 100644
--- a/drivers/gpu/drm/sun4i/sun4i_drv.c
+++ b/drivers/gpu/drm/sun4i/sun4i_drv.c
@@ -142,9 +142,9 @@ static int sun4i_drv_bind(struct device *dev)
142 142
143 /* Create our layers */ 143 /* Create our layers */
144 drv->layers = sun4i_layers_init(drm); 144 drv->layers = sun4i_layers_init(drm);
145 if (!drv->layers) { 145 if (IS_ERR(drv->layers)) {
146 dev_err(drm->dev, "Couldn't create the planes\n"); 146 dev_err(drm->dev, "Couldn't create the planes\n");
147 ret = -EINVAL; 147 ret = PTR_ERR(drv->layers);
148 goto free_drm; 148 goto free_drm;
149 } 149 }
150 150
diff --git a/drivers/gpu/drm/sun4i/sun4i_rgb.c b/drivers/gpu/drm/sun4i/sun4i_rgb.c
index c3ff10f559cc..d198ad7e5323 100644
--- a/drivers/gpu/drm/sun4i/sun4i_rgb.c
+++ b/drivers/gpu/drm/sun4i/sun4i_rgb.c
@@ -152,15 +152,13 @@ static void sun4i_rgb_encoder_enable(struct drm_encoder *encoder)
152 152
153 DRM_DEBUG_DRIVER("Enabling RGB output\n"); 153 DRM_DEBUG_DRIVER("Enabling RGB output\n");
154 154
155 if (!IS_ERR(tcon->panel)) { 155 if (!IS_ERR(tcon->panel))
156 drm_panel_prepare(tcon->panel); 156 drm_panel_prepare(tcon->panel);
157 drm_panel_enable(tcon->panel);
158 }
159
160 /* encoder->bridge can be NULL; drm_bridge_enable checks for it */
161 drm_bridge_enable(encoder->bridge);
162 157
163 sun4i_tcon_channel_enable(tcon, 0); 158 sun4i_tcon_channel_enable(tcon, 0);
159
160 if (!IS_ERR(tcon->panel))
161 drm_panel_enable(tcon->panel);
164} 162}
165 163
166static void sun4i_rgb_encoder_disable(struct drm_encoder *encoder) 164static void sun4i_rgb_encoder_disable(struct drm_encoder *encoder)
@@ -171,15 +169,13 @@ static void sun4i_rgb_encoder_disable(struct drm_encoder *encoder)
171 169
172 DRM_DEBUG_DRIVER("Disabling RGB output\n"); 170 DRM_DEBUG_DRIVER("Disabling RGB output\n");
173 171
174 sun4i_tcon_channel_disable(tcon, 0); 172 if (!IS_ERR(tcon->panel))
173 drm_panel_disable(tcon->panel);
175 174
176 /* encoder->bridge can be NULL; drm_bridge_disable checks for it */ 175 sun4i_tcon_channel_disable(tcon, 0);
177 drm_bridge_disable(encoder->bridge);
178 176
179 if (!IS_ERR(tcon->panel)) { 177 if (!IS_ERR(tcon->panel))
180 drm_panel_disable(tcon->panel);
181 drm_panel_unprepare(tcon->panel); 178 drm_panel_unprepare(tcon->panel);
182 }
183} 179}
184 180
185static void sun4i_rgb_encoder_mode_set(struct drm_encoder *encoder, 181static void sun4i_rgb_encoder_mode_set(struct drm_encoder *encoder,
diff --git a/drivers/gpu/drm/udl/udl_main.c b/drivers/gpu/drm/udl/udl_main.c
index 29f0207fa677..873f010d9616 100644
--- a/drivers/gpu/drm/udl/udl_main.c
+++ b/drivers/gpu/drm/udl/udl_main.c
@@ -98,17 +98,23 @@ success:
98static int udl_select_std_channel(struct udl_device *udl) 98static int udl_select_std_channel(struct udl_device *udl)
99{ 99{
100 int ret; 100 int ret;
101 u8 set_def_chn[] = {0x57, 0xCD, 0xDC, 0xA7, 101 static const u8 set_def_chn[] = {0x57, 0xCD, 0xDC, 0xA7,
102 0x1C, 0x88, 0x5E, 0x15, 102 0x1C, 0x88, 0x5E, 0x15,
103 0x60, 0xFE, 0xC6, 0x97, 103 0x60, 0xFE, 0xC6, 0x97,
104 0x16, 0x3D, 0x47, 0xF2}; 104 0x16, 0x3D, 0x47, 0xF2};
105 void *sendbuf;
106
107 sendbuf = kmemdup(set_def_chn, sizeof(set_def_chn), GFP_KERNEL);
108 if (!sendbuf)
109 return -ENOMEM;
105 110
106 ret = usb_control_msg(udl->udev, 111 ret = usb_control_msg(udl->udev,
107 usb_sndctrlpipe(udl->udev, 0), 112 usb_sndctrlpipe(udl->udev, 0),
108 NR_USB_REQUEST_CHANNEL, 113 NR_USB_REQUEST_CHANNEL,
109 (USB_DIR_OUT | USB_TYPE_VENDOR), 0, 0, 114 (USB_DIR_OUT | USB_TYPE_VENDOR), 0, 0,
110 set_def_chn, sizeof(set_def_chn), 115 sendbuf, sizeof(set_def_chn),
111 USB_CTRL_SET_TIMEOUT); 116 USB_CTRL_SET_TIMEOUT);
117 kfree(sendbuf);
112 return ret < 0 ? ret : 0; 118 return ret < 0 ? ret : 0;
113} 119}
114 120
diff --git a/drivers/gpu/drm/via/via_dmablit.c b/drivers/gpu/drm/via/via_dmablit.c
index 7e2a12c4fed2..1a3ad769f8c8 100644
--- a/drivers/gpu/drm/via/via_dmablit.c
+++ b/drivers/gpu/drm/via/via_dmablit.c
@@ -241,8 +241,8 @@ via_lock_all_dma_pages(drm_via_sg_info_t *vsg, drm_via_dmablit_t *xfer)
241 down_read(&current->mm->mmap_sem); 241 down_read(&current->mm->mmap_sem);
242 ret = get_user_pages((unsigned long)xfer->mem_addr, 242 ret = get_user_pages((unsigned long)xfer->mem_addr,
243 vsg->num_pages, 243 vsg->num_pages,
244 (vsg->direction == DMA_FROM_DEVICE), 244 (vsg->direction == DMA_FROM_DEVICE) ? FOLL_WRITE : 0,
245 0, vsg->pages, NULL); 245 vsg->pages, NULL);
246 246
247 up_read(&current->mm->mmap_sem); 247 up_read(&current->mm->mmap_sem);
248 if (ret != vsg->num_pages) { 248 if (ret != vsg->num_pages) {
diff --git a/drivers/gpu/drm/virtio/virtgpu_display.c b/drivers/gpu/drm/virtio/virtgpu_display.c
index 7cf3678623c3..58048709c34e 100644
--- a/drivers/gpu/drm/virtio/virtgpu_display.c
+++ b/drivers/gpu/drm/virtio/virtgpu_display.c
@@ -338,8 +338,7 @@ static void vgdev_atomic_commit_tail(struct drm_atomic_state *state)
338 338
339 drm_atomic_helper_commit_modeset_disables(dev, state); 339 drm_atomic_helper_commit_modeset_disables(dev, state);
340 drm_atomic_helper_commit_modeset_enables(dev, state); 340 drm_atomic_helper_commit_modeset_enables(dev, state);
341 drm_atomic_helper_commit_planes(dev, state, 341 drm_atomic_helper_commit_planes(dev, state, 0);
342 DRM_PLANE_COMMIT_ACTIVE_ONLY);
343 342
344 drm_atomic_helper_commit_hw_done(state); 343 drm_atomic_helper_commit_hw_done(state);
345 344
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
index e8ae3dc476d1..18061a4bc2f2 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
@@ -241,15 +241,15 @@ static int vmwgfx_pm_notifier(struct notifier_block *nb, unsigned long val,
241 void *ptr); 241 void *ptr);
242 242
243MODULE_PARM_DESC(enable_fbdev, "Enable vmwgfx fbdev"); 243MODULE_PARM_DESC(enable_fbdev, "Enable vmwgfx fbdev");
244module_param_named(enable_fbdev, enable_fbdev, int, 0600); 244module_param_named(enable_fbdev, enable_fbdev, int, S_IRUSR | S_IWUSR);
245MODULE_PARM_DESC(force_dma_api, "Force using the DMA API for TTM pages"); 245MODULE_PARM_DESC(force_dma_api, "Force using the DMA API for TTM pages");
246module_param_named(force_dma_api, vmw_force_iommu, int, 0600); 246module_param_named(force_dma_api, vmw_force_iommu, int, S_IRUSR | S_IWUSR);
247MODULE_PARM_DESC(restrict_iommu, "Try to limit IOMMU usage for TTM pages"); 247MODULE_PARM_DESC(restrict_iommu, "Try to limit IOMMU usage for TTM pages");
248module_param_named(restrict_iommu, vmw_restrict_iommu, int, 0600); 248module_param_named(restrict_iommu, vmw_restrict_iommu, int, S_IRUSR | S_IWUSR);
249MODULE_PARM_DESC(force_coherent, "Force coherent TTM pages"); 249MODULE_PARM_DESC(force_coherent, "Force coherent TTM pages");
250module_param_named(force_coherent, vmw_force_coherent, int, 0600); 250module_param_named(force_coherent, vmw_force_coherent, int, S_IRUSR | S_IWUSR);
251MODULE_PARM_DESC(restrict_dma_mask, "Restrict DMA mask to 44 bits with IOMMU"); 251MODULE_PARM_DESC(restrict_dma_mask, "Restrict DMA mask to 44 bits with IOMMU");
252module_param_named(restrict_dma_mask, vmw_restrict_dma_mask, int, 0600); 252module_param_named(restrict_dma_mask, vmw_restrict_dma_mask, int, S_IRUSR | S_IWUSR);
253MODULE_PARM_DESC(assume_16bpp, "Assume 16-bpp when filtering modes"); 253MODULE_PARM_DESC(assume_16bpp, "Assume 16-bpp when filtering modes");
254module_param_named(assume_16bpp, vmw_assume_16bpp, int, 0600); 254module_param_named(assume_16bpp, vmw_assume_16bpp, int, 0600);
255 255
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
index 070d750af16d..1e59a486bba8 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
@@ -43,7 +43,7 @@
43 43
44#define VMWGFX_DRIVER_DATE "20160210" 44#define VMWGFX_DRIVER_DATE "20160210"
45#define VMWGFX_DRIVER_MAJOR 2 45#define VMWGFX_DRIVER_MAJOR 2
46#define VMWGFX_DRIVER_MINOR 10 46#define VMWGFX_DRIVER_MINOR 11
47#define VMWGFX_DRIVER_PATCHLEVEL 0 47#define VMWGFX_DRIVER_PATCHLEVEL 0
48#define VMWGFX_FILE_PAGE_OFFSET 0x00100000 48#define VMWGFX_FILE_PAGE_OFFSET 0x00100000
49#define VMWGFX_FIFO_STATIC_SIZE (1024*1024) 49#define VMWGFX_FIFO_STATIC_SIZE (1024*1024)
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c b/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c
index dc5beff2b4aa..c7b53d987f06 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c
@@ -35,17 +35,37 @@
35#define VMW_RES_HT_ORDER 12 35#define VMW_RES_HT_ORDER 12
36 36
37/** 37/**
38 * enum vmw_resource_relocation_type - Relocation type for resources
39 *
40 * @vmw_res_rel_normal: Traditional relocation. The resource id in the
41 * command stream is replaced with the actual id after validation.
42 * @vmw_res_rel_nop: NOP relocation. The command is unconditionally replaced
43 * with a NOP.
44 * @vmw_res_rel_cond_nop: Conditional NOP relocation. If the resource id
45 * after validation is -1, the command is replaced with a NOP. Otherwise no
46 * action.
47 */
48enum vmw_resource_relocation_type {
49 vmw_res_rel_normal,
50 vmw_res_rel_nop,
51 vmw_res_rel_cond_nop,
52 vmw_res_rel_max
53};
54
55/**
38 * struct vmw_resource_relocation - Relocation info for resources 56 * struct vmw_resource_relocation - Relocation info for resources
39 * 57 *
40 * @head: List head for the software context's relocation list. 58 * @head: List head for the software context's relocation list.
41 * @res: Non-ref-counted pointer to the resource. 59 * @res: Non-ref-counted pointer to the resource.
42 * @offset: Offset of 4 byte entries into the command buffer where the 60 * @offset: Offset of single byte entries into the command buffer where the
43 * id that needs fixup is located. 61 * id that needs fixup is located.
62 * @rel_type: Type of relocation.
44 */ 63 */
45struct vmw_resource_relocation { 64struct vmw_resource_relocation {
46 struct list_head head; 65 struct list_head head;
47 const struct vmw_resource *res; 66 const struct vmw_resource *res;
48 unsigned long offset; 67 u32 offset:29;
68 enum vmw_resource_relocation_type rel_type:3;
49}; 69};
50 70
51/** 71/**
@@ -109,7 +129,18 @@ static int vmw_bo_to_validate_list(struct vmw_sw_context *sw_context,
109 struct vmw_dma_buffer *vbo, 129 struct vmw_dma_buffer *vbo,
110 bool validate_as_mob, 130 bool validate_as_mob,
111 uint32_t *p_val_node); 131 uint32_t *p_val_node);
112 132/**
133 * vmw_ptr_diff - Compute the offset from a to b in bytes
134 *
135 * @a: A starting pointer.
136 * @b: A pointer offset in the same address space.
137 *
138 * Returns: The offset in bytes between the two pointers.
139 */
140static size_t vmw_ptr_diff(void *a, void *b)
141{
142 return (unsigned long) b - (unsigned long) a;
143}
113 144
114/** 145/**
115 * vmw_resources_unreserve - unreserve resources previously reserved for 146 * vmw_resources_unreserve - unreserve resources previously reserved for
@@ -409,11 +440,14 @@ static int vmw_resource_context_res_add(struct vmw_private *dev_priv,
409 * @list: Pointer to head of relocation list. 440 * @list: Pointer to head of relocation list.
410 * @res: The resource. 441 * @res: The resource.
411 * @offset: Offset into the command buffer currently being parsed where the 442 * @offset: Offset into the command buffer currently being parsed where the
412 * id that needs fixup is located. Granularity is 4 bytes. 443 * id that needs fixup is located. Granularity is one byte.
444 * @rel_type: Relocation type.
413 */ 445 */
414static int vmw_resource_relocation_add(struct list_head *list, 446static int vmw_resource_relocation_add(struct list_head *list,
415 const struct vmw_resource *res, 447 const struct vmw_resource *res,
416 unsigned long offset) 448 unsigned long offset,
449 enum vmw_resource_relocation_type
450 rel_type)
417{ 451{
418 struct vmw_resource_relocation *rel; 452 struct vmw_resource_relocation *rel;
419 453
@@ -425,6 +459,7 @@ static int vmw_resource_relocation_add(struct list_head *list,
425 459
426 rel->res = res; 460 rel->res = res;
427 rel->offset = offset; 461 rel->offset = offset;
462 rel->rel_type = rel_type;
428 list_add_tail(&rel->head, list); 463 list_add_tail(&rel->head, list);
429 464
430 return 0; 465 return 0;
@@ -459,11 +494,24 @@ static void vmw_resource_relocations_apply(uint32_t *cb,
459{ 494{
460 struct vmw_resource_relocation *rel; 495 struct vmw_resource_relocation *rel;
461 496
497 /* Validate the struct vmw_resource_relocation member size */
498 BUILD_BUG_ON(SVGA_CB_MAX_SIZE >= (1 << 29));
499 BUILD_BUG_ON(vmw_res_rel_max >= (1 << 3));
500
462 list_for_each_entry(rel, list, head) { 501 list_for_each_entry(rel, list, head) {
463 if (likely(rel->res != NULL)) 502 u32 *addr = (u32 *)((unsigned long) cb + rel->offset);
464 cb[rel->offset] = rel->res->id; 503 switch (rel->rel_type) {
465 else 504 case vmw_res_rel_normal:
466 cb[rel->offset] = SVGA_3D_CMD_NOP; 505 *addr = rel->res->id;
506 break;
507 case vmw_res_rel_nop:
508 *addr = SVGA_3D_CMD_NOP;
509 break;
510 default:
511 if (rel->res->id == -1)
512 *addr = SVGA_3D_CMD_NOP;
513 break;
514 }
467 } 515 }
468} 516}
469 517
@@ -655,7 +703,9 @@ static int vmw_cmd_res_reloc_add(struct vmw_private *dev_priv,
655 *p_val = NULL; 703 *p_val = NULL;
656 ret = vmw_resource_relocation_add(&sw_context->res_relocations, 704 ret = vmw_resource_relocation_add(&sw_context->res_relocations,
657 res, 705 res,
658 id_loc - sw_context->buf_start); 706 vmw_ptr_diff(sw_context->buf_start,
707 id_loc),
708 vmw_res_rel_normal);
659 if (unlikely(ret != 0)) 709 if (unlikely(ret != 0))
660 return ret; 710 return ret;
661 711
@@ -721,7 +771,8 @@ vmw_cmd_res_check(struct vmw_private *dev_priv,
721 771
722 return vmw_resource_relocation_add 772 return vmw_resource_relocation_add
723 (&sw_context->res_relocations, res, 773 (&sw_context->res_relocations, res,
724 id_loc - sw_context->buf_start); 774 vmw_ptr_diff(sw_context->buf_start, id_loc),
775 vmw_res_rel_normal);
725 } 776 }
726 777
727 ret = vmw_user_resource_lookup_handle(dev_priv, 778 ret = vmw_user_resource_lookup_handle(dev_priv,
@@ -2143,10 +2194,10 @@ static int vmw_cmd_shader_define(struct vmw_private *dev_priv,
2143 return ret; 2194 return ret;
2144 2195
2145 return vmw_resource_relocation_add(&sw_context->res_relocations, 2196 return vmw_resource_relocation_add(&sw_context->res_relocations,
2146 NULL, &cmd->header.id - 2197 NULL,
2147 sw_context->buf_start); 2198 vmw_ptr_diff(sw_context->buf_start,
2148 2199 &cmd->header.id),
2149 return 0; 2200 vmw_res_rel_nop);
2150} 2201}
2151 2202
2152/** 2203/**
@@ -2188,10 +2239,10 @@ static int vmw_cmd_shader_destroy(struct vmw_private *dev_priv,
2188 return ret; 2239 return ret;
2189 2240
2190 return vmw_resource_relocation_add(&sw_context->res_relocations, 2241 return vmw_resource_relocation_add(&sw_context->res_relocations,
2191 NULL, &cmd->header.id - 2242 NULL,
2192 sw_context->buf_start); 2243 vmw_ptr_diff(sw_context->buf_start,
2193 2244 &cmd->header.id),
2194 return 0; 2245 vmw_res_rel_nop);
2195} 2246}
2196 2247
2197/** 2248/**
@@ -2848,8 +2899,7 @@ static int vmw_cmd_dx_cid_check(struct vmw_private *dev_priv,
2848 * @header: Pointer to the command header in the command stream. 2899 * @header: Pointer to the command header in the command stream.
2849 * 2900 *
2850 * Check that the view exists, and if it was not created using this 2901 * Check that the view exists, and if it was not created using this
2851 * command batch, make sure it's validated (present in the device) so that 2902 * command batch, conditionally make this command a NOP.
2852 * the remove command will not confuse the device.
2853 */ 2903 */
2854static int vmw_cmd_dx_view_remove(struct vmw_private *dev_priv, 2904static int vmw_cmd_dx_view_remove(struct vmw_private *dev_priv,
2855 struct vmw_sw_context *sw_context, 2905 struct vmw_sw_context *sw_context,
@@ -2877,10 +2927,16 @@ static int vmw_cmd_dx_view_remove(struct vmw_private *dev_priv,
2877 return ret; 2927 return ret;
2878 2928
2879 /* 2929 /*
2880 * Add view to the validate list iff it was not created using this 2930 * If the view wasn't created during this command batch, it might
2881 * command batch. 2931 * have been removed due to a context swapout, so add a
2932 * relocation to conditionally make this command a NOP to avoid
2933 * device errors.
2882 */ 2934 */
2883 return vmw_view_res_val_add(sw_context, view); 2935 return vmw_resource_relocation_add(&sw_context->res_relocations,
2936 view,
2937 vmw_ptr_diff(sw_context->buf_start,
2938 &cmd->header.id),
2939 vmw_res_rel_cond_nop);
2884} 2940}
2885 2941
2886/** 2942/**
@@ -3029,6 +3085,35 @@ static int vmw_cmd_dx_genmips(struct vmw_private *dev_priv,
3029 cmd->body.shaderResourceViewId); 3085 cmd->body.shaderResourceViewId);
3030} 3086}
3031 3087
3088/**
3089 * vmw_cmd_dx_transfer_from_buffer -
3090 * Validate an SVGA_3D_CMD_DX_TRANSFER_FROM_BUFFER command
3091 *
3092 * @dev_priv: Pointer to a device private struct.
3093 * @sw_context: The software context being used for this batch.
3094 * @header: Pointer to the command header in the command stream.
3095 */
3096static int vmw_cmd_dx_transfer_from_buffer(struct vmw_private *dev_priv,
3097 struct vmw_sw_context *sw_context,
3098 SVGA3dCmdHeader *header)
3099{
3100 struct {
3101 SVGA3dCmdHeader header;
3102 SVGA3dCmdDXTransferFromBuffer body;
3103 } *cmd = container_of(header, typeof(*cmd), header);
3104 int ret;
3105
3106 ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
3107 user_surface_converter,
3108 &cmd->body.srcSid, NULL);
3109 if (ret != 0)
3110 return ret;
3111
3112 return vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface,
3113 user_surface_converter,
3114 &cmd->body.destSid, NULL);
3115}
3116
3032static int vmw_cmd_check_not_3d(struct vmw_private *dev_priv, 3117static int vmw_cmd_check_not_3d(struct vmw_private *dev_priv,
3033 struct vmw_sw_context *sw_context, 3118 struct vmw_sw_context *sw_context,
3034 void *buf, uint32_t *size) 3119 void *buf, uint32_t *size)
@@ -3379,6 +3464,9 @@ static const struct vmw_cmd_entry vmw_cmd_entries[SVGA_3D_CMD_MAX] = {
3379 &vmw_cmd_buffer_copy_check, true, false, true), 3464 &vmw_cmd_buffer_copy_check, true, false, true),
3380 VMW_CMD_DEF(SVGA_3D_CMD_DX_PRED_COPY_REGION, 3465 VMW_CMD_DEF(SVGA_3D_CMD_DX_PRED_COPY_REGION,
3381 &vmw_cmd_pred_copy_check, true, false, true), 3466 &vmw_cmd_pred_copy_check, true, false, true),
3467 VMW_CMD_DEF(SVGA_3D_CMD_DX_TRANSFER_FROM_BUFFER,
3468 &vmw_cmd_dx_transfer_from_buffer,
3469 true, false, true),
3382}; 3470};
3383 3471
3384static int vmw_cmd_check(struct vmw_private *dev_priv, 3472static int vmw_cmd_check(struct vmw_private *dev_priv,
@@ -3848,14 +3936,14 @@ static void *vmw_execbuf_cmdbuf(struct vmw_private *dev_priv,
3848 int ret; 3936 int ret;
3849 3937
3850 *header = NULL; 3938 *header = NULL;
3851 if (!dev_priv->cman || kernel_commands)
3852 return kernel_commands;
3853
3854 if (command_size > SVGA_CB_MAX_SIZE) { 3939 if (command_size > SVGA_CB_MAX_SIZE) {
3855 DRM_ERROR("Command buffer is too large.\n"); 3940 DRM_ERROR("Command buffer is too large.\n");
3856 return ERR_PTR(-EINVAL); 3941 return ERR_PTR(-EINVAL);
3857 } 3942 }
3858 3943
3944 if (!dev_priv->cman || kernel_commands)
3945 return kernel_commands;
3946
3859 /* If possible, add a little space for fencing. */ 3947 /* If possible, add a little space for fencing. */
3860 cmdbuf_size = command_size + 512; 3948 cmdbuf_size = command_size + 512;
3861 cmdbuf_size = min_t(size_t, cmdbuf_size, SVGA_CB_MAX_SIZE); 3949 cmdbuf_size = min_t(size_t, cmdbuf_size, SVGA_CB_MAX_SIZE);
@@ -4232,9 +4320,6 @@ void __vmw_execbuf_release_pinned_bo(struct vmw_private *dev_priv,
4232 ttm_bo_unref(&query_val.bo); 4320 ttm_bo_unref(&query_val.bo);
4233 ttm_bo_unref(&pinned_val.bo); 4321 ttm_bo_unref(&pinned_val.bo);
4234 vmw_dmabuf_unreference(&dev_priv->pinned_bo); 4322 vmw_dmabuf_unreference(&dev_priv->pinned_bo);
4235 DRM_INFO("Dummy query bo pin count: %d\n",
4236 dev_priv->dummy_query_bo->pin_count);
4237
4238out_unlock: 4323out_unlock:
4239 return; 4324 return;
4240 4325
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c b/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c
index 6a328d507a28..52ca1c9d070e 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c
@@ -574,10 +574,8 @@ static int vmw_user_dmabuf_synccpu_grab(struct vmw_user_dma_buffer *user_bo,
574 bool nonblock = !!(flags & drm_vmw_synccpu_dontblock); 574 bool nonblock = !!(flags & drm_vmw_synccpu_dontblock);
575 long lret; 575 long lret;
576 576
577 if (nonblock) 577 lret = reservation_object_wait_timeout_rcu(bo->resv, true, true,
578 return reservation_object_test_signaled_rcu(bo->resv, true) ? 0 : -EBUSY; 578 nonblock ? 0 : MAX_SCHEDULE_TIMEOUT);
579
580 lret = reservation_object_wait_timeout_rcu(bo->resv, true, true, MAX_SCHEDULE_TIMEOUT);
581 if (!lret) 579 if (!lret)
582 return -EBUSY; 580 return -EBUSY;
583 else if (lret < 0) 581 else if (lret < 0)
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c b/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c
index c2a721a8cef9..b445ce9b9757 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c
@@ -324,7 +324,7 @@ static void vmw_hw_surface_destroy(struct vmw_resource *res)
324 if (res->id != -1) { 324 if (res->id != -1) {
325 325
326 cmd = vmw_fifo_reserve(dev_priv, vmw_surface_destroy_size()); 326 cmd = vmw_fifo_reserve(dev_priv, vmw_surface_destroy_size());
327 if (unlikely(cmd == NULL)) { 327 if (unlikely(!cmd)) {
328 DRM_ERROR("Failed reserving FIFO space for surface " 328 DRM_ERROR("Failed reserving FIFO space for surface "
329 "destruction.\n"); 329 "destruction.\n");
330 return; 330 return;
@@ -397,7 +397,7 @@ static int vmw_legacy_srf_create(struct vmw_resource *res)
397 397
398 submit_size = vmw_surface_define_size(srf); 398 submit_size = vmw_surface_define_size(srf);
399 cmd = vmw_fifo_reserve(dev_priv, submit_size); 399 cmd = vmw_fifo_reserve(dev_priv, submit_size);
400 if (unlikely(cmd == NULL)) { 400 if (unlikely(!cmd)) {
401 DRM_ERROR("Failed reserving FIFO space for surface " 401 DRM_ERROR("Failed reserving FIFO space for surface "
402 "creation.\n"); 402 "creation.\n");
403 ret = -ENOMEM; 403 ret = -ENOMEM;
@@ -446,11 +446,10 @@ static int vmw_legacy_srf_dma(struct vmw_resource *res,
446 uint8_t *cmd; 446 uint8_t *cmd;
447 struct vmw_private *dev_priv = res->dev_priv; 447 struct vmw_private *dev_priv = res->dev_priv;
448 448
449 BUG_ON(val_buf->bo == NULL); 449 BUG_ON(!val_buf->bo);
450
451 submit_size = vmw_surface_dma_size(srf); 450 submit_size = vmw_surface_dma_size(srf);
452 cmd = vmw_fifo_reserve(dev_priv, submit_size); 451 cmd = vmw_fifo_reserve(dev_priv, submit_size);
453 if (unlikely(cmd == NULL)) { 452 if (unlikely(!cmd)) {
454 DRM_ERROR("Failed reserving FIFO space for surface " 453 DRM_ERROR("Failed reserving FIFO space for surface "
455 "DMA.\n"); 454 "DMA.\n");
456 return -ENOMEM; 455 return -ENOMEM;
@@ -538,7 +537,7 @@ static int vmw_legacy_srf_destroy(struct vmw_resource *res)
538 537
539 submit_size = vmw_surface_destroy_size(); 538 submit_size = vmw_surface_destroy_size();
540 cmd = vmw_fifo_reserve(dev_priv, submit_size); 539 cmd = vmw_fifo_reserve(dev_priv, submit_size);
541 if (unlikely(cmd == NULL)) { 540 if (unlikely(!cmd)) {
542 DRM_ERROR("Failed reserving FIFO space for surface " 541 DRM_ERROR("Failed reserving FIFO space for surface "
543 "eviction.\n"); 542 "eviction.\n");
544 return -ENOMEM; 543 return -ENOMEM;
@@ -578,7 +577,7 @@ static int vmw_surface_init(struct vmw_private *dev_priv,
578 int ret; 577 int ret;
579 struct vmw_resource *res = &srf->res; 578 struct vmw_resource *res = &srf->res;
580 579
581 BUG_ON(res_free == NULL); 580 BUG_ON(!res_free);
582 if (!dev_priv->has_mob) 581 if (!dev_priv->has_mob)
583 vmw_fifo_resource_inc(dev_priv); 582 vmw_fifo_resource_inc(dev_priv);
584 ret = vmw_resource_init(dev_priv, res, true, res_free, 583 ret = vmw_resource_init(dev_priv, res, true, res_free,
@@ -700,7 +699,6 @@ int vmw_surface_define_ioctl(struct drm_device *dev, void *data,
700 struct drm_vmw_surface_create_req *req = &arg->req; 699 struct drm_vmw_surface_create_req *req = &arg->req;
701 struct drm_vmw_surface_arg *rep = &arg->rep; 700 struct drm_vmw_surface_arg *rep = &arg->rep;
702 struct ttm_object_file *tfile = vmw_fpriv(file_priv)->tfile; 701 struct ttm_object_file *tfile = vmw_fpriv(file_priv)->tfile;
703 struct drm_vmw_size __user *user_sizes;
704 int ret; 702 int ret;
705 int i, j; 703 int i, j;
706 uint32_t cur_bo_offset; 704 uint32_t cur_bo_offset;
@@ -748,7 +746,7 @@ int vmw_surface_define_ioctl(struct drm_device *dev, void *data,
748 } 746 }
749 747
750 user_srf = kzalloc(sizeof(*user_srf), GFP_KERNEL); 748 user_srf = kzalloc(sizeof(*user_srf), GFP_KERNEL);
751 if (unlikely(user_srf == NULL)) { 749 if (unlikely(!user_srf)) {
752 ret = -ENOMEM; 750 ret = -ENOMEM;
753 goto out_no_user_srf; 751 goto out_no_user_srf;
754 } 752 }
@@ -763,29 +761,21 @@ int vmw_surface_define_ioctl(struct drm_device *dev, void *data,
763 memcpy(srf->mip_levels, req->mip_levels, sizeof(srf->mip_levels)); 761 memcpy(srf->mip_levels, req->mip_levels, sizeof(srf->mip_levels));
764 srf->num_sizes = num_sizes; 762 srf->num_sizes = num_sizes;
765 user_srf->size = size; 763 user_srf->size = size;
766 764 srf->sizes = memdup_user((struct drm_vmw_size __user *)(unsigned long)
767 srf->sizes = kmalloc(srf->num_sizes * sizeof(*srf->sizes), GFP_KERNEL); 765 req->size_addr,
768 if (unlikely(srf->sizes == NULL)) { 766 sizeof(*srf->sizes) * srf->num_sizes);
769 ret = -ENOMEM; 767 if (IS_ERR(srf->sizes)) {
768 ret = PTR_ERR(srf->sizes);
770 goto out_no_sizes; 769 goto out_no_sizes;
771 } 770 }
772 srf->offsets = kmalloc(srf->num_sizes * sizeof(*srf->offsets), 771 srf->offsets = kmalloc_array(srf->num_sizes,
773 GFP_KERNEL); 772 sizeof(*srf->offsets),
774 if (unlikely(srf->offsets == NULL)) { 773 GFP_KERNEL);
774 if (unlikely(!srf->offsets)) {
775 ret = -ENOMEM; 775 ret = -ENOMEM;
776 goto out_no_offsets; 776 goto out_no_offsets;
777 } 777 }
778 778
779 user_sizes = (struct drm_vmw_size __user *)(unsigned long)
780 req->size_addr;
781
782 ret = copy_from_user(srf->sizes, user_sizes,
783 srf->num_sizes * sizeof(*srf->sizes));
784 if (unlikely(ret != 0)) {
785 ret = -EFAULT;
786 goto out_no_copy;
787 }
788
789 srf->base_size = *srf->sizes; 779 srf->base_size = *srf->sizes;
790 srf->autogen_filter = SVGA3D_TEX_FILTER_NONE; 780 srf->autogen_filter = SVGA3D_TEX_FILTER_NONE;
791 srf->multisample_count = 0; 781 srf->multisample_count = 0;
@@ -923,7 +913,7 @@ vmw_surface_handle_reference(struct vmw_private *dev_priv,
923 913
924 ret = -EINVAL; 914 ret = -EINVAL;
925 base = ttm_base_object_lookup_for_ref(dev_priv->tdev, handle); 915 base = ttm_base_object_lookup_for_ref(dev_priv->tdev, handle);
926 if (unlikely(base == NULL)) { 916 if (unlikely(!base)) {
927 DRM_ERROR("Could not find surface to reference.\n"); 917 DRM_ERROR("Could not find surface to reference.\n");
928 goto out_no_lookup; 918 goto out_no_lookup;
929 } 919 }
@@ -1069,7 +1059,7 @@ static int vmw_gb_surface_create(struct vmw_resource *res)
1069 1059
1070 cmd = vmw_fifo_reserve(dev_priv, submit_len); 1060 cmd = vmw_fifo_reserve(dev_priv, submit_len);
1071 cmd2 = (typeof(cmd2))cmd; 1061 cmd2 = (typeof(cmd2))cmd;
1072 if (unlikely(cmd == NULL)) { 1062 if (unlikely(!cmd)) {
1073 DRM_ERROR("Failed reserving FIFO space for surface " 1063 DRM_ERROR("Failed reserving FIFO space for surface "
1074 "creation.\n"); 1064 "creation.\n");
1075 ret = -ENOMEM; 1065 ret = -ENOMEM;
@@ -1135,7 +1125,7 @@ static int vmw_gb_surface_bind(struct vmw_resource *res,
1135 submit_size = sizeof(*cmd1) + (res->backup_dirty ? sizeof(*cmd2) : 0); 1125 submit_size = sizeof(*cmd1) + (res->backup_dirty ? sizeof(*cmd2) : 0);
1136 1126
1137 cmd1 = vmw_fifo_reserve(dev_priv, submit_size); 1127 cmd1 = vmw_fifo_reserve(dev_priv, submit_size);
1138 if (unlikely(cmd1 == NULL)) { 1128 if (unlikely(!cmd1)) {
1139 DRM_ERROR("Failed reserving FIFO space for surface " 1129 DRM_ERROR("Failed reserving FIFO space for surface "
1140 "binding.\n"); 1130 "binding.\n");
1141 return -ENOMEM; 1131 return -ENOMEM;
@@ -1185,7 +1175,7 @@ static int vmw_gb_surface_unbind(struct vmw_resource *res,
1185 1175
1186 submit_size = sizeof(*cmd3) + (readback ? sizeof(*cmd1) : sizeof(*cmd2)); 1176 submit_size = sizeof(*cmd3) + (readback ? sizeof(*cmd1) : sizeof(*cmd2));
1187 cmd = vmw_fifo_reserve(dev_priv, submit_size); 1177 cmd = vmw_fifo_reserve(dev_priv, submit_size);
1188 if (unlikely(cmd == NULL)) { 1178 if (unlikely(!cmd)) {
1189 DRM_ERROR("Failed reserving FIFO space for surface " 1179 DRM_ERROR("Failed reserving FIFO space for surface "
1190 "unbinding.\n"); 1180 "unbinding.\n");
1191 return -ENOMEM; 1181 return -ENOMEM;
@@ -1244,7 +1234,7 @@ static int vmw_gb_surface_destroy(struct vmw_resource *res)
1244 vmw_binding_res_list_scrub(&res->binding_head); 1234 vmw_binding_res_list_scrub(&res->binding_head);
1245 1235
1246 cmd = vmw_fifo_reserve(dev_priv, sizeof(*cmd)); 1236 cmd = vmw_fifo_reserve(dev_priv, sizeof(*cmd));
1247 if (unlikely(cmd == NULL)) { 1237 if (unlikely(!cmd)) {
1248 DRM_ERROR("Failed reserving FIFO space for surface " 1238 DRM_ERROR("Failed reserving FIFO space for surface "
1249 "destruction.\n"); 1239 "destruction.\n");
1250 mutex_unlock(&dev_priv->binding_mutex); 1240 mutex_unlock(&dev_priv->binding_mutex);
@@ -1410,7 +1400,7 @@ int vmw_gb_surface_reference_ioctl(struct drm_device *dev, void *data,
1410 1400
1411 user_srf = container_of(base, struct vmw_user_surface, prime.base); 1401 user_srf = container_of(base, struct vmw_user_surface, prime.base);
1412 srf = &user_srf->srf; 1402 srf = &user_srf->srf;
1413 if (srf->res.backup == NULL) { 1403 if (!srf->res.backup) {
1414 DRM_ERROR("Shared GB surface is missing a backup buffer.\n"); 1404 DRM_ERROR("Shared GB surface is missing a backup buffer.\n");
1415 goto out_bad_resource; 1405 goto out_bad_resource;
1416 } 1406 }
@@ -1524,7 +1514,7 @@ int vmw_surface_gb_priv_define(struct drm_device *dev,
1524 } 1514 }
1525 1515
1526 user_srf = kzalloc(sizeof(*user_srf), GFP_KERNEL); 1516 user_srf = kzalloc(sizeof(*user_srf), GFP_KERNEL);
1527 if (unlikely(user_srf == NULL)) { 1517 if (unlikely(!user_srf)) {
1528 ret = -ENOMEM; 1518 ret = -ENOMEM;
1529 goto out_no_user_srf; 1519 goto out_no_user_srf;
1530 } 1520 }
diff --git a/drivers/gpu/ipu-v3/ipu-image-convert.c b/drivers/gpu/ipu-v3/ipu-image-convert.c
index 2ba7d437a2af..805b6fa7b5f4 100644
--- a/drivers/gpu/ipu-v3/ipu-image-convert.c
+++ b/drivers/gpu/ipu-v3/ipu-image-convert.c
@@ -1617,7 +1617,7 @@ ipu_image_convert(struct ipu_soc *ipu, enum ipu_ic_task ic_task,
1617 ctx = ipu_image_convert_prepare(ipu, ic_task, in, out, rot_mode, 1617 ctx = ipu_image_convert_prepare(ipu, ic_task, in, out, rot_mode,
1618 complete, complete_context); 1618 complete, complete_context);
1619 if (IS_ERR(ctx)) 1619 if (IS_ERR(ctx))
1620 return ERR_PTR(PTR_ERR(ctx)); 1620 return ERR_CAST(ctx);
1621 1621
1622 run = kzalloc(sizeof(*run), GFP_KERNEL); 1622 run = kzalloc(sizeof(*run), GFP_KERNEL);
1623 if (!run) { 1623 if (!run) {
diff --git a/drivers/hid/hid-cp2112.c b/drivers/hid/hid-cp2112.c
index 086d8a507157..60d30203a5fa 100644
--- a/drivers/hid/hid-cp2112.c
+++ b/drivers/hid/hid-cp2112.c
@@ -32,6 +32,11 @@
32#include <linux/usb/ch9.h> 32#include <linux/usb/ch9.h>
33#include "hid-ids.h" 33#include "hid-ids.h"
34 34
35#define CP2112_REPORT_MAX_LENGTH 64
36#define CP2112_GPIO_CONFIG_LENGTH 5
37#define CP2112_GPIO_GET_LENGTH 2
38#define CP2112_GPIO_SET_LENGTH 3
39
35enum { 40enum {
36 CP2112_GPIO_CONFIG = 0x02, 41 CP2112_GPIO_CONFIG = 0x02,
37 CP2112_GPIO_GET = 0x03, 42 CP2112_GPIO_GET = 0x03,
@@ -161,6 +166,8 @@ struct cp2112_device {
161 atomic_t read_avail; 166 atomic_t read_avail;
162 atomic_t xfer_avail; 167 atomic_t xfer_avail;
163 struct gpio_chip gc; 168 struct gpio_chip gc;
169 u8 *in_out_buffer;
170 spinlock_t lock;
164}; 171};
165 172
166static int gpio_push_pull = 0xFF; 173static int gpio_push_pull = 0xFF;
@@ -171,62 +178,86 @@ static int cp2112_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
171{ 178{
172 struct cp2112_device *dev = gpiochip_get_data(chip); 179 struct cp2112_device *dev = gpiochip_get_data(chip);
173 struct hid_device *hdev = dev->hdev; 180 struct hid_device *hdev = dev->hdev;
174 u8 buf[5]; 181 u8 *buf = dev->in_out_buffer;
182 unsigned long flags;
175 int ret; 183 int ret;
176 184
185 spin_lock_irqsave(&dev->lock, flags);
186
177 ret = hid_hw_raw_request(hdev, CP2112_GPIO_CONFIG, buf, 187 ret = hid_hw_raw_request(hdev, CP2112_GPIO_CONFIG, buf,
178 sizeof(buf), HID_FEATURE_REPORT, 188 CP2112_GPIO_CONFIG_LENGTH, HID_FEATURE_REPORT,
179 HID_REQ_GET_REPORT); 189 HID_REQ_GET_REPORT);
180 if (ret != sizeof(buf)) { 190 if (ret != CP2112_GPIO_CONFIG_LENGTH) {
181 hid_err(hdev, "error requesting GPIO config: %d\n", ret); 191 hid_err(hdev, "error requesting GPIO config: %d\n", ret);
182 return ret; 192 goto exit;
183 } 193 }
184 194
185 buf[1] &= ~(1 << offset); 195 buf[1] &= ~(1 << offset);
186 buf[2] = gpio_push_pull; 196 buf[2] = gpio_push_pull;
187 197
188 ret = hid_hw_raw_request(hdev, CP2112_GPIO_CONFIG, buf, sizeof(buf), 198 ret = hid_hw_raw_request(hdev, CP2112_GPIO_CONFIG, buf,
189 HID_FEATURE_REPORT, HID_REQ_SET_REPORT); 199 CP2112_GPIO_CONFIG_LENGTH, HID_FEATURE_REPORT,
200 HID_REQ_SET_REPORT);
190 if (ret < 0) { 201 if (ret < 0) {
191 hid_err(hdev, "error setting GPIO config: %d\n", ret); 202 hid_err(hdev, "error setting GPIO config: %d\n", ret);
192 return ret; 203 goto exit;
193 } 204 }
194 205
195 return 0; 206 ret = 0;
207
208exit:
209 spin_unlock_irqrestore(&dev->lock, flags);
210 return ret <= 0 ? ret : -EIO;
196} 211}
197 212
198static void cp2112_gpio_set(struct gpio_chip *chip, unsigned offset, int value) 213static void cp2112_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
199{ 214{
200 struct cp2112_device *dev = gpiochip_get_data(chip); 215 struct cp2112_device *dev = gpiochip_get_data(chip);
201 struct hid_device *hdev = dev->hdev; 216 struct hid_device *hdev = dev->hdev;
202 u8 buf[3]; 217 u8 *buf = dev->in_out_buffer;
218 unsigned long flags;
203 int ret; 219 int ret;
204 220
221 spin_lock_irqsave(&dev->lock, flags);
222
205 buf[0] = CP2112_GPIO_SET; 223 buf[0] = CP2112_GPIO_SET;
206 buf[1] = value ? 0xff : 0; 224 buf[1] = value ? 0xff : 0;
207 buf[2] = 1 << offset; 225 buf[2] = 1 << offset;
208 226
209 ret = hid_hw_raw_request(hdev, CP2112_GPIO_SET, buf, sizeof(buf), 227 ret = hid_hw_raw_request(hdev, CP2112_GPIO_SET, buf,
210 HID_FEATURE_REPORT, HID_REQ_SET_REPORT); 228 CP2112_GPIO_SET_LENGTH, HID_FEATURE_REPORT,
229 HID_REQ_SET_REPORT);
211 if (ret < 0) 230 if (ret < 0)
212 hid_err(hdev, "error setting GPIO values: %d\n", ret); 231 hid_err(hdev, "error setting GPIO values: %d\n", ret);
232
233 spin_unlock_irqrestore(&dev->lock, flags);
213} 234}
214 235
215static int cp2112_gpio_get(struct gpio_chip *chip, unsigned offset) 236static int cp2112_gpio_get(struct gpio_chip *chip, unsigned offset)
216{ 237{
217 struct cp2112_device *dev = gpiochip_get_data(chip); 238 struct cp2112_device *dev = gpiochip_get_data(chip);
218 struct hid_device *hdev = dev->hdev; 239 struct hid_device *hdev = dev->hdev;
219 u8 buf[2]; 240 u8 *buf = dev->in_out_buffer;
241 unsigned long flags;
220 int ret; 242 int ret;
221 243
222 ret = hid_hw_raw_request(hdev, CP2112_GPIO_GET, buf, sizeof(buf), 244 spin_lock_irqsave(&dev->lock, flags);
223 HID_FEATURE_REPORT, HID_REQ_GET_REPORT); 245
224 if (ret != sizeof(buf)) { 246 ret = hid_hw_raw_request(hdev, CP2112_GPIO_GET, buf,
247 CP2112_GPIO_GET_LENGTH, HID_FEATURE_REPORT,
248 HID_REQ_GET_REPORT);
249 if (ret != CP2112_GPIO_GET_LENGTH) {
225 hid_err(hdev, "error requesting GPIO values: %d\n", ret); 250 hid_err(hdev, "error requesting GPIO values: %d\n", ret);
226 return ret; 251 ret = ret < 0 ? ret : -EIO;
252 goto exit;
227 } 253 }
228 254
229 return (buf[1] >> offset) & 1; 255 ret = (buf[1] >> offset) & 1;
256
257exit:
258 spin_unlock_irqrestore(&dev->lock, flags);
259
260 return ret;
230} 261}
231 262
232static int cp2112_gpio_direction_output(struct gpio_chip *chip, 263static int cp2112_gpio_direction_output(struct gpio_chip *chip,
@@ -234,27 +265,33 @@ static int cp2112_gpio_direction_output(struct gpio_chip *chip,
234{ 265{
235 struct cp2112_device *dev = gpiochip_get_data(chip); 266 struct cp2112_device *dev = gpiochip_get_data(chip);
236 struct hid_device *hdev = dev->hdev; 267 struct hid_device *hdev = dev->hdev;
237 u8 buf[5]; 268 u8 *buf = dev->in_out_buffer;
269 unsigned long flags;
238 int ret; 270 int ret;
239 271
272 spin_lock_irqsave(&dev->lock, flags);
273
240 ret = hid_hw_raw_request(hdev, CP2112_GPIO_CONFIG, buf, 274 ret = hid_hw_raw_request(hdev, CP2112_GPIO_CONFIG, buf,
241 sizeof(buf), HID_FEATURE_REPORT, 275 CP2112_GPIO_CONFIG_LENGTH, HID_FEATURE_REPORT,
242 HID_REQ_GET_REPORT); 276 HID_REQ_GET_REPORT);
243 if (ret != sizeof(buf)) { 277 if (ret != CP2112_GPIO_CONFIG_LENGTH) {
244 hid_err(hdev, "error requesting GPIO config: %d\n", ret); 278 hid_err(hdev, "error requesting GPIO config: %d\n", ret);
245 return ret; 279 goto fail;
246 } 280 }
247 281
248 buf[1] |= 1 << offset; 282 buf[1] |= 1 << offset;
249 buf[2] = gpio_push_pull; 283 buf[2] = gpio_push_pull;
250 284
251 ret = hid_hw_raw_request(hdev, CP2112_GPIO_CONFIG, buf, sizeof(buf), 285 ret = hid_hw_raw_request(hdev, CP2112_GPIO_CONFIG, buf,
252 HID_FEATURE_REPORT, HID_REQ_SET_REPORT); 286 CP2112_GPIO_CONFIG_LENGTH, HID_FEATURE_REPORT,
287 HID_REQ_SET_REPORT);
253 if (ret < 0) { 288 if (ret < 0) {
254 hid_err(hdev, "error setting GPIO config: %d\n", ret); 289 hid_err(hdev, "error setting GPIO config: %d\n", ret);
255 return ret; 290 goto fail;
256 } 291 }
257 292
293 spin_unlock_irqrestore(&dev->lock, flags);
294
258 /* 295 /*
259 * Set gpio value when output direction is already set, 296 * Set gpio value when output direction is already set,
260 * as specified in AN495, Rev. 0.2, cpt. 4.4 297 * as specified in AN495, Rev. 0.2, cpt. 4.4
@@ -262,6 +299,10 @@ static int cp2112_gpio_direction_output(struct gpio_chip *chip,
262 cp2112_gpio_set(chip, offset, value); 299 cp2112_gpio_set(chip, offset, value);
263 300
264 return 0; 301 return 0;
302
303fail:
304 spin_unlock_irqrestore(&dev->lock, flags);
305 return ret < 0 ? ret : -EIO;
265} 306}
266 307
267static int cp2112_hid_get(struct hid_device *hdev, unsigned char report_number, 308static int cp2112_hid_get(struct hid_device *hdev, unsigned char report_number,
@@ -1007,6 +1048,17 @@ static int cp2112_probe(struct hid_device *hdev, const struct hid_device_id *id)
1007 struct cp2112_smbus_config_report config; 1048 struct cp2112_smbus_config_report config;
1008 int ret; 1049 int ret;
1009 1050
1051 dev = devm_kzalloc(&hdev->dev, sizeof(*dev), GFP_KERNEL);
1052 if (!dev)
1053 return -ENOMEM;
1054
1055 dev->in_out_buffer = devm_kzalloc(&hdev->dev, CP2112_REPORT_MAX_LENGTH,
1056 GFP_KERNEL);
1057 if (!dev->in_out_buffer)
1058 return -ENOMEM;
1059
1060 spin_lock_init(&dev->lock);
1061
1010 ret = hid_parse(hdev); 1062 ret = hid_parse(hdev);
1011 if (ret) { 1063 if (ret) {
1012 hid_err(hdev, "parse failed\n"); 1064 hid_err(hdev, "parse failed\n");
@@ -1063,12 +1115,6 @@ static int cp2112_probe(struct hid_device *hdev, const struct hid_device_id *id)
1063 goto err_power_normal; 1115 goto err_power_normal;
1064 } 1116 }
1065 1117
1066 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
1067 if (!dev) {
1068 ret = -ENOMEM;
1069 goto err_power_normal;
1070 }
1071
1072 hid_set_drvdata(hdev, (void *)dev); 1118 hid_set_drvdata(hdev, (void *)dev);
1073 dev->hdev = hdev; 1119 dev->hdev = hdev;
1074 dev->adap.owner = THIS_MODULE; 1120 dev->adap.owner = THIS_MODULE;
@@ -1087,7 +1133,7 @@ static int cp2112_probe(struct hid_device *hdev, const struct hid_device_id *id)
1087 1133
1088 if (ret) { 1134 if (ret) {
1089 hid_err(hdev, "error registering i2c adapter\n"); 1135 hid_err(hdev, "error registering i2c adapter\n");
1090 goto err_free_dev; 1136 goto err_power_normal;
1091 } 1137 }
1092 1138
1093 hid_dbg(hdev, "adapter registered\n"); 1139 hid_dbg(hdev, "adapter registered\n");
@@ -1123,8 +1169,6 @@ err_gpiochip_remove:
1123 gpiochip_remove(&dev->gc); 1169 gpiochip_remove(&dev->gc);
1124err_free_i2c: 1170err_free_i2c:
1125 i2c_del_adapter(&dev->adap); 1171 i2c_del_adapter(&dev->adap);
1126err_free_dev:
1127 kfree(dev);
1128err_power_normal: 1172err_power_normal:
1129 hid_hw_power(hdev, PM_HINT_NORMAL); 1173 hid_hw_power(hdev, PM_HINT_NORMAL);
1130err_hid_close: 1174err_hid_close:
@@ -1149,7 +1193,6 @@ static void cp2112_remove(struct hid_device *hdev)
1149 */ 1193 */
1150 hid_hw_close(hdev); 1194 hid_hw_close(hdev);
1151 hid_hw_stop(hdev); 1195 hid_hw_stop(hdev);
1152 kfree(dev);
1153} 1196}
1154 1197
1155static int cp2112_raw_event(struct hid_device *hdev, struct hid_report *report, 1198static int cp2112_raw_event(struct hid_device *hdev, struct hid_report *report,
diff --git a/drivers/hid/hid-dr.c b/drivers/hid/hid-dr.c
index 8fd4bf77f264..818ea7d93533 100644
--- a/drivers/hid/hid-dr.c
+++ b/drivers/hid/hid-dr.c
@@ -234,58 +234,6 @@ static __u8 pid0011_rdesc_fixed[] = {
234 0xC0 /* End Collection */ 234 0xC0 /* End Collection */
235}; 235};
236 236
237static __u8 pid0006_rdesc_fixed[] = {
238 0x05, 0x01, /* Usage Page (Generic Desktop) */
239 0x09, 0x04, /* Usage (Joystick) */
240 0xA1, 0x01, /* Collection (Application) */
241 0xA1, 0x02, /* Collection (Logical) */
242 0x75, 0x08, /* Report Size (8) */
243 0x95, 0x05, /* Report Count (5) */
244 0x15, 0x00, /* Logical Minimum (0) */
245 0x26, 0xFF, 0x00, /* Logical Maximum (255) */
246 0x35, 0x00, /* Physical Minimum (0) */
247 0x46, 0xFF, 0x00, /* Physical Maximum (255) */
248 0x09, 0x30, /* Usage (X) */
249 0x09, 0x33, /* Usage (Ry) */
250 0x09, 0x32, /* Usage (Z) */
251 0x09, 0x31, /* Usage (Y) */
252 0x09, 0x34, /* Usage (Ry) */
253 0x81, 0x02, /* Input (Variable) */
254 0x75, 0x04, /* Report Size (4) */
255 0x95, 0x01, /* Report Count (1) */
256 0x25, 0x07, /* Logical Maximum (7) */
257 0x46, 0x3B, 0x01, /* Physical Maximum (315) */
258 0x65, 0x14, /* Unit (Centimeter) */
259 0x09, 0x39, /* Usage (Hat switch) */
260 0x81, 0x42, /* Input (Variable) */
261 0x65, 0x00, /* Unit (None) */
262 0x75, 0x01, /* Report Size (1) */
263 0x95, 0x0C, /* Report Count (12) */
264 0x25, 0x01, /* Logical Maximum (1) */
265 0x45, 0x01, /* Physical Maximum (1) */
266 0x05, 0x09, /* Usage Page (Button) */
267 0x19, 0x01, /* Usage Minimum (0x01) */
268 0x29, 0x0C, /* Usage Maximum (0x0C) */
269 0x81, 0x02, /* Input (Variable) */
270 0x06, 0x00, 0xFF, /* Usage Page (Vendor Defined) */
271 0x75, 0x01, /* Report Size (1) */
272 0x95, 0x08, /* Report Count (8) */
273 0x25, 0x01, /* Logical Maximum (1) */
274 0x45, 0x01, /* Physical Maximum (1) */
275 0x09, 0x01, /* Usage (0x01) */
276 0x81, 0x02, /* Input (Variable) */
277 0xC0, /* End Collection */
278 0xA1, 0x02, /* Collection (Logical) */
279 0x75, 0x08, /* Report Size (8) */
280 0x95, 0x07, /* Report Count (7) */
281 0x46, 0xFF, 0x00, /* Physical Maximum (255) */
282 0x26, 0xFF, 0x00, /* Logical Maximum (255) */
283 0x09, 0x02, /* Usage (0x02) */
284 0x91, 0x02, /* Output (Variable) */
285 0xC0, /* End Collection */
286 0xC0 /* End Collection */
287};
288
289static __u8 *dr_report_fixup(struct hid_device *hdev, __u8 *rdesc, 237static __u8 *dr_report_fixup(struct hid_device *hdev, __u8 *rdesc,
290 unsigned int *rsize) 238 unsigned int *rsize)
291{ 239{
@@ -296,16 +244,34 @@ static __u8 *dr_report_fixup(struct hid_device *hdev, __u8 *rdesc,
296 *rsize = sizeof(pid0011_rdesc_fixed); 244 *rsize = sizeof(pid0011_rdesc_fixed);
297 } 245 }
298 break; 246 break;
299 case 0x0006:
300 if (*rsize == sizeof(pid0006_rdesc_fixed)) {
301 rdesc = pid0006_rdesc_fixed;
302 *rsize = sizeof(pid0006_rdesc_fixed);
303 }
304 break;
305 } 247 }
306 return rdesc; 248 return rdesc;
307} 249}
308 250
251#define map_abs(c) hid_map_usage(hi, usage, bit, max, EV_ABS, (c))
252#define map_rel(c) hid_map_usage(hi, usage, bit, max, EV_REL, (c))
253
254static int dr_input_mapping(struct hid_device *hdev, struct hid_input *hi,
255 struct hid_field *field, struct hid_usage *usage,
256 unsigned long **bit, int *max)
257{
258 switch (usage->hid) {
259 /*
260 * revert to the old hid-input behavior where axes
261 * can be randomly assigned when hid->usage is reused.
262 */
263 case HID_GD_X: case HID_GD_Y: case HID_GD_Z:
264 case HID_GD_RX: case HID_GD_RY: case HID_GD_RZ:
265 if (field->flags & HID_MAIN_ITEM_RELATIVE)
266 map_rel(usage->hid & 0xf);
267 else
268 map_abs(usage->hid & 0xf);
269 return 1;
270 }
271
272 return 0;
273}
274
309static int dr_probe(struct hid_device *hdev, const struct hid_device_id *id) 275static int dr_probe(struct hid_device *hdev, const struct hid_device_id *id)
310{ 276{
311 int ret; 277 int ret;
@@ -352,6 +318,7 @@ static struct hid_driver dr_driver = {
352 .id_table = dr_devices, 318 .id_table = dr_devices,
353 .report_fixup = dr_report_fixup, 319 .report_fixup = dr_report_fixup,
354 .probe = dr_probe, 320 .probe = dr_probe,
321 .input_mapping = dr_input_mapping,
355}; 322};
356module_hid_driver(dr_driver); 323module_hid_driver(dr_driver);
357 324
diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
index cd59c79eebdd..575aa65436d1 100644
--- a/drivers/hid/hid-ids.h
+++ b/drivers/hid/hid-ids.h
@@ -64,6 +64,9 @@
64#define USB_VENDOR_ID_AKAI 0x2011 64#define USB_VENDOR_ID_AKAI 0x2011
65#define USB_DEVICE_ID_AKAI_MPKMINI2 0x0715 65#define USB_DEVICE_ID_AKAI_MPKMINI2 0x0715
66 66
67#define USB_VENDOR_ID_AKAI_09E8 0x09E8
68#define USB_DEVICE_ID_AKAI_09E8_MIDIMIX 0x0031
69
67#define USB_VENDOR_ID_ALCOR 0x058f 70#define USB_VENDOR_ID_ALCOR 0x058f
68#define USB_DEVICE_ID_ALCOR_USBRS232 0x9720 71#define USB_DEVICE_ID_ALCOR_USBRS232 0x9720
69 72
@@ -176,6 +179,7 @@
176#define USB_DEVICE_ID_ATEN_4PORTKVM 0x2205 179#define USB_DEVICE_ID_ATEN_4PORTKVM 0x2205
177#define USB_DEVICE_ID_ATEN_4PORTKVMC 0x2208 180#define USB_DEVICE_ID_ATEN_4PORTKVMC 0x2208
178#define USB_DEVICE_ID_ATEN_CS682 0x2213 181#define USB_DEVICE_ID_ATEN_CS682 0x2213
182#define USB_DEVICE_ID_ATEN_CS692 0x8021
179 183
180#define USB_VENDOR_ID_ATMEL 0x03eb 184#define USB_VENDOR_ID_ATMEL 0x03eb
181#define USB_DEVICE_ID_ATMEL_MULTITOUCH 0x211c 185#define USB_DEVICE_ID_ATMEL_MULTITOUCH 0x211c
diff --git a/drivers/hid/hid-led.c b/drivers/hid/hid-led.c
index d8d55f37b4f5..d3e1ab162f7c 100644
--- a/drivers/hid/hid-led.c
+++ b/drivers/hid/hid-led.c
@@ -100,6 +100,7 @@ struct hidled_device {
100 const struct hidled_config *config; 100 const struct hidled_config *config;
101 struct hid_device *hdev; 101 struct hid_device *hdev;
102 struct hidled_rgb *rgb; 102 struct hidled_rgb *rgb;
103 u8 *buf;
103 struct mutex lock; 104 struct mutex lock;
104}; 105};
105 106
@@ -118,13 +119,19 @@ static int hidled_send(struct hidled_device *ldev, __u8 *buf)
118 119
119 mutex_lock(&ldev->lock); 120 mutex_lock(&ldev->lock);
120 121
122 /*
123 * buffer provided to hid_hw_raw_request must not be on the stack
124 * and must not be part of a data structure
125 */
126 memcpy(ldev->buf, buf, ldev->config->report_size);
127
121 if (ldev->config->report_type == RAW_REQUEST) 128 if (ldev->config->report_type == RAW_REQUEST)
122 ret = hid_hw_raw_request(ldev->hdev, buf[0], buf, 129 ret = hid_hw_raw_request(ldev->hdev, buf[0], ldev->buf,
123 ldev->config->report_size, 130 ldev->config->report_size,
124 HID_FEATURE_REPORT, 131 HID_FEATURE_REPORT,
125 HID_REQ_SET_REPORT); 132 HID_REQ_SET_REPORT);
126 else if (ldev->config->report_type == OUTPUT_REPORT) 133 else if (ldev->config->report_type == OUTPUT_REPORT)
127 ret = hid_hw_output_report(ldev->hdev, buf, 134 ret = hid_hw_output_report(ldev->hdev, ldev->buf,
128 ldev->config->report_size); 135 ldev->config->report_size);
129 else 136 else
130 ret = -EINVAL; 137 ret = -EINVAL;
@@ -147,17 +154,21 @@ static int hidled_recv(struct hidled_device *ldev, __u8 *buf)
147 154
148 mutex_lock(&ldev->lock); 155 mutex_lock(&ldev->lock);
149 156
150 ret = hid_hw_raw_request(ldev->hdev, buf[0], buf, 157 memcpy(ldev->buf, buf, ldev->config->report_size);
158
159 ret = hid_hw_raw_request(ldev->hdev, buf[0], ldev->buf,
151 ldev->config->report_size, 160 ldev->config->report_size,
152 HID_FEATURE_REPORT, 161 HID_FEATURE_REPORT,
153 HID_REQ_SET_REPORT); 162 HID_REQ_SET_REPORT);
154 if (ret < 0) 163 if (ret < 0)
155 goto err; 164 goto err;
156 165
157 ret = hid_hw_raw_request(ldev->hdev, buf[0], buf, 166 ret = hid_hw_raw_request(ldev->hdev, buf[0], ldev->buf,
158 ldev->config->report_size, 167 ldev->config->report_size,
159 HID_FEATURE_REPORT, 168 HID_FEATURE_REPORT,
160 HID_REQ_GET_REPORT); 169 HID_REQ_GET_REPORT);
170
171 memcpy(buf, ldev->buf, ldev->config->report_size);
161err: 172err:
162 mutex_unlock(&ldev->lock); 173 mutex_unlock(&ldev->lock);
163 174
@@ -447,6 +458,10 @@ static int hidled_probe(struct hid_device *hdev, const struct hid_device_id *id)
447 if (!ldev) 458 if (!ldev)
448 return -ENOMEM; 459 return -ENOMEM;
449 460
461 ldev->buf = devm_kmalloc(&hdev->dev, MAX_REPORT_SIZE, GFP_KERNEL);
462 if (!ldev->buf)
463 return -ENOMEM;
464
450 ret = hid_parse(hdev); 465 ret = hid_parse(hdev);
451 if (ret) 466 if (ret)
452 return ret; 467 return ret;
diff --git a/drivers/hid/hid-lg.c b/drivers/hid/hid-lg.c
index 76f644deb0a7..c5c5fbe9d605 100644
--- a/drivers/hid/hid-lg.c
+++ b/drivers/hid/hid-lg.c
@@ -756,11 +756,16 @@ static int lg_probe(struct hid_device *hdev, const struct hid_device_id *id)
756 756
757 /* Setup wireless link with Logitech Wii wheel */ 757 /* Setup wireless link with Logitech Wii wheel */
758 if (hdev->product == USB_DEVICE_ID_LOGITECH_WII_WHEEL) { 758 if (hdev->product == USB_DEVICE_ID_LOGITECH_WII_WHEEL) {
759 unsigned char buf[] = { 0x00, 0xAF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; 759 const unsigned char cbuf[] = { 0x00, 0xAF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
760 u8 *buf = kmemdup(cbuf, sizeof(cbuf), GFP_KERNEL);
760 761
761 ret = hid_hw_raw_request(hdev, buf[0], buf, sizeof(buf), 762 if (!buf) {
762 HID_FEATURE_REPORT, HID_REQ_SET_REPORT); 763 ret = -ENOMEM;
764 goto err_free;
765 }
763 766
767 ret = hid_hw_raw_request(hdev, buf[0], buf, sizeof(cbuf),
768 HID_FEATURE_REPORT, HID_REQ_SET_REPORT);
764 if (ret >= 0) { 769 if (ret >= 0) {
765 /* insert a little delay of 10 jiffies ~ 40ms */ 770 /* insert a little delay of 10 jiffies ~ 40ms */
766 wait_queue_head_t wait; 771 wait_queue_head_t wait;
@@ -772,9 +777,10 @@ static int lg_probe(struct hid_device *hdev, const struct hid_device_id *id)
772 buf[1] = 0xB2; 777 buf[1] = 0xB2;
773 get_random_bytes(&buf[2], 2); 778 get_random_bytes(&buf[2], 2);
774 779
775 ret = hid_hw_raw_request(hdev, buf[0], buf, sizeof(buf), 780 ret = hid_hw_raw_request(hdev, buf[0], buf, sizeof(cbuf),
776 HID_FEATURE_REPORT, HID_REQ_SET_REPORT); 781 HID_FEATURE_REPORT, HID_REQ_SET_REPORT);
777 } 782 }
783 kfree(buf);
778 } 784 }
779 785
780 if (drv_data->quirks & LG_FF) 786 if (drv_data->quirks & LG_FF)
diff --git a/drivers/hid/hid-magicmouse.c b/drivers/hid/hid-magicmouse.c
index d6fa496d0ca2..20b40ad26325 100644
--- a/drivers/hid/hid-magicmouse.c
+++ b/drivers/hid/hid-magicmouse.c
@@ -493,7 +493,8 @@ static int magicmouse_input_configured(struct hid_device *hdev,
493static int magicmouse_probe(struct hid_device *hdev, 493static int magicmouse_probe(struct hid_device *hdev,
494 const struct hid_device_id *id) 494 const struct hid_device_id *id)
495{ 495{
496 __u8 feature[] = { 0xd7, 0x01 }; 496 const u8 feature[] = { 0xd7, 0x01 };
497 u8 *buf;
497 struct magicmouse_sc *msc; 498 struct magicmouse_sc *msc;
498 struct hid_report *report; 499 struct hid_report *report;
499 int ret; 500 int ret;
@@ -544,6 +545,12 @@ static int magicmouse_probe(struct hid_device *hdev,
544 } 545 }
545 report->size = 6; 546 report->size = 6;
546 547
548 buf = kmemdup(feature, sizeof(feature), GFP_KERNEL);
549 if (!buf) {
550 ret = -ENOMEM;
551 goto err_stop_hw;
552 }
553
547 /* 554 /*
548 * Some devices repond with 'invalid report id' when feature 555 * Some devices repond with 'invalid report id' when feature
549 * report switching it into multitouch mode is sent to it. 556 * report switching it into multitouch mode is sent to it.
@@ -552,8 +559,9 @@ static int magicmouse_probe(struct hid_device *hdev,
552 * but there seems to be no other way of switching the mode. 559 * but there seems to be no other way of switching the mode.
553 * Thus the super-ugly hacky success check below. 560 * Thus the super-ugly hacky success check below.
554 */ 561 */
555 ret = hid_hw_raw_request(hdev, feature[0], feature, sizeof(feature), 562 ret = hid_hw_raw_request(hdev, buf[0], buf, sizeof(feature),
556 HID_FEATURE_REPORT, HID_REQ_SET_REPORT); 563 HID_FEATURE_REPORT, HID_REQ_SET_REPORT);
564 kfree(buf);
557 if (ret != -EIO && ret != sizeof(feature)) { 565 if (ret != -EIO && ret != sizeof(feature)) {
558 hid_err(hdev, "unable to request touch data (%d)\n", ret); 566 hid_err(hdev, "unable to request touch data (%d)\n", ret);
559 goto err_stop_hw; 567 goto err_stop_hw;
diff --git a/drivers/hid/hid-rmi.c b/drivers/hid/hid-rmi.c
index 9cd2ca34a6be..be89bcbf6a71 100644
--- a/drivers/hid/hid-rmi.c
+++ b/drivers/hid/hid-rmi.c
@@ -188,10 +188,16 @@ static int rmi_set_page(struct hid_device *hdev, u8 page)
188static int rmi_set_mode(struct hid_device *hdev, u8 mode) 188static int rmi_set_mode(struct hid_device *hdev, u8 mode)
189{ 189{
190 int ret; 190 int ret;
191 u8 txbuf[2] = {RMI_SET_RMI_MODE_REPORT_ID, mode}; 191 const u8 txbuf[2] = {RMI_SET_RMI_MODE_REPORT_ID, mode};
192 u8 *buf;
192 193
193 ret = hid_hw_raw_request(hdev, RMI_SET_RMI_MODE_REPORT_ID, txbuf, 194 buf = kmemdup(txbuf, sizeof(txbuf), GFP_KERNEL);
195 if (!buf)
196 return -ENOMEM;
197
198 ret = hid_hw_raw_request(hdev, RMI_SET_RMI_MODE_REPORT_ID, buf,
194 sizeof(txbuf), HID_FEATURE_REPORT, HID_REQ_SET_REPORT); 199 sizeof(txbuf), HID_FEATURE_REPORT, HID_REQ_SET_REPORT);
200 kfree(buf);
195 if (ret < 0) { 201 if (ret < 0) {
196 dev_err(&hdev->dev, "unable to set rmi mode to %d (%d)\n", mode, 202 dev_err(&hdev->dev, "unable to set rmi mode to %d (%d)\n", mode,
197 ret); 203 ret);
diff --git a/drivers/hid/hid-sensor-custom.c b/drivers/hid/hid-sensor-custom.c
index 5614fee82347..3a84aaf1418b 100644
--- a/drivers/hid/hid-sensor-custom.c
+++ b/drivers/hid/hid-sensor-custom.c
@@ -292,11 +292,11 @@ static ssize_t show_value(struct device *dev, struct device_attribute *attr,
292 bool input = false; 292 bool input = false;
293 int value = 0; 293 int value = 0;
294 294
295 if (sscanf(attr->attr.name, "feature-%d-%x-%s", &index, &usage, 295 if (sscanf(attr->attr.name, "feature-%x-%x-%s", &index, &usage,
296 name) == 3) { 296 name) == 3) {
297 feature = true; 297 feature = true;
298 field_index = index + sensor_inst->input_field_count; 298 field_index = index + sensor_inst->input_field_count;
299 } else if (sscanf(attr->attr.name, "input-%d-%x-%s", &index, &usage, 299 } else if (sscanf(attr->attr.name, "input-%x-%x-%s", &index, &usage,
300 name) == 3) { 300 name) == 3) {
301 input = true; 301 input = true;
302 field_index = index; 302 field_index = index;
@@ -398,7 +398,7 @@ static ssize_t store_value(struct device *dev, struct device_attribute *attr,
398 char name[HID_CUSTOM_NAME_LENGTH]; 398 char name[HID_CUSTOM_NAME_LENGTH];
399 int value; 399 int value;
400 400
401 if (sscanf(attr->attr.name, "feature-%d-%x-%s", &index, &usage, 401 if (sscanf(attr->attr.name, "feature-%x-%x-%s", &index, &usage,
402 name) == 3) { 402 name) == 3) {
403 field_index = index + sensor_inst->input_field_count; 403 field_index = index + sensor_inst->input_field_count;
404 } else 404 } else
diff --git a/drivers/hid/hid-sensor-hub.c b/drivers/hid/hid-sensor-hub.c
index 658a607dc6d9..60875625cbdf 100644
--- a/drivers/hid/hid-sensor-hub.c
+++ b/drivers/hid/hid-sensor-hub.c
@@ -212,6 +212,7 @@ int sensor_hub_set_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
212 __s32 value; 212 __s32 value;
213 int ret = 0; 213 int ret = 0;
214 214
215 memset(buffer, 0, buffer_size);
215 mutex_lock(&data->mutex); 216 mutex_lock(&data->mutex);
216 report = sensor_hub_report(report_id, hsdev->hdev, HID_FEATURE_REPORT); 217 report = sensor_hub_report(report_id, hsdev->hdev, HID_FEATURE_REPORT);
217 if (!report || (field_index >= report->maxfield)) { 218 if (!report || (field_index >= report->maxfield)) {
@@ -251,6 +252,9 @@ int sensor_hub_get_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
251 struct sensor_hub_data *data = hid_get_drvdata(hsdev->hdev); 252 struct sensor_hub_data *data = hid_get_drvdata(hsdev->hdev);
252 int report_size; 253 int report_size;
253 int ret = 0; 254 int ret = 0;
255 u8 *val_ptr;
256 int buffer_index = 0;
257 int i;
254 258
255 mutex_lock(&data->mutex); 259 mutex_lock(&data->mutex);
256 report = sensor_hub_report(report_id, hsdev->hdev, HID_FEATURE_REPORT); 260 report = sensor_hub_report(report_id, hsdev->hdev, HID_FEATURE_REPORT);
@@ -271,7 +275,17 @@ int sensor_hub_get_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
271 goto done_proc; 275 goto done_proc;
272 } 276 }
273 ret = min(report_size, buffer_size); 277 ret = min(report_size, buffer_size);
274 memcpy(buffer, report->field[field_index]->value, ret); 278
279 val_ptr = (u8 *)report->field[field_index]->value;
280 for (i = 0; i < report->field[field_index]->report_count; ++i) {
281 if (buffer_index >= ret)
282 break;
283
284 memcpy(&((u8 *)buffer)[buffer_index], val_ptr,
285 report->field[field_index]->report_size / 8);
286 val_ptr += sizeof(__s32);
287 buffer_index += (report->field[field_index]->report_size / 8);
288 }
275 289
276done_proc: 290done_proc:
277 mutex_unlock(&data->mutex); 291 mutex_unlock(&data->mutex);
diff --git a/drivers/hid/intel-ish-hid/ipc/ipc.c b/drivers/hid/intel-ish-hid/ipc/ipc.c
index e2517c11e0ee..0c9ac4d5d850 100644
--- a/drivers/hid/intel-ish-hid/ipc/ipc.c
+++ b/drivers/hid/intel-ish-hid/ipc/ipc.c
@@ -638,6 +638,58 @@ eoi:
638} 638}
639 639
640/** 640/**
641 * ish_disable_dma() - disable dma communication between host and ISHFW
642 * @dev: ishtp device pointer
643 *
644 * Clear the dma enable bit and wait for dma inactive.
645 *
646 * Return: 0 for success else error code.
647 */
648static int ish_disable_dma(struct ishtp_device *dev)
649{
650 unsigned int dma_delay;
651
652 /* Clear the dma enable bit */
653 ish_reg_write(dev, IPC_REG_ISH_RMP2, 0);
654
655 /* wait for dma inactive */
656 for (dma_delay = 0; dma_delay < MAX_DMA_DELAY &&
657 _ish_read_fw_sts_reg(dev) & (IPC_ISH_IN_DMA);
658 dma_delay += 5)
659 mdelay(5);
660
661 if (dma_delay >= MAX_DMA_DELAY) {
662 dev_err(dev->devc,
663 "Wait for DMA inactive timeout\n");
664 return -EBUSY;
665 }
666
667 return 0;
668}
669
670/**
671 * ish_wakeup() - wakeup ishfw from waiting-for-host state
672 * @dev: ishtp device pointer
673 *
674 * Set the dma enable bit and send a void message to FW,
675 * it wil wakeup FW from waiting-for-host state.
676 */
677static void ish_wakeup(struct ishtp_device *dev)
678{
679 /* Set dma enable bit */
680 ish_reg_write(dev, IPC_REG_ISH_RMP2, IPC_RMP2_DMA_ENABLED);
681
682 /*
683 * Send 0 IPC message so that ISH FW wakes up if it was already
684 * asleep.
685 */
686 ish_reg_write(dev, IPC_REG_HOST2ISH_DRBL, IPC_DRBL_BUSY_BIT);
687
688 /* Flush writes to doorbell and REMAP2 */
689 ish_reg_read(dev, IPC_REG_ISH_HOST_FWSTS);
690}
691
692/**
641 * _ish_hw_reset() - HW reset 693 * _ish_hw_reset() - HW reset
642 * @dev: ishtp device pointer 694 * @dev: ishtp device pointer
643 * 695 *
@@ -649,7 +701,6 @@ static int _ish_hw_reset(struct ishtp_device *dev)
649{ 701{
650 struct pci_dev *pdev = dev->pdev; 702 struct pci_dev *pdev = dev->pdev;
651 int rv; 703 int rv;
652 unsigned int dma_delay;
653 uint16_t csr; 704 uint16_t csr;
654 705
655 if (!pdev) 706 if (!pdev)
@@ -664,15 +715,8 @@ static int _ish_hw_reset(struct ishtp_device *dev)
664 return -EINVAL; 715 return -EINVAL;
665 } 716 }
666 717
667 /* Now trigger reset to FW */ 718 /* Disable dma communication between FW and host */
668 ish_reg_write(dev, IPC_REG_ISH_RMP2, 0); 719 if (ish_disable_dma(dev)) {
669
670 for (dma_delay = 0; dma_delay < MAX_DMA_DELAY &&
671 _ish_read_fw_sts_reg(dev) & (IPC_ISH_IN_DMA);
672 dma_delay += 5)
673 mdelay(5);
674
675 if (dma_delay >= MAX_DMA_DELAY) {
676 dev_err(&pdev->dev, 720 dev_err(&pdev->dev,
677 "Can't reset - stuck with DMA in-progress\n"); 721 "Can't reset - stuck with DMA in-progress\n");
678 return -EBUSY; 722 return -EBUSY;
@@ -690,16 +734,8 @@ static int _ish_hw_reset(struct ishtp_device *dev)
690 csr |= PCI_D0; 734 csr |= PCI_D0;
691 pci_write_config_word(pdev, pdev->pm_cap + PCI_PM_CTRL, csr); 735 pci_write_config_word(pdev, pdev->pm_cap + PCI_PM_CTRL, csr);
692 736
693 ish_reg_write(dev, IPC_REG_ISH_RMP2, IPC_RMP2_DMA_ENABLED); 737 /* Now we can enable ISH DMA operation and wakeup ISHFW */
694 738 ish_wakeup(dev);
695 /*
696 * Send 0 IPC message so that ISH FW wakes up if it was already
697 * asleep
698 */
699 ish_reg_write(dev, IPC_REG_HOST2ISH_DRBL, IPC_DRBL_BUSY_BIT);
700
701 /* Flush writes to doorbell and REMAP2 */
702 ish_reg_read(dev, IPC_REG_ISH_HOST_FWSTS);
703 739
704 return 0; 740 return 0;
705} 741}
@@ -758,16 +794,9 @@ static int _ish_ipc_reset(struct ishtp_device *dev)
758int ish_hw_start(struct ishtp_device *dev) 794int ish_hw_start(struct ishtp_device *dev)
759{ 795{
760 ish_set_host_rdy(dev); 796 ish_set_host_rdy(dev);
761 /* After that we can enable ISH DMA operation */
762 ish_reg_write(dev, IPC_REG_ISH_RMP2, IPC_RMP2_DMA_ENABLED);
763 797
764 /* 798 /* After that we can enable ISH DMA operation and wakeup ISHFW */
765 * Send 0 IPC message so that ISH FW wakes up if it was already 799 ish_wakeup(dev);
766 * asleep
767 */
768 ish_reg_write(dev, IPC_REG_HOST2ISH_DRBL, IPC_DRBL_BUSY_BIT);
769 /* Flush write to doorbell */
770 ish_reg_read(dev, IPC_REG_ISH_HOST_FWSTS);
771 800
772 set_host_ready(dev); 801 set_host_ready(dev);
773 802
@@ -876,6 +905,21 @@ struct ishtp_device *ish_dev_init(struct pci_dev *pdev)
876 */ 905 */
877void ish_device_disable(struct ishtp_device *dev) 906void ish_device_disable(struct ishtp_device *dev)
878{ 907{
908 struct pci_dev *pdev = dev->pdev;
909
910 if (!pdev)
911 return;
912
913 /* Disable dma communication between FW and host */
914 if (ish_disable_dma(dev)) {
915 dev_err(&pdev->dev,
916 "Can't reset - stuck with DMA in-progress\n");
917 return;
918 }
919
920 /* Put ISH to D3hot state for power saving */
921 pci_set_power_state(pdev, PCI_D3hot);
922
879 dev->dev_state = ISHTP_DEV_DISABLED; 923 dev->dev_state = ISHTP_DEV_DISABLED;
880 ish_clr_host_rdy(dev); 924 ish_clr_host_rdy(dev);
881} 925}
diff --git a/drivers/hid/intel-ish-hid/ipc/pci-ish.c b/drivers/hid/intel-ish-hid/ipc/pci-ish.c
index 42f0beeb09fd..20d647d2dd2c 100644
--- a/drivers/hid/intel-ish-hid/ipc/pci-ish.c
+++ b/drivers/hid/intel-ish-hid/ipc/pci-ish.c
@@ -146,7 +146,7 @@ static int ish_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
146 pdev->dev_flags |= PCI_DEV_FLAGS_NO_D3; 146 pdev->dev_flags |= PCI_DEV_FLAGS_NO_D3;
147 147
148 /* request and enable interrupt */ 148 /* request and enable interrupt */
149 ret = request_irq(pdev->irq, ish_irq_handler, IRQF_NO_SUSPEND, 149 ret = request_irq(pdev->irq, ish_irq_handler, IRQF_SHARED,
150 KBUILD_MODNAME, dev); 150 KBUILD_MODNAME, dev);
151 if (ret) { 151 if (ret) {
152 dev_err(&pdev->dev, "ISH: request IRQ failure (%d)\n", 152 dev_err(&pdev->dev, "ISH: request IRQ failure (%d)\n",
@@ -202,6 +202,7 @@ static void ish_remove(struct pci_dev *pdev)
202 kfree(ishtp_dev); 202 kfree(ishtp_dev);
203} 203}
204 204
205#ifdef CONFIG_PM
205static struct device *ish_resume_device; 206static struct device *ish_resume_device;
206 207
207/** 208/**
@@ -293,7 +294,6 @@ static int ish_resume(struct device *device)
293 return 0; 294 return 0;
294} 295}
295 296
296#ifdef CONFIG_PM
297static const struct dev_pm_ops ish_pm_ops = { 297static const struct dev_pm_ops ish_pm_ops = {
298 .suspend = ish_suspend, 298 .suspend = ish_suspend,
299 .resume = ish_resume, 299 .resume = ish_resume,
@@ -301,7 +301,7 @@ static const struct dev_pm_ops ish_pm_ops = {
301#define ISHTP_ISH_PM_OPS (&ish_pm_ops) 301#define ISHTP_ISH_PM_OPS (&ish_pm_ops)
302#else 302#else
303#define ISHTP_ISH_PM_OPS NULL 303#define ISHTP_ISH_PM_OPS NULL
304#endif 304#endif /* CONFIG_PM */
305 305
306static struct pci_driver ish_driver = { 306static struct pci_driver ish_driver = {
307 .name = KBUILD_MODNAME, 307 .name = KBUILD_MODNAME,
diff --git a/drivers/hid/usbhid/hid-quirks.c b/drivers/hid/usbhid/hid-quirks.c
index 0a0eca5da47d..e6cfd323babc 100644
--- a/drivers/hid/usbhid/hid-quirks.c
+++ b/drivers/hid/usbhid/hid-quirks.c
@@ -56,12 +56,14 @@ static const struct hid_blacklist {
56 56
57 { USB_VENDOR_ID_AIREN, USB_DEVICE_ID_AIREN_SLIMPLUS, HID_QUIRK_NOGET }, 57 { USB_VENDOR_ID_AIREN, USB_DEVICE_ID_AIREN_SLIMPLUS, HID_QUIRK_NOGET },
58 { USB_VENDOR_ID_AKAI, USB_DEVICE_ID_AKAI_MPKMINI2, HID_QUIRK_NO_INIT_REPORTS }, 58 { USB_VENDOR_ID_AKAI, USB_DEVICE_ID_AKAI_MPKMINI2, HID_QUIRK_NO_INIT_REPORTS },
59 { USB_VENDOR_ID_AKAI_09E8, USB_DEVICE_ID_AKAI_09E8_MIDIMIX, HID_QUIRK_NO_INIT_REPORTS },
59 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_UC100KM, HID_QUIRK_NOGET }, 60 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_UC100KM, HID_QUIRK_NOGET },
60 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_CS124U, HID_QUIRK_NOGET }, 61 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_CS124U, HID_QUIRK_NOGET },
61 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_2PORTKVM, HID_QUIRK_NOGET }, 62 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_2PORTKVM, HID_QUIRK_NOGET },
62 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_4PORTKVM, HID_QUIRK_NOGET }, 63 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_4PORTKVM, HID_QUIRK_NOGET },
63 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_4PORTKVMC, HID_QUIRK_NOGET }, 64 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_4PORTKVMC, HID_QUIRK_NOGET },
64 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_CS682, HID_QUIRK_NOGET }, 65 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_CS682, HID_QUIRK_NOGET },
66 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_CS692, HID_QUIRK_NOGET },
65 { USB_VENDOR_ID_CH, USB_DEVICE_ID_CH_FIGHTERSTICK, HID_QUIRK_NOGET }, 67 { USB_VENDOR_ID_CH, USB_DEVICE_ID_CH_FIGHTERSTICK, HID_QUIRK_NOGET },
66 { USB_VENDOR_ID_CH, USB_DEVICE_ID_CH_COMBATSTICK, HID_QUIRK_NOGET }, 68 { USB_VENDOR_ID_CH, USB_DEVICE_ID_CH_COMBATSTICK, HID_QUIRK_NOGET },
67 { USB_VENDOR_ID_CH, USB_DEVICE_ID_CH_FLIGHT_SIM_ECLIPSE_YOKE, HID_QUIRK_NOGET }, 69 { USB_VENDOR_ID_CH, USB_DEVICE_ID_CH_FLIGHT_SIM_ECLIPSE_YOKE, HID_QUIRK_NOGET },
diff --git a/drivers/hv/hv_util.c b/drivers/hv/hv_util.c
index 4aa3cb63fd41..bcd06306f3e8 100644
--- a/drivers/hv/hv_util.c
+++ b/drivers/hv/hv_util.c
@@ -314,10 +314,14 @@ static void heartbeat_onchannelcallback(void *context)
314 u8 *hbeat_txf_buf = util_heartbeat.recv_buffer; 314 u8 *hbeat_txf_buf = util_heartbeat.recv_buffer;
315 struct icmsg_negotiate *negop = NULL; 315 struct icmsg_negotiate *negop = NULL;
316 316
317 vmbus_recvpacket(channel, hbeat_txf_buf, 317 while (1) {
318 PAGE_SIZE, &recvlen, &requestid); 318
319 vmbus_recvpacket(channel, hbeat_txf_buf,
320 PAGE_SIZE, &recvlen, &requestid);
321
322 if (!recvlen)
323 break;
319 324
320 if (recvlen > 0) {
321 icmsghdrp = (struct icmsg_hdr *)&hbeat_txf_buf[ 325 icmsghdrp = (struct icmsg_hdr *)&hbeat_txf_buf[
322 sizeof(struct vmbuspipe_hdr)]; 326 sizeof(struct vmbuspipe_hdr)];
323 327
diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
index a259e18d22d5..0276d2ef06ee 100644
--- a/drivers/hv/vmbus_drv.c
+++ b/drivers/hv/vmbus_drv.c
@@ -961,7 +961,7 @@ int vmbus_device_register(struct hv_device *child_device_obj)
961{ 961{
962 int ret = 0; 962 int ret = 0;
963 963
964 dev_set_name(&child_device_obj->device, "vmbus-%pUl", 964 dev_set_name(&child_device_obj->device, "%pUl",
965 child_device_obj->channel->offermsg.offer.if_instance.b); 965 child_device_obj->channel->offermsg.offer.if_instance.b);
966 966
967 child_device_obj->device.bus = &hv_bus; 967 child_device_obj->device.bus = &hv_bus;
diff --git a/drivers/hwmon/adm9240.c b/drivers/hwmon/adm9240.c
index 98114cef1e43..2fe1828bd10b 100644
--- a/drivers/hwmon/adm9240.c
+++ b/drivers/hwmon/adm9240.c
@@ -194,10 +194,10 @@ static struct adm9240_data *adm9240_update_device(struct device *dev)
194 * 0.5'C per two measurement cycles thus ignore possible 194 * 0.5'C per two measurement cycles thus ignore possible
195 * but unlikely aliasing error on lsb reading. --Grant 195 * but unlikely aliasing error on lsb reading. --Grant
196 */ 196 */
197 data->temp = ((i2c_smbus_read_byte_data(client, 197 data->temp = (i2c_smbus_read_byte_data(client,
198 ADM9240_REG_TEMP) << 8) | 198 ADM9240_REG_TEMP) << 8) |
199 i2c_smbus_read_byte_data(client, 199 i2c_smbus_read_byte_data(client,
200 ADM9240_REG_TEMP_CONF)) / 128; 200 ADM9240_REG_TEMP_CONF);
201 201
202 for (i = 0; i < 2; i++) { /* read fans */ 202 for (i = 0; i < 2; i++) { /* read fans */
203 data->fan[i] = i2c_smbus_read_byte_data(client, 203 data->fan[i] = i2c_smbus_read_byte_data(client,
@@ -263,7 +263,7 @@ static ssize_t show_temp(struct device *dev, struct device_attribute *dummy,
263 char *buf) 263 char *buf)
264{ 264{
265 struct adm9240_data *data = adm9240_update_device(dev); 265 struct adm9240_data *data = adm9240_update_device(dev);
266 return sprintf(buf, "%d\n", data->temp * 500); /* 9-bit value */ 266 return sprintf(buf, "%d\n", data->temp / 128 * 500); /* 9-bit value */
267} 267}
268 268
269static ssize_t show_max(struct device *dev, struct device_attribute *devattr, 269static ssize_t show_max(struct device *dev, struct device_attribute *devattr,
diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c
index adae6848ffb2..a74c075a30ec 100644
--- a/drivers/hwmon/hwmon.c
+++ b/drivers/hwmon/hwmon.c
@@ -536,8 +536,10 @@ __hwmon_device_register(struct device *dev, const char *name, void *drvdata,
536 536
537 hwdev->groups = devm_kcalloc(dev, ngroups, sizeof(*groups), 537 hwdev->groups = devm_kcalloc(dev, ngroups, sizeof(*groups),
538 GFP_KERNEL); 538 GFP_KERNEL);
539 if (!hwdev->groups) 539 if (!hwdev->groups) {
540 return ERR_PTR(-ENOMEM); 540 err = -ENOMEM;
541 goto free_hwmon;
542 }
541 543
542 attrs = __hwmon_create_attrs(dev, drvdata, chip); 544 attrs = __hwmon_create_attrs(dev, drvdata, chip);
543 if (IS_ERR(attrs)) { 545 if (IS_ERR(attrs)) {
diff --git a/drivers/hwmon/max31790.c b/drivers/hwmon/max31790.c
index bef84e085973..c1b9275978f9 100644
--- a/drivers/hwmon/max31790.c
+++ b/drivers/hwmon/max31790.c
@@ -268,11 +268,13 @@ static int max31790_read_pwm(struct device *dev, u32 attr, int channel,
268 long *val) 268 long *val)
269{ 269{
270 struct max31790_data *data = max31790_update_device(dev); 270 struct max31790_data *data = max31790_update_device(dev);
271 u8 fan_config = data->fan_config[channel]; 271 u8 fan_config;
272 272
273 if (IS_ERR(data)) 273 if (IS_ERR(data))
274 return PTR_ERR(data); 274 return PTR_ERR(data);
275 275
276 fan_config = data->fan_config[channel];
277
276 switch (attr) { 278 switch (attr) {
277 case hwmon_pwm_input: 279 case hwmon_pwm_input:
278 *val = data->pwm[channel] >> 8; 280 *val = data->pwm[channel] >> 8;
diff --git a/drivers/i2c/Kconfig b/drivers/i2c/Kconfig
index d223650a97e4..11edabf425ae 100644
--- a/drivers/i2c/Kconfig
+++ b/drivers/i2c/Kconfig
@@ -59,7 +59,6 @@ config I2C_CHARDEV
59 59
60config I2C_MUX 60config I2C_MUX
61 tristate "I2C bus multiplexing support" 61 tristate "I2C bus multiplexing support"
62 depends on HAS_IOMEM
63 help 62 help
64 Say Y here if you want the I2C core to support the ability to 63 Say Y here if you want the I2C core to support the ability to
65 handle multiplexed I2C bus topologies, by presenting each 64 handle multiplexed I2C bus topologies, by presenting each
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index 6d94e2ec5b4f..d252276feadf 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -79,12 +79,12 @@ config I2C_AMD8111
79 79
80config I2C_HIX5HD2 80config I2C_HIX5HD2
81 tristate "Hix5hd2 high-speed I2C driver" 81 tristate "Hix5hd2 high-speed I2C driver"
82 depends on ARCH_HIX5HD2 || COMPILE_TEST 82 depends on ARCH_HISI || ARCH_HIX5HD2 || COMPILE_TEST
83 help 83 help
84 Say Y here to include support for high-speed I2C controller in the 84 Say Y here to include support for the high-speed I2C controller
85 Hisilicon based hix5hd2 SoCs. 85 used in HiSilicon hix5hd2 SoCs.
86 86
87 This driver can also be built as a module. If so, the module 87 This driver can also be built as a module. If so, the module
88 will be called i2c-hix5hd2. 88 will be called i2c-hix5hd2.
89 89
90config I2C_I801 90config I2C_I801
@@ -589,10 +589,10 @@ config I2C_IMG
589 589
590config I2C_IMX 590config I2C_IMX
591 tristate "IMX I2C interface" 591 tristate "IMX I2C interface"
592 depends on ARCH_MXC || ARCH_LAYERSCAPE 592 depends on ARCH_MXC || ARCH_LAYERSCAPE || COLDFIRE
593 help 593 help
594 Say Y here if you want to use the IIC bus controller on 594 Say Y here if you want to use the IIC bus controller on
595 the Freescale i.MX/MXC or Layerscape processors. 595 the Freescale i.MX/MXC, Layerscape or ColdFire processors.
596 596
597 This driver can also be built as a module. If so, the module 597 This driver can also be built as a module. If so, the module
598 will be called i2c-imx. 598 will be called i2c-imx.
diff --git a/drivers/i2c/busses/i2c-designware-core.c b/drivers/i2c/busses/i2c-designware-core.c
index 1fe93c43215c..b403fa5ecf49 100644
--- a/drivers/i2c/busses/i2c-designware-core.c
+++ b/drivers/i2c/busses/i2c-designware-core.c
@@ -91,9 +91,10 @@
91 DW_IC_INTR_TX_ABRT | \ 91 DW_IC_INTR_TX_ABRT | \
92 DW_IC_INTR_STOP_DET) 92 DW_IC_INTR_STOP_DET)
93 93
94#define DW_IC_STATUS_ACTIVITY 0x1 94#define DW_IC_STATUS_ACTIVITY 0x1
95#define DW_IC_STATUS_TFE BIT(2) 95
96#define DW_IC_STATUS_MST_ACTIVITY BIT(5) 96#define DW_IC_SDA_HOLD_RX_SHIFT 16
97#define DW_IC_SDA_HOLD_RX_MASK GENMASK(23, DW_IC_SDA_HOLD_RX_SHIFT)
97 98
98#define DW_IC_ERR_TX_ABRT 0x1 99#define DW_IC_ERR_TX_ABRT 0x1
99 100
@@ -420,12 +421,20 @@ int i2c_dw_init(struct dw_i2c_dev *dev)
420 /* Configure SDA Hold Time if required */ 421 /* Configure SDA Hold Time if required */
421 reg = dw_readl(dev, DW_IC_COMP_VERSION); 422 reg = dw_readl(dev, DW_IC_COMP_VERSION);
422 if (reg >= DW_IC_SDA_HOLD_MIN_VERS) { 423 if (reg >= DW_IC_SDA_HOLD_MIN_VERS) {
423 if (dev->sda_hold_time) { 424 if (!dev->sda_hold_time) {
424 dw_writel(dev, dev->sda_hold_time, DW_IC_SDA_HOLD);
425 } else {
426 /* Keep previous hold time setting if no one set it */ 425 /* Keep previous hold time setting if no one set it */
427 dev->sda_hold_time = dw_readl(dev, DW_IC_SDA_HOLD); 426 dev->sda_hold_time = dw_readl(dev, DW_IC_SDA_HOLD);
428 } 427 }
428 /*
429 * Workaround for avoiding TX arbitration lost in case I2C
430 * slave pulls SDA down "too quickly" after falling egde of
431 * SCL by enabling non-zero SDA RX hold. Specification says it
432 * extends incoming SDA low to high transition while SCL is
433 * high but it apprears to help also above issue.
434 */
435 if (!(dev->sda_hold_time & DW_IC_SDA_HOLD_RX_MASK))
436 dev->sda_hold_time |= 1 << DW_IC_SDA_HOLD_RX_SHIFT;
437 dw_writel(dev, dev->sda_hold_time, DW_IC_SDA_HOLD);
429 } else { 438 } else {
430 dev_warn(dev->dev, 439 dev_warn(dev->dev,
431 "Hardware too old to adjust SDA hold time.\n"); 440 "Hardware too old to adjust SDA hold time.\n");
@@ -467,25 +476,9 @@ static void i2c_dw_xfer_init(struct dw_i2c_dev *dev)
467{ 476{
468 struct i2c_msg *msgs = dev->msgs; 477 struct i2c_msg *msgs = dev->msgs;
469 u32 ic_tar = 0; 478 u32 ic_tar = 0;
470 bool enabled;
471
472 enabled = dw_readl(dev, DW_IC_ENABLE_STATUS) & 1;
473
474 if (enabled) {
475 u32 ic_status;
476 479
477 /* 480 /* Disable the adapter */
478 * Only disable adapter if ic_tar and ic_con can't be 481 __i2c_dw_enable_and_wait(dev, false);
479 * dynamically updated
480 */
481 ic_status = dw_readl(dev, DW_IC_STATUS);
482 if (!dev->dynamic_tar_update_enabled ||
483 (ic_status & DW_IC_STATUS_MST_ACTIVITY) ||
484 !(ic_status & DW_IC_STATUS_TFE)) {
485 __i2c_dw_enable_and_wait(dev, false);
486 enabled = false;
487 }
488 }
489 482
490 /* if the slave address is ten bit address, enable 10BITADDR */ 483 /* if the slave address is ten bit address, enable 10BITADDR */
491 if (dev->dynamic_tar_update_enabled) { 484 if (dev->dynamic_tar_update_enabled) {
@@ -515,8 +508,8 @@ static void i2c_dw_xfer_init(struct dw_i2c_dev *dev)
515 /* enforce disabled interrupts (due to HW issues) */ 508 /* enforce disabled interrupts (due to HW issues) */
516 i2c_dw_disable_int(dev); 509 i2c_dw_disable_int(dev);
517 510
518 if (!enabled) 511 /* Enable the adapter */
519 __i2c_dw_enable(dev, true); 512 __i2c_dw_enable(dev, true);
520 513
521 /* Clear and enable interrupts */ 514 /* Clear and enable interrupts */
522 dw_readl(dev, DW_IC_CLR_INTR); 515 dw_readl(dev, DW_IC_CLR_INTR);
@@ -600,7 +593,7 @@ i2c_dw_xfer_msg(struct dw_i2c_dev *dev)
600 if (msgs[dev->msg_write_idx].flags & I2C_M_RD) { 593 if (msgs[dev->msg_write_idx].flags & I2C_M_RD) {
601 594
602 /* avoid rx buffer overrun */ 595 /* avoid rx buffer overrun */
603 if (rx_limit - dev->rx_outstanding <= 0) 596 if (dev->rx_outstanding >= dev->rx_fifo_depth)
604 break; 597 break;
605 598
606 dw_writel(dev, cmd | 0x100, DW_IC_DATA_CMD); 599 dw_writel(dev, cmd | 0x100, DW_IC_DATA_CMD);
@@ -697,8 +690,7 @@ static int i2c_dw_handle_tx_abort(struct dw_i2c_dev *dev)
697} 690}
698 691
699/* 692/*
700 * Prepare controller for a transaction and start transfer by calling 693 * Prepare controller for a transaction and call i2c_dw_xfer_msg
701 * i2c_dw_xfer_init()
702 */ 694 */
703static int 695static int
704i2c_dw_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num) 696i2c_dw_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
@@ -741,13 +733,23 @@ i2c_dw_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
741 goto done; 733 goto done;
742 } 734 }
743 735
736 /*
737 * We must disable the adapter before returning and signaling the end
738 * of the current transfer. Otherwise the hardware might continue
739 * generating interrupts which in turn causes a race condition with
740 * the following transfer. Needs some more investigation if the
741 * additional interrupts are a hardware bug or this driver doesn't
742 * handle them correctly yet.
743 */
744 __i2c_dw_enable(dev, false);
745
744 if (dev->msg_err) { 746 if (dev->msg_err) {
745 ret = dev->msg_err; 747 ret = dev->msg_err;
746 goto done; 748 goto done;
747 } 749 }
748 750
749 /* no error */ 751 /* no error */
750 if (likely(!dev->cmd_err)) { 752 if (likely(!dev->cmd_err && !dev->status)) {
751 ret = num; 753 ret = num;
752 goto done; 754 goto done;
753 } 755 }
@@ -757,6 +759,11 @@ i2c_dw_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
757 ret = i2c_dw_handle_tx_abort(dev); 759 ret = i2c_dw_handle_tx_abort(dev);
758 goto done; 760 goto done;
759 } 761 }
762
763 if (dev->status)
764 dev_err(dev->dev,
765 "transfer terminated early - interrupt latency too high?\n");
766
760 ret = -EIO; 767 ret = -EIO;
761 768
762done: 769done:
@@ -877,19 +884,9 @@ static irqreturn_t i2c_dw_isr(int this_irq, void *dev_id)
877 */ 884 */
878 885
879tx_aborted: 886tx_aborted:
880 if ((stat & (DW_IC_INTR_TX_ABRT | DW_IC_INTR_STOP_DET)) 887 if ((stat & (DW_IC_INTR_TX_ABRT | DW_IC_INTR_STOP_DET)) || dev->msg_err)
881 || dev->msg_err) {
882 /*
883 * We must disable interruts before returning and signaling
884 * the end of the current transfer. Otherwise the hardware
885 * might continue generating interrupts for non-existent
886 * transfers.
887 */
888 i2c_dw_disable_int(dev);
889 dw_readl(dev, DW_IC_CLR_INTR);
890
891 complete(&dev->cmd_complete); 888 complete(&dev->cmd_complete);
892 } else if (unlikely(dev->accessor_flags & ACCESS_INTR_MASK)) { 889 else if (unlikely(dev->accessor_flags & ACCESS_INTR_MASK)) {
893 /* workaround to trigger pending interrupt */ 890 /* workaround to trigger pending interrupt */
894 stat = dw_readl(dev, DW_IC_INTR_MASK); 891 stat = dw_readl(dev, DW_IC_INTR_MASK);
895 i2c_dw_disable_int(dev); 892 i2c_dw_disable_int(dev);
diff --git a/drivers/i2c/busses/i2c-digicolor.c b/drivers/i2c/busses/i2c-digicolor.c
index 9604024e0eb0..50813a24c541 100644
--- a/drivers/i2c/busses/i2c-digicolor.c
+++ b/drivers/i2c/busses/i2c-digicolor.c
@@ -347,7 +347,7 @@ static int dc_i2c_probe(struct platform_device *pdev)
347 347
348 ret = i2c_add_adapter(&i2c->adap); 348 ret = i2c_add_adapter(&i2c->adap);
349 if (ret < 0) { 349 if (ret < 0) {
350 clk_unprepare(i2c->clk); 350 clk_disable_unprepare(i2c->clk);
351 return ret; 351 return ret;
352 } 352 }
353 353
@@ -368,6 +368,7 @@ static const struct of_device_id dc_i2c_match[] = {
368 { .compatible = "cnxt,cx92755-i2c" }, 368 { .compatible = "cnxt,cx92755-i2c" },
369 { }, 369 { },
370}; 370};
371MODULE_DEVICE_TABLE(of, dc_i2c_match);
371 372
372static struct platform_driver dc_i2c_driver = { 373static struct platform_driver dc_i2c_driver = {
373 .probe = dc_i2c_probe, 374 .probe = dc_i2c_probe,
diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
index 08847e8b8998..eb3627f35d12 100644
--- a/drivers/i2c/busses/i2c-i801.c
+++ b/drivers/i2c/busses/i2c-i801.c
@@ -146,6 +146,7 @@
146#define SMBHSTCFG_HST_EN 1 146#define SMBHSTCFG_HST_EN 1
147#define SMBHSTCFG_SMB_SMI_EN 2 147#define SMBHSTCFG_SMB_SMI_EN 2
148#define SMBHSTCFG_I2C_EN 4 148#define SMBHSTCFG_I2C_EN 4
149#define SMBHSTCFG_SPD_WD 0x10
149 150
150/* TCO configuration bits for TCOCTL */ 151/* TCO configuration bits for TCOCTL */
151#define TCOCTL_EN 0x0100 152#define TCOCTL_EN 0x0100
@@ -865,9 +866,16 @@ static s32 i801_access(struct i2c_adapter *adap, u16 addr,
865 block = 1; 866 block = 1;
866 break; 867 break;
867 case I2C_SMBUS_I2C_BLOCK_DATA: 868 case I2C_SMBUS_I2C_BLOCK_DATA:
868 /* NB: page 240 of ICH5 datasheet shows that the R/#W 869 /*
869 * bit should be cleared here, even when reading */ 870 * NB: page 240 of ICH5 datasheet shows that the R/#W
870 outb_p((addr & 0x7f) << 1, SMBHSTADD(priv)); 871 * bit should be cleared here, even when reading.
872 * However if SPD Write Disable is set (Lynx Point and later),
873 * the read will fail if we don't set the R/#W bit.
874 */
875 outb_p(((addr & 0x7f) << 1) |
876 ((priv->original_hstcfg & SMBHSTCFG_SPD_WD) ?
877 (read_write & 0x01) : 0),
878 SMBHSTADD(priv));
871 if (read_write == I2C_SMBUS_READ) { 879 if (read_write == I2C_SMBUS_READ) {
872 /* NB: page 240 of ICH5 datasheet also shows 880 /* NB: page 240 of ICH5 datasheet also shows
873 * that DATA1 is the cmd field when reading */ 881 * that DATA1 is the cmd field when reading */
@@ -1573,6 +1581,8 @@ static int i801_probe(struct pci_dev *dev, const struct pci_device_id *id)
1573 /* Disable SMBus interrupt feature if SMBus using SMI# */ 1581 /* Disable SMBus interrupt feature if SMBus using SMI# */
1574 priv->features &= ~FEATURE_IRQ; 1582 priv->features &= ~FEATURE_IRQ;
1575 } 1583 }
1584 if (temp & SMBHSTCFG_SPD_WD)
1585 dev_info(&dev->dev, "SPD Write Disable is set\n");
1576 1586
1577 /* Clear special mode bits */ 1587 /* Clear special mode bits */
1578 if (priv->features & (FEATURE_SMBUS_PEC | FEATURE_BLOCK_BUFFER)) 1588 if (priv->features & (FEATURE_SMBUS_PEC | FEATURE_BLOCK_BUFFER))
diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
index 592a8f26a708..47fc1f1acff7 100644
--- a/drivers/i2c/busses/i2c-imx.c
+++ b/drivers/i2c/busses/i2c-imx.c
@@ -1009,10 +1009,13 @@ static int i2c_imx_init_recovery_info(struct imx_i2c_struct *i2c_imx,
1009 rinfo->sda_gpio = of_get_named_gpio(pdev->dev.of_node, "sda-gpios", 0); 1009 rinfo->sda_gpio = of_get_named_gpio(pdev->dev.of_node, "sda-gpios", 0);
1010 rinfo->scl_gpio = of_get_named_gpio(pdev->dev.of_node, "scl-gpios", 0); 1010 rinfo->scl_gpio = of_get_named_gpio(pdev->dev.of_node, "scl-gpios", 0);
1011 1011
1012 if (!gpio_is_valid(rinfo->sda_gpio) || 1012 if (rinfo->sda_gpio == -EPROBE_DEFER ||
1013 !gpio_is_valid(rinfo->scl_gpio) || 1013 rinfo->scl_gpio == -EPROBE_DEFER) {
1014 IS_ERR(i2c_imx->pinctrl_pins_default) || 1014 return -EPROBE_DEFER;
1015 IS_ERR(i2c_imx->pinctrl_pins_gpio)) { 1015 } else if (!gpio_is_valid(rinfo->sda_gpio) ||
1016 !gpio_is_valid(rinfo->scl_gpio) ||
1017 IS_ERR(i2c_imx->pinctrl_pins_default) ||
1018 IS_ERR(i2c_imx->pinctrl_pins_gpio)) {
1016 dev_dbg(&pdev->dev, "recovery information incomplete\n"); 1019 dev_dbg(&pdev->dev, "recovery information incomplete\n");
1017 return 0; 1020 return 0;
1018 } 1021 }
diff --git a/drivers/i2c/busses/i2c-jz4780.c b/drivers/i2c/busses/i2c-jz4780.c
index b8ea62105f42..30132c3957cd 100644
--- a/drivers/i2c/busses/i2c-jz4780.c
+++ b/drivers/i2c/busses/i2c-jz4780.c
@@ -729,6 +729,7 @@ static const struct of_device_id jz4780_i2c_of_matches[] = {
729 { .compatible = "ingenic,jz4780-i2c", }, 729 { .compatible = "ingenic,jz4780-i2c", },
730 { /* sentinel */ } 730 { /* sentinel */ }
731}; 731};
732MODULE_DEVICE_TABLE(of, jz4780_i2c_of_matches);
732 733
733static int jz4780_i2c_probe(struct platform_device *pdev) 734static int jz4780_i2c_probe(struct platform_device *pdev)
734{ 735{
diff --git a/drivers/i2c/busses/i2c-octeon-core.c b/drivers/i2c/busses/i2c-octeon-core.c
index 419b54bfc7c7..5e63b17f935d 100644
--- a/drivers/i2c/busses/i2c-octeon-core.c
+++ b/drivers/i2c/busses/i2c-octeon-core.c
@@ -381,9 +381,7 @@ static int octeon_i2c_read(struct octeon_i2c *i2c, int target,
381 if (result) 381 if (result)
382 return result; 382 return result;
383 383
384 data[i] = octeon_i2c_data_read(i2c, &result); 384 data[i] = octeon_i2c_data_read(i2c);
385 if (result)
386 return result;
387 if (recv_len && i == 0) { 385 if (recv_len && i == 0) {
388 if (data[i] > I2C_SMBUS_BLOCK_MAX + 1) 386 if (data[i] > I2C_SMBUS_BLOCK_MAX + 1)
389 return -EPROTO; 387 return -EPROTO;
diff --git a/drivers/i2c/busses/i2c-octeon-core.h b/drivers/i2c/busses/i2c-octeon-core.h
index 1db7c835a454..87151ea74acd 100644
--- a/drivers/i2c/busses/i2c-octeon-core.h
+++ b/drivers/i2c/busses/i2c-octeon-core.h
@@ -5,7 +5,6 @@
5#include <linux/i2c.h> 5#include <linux/i2c.h>
6#include <linux/i2c-smbus.h> 6#include <linux/i2c-smbus.h>
7#include <linux/io.h> 7#include <linux/io.h>
8#include <linux/iopoll.h>
9#include <linux/kernel.h> 8#include <linux/kernel.h>
10#include <linux/pci.h> 9#include <linux/pci.h>
11 10
@@ -145,9 +144,9 @@ static inline void octeon_i2c_reg_write(struct octeon_i2c *i2c, u64 eop_reg, u8
145 u64 tmp; 144 u64 tmp;
146 145
147 __raw_writeq(SW_TWSI_V | eop_reg | data, i2c->twsi_base + SW_TWSI(i2c)); 146 __raw_writeq(SW_TWSI_V | eop_reg | data, i2c->twsi_base + SW_TWSI(i2c));
148 147 do {
149 readq_poll_timeout(i2c->twsi_base + SW_TWSI(i2c), tmp, tmp & SW_TWSI_V, 148 tmp = __raw_readq(i2c->twsi_base + SW_TWSI(i2c));
150 I2C_OCTEON_EVENT_WAIT, i2c->adap.timeout); 149 } while ((tmp & SW_TWSI_V) != 0);
151} 150}
152 151
153#define octeon_i2c_ctl_write(i2c, val) \ 152#define octeon_i2c_ctl_write(i2c, val) \
@@ -164,28 +163,24 @@ static inline void octeon_i2c_reg_write(struct octeon_i2c *i2c, u64 eop_reg, u8
164 * 163 *
165 * The I2C core registers are accessed indirectly via the SW_TWSI CSR. 164 * The I2C core registers are accessed indirectly via the SW_TWSI CSR.
166 */ 165 */
167static inline int octeon_i2c_reg_read(struct octeon_i2c *i2c, u64 eop_reg, 166static inline u8 octeon_i2c_reg_read(struct octeon_i2c *i2c, u64 eop_reg)
168 int *error)
169{ 167{
170 u64 tmp; 168 u64 tmp;
171 int ret;
172 169
173 __raw_writeq(SW_TWSI_V | eop_reg | SW_TWSI_R, i2c->twsi_base + SW_TWSI(i2c)); 170 __raw_writeq(SW_TWSI_V | eop_reg | SW_TWSI_R, i2c->twsi_base + SW_TWSI(i2c));
171 do {
172 tmp = __raw_readq(i2c->twsi_base + SW_TWSI(i2c));
173 } while ((tmp & SW_TWSI_V) != 0);
174 174
175 ret = readq_poll_timeout(i2c->twsi_base + SW_TWSI(i2c), tmp,
176 tmp & SW_TWSI_V, I2C_OCTEON_EVENT_WAIT,
177 i2c->adap.timeout);
178 if (error)
179 *error = ret;
180 return tmp & 0xFF; 175 return tmp & 0xFF;
181} 176}
182 177
183#define octeon_i2c_ctl_read(i2c) \ 178#define octeon_i2c_ctl_read(i2c) \
184 octeon_i2c_reg_read(i2c, SW_TWSI_EOP_TWSI_CTL, NULL) 179 octeon_i2c_reg_read(i2c, SW_TWSI_EOP_TWSI_CTL)
185#define octeon_i2c_data_read(i2c, error) \ 180#define octeon_i2c_data_read(i2c) \
186 octeon_i2c_reg_read(i2c, SW_TWSI_EOP_TWSI_DATA, error) 181 octeon_i2c_reg_read(i2c, SW_TWSI_EOP_TWSI_DATA)
187#define octeon_i2c_stat_read(i2c) \ 182#define octeon_i2c_stat_read(i2c) \
188 octeon_i2c_reg_read(i2c, SW_TWSI_EOP_TWSI_STAT, NULL) 183 octeon_i2c_reg_read(i2c, SW_TWSI_EOP_TWSI_STAT)
189 184
190/** 185/**
191 * octeon_i2c_read_int - read the TWSI_INT register 186 * octeon_i2c_read_int - read the TWSI_INT register
diff --git a/drivers/i2c/busses/i2c-rk3x.c b/drivers/i2c/busses/i2c-rk3x.c
index 50702c7bb244..df220666d627 100644
--- a/drivers/i2c/busses/i2c-rk3x.c
+++ b/drivers/i2c/busses/i2c-rk3x.c
@@ -694,6 +694,8 @@ static int rk3x_i2c_v0_calc_timings(unsigned long clk_rate,
694 t_calc->div_low--; 694 t_calc->div_low--;
695 t_calc->div_high--; 695 t_calc->div_high--;
696 696
697 /* Give the tuning value 0, that would not update con register */
698 t_calc->tuning = 0;
697 /* Maximum divider supported by hw is 0xffff */ 699 /* Maximum divider supported by hw is 0xffff */
698 if (t_calc->div_low > 0xffff) { 700 if (t_calc->div_low > 0xffff) {
699 t_calc->div_low = 0xffff; 701 t_calc->div_low = 0xffff;
diff --git a/drivers/i2c/busses/i2c-xgene-slimpro.c b/drivers/i2c/busses/i2c-xgene-slimpro.c
index 263685c7a512..05cf192ef1ac 100644
--- a/drivers/i2c/busses/i2c-xgene-slimpro.c
+++ b/drivers/i2c/busses/i2c-xgene-slimpro.c
@@ -105,7 +105,7 @@ struct slimpro_i2c_dev {
105 struct mbox_chan *mbox_chan; 105 struct mbox_chan *mbox_chan;
106 struct mbox_client mbox_client; 106 struct mbox_client mbox_client;
107 struct completion rd_complete; 107 struct completion rd_complete;
108 u8 dma_buffer[I2C_SMBUS_BLOCK_MAX]; 108 u8 dma_buffer[I2C_SMBUS_BLOCK_MAX + 1]; /* dma_buffer[0] is used for length */
109 u32 *resp_msg; 109 u32 *resp_msg;
110}; 110};
111 111
diff --git a/drivers/i2c/busses/i2c-xlp9xx.c b/drivers/i2c/busses/i2c-xlp9xx.c
index 2a972ed7aa0d..e29ff37a43bd 100644
--- a/drivers/i2c/busses/i2c-xlp9xx.c
+++ b/drivers/i2c/busses/i2c-xlp9xx.c
@@ -426,6 +426,7 @@ static const struct of_device_id xlp9xx_i2c_of_match[] = {
426 { .compatible = "netlogic,xlp980-i2c", }, 426 { .compatible = "netlogic,xlp980-i2c", },
427 { /* sentinel */ }, 427 { /* sentinel */ },
428}; 428};
429MODULE_DEVICE_TABLE(of, xlp9xx_i2c_of_match);
429 430
430#ifdef CONFIG_ACPI 431#ifdef CONFIG_ACPI
431static const struct acpi_device_id xlp9xx_i2c_acpi_ids[] = { 432static const struct acpi_device_id xlp9xx_i2c_acpi_ids[] = {
diff --git a/drivers/i2c/busses/i2c-xlr.c b/drivers/i2c/busses/i2c-xlr.c
index 0968f59b6df5..ad17d88d8573 100644
--- a/drivers/i2c/busses/i2c-xlr.c
+++ b/drivers/i2c/busses/i2c-xlr.c
@@ -358,6 +358,7 @@ static const struct of_device_id xlr_i2c_dt_ids[] = {
358 }, 358 },
359 { } 359 { }
360}; 360};
361MODULE_DEVICE_TABLE(of, xlr_i2c_dt_ids);
361 362
362static int xlr_i2c_probe(struct platform_device *pdev) 363static int xlr_i2c_probe(struct platform_device *pdev)
363{ 364{
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 5ab67219f71e..b432b64e307a 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -1681,6 +1681,7 @@ static struct i2c_client *of_i2c_register_device(struct i2c_adapter *adap,
1681static void of_i2c_register_devices(struct i2c_adapter *adap) 1681static void of_i2c_register_devices(struct i2c_adapter *adap)
1682{ 1682{
1683 struct device_node *bus, *node; 1683 struct device_node *bus, *node;
1684 struct i2c_client *client;
1684 1685
1685 /* Only register child devices if the adapter has a node pointer set */ 1686 /* Only register child devices if the adapter has a node pointer set */
1686 if (!adap->dev.of_node) 1687 if (!adap->dev.of_node)
@@ -1695,7 +1696,14 @@ static void of_i2c_register_devices(struct i2c_adapter *adap)
1695 for_each_available_child_of_node(bus, node) { 1696 for_each_available_child_of_node(bus, node) {
1696 if (of_node_test_and_set_flag(node, OF_POPULATED)) 1697 if (of_node_test_and_set_flag(node, OF_POPULATED))
1697 continue; 1698 continue;
1698 of_i2c_register_device(adap, node); 1699
1700 client = of_i2c_register_device(adap, node);
1701 if (IS_ERR(client)) {
1702 dev_warn(&adap->dev,
1703 "Failed to create I2C device for %s\n",
1704 node->full_name);
1705 of_node_clear_flag(node, OF_POPULATED);
1706 }
1699 } 1707 }
1700 1708
1701 of_node_put(bus); 1709 of_node_put(bus);
@@ -2171,6 +2179,7 @@ int i2c_register_driver(struct module *owner, struct i2c_driver *driver)
2171 /* add the driver to the list of i2c drivers in the driver core */ 2179 /* add the driver to the list of i2c drivers in the driver core */
2172 driver->driver.owner = owner; 2180 driver->driver.owner = owner;
2173 driver->driver.bus = &i2c_bus_type; 2181 driver->driver.bus = &i2c_bus_type;
2182 INIT_LIST_HEAD(&driver->clients);
2174 2183
2175 /* When registration returns, the driver core 2184 /* When registration returns, the driver core
2176 * will have called probe() for all matching-but-unbound devices. 2185 * will have called probe() for all matching-but-unbound devices.
@@ -2181,7 +2190,6 @@ int i2c_register_driver(struct module *owner, struct i2c_driver *driver)
2181 2190
2182 pr_debug("driver [%s] registered\n", driver->driver.name); 2191 pr_debug("driver [%s] registered\n", driver->driver.name);
2183 2192
2184 INIT_LIST_HEAD(&driver->clients);
2185 /* Walk the adapters that are already present */ 2193 /* Walk the adapters that are already present */
2186 i2c_for_each_dev(driver, __process_new_driver); 2194 i2c_for_each_dev(driver, __process_new_driver);
2187 2195
@@ -2299,6 +2307,7 @@ static int of_i2c_notify(struct notifier_block *nb, unsigned long action,
2299 if (IS_ERR(client)) { 2307 if (IS_ERR(client)) {
2300 dev_err(&adap->dev, "failed to create client for '%s'\n", 2308 dev_err(&adap->dev, "failed to create client for '%s'\n",
2301 rd->dn->full_name); 2309 rd->dn->full_name);
2310 of_node_clear_flag(rd->dn, OF_POPULATED);
2302 return notifier_from_errno(PTR_ERR(client)); 2311 return notifier_from_errno(PTR_ERR(client));
2303 } 2312 }
2304 break; 2313 break;
diff --git a/drivers/i2c/muxes/Kconfig b/drivers/i2c/muxes/Kconfig
index e280c8ecc0b5..96de9ce5669b 100644
--- a/drivers/i2c/muxes/Kconfig
+++ b/drivers/i2c/muxes/Kconfig
@@ -63,6 +63,7 @@ config I2C_MUX_PINCTRL
63 63
64config I2C_MUX_REG 64config I2C_MUX_REG
65 tristate "Register-based I2C multiplexer" 65 tristate "Register-based I2C multiplexer"
66 depends on HAS_IOMEM
66 help 67 help
67 If you say yes to this option, support will be included for a 68 If you say yes to this option, support will be included for a
68 register based I2C multiplexer. This driver provides access to 69 register based I2C multiplexer. This driver provides access to
diff --git a/drivers/i2c/muxes/i2c-demux-pinctrl.c b/drivers/i2c/muxes/i2c-demux-pinctrl.c
index b3893f6282ba..3e6fe1760d82 100644
--- a/drivers/i2c/muxes/i2c-demux-pinctrl.c
+++ b/drivers/i2c/muxes/i2c-demux-pinctrl.c
@@ -69,10 +69,28 @@ static int i2c_demux_activate_master(struct i2c_demux_pinctrl_priv *priv, u32 ne
69 goto err_with_revert; 69 goto err_with_revert;
70 } 70 }
71 71
72 p = devm_pinctrl_get_select(adap->dev.parent, priv->bus_name); 72 /*
73 * Check if there are pinctrl states at all. Note: we cant' use
74 * devm_pinctrl_get_select() because we need to distinguish between
75 * the -ENODEV from devm_pinctrl_get() and pinctrl_lookup_state().
76 */
77 p = devm_pinctrl_get(adap->dev.parent);
73 if (IS_ERR(p)) { 78 if (IS_ERR(p)) {
74 ret = PTR_ERR(p); 79 ret = PTR_ERR(p);
75 goto err_with_put; 80 /* continue if just no pinctrl states (e.g. i2c-gpio), otherwise exit */
81 if (ret != -ENODEV)
82 goto err_with_put;
83 } else {
84 /* there are states. check and use them */
85 struct pinctrl_state *s = pinctrl_lookup_state(p, priv->bus_name);
86
87 if (IS_ERR(s)) {
88 ret = PTR_ERR(s);
89 goto err_with_put;
90 }
91 ret = pinctrl_select_state(p, s);
92 if (ret < 0)
93 goto err_with_put;
76 } 94 }
77 95
78 priv->chan[new_chan].parent_adap = adap; 96 priv->chan[new_chan].parent_adap = adap;
diff --git a/drivers/i2c/muxes/i2c-mux-pca954x.c b/drivers/i2c/muxes/i2c-mux-pca954x.c
index 1091346f2480..8bc3d36d2837 100644
--- a/drivers/i2c/muxes/i2c-mux-pca954x.c
+++ b/drivers/i2c/muxes/i2c-mux-pca954x.c
@@ -268,9 +268,9 @@ static int pca954x_probe(struct i2c_client *client,
268 /* discard unconfigured channels */ 268 /* discard unconfigured channels */
269 break; 269 break;
270 idle_disconnect_pd = pdata->modes[num].deselect_on_exit; 270 idle_disconnect_pd = pdata->modes[num].deselect_on_exit;
271 data->deselect |= (idle_disconnect_pd
272 || idle_disconnect_dt) << num;
273 } 271 }
272 data->deselect |= (idle_disconnect_pd ||
273 idle_disconnect_dt) << num;
274 274
275 ret = i2c_mux_add_adapter(muxc, force, num, class); 275 ret = i2c_mux_add_adapter(muxc, force, num, class);
276 276
diff --git a/drivers/iio/accel/st_accel_core.c b/drivers/iio/accel/st_accel_core.c
index da3fb069ec5c..ce69048c88e9 100644
--- a/drivers/iio/accel/st_accel_core.c
+++ b/drivers/iio/accel/st_accel_core.c
@@ -743,8 +743,8 @@ static int st_accel_read_raw(struct iio_dev *indio_dev,
743 743
744 return IIO_VAL_INT; 744 return IIO_VAL_INT;
745 case IIO_CHAN_INFO_SCALE: 745 case IIO_CHAN_INFO_SCALE:
746 *val = 0; 746 *val = adata->current_fullscale->gain / 1000000;
747 *val2 = adata->current_fullscale->gain; 747 *val2 = adata->current_fullscale->gain % 1000000;
748 return IIO_VAL_INT_PLUS_MICRO; 748 return IIO_VAL_INT_PLUS_MICRO;
749 case IIO_CHAN_INFO_SAMP_FREQ: 749 case IIO_CHAN_INFO_SAMP_FREQ:
750 *val = adata->odr; 750 *val = adata->odr;
@@ -763,9 +763,13 @@ static int st_accel_write_raw(struct iio_dev *indio_dev,
763 int err; 763 int err;
764 764
765 switch (mask) { 765 switch (mask) {
766 case IIO_CHAN_INFO_SCALE: 766 case IIO_CHAN_INFO_SCALE: {
767 err = st_sensors_set_fullscale_by_gain(indio_dev, val2); 767 int gain;
768
769 gain = val * 1000000 + val2;
770 err = st_sensors_set_fullscale_by_gain(indio_dev, gain);
768 break; 771 break;
772 }
769 case IIO_CHAN_INFO_SAMP_FREQ: 773 case IIO_CHAN_INFO_SAMP_FREQ:
770 if (val2) 774 if (val2)
771 return -EINVAL; 775 return -EINVAL;
diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
index 7edcf3238620..99c051490eff 100644
--- a/drivers/iio/adc/Kconfig
+++ b/drivers/iio/adc/Kconfig
@@ -437,6 +437,8 @@ config STX104
437config TI_ADC081C 437config TI_ADC081C
438 tristate "Texas Instruments ADC081C/ADC101C/ADC121C family" 438 tristate "Texas Instruments ADC081C/ADC101C/ADC121C family"
439 depends on I2C 439 depends on I2C
440 select IIO_BUFFER
441 select IIO_TRIGGERED_BUFFER
440 help 442 help
441 If you say yes here you get support for Texas Instruments ADC081C, 443 If you say yes here you get support for Texas Instruments ADC081C,
442 ADC101C and ADC121C ADC chips. 444 ADC101C and ADC121C ADC chips.
diff --git a/drivers/iio/chemical/atlas-ph-sensor.c b/drivers/iio/chemical/atlas-ph-sensor.c
index bd321b305a0a..ef761a508630 100644
--- a/drivers/iio/chemical/atlas-ph-sensor.c
+++ b/drivers/iio/chemical/atlas-ph-sensor.c
@@ -213,13 +213,14 @@ static int atlas_check_ec_calibration(struct atlas_data *data)
213 struct device *dev = &data->client->dev; 213 struct device *dev = &data->client->dev;
214 int ret; 214 int ret;
215 unsigned int val; 215 unsigned int val;
216 __be16 rval;
216 217
217 ret = regmap_bulk_read(data->regmap, ATLAS_REG_EC_PROBE, &val, 2); 218 ret = regmap_bulk_read(data->regmap, ATLAS_REG_EC_PROBE, &rval, 2);
218 if (ret) 219 if (ret)
219 return ret; 220 return ret;
220 221
221 dev_info(dev, "probe set to K = %d.%.2d", be16_to_cpu(val) / 100, 222 val = be16_to_cpu(rval);
222 be16_to_cpu(val) % 100); 223 dev_info(dev, "probe set to K = %d.%.2d", val / 100, val % 100);
223 224
224 ret = regmap_read(data->regmap, ATLAS_REG_EC_CALIB_STATUS, &val); 225 ret = regmap_read(data->regmap, ATLAS_REG_EC_CALIB_STATUS, &val);
225 if (ret) 226 if (ret)
diff --git a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
index dc33c1dd5191..b5beea53d6f6 100644
--- a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
+++ b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
@@ -30,26 +30,26 @@ static struct {
30 u32 usage_id; 30 u32 usage_id;
31 int unit; /* 0 for default others from HID sensor spec */ 31 int unit; /* 0 for default others from HID sensor spec */
32 int scale_val0; /* scale, whole number */ 32 int scale_val0; /* scale, whole number */
33 int scale_val1; /* scale, fraction in micros */ 33 int scale_val1; /* scale, fraction in nanos */
34} unit_conversion[] = { 34} unit_conversion[] = {
35 {HID_USAGE_SENSOR_ACCEL_3D, 0, 9, 806650}, 35 {HID_USAGE_SENSOR_ACCEL_3D, 0, 9, 806650000},
36 {HID_USAGE_SENSOR_ACCEL_3D, 36 {HID_USAGE_SENSOR_ACCEL_3D,
37 HID_USAGE_SENSOR_UNITS_METERS_PER_SEC_SQRD, 1, 0}, 37 HID_USAGE_SENSOR_UNITS_METERS_PER_SEC_SQRD, 1, 0},
38 {HID_USAGE_SENSOR_ACCEL_3D, 38 {HID_USAGE_SENSOR_ACCEL_3D,
39 HID_USAGE_SENSOR_UNITS_G, 9, 806650}, 39 HID_USAGE_SENSOR_UNITS_G, 9, 806650000},
40 40
41 {HID_USAGE_SENSOR_GYRO_3D, 0, 0, 17453}, 41 {HID_USAGE_SENSOR_GYRO_3D, 0, 0, 17453293},
42 {HID_USAGE_SENSOR_GYRO_3D, 42 {HID_USAGE_SENSOR_GYRO_3D,
43 HID_USAGE_SENSOR_UNITS_RADIANS_PER_SECOND, 1, 0}, 43 HID_USAGE_SENSOR_UNITS_RADIANS_PER_SECOND, 1, 0},
44 {HID_USAGE_SENSOR_GYRO_3D, 44 {HID_USAGE_SENSOR_GYRO_3D,
45 HID_USAGE_SENSOR_UNITS_DEGREES_PER_SECOND, 0, 17453}, 45 HID_USAGE_SENSOR_UNITS_DEGREES_PER_SECOND, 0, 17453293},
46 46
47 {HID_USAGE_SENSOR_COMPASS_3D, 0, 0, 1000}, 47 {HID_USAGE_SENSOR_COMPASS_3D, 0, 0, 1000000},
48 {HID_USAGE_SENSOR_COMPASS_3D, HID_USAGE_SENSOR_UNITS_GAUSS, 1, 0}, 48 {HID_USAGE_SENSOR_COMPASS_3D, HID_USAGE_SENSOR_UNITS_GAUSS, 1, 0},
49 49
50 {HID_USAGE_SENSOR_INCLINOMETER_3D, 0, 0, 17453}, 50 {HID_USAGE_SENSOR_INCLINOMETER_3D, 0, 0, 17453293},
51 {HID_USAGE_SENSOR_INCLINOMETER_3D, 51 {HID_USAGE_SENSOR_INCLINOMETER_3D,
52 HID_USAGE_SENSOR_UNITS_DEGREES, 0, 17453}, 52 HID_USAGE_SENSOR_UNITS_DEGREES, 0, 17453293},
53 {HID_USAGE_SENSOR_INCLINOMETER_3D, 53 {HID_USAGE_SENSOR_INCLINOMETER_3D,
54 HID_USAGE_SENSOR_UNITS_RADIANS, 1, 0}, 54 HID_USAGE_SENSOR_UNITS_RADIANS, 1, 0},
55 55
@@ -57,7 +57,7 @@ static struct {
57 {HID_USAGE_SENSOR_ALS, HID_USAGE_SENSOR_UNITS_LUX, 1, 0}, 57 {HID_USAGE_SENSOR_ALS, HID_USAGE_SENSOR_UNITS_LUX, 1, 0},
58 58
59 {HID_USAGE_SENSOR_PRESSURE, 0, 100, 0}, 59 {HID_USAGE_SENSOR_PRESSURE, 0, 100, 0},
60 {HID_USAGE_SENSOR_PRESSURE, HID_USAGE_SENSOR_UNITS_PASCAL, 0, 1000}, 60 {HID_USAGE_SENSOR_PRESSURE, HID_USAGE_SENSOR_UNITS_PASCAL, 0, 1000000},
61}; 61};
62 62
63static int pow_10(unsigned power) 63static int pow_10(unsigned power)
@@ -266,15 +266,15 @@ EXPORT_SYMBOL(hid_sensor_write_raw_hyst_value);
266/* 266/*
267 * This fuction applies the unit exponent to the scale. 267 * This fuction applies the unit exponent to the scale.
268 * For example: 268 * For example:
269 * 9.806650 ->exp:2-> val0[980]val1[665000] 269 * 9.806650000 ->exp:2-> val0[980]val1[665000000]
270 * 9.000806 ->exp:2-> val0[900]val1[80600] 270 * 9.000806000 ->exp:2-> val0[900]val1[80600000]
271 * 0.174535 ->exp:2-> val0[17]val1[453500] 271 * 0.174535293 ->exp:2-> val0[17]val1[453529300]
272 * 1.001745 ->exp:0-> val0[1]val1[1745] 272 * 1.001745329 ->exp:0-> val0[1]val1[1745329]
273 * 1.001745 ->exp:2-> val0[100]val1[174500] 273 * 1.001745329 ->exp:2-> val0[100]val1[174532900]
274 * 1.001745 ->exp:4-> val0[10017]val1[450000] 274 * 1.001745329 ->exp:4-> val0[10017]val1[453290000]
275 * 9.806650 ->exp:-2-> val0[0]val1[98066] 275 * 9.806650000 ->exp:-2-> val0[0]val1[98066500]
276 */ 276 */
277static void adjust_exponent_micro(int *val0, int *val1, int scale0, 277static void adjust_exponent_nano(int *val0, int *val1, int scale0,
278 int scale1, int exp) 278 int scale1, int exp)
279{ 279{
280 int i; 280 int i;
@@ -285,32 +285,32 @@ static void adjust_exponent_micro(int *val0, int *val1, int scale0,
285 if (exp > 0) { 285 if (exp > 0) {
286 *val0 = scale0 * pow_10(exp); 286 *val0 = scale0 * pow_10(exp);
287 res = 0; 287 res = 0;
288 if (exp > 6) { 288 if (exp > 9) {
289 *val1 = 0; 289 *val1 = 0;
290 return; 290 return;
291 } 291 }
292 for (i = 0; i < exp; ++i) { 292 for (i = 0; i < exp; ++i) {
293 x = scale1 / pow_10(5 - i); 293 x = scale1 / pow_10(8 - i);
294 res += (pow_10(exp - 1 - i) * x); 294 res += (pow_10(exp - 1 - i) * x);
295 scale1 = scale1 % pow_10(5 - i); 295 scale1 = scale1 % pow_10(8 - i);
296 } 296 }
297 *val0 += res; 297 *val0 += res;
298 *val1 = scale1 * pow_10(exp); 298 *val1 = scale1 * pow_10(exp);
299 } else if (exp < 0) { 299 } else if (exp < 0) {
300 exp = abs(exp); 300 exp = abs(exp);
301 if (exp > 6) { 301 if (exp > 9) {
302 *val0 = *val1 = 0; 302 *val0 = *val1 = 0;
303 return; 303 return;
304 } 304 }
305 *val0 = scale0 / pow_10(exp); 305 *val0 = scale0 / pow_10(exp);
306 rem = scale0 % pow_10(exp); 306 rem = scale0 % pow_10(exp);
307 res = 0; 307 res = 0;
308 for (i = 0; i < (6 - exp); ++i) { 308 for (i = 0; i < (9 - exp); ++i) {
309 x = scale1 / pow_10(5 - i); 309 x = scale1 / pow_10(8 - i);
310 res += (pow_10(5 - exp - i) * x); 310 res += (pow_10(8 - exp - i) * x);
311 scale1 = scale1 % pow_10(5 - i); 311 scale1 = scale1 % pow_10(8 - i);
312 } 312 }
313 *val1 = rem * pow_10(6 - exp) + res; 313 *val1 = rem * pow_10(9 - exp) + res;
314 } else { 314 } else {
315 *val0 = scale0; 315 *val0 = scale0;
316 *val1 = scale1; 316 *val1 = scale1;
@@ -332,14 +332,14 @@ int hid_sensor_format_scale(u32 usage_id,
332 unit_conversion[i].unit == attr_info->units) { 332 unit_conversion[i].unit == attr_info->units) {
333 exp = hid_sensor_convert_exponent( 333 exp = hid_sensor_convert_exponent(
334 attr_info->unit_expo); 334 attr_info->unit_expo);
335 adjust_exponent_micro(val0, val1, 335 adjust_exponent_nano(val0, val1,
336 unit_conversion[i].scale_val0, 336 unit_conversion[i].scale_val0,
337 unit_conversion[i].scale_val1, exp); 337 unit_conversion[i].scale_val1, exp);
338 break; 338 break;
339 } 339 }
340 } 340 }
341 341
342 return IIO_VAL_INT_PLUS_MICRO; 342 return IIO_VAL_INT_PLUS_NANO;
343} 343}
344EXPORT_SYMBOL(hid_sensor_format_scale); 344EXPORT_SYMBOL(hid_sensor_format_scale);
345 345
diff --git a/drivers/iio/common/st_sensors/st_sensors_core.c b/drivers/iio/common/st_sensors/st_sensors_core.c
index 285a64a589d7..975a1f19f747 100644
--- a/drivers/iio/common/st_sensors/st_sensors_core.c
+++ b/drivers/iio/common/st_sensors/st_sensors_core.c
@@ -612,7 +612,7 @@ EXPORT_SYMBOL(st_sensors_sysfs_sampling_frequency_avail);
612ssize_t st_sensors_sysfs_scale_avail(struct device *dev, 612ssize_t st_sensors_sysfs_scale_avail(struct device *dev,
613 struct device_attribute *attr, char *buf) 613 struct device_attribute *attr, char *buf)
614{ 614{
615 int i, len = 0; 615 int i, len = 0, q, r;
616 struct iio_dev *indio_dev = dev_get_drvdata(dev); 616 struct iio_dev *indio_dev = dev_get_drvdata(dev);
617 struct st_sensor_data *sdata = iio_priv(indio_dev); 617 struct st_sensor_data *sdata = iio_priv(indio_dev);
618 618
@@ -621,8 +621,10 @@ ssize_t st_sensors_sysfs_scale_avail(struct device *dev,
621 if (sdata->sensor_settings->fs.fs_avl[i].num == 0) 621 if (sdata->sensor_settings->fs.fs_avl[i].num == 0)
622 break; 622 break;
623 623
624 len += scnprintf(buf + len, PAGE_SIZE - len, "0.%06u ", 624 q = sdata->sensor_settings->fs.fs_avl[i].gain / 1000000;
625 sdata->sensor_settings->fs.fs_avl[i].gain); 625 r = sdata->sensor_settings->fs.fs_avl[i].gain % 1000000;
626
627 len += scnprintf(buf + len, PAGE_SIZE - len, "%u.%06u ", q, r);
626 } 628 }
627 mutex_unlock(&indio_dev->mlock); 629 mutex_unlock(&indio_dev->mlock);
628 buf[len - 1] = '\n'; 630 buf[len - 1] = '\n';
diff --git a/drivers/iio/orientation/hid-sensor-rotation.c b/drivers/iio/orientation/hid-sensor-rotation.c
index b98b9d94d184..a97e802ca523 100644
--- a/drivers/iio/orientation/hid-sensor-rotation.c
+++ b/drivers/iio/orientation/hid-sensor-rotation.c
@@ -335,6 +335,7 @@ static struct platform_driver hid_dev_rot_platform_driver = {
335 .id_table = hid_dev_rot_ids, 335 .id_table = hid_dev_rot_ids,
336 .driver = { 336 .driver = {
337 .name = KBUILD_MODNAME, 337 .name = KBUILD_MODNAME,
338 .pm = &hid_sensor_pm_ops,
338 }, 339 },
339 .probe = hid_dev_rot_probe, 340 .probe = hid_dev_rot_probe,
340 .remove = hid_dev_rot_remove, 341 .remove = hid_dev_rot_remove,
diff --git a/drivers/iio/temperature/maxim_thermocouple.c b/drivers/iio/temperature/maxim_thermocouple.c
index 39dd2026ccc9..f962f31a5eb2 100644
--- a/drivers/iio/temperature/maxim_thermocouple.c
+++ b/drivers/iio/temperature/maxim_thermocouple.c
@@ -123,22 +123,26 @@ static int maxim_thermocouple_read(struct maxim_thermocouple_data *data,
123{ 123{
124 unsigned int storage_bytes = data->chip->read_size; 124 unsigned int storage_bytes = data->chip->read_size;
125 unsigned int shift = chan->scan_type.shift + (chan->address * 8); 125 unsigned int shift = chan->scan_type.shift + (chan->address * 8);
126 unsigned int buf; 126 __be16 buf16;
127 __be32 buf32;
127 int ret; 128 int ret;
128 129
129 ret = spi_read(data->spi, (void *) &buf, storage_bytes);
130 if (ret)
131 return ret;
132
133 switch (storage_bytes) { 130 switch (storage_bytes) {
134 case 2: 131 case 2:
135 *val = be16_to_cpu(buf); 132 ret = spi_read(data->spi, (void *)&buf16, storage_bytes);
133 *val = be16_to_cpu(buf16);
136 break; 134 break;
137 case 4: 135 case 4:
138 *val = be32_to_cpu(buf); 136 ret = spi_read(data->spi, (void *)&buf32, storage_bytes);
137 *val = be32_to_cpu(buf32);
139 break; 138 break;
139 default:
140 ret = -EINVAL;
140 } 141 }
141 142
143 if (ret)
144 return ret;
145
142 /* check to be sure this is a valid reading */ 146 /* check to be sure this is a valid reading */
143 if (*val & data->chip->status_bit) 147 if (*val & data->chip->status_bit)
144 return -EINVAL; 148 return -EINVAL;
diff --git a/drivers/infiniband/core/addr.c b/drivers/infiniband/core/addr.c
index b136d3acc5bd..0f58f46dbad7 100644
--- a/drivers/infiniband/core/addr.c
+++ b/drivers/infiniband/core/addr.c
@@ -699,13 +699,16 @@ EXPORT_SYMBOL(rdma_addr_cancel);
699struct resolve_cb_context { 699struct resolve_cb_context {
700 struct rdma_dev_addr *addr; 700 struct rdma_dev_addr *addr;
701 struct completion comp; 701 struct completion comp;
702 int status;
702}; 703};
703 704
704static void resolve_cb(int status, struct sockaddr *src_addr, 705static void resolve_cb(int status, struct sockaddr *src_addr,
705 struct rdma_dev_addr *addr, void *context) 706 struct rdma_dev_addr *addr, void *context)
706{ 707{
707 memcpy(((struct resolve_cb_context *)context)->addr, addr, sizeof(struct 708 if (!status)
708 rdma_dev_addr)); 709 memcpy(((struct resolve_cb_context *)context)->addr,
710 addr, sizeof(struct rdma_dev_addr));
711 ((struct resolve_cb_context *)context)->status = status;
709 complete(&((struct resolve_cb_context *)context)->comp); 712 complete(&((struct resolve_cb_context *)context)->comp);
710} 713}
711 714
@@ -743,6 +746,10 @@ int rdma_addr_find_l2_eth_by_grh(const union ib_gid *sgid,
743 746
744 wait_for_completion(&ctx.comp); 747 wait_for_completion(&ctx.comp);
745 748
749 ret = ctx.status;
750 if (ret)
751 return ret;
752
746 memcpy(dmac, dev_addr.dst_dev_addr, ETH_ALEN); 753 memcpy(dmac, dev_addr.dst_dev_addr, ETH_ALEN);
747 dev = dev_get_by_index(&init_net, dev_addr.bound_dev_if); 754 dev = dev_get_by_index(&init_net, dev_addr.bound_dev_if);
748 if (!dev) 755 if (!dev)
diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
index c99525512b34..71c7c4c328ef 100644
--- a/drivers/infiniband/core/cm.c
+++ b/drivers/infiniband/core/cm.c
@@ -80,6 +80,8 @@ static struct ib_cm {
80 __be32 random_id_operand; 80 __be32 random_id_operand;
81 struct list_head timewait_list; 81 struct list_head timewait_list;
82 struct workqueue_struct *wq; 82 struct workqueue_struct *wq;
83 /* Sync on cm change port state */
84 spinlock_t state_lock;
83} cm; 85} cm;
84 86
85/* Counter indexes ordered by attribute ID */ 87/* Counter indexes ordered by attribute ID */
@@ -161,6 +163,8 @@ struct cm_port {
161 struct ib_mad_agent *mad_agent; 163 struct ib_mad_agent *mad_agent;
162 struct kobject port_obj; 164 struct kobject port_obj;
163 u8 port_num; 165 u8 port_num;
166 struct list_head cm_priv_prim_list;
167 struct list_head cm_priv_altr_list;
164 struct cm_counter_group counter_group[CM_COUNTER_GROUPS]; 168 struct cm_counter_group counter_group[CM_COUNTER_GROUPS];
165}; 169};
166 170
@@ -241,6 +245,12 @@ struct cm_id_private {
241 u8 service_timeout; 245 u8 service_timeout;
242 u8 target_ack_delay; 246 u8 target_ack_delay;
243 247
248 struct list_head prim_list;
249 struct list_head altr_list;
250 /* Indicates that the send port mad is registered and av is set */
251 int prim_send_port_not_ready;
252 int altr_send_port_not_ready;
253
244 struct list_head work_list; 254 struct list_head work_list;
245 atomic_t work_count; 255 atomic_t work_count;
246}; 256};
@@ -259,20 +269,47 @@ static int cm_alloc_msg(struct cm_id_private *cm_id_priv,
259 struct ib_mad_agent *mad_agent; 269 struct ib_mad_agent *mad_agent;
260 struct ib_mad_send_buf *m; 270 struct ib_mad_send_buf *m;
261 struct ib_ah *ah; 271 struct ib_ah *ah;
272 struct cm_av *av;
273 unsigned long flags, flags2;
274 int ret = 0;
262 275
276 /* don't let the port to be released till the agent is down */
277 spin_lock_irqsave(&cm.state_lock, flags2);
278 spin_lock_irqsave(&cm.lock, flags);
279 if (!cm_id_priv->prim_send_port_not_ready)
280 av = &cm_id_priv->av;
281 else if (!cm_id_priv->altr_send_port_not_ready &&
282 (cm_id_priv->alt_av.port))
283 av = &cm_id_priv->alt_av;
284 else {
285 pr_info("%s: not valid CM id\n", __func__);
286 ret = -ENODEV;
287 spin_unlock_irqrestore(&cm.lock, flags);
288 goto out;
289 }
290 spin_unlock_irqrestore(&cm.lock, flags);
291 /* Make sure the port haven't released the mad yet */
263 mad_agent = cm_id_priv->av.port->mad_agent; 292 mad_agent = cm_id_priv->av.port->mad_agent;
264 ah = ib_create_ah(mad_agent->qp->pd, &cm_id_priv->av.ah_attr); 293 if (!mad_agent) {
265 if (IS_ERR(ah)) 294 pr_info("%s: not a valid MAD agent\n", __func__);
266 return PTR_ERR(ah); 295 ret = -ENODEV;
296 goto out;
297 }
298 ah = ib_create_ah(mad_agent->qp->pd, &av->ah_attr);
299 if (IS_ERR(ah)) {
300 ret = PTR_ERR(ah);
301 goto out;
302 }
267 303
268 m = ib_create_send_mad(mad_agent, cm_id_priv->id.remote_cm_qpn, 304 m = ib_create_send_mad(mad_agent, cm_id_priv->id.remote_cm_qpn,
269 cm_id_priv->av.pkey_index, 305 av->pkey_index,
270 0, IB_MGMT_MAD_HDR, IB_MGMT_MAD_DATA, 306 0, IB_MGMT_MAD_HDR, IB_MGMT_MAD_DATA,
271 GFP_ATOMIC, 307 GFP_ATOMIC,
272 IB_MGMT_BASE_VERSION); 308 IB_MGMT_BASE_VERSION);
273 if (IS_ERR(m)) { 309 if (IS_ERR(m)) {
274 ib_destroy_ah(ah); 310 ib_destroy_ah(ah);
275 return PTR_ERR(m); 311 ret = PTR_ERR(m);
312 goto out;
276 } 313 }
277 314
278 /* Timeout set by caller if response is expected. */ 315 /* Timeout set by caller if response is expected. */
@@ -282,7 +319,10 @@ static int cm_alloc_msg(struct cm_id_private *cm_id_priv,
282 atomic_inc(&cm_id_priv->refcount); 319 atomic_inc(&cm_id_priv->refcount);
283 m->context[0] = cm_id_priv; 320 m->context[0] = cm_id_priv;
284 *msg = m; 321 *msg = m;
285 return 0; 322
323out:
324 spin_unlock_irqrestore(&cm.state_lock, flags2);
325 return ret;
286} 326}
287 327
288static int cm_alloc_response_msg(struct cm_port *port, 328static int cm_alloc_response_msg(struct cm_port *port,
@@ -352,7 +392,8 @@ static void cm_init_av_for_response(struct cm_port *port, struct ib_wc *wc,
352 grh, &av->ah_attr); 392 grh, &av->ah_attr);
353} 393}
354 394
355static int cm_init_av_by_path(struct ib_sa_path_rec *path, struct cm_av *av) 395static int cm_init_av_by_path(struct ib_sa_path_rec *path, struct cm_av *av,
396 struct cm_id_private *cm_id_priv)
356{ 397{
357 struct cm_device *cm_dev; 398 struct cm_device *cm_dev;
358 struct cm_port *port = NULL; 399 struct cm_port *port = NULL;
@@ -387,7 +428,17 @@ static int cm_init_av_by_path(struct ib_sa_path_rec *path, struct cm_av *av)
387 &av->ah_attr); 428 &av->ah_attr);
388 av->timeout = path->packet_life_time + 1; 429 av->timeout = path->packet_life_time + 1;
389 430
390 return 0; 431 spin_lock_irqsave(&cm.lock, flags);
432 if (&cm_id_priv->av == av)
433 list_add_tail(&cm_id_priv->prim_list, &port->cm_priv_prim_list);
434 else if (&cm_id_priv->alt_av == av)
435 list_add_tail(&cm_id_priv->altr_list, &port->cm_priv_altr_list);
436 else
437 ret = -EINVAL;
438
439 spin_unlock_irqrestore(&cm.lock, flags);
440
441 return ret;
391} 442}
392 443
393static int cm_alloc_id(struct cm_id_private *cm_id_priv) 444static int cm_alloc_id(struct cm_id_private *cm_id_priv)
@@ -677,6 +728,8 @@ struct ib_cm_id *ib_create_cm_id(struct ib_device *device,
677 spin_lock_init(&cm_id_priv->lock); 728 spin_lock_init(&cm_id_priv->lock);
678 init_completion(&cm_id_priv->comp); 729 init_completion(&cm_id_priv->comp);
679 INIT_LIST_HEAD(&cm_id_priv->work_list); 730 INIT_LIST_HEAD(&cm_id_priv->work_list);
731 INIT_LIST_HEAD(&cm_id_priv->prim_list);
732 INIT_LIST_HEAD(&cm_id_priv->altr_list);
680 atomic_set(&cm_id_priv->work_count, -1); 733 atomic_set(&cm_id_priv->work_count, -1);
681 atomic_set(&cm_id_priv->refcount, 1); 734 atomic_set(&cm_id_priv->refcount, 1);
682 return &cm_id_priv->id; 735 return &cm_id_priv->id;
@@ -892,6 +945,15 @@ retest:
892 break; 945 break;
893 } 946 }
894 947
948 spin_lock_irq(&cm.lock);
949 if (!list_empty(&cm_id_priv->altr_list) &&
950 (!cm_id_priv->altr_send_port_not_ready))
951 list_del(&cm_id_priv->altr_list);
952 if (!list_empty(&cm_id_priv->prim_list) &&
953 (!cm_id_priv->prim_send_port_not_ready))
954 list_del(&cm_id_priv->prim_list);
955 spin_unlock_irq(&cm.lock);
956
895 cm_free_id(cm_id->local_id); 957 cm_free_id(cm_id->local_id);
896 cm_deref_id(cm_id_priv); 958 cm_deref_id(cm_id_priv);
897 wait_for_completion(&cm_id_priv->comp); 959 wait_for_completion(&cm_id_priv->comp);
@@ -1192,12 +1254,13 @@ int ib_send_cm_req(struct ib_cm_id *cm_id,
1192 goto out; 1254 goto out;
1193 } 1255 }
1194 1256
1195 ret = cm_init_av_by_path(param->primary_path, &cm_id_priv->av); 1257 ret = cm_init_av_by_path(param->primary_path, &cm_id_priv->av,
1258 cm_id_priv);
1196 if (ret) 1259 if (ret)
1197 goto error1; 1260 goto error1;
1198 if (param->alternate_path) { 1261 if (param->alternate_path) {
1199 ret = cm_init_av_by_path(param->alternate_path, 1262 ret = cm_init_av_by_path(param->alternate_path,
1200 &cm_id_priv->alt_av); 1263 &cm_id_priv->alt_av, cm_id_priv);
1201 if (ret) 1264 if (ret)
1202 goto error1; 1265 goto error1;
1203 } 1266 }
@@ -1653,7 +1716,8 @@ static int cm_req_handler(struct cm_work *work)
1653 dev_put(gid_attr.ndev); 1716 dev_put(gid_attr.ndev);
1654 } 1717 }
1655 work->path[0].gid_type = gid_attr.gid_type; 1718 work->path[0].gid_type = gid_attr.gid_type;
1656 ret = cm_init_av_by_path(&work->path[0], &cm_id_priv->av); 1719 ret = cm_init_av_by_path(&work->path[0], &cm_id_priv->av,
1720 cm_id_priv);
1657 } 1721 }
1658 if (ret) { 1722 if (ret) {
1659 int err = ib_get_cached_gid(work->port->cm_dev->ib_device, 1723 int err = ib_get_cached_gid(work->port->cm_dev->ib_device,
@@ -1672,7 +1736,8 @@ static int cm_req_handler(struct cm_work *work)
1672 goto rejected; 1736 goto rejected;
1673 } 1737 }
1674 if (req_msg->alt_local_lid) { 1738 if (req_msg->alt_local_lid) {
1675 ret = cm_init_av_by_path(&work->path[1], &cm_id_priv->alt_av); 1739 ret = cm_init_av_by_path(&work->path[1], &cm_id_priv->alt_av,
1740 cm_id_priv);
1676 if (ret) { 1741 if (ret) {
1677 ib_send_cm_rej(cm_id, IB_CM_REJ_INVALID_ALT_GID, 1742 ib_send_cm_rej(cm_id, IB_CM_REJ_INVALID_ALT_GID,
1678 &work->path[0].sgid, 1743 &work->path[0].sgid,
@@ -2727,7 +2792,8 @@ int ib_send_cm_lap(struct ib_cm_id *cm_id,
2727 goto out; 2792 goto out;
2728 } 2793 }
2729 2794
2730 ret = cm_init_av_by_path(alternate_path, &cm_id_priv->alt_av); 2795 ret = cm_init_av_by_path(alternate_path, &cm_id_priv->alt_av,
2796 cm_id_priv);
2731 if (ret) 2797 if (ret)
2732 goto out; 2798 goto out;
2733 cm_id_priv->alt_av.timeout = 2799 cm_id_priv->alt_av.timeout =
@@ -2839,7 +2905,8 @@ static int cm_lap_handler(struct cm_work *work)
2839 cm_init_av_for_response(work->port, work->mad_recv_wc->wc, 2905 cm_init_av_for_response(work->port, work->mad_recv_wc->wc,
2840 work->mad_recv_wc->recv_buf.grh, 2906 work->mad_recv_wc->recv_buf.grh,
2841 &cm_id_priv->av); 2907 &cm_id_priv->av);
2842 cm_init_av_by_path(param->alternate_path, &cm_id_priv->alt_av); 2908 cm_init_av_by_path(param->alternate_path, &cm_id_priv->alt_av,
2909 cm_id_priv);
2843 ret = atomic_inc_and_test(&cm_id_priv->work_count); 2910 ret = atomic_inc_and_test(&cm_id_priv->work_count);
2844 if (!ret) 2911 if (!ret)
2845 list_add_tail(&work->list, &cm_id_priv->work_list); 2912 list_add_tail(&work->list, &cm_id_priv->work_list);
@@ -3031,7 +3098,7 @@ int ib_send_cm_sidr_req(struct ib_cm_id *cm_id,
3031 return -EINVAL; 3098 return -EINVAL;
3032 3099
3033 cm_id_priv = container_of(cm_id, struct cm_id_private, id); 3100 cm_id_priv = container_of(cm_id, struct cm_id_private, id);
3034 ret = cm_init_av_by_path(param->path, &cm_id_priv->av); 3101 ret = cm_init_av_by_path(param->path, &cm_id_priv->av, cm_id_priv);
3035 if (ret) 3102 if (ret)
3036 goto out; 3103 goto out;
3037 3104
@@ -3468,7 +3535,9 @@ out:
3468static int cm_migrate(struct ib_cm_id *cm_id) 3535static int cm_migrate(struct ib_cm_id *cm_id)
3469{ 3536{
3470 struct cm_id_private *cm_id_priv; 3537 struct cm_id_private *cm_id_priv;
3538 struct cm_av tmp_av;
3471 unsigned long flags; 3539 unsigned long flags;
3540 int tmp_send_port_not_ready;
3472 int ret = 0; 3541 int ret = 0;
3473 3542
3474 cm_id_priv = container_of(cm_id, struct cm_id_private, id); 3543 cm_id_priv = container_of(cm_id, struct cm_id_private, id);
@@ -3477,7 +3546,14 @@ static int cm_migrate(struct ib_cm_id *cm_id)
3477 (cm_id->lap_state == IB_CM_LAP_UNINIT || 3546 (cm_id->lap_state == IB_CM_LAP_UNINIT ||
3478 cm_id->lap_state == IB_CM_LAP_IDLE)) { 3547 cm_id->lap_state == IB_CM_LAP_IDLE)) {
3479 cm_id->lap_state = IB_CM_LAP_IDLE; 3548 cm_id->lap_state = IB_CM_LAP_IDLE;
3549 /* Swap address vector */
3550 tmp_av = cm_id_priv->av;
3480 cm_id_priv->av = cm_id_priv->alt_av; 3551 cm_id_priv->av = cm_id_priv->alt_av;
3552 cm_id_priv->alt_av = tmp_av;
3553 /* Swap port send ready state */
3554 tmp_send_port_not_ready = cm_id_priv->prim_send_port_not_ready;
3555 cm_id_priv->prim_send_port_not_ready = cm_id_priv->altr_send_port_not_ready;
3556 cm_id_priv->altr_send_port_not_ready = tmp_send_port_not_ready;
3481 } else 3557 } else
3482 ret = -EINVAL; 3558 ret = -EINVAL;
3483 spin_unlock_irqrestore(&cm_id_priv->lock, flags); 3559 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
@@ -3888,6 +3964,9 @@ static void cm_add_one(struct ib_device *ib_device)
3888 port->cm_dev = cm_dev; 3964 port->cm_dev = cm_dev;
3889 port->port_num = i; 3965 port->port_num = i;
3890 3966
3967 INIT_LIST_HEAD(&port->cm_priv_prim_list);
3968 INIT_LIST_HEAD(&port->cm_priv_altr_list);
3969
3891 ret = cm_create_port_fs(port); 3970 ret = cm_create_port_fs(port);
3892 if (ret) 3971 if (ret)
3893 goto error1; 3972 goto error1;
@@ -3945,6 +4024,8 @@ static void cm_remove_one(struct ib_device *ib_device, void *client_data)
3945{ 4024{
3946 struct cm_device *cm_dev = client_data; 4025 struct cm_device *cm_dev = client_data;
3947 struct cm_port *port; 4026 struct cm_port *port;
4027 struct cm_id_private *cm_id_priv;
4028 struct ib_mad_agent *cur_mad_agent;
3948 struct ib_port_modify port_modify = { 4029 struct ib_port_modify port_modify = {
3949 .clr_port_cap_mask = IB_PORT_CM_SUP 4030 .clr_port_cap_mask = IB_PORT_CM_SUP
3950 }; 4031 };
@@ -3968,15 +4049,27 @@ static void cm_remove_one(struct ib_device *ib_device, void *client_data)
3968 4049
3969 port = cm_dev->port[i-1]; 4050 port = cm_dev->port[i-1];
3970 ib_modify_port(ib_device, port->port_num, 0, &port_modify); 4051 ib_modify_port(ib_device, port->port_num, 0, &port_modify);
4052 /* Mark all the cm_id's as not valid */
4053 spin_lock_irq(&cm.lock);
4054 list_for_each_entry(cm_id_priv, &port->cm_priv_altr_list, altr_list)
4055 cm_id_priv->altr_send_port_not_ready = 1;
4056 list_for_each_entry(cm_id_priv, &port->cm_priv_prim_list, prim_list)
4057 cm_id_priv->prim_send_port_not_ready = 1;
4058 spin_unlock_irq(&cm.lock);
3971 /* 4059 /*
3972 * We flush the queue here after the going_down set, this 4060 * We flush the queue here after the going_down set, this
3973 * verify that no new works will be queued in the recv handler, 4061 * verify that no new works will be queued in the recv handler,
3974 * after that we can call the unregister_mad_agent 4062 * after that we can call the unregister_mad_agent
3975 */ 4063 */
3976 flush_workqueue(cm.wq); 4064 flush_workqueue(cm.wq);
3977 ib_unregister_mad_agent(port->mad_agent); 4065 spin_lock_irq(&cm.state_lock);
4066 cur_mad_agent = port->mad_agent;
4067 port->mad_agent = NULL;
4068 spin_unlock_irq(&cm.state_lock);
4069 ib_unregister_mad_agent(cur_mad_agent);
3978 cm_remove_port_fs(port); 4070 cm_remove_port_fs(port);
3979 } 4071 }
4072
3980 device_unregister(cm_dev->device); 4073 device_unregister(cm_dev->device);
3981 kfree(cm_dev); 4074 kfree(cm_dev);
3982} 4075}
@@ -3989,6 +4082,7 @@ static int __init ib_cm_init(void)
3989 INIT_LIST_HEAD(&cm.device_list); 4082 INIT_LIST_HEAD(&cm.device_list);
3990 rwlock_init(&cm.device_lock); 4083 rwlock_init(&cm.device_lock);
3991 spin_lock_init(&cm.lock); 4084 spin_lock_init(&cm.lock);
4085 spin_lock_init(&cm.state_lock);
3992 cm.listen_service_table = RB_ROOT; 4086 cm.listen_service_table = RB_ROOT;
3993 cm.listen_service_id = be64_to_cpu(IB_CM_ASSIGN_SERVICE_ID); 4087 cm.listen_service_id = be64_to_cpu(IB_CM_ASSIGN_SERVICE_ID);
3994 cm.remote_id_table = RB_ROOT; 4088 cm.remote_id_table = RB_ROOT;
diff --git a/drivers/infiniband/core/cma.c b/drivers/infiniband/core/cma.c
index 36bf50ebb187..2a6fc47a1dfb 100644
--- a/drivers/infiniband/core/cma.c
+++ b/drivers/infiniband/core/cma.c
@@ -1094,47 +1094,47 @@ static void cma_save_ib_info(struct sockaddr *src_addr,
1094 } 1094 }
1095} 1095}
1096 1096
1097static void cma_save_ip4_info(struct sockaddr *src_addr, 1097static void cma_save_ip4_info(struct sockaddr_in *src_addr,
1098 struct sockaddr *dst_addr, 1098 struct sockaddr_in *dst_addr,
1099 struct cma_hdr *hdr, 1099 struct cma_hdr *hdr,
1100 __be16 local_port) 1100 __be16 local_port)
1101{ 1101{
1102 struct sockaddr_in *ip4;
1103
1104 if (src_addr) { 1102 if (src_addr) {
1105 ip4 = (struct sockaddr_in *)src_addr; 1103 *src_addr = (struct sockaddr_in) {
1106 ip4->sin_family = AF_INET; 1104 .sin_family = AF_INET,
1107 ip4->sin_addr.s_addr = hdr->dst_addr.ip4.addr; 1105 .sin_addr.s_addr = hdr->dst_addr.ip4.addr,
1108 ip4->sin_port = local_port; 1106 .sin_port = local_port,
1107 };
1109 } 1108 }
1110 1109
1111 if (dst_addr) { 1110 if (dst_addr) {
1112 ip4 = (struct sockaddr_in *)dst_addr; 1111 *dst_addr = (struct sockaddr_in) {
1113 ip4->sin_family = AF_INET; 1112 .sin_family = AF_INET,
1114 ip4->sin_addr.s_addr = hdr->src_addr.ip4.addr; 1113 .sin_addr.s_addr = hdr->src_addr.ip4.addr,
1115 ip4->sin_port = hdr->port; 1114 .sin_port = hdr->port,
1115 };
1116 } 1116 }
1117} 1117}
1118 1118
1119static void cma_save_ip6_info(struct sockaddr *src_addr, 1119static void cma_save_ip6_info(struct sockaddr_in6 *src_addr,
1120 struct sockaddr *dst_addr, 1120 struct sockaddr_in6 *dst_addr,
1121 struct cma_hdr *hdr, 1121 struct cma_hdr *hdr,
1122 __be16 local_port) 1122 __be16 local_port)
1123{ 1123{
1124 struct sockaddr_in6 *ip6;
1125
1126 if (src_addr) { 1124 if (src_addr) {
1127 ip6 = (struct sockaddr_in6 *)src_addr; 1125 *src_addr = (struct sockaddr_in6) {
1128 ip6->sin6_family = AF_INET6; 1126 .sin6_family = AF_INET6,
1129 ip6->sin6_addr = hdr->dst_addr.ip6; 1127 .sin6_addr = hdr->dst_addr.ip6,
1130 ip6->sin6_port = local_port; 1128 .sin6_port = local_port,
1129 };
1131 } 1130 }
1132 1131
1133 if (dst_addr) { 1132 if (dst_addr) {
1134 ip6 = (struct sockaddr_in6 *)dst_addr; 1133 *dst_addr = (struct sockaddr_in6) {
1135 ip6->sin6_family = AF_INET6; 1134 .sin6_family = AF_INET6,
1136 ip6->sin6_addr = hdr->src_addr.ip6; 1135 .sin6_addr = hdr->src_addr.ip6,
1137 ip6->sin6_port = hdr->port; 1136 .sin6_port = hdr->port,
1137 };
1138 } 1138 }
1139} 1139}
1140 1140
@@ -1159,10 +1159,12 @@ static int cma_save_ip_info(struct sockaddr *src_addr,
1159 1159
1160 switch (cma_get_ip_ver(hdr)) { 1160 switch (cma_get_ip_ver(hdr)) {
1161 case 4: 1161 case 4:
1162 cma_save_ip4_info(src_addr, dst_addr, hdr, port); 1162 cma_save_ip4_info((struct sockaddr_in *)src_addr,
1163 (struct sockaddr_in *)dst_addr, hdr, port);
1163 break; 1164 break;
1164 case 6: 1165 case 6:
1165 cma_save_ip6_info(src_addr, dst_addr, hdr, port); 1166 cma_save_ip6_info((struct sockaddr_in6 *)src_addr,
1167 (struct sockaddr_in6 *)dst_addr, hdr, port);
1166 break; 1168 break;
1167 default: 1169 default:
1168 return -EAFNOSUPPORT; 1170 return -EAFNOSUPPORT;
@@ -2436,6 +2438,18 @@ static int iboe_tos_to_sl(struct net_device *ndev, int tos)
2436 return 0; 2438 return 0;
2437} 2439}
2438 2440
2441static enum ib_gid_type cma_route_gid_type(enum rdma_network_type network_type,
2442 unsigned long supported_gids,
2443 enum ib_gid_type default_gid)
2444{
2445 if ((network_type == RDMA_NETWORK_IPV4 ||
2446 network_type == RDMA_NETWORK_IPV6) &&
2447 test_bit(IB_GID_TYPE_ROCE_UDP_ENCAP, &supported_gids))
2448 return IB_GID_TYPE_ROCE_UDP_ENCAP;
2449
2450 return default_gid;
2451}
2452
2439static int cma_resolve_iboe_route(struct rdma_id_private *id_priv) 2453static int cma_resolve_iboe_route(struct rdma_id_private *id_priv)
2440{ 2454{
2441 struct rdma_route *route = &id_priv->id.route; 2455 struct rdma_route *route = &id_priv->id.route;
@@ -2461,6 +2475,8 @@ static int cma_resolve_iboe_route(struct rdma_id_private *id_priv)
2461 route->num_paths = 1; 2475 route->num_paths = 1;
2462 2476
2463 if (addr->dev_addr.bound_dev_if) { 2477 if (addr->dev_addr.bound_dev_if) {
2478 unsigned long supported_gids;
2479
2464 ndev = dev_get_by_index(&init_net, addr->dev_addr.bound_dev_if); 2480 ndev = dev_get_by_index(&init_net, addr->dev_addr.bound_dev_if);
2465 if (!ndev) { 2481 if (!ndev) {
2466 ret = -ENODEV; 2482 ret = -ENODEV;
@@ -2484,7 +2500,12 @@ static int cma_resolve_iboe_route(struct rdma_id_private *id_priv)
2484 2500
2485 route->path_rec->net = &init_net; 2501 route->path_rec->net = &init_net;
2486 route->path_rec->ifindex = ndev->ifindex; 2502 route->path_rec->ifindex = ndev->ifindex;
2487 route->path_rec->gid_type = id_priv->gid_type; 2503 supported_gids = roce_gid_type_mask_support(id_priv->id.device,
2504 id_priv->id.port_num);
2505 route->path_rec->gid_type =
2506 cma_route_gid_type(addr->dev_addr.network,
2507 supported_gids,
2508 id_priv->gid_type);
2488 } 2509 }
2489 if (!ndev) { 2510 if (!ndev) {
2490 ret = -ENODEV; 2511 ret = -ENODEV;
diff --git a/drivers/infiniband/core/umem.c b/drivers/infiniband/core/umem.c
index c68746ce6624..84b4eff90395 100644
--- a/drivers/infiniband/core/umem.c
+++ b/drivers/infiniband/core/umem.c
@@ -94,6 +94,7 @@ struct ib_umem *ib_umem_get(struct ib_ucontext *context, unsigned long addr,
94 unsigned long dma_attrs = 0; 94 unsigned long dma_attrs = 0;
95 struct scatterlist *sg, *sg_list_start; 95 struct scatterlist *sg, *sg_list_start;
96 int need_release = 0; 96 int need_release = 0;
97 unsigned int gup_flags = FOLL_WRITE;
97 98
98 if (dmasync) 99 if (dmasync)
99 dma_attrs |= DMA_ATTR_WRITE_BARRIER; 100 dma_attrs |= DMA_ATTR_WRITE_BARRIER;
@@ -174,7 +175,7 @@ struct ib_umem *ib_umem_get(struct ib_ucontext *context, unsigned long addr,
174 175
175 cur_base = addr & PAGE_MASK; 176 cur_base = addr & PAGE_MASK;
176 177
177 if (npages == 0) { 178 if (npages == 0 || npages > UINT_MAX) {
178 ret = -EINVAL; 179 ret = -EINVAL;
179 goto out; 180 goto out;
180 } 181 }
@@ -183,6 +184,9 @@ struct ib_umem *ib_umem_get(struct ib_ucontext *context, unsigned long addr,
183 if (ret) 184 if (ret)
184 goto out; 185 goto out;
185 186
187 if (!umem->writable)
188 gup_flags |= FOLL_FORCE;
189
186 need_release = 1; 190 need_release = 1;
187 sg_list_start = umem->sg_head.sgl; 191 sg_list_start = umem->sg_head.sgl;
188 192
@@ -190,7 +194,7 @@ struct ib_umem *ib_umem_get(struct ib_ucontext *context, unsigned long addr,
190 ret = get_user_pages(cur_base, 194 ret = get_user_pages(cur_base,
191 min_t(unsigned long, npages, 195 min_t(unsigned long, npages,
192 PAGE_SIZE / sizeof (struct page *)), 196 PAGE_SIZE / sizeof (struct page *)),
193 1, !umem->writable, page_list, vma_list); 197 gup_flags, page_list, vma_list);
194 198
195 if (ret < 0) 199 if (ret < 0)
196 goto out; 200 goto out;
diff --git a/drivers/infiniband/core/umem_odp.c b/drivers/infiniband/core/umem_odp.c
index 75077a018675..1f0fe3217f23 100644
--- a/drivers/infiniband/core/umem_odp.c
+++ b/drivers/infiniband/core/umem_odp.c
@@ -527,6 +527,7 @@ int ib_umem_odp_map_dma_pages(struct ib_umem *umem, u64 user_virt, u64 bcnt,
527 u64 off; 527 u64 off;
528 int j, k, ret = 0, start_idx, npages = 0; 528 int j, k, ret = 0, start_idx, npages = 0;
529 u64 base_virt_addr; 529 u64 base_virt_addr;
530 unsigned int flags = 0;
530 531
531 if (access_mask == 0) 532 if (access_mask == 0)
532 return -EINVAL; 533 return -EINVAL;
@@ -556,6 +557,9 @@ int ib_umem_odp_map_dma_pages(struct ib_umem *umem, u64 user_virt, u64 bcnt,
556 goto out_put_task; 557 goto out_put_task;
557 } 558 }
558 559
560 if (access_mask & ODP_WRITE_ALLOWED_BIT)
561 flags |= FOLL_WRITE;
562
559 start_idx = (user_virt - ib_umem_start(umem)) >> PAGE_SHIFT; 563 start_idx = (user_virt - ib_umem_start(umem)) >> PAGE_SHIFT;
560 k = start_idx; 564 k = start_idx;
561 565
@@ -574,8 +578,7 @@ int ib_umem_odp_map_dma_pages(struct ib_umem *umem, u64 user_virt, u64 bcnt,
574 */ 578 */
575 npages = get_user_pages_remote(owning_process, owning_mm, 579 npages = get_user_pages_remote(owning_process, owning_mm,
576 user_virt, gup_num_pages, 580 user_virt, gup_num_pages,
577 access_mask & ODP_WRITE_ALLOWED_BIT, 581 flags, local_page_list, NULL);
578 0, local_page_list, NULL);
579 up_read(&owning_mm->mmap_sem); 582 up_read(&owning_mm->mmap_sem);
580 583
581 if (npages < 0) 584 if (npages < 0)
diff --git a/drivers/infiniband/core/uverbs_main.c b/drivers/infiniband/core/uverbs_main.c
index 0012fa58c105..44b1104eb168 100644
--- a/drivers/infiniband/core/uverbs_main.c
+++ b/drivers/infiniband/core/uverbs_main.c
@@ -262,12 +262,9 @@ static int ib_uverbs_cleanup_ucontext(struct ib_uverbs_file *file,
262 container_of(uobj, struct ib_uqp_object, uevent.uobject); 262 container_of(uobj, struct ib_uqp_object, uevent.uobject);
263 263
264 idr_remove_uobj(&ib_uverbs_qp_idr, uobj); 264 idr_remove_uobj(&ib_uverbs_qp_idr, uobj);
265 if (qp != qp->real_qp) { 265 if (qp == qp->real_qp)
266 ib_close_qp(qp);
267 } else {
268 ib_uverbs_detach_umcast(qp, uqp); 266 ib_uverbs_detach_umcast(qp, uqp);
269 ib_destroy_qp(qp); 267 ib_destroy_qp(qp);
270 }
271 ib_uverbs_release_uevent(file, &uqp->uevent); 268 ib_uverbs_release_uevent(file, &uqp->uevent);
272 kfree(uqp); 269 kfree(uqp);
273 } 270 }
diff --git a/drivers/infiniband/hw/cxgb4/cq.c b/drivers/infiniband/hw/cxgb4/cq.c
index 867b8cf82be8..19c6477af19f 100644
--- a/drivers/infiniband/hw/cxgb4/cq.c
+++ b/drivers/infiniband/hw/cxgb4/cq.c
@@ -666,18 +666,6 @@ skip_cqe:
666 return ret; 666 return ret;
667} 667}
668 668
669static void invalidate_mr(struct c4iw_dev *rhp, u32 rkey)
670{
671 struct c4iw_mr *mhp;
672 unsigned long flags;
673
674 spin_lock_irqsave(&rhp->lock, flags);
675 mhp = get_mhp(rhp, rkey >> 8);
676 if (mhp)
677 mhp->attr.state = 0;
678 spin_unlock_irqrestore(&rhp->lock, flags);
679}
680
681/* 669/*
682 * Get one cq entry from c4iw and map it to openib. 670 * Get one cq entry from c4iw and map it to openib.
683 * 671 *
@@ -733,7 +721,7 @@ static int c4iw_poll_cq_one(struct c4iw_cq *chp, struct ib_wc *wc)
733 CQE_OPCODE(&cqe) == FW_RI_SEND_WITH_SE_INV) { 721 CQE_OPCODE(&cqe) == FW_RI_SEND_WITH_SE_INV) {
734 wc->ex.invalidate_rkey = CQE_WRID_STAG(&cqe); 722 wc->ex.invalidate_rkey = CQE_WRID_STAG(&cqe);
735 wc->wc_flags |= IB_WC_WITH_INVALIDATE; 723 wc->wc_flags |= IB_WC_WITH_INVALIDATE;
736 invalidate_mr(qhp->rhp, wc->ex.invalidate_rkey); 724 c4iw_invalidate_mr(qhp->rhp, wc->ex.invalidate_rkey);
737 } 725 }
738 } else { 726 } else {
739 switch (CQE_OPCODE(&cqe)) { 727 switch (CQE_OPCODE(&cqe)) {
@@ -762,7 +750,8 @@ static int c4iw_poll_cq_one(struct c4iw_cq *chp, struct ib_wc *wc)
762 750
763 /* Invalidate the MR if the fastreg failed */ 751 /* Invalidate the MR if the fastreg failed */
764 if (CQE_STATUS(&cqe) != T4_ERR_SUCCESS) 752 if (CQE_STATUS(&cqe) != T4_ERR_SUCCESS)
765 invalidate_mr(qhp->rhp, CQE_WRID_FR_STAG(&cqe)); 753 c4iw_invalidate_mr(qhp->rhp,
754 CQE_WRID_FR_STAG(&cqe));
766 break; 755 break;
767 default: 756 default:
768 printk(KERN_ERR MOD "Unexpected opcode %d " 757 printk(KERN_ERR MOD "Unexpected opcode %d "
diff --git a/drivers/infiniband/hw/cxgb4/iw_cxgb4.h b/drivers/infiniband/hw/cxgb4/iw_cxgb4.h
index 7e7f79e55006..4788e1a46fde 100644
--- a/drivers/infiniband/hw/cxgb4/iw_cxgb4.h
+++ b/drivers/infiniband/hw/cxgb4/iw_cxgb4.h
@@ -999,6 +999,6 @@ extern int db_coalescing_threshold;
999extern int use_dsgl; 999extern int use_dsgl;
1000void c4iw_drain_rq(struct ib_qp *qp); 1000void c4iw_drain_rq(struct ib_qp *qp);
1001void c4iw_drain_sq(struct ib_qp *qp); 1001void c4iw_drain_sq(struct ib_qp *qp);
1002 1002void c4iw_invalidate_mr(struct c4iw_dev *rhp, u32 rkey);
1003 1003
1004#endif 1004#endif
diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
index 80e27749420a..410408f886c1 100644
--- a/drivers/infiniband/hw/cxgb4/mem.c
+++ b/drivers/infiniband/hw/cxgb4/mem.c
@@ -770,3 +770,15 @@ int c4iw_dereg_mr(struct ib_mr *ib_mr)
770 kfree(mhp); 770 kfree(mhp);
771 return 0; 771 return 0;
772} 772}
773
774void c4iw_invalidate_mr(struct c4iw_dev *rhp, u32 rkey)
775{
776 struct c4iw_mr *mhp;
777 unsigned long flags;
778
779 spin_lock_irqsave(&rhp->lock, flags);
780 mhp = get_mhp(rhp, rkey >> 8);
781 if (mhp)
782 mhp->attr.state = 0;
783 spin_unlock_irqrestore(&rhp->lock, flags);
784}
diff --git a/drivers/infiniband/hw/cxgb4/qp.c b/drivers/infiniband/hw/cxgb4/qp.c
index f57deba6717c..b7ac97b27c88 100644
--- a/drivers/infiniband/hw/cxgb4/qp.c
+++ b/drivers/infiniband/hw/cxgb4/qp.c
@@ -706,12 +706,8 @@ static int build_memreg(struct t4_sq *sq, union t4_wr *wqe,
706 return 0; 706 return 0;
707} 707}
708 708
709static int build_inv_stag(struct c4iw_dev *dev, union t4_wr *wqe, 709static int build_inv_stag(union t4_wr *wqe, struct ib_send_wr *wr, u8 *len16)
710 struct ib_send_wr *wr, u8 *len16)
711{ 710{
712 struct c4iw_mr *mhp = get_mhp(dev, wr->ex.invalidate_rkey >> 8);
713
714 mhp->attr.state = 0;
715 wqe->inv.stag_inv = cpu_to_be32(wr->ex.invalidate_rkey); 711 wqe->inv.stag_inv = cpu_to_be32(wr->ex.invalidate_rkey);
716 wqe->inv.r2 = 0; 712 wqe->inv.r2 = 0;
717 *len16 = DIV_ROUND_UP(sizeof wqe->inv, 16); 713 *len16 = DIV_ROUND_UP(sizeof wqe->inv, 16);
@@ -797,11 +793,13 @@ int c4iw_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
797 spin_lock_irqsave(&qhp->lock, flag); 793 spin_lock_irqsave(&qhp->lock, flag);
798 if (t4_wq_in_error(&qhp->wq)) { 794 if (t4_wq_in_error(&qhp->wq)) {
799 spin_unlock_irqrestore(&qhp->lock, flag); 795 spin_unlock_irqrestore(&qhp->lock, flag);
796 *bad_wr = wr;
800 return -EINVAL; 797 return -EINVAL;
801 } 798 }
802 num_wrs = t4_sq_avail(&qhp->wq); 799 num_wrs = t4_sq_avail(&qhp->wq);
803 if (num_wrs == 0) { 800 if (num_wrs == 0) {
804 spin_unlock_irqrestore(&qhp->lock, flag); 801 spin_unlock_irqrestore(&qhp->lock, flag);
802 *bad_wr = wr;
805 return -ENOMEM; 803 return -ENOMEM;
806 } 804 }
807 while (wr) { 805 while (wr) {
@@ -840,10 +838,13 @@ int c4iw_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
840 case IB_WR_RDMA_READ_WITH_INV: 838 case IB_WR_RDMA_READ_WITH_INV:
841 fw_opcode = FW_RI_RDMA_READ_WR; 839 fw_opcode = FW_RI_RDMA_READ_WR;
842 swsqe->opcode = FW_RI_READ_REQ; 840 swsqe->opcode = FW_RI_READ_REQ;
843 if (wr->opcode == IB_WR_RDMA_READ_WITH_INV) 841 if (wr->opcode == IB_WR_RDMA_READ_WITH_INV) {
842 c4iw_invalidate_mr(qhp->rhp,
843 wr->sg_list[0].lkey);
844 fw_flags = FW_RI_RDMA_READ_INVALIDATE; 844 fw_flags = FW_RI_RDMA_READ_INVALIDATE;
845 else 845 } else {
846 fw_flags = 0; 846 fw_flags = 0;
847 }
847 err = build_rdma_read(wqe, wr, &len16); 848 err = build_rdma_read(wqe, wr, &len16);
848 if (err) 849 if (err)
849 break; 850 break;
@@ -876,7 +877,8 @@ int c4iw_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
876 fw_flags |= FW_RI_LOCAL_FENCE_FLAG; 877 fw_flags |= FW_RI_LOCAL_FENCE_FLAG;
877 fw_opcode = FW_RI_INV_LSTAG_WR; 878 fw_opcode = FW_RI_INV_LSTAG_WR;
878 swsqe->opcode = FW_RI_LOCAL_INV; 879 swsqe->opcode = FW_RI_LOCAL_INV;
879 err = build_inv_stag(qhp->rhp, wqe, wr, &len16); 880 err = build_inv_stag(wqe, wr, &len16);
881 c4iw_invalidate_mr(qhp->rhp, wr->ex.invalidate_rkey);
880 break; 882 break;
881 default: 883 default:
882 PDBG("%s post of type=%d TBD!\n", __func__, 884 PDBG("%s post of type=%d TBD!\n", __func__,
@@ -934,11 +936,13 @@ int c4iw_post_receive(struct ib_qp *ibqp, struct ib_recv_wr *wr,
934 spin_lock_irqsave(&qhp->lock, flag); 936 spin_lock_irqsave(&qhp->lock, flag);
935 if (t4_wq_in_error(&qhp->wq)) { 937 if (t4_wq_in_error(&qhp->wq)) {
936 spin_unlock_irqrestore(&qhp->lock, flag); 938 spin_unlock_irqrestore(&qhp->lock, flag);
939 *bad_wr = wr;
937 return -EINVAL; 940 return -EINVAL;
938 } 941 }
939 num_wrs = t4_rq_avail(&qhp->wq); 942 num_wrs = t4_rq_avail(&qhp->wq);
940 if (num_wrs == 0) { 943 if (num_wrs == 0) {
941 spin_unlock_irqrestore(&qhp->lock, flag); 944 spin_unlock_irqrestore(&qhp->lock, flag);
945 *bad_wr = wr;
942 return -ENOMEM; 946 return -ENOMEM;
943 } 947 }
944 while (wr) { 948 while (wr) {
diff --git a/drivers/infiniband/hw/hfi1/affinity.c b/drivers/infiniband/hw/hfi1/affinity.c
index a26a9a0bfc41..67ea85a56945 100644
--- a/drivers/infiniband/hw/hfi1/affinity.c
+++ b/drivers/infiniband/hw/hfi1/affinity.c
@@ -775,75 +775,3 @@ void hfi1_put_proc_affinity(int cpu)
775 } 775 }
776 mutex_unlock(&affinity->lock); 776 mutex_unlock(&affinity->lock);
777} 777}
778
779int hfi1_set_sdma_affinity(struct hfi1_devdata *dd, const char *buf,
780 size_t count)
781{
782 struct hfi1_affinity_node *entry;
783 cpumask_var_t mask;
784 int ret, i;
785
786 mutex_lock(&node_affinity.lock);
787 entry = node_affinity_lookup(dd->node);
788
789 if (!entry) {
790 ret = -EINVAL;
791 goto unlock;
792 }
793
794 ret = zalloc_cpumask_var(&mask, GFP_KERNEL);
795 if (!ret) {
796 ret = -ENOMEM;
797 goto unlock;
798 }
799
800 ret = cpulist_parse(buf, mask);
801 if (ret)
802 goto out;
803
804 if (!cpumask_subset(mask, cpu_online_mask) || cpumask_empty(mask)) {
805 dd_dev_warn(dd, "Invalid CPU mask\n");
806 ret = -EINVAL;
807 goto out;
808 }
809
810 /* reset the SDMA interrupt affinity details */
811 init_cpu_mask_set(&entry->def_intr);
812 cpumask_copy(&entry->def_intr.mask, mask);
813
814 /* Reassign the affinity for each SDMA interrupt. */
815 for (i = 0; i < dd->num_msix_entries; i++) {
816 struct hfi1_msix_entry *msix;
817
818 msix = &dd->msix_entries[i];
819 if (msix->type != IRQ_SDMA)
820 continue;
821
822 ret = get_irq_affinity(dd, msix);
823
824 if (ret)
825 break;
826 }
827out:
828 free_cpumask_var(mask);
829unlock:
830 mutex_unlock(&node_affinity.lock);
831 return ret ? ret : strnlen(buf, PAGE_SIZE);
832}
833
834int hfi1_get_sdma_affinity(struct hfi1_devdata *dd, char *buf)
835{
836 struct hfi1_affinity_node *entry;
837
838 mutex_lock(&node_affinity.lock);
839 entry = node_affinity_lookup(dd->node);
840
841 if (!entry) {
842 mutex_unlock(&node_affinity.lock);
843 return -EINVAL;
844 }
845
846 cpumap_print_to_pagebuf(true, buf, &entry->def_intr.mask);
847 mutex_unlock(&node_affinity.lock);
848 return strnlen(buf, PAGE_SIZE);
849}
diff --git a/drivers/infiniband/hw/hfi1/affinity.h b/drivers/infiniband/hw/hfi1/affinity.h
index b89ea3c0ee1a..42e63316afd1 100644
--- a/drivers/infiniband/hw/hfi1/affinity.h
+++ b/drivers/infiniband/hw/hfi1/affinity.h
@@ -102,10 +102,6 @@ int hfi1_get_proc_affinity(int);
102/* Release a CPU used by a user process. */ 102/* Release a CPU used by a user process. */
103void hfi1_put_proc_affinity(int); 103void hfi1_put_proc_affinity(int);
104 104
105int hfi1_get_sdma_affinity(struct hfi1_devdata *dd, char *buf);
106int hfi1_set_sdma_affinity(struct hfi1_devdata *dd, const char *buf,
107 size_t count);
108
109struct hfi1_affinity_node { 105struct hfi1_affinity_node {
110 int node; 106 int node;
111 struct cpu_mask_set def_intr; 107 struct cpu_mask_set def_intr;
diff --git a/drivers/infiniband/hw/hfi1/chip.c b/drivers/infiniband/hw/hfi1/chip.c
index 9bf5f23544d4..24d0820873cf 100644
--- a/drivers/infiniband/hw/hfi1/chip.c
+++ b/drivers/infiniband/hw/hfi1/chip.c
@@ -6301,19 +6301,8 @@ void set_up_vl15(struct hfi1_devdata *dd, u8 vau, u16 vl15buf)
6301 /* leave shared count at zero for both global and VL15 */ 6301 /* leave shared count at zero for both global and VL15 */
6302 write_global_credit(dd, vau, vl15buf, 0); 6302 write_global_credit(dd, vau, vl15buf, 0);
6303 6303
6304 /* We may need some credits for another VL when sending packets 6304 write_csr(dd, SEND_CM_CREDIT_VL15, (u64)vl15buf
6305 * with the snoop interface. Dividing it down the middle for VL15 6305 << SEND_CM_CREDIT_VL15_DEDICATED_LIMIT_VL_SHIFT);
6306 * and VL0 should suffice.
6307 */
6308 if (unlikely(dd->hfi1_snoop.mode_flag == HFI1_PORT_SNOOP_MODE)) {
6309 write_csr(dd, SEND_CM_CREDIT_VL15, (u64)(vl15buf >> 1)
6310 << SEND_CM_CREDIT_VL15_DEDICATED_LIMIT_VL_SHIFT);
6311 write_csr(dd, SEND_CM_CREDIT_VL, (u64)(vl15buf >> 1)
6312 << SEND_CM_CREDIT_VL_DEDICATED_LIMIT_VL_SHIFT);
6313 } else {
6314 write_csr(dd, SEND_CM_CREDIT_VL15, (u64)vl15buf
6315 << SEND_CM_CREDIT_VL15_DEDICATED_LIMIT_VL_SHIFT);
6316 }
6317} 6306}
6318 6307
6319/* 6308/*
@@ -9915,9 +9904,6 @@ static void set_lidlmc(struct hfi1_pportdata *ppd)
9915 u32 mask = ~((1U << ppd->lmc) - 1); 9904 u32 mask = ~((1U << ppd->lmc) - 1);
9916 u64 c1 = read_csr(ppd->dd, DCC_CFG_PORT_CONFIG1); 9905 u64 c1 = read_csr(ppd->dd, DCC_CFG_PORT_CONFIG1);
9917 9906
9918 if (dd->hfi1_snoop.mode_flag)
9919 dd_dev_info(dd, "Set lid/lmc while snooping");
9920
9921 c1 &= ~(DCC_CFG_PORT_CONFIG1_TARGET_DLID_SMASK 9907 c1 &= ~(DCC_CFG_PORT_CONFIG1_TARGET_DLID_SMASK
9922 | DCC_CFG_PORT_CONFIG1_DLID_MASK_SMASK); 9908 | DCC_CFG_PORT_CONFIG1_DLID_MASK_SMASK);
9923 c1 |= ((ppd->lid & DCC_CFG_PORT_CONFIG1_TARGET_DLID_MASK) 9909 c1 |= ((ppd->lid & DCC_CFG_PORT_CONFIG1_TARGET_DLID_MASK)
@@ -12112,7 +12098,7 @@ static void update_synth_timer(unsigned long opaque)
12112 mod_timer(&dd->synth_stats_timer, jiffies + HZ * SYNTH_CNT_TIME); 12098 mod_timer(&dd->synth_stats_timer, jiffies + HZ * SYNTH_CNT_TIME);
12113} 12099}
12114 12100
12115#define C_MAX_NAME 13 /* 12 chars + one for /0 */ 12101#define C_MAX_NAME 16 /* 15 chars + one for /0 */
12116static int init_cntrs(struct hfi1_devdata *dd) 12102static int init_cntrs(struct hfi1_devdata *dd)
12117{ 12103{
12118 int i, rcv_ctxts, j; 12104 int i, rcv_ctxts, j;
@@ -14463,7 +14449,7 @@ struct hfi1_devdata *hfi1_init_dd(struct pci_dev *pdev,
14463 * Any error printing is already done by the init code. 14449 * Any error printing is already done by the init code.
14464 * On return, we have the chip mapped. 14450 * On return, we have the chip mapped.
14465 */ 14451 */
14466 ret = hfi1_pcie_ddinit(dd, pdev, ent); 14452 ret = hfi1_pcie_ddinit(dd, pdev);
14467 if (ret < 0) 14453 if (ret < 0)
14468 goto bail_free; 14454 goto bail_free;
14469 14455
@@ -14691,6 +14677,11 @@ struct hfi1_devdata *hfi1_init_dd(struct pci_dev *pdev,
14691 if (ret) 14677 if (ret)
14692 goto bail_free_cntrs; 14678 goto bail_free_cntrs;
14693 14679
14680 init_completion(&dd->user_comp);
14681
14682 /* The user refcount starts with one to inidicate an active device */
14683 atomic_set(&dd->user_refcount, 1);
14684
14694 goto bail; 14685 goto bail;
14695 14686
14696bail_free_rcverr: 14687bail_free_rcverr:
diff --git a/drivers/infiniband/hw/hfi1/chip.h b/drivers/infiniband/hw/hfi1/chip.h
index 92345259a8f4..043fd21dc5f3 100644
--- a/drivers/infiniband/hw/hfi1/chip.h
+++ b/drivers/infiniband/hw/hfi1/chip.h
@@ -320,6 +320,9 @@
320/* DC_DC8051_CFG_MODE.GENERAL bits */ 320/* DC_DC8051_CFG_MODE.GENERAL bits */
321#define DISABLE_SELF_GUID_CHECK 0x2 321#define DISABLE_SELF_GUID_CHECK 0x2
322 322
323/* Bad L2 frame error code */
324#define BAD_L2_ERR 0x6
325
323/* 326/*
324 * Eager buffer minimum and maximum sizes supported by the hardware. 327 * Eager buffer minimum and maximum sizes supported by the hardware.
325 * All power-of-two sizes in between are supported as well. 328 * All power-of-two sizes in between are supported as well.
diff --git a/drivers/infiniband/hw/hfi1/driver.c b/drivers/infiniband/hw/hfi1/driver.c
index 6563e4d38b80..c5efff29c147 100644
--- a/drivers/infiniband/hw/hfi1/driver.c
+++ b/drivers/infiniband/hw/hfi1/driver.c
@@ -599,7 +599,6 @@ static void __prescan_rxq(struct hfi1_packet *packet)
599 dd->rhf_offset; 599 dd->rhf_offset;
600 struct rvt_qp *qp; 600 struct rvt_qp *qp;
601 struct ib_header *hdr; 601 struct ib_header *hdr;
602 struct ib_other_headers *ohdr;
603 struct rvt_dev_info *rdi = &dd->verbs_dev.rdi; 602 struct rvt_dev_info *rdi = &dd->verbs_dev.rdi;
604 u64 rhf = rhf_to_cpu(rhf_addr); 603 u64 rhf = rhf_to_cpu(rhf_addr);
605 u32 etype = rhf_rcv_type(rhf), qpn, bth1; 604 u32 etype = rhf_rcv_type(rhf), qpn, bth1;
@@ -615,18 +614,21 @@ static void __prescan_rxq(struct hfi1_packet *packet)
615 if (etype != RHF_RCV_TYPE_IB) 614 if (etype != RHF_RCV_TYPE_IB)
616 goto next; 615 goto next;
617 616
618 hdr = hfi1_get_msgheader(dd, rhf_addr); 617 packet->hdr = hfi1_get_msgheader(dd, rhf_addr);
618 hdr = packet->hdr;
619 619
620 lnh = be16_to_cpu(hdr->lrh[0]) & 3; 620 lnh = be16_to_cpu(hdr->lrh[0]) & 3;
621 621
622 if (lnh == HFI1_LRH_BTH) 622 if (lnh == HFI1_LRH_BTH) {
623 ohdr = &hdr->u.oth; 623 packet->ohdr = &hdr->u.oth;
624 else if (lnh == HFI1_LRH_GRH) 624 } else if (lnh == HFI1_LRH_GRH) {
625 ohdr = &hdr->u.l.oth; 625 packet->ohdr = &hdr->u.l.oth;
626 else 626 packet->rcv_flags |= HFI1_HAS_GRH;
627 } else {
627 goto next; /* just in case */ 628 goto next; /* just in case */
629 }
628 630
629 bth1 = be32_to_cpu(ohdr->bth[1]); 631 bth1 = be32_to_cpu(packet->ohdr->bth[1]);
630 is_ecn = !!(bth1 & (HFI1_FECN_SMASK | HFI1_BECN_SMASK)); 632 is_ecn = !!(bth1 & (HFI1_FECN_SMASK | HFI1_BECN_SMASK));
631 633
632 if (!is_ecn) 634 if (!is_ecn)
@@ -646,7 +648,7 @@ static void __prescan_rxq(struct hfi1_packet *packet)
646 648
647 /* turn off BECN, FECN */ 649 /* turn off BECN, FECN */
648 bth1 &= ~(HFI1_FECN_SMASK | HFI1_BECN_SMASK); 650 bth1 &= ~(HFI1_FECN_SMASK | HFI1_BECN_SMASK);
649 ohdr->bth[1] = cpu_to_be32(bth1); 651 packet->ohdr->bth[1] = cpu_to_be32(bth1);
650next: 652next:
651 update_ps_mdata(&mdata, rcd); 653 update_ps_mdata(&mdata, rcd);
652 } 654 }
@@ -1360,12 +1362,25 @@ int process_receive_ib(struct hfi1_packet *packet)
1360 1362
1361int process_receive_bypass(struct hfi1_packet *packet) 1363int process_receive_bypass(struct hfi1_packet *packet)
1362{ 1364{
1365 struct hfi1_devdata *dd = packet->rcd->dd;
1366
1363 if (unlikely(rhf_err_flags(packet->rhf))) 1367 if (unlikely(rhf_err_flags(packet->rhf)))
1364 handle_eflags(packet); 1368 handle_eflags(packet);
1365 1369
1366 dd_dev_err(packet->rcd->dd, 1370 dd_dev_err(dd,
1367 "Bypass packets are not supported in normal operation. Dropping\n"); 1371 "Bypass packets are not supported in normal operation. Dropping\n");
1368 incr_cntr64(&packet->rcd->dd->sw_rcv_bypass_packet_errors); 1372 incr_cntr64(&dd->sw_rcv_bypass_packet_errors);
1373 if (!(dd->err_info_rcvport.status_and_code & OPA_EI_STATUS_SMASK)) {
1374 u64 *flits = packet->ebuf;
1375
1376 if (flits && !(packet->rhf & RHF_LEN_ERR)) {
1377 dd->err_info_rcvport.packet_flit1 = flits[0];
1378 dd->err_info_rcvport.packet_flit2 =
1379 packet->tlen > sizeof(flits[0]) ? flits[1] : 0;
1380 }
1381 dd->err_info_rcvport.status_and_code |=
1382 (OPA_EI_STATUS_SMASK | BAD_L2_ERR);
1383 }
1369 return RHF_RCV_CONTINUE; 1384 return RHF_RCV_CONTINUE;
1370} 1385}
1371 1386
diff --git a/drivers/infiniband/hw/hfi1/file_ops.c b/drivers/infiniband/hw/hfi1/file_ops.c
index 677efa0e8cd6..bd786b7bd30b 100644
--- a/drivers/infiniband/hw/hfi1/file_ops.c
+++ b/drivers/infiniband/hw/hfi1/file_ops.c
@@ -172,6 +172,9 @@ static int hfi1_file_open(struct inode *inode, struct file *fp)
172 struct hfi1_devdata, 172 struct hfi1_devdata,
173 user_cdev); 173 user_cdev);
174 174
175 if (!atomic_inc_not_zero(&dd->user_refcount))
176 return -ENXIO;
177
175 /* Just take a ref now. Not all opens result in a context assign */ 178 /* Just take a ref now. Not all opens result in a context assign */
176 kobject_get(&dd->kobj); 179 kobject_get(&dd->kobj);
177 180
@@ -183,11 +186,17 @@ static int hfi1_file_open(struct inode *inode, struct file *fp)
183 fd->rec_cpu_num = -1; /* no cpu affinity by default */ 186 fd->rec_cpu_num = -1; /* no cpu affinity by default */
184 fd->mm = current->mm; 187 fd->mm = current->mm;
185 atomic_inc(&fd->mm->mm_count); 188 atomic_inc(&fd->mm->mm_count);
186 } 189 fp->private_data = fd;
190 } else {
191 fp->private_data = NULL;
192
193 if (atomic_dec_and_test(&dd->user_refcount))
194 complete(&dd->user_comp);
187 195
188 fp->private_data = fd; 196 return -ENOMEM;
197 }
189 198
190 return fd ? 0 : -ENOMEM; 199 return 0;
191} 200}
192 201
193static long hfi1_file_ioctl(struct file *fp, unsigned int cmd, 202static long hfi1_file_ioctl(struct file *fp, unsigned int cmd,
@@ -798,6 +807,10 @@ static int hfi1_file_close(struct inode *inode, struct file *fp)
798done: 807done:
799 mmdrop(fdata->mm); 808 mmdrop(fdata->mm);
800 kobject_put(&dd->kobj); 809 kobject_put(&dd->kobj);
810
811 if (atomic_dec_and_test(&dd->user_refcount))
812 complete(&dd->user_comp);
813
801 kfree(fdata); 814 kfree(fdata);
802 return 0; 815 return 0;
803} 816}
diff --git a/drivers/infiniband/hw/hfi1/hfi.h b/drivers/infiniband/hw/hfi1/hfi.h
index 7eef11b316ff..cc87fd4e534b 100644
--- a/drivers/infiniband/hw/hfi1/hfi.h
+++ b/drivers/infiniband/hw/hfi1/hfi.h
@@ -367,26 +367,6 @@ struct hfi1_packet {
367 u8 etype; 367 u8 etype;
368}; 368};
369 369
370/*
371 * Private data for snoop/capture support.
372 */
373struct hfi1_snoop_data {
374 int mode_flag;
375 struct cdev cdev;
376 struct device *class_dev;
377 /* protect snoop data */
378 spinlock_t snoop_lock;
379 struct list_head queue;
380 wait_queue_head_t waitq;
381 void *filter_value;
382 int (*filter_callback)(void *hdr, void *data, void *value);
383 u64 dcc_cfg; /* saved value of DCC Cfg register */
384};
385
386/* snoop mode_flag values */
387#define HFI1_PORT_SNOOP_MODE 1U
388#define HFI1_PORT_CAPTURE_MODE 2U
389
390struct rvt_sge_state; 370struct rvt_sge_state;
391 371
392/* 372/*
@@ -613,8 +593,6 @@ struct hfi1_pportdata {
613 struct mutex hls_lock; 593 struct mutex hls_lock;
614 u32 host_link_state; 594 u32 host_link_state;
615 595
616 spinlock_t sdma_alllock ____cacheline_aligned_in_smp;
617
618 u32 lstate; /* logical link state */ 596 u32 lstate; /* logical link state */
619 597
620 /* these are the "32 bit" regs */ 598 /* these are the "32 bit" regs */
@@ -1104,8 +1082,6 @@ struct hfi1_devdata {
1104 char *portcntrnames; 1082 char *portcntrnames;
1105 size_t portcntrnameslen; 1083 size_t portcntrnameslen;
1106 1084
1107 struct hfi1_snoop_data hfi1_snoop;
1108
1109 struct err_info_rcvport err_info_rcvport; 1085 struct err_info_rcvport err_info_rcvport;
1110 struct err_info_constraint err_info_rcv_constraint; 1086 struct err_info_constraint err_info_rcv_constraint;
1111 struct err_info_constraint err_info_xmit_constraint; 1087 struct err_info_constraint err_info_xmit_constraint;
@@ -1141,8 +1117,8 @@ struct hfi1_devdata {
1141 rhf_rcv_function_ptr normal_rhf_rcv_functions[8]; 1117 rhf_rcv_function_ptr normal_rhf_rcv_functions[8];
1142 1118
1143 /* 1119 /*
1144 * Handlers for outgoing data so that snoop/capture does not 1120 * Capability to have different send engines simply by changing a
1145 * have to have its hooks in the send path 1121 * pointer value.
1146 */ 1122 */
1147 send_routine process_pio_send; 1123 send_routine process_pio_send;
1148 send_routine process_dma_send; 1124 send_routine process_dma_send;
@@ -1174,6 +1150,10 @@ struct hfi1_devdata {
1174 spinlock_t aspm_lock; 1150 spinlock_t aspm_lock;
1175 /* Number of verbs contexts which have disabled ASPM */ 1151 /* Number of verbs contexts which have disabled ASPM */
1176 atomic_t aspm_disabled_cnt; 1152 atomic_t aspm_disabled_cnt;
1153 /* Keeps track of user space clients */
1154 atomic_t user_refcount;
1155 /* Used to wait for outstanding user space clients before dev removal */
1156 struct completion user_comp;
1177 1157
1178 struct hfi1_affinity *affinity; 1158 struct hfi1_affinity *affinity;
1179 struct rhashtable sdma_rht; 1159 struct rhashtable sdma_rht;
@@ -1221,8 +1201,6 @@ struct hfi1_devdata *hfi1_lookup(int unit);
1221extern u32 hfi1_cpulist_count; 1201extern u32 hfi1_cpulist_count;
1222extern unsigned long *hfi1_cpulist; 1202extern unsigned long *hfi1_cpulist;
1223 1203
1224extern unsigned int snoop_drop_send;
1225extern unsigned int snoop_force_capture;
1226int hfi1_init(struct hfi1_devdata *, int); 1204int hfi1_init(struct hfi1_devdata *, int);
1227int hfi1_count_units(int *npresentp, int *nupp); 1205int hfi1_count_units(int *npresentp, int *nupp);
1228int hfi1_count_active_units(void); 1206int hfi1_count_active_units(void);
@@ -1557,13 +1535,6 @@ void set_up_vl15(struct hfi1_devdata *dd, u8 vau, u16 vl15buf);
1557void reset_link_credits(struct hfi1_devdata *dd); 1535void reset_link_credits(struct hfi1_devdata *dd);
1558void assign_remote_cm_au_table(struct hfi1_devdata *dd, u8 vcu); 1536void assign_remote_cm_au_table(struct hfi1_devdata *dd, u8 vcu);
1559 1537
1560int snoop_recv_handler(struct hfi1_packet *packet);
1561int snoop_send_dma_handler(struct rvt_qp *qp, struct hfi1_pkt_state *ps,
1562 u64 pbc);
1563int snoop_send_pio_handler(struct rvt_qp *qp, struct hfi1_pkt_state *ps,
1564 u64 pbc);
1565void snoop_inline_pio_send(struct hfi1_devdata *dd, struct pio_buf *pbuf,
1566 u64 pbc, const void *from, size_t count);
1567int set_buffer_control(struct hfi1_pportdata *ppd, struct buffer_control *bc); 1538int set_buffer_control(struct hfi1_pportdata *ppd, struct buffer_control *bc);
1568 1539
1569static inline struct hfi1_devdata *dd_from_ppd(struct hfi1_pportdata *ppd) 1540static inline struct hfi1_devdata *dd_from_ppd(struct hfi1_pportdata *ppd)
@@ -1763,8 +1734,7 @@ int qsfp_dump(struct hfi1_pportdata *ppd, char *buf, int len);
1763 1734
1764int hfi1_pcie_init(struct pci_dev *, const struct pci_device_id *); 1735int hfi1_pcie_init(struct pci_dev *, const struct pci_device_id *);
1765void hfi1_pcie_cleanup(struct pci_dev *); 1736void hfi1_pcie_cleanup(struct pci_dev *);
1766int hfi1_pcie_ddinit(struct hfi1_devdata *, struct pci_dev *, 1737int hfi1_pcie_ddinit(struct hfi1_devdata *, struct pci_dev *);
1767 const struct pci_device_id *);
1768void hfi1_pcie_ddcleanup(struct hfi1_devdata *); 1738void hfi1_pcie_ddcleanup(struct hfi1_devdata *);
1769void hfi1_pcie_flr(struct hfi1_devdata *); 1739void hfi1_pcie_flr(struct hfi1_devdata *);
1770int pcie_speeds(struct hfi1_devdata *); 1740int pcie_speeds(struct hfi1_devdata *);
@@ -1799,8 +1769,6 @@ int kdeth_process_expected(struct hfi1_packet *packet);
1799int kdeth_process_eager(struct hfi1_packet *packet); 1769int kdeth_process_eager(struct hfi1_packet *packet);
1800int process_receive_invalid(struct hfi1_packet *packet); 1770int process_receive_invalid(struct hfi1_packet *packet);
1801 1771
1802extern rhf_rcv_function_ptr snoop_rhf_rcv_functions[8];
1803
1804void update_sge(struct rvt_sge_state *ss, u32 length); 1772void update_sge(struct rvt_sge_state *ss, u32 length);
1805 1773
1806/* global module parameter variables */ 1774/* global module parameter variables */
@@ -1827,9 +1795,6 @@ extern struct mutex hfi1_mutex;
1827#define DRIVER_NAME "hfi1" 1795#define DRIVER_NAME "hfi1"
1828#define HFI1_USER_MINOR_BASE 0 1796#define HFI1_USER_MINOR_BASE 0
1829#define HFI1_TRACE_MINOR 127 1797#define HFI1_TRACE_MINOR 127
1830#define HFI1_DIAGPKT_MINOR 128
1831#define HFI1_DIAG_MINOR_BASE 129
1832#define HFI1_SNOOP_CAPTURE_BASE 200
1833#define HFI1_NMINORS 255 1798#define HFI1_NMINORS 255
1834 1799
1835#define PCI_VENDOR_ID_INTEL 0x8086 1800#define PCI_VENDOR_ID_INTEL 0x8086
@@ -1848,7 +1813,13 @@ extern struct mutex hfi1_mutex;
1848static inline u64 hfi1_pkt_default_send_ctxt_mask(struct hfi1_devdata *dd, 1813static inline u64 hfi1_pkt_default_send_ctxt_mask(struct hfi1_devdata *dd,
1849 u16 ctxt_type) 1814 u16 ctxt_type)
1850{ 1815{
1851 u64 base_sc_integrity = 1816 u64 base_sc_integrity;
1817
1818 /* No integrity checks if HFI1_CAP_NO_INTEGRITY is set */
1819 if (HFI1_CAP_IS_KSET(NO_INTEGRITY))
1820 return 0;
1821
1822 base_sc_integrity =
1852 SEND_CTXT_CHECK_ENABLE_DISALLOW_BYPASS_BAD_PKT_LEN_SMASK 1823 SEND_CTXT_CHECK_ENABLE_DISALLOW_BYPASS_BAD_PKT_LEN_SMASK
1853 | SEND_CTXT_CHECK_ENABLE_DISALLOW_PBC_STATIC_RATE_CONTROL_SMASK 1824 | SEND_CTXT_CHECK_ENABLE_DISALLOW_PBC_STATIC_RATE_CONTROL_SMASK
1854 | SEND_CTXT_CHECK_ENABLE_DISALLOW_TOO_LONG_BYPASS_PACKETS_SMASK 1825 | SEND_CTXT_CHECK_ENABLE_DISALLOW_TOO_LONG_BYPASS_PACKETS_SMASK
@@ -1863,7 +1834,6 @@ static inline u64 hfi1_pkt_default_send_ctxt_mask(struct hfi1_devdata *dd,
1863 | SEND_CTXT_CHECK_ENABLE_CHECK_VL_MAPPING_SMASK 1834 | SEND_CTXT_CHECK_ENABLE_CHECK_VL_MAPPING_SMASK
1864 | SEND_CTXT_CHECK_ENABLE_CHECK_OPCODE_SMASK 1835 | SEND_CTXT_CHECK_ENABLE_CHECK_OPCODE_SMASK
1865 | SEND_CTXT_CHECK_ENABLE_CHECK_SLID_SMASK 1836 | SEND_CTXT_CHECK_ENABLE_CHECK_SLID_SMASK
1866 | SEND_CTXT_CHECK_ENABLE_CHECK_JOB_KEY_SMASK
1867 | SEND_CTXT_CHECK_ENABLE_CHECK_VL_SMASK 1837 | SEND_CTXT_CHECK_ENABLE_CHECK_VL_SMASK
1868 | SEND_CTXT_CHECK_ENABLE_CHECK_ENABLE_SMASK; 1838 | SEND_CTXT_CHECK_ENABLE_CHECK_ENABLE_SMASK;
1869 1839
@@ -1872,18 +1842,23 @@ static inline u64 hfi1_pkt_default_send_ctxt_mask(struct hfi1_devdata *dd,
1872 else 1842 else
1873 base_sc_integrity |= HFI1_PKT_KERNEL_SC_INTEGRITY; 1843 base_sc_integrity |= HFI1_PKT_KERNEL_SC_INTEGRITY;
1874 1844
1875 if (is_ax(dd)) 1845 /* turn on send-side job key checks if !A0 */
1876 /* turn off send-side job key checks - A0 */ 1846 if (!is_ax(dd))
1877 return base_sc_integrity & 1847 base_sc_integrity |= SEND_CTXT_CHECK_ENABLE_CHECK_JOB_KEY_SMASK;
1878 ~SEND_CTXT_CHECK_ENABLE_CHECK_JOB_KEY_SMASK; 1848
1879 return base_sc_integrity; 1849 return base_sc_integrity;
1880} 1850}
1881 1851
1882static inline u64 hfi1_pkt_base_sdma_integrity(struct hfi1_devdata *dd) 1852static inline u64 hfi1_pkt_base_sdma_integrity(struct hfi1_devdata *dd)
1883{ 1853{
1884 u64 base_sdma_integrity = 1854 u64 base_sdma_integrity;
1855
1856 /* No integrity checks if HFI1_CAP_NO_INTEGRITY is set */
1857 if (HFI1_CAP_IS_KSET(NO_INTEGRITY))
1858 return 0;
1859
1860 base_sdma_integrity =
1885 SEND_DMA_CHECK_ENABLE_DISALLOW_BYPASS_BAD_PKT_LEN_SMASK 1861 SEND_DMA_CHECK_ENABLE_DISALLOW_BYPASS_BAD_PKT_LEN_SMASK
1886 | SEND_DMA_CHECK_ENABLE_DISALLOW_PBC_STATIC_RATE_CONTROL_SMASK
1887 | SEND_DMA_CHECK_ENABLE_DISALLOW_TOO_LONG_BYPASS_PACKETS_SMASK 1862 | SEND_DMA_CHECK_ENABLE_DISALLOW_TOO_LONG_BYPASS_PACKETS_SMASK
1888 | SEND_DMA_CHECK_ENABLE_DISALLOW_TOO_LONG_IB_PACKETS_SMASK 1863 | SEND_DMA_CHECK_ENABLE_DISALLOW_TOO_LONG_IB_PACKETS_SMASK
1889 | SEND_DMA_CHECK_ENABLE_DISALLOW_BAD_PKT_LEN_SMASK 1864 | SEND_DMA_CHECK_ENABLE_DISALLOW_BAD_PKT_LEN_SMASK
@@ -1895,14 +1870,18 @@ static inline u64 hfi1_pkt_base_sdma_integrity(struct hfi1_devdata *dd)
1895 | SEND_DMA_CHECK_ENABLE_CHECK_VL_MAPPING_SMASK 1870 | SEND_DMA_CHECK_ENABLE_CHECK_VL_MAPPING_SMASK
1896 | SEND_DMA_CHECK_ENABLE_CHECK_OPCODE_SMASK 1871 | SEND_DMA_CHECK_ENABLE_CHECK_OPCODE_SMASK
1897 | SEND_DMA_CHECK_ENABLE_CHECK_SLID_SMASK 1872 | SEND_DMA_CHECK_ENABLE_CHECK_SLID_SMASK
1898 | SEND_DMA_CHECK_ENABLE_CHECK_JOB_KEY_SMASK
1899 | SEND_DMA_CHECK_ENABLE_CHECK_VL_SMASK 1873 | SEND_DMA_CHECK_ENABLE_CHECK_VL_SMASK
1900 | SEND_DMA_CHECK_ENABLE_CHECK_ENABLE_SMASK; 1874 | SEND_DMA_CHECK_ENABLE_CHECK_ENABLE_SMASK;
1901 1875
1902 if (is_ax(dd)) 1876 if (!HFI1_CAP_IS_KSET(STATIC_RATE_CTRL))
1903 /* turn off send-side job key checks - A0 */ 1877 base_sdma_integrity |=
1904 return base_sdma_integrity & 1878 SEND_DMA_CHECK_ENABLE_DISALLOW_PBC_STATIC_RATE_CONTROL_SMASK;
1905 ~SEND_DMA_CHECK_ENABLE_CHECK_JOB_KEY_SMASK; 1879
1880 /* turn on send-side job key checks if !A0 */
1881 if (!is_ax(dd))
1882 base_sdma_integrity |=
1883 SEND_DMA_CHECK_ENABLE_CHECK_JOB_KEY_SMASK;
1884
1906 return base_sdma_integrity; 1885 return base_sdma_integrity;
1907} 1886}
1908 1887
diff --git a/drivers/infiniband/hw/hfi1/init.c b/drivers/infiniband/hw/hfi1/init.c
index 60db61536fed..e3b5bc93bc70 100644
--- a/drivers/infiniband/hw/hfi1/init.c
+++ b/drivers/infiniband/hw/hfi1/init.c
@@ -144,6 +144,8 @@ int hfi1_create_ctxts(struct hfi1_devdata *dd)
144 struct hfi1_ctxtdata *rcd; 144 struct hfi1_ctxtdata *rcd;
145 145
146 ppd = dd->pport + (i % dd->num_pports); 146 ppd = dd->pport + (i % dd->num_pports);
147
148 /* dd->rcd[i] gets assigned inside the callee */
147 rcd = hfi1_create_ctxtdata(ppd, i, dd->node); 149 rcd = hfi1_create_ctxtdata(ppd, i, dd->node);
148 if (!rcd) { 150 if (!rcd) {
149 dd_dev_err(dd, 151 dd_dev_err(dd,
@@ -169,8 +171,6 @@ int hfi1_create_ctxts(struct hfi1_devdata *dd)
169 if (!rcd->sc) { 171 if (!rcd->sc) {
170 dd_dev_err(dd, 172 dd_dev_err(dd,
171 "Unable to allocate kernel send context, failing\n"); 173 "Unable to allocate kernel send context, failing\n");
172 dd->rcd[rcd->ctxt] = NULL;
173 hfi1_free_ctxtdata(dd, rcd);
174 goto nomem; 174 goto nomem;
175 } 175 }
176 176
@@ -178,9 +178,6 @@ int hfi1_create_ctxts(struct hfi1_devdata *dd)
178 if (ret < 0) { 178 if (ret < 0) {
179 dd_dev_err(dd, 179 dd_dev_err(dd,
180 "Failed to setup kernel receive context, failing\n"); 180 "Failed to setup kernel receive context, failing\n");
181 sc_free(rcd->sc);
182 dd->rcd[rcd->ctxt] = NULL;
183 hfi1_free_ctxtdata(dd, rcd);
184 ret = -EFAULT; 181 ret = -EFAULT;
185 goto bail; 182 goto bail;
186 } 183 }
@@ -196,6 +193,10 @@ int hfi1_create_ctxts(struct hfi1_devdata *dd)
196nomem: 193nomem:
197 ret = -ENOMEM; 194 ret = -ENOMEM;
198bail: 195bail:
196 if (dd->rcd) {
197 for (i = 0; i < dd->num_rcv_contexts; ++i)
198 hfi1_free_ctxtdata(dd, dd->rcd[i]);
199 }
199 kfree(dd->rcd); 200 kfree(dd->rcd);
200 dd->rcd = NULL; 201 dd->rcd = NULL;
201 return ret; 202 return ret;
@@ -216,7 +217,7 @@ struct hfi1_ctxtdata *hfi1_create_ctxtdata(struct hfi1_pportdata *ppd, u32 ctxt,
216 dd->num_rcv_contexts - dd->first_user_ctxt) 217 dd->num_rcv_contexts - dd->first_user_ctxt)
217 kctxt_ngroups = (dd->rcv_entries.nctxt_extra - 218 kctxt_ngroups = (dd->rcv_entries.nctxt_extra -
218 (dd->num_rcv_contexts - dd->first_user_ctxt)); 219 (dd->num_rcv_contexts - dd->first_user_ctxt));
219 rcd = kzalloc(sizeof(*rcd), GFP_KERNEL); 220 rcd = kzalloc_node(sizeof(*rcd), GFP_KERNEL, numa);
220 if (rcd) { 221 if (rcd) {
221 u32 rcvtids, max_entries; 222 u32 rcvtids, max_entries;
222 223
@@ -261,13 +262,6 @@ struct hfi1_ctxtdata *hfi1_create_ctxtdata(struct hfi1_pportdata *ppd, u32 ctxt,
261 } 262 }
262 rcd->eager_base = base * dd->rcv_entries.group_size; 263 rcd->eager_base = base * dd->rcv_entries.group_size;
263 264
264 /* Validate and initialize Rcv Hdr Q variables */
265 if (rcvhdrcnt % HDRQ_INCREMENT) {
266 dd_dev_err(dd,
267 "ctxt%u: header queue count %d must be divisible by %lu\n",
268 rcd->ctxt, rcvhdrcnt, HDRQ_INCREMENT);
269 goto bail;
270 }
271 rcd->rcvhdrq_cnt = rcvhdrcnt; 265 rcd->rcvhdrq_cnt = rcvhdrcnt;
272 rcd->rcvhdrqentsize = hfi1_hdrq_entsize; 266 rcd->rcvhdrqentsize = hfi1_hdrq_entsize;
273 /* 267 /*
@@ -506,7 +500,6 @@ void hfi1_init_pportdata(struct pci_dev *pdev, struct hfi1_pportdata *ppd,
506 INIT_WORK(&ppd->qsfp_info.qsfp_work, qsfp_event); 500 INIT_WORK(&ppd->qsfp_info.qsfp_work, qsfp_event);
507 501
508 mutex_init(&ppd->hls_lock); 502 mutex_init(&ppd->hls_lock);
509 spin_lock_init(&ppd->sdma_alllock);
510 spin_lock_init(&ppd->qsfp_info.qsfp_lock); 503 spin_lock_init(&ppd->qsfp_info.qsfp_lock);
511 504
512 ppd->qsfp_info.ppd = ppd; 505 ppd->qsfp_info.ppd = ppd;
@@ -1399,28 +1392,43 @@ static void postinit_cleanup(struct hfi1_devdata *dd)
1399 hfi1_free_devdata(dd); 1392 hfi1_free_devdata(dd);
1400} 1393}
1401 1394
1395static int init_validate_rcvhdrcnt(struct device *dev, uint thecnt)
1396{
1397 if (thecnt <= HFI1_MIN_HDRQ_EGRBUF_CNT) {
1398 hfi1_early_err(dev, "Receive header queue count too small\n");
1399 return -EINVAL;
1400 }
1401
1402 if (thecnt > HFI1_MAX_HDRQ_EGRBUF_CNT) {
1403 hfi1_early_err(dev,
1404 "Receive header queue count cannot be greater than %u\n",
1405 HFI1_MAX_HDRQ_EGRBUF_CNT);
1406 return -EINVAL;
1407 }
1408
1409 if (thecnt % HDRQ_INCREMENT) {
1410 hfi1_early_err(dev, "Receive header queue count %d must be divisible by %lu\n",
1411 thecnt, HDRQ_INCREMENT);
1412 return -EINVAL;
1413 }
1414
1415 return 0;
1416}
1417
1402static int init_one(struct pci_dev *pdev, const struct pci_device_id *ent) 1418static int init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
1403{ 1419{
1404 int ret = 0, j, pidx, initfail; 1420 int ret = 0, j, pidx, initfail;
1405 struct hfi1_devdata *dd = ERR_PTR(-EINVAL); 1421 struct hfi1_devdata *dd;
1406 struct hfi1_pportdata *ppd; 1422 struct hfi1_pportdata *ppd;
1407 1423
1408 /* First, lock the non-writable module parameters */ 1424 /* First, lock the non-writable module parameters */
1409 HFI1_CAP_LOCK(); 1425 HFI1_CAP_LOCK();
1410 1426
1411 /* Validate some global module parameters */ 1427 /* Validate some global module parameters */
1412 if (rcvhdrcnt <= HFI1_MIN_HDRQ_EGRBUF_CNT) { 1428 ret = init_validate_rcvhdrcnt(&pdev->dev, rcvhdrcnt);
1413 hfi1_early_err(&pdev->dev, "Header queue count too small\n"); 1429 if (ret)
1414 ret = -EINVAL;
1415 goto bail;
1416 }
1417 if (rcvhdrcnt > HFI1_MAX_HDRQ_EGRBUF_CNT) {
1418 hfi1_early_err(&pdev->dev,
1419 "Receive header queue count cannot be greater than %u\n",
1420 HFI1_MAX_HDRQ_EGRBUF_CNT);
1421 ret = -EINVAL;
1422 goto bail; 1430 goto bail;
1423 } 1431
1424 /* use the encoding function as a sanitization check */ 1432 /* use the encoding function as a sanitization check */
1425 if (!encode_rcv_header_entry_size(hfi1_hdrq_entsize)) { 1433 if (!encode_rcv_header_entry_size(hfi1_hdrq_entsize)) {
1426 hfi1_early_err(&pdev->dev, "Invalid HdrQ Entry size %u\n", 1434 hfi1_early_err(&pdev->dev, "Invalid HdrQ Entry size %u\n",
@@ -1461,26 +1469,25 @@ static int init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
1461 if (ret) 1469 if (ret)
1462 goto bail; 1470 goto bail;
1463 1471
1464 /* 1472 if (!(ent->device == PCI_DEVICE_ID_INTEL0 ||
1465 * Do device-specific initialization, function table setup, dd 1473 ent->device == PCI_DEVICE_ID_INTEL1)) {
1466 * allocation, etc.
1467 */
1468 switch (ent->device) {
1469 case PCI_DEVICE_ID_INTEL0:
1470 case PCI_DEVICE_ID_INTEL1:
1471 dd = hfi1_init_dd(pdev, ent);
1472 break;
1473 default:
1474 hfi1_early_err(&pdev->dev, 1474 hfi1_early_err(&pdev->dev,
1475 "Failing on unknown Intel deviceid 0x%x\n", 1475 "Failing on unknown Intel deviceid 0x%x\n",
1476 ent->device); 1476 ent->device);
1477 ret = -ENODEV; 1477 ret = -ENODEV;
1478 goto clean_bail;
1478 } 1479 }
1479 1480
1480 if (IS_ERR(dd)) 1481 /*
1482 * Do device-specific initialization, function table setup, dd
1483 * allocation, etc.
1484 */
1485 dd = hfi1_init_dd(pdev, ent);
1486
1487 if (IS_ERR(dd)) {
1481 ret = PTR_ERR(dd); 1488 ret = PTR_ERR(dd);
1482 if (ret)
1483 goto clean_bail; /* error already printed */ 1489 goto clean_bail; /* error already printed */
1490 }
1484 1491
1485 ret = create_workqueues(dd); 1492 ret = create_workqueues(dd);
1486 if (ret) 1493 if (ret)
@@ -1538,12 +1545,31 @@ bail:
1538 return ret; 1545 return ret;
1539} 1546}
1540 1547
1548static void wait_for_clients(struct hfi1_devdata *dd)
1549{
1550 /*
1551 * Remove the device init value and complete the device if there is
1552 * no clients or wait for active clients to finish.
1553 */
1554 if (atomic_dec_and_test(&dd->user_refcount))
1555 complete(&dd->user_comp);
1556
1557 wait_for_completion(&dd->user_comp);
1558}
1559
1541static void remove_one(struct pci_dev *pdev) 1560static void remove_one(struct pci_dev *pdev)
1542{ 1561{
1543 struct hfi1_devdata *dd = pci_get_drvdata(pdev); 1562 struct hfi1_devdata *dd = pci_get_drvdata(pdev);
1544 1563
1545 /* close debugfs files before ib unregister */ 1564 /* close debugfs files before ib unregister */
1546 hfi1_dbg_ibdev_exit(&dd->verbs_dev); 1565 hfi1_dbg_ibdev_exit(&dd->verbs_dev);
1566
1567 /* remove the /dev hfi1 interface */
1568 hfi1_device_remove(dd);
1569
1570 /* wait for existing user space clients to finish */
1571 wait_for_clients(dd);
1572
1547 /* unregister from IB core */ 1573 /* unregister from IB core */
1548 hfi1_unregister_ib_device(dd); 1574 hfi1_unregister_ib_device(dd);
1549 1575
@@ -1558,8 +1584,6 @@ static void remove_one(struct pci_dev *pdev)
1558 /* wait until all of our (qsfp) queue_work() calls complete */ 1584 /* wait until all of our (qsfp) queue_work() calls complete */
1559 flush_workqueue(ib_wq); 1585 flush_workqueue(ib_wq);
1560 1586
1561 hfi1_device_remove(dd);
1562
1563 postinit_cleanup(dd); 1587 postinit_cleanup(dd);
1564} 1588}
1565 1589
diff --git a/drivers/infiniband/hw/hfi1/pcie.c b/drivers/infiniband/hw/hfi1/pcie.c
index 89c68da1c273..4ac8f330c5cb 100644
--- a/drivers/infiniband/hw/hfi1/pcie.c
+++ b/drivers/infiniband/hw/hfi1/pcie.c
@@ -157,8 +157,7 @@ void hfi1_pcie_cleanup(struct pci_dev *pdev)
157 * fields required to re-initialize after a chip reset, or for 157 * fields required to re-initialize after a chip reset, or for
158 * various other purposes 158 * various other purposes
159 */ 159 */
160int hfi1_pcie_ddinit(struct hfi1_devdata *dd, struct pci_dev *pdev, 160int hfi1_pcie_ddinit(struct hfi1_devdata *dd, struct pci_dev *pdev)
161 const struct pci_device_id *ent)
162{ 161{
163 unsigned long len; 162 unsigned long len;
164 resource_size_t addr; 163 resource_size_t addr;
diff --git a/drivers/infiniband/hw/hfi1/pio.c b/drivers/infiniband/hw/hfi1/pio.c
index 50a3a36d9363..d89b8745d4c1 100644
--- a/drivers/infiniband/hw/hfi1/pio.c
+++ b/drivers/infiniband/hw/hfi1/pio.c
@@ -668,19 +668,12 @@ void sc_set_cr_threshold(struct send_context *sc, u32 new_threshold)
668void set_pio_integrity(struct send_context *sc) 668void set_pio_integrity(struct send_context *sc)
669{ 669{
670 struct hfi1_devdata *dd = sc->dd; 670 struct hfi1_devdata *dd = sc->dd;
671 u64 reg = 0;
672 u32 hw_context = sc->hw_context; 671 u32 hw_context = sc->hw_context;
673 int type = sc->type; 672 int type = sc->type;
674 673
675 /* 674 write_kctxt_csr(dd, hw_context,
676 * No integrity checks if HFI1_CAP_NO_INTEGRITY is set, or if 675 SC(CHECK_ENABLE),
677 * we're snooping. 676 hfi1_pkt_default_send_ctxt_mask(dd, type));
678 */
679 if (likely(!HFI1_CAP_IS_KSET(NO_INTEGRITY)) &&
680 dd->hfi1_snoop.mode_flag != HFI1_PORT_SNOOP_MODE)
681 reg = hfi1_pkt_default_send_ctxt_mask(dd, type);
682
683 write_kctxt_csr(dd, hw_context, SC(CHECK_ENABLE), reg);
684} 677}
685 678
686static u32 get_buffers_allocated(struct send_context *sc) 679static u32 get_buffers_allocated(struct send_context *sc)
diff --git a/drivers/infiniband/hw/hfi1/rc.c b/drivers/infiniband/hw/hfi1/rc.c
index 8bc5013f39a1..83198a8a8797 100644
--- a/drivers/infiniband/hw/hfi1/rc.c
+++ b/drivers/infiniband/hw/hfi1/rc.c
@@ -89,7 +89,7 @@ void hfi1_add_rnr_timer(struct rvt_qp *qp, u32 to)
89 89
90 lockdep_assert_held(&qp->s_lock); 90 lockdep_assert_held(&qp->s_lock);
91 qp->s_flags |= RVT_S_WAIT_RNR; 91 qp->s_flags |= RVT_S_WAIT_RNR;
92 qp->s_timer.expires = jiffies + usecs_to_jiffies(to); 92 priv->s_rnr_timer.expires = jiffies + usecs_to_jiffies(to);
93 add_timer(&priv->s_rnr_timer); 93 add_timer(&priv->s_rnr_timer);
94} 94}
95 95
diff --git a/drivers/infiniband/hw/hfi1/sdma.c b/drivers/infiniband/hw/hfi1/sdma.c
index fd39bcaa062d..9cbe52d21077 100644
--- a/drivers/infiniband/hw/hfi1/sdma.c
+++ b/drivers/infiniband/hw/hfi1/sdma.c
@@ -2009,11 +2009,6 @@ static void sdma_hw_start_up(struct sdma_engine *sde)
2009 write_sde_csr(sde, SD(ENG_ERR_CLEAR), reg); 2009 write_sde_csr(sde, SD(ENG_ERR_CLEAR), reg);
2010} 2010}
2011 2011
2012#define CLEAR_STATIC_RATE_CONTROL_SMASK(r) \
2013(r &= ~SEND_DMA_CHECK_ENABLE_DISALLOW_PBC_STATIC_RATE_CONTROL_SMASK)
2014
2015#define SET_STATIC_RATE_CONTROL_SMASK(r) \
2016(r |= SEND_DMA_CHECK_ENABLE_DISALLOW_PBC_STATIC_RATE_CONTROL_SMASK)
2017/* 2012/*
2018 * set_sdma_integrity 2013 * set_sdma_integrity
2019 * 2014 *
@@ -2022,19 +2017,9 @@ static void sdma_hw_start_up(struct sdma_engine *sde)
2022static void set_sdma_integrity(struct sdma_engine *sde) 2017static void set_sdma_integrity(struct sdma_engine *sde)
2023{ 2018{
2024 struct hfi1_devdata *dd = sde->dd; 2019 struct hfi1_devdata *dd = sde->dd;
2025 u64 reg;
2026
2027 if (unlikely(HFI1_CAP_IS_KSET(NO_INTEGRITY)))
2028 return;
2029
2030 reg = hfi1_pkt_base_sdma_integrity(dd);
2031
2032 if (HFI1_CAP_IS_KSET(STATIC_RATE_CTRL))
2033 CLEAR_STATIC_RATE_CONTROL_SMASK(reg);
2034 else
2035 SET_STATIC_RATE_CONTROL_SMASK(reg);
2036 2020
2037 write_sde_csr(sde, SD(CHECK_ENABLE), reg); 2021 write_sde_csr(sde, SD(CHECK_ENABLE),
2022 hfi1_pkt_base_sdma_integrity(dd));
2038} 2023}
2039 2024
2040static void init_sdma_regs( 2025static void init_sdma_regs(
diff --git a/drivers/infiniband/hw/hfi1/sysfs.c b/drivers/infiniband/hw/hfi1/sysfs.c
index edba22461a9c..919a5474e651 100644
--- a/drivers/infiniband/hw/hfi1/sysfs.c
+++ b/drivers/infiniband/hw/hfi1/sysfs.c
@@ -49,7 +49,6 @@
49#include "hfi.h" 49#include "hfi.h"
50#include "mad.h" 50#include "mad.h"
51#include "trace.h" 51#include "trace.h"
52#include "affinity.h"
53 52
54/* 53/*
55 * Start of per-port congestion control structures and support code 54 * Start of per-port congestion control structures and support code
@@ -623,27 +622,6 @@ static ssize_t show_tempsense(struct device *device,
623 return ret; 622 return ret;
624} 623}
625 624
626static ssize_t show_sdma_affinity(struct device *device,
627 struct device_attribute *attr, char *buf)
628{
629 struct hfi1_ibdev *dev =
630 container_of(device, struct hfi1_ibdev, rdi.ibdev.dev);
631 struct hfi1_devdata *dd = dd_from_dev(dev);
632
633 return hfi1_get_sdma_affinity(dd, buf);
634}
635
636static ssize_t store_sdma_affinity(struct device *device,
637 struct device_attribute *attr,
638 const char *buf, size_t count)
639{
640 struct hfi1_ibdev *dev =
641 container_of(device, struct hfi1_ibdev, rdi.ibdev.dev);
642 struct hfi1_devdata *dd = dd_from_dev(dev);
643
644 return hfi1_set_sdma_affinity(dd, buf, count);
645}
646
647/* 625/*
648 * end of per-unit (or driver, in some cases, but replicated 626 * end of per-unit (or driver, in some cases, but replicated
649 * per unit) functions 627 * per unit) functions
@@ -658,8 +636,6 @@ static DEVICE_ATTR(serial, S_IRUGO, show_serial, NULL);
658static DEVICE_ATTR(boardversion, S_IRUGO, show_boardversion, NULL); 636static DEVICE_ATTR(boardversion, S_IRUGO, show_boardversion, NULL);
659static DEVICE_ATTR(tempsense, S_IRUGO, show_tempsense, NULL); 637static DEVICE_ATTR(tempsense, S_IRUGO, show_tempsense, NULL);
660static DEVICE_ATTR(chip_reset, S_IWUSR, NULL, store_chip_reset); 638static DEVICE_ATTR(chip_reset, S_IWUSR, NULL, store_chip_reset);
661static DEVICE_ATTR(sdma_affinity, S_IWUSR | S_IRUGO, show_sdma_affinity,
662 store_sdma_affinity);
663 639
664static struct device_attribute *hfi1_attributes[] = { 640static struct device_attribute *hfi1_attributes[] = {
665 &dev_attr_hw_rev, 641 &dev_attr_hw_rev,
@@ -670,7 +646,6 @@ static struct device_attribute *hfi1_attributes[] = {
670 &dev_attr_boardversion, 646 &dev_attr_boardversion,
671 &dev_attr_tempsense, 647 &dev_attr_tempsense,
672 &dev_attr_chip_reset, 648 &dev_attr_chip_reset,
673 &dev_attr_sdma_affinity,
674}; 649};
675 650
676int hfi1_create_port_files(struct ib_device *ibdev, u8 port_num, 651int hfi1_create_port_files(struct ib_device *ibdev, u8 port_num,
diff --git a/drivers/infiniband/hw/hfi1/trace_rx.h b/drivers/infiniband/hw/hfi1/trace_rx.h
index 11e02b228922..f77e59fb43fe 100644
--- a/drivers/infiniband/hw/hfi1/trace_rx.h
+++ b/drivers/infiniband/hw/hfi1/trace_rx.h
@@ -253,66 +253,6 @@ TRACE_EVENT(hfi1_mmu_invalidate,
253 ) 253 )
254 ); 254 );
255 255
256#define SNOOP_PRN \
257 "slid %.4x dlid %.4x qpn 0x%.6x opcode 0x%.2x,%s " \
258 "svc lvl %d pkey 0x%.4x [header = %d bytes] [data = %d bytes]"
259
260TRACE_EVENT(snoop_capture,
261 TP_PROTO(struct hfi1_devdata *dd,
262 int hdr_len,
263 struct ib_header *hdr,
264 int data_len,
265 void *data),
266 TP_ARGS(dd, hdr_len, hdr, data_len, data),
267 TP_STRUCT__entry(
268 DD_DEV_ENTRY(dd)
269 __field(u16, slid)
270 __field(u16, dlid)
271 __field(u32, qpn)
272 __field(u8, opcode)
273 __field(u8, sl)
274 __field(u16, pkey)
275 __field(u32, hdr_len)
276 __field(u32, data_len)
277 __field(u8, lnh)
278 __dynamic_array(u8, raw_hdr, hdr_len)
279 __dynamic_array(u8, raw_pkt, data_len)
280 ),
281 TP_fast_assign(
282 struct ib_other_headers *ohdr;
283
284 __entry->lnh = (u8)(be16_to_cpu(hdr->lrh[0]) & 3);
285 if (__entry->lnh == HFI1_LRH_BTH)
286 ohdr = &hdr->u.oth;
287 else
288 ohdr = &hdr->u.l.oth;
289 DD_DEV_ASSIGN(dd);
290 __entry->slid = be16_to_cpu(hdr->lrh[3]);
291 __entry->dlid = be16_to_cpu(hdr->lrh[1]);
292 __entry->qpn = be32_to_cpu(ohdr->bth[1]) & RVT_QPN_MASK;
293 __entry->opcode = (be32_to_cpu(ohdr->bth[0]) >> 24) & 0xff;
294 __entry->sl = (u8)(be16_to_cpu(hdr->lrh[0]) >> 4) & 0xf;
295 __entry->pkey = be32_to_cpu(ohdr->bth[0]) & 0xffff;
296 __entry->hdr_len = hdr_len;
297 __entry->data_len = data_len;
298 memcpy(__get_dynamic_array(raw_hdr), hdr, hdr_len);
299 memcpy(__get_dynamic_array(raw_pkt), data, data_len);
300 ),
301 TP_printk(
302 "[%s] " SNOOP_PRN,
303 __get_str(dev),
304 __entry->slid,
305 __entry->dlid,
306 __entry->qpn,
307 __entry->opcode,
308 show_ib_opcode(__entry->opcode),
309 __entry->sl,
310 __entry->pkey,
311 __entry->hdr_len,
312 __entry->data_len
313 )
314);
315
316#endif /* __HFI1_TRACE_RX_H */ 256#endif /* __HFI1_TRACE_RX_H */
317 257
318#undef TRACE_INCLUDE_PATH 258#undef TRACE_INCLUDE_PATH
diff --git a/drivers/infiniband/hw/hfi1/user_sdma.c b/drivers/infiniband/hw/hfi1/user_sdma.c
index a761f804111e..77697d690f3e 100644
--- a/drivers/infiniband/hw/hfi1/user_sdma.c
+++ b/drivers/infiniband/hw/hfi1/user_sdma.c
@@ -1144,7 +1144,7 @@ static int pin_vector_pages(struct user_sdma_request *req,
1144 rb_node = hfi1_mmu_rb_extract(pq->handler, 1144 rb_node = hfi1_mmu_rb_extract(pq->handler,
1145 (unsigned long)iovec->iov.iov_base, 1145 (unsigned long)iovec->iov.iov_base,
1146 iovec->iov.iov_len); 1146 iovec->iov.iov_len);
1147 if (rb_node && !IS_ERR(rb_node)) 1147 if (rb_node)
1148 node = container_of(rb_node, struct sdma_mmu_node, rb); 1148 node = container_of(rb_node, struct sdma_mmu_node, rb);
1149 else 1149 else
1150 rb_node = NULL; 1150 rb_node = NULL;
diff --git a/drivers/infiniband/hw/mlx4/ah.c b/drivers/infiniband/hw/mlx4/ah.c
index 5fc623362731..b9bf0759f10a 100644
--- a/drivers/infiniband/hw/mlx4/ah.c
+++ b/drivers/infiniband/hw/mlx4/ah.c
@@ -102,7 +102,10 @@ static struct ib_ah *create_iboe_ah(struct ib_pd *pd, struct ib_ah_attr *ah_attr
102 if (vlan_tag < 0x1000) 102 if (vlan_tag < 0x1000)
103 vlan_tag |= (ah_attr->sl & 7) << 13; 103 vlan_tag |= (ah_attr->sl & 7) << 13;
104 ah->av.eth.port_pd = cpu_to_be32(to_mpd(pd)->pdn | (ah_attr->port_num << 24)); 104 ah->av.eth.port_pd = cpu_to_be32(to_mpd(pd)->pdn | (ah_attr->port_num << 24));
105 ah->av.eth.gid_index = mlx4_ib_gid_index_to_real_index(ibdev, ah_attr->port_num, ah_attr->grh.sgid_index); 105 ret = mlx4_ib_gid_index_to_real_index(ibdev, ah_attr->port_num, ah_attr->grh.sgid_index);
106 if (ret < 0)
107 return ERR_PTR(ret);
108 ah->av.eth.gid_index = ret;
106 ah->av.eth.vlan = cpu_to_be16(vlan_tag); 109 ah->av.eth.vlan = cpu_to_be16(vlan_tag);
107 ah->av.eth.hop_limit = ah_attr->grh.hop_limit; 110 ah->av.eth.hop_limit = ah_attr->grh.hop_limit;
108 if (ah_attr->static_rate) { 111 if (ah_attr->static_rate) {
diff --git a/drivers/infiniband/hw/mlx4/cq.c b/drivers/infiniband/hw/mlx4/cq.c
index 1ea686b9e0f9..6a0fec357dae 100644
--- a/drivers/infiniband/hw/mlx4/cq.c
+++ b/drivers/infiniband/hw/mlx4/cq.c
@@ -253,11 +253,14 @@ struct ib_cq *mlx4_ib_create_cq(struct ib_device *ibdev,
253 if (context) 253 if (context)
254 if (ib_copy_to_udata(udata, &cq->mcq.cqn, sizeof (__u32))) { 254 if (ib_copy_to_udata(udata, &cq->mcq.cqn, sizeof (__u32))) {
255 err = -EFAULT; 255 err = -EFAULT;
256 goto err_dbmap; 256 goto err_cq_free;
257 } 257 }
258 258
259 return &cq->ibcq; 259 return &cq->ibcq;
260 260
261err_cq_free:
262 mlx4_cq_free(dev->dev, &cq->mcq);
263
261err_dbmap: 264err_dbmap:
262 if (context) 265 if (context)
263 mlx4_ib_db_unmap_user(to_mucontext(context), &cq->db); 266 mlx4_ib_db_unmap_user(to_mucontext(context), &cq->db);
diff --git a/drivers/infiniband/hw/mlx5/cq.c b/drivers/infiniband/hw/mlx5/cq.c
index 79d017baf6f4..fcd04b881ec1 100644
--- a/drivers/infiniband/hw/mlx5/cq.c
+++ b/drivers/infiniband/hw/mlx5/cq.c
@@ -932,8 +932,7 @@ struct ib_cq *mlx5_ib_create_cq(struct ib_device *ibdev,
932 if (err) 932 if (err)
933 goto err_create; 933 goto err_create;
934 } else { 934 } else {
935 /* for now choose 64 bytes till we have a proper interface */ 935 cqe_size = cache_line_size() == 128 ? 128 : 64;
936 cqe_size = 64;
937 err = create_cq_kernel(dev, cq, entries, cqe_size, &cqb, 936 err = create_cq_kernel(dev, cq, entries, cqe_size, &cqb,
938 &index, &inlen); 937 &index, &inlen);
939 if (err) 938 if (err)
diff --git a/drivers/infiniband/hw/mlx5/main.c b/drivers/infiniband/hw/mlx5/main.c
index 22174774dbb8..32b09f059c84 100644
--- a/drivers/infiniband/hw/mlx5/main.c
+++ b/drivers/infiniband/hw/mlx5/main.c
@@ -1019,7 +1019,7 @@ static struct ib_ucontext *mlx5_ib_alloc_ucontext(struct ib_device *ibdev,
1019 resp.qp_tab_size = 1 << MLX5_CAP_GEN(dev->mdev, log_max_qp); 1019 resp.qp_tab_size = 1 << MLX5_CAP_GEN(dev->mdev, log_max_qp);
1020 if (mlx5_core_is_pf(dev->mdev) && MLX5_CAP_GEN(dev->mdev, bf)) 1020 if (mlx5_core_is_pf(dev->mdev) && MLX5_CAP_GEN(dev->mdev, bf))
1021 resp.bf_reg_size = 1 << MLX5_CAP_GEN(dev->mdev, log_bf_reg_size); 1021 resp.bf_reg_size = 1 << MLX5_CAP_GEN(dev->mdev, log_bf_reg_size);
1022 resp.cache_line_size = L1_CACHE_BYTES; 1022 resp.cache_line_size = cache_line_size();
1023 resp.max_sq_desc_sz = MLX5_CAP_GEN(dev->mdev, max_wqe_sz_sq); 1023 resp.max_sq_desc_sz = MLX5_CAP_GEN(dev->mdev, max_wqe_sz_sq);
1024 resp.max_rq_desc_sz = MLX5_CAP_GEN(dev->mdev, max_wqe_sz_rq); 1024 resp.max_rq_desc_sz = MLX5_CAP_GEN(dev->mdev, max_wqe_sz_rq);
1025 resp.max_send_wqebb = 1 << MLX5_CAP_GEN(dev->mdev, log_max_qp_sz); 1025 resp.max_send_wqebb = 1 << MLX5_CAP_GEN(dev->mdev, log_max_qp_sz);
@@ -2311,14 +2311,14 @@ static void mlx5_ib_event(struct mlx5_core_dev *dev, void *context,
2311{ 2311{
2312 struct mlx5_ib_dev *ibdev = (struct mlx5_ib_dev *)context; 2312 struct mlx5_ib_dev *ibdev = (struct mlx5_ib_dev *)context;
2313 struct ib_event ibev; 2313 struct ib_event ibev;
2314 2314 bool fatal = false;
2315 u8 port = 0; 2315 u8 port = 0;
2316 2316
2317 switch (event) { 2317 switch (event) {
2318 case MLX5_DEV_EVENT_SYS_ERROR: 2318 case MLX5_DEV_EVENT_SYS_ERROR:
2319 ibdev->ib_active = false;
2320 ibev.event = IB_EVENT_DEVICE_FATAL; 2319 ibev.event = IB_EVENT_DEVICE_FATAL;
2321 mlx5_ib_handle_internal_error(ibdev); 2320 mlx5_ib_handle_internal_error(ibdev);
2321 fatal = true;
2322 break; 2322 break;
2323 2323
2324 case MLX5_DEV_EVENT_PORT_UP: 2324 case MLX5_DEV_EVENT_PORT_UP:
@@ -2370,6 +2370,9 @@ static void mlx5_ib_event(struct mlx5_core_dev *dev, void *context,
2370 2370
2371 if (ibdev->ib_active) 2371 if (ibdev->ib_active)
2372 ib_dispatch_event(&ibev); 2372 ib_dispatch_event(&ibev);
2373
2374 if (fatal)
2375 ibdev->ib_active = false;
2373} 2376}
2374 2377
2375static void get_ext_port_caps(struct mlx5_ib_dev *dev) 2378static void get_ext_port_caps(struct mlx5_ib_dev *dev)
@@ -3115,7 +3118,7 @@ static void *mlx5_ib_add(struct mlx5_core_dev *mdev)
3115 } 3118 }
3116 err = init_node_data(dev); 3119 err = init_node_data(dev);
3117 if (err) 3120 if (err)
3118 goto err_dealloc; 3121 goto err_free_port;
3119 3122
3120 mutex_init(&dev->flow_db.lock); 3123 mutex_init(&dev->flow_db.lock);
3121 mutex_init(&dev->cap_mask_mutex); 3124 mutex_init(&dev->cap_mask_mutex);
@@ -3125,7 +3128,7 @@ static void *mlx5_ib_add(struct mlx5_core_dev *mdev)
3125 if (ll == IB_LINK_LAYER_ETHERNET) { 3128 if (ll == IB_LINK_LAYER_ETHERNET) {
3126 err = mlx5_enable_roce(dev); 3129 err = mlx5_enable_roce(dev);
3127 if (err) 3130 if (err)
3128 goto err_dealloc; 3131 goto err_free_port;
3129 } 3132 }
3130 3133
3131 err = create_dev_resources(&dev->devr); 3134 err = create_dev_resources(&dev->devr);
diff --git a/drivers/infiniband/hw/mlx5/mlx5_ib.h b/drivers/infiniband/hw/mlx5/mlx5_ib.h
index dcdcd195fe53..7d689903c87c 100644
--- a/drivers/infiniband/hw/mlx5/mlx5_ib.h
+++ b/drivers/infiniband/hw/mlx5/mlx5_ib.h
@@ -626,6 +626,8 @@ struct mlx5_ib_dev {
626 struct mlx5_ib_resources devr; 626 struct mlx5_ib_resources devr;
627 struct mlx5_mr_cache cache; 627 struct mlx5_mr_cache cache;
628 struct timer_list delay_timer; 628 struct timer_list delay_timer;
629 /* Prevents soft lock on massive reg MRs */
630 struct mutex slow_path_mutex;
629 int fill_delay; 631 int fill_delay;
630#ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING 632#ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING
631 struct ib_odp_caps odp_caps; 633 struct ib_odp_caps odp_caps;
diff --git a/drivers/infiniband/hw/mlx5/mr.c b/drivers/infiniband/hw/mlx5/mr.c
index d4ad672b905b..4e9012463c37 100644
--- a/drivers/infiniband/hw/mlx5/mr.c
+++ b/drivers/infiniband/hw/mlx5/mr.c
@@ -610,6 +610,7 @@ int mlx5_mr_cache_init(struct mlx5_ib_dev *dev)
610 int err; 610 int err;
611 int i; 611 int i;
612 612
613 mutex_init(&dev->slow_path_mutex);
613 cache->wq = alloc_ordered_workqueue("mkey_cache", WQ_MEM_RECLAIM); 614 cache->wq = alloc_ordered_workqueue("mkey_cache", WQ_MEM_RECLAIM);
614 if (!cache->wq) { 615 if (!cache->wq) {
615 mlx5_ib_warn(dev, "failed to create work queue\n"); 616 mlx5_ib_warn(dev, "failed to create work queue\n");
@@ -1182,9 +1183,12 @@ struct ib_mr *mlx5_ib_reg_user_mr(struct ib_pd *pd, u64 start, u64 length,
1182 goto error; 1183 goto error;
1183 } 1184 }
1184 1185
1185 if (!mr) 1186 if (!mr) {
1187 mutex_lock(&dev->slow_path_mutex);
1186 mr = reg_create(NULL, pd, virt_addr, length, umem, ncont, 1188 mr = reg_create(NULL, pd, virt_addr, length, umem, ncont,
1187 page_shift, access_flags); 1189 page_shift, access_flags);
1190 mutex_unlock(&dev->slow_path_mutex);
1191 }
1188 1192
1189 if (IS_ERR(mr)) { 1193 if (IS_ERR(mr)) {
1190 err = PTR_ERR(mr); 1194 err = PTR_ERR(mr);
diff --git a/drivers/infiniband/hw/mlx5/qp.c b/drivers/infiniband/hw/mlx5/qp.c
index 41f4c2afbcdd..d1e921816bfe 100644
--- a/drivers/infiniband/hw/mlx5/qp.c
+++ b/drivers/infiniband/hw/mlx5/qp.c
@@ -52,7 +52,6 @@ enum {
52 52
53enum { 53enum {
54 MLX5_IB_SQ_STRIDE = 6, 54 MLX5_IB_SQ_STRIDE = 6,
55 MLX5_IB_CACHE_LINE_SIZE = 64,
56}; 55};
57 56
58static const u32 mlx5_ib_opcode[] = { 57static const u32 mlx5_ib_opcode[] = {
@@ -2052,8 +2051,8 @@ struct ib_qp *mlx5_ib_create_qp(struct ib_pd *pd,
2052 2051
2053 mlx5_ib_dbg(dev, "ib qpnum 0x%x, mlx qpn 0x%x, rcqn 0x%x, scqn 0x%x\n", 2052 mlx5_ib_dbg(dev, "ib qpnum 0x%x, mlx qpn 0x%x, rcqn 0x%x, scqn 0x%x\n",
2054 qp->ibqp.qp_num, qp->trans_qp.base.mqp.qpn, 2053 qp->ibqp.qp_num, qp->trans_qp.base.mqp.qpn,
2055 to_mcq(init_attr->recv_cq)->mcq.cqn, 2054 init_attr->recv_cq ? to_mcq(init_attr->recv_cq)->mcq.cqn : -1,
2056 to_mcq(init_attr->send_cq)->mcq.cqn); 2055 init_attr->send_cq ? to_mcq(init_attr->send_cq)->mcq.cqn : -1);
2057 2056
2058 qp->trans_qp.xrcdn = xrcdn; 2057 qp->trans_qp.xrcdn = xrcdn;
2059 2058
@@ -4815,6 +4814,14 @@ struct ib_rwq_ind_table *mlx5_ib_create_rwq_ind_table(struct ib_device *device,
4815 udata->inlen)) 4814 udata->inlen))
4816 return ERR_PTR(-EOPNOTSUPP); 4815 return ERR_PTR(-EOPNOTSUPP);
4817 4816
4817 if (init_attr->log_ind_tbl_size >
4818 MLX5_CAP_GEN(dev->mdev, log_max_rqt_size)) {
4819 mlx5_ib_dbg(dev, "log_ind_tbl_size = %d is bigger than supported = %d\n",
4820 init_attr->log_ind_tbl_size,
4821 MLX5_CAP_GEN(dev->mdev, log_max_rqt_size));
4822 return ERR_PTR(-EINVAL);
4823 }
4824
4818 min_resp_len = offsetof(typeof(resp), reserved) + sizeof(resp.reserved); 4825 min_resp_len = offsetof(typeof(resp), reserved) + sizeof(resp.reserved);
4819 if (udata->outlen && udata->outlen < min_resp_len) 4826 if (udata->outlen && udata->outlen < min_resp_len)
4820 return ERR_PTR(-EINVAL); 4827 return ERR_PTR(-EINVAL);
diff --git a/drivers/infiniband/hw/mthca/mthca_memfree.c b/drivers/infiniband/hw/mthca/mthca_memfree.c
index 6c00d04b8b28..c6fe89d79248 100644
--- a/drivers/infiniband/hw/mthca/mthca_memfree.c
+++ b/drivers/infiniband/hw/mthca/mthca_memfree.c
@@ -472,7 +472,7 @@ int mthca_map_user_db(struct mthca_dev *dev, struct mthca_uar *uar,
472 goto out; 472 goto out;
473 } 473 }
474 474
475 ret = get_user_pages(uaddr & PAGE_MASK, 1, 1, 0, pages, NULL); 475 ret = get_user_pages(uaddr & PAGE_MASK, 1, FOLL_WRITE, pages, NULL);
476 if (ret < 0) 476 if (ret < 0)
477 goto out; 477 goto out;
478 478
diff --git a/drivers/infiniband/hw/qedr/Kconfig b/drivers/infiniband/hw/qedr/Kconfig
index 7c06d85568d4..6c9f3923e838 100644
--- a/drivers/infiniband/hw/qedr/Kconfig
+++ b/drivers/infiniband/hw/qedr/Kconfig
@@ -2,6 +2,7 @@ config INFINIBAND_QEDR
2 tristate "QLogic RoCE driver" 2 tristate "QLogic RoCE driver"
3 depends on 64BIT && QEDE 3 depends on 64BIT && QEDE
4 select QED_LL2 4 select QED_LL2
5 select QED_RDMA
5 ---help--- 6 ---help---
6 This driver provides low-level InfiniBand over Ethernet 7 This driver provides low-level InfiniBand over Ethernet
7 support for QLogic QED host channel adapters (HCAs). 8 support for QLogic QED host channel adapters (HCAs).
diff --git a/drivers/infiniband/hw/qib/qib_user_pages.c b/drivers/infiniband/hw/qib/qib_user_pages.c
index 2d2b94fd3633..75f08624ac05 100644
--- a/drivers/infiniband/hw/qib/qib_user_pages.c
+++ b/drivers/infiniband/hw/qib/qib_user_pages.c
@@ -67,7 +67,8 @@ static int __qib_get_user_pages(unsigned long start_page, size_t num_pages,
67 67
68 for (got = 0; got < num_pages; got += ret) { 68 for (got = 0; got < num_pages; got += ret) {
69 ret = get_user_pages(start_page + got * PAGE_SIZE, 69 ret = get_user_pages(start_page + got * PAGE_SIZE,
70 num_pages - got, 1, 1, 70 num_pages - got,
71 FOLL_WRITE | FOLL_FORCE,
71 p + got, NULL); 72 p + got, NULL);
72 if (ret < 0) 73 if (ret < 0)
73 goto bail_release; 74 goto bail_release;
diff --git a/drivers/infiniband/hw/usnic/usnic_uiom.c b/drivers/infiniband/hw/usnic/usnic_uiom.c
index a0b6ebee4d8a..1ccee6ea5bc3 100644
--- a/drivers/infiniband/hw/usnic/usnic_uiom.c
+++ b/drivers/infiniband/hw/usnic/usnic_uiom.c
@@ -111,6 +111,7 @@ static int usnic_uiom_get_pages(unsigned long addr, size_t size, int writable,
111 int i; 111 int i;
112 int flags; 112 int flags;
113 dma_addr_t pa; 113 dma_addr_t pa;
114 unsigned int gup_flags;
114 115
115 if (!can_do_mlock()) 116 if (!can_do_mlock())
116 return -EPERM; 117 return -EPERM;
@@ -135,6 +136,8 @@ static int usnic_uiom_get_pages(unsigned long addr, size_t size, int writable,
135 136
136 flags = IOMMU_READ | IOMMU_CACHE; 137 flags = IOMMU_READ | IOMMU_CACHE;
137 flags |= (writable) ? IOMMU_WRITE : 0; 138 flags |= (writable) ? IOMMU_WRITE : 0;
139 gup_flags = FOLL_WRITE;
140 gup_flags |= (writable) ? 0 : FOLL_FORCE;
138 cur_base = addr & PAGE_MASK; 141 cur_base = addr & PAGE_MASK;
139 ret = 0; 142 ret = 0;
140 143
@@ -142,7 +145,7 @@ static int usnic_uiom_get_pages(unsigned long addr, size_t size, int writable,
142 ret = get_user_pages(cur_base, 145 ret = get_user_pages(cur_base,
143 min_t(unsigned long, npages, 146 min_t(unsigned long, npages,
144 PAGE_SIZE / sizeof(struct page *)), 147 PAGE_SIZE / sizeof(struct page *)),
145 1, !writable, page_list, NULL); 148 gup_flags, page_list, NULL);
146 149
147 if (ret < 0) 150 if (ret < 0)
148 goto out; 151 goto out;
diff --git a/drivers/infiniband/sw/rdmavt/dma.c b/drivers/infiniband/sw/rdmavt/dma.c
index 01f71caa3ac4..f2cefb0d9180 100644
--- a/drivers/infiniband/sw/rdmavt/dma.c
+++ b/drivers/infiniband/sw/rdmavt/dma.c
@@ -90,9 +90,6 @@ static u64 rvt_dma_map_page(struct ib_device *dev, struct page *page,
90 if (WARN_ON(!valid_dma_direction(direction))) 90 if (WARN_ON(!valid_dma_direction(direction)))
91 return BAD_DMA_ADDRESS; 91 return BAD_DMA_ADDRESS;
92 92
93 if (offset + size > PAGE_SIZE)
94 return BAD_DMA_ADDRESS;
95
96 addr = (u64)page_address(page); 93 addr = (u64)page_address(page);
97 if (addr) 94 if (addr)
98 addr += offset; 95 addr += offset;
diff --git a/drivers/infiniband/sw/rxe/rxe_net.c b/drivers/infiniband/sw/rxe/rxe_net.c
index b8258e4f0aea..ffff5a54cb34 100644
--- a/drivers/infiniband/sw/rxe/rxe_net.c
+++ b/drivers/infiniband/sw/rxe/rxe_net.c
@@ -243,10 +243,8 @@ static struct socket *rxe_setup_udp_tunnel(struct net *net, __be16 port,
243{ 243{
244 int err; 244 int err;
245 struct socket *sock; 245 struct socket *sock;
246 struct udp_port_cfg udp_cfg; 246 struct udp_port_cfg udp_cfg = {0};
247 struct udp_tunnel_sock_cfg tnl_cfg; 247 struct udp_tunnel_sock_cfg tnl_cfg = {0};
248
249 memset(&udp_cfg, 0, sizeof(udp_cfg));
250 248
251 if (ipv6) { 249 if (ipv6) {
252 udp_cfg.family = AF_INET6; 250 udp_cfg.family = AF_INET6;
@@ -264,10 +262,8 @@ static struct socket *rxe_setup_udp_tunnel(struct net *net, __be16 port,
264 return ERR_PTR(err); 262 return ERR_PTR(err);
265 } 263 }
266 264
267 tnl_cfg.sk_user_data = NULL;
268 tnl_cfg.encap_type = 1; 265 tnl_cfg.encap_type = 1;
269 tnl_cfg.encap_rcv = rxe_udp_encap_recv; 266 tnl_cfg.encap_rcv = rxe_udp_encap_recv;
270 tnl_cfg.encap_destroy = NULL;
271 267
272 /* Setup UDP tunnel */ 268 /* Setup UDP tunnel */
273 setup_udp_tunnel_sock(net, sock, &tnl_cfg); 269 setup_udp_tunnel_sock(net, sock, &tnl_cfg);
diff --git a/drivers/infiniband/sw/rxe/rxe_qp.c b/drivers/infiniband/sw/rxe/rxe_qp.c
index b8036cfbce04..c3e60e4bde6e 100644
--- a/drivers/infiniband/sw/rxe/rxe_qp.c
+++ b/drivers/infiniband/sw/rxe/rxe_qp.c
@@ -522,6 +522,7 @@ static void rxe_qp_reset(struct rxe_qp *qp)
522 if (qp->sq.queue) { 522 if (qp->sq.queue) {
523 __rxe_do_task(&qp->comp.task); 523 __rxe_do_task(&qp->comp.task);
524 __rxe_do_task(&qp->req.task); 524 __rxe_do_task(&qp->req.task);
525 rxe_queue_reset(qp->sq.queue);
525 } 526 }
526 527
527 /* cleanup attributes */ 528 /* cleanup attributes */
@@ -573,6 +574,7 @@ void rxe_qp_error(struct rxe_qp *qp)
573{ 574{
574 qp->req.state = QP_STATE_ERROR; 575 qp->req.state = QP_STATE_ERROR;
575 qp->resp.state = QP_STATE_ERROR; 576 qp->resp.state = QP_STATE_ERROR;
577 qp->attr.qp_state = IB_QPS_ERR;
576 578
577 /* drain work and packet queues */ 579 /* drain work and packet queues */
578 rxe_run_task(&qp->resp.task, 1); 580 rxe_run_task(&qp->resp.task, 1);
diff --git a/drivers/infiniband/sw/rxe/rxe_queue.c b/drivers/infiniband/sw/rxe/rxe_queue.c
index 08274254eb88..d14bf496d62d 100644
--- a/drivers/infiniband/sw/rxe/rxe_queue.c
+++ b/drivers/infiniband/sw/rxe/rxe_queue.c
@@ -84,6 +84,15 @@ err1:
84 return -EINVAL; 84 return -EINVAL;
85} 85}
86 86
87inline void rxe_queue_reset(struct rxe_queue *q)
88{
89 /* queue is comprised from header and the memory
90 * of the actual queue. See "struct rxe_queue_buf" in rxe_queue.h
91 * reset only the queue itself and not the management header
92 */
93 memset(q->buf->data, 0, q->buf_size - sizeof(struct rxe_queue_buf));
94}
95
87struct rxe_queue *rxe_queue_init(struct rxe_dev *rxe, 96struct rxe_queue *rxe_queue_init(struct rxe_dev *rxe,
88 int *num_elem, 97 int *num_elem,
89 unsigned int elem_size) 98 unsigned int elem_size)
diff --git a/drivers/infiniband/sw/rxe/rxe_queue.h b/drivers/infiniband/sw/rxe/rxe_queue.h
index 239fd609c31e..8c8641c87817 100644
--- a/drivers/infiniband/sw/rxe/rxe_queue.h
+++ b/drivers/infiniband/sw/rxe/rxe_queue.h
@@ -84,6 +84,8 @@ int do_mmap_info(struct rxe_dev *rxe,
84 size_t buf_size, 84 size_t buf_size,
85 struct rxe_mmap_info **ip_p); 85 struct rxe_mmap_info **ip_p);
86 86
87void rxe_queue_reset(struct rxe_queue *q);
88
87struct rxe_queue *rxe_queue_init(struct rxe_dev *rxe, 89struct rxe_queue *rxe_queue_init(struct rxe_dev *rxe,
88 int *num_elem, 90 int *num_elem,
89 unsigned int elem_size); 91 unsigned int elem_size);
diff --git a/drivers/infiniband/sw/rxe/rxe_req.c b/drivers/infiniband/sw/rxe/rxe_req.c
index 832846b73ea0..22bd9630dcd9 100644
--- a/drivers/infiniband/sw/rxe/rxe_req.c
+++ b/drivers/infiniband/sw/rxe/rxe_req.c
@@ -696,7 +696,8 @@ next_wqe:
696 qp->req.wqe_index); 696 qp->req.wqe_index);
697 wqe->state = wqe_state_done; 697 wqe->state = wqe_state_done;
698 wqe->status = IB_WC_SUCCESS; 698 wqe->status = IB_WC_SUCCESS;
699 goto complete; 699 __rxe_do_task(&qp->comp.task);
700 return 0;
700 } 701 }
701 payload = mtu; 702 payload = mtu;
702 } 703 }
@@ -745,13 +746,17 @@ err:
745 wqe->status = IB_WC_LOC_PROT_ERR; 746 wqe->status = IB_WC_LOC_PROT_ERR;
746 wqe->state = wqe_state_error; 747 wqe->state = wqe_state_error;
747 748
748complete: 749 /*
749 if (qp_type(qp) != IB_QPT_RC) { 750 * IBA Spec. Section 10.7.3.1 SIGNALED COMPLETIONS
750 while (rxe_completer(qp) == 0) 751 * ---------8<---------8<-------------
751 ; 752 * ...Note that if a completion error occurs, a Work Completion
752 } 753 * will always be generated, even if the signaling
753 754 * indicator requests an Unsignaled Completion.
754 return 0; 755 * ---------8<---------8<-------------
756 */
757 wqe->wr.send_flags |= IB_SEND_SIGNALED;
758 __rxe_do_task(&qp->comp.task);
759 return -EAGAIN;
755 760
756exit: 761exit:
757 return -EAGAIN; 762 return -EAGAIN;
diff --git a/drivers/infiniband/ulp/ipoib/ipoib.h b/drivers/infiniband/ulp/ipoib/ipoib.h
index 7b8d2d9e2263..da12717a3eb7 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib.h
+++ b/drivers/infiniband/ulp/ipoib/ipoib.h
@@ -63,6 +63,8 @@ enum ipoib_flush_level {
63 63
64enum { 64enum {
65 IPOIB_ENCAP_LEN = 4, 65 IPOIB_ENCAP_LEN = 4,
66 IPOIB_PSEUDO_LEN = 20,
67 IPOIB_HARD_LEN = IPOIB_ENCAP_LEN + IPOIB_PSEUDO_LEN,
66 68
67 IPOIB_UD_HEAD_SIZE = IB_GRH_BYTES + IPOIB_ENCAP_LEN, 69 IPOIB_UD_HEAD_SIZE = IB_GRH_BYTES + IPOIB_ENCAP_LEN,
68 IPOIB_UD_RX_SG = 2, /* max buffer needed for 4K mtu */ 70 IPOIB_UD_RX_SG = 2, /* max buffer needed for 4K mtu */
@@ -134,15 +136,21 @@ struct ipoib_header {
134 u16 reserved; 136 u16 reserved;
135}; 137};
136 138
137struct ipoib_cb { 139struct ipoib_pseudo_header {
138 struct qdisc_skb_cb qdisc_cb; 140 u8 hwaddr[INFINIBAND_ALEN];
139 u8 hwaddr[INFINIBAND_ALEN];
140}; 141};
141 142
142static inline struct ipoib_cb *ipoib_skb_cb(const struct sk_buff *skb) 143static inline void skb_add_pseudo_hdr(struct sk_buff *skb)
143{ 144{
144 BUILD_BUG_ON(sizeof(skb->cb) < sizeof(struct ipoib_cb)); 145 char *data = skb_push(skb, IPOIB_PSEUDO_LEN);
145 return (struct ipoib_cb *)skb->cb; 146
147 /*
148 * only the ipoib header is present now, make room for a dummy
149 * pseudo header and set skb field accordingly
150 */
151 memset(data, 0, IPOIB_PSEUDO_LEN);
152 skb_reset_mac_header(skb);
153 skb_pull(skb, IPOIB_HARD_LEN);
146} 154}
147 155
148/* Used for all multicast joins (broadcast, IPv4 mcast and IPv6 mcast) */ 156/* Used for all multicast joins (broadcast, IPv4 mcast and IPv6 mcast) */
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_cm.c b/drivers/infiniband/ulp/ipoib/ipoib_cm.c
index 4ad297d3de89..339a1eecdfe3 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_cm.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_cm.c
@@ -63,6 +63,8 @@ MODULE_PARM_DESC(cm_data_debug_level,
63#define IPOIB_CM_RX_DELAY (3 * 256 * HZ) 63#define IPOIB_CM_RX_DELAY (3 * 256 * HZ)
64#define IPOIB_CM_RX_UPDATE_MASK (0x3) 64#define IPOIB_CM_RX_UPDATE_MASK (0x3)
65 65
66#define IPOIB_CM_RX_RESERVE (ALIGN(IPOIB_HARD_LEN, 16) - IPOIB_ENCAP_LEN)
67
66static struct ib_qp_attr ipoib_cm_err_attr = { 68static struct ib_qp_attr ipoib_cm_err_attr = {
67 .qp_state = IB_QPS_ERR 69 .qp_state = IB_QPS_ERR
68}; 70};
@@ -146,15 +148,15 @@ static struct sk_buff *ipoib_cm_alloc_rx_skb(struct net_device *dev,
146 struct sk_buff *skb; 148 struct sk_buff *skb;
147 int i; 149 int i;
148 150
149 skb = dev_alloc_skb(IPOIB_CM_HEAD_SIZE + 12); 151 skb = dev_alloc_skb(ALIGN(IPOIB_CM_HEAD_SIZE + IPOIB_PSEUDO_LEN, 16));
150 if (unlikely(!skb)) 152 if (unlikely(!skb))
151 return NULL; 153 return NULL;
152 154
153 /* 155 /*
154 * IPoIB adds a 4 byte header. So we need 12 more bytes to align the 156 * IPoIB adds a IPOIB_ENCAP_LEN byte header, this will align the
155 * IP header to a multiple of 16. 157 * IP header to a multiple of 16.
156 */ 158 */
157 skb_reserve(skb, 12); 159 skb_reserve(skb, IPOIB_CM_RX_RESERVE);
158 160
159 mapping[0] = ib_dma_map_single(priv->ca, skb->data, IPOIB_CM_HEAD_SIZE, 161 mapping[0] = ib_dma_map_single(priv->ca, skb->data, IPOIB_CM_HEAD_SIZE,
160 DMA_FROM_DEVICE); 162 DMA_FROM_DEVICE);
@@ -624,9 +626,9 @@ void ipoib_cm_handle_rx_wc(struct net_device *dev, struct ib_wc *wc)
624 if (wc->byte_len < IPOIB_CM_COPYBREAK) { 626 if (wc->byte_len < IPOIB_CM_COPYBREAK) {
625 int dlen = wc->byte_len; 627 int dlen = wc->byte_len;
626 628
627 small_skb = dev_alloc_skb(dlen + 12); 629 small_skb = dev_alloc_skb(dlen + IPOIB_CM_RX_RESERVE);
628 if (small_skb) { 630 if (small_skb) {
629 skb_reserve(small_skb, 12); 631 skb_reserve(small_skb, IPOIB_CM_RX_RESERVE);
630 ib_dma_sync_single_for_cpu(priv->ca, rx_ring[wr_id].mapping[0], 632 ib_dma_sync_single_for_cpu(priv->ca, rx_ring[wr_id].mapping[0],
631 dlen, DMA_FROM_DEVICE); 633 dlen, DMA_FROM_DEVICE);
632 skb_copy_from_linear_data(skb, small_skb->data, dlen); 634 skb_copy_from_linear_data(skb, small_skb->data, dlen);
@@ -663,8 +665,7 @@ void ipoib_cm_handle_rx_wc(struct net_device *dev, struct ib_wc *wc)
663 665
664copied: 666copied:
665 skb->protocol = ((struct ipoib_header *) skb->data)->proto; 667 skb->protocol = ((struct ipoib_header *) skb->data)->proto;
666 skb_reset_mac_header(skb); 668 skb_add_pseudo_hdr(skb);
667 skb_pull(skb, IPOIB_ENCAP_LEN);
668 669
669 ++dev->stats.rx_packets; 670 ++dev->stats.rx_packets;
670 dev->stats.rx_bytes += skb->len; 671 dev->stats.rx_bytes += skb->len;
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_ib.c b/drivers/infiniband/ulp/ipoib/ipoib_ib.c
index be11d5d5b8c1..830fecb6934c 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_ib.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_ib.c
@@ -128,16 +128,15 @@ static struct sk_buff *ipoib_alloc_rx_skb(struct net_device *dev, int id)
128 128
129 buf_size = IPOIB_UD_BUF_SIZE(priv->max_ib_mtu); 129 buf_size = IPOIB_UD_BUF_SIZE(priv->max_ib_mtu);
130 130
131 skb = dev_alloc_skb(buf_size + IPOIB_ENCAP_LEN); 131 skb = dev_alloc_skb(buf_size + IPOIB_HARD_LEN);
132 if (unlikely(!skb)) 132 if (unlikely(!skb))
133 return NULL; 133 return NULL;
134 134
135 /* 135 /*
136 * IB will leave a 40 byte gap for a GRH and IPoIB adds a 4 byte 136 * the IP header will be at IPOIP_HARD_LEN + IB_GRH_BYTES, that is
137 * header. So we need 4 more bytes to get to 48 and align the 137 * 64 bytes aligned
138 * IP header to a multiple of 16.
139 */ 138 */
140 skb_reserve(skb, 4); 139 skb_reserve(skb, sizeof(struct ipoib_pseudo_header));
141 140
142 mapping = priv->rx_ring[id].mapping; 141 mapping = priv->rx_ring[id].mapping;
143 mapping[0] = ib_dma_map_single(priv->ca, skb->data, buf_size, 142 mapping[0] = ib_dma_map_single(priv->ca, skb->data, buf_size,
@@ -253,8 +252,7 @@ static void ipoib_ib_handle_rx_wc(struct net_device *dev, struct ib_wc *wc)
253 skb_pull(skb, IB_GRH_BYTES); 252 skb_pull(skb, IB_GRH_BYTES);
254 253
255 skb->protocol = ((struct ipoib_header *) skb->data)->proto; 254 skb->protocol = ((struct ipoib_header *) skb->data)->proto;
256 skb_reset_mac_header(skb); 255 skb_add_pseudo_hdr(skb);
257 skb_pull(skb, IPOIB_ENCAP_LEN);
258 256
259 ++dev->stats.rx_packets; 257 ++dev->stats.rx_packets;
260 dev->stats.rx_bytes += skb->len; 258 dev->stats.rx_bytes += skb->len;
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_main.c b/drivers/infiniband/ulp/ipoib/ipoib_main.c
index 5636fc3da6b8..b58d9dca5c93 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_main.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_main.c
@@ -925,9 +925,12 @@ static void neigh_add_path(struct sk_buff *skb, u8 *daddr,
925 ipoib_neigh_free(neigh); 925 ipoib_neigh_free(neigh);
926 goto err_drop; 926 goto err_drop;
927 } 927 }
928 if (skb_queue_len(&neigh->queue) < IPOIB_MAX_PATH_REC_QUEUE) 928 if (skb_queue_len(&neigh->queue) <
929 IPOIB_MAX_PATH_REC_QUEUE) {
930 /* put pseudoheader back on for next time */
931 skb_push(skb, IPOIB_PSEUDO_LEN);
929 __skb_queue_tail(&neigh->queue, skb); 932 __skb_queue_tail(&neigh->queue, skb);
930 else { 933 } else {
931 ipoib_warn(priv, "queue length limit %d. Packet drop.\n", 934 ipoib_warn(priv, "queue length limit %d. Packet drop.\n",
932 skb_queue_len(&neigh->queue)); 935 skb_queue_len(&neigh->queue));
933 goto err_drop; 936 goto err_drop;
@@ -964,7 +967,7 @@ err_drop:
964} 967}
965 968
966static void unicast_arp_send(struct sk_buff *skb, struct net_device *dev, 969static void unicast_arp_send(struct sk_buff *skb, struct net_device *dev,
967 struct ipoib_cb *cb) 970 struct ipoib_pseudo_header *phdr)
968{ 971{
969 struct ipoib_dev_priv *priv = netdev_priv(dev); 972 struct ipoib_dev_priv *priv = netdev_priv(dev);
970 struct ipoib_path *path; 973 struct ipoib_path *path;
@@ -972,16 +975,18 @@ static void unicast_arp_send(struct sk_buff *skb, struct net_device *dev,
972 975
973 spin_lock_irqsave(&priv->lock, flags); 976 spin_lock_irqsave(&priv->lock, flags);
974 977
975 path = __path_find(dev, cb->hwaddr + 4); 978 path = __path_find(dev, phdr->hwaddr + 4);
976 if (!path || !path->valid) { 979 if (!path || !path->valid) {
977 int new_path = 0; 980 int new_path = 0;
978 981
979 if (!path) { 982 if (!path) {
980 path = path_rec_create(dev, cb->hwaddr + 4); 983 path = path_rec_create(dev, phdr->hwaddr + 4);
981 new_path = 1; 984 new_path = 1;
982 } 985 }
983 if (path) { 986 if (path) {
984 if (skb_queue_len(&path->queue) < IPOIB_MAX_PATH_REC_QUEUE) { 987 if (skb_queue_len(&path->queue) < IPOIB_MAX_PATH_REC_QUEUE) {
988 /* put pseudoheader back on for next time */
989 skb_push(skb, IPOIB_PSEUDO_LEN);
985 __skb_queue_tail(&path->queue, skb); 990 __skb_queue_tail(&path->queue, skb);
986 } else { 991 } else {
987 ++dev->stats.tx_dropped; 992 ++dev->stats.tx_dropped;
@@ -1009,10 +1014,12 @@ static void unicast_arp_send(struct sk_buff *skb, struct net_device *dev,
1009 be16_to_cpu(path->pathrec.dlid)); 1014 be16_to_cpu(path->pathrec.dlid));
1010 1015
1011 spin_unlock_irqrestore(&priv->lock, flags); 1016 spin_unlock_irqrestore(&priv->lock, flags);
1012 ipoib_send(dev, skb, path->ah, IPOIB_QPN(cb->hwaddr)); 1017 ipoib_send(dev, skb, path->ah, IPOIB_QPN(phdr->hwaddr));
1013 return; 1018 return;
1014 } else if ((path->query || !path_rec_start(dev, path)) && 1019 } else if ((path->query || !path_rec_start(dev, path)) &&
1015 skb_queue_len(&path->queue) < IPOIB_MAX_PATH_REC_QUEUE) { 1020 skb_queue_len(&path->queue) < IPOIB_MAX_PATH_REC_QUEUE) {
1021 /* put pseudoheader back on for next time */
1022 skb_push(skb, IPOIB_PSEUDO_LEN);
1016 __skb_queue_tail(&path->queue, skb); 1023 __skb_queue_tail(&path->queue, skb);
1017 } else { 1024 } else {
1018 ++dev->stats.tx_dropped; 1025 ++dev->stats.tx_dropped;
@@ -1026,13 +1033,15 @@ static int ipoib_start_xmit(struct sk_buff *skb, struct net_device *dev)
1026{ 1033{
1027 struct ipoib_dev_priv *priv = netdev_priv(dev); 1034 struct ipoib_dev_priv *priv = netdev_priv(dev);
1028 struct ipoib_neigh *neigh; 1035 struct ipoib_neigh *neigh;
1029 struct ipoib_cb *cb = ipoib_skb_cb(skb); 1036 struct ipoib_pseudo_header *phdr;
1030 struct ipoib_header *header; 1037 struct ipoib_header *header;
1031 unsigned long flags; 1038 unsigned long flags;
1032 1039
1040 phdr = (struct ipoib_pseudo_header *) skb->data;
1041 skb_pull(skb, sizeof(*phdr));
1033 header = (struct ipoib_header *) skb->data; 1042 header = (struct ipoib_header *) skb->data;
1034 1043
1035 if (unlikely(cb->hwaddr[4] == 0xff)) { 1044 if (unlikely(phdr->hwaddr[4] == 0xff)) {
1036 /* multicast, arrange "if" according to probability */ 1045 /* multicast, arrange "if" according to probability */
1037 if ((header->proto != htons(ETH_P_IP)) && 1046 if ((header->proto != htons(ETH_P_IP)) &&
1038 (header->proto != htons(ETH_P_IPV6)) && 1047 (header->proto != htons(ETH_P_IPV6)) &&
@@ -1045,13 +1054,13 @@ static int ipoib_start_xmit(struct sk_buff *skb, struct net_device *dev)
1045 return NETDEV_TX_OK; 1054 return NETDEV_TX_OK;
1046 } 1055 }
1047 /* Add in the P_Key for multicast*/ 1056 /* Add in the P_Key for multicast*/
1048 cb->hwaddr[8] = (priv->pkey >> 8) & 0xff; 1057 phdr->hwaddr[8] = (priv->pkey >> 8) & 0xff;
1049 cb->hwaddr[9] = priv->pkey & 0xff; 1058 phdr->hwaddr[9] = priv->pkey & 0xff;
1050 1059
1051 neigh = ipoib_neigh_get(dev, cb->hwaddr); 1060 neigh = ipoib_neigh_get(dev, phdr->hwaddr);
1052 if (likely(neigh)) 1061 if (likely(neigh))
1053 goto send_using_neigh; 1062 goto send_using_neigh;
1054 ipoib_mcast_send(dev, cb->hwaddr, skb); 1063 ipoib_mcast_send(dev, phdr->hwaddr, skb);
1055 return NETDEV_TX_OK; 1064 return NETDEV_TX_OK;
1056 } 1065 }
1057 1066
@@ -1060,16 +1069,16 @@ static int ipoib_start_xmit(struct sk_buff *skb, struct net_device *dev)
1060 case htons(ETH_P_IP): 1069 case htons(ETH_P_IP):
1061 case htons(ETH_P_IPV6): 1070 case htons(ETH_P_IPV6):
1062 case htons(ETH_P_TIPC): 1071 case htons(ETH_P_TIPC):
1063 neigh = ipoib_neigh_get(dev, cb->hwaddr); 1072 neigh = ipoib_neigh_get(dev, phdr->hwaddr);
1064 if (unlikely(!neigh)) { 1073 if (unlikely(!neigh)) {
1065 neigh_add_path(skb, cb->hwaddr, dev); 1074 neigh_add_path(skb, phdr->hwaddr, dev);
1066 return NETDEV_TX_OK; 1075 return NETDEV_TX_OK;
1067 } 1076 }
1068 break; 1077 break;
1069 case htons(ETH_P_ARP): 1078 case htons(ETH_P_ARP):
1070 case htons(ETH_P_RARP): 1079 case htons(ETH_P_RARP):
1071 /* for unicast ARP and RARP should always perform path find */ 1080 /* for unicast ARP and RARP should always perform path find */
1072 unicast_arp_send(skb, dev, cb); 1081 unicast_arp_send(skb, dev, phdr);
1073 return NETDEV_TX_OK; 1082 return NETDEV_TX_OK;
1074 default: 1083 default:
1075 /* ethertype not supported by IPoIB */ 1084 /* ethertype not supported by IPoIB */
@@ -1086,11 +1095,13 @@ send_using_neigh:
1086 goto unref; 1095 goto unref;
1087 } 1096 }
1088 } else if (neigh->ah) { 1097 } else if (neigh->ah) {
1089 ipoib_send(dev, skb, neigh->ah, IPOIB_QPN(cb->hwaddr)); 1098 ipoib_send(dev, skb, neigh->ah, IPOIB_QPN(phdr->hwaddr));
1090 goto unref; 1099 goto unref;
1091 } 1100 }
1092 1101
1093 if (skb_queue_len(&neigh->queue) < IPOIB_MAX_PATH_REC_QUEUE) { 1102 if (skb_queue_len(&neigh->queue) < IPOIB_MAX_PATH_REC_QUEUE) {
1103 /* put pseudoheader back on for next time */
1104 skb_push(skb, sizeof(*phdr));
1094 spin_lock_irqsave(&priv->lock, flags); 1105 spin_lock_irqsave(&priv->lock, flags);
1095 __skb_queue_tail(&neigh->queue, skb); 1106 __skb_queue_tail(&neigh->queue, skb);
1096 spin_unlock_irqrestore(&priv->lock, flags); 1107 spin_unlock_irqrestore(&priv->lock, flags);
@@ -1122,8 +1133,8 @@ static int ipoib_hard_header(struct sk_buff *skb,
1122 unsigned short type, 1133 unsigned short type,
1123 const void *daddr, const void *saddr, unsigned len) 1134 const void *daddr, const void *saddr, unsigned len)
1124{ 1135{
1136 struct ipoib_pseudo_header *phdr;
1125 struct ipoib_header *header; 1137 struct ipoib_header *header;
1126 struct ipoib_cb *cb = ipoib_skb_cb(skb);
1127 1138
1128 header = (struct ipoib_header *) skb_push(skb, sizeof *header); 1139 header = (struct ipoib_header *) skb_push(skb, sizeof *header);
1129 1140
@@ -1132,12 +1143,13 @@ static int ipoib_hard_header(struct sk_buff *skb,
1132 1143
1133 /* 1144 /*
1134 * we don't rely on dst_entry structure, always stuff the 1145 * we don't rely on dst_entry structure, always stuff the
1135 * destination address into skb->cb so we can figure out where 1146 * destination address into skb hard header so we can figure out where
1136 * to send the packet later. 1147 * to send the packet later.
1137 */ 1148 */
1138 memcpy(cb->hwaddr, daddr, INFINIBAND_ALEN); 1149 phdr = (struct ipoib_pseudo_header *) skb_push(skb, sizeof(*phdr));
1150 memcpy(phdr->hwaddr, daddr, INFINIBAND_ALEN);
1139 1151
1140 return sizeof *header; 1152 return IPOIB_HARD_LEN;
1141} 1153}
1142 1154
1143static void ipoib_set_mcast_list(struct net_device *dev) 1155static void ipoib_set_mcast_list(struct net_device *dev)
@@ -1759,7 +1771,7 @@ void ipoib_setup(struct net_device *dev)
1759 1771
1760 dev->flags |= IFF_BROADCAST | IFF_MULTICAST; 1772 dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
1761 1773
1762 dev->hard_header_len = IPOIB_ENCAP_LEN; 1774 dev->hard_header_len = IPOIB_HARD_LEN;
1763 dev->addr_len = INFINIBAND_ALEN; 1775 dev->addr_len = INFINIBAND_ALEN;
1764 dev->type = ARPHRD_INFINIBAND; 1776 dev->type = ARPHRD_INFINIBAND;
1765 dev->tx_queue_len = ipoib_sendq_size * 2; 1777 dev->tx_queue_len = ipoib_sendq_size * 2;
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_multicast.c b/drivers/infiniband/ulp/ipoib/ipoib_multicast.c
index d3394b6add24..1909dd252c94 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_multicast.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_multicast.c
@@ -796,9 +796,11 @@ void ipoib_mcast_send(struct net_device *dev, u8 *daddr, struct sk_buff *skb)
796 __ipoib_mcast_add(dev, mcast); 796 __ipoib_mcast_add(dev, mcast);
797 list_add_tail(&mcast->list, &priv->multicast_list); 797 list_add_tail(&mcast->list, &priv->multicast_list);
798 } 798 }
799 if (skb_queue_len(&mcast->pkt_queue) < IPOIB_MAX_MCAST_QUEUE) 799 if (skb_queue_len(&mcast->pkt_queue) < IPOIB_MAX_MCAST_QUEUE) {
800 /* put pseudoheader back on for next time */
801 skb_push(skb, sizeof(struct ipoib_pseudo_header));
800 skb_queue_tail(&mcast->pkt_queue, skb); 802 skb_queue_tail(&mcast->pkt_queue, skb);
801 else { 803 } else {
802 ++dev->stats.tx_dropped; 804 ++dev->stats.tx_dropped;
803 dev_kfree_skb_any(skb); 805 dev_kfree_skb_any(skb);
804 } 806 }
diff --git a/drivers/input/misc/arizona-haptics.c b/drivers/input/misc/arizona-haptics.c
index 982936334537..07ec465f1095 100644
--- a/drivers/input/misc/arizona-haptics.c
+++ b/drivers/input/misc/arizona-haptics.c
@@ -37,6 +37,8 @@ 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 snd_soc_component *component =
41 snd_soc_dapm_to_component(arizona->dapm);
40 int ret; 42 int ret;
41 43
42 if (!haptics->arizona->dapm) { 44 if (!haptics->arizona->dapm) {
@@ -66,7 +68,7 @@ static void arizona_haptics_work(struct work_struct *work)
66 return; 68 return;
67 } 69 }
68 70
69 ret = snd_soc_dapm_enable_pin(arizona->dapm, "HAPTICS"); 71 ret = snd_soc_component_enable_pin(component, "HAPTICS");
70 if (ret != 0) { 72 if (ret != 0) {
71 dev_err(arizona->dev, "Failed to start HAPTICS: %d\n", 73 dev_err(arizona->dev, "Failed to start HAPTICS: %d\n",
72 ret); 74 ret);
@@ -81,7 +83,7 @@ static void arizona_haptics_work(struct work_struct *work)
81 } 83 }
82 } else { 84 } else {
83 /* This disable sequence will be a noop if already enabled */ 85 /* This disable sequence will be a noop if already enabled */
84 ret = snd_soc_dapm_disable_pin(arizona->dapm, "HAPTICS"); 86 ret = snd_soc_component_disable_pin(component, "HAPTICS");
85 if (ret != 0) { 87 if (ret != 0) {
86 dev_err(arizona->dev, "Failed to disable HAPTICS: %d\n", 88 dev_err(arizona->dev, "Failed to disable HAPTICS: %d\n",
87 ret); 89 ret);
@@ -140,11 +142,14 @@ static int arizona_haptics_play(struct input_dev *input, void *data,
140static void arizona_haptics_close(struct input_dev *input) 142static void arizona_haptics_close(struct input_dev *input)
141{ 143{
142 struct arizona_haptics *haptics = input_get_drvdata(input); 144 struct arizona_haptics *haptics = input_get_drvdata(input);
145 struct snd_soc_component *component;
143 146
144 cancel_work_sync(&haptics->work); 147 cancel_work_sync(&haptics->work);
145 148
146 if (haptics->arizona->dapm) 149 if (haptics->arizona->dapm) {
147 snd_soc_dapm_disable_pin(haptics->arizona->dapm, "HAPTICS"); 150 component = snd_soc_dapm_to_component(haptics->arizona->dapm);
151 snd_soc_component_disable_pin(component, "HAPTICS");
152 }
148} 153}
149 154
150static int arizona_haptics_probe(struct platform_device *pdev) 155static int arizona_haptics_probe(struct platform_device *pdev)
diff --git a/drivers/input/mouse/focaltech.c b/drivers/input/mouse/focaltech.c
index 54eceb30ede5..a7d39689bbfb 100644
--- a/drivers/input/mouse/focaltech.c
+++ b/drivers/input/mouse/focaltech.c
@@ -43,7 +43,7 @@ int focaltech_detect(struct psmouse *psmouse, bool set_properties)
43 43
44 if (set_properties) { 44 if (set_properties) {
45 psmouse->vendor = "FocalTech"; 45 psmouse->vendor = "FocalTech";
46 psmouse->name = "FocalTech Touchpad"; 46 psmouse->name = "Touchpad";
47 } 47 }
48 48
49 return 0; 49 return 0;
@@ -146,8 +146,8 @@ static void focaltech_report_state(struct psmouse *psmouse)
146 } 146 }
147 input_mt_report_pointer_emulation(dev, true); 147 input_mt_report_pointer_emulation(dev, true);
148 148
149 input_report_key(psmouse->dev, BTN_LEFT, state->pressed); 149 input_report_key(dev, BTN_LEFT, state->pressed);
150 input_sync(psmouse->dev); 150 input_sync(dev);
151} 151}
152 152
153static void focaltech_process_touch_packet(struct psmouse *psmouse, 153static void focaltech_process_touch_packet(struct psmouse *psmouse,
diff --git a/drivers/input/mouse/psmouse-base.c b/drivers/input/mouse/psmouse-base.c
index fb4b185dea96..bee267424972 100644
--- a/drivers/input/mouse/psmouse-base.c
+++ b/drivers/input/mouse/psmouse-base.c
@@ -1115,10 +1115,6 @@ static int psmouse_extensions(struct psmouse *psmouse,
1115 if (psmouse_try_protocol(psmouse, PSMOUSE_TOUCHKIT_PS2, 1115 if (psmouse_try_protocol(psmouse, PSMOUSE_TOUCHKIT_PS2,
1116 &max_proto, set_properties, true)) 1116 &max_proto, set_properties, true))
1117 return PSMOUSE_TOUCHKIT_PS2; 1117 return PSMOUSE_TOUCHKIT_PS2;
1118
1119 if (psmouse_try_protocol(psmouse, PSMOUSE_BYD,
1120 &max_proto, set_properties, true))
1121 return PSMOUSE_BYD;
1122 } 1118 }
1123 1119
1124 /* 1120 /*
diff --git a/drivers/input/serio/i8042-x86ia64io.h b/drivers/input/serio/i8042-x86ia64io.h
index f4bfb4b2d50a..073246c7d163 100644
--- a/drivers/input/serio/i8042-x86ia64io.h
+++ b/drivers/input/serio/i8042-x86ia64io.h
@@ -877,6 +877,13 @@ static const struct dmi_system_id __initconst i8042_dmi_kbdreset_table[] = {
877 DMI_MATCH(DMI_PRODUCT_NAME, "P34"), 877 DMI_MATCH(DMI_PRODUCT_NAME, "P34"),
878 }, 878 },
879 }, 879 },
880 {
881 /* Schenker XMG C504 - Elantech touchpad */
882 .matches = {
883 DMI_MATCH(DMI_SYS_VENDOR, "XMG"),
884 DMI_MATCH(DMI_PRODUCT_NAME, "C504"),
885 },
886 },
880 { } 887 { }
881}; 888};
882 889
diff --git a/drivers/iommu/arm-smmu-v3.c b/drivers/iommu/arm-smmu-v3.c
index 15c01c3cd540..e6f9b2d745ca 100644
--- a/drivers/iommu/arm-smmu-v3.c
+++ b/drivers/iommu/arm-smmu-v3.c
@@ -2636,17 +2636,26 @@ static int arm_smmu_device_dt_probe(struct platform_device *pdev)
2636 /* And we're up. Go go go! */ 2636 /* And we're up. Go go go! */
2637 of_iommu_set_ops(dev->of_node, &arm_smmu_ops); 2637 of_iommu_set_ops(dev->of_node, &arm_smmu_ops);
2638#ifdef CONFIG_PCI 2638#ifdef CONFIG_PCI
2639 pci_request_acs(); 2639 if (pci_bus_type.iommu_ops != &arm_smmu_ops) {
2640 ret = bus_set_iommu(&pci_bus_type, &arm_smmu_ops); 2640 pci_request_acs();
2641 if (ret) 2641 ret = bus_set_iommu(&pci_bus_type, &arm_smmu_ops);
2642 return ret; 2642 if (ret)
2643 return ret;
2644 }
2643#endif 2645#endif
2644#ifdef CONFIG_ARM_AMBA 2646#ifdef CONFIG_ARM_AMBA
2645 ret = bus_set_iommu(&amba_bustype, &arm_smmu_ops); 2647 if (amba_bustype.iommu_ops != &arm_smmu_ops) {
2646 if (ret) 2648 ret = bus_set_iommu(&amba_bustype, &arm_smmu_ops);
2647 return ret; 2649 if (ret)
2650 return ret;
2651 }
2648#endif 2652#endif
2649 return bus_set_iommu(&platform_bus_type, &arm_smmu_ops); 2653 if (platform_bus_type.iommu_ops != &arm_smmu_ops) {
2654 ret = bus_set_iommu(&platform_bus_type, &arm_smmu_ops);
2655 if (ret)
2656 return ret;
2657 }
2658 return 0;
2650} 2659}
2651 2660
2652static int arm_smmu_device_remove(struct platform_device *pdev) 2661static int arm_smmu_device_remove(struct platform_device *pdev)
diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c
index c841eb7a1a74..8f7281444551 100644
--- a/drivers/iommu/arm-smmu.c
+++ b/drivers/iommu/arm-smmu.c
@@ -324,8 +324,10 @@ struct arm_smmu_master_cfg {
324#define INVALID_SMENDX -1 324#define INVALID_SMENDX -1
325#define __fwspec_cfg(fw) ((struct arm_smmu_master_cfg *)fw->iommu_priv) 325#define __fwspec_cfg(fw) ((struct arm_smmu_master_cfg *)fw->iommu_priv)
326#define fwspec_smmu(fw) (__fwspec_cfg(fw)->smmu) 326#define fwspec_smmu(fw) (__fwspec_cfg(fw)->smmu)
327#define fwspec_smendx(fw, i) \
328 (i >= fw->num_ids ? INVALID_SMENDX : __fwspec_cfg(fw)->smendx[i])
327#define for_each_cfg_sme(fw, i, idx) \ 329#define for_each_cfg_sme(fw, i, idx) \
328 for (i = 0; idx = __fwspec_cfg(fw)->smendx[i], i < fw->num_ids; ++i) 330 for (i = 0; idx = fwspec_smendx(fw, i), i < fw->num_ids; ++i)
329 331
330struct arm_smmu_device { 332struct arm_smmu_device {
331 struct device *dev; 333 struct device *dev;
@@ -1228,6 +1230,16 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev)
1228 return -ENXIO; 1230 return -ENXIO;
1229 } 1231 }
1230 1232
1233 /*
1234 * FIXME: The arch/arm DMA API code tries to attach devices to its own
1235 * domains between of_xlate() and add_device() - we have no way to cope
1236 * with that, so until ARM gets converted to rely on groups and default
1237 * domains, just say no (but more politely than by dereferencing NULL).
1238 * This should be at least a WARN_ON once that's sorted.
1239 */
1240 if (!fwspec->iommu_priv)
1241 return -ENODEV;
1242
1231 smmu = fwspec_smmu(fwspec); 1243 smmu = fwspec_smmu(fwspec);
1232 /* Ensure that the domain is finalised */ 1244 /* Ensure that the domain is finalised */
1233 ret = arm_smmu_init_domain_context(domain, smmu); 1245 ret = arm_smmu_init_domain_context(domain, smmu);
@@ -1390,7 +1402,7 @@ static int arm_smmu_add_device(struct device *dev)
1390 fwspec = dev->iommu_fwspec; 1402 fwspec = dev->iommu_fwspec;
1391 if (ret) 1403 if (ret)
1392 goto out_free; 1404 goto out_free;
1393 } else if (fwspec) { 1405 } else if (fwspec && fwspec->ops == &arm_smmu_ops) {
1394 smmu = arm_smmu_get_by_node(to_of_node(fwspec->iommu_fwnode)); 1406 smmu = arm_smmu_get_by_node(to_of_node(fwspec->iommu_fwnode));
1395 } else { 1407 } else {
1396 return -ENODEV; 1408 return -ENODEV;
diff --git a/drivers/iommu/dmar.c b/drivers/iommu/dmar.c
index 58470f5ced04..8c53748a769d 100644
--- a/drivers/iommu/dmar.c
+++ b/drivers/iommu/dmar.c
@@ -338,7 +338,9 @@ static int dmar_pci_bus_notifier(struct notifier_block *nb,
338 struct pci_dev *pdev = to_pci_dev(data); 338 struct pci_dev *pdev = to_pci_dev(data);
339 struct dmar_pci_notify_info *info; 339 struct dmar_pci_notify_info *info;
340 340
341 /* Only care about add/remove events for physical functions */ 341 /* Only care about add/remove events for physical functions.
342 * For VFs we actually do the lookup based on the corresponding
343 * PF in device_to_iommu() anyway. */
342 if (pdev->is_virtfn) 344 if (pdev->is_virtfn)
343 return NOTIFY_DONE; 345 return NOTIFY_DONE;
344 if (action != BUS_NOTIFY_ADD_DEVICE && 346 if (action != BUS_NOTIFY_ADD_DEVICE &&
diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
index a4407eabf0e6..d8376c2d18b3 100644
--- a/drivers/iommu/intel-iommu.c
+++ b/drivers/iommu/intel-iommu.c
@@ -892,7 +892,13 @@ static struct intel_iommu *device_to_iommu(struct device *dev, u8 *bus, u8 *devf
892 return NULL; 892 return NULL;
893 893
894 if (dev_is_pci(dev)) { 894 if (dev_is_pci(dev)) {
895 struct pci_dev *pf_pdev;
896
895 pdev = to_pci_dev(dev); 897 pdev = to_pci_dev(dev);
898 /* VFs aren't listed in scope tables; we need to look up
899 * the PF instead to find the IOMMU. */
900 pf_pdev = pci_physfn(pdev);
901 dev = &pf_pdev->dev;
896 segment = pci_domain_nr(pdev->bus); 902 segment = pci_domain_nr(pdev->bus);
897 } else if (has_acpi_companion(dev)) 903 } else if (has_acpi_companion(dev))
898 dev = &ACPI_COMPANION(dev)->dev; 904 dev = &ACPI_COMPANION(dev)->dev;
@@ -905,6 +911,13 @@ static struct intel_iommu *device_to_iommu(struct device *dev, u8 *bus, u8 *devf
905 for_each_active_dev_scope(drhd->devices, 911 for_each_active_dev_scope(drhd->devices,
906 drhd->devices_cnt, i, tmp) { 912 drhd->devices_cnt, i, tmp) {
907 if (tmp == dev) { 913 if (tmp == dev) {
914 /* For a VF use its original BDF# not that of the PF
915 * which we used for the IOMMU lookup. Strictly speaking
916 * we could do this for all PCI devices; we only need to
917 * get the BDF# from the scope table for ACPI matches. */
918 if (pdev->is_virtfn)
919 goto got_pdev;
920
908 *bus = drhd->devices[i].bus; 921 *bus = drhd->devices[i].bus;
909 *devfn = drhd->devices[i].devfn; 922 *devfn = drhd->devices[i].devfn;
910 goto out; 923 goto out;
@@ -1711,6 +1724,7 @@ static void disable_dmar_iommu(struct intel_iommu *iommu)
1711 if (!iommu->domains || !iommu->domain_ids) 1724 if (!iommu->domains || !iommu->domain_ids)
1712 return; 1725 return;
1713 1726
1727again:
1714 spin_lock_irqsave(&device_domain_lock, flags); 1728 spin_lock_irqsave(&device_domain_lock, flags);
1715 list_for_each_entry_safe(info, tmp, &device_domain_list, global) { 1729 list_for_each_entry_safe(info, tmp, &device_domain_list, global) {
1716 struct dmar_domain *domain; 1730 struct dmar_domain *domain;
@@ -1723,10 +1737,19 @@ static void disable_dmar_iommu(struct intel_iommu *iommu)
1723 1737
1724 domain = info->domain; 1738 domain = info->domain;
1725 1739
1726 dmar_remove_one_dev_info(domain, info->dev); 1740 __dmar_remove_one_dev_info(info);
1727 1741
1728 if (!domain_type_is_vm_or_si(domain)) 1742 if (!domain_type_is_vm_or_si(domain)) {
1743 /*
1744 * The domain_exit() function can't be called under
1745 * device_domain_lock, as it takes this lock itself.
1746 * So release the lock here and re-run the loop
1747 * afterwards.
1748 */
1749 spin_unlock_irqrestore(&device_domain_lock, flags);
1729 domain_exit(domain); 1750 domain_exit(domain);
1751 goto again;
1752 }
1730 } 1753 }
1731 spin_unlock_irqrestore(&device_domain_lock, flags); 1754 spin_unlock_irqrestore(&device_domain_lock, flags);
1732 1755
diff --git a/drivers/iommu/intel-svm.c b/drivers/iommu/intel-svm.c
index 8ebb3530afa7..cb72e0011310 100644
--- a/drivers/iommu/intel-svm.c
+++ b/drivers/iommu/intel-svm.c
@@ -39,10 +39,18 @@ int intel_svm_alloc_pasid_tables(struct intel_iommu *iommu)
39 struct page *pages; 39 struct page *pages;
40 int order; 40 int order;
41 41
42 order = ecap_pss(iommu->ecap) + 7 - PAGE_SHIFT; 42 /* Start at 2 because it's defined as 2^(1+PSS) */
43 if (order < 0) 43 iommu->pasid_max = 2 << ecap_pss(iommu->ecap);
44 order = 0; 44
45 45 /* Eventually I'm promised we will get a multi-level PASID table
46 * and it won't have to be physically contiguous. Until then,
47 * limit the size because 8MiB contiguous allocations can be hard
48 * to come by. The limit of 0x20000, which is 1MiB for each of
49 * the PASID and PASID-state tables, is somewhat arbitrary. */
50 if (iommu->pasid_max > 0x20000)
51 iommu->pasid_max = 0x20000;
52
53 order = get_order(sizeof(struct pasid_entry) * iommu->pasid_max);
46 pages = alloc_pages(GFP_KERNEL | __GFP_ZERO, order); 54 pages = alloc_pages(GFP_KERNEL | __GFP_ZERO, order);
47 if (!pages) { 55 if (!pages) {
48 pr_warn("IOMMU: %s: Failed to allocate PASID table\n", 56 pr_warn("IOMMU: %s: Failed to allocate PASID table\n",
@@ -53,6 +61,8 @@ int intel_svm_alloc_pasid_tables(struct intel_iommu *iommu)
53 pr_info("%s: Allocated order %d PASID table.\n", iommu->name, order); 61 pr_info("%s: Allocated order %d PASID table.\n", iommu->name, order);
54 62
55 if (ecap_dis(iommu->ecap)) { 63 if (ecap_dis(iommu->ecap)) {
64 /* Just making it explicit... */
65 BUILD_BUG_ON(sizeof(struct pasid_entry) != sizeof(struct pasid_state_entry));
56 pages = alloc_pages(GFP_KERNEL | __GFP_ZERO, order); 66 pages = alloc_pages(GFP_KERNEL | __GFP_ZERO, order);
57 if (pages) 67 if (pages)
58 iommu->pasid_state_table = page_address(pages); 68 iommu->pasid_state_table = page_address(pages);
@@ -68,11 +78,7 @@ int intel_svm_alloc_pasid_tables(struct intel_iommu *iommu)
68 78
69int intel_svm_free_pasid_tables(struct intel_iommu *iommu) 79int intel_svm_free_pasid_tables(struct intel_iommu *iommu)
70{ 80{
71 int order; 81 int order = get_order(sizeof(struct pasid_entry) * iommu->pasid_max);
72
73 order = ecap_pss(iommu->ecap) + 7 - PAGE_SHIFT;
74 if (order < 0)
75 order = 0;
76 82
77 if (iommu->pasid_table) { 83 if (iommu->pasid_table) {
78 free_pages((unsigned long)iommu->pasid_table, order); 84 free_pages((unsigned long)iommu->pasid_table, order);
@@ -371,8 +377,8 @@ int intel_svm_bind_mm(struct device *dev, int *pasid, int flags, struct svm_dev_
371 } 377 }
372 svm->iommu = iommu; 378 svm->iommu = iommu;
373 379
374 if (pasid_max > 2 << ecap_pss(iommu->ecap)) 380 if (pasid_max > iommu->pasid_max)
375 pasid_max = 2 << ecap_pss(iommu->ecap); 381 pasid_max = iommu->pasid_max;
376 382
377 /* Do not use PASID 0 in caching mode (virtualised IOMMU) */ 383 /* Do not use PASID 0 in caching mode (virtualised IOMMU) */
378 ret = idr_alloc(&iommu->pasid_idr, svm, 384 ret = idr_alloc(&iommu->pasid_idr, svm,
diff --git a/drivers/ipack/ipack.c b/drivers/ipack/ipack.c
index c0e7b624ce54..12102448fddd 100644
--- a/drivers/ipack/ipack.c
+++ b/drivers/ipack/ipack.c
@@ -178,7 +178,7 @@ static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
178 idev->id_vendor, idev->id_device); 178 idev->id_vendor, idev->id_device);
179} 179}
180 180
181ipack_device_attr(id_format, "0x%hhu\n"); 181ipack_device_attr(id_format, "0x%hhx\n");
182 182
183static DEVICE_ATTR_RO(id); 183static DEVICE_ATTR_RO(id);
184static DEVICE_ATTR_RO(id_device); 184static DEVICE_ATTR_RO(id_device);
diff --git a/drivers/irqchip/Kconfig b/drivers/irqchip/Kconfig
index 82b0b5daf3f5..bc0af3307bbf 100644
--- a/drivers/irqchip/Kconfig
+++ b/drivers/irqchip/Kconfig
@@ -158,8 +158,8 @@ config PIC32_EVIC
158 select IRQ_DOMAIN 158 select IRQ_DOMAIN
159 159
160config JCORE_AIC 160config JCORE_AIC
161 bool "J-Core integrated AIC" 161 bool "J-Core integrated AIC" if COMPILE_TEST
162 depends on OF && (SUPERH || COMPILE_TEST) 162 depends on OF
163 select IRQ_DOMAIN 163 select IRQ_DOMAIN
164 help 164 help
165 Support for the J-Core integrated AIC. 165 Support for the J-Core integrated AIC.
diff --git a/drivers/irqchip/irq-eznps.c b/drivers/irqchip/irq-eznps.c
index efbf0e4304b7..2a7a38830a8d 100644
--- a/drivers/irqchip/irq-eznps.c
+++ b/drivers/irqchip/irq-eznps.c
@@ -85,7 +85,7 @@ static void nps400_irq_eoi_global(struct irq_data *irqd)
85 nps_ack_gic(); 85 nps_ack_gic();
86} 86}
87 87
88static void nps400_irq_eoi(struct irq_data *irqd) 88static void nps400_irq_ack(struct irq_data *irqd)
89{ 89{
90 unsigned int __maybe_unused irq = irqd_to_hwirq(irqd); 90 unsigned int __maybe_unused irq = irqd_to_hwirq(irqd);
91 91
@@ -103,7 +103,7 @@ static struct irq_chip nps400_irq_chip_percpu = {
103 .name = "NPS400 IC", 103 .name = "NPS400 IC",
104 .irq_mask = nps400_irq_mask, 104 .irq_mask = nps400_irq_mask,
105 .irq_unmask = nps400_irq_unmask, 105 .irq_unmask = nps400_irq_unmask,
106 .irq_eoi = nps400_irq_eoi, 106 .irq_ack = nps400_irq_ack,
107}; 107};
108 108
109static int nps400_irq_map(struct irq_domain *d, unsigned int virq, 109static int nps400_irq_map(struct irq_domain *d, unsigned int virq,
@@ -135,7 +135,7 @@ static const struct irq_domain_ops nps400_irq_ops = {
135static int __init nps400_of_init(struct device_node *node, 135static int __init nps400_of_init(struct device_node *node,
136 struct device_node *parent) 136 struct device_node *parent)
137{ 137{
138 static struct irq_domain *nps400_root_domain; 138 struct irq_domain *nps400_root_domain;
139 139
140 if (parent) { 140 if (parent) {
141 pr_err("DeviceTree incore ic not a root irq controller\n"); 141 pr_err("DeviceTree incore ic not a root irq controller\n");
diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c
index 003495d91f9c..c5dee300e8a3 100644
--- a/drivers/irqchip/irq-gic-v3-its.c
+++ b/drivers/irqchip/irq-gic-v3-its.c
@@ -1023,7 +1023,7 @@ static void its_free_tables(struct its_node *its)
1023 1023
1024static int its_alloc_tables(struct its_node *its) 1024static int its_alloc_tables(struct its_node *its)
1025{ 1025{
1026 u64 typer = readq_relaxed(its->base + GITS_TYPER); 1026 u64 typer = gic_read_typer(its->base + GITS_TYPER);
1027 u32 ids = GITS_TYPER_DEVBITS(typer); 1027 u32 ids = GITS_TYPER_DEVBITS(typer);
1028 u64 shr = GITS_BASER_InnerShareable; 1028 u64 shr = GITS_BASER_InnerShareable;
1029 u64 cache = GITS_BASER_WaWb; 1029 u64 cache = GITS_BASER_WaWb;
@@ -1198,7 +1198,7 @@ static void its_cpu_init_collection(void)
1198 * We now have to bind each collection to its target 1198 * We now have to bind each collection to its target
1199 * redistributor. 1199 * redistributor.
1200 */ 1200 */
1201 if (readq_relaxed(its->base + GITS_TYPER) & GITS_TYPER_PTA) { 1201 if (gic_read_typer(its->base + GITS_TYPER) & GITS_TYPER_PTA) {
1202 /* 1202 /*
1203 * This ITS wants the physical address of the 1203 * This ITS wants the physical address of the
1204 * redistributor. 1204 * redistributor.
@@ -1208,7 +1208,7 @@ static void its_cpu_init_collection(void)
1208 /* 1208 /*
1209 * This ITS wants a linear CPU number. 1209 * This ITS wants a linear CPU number.
1210 */ 1210 */
1211 target = readq_relaxed(gic_data_rdist_rd_base() + GICR_TYPER); 1211 target = gic_read_typer(gic_data_rdist_rd_base() + GICR_TYPER);
1212 target = GICR_TYPER_CPU_NUMBER(target) << 16; 1212 target = GICR_TYPER_CPU_NUMBER(target) << 16;
1213 } 1213 }
1214 1214
@@ -1691,7 +1691,7 @@ static int __init its_probe_one(struct resource *res,
1691 INIT_LIST_HEAD(&its->its_device_list); 1691 INIT_LIST_HEAD(&its->its_device_list);
1692 its->base = its_base; 1692 its->base = its_base;
1693 its->phys_base = res->start; 1693 its->phys_base = res->start;
1694 its->ite_size = ((readl_relaxed(its_base + GITS_TYPER) >> 4) & 0xf) + 1; 1694 its->ite_size = ((gic_read_typer(its_base + GITS_TYPER) >> 4) & 0xf) + 1;
1695 its->numa_node = numa_node; 1695 its->numa_node = numa_node;
1696 1696
1697 its->cmd_base = kzalloc(ITS_CMD_QUEUE_SZ, GFP_KERNEL); 1697 its->cmd_base = kzalloc(ITS_CMD_QUEUE_SZ, GFP_KERNEL);
@@ -1763,7 +1763,7 @@ out_unmap:
1763 1763
1764static bool gic_rdists_supports_plpis(void) 1764static bool gic_rdists_supports_plpis(void)
1765{ 1765{
1766 return !!(readl_relaxed(gic_data_rdist_rd_base() + GICR_TYPER) & GICR_TYPER_PLPIS); 1766 return !!(gic_read_typer(gic_data_rdist_rd_base() + GICR_TYPER) & GICR_TYPER_PLPIS);
1767} 1767}
1768 1768
1769int its_cpu_init(void) 1769int its_cpu_init(void)
diff --git a/drivers/irqchip/irq-gic-v3.c b/drivers/irqchip/irq-gic-v3.c
index 9b81bd8b929c..19d642eae096 100644
--- a/drivers/irqchip/irq-gic-v3.c
+++ b/drivers/irqchip/irq-gic-v3.c
@@ -153,7 +153,7 @@ static void gic_enable_redist(bool enable)
153 return; /* No PM support in this redistributor */ 153 return; /* No PM support in this redistributor */
154 } 154 }
155 155
156 while (count--) { 156 while (--count) {
157 val = readl_relaxed(rbase + GICR_WAKER); 157 val = readl_relaxed(rbase + GICR_WAKER);
158 if (enable ^ (bool)(val & GICR_WAKER_ChildrenAsleep)) 158 if (enable ^ (bool)(val & GICR_WAKER_ChildrenAsleep))
159 break; 159 break;
diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
index 58e5b4e87056..d6c404b3584d 100644
--- a/drivers/irqchip/irq-gic.c
+++ b/drivers/irqchip/irq-gic.c
@@ -1279,7 +1279,7 @@ static bool gic_check_eoimode(struct device_node *node, void __iomem **base)
1279 */ 1279 */
1280 *base += 0xf000; 1280 *base += 0xf000;
1281 cpuif_res.start += 0xf000; 1281 cpuif_res.start += 0xf000;
1282 pr_warn("GIC: Adjusting CPU interface base to %pa", 1282 pr_warn("GIC: Adjusting CPU interface base to %pa\n",
1283 &cpuif_res.start); 1283 &cpuif_res.start);
1284 } 1284 }
1285 1285
diff --git a/drivers/irqchip/irq-jcore-aic.c b/drivers/irqchip/irq-jcore-aic.c
index 84b01dec277d..033bccb41455 100644
--- a/drivers/irqchip/irq-jcore-aic.c
+++ b/drivers/irqchip/irq-jcore-aic.c
@@ -25,12 +25,30 @@
25 25
26static struct irq_chip jcore_aic; 26static struct irq_chip jcore_aic;
27 27
28/*
29 * The J-Core AIC1 and AIC2 are cpu-local interrupt controllers and do
30 * not distinguish or use distinct irq number ranges for per-cpu event
31 * interrupts (timer, IPI). Since information to determine whether a
32 * particular irq number should be treated as per-cpu is not available
33 * at mapping time, we use a wrapper handler function which chooses
34 * the right handler at runtime based on whether IRQF_PERCPU was used
35 * when requesting the irq.
36 */
37
38static void handle_jcore_irq(struct irq_desc *desc)
39{
40 if (irqd_is_per_cpu(irq_desc_get_irq_data(desc)))
41 handle_percpu_irq(desc);
42 else
43 handle_simple_irq(desc);
44}
45
28static int jcore_aic_irqdomain_map(struct irq_domain *d, unsigned int irq, 46static int jcore_aic_irqdomain_map(struct irq_domain *d, unsigned int irq,
29 irq_hw_number_t hwirq) 47 irq_hw_number_t hwirq)
30{ 48{
31 struct irq_chip *aic = d->host_data; 49 struct irq_chip *aic = d->host_data;
32 50
33 irq_set_chip_and_handler(irq, aic, handle_simple_irq); 51 irq_set_chip_and_handler(irq, aic, handle_jcore_irq);
34 52
35 return 0; 53 return 0;
36} 54}
diff --git a/drivers/isdn/gigaset/ser-gigaset.c b/drivers/isdn/gigaset/ser-gigaset.c
index d1f8ab915b15..b90776ef56ec 100644
--- a/drivers/isdn/gigaset/ser-gigaset.c
+++ b/drivers/isdn/gigaset/ser-gigaset.c
@@ -755,8 +755,10 @@ static int __init ser_gigaset_init(void)
755 driver = gigaset_initdriver(GIGASET_MINOR, GIGASET_MINORS, 755 driver = gigaset_initdriver(GIGASET_MINOR, GIGASET_MINORS,
756 GIGASET_MODULENAME, GIGASET_DEVNAME, 756 GIGASET_MODULENAME, GIGASET_DEVNAME,
757 &ops, THIS_MODULE); 757 &ops, THIS_MODULE);
758 if (!driver) 758 if (!driver) {
759 rc = -ENOMEM;
759 goto error; 760 goto error;
761 }
760 762
761 rc = tty_register_ldisc(N_GIGASET_M101, &gigaset_ldisc); 763 rc = tty_register_ldisc(N_GIGASET_M101, &gigaset_ldisc);
762 if (rc != 0) { 764 if (rc != 0) {
diff --git a/drivers/isdn/hisax/hfc4s8s_l1.c b/drivers/isdn/hisax/hfc4s8s_l1.c
index 9600cd771f1a..e034ed847ff3 100644
--- a/drivers/isdn/hisax/hfc4s8s_l1.c
+++ b/drivers/isdn/hisax/hfc4s8s_l1.c
@@ -1499,6 +1499,7 @@ hfc4s8s_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1499 printk(KERN_INFO 1499 printk(KERN_INFO
1500 "HFC-4S/8S: failed to request address space at 0x%04x\n", 1500 "HFC-4S/8S: failed to request address space at 0x%04x\n",
1501 hw->iobase); 1501 hw->iobase);
1502 err = -EBUSY;
1502 goto out; 1503 goto out;
1503 } 1504 }
1504 1505
diff --git a/drivers/mailbox/pcc.c b/drivers/mailbox/pcc.c
index 08c87fadca8c..1f32688c312d 100644
--- a/drivers/mailbox/pcc.c
+++ b/drivers/mailbox/pcc.c
@@ -65,6 +65,7 @@
65#include <linux/mailbox_controller.h> 65#include <linux/mailbox_controller.h>
66#include <linux/mailbox_client.h> 66#include <linux/mailbox_client.h>
67#include <linux/io-64-nonatomic-lo-hi.h> 67#include <linux/io-64-nonatomic-lo-hi.h>
68#include <acpi/pcc.h>
68 69
69#include "mailbox.h" 70#include "mailbox.h"
70 71
@@ -267,6 +268,8 @@ struct mbox_chan *pcc_mbox_request_channel(struct mbox_client *cl,
267 if (chan->txdone_method == TXDONE_BY_POLL && cl->knows_txdone) 268 if (chan->txdone_method == TXDONE_BY_POLL && cl->knows_txdone)
268 chan->txdone_method |= TXDONE_BY_ACK; 269 chan->txdone_method |= TXDONE_BY_ACK;
269 270
271 spin_unlock_irqrestore(&chan->lock, flags);
272
270 if (pcc_doorbell_irq[subspace_id] > 0) { 273 if (pcc_doorbell_irq[subspace_id] > 0) {
271 int rc; 274 int rc;
272 275
@@ -275,12 +278,11 @@ struct mbox_chan *pcc_mbox_request_channel(struct mbox_client *cl,
275 if (unlikely(rc)) { 278 if (unlikely(rc)) {
276 dev_err(dev, "failed to register PCC interrupt %d\n", 279 dev_err(dev, "failed to register PCC interrupt %d\n",
277 pcc_doorbell_irq[subspace_id]); 280 pcc_doorbell_irq[subspace_id]);
281 pcc_mbox_free_channel(chan);
278 chan = ERR_PTR(rc); 282 chan = ERR_PTR(rc);
279 } 283 }
280 } 284 }
281 285
282 spin_unlock_irqrestore(&chan->lock, flags);
283
284 return chan; 286 return chan;
285} 287}
286EXPORT_SYMBOL_GPL(pcc_mbox_request_channel); 288EXPORT_SYMBOL_GPL(pcc_mbox_request_channel);
@@ -304,20 +306,19 @@ void pcc_mbox_free_channel(struct mbox_chan *chan)
304 return; 306 return;
305 } 307 }
306 308
309 if (pcc_doorbell_irq[id] > 0)
310 devm_free_irq(chan->mbox->dev, pcc_doorbell_irq[id], chan);
311
307 spin_lock_irqsave(&chan->lock, flags); 312 spin_lock_irqsave(&chan->lock, flags);
308 chan->cl = NULL; 313 chan->cl = NULL;
309 chan->active_req = NULL; 314 chan->active_req = NULL;
310 if (chan->txdone_method == (TXDONE_BY_POLL | TXDONE_BY_ACK)) 315 if (chan->txdone_method == (TXDONE_BY_POLL | TXDONE_BY_ACK))
311 chan->txdone_method = TXDONE_BY_POLL; 316 chan->txdone_method = TXDONE_BY_POLL;
312 317
313 if (pcc_doorbell_irq[id] > 0)
314 devm_free_irq(chan->mbox->dev, pcc_doorbell_irq[id], chan);
315
316 spin_unlock_irqrestore(&chan->lock, flags); 318 spin_unlock_irqrestore(&chan->lock, flags);
317} 319}
318EXPORT_SYMBOL_GPL(pcc_mbox_free_channel); 320EXPORT_SYMBOL_GPL(pcc_mbox_free_channel);
319 321
320
321/** 322/**
322 * pcc_send_data - Called from Mailbox Controller code. Used 323 * pcc_send_data - Called from Mailbox Controller code. Used
323 * here only to ring the channel doorbell. The PCC client 324 * here only to ring the channel doorbell. The PCC client
diff --git a/drivers/md/dm-raid.c b/drivers/md/dm-raid.c
index 8abde6b8cedc..6d53810963f7 100644
--- a/drivers/md/dm-raid.c
+++ b/drivers/md/dm-raid.c
@@ -266,7 +266,7 @@ static struct raid_type {
266 {"raid10_offset", "raid10 offset (striped mirrors)", 0, 2, 10, ALGORITHM_RAID10_OFFSET}, 266 {"raid10_offset", "raid10 offset (striped mirrors)", 0, 2, 10, ALGORITHM_RAID10_OFFSET},
267 {"raid10_near", "raid10 near (striped mirrors)", 0, 2, 10, ALGORITHM_RAID10_NEAR}, 267 {"raid10_near", "raid10 near (striped mirrors)", 0, 2, 10, ALGORITHM_RAID10_NEAR},
268 {"raid10", "raid10 (striped mirrors)", 0, 2, 10, ALGORITHM_RAID10_DEFAULT}, 268 {"raid10", "raid10 (striped mirrors)", 0, 2, 10, ALGORITHM_RAID10_DEFAULT},
269 {"raid4", "raid4 (dedicated last parity disk)", 1, 2, 4, ALGORITHM_PARITY_N}, /* raid4 layout = raid5_n */ 269 {"raid4", "raid4 (dedicated first parity disk)", 1, 2, 5, ALGORITHM_PARITY_0}, /* raid4 layout = raid5_0 */
270 {"raid5_n", "raid5 (dedicated last parity disk)", 1, 2, 5, ALGORITHM_PARITY_N}, 270 {"raid5_n", "raid5 (dedicated last parity disk)", 1, 2, 5, ALGORITHM_PARITY_N},
271 {"raid5_ls", "raid5 (left symmetric)", 1, 2, 5, ALGORITHM_LEFT_SYMMETRIC}, 271 {"raid5_ls", "raid5 (left symmetric)", 1, 2, 5, ALGORITHM_LEFT_SYMMETRIC},
272 {"raid5_rs", "raid5 (right symmetric)", 1, 2, 5, ALGORITHM_RIGHT_SYMMETRIC}, 272 {"raid5_rs", "raid5 (right symmetric)", 1, 2, 5, ALGORITHM_RIGHT_SYMMETRIC},
@@ -2087,11 +2087,11 @@ static int super_init_validation(struct raid_set *rs, struct md_rdev *rdev)
2087 /* 2087 /*
2088 * No takeover/reshaping, because we don't have the extended v1.9.0 metadata 2088 * No takeover/reshaping, because we don't have the extended v1.9.0 metadata
2089 */ 2089 */
2090 if (le32_to_cpu(sb->level) != mddev->level) { 2090 if (le32_to_cpu(sb->level) != mddev->new_level) {
2091 DMERR("Reshaping/takeover raid sets not yet supported. (raid level/stripes/size change)"); 2091 DMERR("Reshaping/takeover raid sets not yet supported. (raid level/stripes/size change)");
2092 return -EINVAL; 2092 return -EINVAL;
2093 } 2093 }
2094 if (le32_to_cpu(sb->layout) != mddev->layout) { 2094 if (le32_to_cpu(sb->layout) != mddev->new_layout) {
2095 DMERR("Reshaping raid sets not yet supported. (raid layout change)"); 2095 DMERR("Reshaping raid sets not yet supported. (raid layout change)");
2096 DMERR(" 0x%X vs 0x%X", le32_to_cpu(sb->layout), mddev->layout); 2096 DMERR(" 0x%X vs 0x%X", le32_to_cpu(sb->layout), mddev->layout);
2097 DMERR(" Old layout: %s w/ %d copies", 2097 DMERR(" Old layout: %s w/ %d copies",
@@ -2102,7 +2102,7 @@ static int super_init_validation(struct raid_set *rs, struct md_rdev *rdev)
2102 raid10_md_layout_to_copies(mddev->layout)); 2102 raid10_md_layout_to_copies(mddev->layout));
2103 return -EINVAL; 2103 return -EINVAL;
2104 } 2104 }
2105 if (le32_to_cpu(sb->stripe_sectors) != mddev->chunk_sectors) { 2105 if (le32_to_cpu(sb->stripe_sectors) != mddev->new_chunk_sectors) {
2106 DMERR("Reshaping raid sets not yet supported. (stripe sectors change)"); 2106 DMERR("Reshaping raid sets not yet supported. (stripe sectors change)");
2107 return -EINVAL; 2107 return -EINVAL;
2108 } 2108 }
@@ -2115,6 +2115,8 @@ static int super_init_validation(struct raid_set *rs, struct md_rdev *rdev)
2115 return -EINVAL; 2115 return -EINVAL;
2116 } 2116 }
2117 2117
2118 DMINFO("Discovered old metadata format; upgrading to extended metadata format");
2119
2118 /* Table line is checked vs. authoritative superblock */ 2120 /* Table line is checked vs. authoritative superblock */
2119 rs_set_new(rs); 2121 rs_set_new(rs);
2120 } 2122 }
@@ -2258,7 +2260,8 @@ static int super_validate(struct raid_set *rs, struct md_rdev *rdev)
2258 if (!mddev->events && super_init_validation(rs, rdev)) 2260 if (!mddev->events && super_init_validation(rs, rdev))
2259 return -EINVAL; 2261 return -EINVAL;
2260 2262
2261 if (le32_to_cpu(sb->compat_features) != FEATURE_FLAG_SUPPORTS_V190) { 2263 if (le32_to_cpu(sb->compat_features) &&
2264 le32_to_cpu(sb->compat_features) != FEATURE_FLAG_SUPPORTS_V190) {
2262 rs->ti->error = "Unable to assemble array: Unknown flag(s) in compatible feature flags"; 2265 rs->ti->error = "Unable to assemble array: Unknown flag(s) in compatible feature flags";
2263 return -EINVAL; 2266 return -EINVAL;
2264 } 2267 }
@@ -3646,7 +3649,7 @@ static void raid_resume(struct dm_target *ti)
3646 3649
3647static struct target_type raid_target = { 3650static struct target_type raid_target = {
3648 .name = "raid", 3651 .name = "raid",
3649 .version = {1, 9, 0}, 3652 .version = {1, 9, 1},
3650 .module = THIS_MODULE, 3653 .module = THIS_MODULE,
3651 .ctr = raid_ctr, 3654 .ctr = raid_ctr,
3652 .dtr = raid_dtr, 3655 .dtr = raid_dtr,
diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
index bdf1606f67bc..9a8b71067c6e 100644
--- a/drivers/md/dm-raid1.c
+++ b/drivers/md/dm-raid1.c
@@ -145,7 +145,6 @@ static void dispatch_bios(void *context, struct bio_list *bio_list)
145 145
146struct dm_raid1_bio_record { 146struct dm_raid1_bio_record {
147 struct mirror *m; 147 struct mirror *m;
148 /* if details->bi_bdev == NULL, details were not saved */
149 struct dm_bio_details details; 148 struct dm_bio_details details;
150 region_t write_region; 149 region_t write_region;
151}; 150};
@@ -1200,8 +1199,6 @@ static int mirror_map(struct dm_target *ti, struct bio *bio)
1200 struct dm_raid1_bio_record *bio_record = 1199 struct dm_raid1_bio_record *bio_record =
1201 dm_per_bio_data(bio, sizeof(struct dm_raid1_bio_record)); 1200 dm_per_bio_data(bio, sizeof(struct dm_raid1_bio_record));
1202 1201
1203 bio_record->details.bi_bdev = NULL;
1204
1205 if (rw == WRITE) { 1202 if (rw == WRITE) {
1206 /* Save region for mirror_end_io() handler */ 1203 /* Save region for mirror_end_io() handler */
1207 bio_record->write_region = dm_rh_bio_to_region(ms->rh, bio); 1204 bio_record->write_region = dm_rh_bio_to_region(ms->rh, bio);
@@ -1260,22 +1257,12 @@ static int mirror_end_io(struct dm_target *ti, struct bio *bio, int error)
1260 } 1257 }
1261 1258
1262 if (error == -EOPNOTSUPP) 1259 if (error == -EOPNOTSUPP)
1263 goto out; 1260 return error;
1264 1261
1265 if ((error == -EWOULDBLOCK) && (bio->bi_opf & REQ_RAHEAD)) 1262 if ((error == -EWOULDBLOCK) && (bio->bi_opf & REQ_RAHEAD))
1266 goto out; 1263 return error;
1267 1264
1268 if (unlikely(error)) { 1265 if (unlikely(error)) {
1269 if (!bio_record->details.bi_bdev) {
1270 /*
1271 * There wasn't enough memory to record necessary
1272 * information for a retry or there was no other
1273 * mirror in-sync.
1274 */
1275 DMERR_LIMIT("Mirror read failed.");
1276 return -EIO;
1277 }
1278
1279 m = bio_record->m; 1266 m = bio_record->m;
1280 1267
1281 DMERR("Mirror read failed from %s. Trying alternative device.", 1268 DMERR("Mirror read failed from %s. Trying alternative device.",
@@ -1291,7 +1278,7 @@ static int mirror_end_io(struct dm_target *ti, struct bio *bio, int error)
1291 bd = &bio_record->details; 1278 bd = &bio_record->details;
1292 1279
1293 dm_bio_restore(bd, bio); 1280 dm_bio_restore(bd, bio);
1294 bio_record->details.bi_bdev = NULL; 1281 bio->bi_error = 0;
1295 1282
1296 queue_bio(ms, bio, rw); 1283 queue_bio(ms, bio, rw);
1297 return DM_ENDIO_INCOMPLETE; 1284 return DM_ENDIO_INCOMPLETE;
@@ -1299,9 +1286,6 @@ static int mirror_end_io(struct dm_target *ti, struct bio *bio, int error)
1299 DMERR("All replicated volumes dead, failing I/O"); 1286 DMERR("All replicated volumes dead, failing I/O");
1300 } 1287 }
1301 1288
1302out:
1303 bio_record->details.bi_bdev = NULL;
1304
1305 return error; 1289 return error;
1306} 1290}
1307 1291
diff --git a/drivers/md/dm-rq.c b/drivers/md/dm-rq.c
index dc75bea0d541..1d0d2adc050a 100644
--- a/drivers/md/dm-rq.c
+++ b/drivers/md/dm-rq.c
@@ -856,8 +856,11 @@ int dm_old_init_request_queue(struct mapped_device *md)
856 kthread_init_worker(&md->kworker); 856 kthread_init_worker(&md->kworker);
857 md->kworker_task = kthread_run(kthread_worker_fn, &md->kworker, 857 md->kworker_task = kthread_run(kthread_worker_fn, &md->kworker,
858 "kdmwork-%s", dm_device_name(md)); 858 "kdmwork-%s", dm_device_name(md));
859 if (IS_ERR(md->kworker_task)) 859 if (IS_ERR(md->kworker_task)) {
860 return PTR_ERR(md->kworker_task); 860 int error = PTR_ERR(md->kworker_task);
861 md->kworker_task = NULL;
862 return error;
863 }
861 864
862 elv_register_queue(md->queue); 865 elv_register_queue(md->queue);
863 866
diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
index 3e407a9cde1f..c4b53b332607 100644
--- a/drivers/md/dm-table.c
+++ b/drivers/md/dm-table.c
@@ -695,37 +695,32 @@ int dm_table_add_target(struct dm_table *t, const char *type,
695 695
696 tgt->type = dm_get_target_type(type); 696 tgt->type = dm_get_target_type(type);
697 if (!tgt->type) { 697 if (!tgt->type) {
698 DMERR("%s: %s: unknown target type", dm_device_name(t->md), 698 DMERR("%s: %s: unknown target type", dm_device_name(t->md), type);
699 type);
700 return -EINVAL; 699 return -EINVAL;
701 } 700 }
702 701
703 if (dm_target_needs_singleton(tgt->type)) { 702 if (dm_target_needs_singleton(tgt->type)) {
704 if (t->num_targets) { 703 if (t->num_targets) {
705 DMERR("%s: target type %s must appear alone in table", 704 tgt->error = "singleton target type must appear alone in table";
706 dm_device_name(t->md), type); 705 goto bad;
707 return -EINVAL;
708 } 706 }
709 t->singleton = true; 707 t->singleton = true;
710 } 708 }
711 709
712 if (dm_target_always_writeable(tgt->type) && !(t->mode & FMODE_WRITE)) { 710 if (dm_target_always_writeable(tgt->type) && !(t->mode & FMODE_WRITE)) {
713 DMERR("%s: target type %s may not be included in read-only tables", 711 tgt->error = "target type may not be included in a read-only table";
714 dm_device_name(t->md), type); 712 goto bad;
715 return -EINVAL;
716 } 713 }
717 714
718 if (t->immutable_target_type) { 715 if (t->immutable_target_type) {
719 if (t->immutable_target_type != tgt->type) { 716 if (t->immutable_target_type != tgt->type) {
720 DMERR("%s: immutable target type %s cannot be mixed with other target types", 717 tgt->error = "immutable target type cannot be mixed with other target types";
721 dm_device_name(t->md), t->immutable_target_type->name); 718 goto bad;
722 return -EINVAL;
723 } 719 }
724 } else if (dm_target_is_immutable(tgt->type)) { 720 } else if (dm_target_is_immutable(tgt->type)) {
725 if (t->num_targets) { 721 if (t->num_targets) {
726 DMERR("%s: immutable target type %s cannot be mixed with other target types", 722 tgt->error = "immutable target type cannot be mixed with other target types";
727 dm_device_name(t->md), tgt->type->name); 723 goto bad;
728 return -EINVAL;
729 } 724 }
730 t->immutable_target_type = tgt->type; 725 t->immutable_target_type = tgt->type;
731 } 726 }
@@ -740,7 +735,6 @@ int dm_table_add_target(struct dm_table *t, const char *type,
740 */ 735 */
741 if (!adjoin(t, tgt)) { 736 if (!adjoin(t, tgt)) {
742 tgt->error = "Gap in table"; 737 tgt->error = "Gap in table";
743 r = -EINVAL;
744 goto bad; 738 goto bad;
745 } 739 }
746 740
diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index 147af9536d0c..ef7bf1dd6900 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -1423,8 +1423,6 @@ static void cleanup_mapped_device(struct mapped_device *md)
1423 if (md->bs) 1423 if (md->bs)
1424 bioset_free(md->bs); 1424 bioset_free(md->bs);
1425 1425
1426 cleanup_srcu_struct(&md->io_barrier);
1427
1428 if (md->disk) { 1426 if (md->disk) {
1429 spin_lock(&_minor_lock); 1427 spin_lock(&_minor_lock);
1430 md->disk->private_data = NULL; 1428 md->disk->private_data = NULL;
@@ -1436,6 +1434,8 @@ static void cleanup_mapped_device(struct mapped_device *md)
1436 if (md->queue) 1434 if (md->queue)
1437 blk_cleanup_queue(md->queue); 1435 blk_cleanup_queue(md->queue);
1438 1436
1437 cleanup_srcu_struct(&md->io_barrier);
1438
1439 if (md->bdev) { 1439 if (md->bdev) {
1440 bdput(md->bdev); 1440 bdput(md->bdev);
1441 md->bdev = NULL; 1441 md->bdev = NULL;
diff --git a/drivers/md/md.c b/drivers/md/md.c
index eac84d8ff724..2089d46b0eb8 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -3887,10 +3887,10 @@ array_state_show(struct mddev *mddev, char *page)
3887 st = read_auto; 3887 st = read_auto;
3888 break; 3888 break;
3889 case 0: 3889 case 0:
3890 if (mddev->in_sync) 3890 if (test_bit(MD_CHANGE_PENDING, &mddev->flags))
3891 st = clean;
3892 else if (test_bit(MD_CHANGE_PENDING, &mddev->flags))
3893 st = write_pending; 3891 st = write_pending;
3892 else if (mddev->in_sync)
3893 st = clean;
3894 else if (mddev->safemode) 3894 else if (mddev->safemode)
3895 st = active_idle; 3895 st = active_idle;
3896 else 3896 else
@@ -8144,14 +8144,14 @@ void md_do_sync(struct md_thread *thread)
8144 8144
8145 if (!test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery) && 8145 if (!test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery) &&
8146 !test_bit(MD_RECOVERY_INTR, &mddev->recovery) && 8146 !test_bit(MD_RECOVERY_INTR, &mddev->recovery) &&
8147 mddev->curr_resync > 2) { 8147 mddev->curr_resync > 3) {
8148 mddev->curr_resync_completed = mddev->curr_resync; 8148 mddev->curr_resync_completed = mddev->curr_resync;
8149 sysfs_notify(&mddev->kobj, NULL, "sync_completed"); 8149 sysfs_notify(&mddev->kobj, NULL, "sync_completed");
8150 } 8150 }
8151 mddev->pers->sync_request(mddev, max_sectors, &skipped); 8151 mddev->pers->sync_request(mddev, max_sectors, &skipped);
8152 8152
8153 if (!test_bit(MD_RECOVERY_CHECK, &mddev->recovery) && 8153 if (!test_bit(MD_RECOVERY_CHECK, &mddev->recovery) &&
8154 mddev->curr_resync > 2) { 8154 mddev->curr_resync > 3) {
8155 if (test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) { 8155 if (test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) {
8156 if (test_bit(MD_RECOVERY_INTR, &mddev->recovery)) { 8156 if (test_bit(MD_RECOVERY_INTR, &mddev->recovery)) {
8157 if (mddev->curr_resync >= mddev->recovery_cp) { 8157 if (mddev->curr_resync >= mddev->recovery_cp) {
diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index 1961d827dbd1..29e2df5cd77b 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -403,11 +403,14 @@ static void raid1_end_write_request(struct bio *bio)
403 struct bio *to_put = NULL; 403 struct bio *to_put = NULL;
404 int mirror = find_bio_disk(r1_bio, bio); 404 int mirror = find_bio_disk(r1_bio, bio);
405 struct md_rdev *rdev = conf->mirrors[mirror].rdev; 405 struct md_rdev *rdev = conf->mirrors[mirror].rdev;
406 bool discard_error;
407
408 discard_error = bio->bi_error && bio_op(bio) == REQ_OP_DISCARD;
406 409
407 /* 410 /*
408 * 'one mirror IO has finished' event handler: 411 * 'one mirror IO has finished' event handler:
409 */ 412 */
410 if (bio->bi_error) { 413 if (bio->bi_error && !discard_error) {
411 set_bit(WriteErrorSeen, &rdev->flags); 414 set_bit(WriteErrorSeen, &rdev->flags);
412 if (!test_and_set_bit(WantReplacement, &rdev->flags)) 415 if (!test_and_set_bit(WantReplacement, &rdev->flags))
413 set_bit(MD_RECOVERY_NEEDED, & 416 set_bit(MD_RECOVERY_NEEDED, &
@@ -444,7 +447,7 @@ static void raid1_end_write_request(struct bio *bio)
444 447
445 /* Maybe we can clear some bad blocks. */ 448 /* Maybe we can clear some bad blocks. */
446 if (is_badblock(rdev, r1_bio->sector, r1_bio->sectors, 449 if (is_badblock(rdev, r1_bio->sector, r1_bio->sectors,
447 &first_bad, &bad_sectors)) { 450 &first_bad, &bad_sectors) && !discard_error) {
448 r1_bio->bios[mirror] = IO_MADE_GOOD; 451 r1_bio->bios[mirror] = IO_MADE_GOOD;
449 set_bit(R1BIO_MadeGood, &r1_bio->state); 452 set_bit(R1BIO_MadeGood, &r1_bio->state);
450 } 453 }
@@ -2294,17 +2297,23 @@ static void handle_read_error(struct r1conf *conf, struct r1bio *r1_bio)
2294 * This is all done synchronously while the array is 2297 * This is all done synchronously while the array is
2295 * frozen 2298 * frozen
2296 */ 2299 */
2300
2301 bio = r1_bio->bios[r1_bio->read_disk];
2302 bdevname(bio->bi_bdev, b);
2303 bio_put(bio);
2304 r1_bio->bios[r1_bio->read_disk] = NULL;
2305
2297 if (mddev->ro == 0) { 2306 if (mddev->ro == 0) {
2298 freeze_array(conf, 1); 2307 freeze_array(conf, 1);
2299 fix_read_error(conf, r1_bio->read_disk, 2308 fix_read_error(conf, r1_bio->read_disk,
2300 r1_bio->sector, r1_bio->sectors); 2309 r1_bio->sector, r1_bio->sectors);
2301 unfreeze_array(conf); 2310 unfreeze_array(conf);
2302 } else 2311 } else {
2303 md_error(mddev, conf->mirrors[r1_bio->read_disk].rdev); 2312 r1_bio->bios[r1_bio->read_disk] = IO_BLOCKED;
2313 }
2314
2304 rdev_dec_pending(conf->mirrors[r1_bio->read_disk].rdev, conf->mddev); 2315 rdev_dec_pending(conf->mirrors[r1_bio->read_disk].rdev, conf->mddev);
2305 2316
2306 bio = r1_bio->bios[r1_bio->read_disk];
2307 bdevname(bio->bi_bdev, b);
2308read_more: 2317read_more:
2309 disk = read_balance(conf, r1_bio, &max_sectors); 2318 disk = read_balance(conf, r1_bio, &max_sectors);
2310 if (disk == -1) { 2319 if (disk == -1) {
@@ -2315,11 +2324,6 @@ read_more:
2315 } else { 2324 } else {
2316 const unsigned long do_sync 2325 const unsigned long do_sync
2317 = r1_bio->master_bio->bi_opf & REQ_SYNC; 2326 = r1_bio->master_bio->bi_opf & REQ_SYNC;
2318 if (bio) {
2319 r1_bio->bios[r1_bio->read_disk] =
2320 mddev->ro ? IO_BLOCKED : NULL;
2321 bio_put(bio);
2322 }
2323 r1_bio->read_disk = disk; 2327 r1_bio->read_disk = disk;
2324 bio = bio_clone_mddev(r1_bio->master_bio, GFP_NOIO, mddev); 2328 bio = bio_clone_mddev(r1_bio->master_bio, GFP_NOIO, mddev);
2325 bio_trim(bio, r1_bio->sector - bio->bi_iter.bi_sector, 2329 bio_trim(bio, r1_bio->sector - bio->bi_iter.bi_sector,
diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index be1a9fca3b2d..39fddda2fef2 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -447,6 +447,9 @@ static void raid10_end_write_request(struct bio *bio)
447 struct r10conf *conf = r10_bio->mddev->private; 447 struct r10conf *conf = r10_bio->mddev->private;
448 int slot, repl; 448 int slot, repl;
449 struct md_rdev *rdev = NULL; 449 struct md_rdev *rdev = NULL;
450 bool discard_error;
451
452 discard_error = bio->bi_error && bio_op(bio) == REQ_OP_DISCARD;
450 453
451 dev = find_bio_disk(conf, r10_bio, bio, &slot, &repl); 454 dev = find_bio_disk(conf, r10_bio, bio, &slot, &repl);
452 455
@@ -460,7 +463,7 @@ static void raid10_end_write_request(struct bio *bio)
460 /* 463 /*
461 * this branch is our 'one mirror IO has finished' event handler: 464 * this branch is our 'one mirror IO has finished' event handler:
462 */ 465 */
463 if (bio->bi_error) { 466 if (bio->bi_error && !discard_error) {
464 if (repl) 467 if (repl)
465 /* Never record new bad blocks to replacement, 468 /* Never record new bad blocks to replacement,
466 * just fail it. 469 * just fail it.
@@ -503,7 +506,7 @@ static void raid10_end_write_request(struct bio *bio)
503 if (is_badblock(rdev, 506 if (is_badblock(rdev,
504 r10_bio->devs[slot].addr, 507 r10_bio->devs[slot].addr,
505 r10_bio->sectors, 508 r10_bio->sectors,
506 &first_bad, &bad_sectors)) { 509 &first_bad, &bad_sectors) && !discard_error) {
507 bio_put(bio); 510 bio_put(bio);
508 if (repl) 511 if (repl)
509 r10_bio->devs[slot].repl_bio = IO_MADE_GOOD; 512 r10_bio->devs[slot].repl_bio = IO_MADE_GOOD;
diff --git a/drivers/md/raid5-cache.c b/drivers/md/raid5-cache.c
index 1b1ab4a1d132..a227a9f3ee65 100644
--- a/drivers/md/raid5-cache.c
+++ b/drivers/md/raid5-cache.c
@@ -1087,7 +1087,7 @@ static int r5l_recovery_log(struct r5l_log *log)
1087 * 1's seq + 10 and let superblock points to meta2. The same recovery will 1087 * 1's seq + 10 and let superblock points to meta2. The same recovery will
1088 * not think meta 3 is a valid meta, because its seq doesn't match 1088 * not think meta 3 is a valid meta, because its seq doesn't match
1089 */ 1089 */
1090 if (ctx.seq > log->last_cp_seq + 1) { 1090 if (ctx.seq > log->last_cp_seq) {
1091 int ret; 1091 int ret;
1092 1092
1093 ret = r5l_log_write_empty_meta_block(log, ctx.pos, ctx.seq + 10); 1093 ret = r5l_log_write_empty_meta_block(log, ctx.pos, ctx.seq + 10);
@@ -1096,6 +1096,8 @@ static int r5l_recovery_log(struct r5l_log *log)
1096 log->seq = ctx.seq + 11; 1096 log->seq = ctx.seq + 11;
1097 log->log_start = r5l_ring_add(log, ctx.pos, BLOCK_SECTORS); 1097 log->log_start = r5l_ring_add(log, ctx.pos, BLOCK_SECTORS);
1098 r5l_write_super(log, ctx.pos); 1098 r5l_write_super(log, ctx.pos);
1099 log->last_checkpoint = ctx.pos;
1100 log->next_checkpoint = ctx.pos;
1099 } else { 1101 } else {
1100 log->log_start = ctx.pos; 1102 log->log_start = ctx.pos;
1101 log->seq = ctx.seq; 1103 log->seq = ctx.seq;
@@ -1154,6 +1156,7 @@ create:
1154 if (create_super) { 1156 if (create_super) {
1155 log->last_cp_seq = prandom_u32(); 1157 log->last_cp_seq = prandom_u32();
1156 cp = 0; 1158 cp = 0;
1159 r5l_log_write_empty_meta_block(log, cp, log->last_cp_seq);
1157 /* 1160 /*
1158 * Make sure super points to correct address. Log might have 1161 * Make sure super points to correct address. Log might have
1159 * data very soon. If super hasn't correct log tail address, 1162 * data very soon. If super hasn't correct log tail address,
@@ -1168,6 +1171,7 @@ create:
1168 if (log->max_free_space > RECLAIM_MAX_FREE_SPACE) 1171 if (log->max_free_space > RECLAIM_MAX_FREE_SPACE)
1169 log->max_free_space = RECLAIM_MAX_FREE_SPACE; 1172 log->max_free_space = RECLAIM_MAX_FREE_SPACE;
1170 log->last_checkpoint = cp; 1173 log->last_checkpoint = cp;
1174 log->next_checkpoint = cp;
1171 1175
1172 __free_page(page); 1176 __free_page(page);
1173 1177
diff --git a/drivers/media/dvb-frontends/Kconfig b/drivers/media/dvb-frontends/Kconfig
index 012225587c25..b71b747ee0ba 100644
--- a/drivers/media/dvb-frontends/Kconfig
+++ b/drivers/media/dvb-frontends/Kconfig
@@ -513,6 +513,11 @@ config DVB_AS102_FE
513 depends on DVB_CORE 513 depends on DVB_CORE
514 default DVB_AS102 514 default DVB_AS102
515 515
516config DVB_GP8PSK_FE
517 tristate
518 depends on DVB_CORE
519 default DVB_USB_GP8PSK
520
516comment "DVB-C (cable) frontends" 521comment "DVB-C (cable) frontends"
517 depends on DVB_CORE 522 depends on DVB_CORE
518 523
diff --git a/drivers/media/dvb-frontends/Makefile b/drivers/media/dvb-frontends/Makefile
index e90165ad361b..93921a4eaa27 100644
--- a/drivers/media/dvb-frontends/Makefile
+++ b/drivers/media/dvb-frontends/Makefile
@@ -121,6 +121,7 @@ obj-$(CONFIG_DVB_RTL2832_SDR) += rtl2832_sdr.o
121obj-$(CONFIG_DVB_M88RS2000) += m88rs2000.o 121obj-$(CONFIG_DVB_M88RS2000) += m88rs2000.o
122obj-$(CONFIG_DVB_AF9033) += af9033.o 122obj-$(CONFIG_DVB_AF9033) += af9033.o
123obj-$(CONFIG_DVB_AS102_FE) += as102_fe.o 123obj-$(CONFIG_DVB_AS102_FE) += as102_fe.o
124obj-$(CONFIG_DVB_GP8PSK_FE) += gp8psk-fe.o
124obj-$(CONFIG_DVB_TC90522) += tc90522.o 125obj-$(CONFIG_DVB_TC90522) += tc90522.o
125obj-$(CONFIG_DVB_HORUS3A) += horus3a.o 126obj-$(CONFIG_DVB_HORUS3A) += horus3a.o
126obj-$(CONFIG_DVB_ASCOT2E) += ascot2e.o 127obj-$(CONFIG_DVB_ASCOT2E) += ascot2e.o
diff --git a/drivers/media/usb/dvb-usb/gp8psk-fe.c b/drivers/media/dvb-frontends/gp8psk-fe.c
index db6eb79cde07..93f59bfea092 100644
--- a/drivers/media/usb/dvb-usb/gp8psk-fe.c
+++ b/drivers/media/dvb-frontends/gp8psk-fe.c
@@ -1,5 +1,5 @@
1/* DVB USB compliant Linux driver for the 1/*
2 * - GENPIX 8pks/qpsk/DCII USB2.0 DVB-S module 2 * Frontend driver for the GENPIX 8pks/qpsk/DCII USB2.0 DVB-S module
3 * 3 *
4 * Copyright (C) 2006,2007 Alan Nisota (alannisota@gmail.com) 4 * Copyright (C) 2006,2007 Alan Nisota (alannisota@gmail.com)
5 * Copyright (C) 2006,2007 Genpix Electronics (genpix@genpix-electronics.com) 5 * Copyright (C) 2006,2007 Genpix Electronics (genpix@genpix-electronics.com)
@@ -8,17 +8,31 @@
8 * 8 *
9 * This module is based off the vp7045 and vp702x modules 9 * This module is based off the vp7045 and vp702x modules
10 * 10 *
11 * This program is free software; you can redistribute it and/or modify it 11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the Free 12 * under the terms of the GNU General Public License as published by the Free
13 * Software Foundation, version 2. 13 * Software Foundation, version 2.
14 *
15 * see Documentation/dvb/README.dvb-usb for more information
16 */ 14 */
17#include "gp8psk.h" 15
16#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
17
18#include "gp8psk-fe.h"
19#include "dvb_frontend.h"
20
21static int debug;
22module_param(debug, int, 0644);
23MODULE_PARM_DESC(debug, "Turn on/off debugging (default:off).");
24
25#define dprintk(fmt, arg...) do { \
26 if (debug) \
27 printk(KERN_DEBUG pr_fmt("%s: " fmt), \
28 __func__, ##arg); \
29} while (0)
18 30
19struct gp8psk_fe_state { 31struct gp8psk_fe_state {
20 struct dvb_frontend fe; 32 struct dvb_frontend fe;
21 struct dvb_usb_device *d; 33 void *priv;
34 const struct gp8psk_fe_ops *ops;
35 bool is_rev1;
22 u8 lock; 36 u8 lock;
23 u16 snr; 37 u16 snr;
24 unsigned long next_status_check; 38 unsigned long next_status_check;
@@ -29,22 +43,24 @@ static int gp8psk_tuned_to_DCII(struct dvb_frontend *fe)
29{ 43{
30 struct gp8psk_fe_state *st = fe->demodulator_priv; 44 struct gp8psk_fe_state *st = fe->demodulator_priv;
31 u8 status; 45 u8 status;
32 gp8psk_usb_in_op(st->d, GET_8PSK_CONFIG, 0, 0, &status, 1); 46
47 st->ops->in(st->priv, GET_8PSK_CONFIG, 0, 0, &status, 1);
33 return status & bmDCtuned; 48 return status & bmDCtuned;
34} 49}
35 50
36static int gp8psk_set_tuner_mode(struct dvb_frontend *fe, int mode) 51static int gp8psk_set_tuner_mode(struct dvb_frontend *fe, int mode)
37{ 52{
38 struct gp8psk_fe_state *state = fe->demodulator_priv; 53 struct gp8psk_fe_state *st = fe->demodulator_priv;
39 return gp8psk_usb_out_op(state->d, SET_8PSK_CONFIG, mode, 0, NULL, 0); 54
55 return st->ops->out(st->priv, SET_8PSK_CONFIG, mode, 0, NULL, 0);
40} 56}
41 57
42static int gp8psk_fe_update_status(struct gp8psk_fe_state *st) 58static int gp8psk_fe_update_status(struct gp8psk_fe_state *st)
43{ 59{
44 u8 buf[6]; 60 u8 buf[6];
45 if (time_after(jiffies,st->next_status_check)) { 61 if (time_after(jiffies,st->next_status_check)) {
46 gp8psk_usb_in_op(st->d, GET_SIGNAL_LOCK, 0,0,&st->lock,1); 62 st->ops->in(st->priv, GET_SIGNAL_LOCK, 0, 0, &st->lock, 1);
47 gp8psk_usb_in_op(st->d, GET_SIGNAL_STRENGTH, 0,0,buf,6); 63 st->ops->in(st->priv, GET_SIGNAL_STRENGTH, 0, 0, buf, 6);
48 st->snr = (buf[1]) << 8 | buf[0]; 64 st->snr = (buf[1]) << 8 | buf[0];
49 st->next_status_check = jiffies + (st->status_check_interval*HZ)/1000; 65 st->next_status_check = jiffies + (st->status_check_interval*HZ)/1000;
50 } 66 }
@@ -116,13 +132,12 @@ static int gp8psk_fe_get_tune_settings(struct dvb_frontend* fe, struct dvb_front
116 132
117static int gp8psk_fe_set_frontend(struct dvb_frontend *fe) 133static int gp8psk_fe_set_frontend(struct dvb_frontend *fe)
118{ 134{
119 struct gp8psk_fe_state *state = fe->demodulator_priv; 135 struct gp8psk_fe_state *st = fe->demodulator_priv;
120 struct dtv_frontend_properties *c = &fe->dtv_property_cache; 136 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
121 u8 cmd[10]; 137 u8 cmd[10];
122 u32 freq = c->frequency * 1000; 138 u32 freq = c->frequency * 1000;
123 int gp_product_id = le16_to_cpu(state->d->udev->descriptor.idProduct);
124 139
125 deb_fe("%s()\n", __func__); 140 dprintk("%s()\n", __func__);
126 141
127 cmd[4] = freq & 0xff; 142 cmd[4] = freq & 0xff;
128 cmd[5] = (freq >> 8) & 0xff; 143 cmd[5] = (freq >> 8) & 0xff;
@@ -136,21 +151,21 @@ static int gp8psk_fe_set_frontend(struct dvb_frontend *fe)
136 switch (c->delivery_system) { 151 switch (c->delivery_system) {
137 case SYS_DVBS: 152 case SYS_DVBS:
138 if (c->modulation != QPSK) { 153 if (c->modulation != QPSK) {
139 deb_fe("%s: unsupported modulation selected (%d)\n", 154 dprintk("%s: unsupported modulation selected (%d)\n",
140 __func__, c->modulation); 155 __func__, c->modulation);
141 return -EOPNOTSUPP; 156 return -EOPNOTSUPP;
142 } 157 }
143 c->fec_inner = FEC_AUTO; 158 c->fec_inner = FEC_AUTO;
144 break; 159 break;
145 case SYS_DVBS2: /* kept for backwards compatibility */ 160 case SYS_DVBS2: /* kept for backwards compatibility */
146 deb_fe("%s: DVB-S2 delivery system selected\n", __func__); 161 dprintk("%s: DVB-S2 delivery system selected\n", __func__);
147 break; 162 break;
148 case SYS_TURBO: 163 case SYS_TURBO:
149 deb_fe("%s: Turbo-FEC delivery system selected\n", __func__); 164 dprintk("%s: Turbo-FEC delivery system selected\n", __func__);
150 break; 165 break;
151 166
152 default: 167 default:
153 deb_fe("%s: unsupported delivery system selected (%d)\n", 168 dprintk("%s: unsupported delivery system selected (%d)\n",
154 __func__, c->delivery_system); 169 __func__, c->delivery_system);
155 return -EOPNOTSUPP; 170 return -EOPNOTSUPP;
156 } 171 }
@@ -161,9 +176,9 @@ static int gp8psk_fe_set_frontend(struct dvb_frontend *fe)
161 cmd[3] = (c->symbol_rate >> 24) & 0xff; 176 cmd[3] = (c->symbol_rate >> 24) & 0xff;
162 switch (c->modulation) { 177 switch (c->modulation) {
163 case QPSK: 178 case QPSK:
164 if (gp_product_id == USB_PID_GENPIX_8PSK_REV_1_WARM) 179 if (st->is_rev1)
165 if (gp8psk_tuned_to_DCII(fe)) 180 if (gp8psk_tuned_to_DCII(fe))
166 gp8psk_bcm4500_reload(state->d); 181 st->ops->reload(st->priv);
167 switch (c->fec_inner) { 182 switch (c->fec_inner) {
168 case FEC_1_2: 183 case FEC_1_2:
169 cmd[9] = 0; break; 184 cmd[9] = 0; break;
@@ -207,18 +222,18 @@ static int gp8psk_fe_set_frontend(struct dvb_frontend *fe)
207 cmd[9] = 0; 222 cmd[9] = 0;
208 break; 223 break;
209 default: /* Unknown modulation */ 224 default: /* Unknown modulation */
210 deb_fe("%s: unsupported modulation selected (%d)\n", 225 dprintk("%s: unsupported modulation selected (%d)\n",
211 __func__, c->modulation); 226 __func__, c->modulation);
212 return -EOPNOTSUPP; 227 return -EOPNOTSUPP;
213 } 228 }
214 229
215 if (gp_product_id == USB_PID_GENPIX_8PSK_REV_1_WARM) 230 if (st->is_rev1)
216 gp8psk_set_tuner_mode(fe, 0); 231 gp8psk_set_tuner_mode(fe, 0);
217 gp8psk_usb_out_op(state->d, TUNE_8PSK, 0, 0, cmd, 10); 232 st->ops->out(st->priv, TUNE_8PSK, 0, 0, cmd, 10);
218 233
219 state->lock = 0; 234 st->lock = 0;
220 state->next_status_check = jiffies; 235 st->next_status_check = jiffies;
221 state->status_check_interval = 200; 236 st->status_check_interval = 200;
222 237
223 return 0; 238 return 0;
224} 239}
@@ -228,9 +243,9 @@ static int gp8psk_fe_send_diseqc_msg (struct dvb_frontend* fe,
228{ 243{
229 struct gp8psk_fe_state *st = fe->demodulator_priv; 244 struct gp8psk_fe_state *st = fe->demodulator_priv;
230 245
231 deb_fe("%s\n",__func__); 246 dprintk("%s\n", __func__);
232 247
233 if (gp8psk_usb_out_op(st->d,SEND_DISEQC_COMMAND, m->msg[0], 0, 248 if (st->ops->out(st->priv, SEND_DISEQC_COMMAND, m->msg[0], 0,
234 m->msg, m->msg_len)) { 249 m->msg, m->msg_len)) {
235 return -EINVAL; 250 return -EINVAL;
236 } 251 }
@@ -243,12 +258,12 @@ static int gp8psk_fe_send_diseqc_burst(struct dvb_frontend *fe,
243 struct gp8psk_fe_state *st = fe->demodulator_priv; 258 struct gp8psk_fe_state *st = fe->demodulator_priv;
244 u8 cmd; 259 u8 cmd;
245 260
246 deb_fe("%s\n",__func__); 261 dprintk("%s\n", __func__);
247 262
248 /* These commands are certainly wrong */ 263 /* These commands are certainly wrong */
249 cmd = (burst == SEC_MINI_A) ? 0x00 : 0x01; 264 cmd = (burst == SEC_MINI_A) ? 0x00 : 0x01;
250 265
251 if (gp8psk_usb_out_op(st->d,SEND_DISEQC_COMMAND, cmd, 0, 266 if (st->ops->out(st->priv, SEND_DISEQC_COMMAND, cmd, 0,
252 &cmd, 0)) { 267 &cmd, 0)) {
253 return -EINVAL; 268 return -EINVAL;
254 } 269 }
@@ -258,10 +273,10 @@ static int gp8psk_fe_send_diseqc_burst(struct dvb_frontend *fe,
258static int gp8psk_fe_set_tone(struct dvb_frontend *fe, 273static int gp8psk_fe_set_tone(struct dvb_frontend *fe,
259 enum fe_sec_tone_mode tone) 274 enum fe_sec_tone_mode tone)
260{ 275{
261 struct gp8psk_fe_state* state = fe->demodulator_priv; 276 struct gp8psk_fe_state *st = fe->demodulator_priv;
262 277
263 if (gp8psk_usb_out_op(state->d,SET_22KHZ_TONE, 278 if (st->ops->out(st->priv, SET_22KHZ_TONE,
264 (tone == SEC_TONE_ON), 0, NULL, 0)) { 279 (tone == SEC_TONE_ON), 0, NULL, 0)) {
265 return -EINVAL; 280 return -EINVAL;
266 } 281 }
267 return 0; 282 return 0;
@@ -270,9 +285,9 @@ static int gp8psk_fe_set_tone(struct dvb_frontend *fe,
270static int gp8psk_fe_set_voltage(struct dvb_frontend *fe, 285static int gp8psk_fe_set_voltage(struct dvb_frontend *fe,
271 enum fe_sec_voltage voltage) 286 enum fe_sec_voltage voltage)
272{ 287{
273 struct gp8psk_fe_state* state = fe->demodulator_priv; 288 struct gp8psk_fe_state *st = fe->demodulator_priv;
274 289
275 if (gp8psk_usb_out_op(state->d,SET_LNB_VOLTAGE, 290 if (st->ops->out(st->priv, SET_LNB_VOLTAGE,
276 voltage == SEC_VOLTAGE_18, 0, NULL, 0)) { 291 voltage == SEC_VOLTAGE_18, 0, NULL, 0)) {
277 return -EINVAL; 292 return -EINVAL;
278 } 293 }
@@ -281,52 +296,60 @@ static int gp8psk_fe_set_voltage(struct dvb_frontend *fe,
281 296
282static int gp8psk_fe_enable_high_lnb_voltage(struct dvb_frontend* fe, long onoff) 297static int gp8psk_fe_enable_high_lnb_voltage(struct dvb_frontend* fe, long onoff)
283{ 298{
284 struct gp8psk_fe_state* state = fe->demodulator_priv; 299 struct gp8psk_fe_state *st = fe->demodulator_priv;
285 return gp8psk_usb_out_op(state->d, USE_EXTRA_VOLT, onoff, 0,NULL,0); 300
301 return st->ops->out(st->priv, USE_EXTRA_VOLT, onoff, 0, NULL, 0);
286} 302}
287 303
288static int gp8psk_fe_send_legacy_dish_cmd (struct dvb_frontend* fe, unsigned long sw_cmd) 304static int gp8psk_fe_send_legacy_dish_cmd (struct dvb_frontend* fe, unsigned long sw_cmd)
289{ 305{
290 struct gp8psk_fe_state* state = fe->demodulator_priv; 306 struct gp8psk_fe_state *st = fe->demodulator_priv;
291 u8 cmd = sw_cmd & 0x7f; 307 u8 cmd = sw_cmd & 0x7f;
292 308
293 if (gp8psk_usb_out_op(state->d,SET_DN_SWITCH, cmd, 0, 309 if (st->ops->out(st->priv, SET_DN_SWITCH, cmd, 0, NULL, 0))
294 NULL, 0)) {
295 return -EINVAL; 310 return -EINVAL;
296 } 311
297 if (gp8psk_usb_out_op(state->d,SET_LNB_VOLTAGE, !!(sw_cmd & 0x80), 312 if (st->ops->out(st->priv, SET_LNB_VOLTAGE, !!(sw_cmd & 0x80),
298 0, NULL, 0)) { 313 0, NULL, 0))
299 return -EINVAL; 314 return -EINVAL;
300 }
301 315
302 return 0; 316 return 0;
303} 317}
304 318
305static void gp8psk_fe_release(struct dvb_frontend* fe) 319static void gp8psk_fe_release(struct dvb_frontend* fe)
306{ 320{
307 struct gp8psk_fe_state *state = fe->demodulator_priv; 321 struct gp8psk_fe_state *st = fe->demodulator_priv;
308 kfree(state); 322
323 kfree(st);
309} 324}
310 325
311static struct dvb_frontend_ops gp8psk_fe_ops; 326static struct dvb_frontend_ops gp8psk_fe_ops;
312 327
313struct dvb_frontend * gp8psk_fe_attach(struct dvb_usb_device *d) 328struct dvb_frontend *gp8psk_fe_attach(const struct gp8psk_fe_ops *ops,
329 void *priv, bool is_rev1)
314{ 330{
315 struct gp8psk_fe_state *s = kzalloc(sizeof(struct gp8psk_fe_state), GFP_KERNEL); 331 struct gp8psk_fe_state *st;
316 if (s == NULL)
317 goto error;
318
319 s->d = d;
320 memcpy(&s->fe.ops, &gp8psk_fe_ops, sizeof(struct dvb_frontend_ops));
321 s->fe.demodulator_priv = s;
322
323 goto success;
324error:
325 return NULL;
326success:
327 return &s->fe;
328}
329 332
333 if (!ops || !ops->in || !ops->out || !ops->reload) {
334 pr_err("Error! gp8psk-fe ops not defined.\n");
335 return NULL;
336 }
337
338 st = kzalloc(sizeof(struct gp8psk_fe_state), GFP_KERNEL);
339 if (!st)
340 return NULL;
341
342 memcpy(&st->fe.ops, &gp8psk_fe_ops, sizeof(struct dvb_frontend_ops));
343 st->fe.demodulator_priv = st;
344 st->ops = ops;
345 st->priv = priv;
346 st->is_rev1 = is_rev1;
347
348 pr_info("Frontend %sattached\n", is_rev1 ? "revision 1 " : "");
349
350 return &st->fe;
351}
352EXPORT_SYMBOL_GPL(gp8psk_fe_attach);
330 353
331static struct dvb_frontend_ops gp8psk_fe_ops = { 354static struct dvb_frontend_ops gp8psk_fe_ops = {
332 .delsys = { SYS_DVBS }, 355 .delsys = { SYS_DVBS },
@@ -370,3 +393,8 @@ static struct dvb_frontend_ops gp8psk_fe_ops = {
370 .dishnetwork_send_legacy_command = gp8psk_fe_send_legacy_dish_cmd, 393 .dishnetwork_send_legacy_command = gp8psk_fe_send_legacy_dish_cmd,
371 .enable_high_lnb_voltage = gp8psk_fe_enable_high_lnb_voltage 394 .enable_high_lnb_voltage = gp8psk_fe_enable_high_lnb_voltage
372}; 395};
396
397MODULE_AUTHOR("Alan Nisota <alannisota@gamil.com>");
398MODULE_DESCRIPTION("Frontend Driver for Genpix DVB-S");
399MODULE_VERSION("1.1");
400MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb-frontends/gp8psk-fe.h b/drivers/media/dvb-frontends/gp8psk-fe.h
new file mode 100644
index 000000000000..6c7944b1ecd6
--- /dev/null
+++ b/drivers/media/dvb-frontends/gp8psk-fe.h
@@ -0,0 +1,82 @@
1/*
2 * gp8psk_fe 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 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */
14
15#ifndef GP8PSK_FE_H
16#define GP8PSK_FE_H
17
18#include <linux/types.h>
19
20/* gp8psk commands */
21
22#define GET_8PSK_CONFIG 0x80 /* in */
23#define SET_8PSK_CONFIG 0x81
24#define I2C_WRITE 0x83
25#define I2C_READ 0x84
26#define ARM_TRANSFER 0x85
27#define TUNE_8PSK 0x86
28#define GET_SIGNAL_STRENGTH 0x87 /* in */
29#define LOAD_BCM4500 0x88
30#define BOOT_8PSK 0x89 /* in */
31#define START_INTERSIL 0x8A /* in */
32#define SET_LNB_VOLTAGE 0x8B
33#define SET_22KHZ_TONE 0x8C
34#define SEND_DISEQC_COMMAND 0x8D
35#define SET_DVB_MODE 0x8E
36#define SET_DN_SWITCH 0x8F
37#define GET_SIGNAL_LOCK 0x90 /* in */
38#define GET_FW_VERS 0x92
39#define GET_SERIAL_NUMBER 0x93 /* in */
40#define USE_EXTRA_VOLT 0x94
41#define GET_FPGA_VERS 0x95
42#define CW3K_INIT 0x9d
43
44/* PSK_configuration bits */
45#define bm8pskStarted 0x01
46#define bm8pskFW_Loaded 0x02
47#define bmIntersilOn 0x04
48#define bmDVBmode 0x08
49#define bm22kHz 0x10
50#define bmSEL18V 0x20
51#define bmDCtuned 0x40
52#define bmArmed 0x80
53
54/* Satellite modulation modes */
55#define ADV_MOD_DVB_QPSK 0 /* DVB-S QPSK */
56#define ADV_MOD_TURBO_QPSK 1 /* Turbo QPSK */
57#define ADV_MOD_TURBO_8PSK 2 /* Turbo 8PSK (also used for Trellis 8PSK) */
58#define ADV_MOD_TURBO_16QAM 3 /* Turbo 16QAM (also used for Trellis 8PSK) */
59
60#define ADV_MOD_DCII_C_QPSK 4 /* Digicipher II Combo */
61#define ADV_MOD_DCII_I_QPSK 5 /* Digicipher II I-stream */
62#define ADV_MOD_DCII_Q_QPSK 6 /* Digicipher II Q-stream */
63#define ADV_MOD_DCII_C_OQPSK 7 /* Digicipher II offset QPSK */
64#define ADV_MOD_DSS_QPSK 8 /* DSS (DIRECTV) QPSK */
65#define ADV_MOD_DVB_BPSK 9 /* DVB-S BPSK */
66
67/* firmware revision id's */
68#define GP8PSK_FW_REV1 0x020604
69#define GP8PSK_FW_REV2 0x020704
70#define GP8PSK_FW_VERS(_fw_vers) \
71 ((_fw_vers)[2]<<0x10 | (_fw_vers)[1]<<0x08 | (_fw_vers)[0])
72
73struct gp8psk_fe_ops {
74 int (*in)(void *priv, u8 req, u16 value, u16 index, u8 *b, int blen);
75 int (*out)(void *priv, u8 req, u16 value, u16 index, u8 *b, int blen);
76 int (*reload)(void *priv);
77};
78
79struct dvb_frontend *gp8psk_fe_attach(const struct gp8psk_fe_ops *ops,
80 void *priv, bool is_rev1);
81
82#endif
diff --git a/drivers/media/i2c/ir-kbd-i2c.c b/drivers/media/i2c/ir-kbd-i2c.c
index f95a6bc839d5..cede3975d04b 100644
--- a/drivers/media/i2c/ir-kbd-i2c.c
+++ b/drivers/media/i2c/ir-kbd-i2c.c
@@ -118,7 +118,7 @@ static int get_key_haup_common(struct IR_i2c *ir, enum rc_type *protocol,
118 *protocol = RC_TYPE_RC6_MCE; 118 *protocol = RC_TYPE_RC6_MCE;
119 dev &= 0x7f; 119 dev &= 0x7f;
120 dprintk(1, "ir hauppauge (rc6-mce): t%d vendor=%d dev=%d code=%d\n", 120 dprintk(1, "ir hauppauge (rc6-mce): t%d vendor=%d dev=%d code=%d\n",
121 toggle, vendor, dev, code); 121 *ptoggle, vendor, dev, code);
122 } else { 122 } else {
123 *ptoggle = 0; 123 *ptoggle = 0;
124 *protocol = RC_TYPE_RC6_6A_32; 124 *protocol = RC_TYPE_RC6_6A_32;
diff --git a/drivers/media/pci/ivtv/ivtv-udma.c b/drivers/media/pci/ivtv/ivtv-udma.c
index 4769469fe842..2c9232ef7baa 100644
--- a/drivers/media/pci/ivtv/ivtv-udma.c
+++ b/drivers/media/pci/ivtv/ivtv-udma.c
@@ -124,8 +124,8 @@ int ivtv_udma_setup(struct ivtv *itv, unsigned long ivtv_dest_addr,
124 } 124 }
125 125
126 /* Get user pages for DMA Xfer */ 126 /* Get user pages for DMA Xfer */
127 err = get_user_pages_unlocked(user_dma.uaddr, user_dma.page_count, 0, 127 err = get_user_pages_unlocked(user_dma.uaddr, user_dma.page_count,
128 1, dma->map); 128 dma->map, FOLL_FORCE);
129 129
130 if (user_dma.page_count != err) { 130 if (user_dma.page_count != err) {
131 IVTV_DEBUG_WARN("failed to map user pages, returned %d instead of %d\n", 131 IVTV_DEBUG_WARN("failed to map user pages, returned %d instead of %d\n",
diff --git a/drivers/media/pci/ivtv/ivtv-yuv.c b/drivers/media/pci/ivtv/ivtv-yuv.c
index b094054cda6e..f7299d3d8244 100644
--- a/drivers/media/pci/ivtv/ivtv-yuv.c
+++ b/drivers/media/pci/ivtv/ivtv-yuv.c
@@ -76,11 +76,12 @@ static int ivtv_yuv_prep_user_dma(struct ivtv *itv, struct ivtv_user_dma *dma,
76 76
77 /* Get user pages for DMA Xfer */ 77 /* Get user pages for DMA Xfer */
78 y_pages = get_user_pages_unlocked(y_dma.uaddr, 78 y_pages = get_user_pages_unlocked(y_dma.uaddr,
79 y_dma.page_count, 0, 1, &dma->map[0]); 79 y_dma.page_count, &dma->map[0], FOLL_FORCE);
80 uv_pages = 0; /* silence gcc. value is set and consumed only if: */ 80 uv_pages = 0; /* silence gcc. value is set and consumed only if: */
81 if (y_pages == y_dma.page_count) { 81 if (y_pages == y_dma.page_count) {
82 uv_pages = get_user_pages_unlocked(uv_dma.uaddr, 82 uv_pages = get_user_pages_unlocked(uv_dma.uaddr,
83 uv_dma.page_count, 0, 1, &dma->map[y_pages]); 83 uv_dma.page_count, &dma->map[y_pages],
84 FOLL_FORCE);
84 } 85 }
85 86
86 if (y_pages != y_dma.page_count || uv_pages != uv_dma.page_count) { 87 if (y_pages != y_dma.page_count || uv_pages != uv_dma.page_count) {
diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
index e668dde6d857..a31b95cb3b09 100644
--- a/drivers/media/platform/omap/omap_vout.c
+++ b/drivers/media/platform/omap/omap_vout.c
@@ -214,7 +214,7 @@ static int omap_vout_get_userptr(struct videobuf_buffer *vb, u32 virtp,
214 if (!vec) 214 if (!vec)
215 return -ENOMEM; 215 return -ENOMEM;
216 216
217 ret = get_vaddr_frames(virtp, 1, true, false, vec); 217 ret = get_vaddr_frames(virtp, 1, FOLL_WRITE, vec);
218 if (ret != 1) { 218 if (ret != 1) {
219 frame_vector_destroy(vec); 219 frame_vector_destroy(vec);
220 return -EINVAL; 220 return -EINVAL;
diff --git a/drivers/media/tuners/tuner-xc2028.c b/drivers/media/tuners/tuner-xc2028.c
index 317ef63ee789..8d96a22647b3 100644
--- a/drivers/media/tuners/tuner-xc2028.c
+++ b/drivers/media/tuners/tuner-xc2028.c
@@ -281,6 +281,14 @@ static void free_firmware(struct xc2028_data *priv)
281 int i; 281 int i;
282 tuner_dbg("%s called\n", __func__); 282 tuner_dbg("%s called\n", __func__);
283 283
284 /* free allocated f/w string */
285 if (priv->fname != firmware_name)
286 kfree(priv->fname);
287 priv->fname = NULL;
288
289 priv->state = XC2028_NO_FIRMWARE;
290 memset(&priv->cur_fw, 0, sizeof(priv->cur_fw));
291
284 if (!priv->firm) 292 if (!priv->firm)
285 return; 293 return;
286 294
@@ -291,9 +299,6 @@ static void free_firmware(struct xc2028_data *priv)
291 299
292 priv->firm = NULL; 300 priv->firm = NULL;
293 priv->firm_size = 0; 301 priv->firm_size = 0;
294 priv->state = XC2028_NO_FIRMWARE;
295
296 memset(&priv->cur_fw, 0, sizeof(priv->cur_fw));
297} 302}
298 303
299static int load_all_firmwares(struct dvb_frontend *fe, 304static int load_all_firmwares(struct dvb_frontend *fe,
@@ -884,9 +889,8 @@ read_not_reliable:
884 return 0; 889 return 0;
885 890
886fail: 891fail:
887 priv->state = XC2028_NO_FIRMWARE; 892 free_firmware(priv);
888 893
889 memset(&priv->cur_fw, 0, sizeof(priv->cur_fw));
890 if (retry_count < 8) { 894 if (retry_count < 8) {
891 msleep(50); 895 msleep(50);
892 retry_count++; 896 retry_count++;
@@ -1332,11 +1336,8 @@ static int xc2028_dvb_release(struct dvb_frontend *fe)
1332 mutex_lock(&xc2028_list_mutex); 1336 mutex_lock(&xc2028_list_mutex);
1333 1337
1334 /* only perform final cleanup if this is the last instance */ 1338 /* only perform final cleanup if this is the last instance */
1335 if (hybrid_tuner_report_instance_count(priv) == 1) { 1339 if (hybrid_tuner_report_instance_count(priv) == 1)
1336 free_firmware(priv); 1340 free_firmware(priv);
1337 kfree(priv->ctrl.fname);
1338 priv->ctrl.fname = NULL;
1339 }
1340 1341
1341 if (priv) 1342 if (priv)
1342 hybrid_tuner_release_state(priv); 1343 hybrid_tuner_release_state(priv);
@@ -1399,19 +1400,8 @@ static int xc2028_set_config(struct dvb_frontend *fe, void *priv_cfg)
1399 1400
1400 /* 1401 /*
1401 * Copy the config data. 1402 * Copy the config data.
1402 * For the firmware name, keep a local copy of the string,
1403 * in order to avoid troubles during device release.
1404 */ 1403 */
1405 kfree(priv->ctrl.fname);
1406 priv->ctrl.fname = NULL;
1407 memcpy(&priv->ctrl, p, sizeof(priv->ctrl)); 1404 memcpy(&priv->ctrl, p, sizeof(priv->ctrl));
1408 if (p->fname) {
1409 priv->ctrl.fname = kstrdup(p->fname, GFP_KERNEL);
1410 if (priv->ctrl.fname == NULL) {
1411 rc = -ENOMEM;
1412 goto unlock;
1413 }
1414 }
1415 1405
1416 /* 1406 /*
1417 * If firmware name changed, frees firmware. As free_firmware will 1407 * If firmware name changed, frees firmware. As free_firmware will
@@ -1426,10 +1416,15 @@ static int xc2028_set_config(struct dvb_frontend *fe, void *priv_cfg)
1426 1416
1427 if (priv->state == XC2028_NO_FIRMWARE) { 1417 if (priv->state == XC2028_NO_FIRMWARE) {
1428 if (!firmware_name[0]) 1418 if (!firmware_name[0])
1429 priv->fname = priv->ctrl.fname; 1419 priv->fname = kstrdup(p->fname, GFP_KERNEL);
1430 else 1420 else
1431 priv->fname = firmware_name; 1421 priv->fname = firmware_name;
1432 1422
1423 if (!priv->fname) {
1424 rc = -ENOMEM;
1425 goto unlock;
1426 }
1427
1433 rc = request_firmware_nowait(THIS_MODULE, 1, 1428 rc = request_firmware_nowait(THIS_MODULE, 1,
1434 priv->fname, 1429 priv->fname,
1435 priv->i2c_props.adap->dev.parent, 1430 priv->i2c_props.adap->dev.parent,
diff --git a/drivers/media/usb/b2c2/flexcop-usb.c b/drivers/media/usb/b2c2/flexcop-usb.c
index d4bdba60b0f7..52bc42da8a4c 100644
--- a/drivers/media/usb/b2c2/flexcop-usb.c
+++ b/drivers/media/usb/b2c2/flexcop-usb.c
@@ -73,23 +73,34 @@ static int flexcop_usb_readwrite_dw(struct flexcop_device *fc, u16 wRegOffsPCI,
73 u8 request_type = (read ? USB_DIR_IN : USB_DIR_OUT) | USB_TYPE_VENDOR; 73 u8 request_type = (read ? USB_DIR_IN : USB_DIR_OUT) | USB_TYPE_VENDOR;
74 u8 wAddress = B2C2_FLEX_PCIOFFSET_TO_INTERNALADDR(wRegOffsPCI) | 74 u8 wAddress = B2C2_FLEX_PCIOFFSET_TO_INTERNALADDR(wRegOffsPCI) |
75 (read ? 0x80 : 0); 75 (read ? 0x80 : 0);
76 int ret;
77
78 mutex_lock(&fc_usb->data_mutex);
79 if (!read)
80 memcpy(fc_usb->data, val, sizeof(*val));
76 81
77 int len = usb_control_msg(fc_usb->udev, 82 ret = usb_control_msg(fc_usb->udev,
78 read ? B2C2_USB_CTRL_PIPE_IN : B2C2_USB_CTRL_PIPE_OUT, 83 read ? B2C2_USB_CTRL_PIPE_IN : B2C2_USB_CTRL_PIPE_OUT,
79 request, 84 request,
80 request_type, /* 0xc0 read or 0x40 write */ 85 request_type, /* 0xc0 read or 0x40 write */
81 wAddress, 86 wAddress,
82 0, 87 0,
83 val, 88 fc_usb->data,
84 sizeof(u32), 89 sizeof(u32),
85 B2C2_WAIT_FOR_OPERATION_RDW * HZ); 90 B2C2_WAIT_FOR_OPERATION_RDW * HZ);
86 91
87 if (len != sizeof(u32)) { 92 if (ret != sizeof(u32)) {
88 err("error while %s dword from %d (%d).", read ? "reading" : 93 err("error while %s dword from %d (%d).", read ? "reading" :
89 "writing", wAddress, wRegOffsPCI); 94 "writing", wAddress, wRegOffsPCI);
90 return -EIO; 95 if (ret >= 0)
96 ret = -EIO;
91 } 97 }
92 return 0; 98
99 if (read && ret >= 0)
100 memcpy(val, fc_usb->data, sizeof(*val));
101 mutex_unlock(&fc_usb->data_mutex);
102
103 return ret;
93} 104}
94/* 105/*
95 * DKT 010817 - add support for V8 memory read/write and flash update 106 * DKT 010817 - add support for V8 memory read/write and flash update
@@ -100,9 +111,14 @@ static int flexcop_usb_v8_memory_req(struct flexcop_usb *fc_usb,
100{ 111{
101 u8 request_type = USB_TYPE_VENDOR; 112 u8 request_type = USB_TYPE_VENDOR;
102 u16 wIndex; 113 u16 wIndex;
103 int nWaitTime, pipe, len; 114 int nWaitTime, pipe, ret;
104 wIndex = page << 8; 115 wIndex = page << 8;
105 116
117 if (buflen > sizeof(fc_usb->data)) {
118 err("Buffer size bigger than max URB control message\n");
119 return -EIO;
120 }
121
106 switch (req) { 122 switch (req) {
107 case B2C2_USB_READ_V8_MEM: 123 case B2C2_USB_READ_V8_MEM:
108 nWaitTime = B2C2_WAIT_FOR_OPERATION_V8READ; 124 nWaitTime = B2C2_WAIT_FOR_OPERATION_V8READ;
@@ -127,17 +143,32 @@ static int flexcop_usb_v8_memory_req(struct flexcop_usb *fc_usb,
127 deb_v8("v8mem: %02x %02x %04x %04x, len: %d\n", request_type, req, 143 deb_v8("v8mem: %02x %02x %04x %04x, len: %d\n", request_type, req,
128 wAddress, wIndex, buflen); 144 wAddress, wIndex, buflen);
129 145
130 len = usb_control_msg(fc_usb->udev, pipe, 146 mutex_lock(&fc_usb->data_mutex);
147
148 if ((request_type & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT)
149 memcpy(fc_usb->data, pbBuffer, buflen);
150
151 ret = usb_control_msg(fc_usb->udev, pipe,
131 req, 152 req,
132 request_type, 153 request_type,
133 wAddress, 154 wAddress,
134 wIndex, 155 wIndex,
135 pbBuffer, 156 fc_usb->data,
136 buflen, 157 buflen,
137 nWaitTime * HZ); 158 nWaitTime * HZ);
159 if (ret != buflen)
160 ret = -EIO;
161
162 if (ret >= 0) {
163 ret = 0;
164 if ((request_type & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN)
165 memcpy(pbBuffer, fc_usb->data, buflen);
166 }
138 167
139 debug_dump(pbBuffer, len, deb_v8); 168 mutex_unlock(&fc_usb->data_mutex);
140 return len == buflen ? 0 : -EIO; 169
170 debug_dump(pbBuffer, ret, deb_v8);
171 return ret;
141} 172}
142 173
143#define bytes_left_to_read_on_page(paddr,buflen) \ 174#define bytes_left_to_read_on_page(paddr,buflen) \
@@ -196,29 +227,6 @@ static int flexcop_usb_get_mac_addr(struct flexcop_device *fc, int extended)
196 fc->dvb_adapter.proposed_mac, 6); 227 fc->dvb_adapter.proposed_mac, 6);
197} 228}
198 229
199#if 0
200static int flexcop_usb_utility_req(struct flexcop_usb *fc_usb, int set,
201 flexcop_usb_utility_function_t func, u8 extra, u16 wIndex,
202 u16 buflen, u8 *pvBuffer)
203{
204 u16 wValue;
205 u8 request_type = (set ? USB_DIR_OUT : USB_DIR_IN) | USB_TYPE_VENDOR;
206 int nWaitTime = 2,
207 pipe = set ? B2C2_USB_CTRL_PIPE_OUT : B2C2_USB_CTRL_PIPE_IN, len;
208 wValue = (func << 8) | extra;
209
210 len = usb_control_msg(fc_usb->udev,pipe,
211 B2C2_USB_UTILITY,
212 request_type,
213 wValue,
214 wIndex,
215 pvBuffer,
216 buflen,
217 nWaitTime * HZ);
218 return len == buflen ? 0 : -EIO;
219}
220#endif
221
222/* usb i2c stuff */ 230/* usb i2c stuff */
223static int flexcop_usb_i2c_req(struct flexcop_i2c_adapter *i2c, 231static int flexcop_usb_i2c_req(struct flexcop_i2c_adapter *i2c,
224 flexcop_usb_request_t req, flexcop_usb_i2c_function_t func, 232 flexcop_usb_request_t req, flexcop_usb_i2c_function_t func,
@@ -226,9 +234,14 @@ static int flexcop_usb_i2c_req(struct flexcop_i2c_adapter *i2c,
226{ 234{
227 struct flexcop_usb *fc_usb = i2c->fc->bus_specific; 235 struct flexcop_usb *fc_usb = i2c->fc->bus_specific;
228 u16 wValue, wIndex; 236 u16 wValue, wIndex;
229 int nWaitTime,pipe,len; 237 int nWaitTime, pipe, ret;
230 u8 request_type = USB_TYPE_VENDOR; 238 u8 request_type = USB_TYPE_VENDOR;
231 239
240 if (buflen > sizeof(fc_usb->data)) {
241 err("Buffer size bigger than max URB control message\n");
242 return -EIO;
243 }
244
232 switch (func) { 245 switch (func) {
233 case USB_FUNC_I2C_WRITE: 246 case USB_FUNC_I2C_WRITE:
234 case USB_FUNC_I2C_MULTIWRITE: 247 case USB_FUNC_I2C_MULTIWRITE:
@@ -257,15 +270,32 @@ static int flexcop_usb_i2c_req(struct flexcop_i2c_adapter *i2c,
257 wValue & 0xff, wValue >> 8, 270 wValue & 0xff, wValue >> 8,
258 wIndex & 0xff, wIndex >> 8); 271 wIndex & 0xff, wIndex >> 8);
259 272
260 len = usb_control_msg(fc_usb->udev,pipe, 273 mutex_lock(&fc_usb->data_mutex);
274
275 if ((request_type & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT)
276 memcpy(fc_usb->data, buf, buflen);
277
278 ret = usb_control_msg(fc_usb->udev, pipe,
261 req, 279 req,
262 request_type, 280 request_type,
263 wValue, 281 wValue,
264 wIndex, 282 wIndex,
265 buf, 283 fc_usb->data,
266 buflen, 284 buflen,
267 nWaitTime * HZ); 285 nWaitTime * HZ);
268 return len == buflen ? 0 : -EREMOTEIO; 286
287 if (ret != buflen)
288 ret = -EIO;
289
290 if (ret >= 0) {
291 ret = 0;
292 if ((request_type & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN)
293 memcpy(buf, fc_usb->data, buflen);
294 }
295
296 mutex_unlock(&fc_usb->data_mutex);
297
298 return 0;
269} 299}
270 300
271/* actual bus specific access functions, 301/* actual bus specific access functions,
@@ -516,6 +546,7 @@ static int flexcop_usb_probe(struct usb_interface *intf,
516 /* general flexcop init */ 546 /* general flexcop init */
517 fc_usb = fc->bus_specific; 547 fc_usb = fc->bus_specific;
518 fc_usb->fc_dev = fc; 548 fc_usb->fc_dev = fc;
549 mutex_init(&fc_usb->data_mutex);
519 550
520 fc->read_ibi_reg = flexcop_usb_read_ibi_reg; 551 fc->read_ibi_reg = flexcop_usb_read_ibi_reg;
521 fc->write_ibi_reg = flexcop_usb_write_ibi_reg; 552 fc->write_ibi_reg = flexcop_usb_write_ibi_reg;
diff --git a/drivers/media/usb/b2c2/flexcop-usb.h b/drivers/media/usb/b2c2/flexcop-usb.h
index 92529a9c4475..25ad43166e78 100644
--- a/drivers/media/usb/b2c2/flexcop-usb.h
+++ b/drivers/media/usb/b2c2/flexcop-usb.h
@@ -29,6 +29,10 @@ struct flexcop_usb {
29 29
30 u8 tmp_buffer[1023+190]; 30 u8 tmp_buffer[1023+190];
31 int tmp_buffer_length; 31 int tmp_buffer_length;
32
33 /* for URB control messages */
34 u8 data[80];
35 struct mutex data_mutex;
32}; 36};
33 37
34#if 0 38#if 0
diff --git a/drivers/media/usb/cpia2/cpia2_usb.c b/drivers/media/usb/cpia2/cpia2_usb.c
index 13620cdf0599..e9100a235831 100644
--- a/drivers/media/usb/cpia2/cpia2_usb.c
+++ b/drivers/media/usb/cpia2/cpia2_usb.c
@@ -545,18 +545,30 @@ static void free_sbufs(struct camera_data *cam)
545static int write_packet(struct usb_device *udev, 545static int write_packet(struct usb_device *udev,
546 u8 request, u8 * registers, u16 start, size_t size) 546 u8 request, u8 * registers, u16 start, size_t size)
547{ 547{
548 unsigned char *buf;
549 int ret;
550
548 if (!registers || size <= 0) 551 if (!registers || size <= 0)
549 return -EINVAL; 552 return -EINVAL;
550 553
551 return usb_control_msg(udev, 554 buf = kmalloc(size, GFP_KERNEL);
555 if (!buf)
556 return -ENOMEM;
557
558 memcpy(buf, registers, size);
559
560 ret = usb_control_msg(udev,
552 usb_sndctrlpipe(udev, 0), 561 usb_sndctrlpipe(udev, 0),
553 request, 562 request,
554 USB_TYPE_VENDOR | USB_RECIP_DEVICE, 563 USB_TYPE_VENDOR | USB_RECIP_DEVICE,
555 start, /* value */ 564 start, /* value */
556 0, /* index */ 565 0, /* index */
557 registers, /* buffer */ 566 buf, /* buffer */
558 size, 567 size,
559 HZ); 568 HZ);
569
570 kfree(buf);
571 return ret;
560} 572}
561 573
562/**************************************************************************** 574/****************************************************************************
@@ -567,18 +579,32 @@ static int write_packet(struct usb_device *udev,
567static int read_packet(struct usb_device *udev, 579static int read_packet(struct usb_device *udev,
568 u8 request, u8 * registers, u16 start, size_t size) 580 u8 request, u8 * registers, u16 start, size_t size)
569{ 581{
582 unsigned char *buf;
583 int ret;
584
570 if (!registers || size <= 0) 585 if (!registers || size <= 0)
571 return -EINVAL; 586 return -EINVAL;
572 587
573 return usb_control_msg(udev, 588 buf = kmalloc(size, GFP_KERNEL);
589 if (!buf)
590 return -ENOMEM;
591
592 ret = usb_control_msg(udev,
574 usb_rcvctrlpipe(udev, 0), 593 usb_rcvctrlpipe(udev, 0),
575 request, 594 request,
576 USB_DIR_IN|USB_TYPE_VENDOR|USB_RECIP_DEVICE, 595 USB_DIR_IN|USB_TYPE_VENDOR|USB_RECIP_DEVICE,
577 start, /* value */ 596 start, /* value */
578 0, /* index */ 597 0, /* index */
579 registers, /* buffer */ 598 buf, /* buffer */
580 size, 599 size,
581 HZ); 600 HZ);
601
602 if (ret >= 0)
603 memcpy(registers, buf, size);
604
605 kfree(buf);
606
607 return ret;
582} 608}
583 609
584/****************************************************************************** 610/******************************************************************************
diff --git a/drivers/media/usb/dvb-usb/Makefile b/drivers/media/usb/dvb-usb/Makefile
index 2a7b5a963acf..3b3f32b426d1 100644
--- a/drivers/media/usb/dvb-usb/Makefile
+++ b/drivers/media/usb/dvb-usb/Makefile
@@ -8,7 +8,7 @@ obj-$(CONFIG_DVB_USB_VP7045) += dvb-usb-vp7045.o
8dvb-usb-vp702x-objs := vp702x.o vp702x-fe.o 8dvb-usb-vp702x-objs := vp702x.o vp702x-fe.o
9obj-$(CONFIG_DVB_USB_VP702X) += dvb-usb-vp702x.o 9obj-$(CONFIG_DVB_USB_VP702X) += dvb-usb-vp702x.o
10 10
11dvb-usb-gp8psk-objs := gp8psk.o gp8psk-fe.o 11dvb-usb-gp8psk-objs := gp8psk.o
12obj-$(CONFIG_DVB_USB_GP8PSK) += dvb-usb-gp8psk.o 12obj-$(CONFIG_DVB_USB_GP8PSK) += dvb-usb-gp8psk.o
13 13
14dvb-usb-dtt200u-objs := dtt200u.o dtt200u-fe.o 14dvb-usb-dtt200u-objs := dtt200u.o dtt200u-fe.o
diff --git a/drivers/media/usb/dvb-usb/af9005.c b/drivers/media/usb/dvb-usb/af9005.c
index efa782ed6e2d..7853261906b1 100644
--- a/drivers/media/usb/dvb-usb/af9005.c
+++ b/drivers/media/usb/dvb-usb/af9005.c
@@ -52,17 +52,15 @@ u8 regmask[8] = { 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff };
52struct af9005_device_state { 52struct af9005_device_state {
53 u8 sequence; 53 u8 sequence;
54 int led_state; 54 int led_state;
55 unsigned char data[256];
55}; 56};
56 57
57static int af9005_generic_read_write(struct dvb_usb_device *d, u16 reg, 58static int af9005_generic_read_write(struct dvb_usb_device *d, u16 reg,
58 int readwrite, int type, u8 * values, int len) 59 int readwrite, int type, u8 * values, int len)
59{ 60{
60 struct af9005_device_state *st = d->priv; 61 struct af9005_device_state *st = d->priv;
61 u8 obuf[16] = { 0 }; 62 u8 command, seq;
62 u8 ibuf[17] = { 0 }; 63 int i, ret;
63 u8 command;
64 int i;
65 int ret;
66 64
67 if (len < 1) { 65 if (len < 1) {
68 err("generic read/write, less than 1 byte. Makes no sense."); 66 err("generic read/write, less than 1 byte. Makes no sense.");
@@ -73,16 +71,17 @@ static int af9005_generic_read_write(struct dvb_usb_device *d, u16 reg,
73 return -EINVAL; 71 return -EINVAL;
74 } 72 }
75 73
76 obuf[0] = 14; /* rest of buffer length low */ 74 mutex_lock(&d->data_mutex);
77 obuf[1] = 0; /* rest of buffer length high */ 75 st->data[0] = 14; /* rest of buffer length low */
76 st->data[1] = 0; /* rest of buffer length high */
78 77
79 obuf[2] = AF9005_REGISTER_RW; /* register operation */ 78 st->data[2] = AF9005_REGISTER_RW; /* register operation */
80 obuf[3] = 12; /* rest of buffer length */ 79 st->data[3] = 12; /* rest of buffer length */
81 80
82 obuf[4] = st->sequence++; /* sequence number */ 81 st->data[4] = seq = st->sequence++; /* sequence number */
83 82
84 obuf[5] = (u8) (reg >> 8); /* register address */ 83 st->data[5] = (u8) (reg >> 8); /* register address */
85 obuf[6] = (u8) (reg & 0xff); 84 st->data[6] = (u8) (reg & 0xff);
86 85
87 if (type == AF9005_OFDM_REG) { 86 if (type == AF9005_OFDM_REG) {
88 command = AF9005_CMD_OFDM_REG; 87 command = AF9005_CMD_OFDM_REG;
@@ -96,51 +95,52 @@ static int af9005_generic_read_write(struct dvb_usb_device *d, u16 reg,
96 command |= readwrite; 95 command |= readwrite;
97 if (readwrite == AF9005_CMD_WRITE) 96 if (readwrite == AF9005_CMD_WRITE)
98 for (i = 0; i < len; i++) 97 for (i = 0; i < len; i++)
99 obuf[8 + i] = values[i]; 98 st->data[8 + i] = values[i];
100 else if (type == AF9005_TUNER_REG) 99 else if (type == AF9005_TUNER_REG)
101 /* read command for tuner, the first byte contains the i2c address */ 100 /* read command for tuner, the first byte contains the i2c address */
102 obuf[8] = values[0]; 101 st->data[8] = values[0];
103 obuf[7] = command; 102 st->data[7] = command;
104 103
105 ret = dvb_usb_generic_rw(d, obuf, 16, ibuf, 17, 0); 104 ret = dvb_usb_generic_rw(d, st->data, 16, st->data, 17, 0);
106 if (ret) 105 if (ret)
107 return ret; 106 goto ret;
108 107
109 /* sanity check */ 108 /* sanity check */
110 if (ibuf[2] != AF9005_REGISTER_RW_ACK) { 109 if (st->data[2] != AF9005_REGISTER_RW_ACK) {
111 err("generic read/write, wrong reply code."); 110 err("generic read/write, wrong reply code.");
112 return -EIO; 111 ret = -EIO;
112 goto ret;
113 } 113 }
114 if (ibuf[3] != 0x0d) { 114 if (st->data[3] != 0x0d) {
115 err("generic read/write, wrong length in reply."); 115 err("generic read/write, wrong length in reply.");
116 return -EIO; 116 ret = -EIO;
117 goto ret;
117 } 118 }
118 if (ibuf[4] != obuf[4]) { 119 if (st->data[4] != seq) {
119 err("generic read/write, wrong sequence in reply."); 120 err("generic read/write, wrong sequence in reply.");
120 return -EIO; 121 ret = -EIO;
122 goto ret;
121 } 123 }
122 /* 124 /*
123 Windows driver doesn't check these fields, in fact sometimes 125 * In thesis, both input and output buffers should have
124 the register in the reply is different that what has been sent 126 * identical values for st->data[5] to st->data[8].
125 127 * However, windows driver doesn't check these fields, in fact
126 if (ibuf[5] != obuf[5] || ibuf[6] != obuf[6]) { 128 * sometimes the register in the reply is different that what
127 err("generic read/write, wrong register in reply."); 129 * has been sent
128 return -EIO;
129 }
130 if (ibuf[7] != command) {
131 err("generic read/write wrong command in reply.");
132 return -EIO;
133 }
134 */ 130 */
135 if (ibuf[16] != 0x01) { 131 if (st->data[16] != 0x01) {
136 err("generic read/write wrong status code in reply."); 132 err("generic read/write wrong status code in reply.");
137 return -EIO; 133 ret = -EIO;
134 goto ret;
138 } 135 }
136
139 if (readwrite == AF9005_CMD_READ) 137 if (readwrite == AF9005_CMD_READ)
140 for (i = 0; i < len; i++) 138 for (i = 0; i < len; i++)
141 values[i] = ibuf[8 + i]; 139 values[i] = st->data[8 + i];
142 140
143 return 0; 141ret:
142 mutex_unlock(&d->data_mutex);
143 return ret;
144 144
145} 145}
146 146
@@ -464,8 +464,7 @@ int af9005_send_command(struct dvb_usb_device *d, u8 command, u8 * wbuf,
464 struct af9005_device_state *st = d->priv; 464 struct af9005_device_state *st = d->priv;
465 465
466 int ret, i, packet_len; 466 int ret, i, packet_len;
467 u8 buf[64]; 467 u8 seq;
468 u8 ibuf[64];
469 468
470 if (wlen < 0) { 469 if (wlen < 0) {
471 err("send command, wlen less than 0 bytes. Makes no sense."); 470 err("send command, wlen less than 0 bytes. Makes no sense.");
@@ -480,94 +479,97 @@ int af9005_send_command(struct dvb_usb_device *d, u8 command, u8 * wbuf,
480 return -EINVAL; 479 return -EINVAL;
481 } 480 }
482 packet_len = wlen + 5; 481 packet_len = wlen + 5;
483 buf[0] = (u8) (packet_len & 0xff); 482
484 buf[1] = (u8) ((packet_len & 0xff00) >> 8); 483 mutex_lock(&d->data_mutex);
485 484
486 buf[2] = 0x26; /* packet type */ 485 st->data[0] = (u8) (packet_len & 0xff);
487 buf[3] = wlen + 3; 486 st->data[1] = (u8) ((packet_len & 0xff00) >> 8);
488 buf[4] = st->sequence++; 487
489 buf[5] = command; 488 st->data[2] = 0x26; /* packet type */
490 buf[6] = wlen; 489 st->data[3] = wlen + 3;
490 st->data[4] = seq = st->sequence++;
491 st->data[5] = command;
492 st->data[6] = wlen;
491 for (i = 0; i < wlen; i++) 493 for (i = 0; i < wlen; i++)
492 buf[7 + i] = wbuf[i]; 494 st->data[7 + i] = wbuf[i];
493 ret = dvb_usb_generic_rw(d, buf, wlen + 7, ibuf, rlen + 7, 0); 495 ret = dvb_usb_generic_rw(d, st->data, wlen + 7, st->data, rlen + 7, 0);
494 if (ret) 496 if (st->data[2] != 0x27) {
495 return ret;
496 if (ibuf[2] != 0x27) {
497 err("send command, wrong reply code."); 497 err("send command, wrong reply code.");
498 return -EIO; 498 ret = -EIO;
499 } 499 } else if (st->data[4] != seq) {
500 if (ibuf[4] != buf[4]) {
501 err("send command, wrong sequence in reply."); 500 err("send command, wrong sequence in reply.");
502 return -EIO; 501 ret = -EIO;
503 } 502 } else if (st->data[5] != 0x01) {
504 if (ibuf[5] != 0x01) {
505 err("send command, wrong status code in reply."); 503 err("send command, wrong status code in reply.");
506 return -EIO; 504 ret = -EIO;
507 } 505 } else if (st->data[6] != rlen) {
508 if (ibuf[6] != rlen) {
509 err("send command, invalid data length in reply."); 506 err("send command, invalid data length in reply.");
510 return -EIO; 507 ret = -EIO;
511 } 508 }
512 for (i = 0; i < rlen; i++) 509 if (!ret) {
513 rbuf[i] = ibuf[i + 7]; 510 for (i = 0; i < rlen; i++)
514 return 0; 511 rbuf[i] = st->data[i + 7];
512 }
513
514 mutex_unlock(&d->data_mutex);
515 return ret;
515} 516}
516 517
517int af9005_read_eeprom(struct dvb_usb_device *d, u8 address, u8 * values, 518int af9005_read_eeprom(struct dvb_usb_device *d, u8 address, u8 * values,
518 int len) 519 int len)
519{ 520{
520 struct af9005_device_state *st = d->priv; 521 struct af9005_device_state *st = d->priv;
521 u8 obuf[16], ibuf[14]; 522 u8 seq;
522 int ret, i; 523 int ret, i;
523 524
524 memset(obuf, 0, sizeof(obuf)); 525 mutex_lock(&d->data_mutex);
525 memset(ibuf, 0, sizeof(ibuf));
526 526
527 obuf[0] = 14; /* length of rest of packet low */ 527 memset(st->data, 0, sizeof(st->data));
528 obuf[1] = 0; /* length of rest of packer high */
529 528
530 obuf[2] = 0x2a; /* read/write eeprom */ 529 st->data[0] = 14; /* length of rest of packet low */
530 st->data[1] = 0; /* length of rest of packer high */
531 531
532 obuf[3] = 12; /* size */ 532 st->data[2] = 0x2a; /* read/write eeprom */
533 533
534 obuf[4] = st->sequence++; 534 st->data[3] = 12; /* size */
535 535
536 obuf[5] = 0; /* read */ 536 st->data[4] = seq = st->sequence++;
537 537
538 obuf[6] = len; 538 st->data[5] = 0; /* read */
539 obuf[7] = address; 539
540 ret = dvb_usb_generic_rw(d, obuf, 16, ibuf, 14, 0); 540 st->data[6] = len;
541 if (ret) 541 st->data[7] = address;
542 return ret; 542 ret = dvb_usb_generic_rw(d, st->data, 16, st->data, 14, 0);
543 if (ibuf[2] != 0x2b) { 543 if (st->data[2] != 0x2b) {
544 err("Read eeprom, invalid reply code"); 544 err("Read eeprom, invalid reply code");
545 return -EIO; 545 ret = -EIO;
546 } 546 } else if (st->data[3] != 10) {
547 if (ibuf[3] != 10) {
548 err("Read eeprom, invalid reply length"); 547 err("Read eeprom, invalid reply length");
549 return -EIO; 548 ret = -EIO;
550 } 549 } else if (st->data[4] != seq) {
551 if (ibuf[4] != obuf[4]) {
552 err("Read eeprom, wrong sequence in reply "); 550 err("Read eeprom, wrong sequence in reply ");
553 return -EIO; 551 ret = -EIO;
554 } 552 } else if (st->data[5] != 1) {
555 if (ibuf[5] != 1) {
556 err("Read eeprom, wrong status in reply "); 553 err("Read eeprom, wrong status in reply ");
557 return -EIO; 554 ret = -EIO;
558 } 555 }
559 for (i = 0; i < len; i++) { 556
560 values[i] = ibuf[6 + i]; 557 if (!ret) {
558 for (i = 0; i < len; i++)
559 values[i] = st->data[6 + i];
561 } 560 }
562 return 0; 561 mutex_unlock(&d->data_mutex);
562
563 return ret;
563} 564}
564 565
565static int af9005_boot_packet(struct usb_device *udev, int type, u8 * reply) 566static int af9005_boot_packet(struct usb_device *udev, int type, u8 *reply,
567 u8 *buf, int size)
566{ 568{
567 u8 buf[FW_BULKOUT_SIZE + 2];
568 u16 checksum; 569 u16 checksum;
569 int act_len, i, ret; 570 int act_len, i, ret;
570 memset(buf, 0, sizeof(buf)); 571
572 memset(buf, 0, size);
571 buf[0] = (u8) (FW_BULKOUT_SIZE & 0xff); 573 buf[0] = (u8) (FW_BULKOUT_SIZE & 0xff);
572 buf[1] = (u8) ((FW_BULKOUT_SIZE >> 8) & 0xff); 574 buf[1] = (u8) ((FW_BULKOUT_SIZE >> 8) & 0xff);
573 switch (type) { 575 switch (type) {
@@ -720,15 +722,21 @@ static int af9005_download_firmware(struct usb_device *udev, const struct firmwa
720{ 722{
721 int i, packets, ret, act_len; 723 int i, packets, ret, act_len;
722 724
723 u8 buf[FW_BULKOUT_SIZE + 2]; 725 u8 *buf;
724 u8 reply; 726 u8 reply;
725 727
726 ret = af9005_boot_packet(udev, FW_CONFIG, &reply); 728 buf = kmalloc(FW_BULKOUT_SIZE + 2, GFP_KERNEL);
729 if (!buf)
730 return -ENOMEM;
731
732 ret = af9005_boot_packet(udev, FW_CONFIG, &reply, buf,
733 FW_BULKOUT_SIZE + 2);
727 if (ret) 734 if (ret)
728 return ret; 735 goto err;
729 if (reply != 0x01) { 736 if (reply != 0x01) {
730 err("before downloading firmware, FW_CONFIG expected 0x01, received 0x%x", reply); 737 err("before downloading firmware, FW_CONFIG expected 0x01, received 0x%x", reply);
731 return -EIO; 738 ret = -EIO;
739 goto err;
732 } 740 }
733 packets = fw->size / FW_BULKOUT_SIZE; 741 packets = fw->size / FW_BULKOUT_SIZE;
734 buf[0] = (u8) (FW_BULKOUT_SIZE & 0xff); 742 buf[0] = (u8) (FW_BULKOUT_SIZE & 0xff);
@@ -743,28 +751,35 @@ static int af9005_download_firmware(struct usb_device *udev, const struct firmwa
743 buf, FW_BULKOUT_SIZE + 2, &act_len, 1000); 751 buf, FW_BULKOUT_SIZE + 2, &act_len, 1000);
744 if (ret) { 752 if (ret) {
745 err("firmware download failed at packet %d with code %d", i, ret); 753 err("firmware download failed at packet %d with code %d", i, ret);
746 return ret; 754 goto err;
747 } 755 }
748 } 756 }
749 ret = af9005_boot_packet(udev, FW_CONFIRM, &reply); 757 ret = af9005_boot_packet(udev, FW_CONFIRM, &reply,
758 buf, FW_BULKOUT_SIZE + 2);
750 if (ret) 759 if (ret)
751 return ret; 760 goto err;
752 if (reply != (u8) (packets & 0xff)) { 761 if (reply != (u8) (packets & 0xff)) {
753 err("after downloading firmware, FW_CONFIRM expected 0x%x, received 0x%x", packets & 0xff, reply); 762 err("after downloading firmware, FW_CONFIRM expected 0x%x, received 0x%x", packets & 0xff, reply);
754 return -EIO; 763 ret = -EIO;
764 goto err;
755 } 765 }
756 ret = af9005_boot_packet(udev, FW_BOOT, &reply); 766 ret = af9005_boot_packet(udev, FW_BOOT, &reply, buf,
767 FW_BULKOUT_SIZE + 2);
757 if (ret) 768 if (ret)
758 return ret; 769 goto err;
759 ret = af9005_boot_packet(udev, FW_CONFIG, &reply); 770 ret = af9005_boot_packet(udev, FW_CONFIG, &reply, buf,
771 FW_BULKOUT_SIZE + 2);
760 if (ret) 772 if (ret)
761 return ret; 773 goto err;
762 if (reply != 0x02) { 774 if (reply != 0x02) {
763 err("after downloading firmware, FW_CONFIG expected 0x02, received 0x%x", reply); 775 err("after downloading firmware, FW_CONFIG expected 0x02, received 0x%x", reply);
764 return -EIO; 776 ret = -EIO;
777 goto err;
765 } 778 }
766 779
767 return 0; 780err:
781 kfree(buf);
782 return ret;
768 783
769} 784}
770 785
@@ -823,53 +838,59 @@ static int af9005_rc_query(struct dvb_usb_device *d, u32 * event, int *state)
823{ 838{
824 struct af9005_device_state *st = d->priv; 839 struct af9005_device_state *st = d->priv;
825 int ret, len; 840 int ret, len;
826 841 u8 seq;
827 u8 obuf[5];
828 u8 ibuf[256];
829 842
830 *state = REMOTE_NO_KEY_PRESSED; 843 *state = REMOTE_NO_KEY_PRESSED;
831 if (rc_decode == NULL) { 844 if (rc_decode == NULL) {
832 /* it shouldn't never come here */ 845 /* it shouldn't never come here */
833 return 0; 846 return 0;
834 } 847 }
848
849 mutex_lock(&d->data_mutex);
850
835 /* deb_info("rc_query\n"); */ 851 /* deb_info("rc_query\n"); */
836 obuf[0] = 3; /* rest of packet length low */ 852 st->data[0] = 3; /* rest of packet length low */
837 obuf[1] = 0; /* rest of packet lentgh high */ 853 st->data[1] = 0; /* rest of packet lentgh high */
838 obuf[2] = 0x40; /* read remote */ 854 st->data[2] = 0x40; /* read remote */
839 obuf[3] = 1; /* rest of packet length */ 855 st->data[3] = 1; /* rest of packet length */
840 obuf[4] = st->sequence++; /* sequence number */ 856 st->data[4] = seq = st->sequence++; /* sequence number */
841 ret = dvb_usb_generic_rw(d, obuf, 5, ibuf, 256, 0); 857 ret = dvb_usb_generic_rw(d, st->data, 5, st->data, 256, 0);
842 if (ret) { 858 if (ret) {
843 err("rc query failed"); 859 err("rc query failed");
844 return ret; 860 goto ret;
845 } 861 }
846 if (ibuf[2] != 0x41) { 862 if (st->data[2] != 0x41) {
847 err("rc query bad header."); 863 err("rc query bad header.");
848 return -EIO; 864 ret = -EIO;
849 } 865 goto ret;
850 if (ibuf[4] != obuf[4]) { 866 } else if (st->data[4] != seq) {
851 err("rc query bad sequence."); 867 err("rc query bad sequence.");
852 return -EIO; 868 ret = -EIO;
869 goto ret;
853 } 870 }
854 len = ibuf[5]; 871 len = st->data[5];
855 if (len > 246) { 872 if (len > 246) {
856 err("rc query invalid length"); 873 err("rc query invalid length");
857 return -EIO; 874 ret = -EIO;
875 goto ret;
858 } 876 }
859 if (len > 0) { 877 if (len > 0) {
860 deb_rc("rc data (%d) ", len); 878 deb_rc("rc data (%d) ", len);
861 debug_dump((ibuf + 6), len, deb_rc); 879 debug_dump((st->data + 6), len, deb_rc);
862 ret = rc_decode(d, &ibuf[6], len, event, state); 880 ret = rc_decode(d, &st->data[6], len, event, state);
863 if (ret) { 881 if (ret) {
864 err("rc_decode failed"); 882 err("rc_decode failed");
865 return ret; 883 goto ret;
866 } else { 884 } else {
867 deb_rc("rc_decode state %x event %x\n", *state, *event); 885 deb_rc("rc_decode state %x event %x\n", *state, *event);
868 if (*state == REMOTE_KEY_REPEAT) 886 if (*state == REMOTE_KEY_REPEAT)
869 *event = d->last_event; 887 *event = d->last_event;
870 } 888 }
871 } 889 }
872 return 0; 890
891ret:
892 mutex_unlock(&d->data_mutex);
893 return ret;
873} 894}
874 895
875static int af9005_power_ctrl(struct dvb_usb_device *d, int onoff) 896static int af9005_power_ctrl(struct dvb_usb_device *d, int onoff)
@@ -953,10 +974,16 @@ static int af9005_identify_state(struct usb_device *udev,
953 int *cold) 974 int *cold)
954{ 975{
955 int ret; 976 int ret;
956 u8 reply; 977 u8 reply, *buf;
957 ret = af9005_boot_packet(udev, FW_CONFIG, &reply); 978
979 buf = kmalloc(FW_BULKOUT_SIZE + 2, GFP_KERNEL);
980 if (!buf)
981 return -ENOMEM;
982
983 ret = af9005_boot_packet(udev, FW_CONFIG, &reply,
984 buf, FW_BULKOUT_SIZE + 2);
958 if (ret) 985 if (ret)
959 return ret; 986 goto err;
960 deb_info("result of FW_CONFIG in identify state %d\n", reply); 987 deb_info("result of FW_CONFIG in identify state %d\n", reply);
961 if (reply == 0x01) 988 if (reply == 0x01)
962 *cold = 1; 989 *cold = 1;
@@ -965,7 +992,10 @@ static int af9005_identify_state(struct usb_device *udev,
965 else 992 else
966 return -EIO; 993 return -EIO;
967 deb_info("Identify state cold = %d\n", *cold); 994 deb_info("Identify state cold = %d\n", *cold);
968 return 0; 995
996err:
997 kfree(buf);
998 return ret;
969} 999}
970 1000
971static struct dvb_usb_device_properties af9005_properties; 1001static struct dvb_usb_device_properties af9005_properties;
@@ -974,7 +1004,7 @@ static int af9005_usb_probe(struct usb_interface *intf,
974 const struct usb_device_id *id) 1004 const struct usb_device_id *id)
975{ 1005{
976 return dvb_usb_device_init(intf, &af9005_properties, 1006 return dvb_usb_device_init(intf, &af9005_properties,
977 THIS_MODULE, NULL, adapter_nr); 1007 THIS_MODULE, NULL, adapter_nr);
978} 1008}
979 1009
980enum af9005_usb_table_entry { 1010enum af9005_usb_table_entry {
diff --git a/drivers/media/usb/dvb-usb/cinergyT2-core.c b/drivers/media/usb/dvb-usb/cinergyT2-core.c
index 9fd1527494eb..290275bc7fde 100644
--- a/drivers/media/usb/dvb-usb/cinergyT2-core.c
+++ b/drivers/media/usb/dvb-usb/cinergyT2-core.c
@@ -41,6 +41,7 @@ DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
41 41
42struct cinergyt2_state { 42struct cinergyt2_state {
43 u8 rc_counter; 43 u8 rc_counter;
44 unsigned char data[64];
44}; 45};
45 46
46/* We are missing a release hook with usb_device data */ 47/* We are missing a release hook with usb_device data */
@@ -50,38 +51,57 @@ static struct dvb_usb_device_properties cinergyt2_properties;
50 51
51static int cinergyt2_streaming_ctrl(struct dvb_usb_adapter *adap, int enable) 52static int cinergyt2_streaming_ctrl(struct dvb_usb_adapter *adap, int enable)
52{ 53{
53 char buf[] = { CINERGYT2_EP1_CONTROL_STREAM_TRANSFER, enable ? 1 : 0 }; 54 struct dvb_usb_device *d = adap->dev;
54 char result[64]; 55 struct cinergyt2_state *st = d->priv;
55 return dvb_usb_generic_rw(adap->dev, buf, sizeof(buf), result, 56 int ret;
56 sizeof(result), 0); 57
58 mutex_lock(&d->data_mutex);
59 st->data[0] = CINERGYT2_EP1_CONTROL_STREAM_TRANSFER;
60 st->data[1] = enable ? 1 : 0;
61
62 ret = dvb_usb_generic_rw(d, st->data, 2, st->data, 64, 0);
63 mutex_unlock(&d->data_mutex);
64
65 return ret;
57} 66}
58 67
59static int cinergyt2_power_ctrl(struct dvb_usb_device *d, int enable) 68static int cinergyt2_power_ctrl(struct dvb_usb_device *d, int enable)
60{ 69{
61 char buf[] = { CINERGYT2_EP1_SLEEP_MODE, enable ? 0 : 1 }; 70 struct cinergyt2_state *st = d->priv;
62 char state[3]; 71 int ret;
63 return dvb_usb_generic_rw(d, buf, sizeof(buf), state, sizeof(state), 0); 72
73 mutex_lock(&d->data_mutex);
74 st->data[0] = CINERGYT2_EP1_SLEEP_MODE;
75 st->data[1] = enable ? 0 : 1;
76
77 ret = dvb_usb_generic_rw(d, st->data, 2, st->data, 3, 0);
78 mutex_unlock(&d->data_mutex);
79
80 return ret;
64} 81}
65 82
66static int cinergyt2_frontend_attach(struct dvb_usb_adapter *adap) 83static int cinergyt2_frontend_attach(struct dvb_usb_adapter *adap)
67{ 84{
68 char query[] = { CINERGYT2_EP1_GET_FIRMWARE_VERSION }; 85 struct dvb_usb_device *d = adap->dev;
69 char state[3]; 86 struct cinergyt2_state *st = d->priv;
70 int ret; 87 int ret;
71 88
72 adap->fe_adap[0].fe = cinergyt2_fe_attach(adap->dev); 89 adap->fe_adap[0].fe = cinergyt2_fe_attach(adap->dev);
73 90
74 ret = dvb_usb_generic_rw(adap->dev, query, sizeof(query), state, 91 mutex_lock(&d->data_mutex);
75 sizeof(state), 0); 92 st->data[0] = CINERGYT2_EP1_GET_FIRMWARE_VERSION;
93
94 ret = dvb_usb_generic_rw(d, st->data, 1, st->data, 3, 0);
76 if (ret < 0) { 95 if (ret < 0) {
77 deb_rc("cinergyt2_power_ctrl() Failed to retrieve sleep " 96 deb_rc("cinergyt2_power_ctrl() Failed to retrieve sleep "
78 "state info\n"); 97 "state info\n");
79 } 98 }
99 mutex_unlock(&d->data_mutex);
80 100
81 /* Copy this pointer as we are gonna need it in the release phase */ 101 /* Copy this pointer as we are gonna need it in the release phase */
82 cinergyt2_usb_device = adap->dev; 102 cinergyt2_usb_device = adap->dev;
83 103
84 return 0; 104 return ret;
85} 105}
86 106
87static struct rc_map_table rc_map_cinergyt2_table[] = { 107static struct rc_map_table rc_map_cinergyt2_table[] = {
@@ -141,13 +161,18 @@ static int repeatable_keys[] = {
141static int cinergyt2_rc_query(struct dvb_usb_device *d, u32 *event, int *state) 161static int cinergyt2_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
142{ 162{
143 struct cinergyt2_state *st = d->priv; 163 struct cinergyt2_state *st = d->priv;
144 u8 key[5] = {0, 0, 0, 0, 0}, cmd = CINERGYT2_EP1_GET_RC_EVENTS; 164 int i, ret;
145 int i;
146 165
147 *state = REMOTE_NO_KEY_PRESSED; 166 *state = REMOTE_NO_KEY_PRESSED;
148 167
149 dvb_usb_generic_rw(d, &cmd, 1, key, sizeof(key), 0); 168 mutex_lock(&d->data_mutex);
150 if (key[4] == 0xff) { 169 st->data[0] = CINERGYT2_EP1_GET_RC_EVENTS;
170
171 ret = dvb_usb_generic_rw(d, st->data, 1, st->data, 5, 0);
172 if (ret < 0)
173 goto ret;
174
175 if (st->data[4] == 0xff) {
151 /* key repeat */ 176 /* key repeat */
152 st->rc_counter++; 177 st->rc_counter++;
153 if (st->rc_counter > RC_REPEAT_DELAY) { 178 if (st->rc_counter > RC_REPEAT_DELAY) {
@@ -157,34 +182,36 @@ static int cinergyt2_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
157 *event = d->last_event; 182 *event = d->last_event;
158 deb_rc("repeat key, event %x\n", 183 deb_rc("repeat key, event %x\n",
159 *event); 184 *event);
160 return 0; 185 goto ret;
161 } 186 }
162 } 187 }
163 deb_rc("repeated key (non repeatable)\n"); 188 deb_rc("repeated key (non repeatable)\n");
164 } 189 }
165 return 0; 190 goto ret;
166 } 191 }
167 192
168 /* hack to pass checksum on the custom field */ 193 /* hack to pass checksum on the custom field */
169 key[2] = ~key[1]; 194 st->data[2] = ~st->data[1];
170 dvb_usb_nec_rc_key_to_event(d, key, event, state); 195 dvb_usb_nec_rc_key_to_event(d, st->data, event, state);
171 if (key[0] != 0) { 196 if (st->data[0] != 0) {
172 if (*event != d->last_event) 197 if (*event != d->last_event)
173 st->rc_counter = 0; 198 st->rc_counter = 0;
174 199
175 deb_rc("key: %*ph\n", 5, key); 200 deb_rc("key: %*ph\n", 5, st->data);
176 } 201 }
177 return 0; 202
203ret:
204 mutex_unlock(&d->data_mutex);
205 return ret;
178} 206}
179 207
180static int cinergyt2_usb_probe(struct usb_interface *intf, 208static int cinergyt2_usb_probe(struct usb_interface *intf,
181 const struct usb_device_id *id) 209 const struct usb_device_id *id)
182{ 210{
183 return dvb_usb_device_init(intf, &cinergyt2_properties, 211 return dvb_usb_device_init(intf, &cinergyt2_properties,
184 THIS_MODULE, NULL, adapter_nr); 212 THIS_MODULE, NULL, adapter_nr);
185} 213}
186 214
187
188static struct usb_device_id cinergyt2_usb_table[] = { 215static struct usb_device_id cinergyt2_usb_table[] = {
189 { USB_DEVICE(USB_VID_TERRATEC, 0x0038) }, 216 { USB_DEVICE(USB_VID_TERRATEC, 0x0038) },
190 { 0 } 217 { 0 }
diff --git a/drivers/media/usb/dvb-usb/cinergyT2-fe.c b/drivers/media/usb/dvb-usb/cinergyT2-fe.c
index b3ec743a7a2e..2d29b4174dba 100644
--- a/drivers/media/usb/dvb-usb/cinergyT2-fe.c
+++ b/drivers/media/usb/dvb-usb/cinergyT2-fe.c
@@ -139,32 +139,42 @@ static uint16_t compute_tps(struct dtv_frontend_properties *op)
139struct cinergyt2_fe_state { 139struct cinergyt2_fe_state {
140 struct dvb_frontend fe; 140 struct dvb_frontend fe;
141 struct dvb_usb_device *d; 141 struct dvb_usb_device *d;
142
143 unsigned char data[64];
144 struct mutex data_mutex;
145
146 struct dvbt_get_status_msg status;
142}; 147};
143 148
144static int cinergyt2_fe_read_status(struct dvb_frontend *fe, 149static int cinergyt2_fe_read_status(struct dvb_frontend *fe,
145 enum fe_status *status) 150 enum fe_status *status)
146{ 151{
147 struct cinergyt2_fe_state *state = fe->demodulator_priv; 152 struct cinergyt2_fe_state *state = fe->demodulator_priv;
148 struct dvbt_get_status_msg result;
149 u8 cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
150 int ret; 153 int ret;
151 154
152 ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (u8 *)&result, 155 mutex_lock(&state->data_mutex);
153 sizeof(result), 0); 156 state->data[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
157
158 ret = dvb_usb_generic_rw(state->d, state->data, 1,
159 state->data, sizeof(state->status), 0);
160 if (!ret)
161 memcpy(&state->status, state->data, sizeof(state->status));
162 mutex_unlock(&state->data_mutex);
163
154 if (ret < 0) 164 if (ret < 0)
155 return ret; 165 return ret;
156 166
157 *status = 0; 167 *status = 0;
158 168
159 if (0xffff - le16_to_cpu(result.gain) > 30) 169 if (0xffff - le16_to_cpu(state->status.gain) > 30)
160 *status |= FE_HAS_SIGNAL; 170 *status |= FE_HAS_SIGNAL;
161 if (result.lock_bits & (1 << 6)) 171 if (state->status.lock_bits & (1 << 6))
162 *status |= FE_HAS_LOCK; 172 *status |= FE_HAS_LOCK;
163 if (result.lock_bits & (1 << 5)) 173 if (state->status.lock_bits & (1 << 5))
164 *status |= FE_HAS_SYNC; 174 *status |= FE_HAS_SYNC;
165 if (result.lock_bits & (1 << 4)) 175 if (state->status.lock_bits & (1 << 4))
166 *status |= FE_HAS_CARRIER; 176 *status |= FE_HAS_CARRIER;
167 if (result.lock_bits & (1 << 1)) 177 if (state->status.lock_bits & (1 << 1))
168 *status |= FE_HAS_VITERBI; 178 *status |= FE_HAS_VITERBI;
169 179
170 if ((*status & (FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_SYNC)) != 180 if ((*status & (FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_SYNC)) !=
@@ -177,34 +187,16 @@ static int cinergyt2_fe_read_status(struct dvb_frontend *fe,
177static int cinergyt2_fe_read_ber(struct dvb_frontend *fe, u32 *ber) 187static int cinergyt2_fe_read_ber(struct dvb_frontend *fe, u32 *ber)
178{ 188{
179 struct cinergyt2_fe_state *state = fe->demodulator_priv; 189 struct cinergyt2_fe_state *state = fe->demodulator_priv;
180 struct dvbt_get_status_msg status;
181 char cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
182 int ret;
183
184 ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (char *)&status,
185 sizeof(status), 0);
186 if (ret < 0)
187 return ret;
188 190
189 *ber = le32_to_cpu(status.viterbi_error_rate); 191 *ber = le32_to_cpu(state->status.viterbi_error_rate);
190 return 0; 192 return 0;
191} 193}
192 194
193static int cinergyt2_fe_read_unc_blocks(struct dvb_frontend *fe, u32 *unc) 195static int cinergyt2_fe_read_unc_blocks(struct dvb_frontend *fe, u32 *unc)
194{ 196{
195 struct cinergyt2_fe_state *state = fe->demodulator_priv; 197 struct cinergyt2_fe_state *state = fe->demodulator_priv;
196 struct dvbt_get_status_msg status;
197 u8 cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
198 int ret;
199 198
200 ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (u8 *)&status, 199 *unc = le32_to_cpu(state->status.uncorrected_block_count);
201 sizeof(status), 0);
202 if (ret < 0) {
203 err("cinergyt2_fe_read_unc_blocks() Failed! (Error=%d)\n",
204 ret);
205 return ret;
206 }
207 *unc = le32_to_cpu(status.uncorrected_block_count);
208 return 0; 200 return 0;
209} 201}
210 202
@@ -212,35 +204,16 @@ static int cinergyt2_fe_read_signal_strength(struct dvb_frontend *fe,
212 u16 *strength) 204 u16 *strength)
213{ 205{
214 struct cinergyt2_fe_state *state = fe->demodulator_priv; 206 struct cinergyt2_fe_state *state = fe->demodulator_priv;
215 struct dvbt_get_status_msg status;
216 char cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
217 int ret;
218 207
219 ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (char *)&status, 208 *strength = (0xffff - le16_to_cpu(state->status.gain));
220 sizeof(status), 0);
221 if (ret < 0) {
222 err("cinergyt2_fe_read_signal_strength() Failed!"
223 " (Error=%d)\n", ret);
224 return ret;
225 }
226 *strength = (0xffff - le16_to_cpu(status.gain));
227 return 0; 209 return 0;
228} 210}
229 211
230static int cinergyt2_fe_read_snr(struct dvb_frontend *fe, u16 *snr) 212static int cinergyt2_fe_read_snr(struct dvb_frontend *fe, u16 *snr)
231{ 213{
232 struct cinergyt2_fe_state *state = fe->demodulator_priv; 214 struct cinergyt2_fe_state *state = fe->demodulator_priv;
233 struct dvbt_get_status_msg status;
234 char cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
235 int ret;
236 215
237 ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (char *)&status, 216 *snr = (state->status.snr << 8) | state->status.snr;
238 sizeof(status), 0);
239 if (ret < 0) {
240 err("cinergyt2_fe_read_snr() Failed! (Error=%d)\n", ret);
241 return ret;
242 }
243 *snr = (status.snr << 8) | status.snr;
244 return 0; 217 return 0;
245} 218}
246 219
@@ -266,34 +239,36 @@ static int cinergyt2_fe_set_frontend(struct dvb_frontend *fe)
266{ 239{
267 struct dtv_frontend_properties *fep = &fe->dtv_property_cache; 240 struct dtv_frontend_properties *fep = &fe->dtv_property_cache;
268 struct cinergyt2_fe_state *state = fe->demodulator_priv; 241 struct cinergyt2_fe_state *state = fe->demodulator_priv;
269 struct dvbt_set_parameters_msg param; 242 struct dvbt_set_parameters_msg *param;
270 char result[2];
271 int err; 243 int err;
272 244
273 param.cmd = CINERGYT2_EP1_SET_TUNER_PARAMETERS; 245 mutex_lock(&state->data_mutex);
274 param.tps = cpu_to_le16(compute_tps(fep)); 246
275 param.freq = cpu_to_le32(fep->frequency / 1000); 247 param = (void *)state->data;
276 param.flags = 0; 248 param->cmd = CINERGYT2_EP1_SET_TUNER_PARAMETERS;
249 param->tps = cpu_to_le16(compute_tps(fep));
250 param->freq = cpu_to_le32(fep->frequency / 1000);
251 param->flags = 0;
277 252
278 switch (fep->bandwidth_hz) { 253 switch (fep->bandwidth_hz) {
279 default: 254 default:
280 case 8000000: 255 case 8000000:
281 param.bandwidth = 8; 256 param->bandwidth = 8;
282 break; 257 break;
283 case 7000000: 258 case 7000000:
284 param.bandwidth = 7; 259 param->bandwidth = 7;
285 break; 260 break;
286 case 6000000: 261 case 6000000:
287 param.bandwidth = 6; 262 param->bandwidth = 6;
288 break; 263 break;
289 } 264 }
290 265
291 err = dvb_usb_generic_rw(state->d, 266 err = dvb_usb_generic_rw(state->d, state->data, sizeof(*param),
292 (char *)&param, sizeof(param), 267 state->data, 2, 0);
293 result, sizeof(result), 0);
294 if (err < 0) 268 if (err < 0)
295 err("cinergyt2_fe_set_frontend() Failed! err=%d\n", err); 269 err("cinergyt2_fe_set_frontend() Failed! err=%d\n", err);
296 270
271 mutex_unlock(&state->data_mutex);
297 return (err < 0) ? err : 0; 272 return (err < 0) ? err : 0;
298} 273}
299 274
@@ -315,6 +290,7 @@ struct dvb_frontend *cinergyt2_fe_attach(struct dvb_usb_device *d)
315 s->d = d; 290 s->d = d;
316 memcpy(&s->fe.ops, &cinergyt2_fe_ops, sizeof(struct dvb_frontend_ops)); 291 memcpy(&s->fe.ops, &cinergyt2_fe_ops, sizeof(struct dvb_frontend_ops));
317 s->fe.demodulator_priv = s; 292 s->fe.demodulator_priv = s;
293 mutex_init(&s->data_mutex);
318 return &s->fe; 294 return &s->fe;
319} 295}
320 296
diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
index 907ac01ae297..243403081fa5 100644
--- a/drivers/media/usb/dvb-usb/cxusb.c
+++ b/drivers/media/usb/dvb-usb/cxusb.c
@@ -45,9 +45,6 @@
45#include "si2168.h" 45#include "si2168.h"
46#include "si2157.h" 46#include "si2157.h"
47 47
48/* Max transfer size done by I2C transfer functions */
49#define MAX_XFER_SIZE 80
50
51/* debug */ 48/* debug */
52static int dvb_usb_cxusb_debug; 49static int dvb_usb_cxusb_debug;
53module_param_named(debug, dvb_usb_cxusb_debug, int, 0644); 50module_param_named(debug, dvb_usb_cxusb_debug, int, 0644);
@@ -61,23 +58,27 @@ DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
61static int cxusb_ctrl_msg(struct dvb_usb_device *d, 58static int cxusb_ctrl_msg(struct dvb_usb_device *d,
62 u8 cmd, u8 *wbuf, int wlen, u8 *rbuf, int rlen) 59 u8 cmd, u8 *wbuf, int wlen, u8 *rbuf, int rlen)
63{ 60{
64 int wo = (rbuf == NULL || rlen == 0); /* write-only */ 61 struct cxusb_state *st = d->priv;
65 u8 sndbuf[MAX_XFER_SIZE]; 62 int ret, wo;
66 63
67 if (1 + wlen > sizeof(sndbuf)) { 64 if (1 + wlen > MAX_XFER_SIZE) {
68 warn("i2c wr: len=%d is too big!\n", 65 warn("i2c wr: len=%d is too big!\n", wlen);
69 wlen);
70 return -EOPNOTSUPP; 66 return -EOPNOTSUPP;
71 } 67 }
72 68
73 memset(sndbuf, 0, 1+wlen); 69 wo = (rbuf == NULL || rlen == 0); /* write-only */
74 70
75 sndbuf[0] = cmd; 71 mutex_lock(&d->data_mutex);
76 memcpy(&sndbuf[1], wbuf, wlen); 72 st->data[0] = cmd;
73 memcpy(&st->data[1], wbuf, wlen);
77 if (wo) 74 if (wo)
78 return dvb_usb_generic_write(d, sndbuf, 1+wlen); 75 ret = dvb_usb_generic_write(d, st->data, 1 + wlen);
79 else 76 else
80 return dvb_usb_generic_rw(d, sndbuf, 1+wlen, rbuf, rlen, 0); 77 ret = dvb_usb_generic_rw(d, st->data, 1 + wlen,
78 rbuf, rlen, 0);
79
80 mutex_unlock(&d->data_mutex);
81 return ret;
81} 82}
82 83
83/* GPIO */ 84/* GPIO */
diff --git a/drivers/media/usb/dvb-usb/cxusb.h b/drivers/media/usb/dvb-usb/cxusb.h
index 527ff7905e15..18acda19527a 100644
--- a/drivers/media/usb/dvb-usb/cxusb.h
+++ b/drivers/media/usb/dvb-usb/cxusb.h
@@ -28,10 +28,15 @@
28#define CMD_ANALOG 0x50 28#define CMD_ANALOG 0x50
29#define CMD_DIGITAL 0x51 29#define CMD_DIGITAL 0x51
30 30
31/* Max transfer size done by I2C transfer functions */
32#define MAX_XFER_SIZE 80
33
31struct cxusb_state { 34struct cxusb_state {
32 u8 gpio_write_state[3]; 35 u8 gpio_write_state[3];
33 struct i2c_client *i2c_client_demod; 36 struct i2c_client *i2c_client_demod;
34 struct i2c_client *i2c_client_tuner; 37 struct i2c_client *i2c_client_tuner;
38
39 unsigned char data[MAX_XFER_SIZE];
35}; 40};
36 41
37#endif 42#endif
diff --git a/drivers/media/usb/dvb-usb/dib0700_core.c b/drivers/media/usb/dvb-usb/dib0700_core.c
index f3196658fb70..47ce9d5de4c6 100644
--- a/drivers/media/usb/dvb-usb/dib0700_core.c
+++ b/drivers/media/usb/dvb-usb/dib0700_core.c
@@ -213,7 +213,7 @@ static int dib0700_i2c_xfer_new(struct i2c_adapter *adap, struct i2c_msg *msg,
213 usb_rcvctrlpipe(d->udev, 0), 213 usb_rcvctrlpipe(d->udev, 0),
214 REQUEST_NEW_I2C_READ, 214 REQUEST_NEW_I2C_READ,
215 USB_TYPE_VENDOR | USB_DIR_IN, 215 USB_TYPE_VENDOR | USB_DIR_IN,
216 value, index, msg[i].buf, 216 value, index, st->buf,
217 msg[i].len, 217 msg[i].len,
218 USB_CTRL_GET_TIMEOUT); 218 USB_CTRL_GET_TIMEOUT);
219 if (result < 0) { 219 if (result < 0) {
@@ -221,6 +221,14 @@ static int dib0700_i2c_xfer_new(struct i2c_adapter *adap, struct i2c_msg *msg,
221 break; 221 break;
222 } 222 }
223 223
224 if (msg[i].len > sizeof(st->buf)) {
225 deb_info("buffer too small to fit %d bytes\n",
226 msg[i].len);
227 return -EIO;
228 }
229
230 memcpy(msg[i].buf, st->buf, msg[i].len);
231
224 deb_data("<<< "); 232 deb_data("<<< ");
225 debug_dump(msg[i].buf, msg[i].len, deb_data); 233 debug_dump(msg[i].buf, msg[i].len, deb_data);
226 234
@@ -238,6 +246,13 @@ static int dib0700_i2c_xfer_new(struct i2c_adapter *adap, struct i2c_msg *msg,
238 /* I2C ctrl + FE bus; */ 246 /* I2C ctrl + FE bus; */
239 st->buf[3] = ((gen_mode << 6) & 0xC0) | 247 st->buf[3] = ((gen_mode << 6) & 0xC0) |
240 ((bus_mode << 4) & 0x30); 248 ((bus_mode << 4) & 0x30);
249
250 if (msg[i].len > sizeof(st->buf) - 4) {
251 deb_info("i2c message to big: %d\n",
252 msg[i].len);
253 return -EIO;
254 }
255
241 /* The Actual i2c payload */ 256 /* The Actual i2c payload */
242 memcpy(&st->buf[4], msg[i].buf, msg[i].len); 257 memcpy(&st->buf[4], msg[i].buf, msg[i].len);
243 258
@@ -283,6 +298,11 @@ static int dib0700_i2c_xfer_legacy(struct i2c_adapter *adap,
283 /* fill in the address */ 298 /* fill in the address */
284 st->buf[1] = msg[i].addr << 1; 299 st->buf[1] = msg[i].addr << 1;
285 /* fill the buffer */ 300 /* fill the buffer */
301 if (msg[i].len > sizeof(st->buf) - 2) {
302 deb_info("i2c xfer to big: %d\n",
303 msg[i].len);
304 return -EIO;
305 }
286 memcpy(&st->buf[2], msg[i].buf, msg[i].len); 306 memcpy(&st->buf[2], msg[i].buf, msg[i].len);
287 307
288 /* write/read request */ 308 /* write/read request */
@@ -292,13 +312,20 @@ static int dib0700_i2c_xfer_legacy(struct i2c_adapter *adap,
292 312
293 /* special thing in the current firmware: when length is zero the read-failed */ 313 /* special thing in the current firmware: when length is zero the read-failed */
294 len = dib0700_ctrl_rd(d, st->buf, msg[i].len + 2, 314 len = dib0700_ctrl_rd(d, st->buf, msg[i].len + 2,
295 msg[i+1].buf, msg[i+1].len); 315 st->buf, msg[i + 1].len);
296 if (len <= 0) { 316 if (len <= 0) {
297 deb_info("I2C read failed on address 0x%02x\n", 317 deb_info("I2C read failed on address 0x%02x\n",
298 msg[i].addr); 318 msg[i].addr);
299 break; 319 break;
300 } 320 }
301 321
322 if (msg[i + 1].len > sizeof(st->buf)) {
323 deb_info("i2c xfer buffer to small for %d\n",
324 msg[i].len);
325 return -EIO;
326 }
327 memcpy(msg[i + 1].buf, st->buf, msg[i + 1].len);
328
302 msg[i+1].len = len; 329 msg[i+1].len = len;
303 330
304 i++; 331 i++;
@@ -677,7 +704,7 @@ static void dib0700_rc_urb_completion(struct urb *purb)
677 struct dvb_usb_device *d = purb->context; 704 struct dvb_usb_device *d = purb->context;
678 struct dib0700_rc_response *poll_reply; 705 struct dib0700_rc_response *poll_reply;
679 enum rc_type protocol; 706 enum rc_type protocol;
680 u32 uninitialized_var(keycode); 707 u32 keycode;
681 u8 toggle; 708 u8 toggle;
682 709
683 deb_info("%s()\n", __func__); 710 deb_info("%s()\n", __func__);
@@ -718,7 +745,8 @@ static void dib0700_rc_urb_completion(struct urb *purb)
718 poll_reply->nec.data == 0x00 && 745 poll_reply->nec.data == 0x00 &&
719 poll_reply->nec.not_data == 0xff) { 746 poll_reply->nec.not_data == 0xff) {
720 poll_reply->data_state = 2; 747 poll_reply->data_state = 2;
721 break; 748 rc_repeat(d->rc_dev);
749 goto resubmit;
722 } 750 }
723 751
724 if ((poll_reply->nec.data ^ poll_reply->nec.not_data) != 0xff) { 752 if ((poll_reply->nec.data ^ poll_reply->nec.not_data) != 0xff) {
diff --git a/drivers/media/usb/dvb-usb/dib0700_devices.c b/drivers/media/usb/dvb-usb/dib0700_devices.c
index 0857b56e652c..ef1b8ee75c57 100644
--- a/drivers/media/usb/dvb-usb/dib0700_devices.c
+++ b/drivers/media/usb/dvb-usb/dib0700_devices.c
@@ -508,8 +508,6 @@ static int stk7700ph_tuner_attach(struct dvb_usb_adapter *adap)
508 508
509#define DEFAULT_RC_INTERVAL 50 509#define DEFAULT_RC_INTERVAL 50
510 510
511static u8 rc_request[] = { REQUEST_POLL_RC, 0 };
512
513/* 511/*
514 * This function is used only when firmware is < 1.20 version. Newer 512 * This function is used only when firmware is < 1.20 version. Newer
515 * firmwares use bulk mode, with functions implemented at dib0700_core, 513 * firmwares use bulk mode, with functions implemented at dib0700_core,
@@ -517,7 +515,6 @@ static u8 rc_request[] = { REQUEST_POLL_RC, 0 };
517 */ 515 */
518static int dib0700_rc_query_old_firmware(struct dvb_usb_device *d) 516static int dib0700_rc_query_old_firmware(struct dvb_usb_device *d)
519{ 517{
520 u8 key[4];
521 enum rc_type protocol; 518 enum rc_type protocol;
522 u32 scancode; 519 u32 scancode;
523 u8 toggle; 520 u8 toggle;
@@ -532,39 +529,43 @@ static int dib0700_rc_query_old_firmware(struct dvb_usb_device *d)
532 return 0; 529 return 0;
533 } 530 }
534 531
535 i = dib0700_ctrl_rd(d, rc_request, 2, key, 4); 532 st->buf[0] = REQUEST_POLL_RC;
533 st->buf[1] = 0;
534
535 i = dib0700_ctrl_rd(d, st->buf, 2, st->buf, 4);
536 if (i <= 0) { 536 if (i <= 0) {
537 err("RC Query Failed"); 537 err("RC Query Failed");
538 return -1; 538 return -EIO;
539 } 539 }
540 540
541 /* losing half of KEY_0 events from Philipps rc5 remotes.. */ 541 /* losing half of KEY_0 events from Philipps rc5 remotes.. */
542 if (key[0] == 0 && key[1] == 0 && key[2] == 0 && key[3] == 0) 542 if (st->buf[0] == 0 && st->buf[1] == 0
543 && st->buf[2] == 0 && st->buf[3] == 0)
543 return 0; 544 return 0;
544 545
545 /* info("%d: %2X %2X %2X %2X",dvb_usb_dib0700_ir_proto,(int)key[3-2],(int)key[3-3],(int)key[3-1],(int)key[3]); */ 546 /* info("%d: %2X %2X %2X %2X",dvb_usb_dib0700_ir_proto,(int)st->buf[3 - 2],(int)st->buf[3 - 3],(int)st->buf[3 - 1],(int)st->buf[3]); */
546 547
547 dib0700_rc_setup(d, NULL); /* reset ir sensor data to prevent false events */ 548 dib0700_rc_setup(d, NULL); /* reset ir sensor data to prevent false events */
548 549
549 switch (d->props.rc.core.protocol) { 550 switch (d->props.rc.core.protocol) {
550 case RC_BIT_NEC: 551 case RC_BIT_NEC:
551 /* NEC protocol sends repeat code as 0 0 0 FF */ 552 /* NEC protocol sends repeat code as 0 0 0 FF */
552 if ((key[3-2] == 0x00) && (key[3-3] == 0x00) && 553 if ((st->buf[3 - 2] == 0x00) && (st->buf[3 - 3] == 0x00) &&
553 (key[3] == 0xff)) { 554 (st->buf[3] == 0xff)) {
554 rc_repeat(d->rc_dev); 555 rc_repeat(d->rc_dev);
555 return 0; 556 return 0;
556 } 557 }
557 558
558 protocol = RC_TYPE_NEC; 559 protocol = RC_TYPE_NEC;
559 scancode = RC_SCANCODE_NEC(key[3-2], key[3-3]); 560 scancode = RC_SCANCODE_NEC(st->buf[3 - 2], st->buf[3 - 3]);
560 toggle = 0; 561 toggle = 0;
561 break; 562 break;
562 563
563 default: 564 default:
564 /* RC-5 protocol changes toggle bit on new keypress */ 565 /* RC-5 protocol changes toggle bit on new keypress */
565 protocol = RC_TYPE_RC5; 566 protocol = RC_TYPE_RC5;
566 scancode = RC_SCANCODE_RC5(key[3-2], key[3-3]); 567 scancode = RC_SCANCODE_RC5(st->buf[3 - 2], st->buf[3 - 3]);
567 toggle = key[3-1]; 568 toggle = st->buf[3 - 1];
568 break; 569 break;
569 } 570 }
570 571
diff --git a/drivers/media/usb/dvb-usb/dibusb-common.c b/drivers/media/usb/dvb-usb/dibusb-common.c
index 18ed3bfbb5e2..de3ee2547479 100644
--- a/drivers/media/usb/dvb-usb/dibusb-common.c
+++ b/drivers/media/usb/dvb-usb/dibusb-common.c
@@ -62,72 +62,117 @@ EXPORT_SYMBOL(dibusb_pid_filter_ctrl);
62 62
63int dibusb_power_ctrl(struct dvb_usb_device *d, int onoff) 63int dibusb_power_ctrl(struct dvb_usb_device *d, int onoff)
64{ 64{
65 u8 b[3]; 65 u8 *b;
66 int ret; 66 int ret;
67
68 b = kmalloc(3, GFP_KERNEL);
69 if (!b)
70 return -ENOMEM;
71
67 b[0] = DIBUSB_REQ_SET_IOCTL; 72 b[0] = DIBUSB_REQ_SET_IOCTL;
68 b[1] = DIBUSB_IOCTL_CMD_POWER_MODE; 73 b[1] = DIBUSB_IOCTL_CMD_POWER_MODE;
69 b[2] = onoff ? DIBUSB_IOCTL_POWER_WAKEUP : DIBUSB_IOCTL_POWER_SLEEP; 74 b[2] = onoff ? DIBUSB_IOCTL_POWER_WAKEUP : DIBUSB_IOCTL_POWER_SLEEP;
70 ret = dvb_usb_generic_write(d,b,3); 75
76 ret = dvb_usb_generic_write(d, b, 3);
77
78 kfree(b);
79
71 msleep(10); 80 msleep(10);
81
72 return ret; 82 return ret;
73} 83}
74EXPORT_SYMBOL(dibusb_power_ctrl); 84EXPORT_SYMBOL(dibusb_power_ctrl);
75 85
76int dibusb2_0_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff) 86int dibusb2_0_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
77{ 87{
78 u8 b[3] = { 0 };
79 int ret; 88 int ret;
89 u8 *b;
90
91 b = kmalloc(3, GFP_KERNEL);
92 if (!b)
93 return -ENOMEM;
80 94
81 if ((ret = dibusb_streaming_ctrl(adap,onoff)) < 0) 95 if ((ret = dibusb_streaming_ctrl(adap,onoff)) < 0)
82 return ret; 96 goto ret;
83 97
84 if (onoff) { 98 if (onoff) {
85 b[0] = DIBUSB_REQ_SET_STREAMING_MODE; 99 b[0] = DIBUSB_REQ_SET_STREAMING_MODE;
86 b[1] = 0x00; 100 b[1] = 0x00;
87 if ((ret = dvb_usb_generic_write(adap->dev,b,2)) < 0) 101 ret = dvb_usb_generic_write(adap->dev, b, 2);
88 return ret; 102 if (ret < 0)
103 goto ret;
89 } 104 }
90 105
91 b[0] = DIBUSB_REQ_SET_IOCTL; 106 b[0] = DIBUSB_REQ_SET_IOCTL;
92 b[1] = onoff ? DIBUSB_IOCTL_CMD_ENABLE_STREAM : DIBUSB_IOCTL_CMD_DISABLE_STREAM; 107 b[1] = onoff ? DIBUSB_IOCTL_CMD_ENABLE_STREAM : DIBUSB_IOCTL_CMD_DISABLE_STREAM;
93 return dvb_usb_generic_write(adap->dev,b,3); 108 ret = dvb_usb_generic_write(adap->dev, b, 3);
109
110ret:
111 kfree(b);
112 return ret;
94} 113}
95EXPORT_SYMBOL(dibusb2_0_streaming_ctrl); 114EXPORT_SYMBOL(dibusb2_0_streaming_ctrl);
96 115
97int dibusb2_0_power_ctrl(struct dvb_usb_device *d, int onoff) 116int dibusb2_0_power_ctrl(struct dvb_usb_device *d, int onoff)
98{ 117{
99 if (onoff) { 118 u8 *b;
100 u8 b[3] = { DIBUSB_REQ_SET_IOCTL, DIBUSB_IOCTL_CMD_POWER_MODE, DIBUSB_IOCTL_POWER_WAKEUP }; 119 int ret;
101 return dvb_usb_generic_write(d,b,3); 120
102 } else 121 if (!onoff)
103 return 0; 122 return 0;
123
124 b = kmalloc(3, GFP_KERNEL);
125 if (!b)
126 return -ENOMEM;
127
128 b[0] = DIBUSB_REQ_SET_IOCTL;
129 b[1] = DIBUSB_IOCTL_CMD_POWER_MODE;
130 b[2] = DIBUSB_IOCTL_POWER_WAKEUP;
131
132 ret = dvb_usb_generic_write(d, b, 3);
133
134 kfree(b);
135
136 return ret;
104} 137}
105EXPORT_SYMBOL(dibusb2_0_power_ctrl); 138EXPORT_SYMBOL(dibusb2_0_power_ctrl);
106 139
107static int dibusb_i2c_msg(struct dvb_usb_device *d, u8 addr, 140static int dibusb_i2c_msg(struct dvb_usb_device *d, u8 addr,
108 u8 *wbuf, u16 wlen, u8 *rbuf, u16 rlen) 141 u8 *wbuf, u16 wlen, u8 *rbuf, u16 rlen)
109{ 142{
110 u8 sndbuf[MAX_XFER_SIZE]; /* lead(1) devaddr,direction(1) addr(2) data(wlen) (len(2) (when reading)) */ 143 u8 *sndbuf;
144 int ret, wo, len;
145
111 /* write only ? */ 146 /* write only ? */
112 int wo = (rbuf == NULL || rlen == 0), 147 wo = (rbuf == NULL || rlen == 0);
113 len = 2 + wlen + (wo ? 0 : 2); 148
149 len = 2 + wlen + (wo ? 0 : 2);
150
151 sndbuf = kmalloc(MAX_XFER_SIZE, GFP_KERNEL);
152 if (!sndbuf)
153 return -ENOMEM;
114 154
115 if (4 + wlen > sizeof(sndbuf)) { 155 if (4 + wlen > MAX_XFER_SIZE) {
116 warn("i2c wr: len=%d is too big!\n", wlen); 156 warn("i2c wr: len=%d is too big!\n", wlen);
117 return -EOPNOTSUPP; 157 ret = -EOPNOTSUPP;
158 goto ret;
118 } 159 }
119 160
120 sndbuf[0] = wo ? DIBUSB_REQ_I2C_WRITE : DIBUSB_REQ_I2C_READ; 161 sndbuf[0] = wo ? DIBUSB_REQ_I2C_WRITE : DIBUSB_REQ_I2C_READ;
121 sndbuf[1] = (addr << 1) | (wo ? 0 : 1); 162 sndbuf[1] = (addr << 1) | (wo ? 0 : 1);
122 163
123 memcpy(&sndbuf[2],wbuf,wlen); 164 memcpy(&sndbuf[2], wbuf, wlen);
124 165
125 if (!wo) { 166 if (!wo) {
126 sndbuf[wlen+2] = (rlen >> 8) & 0xff; 167 sndbuf[wlen + 2] = (rlen >> 8) & 0xff;
127 sndbuf[wlen+3] = rlen & 0xff; 168 sndbuf[wlen + 3] = rlen & 0xff;
128 } 169 }
129 170
130 return dvb_usb_generic_rw(d,sndbuf,len,rbuf,rlen,0); 171 ret = dvb_usb_generic_rw(d, sndbuf, len, rbuf, rlen, 0);
172
173ret:
174 kfree(sndbuf);
175 return ret;
131} 176}
132 177
133/* 178/*
@@ -319,11 +364,27 @@ EXPORT_SYMBOL(rc_map_dibusb_table);
319 364
320int dibusb_rc_query(struct dvb_usb_device *d, u32 *event, int *state) 365int dibusb_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
321{ 366{
322 u8 key[5],cmd = DIBUSB_REQ_POLL_REMOTE; 367 u8 *buf;
323 dvb_usb_generic_rw(d,&cmd,1,key,5,0); 368 int ret;
324 dvb_usb_nec_rc_key_to_event(d,key,event,state); 369
325 if (key[0] != 0) 370 buf = kmalloc(5, GFP_KERNEL);
326 deb_info("key: %*ph\n", 5, key); 371 if (!buf)
327 return 0; 372 return -ENOMEM;
373
374 buf[0] = DIBUSB_REQ_POLL_REMOTE;
375
376 ret = dvb_usb_generic_rw(d, buf, 1, buf, 5, 0);
377 if (ret < 0)
378 goto ret;
379
380 dvb_usb_nec_rc_key_to_event(d, buf, event, state);
381
382 if (buf[0] != 0)
383 deb_info("key: %*ph\n", 5, buf);
384
385 kfree(buf);
386
387ret:
388 return ret;
328} 389}
329EXPORT_SYMBOL(dibusb_rc_query); 390EXPORT_SYMBOL(dibusb_rc_query);
diff --git a/drivers/media/usb/dvb-usb/dibusb.h b/drivers/media/usb/dvb-usb/dibusb.h
index 3f82163d8ab8..697be2a17ade 100644
--- a/drivers/media/usb/dvb-usb/dibusb.h
+++ b/drivers/media/usb/dvb-usb/dibusb.h
@@ -96,6 +96,9 @@
96#define DIBUSB_IOCTL_CMD_ENABLE_STREAM 0x01 96#define DIBUSB_IOCTL_CMD_ENABLE_STREAM 0x01
97#define DIBUSB_IOCTL_CMD_DISABLE_STREAM 0x02 97#define DIBUSB_IOCTL_CMD_DISABLE_STREAM 0x02
98 98
99/* Max transfer size done by I2C transfer functions */
100#define MAX_XFER_SIZE 64
101
99struct dibusb_state { 102struct dibusb_state {
100 struct dib_fe_xfer_ops ops; 103 struct dib_fe_xfer_ops ops;
101 int mt2060_present; 104 int mt2060_present;
diff --git a/drivers/media/usb/dvb-usb/digitv.c b/drivers/media/usb/dvb-usb/digitv.c
index 63134335c994..4284f6984dc1 100644
--- a/drivers/media/usb/dvb-usb/digitv.c
+++ b/drivers/media/usb/dvb-usb/digitv.c
@@ -28,22 +28,26 @@ DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
28static int digitv_ctrl_msg(struct dvb_usb_device *d, 28static int digitv_ctrl_msg(struct dvb_usb_device *d,
29 u8 cmd, u8 vv, u8 *wbuf, int wlen, u8 *rbuf, int rlen) 29 u8 cmd, u8 vv, u8 *wbuf, int wlen, u8 *rbuf, int rlen)
30{ 30{
31 int wo = (rbuf == NULL || rlen == 0); /* write-only */ 31 struct digitv_state *st = d->priv;
32 u8 sndbuf[7],rcvbuf[7]; 32 int ret, wo;
33 memset(sndbuf,0,7); memset(rcvbuf,0,7);
34 33
35 sndbuf[0] = cmd; 34 wo = (rbuf == NULL || rlen == 0); /* write-only */
36 sndbuf[1] = vv; 35
37 sndbuf[2] = wo ? wlen : rlen; 36 memset(st->sndbuf, 0, 7);
37 memset(st->rcvbuf, 0, 7);
38
39 st->sndbuf[0] = cmd;
40 st->sndbuf[1] = vv;
41 st->sndbuf[2] = wo ? wlen : rlen;
38 42
39 if (wo) { 43 if (wo) {
40 memcpy(&sndbuf[3],wbuf,wlen); 44 memcpy(&st->sndbuf[3], wbuf, wlen);
41 dvb_usb_generic_write(d,sndbuf,7); 45 ret = dvb_usb_generic_write(d, st->sndbuf, 7);
42 } else { 46 } else {
43 dvb_usb_generic_rw(d,sndbuf,7,rcvbuf,7,10); 47 ret = dvb_usb_generic_rw(d, st->sndbuf, 7, st->rcvbuf, 7, 10);
44 memcpy(rbuf,&rcvbuf[3],rlen); 48 memcpy(rbuf, &st->rcvbuf[3], rlen);
45 } 49 }
46 return 0; 50 return ret;
47} 51}
48 52
49/* I2C */ 53/* I2C */
diff --git a/drivers/media/usb/dvb-usb/digitv.h b/drivers/media/usb/dvb-usb/digitv.h
index 908c09f4966b..581e09c25491 100644
--- a/drivers/media/usb/dvb-usb/digitv.h
+++ b/drivers/media/usb/dvb-usb/digitv.h
@@ -5,7 +5,10 @@
5#include "dvb-usb.h" 5#include "dvb-usb.h"
6 6
7struct digitv_state { 7struct digitv_state {
8 int is_nxt6000; 8 int is_nxt6000;
9
10 unsigned char sndbuf[7];
11 unsigned char rcvbuf[7];
9}; 12};
10 13
11/* protocol (from usblogging and the SDK: 14/* protocol (from usblogging and the SDK:
diff --git a/drivers/media/usb/dvb-usb/dtt200u-fe.c b/drivers/media/usb/dvb-usb/dtt200u-fe.c
index c09332bd99cb..f5c042baa254 100644
--- a/drivers/media/usb/dvb-usb/dtt200u-fe.c
+++ b/drivers/media/usb/dvb-usb/dtt200u-fe.c
@@ -18,17 +18,28 @@ struct dtt200u_fe_state {
18 18
19 struct dtv_frontend_properties fep; 19 struct dtv_frontend_properties fep;
20 struct dvb_frontend frontend; 20 struct dvb_frontend frontend;
21
22 unsigned char data[80];
23 struct mutex data_mutex;
21}; 24};
22 25
23static int dtt200u_fe_read_status(struct dvb_frontend *fe, 26static int dtt200u_fe_read_status(struct dvb_frontend *fe,
24 enum fe_status *stat) 27 enum fe_status *stat)
25{ 28{
26 struct dtt200u_fe_state *state = fe->demodulator_priv; 29 struct dtt200u_fe_state *state = fe->demodulator_priv;
27 u8 st = GET_TUNE_STATUS, b[3]; 30 int ret;
31
32 mutex_lock(&state->data_mutex);
33 state->data[0] = GET_TUNE_STATUS;
28 34
29 dvb_usb_generic_rw(state->d,&st,1,b,3,0); 35 ret = dvb_usb_generic_rw(state->d, state->data, 1, state->data, 3, 0);
36 if (ret < 0) {
37 *stat = 0;
38 mutex_unlock(&state->data_mutex);
39 return ret;
40 }
30 41
31 switch (b[0]) { 42 switch (state->data[0]) {
32 case 0x01: 43 case 0x01:
33 *stat = FE_HAS_SIGNAL | FE_HAS_CARRIER | 44 *stat = FE_HAS_SIGNAL | FE_HAS_CARRIER |
34 FE_HAS_VITERBI | FE_HAS_SYNC | FE_HAS_LOCK; 45 FE_HAS_VITERBI | FE_HAS_SYNC | FE_HAS_LOCK;
@@ -41,51 +52,86 @@ static int dtt200u_fe_read_status(struct dvb_frontend *fe,
41 *stat = 0; 52 *stat = 0;
42 break; 53 break;
43 } 54 }
55 mutex_unlock(&state->data_mutex);
44 return 0; 56 return 0;
45} 57}
46 58
47static int dtt200u_fe_read_ber(struct dvb_frontend* fe, u32 *ber) 59static int dtt200u_fe_read_ber(struct dvb_frontend* fe, u32 *ber)
48{ 60{
49 struct dtt200u_fe_state *state = fe->demodulator_priv; 61 struct dtt200u_fe_state *state = fe->demodulator_priv;
50 u8 bw = GET_VIT_ERR_CNT,b[3]; 62 int ret;
51 dvb_usb_generic_rw(state->d,&bw,1,b,3,0); 63
52 *ber = (b[0] << 16) | (b[1] << 8) | b[2]; 64 mutex_lock(&state->data_mutex);
53 return 0; 65 state->data[0] = GET_VIT_ERR_CNT;
66
67 ret = dvb_usb_generic_rw(state->d, state->data, 1, state->data, 3, 0);
68 if (ret >= 0)
69 *ber = (state->data[0] << 16) | (state->data[1] << 8) | state->data[2];
70
71 mutex_unlock(&state->data_mutex);
72 return ret;
54} 73}
55 74
56static int dtt200u_fe_read_unc_blocks(struct dvb_frontend* fe, u32 *unc) 75static int dtt200u_fe_read_unc_blocks(struct dvb_frontend* fe, u32 *unc)
57{ 76{
58 struct dtt200u_fe_state *state = fe->demodulator_priv; 77 struct dtt200u_fe_state *state = fe->demodulator_priv;
59 u8 bw = GET_RS_UNCOR_BLK_CNT,b[2]; 78 int ret;
60 79
61 dvb_usb_generic_rw(state->d,&bw,1,b,2,0); 80 mutex_lock(&state->data_mutex);
62 *unc = (b[0] << 8) | b[1]; 81 state->data[0] = GET_RS_UNCOR_BLK_CNT;
63 return 0; 82
83 ret = dvb_usb_generic_rw(state->d, state->data, 1, state->data, 2, 0);
84 if (ret >= 0)
85 *unc = (state->data[0] << 8) | state->data[1];
86
87 mutex_unlock(&state->data_mutex);
88 return ret;
64} 89}
65 90
66static int dtt200u_fe_read_signal_strength(struct dvb_frontend* fe, u16 *strength) 91static int dtt200u_fe_read_signal_strength(struct dvb_frontend* fe, u16 *strength)
67{ 92{
68 struct dtt200u_fe_state *state = fe->demodulator_priv; 93 struct dtt200u_fe_state *state = fe->demodulator_priv;
69 u8 bw = GET_AGC, b; 94 int ret;
70 dvb_usb_generic_rw(state->d,&bw,1,&b,1,0); 95
71 *strength = (b << 8) | b; 96 mutex_lock(&state->data_mutex);
72 return 0; 97 state->data[0] = GET_AGC;
98
99 ret = dvb_usb_generic_rw(state->d, state->data, 1, state->data, 1, 0);
100 if (ret >= 0)
101 *strength = (state->data[0] << 8) | state->data[0];
102
103 mutex_unlock(&state->data_mutex);
104 return ret;
73} 105}
74 106
75static int dtt200u_fe_read_snr(struct dvb_frontend* fe, u16 *snr) 107static int dtt200u_fe_read_snr(struct dvb_frontend* fe, u16 *snr)
76{ 108{
77 struct dtt200u_fe_state *state = fe->demodulator_priv; 109 struct dtt200u_fe_state *state = fe->demodulator_priv;
78 u8 bw = GET_SNR,br; 110 int ret;
79 dvb_usb_generic_rw(state->d,&bw,1,&br,1,0); 111
80 *snr = ~((br << 8) | br); 112 mutex_lock(&state->data_mutex);
81 return 0; 113 state->data[0] = GET_SNR;
114
115 ret = dvb_usb_generic_rw(state->d, state->data, 1, state->data, 1, 0);
116 if (ret >= 0)
117 *snr = ~((state->data[0] << 8) | state->data[0]);
118
119 mutex_unlock(&state->data_mutex);
120 return ret;
82} 121}
83 122
84static int dtt200u_fe_init(struct dvb_frontend* fe) 123static int dtt200u_fe_init(struct dvb_frontend* fe)
85{ 124{
86 struct dtt200u_fe_state *state = fe->demodulator_priv; 125 struct dtt200u_fe_state *state = fe->demodulator_priv;
87 u8 b = SET_INIT; 126 int ret;
88 return dvb_usb_generic_write(state->d,&b,1); 127
128 mutex_lock(&state->data_mutex);
129 state->data[0] = SET_INIT;
130
131 ret = dvb_usb_generic_write(state->d, state->data, 1);
132 mutex_unlock(&state->data_mutex);
133
134 return ret;
89} 135}
90 136
91static int dtt200u_fe_sleep(struct dvb_frontend* fe) 137static int dtt200u_fe_sleep(struct dvb_frontend* fe)
@@ -105,39 +151,40 @@ static int dtt200u_fe_set_frontend(struct dvb_frontend *fe)
105{ 151{
106 struct dtv_frontend_properties *fep = &fe->dtv_property_cache; 152 struct dtv_frontend_properties *fep = &fe->dtv_property_cache;
107 struct dtt200u_fe_state *state = fe->demodulator_priv; 153 struct dtt200u_fe_state *state = fe->demodulator_priv;
108 int i; 154 int ret;
109 enum fe_status st;
110 u16 freq = fep->frequency / 250000; 155 u16 freq = fep->frequency / 250000;
111 u8 bwbuf[2] = { SET_BANDWIDTH, 0 },freqbuf[3] = { SET_RF_FREQ, 0, 0 };
112 156
157 mutex_lock(&state->data_mutex);
158 state->data[0] = SET_BANDWIDTH;
113 switch (fep->bandwidth_hz) { 159 switch (fep->bandwidth_hz) {
114 case 8000000: 160 case 8000000:
115 bwbuf[1] = 8; 161 state->data[1] = 8;
116 break; 162 break;
117 case 7000000: 163 case 7000000:
118 bwbuf[1] = 7; 164 state->data[1] = 7;
119 break; 165 break;
120 case 6000000: 166 case 6000000:
121 bwbuf[1] = 6; 167 state->data[1] = 6;
122 break; 168 break;
123 default: 169 default:
124 return -EINVAL; 170 ret = -EINVAL;
171 goto ret;
125 } 172 }
126 173
127 dvb_usb_generic_write(state->d,bwbuf,2); 174 ret = dvb_usb_generic_write(state->d, state->data, 2);
175 if (ret < 0)
176 goto ret;
128 177
129 freqbuf[1] = freq & 0xff; 178 state->data[0] = SET_RF_FREQ;
130 freqbuf[2] = (freq >> 8) & 0xff; 179 state->data[1] = freq & 0xff;
131 dvb_usb_generic_write(state->d,freqbuf,3); 180 state->data[2] = (freq >> 8) & 0xff;
181 ret = dvb_usb_generic_write(state->d, state->data, 3);
182 if (ret < 0)
183 goto ret;
132 184
133 for (i = 0; i < 30; i++) { 185ret:
134 msleep(20); 186 mutex_unlock(&state->data_mutex);
135 dtt200u_fe_read_status(fe, &st); 187 return ret;
136 if (st & FE_TIMEDOUT)
137 continue;
138 }
139
140 return 0;
141} 188}
142 189
143static int dtt200u_fe_get_frontend(struct dvb_frontend* fe, 190static int dtt200u_fe_get_frontend(struct dvb_frontend* fe,
@@ -169,6 +216,7 @@ struct dvb_frontend* dtt200u_fe_attach(struct dvb_usb_device *d)
169 deb_info("attaching frontend dtt200u\n"); 216 deb_info("attaching frontend dtt200u\n");
170 217
171 state->d = d; 218 state->d = d;
219 mutex_init(&state->data_mutex);
172 220
173 memcpy(&state->frontend.ops,&dtt200u_fe_ops,sizeof(struct dvb_frontend_ops)); 221 memcpy(&state->frontend.ops,&dtt200u_fe_ops,sizeof(struct dvb_frontend_ops));
174 state->frontend.demodulator_priv = state; 222 state->frontend.demodulator_priv = state;
diff --git a/drivers/media/usb/dvb-usb/dtt200u.c b/drivers/media/usb/dvb-usb/dtt200u.c
index d2a01b50af0d..fcbff7fb0c4e 100644
--- a/drivers/media/usb/dvb-usb/dtt200u.c
+++ b/drivers/media/usb/dvb-usb/dtt200u.c
@@ -20,75 +20,115 @@ MODULE_PARM_DESC(debug, "set debugging level (1=info,xfer=2 (or-able))." DVB_USB
20 20
21DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); 21DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
22 22
23struct dtt200u_state {
24 unsigned char data[80];
25};
26
23static int dtt200u_power_ctrl(struct dvb_usb_device *d, int onoff) 27static int dtt200u_power_ctrl(struct dvb_usb_device *d, int onoff)
24{ 28{
25 u8 b = SET_INIT; 29 struct dtt200u_state *st = d->priv;
30 int ret = 0;
31
32 mutex_lock(&d->data_mutex);
33
34 st->data[0] = SET_INIT;
26 35
27 if (onoff) 36 if (onoff)
28 dvb_usb_generic_write(d,&b,2); 37 ret = dvb_usb_generic_write(d, st->data, 2);
29 38
30 return 0; 39 mutex_unlock(&d->data_mutex);
40 return ret;
31} 41}
32 42
33static int dtt200u_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff) 43static int dtt200u_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
34{ 44{
35 u8 b_streaming[2] = { SET_STREAMING, onoff }; 45 struct dvb_usb_device *d = adap->dev;
36 u8 b_rst_pid = RESET_PID_FILTER; 46 struct dtt200u_state *st = d->priv;
47 int ret;
37 48
38 dvb_usb_generic_write(adap->dev, b_streaming, 2); 49 mutex_lock(&d->data_mutex);
50 st->data[0] = SET_STREAMING;
51 st->data[1] = onoff;
39 52
40 if (onoff == 0) 53 ret = dvb_usb_generic_write(adap->dev, st->data, 2);
41 dvb_usb_generic_write(adap->dev, &b_rst_pid, 1); 54 if (ret < 0)
42 return 0; 55 goto ret;
56
57 if (onoff)
58 goto ret;
59
60 st->data[0] = RESET_PID_FILTER;
61 ret = dvb_usb_generic_write(adap->dev, st->data, 1);
62
63ret:
64 mutex_unlock(&d->data_mutex);
65
66 return ret;
43} 67}
44 68
45static int dtt200u_pid_filter(struct dvb_usb_adapter *adap, int index, u16 pid, int onoff) 69static int dtt200u_pid_filter(struct dvb_usb_adapter *adap, int index, u16 pid, int onoff)
46{ 70{
47 u8 b_pid[4]; 71 struct dvb_usb_device *d = adap->dev;
72 struct dtt200u_state *st = d->priv;
73 int ret;
74
48 pid = onoff ? pid : 0; 75 pid = onoff ? pid : 0;
49 76
50 b_pid[0] = SET_PID_FILTER; 77 mutex_lock(&d->data_mutex);
51 b_pid[1] = index; 78 st->data[0] = SET_PID_FILTER;
52 b_pid[2] = pid & 0xff; 79 st->data[1] = index;
53 b_pid[3] = (pid >> 8) & 0x1f; 80 st->data[2] = pid & 0xff;
81 st->data[3] = (pid >> 8) & 0x1f;
82
83 ret = dvb_usb_generic_write(adap->dev, st->data, 4);
84 mutex_unlock(&d->data_mutex);
54 85
55 return dvb_usb_generic_write(adap->dev, b_pid, 4); 86 return ret;
56} 87}
57 88
58static int dtt200u_rc_query(struct dvb_usb_device *d) 89static int dtt200u_rc_query(struct dvb_usb_device *d)
59{ 90{
60 u8 key[5],cmd = GET_RC_CODE; 91 struct dtt200u_state *st = d->priv;
61 u32 scancode; 92 u32 scancode;
93 int ret;
94
95 mutex_lock(&d->data_mutex);
96 st->data[0] = GET_RC_CODE;
62 97
63 dvb_usb_generic_rw(d,&cmd,1,key,5,0); 98 ret = dvb_usb_generic_rw(d, st->data, 1, st->data, 5, 0);
64 if (key[0] == 1) { 99 if (ret < 0)
100 goto ret;
101
102 if (st->data[0] == 1) {
65 enum rc_type proto = RC_TYPE_NEC; 103 enum rc_type proto = RC_TYPE_NEC;
66 104
67 scancode = key[1]; 105 scancode = st->data[1];
68 if ((u8) ~key[1] != key[2]) { 106 if ((u8) ~st->data[1] != st->data[2]) {
69 /* Extended NEC */ 107 /* Extended NEC */
70 scancode = scancode << 8; 108 scancode = scancode << 8;
71 scancode |= key[2]; 109 scancode |= st->data[2];
72 proto = RC_TYPE_NECX; 110 proto = RC_TYPE_NECX;
73 } 111 }
74 scancode = scancode << 8; 112 scancode = scancode << 8;
75 scancode |= key[3]; 113 scancode |= st->data[3];
76 114
77 /* Check command checksum is ok */ 115 /* Check command checksum is ok */
78 if ((u8) ~key[3] == key[4]) 116 if ((u8) ~st->data[3] == st->data[4])
79 rc_keydown(d->rc_dev, proto, scancode, 0); 117 rc_keydown(d->rc_dev, proto, scancode, 0);
80 else 118 else
81 rc_keyup(d->rc_dev); 119 rc_keyup(d->rc_dev);
82 } else if (key[0] == 2) { 120 } else if (st->data[0] == 2) {
83 rc_repeat(d->rc_dev); 121 rc_repeat(d->rc_dev);
84 } else { 122 } else {
85 rc_keyup(d->rc_dev); 123 rc_keyup(d->rc_dev);
86 } 124 }
87 125
88 if (key[0] != 0) 126 if (st->data[0] != 0)
89 deb_info("key: %*ph\n", 5, key); 127 deb_info("st->data: %*ph\n", 5, st->data);
90 128
91 return 0; 129ret:
130 mutex_unlock(&d->data_mutex);
131 return ret;
92} 132}
93 133
94static int dtt200u_frontend_attach(struct dvb_usb_adapter *adap) 134static int dtt200u_frontend_attach(struct dvb_usb_adapter *adap)
@@ -140,6 +180,8 @@ static struct dvb_usb_device_properties dtt200u_properties = {
140 .usb_ctrl = CYPRESS_FX2, 180 .usb_ctrl = CYPRESS_FX2,
141 .firmware = "dvb-usb-dtt200u-01.fw", 181 .firmware = "dvb-usb-dtt200u-01.fw",
142 182
183 .size_of_priv = sizeof(struct dtt200u_state),
184
143 .num_adapters = 1, 185 .num_adapters = 1,
144 .adapter = { 186 .adapter = {
145 { 187 {
@@ -190,6 +232,8 @@ static struct dvb_usb_device_properties wt220u_properties = {
190 .usb_ctrl = CYPRESS_FX2, 232 .usb_ctrl = CYPRESS_FX2,
191 .firmware = "dvb-usb-wt220u-02.fw", 233 .firmware = "dvb-usb-wt220u-02.fw",
192 234
235 .size_of_priv = sizeof(struct dtt200u_state),
236
193 .num_adapters = 1, 237 .num_adapters = 1,
194 .adapter = { 238 .adapter = {
195 { 239 {
@@ -240,6 +284,8 @@ static struct dvb_usb_device_properties wt220u_fc_properties = {
240 .usb_ctrl = CYPRESS_FX2, 284 .usb_ctrl = CYPRESS_FX2,
241 .firmware = "dvb-usb-wt220u-fc03.fw", 285 .firmware = "dvb-usb-wt220u-fc03.fw",
242 286
287 .size_of_priv = sizeof(struct dtt200u_state),
288
243 .num_adapters = 1, 289 .num_adapters = 1,
244 .adapter = { 290 .adapter = {
245 { 291 {
@@ -290,6 +336,8 @@ static struct dvb_usb_device_properties wt220u_zl0353_properties = {
290 .usb_ctrl = CYPRESS_FX2, 336 .usb_ctrl = CYPRESS_FX2,
291 .firmware = "dvb-usb-wt220u-zl0353-01.fw", 337 .firmware = "dvb-usb-wt220u-zl0353-01.fw",
292 338
339 .size_of_priv = sizeof(struct dtt200u_state),
340
293 .num_adapters = 1, 341 .num_adapters = 1,
294 .adapter = { 342 .adapter = {
295 { 343 {
@@ -340,6 +388,8 @@ static struct dvb_usb_device_properties wt220u_miglia_properties = {
340 .usb_ctrl = CYPRESS_FX2, 388 .usb_ctrl = CYPRESS_FX2,
341 .firmware = "dvb-usb-wt220u-miglia-01.fw", 389 .firmware = "dvb-usb-wt220u-miglia-01.fw",
342 390
391 .size_of_priv = sizeof(struct dtt200u_state),
392
343 .num_adapters = 1, 393 .num_adapters = 1,
344 .generic_bulk_ctrl_endpoint = 0x01, 394 .generic_bulk_ctrl_endpoint = 0x01,
345 395
diff --git a/drivers/media/usb/dvb-usb/dtv5100.c b/drivers/media/usb/dvb-usb/dtv5100.c
index 3d11df41cac0..c60fb54f445f 100644
--- a/drivers/media/usb/dvb-usb/dtv5100.c
+++ b/drivers/media/usb/dvb-usb/dtv5100.c
@@ -31,9 +31,14 @@ module_param_named(debug, dvb_usb_dtv5100_debug, int, 0644);
31MODULE_PARM_DESC(debug, "set debugging level" DVB_USB_DEBUG_STATUS); 31MODULE_PARM_DESC(debug, "set debugging level" DVB_USB_DEBUG_STATUS);
32DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); 32DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
33 33
34struct dtv5100_state {
35 unsigned char data[80];
36};
37
34static int dtv5100_i2c_msg(struct dvb_usb_device *d, u8 addr, 38static int dtv5100_i2c_msg(struct dvb_usb_device *d, u8 addr,
35 u8 *wbuf, u16 wlen, u8 *rbuf, u16 rlen) 39 u8 *wbuf, u16 wlen, u8 *rbuf, u16 rlen)
36{ 40{
41 struct dtv5100_state *st = d->priv;
37 u8 request; 42 u8 request;
38 u8 type; 43 u8 type;
39 u16 value; 44 u16 value;
@@ -60,9 +65,10 @@ static int dtv5100_i2c_msg(struct dvb_usb_device *d, u8 addr,
60 } 65 }
61 index = (addr << 8) + wbuf[0]; 66 index = (addr << 8) + wbuf[0];
62 67
68 memcpy(st->data, rbuf, rlen);
63 msleep(1); /* avoid I2C errors */ 69 msleep(1); /* avoid I2C errors */
64 return usb_control_msg(d->udev, usb_rcvctrlpipe(d->udev, 0), request, 70 return usb_control_msg(d->udev, usb_rcvctrlpipe(d->udev, 0), request,
65 type, value, index, rbuf, rlen, 71 type, value, index, st->data, rlen,
66 DTV5100_USB_TIMEOUT); 72 DTV5100_USB_TIMEOUT);
67} 73}
68 74
@@ -176,7 +182,7 @@ static struct dvb_usb_device_properties dtv5100_properties = {
176 .caps = DVB_USB_IS_AN_I2C_ADAPTER, 182 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
177 .usb_ctrl = DEVICE_SPECIFIC, 183 .usb_ctrl = DEVICE_SPECIFIC,
178 184
179 .size_of_priv = 0, 185 .size_of_priv = sizeof(struct dtv5100_state),
180 186
181 .num_adapters = 1, 187 .num_adapters = 1,
182 .adapter = {{ 188 .adapter = {{
diff --git a/drivers/media/usb/dvb-usb/dvb-usb-init.c b/drivers/media/usb/dvb-usb/dvb-usb-init.c
index 3896ba9a4179..84308569e7dc 100644
--- a/drivers/media/usb/dvb-usb/dvb-usb-init.c
+++ b/drivers/media/usb/dvb-usb/dvb-usb-init.c
@@ -142,6 +142,7 @@ static int dvb_usb_init(struct dvb_usb_device *d, short *adapter_nums)
142{ 142{
143 int ret = 0; 143 int ret = 0;
144 144
145 mutex_init(&d->data_mutex);
145 mutex_init(&d->usb_mutex); 146 mutex_init(&d->usb_mutex);
146 mutex_init(&d->i2c_mutex); 147 mutex_init(&d->i2c_mutex);
147 148
diff --git a/drivers/media/usb/dvb-usb/dvb-usb.h b/drivers/media/usb/dvb-usb/dvb-usb.h
index 639c4678c65b..107255b08b2b 100644
--- a/drivers/media/usb/dvb-usb/dvb-usb.h
+++ b/drivers/media/usb/dvb-usb/dvb-usb.h
@@ -404,8 +404,12 @@ struct dvb_usb_adapter {
404 * Powered is in/decremented for each call to modify the state. 404 * Powered is in/decremented for each call to modify the state.
405 * @udev: pointer to the device's struct usb_device. 405 * @udev: pointer to the device's struct usb_device.
406 * 406 *
407 * @usb_mutex: semaphore of USB control messages (reading needs two messages) 407 * @data_mutex: mutex to protect the data structure used to store URB data
408 * @i2c_mutex: semaphore for i2c-transfers 408 * @usb_mutex: mutex of USB control messages (reading needs two messages).
409 * Please notice that this mutex is used internally at the generic
410 * URB control functions. So, drivers using dvb_usb_generic_rw() and
411 * derivated functions should not lock it internally.
412 * @i2c_mutex: mutex for i2c-transfers
409 * 413 *
410 * @i2c_adap: device's i2c_adapter if it uses I2CoverUSB 414 * @i2c_adap: device's i2c_adapter if it uses I2CoverUSB
411 * 415 *
@@ -433,6 +437,7 @@ struct dvb_usb_device {
433 int powered; 437 int powered;
434 438
435 /* locking */ 439 /* locking */
440 struct mutex data_mutex;
436 struct mutex usb_mutex; 441 struct mutex usb_mutex;
437 442
438 /* i2c */ 443 /* i2c */
diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
index 5fb0c650926e..2c720cb2fb00 100644
--- a/drivers/media/usb/dvb-usb/dw2102.c
+++ b/drivers/media/usb/dvb-usb/dw2102.c
@@ -852,7 +852,7 @@ static int su3000_power_ctrl(struct dvb_usb_device *d, int i)
852 if (i && !state->initialized) { 852 if (i && !state->initialized) {
853 state->initialized = 1; 853 state->initialized = 1;
854 /* reset board */ 854 /* reset board */
855 dvb_usb_generic_rw(d, obuf, 2, NULL, 0, 0); 855 return dvb_usb_generic_rw(d, obuf, 2, NULL, 0, 0);
856 } 856 }
857 857
858 return 0; 858 return 0;
diff --git a/drivers/media/usb/dvb-usb/gp8psk.c b/drivers/media/usb/dvb-usb/gp8psk.c
index 5d0384dd45b5..993bb7a72985 100644
--- a/drivers/media/usb/dvb-usb/gp8psk.c
+++ b/drivers/media/usb/dvb-usb/gp8psk.c
@@ -15,6 +15,7 @@
15 * see Documentation/dvb/README.dvb-usb for more information 15 * see Documentation/dvb/README.dvb-usb for more information
16 */ 16 */
17#include "gp8psk.h" 17#include "gp8psk.h"
18#include "gp8psk-fe.h"
18 19
19/* debug */ 20/* debug */
20static char bcm4500_firmware[] = "dvb-usb-gp8psk-02.fw"; 21static char bcm4500_firmware[] = "dvb-usb-gp8psk-02.fw";
@@ -24,37 +25,19 @@ MODULE_PARM_DESC(debug, "set debugging level (1=info,xfer=2,rc=4 (or-able))." DV
24 25
25DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); 26DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
26 27
27static int gp8psk_get_fw_version(struct dvb_usb_device *d, u8 *fw_vers) 28struct gp8psk_state {
28{ 29 unsigned char data[80];
29 return (gp8psk_usb_in_op(d, GET_FW_VERS, 0, 0, fw_vers, 6)); 30};
30}
31
32static int gp8psk_get_fpga_version(struct dvb_usb_device *d, u8 *fpga_vers)
33{
34 return (gp8psk_usb_in_op(d, GET_FPGA_VERS, 0, 0, fpga_vers, 1));
35}
36
37static void gp8psk_info(struct dvb_usb_device *d)
38{
39 u8 fpga_vers, fw_vers[6];
40
41 if (!gp8psk_get_fw_version(d, fw_vers))
42 info("FW Version = %i.%02i.%i (0x%x) Build %4i/%02i/%02i",
43 fw_vers[2], fw_vers[1], fw_vers[0], GP8PSK_FW_VERS(fw_vers),
44 2000 + fw_vers[5], fw_vers[4], fw_vers[3]);
45 else
46 info("failed to get FW version");
47
48 if (!gp8psk_get_fpga_version(d, &fpga_vers))
49 info("FPGA Version = %i", fpga_vers);
50 else
51 info("failed to get FPGA version");
52}
53 31
54int gp8psk_usb_in_op(struct dvb_usb_device *d, u8 req, u16 value, u16 index, u8 *b, int blen) 32static int gp8psk_usb_in_op(struct dvb_usb_device *d, u8 req, u16 value,
33 u16 index, u8 *b, int blen)
55{ 34{
35 struct gp8psk_state *st = d->priv;
56 int ret = 0,try = 0; 36 int ret = 0,try = 0;
57 37
38 if (blen > sizeof(st->data))
39 return -EIO;
40
58 if ((ret = mutex_lock_interruptible(&d->usb_mutex))) 41 if ((ret = mutex_lock_interruptible(&d->usb_mutex)))
59 return ret; 42 return ret;
60 43
@@ -63,7 +46,7 @@ int gp8psk_usb_in_op(struct dvb_usb_device *d, u8 req, u16 value, u16 index, u8
63 usb_rcvctrlpipe(d->udev,0), 46 usb_rcvctrlpipe(d->udev,0),
64 req, 47 req,
65 USB_TYPE_VENDOR | USB_DIR_IN, 48 USB_TYPE_VENDOR | USB_DIR_IN,
66 value,index,b,blen, 49 value, index, st->data, blen,
67 2000); 50 2000);
68 deb_info("reading number %d (ret: %d)\n",try,ret); 51 deb_info("reading number %d (ret: %d)\n",try,ret);
69 try++; 52 try++;
@@ -72,8 +55,10 @@ int gp8psk_usb_in_op(struct dvb_usb_device *d, u8 req, u16 value, u16 index, u8
72 if (ret < 0 || ret != blen) { 55 if (ret < 0 || ret != blen) {
73 warn("usb in %d operation failed.", req); 56 warn("usb in %d operation failed.", req);
74 ret = -EIO; 57 ret = -EIO;
75 } else 58 } else {
76 ret = 0; 59 ret = 0;
60 memcpy(b, st->data, blen);
61 }
77 62
78 deb_xfer("in: req. %x, val: %x, ind: %x, buffer: ",req,value,index); 63 deb_xfer("in: req. %x, val: %x, ind: %x, buffer: ",req,value,index);
79 debug_dump(b,blen,deb_xfer); 64 debug_dump(b,blen,deb_xfer);
@@ -83,22 +68,27 @@ int gp8psk_usb_in_op(struct dvb_usb_device *d, u8 req, u16 value, u16 index, u8
83 return ret; 68 return ret;
84} 69}
85 70
86int gp8psk_usb_out_op(struct dvb_usb_device *d, u8 req, u16 value, 71static int gp8psk_usb_out_op(struct dvb_usb_device *d, u8 req, u16 value,
87 u16 index, u8 *b, int blen) 72 u16 index, u8 *b, int blen)
88{ 73{
74 struct gp8psk_state *st = d->priv;
89 int ret; 75 int ret;
90 76
91 deb_xfer("out: req. %x, val: %x, ind: %x, buffer: ",req,value,index); 77 deb_xfer("out: req. %x, val: %x, ind: %x, buffer: ",req,value,index);
92 debug_dump(b,blen,deb_xfer); 78 debug_dump(b,blen,deb_xfer);
93 79
80 if (blen > sizeof(st->data))
81 return -EIO;
82
94 if ((ret = mutex_lock_interruptible(&d->usb_mutex))) 83 if ((ret = mutex_lock_interruptible(&d->usb_mutex)))
95 return ret; 84 return ret;
96 85
86 memcpy(st->data, b, blen);
97 if (usb_control_msg(d->udev, 87 if (usb_control_msg(d->udev,
98 usb_sndctrlpipe(d->udev,0), 88 usb_sndctrlpipe(d->udev,0),
99 req, 89 req,
100 USB_TYPE_VENDOR | USB_DIR_OUT, 90 USB_TYPE_VENDOR | USB_DIR_OUT,
101 value,index,b,blen, 91 value, index, st->data, blen,
102 2000) != blen) { 92 2000) != blen) {
103 warn("usb out operation failed."); 93 warn("usb out operation failed.");
104 ret = -EIO; 94 ret = -EIO;
@@ -109,6 +99,34 @@ int gp8psk_usb_out_op(struct dvb_usb_device *d, u8 req, u16 value,
109 return ret; 99 return ret;
110} 100}
111 101
102
103static int gp8psk_get_fw_version(struct dvb_usb_device *d, u8 *fw_vers)
104{
105 return gp8psk_usb_in_op(d, GET_FW_VERS, 0, 0, fw_vers, 6);
106}
107
108static int gp8psk_get_fpga_version(struct dvb_usb_device *d, u8 *fpga_vers)
109{
110 return gp8psk_usb_in_op(d, GET_FPGA_VERS, 0, 0, fpga_vers, 1);
111}
112
113static void gp8psk_info(struct dvb_usb_device *d)
114{
115 u8 fpga_vers, fw_vers[6];
116
117 if (!gp8psk_get_fw_version(d, fw_vers))
118 info("FW Version = %i.%02i.%i (0x%x) Build %4i/%02i/%02i",
119 fw_vers[2], fw_vers[1], fw_vers[0], GP8PSK_FW_VERS(fw_vers),
120 2000 + fw_vers[5], fw_vers[4], fw_vers[3]);
121 else
122 info("failed to get FW version");
123
124 if (!gp8psk_get_fpga_version(d, &fpga_vers))
125 info("FPGA Version = %i", fpga_vers);
126 else
127 info("failed to get FPGA version");
128}
129
112static int gp8psk_load_bcm4500fw(struct dvb_usb_device *d) 130static int gp8psk_load_bcm4500fw(struct dvb_usb_device *d)
113{ 131{
114 int ret; 132 int ret;
@@ -143,6 +161,11 @@ static int gp8psk_load_bcm4500fw(struct dvb_usb_device *d)
143 err("failed to load bcm4500 firmware."); 161 err("failed to load bcm4500 firmware.");
144 goto out_free; 162 goto out_free;
145 } 163 }
164 if (buflen > 64) {
165 err("firmare chunk size bigger than 64 bytes.");
166 goto out_free;
167 }
168
146 memcpy(buf, ptr, buflen); 169 memcpy(buf, ptr, buflen);
147 if (dvb_usb_generic_write(d, buf, buflen)) { 170 if (dvb_usb_generic_write(d, buf, buflen)) {
148 err("failed to load bcm4500 firmware."); 171 err("failed to load bcm4500 firmware.");
@@ -206,10 +229,13 @@ static int gp8psk_power_ctrl(struct dvb_usb_device *d, int onoff)
206 return 0; 229 return 0;
207} 230}
208 231
209int gp8psk_bcm4500_reload(struct dvb_usb_device *d) 232static int gp8psk_bcm4500_reload(struct dvb_usb_device *d)
210{ 233{
211 u8 buf; 234 u8 buf;
212 int gp_product_id = le16_to_cpu(d->udev->descriptor.idProduct); 235 int gp_product_id = le16_to_cpu(d->udev->descriptor.idProduct);
236
237 deb_xfer("reloading firmware\n");
238
213 /* Turn off 8psk power */ 239 /* Turn off 8psk power */
214 if (gp8psk_usb_in_op(d, BOOT_8PSK, 0, 0, &buf, 1)) 240 if (gp8psk_usb_in_op(d, BOOT_8PSK, 0, 0, &buf, 1))
215 return -EINVAL; 241 return -EINVAL;
@@ -228,9 +254,47 @@ static int gp8psk_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
228 return gp8psk_usb_out_op(adap->dev, ARM_TRANSFER, onoff, 0 , NULL, 0); 254 return gp8psk_usb_out_op(adap->dev, ARM_TRANSFER, onoff, 0 , NULL, 0);
229} 255}
230 256
257/* Callbacks for gp8psk-fe.c */
258
259static int gp8psk_fe_in(void *priv, u8 req, u16 value,
260 u16 index, u8 *b, int blen)
261{
262 struct dvb_usb_device *d = priv;
263
264 return gp8psk_usb_in_op(d, req, value, index, b, blen);
265}
266
267static int gp8psk_fe_out(void *priv, u8 req, u16 value,
268 u16 index, u8 *b, int blen)
269{
270 struct dvb_usb_device *d = priv;
271
272 return gp8psk_usb_out_op(d, req, value, index, b, blen);
273}
274
275static int gp8psk_fe_reload(void *priv)
276{
277 struct dvb_usb_device *d = priv;
278
279 return gp8psk_bcm4500_reload(d);
280}
281
282const struct gp8psk_fe_ops gp8psk_fe_ops = {
283 .in = gp8psk_fe_in,
284 .out = gp8psk_fe_out,
285 .reload = gp8psk_fe_reload,
286};
287
231static int gp8psk_frontend_attach(struct dvb_usb_adapter *adap) 288static int gp8psk_frontend_attach(struct dvb_usb_adapter *adap)
232{ 289{
233 adap->fe_adap[0].fe = gp8psk_fe_attach(adap->dev); 290 struct dvb_usb_device *d = adap->dev;
291 int id = le16_to_cpu(d->udev->descriptor.idProduct);
292 int is_rev1;
293
294 is_rev1 = (id == USB_PID_GENPIX_8PSK_REV_1_WARM) ? true : false;
295
296 adap->fe_adap[0].fe = dvb_attach(gp8psk_fe_attach,
297 &gp8psk_fe_ops, d, is_rev1);
234 return 0; 298 return 0;
235} 299}
236 300
@@ -265,6 +329,8 @@ static struct dvb_usb_device_properties gp8psk_properties = {
265 .usb_ctrl = CYPRESS_FX2, 329 .usb_ctrl = CYPRESS_FX2,
266 .firmware = "dvb-usb-gp8psk-01.fw", 330 .firmware = "dvb-usb-gp8psk-01.fw",
267 331
332 .size_of_priv = sizeof(struct gp8psk_state),
333
268 .num_adapters = 1, 334 .num_adapters = 1,
269 .adapter = { 335 .adapter = {
270 { 336 {
diff --git a/drivers/media/usb/dvb-usb/gp8psk.h b/drivers/media/usb/dvb-usb/gp8psk.h
index ed32b9da4843..d8975b866dee 100644
--- a/drivers/media/usb/dvb-usb/gp8psk.h
+++ b/drivers/media/usb/dvb-usb/gp8psk.h
@@ -24,58 +24,6 @@ extern int dvb_usb_gp8psk_debug;
24#define deb_info(args...) dprintk(dvb_usb_gp8psk_debug,0x01,args) 24#define deb_info(args...) dprintk(dvb_usb_gp8psk_debug,0x01,args)
25#define deb_xfer(args...) dprintk(dvb_usb_gp8psk_debug,0x02,args) 25#define deb_xfer(args...) dprintk(dvb_usb_gp8psk_debug,0x02,args)
26#define deb_rc(args...) dprintk(dvb_usb_gp8psk_debug,0x04,args) 26#define deb_rc(args...) dprintk(dvb_usb_gp8psk_debug,0x04,args)
27#define deb_fe(args...) dprintk(dvb_usb_gp8psk_debug,0x08,args)
28
29/* Twinhan Vendor requests */
30#define TH_COMMAND_IN 0xC0
31#define TH_COMMAND_OUT 0xC1
32
33/* gp8psk commands */
34
35#define GET_8PSK_CONFIG 0x80 /* in */
36#define SET_8PSK_CONFIG 0x81
37#define I2C_WRITE 0x83
38#define I2C_READ 0x84
39#define ARM_TRANSFER 0x85
40#define TUNE_8PSK 0x86
41#define GET_SIGNAL_STRENGTH 0x87 /* in */
42#define LOAD_BCM4500 0x88
43#define BOOT_8PSK 0x89 /* in */
44#define START_INTERSIL 0x8A /* in */
45#define SET_LNB_VOLTAGE 0x8B
46#define SET_22KHZ_TONE 0x8C
47#define SEND_DISEQC_COMMAND 0x8D
48#define SET_DVB_MODE 0x8E
49#define SET_DN_SWITCH 0x8F
50#define GET_SIGNAL_LOCK 0x90 /* in */
51#define GET_FW_VERS 0x92
52#define GET_SERIAL_NUMBER 0x93 /* in */
53#define USE_EXTRA_VOLT 0x94
54#define GET_FPGA_VERS 0x95
55#define CW3K_INIT 0x9d
56
57/* PSK_configuration bits */
58#define bm8pskStarted 0x01
59#define bm8pskFW_Loaded 0x02
60#define bmIntersilOn 0x04
61#define bmDVBmode 0x08
62#define bm22kHz 0x10
63#define bmSEL18V 0x20
64#define bmDCtuned 0x40
65#define bmArmed 0x80
66
67/* Satellite modulation modes */
68#define ADV_MOD_DVB_QPSK 0 /* DVB-S QPSK */
69#define ADV_MOD_TURBO_QPSK 1 /* Turbo QPSK */
70#define ADV_MOD_TURBO_8PSK 2 /* Turbo 8PSK (also used for Trellis 8PSK) */
71#define ADV_MOD_TURBO_16QAM 3 /* Turbo 16QAM (also used for Trellis 8PSK) */
72
73#define ADV_MOD_DCII_C_QPSK 4 /* Digicipher II Combo */
74#define ADV_MOD_DCII_I_QPSK 5 /* Digicipher II I-stream */
75#define ADV_MOD_DCII_Q_QPSK 6 /* Digicipher II Q-stream */
76#define ADV_MOD_DCII_C_OQPSK 7 /* Digicipher II offset QPSK */
77#define ADV_MOD_DSS_QPSK 8 /* DSS (DIRECTV) QPSK */
78#define ADV_MOD_DVB_BPSK 9 /* DVB-S BPSK */
79 27
80#define GET_USB_SPEED 0x07 28#define GET_USB_SPEED 0x07
81 29
@@ -86,15 +34,4 @@ extern int dvb_usb_gp8psk_debug;
86#define PRODUCT_STRING_READ 0x0D 34#define PRODUCT_STRING_READ 0x0D
87#define FW_BCD_VERSION_READ 0x14 35#define FW_BCD_VERSION_READ 0x14
88 36
89/* firmware revision id's */
90#define GP8PSK_FW_REV1 0x020604
91#define GP8PSK_FW_REV2 0x020704
92#define GP8PSK_FW_VERS(_fw_vers) ((_fw_vers)[2]<<0x10 | (_fw_vers)[1]<<0x08 | (_fw_vers)[0])
93
94extern struct dvb_frontend * gp8psk_fe_attach(struct dvb_usb_device *d);
95extern int gp8psk_usb_in_op(struct dvb_usb_device *d, u8 req, u16 value, u16 index, u8 *b, int blen);
96extern int gp8psk_usb_out_op(struct dvb_usb_device *d, u8 req, u16 value,
97 u16 index, u8 *b, int blen);
98extern int gp8psk_bcm4500_reload(struct dvb_usb_device *d);
99
100#endif 37#endif
diff --git a/drivers/media/usb/dvb-usb/nova-t-usb2.c b/drivers/media/usb/dvb-usb/nova-t-usb2.c
index fc7569e2728d..1babd3341910 100644
--- a/drivers/media/usb/dvb-usb/nova-t-usb2.c
+++ b/drivers/media/usb/dvb-usb/nova-t-usb2.c
@@ -74,22 +74,31 @@ static struct rc_map_table rc_map_haupp_table[] = {
74 */ 74 */
75static int nova_t_rc_query(struct dvb_usb_device *d, u32 *event, int *state) 75static int nova_t_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
76{ 76{
77 u8 key[5],cmd[2] = { DIBUSB_REQ_POLL_REMOTE, 0x35 }, data,toggle,custom; 77 u8 *buf, data, toggle, custom;
78 u16 raw; 78 u16 raw;
79 int i; 79 int i, ret;
80 struct dibusb_device_state *st = d->priv; 80 struct dibusb_device_state *st = d->priv;
81 81
82 dvb_usb_generic_rw(d,cmd,2,key,5,0); 82 buf = kmalloc(5, GFP_KERNEL);
83 if (!buf)
84 return -ENOMEM;
85
86 buf[0] = DIBUSB_REQ_POLL_REMOTE;
87 buf[1] = 0x35;
88 ret = dvb_usb_generic_rw(d, buf, 2, buf, 5, 0);
89 if (ret < 0)
90 goto ret;
83 91
84 *state = REMOTE_NO_KEY_PRESSED; 92 *state = REMOTE_NO_KEY_PRESSED;
85 switch (key[0]) { 93 switch (buf[0]) {
86 case DIBUSB_RC_HAUPPAUGE_KEY_PRESSED: 94 case DIBUSB_RC_HAUPPAUGE_KEY_PRESSED:
87 raw = ((key[1] << 8) | key[2]) >> 3; 95 raw = ((buf[1] << 8) | buf[2]) >> 3;
88 toggle = !!(raw & 0x800); 96 toggle = !!(raw & 0x800);
89 data = raw & 0x3f; 97 data = raw & 0x3f;
90 custom = (raw >> 6) & 0x1f; 98 custom = (raw >> 6) & 0x1f;
91 99
92 deb_rc("raw key code 0x%02x, 0x%02x, 0x%02x to c: %02x d: %02x toggle: %d\n",key[1],key[2],key[3],custom,data,toggle); 100 deb_rc("raw key code 0x%02x, 0x%02x, 0x%02x to c: %02x d: %02x toggle: %d\n",
101 buf[1], buf[2], buf[3], custom, data, toggle);
93 102
94 for (i = 0; i < ARRAY_SIZE(rc_map_haupp_table); i++) { 103 for (i = 0; i < ARRAY_SIZE(rc_map_haupp_table); i++) {
95 if (rc5_data(&rc_map_haupp_table[i]) == data && 104 if (rc5_data(&rc_map_haupp_table[i]) == data &&
@@ -117,7 +126,9 @@ static int nova_t_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
117 break; 126 break;
118 } 127 }
119 128
120 return 0; 129ret:
130 kfree(buf);
131 return ret;
121} 132}
122 133
123static int nova_t_read_mac_address (struct dvb_usb_device *d, u8 mac[6]) 134static int nova_t_read_mac_address (struct dvb_usb_device *d, u8 mac[6])
diff --git a/drivers/media/usb/dvb-usb/pctv452e.c b/drivers/media/usb/dvb-usb/pctv452e.c
index c05de1b088a4..07fa08be9e99 100644
--- a/drivers/media/usb/dvb-usb/pctv452e.c
+++ b/drivers/media/usb/dvb-usb/pctv452e.c
@@ -97,48 +97,53 @@ struct pctv452e_state {
97 u8 c; /* transaction counter, wraps around... */ 97 u8 c; /* transaction counter, wraps around... */
98 u8 initialized; /* set to 1 if 0x15 has been sent */ 98 u8 initialized; /* set to 1 if 0x15 has been sent */
99 u16 last_rc_key; 99 u16 last_rc_key;
100
101 unsigned char data[80];
100}; 102};
101 103
102static int tt3650_ci_msg(struct dvb_usb_device *d, u8 cmd, u8 *data, 104static int tt3650_ci_msg(struct dvb_usb_device *d, u8 cmd, u8 *data,
103 unsigned int write_len, unsigned int read_len) 105 unsigned int write_len, unsigned int read_len)
104{ 106{
105 struct pctv452e_state *state = (struct pctv452e_state *)d->priv; 107 struct pctv452e_state *state = (struct pctv452e_state *)d->priv;
106 u8 buf[64];
107 u8 id; 108 u8 id;
108 unsigned int rlen; 109 unsigned int rlen;
109 int ret; 110 int ret;
110 111
111 BUG_ON(NULL == data && 0 != (write_len | read_len)); 112 if (!data || (write_len > 64 - 4) || (read_len > 64 - 4)) {
112 BUG_ON(write_len > 64 - 4); 113 err("%s: transfer data invalid", __func__);
113 BUG_ON(read_len > 64 - 4); 114 return -EIO;
115 }
114 116
117 mutex_lock(&state->ca_mutex);
115 id = state->c++; 118 id = state->c++;
116 119
117 buf[0] = SYNC_BYTE_OUT; 120 state->data[0] = SYNC_BYTE_OUT;
118 buf[1] = id; 121 state->data[1] = id;
119 buf[2] = cmd; 122 state->data[2] = cmd;
120 buf[3] = write_len; 123 state->data[3] = write_len;
121 124
122 memcpy(buf + 4, data, write_len); 125 memcpy(state->data + 4, data, write_len);
123 126
124 rlen = (read_len > 0) ? 64 : 0; 127 rlen = (read_len > 0) ? 64 : 0;
125 ret = dvb_usb_generic_rw(d, buf, 4 + write_len, 128 ret = dvb_usb_generic_rw(d, state->data, 4 + write_len,
126 buf, rlen, /* delay_ms */ 0); 129 state->data, rlen, /* delay_ms */ 0);
127 if (0 != ret) 130 if (0 != ret)
128 goto failed; 131 goto failed;
129 132
130 ret = -EIO; 133 ret = -EIO;
131 if (SYNC_BYTE_IN != buf[0] || id != buf[1]) 134 if (SYNC_BYTE_IN != state->data[0] || id != state->data[1])
132 goto failed; 135 goto failed;
133 136
134 memcpy(data, buf + 4, read_len); 137 memcpy(data, state->data + 4, read_len);
135 138
139 mutex_unlock(&state->ca_mutex);
136 return 0; 140 return 0;
137 141
138failed: 142failed:
139 err("CI error %d; %02X %02X %02X -> %*ph.", 143 err("CI error %d; %02X %02X %02X -> %*ph.",
140 ret, SYNC_BYTE_OUT, id, cmd, 3, buf); 144 ret, SYNC_BYTE_OUT, id, cmd, 3, state->data);
141 145
146 mutex_unlock(&state->ca_mutex);
142 return ret; 147 return ret;
143} 148}
144 149
@@ -405,52 +410,53 @@ static int pctv452e_i2c_msg(struct dvb_usb_device *d, u8 addr,
405 u8 *rcv_buf, u8 rcv_len) 410 u8 *rcv_buf, u8 rcv_len)
406{ 411{
407 struct pctv452e_state *state = (struct pctv452e_state *)d->priv; 412 struct pctv452e_state *state = (struct pctv452e_state *)d->priv;
408 u8 buf[64];
409 u8 id; 413 u8 id;
410 int ret; 414 int ret;
411 415
416 mutex_lock(&state->ca_mutex);
412 id = state->c++; 417 id = state->c++;
413 418
414 ret = -EINVAL; 419 ret = -EINVAL;
415 if (snd_len > 64 - 7 || rcv_len > 64 - 7) 420 if (snd_len > 64 - 7 || rcv_len > 64 - 7)
416 goto failed; 421 goto failed;
417 422
418 buf[0] = SYNC_BYTE_OUT; 423 state->data[0] = SYNC_BYTE_OUT;
419 buf[1] = id; 424 state->data[1] = id;
420 buf[2] = PCTV_CMD_I2C; 425 state->data[2] = PCTV_CMD_I2C;
421 buf[3] = snd_len + 3; 426 state->data[3] = snd_len + 3;
422 buf[4] = addr << 1; 427 state->data[4] = addr << 1;
423 buf[5] = snd_len; 428 state->data[5] = snd_len;
424 buf[6] = rcv_len; 429 state->data[6] = rcv_len;
425 430
426 memcpy(buf + 7, snd_buf, snd_len); 431 memcpy(state->data + 7, snd_buf, snd_len);
427 432
428 ret = dvb_usb_generic_rw(d, buf, 7 + snd_len, 433 ret = dvb_usb_generic_rw(d, state->data, 7 + snd_len,
429 buf, /* rcv_len */ 64, 434 state->data, /* rcv_len */ 64,
430 /* delay_ms */ 0); 435 /* delay_ms */ 0);
431 if (ret < 0) 436 if (ret < 0)
432 goto failed; 437 goto failed;
433 438
434 /* TT USB protocol error. */ 439 /* TT USB protocol error. */
435 ret = -EIO; 440 ret = -EIO;
436 if (SYNC_BYTE_IN != buf[0] || id != buf[1]) 441 if (SYNC_BYTE_IN != state->data[0] || id != state->data[1])
437 goto failed; 442 goto failed;
438 443
439 /* I2C device didn't respond as expected. */ 444 /* I2C device didn't respond as expected. */
440 ret = -EREMOTEIO; 445 ret = -EREMOTEIO;
441 if (buf[5] < snd_len || buf[6] < rcv_len) 446 if (state->data[5] < snd_len || state->data[6] < rcv_len)
442 goto failed; 447 goto failed;
443 448
444 memcpy(rcv_buf, buf + 7, rcv_len); 449 memcpy(rcv_buf, state->data + 7, rcv_len);
450 mutex_unlock(&state->ca_mutex);
445 451
446 return rcv_len; 452 return rcv_len;
447 453
448failed: 454failed:
449 err("I2C error %d; %02X %02X %02X %02X %02X -> " 455 err("I2C error %d; %02X %02X %02X %02X %02X -> %*ph",
450 "%02X %02X %02X %02X %02X.",
451 ret, SYNC_BYTE_OUT, id, addr << 1, snd_len, rcv_len, 456 ret, SYNC_BYTE_OUT, id, addr << 1, snd_len, rcv_len,
452 buf[0], buf[1], buf[4], buf[5], buf[6]); 457 7, state->data);
453 458
459 mutex_unlock(&state->ca_mutex);
454 return ret; 460 return ret;
455} 461}
456 462
@@ -499,8 +505,7 @@ static u32 pctv452e_i2c_func(struct i2c_adapter *adapter)
499static int pctv452e_power_ctrl(struct dvb_usb_device *d, int i) 505static int pctv452e_power_ctrl(struct dvb_usb_device *d, int i)
500{ 506{
501 struct pctv452e_state *state = (struct pctv452e_state *)d->priv; 507 struct pctv452e_state *state = (struct pctv452e_state *)d->priv;
502 u8 b0[] = { 0xaa, 0, PCTV_CMD_RESET, 1, 0 }; 508 u8 *rx;
503 u8 rx[PCTV_ANSWER_LEN];
504 int ret; 509 int ret;
505 510
506 info("%s: %d\n", __func__, i); 511 info("%s: %d\n", __func__, i);
@@ -511,6 +516,11 @@ static int pctv452e_power_ctrl(struct dvb_usb_device *d, int i)
511 if (state->initialized) 516 if (state->initialized)
512 return 0; 517 return 0;
513 518
519 rx = kmalloc(PCTV_ANSWER_LEN, GFP_KERNEL);
520 if (!rx)
521 return -ENOMEM;
522
523 mutex_lock(&state->ca_mutex);
514 /* hmm where shoud this should go? */ 524 /* hmm where shoud this should go? */
515 ret = usb_set_interface(d->udev, 0, ISOC_INTERFACE_ALTERNATIVE); 525 ret = usb_set_interface(d->udev, 0, ISOC_INTERFACE_ALTERNATIVE);
516 if (ret != 0) 526 if (ret != 0)
@@ -518,65 +528,75 @@ static int pctv452e_power_ctrl(struct dvb_usb_device *d, int i)
518 __func__, ret); 528 __func__, ret);
519 529
520 /* this is a one-time initialization, dont know where to put */ 530 /* this is a one-time initialization, dont know where to put */
521 b0[1] = state->c++; 531 state->data[0] = 0xaa;
532 state->data[1] = state->c++;
533 state->data[2] = PCTV_CMD_RESET;
534 state->data[3] = 1;
535 state->data[4] = 0;
522 /* reset board */ 536 /* reset board */
523 ret = dvb_usb_generic_rw(d, b0, sizeof(b0), rx, PCTV_ANSWER_LEN, 0); 537 ret = dvb_usb_generic_rw(d, state->data, 5, rx, PCTV_ANSWER_LEN, 0);
524 if (ret) 538 if (ret)
525 return ret; 539 goto ret;
526 540
527 b0[1] = state->c++; 541 state->data[1] = state->c++;
528 b0[4] = 1; 542 state->data[4] = 1;
529 /* reset board (again?) */ 543 /* reset board (again?) */
530 ret = dvb_usb_generic_rw(d, b0, sizeof(b0), rx, PCTV_ANSWER_LEN, 0); 544 ret = dvb_usb_generic_rw(d, state->data, 5, rx, PCTV_ANSWER_LEN, 0);
531 if (ret) 545 if (ret)
532 return ret; 546 goto ret;
533 547
534 state->initialized = 1; 548 state->initialized = 1;
535 549
536 return 0; 550ret:
551 mutex_unlock(&state->ca_mutex);
552 kfree(rx);
553 return ret;
537} 554}
538 555
539static int pctv452e_rc_query(struct dvb_usb_device *d) 556static int pctv452e_rc_query(struct dvb_usb_device *d)
540{ 557{
541 struct pctv452e_state *state = (struct pctv452e_state *)d->priv; 558 struct pctv452e_state *state = (struct pctv452e_state *)d->priv;
542 u8 b[CMD_BUFFER_SIZE];
543 u8 rx[PCTV_ANSWER_LEN];
544 int ret, i; 559 int ret, i;
545 u8 id = state->c++; 560 u8 id;
561
562 mutex_lock(&state->ca_mutex);
563 id = state->c++;
546 564
547 /* prepare command header */ 565 /* prepare command header */
548 b[0] = SYNC_BYTE_OUT; 566 state->data[0] = SYNC_BYTE_OUT;
549 b[1] = id; 567 state->data[1] = id;
550 b[2] = PCTV_CMD_IR; 568 state->data[2] = PCTV_CMD_IR;
551 b[3] = 0; 569 state->data[3] = 0;
552 570
553 /* send ir request */ 571 /* send ir request */
554 ret = dvb_usb_generic_rw(d, b, 4, rx, PCTV_ANSWER_LEN, 0); 572 ret = dvb_usb_generic_rw(d, state->data, 4,
573 state->data, PCTV_ANSWER_LEN, 0);
555 if (ret != 0) 574 if (ret != 0)
556 return ret; 575 goto ret;
557 576
558 if (debug > 3) { 577 if (debug > 3) {
559 info("%s: read: %2d: %*ph: ", __func__, ret, 3, rx); 578 info("%s: read: %2d: %*ph: ", __func__, ret, 3, state->data);
560 for (i = 0; (i < rx[3]) && ((i+3) < PCTV_ANSWER_LEN); i++) 579 for (i = 0; (i < state->data[3]) && ((i + 3) < PCTV_ANSWER_LEN); i++)
561 info(" %02x", rx[i+3]); 580 info(" %02x", state->data[i + 3]);
562 581
563 info("\n"); 582 info("\n");
564 } 583 }
565 584
566 if ((rx[3] == 9) && (rx[12] & 0x01)) { 585 if ((state->data[3] == 9) && (state->data[12] & 0x01)) {
567 /* got a "press" event */ 586 /* got a "press" event */
568 state->last_rc_key = RC_SCANCODE_RC5(rx[7], rx[6]); 587 state->last_rc_key = RC_SCANCODE_RC5(state->data[7], state->data[6]);
569 if (debug > 2) 588 if (debug > 2)
570 info("%s: cmd=0x%02x sys=0x%02x\n", 589 info("%s: cmd=0x%02x sys=0x%02x\n",
571 __func__, rx[6], rx[7]); 590 __func__, state->data[6], state->data[7]);
572 591
573 rc_keydown(d->rc_dev, RC_TYPE_RC5, state->last_rc_key, 0); 592 rc_keydown(d->rc_dev, RC_TYPE_RC5, state->last_rc_key, 0);
574 } else if (state->last_rc_key) { 593 } else if (state->last_rc_key) {
575 rc_keyup(d->rc_dev); 594 rc_keyup(d->rc_dev);
576 state->last_rc_key = 0; 595 state->last_rc_key = 0;
577 } 596 }
578 597ret:
579 return 0; 598 mutex_unlock(&state->ca_mutex);
599 return ret;
580} 600}
581 601
582static int pctv452e_read_mac_address(struct dvb_usb_device *d, u8 mac[6]) 602static int pctv452e_read_mac_address(struct dvb_usb_device *d, u8 mac[6])
diff --git a/drivers/media/usb/dvb-usb/technisat-usb2.c b/drivers/media/usb/dvb-usb/technisat-usb2.c
index d9f3262bf071..4706628a3ed5 100644
--- a/drivers/media/usb/dvb-usb/technisat-usb2.c
+++ b/drivers/media/usb/dvb-usb/technisat-usb2.c
@@ -89,9 +89,13 @@ struct technisat_usb2_state {
89static int technisat_usb2_i2c_access(struct usb_device *udev, 89static int technisat_usb2_i2c_access(struct usb_device *udev,
90 u8 device_addr, u8 *tx, u8 txlen, u8 *rx, u8 rxlen) 90 u8 device_addr, u8 *tx, u8 txlen, u8 *rx, u8 rxlen)
91{ 91{
92 u8 b[64]; 92 u8 *b;
93 int ret, actual_length; 93 int ret, actual_length;
94 94
95 b = kmalloc(64, GFP_KERNEL);
96 if (!b)
97 return -ENOMEM;
98
95 deb_i2c("i2c-access: %02x, tx: ", device_addr); 99 deb_i2c("i2c-access: %02x, tx: ", device_addr);
96 debug_dump(tx, txlen, deb_i2c); 100 debug_dump(tx, txlen, deb_i2c);
97 deb_i2c(" "); 101 deb_i2c(" ");
@@ -123,7 +127,7 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
123 127
124 if (ret < 0) { 128 if (ret < 0) {
125 err("i2c-error: out failed %02x = %d", device_addr, ret); 129 err("i2c-error: out failed %02x = %d", device_addr, ret);
126 return -ENODEV; 130 goto err;
127 } 131 }
128 132
129 ret = usb_bulk_msg(udev, 133 ret = usb_bulk_msg(udev,
@@ -131,7 +135,7 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
131 b, 64, &actual_length, 1000); 135 b, 64, &actual_length, 1000);
132 if (ret < 0) { 136 if (ret < 0) {
133 err("i2c-error: in failed %02x = %d", device_addr, ret); 137 err("i2c-error: in failed %02x = %d", device_addr, ret);
134 return -ENODEV; 138 goto err;
135 } 139 }
136 140
137 if (b[0] != I2C_STATUS_OK) { 141 if (b[0] != I2C_STATUS_OK) {
@@ -140,7 +144,7 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
140 if (!(b[0] == I2C_STATUS_NAK && 144 if (!(b[0] == I2C_STATUS_NAK &&
141 device_addr == 0x60 145 device_addr == 0x60
142 /* && device_is_technisat_usb2 */)) 146 /* && device_is_technisat_usb2 */))
143 return -ENODEV; 147 goto err;
144 } 148 }
145 149
146 deb_i2c("status: %d, ", b[0]); 150 deb_i2c("status: %d, ", b[0]);
@@ -154,7 +158,9 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
154 158
155 deb_i2c("\n"); 159 deb_i2c("\n");
156 160
157 return 0; 161err:
162 kfree(b);
163 return ret;
158} 164}
159 165
160static int technisat_usb2_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msg, 166static int technisat_usb2_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msg,
diff --git a/drivers/media/usb/s2255/s2255drv.c b/drivers/media/usb/s2255/s2255drv.c
index c3a0e87066eb..f7bb78c1873c 100644
--- a/drivers/media/usb/s2255/s2255drv.c
+++ b/drivers/media/usb/s2255/s2255drv.c
@@ -1901,19 +1901,30 @@ static long s2255_vendor_req(struct s2255_dev *dev, unsigned char Request,
1901 s32 TransferBufferLength, int bOut) 1901 s32 TransferBufferLength, int bOut)
1902{ 1902{
1903 int r; 1903 int r;
1904 unsigned char *buf;
1905
1906 buf = kmalloc(TransferBufferLength, GFP_KERNEL);
1907 if (!buf)
1908 return -ENOMEM;
1909
1904 if (!bOut) { 1910 if (!bOut) {
1905 r = usb_control_msg(dev->udev, usb_rcvctrlpipe(dev->udev, 0), 1911 r = usb_control_msg(dev->udev, usb_rcvctrlpipe(dev->udev, 0),
1906 Request, 1912 Request,
1907 USB_TYPE_VENDOR | USB_RECIP_DEVICE | 1913 USB_TYPE_VENDOR | USB_RECIP_DEVICE |
1908 USB_DIR_IN, 1914 USB_DIR_IN,
1909 Value, Index, TransferBuffer, 1915 Value, Index, buf,
1910 TransferBufferLength, HZ * 5); 1916 TransferBufferLength, HZ * 5);
1917
1918 if (r >= 0)
1919 memcpy(TransferBuffer, buf, TransferBufferLength);
1911 } else { 1920 } else {
1921 memcpy(buf, TransferBuffer, TransferBufferLength);
1912 r = usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, 0), 1922 r = usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, 0),
1913 Request, USB_TYPE_VENDOR | USB_RECIP_DEVICE, 1923 Request, USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1914 Value, Index, TransferBuffer, 1924 Value, Index, buf,
1915 TransferBufferLength, HZ * 5); 1925 TransferBufferLength, HZ * 5);
1916 } 1926 }
1927 kfree(buf);
1917 return r; 1928 return r;
1918} 1929}
1919 1930
diff --git a/drivers/media/usb/stkwebcam/stk-webcam.c b/drivers/media/usb/stkwebcam/stk-webcam.c
index db200c9d796d..22a9aae16291 100644
--- a/drivers/media/usb/stkwebcam/stk-webcam.c
+++ b/drivers/media/usb/stkwebcam/stk-webcam.c
@@ -147,20 +147,26 @@ int stk_camera_write_reg(struct stk_camera *dev, u16 index, u8 value)
147int stk_camera_read_reg(struct stk_camera *dev, u16 index, int *value) 147int stk_camera_read_reg(struct stk_camera *dev, u16 index, int *value)
148{ 148{
149 struct usb_device *udev = dev->udev; 149 struct usb_device *udev = dev->udev;
150 unsigned char *buf;
150 int ret; 151 int ret;
151 152
153 buf = kmalloc(sizeof(u8), GFP_KERNEL);
154 if (!buf)
155 return -ENOMEM;
156
152 ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), 157 ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
153 0x00, 158 0x00,
154 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 159 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
155 0x00, 160 0x00,
156 index, 161 index,
157 (u8 *) value, 162 buf,
158 sizeof(u8), 163 sizeof(u8),
159 500); 164 500);
160 if (ret < 0) 165 if (ret >= 0)
161 return ret; 166 memcpy(value, buf, sizeof(u8));
162 else 167
163 return 0; 168 kfree(buf);
169 return ret;
164} 170}
165 171
166static int stk_start_stream(struct stk_camera *dev) 172static int stk_start_stream(struct stk_camera *dev)
diff --git a/drivers/media/v4l2-core/videobuf-dma-sg.c b/drivers/media/v4l2-core/videobuf-dma-sg.c
index f300f060b3f3..1db0af6c7f94 100644
--- a/drivers/media/v4l2-core/videobuf-dma-sg.c
+++ b/drivers/media/v4l2-core/videobuf-dma-sg.c
@@ -156,6 +156,7 @@ static int videobuf_dma_init_user_locked(struct videobuf_dmabuf *dma,
156{ 156{
157 unsigned long first, last; 157 unsigned long first, last;
158 int err, rw = 0; 158 int err, rw = 0;
159 unsigned int flags = FOLL_FORCE;
159 160
160 dma->direction = direction; 161 dma->direction = direction;
161 switch (dma->direction) { 162 switch (dma->direction) {
@@ -178,12 +179,14 @@ static int videobuf_dma_init_user_locked(struct videobuf_dmabuf *dma,
178 if (NULL == dma->pages) 179 if (NULL == dma->pages)
179 return -ENOMEM; 180 return -ENOMEM;
180 181
182 if (rw == READ)
183 flags |= FOLL_WRITE;
184
181 dprintk(1, "init user [0x%lx+0x%lx => %d pages]\n", 185 dprintk(1, "init user [0x%lx+0x%lx => %d pages]\n",
182 data, size, dma->nr_pages); 186 data, size, dma->nr_pages);
183 187
184 err = get_user_pages(data & PAGE_MASK, dma->nr_pages, 188 err = get_user_pages(data & PAGE_MASK, dma->nr_pages,
185 rw == READ, 1, /* force */ 189 flags, dma->pages, NULL);
186 dma->pages, NULL);
187 190
188 if (err != dma->nr_pages) { 191 if (err != dma->nr_pages) {
189 dma->nr_pages = (err >= 0) ? err : 0; 192 dma->nr_pages = (err >= 0) ? err : 0;
diff --git a/drivers/media/v4l2-core/videobuf2-memops.c b/drivers/media/v4l2-core/videobuf2-memops.c
index 3c3b517f1d1c..1cd322e939c7 100644
--- a/drivers/media/v4l2-core/videobuf2-memops.c
+++ b/drivers/media/v4l2-core/videobuf2-memops.c
@@ -42,6 +42,10 @@ struct frame_vector *vb2_create_framevec(unsigned long start,
42 unsigned long first, last; 42 unsigned long first, last;
43 unsigned long nr; 43 unsigned long nr;
44 struct frame_vector *vec; 44 struct frame_vector *vec;
45 unsigned int flags = FOLL_FORCE;
46
47 if (write)
48 flags |= FOLL_WRITE;
45 49
46 first = start >> PAGE_SHIFT; 50 first = start >> PAGE_SHIFT;
47 last = (start + length - 1) >> PAGE_SHIFT; 51 last = (start + length - 1) >> PAGE_SHIFT;
@@ -49,7 +53,7 @@ struct frame_vector *vb2_create_framevec(unsigned long start,
49 vec = frame_vector_create(nr); 53 vec = frame_vector_create(nr);
50 if (!vec) 54 if (!vec)
51 return ERR_PTR(-ENOMEM); 55 return ERR_PTR(-ENOMEM);
52 ret = get_vaddr_frames(start & PAGE_MASK, nr, write, true, vec); 56 ret = get_vaddr_frames(start & PAGE_MASK, nr, flags, vec);
53 if (ret < 0) 57 if (ret < 0)
54 goto out_destroy; 58 goto out_destroy;
55 /* We accept only complete set of PFNs */ 59 /* We accept only complete set of PFNs */
diff --git a/drivers/memstick/host/rtsx_usb_ms.c b/drivers/memstick/host/rtsx_usb_ms.c
index d34bc3530385..2e3cf012ef48 100644
--- a/drivers/memstick/host/rtsx_usb_ms.c
+++ b/drivers/memstick/host/rtsx_usb_ms.c
@@ -524,6 +524,7 @@ static void rtsx_usb_ms_handle_req(struct work_struct *work)
524 int rc; 524 int rc;
525 525
526 if (!host->req) { 526 if (!host->req) {
527 pm_runtime_get_sync(ms_dev(host));
527 do { 528 do {
528 rc = memstick_next_req(msh, &host->req); 529 rc = memstick_next_req(msh, &host->req);
529 dev_dbg(ms_dev(host), "next req %d\n", rc); 530 dev_dbg(ms_dev(host), "next req %d\n", rc);
@@ -544,6 +545,7 @@ static void rtsx_usb_ms_handle_req(struct work_struct *work)
544 host->req->error); 545 host->req->error);
545 } 546 }
546 } while (!rc); 547 } while (!rc);
548 pm_runtime_put(ms_dev(host));
547 } 549 }
548 550
549} 551}
@@ -570,6 +572,7 @@ static int rtsx_usb_ms_set_param(struct memstick_host *msh,
570 dev_dbg(ms_dev(host), "%s: param = %d, value = %d\n", 572 dev_dbg(ms_dev(host), "%s: param = %d, value = %d\n",
571 __func__, param, value); 573 __func__, param, value);
572 574
575 pm_runtime_get_sync(ms_dev(host));
573 mutex_lock(&ucr->dev_mutex); 576 mutex_lock(&ucr->dev_mutex);
574 577
575 err = rtsx_usb_card_exclusive_check(ucr, RTSX_USB_MS_CARD); 578 err = rtsx_usb_card_exclusive_check(ucr, RTSX_USB_MS_CARD);
@@ -635,6 +638,7 @@ static int rtsx_usb_ms_set_param(struct memstick_host *msh,
635 } 638 }
636out: 639out:
637 mutex_unlock(&ucr->dev_mutex); 640 mutex_unlock(&ucr->dev_mutex);
641 pm_runtime_put(ms_dev(host));
638 642
639 /* power-on delay */ 643 /* power-on delay */
640 if (param == MEMSTICK_POWER && value == MEMSTICK_POWER_ON) 644 if (param == MEMSTICK_POWER && value == MEMSTICK_POWER_ON)
@@ -681,6 +685,7 @@ static int rtsx_usb_detect_ms_card(void *__host)
681 int err; 685 int err;
682 686
683 for (;;) { 687 for (;;) {
688 pm_runtime_get_sync(ms_dev(host));
684 mutex_lock(&ucr->dev_mutex); 689 mutex_lock(&ucr->dev_mutex);
685 690
686 /* Check pending MS card changes */ 691 /* Check pending MS card changes */
@@ -703,6 +708,7 @@ static int rtsx_usb_detect_ms_card(void *__host)
703 } 708 }
704 709
705poll_again: 710poll_again:
711 pm_runtime_put(ms_dev(host));
706 if (host->eject) 712 if (host->eject)
707 break; 713 break;
708 714
diff --git a/drivers/mfd/intel-lpss-pci.c b/drivers/mfd/intel-lpss-pci.c
index 3228fd182a99..9ff243970e93 100644
--- a/drivers/mfd/intel-lpss-pci.c
+++ b/drivers/mfd/intel-lpss-pci.c
@@ -123,19 +123,6 @@ static const struct intel_lpss_platform_info apl_i2c_info = {
123 .properties = apl_i2c_properties, 123 .properties = apl_i2c_properties,
124}; 124};
125 125
126static const struct intel_lpss_platform_info kbl_info = {
127 .clk_rate = 120000000,
128};
129
130static const struct intel_lpss_platform_info kbl_uart_info = {
131 .clk_rate = 120000000,
132 .clk_con_id = "baudclk",
133};
134
135static const struct intel_lpss_platform_info kbl_i2c_info = {
136 .clk_rate = 133000000,
137};
138
139static const struct pci_device_id intel_lpss_pci_ids[] = { 126static const struct pci_device_id intel_lpss_pci_ids[] = {
140 /* BXT A-Step */ 127 /* BXT A-Step */
141 { PCI_VDEVICE(INTEL, 0x0aac), (kernel_ulong_t)&bxt_i2c_info }, 128 { PCI_VDEVICE(INTEL, 0x0aac), (kernel_ulong_t)&bxt_i2c_info },
@@ -207,15 +194,15 @@ static const struct pci_device_id intel_lpss_pci_ids[] = {
207 { PCI_VDEVICE(INTEL, 0xa161), (kernel_ulong_t)&spt_i2c_info }, 194 { PCI_VDEVICE(INTEL, 0xa161), (kernel_ulong_t)&spt_i2c_info },
208 { PCI_VDEVICE(INTEL, 0xa166), (kernel_ulong_t)&spt_uart_info }, 195 { PCI_VDEVICE(INTEL, 0xa166), (kernel_ulong_t)&spt_uart_info },
209 /* KBL-H */ 196 /* KBL-H */
210 { PCI_VDEVICE(INTEL, 0xa2a7), (kernel_ulong_t)&kbl_uart_info }, 197 { PCI_VDEVICE(INTEL, 0xa2a7), (kernel_ulong_t)&spt_uart_info },
211 { PCI_VDEVICE(INTEL, 0xa2a8), (kernel_ulong_t)&kbl_uart_info }, 198 { PCI_VDEVICE(INTEL, 0xa2a8), (kernel_ulong_t)&spt_uart_info },
212 { PCI_VDEVICE(INTEL, 0xa2a9), (kernel_ulong_t)&kbl_info }, 199 { PCI_VDEVICE(INTEL, 0xa2a9), (kernel_ulong_t)&spt_info },
213 { PCI_VDEVICE(INTEL, 0xa2aa), (kernel_ulong_t)&kbl_info }, 200 { PCI_VDEVICE(INTEL, 0xa2aa), (kernel_ulong_t)&spt_info },
214 { PCI_VDEVICE(INTEL, 0xa2e0), (kernel_ulong_t)&kbl_i2c_info }, 201 { PCI_VDEVICE(INTEL, 0xa2e0), (kernel_ulong_t)&spt_i2c_info },
215 { PCI_VDEVICE(INTEL, 0xa2e1), (kernel_ulong_t)&kbl_i2c_info }, 202 { PCI_VDEVICE(INTEL, 0xa2e1), (kernel_ulong_t)&spt_i2c_info },
216 { PCI_VDEVICE(INTEL, 0xa2e2), (kernel_ulong_t)&kbl_i2c_info }, 203 { PCI_VDEVICE(INTEL, 0xa2e2), (kernel_ulong_t)&spt_i2c_info },
217 { PCI_VDEVICE(INTEL, 0xa2e3), (kernel_ulong_t)&kbl_i2c_info }, 204 { PCI_VDEVICE(INTEL, 0xa2e3), (kernel_ulong_t)&spt_i2c_info },
218 { PCI_VDEVICE(INTEL, 0xa2e6), (kernel_ulong_t)&kbl_uart_info }, 205 { PCI_VDEVICE(INTEL, 0xa2e6), (kernel_ulong_t)&spt_uart_info },
219 { } 206 { }
220}; 207};
221MODULE_DEVICE_TABLE(pci, intel_lpss_pci_ids); 208MODULE_DEVICE_TABLE(pci, intel_lpss_pci_ids);
diff --git a/drivers/mfd/intel-lpss.c b/drivers/mfd/intel-lpss.c
index 41b113875d64..70c646b0097d 100644
--- a/drivers/mfd/intel-lpss.c
+++ b/drivers/mfd/intel-lpss.c
@@ -502,9 +502,6 @@ int intel_lpss_suspend(struct device *dev)
502 for (i = 0; i < LPSS_PRIV_REG_COUNT; i++) 502 for (i = 0; i < LPSS_PRIV_REG_COUNT; i++)
503 lpss->priv_ctx[i] = readl(lpss->priv + i * 4); 503 lpss->priv_ctx[i] = readl(lpss->priv + i * 4);
504 504
505 /* Put the device into reset state */
506 writel(0, lpss->priv + LPSS_PRIV_RESETS);
507
508 return 0; 505 return 0;
509} 506}
510EXPORT_SYMBOL_GPL(intel_lpss_suspend); 507EXPORT_SYMBOL_GPL(intel_lpss_suspend);
diff --git a/drivers/mfd/intel_soc_pmic_bxtwc.c b/drivers/mfd/intel_soc_pmic_bxtwc.c
index 43e54b7e908f..f9a8c5203873 100644
--- a/drivers/mfd/intel_soc_pmic_bxtwc.c
+++ b/drivers/mfd/intel_soc_pmic_bxtwc.c
@@ -86,6 +86,7 @@ enum bxtwc_irqs_level2 {
86 BXTWC_THRM2_IRQ, 86 BXTWC_THRM2_IRQ,
87 BXTWC_BCU_IRQ, 87 BXTWC_BCU_IRQ,
88 BXTWC_ADC_IRQ, 88 BXTWC_ADC_IRQ,
89 BXTWC_USBC_IRQ,
89 BXTWC_CHGR0_IRQ, 90 BXTWC_CHGR0_IRQ,
90 BXTWC_CHGR1_IRQ, 91 BXTWC_CHGR1_IRQ,
91 BXTWC_GPIO0_IRQ, 92 BXTWC_GPIO0_IRQ,
@@ -111,7 +112,8 @@ static const struct regmap_irq bxtwc_regmap_irqs_level2[] = {
111 REGMAP_IRQ_REG(BXTWC_THRM2_IRQ, 2, 0xff), 112 REGMAP_IRQ_REG(BXTWC_THRM2_IRQ, 2, 0xff),
112 REGMAP_IRQ_REG(BXTWC_BCU_IRQ, 3, 0x1f), 113 REGMAP_IRQ_REG(BXTWC_BCU_IRQ, 3, 0x1f),
113 REGMAP_IRQ_REG(BXTWC_ADC_IRQ, 4, 0xff), 114 REGMAP_IRQ_REG(BXTWC_ADC_IRQ, 4, 0xff),
114 REGMAP_IRQ_REG(BXTWC_CHGR0_IRQ, 5, 0x3f), 115 REGMAP_IRQ_REG(BXTWC_USBC_IRQ, 5, BIT(5)),
116 REGMAP_IRQ_REG(BXTWC_CHGR0_IRQ, 5, 0x1f),
115 REGMAP_IRQ_REG(BXTWC_CHGR1_IRQ, 6, 0x1f), 117 REGMAP_IRQ_REG(BXTWC_CHGR1_IRQ, 6, 0x1f),
116 REGMAP_IRQ_REG(BXTWC_GPIO0_IRQ, 7, 0xff), 118 REGMAP_IRQ_REG(BXTWC_GPIO0_IRQ, 7, 0xff),
117 REGMAP_IRQ_REG(BXTWC_GPIO1_IRQ, 8, 0x3f), 119 REGMAP_IRQ_REG(BXTWC_GPIO1_IRQ, 8, 0x3f),
@@ -146,7 +148,7 @@ static struct resource adc_resources[] = {
146}; 148};
147 149
148static struct resource usbc_resources[] = { 150static struct resource usbc_resources[] = {
149 DEFINE_RES_IRQ_NAMED(BXTWC_CHGR0_IRQ, "USBC"), 151 DEFINE_RES_IRQ(BXTWC_USBC_IRQ),
150}; 152};
151 153
152static struct resource charger_resources[] = { 154static struct resource charger_resources[] = {
diff --git a/drivers/mfd/mfd-core.c b/drivers/mfd/mfd-core.c
index 3ac486a597f3..c57e407020f1 100644
--- a/drivers/mfd/mfd-core.c
+++ b/drivers/mfd/mfd-core.c
@@ -399,6 +399,8 @@ int mfd_clone_cell(const char *cell, const char **clones, size_t n_clones)
399 clones[i]); 399 clones[i]);
400 } 400 }
401 401
402 put_device(dev);
403
402 return 0; 404 return 0;
403} 405}
404EXPORT_SYMBOL(mfd_clone_cell); 406EXPORT_SYMBOL(mfd_clone_cell);
diff --git a/drivers/mfd/stmpe.c b/drivers/mfd/stmpe.c
index cfdae8a3d779..b0c7bcdaf5df 100644
--- a/drivers/mfd/stmpe.c
+++ b/drivers/mfd/stmpe.c
@@ -851,6 +851,8 @@ static int stmpe_reset(struct stmpe *stmpe)
851 if (ret < 0) 851 if (ret < 0)
852 return ret; 852 return ret;
853 853
854 msleep(10);
855
854 timeout = jiffies + msecs_to_jiffies(100); 856 timeout = jiffies + msecs_to_jiffies(100);
855 while (time_before(jiffies, timeout)) { 857 while (time_before(jiffies, timeout)) {
856 ret = __stmpe_reg_read(stmpe, stmpe->regs[STMPE_IDX_SYS_CTRL]); 858 ret = __stmpe_reg_read(stmpe, stmpe->regs[STMPE_IDX_SYS_CTRL]);
diff --git a/drivers/mfd/syscon.c b/drivers/mfd/syscon.c
index 2f2225e845ef..b93fe4c4957a 100644
--- a/drivers/mfd/syscon.c
+++ b/drivers/mfd/syscon.c
@@ -73,8 +73,10 @@ static struct syscon *of_syscon_register(struct device_node *np)
73 /* Parse the device's DT node for an endianness specification */ 73 /* Parse the device's DT node for an endianness specification */
74 if (of_property_read_bool(np, "big-endian")) 74 if (of_property_read_bool(np, "big-endian"))
75 syscon_config.val_format_endian = REGMAP_ENDIAN_BIG; 75 syscon_config.val_format_endian = REGMAP_ENDIAN_BIG;
76 else if (of_property_read_bool(np, "little-endian")) 76 else if (of_property_read_bool(np, "little-endian"))
77 syscon_config.val_format_endian = REGMAP_ENDIAN_LITTLE; 77 syscon_config.val_format_endian = REGMAP_ENDIAN_LITTLE;
78 else if (of_property_read_bool(np, "native-endian"))
79 syscon_config.val_format_endian = REGMAP_ENDIAN_NATIVE;
78 80
79 /* 81 /*
80 * search for reg-io-width property in DT. If it is not provided, 82 * search for reg-io-width property in DT. If it is not provided,
diff --git a/drivers/mfd/wm8994-core.c b/drivers/mfd/wm8994-core.c
index 7eec619a6023..8588dbad3301 100644
--- a/drivers/mfd/wm8994-core.c
+++ b/drivers/mfd/wm8994-core.c
@@ -393,8 +393,13 @@ static int wm8994_device_init(struct wm8994 *wm8994, int irq)
393 BUG(); 393 BUG();
394 goto err; 394 goto err;
395 } 395 }
396 396
397 ret = devm_regulator_bulk_get(wm8994->dev, wm8994->num_supplies, 397 /*
398 * Can't use devres helper here as some of the supplies are provided by
399 * wm8994->dev's children (regulators) and those regulators are
400 * unregistered by the devres core before the supplies are freed.
401 */
402 ret = regulator_bulk_get(wm8994->dev, wm8994->num_supplies,
398 wm8994->supplies); 403 wm8994->supplies);
399 if (ret != 0) { 404 if (ret != 0) {
400 dev_err(wm8994->dev, "Failed to get supplies: %d\n", ret); 405 dev_err(wm8994->dev, "Failed to get supplies: %d\n", ret);
@@ -405,7 +410,7 @@ static int wm8994_device_init(struct wm8994 *wm8994, int irq)
405 wm8994->supplies); 410 wm8994->supplies);
406 if (ret != 0) { 411 if (ret != 0) {
407 dev_err(wm8994->dev, "Failed to enable supplies: %d\n", ret); 412 dev_err(wm8994->dev, "Failed to enable supplies: %d\n", ret);
408 goto err; 413 goto err_regulator_free;
409 } 414 }
410 415
411 ret = wm8994_reg_read(wm8994, WM8994_SOFTWARE_RESET); 416 ret = wm8994_reg_read(wm8994, WM8994_SOFTWARE_RESET);
@@ -596,6 +601,8 @@ err_irq:
596err_enable: 601err_enable:
597 regulator_bulk_disable(wm8994->num_supplies, 602 regulator_bulk_disable(wm8994->num_supplies,
598 wm8994->supplies); 603 wm8994->supplies);
604err_regulator_free:
605 regulator_bulk_free(wm8994->num_supplies, wm8994->supplies);
599err: 606err:
600 mfd_remove_devices(wm8994->dev); 607 mfd_remove_devices(wm8994->dev);
601 return ret; 608 return ret;
@@ -604,10 +611,11 @@ err:
604static void wm8994_device_exit(struct wm8994 *wm8994) 611static void wm8994_device_exit(struct wm8994 *wm8994)
605{ 612{
606 pm_runtime_disable(wm8994->dev); 613 pm_runtime_disable(wm8994->dev);
607 mfd_remove_devices(wm8994->dev);
608 wm8994_irq_exit(wm8994); 614 wm8994_irq_exit(wm8994);
609 regulator_bulk_disable(wm8994->num_supplies, 615 regulator_bulk_disable(wm8994->num_supplies,
610 wm8994->supplies); 616 wm8994->supplies);
617 regulator_bulk_free(wm8994->num_supplies, wm8994->supplies);
618 mfd_remove_devices(wm8994->dev);
611} 619}
612 620
613static const struct of_device_id wm8994_of_match[] = { 621static const struct of_device_id wm8994_of_match[] = {
diff --git a/drivers/misc/cxl/api.c b/drivers/misc/cxl/api.c
index f3d34b941f85..2e5233b60971 100644
--- a/drivers/misc/cxl/api.c
+++ b/drivers/misc/cxl/api.c
@@ -229,6 +229,14 @@ int cxl_start_context(struct cxl_context *ctx, u64 wed,
229 if (ctx->status == STARTED) 229 if (ctx->status == STARTED)
230 goto out; /* already started */ 230 goto out; /* already started */
231 231
232 /*
233 * Increment the mapped context count for adapter. This also checks
234 * if adapter_context_lock is taken.
235 */
236 rc = cxl_adapter_context_get(ctx->afu->adapter);
237 if (rc)
238 goto out;
239
232 if (task) { 240 if (task) {
233 ctx->pid = get_task_pid(task, PIDTYPE_PID); 241 ctx->pid = get_task_pid(task, PIDTYPE_PID);
234 ctx->glpid = get_task_pid(task->group_leader, PIDTYPE_PID); 242 ctx->glpid = get_task_pid(task->group_leader, PIDTYPE_PID);
@@ -239,7 +247,10 @@ int cxl_start_context(struct cxl_context *ctx, u64 wed,
239 cxl_ctx_get(); 247 cxl_ctx_get();
240 248
241 if ((rc = cxl_ops->attach_process(ctx, kernel, wed, 0))) { 249 if ((rc = cxl_ops->attach_process(ctx, kernel, wed, 0))) {
250 put_pid(ctx->glpid);
242 put_pid(ctx->pid); 251 put_pid(ctx->pid);
252 ctx->glpid = ctx->pid = NULL;
253 cxl_adapter_context_put(ctx->afu->adapter);
243 cxl_ctx_put(); 254 cxl_ctx_put();
244 goto out; 255 goto out;
245 } 256 }
diff --git a/drivers/misc/cxl/context.c b/drivers/misc/cxl/context.c
index c466ee2b0c97..5e506c19108a 100644
--- a/drivers/misc/cxl/context.c
+++ b/drivers/misc/cxl/context.c
@@ -238,6 +238,9 @@ int __detach_context(struct cxl_context *ctx)
238 put_pid(ctx->glpid); 238 put_pid(ctx->glpid);
239 239
240 cxl_ctx_put(); 240 cxl_ctx_put();
241
242 /* Decrease the attached context count on the adapter */
243 cxl_adapter_context_put(ctx->afu->adapter);
241 return 0; 244 return 0;
242} 245}
243 246
diff --git a/drivers/misc/cxl/cxl.h b/drivers/misc/cxl/cxl.h
index 01d372aba131..a144073593fa 100644
--- a/drivers/misc/cxl/cxl.h
+++ b/drivers/misc/cxl/cxl.h
@@ -618,6 +618,14 @@ struct cxl {
618 bool perst_select_user; 618 bool perst_select_user;
619 bool perst_same_image; 619 bool perst_same_image;
620 bool psl_timebase_synced; 620 bool psl_timebase_synced;
621
622 /*
623 * number of contexts mapped on to this card. Possible values are:
624 * >0: Number of contexts mapped and new one can be mapped.
625 * 0: No active contexts and new ones can be mapped.
626 * -1: No contexts mapped and new ones cannot be mapped.
627 */
628 atomic_t contexts_num;
621}; 629};
622 630
623int cxl_pci_alloc_one_irq(struct cxl *adapter); 631int cxl_pci_alloc_one_irq(struct cxl *adapter);
@@ -944,4 +952,20 @@ bool cxl_pci_is_vphb_device(struct pci_dev *dev);
944 952
945/* decode AFU error bits in the PSL register PSL_SERR_An */ 953/* decode AFU error bits in the PSL register PSL_SERR_An */
946void cxl_afu_decode_psl_serr(struct cxl_afu *afu, u64 serr); 954void cxl_afu_decode_psl_serr(struct cxl_afu *afu, u64 serr);
955
956/*
957 * Increments the number of attached contexts on an adapter.
958 * In case an adapter_context_lock is taken the return -EBUSY.
959 */
960int cxl_adapter_context_get(struct cxl *adapter);
961
962/* Decrements the number of attached contexts on an adapter */
963void cxl_adapter_context_put(struct cxl *adapter);
964
965/* If no active contexts then prevents contexts from being attached */
966int cxl_adapter_context_lock(struct cxl *adapter);
967
968/* Unlock the contexts-lock if taken. Warn and force unlock otherwise */
969void cxl_adapter_context_unlock(struct cxl *adapter);
970
947#endif 971#endif
diff --git a/drivers/misc/cxl/file.c b/drivers/misc/cxl/file.c
index 5fb9894b157f..77080cc5fa0a 100644
--- a/drivers/misc/cxl/file.c
+++ b/drivers/misc/cxl/file.c
@@ -194,6 +194,16 @@ static long afu_ioctl_start_work(struct cxl_context *ctx,
194 ctx->mmio_err_ff = !!(work.flags & CXL_START_WORK_ERR_FF); 194 ctx->mmio_err_ff = !!(work.flags & CXL_START_WORK_ERR_FF);
195 195
196 /* 196 /*
197 * Increment the mapped context count for adapter. This also checks
198 * if adapter_context_lock is taken.
199 */
200 rc = cxl_adapter_context_get(ctx->afu->adapter);
201 if (rc) {
202 afu_release_irqs(ctx, ctx);
203 goto out;
204 }
205
206 /*
197 * We grab the PID here and not in the file open to allow for the case 207 * We grab the PID here and not in the file open to allow for the case
198 * where a process (master, some daemon, etc) has opened the chardev on 208 * where a process (master, some daemon, etc) has opened the chardev on
199 * behalf of another process, so the AFU's mm gets bound to the process 209 * behalf of another process, so the AFU's mm gets bound to the process
@@ -205,11 +215,16 @@ static long afu_ioctl_start_work(struct cxl_context *ctx,
205 ctx->pid = get_task_pid(current, PIDTYPE_PID); 215 ctx->pid = get_task_pid(current, PIDTYPE_PID);
206 ctx->glpid = get_task_pid(current->group_leader, PIDTYPE_PID); 216 ctx->glpid = get_task_pid(current->group_leader, PIDTYPE_PID);
207 217
218
208 trace_cxl_attach(ctx, work.work_element_descriptor, work.num_interrupts, amr); 219 trace_cxl_attach(ctx, work.work_element_descriptor, work.num_interrupts, amr);
209 220
210 if ((rc = cxl_ops->attach_process(ctx, false, work.work_element_descriptor, 221 if ((rc = cxl_ops->attach_process(ctx, false, work.work_element_descriptor,
211 amr))) { 222 amr))) {
212 afu_release_irqs(ctx, ctx); 223 afu_release_irqs(ctx, ctx);
224 cxl_adapter_context_put(ctx->afu->adapter);
225 put_pid(ctx->glpid);
226 put_pid(ctx->pid);
227 ctx->glpid = ctx->pid = NULL;
213 goto out; 228 goto out;
214 } 229 }
215 230
diff --git a/drivers/misc/cxl/guest.c b/drivers/misc/cxl/guest.c
index 9aa58a77a24d..3e102cd6ed91 100644
--- a/drivers/misc/cxl/guest.c
+++ b/drivers/misc/cxl/guest.c
@@ -1152,6 +1152,9 @@ struct cxl *cxl_guest_init_adapter(struct device_node *np, struct platform_devic
1152 if ((rc = cxl_sysfs_adapter_add(adapter))) 1152 if ((rc = cxl_sysfs_adapter_add(adapter)))
1153 goto err_put1; 1153 goto err_put1;
1154 1154
1155 /* release the context lock as the adapter is configured */
1156 cxl_adapter_context_unlock(adapter);
1157
1155 return adapter; 1158 return adapter;
1156 1159
1157err_put1: 1160err_put1:
diff --git a/drivers/misc/cxl/main.c b/drivers/misc/cxl/main.c
index d9be23b24aa3..62e0dfb5f15b 100644
--- a/drivers/misc/cxl/main.c
+++ b/drivers/misc/cxl/main.c
@@ -243,8 +243,10 @@ struct cxl *cxl_alloc_adapter(void)
243 if (dev_set_name(&adapter->dev, "card%i", adapter->adapter_num)) 243 if (dev_set_name(&adapter->dev, "card%i", adapter->adapter_num))
244 goto err2; 244 goto err2;
245 245
246 return adapter; 246 /* start with context lock taken */
247 atomic_set(&adapter->contexts_num, -1);
247 248
249 return adapter;
248err2: 250err2:
249 cxl_remove_adapter_nr(adapter); 251 cxl_remove_adapter_nr(adapter);
250err1: 252err1:
@@ -286,6 +288,44 @@ int cxl_afu_select_best_mode(struct cxl_afu *afu)
286 return 0; 288 return 0;
287} 289}
288 290
291int cxl_adapter_context_get(struct cxl *adapter)
292{
293 int rc;
294
295 rc = atomic_inc_unless_negative(&adapter->contexts_num);
296 return rc >= 0 ? 0 : -EBUSY;
297}
298
299void cxl_adapter_context_put(struct cxl *adapter)
300{
301 atomic_dec_if_positive(&adapter->contexts_num);
302}
303
304int cxl_adapter_context_lock(struct cxl *adapter)
305{
306 int rc;
307 /* no active contexts -> contexts_num == 0 */
308 rc = atomic_cmpxchg(&adapter->contexts_num, 0, -1);
309 return rc ? -EBUSY : 0;
310}
311
312void cxl_adapter_context_unlock(struct cxl *adapter)
313{
314 int val = atomic_cmpxchg(&adapter->contexts_num, -1, 0);
315
316 /*
317 * contexts lock taken -> contexts_num == -1
318 * If not true then show a warning and force reset the lock.
319 * This will happen when context_unlock was requested without
320 * doing a context_lock.
321 */
322 if (val != -1) {
323 atomic_set(&adapter->contexts_num, 0);
324 WARN(1, "Adapter context unlocked with %d active contexts",
325 val);
326 }
327}
328
289static int __init init_cxl(void) 329static int __init init_cxl(void)
290{ 330{
291 int rc = 0; 331 int rc = 0;
diff --git a/drivers/misc/cxl/pci.c b/drivers/misc/cxl/pci.c
index 7afad8477ad5..e96be9ca4e60 100644
--- a/drivers/misc/cxl/pci.c
+++ b/drivers/misc/cxl/pci.c
@@ -1487,6 +1487,8 @@ static int cxl_configure_adapter(struct cxl *adapter, struct pci_dev *dev)
1487 if ((rc = cxl_native_register_psl_err_irq(adapter))) 1487 if ((rc = cxl_native_register_psl_err_irq(adapter)))
1488 goto err; 1488 goto err;
1489 1489
1490 /* Release the context lock as adapter is configured */
1491 cxl_adapter_context_unlock(adapter);
1490 return 0; 1492 return 0;
1491 1493
1492err: 1494err:
diff --git a/drivers/misc/cxl/sysfs.c b/drivers/misc/cxl/sysfs.c
index b043c20f158f..a8b6d6a635e9 100644
--- a/drivers/misc/cxl/sysfs.c
+++ b/drivers/misc/cxl/sysfs.c
@@ -75,12 +75,31 @@ static ssize_t reset_adapter_store(struct device *device,
75 int val; 75 int val;
76 76
77 rc = sscanf(buf, "%i", &val); 77 rc = sscanf(buf, "%i", &val);
78 if ((rc != 1) || (val != 1)) 78 if ((rc != 1) || (val != 1 && val != -1))
79 return -EINVAL; 79 return -EINVAL;
80 80
81 if ((rc = cxl_ops->adapter_reset(adapter))) 81 /*
82 return rc; 82 * See if we can lock the context mapping that's only allowed
83 return count; 83 * when there are no contexts attached to the adapter. Once
84 * taken this will also prevent any context from getting activated.
85 */
86 if (val == 1) {
87 rc = cxl_adapter_context_lock(adapter);
88 if (rc)
89 goto out;
90
91 rc = cxl_ops->adapter_reset(adapter);
92 /* In case reset failed release context lock */
93 if (rc)
94 cxl_adapter_context_unlock(adapter);
95
96 } else if (val == -1) {
97 /* Perform a forced adapter reset */
98 rc = cxl_ops->adapter_reset(adapter);
99 }
100
101out:
102 return rc ? rc : count;
84} 103}
85 104
86static ssize_t load_image_on_perst_show(struct device *device, 105static ssize_t load_image_on_perst_show(struct device *device,
diff --git a/drivers/misc/genwqe/card_utils.c b/drivers/misc/genwqe/card_utils.c
index 8a679ecc8fd1..fc2794b513fa 100644
--- a/drivers/misc/genwqe/card_utils.c
+++ b/drivers/misc/genwqe/card_utils.c
@@ -352,17 +352,27 @@ int genwqe_alloc_sync_sgl(struct genwqe_dev *cd, struct genwqe_sgl *sgl,
352 if (copy_from_user(sgl->lpage, user_addr + user_size - 352 if (copy_from_user(sgl->lpage, user_addr + user_size -
353 sgl->lpage_size, sgl->lpage_size)) { 353 sgl->lpage_size, sgl->lpage_size)) {
354 rc = -EFAULT; 354 rc = -EFAULT;
355 goto err_out1; 355 goto err_out2;
356 } 356 }
357 } 357 }
358 return 0; 358 return 0;
359 359
360 err_out2:
361 __genwqe_free_consistent(cd, PAGE_SIZE, sgl->lpage,
362 sgl->lpage_dma_addr);
363 sgl->lpage = NULL;
364 sgl->lpage_dma_addr = 0;
360 err_out1: 365 err_out1:
361 __genwqe_free_consistent(cd, PAGE_SIZE, sgl->fpage, 366 __genwqe_free_consistent(cd, PAGE_SIZE, sgl->fpage,
362 sgl->fpage_dma_addr); 367 sgl->fpage_dma_addr);
368 sgl->fpage = NULL;
369 sgl->fpage_dma_addr = 0;
363 err_out: 370 err_out:
364 __genwqe_free_consistent(cd, sgl->sgl_size, sgl->sgl, 371 __genwqe_free_consistent(cd, sgl->sgl_size, sgl->sgl,
365 sgl->sgl_dma_addr); 372 sgl->sgl_dma_addr);
373 sgl->sgl = NULL;
374 sgl->sgl_dma_addr = 0;
375 sgl->sgl_size = 0;
366 return -ENOMEM; 376 return -ENOMEM;
367} 377}
368 378
diff --git a/drivers/misc/mei/bus-fixup.c b/drivers/misc/mei/bus-fixup.c
index e9e6ea3ab73c..75b9d4ac8b1e 100644
--- a/drivers/misc/mei/bus-fixup.c
+++ b/drivers/misc/mei/bus-fixup.c
@@ -178,7 +178,7 @@ static int mei_nfc_if_version(struct mei_cl *cl,
178 178
179 ret = 0; 179 ret = 0;
180 bytes_recv = __mei_cl_recv(cl, (u8 *)reply, if_version_length); 180 bytes_recv = __mei_cl_recv(cl, (u8 *)reply, if_version_length);
181 if (bytes_recv < 0 || bytes_recv < sizeof(struct mei_nfc_reply)) { 181 if (bytes_recv < if_version_length) {
182 dev_err(bus->dev, "Could not read IF version\n"); 182 dev_err(bus->dev, "Could not read IF version\n");
183 ret = -EIO; 183 ret = -EIO;
184 goto err; 184 goto err;
diff --git a/drivers/misc/mei/hw-txe.c b/drivers/misc/mei/hw-txe.c
index e6e5e55a12ed..60415a2bfcbd 100644
--- a/drivers/misc/mei/hw-txe.c
+++ b/drivers/misc/mei/hw-txe.c
@@ -981,11 +981,13 @@ static bool mei_txe_check_and_ack_intrs(struct mei_device *dev, bool do_ack)
981 hisr = mei_txe_br_reg_read(hw, HISR_REG); 981 hisr = mei_txe_br_reg_read(hw, HISR_REG);
982 982
983 aliveness = mei_txe_aliveness_get(dev); 983 aliveness = mei_txe_aliveness_get(dev);
984 if (hhisr & IPC_HHIER_SEC && aliveness) 984 if (hhisr & IPC_HHIER_SEC && aliveness) {
985 ipc_isr = mei_txe_sec_reg_read_silent(hw, 985 ipc_isr = mei_txe_sec_reg_read_silent(hw,
986 SEC_IPC_HOST_INT_STATUS_REG); 986 SEC_IPC_HOST_INT_STATUS_REG);
987 else 987 } else {
988 ipc_isr = 0; 988 ipc_isr = 0;
989 hhisr &= ~IPC_HHIER_SEC;
990 }
989 991
990 generated = generated || 992 generated = generated ||
991 (hisr & HISR_INT_STS_MSK) || 993 (hisr & HISR_INT_STS_MSK) ||
diff --git a/drivers/misc/mic/scif/scif_rma.c b/drivers/misc/mic/scif/scif_rma.c
index e0203b1a20fd..f806a4471eb9 100644
--- a/drivers/misc/mic/scif/scif_rma.c
+++ b/drivers/misc/mic/scif/scif_rma.c
@@ -1396,8 +1396,7 @@ retry:
1396 pinned_pages->nr_pages = get_user_pages( 1396 pinned_pages->nr_pages = get_user_pages(
1397 (u64)addr, 1397 (u64)addr,
1398 nr_pages, 1398 nr_pages,
1399 !!(prot & SCIF_PROT_WRITE), 1399 (prot & SCIF_PROT_WRITE) ? FOLL_WRITE : 0,
1400 0,
1401 pinned_pages->pages, 1400 pinned_pages->pages,
1402 NULL); 1401 NULL);
1403 up_write(&mm->mmap_sem); 1402 up_write(&mm->mmap_sem);
diff --git a/drivers/misc/sgi-gru/grufault.c b/drivers/misc/sgi-gru/grufault.c
index a2d97b9b17e3..6fb773dbcd0c 100644
--- a/drivers/misc/sgi-gru/grufault.c
+++ b/drivers/misc/sgi-gru/grufault.c
@@ -198,7 +198,7 @@ static int non_atomic_pte_lookup(struct vm_area_struct *vma,
198#else 198#else
199 *pageshift = PAGE_SHIFT; 199 *pageshift = PAGE_SHIFT;
200#endif 200#endif
201 if (get_user_pages(vaddr, 1, write, 0, &page, NULL) <= 0) 201 if (get_user_pages(vaddr, 1, write ? FOLL_WRITE : 0, &page, NULL) <= 0)
202 return -EFAULT; 202 return -EFAULT;
203 *paddr = page_to_phys(page); 203 *paddr = page_to_phys(page);
204 put_page(page); 204 put_page(page);
diff --git a/drivers/misc/sgi-gru/grumain.c b/drivers/misc/sgi-gru/grumain.c
index 1525870f460a..33741ad4a74a 100644
--- a/drivers/misc/sgi-gru/grumain.c
+++ b/drivers/misc/sgi-gru/grumain.c
@@ -283,7 +283,7 @@ static void gru_unload_mm_tracker(struct gru_state *gru,
283 spin_lock(&gru->gs_asid_lock); 283 spin_lock(&gru->gs_asid_lock);
284 BUG_ON((asids->mt_ctxbitmap & ctxbitmap) != ctxbitmap); 284 BUG_ON((asids->mt_ctxbitmap & ctxbitmap) != ctxbitmap);
285 asids->mt_ctxbitmap ^= ctxbitmap; 285 asids->mt_ctxbitmap ^= ctxbitmap;
286 gru_dbg(grudev, "gid %d, gts %p, gms %p, ctxnum 0x%d, asidmap 0x%lx\n", 286 gru_dbg(grudev, "gid %d, gts %p, gms %p, ctxnum %d, asidmap 0x%lx\n",
287 gru->gs_gid, gts, gms, gts->ts_ctxnum, gms->ms_asidmap[0]); 287 gru->gs_gid, gts, gms, gts->ts_ctxnum, gms->ms_asidmap[0]);
288 spin_unlock(&gru->gs_asid_lock); 288 spin_unlock(&gru->gs_asid_lock);
289 spin_unlock(&gms->ms_asid_lock); 289 spin_unlock(&gms->ms_asid_lock);
diff --git a/drivers/misc/vmw_vmci/vmci_doorbell.c b/drivers/misc/vmw_vmci/vmci_doorbell.c
index a8cee33ae8d2..b3fa738ae005 100644
--- a/drivers/misc/vmw_vmci/vmci_doorbell.c
+++ b/drivers/misc/vmw_vmci/vmci_doorbell.c
@@ -431,6 +431,12 @@ int vmci_doorbell_create(struct vmci_handle *handle,
431 if (vmci_handle_is_invalid(*handle)) { 431 if (vmci_handle_is_invalid(*handle)) {
432 u32 context_id = vmci_get_context_id(); 432 u32 context_id = vmci_get_context_id();
433 433
434 if (context_id == VMCI_INVALID_ID) {
435 pr_warn("Failed to get context ID\n");
436 result = VMCI_ERROR_NO_RESOURCES;
437 goto free_mem;
438 }
439
434 /* Let resource code allocate a free ID for us */ 440 /* Let resource code allocate a free ID for us */
435 new_handle = vmci_make_handle(context_id, VMCI_INVALID_ID); 441 new_handle = vmci_make_handle(context_id, VMCI_INVALID_ID);
436 } else { 442 } else {
@@ -525,7 +531,7 @@ int vmci_doorbell_destroy(struct vmci_handle handle)
525 531
526 entry = container_of(resource, struct dbell_entry, resource); 532 entry = container_of(resource, struct dbell_entry, resource);
527 533
528 if (vmci_guest_code_active()) { 534 if (!hlist_unhashed(&entry->node)) {
529 int result; 535 int result;
530 536
531 dbell_index_table_remove(entry); 537 dbell_index_table_remove(entry);
diff --git a/drivers/misc/vmw_vmci/vmci_driver.c b/drivers/misc/vmw_vmci/vmci_driver.c
index 896be150e28f..d7eaf1eb11e7 100644
--- a/drivers/misc/vmw_vmci/vmci_driver.c
+++ b/drivers/misc/vmw_vmci/vmci_driver.c
@@ -113,5 +113,5 @@ module_exit(vmci_drv_exit);
113 113
114MODULE_AUTHOR("VMware, Inc."); 114MODULE_AUTHOR("VMware, Inc.");
115MODULE_DESCRIPTION("VMware Virtual Machine Communication Interface."); 115MODULE_DESCRIPTION("VMware Virtual Machine Communication Interface.");
116MODULE_VERSION("1.1.4.0-k"); 116MODULE_VERSION("1.1.5.0-k");
117MODULE_LICENSE("GPL v2"); 117MODULE_LICENSE("GPL v2");
diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
index c3335112e68c..709a872ed484 100644
--- a/drivers/mmc/card/block.c
+++ b/drivers/mmc/card/block.c
@@ -46,6 +46,7 @@
46#include <asm/uaccess.h> 46#include <asm/uaccess.h>
47 47
48#include "queue.h" 48#include "queue.h"
49#include "block.h"
49 50
50MODULE_ALIAS("mmc:block"); 51MODULE_ALIAS("mmc:block");
51#ifdef MODULE_PARAM_PREFIX 52#ifdef MODULE_PARAM_PREFIX
@@ -1786,7 +1787,7 @@ static void mmc_blk_packed_hdr_wrq_prep(struct mmc_queue_req *mqrq,
1786 struct mmc_blk_data *md = mq->data; 1787 struct mmc_blk_data *md = mq->data;
1787 struct mmc_packed *packed = mqrq->packed; 1788 struct mmc_packed *packed = mqrq->packed;
1788 bool do_rel_wr, do_data_tag; 1789 bool do_rel_wr, do_data_tag;
1789 u32 *packed_cmd_hdr; 1790 __le32 *packed_cmd_hdr;
1790 u8 hdr_blocks; 1791 u8 hdr_blocks;
1791 u8 i = 1; 1792 u8 i = 1;
1792 1793
diff --git a/drivers/mmc/card/mmc_test.c b/drivers/mmc/card/mmc_test.c
index 5a8dc5a76e0d..3678220964fe 100644
--- a/drivers/mmc/card/mmc_test.c
+++ b/drivers/mmc/card/mmc_test.c
@@ -2347,7 +2347,7 @@ static int mmc_test_ongoing_transfer(struct mmc_test_card *test,
2347 struct mmc_test_req *rq = mmc_test_req_alloc(); 2347 struct mmc_test_req *rq = mmc_test_req_alloc();
2348 struct mmc_host *host = test->card->host; 2348 struct mmc_host *host = test->card->host;
2349 struct mmc_test_area *t = &test->area; 2349 struct mmc_test_area *t = &test->area;
2350 struct mmc_async_req areq; 2350 struct mmc_test_async_req test_areq = { .test = test };
2351 struct mmc_request *mrq; 2351 struct mmc_request *mrq;
2352 unsigned long timeout; 2352 unsigned long timeout;
2353 bool expired = false; 2353 bool expired = false;
@@ -2363,8 +2363,8 @@ static int mmc_test_ongoing_transfer(struct mmc_test_card *test,
2363 mrq->sbc = &rq->sbc; 2363 mrq->sbc = &rq->sbc;
2364 mrq->cap_cmd_during_tfr = true; 2364 mrq->cap_cmd_during_tfr = true;
2365 2365
2366 areq.mrq = mrq; 2366 test_areq.areq.mrq = mrq;
2367 areq.err_check = mmc_test_check_result_async; 2367 test_areq.areq.err_check = mmc_test_check_result_async;
2368 2368
2369 mmc_test_prepare_mrq(test, mrq, t->sg, t->sg_len, dev_addr, t->blocks, 2369 mmc_test_prepare_mrq(test, mrq, t->sg, t->sg_len, dev_addr, t->blocks,
2370 512, write); 2370 512, write);
@@ -2378,7 +2378,7 @@ static int mmc_test_ongoing_transfer(struct mmc_test_card *test,
2378 2378
2379 /* Start ongoing data request */ 2379 /* Start ongoing data request */
2380 if (use_areq) { 2380 if (use_areq) {
2381 mmc_start_req(host, &areq, &ret); 2381 mmc_start_req(host, &test_areq.areq, &ret);
2382 if (ret) 2382 if (ret)
2383 goto out_free; 2383 goto out_free;
2384 } else { 2384 } else {
diff --git a/drivers/mmc/card/queue.h b/drivers/mmc/card/queue.h
index 3c15a75bae86..342f1e3f301e 100644
--- a/drivers/mmc/card/queue.h
+++ b/drivers/mmc/card/queue.h
@@ -31,7 +31,7 @@ enum mmc_packed_type {
31 31
32struct mmc_packed { 32struct mmc_packed {
33 struct list_head list; 33 struct list_head list;
34 u32 cmd_hdr[1024]; 34 __le32 cmd_hdr[1024];
35 unsigned int blocks; 35 unsigned int blocks;
36 u8 nr_entries; 36 u8 nr_entries;
37 u8 retries; 37 u8 retries;
diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c
index 3486bc7fbb64..df19777068a6 100644
--- a/drivers/mmc/core/mmc.c
+++ b/drivers/mmc/core/mmc.c
@@ -26,6 +26,8 @@
26#include "mmc_ops.h" 26#include "mmc_ops.h"
27#include "sd_ops.h" 27#include "sd_ops.h"
28 28
29#define DEFAULT_CMD6_TIMEOUT_MS 500
30
29static const unsigned int tran_exp[] = { 31static const unsigned int tran_exp[] = {
30 10000, 100000, 1000000, 10000000, 32 10000, 100000, 1000000, 10000000,
31 0, 0, 0, 0 33 0, 0, 0, 0
@@ -571,6 +573,7 @@ static int mmc_decode_ext_csd(struct mmc_card *card, u8 *ext_csd)
571 card->erased_byte = 0x0; 573 card->erased_byte = 0x0;
572 574
573 /* eMMC v4.5 or later */ 575 /* eMMC v4.5 or later */
576 card->ext_csd.generic_cmd6_time = DEFAULT_CMD6_TIMEOUT_MS;
574 if (card->ext_csd.rev >= 6) { 577 if (card->ext_csd.rev >= 6) {
575 card->ext_csd.feature_support |= MMC_DISCARD_FEATURE; 578 card->ext_csd.feature_support |= MMC_DISCARD_FEATURE;
576 579
@@ -1263,6 +1266,16 @@ static int mmc_select_hs400es(struct mmc_card *card)
1263 goto out_err; 1266 goto out_err;
1264 } 1267 }
1265 1268
1269 if (card->mmc_avail_type & EXT_CSD_CARD_TYPE_HS400_1_2V)
1270 err = __mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_120);
1271
1272 if (err && card->mmc_avail_type & EXT_CSD_CARD_TYPE_HS400_1_8V)
1273 err = __mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_180);
1274
1275 /* If fails try again during next card power cycle */
1276 if (err)
1277 goto out_err;
1278
1266 err = mmc_select_bus_width(card); 1279 err = mmc_select_bus_width(card);
1267 if (err < 0) 1280 if (err < 0)
1268 goto out_err; 1281 goto out_err;
@@ -1272,6 +1285,8 @@ static int mmc_select_hs400es(struct mmc_card *card)
1272 if (err) 1285 if (err)
1273 goto out_err; 1286 goto out_err;
1274 1287
1288 mmc_set_clock(host, card->ext_csd.hs_max_dtr);
1289
1275 err = mmc_switch_status(card); 1290 err = mmc_switch_status(card);
1276 if (err) 1291 if (err)
1277 goto out_err; 1292 goto out_err;
diff --git a/drivers/mmc/host/dw_mmc-pltfm.c b/drivers/mmc/host/dw_mmc-pltfm.c
index c0bb0c793e84..dbbc4303bdd0 100644
--- a/drivers/mmc/host/dw_mmc-pltfm.c
+++ b/drivers/mmc/host/dw_mmc-pltfm.c
@@ -46,12 +46,13 @@ int dw_mci_pltfm_register(struct platform_device *pdev,
46 host->pdata = pdev->dev.platform_data; 46 host->pdata = pdev->dev.platform_data;
47 47
48 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0); 48 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
49 /* Get registers' physical base address */
50 host->phy_regs = regs->start;
51 host->regs = devm_ioremap_resource(&pdev->dev, regs); 49 host->regs = devm_ioremap_resource(&pdev->dev, regs);
52 if (IS_ERR(host->regs)) 50 if (IS_ERR(host->regs))
53 return PTR_ERR(host->regs); 51 return PTR_ERR(host->regs);
54 52
53 /* Get registers' physical base address */
54 host->phy_regs = regs->start;
55
55 platform_set_drvdata(pdev, host); 56 platform_set_drvdata(pdev, host);
56 return dw_mci_probe(host); 57 return dw_mci_probe(host);
57} 58}
diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c
index 4fcbc4012ed0..df478ae72e23 100644
--- a/drivers/mmc/host/dw_mmc.c
+++ b/drivers/mmc/host/dw_mmc.c
@@ -1058,6 +1058,7 @@ static int dw_mci_submit_data_dma(struct dw_mci *host, struct mmc_data *data)
1058 spin_unlock_irqrestore(&host->irq_lock, irqflags); 1058 spin_unlock_irqrestore(&host->irq_lock, irqflags);
1059 1059
1060 if (host->dma_ops->start(host, sg_len)) { 1060 if (host->dma_ops->start(host, sg_len)) {
1061 host->dma_ops->stop(host);
1061 /* We can't do DMA, try PIO for this one */ 1062 /* We can't do DMA, try PIO for this one */
1062 dev_dbg(host->dev, 1063 dev_dbg(host->dev,
1063 "%s: fall back to PIO mode for current transfer\n", 1064 "%s: fall back to PIO mode for current transfer\n",
@@ -2940,7 +2941,7 @@ static struct dw_mci_board *dw_mci_parse_dt(struct dw_mci *host)
2940 return ERR_PTR(-ENOMEM); 2941 return ERR_PTR(-ENOMEM);
2941 2942
2942 /* find reset controller when exist */ 2943 /* find reset controller when exist */
2943 pdata->rstc = devm_reset_control_get_optional(dev, NULL); 2944 pdata->rstc = devm_reset_control_get_optional(dev, "reset");
2944 if (IS_ERR(pdata->rstc)) { 2945 if (IS_ERR(pdata->rstc)) {
2945 if (PTR_ERR(pdata->rstc) == -EPROBE_DEFER) 2946 if (PTR_ERR(pdata->rstc) == -EPROBE_DEFER)
2946 return ERR_PTR(-EPROBE_DEFER); 2947 return ERR_PTR(-EPROBE_DEFER);
diff --git a/drivers/mmc/host/mxs-mmc.c b/drivers/mmc/host/mxs-mmc.c
index d839147e591d..44ecebd1ea8c 100644
--- a/drivers/mmc/host/mxs-mmc.c
+++ b/drivers/mmc/host/mxs-mmc.c
@@ -661,13 +661,13 @@ static int mxs_mmc_probe(struct platform_device *pdev)
661 661
662 platform_set_drvdata(pdev, mmc); 662 platform_set_drvdata(pdev, mmc);
663 663
664 spin_lock_init(&host->lock);
665
664 ret = devm_request_irq(&pdev->dev, irq_err, mxs_mmc_irq_handler, 0, 666 ret = devm_request_irq(&pdev->dev, irq_err, mxs_mmc_irq_handler, 0,
665 dev_name(&pdev->dev), host); 667 dev_name(&pdev->dev), host);
666 if (ret) 668 if (ret)
667 goto out_free_dma; 669 goto out_free_dma;
668 670
669 spin_lock_init(&host->lock);
670
671 ret = mmc_add_host(mmc); 671 ret = mmc_add_host(mmc);
672 if (ret) 672 if (ret)
673 goto out_free_dma; 673 goto out_free_dma;
diff --git a/drivers/mmc/host/rtsx_usb_sdmmc.c b/drivers/mmc/host/rtsx_usb_sdmmc.c
index 4106295527b9..6e9c0f8fddb1 100644
--- a/drivers/mmc/host/rtsx_usb_sdmmc.c
+++ b/drivers/mmc/host/rtsx_usb_sdmmc.c
@@ -1138,11 +1138,6 @@ static void sdmmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
1138 dev_dbg(sdmmc_dev(host), "%s\n", __func__); 1138 dev_dbg(sdmmc_dev(host), "%s\n", __func__);
1139 mutex_lock(&ucr->dev_mutex); 1139 mutex_lock(&ucr->dev_mutex);
1140 1140
1141 if (rtsx_usb_card_exclusive_check(ucr, RTSX_USB_SD_CARD)) {
1142 mutex_unlock(&ucr->dev_mutex);
1143 return;
1144 }
1145
1146 sd_set_power_mode(host, ios->power_mode); 1141 sd_set_power_mode(host, ios->power_mode);
1147 sd_set_bus_width(host, ios->bus_width); 1142 sd_set_bus_width(host, ios->bus_width);
1148 sd_set_timing(host, ios->timing, &host->ddr_mode); 1143 sd_set_timing(host, ios->timing, &host->ddr_mode);
@@ -1314,6 +1309,7 @@ static void rtsx_usb_update_led(struct work_struct *work)
1314 container_of(work, struct rtsx_usb_sdmmc, led_work); 1309 container_of(work, struct rtsx_usb_sdmmc, led_work);
1315 struct rtsx_ucr *ucr = host->ucr; 1310 struct rtsx_ucr *ucr = host->ucr;
1316 1311
1312 pm_runtime_get_sync(sdmmc_dev(host));
1317 mutex_lock(&ucr->dev_mutex); 1313 mutex_lock(&ucr->dev_mutex);
1318 1314
1319 if (host->led.brightness == LED_OFF) 1315 if (host->led.brightness == LED_OFF)
@@ -1322,6 +1318,7 @@ static void rtsx_usb_update_led(struct work_struct *work)
1322 rtsx_usb_turn_on_led(ucr); 1318 rtsx_usb_turn_on_led(ucr);
1323 1319
1324 mutex_unlock(&ucr->dev_mutex); 1320 mutex_unlock(&ucr->dev_mutex);
1321 pm_runtime_put(sdmmc_dev(host));
1325} 1322}
1326#endif 1323#endif
1327 1324
diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
index 1f54fd8755c8..7123ef96ed18 100644
--- a/drivers/mmc/host/sdhci-esdhc-imx.c
+++ b/drivers/mmc/host/sdhci-esdhc-imx.c
@@ -346,7 +346,8 @@ static void esdhc_writel_le(struct sdhci_host *host, u32 val, int reg)
346 struct pltfm_imx_data *imx_data = sdhci_pltfm_priv(pltfm_host); 346 struct pltfm_imx_data *imx_data = sdhci_pltfm_priv(pltfm_host);
347 u32 data; 347 u32 data;
348 348
349 if (unlikely(reg == SDHCI_INT_ENABLE || reg == SDHCI_SIGNAL_ENABLE)) { 349 if (unlikely(reg == SDHCI_INT_ENABLE || reg == SDHCI_SIGNAL_ENABLE ||
350 reg == SDHCI_INT_STATUS)) {
350 if ((val & SDHCI_INT_CARD_INT) && !esdhc_is_usdhc(imx_data)) { 351 if ((val & SDHCI_INT_CARD_INT) && !esdhc_is_usdhc(imx_data)) {
351 /* 352 /*
352 * Clear and then set D3CD bit to avoid missing the 353 * Clear and then set D3CD bit to avoid missing the
@@ -555,6 +556,25 @@ static void esdhc_writew_le(struct sdhci_host *host, u16 val, int reg)
555 esdhc_clrset_le(host, 0xffff, val, reg); 556 esdhc_clrset_le(host, 0xffff, val, reg);
556} 557}
557 558
559static u8 esdhc_readb_le(struct sdhci_host *host, int reg)
560{
561 u8 ret;
562 u32 val;
563
564 switch (reg) {
565 case SDHCI_HOST_CONTROL:
566 val = readl(host->ioaddr + reg);
567
568 ret = val & SDHCI_CTRL_LED;
569 ret |= (val >> 5) & SDHCI_CTRL_DMA_MASK;
570 ret |= (val & ESDHC_CTRL_4BITBUS);
571 ret |= (val & ESDHC_CTRL_8BITBUS) << 3;
572 return ret;
573 }
574
575 return readb(host->ioaddr + reg);
576}
577
558static void esdhc_writeb_le(struct sdhci_host *host, u8 val, int reg) 578static void esdhc_writeb_le(struct sdhci_host *host, u8 val, int reg)
559{ 579{
560 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); 580 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
@@ -947,6 +967,7 @@ static void esdhc_set_timeout(struct sdhci_host *host, struct mmc_command *cmd)
947static struct sdhci_ops sdhci_esdhc_ops = { 967static struct sdhci_ops sdhci_esdhc_ops = {
948 .read_l = esdhc_readl_le, 968 .read_l = esdhc_readl_le,
949 .read_w = esdhc_readw_le, 969 .read_w = esdhc_readw_le,
970 .read_b = esdhc_readb_le,
950 .write_l = esdhc_writel_le, 971 .write_l = esdhc_writel_le,
951 .write_w = esdhc_writew_le, 972 .write_w = esdhc_writew_le,
952 .write_b = esdhc_writeb_le, 973 .write_b = esdhc_writeb_le,
diff --git a/drivers/mmc/host/sdhci-msm.c b/drivers/mmc/host/sdhci-msm.c
index 8ef44a2a2fd9..90ed2e12d345 100644
--- a/drivers/mmc/host/sdhci-msm.c
+++ b/drivers/mmc/host/sdhci-msm.c
@@ -647,6 +647,7 @@ static int sdhci_msm_probe(struct platform_device *pdev)
647 if (msm_host->pwr_irq < 0) { 647 if (msm_host->pwr_irq < 0) {
648 dev_err(&pdev->dev, "Get pwr_irq failed (%d)\n", 648 dev_err(&pdev->dev, "Get pwr_irq failed (%d)\n",
649 msm_host->pwr_irq); 649 msm_host->pwr_irq);
650 ret = msm_host->pwr_irq;
650 goto clk_disable; 651 goto clk_disable;
651 } 652 }
652 653
diff --git a/drivers/mmc/host/sdhci-of-arasan.c b/drivers/mmc/host/sdhci-of-arasan.c
index da8e40af6f85..410a55b1c25f 100644
--- a/drivers/mmc/host/sdhci-of-arasan.c
+++ b/drivers/mmc/host/sdhci-of-arasan.c
@@ -250,7 +250,7 @@ static void sdhci_arasan_hs400_enhanced_strobe(struct mmc_host *mmc,
250 writel(vendor, host->ioaddr + SDHCI_ARASAN_VENDOR_REGISTER); 250 writel(vendor, host->ioaddr + SDHCI_ARASAN_VENDOR_REGISTER);
251} 251}
252 252
253void sdhci_arasan_reset(struct sdhci_host *host, u8 mask) 253static void sdhci_arasan_reset(struct sdhci_host *host, u8 mask)
254{ 254{
255 u8 ctrl; 255 u8 ctrl;
256 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); 256 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
@@ -265,6 +265,28 @@ void sdhci_arasan_reset(struct sdhci_host *host, u8 mask)
265 } 265 }
266} 266}
267 267
268static int sdhci_arasan_voltage_switch(struct mmc_host *mmc,
269 struct mmc_ios *ios)
270{
271 switch (ios->signal_voltage) {
272 case MMC_SIGNAL_VOLTAGE_180:
273 /*
274 * Plese don't switch to 1V8 as arasan,5.1 doesn't
275 * actually refer to this setting to indicate the
276 * signal voltage and the state machine will be broken
277 * actually if we force to enable 1V8. That's something
278 * like broken quirk but we could work around here.
279 */
280 return 0;
281 case MMC_SIGNAL_VOLTAGE_330:
282 case MMC_SIGNAL_VOLTAGE_120:
283 /* We don't support 3V3 and 1V2 */
284 break;
285 }
286
287 return -EINVAL;
288}
289
268static struct sdhci_ops sdhci_arasan_ops = { 290static struct sdhci_ops sdhci_arasan_ops = {
269 .set_clock = sdhci_arasan_set_clock, 291 .set_clock = sdhci_arasan_set_clock,
270 .get_max_clock = sdhci_pltfm_clk_get_max_clock, 292 .get_max_clock = sdhci_pltfm_clk_get_max_clock,
@@ -661,6 +683,8 @@ static int sdhci_arasan_probe(struct platform_device *pdev)
661 683
662 host->mmc_host_ops.hs400_enhanced_strobe = 684 host->mmc_host_ops.hs400_enhanced_strobe =
663 sdhci_arasan_hs400_enhanced_strobe; 685 sdhci_arasan_hs400_enhanced_strobe;
686 host->mmc_host_ops.start_signal_voltage_switch =
687 sdhci_arasan_voltage_switch;
664 } 688 }
665 689
666 ret = sdhci_add_host(host); 690 ret = sdhci_add_host(host);
diff --git a/drivers/mmc/host/sdhci-of-esdhc.c b/drivers/mmc/host/sdhci-of-esdhc.c
index fb71c866eacc..1bb11e4a9fe5 100644
--- a/drivers/mmc/host/sdhci-of-esdhc.c
+++ b/drivers/mmc/host/sdhci-of-esdhc.c
@@ -66,6 +66,20 @@ static u32 esdhc_readl_fixup(struct sdhci_host *host,
66 return ret; 66 return ret;
67 } 67 }
68 } 68 }
69 /*
70 * The DAT[3:0] line signal levels and the CMD line signal level are
71 * not compatible with standard SDHC register. The line signal levels
72 * DAT[7:0] are at bits 31:24 and the command line signal level is at
73 * bit 23. All other bits are the same as in the standard SDHC
74 * register.
75 */
76 if (spec_reg == SDHCI_PRESENT_STATE) {
77 ret = value & 0x000fffff;
78 ret |= (value >> 4) & SDHCI_DATA_LVL_MASK;
79 ret |= (value << 1) & SDHCI_CMD_LVL;
80 return ret;
81 }
82
69 ret = value; 83 ret = value;
70 return ret; 84 return ret;
71} 85}
diff --git a/drivers/mmc/host/sdhci-pci-core.c b/drivers/mmc/host/sdhci-pci-core.c
index 72a1f1f5180a..1d9e00a00e9f 100644
--- a/drivers/mmc/host/sdhci-pci-core.c
+++ b/drivers/mmc/host/sdhci-pci-core.c
@@ -32,6 +32,14 @@
32#include "sdhci-pci.h" 32#include "sdhci-pci.h"
33#include "sdhci-pci-o2micro.h" 33#include "sdhci-pci-o2micro.h"
34 34
35static int sdhci_pci_enable_dma(struct sdhci_host *host);
36static void sdhci_pci_set_bus_width(struct sdhci_host *host, int width);
37static void sdhci_pci_hw_reset(struct sdhci_host *host);
38static int sdhci_pci_select_drive_strength(struct sdhci_host *host,
39 struct mmc_card *card,
40 unsigned int max_dtr, int host_drv,
41 int card_drv, int *drv_type);
42
35/*****************************************************************************\ 43/*****************************************************************************\
36 * * 44 * *
37 * Hardware specific quirk handling * 45 * Hardware specific quirk handling *
@@ -390,6 +398,45 @@ static int byt_sd_probe_slot(struct sdhci_pci_slot *slot)
390 return 0; 398 return 0;
391} 399}
392 400
401#define SDHCI_INTEL_PWR_TIMEOUT_CNT 20
402#define SDHCI_INTEL_PWR_TIMEOUT_UDELAY 100
403
404static void sdhci_intel_set_power(struct sdhci_host *host, unsigned char mode,
405 unsigned short vdd)
406{
407 int cntr;
408 u8 reg;
409
410 sdhci_set_power(host, mode, vdd);
411
412 if (mode == MMC_POWER_OFF)
413 return;
414
415 /*
416 * Bus power might not enable after D3 -> D0 transition due to the
417 * present state not yet having propagated. Retry for up to 2ms.
418 */
419 for (cntr = 0; cntr < SDHCI_INTEL_PWR_TIMEOUT_CNT; cntr++) {
420 reg = sdhci_readb(host, SDHCI_POWER_CONTROL);
421 if (reg & SDHCI_POWER_ON)
422 break;
423 udelay(SDHCI_INTEL_PWR_TIMEOUT_UDELAY);
424 reg |= SDHCI_POWER_ON;
425 sdhci_writeb(host, reg, SDHCI_POWER_CONTROL);
426 }
427}
428
429static const struct sdhci_ops sdhci_intel_byt_ops = {
430 .set_clock = sdhci_set_clock,
431 .set_power = sdhci_intel_set_power,
432 .enable_dma = sdhci_pci_enable_dma,
433 .set_bus_width = sdhci_pci_set_bus_width,
434 .reset = sdhci_reset,
435 .set_uhs_signaling = sdhci_set_uhs_signaling,
436 .hw_reset = sdhci_pci_hw_reset,
437 .select_drive_strength = sdhci_pci_select_drive_strength,
438};
439
393static const struct sdhci_pci_fixes sdhci_intel_byt_emmc = { 440static const struct sdhci_pci_fixes sdhci_intel_byt_emmc = {
394 .allow_runtime_pm = true, 441 .allow_runtime_pm = true,
395 .probe_slot = byt_emmc_probe_slot, 442 .probe_slot = byt_emmc_probe_slot,
@@ -397,6 +444,7 @@ static const struct sdhci_pci_fixes sdhci_intel_byt_emmc = {
397 .quirks2 = SDHCI_QUIRK2_PRESET_VALUE_BROKEN | 444 .quirks2 = SDHCI_QUIRK2_PRESET_VALUE_BROKEN |
398 SDHCI_QUIRK2_CAPS_BIT63_FOR_HS400 | 445 SDHCI_QUIRK2_CAPS_BIT63_FOR_HS400 |
399 SDHCI_QUIRK2_STOP_WITH_TC, 446 SDHCI_QUIRK2_STOP_WITH_TC,
447 .ops = &sdhci_intel_byt_ops,
400}; 448};
401 449
402static const struct sdhci_pci_fixes sdhci_intel_byt_sdio = { 450static const struct sdhci_pci_fixes sdhci_intel_byt_sdio = {
@@ -405,6 +453,7 @@ static const struct sdhci_pci_fixes sdhci_intel_byt_sdio = {
405 SDHCI_QUIRK2_PRESET_VALUE_BROKEN, 453 SDHCI_QUIRK2_PRESET_VALUE_BROKEN,
406 .allow_runtime_pm = true, 454 .allow_runtime_pm = true,
407 .probe_slot = byt_sdio_probe_slot, 455 .probe_slot = byt_sdio_probe_slot,
456 .ops = &sdhci_intel_byt_ops,
408}; 457};
409 458
410static const struct sdhci_pci_fixes sdhci_intel_byt_sd = { 459static const struct sdhci_pci_fixes sdhci_intel_byt_sd = {
@@ -415,6 +464,7 @@ static const struct sdhci_pci_fixes sdhci_intel_byt_sd = {
415 .allow_runtime_pm = true, 464 .allow_runtime_pm = true,
416 .own_cd_for_runtime_pm = true, 465 .own_cd_for_runtime_pm = true,
417 .probe_slot = byt_sd_probe_slot, 466 .probe_slot = byt_sd_probe_slot,
467 .ops = &sdhci_intel_byt_ops,
418}; 468};
419 469
420/* Define Host controllers for Intel Merrifield platform */ 470/* Define Host controllers for Intel Merrifield platform */
@@ -1648,7 +1698,9 @@ static struct sdhci_pci_slot *sdhci_pci_probe_slot(
1648 } 1698 }
1649 1699
1650 host->hw_name = "PCI"; 1700 host->hw_name = "PCI";
1651 host->ops = &sdhci_pci_ops; 1701 host->ops = chip->fixes && chip->fixes->ops ?
1702 chip->fixes->ops :
1703 &sdhci_pci_ops;
1652 host->quirks = chip->quirks; 1704 host->quirks = chip->quirks;
1653 host->quirks2 = chip->quirks2; 1705 host->quirks2 = chip->quirks2;
1654 1706
diff --git a/drivers/mmc/host/sdhci-pci.h b/drivers/mmc/host/sdhci-pci.h
index 9c7c08b93223..6bccf56bc5ff 100644
--- a/drivers/mmc/host/sdhci-pci.h
+++ b/drivers/mmc/host/sdhci-pci.h
@@ -65,6 +65,8 @@ struct sdhci_pci_fixes {
65 65
66 int (*suspend) (struct sdhci_pci_chip *); 66 int (*suspend) (struct sdhci_pci_chip *);
67 int (*resume) (struct sdhci_pci_chip *); 67 int (*resume) (struct sdhci_pci_chip *);
68
69 const struct sdhci_ops *ops;
68}; 70};
69 71
70struct sdhci_pci_slot { 72struct sdhci_pci_slot {
diff --git a/drivers/mmc/host/sdhci-pxav3.c b/drivers/mmc/host/sdhci-pxav3.c
index dd1938d341f7..d0f5c05fbc19 100644
--- a/drivers/mmc/host/sdhci-pxav3.c
+++ b/drivers/mmc/host/sdhci-pxav3.c
@@ -315,7 +315,7 @@ static void pxav3_set_power(struct sdhci_host *host, unsigned char mode,
315 struct mmc_host *mmc = host->mmc; 315 struct mmc_host *mmc = host->mmc;
316 u8 pwr = host->pwr; 316 u8 pwr = host->pwr;
317 317
318 sdhci_set_power(host, mode, vdd); 318 sdhci_set_power_noreg(host, mode, vdd);
319 319
320 if (host->pwr == pwr) 320 if (host->pwr == pwr)
321 return; 321 return;
diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
index 48055666c655..42ef3ebb1d8c 100644
--- a/drivers/mmc/host/sdhci.c
+++ b/drivers/mmc/host/sdhci.c
@@ -687,7 +687,7 @@ static u8 sdhci_calc_timeout(struct sdhci_host *host, struct mmc_command *cmd)
687 * host->clock is in Hz. target_timeout is in us. 687 * host->clock is in Hz. target_timeout is in us.
688 * Hence, us = 1000000 * cycles / Hz. Round up. 688 * Hence, us = 1000000 * cycles / Hz. Round up.
689 */ 689 */
690 val = 1000000 * data->timeout_clks; 690 val = 1000000ULL * data->timeout_clks;
691 if (do_div(val, host->clock)) 691 if (do_div(val, host->clock))
692 target_timeout++; 692 target_timeout++;
693 target_timeout += val; 693 target_timeout += val;
@@ -1077,6 +1077,10 @@ void sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd)
1077 /* Initially, a command has no error */ 1077 /* Initially, a command has no error */
1078 cmd->error = 0; 1078 cmd->error = 0;
1079 1079
1080 if ((host->quirks2 & SDHCI_QUIRK2_STOP_WITH_TC) &&
1081 cmd->opcode == MMC_STOP_TRANSMISSION)
1082 cmd->flags |= MMC_RSP_BUSY;
1083
1080 /* Wait max 10 ms */ 1084 /* Wait max 10 ms */
1081 timeout = 10; 1085 timeout = 10;
1082 1086
@@ -1390,8 +1394,8 @@ static void sdhci_set_power_reg(struct sdhci_host *host, unsigned char mode,
1390 sdhci_writeb(host, 0, SDHCI_POWER_CONTROL); 1394 sdhci_writeb(host, 0, SDHCI_POWER_CONTROL);
1391} 1395}
1392 1396
1393void sdhci_set_power(struct sdhci_host *host, unsigned char mode, 1397void sdhci_set_power_noreg(struct sdhci_host *host, unsigned char mode,
1394 unsigned short vdd) 1398 unsigned short vdd)
1395{ 1399{
1396 u8 pwr = 0; 1400 u8 pwr = 0;
1397 1401
@@ -1455,20 +1459,17 @@ void sdhci_set_power(struct sdhci_host *host, unsigned char mode,
1455 mdelay(10); 1459 mdelay(10);
1456 } 1460 }
1457} 1461}
1458EXPORT_SYMBOL_GPL(sdhci_set_power); 1462EXPORT_SYMBOL_GPL(sdhci_set_power_noreg);
1459 1463
1460static void __sdhci_set_power(struct sdhci_host *host, unsigned char mode, 1464void sdhci_set_power(struct sdhci_host *host, unsigned char mode,
1461 unsigned short vdd) 1465 unsigned short vdd)
1462{ 1466{
1463 struct mmc_host *mmc = host->mmc; 1467 if (IS_ERR(host->mmc->supply.vmmc))
1464 1468 sdhci_set_power_noreg(host, mode, vdd);
1465 if (host->ops->set_power)
1466 host->ops->set_power(host, mode, vdd);
1467 else if (!IS_ERR(mmc->supply.vmmc))
1468 sdhci_set_power_reg(host, mode, vdd);
1469 else 1469 else
1470 sdhci_set_power(host, mode, vdd); 1470 sdhci_set_power_reg(host, mode, vdd);
1471} 1471}
1472EXPORT_SYMBOL_GPL(sdhci_set_power);
1472 1473
1473/*****************************************************************************\ 1474/*****************************************************************************\
1474 * * 1475 * *
@@ -1609,7 +1610,10 @@ static void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
1609 } 1610 }
1610 } 1611 }
1611 1612
1612 __sdhci_set_power(host, ios->power_mode, ios->vdd); 1613 if (host->ops->set_power)
1614 host->ops->set_power(host, ios->power_mode, ios->vdd);
1615 else
1616 sdhci_set_power(host, ios->power_mode, ios->vdd);
1613 1617
1614 if (host->ops->platform_send_init_74_clocks) 1618 if (host->ops->platform_send_init_74_clocks)
1615 host->ops->platform_send_init_74_clocks(host, ios->power_mode); 1619 host->ops->platform_send_init_74_clocks(host, ios->power_mode);
@@ -2082,6 +2086,10 @@ static int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode)
2082 2086
2083 if (!host->tuning_done) { 2087 if (!host->tuning_done) {
2084 pr_info(DRIVER_NAME ": Timeout waiting for Buffer Read Ready interrupt during tuning procedure, falling back to fixed sampling clock\n"); 2088 pr_info(DRIVER_NAME ": Timeout waiting for Buffer Read Ready interrupt during tuning procedure, falling back to fixed sampling clock\n");
2089
2090 sdhci_do_reset(host, SDHCI_RESET_CMD);
2091 sdhci_do_reset(host, SDHCI_RESET_DATA);
2092
2085 ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2); 2093 ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2);
2086 ctrl &= ~SDHCI_CTRL_TUNED_CLK; 2094 ctrl &= ~SDHCI_CTRL_TUNED_CLK;
2087 ctrl &= ~SDHCI_CTRL_EXEC_TUNING; 2095 ctrl &= ~SDHCI_CTRL_EXEC_TUNING;
@@ -2282,10 +2290,8 @@ static bool sdhci_request_done(struct sdhci_host *host)
2282 2290
2283 for (i = 0; i < SDHCI_MAX_MRQS; i++) { 2291 for (i = 0; i < SDHCI_MAX_MRQS; i++) {
2284 mrq = host->mrqs_done[i]; 2292 mrq = host->mrqs_done[i];
2285 if (mrq) { 2293 if (mrq)
2286 host->mrqs_done[i] = NULL;
2287 break; 2294 break;
2288 }
2289 } 2295 }
2290 2296
2291 if (!mrq) { 2297 if (!mrq) {
@@ -2316,6 +2322,17 @@ static bool sdhci_request_done(struct sdhci_host *host)
2316 * upon error conditions. 2322 * upon error conditions.
2317 */ 2323 */
2318 if (sdhci_needs_reset(host, mrq)) { 2324 if (sdhci_needs_reset(host, mrq)) {
2325 /*
2326 * Do not finish until command and data lines are available for
2327 * reset. Note there can only be one other mrq, so it cannot
2328 * also be in mrqs_done, otherwise host->cmd and host->data_cmd
2329 * would both be null.
2330 */
2331 if (host->cmd || host->data_cmd) {
2332 spin_unlock_irqrestore(&host->lock, flags);
2333 return true;
2334 }
2335
2319 /* Some controllers need this kick or reset won't work here */ 2336 /* Some controllers need this kick or reset won't work here */
2320 if (host->quirks & SDHCI_QUIRK_CLOCK_BEFORE_RESET) 2337 if (host->quirks & SDHCI_QUIRK_CLOCK_BEFORE_RESET)
2321 /* This is to force an update */ 2338 /* This is to force an update */
@@ -2323,10 +2340,8 @@ static bool sdhci_request_done(struct sdhci_host *host)
2323 2340
2324 /* Spec says we should do both at the same time, but Ricoh 2341 /* Spec says we should do both at the same time, but Ricoh
2325 controllers do not like that. */ 2342 controllers do not like that. */
2326 if (!host->cmd) 2343 sdhci_do_reset(host, SDHCI_RESET_CMD);
2327 sdhci_do_reset(host, SDHCI_RESET_CMD); 2344 sdhci_do_reset(host, SDHCI_RESET_DATA);
2328 if (!host->data_cmd)
2329 sdhci_do_reset(host, SDHCI_RESET_DATA);
2330 2345
2331 host->pending_reset = false; 2346 host->pending_reset = false;
2332 } 2347 }
@@ -2334,6 +2349,8 @@ static bool sdhci_request_done(struct sdhci_host *host)
2334 if (!sdhci_has_requests(host)) 2349 if (!sdhci_has_requests(host))
2335 sdhci_led_deactivate(host); 2350 sdhci_led_deactivate(host);
2336 2351
2352 host->mrqs_done[i] = NULL;
2353
2337 mmiowb(); 2354 mmiowb();
2338 spin_unlock_irqrestore(&host->lock, flags); 2355 spin_unlock_irqrestore(&host->lock, flags);
2339 2356
@@ -2409,7 +2426,7 @@ static void sdhci_timeout_data_timer(unsigned long data)
2409 * * 2426 * *
2410\*****************************************************************************/ 2427\*****************************************************************************/
2411 2428
2412static void sdhci_cmd_irq(struct sdhci_host *host, u32 intmask, u32 *mask) 2429static void sdhci_cmd_irq(struct sdhci_host *host, u32 intmask)
2413{ 2430{
2414 if (!host->cmd) { 2431 if (!host->cmd) {
2415 /* 2432 /*
@@ -2453,11 +2470,6 @@ static void sdhci_cmd_irq(struct sdhci_host *host, u32 intmask, u32 *mask)
2453 return; 2470 return;
2454 } 2471 }
2455 2472
2456 if ((host->quirks2 & SDHCI_QUIRK2_STOP_WITH_TC) &&
2457 !(host->cmd->flags & MMC_RSP_BUSY) && !host->data &&
2458 host->cmd->opcode == MMC_STOP_TRANSMISSION)
2459 *mask &= ~SDHCI_INT_DATA_END;
2460
2461 if (intmask & SDHCI_INT_RESPONSE) 2473 if (intmask & SDHCI_INT_RESPONSE)
2462 sdhci_finish_command(host); 2474 sdhci_finish_command(host);
2463} 2475}
@@ -2513,9 +2525,6 @@ static void sdhci_data_irq(struct sdhci_host *host, u32 intmask)
2513 if (!host->data) { 2525 if (!host->data) {
2514 struct mmc_command *data_cmd = host->data_cmd; 2526 struct mmc_command *data_cmd = host->data_cmd;
2515 2527
2516 if (data_cmd)
2517 host->data_cmd = NULL;
2518
2519 /* 2528 /*
2520 * The "data complete" interrupt is also used to 2529 * The "data complete" interrupt is also used to
2521 * indicate that a busy state has ended. See comment 2530 * indicate that a busy state has ended. See comment
@@ -2523,11 +2532,13 @@ static void sdhci_data_irq(struct sdhci_host *host, u32 intmask)
2523 */ 2532 */
2524 if (data_cmd && (data_cmd->flags & MMC_RSP_BUSY)) { 2533 if (data_cmd && (data_cmd->flags & MMC_RSP_BUSY)) {
2525 if (intmask & SDHCI_INT_DATA_TIMEOUT) { 2534 if (intmask & SDHCI_INT_DATA_TIMEOUT) {
2535 host->data_cmd = NULL;
2526 data_cmd->error = -ETIMEDOUT; 2536 data_cmd->error = -ETIMEDOUT;
2527 sdhci_finish_mrq(host, data_cmd->mrq); 2537 sdhci_finish_mrq(host, data_cmd->mrq);
2528 return; 2538 return;
2529 } 2539 }
2530 if (intmask & SDHCI_INT_DATA_END) { 2540 if (intmask & SDHCI_INT_DATA_END) {
2541 host->data_cmd = NULL;
2531 /* 2542 /*
2532 * Some cards handle busy-end interrupt 2543 * Some cards handle busy-end interrupt
2533 * before the command completed, so make 2544 * before the command completed, so make
@@ -2680,8 +2691,7 @@ static irqreturn_t sdhci_irq(int irq, void *dev_id)
2680 } 2691 }
2681 2692
2682 if (intmask & SDHCI_INT_CMD_MASK) 2693 if (intmask & SDHCI_INT_CMD_MASK)
2683 sdhci_cmd_irq(host, intmask & SDHCI_INT_CMD_MASK, 2694 sdhci_cmd_irq(host, intmask & SDHCI_INT_CMD_MASK);
2684 &intmask);
2685 2695
2686 if (intmask & SDHCI_INT_DATA_MASK) 2696 if (intmask & SDHCI_INT_DATA_MASK)
2687 sdhci_data_irq(host, intmask & SDHCI_INT_DATA_MASK); 2697 sdhci_data_irq(host, intmask & SDHCI_INT_DATA_MASK);
@@ -2914,6 +2924,10 @@ int sdhci_runtime_resume_host(struct sdhci_host *host)
2914 spin_unlock_irqrestore(&host->lock, flags); 2924 spin_unlock_irqrestore(&host->lock, flags);
2915 } 2925 }
2916 2926
2927 if ((mmc->caps2 & MMC_CAP2_HS400_ES) &&
2928 mmc->ops->hs400_enhanced_strobe)
2929 mmc->ops->hs400_enhanced_strobe(mmc, &mmc->ios);
2930
2917 spin_lock_irqsave(&host->lock, flags); 2931 spin_lock_irqsave(&host->lock, flags);
2918 2932
2919 host->runtime_suspended = false; 2933 host->runtime_suspended = false;
diff --git a/drivers/mmc/host/sdhci.h b/drivers/mmc/host/sdhci.h
index c722cd23205c..2570455b219a 100644
--- a/drivers/mmc/host/sdhci.h
+++ b/drivers/mmc/host/sdhci.h
@@ -73,6 +73,7 @@
73#define SDHCI_DATA_LVL_MASK 0x00F00000 73#define SDHCI_DATA_LVL_MASK 0x00F00000
74#define SDHCI_DATA_LVL_SHIFT 20 74#define SDHCI_DATA_LVL_SHIFT 20
75#define SDHCI_DATA_0_LVL_MASK 0x00100000 75#define SDHCI_DATA_0_LVL_MASK 0x00100000
76#define SDHCI_CMD_LVL 0x01000000
76 77
77#define SDHCI_HOST_CONTROL 0x28 78#define SDHCI_HOST_CONTROL 0x28
78#define SDHCI_CTRL_LED 0x01 79#define SDHCI_CTRL_LED 0x01
@@ -683,6 +684,8 @@ u16 sdhci_calc_clk(struct sdhci_host *host, unsigned int clock,
683void sdhci_set_clock(struct sdhci_host *host, unsigned int clock); 684void sdhci_set_clock(struct sdhci_host *host, unsigned int clock);
684void sdhci_set_power(struct sdhci_host *host, unsigned char mode, 685void sdhci_set_power(struct sdhci_host *host, unsigned char mode,
685 unsigned short vdd); 686 unsigned short vdd);
687void sdhci_set_power_noreg(struct sdhci_host *host, unsigned char mode,
688 unsigned short vdd);
686void sdhci_set_bus_width(struct sdhci_host *host, int width); 689void sdhci_set_bus_width(struct sdhci_host *host, int width);
687void sdhci_reset(struct sdhci_host *host, u8 mask); 690void sdhci_reset(struct sdhci_host *host, u8 mask);
688void sdhci_set_uhs_signaling(struct sdhci_host *host, unsigned timing); 691void sdhci_set_uhs_signaling(struct sdhci_host *host, unsigned timing);
diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-lib.c b/drivers/mtd/nand/gpmi-nand/gpmi-lib.c
index 0f68a99fc4ad..141bd70a49c2 100644
--- a/drivers/mtd/nand/gpmi-nand/gpmi-lib.c
+++ b/drivers/mtd/nand/gpmi-nand/gpmi-lib.c
@@ -161,7 +161,7 @@ int gpmi_init(struct gpmi_nand_data *this)
161 161
162 ret = gpmi_enable_clk(this); 162 ret = gpmi_enable_clk(this);
163 if (ret) 163 if (ret)
164 goto err_out; 164 return ret;
165 ret = gpmi_reset_block(r->gpmi_regs, false); 165 ret = gpmi_reset_block(r->gpmi_regs, false);
166 if (ret) 166 if (ret)
167 goto err_out; 167 goto err_out;
@@ -197,6 +197,7 @@ int gpmi_init(struct gpmi_nand_data *this)
197 gpmi_disable_clk(this); 197 gpmi_disable_clk(this);
198 return 0; 198 return 0;
199err_out: 199err_out:
200 gpmi_disable_clk(this);
200 return ret; 201 return ret;
201} 202}
202 203
@@ -270,7 +271,7 @@ int bch_set_geometry(struct gpmi_nand_data *this)
270 271
271 ret = gpmi_enable_clk(this); 272 ret = gpmi_enable_clk(this);
272 if (ret) 273 if (ret)
273 goto err_out; 274 return ret;
274 275
275 /* 276 /*
276 * Due to erratum #2847 of the MX23, the BCH cannot be soft reset on this 277 * Due to erratum #2847 of the MX23, the BCH cannot be soft reset on this
@@ -308,6 +309,7 @@ int bch_set_geometry(struct gpmi_nand_data *this)
308 gpmi_disable_clk(this); 309 gpmi_disable_clk(this);
309 return 0; 310 return 0;
310err_out: 311err_out:
312 gpmi_disable_clk(this);
311 return ret; 313 return ret;
312} 314}
313 315
diff --git a/drivers/mtd/nand/mtk_ecc.c b/drivers/mtd/nand/mtk_ecc.c
index d54f666417e1..dbf256217b3e 100644
--- a/drivers/mtd/nand/mtk_ecc.c
+++ b/drivers/mtd/nand/mtk_ecc.c
@@ -86,6 +86,8 @@ struct mtk_ecc {
86 struct completion done; 86 struct completion done;
87 struct mutex lock; 87 struct mutex lock;
88 u32 sectors; 88 u32 sectors;
89
90 u8 eccdata[112];
89}; 91};
90 92
91static inline void mtk_ecc_wait_idle(struct mtk_ecc *ecc, 93static inline void mtk_ecc_wait_idle(struct mtk_ecc *ecc,
@@ -366,9 +368,8 @@ int mtk_ecc_encode(struct mtk_ecc *ecc, struct mtk_ecc_config *config,
366 u8 *data, u32 bytes) 368 u8 *data, u32 bytes)
367{ 369{
368 dma_addr_t addr; 370 dma_addr_t addr;
369 u8 *p; 371 u32 len;
370 u32 len, i, val; 372 int ret;
371 int ret = 0;
372 373
373 addr = dma_map_single(ecc->dev, data, bytes, DMA_TO_DEVICE); 374 addr = dma_map_single(ecc->dev, data, bytes, DMA_TO_DEVICE);
374 ret = dma_mapping_error(ecc->dev, addr); 375 ret = dma_mapping_error(ecc->dev, addr);
@@ -393,14 +394,12 @@ int mtk_ecc_encode(struct mtk_ecc *ecc, struct mtk_ecc_config *config,
393 394
394 /* Program ECC bytes to OOB: per sector oob = FDM + ECC + SPARE */ 395 /* Program ECC bytes to OOB: per sector oob = FDM + ECC + SPARE */
395 len = (config->strength * ECC_PARITY_BITS + 7) >> 3; 396 len = (config->strength * ECC_PARITY_BITS + 7) >> 3;
396 p = data + bytes;
397 397
398 /* write the parity bytes generated by the ECC back to the OOB region */ 398 /* write the parity bytes generated by the ECC back to temp buffer */
399 for (i = 0; i < len; i++) { 399 __ioread32_copy(ecc->eccdata, ecc->regs + ECC_ENCPAR(0), round_up(len, 4));
400 if ((i % 4) == 0) 400
401 val = readl(ecc->regs + ECC_ENCPAR(i / 4)); 401 /* copy into possibly unaligned OOB region with actual length */
402 p[i] = (val >> ((i % 4) * 8)) & 0xff; 402 memcpy(data + bytes, ecc->eccdata, len);
403 }
404timeout: 403timeout:
405 404
406 dma_unmap_single(ecc->dev, addr, bytes, DMA_TO_DEVICE); 405 dma_unmap_single(ecc->dev, addr, bytes, DMA_TO_DEVICE);
diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index e5718e5ecf92..3bde96a3f7bf 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -1095,10 +1095,11 @@ static void nand_release_data_interface(struct nand_chip *chip)
1095/** 1095/**
1096 * nand_reset - Reset and initialize a NAND device 1096 * nand_reset - Reset and initialize a NAND device
1097 * @chip: The NAND chip 1097 * @chip: The NAND chip
1098 * @chipnr: Internal die id
1098 * 1099 *
1099 * Returns 0 for success or negative error code otherwise 1100 * Returns 0 for success or negative error code otherwise
1100 */ 1101 */
1101int nand_reset(struct nand_chip *chip) 1102int nand_reset(struct nand_chip *chip, int chipnr)
1102{ 1103{
1103 struct mtd_info *mtd = nand_to_mtd(chip); 1104 struct mtd_info *mtd = nand_to_mtd(chip);
1104 int ret; 1105 int ret;
@@ -1107,9 +1108,17 @@ int nand_reset(struct nand_chip *chip)
1107 if (ret) 1108 if (ret)
1108 return ret; 1109 return ret;
1109 1110
1111 /*
1112 * The CS line has to be released before we can apply the new NAND
1113 * interface settings, hence this weird ->select_chip() dance.
1114 */
1115 chip->select_chip(mtd, chipnr);
1110 chip->cmdfunc(mtd, NAND_CMD_RESET, -1, -1); 1116 chip->cmdfunc(mtd, NAND_CMD_RESET, -1, -1);
1117 chip->select_chip(mtd, -1);
1111 1118
1119 chip->select_chip(mtd, chipnr);
1112 ret = nand_setup_data_interface(chip); 1120 ret = nand_setup_data_interface(chip);
1121 chip->select_chip(mtd, -1);
1113 if (ret) 1122 if (ret)
1114 return ret; 1123 return ret;
1115 1124
@@ -1185,8 +1194,6 @@ int nand_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
1185 /* Shift to get chip number */ 1194 /* Shift to get chip number */
1186 chipnr = ofs >> chip->chip_shift; 1195 chipnr = ofs >> chip->chip_shift;
1187 1196
1188 chip->select_chip(mtd, chipnr);
1189
1190 /* 1197 /*
1191 * Reset the chip. 1198 * Reset the chip.
1192 * If we want to check the WP through READ STATUS and check the bit 7 1199 * If we want to check the WP through READ STATUS and check the bit 7
@@ -1194,7 +1201,9 @@ int nand_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
1194 * some operation can also clear the bit 7 of status register 1201 * some operation can also clear the bit 7 of status register
1195 * eg. erase/program a locked block 1202 * eg. erase/program a locked block
1196 */ 1203 */
1197 nand_reset(chip); 1204 nand_reset(chip, chipnr);
1205
1206 chip->select_chip(mtd, chipnr);
1198 1207
1199 /* Check, if it is write protected */ 1208 /* Check, if it is write protected */
1200 if (nand_check_wp(mtd)) { 1209 if (nand_check_wp(mtd)) {
@@ -1244,8 +1253,6 @@ int nand_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
1244 /* Shift to get chip number */ 1253 /* Shift to get chip number */
1245 chipnr = ofs >> chip->chip_shift; 1254 chipnr = ofs >> chip->chip_shift;
1246 1255
1247 chip->select_chip(mtd, chipnr);
1248
1249 /* 1256 /*
1250 * Reset the chip. 1257 * Reset the chip.
1251 * If we want to check the WP through READ STATUS and check the bit 7 1258 * If we want to check the WP through READ STATUS and check the bit 7
@@ -1253,7 +1260,9 @@ int nand_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
1253 * some operation can also clear the bit 7 of status register 1260 * some operation can also clear the bit 7 of status register
1254 * eg. erase/program a locked block 1261 * eg. erase/program a locked block
1255 */ 1262 */
1256 nand_reset(chip); 1263 nand_reset(chip, chipnr);
1264
1265 chip->select_chip(mtd, chipnr);
1257 1266
1258 /* Check, if it is write protected */ 1267 /* Check, if it is write protected */
1259 if (nand_check_wp(mtd)) { 1268 if (nand_check_wp(mtd)) {
@@ -2940,10 +2949,6 @@ static int nand_do_write_oob(struct mtd_info *mtd, loff_t to,
2940 } 2949 }
2941 2950
2942 chipnr = (int)(to >> chip->chip_shift); 2951 chipnr = (int)(to >> chip->chip_shift);
2943 chip->select_chip(mtd, chipnr);
2944
2945 /* Shift to get page */
2946 page = (int)(to >> chip->page_shift);
2947 2952
2948 /* 2953 /*
2949 * Reset the chip. Some chips (like the Toshiba TC5832DC found in one 2954 * Reset the chip. Some chips (like the Toshiba TC5832DC found in one
@@ -2951,7 +2956,12 @@ static int nand_do_write_oob(struct mtd_info *mtd, loff_t to,
2951 * if we don't do this. I have no clue why, but I seem to have 'fixed' 2956 * if we don't do this. I have no clue why, but I seem to have 'fixed'
2952 * it in the doc2000 driver in August 1999. dwmw2. 2957 * it in the doc2000 driver in August 1999. dwmw2.
2953 */ 2958 */
2954 nand_reset(chip); 2959 nand_reset(chip, chipnr);
2960
2961 chip->select_chip(mtd, chipnr);
2962
2963 /* Shift to get page */
2964 page = (int)(to >> chip->page_shift);
2955 2965
2956 /* Check, if it is write protected */ 2966 /* Check, if it is write protected */
2957 if (nand_check_wp(mtd)) { 2967 if (nand_check_wp(mtd)) {
@@ -3984,14 +3994,14 @@ static struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd,
3984 int i, maf_idx; 3994 int i, maf_idx;
3985 u8 id_data[8]; 3995 u8 id_data[8];
3986 3996
3987 /* Select the device */
3988 chip->select_chip(mtd, 0);
3989
3990 /* 3997 /*
3991 * Reset the chip, required by some chips (e.g. Micron MT29FxGxxxxx) 3998 * Reset the chip, required by some chips (e.g. Micron MT29FxGxxxxx)
3992 * after power-up. 3999 * after power-up.
3993 */ 4000 */
3994 nand_reset(chip); 4001 nand_reset(chip, 0);
4002
4003 /* Select the device */
4004 chip->select_chip(mtd, 0);
3995 4005
3996 /* Send the command for reading device ID */ 4006 /* Send the command for reading device ID */
3997 chip->cmdfunc(mtd, NAND_CMD_READID, 0x00, -1); 4007 chip->cmdfunc(mtd, NAND_CMD_READID, 0x00, -1);
@@ -4329,17 +4339,31 @@ int nand_scan_ident(struct mtd_info *mtd, int maxchips,
4329 return PTR_ERR(type); 4339 return PTR_ERR(type);
4330 } 4340 }
4331 4341
4342 /* Initialize the ->data_interface field. */
4332 ret = nand_init_data_interface(chip); 4343 ret = nand_init_data_interface(chip);
4333 if (ret) 4344 if (ret)
4334 return ret; 4345 return ret;
4335 4346
4347 /*
4348 * Setup the data interface correctly on the chip and controller side.
4349 * This explicit call to nand_setup_data_interface() is only required
4350 * for the first die, because nand_reset() has been called before
4351 * ->data_interface and ->default_onfi_timing_mode were set.
4352 * For the other dies, nand_reset() will automatically switch to the
4353 * best mode for us.
4354 */
4355 ret = nand_setup_data_interface(chip);
4356 if (ret)
4357 return ret;
4358
4336 chip->select_chip(mtd, -1); 4359 chip->select_chip(mtd, -1);
4337 4360
4338 /* Check for a chip array */ 4361 /* Check for a chip array */
4339 for (i = 1; i < maxchips; i++) { 4362 for (i = 1; i < maxchips; i++) {
4340 chip->select_chip(mtd, i);
4341 /* See comment in nand_get_flash_type for reset */ 4363 /* See comment in nand_get_flash_type for reset */
4342 nand_reset(chip); 4364 nand_reset(chip, i);
4365
4366 chip->select_chip(mtd, i);
4343 /* Send the command for reading device ID */ 4367 /* Send the command for reading device ID */
4344 chip->cmdfunc(mtd, NAND_CMD_READID, 0x00, -1); 4368 chip->cmdfunc(mtd, NAND_CMD_READID, 0x00, -1);
4345 /* Read manufacturer and device IDs */ 4369 /* Read manufacturer and device IDs */
diff --git a/drivers/mtd/ubi/eba.c b/drivers/mtd/ubi/eba.c
index 95c4048a371e..388e46be6ad9 100644
--- a/drivers/mtd/ubi/eba.c
+++ b/drivers/mtd/ubi/eba.c
@@ -741,6 +741,7 @@ static int try_recover_peb(struct ubi_volume *vol, int pnum, int lnum,
741 goto out_put; 741 goto out_put;
742 } 742 }
743 743
744 vid_hdr = ubi_get_vid_hdr(vidb);
744 ubi_assert(vid_hdr->vol_type == UBI_VID_DYNAMIC); 745 ubi_assert(vid_hdr->vol_type == UBI_VID_DYNAMIC);
745 746
746 mutex_lock(&ubi->buf_mutex); 747 mutex_lock(&ubi->buf_mutex);
diff --git a/drivers/mtd/ubi/fastmap.c b/drivers/mtd/ubi/fastmap.c
index d6384d965788..c1f5c29e458e 100644
--- a/drivers/mtd/ubi/fastmap.c
+++ b/drivers/mtd/ubi/fastmap.c
@@ -287,7 +287,7 @@ static int update_vol(struct ubi_device *ubi, struct ubi_attach_info *ai,
287 287
288 /* new_aeb is newer */ 288 /* new_aeb is newer */
289 if (cmp_res & 1) { 289 if (cmp_res & 1) {
290 victim = ubi_alloc_aeb(ai, aeb->ec, aeb->pnum); 290 victim = ubi_alloc_aeb(ai, aeb->pnum, aeb->ec);
291 if (!victim) 291 if (!victim)
292 return -ENOMEM; 292 return -ENOMEM;
293 293
@@ -707,11 +707,11 @@ static int ubi_attach_fastmap(struct ubi_device *ubi,
707 fmvhdr->vol_type, 707 fmvhdr->vol_type,
708 be32_to_cpu(fmvhdr->last_eb_bytes)); 708 be32_to_cpu(fmvhdr->last_eb_bytes));
709 709
710 if (!av) 710 if (IS_ERR(av)) {
711 goto fail_bad; 711 if (PTR_ERR(av) == -EEXIST)
712 if (PTR_ERR(av) == -EINVAL) { 712 ubi_err(ubi, "volume (ID %i) already exists",
713 ubi_err(ubi, "volume (ID %i) already exists", 713 fmvhdr->vol_id);
714 fmvhdr->vol_id); 714
715 goto fail_bad; 715 goto fail_bad;
716 } 716 }
717 717
diff --git a/drivers/net/can/sja1000/plx_pci.c b/drivers/net/can/sja1000/plx_pci.c
index 3eb7430dffbf..f8ff25c8ee2e 100644
--- a/drivers/net/can/sja1000/plx_pci.c
+++ b/drivers/net/can/sja1000/plx_pci.c
@@ -142,6 +142,9 @@ struct plx_pci_card {
142#define CTI_PCI_VENDOR_ID 0x12c4 142#define CTI_PCI_VENDOR_ID 0x12c4
143#define CTI_PCI_DEVICE_ID_CRG001 0x0900 143#define CTI_PCI_DEVICE_ID_CRG001 0x0900
144 144
145#define MOXA_PCI_VENDOR_ID 0x1393
146#define MOXA_PCI_DEVICE_ID 0x0100
147
145static void plx_pci_reset_common(struct pci_dev *pdev); 148static void plx_pci_reset_common(struct pci_dev *pdev);
146static void plx9056_pci_reset_common(struct pci_dev *pdev); 149static void plx9056_pci_reset_common(struct pci_dev *pdev);
147static void plx_pci_reset_marathon_pci(struct pci_dev *pdev); 150static void plx_pci_reset_marathon_pci(struct pci_dev *pdev);
@@ -258,6 +261,14 @@ static struct plx_pci_card_info plx_pci_card_info_elcus = {
258 /* based on PLX9030 */ 261 /* based on PLX9030 */
259}; 262};
260 263
264static struct plx_pci_card_info plx_pci_card_info_moxa = {
265 "MOXA", 2,
266 PLX_PCI_CAN_CLOCK, PLX_PCI_OCR, PLX_PCI_CDR,
267 {0, 0x00, 0x00}, { {0, 0x00, 0x80}, {1, 0x00, 0x80} },
268 &plx_pci_reset_common
269 /* based on PLX9052 */
270};
271
261static const struct pci_device_id plx_pci_tbl[] = { 272static const struct pci_device_id plx_pci_tbl[] = {
262 { 273 {
263 /* Adlink PCI-7841/cPCI-7841 */ 274 /* Adlink PCI-7841/cPCI-7841 */
@@ -357,6 +368,13 @@ static const struct pci_device_id plx_pci_tbl[] = {
357 0, 0, 368 0, 0,
358 (kernel_ulong_t)&plx_pci_card_info_elcus 369 (kernel_ulong_t)&plx_pci_card_info_elcus
359 }, 370 },
371 {
372 /* moxa */
373 MOXA_PCI_VENDOR_ID, MOXA_PCI_DEVICE_ID,
374 PCI_ANY_ID, PCI_ANY_ID,
375 0, 0,
376 (kernel_ulong_t)&plx_pci_card_info_moxa
377 },
360 { 0,} 378 { 0,}
361}; 379};
362MODULE_DEVICE_TABLE(pci, plx_pci_tbl); 380MODULE_DEVICE_TABLE(pci, plx_pci_tbl);
diff --git a/drivers/net/can/usb/peak_usb/pcan_ucan.h b/drivers/net/can/usb/peak_usb/pcan_ucan.h
index e8fc4952c6b0..2147678f0225 100644
--- a/drivers/net/can/usb/peak_usb/pcan_ucan.h
+++ b/drivers/net/can/usb/peak_usb/pcan_ucan.h
@@ -43,11 +43,22 @@ struct __packed pucan_command {
43 u16 args[3]; 43 u16 args[3];
44}; 44};
45 45
46#define PUCAN_TSLOW_BRP_BITS 10
47#define PUCAN_TSLOW_TSGEG1_BITS 8
48#define PUCAN_TSLOW_TSGEG2_BITS 7
49#define PUCAN_TSLOW_SJW_BITS 7
50
51#define PUCAN_TSLOW_BRP_MASK ((1 << PUCAN_TSLOW_BRP_BITS) - 1)
52#define PUCAN_TSLOW_TSEG1_MASK ((1 << PUCAN_TSLOW_TSGEG1_BITS) - 1)
53#define PUCAN_TSLOW_TSEG2_MASK ((1 << PUCAN_TSLOW_TSGEG2_BITS) - 1)
54#define PUCAN_TSLOW_SJW_MASK ((1 << PUCAN_TSLOW_SJW_BITS) - 1)
55
46/* uCAN TIMING_SLOW command fields */ 56/* uCAN TIMING_SLOW command fields */
47#define PUCAN_TSLOW_SJW_T(s, t) (((s) & 0xf) | ((!!(t)) << 7)) 57#define PUCAN_TSLOW_SJW_T(s, t) (((s) & PUCAN_TSLOW_SJW_MASK) | \
48#define PUCAN_TSLOW_TSEG2(t) ((t) & 0xf) 58 ((!!(t)) << 7))
49#define PUCAN_TSLOW_TSEG1(t) ((t) & 0x3f) 59#define PUCAN_TSLOW_TSEG2(t) ((t) & PUCAN_TSLOW_TSEG2_MASK)
50#define PUCAN_TSLOW_BRP(b) ((b) & 0x3ff) 60#define PUCAN_TSLOW_TSEG1(t) ((t) & PUCAN_TSLOW_TSEG1_MASK)
61#define PUCAN_TSLOW_BRP(b) ((b) & PUCAN_TSLOW_BRP_MASK)
51 62
52struct __packed pucan_timing_slow { 63struct __packed pucan_timing_slow {
53 __le16 opcode_channel; 64 __le16 opcode_channel;
@@ -60,11 +71,21 @@ struct __packed pucan_timing_slow {
60 __le16 brp; /* BaudRate Prescaler */ 71 __le16 brp; /* BaudRate Prescaler */
61}; 72};
62 73
74#define PUCAN_TFAST_BRP_BITS 10
75#define PUCAN_TFAST_TSGEG1_BITS 5
76#define PUCAN_TFAST_TSGEG2_BITS 4
77#define PUCAN_TFAST_SJW_BITS 4
78
79#define PUCAN_TFAST_BRP_MASK ((1 << PUCAN_TFAST_BRP_BITS) - 1)
80#define PUCAN_TFAST_TSEG1_MASK ((1 << PUCAN_TFAST_TSGEG1_BITS) - 1)
81#define PUCAN_TFAST_TSEG2_MASK ((1 << PUCAN_TFAST_TSGEG2_BITS) - 1)
82#define PUCAN_TFAST_SJW_MASK ((1 << PUCAN_TFAST_SJW_BITS) - 1)
83
63/* uCAN TIMING_FAST command fields */ 84/* uCAN TIMING_FAST command fields */
64#define PUCAN_TFAST_SJW(s) ((s) & 0x3) 85#define PUCAN_TFAST_SJW(s) ((s) & PUCAN_TFAST_SJW_MASK)
65#define PUCAN_TFAST_TSEG2(t) ((t) & 0x7) 86#define PUCAN_TFAST_TSEG2(t) ((t) & PUCAN_TFAST_TSEG2_MASK)
66#define PUCAN_TFAST_TSEG1(t) ((t) & 0xf) 87#define PUCAN_TFAST_TSEG1(t) ((t) & PUCAN_TFAST_TSEG1_MASK)
67#define PUCAN_TFAST_BRP(b) ((b) & 0x3ff) 88#define PUCAN_TFAST_BRP(b) ((b) & PUCAN_TFAST_BRP_MASK)
68 89
69struct __packed pucan_timing_fast { 90struct __packed pucan_timing_fast {
70 __le16 opcode_channel; 91 __le16 opcode_channel;
diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_core.c b/drivers/net/can/usb/peak_usb/pcan_usb_core.c
index c06382cdfdfe..0b0302af3bd2 100644
--- a/drivers/net/can/usb/peak_usb/pcan_usb_core.c
+++ b/drivers/net/can/usb/peak_usb/pcan_usb_core.c
@@ -39,6 +39,7 @@ static struct usb_device_id peak_usb_table[] = {
39 {USB_DEVICE(PCAN_USB_VENDOR_ID, PCAN_USBPRO_PRODUCT_ID)}, 39 {USB_DEVICE(PCAN_USB_VENDOR_ID, PCAN_USBPRO_PRODUCT_ID)},
40 {USB_DEVICE(PCAN_USB_VENDOR_ID, PCAN_USBFD_PRODUCT_ID)}, 40 {USB_DEVICE(PCAN_USB_VENDOR_ID, PCAN_USBFD_PRODUCT_ID)},
41 {USB_DEVICE(PCAN_USB_VENDOR_ID, PCAN_USBPROFD_PRODUCT_ID)}, 41 {USB_DEVICE(PCAN_USB_VENDOR_ID, PCAN_USBPROFD_PRODUCT_ID)},
42 {USB_DEVICE(PCAN_USB_VENDOR_ID, PCAN_USBX6_PRODUCT_ID)},
42 {} /* Terminating entry */ 43 {} /* Terminating entry */
43}; 44};
44 45
@@ -50,6 +51,7 @@ static const struct peak_usb_adapter *const peak_usb_adapters_list[] = {
50 &pcan_usb_pro, 51 &pcan_usb_pro,
51 &pcan_usb_fd, 52 &pcan_usb_fd,
52 &pcan_usb_pro_fd, 53 &pcan_usb_pro_fd,
54 &pcan_usb_x6,
53}; 55};
54 56
55/* 57/*
@@ -868,23 +870,25 @@ lbl_free_candev:
868static void peak_usb_disconnect(struct usb_interface *intf) 870static void peak_usb_disconnect(struct usb_interface *intf)
869{ 871{
870 struct peak_usb_device *dev; 872 struct peak_usb_device *dev;
873 struct peak_usb_device *dev_prev_siblings;
871 874
872 /* unregister as many netdev devices as siblings */ 875 /* unregister as many netdev devices as siblings */
873 for (dev = usb_get_intfdata(intf); dev; dev = dev->prev_siblings) { 876 for (dev = usb_get_intfdata(intf); dev; dev = dev_prev_siblings) {
874 struct net_device *netdev = dev->netdev; 877 struct net_device *netdev = dev->netdev;
875 char name[IFNAMSIZ]; 878 char name[IFNAMSIZ];
876 879
880 dev_prev_siblings = dev->prev_siblings;
877 dev->state &= ~PCAN_USB_STATE_CONNECTED; 881 dev->state &= ~PCAN_USB_STATE_CONNECTED;
878 strncpy(name, netdev->name, IFNAMSIZ); 882 strncpy(name, netdev->name, IFNAMSIZ);
879 883
880 unregister_netdev(netdev); 884 unregister_netdev(netdev);
881 free_candev(netdev);
882 885
883 kfree(dev->cmd_buf); 886 kfree(dev->cmd_buf);
884 dev->next_siblings = NULL; 887 dev->next_siblings = NULL;
885 if (dev->adapter->dev_free) 888 if (dev->adapter->dev_free)
886 dev->adapter->dev_free(dev); 889 dev->adapter->dev_free(dev);
887 890
891 free_candev(netdev);
888 dev_info(&intf->dev, "%s removed\n", name); 892 dev_info(&intf->dev, "%s removed\n", name);
889 } 893 }
890 894
diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_core.h b/drivers/net/can/usb/peak_usb/pcan_usb_core.h
index 506fe506c9d3..3cbfb069893d 100644
--- a/drivers/net/can/usb/peak_usb/pcan_usb_core.h
+++ b/drivers/net/can/usb/peak_usb/pcan_usb_core.h
@@ -27,6 +27,7 @@
27#define PCAN_USBPRO_PRODUCT_ID 0x000d 27#define PCAN_USBPRO_PRODUCT_ID 0x000d
28#define PCAN_USBPROFD_PRODUCT_ID 0x0011 28#define PCAN_USBPROFD_PRODUCT_ID 0x0011
29#define PCAN_USBFD_PRODUCT_ID 0x0012 29#define PCAN_USBFD_PRODUCT_ID 0x0012
30#define PCAN_USBX6_PRODUCT_ID 0x0014
30 31
31#define PCAN_USB_DRIVER_NAME "peak_usb" 32#define PCAN_USB_DRIVER_NAME "peak_usb"
32 33
@@ -90,6 +91,7 @@ extern const struct peak_usb_adapter pcan_usb;
90extern const struct peak_usb_adapter pcan_usb_pro; 91extern const struct peak_usb_adapter pcan_usb_pro;
91extern const struct peak_usb_adapter pcan_usb_fd; 92extern const struct peak_usb_adapter pcan_usb_fd;
92extern const struct peak_usb_adapter pcan_usb_pro_fd; 93extern const struct peak_usb_adapter pcan_usb_pro_fd;
94extern const struct peak_usb_adapter pcan_usb_x6;
93 95
94struct peak_time_ref { 96struct peak_time_ref {
95 struct timeval tv_host_0, tv_host; 97 struct timeval tv_host_0, tv_host;
diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_fd.c b/drivers/net/can/usb/peak_usb/pcan_usb_fd.c
index ce44a033f63b..304732550f0a 100644
--- a/drivers/net/can/usb/peak_usb/pcan_usb_fd.c
+++ b/drivers/net/can/usb/peak_usb/pcan_usb_fd.c
@@ -993,24 +993,24 @@ static void pcan_usb_fd_free(struct peak_usb_device *dev)
993static const struct can_bittiming_const pcan_usb_fd_const = { 993static const struct can_bittiming_const pcan_usb_fd_const = {
994 .name = "pcan_usb_fd", 994 .name = "pcan_usb_fd",
995 .tseg1_min = 1, 995 .tseg1_min = 1,
996 .tseg1_max = 64, 996 .tseg1_max = (1 << PUCAN_TSLOW_TSGEG1_BITS),
997 .tseg2_min = 1, 997 .tseg2_min = 1,
998 .tseg2_max = 16, 998 .tseg2_max = (1 << PUCAN_TSLOW_TSGEG2_BITS),
999 .sjw_max = 16, 999 .sjw_max = (1 << PUCAN_TSLOW_SJW_BITS),
1000 .brp_min = 1, 1000 .brp_min = 1,
1001 .brp_max = 1024, 1001 .brp_max = (1 << PUCAN_TSLOW_BRP_BITS),
1002 .brp_inc = 1, 1002 .brp_inc = 1,
1003}; 1003};
1004 1004
1005static const struct can_bittiming_const pcan_usb_fd_data_const = { 1005static const struct can_bittiming_const pcan_usb_fd_data_const = {
1006 .name = "pcan_usb_fd", 1006 .name = "pcan_usb_fd",
1007 .tseg1_min = 1, 1007 .tseg1_min = 1,
1008 .tseg1_max = 16, 1008 .tseg1_max = (1 << PUCAN_TFAST_TSGEG1_BITS),
1009 .tseg2_min = 1, 1009 .tseg2_min = 1,
1010 .tseg2_max = 8, 1010 .tseg2_max = (1 << PUCAN_TFAST_TSGEG2_BITS),
1011 .sjw_max = 4, 1011 .sjw_max = (1 << PUCAN_TFAST_SJW_BITS),
1012 .brp_min = 1, 1012 .brp_min = 1,
1013 .brp_max = 1024, 1013 .brp_max = (1 << PUCAN_TFAST_BRP_BITS),
1014 .brp_inc = 1, 1014 .brp_inc = 1,
1015}; 1015};
1016 1016
@@ -1065,24 +1065,24 @@ const struct peak_usb_adapter pcan_usb_fd = {
1065static const struct can_bittiming_const pcan_usb_pro_fd_const = { 1065static const struct can_bittiming_const pcan_usb_pro_fd_const = {
1066 .name = "pcan_usb_pro_fd", 1066 .name = "pcan_usb_pro_fd",
1067 .tseg1_min = 1, 1067 .tseg1_min = 1,
1068 .tseg1_max = 64, 1068 .tseg1_max = (1 << PUCAN_TSLOW_TSGEG1_BITS),
1069 .tseg2_min = 1, 1069 .tseg2_min = 1,
1070 .tseg2_max = 16, 1070 .tseg2_max = (1 << PUCAN_TSLOW_TSGEG2_BITS),
1071 .sjw_max = 16, 1071 .sjw_max = (1 << PUCAN_TSLOW_SJW_BITS),
1072 .brp_min = 1, 1072 .brp_min = 1,
1073 .brp_max = 1024, 1073 .brp_max = (1 << PUCAN_TSLOW_BRP_BITS),
1074 .brp_inc = 1, 1074 .brp_inc = 1,
1075}; 1075};
1076 1076
1077static const struct can_bittiming_const pcan_usb_pro_fd_data_const = { 1077static const struct can_bittiming_const pcan_usb_pro_fd_data_const = {
1078 .name = "pcan_usb_pro_fd", 1078 .name = "pcan_usb_pro_fd",
1079 .tseg1_min = 1, 1079 .tseg1_min = 1,
1080 .tseg1_max = 16, 1080 .tseg1_max = (1 << PUCAN_TFAST_TSGEG1_BITS),
1081 .tseg2_min = 1, 1081 .tseg2_min = 1,
1082 .tseg2_max = 8, 1082 .tseg2_max = (1 << PUCAN_TFAST_TSGEG2_BITS),
1083 .sjw_max = 4, 1083 .sjw_max = (1 << PUCAN_TFAST_SJW_BITS),
1084 .brp_min = 1, 1084 .brp_min = 1,
1085 .brp_max = 1024, 1085 .brp_max = (1 << PUCAN_TFAST_BRP_BITS),
1086 .brp_inc = 1, 1086 .brp_inc = 1,
1087}; 1087};
1088 1088
@@ -1132,3 +1132,75 @@ const struct peak_usb_adapter pcan_usb_pro_fd = {
1132 1132
1133 .do_get_berr_counter = pcan_usb_fd_get_berr_counter, 1133 .do_get_berr_counter = pcan_usb_fd_get_berr_counter,
1134}; 1134};
1135
1136/* describes the PCAN-USB X6 adapter */
1137static const struct can_bittiming_const pcan_usb_x6_const = {
1138 .name = "pcan_usb_x6",
1139 .tseg1_min = 1,
1140 .tseg1_max = (1 << PUCAN_TSLOW_TSGEG1_BITS),
1141 .tseg2_min = 1,
1142 .tseg2_max = (1 << PUCAN_TSLOW_TSGEG2_BITS),
1143 .sjw_max = (1 << PUCAN_TSLOW_SJW_BITS),
1144 .brp_min = 1,
1145 .brp_max = (1 << PUCAN_TSLOW_BRP_BITS),
1146 .brp_inc = 1,
1147};
1148
1149static const struct can_bittiming_const pcan_usb_x6_data_const = {
1150 .name = "pcan_usb_x6",
1151 .tseg1_min = 1,
1152 .tseg1_max = (1 << PUCAN_TFAST_TSGEG1_BITS),
1153 .tseg2_min = 1,
1154 .tseg2_max = (1 << PUCAN_TFAST_TSGEG2_BITS),
1155 .sjw_max = (1 << PUCAN_TFAST_SJW_BITS),
1156 .brp_min = 1,
1157 .brp_max = (1 << PUCAN_TFAST_BRP_BITS),
1158 .brp_inc = 1,
1159};
1160
1161const struct peak_usb_adapter pcan_usb_x6 = {
1162 .name = "PCAN-USB X6",
1163 .device_id = PCAN_USBX6_PRODUCT_ID,
1164 .ctrl_count = PCAN_USBPROFD_CHANNEL_COUNT,
1165 .ctrlmode_supported = CAN_CTRLMODE_FD |
1166 CAN_CTRLMODE_3_SAMPLES | CAN_CTRLMODE_LISTENONLY,
1167 .clock = {
1168 .freq = PCAN_UFD_CRYSTAL_HZ,
1169 },
1170 .bittiming_const = &pcan_usb_x6_const,
1171 .data_bittiming_const = &pcan_usb_x6_data_const,
1172
1173 /* size of device private data */
1174 .sizeof_dev_private = sizeof(struct pcan_usb_fd_device),
1175
1176 /* timestamps usage */
1177 .ts_used_bits = 32,
1178 .ts_period = 1000000, /* calibration period in ts. */
1179 .us_per_ts_scale = 1, /* us = (ts * scale) >> shift */
1180 .us_per_ts_shift = 0,
1181
1182 /* give here messages in/out endpoints */
1183 .ep_msg_in = PCAN_USBPRO_EP_MSGIN,
1184 .ep_msg_out = {PCAN_USBPRO_EP_MSGOUT_0, PCAN_USBPRO_EP_MSGOUT_1},
1185
1186 /* size of rx/tx usb buffers */
1187 .rx_buffer_size = PCAN_UFD_RX_BUFFER_SIZE,
1188 .tx_buffer_size = PCAN_UFD_TX_BUFFER_SIZE,
1189
1190 /* device callbacks */
1191 .intf_probe = pcan_usb_pro_probe, /* same as PCAN-USB Pro */
1192 .dev_init = pcan_usb_fd_init,
1193
1194 .dev_exit = pcan_usb_fd_exit,
1195 .dev_free = pcan_usb_fd_free,
1196 .dev_set_bus = pcan_usb_fd_set_bus,
1197 .dev_set_bittiming = pcan_usb_fd_set_bittiming_slow,
1198 .dev_set_data_bittiming = pcan_usb_fd_set_bittiming_fast,
1199 .dev_decode_buf = pcan_usb_fd_decode_buf,
1200 .dev_start = pcan_usb_fd_start,
1201 .dev_stop = pcan_usb_fd_stop,
1202 .dev_restart_async = pcan_usb_fd_restart_async,
1203 .dev_encode_msg = pcan_usb_fd_encode_msg,
1204
1205 .do_get_berr_counter = pcan_usb_fd_get_berr_counter,
1206};
diff --git a/drivers/net/dsa/b53/b53_common.c b/drivers/net/dsa/b53/b53_common.c
index 7717b19dc806..947adda3397d 100644
--- a/drivers/net/dsa/b53/b53_common.c
+++ b/drivers/net/dsa/b53/b53_common.c
@@ -962,9 +962,10 @@ static void b53_vlan_add(struct dsa_switch *ds, int port,
962 962
963 vl->members |= BIT(port) | BIT(cpu_port); 963 vl->members |= BIT(port) | BIT(cpu_port);
964 if (untagged) 964 if (untagged)
965 vl->untag |= BIT(port) | BIT(cpu_port); 965 vl->untag |= BIT(port);
966 else 966 else
967 vl->untag &= ~(BIT(port) | BIT(cpu_port)); 967 vl->untag &= ~BIT(port);
968 vl->untag &= ~BIT(cpu_port);
968 969
969 b53_set_vlan_entry(dev, vid, vl); 970 b53_set_vlan_entry(dev, vid, vl);
970 b53_fast_age_vlan(dev, vid); 971 b53_fast_age_vlan(dev, vid);
@@ -973,8 +974,6 @@ static void b53_vlan_add(struct dsa_switch *ds, int port,
973 if (pvid) { 974 if (pvid) {
974 b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port), 975 b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port),
975 vlan->vid_end); 976 vlan->vid_end);
976 b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(cpu_port),
977 vlan->vid_end);
978 b53_fast_age_vlan(dev, vid); 977 b53_fast_age_vlan(dev, vid);
979 } 978 }
980} 979}
@@ -984,7 +983,6 @@ static int b53_vlan_del(struct dsa_switch *ds, int port,
984{ 983{
985 struct b53_device *dev = ds->priv; 984 struct b53_device *dev = ds->priv;
986 bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED; 985 bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
987 unsigned int cpu_port = dev->cpu_port;
988 struct b53_vlan *vl; 986 struct b53_vlan *vl;
989 u16 vid; 987 u16 vid;
990 u16 pvid; 988 u16 pvid;
@@ -997,8 +995,6 @@ static int b53_vlan_del(struct dsa_switch *ds, int port,
997 b53_get_vlan_entry(dev, vid, vl); 995 b53_get_vlan_entry(dev, vid, vl);
998 996
999 vl->members &= ~BIT(port); 997 vl->members &= ~BIT(port);
1000 if ((vl->members & BIT(cpu_port)) == BIT(cpu_port))
1001 vl->members = 0;
1002 998
1003 if (pvid == vid) { 999 if (pvid == vid) {
1004 if (is5325(dev) || is5365(dev)) 1000 if (is5325(dev) || is5365(dev))
@@ -1007,18 +1003,14 @@ static int b53_vlan_del(struct dsa_switch *ds, int port,
1007 pvid = 0; 1003 pvid = 0;
1008 } 1004 }
1009 1005
1010 if (untagged) { 1006 if (untagged)
1011 vl->untag &= ~(BIT(port)); 1007 vl->untag &= ~(BIT(port));
1012 if ((vl->untag & BIT(cpu_port)) == BIT(cpu_port))
1013 vl->untag = 0;
1014 }
1015 1008
1016 b53_set_vlan_entry(dev, vid, vl); 1009 b53_set_vlan_entry(dev, vid, vl);
1017 b53_fast_age_vlan(dev, vid); 1010 b53_fast_age_vlan(dev, vid);
1018 } 1011 }
1019 1012
1020 b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port), pvid); 1013 b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port), pvid);
1021 b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(cpu_port), pvid);
1022 b53_fast_age_vlan(dev, pvid); 1014 b53_fast_age_vlan(dev, pvid);
1023 1015
1024 return 0; 1016 return 0;
diff --git a/drivers/net/dsa/b53/b53_mmap.c b/drivers/net/dsa/b53/b53_mmap.c
index 76fb8552c9d9..ef63d24fef81 100644
--- a/drivers/net/dsa/b53/b53_mmap.c
+++ b/drivers/net/dsa/b53/b53_mmap.c
@@ -256,6 +256,7 @@ static const struct of_device_id b53_mmap_of_table[] = {
256 { .compatible = "brcm,bcm63xx-switch" }, 256 { .compatible = "brcm,bcm63xx-switch" },
257 { /* sentinel */ }, 257 { /* sentinel */ },
258}; 258};
259MODULE_DEVICE_TABLE(of, b53_mmap_of_table);
259 260
260static struct platform_driver b53_mmap_driver = { 261static struct platform_driver b53_mmap_driver = {
261 .probe = b53_mmap_probe, 262 .probe = b53_mmap_probe,
diff --git a/drivers/net/dsa/bcm_sf2.c b/drivers/net/dsa/bcm_sf2.c
index e218887f18b7..9ec33b51a0ed 100644
--- a/drivers/net/dsa/bcm_sf2.c
+++ b/drivers/net/dsa/bcm_sf2.c
@@ -588,6 +588,7 @@ static void bcm_sf2_sw_adjust_link(struct dsa_switch *ds, int port,
588 struct phy_device *phydev) 588 struct phy_device *phydev)
589{ 589{
590 struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds); 590 struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds);
591 struct ethtool_eee *p = &priv->port_sts[port].eee;
591 u32 id_mode_dis = 0, port_mode; 592 u32 id_mode_dis = 0, port_mode;
592 const char *str = NULL; 593 const char *str = NULL;
593 u32 reg; 594 u32 reg;
@@ -662,6 +663,9 @@ force_link:
662 reg |= DUPLX_MODE; 663 reg |= DUPLX_MODE;
663 664
664 core_writel(priv, reg, CORE_STS_OVERRIDE_GMIIP_PORT(port)); 665 core_writel(priv, reg, CORE_STS_OVERRIDE_GMIIP_PORT(port));
666
667 if (!phydev->is_pseudo_fixed_link)
668 p->eee_enabled = bcm_sf2_eee_init(ds, port, phydev);
665} 669}
666 670
667static void bcm_sf2_sw_fixed_link_update(struct dsa_switch *ds, int port, 671static void bcm_sf2_sw_fixed_link_update(struct dsa_switch *ds, int port,
@@ -1133,6 +1137,20 @@ static int bcm_sf2_sw_remove(struct platform_device *pdev)
1133 return 0; 1137 return 0;
1134} 1138}
1135 1139
1140static void bcm_sf2_sw_shutdown(struct platform_device *pdev)
1141{
1142 struct bcm_sf2_priv *priv = platform_get_drvdata(pdev);
1143
1144 /* For a kernel about to be kexec'd we want to keep the GPHY on for a
1145 * successful MDIO bus scan to occur. If we did turn off the GPHY
1146 * before (e.g: port_disable), this will also power it back on.
1147 *
1148 * Do not rely on kexec_in_progress, just power the PHY on.
1149 */
1150 if (priv->hw_params.num_gphy == 1)
1151 bcm_sf2_gphy_enable_set(priv->dev->ds, true);
1152}
1153
1136#ifdef CONFIG_PM_SLEEP 1154#ifdef CONFIG_PM_SLEEP
1137static int bcm_sf2_suspend(struct device *dev) 1155static int bcm_sf2_suspend(struct device *dev)
1138{ 1156{
@@ -1158,10 +1176,12 @@ static const struct of_device_id bcm_sf2_of_match[] = {
1158 { .compatible = "brcm,bcm7445-switch-v4.0" }, 1176 { .compatible = "brcm,bcm7445-switch-v4.0" },
1159 { /* sentinel */ }, 1177 { /* sentinel */ },
1160}; 1178};
1179MODULE_DEVICE_TABLE(of, bcm_sf2_of_match);
1161 1180
1162static struct platform_driver bcm_sf2_driver = { 1181static struct platform_driver bcm_sf2_driver = {
1163 .probe = bcm_sf2_sw_probe, 1182 .probe = bcm_sf2_sw_probe,
1164 .remove = bcm_sf2_sw_remove, 1183 .remove = bcm_sf2_sw_remove,
1184 .shutdown = bcm_sf2_sw_shutdown,
1165 .driver = { 1185 .driver = {
1166 .name = "brcm-sf2", 1186 .name = "brcm-sf2",
1167 .of_match_table = bcm_sf2_of_match, 1187 .of_match_table = bcm_sf2_of_match,
diff --git a/drivers/net/ethernet/altera/altera_tse_main.c b/drivers/net/ethernet/altera/altera_tse_main.c
index bda31f308cc2..a0eee7218695 100644
--- a/drivers/net/ethernet/altera/altera_tse_main.c
+++ b/drivers/net/ethernet/altera/altera_tse_main.c
@@ -400,12 +400,6 @@ static int tse_rx(struct altera_tse_private *priv, int limit)
400 400
401 skb_put(skb, pktlength); 401 skb_put(skb, pktlength);
402 402
403 /* make cache consistent with receive packet buffer */
404 dma_sync_single_for_cpu(priv->device,
405 priv->rx_ring[entry].dma_addr,
406 priv->rx_ring[entry].len,
407 DMA_FROM_DEVICE);
408
409 dma_unmap_single(priv->device, priv->rx_ring[entry].dma_addr, 403 dma_unmap_single(priv->device, priv->rx_ring[entry].dma_addr,
410 priv->rx_ring[entry].len, DMA_FROM_DEVICE); 404 priv->rx_ring[entry].len, DMA_FROM_DEVICE);
411 405
@@ -469,7 +463,6 @@ static int tse_tx_complete(struct altera_tse_private *priv)
469 463
470 if (unlikely(netif_queue_stopped(priv->dev) && 464 if (unlikely(netif_queue_stopped(priv->dev) &&
471 tse_tx_avail(priv) > TSE_TX_THRESH(priv))) { 465 tse_tx_avail(priv) > TSE_TX_THRESH(priv))) {
472 netif_tx_lock(priv->dev);
473 if (netif_queue_stopped(priv->dev) && 466 if (netif_queue_stopped(priv->dev) &&
474 tse_tx_avail(priv) > TSE_TX_THRESH(priv)) { 467 tse_tx_avail(priv) > TSE_TX_THRESH(priv)) {
475 if (netif_msg_tx_done(priv)) 468 if (netif_msg_tx_done(priv))
@@ -477,7 +470,6 @@ static int tse_tx_complete(struct altera_tse_private *priv)
477 __func__); 470 __func__);
478 netif_wake_queue(priv->dev); 471 netif_wake_queue(priv->dev);
479 } 472 }
480 netif_tx_unlock(priv->dev);
481 } 473 }
482 474
483 spin_unlock(&priv->tx_lock); 475 spin_unlock(&priv->tx_lock);
@@ -592,10 +584,6 @@ static int tse_start_xmit(struct sk_buff *skb, struct net_device *dev)
592 buffer->dma_addr = dma_addr; 584 buffer->dma_addr = dma_addr;
593 buffer->len = nopaged_len; 585 buffer->len = nopaged_len;
594 586
595 /* Push data out of the cache hierarchy into main memory */
596 dma_sync_single_for_device(priv->device, buffer->dma_addr,
597 buffer->len, DMA_TO_DEVICE);
598
599 priv->dmaops->tx_buffer(priv, buffer); 587 priv->dmaops->tx_buffer(priv, buffer);
600 588
601 skb_tx_timestamp(skb); 589 skb_tx_timestamp(skb);
@@ -819,6 +807,8 @@ static int init_phy(struct net_device *dev)
819 807
820 if (!phydev) { 808 if (!phydev) {
821 netdev_err(dev, "Could not find the PHY\n"); 809 netdev_err(dev, "Could not find the PHY\n");
810 if (fixed_link)
811 of_phy_deregister_fixed_link(priv->device->of_node);
822 return -ENODEV; 812 return -ENODEV;
823 } 813 }
824 814
@@ -1545,10 +1535,15 @@ err_free_netdev:
1545static int altera_tse_remove(struct platform_device *pdev) 1535static int altera_tse_remove(struct platform_device *pdev)
1546{ 1536{
1547 struct net_device *ndev = platform_get_drvdata(pdev); 1537 struct net_device *ndev = platform_get_drvdata(pdev);
1538 struct altera_tse_private *priv = netdev_priv(ndev);
1548 1539
1549 if (ndev->phydev) 1540 if (ndev->phydev) {
1550 phy_disconnect(ndev->phydev); 1541 phy_disconnect(ndev->phydev);
1551 1542
1543 if (of_phy_is_fixed_link(priv->device->of_node))
1544 of_phy_deregister_fixed_link(priv->device->of_node);
1545 }
1546
1552 platform_set_drvdata(pdev, NULL); 1547 platform_set_drvdata(pdev, NULL);
1553 altera_tse_mdio_destroy(ndev); 1548 altera_tse_mdio_destroy(ndev);
1554 unregister_netdev(ndev); 1549 unregister_netdev(ndev);
diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-main.c b/drivers/net/ethernet/amd/xgbe/xgbe-main.c
index 9de078819aa6..4f7635178200 100644
--- a/drivers/net/ethernet/amd/xgbe/xgbe-main.c
+++ b/drivers/net/ethernet/amd/xgbe/xgbe-main.c
@@ -829,7 +829,7 @@ static int xgbe_remove(struct platform_device *pdev)
829 return 0; 829 return 0;
830} 830}
831 831
832#ifdef CONFIG_PM 832#ifdef CONFIG_PM_SLEEP
833static int xgbe_suspend(struct device *dev) 833static int xgbe_suspend(struct device *dev)
834{ 834{
835 struct net_device *netdev = dev_get_drvdata(dev); 835 struct net_device *netdev = dev_get_drvdata(dev);
@@ -874,7 +874,7 @@ static int xgbe_resume(struct device *dev)
874 874
875 return ret; 875 return ret;
876} 876}
877#endif /* CONFIG_PM */ 877#endif /* CONFIG_PM_SLEEP */
878 878
879#ifdef CONFIG_ACPI 879#ifdef CONFIG_ACPI
880static const struct acpi_device_id xgbe_acpi_match[] = { 880static const struct acpi_device_id xgbe_acpi_match[] = {
diff --git a/drivers/net/ethernet/apm/xgene/xgene_enet_hw.c b/drivers/net/ethernet/apm/xgene/xgene_enet_hw.c
index c481f104a8fe..5390ae89136c 100644
--- a/drivers/net/ethernet/apm/xgene/xgene_enet_hw.c
+++ b/drivers/net/ethernet/apm/xgene/xgene_enet_hw.c
@@ -204,17 +204,6 @@ static u32 xgene_enet_ring_len(struct xgene_enet_desc_ring *ring)
204 return num_msgs; 204 return num_msgs;
205} 205}
206 206
207static void xgene_enet_setup_coalescing(struct xgene_enet_desc_ring *ring)
208{
209 u32 data = 0x7777;
210
211 xgene_enet_ring_wr32(ring, CSR_PBM_COAL, 0x8e);
212 xgene_enet_ring_wr32(ring, CSR_PBM_CTICK1, data);
213 xgene_enet_ring_wr32(ring, CSR_PBM_CTICK2, data << 16);
214 xgene_enet_ring_wr32(ring, CSR_THRESHOLD0_SET1, 0x40);
215 xgene_enet_ring_wr32(ring, CSR_THRESHOLD1_SET1, 0x80);
216}
217
218void xgene_enet_parse_error(struct xgene_enet_desc_ring *ring, 207void xgene_enet_parse_error(struct xgene_enet_desc_ring *ring,
219 struct xgene_enet_pdata *pdata, 208 struct xgene_enet_pdata *pdata,
220 enum xgene_enet_err_code status) 209 enum xgene_enet_err_code status)
@@ -929,5 +918,4 @@ struct xgene_ring_ops xgene_ring1_ops = {
929 .clear = xgene_enet_clear_ring, 918 .clear = xgene_enet_clear_ring,
930 .wr_cmd = xgene_enet_wr_cmd, 919 .wr_cmd = xgene_enet_wr_cmd,
931 .len = xgene_enet_ring_len, 920 .len = xgene_enet_ring_len,
932 .coalesce = xgene_enet_setup_coalescing,
933}; 921};
diff --git a/drivers/net/ethernet/apm/xgene/xgene_enet_hw.h b/drivers/net/ethernet/apm/xgene/xgene_enet_hw.h
index 8456337a237d..06e598c8bc16 100644
--- a/drivers/net/ethernet/apm/xgene/xgene_enet_hw.h
+++ b/drivers/net/ethernet/apm/xgene/xgene_enet_hw.h
@@ -55,8 +55,10 @@ enum xgene_enet_rm {
55#define PREFETCH_BUF_EN BIT(21) 55#define PREFETCH_BUF_EN BIT(21)
56#define CSR_RING_ID_BUF 0x000c 56#define CSR_RING_ID_BUF 0x000c
57#define CSR_PBM_COAL 0x0014 57#define CSR_PBM_COAL 0x0014
58#define CSR_PBM_CTICK0 0x0018
58#define CSR_PBM_CTICK1 0x001c 59#define CSR_PBM_CTICK1 0x001c
59#define CSR_PBM_CTICK2 0x0020 60#define CSR_PBM_CTICK2 0x0020
61#define CSR_PBM_CTICK3 0x0024
60#define CSR_THRESHOLD0_SET1 0x0030 62#define CSR_THRESHOLD0_SET1 0x0030
61#define CSR_THRESHOLD1_SET1 0x0034 63#define CSR_THRESHOLD1_SET1 0x0034
62#define CSR_RING_NE_INT_MODE 0x017c 64#define CSR_RING_NE_INT_MODE 0x017c
diff --git a/drivers/net/ethernet/apm/xgene/xgene_enet_main.c b/drivers/net/ethernet/apm/xgene/xgene_enet_main.c
index 429f18fc5503..8158d4698734 100644
--- a/drivers/net/ethernet/apm/xgene/xgene_enet_main.c
+++ b/drivers/net/ethernet/apm/xgene/xgene_enet_main.c
@@ -1188,7 +1188,8 @@ static int xgene_enet_create_desc_rings(struct net_device *ndev)
1188 tx_ring->dst_ring_num = xgene_enet_dst_ring_num(cp_ring); 1188 tx_ring->dst_ring_num = xgene_enet_dst_ring_num(cp_ring);
1189 } 1189 }
1190 1190
1191 pdata->ring_ops->coalesce(pdata->tx_ring[0]); 1191 if (pdata->ring_ops->coalesce)
1192 pdata->ring_ops->coalesce(pdata->tx_ring[0]);
1192 pdata->tx_qcnt_hi = pdata->tx_ring[0]->slots - 128; 1193 pdata->tx_qcnt_hi = pdata->tx_ring[0]->slots - 128;
1193 1194
1194 return 0; 1195 return 0;
diff --git a/drivers/net/ethernet/apm/xgene/xgene_enet_ring2.c b/drivers/net/ethernet/apm/xgene/xgene_enet_ring2.c
index 2b76732add5d..af51dd5844ce 100644
--- a/drivers/net/ethernet/apm/xgene/xgene_enet_ring2.c
+++ b/drivers/net/ethernet/apm/xgene/xgene_enet_ring2.c
@@ -30,7 +30,7 @@ static void xgene_enet_ring_init(struct xgene_enet_desc_ring *ring)
30 ring_cfg[0] |= SET_VAL(X2_INTLINE, ring->id & RING_BUFNUM_MASK); 30 ring_cfg[0] |= SET_VAL(X2_INTLINE, ring->id & RING_BUFNUM_MASK);
31 ring_cfg[3] |= SET_BIT(X2_DEQINTEN); 31 ring_cfg[3] |= SET_BIT(X2_DEQINTEN);
32 } 32 }
33 ring_cfg[0] |= SET_VAL(X2_CFGCRID, 1); 33 ring_cfg[0] |= SET_VAL(X2_CFGCRID, 2);
34 34
35 addr >>= 8; 35 addr >>= 8;
36 ring_cfg[2] |= QCOHERENT | SET_VAL(RINGADDRL, addr); 36 ring_cfg[2] |= QCOHERENT | SET_VAL(RINGADDRL, addr);
@@ -192,13 +192,15 @@ static u32 xgene_enet_ring_len(struct xgene_enet_desc_ring *ring)
192 192
193static void xgene_enet_setup_coalescing(struct xgene_enet_desc_ring *ring) 193static void xgene_enet_setup_coalescing(struct xgene_enet_desc_ring *ring)
194{ 194{
195 u32 data = 0x7777; 195 u32 data = 0x77777777;
196 196
197 xgene_enet_ring_wr32(ring, CSR_PBM_COAL, 0x8e); 197 xgene_enet_ring_wr32(ring, CSR_PBM_COAL, 0x8e);
198 xgene_enet_ring_wr32(ring, CSR_PBM_CTICK0, data);
198 xgene_enet_ring_wr32(ring, CSR_PBM_CTICK1, data); 199 xgene_enet_ring_wr32(ring, CSR_PBM_CTICK1, data);
199 xgene_enet_ring_wr32(ring, CSR_PBM_CTICK2, data << 16); 200 xgene_enet_ring_wr32(ring, CSR_PBM_CTICK2, data);
200 xgene_enet_ring_wr32(ring, CSR_THRESHOLD0_SET1, 0x40); 201 xgene_enet_ring_wr32(ring, CSR_PBM_CTICK3, data);
201 xgene_enet_ring_wr32(ring, CSR_THRESHOLD1_SET1, 0x80); 202 xgene_enet_ring_wr32(ring, CSR_THRESHOLD0_SET1, 0x08);
203 xgene_enet_ring_wr32(ring, CSR_THRESHOLD1_SET1, 0x10);
202} 204}
203 205
204struct xgene_ring_ops xgene_ring2_ops = { 206struct xgene_ring_ops xgene_ring2_ops = {
diff --git a/drivers/net/ethernet/arc/emac_main.c b/drivers/net/ethernet/arc/emac_main.c
index b0da9693f28a..be865b4dada2 100644
--- a/drivers/net/ethernet/arc/emac_main.c
+++ b/drivers/net/ethernet/arc/emac_main.c
@@ -460,7 +460,7 @@ static void arc_emac_set_rx_mode(struct net_device *ndev)
460 if (ndev->flags & IFF_ALLMULTI) { 460 if (ndev->flags & IFF_ALLMULTI) {
461 arc_reg_set(priv, R_LAFL, ~0); 461 arc_reg_set(priv, R_LAFL, ~0);
462 arc_reg_set(priv, R_LAFH, ~0); 462 arc_reg_set(priv, R_LAFH, ~0);
463 } else { 463 } else if (ndev->flags & IFF_MULTICAST) {
464 struct netdev_hw_addr *ha; 464 struct netdev_hw_addr *ha;
465 unsigned int filter[2] = { 0, 0 }; 465 unsigned int filter[2] = { 0, 0 };
466 int bit; 466 int bit;
@@ -472,6 +472,9 @@ static void arc_emac_set_rx_mode(struct net_device *ndev)
472 472
473 arc_reg_set(priv, R_LAFL, filter[0]); 473 arc_reg_set(priv, R_LAFL, filter[0]);
474 arc_reg_set(priv, R_LAFH, filter[1]); 474 arc_reg_set(priv, R_LAFH, filter[1]);
475 } else {
476 arc_reg_set(priv, R_LAFL, 0);
477 arc_reg_set(priv, R_LAFH, 0);
475 } 478 }
476 } 479 }
477} 480}
@@ -764,8 +767,6 @@ int arc_emac_probe(struct net_device *ndev, int interface)
764 ndev->netdev_ops = &arc_emac_netdev_ops; 767 ndev->netdev_ops = &arc_emac_netdev_ops;
765 ndev->ethtool_ops = &arc_emac_ethtool_ops; 768 ndev->ethtool_ops = &arc_emac_ethtool_ops;
766 ndev->watchdog_timeo = TX_TIMEOUT; 769 ndev->watchdog_timeo = TX_TIMEOUT;
767 /* FIXME :: no multicast support yet */
768 ndev->flags &= ~IFF_MULTICAST;
769 770
770 priv = netdev_priv(ndev); 771 priv = netdev_priv(ndev);
771 priv->dev = dev; 772 priv->dev = dev;
diff --git a/drivers/net/ethernet/aurora/nb8800.c b/drivers/net/ethernet/aurora/nb8800.c
index b047fd607b83..e078d8da978c 100644
--- a/drivers/net/ethernet/aurora/nb8800.c
+++ b/drivers/net/ethernet/aurora/nb8800.c
@@ -1358,6 +1358,7 @@ static const struct of_device_id nb8800_dt_ids[] = {
1358 }, 1358 },
1359 { } 1359 { }
1360}; 1360};
1361MODULE_DEVICE_TABLE(of, nb8800_dt_ids);
1361 1362
1362static int nb8800_probe(struct platform_device *pdev) 1363static int nb8800_probe(struct platform_device *pdev)
1363{ 1364{
@@ -1465,12 +1466,12 @@ static int nb8800_probe(struct platform_device *pdev)
1465 1466
1466 ret = nb8800_hw_init(dev); 1467 ret = nb8800_hw_init(dev);
1467 if (ret) 1468 if (ret)
1468 goto err_free_bus; 1469 goto err_deregister_fixed_link;
1469 1470
1470 if (ops && ops->init) { 1471 if (ops && ops->init) {
1471 ret = ops->init(dev); 1472 ret = ops->init(dev);
1472 if (ret) 1473 if (ret)
1473 goto err_free_bus; 1474 goto err_deregister_fixed_link;
1474 } 1475 }
1475 1476
1476 dev->netdev_ops = &nb8800_netdev_ops; 1477 dev->netdev_ops = &nb8800_netdev_ops;
@@ -1503,6 +1504,9 @@ static int nb8800_probe(struct platform_device *pdev)
1503 1504
1504err_free_dma: 1505err_free_dma:
1505 nb8800_dma_free(dev); 1506 nb8800_dma_free(dev);
1507err_deregister_fixed_link:
1508 if (of_phy_is_fixed_link(pdev->dev.of_node))
1509 of_phy_deregister_fixed_link(pdev->dev.of_node);
1506err_free_bus: 1510err_free_bus:
1507 of_node_put(priv->phy_node); 1511 of_node_put(priv->phy_node);
1508 mdiobus_unregister(bus); 1512 mdiobus_unregister(bus);
@@ -1520,6 +1524,8 @@ static int nb8800_remove(struct platform_device *pdev)
1520 struct nb8800_priv *priv = netdev_priv(ndev); 1524 struct nb8800_priv *priv = netdev_priv(ndev);
1521 1525
1522 unregister_netdev(ndev); 1526 unregister_netdev(ndev);
1527 if (of_phy_is_fixed_link(pdev->dev.of_node))
1528 of_phy_deregister_fixed_link(pdev->dev.of_node);
1523 of_node_put(priv->phy_node); 1529 of_node_put(priv->phy_node);
1524 1530
1525 mdiobus_unregister(priv->mii_bus); 1531 mdiobus_unregister(priv->mii_bus);
diff --git a/drivers/net/ethernet/broadcom/bcm63xx_enet.c b/drivers/net/ethernet/broadcom/bcm63xx_enet.c
index ae364c74baf3..537090952c45 100644
--- a/drivers/net/ethernet/broadcom/bcm63xx_enet.c
+++ b/drivers/net/ethernet/broadcom/bcm63xx_enet.c
@@ -1126,7 +1126,8 @@ out_freeirq:
1126 free_irq(dev->irq, dev); 1126 free_irq(dev->irq, dev);
1127 1127
1128out_phy_disconnect: 1128out_phy_disconnect:
1129 phy_disconnect(phydev); 1129 if (priv->has_phy)
1130 phy_disconnect(phydev);
1130 1131
1131 return ret; 1132 return ret;
1132} 1133}
diff --git a/drivers/net/ethernet/broadcom/bcmsysport.c b/drivers/net/ethernet/broadcom/bcmsysport.c
index c3354b9941d1..25d1eb4933d0 100644
--- a/drivers/net/ethernet/broadcom/bcmsysport.c
+++ b/drivers/net/ethernet/broadcom/bcmsysport.c
@@ -1755,13 +1755,13 @@ static int bcm_sysport_probe(struct platform_device *pdev)
1755 if (priv->irq0 <= 0 || priv->irq1 <= 0) { 1755 if (priv->irq0 <= 0 || priv->irq1 <= 0) {
1756 dev_err(&pdev->dev, "invalid interrupts\n"); 1756 dev_err(&pdev->dev, "invalid interrupts\n");
1757 ret = -EINVAL; 1757 ret = -EINVAL;
1758 goto err; 1758 goto err_free_netdev;
1759 } 1759 }
1760 1760
1761 priv->base = devm_ioremap_resource(&pdev->dev, r); 1761 priv->base = devm_ioremap_resource(&pdev->dev, r);
1762 if (IS_ERR(priv->base)) { 1762 if (IS_ERR(priv->base)) {
1763 ret = PTR_ERR(priv->base); 1763 ret = PTR_ERR(priv->base);
1764 goto err; 1764 goto err_free_netdev;
1765 } 1765 }
1766 1766
1767 priv->netdev = dev; 1767 priv->netdev = dev;
@@ -1779,7 +1779,7 @@ static int bcm_sysport_probe(struct platform_device *pdev)
1779 ret = of_phy_register_fixed_link(dn); 1779 ret = of_phy_register_fixed_link(dn);
1780 if (ret) { 1780 if (ret) {
1781 dev_err(&pdev->dev, "failed to register fixed PHY\n"); 1781 dev_err(&pdev->dev, "failed to register fixed PHY\n");
1782 goto err; 1782 goto err_free_netdev;
1783 } 1783 }
1784 1784
1785 priv->phy_dn = dn; 1785 priv->phy_dn = dn;
@@ -1821,7 +1821,7 @@ static int bcm_sysport_probe(struct platform_device *pdev)
1821 ret = register_netdev(dev); 1821 ret = register_netdev(dev);
1822 if (ret) { 1822 if (ret) {
1823 dev_err(&pdev->dev, "failed to register net_device\n"); 1823 dev_err(&pdev->dev, "failed to register net_device\n");
1824 goto err; 1824 goto err_deregister_fixed_link;
1825 } 1825 }
1826 1826
1827 priv->rev = topctrl_readl(priv, REV_CNTL) & REV_MASK; 1827 priv->rev = topctrl_readl(priv, REV_CNTL) & REV_MASK;
@@ -1832,7 +1832,11 @@ static int bcm_sysport_probe(struct platform_device *pdev)
1832 priv->base, priv->irq0, priv->irq1, txq, rxq); 1832 priv->base, priv->irq0, priv->irq1, txq, rxq);
1833 1833
1834 return 0; 1834 return 0;
1835err: 1835
1836err_deregister_fixed_link:
1837 if (of_phy_is_fixed_link(dn))
1838 of_phy_deregister_fixed_link(dn);
1839err_free_netdev:
1836 free_netdev(dev); 1840 free_netdev(dev);
1837 return ret; 1841 return ret;
1838} 1842}
@@ -1840,11 +1844,14 @@ err:
1840static int bcm_sysport_remove(struct platform_device *pdev) 1844static int bcm_sysport_remove(struct platform_device *pdev)
1841{ 1845{
1842 struct net_device *dev = dev_get_drvdata(&pdev->dev); 1846 struct net_device *dev = dev_get_drvdata(&pdev->dev);
1847 struct device_node *dn = pdev->dev.of_node;
1843 1848
1844 /* Not much to do, ndo_close has been called 1849 /* Not much to do, ndo_close has been called
1845 * and we use managed allocations 1850 * and we use managed allocations
1846 */ 1851 */
1847 unregister_netdev(dev); 1852 unregister_netdev(dev);
1853 if (of_phy_is_fixed_link(dn))
1854 of_phy_deregister_fixed_link(dn);
1848 free_netdev(dev); 1855 free_netdev(dev);
1849 dev_set_drvdata(&pdev->dev, NULL); 1856 dev_set_drvdata(&pdev->dev, NULL);
1850 1857
diff --git a/drivers/net/ethernet/broadcom/bgmac.c b/drivers/net/ethernet/broadcom/bgmac.c
index 856379cbb402..49f4cafe5438 100644
--- a/drivers/net/ethernet/broadcom/bgmac.c
+++ b/drivers/net/ethernet/broadcom/bgmac.c
@@ -307,6 +307,10 @@ static void bgmac_dma_rx_enable(struct bgmac *bgmac,
307 u32 ctl; 307 u32 ctl;
308 308
309 ctl = bgmac_read(bgmac, ring->mmio_base + BGMAC_DMA_RX_CTL); 309 ctl = bgmac_read(bgmac, ring->mmio_base + BGMAC_DMA_RX_CTL);
310
311 /* preserve ONLY bits 16-17 from current hardware value */
312 ctl &= BGMAC_DMA_RX_ADDREXT_MASK;
313
310 if (bgmac->feature_flags & BGMAC_FEAT_RX_MASK_SETUP) { 314 if (bgmac->feature_flags & BGMAC_FEAT_RX_MASK_SETUP) {
311 ctl &= ~BGMAC_DMA_RX_BL_MASK; 315 ctl &= ~BGMAC_DMA_RX_BL_MASK;
312 ctl |= BGMAC_DMA_RX_BL_128 << BGMAC_DMA_RX_BL_SHIFT; 316 ctl |= BGMAC_DMA_RX_BL_128 << BGMAC_DMA_RX_BL_SHIFT;
@@ -317,7 +321,6 @@ static void bgmac_dma_rx_enable(struct bgmac *bgmac,
317 ctl &= ~BGMAC_DMA_RX_PT_MASK; 321 ctl &= ~BGMAC_DMA_RX_PT_MASK;
318 ctl |= BGMAC_DMA_RX_PT_1 << BGMAC_DMA_RX_PT_SHIFT; 322 ctl |= BGMAC_DMA_RX_PT_1 << BGMAC_DMA_RX_PT_SHIFT;
319 } 323 }
320 ctl &= BGMAC_DMA_RX_ADDREXT_MASK;
321 ctl |= BGMAC_DMA_RX_ENABLE; 324 ctl |= BGMAC_DMA_RX_ENABLE;
322 ctl |= BGMAC_DMA_RX_PARITY_DISABLE; 325 ctl |= BGMAC_DMA_RX_PARITY_DISABLE;
323 ctl |= BGMAC_DMA_RX_OVERFLOW_CONT; 326 ctl |= BGMAC_DMA_RX_OVERFLOW_CONT;
@@ -1046,9 +1049,9 @@ static void bgmac_enable(struct bgmac *bgmac)
1046 1049
1047 mode = (bgmac_read(bgmac, BGMAC_DEV_STATUS) & BGMAC_DS_MM_MASK) >> 1050 mode = (bgmac_read(bgmac, BGMAC_DEV_STATUS) & BGMAC_DS_MM_MASK) >>
1048 BGMAC_DS_MM_SHIFT; 1051 BGMAC_DS_MM_SHIFT;
1049 if (!(bgmac->feature_flags & BGMAC_FEAT_CLKCTLST) || mode != 0) 1052 if (bgmac->feature_flags & BGMAC_FEAT_CLKCTLST || mode != 0)
1050 bgmac_set(bgmac, BCMA_CLKCTLST, BCMA_CLKCTLST_FORCEHT); 1053 bgmac_set(bgmac, BCMA_CLKCTLST, BCMA_CLKCTLST_FORCEHT);
1051 if (bgmac->feature_flags & BGMAC_FEAT_CLKCTLST && mode == 2) 1054 if (!(bgmac->feature_flags & BGMAC_FEAT_CLKCTLST) && mode == 2)
1052 bgmac_cco_ctl_maskset(bgmac, 1, ~0, 1055 bgmac_cco_ctl_maskset(bgmac, 1, ~0,
1053 BGMAC_CHIPCTL_1_RXC_DLL_BYPASS); 1056 BGMAC_CHIPCTL_1_RXC_DLL_BYPASS);
1054 1057
@@ -1449,7 +1452,7 @@ static int bgmac_phy_connect(struct bgmac *bgmac)
1449 phy_dev = phy_connect(bgmac->net_dev, bus_id, &bgmac_adjust_link, 1452 phy_dev = phy_connect(bgmac->net_dev, bus_id, &bgmac_adjust_link,
1450 PHY_INTERFACE_MODE_MII); 1453 PHY_INTERFACE_MODE_MII);
1451 if (IS_ERR(phy_dev)) { 1454 if (IS_ERR(phy_dev)) {
1452 dev_err(bgmac->dev, "PHY connecton failed\n"); 1455 dev_err(bgmac->dev, "PHY connection failed\n");
1453 return PTR_ERR(phy_dev); 1456 return PTR_ERR(phy_dev);
1454 } 1457 }
1455 1458
diff --git a/drivers/net/ethernet/broadcom/bnx2.c b/drivers/net/ethernet/broadcom/bnx2.c
index 27f11a5d5fe2..1f7034d739b0 100644
--- a/drivers/net/ethernet/broadcom/bnx2.c
+++ b/drivers/net/ethernet/broadcom/bnx2.c
@@ -49,6 +49,7 @@
49#include <linux/firmware.h> 49#include <linux/firmware.h>
50#include <linux/log2.h> 50#include <linux/log2.h>
51#include <linux/aer.h> 51#include <linux/aer.h>
52#include <linux/crash_dump.h>
52 53
53#if IS_ENABLED(CONFIG_CNIC) 54#if IS_ENABLED(CONFIG_CNIC)
54#define BCM_CNIC 1 55#define BCM_CNIC 1
@@ -271,22 +272,25 @@ static inline u32 bnx2_tx_avail(struct bnx2 *bp, struct bnx2_tx_ring_info *txr)
271static u32 272static u32
272bnx2_reg_rd_ind(struct bnx2 *bp, u32 offset) 273bnx2_reg_rd_ind(struct bnx2 *bp, u32 offset)
273{ 274{
275 unsigned long flags;
274 u32 val; 276 u32 val;
275 277
276 spin_lock_bh(&bp->indirect_lock); 278 spin_lock_irqsave(&bp->indirect_lock, flags);
277 BNX2_WR(bp, BNX2_PCICFG_REG_WINDOW_ADDRESS, offset); 279 BNX2_WR(bp, BNX2_PCICFG_REG_WINDOW_ADDRESS, offset);
278 val = BNX2_RD(bp, BNX2_PCICFG_REG_WINDOW); 280 val = BNX2_RD(bp, BNX2_PCICFG_REG_WINDOW);
279 spin_unlock_bh(&bp->indirect_lock); 281 spin_unlock_irqrestore(&bp->indirect_lock, flags);
280 return val; 282 return val;
281} 283}
282 284
283static void 285static void
284bnx2_reg_wr_ind(struct bnx2 *bp, u32 offset, u32 val) 286bnx2_reg_wr_ind(struct bnx2 *bp, u32 offset, u32 val)
285{ 287{
286 spin_lock_bh(&bp->indirect_lock); 288 unsigned long flags;
289
290 spin_lock_irqsave(&bp->indirect_lock, flags);
287 BNX2_WR(bp, BNX2_PCICFG_REG_WINDOW_ADDRESS, offset); 291 BNX2_WR(bp, BNX2_PCICFG_REG_WINDOW_ADDRESS, offset);
288 BNX2_WR(bp, BNX2_PCICFG_REG_WINDOW, val); 292 BNX2_WR(bp, BNX2_PCICFG_REG_WINDOW, val);
289 spin_unlock_bh(&bp->indirect_lock); 293 spin_unlock_irqrestore(&bp->indirect_lock, flags);
290} 294}
291 295
292static void 296static void
@@ -304,8 +308,10 @@ bnx2_shmem_rd(struct bnx2 *bp, u32 offset)
304static void 308static void
305bnx2_ctx_wr(struct bnx2 *bp, u32 cid_addr, u32 offset, u32 val) 309bnx2_ctx_wr(struct bnx2 *bp, u32 cid_addr, u32 offset, u32 val)
306{ 310{
311 unsigned long flags;
312
307 offset += cid_addr; 313 offset += cid_addr;
308 spin_lock_bh(&bp->indirect_lock); 314 spin_lock_irqsave(&bp->indirect_lock, flags);
309 if (BNX2_CHIP(bp) == BNX2_CHIP_5709) { 315 if (BNX2_CHIP(bp) == BNX2_CHIP_5709) {
310 int i; 316 int i;
311 317
@@ -322,7 +328,7 @@ bnx2_ctx_wr(struct bnx2 *bp, u32 cid_addr, u32 offset, u32 val)
322 BNX2_WR(bp, BNX2_CTX_DATA_ADR, offset); 328 BNX2_WR(bp, BNX2_CTX_DATA_ADR, offset);
323 BNX2_WR(bp, BNX2_CTX_DATA, val); 329 BNX2_WR(bp, BNX2_CTX_DATA, val);
324 } 330 }
325 spin_unlock_bh(&bp->indirect_lock); 331 spin_unlock_irqrestore(&bp->indirect_lock, flags);
326} 332}
327 333
328#ifdef BCM_CNIC 334#ifdef BCM_CNIC
@@ -4759,15 +4765,16 @@ bnx2_setup_msix_tbl(struct bnx2 *bp)
4759 BNX2_WR(bp, BNX2_PCI_GRC_WINDOW3_ADDR, BNX2_MSIX_PBA_ADDR); 4765 BNX2_WR(bp, BNX2_PCI_GRC_WINDOW3_ADDR, BNX2_MSIX_PBA_ADDR);
4760} 4766}
4761 4767
4762static int 4768static void
4763bnx2_reset_chip(struct bnx2 *bp, u32 reset_code) 4769bnx2_wait_dma_complete(struct bnx2 *bp)
4764{ 4770{
4765 u32 val; 4771 u32 val;
4766 int i, rc = 0; 4772 int i;
4767 u8 old_port;
4768 4773
4769 /* Wait for the current PCI transaction to complete before 4774 /*
4770 * issuing a reset. */ 4775 * Wait for the current PCI transaction to complete before
4776 * issuing a reset.
4777 */
4771 if ((BNX2_CHIP(bp) == BNX2_CHIP_5706) || 4778 if ((BNX2_CHIP(bp) == BNX2_CHIP_5706) ||
4772 (BNX2_CHIP(bp) == BNX2_CHIP_5708)) { 4779 (BNX2_CHIP(bp) == BNX2_CHIP_5708)) {
4773 BNX2_WR(bp, BNX2_MISC_ENABLE_CLR_BITS, 4780 BNX2_WR(bp, BNX2_MISC_ENABLE_CLR_BITS,
@@ -4791,6 +4798,21 @@ bnx2_reset_chip(struct bnx2 *bp, u32 reset_code)
4791 } 4798 }
4792 } 4799 }
4793 4800
4801 return;
4802}
4803
4804
4805static int
4806bnx2_reset_chip(struct bnx2 *bp, u32 reset_code)
4807{
4808 u32 val;
4809 int i, rc = 0;
4810 u8 old_port;
4811
4812 /* Wait for the current PCI transaction to complete before
4813 * issuing a reset. */
4814 bnx2_wait_dma_complete(bp);
4815
4794 /* Wait for the firmware to tell us it is ok to issue a reset. */ 4816 /* Wait for the firmware to tell us it is ok to issue a reset. */
4795 bnx2_fw_sync(bp, BNX2_DRV_MSG_DATA_WAIT0 | reset_code, 1, 1); 4817 bnx2_fw_sync(bp, BNX2_DRV_MSG_DATA_WAIT0 | reset_code, 1, 1);
4796 4818
@@ -6356,6 +6378,10 @@ bnx2_open(struct net_device *dev)
6356 struct bnx2 *bp = netdev_priv(dev); 6378 struct bnx2 *bp = netdev_priv(dev);
6357 int rc; 6379 int rc;
6358 6380
6381 rc = bnx2_request_firmware(bp);
6382 if (rc < 0)
6383 goto out;
6384
6359 netif_carrier_off(dev); 6385 netif_carrier_off(dev);
6360 6386
6361 bnx2_disable_int(bp); 6387 bnx2_disable_int(bp);
@@ -6424,6 +6450,7 @@ open_err:
6424 bnx2_free_irq(bp); 6450 bnx2_free_irq(bp);
6425 bnx2_free_mem(bp); 6451 bnx2_free_mem(bp);
6426 bnx2_del_napi(bp); 6452 bnx2_del_napi(bp);
6453 bnx2_release_firmware(bp);
6427 goto out; 6454 goto out;
6428} 6455}
6429 6456
@@ -8570,12 +8597,15 @@ bnx2_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
8570 8597
8571 pci_set_drvdata(pdev, dev); 8598 pci_set_drvdata(pdev, dev);
8572 8599
8573 rc = bnx2_request_firmware(bp); 8600 /*
8574 if (rc < 0) 8601 * In-flight DMA from 1st kernel could continue going in kdump kernel.
8575 goto error; 8602 * New io-page table has been created before bnx2 does reset at open stage.
8576 8603 * We have to wait for the in-flight DMA to complete to avoid it look up
8604 * into the newly created io-page table.
8605 */
8606 if (is_kdump_kernel())
8607 bnx2_wait_dma_complete(bp);
8577 8608
8578 bnx2_reset_chip(bp, BNX2_DRV_MSG_CODE_RESET);
8579 memcpy(dev->dev_addr, bp->mac_addr, ETH_ALEN); 8609 memcpy(dev->dev_addr, bp->mac_addr, ETH_ALEN);
8580 8610
8581 dev->hw_features = NETIF_F_IP_CSUM | NETIF_F_SG | 8611 dev->hw_features = NETIF_F_IP_CSUM | NETIF_F_SG |
@@ -8608,7 +8638,6 @@ bnx2_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
8608 return 0; 8638 return 0;
8609 8639
8610error: 8640error:
8611 bnx2_release_firmware(bp);
8612 pci_iounmap(pdev, bp->regview); 8641 pci_iounmap(pdev, bp->regview);
8613 pci_release_regions(pdev); 8642 pci_release_regions(pdev);
8614 pci_disable_device(pdev); 8643 pci_disable_device(pdev);
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c
index 85a7800bfc12..5f19427c7b27 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c
@@ -1872,8 +1872,16 @@ static void bnx2x_get_ringparam(struct net_device *dev,
1872 1872
1873 ering->rx_max_pending = MAX_RX_AVAIL; 1873 ering->rx_max_pending = MAX_RX_AVAIL;
1874 1874
1875 /* If size isn't already set, we give an estimation of the number
1876 * of buffers we'll have. We're neglecting some possible conditions
1877 * [we couldn't know for certain at this point if number of queues
1878 * might shrink] but the number would be correct for the likely
1879 * scenario.
1880 */
1875 if (bp->rx_ring_size) 1881 if (bp->rx_ring_size)
1876 ering->rx_pending = bp->rx_ring_size; 1882 ering->rx_pending = bp->rx_ring_size;
1883 else if (BNX2X_NUM_RX_QUEUES(bp))
1884 ering->rx_pending = MAX_RX_AVAIL / BNX2X_NUM_RX_QUEUES(bp);
1877 else 1885 else
1878 ering->rx_pending = MAX_RX_AVAIL; 1886 ering->rx_pending = MAX_RX_AVAIL;
1879 1887
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
index 20fe6a8c35c1..4febe60eadc2 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
@@ -10138,7 +10138,7 @@ static void __bnx2x_add_udp_port(struct bnx2x *bp, u16 port,
10138{ 10138{
10139 struct bnx2x_udp_tunnel *udp_port = &bp->udp_tunnel_ports[type]; 10139 struct bnx2x_udp_tunnel *udp_port = &bp->udp_tunnel_ports[type];
10140 10140
10141 if (!netif_running(bp->dev) || !IS_PF(bp)) 10141 if (!netif_running(bp->dev) || !IS_PF(bp) || CHIP_IS_E1x(bp))
10142 return; 10142 return;
10143 10143
10144 if (udp_port->count && udp_port->dst_port == port) { 10144 if (udp_port->count && udp_port->dst_port == port) {
@@ -10163,7 +10163,7 @@ static void __bnx2x_del_udp_port(struct bnx2x *bp, u16 port,
10163{ 10163{
10164 struct bnx2x_udp_tunnel *udp_port = &bp->udp_tunnel_ports[type]; 10164 struct bnx2x_udp_tunnel *udp_port = &bp->udp_tunnel_ports[type];
10165 10165
10166 if (!IS_PF(bp)) 10166 if (!IS_PF(bp) || CHIP_IS_E1x(bp))
10167 return; 10167 return;
10168 10168
10169 if (!udp_port->count || udp_port->dst_port != port) { 10169 if (!udp_port->count || udp_port->dst_port != port) {
@@ -13505,6 +13505,7 @@ static int bnx2x_init_firmware(struct bnx2x *bp)
13505 13505
13506 /* Initialize the pointers to the init arrays */ 13506 /* Initialize the pointers to the init arrays */
13507 /* Blob */ 13507 /* Blob */
13508 rc = -ENOMEM;
13508 BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n); 13509 BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n);
13509 13510
13510 /* Opcodes */ 13511 /* Opcodes */
@@ -15241,7 +15242,7 @@ static void bnx2x_init_cyclecounter(struct bnx2x *bp)
15241 memset(&bp->cyclecounter, 0, sizeof(bp->cyclecounter)); 15242 memset(&bp->cyclecounter, 0, sizeof(bp->cyclecounter));
15242 bp->cyclecounter.read = bnx2x_cyclecounter_read; 15243 bp->cyclecounter.read = bnx2x_cyclecounter_read;
15243 bp->cyclecounter.mask = CYCLECOUNTER_MASK(64); 15244 bp->cyclecounter.mask = CYCLECOUNTER_MASK(64);
15244 bp->cyclecounter.shift = 1; 15245 bp->cyclecounter.shift = 0;
15245 bp->cyclecounter.mult = 1; 15246 bp->cyclecounter.mult = 1;
15246} 15247}
15247 15248
diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.c b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
index a9f9f3738022..f08a20b921e7 100644
--- a/drivers/net/ethernet/broadcom/bnxt/bnxt.c
+++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
@@ -1811,6 +1811,9 @@ static int bnxt_busy_poll(struct napi_struct *napi)
1811 if (atomic_read(&bp->intr_sem) != 0) 1811 if (atomic_read(&bp->intr_sem) != 0)
1812 return LL_FLUSH_FAILED; 1812 return LL_FLUSH_FAILED;
1813 1813
1814 if (!bp->link_info.link_up)
1815 return LL_FLUSH_FAILED;
1816
1814 if (!bnxt_lock_poll(bnapi)) 1817 if (!bnxt_lock_poll(bnapi))
1815 return LL_FLUSH_BUSY; 1818 return LL_FLUSH_BUSY;
1816 1819
@@ -3210,11 +3213,17 @@ static int bnxt_hwrm_tunnel_dst_port_alloc(struct bnxt *bp, __be16 port,
3210 goto err_out; 3213 goto err_out;
3211 } 3214 }
3212 3215
3213 if (tunnel_type & TUNNEL_DST_PORT_ALLOC_REQ_TUNNEL_TYPE_VXLAN) 3216 switch (tunnel_type) {
3217 case TUNNEL_DST_PORT_ALLOC_REQ_TUNNEL_TYPE_VXLAN:
3214 bp->vxlan_fw_dst_port_id = resp->tunnel_dst_port_id; 3218 bp->vxlan_fw_dst_port_id = resp->tunnel_dst_port_id;
3215 3219 break;
3216 else if (tunnel_type & TUNNEL_DST_PORT_ALLOC_REQ_TUNNEL_TYPE_GENEVE) 3220 case TUNNEL_DST_PORT_ALLOC_REQ_TUNNEL_TYPE_GENEVE:
3217 bp->nge_fw_dst_port_id = resp->tunnel_dst_port_id; 3221 bp->nge_fw_dst_port_id = resp->tunnel_dst_port_id;
3222 break;
3223 default:
3224 break;
3225 }
3226
3218err_out: 3227err_out:
3219 mutex_unlock(&bp->hwrm_cmd_lock); 3228 mutex_unlock(&bp->hwrm_cmd_lock);
3220 return rc; 3229 return rc;
@@ -4111,7 +4120,7 @@ static int bnxt_hwrm_stat_ctx_alloc(struct bnxt *bp)
4111 bp->grp_info[i].fw_stats_ctx = cpr->hw_stats_ctx_id; 4120 bp->grp_info[i].fw_stats_ctx = cpr->hw_stats_ctx_id;
4112 } 4121 }
4113 mutex_unlock(&bp->hwrm_cmd_lock); 4122 mutex_unlock(&bp->hwrm_cmd_lock);
4114 return 0; 4123 return rc;
4115} 4124}
4116 4125
4117static int bnxt_hwrm_func_qcfg(struct bnxt *bp) 4126static int bnxt_hwrm_func_qcfg(struct bnxt *bp)
@@ -4934,6 +4943,10 @@ static void bnxt_del_napi(struct bnxt *bp)
4934 napi_hash_del(&bnapi->napi); 4943 napi_hash_del(&bnapi->napi);
4935 netif_napi_del(&bnapi->napi); 4944 netif_napi_del(&bnapi->napi);
4936 } 4945 }
4946 /* We called napi_hash_del() before netif_napi_del(), we need
4947 * to respect an RCU grace period before freeing napi structures.
4948 */
4949 synchronize_net();
4937} 4950}
4938 4951
4939static void bnxt_init_napi(struct bnxt *bp) 4952static void bnxt_init_napi(struct bnxt *bp)
@@ -6309,6 +6322,7 @@ static int bnxt_setup_tc(struct net_device *dev, u32 handle, __be16 proto,
6309 struct tc_to_netdev *ntc) 6322 struct tc_to_netdev *ntc)
6310{ 6323{
6311 struct bnxt *bp = netdev_priv(dev); 6324 struct bnxt *bp = netdev_priv(dev);
6325 bool sh = false;
6312 u8 tc; 6326 u8 tc;
6313 6327
6314 if (ntc->type != TC_SETUP_MQPRIO) 6328 if (ntc->type != TC_SETUP_MQPRIO)
@@ -6325,12 +6339,11 @@ static int bnxt_setup_tc(struct net_device *dev, u32 handle, __be16 proto,
6325 if (netdev_get_num_tc(dev) == tc) 6339 if (netdev_get_num_tc(dev) == tc)
6326 return 0; 6340 return 0;
6327 6341
6342 if (bp->flags & BNXT_FLAG_SHARED_RINGS)
6343 sh = true;
6344
6328 if (tc) { 6345 if (tc) {
6329 int max_rx_rings, max_tx_rings, rc; 6346 int max_rx_rings, max_tx_rings, rc;
6330 bool sh = false;
6331
6332 if (bp->flags & BNXT_FLAG_SHARED_RINGS)
6333 sh = true;
6334 6347
6335 rc = bnxt_get_max_rings(bp, &max_rx_rings, &max_tx_rings, sh); 6348 rc = bnxt_get_max_rings(bp, &max_rx_rings, &max_tx_rings, sh);
6336 if (rc || bp->tx_nr_rings_per_tc * tc > max_tx_rings) 6349 if (rc || bp->tx_nr_rings_per_tc * tc > max_tx_rings)
@@ -6348,7 +6361,8 @@ static int bnxt_setup_tc(struct net_device *dev, u32 handle, __be16 proto,
6348 bp->tx_nr_rings = bp->tx_nr_rings_per_tc; 6361 bp->tx_nr_rings = bp->tx_nr_rings_per_tc;
6349 netdev_reset_tc(dev); 6362 netdev_reset_tc(dev);
6350 } 6363 }
6351 bp->cp_nr_rings = max_t(int, bp->tx_nr_rings, bp->rx_nr_rings); 6364 bp->cp_nr_rings = sh ? max_t(int, bp->tx_nr_rings, bp->rx_nr_rings) :
6365 bp->tx_nr_rings + bp->rx_nr_rings;
6352 bp->num_stat_ctxs = bp->cp_nr_rings; 6366 bp->num_stat_ctxs = bp->cp_nr_rings;
6353 6367
6354 if (netif_running(bp->dev)) 6368 if (netif_running(bp->dev))
diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_sriov.c b/drivers/net/ethernet/broadcom/bnxt/bnxt_sriov.c
index ec6cd18842c3..60e2af8678bd 100644
--- a/drivers/net/ethernet/broadcom/bnxt/bnxt_sriov.c
+++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_sriov.c
@@ -774,8 +774,8 @@ static int bnxt_vf_set_link(struct bnxt *bp, struct bnxt_vf_info *vf)
774 774
775 if (vf->flags & BNXT_VF_LINK_UP) { 775 if (vf->flags & BNXT_VF_LINK_UP) {
776 /* if physical link is down, force link up on VF */ 776 /* if physical link is down, force link up on VF */
777 if (phy_qcfg_resp.link == 777 if (phy_qcfg_resp.link !=
778 PORT_PHY_QCFG_RESP_LINK_NO_LINK) { 778 PORT_PHY_QCFG_RESP_LINK_LINK) {
779 phy_qcfg_resp.link = 779 phy_qcfg_resp.link =
780 PORT_PHY_QCFG_RESP_LINK_LINK; 780 PORT_PHY_QCFG_RESP_LINK_LINK;
781 phy_qcfg_resp.link_speed = cpu_to_le16( 781 phy_qcfg_resp.link_speed = cpu_to_le16(
diff --git a/drivers/net/ethernet/broadcom/genet/bcmgenet.c b/drivers/net/ethernet/broadcom/genet/bcmgenet.c
index 4464bc5db934..a4e60e56c14f 100644
--- a/drivers/net/ethernet/broadcom/genet/bcmgenet.c
+++ b/drivers/net/ethernet/broadcom/genet/bcmgenet.c
@@ -1172,6 +1172,7 @@ static unsigned int __bcmgenet_tx_reclaim(struct net_device *dev,
1172 struct bcmgenet_tx_ring *ring) 1172 struct bcmgenet_tx_ring *ring)
1173{ 1173{
1174 struct bcmgenet_priv *priv = netdev_priv(dev); 1174 struct bcmgenet_priv *priv = netdev_priv(dev);
1175 struct device *kdev = &priv->pdev->dev;
1175 struct enet_cb *tx_cb_ptr; 1176 struct enet_cb *tx_cb_ptr;
1176 struct netdev_queue *txq; 1177 struct netdev_queue *txq;
1177 unsigned int pkts_compl = 0; 1178 unsigned int pkts_compl = 0;
@@ -1199,13 +1200,13 @@ static unsigned int __bcmgenet_tx_reclaim(struct net_device *dev,
1199 if (tx_cb_ptr->skb) { 1200 if (tx_cb_ptr->skb) {
1200 pkts_compl++; 1201 pkts_compl++;
1201 bytes_compl += GENET_CB(tx_cb_ptr->skb)->bytes_sent; 1202 bytes_compl += GENET_CB(tx_cb_ptr->skb)->bytes_sent;
1202 dma_unmap_single(&dev->dev, 1203 dma_unmap_single(kdev,
1203 dma_unmap_addr(tx_cb_ptr, dma_addr), 1204 dma_unmap_addr(tx_cb_ptr, dma_addr),
1204 dma_unmap_len(tx_cb_ptr, dma_len), 1205 dma_unmap_len(tx_cb_ptr, dma_len),
1205 DMA_TO_DEVICE); 1206 DMA_TO_DEVICE);
1206 bcmgenet_free_cb(tx_cb_ptr); 1207 bcmgenet_free_cb(tx_cb_ptr);
1207 } else if (dma_unmap_addr(tx_cb_ptr, dma_addr)) { 1208 } else if (dma_unmap_addr(tx_cb_ptr, dma_addr)) {
1208 dma_unmap_page(&dev->dev, 1209 dma_unmap_page(kdev,
1209 dma_unmap_addr(tx_cb_ptr, dma_addr), 1210 dma_unmap_addr(tx_cb_ptr, dma_addr),
1210 dma_unmap_len(tx_cb_ptr, dma_len), 1211 dma_unmap_len(tx_cb_ptr, dma_len),
1211 DMA_TO_DEVICE); 1212 DMA_TO_DEVICE);
@@ -1775,6 +1776,7 @@ static int bcmgenet_alloc_rx_buffers(struct bcmgenet_priv *priv,
1775 1776
1776static void bcmgenet_free_rx_buffers(struct bcmgenet_priv *priv) 1777static void bcmgenet_free_rx_buffers(struct bcmgenet_priv *priv)
1777{ 1778{
1779 struct device *kdev = &priv->pdev->dev;
1778 struct enet_cb *cb; 1780 struct enet_cb *cb;
1779 int i; 1781 int i;
1780 1782
@@ -1782,7 +1784,7 @@ static void bcmgenet_free_rx_buffers(struct bcmgenet_priv *priv)
1782 cb = &priv->rx_cbs[i]; 1784 cb = &priv->rx_cbs[i];
1783 1785
1784 if (dma_unmap_addr(cb, dma_addr)) { 1786 if (dma_unmap_addr(cb, dma_addr)) {
1785 dma_unmap_single(&priv->dev->dev, 1787 dma_unmap_single(kdev,
1786 dma_unmap_addr(cb, dma_addr), 1788 dma_unmap_addr(cb, dma_addr),
1787 priv->rx_buf_len, DMA_FROM_DEVICE); 1789 priv->rx_buf_len, DMA_FROM_DEVICE);
1788 dma_unmap_addr_set(cb, dma_addr, 0); 1790 dma_unmap_addr_set(cb, dma_addr, 0);
diff --git a/drivers/net/ethernet/broadcom/genet/bcmmii.c b/drivers/net/ethernet/broadcom/genet/bcmmii.c
index 457c3bc8cfff..e87607621e62 100644
--- a/drivers/net/ethernet/broadcom/genet/bcmmii.c
+++ b/drivers/net/ethernet/broadcom/genet/bcmmii.c
@@ -542,8 +542,10 @@ static int bcmgenet_mii_of_init(struct bcmgenet_priv *priv)
542 /* Make sure we initialize MoCA PHYs with a link down */ 542 /* Make sure we initialize MoCA PHYs with a link down */
543 if (phy_mode == PHY_INTERFACE_MODE_MOCA) { 543 if (phy_mode == PHY_INTERFACE_MODE_MOCA) {
544 phydev = of_phy_find_device(dn); 544 phydev = of_phy_find_device(dn);
545 if (phydev) 545 if (phydev) {
546 phydev->link = 0; 546 phydev->link = 0;
547 put_device(&phydev->mdio.dev);
548 }
547 } 549 }
548 550
549 return 0; 551 return 0;
@@ -625,6 +627,7 @@ static int bcmgenet_mii_bus_init(struct bcmgenet_priv *priv)
625int bcmgenet_mii_init(struct net_device *dev) 627int bcmgenet_mii_init(struct net_device *dev)
626{ 628{
627 struct bcmgenet_priv *priv = netdev_priv(dev); 629 struct bcmgenet_priv *priv = netdev_priv(dev);
630 struct device_node *dn = priv->pdev->dev.of_node;
628 int ret; 631 int ret;
629 632
630 ret = bcmgenet_mii_alloc(priv); 633 ret = bcmgenet_mii_alloc(priv);
@@ -638,6 +641,8 @@ int bcmgenet_mii_init(struct net_device *dev)
638 return 0; 641 return 0;
639 642
640out: 643out:
644 if (of_phy_is_fixed_link(dn))
645 of_phy_deregister_fixed_link(dn);
641 of_node_put(priv->phy_dn); 646 of_node_put(priv->phy_dn);
642 mdiobus_unregister(priv->mii_bus); 647 mdiobus_unregister(priv->mii_bus);
643 mdiobus_free(priv->mii_bus); 648 mdiobus_free(priv->mii_bus);
@@ -647,7 +652,10 @@ out:
647void bcmgenet_mii_exit(struct net_device *dev) 652void bcmgenet_mii_exit(struct net_device *dev)
648{ 653{
649 struct bcmgenet_priv *priv = netdev_priv(dev); 654 struct bcmgenet_priv *priv = netdev_priv(dev);
655 struct device_node *dn = priv->pdev->dev.of_node;
650 656
657 if (of_phy_is_fixed_link(dn))
658 of_phy_deregister_fixed_link(dn);
651 of_node_put(priv->phy_dn); 659 of_node_put(priv->phy_dn);
652 mdiobus_unregister(priv->mii_bus); 660 mdiobus_unregister(priv->mii_bus);
653 mdiobus_free(priv->mii_bus); 661 mdiobus_free(priv->mii_bus);
diff --git a/drivers/net/ethernet/brocade/bna/bnad.c b/drivers/net/ethernet/brocade/bna/bnad.c
index f9df4b5ae90e..f42f672b0e7e 100644
--- a/drivers/net/ethernet/brocade/bna/bnad.c
+++ b/drivers/net/ethernet/brocade/bna/bnad.c
@@ -177,6 +177,7 @@ bnad_txcmpl_process(struct bnad *bnad, struct bna_tcb *tcb)
177 return 0; 177 return 0;
178 178
179 hw_cons = *(tcb->hw_consumer_index); 179 hw_cons = *(tcb->hw_consumer_index);
180 rmb();
180 cons = tcb->consumer_index; 181 cons = tcb->consumer_index;
181 q_depth = tcb->q_depth; 182 q_depth = tcb->q_depth;
182 183
@@ -3094,7 +3095,7 @@ bnad_start_xmit(struct sk_buff *skb, struct net_device *netdev)
3094 BNA_QE_INDX_INC(prod, q_depth); 3095 BNA_QE_INDX_INC(prod, q_depth);
3095 tcb->producer_index = prod; 3096 tcb->producer_index = prod;
3096 3097
3097 smp_mb(); 3098 wmb();
3098 3099
3099 if (unlikely(!test_bit(BNAD_TXQ_TX_STARTED, &tcb->flags))) 3100 if (unlikely(!test_bit(BNAD_TXQ_TX_STARTED, &tcb->flags)))
3100 return NETDEV_TX_OK; 3101 return NETDEV_TX_OK;
@@ -3102,7 +3103,6 @@ bnad_start_xmit(struct sk_buff *skb, struct net_device *netdev)
3102 skb_tx_timestamp(skb); 3103 skb_tx_timestamp(skb);
3103 3104
3104 bna_txq_prod_indx_doorbell(tcb); 3105 bna_txq_prod_indx_doorbell(tcb);
3105 smp_mb();
3106 3106
3107 return NETDEV_TX_OK; 3107 return NETDEV_TX_OK;
3108} 3108}
diff --git a/drivers/net/ethernet/cadence/macb.c b/drivers/net/ethernet/cadence/macb.c
index b32444a3ed79..ec09fcece711 100644
--- a/drivers/net/ethernet/cadence/macb.c
+++ b/drivers/net/ethernet/cadence/macb.c
@@ -975,6 +975,7 @@ static inline void macb_init_rx_ring(struct macb *bp)
975 addr += bp->rx_buffer_size; 975 addr += bp->rx_buffer_size;
976 } 976 }
977 bp->rx_ring[RX_RING_SIZE - 1].addr |= MACB_BIT(RX_WRAP); 977 bp->rx_ring[RX_RING_SIZE - 1].addr |= MACB_BIT(RX_WRAP);
978 bp->rx_tail = 0;
978} 979}
979 980
980static int macb_rx(struct macb *bp, int budget) 981static int macb_rx(struct macb *bp, int budget)
@@ -1156,6 +1157,7 @@ static irqreturn_t macb_interrupt(int irq, void *dev_id)
1156 if (status & MACB_BIT(RXUBR)) { 1157 if (status & MACB_BIT(RXUBR)) {
1157 ctrl = macb_readl(bp, NCR); 1158 ctrl = macb_readl(bp, NCR);
1158 macb_writel(bp, NCR, ctrl & ~MACB_BIT(RE)); 1159 macb_writel(bp, NCR, ctrl & ~MACB_BIT(RE));
1160 wmb();
1159 macb_writel(bp, NCR, ctrl | MACB_BIT(RE)); 1161 macb_writel(bp, NCR, ctrl | MACB_BIT(RE));
1160 1162
1161 if (bp->caps & MACB_CAPS_ISR_CLEAR_ON_WRITE) 1163 if (bp->caps & MACB_CAPS_ISR_CLEAR_ON_WRITE)
@@ -1616,8 +1618,6 @@ static void macb_init_rings(struct macb *bp)
1616 bp->queues[0].tx_head = 0; 1618 bp->queues[0].tx_head = 0;
1617 bp->queues[0].tx_tail = 0; 1619 bp->queues[0].tx_tail = 0;
1618 bp->queues[0].tx_ring[TX_RING_SIZE - 1].ctrl |= MACB_BIT(TX_WRAP); 1620 bp->queues[0].tx_ring[TX_RING_SIZE - 1].ctrl |= MACB_BIT(TX_WRAP);
1619
1620 bp->rx_tail = 0;
1621} 1621}
1622 1622
1623static void macb_reset_hw(struct macb *bp) 1623static void macb_reset_hw(struct macb *bp)
@@ -2673,6 +2673,12 @@ static int at91ether_start_xmit(struct sk_buff *skb, struct net_device *dev)
2673 lp->skb_length = skb->len; 2673 lp->skb_length = skb->len;
2674 lp->skb_physaddr = dma_map_single(NULL, skb->data, skb->len, 2674 lp->skb_physaddr = dma_map_single(NULL, skb->data, skb->len,
2675 DMA_TO_DEVICE); 2675 DMA_TO_DEVICE);
2676 if (dma_mapping_error(NULL, lp->skb_physaddr)) {
2677 dev_kfree_skb_any(skb);
2678 dev->stats.tx_dropped++;
2679 netdev_err(dev, "%s: DMA mapping error\n", __func__);
2680 return NETDEV_TX_OK;
2681 }
2676 2682
2677 /* Set address of the data in the Transmit Address register */ 2683 /* Set address of the data in the Transmit Address register */
2678 macb_writel(lp, TAR, lp->skb_physaddr); 2684 macb_writel(lp, TAR, lp->skb_physaddr);
@@ -2764,6 +2770,7 @@ static irqreturn_t at91ether_interrupt(int irq, void *dev_id)
2764 if (intstatus & MACB_BIT(RXUBR)) { 2770 if (intstatus & MACB_BIT(RXUBR)) {
2765 ctl = macb_readl(lp, NCR); 2771 ctl = macb_readl(lp, NCR);
2766 macb_writel(lp, NCR, ctl & ~MACB_BIT(RE)); 2772 macb_writel(lp, NCR, ctl & ~MACB_BIT(RE));
2773 wmb();
2767 macb_writel(lp, NCR, ctl | MACB_BIT(RE)); 2774 macb_writel(lp, NCR, ctl | MACB_BIT(RE));
2768 } 2775 }
2769 2776
diff --git a/drivers/net/ethernet/cavium/thunder/nic.h b/drivers/net/ethernet/cavium/thunder/nic.h
index 30426109711c..86bd93ce2ea3 100644
--- a/drivers/net/ethernet/cavium/thunder/nic.h
+++ b/drivers/net/ethernet/cavium/thunder/nic.h
@@ -47,7 +47,7 @@
47 47
48/* Min/Max packet size */ 48/* Min/Max packet size */
49#define NIC_HW_MIN_FRS 64 49#define NIC_HW_MIN_FRS 64
50#define NIC_HW_MAX_FRS 9200 /* 9216 max packet including FCS */ 50#define NIC_HW_MAX_FRS 9190 /* Excluding L2 header and FCS */
51 51
52/* Max pkinds */ 52/* Max pkinds */
53#define NIC_MAX_PKIND 16 53#define NIC_MAX_PKIND 16
@@ -178,11 +178,11 @@ enum tx_stats_reg_offset {
178 178
179struct nicvf_hw_stats { 179struct nicvf_hw_stats {
180 u64 rx_bytes; 180 u64 rx_bytes;
181 u64 rx_frames;
181 u64 rx_ucast_frames; 182 u64 rx_ucast_frames;
182 u64 rx_bcast_frames; 183 u64 rx_bcast_frames;
183 u64 rx_mcast_frames; 184 u64 rx_mcast_frames;
184 u64 rx_fcs_errors; 185 u64 rx_drops;
185 u64 rx_l2_errors;
186 u64 rx_drop_red; 186 u64 rx_drop_red;
187 u64 rx_drop_red_bytes; 187 u64 rx_drop_red_bytes;
188 u64 rx_drop_overrun; 188 u64 rx_drop_overrun;
@@ -191,6 +191,19 @@ struct nicvf_hw_stats {
191 u64 rx_drop_mcast; 191 u64 rx_drop_mcast;
192 u64 rx_drop_l3_bcast; 192 u64 rx_drop_l3_bcast;
193 u64 rx_drop_l3_mcast; 193 u64 rx_drop_l3_mcast;
194 u64 rx_fcs_errors;
195 u64 rx_l2_errors;
196
197 u64 tx_bytes;
198 u64 tx_frames;
199 u64 tx_ucast_frames;
200 u64 tx_bcast_frames;
201 u64 tx_mcast_frames;
202 u64 tx_drops;
203};
204
205struct nicvf_drv_stats {
206 /* CQE Rx errs */
194 u64 rx_bgx_truncated_pkts; 207 u64 rx_bgx_truncated_pkts;
195 u64 rx_jabber_errs; 208 u64 rx_jabber_errs;
196 u64 rx_fcs_errs; 209 u64 rx_fcs_errs;
@@ -216,34 +229,30 @@ struct nicvf_hw_stats {
216 u64 rx_l4_pclp; 229 u64 rx_l4_pclp;
217 u64 rx_truncated_pkts; 230 u64 rx_truncated_pkts;
218 231
219 u64 tx_bytes_ok; 232 /* CQE Tx errs */
220 u64 tx_ucast_frames_ok; 233 u64 tx_desc_fault;
221 u64 tx_bcast_frames_ok; 234 u64 tx_hdr_cons_err;
222 u64 tx_mcast_frames_ok; 235 u64 tx_subdesc_err;
223 u64 tx_drops; 236 u64 tx_max_size_exceeded;
224}; 237 u64 tx_imm_size_oflow;
225 238 u64 tx_data_seq_err;
226struct nicvf_drv_stats { 239 u64 tx_mem_seq_err;
227 /* Rx */ 240 u64 tx_lock_viol;
228 u64 rx_frames_ok; 241 u64 tx_data_fault;
229 u64 rx_frames_64; 242 u64 tx_tstmp_conflict;
230 u64 rx_frames_127; 243 u64 tx_tstmp_timeout;
231 u64 rx_frames_255; 244 u64 tx_mem_fault;
232 u64 rx_frames_511; 245 u64 tx_csum_overlap;
233 u64 rx_frames_1023; 246 u64 tx_csum_overflow;
234 u64 rx_frames_1518; 247
235 u64 rx_frames_jumbo; 248 /* driver debug stats */
236 u64 rx_drops;
237
238 u64 rcv_buffer_alloc_failures; 249 u64 rcv_buffer_alloc_failures;
239
240 /* Tx */
241 u64 tx_frames_ok;
242 u64 tx_drops;
243 u64 tx_tso; 250 u64 tx_tso;
244 u64 tx_timeout; 251 u64 tx_timeout;
245 u64 txq_stop; 252 u64 txq_stop;
246 u64 txq_wake; 253 u64 txq_wake;
254
255 struct u64_stats_sync syncp;
247}; 256};
248 257
249struct nicvf { 258struct nicvf {
@@ -282,7 +291,6 @@ struct nicvf {
282 291
283 u8 node; 292 u8 node;
284 u8 cpi_alg; 293 u8 cpi_alg;
285 u16 mtu;
286 bool link_up; 294 bool link_up;
287 u8 duplex; 295 u8 duplex;
288 u32 speed; 296 u32 speed;
@@ -298,7 +306,7 @@ struct nicvf {
298 306
299 /* Stats */ 307 /* Stats */
300 struct nicvf_hw_stats hw_stats; 308 struct nicvf_hw_stats hw_stats;
301 struct nicvf_drv_stats drv_stats; 309 struct nicvf_drv_stats __percpu *drv_stats;
302 struct bgx_stats bgx_stats; 310 struct bgx_stats bgx_stats;
303 311
304 /* MSI-X */ 312 /* MSI-X */
diff --git a/drivers/net/ethernet/cavium/thunder/nic_main.c b/drivers/net/ethernet/cavium/thunder/nic_main.c
index 2bbf4cbf08b2..6677b96e1f3f 100644
--- a/drivers/net/ethernet/cavium/thunder/nic_main.c
+++ b/drivers/net/ethernet/cavium/thunder/nic_main.c
@@ -11,6 +11,7 @@
11#include <linux/pci.h> 11#include <linux/pci.h>
12#include <linux/etherdevice.h> 12#include <linux/etherdevice.h>
13#include <linux/of.h> 13#include <linux/of.h>
14#include <linux/if_vlan.h>
14 15
15#include "nic_reg.h" 16#include "nic_reg.h"
16#include "nic.h" 17#include "nic.h"
@@ -260,18 +261,31 @@ static void nic_get_bgx_stats(struct nicpf *nic, struct bgx_stats_msg *bgx)
260/* Update hardware min/max frame size */ 261/* Update hardware min/max frame size */
261static int nic_update_hw_frs(struct nicpf *nic, int new_frs, int vf) 262static int nic_update_hw_frs(struct nicpf *nic, int new_frs, int vf)
262{ 263{
263 if ((new_frs > NIC_HW_MAX_FRS) || (new_frs < NIC_HW_MIN_FRS)) { 264 int bgx, lmac, lmac_cnt;
264 dev_err(&nic->pdev->dev, 265 u64 lmac_credits;
265 "Invalid MTU setting from VF%d rejected, should be between %d and %d\n", 266
266 vf, NIC_HW_MIN_FRS, NIC_HW_MAX_FRS); 267 if ((new_frs > NIC_HW_MAX_FRS) || (new_frs < NIC_HW_MIN_FRS))
267 return 1; 268 return 1;
268 }
269 new_frs += ETH_HLEN;
270 if (new_frs <= nic->pkind.maxlen)
271 return 0;
272 269
273 nic->pkind.maxlen = new_frs; 270 bgx = NIC_GET_BGX_FROM_VF_LMAC_MAP(nic->vf_lmac_map[vf]);
274 nic_reg_write(nic, NIC_PF_PKIND_0_15_CFG, *(u64 *)&nic->pkind); 271 lmac = NIC_GET_LMAC_FROM_VF_LMAC_MAP(nic->vf_lmac_map[vf]);
272 lmac += bgx * MAX_LMAC_PER_BGX;
273
274 new_frs += VLAN_ETH_HLEN + ETH_FCS_LEN + 4;
275
276 /* Update corresponding LMAC credits */
277 lmac_cnt = bgx_get_lmac_count(nic->node, bgx);
278 lmac_credits = nic_reg_read(nic, NIC_PF_LMAC_0_7_CREDIT + (lmac * 8));
279 lmac_credits &= ~(0xFFFFFULL << 12);
280 lmac_credits |= (((((48 * 1024) / lmac_cnt) - new_frs) / 16) << 12);
281 nic_reg_write(nic, NIC_PF_LMAC_0_7_CREDIT + (lmac * 8), lmac_credits);
282
283 /* Enforce MTU in HW
284 * This config is supported only from 88xx pass 2.0 onwards.
285 */
286 if (!pass1_silicon(nic->pdev))
287 nic_reg_write(nic,
288 NIC_PF_LMAC_0_7_CFG2 + (lmac * 8), new_frs);
275 return 0; 289 return 0;
276} 290}
277 291
@@ -464,7 +478,7 @@ static int nic_init_hw(struct nicpf *nic)
464 478
465 /* PKIND configuration */ 479 /* PKIND configuration */
466 nic->pkind.minlen = 0; 480 nic->pkind.minlen = 0;
467 nic->pkind.maxlen = NIC_HW_MAX_FRS + ETH_HLEN; 481 nic->pkind.maxlen = NIC_HW_MAX_FRS + VLAN_ETH_HLEN + ETH_FCS_LEN + 4;
468 nic->pkind.lenerr_en = 1; 482 nic->pkind.lenerr_en = 1;
469 nic->pkind.rx_hdr = 0; 483 nic->pkind.rx_hdr = 0;
470 nic->pkind.hdr_sl = 0; 484 nic->pkind.hdr_sl = 0;
@@ -837,6 +851,7 @@ static int nic_reset_stat_counters(struct nicpf *nic,
837 nic_reg_write(nic, reg_addr, 0); 851 nic_reg_write(nic, reg_addr, 0);
838 } 852 }
839 } 853 }
854
840 return 0; 855 return 0;
841} 856}
842 857
diff --git a/drivers/net/ethernet/cavium/thunder/nic_reg.h b/drivers/net/ethernet/cavium/thunder/nic_reg.h
index edf779f5a227..80d46337cf29 100644
--- a/drivers/net/ethernet/cavium/thunder/nic_reg.h
+++ b/drivers/net/ethernet/cavium/thunder/nic_reg.h
@@ -106,6 +106,7 @@
106#define NIC_PF_MPI_0_2047_CFG (0x210000) 106#define NIC_PF_MPI_0_2047_CFG (0x210000)
107#define NIC_PF_RSSI_0_4097_RQ (0x220000) 107#define NIC_PF_RSSI_0_4097_RQ (0x220000)
108#define NIC_PF_LMAC_0_7_CFG (0x240000) 108#define NIC_PF_LMAC_0_7_CFG (0x240000)
109#define NIC_PF_LMAC_0_7_CFG2 (0x240100)
109#define NIC_PF_LMAC_0_7_SW_XOFF (0x242000) 110#define NIC_PF_LMAC_0_7_SW_XOFF (0x242000)
110#define NIC_PF_LMAC_0_7_CREDIT (0x244000) 111#define NIC_PF_LMAC_0_7_CREDIT (0x244000)
111#define NIC_PF_CHAN_0_255_TX_CFG (0x400000) 112#define NIC_PF_CHAN_0_255_TX_CFG (0x400000)
diff --git a/drivers/net/ethernet/cavium/thunder/nicvf_ethtool.c b/drivers/net/ethernet/cavium/thunder/nicvf_ethtool.c
index ad4fddb55421..432bf6be57cb 100644
--- a/drivers/net/ethernet/cavium/thunder/nicvf_ethtool.c
+++ b/drivers/net/ethernet/cavium/thunder/nicvf_ethtool.c
@@ -36,11 +36,11 @@ struct nicvf_stat {
36 36
37static const struct nicvf_stat nicvf_hw_stats[] = { 37static const struct nicvf_stat nicvf_hw_stats[] = {
38 NICVF_HW_STAT(rx_bytes), 38 NICVF_HW_STAT(rx_bytes),
39 NICVF_HW_STAT(rx_frames),
39 NICVF_HW_STAT(rx_ucast_frames), 40 NICVF_HW_STAT(rx_ucast_frames),
40 NICVF_HW_STAT(rx_bcast_frames), 41 NICVF_HW_STAT(rx_bcast_frames),
41 NICVF_HW_STAT(rx_mcast_frames), 42 NICVF_HW_STAT(rx_mcast_frames),
42 NICVF_HW_STAT(rx_fcs_errors), 43 NICVF_HW_STAT(rx_drops),
43 NICVF_HW_STAT(rx_l2_errors),
44 NICVF_HW_STAT(rx_drop_red), 44 NICVF_HW_STAT(rx_drop_red),
45 NICVF_HW_STAT(rx_drop_red_bytes), 45 NICVF_HW_STAT(rx_drop_red_bytes),
46 NICVF_HW_STAT(rx_drop_overrun), 46 NICVF_HW_STAT(rx_drop_overrun),
@@ -49,50 +49,59 @@ static const struct nicvf_stat nicvf_hw_stats[] = {
49 NICVF_HW_STAT(rx_drop_mcast), 49 NICVF_HW_STAT(rx_drop_mcast),
50 NICVF_HW_STAT(rx_drop_l3_bcast), 50 NICVF_HW_STAT(rx_drop_l3_bcast),
51 NICVF_HW_STAT(rx_drop_l3_mcast), 51 NICVF_HW_STAT(rx_drop_l3_mcast),
52 NICVF_HW_STAT(rx_bgx_truncated_pkts), 52 NICVF_HW_STAT(rx_fcs_errors),
53 NICVF_HW_STAT(rx_jabber_errs), 53 NICVF_HW_STAT(rx_l2_errors),
54 NICVF_HW_STAT(rx_fcs_errs), 54 NICVF_HW_STAT(tx_bytes),
55 NICVF_HW_STAT(rx_bgx_errs), 55 NICVF_HW_STAT(tx_frames),
56 NICVF_HW_STAT(rx_prel2_errs), 56 NICVF_HW_STAT(tx_ucast_frames),
57 NICVF_HW_STAT(rx_l2_hdr_malformed), 57 NICVF_HW_STAT(tx_bcast_frames),
58 NICVF_HW_STAT(rx_oversize), 58 NICVF_HW_STAT(tx_mcast_frames),
59 NICVF_HW_STAT(rx_undersize), 59 NICVF_HW_STAT(tx_drops),
60 NICVF_HW_STAT(rx_l2_len_mismatch),
61 NICVF_HW_STAT(rx_l2_pclp),
62 NICVF_HW_STAT(rx_ip_ver_errs),
63 NICVF_HW_STAT(rx_ip_csum_errs),
64 NICVF_HW_STAT(rx_ip_hdr_malformed),
65 NICVF_HW_STAT(rx_ip_payload_malformed),
66 NICVF_HW_STAT(rx_ip_ttl_errs),
67 NICVF_HW_STAT(rx_l3_pclp),
68 NICVF_HW_STAT(rx_l4_malformed),
69 NICVF_HW_STAT(rx_l4_csum_errs),
70 NICVF_HW_STAT(rx_udp_len_errs),
71 NICVF_HW_STAT(rx_l4_port_errs),
72 NICVF_HW_STAT(rx_tcp_flag_errs),
73 NICVF_HW_STAT(rx_tcp_offset_errs),
74 NICVF_HW_STAT(rx_l4_pclp),
75 NICVF_HW_STAT(rx_truncated_pkts),
76 NICVF_HW_STAT(tx_bytes_ok),
77 NICVF_HW_STAT(tx_ucast_frames_ok),
78 NICVF_HW_STAT(tx_bcast_frames_ok),
79 NICVF_HW_STAT(tx_mcast_frames_ok),
80}; 60};
81 61
82static const struct nicvf_stat nicvf_drv_stats[] = { 62static const struct nicvf_stat nicvf_drv_stats[] = {
83 NICVF_DRV_STAT(rx_frames_ok), 63 NICVF_DRV_STAT(rx_bgx_truncated_pkts),
84 NICVF_DRV_STAT(rx_frames_64), 64 NICVF_DRV_STAT(rx_jabber_errs),
85 NICVF_DRV_STAT(rx_frames_127), 65 NICVF_DRV_STAT(rx_fcs_errs),
86 NICVF_DRV_STAT(rx_frames_255), 66 NICVF_DRV_STAT(rx_bgx_errs),
87 NICVF_DRV_STAT(rx_frames_511), 67 NICVF_DRV_STAT(rx_prel2_errs),
88 NICVF_DRV_STAT(rx_frames_1023), 68 NICVF_DRV_STAT(rx_l2_hdr_malformed),
89 NICVF_DRV_STAT(rx_frames_1518), 69 NICVF_DRV_STAT(rx_oversize),
90 NICVF_DRV_STAT(rx_frames_jumbo), 70 NICVF_DRV_STAT(rx_undersize),
91 NICVF_DRV_STAT(rx_drops), 71 NICVF_DRV_STAT(rx_l2_len_mismatch),
72 NICVF_DRV_STAT(rx_l2_pclp),
73 NICVF_DRV_STAT(rx_ip_ver_errs),
74 NICVF_DRV_STAT(rx_ip_csum_errs),
75 NICVF_DRV_STAT(rx_ip_hdr_malformed),
76 NICVF_DRV_STAT(rx_ip_payload_malformed),
77 NICVF_DRV_STAT(rx_ip_ttl_errs),
78 NICVF_DRV_STAT(rx_l3_pclp),
79 NICVF_DRV_STAT(rx_l4_malformed),
80 NICVF_DRV_STAT(rx_l4_csum_errs),
81 NICVF_DRV_STAT(rx_udp_len_errs),
82 NICVF_DRV_STAT(rx_l4_port_errs),
83 NICVF_DRV_STAT(rx_tcp_flag_errs),
84 NICVF_DRV_STAT(rx_tcp_offset_errs),
85 NICVF_DRV_STAT(rx_l4_pclp),
86 NICVF_DRV_STAT(rx_truncated_pkts),
87
88 NICVF_DRV_STAT(tx_desc_fault),
89 NICVF_DRV_STAT(tx_hdr_cons_err),
90 NICVF_DRV_STAT(tx_subdesc_err),
91 NICVF_DRV_STAT(tx_max_size_exceeded),
92 NICVF_DRV_STAT(tx_imm_size_oflow),
93 NICVF_DRV_STAT(tx_data_seq_err),
94 NICVF_DRV_STAT(tx_mem_seq_err),
95 NICVF_DRV_STAT(tx_lock_viol),
96 NICVF_DRV_STAT(tx_data_fault),
97 NICVF_DRV_STAT(tx_tstmp_conflict),
98 NICVF_DRV_STAT(tx_tstmp_timeout),
99 NICVF_DRV_STAT(tx_mem_fault),
100 NICVF_DRV_STAT(tx_csum_overlap),
101 NICVF_DRV_STAT(tx_csum_overflow),
102
92 NICVF_DRV_STAT(rcv_buffer_alloc_failures), 103 NICVF_DRV_STAT(rcv_buffer_alloc_failures),
93 NICVF_DRV_STAT(tx_frames_ok),
94 NICVF_DRV_STAT(tx_tso), 104 NICVF_DRV_STAT(tx_tso),
95 NICVF_DRV_STAT(tx_drops),
96 NICVF_DRV_STAT(tx_timeout), 105 NICVF_DRV_STAT(tx_timeout),
97 NICVF_DRV_STAT(txq_stop), 106 NICVF_DRV_STAT(txq_stop),
98 NICVF_DRV_STAT(txq_wake), 107 NICVF_DRV_STAT(txq_wake),
@@ -278,8 +287,8 @@ static void nicvf_get_ethtool_stats(struct net_device *netdev,
278 struct ethtool_stats *stats, u64 *data) 287 struct ethtool_stats *stats, u64 *data)
279{ 288{
280 struct nicvf *nic = netdev_priv(netdev); 289 struct nicvf *nic = netdev_priv(netdev);
281 int stat; 290 int stat, tmp_stats;
282 int sqs; 291 int sqs, cpu;
283 292
284 nicvf_update_stats(nic); 293 nicvf_update_stats(nic);
285 294
@@ -289,9 +298,13 @@ static void nicvf_get_ethtool_stats(struct net_device *netdev,
289 for (stat = 0; stat < nicvf_n_hw_stats; stat++) 298 for (stat = 0; stat < nicvf_n_hw_stats; stat++)
290 *(data++) = ((u64 *)&nic->hw_stats) 299 *(data++) = ((u64 *)&nic->hw_stats)
291 [nicvf_hw_stats[stat].index]; 300 [nicvf_hw_stats[stat].index];
292 for (stat = 0; stat < nicvf_n_drv_stats; stat++) 301 for (stat = 0; stat < nicvf_n_drv_stats; stat++) {
293 *(data++) = ((u64 *)&nic->drv_stats) 302 tmp_stats = 0;
294 [nicvf_drv_stats[stat].index]; 303 for_each_possible_cpu(cpu)
304 tmp_stats += ((u64 *)per_cpu_ptr(nic->drv_stats, cpu))
305 [nicvf_drv_stats[stat].index];
306 *(data++) = tmp_stats;
307 }
295 308
296 nicvf_get_qset_stats(nic, stats, &data); 309 nicvf_get_qset_stats(nic, stats, &data);
297 310
diff --git a/drivers/net/ethernet/cavium/thunder/nicvf_main.c b/drivers/net/ethernet/cavium/thunder/nicvf_main.c
index 45a13f718863..8a37012c9c89 100644
--- a/drivers/net/ethernet/cavium/thunder/nicvf_main.c
+++ b/drivers/net/ethernet/cavium/thunder/nicvf_main.c
@@ -69,25 +69,6 @@ static inline u8 nicvf_netdev_qidx(struct nicvf *nic, u8 qidx)
69 return qidx; 69 return qidx;
70} 70}
71 71
72static inline void nicvf_set_rx_frame_cnt(struct nicvf *nic,
73 struct sk_buff *skb)
74{
75 if (skb->len <= 64)
76 nic->drv_stats.rx_frames_64++;
77 else if (skb->len <= 127)
78 nic->drv_stats.rx_frames_127++;
79 else if (skb->len <= 255)
80 nic->drv_stats.rx_frames_255++;
81 else if (skb->len <= 511)
82 nic->drv_stats.rx_frames_511++;
83 else if (skb->len <= 1023)
84 nic->drv_stats.rx_frames_1023++;
85 else if (skb->len <= 1518)
86 nic->drv_stats.rx_frames_1518++;
87 else
88 nic->drv_stats.rx_frames_jumbo++;
89}
90
91/* The Cavium ThunderX network controller can *only* be found in SoCs 72/* The Cavium ThunderX network controller can *only* be found in SoCs
92 * containing the ThunderX ARM64 CPU implementation. All accesses to the device 73 * containing the ThunderX ARM64 CPU implementation. All accesses to the device
93 * registers on this platform are implicitly strongly ordered with respect 74 * registers on this platform are implicitly strongly ordered with respect
@@ -492,9 +473,6 @@ int nicvf_set_real_num_queues(struct net_device *netdev,
492static int nicvf_init_resources(struct nicvf *nic) 473static int nicvf_init_resources(struct nicvf *nic)
493{ 474{
494 int err; 475 int err;
495 union nic_mbx mbx = {};
496
497 mbx.msg.msg = NIC_MBOX_MSG_CFG_DONE;
498 476
499 /* Enable Qset */ 477 /* Enable Qset */
500 nicvf_qset_config(nic, true); 478 nicvf_qset_config(nic, true);
@@ -507,14 +485,10 @@ static int nicvf_init_resources(struct nicvf *nic)
507 return err; 485 return err;
508 } 486 }
509 487
510 /* Send VF config done msg to PF */
511 nicvf_write_to_mbx(nic, &mbx);
512
513 return 0; 488 return 0;
514} 489}
515 490
516static void nicvf_snd_pkt_handler(struct net_device *netdev, 491static void nicvf_snd_pkt_handler(struct net_device *netdev,
517 struct cmp_queue *cq,
518 struct cqe_send_t *cqe_tx, 492 struct cqe_send_t *cqe_tx,
519 int cqe_type, int budget, 493 int cqe_type, int budget,
520 unsigned int *tx_pkts, unsigned int *tx_bytes) 494 unsigned int *tx_pkts, unsigned int *tx_bytes)
@@ -536,7 +510,7 @@ static void nicvf_snd_pkt_handler(struct net_device *netdev,
536 __func__, cqe_tx->sq_qs, cqe_tx->sq_idx, 510 __func__, cqe_tx->sq_qs, cqe_tx->sq_idx,
537 cqe_tx->sqe_ptr, hdr->subdesc_cnt); 511 cqe_tx->sqe_ptr, hdr->subdesc_cnt);
538 512
539 nicvf_check_cqe_tx_errs(nic, cq, cqe_tx); 513 nicvf_check_cqe_tx_errs(nic, cqe_tx);
540 skb = (struct sk_buff *)sq->skbuff[cqe_tx->sqe_ptr]; 514 skb = (struct sk_buff *)sq->skbuff[cqe_tx->sqe_ptr];
541 if (skb) { 515 if (skb) {
542 /* Check for dummy descriptor used for HW TSO offload on 88xx */ 516 /* Check for dummy descriptor used for HW TSO offload on 88xx */
@@ -630,8 +604,6 @@ static void nicvf_rcv_pkt_handler(struct net_device *netdev,
630 return; 604 return;
631 } 605 }
632 606
633 nicvf_set_rx_frame_cnt(nic, skb);
634
635 nicvf_set_rxhash(netdev, cqe_rx, skb); 607 nicvf_set_rxhash(netdev, cqe_rx, skb);
636 608
637 skb_record_rx_queue(skb, rq_idx); 609 skb_record_rx_queue(skb, rq_idx);
@@ -703,7 +675,7 @@ loop:
703 work_done++; 675 work_done++;
704 break; 676 break;
705 case CQE_TYPE_SEND: 677 case CQE_TYPE_SEND:
706 nicvf_snd_pkt_handler(netdev, cq, 678 nicvf_snd_pkt_handler(netdev,
707 (void *)cq_desc, CQE_TYPE_SEND, 679 (void *)cq_desc, CQE_TYPE_SEND,
708 budget, &tx_pkts, &tx_bytes); 680 budget, &tx_pkts, &tx_bytes);
709 tx_done++; 681 tx_done++;
@@ -740,7 +712,7 @@ done:
740 nic = nic->pnicvf; 712 nic = nic->pnicvf;
741 if (netif_tx_queue_stopped(txq) && netif_carrier_ok(netdev)) { 713 if (netif_tx_queue_stopped(txq) && netif_carrier_ok(netdev)) {
742 netif_tx_start_queue(txq); 714 netif_tx_start_queue(txq);
743 nic->drv_stats.txq_wake++; 715 this_cpu_inc(nic->drv_stats->txq_wake);
744 if (netif_msg_tx_err(nic)) 716 if (netif_msg_tx_err(nic))
745 netdev_warn(netdev, 717 netdev_warn(netdev,
746 "%s: Transmit queue wakeup SQ%d\n", 718 "%s: Transmit queue wakeup SQ%d\n",
@@ -1084,7 +1056,7 @@ static netdev_tx_t nicvf_xmit(struct sk_buff *skb, struct net_device *netdev)
1084 1056
1085 if (!netif_tx_queue_stopped(txq) && !nicvf_sq_append_skb(nic, skb)) { 1057 if (!netif_tx_queue_stopped(txq) && !nicvf_sq_append_skb(nic, skb)) {
1086 netif_tx_stop_queue(txq); 1058 netif_tx_stop_queue(txq);
1087 nic->drv_stats.txq_stop++; 1059 this_cpu_inc(nic->drv_stats->txq_stop);
1088 if (netif_msg_tx_err(nic)) 1060 if (netif_msg_tx_err(nic))
1089 netdev_warn(netdev, 1061 netdev_warn(netdev,
1090 "%s: Transmit ring full, stopping SQ%d\n", 1062 "%s: Transmit ring full, stopping SQ%d\n",
@@ -1189,14 +1161,24 @@ int nicvf_stop(struct net_device *netdev)
1189 return 0; 1161 return 0;
1190} 1162}
1191 1163
1164static int nicvf_update_hw_max_frs(struct nicvf *nic, int mtu)
1165{
1166 union nic_mbx mbx = {};
1167
1168 mbx.frs.msg = NIC_MBOX_MSG_SET_MAX_FRS;
1169 mbx.frs.max_frs = mtu;
1170 mbx.frs.vf_id = nic->vf_id;
1171
1172 return nicvf_send_msg_to_pf(nic, &mbx);
1173}
1174
1192int nicvf_open(struct net_device *netdev) 1175int nicvf_open(struct net_device *netdev)
1193{ 1176{
1194 int err, qidx; 1177 int cpu, err, qidx;
1195 struct nicvf *nic = netdev_priv(netdev); 1178 struct nicvf *nic = netdev_priv(netdev);
1196 struct queue_set *qs = nic->qs; 1179 struct queue_set *qs = nic->qs;
1197 struct nicvf_cq_poll *cq_poll = NULL; 1180 struct nicvf_cq_poll *cq_poll = NULL;
1198 1181 union nic_mbx mbx = {};
1199 nic->mtu = netdev->mtu;
1200 1182
1201 netif_carrier_off(netdev); 1183 netif_carrier_off(netdev);
1202 1184
@@ -1248,9 +1230,17 @@ int nicvf_open(struct net_device *netdev)
1248 if (nic->sqs_mode) 1230 if (nic->sqs_mode)
1249 nicvf_get_primary_vf_struct(nic); 1231 nicvf_get_primary_vf_struct(nic);
1250 1232
1251 /* Configure receive side scaling */ 1233 /* Configure receive side scaling and MTU */
1252 if (!nic->sqs_mode) 1234 if (!nic->sqs_mode) {
1253 nicvf_rss_init(nic); 1235 nicvf_rss_init(nic);
1236 if (nicvf_update_hw_max_frs(nic, netdev->mtu))
1237 goto cleanup;
1238
1239 /* Clear percpu stats */
1240 for_each_possible_cpu(cpu)
1241 memset(per_cpu_ptr(nic->drv_stats, cpu), 0,
1242 sizeof(struct nicvf_drv_stats));
1243 }
1254 1244
1255 err = nicvf_register_interrupts(nic); 1245 err = nicvf_register_interrupts(nic);
1256 if (err) 1246 if (err)
@@ -1276,8 +1266,9 @@ int nicvf_open(struct net_device *netdev)
1276 for (qidx = 0; qidx < qs->rbdr_cnt; qidx++) 1266 for (qidx = 0; qidx < qs->rbdr_cnt; qidx++)
1277 nicvf_enable_intr(nic, NICVF_INTR_RBDR, qidx); 1267 nicvf_enable_intr(nic, NICVF_INTR_RBDR, qidx);
1278 1268
1279 nic->drv_stats.txq_stop = 0; 1269 /* Send VF config done msg to PF */
1280 nic->drv_stats.txq_wake = 0; 1270 mbx.msg.msg = NIC_MBOX_MSG_CFG_DONE;
1271 nicvf_write_to_mbx(nic, &mbx);
1281 1272
1282 return 0; 1273 return 0;
1283cleanup: 1274cleanup:
@@ -1297,17 +1288,6 @@ napi_del:
1297 return err; 1288 return err;
1298} 1289}
1299 1290
1300static int nicvf_update_hw_max_frs(struct nicvf *nic, int mtu)
1301{
1302 union nic_mbx mbx = {};
1303
1304 mbx.frs.msg = NIC_MBOX_MSG_SET_MAX_FRS;
1305 mbx.frs.max_frs = mtu;
1306 mbx.frs.vf_id = nic->vf_id;
1307
1308 return nicvf_send_msg_to_pf(nic, &mbx);
1309}
1310
1311static int nicvf_change_mtu(struct net_device *netdev, int new_mtu) 1291static int nicvf_change_mtu(struct net_device *netdev, int new_mtu)
1312{ 1292{
1313 struct nicvf *nic = netdev_priv(netdev); 1293 struct nicvf *nic = netdev_priv(netdev);
@@ -1318,10 +1298,13 @@ static int nicvf_change_mtu(struct net_device *netdev, int new_mtu)
1318 if (new_mtu < NIC_HW_MIN_FRS) 1298 if (new_mtu < NIC_HW_MIN_FRS)
1319 return -EINVAL; 1299 return -EINVAL;
1320 1300
1301 netdev->mtu = new_mtu;
1302
1303 if (!netif_running(netdev))
1304 return 0;
1305
1321 if (nicvf_update_hw_max_frs(nic, new_mtu)) 1306 if (nicvf_update_hw_max_frs(nic, new_mtu))
1322 return -EINVAL; 1307 return -EINVAL;
1323 netdev->mtu = new_mtu;
1324 nic->mtu = new_mtu;
1325 1308
1326 return 0; 1309 return 0;
1327} 1310}
@@ -1379,9 +1362,10 @@ void nicvf_update_lmac_stats(struct nicvf *nic)
1379 1362
1380void nicvf_update_stats(struct nicvf *nic) 1363void nicvf_update_stats(struct nicvf *nic)
1381{ 1364{
1382 int qidx; 1365 int qidx, cpu;
1366 u64 tmp_stats = 0;
1383 struct nicvf_hw_stats *stats = &nic->hw_stats; 1367 struct nicvf_hw_stats *stats = &nic->hw_stats;
1384 struct nicvf_drv_stats *drv_stats = &nic->drv_stats; 1368 struct nicvf_drv_stats *drv_stats;
1385 struct queue_set *qs = nic->qs; 1369 struct queue_set *qs = nic->qs;
1386 1370
1387#define GET_RX_STATS(reg) \ 1371#define GET_RX_STATS(reg) \
@@ -1404,21 +1388,33 @@ void nicvf_update_stats(struct nicvf *nic)
1404 stats->rx_drop_l3_bcast = GET_RX_STATS(RX_DRP_L3BCAST); 1388 stats->rx_drop_l3_bcast = GET_RX_STATS(RX_DRP_L3BCAST);
1405 stats->rx_drop_l3_mcast = GET_RX_STATS(RX_DRP_L3MCAST); 1389 stats->rx_drop_l3_mcast = GET_RX_STATS(RX_DRP_L3MCAST);
1406 1390
1407 stats->tx_bytes_ok = GET_TX_STATS(TX_OCTS); 1391 stats->tx_bytes = GET_TX_STATS(TX_OCTS);
1408 stats->tx_ucast_frames_ok = GET_TX_STATS(TX_UCAST); 1392 stats->tx_ucast_frames = GET_TX_STATS(TX_UCAST);
1409 stats->tx_bcast_frames_ok = GET_TX_STATS(TX_BCAST); 1393 stats->tx_bcast_frames = GET_TX_STATS(TX_BCAST);
1410 stats->tx_mcast_frames_ok = GET_TX_STATS(TX_MCAST); 1394 stats->tx_mcast_frames = GET_TX_STATS(TX_MCAST);
1411 stats->tx_drops = GET_TX_STATS(TX_DROP); 1395 stats->tx_drops = GET_TX_STATS(TX_DROP);
1412 1396
1413 drv_stats->tx_frames_ok = stats->tx_ucast_frames_ok + 1397 /* On T88 pass 2.0, the dummy SQE added for TSO notification
1414 stats->tx_bcast_frames_ok + 1398 * via CQE has 'dont_send' set. Hence HW drops the pkt pointed
1415 stats->tx_mcast_frames_ok; 1399 * pointed by dummy SQE and results in tx_drops counter being
1416 drv_stats->rx_frames_ok = stats->rx_ucast_frames + 1400 * incremented. Subtracting it from tx_tso counter will give
1417 stats->rx_bcast_frames + 1401 * exact tx_drops counter.
1418 stats->rx_mcast_frames; 1402 */
1419 drv_stats->rx_drops = stats->rx_drop_red + 1403 if (nic->t88 && nic->hw_tso) {
1420 stats->rx_drop_overrun; 1404 for_each_possible_cpu(cpu) {
1421 drv_stats->tx_drops = stats->tx_drops; 1405 drv_stats = per_cpu_ptr(nic->drv_stats, cpu);
1406 tmp_stats += drv_stats->tx_tso;
1407 }
1408 stats->tx_drops = tmp_stats - stats->tx_drops;
1409 }
1410 stats->tx_frames = stats->tx_ucast_frames +
1411 stats->tx_bcast_frames +
1412 stats->tx_mcast_frames;
1413 stats->rx_frames = stats->rx_ucast_frames +
1414 stats->rx_bcast_frames +
1415 stats->rx_mcast_frames;
1416 stats->rx_drops = stats->rx_drop_red +
1417 stats->rx_drop_overrun;
1422 1418
1423 /* Update RQ and SQ stats */ 1419 /* Update RQ and SQ stats */
1424 for (qidx = 0; qidx < qs->rq_cnt; qidx++) 1420 for (qidx = 0; qidx < qs->rq_cnt; qidx++)
@@ -1432,18 +1428,17 @@ static struct rtnl_link_stats64 *nicvf_get_stats64(struct net_device *netdev,
1432{ 1428{
1433 struct nicvf *nic = netdev_priv(netdev); 1429 struct nicvf *nic = netdev_priv(netdev);
1434 struct nicvf_hw_stats *hw_stats = &nic->hw_stats; 1430 struct nicvf_hw_stats *hw_stats = &nic->hw_stats;
1435 struct nicvf_drv_stats *drv_stats = &nic->drv_stats;
1436 1431
1437 nicvf_update_stats(nic); 1432 nicvf_update_stats(nic);
1438 1433
1439 stats->rx_bytes = hw_stats->rx_bytes; 1434 stats->rx_bytes = hw_stats->rx_bytes;
1440 stats->rx_packets = drv_stats->rx_frames_ok; 1435 stats->rx_packets = hw_stats->rx_frames;
1441 stats->rx_dropped = drv_stats->rx_drops; 1436 stats->rx_dropped = hw_stats->rx_drops;
1442 stats->multicast = hw_stats->rx_mcast_frames; 1437 stats->multicast = hw_stats->rx_mcast_frames;
1443 1438
1444 stats->tx_bytes = hw_stats->tx_bytes_ok; 1439 stats->tx_bytes = hw_stats->tx_bytes;
1445 stats->tx_packets = drv_stats->tx_frames_ok; 1440 stats->tx_packets = hw_stats->tx_frames;
1446 stats->tx_dropped = drv_stats->tx_drops; 1441 stats->tx_dropped = hw_stats->tx_drops;
1447 1442
1448 return stats; 1443 return stats;
1449} 1444}
@@ -1456,7 +1451,7 @@ static void nicvf_tx_timeout(struct net_device *dev)
1456 netdev_warn(dev, "%s: Transmit timed out, resetting\n", 1451 netdev_warn(dev, "%s: Transmit timed out, resetting\n",
1457 dev->name); 1452 dev->name);
1458 1453
1459 nic->drv_stats.tx_timeout++; 1454 this_cpu_inc(nic->drv_stats->tx_timeout);
1460 schedule_work(&nic->reset_task); 1455 schedule_work(&nic->reset_task);
1461} 1456}
1462 1457
@@ -1590,6 +1585,12 @@ static int nicvf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1590 goto err_free_netdev; 1585 goto err_free_netdev;
1591 } 1586 }
1592 1587
1588 nic->drv_stats = netdev_alloc_pcpu_stats(struct nicvf_drv_stats);
1589 if (!nic->drv_stats) {
1590 err = -ENOMEM;
1591 goto err_free_netdev;
1592 }
1593
1593 err = nicvf_set_qset_resources(nic); 1594 err = nicvf_set_qset_resources(nic);
1594 if (err) 1595 if (err)
1595 goto err_free_netdev; 1596 goto err_free_netdev;
@@ -1648,6 +1649,8 @@ err_unregister_interrupts:
1648 nicvf_unregister_interrupts(nic); 1649 nicvf_unregister_interrupts(nic);
1649err_free_netdev: 1650err_free_netdev:
1650 pci_set_drvdata(pdev, NULL); 1651 pci_set_drvdata(pdev, NULL);
1652 if (nic->drv_stats)
1653 free_percpu(nic->drv_stats);
1651 free_netdev(netdev); 1654 free_netdev(netdev);
1652err_release_regions: 1655err_release_regions:
1653 pci_release_regions(pdev); 1656 pci_release_regions(pdev);
@@ -1675,6 +1678,8 @@ static void nicvf_remove(struct pci_dev *pdev)
1675 unregister_netdev(pnetdev); 1678 unregister_netdev(pnetdev);
1676 nicvf_unregister_interrupts(nic); 1679 nicvf_unregister_interrupts(nic);
1677 pci_set_drvdata(pdev, NULL); 1680 pci_set_drvdata(pdev, NULL);
1681 if (nic->drv_stats)
1682 free_percpu(nic->drv_stats);
1678 free_netdev(netdev); 1683 free_netdev(netdev);
1679 pci_release_regions(pdev); 1684 pci_release_regions(pdev);
1680 pci_disable_device(pdev); 1685 pci_disable_device(pdev);
diff --git a/drivers/net/ethernet/cavium/thunder/nicvf_queues.c b/drivers/net/ethernet/cavium/thunder/nicvf_queues.c
index a4fc50155881..747ef0882976 100644
--- a/drivers/net/ethernet/cavium/thunder/nicvf_queues.c
+++ b/drivers/net/ethernet/cavium/thunder/nicvf_queues.c
@@ -104,7 +104,8 @@ static inline int nicvf_alloc_rcv_buffer(struct nicvf *nic, gfp_t gfp,
104 nic->rb_page = alloc_pages(gfp | __GFP_COMP | __GFP_NOWARN, 104 nic->rb_page = alloc_pages(gfp | __GFP_COMP | __GFP_NOWARN,
105 order); 105 order);
106 if (!nic->rb_page) { 106 if (!nic->rb_page) {
107 nic->drv_stats.rcv_buffer_alloc_failures++; 107 this_cpu_inc(nic->pnicvf->drv_stats->
108 rcv_buffer_alloc_failures);
108 return -ENOMEM; 109 return -ENOMEM;
109 } 110 }
110 nic->rb_page_offset = 0; 111 nic->rb_page_offset = 0;
@@ -270,7 +271,8 @@ refill:
270 rbdr_idx, new_rb); 271 rbdr_idx, new_rb);
271next_rbdr: 272next_rbdr:
272 /* Re-enable RBDR interrupts only if buffer allocation is success */ 273 /* Re-enable RBDR interrupts only if buffer allocation is success */
273 if (!nic->rb_alloc_fail && rbdr->enable) 274 if (!nic->rb_alloc_fail && rbdr->enable &&
275 netif_running(nic->pnicvf->netdev))
274 nicvf_enable_intr(nic, NICVF_INTR_RBDR, rbdr_idx); 276 nicvf_enable_intr(nic, NICVF_INTR_RBDR, rbdr_idx);
275 277
276 if (rbdr_idx) 278 if (rbdr_idx)
@@ -361,6 +363,8 @@ static int nicvf_init_snd_queue(struct nicvf *nic,
361 363
362static void nicvf_free_snd_queue(struct nicvf *nic, struct snd_queue *sq) 364static void nicvf_free_snd_queue(struct nicvf *nic, struct snd_queue *sq)
363{ 365{
366 struct sk_buff *skb;
367
364 if (!sq) 368 if (!sq)
365 return; 369 return;
366 if (!sq->dmem.base) 370 if (!sq->dmem.base)
@@ -371,6 +375,15 @@ static void nicvf_free_snd_queue(struct nicvf *nic, struct snd_queue *sq)
371 sq->dmem.q_len * TSO_HEADER_SIZE, 375 sq->dmem.q_len * TSO_HEADER_SIZE,
372 sq->tso_hdrs, sq->tso_hdrs_phys); 376 sq->tso_hdrs, sq->tso_hdrs_phys);
373 377
378 /* Free pending skbs in the queue */
379 smp_rmb();
380 while (sq->head != sq->tail) {
381 skb = (struct sk_buff *)sq->skbuff[sq->head];
382 if (skb)
383 dev_kfree_skb_any(skb);
384 sq->head++;
385 sq->head &= (sq->dmem.q_len - 1);
386 }
374 kfree(sq->skbuff); 387 kfree(sq->skbuff);
375 nicvf_free_q_desc_mem(nic, &sq->dmem); 388 nicvf_free_q_desc_mem(nic, &sq->dmem);
376} 389}
@@ -483,9 +496,12 @@ static void nicvf_reset_rcv_queue_stats(struct nicvf *nic)
483{ 496{
484 union nic_mbx mbx = {}; 497 union nic_mbx mbx = {};
485 498
486 /* Reset all RXQ's stats */ 499 /* Reset all RQ/SQ and VF stats */
487 mbx.reset_stat.msg = NIC_MBOX_MSG_RESET_STAT_COUNTER; 500 mbx.reset_stat.msg = NIC_MBOX_MSG_RESET_STAT_COUNTER;
501 mbx.reset_stat.rx_stat_mask = 0x3FFF;
502 mbx.reset_stat.tx_stat_mask = 0x1F;
488 mbx.reset_stat.rq_stat_mask = 0xFFFF; 503 mbx.reset_stat.rq_stat_mask = 0xFFFF;
504 mbx.reset_stat.sq_stat_mask = 0xFFFF;
489 nicvf_send_msg_to_pf(nic, &mbx); 505 nicvf_send_msg_to_pf(nic, &mbx);
490} 506}
491 507
@@ -538,9 +554,12 @@ static void nicvf_rcv_queue_config(struct nicvf *nic, struct queue_set *qs,
538 mbx.rq.cfg = (1ULL << 62) | (RQ_CQ_DROP << 8); 554 mbx.rq.cfg = (1ULL << 62) | (RQ_CQ_DROP << 8);
539 nicvf_send_msg_to_pf(nic, &mbx); 555 nicvf_send_msg_to_pf(nic, &mbx);
540 556
541 nicvf_queue_reg_write(nic, NIC_QSET_RQ_GEN_CFG, 0, 0x00); 557 if (!nic->sqs_mode && (qidx == 0)) {
542 if (!nic->sqs_mode) 558 /* Enable checking L3/L4 length and TCP/UDP checksums */
559 nicvf_queue_reg_write(nic, NIC_QSET_RQ_GEN_CFG, 0,
560 (BIT(24) | BIT(23) | BIT(21)));
543 nicvf_config_vlan_stripping(nic, nic->netdev->features); 561 nicvf_config_vlan_stripping(nic, nic->netdev->features);
562 }
544 563
545 /* Enable Receive queue */ 564 /* Enable Receive queue */
546 memset(&rq_cfg, 0, sizeof(struct rq_cfg)); 565 memset(&rq_cfg, 0, sizeof(struct rq_cfg));
@@ -1029,7 +1048,7 @@ nicvf_sq_add_hdr_subdesc(struct nicvf *nic, struct snd_queue *sq, int qentry,
1029 hdr->tso_max_paysize = skb_shinfo(skb)->gso_size; 1048 hdr->tso_max_paysize = skb_shinfo(skb)->gso_size;
1030 /* For non-tunneled pkts, point this to L2 ethertype */ 1049 /* For non-tunneled pkts, point this to L2 ethertype */
1031 hdr->inner_l3_offset = skb_network_offset(skb) - 2; 1050 hdr->inner_l3_offset = skb_network_offset(skb) - 2;
1032 nic->drv_stats.tx_tso++; 1051 this_cpu_inc(nic->pnicvf->drv_stats->tx_tso);
1033 } 1052 }
1034} 1053}
1035 1054
@@ -1161,7 +1180,7 @@ static int nicvf_sq_append_tso(struct nicvf *nic, struct snd_queue *sq,
1161 1180
1162 nicvf_sq_doorbell(nic, skb, sq_num, desc_cnt); 1181 nicvf_sq_doorbell(nic, skb, sq_num, desc_cnt);
1163 1182
1164 nic->drv_stats.tx_tso++; 1183 this_cpu_inc(nic->pnicvf->drv_stats->tx_tso);
1165 return 1; 1184 return 1;
1166} 1185}
1167 1186
@@ -1422,8 +1441,6 @@ void nicvf_update_sq_stats(struct nicvf *nic, int sq_idx)
1422/* Check for errors in the receive cmp.queue entry */ 1441/* Check for errors in the receive cmp.queue entry */
1423int nicvf_check_cqe_rx_errs(struct nicvf *nic, struct cqe_rx_t *cqe_rx) 1442int nicvf_check_cqe_rx_errs(struct nicvf *nic, struct cqe_rx_t *cqe_rx)
1424{ 1443{
1425 struct nicvf_hw_stats *stats = &nic->hw_stats;
1426
1427 if (!cqe_rx->err_level && !cqe_rx->err_opcode) 1444 if (!cqe_rx->err_level && !cqe_rx->err_opcode)
1428 return 0; 1445 return 0;
1429 1446
@@ -1435,76 +1452,76 @@ int nicvf_check_cqe_rx_errs(struct nicvf *nic, struct cqe_rx_t *cqe_rx)
1435 1452
1436 switch (cqe_rx->err_opcode) { 1453 switch (cqe_rx->err_opcode) {
1437 case CQ_RX_ERROP_RE_PARTIAL: 1454 case CQ_RX_ERROP_RE_PARTIAL:
1438 stats->rx_bgx_truncated_pkts++; 1455 this_cpu_inc(nic->drv_stats->rx_bgx_truncated_pkts);
1439 break; 1456 break;
1440 case CQ_RX_ERROP_RE_JABBER: 1457 case CQ_RX_ERROP_RE_JABBER:
1441 stats->rx_jabber_errs++; 1458 this_cpu_inc(nic->drv_stats->rx_jabber_errs);
1442 break; 1459 break;
1443 case CQ_RX_ERROP_RE_FCS: 1460 case CQ_RX_ERROP_RE_FCS:
1444 stats->rx_fcs_errs++; 1461 this_cpu_inc(nic->drv_stats->rx_fcs_errs);
1445 break; 1462 break;
1446 case CQ_RX_ERROP_RE_RX_CTL: 1463 case CQ_RX_ERROP_RE_RX_CTL:
1447 stats->rx_bgx_errs++; 1464 this_cpu_inc(nic->drv_stats->rx_bgx_errs);
1448 break; 1465 break;
1449 case CQ_RX_ERROP_PREL2_ERR: 1466 case CQ_RX_ERROP_PREL2_ERR:
1450 stats->rx_prel2_errs++; 1467 this_cpu_inc(nic->drv_stats->rx_prel2_errs);
1451 break; 1468 break;
1452 case CQ_RX_ERROP_L2_MAL: 1469 case CQ_RX_ERROP_L2_MAL:
1453 stats->rx_l2_hdr_malformed++; 1470 this_cpu_inc(nic->drv_stats->rx_l2_hdr_malformed);
1454 break; 1471 break;
1455 case CQ_RX_ERROP_L2_OVERSIZE: 1472 case CQ_RX_ERROP_L2_OVERSIZE:
1456 stats->rx_oversize++; 1473 this_cpu_inc(nic->drv_stats->rx_oversize);
1457 break; 1474 break;
1458 case CQ_RX_ERROP_L2_UNDERSIZE: 1475 case CQ_RX_ERROP_L2_UNDERSIZE:
1459 stats->rx_undersize++; 1476 this_cpu_inc(nic->drv_stats->rx_undersize);
1460 break; 1477 break;
1461 case CQ_RX_ERROP_L2_LENMISM: 1478 case CQ_RX_ERROP_L2_LENMISM:
1462 stats->rx_l2_len_mismatch++; 1479 this_cpu_inc(nic->drv_stats->rx_l2_len_mismatch);
1463 break; 1480 break;
1464 case CQ_RX_ERROP_L2_PCLP: 1481 case CQ_RX_ERROP_L2_PCLP:
1465 stats->rx_l2_pclp++; 1482 this_cpu_inc(nic->drv_stats->rx_l2_pclp);
1466 break; 1483 break;
1467 case CQ_RX_ERROP_IP_NOT: 1484 case CQ_RX_ERROP_IP_NOT:
1468 stats->rx_ip_ver_errs++; 1485 this_cpu_inc(nic->drv_stats->rx_ip_ver_errs);
1469 break; 1486 break;
1470 case CQ_RX_ERROP_IP_CSUM_ERR: 1487 case CQ_RX_ERROP_IP_CSUM_ERR:
1471 stats->rx_ip_csum_errs++; 1488 this_cpu_inc(nic->drv_stats->rx_ip_csum_errs);
1472 break; 1489 break;
1473 case CQ_RX_ERROP_IP_MAL: 1490 case CQ_RX_ERROP_IP_MAL:
1474 stats->rx_ip_hdr_malformed++; 1491 this_cpu_inc(nic->drv_stats->rx_ip_hdr_malformed);
1475 break; 1492 break;
1476 case CQ_RX_ERROP_IP_MALD: 1493 case CQ_RX_ERROP_IP_MALD:
1477 stats->rx_ip_payload_malformed++; 1494 this_cpu_inc(nic->drv_stats->rx_ip_payload_malformed);
1478 break; 1495 break;
1479 case CQ_RX_ERROP_IP_HOP: 1496 case CQ_RX_ERROP_IP_HOP:
1480 stats->rx_ip_ttl_errs++; 1497 this_cpu_inc(nic->drv_stats->rx_ip_ttl_errs);
1481 break; 1498 break;
1482 case CQ_RX_ERROP_L3_PCLP: 1499 case CQ_RX_ERROP_L3_PCLP:
1483 stats->rx_l3_pclp++; 1500 this_cpu_inc(nic->drv_stats->rx_l3_pclp);
1484 break; 1501 break;
1485 case CQ_RX_ERROP_L4_MAL: 1502 case CQ_RX_ERROP_L4_MAL:
1486 stats->rx_l4_malformed++; 1503 this_cpu_inc(nic->drv_stats->rx_l4_malformed);
1487 break; 1504 break;
1488 case CQ_RX_ERROP_L4_CHK: 1505 case CQ_RX_ERROP_L4_CHK:
1489 stats->rx_l4_csum_errs++; 1506 this_cpu_inc(nic->drv_stats->rx_l4_csum_errs);
1490 break; 1507 break;
1491 case CQ_RX_ERROP_UDP_LEN: 1508 case CQ_RX_ERROP_UDP_LEN:
1492 stats->rx_udp_len_errs++; 1509 this_cpu_inc(nic->drv_stats->rx_udp_len_errs);
1493 break; 1510 break;
1494 case CQ_RX_ERROP_L4_PORT: 1511 case CQ_RX_ERROP_L4_PORT:
1495 stats->rx_l4_port_errs++; 1512 this_cpu_inc(nic->drv_stats->rx_l4_port_errs);
1496 break; 1513 break;
1497 case CQ_RX_ERROP_TCP_FLAG: 1514 case CQ_RX_ERROP_TCP_FLAG:
1498 stats->rx_tcp_flag_errs++; 1515 this_cpu_inc(nic->drv_stats->rx_tcp_flag_errs);
1499 break; 1516 break;
1500 case CQ_RX_ERROP_TCP_OFFSET: 1517 case CQ_RX_ERROP_TCP_OFFSET:
1501 stats->rx_tcp_offset_errs++; 1518 this_cpu_inc(nic->drv_stats->rx_tcp_offset_errs);
1502 break; 1519 break;
1503 case CQ_RX_ERROP_L4_PCLP: 1520 case CQ_RX_ERROP_L4_PCLP:
1504 stats->rx_l4_pclp++; 1521 this_cpu_inc(nic->drv_stats->rx_l4_pclp);
1505 break; 1522 break;
1506 case CQ_RX_ERROP_RBDR_TRUNC: 1523 case CQ_RX_ERROP_RBDR_TRUNC:
1507 stats->rx_truncated_pkts++; 1524 this_cpu_inc(nic->drv_stats->rx_truncated_pkts);
1508 break; 1525 break;
1509 } 1526 }
1510 1527
@@ -1512,53 +1529,52 @@ int nicvf_check_cqe_rx_errs(struct nicvf *nic, struct cqe_rx_t *cqe_rx)
1512} 1529}
1513 1530
1514/* Check for errors in the send cmp.queue entry */ 1531/* Check for errors in the send cmp.queue entry */
1515int nicvf_check_cqe_tx_errs(struct nicvf *nic, 1532int nicvf_check_cqe_tx_errs(struct nicvf *nic, struct cqe_send_t *cqe_tx)
1516 struct cmp_queue *cq, struct cqe_send_t *cqe_tx)
1517{ 1533{
1518 struct cmp_queue_stats *stats = &cq->stats;
1519
1520 switch (cqe_tx->send_status) { 1534 switch (cqe_tx->send_status) {
1521 case CQ_TX_ERROP_GOOD: 1535 case CQ_TX_ERROP_GOOD:
1522 stats->tx.good++;
1523 return 0; 1536 return 0;
1524 case CQ_TX_ERROP_DESC_FAULT: 1537 case CQ_TX_ERROP_DESC_FAULT:
1525 stats->tx.desc_fault++; 1538 this_cpu_inc(nic->drv_stats->tx_desc_fault);
1526 break; 1539 break;
1527 case CQ_TX_ERROP_HDR_CONS_ERR: 1540 case CQ_TX_ERROP_HDR_CONS_ERR:
1528 stats->tx.hdr_cons_err++; 1541 this_cpu_inc(nic->drv_stats->tx_hdr_cons_err);
1529 break; 1542 break;
1530 case CQ_TX_ERROP_SUBDC_ERR: 1543 case CQ_TX_ERROP_SUBDC_ERR:
1531 stats->tx.subdesc_err++; 1544 this_cpu_inc(nic->drv_stats->tx_subdesc_err);
1545 break;
1546 case CQ_TX_ERROP_MAX_SIZE_VIOL:
1547 this_cpu_inc(nic->drv_stats->tx_max_size_exceeded);
1532 break; 1548 break;
1533 case CQ_TX_ERROP_IMM_SIZE_OFLOW: 1549 case CQ_TX_ERROP_IMM_SIZE_OFLOW:
1534 stats->tx.imm_size_oflow++; 1550 this_cpu_inc(nic->drv_stats->tx_imm_size_oflow);
1535 break; 1551 break;
1536 case CQ_TX_ERROP_DATA_SEQUENCE_ERR: 1552 case CQ_TX_ERROP_DATA_SEQUENCE_ERR:
1537 stats->tx.data_seq_err++; 1553 this_cpu_inc(nic->drv_stats->tx_data_seq_err);
1538 break; 1554 break;
1539 case CQ_TX_ERROP_MEM_SEQUENCE_ERR: 1555 case CQ_TX_ERROP_MEM_SEQUENCE_ERR:
1540 stats->tx.mem_seq_err++; 1556 this_cpu_inc(nic->drv_stats->tx_mem_seq_err);
1541 break; 1557 break;
1542 case CQ_TX_ERROP_LOCK_VIOL: 1558 case CQ_TX_ERROP_LOCK_VIOL:
1543 stats->tx.lock_viol++; 1559 this_cpu_inc(nic->drv_stats->tx_lock_viol);
1544 break; 1560 break;
1545 case CQ_TX_ERROP_DATA_FAULT: 1561 case CQ_TX_ERROP_DATA_FAULT:
1546 stats->tx.data_fault++; 1562 this_cpu_inc(nic->drv_stats->tx_data_fault);
1547 break; 1563 break;
1548 case CQ_TX_ERROP_TSTMP_CONFLICT: 1564 case CQ_TX_ERROP_TSTMP_CONFLICT:
1549 stats->tx.tstmp_conflict++; 1565 this_cpu_inc(nic->drv_stats->tx_tstmp_conflict);
1550 break; 1566 break;
1551 case CQ_TX_ERROP_TSTMP_TIMEOUT: 1567 case CQ_TX_ERROP_TSTMP_TIMEOUT:
1552 stats->tx.tstmp_timeout++; 1568 this_cpu_inc(nic->drv_stats->tx_tstmp_timeout);
1553 break; 1569 break;
1554 case CQ_TX_ERROP_MEM_FAULT: 1570 case CQ_TX_ERROP_MEM_FAULT:
1555 stats->tx.mem_fault++; 1571 this_cpu_inc(nic->drv_stats->tx_mem_fault);
1556 break; 1572 break;
1557 case CQ_TX_ERROP_CK_OVERLAP: 1573 case CQ_TX_ERROP_CK_OVERLAP:
1558 stats->tx.csum_overlap++; 1574 this_cpu_inc(nic->drv_stats->tx_csum_overlap);
1559 break; 1575 break;
1560 case CQ_TX_ERROP_CK_OFLOW: 1576 case CQ_TX_ERROP_CK_OFLOW:
1561 stats->tx.csum_overflow++; 1577 this_cpu_inc(nic->drv_stats->tx_csum_overflow);
1562 break; 1578 break;
1563 } 1579 }
1564 1580
diff --git a/drivers/net/ethernet/cavium/thunder/nicvf_queues.h b/drivers/net/ethernet/cavium/thunder/nicvf_queues.h
index 869f3386028b..2e3c940c1093 100644
--- a/drivers/net/ethernet/cavium/thunder/nicvf_queues.h
+++ b/drivers/net/ethernet/cavium/thunder/nicvf_queues.h
@@ -158,6 +158,7 @@ enum CQ_TX_ERROP_E {
158 CQ_TX_ERROP_DESC_FAULT = 0x10, 158 CQ_TX_ERROP_DESC_FAULT = 0x10,
159 CQ_TX_ERROP_HDR_CONS_ERR = 0x11, 159 CQ_TX_ERROP_HDR_CONS_ERR = 0x11,
160 CQ_TX_ERROP_SUBDC_ERR = 0x12, 160 CQ_TX_ERROP_SUBDC_ERR = 0x12,
161 CQ_TX_ERROP_MAX_SIZE_VIOL = 0x13,
161 CQ_TX_ERROP_IMM_SIZE_OFLOW = 0x80, 162 CQ_TX_ERROP_IMM_SIZE_OFLOW = 0x80,
162 CQ_TX_ERROP_DATA_SEQUENCE_ERR = 0x81, 163 CQ_TX_ERROP_DATA_SEQUENCE_ERR = 0x81,
163 CQ_TX_ERROP_MEM_SEQUENCE_ERR = 0x82, 164 CQ_TX_ERROP_MEM_SEQUENCE_ERR = 0x82,
@@ -171,25 +172,6 @@ enum CQ_TX_ERROP_E {
171 CQ_TX_ERROP_ENUM_LAST = 0x8a, 172 CQ_TX_ERROP_ENUM_LAST = 0x8a,
172}; 173};
173 174
174struct cmp_queue_stats {
175 struct tx_stats {
176 u64 good;
177 u64 desc_fault;
178 u64 hdr_cons_err;
179 u64 subdesc_err;
180 u64 imm_size_oflow;
181 u64 data_seq_err;
182 u64 mem_seq_err;
183 u64 lock_viol;
184 u64 data_fault;
185 u64 tstmp_conflict;
186 u64 tstmp_timeout;
187 u64 mem_fault;
188 u64 csum_overlap;
189 u64 csum_overflow;
190 } tx;
191} ____cacheline_aligned_in_smp;
192
193enum RQ_SQ_STATS { 175enum RQ_SQ_STATS {
194 RQ_SQ_STATS_OCTS, 176 RQ_SQ_STATS_OCTS,
195 RQ_SQ_STATS_PKTS, 177 RQ_SQ_STATS_PKTS,
@@ -241,7 +223,6 @@ struct cmp_queue {
241 spinlock_t lock; /* lock to serialize processing CQEs */ 223 spinlock_t lock; /* lock to serialize processing CQEs */
242 void *desc; 224 void *desc;
243 struct q_desc_mem dmem; 225 struct q_desc_mem dmem;
244 struct cmp_queue_stats stats;
245 int irq; 226 int irq;
246} ____cacheline_aligned_in_smp; 227} ____cacheline_aligned_in_smp;
247 228
@@ -336,6 +317,5 @@ u64 nicvf_queue_reg_read(struct nicvf *nic,
336void nicvf_update_rq_stats(struct nicvf *nic, int rq_idx); 317void nicvf_update_rq_stats(struct nicvf *nic, int rq_idx);
337void nicvf_update_sq_stats(struct nicvf *nic, int sq_idx); 318void nicvf_update_sq_stats(struct nicvf *nic, int sq_idx);
338int nicvf_check_cqe_rx_errs(struct nicvf *nic, struct cqe_rx_t *cqe_rx); 319int nicvf_check_cqe_rx_errs(struct nicvf *nic, struct cqe_rx_t *cqe_rx);
339int nicvf_check_cqe_tx_errs(struct nicvf *nic, 320int nicvf_check_cqe_tx_errs(struct nicvf *nic, struct cqe_send_t *cqe_tx);
340 struct cmp_queue *cq, struct cqe_send_t *cqe_tx);
341#endif /* NICVF_QUEUES_H */ 321#endif /* NICVF_QUEUES_H */
diff --git a/drivers/net/ethernet/cavium/thunder/thunder_bgx.c b/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
index 8bbaedbb7b94..050e21fbb147 100644
--- a/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
+++ b/drivers/net/ethernet/cavium/thunder/thunder_bgx.c
@@ -1242,8 +1242,8 @@ static int bgx_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1242 1242
1243 pci_read_config_word(pdev, PCI_DEVICE_ID, &sdevid); 1243 pci_read_config_word(pdev, PCI_DEVICE_ID, &sdevid);
1244 if (sdevid != PCI_DEVICE_ID_THUNDER_RGX) { 1244 if (sdevid != PCI_DEVICE_ID_THUNDER_RGX) {
1245 bgx->bgx_id = 1245 bgx->bgx_id = (pci_resource_start(pdev,
1246 (pci_resource_start(pdev, PCI_CFG_REG_BAR_NUM) >> 24) & 1; 1246 PCI_CFG_REG_BAR_NUM) >> 24) & BGX_ID_MASK;
1247 bgx->bgx_id += nic_get_node_id(pdev) * MAX_BGX_PER_NODE; 1247 bgx->bgx_id += nic_get_node_id(pdev) * MAX_BGX_PER_NODE;
1248 bgx->max_lmac = MAX_LMAC_PER_BGX; 1248 bgx->max_lmac = MAX_LMAC_PER_BGX;
1249 bgx_vnic[bgx->bgx_id] = bgx; 1249 bgx_vnic[bgx->bgx_id] = bgx;
diff --git a/drivers/net/ethernet/cavium/thunder/thunder_bgx.h b/drivers/net/ethernet/cavium/thunder/thunder_bgx.h
index d59c71e4a000..01cc7c859131 100644
--- a/drivers/net/ethernet/cavium/thunder/thunder_bgx.h
+++ b/drivers/net/ethernet/cavium/thunder/thunder_bgx.h
@@ -28,6 +28,8 @@
28#define MAX_DMAC_PER_LMAC 8 28#define MAX_DMAC_PER_LMAC 8
29#define MAX_FRAME_SIZE 9216 29#define MAX_FRAME_SIZE 9216
30 30
31#define BGX_ID_MASK 0x3
32
31#define MAX_DMAC_PER_LMAC_TNS_BYPASS_MODE 2 33#define MAX_DMAC_PER_LMAC_TNS_BYPASS_MODE 2
32 34
33/* Registers */ 35/* Registers */
diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
index f320497368f4..19dc9e25aa72 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
@@ -4057,7 +4057,7 @@ static void cfg_queues(struct adapter *adap)
4057 * capped by the number of available cores. 4057 * capped by the number of available cores.
4058 */ 4058 */
4059 if (n10g) { 4059 if (n10g) {
4060 i = num_online_cpus(); 4060 i = min_t(int, MAX_OFLD_QSETS, num_online_cpus());
4061 s->ofldqsets = roundup(i, adap->params.nports); 4061 s->ofldqsets = roundup(i, adap->params.nports);
4062 } else { 4062 } else {
4063 s->ofldqsets = adap->params.nports; 4063 s->ofldqsets = adap->params.nports;
@@ -4931,6 +4931,7 @@ static int init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
4931 */ 4931 */
4932 for_each_port(adapter, i) { 4932 for_each_port(adapter, i) {
4933 pi = adap2pinfo(adapter, i); 4933 pi = adap2pinfo(adapter, i);
4934 adapter->port[i]->dev_port = pi->lport;
4934 netif_set_real_num_tx_queues(adapter->port[i], pi->nqsets); 4935 netif_set_real_num_tx_queues(adapter->port[i], pi->nqsets);
4935 netif_set_real_num_rx_queues(adapter->port[i], pi->nqsets); 4936 netif_set_real_num_rx_queues(adapter->port[i], pi->nqsets);
4936 4937
diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_uld.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_uld.c
index 0945fa49a5dd..2471ff465d5c 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_uld.c
+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_uld.c
@@ -135,15 +135,17 @@ static int uldrx_handler(struct sge_rspq *q, const __be64 *rsp,
135} 135}
136 136
137static int alloc_uld_rxqs(struct adapter *adap, 137static int alloc_uld_rxqs(struct adapter *adap,
138 struct sge_uld_rxq_info *rxq_info, 138 struct sge_uld_rxq_info *rxq_info, bool lro)
139 unsigned int nq, unsigned int offset, bool lro)
140{ 139{
141 struct sge *s = &adap->sge; 140 struct sge *s = &adap->sge;
142 struct sge_ofld_rxq *q = rxq_info->uldrxq + offset; 141 unsigned int nq = rxq_info->nrxq + rxq_info->nciq;
143 unsigned short *ids = rxq_info->rspq_id + offset; 142 struct sge_ofld_rxq *q = rxq_info->uldrxq;
144 unsigned int per_chan = nq / adap->params.nports; 143 unsigned short *ids = rxq_info->rspq_id;
145 unsigned int bmap_idx = 0; 144 unsigned int bmap_idx = 0;
146 int i, err, msi_idx; 145 unsigned int per_chan;
146 int i, err, msi_idx, que_idx = 0;
147
148 per_chan = rxq_info->nrxq / adap->params.nports;
147 149
148 if (adap->flags & USING_MSIX) 150 if (adap->flags & USING_MSIX)
149 msi_idx = 1; 151 msi_idx = 1;
@@ -151,12 +153,18 @@ static int alloc_uld_rxqs(struct adapter *adap,
151 msi_idx = -((int)s->intrq.abs_id + 1); 153 msi_idx = -((int)s->intrq.abs_id + 1);
152 154
153 for (i = 0; i < nq; i++, q++) { 155 for (i = 0; i < nq; i++, q++) {
156 if (i == rxq_info->nrxq) {
157 /* start allocation of concentrator queues */
158 per_chan = rxq_info->nciq / adap->params.nports;
159 que_idx = 0;
160 }
161
154 if (msi_idx >= 0) { 162 if (msi_idx >= 0) {
155 bmap_idx = get_msix_idx_from_bmap(adap); 163 bmap_idx = get_msix_idx_from_bmap(adap);
156 msi_idx = adap->msix_info_ulds[bmap_idx].idx; 164 msi_idx = adap->msix_info_ulds[bmap_idx].idx;
157 } 165 }
158 err = t4_sge_alloc_rxq(adap, &q->rspq, false, 166 err = t4_sge_alloc_rxq(adap, &q->rspq, false,
159 adap->port[i / per_chan], 167 adap->port[que_idx++ / per_chan],
160 msi_idx, 168 msi_idx,
161 q->fl.size ? &q->fl : NULL, 169 q->fl.size ? &q->fl : NULL,
162 uldrx_handler, 170 uldrx_handler,
@@ -165,29 +173,19 @@ static int alloc_uld_rxqs(struct adapter *adap,
165 if (err) 173 if (err)
166 goto freeout; 174 goto freeout;
167 if (msi_idx >= 0) 175 if (msi_idx >= 0)
168 rxq_info->msix_tbl[i + offset] = bmap_idx; 176 rxq_info->msix_tbl[i] = bmap_idx;
169 memset(&q->stats, 0, sizeof(q->stats)); 177 memset(&q->stats, 0, sizeof(q->stats));
170 if (ids) 178 if (ids)
171 ids[i] = q->rspq.abs_id; 179 ids[i] = q->rspq.abs_id;
172 } 180 }
173 return 0; 181 return 0;
174freeout: 182freeout:
175 q = rxq_info->uldrxq + offset; 183 q = rxq_info->uldrxq;
176 for ( ; i; i--, q++) { 184 for ( ; i; i--, q++) {
177 if (q->rspq.desc) 185 if (q->rspq.desc)
178 free_rspq_fl(adap, &q->rspq, 186 free_rspq_fl(adap, &q->rspq,
179 q->fl.size ? &q->fl : NULL); 187 q->fl.size ? &q->fl : NULL);
180 } 188 }
181
182 /* We need to free rxq also in case of ciq allocation failure */
183 if (offset) {
184 q = rxq_info->uldrxq + offset;
185 for ( ; i; i--, q++) {
186 if (q->rspq.desc)
187 free_rspq_fl(adap, &q->rspq,
188 q->fl.size ? &q->fl : NULL);
189 }
190 }
191 return err; 189 return err;
192} 190}
193 191
@@ -205,9 +203,7 @@ setup_sge_queues_uld(struct adapter *adap, unsigned int uld_type, bool lro)
205 return -ENOMEM; 203 return -ENOMEM;
206 } 204 }
207 205
208 ret = !(!alloc_uld_rxqs(adap, rxq_info, rxq_info->nrxq, 0, lro) && 206 ret = !(!alloc_uld_rxqs(adap, rxq_info, lro));
209 !alloc_uld_rxqs(adap, rxq_info, rxq_info->nciq,
210 rxq_info->nrxq, lro));
211 207
212 /* Tell uP to route control queue completions to rdma rspq */ 208 /* Tell uP to route control queue completions to rdma rspq */
213 if (adap->flags & FULL_INIT_DONE && 209 if (adap->flags & FULL_INIT_DONE &&
diff --git a/drivers/net/ethernet/chelsio/cxgb4/sched.c b/drivers/net/ethernet/chelsio/cxgb4/sched.c
index 539de764bbd3..cbd68a8fe2e4 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/sched.c
+++ b/drivers/net/ethernet/chelsio/cxgb4/sched.c
@@ -210,8 +210,10 @@ static int t4_sched_queue_bind(struct port_info *pi, struct ch_sched_queue *p)
210 210
211 /* Unbind queue from any existing class */ 211 /* Unbind queue from any existing class */
212 err = t4_sched_queue_unbind(pi, p); 212 err = t4_sched_queue_unbind(pi, p);
213 if (err) 213 if (err) {
214 t4_free_mem(qe);
214 goto out; 215 goto out;
216 }
215 217
216 /* Bind queue to specified class */ 218 /* Bind queue to specified class */
217 memset(qe, 0, sizeof(*qe)); 219 memset(qe, 0, sizeof(*qe));
diff --git a/drivers/net/ethernet/chelsio/cxgb4/sge.c b/drivers/net/ethernet/chelsio/cxgb4/sge.c
index 1e74fd6085df..e19a0ca8e5dd 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/sge.c
+++ b/drivers/net/ethernet/chelsio/cxgb4/sge.c
@@ -2951,7 +2951,6 @@ void free_rspq_fl(struct adapter *adap, struct sge_rspq *rq,
2951 rq->cntxt_id, fl_id, 0xffff); 2951 rq->cntxt_id, fl_id, 0xffff);
2952 dma_free_coherent(adap->pdev_dev, (rq->size + 1) * rq->iqe_len, 2952 dma_free_coherent(adap->pdev_dev, (rq->size + 1) * rq->iqe_len,
2953 rq->desc, rq->phys_addr); 2953 rq->desc, rq->phys_addr);
2954 napi_hash_del(&rq->napi);
2955 netif_napi_del(&rq->napi); 2954 netif_napi_del(&rq->napi);
2956 rq->netdev = NULL; 2955 rq->netdev = NULL;
2957 rq->cntxt_id = rq->abs_id = 0; 2956 rq->cntxt_id = rq->abs_id = 0;
diff --git a/drivers/net/ethernet/chelsio/cxgb4/t4_hw.c b/drivers/net/ethernet/chelsio/cxgb4/t4_hw.c
index 20dec85da63d..e8139514d32c 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/t4_hw.c
+++ b/drivers/net/ethernet/chelsio/cxgb4/t4_hw.c
@@ -7851,7 +7851,6 @@ int t4_port_init(struct adapter *adap, int mbox, int pf, int vf)
7851 return ret; 7851 return ret;
7852 7852
7853 memcpy(adap->port[i]->dev_addr, addr, ETH_ALEN); 7853 memcpy(adap->port[i]->dev_addr, addr, ETH_ALEN);
7854 adap->port[i]->dev_port = j;
7855 j++; 7854 j++;
7856 } 7855 }
7857 return 0; 7856 return 0;
diff --git a/drivers/net/ethernet/chelsio/cxgb4/t4_pci_id_tbl.h b/drivers/net/ethernet/chelsio/cxgb4/t4_pci_id_tbl.h
index 50812a1d67bd..ecf3ccc257bc 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/t4_pci_id_tbl.h
+++ b/drivers/net/ethernet/chelsio/cxgb4/t4_pci_id_tbl.h
@@ -168,6 +168,7 @@ CH_PCI_DEVICE_ID_TABLE_DEFINE_BEGIN
168 CH_PCI_ID_TABLE_FENTRY(0x509a), /* Custom T520-CR */ 168 CH_PCI_ID_TABLE_FENTRY(0x509a), /* Custom T520-CR */
169 CH_PCI_ID_TABLE_FENTRY(0x509b), /* Custom T540-CR LOM */ 169 CH_PCI_ID_TABLE_FENTRY(0x509b), /* Custom T540-CR LOM */
170 CH_PCI_ID_TABLE_FENTRY(0x509c), /* Custom T520-CR*/ 170 CH_PCI_ID_TABLE_FENTRY(0x509c), /* Custom T520-CR*/
171 CH_PCI_ID_TABLE_FENTRY(0x509d), /* Custom T540-CR*/
171 172
172 /* T6 adapters: 173 /* T6 adapters:
173 */ 174 */
@@ -178,9 +179,9 @@ CH_PCI_DEVICE_ID_TABLE_DEFINE_BEGIN
178 CH_PCI_ID_TABLE_FENTRY(0x6005), 179 CH_PCI_ID_TABLE_FENTRY(0x6005),
179 CH_PCI_ID_TABLE_FENTRY(0x6006), 180 CH_PCI_ID_TABLE_FENTRY(0x6006),
180 CH_PCI_ID_TABLE_FENTRY(0x6007), 181 CH_PCI_ID_TABLE_FENTRY(0x6007),
182 CH_PCI_ID_TABLE_FENTRY(0x6008),
181 CH_PCI_ID_TABLE_FENTRY(0x6009), 183 CH_PCI_ID_TABLE_FENTRY(0x6009),
182 CH_PCI_ID_TABLE_FENTRY(0x600d), 184 CH_PCI_ID_TABLE_FENTRY(0x600d),
183 CH_PCI_ID_TABLE_FENTRY(0x6010),
184 CH_PCI_ID_TABLE_FENTRY(0x6011), 185 CH_PCI_ID_TABLE_FENTRY(0x6011),
185 CH_PCI_ID_TABLE_FENTRY(0x6014), 186 CH_PCI_ID_TABLE_FENTRY(0x6014),
186 CH_PCI_ID_TABLE_FENTRY(0x6015), 187 CH_PCI_ID_TABLE_FENTRY(0x6015),
diff --git a/drivers/net/ethernet/chelsio/cxgb4vf/cxgb4vf_main.c b/drivers/net/ethernet/chelsio/cxgb4vf/cxgb4vf_main.c
index 100b2cc064a3..a37481c04a87 100644
--- a/drivers/net/ethernet/chelsio/cxgb4vf/cxgb4vf_main.c
+++ b/drivers/net/ethernet/chelsio/cxgb4vf/cxgb4vf_main.c
@@ -2969,6 +2969,7 @@ static int cxgb4vf_pci_probe(struct pci_dev *pdev,
2969 2969
2970 netdev->netdev_ops = &cxgb4vf_netdev_ops; 2970 netdev->netdev_ops = &cxgb4vf_netdev_ops;
2971 netdev->ethtool_ops = &cxgb4vf_ethtool_ops; 2971 netdev->ethtool_ops = &cxgb4vf_ethtool_ops;
2972 netdev->dev_port = pi->port_id;
2972 2973
2973 /* 2974 /*
2974 * Initialize the hardware/software state for the port. 2975 * Initialize the hardware/software state for the port.
diff --git a/drivers/net/ethernet/cirrus/ep93xx_eth.c b/drivers/net/ethernet/cirrus/ep93xx_eth.c
index de9f7c97d916..9a161e981529 100644
--- a/drivers/net/ethernet/cirrus/ep93xx_eth.c
+++ b/drivers/net/ethernet/cirrus/ep93xx_eth.c
@@ -468,6 +468,9 @@ static void ep93xx_free_buffers(struct ep93xx_priv *ep)
468 struct device *dev = ep->dev->dev.parent; 468 struct device *dev = ep->dev->dev.parent;
469 int i; 469 int i;
470 470
471 if (!ep->descs)
472 return;
473
471 for (i = 0; i < RX_QUEUE_ENTRIES; i++) { 474 for (i = 0; i < RX_QUEUE_ENTRIES; i++) {
472 dma_addr_t d; 475 dma_addr_t d;
473 476
@@ -490,6 +493,7 @@ static void ep93xx_free_buffers(struct ep93xx_priv *ep)
490 493
491 dma_free_coherent(dev, sizeof(struct ep93xx_descs), ep->descs, 494 dma_free_coherent(dev, sizeof(struct ep93xx_descs), ep->descs,
492 ep->descs_dma_addr); 495 ep->descs_dma_addr);
496 ep->descs = NULL;
493} 497}
494 498
495static int ep93xx_alloc_buffers(struct ep93xx_priv *ep) 499static int ep93xx_alloc_buffers(struct ep93xx_priv *ep)
diff --git a/drivers/net/ethernet/cisco/enic/vnic_rq.c b/drivers/net/ethernet/cisco/enic/vnic_rq.c
index e572a527b18d..36bc2c71fba9 100644
--- a/drivers/net/ethernet/cisco/enic/vnic_rq.c
+++ b/drivers/net/ethernet/cisco/enic/vnic_rq.c
@@ -169,19 +169,28 @@ int vnic_rq_disable(struct vnic_rq *rq)
169{ 169{
170 unsigned int wait; 170 unsigned int wait;
171 struct vnic_dev *vdev = rq->vdev; 171 struct vnic_dev *vdev = rq->vdev;
172 int i;
172 173
173 iowrite32(0, &rq->ctrl->enable); 174 /* Due to a race condition with clearing RQ "mini-cache" in hw, we need
175 * to disable the RQ twice to guarantee that stale descriptors are not
176 * used when this RQ is re-enabled.
177 */
178 for (i = 0; i < 2; i++) {
179 iowrite32(0, &rq->ctrl->enable);
174 180
175 /* Wait for HW to ACK disable request */ 181 /* Wait for HW to ACK disable request */
176 for (wait = 0; wait < 1000; wait++) { 182 for (wait = 20000; wait > 0; wait--)
177 if (!(ioread32(&rq->ctrl->running))) 183 if (!ioread32(&rq->ctrl->running))
178 return 0; 184 break;
179 udelay(10); 185 if (!wait) {
180 } 186 vdev_neterr(vdev, "Failed to disable RQ[%d]\n",
187 rq->index);
181 188
182 vdev_neterr(vdev, "Failed to disable RQ[%d]\n", rq->index); 189 return -ETIMEDOUT;
190 }
191 }
183 192
184 return -ETIMEDOUT; 193 return 0;
185} 194}
186 195
187void vnic_rq_clean(struct vnic_rq *rq, 196void vnic_rq_clean(struct vnic_rq *rq,
@@ -212,6 +221,11 @@ void vnic_rq_clean(struct vnic_rq *rq,
212 [fetch_index % VNIC_RQ_BUF_BLK_ENTRIES(count)]; 221 [fetch_index % VNIC_RQ_BUF_BLK_ENTRIES(count)];
213 iowrite32(fetch_index, &rq->ctrl->posted_index); 222 iowrite32(fetch_index, &rq->ctrl->posted_index);
214 223
224 /* Anytime we write fetch_index, we need to re-write 0 to rq->enable
225 * to re-sync internal VIC state.
226 */
227 iowrite32(0, &rq->ctrl->enable);
228
215 vnic_dev_clear_desc_ring(&rq->ring); 229 vnic_dev_clear_desc_ring(&rq->ring);
216} 230}
217 231
diff --git a/drivers/net/ethernet/emulex/benet/be_cmds.c b/drivers/net/ethernet/emulex/benet/be_cmds.c
index 1fb5d7239254..0e74529a4209 100644
--- a/drivers/net/ethernet/emulex/benet/be_cmds.c
+++ b/drivers/net/ethernet/emulex/benet/be_cmds.c
@@ -90,7 +90,8 @@ static struct be_cmd_priv_map cmd_priv_map[] = {
90 { 90 {
91 OPCODE_COMMON_SET_HSW_CONFIG, 91 OPCODE_COMMON_SET_HSW_CONFIG,
92 CMD_SUBSYSTEM_COMMON, 92 CMD_SUBSYSTEM_COMMON,
93 BE_PRIV_DEVCFG | BE_PRIV_VHADM 93 BE_PRIV_DEVCFG | BE_PRIV_VHADM |
94 BE_PRIV_DEVSEC
94 }, 95 },
95 { 96 {
96 OPCODE_COMMON_GET_EXT_FAT_CAPABILITIES, 97 OPCODE_COMMON_GET_EXT_FAT_CAPABILITIES,
diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
index cece8a08edca..93aa2939142a 100644
--- a/drivers/net/ethernet/emulex/benet/be_main.c
+++ b/drivers/net/ethernet/emulex/benet/be_main.c
@@ -2813,7 +2813,6 @@ static void be_evt_queues_destroy(struct be_adapter *adapter)
2813 if (eqo->q.created) { 2813 if (eqo->q.created) {
2814 be_eq_clean(eqo); 2814 be_eq_clean(eqo);
2815 be_cmd_q_destroy(adapter, &eqo->q, QTYPE_EQ); 2815 be_cmd_q_destroy(adapter, &eqo->q, QTYPE_EQ);
2816 napi_hash_del(&eqo->napi);
2817 netif_napi_del(&eqo->napi); 2816 netif_napi_del(&eqo->napi);
2818 free_cpumask_var(eqo->affinity_mask); 2817 free_cpumask_var(eqo->affinity_mask);
2819 } 2818 }
diff --git a/drivers/net/ethernet/ezchip/nps_enet.c b/drivers/net/ethernet/ezchip/nps_enet.c
index f928e6f79c89..223f35cc034c 100644
--- a/drivers/net/ethernet/ezchip/nps_enet.c
+++ b/drivers/net/ethernet/ezchip/nps_enet.c
@@ -669,6 +669,7 @@ static const struct of_device_id nps_enet_dt_ids[] = {
669 { .compatible = "ezchip,nps-mgt-enet" }, 669 { .compatible = "ezchip,nps-mgt-enet" },
670 { /* Sentinel */ } 670 { /* Sentinel */ }
671}; 671};
672MODULE_DEVICE_TABLE(of, nps_enet_dt_ids);
672 673
673static struct platform_driver nps_enet_driver = { 674static struct platform_driver nps_enet_driver = {
674 .probe = nps_enet_probe, 675 .probe = nps_enet_probe,
diff --git a/drivers/net/ethernet/freescale/fec.h b/drivers/net/ethernet/freescale/fec.h
index c865135f3cb9..5ea740b4cf14 100644
--- a/drivers/net/ethernet/freescale/fec.h
+++ b/drivers/net/ethernet/freescale/fec.h
@@ -574,6 +574,8 @@ struct fec_enet_private {
574 unsigned int reload_period; 574 unsigned int reload_period;
575 int pps_enable; 575 int pps_enable;
576 unsigned int next_counter; 576 unsigned int next_counter;
577
578 u64 ethtool_stats[0];
577}; 579};
578 580
579void fec_ptp_init(struct platform_device *pdev); 581void fec_ptp_init(struct platform_device *pdev);
diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c
index 48a033e64423..12aef1b15356 100644
--- a/drivers/net/ethernet/freescale/fec_main.c
+++ b/drivers/net/ethernet/freescale/fec_main.c
@@ -1430,14 +1430,14 @@ fec_enet_rx_queue(struct net_device *ndev, int budget, u16 queue_id)
1430 skb_put(skb, pkt_len - 4); 1430 skb_put(skb, pkt_len - 4);
1431 data = skb->data; 1431 data = skb->data;
1432 1432
1433 if (!is_copybreak && need_swap)
1434 swap_buffer(data, pkt_len);
1435
1433#if !defined(CONFIG_M5272) 1436#if !defined(CONFIG_M5272)
1434 if (fep->quirks & FEC_QUIRK_HAS_RACC) 1437 if (fep->quirks & FEC_QUIRK_HAS_RACC)
1435 data = skb_pull_inline(skb, 2); 1438 data = skb_pull_inline(skb, 2);
1436#endif 1439#endif
1437 1440
1438 if (!is_copybreak && need_swap)
1439 swap_buffer(data, pkt_len);
1440
1441 /* Extract the enhanced buffer descriptor */ 1441 /* Extract the enhanced buffer descriptor */
1442 ebdp = NULL; 1442 ebdp = NULL;
1443 if (fep->bufdesc_ex) 1443 if (fep->bufdesc_ex)
@@ -2313,14 +2313,26 @@ static const struct fec_stat {
2313 { "IEEE_rx_octets_ok", IEEE_R_OCTETS_OK }, 2313 { "IEEE_rx_octets_ok", IEEE_R_OCTETS_OK },
2314}; 2314};
2315 2315
2316static void fec_enet_get_ethtool_stats(struct net_device *dev, 2316#define FEC_STATS_SIZE (ARRAY_SIZE(fec_stats) * sizeof(u64))
2317 struct ethtool_stats *stats, u64 *data) 2317
2318static void fec_enet_update_ethtool_stats(struct net_device *dev)
2318{ 2319{
2319 struct fec_enet_private *fep = netdev_priv(dev); 2320 struct fec_enet_private *fep = netdev_priv(dev);
2320 int i; 2321 int i;
2321 2322
2322 for (i = 0; i < ARRAY_SIZE(fec_stats); i++) 2323 for (i = 0; i < ARRAY_SIZE(fec_stats); i++)
2323 data[i] = readl(fep->hwp + fec_stats[i].offset); 2324 fep->ethtool_stats[i] = readl(fep->hwp + fec_stats[i].offset);
2325}
2326
2327static void fec_enet_get_ethtool_stats(struct net_device *dev,
2328 struct ethtool_stats *stats, u64 *data)
2329{
2330 struct fec_enet_private *fep = netdev_priv(dev);
2331
2332 if (netif_running(dev))
2333 fec_enet_update_ethtool_stats(dev);
2334
2335 memcpy(data, fep->ethtool_stats, FEC_STATS_SIZE);
2324} 2336}
2325 2337
2326static void fec_enet_get_strings(struct net_device *netdev, 2338static void fec_enet_get_strings(struct net_device *netdev,
@@ -2345,6 +2357,12 @@ static int fec_enet_get_sset_count(struct net_device *dev, int sset)
2345 return -EOPNOTSUPP; 2357 return -EOPNOTSUPP;
2346 } 2358 }
2347} 2359}
2360
2361#else /* !defined(CONFIG_M5272) */
2362#define FEC_STATS_SIZE 0
2363static inline void fec_enet_update_ethtool_stats(struct net_device *dev)
2364{
2365}
2348#endif /* !defined(CONFIG_M5272) */ 2366#endif /* !defined(CONFIG_M5272) */
2349 2367
2350static int fec_enet_nway_reset(struct net_device *dev) 2368static int fec_enet_nway_reset(struct net_device *dev)
@@ -2874,6 +2892,8 @@ fec_enet_close(struct net_device *ndev)
2874 if (fep->quirks & FEC_QUIRK_ERR006687) 2892 if (fep->quirks & FEC_QUIRK_ERR006687)
2875 imx6q_cpuidle_fec_irqs_unused(); 2893 imx6q_cpuidle_fec_irqs_unused();
2876 2894
2895 fec_enet_update_ethtool_stats(ndev);
2896
2877 fec_enet_clk_enable(ndev, false); 2897 fec_enet_clk_enable(ndev, false);
2878 pinctrl_pm_select_sleep_state(&fep->pdev->dev); 2898 pinctrl_pm_select_sleep_state(&fep->pdev->dev);
2879 pm_runtime_mark_last_busy(&fep->pdev->dev); 2899 pm_runtime_mark_last_busy(&fep->pdev->dev);
@@ -3180,6 +3200,8 @@ static int fec_enet_init(struct net_device *ndev)
3180 3200
3181 fec_restart(ndev); 3201 fec_restart(ndev);
3182 3202
3203 fec_enet_update_ethtool_stats(ndev);
3204
3183 return 0; 3205 return 0;
3184} 3206}
3185 3207
@@ -3278,8 +3300,8 @@ fec_probe(struct platform_device *pdev)
3278 fec_enet_get_queue_num(pdev, &num_tx_qs, &num_rx_qs); 3300 fec_enet_get_queue_num(pdev, &num_tx_qs, &num_rx_qs);
3279 3301
3280 /* Init network device */ 3302 /* Init network device */
3281 ndev = alloc_etherdev_mqs(sizeof(struct fec_enet_private), 3303 ndev = alloc_etherdev_mqs(sizeof(struct fec_enet_private) +
3282 num_tx_qs, num_rx_qs); 3304 FEC_STATS_SIZE, num_tx_qs, num_rx_qs);
3283 if (!ndev) 3305 if (!ndev)
3284 return -ENOMEM; 3306 return -ENOMEM;
3285 3307
@@ -3475,6 +3497,8 @@ failed_regulator:
3475failed_clk_ipg: 3497failed_clk_ipg:
3476 fec_enet_clk_enable(ndev, false); 3498 fec_enet_clk_enable(ndev, false);
3477failed_clk: 3499failed_clk:
3500 if (of_phy_is_fixed_link(np))
3501 of_phy_deregister_fixed_link(np);
3478failed_phy: 3502failed_phy:
3479 of_node_put(phy_node); 3503 of_node_put(phy_node);
3480failed_ioremap: 3504failed_ioremap:
@@ -3488,6 +3512,7 @@ fec_drv_remove(struct platform_device *pdev)
3488{ 3512{
3489 struct net_device *ndev = platform_get_drvdata(pdev); 3513 struct net_device *ndev = platform_get_drvdata(pdev);
3490 struct fec_enet_private *fep = netdev_priv(ndev); 3514 struct fec_enet_private *fep = netdev_priv(ndev);
3515 struct device_node *np = pdev->dev.of_node;
3491 3516
3492 cancel_work_sync(&fep->tx_timeout_work); 3517 cancel_work_sync(&fep->tx_timeout_work);
3493 fec_ptp_stop(pdev); 3518 fec_ptp_stop(pdev);
@@ -3495,6 +3520,8 @@ fec_drv_remove(struct platform_device *pdev)
3495 fec_enet_mii_remove(fep); 3520 fec_enet_mii_remove(fep);
3496 if (fep->reg_phy) 3521 if (fep->reg_phy)
3497 regulator_disable(fep->reg_phy); 3522 regulator_disable(fep->reg_phy);
3523 if (of_phy_is_fixed_link(np))
3524 of_phy_deregister_fixed_link(np);
3498 of_node_put(fep->phy_node); 3525 of_node_put(fep->phy_node);
3499 free_netdev(ndev); 3526 free_netdev(ndev);
3500 3527
diff --git a/drivers/net/ethernet/freescale/fman/fman_memac.c b/drivers/net/ethernet/freescale/fman/fman_memac.c
index 53ef51e3bd9e..71a5ded9d1de 100644
--- a/drivers/net/ethernet/freescale/fman/fman_memac.c
+++ b/drivers/net/ethernet/freescale/fman/fman_memac.c
@@ -1107,6 +1107,9 @@ int memac_free(struct fman_mac *memac)
1107{ 1107{
1108 free_init_resources(memac); 1108 free_init_resources(memac);
1109 1109
1110 if (memac->pcsphy)
1111 put_device(&memac->pcsphy->mdio.dev);
1112
1110 kfree(memac->memac_drv_param); 1113 kfree(memac->memac_drv_param);
1111 kfree(memac); 1114 kfree(memac);
1112 1115
diff --git a/drivers/net/ethernet/freescale/fman/fman_tgec.c b/drivers/net/ethernet/freescale/fman/fman_tgec.c
index efabb04a1ae8..4b0f3a50b293 100644
--- a/drivers/net/ethernet/freescale/fman/fman_tgec.c
+++ b/drivers/net/ethernet/freescale/fman/fman_tgec.c
@@ -722,9 +722,6 @@ int tgec_free(struct fman_mac *tgec)
722{ 722{
723 free_init_resources(tgec); 723 free_init_resources(tgec);
724 724
725 if (tgec->cfg)
726 tgec->cfg = NULL;
727
728 kfree(tgec->cfg); 725 kfree(tgec->cfg);
729 kfree(tgec); 726 kfree(tgec);
730 727
diff --git a/drivers/net/ethernet/freescale/fman/mac.c b/drivers/net/ethernet/freescale/fman/mac.c
index 8fe6b3e253fa..736db9d9b0ad 100644
--- a/drivers/net/ethernet/freescale/fman/mac.c
+++ b/drivers/net/ethernet/freescale/fman/mac.c
@@ -892,6 +892,8 @@ static int mac_probe(struct platform_device *_of_dev)
892 priv->fixed_link->duplex = phy->duplex; 892 priv->fixed_link->duplex = phy->duplex;
893 priv->fixed_link->pause = phy->pause; 893 priv->fixed_link->pause = phy->pause;
894 priv->fixed_link->asym_pause = phy->asym_pause; 894 priv->fixed_link->asym_pause = phy->asym_pause;
895
896 put_device(&phy->mdio.dev);
895 } 897 }
896 898
897 err = mac_dev->init(mac_dev); 899 err = mac_dev->init(mac_dev);
diff --git a/drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c b/drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c
index dc120c148d97..4b86260584a0 100644
--- a/drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c
+++ b/drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c
@@ -980,7 +980,7 @@ static int fs_enet_probe(struct platform_device *ofdev)
980 err = clk_prepare_enable(clk); 980 err = clk_prepare_enable(clk);
981 if (err) { 981 if (err) {
982 ret = err; 982 ret = err;
983 goto out_free_fpi; 983 goto out_deregister_fixed_link;
984 } 984 }
985 fpi->clk_per = clk; 985 fpi->clk_per = clk;
986 } 986 }
@@ -1061,6 +1061,9 @@ out_put:
1061 of_node_put(fpi->phy_node); 1061 of_node_put(fpi->phy_node);
1062 if (fpi->clk_per) 1062 if (fpi->clk_per)
1063 clk_disable_unprepare(fpi->clk_per); 1063 clk_disable_unprepare(fpi->clk_per);
1064out_deregister_fixed_link:
1065 if (of_phy_is_fixed_link(ofdev->dev.of_node))
1066 of_phy_deregister_fixed_link(ofdev->dev.of_node);
1064out_free_fpi: 1067out_free_fpi:
1065 kfree(fpi); 1068 kfree(fpi);
1066 return ret; 1069 return ret;
@@ -1079,6 +1082,8 @@ static int fs_enet_remove(struct platform_device *ofdev)
1079 of_node_put(fep->fpi->phy_node); 1082 of_node_put(fep->fpi->phy_node);
1080 if (fep->fpi->clk_per) 1083 if (fep->fpi->clk_per)
1081 clk_disable_unprepare(fep->fpi->clk_per); 1084 clk_disable_unprepare(fep->fpi->clk_per);
1085 if (of_phy_is_fixed_link(ofdev->dev.of_node))
1086 of_phy_deregister_fixed_link(ofdev->dev.of_node);
1082 free_netdev(ndev); 1087 free_netdev(ndev);
1083 return 0; 1088 return 0;
1084} 1089}
diff --git a/drivers/net/ethernet/freescale/gianfar.c b/drivers/net/ethernet/freescale/gianfar.c
index 4b4f5bc0e279..9061c2f82b9c 100644
--- a/drivers/net/ethernet/freescale/gianfar.c
+++ b/drivers/net/ethernet/freescale/gianfar.c
@@ -1312,6 +1312,7 @@ static void gfar_init_addr_hash_table(struct gfar_private *priv)
1312 */ 1312 */
1313static int gfar_probe(struct platform_device *ofdev) 1313static int gfar_probe(struct platform_device *ofdev)
1314{ 1314{
1315 struct device_node *np = ofdev->dev.of_node;
1315 struct net_device *dev = NULL; 1316 struct net_device *dev = NULL;
1316 struct gfar_private *priv = NULL; 1317 struct gfar_private *priv = NULL;
1317 int err = 0, i; 1318 int err = 0, i;
@@ -1462,6 +1463,8 @@ static int gfar_probe(struct platform_device *ofdev)
1462 return 0; 1463 return 0;
1463 1464
1464register_fail: 1465register_fail:
1466 if (of_phy_is_fixed_link(np))
1467 of_phy_deregister_fixed_link(np);
1465 unmap_group_regs(priv); 1468 unmap_group_regs(priv);
1466 gfar_free_rx_queues(priv); 1469 gfar_free_rx_queues(priv);
1467 gfar_free_tx_queues(priv); 1470 gfar_free_tx_queues(priv);
@@ -1474,11 +1477,16 @@ register_fail:
1474static int gfar_remove(struct platform_device *ofdev) 1477static int gfar_remove(struct platform_device *ofdev)
1475{ 1478{
1476 struct gfar_private *priv = platform_get_drvdata(ofdev); 1479 struct gfar_private *priv = platform_get_drvdata(ofdev);
1480 struct device_node *np = ofdev->dev.of_node;
1477 1481
1478 of_node_put(priv->phy_node); 1482 of_node_put(priv->phy_node);
1479 of_node_put(priv->tbi_node); 1483 of_node_put(priv->tbi_node);
1480 1484
1481 unregister_netdev(priv->ndev); 1485 unregister_netdev(priv->ndev);
1486
1487 if (of_phy_is_fixed_link(np))
1488 of_phy_deregister_fixed_link(np);
1489
1482 unmap_group_regs(priv); 1490 unmap_group_regs(priv);
1483 gfar_free_rx_queues(priv); 1491 gfar_free_rx_queues(priv);
1484 gfar_free_tx_queues(priv); 1492 gfar_free_tx_queues(priv);
diff --git a/drivers/net/ethernet/freescale/ucc_geth.c b/drivers/net/ethernet/freescale/ucc_geth.c
index 186ef8f16c80..f76d33279454 100644
--- a/drivers/net/ethernet/freescale/ucc_geth.c
+++ b/drivers/net/ethernet/freescale/ucc_geth.c
@@ -3868,9 +3868,8 @@ static int ucc_geth_probe(struct platform_device* ofdev)
3868 dev = alloc_etherdev(sizeof(*ugeth)); 3868 dev = alloc_etherdev(sizeof(*ugeth));
3869 3869
3870 if (dev == NULL) { 3870 if (dev == NULL) {
3871 of_node_put(ug_info->tbi_node); 3871 err = -ENOMEM;
3872 of_node_put(ug_info->phy_node); 3872 goto err_deregister_fixed_link;
3873 return -ENOMEM;
3874 } 3873 }
3875 3874
3876 ugeth = netdev_priv(dev); 3875 ugeth = netdev_priv(dev);
@@ -3907,10 +3906,7 @@ static int ucc_geth_probe(struct platform_device* ofdev)
3907 if (netif_msg_probe(ugeth)) 3906 if (netif_msg_probe(ugeth))
3908 pr_err("%s: Cannot register net device, aborting\n", 3907 pr_err("%s: Cannot register net device, aborting\n",
3909 dev->name); 3908 dev->name);
3910 free_netdev(dev); 3909 goto err_free_netdev;
3911 of_node_put(ug_info->tbi_node);
3912 of_node_put(ug_info->phy_node);
3913 return err;
3914 } 3910 }
3915 3911
3916 mac_addr = of_get_mac_address(np); 3912 mac_addr = of_get_mac_address(np);
@@ -3923,16 +3919,29 @@ static int ucc_geth_probe(struct platform_device* ofdev)
3923 ugeth->node = np; 3919 ugeth->node = np;
3924 3920
3925 return 0; 3921 return 0;
3922
3923err_free_netdev:
3924 free_netdev(dev);
3925err_deregister_fixed_link:
3926 if (of_phy_is_fixed_link(np))
3927 of_phy_deregister_fixed_link(np);
3928 of_node_put(ug_info->tbi_node);
3929 of_node_put(ug_info->phy_node);
3930
3931 return err;
3926} 3932}
3927 3933
3928static int ucc_geth_remove(struct platform_device* ofdev) 3934static int ucc_geth_remove(struct platform_device* ofdev)
3929{ 3935{
3930 struct net_device *dev = platform_get_drvdata(ofdev); 3936 struct net_device *dev = platform_get_drvdata(ofdev);
3931 struct ucc_geth_private *ugeth = netdev_priv(dev); 3937 struct ucc_geth_private *ugeth = netdev_priv(dev);
3938 struct device_node *np = ofdev->dev.of_node;
3932 3939
3933 unregister_netdev(dev); 3940 unregister_netdev(dev);
3934 free_netdev(dev); 3941 free_netdev(dev);
3935 ucc_geth_memclean(ugeth); 3942 ucc_geth_memclean(ugeth);
3943 if (of_phy_is_fixed_link(np))
3944 of_phy_deregister_fixed_link(np);
3936 of_node_put(ugeth->ug_info->tbi_node); 3945 of_node_put(ugeth->ug_info->tbi_node);
3937 of_node_put(ugeth->ug_info->phy_node); 3946 of_node_put(ugeth->ug_info->phy_node);
3938 3947
diff --git a/drivers/net/ethernet/hisilicon/hns/hnae.c b/drivers/net/ethernet/hisilicon/hns/hnae.c
index c54c6fac0d1d..b6ed818f78ff 100644
--- a/drivers/net/ethernet/hisilicon/hns/hnae.c
+++ b/drivers/net/ethernet/hisilicon/hns/hnae.c
@@ -332,8 +332,10 @@ struct hnae_handle *hnae_get_handle(struct device *owner_dev,
332 return ERR_PTR(-ENODEV); 332 return ERR_PTR(-ENODEV);
333 333
334 handle = dev->ops->get_handle(dev, port_id); 334 handle = dev->ops->get_handle(dev, port_id);
335 if (IS_ERR(handle)) 335 if (IS_ERR(handle)) {
336 put_device(&dev->cls_dev);
336 return handle; 337 return handle;
338 }
337 339
338 handle->dev = dev; 340 handle->dev = dev;
339 handle->owner_dev = owner_dev; 341 handle->owner_dev = owner_dev;
@@ -356,6 +358,8 @@ out_when_init_queue:
356 for (j = i - 1; j >= 0; j--) 358 for (j = i - 1; j >= 0; j--)
357 hnae_fini_queue(handle->qs[j]); 359 hnae_fini_queue(handle->qs[j]);
358 360
361 put_device(&dev->cls_dev);
362
359 return ERR_PTR(-ENOMEM); 363 return ERR_PTR(-ENOMEM);
360} 364}
361EXPORT_SYMBOL(hnae_get_handle); 365EXPORT_SYMBOL(hnae_get_handle);
@@ -377,6 +381,8 @@ void hnae_put_handle(struct hnae_handle *h)
377 dev->ops->put_handle(h); 381 dev->ops->put_handle(h);
378 382
379 module_put(dev->owner); 383 module_put(dev->owner);
384
385 put_device(&dev->cls_dev);
380} 386}
381EXPORT_SYMBOL(hnae_put_handle); 387EXPORT_SYMBOL(hnae_put_handle);
382 388
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
index 8d70377f6624..8ea3d95fa483 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
@@ -2751,6 +2751,7 @@ static const struct of_device_id g_dsaf_match[] = {
2751 {.compatible = "hisilicon,hns-dsaf-v2"}, 2751 {.compatible = "hisilicon,hns-dsaf-v2"},
2752 {} 2752 {}
2753}; 2753};
2754MODULE_DEVICE_TABLE(of, g_dsaf_match);
2754 2755
2755static struct platform_driver g_dsaf_driver = { 2756static struct platform_driver g_dsaf_driver = {
2756 .probe = hns_dsaf_probe, 2757 .probe = hns_dsaf_probe,
diff --git a/drivers/net/ethernet/hisilicon/hns_mdio.c b/drivers/net/ethernet/hisilicon/hns_mdio.c
index 33f4c483af0f..501eb2090ca6 100644
--- a/drivers/net/ethernet/hisilicon/hns_mdio.c
+++ b/drivers/net/ethernet/hisilicon/hns_mdio.c
@@ -563,6 +563,7 @@ static const struct of_device_id hns_mdio_match[] = {
563 {.compatible = "hisilicon,hns-mdio"}, 563 {.compatible = "hisilicon,hns-mdio"},
564 {} 564 {}
565}; 565};
566MODULE_DEVICE_TABLE(of, hns_mdio_match);
566 567
567static const struct acpi_device_id hns_mdio_acpi_match[] = { 568static const struct acpi_device_id hns_mdio_acpi_match[] = {
568 { "HISI0141", 0 }, 569 { "HISI0141", 0 },
diff --git a/drivers/net/ethernet/ibm/ehea/ehea_main.c b/drivers/net/ethernet/ibm/ehea/ehea_main.c
index 54efa9a5167b..bd719e25dd76 100644
--- a/drivers/net/ethernet/ibm/ehea/ehea_main.c
+++ b/drivers/net/ethernet/ibm/ehea/ehea_main.c
@@ -2446,6 +2446,8 @@ static int ehea_open(struct net_device *dev)
2446 2446
2447 netif_info(port, ifup, dev, "enabling port\n"); 2447 netif_info(port, ifup, dev, "enabling port\n");
2448 2448
2449 netif_carrier_off(dev);
2450
2449 ret = ehea_up(dev); 2451 ret = ehea_up(dev);
2450 if (!ret) { 2452 if (!ret) {
2451 port_napi_enable(port); 2453 port_napi_enable(port);
diff --git a/drivers/net/ethernet/ibm/ibmveth.c b/drivers/net/ethernet/ibm/ibmveth.c
index ebe60719e489..a36022ba4e42 100644
--- a/drivers/net/ethernet/ibm/ibmveth.c
+++ b/drivers/net/ethernet/ibm/ibmveth.c
@@ -58,7 +58,7 @@ static struct kobj_type ktype_veth_pool;
58 58
59static const char ibmveth_driver_name[] = "ibmveth"; 59static const char ibmveth_driver_name[] = "ibmveth";
60static const char ibmveth_driver_string[] = "IBM Power Virtual Ethernet Driver"; 60static const char ibmveth_driver_string[] = "IBM Power Virtual Ethernet Driver";
61#define ibmveth_driver_version "1.05" 61#define ibmveth_driver_version "1.06"
62 62
63MODULE_AUTHOR("Santiago Leon <santil@linux.vnet.ibm.com>"); 63MODULE_AUTHOR("Santiago Leon <santil@linux.vnet.ibm.com>");
64MODULE_DESCRIPTION("IBM Power Virtual Ethernet Driver"); 64MODULE_DESCRIPTION("IBM Power Virtual Ethernet Driver");
@@ -137,6 +137,11 @@ static inline int ibmveth_rxq_frame_offset(struct ibmveth_adapter *adapter)
137 return ibmveth_rxq_flags(adapter) & IBMVETH_RXQ_OFF_MASK; 137 return ibmveth_rxq_flags(adapter) & IBMVETH_RXQ_OFF_MASK;
138} 138}
139 139
140static inline int ibmveth_rxq_large_packet(struct ibmveth_adapter *adapter)
141{
142 return ibmveth_rxq_flags(adapter) & IBMVETH_RXQ_LRG_PKT;
143}
144
140static inline int ibmveth_rxq_frame_length(struct ibmveth_adapter *adapter) 145static inline int ibmveth_rxq_frame_length(struct ibmveth_adapter *adapter)
141{ 146{
142 return be32_to_cpu(adapter->rx_queue.queue_addr[adapter->rx_queue.index].length); 147 return be32_to_cpu(adapter->rx_queue.queue_addr[adapter->rx_queue.index].length);
@@ -1174,6 +1179,45 @@ map_failed:
1174 goto retry_bounce; 1179 goto retry_bounce;
1175} 1180}
1176 1181
1182static void ibmveth_rx_mss_helper(struct sk_buff *skb, u16 mss, int lrg_pkt)
1183{
1184 int offset = 0;
1185
1186 /* only TCP packets will be aggregated */
1187 if (skb->protocol == htons(ETH_P_IP)) {
1188 struct iphdr *iph = (struct iphdr *)skb->data;
1189
1190 if (iph->protocol == IPPROTO_TCP) {
1191 offset = iph->ihl * 4;
1192 skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
1193 } else {
1194 return;
1195 }
1196 } else if (skb->protocol == htons(ETH_P_IPV6)) {
1197 struct ipv6hdr *iph6 = (struct ipv6hdr *)skb->data;
1198
1199 if (iph6->nexthdr == IPPROTO_TCP) {
1200 offset = sizeof(struct ipv6hdr);
1201 skb_shinfo(skb)->gso_type = SKB_GSO_TCPV6;
1202 } else {
1203 return;
1204 }
1205 } else {
1206 return;
1207 }
1208 /* if mss is not set through Large Packet bit/mss in rx buffer,
1209 * expect that the mss will be written to the tcp header checksum.
1210 */
1211 if (lrg_pkt) {
1212 skb_shinfo(skb)->gso_size = mss;
1213 } else if (offset) {
1214 struct tcphdr *tcph = (struct tcphdr *)(skb->data + offset);
1215
1216 skb_shinfo(skb)->gso_size = ntohs(tcph->check);
1217 tcph->check = 0;
1218 }
1219}
1220
1177static int ibmveth_poll(struct napi_struct *napi, int budget) 1221static int ibmveth_poll(struct napi_struct *napi, int budget)
1178{ 1222{
1179 struct ibmveth_adapter *adapter = 1223 struct ibmveth_adapter *adapter =
@@ -1182,6 +1226,7 @@ static int ibmveth_poll(struct napi_struct *napi, int budget)
1182 int frames_processed = 0; 1226 int frames_processed = 0;
1183 unsigned long lpar_rc; 1227 unsigned long lpar_rc;
1184 struct iphdr *iph; 1228 struct iphdr *iph;
1229 u16 mss = 0;
1185 1230
1186restart_poll: 1231restart_poll:
1187 while (frames_processed < budget) { 1232 while (frames_processed < budget) {
@@ -1199,9 +1244,21 @@ restart_poll:
1199 int length = ibmveth_rxq_frame_length(adapter); 1244 int length = ibmveth_rxq_frame_length(adapter);
1200 int offset = ibmveth_rxq_frame_offset(adapter); 1245 int offset = ibmveth_rxq_frame_offset(adapter);
1201 int csum_good = ibmveth_rxq_csum_good(adapter); 1246 int csum_good = ibmveth_rxq_csum_good(adapter);
1247 int lrg_pkt = ibmveth_rxq_large_packet(adapter);
1202 1248
1203 skb = ibmveth_rxq_get_buffer(adapter); 1249 skb = ibmveth_rxq_get_buffer(adapter);
1204 1250
1251 /* if the large packet bit is set in the rx queue
1252 * descriptor, the mss will be written by PHYP eight
1253 * bytes from the start of the rx buffer, which is
1254 * skb->data at this stage
1255 */
1256 if (lrg_pkt) {
1257 __be64 *rxmss = (__be64 *)(skb->data + 8);
1258
1259 mss = (u16)be64_to_cpu(*rxmss);
1260 }
1261
1205 new_skb = NULL; 1262 new_skb = NULL;
1206 if (length < rx_copybreak) 1263 if (length < rx_copybreak)
1207 new_skb = netdev_alloc_skb(netdev, length); 1264 new_skb = netdev_alloc_skb(netdev, length);
@@ -1235,11 +1292,15 @@ restart_poll:
1235 if (iph->check == 0xffff) { 1292 if (iph->check == 0xffff) {
1236 iph->check = 0; 1293 iph->check = 0;
1237 iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl); 1294 iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl);
1238 adapter->rx_large_packets++;
1239 } 1295 }
1240 } 1296 }
1241 } 1297 }
1242 1298
1299 if (length > netdev->mtu + ETH_HLEN) {
1300 ibmveth_rx_mss_helper(skb, mss, lrg_pkt);
1301 adapter->rx_large_packets++;
1302 }
1303
1243 napi_gro_receive(napi, skb); /* send it up */ 1304 napi_gro_receive(napi, skb); /* send it up */
1244 1305
1245 netdev->stats.rx_packets++; 1306 netdev->stats.rx_packets++;
diff --git a/drivers/net/ethernet/ibm/ibmveth.h b/drivers/net/ethernet/ibm/ibmveth.h
index 4eade67fe30c..7acda04d034e 100644
--- a/drivers/net/ethernet/ibm/ibmveth.h
+++ b/drivers/net/ethernet/ibm/ibmveth.h
@@ -209,6 +209,7 @@ struct ibmveth_rx_q_entry {
209#define IBMVETH_RXQ_TOGGLE 0x80000000 209#define IBMVETH_RXQ_TOGGLE 0x80000000
210#define IBMVETH_RXQ_TOGGLE_SHIFT 31 210#define IBMVETH_RXQ_TOGGLE_SHIFT 31
211#define IBMVETH_RXQ_VALID 0x40000000 211#define IBMVETH_RXQ_VALID 0x40000000
212#define IBMVETH_RXQ_LRG_PKT 0x04000000
212#define IBMVETH_RXQ_NO_CSUM 0x02000000 213#define IBMVETH_RXQ_NO_CSUM 0x02000000
213#define IBMVETH_RXQ_CSUM_GOOD 0x01000000 214#define IBMVETH_RXQ_CSUM_GOOD 0x01000000
214#define IBMVETH_RXQ_OFF_MASK 0x0000FFFF 215#define IBMVETH_RXQ_OFF_MASK 0x0000FFFF
diff --git a/drivers/net/ethernet/ibm/ibmvnic.c b/drivers/net/ethernet/ibm/ibmvnic.c
index bfe17d9c022d..0fbf686f5e7c 100644
--- a/drivers/net/ethernet/ibm/ibmvnic.c
+++ b/drivers/net/ethernet/ibm/ibmvnic.c
@@ -74,7 +74,6 @@
74#include <asm/iommu.h> 74#include <asm/iommu.h>
75#include <linux/uaccess.h> 75#include <linux/uaccess.h>
76#include <asm/firmware.h> 76#include <asm/firmware.h>
77#include <linux/seq_file.h>
78#include <linux/workqueue.h> 77#include <linux/workqueue.h>
79 78
80#include "ibmvnic.h" 79#include "ibmvnic.h"
@@ -1190,7 +1189,7 @@ static struct ibmvnic_sub_crq_queue *init_sub_crq_queue(struct ibmvnic_adapter
1190 if (!scrq) 1189 if (!scrq)
1191 return NULL; 1190 return NULL;
1192 1191
1193 scrq->msgs = (union sub_crq *)__get_free_pages(GFP_KERNEL, 2); 1192 scrq->msgs = (union sub_crq *)__get_free_pages(GFP_ATOMIC, 2);
1194 memset(scrq->msgs, 0, 4 * PAGE_SIZE); 1193 memset(scrq->msgs, 0, 4 * PAGE_SIZE);
1195 if (!scrq->msgs) { 1194 if (!scrq->msgs) {
1196 dev_warn(dev, "Couldn't allocate crq queue messages page\n"); 1195 dev_warn(dev, "Couldn't allocate crq queue messages page\n");
@@ -1461,14 +1460,16 @@ static int init_sub_crq_irqs(struct ibmvnic_adapter *adapter)
1461 return rc; 1460 return rc;
1462 1461
1463req_rx_irq_failed: 1462req_rx_irq_failed:
1464 for (j = 0; j < i; j++) 1463 for (j = 0; j < i; j++) {
1465 free_irq(adapter->rx_scrq[j]->irq, adapter->rx_scrq[j]); 1464 free_irq(adapter->rx_scrq[j]->irq, adapter->rx_scrq[j]);
1466 irq_dispose_mapping(adapter->rx_scrq[j]->irq); 1465 irq_dispose_mapping(adapter->rx_scrq[j]->irq);
1466 }
1467 i = adapter->req_tx_queues; 1467 i = adapter->req_tx_queues;
1468req_tx_irq_failed: 1468req_tx_irq_failed:
1469 for (j = 0; j < i; j++) 1469 for (j = 0; j < i; j++) {
1470 free_irq(adapter->tx_scrq[j]->irq, adapter->tx_scrq[j]); 1470 free_irq(adapter->tx_scrq[j]->irq, adapter->tx_scrq[j]);
1471 irq_dispose_mapping(adapter->rx_scrq[j]->irq); 1471 irq_dispose_mapping(adapter->rx_scrq[j]->irq);
1472 }
1472 release_sub_crqs_no_irqs(adapter); 1473 release_sub_crqs_no_irqs(adapter);
1473 return rc; 1474 return rc;
1474} 1475}
@@ -1503,9 +1504,8 @@ static void init_sub_crqs(struct ibmvnic_adapter *adapter, int retry)
1503 adapter->max_rx_add_entries_per_subcrq > entries_page ? 1504 adapter->max_rx_add_entries_per_subcrq > entries_page ?
1504 entries_page : adapter->max_rx_add_entries_per_subcrq; 1505 entries_page : adapter->max_rx_add_entries_per_subcrq;
1505 1506
1506 /* Choosing the maximum number of queues supported by firmware*/ 1507 adapter->req_tx_queues = adapter->opt_tx_comp_sub_queues;
1507 adapter->req_tx_queues = adapter->max_tx_queues; 1508 adapter->req_rx_queues = adapter->opt_rx_comp_queues;
1508 adapter->req_rx_queues = adapter->max_rx_queues;
1509 adapter->req_rx_add_queues = adapter->max_rx_add_queues; 1509 adapter->req_rx_add_queues = adapter->max_rx_add_queues;
1510 1510
1511 adapter->req_mtu = adapter->max_mtu; 1511 adapter->req_mtu = adapter->max_mtu;
@@ -3232,6 +3232,27 @@ static void ibmvnic_free_inflight(struct ibmvnic_adapter *adapter)
3232 spin_unlock_irqrestore(&adapter->inflight_lock, flags); 3232 spin_unlock_irqrestore(&adapter->inflight_lock, flags);
3233} 3233}
3234 3234
3235static void ibmvnic_xport_event(struct work_struct *work)
3236{
3237 struct ibmvnic_adapter *adapter = container_of(work,
3238 struct ibmvnic_adapter,
3239 ibmvnic_xport);
3240 struct device *dev = &adapter->vdev->dev;
3241 long rc;
3242
3243 ibmvnic_free_inflight(adapter);
3244 release_sub_crqs(adapter);
3245 if (adapter->migrated) {
3246 rc = ibmvnic_reenable_crq_queue(adapter);
3247 if (rc)
3248 dev_err(dev, "Error after enable rc=%ld\n", rc);
3249 adapter->migrated = false;
3250 rc = ibmvnic_send_crq_init(adapter);
3251 if (rc)
3252 dev_err(dev, "Error sending init rc=%ld\n", rc);
3253 }
3254}
3255
3235static void ibmvnic_handle_crq(union ibmvnic_crq *crq, 3256static void ibmvnic_handle_crq(union ibmvnic_crq *crq,
3236 struct ibmvnic_adapter *adapter) 3257 struct ibmvnic_adapter *adapter)
3237{ 3258{
@@ -3267,15 +3288,7 @@ static void ibmvnic_handle_crq(union ibmvnic_crq *crq,
3267 if (gen_crq->cmd == IBMVNIC_PARTITION_MIGRATED) { 3288 if (gen_crq->cmd == IBMVNIC_PARTITION_MIGRATED) {
3268 dev_info(dev, "Re-enabling adapter\n"); 3289 dev_info(dev, "Re-enabling adapter\n");
3269 adapter->migrated = true; 3290 adapter->migrated = true;
3270 ibmvnic_free_inflight(adapter); 3291 schedule_work(&adapter->ibmvnic_xport);
3271 release_sub_crqs(adapter);
3272 rc = ibmvnic_reenable_crq_queue(adapter);
3273 if (rc)
3274 dev_err(dev, "Error after enable rc=%ld\n", rc);
3275 adapter->migrated = false;
3276 rc = ibmvnic_send_crq_init(adapter);
3277 if (rc)
3278 dev_err(dev, "Error sending init rc=%ld\n", rc);
3279 } else if (gen_crq->cmd == IBMVNIC_DEVICE_FAILOVER) { 3292 } else if (gen_crq->cmd == IBMVNIC_DEVICE_FAILOVER) {
3280 dev_info(dev, "Backing device failover detected\n"); 3293 dev_info(dev, "Backing device failover detected\n");
3281 netif_carrier_off(netdev); 3294 netif_carrier_off(netdev);
@@ -3284,8 +3297,7 @@ static void ibmvnic_handle_crq(union ibmvnic_crq *crq,
3284 /* The adapter lost the connection */ 3297 /* The adapter lost the connection */
3285 dev_err(dev, "Virtual Adapter failed (rc=%d)\n", 3298 dev_err(dev, "Virtual Adapter failed (rc=%d)\n",
3286 gen_crq->cmd); 3299 gen_crq->cmd);
3287 ibmvnic_free_inflight(adapter); 3300 schedule_work(&adapter->ibmvnic_xport);
3288 release_sub_crqs(adapter);
3289 } 3301 }
3290 return; 3302 return;
3291 case IBMVNIC_CRQ_CMD_RSP: 3303 case IBMVNIC_CRQ_CMD_RSP:
@@ -3654,6 +3666,7 @@ static void handle_crq_init_rsp(struct work_struct *work)
3654 goto task_failed; 3666 goto task_failed;
3655 3667
3656 netdev->real_num_tx_queues = adapter->req_tx_queues; 3668 netdev->real_num_tx_queues = adapter->req_tx_queues;
3669 netdev->mtu = adapter->req_mtu;
3657 3670
3658 if (adapter->failover) { 3671 if (adapter->failover) {
3659 adapter->failover = false; 3672 adapter->failover = false;
@@ -3691,7 +3704,7 @@ static int ibmvnic_probe(struct vio_dev *dev, const struct vio_device_id *id)
3691 struct net_device *netdev; 3704 struct net_device *netdev;
3692 unsigned char *mac_addr_p; 3705 unsigned char *mac_addr_p;
3693 struct dentry *ent; 3706 struct dentry *ent;
3694 char buf[16]; /* debugfs name buf */ 3707 char buf[17]; /* debugfs name buf */
3695 int rc; 3708 int rc;
3696 3709
3697 dev_dbg(&dev->dev, "entering ibmvnic_probe for UA 0x%x\n", 3710 dev_dbg(&dev->dev, "entering ibmvnic_probe for UA 0x%x\n",
@@ -3725,6 +3738,7 @@ static int ibmvnic_probe(struct vio_dev *dev, const struct vio_device_id *id)
3725 SET_NETDEV_DEV(netdev, &dev->dev); 3738 SET_NETDEV_DEV(netdev, &dev->dev);
3726 3739
3727 INIT_WORK(&adapter->vnic_crq_init, handle_crq_init_rsp); 3740 INIT_WORK(&adapter->vnic_crq_init, handle_crq_init_rsp);
3741 INIT_WORK(&adapter->ibmvnic_xport, ibmvnic_xport_event);
3728 3742
3729 spin_lock_init(&adapter->stats_lock); 3743 spin_lock_init(&adapter->stats_lock);
3730 3744
@@ -3792,6 +3806,7 @@ static int ibmvnic_probe(struct vio_dev *dev, const struct vio_device_id *id)
3792 } 3806 }
3793 3807
3794 netdev->real_num_tx_queues = adapter->req_tx_queues; 3808 netdev->real_num_tx_queues = adapter->req_tx_queues;
3809 netdev->mtu = adapter->req_mtu;
3795 3810
3796 rc = register_netdev(netdev); 3811 rc = register_netdev(netdev);
3797 if (rc) { 3812 if (rc) {
@@ -3828,6 +3843,9 @@ static int ibmvnic_remove(struct vio_dev *dev)
3828 if (adapter->debugfs_dir && !IS_ERR(adapter->debugfs_dir)) 3843 if (adapter->debugfs_dir && !IS_ERR(adapter->debugfs_dir))
3829 debugfs_remove_recursive(adapter->debugfs_dir); 3844 debugfs_remove_recursive(adapter->debugfs_dir);
3830 3845
3846 dma_unmap_single(&dev->dev, adapter->stats_token,
3847 sizeof(struct ibmvnic_statistics), DMA_FROM_DEVICE);
3848
3831 if (adapter->ras_comps) 3849 if (adapter->ras_comps)
3832 dma_free_coherent(&dev->dev, 3850 dma_free_coherent(&dev->dev,
3833 adapter->ras_comp_num * 3851 adapter->ras_comp_num *
diff --git a/drivers/net/ethernet/ibm/ibmvnic.h b/drivers/net/ethernet/ibm/ibmvnic.h
index bfc84c7d0e11..dd775d951b73 100644
--- a/drivers/net/ethernet/ibm/ibmvnic.h
+++ b/drivers/net/ethernet/ibm/ibmvnic.h
@@ -27,7 +27,7 @@
27/**************************************************************************/ 27/**************************************************************************/
28 28
29#define IBMVNIC_NAME "ibmvnic" 29#define IBMVNIC_NAME "ibmvnic"
30#define IBMVNIC_DRIVER_VERSION "1.0" 30#define IBMVNIC_DRIVER_VERSION "1.0.1"
31#define IBMVNIC_INVALID_MAP -1 31#define IBMVNIC_INVALID_MAP -1
32#define IBMVNIC_STATS_TIMEOUT 1 32#define IBMVNIC_STATS_TIMEOUT 1
33/* basic structures plus 100 2k buffers */ 33/* basic structures plus 100 2k buffers */
@@ -1048,5 +1048,6 @@ struct ibmvnic_adapter {
1048 u8 map_id; 1048 u8 map_id;
1049 1049
1050 struct work_struct vnic_crq_init; 1050 struct work_struct vnic_crq_init;
1051 struct work_struct ibmvnic_xport;
1051 bool failover; 1052 bool failover;
1052}; 1053};
diff --git a/drivers/net/ethernet/intel/i40e/i40e.h b/drivers/net/ethernet/intel/i40e/i40e.h
index 2030d7c1dc94..6d61e443bdf8 100644
--- a/drivers/net/ethernet/intel/i40e/i40e.h
+++ b/drivers/net/ethernet/intel/i40e/i40e.h
@@ -92,6 +92,7 @@
92#define I40E_AQ_LEN 256 92#define I40E_AQ_LEN 256
93#define I40E_AQ_WORK_LIMIT 66 /* max number of VFs + a little */ 93#define I40E_AQ_WORK_LIMIT 66 /* max number of VFs + a little */
94#define I40E_MAX_USER_PRIORITY 8 94#define I40E_MAX_USER_PRIORITY 8
95#define I40E_DEFAULT_TRAFFIC_CLASS BIT(0)
95#define I40E_DEFAULT_MSG_ENABLE 4 96#define I40E_DEFAULT_MSG_ENABLE 4
96#define I40E_QUEUE_WAIT_RETRY_LIMIT 10 97#define I40E_QUEUE_WAIT_RETRY_LIMIT 10
97#define I40E_INT_NAME_STR_LEN (IFNAMSIZ + 16) 98#define I40E_INT_NAME_STR_LEN (IFNAMSIZ + 16)
diff --git a/drivers/net/ethernet/intel/i40e/i40e_main.c b/drivers/net/ethernet/intel/i40e/i40e_main.c
index ac1faee2a5b8..31c97e3937a4 100644
--- a/drivers/net/ethernet/intel/i40e/i40e_main.c
+++ b/drivers/net/ethernet/intel/i40e/i40e_main.c
@@ -4641,29 +4641,6 @@ static u8 i40e_pf_get_num_tc(struct i40e_pf *pf)
4641} 4641}
4642 4642
4643/** 4643/**
4644 * i40e_pf_get_default_tc - Get bitmap for first enabled TC
4645 * @pf: PF being queried
4646 *
4647 * Return a bitmap for first enabled traffic class for this PF.
4648 **/
4649static u8 i40e_pf_get_default_tc(struct i40e_pf *pf)
4650{
4651 u8 enabled_tc = pf->hw.func_caps.enabled_tcmap;
4652 u8 i = 0;
4653
4654 if (!enabled_tc)
4655 return 0x1; /* TC0 */
4656
4657 /* Find the first enabled TC */
4658 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
4659 if (enabled_tc & BIT(i))
4660 break;
4661 }
4662
4663 return BIT(i);
4664}
4665
4666/**
4667 * i40e_pf_get_pf_tc_map - Get bitmap for enabled traffic classes 4644 * i40e_pf_get_pf_tc_map - Get bitmap for enabled traffic classes
4668 * @pf: PF being queried 4645 * @pf: PF being queried
4669 * 4646 *
@@ -4673,7 +4650,7 @@ static u8 i40e_pf_get_tc_map(struct i40e_pf *pf)
4673{ 4650{
4674 /* If DCB is not enabled for this PF then just return default TC */ 4651 /* If DCB is not enabled for this PF then just return default TC */
4675 if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) 4652 if (!(pf->flags & I40E_FLAG_DCB_ENABLED))
4676 return i40e_pf_get_default_tc(pf); 4653 return I40E_DEFAULT_TRAFFIC_CLASS;
4677 4654
4678 /* SFP mode we want PF to be enabled for all TCs */ 4655 /* SFP mode we want PF to be enabled for all TCs */
4679 if (!(pf->flags & I40E_FLAG_MFP_ENABLED)) 4656 if (!(pf->flags & I40E_FLAG_MFP_ENABLED))
@@ -4683,7 +4660,7 @@ static u8 i40e_pf_get_tc_map(struct i40e_pf *pf)
4683 if (pf->hw.func_caps.iscsi) 4660 if (pf->hw.func_caps.iscsi)
4684 return i40e_get_iscsi_tc_map(pf); 4661 return i40e_get_iscsi_tc_map(pf);
4685 else 4662 else
4686 return i40e_pf_get_default_tc(pf); 4663 return I40E_DEFAULT_TRAFFIC_CLASS;
4687} 4664}
4688 4665
4689/** 4666/**
@@ -5029,7 +5006,7 @@ static void i40e_dcb_reconfigure(struct i40e_pf *pf)
5029 if (v == pf->lan_vsi) 5006 if (v == pf->lan_vsi)
5030 tc_map = i40e_pf_get_tc_map(pf); 5007 tc_map = i40e_pf_get_tc_map(pf);
5031 else 5008 else
5032 tc_map = i40e_pf_get_default_tc(pf); 5009 tc_map = I40E_DEFAULT_TRAFFIC_CLASS;
5033#ifdef I40E_FCOE 5010#ifdef I40E_FCOE
5034 if (pf->vsi[v]->type == I40E_VSI_FCOE) 5011 if (pf->vsi[v]->type == I40E_VSI_FCOE)
5035 tc_map = i40e_get_fcoe_tc_map(pf); 5012 tc_map = i40e_get_fcoe_tc_map(pf);
@@ -5717,7 +5694,7 @@ static int i40e_handle_lldp_event(struct i40e_pf *pf,
5717 u8 type; 5694 u8 type;
5718 5695
5719 /* Not DCB capable or capability disabled */ 5696 /* Not DCB capable or capability disabled */
5720 if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) 5697 if (!(pf->flags & I40E_FLAG_DCB_CAPABLE))
5721 return ret; 5698 return ret;
5722 5699
5723 /* Ignore if event is not for Nearest Bridge */ 5700 /* Ignore if event is not for Nearest Bridge */
@@ -7707,6 +7684,7 @@ static int i40e_init_msix(struct i40e_pf *pf)
7707 pf->flags &= ~I40E_FLAG_MSIX_ENABLED; 7684 pf->flags &= ~I40E_FLAG_MSIX_ENABLED;
7708 kfree(pf->msix_entries); 7685 kfree(pf->msix_entries);
7709 pf->msix_entries = NULL; 7686 pf->msix_entries = NULL;
7687 pci_disable_msix(pf->pdev);
7710 return -ENODEV; 7688 return -ENODEV;
7711 7689
7712 } else if (v_actual == I40E_MIN_MSIX) { 7690 } else if (v_actual == I40E_MIN_MSIX) {
@@ -9056,7 +9034,7 @@ static int i40e_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
9056 return 0; 9034 return 0;
9057 9035
9058 return ndo_dflt_bridge_getlink(skb, pid, seq, dev, veb->bridge_mode, 9036 return ndo_dflt_bridge_getlink(skb, pid, seq, dev, veb->bridge_mode,
9059 nlflags, 0, 0, filter_mask, NULL); 9037 0, 0, nlflags, filter_mask, NULL);
9060} 9038}
9061 9039
9062/* Hardware supports L4 tunnel length of 128B (=2^7) which includes 9040/* Hardware supports L4 tunnel length of 128B (=2^7) which includes
diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c
index edc9a6ac5169..9affd7c198bd 100644
--- a/drivers/net/ethernet/intel/igb/igb_main.c
+++ b/drivers/net/ethernet/intel/igb/igb_main.c
@@ -4931,11 +4931,15 @@ static int igb_tso(struct igb_ring *tx_ring,
4931 4931
4932 /* initialize outer IP header fields */ 4932 /* initialize outer IP header fields */
4933 if (ip.v4->version == 4) { 4933 if (ip.v4->version == 4) {
4934 unsigned char *csum_start = skb_checksum_start(skb);
4935 unsigned char *trans_start = ip.hdr + (ip.v4->ihl * 4);
4936
4934 /* IP header will have to cancel out any data that 4937 /* IP header will have to cancel out any data that
4935 * is not a part of the outer IP header 4938 * is not a part of the outer IP header
4936 */ 4939 */
4937 ip.v4->check = csum_fold(csum_add(lco_csum(skb), 4940 ip.v4->check = csum_fold(csum_partial(trans_start,
4938 csum_unfold(l4.tcp->check))); 4941 csum_start - trans_start,
4942 0));
4939 type_tucmd |= E1000_ADVTXD_TUCMD_IPV4; 4943 type_tucmd |= E1000_ADVTXD_TUCMD_IPV4;
4940 4944
4941 ip.v4->tot_len = 0; 4945 ip.v4->tot_len = 0;
diff --git a/drivers/net/ethernet/intel/igbvf/netdev.c b/drivers/net/ethernet/intel/igbvf/netdev.c
index 12bb877df860..7dff7f6239cd 100644
--- a/drivers/net/ethernet/intel/igbvf/netdev.c
+++ b/drivers/net/ethernet/intel/igbvf/netdev.c
@@ -1965,11 +1965,15 @@ static int igbvf_tso(struct igbvf_ring *tx_ring,
1965 1965
1966 /* initialize outer IP header fields */ 1966 /* initialize outer IP header fields */
1967 if (ip.v4->version == 4) { 1967 if (ip.v4->version == 4) {
1968 unsigned char *csum_start = skb_checksum_start(skb);
1969 unsigned char *trans_start = ip.hdr + (ip.v4->ihl * 4);
1970
1968 /* IP header will have to cancel out any data that 1971 /* IP header will have to cancel out any data that
1969 * is not a part of the outer IP header 1972 * is not a part of the outer IP header
1970 */ 1973 */
1971 ip.v4->check = csum_fold(csum_add(lco_csum(skb), 1974 ip.v4->check = csum_fold(csum_partial(trans_start,
1972 csum_unfold(l4.tcp->check))); 1975 csum_start - trans_start,
1976 0));
1973 type_tucmd |= E1000_ADVTXD_TUCMD_IPV4; 1977 type_tucmd |= E1000_ADVTXD_TUCMD_IPV4;
1974 1978
1975 ip.v4->tot_len = 0; 1979 ip.v4->tot_len = 0;
diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
index a244d9a67264..fee1f2918ead 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
@@ -7277,11 +7277,15 @@ static int ixgbe_tso(struct ixgbe_ring *tx_ring,
7277 7277
7278 /* initialize outer IP header fields */ 7278 /* initialize outer IP header fields */
7279 if (ip.v4->version == 4) { 7279 if (ip.v4->version == 4) {
7280 unsigned char *csum_start = skb_checksum_start(skb);
7281 unsigned char *trans_start = ip.hdr + (ip.v4->ihl * 4);
7282
7280 /* IP header will have to cancel out any data that 7283 /* IP header will have to cancel out any data that
7281 * is not a part of the outer IP header 7284 * is not a part of the outer IP header
7282 */ 7285 */
7283 ip.v4->check = csum_fold(csum_add(lco_csum(skb), 7286 ip.v4->check = csum_fold(csum_partial(trans_start,
7284 csum_unfold(l4.tcp->check))); 7287 csum_start - trans_start,
7288 0));
7285 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4; 7289 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
7286 7290
7287 ip.v4->tot_len = 0; 7291 ip.v4->tot_len = 0;
@@ -9135,10 +9139,14 @@ static void *ixgbe_fwd_add(struct net_device *pdev, struct net_device *vdev)
9135 goto fwd_add_err; 9139 goto fwd_add_err;
9136 fwd_adapter->pool = pool; 9140 fwd_adapter->pool = pool;
9137 fwd_adapter->real_adapter = adapter; 9141 fwd_adapter->real_adapter = adapter;
9138 err = ixgbe_fwd_ring_up(vdev, fwd_adapter); 9142
9139 if (err) 9143 if (netif_running(pdev)) {
9140 goto fwd_add_err; 9144 err = ixgbe_fwd_ring_up(vdev, fwd_adapter);
9141 netif_tx_start_all_queues(vdev); 9145 if (err)
9146 goto fwd_add_err;
9147 netif_tx_start_all_queues(vdev);
9148 }
9149
9142 return fwd_adapter; 9150 return fwd_adapter;
9143fwd_add_err: 9151fwd_add_err:
9144 /* unwind counter and free adapter struct */ 9152 /* unwind counter and free adapter struct */
diff --git a/drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c b/drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c
index 7eaac3234049..cbf70fe4028a 100644
--- a/drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c
+++ b/drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c
@@ -3329,11 +3329,15 @@ static int ixgbevf_tso(struct ixgbevf_ring *tx_ring,
3329 3329
3330 /* initialize outer IP header fields */ 3330 /* initialize outer IP header fields */
3331 if (ip.v4->version == 4) { 3331 if (ip.v4->version == 4) {
3332 unsigned char *csum_start = skb_checksum_start(skb);
3333 unsigned char *trans_start = ip.hdr + (ip.v4->ihl * 4);
3334
3332 /* IP header will have to cancel out any data that 3335 /* IP header will have to cancel out any data that
3333 * is not a part of the outer IP header 3336 * is not a part of the outer IP header
3334 */ 3337 */
3335 ip.v4->check = csum_fold(csum_add(lco_csum(skb), 3338 ip.v4->check = csum_fold(csum_partial(trans_start,
3336 csum_unfold(l4.tcp->check))); 3339 csum_start - trans_start,
3340 0));
3337 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4; 3341 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
3338 3342
3339 ip.v4->tot_len = 0; 3343 ip.v4->tot_len = 0;
diff --git a/drivers/net/ethernet/lantiq_etop.c b/drivers/net/ethernet/lantiq_etop.c
index 91e09d68b7e2..a167fd7ee13e 100644
--- a/drivers/net/ethernet/lantiq_etop.c
+++ b/drivers/net/ethernet/lantiq_etop.c
@@ -704,6 +704,7 @@ ltq_etop_probe(struct platform_device *pdev)
704 priv->pldata = dev_get_platdata(&pdev->dev); 704 priv->pldata = dev_get_platdata(&pdev->dev);
705 priv->netdev = dev; 705 priv->netdev = dev;
706 spin_lock_init(&priv->lock); 706 spin_lock_init(&priv->lock);
707 SET_NETDEV_DEV(dev, &pdev->dev);
707 708
708 for (i = 0; i < MAX_DMA_CHAN; i++) { 709 for (i = 0; i < MAX_DMA_CHAN; i++) {
709 if (IS_TX(i)) 710 if (IS_TX(i))
diff --git a/drivers/net/ethernet/marvell/mv643xx_eth.c b/drivers/net/ethernet/marvell/mv643xx_eth.c
index 55831188bc32..5b12022adf1f 100644
--- a/drivers/net/ethernet/marvell/mv643xx_eth.c
+++ b/drivers/net/ethernet/marvell/mv643xx_eth.c
@@ -1381,6 +1381,7 @@ static unsigned int get_rx_coal(struct mv643xx_eth_private *mp)
1381 temp = (val & 0x003fff00) >> 8; 1381 temp = (val & 0x003fff00) >> 8;
1382 1382
1383 temp *= 64000000; 1383 temp *= 64000000;
1384 temp += mp->t_clk / 2;
1384 do_div(temp, mp->t_clk); 1385 do_div(temp, mp->t_clk);
1385 1386
1386 return (unsigned int)temp; 1387 return (unsigned int)temp;
@@ -1417,6 +1418,7 @@ static unsigned int get_tx_coal(struct mv643xx_eth_private *mp)
1417 1418
1418 temp = (rdlp(mp, TX_FIFO_URGENT_THRESHOLD) & 0x3fff0) >> 4; 1419 temp = (rdlp(mp, TX_FIFO_URGENT_THRESHOLD) & 0x3fff0) >> 4;
1419 temp *= 64000000; 1420 temp *= 64000000;
1421 temp += mp->t_clk / 2;
1420 do_div(temp, mp->t_clk); 1422 do_div(temp, mp->t_clk);
1421 1423
1422 return (unsigned int)temp; 1424 return (unsigned int)temp;
@@ -2968,6 +2970,22 @@ static void set_params(struct mv643xx_eth_private *mp,
2968 mp->txq_count = pd->tx_queue_count ? : 1; 2970 mp->txq_count = pd->tx_queue_count ? : 1;
2969} 2971}
2970 2972
2973static int get_phy_mode(struct mv643xx_eth_private *mp)
2974{
2975 struct device *dev = mp->dev->dev.parent;
2976 int iface = -1;
2977
2978 if (dev->of_node)
2979 iface = of_get_phy_mode(dev->of_node);
2980
2981 /* Historical default if unspecified. We could also read/write
2982 * the interface state in the PSC1
2983 */
2984 if (iface < 0)
2985 iface = PHY_INTERFACE_MODE_GMII;
2986 return iface;
2987}
2988
2971static struct phy_device *phy_scan(struct mv643xx_eth_private *mp, 2989static struct phy_device *phy_scan(struct mv643xx_eth_private *mp,
2972 int phy_addr) 2990 int phy_addr)
2973{ 2991{
@@ -2994,7 +3012,7 @@ static struct phy_device *phy_scan(struct mv643xx_eth_private *mp,
2994 "orion-mdio-mii", addr); 3012 "orion-mdio-mii", addr);
2995 3013
2996 phydev = phy_connect(mp->dev, phy_id, mv643xx_eth_adjust_link, 3014 phydev = phy_connect(mp->dev, phy_id, mv643xx_eth_adjust_link,
2997 PHY_INTERFACE_MODE_GMII); 3015 get_phy_mode(mp));
2998 if (!IS_ERR(phydev)) { 3016 if (!IS_ERR(phydev)) {
2999 phy_addr_set(mp, addr); 3017 phy_addr_set(mp, addr);
3000 break; 3018 break;
@@ -3090,6 +3108,7 @@ static int mv643xx_eth_probe(struct platform_device *pdev)
3090 if (!dev) 3108 if (!dev)
3091 return -ENOMEM; 3109 return -ENOMEM;
3092 3110
3111 SET_NETDEV_DEV(dev, &pdev->dev);
3093 mp = netdev_priv(dev); 3112 mp = netdev_priv(dev);
3094 platform_set_drvdata(pdev, mp); 3113 platform_set_drvdata(pdev, mp);
3095 3114
@@ -3129,7 +3148,7 @@ static int mv643xx_eth_probe(struct platform_device *pdev)
3129 if (pd->phy_node) { 3148 if (pd->phy_node) {
3130 mp->phy = of_phy_connect(mp->dev, pd->phy_node, 3149 mp->phy = of_phy_connect(mp->dev, pd->phy_node,
3131 mv643xx_eth_adjust_link, 0, 3150 mv643xx_eth_adjust_link, 0,
3132 PHY_INTERFACE_MODE_GMII); 3151 get_phy_mode(mp));
3133 if (!mp->phy) 3152 if (!mp->phy)
3134 err = -ENODEV; 3153 err = -ENODEV;
3135 else 3154 else
@@ -3187,8 +3206,6 @@ static int mv643xx_eth_probe(struct platform_device *pdev)
3187 dev->priv_flags |= IFF_UNICAST_FLT; 3206 dev->priv_flags |= IFF_UNICAST_FLT;
3188 dev->gso_max_segs = MV643XX_MAX_TSO_SEGS; 3207 dev->gso_max_segs = MV643XX_MAX_TSO_SEGS;
3189 3208
3190 SET_NETDEV_DEV(dev, &pdev->dev);
3191
3192 if (mp->shared->win_protect) 3209 if (mp->shared->win_protect)
3193 wrl(mp, WINDOW_PROTECT(mp->port_num), mp->shared->win_protect); 3210 wrl(mp, WINDOW_PROTECT(mp->port_num), mp->shared->win_protect);
3194 3211
diff --git a/drivers/net/ethernet/marvell/mvneta.c b/drivers/net/ethernet/marvell/mvneta.c
index 5cb07c2017bf..707bc4680b9b 100644
--- a/drivers/net/ethernet/marvell/mvneta.c
+++ b/drivers/net/ethernet/marvell/mvneta.c
@@ -4151,7 +4151,7 @@ static int mvneta_probe(struct platform_device *pdev)
4151 dev->features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO; 4151 dev->features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO;
4152 dev->hw_features |= dev->features; 4152 dev->hw_features |= dev->features;
4153 dev->vlan_features |= dev->features; 4153 dev->vlan_features |= dev->features;
4154 dev->priv_flags |= IFF_UNICAST_FLT | IFF_LIVE_ADDR_CHANGE; 4154 dev->priv_flags |= IFF_LIVE_ADDR_CHANGE;
4155 dev->gso_max_segs = MVNETA_MAX_TSO_SEGS; 4155 dev->gso_max_segs = MVNETA_MAX_TSO_SEGS;
4156 4156
4157 err = register_netdev(dev); 4157 err = register_netdev(dev);
@@ -4191,6 +4191,8 @@ err_clk:
4191 clk_disable_unprepare(pp->clk); 4191 clk_disable_unprepare(pp->clk);
4192err_put_phy_node: 4192err_put_phy_node:
4193 of_node_put(phy_node); 4193 of_node_put(phy_node);
4194 if (of_phy_is_fixed_link(dn))
4195 of_phy_deregister_fixed_link(dn);
4194err_free_irq: 4196err_free_irq:
4195 irq_dispose_mapping(dev->irq); 4197 irq_dispose_mapping(dev->irq);
4196err_free_netdev: 4198err_free_netdev:
@@ -4202,6 +4204,7 @@ err_free_netdev:
4202static int mvneta_remove(struct platform_device *pdev) 4204static int mvneta_remove(struct platform_device *pdev)
4203{ 4205{
4204 struct net_device *dev = platform_get_drvdata(pdev); 4206 struct net_device *dev = platform_get_drvdata(pdev);
4207 struct device_node *dn = pdev->dev.of_node;
4205 struct mvneta_port *pp = netdev_priv(dev); 4208 struct mvneta_port *pp = netdev_priv(dev);
4206 4209
4207 unregister_netdev(dev); 4210 unregister_netdev(dev);
@@ -4209,6 +4212,8 @@ static int mvneta_remove(struct platform_device *pdev)
4209 clk_disable_unprepare(pp->clk); 4212 clk_disable_unprepare(pp->clk);
4210 free_percpu(pp->ports); 4213 free_percpu(pp->ports);
4211 free_percpu(pp->stats); 4214 free_percpu(pp->stats);
4215 if (of_phy_is_fixed_link(dn))
4216 of_phy_deregister_fixed_link(dn);
4212 irq_dispose_mapping(dev->irq); 4217 irq_dispose_mapping(dev->irq);
4213 of_node_put(pp->phy_node); 4218 of_node_put(pp->phy_node);
4214 free_netdev(dev); 4219 free_netdev(dev);
diff --git a/drivers/net/ethernet/marvell/mvpp2.c b/drivers/net/ethernet/marvell/mvpp2.c
index 60227a3452a4..1026c452e39d 100644
--- a/drivers/net/ethernet/marvell/mvpp2.c
+++ b/drivers/net/ethernet/marvell/mvpp2.c
@@ -3293,7 +3293,7 @@ static void mvpp2_cls_init(struct mvpp2 *priv)
3293 mvpp2_write(priv, MVPP2_CLS_MODE_REG, MVPP2_CLS_MODE_ACTIVE_MASK); 3293 mvpp2_write(priv, MVPP2_CLS_MODE_REG, MVPP2_CLS_MODE_ACTIVE_MASK);
3294 3294
3295 /* Clear classifier flow table */ 3295 /* Clear classifier flow table */
3296 memset(&fe.data, 0, MVPP2_CLS_FLOWS_TBL_DATA_WORDS); 3296 memset(&fe.data, 0, sizeof(fe.data));
3297 for (index = 0; index < MVPP2_CLS_FLOWS_TBL_SIZE; index++) { 3297 for (index = 0; index < MVPP2_CLS_FLOWS_TBL_SIZE; index++) {
3298 fe.index = index; 3298 fe.index = index;
3299 mvpp2_cls_flow_write(priv, &fe); 3299 mvpp2_cls_flow_write(priv, &fe);
diff --git a/drivers/net/ethernet/marvell/sky2.c b/drivers/net/ethernet/marvell/sky2.c
index f05ea56dcff2..941c8e2c944e 100644
--- a/drivers/net/ethernet/marvell/sky2.c
+++ b/drivers/net/ethernet/marvell/sky2.c
@@ -5220,6 +5220,19 @@ static SIMPLE_DEV_PM_OPS(sky2_pm_ops, sky2_suspend, sky2_resume);
5220 5220
5221static void sky2_shutdown(struct pci_dev *pdev) 5221static void sky2_shutdown(struct pci_dev *pdev)
5222{ 5222{
5223 struct sky2_hw *hw = pci_get_drvdata(pdev);
5224 int port;
5225
5226 for (port = 0; port < hw->ports; port++) {
5227 struct net_device *ndev = hw->dev[port];
5228
5229 rtnl_lock();
5230 if (netif_running(ndev)) {
5231 dev_close(ndev);
5232 netif_device_detach(ndev);
5233 }
5234 rtnl_unlock();
5235 }
5223 sky2_suspend(&pdev->dev); 5236 sky2_suspend(&pdev->dev);
5224 pci_wake_from_d3(pdev, device_may_wakeup(&pdev->dev)); 5237 pci_wake_from_d3(pdev, device_may_wakeup(&pdev->dev));
5225 pci_set_power_state(pdev, PCI_D3hot); 5238 pci_set_power_state(pdev, PCI_D3hot);
diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
index 4a62ffd7729d..86a89cbd3ec9 100644
--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
@@ -318,6 +318,8 @@ static int mtk_phy_connect(struct net_device *dev)
318 return 0; 318 return 0;
319 319
320err_phy: 320err_phy:
321 if (of_phy_is_fixed_link(mac->of_node))
322 of_phy_deregister_fixed_link(mac->of_node);
321 of_node_put(np); 323 of_node_put(np);
322 dev_err(eth->dev, "%s: invalid phy\n", __func__); 324 dev_err(eth->dev, "%s: invalid phy\n", __func__);
323 return -EINVAL; 325 return -EINVAL;
@@ -1923,6 +1925,8 @@ static void mtk_uninit(struct net_device *dev)
1923 struct mtk_eth *eth = mac->hw; 1925 struct mtk_eth *eth = mac->hw;
1924 1926
1925 phy_disconnect(dev->phydev); 1927 phy_disconnect(dev->phydev);
1928 if (of_phy_is_fixed_link(mac->of_node))
1929 of_phy_deregister_fixed_link(mac->of_node);
1926 mtk_irq_disable(eth, MTK_QDMA_INT_MASK, ~0); 1930 mtk_irq_disable(eth, MTK_QDMA_INT_MASK, ~0);
1927 mtk_irq_disable(eth, MTK_PDMA_INT_MASK, ~0); 1931 mtk_irq_disable(eth, MTK_PDMA_INT_MASK, ~0);
1928} 1932}
diff --git a/drivers/net/ethernet/mellanox/mlx4/cmd.c b/drivers/net/ethernet/mellanox/mlx4/cmd.c
index b1cef7a0f7ca..e36bebcab3f2 100644
--- a/drivers/net/ethernet/mellanox/mlx4/cmd.c
+++ b/drivers/net/ethernet/mellanox/mlx4/cmd.c
@@ -2469,6 +2469,7 @@ err_comm_admin:
2469 kfree(priv->mfunc.master.slave_state); 2469 kfree(priv->mfunc.master.slave_state);
2470err_comm: 2470err_comm:
2471 iounmap(priv->mfunc.comm); 2471 iounmap(priv->mfunc.comm);
2472 priv->mfunc.comm = NULL;
2472err_vhcr: 2473err_vhcr:
2473 dma_free_coherent(&dev->persist->pdev->dev, PAGE_SIZE, 2474 dma_free_coherent(&dev->persist->pdev->dev, PAGE_SIZE,
2474 priv->mfunc.vhcr, 2475 priv->mfunc.vhcr,
@@ -2537,6 +2538,13 @@ void mlx4_report_internal_err_comm_event(struct mlx4_dev *dev)
2537 int slave; 2538 int slave;
2538 u32 slave_read; 2539 u32 slave_read;
2539 2540
2541 /* If the comm channel has not yet been initialized,
2542 * skip reporting the internal error event to all
2543 * the communication channels.
2544 */
2545 if (!priv->mfunc.comm)
2546 return;
2547
2540 /* Report an internal error event to all 2548 /* Report an internal error event to all
2541 * communication channels. 2549 * communication channels.
2542 */ 2550 */
@@ -2571,6 +2579,7 @@ void mlx4_multi_func_cleanup(struct mlx4_dev *dev)
2571 } 2579 }
2572 2580
2573 iounmap(priv->mfunc.comm); 2581 iounmap(priv->mfunc.comm);
2582 priv->mfunc.comm = NULL;
2574} 2583}
2575 2584
2576void mlx4_cmd_cleanup(struct mlx4_dev *dev, int cleanup_mask) 2585void mlx4_cmd_cleanup(struct mlx4_dev *dev, int cleanup_mask)
diff --git a/drivers/net/ethernet/mellanox/mlx4/en_clock.c b/drivers/net/ethernet/mellanox/mlx4/en_clock.c
index 08fc5fc56d43..a5fc46bbcbe2 100644
--- a/drivers/net/ethernet/mellanox/mlx4/en_clock.c
+++ b/drivers/net/ethernet/mellanox/mlx4/en_clock.c
@@ -245,8 +245,11 @@ static u32 freq_to_shift(u16 freq)
245{ 245{
246 u32 freq_khz = freq * 1000; 246 u32 freq_khz = freq * 1000;
247 u64 max_val_cycles = freq_khz * 1000 * MLX4_EN_WRAP_AROUND_SEC; 247 u64 max_val_cycles = freq_khz * 1000 * MLX4_EN_WRAP_AROUND_SEC;
248 u64 tmp_rounded =
249 roundup_pow_of_two(max_val_cycles) > max_val_cycles ?
250 roundup_pow_of_two(max_val_cycles) - 1 : UINT_MAX;
248 u64 max_val_cycles_rounded = is_power_of_2(max_val_cycles + 1) ? 251 u64 max_val_cycles_rounded = is_power_of_2(max_val_cycles + 1) ?
249 max_val_cycles : roundup_pow_of_two(max_val_cycles) - 1; 252 max_val_cycles : tmp_rounded;
250 /* calculate max possible multiplier in order to fit in 64bit */ 253 /* calculate max possible multiplier in order to fit in 64bit */
251 u64 max_mul = div_u64(0xffffffffffffffffULL, max_val_cycles_rounded); 254 u64 max_mul = div_u64(0xffffffffffffffffULL, max_val_cycles_rounded);
252 255
diff --git a/drivers/net/ethernet/mellanox/mlx4/en_cq.c b/drivers/net/ethernet/mellanox/mlx4/en_cq.c
index 132cea655920..e3be7e44ff51 100644
--- a/drivers/net/ethernet/mellanox/mlx4/en_cq.c
+++ b/drivers/net/ethernet/mellanox/mlx4/en_cq.c
@@ -127,7 +127,15 @@ int mlx4_en_activate_cq(struct mlx4_en_priv *priv, struct mlx4_en_cq *cq,
127 /* For TX we use the same irq per 127 /* For TX we use the same irq per
128 ring we assigned for the RX */ 128 ring we assigned for the RX */
129 struct mlx4_en_cq *rx_cq; 129 struct mlx4_en_cq *rx_cq;
130 130 int xdp_index;
131
132 /* The xdp tx irq must align with the rx ring that forwards to
133 * it, so reindex these from 0. This should only happen when
134 * tx_ring_num is not a multiple of rx_ring_num.
135 */
136 xdp_index = (priv->xdp_ring_num - priv->tx_ring_num) + cq_idx;
137 if (xdp_index >= 0)
138 cq_idx = xdp_index;
131 cq_idx = cq_idx % priv->rx_ring_num; 139 cq_idx = cq_idx % priv->rx_ring_num;
132 rx_cq = priv->rx_cq[cq_idx]; 140 rx_cq = priv->rx_cq[cq_idx];
133 cq->vector = rx_cq->vector; 141 cq->vector = rx_cq->vector;
diff --git a/drivers/net/ethernet/mellanox/mlx4/en_netdev.c b/drivers/net/ethernet/mellanox/mlx4/en_netdev.c
index 7e703bed7b82..fb8bb027b69c 100644
--- a/drivers/net/ethernet/mellanox/mlx4/en_netdev.c
+++ b/drivers/net/ethernet/mellanox/mlx4/en_netdev.c
@@ -129,6 +129,9 @@ static enum mlx4_net_trans_rule_id mlx4_ip_proto_to_trans_rule_id(u8 ip_proto)
129 } 129 }
130}; 130};
131 131
132/* Must not acquire state_lock, as its corresponding work_sync
133 * is done under it.
134 */
132static void mlx4_en_filter_work(struct work_struct *work) 135static void mlx4_en_filter_work(struct work_struct *work)
133{ 136{
134 struct mlx4_en_filter *filter = container_of(work, 137 struct mlx4_en_filter *filter = container_of(work,
@@ -1733,6 +1736,13 @@ int mlx4_en_start_port(struct net_device *dev)
1733 udp_tunnel_get_rx_info(dev); 1736 udp_tunnel_get_rx_info(dev);
1734 1737
1735 priv->port_up = true; 1738 priv->port_up = true;
1739
1740 /* Process all completions if exist to prevent
1741 * the queues freezing if they are full
1742 */
1743 for (i = 0; i < priv->rx_ring_num; i++)
1744 napi_schedule(&priv->rx_cq[i]->napi);
1745
1736 netif_tx_start_all_queues(dev); 1746 netif_tx_start_all_queues(dev);
1737 netif_device_attach(dev); 1747 netif_device_attach(dev);
1738 1748
@@ -1910,8 +1920,9 @@ static void mlx4_en_clear_stats(struct net_device *dev)
1910 struct mlx4_en_dev *mdev = priv->mdev; 1920 struct mlx4_en_dev *mdev = priv->mdev;
1911 int i; 1921 int i;
1912 1922
1913 if (mlx4_en_DUMP_ETH_STATS(mdev, priv->port, 1)) 1923 if (!mlx4_is_slave(mdev->dev))
1914 en_dbg(HW, priv, "Failed dumping statistics\n"); 1924 if (mlx4_en_DUMP_ETH_STATS(mdev, priv->port, 1))
1925 en_dbg(HW, priv, "Failed dumping statistics\n");
1915 1926
1916 memset(&priv->pstats, 0, sizeof(priv->pstats)); 1927 memset(&priv->pstats, 0, sizeof(priv->pstats));
1917 memset(&priv->pkstats, 0, sizeof(priv->pkstats)); 1928 memset(&priv->pkstats, 0, sizeof(priv->pkstats));
@@ -2068,13 +2079,6 @@ err:
2068 return -ENOMEM; 2079 return -ENOMEM;
2069} 2080}
2070 2081
2071static void mlx4_en_shutdown(struct net_device *dev)
2072{
2073 rtnl_lock();
2074 netif_device_detach(dev);
2075 mlx4_en_close(dev);
2076 rtnl_unlock();
2077}
2078 2082
2079static int mlx4_en_copy_priv(struct mlx4_en_priv *dst, 2083static int mlx4_en_copy_priv(struct mlx4_en_priv *dst,
2080 struct mlx4_en_priv *src, 2084 struct mlx4_en_priv *src,
@@ -2151,8 +2155,6 @@ void mlx4_en_destroy_netdev(struct net_device *dev)
2151{ 2155{
2152 struct mlx4_en_priv *priv = netdev_priv(dev); 2156 struct mlx4_en_priv *priv = netdev_priv(dev);
2153 struct mlx4_en_dev *mdev = priv->mdev; 2157 struct mlx4_en_dev *mdev = priv->mdev;
2154 bool shutdown = mdev->dev->persist->interface_state &
2155 MLX4_INTERFACE_STATE_SHUTDOWN;
2156 2158
2157 en_dbg(DRV, priv, "Destroying netdev on port:%d\n", priv->port); 2159 en_dbg(DRV, priv, "Destroying netdev on port:%d\n", priv->port);
2158 2160
@@ -2160,10 +2162,7 @@ void mlx4_en_destroy_netdev(struct net_device *dev)
2160 if (priv->registered) { 2162 if (priv->registered) {
2161 devlink_port_type_clear(mlx4_get_devlink_port(mdev->dev, 2163 devlink_port_type_clear(mlx4_get_devlink_port(mdev->dev,
2162 priv->port)); 2164 priv->port));
2163 if (shutdown) 2165 unregister_netdev(dev);
2164 mlx4_en_shutdown(dev);
2165 else
2166 unregister_netdev(dev);
2167 } 2166 }
2168 2167
2169 if (priv->allocated) 2168 if (priv->allocated)
@@ -2181,19 +2180,18 @@ void mlx4_en_destroy_netdev(struct net_device *dev)
2181 mutex_lock(&mdev->state_lock); 2180 mutex_lock(&mdev->state_lock);
2182 mdev->pndev[priv->port] = NULL; 2181 mdev->pndev[priv->port] = NULL;
2183 mdev->upper[priv->port] = NULL; 2182 mdev->upper[priv->port] = NULL;
2184 mutex_unlock(&mdev->state_lock);
2185 2183
2186#ifdef CONFIG_RFS_ACCEL 2184#ifdef CONFIG_RFS_ACCEL
2187 mlx4_en_cleanup_filters(priv); 2185 mlx4_en_cleanup_filters(priv);
2188#endif 2186#endif
2189 2187
2190 mlx4_en_free_resources(priv); 2188 mlx4_en_free_resources(priv);
2189 mutex_unlock(&mdev->state_lock);
2191 2190
2192 kfree(priv->tx_ring); 2191 kfree(priv->tx_ring);
2193 kfree(priv->tx_cq); 2192 kfree(priv->tx_cq);
2194 2193
2195 if (!shutdown) 2194 free_netdev(dev);
2196 free_netdev(dev);
2197} 2195}
2198 2196
2199static int mlx4_en_change_mtu(struct net_device *dev, int new_mtu) 2197static int mlx4_en_change_mtu(struct net_device *dev, int new_mtu)
diff --git a/drivers/net/ethernet/mellanox/mlx4/en_port.c b/drivers/net/ethernet/mellanox/mlx4/en_port.c
index 5aa8b751f417..59473a0ebcdf 100644
--- a/drivers/net/ethernet/mellanox/mlx4/en_port.c
+++ b/drivers/net/ethernet/mellanox/mlx4/en_port.c
@@ -166,7 +166,7 @@ int mlx4_en_DUMP_ETH_STATS(struct mlx4_en_dev *mdev, u8 port, u8 reset)
166 return PTR_ERR(mailbox); 166 return PTR_ERR(mailbox);
167 err = mlx4_cmd_box(mdev->dev, 0, mailbox->dma, in_mod, 0, 167 err = mlx4_cmd_box(mdev->dev, 0, mailbox->dma, in_mod, 0,
168 MLX4_CMD_DUMP_ETH_STATS, MLX4_CMD_TIME_CLASS_B, 168 MLX4_CMD_DUMP_ETH_STATS, MLX4_CMD_TIME_CLASS_B,
169 MLX4_CMD_WRAPPED); 169 MLX4_CMD_NATIVE);
170 if (err) 170 if (err)
171 goto out; 171 goto out;
172 172
@@ -322,7 +322,7 @@ int mlx4_en_DUMP_ETH_STATS(struct mlx4_en_dev *mdev, u8 port, u8 reset)
322 err = mlx4_cmd_box(mdev->dev, 0, mailbox->dma, 322 err = mlx4_cmd_box(mdev->dev, 0, mailbox->dma,
323 in_mod | MLX4_DUMP_ETH_STATS_FLOW_CONTROL, 323 in_mod | MLX4_DUMP_ETH_STATS_FLOW_CONTROL,
324 0, MLX4_CMD_DUMP_ETH_STATS, 324 0, MLX4_CMD_DUMP_ETH_STATS,
325 MLX4_CMD_TIME_CLASS_B, MLX4_CMD_WRAPPED); 325 MLX4_CMD_TIME_CLASS_B, MLX4_CMD_NATIVE);
326 if (err) 326 if (err)
327 goto out; 327 goto out;
328 } 328 }
diff --git a/drivers/net/ethernet/mellanox/mlx4/en_selftest.c b/drivers/net/ethernet/mellanox/mlx4/en_selftest.c
index b66e03d9711f..c06346a82496 100644
--- a/drivers/net/ethernet/mellanox/mlx4/en_selftest.c
+++ b/drivers/net/ethernet/mellanox/mlx4/en_selftest.c
@@ -118,6 +118,29 @@ mlx4_en_test_loopback_exit:
118 return !loopback_ok; 118 return !loopback_ok;
119} 119}
120 120
121static int mlx4_en_test_interrupts(struct mlx4_en_priv *priv)
122{
123 struct mlx4_en_dev *mdev = priv->mdev;
124 int err = 0;
125 int i = 0;
126
127 err = mlx4_test_async(mdev->dev);
128 /* When not in MSI_X or slave, test only async */
129 if (!(mdev->dev->flags & MLX4_FLAG_MSI_X) || mlx4_is_slave(mdev->dev))
130 return err;
131
132 /* A loop over all completion vectors of current port,
133 * for each vector check whether it works by mapping command
134 * completions to that vector and performing a NOP command
135 */
136 for (i = 0; i < priv->rx_ring_num; i++) {
137 err = mlx4_test_interrupt(mdev->dev, priv->rx_cq[i]->vector);
138 if (err)
139 break;
140 }
141
142 return err;
143}
121 144
122static int mlx4_en_test_link(struct mlx4_en_priv *priv) 145static int mlx4_en_test_link(struct mlx4_en_priv *priv)
123{ 146{
@@ -151,7 +174,6 @@ static int mlx4_en_test_speed(struct mlx4_en_priv *priv)
151void mlx4_en_ex_selftest(struct net_device *dev, u32 *flags, u64 *buf) 174void mlx4_en_ex_selftest(struct net_device *dev, u32 *flags, u64 *buf)
152{ 175{
153 struct mlx4_en_priv *priv = netdev_priv(dev); 176 struct mlx4_en_priv *priv = netdev_priv(dev);
154 struct mlx4_en_dev *mdev = priv->mdev;
155 int i, carrier_ok; 177 int i, carrier_ok;
156 178
157 memset(buf, 0, sizeof(u64) * MLX4_EN_NUM_SELF_TEST); 179 memset(buf, 0, sizeof(u64) * MLX4_EN_NUM_SELF_TEST);
@@ -177,7 +199,7 @@ void mlx4_en_ex_selftest(struct net_device *dev, u32 *flags, u64 *buf)
177 netif_carrier_on(dev); 199 netif_carrier_on(dev);
178 200
179 } 201 }
180 buf[0] = mlx4_test_interrupts(mdev->dev); 202 buf[0] = mlx4_en_test_interrupts(priv);
181 buf[1] = mlx4_en_test_link(priv); 203 buf[1] = mlx4_en_test_link(priv);
182 buf[2] = mlx4_en_test_speed(priv); 204 buf[2] = mlx4_en_test_speed(priv);
183 205
diff --git a/drivers/net/ethernet/mellanox/mlx4/eq.c b/drivers/net/ethernet/mellanox/mlx4/eq.c
index cf8f8a72a801..cd3638e6fe25 100644
--- a/drivers/net/ethernet/mellanox/mlx4/eq.c
+++ b/drivers/net/ethernet/mellanox/mlx4/eq.c
@@ -1361,53 +1361,49 @@ void mlx4_cleanup_eq_table(struct mlx4_dev *dev)
1361 kfree(priv->eq_table.uar_map); 1361 kfree(priv->eq_table.uar_map);
1362} 1362}
1363 1363
1364/* A test that verifies that we can accept interrupts on all 1364/* A test that verifies that we can accept interrupts
1365 * the irq vectors of the device. 1365 * on the vector allocated for asynchronous events
1366 */
1367int mlx4_test_async(struct mlx4_dev *dev)
1368{
1369 return mlx4_NOP(dev);
1370}
1371EXPORT_SYMBOL(mlx4_test_async);
1372
1373/* A test that verifies that we can accept interrupts
1374 * on the given irq vector of the tested port.
1366 * Interrupts are checked using the NOP command. 1375 * Interrupts are checked using the NOP command.
1367 */ 1376 */
1368int mlx4_test_interrupts(struct mlx4_dev *dev) 1377int mlx4_test_interrupt(struct mlx4_dev *dev, int vector)
1369{ 1378{
1370 struct mlx4_priv *priv = mlx4_priv(dev); 1379 struct mlx4_priv *priv = mlx4_priv(dev);
1371 int i;
1372 int err; 1380 int err;
1373 1381
1374 err = mlx4_NOP(dev); 1382 /* Temporary use polling for command completions */
1375 /* When not in MSI_X, there is only one irq to check */ 1383 mlx4_cmd_use_polling(dev);
1376 if (!(dev->flags & MLX4_FLAG_MSI_X) || mlx4_is_slave(dev))
1377 return err;
1378
1379 /* A loop over all completion vectors, for each vector we will check
1380 * whether it works by mapping command completions to that vector
1381 * and performing a NOP command
1382 */
1383 for(i = 0; !err && (i < dev->caps.num_comp_vectors); ++i) {
1384 /* Make sure request_irq was called */
1385 if (!priv->eq_table.eq[i].have_irq)
1386 continue;
1387
1388 /* Temporary use polling for command completions */
1389 mlx4_cmd_use_polling(dev);
1390
1391 /* Map the new eq to handle all asynchronous events */
1392 err = mlx4_MAP_EQ(dev, get_async_ev_mask(dev), 0,
1393 priv->eq_table.eq[i].eqn);
1394 if (err) {
1395 mlx4_warn(dev, "Failed mapping eq for interrupt test\n");
1396 mlx4_cmd_use_events(dev);
1397 break;
1398 }
1399 1384
1400 /* Go back to using events */ 1385 /* Map the new eq to handle all asynchronous events */
1401 mlx4_cmd_use_events(dev); 1386 err = mlx4_MAP_EQ(dev, get_async_ev_mask(dev), 0,
1402 err = mlx4_NOP(dev); 1387 priv->eq_table.eq[MLX4_CQ_TO_EQ_VECTOR(vector)].eqn);
1388 if (err) {
1389 mlx4_warn(dev, "Failed mapping eq for interrupt test\n");
1390 goto out;
1403 } 1391 }
1404 1392
1393 /* Go back to using events */
1394 mlx4_cmd_use_events(dev);
1395 err = mlx4_NOP(dev);
1396
1405 /* Return to default */ 1397 /* Return to default */
1398 mlx4_cmd_use_polling(dev);
1399out:
1406 mlx4_MAP_EQ(dev, get_async_ev_mask(dev), 0, 1400 mlx4_MAP_EQ(dev, get_async_ev_mask(dev), 0,
1407 priv->eq_table.eq[MLX4_EQ_ASYNC].eqn); 1401 priv->eq_table.eq[MLX4_EQ_ASYNC].eqn);
1402 mlx4_cmd_use_events(dev);
1403
1408 return err; 1404 return err;
1409} 1405}
1410EXPORT_SYMBOL(mlx4_test_interrupts); 1406EXPORT_SYMBOL(mlx4_test_interrupt);
1411 1407
1412bool mlx4_is_eq_vector_valid(struct mlx4_dev *dev, u8 port, int vector) 1408bool mlx4_is_eq_vector_valid(struct mlx4_dev *dev, u8 port, int vector)
1413{ 1409{
diff --git a/drivers/net/ethernet/mellanox/mlx4/fw.c b/drivers/net/ethernet/mellanox/mlx4/fw.c
index c41ab31a39f8..84bab9f0732e 100644
--- a/drivers/net/ethernet/mellanox/mlx4/fw.c
+++ b/drivers/net/ethernet/mellanox/mlx4/fw.c
@@ -49,9 +49,9 @@ enum {
49extern void __buggy_use_of_MLX4_GET(void); 49extern void __buggy_use_of_MLX4_GET(void);
50extern void __buggy_use_of_MLX4_PUT(void); 50extern void __buggy_use_of_MLX4_PUT(void);
51 51
52static bool enable_qos = true; 52static bool enable_qos;
53module_param(enable_qos, bool, 0444); 53module_param(enable_qos, bool, 0444);
54MODULE_PARM_DESC(enable_qos, "Enable Enhanced QoS support (default: on)"); 54MODULE_PARM_DESC(enable_qos, "Enable Enhanced QoS support (default: off)");
55 55
56#define MLX4_GET(dest, source, offset) \ 56#define MLX4_GET(dest, source, offset) \
57 do { \ 57 do { \
diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c b/drivers/net/ethernet/mellanox/mlx4/main.c
index 7183ac4135d2..75d07fa9d0b1 100644
--- a/drivers/net/ethernet/mellanox/mlx4/main.c
+++ b/drivers/net/ethernet/mellanox/mlx4/main.c
@@ -1102,6 +1102,14 @@ static int __set_port_type(struct mlx4_port_info *info,
1102 int i; 1102 int i;
1103 int err = 0; 1103 int err = 0;
1104 1104
1105 if ((port_type & mdev->caps.supported_type[info->port]) != port_type) {
1106 mlx4_err(mdev,
1107 "Requested port type for port %d is not supported on this HCA\n",
1108 info->port);
1109 err = -EINVAL;
1110 goto err_sup;
1111 }
1112
1105 mlx4_stop_sense(mdev); 1113 mlx4_stop_sense(mdev);
1106 mutex_lock(&priv->port_mutex); 1114 mutex_lock(&priv->port_mutex);
1107 info->tmp_type = port_type; 1115 info->tmp_type = port_type;
@@ -1147,7 +1155,7 @@ static int __set_port_type(struct mlx4_port_info *info,
1147out: 1155out:
1148 mlx4_start_sense(mdev); 1156 mlx4_start_sense(mdev);
1149 mutex_unlock(&priv->port_mutex); 1157 mutex_unlock(&priv->port_mutex);
1150 1158err_sup:
1151 return err; 1159 return err;
1152} 1160}
1153 1161
@@ -4139,11 +4147,8 @@ static void mlx4_shutdown(struct pci_dev *pdev)
4139 4147
4140 mlx4_info(persist->dev, "mlx4_shutdown was called\n"); 4148 mlx4_info(persist->dev, "mlx4_shutdown was called\n");
4141 mutex_lock(&persist->interface_state_mutex); 4149 mutex_lock(&persist->interface_state_mutex);
4142 if (persist->interface_state & MLX4_INTERFACE_STATE_UP) { 4150 if (persist->interface_state & MLX4_INTERFACE_STATE_UP)
4143 /* Notify mlx4 clients that the kernel is being shut down */
4144 persist->interface_state |= MLX4_INTERFACE_STATE_SHUTDOWN;
4145 mlx4_unload_one(pdev); 4151 mlx4_unload_one(pdev);
4146 }
4147 mutex_unlock(&persist->interface_state_mutex); 4152 mutex_unlock(&persist->interface_state_mutex);
4148} 4153}
4149 4154
diff --git a/drivers/net/ethernet/mellanox/mlx4/mcg.c b/drivers/net/ethernet/mellanox/mlx4/mcg.c
index 94b891c118c1..1a670b681555 100644
--- a/drivers/net/ethernet/mellanox/mlx4/mcg.c
+++ b/drivers/net/ethernet/mellanox/mlx4/mcg.c
@@ -1457,7 +1457,12 @@ EXPORT_SYMBOL_GPL(mlx4_multicast_detach);
1457int mlx4_flow_steer_promisc_add(struct mlx4_dev *dev, u8 port, 1457int mlx4_flow_steer_promisc_add(struct mlx4_dev *dev, u8 port,
1458 u32 qpn, enum mlx4_net_trans_promisc_mode mode) 1458 u32 qpn, enum mlx4_net_trans_promisc_mode mode)
1459{ 1459{
1460 struct mlx4_net_trans_rule rule; 1460 struct mlx4_net_trans_rule rule = {
1461 .queue_mode = MLX4_NET_TRANS_Q_FIFO,
1462 .exclusive = 0,
1463 .allow_loopback = 1,
1464 };
1465
1461 u64 *regid_p; 1466 u64 *regid_p;
1462 1467
1463 switch (mode) { 1468 switch (mode) {
diff --git a/drivers/net/ethernet/mellanox/mlx4/mlx4.h b/drivers/net/ethernet/mellanox/mlx4/mlx4.h
index e4878f31e45d..88ee7d8a5923 100644
--- a/drivers/net/ethernet/mellanox/mlx4/mlx4.h
+++ b/drivers/net/ethernet/mellanox/mlx4/mlx4.h
@@ -145,9 +145,10 @@ enum mlx4_resource {
145 RES_MTT, 145 RES_MTT,
146 RES_MAC, 146 RES_MAC,
147 RES_VLAN, 147 RES_VLAN,
148 RES_EQ, 148 RES_NPORT_ID,
149 RES_COUNTER, 149 RES_COUNTER,
150 RES_FS_RULE, 150 RES_FS_RULE,
151 RES_EQ,
151 MLX4_NUM_OF_RESOURCE_TYPE 152 MLX4_NUM_OF_RESOURCE_TYPE
152}; 153};
153 154
@@ -1329,8 +1330,6 @@ int mlx4_SET_VLAN_FLTR_wrapper(struct mlx4_dev *dev, int slave,
1329 struct mlx4_cmd_info *cmd); 1330 struct mlx4_cmd_info *cmd);
1330int mlx4_common_set_vlan_fltr(struct mlx4_dev *dev, int function, 1331int mlx4_common_set_vlan_fltr(struct mlx4_dev *dev, int function,
1331 int port, void *buf); 1332 int port, void *buf);
1332int mlx4_common_dump_eth_stats(struct mlx4_dev *dev, int slave, u32 in_mod,
1333 struct mlx4_cmd_mailbox *outbox);
1334int mlx4_DUMP_ETH_STATS_wrapper(struct mlx4_dev *dev, int slave, 1333int mlx4_DUMP_ETH_STATS_wrapper(struct mlx4_dev *dev, int slave,
1335 struct mlx4_vhcr *vhcr, 1334 struct mlx4_vhcr *vhcr,
1336 struct mlx4_cmd_mailbox *inbox, 1335 struct mlx4_cmd_mailbox *inbox,
diff --git a/drivers/net/ethernet/mellanox/mlx4/port.c b/drivers/net/ethernet/mellanox/mlx4/port.c
index c5b2064297a1..b656dd5772e5 100644
--- a/drivers/net/ethernet/mellanox/mlx4/port.c
+++ b/drivers/net/ethernet/mellanox/mlx4/port.c
@@ -1728,24 +1728,13 @@ int mlx4_SET_VLAN_FLTR_wrapper(struct mlx4_dev *dev, int slave,
1728 return err; 1728 return err;
1729} 1729}
1730 1730
1731int mlx4_common_dump_eth_stats(struct mlx4_dev *dev, int slave,
1732 u32 in_mod, struct mlx4_cmd_mailbox *outbox)
1733{
1734 return mlx4_cmd_box(dev, 0, outbox->dma, in_mod, 0,
1735 MLX4_CMD_DUMP_ETH_STATS, MLX4_CMD_TIME_CLASS_B,
1736 MLX4_CMD_NATIVE);
1737}
1738
1739int mlx4_DUMP_ETH_STATS_wrapper(struct mlx4_dev *dev, int slave, 1731int mlx4_DUMP_ETH_STATS_wrapper(struct mlx4_dev *dev, int slave,
1740 struct mlx4_vhcr *vhcr, 1732 struct mlx4_vhcr *vhcr,
1741 struct mlx4_cmd_mailbox *inbox, 1733 struct mlx4_cmd_mailbox *inbox,
1742 struct mlx4_cmd_mailbox *outbox, 1734 struct mlx4_cmd_mailbox *outbox,
1743 struct mlx4_cmd_info *cmd) 1735 struct mlx4_cmd_info *cmd)
1744{ 1736{
1745 if (slave != dev->caps.function) 1737 return 0;
1746 return 0;
1747 return mlx4_common_dump_eth_stats(dev, slave,
1748 vhcr->in_modifier, outbox);
1749} 1738}
1750 1739
1751int mlx4_get_slave_from_roce_gid(struct mlx4_dev *dev, int port, u8 *gid, 1740int mlx4_get_slave_from_roce_gid(struct mlx4_dev *dev, int port, u8 *gid,
diff --git a/drivers/net/ethernet/mellanox/mlx4/resource_tracker.c b/drivers/net/ethernet/mellanox/mlx4/resource_tracker.c
index 84d7857ccc27..c548beaaf910 100644
--- a/drivers/net/ethernet/mellanox/mlx4/resource_tracker.c
+++ b/drivers/net/ethernet/mellanox/mlx4/resource_tracker.c
@@ -1605,13 +1605,14 @@ static int eq_res_start_move_to(struct mlx4_dev *dev, int slave, int index,
1605 r->com.from_state = r->com.state; 1605 r->com.from_state = r->com.state;
1606 r->com.to_state = state; 1606 r->com.to_state = state;
1607 r->com.state = RES_EQ_BUSY; 1607 r->com.state = RES_EQ_BUSY;
1608 if (eq)
1609 *eq = r;
1610 } 1608 }
1611 } 1609 }
1612 1610
1613 spin_unlock_irq(mlx4_tlock(dev)); 1611 spin_unlock_irq(mlx4_tlock(dev));
1614 1612
1613 if (!err && eq)
1614 *eq = r;
1615
1615 return err; 1616 return err;
1616} 1617}
1617 1618
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/Kconfig b/drivers/net/ethernet/mellanox/mlx5/core/Kconfig
index aae46884bf93..521cfdb7d11e 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/Kconfig
+++ b/drivers/net/ethernet/mellanox/mlx5/core/Kconfig
@@ -18,8 +18,6 @@ config MLX5_CORE_EN
18 default n 18 default n
19 ---help--- 19 ---help---
20 Ethernet support in Mellanox Technologies ConnectX-4 NIC. 20 Ethernet support in Mellanox Technologies ConnectX-4 NIC.
21 Ethernet and Infiniband support in ConnectX-4 are currently mutually
22 exclusive.
23 21
24config MLX5_CORE_EN_DCB 22config MLX5_CORE_EN_DCB
25 bool "Data Center Bridging (DCB) Support" 23 bool "Data Center Bridging (DCB) Support"
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/alloc.c b/drivers/net/ethernet/mellanox/mlx5/core/alloc.c
index 6cb38304669f..2c6e3c7b7417 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/alloc.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/alloc.c
@@ -41,6 +41,13 @@
41 41
42#include "mlx5_core.h" 42#include "mlx5_core.h"
43 43
44struct mlx5_db_pgdir {
45 struct list_head list;
46 unsigned long *bitmap;
47 __be32 *db_page;
48 dma_addr_t db_dma;
49};
50
44/* Handling for queue buffers -- we allocate a bunch of memory and 51/* Handling for queue buffers -- we allocate a bunch of memory and
45 * register it in a memory region at HCA virtual address 0. 52 * register it in a memory region at HCA virtual address 0.
46 */ 53 */
@@ -102,17 +109,28 @@ EXPORT_SYMBOL_GPL(mlx5_buf_free);
102static struct mlx5_db_pgdir *mlx5_alloc_db_pgdir(struct mlx5_core_dev *dev, 109static struct mlx5_db_pgdir *mlx5_alloc_db_pgdir(struct mlx5_core_dev *dev,
103 int node) 110 int node)
104{ 111{
112 u32 db_per_page = PAGE_SIZE / cache_line_size();
105 struct mlx5_db_pgdir *pgdir; 113 struct mlx5_db_pgdir *pgdir;
106 114
107 pgdir = kzalloc(sizeof(*pgdir), GFP_KERNEL); 115 pgdir = kzalloc(sizeof(*pgdir), GFP_KERNEL);
108 if (!pgdir) 116 if (!pgdir)
109 return NULL; 117 return NULL;
110 118
111 bitmap_fill(pgdir->bitmap, MLX5_DB_PER_PAGE); 119 pgdir->bitmap = kcalloc(BITS_TO_LONGS(db_per_page),
120 sizeof(unsigned long),
121 GFP_KERNEL);
122
123 if (!pgdir->bitmap) {
124 kfree(pgdir);
125 return NULL;
126 }
127
128 bitmap_fill(pgdir->bitmap, db_per_page);
112 129
113 pgdir->db_page = mlx5_dma_zalloc_coherent_node(dev, PAGE_SIZE, 130 pgdir->db_page = mlx5_dma_zalloc_coherent_node(dev, PAGE_SIZE,
114 &pgdir->db_dma, node); 131 &pgdir->db_dma, node);
115 if (!pgdir->db_page) { 132 if (!pgdir->db_page) {
133 kfree(pgdir->bitmap);
116 kfree(pgdir); 134 kfree(pgdir);
117 return NULL; 135 return NULL;
118 } 136 }
@@ -123,18 +141,19 @@ static struct mlx5_db_pgdir *mlx5_alloc_db_pgdir(struct mlx5_core_dev *dev,
123static int mlx5_alloc_db_from_pgdir(struct mlx5_db_pgdir *pgdir, 141static int mlx5_alloc_db_from_pgdir(struct mlx5_db_pgdir *pgdir,
124 struct mlx5_db *db) 142 struct mlx5_db *db)
125{ 143{
144 u32 db_per_page = PAGE_SIZE / cache_line_size();
126 int offset; 145 int offset;
127 int i; 146 int i;
128 147
129 i = find_first_bit(pgdir->bitmap, MLX5_DB_PER_PAGE); 148 i = find_first_bit(pgdir->bitmap, db_per_page);
130 if (i >= MLX5_DB_PER_PAGE) 149 if (i >= db_per_page)
131 return -ENOMEM; 150 return -ENOMEM;
132 151
133 __clear_bit(i, pgdir->bitmap); 152 __clear_bit(i, pgdir->bitmap);
134 153
135 db->u.pgdir = pgdir; 154 db->u.pgdir = pgdir;
136 db->index = i; 155 db->index = i;
137 offset = db->index * L1_CACHE_BYTES; 156 offset = db->index * cache_line_size();
138 db->db = pgdir->db_page + offset / sizeof(*pgdir->db_page); 157 db->db = pgdir->db_page + offset / sizeof(*pgdir->db_page);
139 db->dma = pgdir->db_dma + offset; 158 db->dma = pgdir->db_dma + offset;
140 159
@@ -181,14 +200,16 @@ EXPORT_SYMBOL_GPL(mlx5_db_alloc);
181 200
182void mlx5_db_free(struct mlx5_core_dev *dev, struct mlx5_db *db) 201void mlx5_db_free(struct mlx5_core_dev *dev, struct mlx5_db *db)
183{ 202{
203 u32 db_per_page = PAGE_SIZE / cache_line_size();
184 mutex_lock(&dev->priv.pgdir_mutex); 204 mutex_lock(&dev->priv.pgdir_mutex);
185 205
186 __set_bit(db->index, db->u.pgdir->bitmap); 206 __set_bit(db->index, db->u.pgdir->bitmap);
187 207
188 if (bitmap_full(db->u.pgdir->bitmap, MLX5_DB_PER_PAGE)) { 208 if (bitmap_full(db->u.pgdir->bitmap, db_per_page)) {
189 dma_free_coherent(&(dev->pdev->dev), PAGE_SIZE, 209 dma_free_coherent(&(dev->pdev->dev), PAGE_SIZE,
190 db->u.pgdir->db_page, db->u.pgdir->db_dma); 210 db->u.pgdir->db_page, db->u.pgdir->db_dma);
191 list_del(&db->u.pgdir->list); 211 list_del(&db->u.pgdir->list);
212 kfree(db->u.pgdir->bitmap);
192 kfree(db->u.pgdir); 213 kfree(db->u.pgdir);
193 } 214 }
194 215
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/cmd.c b/drivers/net/ethernet/mellanox/mlx5/core/cmd.c
index 1e639f886021..bfe410e8a469 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/cmd.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/cmd.c
@@ -268,11 +268,6 @@ static void dump_buf(void *buf, int size, int data_only, int offset)
268 pr_debug("\n"); 268 pr_debug("\n");
269} 269}
270 270
271enum {
272 MLX5_DRIVER_STATUS_ABORTED = 0xfe,
273 MLX5_DRIVER_SYND = 0xbadd00de,
274};
275
276static int mlx5_internal_err_ret_value(struct mlx5_core_dev *dev, u16 op, 271static int mlx5_internal_err_ret_value(struct mlx5_core_dev *dev, u16 op,
277 u32 *synd, u8 *status) 272 u32 *synd, u8 *status)
278{ 273{
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en.h b/drivers/net/ethernet/mellanox/mlx5/core/en.h
index 460363b66cb1..71382df59fc0 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en.h
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en.h
@@ -85,6 +85,9 @@
85#define MLX5_MPWRQ_SMALL_PACKET_THRESHOLD (128) 85#define MLX5_MPWRQ_SMALL_PACKET_THRESHOLD (128)
86 86
87#define MLX5E_PARAMS_DEFAULT_LRO_WQE_SZ (64 * 1024) 87#define MLX5E_PARAMS_DEFAULT_LRO_WQE_SZ (64 * 1024)
88#define MLX5E_DEFAULT_LRO_TIMEOUT 32
89#define MLX5E_LRO_TIMEOUT_ARR_SIZE 4
90
88#define MLX5E_PARAMS_DEFAULT_RX_CQ_MODERATION_USEC 0x10 91#define MLX5E_PARAMS_DEFAULT_RX_CQ_MODERATION_USEC 0x10
89#define MLX5E_PARAMS_DEFAULT_RX_CQ_MODERATION_USEC_FROM_CQE 0x3 92#define MLX5E_PARAMS_DEFAULT_RX_CQ_MODERATION_USEC_FROM_CQE 0x3
90#define MLX5E_PARAMS_DEFAULT_RX_CQ_MODERATION_PKTS 0x20 93#define MLX5E_PARAMS_DEFAULT_RX_CQ_MODERATION_PKTS 0x20
@@ -221,6 +224,7 @@ struct mlx5e_params {
221 struct ieee_ets ets; 224 struct ieee_ets ets;
222#endif 225#endif
223 bool rx_am_enabled; 226 bool rx_am_enabled;
227 u32 lro_timeout;
224}; 228};
225 229
226struct mlx5e_tstamp { 230struct mlx5e_tstamp {
@@ -237,7 +241,7 @@ struct mlx5e_tstamp {
237}; 241};
238 242
239enum { 243enum {
240 MLX5E_RQ_STATE_FLUSH, 244 MLX5E_RQ_STATE_ENABLED,
241 MLX5E_RQ_STATE_UMR_WQE_IN_PROGRESS, 245 MLX5E_RQ_STATE_UMR_WQE_IN_PROGRESS,
242 MLX5E_RQ_STATE_AM, 246 MLX5E_RQ_STATE_AM,
243}; 247};
@@ -390,7 +394,7 @@ struct mlx5e_sq_dma {
390}; 394};
391 395
392enum { 396enum {
393 MLX5E_SQ_STATE_FLUSH, 397 MLX5E_SQ_STATE_ENABLED,
394 MLX5E_SQ_STATE_BF_ENABLE, 398 MLX5E_SQ_STATE_BF_ENABLE,
395}; 399};
396 400
@@ -888,5 +892,6 @@ int mlx5e_attach_netdev(struct mlx5_core_dev *mdev, struct net_device *netdev);
888void mlx5e_detach_netdev(struct mlx5_core_dev *mdev, struct net_device *netdev); 892void mlx5e_detach_netdev(struct mlx5_core_dev *mdev, struct net_device *netdev);
889struct rtnl_link_stats64 * 893struct rtnl_link_stats64 *
890mlx5e_get_stats(struct net_device *dev, struct rtnl_link_stats64 *stats); 894mlx5e_get_stats(struct net_device *dev, struct rtnl_link_stats64 *stats);
895u32 mlx5e_choose_lro_timeout(struct mlx5_core_dev *mdev, u32 wanted_timeout);
891 896
892#endif /* __MLX5_EN_H__ */ 897#endif /* __MLX5_EN_H__ */
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
index 7eaf38020a8f..246d98ebb588 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
@@ -759,6 +759,7 @@ static int mlx5e_open_rq(struct mlx5e_channel *c,
759 if (err) 759 if (err)
760 goto err_destroy_rq; 760 goto err_destroy_rq;
761 761
762 set_bit(MLX5E_RQ_STATE_ENABLED, &rq->state);
762 err = mlx5e_modify_rq_state(rq, MLX5_RQC_STATE_RST, MLX5_RQC_STATE_RDY); 763 err = mlx5e_modify_rq_state(rq, MLX5_RQC_STATE_RST, MLX5_RQC_STATE_RDY);
763 if (err) 764 if (err)
764 goto err_disable_rq; 765 goto err_disable_rq;
@@ -773,6 +774,7 @@ static int mlx5e_open_rq(struct mlx5e_channel *c,
773 return 0; 774 return 0;
774 775
775err_disable_rq: 776err_disable_rq:
777 clear_bit(MLX5E_RQ_STATE_ENABLED, &rq->state);
776 mlx5e_disable_rq(rq); 778 mlx5e_disable_rq(rq);
777err_destroy_rq: 779err_destroy_rq:
778 mlx5e_destroy_rq(rq); 780 mlx5e_destroy_rq(rq);
@@ -782,7 +784,7 @@ err_destroy_rq:
782 784
783static void mlx5e_close_rq(struct mlx5e_rq *rq) 785static void mlx5e_close_rq(struct mlx5e_rq *rq)
784{ 786{
785 set_bit(MLX5E_RQ_STATE_FLUSH, &rq->state); 787 clear_bit(MLX5E_RQ_STATE_ENABLED, &rq->state);
786 napi_synchronize(&rq->channel->napi); /* prevent mlx5e_post_rx_wqes */ 788 napi_synchronize(&rq->channel->napi); /* prevent mlx5e_post_rx_wqes */
787 cancel_work_sync(&rq->am.work); 789 cancel_work_sync(&rq->am.work);
788 790
@@ -1006,7 +1008,6 @@ static int mlx5e_enable_sq(struct mlx5e_sq *sq, struct mlx5e_sq_param *param)
1006 MLX5_SET(sqc, sqc, min_wqe_inline_mode, sq->min_inline_mode); 1008 MLX5_SET(sqc, sqc, min_wqe_inline_mode, sq->min_inline_mode);
1007 MLX5_SET(sqc, sqc, state, MLX5_SQC_STATE_RST); 1009 MLX5_SET(sqc, sqc, state, MLX5_SQC_STATE_RST);
1008 MLX5_SET(sqc, sqc, tis_lst_sz, param->type == MLX5E_SQ_ICO ? 0 : 1); 1010 MLX5_SET(sqc, sqc, tis_lst_sz, param->type == MLX5E_SQ_ICO ? 0 : 1);
1009 MLX5_SET(sqc, sqc, flush_in_error_en, 1);
1010 1011
1011 MLX5_SET(wq, wq, wq_type, MLX5_WQ_TYPE_CYCLIC); 1012 MLX5_SET(wq, wq, wq_type, MLX5_WQ_TYPE_CYCLIC);
1012 MLX5_SET(wq, wq, uar_page, sq->uar.index); 1013 MLX5_SET(wq, wq, uar_page, sq->uar.index);
@@ -1083,6 +1084,7 @@ static int mlx5e_open_sq(struct mlx5e_channel *c,
1083 if (err) 1084 if (err)
1084 goto err_destroy_sq; 1085 goto err_destroy_sq;
1085 1086
1087 set_bit(MLX5E_SQ_STATE_ENABLED, &sq->state);
1086 err = mlx5e_modify_sq(sq, MLX5_SQC_STATE_RST, MLX5_SQC_STATE_RDY, 1088 err = mlx5e_modify_sq(sq, MLX5_SQC_STATE_RST, MLX5_SQC_STATE_RDY,
1087 false, 0); 1089 false, 0);
1088 if (err) 1090 if (err)
@@ -1096,6 +1098,7 @@ static int mlx5e_open_sq(struct mlx5e_channel *c,
1096 return 0; 1098 return 0;
1097 1099
1098err_disable_sq: 1100err_disable_sq:
1101 clear_bit(MLX5E_SQ_STATE_ENABLED, &sq->state);
1099 mlx5e_disable_sq(sq); 1102 mlx5e_disable_sq(sq);
1100err_destroy_sq: 1103err_destroy_sq:
1101 mlx5e_destroy_sq(sq); 1104 mlx5e_destroy_sq(sq);
@@ -1112,7 +1115,7 @@ static inline void netif_tx_disable_queue(struct netdev_queue *txq)
1112 1115
1113static void mlx5e_close_sq(struct mlx5e_sq *sq) 1116static void mlx5e_close_sq(struct mlx5e_sq *sq)
1114{ 1117{
1115 set_bit(MLX5E_SQ_STATE_FLUSH, &sq->state); 1118 clear_bit(MLX5E_SQ_STATE_ENABLED, &sq->state);
1116 /* prevent netif_tx_wake_queue */ 1119 /* prevent netif_tx_wake_queue */
1117 napi_synchronize(&sq->channel->napi); 1120 napi_synchronize(&sq->channel->napi);
1118 1121
@@ -1445,6 +1448,7 @@ static int mlx5e_open_channel(struct mlx5e_priv *priv, int ix,
1445 c->netdev = priv->netdev; 1448 c->netdev = priv->netdev;
1446 c->mkey_be = cpu_to_be32(priv->mdev->mlx5e_res.mkey.key); 1449 c->mkey_be = cpu_to_be32(priv->mdev->mlx5e_res.mkey.key);
1447 c->num_tc = priv->params.num_tc; 1450 c->num_tc = priv->params.num_tc;
1451 c->xdp = !!priv->xdp_prog;
1448 1452
1449 if (priv->params.rx_am_enabled) 1453 if (priv->params.rx_am_enabled)
1450 rx_cq_profile = mlx5e_am_get_def_profile(priv->params.rx_cq_period_mode); 1454 rx_cq_profile = mlx5e_am_get_def_profile(priv->params.rx_cq_period_mode);
@@ -1468,6 +1472,12 @@ static int mlx5e_open_channel(struct mlx5e_priv *priv, int ix,
1468 if (err) 1472 if (err)
1469 goto err_close_tx_cqs; 1473 goto err_close_tx_cqs;
1470 1474
1475 /* XDP SQ CQ params are same as normal TXQ sq CQ params */
1476 err = c->xdp ? mlx5e_open_cq(c, &cparam->tx_cq, &c->xdp_sq.cq,
1477 priv->params.tx_cq_moderation) : 0;
1478 if (err)
1479 goto err_close_rx_cq;
1480
1471 napi_enable(&c->napi); 1481 napi_enable(&c->napi);
1472 1482
1473 err = mlx5e_open_sq(c, 0, &cparam->icosq, &c->icosq); 1483 err = mlx5e_open_sq(c, 0, &cparam->icosq, &c->icosq);
@@ -1488,21 +1498,10 @@ static int mlx5e_open_channel(struct mlx5e_priv *priv, int ix,
1488 } 1498 }
1489 } 1499 }
1490 1500
1491 if (priv->xdp_prog) { 1501 err = c->xdp ? mlx5e_open_sq(c, 0, &cparam->xdp_sq, &c->xdp_sq) : 0;
1492 /* XDP SQ CQ params are same as normal TXQ sq CQ params */ 1502 if (err)
1493 err = mlx5e_open_cq(c, &cparam->tx_cq, &c->xdp_sq.cq, 1503 goto err_close_sqs;
1494 priv->params.tx_cq_moderation);
1495 if (err)
1496 goto err_close_sqs;
1497
1498 err = mlx5e_open_sq(c, 0, &cparam->xdp_sq, &c->xdp_sq);
1499 if (err) {
1500 mlx5e_close_cq(&c->xdp_sq.cq);
1501 goto err_close_sqs;
1502 }
1503 }
1504 1504
1505 c->xdp = !!priv->xdp_prog;
1506 err = mlx5e_open_rq(c, &cparam->rq, &c->rq); 1505 err = mlx5e_open_rq(c, &cparam->rq, &c->rq);
1507 if (err) 1506 if (err)
1508 goto err_close_xdp_sq; 1507 goto err_close_xdp_sq;
@@ -1512,7 +1511,8 @@ static int mlx5e_open_channel(struct mlx5e_priv *priv, int ix,
1512 1511
1513 return 0; 1512 return 0;
1514err_close_xdp_sq: 1513err_close_xdp_sq:
1515 mlx5e_close_sq(&c->xdp_sq); 1514 if (c->xdp)
1515 mlx5e_close_sq(&c->xdp_sq);
1516 1516
1517err_close_sqs: 1517err_close_sqs:
1518 mlx5e_close_sqs(c); 1518 mlx5e_close_sqs(c);
@@ -1522,6 +1522,10 @@ err_close_icosq:
1522 1522
1523err_disable_napi: 1523err_disable_napi:
1524 napi_disable(&c->napi); 1524 napi_disable(&c->napi);
1525 if (c->xdp)
1526 mlx5e_close_cq(&c->xdp_sq.cq);
1527
1528err_close_rx_cq:
1525 mlx5e_close_cq(&c->rq.cq); 1529 mlx5e_close_cq(&c->rq.cq);
1526 1530
1527err_close_tx_cqs: 1531err_close_tx_cqs:
@@ -1971,9 +1975,7 @@ static void mlx5e_build_tir_ctx_lro(void *tirc, struct mlx5e_priv *priv)
1971 MLX5_SET(tirc, tirc, lro_max_ip_payload_size, 1975 MLX5_SET(tirc, tirc, lro_max_ip_payload_size,
1972 (priv->params.lro_wqe_sz - 1976 (priv->params.lro_wqe_sz -
1973 ROUGH_MAX_L2_L3_HDR_SZ) >> 8); 1977 ROUGH_MAX_L2_L3_HDR_SZ) >> 8);
1974 MLX5_SET(tirc, tirc, lro_timeout_period_usecs, 1978 MLX5_SET(tirc, tirc, lro_timeout_period_usecs, priv->params.lro_timeout);
1975 MLX5_CAP_ETH(priv->mdev,
1976 lro_timer_supported_periods[2]));
1977} 1979}
1978 1980
1979void mlx5e_build_tir_ctx_hash(void *tirc, struct mlx5e_priv *priv) 1981void mlx5e_build_tir_ctx_hash(void *tirc, struct mlx5e_priv *priv)
@@ -3093,7 +3095,7 @@ static void mlx5e_tx_timeout(struct net_device *dev)
3093 if (!netif_xmit_stopped(netdev_get_tx_queue(dev, i))) 3095 if (!netif_xmit_stopped(netdev_get_tx_queue(dev, i)))
3094 continue; 3096 continue;
3095 sched_work = true; 3097 sched_work = true;
3096 set_bit(MLX5E_SQ_STATE_FLUSH, &sq->state); 3098 clear_bit(MLX5E_SQ_STATE_ENABLED, &sq->state);
3097 netdev_err(dev, "TX timeout on queue: %d, SQ: 0x%x, CQ: 0x%x, SQ Cons: 0x%x SQ Prod: 0x%x\n", 3099 netdev_err(dev, "TX timeout on queue: %d, SQ: 0x%x, CQ: 0x%x, SQ Cons: 0x%x SQ Prod: 0x%x\n",
3098 i, sq->sqn, sq->cq.mcq.cqn, sq->cc, sq->pc); 3100 i, sq->sqn, sq->cq.mcq.cqn, sq->cc, sq->pc);
3099 } 3101 }
@@ -3148,13 +3150,13 @@ static int mlx5e_xdp_set(struct net_device *netdev, struct bpf_prog *prog)
3148 for (i = 0; i < priv->params.num_channels; i++) { 3150 for (i = 0; i < priv->params.num_channels; i++) {
3149 struct mlx5e_channel *c = priv->channel[i]; 3151 struct mlx5e_channel *c = priv->channel[i];
3150 3152
3151 set_bit(MLX5E_RQ_STATE_FLUSH, &c->rq.state); 3153 clear_bit(MLX5E_RQ_STATE_ENABLED, &c->rq.state);
3152 napi_synchronize(&c->napi); 3154 napi_synchronize(&c->napi);
3153 /* prevent mlx5e_poll_rx_cq from accessing rq->xdp_prog */ 3155 /* prevent mlx5e_poll_rx_cq from accessing rq->xdp_prog */
3154 3156
3155 old_prog = xchg(&c->rq.xdp_prog, prog); 3157 old_prog = xchg(&c->rq.xdp_prog, prog);
3156 3158
3157 clear_bit(MLX5E_RQ_STATE_FLUSH, &c->rq.state); 3159 set_bit(MLX5E_RQ_STATE_ENABLED, &c->rq.state);
3158 /* napi_schedule in case we have missed anything */ 3160 /* napi_schedule in case we have missed anything */
3159 set_bit(MLX5E_CHANNEL_NAPI_SCHED, &c->flags); 3161 set_bit(MLX5E_CHANNEL_NAPI_SCHED, &c->flags);
3160 napi_schedule(&c->napi); 3162 napi_schedule(&c->napi);
@@ -3401,6 +3403,18 @@ static void mlx5e_query_min_inline(struct mlx5_core_dev *mdev,
3401 } 3403 }
3402} 3404}
3403 3405
3406u32 mlx5e_choose_lro_timeout(struct mlx5_core_dev *mdev, u32 wanted_timeout)
3407{
3408 int i;
3409
3410 /* The supported periods are organized in ascending order */
3411 for (i = 0; i < MLX5E_LRO_TIMEOUT_ARR_SIZE - 1; i++)
3412 if (MLX5_CAP_ETH(mdev, lro_timer_supported_periods[i]) >= wanted_timeout)
3413 break;
3414
3415 return MLX5_CAP_ETH(mdev, lro_timer_supported_periods[i]);
3416}
3417
3404static void mlx5e_build_nic_netdev_priv(struct mlx5_core_dev *mdev, 3418static void mlx5e_build_nic_netdev_priv(struct mlx5_core_dev *mdev,
3405 struct net_device *netdev, 3419 struct net_device *netdev,
3406 const struct mlx5e_profile *profile, 3420 const struct mlx5e_profile *profile,
@@ -3419,6 +3433,9 @@ static void mlx5e_build_nic_netdev_priv(struct mlx5_core_dev *mdev,
3419 priv->profile = profile; 3433 priv->profile = profile;
3420 priv->ppriv = ppriv; 3434 priv->ppriv = ppriv;
3421 3435
3436 priv->params.lro_timeout =
3437 mlx5e_choose_lro_timeout(mdev, MLX5E_DEFAULT_LRO_TIMEOUT);
3438
3422 priv->params.log_sq_size = MLX5E_PARAMS_DEFAULT_LOG_SQ_SIZE; 3439 priv->params.log_sq_size = MLX5E_PARAMS_DEFAULT_LOG_SQ_SIZE;
3423 3440
3424 /* set CQE compression */ 3441 /* set CQE compression */
@@ -4035,7 +4052,6 @@ void mlx5e_destroy_netdev(struct mlx5_core_dev *mdev, struct mlx5e_priv *priv)
4035 const struct mlx5e_profile *profile = priv->profile; 4052 const struct mlx5e_profile *profile = priv->profile;
4036 struct net_device *netdev = priv->netdev; 4053 struct net_device *netdev = priv->netdev;
4037 4054
4038 unregister_netdev(netdev);
4039 destroy_workqueue(priv->wq); 4055 destroy_workqueue(priv->wq);
4040 if (profile->cleanup) 4056 if (profile->cleanup)
4041 profile->cleanup(priv); 4057 profile->cleanup(priv);
@@ -4052,6 +4068,7 @@ static void mlx5e_remove(struct mlx5_core_dev *mdev, void *vpriv)
4052 for (vport = 1; vport < total_vfs; vport++) 4068 for (vport = 1; vport < total_vfs; vport++)
4053 mlx5_eswitch_unregister_vport_rep(esw, vport); 4069 mlx5_eswitch_unregister_vport_rep(esw, vport);
4054 4070
4071 unregister_netdev(priv->netdev);
4055 mlx5e_detach(mdev, vpriv); 4072 mlx5e_detach(mdev, vpriv);
4056 mlx5e_destroy_netdev(mdev, priv); 4073 mlx5e_destroy_netdev(mdev, priv);
4057} 4074}
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c
index 3c97da103d30..bf1c09ca73c0 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c
@@ -308,7 +308,7 @@ static void mlx5e_build_rep_netdev(struct net_device *netdev)
308 netdev->switchdev_ops = &mlx5e_rep_switchdev_ops; 308 netdev->switchdev_ops = &mlx5e_rep_switchdev_ops;
309#endif 309#endif
310 310
311 netdev->features |= NETIF_F_VLAN_CHALLENGED | NETIF_F_HW_TC; 311 netdev->features |= NETIF_F_VLAN_CHALLENGED | NETIF_F_HW_TC | NETIF_F_NETNS_LOCAL;
312 netdev->hw_features |= NETIF_F_HW_TC; 312 netdev->hw_features |= NETIF_F_HW_TC;
313 313
314 eth_hw_addr_random(netdev); 314 eth_hw_addr_random(netdev);
@@ -457,6 +457,7 @@ void mlx5e_vport_rep_unload(struct mlx5_eswitch *esw,
457 struct mlx5e_priv *priv = rep->priv_data; 457 struct mlx5e_priv *priv = rep->priv_data;
458 struct net_device *netdev = priv->netdev; 458 struct net_device *netdev = priv->netdev;
459 459
460 unregister_netdev(netdev);
460 mlx5e_detach_netdev(esw->dev, netdev); 461 mlx5e_detach_netdev(esw->dev, netdev);
461 mlx5e_destroy_netdev(esw->dev, priv); 462 mlx5e_destroy_netdev(esw->dev, priv);
462} 463}
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c b/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c
index c6de6fba5843..33495d88aeb2 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c
@@ -340,7 +340,7 @@ static inline void mlx5e_post_umr_wqe(struct mlx5e_rq *rq, u16 ix)
340 while ((pi = (sq->pc & wq->sz_m1)) > sq->edge) { 340 while ((pi = (sq->pc & wq->sz_m1)) > sq->edge) {
341 sq->db.ico_wqe[pi].opcode = MLX5_OPCODE_NOP; 341 sq->db.ico_wqe[pi].opcode = MLX5_OPCODE_NOP;
342 sq->db.ico_wqe[pi].num_wqebbs = 1; 342 sq->db.ico_wqe[pi].num_wqebbs = 1;
343 mlx5e_send_nop(sq, true); 343 mlx5e_send_nop(sq, false);
344 } 344 }
345 345
346 wqe = mlx5_wq_cyc_get_wqe(wq, pi); 346 wqe = mlx5_wq_cyc_get_wqe(wq, pi);
@@ -412,7 +412,7 @@ void mlx5e_post_rx_mpwqe(struct mlx5e_rq *rq)
412 412
413 clear_bit(MLX5E_RQ_STATE_UMR_WQE_IN_PROGRESS, &rq->state); 413 clear_bit(MLX5E_RQ_STATE_UMR_WQE_IN_PROGRESS, &rq->state);
414 414
415 if (unlikely(test_bit(MLX5E_RQ_STATE_FLUSH, &rq->state))) { 415 if (unlikely(!test_bit(MLX5E_RQ_STATE_ENABLED, &rq->state))) {
416 mlx5e_free_rx_mpwqe(rq, &rq->mpwqe.info[wq->head]); 416 mlx5e_free_rx_mpwqe(rq, &rq->mpwqe.info[wq->head]);
417 return; 417 return;
418 } 418 }
@@ -445,7 +445,7 @@ void mlx5e_dealloc_rx_mpwqe(struct mlx5e_rq *rq, u16 ix)
445} 445}
446 446
447#define RQ_CANNOT_POST(rq) \ 447#define RQ_CANNOT_POST(rq) \
448 (test_bit(MLX5E_RQ_STATE_FLUSH, &rq->state) || \ 448 (!test_bit(MLX5E_RQ_STATE_ENABLED, &rq->state) || \
449 test_bit(MLX5E_RQ_STATE_UMR_WQE_IN_PROGRESS, &rq->state)) 449 test_bit(MLX5E_RQ_STATE_UMR_WQE_IN_PROGRESS, &rq->state))
450 450
451bool mlx5e_post_rx_wqes(struct mlx5e_rq *rq) 451bool mlx5e_post_rx_wqes(struct mlx5e_rq *rq)
@@ -924,7 +924,7 @@ int mlx5e_poll_rx_cq(struct mlx5e_cq *cq, int budget)
924 struct mlx5e_sq *xdp_sq = &rq->channel->xdp_sq; 924 struct mlx5e_sq *xdp_sq = &rq->channel->xdp_sq;
925 int work_done = 0; 925 int work_done = 0;
926 926
927 if (unlikely(test_bit(MLX5E_RQ_STATE_FLUSH, &rq->state))) 927 if (unlikely(!test_bit(MLX5E_RQ_STATE_ENABLED, &rq->state)))
928 return 0; 928 return 0;
929 929
930 if (cq->decmprs_left) 930 if (cq->decmprs_left)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
index ce8c54d18906..6bb21b31cfeb 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
@@ -237,12 +237,15 @@ static int parse_cls_flower(struct mlx5e_priv *priv, struct mlx5_flow_spec *spec
237 skb_flow_dissector_target(f->dissector, 237 skb_flow_dissector_target(f->dissector,
238 FLOW_DISSECTOR_KEY_VLAN, 238 FLOW_DISSECTOR_KEY_VLAN,
239 f->mask); 239 f->mask);
240 if (mask->vlan_id) { 240 if (mask->vlan_id || mask->vlan_priority) {
241 MLX5_SET(fte_match_set_lyr_2_4, headers_c, vlan_tag, 1); 241 MLX5_SET(fte_match_set_lyr_2_4, headers_c, vlan_tag, 1);
242 MLX5_SET(fte_match_set_lyr_2_4, headers_v, vlan_tag, 1); 242 MLX5_SET(fte_match_set_lyr_2_4, headers_v, vlan_tag, 1);
243 243
244 MLX5_SET(fte_match_set_lyr_2_4, headers_c, first_vid, mask->vlan_id); 244 MLX5_SET(fte_match_set_lyr_2_4, headers_c, first_vid, mask->vlan_id);
245 MLX5_SET(fte_match_set_lyr_2_4, headers_v, first_vid, key->vlan_id); 245 MLX5_SET(fte_match_set_lyr_2_4, headers_v, first_vid, key->vlan_id);
246
247 MLX5_SET(fte_match_set_lyr_2_4, headers_c, first_prio, mask->vlan_priority);
248 MLX5_SET(fte_match_set_lyr_2_4, headers_v, first_prio, key->vlan_priority);
246 } 249 }
247 } 250 }
248 251
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_tx.c b/drivers/net/ethernet/mellanox/mlx5/core/en_tx.c
index 70a717382357..cfb68371c397 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_tx.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_tx.c
@@ -409,7 +409,7 @@ bool mlx5e_poll_tx_cq(struct mlx5e_cq *cq, int napi_budget)
409 409
410 sq = container_of(cq, struct mlx5e_sq, cq); 410 sq = container_of(cq, struct mlx5e_sq, cq);
411 411
412 if (unlikely(test_bit(MLX5E_SQ_STATE_FLUSH, &sq->state))) 412 if (unlikely(!test_bit(MLX5E_SQ_STATE_ENABLED, &sq->state)))
413 return false; 413 return false;
414 414
415 npkts = 0; 415 npkts = 0;
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_txrx.c b/drivers/net/ethernet/mellanox/mlx5/core/en_txrx.c
index 5703f19a6a24..e5c12a732aa1 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_txrx.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_txrx.c
@@ -56,7 +56,7 @@ static void mlx5e_poll_ico_cq(struct mlx5e_cq *cq)
56 struct mlx5_cqe64 *cqe; 56 struct mlx5_cqe64 *cqe;
57 u16 sqcc; 57 u16 sqcc;
58 58
59 if (unlikely(test_bit(MLX5E_SQ_STATE_FLUSH, &sq->state))) 59 if (unlikely(!test_bit(MLX5E_SQ_STATE_ENABLED, &sq->state)))
60 return; 60 return;
61 61
62 cqe = mlx5e_get_cqe(cq); 62 cqe = mlx5e_get_cqe(cq);
@@ -113,7 +113,7 @@ static inline bool mlx5e_poll_xdp_tx_cq(struct mlx5e_cq *cq)
113 113
114 sq = container_of(cq, struct mlx5e_sq, cq); 114 sq = container_of(cq, struct mlx5e_sq, cq);
115 115
116 if (unlikely(test_bit(MLX5E_SQ_STATE_FLUSH, &sq->state))) 116 if (unlikely(!test_bit(MLX5E_SQ_STATE_ENABLED, &sq->state)))
117 return false; 117 return false;
118 118
119 /* sq->cc must be updated only after mlx5_cqwq_update_db_record(), 119 /* sq->cc must be updated only after mlx5_cqwq_update_db_record(),
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
index abbf2c369923..be1f7333ab7f 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
@@ -931,8 +931,8 @@ static void esw_vport_change_handler(struct work_struct *work)
931 mutex_unlock(&esw->state_lock); 931 mutex_unlock(&esw->state_lock);
932} 932}
933 933
934static void esw_vport_enable_egress_acl(struct mlx5_eswitch *esw, 934static int esw_vport_enable_egress_acl(struct mlx5_eswitch *esw,
935 struct mlx5_vport *vport) 935 struct mlx5_vport *vport)
936{ 936{
937 int inlen = MLX5_ST_SZ_BYTES(create_flow_group_in); 937 int inlen = MLX5_ST_SZ_BYTES(create_flow_group_in);
938 struct mlx5_flow_group *vlan_grp = NULL; 938 struct mlx5_flow_group *vlan_grp = NULL;
@@ -949,9 +949,11 @@ static void esw_vport_enable_egress_acl(struct mlx5_eswitch *esw,
949 int table_size = 2; 949 int table_size = 2;
950 int err = 0; 950 int err = 0;
951 951
952 if (!MLX5_CAP_ESW_EGRESS_ACL(dev, ft_support) || 952 if (!MLX5_CAP_ESW_EGRESS_ACL(dev, ft_support))
953 !IS_ERR_OR_NULL(vport->egress.acl)) 953 return -EOPNOTSUPP;
954 return; 954
955 if (!IS_ERR_OR_NULL(vport->egress.acl))
956 return 0;
955 957
956 esw_debug(dev, "Create vport[%d] egress ACL log_max_size(%d)\n", 958 esw_debug(dev, "Create vport[%d] egress ACL log_max_size(%d)\n",
957 vport->vport, MLX5_CAP_ESW_EGRESS_ACL(dev, log_max_ft_size)); 959 vport->vport, MLX5_CAP_ESW_EGRESS_ACL(dev, log_max_ft_size));
@@ -959,12 +961,12 @@ static void esw_vport_enable_egress_acl(struct mlx5_eswitch *esw,
959 root_ns = mlx5_get_flow_namespace(dev, MLX5_FLOW_NAMESPACE_ESW_EGRESS); 961 root_ns = mlx5_get_flow_namespace(dev, MLX5_FLOW_NAMESPACE_ESW_EGRESS);
960 if (!root_ns) { 962 if (!root_ns) {
961 esw_warn(dev, "Failed to get E-Switch egress flow namespace\n"); 963 esw_warn(dev, "Failed to get E-Switch egress flow namespace\n");
962 return; 964 return -EIO;
963 } 965 }
964 966
965 flow_group_in = mlx5_vzalloc(inlen); 967 flow_group_in = mlx5_vzalloc(inlen);
966 if (!flow_group_in) 968 if (!flow_group_in)
967 return; 969 return -ENOMEM;
968 970
969 acl = mlx5_create_vport_flow_table(root_ns, 0, table_size, 0, vport->vport); 971 acl = mlx5_create_vport_flow_table(root_ns, 0, table_size, 0, vport->vport);
970 if (IS_ERR(acl)) { 972 if (IS_ERR(acl)) {
@@ -1009,6 +1011,7 @@ out:
1009 mlx5_destroy_flow_group(vlan_grp); 1011 mlx5_destroy_flow_group(vlan_grp);
1010 if (err && !IS_ERR_OR_NULL(acl)) 1012 if (err && !IS_ERR_OR_NULL(acl))
1011 mlx5_destroy_flow_table(acl); 1013 mlx5_destroy_flow_table(acl);
1014 return err;
1012} 1015}
1013 1016
1014static void esw_vport_cleanup_egress_rules(struct mlx5_eswitch *esw, 1017static void esw_vport_cleanup_egress_rules(struct mlx5_eswitch *esw,
@@ -1041,8 +1044,8 @@ static void esw_vport_disable_egress_acl(struct mlx5_eswitch *esw,
1041 vport->egress.acl = NULL; 1044 vport->egress.acl = NULL;
1042} 1045}
1043 1046
1044static void esw_vport_enable_ingress_acl(struct mlx5_eswitch *esw, 1047static int esw_vport_enable_ingress_acl(struct mlx5_eswitch *esw,
1045 struct mlx5_vport *vport) 1048 struct mlx5_vport *vport)
1046{ 1049{
1047 int inlen = MLX5_ST_SZ_BYTES(create_flow_group_in); 1050 int inlen = MLX5_ST_SZ_BYTES(create_flow_group_in);
1048 struct mlx5_core_dev *dev = esw->dev; 1051 struct mlx5_core_dev *dev = esw->dev;
@@ -1063,9 +1066,11 @@ static void esw_vport_enable_ingress_acl(struct mlx5_eswitch *esw,
1063 int table_size = 4; 1066 int table_size = 4;
1064 int err = 0; 1067 int err = 0;
1065 1068
1066 if (!MLX5_CAP_ESW_INGRESS_ACL(dev, ft_support) || 1069 if (!MLX5_CAP_ESW_INGRESS_ACL(dev, ft_support))
1067 !IS_ERR_OR_NULL(vport->ingress.acl)) 1070 return -EOPNOTSUPP;
1068 return; 1071
1072 if (!IS_ERR_OR_NULL(vport->ingress.acl))
1073 return 0;
1069 1074
1070 esw_debug(dev, "Create vport[%d] ingress ACL log_max_size(%d)\n", 1075 esw_debug(dev, "Create vport[%d] ingress ACL log_max_size(%d)\n",
1071 vport->vport, MLX5_CAP_ESW_INGRESS_ACL(dev, log_max_ft_size)); 1076 vport->vport, MLX5_CAP_ESW_INGRESS_ACL(dev, log_max_ft_size));
@@ -1073,12 +1078,12 @@ static void esw_vport_enable_ingress_acl(struct mlx5_eswitch *esw,
1073 root_ns = mlx5_get_flow_namespace(dev, MLX5_FLOW_NAMESPACE_ESW_INGRESS); 1078 root_ns = mlx5_get_flow_namespace(dev, MLX5_FLOW_NAMESPACE_ESW_INGRESS);
1074 if (!root_ns) { 1079 if (!root_ns) {
1075 esw_warn(dev, "Failed to get E-Switch ingress flow namespace\n"); 1080 esw_warn(dev, "Failed to get E-Switch ingress flow namespace\n");
1076 return; 1081 return -EIO;
1077 } 1082 }
1078 1083
1079 flow_group_in = mlx5_vzalloc(inlen); 1084 flow_group_in = mlx5_vzalloc(inlen);
1080 if (!flow_group_in) 1085 if (!flow_group_in)
1081 return; 1086 return -ENOMEM;
1082 1087
1083 acl = mlx5_create_vport_flow_table(root_ns, 0, table_size, 0, vport->vport); 1088 acl = mlx5_create_vport_flow_table(root_ns, 0, table_size, 0, vport->vport);
1084 if (IS_ERR(acl)) { 1089 if (IS_ERR(acl)) {
@@ -1167,6 +1172,7 @@ out:
1167 } 1172 }
1168 1173
1169 kvfree(flow_group_in); 1174 kvfree(flow_group_in);
1175 return err;
1170} 1176}
1171 1177
1172static void esw_vport_cleanup_ingress_rules(struct mlx5_eswitch *esw, 1178static void esw_vport_cleanup_ingress_rules(struct mlx5_eswitch *esw,
@@ -1225,7 +1231,13 @@ static int esw_vport_ingress_config(struct mlx5_eswitch *esw,
1225 return 0; 1231 return 0;
1226 } 1232 }
1227 1233
1228 esw_vport_enable_ingress_acl(esw, vport); 1234 err = esw_vport_enable_ingress_acl(esw, vport);
1235 if (err) {
1236 mlx5_core_warn(esw->dev,
1237 "failed to enable ingress acl (%d) on vport[%d]\n",
1238 err, vport->vport);
1239 return err;
1240 }
1229 1241
1230 esw_debug(esw->dev, 1242 esw_debug(esw->dev,
1231 "vport[%d] configure ingress rules, vlan(%d) qos(%d)\n", 1243 "vport[%d] configure ingress rules, vlan(%d) qos(%d)\n",
@@ -1299,7 +1311,13 @@ static int esw_vport_egress_config(struct mlx5_eswitch *esw,
1299 return 0; 1311 return 0;
1300 } 1312 }
1301 1313
1302 esw_vport_enable_egress_acl(esw, vport); 1314 err = esw_vport_enable_egress_acl(esw, vport);
1315 if (err) {
1316 mlx5_core_warn(esw->dev,
1317 "failed to enable egress acl (%d) on vport[%d]\n",
1318 err, vport->vport);
1319 return err;
1320 }
1303 1321
1304 esw_debug(esw->dev, 1322 esw_debug(esw->dev,
1305 "vport[%d] configure egress rules, vlan(%d) qos(%d)\n", 1323 "vport[%d] configure egress rules, vlan(%d) qos(%d)\n",
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c b/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
index c55ad8d00c05..d239f5d0ea36 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
@@ -57,7 +57,8 @@ mlx5_eswitch_add_offloaded_rule(struct mlx5_eswitch *esw,
57 if (esw->mode != SRIOV_OFFLOADS) 57 if (esw->mode != SRIOV_OFFLOADS)
58 return ERR_PTR(-EOPNOTSUPP); 58 return ERR_PTR(-EOPNOTSUPP);
59 59
60 action = attr->action; 60 /* per flow vlan pop/push is emulated, don't set that into the firmware */
61 action = attr->action & ~(MLX5_FLOW_CONTEXT_ACTION_VLAN_PUSH | MLX5_FLOW_CONTEXT_ACTION_VLAN_POP);
61 62
62 if (action & MLX5_FLOW_CONTEXT_ACTION_FWD_DEST) { 63 if (action & MLX5_FLOW_CONTEXT_ACTION_FWD_DEST) {
63 dest.type = MLX5_FLOW_DESTINATION_TYPE_VPORT; 64 dest.type = MLX5_FLOW_DESTINATION_TYPE_VPORT;
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/fs_core.c b/drivers/net/ethernet/mellanox/mlx5/core/fs_core.c
index 5da2cc878582..914e5466f729 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/fs_core.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/fs_core.c
@@ -436,6 +436,9 @@ static void del_flow_group(struct fs_node *node)
436 fs_get_obj(ft, fg->node.parent); 436 fs_get_obj(ft, fg->node.parent);
437 dev = get_dev(&ft->node); 437 dev = get_dev(&ft->node);
438 438
439 if (ft->autogroup.active)
440 ft->autogroup.num_groups--;
441
439 if (mlx5_cmd_destroy_flow_group(dev, ft, fg->id)) 442 if (mlx5_cmd_destroy_flow_group(dev, ft, fg->id))
440 mlx5_core_warn(dev, "flow steering can't destroy fg %d of ft %d\n", 443 mlx5_core_warn(dev, "flow steering can't destroy fg %d of ft %d\n",
441 fg->id, ft->id); 444 fg->id, ft->id);
@@ -879,7 +882,7 @@ static struct mlx5_flow_group *create_flow_group_common(struct mlx5_flow_table *
879 tree_init_node(&fg->node, !is_auto_fg, del_flow_group); 882 tree_init_node(&fg->node, !is_auto_fg, del_flow_group);
880 tree_add_node(&fg->node, &ft->node); 883 tree_add_node(&fg->node, &ft->node);
881 /* Add node to group list */ 884 /* Add node to group list */
882 list_add(&fg->node.list, ft->node.children.prev); 885 list_add(&fg->node.list, prev_fg);
883 886
884 return fg; 887 return fg;
885} 888}
@@ -893,7 +896,7 @@ struct mlx5_flow_group *mlx5_create_flow_group(struct mlx5_flow_table *ft,
893 return ERR_PTR(-EPERM); 896 return ERR_PTR(-EPERM);
894 897
895 lock_ref_node(&ft->node); 898 lock_ref_node(&ft->node);
896 fg = create_flow_group_common(ft, fg_in, &ft->node.children, false); 899 fg = create_flow_group_common(ft, fg_in, ft->node.children.prev, false);
897 unlock_ref_node(&ft->node); 900 unlock_ref_node(&ft->node);
898 901
899 return fg; 902 return fg;
@@ -1012,7 +1015,7 @@ static struct mlx5_flow_group *create_autogroup(struct mlx5_flow_table *ft,
1012 u32 *match_criteria) 1015 u32 *match_criteria)
1013{ 1016{
1014 int inlen = MLX5_ST_SZ_BYTES(create_flow_group_in); 1017 int inlen = MLX5_ST_SZ_BYTES(create_flow_group_in);
1015 struct list_head *prev = &ft->node.children; 1018 struct list_head *prev = ft->node.children.prev;
1016 unsigned int candidate_index = 0; 1019 unsigned int candidate_index = 0;
1017 struct mlx5_flow_group *fg; 1020 struct mlx5_flow_group *fg;
1018 void *match_criteria_addr; 1021 void *match_criteria_addr;
@@ -1687,7 +1690,7 @@ static int init_root_ns(struct mlx5_flow_steering *steering)
1687{ 1690{
1688 1691
1689 steering->root_ns = create_root_ns(steering, FS_FT_NIC_RX); 1692 steering->root_ns = create_root_ns(steering, FS_FT_NIC_RX);
1690 if (IS_ERR_OR_NULL(steering->root_ns)) 1693 if (!steering->root_ns)
1691 goto cleanup; 1694 goto cleanup;
1692 1695
1693 if (init_root_tree(steering, &root_fs, &steering->root_ns->ns.node)) 1696 if (init_root_tree(steering, &root_fs, &steering->root_ns->ns.node))
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/fs_counters.c b/drivers/net/ethernet/mellanox/mlx5/core/fs_counters.c
index 3a9195b4169d..3b026c151cf2 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/fs_counters.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/fs_counters.c
@@ -218,6 +218,7 @@ struct mlx5_fc *mlx5_fc_create(struct mlx5_core_dev *dev, bool aging)
218 goto err_out; 218 goto err_out;
219 219
220 if (aging) { 220 if (aging) {
221 counter->cache.lastuse = jiffies;
221 counter->aging = true; 222 counter->aging = true;
222 223
223 spin_lock(&fc_stats->addlist_lock); 224 spin_lock(&fc_stats->addlist_lock);
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/health.c b/drivers/net/ethernet/mellanox/mlx5/core/health.c
index 1a05fb965c8d..5bcf93422ee0 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/health.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/health.c
@@ -61,10 +61,15 @@ enum {
61enum { 61enum {
62 MLX5_NIC_IFC_FULL = 0, 62 MLX5_NIC_IFC_FULL = 0,
63 MLX5_NIC_IFC_DISABLED = 1, 63 MLX5_NIC_IFC_DISABLED = 1,
64 MLX5_NIC_IFC_NO_DRAM_NIC = 2 64 MLX5_NIC_IFC_NO_DRAM_NIC = 2,
65 MLX5_NIC_IFC_INVALID = 3
65}; 66};
66 67
67static u8 get_nic_interface(struct mlx5_core_dev *dev) 68enum {
69 MLX5_DROP_NEW_HEALTH_WORK,
70};
71
72static u8 get_nic_state(struct mlx5_core_dev *dev)
68{ 73{
69 return (ioread32be(&dev->iseg->cmdq_addr_l_sz) >> 8) & 3; 74 return (ioread32be(&dev->iseg->cmdq_addr_l_sz) >> 8) & 3;
70} 75}
@@ -97,7 +102,7 @@ static int in_fatal(struct mlx5_core_dev *dev)
97 struct mlx5_core_health *health = &dev->priv.health; 102 struct mlx5_core_health *health = &dev->priv.health;
98 struct health_buffer __iomem *h = health->health; 103 struct health_buffer __iomem *h = health->health;
99 104
100 if (get_nic_interface(dev) == MLX5_NIC_IFC_DISABLED) 105 if (get_nic_state(dev) == MLX5_NIC_IFC_DISABLED)
101 return 1; 106 return 1;
102 107
103 if (ioread32be(&h->fw_ver) == 0xffffffff) 108 if (ioread32be(&h->fw_ver) == 0xffffffff)
@@ -127,7 +132,7 @@ unlock:
127 132
128static void mlx5_handle_bad_state(struct mlx5_core_dev *dev) 133static void mlx5_handle_bad_state(struct mlx5_core_dev *dev)
129{ 134{
130 u8 nic_interface = get_nic_interface(dev); 135 u8 nic_interface = get_nic_state(dev);
131 136
132 switch (nic_interface) { 137 switch (nic_interface) {
133 case MLX5_NIC_IFC_FULL: 138 case MLX5_NIC_IFC_FULL:
@@ -149,8 +154,34 @@ static void mlx5_handle_bad_state(struct mlx5_core_dev *dev)
149 mlx5_disable_device(dev); 154 mlx5_disable_device(dev);
150} 155}
151 156
157static void health_recover(struct work_struct *work)
158{
159 struct mlx5_core_health *health;
160 struct delayed_work *dwork;
161 struct mlx5_core_dev *dev;
162 struct mlx5_priv *priv;
163 u8 nic_state;
164
165 dwork = container_of(work, struct delayed_work, work);
166 health = container_of(dwork, struct mlx5_core_health, recover_work);
167 priv = container_of(health, struct mlx5_priv, health);
168 dev = container_of(priv, struct mlx5_core_dev, priv);
169
170 nic_state = get_nic_state(dev);
171 if (nic_state == MLX5_NIC_IFC_INVALID) {
172 dev_err(&dev->pdev->dev, "health recovery flow aborted since the nic state is invalid\n");
173 return;
174 }
175
176 dev_err(&dev->pdev->dev, "starting health recovery flow\n");
177 mlx5_recover_device(dev);
178}
179
180/* How much time to wait until health resetting the driver (in msecs) */
181#define MLX5_RECOVERY_DELAY_MSECS 60000
152static void health_care(struct work_struct *work) 182static void health_care(struct work_struct *work)
153{ 183{
184 unsigned long recover_delay = msecs_to_jiffies(MLX5_RECOVERY_DELAY_MSECS);
154 struct mlx5_core_health *health; 185 struct mlx5_core_health *health;
155 struct mlx5_core_dev *dev; 186 struct mlx5_core_dev *dev;
156 struct mlx5_priv *priv; 187 struct mlx5_priv *priv;
@@ -160,6 +191,14 @@ static void health_care(struct work_struct *work)
160 dev = container_of(priv, struct mlx5_core_dev, priv); 191 dev = container_of(priv, struct mlx5_core_dev, priv);
161 mlx5_core_warn(dev, "handling bad device here\n"); 192 mlx5_core_warn(dev, "handling bad device here\n");
162 mlx5_handle_bad_state(dev); 193 mlx5_handle_bad_state(dev);
194
195 spin_lock(&health->wq_lock);
196 if (!test_bit(MLX5_DROP_NEW_HEALTH_WORK, &health->flags))
197 schedule_delayed_work(&health->recover_work, recover_delay);
198 else
199 dev_err(&dev->pdev->dev,
200 "new health works are not permitted at this stage\n");
201 spin_unlock(&health->wq_lock);
163} 202}
164 203
165static const char *hsynd_str(u8 synd) 204static const char *hsynd_str(u8 synd)
@@ -272,7 +311,13 @@ static void poll_health(unsigned long data)
272 if (in_fatal(dev) && !health->sick) { 311 if (in_fatal(dev) && !health->sick) {
273 health->sick = true; 312 health->sick = true;
274 print_health_info(dev); 313 print_health_info(dev);
275 schedule_work(&health->work); 314 spin_lock(&health->wq_lock);
315 if (!test_bit(MLX5_DROP_NEW_HEALTH_WORK, &health->flags))
316 queue_work(health->wq, &health->work);
317 else
318 dev_err(&dev->pdev->dev,
319 "new health works are not permitted at this stage\n");
320 spin_unlock(&health->wq_lock);
276 } 321 }
277} 322}
278 323
@@ -281,6 +326,8 @@ void mlx5_start_health_poll(struct mlx5_core_dev *dev)
281 struct mlx5_core_health *health = &dev->priv.health; 326 struct mlx5_core_health *health = &dev->priv.health;
282 327
283 init_timer(&health->timer); 328 init_timer(&health->timer);
329 health->sick = 0;
330 clear_bit(MLX5_DROP_NEW_HEALTH_WORK, &health->flags);
284 health->health = &dev->iseg->health; 331 health->health = &dev->iseg->health;
285 health->health_counter = &dev->iseg->health_counter; 332 health->health_counter = &dev->iseg->health_counter;
286 333
@@ -297,11 +344,22 @@ void mlx5_stop_health_poll(struct mlx5_core_dev *dev)
297 del_timer_sync(&health->timer); 344 del_timer_sync(&health->timer);
298} 345}
299 346
347void mlx5_drain_health_wq(struct mlx5_core_dev *dev)
348{
349 struct mlx5_core_health *health = &dev->priv.health;
350
351 spin_lock(&health->wq_lock);
352 set_bit(MLX5_DROP_NEW_HEALTH_WORK, &health->flags);
353 spin_unlock(&health->wq_lock);
354 cancel_delayed_work_sync(&health->recover_work);
355 cancel_work_sync(&health->work);
356}
357
300void mlx5_health_cleanup(struct mlx5_core_dev *dev) 358void mlx5_health_cleanup(struct mlx5_core_dev *dev)
301{ 359{
302 struct mlx5_core_health *health = &dev->priv.health; 360 struct mlx5_core_health *health = &dev->priv.health;
303 361
304 flush_work(&health->work); 362 destroy_workqueue(health->wq);
305} 363}
306 364
307int mlx5_health_init(struct mlx5_core_dev *dev) 365int mlx5_health_init(struct mlx5_core_dev *dev)
@@ -316,9 +374,13 @@ int mlx5_health_init(struct mlx5_core_dev *dev)
316 374
317 strcpy(name, "mlx5_health"); 375 strcpy(name, "mlx5_health");
318 strcat(name, dev_name(&dev->pdev->dev)); 376 strcat(name, dev_name(&dev->pdev->dev));
377 health->wq = create_singlethread_workqueue(name);
319 kfree(name); 378 kfree(name);
320 379 if (!health->wq)
380 return -ENOMEM;
381 spin_lock_init(&health->wq_lock);
321 INIT_WORK(&health->work, health_care); 382 INIT_WORK(&health->work, health_care);
383 INIT_DELAYED_WORK(&health->recover_work, health_recover);
322 384
323 return 0; 385 return 0;
324} 386}
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/main.c b/drivers/net/ethernet/mellanox/mlx5/core/main.c
index d9c3c70b29e4..ada24e103b02 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/main.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/main.c
@@ -46,7 +46,6 @@
46#include <linux/mlx5/srq.h> 46#include <linux/mlx5/srq.h>
47#include <linux/debugfs.h> 47#include <linux/debugfs.h>
48#include <linux/kmod.h> 48#include <linux/kmod.h>
49#include <linux/delay.h>
50#include <linux/mlx5/mlx5_ifc.h> 49#include <linux/mlx5/mlx5_ifc.h>
51#ifdef CONFIG_RFS_ACCEL 50#ifdef CONFIG_RFS_ACCEL
52#include <linux/cpu_rmap.h> 51#include <linux/cpu_rmap.h>
@@ -63,13 +62,13 @@ MODULE_DESCRIPTION("Mellanox Connect-IB, ConnectX-4 core driver");
63MODULE_LICENSE("Dual BSD/GPL"); 62MODULE_LICENSE("Dual BSD/GPL");
64MODULE_VERSION(DRIVER_VERSION); 63MODULE_VERSION(DRIVER_VERSION);
65 64
66int mlx5_core_debug_mask; 65unsigned int mlx5_core_debug_mask;
67module_param_named(debug_mask, mlx5_core_debug_mask, int, 0644); 66module_param_named(debug_mask, mlx5_core_debug_mask, uint, 0644);
68MODULE_PARM_DESC(debug_mask, "debug mask: 1 = dump cmd data, 2 = dump cmd exec time, 3 = both. Default=0"); 67MODULE_PARM_DESC(debug_mask, "debug mask: 1 = dump cmd data, 2 = dump cmd exec time, 3 = both. Default=0");
69 68
70#define MLX5_DEFAULT_PROF 2 69#define MLX5_DEFAULT_PROF 2
71static int prof_sel = MLX5_DEFAULT_PROF; 70static unsigned int prof_sel = MLX5_DEFAULT_PROF;
72module_param_named(prof_sel, prof_sel, int, 0444); 71module_param_named(prof_sel, prof_sel, uint, 0444);
73MODULE_PARM_DESC(prof_sel, "profile selector. Valid range 0 - 2"); 72MODULE_PARM_DESC(prof_sel, "profile selector. Valid range 0 - 2");
74 73
75enum { 74enum {
@@ -733,13 +732,15 @@ static int mlx5_core_set_issi(struct mlx5_core_dev *dev)
733 u8 status; 732 u8 status;
734 733
735 mlx5_cmd_mbox_status(query_out, &status, &syndrome); 734 mlx5_cmd_mbox_status(query_out, &status, &syndrome);
736 if (status == MLX5_CMD_STAT_BAD_OP_ERR) { 735 if (!status || syndrome == MLX5_DRIVER_SYND) {
737 pr_debug("Only ISSI 0 is supported\n"); 736 mlx5_core_err(dev, "Failed to query ISSI err(%d) status(%d) synd(%d)\n",
738 return 0; 737 err, status, syndrome);
738 return err;
739 } 739 }
740 740
741 pr_err("failed to query ISSI err(%d)\n", err); 741 mlx5_core_warn(dev, "Query ISSI is not supported by FW, ISSI is 0\n");
742 return err; 742 dev->issi = 0;
743 return 0;
743 } 744 }
744 745
745 sup_issi = MLX5_GET(query_issi_out, query_out, supported_issi_dw0); 746 sup_issi = MLX5_GET(query_issi_out, query_out, supported_issi_dw0);
@@ -753,7 +754,8 @@ static int mlx5_core_set_issi(struct mlx5_core_dev *dev)
753 err = mlx5_cmd_exec(dev, set_in, sizeof(set_in), 754 err = mlx5_cmd_exec(dev, set_in, sizeof(set_in),
754 set_out, sizeof(set_out)); 755 set_out, sizeof(set_out));
755 if (err) { 756 if (err) {
756 pr_err("failed to set ISSI=1 err(%d)\n", err); 757 mlx5_core_err(dev, "Failed to set ISSI to 1 err(%d)\n",
758 err);
757 return err; 759 return err;
758 } 760 }
759 761
@@ -844,12 +846,6 @@ static int mlx5_init_once(struct mlx5_core_dev *dev, struct mlx5_priv *priv)
844 struct pci_dev *pdev = dev->pdev; 846 struct pci_dev *pdev = dev->pdev;
845 int err; 847 int err;
846 848
847 err = mlx5_query_hca_caps(dev);
848 if (err) {
849 dev_err(&pdev->dev, "query hca failed\n");
850 goto out;
851 }
852
853 err = mlx5_query_board_id(dev); 849 err = mlx5_query_board_id(dev);
854 if (err) { 850 if (err) {
855 dev_err(&pdev->dev, "query board id failed\n"); 851 dev_err(&pdev->dev, "query board id failed\n");
@@ -1023,6 +1019,12 @@ static int mlx5_load_one(struct mlx5_core_dev *dev, struct mlx5_priv *priv,
1023 1019
1024 mlx5_start_health_poll(dev); 1020 mlx5_start_health_poll(dev);
1025 1021
1022 err = mlx5_query_hca_caps(dev);
1023 if (err) {
1024 dev_err(&pdev->dev, "query hca failed\n");
1025 goto err_stop_poll;
1026 }
1027
1026 if (boot && mlx5_init_once(dev, priv)) { 1028 if (boot && mlx5_init_once(dev, priv)) {
1027 dev_err(&pdev->dev, "sw objs init failed\n"); 1029 dev_err(&pdev->dev, "sw objs init failed\n");
1028 goto err_stop_poll; 1030 goto err_stop_poll;
@@ -1226,15 +1228,9 @@ static int init_one(struct pci_dev *pdev,
1226 1228
1227 pci_set_drvdata(pdev, dev); 1229 pci_set_drvdata(pdev, dev);
1228 1230
1229 if (prof_sel < 0 || prof_sel >= ARRAY_SIZE(profile)) {
1230 mlx5_core_warn(dev,
1231 "selected profile out of range, selecting default (%d)\n",
1232 MLX5_DEFAULT_PROF);
1233 prof_sel = MLX5_DEFAULT_PROF;
1234 }
1235 dev->profile = &profile[prof_sel];
1236 dev->pdev = pdev; 1231 dev->pdev = pdev;
1237 dev->event = mlx5_core_event; 1232 dev->event = mlx5_core_event;
1233 dev->profile = &profile[prof_sel];
1238 1234
1239 INIT_LIST_HEAD(&priv->ctx_list); 1235 INIT_LIST_HEAD(&priv->ctx_list);
1240 spin_lock_init(&priv->ctx_lock); 1236 spin_lock_init(&priv->ctx_lock);
@@ -1313,10 +1309,16 @@ static pci_ers_result_t mlx5_pci_err_detected(struct pci_dev *pdev,
1313 struct mlx5_priv *priv = &dev->priv; 1309 struct mlx5_priv *priv = &dev->priv;
1314 1310
1315 dev_info(&pdev->dev, "%s was called\n", __func__); 1311 dev_info(&pdev->dev, "%s was called\n", __func__);
1312
1316 mlx5_enter_error_state(dev); 1313 mlx5_enter_error_state(dev);
1317 mlx5_unload_one(dev, priv, false); 1314 mlx5_unload_one(dev, priv, false);
1318 pci_save_state(pdev); 1315 /* In case of kernel call save the pci state and drain health wq */
1319 mlx5_pci_disable_device(dev); 1316 if (state) {
1317 pci_save_state(pdev);
1318 mlx5_drain_health_wq(dev);
1319 mlx5_pci_disable_device(dev);
1320 }
1321
1320 return state == pci_channel_io_perm_failure ? 1322 return state == pci_channel_io_perm_failure ?
1321 PCI_ERS_RESULT_DISCONNECT : PCI_ERS_RESULT_NEED_RESET; 1323 PCI_ERS_RESULT_DISCONNECT : PCI_ERS_RESULT_NEED_RESET;
1322} 1324}
@@ -1373,11 +1375,6 @@ static pci_ers_result_t mlx5_pci_slot_reset(struct pci_dev *pdev)
1373 return PCI_ERS_RESULT_RECOVERED; 1375 return PCI_ERS_RESULT_RECOVERED;
1374} 1376}
1375 1377
1376void mlx5_disable_device(struct mlx5_core_dev *dev)
1377{
1378 mlx5_pci_err_detected(dev->pdev, 0);
1379}
1380
1381static void mlx5_pci_resume(struct pci_dev *pdev) 1378static void mlx5_pci_resume(struct pci_dev *pdev)
1382{ 1379{
1383 struct mlx5_core_dev *dev = pci_get_drvdata(pdev); 1380 struct mlx5_core_dev *dev = pci_get_drvdata(pdev);
@@ -1427,6 +1424,18 @@ static const struct pci_device_id mlx5_core_pci_table[] = {
1427 1424
1428MODULE_DEVICE_TABLE(pci, mlx5_core_pci_table); 1425MODULE_DEVICE_TABLE(pci, mlx5_core_pci_table);
1429 1426
1427void mlx5_disable_device(struct mlx5_core_dev *dev)
1428{
1429 mlx5_pci_err_detected(dev->pdev, 0);
1430}
1431
1432void mlx5_recover_device(struct mlx5_core_dev *dev)
1433{
1434 mlx5_pci_disable_device(dev);
1435 if (mlx5_pci_slot_reset(dev->pdev) == PCI_ERS_RESULT_RECOVERED)
1436 mlx5_pci_resume(dev->pdev);
1437}
1438
1430static struct pci_driver mlx5_core_driver = { 1439static struct pci_driver mlx5_core_driver = {
1431 .name = DRIVER_NAME, 1440 .name = DRIVER_NAME,
1432 .id_table = mlx5_core_pci_table, 1441 .id_table = mlx5_core_pci_table,
@@ -1437,10 +1446,22 @@ static struct pci_driver mlx5_core_driver = {
1437 .sriov_configure = mlx5_core_sriov_configure, 1446 .sriov_configure = mlx5_core_sriov_configure,
1438}; 1447};
1439 1448
1449static void mlx5_core_verify_params(void)
1450{
1451 if (prof_sel >= ARRAY_SIZE(profile)) {
1452 pr_warn("mlx5_core: WARNING: Invalid module parameter prof_sel %d, valid range 0-%zu, changing back to default(%d)\n",
1453 prof_sel,
1454 ARRAY_SIZE(profile) - 1,
1455 MLX5_DEFAULT_PROF);
1456 prof_sel = MLX5_DEFAULT_PROF;
1457 }
1458}
1459
1440static int __init init(void) 1460static int __init init(void)
1441{ 1461{
1442 int err; 1462 int err;
1443 1463
1464 mlx5_core_verify_params();
1444 mlx5_register_debugfs(); 1465 mlx5_register_debugfs();
1445 1466
1446 err = pci_register_driver(&mlx5_core_driver); 1467 err = pci_register_driver(&mlx5_core_driver);
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/mlx5_core.h b/drivers/net/ethernet/mellanox/mlx5/core/mlx5_core.h
index 3d0cfb9f18f9..63b9a0dba885 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/mlx5_core.h
+++ b/drivers/net/ethernet/mellanox/mlx5/core/mlx5_core.h
@@ -44,11 +44,11 @@
44 44
45#define MLX5_TOTAL_VPORTS(mdev) (1 + pci_sriov_get_totalvfs(mdev->pdev)) 45#define MLX5_TOTAL_VPORTS(mdev) (1 + pci_sriov_get_totalvfs(mdev->pdev))
46 46
47extern int mlx5_core_debug_mask; 47extern uint mlx5_core_debug_mask;
48 48
49#define mlx5_core_dbg(__dev, format, ...) \ 49#define mlx5_core_dbg(__dev, format, ...) \
50 dev_dbg(&(__dev)->pdev->dev, "%s:%s:%d:(pid %d): " format, \ 50 dev_dbg(&(__dev)->pdev->dev, "%s:%d:(pid %d): " format, \
51 (__dev)->priv.name, __func__, __LINE__, current->pid, \ 51 __func__, __LINE__, current->pid, \
52 ##__VA_ARGS__) 52 ##__VA_ARGS__)
53 53
54#define mlx5_core_dbg_mask(__dev, mask, format, ...) \ 54#define mlx5_core_dbg_mask(__dev, mask, format, ...) \
@@ -63,8 +63,8 @@ do { \
63 ##__VA_ARGS__) 63 ##__VA_ARGS__)
64 64
65#define mlx5_core_warn(__dev, format, ...) \ 65#define mlx5_core_warn(__dev, format, ...) \
66 dev_warn(&(__dev)->pdev->dev, "%s:%s:%d:(pid %d): " format, \ 66 dev_warn(&(__dev)->pdev->dev, "%s:%d:(pid %d): " format, \
67 (__dev)->priv.name, __func__, __LINE__, current->pid, \ 67 __func__, __LINE__, current->pid, \
68 ##__VA_ARGS__) 68 ##__VA_ARGS__)
69 69
70#define mlx5_core_info(__dev, format, ...) \ 70#define mlx5_core_info(__dev, format, ...) \
@@ -75,6 +75,11 @@ enum {
75 MLX5_CMD_TIME, /* print command execution time */ 75 MLX5_CMD_TIME, /* print command execution time */
76}; 76};
77 77
78enum {
79 MLX5_DRIVER_STATUS_ABORTED = 0xfe,
80 MLX5_DRIVER_SYND = 0xbadd00de,
81};
82
78int mlx5_query_hca_caps(struct mlx5_core_dev *dev); 83int mlx5_query_hca_caps(struct mlx5_core_dev *dev);
79int mlx5_query_board_id(struct mlx5_core_dev *dev); 84int mlx5_query_board_id(struct mlx5_core_dev *dev);
80int mlx5_cmd_init_hca(struct mlx5_core_dev *dev); 85int mlx5_cmd_init_hca(struct mlx5_core_dev *dev);
@@ -83,6 +88,7 @@ void mlx5_core_event(struct mlx5_core_dev *dev, enum mlx5_dev_event event,
83 unsigned long param); 88 unsigned long param);
84void mlx5_enter_error_state(struct mlx5_core_dev *dev); 89void mlx5_enter_error_state(struct mlx5_core_dev *dev);
85void mlx5_disable_device(struct mlx5_core_dev *dev); 90void mlx5_disable_device(struct mlx5_core_dev *dev);
91void mlx5_recover_device(struct mlx5_core_dev *dev);
86int mlx5_sriov_init(struct mlx5_core_dev *dev); 92int mlx5_sriov_init(struct mlx5_core_dev *dev);
87void mlx5_sriov_cleanup(struct mlx5_core_dev *dev); 93void mlx5_sriov_cleanup(struct mlx5_core_dev *dev);
88int mlx5_sriov_attach(struct mlx5_core_dev *dev); 94int mlx5_sriov_attach(struct mlx5_core_dev *dev);
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/pagealloc.c b/drivers/net/ethernet/mellanox/mlx5/core/pagealloc.c
index cc4fd61914d3..a57d5a81eb05 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/pagealloc.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/pagealloc.c
@@ -209,6 +209,7 @@ static void free_4k(struct mlx5_core_dev *dev, u64 addr)
209static int alloc_system_page(struct mlx5_core_dev *dev, u16 func_id) 209static int alloc_system_page(struct mlx5_core_dev *dev, u16 func_id)
210{ 210{
211 struct page *page; 211 struct page *page;
212 u64 zero_addr = 1;
212 u64 addr; 213 u64 addr;
213 int err; 214 int err;
214 int nid = dev_to_node(&dev->pdev->dev); 215 int nid = dev_to_node(&dev->pdev->dev);
@@ -218,26 +219,35 @@ static int alloc_system_page(struct mlx5_core_dev *dev, u16 func_id)
218 mlx5_core_warn(dev, "failed to allocate page\n"); 219 mlx5_core_warn(dev, "failed to allocate page\n");
219 return -ENOMEM; 220 return -ENOMEM;
220 } 221 }
222map:
221 addr = dma_map_page(&dev->pdev->dev, page, 0, 223 addr = dma_map_page(&dev->pdev->dev, page, 0,
222 PAGE_SIZE, DMA_BIDIRECTIONAL); 224 PAGE_SIZE, DMA_BIDIRECTIONAL);
223 if (dma_mapping_error(&dev->pdev->dev, addr)) { 225 if (dma_mapping_error(&dev->pdev->dev, addr)) {
224 mlx5_core_warn(dev, "failed dma mapping page\n"); 226 mlx5_core_warn(dev, "failed dma mapping page\n");
225 err = -ENOMEM; 227 err = -ENOMEM;
226 goto out_alloc; 228 goto err_mapping;
227 } 229 }
230
231 /* Firmware doesn't support page with physical address 0 */
232 if (addr == 0) {
233 zero_addr = addr;
234 goto map;
235 }
236
228 err = insert_page(dev, addr, page, func_id); 237 err = insert_page(dev, addr, page, func_id);
229 if (err) { 238 if (err) {
230 mlx5_core_err(dev, "failed to track allocated page\n"); 239 mlx5_core_err(dev, "failed to track allocated page\n");
231 goto out_mapping; 240 dma_unmap_page(&dev->pdev->dev, addr, PAGE_SIZE,
241 DMA_BIDIRECTIONAL);
232 } 242 }
233 243
234 return 0; 244err_mapping:
235 245 if (err)
236out_mapping: 246 __free_page(page);
237 dma_unmap_page(&dev->pdev->dev, addr, PAGE_SIZE, DMA_BIDIRECTIONAL);
238 247
239out_alloc: 248 if (zero_addr == 0)
240 __free_page(page); 249 dma_unmap_page(&dev->pdev->dev, zero_addr, PAGE_SIZE,
250 DMA_BIDIRECTIONAL);
241 251
242 return err; 252 return err;
243} 253}
diff --git a/drivers/net/ethernet/mellanox/mlxsw/pci.c b/drivers/net/ethernet/mellanox/mlxsw/pci.c
index e742bd4e8894..912f71f84209 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/pci.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/pci.c
@@ -1838,11 +1838,17 @@ static const struct mlxsw_bus mlxsw_pci_bus = {
1838 .cmd_exec = mlxsw_pci_cmd_exec, 1838 .cmd_exec = mlxsw_pci_cmd_exec,
1839}; 1839};
1840 1840
1841static int mlxsw_pci_sw_reset(struct mlxsw_pci *mlxsw_pci) 1841static int mlxsw_pci_sw_reset(struct mlxsw_pci *mlxsw_pci,
1842 const struct pci_device_id *id)
1842{ 1843{
1843 unsigned long end; 1844 unsigned long end;
1844 1845
1845 mlxsw_pci_write32(mlxsw_pci, SW_RESET, MLXSW_PCI_SW_RESET_RST_BIT); 1846 mlxsw_pci_write32(mlxsw_pci, SW_RESET, MLXSW_PCI_SW_RESET_RST_BIT);
1847 if (id->device == PCI_DEVICE_ID_MELLANOX_SWITCHX2) {
1848 msleep(MLXSW_PCI_SW_RESET_TIMEOUT_MSECS);
1849 return 0;
1850 }
1851
1846 wmb(); /* reset needs to be written before we read control register */ 1852 wmb(); /* reset needs to be written before we read control register */
1847 end = jiffies + msecs_to_jiffies(MLXSW_PCI_SW_RESET_TIMEOUT_MSECS); 1853 end = jiffies + msecs_to_jiffies(MLXSW_PCI_SW_RESET_TIMEOUT_MSECS);
1848 do { 1854 do {
@@ -1909,7 +1915,7 @@ static int mlxsw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1909 mlxsw_pci->pdev = pdev; 1915 mlxsw_pci->pdev = pdev;
1910 pci_set_drvdata(pdev, mlxsw_pci); 1916 pci_set_drvdata(pdev, mlxsw_pci);
1911 1917
1912 err = mlxsw_pci_sw_reset(mlxsw_pci); 1918 err = mlxsw_pci_sw_reset(mlxsw_pci, id);
1913 if (err) { 1919 if (err) {
1914 dev_err(&pdev->dev, "Software reset failed\n"); 1920 dev_err(&pdev->dev, "Software reset failed\n");
1915 goto err_sw_reset; 1921 goto err_sw_reset;
diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c
index 1ec0a4ce3c46..dda5761e91bc 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c
@@ -231,7 +231,7 @@ mlxsw_sp_span_entry_create(struct mlxsw_sp_port *port)
231 231
232 span_entry->used = true; 232 span_entry->used = true;
233 span_entry->id = index; 233 span_entry->id = index;
234 span_entry->ref_count = 0; 234 span_entry->ref_count = 1;
235 span_entry->local_port = local_port; 235 span_entry->local_port = local_port;
236 return span_entry; 236 return span_entry;
237} 237}
@@ -270,6 +270,7 @@ static struct mlxsw_sp_span_entry
270 270
271 span_entry = mlxsw_sp_span_entry_find(port); 271 span_entry = mlxsw_sp_span_entry_find(port);
272 if (span_entry) { 272 if (span_entry) {
273 /* Already exists, just take a reference */
273 span_entry->ref_count++; 274 span_entry->ref_count++;
274 return span_entry; 275 return span_entry;
275 } 276 }
@@ -280,6 +281,7 @@ static struct mlxsw_sp_span_entry
280static int mlxsw_sp_span_entry_put(struct mlxsw_sp *mlxsw_sp, 281static int mlxsw_sp_span_entry_put(struct mlxsw_sp *mlxsw_sp,
281 struct mlxsw_sp_span_entry *span_entry) 282 struct mlxsw_sp_span_entry *span_entry)
282{ 283{
284 WARN_ON(!span_entry->ref_count);
283 if (--span_entry->ref_count == 0) 285 if (--span_entry->ref_count == 0)
284 mlxsw_sp_span_entry_destroy(mlxsw_sp, span_entry); 286 mlxsw_sp_span_entry_destroy(mlxsw_sp, span_entry);
285 return 0; 287 return 0;
diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum.h b/drivers/net/ethernet/mellanox/mlxsw/spectrum.h
index 9b22863a924b..97bbc1d21df8 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum.h
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum.h
@@ -115,7 +115,7 @@ struct mlxsw_sp_rif {
115struct mlxsw_sp_mid { 115struct mlxsw_sp_mid {
116 struct list_head list; 116 struct list_head list;
117 unsigned char addr[ETH_ALEN]; 117 unsigned char addr[ETH_ALEN];
118 u16 vid; 118 u16 fid;
119 u16 mid; 119 u16 mid;
120 unsigned int ref_count; 120 unsigned int ref_count;
121}; 121};
diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c
index 78fc557d6dd7..e83072da6272 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c
@@ -320,6 +320,8 @@ mlxsw_sp_lpm_tree_create(struct mlxsw_sp *mlxsw_sp,
320 lpm_tree); 320 lpm_tree);
321 if (err) 321 if (err)
322 goto err_left_struct_set; 322 goto err_left_struct_set;
323 memcpy(&lpm_tree->prefix_usage, prefix_usage,
324 sizeof(lpm_tree->prefix_usage));
323 return lpm_tree; 325 return lpm_tree;
324 326
325err_left_struct_set: 327err_left_struct_set:
@@ -343,7 +345,8 @@ mlxsw_sp_lpm_tree_get(struct mlxsw_sp *mlxsw_sp,
343 345
344 for (i = 0; i < MLXSW_SP_LPM_TREE_COUNT; i++) { 346 for (i = 0; i < MLXSW_SP_LPM_TREE_COUNT; i++) {
345 lpm_tree = &mlxsw_sp->router.lpm_trees[i]; 347 lpm_tree = &mlxsw_sp->router.lpm_trees[i];
346 if (lpm_tree->proto == proto && 348 if (lpm_tree->ref_count != 0 &&
349 lpm_tree->proto == proto &&
347 mlxsw_sp_prefix_usage_eq(&lpm_tree->prefix_usage, 350 mlxsw_sp_prefix_usage_eq(&lpm_tree->prefix_usage,
348 prefix_usage)) 351 prefix_usage))
349 goto inc_ref_count; 352 goto inc_ref_count;
@@ -591,21 +594,22 @@ static int mlxsw_sp_vrs_init(struct mlxsw_sp *mlxsw_sp)
591 return 0; 594 return 0;
592} 595}
593 596
597static void mlxsw_sp_router_fib_flush(struct mlxsw_sp *mlxsw_sp);
598
594static void mlxsw_sp_vrs_fini(struct mlxsw_sp *mlxsw_sp) 599static void mlxsw_sp_vrs_fini(struct mlxsw_sp *mlxsw_sp)
595{ 600{
601 mlxsw_sp_router_fib_flush(mlxsw_sp);
596 kfree(mlxsw_sp->router.vrs); 602 kfree(mlxsw_sp->router.vrs);
597} 603}
598 604
599struct mlxsw_sp_neigh_key { 605struct mlxsw_sp_neigh_key {
600 unsigned char addr[sizeof(struct in6_addr)]; 606 struct neighbour *n;
601 struct net_device *dev;
602}; 607};
603 608
604struct mlxsw_sp_neigh_entry { 609struct mlxsw_sp_neigh_entry {
605 struct rhash_head ht_node; 610 struct rhash_head ht_node;
606 struct mlxsw_sp_neigh_key key; 611 struct mlxsw_sp_neigh_key key;
607 u16 rif; 612 u16 rif;
608 struct neighbour *n;
609 bool offloaded; 613 bool offloaded;
610 struct delayed_work dw; 614 struct delayed_work dw;
611 struct mlxsw_sp_port *mlxsw_sp_port; 615 struct mlxsw_sp_port *mlxsw_sp_port;
@@ -643,19 +647,15 @@ mlxsw_sp_neigh_entry_remove(struct mlxsw_sp *mlxsw_sp,
643static void mlxsw_sp_router_neigh_update_hw(struct work_struct *work); 647static void mlxsw_sp_router_neigh_update_hw(struct work_struct *work);
644 648
645static struct mlxsw_sp_neigh_entry * 649static struct mlxsw_sp_neigh_entry *
646mlxsw_sp_neigh_entry_create(const void *addr, size_t addr_len, 650mlxsw_sp_neigh_entry_create(struct neighbour *n, u16 rif)
647 struct net_device *dev, u16 rif,
648 struct neighbour *n)
649{ 651{
650 struct mlxsw_sp_neigh_entry *neigh_entry; 652 struct mlxsw_sp_neigh_entry *neigh_entry;
651 653
652 neigh_entry = kzalloc(sizeof(*neigh_entry), GFP_ATOMIC); 654 neigh_entry = kzalloc(sizeof(*neigh_entry), GFP_ATOMIC);
653 if (!neigh_entry) 655 if (!neigh_entry)
654 return NULL; 656 return NULL;
655 memcpy(neigh_entry->key.addr, addr, addr_len); 657 neigh_entry->key.n = n;
656 neigh_entry->key.dev = dev;
657 neigh_entry->rif = rif; 658 neigh_entry->rif = rif;
658 neigh_entry->n = n;
659 INIT_DELAYED_WORK(&neigh_entry->dw, mlxsw_sp_router_neigh_update_hw); 659 INIT_DELAYED_WORK(&neigh_entry->dw, mlxsw_sp_router_neigh_update_hw);
660 INIT_LIST_HEAD(&neigh_entry->nexthop_list); 660 INIT_LIST_HEAD(&neigh_entry->nexthop_list);
661 return neigh_entry; 661 return neigh_entry;
@@ -668,13 +668,11 @@ mlxsw_sp_neigh_entry_destroy(struct mlxsw_sp_neigh_entry *neigh_entry)
668} 668}
669 669
670static struct mlxsw_sp_neigh_entry * 670static struct mlxsw_sp_neigh_entry *
671mlxsw_sp_neigh_entry_lookup(struct mlxsw_sp *mlxsw_sp, const void *addr, 671mlxsw_sp_neigh_entry_lookup(struct mlxsw_sp *mlxsw_sp, struct neighbour *n)
672 size_t addr_len, struct net_device *dev)
673{ 672{
674 struct mlxsw_sp_neigh_key key = {{ 0 } }; 673 struct mlxsw_sp_neigh_key key;
675 674
676 memcpy(key.addr, addr, addr_len); 675 key.n = n;
677 key.dev = dev;
678 return rhashtable_lookup_fast(&mlxsw_sp->router.neigh_ht, 676 return rhashtable_lookup_fast(&mlxsw_sp->router.neigh_ht,
679 &key, mlxsw_sp_neigh_ht_params); 677 &key, mlxsw_sp_neigh_ht_params);
680} 678}
@@ -686,26 +684,20 @@ int mlxsw_sp_router_neigh_construct(struct net_device *dev,
686 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp; 684 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
687 struct mlxsw_sp_neigh_entry *neigh_entry; 685 struct mlxsw_sp_neigh_entry *neigh_entry;
688 struct mlxsw_sp_rif *r; 686 struct mlxsw_sp_rif *r;
689 u32 dip;
690 int err; 687 int err;
691 688
692 if (n->tbl != &arp_tbl) 689 if (n->tbl != &arp_tbl)
693 return 0; 690 return 0;
694 691
695 dip = ntohl(*((__be32 *) n->primary_key)); 692 neigh_entry = mlxsw_sp_neigh_entry_lookup(mlxsw_sp, n);
696 neigh_entry = mlxsw_sp_neigh_entry_lookup(mlxsw_sp, &dip, sizeof(dip), 693 if (neigh_entry)
697 n->dev);
698 if (neigh_entry) {
699 WARN_ON(neigh_entry->n != n);
700 return 0; 694 return 0;
701 }
702 695
703 r = mlxsw_sp_rif_find_by_dev(mlxsw_sp, n->dev); 696 r = mlxsw_sp_rif_find_by_dev(mlxsw_sp, n->dev);
704 if (WARN_ON(!r)) 697 if (WARN_ON(!r))
705 return -EINVAL; 698 return -EINVAL;
706 699
707 neigh_entry = mlxsw_sp_neigh_entry_create(&dip, sizeof(dip), n->dev, 700 neigh_entry = mlxsw_sp_neigh_entry_create(n, r->rif);
708 r->rif, n);
709 if (!neigh_entry) 701 if (!neigh_entry)
710 return -ENOMEM; 702 return -ENOMEM;
711 err = mlxsw_sp_neigh_entry_insert(mlxsw_sp, neigh_entry); 703 err = mlxsw_sp_neigh_entry_insert(mlxsw_sp, neigh_entry);
@@ -724,14 +716,11 @@ void mlxsw_sp_router_neigh_destroy(struct net_device *dev,
724 struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev); 716 struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev);
725 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp; 717 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
726 struct mlxsw_sp_neigh_entry *neigh_entry; 718 struct mlxsw_sp_neigh_entry *neigh_entry;
727 u32 dip;
728 719
729 if (n->tbl != &arp_tbl) 720 if (n->tbl != &arp_tbl)
730 return; 721 return;
731 722
732 dip = ntohl(*((__be32 *) n->primary_key)); 723 neigh_entry = mlxsw_sp_neigh_entry_lookup(mlxsw_sp, n);
733 neigh_entry = mlxsw_sp_neigh_entry_lookup(mlxsw_sp, &dip, sizeof(dip),
734 n->dev);
735 if (!neigh_entry) 724 if (!neigh_entry)
736 return; 725 return;
737 mlxsw_sp_neigh_entry_remove(mlxsw_sp, neigh_entry); 726 mlxsw_sp_neigh_entry_remove(mlxsw_sp, neigh_entry);
@@ -814,6 +803,26 @@ static void mlxsw_sp_router_neigh_rec_process(struct mlxsw_sp *mlxsw_sp,
814 } 803 }
815} 804}
816 805
806static bool mlxsw_sp_router_rauhtd_is_full(char *rauhtd_pl)
807{
808 u8 num_rec, last_rec_index, num_entries;
809
810 num_rec = mlxsw_reg_rauhtd_num_rec_get(rauhtd_pl);
811 last_rec_index = num_rec - 1;
812
813 if (num_rec < MLXSW_REG_RAUHTD_REC_MAX_NUM)
814 return false;
815 if (mlxsw_reg_rauhtd_rec_type_get(rauhtd_pl, last_rec_index) ==
816 MLXSW_REG_RAUHTD_TYPE_IPV6)
817 return true;
818
819 num_entries = mlxsw_reg_rauhtd_ipv4_rec_num_entries_get(rauhtd_pl,
820 last_rec_index);
821 if (++num_entries == MLXSW_REG_RAUHTD_IPV4_ENT_PER_REC)
822 return true;
823 return false;
824}
825
817static int mlxsw_sp_router_neighs_update_rauhtd(struct mlxsw_sp *mlxsw_sp) 826static int mlxsw_sp_router_neighs_update_rauhtd(struct mlxsw_sp *mlxsw_sp)
818{ 827{
819 char *rauhtd_pl; 828 char *rauhtd_pl;
@@ -840,7 +849,7 @@ static int mlxsw_sp_router_neighs_update_rauhtd(struct mlxsw_sp *mlxsw_sp)
840 for (i = 0; i < num_rec; i++) 849 for (i = 0; i < num_rec; i++)
841 mlxsw_sp_router_neigh_rec_process(mlxsw_sp, rauhtd_pl, 850 mlxsw_sp_router_neigh_rec_process(mlxsw_sp, rauhtd_pl,
842 i); 851 i);
843 } while (num_rec); 852 } while (mlxsw_sp_router_rauhtd_is_full(rauhtd_pl));
844 rtnl_unlock(); 853 rtnl_unlock();
845 854
846 kfree(rauhtd_pl); 855 kfree(rauhtd_pl);
@@ -859,7 +868,7 @@ static void mlxsw_sp_router_neighs_update_nh(struct mlxsw_sp *mlxsw_sp)
859 * is active regardless of the traffic. 868 * is active regardless of the traffic.
860 */ 869 */
861 if (!list_empty(&neigh_entry->nexthop_list)) 870 if (!list_empty(&neigh_entry->nexthop_list))
862 neigh_event_send(neigh_entry->n, NULL); 871 neigh_event_send(neigh_entry->key.n, NULL);
863 } 872 }
864 rtnl_unlock(); 873 rtnl_unlock();
865} 874}
@@ -905,9 +914,9 @@ static void mlxsw_sp_router_probe_unresolved_nexthops(struct work_struct *work)
905 rtnl_lock(); 914 rtnl_lock();
906 list_for_each_entry(neigh_entry, &mlxsw_sp->router.nexthop_neighs_list, 915 list_for_each_entry(neigh_entry, &mlxsw_sp->router.nexthop_neighs_list,
907 nexthop_neighs_list_node) { 916 nexthop_neighs_list_node) {
908 if (!(neigh_entry->n->nud_state & NUD_VALID) && 917 if (!(neigh_entry->key.n->nud_state & NUD_VALID) &&
909 !list_empty(&neigh_entry->nexthop_list)) 918 !list_empty(&neigh_entry->nexthop_list))
910 neigh_event_send(neigh_entry->n, NULL); 919 neigh_event_send(neigh_entry->key.n, NULL);
911 } 920 }
912 rtnl_unlock(); 921 rtnl_unlock();
913 922
@@ -924,7 +933,7 @@ static void mlxsw_sp_router_neigh_update_hw(struct work_struct *work)
924{ 933{
925 struct mlxsw_sp_neigh_entry *neigh_entry = 934 struct mlxsw_sp_neigh_entry *neigh_entry =
926 container_of(work, struct mlxsw_sp_neigh_entry, dw.work); 935 container_of(work, struct mlxsw_sp_neigh_entry, dw.work);
927 struct neighbour *n = neigh_entry->n; 936 struct neighbour *n = neigh_entry->key.n;
928 struct mlxsw_sp_port *mlxsw_sp_port = neigh_entry->mlxsw_sp_port; 937 struct mlxsw_sp_port *mlxsw_sp_port = neigh_entry->mlxsw_sp_port;
929 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp; 938 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
930 char rauht_pl[MLXSW_REG_RAUHT_LEN]; 939 char rauht_pl[MLXSW_REG_RAUHT_LEN];
@@ -1027,11 +1036,8 @@ int mlxsw_sp_router_netevent_event(struct notifier_block *unused,
1027 1036
1028 mlxsw_sp = mlxsw_sp_port->mlxsw_sp; 1037 mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
1029 dip = ntohl(*((__be32 *) n->primary_key)); 1038 dip = ntohl(*((__be32 *) n->primary_key));
1030 neigh_entry = mlxsw_sp_neigh_entry_lookup(mlxsw_sp, 1039 neigh_entry = mlxsw_sp_neigh_entry_lookup(mlxsw_sp, n);
1031 &dip, 1040 if (WARN_ON(!neigh_entry)) {
1032 sizeof(__be32),
1033 dev);
1034 if (WARN_ON(!neigh_entry) || WARN_ON(neigh_entry->n != n)) {
1035 mlxsw_sp_port_dev_put(mlxsw_sp_port); 1041 mlxsw_sp_port_dev_put(mlxsw_sp_port);
1036 return NOTIFY_DONE; 1042 return NOTIFY_DONE;
1037 } 1043 }
@@ -1340,33 +1346,26 @@ static int mlxsw_sp_nexthop_init(struct mlxsw_sp *mlxsw_sp,
1340 struct fib_nh *fib_nh) 1346 struct fib_nh *fib_nh)
1341{ 1347{
1342 struct mlxsw_sp_neigh_entry *neigh_entry; 1348 struct mlxsw_sp_neigh_entry *neigh_entry;
1343 u32 gwip = ntohl(fib_nh->nh_gw);
1344 struct net_device *dev = fib_nh->nh_dev; 1349 struct net_device *dev = fib_nh->nh_dev;
1345 struct neighbour *n; 1350 struct neighbour *n;
1346 u8 nud_state; 1351 u8 nud_state;
1347 1352
1348 neigh_entry = mlxsw_sp_neigh_entry_lookup(mlxsw_sp, &gwip, 1353 /* Take a reference of neigh here ensuring that neigh would
1349 sizeof(gwip), dev); 1354 * not be detructed before the nexthop entry is finished.
1350 if (!neigh_entry) { 1355 * The reference is taken either in neigh_lookup() or
1351 __be32 gwipn = htonl(gwip); 1356 * in neith_create() in case n is not found.
1352 1357 */
1353 n = neigh_create(&arp_tbl, &gwipn, dev); 1358 n = neigh_lookup(&arp_tbl, &fib_nh->nh_gw, dev);
1359 if (!n) {
1360 n = neigh_create(&arp_tbl, &fib_nh->nh_gw, dev);
1354 if (IS_ERR(n)) 1361 if (IS_ERR(n))
1355 return PTR_ERR(n); 1362 return PTR_ERR(n);
1356 neigh_event_send(n, NULL); 1363 neigh_event_send(n, NULL);
1357 neigh_entry = mlxsw_sp_neigh_entry_lookup(mlxsw_sp, &gwip, 1364 }
1358 sizeof(gwip), dev); 1365 neigh_entry = mlxsw_sp_neigh_entry_lookup(mlxsw_sp, n);
1359 if (!neigh_entry) { 1366 if (!neigh_entry) {
1360 neigh_release(n); 1367 neigh_release(n);
1361 return -EINVAL; 1368 return -EINVAL;
1362 }
1363 } else {
1364 /* Take a reference of neigh here ensuring that neigh would
1365 * not be detructed before the nexthop entry is finished.
1366 * The second branch takes the reference in neith_create()
1367 */
1368 n = neigh_entry->n;
1369 neigh_clone(n);
1370 } 1369 }
1371 1370
1372 /* If that is the first nexthop connected to that neigh, add to 1371 /* If that is the first nexthop connected to that neigh, add to
@@ -1400,7 +1399,7 @@ static void mlxsw_sp_nexthop_fini(struct mlxsw_sp *mlxsw_sp,
1400 if (list_empty(&nh->neigh_entry->nexthop_list)) 1399 if (list_empty(&nh->neigh_entry->nexthop_list))
1401 list_del(&nh->neigh_entry->nexthop_neighs_list_node); 1400 list_del(&nh->neigh_entry->nexthop_neighs_list_node);
1402 1401
1403 neigh_release(neigh_entry->n); 1402 neigh_release(neigh_entry->key.n);
1404} 1403}
1405 1404
1406static struct mlxsw_sp_nexthop_group * 1405static struct mlxsw_sp_nexthop_group *
@@ -1460,11 +1459,11 @@ static bool mlxsw_sp_nexthop_match(struct mlxsw_sp_nexthop *nh,
1460 1459
1461 for (i = 0; i < fi->fib_nhs; i++) { 1460 for (i = 0; i < fi->fib_nhs; i++) {
1462 struct fib_nh *fib_nh = &fi->fib_nh[i]; 1461 struct fib_nh *fib_nh = &fi->fib_nh[i];
1463 u32 gwip = ntohl(fib_nh->nh_gw); 1462 struct neighbour *n = nh->neigh_entry->key.n;
1464 1463
1465 if (memcmp(nh->neigh_entry->key.addr, 1464 if (memcmp(n->primary_key, &fib_nh->nh_gw,
1466 &gwip, sizeof(u32)) == 0 && 1465 sizeof(fib_nh->nh_gw)) == 0 &&
1467 nh->neigh_entry->key.dev == fib_nh->nh_dev) 1466 n->dev == fib_nh->nh_dev)
1468 return true; 1467 return true;
1469 } 1468 }
1470 return false; 1469 return false;
@@ -1820,19 +1819,17 @@ err_fib_entry_insert:
1820 return err; 1819 return err;
1821} 1820}
1822 1821
1823static int mlxsw_sp_router_fib4_del(struct mlxsw_sp *mlxsw_sp, 1822static void mlxsw_sp_router_fib4_del(struct mlxsw_sp *mlxsw_sp,
1824 struct fib_entry_notifier_info *fen_info) 1823 struct fib_entry_notifier_info *fen_info)
1825{ 1824{
1826 struct mlxsw_sp_fib_entry *fib_entry; 1825 struct mlxsw_sp_fib_entry *fib_entry;
1827 1826
1828 if (mlxsw_sp->router.aborted) 1827 if (mlxsw_sp->router.aborted)
1829 return 0; 1828 return;
1830 1829
1831 fib_entry = mlxsw_sp_fib_entry_find(mlxsw_sp, fen_info); 1830 fib_entry = mlxsw_sp_fib_entry_find(mlxsw_sp, fen_info);
1832 if (!fib_entry) { 1831 if (!fib_entry)
1833 dev_warn(mlxsw_sp->bus_info->dev, "Failed to find FIB4 entry being removed.\n"); 1832 return;
1834 return -ENOENT;
1835 }
1836 1833
1837 if (fib_entry->ref_count == 1) { 1834 if (fib_entry->ref_count == 1) {
1838 mlxsw_sp_fib_entry_del(mlxsw_sp, fib_entry); 1835 mlxsw_sp_fib_entry_del(mlxsw_sp, fib_entry);
@@ -1840,7 +1837,6 @@ static int mlxsw_sp_router_fib4_del(struct mlxsw_sp *mlxsw_sp,
1840 } 1837 }
1841 1838
1842 mlxsw_sp_fib_entry_put(mlxsw_sp, fib_entry); 1839 mlxsw_sp_fib_entry_put(mlxsw_sp, fib_entry);
1843 return 0;
1844} 1840}
1845 1841
1846static int mlxsw_sp_router_set_abort_trap(struct mlxsw_sp *mlxsw_sp) 1842static int mlxsw_sp_router_set_abort_trap(struct mlxsw_sp *mlxsw_sp)
@@ -1862,7 +1858,8 @@ static int mlxsw_sp_router_set_abort_trap(struct mlxsw_sp *mlxsw_sp)
1862 if (err) 1858 if (err)
1863 return err; 1859 return err;
1864 1860
1865 mlxsw_reg_raltb_pack(raltb_pl, 0, MLXSW_REG_RALXX_PROTOCOL_IPV4, 0); 1861 mlxsw_reg_raltb_pack(raltb_pl, 0, MLXSW_REG_RALXX_PROTOCOL_IPV4,
1862 MLXSW_SP_LPM_TREE_MIN);
1866 err = mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(raltb), raltb_pl); 1863 err = mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(raltb), raltb_pl);
1867 if (err) 1864 if (err)
1868 return err; 1865 return err;
@@ -1873,18 +1870,18 @@ static int mlxsw_sp_router_set_abort_trap(struct mlxsw_sp *mlxsw_sp)
1873 return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(ralue), ralue_pl); 1870 return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(ralue), ralue_pl);
1874} 1871}
1875 1872
1876static void mlxsw_sp_router_fib4_abort(struct mlxsw_sp *mlxsw_sp) 1873static void mlxsw_sp_router_fib_flush(struct mlxsw_sp *mlxsw_sp)
1877{ 1874{
1878 struct mlxsw_resources *resources; 1875 struct mlxsw_resources *resources;
1879 struct mlxsw_sp_fib_entry *fib_entry; 1876 struct mlxsw_sp_fib_entry *fib_entry;
1880 struct mlxsw_sp_fib_entry *tmp; 1877 struct mlxsw_sp_fib_entry *tmp;
1881 struct mlxsw_sp_vr *vr; 1878 struct mlxsw_sp_vr *vr;
1882 int i; 1879 int i;
1883 int err;
1884 1880
1885 resources = mlxsw_core_resources_get(mlxsw_sp->core); 1881 resources = mlxsw_core_resources_get(mlxsw_sp->core);
1886 for (i = 0; i < resources->max_virtual_routers; i++) { 1882 for (i = 0; i < resources->max_virtual_routers; i++) {
1887 vr = &mlxsw_sp->router.vrs[i]; 1883 vr = &mlxsw_sp->router.vrs[i];
1884
1888 if (!vr->used) 1885 if (!vr->used)
1889 continue; 1886 continue;
1890 1887
@@ -1900,6 +1897,13 @@ static void mlxsw_sp_router_fib4_abort(struct mlxsw_sp *mlxsw_sp)
1900 break; 1897 break;
1901 } 1898 }
1902 } 1899 }
1900}
1901
1902static void mlxsw_sp_router_fib4_abort(struct mlxsw_sp *mlxsw_sp)
1903{
1904 int err;
1905
1906 mlxsw_sp_router_fib_flush(mlxsw_sp);
1903 mlxsw_sp->router.aborted = true; 1907 mlxsw_sp->router.aborted = true;
1904 err = mlxsw_sp_router_set_abort_trap(mlxsw_sp); 1908 err = mlxsw_sp_router_set_abort_trap(mlxsw_sp);
1905 if (err) 1909 if (err)
@@ -1957,6 +1961,9 @@ static int mlxsw_sp_router_fib_event(struct notifier_block *nb,
1957 struct fib_entry_notifier_info *fen_info = ptr; 1961 struct fib_entry_notifier_info *fen_info = ptr;
1958 int err; 1962 int err;
1959 1963
1964 if (!net_eq(fen_info->info.net, &init_net))
1965 return NOTIFY_DONE;
1966
1960 switch (event) { 1967 switch (event) {
1961 case FIB_EVENT_ENTRY_ADD: 1968 case FIB_EVENT_ENTRY_ADD:
1962 err = mlxsw_sp_router_fib4_add(mlxsw_sp, fen_info); 1969 err = mlxsw_sp_router_fib4_add(mlxsw_sp, fen_info);
diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c
index 5e00c79e8133..1e2c8eca3af1 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c
@@ -929,12 +929,12 @@ static int mlxsw_sp_port_smid_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 mid,
929 929
930static struct mlxsw_sp_mid *__mlxsw_sp_mc_get(struct mlxsw_sp *mlxsw_sp, 930static struct mlxsw_sp_mid *__mlxsw_sp_mc_get(struct mlxsw_sp *mlxsw_sp,
931 const unsigned char *addr, 931 const unsigned char *addr,
932 u16 vid) 932 u16 fid)
933{ 933{
934 struct mlxsw_sp_mid *mid; 934 struct mlxsw_sp_mid *mid;
935 935
936 list_for_each_entry(mid, &mlxsw_sp->br_mids.list, list) { 936 list_for_each_entry(mid, &mlxsw_sp->br_mids.list, list) {
937 if (ether_addr_equal(mid->addr, addr) && mid->vid == vid) 937 if (ether_addr_equal(mid->addr, addr) && mid->fid == fid)
938 return mid; 938 return mid;
939 } 939 }
940 return NULL; 940 return NULL;
@@ -942,7 +942,7 @@ static struct mlxsw_sp_mid *__mlxsw_sp_mc_get(struct mlxsw_sp *mlxsw_sp,
942 942
943static struct mlxsw_sp_mid *__mlxsw_sp_mc_alloc(struct mlxsw_sp *mlxsw_sp, 943static struct mlxsw_sp_mid *__mlxsw_sp_mc_alloc(struct mlxsw_sp *mlxsw_sp,
944 const unsigned char *addr, 944 const unsigned char *addr,
945 u16 vid) 945 u16 fid)
946{ 946{
947 struct mlxsw_sp_mid *mid; 947 struct mlxsw_sp_mid *mid;
948 u16 mid_idx; 948 u16 mid_idx;
@@ -958,7 +958,7 @@ static struct mlxsw_sp_mid *__mlxsw_sp_mc_alloc(struct mlxsw_sp *mlxsw_sp,
958 958
959 set_bit(mid_idx, mlxsw_sp->br_mids.mapped); 959 set_bit(mid_idx, mlxsw_sp->br_mids.mapped);
960 ether_addr_copy(mid->addr, addr); 960 ether_addr_copy(mid->addr, addr);
961 mid->vid = vid; 961 mid->fid = fid;
962 mid->mid = mid_idx; 962 mid->mid = mid_idx;
963 mid->ref_count = 0; 963 mid->ref_count = 0;
964 list_add_tail(&mid->list, &mlxsw_sp->br_mids.list); 964 list_add_tail(&mid->list, &mlxsw_sp->br_mids.list);
@@ -991,9 +991,9 @@ static int mlxsw_sp_port_mdb_add(struct mlxsw_sp_port *mlxsw_sp_port,
991 if (switchdev_trans_ph_prepare(trans)) 991 if (switchdev_trans_ph_prepare(trans))
992 return 0; 992 return 0;
993 993
994 mid = __mlxsw_sp_mc_get(mlxsw_sp, mdb->addr, mdb->vid); 994 mid = __mlxsw_sp_mc_get(mlxsw_sp, mdb->addr, fid);
995 if (!mid) { 995 if (!mid) {
996 mid = __mlxsw_sp_mc_alloc(mlxsw_sp, mdb->addr, mdb->vid); 996 mid = __mlxsw_sp_mc_alloc(mlxsw_sp, mdb->addr, fid);
997 if (!mid) { 997 if (!mid) {
998 netdev_err(dev, "Unable to allocate MC group\n"); 998 netdev_err(dev, "Unable to allocate MC group\n");
999 return -ENOMEM; 999 return -ENOMEM;
@@ -1137,7 +1137,7 @@ static int mlxsw_sp_port_mdb_del(struct mlxsw_sp_port *mlxsw_sp_port,
1137 u16 mid_idx; 1137 u16 mid_idx;
1138 int err = 0; 1138 int err = 0;
1139 1139
1140 mid = __mlxsw_sp_mc_get(mlxsw_sp, mdb->addr, mdb->vid); 1140 mid = __mlxsw_sp_mc_get(mlxsw_sp, mdb->addr, fid);
1141 if (!mid) { 1141 if (!mid) {
1142 netdev_err(dev, "Unable to remove port from MC DB\n"); 1142 netdev_err(dev, "Unable to remove port from MC DB\n");
1143 return -EINVAL; 1143 return -EINVAL;
diff --git a/drivers/net/ethernet/mellanox/mlxsw/switchx2.c b/drivers/net/ethernet/mellanox/mlxsw/switchx2.c
index c0c23e2f3275..92bda8703f87 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/switchx2.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/switchx2.c
@@ -1088,6 +1088,7 @@ err_port_stp_state_set:
1088err_port_admin_status_set: 1088err_port_admin_status_set:
1089err_port_mtu_set: 1089err_port_mtu_set:
1090err_port_speed_set: 1090err_port_speed_set:
1091 mlxsw_sx_port_swid_set(mlxsw_sx_port, MLXSW_PORT_SWID_DISABLED_PORT);
1091err_port_swid_set: 1092err_port_swid_set:
1092err_port_system_port_mapping_set: 1093err_port_system_port_mapping_set:
1093port_not_usable: 1094port_not_usable:
diff --git a/drivers/net/ethernet/qlogic/Kconfig b/drivers/net/ethernet/qlogic/Kconfig
index 1e8339a67f6e..32f2a45f4ab2 100644
--- a/drivers/net/ethernet/qlogic/Kconfig
+++ b/drivers/net/ethernet/qlogic/Kconfig
@@ -107,4 +107,7 @@ config QEDE
107 ---help--- 107 ---help---
108 This enables the support for ... 108 This enables the support for ...
109 109
110config QED_RDMA
111 bool
112
110endif # NET_VENDOR_QLOGIC 113endif # NET_VENDOR_QLOGIC
diff --git a/drivers/net/ethernet/qlogic/qed/Makefile b/drivers/net/ethernet/qlogic/qed/Makefile
index cda0af7fbc20..967acf322c09 100644
--- a/drivers/net/ethernet/qlogic/qed/Makefile
+++ b/drivers/net/ethernet/qlogic/qed/Makefile
@@ -5,4 +5,4 @@ qed-y := qed_cxt.o qed_dev.o qed_hw.o qed_init_fw_funcs.o qed_init_ops.o \
5 qed_selftest.o qed_dcbx.o qed_debug.o 5 qed_selftest.o qed_dcbx.o qed_debug.o
6qed-$(CONFIG_QED_SRIOV) += qed_sriov.o qed_vf.o 6qed-$(CONFIG_QED_SRIOV) += qed_sriov.o qed_vf.o
7qed-$(CONFIG_QED_LL2) += qed_ll2.o 7qed-$(CONFIG_QED_LL2) += qed_ll2.o
8qed-$(CONFIG_INFINIBAND_QEDR) += qed_roce.o 8qed-$(CONFIG_QED_RDMA) += qed_roce.o
diff --git a/drivers/net/ethernet/qlogic/qed/qed_cxt.c b/drivers/net/ethernet/qlogic/qed/qed_cxt.c
index 82370a1a59ad..0c42c240b5cf 100644
--- a/drivers/net/ethernet/qlogic/qed/qed_cxt.c
+++ b/drivers/net/ethernet/qlogic/qed/qed_cxt.c
@@ -47,13 +47,8 @@
47#define TM_ALIGN BIT(TM_SHIFT) 47#define TM_ALIGN BIT(TM_SHIFT)
48#define TM_ELEM_SIZE 4 48#define TM_ELEM_SIZE 4
49 49
50/* ILT constants */
51#if IS_ENABLED(CONFIG_INFINIBAND_QEDR)
52/* For RoCE we configure to 64K to cover for RoCE max tasks 256K purpose. */ 50/* For RoCE we configure to 64K to cover for RoCE max tasks 256K purpose. */
53#define ILT_DEFAULT_HW_P_SIZE 4 51#define ILT_DEFAULT_HW_P_SIZE (IS_ENABLED(CONFIG_QED_RDMA) ? 4 : 3)
54#else
55#define ILT_DEFAULT_HW_P_SIZE 3
56#endif
57 52
58#define ILT_PAGE_IN_BYTES(hw_p_size) (1U << ((hw_p_size) + 12)) 53#define ILT_PAGE_IN_BYTES(hw_p_size) (1U << ((hw_p_size) + 12))
59#define ILT_CFG_REG(cli, reg) PSWRQ2_REG_ ## cli ## _ ## reg ## _RT_OFFSET 54#define ILT_CFG_REG(cli, reg) PSWRQ2_REG_ ## cli ## _ ## reg ## _RT_OFFSET
@@ -349,14 +344,14 @@ static struct qed_tid_seg *qed_cxt_tid_seg_info(struct qed_hwfn *p_hwfn,
349 return NULL; 344 return NULL;
350} 345}
351 346
352void qed_cxt_set_srq_count(struct qed_hwfn *p_hwfn, u32 num_srqs) 347static void qed_cxt_set_srq_count(struct qed_hwfn *p_hwfn, u32 num_srqs)
353{ 348{
354 struct qed_cxt_mngr *p_mgr = p_hwfn->p_cxt_mngr; 349 struct qed_cxt_mngr *p_mgr = p_hwfn->p_cxt_mngr;
355 350
356 p_mgr->srq_count = num_srqs; 351 p_mgr->srq_count = num_srqs;
357} 352}
358 353
359u32 qed_cxt_get_srq_count(struct qed_hwfn *p_hwfn) 354static u32 qed_cxt_get_srq_count(struct qed_hwfn *p_hwfn)
360{ 355{
361 struct qed_cxt_mngr *p_mgr = p_hwfn->p_cxt_mngr; 356 struct qed_cxt_mngr *p_mgr = p_hwfn->p_cxt_mngr;
362 357
@@ -1804,8 +1799,8 @@ int qed_cxt_get_cid_info(struct qed_hwfn *p_hwfn, struct qed_cxt_info *p_info)
1804 return 0; 1799 return 0;
1805} 1800}
1806 1801
1807void qed_rdma_set_pf_params(struct qed_hwfn *p_hwfn, 1802static void qed_rdma_set_pf_params(struct qed_hwfn *p_hwfn,
1808 struct qed_rdma_pf_params *p_params) 1803 struct qed_rdma_pf_params *p_params)
1809{ 1804{
1810 u32 num_cons, num_tasks, num_qps, num_mrs, num_srqs; 1805 u32 num_cons, num_tasks, num_qps, num_mrs, num_srqs;
1811 enum protocol_type proto; 1806 enum protocol_type proto;
diff --git a/drivers/net/ethernet/qlogic/qed/qed_dcbx.c b/drivers/net/ethernet/qlogic/qed/qed_dcbx.c
index 130da1c0490b..a4789a93b692 100644
--- a/drivers/net/ethernet/qlogic/qed/qed_dcbx.c
+++ b/drivers/net/ethernet/qlogic/qed/qed_dcbx.c
@@ -1190,6 +1190,7 @@ int qed_dcbx_get_config_params(struct qed_hwfn *p_hwfn,
1190 if (!dcbx_info) 1190 if (!dcbx_info)
1191 return -ENOMEM; 1191 return -ENOMEM;
1192 1192
1193 memset(dcbx_info, 0, sizeof(*dcbx_info));
1193 rc = qed_dcbx_query_params(p_hwfn, dcbx_info, QED_DCBX_OPERATIONAL_MIB); 1194 rc = qed_dcbx_query_params(p_hwfn, dcbx_info, QED_DCBX_OPERATIONAL_MIB);
1194 if (rc) { 1195 if (rc) {
1195 kfree(dcbx_info); 1196 kfree(dcbx_info);
@@ -1225,6 +1226,7 @@ static struct qed_dcbx_get *qed_dcbnl_get_dcbx(struct qed_hwfn *hwfn,
1225 if (!dcbx_info) 1226 if (!dcbx_info)
1226 return NULL; 1227 return NULL;
1227 1228
1229 memset(dcbx_info, 0, sizeof(*dcbx_info));
1228 if (qed_dcbx_query_params(hwfn, dcbx_info, type)) { 1230 if (qed_dcbx_query_params(hwfn, dcbx_info, type)) {
1229 kfree(dcbx_info); 1231 kfree(dcbx_info);
1230 return NULL; 1232 return NULL;
diff --git a/drivers/net/ethernet/qlogic/qed/qed_debug.c b/drivers/net/ethernet/qlogic/qed/qed_debug.c
index 88e7d5bef909..68f19ca57f96 100644
--- a/drivers/net/ethernet/qlogic/qed/qed_debug.c
+++ b/drivers/net/ethernet/qlogic/qed/qed_debug.c
@@ -405,7 +405,7 @@ struct phy_defs {
405/***************************** Constant Arrays *******************************/ 405/***************************** Constant Arrays *******************************/
406 406
407/* Debug arrays */ 407/* Debug arrays */
408static struct dbg_array s_dbg_arrays[MAX_BIN_DBG_BUFFER_TYPE] = { {0} }; 408static struct dbg_array s_dbg_arrays[MAX_BIN_DBG_BUFFER_TYPE] = { {NULL} };
409 409
410/* Chip constant definitions array */ 410/* Chip constant definitions array */
411static struct chip_defs s_chip_defs[MAX_CHIP_IDS] = { 411static struct chip_defs s_chip_defs[MAX_CHIP_IDS] = {
@@ -4028,10 +4028,10 @@ static enum dbg_status qed_mcp_trace_read_meta(struct qed_hwfn *p_hwfn,
4028} 4028}
4029 4029
4030/* Dump MCP Trace */ 4030/* Dump MCP Trace */
4031enum dbg_status qed_mcp_trace_dump(struct qed_hwfn *p_hwfn, 4031static enum dbg_status qed_mcp_trace_dump(struct qed_hwfn *p_hwfn,
4032 struct qed_ptt *p_ptt, 4032 struct qed_ptt *p_ptt,
4033 u32 *dump_buf, 4033 u32 *dump_buf,
4034 bool dump, u32 *num_dumped_dwords) 4034 bool dump, u32 *num_dumped_dwords)
4035{ 4035{
4036 u32 trace_data_grc_addr, trace_data_size_bytes, trace_data_size_dwords; 4036 u32 trace_data_grc_addr, trace_data_size_bytes, trace_data_size_dwords;
4037 u32 trace_meta_size_dwords, running_bundle_id, offset = 0; 4037 u32 trace_meta_size_dwords, running_bundle_id, offset = 0;
@@ -4130,10 +4130,10 @@ enum dbg_status qed_mcp_trace_dump(struct qed_hwfn *p_hwfn,
4130} 4130}
4131 4131
4132/* Dump GRC FIFO */ 4132/* Dump GRC FIFO */
4133enum dbg_status qed_reg_fifo_dump(struct qed_hwfn *p_hwfn, 4133static enum dbg_status qed_reg_fifo_dump(struct qed_hwfn *p_hwfn,
4134 struct qed_ptt *p_ptt, 4134 struct qed_ptt *p_ptt,
4135 u32 *dump_buf, 4135 u32 *dump_buf,
4136 bool dump, u32 *num_dumped_dwords) 4136 bool dump, u32 *num_dumped_dwords)
4137{ 4137{
4138 u32 offset = 0, dwords_read, size_param_offset; 4138 u32 offset = 0, dwords_read, size_param_offset;
4139 bool fifo_has_data; 4139 bool fifo_has_data;
@@ -4192,10 +4192,10 @@ enum dbg_status qed_reg_fifo_dump(struct qed_hwfn *p_hwfn,
4192} 4192}
4193 4193
4194/* Dump IGU FIFO */ 4194/* Dump IGU FIFO */
4195enum dbg_status qed_igu_fifo_dump(struct qed_hwfn *p_hwfn, 4195static enum dbg_status qed_igu_fifo_dump(struct qed_hwfn *p_hwfn,
4196 struct qed_ptt *p_ptt, 4196 struct qed_ptt *p_ptt,
4197 u32 *dump_buf, 4197 u32 *dump_buf,
4198 bool dump, u32 *num_dumped_dwords) 4198 bool dump, u32 *num_dumped_dwords)
4199{ 4199{
4200 u32 offset = 0, dwords_read, size_param_offset; 4200 u32 offset = 0, dwords_read, size_param_offset;
4201 bool fifo_has_data; 4201 bool fifo_has_data;
@@ -4255,10 +4255,11 @@ enum dbg_status qed_igu_fifo_dump(struct qed_hwfn *p_hwfn,
4255} 4255}
4256 4256
4257/* Protection Override dump */ 4257/* Protection Override dump */
4258enum dbg_status qed_protection_override_dump(struct qed_hwfn *p_hwfn, 4258static enum dbg_status qed_protection_override_dump(struct qed_hwfn *p_hwfn,
4259 struct qed_ptt *p_ptt, 4259 struct qed_ptt *p_ptt,
4260 u32 *dump_buf, 4260 u32 *dump_buf,
4261 bool dump, u32 *num_dumped_dwords) 4261 bool dump,
4262 u32 *num_dumped_dwords)
4262{ 4263{
4263 u32 offset = 0, size_param_offset, override_window_dwords; 4264 u32 offset = 0, size_param_offset, override_window_dwords;
4264 4265
@@ -6339,10 +6340,11 @@ enum dbg_status qed_print_fw_asserts_results(struct qed_hwfn *p_hwfn,
6339} 6340}
6340 6341
6341/* Wrapper for unifying the idle_chk and mcp_trace api */ 6342/* Wrapper for unifying the idle_chk and mcp_trace api */
6342enum dbg_status qed_print_idle_chk_results_wrapper(struct qed_hwfn *p_hwfn, 6343static enum dbg_status
6343 u32 *dump_buf, 6344qed_print_idle_chk_results_wrapper(struct qed_hwfn *p_hwfn,
6344 u32 num_dumped_dwords, 6345 u32 *dump_buf,
6345 char *results_buf) 6346 u32 num_dumped_dwords,
6347 char *results_buf)
6346{ 6348{
6347 u32 num_errors, num_warnnings; 6349 u32 num_errors, num_warnnings;
6348 6350
@@ -6413,8 +6415,8 @@ static void qed_dbg_print_feature(u8 *p_text_buf, u32 text_size)
6413 6415
6414#define QED_RESULTS_BUF_MIN_SIZE 16 6416#define QED_RESULTS_BUF_MIN_SIZE 16
6415/* Generic function for decoding debug feature info */ 6417/* Generic function for decoding debug feature info */
6416enum dbg_status format_feature(struct qed_hwfn *p_hwfn, 6418static enum dbg_status format_feature(struct qed_hwfn *p_hwfn,
6417 enum qed_dbg_features feature_idx) 6419 enum qed_dbg_features feature_idx)
6418{ 6420{
6419 struct qed_dbg_feature *feature = 6421 struct qed_dbg_feature *feature =
6420 &p_hwfn->cdev->dbg_params.features[feature_idx]; 6422 &p_hwfn->cdev->dbg_params.features[feature_idx];
@@ -6480,8 +6482,9 @@ enum dbg_status format_feature(struct qed_hwfn *p_hwfn,
6480} 6482}
6481 6483
6482/* Generic function for performing the dump of a debug feature. */ 6484/* Generic function for performing the dump of a debug feature. */
6483enum dbg_status qed_dbg_dump(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt, 6485static enum dbg_status qed_dbg_dump(struct qed_hwfn *p_hwfn,
6484 enum qed_dbg_features feature_idx) 6486 struct qed_ptt *p_ptt,
6487 enum qed_dbg_features feature_idx)
6485{ 6488{
6486 struct qed_dbg_feature *feature = 6489 struct qed_dbg_feature *feature =
6487 &p_hwfn->cdev->dbg_params.features[feature_idx]; 6490 &p_hwfn->cdev->dbg_params.features[feature_idx];
diff --git a/drivers/net/ethernet/qlogic/qed/qed_dev.c b/drivers/net/ethernet/qlogic/qed/qed_dev.c
index 754f6a908858..edae5fc5fccd 100644
--- a/drivers/net/ethernet/qlogic/qed/qed_dev.c
+++ b/drivers/net/ethernet/qlogic/qed/qed_dev.c
@@ -497,12 +497,13 @@ int qed_resc_alloc(struct qed_dev *cdev)
497 if (p_hwfn->hw_info.personality == QED_PCI_ETH_ROCE) { 497 if (p_hwfn->hw_info.personality == QED_PCI_ETH_ROCE) {
498 num_cons = qed_cxt_get_proto_cid_count(p_hwfn, 498 num_cons = qed_cxt_get_proto_cid_count(p_hwfn,
499 PROTOCOLID_ROCE, 499 PROTOCOLID_ROCE,
500 0) * 2; 500 NULL) * 2;
501 n_eqes += num_cons + 2 * MAX_NUM_VFS_BB; 501 n_eqes += num_cons + 2 * MAX_NUM_VFS_BB;
502 } else if (p_hwfn->hw_info.personality == QED_PCI_ISCSI) { 502 } else if (p_hwfn->hw_info.personality == QED_PCI_ISCSI) {
503 num_cons = 503 num_cons =
504 qed_cxt_get_proto_cid_count(p_hwfn, 504 qed_cxt_get_proto_cid_count(p_hwfn,
505 PROTOCOLID_ISCSI, 0); 505 PROTOCOLID_ISCSI,
506 NULL);
506 n_eqes += 2 * num_cons; 507 n_eqes += 2 * num_cons;
507 } 508 }
508 509
@@ -1422,19 +1423,19 @@ static void qed_hw_set_feat(struct qed_hwfn *p_hwfn)
1422 u32 *feat_num = p_hwfn->hw_info.feat_num; 1423 u32 *feat_num = p_hwfn->hw_info.feat_num;
1423 int num_features = 1; 1424 int num_features = 1;
1424 1425
1425#if IS_ENABLED(CONFIG_INFINIBAND_QEDR) 1426 if (IS_ENABLED(CONFIG_QED_RDMA) &&
1426 /* Roce CNQ each requires: 1 status block + 1 CNQ. We divide the 1427 p_hwfn->hw_info.personality == QED_PCI_ETH_ROCE) {
1427 * status blocks equally between L2 / RoCE but with consideration as 1428 /* Roce CNQ each requires: 1 status block + 1 CNQ. We divide
1428 * to how many l2 queues / cnqs we have 1429 * the status blocks equally between L2 / RoCE but with
1429 */ 1430 * consideration as to how many l2 queues / cnqs we have.
1430 if (p_hwfn->hw_info.personality == QED_PCI_ETH_ROCE) { 1431 */
1431 num_features++; 1432 num_features++;
1432 1433
1433 feat_num[QED_RDMA_CNQ] = 1434 feat_num[QED_RDMA_CNQ] =
1434 min_t(u32, RESC_NUM(p_hwfn, QED_SB) / num_features, 1435 min_t(u32, RESC_NUM(p_hwfn, QED_SB) / num_features,
1435 RESC_NUM(p_hwfn, QED_RDMA_CNQ_RAM)); 1436 RESC_NUM(p_hwfn, QED_RDMA_CNQ_RAM));
1436 } 1437 }
1437#endif 1438
1438 feat_num[QED_PF_L2_QUE] = min_t(u32, RESC_NUM(p_hwfn, QED_SB) / 1439 feat_num[QED_PF_L2_QUE] = min_t(u32, RESC_NUM(p_hwfn, QED_SB) /
1439 num_features, 1440 num_features,
1440 RESC_NUM(p_hwfn, QED_L2_QUEUE)); 1441 RESC_NUM(p_hwfn, QED_L2_QUEUE));
diff --git a/drivers/net/ethernet/qlogic/qed/qed_hsi.h b/drivers/net/ethernet/qlogic/qed/qed_hsi.h
index 72eee29c677f..2777d5bb4380 100644
--- a/drivers/net/ethernet/qlogic/qed/qed_hsi.h
+++ b/drivers/net/ethernet/qlogic/qed/qed_hsi.h
@@ -727,9 +727,6 @@ struct core_tx_bd_flags {
727#define CORE_TX_BD_FLAGS_L4_PROTOCOL_SHIFT 6 727#define CORE_TX_BD_FLAGS_L4_PROTOCOL_SHIFT 6
728#define CORE_TX_BD_FLAGS_L4_PSEUDO_CSUM_MODE_MASK 0x1 728#define CORE_TX_BD_FLAGS_L4_PSEUDO_CSUM_MODE_MASK 0x1
729#define CORE_TX_BD_FLAGS_L4_PSEUDO_CSUM_MODE_SHIFT 7 729#define CORE_TX_BD_FLAGS_L4_PSEUDO_CSUM_MODE_SHIFT 7
730#define CORE_TX_BD_FLAGS_ROCE_FLAV_MASK 0x1
731#define CORE_TX_BD_FLAGS_ROCE_FLAV_SHIFT 12
732
733}; 730};
734 731
735struct core_tx_bd { 732struct core_tx_bd {
diff --git a/drivers/net/ethernet/qlogic/qed/qed_ll2.c b/drivers/net/ethernet/qlogic/qed/qed_ll2.c
index 02a8be2faed7..62ae55bd81b8 100644
--- a/drivers/net/ethernet/qlogic/qed/qed_ll2.c
+++ b/drivers/net/ethernet/qlogic/qed/qed_ll2.c
@@ -38,6 +38,7 @@
38#include "qed_mcp.h" 38#include "qed_mcp.h"
39#include "qed_reg_addr.h" 39#include "qed_reg_addr.h"
40#include "qed_sp.h" 40#include "qed_sp.h"
41#include "qed_roce.h"
41 42
42#define QED_LL2_RX_REGISTERED(ll2) ((ll2)->rx_queue.b_cb_registred) 43#define QED_LL2_RX_REGISTERED(ll2) ((ll2)->rx_queue.b_cb_registred)
43#define QED_LL2_TX_REGISTERED(ll2) ((ll2)->tx_queue.b_cb_registred) 44#define QED_LL2_TX_REGISTERED(ll2) ((ll2)->tx_queue.b_cb_registred)
@@ -140,11 +141,11 @@ static void qed_ll2_kill_buffers(struct qed_dev *cdev)
140 qed_ll2_dealloc_buffer(cdev, buffer); 141 qed_ll2_dealloc_buffer(cdev, buffer);
141} 142}
142 143
143void qed_ll2b_complete_rx_packet(struct qed_hwfn *p_hwfn, 144static void qed_ll2b_complete_rx_packet(struct qed_hwfn *p_hwfn,
144 u8 connection_handle, 145 u8 connection_handle,
145 struct qed_ll2_rx_packet *p_pkt, 146 struct qed_ll2_rx_packet *p_pkt,
146 struct core_rx_fast_path_cqe *p_cqe, 147 struct core_rx_fast_path_cqe *p_cqe,
147 bool b_last_packet) 148 bool b_last_packet)
148{ 149{
149 u16 packet_length = le16_to_cpu(p_cqe->packet_length); 150 u16 packet_length = le16_to_cpu(p_cqe->packet_length);
150 struct qed_ll2_buffer *buffer = p_pkt->cookie; 151 struct qed_ll2_buffer *buffer = p_pkt->cookie;
@@ -515,7 +516,7 @@ static int qed_ll2_rxq_completion(struct qed_hwfn *p_hwfn, void *cookie)
515 return rc; 516 return rc;
516} 517}
517 518
518void qed_ll2_rxq_flush(struct qed_hwfn *p_hwfn, u8 connection_handle) 519static void qed_ll2_rxq_flush(struct qed_hwfn *p_hwfn, u8 connection_handle)
519{ 520{
520 struct qed_ll2_info *p_ll2_conn = NULL; 521 struct qed_ll2_info *p_ll2_conn = NULL;
521 struct qed_ll2_rx_packet *p_pkt = NULL; 522 struct qed_ll2_rx_packet *p_pkt = NULL;
@@ -537,8 +538,7 @@ void qed_ll2_rxq_flush(struct qed_hwfn *p_hwfn, u8 connection_handle)
537 if (!p_pkt) 538 if (!p_pkt)
538 break; 539 break;
539 540
540 list_del(&p_pkt->list_entry); 541 list_move_tail(&p_pkt->list_entry, &p_rx->free_descq);
541 list_add_tail(&p_pkt->list_entry, &p_rx->free_descq);
542 542
543 rx_buf_addr = p_pkt->rx_buf_addr; 543 rx_buf_addr = p_pkt->rx_buf_addr;
544 cookie = p_pkt->cookie; 544 cookie = p_pkt->cookie;
@@ -992,9 +992,8 @@ static void qed_ll2_post_rx_buffer_notify_fw(struct qed_hwfn *p_hwfn,
992 p_posting_packet = list_first_entry(&p_rx->posting_descq, 992 p_posting_packet = list_first_entry(&p_rx->posting_descq,
993 struct qed_ll2_rx_packet, 993 struct qed_ll2_rx_packet,
994 list_entry); 994 list_entry);
995 list_del(&p_posting_packet->list_entry); 995 list_move_tail(&p_posting_packet->list_entry,
996 list_add_tail(&p_posting_packet->list_entry, 996 &p_rx->active_descq);
997 &p_rx->active_descq);
998 b_notify_fw = true; 997 b_notify_fw = true;
999 } 998 }
1000 999
@@ -1120,12 +1119,10 @@ static void qed_ll2_prepare_tx_packet_set_bd(struct qed_hwfn *p_hwfn,
1120 start_bd->bd_flags.as_bitfield |= CORE_TX_BD_FLAGS_START_BD_MASK << 1119 start_bd->bd_flags.as_bitfield |= CORE_TX_BD_FLAGS_START_BD_MASK <<
1121 CORE_TX_BD_FLAGS_START_BD_SHIFT; 1120 CORE_TX_BD_FLAGS_START_BD_SHIFT;
1122 SET_FIELD(start_bd->bitfield0, CORE_TX_BD_NBDS, num_of_bds); 1121 SET_FIELD(start_bd->bitfield0, CORE_TX_BD_NBDS, num_of_bds);
1122 SET_FIELD(start_bd->bitfield0, CORE_TX_BD_ROCE_FLAV, type);
1123 DMA_REGPAIR_LE(start_bd->addr, first_frag); 1123 DMA_REGPAIR_LE(start_bd->addr, first_frag);
1124 start_bd->nbytes = cpu_to_le16(first_frag_len); 1124 start_bd->nbytes = cpu_to_le16(first_frag_len);
1125 1125
1126 SET_FIELD(start_bd->bd_flags.as_bitfield, CORE_TX_BD_FLAGS_ROCE_FLAV,
1127 type);
1128
1129 DP_VERBOSE(p_hwfn, 1126 DP_VERBOSE(p_hwfn,
1130 (NETIF_MSG_TX_QUEUED | QED_MSG_LL2), 1127 (NETIF_MSG_TX_QUEUED | QED_MSG_LL2),
1131 "LL2 [q 0x%02x cid 0x%08x type 0x%08x] Tx Producer at [0x%04x] - set with a %04x bytes %02x BDs buffer at %08x:%08x\n", 1128 "LL2 [q 0x%02x cid 0x%08x type 0x%08x] Tx Producer at [0x%04x] - set with a %04x bytes %02x BDs buffer at %08x:%08x\n",
@@ -1188,8 +1185,7 @@ static void qed_ll2_tx_packet_notify(struct qed_hwfn *p_hwfn,
1188 if (!p_pkt) 1185 if (!p_pkt)
1189 break; 1186 break;
1190 1187
1191 list_del(&p_pkt->list_entry); 1188 list_move_tail(&p_pkt->list_entry, &p_tx->active_descq);
1192 list_add_tail(&p_pkt->list_entry, &p_tx->active_descq);
1193 } 1189 }
1194 1190
1195 SET_FIELD(db_msg.params, CORE_DB_DATA_DEST, DB_DEST_XCM); 1191 SET_FIELD(db_msg.params, CORE_DB_DATA_DEST, DB_DEST_XCM);
@@ -1734,6 +1730,7 @@ static int qed_ll2_start_xmit(struct qed_dev *cdev, struct sk_buff *skb)
1734 mapping))) { 1730 mapping))) {
1735 DP_NOTICE(cdev, 1731 DP_NOTICE(cdev,
1736 "Unable to map frag - dropping packet\n"); 1732 "Unable to map frag - dropping packet\n");
1733 rc = -ENOMEM;
1737 goto err; 1734 goto err;
1738 } 1735 }
1739 } else { 1736 } else {
diff --git a/drivers/net/ethernet/qlogic/qed/qed_ll2.h b/drivers/net/ethernet/qlogic/qed/qed_ll2.h
index 80a5dc2d652d..4e3d62a16cab 100644
--- a/drivers/net/ethernet/qlogic/qed/qed_ll2.h
+++ b/drivers/net/ethernet/qlogic/qed/qed_ll2.h
@@ -293,24 +293,4 @@ void qed_ll2_setup(struct qed_hwfn *p_hwfn,
293 */ 293 */
294void qed_ll2_free(struct qed_hwfn *p_hwfn, 294void qed_ll2_free(struct qed_hwfn *p_hwfn,
295 struct qed_ll2_info *p_ll2_connections); 295 struct qed_ll2_info *p_ll2_connections);
296void qed_ll2b_complete_rx_gsi_packet(struct qed_hwfn *p_hwfn,
297 u8 connection_handle,
298 void *cookie,
299 dma_addr_t rx_buf_addr,
300 u16 data_length,
301 u8 data_length_error,
302 u16 parse_flags,
303 u16 vlan,
304 u32 src_mac_addr_hi,
305 u16 src_mac_addr_lo, bool b_last_packet);
306void qed_ll2b_complete_tx_gsi_packet(struct qed_hwfn *p_hwfn,
307 u8 connection_handle,
308 void *cookie,
309 dma_addr_t first_frag_addr,
310 bool b_last_fragment, bool b_last_packet);
311void qed_ll2b_release_tx_gsi_packet(struct qed_hwfn *p_hwfn,
312 u8 connection_handle,
313 void *cookie,
314 dma_addr_t first_frag_addr,
315 bool b_last_fragment, bool b_last_packet);
316#endif 296#endif
diff --git a/drivers/net/ethernet/qlogic/qed/qed_main.c b/drivers/net/ethernet/qlogic/qed/qed_main.c
index 4ee3151e80c2..333c7442e48a 100644
--- a/drivers/net/ethernet/qlogic/qed/qed_main.c
+++ b/drivers/net/ethernet/qlogic/qed/qed_main.c
@@ -33,10 +33,8 @@
33#include "qed_hw.h" 33#include "qed_hw.h"
34#include "qed_selftest.h" 34#include "qed_selftest.h"
35 35
36#if IS_ENABLED(CONFIG_INFINIBAND_QEDR)
37#define QED_ROCE_QPS (8192) 36#define QED_ROCE_QPS (8192)
38#define QED_ROCE_DPIS (8) 37#define QED_ROCE_DPIS (8)
39#endif
40 38
41static char version[] = 39static char version[] =
42 "QLogic FastLinQ 4xxxx Core Module qed " DRV_MODULE_VERSION "\n"; 40 "QLogic FastLinQ 4xxxx Core Module qed " DRV_MODULE_VERSION "\n";
@@ -682,9 +680,7 @@ static int qed_slowpath_setup_int(struct qed_dev *cdev,
682 enum qed_int_mode int_mode) 680 enum qed_int_mode int_mode)
683{ 681{
684 struct qed_sb_cnt_info sb_cnt_info; 682 struct qed_sb_cnt_info sb_cnt_info;
685#if IS_ENABLED(CONFIG_INFINIBAND_QEDR) 683 int num_l2_queues = 0;
686 int num_l2_queues;
687#endif
688 int rc; 684 int rc;
689 int i; 685 int i;
690 686
@@ -715,8 +711,9 @@ static int qed_slowpath_setup_int(struct qed_dev *cdev,
715 cdev->int_params.fp_msix_cnt = cdev->int_params.out.num_vectors - 711 cdev->int_params.fp_msix_cnt = cdev->int_params.out.num_vectors -
716 cdev->num_hwfns; 712 cdev->num_hwfns;
717 713
718#if IS_ENABLED(CONFIG_INFINIBAND_QEDR) 714 if (!IS_ENABLED(CONFIG_QED_RDMA))
719 num_l2_queues = 0; 715 return 0;
716
720 for_each_hwfn(cdev, i) 717 for_each_hwfn(cdev, i)
721 num_l2_queues += FEAT_NUM(&cdev->hwfns[i], QED_PF_L2_QUE); 718 num_l2_queues += FEAT_NUM(&cdev->hwfns[i], QED_PF_L2_QUE);
722 719
@@ -738,7 +735,6 @@ static int qed_slowpath_setup_int(struct qed_dev *cdev,
738 DP_VERBOSE(cdev, QED_MSG_RDMA, "roce_msix_cnt=%d roce_msix_base=%d\n", 735 DP_VERBOSE(cdev, QED_MSG_RDMA, "roce_msix_cnt=%d roce_msix_base=%d\n",
739 cdev->int_params.rdma_msix_cnt, 736 cdev->int_params.rdma_msix_cnt,
740 cdev->int_params.rdma_msix_base); 737 cdev->int_params.rdma_msix_base);
741#endif
742 738
743 return 0; 739 return 0;
744} 740}
@@ -843,13 +839,14 @@ static void qed_update_pf_params(struct qed_dev *cdev,
843{ 839{
844 int i; 840 int i;
845 841
846#if IS_ENABLED(CONFIG_INFINIBAND_QEDR) 842 if (IS_ENABLED(CONFIG_QED_RDMA)) {
847 params->rdma_pf_params.num_qps = QED_ROCE_QPS; 843 params->rdma_pf_params.num_qps = QED_ROCE_QPS;
848 params->rdma_pf_params.min_dpis = QED_ROCE_DPIS; 844 params->rdma_pf_params.min_dpis = QED_ROCE_DPIS;
849 /* divide by 3 the MRs to avoid MF ILT overflow */ 845 /* divide by 3 the MRs to avoid MF ILT overflow */
850 params->rdma_pf_params.num_mrs = RDMA_MAX_TIDS; 846 params->rdma_pf_params.num_mrs = RDMA_MAX_TIDS;
851 params->rdma_pf_params.gl_pi = QED_ROCE_PROTOCOL_INDEX; 847 params->rdma_pf_params.gl_pi = QED_ROCE_PROTOCOL_INDEX;
852#endif 848 }
849
853 for (i = 0; i < cdev->num_hwfns; i++) { 850 for (i = 0; i < cdev->num_hwfns; i++) {
854 struct qed_hwfn *p_hwfn = &cdev->hwfns[i]; 851 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
855 852
@@ -880,6 +877,7 @@ static int qed_slowpath_start(struct qed_dev *cdev,
880 } 877 }
881 } 878 }
882 879
880 cdev->rx_coalesce_usecs = QED_DEFAULT_RX_USECS;
883 rc = qed_nic_setup(cdev); 881 rc = qed_nic_setup(cdev);
884 if (rc) 882 if (rc)
885 goto err; 883 goto err;
@@ -1432,7 +1430,7 @@ static int qed_set_led(struct qed_dev *cdev, enum qed_led_mode mode)
1432 return status; 1430 return status;
1433} 1431}
1434 1432
1435struct qed_selftest_ops qed_selftest_ops_pass = { 1433static struct qed_selftest_ops qed_selftest_ops_pass = {
1436 .selftest_memory = &qed_selftest_memory, 1434 .selftest_memory = &qed_selftest_memory,
1437 .selftest_interrupt = &qed_selftest_interrupt, 1435 .selftest_interrupt = &qed_selftest_interrupt,
1438 .selftest_register = &qed_selftest_register, 1436 .selftest_register = &qed_selftest_register,
diff --git a/drivers/net/ethernet/qlogic/qed/qed_roce.c b/drivers/net/ethernet/qlogic/qed/qed_roce.c
index 76831a398bed..f3a825a8f8d5 100644
--- a/drivers/net/ethernet/qlogic/qed/qed_roce.c
+++ b/drivers/net/ethernet/qlogic/qed/qed_roce.c
@@ -129,17 +129,12 @@ static void qed_bmap_release_id(struct qed_hwfn *p_hwfn,
129 } 129 }
130} 130}
131 131
132u32 qed_rdma_get_sb_id(void *p_hwfn, u32 rel_sb_id) 132static u32 qed_rdma_get_sb_id(void *p_hwfn, u32 rel_sb_id)
133{ 133{
134 /* First sb id for RoCE is after all the l2 sb */ 134 /* First sb id for RoCE is after all the l2 sb */
135 return FEAT_NUM((struct qed_hwfn *)p_hwfn, QED_PF_L2_QUE) + rel_sb_id; 135 return FEAT_NUM((struct qed_hwfn *)p_hwfn, QED_PF_L2_QUE) + rel_sb_id;
136} 136}
137 137
138u32 qed_rdma_query_cau_timer_res(void *rdma_cxt)
139{
140 return QED_CAU_DEF_RX_TIMER_RES;
141}
142
143static int qed_rdma_alloc(struct qed_hwfn *p_hwfn, 138static int qed_rdma_alloc(struct qed_hwfn *p_hwfn,
144 struct qed_ptt *p_ptt, 139 struct qed_ptt *p_ptt,
145 struct qed_rdma_start_in_params *params) 140 struct qed_rdma_start_in_params *params)
@@ -162,7 +157,8 @@ static int qed_rdma_alloc(struct qed_hwfn *p_hwfn,
162 p_hwfn->p_rdma_info = p_rdma_info; 157 p_hwfn->p_rdma_info = p_rdma_info;
163 p_rdma_info->proto = PROTOCOLID_ROCE; 158 p_rdma_info->proto = PROTOCOLID_ROCE;
164 159
165 num_cons = qed_cxt_get_proto_cid_count(p_hwfn, p_rdma_info->proto, 0); 160 num_cons = qed_cxt_get_proto_cid_count(p_hwfn, p_rdma_info->proto,
161 NULL);
166 162
167 p_rdma_info->num_qps = num_cons / 2; 163 p_rdma_info->num_qps = num_cons / 2;
168 164
@@ -275,7 +271,7 @@ free_rdma_info:
275 return rc; 271 return rc;
276} 272}
277 273
278void qed_rdma_resc_free(struct qed_hwfn *p_hwfn) 274static void qed_rdma_resc_free(struct qed_hwfn *p_hwfn)
279{ 275{
280 struct qed_rdma_info *p_rdma_info = p_hwfn->p_rdma_info; 276 struct qed_rdma_info *p_rdma_info = p_hwfn->p_rdma_info;
281 277
@@ -527,6 +523,26 @@ static int qed_rdma_start_fw(struct qed_hwfn *p_hwfn,
527 return qed_spq_post(p_hwfn, p_ent, NULL); 523 return qed_spq_post(p_hwfn, p_ent, NULL);
528} 524}
529 525
526static int qed_rdma_alloc_tid(void *rdma_cxt, u32 *itid)
527{
528 struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt;
529 int rc;
530
531 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Allocate TID\n");
532
533 spin_lock_bh(&p_hwfn->p_rdma_info->lock);
534 rc = qed_rdma_bmap_alloc_id(p_hwfn,
535 &p_hwfn->p_rdma_info->tid_map, itid);
536 spin_unlock_bh(&p_hwfn->p_rdma_info->lock);
537 if (rc)
538 goto out;
539
540 rc = qed_cxt_dynamic_ilt_alloc(p_hwfn, QED_ELEM_TASK, *itid);
541out:
542 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Allocate TID - done, rc = %d\n", rc);
543 return rc;
544}
545
530static int qed_rdma_reserve_lkey(struct qed_hwfn *p_hwfn) 546static int qed_rdma_reserve_lkey(struct qed_hwfn *p_hwfn)
531{ 547{
532 struct qed_rdma_device *dev = p_hwfn->p_rdma_info->dev; 548 struct qed_rdma_device *dev = p_hwfn->p_rdma_info->dev;
@@ -573,7 +589,7 @@ static int qed_rdma_setup(struct qed_hwfn *p_hwfn,
573 return qed_rdma_start_fw(p_hwfn, params, p_ptt); 589 return qed_rdma_start_fw(p_hwfn, params, p_ptt);
574} 590}
575 591
576int qed_rdma_stop(void *rdma_cxt) 592static int qed_rdma_stop(void *rdma_cxt)
577{ 593{
578 struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt; 594 struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt;
579 struct rdma_close_func_ramrod_data *p_ramrod; 595 struct rdma_close_func_ramrod_data *p_ramrod;
@@ -629,8 +645,8 @@ out:
629 return rc; 645 return rc;
630} 646}
631 647
632int qed_rdma_add_user(void *rdma_cxt, 648static int qed_rdma_add_user(void *rdma_cxt,
633 struct qed_rdma_add_user_out_params *out_params) 649 struct qed_rdma_add_user_out_params *out_params)
634{ 650{
635 struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt; 651 struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt;
636 u32 dpi_start_offset; 652 u32 dpi_start_offset;
@@ -664,7 +680,7 @@ int qed_rdma_add_user(void *rdma_cxt,
664 return rc; 680 return rc;
665} 681}
666 682
667struct qed_rdma_port *qed_rdma_query_port(void *rdma_cxt) 683static struct qed_rdma_port *qed_rdma_query_port(void *rdma_cxt)
668{ 684{
669 struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt; 685 struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt;
670 struct qed_rdma_port *p_port = p_hwfn->p_rdma_info->port; 686 struct qed_rdma_port *p_port = p_hwfn->p_rdma_info->port;
@@ -680,7 +696,7 @@ struct qed_rdma_port *qed_rdma_query_port(void *rdma_cxt)
680 return p_port; 696 return p_port;
681} 697}
682 698
683struct qed_rdma_device *qed_rdma_query_device(void *rdma_cxt) 699static struct qed_rdma_device *qed_rdma_query_device(void *rdma_cxt)
684{ 700{
685 struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt; 701 struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt;
686 702
@@ -690,7 +706,7 @@ struct qed_rdma_device *qed_rdma_query_device(void *rdma_cxt)
690 return p_hwfn->p_rdma_info->dev; 706 return p_hwfn->p_rdma_info->dev;
691} 707}
692 708
693void qed_rdma_free_tid(void *rdma_cxt, u32 itid) 709static void qed_rdma_free_tid(void *rdma_cxt, u32 itid)
694{ 710{
695 struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt; 711 struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt;
696 712
@@ -701,27 +717,7 @@ void qed_rdma_free_tid(void *rdma_cxt, u32 itid)
701 spin_unlock_bh(&p_hwfn->p_rdma_info->lock); 717 spin_unlock_bh(&p_hwfn->p_rdma_info->lock);
702} 718}
703 719
704int qed_rdma_alloc_tid(void *rdma_cxt, u32 *itid) 720static void qed_rdma_cnq_prod_update(void *rdma_cxt, u8 qz_offset, u16 prod)
705{
706 struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt;
707 int rc;
708
709 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Allocate TID\n");
710
711 spin_lock_bh(&p_hwfn->p_rdma_info->lock);
712 rc = qed_rdma_bmap_alloc_id(p_hwfn,
713 &p_hwfn->p_rdma_info->tid_map, itid);
714 spin_unlock_bh(&p_hwfn->p_rdma_info->lock);
715 if (rc)
716 goto out;
717
718 rc = qed_cxt_dynamic_ilt_alloc(p_hwfn, QED_ELEM_TASK, *itid);
719out:
720 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Allocate TID - done, rc = %d\n", rc);
721 return rc;
722}
723
724void qed_rdma_cnq_prod_update(void *rdma_cxt, u8 qz_offset, u16 prod)
725{ 721{
726 struct qed_hwfn *p_hwfn; 722 struct qed_hwfn *p_hwfn;
727 u16 qz_num; 723 u16 qz_num;
@@ -816,7 +812,7 @@ static int qed_rdma_get_int(struct qed_dev *cdev, struct qed_int_info *info)
816 return 0; 812 return 0;
817} 813}
818 814
819int qed_rdma_alloc_pd(void *rdma_cxt, u16 *pd) 815static int qed_rdma_alloc_pd(void *rdma_cxt, u16 *pd)
820{ 816{
821 struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt; 817 struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt;
822 u32 returned_id; 818 u32 returned_id;
@@ -836,7 +832,7 @@ int qed_rdma_alloc_pd(void *rdma_cxt, u16 *pd)
836 return rc; 832 return rc;
837} 833}
838 834
839void qed_rdma_free_pd(void *rdma_cxt, u16 pd) 835static void qed_rdma_free_pd(void *rdma_cxt, u16 pd)
840{ 836{
841 struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt; 837 struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt;
842 838
@@ -873,8 +869,9 @@ qed_rdma_toggle_bit_create_resize_cq(struct qed_hwfn *p_hwfn, u16 icid)
873 return toggle_bit; 869 return toggle_bit;
874} 870}
875 871
876int qed_rdma_create_cq(void *rdma_cxt, 872static int qed_rdma_create_cq(void *rdma_cxt,
877 struct qed_rdma_create_cq_in_params *params, u16 *icid) 873 struct qed_rdma_create_cq_in_params *params,
874 u16 *icid)
878{ 875{
879 struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt; 876 struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt;
880 struct qed_rdma_info *p_info = p_hwfn->p_rdma_info; 877 struct qed_rdma_info *p_info = p_hwfn->p_rdma_info;
@@ -957,98 +954,10 @@ err:
957 return rc; 954 return rc;
958} 955}
959 956
960int qed_rdma_resize_cq(void *rdma_cxt, 957static int
961 struct qed_rdma_resize_cq_in_params *in_params, 958qed_rdma_destroy_cq(void *rdma_cxt,
962 struct qed_rdma_resize_cq_out_params *out_params) 959 struct qed_rdma_destroy_cq_in_params *in_params,
963{ 960 struct qed_rdma_destroy_cq_out_params *out_params)
964 struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt;
965 struct rdma_resize_cq_output_params *p_ramrod_res;
966 struct rdma_resize_cq_ramrod_data *p_ramrod;
967 enum qed_rdma_toggle_bit toggle_bit;
968 struct qed_sp_init_data init_data;
969 struct qed_spq_entry *p_ent;
970 dma_addr_t ramrod_res_phys;
971 u8 fw_return_code;
972 int rc = -ENOMEM;
973
974 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "icid = %08x\n", in_params->icid);
975
976 p_ramrod_res =
977 (struct rdma_resize_cq_output_params *)
978 dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
979 sizeof(struct rdma_resize_cq_output_params),
980 &ramrod_res_phys, GFP_KERNEL);
981 if (!p_ramrod_res) {
982 DP_NOTICE(p_hwfn,
983 "qed resize cq failed: cannot allocate memory (ramrod)\n");
984 return rc;
985 }
986
987 /* Get SPQ entry */
988 memset(&init_data, 0, sizeof(init_data));
989 init_data.cid = in_params->icid;
990 init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
991 init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
992
993 rc = qed_sp_init_request(p_hwfn, &p_ent,
994 RDMA_RAMROD_RESIZE_CQ,
995 p_hwfn->p_rdma_info->proto, &init_data);
996 if (rc)
997 goto err;
998
999 p_ramrod = &p_ent->ramrod.rdma_resize_cq;
1000
1001 p_ramrod->flags = 0;
1002
1003 /* toggle the bit for every resize or create cq for a given icid */
1004 toggle_bit = qed_rdma_toggle_bit_create_resize_cq(p_hwfn,
1005 in_params->icid);
1006
1007 SET_FIELD(p_ramrod->flags,
1008 RDMA_RESIZE_CQ_RAMROD_DATA_TOGGLE_BIT, toggle_bit);
1009
1010 SET_FIELD(p_ramrod->flags,
1011 RDMA_RESIZE_CQ_RAMROD_DATA_IS_TWO_LEVEL_PBL,
1012 in_params->pbl_two_level);
1013
1014 p_ramrod->pbl_log_page_size = in_params->pbl_page_size_log - 12;
1015 p_ramrod->pbl_num_pages = cpu_to_le16(in_params->pbl_num_pages);
1016 p_ramrod->max_cqes = cpu_to_le32(in_params->cq_size);
1017 DMA_REGPAIR_LE(p_ramrod->pbl_addr, in_params->pbl_ptr);
1018 DMA_REGPAIR_LE(p_ramrod->output_params_addr, ramrod_res_phys);
1019
1020 rc = qed_spq_post(p_hwfn, p_ent, &fw_return_code);
1021 if (rc)
1022 goto err;
1023
1024 if (fw_return_code != RDMA_RETURN_OK) {
1025 DP_NOTICE(p_hwfn, "fw_return_code = %d\n", fw_return_code);
1026 rc = -EINVAL;
1027 goto err;
1028 }
1029
1030 out_params->prod = le32_to_cpu(p_ramrod_res->old_cq_prod);
1031 out_params->cons = le32_to_cpu(p_ramrod_res->old_cq_cons);
1032
1033 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
1034 sizeof(struct rdma_resize_cq_output_params),
1035 p_ramrod_res, ramrod_res_phys);
1036
1037 DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Resized CQ, rc = %d\n", rc);
1038
1039 return rc;
1040
1041err: dma_free_coherent(&p_hwfn->cdev->pdev->dev,
1042 sizeof(struct rdma_resize_cq_output_params),
1043 p_ramrod_res, ramrod_res_phys);
1044 DP_NOTICE(p_hwfn, "Resized CQ, Failed - rc = %d\n", rc);
1045
1046 return rc;
1047}
1048
1049int qed_rdma_destroy_cq(void *rdma_cxt,
1050 struct qed_rdma_destroy_cq_in_params *in_params,
1051 struct qed_rdma_destroy_cq_out_params *out_params)
1052{ 961{
1053 struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt; 962 struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt;
1054 struct rdma_destroy_cq_output_params *p_ramrod_res; 963 struct rdma_destroy_cq_output_params *p_ramrod_res;
@@ -1169,7 +1078,7 @@ static enum roce_flavor qed_roce_mode_to_flavor(enum roce_mode roce_mode)
1169 return flavor; 1078 return flavor;
1170} 1079}
1171 1080
1172int qed_roce_alloc_cid(struct qed_hwfn *p_hwfn, u16 *cid) 1081static int qed_roce_alloc_cid(struct qed_hwfn *p_hwfn, u16 *cid)
1173{ 1082{
1174 struct qed_rdma_info *p_rdma_info = p_hwfn->p_rdma_info; 1083 struct qed_rdma_info *p_rdma_info = p_hwfn->p_rdma_info;
1175 u32 responder_icid; 1084 u32 responder_icid;
@@ -1793,9 +1702,9 @@ err:
1793 return rc; 1702 return rc;
1794} 1703}
1795 1704
1796int qed_roce_query_qp(struct qed_hwfn *p_hwfn, 1705static int qed_roce_query_qp(struct qed_hwfn *p_hwfn,
1797 struct qed_rdma_qp *qp, 1706 struct qed_rdma_qp *qp,
1798 struct qed_rdma_query_qp_out_params *out_params) 1707 struct qed_rdma_query_qp_out_params *out_params)
1799{ 1708{
1800 struct roce_query_qp_resp_output_params *p_resp_ramrod_res; 1709 struct roce_query_qp_resp_output_params *p_resp_ramrod_res;
1801 struct roce_query_qp_req_output_params *p_req_ramrod_res; 1710 struct roce_query_qp_req_output_params *p_req_ramrod_res;
@@ -1936,7 +1845,7 @@ err_resp:
1936 return rc; 1845 return rc;
1937} 1846}
1938 1847
1939int qed_roce_destroy_qp(struct qed_hwfn *p_hwfn, struct qed_rdma_qp *qp) 1848static int qed_roce_destroy_qp(struct qed_hwfn *p_hwfn, struct qed_rdma_qp *qp)
1940{ 1849{
1941 u32 num_invalidated_mw = 0; 1850 u32 num_invalidated_mw = 0;
1942 u32 num_bound_mw = 0; 1851 u32 num_bound_mw = 0;
@@ -1985,9 +1894,9 @@ int qed_roce_destroy_qp(struct qed_hwfn *p_hwfn, struct qed_rdma_qp *qp)
1985 return 0; 1894 return 0;
1986} 1895}
1987 1896
1988int qed_rdma_query_qp(void *rdma_cxt, 1897static int qed_rdma_query_qp(void *rdma_cxt,
1989 struct qed_rdma_qp *qp, 1898 struct qed_rdma_qp *qp,
1990 struct qed_rdma_query_qp_out_params *out_params) 1899 struct qed_rdma_query_qp_out_params *out_params)
1991{ 1900{
1992 struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt; 1901 struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt;
1993 int rc; 1902 int rc;
@@ -2022,7 +1931,7 @@ int qed_rdma_query_qp(void *rdma_cxt,
2022 return rc; 1931 return rc;
2023} 1932}
2024 1933
2025int qed_rdma_destroy_qp(void *rdma_cxt, struct qed_rdma_qp *qp) 1934static int qed_rdma_destroy_qp(void *rdma_cxt, struct qed_rdma_qp *qp)
2026{ 1935{
2027 struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt; 1936 struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt;
2028 int rc = 0; 1937 int rc = 0;
@@ -2038,7 +1947,7 @@ int qed_rdma_destroy_qp(void *rdma_cxt, struct qed_rdma_qp *qp)
2038 return rc; 1947 return rc;
2039} 1948}
2040 1949
2041struct qed_rdma_qp * 1950static struct qed_rdma_qp *
2042qed_rdma_create_qp(void *rdma_cxt, 1951qed_rdma_create_qp(void *rdma_cxt,
2043 struct qed_rdma_create_qp_in_params *in_params, 1952 struct qed_rdma_create_qp_in_params *in_params,
2044 struct qed_rdma_create_qp_out_params *out_params) 1953 struct qed_rdma_create_qp_out_params *out_params)
@@ -2215,9 +2124,9 @@ static int qed_roce_modify_qp(struct qed_hwfn *p_hwfn,
2215 return rc; 2124 return rc;
2216} 2125}
2217 2126
2218int qed_rdma_modify_qp(void *rdma_cxt, 2127static int qed_rdma_modify_qp(void *rdma_cxt,
2219 struct qed_rdma_qp *qp, 2128 struct qed_rdma_qp *qp,
2220 struct qed_rdma_modify_qp_in_params *params) 2129 struct qed_rdma_modify_qp_in_params *params)
2221{ 2130{
2222 struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt; 2131 struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt;
2223 enum qed_roce_qp_state prev_state; 2132 enum qed_roce_qp_state prev_state;
@@ -2312,8 +2221,9 @@ int qed_rdma_modify_qp(void *rdma_cxt,
2312 return rc; 2221 return rc;
2313} 2222}
2314 2223
2315int qed_rdma_register_tid(void *rdma_cxt, 2224static int
2316 struct qed_rdma_register_tid_in_params *params) 2225qed_rdma_register_tid(void *rdma_cxt,
2226 struct qed_rdma_register_tid_in_params *params)
2317{ 2227{
2318 struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt; 2228 struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt;
2319 struct rdma_register_tid_ramrod_data *p_ramrod; 2229 struct rdma_register_tid_ramrod_data *p_ramrod;
@@ -2450,7 +2360,7 @@ int qed_rdma_register_tid(void *rdma_cxt,
2450 return rc; 2360 return rc;
2451} 2361}
2452 2362
2453int qed_rdma_deregister_tid(void *rdma_cxt, u32 itid) 2363static int qed_rdma_deregister_tid(void *rdma_cxt, u32 itid)
2454{ 2364{
2455 struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt; 2365 struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt;
2456 struct rdma_deregister_tid_ramrod_data *p_ramrod; 2366 struct rdma_deregister_tid_ramrod_data *p_ramrod;
@@ -2561,7 +2471,8 @@ void qed_rdma_dpm_bar(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
2561 qed_rdma_dpm_conf(p_hwfn, p_ptt); 2471 qed_rdma_dpm_conf(p_hwfn, p_ptt);
2562} 2472}
2563 2473
2564int qed_rdma_start(void *rdma_cxt, struct qed_rdma_start_in_params *params) 2474static int qed_rdma_start(void *rdma_cxt,
2475 struct qed_rdma_start_in_params *params)
2565{ 2476{
2566 struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt; 2477 struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt;
2567 struct qed_ptt *p_ptt; 2478 struct qed_ptt *p_ptt;
@@ -2601,7 +2512,7 @@ static int qed_rdma_init(struct qed_dev *cdev,
2601 return qed_rdma_start(QED_LEADING_HWFN(cdev), params); 2512 return qed_rdma_start(QED_LEADING_HWFN(cdev), params);
2602} 2513}
2603 2514
2604void qed_rdma_remove_user(void *rdma_cxt, u16 dpi) 2515static void qed_rdma_remove_user(void *rdma_cxt, u16 dpi)
2605{ 2516{
2606 struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt; 2517 struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt;
2607 2518
@@ -2809,11 +2720,6 @@ static int qed_roce_ll2_stop(struct qed_dev *cdev)
2809 struct qed_roce_ll2_info *roce_ll2 = hwfn->ll2; 2720 struct qed_roce_ll2_info *roce_ll2 = hwfn->ll2;
2810 int rc; 2721 int rc;
2811 2722
2812 if (!cdev) {
2813 DP_ERR(cdev, "qed roce ll2 stop: invalid cdev\n");
2814 return -EINVAL;
2815 }
2816
2817 if (roce_ll2->handle == QED_LL2_UNUSED_HANDLE) { 2723 if (roce_ll2->handle == QED_LL2_UNUSED_HANDLE) {
2818 DP_ERR(cdev, "qed roce ll2 stop: cannot stop an unused LL2\n"); 2724 DP_ERR(cdev, "qed roce ll2 stop: cannot stop an unused LL2\n");
2819 return -EINVAL; 2725 return -EINVAL;
@@ -2850,7 +2756,7 @@ static int qed_roce_ll2_tx(struct qed_dev *cdev,
2850 int rc; 2756 int rc;
2851 int i; 2757 int i;
2852 2758
2853 if (!cdev || !pkt || !params) { 2759 if (!pkt || !params) {
2854 DP_ERR(cdev, 2760 DP_ERR(cdev,
2855 "roce ll2 tx: failed tx because one of the following is NULL - drv=%p, pkt=%p, params=%p\n", 2761 "roce ll2 tx: failed tx because one of the following is NULL - drv=%p, pkt=%p, params=%p\n",
2856 cdev, pkt, params); 2762 cdev, pkt, params);
diff --git a/drivers/net/ethernet/qlogic/qed/qed_roce.h b/drivers/net/ethernet/qlogic/qed/qed_roce.h
index 2f091e8a0f40..279f342af8db 100644
--- a/drivers/net/ethernet/qlogic/qed/qed_roce.h
+++ b/drivers/net/ethernet/qlogic/qed/qed_roce.h
@@ -95,26 +95,6 @@ struct qed_rdma_info {
95 enum protocol_type proto; 95 enum protocol_type proto;
96}; 96};
97 97
98struct qed_rdma_resize_cq_in_params {
99 u16 icid;
100 u32 cq_size;
101 bool pbl_two_level;
102 u64 pbl_ptr;
103 u16 pbl_num_pages;
104 u8 pbl_page_size_log;
105};
106
107struct qed_rdma_resize_cq_out_params {
108 u32 prod;
109 u32 cons;
110};
111
112struct qed_rdma_resize_cnq_in_params {
113 u32 cnq_id;
114 u32 pbl_page_size_log;
115 u64 pbl_ptr;
116};
117
118struct qed_rdma_qp { 98struct qed_rdma_qp {
119 struct regpair qp_handle; 99 struct regpair qp_handle;
120 struct regpair qp_handle_async; 100 struct regpair qp_handle_async;
@@ -181,36 +161,55 @@ struct qed_rdma_qp {
181 dma_addr_t shared_queue_phys_addr; 161 dma_addr_t shared_queue_phys_addr;
182}; 162};
183 163
184int 164#if IS_ENABLED(CONFIG_QED_RDMA)
185qed_rdma_add_user(void *rdma_cxt, 165void qed_rdma_dpm_bar(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
186 struct qed_rdma_add_user_out_params *out_params);
187int qed_rdma_alloc_pd(void *rdma_cxt, u16 *pd);
188int qed_rdma_alloc_tid(void *rdma_cxt, u32 *tid);
189int qed_rdma_deregister_tid(void *rdma_cxt, u32 tid);
190void qed_rdma_free_tid(void *rdma_cxt, u32 tid);
191struct qed_rdma_device *qed_rdma_query_device(void *rdma_cxt);
192struct qed_rdma_port *qed_rdma_query_port(void *rdma_cxt);
193int
194qed_rdma_register_tid(void *rdma_cxt,
195 struct qed_rdma_register_tid_in_params *params);
196void qed_rdma_remove_user(void *rdma_cxt, u16 dpi);
197int qed_rdma_start(void *p_hwfn, struct qed_rdma_start_in_params *params);
198int qed_rdma_stop(void *rdma_cxt);
199u32 qed_rdma_get_sb_id(void *p_hwfn, u32 rel_sb_id);
200u32 qed_rdma_query_cau_timer_res(void *p_hwfn);
201void qed_rdma_cnq_prod_update(void *rdma_cxt, u8 cnq_index, u16 prod);
202void qed_rdma_resc_free(struct qed_hwfn *p_hwfn);
203void qed_async_roce_event(struct qed_hwfn *p_hwfn, 166void qed_async_roce_event(struct qed_hwfn *p_hwfn,
204 struct event_ring_entry *p_eqe); 167 struct event_ring_entry *p_eqe);
205int qed_rdma_destroy_qp(void *rdma_cxt, struct qed_rdma_qp *qp); 168void qed_ll2b_complete_tx_gsi_packet(struct qed_hwfn *p_hwfn,
206int qed_rdma_modify_qp(void *rdma_cxt, struct qed_rdma_qp *qp, 169 u8 connection_handle,
207 struct qed_rdma_modify_qp_in_params *params); 170 void *cookie,
208int qed_rdma_query_qp(void *rdma_cxt, struct qed_rdma_qp *qp, 171 dma_addr_t first_frag_addr,
209 struct qed_rdma_query_qp_out_params *out_params); 172 bool b_last_fragment, bool b_last_packet);
210 173void qed_ll2b_release_tx_gsi_packet(struct qed_hwfn *p_hwfn,
211#if IS_ENABLED(CONFIG_INFINIBAND_QEDR) 174 u8 connection_handle,
212void qed_rdma_dpm_bar(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt); 175 void *cookie,
176 dma_addr_t first_frag_addr,
177 bool b_last_fragment, bool b_last_packet);
178void qed_ll2b_complete_rx_gsi_packet(struct qed_hwfn *p_hwfn,
179 u8 connection_handle,
180 void *cookie,
181 dma_addr_t rx_buf_addr,
182 u16 data_length,
183 u8 data_length_error,
184 u16 parse_flags,
185 u16 vlan,
186 u32 src_mac_addr_hi,
187 u16 src_mac_addr_lo, bool b_last_packet);
213#else 188#else
214void qed_rdma_dpm_bar(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt) {} 189static inline void qed_rdma_dpm_bar(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt) {}
190static inline void qed_async_roce_event(struct qed_hwfn *p_hwfn, struct event_ring_entry *p_eqe) {}
191static inline void qed_ll2b_complete_tx_gsi_packet(struct qed_hwfn *p_hwfn,
192 u8 connection_handle,
193 void *cookie,
194 dma_addr_t first_frag_addr,
195 bool b_last_fragment,
196 bool b_last_packet) {}
197static inline void qed_ll2b_release_tx_gsi_packet(struct qed_hwfn *p_hwfn,
198 u8 connection_handle,
199 void *cookie,
200 dma_addr_t first_frag_addr,
201 bool b_last_fragment,
202 bool b_last_packet) {}
203static inline void qed_ll2b_complete_rx_gsi_packet(struct qed_hwfn *p_hwfn,
204 u8 connection_handle,
205 void *cookie,
206 dma_addr_t rx_buf_addr,
207 u16 data_length,
208 u8 data_length_error,
209 u16 parse_flags,
210 u16 vlan,
211 u32 src_mac_addr_hi,
212 u16 src_mac_addr_lo,
213 bool b_last_packet) {}
215#endif 214#endif
216#endif 215#endif
diff --git a/drivers/net/ethernet/qlogic/qed/qed_sp.h b/drivers/net/ethernet/qlogic/qed/qed_sp.h
index 652c90819758..b2c08e4d2a9b 100644
--- a/drivers/net/ethernet/qlogic/qed/qed_sp.h
+++ b/drivers/net/ethernet/qlogic/qed/qed_sp.h
@@ -80,7 +80,6 @@ union ramrod_data {
80 struct roce_destroy_qp_resp_ramrod_data roce_destroy_qp_resp; 80 struct roce_destroy_qp_resp_ramrod_data roce_destroy_qp_resp;
81 struct roce_destroy_qp_req_ramrod_data roce_destroy_qp_req; 81 struct roce_destroy_qp_req_ramrod_data roce_destroy_qp_req;
82 struct rdma_create_cq_ramrod_data rdma_create_cq; 82 struct rdma_create_cq_ramrod_data rdma_create_cq;
83 struct rdma_resize_cq_ramrod_data rdma_resize_cq;
84 struct rdma_destroy_cq_ramrod_data rdma_destroy_cq; 83 struct rdma_destroy_cq_ramrod_data rdma_destroy_cq;
85 struct rdma_srq_create_ramrod_data rdma_create_srq; 84 struct rdma_srq_create_ramrod_data rdma_create_srq;
86 struct rdma_srq_destroy_ramrod_data rdma_destroy_srq; 85 struct rdma_srq_destroy_ramrod_data rdma_destroy_srq;
diff --git a/drivers/net/ethernet/qlogic/qed/qed_spq.c b/drivers/net/ethernet/qlogic/qed/qed_spq.c
index caff41544898..9fbaf9429fd0 100644
--- a/drivers/net/ethernet/qlogic/qed/qed_spq.c
+++ b/drivers/net/ethernet/qlogic/qed/qed_spq.c
@@ -28,9 +28,7 @@
28#include "qed_reg_addr.h" 28#include "qed_reg_addr.h"
29#include "qed_sp.h" 29#include "qed_sp.h"
30#include "qed_sriov.h" 30#include "qed_sriov.h"
31#if IS_ENABLED(CONFIG_INFINIBAND_QEDR)
32#include "qed_roce.h" 31#include "qed_roce.h"
33#endif
34 32
35/*************************************************************************** 33/***************************************************************************
36* Structures & Definitions 34* Structures & Definitions
@@ -240,11 +238,9 @@ qed_async_event_completion(struct qed_hwfn *p_hwfn,
240 struct event_ring_entry *p_eqe) 238 struct event_ring_entry *p_eqe)
241{ 239{
242 switch (p_eqe->protocol_id) { 240 switch (p_eqe->protocol_id) {
243#if IS_ENABLED(CONFIG_INFINIBAND_QEDR)
244 case PROTOCOLID_ROCE: 241 case PROTOCOLID_ROCE:
245 qed_async_roce_event(p_hwfn, p_eqe); 242 qed_async_roce_event(p_hwfn, p_eqe);
246 return 0; 243 return 0;
247#endif
248 case PROTOCOLID_COMMON: 244 case PROTOCOLID_COMMON:
249 return qed_sriov_eqe_event(p_hwfn, 245 return qed_sriov_eqe_event(p_hwfn,
250 p_eqe->opcode, 246 p_eqe->opcode,
diff --git a/drivers/net/ethernet/qlogic/qede/Makefile b/drivers/net/ethernet/qlogic/qede/Makefile
index 28dc58919c85..048a230c3ce0 100644
--- a/drivers/net/ethernet/qlogic/qede/Makefile
+++ b/drivers/net/ethernet/qlogic/qede/Makefile
@@ -2,4 +2,4 @@ obj-$(CONFIG_QEDE) := qede.o
2 2
3qede-y := qede_main.o qede_ethtool.o 3qede-y := qede_main.o qede_ethtool.o
4qede-$(CONFIG_DCB) += qede_dcbnl.o 4qede-$(CONFIG_DCB) += qede_dcbnl.o
5qede-$(CONFIG_INFINIBAND_QEDR) += qede_roce.o 5qede-$(CONFIG_QED_RDMA) += qede_roce.o
diff --git a/drivers/net/ethernet/qlogic/qede/qede.h b/drivers/net/ethernet/qlogic/qede/qede.h
index 28c0e9f42c9e..974689a13337 100644
--- a/drivers/net/ethernet/qlogic/qede/qede.h
+++ b/drivers/net/ethernet/qlogic/qede/qede.h
@@ -348,12 +348,13 @@ bool qede_has_rx_work(struct qede_rx_queue *rxq);
348int qede_txq_has_work(struct qede_tx_queue *txq); 348int qede_txq_has_work(struct qede_tx_queue *txq);
349void qede_recycle_rx_bd_ring(struct qede_rx_queue *rxq, struct qede_dev *edev, 349void qede_recycle_rx_bd_ring(struct qede_rx_queue *rxq, struct qede_dev *edev,
350 u8 count); 350 u8 count);
351void qede_update_rx_prod(struct qede_dev *edev, struct qede_rx_queue *rxq);
351 352
352#define RX_RING_SIZE_POW 13 353#define RX_RING_SIZE_POW 13
353#define RX_RING_SIZE ((u16)BIT(RX_RING_SIZE_POW)) 354#define RX_RING_SIZE ((u16)BIT(RX_RING_SIZE_POW))
354#define NUM_RX_BDS_MAX (RX_RING_SIZE - 1) 355#define NUM_RX_BDS_MAX (RX_RING_SIZE - 1)
355#define NUM_RX_BDS_MIN 128 356#define NUM_RX_BDS_MIN 128
356#define NUM_RX_BDS_DEF NUM_RX_BDS_MAX 357#define NUM_RX_BDS_DEF ((u16)BIT(10) - 1)
357 358
358#define TX_RING_SIZE_POW 13 359#define TX_RING_SIZE_POW 13
359#define TX_RING_SIZE ((u16)BIT(TX_RING_SIZE_POW)) 360#define TX_RING_SIZE ((u16)BIT(TX_RING_SIZE_POW))
diff --git a/drivers/net/ethernet/qlogic/qede/qede_ethtool.c b/drivers/net/ethernet/qlogic/qede/qede_ethtool.c
index 25a9b293ee8f..7567cc464b88 100644
--- a/drivers/net/ethernet/qlogic/qede/qede_ethtool.c
+++ b/drivers/net/ethernet/qlogic/qede/qede_ethtool.c
@@ -175,16 +175,23 @@ static void qede_get_strings_stats(struct qede_dev *edev, u8 *buf)
175 for (i = 0, k = 0; i < QEDE_QUEUE_CNT(edev); i++) { 175 for (i = 0, k = 0; i < QEDE_QUEUE_CNT(edev); i++) {
176 int tc; 176 int tc;
177 177
178 for (j = 0; j < QEDE_NUM_RQSTATS; j++) 178 if (edev->fp_array[i].type & QEDE_FASTPATH_RX) {
179 sprintf(buf + (k + j) * ETH_GSTRING_LEN, 179 for (j = 0; j < QEDE_NUM_RQSTATS; j++)
180 "%d: %s", i, qede_rqstats_arr[j].string);
181 k += QEDE_NUM_RQSTATS;
182 for (tc = 0; tc < edev->num_tc; tc++) {
183 for (j = 0; j < QEDE_NUM_TQSTATS; j++)
184 sprintf(buf + (k + j) * ETH_GSTRING_LEN, 180 sprintf(buf + (k + j) * ETH_GSTRING_LEN,
185 "%d.%d: %s", i, tc, 181 "%d: %s", i,
186 qede_tqstats_arr[j].string); 182 qede_rqstats_arr[j].string);
187 k += QEDE_NUM_TQSTATS; 183 k += QEDE_NUM_RQSTATS;
184 }
185
186 if (edev->fp_array[i].type & QEDE_FASTPATH_TX) {
187 for (tc = 0; tc < edev->num_tc; tc++) {
188 for (j = 0; j < QEDE_NUM_TQSTATS; j++)
189 sprintf(buf + (k + j) *
190 ETH_GSTRING_LEN,
191 "%d.%d: %s", i, tc,
192 qede_tqstats_arr[j].string);
193 k += QEDE_NUM_TQSTATS;
194 }
188 } 195 }
189 } 196 }
190 197
@@ -756,6 +763,8 @@ static void qede_get_channels(struct net_device *dev,
756 struct qede_dev *edev = netdev_priv(dev); 763 struct qede_dev *edev = netdev_priv(dev);
757 764
758 channels->max_combined = QEDE_MAX_RSS_CNT(edev); 765 channels->max_combined = QEDE_MAX_RSS_CNT(edev);
766 channels->max_rx = QEDE_MAX_RSS_CNT(edev);
767 channels->max_tx = QEDE_MAX_RSS_CNT(edev);
759 channels->combined_count = QEDE_QUEUE_CNT(edev) - edev->fp_num_tx - 768 channels->combined_count = QEDE_QUEUE_CNT(edev) - edev->fp_num_tx -
760 edev->fp_num_rx; 769 edev->fp_num_rx;
761 channels->tx_count = edev->fp_num_tx; 770 channels->tx_count = edev->fp_num_tx;
@@ -820,6 +829,13 @@ static int qede_set_channels(struct net_device *dev,
820 edev->req_queues = count; 829 edev->req_queues = count;
821 edev->req_num_tx = channels->tx_count; 830 edev->req_num_tx = channels->tx_count;
822 edev->req_num_rx = channels->rx_count; 831 edev->req_num_rx = channels->rx_count;
832 /* Reset the indirection table if rx queue count is updated */
833 if ((edev->req_queues - edev->req_num_tx) != QEDE_RSS_COUNT(edev)) {
834 edev->rss_params_inited &= ~QEDE_RSS_INDIR_INITED;
835 memset(&edev->rss_params.rss_ind_table, 0,
836 sizeof(edev->rss_params.rss_ind_table));
837 }
838
823 if (netif_running(dev)) 839 if (netif_running(dev))
824 qede_reload(edev, NULL, NULL); 840 qede_reload(edev, NULL, NULL);
825 841
@@ -1053,6 +1069,12 @@ static int qede_set_rxfh(struct net_device *dev, const u32 *indir,
1053 struct qede_dev *edev = netdev_priv(dev); 1069 struct qede_dev *edev = netdev_priv(dev);
1054 int i; 1070 int i;
1055 1071
1072 if (edev->dev_info.common.num_hwfns > 1) {
1073 DP_INFO(edev,
1074 "RSS configuration is not supported for 100G devices\n");
1075 return -EOPNOTSUPP;
1076 }
1077
1056 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP) 1078 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
1057 return -EOPNOTSUPP; 1079 return -EOPNOTSUPP;
1058 1080
@@ -1184,8 +1206,8 @@ static int qede_selftest_transmit_traffic(struct qede_dev *edev,
1184 } 1206 }
1185 1207
1186 first_bd = (struct eth_tx_1st_bd *)qed_chain_consume(&txq->tx_pbl); 1208 first_bd = (struct eth_tx_1st_bd *)qed_chain_consume(&txq->tx_pbl);
1187 dma_unmap_page(&edev->pdev->dev, BD_UNMAP_ADDR(first_bd), 1209 dma_unmap_single(&edev->pdev->dev, BD_UNMAP_ADDR(first_bd),
1188 BD_UNMAP_LEN(first_bd), DMA_TO_DEVICE); 1210 BD_UNMAP_LEN(first_bd), DMA_TO_DEVICE);
1189 txq->sw_tx_cons++; 1211 txq->sw_tx_cons++;
1190 txq->sw_tx_ring[idx].skb = NULL; 1212 txq->sw_tx_ring[idx].skb = NULL;
1191 1213
@@ -1199,8 +1221,8 @@ static int qede_selftest_receive_traffic(struct qede_dev *edev)
1199 struct qede_rx_queue *rxq = NULL; 1221 struct qede_rx_queue *rxq = NULL;
1200 struct sw_rx_data *sw_rx_data; 1222 struct sw_rx_data *sw_rx_data;
1201 union eth_rx_cqe *cqe; 1223 union eth_rx_cqe *cqe;
1224 int i, rc = 0;
1202 u8 *data_ptr; 1225 u8 *data_ptr;
1203 int i;
1204 1226
1205 for_each_queue(i) { 1227 for_each_queue(i) {
1206 if (edev->fp_array[i].type & QEDE_FASTPATH_RX) { 1228 if (edev->fp_array[i].type & QEDE_FASTPATH_RX) {
@@ -1219,46 +1241,60 @@ static int qede_selftest_receive_traffic(struct qede_dev *edev)
1219 * queue and that the loopback traffic is not IP. 1241 * queue and that the loopback traffic is not IP.
1220 */ 1242 */
1221 for (i = 0; i < QEDE_SELFTEST_POLL_COUNT; i++) { 1243 for (i = 0; i < QEDE_SELFTEST_POLL_COUNT; i++) {
1222 if (qede_has_rx_work(rxq)) 1244 if (!qede_has_rx_work(rxq)) {
1245 usleep_range(100, 200);
1246 continue;
1247 }
1248
1249 hw_comp_cons = le16_to_cpu(*rxq->hw_cons_ptr);
1250 sw_comp_cons = qed_chain_get_cons_idx(&rxq->rx_comp_ring);
1251
1252 /* Memory barrier to prevent the CPU from doing speculative
1253 * reads of CQE/BD before reading hw_comp_cons. If the CQE is
1254 * read before it is written by FW, then FW writes CQE and SB,
1255 * and then the CPU reads the hw_comp_cons, it will use an old
1256 * CQE.
1257 */
1258 rmb();
1259
1260 /* Get the CQE from the completion ring */
1261 cqe = (union eth_rx_cqe *)qed_chain_consume(&rxq->rx_comp_ring);
1262
1263 /* Get the data from the SW ring */
1264 sw_rx_index = rxq->sw_rx_cons & NUM_RX_BDS_MAX;
1265 sw_rx_data = &rxq->sw_rx_ring[sw_rx_index];
1266 fp_cqe = &cqe->fast_path_regular;
1267 len = le16_to_cpu(fp_cqe->len_on_first_bd);
1268 data_ptr = (u8 *)(page_address(sw_rx_data->data) +
1269 fp_cqe->placement_offset +
1270 sw_rx_data->page_offset);
1271 if (ether_addr_equal(data_ptr, edev->ndev->dev_addr) &&
1272 ether_addr_equal(data_ptr + ETH_ALEN,
1273 edev->ndev->dev_addr)) {
1274 for (i = ETH_HLEN; i < len; i++)
1275 if (data_ptr[i] != (unsigned char)(i & 0xff)) {
1276 rc = -1;
1277 break;
1278 }
1279
1280 qede_recycle_rx_bd_ring(rxq, edev, 1);
1281 qed_chain_recycle_consumed(&rxq->rx_comp_ring);
1223 break; 1282 break;
1224 usleep_range(100, 200); 1283 }
1284
1285 DP_INFO(edev, "Not the transmitted packet\n");
1286 qede_recycle_rx_bd_ring(rxq, edev, 1);
1287 qed_chain_recycle_consumed(&rxq->rx_comp_ring);
1225 } 1288 }
1226 1289
1227 if (!qede_has_rx_work(rxq)) { 1290 if (i == QEDE_SELFTEST_POLL_COUNT) {
1228 DP_NOTICE(edev, "Failed to receive the traffic\n"); 1291 DP_NOTICE(edev, "Failed to receive the traffic\n");
1229 return -1; 1292 return -1;
1230 } 1293 }
1231 1294
1232 hw_comp_cons = le16_to_cpu(*rxq->hw_cons_ptr); 1295 qede_update_rx_prod(edev, rxq);
1233 sw_comp_cons = qed_chain_get_cons_idx(&rxq->rx_comp_ring);
1234 1296
1235 /* Memory barrier to prevent the CPU from doing speculative reads of CQE 1297 return rc;
1236 * / BD before reading hw_comp_cons. If the CQE is read before it is
1237 * written by FW, then FW writes CQE and SB, and then the CPU reads the
1238 * hw_comp_cons, it will use an old CQE.
1239 */
1240 rmb();
1241
1242 /* Get the CQE from the completion ring */
1243 cqe = (union eth_rx_cqe *)qed_chain_consume(&rxq->rx_comp_ring);
1244
1245 /* Get the data from the SW ring */
1246 sw_rx_index = rxq->sw_rx_cons & NUM_RX_BDS_MAX;
1247 sw_rx_data = &rxq->sw_rx_ring[sw_rx_index];
1248 fp_cqe = &cqe->fast_path_regular;
1249 len = le16_to_cpu(fp_cqe->len_on_first_bd);
1250 data_ptr = (u8 *)(page_address(sw_rx_data->data) +
1251 fp_cqe->placement_offset + sw_rx_data->page_offset);
1252 for (i = ETH_HLEN; i < len; i++)
1253 if (data_ptr[i] != (unsigned char)(i & 0xff)) {
1254 DP_NOTICE(edev, "Loopback test failed\n");
1255 qede_recycle_rx_bd_ring(rxq, edev, 1);
1256 return -1;
1257 }
1258
1259 qede_recycle_rx_bd_ring(rxq, edev, 1);
1260
1261 return 0;
1262} 1298}
1263 1299
1264static int qede_selftest_run_loopback(struct qede_dev *edev, u32 loopback_mode) 1300static int qede_selftest_run_loopback(struct qede_dev *edev, u32 loopback_mode)
diff --git a/drivers/net/ethernet/qlogic/qede/qede_main.c b/drivers/net/ethernet/qlogic/qede/qede_main.c
index 343038ca047d..85f46dbecd5b 100644
--- a/drivers/net/ethernet/qlogic/qede/qede_main.c
+++ b/drivers/net/ethernet/qlogic/qede/qede_main.c
@@ -313,8 +313,8 @@ static int qede_free_tx_pkt(struct qede_dev *edev,
313 split_bd_len = BD_UNMAP_LEN(split); 313 split_bd_len = BD_UNMAP_LEN(split);
314 bds_consumed++; 314 bds_consumed++;
315 } 315 }
316 dma_unmap_page(&edev->pdev->dev, BD_UNMAP_ADDR(first_bd), 316 dma_unmap_single(&edev->pdev->dev, BD_UNMAP_ADDR(first_bd),
317 BD_UNMAP_LEN(first_bd) + split_bd_len, DMA_TO_DEVICE); 317 BD_UNMAP_LEN(first_bd) + split_bd_len, DMA_TO_DEVICE);
318 318
319 /* Unmap the data of the skb frags */ 319 /* Unmap the data of the skb frags */
320 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++, bds_consumed++) { 320 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++, bds_consumed++) {
@@ -359,8 +359,8 @@ static void qede_free_failed_tx_pkt(struct qede_dev *edev,
359 nbd--; 359 nbd--;
360 } 360 }
361 361
362 dma_unmap_page(&edev->pdev->dev, BD_UNMAP_ADDR(first_bd), 362 dma_unmap_single(&edev->pdev->dev, BD_UNMAP_ADDR(first_bd),
363 BD_UNMAP_LEN(first_bd) + split_bd_len, DMA_TO_DEVICE); 363 BD_UNMAP_LEN(first_bd) + split_bd_len, DMA_TO_DEVICE);
364 364
365 /* Unmap the data of the skb frags */ 365 /* Unmap the data of the skb frags */
366 for (i = 0; i < nbd; i++) { 366 for (i = 0; i < nbd; i++) {
@@ -943,8 +943,7 @@ static inline int qede_realloc_rx_buffer(struct qede_dev *edev,
943 return 0; 943 return 0;
944} 944}
945 945
946static inline void qede_update_rx_prod(struct qede_dev *edev, 946void qede_update_rx_prod(struct qede_dev *edev, struct qede_rx_queue *rxq)
947 struct qede_rx_queue *rxq)
948{ 947{
949 u16 bd_prod = qed_chain_get_prod_idx(&rxq->rx_bd_ring); 948 u16 bd_prod = qed_chain_get_prod_idx(&rxq->rx_bd_ring);
950 u16 cqe_prod = qed_chain_get_prod_idx(&rxq->rx_comp_ring); 949 u16 cqe_prod = qed_chain_get_prod_idx(&rxq->rx_comp_ring);
@@ -2840,7 +2839,7 @@ static int qede_alloc_sge_mem(struct qede_dev *edev, struct qede_rx_queue *rxq)
2840 } 2839 }
2841 2840
2842 mapping = dma_map_page(&edev->pdev->dev, replace_buf->data, 0, 2841 mapping = dma_map_page(&edev->pdev->dev, replace_buf->data, 0,
2843 rxq->rx_buf_size, DMA_FROM_DEVICE); 2842 PAGE_SIZE, DMA_FROM_DEVICE);
2844 if (unlikely(dma_mapping_error(&edev->pdev->dev, mapping))) { 2843 if (unlikely(dma_mapping_error(&edev->pdev->dev, mapping))) {
2845 DP_NOTICE(edev, 2844 DP_NOTICE(edev,
2846 "Failed to map TPA replacement buffer\n"); 2845 "Failed to map TPA replacement buffer\n");
@@ -2941,7 +2940,7 @@ static int qede_alloc_mem_txq(struct qede_dev *edev, struct qede_tx_queue *txq)
2941 txq->num_tx_buffers = edev->q_num_tx_buffers; 2940 txq->num_tx_buffers = edev->q_num_tx_buffers;
2942 2941
2943 /* Allocate the parallel driver ring for Tx buffers */ 2942 /* Allocate the parallel driver ring for Tx buffers */
2944 size = sizeof(*txq->sw_tx_ring) * NUM_TX_BDS_MAX; 2943 size = sizeof(*txq->sw_tx_ring) * TX_RING_SIZE;
2945 txq->sw_tx_ring = kzalloc(size, GFP_KERNEL); 2944 txq->sw_tx_ring = kzalloc(size, GFP_KERNEL);
2946 if (!txq->sw_tx_ring) { 2945 if (!txq->sw_tx_ring) {
2947 DP_NOTICE(edev, "Tx buffers ring allocation failed\n"); 2946 DP_NOTICE(edev, "Tx buffers ring allocation failed\n");
@@ -2952,7 +2951,7 @@ static int qede_alloc_mem_txq(struct qede_dev *edev, struct qede_tx_queue *txq)
2952 QED_CHAIN_USE_TO_CONSUME_PRODUCE, 2951 QED_CHAIN_USE_TO_CONSUME_PRODUCE,
2953 QED_CHAIN_MODE_PBL, 2952 QED_CHAIN_MODE_PBL,
2954 QED_CHAIN_CNT_TYPE_U16, 2953 QED_CHAIN_CNT_TYPE_U16,
2955 NUM_TX_BDS_MAX, 2954 TX_RING_SIZE,
2956 sizeof(*p_virt), &txq->tx_pbl); 2955 sizeof(*p_virt), &txq->tx_pbl);
2957 if (rc) 2956 if (rc)
2958 goto err; 2957 goto err;
diff --git a/drivers/net/ethernet/qualcomm/emac/emac-mac.c b/drivers/net/ethernet/qualcomm/emac/emac-mac.c
index e97968ed4b8f..0b4deb31e742 100644
--- a/drivers/net/ethernet/qualcomm/emac/emac-mac.c
+++ b/drivers/net/ethernet/qualcomm/emac/emac-mac.c
@@ -575,10 +575,11 @@ void emac_mac_start(struct emac_adapter *adpt)
575 575
576 mac |= TXEN | RXEN; /* enable RX/TX */ 576 mac |= TXEN | RXEN; /* enable RX/TX */
577 577
578 /* We don't have ethtool support yet, so force flow-control mode 578 /* Configure MAC flow control to match the PHY's settings. */
579 * to 'full' always. 579 if (phydev->pause)
580 */ 580 mac |= RXFC;
581 mac |= TXFC | RXFC; 581 if (phydev->pause != phydev->asym_pause)
582 mac |= TXFC;
582 583
583 /* setup link speed */ 584 /* setup link speed */
584 mac &= ~SPEED_MASK; 585 mac &= ~SPEED_MASK;
@@ -1003,6 +1004,12 @@ int emac_mac_up(struct emac_adapter *adpt)
1003 writel((u32)~DIS_INT, adpt->base + EMAC_INT_STATUS); 1004 writel((u32)~DIS_INT, adpt->base + EMAC_INT_STATUS);
1004 writel(adpt->irq.mask, adpt->base + EMAC_INT_MASK); 1005 writel(adpt->irq.mask, adpt->base + EMAC_INT_MASK);
1005 1006
1007 /* Enable pause frames. Without this feature, the EMAC has been shown
1008 * to receive (and drop) frames with FCS errors at gigabit connections.
1009 */
1010 adpt->phydev->supported |= SUPPORTED_Pause | SUPPORTED_Asym_Pause;
1011 adpt->phydev->advertising |= SUPPORTED_Pause | SUPPORTED_Asym_Pause;
1012
1006 adpt->phydev->irq = PHY_IGNORE_INTERRUPT; 1013 adpt->phydev->irq = PHY_IGNORE_INTERRUPT;
1007 phy_start(adpt->phydev); 1014 phy_start(adpt->phydev);
1008 1015
@@ -1021,14 +1028,18 @@ void emac_mac_down(struct emac_adapter *adpt)
1021 napi_disable(&adpt->rx_q.napi); 1028 napi_disable(&adpt->rx_q.napi);
1022 1029
1023 phy_stop(adpt->phydev); 1030 phy_stop(adpt->phydev);
1024 phy_disconnect(adpt->phydev);
1025 1031
1026 /* disable mac irq */ 1032 /* Interrupts must be disabled before the PHY is disconnected, to
1033 * avoid a race condition where adjust_link is null when we get
1034 * an interrupt.
1035 */
1027 writel(DIS_INT, adpt->base + EMAC_INT_STATUS); 1036 writel(DIS_INT, adpt->base + EMAC_INT_STATUS);
1028 writel(0, adpt->base + EMAC_INT_MASK); 1037 writel(0, adpt->base + EMAC_INT_MASK);
1029 synchronize_irq(adpt->irq.irq); 1038 synchronize_irq(adpt->irq.irq);
1030 free_irq(adpt->irq.irq, &adpt->irq); 1039 free_irq(adpt->irq.irq, &adpt->irq);
1031 1040
1041 phy_disconnect(adpt->phydev);
1042
1032 emac_mac_reset(adpt); 1043 emac_mac_reset(adpt);
1033 1044
1034 emac_tx_q_descs_free(adpt); 1045 emac_tx_q_descs_free(adpt);
diff --git a/drivers/net/ethernet/qualcomm/emac/emac-phy.c b/drivers/net/ethernet/qualcomm/emac/emac-phy.c
index da4e90db4d98..99a14df28b96 100644
--- a/drivers/net/ethernet/qualcomm/emac/emac-phy.c
+++ b/drivers/net/ethernet/qualcomm/emac/emac-phy.c
@@ -212,6 +212,7 @@ int emac_phy_config(struct platform_device *pdev, struct emac_adapter *adpt)
212 212
213 phy_np = of_parse_phandle(np, "phy-handle", 0); 213 phy_np = of_parse_phandle(np, "phy-handle", 0);
214 adpt->phydev = of_phy_find_device(phy_np); 214 adpt->phydev = of_phy_find_device(phy_np);
215 of_node_put(phy_np);
215 } 216 }
216 217
217 if (!adpt->phydev) { 218 if (!adpt->phydev) {
diff --git a/drivers/net/ethernet/qualcomm/emac/emac-sgmii.c b/drivers/net/ethernet/qualcomm/emac/emac-sgmii.c
index 75c1b530e39e..72fe343c7a36 100644
--- a/drivers/net/ethernet/qualcomm/emac/emac-sgmii.c
+++ b/drivers/net/ethernet/qualcomm/emac/emac-sgmii.c
@@ -421,7 +421,7 @@ static const struct emac_reg_write sgmii_v2_laned[] = {
421 /* CDR Settings */ 421 /* CDR Settings */
422 {EMAC_SGMII_LN_UCDR_FO_GAIN_MODE0, 422 {EMAC_SGMII_LN_UCDR_FO_GAIN_MODE0,
423 UCDR_STEP_BY_TWO_MODE0 | UCDR_xO_GAIN_MODE(10)}, 423 UCDR_STEP_BY_TWO_MODE0 | UCDR_xO_GAIN_MODE(10)},
424 {EMAC_SGMII_LN_UCDR_SO_GAIN_MODE0, UCDR_xO_GAIN_MODE(6)}, 424 {EMAC_SGMII_LN_UCDR_SO_GAIN_MODE0, UCDR_xO_GAIN_MODE(0)},
425 {EMAC_SGMII_LN_UCDR_SO_CONFIG, UCDR_ENABLE | UCDR_SO_SATURATION(12)}, 425 {EMAC_SGMII_LN_UCDR_SO_CONFIG, UCDR_ENABLE | UCDR_SO_SATURATION(12)},
426 426
427 /* TX/RX Settings */ 427 /* TX/RX Settings */
diff --git a/drivers/net/ethernet/qualcomm/emac/emac.c b/drivers/net/ethernet/qualcomm/emac/emac.c
index 9bf3b2b82e95..57b35aeac51a 100644
--- a/drivers/net/ethernet/qualcomm/emac/emac.c
+++ b/drivers/net/ethernet/qualcomm/emac/emac.c
@@ -575,6 +575,7 @@ static const struct of_device_id emac_dt_match[] = {
575 }, 575 },
576 {} 576 {}
577}; 577};
578MODULE_DEVICE_TABLE(of, emac_dt_match);
578 579
579#if IS_ENABLED(CONFIG_ACPI) 580#if IS_ENABLED(CONFIG_ACPI)
580static const struct acpi_device_id emac_acpi_match[] = { 581static const struct acpi_device_id emac_acpi_match[] = {
@@ -710,6 +711,8 @@ static int emac_probe(struct platform_device *pdev)
710err_undo_napi: 711err_undo_napi:
711 netif_napi_del(&adpt->rx_q.napi); 712 netif_napi_del(&adpt->rx_q.napi);
712err_undo_mdiobus: 713err_undo_mdiobus:
714 if (!has_acpi_companion(&pdev->dev))
715 put_device(&adpt->phydev->mdio.dev);
713 mdiobus_unregister(adpt->mii_bus); 716 mdiobus_unregister(adpt->mii_bus);
714err_undo_clocks: 717err_undo_clocks:
715 emac_clks_teardown(adpt); 718 emac_clks_teardown(adpt);
@@ -729,6 +732,8 @@ static int emac_remove(struct platform_device *pdev)
729 732
730 emac_clks_teardown(adpt); 733 emac_clks_teardown(adpt);
731 734
735 if (!has_acpi_companion(&pdev->dev))
736 put_device(&adpt->phydev->mdio.dev);
732 mdiobus_unregister(adpt->mii_bus); 737 mdiobus_unregister(adpt->mii_bus);
733 free_netdev(netdev); 738 free_netdev(netdev);
734 739
diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
index e55638c7505a..bf000d819a21 100644
--- a/drivers/net/ethernet/realtek/r8169.c
+++ b/drivers/net/ethernet/realtek/r8169.c
@@ -8273,7 +8273,8 @@ static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
8273 if ((sizeof(dma_addr_t) > 4) && 8273 if ((sizeof(dma_addr_t) > 4) &&
8274 (use_dac == 1 || (use_dac == -1 && pci_is_pcie(pdev) && 8274 (use_dac == 1 || (use_dac == -1 && pci_is_pcie(pdev) &&
8275 tp->mac_version >= RTL_GIGA_MAC_VER_18)) && 8275 tp->mac_version >= RTL_GIGA_MAC_VER_18)) &&
8276 !pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) { 8276 !pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) &&
8277 !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64))) {
8277 8278
8278 /* CPlusCmd Dual Access Cycle is only needed for non-PCIe */ 8279 /* CPlusCmd Dual Access Cycle is only needed for non-PCIe */
8279 if (!pci_is_pcie(pdev)) 8280 if (!pci_is_pcie(pdev))
diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c
index 630536bc72f9..d6a217874a8b 100644
--- a/drivers/net/ethernet/renesas/ravb_main.c
+++ b/drivers/net/ethernet/renesas/ravb_main.c
@@ -1008,20 +1008,18 @@ static int ravb_phy_init(struct net_device *ndev)
1008 of_node_put(pn); 1008 of_node_put(pn);
1009 if (!phydev) { 1009 if (!phydev) {
1010 netdev_err(ndev, "failed to connect PHY\n"); 1010 netdev_err(ndev, "failed to connect PHY\n");
1011 return -ENOENT; 1011 err = -ENOENT;
1012 goto err_deregister_fixed_link;
1012 } 1013 }
1013 1014
1014 /* This driver only support 10/100Mbit speeds on Gen3 1015 /* This driver only support 10/100Mbit speeds on Gen3
1015 * at this time. 1016 * at this time.
1016 */ 1017 */
1017 if (priv->chip_id == RCAR_GEN3) { 1018 if (priv->chip_id == RCAR_GEN3) {
1018 int err;
1019
1020 err = phy_set_max_speed(phydev, SPEED_100); 1019 err = phy_set_max_speed(phydev, SPEED_100);
1021 if (err) { 1020 if (err) {
1022 netdev_err(ndev, "failed to limit PHY to 100Mbit/s\n"); 1021 netdev_err(ndev, "failed to limit PHY to 100Mbit/s\n");
1023 phy_disconnect(phydev); 1022 goto err_phy_disconnect;
1024 return err;
1025 } 1023 }
1026 1024
1027 netdev_info(ndev, "limited PHY to 100Mbit/s\n"); 1025 netdev_info(ndev, "limited PHY to 100Mbit/s\n");
@@ -1033,6 +1031,14 @@ static int ravb_phy_init(struct net_device *ndev)
1033 phy_attached_info(phydev); 1031 phy_attached_info(phydev);
1034 1032
1035 return 0; 1033 return 0;
1034
1035err_phy_disconnect:
1036 phy_disconnect(phydev);
1037err_deregister_fixed_link:
1038 if (of_phy_is_fixed_link(np))
1039 of_phy_deregister_fixed_link(np);
1040
1041 return err;
1036} 1042}
1037 1043
1038/* PHY control start function */ 1044/* PHY control start function */
@@ -1634,6 +1640,7 @@ static void ravb_set_rx_mode(struct net_device *ndev)
1634/* Device close function for Ethernet AVB */ 1640/* Device close function for Ethernet AVB */
1635static int ravb_close(struct net_device *ndev) 1641static int ravb_close(struct net_device *ndev)
1636{ 1642{
1643 struct device_node *np = ndev->dev.parent->of_node;
1637 struct ravb_private *priv = netdev_priv(ndev); 1644 struct ravb_private *priv = netdev_priv(ndev);
1638 struct ravb_tstamp_skb *ts_skb, *ts_skb2; 1645 struct ravb_tstamp_skb *ts_skb, *ts_skb2;
1639 1646
@@ -1663,6 +1670,8 @@ static int ravb_close(struct net_device *ndev)
1663 if (ndev->phydev) { 1670 if (ndev->phydev) {
1664 phy_stop(ndev->phydev); 1671 phy_stop(ndev->phydev);
1665 phy_disconnect(ndev->phydev); 1672 phy_disconnect(ndev->phydev);
1673 if (of_phy_is_fixed_link(np))
1674 of_phy_deregister_fixed_link(np);
1666 } 1675 }
1667 1676
1668 if (priv->chip_id != RCAR_GEN2) { 1677 if (priv->chip_id != RCAR_GEN2) {
diff --git a/drivers/net/ethernet/renesas/sh_eth.c b/drivers/net/ethernet/renesas/sh_eth.c
index 05b0dc55de77..1a92de705199 100644
--- a/drivers/net/ethernet/renesas/sh_eth.c
+++ b/drivers/net/ethernet/renesas/sh_eth.c
@@ -518,7 +518,7 @@ static struct sh_eth_cpu_data r7s72100_data = {
518 518
519 .ecsr_value = ECSR_ICD, 519 .ecsr_value = ECSR_ICD,
520 .ecsipr_value = ECSIPR_ICDIP, 520 .ecsipr_value = ECSIPR_ICDIP,
521 .eesipr_value = 0xff7f009f, 521 .eesipr_value = 0xe77f009f,
522 522
523 .tx_check = EESR_TC1 | EESR_FTC, 523 .tx_check = EESR_TC1 | EESR_FTC,
524 .eesr_err_check = EESR_TWB1 | EESR_TWB | EESR_TABT | EESR_RABT | 524 .eesr_err_check = EESR_TWB1 | EESR_TWB | EESR_TABT | EESR_RABT |
diff --git a/drivers/net/ethernet/rocker/rocker_main.c b/drivers/net/ethernet/rocker/rocker_main.c
index 5424fb341613..24b746406bc7 100644
--- a/drivers/net/ethernet/rocker/rocker_main.c
+++ b/drivers/net/ethernet/rocker/rocker_main.c
@@ -1471,7 +1471,7 @@ static int rocker_world_check_init(struct rocker_port *rocker_port)
1471 if (rocker->wops) { 1471 if (rocker->wops) {
1472 if (rocker->wops->mode != mode) { 1472 if (rocker->wops->mode != mode) {
1473 dev_err(&rocker->pdev->dev, "hardware has ports in different worlds, which is not supported\n"); 1473 dev_err(&rocker->pdev->dev, "hardware has ports in different worlds, which is not supported\n");
1474 return err; 1474 return -EINVAL;
1475 } 1475 }
1476 return 0; 1476 return 0;
1477 } 1477 }
diff --git a/drivers/net/ethernet/rocker/rocker_ofdpa.c b/drivers/net/ethernet/rocker/rocker_ofdpa.c
index 431a60804272..4ca461322d60 100644
--- a/drivers/net/ethernet/rocker/rocker_ofdpa.c
+++ b/drivers/net/ethernet/rocker/rocker_ofdpa.c
@@ -1493,8 +1493,6 @@ static int ofdpa_port_ipv4_nh(struct ofdpa_port *ofdpa_port,
1493 spin_lock_irqsave(&ofdpa->neigh_tbl_lock, lock_flags); 1493 spin_lock_irqsave(&ofdpa->neigh_tbl_lock, lock_flags);
1494 1494
1495 found = ofdpa_neigh_tbl_find(ofdpa, ip_addr); 1495 found = ofdpa_neigh_tbl_find(ofdpa, ip_addr);
1496 if (found)
1497 *index = found->index;
1498 1496
1499 updating = found && adding; 1497 updating = found && adding;
1500 removing = found && !adding; 1498 removing = found && !adding;
@@ -1508,9 +1506,11 @@ static int ofdpa_port_ipv4_nh(struct ofdpa_port *ofdpa_port,
1508 resolved = false; 1506 resolved = false;
1509 } else if (removing) { 1507 } else if (removing) {
1510 ofdpa_neigh_del(trans, found); 1508 ofdpa_neigh_del(trans, found);
1509 *index = found->index;
1511 } else if (updating) { 1510 } else if (updating) {
1512 ofdpa_neigh_update(found, trans, NULL, false); 1511 ofdpa_neigh_update(found, trans, NULL, false);
1513 resolved = !is_zero_ether_addr(found->eth_dst); 1512 resolved = !is_zero_ether_addr(found->eth_dst);
1513 *index = found->index;
1514 } else { 1514 } else {
1515 err = -ENOENT; 1515 err = -ENOENT;
1516 } 1516 }
diff --git a/drivers/net/ethernet/sfc/efx.c b/drivers/net/ethernet/sfc/efx.c
index 3cf3557106c2..6b89e4a7b164 100644
--- a/drivers/net/ethernet/sfc/efx.c
+++ b/drivers/net/ethernet/sfc/efx.c
@@ -485,6 +485,9 @@ efx_copy_channel(const struct efx_channel *old_channel)
485 *channel = *old_channel; 485 *channel = *old_channel;
486 486
487 channel->napi_dev = NULL; 487 channel->napi_dev = NULL;
488 INIT_HLIST_NODE(&channel->napi_str.napi_hash_node);
489 channel->napi_str.napi_id = 0;
490 channel->napi_str.state = 0;
488 memset(&channel->eventq, 0, sizeof(channel->eventq)); 491 memset(&channel->eventq, 0, sizeof(channel->eventq));
489 492
490 for (j = 0; j < EFX_TXQ_TYPES; j++) { 493 for (j = 0; j < EFX_TXQ_TYPES; j++) {
diff --git a/drivers/net/ethernet/smsc/smsc911x.c b/drivers/net/ethernet/smsc/smsc911x.c
index e9b8579e6241..8b0016a785c0 100644
--- a/drivers/net/ethernet/smsc/smsc911x.c
+++ b/drivers/net/ethernet/smsc/smsc911x.c
@@ -438,9 +438,16 @@ static int smsc911x_request_resources(struct platform_device *pdev)
438 ret = regulator_bulk_get(&pdev->dev, 438 ret = regulator_bulk_get(&pdev->dev,
439 ARRAY_SIZE(pdata->supplies), 439 ARRAY_SIZE(pdata->supplies),
440 pdata->supplies); 440 pdata->supplies);
441 if (ret) 441 if (ret) {
442 /*
443 * Retry on deferrals, else just report the error
444 * and try to continue.
445 */
446 if (ret == -EPROBE_DEFER)
447 return ret;
442 netdev_err(ndev, "couldn't get regulators %d\n", 448 netdev_err(ndev, "couldn't get regulators %d\n",
443 ret); 449 ret);
450 }
444 451
445 /* Request optional RESET GPIO */ 452 /* Request optional RESET GPIO */
446 pdata->reset_gpiod = devm_gpiod_get_optional(&pdev->dev, 453 pdata->reset_gpiod = devm_gpiod_get_optional(&pdev->dev,
diff --git a/drivers/net/ethernet/stmicro/stmmac/Kconfig b/drivers/net/ethernet/stmicro/stmmac/Kconfig
index 3818c5e06eba..4b78168a5f3c 100644
--- a/drivers/net/ethernet/stmicro/stmmac/Kconfig
+++ b/drivers/net/ethernet/stmicro/stmmac/Kconfig
@@ -107,7 +107,7 @@ config DWMAC_STI
107config DWMAC_STM32 107config DWMAC_STM32
108 tristate "STM32 DWMAC support" 108 tristate "STM32 DWMAC support"
109 default ARCH_STM32 109 default ARCH_STM32
110 depends on OF && HAS_IOMEM 110 depends on OF && HAS_IOMEM && (ARCH_STM32 || COMPILE_TEST)
111 select MFD_SYSCON 111 select MFD_SYSCON
112 ---help--- 112 ---help---
113 Support for ethernet controller on STM32 SOCs. 113 Support for ethernet controller on STM32 SOCs.
diff --git a/drivers/net/ethernet/stmicro/stmmac/altr_tse_pcs.c b/drivers/net/ethernet/stmicro/stmmac/altr_tse_pcs.c
index 2920e2ee3864..489ef146201e 100644
--- a/drivers/net/ethernet/stmicro/stmmac/altr_tse_pcs.c
+++ b/drivers/net/ethernet/stmicro/stmmac/altr_tse_pcs.c
@@ -63,8 +63,8 @@
63#define TSE_PCS_SGMII_LINK_TIMER_0 0x0D40 63#define TSE_PCS_SGMII_LINK_TIMER_0 0x0D40
64#define TSE_PCS_SGMII_LINK_TIMER_1 0x0003 64#define TSE_PCS_SGMII_LINK_TIMER_1 0x0003
65#define TSE_PCS_SW_RESET_TIMEOUT 100 65#define TSE_PCS_SW_RESET_TIMEOUT 100
66#define TSE_PCS_USE_SGMII_AN_MASK BIT(2) 66#define TSE_PCS_USE_SGMII_AN_MASK BIT(1)
67#define TSE_PCS_USE_SGMII_ENA BIT(1) 67#define TSE_PCS_USE_SGMII_ENA BIT(0)
68 68
69#define SGMII_ADAPTER_CTRL_REG 0x00 69#define SGMII_ADAPTER_CTRL_REG 0x00
70#define SGMII_ADAPTER_DISABLE 0x0001 70#define SGMII_ADAPTER_DISABLE 0x0001
diff --git a/drivers/net/ethernet/stmicro/stmmac/common.h b/drivers/net/ethernet/stmicro/stmmac/common.h
index d3292c4a6eda..6d2de4e01f6d 100644
--- a/drivers/net/ethernet/stmicro/stmmac/common.h
+++ b/drivers/net/ethernet/stmicro/stmmac/common.h
@@ -120,14 +120,17 @@ struct stmmac_extra_stats {
120 unsigned long ip_csum_bypassed; 120 unsigned long ip_csum_bypassed;
121 unsigned long ipv4_pkt_rcvd; 121 unsigned long ipv4_pkt_rcvd;
122 unsigned long ipv6_pkt_rcvd; 122 unsigned long ipv6_pkt_rcvd;
123 unsigned long rx_msg_type_ext_no_ptp; 123 unsigned long no_ptp_rx_msg_type_ext;
124 unsigned long rx_msg_type_sync; 124 unsigned long ptp_rx_msg_type_sync;
125 unsigned long rx_msg_type_follow_up; 125 unsigned long ptp_rx_msg_type_follow_up;
126 unsigned long rx_msg_type_delay_req; 126 unsigned long ptp_rx_msg_type_delay_req;
127 unsigned long rx_msg_type_delay_resp; 127 unsigned long ptp_rx_msg_type_delay_resp;
128 unsigned long rx_msg_type_pdelay_req; 128 unsigned long ptp_rx_msg_type_pdelay_req;
129 unsigned long rx_msg_type_pdelay_resp; 129 unsigned long ptp_rx_msg_type_pdelay_resp;
130 unsigned long rx_msg_type_pdelay_follow_up; 130 unsigned long ptp_rx_msg_type_pdelay_follow_up;
131 unsigned long ptp_rx_msg_type_announce;
132 unsigned long ptp_rx_msg_type_management;
133 unsigned long ptp_rx_msg_pkt_reserved_type;
131 unsigned long ptp_frame_type; 134 unsigned long ptp_frame_type;
132 unsigned long ptp_ver; 135 unsigned long ptp_ver;
133 unsigned long timestamp_dropped; 136 unsigned long timestamp_dropped;
@@ -482,11 +485,12 @@ struct stmmac_ops {
482/* PTP and HW Timer helpers */ 485/* PTP and HW Timer helpers */
483struct stmmac_hwtimestamp { 486struct stmmac_hwtimestamp {
484 void (*config_hw_tstamping) (void __iomem *ioaddr, u32 data); 487 void (*config_hw_tstamping) (void __iomem *ioaddr, u32 data);
485 u32 (*config_sub_second_increment) (void __iomem *ioaddr, u32 clk_rate); 488 u32 (*config_sub_second_increment)(void __iomem *ioaddr, u32 ptp_clock,
489 int gmac4);
486 int (*init_systime) (void __iomem *ioaddr, u32 sec, u32 nsec); 490 int (*init_systime) (void __iomem *ioaddr, u32 sec, u32 nsec);
487 int (*config_addend) (void __iomem *ioaddr, u32 addend); 491 int (*config_addend) (void __iomem *ioaddr, u32 addend);
488 int (*adjust_systime) (void __iomem *ioaddr, u32 sec, u32 nsec, 492 int (*adjust_systime) (void __iomem *ioaddr, u32 sec, u32 nsec,
489 int add_sub); 493 int add_sub, int gmac4);
490 u64(*get_systime) (void __iomem *ioaddr); 494 u64(*get_systime) (void __iomem *ioaddr);
491}; 495};
492 496
diff --git a/drivers/net/ethernet/stmicro/stmmac/descs.h b/drivers/net/ethernet/stmicro/stmmac/descs.h
index 2e4c171a2b41..e3c86d422109 100644
--- a/drivers/net/ethernet/stmicro/stmmac/descs.h
+++ b/drivers/net/ethernet/stmicro/stmmac/descs.h
@@ -155,14 +155,18 @@
155#define ERDES4_L3_L4_FILT_NO_MATCH_MASK GENMASK(27, 26) 155#define ERDES4_L3_L4_FILT_NO_MATCH_MASK GENMASK(27, 26)
156 156
157/* Extended RDES4 message type definitions */ 157/* Extended RDES4 message type definitions */
158#define RDES_EXT_NO_PTP 0 158#define RDES_EXT_NO_PTP 0x0
159#define RDES_EXT_SYNC 1 159#define RDES_EXT_SYNC 0x1
160#define RDES_EXT_FOLLOW_UP 2 160#define RDES_EXT_FOLLOW_UP 0x2
161#define RDES_EXT_DELAY_REQ 3 161#define RDES_EXT_DELAY_REQ 0x3
162#define RDES_EXT_DELAY_RESP 4 162#define RDES_EXT_DELAY_RESP 0x4
163#define RDES_EXT_PDELAY_REQ 5 163#define RDES_EXT_PDELAY_REQ 0x5
164#define RDES_EXT_PDELAY_RESP 6 164#define RDES_EXT_PDELAY_RESP 0x6
165#define RDES_EXT_PDELAY_FOLLOW_UP 7 165#define RDES_EXT_PDELAY_FOLLOW_UP 0x7
166#define RDES_PTP_ANNOUNCE 0x8
167#define RDES_PTP_MANAGEMENT 0x9
168#define RDES_PTP_SIGNALING 0xa
169#define RDES_PTP_PKT_RESERVED_TYPE 0xf
166 170
167/* Basic descriptor structure for normal and alternate descriptors */ 171/* Basic descriptor structure for normal and alternate descriptors */
168struct dma_desc { 172struct dma_desc {
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-generic.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-generic.c
index b1e5f24708c9..e6e6c2fcc4b7 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-generic.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-generic.c
@@ -50,10 +50,23 @@ static int dwmac_generic_probe(struct platform_device *pdev)
50 if (plat_dat->init) { 50 if (plat_dat->init) {
51 ret = plat_dat->init(pdev, plat_dat->bsp_priv); 51 ret = plat_dat->init(pdev, plat_dat->bsp_priv);
52 if (ret) 52 if (ret)
53 return ret; 53 goto err_remove_config_dt;
54 } 54 }
55 55
56 return stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res); 56 ret = stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res);
57 if (ret)
58 goto err_exit;
59
60 return 0;
61
62err_exit:
63 if (plat_dat->exit)
64 plat_dat->exit(pdev, plat_dat->bsp_priv);
65err_remove_config_dt:
66 if (pdev->dev.of_node)
67 stmmac_remove_config_dt(pdev, plat_dat);
68
69 return ret;
57} 70}
58 71
59static const struct of_device_id dwmac_generic_match[] = { 72static const struct of_device_id dwmac_generic_match[] = {
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-ipq806x.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-ipq806x.c
index 36d3355f2fb0..866444b6c82f 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-ipq806x.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-ipq806x.c
@@ -271,15 +271,17 @@ static int ipq806x_gmac_probe(struct platform_device *pdev)
271 return PTR_ERR(plat_dat); 271 return PTR_ERR(plat_dat);
272 272
273 gmac = devm_kzalloc(dev, sizeof(*gmac), GFP_KERNEL); 273 gmac = devm_kzalloc(dev, sizeof(*gmac), GFP_KERNEL);
274 if (!gmac) 274 if (!gmac) {
275 return -ENOMEM; 275 err = -ENOMEM;
276 goto err_remove_config_dt;
277 }
276 278
277 gmac->pdev = pdev; 279 gmac->pdev = pdev;
278 280
279 err = ipq806x_gmac_of_parse(gmac); 281 err = ipq806x_gmac_of_parse(gmac);
280 if (err) { 282 if (err) {
281 dev_err(dev, "device tree parsing error\n"); 283 dev_err(dev, "device tree parsing error\n");
282 return err; 284 goto err_remove_config_dt;
283 } 285 }
284 286
285 regmap_write(gmac->qsgmii_csr, QSGMII_PCS_CAL_LCKDT_CTL, 287 regmap_write(gmac->qsgmii_csr, QSGMII_PCS_CAL_LCKDT_CTL,
@@ -300,7 +302,8 @@ static int ipq806x_gmac_probe(struct platform_device *pdev)
300 default: 302 default:
301 dev_err(&pdev->dev, "Unsupported PHY mode: \"%s\"\n", 303 dev_err(&pdev->dev, "Unsupported PHY mode: \"%s\"\n",
302 phy_modes(gmac->phy_mode)); 304 phy_modes(gmac->phy_mode));
303 return -EINVAL; 305 err = -EINVAL;
306 goto err_remove_config_dt;
304 } 307 }
305 regmap_write(gmac->nss_common, NSS_COMMON_GMAC_CTL(gmac->id), val); 308 regmap_write(gmac->nss_common, NSS_COMMON_GMAC_CTL(gmac->id), val);
306 309
@@ -319,7 +322,8 @@ static int ipq806x_gmac_probe(struct platform_device *pdev)
319 default: 322 default:
320 dev_err(&pdev->dev, "Unsupported PHY mode: \"%s\"\n", 323 dev_err(&pdev->dev, "Unsupported PHY mode: \"%s\"\n",
321 phy_modes(gmac->phy_mode)); 324 phy_modes(gmac->phy_mode));
322 return -EINVAL; 325 err = -EINVAL;
326 goto err_remove_config_dt;
323 } 327 }
324 regmap_write(gmac->nss_common, NSS_COMMON_CLK_SRC_CTRL, val); 328 regmap_write(gmac->nss_common, NSS_COMMON_CLK_SRC_CTRL, val);
325 329
@@ -346,7 +350,16 @@ static int ipq806x_gmac_probe(struct platform_device *pdev)
346 plat_dat->bsp_priv = gmac; 350 plat_dat->bsp_priv = gmac;
347 plat_dat->fix_mac_speed = ipq806x_gmac_fix_mac_speed; 351 plat_dat->fix_mac_speed = ipq806x_gmac_fix_mac_speed;
348 352
349 return stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res); 353 err = stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res);
354 if (err)
355 goto err_remove_config_dt;
356
357 return 0;
358
359err_remove_config_dt:
360 stmmac_remove_config_dt(pdev, plat_dat);
361
362 return err;
350} 363}
351 364
352static const struct of_device_id ipq806x_gmac_dwmac_match[] = { 365static const struct of_device_id ipq806x_gmac_dwmac_match[] = {
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-lpc18xx.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-lpc18xx.c
index 78e9d1861896..3d3f43d91b98 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-lpc18xx.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-lpc18xx.c
@@ -46,7 +46,8 @@ static int lpc18xx_dwmac_probe(struct platform_device *pdev)
46 reg = syscon_regmap_lookup_by_compatible("nxp,lpc1850-creg"); 46 reg = syscon_regmap_lookup_by_compatible("nxp,lpc1850-creg");
47 if (IS_ERR(reg)) { 47 if (IS_ERR(reg)) {
48 dev_err(&pdev->dev, "syscon lookup failed\n"); 48 dev_err(&pdev->dev, "syscon lookup failed\n");
49 return PTR_ERR(reg); 49 ret = PTR_ERR(reg);
50 goto err_remove_config_dt;
50 } 51 }
51 52
52 if (plat_dat->interface == PHY_INTERFACE_MODE_MII) { 53 if (plat_dat->interface == PHY_INTERFACE_MODE_MII) {
@@ -55,13 +56,23 @@ static int lpc18xx_dwmac_probe(struct platform_device *pdev)
55 ethmode = LPC18XX_CREG_CREG6_ETHMODE_RMII; 56 ethmode = LPC18XX_CREG_CREG6_ETHMODE_RMII;
56 } else { 57 } else {
57 dev_err(&pdev->dev, "Only MII and RMII mode supported\n"); 58 dev_err(&pdev->dev, "Only MII and RMII mode supported\n");
58 return -EINVAL; 59 ret = -EINVAL;
60 goto err_remove_config_dt;
59 } 61 }
60 62
61 regmap_update_bits(reg, LPC18XX_CREG_CREG6, 63 regmap_update_bits(reg, LPC18XX_CREG_CREG6,
62 LPC18XX_CREG_CREG6_ETHMODE_MASK, ethmode); 64 LPC18XX_CREG_CREG6_ETHMODE_MASK, ethmode);
63 65
64 return stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res); 66 ret = stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res);
67 if (ret)
68 goto err_remove_config_dt;
69
70 return 0;
71
72err_remove_config_dt:
73 stmmac_remove_config_dt(pdev, plat_dat);
74
75 return ret;
65} 76}
66 77
67static const struct of_device_id lpc18xx_dwmac_match[] = { 78static const struct of_device_id lpc18xx_dwmac_match[] = {
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-meson.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-meson.c
index 309d99536a2c..7fdd1760a74c 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-meson.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-meson.c
@@ -64,18 +64,31 @@ static int meson6_dwmac_probe(struct platform_device *pdev)
64 return PTR_ERR(plat_dat); 64 return PTR_ERR(plat_dat);
65 65
66 dwmac = devm_kzalloc(&pdev->dev, sizeof(*dwmac), GFP_KERNEL); 66 dwmac = devm_kzalloc(&pdev->dev, sizeof(*dwmac), GFP_KERNEL);
67 if (!dwmac) 67 if (!dwmac) {
68 return -ENOMEM; 68 ret = -ENOMEM;
69 goto err_remove_config_dt;
70 }
69 71
70 res = platform_get_resource(pdev, IORESOURCE_MEM, 1); 72 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
71 dwmac->reg = devm_ioremap_resource(&pdev->dev, res); 73 dwmac->reg = devm_ioremap_resource(&pdev->dev, res);
72 if (IS_ERR(dwmac->reg)) 74 if (IS_ERR(dwmac->reg)) {
73 return PTR_ERR(dwmac->reg); 75 ret = PTR_ERR(dwmac->reg);
76 goto err_remove_config_dt;
77 }
74 78
75 plat_dat->bsp_priv = dwmac; 79 plat_dat->bsp_priv = dwmac;
76 plat_dat->fix_mac_speed = meson6_dwmac_fix_mac_speed; 80 plat_dat->fix_mac_speed = meson6_dwmac_fix_mac_speed;
77 81
78 return stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res); 82 ret = stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res);
83 if (ret)
84 goto err_remove_config_dt;
85
86 return 0;
87
88err_remove_config_dt:
89 stmmac_remove_config_dt(pdev, plat_dat);
90
91 return ret;
79} 92}
80 93
81static const struct of_device_id meson6_dwmac_match[] = { 94static const struct of_device_id meson6_dwmac_match[] = {
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-meson8b.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-meson8b.c
index 250e4ceafc8d..ffaed1f35efe 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-meson8b.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-meson8b.c
@@ -264,32 +264,48 @@ static int meson8b_dwmac_probe(struct platform_device *pdev)
264 return PTR_ERR(plat_dat); 264 return PTR_ERR(plat_dat);
265 265
266 dwmac = devm_kzalloc(&pdev->dev, sizeof(*dwmac), GFP_KERNEL); 266 dwmac = devm_kzalloc(&pdev->dev, sizeof(*dwmac), GFP_KERNEL);
267 if (!dwmac) 267 if (!dwmac) {
268 return -ENOMEM; 268 ret = -ENOMEM;
269 goto err_remove_config_dt;
270 }
269 271
270 res = platform_get_resource(pdev, IORESOURCE_MEM, 1); 272 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
271 dwmac->regs = devm_ioremap_resource(&pdev->dev, res); 273 dwmac->regs = devm_ioremap_resource(&pdev->dev, res);
272 if (IS_ERR(dwmac->regs)) 274 if (IS_ERR(dwmac->regs)) {
273 return PTR_ERR(dwmac->regs); 275 ret = PTR_ERR(dwmac->regs);
276 goto err_remove_config_dt;
277 }
274 278
275 dwmac->pdev = pdev; 279 dwmac->pdev = pdev;
276 dwmac->phy_mode = of_get_phy_mode(pdev->dev.of_node); 280 dwmac->phy_mode = of_get_phy_mode(pdev->dev.of_node);
277 if (dwmac->phy_mode < 0) { 281 if (dwmac->phy_mode < 0) {
278 dev_err(&pdev->dev, "missing phy-mode property\n"); 282 dev_err(&pdev->dev, "missing phy-mode property\n");
279 return -EINVAL; 283 ret = -EINVAL;
284 goto err_remove_config_dt;
280 } 285 }
281 286
282 ret = meson8b_init_clk(dwmac); 287 ret = meson8b_init_clk(dwmac);
283 if (ret) 288 if (ret)
284 return ret; 289 goto err_remove_config_dt;
285 290
286 ret = meson8b_init_prg_eth(dwmac); 291 ret = meson8b_init_prg_eth(dwmac);
287 if (ret) 292 if (ret)
288 return ret; 293 goto err_remove_config_dt;
289 294
290 plat_dat->bsp_priv = dwmac; 295 plat_dat->bsp_priv = dwmac;
291 296
292 return stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res); 297 ret = stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res);
298 if (ret)
299 goto err_clk_disable;
300
301 return 0;
302
303err_clk_disable:
304 clk_disable_unprepare(dwmac->m25_div_clk);
305err_remove_config_dt:
306 stmmac_remove_config_dt(pdev, plat_dat);
307
308 return ret;
293} 309}
294 310
295static int meson8b_dwmac_remove(struct platform_device *pdev) 311static int meson8b_dwmac_remove(struct platform_device *pdev)
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
index 3740a4417fa0..d80c88bd2bba 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
@@ -981,14 +981,27 @@ static int rk_gmac_probe(struct platform_device *pdev)
981 plat_dat->resume = rk_gmac_resume; 981 plat_dat->resume = rk_gmac_resume;
982 982
983 plat_dat->bsp_priv = rk_gmac_setup(pdev, data); 983 plat_dat->bsp_priv = rk_gmac_setup(pdev, data);
984 if (IS_ERR(plat_dat->bsp_priv)) 984 if (IS_ERR(plat_dat->bsp_priv)) {
985 return PTR_ERR(plat_dat->bsp_priv); 985 ret = PTR_ERR(plat_dat->bsp_priv);
986 goto err_remove_config_dt;
987 }
986 988
987 ret = rk_gmac_init(pdev, plat_dat->bsp_priv); 989 ret = rk_gmac_init(pdev, plat_dat->bsp_priv);
988 if (ret) 990 if (ret)
989 return ret; 991 goto err_remove_config_dt;
992
993 ret = stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res);
994 if (ret)
995 goto err_gmac_exit;
996
997 return 0;
998
999err_gmac_exit:
1000 rk_gmac_exit(pdev, plat_dat->bsp_priv);
1001err_remove_config_dt:
1002 stmmac_remove_config_dt(pdev, plat_dat);
990 1003
991 return stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res); 1004 return ret;
992} 1005}
993 1006
994static const struct of_device_id rk_gmac_dwmac_match[] = { 1007static const struct of_device_id rk_gmac_dwmac_match[] = {
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c
index bec6963ac71e..0c420e97de1e 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c
@@ -304,6 +304,8 @@ static int socfpga_dwmac_probe(struct platform_device *pdev)
304 struct device *dev = &pdev->dev; 304 struct device *dev = &pdev->dev;
305 int ret; 305 int ret;
306 struct socfpga_dwmac *dwmac; 306 struct socfpga_dwmac *dwmac;
307 struct net_device *ndev;
308 struct stmmac_priv *stpriv;
307 309
308 ret = stmmac_get_platform_resources(pdev, &stmmac_res); 310 ret = stmmac_get_platform_resources(pdev, &stmmac_res);
309 if (ret) 311 if (ret)
@@ -314,32 +316,43 @@ static int socfpga_dwmac_probe(struct platform_device *pdev)
314 return PTR_ERR(plat_dat); 316 return PTR_ERR(plat_dat);
315 317
316 dwmac = devm_kzalloc(dev, sizeof(*dwmac), GFP_KERNEL); 318 dwmac = devm_kzalloc(dev, sizeof(*dwmac), GFP_KERNEL);
317 if (!dwmac) 319 if (!dwmac) {
318 return -ENOMEM; 320 ret = -ENOMEM;
321 goto err_remove_config_dt;
322 }
319 323
320 ret = socfpga_dwmac_parse_data(dwmac, dev); 324 ret = socfpga_dwmac_parse_data(dwmac, dev);
321 if (ret) { 325 if (ret) {
322 dev_err(dev, "Unable to parse OF data\n"); 326 dev_err(dev, "Unable to parse OF data\n");
323 return ret; 327 goto err_remove_config_dt;
324 } 328 }
325 329
326 plat_dat->bsp_priv = dwmac; 330 plat_dat->bsp_priv = dwmac;
327 plat_dat->fix_mac_speed = socfpga_dwmac_fix_mac_speed; 331 plat_dat->fix_mac_speed = socfpga_dwmac_fix_mac_speed;
328 332
329 ret = stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res); 333 ret = stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res);
334 if (ret)
335 goto err_remove_config_dt;
330 336
331 if (!ret) { 337 ndev = platform_get_drvdata(pdev);
332 struct net_device *ndev = platform_get_drvdata(pdev); 338 stpriv = netdev_priv(ndev);
333 struct stmmac_priv *stpriv = netdev_priv(ndev);
334 339
335 /* The socfpga driver needs to control the stmmac reset to 340 /* The socfpga driver needs to control the stmmac reset to set the phy
336 * set the phy mode. Create a copy of the core reset handel 341 * mode. Create a copy of the core reset handle so it can be used by
337 * so it can be used by the driver later. 342 * the driver later.
338 */ 343 */
339 dwmac->stmmac_rst = stpriv->stmmac_rst; 344 dwmac->stmmac_rst = stpriv->stmmac_rst;
340 345
341 ret = socfpga_dwmac_set_phy_mode(dwmac); 346 ret = socfpga_dwmac_set_phy_mode(dwmac);
342 } 347 if (ret)
348 goto err_dvr_remove;
349
350 return 0;
351
352err_dvr_remove:
353 stmmac_dvr_remove(&pdev->dev);
354err_remove_config_dt:
355 stmmac_remove_config_dt(pdev, plat_dat);
343 356
344 return ret; 357 return ret;
345} 358}
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c
index 58c05acc2aab..060b98c37a85 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sti.c
@@ -345,13 +345,15 @@ static int sti_dwmac_probe(struct platform_device *pdev)
345 return PTR_ERR(plat_dat); 345 return PTR_ERR(plat_dat);
346 346
347 dwmac = devm_kzalloc(&pdev->dev, sizeof(*dwmac), GFP_KERNEL); 347 dwmac = devm_kzalloc(&pdev->dev, sizeof(*dwmac), GFP_KERNEL);
348 if (!dwmac) 348 if (!dwmac) {
349 return -ENOMEM; 349 ret = -ENOMEM;
350 goto err_remove_config_dt;
351 }
350 352
351 ret = sti_dwmac_parse_data(dwmac, pdev); 353 ret = sti_dwmac_parse_data(dwmac, pdev);
352 if (ret) { 354 if (ret) {
353 dev_err(&pdev->dev, "Unable to parse OF data\n"); 355 dev_err(&pdev->dev, "Unable to parse OF data\n");
354 return ret; 356 goto err_remove_config_dt;
355 } 357 }
356 358
357 dwmac->fix_retime_src = data->fix_retime_src; 359 dwmac->fix_retime_src = data->fix_retime_src;
@@ -363,9 +365,20 @@ static int sti_dwmac_probe(struct platform_device *pdev)
363 365
364 ret = sti_dwmac_init(pdev, plat_dat->bsp_priv); 366 ret = sti_dwmac_init(pdev, plat_dat->bsp_priv);
365 if (ret) 367 if (ret)
366 return ret; 368 goto err_remove_config_dt;
369
370 ret = stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res);
371 if (ret)
372 goto err_dwmac_exit;
373
374 return 0;
375
376err_dwmac_exit:
377 sti_dwmac_exit(pdev, plat_dat->bsp_priv);
378err_remove_config_dt:
379 stmmac_remove_config_dt(pdev, plat_dat);
367 380
368 return stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res); 381 return ret;
369} 382}
370 383
371static const struct sti_dwmac_of_data stih4xx_dwmac_data = { 384static const struct sti_dwmac_of_data stih4xx_dwmac_data = {
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c
index e5a926b8bee7..61cb24810d10 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c
@@ -107,24 +107,33 @@ static int stm32_dwmac_probe(struct platform_device *pdev)
107 return PTR_ERR(plat_dat); 107 return PTR_ERR(plat_dat);
108 108
109 dwmac = devm_kzalloc(&pdev->dev, sizeof(*dwmac), GFP_KERNEL); 109 dwmac = devm_kzalloc(&pdev->dev, sizeof(*dwmac), GFP_KERNEL);
110 if (!dwmac) 110 if (!dwmac) {
111 return -ENOMEM; 111 ret = -ENOMEM;
112 goto err_remove_config_dt;
113 }
112 114
113 ret = stm32_dwmac_parse_data(dwmac, &pdev->dev); 115 ret = stm32_dwmac_parse_data(dwmac, &pdev->dev);
114 if (ret) { 116 if (ret) {
115 dev_err(&pdev->dev, "Unable to parse OF data\n"); 117 dev_err(&pdev->dev, "Unable to parse OF data\n");
116 return ret; 118 goto err_remove_config_dt;
117 } 119 }
118 120
119 plat_dat->bsp_priv = dwmac; 121 plat_dat->bsp_priv = dwmac;
120 122
121 ret = stm32_dwmac_init(plat_dat); 123 ret = stm32_dwmac_init(plat_dat);
122 if (ret) 124 if (ret)
123 return ret; 125 goto err_remove_config_dt;
124 126
125 ret = stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res); 127 ret = stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res);
126 if (ret) 128 if (ret)
127 stm32_dwmac_clk_disable(dwmac); 129 goto err_clk_disable;
130
131 return 0;
132
133err_clk_disable:
134 stm32_dwmac_clk_disable(dwmac);
135err_remove_config_dt:
136 stmmac_remove_config_dt(pdev, plat_dat);
128 137
129 return ret; 138 return ret;
130} 139}
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sunxi.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-sunxi.c
index adff46375a32..d07520fb969e 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sunxi.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sunxi.c
@@ -120,22 +120,27 @@ static int sun7i_gmac_probe(struct platform_device *pdev)
120 return PTR_ERR(plat_dat); 120 return PTR_ERR(plat_dat);
121 121
122 gmac = devm_kzalloc(dev, sizeof(*gmac), GFP_KERNEL); 122 gmac = devm_kzalloc(dev, sizeof(*gmac), GFP_KERNEL);
123 if (!gmac) 123 if (!gmac) {
124 return -ENOMEM; 124 ret = -ENOMEM;
125 goto err_remove_config_dt;
126 }
125 127
126 gmac->interface = of_get_phy_mode(dev->of_node); 128 gmac->interface = of_get_phy_mode(dev->of_node);
127 129
128 gmac->tx_clk = devm_clk_get(dev, "allwinner_gmac_tx"); 130 gmac->tx_clk = devm_clk_get(dev, "allwinner_gmac_tx");
129 if (IS_ERR(gmac->tx_clk)) { 131 if (IS_ERR(gmac->tx_clk)) {
130 dev_err(dev, "could not get tx clock\n"); 132 dev_err(dev, "could not get tx clock\n");
131 return PTR_ERR(gmac->tx_clk); 133 ret = PTR_ERR(gmac->tx_clk);
134 goto err_remove_config_dt;
132 } 135 }
133 136
134 /* Optional regulator for PHY */ 137 /* Optional regulator for PHY */
135 gmac->regulator = devm_regulator_get_optional(dev, "phy"); 138 gmac->regulator = devm_regulator_get_optional(dev, "phy");
136 if (IS_ERR(gmac->regulator)) { 139 if (IS_ERR(gmac->regulator)) {
137 if (PTR_ERR(gmac->regulator) == -EPROBE_DEFER) 140 if (PTR_ERR(gmac->regulator) == -EPROBE_DEFER) {
138 return -EPROBE_DEFER; 141 ret = -EPROBE_DEFER;
142 goto err_remove_config_dt;
143 }
139 dev_info(dev, "no regulator found\n"); 144 dev_info(dev, "no regulator found\n");
140 gmac->regulator = NULL; 145 gmac->regulator = NULL;
141 } 146 }
@@ -151,11 +156,18 @@ static int sun7i_gmac_probe(struct platform_device *pdev)
151 156
152 ret = sun7i_gmac_init(pdev, plat_dat->bsp_priv); 157 ret = sun7i_gmac_init(pdev, plat_dat->bsp_priv);
153 if (ret) 158 if (ret)
154 return ret; 159 goto err_remove_config_dt;
155 160
156 ret = stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res); 161 ret = stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res);
157 if (ret) 162 if (ret)
158 sun7i_gmac_exit(pdev, plat_dat->bsp_priv); 163 goto err_gmac_exit;
164
165 return 0;
166
167err_gmac_exit:
168 sun7i_gmac_exit(pdev, plat_dat->bsp_priv);
169err_remove_config_dt:
170 stmmac_remove_config_dt(pdev, plat_dat);
159 171
160 return ret; 172 return ret;
161} 173}
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c b/drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c
index 990746955216..f35385266fbf 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c
@@ -43,9 +43,11 @@ static void dwmac1000_dma_axi(void __iomem *ioaddr, struct stmmac_axi *axi)
43 if (axi->axi_xit_frm) 43 if (axi->axi_xit_frm)
44 value |= DMA_AXI_LPI_XIT_FRM; 44 value |= DMA_AXI_LPI_XIT_FRM;
45 45
46 value &= ~DMA_AXI_WR_OSR_LMT;
46 value |= (axi->axi_wr_osr_lmt & DMA_AXI_WR_OSR_LMT_MASK) << 47 value |= (axi->axi_wr_osr_lmt & DMA_AXI_WR_OSR_LMT_MASK) <<
47 DMA_AXI_WR_OSR_LMT_SHIFT; 48 DMA_AXI_WR_OSR_LMT_SHIFT;
48 49
50 value &= ~DMA_AXI_RD_OSR_LMT;
49 value |= (axi->axi_rd_osr_lmt & DMA_AXI_RD_OSR_LMT_MASK) << 51 value |= (axi->axi_rd_osr_lmt & DMA_AXI_RD_OSR_LMT_MASK) <<
50 DMA_AXI_RD_OSR_LMT_SHIFT; 52 DMA_AXI_RD_OSR_LMT_SHIFT;
51 53
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c b/drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c
index 4ec7397e7fb3..a601f8d43b75 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c
@@ -123,22 +123,29 @@ static int dwmac4_wrback_get_rx_status(void *data, struct stmmac_extra_stats *x,
123 x->ipv4_pkt_rcvd++; 123 x->ipv4_pkt_rcvd++;
124 if (rdes1 & RDES1_IPV6_HEADER) 124 if (rdes1 & RDES1_IPV6_HEADER)
125 x->ipv6_pkt_rcvd++; 125 x->ipv6_pkt_rcvd++;
126 if (message_type == RDES_EXT_SYNC) 126
127 x->rx_msg_type_sync++; 127 if (message_type == RDES_EXT_NO_PTP)
128 x->no_ptp_rx_msg_type_ext++;
129 else if (message_type == RDES_EXT_SYNC)
130 x->ptp_rx_msg_type_sync++;
128 else if (message_type == RDES_EXT_FOLLOW_UP) 131 else if (message_type == RDES_EXT_FOLLOW_UP)
129 x->rx_msg_type_follow_up++; 132 x->ptp_rx_msg_type_follow_up++;
130 else if (message_type == RDES_EXT_DELAY_REQ) 133 else if (message_type == RDES_EXT_DELAY_REQ)
131 x->rx_msg_type_delay_req++; 134 x->ptp_rx_msg_type_delay_req++;
132 else if (message_type == RDES_EXT_DELAY_RESP) 135 else if (message_type == RDES_EXT_DELAY_RESP)
133 x->rx_msg_type_delay_resp++; 136 x->ptp_rx_msg_type_delay_resp++;
134 else if (message_type == RDES_EXT_PDELAY_REQ) 137 else if (message_type == RDES_EXT_PDELAY_REQ)
135 x->rx_msg_type_pdelay_req++; 138 x->ptp_rx_msg_type_pdelay_req++;
136 else if (message_type == RDES_EXT_PDELAY_RESP) 139 else if (message_type == RDES_EXT_PDELAY_RESP)
137 x->rx_msg_type_pdelay_resp++; 140 x->ptp_rx_msg_type_pdelay_resp++;
138 else if (message_type == RDES_EXT_PDELAY_FOLLOW_UP) 141 else if (message_type == RDES_EXT_PDELAY_FOLLOW_UP)
139 x->rx_msg_type_pdelay_follow_up++; 142 x->ptp_rx_msg_type_pdelay_follow_up++;
140 else 143 else if (message_type == RDES_PTP_ANNOUNCE)
141 x->rx_msg_type_ext_no_ptp++; 144 x->ptp_rx_msg_type_announce++;
145 else if (message_type == RDES_PTP_MANAGEMENT)
146 x->ptp_rx_msg_type_management++;
147 else if (message_type == RDES_PTP_PKT_RESERVED_TYPE)
148 x->ptp_rx_msg_pkt_reserved_type++;
142 149
143 if (rdes1 & RDES1_PTP_PACKET_TYPE) 150 if (rdes1 & RDES1_PTP_PACKET_TYPE)
144 x->ptp_frame_type++; 151 x->ptp_frame_type++;
@@ -204,14 +211,18 @@ static void dwmac4_rd_enable_tx_timestamp(struct dma_desc *p)
204 211
205static int dwmac4_wrback_get_tx_timestamp_status(struct dma_desc *p) 212static int dwmac4_wrback_get_tx_timestamp_status(struct dma_desc *p)
206{ 213{
207 return (p->des3 & TDES3_TIMESTAMP_STATUS) 214 /* Context type from W/B descriptor must be zero */
208 >> TDES3_TIMESTAMP_STATUS_SHIFT; 215 if (p->des3 & TDES3_CONTEXT_TYPE)
216 return -EINVAL;
217
218 /* Tx Timestamp Status is 1 so des0 and des1'll have valid values */
219 if (p->des3 & TDES3_TIMESTAMP_STATUS)
220 return 0;
221
222 return 1;
209} 223}
210 224
211/* NOTE: For RX CTX bit has to be checked before 225static inline u64 dwmac4_get_timestamp(void *desc, u32 ats)
212 * HAVE a specific function for TX and another one for RX
213 */
214static u64 dwmac4_wrback_get_timestamp(void *desc, u32 ats)
215{ 226{
216 struct dma_desc *p = (struct dma_desc *)desc; 227 struct dma_desc *p = (struct dma_desc *)desc;
217 u64 ns; 228 u64 ns;
@@ -223,12 +234,54 @@ static u64 dwmac4_wrback_get_timestamp(void *desc, u32 ats)
223 return ns; 234 return ns;
224} 235}
225 236
226static int dwmac4_context_get_rx_timestamp_status(void *desc, u32 ats) 237static int dwmac4_rx_check_timestamp(void *desc)
238{
239 struct dma_desc *p = (struct dma_desc *)desc;
240 u32 own, ctxt;
241 int ret = 1;
242
243 own = p->des3 & RDES3_OWN;
244 ctxt = ((p->des3 & RDES3_CONTEXT_DESCRIPTOR)
245 >> RDES3_CONTEXT_DESCRIPTOR_SHIFT);
246
247 if (likely(!own && ctxt)) {
248 if ((p->des0 == 0xffffffff) && (p->des1 == 0xffffffff))
249 /* Corrupted value */
250 ret = -EINVAL;
251 else
252 /* A valid Timestamp is ready to be read */
253 ret = 0;
254 }
255
256 /* Timestamp not ready */
257 return ret;
258}
259
260static int dwmac4_wrback_get_rx_timestamp_status(void *desc, u32 ats)
227{ 261{
228 struct dma_desc *p = (struct dma_desc *)desc; 262 struct dma_desc *p = (struct dma_desc *)desc;
263 int ret = -EINVAL;
264
265 /* Get the status from normal w/b descriptor */
266 if (likely(p->des3 & TDES3_RS1V)) {
267 if (likely(p->des1 & RDES1_TIMESTAMP_AVAILABLE)) {
268 int i = 0;
269
270 /* Check if timestamp is OK from context descriptor */
271 do {
272 ret = dwmac4_rx_check_timestamp(desc);
273 if (ret < 0)
274 goto exit;
275 i++;
229 276
230 return (p->des1 & RDES1_TIMESTAMP_AVAILABLE) 277 } while ((ret == 1) || (i < 10));
231 >> RDES1_TIMESTAMP_AVAILABLE_SHIFT; 278
279 if (i == 10)
280 ret = -EBUSY;
281 }
282 }
283exit:
284 return ret;
232} 285}
233 286
234static void dwmac4_rd_init_rx_desc(struct dma_desc *p, int disable_rx_ic, 287static void dwmac4_rd_init_rx_desc(struct dma_desc *p, int disable_rx_ic,
@@ -347,10 +400,9 @@ static void dwmac4_display_ring(void *head, unsigned int size, bool rx)
347 pr_info("%s descriptor ring:\n", rx ? "RX" : "TX"); 400 pr_info("%s descriptor ring:\n", rx ? "RX" : "TX");
348 401
349 for (i = 0; i < size; i++) { 402 for (i = 0; i < size; i++) {
350 if (p->des0) 403 pr_info("%d [0x%x]: 0x%x 0x%x 0x%x 0x%x\n",
351 pr_info("%d [0x%x]: 0x%x 0x%x 0x%x 0x%x\n", 404 i, (unsigned int)virt_to_phys(p),
352 i, (unsigned int)virt_to_phys(p), 405 p->des0, p->des1, p->des2, p->des3);
353 p->des0, p->des1, p->des2, p->des3);
354 p++; 406 p++;
355 } 407 }
356} 408}
@@ -374,8 +426,8 @@ const struct stmmac_desc_ops dwmac4_desc_ops = {
374 .get_rx_frame_len = dwmac4_wrback_get_rx_frame_len, 426 .get_rx_frame_len = dwmac4_wrback_get_rx_frame_len,
375 .enable_tx_timestamp = dwmac4_rd_enable_tx_timestamp, 427 .enable_tx_timestamp = dwmac4_rd_enable_tx_timestamp,
376 .get_tx_timestamp_status = dwmac4_wrback_get_tx_timestamp_status, 428 .get_tx_timestamp_status = dwmac4_wrback_get_tx_timestamp_status,
377 .get_timestamp = dwmac4_wrback_get_timestamp, 429 .get_rx_timestamp_status = dwmac4_wrback_get_rx_timestamp_status,
378 .get_rx_timestamp_status = dwmac4_context_get_rx_timestamp_status, 430 .get_timestamp = dwmac4_get_timestamp,
379 .set_tx_ic = dwmac4_rd_set_tx_ic, 431 .set_tx_ic = dwmac4_rd_set_tx_ic,
380 .prepare_tx_desc = dwmac4_rd_prepare_tx_desc, 432 .prepare_tx_desc = dwmac4_rd_prepare_tx_desc,
381 .prepare_tso_tx_desc = dwmac4_rd_prepare_tso_tx_desc, 433 .prepare_tso_tx_desc = dwmac4_rd_prepare_tso_tx_desc,
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.h b/drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.h
index 0902a2edeaa9..9736c505211a 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.h
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.h
@@ -59,10 +59,13 @@
59#define TDES3_CTXT_TCMSSV BIT(26) 59#define TDES3_CTXT_TCMSSV BIT(26)
60 60
61/* TDES3 Common */ 61/* TDES3 Common */
62#define TDES3_RS1V BIT(26)
63#define TDES3_RS1V_SHIFT 26
62#define TDES3_LAST_DESCRIPTOR BIT(28) 64#define TDES3_LAST_DESCRIPTOR BIT(28)
63#define TDES3_LAST_DESCRIPTOR_SHIFT 28 65#define TDES3_LAST_DESCRIPTOR_SHIFT 28
64#define TDES3_FIRST_DESCRIPTOR BIT(29) 66#define TDES3_FIRST_DESCRIPTOR BIT(29)
65#define TDES3_CONTEXT_TYPE BIT(30) 67#define TDES3_CONTEXT_TYPE BIT(30)
68#define TDES3_CONTEXT_TYPE_SHIFT 30
66 69
67/* TDS3 use for both format (read and write back) */ 70/* TDS3 use for both format (read and write back) */
68#define TDES3_OWN BIT(31) 71#define TDES3_OWN BIT(31)
@@ -117,6 +120,7 @@
117#define RDES3_LAST_DESCRIPTOR BIT(28) 120#define RDES3_LAST_DESCRIPTOR BIT(28)
118#define RDES3_FIRST_DESCRIPTOR BIT(29) 121#define RDES3_FIRST_DESCRIPTOR BIT(29)
119#define RDES3_CONTEXT_DESCRIPTOR BIT(30) 122#define RDES3_CONTEXT_DESCRIPTOR BIT(30)
123#define RDES3_CONTEXT_DESCRIPTOR_SHIFT 30
120 124
121/* RDES3 (read format) */ 125/* RDES3 (read format) */
122#define RDES3_BUFFER1_VALID_ADDR BIT(24) 126#define RDES3_BUFFER1_VALID_ADDR BIT(24)
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4_dma.c b/drivers/net/ethernet/stmicro/stmmac/dwmac4_dma.c
index 116151cd6a95..32bc2fc73cdc 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac4_dma.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4_dma.c
@@ -30,9 +30,11 @@ static void dwmac4_dma_axi(void __iomem *ioaddr, struct stmmac_axi *axi)
30 if (axi->axi_xit_frm) 30 if (axi->axi_xit_frm)
31 value |= DMA_AXI_LPI_XIT_FRM; 31 value |= DMA_AXI_LPI_XIT_FRM;
32 32
33 value &= ~DMA_AXI_WR_OSR_LMT;
33 value |= (axi->axi_wr_osr_lmt & DMA_AXI_OSR_MAX) << 34 value |= (axi->axi_wr_osr_lmt & DMA_AXI_OSR_MAX) <<
34 DMA_AXI_WR_OSR_LMT_SHIFT; 35 DMA_AXI_WR_OSR_LMT_SHIFT;
35 36
37 value &= ~DMA_AXI_RD_OSR_LMT;
36 value |= (axi->axi_rd_osr_lmt & DMA_AXI_OSR_MAX) << 38 value |= (axi->axi_rd_osr_lmt & DMA_AXI_OSR_MAX) <<
37 DMA_AXI_RD_OSR_LMT_SHIFT; 39 DMA_AXI_RD_OSR_LMT_SHIFT;
38 40
diff --git a/drivers/net/ethernet/stmicro/stmmac/enh_desc.c b/drivers/net/ethernet/stmicro/stmmac/enh_desc.c
index 38f19c99cf59..e75549327c34 100644
--- a/drivers/net/ethernet/stmicro/stmmac/enh_desc.c
+++ b/drivers/net/ethernet/stmicro/stmmac/enh_desc.c
@@ -150,22 +150,30 @@ static void enh_desc_get_ext_status(void *data, struct stmmac_extra_stats *x,
150 x->ipv4_pkt_rcvd++; 150 x->ipv4_pkt_rcvd++;
151 if (rdes4 & ERDES4_IPV6_PKT_RCVD) 151 if (rdes4 & ERDES4_IPV6_PKT_RCVD)
152 x->ipv6_pkt_rcvd++; 152 x->ipv6_pkt_rcvd++;
153 if (message_type == RDES_EXT_SYNC) 153
154 x->rx_msg_type_sync++; 154 if (message_type == RDES_EXT_NO_PTP)
155 x->no_ptp_rx_msg_type_ext++;
156 else if (message_type == RDES_EXT_SYNC)
157 x->ptp_rx_msg_type_sync++;
155 else if (message_type == RDES_EXT_FOLLOW_UP) 158 else if (message_type == RDES_EXT_FOLLOW_UP)
156 x->rx_msg_type_follow_up++; 159 x->ptp_rx_msg_type_follow_up++;
157 else if (message_type == RDES_EXT_DELAY_REQ) 160 else if (message_type == RDES_EXT_DELAY_REQ)
158 x->rx_msg_type_delay_req++; 161 x->ptp_rx_msg_type_delay_req++;
159 else if (message_type == RDES_EXT_DELAY_RESP) 162 else if (message_type == RDES_EXT_DELAY_RESP)
160 x->rx_msg_type_delay_resp++; 163 x->ptp_rx_msg_type_delay_resp++;
161 else if (message_type == RDES_EXT_PDELAY_REQ) 164 else if (message_type == RDES_EXT_PDELAY_REQ)
162 x->rx_msg_type_pdelay_req++; 165 x->ptp_rx_msg_type_pdelay_req++;
163 else if (message_type == RDES_EXT_PDELAY_RESP) 166 else if (message_type == RDES_EXT_PDELAY_RESP)
164 x->rx_msg_type_pdelay_resp++; 167 x->ptp_rx_msg_type_pdelay_resp++;
165 else if (message_type == RDES_EXT_PDELAY_FOLLOW_UP) 168 else if (message_type == RDES_EXT_PDELAY_FOLLOW_UP)
166 x->rx_msg_type_pdelay_follow_up++; 169 x->ptp_rx_msg_type_pdelay_follow_up++;
167 else 170 else if (message_type == RDES_PTP_ANNOUNCE)
168 x->rx_msg_type_ext_no_ptp++; 171 x->ptp_rx_msg_type_announce++;
172 else if (message_type == RDES_PTP_MANAGEMENT)
173 x->ptp_rx_msg_type_management++;
174 else if (message_type == RDES_PTP_PKT_RESERVED_TYPE)
175 x->ptp_rx_msg_pkt_reserved_type++;
176
169 if (rdes4 & ERDES4_PTP_FRAME_TYPE) 177 if (rdes4 & ERDES4_PTP_FRAME_TYPE)
170 x->ptp_frame_type++; 178 x->ptp_frame_type++;
171 if (rdes4 & ERDES4_PTP_VER) 179 if (rdes4 & ERDES4_PTP_VER)
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac.h b/drivers/net/ethernet/stmicro/stmmac/stmmac.h
index 8dc9056c1001..4d2a759b8465 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac.h
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac.h
@@ -129,6 +129,7 @@ struct stmmac_priv {
129 int irq_wake; 129 int irq_wake;
130 spinlock_t ptp_lock; 130 spinlock_t ptp_lock;
131 void __iomem *mmcaddr; 131 void __iomem *mmcaddr;
132 void __iomem *ptpaddr;
132 u32 rx_tail_addr; 133 u32 rx_tail_addr;
133 u32 tx_tail_addr; 134 u32 tx_tail_addr;
134 u32 mss; 135 u32 mss;
@@ -145,7 +146,7 @@ int stmmac_mdio_register(struct net_device *ndev);
145int stmmac_mdio_reset(struct mii_bus *mii); 146int stmmac_mdio_reset(struct mii_bus *mii);
146void stmmac_set_ethtool_ops(struct net_device *netdev); 147void stmmac_set_ethtool_ops(struct net_device *netdev);
147 148
148int stmmac_ptp_register(struct stmmac_priv *priv); 149void stmmac_ptp_register(struct stmmac_priv *priv);
149void stmmac_ptp_unregister(struct stmmac_priv *priv); 150void stmmac_ptp_unregister(struct stmmac_priv *priv);
150int stmmac_resume(struct device *dev); 151int stmmac_resume(struct device *dev);
151int stmmac_suspend(struct device *dev); 152int stmmac_suspend(struct device *dev);
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c
index 1e06173fc9d7..c5d0142adda2 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c
@@ -115,14 +115,17 @@ static const struct stmmac_stats stmmac_gstrings_stats[] = {
115 STMMAC_STAT(ip_csum_bypassed), 115 STMMAC_STAT(ip_csum_bypassed),
116 STMMAC_STAT(ipv4_pkt_rcvd), 116 STMMAC_STAT(ipv4_pkt_rcvd),
117 STMMAC_STAT(ipv6_pkt_rcvd), 117 STMMAC_STAT(ipv6_pkt_rcvd),
118 STMMAC_STAT(rx_msg_type_ext_no_ptp), 118 STMMAC_STAT(no_ptp_rx_msg_type_ext),
119 STMMAC_STAT(rx_msg_type_sync), 119 STMMAC_STAT(ptp_rx_msg_type_sync),
120 STMMAC_STAT(rx_msg_type_follow_up), 120 STMMAC_STAT(ptp_rx_msg_type_follow_up),
121 STMMAC_STAT(rx_msg_type_delay_req), 121 STMMAC_STAT(ptp_rx_msg_type_delay_req),
122 STMMAC_STAT(rx_msg_type_delay_resp), 122 STMMAC_STAT(ptp_rx_msg_type_delay_resp),
123 STMMAC_STAT(rx_msg_type_pdelay_req), 123 STMMAC_STAT(ptp_rx_msg_type_pdelay_req),
124 STMMAC_STAT(rx_msg_type_pdelay_resp), 124 STMMAC_STAT(ptp_rx_msg_type_pdelay_resp),
125 STMMAC_STAT(rx_msg_type_pdelay_follow_up), 125 STMMAC_STAT(ptp_rx_msg_type_pdelay_follow_up),
126 STMMAC_STAT(ptp_rx_msg_type_announce),
127 STMMAC_STAT(ptp_rx_msg_type_management),
128 STMMAC_STAT(ptp_rx_msg_pkt_reserved_type),
126 STMMAC_STAT(ptp_frame_type), 129 STMMAC_STAT(ptp_frame_type),
127 STMMAC_STAT(ptp_ver), 130 STMMAC_STAT(ptp_ver),
128 STMMAC_STAT(timestamp_dropped), 131 STMMAC_STAT(timestamp_dropped),
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c
index a77f68918010..10d6059b2f26 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c
@@ -34,21 +34,29 @@ static void stmmac_config_hw_tstamping(void __iomem *ioaddr, u32 data)
34} 34}
35 35
36static u32 stmmac_config_sub_second_increment(void __iomem *ioaddr, 36static u32 stmmac_config_sub_second_increment(void __iomem *ioaddr,
37 u32 ptp_clock) 37 u32 ptp_clock, int gmac4)
38{ 38{
39 u32 value = readl(ioaddr + PTP_TCR); 39 u32 value = readl(ioaddr + PTP_TCR);
40 unsigned long data; 40 unsigned long data;
41 41
42 /* Convert the ptp_clock to nano second 42 /* For GMAC3.x, 4.x versions, convert the ptp_clock to nano second
43 * formula = (2/ptp_clock) * 1000000000 43 * formula = (1/ptp_clock) * 1000000000
44 * where, ptp_clock = 50MHz. 44 * where ptp_clock is 50MHz if fine method is used to update system
45 */ 45 */
46 data = (2000000000ULL / ptp_clock); 46 if (value & PTP_TCR_TSCFUPDT)
47 data = (1000000000ULL / 50000000);
48 else
49 data = (1000000000ULL / ptp_clock);
47 50
48 /* 0.465ns accuracy */ 51 /* 0.465ns accuracy */
49 if (!(value & PTP_TCR_TSCTRLSSR)) 52 if (!(value & PTP_TCR_TSCTRLSSR))
50 data = (data * 1000) / 465; 53 data = (data * 1000) / 465;
51 54
55 data &= PTP_SSIR_SSINC_MASK;
56
57 if (gmac4)
58 data = data << GMAC4_PTP_SSIR_SSINC_SHIFT;
59
52 writel(data, ioaddr + PTP_SSIR); 60 writel(data, ioaddr + PTP_SSIR);
53 61
54 return data; 62 return data;
@@ -104,14 +112,30 @@ static int stmmac_config_addend(void __iomem *ioaddr, u32 addend)
104} 112}
105 113
106static int stmmac_adjust_systime(void __iomem *ioaddr, u32 sec, u32 nsec, 114static int stmmac_adjust_systime(void __iomem *ioaddr, u32 sec, u32 nsec,
107 int add_sub) 115 int add_sub, int gmac4)
108{ 116{
109 u32 value; 117 u32 value;
110 int limit; 118 int limit;
111 119
120 if (add_sub) {
121 /* If the new sec value needs to be subtracted with
122 * the system time, then MAC_STSUR reg should be
123 * programmed with (2^32 – <new_sec_value>)
124 */
125 if (gmac4)
126 sec = (100000000ULL - sec);
127
128 value = readl(ioaddr + PTP_TCR);
129 if (value & PTP_TCR_TSCTRLSSR)
130 nsec = (PTP_DIGITAL_ROLLOVER_MODE - nsec);
131 else
132 nsec = (PTP_BINARY_ROLLOVER_MODE - nsec);
133 }
134
112 writel(sec, ioaddr + PTP_STSUR); 135 writel(sec, ioaddr + PTP_STSUR);
113 writel(((add_sub << PTP_STNSUR_ADDSUB_SHIFT) | nsec), 136 value = (add_sub << PTP_STNSUR_ADDSUB_SHIFT) | nsec;
114 ioaddr + PTP_STNSUR); 137 writel(value, ioaddr + PTP_STNSUR);
138
115 /* issue command to initialize the system time value */ 139 /* issue command to initialize the system time value */
116 value = readl(ioaddr + PTP_TCR); 140 value = readl(ioaddr + PTP_TCR);
117 value |= PTP_TCR_TSUPDT; 141 value |= PTP_TCR_TSUPDT;
@@ -134,8 +158,9 @@ static u64 stmmac_get_systime(void __iomem *ioaddr)
134{ 158{
135 u64 ns; 159 u64 ns;
136 160
161 /* Get the TSSS value */
137 ns = readl(ioaddr + PTP_STNSR); 162 ns = readl(ioaddr + PTP_STNSR);
138 /* convert sec time value to nanosecond */ 163 /* Get the TSS and convert sec time value to nanosecond */
139 ns += readl(ioaddr + PTP_STSR) * 1000000000ULL; 164 ns += readl(ioaddr + PTP_STSR) * 1000000000ULL;
140 165
141 return ns; 166 return ns;
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index 6c85b61aaa0b..caf069a465f2 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -340,18 +340,17 @@ out:
340 340
341/* stmmac_get_tx_hwtstamp - get HW TX timestamps 341/* stmmac_get_tx_hwtstamp - get HW TX timestamps
342 * @priv: driver private structure 342 * @priv: driver private structure
343 * @entry : descriptor index to be used. 343 * @p : descriptor pointer
344 * @skb : the socket buffer 344 * @skb : the socket buffer
345 * Description : 345 * Description :
346 * This function will read timestamp from the descriptor & pass it to stack. 346 * This function will read timestamp from the descriptor & pass it to stack.
347 * and also perform some sanity checks. 347 * and also perform some sanity checks.
348 */ 348 */
349static void stmmac_get_tx_hwtstamp(struct stmmac_priv *priv, 349static void stmmac_get_tx_hwtstamp(struct stmmac_priv *priv,
350 unsigned int entry, struct sk_buff *skb) 350 struct dma_desc *p, struct sk_buff *skb)
351{ 351{
352 struct skb_shared_hwtstamps shhwtstamp; 352 struct skb_shared_hwtstamps shhwtstamp;
353 u64 ns; 353 u64 ns;
354 void *desc = NULL;
355 354
356 if (!priv->hwts_tx_en) 355 if (!priv->hwts_tx_en)
357 return; 356 return;
@@ -360,58 +359,55 @@ static void stmmac_get_tx_hwtstamp(struct stmmac_priv *priv,
360 if (likely(!skb || !(skb_shinfo(skb)->tx_flags & SKBTX_IN_PROGRESS))) 359 if (likely(!skb || !(skb_shinfo(skb)->tx_flags & SKBTX_IN_PROGRESS)))
361 return; 360 return;
362 361
363 if (priv->adv_ts)
364 desc = (priv->dma_etx + entry);
365 else
366 desc = (priv->dma_tx + entry);
367
368 /* check tx tstamp status */ 362 /* check tx tstamp status */
369 if (!priv->hw->desc->get_tx_timestamp_status((struct dma_desc *)desc)) 363 if (!priv->hw->desc->get_tx_timestamp_status(p)) {
370 return; 364 /* get the valid tstamp */
365 ns = priv->hw->desc->get_timestamp(p, priv->adv_ts);
371 366
372 /* get the valid tstamp */ 367 memset(&shhwtstamp, 0, sizeof(struct skb_shared_hwtstamps));
373 ns = priv->hw->desc->get_timestamp(desc, priv->adv_ts); 368 shhwtstamp.hwtstamp = ns_to_ktime(ns);
374 369
375 memset(&shhwtstamp, 0, sizeof(struct skb_shared_hwtstamps)); 370 netdev_info(priv->dev, "get valid TX hw timestamp %llu\n", ns);
376 shhwtstamp.hwtstamp = ns_to_ktime(ns); 371 /* pass tstamp to stack */
377 /* pass tstamp to stack */ 372 skb_tstamp_tx(skb, &shhwtstamp);
378 skb_tstamp_tx(skb, &shhwtstamp); 373 }
379 374
380 return; 375 return;
381} 376}
382 377
383/* stmmac_get_rx_hwtstamp - get HW RX timestamps 378/* stmmac_get_rx_hwtstamp - get HW RX timestamps
384 * @priv: driver private structure 379 * @priv: driver private structure
385 * @entry : descriptor index to be used. 380 * @p : descriptor pointer
381 * @np : next descriptor pointer
386 * @skb : the socket buffer 382 * @skb : the socket buffer
387 * Description : 383 * Description :
388 * This function will read received packet's timestamp from the descriptor 384 * This function will read received packet's timestamp from the descriptor
389 * and pass it to stack. It also perform some sanity checks. 385 * and pass it to stack. It also perform some sanity checks.
390 */ 386 */
391static void stmmac_get_rx_hwtstamp(struct stmmac_priv *priv, 387static void stmmac_get_rx_hwtstamp(struct stmmac_priv *priv, struct dma_desc *p,
392 unsigned int entry, struct sk_buff *skb) 388 struct dma_desc *np, struct sk_buff *skb)
393{ 389{
394 struct skb_shared_hwtstamps *shhwtstamp = NULL; 390 struct skb_shared_hwtstamps *shhwtstamp = NULL;
395 u64 ns; 391 u64 ns;
396 void *desc = NULL;
397 392
398 if (!priv->hwts_rx_en) 393 if (!priv->hwts_rx_en)
399 return; 394 return;
400 395
401 if (priv->adv_ts) 396 /* Check if timestamp is available */
402 desc = (priv->dma_erx + entry); 397 if (!priv->hw->desc->get_rx_timestamp_status(p, priv->adv_ts)) {
403 else 398 /* For GMAC4, the valid timestamp is from CTX next desc. */
404 desc = (priv->dma_rx + entry); 399 if (priv->plat->has_gmac4)
405 400 ns = priv->hw->desc->get_timestamp(np, priv->adv_ts);
406 /* exit if rx tstamp is not valid */ 401 else
407 if (!priv->hw->desc->get_rx_timestamp_status(desc, priv->adv_ts)) 402 ns = priv->hw->desc->get_timestamp(p, priv->adv_ts);
408 return;
409 403
410 /* get valid tstamp */ 404 netdev_info(priv->dev, "get valid RX hw timestamp %llu\n", ns);
411 ns = priv->hw->desc->get_timestamp(desc, priv->adv_ts); 405 shhwtstamp = skb_hwtstamps(skb);
412 shhwtstamp = skb_hwtstamps(skb); 406 memset(shhwtstamp, 0, sizeof(struct skb_shared_hwtstamps));
413 memset(shhwtstamp, 0, sizeof(struct skb_shared_hwtstamps)); 407 shhwtstamp->hwtstamp = ns_to_ktime(ns);
414 shhwtstamp->hwtstamp = ns_to_ktime(ns); 408 } else {
409 netdev_err(priv->dev, "cannot get RX hw timestamp\n");
410 }
415} 411}
416 412
417/** 413/**
@@ -598,17 +594,18 @@ static int stmmac_hwtstamp_ioctl(struct net_device *dev, struct ifreq *ifr)
598 priv->hwts_tx_en = config.tx_type == HWTSTAMP_TX_ON; 594 priv->hwts_tx_en = config.tx_type == HWTSTAMP_TX_ON;
599 595
600 if (!priv->hwts_tx_en && !priv->hwts_rx_en) 596 if (!priv->hwts_tx_en && !priv->hwts_rx_en)
601 priv->hw->ptp->config_hw_tstamping(priv->ioaddr, 0); 597 priv->hw->ptp->config_hw_tstamping(priv->ptpaddr, 0);
602 else { 598 else {
603 value = (PTP_TCR_TSENA | PTP_TCR_TSCFUPDT | PTP_TCR_TSCTRLSSR | 599 value = (PTP_TCR_TSENA | PTP_TCR_TSCFUPDT | PTP_TCR_TSCTRLSSR |
604 tstamp_all | ptp_v2 | ptp_over_ethernet | 600 tstamp_all | ptp_v2 | ptp_over_ethernet |
605 ptp_over_ipv6_udp | ptp_over_ipv4_udp | ts_event_en | 601 ptp_over_ipv6_udp | ptp_over_ipv4_udp | ts_event_en |
606 ts_master_en | snap_type_sel); 602 ts_master_en | snap_type_sel);
607 priv->hw->ptp->config_hw_tstamping(priv->ioaddr, value); 603 priv->hw->ptp->config_hw_tstamping(priv->ptpaddr, value);
608 604
609 /* program Sub Second Increment reg */ 605 /* program Sub Second Increment reg */
610 sec_inc = priv->hw->ptp->config_sub_second_increment( 606 sec_inc = priv->hw->ptp->config_sub_second_increment(
611 priv->ioaddr, priv->clk_ptp_rate); 607 priv->ptpaddr, priv->clk_ptp_rate,
608 priv->plat->has_gmac4);
612 temp = div_u64(1000000000ULL, sec_inc); 609 temp = div_u64(1000000000ULL, sec_inc);
613 610
614 /* calculate default added value: 611 /* calculate default added value:
@@ -618,14 +615,14 @@ static int stmmac_hwtstamp_ioctl(struct net_device *dev, struct ifreq *ifr)
618 */ 615 */
619 temp = (u64)(temp << 32); 616 temp = (u64)(temp << 32);
620 priv->default_addend = div_u64(temp, priv->clk_ptp_rate); 617 priv->default_addend = div_u64(temp, priv->clk_ptp_rate);
621 priv->hw->ptp->config_addend(priv->ioaddr, 618 priv->hw->ptp->config_addend(priv->ptpaddr,
622 priv->default_addend); 619 priv->default_addend);
623 620
624 /* initialize system time */ 621 /* initialize system time */
625 ktime_get_real_ts64(&now); 622 ktime_get_real_ts64(&now);
626 623
627 /* lower 32 bits of tv_sec are safe until y2106 */ 624 /* lower 32 bits of tv_sec are safe until y2106 */
628 priv->hw->ptp->init_systime(priv->ioaddr, (u32)now.tv_sec, 625 priv->hw->ptp->init_systime(priv->ptpaddr, (u32)now.tv_sec,
629 now.tv_nsec); 626 now.tv_nsec);
630 } 627 }
631 628
@@ -676,7 +673,9 @@ static int stmmac_init_ptp(struct stmmac_priv *priv)
676 priv->hwts_tx_en = 0; 673 priv->hwts_tx_en = 0;
677 priv->hwts_rx_en = 0; 674 priv->hwts_rx_en = 0;
678 675
679 return stmmac_ptp_register(priv); 676 stmmac_ptp_register(priv);
677
678 return 0;
680} 679}
681 680
682static void stmmac_release_ptp(struct stmmac_priv *priv) 681static void stmmac_release_ptp(struct stmmac_priv *priv)
@@ -878,6 +877,13 @@ static int stmmac_init_phy(struct net_device *dev)
878 return -ENODEV; 877 return -ENODEV;
879 } 878 }
880 879
880 /* stmmac_adjust_link will change this to PHY_IGNORE_INTERRUPT to avoid
881 * subsequent PHY polling, make sure we force a link transition if
882 * we have a UP/DOWN/UP transition
883 */
884 if (phydev->is_pseudo_fixed_link)
885 phydev->irq = PHY_POLL;
886
881 pr_debug("stmmac_init_phy: %s: attached to PHY (UID 0x%x)" 887 pr_debug("stmmac_init_phy: %s: attached to PHY (UID 0x%x)"
882 " Link = %d\n", dev->name, phydev->phy_id, phydev->link); 888 " Link = %d\n", dev->name, phydev->phy_id, phydev->link);
883 889
@@ -1331,7 +1337,7 @@ static void stmmac_tx_clean(struct stmmac_priv *priv)
1331 priv->dev->stats.tx_packets++; 1337 priv->dev->stats.tx_packets++;
1332 priv->xstats.tx_pkt_n++; 1338 priv->xstats.tx_pkt_n++;
1333 } 1339 }
1334 stmmac_get_tx_hwtstamp(priv, entry, skb); 1340 stmmac_get_tx_hwtstamp(priv, p, skb);
1335 } 1341 }
1336 1342
1337 if (likely(priv->tx_skbuff_dma[entry].buf)) { 1343 if (likely(priv->tx_skbuff_dma[entry].buf)) {
@@ -1477,10 +1483,13 @@ static void stmmac_mmc_setup(struct stmmac_priv *priv)
1477 unsigned int mode = MMC_CNTRL_RESET_ON_READ | MMC_CNTRL_COUNTER_RESET | 1483 unsigned int mode = MMC_CNTRL_RESET_ON_READ | MMC_CNTRL_COUNTER_RESET |
1478 MMC_CNTRL_PRESET | MMC_CNTRL_FULL_HALF_PRESET; 1484 MMC_CNTRL_PRESET | MMC_CNTRL_FULL_HALF_PRESET;
1479 1485
1480 if (priv->synopsys_id >= DWMAC_CORE_4_00) 1486 if (priv->synopsys_id >= DWMAC_CORE_4_00) {
1487 priv->ptpaddr = priv->ioaddr + PTP_GMAC4_OFFSET;
1481 priv->mmcaddr = priv->ioaddr + MMC_GMAC4_OFFSET; 1488 priv->mmcaddr = priv->ioaddr + MMC_GMAC4_OFFSET;
1482 else 1489 } else {
1490 priv->ptpaddr = priv->ioaddr + PTP_GMAC3_X_OFFSET;
1483 priv->mmcaddr = priv->ioaddr + MMC_GMAC3_X_OFFSET; 1491 priv->mmcaddr = priv->ioaddr + MMC_GMAC3_X_OFFSET;
1492 }
1484 1493
1485 dwmac_mmc_intr_all_mask(priv->mmcaddr); 1494 dwmac_mmc_intr_all_mask(priv->mmcaddr);
1486 1495
@@ -1710,7 +1719,7 @@ static int stmmac_hw_setup(struct net_device *dev, bool init_ptp)
1710 if (init_ptp) { 1719 if (init_ptp) {
1711 ret = stmmac_init_ptp(priv); 1720 ret = stmmac_init_ptp(priv);
1712 if (ret) 1721 if (ret)
1713 netdev_warn(priv->dev, "PTP support cannot init.\n"); 1722 netdev_warn(priv->dev, "fail to init PTP.\n");
1714 } 1723 }
1715 1724
1716#ifdef CONFIG_DEBUG_FS 1725#ifdef CONFIG_DEBUG_FS
@@ -2475,7 +2484,7 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit)
2475 if (netif_msg_rx_status(priv)) { 2484 if (netif_msg_rx_status(priv)) {
2476 void *rx_head; 2485 void *rx_head;
2477 2486
2478 pr_debug("%s: descriptor ring:\n", __func__); 2487 pr_info(">>>>>> %s: descriptor ring:\n", __func__);
2479 if (priv->extend_desc) 2488 if (priv->extend_desc)
2480 rx_head = (void *)priv->dma_erx; 2489 rx_head = (void *)priv->dma_erx;
2481 else 2490 else
@@ -2486,6 +2495,7 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit)
2486 while (count < limit) { 2495 while (count < limit) {
2487 int status; 2496 int status;
2488 struct dma_desc *p; 2497 struct dma_desc *p;
2498 struct dma_desc *np;
2489 2499
2490 if (priv->extend_desc) 2500 if (priv->extend_desc)
2491 p = (struct dma_desc *)(priv->dma_erx + entry); 2501 p = (struct dma_desc *)(priv->dma_erx + entry);
@@ -2505,9 +2515,11 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit)
2505 next_entry = priv->cur_rx; 2515 next_entry = priv->cur_rx;
2506 2516
2507 if (priv->extend_desc) 2517 if (priv->extend_desc)
2508 prefetch(priv->dma_erx + next_entry); 2518 np = (struct dma_desc *)(priv->dma_erx + next_entry);
2509 else 2519 else
2510 prefetch(priv->dma_rx + next_entry); 2520 np = priv->dma_rx + next_entry;
2521
2522 prefetch(np);
2511 2523
2512 if ((priv->extend_desc) && (priv->hw->desc->rx_extended_status)) 2524 if ((priv->extend_desc) && (priv->hw->desc->rx_extended_status))
2513 priv->hw->desc->rx_extended_status(&priv->dev->stats, 2525 priv->hw->desc->rx_extended_status(&priv->dev->stats,
@@ -2559,7 +2571,7 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit)
2559 frame_len -= ETH_FCS_LEN; 2571 frame_len -= ETH_FCS_LEN;
2560 2572
2561 if (netif_msg_rx_status(priv)) { 2573 if (netif_msg_rx_status(priv)) {
2562 pr_debug("\tdesc: %p [entry %d] buff=0x%x\n", 2574 pr_info("\tdesc: %p [entry %d] buff=0x%x\n",
2563 p, entry, des); 2575 p, entry, des);
2564 if (frame_len > ETH_FRAME_LEN) 2576 if (frame_len > ETH_FRAME_LEN)
2565 pr_debug("\tframe size %d, COE: %d\n", 2577 pr_debug("\tframe size %d, COE: %d\n",
@@ -2616,13 +2628,13 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit)
2616 DMA_FROM_DEVICE); 2628 DMA_FROM_DEVICE);
2617 } 2629 }
2618 2630
2619 stmmac_get_rx_hwtstamp(priv, entry, skb);
2620
2621 if (netif_msg_pktdata(priv)) { 2631 if (netif_msg_pktdata(priv)) {
2622 pr_debug("frame received (%dbytes)", frame_len); 2632 pr_debug("frame received (%dbytes)", frame_len);
2623 print_pkt(skb->data, frame_len); 2633 print_pkt(skb->data, frame_len);
2624 } 2634 }
2625 2635
2636 stmmac_get_rx_hwtstamp(priv, p, np, skb);
2637
2626 stmmac_rx_vlan(priv->dev, skb); 2638 stmmac_rx_vlan(priv->dev, skb);
2627 2639
2628 skb->protocol = eth_type_trans(skb, priv->dev); 2640 skb->protocol = eth_type_trans(skb, priv->dev);
@@ -3404,7 +3416,6 @@ int stmmac_dvr_remove(struct device *dev)
3404 stmmac_set_mac(priv->ioaddr, false); 3416 stmmac_set_mac(priv->ioaddr, false);
3405 netif_carrier_off(ndev); 3417 netif_carrier_off(ndev);
3406 unregister_netdev(ndev); 3418 unregister_netdev(ndev);
3407 of_node_put(priv->plat->phy_node);
3408 if (priv->stmmac_rst) 3419 if (priv->stmmac_rst)
3409 reset_control_assert(priv->stmmac_rst); 3420 reset_control_assert(priv->stmmac_rst);
3410 clk_disable_unprepare(priv->pclk); 3421 clk_disable_unprepare(priv->pclk);
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
index 0a0d6a86f397..ac3d39c69509 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
@@ -126,8 +126,10 @@ static struct stmmac_axi *stmmac_axi_setup(struct platform_device *pdev)
126 axi->axi_mb = of_property_read_bool(np, "snps,axi_mb"); 126 axi->axi_mb = of_property_read_bool(np, "snps,axi_mb");
127 axi->axi_rb = of_property_read_bool(np, "snps,axi_rb"); 127 axi->axi_rb = of_property_read_bool(np, "snps,axi_rb");
128 128
129 of_property_read_u32(np, "snps,wr_osr_lmt", &axi->axi_wr_osr_lmt); 129 if (of_property_read_u32(np, "snps,wr_osr_lmt", &axi->axi_wr_osr_lmt))
130 of_property_read_u32(np, "snps,rd_osr_lmt", &axi->axi_rd_osr_lmt); 130 axi->axi_wr_osr_lmt = 1;
131 if (of_property_read_u32(np, "snps,rd_osr_lmt", &axi->axi_rd_osr_lmt))
132 axi->axi_rd_osr_lmt = 1;
131 of_property_read_u32_array(np, "snps,blen", axi->axi_blen, AXI_BLEN); 133 of_property_read_u32_array(np, "snps,blen", axi->axi_blen, AXI_BLEN);
132 of_node_put(np); 134 of_node_put(np);
133 135
@@ -200,7 +202,6 @@ static int stmmac_dt_phy(struct plat_stmmacenet_data *plat,
200/** 202/**
201 * stmmac_probe_config_dt - parse device-tree driver parameters 203 * stmmac_probe_config_dt - parse device-tree driver parameters
202 * @pdev: platform_device structure 204 * @pdev: platform_device structure
203 * @plat: driver data platform structure
204 * @mac: MAC address to use 205 * @mac: MAC address to use
205 * Description: 206 * Description:
206 * this function is to read the driver parameters from device-tree and 207 * this function is to read the driver parameters from device-tree and
@@ -306,7 +307,7 @@ stmmac_probe_config_dt(struct platform_device *pdev, const char **mac)
306 dma_cfg = devm_kzalloc(&pdev->dev, sizeof(*dma_cfg), 307 dma_cfg = devm_kzalloc(&pdev->dev, sizeof(*dma_cfg),
307 GFP_KERNEL); 308 GFP_KERNEL);
308 if (!dma_cfg) { 309 if (!dma_cfg) {
309 of_node_put(plat->phy_node); 310 stmmac_remove_config_dt(pdev, plat);
310 return ERR_PTR(-ENOMEM); 311 return ERR_PTR(-ENOMEM);
311 } 312 }
312 plat->dma_cfg = dma_cfg; 313 plat->dma_cfg = dma_cfg;
@@ -329,14 +330,37 @@ stmmac_probe_config_dt(struct platform_device *pdev, const char **mac)
329 330
330 return plat; 331 return plat;
331} 332}
333
334/**
335 * stmmac_remove_config_dt - undo the effects of stmmac_probe_config_dt()
336 * @pdev: platform_device structure
337 * @plat: driver data platform structure
338 *
339 * Release resources claimed by stmmac_probe_config_dt().
340 */
341void stmmac_remove_config_dt(struct platform_device *pdev,
342 struct plat_stmmacenet_data *plat)
343{
344 struct device_node *np = pdev->dev.of_node;
345
346 if (of_phy_is_fixed_link(np))
347 of_phy_deregister_fixed_link(np);
348 of_node_put(plat->phy_node);
349}
332#else 350#else
333struct plat_stmmacenet_data * 351struct plat_stmmacenet_data *
334stmmac_probe_config_dt(struct platform_device *pdev, const char **mac) 352stmmac_probe_config_dt(struct platform_device *pdev, const char **mac)
335{ 353{
336 return ERR_PTR(-ENOSYS); 354 return ERR_PTR(-ENOSYS);
337} 355}
356
357void stmmac_remove_config_dt(struct platform_device *pdev,
358 struct plat_stmmacenet_data *plat)
359{
360}
338#endif /* CONFIG_OF */ 361#endif /* CONFIG_OF */
339EXPORT_SYMBOL_GPL(stmmac_probe_config_dt); 362EXPORT_SYMBOL_GPL(stmmac_probe_config_dt);
363EXPORT_SYMBOL_GPL(stmmac_remove_config_dt);
340 364
341int stmmac_get_platform_resources(struct platform_device *pdev, 365int stmmac_get_platform_resources(struct platform_device *pdev,
342 struct stmmac_resources *stmmac_res) 366 struct stmmac_resources *stmmac_res)
@@ -392,10 +416,13 @@ int stmmac_pltfr_remove(struct platform_device *pdev)
392{ 416{
393 struct net_device *ndev = platform_get_drvdata(pdev); 417 struct net_device *ndev = platform_get_drvdata(pdev);
394 struct stmmac_priv *priv = netdev_priv(ndev); 418 struct stmmac_priv *priv = netdev_priv(ndev);
419 struct plat_stmmacenet_data *plat = priv->plat;
395 int ret = stmmac_dvr_remove(&pdev->dev); 420 int ret = stmmac_dvr_remove(&pdev->dev);
396 421
397 if (priv->plat->exit) 422 if (plat->exit)
398 priv->plat->exit(pdev, priv->plat->bsp_priv); 423 plat->exit(pdev, plat->bsp_priv);
424
425 stmmac_remove_config_dt(pdev, plat);
399 426
400 return ret; 427 return ret;
401} 428}
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.h b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.h
index 64e147f53a9c..b72eb0de57b7 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.h
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.h
@@ -23,6 +23,8 @@
23 23
24struct plat_stmmacenet_data * 24struct plat_stmmacenet_data *
25stmmac_probe_config_dt(struct platform_device *pdev, const char **mac); 25stmmac_probe_config_dt(struct platform_device *pdev, const char **mac);
26void stmmac_remove_config_dt(struct platform_device *pdev,
27 struct plat_stmmacenet_data *plat);
26 28
27int stmmac_get_platform_resources(struct platform_device *pdev, 29int stmmac_get_platform_resources(struct platform_device *pdev,
28 struct stmmac_resources *stmmac_res); 30 struct stmmac_resources *stmmac_res);
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c
index 289d52725a6c..3eb281d1db08 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c
@@ -54,7 +54,7 @@ static int stmmac_adjust_freq(struct ptp_clock_info *ptp, s32 ppb)
54 54
55 spin_lock_irqsave(&priv->ptp_lock, flags); 55 spin_lock_irqsave(&priv->ptp_lock, flags);
56 56
57 priv->hw->ptp->config_addend(priv->ioaddr, addend); 57 priv->hw->ptp->config_addend(priv->ptpaddr, addend);
58 58
59 spin_unlock_irqrestore(&priv->ptp_lock, flags); 59 spin_unlock_irqrestore(&priv->ptp_lock, flags);
60 60
@@ -89,7 +89,8 @@ static int stmmac_adjust_time(struct ptp_clock_info *ptp, s64 delta)
89 89
90 spin_lock_irqsave(&priv->ptp_lock, flags); 90 spin_lock_irqsave(&priv->ptp_lock, flags);
91 91
92 priv->hw->ptp->adjust_systime(priv->ioaddr, sec, nsec, neg_adj); 92 priv->hw->ptp->adjust_systime(priv->ptpaddr, sec, nsec, neg_adj,
93 priv->plat->has_gmac4);
93 94
94 spin_unlock_irqrestore(&priv->ptp_lock, flags); 95 spin_unlock_irqrestore(&priv->ptp_lock, flags);
95 96
@@ -114,7 +115,7 @@ static int stmmac_get_time(struct ptp_clock_info *ptp, struct timespec64 *ts)
114 115
115 spin_lock_irqsave(&priv->ptp_lock, flags); 116 spin_lock_irqsave(&priv->ptp_lock, flags);
116 117
117 ns = priv->hw->ptp->get_systime(priv->ioaddr); 118 ns = priv->hw->ptp->get_systime(priv->ptpaddr);
118 119
119 spin_unlock_irqrestore(&priv->ptp_lock, flags); 120 spin_unlock_irqrestore(&priv->ptp_lock, flags);
120 121
@@ -141,7 +142,7 @@ static int stmmac_set_time(struct ptp_clock_info *ptp,
141 142
142 spin_lock_irqsave(&priv->ptp_lock, flags); 143 spin_lock_irqsave(&priv->ptp_lock, flags);
143 144
144 priv->hw->ptp->init_systime(priv->ioaddr, ts->tv_sec, ts->tv_nsec); 145 priv->hw->ptp->init_systime(priv->ptpaddr, ts->tv_sec, ts->tv_nsec);
145 146
146 spin_unlock_irqrestore(&priv->ptp_lock, flags); 147 spin_unlock_irqrestore(&priv->ptp_lock, flags);
147 148
@@ -177,7 +178,7 @@ static struct ptp_clock_info stmmac_ptp_clock_ops = {
177 * Description: this function will register the ptp clock driver 178 * Description: this function will register the ptp clock driver
178 * to kernel. It also does some house keeping work. 179 * to kernel. It also does some house keeping work.
179 */ 180 */
180int stmmac_ptp_register(struct stmmac_priv *priv) 181void stmmac_ptp_register(struct stmmac_priv *priv)
181{ 182{
182 spin_lock_init(&priv->ptp_lock); 183 spin_lock_init(&priv->ptp_lock);
183 priv->ptp_clock_ops = stmmac_ptp_clock_ops; 184 priv->ptp_clock_ops = stmmac_ptp_clock_ops;
@@ -185,15 +186,10 @@ int stmmac_ptp_register(struct stmmac_priv *priv)
185 priv->ptp_clock = ptp_clock_register(&priv->ptp_clock_ops, 186 priv->ptp_clock = ptp_clock_register(&priv->ptp_clock_ops,
186 priv->device); 187 priv->device);
187 if (IS_ERR(priv->ptp_clock)) { 188 if (IS_ERR(priv->ptp_clock)) {
189 netdev_err(priv->dev, "ptp_clock_register failed\n");
188 priv->ptp_clock = NULL; 190 priv->ptp_clock = NULL;
189 return PTR_ERR(priv->ptp_clock); 191 } else if (priv->ptp_clock)
190 } 192 netdev_info(priv->dev, "registered PTP clock\n");
191
192 spin_lock_init(&priv->ptp_lock);
193
194 netdev_dbg(priv->dev, "Added PTP HW clock successfully\n");
195
196 return 0;
197} 193}
198 194
199/** 195/**
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h b/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h
index 4535df37c227..c06938c47af5 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h
@@ -22,51 +22,53 @@
22 Author: Rayagond Kokatanur <rayagond@vayavyalabs.com> 22 Author: Rayagond Kokatanur <rayagond@vayavyalabs.com>
23******************************************************************************/ 23******************************************************************************/
24 24
25#ifndef __STMMAC_PTP_H__ 25#ifndef __STMMAC_PTP_H__
26#define __STMMAC_PTP_H__ 26#define __STMMAC_PTP_H__
27 27
28/* IEEE 1588 PTP register offsets */ 28#define PTP_GMAC4_OFFSET 0xb00
29#define PTP_TCR 0x0700 /* Timestamp Control Reg */ 29#define PTP_GMAC3_X_OFFSET 0x700
30#define PTP_SSIR 0x0704 /* Sub-Second Increment Reg */
31#define PTP_STSR 0x0708 /* System Time – Seconds Regr */
32#define PTP_STNSR 0x070C /* System Time – Nanoseconds Reg */
33#define PTP_STSUR 0x0710 /* System Time – Seconds Update Reg */
34#define PTP_STNSUR 0x0714 /* System Time – Nanoseconds Update Reg */
35#define PTP_TAR 0x0718 /* Timestamp Addend Reg */
36#define PTP_TTSR 0x071C /* Target Time Seconds Reg */
37#define PTP_TTNSR 0x0720 /* Target Time Nanoseconds Reg */
38#define PTP_STHWSR 0x0724 /* System Time - Higher Word Seconds Reg */
39#define PTP_TSR 0x0728 /* Timestamp Status */
40 30
41#define PTP_STNSUR_ADDSUB_SHIFT 31 31/* IEEE 1588 PTP register offsets */
32#define PTP_TCR 0x00 /* Timestamp Control Reg */
33#define PTP_SSIR 0x04 /* Sub-Second Increment Reg */
34#define PTP_STSR 0x08 /* System Time – Seconds Regr */
35#define PTP_STNSR 0x0c /* System Time – Nanoseconds Reg */
36#define PTP_STSUR 0x10 /* System Time – Seconds Update Reg */
37#define PTP_STNSUR 0x14 /* System Time – Nanoseconds Update Reg */
38#define PTP_TAR 0x18 /* Timestamp Addend Reg */
42 39
43/* PTP TCR defines */ 40#define PTP_STNSUR_ADDSUB_SHIFT 31
44#define PTP_TCR_TSENA 0x00000001 /* Timestamp Enable */ 41#define PTP_DIGITAL_ROLLOVER_MODE 0x3B9ACA00 /* 10e9-1 ns */
45#define PTP_TCR_TSCFUPDT 0x00000002 /* Timestamp Fine/Coarse Update */ 42#define PTP_BINARY_ROLLOVER_MODE 0x80000000 /* ~0.466 ns */
46#define PTP_TCR_TSINIT 0x00000004 /* Timestamp Initialize */
47#define PTP_TCR_TSUPDT 0x00000008 /* Timestamp Update */
48/* Timestamp Interrupt Trigger Enable */
49#define PTP_TCR_TSTRIG 0x00000010
50#define PTP_TCR_TSADDREG 0x00000020 /* Addend Reg Update */
51#define PTP_TCR_TSENALL 0x00000100 /* Enable Timestamp for All Frames */
52/* Timestamp Digital or Binary Rollover Control */
53#define PTP_TCR_TSCTRLSSR 0x00000200
54 43
44/* PTP Timestamp control register defines */
45#define PTP_TCR_TSENA BIT(0) /* Timestamp Enable */
46#define PTP_TCR_TSCFUPDT BIT(1) /* Timestamp Fine/Coarse Update */
47#define PTP_TCR_TSINIT BIT(2) /* Timestamp Initialize */
48#define PTP_TCR_TSUPDT BIT(3) /* Timestamp Update */
49#define PTP_TCR_TSTRIG BIT(4) /* Timestamp Interrupt Trigger Enable */
50#define PTP_TCR_TSADDREG BIT(5) /* Addend Reg Update */
51#define PTP_TCR_TSENALL BIT(8) /* Enable Timestamp for All Frames */
52#define PTP_TCR_TSCTRLSSR BIT(9) /* Digital or Binary Rollover Control */
55/* Enable PTP packet Processing for Version 2 Format */ 53/* Enable PTP packet Processing for Version 2 Format */
56#define PTP_TCR_TSVER2ENA 0x00000400 54#define PTP_TCR_TSVER2ENA BIT(10)
57/* Enable Processing of PTP over Ethernet Frames */ 55/* Enable Processing of PTP over Ethernet Frames */
58#define PTP_TCR_TSIPENA 0x00000800 56#define PTP_TCR_TSIPENA BIT(11)
59/* Enable Processing of PTP Frames Sent over IPv6-UDP */ 57/* Enable Processing of PTP Frames Sent over IPv6-UDP */
60#define PTP_TCR_TSIPV6ENA 0x00001000 58#define PTP_TCR_TSIPV6ENA BIT(12)
61/* Enable Processing of PTP Frames Sent over IPv4-UDP */ 59/* Enable Processing of PTP Frames Sent over IPv4-UDP */
62#define PTP_TCR_TSIPV4ENA 0x00002000 60#define PTP_TCR_TSIPV4ENA BIT(13)
63/* Enable Timestamp Snapshot for Event Messages */ 61/* Enable Timestamp Snapshot for Event Messages */
64#define PTP_TCR_TSEVNTENA 0x00004000 62#define PTP_TCR_TSEVNTENA BIT(14)
65/* Enable Snapshot for Messages Relevant to Master */ 63/* Enable Snapshot for Messages Relevant to Master */
66#define PTP_TCR_TSMSTRENA 0x00008000 64#define PTP_TCR_TSMSTRENA BIT(15)
67/* Select PTP packets for Taking Snapshots */ 65/* Select PTP packets for Taking Snapshots */
68#define PTP_TCR_SNAPTYPSEL_1 0x00010000 66#define PTP_TCR_SNAPTYPSEL_1 GENMASK(17, 16)
69/* Enable MAC address for PTP Frame Filtering */ 67/* Enable MAC address for PTP Frame Filtering */
70#define PTP_TCR_TSENMACADDR 0x00040000 68#define PTP_TCR_TSENMACADDR BIT(18)
69
70/* SSIR defines */
71#define PTP_SSIR_SSINC_MASK 0xff
72#define GMAC4_PTP_SSIR_SSINC_SHIFT 16
71 73
72#endif /* __STMMAC_PTP_H__ */ 74#endif /* __STMMAC_PTP_H__ */
diff --git a/drivers/net/ethernet/sun/sunbmac.c b/drivers/net/ethernet/sun/sunbmac.c
index aa4f9d2d8fa9..02f452730d52 100644
--- a/drivers/net/ethernet/sun/sunbmac.c
+++ b/drivers/net/ethernet/sun/sunbmac.c
@@ -623,6 +623,7 @@ static int bigmac_init_hw(struct bigmac *bp, int from_irq)
623 void __iomem *gregs = bp->gregs; 623 void __iomem *gregs = bp->gregs;
624 void __iomem *cregs = bp->creg; 624 void __iomem *cregs = bp->creg;
625 void __iomem *bregs = bp->bregs; 625 void __iomem *bregs = bp->bregs;
626 __u32 bblk_dvma = (__u32)bp->bblock_dvma;
626 unsigned char *e = &bp->dev->dev_addr[0]; 627 unsigned char *e = &bp->dev->dev_addr[0];
627 628
628 /* Latch current counters into statistics. */ 629 /* Latch current counters into statistics. */
@@ -671,9 +672,9 @@ static int bigmac_init_hw(struct bigmac *bp, int from_irq)
671 bregs + BMAC_XIFCFG); 672 bregs + BMAC_XIFCFG);
672 673
673 /* Tell the QEC where the ring descriptors are. */ 674 /* Tell the QEC where the ring descriptors are. */
674 sbus_writel(bp->bblock_dvma + bib_offset(be_rxd, 0), 675 sbus_writel(bblk_dvma + bib_offset(be_rxd, 0),
675 cregs + CREG_RXDS); 676 cregs + CREG_RXDS);
676 sbus_writel(bp->bblock_dvma + bib_offset(be_txd, 0), 677 sbus_writel(bblk_dvma + bib_offset(be_txd, 0),
677 cregs + CREG_TXDS); 678 cregs + CREG_TXDS);
678 679
679 /* Setup the FIFO pointers into QEC local memory. */ 680 /* Setup the FIFO pointers into QEC local memory. */
diff --git a/drivers/net/ethernet/sun/sunbmac.h b/drivers/net/ethernet/sun/sunbmac.h
index 06dd21707353..532fc56830cf 100644
--- a/drivers/net/ethernet/sun/sunbmac.h
+++ b/drivers/net/ethernet/sun/sunbmac.h
@@ -291,7 +291,7 @@ struct bigmac {
291 void __iomem *bregs; /* BigMAC Registers */ 291 void __iomem *bregs; /* BigMAC Registers */
292 void __iomem *tregs; /* BigMAC Transceiver */ 292 void __iomem *tregs; /* BigMAC Transceiver */
293 struct bmac_init_block *bmac_block; /* RX and TX descriptors */ 293 struct bmac_init_block *bmac_block; /* RX and TX descriptors */
294 __u32 bblock_dvma; /* RX and TX descriptors */ 294 dma_addr_t bblock_dvma; /* RX and TX descriptors */
295 295
296 spinlock_t lock; 296 spinlock_t lock;
297 297
diff --git a/drivers/net/ethernet/sun/sunqe.c b/drivers/net/ethernet/sun/sunqe.c
index 9b825780b3be..9582948145c1 100644
--- a/drivers/net/ethernet/sun/sunqe.c
+++ b/drivers/net/ethernet/sun/sunqe.c
@@ -124,7 +124,7 @@ static void qe_init_rings(struct sunqe *qep)
124{ 124{
125 struct qe_init_block *qb = qep->qe_block; 125 struct qe_init_block *qb = qep->qe_block;
126 struct sunqe_buffers *qbufs = qep->buffers; 126 struct sunqe_buffers *qbufs = qep->buffers;
127 __u32 qbufs_dvma = qep->buffers_dvma; 127 __u32 qbufs_dvma = (__u32)qep->buffers_dvma;
128 int i; 128 int i;
129 129
130 qep->rx_new = qep->rx_old = qep->tx_new = qep->tx_old = 0; 130 qep->rx_new = qep->rx_old = qep->tx_new = qep->tx_old = 0;
@@ -144,6 +144,7 @@ static int qe_init(struct sunqe *qep, int from_irq)
144 void __iomem *mregs = qep->mregs; 144 void __iomem *mregs = qep->mregs;
145 void __iomem *gregs = qecp->gregs; 145 void __iomem *gregs = qecp->gregs;
146 unsigned char *e = &qep->dev->dev_addr[0]; 146 unsigned char *e = &qep->dev->dev_addr[0];
147 __u32 qblk_dvma = (__u32)qep->qblock_dvma;
147 u32 tmp; 148 u32 tmp;
148 int i; 149 int i;
149 150
@@ -152,8 +153,8 @@ static int qe_init(struct sunqe *qep, int from_irq)
152 return -EAGAIN; 153 return -EAGAIN;
153 154
154 /* Setup initial rx/tx init block pointers. */ 155 /* Setup initial rx/tx init block pointers. */
155 sbus_writel(qep->qblock_dvma + qib_offset(qe_rxd, 0), cregs + CREG_RXDS); 156 sbus_writel(qblk_dvma + qib_offset(qe_rxd, 0), cregs + CREG_RXDS);
156 sbus_writel(qep->qblock_dvma + qib_offset(qe_txd, 0), cregs + CREG_TXDS); 157 sbus_writel(qblk_dvma + qib_offset(qe_txd, 0), cregs + CREG_TXDS);
157 158
158 /* Enable/mask the various irq's. */ 159 /* Enable/mask the various irq's. */
159 sbus_writel(0, cregs + CREG_RIMASK); 160 sbus_writel(0, cregs + CREG_RIMASK);
@@ -413,7 +414,7 @@ static void qe_rx(struct sunqe *qep)
413 struct net_device *dev = qep->dev; 414 struct net_device *dev = qep->dev;
414 struct qe_rxd *this; 415 struct qe_rxd *this;
415 struct sunqe_buffers *qbufs = qep->buffers; 416 struct sunqe_buffers *qbufs = qep->buffers;
416 __u32 qbufs_dvma = qep->buffers_dvma; 417 __u32 qbufs_dvma = (__u32)qep->buffers_dvma;
417 int elem = qep->rx_new; 418 int elem = qep->rx_new;
418 u32 flags; 419 u32 flags;
419 420
@@ -572,7 +573,7 @@ static int qe_start_xmit(struct sk_buff *skb, struct net_device *dev)
572{ 573{
573 struct sunqe *qep = netdev_priv(dev); 574 struct sunqe *qep = netdev_priv(dev);
574 struct sunqe_buffers *qbufs = qep->buffers; 575 struct sunqe_buffers *qbufs = qep->buffers;
575 __u32 txbuf_dvma, qbufs_dvma = qep->buffers_dvma; 576 __u32 txbuf_dvma, qbufs_dvma = (__u32)qep->buffers_dvma;
576 unsigned char *txbuf; 577 unsigned char *txbuf;
577 int len, entry; 578 int len, entry;
578 579
diff --git a/drivers/net/ethernet/sun/sunqe.h b/drivers/net/ethernet/sun/sunqe.h
index 581781b6b2fa..ae190b77431b 100644
--- a/drivers/net/ethernet/sun/sunqe.h
+++ b/drivers/net/ethernet/sun/sunqe.h
@@ -334,12 +334,12 @@ struct sunqe {
334 void __iomem *qcregs; /* QEC per-channel Registers */ 334 void __iomem *qcregs; /* QEC per-channel Registers */
335 void __iomem *mregs; /* Per-channel MACE Registers */ 335 void __iomem *mregs; /* Per-channel MACE Registers */
336 struct qe_init_block *qe_block; /* RX and TX descriptors */ 336 struct qe_init_block *qe_block; /* RX and TX descriptors */
337 __u32 qblock_dvma; /* RX and TX descriptors */ 337 dma_addr_t qblock_dvma; /* RX and TX descriptors */
338 spinlock_t lock; /* Protects txfull state */ 338 spinlock_t lock; /* Protects txfull state */
339 int rx_new, rx_old; /* RX ring extents */ 339 int rx_new, rx_old; /* RX ring extents */
340 int tx_new, tx_old; /* TX ring extents */ 340 int tx_new, tx_old; /* TX ring extents */
341 struct sunqe_buffers *buffers; /* CPU visible address. */ 341 struct sunqe_buffers *buffers; /* CPU visible address. */
342 __u32 buffers_dvma; /* DVMA visible address. */ 342 dma_addr_t buffers_dvma; /* DVMA visible address. */
343 struct sunqec *parent; 343 struct sunqec *parent;
344 u8 mconfig; /* Base MACE mconfig value */ 344 u8 mconfig; /* Base MACE mconfig value */
345 struct platform_device *op; /* QE's OF device struct */ 345 struct platform_device *op; /* QE's OF device struct */
diff --git a/drivers/net/ethernet/synopsys/dwc_eth_qos.c b/drivers/net/ethernet/synopsys/dwc_eth_qos.c
index 0d0053128542..97d64bfed465 100644
--- a/drivers/net/ethernet/synopsys/dwc_eth_qos.c
+++ b/drivers/net/ethernet/synopsys/dwc_eth_qos.c
@@ -33,7 +33,6 @@
33#include <linux/stat.h> 33#include <linux/stat.h>
34#include <linux/types.h> 34#include <linux/types.h>
35 35
36#include <linux/types.h>
37#include <linux/slab.h> 36#include <linux/slab.h>
38#include <linux/delay.h> 37#include <linux/delay.h>
39#include <linux/mm.h> 38#include <linux/mm.h>
@@ -43,7 +42,6 @@
43 42
44#include <linux/phy.h> 43#include <linux/phy.h>
45#include <linux/mii.h> 44#include <linux/mii.h>
46#include <linux/delay.h>
47#include <linux/dma-mapping.h> 45#include <linux/dma-mapping.h>
48#include <linux/vmalloc.h> 46#include <linux/vmalloc.h>
49 47
@@ -982,11 +980,13 @@ static int dwceqos_mii_probe(struct net_device *ndev)
982 if (netif_msg_probe(lp)) 980 if (netif_msg_probe(lp))
983 phy_attached_info(phydev); 981 phy_attached_info(phydev);
984 982
985 phydev->supported &= PHY_GBIT_FEATURES; 983 phydev->supported &= PHY_GBIT_FEATURES | SUPPORTED_Pause |
984 SUPPORTED_Asym_Pause;
986 985
987 lp->link = 0; 986 lp->link = 0;
988 lp->speed = 0; 987 lp->speed = 0;
989 lp->duplex = DUPLEX_UNKNOWN; 988 lp->duplex = DUPLEX_UNKNOWN;
989 lp->flowcontrol.autoneg = AUTONEG_ENABLE;
990 990
991 return 0; 991 return 0;
992} 992}
@@ -2881,7 +2881,7 @@ static int dwceqos_probe(struct platform_device *pdev)
2881 ret = of_get_phy_mode(lp->pdev->dev.of_node); 2881 ret = of_get_phy_mode(lp->pdev->dev.of_node);
2882 if (ret < 0) { 2882 if (ret < 0) {
2883 dev_err(&lp->pdev->dev, "error in getting phy i/f\n"); 2883 dev_err(&lp->pdev->dev, "error in getting phy i/f\n");
2884 goto err_out_clk_dis_phy; 2884 goto err_out_deregister_fixed_link;
2885 } 2885 }
2886 2886
2887 lp->phy_interface = ret; 2887 lp->phy_interface = ret;
@@ -2889,14 +2889,14 @@ static int dwceqos_probe(struct platform_device *pdev)
2889 ret = dwceqos_mii_init(lp); 2889 ret = dwceqos_mii_init(lp);
2890 if (ret) { 2890 if (ret) {
2891 dev_err(&lp->pdev->dev, "error in dwceqos_mii_init\n"); 2891 dev_err(&lp->pdev->dev, "error in dwceqos_mii_init\n");
2892 goto err_out_clk_dis_phy; 2892 goto err_out_deregister_fixed_link;
2893 } 2893 }
2894 2894
2895 ret = dwceqos_mii_probe(ndev); 2895 ret = dwceqos_mii_probe(ndev);
2896 if (ret != 0) { 2896 if (ret != 0) {
2897 netdev_err(ndev, "mii_probe fail.\n"); 2897 netdev_err(ndev, "mii_probe fail.\n");
2898 ret = -ENXIO; 2898 ret = -ENXIO;
2899 goto err_out_clk_dis_phy; 2899 goto err_out_deregister_fixed_link;
2900 } 2900 }
2901 2901
2902 dwceqos_set_umac_addr(lp, lp->ndev->dev_addr, 0); 2902 dwceqos_set_umac_addr(lp, lp->ndev->dev_addr, 0);
@@ -2914,7 +2914,7 @@ static int dwceqos_probe(struct platform_device *pdev)
2914 if (ret) { 2914 if (ret) {
2915 dev_err(&lp->pdev->dev, "Unable to retrieve DT, error %d\n", 2915 dev_err(&lp->pdev->dev, "Unable to retrieve DT, error %d\n",
2916 ret); 2916 ret);
2917 goto err_out_clk_dis_phy; 2917 goto err_out_deregister_fixed_link;
2918 } 2918 }
2919 dev_info(&lp->pdev->dev, "pdev->id %d, baseaddr 0x%08lx, irq %d\n", 2919 dev_info(&lp->pdev->dev, "pdev->id %d, baseaddr 0x%08lx, irq %d\n",
2920 pdev->id, ndev->base_addr, ndev->irq); 2920 pdev->id, ndev->base_addr, ndev->irq);
@@ -2924,7 +2924,7 @@ static int dwceqos_probe(struct platform_device *pdev)
2924 if (ret) { 2924 if (ret) {
2925 dev_err(&lp->pdev->dev, "Unable to request IRQ %d, error %d\n", 2925 dev_err(&lp->pdev->dev, "Unable to request IRQ %d, error %d\n",
2926 ndev->irq, ret); 2926 ndev->irq, ret);
2927 goto err_out_clk_dis_phy; 2927 goto err_out_deregister_fixed_link;
2928 } 2928 }
2929 2929
2930 if (netif_msg_probe(lp)) 2930 if (netif_msg_probe(lp))
@@ -2935,11 +2935,14 @@ static int dwceqos_probe(struct platform_device *pdev)
2935 ret = register_netdev(ndev); 2935 ret = register_netdev(ndev);
2936 if (ret) { 2936 if (ret) {
2937 dev_err(&pdev->dev, "Cannot register net device, aborting.\n"); 2937 dev_err(&pdev->dev, "Cannot register net device, aborting.\n");
2938 goto err_out_clk_dis_phy; 2938 goto err_out_deregister_fixed_link;
2939 } 2939 }
2940 2940
2941 return 0; 2941 return 0;
2942 2942
2943err_out_deregister_fixed_link:
2944 if (of_phy_is_fixed_link(pdev->dev.of_node))
2945 of_phy_deregister_fixed_link(pdev->dev.of_node);
2943err_out_clk_dis_phy: 2946err_out_clk_dis_phy:
2944 clk_disable_unprepare(lp->phy_ref_clk); 2947 clk_disable_unprepare(lp->phy_ref_clk);
2945err_out_clk_dis_aper: 2948err_out_clk_dis_aper:
@@ -2959,8 +2962,11 @@ static int dwceqos_remove(struct platform_device *pdev)
2959 if (ndev) { 2962 if (ndev) {
2960 lp = netdev_priv(ndev); 2963 lp = netdev_priv(ndev);
2961 2964
2962 if (ndev->phydev) 2965 if (ndev->phydev) {
2963 phy_disconnect(ndev->phydev); 2966 phy_disconnect(ndev->phydev);
2967 if (of_phy_is_fixed_link(pdev->dev.of_node))
2968 of_phy_deregister_fixed_link(pdev->dev.of_node);
2969 }
2964 mdiobus_unregister(lp->mii_bus); 2970 mdiobus_unregister(lp->mii_bus);
2965 mdiobus_free(lp->mii_bus); 2971 mdiobus_free(lp->mii_bus);
2966 2972
diff --git a/drivers/net/ethernet/ti/cpmac.c b/drivers/net/ethernet/ti/cpmac.c
index fa0cfda24fd9..28097be2ff28 100644
--- a/drivers/net/ethernet/ti/cpmac.c
+++ b/drivers/net/ethernet/ti/cpmac.c
@@ -1113,6 +1113,7 @@ static int cpmac_probe(struct platform_device *pdev)
1113 if (!dev) 1113 if (!dev)
1114 return -ENOMEM; 1114 return -ENOMEM;
1115 1115
1116 SET_NETDEV_DEV(dev, &pdev->dev);
1116 platform_set_drvdata(pdev, dev); 1117 platform_set_drvdata(pdev, dev);
1117 priv = netdev_priv(dev); 1118 priv = netdev_priv(dev);
1118 1119
diff --git a/drivers/net/ethernet/ti/cpsw-phy-sel.c b/drivers/net/ethernet/ti/cpsw-phy-sel.c
index 054a8dd23dae..18013645e76c 100644
--- a/drivers/net/ethernet/ti/cpsw-phy-sel.c
+++ b/drivers/net/ethernet/ti/cpsw-phy-sel.c
@@ -81,6 +81,7 @@ static void cpsw_gmii_sel_am3352(struct cpsw_phy_sel_priv *priv,
81 }; 81 };
82 82
83 mask = GMII_SEL_MODE_MASK << (slave * 2) | BIT(slave + 6); 83 mask = GMII_SEL_MODE_MASK << (slave * 2) | BIT(slave + 6);
84 mask |= BIT(slave + 4);
84 mode <<= slave * 2; 85 mode <<= slave * 2;
85 86
86 if (priv->rmii_clock_external) { 87 if (priv->rmii_clock_external) {
@@ -176,9 +177,12 @@ void cpsw_phy_sel(struct device *dev, phy_interface_t phy_mode, int slave)
176 } 177 }
177 178
178 dev = bus_find_device(&platform_bus_type, NULL, node, match); 179 dev = bus_find_device(&platform_bus_type, NULL, node, match);
180 of_node_put(node);
179 priv = dev_get_drvdata(dev); 181 priv = dev_get_drvdata(dev);
180 182
181 priv->cpsw_phy_sel(priv, phy_mode, slave); 183 priv->cpsw_phy_sel(priv, phy_mode, slave);
184
185 put_device(dev);
182} 186}
183EXPORT_SYMBOL_GPL(cpsw_phy_sel); 187EXPORT_SYMBOL_GPL(cpsw_phy_sel);
184 188
diff --git a/drivers/net/ethernet/ti/cpsw.c b/drivers/net/ethernet/ti/cpsw.c
index c6cff3d2ff05..b9087b828eff 100644
--- a/drivers/net/ethernet/ti/cpsw.c
+++ b/drivers/net/ethernet/ti/cpsw.c
@@ -2375,8 +2375,11 @@ static int cpsw_probe_dt(struct cpsw_platform_data *data,
2375 * to the PHY is the Ethernet MAC DT node. 2375 * to the PHY is the Ethernet MAC DT node.
2376 */ 2376 */
2377 ret = of_phy_register_fixed_link(slave_node); 2377 ret = of_phy_register_fixed_link(slave_node);
2378 if (ret) 2378 if (ret) {
2379 if (ret != -EPROBE_DEFER)
2380 dev_err(&pdev->dev, "failed to register fixed-link phy: %d\n", ret);
2379 return ret; 2381 return ret;
2382 }
2380 slave_data->phy_node = of_node_get(slave_node); 2383 slave_data->phy_node = of_node_get(slave_node);
2381 } else if (parp) { 2384 } else if (parp) {
2382 u32 phyid; 2385 u32 phyid;
@@ -2397,6 +2400,7 @@ static int cpsw_probe_dt(struct cpsw_platform_data *data,
2397 } 2400 }
2398 snprintf(slave_data->phy_id, sizeof(slave_data->phy_id), 2401 snprintf(slave_data->phy_id, sizeof(slave_data->phy_id),
2399 PHY_ID_FMT, mdio->name, phyid); 2402 PHY_ID_FMT, mdio->name, phyid);
2403 put_device(&mdio->dev);
2400 } else { 2404 } else {
2401 dev_err(&pdev->dev, 2405 dev_err(&pdev->dev,
2402 "No slave[%d] phy_id, phy-handle, or fixed-link property\n", 2406 "No slave[%d] phy_id, phy-handle, or fixed-link property\n",
@@ -2440,6 +2444,34 @@ no_phy_slave:
2440 return 0; 2444 return 0;
2441} 2445}
2442 2446
2447static void cpsw_remove_dt(struct platform_device *pdev)
2448{
2449 struct net_device *ndev = platform_get_drvdata(pdev);
2450 struct cpsw_common *cpsw = ndev_to_cpsw(ndev);
2451 struct cpsw_platform_data *data = &cpsw->data;
2452 struct device_node *node = pdev->dev.of_node;
2453 struct device_node *slave_node;
2454 int i = 0;
2455
2456 for_each_available_child_of_node(node, slave_node) {
2457 struct cpsw_slave_data *slave_data = &data->slave_data[i];
2458
2459 if (strcmp(slave_node->name, "slave"))
2460 continue;
2461
2462 if (of_phy_is_fixed_link(slave_node))
2463 of_phy_deregister_fixed_link(slave_node);
2464
2465 of_node_put(slave_data->phy_node);
2466
2467 i++;
2468 if (i == data->slaves)
2469 break;
2470 }
2471
2472 of_platform_depopulate(&pdev->dev);
2473}
2474
2443static int cpsw_probe_dual_emac(struct cpsw_priv *priv) 2475static int cpsw_probe_dual_emac(struct cpsw_priv *priv)
2444{ 2476{
2445 struct cpsw_common *cpsw = priv->cpsw; 2477 struct cpsw_common *cpsw = priv->cpsw;
@@ -2547,6 +2579,9 @@ static int cpsw_probe(struct platform_device *pdev)
2547 int irq; 2579 int irq;
2548 2580
2549 cpsw = devm_kzalloc(&pdev->dev, sizeof(struct cpsw_common), GFP_KERNEL); 2581 cpsw = devm_kzalloc(&pdev->dev, sizeof(struct cpsw_common), GFP_KERNEL);
2582 if (!cpsw)
2583 return -ENOMEM;
2584
2550 cpsw->dev = &pdev->dev; 2585 cpsw->dev = &pdev->dev;
2551 2586
2552 ndev = alloc_etherdev_mq(sizeof(struct cpsw_priv), CPSW_MAX_QUEUES); 2587 ndev = alloc_etherdev_mq(sizeof(struct cpsw_priv), CPSW_MAX_QUEUES);
@@ -2584,11 +2619,19 @@ static int cpsw_probe(struct platform_device *pdev)
2584 /* Select default pin state */ 2619 /* Select default pin state */
2585 pinctrl_pm_select_default_state(&pdev->dev); 2620 pinctrl_pm_select_default_state(&pdev->dev);
2586 2621
2587 if (cpsw_probe_dt(&cpsw->data, pdev)) { 2622 /* Need to enable clocks with runtime PM api to access module
2588 dev_err(&pdev->dev, "cpsw: platform data missing\n"); 2623 * registers
2589 ret = -ENODEV; 2624 */
2625 ret = pm_runtime_get_sync(&pdev->dev);
2626 if (ret < 0) {
2627 pm_runtime_put_noidle(&pdev->dev);
2590 goto clean_runtime_disable_ret; 2628 goto clean_runtime_disable_ret;
2591 } 2629 }
2630
2631 ret = cpsw_probe_dt(&cpsw->data, pdev);
2632 if (ret)
2633 goto clean_dt_ret;
2634
2592 data = &cpsw->data; 2635 data = &cpsw->data;
2593 cpsw->rx_ch_num = 1; 2636 cpsw->rx_ch_num = 1;
2594 cpsw->tx_ch_num = 1; 2637 cpsw->tx_ch_num = 1;
@@ -2608,7 +2651,7 @@ static int cpsw_probe(struct platform_device *pdev)
2608 GFP_KERNEL); 2651 GFP_KERNEL);
2609 if (!cpsw->slaves) { 2652 if (!cpsw->slaves) {
2610 ret = -ENOMEM; 2653 ret = -ENOMEM;
2611 goto clean_runtime_disable_ret; 2654 goto clean_dt_ret;
2612 } 2655 }
2613 for (i = 0; i < data->slaves; i++) 2656 for (i = 0; i < data->slaves; i++)
2614 cpsw->slaves[i].slave_num = i; 2657 cpsw->slaves[i].slave_num = i;
@@ -2620,7 +2663,7 @@ static int cpsw_probe(struct platform_device *pdev)
2620 if (IS_ERR(clk)) { 2663 if (IS_ERR(clk)) {
2621 dev_err(priv->dev, "fck is not found\n"); 2664 dev_err(priv->dev, "fck is not found\n");
2622 ret = -ENODEV; 2665 ret = -ENODEV;
2623 goto clean_runtime_disable_ret; 2666 goto clean_dt_ret;
2624 } 2667 }
2625 cpsw->bus_freq_mhz = clk_get_rate(clk) / 1000000; 2668 cpsw->bus_freq_mhz = clk_get_rate(clk) / 1000000;
2626 2669
@@ -2628,26 +2671,17 @@ static int cpsw_probe(struct platform_device *pdev)
2628 ss_regs = devm_ioremap_resource(&pdev->dev, ss_res); 2671 ss_regs = devm_ioremap_resource(&pdev->dev, ss_res);
2629 if (IS_ERR(ss_regs)) { 2672 if (IS_ERR(ss_regs)) {
2630 ret = PTR_ERR(ss_regs); 2673 ret = PTR_ERR(ss_regs);
2631 goto clean_runtime_disable_ret; 2674 goto clean_dt_ret;
2632 } 2675 }
2633 cpsw->regs = ss_regs; 2676 cpsw->regs = ss_regs;
2634 2677
2635 /* Need to enable clocks with runtime PM api to access module
2636 * registers
2637 */
2638 ret = pm_runtime_get_sync(&pdev->dev);
2639 if (ret < 0) {
2640 pm_runtime_put_noidle(&pdev->dev);
2641 goto clean_runtime_disable_ret;
2642 }
2643 cpsw->version = readl(&cpsw->regs->id_ver); 2678 cpsw->version = readl(&cpsw->regs->id_ver);
2644 pm_runtime_put_sync(&pdev->dev);
2645 2679
2646 res = platform_get_resource(pdev, IORESOURCE_MEM, 1); 2680 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
2647 cpsw->wr_regs = devm_ioremap_resource(&pdev->dev, res); 2681 cpsw->wr_regs = devm_ioremap_resource(&pdev->dev, res);
2648 if (IS_ERR(cpsw->wr_regs)) { 2682 if (IS_ERR(cpsw->wr_regs)) {
2649 ret = PTR_ERR(cpsw->wr_regs); 2683 ret = PTR_ERR(cpsw->wr_regs);
2650 goto clean_runtime_disable_ret; 2684 goto clean_dt_ret;
2651 } 2685 }
2652 2686
2653 memset(&dma_params, 0, sizeof(dma_params)); 2687 memset(&dma_params, 0, sizeof(dma_params));
@@ -2684,7 +2718,7 @@ static int cpsw_probe(struct platform_device *pdev)
2684 default: 2718 default:
2685 dev_err(priv->dev, "unknown version 0x%08x\n", cpsw->version); 2719 dev_err(priv->dev, "unknown version 0x%08x\n", cpsw->version);
2686 ret = -ENODEV; 2720 ret = -ENODEV;
2687 goto clean_runtime_disable_ret; 2721 goto clean_dt_ret;
2688 } 2722 }
2689 for (i = 0; i < cpsw->data.slaves; i++) { 2723 for (i = 0; i < cpsw->data.slaves; i++) {
2690 struct cpsw_slave *slave = &cpsw->slaves[i]; 2724 struct cpsw_slave *slave = &cpsw->slaves[i];
@@ -2713,7 +2747,7 @@ static int cpsw_probe(struct platform_device *pdev)
2713 if (!cpsw->dma) { 2747 if (!cpsw->dma) {
2714 dev_err(priv->dev, "error initializing dma\n"); 2748 dev_err(priv->dev, "error initializing dma\n");
2715 ret = -ENOMEM; 2749 ret = -ENOMEM;
2716 goto clean_runtime_disable_ret; 2750 goto clean_dt_ret;
2717 } 2751 }
2718 2752
2719 cpsw->txch[0] = cpdma_chan_create(cpsw->dma, 0, cpsw_tx_handler, 0); 2753 cpsw->txch[0] = cpdma_chan_create(cpsw->dma, 0, cpsw_tx_handler, 0);
@@ -2811,16 +2845,23 @@ static int cpsw_probe(struct platform_device *pdev)
2811 ret = cpsw_probe_dual_emac(priv); 2845 ret = cpsw_probe_dual_emac(priv);
2812 if (ret) { 2846 if (ret) {
2813 cpsw_err(priv, probe, "error probe slave 2 emac interface\n"); 2847 cpsw_err(priv, probe, "error probe slave 2 emac interface\n");
2814 goto clean_ale_ret; 2848 goto clean_unregister_netdev_ret;
2815 } 2849 }
2816 } 2850 }
2817 2851
2852 pm_runtime_put(&pdev->dev);
2853
2818 return 0; 2854 return 0;
2819 2855
2856clean_unregister_netdev_ret:
2857 unregister_netdev(ndev);
2820clean_ale_ret: 2858clean_ale_ret:
2821 cpsw_ale_destroy(cpsw->ale); 2859 cpsw_ale_destroy(cpsw->ale);
2822clean_dma_ret: 2860clean_dma_ret:
2823 cpdma_ctlr_destroy(cpsw->dma); 2861 cpdma_ctlr_destroy(cpsw->dma);
2862clean_dt_ret:
2863 cpsw_remove_dt(pdev);
2864 pm_runtime_put_sync(&pdev->dev);
2824clean_runtime_disable_ret: 2865clean_runtime_disable_ret:
2825 pm_runtime_disable(&pdev->dev); 2866 pm_runtime_disable(&pdev->dev);
2826clean_ndev_ret: 2867clean_ndev_ret:
@@ -2846,7 +2887,7 @@ static int cpsw_remove(struct platform_device *pdev)
2846 2887
2847 cpsw_ale_destroy(cpsw->ale); 2888 cpsw_ale_destroy(cpsw->ale);
2848 cpdma_ctlr_destroy(cpsw->dma); 2889 cpdma_ctlr_destroy(cpsw->dma);
2849 of_platform_depopulate(&pdev->dev); 2890 cpsw_remove_dt(pdev);
2850 pm_runtime_put_sync(&pdev->dev); 2891 pm_runtime_put_sync(&pdev->dev);
2851 pm_runtime_disable(&pdev->dev); 2892 pm_runtime_disable(&pdev->dev);
2852 if (cpsw->data.dual_emac) 2893 if (cpsw->data.dual_emac)
@@ -2889,6 +2930,8 @@ static int cpsw_resume(struct device *dev)
2889 /* Select default pin state */ 2930 /* Select default pin state */
2890 pinctrl_pm_select_default_state(dev); 2931 pinctrl_pm_select_default_state(dev);
2891 2932
2933 /* shut up ASSERT_RTNL() warning in netif_set_real_num_tx/rx_queues */
2934 rtnl_lock();
2892 if (cpsw->data.dual_emac) { 2935 if (cpsw->data.dual_emac) {
2893 int i; 2936 int i;
2894 2937
@@ -2900,6 +2943,8 @@ static int cpsw_resume(struct device *dev)
2900 if (netif_running(ndev)) 2943 if (netif_running(ndev))
2901 cpsw_ndo_open(ndev); 2944 cpsw_ndo_open(ndev);
2902 } 2945 }
2946 rtnl_unlock();
2947
2903 return 0; 2948 return 0;
2904} 2949}
2905#endif 2950#endif
diff --git a/drivers/net/ethernet/ti/davinci_emac.c b/drivers/net/ethernet/ti/davinci_emac.c
index 2fd94a5bc1f3..481c7bf0395b 100644
--- a/drivers/net/ethernet/ti/davinci_emac.c
+++ b/drivers/net/ethernet/ti/davinci_emac.c
@@ -1410,6 +1410,7 @@ static int emac_dev_open(struct net_device *ndev)
1410 int i = 0; 1410 int i = 0;
1411 struct emac_priv *priv = netdev_priv(ndev); 1411 struct emac_priv *priv = netdev_priv(ndev);
1412 struct phy_device *phydev = NULL; 1412 struct phy_device *phydev = NULL;
1413 struct device *phy = NULL;
1413 1414
1414 ret = pm_runtime_get_sync(&priv->pdev->dev); 1415 ret = pm_runtime_get_sync(&priv->pdev->dev);
1415 if (ret < 0) { 1416 if (ret < 0) {
@@ -1488,19 +1489,20 @@ static int emac_dev_open(struct net_device *ndev)
1488 1489
1489 /* use the first phy on the bus if pdata did not give us a phy id */ 1490 /* use the first phy on the bus if pdata did not give us a phy id */
1490 if (!phydev && !priv->phy_id) { 1491 if (!phydev && !priv->phy_id) {
1491 struct device *phy;
1492
1493 phy = bus_find_device(&mdio_bus_type, NULL, NULL, 1492 phy = bus_find_device(&mdio_bus_type, NULL, NULL,
1494 match_first_device); 1493 match_first_device);
1495 if (phy) 1494 if (phy) {
1496 priv->phy_id = dev_name(phy); 1495 priv->phy_id = dev_name(phy);
1496 if (!priv->phy_id || !*priv->phy_id)
1497 put_device(phy);
1498 }
1497 } 1499 }
1498 1500
1499 if (!phydev && priv->phy_id && *priv->phy_id) { 1501 if (!phydev && priv->phy_id && *priv->phy_id) {
1500 phydev = phy_connect(ndev, priv->phy_id, 1502 phydev = phy_connect(ndev, priv->phy_id,
1501 &emac_adjust_link, 1503 &emac_adjust_link,
1502 PHY_INTERFACE_MODE_MII); 1504 PHY_INTERFACE_MODE_MII);
1503 1505 put_device(phy); /* reference taken by bus_find_device */
1504 if (IS_ERR(phydev)) { 1506 if (IS_ERR(phydev)) {
1505 dev_err(emac_dev, "could not connect to phy %s\n", 1507 dev_err(emac_dev, "could not connect to phy %s\n",
1506 priv->phy_id); 1508 priv->phy_id);
@@ -1765,6 +1767,7 @@ static int davinci_emac_try_get_mac(struct platform_device *pdev,
1765 */ 1767 */
1766static int davinci_emac_probe(struct platform_device *pdev) 1768static int davinci_emac_probe(struct platform_device *pdev)
1767{ 1769{
1770 struct device_node *np = pdev->dev.of_node;
1768 int rc = 0; 1771 int rc = 0;
1769 struct resource *res, *res_ctrl; 1772 struct resource *res, *res_ctrl;
1770 struct net_device *ndev; 1773 struct net_device *ndev;
@@ -1803,7 +1806,7 @@ static int davinci_emac_probe(struct platform_device *pdev)
1803 if (!pdata) { 1806 if (!pdata) {
1804 dev_err(&pdev->dev, "no platform data\n"); 1807 dev_err(&pdev->dev, "no platform data\n");
1805 rc = -ENODEV; 1808 rc = -ENODEV;
1806 goto no_pdata; 1809 goto err_free_netdev;
1807 } 1810 }
1808 1811
1809 /* MAC addr and PHY mask , RMII enable info from platform_data */ 1812 /* MAC addr and PHY mask , RMII enable info from platform_data */
@@ -1939,6 +1942,10 @@ no_cpdma_chan:
1939 cpdma_chan_destroy(priv->rxchan); 1942 cpdma_chan_destroy(priv->rxchan);
1940 cpdma_ctlr_destroy(priv->dma); 1943 cpdma_ctlr_destroy(priv->dma);
1941no_pdata: 1944no_pdata:
1945 if (of_phy_is_fixed_link(np))
1946 of_phy_deregister_fixed_link(np);
1947 of_node_put(priv->phy_node);
1948err_free_netdev:
1942 free_netdev(ndev); 1949 free_netdev(ndev);
1943 return rc; 1950 return rc;
1944} 1951}
@@ -1954,6 +1961,7 @@ static int davinci_emac_remove(struct platform_device *pdev)
1954{ 1961{
1955 struct net_device *ndev = platform_get_drvdata(pdev); 1962 struct net_device *ndev = platform_get_drvdata(pdev);
1956 struct emac_priv *priv = netdev_priv(ndev); 1963 struct emac_priv *priv = netdev_priv(ndev);
1964 struct device_node *np = pdev->dev.of_node;
1957 1965
1958 dev_notice(&ndev->dev, "DaVinci EMAC: davinci_emac_remove()\n"); 1966 dev_notice(&ndev->dev, "DaVinci EMAC: davinci_emac_remove()\n");
1959 1967
@@ -1966,6 +1974,8 @@ static int davinci_emac_remove(struct platform_device *pdev)
1966 unregister_netdev(ndev); 1974 unregister_netdev(ndev);
1967 of_node_put(priv->phy_node); 1975 of_node_put(priv->phy_node);
1968 pm_runtime_disable(&pdev->dev); 1976 pm_runtime_disable(&pdev->dev);
1977 if (of_phy_is_fixed_link(np))
1978 of_phy_deregister_fixed_link(np);
1969 free_netdev(ndev); 1979 free_netdev(ndev);
1970 1980
1971 return 0; 1981 return 0;
diff --git a/drivers/net/ethernet/toshiba/ps3_gelic_wireless.c b/drivers/net/ethernet/toshiba/ps3_gelic_wireless.c
index 446ea580ad42..928c1dca2673 100644
--- a/drivers/net/ethernet/toshiba/ps3_gelic_wireless.c
+++ b/drivers/net/ethernet/toshiba/ps3_gelic_wireless.c
@@ -1694,7 +1694,7 @@ struct gelic_wl_scan_info *gelic_wl_find_best_bss(struct gelic_wl_info *wl)
1694 pr_debug("%s: bssid matched\n", __func__); 1694 pr_debug("%s: bssid matched\n", __func__);
1695 break; 1695 break;
1696 } else { 1696 } else {
1697 pr_debug("%s: bssid unmached\n", __func__); 1697 pr_debug("%s: bssid unmatched\n", __func__);
1698 continue; 1698 continue;
1699 } 1699 }
1700 } 1700 }
diff --git a/drivers/net/ethernet/xscale/ixp4xx_eth.c b/drivers/net/ethernet/xscale/ixp4xx_eth.c
index 7f127dc1b7ba..fa32391720fe 100644
--- a/drivers/net/ethernet/xscale/ixp4xx_eth.c
+++ b/drivers/net/ethernet/xscale/ixp4xx_eth.c
@@ -708,8 +708,7 @@ static int eth_poll(struct napi_struct *napi, int budget)
708 if (!qmgr_stat_below_low_watermark(rxq) && 708 if (!qmgr_stat_below_low_watermark(rxq) &&
709 napi_reschedule(napi)) { /* not empty again */ 709 napi_reschedule(napi)) { /* not empty again */
710#if DEBUG_RX 710#if DEBUG_RX
711 printk(KERN_DEBUG "%s: eth_poll" 711 printk(KERN_DEBUG "%s: eth_poll napi_reschedule succeeded\n",
712 " napi_reschedule successed\n",
713 dev->name); 712 dev->name);
714#endif 713#endif
715 qmgr_disable_irq(rxq); 714 qmgr_disable_irq(rxq);
diff --git a/drivers/net/geneve.c b/drivers/net/geneve.c
index 3c20e87bb761..8b4822ad27cb 100644
--- a/drivers/net/geneve.c
+++ b/drivers/net/geneve.c
@@ -58,9 +58,9 @@ struct geneve_dev {
58 struct hlist_node hlist; /* vni hash table */ 58 struct hlist_node hlist; /* vni hash table */
59 struct net *net; /* netns for packet i/o */ 59 struct net *net; /* netns for packet i/o */
60 struct net_device *dev; /* netdev for geneve tunnel */ 60 struct net_device *dev; /* netdev for geneve tunnel */
61 struct geneve_sock *sock4; /* IPv4 socket used for geneve tunnel */ 61 struct geneve_sock __rcu *sock4; /* IPv4 socket used for geneve tunnel */
62#if IS_ENABLED(CONFIG_IPV6) 62#if IS_ENABLED(CONFIG_IPV6)
63 struct geneve_sock *sock6; /* IPv6 socket used for geneve tunnel */ 63 struct geneve_sock __rcu *sock6; /* IPv6 socket used for geneve tunnel */
64#endif 64#endif
65 u8 vni[3]; /* virtual network ID for tunnel */ 65 u8 vni[3]; /* virtual network ID for tunnel */
66 u8 ttl; /* TTL override */ 66 u8 ttl; /* TTL override */
@@ -453,7 +453,7 @@ static struct sk_buff **geneve_gro_receive(struct sock *sk,
453 453
454 skb_gro_pull(skb, gh_len); 454 skb_gro_pull(skb, gh_len);
455 skb_gro_postpull_rcsum(skb, gh, gh_len); 455 skb_gro_postpull_rcsum(skb, gh, gh_len);
456 pp = ptype->callbacks.gro_receive(head, skb); 456 pp = call_gro_receive(ptype->callbacks.gro_receive, head, skb);
457 flush = 0; 457 flush = 0;
458 458
459out_unlock: 459out_unlock:
@@ -543,9 +543,19 @@ static void __geneve_sock_release(struct geneve_sock *gs)
543 543
544static void geneve_sock_release(struct geneve_dev *geneve) 544static void geneve_sock_release(struct geneve_dev *geneve)
545{ 545{
546 __geneve_sock_release(geneve->sock4); 546 struct geneve_sock *gs4 = rtnl_dereference(geneve->sock4);
547#if IS_ENABLED(CONFIG_IPV6) 547#if IS_ENABLED(CONFIG_IPV6)
548 __geneve_sock_release(geneve->sock6); 548 struct geneve_sock *gs6 = rtnl_dereference(geneve->sock6);
549
550 rcu_assign_pointer(geneve->sock6, NULL);
551#endif
552
553 rcu_assign_pointer(geneve->sock4, NULL);
554 synchronize_net();
555
556 __geneve_sock_release(gs4);
557#if IS_ENABLED(CONFIG_IPV6)
558 __geneve_sock_release(gs6);
549#endif 559#endif
550} 560}
551 561
@@ -586,10 +596,10 @@ out:
586 gs->flags = geneve->flags; 596 gs->flags = geneve->flags;
587#if IS_ENABLED(CONFIG_IPV6) 597#if IS_ENABLED(CONFIG_IPV6)
588 if (ipv6) 598 if (ipv6)
589 geneve->sock6 = gs; 599 rcu_assign_pointer(geneve->sock6, gs);
590 else 600 else
591#endif 601#endif
592 geneve->sock4 = gs; 602 rcu_assign_pointer(geneve->sock4, gs);
593 603
594 hash = geneve_net_vni_hash(geneve->vni); 604 hash = geneve_net_vni_hash(geneve->vni);
595 hlist_add_head_rcu(&geneve->hlist, &gs->vni_list[hash]); 605 hlist_add_head_rcu(&geneve->hlist, &gs->vni_list[hash]);
@@ -603,9 +613,7 @@ static int geneve_open(struct net_device *dev)
603 bool metadata = geneve->collect_md; 613 bool metadata = geneve->collect_md;
604 int ret = 0; 614 int ret = 0;
605 615
606 geneve->sock4 = NULL;
607#if IS_ENABLED(CONFIG_IPV6) 616#if IS_ENABLED(CONFIG_IPV6)
608 geneve->sock6 = NULL;
609 if (ipv6 || metadata) 617 if (ipv6 || metadata)
610 ret = geneve_sock_add(geneve, true); 618 ret = geneve_sock_add(geneve, true);
611#endif 619#endif
@@ -720,6 +728,9 @@ static struct rtable *geneve_get_v4_rt(struct sk_buff *skb,
720 struct rtable *rt = NULL; 728 struct rtable *rt = NULL;
721 __u8 tos; 729 __u8 tos;
722 730
731 if (!rcu_dereference(geneve->sock4))
732 return ERR_PTR(-EIO);
733
723 memset(fl4, 0, sizeof(*fl4)); 734 memset(fl4, 0, sizeof(*fl4));
724 fl4->flowi4_mark = skb->mark; 735 fl4->flowi4_mark = skb->mark;
725 fl4->flowi4_proto = IPPROTO_UDP; 736 fl4->flowi4_proto = IPPROTO_UDP;
@@ -772,11 +783,15 @@ static struct dst_entry *geneve_get_v6_dst(struct sk_buff *skb,
772{ 783{
773 bool use_cache = ip_tunnel_dst_cache_usable(skb, info); 784 bool use_cache = ip_tunnel_dst_cache_usable(skb, info);
774 struct geneve_dev *geneve = netdev_priv(dev); 785 struct geneve_dev *geneve = netdev_priv(dev);
775 struct geneve_sock *gs6 = geneve->sock6;
776 struct dst_entry *dst = NULL; 786 struct dst_entry *dst = NULL;
777 struct dst_cache *dst_cache; 787 struct dst_cache *dst_cache;
788 struct geneve_sock *gs6;
778 __u8 prio; 789 __u8 prio;
779 790
791 gs6 = rcu_dereference(geneve->sock6);
792 if (!gs6)
793 return ERR_PTR(-EIO);
794
780 memset(fl6, 0, sizeof(*fl6)); 795 memset(fl6, 0, sizeof(*fl6));
781 fl6->flowi6_mark = skb->mark; 796 fl6->flowi6_mark = skb->mark;
782 fl6->flowi6_proto = IPPROTO_UDP; 797 fl6->flowi6_proto = IPPROTO_UDP;
@@ -842,9 +857,8 @@ static netdev_tx_t geneve_xmit_skb(struct sk_buff *skb, struct net_device *dev,
842 struct ip_tunnel_info *info) 857 struct ip_tunnel_info *info)
843{ 858{
844 struct geneve_dev *geneve = netdev_priv(dev); 859 struct geneve_dev *geneve = netdev_priv(dev);
845 struct geneve_sock *gs4 = geneve->sock4; 860 struct geneve_sock *gs4;
846 struct rtable *rt = NULL; 861 struct rtable *rt = NULL;
847 const struct iphdr *iip; /* interior IP header */
848 int err = -EINVAL; 862 int err = -EINVAL;
849 struct flowi4 fl4; 863 struct flowi4 fl4;
850 __u8 tos, ttl; 864 __u8 tos, ttl;
@@ -853,6 +867,10 @@ static netdev_tx_t geneve_xmit_skb(struct sk_buff *skb, struct net_device *dev,
853 bool xnet = !net_eq(geneve->net, dev_net(geneve->dev)); 867 bool xnet = !net_eq(geneve->net, dev_net(geneve->dev));
854 u32 flags = geneve->flags; 868 u32 flags = geneve->flags;
855 869
870 gs4 = rcu_dereference(geneve->sock4);
871 if (!gs4)
872 goto tx_error;
873
856 if (geneve->collect_md) { 874 if (geneve->collect_md) {
857 if (unlikely(!info || !(info->mode & IP_TUNNEL_INFO_TX))) { 875 if (unlikely(!info || !(info->mode & IP_TUNNEL_INFO_TX))) {
858 netdev_dbg(dev, "no tunnel metadata\n"); 876 netdev_dbg(dev, "no tunnel metadata\n");
@@ -871,8 +889,6 @@ static netdev_tx_t geneve_xmit_skb(struct sk_buff *skb, struct net_device *dev,
871 sport = udp_flow_src_port(geneve->net, skb, 1, USHRT_MAX, true); 889 sport = udp_flow_src_port(geneve->net, skb, 1, USHRT_MAX, true);
872 skb_reset_mac_header(skb); 890 skb_reset_mac_header(skb);
873 891
874 iip = ip_hdr(skb);
875
876 if (info) { 892 if (info) {
877 const struct ip_tunnel_key *key = &info->key; 893 const struct ip_tunnel_key *key = &info->key;
878 u8 *opts = NULL; 894 u8 *opts = NULL;
@@ -892,7 +908,7 @@ static netdev_tx_t geneve_xmit_skb(struct sk_buff *skb, struct net_device *dev,
892 if (unlikely(err)) 908 if (unlikely(err))
893 goto tx_error; 909 goto tx_error;
894 910
895 tos = ip_tunnel_ecn_encap(key->tos, iip, skb); 911 tos = ip_tunnel_ecn_encap(key->tos, ip_hdr(skb), skb);
896 ttl = key->ttl; 912 ttl = key->ttl;
897 df = key->tun_flags & TUNNEL_DONT_FRAGMENT ? htons(IP_DF) : 0; 913 df = key->tun_flags & TUNNEL_DONT_FRAGMENT ? htons(IP_DF) : 0;
898 } else { 914 } else {
@@ -901,7 +917,7 @@ static netdev_tx_t geneve_xmit_skb(struct sk_buff *skb, struct net_device *dev,
901 if (unlikely(err)) 917 if (unlikely(err))
902 goto tx_error; 918 goto tx_error;
903 919
904 tos = ip_tunnel_ecn_encap(fl4.flowi4_tos, iip, skb); 920 tos = ip_tunnel_ecn_encap(fl4.flowi4_tos, ip_hdr(skb), skb);
905 ttl = geneve->ttl; 921 ttl = geneve->ttl;
906 if (!ttl && IN_MULTICAST(ntohl(fl4.daddr))) 922 if (!ttl && IN_MULTICAST(ntohl(fl4.daddr)))
907 ttl = 1; 923 ttl = 1;
@@ -932,9 +948,8 @@ static netdev_tx_t geneve6_xmit_skb(struct sk_buff *skb, struct net_device *dev,
932 struct ip_tunnel_info *info) 948 struct ip_tunnel_info *info)
933{ 949{
934 struct geneve_dev *geneve = netdev_priv(dev); 950 struct geneve_dev *geneve = netdev_priv(dev);
935 struct geneve_sock *gs6 = geneve->sock6;
936 struct dst_entry *dst = NULL; 951 struct dst_entry *dst = NULL;
937 const struct iphdr *iip; /* interior IP header */ 952 struct geneve_sock *gs6;
938 int err = -EINVAL; 953 int err = -EINVAL;
939 struct flowi6 fl6; 954 struct flowi6 fl6;
940 __u8 prio, ttl; 955 __u8 prio, ttl;
@@ -943,6 +958,10 @@ static netdev_tx_t geneve6_xmit_skb(struct sk_buff *skb, struct net_device *dev,
943 bool xnet = !net_eq(geneve->net, dev_net(geneve->dev)); 958 bool xnet = !net_eq(geneve->net, dev_net(geneve->dev));
944 u32 flags = geneve->flags; 959 u32 flags = geneve->flags;
945 960
961 gs6 = rcu_dereference(geneve->sock6);
962 if (!gs6)
963 goto tx_error;
964
946 if (geneve->collect_md) { 965 if (geneve->collect_md) {
947 if (unlikely(!info || !(info->mode & IP_TUNNEL_INFO_TX))) { 966 if (unlikely(!info || !(info->mode & IP_TUNNEL_INFO_TX))) {
948 netdev_dbg(dev, "no tunnel metadata\n"); 967 netdev_dbg(dev, "no tunnel metadata\n");
@@ -959,8 +978,6 @@ static netdev_tx_t geneve6_xmit_skb(struct sk_buff *skb, struct net_device *dev,
959 sport = udp_flow_src_port(geneve->net, skb, 1, USHRT_MAX, true); 978 sport = udp_flow_src_port(geneve->net, skb, 1, USHRT_MAX, true);
960 skb_reset_mac_header(skb); 979 skb_reset_mac_header(skb);
961 980
962 iip = ip_hdr(skb);
963
964 if (info) { 981 if (info) {
965 const struct ip_tunnel_key *key = &info->key; 982 const struct ip_tunnel_key *key = &info->key;
966 u8 *opts = NULL; 983 u8 *opts = NULL;
@@ -981,7 +998,7 @@ static netdev_tx_t geneve6_xmit_skb(struct sk_buff *skb, struct net_device *dev,
981 if (unlikely(err)) 998 if (unlikely(err))
982 goto tx_error; 999 goto tx_error;
983 1000
984 prio = ip_tunnel_ecn_encap(key->tos, iip, skb); 1001 prio = ip_tunnel_ecn_encap(key->tos, ip_hdr(skb), skb);
985 ttl = key->ttl; 1002 ttl = key->ttl;
986 label = info->key.label; 1003 label = info->key.label;
987 } else { 1004 } else {
@@ -991,7 +1008,7 @@ static netdev_tx_t geneve6_xmit_skb(struct sk_buff *skb, struct net_device *dev,
991 goto tx_error; 1008 goto tx_error;
992 1009
993 prio = ip_tunnel_ecn_encap(ip6_tclass(fl6.flowlabel), 1010 prio = ip_tunnel_ecn_encap(ip6_tclass(fl6.flowlabel),
994 iip, skb); 1011 ip_hdr(skb), skb);
995 ttl = geneve->ttl; 1012 ttl = geneve->ttl;
996 if (!ttl && ipv6_addr_is_multicast(&fl6.daddr)) 1013 if (!ttl && ipv6_addr_is_multicast(&fl6.daddr))
997 ttl = 1; 1014 ttl = 1;
diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c
index f0919bd3a563..c9140c3aeb67 100644
--- a/drivers/net/hyperv/netvsc_drv.c
+++ b/drivers/net/hyperv/netvsc_drv.c
@@ -47,6 +47,10 @@
47 NETIF_F_TSO | \ 47 NETIF_F_TSO | \
48 NETIF_F_TSO6 | \ 48 NETIF_F_TSO6 | \
49 NETIF_F_HW_CSUM) 49 NETIF_F_HW_CSUM)
50
51/* Restrict GSO size to account for NVGRE */
52#define NETVSC_GSO_MAX_SIZE 62768
53
50static int ring_size = 128; 54static int ring_size = 128;
51module_param(ring_size, int, S_IRUGO); 55module_param(ring_size, int, S_IRUGO);
52MODULE_PARM_DESC(ring_size, "Ring buffer size (# of pages)"); 56MODULE_PARM_DESC(ring_size, "Ring buffer size (# of pages)");
@@ -447,7 +451,7 @@ static int netvsc_start_xmit(struct sk_buff *skb, struct net_device *net)
447 * Setup the sendside checksum offload only if this is not a 451 * Setup the sendside checksum offload only if this is not a
448 * GSO packet. 452 * GSO packet.
449 */ 453 */
450 if (skb_is_gso(skb)) { 454 if ((net_trans_info & (INFO_TCP | INFO_UDP)) && skb_is_gso(skb)) {
451 struct ndis_tcp_lso_info *lso_info; 455 struct ndis_tcp_lso_info *lso_info;
452 456
453 rndis_msg_size += NDIS_LSO_PPI_SIZE; 457 rndis_msg_size += NDIS_LSO_PPI_SIZE;
@@ -607,15 +611,18 @@ static struct sk_buff *netvsc_alloc_recv_skb(struct net_device *net,
607 packet->total_data_buflen); 611 packet->total_data_buflen);
608 612
609 skb->protocol = eth_type_trans(skb, net); 613 skb->protocol = eth_type_trans(skb, net);
610 if (csum_info) { 614
611 /* We only look at the IP checksum here. 615 /* skb is already created with CHECKSUM_NONE */
612 * Should we be dropping the packet if checksum 616 skb_checksum_none_assert(skb);
613 * failed? How do we deal with other checksums - TCP/UDP? 617
614 */ 618 /*
615 if (csum_info->receive.ip_checksum_succeeded) 619 * In Linux, the IP checksum is always checked.
620 * Do L4 checksum offload if enabled and present.
621 */
622 if (csum_info && (net->features & NETIF_F_RXCSUM)) {
623 if (csum_info->receive.tcp_checksum_succeeded ||
624 csum_info->receive.udp_checksum_succeeded)
616 skb->ip_summed = CHECKSUM_UNNECESSARY; 625 skb->ip_summed = CHECKSUM_UNNECESSARY;
617 else
618 skb->ip_summed = CHECKSUM_NONE;
619 } 626 }
620 627
621 if (vlan_tci & VLAN_TAG_PRESENT) 628 if (vlan_tci & VLAN_TAG_PRESENT)
@@ -696,12 +703,8 @@ int netvsc_recv_callback(struct hv_device *device_obj,
696static void netvsc_get_drvinfo(struct net_device *net, 703static void netvsc_get_drvinfo(struct net_device *net,
697 struct ethtool_drvinfo *info) 704 struct ethtool_drvinfo *info)
698{ 705{
699 struct net_device_context *net_device_ctx = netdev_priv(net);
700 struct hv_device *dev = net_device_ctx->device_ctx;
701
702 strlcpy(info->driver, KBUILD_MODNAME, sizeof(info->driver)); 706 strlcpy(info->driver, KBUILD_MODNAME, sizeof(info->driver));
703 strlcpy(info->fw_version, "N/A", sizeof(info->fw_version)); 707 strlcpy(info->fw_version, "N/A", sizeof(info->fw_version));
704 strlcpy(info->bus_info, vmbus_dev_name(dev), sizeof(info->bus_info));
705} 708}
706 709
707static void netvsc_get_channels(struct net_device *net, 710static void netvsc_get_channels(struct net_device *net,
@@ -1401,6 +1404,7 @@ static int netvsc_probe(struct hv_device *dev,
1401 nvdev = net_device_ctx->nvdev; 1404 nvdev = net_device_ctx->nvdev;
1402 netif_set_real_num_tx_queues(net, nvdev->num_chn); 1405 netif_set_real_num_tx_queues(net, nvdev->num_chn);
1403 netif_set_real_num_rx_queues(net, nvdev->num_chn); 1406 netif_set_real_num_rx_queues(net, nvdev->num_chn);
1407 netif_set_gso_max_size(net, NETVSC_GSO_MAX_SIZE);
1404 1408
1405 ret = register_netdev(net); 1409 ret = register_netdev(net);
1406 if (ret != 0) { 1410 if (ret != 0) {
diff --git a/drivers/net/ieee802154/adf7242.c b/drivers/net/ieee802154/adf7242.c
index 9fa7ac9f8e68..f355df7cf84a 100644
--- a/drivers/net/ieee802154/adf7242.c
+++ b/drivers/net/ieee802154/adf7242.c
@@ -20,7 +20,6 @@
20#include <linux/skbuff.h> 20#include <linux/skbuff.h>
21#include <linux/of.h> 21#include <linux/of.h>
22#include <linux/irq.h> 22#include <linux/irq.h>
23#include <linux/delay.h>
24#include <linux/debugfs.h> 23#include <linux/debugfs.h>
25#include <linux/bitops.h> 24#include <linux/bitops.h>
26#include <linux/ieee802154.h> 25#include <linux/ieee802154.h>
diff --git a/drivers/net/ipvlan/ipvlan_main.c b/drivers/net/ipvlan/ipvlan_main.c
index f442eb366863..dfbc4ef6d507 100644
--- a/drivers/net/ipvlan/ipvlan_main.c
+++ b/drivers/net/ipvlan/ipvlan_main.c
@@ -497,6 +497,7 @@ static int ipvlan_link_new(struct net *src_net, struct net_device *dev,
497 struct net_device *phy_dev; 497 struct net_device *phy_dev;
498 int err; 498 int err;
499 u16 mode = IPVLAN_MODE_L3; 499 u16 mode = IPVLAN_MODE_L3;
500 bool create = false;
500 501
501 if (!tb[IFLA_LINK]) 502 if (!tb[IFLA_LINK])
502 return -EINVAL; 503 return -EINVAL;
@@ -513,6 +514,7 @@ static int ipvlan_link_new(struct net *src_net, struct net_device *dev,
513 err = ipvlan_port_create(phy_dev); 514 err = ipvlan_port_create(phy_dev);
514 if (err < 0) 515 if (err < 0)
515 return err; 516 return err;
517 create = true;
516 } 518 }
517 519
518 if (data && data[IFLA_IPVLAN_MODE]) 520 if (data && data[IFLA_IPVLAN_MODE])
@@ -536,22 +538,29 @@ static int ipvlan_link_new(struct net *src_net, struct net_device *dev,
536 538
537 err = register_netdevice(dev); 539 err = register_netdevice(dev);
538 if (err < 0) 540 if (err < 0)
539 return err; 541 goto destroy_ipvlan_port;
540 542
541 err = netdev_upper_dev_link(phy_dev, dev); 543 err = netdev_upper_dev_link(phy_dev, dev);
542 if (err) { 544 if (err) {
543 unregister_netdevice(dev); 545 goto unregister_netdev;
544 return err;
545 } 546 }
546 err = ipvlan_set_port_mode(port, mode); 547 err = ipvlan_set_port_mode(port, mode);
547 if (err) { 548 if (err) {
548 unregister_netdevice(dev); 549 goto unlink_netdev;
549 return err;
550 } 550 }
551 551
552 list_add_tail_rcu(&ipvlan->pnode, &port->ipvlans); 552 list_add_tail_rcu(&ipvlan->pnode, &port->ipvlans);
553 netif_stacked_transfer_operstate(phy_dev, dev); 553 netif_stacked_transfer_operstate(phy_dev, dev);
554 return 0; 554 return 0;
555
556unlink_netdev:
557 netdev_upper_dev_unlink(phy_dev, dev);
558unregister_netdev:
559 unregister_netdevice(dev);
560destroy_ipvlan_port:
561 if (create)
562 ipvlan_port_destroy(phy_dev);
563 return err;
555} 564}
556 565
557static void ipvlan_link_delete(struct net_device *dev, struct list_head *head) 566static void ipvlan_link_delete(struct net_device *dev, struct list_head *head)
diff --git a/drivers/net/irda/irda-usb.c b/drivers/net/irda/irda-usb.c
index a198946bc54f..8716b8c07feb 100644
--- a/drivers/net/irda/irda-usb.c
+++ b/drivers/net/irda/irda-usb.c
@@ -1723,6 +1723,7 @@ static int irda_usb_probe(struct usb_interface *intf,
1723 /* Don't change this buffer size and allocation without doing 1723 /* Don't change this buffer size and allocation without doing
1724 * some heavy and complete testing. Don't ask why :-( 1724 * some heavy and complete testing. Don't ask why :-(
1725 * Jean II */ 1725 * Jean II */
1726 ret = -ENOMEM;
1726 self->speed_buff = kzalloc(IRDA_USB_SPEED_MTU, GFP_KERNEL); 1727 self->speed_buff = kzalloc(IRDA_USB_SPEED_MTU, GFP_KERNEL);
1727 if (!self->speed_buff) 1728 if (!self->speed_buff)
1728 goto err_out_3; 1729 goto err_out_3;
diff --git a/drivers/net/irda/w83977af_ir.c b/drivers/net/irda/w83977af_ir.c
index 4e3d2e7c697c..e8c3a8c32534 100644
--- a/drivers/net/irda/w83977af_ir.c
+++ b/drivers/net/irda/w83977af_ir.c
@@ -518,7 +518,9 @@ static netdev_tx_t w83977af_hard_xmit(struct sk_buff *skb,
518 518
519 mtt = irda_get_mtt(skb); 519 mtt = irda_get_mtt(skb);
520 pr_debug("%s(%ld), mtt=%d\n", __func__ , jiffies, mtt); 520 pr_debug("%s(%ld), mtt=%d\n", __func__ , jiffies, mtt);
521 if (mtt) 521 if (mtt > 1000)
522 mdelay(mtt/1000);
523 else if (mtt)
522 udelay(mtt); 524 udelay(mtt);
523 525
524 /* Enable DMA interrupt */ 526 /* Enable DMA interrupt */
diff --git a/drivers/net/macsec.c b/drivers/net/macsec.c
index 3ea47f28e143..d2e61e002926 100644
--- a/drivers/net/macsec.c
+++ b/drivers/net/macsec.c
@@ -397,6 +397,14 @@ static struct macsec_cb *macsec_skb_cb(struct sk_buff *skb)
397#define DEFAULT_ENCRYPT false 397#define DEFAULT_ENCRYPT false
398#define DEFAULT_ENCODING_SA 0 398#define DEFAULT_ENCODING_SA 0
399 399
400static bool send_sci(const struct macsec_secy *secy)
401{
402 const struct macsec_tx_sc *tx_sc = &secy->tx_sc;
403
404 return tx_sc->send_sci ||
405 (secy->n_rx_sc > 1 && !tx_sc->end_station && !tx_sc->scb);
406}
407
400static sci_t make_sci(u8 *addr, __be16 port) 408static sci_t make_sci(u8 *addr, __be16 port)
401{ 409{
402 sci_t sci; 410 sci_t sci;
@@ -437,15 +445,15 @@ static unsigned int macsec_extra_len(bool sci_present)
437 445
438/* Fill SecTAG according to IEEE 802.1AE-2006 10.5.3 */ 446/* Fill SecTAG according to IEEE 802.1AE-2006 10.5.3 */
439static void macsec_fill_sectag(struct macsec_eth_header *h, 447static void macsec_fill_sectag(struct macsec_eth_header *h,
440 const struct macsec_secy *secy, u32 pn) 448 const struct macsec_secy *secy, u32 pn,
449 bool sci_present)
441{ 450{
442 const struct macsec_tx_sc *tx_sc = &secy->tx_sc; 451 const struct macsec_tx_sc *tx_sc = &secy->tx_sc;
443 452
444 memset(&h->tci_an, 0, macsec_sectag_len(tx_sc->send_sci)); 453 memset(&h->tci_an, 0, macsec_sectag_len(sci_present));
445 h->eth.h_proto = htons(ETH_P_MACSEC); 454 h->eth.h_proto = htons(ETH_P_MACSEC);
446 455
447 if (tx_sc->send_sci || 456 if (sci_present) {
448 (secy->n_rx_sc > 1 && !tx_sc->end_station && !tx_sc->scb)) {
449 h->tci_an |= MACSEC_TCI_SC; 457 h->tci_an |= MACSEC_TCI_SC;
450 memcpy(&h->secure_channel_id, &secy->sci, 458 memcpy(&h->secure_channel_id, &secy->sci,
451 sizeof(h->secure_channel_id)); 459 sizeof(h->secure_channel_id));
@@ -650,6 +658,7 @@ static struct sk_buff *macsec_encrypt(struct sk_buff *skb,
650 struct macsec_tx_sc *tx_sc; 658 struct macsec_tx_sc *tx_sc;
651 struct macsec_tx_sa *tx_sa; 659 struct macsec_tx_sa *tx_sa;
652 struct macsec_dev *macsec = macsec_priv(dev); 660 struct macsec_dev *macsec = macsec_priv(dev);
661 bool sci_present;
653 u32 pn; 662 u32 pn;
654 663
655 secy = &macsec->secy; 664 secy = &macsec->secy;
@@ -687,7 +696,8 @@ static struct sk_buff *macsec_encrypt(struct sk_buff *skb,
687 696
688 unprotected_len = skb->len; 697 unprotected_len = skb->len;
689 eth = eth_hdr(skb); 698 eth = eth_hdr(skb);
690 hh = (struct macsec_eth_header *)skb_push(skb, macsec_extra_len(tx_sc->send_sci)); 699 sci_present = send_sci(secy);
700 hh = (struct macsec_eth_header *)skb_push(skb, macsec_extra_len(sci_present));
691 memmove(hh, eth, 2 * ETH_ALEN); 701 memmove(hh, eth, 2 * ETH_ALEN);
692 702
693 pn = tx_sa_update_pn(tx_sa, secy); 703 pn = tx_sa_update_pn(tx_sa, secy);
@@ -696,7 +706,7 @@ static struct sk_buff *macsec_encrypt(struct sk_buff *skb,
696 kfree_skb(skb); 706 kfree_skb(skb);
697 return ERR_PTR(-ENOLINK); 707 return ERR_PTR(-ENOLINK);
698 } 708 }
699 macsec_fill_sectag(hh, secy, pn); 709 macsec_fill_sectag(hh, secy, pn, sci_present);
700 macsec_set_shortlen(hh, unprotected_len - 2 * ETH_ALEN); 710 macsec_set_shortlen(hh, unprotected_len - 2 * ETH_ALEN);
701 711
702 skb_put(skb, secy->icv_len); 712 skb_put(skb, secy->icv_len);
@@ -726,10 +736,10 @@ static struct sk_buff *macsec_encrypt(struct sk_buff *skb,
726 skb_to_sgvec(skb, sg, 0, skb->len); 736 skb_to_sgvec(skb, sg, 0, skb->len);
727 737
728 if (tx_sc->encrypt) { 738 if (tx_sc->encrypt) {
729 int len = skb->len - macsec_hdr_len(tx_sc->send_sci) - 739 int len = skb->len - macsec_hdr_len(sci_present) -
730 secy->icv_len; 740 secy->icv_len;
731 aead_request_set_crypt(req, sg, sg, len, iv); 741 aead_request_set_crypt(req, sg, sg, len, iv);
732 aead_request_set_ad(req, macsec_hdr_len(tx_sc->send_sci)); 742 aead_request_set_ad(req, macsec_hdr_len(sci_present));
733 } else { 743 } else {
734 aead_request_set_crypt(req, sg, sg, 0, iv); 744 aead_request_set_crypt(req, sg, sg, 0, iv);
735 aead_request_set_ad(req, skb->len - secy->icv_len); 745 aead_request_set_ad(req, skb->len - secy->icv_len);
diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
index 3234fcdea317..26d6f0bbe14b 100644
--- a/drivers/net/macvlan.c
+++ b/drivers/net/macvlan.c
@@ -623,7 +623,8 @@ hash_add:
623 return 0; 623 return 0;
624 624
625clear_multi: 625clear_multi:
626 dev_set_allmulti(lowerdev, -1); 626 if (dev->flags & IFF_ALLMULTI)
627 dev_set_allmulti(lowerdev, -1);
627del_unicast: 628del_unicast:
628 dev_uc_del(lowerdev, dev->dev_addr); 629 dev_uc_del(lowerdev, dev->dev_addr);
629out: 630out:
@@ -1278,6 +1279,7 @@ int macvlan_common_newlink(struct net *src_net, struct net_device *dev,
1278 struct net_device *lowerdev; 1279 struct net_device *lowerdev;
1279 int err; 1280 int err;
1280 int macmode; 1281 int macmode;
1282 bool create = false;
1281 1283
1282 if (!tb[IFLA_LINK]) 1284 if (!tb[IFLA_LINK])
1283 return -EINVAL; 1285 return -EINVAL;
@@ -1304,12 +1306,18 @@ int macvlan_common_newlink(struct net *src_net, struct net_device *dev,
1304 err = macvlan_port_create(lowerdev); 1306 err = macvlan_port_create(lowerdev);
1305 if (err < 0) 1307 if (err < 0)
1306 return err; 1308 return err;
1309 create = true;
1307 } 1310 }
1308 port = macvlan_port_get_rtnl(lowerdev); 1311 port = macvlan_port_get_rtnl(lowerdev);
1309 1312
1310 /* Only 1 macvlan device can be created in passthru mode */ 1313 /* Only 1 macvlan device can be created in passthru mode */
1311 if (port->passthru) 1314 if (port->passthru) {
1312 return -EINVAL; 1315 /* The macvlan port must be not created this time,
1316 * still goto destroy_macvlan_port for readability.
1317 */
1318 err = -EINVAL;
1319 goto destroy_macvlan_port;
1320 }
1313 1321
1314 vlan->lowerdev = lowerdev; 1322 vlan->lowerdev = lowerdev;
1315 vlan->dev = dev; 1323 vlan->dev = dev;
@@ -1325,24 +1333,28 @@ int macvlan_common_newlink(struct net *src_net, struct net_device *dev,
1325 vlan->flags = nla_get_u16(data[IFLA_MACVLAN_FLAGS]); 1333 vlan->flags = nla_get_u16(data[IFLA_MACVLAN_FLAGS]);
1326 1334
1327 if (vlan->mode == MACVLAN_MODE_PASSTHRU) { 1335 if (vlan->mode == MACVLAN_MODE_PASSTHRU) {
1328 if (port->count) 1336 if (port->count) {
1329 return -EINVAL; 1337 err = -EINVAL;
1338 goto destroy_macvlan_port;
1339 }
1330 port->passthru = true; 1340 port->passthru = true;
1331 eth_hw_addr_inherit(dev, lowerdev); 1341 eth_hw_addr_inherit(dev, lowerdev);
1332 } 1342 }
1333 1343
1334 if (data && data[IFLA_MACVLAN_MACADDR_MODE]) { 1344 if (data && data[IFLA_MACVLAN_MACADDR_MODE]) {
1335 if (vlan->mode != MACVLAN_MODE_SOURCE) 1345 if (vlan->mode != MACVLAN_MODE_SOURCE) {
1336 return -EINVAL; 1346 err = -EINVAL;
1347 goto destroy_macvlan_port;
1348 }
1337 macmode = nla_get_u32(data[IFLA_MACVLAN_MACADDR_MODE]); 1349 macmode = nla_get_u32(data[IFLA_MACVLAN_MACADDR_MODE]);
1338 err = macvlan_changelink_sources(vlan, macmode, data); 1350 err = macvlan_changelink_sources(vlan, macmode, data);
1339 if (err) 1351 if (err)
1340 return err; 1352 goto destroy_macvlan_port;
1341 } 1353 }
1342 1354
1343 err = register_netdevice(dev); 1355 err = register_netdevice(dev);
1344 if (err < 0) 1356 if (err < 0)
1345 return err; 1357 goto destroy_macvlan_port;
1346 1358
1347 dev->priv_flags |= IFF_MACVLAN; 1359 dev->priv_flags |= IFF_MACVLAN;
1348 err = netdev_upper_dev_link(lowerdev, dev); 1360 err = netdev_upper_dev_link(lowerdev, dev);
@@ -1357,7 +1369,9 @@ int macvlan_common_newlink(struct net *src_net, struct net_device *dev,
1357 1369
1358unregister_netdev: 1370unregister_netdev:
1359 unregister_netdevice(dev); 1371 unregister_netdevice(dev);
1360 1372destroy_macvlan_port:
1373 if (create)
1374 macvlan_port_destroy(port->dev);
1361 return err; 1375 return err;
1362} 1376}
1363EXPORT_SYMBOL_GPL(macvlan_common_newlink); 1377EXPORT_SYMBOL_GPL(macvlan_common_newlink);
diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
index 070e3290aa6e..7869b0651576 100644
--- a/drivers/net/macvtap.c
+++ b/drivers/net/macvtap.c
@@ -491,7 +491,13 @@ static int macvtap_newlink(struct net *src_net,
491 /* Don't put anything that may fail after macvlan_common_newlink 491 /* Don't put anything that may fail after macvlan_common_newlink
492 * because we can't undo what it does. 492 * because we can't undo what it does.
493 */ 493 */
494 return macvlan_common_newlink(src_net, dev, tb, data); 494 err = macvlan_common_newlink(src_net, dev, tb, data);
495 if (err) {
496 netdev_rx_handler_unregister(dev);
497 return err;
498 }
499
500 return 0;
495} 501}
496 502
497static void macvtap_dellink(struct net_device *dev, 503static void macvtap_dellink(struct net_device *dev,
@@ -736,13 +742,8 @@ static ssize_t macvtap_get_user(struct macvtap_queue *q, struct msghdr *m,
736 742
737 if (zerocopy) 743 if (zerocopy)
738 err = zerocopy_sg_from_iter(skb, from); 744 err = zerocopy_sg_from_iter(skb, from);
739 else { 745 else
740 err = skb_copy_datagram_from_iter(skb, 0, from, len); 746 err = skb_copy_datagram_from_iter(skb, 0, from, len);
741 if (!err && m && m->msg_control) {
742 struct ubuf_info *uarg = m->msg_control;
743 uarg->callback(uarg, false);
744 }
745 }
746 747
747 if (err) 748 if (err)
748 goto err_kfree; 749 goto err_kfree;
@@ -773,7 +774,11 @@ static ssize_t macvtap_get_user(struct macvtap_queue *q, struct msghdr *m,
773 skb_shinfo(skb)->destructor_arg = m->msg_control; 774 skb_shinfo(skb)->destructor_arg = m->msg_control;
774 skb_shinfo(skb)->tx_flags |= SKBTX_DEV_ZEROCOPY; 775 skb_shinfo(skb)->tx_flags |= SKBTX_DEV_ZEROCOPY;
775 skb_shinfo(skb)->tx_flags |= SKBTX_SHARED_FRAG; 776 skb_shinfo(skb)->tx_flags |= SKBTX_SHARED_FRAG;
777 } else if (m && m->msg_control) {
778 struct ubuf_info *uarg = m->msg_control;
779 uarg->callback(uarg, false);
776 } 780 }
781
777 if (vlan) { 782 if (vlan) {
778 skb->dev = vlan->dev; 783 skb->dev = vlan->dev;
779 dev_queue_xmit(skb); 784 dev_queue_xmit(skb);
diff --git a/drivers/net/phy/at803x.c b/drivers/net/phy/at803x.c
index f279a897a5c7..a52b560e428b 100644
--- a/drivers/net/phy/at803x.c
+++ b/drivers/net/phy/at803x.c
@@ -42,19 +42,24 @@
42#define AT803X_MMD_ACCESS_CONTROL 0x0D 42#define AT803X_MMD_ACCESS_CONTROL 0x0D
43#define AT803X_MMD_ACCESS_CONTROL_DATA 0x0E 43#define AT803X_MMD_ACCESS_CONTROL_DATA 0x0E
44#define AT803X_FUNC_DATA 0x4003 44#define AT803X_FUNC_DATA 0x4003
45#define AT803X_REG_CHIP_CONFIG 0x1f
46#define AT803X_BT_BX_REG_SEL 0x8000
45 47
46#define AT803X_DEBUG_ADDR 0x1D 48#define AT803X_DEBUG_ADDR 0x1D
47#define AT803X_DEBUG_DATA 0x1E 49#define AT803X_DEBUG_DATA 0x1E
48 50
51#define AT803X_MODE_CFG_MASK 0x0F
52#define AT803X_MODE_CFG_SGMII 0x01
53
54#define AT803X_PSSR 0x11 /*PHY-Specific Status Register*/
55#define AT803X_PSSR_MR_AN_COMPLETE 0x0200
56
49#define AT803X_DEBUG_REG_0 0x00 57#define AT803X_DEBUG_REG_0 0x00
50#define AT803X_DEBUG_RX_CLK_DLY_EN BIT(15) 58#define AT803X_DEBUG_RX_CLK_DLY_EN BIT(15)
51 59
52#define AT803X_DEBUG_REG_5 0x05 60#define AT803X_DEBUG_REG_5 0x05
53#define AT803X_DEBUG_TX_CLK_DLY_EN BIT(8) 61#define AT803X_DEBUG_TX_CLK_DLY_EN BIT(8)
54 62
55#define AT803X_REG_CHIP_CONFIG 0x1f
56#define AT803X_BT_BX_REG_SEL 0x8000
57
58#define ATH8030_PHY_ID 0x004dd076 63#define ATH8030_PHY_ID 0x004dd076
59#define ATH8031_PHY_ID 0x004dd074 64#define ATH8031_PHY_ID 0x004dd074
60#define ATH8035_PHY_ID 0x004dd072 65#define ATH8035_PHY_ID 0x004dd072
@@ -209,7 +214,6 @@ static int at803x_suspend(struct phy_device *phydev)
209{ 214{
210 int value; 215 int value;
211 int wol_enabled; 216 int wol_enabled;
212 int ccr;
213 217
214 mutex_lock(&phydev->lock); 218 mutex_lock(&phydev->lock);
215 219
@@ -225,16 +229,6 @@ static int at803x_suspend(struct phy_device *phydev)
225 229
226 phy_write(phydev, MII_BMCR, value); 230 phy_write(phydev, MII_BMCR, value);
227 231
228 if (phydev->interface != PHY_INTERFACE_MODE_SGMII)
229 goto done;
230
231 /* also power-down SGMII interface */
232 ccr = phy_read(phydev, AT803X_REG_CHIP_CONFIG);
233 phy_write(phydev, AT803X_REG_CHIP_CONFIG, ccr & ~AT803X_BT_BX_REG_SEL);
234 phy_write(phydev, MII_BMCR, phy_read(phydev, MII_BMCR) | BMCR_PDOWN);
235 phy_write(phydev, AT803X_REG_CHIP_CONFIG, ccr | AT803X_BT_BX_REG_SEL);
236
237done:
238 mutex_unlock(&phydev->lock); 232 mutex_unlock(&phydev->lock);
239 233
240 return 0; 234 return 0;
@@ -243,7 +237,6 @@ done:
243static int at803x_resume(struct phy_device *phydev) 237static int at803x_resume(struct phy_device *phydev)
244{ 238{
245 int value; 239 int value;
246 int ccr;
247 240
248 mutex_lock(&phydev->lock); 241 mutex_lock(&phydev->lock);
249 242
@@ -251,17 +244,6 @@ static int at803x_resume(struct phy_device *phydev)
251 value &= ~(BMCR_PDOWN | BMCR_ISOLATE); 244 value &= ~(BMCR_PDOWN | BMCR_ISOLATE);
252 phy_write(phydev, MII_BMCR, value); 245 phy_write(phydev, MII_BMCR, value);
253 246
254 if (phydev->interface != PHY_INTERFACE_MODE_SGMII)
255 goto done;
256
257 /* also power-up SGMII interface */
258 ccr = phy_read(phydev, AT803X_REG_CHIP_CONFIG);
259 phy_write(phydev, AT803X_REG_CHIP_CONFIG, ccr & ~AT803X_BT_BX_REG_SEL);
260 value = phy_read(phydev, MII_BMCR) & ~(BMCR_PDOWN | BMCR_ISOLATE);
261 phy_write(phydev, MII_BMCR, value);
262 phy_write(phydev, AT803X_REG_CHIP_CONFIG, ccr | AT803X_BT_BX_REG_SEL);
263
264done:
265 mutex_unlock(&phydev->lock); 247 mutex_unlock(&phydev->lock);
266 248
267 return 0; 249 return 0;
@@ -381,6 +363,36 @@ static void at803x_link_change_notify(struct phy_device *phydev)
381 } 363 }
382} 364}
383 365
366static int at803x_aneg_done(struct phy_device *phydev)
367{
368 int ccr;
369
370 int aneg_done = genphy_aneg_done(phydev);
371 if (aneg_done != BMSR_ANEGCOMPLETE)
372 return aneg_done;
373
374 /*
375 * in SGMII mode, if copper side autoneg is successful,
376 * also check SGMII side autoneg result
377 */
378 ccr = phy_read(phydev, AT803X_REG_CHIP_CONFIG);
379 if ((ccr & AT803X_MODE_CFG_MASK) != AT803X_MODE_CFG_SGMII)
380 return aneg_done;
381
382 /* switch to SGMII/fiber page */
383 phy_write(phydev, AT803X_REG_CHIP_CONFIG, ccr & ~AT803X_BT_BX_REG_SEL);
384
385 /* check if the SGMII link is OK. */
386 if (!(phy_read(phydev, AT803X_PSSR) & AT803X_PSSR_MR_AN_COMPLETE)) {
387 pr_warn("803x_aneg_done: SGMII link is not ok\n");
388 aneg_done = 0;
389 }
390 /* switch back to copper page */
391 phy_write(phydev, AT803X_REG_CHIP_CONFIG, ccr | AT803X_BT_BX_REG_SEL);
392
393 return aneg_done;
394}
395
384static struct phy_driver at803x_driver[] = { 396static struct phy_driver at803x_driver[] = {
385{ 397{
386 /* ATHEROS 8035 */ 398 /* ATHEROS 8035 */
@@ -432,6 +444,7 @@ static struct phy_driver at803x_driver[] = {
432 .flags = PHY_HAS_INTERRUPT, 444 .flags = PHY_HAS_INTERRUPT,
433 .config_aneg = genphy_config_aneg, 445 .config_aneg = genphy_config_aneg,
434 .read_status = genphy_read_status, 446 .read_status = genphy_read_status,
447 .aneg_done = at803x_aneg_done,
435 .ack_interrupt = &at803x_ack_interrupt, 448 .ack_interrupt = &at803x_ack_interrupt,
436 .config_intr = &at803x_config_intr, 449 .config_intr = &at803x_config_intr,
437} }; 450} };
diff --git a/drivers/net/phy/dp83848.c b/drivers/net/phy/dp83848.c
index 03d54c4adc88..800b39f06279 100644
--- a/drivers/net/phy/dp83848.c
+++ b/drivers/net/phy/dp83848.c
@@ -19,6 +19,7 @@
19#define TI_DP83848C_PHY_ID 0x20005ca0 19#define TI_DP83848C_PHY_ID 0x20005ca0
20#define NS_DP83848C_PHY_ID 0x20005c90 20#define NS_DP83848C_PHY_ID 0x20005c90
21#define TLK10X_PHY_ID 0x2000a210 21#define TLK10X_PHY_ID 0x2000a210
22#define TI_DP83822_PHY_ID 0x2000a240
22 23
23/* Registers */ 24/* Registers */
24#define DP83848_MICR 0x11 /* MII Interrupt Control Register */ 25#define DP83848_MICR 0x11 /* MII Interrupt Control Register */
@@ -77,6 +78,7 @@ static struct mdio_device_id __maybe_unused dp83848_tbl[] = {
77 { TI_DP83848C_PHY_ID, 0xfffffff0 }, 78 { TI_DP83848C_PHY_ID, 0xfffffff0 },
78 { NS_DP83848C_PHY_ID, 0xfffffff0 }, 79 { NS_DP83848C_PHY_ID, 0xfffffff0 },
79 { TLK10X_PHY_ID, 0xfffffff0 }, 80 { TLK10X_PHY_ID, 0xfffffff0 },
81 { TI_DP83822_PHY_ID, 0xfffffff0 },
80 { } 82 { }
81}; 83};
82MODULE_DEVICE_TABLE(mdio, dp83848_tbl); 84MODULE_DEVICE_TABLE(mdio, dp83848_tbl);
@@ -105,6 +107,7 @@ static struct phy_driver dp83848_driver[] = {
105 DP83848_PHY_DRIVER(TI_DP83848C_PHY_ID, "TI DP83848C 10/100 Mbps PHY"), 107 DP83848_PHY_DRIVER(TI_DP83848C_PHY_ID, "TI DP83848C 10/100 Mbps PHY"),
106 DP83848_PHY_DRIVER(NS_DP83848C_PHY_ID, "NS DP83848C 10/100 Mbps PHY"), 108 DP83848_PHY_DRIVER(NS_DP83848C_PHY_ID, "NS DP83848C 10/100 Mbps PHY"),
107 DP83848_PHY_DRIVER(TLK10X_PHY_ID, "TI TLK10X 10/100 Mbps PHY"), 109 DP83848_PHY_DRIVER(TLK10X_PHY_ID, "TI TLK10X 10/100 Mbps PHY"),
110 DP83848_PHY_DRIVER(TI_DP83822_PHY_ID, "TI DP83822 10/100 Mbps PHY"),
108}; 111};
109module_phy_driver(dp83848_driver); 112module_phy_driver(dp83848_driver);
110 113
diff --git a/drivers/net/phy/fixed_phy.c b/drivers/net/phy/fixed_phy.c
index c649c101bbab..eb5167210681 100644
--- a/drivers/net/phy/fixed_phy.c
+++ b/drivers/net/phy/fixed_phy.c
@@ -279,7 +279,7 @@ EXPORT_SYMBOL_GPL(fixed_phy_register);
279void fixed_phy_unregister(struct phy_device *phy) 279void fixed_phy_unregister(struct phy_device *phy)
280{ 280{
281 phy_device_remove(phy); 281 phy_device_remove(phy);
282 282 of_node_put(phy->mdio.dev.of_node);
283 fixed_phy_del(phy->mdio.addr); 283 fixed_phy_del(phy->mdio.addr);
284} 284}
285EXPORT_SYMBOL_GPL(fixed_phy_unregister); 285EXPORT_SYMBOL_GPL(fixed_phy_unregister);
diff --git a/drivers/net/phy/micrel.c b/drivers/net/phy/micrel.c
index 081df68d2ce1..ea92d524d5a8 100644
--- a/drivers/net/phy/micrel.c
+++ b/drivers/net/phy/micrel.c
@@ -318,12 +318,12 @@ static int ksz8041_config_init(struct phy_device *phydev)
318 /* Limit supported and advertised modes in fiber mode */ 318 /* Limit supported and advertised modes in fiber mode */
319 if (of_property_read_bool(of_node, "micrel,fiber-mode")) { 319 if (of_property_read_bool(of_node, "micrel,fiber-mode")) {
320 phydev->dev_flags |= MICREL_PHY_FXEN; 320 phydev->dev_flags |= MICREL_PHY_FXEN;
321 phydev->supported &= SUPPORTED_FIBRE | 321 phydev->supported &= SUPPORTED_100baseT_Full |
322 SUPPORTED_100baseT_Full |
323 SUPPORTED_100baseT_Half; 322 SUPPORTED_100baseT_Half;
324 phydev->advertising &= ADVERTISED_FIBRE | 323 phydev->supported |= SUPPORTED_FIBRE;
325 ADVERTISED_100baseT_Full | 324 phydev->advertising &= ADVERTISED_100baseT_Full |
326 ADVERTISED_100baseT_Half; 325 ADVERTISED_100baseT_Half;
326 phydev->advertising |= ADVERTISED_FIBRE;
327 phydev->autoneg = AUTONEG_DISABLE; 327 phydev->autoneg = AUTONEG_DISABLE;
328 } 328 }
329 329
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index e977ba931878..c4ceb082e970 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -723,6 +723,7 @@ struct phy_device *phy_connect(struct net_device *dev, const char *bus_id,
723 phydev = to_phy_device(d); 723 phydev = to_phy_device(d);
724 724
725 rc = phy_connect_direct(dev, phydev, handler, interface); 725 rc = phy_connect_direct(dev, phydev, handler, interface);
726 put_device(d);
726 if (rc) 727 if (rc)
727 return ERR_PTR(rc); 728 return ERR_PTR(rc);
728 729
@@ -856,11 +857,17 @@ EXPORT_SYMBOL(phy_attached_print);
856int phy_attach_direct(struct net_device *dev, struct phy_device *phydev, 857int phy_attach_direct(struct net_device *dev, struct phy_device *phydev,
857 u32 flags, phy_interface_t interface) 858 u32 flags, phy_interface_t interface)
858{ 859{
860 struct module *ndev_owner = dev->dev.parent->driver->owner;
859 struct mii_bus *bus = phydev->mdio.bus; 861 struct mii_bus *bus = phydev->mdio.bus;
860 struct device *d = &phydev->mdio.dev; 862 struct device *d = &phydev->mdio.dev;
861 int err; 863 int err;
862 864
863 if (!try_module_get(bus->owner)) { 865 /* For Ethernet device drivers that register their own MDIO bus, we
866 * will have bus->owner match ndev_mod, so we do not want to increment
867 * our own module->refcnt here, otherwise we would not be able to
868 * unload later on.
869 */
870 if (ndev_owner != bus->owner && !try_module_get(bus->owner)) {
864 dev_err(&dev->dev, "failed to get the bus module\n"); 871 dev_err(&dev->dev, "failed to get the bus module\n");
865 return -EIO; 872 return -EIO;
866 } 873 }
@@ -920,7 +927,8 @@ int phy_attach_direct(struct net_device *dev, struct phy_device *phydev,
920 927
921error: 928error:
922 put_device(d); 929 put_device(d);
923 module_put(bus->owner); 930 if (ndev_owner != bus->owner)
931 module_put(bus->owner);
924 return err; 932 return err;
925} 933}
926EXPORT_SYMBOL(phy_attach_direct); 934EXPORT_SYMBOL(phy_attach_direct);
@@ -953,6 +961,7 @@ struct phy_device *phy_attach(struct net_device *dev, const char *bus_id,
953 phydev = to_phy_device(d); 961 phydev = to_phy_device(d);
954 962
955 rc = phy_attach_direct(dev, phydev, phydev->dev_flags, interface); 963 rc = phy_attach_direct(dev, phydev, phydev->dev_flags, interface);
964 put_device(d);
956 if (rc) 965 if (rc)
957 return ERR_PTR(rc); 966 return ERR_PTR(rc);
958 967
@@ -969,6 +978,8 @@ EXPORT_SYMBOL(phy_attach);
969 */ 978 */
970void phy_detach(struct phy_device *phydev) 979void phy_detach(struct phy_device *phydev)
971{ 980{
981 struct net_device *dev = phydev->attached_dev;
982 struct module *ndev_owner = dev->dev.parent->driver->owner;
972 struct mii_bus *bus; 983 struct mii_bus *bus;
973 int i; 984 int i;
974 985
@@ -996,7 +1007,8 @@ void phy_detach(struct phy_device *phydev)
996 bus = phydev->mdio.bus; 1007 bus = phydev->mdio.bus;
997 1008
998 put_device(&phydev->mdio.dev); 1009 put_device(&phydev->mdio.dev);
999 module_put(bus->owner); 1010 if (ndev_owner != bus->owner)
1011 module_put(bus->owner);
1000} 1012}
1001EXPORT_SYMBOL(phy_detach); 1013EXPORT_SYMBOL(phy_detach);
1002 1014
diff --git a/drivers/net/phy/realtek.c b/drivers/net/phy/realtek.c
index aadd6e9f54ad..9cbe645e3d89 100644
--- a/drivers/net/phy/realtek.c
+++ b/drivers/net/phy/realtek.c
@@ -102,15 +102,19 @@ static int rtl8211f_config_init(struct phy_device *phydev)
102 if (ret < 0) 102 if (ret < 0)
103 return ret; 103 return ret;
104 104
105 if (phydev->interface == PHY_INTERFACE_MODE_RGMII) { 105 phy_write(phydev, RTL8211F_PAGE_SELECT, 0xd08);
106 /* enable TXDLY */ 106 reg = phy_read(phydev, 0x11);
107 phy_write(phydev, RTL8211F_PAGE_SELECT, 0xd08); 107
108 reg = phy_read(phydev, 0x11); 108 /* enable TX-delay for rgmii-id and rgmii-txid, otherwise disable it */
109 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID ||
110 phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID)
109 reg |= RTL8211F_TX_DELAY; 111 reg |= RTL8211F_TX_DELAY;
110 phy_write(phydev, 0x11, reg); 112 else
111 /* restore to default page 0 */ 113 reg &= ~RTL8211F_TX_DELAY;
112 phy_write(phydev, RTL8211F_PAGE_SELECT, 0x0); 114
113 } 115 phy_write(phydev, 0x11, reg);
116 /* restore to default page 0 */
117 phy_write(phydev, RTL8211F_PAGE_SELECT, 0x0);
114 118
115 return 0; 119 return 0;
116} 120}
diff --git a/drivers/net/phy/vitesse.c b/drivers/net/phy/vitesse.c
index 2e37eb337d48..24b4a09468dd 100644
--- a/drivers/net/phy/vitesse.c
+++ b/drivers/net/phy/vitesse.c
@@ -62,6 +62,10 @@
62/* Vitesse Extended Page Access Register */ 62/* Vitesse Extended Page Access Register */
63#define MII_VSC82X4_EXT_PAGE_ACCESS 0x1f 63#define MII_VSC82X4_EXT_PAGE_ACCESS 0x1f
64 64
65/* Vitesse VSC8601 Extended PHY Control Register 1 */
66#define MII_VSC8601_EPHY_CTL 0x17
67#define MII_VSC8601_EPHY_CTL_RGMII_SKEW (1 << 8)
68
65#define PHY_ID_VSC8234 0x000fc620 69#define PHY_ID_VSC8234 0x000fc620
66#define PHY_ID_VSC8244 0x000fc6c0 70#define PHY_ID_VSC8244 0x000fc6c0
67#define PHY_ID_VSC8514 0x00070670 71#define PHY_ID_VSC8514 0x00070670
@@ -111,6 +115,34 @@ static int vsc824x_config_init(struct phy_device *phydev)
111 return err; 115 return err;
112} 116}
113 117
118/* This adds a skew for both TX and RX clocks, so the skew should only be
119 * applied to "rgmii-id" interfaces. It may not work as expected
120 * on "rgmii-txid", "rgmii-rxid" or "rgmii" interfaces. */
121static int vsc8601_add_skew(struct phy_device *phydev)
122{
123 int ret;
124
125 ret = phy_read(phydev, MII_VSC8601_EPHY_CTL);
126 if (ret < 0)
127 return ret;
128
129 ret |= MII_VSC8601_EPHY_CTL_RGMII_SKEW;
130 return phy_write(phydev, MII_VSC8601_EPHY_CTL, ret);
131}
132
133static int vsc8601_config_init(struct phy_device *phydev)
134{
135 int ret = 0;
136
137 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID)
138 ret = vsc8601_add_skew(phydev);
139
140 if (ret < 0)
141 return ret;
142
143 return genphy_config_init(phydev);
144}
145
114static int vsc824x_ack_interrupt(struct phy_device *phydev) 146static int vsc824x_ack_interrupt(struct phy_device *phydev)
115{ 147{
116 int err = 0; 148 int err = 0;
@@ -275,7 +307,7 @@ static struct phy_driver vsc82xx_driver[] = {
275 .phy_id_mask = 0x000ffff0, 307 .phy_id_mask = 0x000ffff0,
276 .features = PHY_GBIT_FEATURES, 308 .features = PHY_GBIT_FEATURES,
277 .flags = PHY_HAS_INTERRUPT, 309 .flags = PHY_HAS_INTERRUPT,
278 .config_init = &genphy_config_init, 310 .config_init = &vsc8601_config_init,
279 .config_aneg = &genphy_config_aneg, 311 .config_aneg = &genphy_config_aneg,
280 .read_status = &genphy_read_status, 312 .read_status = &genphy_read_status,
281 .ack_interrupt = &vsc824x_ack_interrupt, 313 .ack_interrupt = &vsc824x_ack_interrupt,
diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index 8093e39ae263..db6acecabeaa 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -1246,13 +1246,8 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
1246 1246
1247 if (zerocopy) 1247 if (zerocopy)
1248 err = zerocopy_sg_from_iter(skb, from); 1248 err = zerocopy_sg_from_iter(skb, from);
1249 else { 1249 else
1250 err = skb_copy_datagram_from_iter(skb, 0, from, len); 1250 err = skb_copy_datagram_from_iter(skb, 0, from, len);
1251 if (!err && msg_control) {
1252 struct ubuf_info *uarg = msg_control;
1253 uarg->callback(uarg, false);
1254 }
1255 }
1256 1251
1257 if (err) { 1252 if (err) {
1258 this_cpu_inc(tun->pcpu_stats->rx_dropped); 1253 this_cpu_inc(tun->pcpu_stats->rx_dropped);
@@ -1298,6 +1293,9 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
1298 skb_shinfo(skb)->destructor_arg = msg_control; 1293 skb_shinfo(skb)->destructor_arg = msg_control;
1299 skb_shinfo(skb)->tx_flags |= SKBTX_DEV_ZEROCOPY; 1294 skb_shinfo(skb)->tx_flags |= SKBTX_DEV_ZEROCOPY;
1300 skb_shinfo(skb)->tx_flags |= SKBTX_SHARED_FRAG; 1295 skb_shinfo(skb)->tx_flags |= SKBTX_SHARED_FRAG;
1296 } else if (msg_control) {
1297 struct ubuf_info *uarg = msg_control;
1298 uarg->callback(uarg, false);
1301 } 1299 }
1302 1300
1303 skb_reset_network_header(skb); 1301 skb_reset_network_header(skb);
diff --git a/drivers/net/usb/asix_common.c b/drivers/net/usb/asix_common.c
index f79eb12c326a..125cff57c759 100644
--- a/drivers/net/usb/asix_common.c
+++ b/drivers/net/usb/asix_common.c
@@ -433,13 +433,13 @@ int asix_mdio_read(struct net_device *netdev, int phy_id, int loc)
433 mutex_lock(&dev->phy_mutex); 433 mutex_lock(&dev->phy_mutex);
434 do { 434 do {
435 ret = asix_set_sw_mii(dev, 0); 435 ret = asix_set_sw_mii(dev, 0);
436 if (ret == -ENODEV) 436 if (ret == -ENODEV || ret == -ETIMEDOUT)
437 break; 437 break;
438 usleep_range(1000, 1100); 438 usleep_range(1000, 1100);
439 ret = asix_read_cmd(dev, AX_CMD_STATMNGSTS_REG, 439 ret = asix_read_cmd(dev, AX_CMD_STATMNGSTS_REG,
440 0, 0, 1, &smsr, 0); 440 0, 0, 1, &smsr, 0);
441 } while (!(smsr & AX_HOST_EN) && (i++ < 30) && (ret != -ENODEV)); 441 } while (!(smsr & AX_HOST_EN) && (i++ < 30) && (ret != -ENODEV));
442 if (ret == -ENODEV) { 442 if (ret == -ENODEV || ret == -ETIMEDOUT) {
443 mutex_unlock(&dev->phy_mutex); 443 mutex_unlock(&dev->phy_mutex);
444 return ret; 444 return ret;
445 } 445 }
@@ -497,13 +497,13 @@ int asix_mdio_read_nopm(struct net_device *netdev, int phy_id, int loc)
497 mutex_lock(&dev->phy_mutex); 497 mutex_lock(&dev->phy_mutex);
498 do { 498 do {
499 ret = asix_set_sw_mii(dev, 1); 499 ret = asix_set_sw_mii(dev, 1);
500 if (ret == -ENODEV) 500 if (ret == -ENODEV || ret == -ETIMEDOUT)
501 break; 501 break;
502 usleep_range(1000, 1100); 502 usleep_range(1000, 1100);
503 ret = asix_read_cmd(dev, AX_CMD_STATMNGSTS_REG, 503 ret = asix_read_cmd(dev, AX_CMD_STATMNGSTS_REG,
504 0, 0, 1, &smsr, 1); 504 0, 0, 1, &smsr, 1);
505 } while (!(smsr & AX_HOST_EN) && (i++ < 30) && (ret != -ENODEV)); 505 } while (!(smsr & AX_HOST_EN) && (i++ < 30) && (ret != -ENODEV));
506 if (ret == -ENODEV) { 506 if (ret == -ENODEV || ret == -ETIMEDOUT) {
507 mutex_unlock(&dev->phy_mutex); 507 mutex_unlock(&dev->phy_mutex);
508 return ret; 508 return ret;
509 } 509 }
diff --git a/drivers/net/usb/asix_devices.c b/drivers/net/usb/asix_devices.c
index cce24950a0ab..dc7b6392e75a 100644
--- a/drivers/net/usb/asix_devices.c
+++ b/drivers/net/usb/asix_devices.c
@@ -603,12 +603,12 @@ static void ax88772_suspend(struct usbnet *dev)
603 u16 medium; 603 u16 medium;
604 604
605 /* Stop MAC operation */ 605 /* Stop MAC operation */
606 medium = asix_read_medium_status(dev, 0); 606 medium = asix_read_medium_status(dev, 1);
607 medium &= ~AX_MEDIUM_RE; 607 medium &= ~AX_MEDIUM_RE;
608 asix_write_medium_mode(dev, medium, 0); 608 asix_write_medium_mode(dev, medium, 1);
609 609
610 netdev_dbg(dev->net, "ax88772_suspend: medium=0x%04x\n", 610 netdev_dbg(dev->net, "ax88772_suspend: medium=0x%04x\n",
611 asix_read_medium_status(dev, 0)); 611 asix_read_medium_status(dev, 1));
612 612
613 /* Preserve BMCR for restoring */ 613 /* Preserve BMCR for restoring */
614 priv->presvd_phy_bmcr = 614 priv->presvd_phy_bmcr =
diff --git a/drivers/net/usb/ax88179_178a.c b/drivers/net/usb/ax88179_178a.c
index e6338c16081a..8a6675d92b98 100644
--- a/drivers/net/usb/ax88179_178a.c
+++ b/drivers/net/usb/ax88179_178a.c
@@ -1656,6 +1656,19 @@ static const struct driver_info ax88178a_info = {
1656 .tx_fixup = ax88179_tx_fixup, 1656 .tx_fixup = ax88179_tx_fixup,
1657}; 1657};
1658 1658
1659static const struct driver_info cypress_GX3_info = {
1660 .description = "Cypress GX3 SuperSpeed to Gigabit Ethernet Controller",
1661 .bind = ax88179_bind,
1662 .unbind = ax88179_unbind,
1663 .status = ax88179_status,
1664 .link_reset = ax88179_link_reset,
1665 .reset = ax88179_reset,
1666 .stop = ax88179_stop,
1667 .flags = FLAG_ETHER | FLAG_FRAMING_AX,
1668 .rx_fixup = ax88179_rx_fixup,
1669 .tx_fixup = ax88179_tx_fixup,
1670};
1671
1659static const struct driver_info dlink_dub1312_info = { 1672static const struct driver_info dlink_dub1312_info = {
1660 .description = "D-Link DUB-1312 USB 3.0 to Gigabit Ethernet Adapter", 1673 .description = "D-Link DUB-1312 USB 3.0 to Gigabit Ethernet Adapter",
1661 .bind = ax88179_bind, 1674 .bind = ax88179_bind,
@@ -1718,6 +1731,10 @@ static const struct usb_device_id products[] = {
1718 USB_DEVICE(0x0b95, 0x178a), 1731 USB_DEVICE(0x0b95, 0x178a),
1719 .driver_info = (unsigned long)&ax88178a_info, 1732 .driver_info = (unsigned long)&ax88178a_info,
1720}, { 1733}, {
1734 /* Cypress GX3 SuperSpeed to Gigabit Ethernet Bridge Controller */
1735 USB_DEVICE(0x04b4, 0x3610),
1736 .driver_info = (unsigned long)&cypress_GX3_info,
1737}, {
1721 /* D-Link DUB-1312 USB 3.0 to Gigabit Ethernet Adapter */ 1738 /* D-Link DUB-1312 USB 3.0 to Gigabit Ethernet Adapter */
1722 USB_DEVICE(0x2001, 0x4a00), 1739 USB_DEVICE(0x2001, 0x4a00),
1723 .driver_info = (unsigned long)&dlink_dub1312_info, 1740 .driver_info = (unsigned long)&dlink_dub1312_info,
diff --git a/drivers/net/usb/cdc_ether.c b/drivers/net/usb/cdc_ether.c
index c47ec0a04c8e..dd623f674487 100644
--- a/drivers/net/usb/cdc_ether.c
+++ b/drivers/net/usb/cdc_ether.c
@@ -388,12 +388,6 @@ void usbnet_cdc_status(struct usbnet *dev, struct urb *urb)
388 case USB_CDC_NOTIFY_NETWORK_CONNECTION: 388 case USB_CDC_NOTIFY_NETWORK_CONNECTION:
389 netif_dbg(dev, timer, dev->net, "CDC: carrier %s\n", 389 netif_dbg(dev, timer, dev->net, "CDC: carrier %s\n",
390 event->wValue ? "on" : "off"); 390 event->wValue ? "on" : "off");
391
392 /* Work-around for devices with broken off-notifications */
393 if (event->wValue &&
394 !test_bit(__LINK_STATE_NOCARRIER, &dev->net->state))
395 usbnet_link_change(dev, 0, 0);
396
397 usbnet_link_change(dev, !!event->wValue, 0); 391 usbnet_link_change(dev, !!event->wValue, 0);
398 break; 392 break;
399 case USB_CDC_NOTIFY_SPEED_CHANGE: /* tx/rx rates */ 393 case USB_CDC_NOTIFY_SPEED_CHANGE: /* tx/rx rates */
@@ -466,6 +460,36 @@ static int usbnet_cdc_zte_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
466 return 1; 460 return 1;
467} 461}
468 462
463/* Ensure correct link state
464 *
465 * Some devices (ZTE MF823/831/910) export two carrier on notifications when
466 * connected. This causes the link state to be incorrect. Work around this by
467 * always setting the state to off, then on.
468 */
469void usbnet_cdc_zte_status(struct usbnet *dev, struct urb *urb)
470{
471 struct usb_cdc_notification *event;
472
473 if (urb->actual_length < sizeof(*event))
474 return;
475
476 event = urb->transfer_buffer;
477
478 if (event->bNotificationType != USB_CDC_NOTIFY_NETWORK_CONNECTION) {
479 usbnet_cdc_status(dev, urb);
480 return;
481 }
482
483 netif_dbg(dev, timer, dev->net, "CDC: carrier %s\n",
484 event->wValue ? "on" : "off");
485
486 if (event->wValue &&
487 netif_carrier_ok(dev->net))
488 netif_carrier_off(dev->net);
489
490 usbnet_link_change(dev, !!event->wValue, 0);
491}
492
469static const struct driver_info cdc_info = { 493static const struct driver_info cdc_info = {
470 .description = "CDC Ethernet Device", 494 .description = "CDC Ethernet Device",
471 .flags = FLAG_ETHER | FLAG_POINTTOPOINT, 495 .flags = FLAG_ETHER | FLAG_POINTTOPOINT,
@@ -481,7 +505,7 @@ static const struct driver_info zte_cdc_info = {
481 .flags = FLAG_ETHER | FLAG_POINTTOPOINT, 505 .flags = FLAG_ETHER | FLAG_POINTTOPOINT,
482 .bind = usbnet_cdc_zte_bind, 506 .bind = usbnet_cdc_zte_bind,
483 .unbind = usbnet_cdc_unbind, 507 .unbind = usbnet_cdc_unbind,
484 .status = usbnet_cdc_status, 508 .status = usbnet_cdc_zte_status,
485 .set_rx_mode = usbnet_cdc_update_filter, 509 .set_rx_mode = usbnet_cdc_update_filter,
486 .manage_power = usbnet_manage_power, 510 .manage_power = usbnet_manage_power,
487 .rx_fixup = usbnet_cdc_zte_rx_fixup, 511 .rx_fixup = usbnet_cdc_zte_rx_fixup,
diff --git a/drivers/net/usb/cdc_mbim.c b/drivers/net/usb/cdc_mbim.c
index 96a5028621c8..3a98f3762a4c 100644
--- a/drivers/net/usb/cdc_mbim.c
+++ b/drivers/net/usb/cdc_mbim.c
@@ -602,6 +602,21 @@ static const struct driver_info cdc_mbim_info_ndp_to_end = {
602 .data = CDC_NCM_FLAG_NDP_TO_END, 602 .data = CDC_NCM_FLAG_NDP_TO_END,
603}; 603};
604 604
605/* Some modems (e.g. Telit LE922A6) do not work properly with altsetting
606 * toggle done in cdc_ncm_bind_common. CDC_MBIM_FLAG_AVOID_ALTSETTING_TOGGLE
607 * flag is used to avoid this procedure.
608 */
609static const struct driver_info cdc_mbim_info_avoid_altsetting_toggle = {
610 .description = "CDC MBIM",
611 .flags = FLAG_NO_SETINT | FLAG_MULTI_PACKET | FLAG_WWAN,
612 .bind = cdc_mbim_bind,
613 .unbind = cdc_mbim_unbind,
614 .manage_power = cdc_mbim_manage_power,
615 .rx_fixup = cdc_mbim_rx_fixup,
616 .tx_fixup = cdc_mbim_tx_fixup,
617 .data = CDC_MBIM_FLAG_AVOID_ALTSETTING_TOGGLE,
618};
619
605static const struct usb_device_id mbim_devs[] = { 620static const struct usb_device_id mbim_devs[] = {
606 /* This duplicate NCM entry is intentional. MBIM devices can 621 /* This duplicate NCM entry is intentional. MBIM devices can
607 * be disguised as NCM by default, and this is necessary to 622 * be disguised as NCM by default, and this is necessary to
@@ -626,6 +641,12 @@ static const struct usb_device_id mbim_devs[] = {
626 { USB_VENDOR_AND_INTERFACE_INFO(0x12d1, USB_CLASS_COMM, USB_CDC_SUBCLASS_MBIM, USB_CDC_PROTO_NONE), 641 { USB_VENDOR_AND_INTERFACE_INFO(0x12d1, USB_CLASS_COMM, USB_CDC_SUBCLASS_MBIM, USB_CDC_PROTO_NONE),
627 .driver_info = (unsigned long)&cdc_mbim_info_ndp_to_end, 642 .driver_info = (unsigned long)&cdc_mbim_info_ndp_to_end,
628 }, 643 },
644
645 /* Telit LE922A6 in MBIM composition */
646 { USB_DEVICE_AND_INTERFACE_INFO(0x1bc7, 0x1041, USB_CLASS_COMM, USB_CDC_SUBCLASS_MBIM, USB_CDC_PROTO_NONE),
647 .driver_info = (unsigned long)&cdc_mbim_info_avoid_altsetting_toggle,
648 },
649
629 /* default entry */ 650 /* default entry */
630 { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_MBIM, USB_CDC_PROTO_NONE), 651 { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_MBIM, USB_CDC_PROTO_NONE),
631 .driver_info = (unsigned long)&cdc_mbim_info_zlp, 652 .driver_info = (unsigned long)&cdc_mbim_info_zlp,
diff --git a/drivers/net/usb/cdc_ncm.c b/drivers/net/usb/cdc_ncm.c
index 877c9516e781..afbfc0f656f3 100644
--- a/drivers/net/usb/cdc_ncm.c
+++ b/drivers/net/usb/cdc_ncm.c
@@ -839,11 +839,18 @@ int cdc_ncm_bind_common(struct usbnet *dev, struct usb_interface *intf, u8 data_
839 839
840 iface_no = ctx->data->cur_altsetting->desc.bInterfaceNumber; 840 iface_no = ctx->data->cur_altsetting->desc.bInterfaceNumber;
841 841
842 /* Device-specific flags */
843 ctx->drvflags = drvflags;
844
842 /* Reset data interface. Some devices will not reset properly 845 /* Reset data interface. Some devices will not reset properly
843 * unless they are configured first. Toggle the altsetting to 846 * unless they are configured first. Toggle the altsetting to
844 * force a reset 847 * force a reset.
848 * Some other devices do not work properly with this procedure
849 * that can be avoided using quirk CDC_MBIM_FLAG_AVOID_ALTSETTING_TOGGLE
845 */ 850 */
846 usb_set_interface(dev->udev, iface_no, data_altsetting); 851 if (!(ctx->drvflags & CDC_MBIM_FLAG_AVOID_ALTSETTING_TOGGLE))
852 usb_set_interface(dev->udev, iface_no, data_altsetting);
853
847 temp = usb_set_interface(dev->udev, iface_no, 0); 854 temp = usb_set_interface(dev->udev, iface_no, 0);
848 if (temp) { 855 if (temp) {
849 dev_dbg(&intf->dev, "set interface failed\n"); 856 dev_dbg(&intf->dev, "set interface failed\n");
@@ -890,9 +897,6 @@ int cdc_ncm_bind_common(struct usbnet *dev, struct usb_interface *intf, u8 data_
890 /* finish setting up the device specific data */ 897 /* finish setting up the device specific data */
891 cdc_ncm_setup(dev); 898 cdc_ncm_setup(dev);
892 899
893 /* Device-specific flags */
894 ctx->drvflags = drvflags;
895
896 /* Allocate the delayed NDP if needed. */ 900 /* Allocate the delayed NDP if needed. */
897 if (ctx->drvflags & CDC_NCM_FLAG_NDP_TO_END) { 901 if (ctx->drvflags & CDC_NCM_FLAG_NDP_TO_END) {
898 ctx->delayed_ndp16 = kzalloc(ctx->max_ndp_size, GFP_KERNEL); 902 ctx->delayed_ndp16 = kzalloc(ctx->max_ndp_size, GFP_KERNEL);
diff --git a/drivers/net/usb/kalmia.c b/drivers/net/usb/kalmia.c
index 5662babf0583..3e37724d30ae 100644
--- a/drivers/net/usb/kalmia.c
+++ b/drivers/net/usb/kalmia.c
@@ -151,7 +151,7 @@ kalmia_bind(struct usbnet *dev, struct usb_interface *intf)
151 151
152 status = kalmia_init_and_get_ethernet_addr(dev, ethernet_addr); 152 status = kalmia_init_and_get_ethernet_addr(dev, ethernet_addr);
153 153
154 if (status < 0) { 154 if (status) {
155 usb_set_intfdata(intf, NULL); 155 usb_set_intfdata(intf, NULL);
156 usb_driver_release_interface(driver_of(intf), intf); 156 usb_driver_release_interface(driver_of(intf), intf);
157 return status; 157 return status;
diff --git a/drivers/net/usb/lan78xx.c b/drivers/net/usb/lan78xx.c
index db558b8b32fe..f33460cec79f 100644
--- a/drivers/net/usb/lan78xx.c
+++ b/drivers/net/usb/lan78xx.c
@@ -3395,6 +3395,7 @@ static int lan78xx_probe(struct usb_interface *intf,
3395 if (buf) { 3395 if (buf) {
3396 dev->urb_intr = usb_alloc_urb(0, GFP_KERNEL); 3396 dev->urb_intr = usb_alloc_urb(0, GFP_KERNEL);
3397 if (!dev->urb_intr) { 3397 if (!dev->urb_intr) {
3398 ret = -ENOMEM;
3398 kfree(buf); 3399 kfree(buf);
3399 goto out3; 3400 goto out3;
3400 } else { 3401 } else {
diff --git a/drivers/net/usb/qmi_wwan.c b/drivers/net/usb/qmi_wwan.c
index 3ff76c6db4f6..6fe1cdb0174f 100644
--- a/drivers/net/usb/qmi_wwan.c
+++ b/drivers/net/usb/qmi_wwan.c
@@ -894,6 +894,7 @@ static const struct usb_device_id products[] = {
894 {QMI_FIXED_INTF(0x1bbb, 0x0203, 2)}, /* Alcatel L800MA */ 894 {QMI_FIXED_INTF(0x1bbb, 0x0203, 2)}, /* Alcatel L800MA */
895 {QMI_FIXED_INTF(0x2357, 0x0201, 4)}, /* TP-LINK HSUPA Modem MA180 */ 895 {QMI_FIXED_INTF(0x2357, 0x0201, 4)}, /* TP-LINK HSUPA Modem MA180 */
896 {QMI_FIXED_INTF(0x2357, 0x9000, 4)}, /* TP-LINK MA260 */ 896 {QMI_FIXED_INTF(0x2357, 0x9000, 4)}, /* TP-LINK MA260 */
897 {QMI_QUIRK_SET_DTR(0x1bc7, 0x1040, 2)}, /* Telit LE922A */
897 {QMI_FIXED_INTF(0x1bc7, 0x1200, 5)}, /* Telit LE920 */ 898 {QMI_FIXED_INTF(0x1bc7, 0x1200, 5)}, /* Telit LE920 */
898 {QMI_FIXED_INTF(0x1bc7, 0x1201, 2)}, /* Telit LE920 */ 899 {QMI_FIXED_INTF(0x1bc7, 0x1201, 2)}, /* Telit LE920 */
899 {QMI_FIXED_INTF(0x1c9e, 0x9b01, 3)}, /* XS Stick W100-2 from 4G Systems */ 900 {QMI_FIXED_INTF(0x1c9e, 0x9b01, 3)}, /* XS Stick W100-2 from 4G Systems */
diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
index 44d439f50961..efb84f092492 100644
--- a/drivers/net/usb/r8152.c
+++ b/drivers/net/usb/r8152.c
@@ -1730,7 +1730,7 @@ static u8 r8152_rx_csum(struct r8152 *tp, struct rx_desc *rx_desc)
1730 u8 checksum = CHECKSUM_NONE; 1730 u8 checksum = CHECKSUM_NONE;
1731 u32 opts2, opts3; 1731 u32 opts2, opts3;
1732 1732
1733 if (tp->version == RTL_VER_01) 1733 if (tp->version == RTL_VER_01 || tp->version == RTL_VER_02)
1734 goto return_result; 1734 goto return_result;
1735 1735
1736 opts2 = le32_to_cpu(rx_desc->opts2); 1736 opts2 = le32_to_cpu(rx_desc->opts2);
@@ -1745,7 +1745,7 @@ static u8 r8152_rx_csum(struct r8152 *tp, struct rx_desc *rx_desc)
1745 checksum = CHECKSUM_NONE; 1745 checksum = CHECKSUM_NONE;
1746 else 1746 else
1747 checksum = CHECKSUM_UNNECESSARY; 1747 checksum = CHECKSUM_UNNECESSARY;
1748 } else if (RD_IPV6_CS) { 1748 } else if (opts2 & RD_IPV6_CS) {
1749 if ((opts2 & RD_UDP_CS) && !(opts3 & UDPF)) 1749 if ((opts2 & RD_UDP_CS) && !(opts3 & UDPF))
1750 checksum = CHECKSUM_UNNECESSARY; 1750 checksum = CHECKSUM_UNNECESSARY;
1751 else if ((opts2 & RD_TCP_CS) && !(opts3 & TCPF)) 1751 else if ((opts2 & RD_TCP_CS) && !(opts3 & TCPF))
@@ -3266,10 +3266,8 @@ static int rtl8152_open(struct net_device *netdev)
3266 goto out; 3266 goto out;
3267 3267
3268 res = usb_autopm_get_interface(tp->intf); 3268 res = usb_autopm_get_interface(tp->intf);
3269 if (res < 0) { 3269 if (res < 0)
3270 free_all_mem(tp); 3270 goto out_free;
3271 goto out;
3272 }
3273 3271
3274 mutex_lock(&tp->control); 3272 mutex_lock(&tp->control);
3275 3273
@@ -3285,10 +3283,9 @@ static int rtl8152_open(struct net_device *netdev)
3285 netif_device_detach(tp->netdev); 3283 netif_device_detach(tp->netdev);
3286 netif_warn(tp, ifup, netdev, "intr_urb submit failed: %d\n", 3284 netif_warn(tp, ifup, netdev, "intr_urb submit failed: %d\n",
3287 res); 3285 res);
3288 free_all_mem(tp); 3286 goto out_unlock;
3289 } else {
3290 napi_enable(&tp->napi);
3291 } 3287 }
3288 napi_enable(&tp->napi);
3292 3289
3293 mutex_unlock(&tp->control); 3290 mutex_unlock(&tp->control);
3294 3291
@@ -3297,7 +3294,13 @@ static int rtl8152_open(struct net_device *netdev)
3297 tp->pm_notifier.notifier_call = rtl_notifier; 3294 tp->pm_notifier.notifier_call = rtl_notifier;
3298 register_pm_notifier(&tp->pm_notifier); 3295 register_pm_notifier(&tp->pm_notifier);
3299#endif 3296#endif
3297 return 0;
3300 3298
3299out_unlock:
3300 mutex_unlock(&tp->control);
3301 usb_autopm_put_interface(tp->intf);
3302out_free:
3303 free_all_mem(tp);
3301out: 3304out:
3302 return res; 3305 return res;
3303} 3306}
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index fad84f3f4109..cbf1c613c67a 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -969,12 +969,17 @@ static int virtnet_set_mac_address(struct net_device *dev, void *p)
969 struct virtnet_info *vi = netdev_priv(dev); 969 struct virtnet_info *vi = netdev_priv(dev);
970 struct virtio_device *vdev = vi->vdev; 970 struct virtio_device *vdev = vi->vdev;
971 int ret; 971 int ret;
972 struct sockaddr *addr = p; 972 struct sockaddr *addr;
973 struct scatterlist sg; 973 struct scatterlist sg;
974 974
975 ret = eth_prepare_mac_addr_change(dev, p); 975 addr = kmalloc(sizeof(*addr), GFP_KERNEL);
976 if (!addr)
977 return -ENOMEM;
978 memcpy(addr, p, sizeof(*addr));
979
980 ret = eth_prepare_mac_addr_change(dev, addr);
976 if (ret) 981 if (ret)
977 return ret; 982 goto out;
978 983
979 if (virtio_has_feature(vdev, VIRTIO_NET_F_CTRL_MAC_ADDR)) { 984 if (virtio_has_feature(vdev, VIRTIO_NET_F_CTRL_MAC_ADDR)) {
980 sg_init_one(&sg, addr->sa_data, dev->addr_len); 985 sg_init_one(&sg, addr->sa_data, dev->addr_len);
@@ -982,7 +987,8 @@ static int virtnet_set_mac_address(struct net_device *dev, void *p)
982 VIRTIO_NET_CTRL_MAC_ADDR_SET, &sg)) { 987 VIRTIO_NET_CTRL_MAC_ADDR_SET, &sg)) {
983 dev_warn(&vdev->dev, 988 dev_warn(&vdev->dev,
984 "Failed to set mac address by vq command.\n"); 989 "Failed to set mac address by vq command.\n");
985 return -EINVAL; 990 ret = -EINVAL;
991 goto out;
986 } 992 }
987 } else if (virtio_has_feature(vdev, VIRTIO_NET_F_MAC) && 993 } else if (virtio_has_feature(vdev, VIRTIO_NET_F_MAC) &&
988 !virtio_has_feature(vdev, VIRTIO_F_VERSION_1)) { 994 !virtio_has_feature(vdev, VIRTIO_F_VERSION_1)) {
@@ -996,8 +1002,11 @@ static int virtnet_set_mac_address(struct net_device *dev, void *p)
996 } 1002 }
997 1003
998 eth_commit_mac_addr_change(dev, p); 1004 eth_commit_mac_addr_change(dev, p);
1005 ret = 0;
999 1006
1000 return 0; 1007out:
1008 kfree(addr);
1009 return ret;
1001} 1010}
1002 1011
1003static struct rtnl_link_stats64 *virtnet_stats(struct net_device *dev, 1012static struct rtnl_link_stats64 *virtnet_stats(struct net_device *dev,
@@ -1497,6 +1506,11 @@ static void virtnet_free_queues(struct virtnet_info *vi)
1497 netif_napi_del(&vi->rq[i].napi); 1506 netif_napi_del(&vi->rq[i].napi);
1498 } 1507 }
1499 1508
1509 /* We called napi_hash_del() before netif_napi_del(),
1510 * we need to respect an RCU grace period before freeing vi->rq
1511 */
1512 synchronize_net();
1513
1500 kfree(vi->rq); 1514 kfree(vi->rq);
1501 kfree(vi->sq); 1515 kfree(vi->sq);
1502} 1516}
@@ -2038,23 +2052,33 @@ static struct virtio_device_id id_table[] = {
2038 { 0 }, 2052 { 0 },
2039}; 2053};
2040 2054
2055#define VIRTNET_FEATURES \
2056 VIRTIO_NET_F_CSUM, VIRTIO_NET_F_GUEST_CSUM, \
2057 VIRTIO_NET_F_MAC, \
2058 VIRTIO_NET_F_HOST_TSO4, VIRTIO_NET_F_HOST_UFO, VIRTIO_NET_F_HOST_TSO6, \
2059 VIRTIO_NET_F_HOST_ECN, VIRTIO_NET_F_GUEST_TSO4, VIRTIO_NET_F_GUEST_TSO6, \
2060 VIRTIO_NET_F_GUEST_ECN, VIRTIO_NET_F_GUEST_UFO, \
2061 VIRTIO_NET_F_MRG_RXBUF, VIRTIO_NET_F_STATUS, VIRTIO_NET_F_CTRL_VQ, \
2062 VIRTIO_NET_F_CTRL_RX, VIRTIO_NET_F_CTRL_VLAN, \
2063 VIRTIO_NET_F_GUEST_ANNOUNCE, VIRTIO_NET_F_MQ, \
2064 VIRTIO_NET_F_CTRL_MAC_ADDR, \
2065 VIRTIO_NET_F_MTU
2066
2041static unsigned int features[] = { 2067static unsigned int features[] = {
2042 VIRTIO_NET_F_CSUM, VIRTIO_NET_F_GUEST_CSUM, 2068 VIRTNET_FEATURES,
2043 VIRTIO_NET_F_GSO, VIRTIO_NET_F_MAC, 2069};
2044 VIRTIO_NET_F_HOST_TSO4, VIRTIO_NET_F_HOST_UFO, VIRTIO_NET_F_HOST_TSO6, 2070
2045 VIRTIO_NET_F_HOST_ECN, VIRTIO_NET_F_GUEST_TSO4, VIRTIO_NET_F_GUEST_TSO6, 2071static unsigned int features_legacy[] = {
2046 VIRTIO_NET_F_GUEST_ECN, VIRTIO_NET_F_GUEST_UFO, 2072 VIRTNET_FEATURES,
2047 VIRTIO_NET_F_MRG_RXBUF, VIRTIO_NET_F_STATUS, VIRTIO_NET_F_CTRL_VQ, 2073 VIRTIO_NET_F_GSO,
2048 VIRTIO_NET_F_CTRL_RX, VIRTIO_NET_F_CTRL_VLAN,
2049 VIRTIO_NET_F_GUEST_ANNOUNCE, VIRTIO_NET_F_MQ,
2050 VIRTIO_NET_F_CTRL_MAC_ADDR,
2051 VIRTIO_F_ANY_LAYOUT, 2074 VIRTIO_F_ANY_LAYOUT,
2052 VIRTIO_NET_F_MTU,
2053}; 2075};
2054 2076
2055static struct virtio_driver virtio_net_driver = { 2077static struct virtio_driver virtio_net_driver = {
2056 .feature_table = features, 2078 .feature_table = features,
2057 .feature_table_size = ARRAY_SIZE(features), 2079 .feature_table_size = ARRAY_SIZE(features),
2080 .feature_table_legacy = features_legacy,
2081 .feature_table_size_legacy = ARRAY_SIZE(features_legacy),
2058 .driver.name = KBUILD_MODNAME, 2082 .driver.name = KBUILD_MODNAME,
2059 .driver.owner = THIS_MODULE, 2083 .driver.owner = THIS_MODULE,
2060 .id_table = id_table, 2084 .id_table = id_table,
diff --git a/drivers/net/vmxnet3/vmxnet3_drv.c b/drivers/net/vmxnet3/vmxnet3_drv.c
index b5554f2ebee4..ef83ae3b0a44 100644
--- a/drivers/net/vmxnet3/vmxnet3_drv.c
+++ b/drivers/net/vmxnet3/vmxnet3_drv.c
@@ -2279,6 +2279,7 @@ vmxnet3_set_mc(struct net_device *netdev)
2279 &adapter->shared->devRead.rxFilterConf; 2279 &adapter->shared->devRead.rxFilterConf;
2280 u8 *new_table = NULL; 2280 u8 *new_table = NULL;
2281 dma_addr_t new_table_pa = 0; 2281 dma_addr_t new_table_pa = 0;
2282 bool new_table_pa_valid = false;
2282 u32 new_mode = VMXNET3_RXM_UCAST; 2283 u32 new_mode = VMXNET3_RXM_UCAST;
2283 2284
2284 if (netdev->flags & IFF_PROMISC) { 2285 if (netdev->flags & IFF_PROMISC) {
@@ -2307,13 +2308,15 @@ vmxnet3_set_mc(struct net_device *netdev)
2307 new_table, 2308 new_table,
2308 sz, 2309 sz,
2309 PCI_DMA_TODEVICE); 2310 PCI_DMA_TODEVICE);
2311 if (!dma_mapping_error(&adapter->pdev->dev,
2312 new_table_pa)) {
2313 new_mode |= VMXNET3_RXM_MCAST;
2314 new_table_pa_valid = true;
2315 rxConf->mfTablePA = cpu_to_le64(
2316 new_table_pa);
2317 }
2310 } 2318 }
2311 2319 if (!new_table_pa_valid) {
2312 if (!dma_mapping_error(&adapter->pdev->dev,
2313 new_table_pa)) {
2314 new_mode |= VMXNET3_RXM_MCAST;
2315 rxConf->mfTablePA = cpu_to_le64(new_table_pa);
2316 } else {
2317 netdev_info(netdev, 2320 netdev_info(netdev,
2318 "failed to copy mcast list, setting ALL_MULTI\n"); 2321 "failed to copy mcast list, setting ALL_MULTI\n");
2319 new_mode |= VMXNET3_RXM_ALL_MULTI; 2322 new_mode |= VMXNET3_RXM_ALL_MULTI;
@@ -2338,7 +2341,7 @@ vmxnet3_set_mc(struct net_device *netdev)
2338 VMXNET3_CMD_UPDATE_MAC_FILTERS); 2341 VMXNET3_CMD_UPDATE_MAC_FILTERS);
2339 spin_unlock_irqrestore(&adapter->cmd_lock, flags); 2342 spin_unlock_irqrestore(&adapter->cmd_lock, flags);
2340 2343
2341 if (new_table_pa) 2344 if (new_table_pa_valid)
2342 dma_unmap_single(&adapter->pdev->dev, new_table_pa, 2345 dma_unmap_single(&adapter->pdev->dev, new_table_pa,
2343 rxConf->mfTableLen, PCI_DMA_TODEVICE); 2346 rxConf->mfTableLen, PCI_DMA_TODEVICE);
2344 kfree(new_table); 2347 kfree(new_table);
diff --git a/drivers/net/vrf.c b/drivers/net/vrf.c
index 85c271c70d42..820de6a9ddde 100644
--- a/drivers/net/vrf.c
+++ b/drivers/net/vrf.c
@@ -956,6 +956,7 @@ static struct sk_buff *vrf_ip6_rcv(struct net_device *vrf_dev,
956 if (skb->pkt_type == PACKET_LOOPBACK) { 956 if (skb->pkt_type == PACKET_LOOPBACK) {
957 skb->dev = vrf_dev; 957 skb->dev = vrf_dev;
958 skb->skb_iif = vrf_dev->ifindex; 958 skb->skb_iif = vrf_dev->ifindex;
959 IP6CB(skb)->flags |= IP6SKB_L3SLAVE;
959 skb->pkt_type = PACKET_HOST; 960 skb->pkt_type = PACKET_HOST;
960 goto out; 961 goto out;
961 } 962 }
@@ -996,6 +997,7 @@ static struct sk_buff *vrf_ip_rcv(struct net_device *vrf_dev,
996{ 997{
997 skb->dev = vrf_dev; 998 skb->dev = vrf_dev;
998 skb->skb_iif = vrf_dev->ifindex; 999 skb->skb_iif = vrf_dev->ifindex;
1000 IPCB(skb)->flags |= IPSKB_L3SLAVE;
999 1001
1000 /* loopback traffic; do not push through packet taps again. 1002 /* loopback traffic; do not push through packet taps again.
1001 * Reset pkt_type for upper layers to process skb 1003 * Reset pkt_type for upper layers to process skb
diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
index e7d16687538b..2ba01ca02c9c 100644
--- a/drivers/net/vxlan.c
+++ b/drivers/net/vxlan.c
@@ -583,7 +583,7 @@ static struct sk_buff **vxlan_gro_receive(struct sock *sk,
583 } 583 }
584 } 584 }
585 585
586 pp = eth_gro_receive(head, skb); 586 pp = call_gro_receive(eth_gro_receive, head, skb);
587 flush = 0; 587 flush = 0;
588 588
589out: 589out:
@@ -611,6 +611,7 @@ static int vxlan_fdb_create(struct vxlan_dev *vxlan,
611 struct vxlan_rdst *rd = NULL; 611 struct vxlan_rdst *rd = NULL;
612 struct vxlan_fdb *f; 612 struct vxlan_fdb *f;
613 int notify = 0; 613 int notify = 0;
614 int rc;
614 615
615 f = __vxlan_find_mac(vxlan, mac); 616 f = __vxlan_find_mac(vxlan, mac);
616 if (f) { 617 if (f) {
@@ -641,8 +642,7 @@ static int vxlan_fdb_create(struct vxlan_dev *vxlan,
641 if ((flags & NLM_F_APPEND) && 642 if ((flags & NLM_F_APPEND) &&
642 (is_multicast_ether_addr(f->eth_addr) || 643 (is_multicast_ether_addr(f->eth_addr) ||
643 is_zero_ether_addr(f->eth_addr))) { 644 is_zero_ether_addr(f->eth_addr))) {
644 int rc = vxlan_fdb_append(f, ip, port, vni, ifindex, 645 rc = vxlan_fdb_append(f, ip, port, vni, ifindex, &rd);
645 &rd);
646 646
647 if (rc < 0) 647 if (rc < 0)
648 return rc; 648 return rc;
@@ -673,7 +673,11 @@ static int vxlan_fdb_create(struct vxlan_dev *vxlan,
673 INIT_LIST_HEAD(&f->remotes); 673 INIT_LIST_HEAD(&f->remotes);
674 memcpy(f->eth_addr, mac, ETH_ALEN); 674 memcpy(f->eth_addr, mac, ETH_ALEN);
675 675
676 vxlan_fdb_append(f, ip, port, vni, ifindex, &rd); 676 rc = vxlan_fdb_append(f, ip, port, vni, ifindex, &rd);
677 if (rc < 0) {
678 kfree(f);
679 return rc;
680 }
677 681
678 ++vxlan->addrcnt; 682 ++vxlan->addrcnt;
679 hlist_add_head_rcu(&f->hlist, 683 hlist_add_head_rcu(&f->hlist,
@@ -943,17 +947,22 @@ static bool vxlan_snoop(struct net_device *dev,
943static bool vxlan_group_used(struct vxlan_net *vn, struct vxlan_dev *dev) 947static bool vxlan_group_used(struct vxlan_net *vn, struct vxlan_dev *dev)
944{ 948{
945 struct vxlan_dev *vxlan; 949 struct vxlan_dev *vxlan;
950 struct vxlan_sock *sock4;
951#if IS_ENABLED(CONFIG_IPV6)
952 struct vxlan_sock *sock6;
953#endif
946 unsigned short family = dev->default_dst.remote_ip.sa.sa_family; 954 unsigned short family = dev->default_dst.remote_ip.sa.sa_family;
947 955
956 sock4 = rtnl_dereference(dev->vn4_sock);
957
948 /* The vxlan_sock is only used by dev, leaving group has 958 /* The vxlan_sock is only used by dev, leaving group has
949 * no effect on other vxlan devices. 959 * no effect on other vxlan devices.
950 */ 960 */
951 if (family == AF_INET && dev->vn4_sock && 961 if (family == AF_INET && sock4 && atomic_read(&sock4->refcnt) == 1)
952 atomic_read(&dev->vn4_sock->refcnt) == 1)
953 return false; 962 return false;
954#if IS_ENABLED(CONFIG_IPV6) 963#if IS_ENABLED(CONFIG_IPV6)
955 if (family == AF_INET6 && dev->vn6_sock && 964 sock6 = rtnl_dereference(dev->vn6_sock);
956 atomic_read(&dev->vn6_sock->refcnt) == 1) 965 if (family == AF_INET6 && sock6 && atomic_read(&sock6->refcnt) == 1)
957 return false; 966 return false;
958#endif 967#endif
959 968
@@ -961,10 +970,12 @@ static bool vxlan_group_used(struct vxlan_net *vn, struct vxlan_dev *dev)
961 if (!netif_running(vxlan->dev) || vxlan == dev) 970 if (!netif_running(vxlan->dev) || vxlan == dev)
962 continue; 971 continue;
963 972
964 if (family == AF_INET && vxlan->vn4_sock != dev->vn4_sock) 973 if (family == AF_INET &&
974 rtnl_dereference(vxlan->vn4_sock) != sock4)
965 continue; 975 continue;
966#if IS_ENABLED(CONFIG_IPV6) 976#if IS_ENABLED(CONFIG_IPV6)
967 if (family == AF_INET6 && vxlan->vn6_sock != dev->vn6_sock) 977 if (family == AF_INET6 &&
978 rtnl_dereference(vxlan->vn6_sock) != sock6)
968 continue; 979 continue;
969#endif 980#endif
970 981
@@ -1005,22 +1016,25 @@ static bool __vxlan_sock_release_prep(struct vxlan_sock *vs)
1005 1016
1006static void vxlan_sock_release(struct vxlan_dev *vxlan) 1017static void vxlan_sock_release(struct vxlan_dev *vxlan)
1007{ 1018{
1008 bool ipv4 = __vxlan_sock_release_prep(vxlan->vn4_sock); 1019 struct vxlan_sock *sock4 = rtnl_dereference(vxlan->vn4_sock);
1009#if IS_ENABLED(CONFIG_IPV6) 1020#if IS_ENABLED(CONFIG_IPV6)
1010 bool ipv6 = __vxlan_sock_release_prep(vxlan->vn6_sock); 1021 struct vxlan_sock *sock6 = rtnl_dereference(vxlan->vn6_sock);
1022
1023 rcu_assign_pointer(vxlan->vn6_sock, NULL);
1011#endif 1024#endif
1012 1025
1026 rcu_assign_pointer(vxlan->vn4_sock, NULL);
1013 synchronize_net(); 1027 synchronize_net();
1014 1028
1015 if (ipv4) { 1029 if (__vxlan_sock_release_prep(sock4)) {
1016 udp_tunnel_sock_release(vxlan->vn4_sock->sock); 1030 udp_tunnel_sock_release(sock4->sock);
1017 kfree(vxlan->vn4_sock); 1031 kfree(sock4);
1018 } 1032 }
1019 1033
1020#if IS_ENABLED(CONFIG_IPV6) 1034#if IS_ENABLED(CONFIG_IPV6)
1021 if (ipv6) { 1035 if (__vxlan_sock_release_prep(sock6)) {
1022 udp_tunnel_sock_release(vxlan->vn6_sock->sock); 1036 udp_tunnel_sock_release(sock6->sock);
1023 kfree(vxlan->vn6_sock); 1037 kfree(sock6);
1024 } 1038 }
1025#endif 1039#endif
1026} 1040}
@@ -1036,18 +1050,21 @@ static int vxlan_igmp_join(struct vxlan_dev *vxlan)
1036 int ret = -EINVAL; 1050 int ret = -EINVAL;
1037 1051
1038 if (ip->sa.sa_family == AF_INET) { 1052 if (ip->sa.sa_family == AF_INET) {
1053 struct vxlan_sock *sock4 = rtnl_dereference(vxlan->vn4_sock);
1039 struct ip_mreqn mreq = { 1054 struct ip_mreqn mreq = {
1040 .imr_multiaddr.s_addr = ip->sin.sin_addr.s_addr, 1055 .imr_multiaddr.s_addr = ip->sin.sin_addr.s_addr,
1041 .imr_ifindex = ifindex, 1056 .imr_ifindex = ifindex,
1042 }; 1057 };
1043 1058
1044 sk = vxlan->vn4_sock->sock->sk; 1059 sk = sock4->sock->sk;
1045 lock_sock(sk); 1060 lock_sock(sk);
1046 ret = ip_mc_join_group(sk, &mreq); 1061 ret = ip_mc_join_group(sk, &mreq);
1047 release_sock(sk); 1062 release_sock(sk);
1048#if IS_ENABLED(CONFIG_IPV6) 1063#if IS_ENABLED(CONFIG_IPV6)
1049 } else { 1064 } else {
1050 sk = vxlan->vn6_sock->sock->sk; 1065 struct vxlan_sock *sock6 = rtnl_dereference(vxlan->vn6_sock);
1066
1067 sk = sock6->sock->sk;
1051 lock_sock(sk); 1068 lock_sock(sk);
1052 ret = ipv6_stub->ipv6_sock_mc_join(sk, ifindex, 1069 ret = ipv6_stub->ipv6_sock_mc_join(sk, ifindex,
1053 &ip->sin6.sin6_addr); 1070 &ip->sin6.sin6_addr);
@@ -1067,18 +1084,21 @@ static int vxlan_igmp_leave(struct vxlan_dev *vxlan)
1067 int ret = -EINVAL; 1084 int ret = -EINVAL;
1068 1085
1069 if (ip->sa.sa_family == AF_INET) { 1086 if (ip->sa.sa_family == AF_INET) {
1087 struct vxlan_sock *sock4 = rtnl_dereference(vxlan->vn4_sock);
1070 struct ip_mreqn mreq = { 1088 struct ip_mreqn mreq = {
1071 .imr_multiaddr.s_addr = ip->sin.sin_addr.s_addr, 1089 .imr_multiaddr.s_addr = ip->sin.sin_addr.s_addr,
1072 .imr_ifindex = ifindex, 1090 .imr_ifindex = ifindex,
1073 }; 1091 };
1074 1092
1075 sk = vxlan->vn4_sock->sock->sk; 1093 sk = sock4->sock->sk;
1076 lock_sock(sk); 1094 lock_sock(sk);
1077 ret = ip_mc_leave_group(sk, &mreq); 1095 ret = ip_mc_leave_group(sk, &mreq);
1078 release_sock(sk); 1096 release_sock(sk);
1079#if IS_ENABLED(CONFIG_IPV6) 1097#if IS_ENABLED(CONFIG_IPV6)
1080 } else { 1098 } else {
1081 sk = vxlan->vn6_sock->sock->sk; 1099 struct vxlan_sock *sock6 = rtnl_dereference(vxlan->vn6_sock);
1100
1101 sk = sock6->sock->sk;
1082 lock_sock(sk); 1102 lock_sock(sk);
1083 ret = ipv6_stub->ipv6_sock_mc_drop(sk, ifindex, 1103 ret = ipv6_stub->ipv6_sock_mc_drop(sk, ifindex,
1084 &ip->sin6.sin6_addr); 1104 &ip->sin6.sin6_addr);
@@ -1828,11 +1848,15 @@ static struct dst_entry *vxlan6_get_route(struct vxlan_dev *vxlan,
1828 struct dst_cache *dst_cache, 1848 struct dst_cache *dst_cache,
1829 const struct ip_tunnel_info *info) 1849 const struct ip_tunnel_info *info)
1830{ 1850{
1851 struct vxlan_sock *sock6 = rcu_dereference(vxlan->vn6_sock);
1831 bool use_cache = ip_tunnel_dst_cache_usable(skb, info); 1852 bool use_cache = ip_tunnel_dst_cache_usable(skb, info);
1832 struct dst_entry *ndst; 1853 struct dst_entry *ndst;
1833 struct flowi6 fl6; 1854 struct flowi6 fl6;
1834 int err; 1855 int err;
1835 1856
1857 if (!sock6)
1858 return ERR_PTR(-EIO);
1859
1836 if (tos && !info) 1860 if (tos && !info)
1837 use_cache = false; 1861 use_cache = false;
1838 if (use_cache) { 1862 if (use_cache) {
@@ -1850,7 +1874,7 @@ static struct dst_entry *vxlan6_get_route(struct vxlan_dev *vxlan,
1850 fl6.flowi6_proto = IPPROTO_UDP; 1874 fl6.flowi6_proto = IPPROTO_UDP;
1851 1875
1852 err = ipv6_stub->ipv6_dst_lookup(vxlan->net, 1876 err = ipv6_stub->ipv6_dst_lookup(vxlan->net,
1853 vxlan->vn6_sock->sock->sk, 1877 sock6->sock->sk,
1854 &ndst, &fl6); 1878 &ndst, &fl6);
1855 if (err < 0) 1879 if (err < 0)
1856 return ERR_PTR(err); 1880 return ERR_PTR(err);
@@ -1995,9 +2019,11 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
1995 } 2019 }
1996 2020
1997 if (dst->sa.sa_family == AF_INET) { 2021 if (dst->sa.sa_family == AF_INET) {
1998 if (!vxlan->vn4_sock) 2022 struct vxlan_sock *sock4 = rcu_dereference(vxlan->vn4_sock);
2023
2024 if (!sock4)
1999 goto drop; 2025 goto drop;
2000 sk = vxlan->vn4_sock->sock->sk; 2026 sk = sock4->sock->sk;
2001 2027
2002 rt = vxlan_get_route(vxlan, skb, 2028 rt = vxlan_get_route(vxlan, skb,
2003 rdst ? rdst->remote_ifindex : 0, tos, 2029 rdst ? rdst->remote_ifindex : 0, tos,
@@ -2050,12 +2076,13 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
2050 src_port, dst_port, xnet, !udp_sum); 2076 src_port, dst_port, xnet, !udp_sum);
2051#if IS_ENABLED(CONFIG_IPV6) 2077#if IS_ENABLED(CONFIG_IPV6)
2052 } else { 2078 } else {
2079 struct vxlan_sock *sock6 = rcu_dereference(vxlan->vn6_sock);
2053 struct dst_entry *ndst; 2080 struct dst_entry *ndst;
2054 u32 rt6i_flags; 2081 u32 rt6i_flags;
2055 2082
2056 if (!vxlan->vn6_sock) 2083 if (!sock6)
2057 goto drop; 2084 goto drop;
2058 sk = vxlan->vn6_sock->sock->sk; 2085 sk = sock6->sock->sk;
2059 2086
2060 ndst = vxlan6_get_route(vxlan, skb, 2087 ndst = vxlan6_get_route(vxlan, skb,
2061 rdst ? rdst->remote_ifindex : 0, tos, 2088 rdst ? rdst->remote_ifindex : 0, tos,
@@ -2415,9 +2442,10 @@ static int vxlan_fill_metadata_dst(struct net_device *dev, struct sk_buff *skb)
2415 dport = info->key.tp_dst ? : vxlan->cfg.dst_port; 2442 dport = info->key.tp_dst ? : vxlan->cfg.dst_port;
2416 2443
2417 if (ip_tunnel_info_af(info) == AF_INET) { 2444 if (ip_tunnel_info_af(info) == AF_INET) {
2445 struct vxlan_sock *sock4 = rcu_dereference(vxlan->vn4_sock);
2418 struct rtable *rt; 2446 struct rtable *rt;
2419 2447
2420 if (!vxlan->vn4_sock) 2448 if (!sock4)
2421 return -EINVAL; 2449 return -EINVAL;
2422 rt = vxlan_get_route(vxlan, skb, 0, info->key.tos, 2450 rt = vxlan_get_route(vxlan, skb, 0, info->key.tos,
2423 info->key.u.ipv4.dst, 2451 info->key.u.ipv4.dst,
@@ -2429,8 +2457,6 @@ static int vxlan_fill_metadata_dst(struct net_device *dev, struct sk_buff *skb)
2429#if IS_ENABLED(CONFIG_IPV6) 2457#if IS_ENABLED(CONFIG_IPV6)
2430 struct dst_entry *ndst; 2458 struct dst_entry *ndst;
2431 2459
2432 if (!vxlan->vn6_sock)
2433 return -EINVAL;
2434 ndst = vxlan6_get_route(vxlan, skb, 0, info->key.tos, 2460 ndst = vxlan6_get_route(vxlan, skb, 0, info->key.tos,
2435 info->key.label, &info->key.u.ipv6.dst, 2461 info->key.label, &info->key.u.ipv6.dst,
2436 &info->key.u.ipv6.src, NULL, info); 2462 &info->key.u.ipv6.src, NULL, info);
@@ -2740,10 +2766,10 @@ static int __vxlan_sock_add(struct vxlan_dev *vxlan, bool ipv6)
2740 return PTR_ERR(vs); 2766 return PTR_ERR(vs);
2741#if IS_ENABLED(CONFIG_IPV6) 2767#if IS_ENABLED(CONFIG_IPV6)
2742 if (ipv6) 2768 if (ipv6)
2743 vxlan->vn6_sock = vs; 2769 rcu_assign_pointer(vxlan->vn6_sock, vs);
2744 else 2770 else
2745#endif 2771#endif
2746 vxlan->vn4_sock = vs; 2772 rcu_assign_pointer(vxlan->vn4_sock, vs);
2747 vxlan_vs_add_dev(vs, vxlan); 2773 vxlan_vs_add_dev(vs, vxlan);
2748 return 0; 2774 return 0;
2749} 2775}
@@ -2754,9 +2780,9 @@ static int vxlan_sock_add(struct vxlan_dev *vxlan)
2754 bool metadata = vxlan->flags & VXLAN_F_COLLECT_METADATA; 2780 bool metadata = vxlan->flags & VXLAN_F_COLLECT_METADATA;
2755 int ret = 0; 2781 int ret = 0;
2756 2782
2757 vxlan->vn4_sock = NULL; 2783 RCU_INIT_POINTER(vxlan->vn4_sock, NULL);
2758#if IS_ENABLED(CONFIG_IPV6) 2784#if IS_ENABLED(CONFIG_IPV6)
2759 vxlan->vn6_sock = NULL; 2785 RCU_INIT_POINTER(vxlan->vn6_sock, NULL);
2760 if (ipv6 || metadata) 2786 if (ipv6 || metadata)
2761 ret = __vxlan_sock_add(vxlan, true); 2787 ret = __vxlan_sock_add(vxlan, true);
2762#endif 2788#endif
diff --git a/drivers/net/wan/Kconfig b/drivers/net/wan/Kconfig
index 33ab3345d333..4e9fe75d7067 100644
--- a/drivers/net/wan/Kconfig
+++ b/drivers/net/wan/Kconfig
@@ -294,7 +294,7 @@ config FSL_UCC_HDLC
294config SLIC_DS26522 294config SLIC_DS26522
295 tristate "Slic Maxim ds26522 card support" 295 tristate "Slic Maxim ds26522 card support"
296 depends on SPI 296 depends on SPI
297 depends on FSL_SOC || ARCH_MXC || ARCH_LAYERSCAPE 297 depends on FSL_SOC || ARCH_MXC || ARCH_LAYERSCAPE || COMPILE_TEST
298 help 298 help
299 This module initializes and configures the slic maxim card 299 This module initializes and configures the slic maxim card
300 in T1 or E1 mode. 300 in T1 or E1 mode.
diff --git a/drivers/net/wan/slic_ds26522.c b/drivers/net/wan/slic_ds26522.c
index d06a887a2352..b776a0ab106c 100644
--- a/drivers/net/wan/slic_ds26522.c
+++ b/drivers/net/wan/slic_ds26522.c
@@ -223,12 +223,19 @@ static int slic_ds26522_probe(struct spi_device *spi)
223 return ret; 223 return ret;
224} 224}
225 225
226static const struct spi_device_id slic_ds26522_id[] = {
227 { .name = "ds26522" },
228 { /* sentinel */ },
229};
230MODULE_DEVICE_TABLE(spi, slic_ds26522_id);
231
226static const struct of_device_id slic_ds26522_match[] = { 232static const struct of_device_id slic_ds26522_match[] = {
227 { 233 {
228 .compatible = "maxim,ds26522", 234 .compatible = "maxim,ds26522",
229 }, 235 },
230 {}, 236 {},
231}; 237};
238MODULE_DEVICE_TABLE(of, slic_ds26522_match);
232 239
233static struct spi_driver slic_ds26522_driver = { 240static struct spi_driver slic_ds26522_driver = {
234 .driver = { 241 .driver = {
@@ -239,6 +246,7 @@ static struct spi_driver slic_ds26522_driver = {
239 }, 246 },
240 .probe = slic_ds26522_probe, 247 .probe = slic_ds26522_probe,
241 .remove = slic_ds26522_remove, 248 .remove = slic_ds26522_remove,
249 .id_table = slic_ds26522_id,
242}; 250};
243 251
244static int __init slic_ds26522_init(void) 252static int __init slic_ds26522_init(void)
diff --git a/drivers/net/wireless/ath/ath10k/core.h b/drivers/net/wireless/ath/ath10k/core.h
index dda49af1eb74..521f1c55c19e 100644
--- a/drivers/net/wireless/ath/ath10k/core.h
+++ b/drivers/net/wireless/ath/ath10k/core.h
@@ -450,6 +450,7 @@ struct ath10k_debug {
450 u32 pktlog_filter; 450 u32 pktlog_filter;
451 u32 reg_addr; 451 u32 reg_addr;
452 u32 nf_cal_period; 452 u32 nf_cal_period;
453 void *cal_data;
453 454
454 struct ath10k_fw_crash_data *fw_crash_data; 455 struct ath10k_fw_crash_data *fw_crash_data;
455}; 456};
diff --git a/drivers/net/wireless/ath/ath10k/debug.c b/drivers/net/wireless/ath/ath10k/debug.c
index 832da6ed9f13..82a4c67f3672 100644
--- a/drivers/net/wireless/ath/ath10k/debug.c
+++ b/drivers/net/wireless/ath/ath10k/debug.c
@@ -30,6 +30,8 @@
30/* ms */ 30/* ms */
31#define ATH10K_DEBUG_HTT_STATS_INTERVAL 1000 31#define ATH10K_DEBUG_HTT_STATS_INTERVAL 1000
32 32
33#define ATH10K_DEBUG_CAL_DATA_LEN 12064
34
33#define ATH10K_FW_CRASH_DUMP_VERSION 1 35#define ATH10K_FW_CRASH_DUMP_VERSION 1
34 36
35/** 37/**
@@ -1451,56 +1453,51 @@ static const struct file_operations fops_fw_dbglog = {
1451 .llseek = default_llseek, 1453 .llseek = default_llseek,
1452}; 1454};
1453 1455
1454static int ath10k_debug_cal_data_open(struct inode *inode, struct file *file) 1456static int ath10k_debug_cal_data_fetch(struct ath10k *ar)
1455{ 1457{
1456 struct ath10k *ar = inode->i_private;
1457 void *buf;
1458 u32 hi_addr; 1458 u32 hi_addr;
1459 __le32 addr; 1459 __le32 addr;
1460 int ret; 1460 int ret;
1461 1461
1462 mutex_lock(&ar->conf_mutex); 1462 lockdep_assert_held(&ar->conf_mutex);
1463
1464 if (ar->state != ATH10K_STATE_ON &&
1465 ar->state != ATH10K_STATE_UTF) {
1466 ret = -ENETDOWN;
1467 goto err;
1468 }
1469 1463
1470 buf = vmalloc(ar->hw_params.cal_data_len); 1464 if (WARN_ON(ar->hw_params.cal_data_len > ATH10K_DEBUG_CAL_DATA_LEN))
1471 if (!buf) { 1465 return -EINVAL;
1472 ret = -ENOMEM;
1473 goto err;
1474 }
1475 1466
1476 hi_addr = host_interest_item_address(HI_ITEM(hi_board_data)); 1467 hi_addr = host_interest_item_address(HI_ITEM(hi_board_data));
1477 1468
1478 ret = ath10k_hif_diag_read(ar, hi_addr, &addr, sizeof(addr)); 1469 ret = ath10k_hif_diag_read(ar, hi_addr, &addr, sizeof(addr));
1479 if (ret) { 1470 if (ret) {
1480 ath10k_warn(ar, "failed to read hi_board_data address: %d\n", ret); 1471 ath10k_warn(ar, "failed to read hi_board_data address: %d\n",
1481 goto err_vfree; 1472 ret);
1473 return ret;
1482 } 1474 }
1483 1475
1484 ret = ath10k_hif_diag_read(ar, le32_to_cpu(addr), buf, 1476 ret = ath10k_hif_diag_read(ar, le32_to_cpu(addr), ar->debug.cal_data,
1485 ar->hw_params.cal_data_len); 1477 ar->hw_params.cal_data_len);
1486 if (ret) { 1478 if (ret) {
1487 ath10k_warn(ar, "failed to read calibration data: %d\n", ret); 1479 ath10k_warn(ar, "failed to read calibration data: %d\n", ret);
1488 goto err_vfree; 1480 return ret;
1489 } 1481 }
1490 1482
1491 file->private_data = buf; 1483 return 0;
1484}
1492 1485
1493 mutex_unlock(&ar->conf_mutex); 1486static int ath10k_debug_cal_data_open(struct inode *inode, struct file *file)
1487{
1488 struct ath10k *ar = inode->i_private;
1494 1489
1495 return 0; 1490 mutex_lock(&ar->conf_mutex);
1496 1491
1497err_vfree: 1492 if (ar->state == ATH10K_STATE_ON ||
1498 vfree(buf); 1493 ar->state == ATH10K_STATE_UTF) {
1494 ath10k_debug_cal_data_fetch(ar);
1495 }
1499 1496
1500err: 1497 file->private_data = ar;
1501 mutex_unlock(&ar->conf_mutex); 1498 mutex_unlock(&ar->conf_mutex);
1502 1499
1503 return ret; 1500 return 0;
1504} 1501}
1505 1502
1506static ssize_t ath10k_debug_cal_data_read(struct file *file, 1503static ssize_t ath10k_debug_cal_data_read(struct file *file,
@@ -1508,18 +1505,16 @@ static ssize_t ath10k_debug_cal_data_read(struct file *file,
1508 size_t count, loff_t *ppos) 1505 size_t count, loff_t *ppos)
1509{ 1506{
1510 struct ath10k *ar = file->private_data; 1507 struct ath10k *ar = file->private_data;
1511 void *buf = file->private_data;
1512 1508
1513 return simple_read_from_buffer(user_buf, count, ppos, 1509 mutex_lock(&ar->conf_mutex);
1514 buf, ar->hw_params.cal_data_len);
1515}
1516 1510
1517static int ath10k_debug_cal_data_release(struct inode *inode, 1511 count = simple_read_from_buffer(user_buf, count, ppos,
1518 struct file *file) 1512 ar->debug.cal_data,
1519{ 1513 ar->hw_params.cal_data_len);
1520 vfree(file->private_data);
1521 1514
1522 return 0; 1515 mutex_unlock(&ar->conf_mutex);
1516
1517 return count;
1523} 1518}
1524 1519
1525static ssize_t ath10k_write_ani_enable(struct file *file, 1520static ssize_t ath10k_write_ani_enable(struct file *file,
@@ -1580,7 +1575,6 @@ static const struct file_operations fops_ani_enable = {
1580static const struct file_operations fops_cal_data = { 1575static const struct file_operations fops_cal_data = {
1581 .open = ath10k_debug_cal_data_open, 1576 .open = ath10k_debug_cal_data_open,
1582 .read = ath10k_debug_cal_data_read, 1577 .read = ath10k_debug_cal_data_read,
1583 .release = ath10k_debug_cal_data_release,
1584 .owner = THIS_MODULE, 1578 .owner = THIS_MODULE,
1585 .llseek = default_llseek, 1579 .llseek = default_llseek,
1586}; 1580};
@@ -1932,6 +1926,8 @@ void ath10k_debug_stop(struct ath10k *ar)
1932{ 1926{
1933 lockdep_assert_held(&ar->conf_mutex); 1927 lockdep_assert_held(&ar->conf_mutex);
1934 1928
1929 ath10k_debug_cal_data_fetch(ar);
1930
1935 /* Must not use _sync to avoid deadlock, we do that in 1931 /* Must not use _sync to avoid deadlock, we do that in
1936 * ath10k_debug_destroy(). The check for htt_stats_mask is to avoid 1932 * ath10k_debug_destroy(). The check for htt_stats_mask is to avoid
1937 * warning from del_timer(). */ 1933 * warning from del_timer(). */
@@ -2344,6 +2340,10 @@ int ath10k_debug_create(struct ath10k *ar)
2344 if (!ar->debug.fw_crash_data) 2340 if (!ar->debug.fw_crash_data)
2345 return -ENOMEM; 2341 return -ENOMEM;
2346 2342
2343 ar->debug.cal_data = vzalloc(ATH10K_DEBUG_CAL_DATA_LEN);
2344 if (!ar->debug.cal_data)
2345 return -ENOMEM;
2346
2347 INIT_LIST_HEAD(&ar->debug.fw_stats.pdevs); 2347 INIT_LIST_HEAD(&ar->debug.fw_stats.pdevs);
2348 INIT_LIST_HEAD(&ar->debug.fw_stats.vdevs); 2348 INIT_LIST_HEAD(&ar->debug.fw_stats.vdevs);
2349 INIT_LIST_HEAD(&ar->debug.fw_stats.peers); 2349 INIT_LIST_HEAD(&ar->debug.fw_stats.peers);
@@ -2357,6 +2357,9 @@ void ath10k_debug_destroy(struct ath10k *ar)
2357 vfree(ar->debug.fw_crash_data); 2357 vfree(ar->debug.fw_crash_data);
2358 ar->debug.fw_crash_data = NULL; 2358 ar->debug.fw_crash_data = NULL;
2359 2359
2360 vfree(ar->debug.cal_data);
2361 ar->debug.cal_data = NULL;
2362
2360 ath10k_debug_fw_stats_reset(ar); 2363 ath10k_debug_fw_stats_reset(ar);
2361 2364
2362 kfree(ar->debug.tpc_stats); 2365 kfree(ar->debug.tpc_stats);
diff --git a/drivers/net/wireless/ath/ath6kl/sdio.c b/drivers/net/wireless/ath/ath6kl/sdio.c
index eab0ab976af2..76eb33679d4b 100644
--- a/drivers/net/wireless/ath/ath6kl/sdio.c
+++ b/drivers/net/wireless/ath/ath6kl/sdio.c
@@ -1401,6 +1401,7 @@ static const struct sdio_device_id ath6kl_sdio_devices[] = {
1401 {SDIO_DEVICE(MANUFACTURER_CODE, (MANUFACTURER_ID_AR6004_BASE | 0x0))}, 1401 {SDIO_DEVICE(MANUFACTURER_CODE, (MANUFACTURER_ID_AR6004_BASE | 0x0))},
1402 {SDIO_DEVICE(MANUFACTURER_CODE, (MANUFACTURER_ID_AR6004_BASE | 0x1))}, 1402 {SDIO_DEVICE(MANUFACTURER_CODE, (MANUFACTURER_ID_AR6004_BASE | 0x1))},
1403 {SDIO_DEVICE(MANUFACTURER_CODE, (MANUFACTURER_ID_AR6004_BASE | 0x2))}, 1403 {SDIO_DEVICE(MANUFACTURER_CODE, (MANUFACTURER_ID_AR6004_BASE | 0x2))},
1404 {SDIO_DEVICE(MANUFACTURER_CODE, (MANUFACTURER_ID_AR6004_BASE | 0x18))},
1404 {}, 1405 {},
1405}; 1406};
1406 1407
diff --git a/drivers/net/wireless/ath/ath9k/ar9003_calib.c b/drivers/net/wireless/ath/ath9k/ar9003_calib.c
index b6f064a8d264..7e27a06e5df1 100644
--- a/drivers/net/wireless/ath/ath9k/ar9003_calib.c
+++ b/drivers/net/wireless/ath/ath9k/ar9003_calib.c
@@ -33,7 +33,6 @@ struct coeff {
33 33
34enum ar9003_cal_types { 34enum ar9003_cal_types {
35 IQ_MISMATCH_CAL = BIT(0), 35 IQ_MISMATCH_CAL = BIT(0),
36 TEMP_COMP_CAL = BIT(1),
37}; 36};
38 37
39static void ar9003_hw_setup_calibration(struct ath_hw *ah, 38static void ar9003_hw_setup_calibration(struct ath_hw *ah,
@@ -59,12 +58,6 @@ static void ar9003_hw_setup_calibration(struct ath_hw *ah,
59 /* Kick-off cal */ 58 /* Kick-off cal */
60 REG_SET_BIT(ah, AR_PHY_TIMING4, AR_PHY_TIMING4_DO_CAL); 59 REG_SET_BIT(ah, AR_PHY_TIMING4, AR_PHY_TIMING4_DO_CAL);
61 break; 60 break;
62 case TEMP_COMP_CAL:
63 ath_dbg(common, CALIBRATE,
64 "starting Temperature Compensation Calibration\n");
65 REG_SET_BIT(ah, AR_CH0_THERM, AR_CH0_THERM_LOCAL);
66 REG_SET_BIT(ah, AR_CH0_THERM, AR_CH0_THERM_START);
67 break;
68 default: 61 default:
69 ath_err(common, "Invalid calibration type\n"); 62 ath_err(common, "Invalid calibration type\n");
70 break; 63 break;
@@ -93,8 +86,7 @@ static bool ar9003_hw_per_calibration(struct ath_hw *ah,
93 /* 86 /*
94 * Accumulate cal measures for active chains 87 * Accumulate cal measures for active chains
95 */ 88 */
96 if (cur_caldata->calCollect) 89 cur_caldata->calCollect(ah);
97 cur_caldata->calCollect(ah);
98 ah->cal_samples++; 90 ah->cal_samples++;
99 91
100 if (ah->cal_samples >= cur_caldata->calNumSamples) { 92 if (ah->cal_samples >= cur_caldata->calNumSamples) {
@@ -107,8 +99,7 @@ static bool ar9003_hw_per_calibration(struct ath_hw *ah,
107 /* 99 /*
108 * Process accumulated data 100 * Process accumulated data
109 */ 101 */
110 if (cur_caldata->calPostProc) 102 cur_caldata->calPostProc(ah, numChains);
111 cur_caldata->calPostProc(ah, numChains);
112 103
113 /* Calibration has finished. */ 104 /* Calibration has finished. */
114 caldata->CalValid |= cur_caldata->calType; 105 caldata->CalValid |= cur_caldata->calType;
@@ -323,16 +314,9 @@ static const struct ath9k_percal_data iq_cal_single_sample = {
323 ar9003_hw_iqcalibrate 314 ar9003_hw_iqcalibrate
324}; 315};
325 316
326static const struct ath9k_percal_data temp_cal_single_sample = {
327 TEMP_COMP_CAL,
328 MIN_CAL_SAMPLES,
329 PER_MAX_LOG_COUNT,
330};
331
332static void ar9003_hw_init_cal_settings(struct ath_hw *ah) 317static void ar9003_hw_init_cal_settings(struct ath_hw *ah)
333{ 318{
334 ah->iq_caldata.calData = &iq_cal_single_sample; 319 ah->iq_caldata.calData = &iq_cal_single_sample;
335 ah->temp_caldata.calData = &temp_cal_single_sample;
336 320
337 if (AR_SREV_9300_20_OR_LATER(ah)) { 321 if (AR_SREV_9300_20_OR_LATER(ah)) {
338 ah->enabled_cals |= TX_IQ_CAL; 322 ah->enabled_cals |= TX_IQ_CAL;
@@ -340,7 +324,7 @@ static void ar9003_hw_init_cal_settings(struct ath_hw *ah)
340 ah->enabled_cals |= TX_IQ_ON_AGC_CAL; 324 ah->enabled_cals |= TX_IQ_ON_AGC_CAL;
341 } 325 }
342 326
343 ah->supp_cals = IQ_MISMATCH_CAL | TEMP_COMP_CAL; 327 ah->supp_cals = IQ_MISMATCH_CAL;
344} 328}
345 329
346#define OFF_UPPER_LT 24 330#define OFF_UPPER_LT 24
@@ -1399,9 +1383,6 @@ static void ar9003_hw_init_cal_common(struct ath_hw *ah)
1399 INIT_CAL(&ah->iq_caldata); 1383 INIT_CAL(&ah->iq_caldata);
1400 INSERT_CAL(ah, &ah->iq_caldata); 1384 INSERT_CAL(ah, &ah->iq_caldata);
1401 1385
1402 INIT_CAL(&ah->temp_caldata);
1403 INSERT_CAL(ah, &ah->temp_caldata);
1404
1405 /* Initialize current pointer to first element in list */ 1386 /* Initialize current pointer to first element in list */
1406 ah->cal_list_curr = ah->cal_list; 1387 ah->cal_list_curr = ah->cal_list;
1407 1388
diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
index 2a5d3ad1169c..9cbca1229bac 100644
--- a/drivers/net/wireless/ath/ath9k/hw.h
+++ b/drivers/net/wireless/ath/ath9k/hw.h
@@ -830,7 +830,6 @@ struct ath_hw {
830 /* Calibration */ 830 /* Calibration */
831 u32 supp_cals; 831 u32 supp_cals;
832 struct ath9k_cal_list iq_caldata; 832 struct ath9k_cal_list iq_caldata;
833 struct ath9k_cal_list temp_caldata;
834 struct ath9k_cal_list adcgain_caldata; 833 struct ath9k_cal_list adcgain_caldata;
835 struct ath9k_cal_list adcdc_caldata; 834 struct ath9k_cal_list adcdc_caldata;
836 struct ath9k_cal_list *cal_list; 835 struct ath9k_cal_list *cal_list;
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c
index b777e1b2f87a..78d9966a3957 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c
@@ -4516,7 +4516,7 @@ brcmf_cfg80211_start_ap(struct wiphy *wiphy, struct net_device *ndev,
4516 /* store current 11d setting */ 4516 /* store current 11d setting */
4517 if (brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_REGULATORY, 4517 if (brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_REGULATORY,
4518 &ifp->vif->is_11d)) { 4518 &ifp->vif->is_11d)) {
4519 supports_11d = false; 4519 is_11d = supports_11d = false;
4520 } else { 4520 } else {
4521 country_ie = brcmf_parse_tlvs((u8 *)settings->beacon.tail, 4521 country_ie = brcmf_parse_tlvs((u8 *)settings->beacon.tail,
4522 settings->beacon.tail_len, 4522 settings->beacon.tail_len,
diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/d3.c b/drivers/net/wireless/intel/iwlwifi/mvm/d3.c
index 4fdc3dad3e85..b88e2048ae0b 100644
--- a/drivers/net/wireless/intel/iwlwifi/mvm/d3.c
+++ b/drivers/net/wireless/intel/iwlwifi/mvm/d3.c
@@ -1087,6 +1087,15 @@ iwl_mvm_netdetect_config(struct iwl_mvm *mvm,
1087 ret = iwl_mvm_switch_to_d3(mvm); 1087 ret = iwl_mvm_switch_to_d3(mvm);
1088 if (ret) 1088 if (ret)
1089 return ret; 1089 return ret;
1090 } else {
1091 /* In theory, we wouldn't have to stop a running sched
1092 * scan in order to start another one (for
1093 * net-detect). But in practice this doesn't seem to
1094 * work properly, so stop any running sched_scan now.
1095 */
1096 ret = iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, true);
1097 if (ret)
1098 return ret;
1090 } 1099 }
1091 1100
1092 /* rfkill release can be either for wowlan or netdetect */ 1101 /* rfkill release can be either for wowlan or netdetect */
@@ -1254,7 +1263,10 @@ static int __iwl_mvm_suspend(struct ieee80211_hw *hw,
1254 out: 1263 out:
1255 if (ret < 0) { 1264 if (ret < 0) {
1256 iwl_mvm_ref(mvm, IWL_MVM_REF_UCODE_DOWN); 1265 iwl_mvm_ref(mvm, IWL_MVM_REF_UCODE_DOWN);
1257 ieee80211_restart_hw(mvm->hw); 1266 if (mvm->restart_fw > 0) {
1267 mvm->restart_fw--;
1268 ieee80211_restart_hw(mvm->hw);
1269 }
1258 iwl_mvm_free_nd(mvm); 1270 iwl_mvm_free_nd(mvm);
1259 } 1271 }
1260 out_noreset: 1272 out_noreset:
@@ -2088,6 +2100,16 @@ static int __iwl_mvm_resume(struct iwl_mvm *mvm, bool test)
2088 iwl_mvm_update_changed_regdom(mvm); 2100 iwl_mvm_update_changed_regdom(mvm);
2089 2101
2090 if (mvm->net_detect) { 2102 if (mvm->net_detect) {
2103 /* If this is a non-unified image, we restart the FW,
2104 * so no need to stop the netdetect scan. If that
2105 * fails, continue and try to get the wake-up reasons,
2106 * but trigger a HW restart by keeping a failure code
2107 * in ret.
2108 */
2109 if (unified_image)
2110 ret = iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_NETDETECT,
2111 false);
2112
2091 iwl_mvm_query_netdetect_reasons(mvm, vif); 2113 iwl_mvm_query_netdetect_reasons(mvm, vif);
2092 /* has unlocked the mutex, so skip that */ 2114 /* has unlocked the mutex, so skip that */
2093 goto out; 2115 goto out;
@@ -2271,7 +2293,8 @@ static void iwl_mvm_d3_test_disconn_work_iter(void *_data, u8 *mac,
2271static int iwl_mvm_d3_test_release(struct inode *inode, struct file *file) 2293static int iwl_mvm_d3_test_release(struct inode *inode, struct file *file)
2272{ 2294{
2273 struct iwl_mvm *mvm = inode->i_private; 2295 struct iwl_mvm *mvm = inode->i_private;
2274 int remaining_time = 10; 2296 bool unified_image = fw_has_capa(&mvm->fw->ucode_capa,
2297 IWL_UCODE_TLV_CAPA_CNSLDTD_D3_D0_IMG);
2275 2298
2276 mvm->d3_test_active = false; 2299 mvm->d3_test_active = false;
2277 2300
@@ -2282,17 +2305,21 @@ static int iwl_mvm_d3_test_release(struct inode *inode, struct file *file)
2282 mvm->trans->system_pm_mode = IWL_PLAT_PM_MODE_DISABLED; 2305 mvm->trans->system_pm_mode = IWL_PLAT_PM_MODE_DISABLED;
2283 2306
2284 iwl_abort_notification_waits(&mvm->notif_wait); 2307 iwl_abort_notification_waits(&mvm->notif_wait);
2285 ieee80211_restart_hw(mvm->hw); 2308 if (!unified_image) {
2309 int remaining_time = 10;
2286 2310
2287 /* wait for restart and disconnect all interfaces */ 2311 ieee80211_restart_hw(mvm->hw);
2288 while (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) && 2312
2289 remaining_time > 0) { 2313 /* wait for restart and disconnect all interfaces */
2290 remaining_time--; 2314 while (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
2291 msleep(1000); 2315 remaining_time > 0) {
2292 } 2316 remaining_time--;
2317 msleep(1000);
2318 }
2293 2319
2294 if (remaining_time == 0) 2320 if (remaining_time == 0)
2295 IWL_ERR(mvm, "Timed out waiting for HW restart to finish!\n"); 2321 IWL_ERR(mvm, "Timed out waiting for HW restart!\n");
2322 }
2296 2323
2297 ieee80211_iterate_active_interfaces_atomic( 2324 ieee80211_iterate_active_interfaces_atomic(
2298 mvm->hw, IEEE80211_IFACE_ITER_NORMAL, 2325 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c b/drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c
index 07da4efe8458..7b7d2a146e30 100644
--- a/drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c
+++ b/drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c
@@ -1529,8 +1529,8 @@ static ssize_t iwl_dbgfs_mem_read(struct file *file, char __user *user_buf,
1529 .data = { &cmd, }, 1529 .data = { &cmd, },
1530 .len = { sizeof(cmd) }, 1530 .len = { sizeof(cmd) },
1531 }; 1531 };
1532 size_t delta, len; 1532 size_t delta;
1533 ssize_t ret; 1533 ssize_t ret, len;
1534 1534
1535 hcmd.id = iwl_cmd_id(*ppos >> 24 ? UMAC_RD_WR : LMAC_RD_WR, 1535 hcmd.id = iwl_cmd_id(*ppos >> 24 ? UMAC_RD_WR : LMAC_RD_WR,
1536 DEBUG_GROUP, 0); 1536 DEBUG_GROUP, 0);
diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/mac80211.c b/drivers/net/wireless/intel/iwlwifi/mvm/mac80211.c
index 318efd814037..1db1dc13e988 100644
--- a/drivers/net/wireless/intel/iwlwifi/mvm/mac80211.c
+++ b/drivers/net/wireless/intel/iwlwifi/mvm/mac80211.c
@@ -4121,7 +4121,6 @@ void iwl_mvm_sync_rx_queues_internal(struct iwl_mvm *mvm,
4121 struct iwl_mvm_internal_rxq_notif *notif, 4121 struct iwl_mvm_internal_rxq_notif *notif,
4122 u32 size) 4122 u32 size)
4123{ 4123{
4124 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(notif_waitq);
4125 u32 qmask = BIT(mvm->trans->num_rx_queues) - 1; 4124 u32 qmask = BIT(mvm->trans->num_rx_queues) - 1;
4126 int ret; 4125 int ret;
4127 4126
@@ -4143,7 +4142,7 @@ void iwl_mvm_sync_rx_queues_internal(struct iwl_mvm *mvm,
4143 } 4142 }
4144 4143
4145 if (notif->sync) 4144 if (notif->sync)
4146 ret = wait_event_timeout(notif_waitq, 4145 ret = wait_event_timeout(mvm->rx_sync_waitq,
4147 atomic_read(&mvm->queue_sync_counter) == 0, 4146 atomic_read(&mvm->queue_sync_counter) == 0,
4148 HZ); 4147 HZ);
4149 WARN_ON_ONCE(!ret); 4148 WARN_ON_ONCE(!ret);
diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/mvm.h b/drivers/net/wireless/intel/iwlwifi/mvm/mvm.h
index d17cbf603f7c..c60703e0c246 100644
--- a/drivers/net/wireless/intel/iwlwifi/mvm/mvm.h
+++ b/drivers/net/wireless/intel/iwlwifi/mvm/mvm.h
@@ -937,6 +937,7 @@ struct iwl_mvm {
937 /* sync d0i3_tx queue and IWL_MVM_STATUS_IN_D0I3 status flag */ 937 /* sync d0i3_tx queue and IWL_MVM_STATUS_IN_D0I3 status flag */
938 spinlock_t d0i3_tx_lock; 938 spinlock_t d0i3_tx_lock;
939 wait_queue_head_t d0i3_exit_waitq; 939 wait_queue_head_t d0i3_exit_waitq;
940 wait_queue_head_t rx_sync_waitq;
940 941
941 /* BT-Coex */ 942 /* BT-Coex */
942 struct iwl_bt_coex_profile_notif last_bt_notif; 943 struct iwl_bt_coex_profile_notif last_bt_notif;
diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/ops.c b/drivers/net/wireless/intel/iwlwifi/mvm/ops.c
index 05fe6dd1a2c8..4d35deb628bc 100644
--- a/drivers/net/wireless/intel/iwlwifi/mvm/ops.c
+++ b/drivers/net/wireless/intel/iwlwifi/mvm/ops.c
@@ -619,6 +619,7 @@ iwl_op_mode_mvm_start(struct iwl_trans *trans, const struct iwl_cfg *cfg,
619 spin_lock_init(&mvm->refs_lock); 619 spin_lock_init(&mvm->refs_lock);
620 skb_queue_head_init(&mvm->d0i3_tx); 620 skb_queue_head_init(&mvm->d0i3_tx);
621 init_waitqueue_head(&mvm->d0i3_exit_waitq); 621 init_waitqueue_head(&mvm->d0i3_exit_waitq);
622 init_waitqueue_head(&mvm->rx_sync_waitq);
622 623
623 atomic_set(&mvm->queue_sync_counter, 0); 624 atomic_set(&mvm->queue_sync_counter, 0);
624 625
diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/rxmq.c b/drivers/net/wireless/intel/iwlwifi/mvm/rxmq.c
index a57c6ef5bc14..6c802cee900c 100644
--- a/drivers/net/wireless/intel/iwlwifi/mvm/rxmq.c
+++ b/drivers/net/wireless/intel/iwlwifi/mvm/rxmq.c
@@ -547,7 +547,8 @@ void iwl_mvm_rx_queue_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb,
547 "Received expired RX queue sync message\n"); 547 "Received expired RX queue sync message\n");
548 return; 548 return;
549 } 549 }
550 atomic_dec(&mvm->queue_sync_counter); 550 if (!atomic_dec_return(&mvm->queue_sync_counter))
551 wake_up(&mvm->rx_sync_waitq);
551 } 552 }
552 553
553 switch (internal_notif->type) { 554 switch (internal_notif->type) {
diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/scan.c b/drivers/net/wireless/intel/iwlwifi/mvm/scan.c
index f279fdd6eb44..fa9743205491 100644
--- a/drivers/net/wireless/intel/iwlwifi/mvm/scan.c
+++ b/drivers/net/wireless/intel/iwlwifi/mvm/scan.c
@@ -1199,6 +1199,9 @@ static int iwl_mvm_num_scans(struct iwl_mvm *mvm)
1199 1199
1200static int iwl_mvm_check_running_scans(struct iwl_mvm *mvm, int type) 1200static int iwl_mvm_check_running_scans(struct iwl_mvm *mvm, int type)
1201{ 1201{
1202 bool unified_image = fw_has_capa(&mvm->fw->ucode_capa,
1203 IWL_UCODE_TLV_CAPA_CNSLDTD_D3_D0_IMG);
1204
1202 /* This looks a bit arbitrary, but the idea is that if we run 1205 /* This looks a bit arbitrary, but the idea is that if we run
1203 * out of possible simultaneous scans and the userspace is 1206 * out of possible simultaneous scans and the userspace is
1204 * trying to run a scan type that is already running, we 1207 * trying to run a scan type that is already running, we
@@ -1225,12 +1228,30 @@ static int iwl_mvm_check_running_scans(struct iwl_mvm *mvm, int type)
1225 return -EBUSY; 1228 return -EBUSY;
1226 return iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_REGULAR, true); 1229 return iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_REGULAR, true);
1227 case IWL_MVM_SCAN_NETDETECT: 1230 case IWL_MVM_SCAN_NETDETECT:
1228 /* No need to stop anything for net-detect since the 1231 /* For non-unified images, there's no need to stop
1229 * firmware is restarted anyway. This way, any sched 1232 * anything for net-detect since the firmware is
1230 * scans that were running will be restarted when we 1233 * restarted anyway. This way, any sched scans that
1231 * resume. 1234 * were running will be restarted when we resume.
1232 */ 1235 */
1233 return 0; 1236 if (!unified_image)
1237 return 0;
1238
1239 /* If this is a unified image and we ran out of scans,
1240 * we need to stop something. Prefer stopping regular
1241 * scans, because the results are useless at this
1242 * point, and we should be able to keep running
1243 * another scheduled scan while suspended.
1244 */
1245 if (mvm->scan_status & IWL_MVM_SCAN_REGULAR_MASK)
1246 return iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_REGULAR,
1247 true);
1248 if (mvm->scan_status & IWL_MVM_SCAN_SCHED_MASK)
1249 return iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED,
1250 true);
1251
1252 /* fall through, something is wrong if no scan was
1253 * running but we ran out of scans.
1254 */
1234 default: 1255 default:
1235 WARN_ON(1); 1256 WARN_ON(1);
1236 break; 1257 break;
diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/drv.c b/drivers/net/wireless/intel/iwlwifi/pcie/drv.c
index 001be406a3d3..2f8134b2a504 100644
--- a/drivers/net/wireless/intel/iwlwifi/pcie/drv.c
+++ b/drivers/net/wireless/intel/iwlwifi/pcie/drv.c
@@ -541,48 +541,64 @@ static const struct pci_device_id iwl_hw_card_ids[] = {
541MODULE_DEVICE_TABLE(pci, iwl_hw_card_ids); 541MODULE_DEVICE_TABLE(pci, iwl_hw_card_ids);
542 542
543#ifdef CONFIG_ACPI 543#ifdef CONFIG_ACPI
544#define SPL_METHOD "SPLC" 544#define ACPI_SPLC_METHOD "SPLC"
545#define SPL_DOMAINTYPE_MODULE BIT(0) 545#define ACPI_SPLC_DOMAIN_WIFI (0x07)
546#define SPL_DOMAINTYPE_WIFI BIT(1)
547#define SPL_DOMAINTYPE_WIGIG BIT(2)
548#define SPL_DOMAINTYPE_RFEM BIT(3)
549 546
550static u64 splx_get_pwr_limit(struct iwl_trans *trans, union acpi_object *splx) 547static u64 splc_get_pwr_limit(struct iwl_trans *trans, union acpi_object *splc)
551{ 548{
552 union acpi_object *limits, *domain_type, *power_limit; 549 union acpi_object *data_pkg, *dflt_pwr_limit;
553 550 int i;
554 if (splx->type != ACPI_TYPE_PACKAGE || 551
555 splx->package.count != 2 || 552 /* We need at least two elements, one for the revision and one
556 splx->package.elements[0].type != ACPI_TYPE_INTEGER || 553 * for the data itself. Also check that the revision is
557 splx->package.elements[0].integer.value != 0) { 554 * supported (currently only revision 0).
558 IWL_ERR(trans, "Unsupported splx structure\n"); 555 */
556 if (splc->type != ACPI_TYPE_PACKAGE ||
557 splc->package.count < 2 ||
558 splc->package.elements[0].type != ACPI_TYPE_INTEGER ||
559 splc->package.elements[0].integer.value != 0) {
560 IWL_DEBUG_INFO(trans,
561 "Unsupported structure returned by the SPLC method. Ignoring.\n");
559 return 0; 562 return 0;
560 } 563 }
561 564
562 limits = &splx->package.elements[1]; 565 /* loop through all the packages to find the one for WiFi */
563 if (limits->type != ACPI_TYPE_PACKAGE || 566 for (i = 1; i < splc->package.count; i++) {
564 limits->package.count < 2 || 567 union acpi_object *domain;
565 limits->package.elements[0].type != ACPI_TYPE_INTEGER || 568
566 limits->package.elements[1].type != ACPI_TYPE_INTEGER) { 569 data_pkg = &splc->package.elements[i];
567 IWL_ERR(trans, "Invalid limits element\n"); 570
568 return 0; 571 /* Skip anything that is not a package with the right
572 * amount of elements (i.e. at least 2 integers).
573 */
574 if (data_pkg->type != ACPI_TYPE_PACKAGE ||
575 data_pkg->package.count < 2 ||
576 data_pkg->package.elements[0].type != ACPI_TYPE_INTEGER ||
577 data_pkg->package.elements[1].type != ACPI_TYPE_INTEGER)
578 continue;
579
580 domain = &data_pkg->package.elements[0];
581 if (domain->integer.value == ACPI_SPLC_DOMAIN_WIFI)
582 break;
583
584 data_pkg = NULL;
569 } 585 }
570 586
571 domain_type = &limits->package.elements[0]; 587 if (!data_pkg) {
572 power_limit = &limits->package.elements[1]; 588 IWL_DEBUG_INFO(trans,
573 if (!(domain_type->integer.value & SPL_DOMAINTYPE_WIFI)) { 589 "No element for the WiFi domain returned by the SPLC method.\n");
574 IWL_DEBUG_INFO(trans, "WiFi power is not limited\n");
575 return 0; 590 return 0;
576 } 591 }
577 592
578 return power_limit->integer.value; 593 dflt_pwr_limit = &data_pkg->package.elements[1];
594 return dflt_pwr_limit->integer.value;
579} 595}
580 596
581static void set_dflt_pwr_limit(struct iwl_trans *trans, struct pci_dev *pdev) 597static void set_dflt_pwr_limit(struct iwl_trans *trans, struct pci_dev *pdev)
582{ 598{
583 acpi_handle pxsx_handle; 599 acpi_handle pxsx_handle;
584 acpi_handle handle; 600 acpi_handle handle;
585 struct acpi_buffer splx = {ACPI_ALLOCATE_BUFFER, NULL}; 601 struct acpi_buffer splc = {ACPI_ALLOCATE_BUFFER, NULL};
586 acpi_status status; 602 acpi_status status;
587 603
588 pxsx_handle = ACPI_HANDLE(&pdev->dev); 604 pxsx_handle = ACPI_HANDLE(&pdev->dev);
@@ -593,23 +609,24 @@ static void set_dflt_pwr_limit(struct iwl_trans *trans, struct pci_dev *pdev)
593 } 609 }
594 610
595 /* Get the method's handle */ 611 /* Get the method's handle */
596 status = acpi_get_handle(pxsx_handle, (acpi_string)SPL_METHOD, &handle); 612 status = acpi_get_handle(pxsx_handle, (acpi_string)ACPI_SPLC_METHOD,
613 &handle);
597 if (ACPI_FAILURE(status)) { 614 if (ACPI_FAILURE(status)) {
598 IWL_DEBUG_INFO(trans, "SPL method not found\n"); 615 IWL_DEBUG_INFO(trans, "SPLC method not found\n");
599 return; 616 return;
600 } 617 }
601 618
602 /* Call SPLC with no arguments */ 619 /* Call SPLC with no arguments */
603 status = acpi_evaluate_object(handle, NULL, NULL, &splx); 620 status = acpi_evaluate_object(handle, NULL, NULL, &splc);
604 if (ACPI_FAILURE(status)) { 621 if (ACPI_FAILURE(status)) {
605 IWL_ERR(trans, "SPLC invocation failed (0x%x)\n", status); 622 IWL_ERR(trans, "SPLC invocation failed (0x%x)\n", status);
606 return; 623 return;
607 } 624 }
608 625
609 trans->dflt_pwr_limit = splx_get_pwr_limit(trans, splx.pointer); 626 trans->dflt_pwr_limit = splc_get_pwr_limit(trans, splc.pointer);
610 IWL_DEBUG_INFO(trans, "Default power limit set to %lld\n", 627 IWL_DEBUG_INFO(trans, "Default power limit set to %lld\n",
611 trans->dflt_pwr_limit); 628 trans->dflt_pwr_limit);
612 kfree(splx.pointer); 629 kfree(splc.pointer);
613} 630}
614 631
615#else /* CONFIG_ACPI */ 632#else /* CONFIG_ACPI */
diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/tx.c b/drivers/net/wireless/intel/iwlwifi/pcie/tx.c
index e9a278b60dfd..5f840f16f40b 100644
--- a/drivers/net/wireless/intel/iwlwifi/pcie/tx.c
+++ b/drivers/net/wireless/intel/iwlwifi/pcie/tx.c
@@ -592,6 +592,7 @@ error:
592static int iwl_pcie_txq_init(struct iwl_trans *trans, struct iwl_txq *txq, 592static int iwl_pcie_txq_init(struct iwl_trans *trans, struct iwl_txq *txq,
593 int slots_num, u32 txq_id) 593 int slots_num, u32 txq_id)
594{ 594{
595 struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
595 int ret; 596 int ret;
596 597
597 txq->need_update = false; 598 txq->need_update = false;
@@ -606,6 +607,13 @@ static int iwl_pcie_txq_init(struct iwl_trans *trans, struct iwl_txq *txq,
606 return ret; 607 return ret;
607 608
608 spin_lock_init(&txq->lock); 609 spin_lock_init(&txq->lock);
610
611 if (txq_id == trans_pcie->cmd_queue) {
612 static struct lock_class_key iwl_pcie_cmd_queue_lock_class;
613
614 lockdep_set_class(&txq->lock, &iwl_pcie_cmd_queue_lock_class);
615 }
616
609 __skb_queue_head_init(&txq->overflow_q); 617 __skb_queue_head_init(&txq->overflow_q);
610 618
611 /* 619 /*
diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
index 431f13b4faf6..d3bad5779376 100644
--- a/drivers/net/wireless/mac80211_hwsim.c
+++ b/drivers/net/wireless/mac80211_hwsim.c
@@ -826,7 +826,7 @@ static void mac80211_hwsim_set_tsf(struct ieee80211_hw *hw,
826 data->bcn_delta = do_div(delta, bcn_int); 826 data->bcn_delta = do_div(delta, bcn_int);
827 } else { 827 } else {
828 data->tsf_offset -= delta; 828 data->tsf_offset -= delta;
829 data->bcn_delta = -do_div(delta, bcn_int); 829 data->bcn_delta = -(s64)do_div(delta, bcn_int);
830 } 830 }
831} 831}
832 832
diff --git a/drivers/net/wireless/marvell/mwifiex/11n_rxreorder.c b/drivers/net/wireless/marvell/mwifiex/11n_rxreorder.c
index 94480123efa3..274dd5a1574a 100644
--- a/drivers/net/wireless/marvell/mwifiex/11n_rxreorder.c
+++ b/drivers/net/wireless/marvell/mwifiex/11n_rxreorder.c
@@ -45,7 +45,7 @@ static int mwifiex_11n_dispatch_amsdu_pkt(struct mwifiex_private *priv,
45 skb_trim(skb, le16_to_cpu(local_rx_pd->rx_pkt_length)); 45 skb_trim(skb, le16_to_cpu(local_rx_pd->rx_pkt_length));
46 46
47 ieee80211_amsdu_to_8023s(skb, &list, priv->curr_addr, 47 ieee80211_amsdu_to_8023s(skb, &list, priv->curr_addr,
48 priv->wdev.iftype, 0, false); 48 priv->wdev.iftype, 0, NULL, NULL);
49 49
50 while (!skb_queue_empty(&list)) { 50 while (!skb_queue_empty(&list)) {
51 struct rx_packet_hdr *rx_hdr; 51 struct rx_packet_hdr *rx_hdr;
diff --git a/drivers/net/wireless/marvell/mwifiex/cfg80211.c b/drivers/net/wireless/marvell/mwifiex/cfg80211.c
index 39ce76ad00bc..16241d21727b 100644
--- a/drivers/net/wireless/marvell/mwifiex/cfg80211.c
+++ b/drivers/net/wireless/marvell/mwifiex/cfg80211.c
@@ -2222,8 +2222,9 @@ done:
2222 is_scanning_required = 1; 2222 is_scanning_required = 1;
2223 } else { 2223 } else {
2224 mwifiex_dbg(priv->adapter, MSG, 2224 mwifiex_dbg(priv->adapter, MSG,
2225 "info: trying to associate to '%s' bssid %pM\n", 2225 "info: trying to associate to '%.*s' bssid %pM\n",
2226 (char *)req_ssid.ssid, bss->bssid); 2226 req_ssid.ssid_len, (char *)req_ssid.ssid,
2227 bss->bssid);
2227 memcpy(&priv->cfg_bssid, bss->bssid, ETH_ALEN); 2228 memcpy(&priv->cfg_bssid, bss->bssid, ETH_ALEN);
2228 break; 2229 break;
2229 } 2230 }
@@ -2283,8 +2284,8 @@ mwifiex_cfg80211_connect(struct wiphy *wiphy, struct net_device *dev,
2283 } 2284 }
2284 2285
2285 mwifiex_dbg(adapter, INFO, 2286 mwifiex_dbg(adapter, INFO,
2286 "info: Trying to associate to %s and bssid %pM\n", 2287 "info: Trying to associate to %.*s and bssid %pM\n",
2287 (char *)sme->ssid, sme->bssid); 2288 (int)sme->ssid_len, (char *)sme->ssid, sme->bssid);
2288 2289
2289 if (!mwifiex_stop_bg_scan(priv)) 2290 if (!mwifiex_stop_bg_scan(priv))
2290 cfg80211_sched_scan_stopped_rtnl(priv->wdev.wiphy); 2291 cfg80211_sched_scan_stopped_rtnl(priv->wdev.wiphy);
@@ -2417,8 +2418,8 @@ mwifiex_cfg80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
2417 } 2418 }
2418 2419
2419 mwifiex_dbg(priv->adapter, MSG, 2420 mwifiex_dbg(priv->adapter, MSG,
2420 "info: trying to join to %s and bssid %pM\n", 2421 "info: trying to join to %.*s and bssid %pM\n",
2421 (char *)params->ssid, params->bssid); 2422 params->ssid_len, (char *)params->ssid, params->bssid);
2422 2423
2423 mwifiex_set_ibss_params(priv, params); 2424 mwifiex_set_ibss_params(priv, params);
2424 2425
diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h
index 1016628926d2..08d587a342d3 100644
--- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h
+++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h
@@ -238,7 +238,7 @@ struct rtl8xxxu_rxdesc16 {
238 u32 pattern1match:1; 238 u32 pattern1match:1;
239 u32 pattern0match:1; 239 u32 pattern0match:1;
240#endif 240#endif
241 __le32 tsfl; 241 u32 tsfl;
242#if 0 242#if 0
243 u32 bassn:12; 243 u32 bassn:12;
244 u32 bavld:1; 244 u32 bavld:1;
@@ -368,7 +368,7 @@ struct rtl8xxxu_rxdesc24 {
368 u32 ldcp:1; 368 u32 ldcp:1;
369 u32 splcp:1; 369 u32 splcp:1;
370#endif 370#endif
371 __le32 tsfl; 371 u32 tsfl;
372}; 372};
373 373
374struct rtl8xxxu_txdesc32 { 374struct rtl8xxxu_txdesc32 {
diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192e.c b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192e.c
index df54d27e7851..a793fedc3654 100644
--- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192e.c
+++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192e.c
@@ -1461,7 +1461,9 @@ static int rtl8192eu_active_to_emu(struct rtl8xxxu_priv *priv)
1461 int count, ret = 0; 1461 int count, ret = 0;
1462 1462
1463 /* Turn off RF */ 1463 /* Turn off RF */
1464 rtl8xxxu_write8(priv, REG_RF_CTRL, 0); 1464 val8 = rtl8xxxu_read8(priv, REG_RF_CTRL);
1465 val8 &= ~RF_ENABLE;
1466 rtl8xxxu_write8(priv, REG_RF_CTRL, val8);
1465 1467
1466 /* Switch DPDT_SEL_P output from register 0x65[2] */ 1468 /* Switch DPDT_SEL_P output from register 0x65[2] */
1467 val8 = rtl8xxxu_read8(priv, REG_LEDCFG2); 1469 val8 = rtl8xxxu_read8(priv, REG_LEDCFG2);
@@ -1593,6 +1595,10 @@ static void rtl8192e_enable_rf(struct rtl8xxxu_priv *priv)
1593 u32 val32; 1595 u32 val32;
1594 u8 val8; 1596 u8 val8;
1595 1597
1598 val32 = rtl8xxxu_read32(priv, REG_RX_WAIT_CCA);
1599 val32 |= (BIT(22) | BIT(23));
1600 rtl8xxxu_write32(priv, REG_RX_WAIT_CCA, val32);
1601
1596 val8 = rtl8xxxu_read8(priv, REG_GPIO_MUXCFG); 1602 val8 = rtl8xxxu_read8(priv, REG_GPIO_MUXCFG);
1597 val8 |= BIT(5); 1603 val8 |= BIT(5);
1598 rtl8xxxu_write8(priv, REG_GPIO_MUXCFG, val8); 1604 rtl8xxxu_write8(priv, REG_GPIO_MUXCFG, val8);
diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8723b.c b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8723b.c
index 6c086b5657e9..02b8ddd98a95 100644
--- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8723b.c
+++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8723b.c
@@ -1498,6 +1498,10 @@ static void rtl8723b_enable_rf(struct rtl8xxxu_priv *priv)
1498 u32 val32; 1498 u32 val32;
1499 u8 val8; 1499 u8 val8;
1500 1500
1501 val32 = rtl8xxxu_read32(priv, REG_RX_WAIT_CCA);
1502 val32 |= (BIT(22) | BIT(23));
1503 rtl8xxxu_write32(priv, REG_RX_WAIT_CCA, val32);
1504
1501 /* 1505 /*
1502 * No indication anywhere as to what 0x0790 does. The 2 antenna 1506 * No indication anywhere as to what 0x0790 does. The 2 antenna
1503 * vendor code preserves bits 6-7 here. 1507 * vendor code preserves bits 6-7 here.
diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c
index b2d7f6e69667..a5e6ec2152bf 100644
--- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c
+++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c
@@ -5197,7 +5197,12 @@ int rtl8xxxu_parse_rxdesc16(struct rtl8xxxu_priv *priv, struct sk_buff *skb)
5197 pkt_offset = roundup(pkt_len + drvinfo_sz + desc_shift + 5197 pkt_offset = roundup(pkt_len + drvinfo_sz + desc_shift +
5198 sizeof(struct rtl8xxxu_rxdesc16), 128); 5198 sizeof(struct rtl8xxxu_rxdesc16), 128);
5199 5199
5200 if (pkt_cnt > 1) 5200 /*
5201 * Only clone the skb if there's enough data at the end to
5202 * at least cover the rx descriptor
5203 */
5204 if (pkt_cnt > 1 &&
5205 urb_len > (pkt_offset + sizeof(struct rtl8xxxu_rxdesc16)))
5201 next_skb = skb_clone(skb, GFP_ATOMIC); 5206 next_skb = skb_clone(skb, GFP_ATOMIC);
5202 5207
5203 rx_status = IEEE80211_SKB_RXCB(skb); 5208 rx_status = IEEE80211_SKB_RXCB(skb);
@@ -5215,7 +5220,7 @@ int rtl8xxxu_parse_rxdesc16(struct rtl8xxxu_priv *priv, struct sk_buff *skb)
5215 rtl8xxxu_rx_parse_phystats(priv, rx_status, phy_stats, 5220 rtl8xxxu_rx_parse_phystats(priv, rx_status, phy_stats,
5216 rx_desc->rxmcs); 5221 rx_desc->rxmcs);
5217 5222
5218 rx_status->mactime = le32_to_cpu(rx_desc->tsfl); 5223 rx_status->mactime = rx_desc->tsfl;
5219 rx_status->flag |= RX_FLAG_MACTIME_START; 5224 rx_status->flag |= RX_FLAG_MACTIME_START;
5220 5225
5221 if (!rx_desc->swdec) 5226 if (!rx_desc->swdec)
@@ -5285,7 +5290,7 @@ int rtl8xxxu_parse_rxdesc24(struct rtl8xxxu_priv *priv, struct sk_buff *skb)
5285 rtl8xxxu_rx_parse_phystats(priv, rx_status, phy_stats, 5290 rtl8xxxu_rx_parse_phystats(priv, rx_status, phy_stats,
5286 rx_desc->rxmcs); 5291 rx_desc->rxmcs);
5287 5292
5288 rx_status->mactime = le32_to_cpu(rx_desc->tsfl); 5293 rx_status->mactime = rx_desc->tsfl;
5289 rx_status->flag |= RX_FLAG_MACTIME_START; 5294 rx_status->flag |= RX_FLAG_MACTIME_START;
5290 5295
5291 if (!rx_desc->swdec) 5296 if (!rx_desc->swdec)
diff --git a/drivers/net/wireless/realtek/rtlwifi/core.c b/drivers/net/wireless/realtek/rtlwifi/core.c
index f95760c13c56..8e7f23c11680 100644
--- a/drivers/net/wireless/realtek/rtlwifi/core.c
+++ b/drivers/net/wireless/realtek/rtlwifi/core.c
@@ -111,7 +111,7 @@ static void rtl_fw_do_work(const struct firmware *firmware, void *context,
111 if (!err) 111 if (!err)
112 goto found_alt; 112 goto found_alt;
113 } 113 }
114 pr_err("Firmware %s not available\n", rtlpriv->cfg->fw_name); 114 pr_err("Selected firmware is not available\n");
115 rtlpriv->max_fw_size = 0; 115 rtlpriv->max_fw_size = 0;
116 return; 116 return;
117 } 117 }
diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/sw.c b/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/sw.c
index e7b11b40e68d..f361808def47 100644
--- a/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/sw.c
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/sw.c
@@ -86,6 +86,7 @@ int rtl88e_init_sw_vars(struct ieee80211_hw *hw)
86 struct rtl_priv *rtlpriv = rtl_priv(hw); 86 struct rtl_priv *rtlpriv = rtl_priv(hw);
87 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); 87 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
88 u8 tid; 88 u8 tid;
89 char *fw_name;
89 90
90 rtl8188ee_bt_reg_init(hw); 91 rtl8188ee_bt_reg_init(hw);
91 rtlpriv->dm.dm_initialgain_enable = 1; 92 rtlpriv->dm.dm_initialgain_enable = 1;
@@ -169,10 +170,10 @@ int rtl88e_init_sw_vars(struct ieee80211_hw *hw)
169 return 1; 170 return 1;
170 } 171 }
171 172
172 rtlpriv->cfg->fw_name = "rtlwifi/rtl8188efw.bin"; 173 fw_name = "rtlwifi/rtl8188efw.bin";
173 rtlpriv->max_fw_size = 0x8000; 174 rtlpriv->max_fw_size = 0x8000;
174 pr_info("Using firmware %s\n", rtlpriv->cfg->fw_name); 175 pr_info("Using firmware %s\n", fw_name);
175 err = request_firmware_nowait(THIS_MODULE, 1, rtlpriv->cfg->fw_name, 176 err = request_firmware_nowait(THIS_MODULE, 1, fw_name,
176 rtlpriv->io.dev, GFP_KERNEL, hw, 177 rtlpriv->io.dev, GFP_KERNEL, hw,
177 rtl_fw_cb); 178 rtl_fw_cb);
178 if (err) { 179 if (err) {
@@ -284,7 +285,6 @@ static const struct rtl_hal_cfg rtl88ee_hal_cfg = {
284 .bar_id = 2, 285 .bar_id = 2,
285 .write_readback = true, 286 .write_readback = true,
286 .name = "rtl88e_pci", 287 .name = "rtl88e_pci",
287 .fw_name = "rtlwifi/rtl8188efw.bin",
288 .ops = &rtl8188ee_hal_ops, 288 .ops = &rtl8188ee_hal_ops,
289 .mod_params = &rtl88ee_mod_params, 289 .mod_params = &rtl88ee_mod_params,
290 290
diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8192ce/sw.c b/drivers/net/wireless/realtek/rtlwifi/rtl8192ce/sw.c
index 87aa209ae325..8b6e37ce3f66 100644
--- a/drivers/net/wireless/realtek/rtlwifi/rtl8192ce/sw.c
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8192ce/sw.c
@@ -96,6 +96,7 @@ int rtl92c_init_sw_vars(struct ieee80211_hw *hw)
96 struct rtl_priv *rtlpriv = rtl_priv(hw); 96 struct rtl_priv *rtlpriv = rtl_priv(hw);
97 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); 97 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
98 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); 98 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
99 char *fw_name = "rtlwifi/rtl8192cfwU.bin";
99 100
100 rtl8192ce_bt_reg_init(hw); 101 rtl8192ce_bt_reg_init(hw);
101 102
@@ -167,15 +168,12 @@ int rtl92c_init_sw_vars(struct ieee80211_hw *hw)
167 } 168 }
168 169
169 /* request fw */ 170 /* request fw */
170 if (IS_VENDOR_UMC_A_CUT(rtlhal->version) && 171 if (IS_81XXC_VENDOR_UMC_B_CUT(rtlhal->version))
171 !IS_92C_SERIAL(rtlhal->version)) 172 fw_name = "rtlwifi/rtl8192cfwU_B.bin";
172 rtlpriv->cfg->fw_name = "rtlwifi/rtl8192cfwU.bin";
173 else if (IS_81XXC_VENDOR_UMC_B_CUT(rtlhal->version))
174 rtlpriv->cfg->fw_name = "rtlwifi/rtl8192cfwU_B.bin";
175 173
176 rtlpriv->max_fw_size = 0x4000; 174 rtlpriv->max_fw_size = 0x4000;
177 pr_info("Using firmware %s\n", rtlpriv->cfg->fw_name); 175 pr_info("Using firmware %s\n", fw_name);
178 err = request_firmware_nowait(THIS_MODULE, 1, rtlpriv->cfg->fw_name, 176 err = request_firmware_nowait(THIS_MODULE, 1, fw_name,
179 rtlpriv->io.dev, GFP_KERNEL, hw, 177 rtlpriv->io.dev, GFP_KERNEL, hw,
180 rtl_fw_cb); 178 rtl_fw_cb);
181 if (err) { 179 if (err) {
@@ -262,7 +260,6 @@ static const struct rtl_hal_cfg rtl92ce_hal_cfg = {
262 .bar_id = 2, 260 .bar_id = 2,
263 .write_readback = true, 261 .write_readback = true,
264 .name = "rtl92c_pci", 262 .name = "rtl92c_pci",
265 .fw_name = "rtlwifi/rtl8192cfw.bin",
266 .ops = &rtl8192ce_hal_ops, 263 .ops = &rtl8192ce_hal_ops,
267 .mod_params = &rtl92ce_mod_params, 264 .mod_params = &rtl92ce_mod_params,
268 265
diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8192cu/sw.c b/drivers/net/wireless/realtek/rtlwifi/rtl8192cu/sw.c
index 7c6f7f0d18c6..f953320f0e23 100644
--- a/drivers/net/wireless/realtek/rtlwifi/rtl8192cu/sw.c
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8192cu/sw.c
@@ -59,6 +59,7 @@ static int rtl92cu_init_sw_vars(struct ieee80211_hw *hw)
59{ 59{
60 struct rtl_priv *rtlpriv = rtl_priv(hw); 60 struct rtl_priv *rtlpriv = rtl_priv(hw);
61 int err; 61 int err;
62 char *fw_name;
62 63
63 rtlpriv->dm.dm_initialgain_enable = true; 64 rtlpriv->dm.dm_initialgain_enable = true;
64 rtlpriv->dm.dm_flag = 0; 65 rtlpriv->dm.dm_flag = 0;
@@ -77,18 +78,18 @@ static int rtl92cu_init_sw_vars(struct ieee80211_hw *hw)
77 } 78 }
78 if (IS_VENDOR_UMC_A_CUT(rtlpriv->rtlhal.version) && 79 if (IS_VENDOR_UMC_A_CUT(rtlpriv->rtlhal.version) &&
79 !IS_92C_SERIAL(rtlpriv->rtlhal.version)) { 80 !IS_92C_SERIAL(rtlpriv->rtlhal.version)) {
80 rtlpriv->cfg->fw_name = "rtlwifi/rtl8192cufw_A.bin"; 81 fw_name = "rtlwifi/rtl8192cufw_A.bin";
81 } else if (IS_81XXC_VENDOR_UMC_B_CUT(rtlpriv->rtlhal.version)) { 82 } else if (IS_81XXC_VENDOR_UMC_B_CUT(rtlpriv->rtlhal.version)) {
82 rtlpriv->cfg->fw_name = "rtlwifi/rtl8192cufw_B.bin"; 83 fw_name = "rtlwifi/rtl8192cufw_B.bin";
83 } else { 84 } else {
84 rtlpriv->cfg->fw_name = "rtlwifi/rtl8192cufw_TMSC.bin"; 85 fw_name = "rtlwifi/rtl8192cufw_TMSC.bin";
85 } 86 }
86 /* provide name of alternative file */ 87 /* provide name of alternative file */
87 rtlpriv->cfg->alt_fw_name = "rtlwifi/rtl8192cufw.bin"; 88 rtlpriv->cfg->alt_fw_name = "rtlwifi/rtl8192cufw.bin";
88 pr_info("Loading firmware %s\n", rtlpriv->cfg->fw_name); 89 pr_info("Loading firmware %s\n", fw_name);
89 rtlpriv->max_fw_size = 0x4000; 90 rtlpriv->max_fw_size = 0x4000;
90 err = request_firmware_nowait(THIS_MODULE, 1, 91 err = request_firmware_nowait(THIS_MODULE, 1,
91 rtlpriv->cfg->fw_name, rtlpriv->io.dev, 92 fw_name, rtlpriv->io.dev,
92 GFP_KERNEL, hw, rtl_fw_cb); 93 GFP_KERNEL, hw, rtl_fw_cb);
93 return err; 94 return err;
94} 95}
@@ -187,7 +188,6 @@ static struct rtl_hal_usbint_cfg rtl92cu_interface_cfg = {
187 188
188static struct rtl_hal_cfg rtl92cu_hal_cfg = { 189static struct rtl_hal_cfg rtl92cu_hal_cfg = {
189 .name = "rtl92c_usb", 190 .name = "rtl92c_usb",
190 .fw_name = "rtlwifi/rtl8192cufw.bin",
191 .ops = &rtl8192cu_hal_ops, 191 .ops = &rtl8192cu_hal_ops,
192 .mod_params = &rtl92cu_mod_params, 192 .mod_params = &rtl92cu_mod_params,
193 .usb_interface_cfg = &rtl92cu_interface_cfg, 193 .usb_interface_cfg = &rtl92cu_interface_cfg,
diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8192de/sw.c b/drivers/net/wireless/realtek/rtlwifi/rtl8192de/sw.c
index 0538a4d09568..1ebfee18882f 100644
--- a/drivers/net/wireless/realtek/rtlwifi/rtl8192de/sw.c
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8192de/sw.c
@@ -92,6 +92,7 @@ static int rtl92d_init_sw_vars(struct ieee80211_hw *hw)
92 u8 tid; 92 u8 tid;
93 struct rtl_priv *rtlpriv = rtl_priv(hw); 93 struct rtl_priv *rtlpriv = rtl_priv(hw);
94 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); 94 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
95 char *fw_name = "rtlwifi/rtl8192defw.bin";
95 96
96 rtlpriv->dm.dm_initialgain_enable = true; 97 rtlpriv->dm.dm_initialgain_enable = true;
97 rtlpriv->dm.dm_flag = 0; 98 rtlpriv->dm.dm_flag = 0;
@@ -181,10 +182,10 @@ static int rtl92d_init_sw_vars(struct ieee80211_hw *hw)
181 182
182 rtlpriv->max_fw_size = 0x8000; 183 rtlpriv->max_fw_size = 0x8000;
183 pr_info("Driver for Realtek RTL8192DE WLAN interface\n"); 184 pr_info("Driver for Realtek RTL8192DE WLAN interface\n");
184 pr_info("Loading firmware file %s\n", rtlpriv->cfg->fw_name); 185 pr_info("Loading firmware file %s\n", fw_name);
185 186
186 /* request fw */ 187 /* request fw */
187 err = request_firmware_nowait(THIS_MODULE, 1, rtlpriv->cfg->fw_name, 188 err = request_firmware_nowait(THIS_MODULE, 1, fw_name,
188 rtlpriv->io.dev, GFP_KERNEL, hw, 189 rtlpriv->io.dev, GFP_KERNEL, hw,
189 rtl_fw_cb); 190 rtl_fw_cb);
190 if (err) { 191 if (err) {
@@ -266,7 +267,6 @@ static const struct rtl_hal_cfg rtl92de_hal_cfg = {
266 .bar_id = 2, 267 .bar_id = 2,
267 .write_readback = true, 268 .write_readback = true,
268 .name = "rtl8192de", 269 .name = "rtl8192de",
269 .fw_name = "rtlwifi/rtl8192defw.bin",
270 .ops = &rtl8192de_hal_ops, 270 .ops = &rtl8192de_hal_ops,
271 .mod_params = &rtl92de_mod_params, 271 .mod_params = &rtl92de_mod_params,
272 272
diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/sw.c b/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/sw.c
index ac299cbe59b0..46b605de36e7 100644
--- a/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/sw.c
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8192ee/sw.c
@@ -91,6 +91,7 @@ int rtl92ee_init_sw_vars(struct ieee80211_hw *hw)
91 struct rtl_priv *rtlpriv = rtl_priv(hw); 91 struct rtl_priv *rtlpriv = rtl_priv(hw);
92 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); 92 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
93 int err = 0; 93 int err = 0;
94 char *fw_name;
94 95
95 rtl92ee_bt_reg_init(hw); 96 rtl92ee_bt_reg_init(hw);
96 rtlpci->msi_support = rtlpriv->cfg->mod_params->msi_support; 97 rtlpci->msi_support = rtlpriv->cfg->mod_params->msi_support;
@@ -170,11 +171,11 @@ int rtl92ee_init_sw_vars(struct ieee80211_hw *hw)
170 } 171 }
171 172
172 /* request fw */ 173 /* request fw */
173 rtlpriv->cfg->fw_name = "rtlwifi/rtl8192eefw.bin"; 174 fw_name = "rtlwifi/rtl8192eefw.bin";
174 175
175 rtlpriv->max_fw_size = 0x8000; 176 rtlpriv->max_fw_size = 0x8000;
176 pr_info("Using firmware %s\n", rtlpriv->cfg->fw_name); 177 pr_info("Using firmware %s\n", fw_name);
177 err = request_firmware_nowait(THIS_MODULE, 1, rtlpriv->cfg->fw_name, 178 err = request_firmware_nowait(THIS_MODULE, 1, fw_name,
178 rtlpriv->io.dev, GFP_KERNEL, hw, 179 rtlpriv->io.dev, GFP_KERNEL, hw,
179 rtl_fw_cb); 180 rtl_fw_cb);
180 if (err) { 181 if (err) {
@@ -266,7 +267,6 @@ static const struct rtl_hal_cfg rtl92ee_hal_cfg = {
266 .bar_id = 2, 267 .bar_id = 2,
267 .write_readback = true, 268 .write_readback = true,
268 .name = "rtl92ee_pci", 269 .name = "rtl92ee_pci",
269 .fw_name = "rtlwifi/rtl8192eefw.bin",
270 .ops = &rtl8192ee_hal_ops, 270 .ops = &rtl8192ee_hal_ops,
271 .mod_params = &rtl92ee_mod_params, 271 .mod_params = &rtl92ee_mod_params,
272 272
diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8192se/sw.c b/drivers/net/wireless/realtek/rtlwifi/rtl8192se/sw.c
index 5e8e02d5de8a..3e1eaeac4fdc 100644
--- a/drivers/net/wireless/realtek/rtlwifi/rtl8192se/sw.c
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8192se/sw.c
@@ -89,12 +89,13 @@ static void rtl92se_fw_cb(const struct firmware *firmware, void *context)
89 struct ieee80211_hw *hw = context; 89 struct ieee80211_hw *hw = context;
90 struct rtl_priv *rtlpriv = rtl_priv(hw); 90 struct rtl_priv *rtlpriv = rtl_priv(hw);
91 struct rt_firmware *pfirmware = NULL; 91 struct rt_firmware *pfirmware = NULL;
92 char *fw_name = "rtlwifi/rtl8192sefw.bin";
92 93
93 RT_TRACE(rtlpriv, COMP_ERR, DBG_LOUD, 94 RT_TRACE(rtlpriv, COMP_ERR, DBG_LOUD,
94 "Firmware callback routine entered!\n"); 95 "Firmware callback routine entered!\n");
95 complete(&rtlpriv->firmware_loading_complete); 96 complete(&rtlpriv->firmware_loading_complete);
96 if (!firmware) { 97 if (!firmware) {
97 pr_err("Firmware %s not available\n", rtlpriv->cfg->fw_name); 98 pr_err("Firmware %s not available\n", fw_name);
98 rtlpriv->max_fw_size = 0; 99 rtlpriv->max_fw_size = 0;
99 return; 100 return;
100 } 101 }
@@ -117,6 +118,7 @@ static int rtl92s_init_sw_vars(struct ieee80211_hw *hw)
117 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); 118 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
118 int err = 0; 119 int err = 0;
119 u16 earlyrxthreshold = 7; 120 u16 earlyrxthreshold = 7;
121 char *fw_name = "rtlwifi/rtl8192sefw.bin";
120 122
121 rtlpriv->dm.dm_initialgain_enable = true; 123 rtlpriv->dm.dm_initialgain_enable = true;
122 rtlpriv->dm.dm_flag = 0; 124 rtlpriv->dm.dm_flag = 0;
@@ -214,9 +216,9 @@ static int rtl92s_init_sw_vars(struct ieee80211_hw *hw)
214 rtlpriv->max_fw_size = RTL8190_MAX_FIRMWARE_CODE_SIZE*2 + 216 rtlpriv->max_fw_size = RTL8190_MAX_FIRMWARE_CODE_SIZE*2 +
215 sizeof(struct fw_hdr); 217 sizeof(struct fw_hdr);
216 pr_info("Driver for Realtek RTL8192SE/RTL8191SE\n" 218 pr_info("Driver for Realtek RTL8192SE/RTL8191SE\n"
217 "Loading firmware %s\n", rtlpriv->cfg->fw_name); 219 "Loading firmware %s\n", fw_name);
218 /* request fw */ 220 /* request fw */
219 err = request_firmware_nowait(THIS_MODULE, 1, rtlpriv->cfg->fw_name, 221 err = request_firmware_nowait(THIS_MODULE, 1, fw_name,
220 rtlpriv->io.dev, GFP_KERNEL, hw, 222 rtlpriv->io.dev, GFP_KERNEL, hw,
221 rtl92se_fw_cb); 223 rtl92se_fw_cb);
222 if (err) { 224 if (err) {
@@ -310,7 +312,6 @@ static const struct rtl_hal_cfg rtl92se_hal_cfg = {
310 .bar_id = 1, 312 .bar_id = 1,
311 .write_readback = false, 313 .write_readback = false,
312 .name = "rtl92s_pci", 314 .name = "rtl92s_pci",
313 .fw_name = "rtlwifi/rtl8192sefw.bin",
314 .ops = &rtl8192se_hal_ops, 315 .ops = &rtl8192se_hal_ops,
315 .mod_params = &rtl92se_mod_params, 316 .mod_params = &rtl92se_mod_params,
316 317
diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8723ae/sw.c b/drivers/net/wireless/realtek/rtlwifi/rtl8723ae/sw.c
index 89c828ad89f4..c51a9e8234e9 100644
--- a/drivers/net/wireless/realtek/rtlwifi/rtl8723ae/sw.c
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8723ae/sw.c
@@ -94,6 +94,7 @@ int rtl8723e_init_sw_vars(struct ieee80211_hw *hw)
94 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); 94 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
95 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); 95 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
96 int err = 0; 96 int err = 0;
97 char *fw_name = "rtlwifi/rtl8723fw.bin";
97 98
98 rtl8723e_bt_reg_init(hw); 99 rtl8723e_bt_reg_init(hw);
99 100
@@ -176,14 +177,12 @@ int rtl8723e_init_sw_vars(struct ieee80211_hw *hw)
176 return 1; 177 return 1;
177 } 178 }
178 179
179 if (IS_VENDOR_8723_A_CUT(rtlhal->version)) 180 if (IS_81xxC_VENDOR_UMC_B_CUT(rtlhal->version))
180 rtlpriv->cfg->fw_name = "rtlwifi/rtl8723fw.bin"; 181 fw_name = "rtlwifi/rtl8723fw_B.bin";
181 else if (IS_81xxC_VENDOR_UMC_B_CUT(rtlhal->version))
182 rtlpriv->cfg->fw_name = "rtlwifi/rtl8723fw_B.bin";
183 182
184 rtlpriv->max_fw_size = 0x6000; 183 rtlpriv->max_fw_size = 0x6000;
185 pr_info("Using firmware %s\n", rtlpriv->cfg->fw_name); 184 pr_info("Using firmware %s\n", fw_name);
186 err = request_firmware_nowait(THIS_MODULE, 1, rtlpriv->cfg->fw_name, 185 err = request_firmware_nowait(THIS_MODULE, 1, fw_name,
187 rtlpriv->io.dev, GFP_KERNEL, hw, 186 rtlpriv->io.dev, GFP_KERNEL, hw,
188 rtl_fw_cb); 187 rtl_fw_cb);
189 if (err) { 188 if (err) {
@@ -280,7 +279,6 @@ static const struct rtl_hal_cfg rtl8723e_hal_cfg = {
280 .bar_id = 2, 279 .bar_id = 2,
281 .write_readback = true, 280 .write_readback = true,
282 .name = "rtl8723e_pci", 281 .name = "rtl8723e_pci",
283 .fw_name = "rtlwifi/rtl8723efw.bin",
284 .ops = &rtl8723e_hal_ops, 282 .ops = &rtl8723e_hal_ops,
285 .mod_params = &rtl8723e_mod_params, 283 .mod_params = &rtl8723e_mod_params,
286 .maps[SYS_ISO_CTRL] = REG_SYS_ISO_CTRL, 284 .maps[SYS_ISO_CTRL] = REG_SYS_ISO_CTRL,
diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8723be/sw.c b/drivers/net/wireless/realtek/rtlwifi/rtl8723be/sw.c
index 20b53f035483..847644d1f5f5 100644
--- a/drivers/net/wireless/realtek/rtlwifi/rtl8723be/sw.c
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8723be/sw.c
@@ -91,6 +91,7 @@ int rtl8723be_init_sw_vars(struct ieee80211_hw *hw)
91 struct rtl_priv *rtlpriv = rtl_priv(hw); 91 struct rtl_priv *rtlpriv = rtl_priv(hw);
92 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); 92 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
93 struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); 93 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
94 char *fw_name = "rtlwifi/rtl8723befw.bin";
94 95
95 rtl8723be_bt_reg_init(hw); 96 rtl8723be_bt_reg_init(hw);
96 rtlpriv->btcoexist.btc_ops = rtl_btc_get_ops_pointer(); 97 rtlpriv->btcoexist.btc_ops = rtl_btc_get_ops_pointer();
@@ -184,8 +185,8 @@ int rtl8723be_init_sw_vars(struct ieee80211_hw *hw)
184 } 185 }
185 186
186 rtlpriv->max_fw_size = 0x8000; 187 rtlpriv->max_fw_size = 0x8000;
187 pr_info("Using firmware %s\n", rtlpriv->cfg->fw_name); 188 pr_info("Using firmware %s\n", fw_name);
188 err = request_firmware_nowait(THIS_MODULE, 1, rtlpriv->cfg->fw_name, 189 err = request_firmware_nowait(THIS_MODULE, 1, fw_name,
189 rtlpriv->io.dev, GFP_KERNEL, hw, 190 rtlpriv->io.dev, GFP_KERNEL, hw,
190 rtl_fw_cb); 191 rtl_fw_cb);
191 if (err) { 192 if (err) {
@@ -280,7 +281,6 @@ static const struct rtl_hal_cfg rtl8723be_hal_cfg = {
280 .bar_id = 2, 281 .bar_id = 2,
281 .write_readback = true, 282 .write_readback = true,
282 .name = "rtl8723be_pci", 283 .name = "rtl8723be_pci",
283 .fw_name = "rtlwifi/rtl8723befw.bin",
284 .ops = &rtl8723be_hal_ops, 284 .ops = &rtl8723be_hal_ops,
285 .mod_params = &rtl8723be_mod_params, 285 .mod_params = &rtl8723be_mod_params,
286 .maps[SYS_ISO_CTRL] = REG_SYS_ISO_CTRL, 286 .maps[SYS_ISO_CTRL] = REG_SYS_ISO_CTRL,
diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/sw.c b/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/sw.c
index 22f687b1f133..297938e0effd 100644
--- a/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/sw.c
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/sw.c
@@ -93,6 +93,7 @@ int rtl8821ae_init_sw_vars(struct ieee80211_hw *hw)
93 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); 93 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
94 struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); 94 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
95 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); 95 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
96 char *fw_name, *wowlan_fw_name;
96 97
97 rtl8821ae_bt_reg_init(hw); 98 rtl8821ae_bt_reg_init(hw);
98 rtlpriv->btcoexist.btc_ops = rtl_btc_get_ops_pointer(); 99 rtlpriv->btcoexist.btc_ops = rtl_btc_get_ops_pointer();
@@ -203,17 +204,17 @@ int rtl8821ae_init_sw_vars(struct ieee80211_hw *hw)
203 } 204 }
204 205
205 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8812AE) { 206 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8812AE) {
206 rtlpriv->cfg->fw_name = "rtlwifi/rtl8812aefw.bin"; 207 fw_name = "rtlwifi/rtl8812aefw.bin";
207 rtlpriv->cfg->wowlan_fw_name = "rtlwifi/rtl8812aefw_wowlan.bin"; 208 wowlan_fw_name = "rtlwifi/rtl8812aefw_wowlan.bin";
208 } else { 209 } else {
209 rtlpriv->cfg->fw_name = "rtlwifi/rtl8821aefw.bin"; 210 fw_name = "rtlwifi/rtl8821aefw.bin";
210 rtlpriv->cfg->wowlan_fw_name = "rtlwifi/rtl8821aefw_wowlan.bin"; 211 wowlan_fw_name = "rtlwifi/rtl8821aefw_wowlan.bin";
211 } 212 }
212 213
213 rtlpriv->max_fw_size = 0x8000; 214 rtlpriv->max_fw_size = 0x8000;
214 /*load normal firmware*/ 215 /*load normal firmware*/
215 pr_info("Using firmware %s\n", rtlpriv->cfg->fw_name); 216 pr_info("Using firmware %s\n", fw_name);
216 err = request_firmware_nowait(THIS_MODULE, 1, rtlpriv->cfg->fw_name, 217 err = request_firmware_nowait(THIS_MODULE, 1, fw_name,
217 rtlpriv->io.dev, GFP_KERNEL, hw, 218 rtlpriv->io.dev, GFP_KERNEL, hw,
218 rtl_fw_cb); 219 rtl_fw_cb);
219 if (err) { 220 if (err) {
@@ -222,9 +223,9 @@ int rtl8821ae_init_sw_vars(struct ieee80211_hw *hw)
222 return 1; 223 return 1;
223 } 224 }
224 /*load wowlan firmware*/ 225 /*load wowlan firmware*/
225 pr_info("Using firmware %s\n", rtlpriv->cfg->wowlan_fw_name); 226 pr_info("Using firmware %s\n", wowlan_fw_name);
226 err = request_firmware_nowait(THIS_MODULE, 1, 227 err = request_firmware_nowait(THIS_MODULE, 1,
227 rtlpriv->cfg->wowlan_fw_name, 228 wowlan_fw_name,
228 rtlpriv->io.dev, GFP_KERNEL, hw, 229 rtlpriv->io.dev, GFP_KERNEL, hw,
229 rtl_wowlan_fw_cb); 230 rtl_wowlan_fw_cb);
230 if (err) { 231 if (err) {
@@ -320,7 +321,6 @@ static const struct rtl_hal_cfg rtl8821ae_hal_cfg = {
320 .bar_id = 2, 321 .bar_id = 2,
321 .write_readback = true, 322 .write_readback = true,
322 .name = "rtl8821ae_pci", 323 .name = "rtl8821ae_pci",
323 .fw_name = "rtlwifi/rtl8821aefw.bin",
324 .ops = &rtl8821ae_hal_ops, 324 .ops = &rtl8821ae_hal_ops,
325 .mod_params = &rtl8821ae_mod_params, 325 .mod_params = &rtl8821ae_mod_params,
326 .maps[SYS_ISO_CTRL] = REG_SYS_ISO_CTRL, 326 .maps[SYS_ISO_CTRL] = REG_SYS_ISO_CTRL,
diff --git a/drivers/net/wireless/realtek/rtlwifi/wifi.h b/drivers/net/wireless/realtek/rtlwifi/wifi.h
index 595f7d5d091a..dafe486f8448 100644
--- a/drivers/net/wireless/realtek/rtlwifi/wifi.h
+++ b/drivers/net/wireless/realtek/rtlwifi/wifi.h
@@ -2278,9 +2278,7 @@ struct rtl_hal_cfg {
2278 u8 bar_id; 2278 u8 bar_id;
2279 bool write_readback; 2279 bool write_readback;
2280 char *name; 2280 char *name;
2281 char *fw_name;
2282 char *alt_fw_name; 2281 char *alt_fw_name;
2283 char *wowlan_fw_name;
2284 struct rtl_hal_ops *ops; 2282 struct rtl_hal_ops *ops;
2285 struct rtl_mod_params *mod_params; 2283 struct rtl_mod_params *mod_params;
2286 struct rtl_hal_usbint_cfg *usb_interface_cfg; 2284 struct rtl_hal_usbint_cfg *usb_interface_cfg;
diff --git a/drivers/net/wireless/ti/wlcore/sdio.c b/drivers/net/wireless/ti/wlcore/sdio.c
index a6e94b1a12cb..47fe7f96a242 100644
--- a/drivers/net/wireless/ti/wlcore/sdio.c
+++ b/drivers/net/wireless/ti/wlcore/sdio.c
@@ -391,7 +391,6 @@ static void wl1271_remove(struct sdio_func *func)
391 pm_runtime_get_noresume(&func->dev); 391 pm_runtime_get_noresume(&func->dev);
392 392
393 platform_device_unregister(glue->core); 393 platform_device_unregister(glue->core);
394 kfree(glue);
395} 394}
396 395
397#ifdef CONFIG_PM 396#ifdef CONFIG_PM
diff --git a/drivers/net/xen-netfront.c b/drivers/net/xen-netfront.c
index e17879dd5d5a..bf2744e1e3db 100644
--- a/drivers/net/xen-netfront.c
+++ b/drivers/net/xen-netfront.c
@@ -304,7 +304,7 @@ static void xennet_alloc_rx_buffers(struct netfront_queue *queue)
304 queue->rx_skbs[id] = skb; 304 queue->rx_skbs[id] = skb;
305 305
306 ref = gnttab_claim_grant_reference(&queue->gref_rx_head); 306 ref = gnttab_claim_grant_reference(&queue->gref_rx_head);
307 BUG_ON((signed short)ref < 0); 307 WARN_ON_ONCE(IS_ERR_VALUE((unsigned long)(int)ref));
308 queue->grant_rx_ref[id] = ref; 308 queue->grant_rx_ref[id] = ref;
309 309
310 page = skb_frag_page(&skb_shinfo(skb)->frags[0]); 310 page = skb_frag_page(&skb_shinfo(skb)->frags[0]);
@@ -428,7 +428,7 @@ static void xennet_tx_setup_grant(unsigned long gfn, unsigned int offset,
428 id = get_id_from_freelist(&queue->tx_skb_freelist, queue->tx_skbs); 428 id = get_id_from_freelist(&queue->tx_skb_freelist, queue->tx_skbs);
429 tx = RING_GET_REQUEST(&queue->tx, queue->tx.req_prod_pvt++); 429 tx = RING_GET_REQUEST(&queue->tx, queue->tx.req_prod_pvt++);
430 ref = gnttab_claim_grant_reference(&queue->gref_tx_head); 430 ref = gnttab_claim_grant_reference(&queue->gref_tx_head);
431 BUG_ON((signed short)ref < 0); 431 WARN_ON_ONCE(IS_ERR_VALUE((unsigned long)(int)ref));
432 432
433 gnttab_grant_foreign_access_ref(ref, queue->info->xbdev->otherend_id, 433 gnttab_grant_foreign_access_ref(ref, queue->info->xbdev->otherend_id,
434 gfn, GNTMAP_readonly); 434 gfn, GNTMAP_readonly);
diff --git a/drivers/nfc/mei_phy.c b/drivers/nfc/mei_phy.c
index 83deda4bb4d6..6f9563a96488 100644
--- a/drivers/nfc/mei_phy.c
+++ b/drivers/nfc/mei_phy.c
@@ -133,7 +133,7 @@ static int mei_nfc_if_version(struct nfc_mei_phy *phy)
133 return -ENOMEM; 133 return -ENOMEM;
134 134
135 bytes_recv = mei_cldev_recv(phy->cldev, (u8 *)reply, if_version_length); 135 bytes_recv = mei_cldev_recv(phy->cldev, (u8 *)reply, if_version_length);
136 if (bytes_recv < 0 || bytes_recv < sizeof(struct mei_nfc_reply)) { 136 if (bytes_recv < 0 || bytes_recv < if_version_length) {
137 pr_err("Could not read IF version\n"); 137 pr_err("Could not read IF version\n");
138 r = -EIO; 138 r = -EIO;
139 goto err; 139 goto err;
diff --git a/drivers/ntb/hw/intel/ntb_hw_intel.c b/drivers/ntb/hw/intel/ntb_hw_intel.c
index 0d5c29ae51de..7310a261c858 100644
--- a/drivers/ntb/hw/intel/ntb_hw_intel.c
+++ b/drivers/ntb/hw/intel/ntb_hw_intel.c
@@ -112,17 +112,17 @@ MODULE_PARM_DESC(xeon_b2b_usd_bar2_addr64,
112 112
113module_param_named(xeon_b2b_usd_bar4_addr64, 113module_param_named(xeon_b2b_usd_bar4_addr64,
114 xeon_b2b_usd_addr.bar4_addr64, ullong, 0644); 114 xeon_b2b_usd_addr.bar4_addr64, ullong, 0644);
115MODULE_PARM_DESC(xeon_b2b_usd_bar2_addr64, 115MODULE_PARM_DESC(xeon_b2b_usd_bar4_addr64,
116 "XEON B2B USD BAR 4 64-bit address"); 116 "XEON B2B USD BAR 4 64-bit address");
117 117
118module_param_named(xeon_b2b_usd_bar4_addr32, 118module_param_named(xeon_b2b_usd_bar4_addr32,
119 xeon_b2b_usd_addr.bar4_addr32, ullong, 0644); 119 xeon_b2b_usd_addr.bar4_addr32, ullong, 0644);
120MODULE_PARM_DESC(xeon_b2b_usd_bar2_addr64, 120MODULE_PARM_DESC(xeon_b2b_usd_bar4_addr32,
121 "XEON B2B USD split-BAR 4 32-bit address"); 121 "XEON B2B USD split-BAR 4 32-bit address");
122 122
123module_param_named(xeon_b2b_usd_bar5_addr32, 123module_param_named(xeon_b2b_usd_bar5_addr32,
124 xeon_b2b_usd_addr.bar5_addr32, ullong, 0644); 124 xeon_b2b_usd_addr.bar5_addr32, ullong, 0644);
125MODULE_PARM_DESC(xeon_b2b_usd_bar2_addr64, 125MODULE_PARM_DESC(xeon_b2b_usd_bar5_addr32,
126 "XEON B2B USD split-BAR 5 32-bit address"); 126 "XEON B2B USD split-BAR 5 32-bit address");
127 127
128module_param_named(xeon_b2b_dsd_bar2_addr64, 128module_param_named(xeon_b2b_dsd_bar2_addr64,
@@ -132,17 +132,17 @@ MODULE_PARM_DESC(xeon_b2b_dsd_bar2_addr64,
132 132
133module_param_named(xeon_b2b_dsd_bar4_addr64, 133module_param_named(xeon_b2b_dsd_bar4_addr64,
134 xeon_b2b_dsd_addr.bar4_addr64, ullong, 0644); 134 xeon_b2b_dsd_addr.bar4_addr64, ullong, 0644);
135MODULE_PARM_DESC(xeon_b2b_dsd_bar2_addr64, 135MODULE_PARM_DESC(xeon_b2b_dsd_bar4_addr64,
136 "XEON B2B DSD BAR 4 64-bit address"); 136 "XEON B2B DSD BAR 4 64-bit address");
137 137
138module_param_named(xeon_b2b_dsd_bar4_addr32, 138module_param_named(xeon_b2b_dsd_bar4_addr32,
139 xeon_b2b_dsd_addr.bar4_addr32, ullong, 0644); 139 xeon_b2b_dsd_addr.bar4_addr32, ullong, 0644);
140MODULE_PARM_DESC(xeon_b2b_dsd_bar2_addr64, 140MODULE_PARM_DESC(xeon_b2b_dsd_bar4_addr32,
141 "XEON B2B DSD split-BAR 4 32-bit address"); 141 "XEON B2B DSD split-BAR 4 32-bit address");
142 142
143module_param_named(xeon_b2b_dsd_bar5_addr32, 143module_param_named(xeon_b2b_dsd_bar5_addr32,
144 xeon_b2b_dsd_addr.bar5_addr32, ullong, 0644); 144 xeon_b2b_dsd_addr.bar5_addr32, ullong, 0644);
145MODULE_PARM_DESC(xeon_b2b_dsd_bar2_addr64, 145MODULE_PARM_DESC(xeon_b2b_dsd_bar5_addr32,
146 "XEON B2B DSD split-BAR 5 32-bit address"); 146 "XEON B2B DSD split-BAR 5 32-bit address");
147 147
148#ifndef ioread64 148#ifndef ioread64
@@ -1755,6 +1755,8 @@ static int xeon_setup_b2b_mw(struct intel_ntb_dev *ndev,
1755 XEON_B2B_MIN_SIZE); 1755 XEON_B2B_MIN_SIZE);
1756 if (!ndev->peer_mmio) 1756 if (!ndev->peer_mmio)
1757 return -EIO; 1757 return -EIO;
1758
1759 ndev->peer_addr = pci_resource_start(pdev, b2b_bar);
1758 } 1760 }
1759 1761
1760 return 0; 1762 return 0;
@@ -2019,6 +2021,7 @@ static int intel_ntb_init_pci(struct intel_ntb_dev *ndev, struct pci_dev *pdev)
2019 goto err_mmio; 2021 goto err_mmio;
2020 } 2022 }
2021 ndev->peer_mmio = ndev->self_mmio; 2023 ndev->peer_mmio = ndev->self_mmio;
2024 ndev->peer_addr = pci_resource_start(pdev, 0);
2022 2025
2023 return 0; 2026 return 0;
2024 2027
diff --git a/drivers/ntb/ntb_transport.c b/drivers/ntb/ntb_transport.c
index 8601c10acf74..4eb8adb34508 100644
--- a/drivers/ntb/ntb_transport.c
+++ b/drivers/ntb/ntb_transport.c
@@ -257,7 +257,7 @@ enum {
257#define NTB_QP_DEF_NUM_ENTRIES 100 257#define NTB_QP_DEF_NUM_ENTRIES 100
258#define NTB_LINK_DOWN_TIMEOUT 10 258#define NTB_LINK_DOWN_TIMEOUT 10
259#define DMA_RETRIES 20 259#define DMA_RETRIES 20
260#define DMA_OUT_RESOURCE_TO 50 260#define DMA_OUT_RESOURCE_TO msecs_to_jiffies(50)
261 261
262static void ntb_transport_rxc_db(unsigned long data); 262static void ntb_transport_rxc_db(unsigned long data);
263static const struct ntb_ctx_ops ntb_transport_ops; 263static const struct ntb_ctx_ops ntb_transport_ops;
diff --git a/drivers/ntb/test/ntb_perf.c b/drivers/ntb/test/ntb_perf.c
index 6a50f20bf1cd..e75d4fdc0866 100644
--- a/drivers/ntb/test/ntb_perf.c
+++ b/drivers/ntb/test/ntb_perf.c
@@ -72,7 +72,7 @@
72#define MAX_THREADS 32 72#define MAX_THREADS 32
73#define MAX_TEST_SIZE SZ_1M 73#define MAX_TEST_SIZE SZ_1M
74#define MAX_SRCS 32 74#define MAX_SRCS 32
75#define DMA_OUT_RESOURCE_TO 50 75#define DMA_OUT_RESOURCE_TO msecs_to_jiffies(50)
76#define DMA_RETRIES 20 76#define DMA_RETRIES 20
77#define SZ_4G (1ULL << 32) 77#define SZ_4G (1ULL << 32)
78#define MAX_SEG_ORDER 20 /* no larger than 1M for kmalloc buffer */ 78#define MAX_SEG_ORDER 20 /* no larger than 1M for kmalloc buffer */
@@ -589,7 +589,7 @@ static ssize_t debugfs_run_read(struct file *filp, char __user *ubuf,
589 return -ENOMEM; 589 return -ENOMEM;
590 590
591 if (mutex_is_locked(&perf->run_mutex)) { 591 if (mutex_is_locked(&perf->run_mutex)) {
592 out_off = snprintf(buf, 64, "running\n"); 592 out_off = scnprintf(buf, 64, "running\n");
593 goto read_from_buf; 593 goto read_from_buf;
594 } 594 }
595 595
@@ -600,14 +600,14 @@ static ssize_t debugfs_run_read(struct file *filp, char __user *ubuf,
600 break; 600 break;
601 601
602 if (pctx->status) { 602 if (pctx->status) {
603 out_off += snprintf(buf + out_off, 1024 - out_off, 603 out_off += scnprintf(buf + out_off, 1024 - out_off,
604 "%d: error %d\n", i, 604 "%d: error %d\n", i,
605 pctx->status); 605 pctx->status);
606 continue; 606 continue;
607 } 607 }
608 608
609 rate = div64_u64(pctx->copied, pctx->diff_us); 609 rate = div64_u64(pctx->copied, pctx->diff_us);
610 out_off += snprintf(buf + out_off, 1024 - out_off, 610 out_off += scnprintf(buf + out_off, 1024 - out_off,
611 "%d: copied %llu bytes in %llu usecs, %llu MBytes/s\n", 611 "%d: copied %llu bytes in %llu usecs, %llu MBytes/s\n",
612 i, pctx->copied, pctx->diff_us, rate); 612 i, pctx->copied, pctx->diff_us, rate);
613 } 613 }
diff --git a/drivers/ntb/test/ntb_pingpong.c b/drivers/ntb/test/ntb_pingpong.c
index 7d311799fca1..435861189d97 100644
--- a/drivers/ntb/test/ntb_pingpong.c
+++ b/drivers/ntb/test/ntb_pingpong.c
@@ -88,7 +88,7 @@ MODULE_PARM_DESC(delay_ms, "Milliseconds to delay the response to peer");
88 88
89static unsigned long db_init = 0x7; 89static unsigned long db_init = 0x7;
90module_param(db_init, ulong, 0644); 90module_param(db_init, ulong, 0644);
91MODULE_PARM_DESC(delay_ms, "Initial doorbell bits to ring on the peer"); 91MODULE_PARM_DESC(db_init, "Initial doorbell bits to ring on the peer");
92 92
93struct pp_ctx { 93struct pp_ctx {
94 struct ntb_dev *ntb; 94 struct ntb_dev *ntb;
diff --git a/drivers/nvdimm/Kconfig b/drivers/nvdimm/Kconfig
index 8b2b740d6679..124c2432ac9c 100644
--- a/drivers/nvdimm/Kconfig
+++ b/drivers/nvdimm/Kconfig
@@ -89,7 +89,7 @@ config NVDIMM_PFN
89 Select Y if unsure 89 Select Y if unsure
90 90
91config NVDIMM_DAX 91config NVDIMM_DAX
92 tristate "NVDIMM DAX: Raw access to persistent memory" 92 bool "NVDIMM DAX: Raw access to persistent memory"
93 default LIBNVDIMM 93 default LIBNVDIMM
94 depends on NVDIMM_PFN 94 depends on NVDIMM_PFN
95 help 95 help
diff --git a/drivers/nvdimm/bus.c b/drivers/nvdimm/bus.c
index a8b6949a8778..23d4a1728cdf 100644
--- a/drivers/nvdimm/bus.c
+++ b/drivers/nvdimm/bus.c
@@ -715,7 +715,7 @@ EXPORT_SYMBOL_GPL(nd_cmd_in_size);
715 715
716u32 nd_cmd_out_size(struct nvdimm *nvdimm, int cmd, 716u32 nd_cmd_out_size(struct nvdimm *nvdimm, int cmd,
717 const struct nd_cmd_desc *desc, int idx, const u32 *in_field, 717 const struct nd_cmd_desc *desc, int idx, const u32 *in_field,
718 const u32 *out_field) 718 const u32 *out_field, unsigned long remainder)
719{ 719{
720 if (idx >= desc->out_num) 720 if (idx >= desc->out_num)
721 return UINT_MAX; 721 return UINT_MAX;
@@ -727,9 +727,24 @@ u32 nd_cmd_out_size(struct nvdimm *nvdimm, int cmd,
727 return in_field[1]; 727 return in_field[1];
728 else if (nvdimm && cmd == ND_CMD_VENDOR && idx == 2) 728 else if (nvdimm && cmd == ND_CMD_VENDOR && idx == 2)
729 return out_field[1]; 729 return out_field[1];
730 else if (!nvdimm && cmd == ND_CMD_ARS_STATUS && idx == 2) 730 else if (!nvdimm && cmd == ND_CMD_ARS_STATUS && idx == 2) {
731 return out_field[1] - 8; 731 /*
732 else if (cmd == ND_CMD_CALL) { 732 * Per table 9-276 ARS Data in ACPI 6.1, out_field[1] is
733 * "Size of Output Buffer in bytes, including this
734 * field."
735 */
736 if (out_field[1] < 4)
737 return 0;
738 /*
739 * ACPI 6.1 is ambiguous if 'status' is included in the
740 * output size. If we encounter an output size that
741 * overshoots the remainder by 4 bytes, assume it was
742 * including 'status'.
743 */
744 if (out_field[1] - 8 == remainder)
745 return remainder;
746 return out_field[1] - 4;
747 } else if (cmd == ND_CMD_CALL) {
733 struct nd_cmd_pkg *pkg = (struct nd_cmd_pkg *) in_field; 748 struct nd_cmd_pkg *pkg = (struct nd_cmd_pkg *) in_field;
734 749
735 return pkg->nd_size_out; 750 return pkg->nd_size_out;
@@ -876,7 +891,7 @@ static int __nd_ioctl(struct nvdimm_bus *nvdimm_bus, struct nvdimm *nvdimm,
876 /* process an output envelope */ 891 /* process an output envelope */
877 for (i = 0; i < desc->out_num; i++) { 892 for (i = 0; i < desc->out_num; i++) {
878 u32 out_size = nd_cmd_out_size(nvdimm, cmd, desc, i, 893 u32 out_size = nd_cmd_out_size(nvdimm, cmd, desc, i,
879 (u32 *) in_env, (u32 *) out_env); 894 (u32 *) in_env, (u32 *) out_env, 0);
880 u32 copy; 895 u32 copy;
881 896
882 if (out_size == UINT_MAX) { 897 if (out_size == UINT_MAX) {
diff --git a/drivers/nvdimm/namespace_devs.c b/drivers/nvdimm/namespace_devs.c
index 3509cff68ef9..abe5c6bc756c 100644
--- a/drivers/nvdimm/namespace_devs.c
+++ b/drivers/nvdimm/namespace_devs.c
@@ -2176,12 +2176,14 @@ static struct device **scan_labels(struct nd_region *nd_region)
2176 return devs; 2176 return devs;
2177 2177
2178 err: 2178 err:
2179 for (i = 0; devs[i]; i++) 2179 if (devs) {
2180 if (is_nd_blk(&nd_region->dev)) 2180 for (i = 0; devs[i]; i++)
2181 namespace_blk_release(devs[i]); 2181 if (is_nd_blk(&nd_region->dev))
2182 else 2182 namespace_blk_release(devs[i]);
2183 namespace_pmem_release(devs[i]); 2183 else
2184 kfree(devs); 2184 namespace_pmem_release(devs[i]);
2185 kfree(devs);
2186 }
2185 return NULL; 2187 return NULL;
2186} 2188}
2187 2189
diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c
index 42b3a8217073..24618431a14b 100644
--- a/drivers/nvdimm/pmem.c
+++ b/drivers/nvdimm/pmem.c
@@ -47,7 +47,7 @@ static struct nd_region *to_region(struct pmem_device *pmem)
47 return to_nd_region(to_dev(pmem)->parent); 47 return to_nd_region(to_dev(pmem)->parent);
48} 48}
49 49
50static void pmem_clear_poison(struct pmem_device *pmem, phys_addr_t offset, 50static int pmem_clear_poison(struct pmem_device *pmem, phys_addr_t offset,
51 unsigned int len) 51 unsigned int len)
52{ 52{
53 struct device *dev = to_dev(pmem); 53 struct device *dev = to_dev(pmem);
@@ -62,8 +62,12 @@ static void pmem_clear_poison(struct pmem_device *pmem, phys_addr_t offset,
62 __func__, (unsigned long long) sector, 62 __func__, (unsigned long long) sector,
63 cleared / 512, cleared / 512 > 1 ? "s" : ""); 63 cleared / 512, cleared / 512 > 1 ? "s" : "");
64 badblocks_clear(&pmem->bb, sector, cleared / 512); 64 badblocks_clear(&pmem->bb, sector, cleared / 512);
65 } else {
66 return -EIO;
65 } 67 }
68
66 invalidate_pmem(pmem->virt_addr + offset, len); 69 invalidate_pmem(pmem->virt_addr + offset, len);
70 return 0;
67} 71}
68 72
69static void write_pmem(void *pmem_addr, struct page *page, 73static void write_pmem(void *pmem_addr, struct page *page,
@@ -123,7 +127,7 @@ static int pmem_do_bvec(struct pmem_device *pmem, struct page *page,
123 flush_dcache_page(page); 127 flush_dcache_page(page);
124 write_pmem(pmem_addr, page, off, len); 128 write_pmem(pmem_addr, page, off, len);
125 if (unlikely(bad_pmem)) { 129 if (unlikely(bad_pmem)) {
126 pmem_clear_poison(pmem, pmem_off, len); 130 rc = pmem_clear_poison(pmem, pmem_off, len);
127 write_pmem(pmem_addr, page, off, len); 131 write_pmem(pmem_addr, page, off, len);
128 } 132 }
129 } 133 }
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 329381a28edf..79e679d12f3b 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -554,7 +554,7 @@ int nvme_identify_ctrl(struct nvme_ctrl *dev, struct nvme_id_ctrl **id)
554 554
555 /* gcc-4.4.4 (at least) has issues with initializers and anon unions */ 555 /* gcc-4.4.4 (at least) has issues with initializers and anon unions */
556 c.identify.opcode = nvme_admin_identify; 556 c.identify.opcode = nvme_admin_identify;
557 c.identify.cns = cpu_to_le32(1); 557 c.identify.cns = cpu_to_le32(NVME_ID_CNS_CTRL);
558 558
559 *id = kmalloc(sizeof(struct nvme_id_ctrl), GFP_KERNEL); 559 *id = kmalloc(sizeof(struct nvme_id_ctrl), GFP_KERNEL);
560 if (!*id) 560 if (!*id)
@@ -572,7 +572,7 @@ static int nvme_identify_ns_list(struct nvme_ctrl *dev, unsigned nsid, __le32 *n
572 struct nvme_command c = { }; 572 struct nvme_command c = { };
573 573
574 c.identify.opcode = nvme_admin_identify; 574 c.identify.opcode = nvme_admin_identify;
575 c.identify.cns = cpu_to_le32(2); 575 c.identify.cns = cpu_to_le32(NVME_ID_CNS_NS_ACTIVE_LIST);
576 c.identify.nsid = cpu_to_le32(nsid); 576 c.identify.nsid = cpu_to_le32(nsid);
577 return nvme_submit_sync_cmd(dev->admin_q, &c, ns_list, 0x1000); 577 return nvme_submit_sync_cmd(dev->admin_q, &c, ns_list, 0x1000);
578} 578}
@@ -900,9 +900,9 @@ static int nvme_revalidate_ns(struct nvme_ns *ns, struct nvme_id_ns **id)
900 return -ENODEV; 900 return -ENODEV;
901 } 901 }
902 902
903 if (ns->ctrl->vs >= NVME_VS(1, 1)) 903 if (ns->ctrl->vs >= NVME_VS(1, 1, 0))
904 memcpy(ns->eui, (*id)->eui64, sizeof(ns->eui)); 904 memcpy(ns->eui, (*id)->eui64, sizeof(ns->eui));
905 if (ns->ctrl->vs >= NVME_VS(1, 2)) 905 if (ns->ctrl->vs >= NVME_VS(1, 2, 0))
906 memcpy(ns->uuid, (*id)->nguid, sizeof(ns->uuid)); 906 memcpy(ns->uuid, (*id)->nguid, sizeof(ns->uuid));
907 907
908 return 0; 908 return 0;
@@ -1086,6 +1086,8 @@ static int nvme_wait_ready(struct nvme_ctrl *ctrl, u64 cap, bool enabled)
1086 int ret; 1086 int ret;
1087 1087
1088 while ((ret = ctrl->ops->reg_read32(ctrl, NVME_REG_CSTS, &csts)) == 0) { 1088 while ((ret = ctrl->ops->reg_read32(ctrl, NVME_REG_CSTS, &csts)) == 0) {
1089 if (csts == ~0)
1090 return -ENODEV;
1089 if ((csts & NVME_CSTS_RDY) == bit) 1091 if ((csts & NVME_CSTS_RDY) == bit)
1090 break; 1092 break;
1091 1093
@@ -1240,7 +1242,7 @@ int nvme_init_identify(struct nvme_ctrl *ctrl)
1240 } 1242 }
1241 page_shift = NVME_CAP_MPSMIN(cap) + 12; 1243 page_shift = NVME_CAP_MPSMIN(cap) + 12;
1242 1244
1243 if (ctrl->vs >= NVME_VS(1, 1)) 1245 if (ctrl->vs >= NVME_VS(1, 1, 0))
1244 ctrl->subsystem = NVME_CAP_NSSRC(cap); 1246 ctrl->subsystem = NVME_CAP_NSSRC(cap);
1245 1247
1246 ret = nvme_identify_ctrl(ctrl, &id); 1248 ret = nvme_identify_ctrl(ctrl, &id);
@@ -1840,7 +1842,7 @@ static void nvme_scan_work(struct work_struct *work)
1840 return; 1842 return;
1841 1843
1842 nn = le32_to_cpu(id->nn); 1844 nn = le32_to_cpu(id->nn);
1843 if (ctrl->vs >= NVME_VS(1, 1) && 1845 if (ctrl->vs >= NVME_VS(1, 1, 0) &&
1844 !(ctrl->quirks & NVME_QUIRK_IDENTIFY_CNS)) { 1846 !(ctrl->quirks & NVME_QUIRK_IDENTIFY_CNS)) {
1845 if (!nvme_scan_ns_list(ctrl, nn)) 1847 if (!nvme_scan_ns_list(ctrl, nn))
1846 goto done; 1848 goto done;
diff --git a/drivers/nvme/host/lightnvm.c b/drivers/nvme/host/lightnvm.c
index f5e3011e31fc..5daf2f4be0cd 100644
--- a/drivers/nvme/host/lightnvm.c
+++ b/drivers/nvme/host/lightnvm.c
@@ -612,7 +612,7 @@ int nvme_nvm_register(struct nvme_ns *ns, char *disk_name, int node,
612 612
613 ret = nvm_register(dev); 613 ret = nvm_register(dev);
614 614
615 ns->lba_shift = ilog2(dev->sec_size) - 9; 615 ns->lba_shift = ilog2(dev->sec_size);
616 616
617 if (sysfs_create_group(&dev->dev.kobj, attrs)) 617 if (sysfs_create_group(&dev->dev.kobj, attrs))
618 pr_warn("%s: failed to create sysfs group for identification\n", 618 pr_warn("%s: failed to create sysfs group for identification\n",
diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index 0fc99f0f2571..5e52034ab010 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -99,6 +99,7 @@ struct nvme_dev {
99 dma_addr_t cmb_dma_addr; 99 dma_addr_t cmb_dma_addr;
100 u64 cmb_size; 100 u64 cmb_size;
101 u32 cmbsz; 101 u32 cmbsz;
102 u32 cmbloc;
102 struct nvme_ctrl ctrl; 103 struct nvme_ctrl ctrl;
103 struct completion ioq_wait; 104 struct completion ioq_wait;
104}; 105};
@@ -893,7 +894,7 @@ static enum blk_eh_timer_return nvme_timeout(struct request *req, bool reserved)
893 "I/O %d QID %d timeout, reset controller\n", 894 "I/O %d QID %d timeout, reset controller\n",
894 req->tag, nvmeq->qid); 895 req->tag, nvmeq->qid);
895 nvme_dev_disable(dev, false); 896 nvme_dev_disable(dev, false);
896 queue_work(nvme_workq, &dev->reset_work); 897 nvme_reset(dev);
897 898
898 /* 899 /*
899 * Mark the request as handled, since the inline shutdown 900 * Mark the request as handled, since the inline shutdown
@@ -1214,7 +1215,7 @@ static int nvme_configure_admin_queue(struct nvme_dev *dev)
1214 u64 cap = lo_hi_readq(dev->bar + NVME_REG_CAP); 1215 u64 cap = lo_hi_readq(dev->bar + NVME_REG_CAP);
1215 struct nvme_queue *nvmeq; 1216 struct nvme_queue *nvmeq;
1216 1217
1217 dev->subsystem = readl(dev->bar + NVME_REG_VS) >= NVME_VS(1, 1) ? 1218 dev->subsystem = readl(dev->bar + NVME_REG_VS) >= NVME_VS(1, 1, 0) ?
1218 NVME_CAP_NSSRC(cap) : 0; 1219 NVME_CAP_NSSRC(cap) : 0;
1219 1220
1220 if (dev->subsystem && 1221 if (dev->subsystem &&
@@ -1241,20 +1242,16 @@ static int nvme_configure_admin_queue(struct nvme_dev *dev)
1241 1242
1242 result = nvme_enable_ctrl(&dev->ctrl, cap); 1243 result = nvme_enable_ctrl(&dev->ctrl, cap);
1243 if (result) 1244 if (result)
1244 goto free_nvmeq; 1245 return result;
1245 1246
1246 nvmeq->cq_vector = 0; 1247 nvmeq->cq_vector = 0;
1247 result = queue_request_irq(nvmeq); 1248 result = queue_request_irq(nvmeq);
1248 if (result) { 1249 if (result) {
1249 nvmeq->cq_vector = -1; 1250 nvmeq->cq_vector = -1;
1250 goto free_nvmeq; 1251 return result;
1251 } 1252 }
1252 1253
1253 return result; 1254 return result;
1254
1255 free_nvmeq:
1256 nvme_free_queues(dev, 0);
1257 return result;
1258} 1255}
1259 1256
1260static bool nvme_should_reset(struct nvme_dev *dev, u32 csts) 1257static bool nvme_should_reset(struct nvme_dev *dev, u32 csts)
@@ -1291,7 +1288,7 @@ static void nvme_watchdog_timer(unsigned long data)
1291 1288
1292 /* Skip controllers under certain specific conditions. */ 1289 /* Skip controllers under certain specific conditions. */
1293 if (nvme_should_reset(dev, csts)) { 1290 if (nvme_should_reset(dev, csts)) {
1294 if (queue_work(nvme_workq, &dev->reset_work)) 1291 if (!nvme_reset(dev))
1295 dev_warn(dev->dev, 1292 dev_warn(dev->dev,
1296 "Failed status: 0x%x, reset controller.\n", 1293 "Failed status: 0x%x, reset controller.\n",
1297 csts); 1294 csts);
@@ -1316,10 +1313,8 @@ static int nvme_create_io_queues(struct nvme_dev *dev)
1316 max = min(dev->max_qid, dev->queue_count - 1); 1313 max = min(dev->max_qid, dev->queue_count - 1);
1317 for (i = dev->online_queues; i <= max; i++) { 1314 for (i = dev->online_queues; i <= max; i++) {
1318 ret = nvme_create_queue(dev->queues[i], i); 1315 ret = nvme_create_queue(dev->queues[i], i);
1319 if (ret) { 1316 if (ret)
1320 nvme_free_queues(dev, i);
1321 break; 1317 break;
1322 }
1323 } 1318 }
1324 1319
1325 /* 1320 /*
@@ -1331,28 +1326,37 @@ static int nvme_create_io_queues(struct nvme_dev *dev)
1331 return ret >= 0 ? 0 : ret; 1326 return ret >= 0 ? 0 : ret;
1332} 1327}
1333 1328
1329static ssize_t nvme_cmb_show(struct device *dev,
1330 struct device_attribute *attr,
1331 char *buf)
1332{
1333 struct nvme_dev *ndev = to_nvme_dev(dev_get_drvdata(dev));
1334
1335 return snprintf(buf, PAGE_SIZE, "cmbloc : x%08x\ncmbsz : x%08x\n",
1336 ndev->cmbloc, ndev->cmbsz);
1337}
1338static DEVICE_ATTR(cmb, S_IRUGO, nvme_cmb_show, NULL);
1339
1334static void __iomem *nvme_map_cmb(struct nvme_dev *dev) 1340static void __iomem *nvme_map_cmb(struct nvme_dev *dev)
1335{ 1341{
1336 u64 szu, size, offset; 1342 u64 szu, size, offset;
1337 u32 cmbloc;
1338 resource_size_t bar_size; 1343 resource_size_t bar_size;
1339 struct pci_dev *pdev = to_pci_dev(dev->dev); 1344 struct pci_dev *pdev = to_pci_dev(dev->dev);
1340 void __iomem *cmb; 1345 void __iomem *cmb;
1341 dma_addr_t dma_addr; 1346 dma_addr_t dma_addr;
1342 1347
1343 if (!use_cmb_sqes)
1344 return NULL;
1345
1346 dev->cmbsz = readl(dev->bar + NVME_REG_CMBSZ); 1348 dev->cmbsz = readl(dev->bar + NVME_REG_CMBSZ);
1347 if (!(NVME_CMB_SZ(dev->cmbsz))) 1349 if (!(NVME_CMB_SZ(dev->cmbsz)))
1348 return NULL; 1350 return NULL;
1351 dev->cmbloc = readl(dev->bar + NVME_REG_CMBLOC);
1349 1352
1350 cmbloc = readl(dev->bar + NVME_REG_CMBLOC); 1353 if (!use_cmb_sqes)
1354 return NULL;
1351 1355
1352 szu = (u64)1 << (12 + 4 * NVME_CMB_SZU(dev->cmbsz)); 1356 szu = (u64)1 << (12 + 4 * NVME_CMB_SZU(dev->cmbsz));
1353 size = szu * NVME_CMB_SZ(dev->cmbsz); 1357 size = szu * NVME_CMB_SZ(dev->cmbsz);
1354 offset = szu * NVME_CMB_OFST(cmbloc); 1358 offset = szu * NVME_CMB_OFST(dev->cmbloc);
1355 bar_size = pci_resource_len(pdev, NVME_CMB_BIR(cmbloc)); 1359 bar_size = pci_resource_len(pdev, NVME_CMB_BIR(dev->cmbloc));
1356 1360
1357 if (offset > bar_size) 1361 if (offset > bar_size)
1358 return NULL; 1362 return NULL;
@@ -1365,7 +1369,7 @@ static void __iomem *nvme_map_cmb(struct nvme_dev *dev)
1365 if (size > bar_size - offset) 1369 if (size > bar_size - offset)
1366 size = bar_size - offset; 1370 size = bar_size - offset;
1367 1371
1368 dma_addr = pci_resource_start(pdev, NVME_CMB_BIR(cmbloc)) + offset; 1372 dma_addr = pci_resource_start(pdev, NVME_CMB_BIR(dev->cmbloc)) + offset;
1369 cmb = ioremap_wc(dma_addr, size); 1373 cmb = ioremap_wc(dma_addr, size);
1370 if (!cmb) 1374 if (!cmb)
1371 return NULL; 1375 return NULL;
@@ -1450,13 +1454,9 @@ static int nvme_setup_io_queues(struct nvme_dev *dev)
1450 result = queue_request_irq(adminq); 1454 result = queue_request_irq(adminq);
1451 if (result) { 1455 if (result) {
1452 adminq->cq_vector = -1; 1456 adminq->cq_vector = -1;
1453 goto free_queues; 1457 return result;
1454 } 1458 }
1455 return nvme_create_io_queues(dev); 1459 return nvme_create_io_queues(dev);
1456
1457 free_queues:
1458 nvme_free_queues(dev, 1);
1459 return result;
1460} 1460}
1461 1461
1462static void nvme_del_queue_end(struct request *req, int error) 1462static void nvme_del_queue_end(struct request *req, int error)
@@ -1511,9 +1511,9 @@ static int nvme_delete_queue(struct nvme_queue *nvmeq, u8 opcode)
1511 return 0; 1511 return 0;
1512} 1512}
1513 1513
1514static void nvme_disable_io_queues(struct nvme_dev *dev) 1514static void nvme_disable_io_queues(struct nvme_dev *dev, int queues)
1515{ 1515{
1516 int pass, queues = dev->online_queues - 1; 1516 int pass;
1517 unsigned long timeout; 1517 unsigned long timeout;
1518 u8 opcode = nvme_admin_delete_sq; 1518 u8 opcode = nvme_admin_delete_sq;
1519 1519
@@ -1616,9 +1616,25 @@ static int nvme_pci_enable(struct nvme_dev *dev)
1616 dev->q_depth); 1616 dev->q_depth);
1617 } 1617 }
1618 1618
1619 if (readl(dev->bar + NVME_REG_VS) >= NVME_VS(1, 2)) 1619 /*
1620 * CMBs can currently only exist on >=1.2 PCIe devices. We only
1621 * populate sysfs if a CMB is implemented. Note that we add the
1622 * CMB attribute to the nvme_ctrl kobj which removes the need to remove
1623 * it on exit. Since nvme_dev_attrs_group has no name we can pass
1624 * NULL as final argument to sysfs_add_file_to_group.
1625 */
1626
1627 if (readl(dev->bar + NVME_REG_VS) >= NVME_VS(1, 2, 0)) {
1620 dev->cmb = nvme_map_cmb(dev); 1628 dev->cmb = nvme_map_cmb(dev);
1621 1629
1630 if (dev->cmbsz) {
1631 if (sysfs_add_file_to_group(&dev->ctrl.device->kobj,
1632 &dev_attr_cmb.attr, NULL))
1633 dev_warn(dev->dev,
1634 "failed to add sysfs attribute for CMB\n");
1635 }
1636 }
1637
1622 pci_enable_pcie_error_reporting(pdev); 1638 pci_enable_pcie_error_reporting(pdev);
1623 pci_save_state(pdev); 1639 pci_save_state(pdev);
1624 return 0; 1640 return 0;
@@ -1649,7 +1665,7 @@ static void nvme_pci_disable(struct nvme_dev *dev)
1649 1665
1650static void nvme_dev_disable(struct nvme_dev *dev, bool shutdown) 1666static void nvme_dev_disable(struct nvme_dev *dev, bool shutdown)
1651{ 1667{
1652 int i; 1668 int i, queues;
1653 u32 csts = -1; 1669 u32 csts = -1;
1654 1670
1655 del_timer_sync(&dev->watchdog_timer); 1671 del_timer_sync(&dev->watchdog_timer);
@@ -1660,6 +1676,7 @@ static void nvme_dev_disable(struct nvme_dev *dev, bool shutdown)
1660 csts = readl(dev->bar + NVME_REG_CSTS); 1676 csts = readl(dev->bar + NVME_REG_CSTS);
1661 } 1677 }
1662 1678
1679 queues = dev->online_queues - 1;
1663 for (i = dev->queue_count - 1; i > 0; i--) 1680 for (i = dev->queue_count - 1; i > 0; i--)
1664 nvme_suspend_queue(dev->queues[i]); 1681 nvme_suspend_queue(dev->queues[i]);
1665 1682
@@ -1671,7 +1688,7 @@ static void nvme_dev_disable(struct nvme_dev *dev, bool shutdown)
1671 if (dev->queue_count) 1688 if (dev->queue_count)
1672 nvme_suspend_queue(dev->queues[0]); 1689 nvme_suspend_queue(dev->queues[0]);
1673 } else { 1690 } else {
1674 nvme_disable_io_queues(dev); 1691 nvme_disable_io_queues(dev, queues);
1675 nvme_disable_admin_queue(dev, shutdown); 1692 nvme_disable_admin_queue(dev, shutdown);
1676 } 1693 }
1677 nvme_pci_disable(dev); 1694 nvme_pci_disable(dev);
@@ -1818,11 +1835,10 @@ static int nvme_reset(struct nvme_dev *dev)
1818{ 1835{
1819 if (!dev->ctrl.admin_q || blk_queue_dying(dev->ctrl.admin_q)) 1836 if (!dev->ctrl.admin_q || blk_queue_dying(dev->ctrl.admin_q))
1820 return -ENODEV; 1837 return -ENODEV;
1821 1838 if (work_busy(&dev->reset_work))
1839 return -ENODEV;
1822 if (!queue_work(nvme_workq, &dev->reset_work)) 1840 if (!queue_work(nvme_workq, &dev->reset_work))
1823 return -EBUSY; 1841 return -EBUSY;
1824
1825 flush_work(&dev->reset_work);
1826 return 0; 1842 return 0;
1827} 1843}
1828 1844
@@ -1846,7 +1862,12 @@ static int nvme_pci_reg_read64(struct nvme_ctrl *ctrl, u32 off, u64 *val)
1846 1862
1847static int nvme_pci_reset_ctrl(struct nvme_ctrl *ctrl) 1863static int nvme_pci_reset_ctrl(struct nvme_ctrl *ctrl)
1848{ 1864{
1849 return nvme_reset(to_nvme_dev(ctrl)); 1865 struct nvme_dev *dev = to_nvme_dev(ctrl);
1866 int ret = nvme_reset(dev);
1867
1868 if (!ret)
1869 flush_work(&dev->reset_work);
1870 return ret;
1850} 1871}
1851 1872
1852static const struct nvme_ctrl_ops nvme_pci_ctrl_ops = { 1873static const struct nvme_ctrl_ops nvme_pci_ctrl_ops = {
@@ -1940,7 +1961,7 @@ static void nvme_reset_notify(struct pci_dev *pdev, bool prepare)
1940 if (prepare) 1961 if (prepare)
1941 nvme_dev_disable(dev, false); 1962 nvme_dev_disable(dev, false);
1942 else 1963 else
1943 queue_work(nvme_workq, &dev->reset_work); 1964 nvme_reset(dev);
1944} 1965}
1945 1966
1946static void nvme_shutdown(struct pci_dev *pdev) 1967static void nvme_shutdown(struct pci_dev *pdev)
@@ -2009,7 +2030,7 @@ static int nvme_resume(struct device *dev)
2009 struct pci_dev *pdev = to_pci_dev(dev); 2030 struct pci_dev *pdev = to_pci_dev(dev);
2010 struct nvme_dev *ndev = pci_get_drvdata(pdev); 2031 struct nvme_dev *ndev = pci_get_drvdata(pdev);
2011 2032
2012 queue_work(nvme_workq, &ndev->reset_work); 2033 nvme_reset(ndev);
2013 return 0; 2034 return 0;
2014} 2035}
2015#endif 2036#endif
@@ -2048,7 +2069,7 @@ static pci_ers_result_t nvme_slot_reset(struct pci_dev *pdev)
2048 2069
2049 dev_info(dev->ctrl.device, "restart after slot reset\n"); 2070 dev_info(dev->ctrl.device, "restart after slot reset\n");
2050 pci_restore_state(pdev); 2071 pci_restore_state(pdev);
2051 queue_work(nvme_workq, &dev->reset_work); 2072 nvme_reset(dev);
2052 return PCI_ERS_RESULT_RECOVERED; 2073 return PCI_ERS_RESULT_RECOVERED;
2053} 2074}
2054 2075
diff --git a/drivers/nvme/host/rdma.c b/drivers/nvme/host/rdma.c
index 5a8388177959..3d25add36d91 100644
--- a/drivers/nvme/host/rdma.c
+++ b/drivers/nvme/host/rdma.c
@@ -83,6 +83,7 @@ enum nvme_rdma_queue_flags {
83 NVME_RDMA_Q_CONNECTED = (1 << 0), 83 NVME_RDMA_Q_CONNECTED = (1 << 0),
84 NVME_RDMA_IB_QUEUE_ALLOCATED = (1 << 1), 84 NVME_RDMA_IB_QUEUE_ALLOCATED = (1 << 1),
85 NVME_RDMA_Q_DELETING = (1 << 2), 85 NVME_RDMA_Q_DELETING = (1 << 2),
86 NVME_RDMA_Q_LIVE = (1 << 3),
86}; 87};
87 88
88struct nvme_rdma_queue { 89struct nvme_rdma_queue {
@@ -624,10 +625,18 @@ static int nvme_rdma_connect_io_queues(struct nvme_rdma_ctrl *ctrl)
624 625
625 for (i = 1; i < ctrl->queue_count; i++) { 626 for (i = 1; i < ctrl->queue_count; i++) {
626 ret = nvmf_connect_io_queue(&ctrl->ctrl, i); 627 ret = nvmf_connect_io_queue(&ctrl->ctrl, i);
627 if (ret) 628 if (ret) {
628 break; 629 dev_info(ctrl->ctrl.device,
630 "failed to connect i/o queue: %d\n", ret);
631 goto out_free_queues;
632 }
633 set_bit(NVME_RDMA_Q_LIVE, &ctrl->queues[i].flags);
629 } 634 }
630 635
636 return 0;
637
638out_free_queues:
639 nvme_rdma_free_io_queues(ctrl);
631 return ret; 640 return ret;
632} 641}
633 642
@@ -712,6 +721,8 @@ static void nvme_rdma_reconnect_ctrl_work(struct work_struct *work)
712 if (ret) 721 if (ret)
713 goto stop_admin_q; 722 goto stop_admin_q;
714 723
724 set_bit(NVME_RDMA_Q_LIVE, &ctrl->queues[0].flags);
725
715 ret = nvme_enable_ctrl(&ctrl->ctrl, ctrl->cap); 726 ret = nvme_enable_ctrl(&ctrl->ctrl, ctrl->cap);
716 if (ret) 727 if (ret)
717 goto stop_admin_q; 728 goto stop_admin_q;
@@ -761,8 +772,10 @@ static void nvme_rdma_error_recovery_work(struct work_struct *work)
761 772
762 nvme_stop_keep_alive(&ctrl->ctrl); 773 nvme_stop_keep_alive(&ctrl->ctrl);
763 774
764 for (i = 0; i < ctrl->queue_count; i++) 775 for (i = 0; i < ctrl->queue_count; i++) {
765 clear_bit(NVME_RDMA_Q_CONNECTED, &ctrl->queues[i].flags); 776 clear_bit(NVME_RDMA_Q_CONNECTED, &ctrl->queues[i].flags);
777 clear_bit(NVME_RDMA_Q_LIVE, &ctrl->queues[i].flags);
778 }
766 779
767 if (ctrl->queue_count > 1) 780 if (ctrl->queue_count > 1)
768 nvme_stop_queues(&ctrl->ctrl); 781 nvme_stop_queues(&ctrl->ctrl);
@@ -1378,6 +1391,24 @@ nvme_rdma_timeout(struct request *rq, bool reserved)
1378 return BLK_EH_HANDLED; 1391 return BLK_EH_HANDLED;
1379} 1392}
1380 1393
1394/*
1395 * We cannot accept any other command until the Connect command has completed.
1396 */
1397static inline bool nvme_rdma_queue_is_ready(struct nvme_rdma_queue *queue,
1398 struct request *rq)
1399{
1400 if (unlikely(!test_bit(NVME_RDMA_Q_LIVE, &queue->flags))) {
1401 struct nvme_command *cmd = (struct nvme_command *)rq->cmd;
1402
1403 if (rq->cmd_type != REQ_TYPE_DRV_PRIV ||
1404 cmd->common.opcode != nvme_fabrics_command ||
1405 cmd->fabrics.fctype != nvme_fabrics_type_connect)
1406 return false;
1407 }
1408
1409 return true;
1410}
1411
1381static int nvme_rdma_queue_rq(struct blk_mq_hw_ctx *hctx, 1412static int nvme_rdma_queue_rq(struct blk_mq_hw_ctx *hctx,
1382 const struct blk_mq_queue_data *bd) 1413 const struct blk_mq_queue_data *bd)
1383{ 1414{
@@ -1394,6 +1425,9 @@ static int nvme_rdma_queue_rq(struct blk_mq_hw_ctx *hctx,
1394 1425
1395 WARN_ON_ONCE(rq->tag < 0); 1426 WARN_ON_ONCE(rq->tag < 0);
1396 1427
1428 if (!nvme_rdma_queue_is_ready(queue, rq))
1429 return BLK_MQ_RQ_QUEUE_BUSY;
1430
1397 dev = queue->device->dev; 1431 dev = queue->device->dev;
1398 ib_dma_sync_single_for_cpu(dev, sqe->dma, 1432 ib_dma_sync_single_for_cpu(dev, sqe->dma,
1399 sizeof(struct nvme_command), DMA_TO_DEVICE); 1433 sizeof(struct nvme_command), DMA_TO_DEVICE);
@@ -1544,6 +1578,8 @@ static int nvme_rdma_configure_admin_queue(struct nvme_rdma_ctrl *ctrl)
1544 if (error) 1578 if (error)
1545 goto out_cleanup_queue; 1579 goto out_cleanup_queue;
1546 1580
1581 set_bit(NVME_RDMA_Q_LIVE, &ctrl->queues[0].flags);
1582
1547 error = nvmf_reg_read64(&ctrl->ctrl, NVME_REG_CAP, &ctrl->cap); 1583 error = nvmf_reg_read64(&ctrl->ctrl, NVME_REG_CAP, &ctrl->cap);
1548 if (error) { 1584 if (error) {
1549 dev_err(ctrl->ctrl.device, 1585 dev_err(ctrl->ctrl.device,
diff --git a/drivers/nvme/host/scsi.c b/drivers/nvme/host/scsi.c
index c2a0a1c7d05d..3eaa4d27801e 100644
--- a/drivers/nvme/host/scsi.c
+++ b/drivers/nvme/host/scsi.c
@@ -606,7 +606,7 @@ static int nvme_fill_device_id_eui64(struct nvme_ns *ns, struct sg_io_hdr *hdr,
606 eui = id_ns->eui64; 606 eui = id_ns->eui64;
607 len = sizeof(id_ns->eui64); 607 len = sizeof(id_ns->eui64);
608 608
609 if (ns->ctrl->vs >= NVME_VS(1, 2)) { 609 if (ns->ctrl->vs >= NVME_VS(1, 2, 0)) {
610 if (bitmap_empty(eui, len * 8)) { 610 if (bitmap_empty(eui, len * 8)) {
611 eui = id_ns->nguid; 611 eui = id_ns->nguid;
612 len = sizeof(id_ns->nguid); 612 len = sizeof(id_ns->nguid);
@@ -679,7 +679,7 @@ static int nvme_trans_device_id_page(struct nvme_ns *ns, struct sg_io_hdr *hdr,
679{ 679{
680 int res; 680 int res;
681 681
682 if (ns->ctrl->vs >= NVME_VS(1, 1)) { 682 if (ns->ctrl->vs >= NVME_VS(1, 1, 0)) {
683 res = nvme_fill_device_id_eui64(ns, hdr, resp, alloc_len); 683 res = nvme_fill_device_id_eui64(ns, hdr, resp, alloc_len);
684 if (res != -EOPNOTSUPP) 684 if (res != -EOPNOTSUPP)
685 return res; 685 return res;
diff --git a/drivers/nvme/target/admin-cmd.c b/drivers/nvme/target/admin-cmd.c
index 7ab9c9381b98..6fe4c48a21e4 100644
--- a/drivers/nvme/target/admin-cmd.c
+++ b/drivers/nvme/target/admin-cmd.c
@@ -199,7 +199,7 @@ static void nvmet_execute_identify_ctrl(struct nvmet_req *req)
199 */ 199 */
200 200
201 /* we support multiple ports and multiples hosts: */ 201 /* we support multiple ports and multiples hosts: */
202 id->mic = (1 << 0) | (1 << 1); 202 id->cmic = (1 << 0) | (1 << 1);
203 203
204 /* no limit on data transfer sizes for now */ 204 /* no limit on data transfer sizes for now */
205 id->mdts = 0; 205 id->mdts = 0;
@@ -511,13 +511,13 @@ int nvmet_parse_admin_cmd(struct nvmet_req *req)
511 case nvme_admin_identify: 511 case nvme_admin_identify:
512 req->data_len = 4096; 512 req->data_len = 4096;
513 switch (le32_to_cpu(cmd->identify.cns)) { 513 switch (le32_to_cpu(cmd->identify.cns)) {
514 case 0x00: 514 case NVME_ID_CNS_NS:
515 req->execute = nvmet_execute_identify_ns; 515 req->execute = nvmet_execute_identify_ns;
516 return 0; 516 return 0;
517 case 0x01: 517 case NVME_ID_CNS_CTRL:
518 req->execute = nvmet_execute_identify_ctrl; 518 req->execute = nvmet_execute_identify_ctrl;
519 return 0; 519 return 0;
520 case 0x02: 520 case NVME_ID_CNS_NS_ACTIVE_LIST:
521 req->execute = nvmet_execute_identify_nslist; 521 req->execute = nvmet_execute_identify_nslist;
522 return 0; 522 return 0;
523 } 523 }
diff --git a/drivers/nvme/target/core.c b/drivers/nvme/target/core.c
index 6559d5afa7bf..a21437a33adb 100644
--- a/drivers/nvme/target/core.c
+++ b/drivers/nvme/target/core.c
@@ -838,9 +838,13 @@ static void nvmet_fatal_error_handler(struct work_struct *work)
838 838
839void nvmet_ctrl_fatal_error(struct nvmet_ctrl *ctrl) 839void nvmet_ctrl_fatal_error(struct nvmet_ctrl *ctrl)
840{ 840{
841 ctrl->csts |= NVME_CSTS_CFS; 841 mutex_lock(&ctrl->lock);
842 INIT_WORK(&ctrl->fatal_err_work, nvmet_fatal_error_handler); 842 if (!(ctrl->csts & NVME_CSTS_CFS)) {
843 schedule_work(&ctrl->fatal_err_work); 843 ctrl->csts |= NVME_CSTS_CFS;
844 INIT_WORK(&ctrl->fatal_err_work, nvmet_fatal_error_handler);
845 schedule_work(&ctrl->fatal_err_work);
846 }
847 mutex_unlock(&ctrl->lock);
844} 848}
845EXPORT_SYMBOL_GPL(nvmet_ctrl_fatal_error); 849EXPORT_SYMBOL_GPL(nvmet_ctrl_fatal_error);
846 850
@@ -882,7 +886,7 @@ struct nvmet_subsys *nvmet_subsys_alloc(const char *subsysnqn,
882 if (!subsys) 886 if (!subsys)
883 return NULL; 887 return NULL;
884 888
885 subsys->ver = (1 << 16) | (2 << 8) | 1; /* NVMe 1.2.1 */ 889 subsys->ver = NVME_VS(1, 2, 1); /* NVMe 1.2.1 */
886 890
887 switch (type) { 891 switch (type) {
888 case NVME_NQN_NVME: 892 case NVME_NQN_NVME:
diff --git a/drivers/nvme/target/discovery.c b/drivers/nvme/target/discovery.c
index 6f65646e89cf..12f39eea569f 100644
--- a/drivers/nvme/target/discovery.c
+++ b/drivers/nvme/target/discovery.c
@@ -54,7 +54,7 @@ static void nvmet_format_discovery_entry(struct nvmf_disc_rsp_page_hdr *hdr,
54 /* we support only dynamic controllers */ 54 /* we support only dynamic controllers */
55 e->cntlid = cpu_to_le16(NVME_CNTLID_DYNAMIC); 55 e->cntlid = cpu_to_le16(NVME_CNTLID_DYNAMIC);
56 e->asqsz = cpu_to_le16(NVMF_AQ_DEPTH); 56 e->asqsz = cpu_to_le16(NVMF_AQ_DEPTH);
57 e->nqntype = type; 57 e->subtype = type;
58 memcpy(e->trsvcid, port->disc_addr.trsvcid, NVMF_TRSVCID_SIZE); 58 memcpy(e->trsvcid, port->disc_addr.trsvcid, NVMF_TRSVCID_SIZE);
59 memcpy(e->traddr, port->disc_addr.traddr, NVMF_TRADDR_SIZE); 59 memcpy(e->traddr, port->disc_addr.traddr, NVMF_TRADDR_SIZE);
60 memcpy(e->tsas.common, port->disc_addr.tsas.common, NVMF_TSAS_SIZE); 60 memcpy(e->tsas.common, port->disc_addr.tsas.common, NVMF_TSAS_SIZE);
@@ -187,7 +187,7 @@ int nvmet_parse_discovery_cmd(struct nvmet_req *req)
187 case nvme_admin_identify: 187 case nvme_admin_identify:
188 req->data_len = 4096; 188 req->data_len = 4096;
189 switch (le32_to_cpu(cmd->identify.cns)) { 189 switch (le32_to_cpu(cmd->identify.cns)) {
190 case 0x01: 190 case NVME_ID_CNS_CTRL:
191 req->execute = 191 req->execute =
192 nvmet_execute_identify_disc_ctrl; 192 nvmet_execute_identify_disc_ctrl;
193 return 0; 193 return 0;
diff --git a/drivers/nvme/target/rdma.c b/drivers/nvme/target/rdma.c
index f8d23999e0f2..005ef5d17a19 100644
--- a/drivers/nvme/target/rdma.c
+++ b/drivers/nvme/target/rdma.c
@@ -951,6 +951,7 @@ err_destroy_cq:
951 951
952static void nvmet_rdma_destroy_queue_ib(struct nvmet_rdma_queue *queue) 952static void nvmet_rdma_destroy_queue_ib(struct nvmet_rdma_queue *queue)
953{ 953{
954 ib_drain_qp(queue->cm_id->qp);
954 rdma_destroy_qp(queue->cm_id); 955 rdma_destroy_qp(queue->cm_id);
955 ib_free_cq(queue->cq); 956 ib_free_cq(queue->cq);
956} 957}
@@ -1066,6 +1067,7 @@ nvmet_rdma_alloc_queue(struct nvmet_rdma_device *ndev,
1066 spin_lock_init(&queue->rsp_wr_wait_lock); 1067 spin_lock_init(&queue->rsp_wr_wait_lock);
1067 INIT_LIST_HEAD(&queue->free_rsps); 1068 INIT_LIST_HEAD(&queue->free_rsps);
1068 spin_lock_init(&queue->rsps_lock); 1069 spin_lock_init(&queue->rsps_lock);
1070 INIT_LIST_HEAD(&queue->queue_list);
1069 1071
1070 queue->idx = ida_simple_get(&nvmet_rdma_queue_ida, 0, 0, GFP_KERNEL); 1072 queue->idx = ida_simple_get(&nvmet_rdma_queue_ida, 0, 0, GFP_KERNEL);
1071 if (queue->idx < 0) { 1073 if (queue->idx < 0) {
@@ -1244,7 +1246,6 @@ static void __nvmet_rdma_queue_disconnect(struct nvmet_rdma_queue *queue)
1244 1246
1245 if (disconnect) { 1247 if (disconnect) {
1246 rdma_disconnect(queue->cm_id); 1248 rdma_disconnect(queue->cm_id);
1247 ib_drain_qp(queue->cm_id->qp);
1248 schedule_work(&queue->release_work); 1249 schedule_work(&queue->release_work);
1249 } 1250 }
1250} 1251}
@@ -1269,7 +1270,12 @@ static void nvmet_rdma_queue_connect_fail(struct rdma_cm_id *cm_id,
1269{ 1270{
1270 WARN_ON_ONCE(queue->state != NVMET_RDMA_Q_CONNECTING); 1271 WARN_ON_ONCE(queue->state != NVMET_RDMA_Q_CONNECTING);
1271 1272
1272 pr_err("failed to connect queue\n"); 1273 mutex_lock(&nvmet_rdma_queue_mutex);
1274 if (!list_empty(&queue->queue_list))
1275 list_del_init(&queue->queue_list);
1276 mutex_unlock(&nvmet_rdma_queue_mutex);
1277
1278 pr_err("failed to connect queue %d\n", queue->idx);
1273 schedule_work(&queue->release_work); 1279 schedule_work(&queue->release_work);
1274} 1280}
1275 1281
@@ -1352,7 +1358,13 @@ static int nvmet_rdma_cm_handler(struct rdma_cm_id *cm_id,
1352 case RDMA_CM_EVENT_ADDR_CHANGE: 1358 case RDMA_CM_EVENT_ADDR_CHANGE:
1353 case RDMA_CM_EVENT_DISCONNECTED: 1359 case RDMA_CM_EVENT_DISCONNECTED:
1354 case RDMA_CM_EVENT_TIMEWAIT_EXIT: 1360 case RDMA_CM_EVENT_TIMEWAIT_EXIT:
1355 nvmet_rdma_queue_disconnect(queue); 1361 /*
1362 * We might end up here when we already freed the qp
1363 * which means queue release sequence is in progress,
1364 * so don't get in the way...
1365 */
1366 if (queue)
1367 nvmet_rdma_queue_disconnect(queue);
1356 break; 1368 break;
1357 case RDMA_CM_EVENT_DEVICE_REMOVAL: 1369 case RDMA_CM_EVENT_DEVICE_REMOVAL:
1358 ret = nvmet_rdma_device_removal(cm_id, queue); 1370 ret = nvmet_rdma_device_removal(cm_id, queue);
diff --git a/drivers/of/base.c b/drivers/of/base.c
index d687e6de24a0..a0bccb54a9bd 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -2077,8 +2077,6 @@ void of_alias_scan(void * (*dt_alloc)(u64 size, u64 align))
2077 name = of_get_property(of_aliases, "stdout", NULL); 2077 name = of_get_property(of_aliases, "stdout", NULL);
2078 if (name) 2078 if (name)
2079 of_stdout = of_find_node_opts_by_path(name, &of_stdout_options); 2079 of_stdout = of_find_node_opts_by_path(name, &of_stdout_options);
2080 if (of_stdout)
2081 console_set_by_of();
2082 } 2080 }
2083 2081
2084 if (!of_aliases) 2082 if (!of_aliases)
diff --git a/drivers/of/of_mdio.c b/drivers/of/of_mdio.c
index b470f7e3521d..262281bd68fa 100644
--- a/drivers/of/of_mdio.c
+++ b/drivers/of/of_mdio.c
@@ -292,6 +292,7 @@ struct phy_device *of_phy_find_device(struct device_node *phy_np)
292 mdiodev = to_mdio_device(d); 292 mdiodev = to_mdio_device(d);
293 if (mdiodev->flags & MDIO_DEVICE_FLAG_PHY) 293 if (mdiodev->flags & MDIO_DEVICE_FLAG_PHY)
294 return to_phy_device(d); 294 return to_phy_device(d);
295 put_device(d);
295 } 296 }
296 297
297 return NULL; 298 return NULL;
@@ -456,8 +457,11 @@ int of_phy_register_fixed_link(struct device_node *np)
456 status.link = 1; 457 status.link = 1;
457 status.duplex = of_property_read_bool(fixed_link_node, 458 status.duplex = of_property_read_bool(fixed_link_node,
458 "full-duplex"); 459 "full-duplex");
459 if (of_property_read_u32(fixed_link_node, "speed", &status.speed)) 460 if (of_property_read_u32(fixed_link_node, "speed",
461 &status.speed)) {
462 of_node_put(fixed_link_node);
460 return -EINVAL; 463 return -EINVAL;
464 }
461 status.pause = of_property_read_bool(fixed_link_node, "pause"); 465 status.pause = of_property_read_bool(fixed_link_node, "pause");
462 status.asym_pause = of_property_read_bool(fixed_link_node, 466 status.asym_pause = of_property_read_bool(fixed_link_node,
463 "asym-pause"); 467 "asym-pause");
@@ -486,3 +490,18 @@ int of_phy_register_fixed_link(struct device_node *np)
486 return -ENODEV; 490 return -ENODEV;
487} 491}
488EXPORT_SYMBOL(of_phy_register_fixed_link); 492EXPORT_SYMBOL(of_phy_register_fixed_link);
493
494void of_phy_deregister_fixed_link(struct device_node *np)
495{
496 struct phy_device *phydev;
497
498 phydev = of_phy_find_device(np);
499 if (!phydev)
500 return;
501
502 fixed_phy_unregister(phydev);
503
504 put_device(&phydev->mdio.dev); /* of_phy_find_device() */
505 phy_device_free(phydev); /* fixed_phy_register() */
506}
507EXPORT_SYMBOL(of_phy_deregister_fixed_link);
diff --git a/drivers/pci/host/pci-layerscape.c b/drivers/pci/host/pci-layerscape.c
index 2cb7315e26d0..653707996342 100644
--- a/drivers/pci/host/pci-layerscape.c
+++ b/drivers/pci/host/pci-layerscape.c
@@ -247,6 +247,7 @@ static int __init ls_pcie_probe(struct platform_device *pdev)
247 247
248 pp = &pcie->pp; 248 pp = &pcie->pp;
249 pp->dev = dev; 249 pp->dev = dev;
250 pcie->drvdata = match->data;
250 pp->ops = pcie->drvdata->ops; 251 pp->ops = pcie->drvdata->ops;
251 252
252 dbi_base = platform_get_resource_byname(pdev, IORESOURCE_MEM, "regs"); 253 dbi_base = platform_get_resource_byname(pdev, IORESOURCE_MEM, "regs");
@@ -256,7 +257,6 @@ static int __init ls_pcie_probe(struct platform_device *pdev)
256 return PTR_ERR(pcie->pp.dbi_base); 257 return PTR_ERR(pcie->pp.dbi_base);
257 } 258 }
258 259
259 pcie->drvdata = match->data;
260 pcie->lut = pcie->pp.dbi_base + pcie->drvdata->lut_offset; 260 pcie->lut = pcie->pp.dbi_base + pcie->drvdata->lut_offset;
261 261
262 if (!ls_pcie_is_bridge(pcie)) 262 if (!ls_pcie_is_bridge(pcie))
diff --git a/drivers/pci/host/pcie-designware-plat.c b/drivers/pci/host/pcie-designware-plat.c
index 537f58a664fa..1a02038c4640 100644
--- a/drivers/pci/host/pcie-designware-plat.c
+++ b/drivers/pci/host/pcie-designware-plat.c
@@ -3,7 +3,7 @@
3 * 3 *
4 * Copyright (C) 2015-2016 Synopsys, Inc. (www.synopsys.com) 4 * Copyright (C) 2015-2016 Synopsys, Inc. (www.synopsys.com)
5 * 5 *
6 * Authors: Joao Pinto <jpinto@synopsys.com> 6 * Authors: Joao Pinto <Joao.Pinto@synopsys.com>
7 * 7 *
8 * This program is free software; you can redistribute it and/or modify 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 9 * it under the terms of the GNU General Public License version 2 as
diff --git a/drivers/pci/host/pcie-designware.c b/drivers/pci/host/pcie-designware.c
index 035f50c03281..bed19994c1e9 100644
--- a/drivers/pci/host/pcie-designware.c
+++ b/drivers/pci/host/pcie-designware.c
@@ -637,8 +637,6 @@ int dw_pcie_host_init(struct pcie_port *pp)
637 } 637 }
638 } 638 }
639 639
640 pp->iatu_unroll_enabled = dw_pcie_iatu_unroll_enabled(pp);
641
642 if (pp->ops->host_init) 640 if (pp->ops->host_init)
643 pp->ops->host_init(pp); 641 pp->ops->host_init(pp);
644 642
@@ -809,6 +807,11 @@ void dw_pcie_setup_rc(struct pcie_port *pp)
809{ 807{
810 u32 val; 808 u32 val;
811 809
810 /* get iATU unroll support */
811 pp->iatu_unroll_enabled = dw_pcie_iatu_unroll_enabled(pp);
812 dev_dbg(pp->dev, "iATU unroll: %s\n",
813 pp->iatu_unroll_enabled ? "enabled" : "disabled");
814
812 /* set the number of lanes */ 815 /* set the number of lanes */
813 val = dw_pcie_readl_rc(pp, PCIE_PORT_LINK_CONTROL); 816 val = dw_pcie_readl_rc(pp, PCIE_PORT_LINK_CONTROL);
814 val &= ~PORT_LINK_MODE_MASK; 817 val &= ~PORT_LINK_MODE_MASK;
diff --git a/drivers/pci/host/pcie-qcom.c b/drivers/pci/host/pcie-qcom.c
index ef0a84c7a588..35936409b2d4 100644
--- a/drivers/pci/host/pcie-qcom.c
+++ b/drivers/pci/host/pcie-qcom.c
@@ -533,11 +533,11 @@ static int qcom_pcie_probe(struct platform_device *pdev)
533 if (IS_ERR(pcie->phy)) 533 if (IS_ERR(pcie->phy))
534 return PTR_ERR(pcie->phy); 534 return PTR_ERR(pcie->phy);
535 535
536 pp->dev = dev;
536 ret = pcie->ops->get_resources(pcie); 537 ret = pcie->ops->get_resources(pcie);
537 if (ret) 538 if (ret)
538 return ret; 539 return ret;
539 540
540 pp->dev = dev;
541 pp->root_bus_nr = -1; 541 pp->root_bus_nr = -1;
542 pp->ops = &qcom_pcie_dw_ops; 542 pp->ops = &qcom_pcie_dw_ops;
543 543
diff --git a/drivers/pci/host/pcie-rockchip.c b/drivers/pci/host/pcie-rockchip.c
index e0b22dab9b7a..e04f69beb42d 100644
--- a/drivers/pci/host/pcie-rockchip.c
+++ b/drivers/pci/host/pcie-rockchip.c
@@ -190,6 +190,9 @@ struct rockchip_pcie {
190 struct reset_control *mgmt_rst; 190 struct reset_control *mgmt_rst;
191 struct reset_control *mgmt_sticky_rst; 191 struct reset_control *mgmt_sticky_rst;
192 struct reset_control *pipe_rst; 192 struct reset_control *pipe_rst;
193 struct reset_control *pm_rst;
194 struct reset_control *aclk_rst;
195 struct reset_control *pclk_rst;
193 struct clk *aclk_pcie; 196 struct clk *aclk_pcie;
194 struct clk *aclk_perf_pcie; 197 struct clk *aclk_perf_pcie;
195 struct clk *hclk_pcie; 198 struct clk *hclk_pcie;
@@ -408,6 +411,44 @@ static int rockchip_pcie_init_port(struct rockchip_pcie *rockchip)
408 411
409 gpiod_set_value(rockchip->ep_gpio, 0); 412 gpiod_set_value(rockchip->ep_gpio, 0);
410 413
414 err = reset_control_assert(rockchip->aclk_rst);
415 if (err) {
416 dev_err(dev, "assert aclk_rst err %d\n", err);
417 return err;
418 }
419
420 err = reset_control_assert(rockchip->pclk_rst);
421 if (err) {
422 dev_err(dev, "assert pclk_rst err %d\n", err);
423 return err;
424 }
425
426 err = reset_control_assert(rockchip->pm_rst);
427 if (err) {
428 dev_err(dev, "assert pm_rst err %d\n", err);
429 return err;
430 }
431
432 udelay(10);
433
434 err = reset_control_deassert(rockchip->pm_rst);
435 if (err) {
436 dev_err(dev, "deassert pm_rst err %d\n", err);
437 return err;
438 }
439
440 err = reset_control_deassert(rockchip->aclk_rst);
441 if (err) {
442 dev_err(dev, "deassert mgmt_sticky_rst err %d\n", err);
443 return err;
444 }
445
446 err = reset_control_deassert(rockchip->pclk_rst);
447 if (err) {
448 dev_err(dev, "deassert mgmt_sticky_rst err %d\n", err);
449 return err;
450 }
451
411 err = phy_init(rockchip->phy); 452 err = phy_init(rockchip->phy);
412 if (err < 0) { 453 if (err < 0) {
413 dev_err(dev, "fail to init phy, err %d\n", err); 454 dev_err(dev, "fail to init phy, err %d\n", err);
@@ -781,6 +822,27 @@ static int rockchip_pcie_parse_dt(struct rockchip_pcie *rockchip)
781 return PTR_ERR(rockchip->pipe_rst); 822 return PTR_ERR(rockchip->pipe_rst);
782 } 823 }
783 824
825 rockchip->pm_rst = devm_reset_control_get(dev, "pm");
826 if (IS_ERR(rockchip->pm_rst)) {
827 if (PTR_ERR(rockchip->pm_rst) != -EPROBE_DEFER)
828 dev_err(dev, "missing pm reset property in node\n");
829 return PTR_ERR(rockchip->pm_rst);
830 }
831
832 rockchip->pclk_rst = devm_reset_control_get(dev, "pclk");
833 if (IS_ERR(rockchip->pclk_rst)) {
834 if (PTR_ERR(rockchip->pclk_rst) != -EPROBE_DEFER)
835 dev_err(dev, "missing pclk reset property in node\n");
836 return PTR_ERR(rockchip->pclk_rst);
837 }
838
839 rockchip->aclk_rst = devm_reset_control_get(dev, "aclk");
840 if (IS_ERR(rockchip->aclk_rst)) {
841 if (PTR_ERR(rockchip->aclk_rst) != -EPROBE_DEFER)
842 dev_err(dev, "missing aclk reset property in node\n");
843 return PTR_ERR(rockchip->aclk_rst);
844 }
845
784 rockchip->ep_gpio = devm_gpiod_get(dev, "ep", GPIOD_OUT_HIGH); 846 rockchip->ep_gpio = devm_gpiod_get(dev, "ep", GPIOD_OUT_HIGH);
785 if (IS_ERR(rockchip->ep_gpio)) { 847 if (IS_ERR(rockchip->ep_gpio)) {
786 dev_err(dev, "missing ep-gpios property in node\n"); 848 dev_err(dev, "missing ep-gpios property in node\n");
diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
index bfdd0744b686..ad70507cfb56 100644
--- a/drivers/pci/msi.c
+++ b/drivers/pci/msi.c
@@ -610,6 +610,7 @@ static int msi_verify_entries(struct pci_dev *dev)
610 * msi_capability_init - configure device's MSI capability structure 610 * msi_capability_init - configure device's MSI capability structure
611 * @dev: pointer to the pci_dev data structure of MSI device function 611 * @dev: pointer to the pci_dev data structure of MSI device function
612 * @nvec: number of interrupts to allocate 612 * @nvec: number of interrupts to allocate
613 * @affinity: flag to indicate cpu irq affinity mask should be set
613 * 614 *
614 * Setup the MSI capability structure of the device with the requested 615 * Setup the MSI capability structure of the device with the requested
615 * number of interrupts. A return value of zero indicates the successful 616 * number of interrupts. A return value of zero indicates the successful
@@ -752,6 +753,7 @@ static void msix_program_entries(struct pci_dev *dev,
752 * @dev: pointer to the pci_dev data structure of MSI-X device function 753 * @dev: pointer to the pci_dev data structure of MSI-X device function
753 * @entries: pointer to an array of struct msix_entry entries 754 * @entries: pointer to an array of struct msix_entry entries
754 * @nvec: number of @entries 755 * @nvec: number of @entries
756 * @affinity: flag to indicate cpu irq affinity mask should be set
755 * 757 *
756 * Setup the MSI-X capability structure of device function with a 758 * Setup the MSI-X capability structure of device function with a
757 * single MSI-X irq. A return of zero indicates the successful setup of 759 * single MSI-X irq. A return of zero indicates the successful setup of
diff --git a/drivers/pci/pci-mid.c b/drivers/pci/pci-mid.c
index 55f453de562e..c7f3408e3148 100644
--- a/drivers/pci/pci-mid.c
+++ b/drivers/pci/pci-mid.c
@@ -29,6 +29,11 @@ static int mid_pci_set_power_state(struct pci_dev *pdev, pci_power_t state)
29 return intel_mid_pci_set_power_state(pdev, state); 29 return intel_mid_pci_set_power_state(pdev, state);
30} 30}
31 31
32static pci_power_t mid_pci_get_power_state(struct pci_dev *pdev)
33{
34 return intel_mid_pci_get_power_state(pdev);
35}
36
32static pci_power_t mid_pci_choose_state(struct pci_dev *pdev) 37static pci_power_t mid_pci_choose_state(struct pci_dev *pdev)
33{ 38{
34 return PCI_D3hot; 39 return PCI_D3hot;
@@ -52,6 +57,7 @@ static bool mid_pci_need_resume(struct pci_dev *dev)
52static struct pci_platform_pm_ops mid_pci_platform_pm = { 57static struct pci_platform_pm_ops mid_pci_platform_pm = {
53 .is_manageable = mid_pci_power_manageable, 58 .is_manageable = mid_pci_power_manageable,
54 .set_state = mid_pci_set_power_state, 59 .set_state = mid_pci_set_power_state,
60 .get_state = mid_pci_get_power_state,
55 .choose_state = mid_pci_choose_state, 61 .choose_state = mid_pci_choose_state,
56 .sleep_wake = mid_pci_sleep_wake, 62 .sleep_wake = mid_pci_sleep_wake,
57 .run_wake = mid_pci_run_wake, 63 .run_wake = mid_pci_run_wake,
diff --git a/drivers/pci/pcie/aer/aer_inject.c b/drivers/pci/pcie/aer/aer_inject.c
index db553dc22c8e..2b6a59266689 100644
--- a/drivers/pci/pcie/aer/aer_inject.c
+++ b/drivers/pci/pcie/aer/aer_inject.c
@@ -307,20 +307,6 @@ out:
307 return 0; 307 return 0;
308} 308}
309 309
310static struct pci_dev *pcie_find_root_port(struct pci_dev *dev)
311{
312 while (1) {
313 if (!pci_is_pcie(dev))
314 break;
315 if (pci_pcie_type(dev) == PCI_EXP_TYPE_ROOT_PORT)
316 return dev;
317 if (!dev->bus->self)
318 break;
319 dev = dev->bus->self;
320 }
321 return NULL;
322}
323
324static int find_aer_device_iter(struct device *device, void *data) 310static int find_aer_device_iter(struct device *device, void *data)
325{ 311{
326 struct pcie_device **result = data; 312 struct pcie_device **result = data;
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index ab002671fa60..104c46d53121 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -1439,6 +1439,21 @@ static void program_hpp_type1(struct pci_dev *dev, struct hpp_type1 *hpp)
1439 dev_warn(&dev->dev, "PCI-X settings not supported\n"); 1439 dev_warn(&dev->dev, "PCI-X settings not supported\n");
1440} 1440}
1441 1441
1442static bool pcie_root_rcb_set(struct pci_dev *dev)
1443{
1444 struct pci_dev *rp = pcie_find_root_port(dev);
1445 u16 lnkctl;
1446
1447 if (!rp)
1448 return false;
1449
1450 pcie_capability_read_word(rp, PCI_EXP_LNKCTL, &lnkctl);
1451 if (lnkctl & PCI_EXP_LNKCTL_RCB)
1452 return true;
1453
1454 return false;
1455}
1456
1442static void program_hpp_type2(struct pci_dev *dev, struct hpp_type2 *hpp) 1457static void program_hpp_type2(struct pci_dev *dev, struct hpp_type2 *hpp)
1443{ 1458{
1444 int pos; 1459 int pos;
@@ -1468,9 +1483,20 @@ static void program_hpp_type2(struct pci_dev *dev, struct hpp_type2 *hpp)
1468 ~hpp->pci_exp_devctl_and, hpp->pci_exp_devctl_or); 1483 ~hpp->pci_exp_devctl_and, hpp->pci_exp_devctl_or);
1469 1484
1470 /* Initialize Link Control Register */ 1485 /* Initialize Link Control Register */
1471 if (pcie_cap_has_lnkctl(dev)) 1486 if (pcie_cap_has_lnkctl(dev)) {
1487
1488 /*
1489 * If the Root Port supports Read Completion Boundary of
1490 * 128, set RCB to 128. Otherwise, clear it.
1491 */
1492 hpp->pci_exp_lnkctl_and |= PCI_EXP_LNKCTL_RCB;
1493 hpp->pci_exp_lnkctl_or &= ~PCI_EXP_LNKCTL_RCB;
1494 if (pcie_root_rcb_set(dev))
1495 hpp->pci_exp_lnkctl_or |= PCI_EXP_LNKCTL_RCB;
1496
1472 pcie_capability_clear_and_set_word(dev, PCI_EXP_LNKCTL, 1497 pcie_capability_clear_and_set_word(dev, PCI_EXP_LNKCTL,
1473 ~hpp->pci_exp_lnkctl_and, hpp->pci_exp_lnkctl_or); 1498 ~hpp->pci_exp_lnkctl_and, hpp->pci_exp_lnkctl_or);
1499 }
1474 1500
1475 /* Find Advanced Error Reporting Enhanced Capability */ 1501 /* Find Advanced Error Reporting Enhanced Capability */
1476 pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ERR); 1502 pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ERR);
diff --git a/drivers/pci/setup-res.c b/drivers/pci/setup-res.c
index 66c4d8f42233..9526e341988b 100644
--- a/drivers/pci/setup-res.c
+++ b/drivers/pci/setup-res.c
@@ -121,6 +121,14 @@ int pci_claim_resource(struct pci_dev *dev, int resource)
121 return -EINVAL; 121 return -EINVAL;
122 } 122 }
123 123
124 /*
125 * If we have a shadow copy in RAM, the PCI device doesn't respond
126 * to the shadow range, so we don't need to claim it, and upstream
127 * bridges don't need to route the range to the device.
128 */
129 if (res->flags & IORESOURCE_ROM_SHADOW)
130 return 0;
131
124 root = pci_find_parent_resource(dev, res); 132 root = pci_find_parent_resource(dev, res);
125 if (!root) { 133 if (!root) {
126 dev_info(&dev->dev, "can't claim BAR %d %pR: no compatible bridge window\n", 134 dev_info(&dev->dev, "can't claim BAR %d %pR: no compatible bridge window\n",
diff --git a/drivers/pcmcia/soc_common.c b/drivers/pcmcia/soc_common.c
index 153f3122283d..b6b316de055c 100644
--- a/drivers/pcmcia/soc_common.c
+++ b/drivers/pcmcia/soc_common.c
@@ -107,7 +107,7 @@ int soc_pcmcia_regulator_set(struct soc_pcmcia_socket *skt,
107 107
108 ret = regulator_enable(r->reg); 108 ret = regulator_enable(r->reg);
109 } else { 109 } else {
110 regulator_disable(r->reg); 110 ret = regulator_disable(r->reg);
111 } 111 }
112 if (ret == 0) 112 if (ret == 0)
113 r->on = on; 113 r->on = on;
diff --git a/drivers/perf/xgene_pmu.c b/drivers/perf/xgene_pmu.c
index c2ac7646b99f..a8ac4bcef2c0 100644
--- a/drivers/perf/xgene_pmu.c
+++ b/drivers/perf/xgene_pmu.c
@@ -1011,7 +1011,7 @@ xgene_pmu_dev_ctx *acpi_get_pmu_hw_inf(struct xgene_pmu *xgene_pmu,
1011 rc = acpi_dev_get_resources(adev, &resource_list, 1011 rc = acpi_dev_get_resources(adev, &resource_list,
1012 acpi_pmu_dev_add_resource, &res); 1012 acpi_pmu_dev_add_resource, &res);
1013 acpi_dev_free_resource_list(&resource_list); 1013 acpi_dev_free_resource_list(&resource_list);
1014 if (rc < 0 || IS_ERR(&res)) { 1014 if (rc < 0) {
1015 dev_err(dev, "PMU type %d: No resource address found\n", type); 1015 dev_err(dev, "PMU type %d: No resource address found\n", type);
1016 goto err; 1016 goto err;
1017 } 1017 }
diff --git a/drivers/phy/phy-da8xx-usb.c b/drivers/phy/phy-da8xx-usb.c
index 32ae78c8ca17..c85fb0b59729 100644
--- a/drivers/phy/phy-da8xx-usb.c
+++ b/drivers/phy/phy-da8xx-usb.c
@@ -198,7 +198,8 @@ static int da8xx_usb_phy_probe(struct platform_device *pdev)
198 } else { 198 } else {
199 int ret; 199 int ret;
200 200
201 ret = phy_create_lookup(d_phy->usb11_phy, "usb-phy", "ohci.0"); 201 ret = phy_create_lookup(d_phy->usb11_phy, "usb-phy",
202 "ohci-da8xx");
202 if (ret) 203 if (ret)
203 dev_warn(dev, "Failed to create usb11 phy lookup\n"); 204 dev_warn(dev, "Failed to create usb11 phy lookup\n");
204 ret = phy_create_lookup(d_phy->usb20_phy, "usb-phy", 205 ret = phy_create_lookup(d_phy->usb20_phy, "usb-phy",
@@ -216,7 +217,7 @@ static int da8xx_usb_phy_remove(struct platform_device *pdev)
216 217
217 if (!pdev->dev.of_node) { 218 if (!pdev->dev.of_node) {
218 phy_remove_lookup(d_phy->usb20_phy, "usb-phy", "musb-da8xx"); 219 phy_remove_lookup(d_phy->usb20_phy, "usb-phy", "musb-da8xx");
219 phy_remove_lookup(d_phy->usb11_phy, "usb-phy", "ohci.0"); 220 phy_remove_lookup(d_phy->usb11_phy, "usb-phy", "ohci-da8xx");
220 } 221 }
221 222
222 return 0; 223 return 0;
diff --git a/drivers/phy/phy-rockchip-pcie.c b/drivers/phy/phy-rockchip-pcie.c
index a2b4c6b58aea..6904633cad68 100644
--- a/drivers/phy/phy-rockchip-pcie.c
+++ b/drivers/phy/phy-rockchip-pcie.c
@@ -249,21 +249,10 @@ err_refclk:
249static int rockchip_pcie_phy_exit(struct phy *phy) 249static int rockchip_pcie_phy_exit(struct phy *phy)
250{ 250{
251 struct rockchip_pcie_phy *rk_phy = phy_get_drvdata(phy); 251 struct rockchip_pcie_phy *rk_phy = phy_get_drvdata(phy);
252 int err = 0;
253 252
254 clk_disable_unprepare(rk_phy->clk_pciephy_ref); 253 clk_disable_unprepare(rk_phy->clk_pciephy_ref);
255 254
256 err = reset_control_deassert(rk_phy->phy_rst); 255 return 0;
257 if (err) {
258 dev_err(&phy->dev, "deassert phy_rst err %d\n", err);
259 goto err_reset;
260 }
261
262 return err;
263
264err_reset:
265 clk_prepare_enable(rk_phy->clk_pciephy_ref);
266 return err;
267} 256}
268 257
269static const struct phy_ops ops = { 258static const struct phy_ops ops = {
diff --git a/drivers/phy/phy-sun4i-usb.c b/drivers/phy/phy-sun4i-usb.c
index b9342a2af7b3..fec34f5213c4 100644
--- a/drivers/phy/phy-sun4i-usb.c
+++ b/drivers/phy/phy-sun4i-usb.c
@@ -264,7 +264,7 @@ static int sun4i_usb_phy_init(struct phy *_phy)
264 return ret; 264 return ret;
265 } 265 }
266 266
267 if (data->cfg->enable_pmu_unk1) { 267 if (phy->pmu && data->cfg->enable_pmu_unk1) {
268 val = readl(phy->pmu + REG_PMU_UNK1); 268 val = readl(phy->pmu + REG_PMU_UNK1);
269 writel(val & ~2, phy->pmu + REG_PMU_UNK1); 269 writel(val & ~2, phy->pmu + REG_PMU_UNK1);
270 } 270 }
diff --git a/drivers/phy/phy-twl4030-usb.c b/drivers/phy/phy-twl4030-usb.c
index 87e6334eab93..547ca7b3f098 100644
--- a/drivers/phy/phy-twl4030-usb.c
+++ b/drivers/phy/phy-twl4030-usb.c
@@ -459,8 +459,6 @@ static int twl4030_phy_power_off(struct phy *phy)
459 struct twl4030_usb *twl = phy_get_drvdata(phy); 459 struct twl4030_usb *twl = phy_get_drvdata(phy);
460 460
461 dev_dbg(twl->dev, "%s\n", __func__); 461 dev_dbg(twl->dev, "%s\n", __func__);
462 pm_runtime_mark_last_busy(twl->dev);
463 pm_runtime_put_autosuspend(twl->dev);
464 462
465 return 0; 463 return 0;
466} 464}
@@ -472,6 +470,8 @@ static int twl4030_phy_power_on(struct phy *phy)
472 dev_dbg(twl->dev, "%s\n", __func__); 470 dev_dbg(twl->dev, "%s\n", __func__);
473 pm_runtime_get_sync(twl->dev); 471 pm_runtime_get_sync(twl->dev);
474 schedule_delayed_work(&twl->id_workaround_work, HZ); 472 schedule_delayed_work(&twl->id_workaround_work, HZ);
473 pm_runtime_mark_last_busy(twl->dev);
474 pm_runtime_put_autosuspend(twl->dev);
475 475
476 return 0; 476 return 0;
477} 477}
diff --git a/drivers/pinctrl/aspeed/pinctrl-aspeed-g5.c b/drivers/pinctrl/aspeed/pinctrl-aspeed-g5.c
index e1ab864e1a7f..87b46390b695 100644
--- a/drivers/pinctrl/aspeed/pinctrl-aspeed-g5.c
+++ b/drivers/pinctrl/aspeed/pinctrl-aspeed-g5.c
@@ -26,7 +26,7 @@
26 26
27#define ASPEED_G5_NR_PINS 228 27#define ASPEED_G5_NR_PINS 228
28 28
29#define COND1 SIG_DESC_BIT(SCU90, 6, 0) 29#define COND1 { SCU90, BIT(6), 0, 0 }
30#define COND2 { SCU94, GENMASK(1, 0), 0, 0 } 30#define COND2 { SCU94, GENMASK(1, 0), 0, 0 }
31 31
32#define B14 0 32#define B14 0
@@ -151,21 +151,21 @@ FUNC_GROUP_DECL(GPID0, F19, E21);
151 151
152#define GPID2_DESC SIG_DESC_SET(SCU8C, 9) 152#define GPID2_DESC SIG_DESC_SET(SCU8C, 9)
153 153
154#define D20 26 154#define F20 26
155SIG_EXPR_LIST_DECL_SINGLE(SD2DAT0, SD2, SD2_DESC); 155SIG_EXPR_LIST_DECL_SINGLE(SD2DAT0, SD2, SD2_DESC);
156SIG_EXPR_DECL(GPID2IN, GPID2, GPID2_DESC); 156SIG_EXPR_DECL(GPID2IN, GPID2, GPID2_DESC);
157SIG_EXPR_DECL(GPID2IN, GPID, GPID_DESC); 157SIG_EXPR_DECL(GPID2IN, GPID, GPID_DESC);
158SIG_EXPR_LIST_DECL_DUAL(GPID2IN, GPID2, GPID); 158SIG_EXPR_LIST_DECL_DUAL(GPID2IN, GPID2, GPID);
159MS_PIN_DECL(D20, GPIOD2, SD2DAT0, GPID2IN); 159MS_PIN_DECL(F20, GPIOD2, SD2DAT0, GPID2IN);
160 160
161#define D21 27 161#define D20 27
162SIG_EXPR_LIST_DECL_SINGLE(SD2DAT1, SD2, SD2_DESC); 162SIG_EXPR_LIST_DECL_SINGLE(SD2DAT1, SD2, SD2_DESC);
163SIG_EXPR_DECL(GPID2OUT, GPID2, GPID2_DESC); 163SIG_EXPR_DECL(GPID2OUT, GPID2, GPID2_DESC);
164SIG_EXPR_DECL(GPID2OUT, GPID, GPID_DESC); 164SIG_EXPR_DECL(GPID2OUT, GPID, GPID_DESC);
165SIG_EXPR_LIST_DECL_DUAL(GPID2OUT, GPID2, GPID); 165SIG_EXPR_LIST_DECL_DUAL(GPID2OUT, GPID2, GPID);
166MS_PIN_DECL(D21, GPIOD3, SD2DAT1, GPID2OUT); 166MS_PIN_DECL(D20, GPIOD3, SD2DAT1, GPID2OUT);
167 167
168FUNC_GROUP_DECL(GPID2, D20, D21); 168FUNC_GROUP_DECL(GPID2, F20, D20);
169 169
170#define GPIE_DESC SIG_DESC_SET(HW_STRAP1, 21) 170#define GPIE_DESC SIG_DESC_SET(HW_STRAP1, 21)
171#define GPIE0_DESC SIG_DESC_SET(SCU8C, 12) 171#define GPIE0_DESC SIG_DESC_SET(SCU8C, 12)
@@ -182,28 +182,88 @@ SIG_EXPR_LIST_DECL_SINGLE(NDCD3, NDCD3, SIG_DESC_SET(SCU80, 17));
182SIG_EXPR_DECL(GPIE0OUT, GPIE0, GPIE0_DESC); 182SIG_EXPR_DECL(GPIE0OUT, GPIE0, GPIE0_DESC);
183SIG_EXPR_DECL(GPIE0OUT, GPIE, GPIE_DESC); 183SIG_EXPR_DECL(GPIE0OUT, GPIE, GPIE_DESC);
184SIG_EXPR_LIST_DECL_DUAL(GPIE0OUT, GPIE0, GPIE); 184SIG_EXPR_LIST_DECL_DUAL(GPIE0OUT, GPIE0, GPIE);
185MS_PIN_DECL(C20, GPIE0, NDCD3, GPIE0OUT); 185MS_PIN_DECL(C20, GPIOE1, NDCD3, GPIE0OUT);
186 186
187FUNC_GROUP_DECL(GPIE0, B20, C20); 187FUNC_GROUP_DECL(GPIE0, B20, C20);
188 188
189#define SPI1_DESC SIG_DESC_SET(HW_STRAP1, 13) 189#define SPI1_DESC { HW_STRAP1, GENMASK(13, 12), 1, 0 }
190#define SPI1DEBUG_DESC { HW_STRAP1, GENMASK(13, 12), 2, 0 }
191#define SPI1PASSTHRU_DESC { HW_STRAP1, GENMASK(13, 12), 3, 0 }
192
190#define C18 64 193#define C18 64
191SIG_EXPR_LIST_DECL_SINGLE(SYSCS, SPI1, COND1, SPI1_DESC); 194SIG_EXPR_DECL(SYSCS, SPI1DEBUG, COND1, SPI1DEBUG_DESC);
195SIG_EXPR_DECL(SYSCS, SPI1PASSTHRU, COND1, SPI1PASSTHRU_DESC);
196SIG_EXPR_LIST_DECL_DUAL(SYSCS, SPI1DEBUG, SPI1PASSTHRU);
192SS_PIN_DECL(C18, GPIOI0, SYSCS); 197SS_PIN_DECL(C18, GPIOI0, SYSCS);
193 198
194#define E15 65 199#define E15 65
195SIG_EXPR_LIST_DECL_SINGLE(SYSCK, SPI1, COND1, SPI1_DESC); 200SIG_EXPR_DECL(SYSCK, SPI1DEBUG, COND1, SPI1DEBUG_DESC);
201SIG_EXPR_DECL(SYSCK, SPI1PASSTHRU, COND1, SPI1PASSTHRU_DESC);
202SIG_EXPR_LIST_DECL_DUAL(SYSCK, SPI1DEBUG, SPI1PASSTHRU);
196SS_PIN_DECL(E15, GPIOI1, SYSCK); 203SS_PIN_DECL(E15, GPIOI1, SYSCK);
197 204
198#define A14 66 205#define B16 66
199SIG_EXPR_LIST_DECL_SINGLE(SYSMOSI, SPI1, COND1, SPI1_DESC); 206SIG_EXPR_DECL(SYSMOSI, SPI1DEBUG, COND1, SPI1DEBUG_DESC);
200SS_PIN_DECL(A14, GPIOI2, SYSMOSI); 207SIG_EXPR_DECL(SYSMOSI, SPI1PASSTHRU, COND1, SPI1PASSTHRU_DESC);
208SIG_EXPR_LIST_DECL_DUAL(SYSMOSI, SPI1DEBUG, SPI1PASSTHRU);
209SS_PIN_DECL(B16, GPIOI2, SYSMOSI);
201 210
202#define C16 67 211#define C16 67
203SIG_EXPR_LIST_DECL_SINGLE(SYSMISO, SPI1, COND1, SPI1_DESC); 212SIG_EXPR_DECL(SYSMISO, SPI1DEBUG, COND1, SPI1DEBUG_DESC);
213SIG_EXPR_DECL(SYSMISO, SPI1PASSTHRU, COND1, SPI1PASSTHRU_DESC);
214SIG_EXPR_LIST_DECL_DUAL(SYSMISO, SPI1DEBUG, SPI1PASSTHRU);
204SS_PIN_DECL(C16, GPIOI3, SYSMISO); 215SS_PIN_DECL(C16, GPIOI3, SYSMISO);
205 216
206FUNC_GROUP_DECL(SPI1, C18, E15, A14, C16); 217#define VB_DESC SIG_DESC_SET(HW_STRAP1, 5)
218
219#define B15 68
220SIG_EXPR_DECL(SPI1CS0, SPI1, COND1, SPI1_DESC);
221SIG_EXPR_DECL(SPI1CS0, SPI1DEBUG, COND1, SPI1DEBUG_DESC);
222SIG_EXPR_DECL(SPI1CS0, SPI1PASSTHRU, COND1, SPI1PASSTHRU_DESC);
223SIG_EXPR_LIST_DECL(SPI1CS0, SIG_EXPR_PTR(SPI1CS0, SPI1),
224 SIG_EXPR_PTR(SPI1CS0, SPI1DEBUG),
225 SIG_EXPR_PTR(SPI1CS0, SPI1PASSTHRU));
226SIG_EXPR_LIST_DECL_SINGLE(VBCS, VGABIOSROM, COND1, VB_DESC);
227MS_PIN_DECL(B15, GPIOI4, SPI1CS0, VBCS);
228
229#define C15 69
230SIG_EXPR_DECL(SPI1CK, SPI1, COND1, SPI1_DESC);
231SIG_EXPR_DECL(SPI1CK, SPI1DEBUG, COND1, SPI1DEBUG_DESC);
232SIG_EXPR_DECL(SPI1CK, SPI1PASSTHRU, COND1, SPI1PASSTHRU_DESC);
233SIG_EXPR_LIST_DECL(SPI1CK, SIG_EXPR_PTR(SPI1CK, SPI1),
234 SIG_EXPR_PTR(SPI1CK, SPI1DEBUG),
235 SIG_EXPR_PTR(SPI1CK, SPI1PASSTHRU));
236SIG_EXPR_LIST_DECL_SINGLE(VBCK, VGABIOSROM, COND1, VB_DESC);
237MS_PIN_DECL(C15, GPIOI5, SPI1CK, VBCK);
238
239#define A14 70
240SIG_EXPR_DECL(SPI1MOSI, SPI1, COND1, SPI1_DESC);
241SIG_EXPR_DECL(SPI1MOSI, SPI1DEBUG, COND1, SPI1DEBUG_DESC);
242SIG_EXPR_DECL(SPI1MOSI, SPI1PASSTHRU, COND1, SPI1PASSTHRU_DESC);
243SIG_EXPR_LIST_DECL(SPI1MOSI, SIG_EXPR_PTR(SPI1MOSI, SPI1),
244 SIG_EXPR_PTR(SPI1MOSI, SPI1DEBUG),
245 SIG_EXPR_PTR(SPI1MOSI, SPI1PASSTHRU));
246SIG_EXPR_LIST_DECL_SINGLE(VBMOSI, VGABIOSROM, COND1, VB_DESC);
247MS_PIN_DECL(A14, GPIOI6, SPI1MOSI, VBMOSI);
248
249#define A15 71
250SIG_EXPR_DECL(SPI1MISO, SPI1, COND1, SPI1_DESC);
251SIG_EXPR_DECL(SPI1MISO, SPI1DEBUG, COND1, SPI1DEBUG_DESC);
252SIG_EXPR_DECL(SPI1MISO, SPI1PASSTHRU, COND1, SPI1PASSTHRU_DESC);
253SIG_EXPR_LIST_DECL(SPI1MISO, SIG_EXPR_PTR(SPI1MISO, SPI1),
254 SIG_EXPR_PTR(SPI1MISO, SPI1DEBUG),
255 SIG_EXPR_PTR(SPI1MISO, SPI1PASSTHRU));
256SIG_EXPR_LIST_DECL_SINGLE(VBMISO, VGABIOSROM, COND1, VB_DESC);
257MS_PIN_DECL(A15, GPIOI7, SPI1MISO, VBMISO);
258
259FUNC_GROUP_DECL(SPI1, B15, C15, A14, A15);
260FUNC_GROUP_DECL(SPI1DEBUG, C18, E15, B16, C16, B15, C15, A14, A15);
261FUNC_GROUP_DECL(SPI1PASSTHRU, C18, E15, B16, C16, B15, C15, A14, A15);
262FUNC_GROUP_DECL(VGABIOSROM, B15, C15, A14, A15);
263
264#define R2 72
265SIG_EXPR_LIST_DECL_SINGLE(SGPMCK, SGPM, SIG_DESC_SET(SCU84, 8));
266SS_PIN_DECL(R2, GPIOJ0, SGPMCK);
207 267
208#define L2 73 268#define L2 73
209SIG_EXPR_LIST_DECL_SINGLE(SGPMLD, SGPM, SIG_DESC_SET(SCU84, 9)); 269SIG_EXPR_LIST_DECL_SINGLE(SGPMLD, SGPM, SIG_DESC_SET(SCU84, 9));
@@ -580,6 +640,7 @@ static struct pinctrl_pin_desc aspeed_g5_pins[ASPEED_G5_NR_PINS] = {
580 ASPEED_PINCTRL_PIN(A12), 640 ASPEED_PINCTRL_PIN(A12),
581 ASPEED_PINCTRL_PIN(A13), 641 ASPEED_PINCTRL_PIN(A13),
582 ASPEED_PINCTRL_PIN(A14), 642 ASPEED_PINCTRL_PIN(A14),
643 ASPEED_PINCTRL_PIN(A15),
583 ASPEED_PINCTRL_PIN(A2), 644 ASPEED_PINCTRL_PIN(A2),
584 ASPEED_PINCTRL_PIN(A3), 645 ASPEED_PINCTRL_PIN(A3),
585 ASPEED_PINCTRL_PIN(A4), 646 ASPEED_PINCTRL_PIN(A4),
@@ -592,6 +653,8 @@ static struct pinctrl_pin_desc aspeed_g5_pins[ASPEED_G5_NR_PINS] = {
592 ASPEED_PINCTRL_PIN(B12), 653 ASPEED_PINCTRL_PIN(B12),
593 ASPEED_PINCTRL_PIN(B13), 654 ASPEED_PINCTRL_PIN(B13),
594 ASPEED_PINCTRL_PIN(B14), 655 ASPEED_PINCTRL_PIN(B14),
656 ASPEED_PINCTRL_PIN(B15),
657 ASPEED_PINCTRL_PIN(B16),
595 ASPEED_PINCTRL_PIN(B2), 658 ASPEED_PINCTRL_PIN(B2),
596 ASPEED_PINCTRL_PIN(B20), 659 ASPEED_PINCTRL_PIN(B20),
597 ASPEED_PINCTRL_PIN(B3), 660 ASPEED_PINCTRL_PIN(B3),
@@ -603,6 +666,7 @@ static struct pinctrl_pin_desc aspeed_g5_pins[ASPEED_G5_NR_PINS] = {
603 ASPEED_PINCTRL_PIN(C12), 666 ASPEED_PINCTRL_PIN(C12),
604 ASPEED_PINCTRL_PIN(C13), 667 ASPEED_PINCTRL_PIN(C13),
605 ASPEED_PINCTRL_PIN(C14), 668 ASPEED_PINCTRL_PIN(C14),
669 ASPEED_PINCTRL_PIN(C15),
606 ASPEED_PINCTRL_PIN(C16), 670 ASPEED_PINCTRL_PIN(C16),
607 ASPEED_PINCTRL_PIN(C18), 671 ASPEED_PINCTRL_PIN(C18),
608 ASPEED_PINCTRL_PIN(C2), 672 ASPEED_PINCTRL_PIN(C2),
@@ -614,7 +678,6 @@ static struct pinctrl_pin_desc aspeed_g5_pins[ASPEED_G5_NR_PINS] = {
614 ASPEED_PINCTRL_PIN(D10), 678 ASPEED_PINCTRL_PIN(D10),
615 ASPEED_PINCTRL_PIN(D2), 679 ASPEED_PINCTRL_PIN(D2),
616 ASPEED_PINCTRL_PIN(D20), 680 ASPEED_PINCTRL_PIN(D20),
617 ASPEED_PINCTRL_PIN(D21),
618 ASPEED_PINCTRL_PIN(D4), 681 ASPEED_PINCTRL_PIN(D4),
619 ASPEED_PINCTRL_PIN(D5), 682 ASPEED_PINCTRL_PIN(D5),
620 ASPEED_PINCTRL_PIN(D6), 683 ASPEED_PINCTRL_PIN(D6),
@@ -630,6 +693,7 @@ static struct pinctrl_pin_desc aspeed_g5_pins[ASPEED_G5_NR_PINS] = {
630 ASPEED_PINCTRL_PIN(E7), 693 ASPEED_PINCTRL_PIN(E7),
631 ASPEED_PINCTRL_PIN(E9), 694 ASPEED_PINCTRL_PIN(E9),
632 ASPEED_PINCTRL_PIN(F19), 695 ASPEED_PINCTRL_PIN(F19),
696 ASPEED_PINCTRL_PIN(F20),
633 ASPEED_PINCTRL_PIN(F9), 697 ASPEED_PINCTRL_PIN(F9),
634 ASPEED_PINCTRL_PIN(H20), 698 ASPEED_PINCTRL_PIN(H20),
635 ASPEED_PINCTRL_PIN(L1), 699 ASPEED_PINCTRL_PIN(L1),
@@ -691,11 +755,14 @@ static const struct aspeed_pin_group aspeed_g5_groups[] = {
691 ASPEED_PINCTRL_GROUP(RMII2), 755 ASPEED_PINCTRL_GROUP(RMII2),
692 ASPEED_PINCTRL_GROUP(SD1), 756 ASPEED_PINCTRL_GROUP(SD1),
693 ASPEED_PINCTRL_GROUP(SPI1), 757 ASPEED_PINCTRL_GROUP(SPI1),
758 ASPEED_PINCTRL_GROUP(SPI1DEBUG),
759 ASPEED_PINCTRL_GROUP(SPI1PASSTHRU),
694 ASPEED_PINCTRL_GROUP(TIMER4), 760 ASPEED_PINCTRL_GROUP(TIMER4),
695 ASPEED_PINCTRL_GROUP(TIMER5), 761 ASPEED_PINCTRL_GROUP(TIMER5),
696 ASPEED_PINCTRL_GROUP(TIMER6), 762 ASPEED_PINCTRL_GROUP(TIMER6),
697 ASPEED_PINCTRL_GROUP(TIMER7), 763 ASPEED_PINCTRL_GROUP(TIMER7),
698 ASPEED_PINCTRL_GROUP(TIMER8), 764 ASPEED_PINCTRL_GROUP(TIMER8),
765 ASPEED_PINCTRL_GROUP(VGABIOSROM),
699}; 766};
700 767
701static const struct aspeed_pin_function aspeed_g5_functions[] = { 768static const struct aspeed_pin_function aspeed_g5_functions[] = {
@@ -733,11 +800,14 @@ static const struct aspeed_pin_function aspeed_g5_functions[] = {
733 ASPEED_PINCTRL_FUNC(RMII2), 800 ASPEED_PINCTRL_FUNC(RMII2),
734 ASPEED_PINCTRL_FUNC(SD1), 801 ASPEED_PINCTRL_FUNC(SD1),
735 ASPEED_PINCTRL_FUNC(SPI1), 802 ASPEED_PINCTRL_FUNC(SPI1),
803 ASPEED_PINCTRL_FUNC(SPI1DEBUG),
804 ASPEED_PINCTRL_FUNC(SPI1PASSTHRU),
736 ASPEED_PINCTRL_FUNC(TIMER4), 805 ASPEED_PINCTRL_FUNC(TIMER4),
737 ASPEED_PINCTRL_FUNC(TIMER5), 806 ASPEED_PINCTRL_FUNC(TIMER5),
738 ASPEED_PINCTRL_FUNC(TIMER6), 807 ASPEED_PINCTRL_FUNC(TIMER6),
739 ASPEED_PINCTRL_FUNC(TIMER7), 808 ASPEED_PINCTRL_FUNC(TIMER7),
740 ASPEED_PINCTRL_FUNC(TIMER8), 809 ASPEED_PINCTRL_FUNC(TIMER8),
810 ASPEED_PINCTRL_FUNC(VGABIOSROM),
741}; 811};
742 812
743static struct aspeed_pinctrl_data aspeed_g5_pinctrl_data = { 813static struct aspeed_pinctrl_data aspeed_g5_pinctrl_data = {
diff --git a/drivers/pinctrl/aspeed/pinctrl-aspeed.c b/drivers/pinctrl/aspeed/pinctrl-aspeed.c
index 0391f9f13f3e..49aeba912531 100644
--- a/drivers/pinctrl/aspeed/pinctrl-aspeed.c
+++ b/drivers/pinctrl/aspeed/pinctrl-aspeed.c
@@ -166,13 +166,9 @@ static bool aspeed_sig_expr_set(const struct aspeed_sig_expr *expr,
166 bool enable, struct regmap *map) 166 bool enable, struct regmap *map)
167{ 167{
168 int i; 168 int i;
169 bool ret;
170
171 ret = aspeed_sig_expr_eval(expr, enable, map);
172 if (ret)
173 return ret;
174 169
175 for (i = 0; i < expr->ndescs; i++) { 170 for (i = 0; i < expr->ndescs; i++) {
171 bool ret;
176 const struct aspeed_sig_desc *desc = &expr->descs[i]; 172 const struct aspeed_sig_desc *desc = &expr->descs[i];
177 u32 pattern = enable ? desc->enable : desc->disable; 173 u32 pattern = enable ? desc->enable : desc->disable;
178 174
@@ -199,12 +195,18 @@ static bool aspeed_sig_expr_set(const struct aspeed_sig_expr *expr,
199static bool aspeed_sig_expr_enable(const struct aspeed_sig_expr *expr, 195static bool aspeed_sig_expr_enable(const struct aspeed_sig_expr *expr,
200 struct regmap *map) 196 struct regmap *map)
201{ 197{
198 if (aspeed_sig_expr_eval(expr, true, map))
199 return true;
200
202 return aspeed_sig_expr_set(expr, true, map); 201 return aspeed_sig_expr_set(expr, true, map);
203} 202}
204 203
205static bool aspeed_sig_expr_disable(const struct aspeed_sig_expr *expr, 204static bool aspeed_sig_expr_disable(const struct aspeed_sig_expr *expr,
206 struct regmap *map) 205 struct regmap *map)
207{ 206{
207 if (!aspeed_sig_expr_eval(expr, true, map))
208 return true;
209
208 return aspeed_sig_expr_set(expr, false, map); 210 return aspeed_sig_expr_set(expr, false, map);
209} 211}
210 212
diff --git a/drivers/pinctrl/bcm/pinctrl-iproc-gpio.c b/drivers/pinctrl/bcm/pinctrl-iproc-gpio.c
index 7f7700716398..5d1e505c3c63 100644
--- a/drivers/pinctrl/bcm/pinctrl-iproc-gpio.c
+++ b/drivers/pinctrl/bcm/pinctrl-iproc-gpio.c
@@ -844,6 +844,6 @@ static struct platform_driver iproc_gpio_driver = {
844 844
845static int __init iproc_gpio_init(void) 845static int __init iproc_gpio_init(void)
846{ 846{
847 return platform_driver_probe(&iproc_gpio_driver, iproc_gpio_probe); 847 return platform_driver_register(&iproc_gpio_driver);
848} 848}
849arch_initcall_sync(iproc_gpio_init); 849arch_initcall_sync(iproc_gpio_init);
diff --git a/drivers/pinctrl/bcm/pinctrl-nsp-gpio.c b/drivers/pinctrl/bcm/pinctrl-nsp-gpio.c
index 35783db1c10b..c8deb8be1da7 100644
--- a/drivers/pinctrl/bcm/pinctrl-nsp-gpio.c
+++ b/drivers/pinctrl/bcm/pinctrl-nsp-gpio.c
@@ -741,6 +741,6 @@ static struct platform_driver nsp_gpio_driver = {
741 741
742static int __init nsp_gpio_init(void) 742static int __init nsp_gpio_init(void)
743{ 743{
744 return platform_driver_probe(&nsp_gpio_driver, nsp_gpio_probe); 744 return platform_driver_register(&nsp_gpio_driver);
745} 745}
746arch_initcall_sync(nsp_gpio_init); 746arch_initcall_sync(nsp_gpio_init);
diff --git a/drivers/pinctrl/freescale/pinctrl-imx.c b/drivers/pinctrl/freescale/pinctrl-imx.c
index 47613201269a..79c4e14a5a75 100644
--- a/drivers/pinctrl/freescale/pinctrl-imx.c
+++ b/drivers/pinctrl/freescale/pinctrl-imx.c
@@ -687,6 +687,7 @@ static int imx_pinctrl_probe_dt(struct platform_device *pdev,
687 if (!info->functions) 687 if (!info->functions)
688 return -ENOMEM; 688 return -ENOMEM;
689 689
690 info->group_index = 0;
690 if (flat_funcs) { 691 if (flat_funcs) {
691 info->ngroups = of_get_child_count(np); 692 info->ngroups = of_get_child_count(np);
692 } else { 693 } else {
diff --git a/drivers/pinctrl/intel/pinctrl-baytrail.c b/drivers/pinctrl/intel/pinctrl-baytrail.c
index d22a9fe2e6df..71bbeb9321ba 100644
--- a/drivers/pinctrl/intel/pinctrl-baytrail.c
+++ b/drivers/pinctrl/intel/pinctrl-baytrail.c
@@ -1808,6 +1808,8 @@ static int byt_pinctrl_probe(struct platform_device *pdev)
1808 return PTR_ERR(vg->pctl_dev); 1808 return PTR_ERR(vg->pctl_dev);
1809 } 1809 }
1810 1810
1811 raw_spin_lock_init(&vg->lock);
1812
1811 ret = byt_gpio_probe(vg); 1813 ret = byt_gpio_probe(vg);
1812 if (ret) { 1814 if (ret) {
1813 pinctrl_unregister(vg->pctl_dev); 1815 pinctrl_unregister(vg->pctl_dev);
@@ -1815,7 +1817,6 @@ static int byt_pinctrl_probe(struct platform_device *pdev)
1815 } 1817 }
1816 1818
1817 platform_set_drvdata(pdev, vg); 1819 platform_set_drvdata(pdev, vg);
1818 raw_spin_lock_init(&vg->lock);
1819 pm_runtime_enable(&pdev->dev); 1820 pm_runtime_enable(&pdev->dev);
1820 1821
1821 return 0; 1822 return 0;
diff --git a/drivers/pinctrl/intel/pinctrl-cherryview.c b/drivers/pinctrl/intel/pinctrl-cherryview.c
index 30389f4ccab4..c43b1e9a06af 100644
--- a/drivers/pinctrl/intel/pinctrl-cherryview.c
+++ b/drivers/pinctrl/intel/pinctrl-cherryview.c
@@ -1652,12 +1652,15 @@ static int chv_pinctrl_probe(struct platform_device *pdev)
1652} 1652}
1653 1653
1654#ifdef CONFIG_PM_SLEEP 1654#ifdef CONFIG_PM_SLEEP
1655static int chv_pinctrl_suspend(struct device *dev) 1655static int chv_pinctrl_suspend_noirq(struct device *dev)
1656{ 1656{
1657 struct platform_device *pdev = to_platform_device(dev); 1657 struct platform_device *pdev = to_platform_device(dev);
1658 struct chv_pinctrl *pctrl = platform_get_drvdata(pdev); 1658 struct chv_pinctrl *pctrl = platform_get_drvdata(pdev);
1659 unsigned long flags;
1659 int i; 1660 int i;
1660 1661
1662 raw_spin_lock_irqsave(&chv_lock, flags);
1663
1661 pctrl->saved_intmask = readl(pctrl->regs + CHV_INTMASK); 1664 pctrl->saved_intmask = readl(pctrl->regs + CHV_INTMASK);
1662 1665
1663 for (i = 0; i < pctrl->community->npins; i++) { 1666 for (i = 0; i < pctrl->community->npins; i++) {
@@ -1678,15 +1681,20 @@ static int chv_pinctrl_suspend(struct device *dev)
1678 ctx->padctrl1 = readl(reg); 1681 ctx->padctrl1 = readl(reg);
1679 } 1682 }
1680 1683
1684 raw_spin_unlock_irqrestore(&chv_lock, flags);
1685
1681 return 0; 1686 return 0;
1682} 1687}
1683 1688
1684static int chv_pinctrl_resume(struct device *dev) 1689static int chv_pinctrl_resume_noirq(struct device *dev)
1685{ 1690{
1686 struct platform_device *pdev = to_platform_device(dev); 1691 struct platform_device *pdev = to_platform_device(dev);
1687 struct chv_pinctrl *pctrl = platform_get_drvdata(pdev); 1692 struct chv_pinctrl *pctrl = platform_get_drvdata(pdev);
1693 unsigned long flags;
1688 int i; 1694 int i;
1689 1695
1696 raw_spin_lock_irqsave(&chv_lock, flags);
1697
1690 /* 1698 /*
1691 * Mask all interrupts before restoring per-pin configuration 1699 * Mask all interrupts before restoring per-pin configuration
1692 * registers because we don't know in which state BIOS left them 1700 * registers because we don't know in which state BIOS left them
@@ -1731,12 +1739,15 @@ static int chv_pinctrl_resume(struct device *dev)
1731 chv_writel(0xffff, pctrl->regs + CHV_INTSTAT); 1739 chv_writel(0xffff, pctrl->regs + CHV_INTSTAT);
1732 chv_writel(pctrl->saved_intmask, pctrl->regs + CHV_INTMASK); 1740 chv_writel(pctrl->saved_intmask, pctrl->regs + CHV_INTMASK);
1733 1741
1742 raw_spin_unlock_irqrestore(&chv_lock, flags);
1743
1734 return 0; 1744 return 0;
1735} 1745}
1736#endif 1746#endif
1737 1747
1738static const struct dev_pm_ops chv_pinctrl_pm_ops = { 1748static const struct dev_pm_ops chv_pinctrl_pm_ops = {
1739 SET_LATE_SYSTEM_SLEEP_PM_OPS(chv_pinctrl_suspend, chv_pinctrl_resume) 1749 SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(chv_pinctrl_suspend_noirq,
1750 chv_pinctrl_resume_noirq)
1740}; 1751};
1741 1752
1742static const struct acpi_device_id chv_pinctrl_acpi_match[] = { 1753static const struct acpi_device_id chv_pinctrl_acpi_match[] = {
diff --git a/drivers/pinctrl/intel/pinctrl-intel.c b/drivers/pinctrl/intel/pinctrl-intel.c
index 63387a40b973..01443762e570 100644
--- a/drivers/pinctrl/intel/pinctrl-intel.c
+++ b/drivers/pinctrl/intel/pinctrl-intel.c
@@ -19,6 +19,7 @@
19#include <linux/pinctrl/pinconf.h> 19#include <linux/pinctrl/pinconf.h>
20#include <linux/pinctrl/pinconf-generic.h> 20#include <linux/pinctrl/pinconf-generic.h>
21 21
22#include "../core.h"
22#include "pinctrl-intel.h" 23#include "pinctrl-intel.h"
23 24
24/* Offset from regs */ 25/* Offset from regs */
@@ -1056,6 +1057,26 @@ int intel_pinctrl_remove(struct platform_device *pdev)
1056EXPORT_SYMBOL_GPL(intel_pinctrl_remove); 1057EXPORT_SYMBOL_GPL(intel_pinctrl_remove);
1057 1058
1058#ifdef CONFIG_PM_SLEEP 1059#ifdef CONFIG_PM_SLEEP
1060static bool intel_pinctrl_should_save(struct intel_pinctrl *pctrl, unsigned pin)
1061{
1062 const struct pin_desc *pd = pin_desc_get(pctrl->pctldev, pin);
1063
1064 if (!pd || !intel_pad_usable(pctrl, pin))
1065 return false;
1066
1067 /*
1068 * Only restore the pin if it is actually in use by the kernel (or
1069 * by userspace). It is possible that some pins are used by the
1070 * BIOS during resume and those are not always locked down so leave
1071 * them alone.
1072 */
1073 if (pd->mux_owner || pd->gpio_owner ||
1074 gpiochip_line_is_irq(&pctrl->chip, pin))
1075 return true;
1076
1077 return false;
1078}
1079
1059int intel_pinctrl_suspend(struct device *dev) 1080int intel_pinctrl_suspend(struct device *dev)
1060{ 1081{
1061 struct platform_device *pdev = to_platform_device(dev); 1082 struct platform_device *pdev = to_platform_device(dev);
@@ -1069,7 +1090,7 @@ int intel_pinctrl_suspend(struct device *dev)
1069 const struct pinctrl_pin_desc *desc = &pctrl->soc->pins[i]; 1090 const struct pinctrl_pin_desc *desc = &pctrl->soc->pins[i];
1070 u32 val; 1091 u32 val;
1071 1092
1072 if (!intel_pad_usable(pctrl, desc->number)) 1093 if (!intel_pinctrl_should_save(pctrl, desc->number))
1073 continue; 1094 continue;
1074 1095
1075 val = readl(intel_get_padcfg(pctrl, desc->number, PADCFG0)); 1096 val = readl(intel_get_padcfg(pctrl, desc->number, PADCFG0));
@@ -1130,7 +1151,7 @@ int intel_pinctrl_resume(struct device *dev)
1130 void __iomem *padcfg; 1151 void __iomem *padcfg;
1131 u32 val; 1152 u32 val;
1132 1153
1133 if (!intel_pad_usable(pctrl, desc->number)) 1154 if (!intel_pinctrl_should_save(pctrl, desc->number))
1134 continue; 1155 continue;
1135 1156
1136 padcfg = intel_get_padcfg(pctrl, desc->number, PADCFG0); 1157 padcfg = intel_get_padcfg(pctrl, desc->number, PADCFG0);
diff --git a/drivers/pinctrl/pinctrl-st.c b/drivers/pinctrl/pinctrl-st.c
index 99da4cf91031..b7bb37167969 100644
--- a/drivers/pinctrl/pinctrl-st.c
+++ b/drivers/pinctrl/pinctrl-st.c
@@ -1512,7 +1512,7 @@ static int st_gpiolib_register_bank(struct st_pinctrl *info,
1512 if (info->irqmux_base || gpio_irq > 0) { 1512 if (info->irqmux_base || gpio_irq > 0) {
1513 err = gpiochip_irqchip_add(&bank->gpio_chip, &st_gpio_irqchip, 1513 err = gpiochip_irqchip_add(&bank->gpio_chip, &st_gpio_irqchip,
1514 0, handle_simple_irq, 1514 0, handle_simple_irq,
1515 IRQ_TYPE_LEVEL_LOW); 1515 IRQ_TYPE_NONE);
1516 if (err) { 1516 if (err) {
1517 gpiochip_remove(&bank->gpio_chip); 1517 gpiochip_remove(&bank->gpio_chip);
1518 dev_info(dev, "could not add irqchip\n"); 1518 dev_info(dev, "could not add irqchip\n");
diff --git a/drivers/pinctrl/stm32/pinctrl-stm32.c b/drivers/pinctrl/stm32/pinctrl-stm32.c
index 200667f08c37..efc43711ff5c 100644
--- a/drivers/pinctrl/stm32/pinctrl-stm32.c
+++ b/drivers/pinctrl/stm32/pinctrl-stm32.c
@@ -1092,9 +1092,11 @@ int stm32_pctl_probe(struct platform_device *pdev)
1092 return -EINVAL; 1092 return -EINVAL;
1093 } 1093 }
1094 1094
1095 ret = stm32_pctrl_dt_setup_irq(pdev, pctl); 1095 if (of_find_property(np, "interrupt-parent", NULL)) {
1096 if (ret) 1096 ret = stm32_pctrl_dt_setup_irq(pdev, pctl);
1097 return ret; 1097 if (ret)
1098 return ret;
1099 }
1098 1100
1099 for_each_child_of_node(np, child) 1101 for_each_child_of_node(np, child)
1100 if (of_property_read_bool(child, "gpio-controller")) 1102 if (of_property_read_bool(child, "gpio-controller"))
diff --git a/drivers/platform/goldfish/goldfish_pipe.c b/drivers/platform/goldfish/goldfish_pipe.c
index 07462d79d040..1aba2c74160e 100644
--- a/drivers/platform/goldfish/goldfish_pipe.c
+++ b/drivers/platform/goldfish/goldfish_pipe.c
@@ -309,7 +309,8 @@ static ssize_t goldfish_pipe_read_write(struct file *filp, char __user *buffer,
309 * much memory to the process. 309 * much memory to the process.
310 */ 310 */
311 down_read(&current->mm->mmap_sem); 311 down_read(&current->mm->mmap_sem);
312 ret = get_user_pages(address, 1, !is_write, 0, &page, NULL); 312 ret = get_user_pages(address, 1, is_write ? 0 : FOLL_WRITE,
313 &page, NULL);
313 up_read(&current->mm->mmap_sem); 314 up_read(&current->mm->mmap_sem);
314 if (ret < 0) 315 if (ret < 0)
315 break; 316 break;
diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig
index 81b8dcca8891..b8a21d7b25d4 100644
--- a/drivers/platform/x86/Kconfig
+++ b/drivers/platform/x86/Kconfig
@@ -576,6 +576,7 @@ config ASUS_WMI
576config ASUS_NB_WMI 576config ASUS_NB_WMI
577 tristate "Asus Notebook WMI Driver" 577 tristate "Asus Notebook WMI Driver"
578 depends on ASUS_WMI 578 depends on ASUS_WMI
579 depends on SERIO_I8042 || SERIO_I8042 = n
579 ---help--- 580 ---help---
580 This is a driver for newer Asus notebooks. It adds extra features 581 This is a driver for newer Asus notebooks. It adds extra features
581 like wireless radio and bluetooth control, leds, hotkeys, backlight... 582 like wireless radio and bluetooth control, leds, hotkeys, backlight...
diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c
index d1a091b93192..a7614fc542b5 100644
--- a/drivers/platform/x86/ideapad-laptop.c
+++ b/drivers/platform/x86/ideapad-laptop.c
@@ -933,6 +933,20 @@ static const struct dmi_system_id no_hw_rfkill_list[] = {
933 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo YOGA 900"), 933 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo YOGA 900"),
934 }, 934 },
935 }, 935 },
936 {
937 .ident = "Lenovo Yoga 900",
938 .matches = {
939 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
940 DMI_MATCH(DMI_BOARD_NAME, "VIUU4"),
941 },
942 },
943 {
944 .ident = "Lenovo YOGA 910-13IKB",
945 .matches = {
946 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
947 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo YOGA 910-13IKB"),
948 },
949 },
936 {} 950 {}
937}; 951};
938 952
diff --git a/drivers/platform/x86/intel-hid.c b/drivers/platform/x86/intel-hid.c
index ed5874217ee7..12dbb5063376 100644
--- a/drivers/platform/x86/intel-hid.c
+++ b/drivers/platform/x86/intel-hid.c
@@ -264,7 +264,7 @@ check_acpi_dev(acpi_handle handle, u32 lvl, void *context, void **rv)
264 return AE_OK; 264 return AE_OK;
265 265
266 if (acpi_match_device_ids(dev, ids) == 0) 266 if (acpi_match_device_ids(dev, ids) == 0)
267 if (acpi_create_platform_device(dev)) 267 if (acpi_create_platform_device(dev, NULL))
268 dev_info(&dev->dev, 268 dev_info(&dev->dev,
269 "intel-hid: created platform device\n"); 269 "intel-hid: created platform device\n");
270 270
diff --git a/drivers/platform/x86/intel-vbtn.c b/drivers/platform/x86/intel-vbtn.c
index 146d02f8c9bc..78080763df51 100644
--- a/drivers/platform/x86/intel-vbtn.c
+++ b/drivers/platform/x86/intel-vbtn.c
@@ -164,7 +164,7 @@ check_acpi_dev(acpi_handle handle, u32 lvl, void *context, void **rv)
164 return AE_OK; 164 return AE_OK;
165 165
166 if (acpi_match_device_ids(dev, ids) == 0) 166 if (acpi_match_device_ids(dev, ids) == 0)
167 if (acpi_create_platform_device(dev)) 167 if (acpi_create_platform_device(dev, NULL))
168 dev_info(&dev->dev, 168 dev_info(&dev->dev,
169 "intel-vbtn: created platform device\n"); 169 "intel-vbtn: created platform device\n");
170 170
diff --git a/drivers/platform/x86/toshiba-wmi.c b/drivers/platform/x86/toshiba-wmi.c
index feac4576b837..2df07ee8f3c3 100644
--- a/drivers/platform/x86/toshiba-wmi.c
+++ b/drivers/platform/x86/toshiba-wmi.c
@@ -24,14 +24,15 @@
24#include <linux/acpi.h> 24#include <linux/acpi.h>
25#include <linux/input.h> 25#include <linux/input.h>
26#include <linux/input/sparse-keymap.h> 26#include <linux/input/sparse-keymap.h>
27#include <linux/dmi.h>
27 28
28MODULE_AUTHOR("Azael Avalos"); 29MODULE_AUTHOR("Azael Avalos");
29MODULE_DESCRIPTION("Toshiba WMI Hotkey Driver"); 30MODULE_DESCRIPTION("Toshiba WMI Hotkey Driver");
30MODULE_LICENSE("GPL"); 31MODULE_LICENSE("GPL");
31 32
32#define TOSHIBA_WMI_EVENT_GUID "59142400-C6A3-40FA-BADB-8A2652834100" 33#define WMI_EVENT_GUID "59142400-C6A3-40FA-BADB-8A2652834100"
33 34
34MODULE_ALIAS("wmi:"TOSHIBA_WMI_EVENT_GUID); 35MODULE_ALIAS("wmi:"WMI_EVENT_GUID);
35 36
36static struct input_dev *toshiba_wmi_input_dev; 37static struct input_dev *toshiba_wmi_input_dev;
37 38
@@ -63,6 +64,16 @@ static void toshiba_wmi_notify(u32 value, void *context)
63 kfree(response.pointer); 64 kfree(response.pointer);
64} 65}
65 66
67static struct dmi_system_id toshiba_wmi_dmi_table[] __initdata = {
68 {
69 .ident = "Toshiba laptop",
70 .matches = {
71 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
72 },
73 },
74 {}
75};
76
66static int __init toshiba_wmi_input_setup(void) 77static int __init toshiba_wmi_input_setup(void)
67{ 78{
68 acpi_status status; 79 acpi_status status;
@@ -81,7 +92,7 @@ static int __init toshiba_wmi_input_setup(void)
81 if (err) 92 if (err)
82 goto err_free_dev; 93 goto err_free_dev;
83 94
84 status = wmi_install_notify_handler(TOSHIBA_WMI_EVENT_GUID, 95 status = wmi_install_notify_handler(WMI_EVENT_GUID,
85 toshiba_wmi_notify, NULL); 96 toshiba_wmi_notify, NULL);
86 if (ACPI_FAILURE(status)) { 97 if (ACPI_FAILURE(status)) {
87 err = -EIO; 98 err = -EIO;
@@ -95,7 +106,7 @@ static int __init toshiba_wmi_input_setup(void)
95 return 0; 106 return 0;
96 107
97 err_remove_notifier: 108 err_remove_notifier:
98 wmi_remove_notify_handler(TOSHIBA_WMI_EVENT_GUID); 109 wmi_remove_notify_handler(WMI_EVENT_GUID);
99 err_free_keymap: 110 err_free_keymap:
100 sparse_keymap_free(toshiba_wmi_input_dev); 111 sparse_keymap_free(toshiba_wmi_input_dev);
101 err_free_dev: 112 err_free_dev:
@@ -105,7 +116,7 @@ static int __init toshiba_wmi_input_setup(void)
105 116
106static void toshiba_wmi_input_destroy(void) 117static void toshiba_wmi_input_destroy(void)
107{ 118{
108 wmi_remove_notify_handler(TOSHIBA_WMI_EVENT_GUID); 119 wmi_remove_notify_handler(WMI_EVENT_GUID);
109 sparse_keymap_free(toshiba_wmi_input_dev); 120 sparse_keymap_free(toshiba_wmi_input_dev);
110 input_unregister_device(toshiba_wmi_input_dev); 121 input_unregister_device(toshiba_wmi_input_dev);
111} 122}
@@ -114,7 +125,8 @@ static int __init toshiba_wmi_init(void)
114{ 125{
115 int ret; 126 int ret;
116 127
117 if (!wmi_has_guid(TOSHIBA_WMI_EVENT_GUID)) 128 if (!wmi_has_guid(WMI_EVENT_GUID) ||
129 !dmi_check_system(toshiba_wmi_dmi_table))
118 return -ENODEV; 130 return -ENODEV;
119 131
120 ret = toshiba_wmi_input_setup(); 132 ret = toshiba_wmi_input_setup();
@@ -130,7 +142,7 @@ static int __init toshiba_wmi_init(void)
130 142
131static void __exit toshiba_wmi_exit(void) 143static void __exit toshiba_wmi_exit(void)
132{ 144{
133 if (wmi_has_guid(TOSHIBA_WMI_EVENT_GUID)) 145 if (wmi_has_guid(WMI_EVENT_GUID))
134 toshiba_wmi_input_destroy(); 146 toshiba_wmi_input_destroy();
135} 147}
136 148
diff --git a/drivers/pwm/pwm-meson.c b/drivers/pwm/pwm-meson.c
index 381871b2bb46..9d5bd7d5c610 100644
--- a/drivers/pwm/pwm-meson.c
+++ b/drivers/pwm/pwm-meson.c
@@ -474,6 +474,7 @@ static int meson_pwm_probe(struct platform_device *pdev)
474 if (IS_ERR(meson->base)) 474 if (IS_ERR(meson->base))
475 return PTR_ERR(meson->base); 475 return PTR_ERR(meson->base);
476 476
477 spin_lock_init(&meson->lock);
477 meson->chip.dev = &pdev->dev; 478 meson->chip.dev = &pdev->dev;
478 meson->chip.ops = &meson_pwm_ops; 479 meson->chip.ops = &meson_pwm_ops;
479 meson->chip.base = -1; 480 meson->chip.base = -1;
diff --git a/drivers/pwm/sysfs.c b/drivers/pwm/sysfs.c
index 0296d8178ae2..a813239300c3 100644
--- a/drivers/pwm/sysfs.c
+++ b/drivers/pwm/sysfs.c
@@ -425,6 +425,8 @@ void pwmchip_sysfs_unexport_children(struct pwm_chip *chip)
425 if (test_bit(PWMF_EXPORTED, &pwm->flags)) 425 if (test_bit(PWMF_EXPORTED, &pwm->flags))
426 pwm_unexport_child(parent, pwm); 426 pwm_unexport_child(parent, pwm);
427 } 427 }
428
429 put_device(parent);
428} 430}
429 431
430static int __init pwm_sysfs_init(void) 432static int __init pwm_sysfs_init(void)
diff --git a/drivers/rapidio/devices/rio_mport_cdev.c b/drivers/rapidio/devices/rio_mport_cdev.c
index 436dfe871d32..9013a585507e 100644
--- a/drivers/rapidio/devices/rio_mport_cdev.c
+++ b/drivers/rapidio/devices/rio_mport_cdev.c
@@ -892,7 +892,8 @@ rio_dma_transfer(struct file *filp, u32 transfer_mode,
892 down_read(&current->mm->mmap_sem); 892 down_read(&current->mm->mmap_sem);
893 pinned = get_user_pages( 893 pinned = get_user_pages(
894 (unsigned long)xfer->loc_addr & PAGE_MASK, 894 (unsigned long)xfer->loc_addr & PAGE_MASK,
895 nr_pages, dir == DMA_FROM_DEVICE, 0, 895 nr_pages,
896 dir == DMA_FROM_DEVICE ? FOLL_WRITE : 0,
896 page_list, NULL); 897 page_list, NULL);
897 up_read(&current->mm->mmap_sem); 898 up_read(&current->mm->mmap_sem);
898 899
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 67426c0477d3..5c1519b229e0 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -2754,7 +2754,7 @@ static int _regulator_set_voltage_time(struct regulator_dev *rdev,
2754 ramp_delay = rdev->desc->ramp_delay; 2754 ramp_delay = rdev->desc->ramp_delay;
2755 2755
2756 if (ramp_delay == 0) { 2756 if (ramp_delay == 0) {
2757 rdev_warn(rdev, "ramp_delay not set\n"); 2757 rdev_dbg(rdev, "ramp_delay not set\n");
2758 return 0; 2758 return 0;
2759 } 2759 }
2760 2760
diff --git a/drivers/regulator/rk808-regulator.c b/drivers/regulator/rk808-regulator.c
index 3314bf299a51..fb44d5215e30 100644
--- a/drivers/regulator/rk808-regulator.c
+++ b/drivers/regulator/rk808-regulator.c
@@ -120,7 +120,7 @@ static const struct regulator_linear_range rk808_ldo3_voltage_ranges[] = {
120static int rk808_buck1_2_get_voltage_sel_regmap(struct regulator_dev *rdev) 120static int rk808_buck1_2_get_voltage_sel_regmap(struct regulator_dev *rdev)
121{ 121{
122 struct rk808_regulator_data *pdata = rdev_get_drvdata(rdev); 122 struct rk808_regulator_data *pdata = rdev_get_drvdata(rdev);
123 int id = rdev->desc->id - RK808_ID_DCDC1; 123 int id = rdev_get_id(rdev);
124 struct gpio_desc *gpio = pdata->dvs_gpio[id]; 124 struct gpio_desc *gpio = pdata->dvs_gpio[id];
125 unsigned int val; 125 unsigned int val;
126 int ret; 126 int ret;
@@ -193,7 +193,7 @@ static int rk808_buck1_2_set_voltage_sel(struct regulator_dev *rdev,
193 unsigned sel) 193 unsigned sel)
194{ 194{
195 struct rk808_regulator_data *pdata = rdev_get_drvdata(rdev); 195 struct rk808_regulator_data *pdata = rdev_get_drvdata(rdev);
196 int id = rdev->desc->id - RK808_ID_DCDC1; 196 int id = rdev_get_id(rdev);
197 struct gpio_desc *gpio = pdata->dvs_gpio[id]; 197 struct gpio_desc *gpio = pdata->dvs_gpio[id];
198 unsigned int reg = rdev->desc->vsel_reg; 198 unsigned int reg = rdev->desc->vsel_reg;
199 unsigned old_sel; 199 unsigned old_sel;
@@ -232,7 +232,7 @@ static int rk808_buck1_2_set_voltage_time_sel(struct regulator_dev *rdev,
232 unsigned int new_selector) 232 unsigned int new_selector)
233{ 233{
234 struct rk808_regulator_data *pdata = rdev_get_drvdata(rdev); 234 struct rk808_regulator_data *pdata = rdev_get_drvdata(rdev);
235 int id = rdev->desc->id - RK808_ID_DCDC1; 235 int id = rdev_get_id(rdev);
236 struct gpio_desc *gpio = pdata->dvs_gpio[id]; 236 struct gpio_desc *gpio = pdata->dvs_gpio[id];
237 237
238 /* if there is no dvs1/2 pin, we don't need wait extra time here. */ 238 /* if there is no dvs1/2 pin, we don't need wait extra time here. */
@@ -245,8 +245,7 @@ static int rk808_buck1_2_set_voltage_time_sel(struct regulator_dev *rdev,
245static int rk808_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay) 245static int rk808_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay)
246{ 246{
247 unsigned int ramp_value = RK808_RAMP_RATE_10MV_PER_US; 247 unsigned int ramp_value = RK808_RAMP_RATE_10MV_PER_US;
248 unsigned int reg = rk808_buck_config_regs[rdev->desc->id - 248 unsigned int reg = rk808_buck_config_regs[rdev_get_id(rdev)];
249 RK808_ID_DCDC1];
250 249
251 switch (ramp_delay) { 250 switch (ramp_delay) {
252 case 1 ... 2000: 251 case 1 ... 2000:
diff --git a/drivers/reset/reset-uniphier.c b/drivers/reset/reset-uniphier.c
index 8b2558e7363e..968c3ae4535c 100644
--- a/drivers/reset/reset-uniphier.c
+++ b/drivers/reset/reset-uniphier.c
@@ -154,7 +154,7 @@ const struct uniphier_reset_data uniphier_sld3_mio_reset_data[] = {
154 UNIPHIER_RESET_END, 154 UNIPHIER_RESET_END,
155}; 155};
156 156
157const struct uniphier_reset_data uniphier_pro5_mio_reset_data[] = { 157const struct uniphier_reset_data uniphier_pro5_sd_reset_data[] = {
158 UNIPHIER_MIO_RESET_SD(0, 0), 158 UNIPHIER_MIO_RESET_SD(0, 0),
159 UNIPHIER_MIO_RESET_SD(1, 1), 159 UNIPHIER_MIO_RESET_SD(1, 1),
160 UNIPHIER_MIO_RESET_EMMC_HW_RESET(6, 1), 160 UNIPHIER_MIO_RESET_EMMC_HW_RESET(6, 1),
@@ -360,7 +360,7 @@ static const struct of_device_id uniphier_reset_match[] = {
360 .compatible = "socionext,uniphier-ld20-reset", 360 .compatible = "socionext,uniphier-ld20-reset",
361 .data = uniphier_ld20_sys_reset_data, 361 .data = uniphier_ld20_sys_reset_data,
362 }, 362 },
363 /* Media I/O reset */ 363 /* Media I/O reset, SD reset */
364 { 364 {
365 .compatible = "socionext,uniphier-sld3-mio-reset", 365 .compatible = "socionext,uniphier-sld3-mio-reset",
366 .data = uniphier_sld3_mio_reset_data, 366 .data = uniphier_sld3_mio_reset_data,
@@ -378,20 +378,20 @@ static const struct of_device_id uniphier_reset_match[] = {
378 .data = uniphier_sld3_mio_reset_data, 378 .data = uniphier_sld3_mio_reset_data,
379 }, 379 },
380 { 380 {
381 .compatible = "socionext,uniphier-pro5-mio-reset", 381 .compatible = "socionext,uniphier-pro5-sd-reset",
382 .data = uniphier_pro5_mio_reset_data, 382 .data = uniphier_pro5_sd_reset_data,
383 }, 383 },
384 { 384 {
385 .compatible = "socionext,uniphier-pxs2-mio-reset", 385 .compatible = "socionext,uniphier-pxs2-sd-reset",
386 .data = uniphier_pro5_mio_reset_data, 386 .data = uniphier_pro5_sd_reset_data,
387 }, 387 },
388 { 388 {
389 .compatible = "socionext,uniphier-ld11-mio-reset", 389 .compatible = "socionext,uniphier-ld11-mio-reset",
390 .data = uniphier_sld3_mio_reset_data, 390 .data = uniphier_sld3_mio_reset_data,
391 }, 391 },
392 { 392 {
393 .compatible = "socionext,uniphier-ld20-mio-reset", 393 .compatible = "socionext,uniphier-ld20-sd-reset",
394 .data = uniphier_pro5_mio_reset_data, 394 .data = uniphier_pro5_sd_reset_data,
395 }, 395 },
396 /* Peripheral reset */ 396 /* Peripheral reset */
397 { 397 {
diff --git a/drivers/rtc/rtc-asm9260.c b/drivers/rtc/rtc-asm9260.c
index 18a93d3e3f93..d36534965635 100644
--- a/drivers/rtc/rtc-asm9260.c
+++ b/drivers/rtc/rtc-asm9260.c
@@ -327,6 +327,7 @@ static const struct of_device_id asm9260_dt_ids[] = {
327 { .compatible = "alphascale,asm9260-rtc", }, 327 { .compatible = "alphascale,asm9260-rtc", },
328 {} 328 {}
329}; 329};
330MODULE_DEVICE_TABLE(of, asm9260_dt_ids);
330 331
331static struct platform_driver asm9260_rtc_driver = { 332static struct platform_driver asm9260_rtc_driver = {
332 .probe = asm9260_rtc_probe, 333 .probe = asm9260_rtc_probe,
diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
index dd3d59806ffa..7030d7cd3861 100644
--- a/drivers/rtc/rtc-cmos.c
+++ b/drivers/rtc/rtc-cmos.c
@@ -776,7 +776,7 @@ static void cmos_do_shutdown(int rtc_irq)
776 spin_unlock_irq(&rtc_lock); 776 spin_unlock_irq(&rtc_lock);
777} 777}
778 778
779static void __exit cmos_do_remove(struct device *dev) 779static void cmos_do_remove(struct device *dev)
780{ 780{
781 struct cmos_rtc *cmos = dev_get_drvdata(dev); 781 struct cmos_rtc *cmos = dev_get_drvdata(dev);
782 struct resource *ports; 782 struct resource *ports;
@@ -996,8 +996,9 @@ static u32 rtc_handler(void *context)
996 struct cmos_rtc *cmos = dev_get_drvdata(dev); 996 struct cmos_rtc *cmos = dev_get_drvdata(dev);
997 unsigned char rtc_control = 0; 997 unsigned char rtc_control = 0;
998 unsigned char rtc_intr; 998 unsigned char rtc_intr;
999 unsigned long flags;
999 1000
1000 spin_lock_irq(&rtc_lock); 1001 spin_lock_irqsave(&rtc_lock, flags);
1001 if (cmos_rtc.suspend_ctrl) 1002 if (cmos_rtc.suspend_ctrl)
1002 rtc_control = CMOS_READ(RTC_CONTROL); 1003 rtc_control = CMOS_READ(RTC_CONTROL);
1003 if (rtc_control & RTC_AIE) { 1004 if (rtc_control & RTC_AIE) {
@@ -1006,7 +1007,7 @@ static u32 rtc_handler(void *context)
1006 rtc_intr = CMOS_READ(RTC_INTR_FLAGS); 1007 rtc_intr = CMOS_READ(RTC_INTR_FLAGS);
1007 rtc_update_irq(cmos->rtc, 1, rtc_intr); 1008 rtc_update_irq(cmos->rtc, 1, rtc_intr);
1008 } 1009 }
1009 spin_unlock_irq(&rtc_lock); 1010 spin_unlock_irqrestore(&rtc_lock, flags);
1010 1011
1011 pm_wakeup_event(dev, 0); 1012 pm_wakeup_event(dev, 0);
1012 acpi_clear_event(ACPI_EVENT_RTC); 1013 acpi_clear_event(ACPI_EVENT_RTC);
@@ -1129,7 +1130,7 @@ static int cmos_pnp_probe(struct pnp_dev *pnp, const struct pnp_device_id *id)
1129 pnp_irq(pnp, 0)); 1130 pnp_irq(pnp, 0));
1130} 1131}
1131 1132
1132static void __exit cmos_pnp_remove(struct pnp_dev *pnp) 1133static void cmos_pnp_remove(struct pnp_dev *pnp)
1133{ 1134{
1134 cmos_do_remove(&pnp->dev); 1135 cmos_do_remove(&pnp->dev);
1135} 1136}
@@ -1161,7 +1162,7 @@ static struct pnp_driver cmos_pnp_driver = {
1161 .name = (char *) driver_name, 1162 .name = (char *) driver_name,
1162 .id_table = rtc_ids, 1163 .id_table = rtc_ids,
1163 .probe = cmos_pnp_probe, 1164 .probe = cmos_pnp_probe,
1164 .remove = __exit_p(cmos_pnp_remove), 1165 .remove = cmos_pnp_remove,
1165 .shutdown = cmos_pnp_shutdown, 1166 .shutdown = cmos_pnp_shutdown,
1166 1167
1167 /* flag ensures resume() gets called, and stops syslog spam */ 1168 /* flag ensures resume() gets called, and stops syslog spam */
@@ -1238,7 +1239,7 @@ static int __init cmos_platform_probe(struct platform_device *pdev)
1238 return cmos_do_probe(&pdev->dev, resource, irq); 1239 return cmos_do_probe(&pdev->dev, resource, irq);
1239} 1240}
1240 1241
1241static int __exit cmos_platform_remove(struct platform_device *pdev) 1242static int cmos_platform_remove(struct platform_device *pdev)
1242{ 1243{
1243 cmos_do_remove(&pdev->dev); 1244 cmos_do_remove(&pdev->dev);
1244 return 0; 1245 return 0;
@@ -1263,7 +1264,7 @@ static void cmos_platform_shutdown(struct platform_device *pdev)
1263MODULE_ALIAS("platform:rtc_cmos"); 1264MODULE_ALIAS("platform:rtc_cmos");
1264 1265
1265static struct platform_driver cmos_platform_driver = { 1266static struct platform_driver cmos_platform_driver = {
1266 .remove = __exit_p(cmos_platform_remove), 1267 .remove = cmos_platform_remove,
1267 .shutdown = cmos_platform_shutdown, 1268 .shutdown = cmos_platform_shutdown,
1268 .driver = { 1269 .driver = {
1269 .name = driver_name, 1270 .name = driver_name,
diff --git a/drivers/rtc/rtc-omap.c b/drivers/rtc/rtc-omap.c
index b04ea9b5ae67..51e52446eacb 100644
--- a/drivers/rtc/rtc-omap.c
+++ b/drivers/rtc/rtc-omap.c
@@ -113,6 +113,7 @@
113/* OMAP_RTC_OSC_REG bit fields: */ 113/* OMAP_RTC_OSC_REG bit fields: */
114#define OMAP_RTC_OSC_32KCLK_EN BIT(6) 114#define OMAP_RTC_OSC_32KCLK_EN BIT(6)
115#define OMAP_RTC_OSC_SEL_32KCLK_SRC BIT(3) 115#define OMAP_RTC_OSC_SEL_32KCLK_SRC BIT(3)
116#define OMAP_RTC_OSC_OSC32K_GZ_DISABLE BIT(4)
116 117
117/* OMAP_RTC_IRQWAKEEN bit fields: */ 118/* OMAP_RTC_IRQWAKEEN bit fields: */
118#define OMAP_RTC_IRQWAKEEN_ALARM_WAKEEN BIT(1) 119#define OMAP_RTC_IRQWAKEEN_ALARM_WAKEEN BIT(1)
@@ -146,6 +147,7 @@ struct omap_rtc {
146 u8 interrupts_reg; 147 u8 interrupts_reg;
147 bool is_pmic_controller; 148 bool is_pmic_controller;
148 bool has_ext_clk; 149 bool has_ext_clk;
150 bool is_suspending;
149 const struct omap_rtc_device_type *type; 151 const struct omap_rtc_device_type *type;
150 struct pinctrl_dev *pctldev; 152 struct pinctrl_dev *pctldev;
151}; 153};
@@ -786,8 +788,9 @@ static int omap_rtc_probe(struct platform_device *pdev)
786 */ 788 */
787 if (rtc->has_ext_clk) { 789 if (rtc->has_ext_clk) {
788 reg = rtc_read(rtc, OMAP_RTC_OSC_REG); 790 reg = rtc_read(rtc, OMAP_RTC_OSC_REG);
789 rtc_write(rtc, OMAP_RTC_OSC_REG, 791 reg &= ~OMAP_RTC_OSC_OSC32K_GZ_DISABLE;
790 reg | OMAP_RTC_OSC_SEL_32KCLK_SRC); 792 reg |= OMAP_RTC_OSC_32KCLK_EN | OMAP_RTC_OSC_SEL_32KCLK_SRC;
793 rtc_writel(rtc, OMAP_RTC_OSC_REG, reg);
791 } 794 }
792 795
793 rtc->type->lock(rtc); 796 rtc->type->lock(rtc);
@@ -898,8 +901,7 @@ static int omap_rtc_suspend(struct device *dev)
898 rtc_write(rtc, OMAP_RTC_INTERRUPTS_REG, 0); 901 rtc_write(rtc, OMAP_RTC_INTERRUPTS_REG, 0);
899 rtc->type->lock(rtc); 902 rtc->type->lock(rtc);
900 903
901 /* Disable the clock/module */ 904 rtc->is_suspending = true;
902 pm_runtime_put_sync(dev);
903 905
904 return 0; 906 return 0;
905} 907}
@@ -908,9 +910,6 @@ static int omap_rtc_resume(struct device *dev)
908{ 910{
909 struct omap_rtc *rtc = dev_get_drvdata(dev); 911 struct omap_rtc *rtc = dev_get_drvdata(dev);
910 912
911 /* Enable the clock/module so that we can access the registers */
912 pm_runtime_get_sync(dev);
913
914 rtc->type->unlock(rtc); 913 rtc->type->unlock(rtc);
915 if (device_may_wakeup(dev)) 914 if (device_may_wakeup(dev))
916 disable_irq_wake(rtc->irq_alarm); 915 disable_irq_wake(rtc->irq_alarm);
@@ -918,11 +917,34 @@ static int omap_rtc_resume(struct device *dev)
918 rtc_write(rtc, OMAP_RTC_INTERRUPTS_REG, rtc->interrupts_reg); 917 rtc_write(rtc, OMAP_RTC_INTERRUPTS_REG, rtc->interrupts_reg);
919 rtc->type->lock(rtc); 918 rtc->type->lock(rtc);
920 919
920 rtc->is_suspending = false;
921
921 return 0; 922 return 0;
922} 923}
923#endif 924#endif
924 925
925static SIMPLE_DEV_PM_OPS(omap_rtc_pm_ops, omap_rtc_suspend, omap_rtc_resume); 926#ifdef CONFIG_PM
927static int omap_rtc_runtime_suspend(struct device *dev)
928{
929 struct omap_rtc *rtc = dev_get_drvdata(dev);
930
931 if (rtc->is_suspending && !rtc->has_ext_clk)
932 return -EBUSY;
933
934 return 0;
935}
936
937static int omap_rtc_runtime_resume(struct device *dev)
938{
939 return 0;
940}
941#endif
942
943static const struct dev_pm_ops omap_rtc_pm_ops = {
944 SET_SYSTEM_SLEEP_PM_OPS(omap_rtc_suspend, omap_rtc_resume)
945 SET_RUNTIME_PM_OPS(omap_rtc_runtime_suspend,
946 omap_rtc_runtime_resume, NULL)
947};
926 948
927static void omap_rtc_shutdown(struct platform_device *pdev) 949static void omap_rtc_shutdown(struct platform_device *pdev)
928{ 950{
diff --git a/drivers/s390/block/dasd_eckd.c b/drivers/s390/block/dasd_eckd.c
index 831935af7389..a7a88476e215 100644
--- a/drivers/s390/block/dasd_eckd.c
+++ b/drivers/s390/block/dasd_eckd.c
@@ -1205,7 +1205,7 @@ static int verify_fcx_max_data(struct dasd_device *device, __u8 lpm)
1205 mdc, lpm); 1205 mdc, lpm);
1206 return mdc; 1206 return mdc;
1207 } 1207 }
1208 fcx_max_data = mdc * FCX_MAX_DATA_FACTOR; 1208 fcx_max_data = (u32)mdc * FCX_MAX_DATA_FACTOR;
1209 if (fcx_max_data < private->fcx_max_data) { 1209 if (fcx_max_data < private->fcx_max_data) {
1210 dev_warn(&device->cdev->dev, 1210 dev_warn(&device->cdev->dev,
1211 "The maximum data size for zHPF requests %u " 1211 "The maximum data size for zHPF requests %u "
@@ -1675,7 +1675,7 @@ static u32 get_fcx_max_data(struct dasd_device *device)
1675 " data size for zHPF requests failed\n"); 1675 " data size for zHPF requests failed\n");
1676 return 0; 1676 return 0;
1677 } else 1677 } else
1678 return mdc * FCX_MAX_DATA_FACTOR; 1678 return (u32)mdc * FCX_MAX_DATA_FACTOR;
1679} 1679}
1680 1680
1681/* 1681/*
diff --git a/drivers/s390/cio/chp.c b/drivers/s390/cio/chp.c
index 46be25c7461e..876c7e6e3a99 100644
--- a/drivers/s390/cio/chp.c
+++ b/drivers/s390/cio/chp.c
@@ -780,7 +780,7 @@ static int cfg_wait_idle(void)
780static int __init chp_init(void) 780static int __init chp_init(void)
781{ 781{
782 struct chp_id chpid; 782 struct chp_id chpid;
783 int ret; 783 int state, ret;
784 784
785 ret = crw_register_handler(CRW_RSC_CPATH, chp_process_crw); 785 ret = crw_register_handler(CRW_RSC_CPATH, chp_process_crw);
786 if (ret) 786 if (ret)
@@ -791,7 +791,9 @@ static int __init chp_init(void)
791 return 0; 791 return 0;
792 /* Register available channel-paths. */ 792 /* Register available channel-paths. */
793 chp_id_for_each(&chpid) { 793 chp_id_for_each(&chpid) {
794 if (chp_info_get_status(chpid) != CHP_STATUS_NOT_RECOGNIZED) 794 state = chp_info_get_status(chpid);
795 if (state == CHP_STATUS_CONFIGURED ||
796 state == CHP_STATUS_STANDBY)
795 chp_new(chpid); 797 chp_new(chpid);
796 } 798 }
797 799
diff --git a/drivers/s390/scsi/zfcp_dbf.c b/drivers/s390/scsi/zfcp_dbf.c
index 637cf8973c9e..581001989937 100644
--- a/drivers/s390/scsi/zfcp_dbf.c
+++ b/drivers/s390/scsi/zfcp_dbf.c
@@ -384,7 +384,7 @@ void zfcp_dbf_san(char *tag, struct zfcp_dbf *dbf,
384 /* if (len > rec_len): 384 /* if (len > rec_len):
385 * dump data up to cap_len ignoring small duplicate in rec->payload 385 * dump data up to cap_len ignoring small duplicate in rec->payload
386 */ 386 */
387 spin_lock_irqsave(&dbf->pay_lock, flags); 387 spin_lock(&dbf->pay_lock);
388 memset(payload, 0, sizeof(*payload)); 388 memset(payload, 0, sizeof(*payload));
389 memcpy(payload->area, paytag, ZFCP_DBF_TAG_LEN); 389 memcpy(payload->area, paytag, ZFCP_DBF_TAG_LEN);
390 payload->fsf_req_id = req_id; 390 payload->fsf_req_id = req_id;
diff --git a/drivers/scsi/NCR5380.c b/drivers/scsi/NCR5380.c
index db2739079cbb..790babc5ef66 100644
--- a/drivers/scsi/NCR5380.c
+++ b/drivers/scsi/NCR5380.c
@@ -353,7 +353,7 @@ static void NCR5380_print_phase(struct Scsi_Host *instance)
353#endif 353#endif
354 354
355 355
356static int probe_irq __initdata; 356static int probe_irq;
357 357
358/** 358/**
359 * probe_intr - helper for IRQ autoprobe 359 * probe_intr - helper for IRQ autoprobe
@@ -365,7 +365,7 @@ static int probe_irq __initdata;
365 * used by the IRQ probe code. 365 * used by the IRQ probe code.
366 */ 366 */
367 367
368static irqreturn_t __init probe_intr(int irq, void *dev_id) 368static irqreturn_t probe_intr(int irq, void *dev_id)
369{ 369{
370 probe_irq = irq; 370 probe_irq = irq;
371 return IRQ_HANDLED; 371 return IRQ_HANDLED;
@@ -380,7 +380,7 @@ static irqreturn_t __init probe_intr(int irq, void *dev_id)
380 * and then looking to see what interrupt actually turned up. 380 * and then looking to see what interrupt actually turned up.
381 */ 381 */
382 382
383static int __init __maybe_unused NCR5380_probe_irq(struct Scsi_Host *instance, 383static int __maybe_unused NCR5380_probe_irq(struct Scsi_Host *instance,
384 int possible) 384 int possible)
385{ 385{
386 struct NCR5380_hostdata *hostdata = shost_priv(instance); 386 struct NCR5380_hostdata *hostdata = shost_priv(instance);
diff --git a/drivers/scsi/arcmsr/arcmsr_hba.c b/drivers/scsi/arcmsr/arcmsr_hba.c
index 3d53d636b17b..f0cfb0451757 100644
--- a/drivers/scsi/arcmsr/arcmsr_hba.c
+++ b/drivers/scsi/arcmsr/arcmsr_hba.c
@@ -2636,18 +2636,9 @@ static int arcmsr_queue_command_lck(struct scsi_cmnd *cmd,
2636 struct AdapterControlBlock *acb = (struct AdapterControlBlock *) host->hostdata; 2636 struct AdapterControlBlock *acb = (struct AdapterControlBlock *) host->hostdata;
2637 struct CommandControlBlock *ccb; 2637 struct CommandControlBlock *ccb;
2638 int target = cmd->device->id; 2638 int target = cmd->device->id;
2639 int lun = cmd->device->lun;
2640 uint8_t scsicmd = cmd->cmnd[0];
2641 cmd->scsi_done = done; 2639 cmd->scsi_done = done;
2642 cmd->host_scribble = NULL; 2640 cmd->host_scribble = NULL;
2643 cmd->result = 0; 2641 cmd->result = 0;
2644 if ((scsicmd == SYNCHRONIZE_CACHE) ||(scsicmd == SEND_DIAGNOSTIC)){
2645 if(acb->devstate[target][lun] == ARECA_RAID_GONE) {
2646 cmd->result = (DID_NO_CONNECT << 16);
2647 }
2648 cmd->scsi_done(cmd);
2649 return 0;
2650 }
2651 if (target == 16) { 2642 if (target == 16) {
2652 /* virtual device for iop message transfer */ 2643 /* virtual device for iop message transfer */
2653 arcmsr_handle_virtual_command(acb, cmd); 2644 arcmsr_handle_virtual_command(acb, cmd);
diff --git a/drivers/scsi/be2iscsi/be_main.c b/drivers/scsi/be2iscsi/be_main.c
index 68138a647dfc..d9239c2d49b1 100644
--- a/drivers/scsi/be2iscsi/be_main.c
+++ b/drivers/scsi/be2iscsi/be_main.c
@@ -900,8 +900,9 @@ void hwi_ring_cq_db(struct beiscsi_hba *phba,
900static struct sgl_handle *alloc_io_sgl_handle(struct beiscsi_hba *phba) 900static struct sgl_handle *alloc_io_sgl_handle(struct beiscsi_hba *phba)
901{ 901{
902 struct sgl_handle *psgl_handle; 902 struct sgl_handle *psgl_handle;
903 unsigned long flags;
903 904
904 spin_lock_bh(&phba->io_sgl_lock); 905 spin_lock_irqsave(&phba->io_sgl_lock, flags);
905 if (phba->io_sgl_hndl_avbl) { 906 if (phba->io_sgl_hndl_avbl) {
906 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_IO, 907 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_IO,
907 "BM_%d : In alloc_io_sgl_handle," 908 "BM_%d : In alloc_io_sgl_handle,"
@@ -919,14 +920,16 @@ static struct sgl_handle *alloc_io_sgl_handle(struct beiscsi_hba *phba)
919 phba->io_sgl_alloc_index++; 920 phba->io_sgl_alloc_index++;
920 } else 921 } else
921 psgl_handle = NULL; 922 psgl_handle = NULL;
922 spin_unlock_bh(&phba->io_sgl_lock); 923 spin_unlock_irqrestore(&phba->io_sgl_lock, flags);
923 return psgl_handle; 924 return psgl_handle;
924} 925}
925 926
926static void 927static void
927free_io_sgl_handle(struct beiscsi_hba *phba, struct sgl_handle *psgl_handle) 928free_io_sgl_handle(struct beiscsi_hba *phba, struct sgl_handle *psgl_handle)
928{ 929{
929 spin_lock_bh(&phba->io_sgl_lock); 930 unsigned long flags;
931
932 spin_lock_irqsave(&phba->io_sgl_lock, flags);
930 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_IO, 933 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_IO,
931 "BM_%d : In free_,io_sgl_free_index=%d\n", 934 "BM_%d : In free_,io_sgl_free_index=%d\n",
932 phba->io_sgl_free_index); 935 phba->io_sgl_free_index);
@@ -941,7 +944,7 @@ free_io_sgl_handle(struct beiscsi_hba *phba, struct sgl_handle *psgl_handle)
941 "value there=%p\n", phba->io_sgl_free_index, 944 "value there=%p\n", phba->io_sgl_free_index,
942 phba->io_sgl_hndl_base 945 phba->io_sgl_hndl_base
943 [phba->io_sgl_free_index]); 946 [phba->io_sgl_free_index]);
944 spin_unlock_bh(&phba->io_sgl_lock); 947 spin_unlock_irqrestore(&phba->io_sgl_lock, flags);
945 return; 948 return;
946 } 949 }
947 phba->io_sgl_hndl_base[phba->io_sgl_free_index] = psgl_handle; 950 phba->io_sgl_hndl_base[phba->io_sgl_free_index] = psgl_handle;
@@ -950,7 +953,7 @@ free_io_sgl_handle(struct beiscsi_hba *phba, struct sgl_handle *psgl_handle)
950 phba->io_sgl_free_index = 0; 953 phba->io_sgl_free_index = 0;
951 else 954 else
952 phba->io_sgl_free_index++; 955 phba->io_sgl_free_index++;
953 spin_unlock_bh(&phba->io_sgl_lock); 956 spin_unlock_irqrestore(&phba->io_sgl_lock, flags);
954} 957}
955 958
956static inline struct wrb_handle * 959static inline struct wrb_handle *
@@ -958,15 +961,16 @@ beiscsi_get_wrb_handle(struct hwi_wrb_context *pwrb_context,
958 unsigned int wrbs_per_cxn) 961 unsigned int wrbs_per_cxn)
959{ 962{
960 struct wrb_handle *pwrb_handle; 963 struct wrb_handle *pwrb_handle;
964 unsigned long flags;
961 965
962 spin_lock_bh(&pwrb_context->wrb_lock); 966 spin_lock_irqsave(&pwrb_context->wrb_lock, flags);
963 pwrb_handle = pwrb_context->pwrb_handle_base[pwrb_context->alloc_index]; 967 pwrb_handle = pwrb_context->pwrb_handle_base[pwrb_context->alloc_index];
964 pwrb_context->wrb_handles_available--; 968 pwrb_context->wrb_handles_available--;
965 if (pwrb_context->alloc_index == (wrbs_per_cxn - 1)) 969 if (pwrb_context->alloc_index == (wrbs_per_cxn - 1))
966 pwrb_context->alloc_index = 0; 970 pwrb_context->alloc_index = 0;
967 else 971 else
968 pwrb_context->alloc_index++; 972 pwrb_context->alloc_index++;
969 spin_unlock_bh(&pwrb_context->wrb_lock); 973 spin_unlock_irqrestore(&pwrb_context->wrb_lock, flags);
970 974
971 if (pwrb_handle) 975 if (pwrb_handle)
972 memset(pwrb_handle->pwrb, 0, sizeof(*pwrb_handle->pwrb)); 976 memset(pwrb_handle->pwrb, 0, sizeof(*pwrb_handle->pwrb));
@@ -1001,14 +1005,16 @@ beiscsi_put_wrb_handle(struct hwi_wrb_context *pwrb_context,
1001 struct wrb_handle *pwrb_handle, 1005 struct wrb_handle *pwrb_handle,
1002 unsigned int wrbs_per_cxn) 1006 unsigned int wrbs_per_cxn)
1003{ 1007{
1004 spin_lock_bh(&pwrb_context->wrb_lock); 1008 unsigned long flags;
1009
1010 spin_lock_irqsave(&pwrb_context->wrb_lock, flags);
1005 pwrb_context->pwrb_handle_base[pwrb_context->free_index] = pwrb_handle; 1011 pwrb_context->pwrb_handle_base[pwrb_context->free_index] = pwrb_handle;
1006 pwrb_context->wrb_handles_available++; 1012 pwrb_context->wrb_handles_available++;
1007 if (pwrb_context->free_index == (wrbs_per_cxn - 1)) 1013 if (pwrb_context->free_index == (wrbs_per_cxn - 1))
1008 pwrb_context->free_index = 0; 1014 pwrb_context->free_index = 0;
1009 else 1015 else
1010 pwrb_context->free_index++; 1016 pwrb_context->free_index++;
1011 spin_unlock_bh(&pwrb_context->wrb_lock); 1017 spin_unlock_irqrestore(&pwrb_context->wrb_lock, flags);
1012} 1018}
1013 1019
1014/** 1020/**
@@ -1037,8 +1043,9 @@ free_wrb_handle(struct beiscsi_hba *phba, struct hwi_wrb_context *pwrb_context,
1037static struct sgl_handle *alloc_mgmt_sgl_handle(struct beiscsi_hba *phba) 1043static struct sgl_handle *alloc_mgmt_sgl_handle(struct beiscsi_hba *phba)
1038{ 1044{
1039 struct sgl_handle *psgl_handle; 1045 struct sgl_handle *psgl_handle;
1046 unsigned long flags;
1040 1047
1041 spin_lock_bh(&phba->mgmt_sgl_lock); 1048 spin_lock_irqsave(&phba->mgmt_sgl_lock, flags);
1042 if (phba->eh_sgl_hndl_avbl) { 1049 if (phba->eh_sgl_hndl_avbl) {
1043 psgl_handle = phba->eh_sgl_hndl_base[phba->eh_sgl_alloc_index]; 1050 psgl_handle = phba->eh_sgl_hndl_base[phba->eh_sgl_alloc_index];
1044 phba->eh_sgl_hndl_base[phba->eh_sgl_alloc_index] = NULL; 1051 phba->eh_sgl_hndl_base[phba->eh_sgl_alloc_index] = NULL;
@@ -1056,14 +1063,16 @@ static struct sgl_handle *alloc_mgmt_sgl_handle(struct beiscsi_hba *phba)
1056 phba->eh_sgl_alloc_index++; 1063 phba->eh_sgl_alloc_index++;
1057 } else 1064 } else
1058 psgl_handle = NULL; 1065 psgl_handle = NULL;
1059 spin_unlock_bh(&phba->mgmt_sgl_lock); 1066 spin_unlock_irqrestore(&phba->mgmt_sgl_lock, flags);
1060 return psgl_handle; 1067 return psgl_handle;
1061} 1068}
1062 1069
1063void 1070void
1064free_mgmt_sgl_handle(struct beiscsi_hba *phba, struct sgl_handle *psgl_handle) 1071free_mgmt_sgl_handle(struct beiscsi_hba *phba, struct sgl_handle *psgl_handle)
1065{ 1072{
1066 spin_lock_bh(&phba->mgmt_sgl_lock); 1073 unsigned long flags;
1074
1075 spin_lock_irqsave(&phba->mgmt_sgl_lock, flags);
1067 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG, 1076 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
1068 "BM_%d : In free_mgmt_sgl_handle," 1077 "BM_%d : In free_mgmt_sgl_handle,"
1069 "eh_sgl_free_index=%d\n", 1078 "eh_sgl_free_index=%d\n",
@@ -1078,7 +1087,7 @@ free_mgmt_sgl_handle(struct beiscsi_hba *phba, struct sgl_handle *psgl_handle)
1078 "BM_%d : Double Free in eh SGL ," 1087 "BM_%d : Double Free in eh SGL ,"
1079 "eh_sgl_free_index=%d\n", 1088 "eh_sgl_free_index=%d\n",
1080 phba->eh_sgl_free_index); 1089 phba->eh_sgl_free_index);
1081 spin_unlock_bh(&phba->mgmt_sgl_lock); 1090 spin_unlock_irqrestore(&phba->mgmt_sgl_lock, flags);
1082 return; 1091 return;
1083 } 1092 }
1084 phba->eh_sgl_hndl_base[phba->eh_sgl_free_index] = psgl_handle; 1093 phba->eh_sgl_hndl_base[phba->eh_sgl_free_index] = psgl_handle;
@@ -1088,7 +1097,7 @@ free_mgmt_sgl_handle(struct beiscsi_hba *phba, struct sgl_handle *psgl_handle)
1088 phba->eh_sgl_free_index = 0; 1097 phba->eh_sgl_free_index = 0;
1089 else 1098 else
1090 phba->eh_sgl_free_index++; 1099 phba->eh_sgl_free_index++;
1091 spin_unlock_bh(&phba->mgmt_sgl_lock); 1100 spin_unlock_irqrestore(&phba->mgmt_sgl_lock, flags);
1092} 1101}
1093 1102
1094static void 1103static void
diff --git a/drivers/scsi/be2iscsi/be_mgmt.c b/drivers/scsi/be2iscsi/be_mgmt.c
index aebc4ddb3060..ac05317bba7f 100644
--- a/drivers/scsi/be2iscsi/be_mgmt.c
+++ b/drivers/scsi/be2iscsi/be_mgmt.c
@@ -1083,7 +1083,7 @@ unsigned int beiscsi_boot_get_sinfo(struct beiscsi_hba *phba)
1083 nonemb_cmd = &phba->boot_struct.nonemb_cmd; 1083 nonemb_cmd = &phba->boot_struct.nonemb_cmd;
1084 nonemb_cmd->size = sizeof(*resp); 1084 nonemb_cmd->size = sizeof(*resp);
1085 nonemb_cmd->va = pci_alloc_consistent(phba->ctrl.pdev, 1085 nonemb_cmd->va = pci_alloc_consistent(phba->ctrl.pdev,
1086 sizeof(nonemb_cmd->size), 1086 nonemb_cmd->size,
1087 &nonemb_cmd->dma); 1087 &nonemb_cmd->dma);
1088 if (!nonemb_cmd->va) { 1088 if (!nonemb_cmd->va) {
1089 mutex_unlock(&ctrl->mbox_lock); 1089 mutex_unlock(&ctrl->mbox_lock);
diff --git a/drivers/scsi/cxgbi/libcxgbi.c b/drivers/scsi/cxgbi/libcxgbi.c
index d1421139e6ea..2ffe029ff2b6 100644
--- a/drivers/scsi/cxgbi/libcxgbi.c
+++ b/drivers/scsi/cxgbi/libcxgbi.c
@@ -2081,9 +2081,10 @@ void cxgbi_cleanup_task(struct iscsi_task *task)
2081 /* never reached the xmit task callout */ 2081 /* never reached the xmit task callout */
2082 if (tdata->skb) 2082 if (tdata->skb)
2083 __kfree_skb(tdata->skb); 2083 __kfree_skb(tdata->skb);
2084 memset(tdata, 0, sizeof(*tdata));
2085 2084
2086 task_release_itt(task, task->hdr_itt); 2085 task_release_itt(task, task->hdr_itt);
2086 memset(tdata, 0, sizeof(*tdata));
2087
2087 iscsi_tcp_cleanup_task(task); 2088 iscsi_tcp_cleanup_task(task);
2088} 2089}
2089EXPORT_SYMBOL_GPL(cxgbi_cleanup_task); 2090EXPORT_SYMBOL_GPL(cxgbi_cleanup_task);
diff --git a/drivers/scsi/device_handler/scsi_dh_alua.c b/drivers/scsi/device_handler/scsi_dh_alua.c
index 241829e59668..7bb20684e9fa 100644
--- a/drivers/scsi/device_handler/scsi_dh_alua.c
+++ b/drivers/scsi/device_handler/scsi_dh_alua.c
@@ -793,6 +793,7 @@ static void alua_rtpg_work(struct work_struct *work)
793 WARN_ON(pg->flags & ALUA_PG_RUN_RTPG); 793 WARN_ON(pg->flags & ALUA_PG_RUN_RTPG);
794 WARN_ON(pg->flags & ALUA_PG_RUN_STPG); 794 WARN_ON(pg->flags & ALUA_PG_RUN_STPG);
795 spin_unlock_irqrestore(&pg->lock, flags); 795 spin_unlock_irqrestore(&pg->lock, flags);
796 kref_put(&pg->kref, release_port_group);
796 return; 797 return;
797 } 798 }
798 if (pg->flags & ALUA_SYNC_STPG) 799 if (pg->flags & ALUA_SYNC_STPG)
@@ -890,6 +891,7 @@ static void alua_rtpg_queue(struct alua_port_group *pg,
890 /* Do not queue if the worker is already running */ 891 /* Do not queue if the worker is already running */
891 if (!(pg->flags & ALUA_PG_RUNNING)) { 892 if (!(pg->flags & ALUA_PG_RUNNING)) {
892 kref_get(&pg->kref); 893 kref_get(&pg->kref);
894 sdev = NULL;
893 start_queue = 1; 895 start_queue = 1;
894 } 896 }
895 } 897 }
@@ -901,7 +903,8 @@ static void alua_rtpg_queue(struct alua_port_group *pg,
901 if (start_queue && 903 if (start_queue &&
902 !queue_delayed_work(alua_wq, &pg->rtpg_work, 904 !queue_delayed_work(alua_wq, &pg->rtpg_work,
903 msecs_to_jiffies(ALUA_RTPG_DELAY_MSECS))) { 905 msecs_to_jiffies(ALUA_RTPG_DELAY_MSECS))) {
904 scsi_device_put(sdev); 906 if (sdev)
907 scsi_device_put(sdev);
905 kref_put(&pg->kref, release_port_group); 908 kref_put(&pg->kref, release_port_group);
906 } 909 }
907} 910}
diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
index d007ec18179a..a1d6ab76a514 100644
--- a/drivers/scsi/hpsa.c
+++ b/drivers/scsi/hpsa.c
@@ -2009,7 +2009,7 @@ static struct hpsa_scsi_dev_t *lookup_hpsa_scsi_dev(struct ctlr_info *h,
2009 2009
2010static int hpsa_slave_alloc(struct scsi_device *sdev) 2010static int hpsa_slave_alloc(struct scsi_device *sdev)
2011{ 2011{
2012 struct hpsa_scsi_dev_t *sd; 2012 struct hpsa_scsi_dev_t *sd = NULL;
2013 unsigned long flags; 2013 unsigned long flags;
2014 struct ctlr_info *h; 2014 struct ctlr_info *h;
2015 2015
@@ -2026,7 +2026,8 @@ static int hpsa_slave_alloc(struct scsi_device *sdev)
2026 sd->target = sdev_id(sdev); 2026 sd->target = sdev_id(sdev);
2027 sd->lun = sdev->lun; 2027 sd->lun = sdev->lun;
2028 } 2028 }
2029 } else 2029 }
2030 if (!sd)
2030 sd = lookup_hpsa_scsi_dev(h, sdev_channel(sdev), 2031 sd = lookup_hpsa_scsi_dev(h, sdev_channel(sdev),
2031 sdev_id(sdev), sdev->lun); 2032 sdev_id(sdev), sdev->lun);
2032 2033
@@ -3840,6 +3841,7 @@ static int hpsa_update_device_info(struct ctlr_info *h,
3840 sizeof(this_device->vendor)); 3841 sizeof(this_device->vendor));
3841 memcpy(this_device->model, &inq_buff[16], 3842 memcpy(this_device->model, &inq_buff[16],
3842 sizeof(this_device->model)); 3843 sizeof(this_device->model));
3844 this_device->rev = inq_buff[2];
3843 memset(this_device->device_id, 0, 3845 memset(this_device->device_id, 0,
3844 sizeof(this_device->device_id)); 3846 sizeof(this_device->device_id));
3845 if (hpsa_get_device_id(h, scsi3addr, this_device->device_id, 8, 3847 if (hpsa_get_device_id(h, scsi3addr, this_device->device_id, 8,
@@ -3929,10 +3931,14 @@ static void figure_bus_target_lun(struct ctlr_info *h,
3929 3931
3930 if (!is_logical_dev_addr_mode(lunaddrbytes)) { 3932 if (!is_logical_dev_addr_mode(lunaddrbytes)) {
3931 /* physical device, target and lun filled in later */ 3933 /* physical device, target and lun filled in later */
3932 if (is_hba_lunid(lunaddrbytes)) 3934 if (is_hba_lunid(lunaddrbytes)) {
3935 int bus = HPSA_HBA_BUS;
3936
3937 if (!device->rev)
3938 bus = HPSA_LEGACY_HBA_BUS;
3933 hpsa_set_bus_target_lun(device, 3939 hpsa_set_bus_target_lun(device,
3934 HPSA_HBA_BUS, 0, lunid & 0x3fff); 3940 bus, 0, lunid & 0x3fff);
3935 else 3941 } else
3936 /* defer target, lun assignment for physical devices */ 3942 /* defer target, lun assignment for physical devices */
3937 hpsa_set_bus_target_lun(device, 3943 hpsa_set_bus_target_lun(device,
3938 HPSA_PHYSICAL_DEVICE_BUS, -1, -1); 3944 HPSA_PHYSICAL_DEVICE_BUS, -1, -1);
diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
index 82cdfad874f3..9ea162de80dc 100644
--- a/drivers/scsi/hpsa.h
+++ b/drivers/scsi/hpsa.h
@@ -69,6 +69,7 @@ struct hpsa_scsi_dev_t {
69 u64 sas_address; 69 u64 sas_address;
70 unsigned char vendor[8]; /* bytes 8-15 of inquiry data */ 70 unsigned char vendor[8]; /* bytes 8-15 of inquiry data */
71 unsigned char model[16]; /* bytes 16-31 of inquiry data */ 71 unsigned char model[16]; /* bytes 16-31 of inquiry data */
72 unsigned char rev; /* byte 2 of inquiry data */
72 unsigned char raid_level; /* from inquiry page 0xC1 */ 73 unsigned char raid_level; /* from inquiry page 0xC1 */
73 unsigned char volume_offline; /* discovered via TUR or VPD */ 74 unsigned char volume_offline; /* discovered via TUR or VPD */
74 u16 queue_depth; /* max queue_depth for this device */ 75 u16 queue_depth; /* max queue_depth for this device */
@@ -402,6 +403,7 @@ struct offline_device_entry {
402#define HPSA_RAID_VOLUME_BUS 1 403#define HPSA_RAID_VOLUME_BUS 1
403#define HPSA_EXTERNAL_RAID_VOLUME_BUS 2 404#define HPSA_EXTERNAL_RAID_VOLUME_BUS 2
404#define HPSA_HBA_BUS 0 405#define HPSA_HBA_BUS 0
406#define HPSA_LEGACY_HBA_BUS 3
405 407
406/* 408/*
407 Send the command to the hardware 409 Send the command to the hardware
diff --git a/drivers/scsi/ipr.c b/drivers/scsi/ipr.c
index a8762a3efeef..532474109624 100644
--- a/drivers/scsi/ipr.c
+++ b/drivers/scsi/ipr.c
@@ -2586,7 +2586,6 @@ static void ipr_process_error(struct ipr_cmnd *ipr_cmd)
2586 struct ipr_hostrcb *hostrcb = ipr_cmd->u.hostrcb; 2586 struct ipr_hostrcb *hostrcb = ipr_cmd->u.hostrcb;
2587 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc); 2587 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
2588 u32 fd_ioasc; 2588 u32 fd_ioasc;
2589 char *envp[] = { "ASYNC_ERR_LOG=1", NULL };
2590 2589
2591 if (ioa_cfg->sis64) 2590 if (ioa_cfg->sis64)
2592 fd_ioasc = be32_to_cpu(hostrcb->hcam.u.error64.fd_ioasc); 2591 fd_ioasc = be32_to_cpu(hostrcb->hcam.u.error64.fd_ioasc);
@@ -2607,8 +2606,8 @@ static void ipr_process_error(struct ipr_cmnd *ipr_cmd)
2607 } 2606 }
2608 2607
2609 list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_report_q); 2608 list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_report_q);
2609 schedule_work(&ioa_cfg->work_q);
2610 hostrcb = ipr_get_free_hostrcb(ioa_cfg); 2610 hostrcb = ipr_get_free_hostrcb(ioa_cfg);
2611 kobject_uevent_env(&ioa_cfg->host->shost_dev.kobj, KOBJ_CHANGE, envp);
2612 2611
2613 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_LOG_DATA, hostrcb); 2612 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_LOG_DATA, hostrcb);
2614} 2613}
diff --git a/drivers/scsi/libfc/fc_lport.c b/drivers/scsi/libfc/fc_lport.c
index 04ce7cfb6d1b..50c71678a156 100644
--- a/drivers/scsi/libfc/fc_lport.c
+++ b/drivers/scsi/libfc/fc_lport.c
@@ -308,7 +308,7 @@ struct fc_host_statistics *fc_get_host_stats(struct Scsi_Host *shost)
308 fc_stats = &lport->host_stats; 308 fc_stats = &lport->host_stats;
309 memset(fc_stats, 0, sizeof(struct fc_host_statistics)); 309 memset(fc_stats, 0, sizeof(struct fc_host_statistics));
310 310
311 fc_stats->seconds_since_last_reset = (lport->boot_time - jiffies) / HZ; 311 fc_stats->seconds_since_last_reset = (jiffies - lport->boot_time) / HZ;
312 312
313 for_each_possible_cpu(cpu) { 313 for_each_possible_cpu(cpu) {
314 struct fc_stats *stats; 314 struct fc_stats *stats;
diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c
index c051694bfcb0..f9b6fba689ff 100644
--- a/drivers/scsi/libiscsi.c
+++ b/drivers/scsi/libiscsi.c
@@ -791,9 +791,9 @@ __iscsi_conn_send_pdu(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
791 791
792free_task: 792free_task:
793 /* regular RX path uses back_lock */ 793 /* regular RX path uses back_lock */
794 spin_lock_bh(&session->back_lock); 794 spin_lock(&session->back_lock);
795 __iscsi_put_task(task); 795 __iscsi_put_task(task);
796 spin_unlock_bh(&session->back_lock); 796 spin_unlock(&session->back_lock);
797 return NULL; 797 return NULL;
798} 798}
799 799
diff --git a/drivers/scsi/lpfc/lpfc_sli.c b/drivers/scsi/lpfc/lpfc_sli.c
index c5326055beee..f4f77c5b0c83 100644
--- a/drivers/scsi/lpfc/lpfc_sli.c
+++ b/drivers/scsi/lpfc/lpfc_sli.c
@@ -1323,18 +1323,20 @@ lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
1323{ 1323{
1324 lockdep_assert_held(&phba->hbalock); 1324 lockdep_assert_held(&phba->hbalock);
1325 1325
1326 BUG_ON(!piocb || !piocb->vport); 1326 BUG_ON(!piocb);
1327 1327
1328 list_add_tail(&piocb->list, &pring->txcmplq); 1328 list_add_tail(&piocb->list, &pring->txcmplq);
1329 piocb->iocb_flag |= LPFC_IO_ON_TXCMPLQ; 1329 piocb->iocb_flag |= LPFC_IO_ON_TXCMPLQ;
1330 1330
1331 if ((unlikely(pring->ringno == LPFC_ELS_RING)) && 1331 if ((unlikely(pring->ringno == LPFC_ELS_RING)) &&
1332 (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && 1332 (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
1333 (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN) && 1333 (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
1334 (!(piocb->vport->load_flag & FC_UNLOADING))) 1334 BUG_ON(!piocb->vport);
1335 mod_timer(&piocb->vport->els_tmofunc, 1335 if (!(piocb->vport->load_flag & FC_UNLOADING))
1336 jiffies + 1336 mod_timer(&piocb->vport->els_tmofunc,
1337 msecs_to_jiffies(1000 * (phba->fc_ratov << 1))); 1337 jiffies +
1338 msecs_to_jiffies(1000 * (phba->fc_ratov << 1)));
1339 }
1338 1340
1339 return 0; 1341 return 0;
1340} 1342}
diff --git a/drivers/scsi/megaraid/megaraid_sas.h b/drivers/scsi/megaraid/megaraid_sas.h
index ca86c885dfaa..3aaea713bf37 100644
--- a/drivers/scsi/megaraid/megaraid_sas.h
+++ b/drivers/scsi/megaraid/megaraid_sas.h
@@ -2233,7 +2233,7 @@ struct megasas_instance_template {
2233}; 2233};
2234 2234
2235#define MEGASAS_IS_LOGICAL(scp) \ 2235#define MEGASAS_IS_LOGICAL(scp) \
2236 (scp->device->channel < MEGASAS_MAX_PD_CHANNELS) ? 0 : 1 2236 ((scp->device->channel < MEGASAS_MAX_PD_CHANNELS) ? 0 : 1)
2237 2237
2238#define MEGASAS_DEV_INDEX(scp) \ 2238#define MEGASAS_DEV_INDEX(scp) \
2239 (((scp->device->channel % 2) * MEGASAS_MAX_DEV_PER_CHANNEL) + \ 2239 (((scp->device->channel % 2) * MEGASAS_MAX_DEV_PER_CHANNEL) + \
diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megaraid/megaraid_sas_base.c
index 9ff57dee72d7..d8b1fbd4c8aa 100644
--- a/drivers/scsi/megaraid/megaraid_sas_base.c
+++ b/drivers/scsi/megaraid/megaraid_sas_base.c
@@ -1700,16 +1700,13 @@ megasas_queue_command(struct Scsi_Host *shost, struct scsi_cmnd *scmd)
1700 goto out_done; 1700 goto out_done;
1701 } 1701 }
1702 1702
1703 switch (scmd->cmnd[0]) { 1703 /*
1704 case SYNCHRONIZE_CACHE: 1704 * FW takes care of flush cache on its own for Virtual Disk.
1705 /* 1705 * No need to send it down for VD. For JBOD send SYNCHRONIZE_CACHE to FW.
1706 * FW takes care of flush cache on its own 1706 */
1707 * No need to send it down 1707 if ((scmd->cmnd[0] == SYNCHRONIZE_CACHE) && MEGASAS_IS_LOGICAL(scmd)) {
1708 */
1709 scmd->result = DID_OK << 16; 1708 scmd->result = DID_OK << 16;
1710 goto out_done; 1709 goto out_done;
1711 default:
1712 break;
1713 } 1710 }
1714 1711
1715 return instance->instancet->build_and_issue_cmd(instance, scmd); 1712 return instance->instancet->build_and_issue_cmd(instance, scmd);
diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
index 209a969a979d..1c4744e78173 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
@@ -1273,9 +1273,9 @@ scsih_target_alloc(struct scsi_target *starget)
1273 sas_target_priv_data->handle = raid_device->handle; 1273 sas_target_priv_data->handle = raid_device->handle;
1274 sas_target_priv_data->sas_address = raid_device->wwid; 1274 sas_target_priv_data->sas_address = raid_device->wwid;
1275 sas_target_priv_data->flags |= MPT_TARGET_FLAGS_VOLUME; 1275 sas_target_priv_data->flags |= MPT_TARGET_FLAGS_VOLUME;
1276 sas_target_priv_data->raid_device = raid_device;
1277 if (ioc->is_warpdrive) 1276 if (ioc->is_warpdrive)
1278 raid_device->starget = starget; 1277 sas_target_priv_data->raid_device = raid_device;
1278 raid_device->starget = starget;
1279 } 1279 }
1280 spin_unlock_irqrestore(&ioc->raid_device_lock, flags); 1280 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1281 return 0; 1281 return 0;
@@ -3885,6 +3885,11 @@ _scsih_temp_threshold_events(struct MPT3SAS_ADAPTER *ioc,
3885 } 3885 }
3886} 3886}
3887 3887
3888static inline bool ata_12_16_cmd(struct scsi_cmnd *scmd)
3889{
3890 return (scmd->cmnd[0] == ATA_12 || scmd->cmnd[0] == ATA_16);
3891}
3892
3888/** 3893/**
3889 * _scsih_flush_running_cmds - completing outstanding commands. 3894 * _scsih_flush_running_cmds - completing outstanding commands.
3890 * @ioc: per adapter object 3895 * @ioc: per adapter object
@@ -3906,6 +3911,9 @@ _scsih_flush_running_cmds(struct MPT3SAS_ADAPTER *ioc)
3906 if (!scmd) 3911 if (!scmd)
3907 continue; 3912 continue;
3908 count++; 3913 count++;
3914 if (ata_12_16_cmd(scmd))
3915 scsi_internal_device_unblock(scmd->device,
3916 SDEV_RUNNING);
3909 mpt3sas_base_free_smid(ioc, smid); 3917 mpt3sas_base_free_smid(ioc, smid);
3910 scsi_dma_unmap(scmd); 3918 scsi_dma_unmap(scmd);
3911 if (ioc->pci_error_recovery) 3919 if (ioc->pci_error_recovery)
@@ -4010,8 +4018,6 @@ _scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status)
4010 SAM_STAT_CHECK_CONDITION; 4018 SAM_STAT_CHECK_CONDITION;
4011} 4019}
4012 4020
4013
4014
4015/** 4021/**
4016 * scsih_qcmd - main scsi request entry point 4022 * scsih_qcmd - main scsi request entry point
4017 * @scmd: pointer to scsi command object 4023 * @scmd: pointer to scsi command object
@@ -4038,6 +4044,13 @@ scsih_qcmd(struct Scsi_Host *shost, struct scsi_cmnd *scmd)
4038 if (ioc->logging_level & MPT_DEBUG_SCSI) 4044 if (ioc->logging_level & MPT_DEBUG_SCSI)
4039 scsi_print_command(scmd); 4045 scsi_print_command(scmd);
4040 4046
4047 /*
4048 * Lock the device for any subsequent command until command is
4049 * done.
4050 */
4051 if (ata_12_16_cmd(scmd))
4052 scsi_internal_device_block(scmd->device);
4053
4041 sas_device_priv_data = scmd->device->hostdata; 4054 sas_device_priv_data = scmd->device->hostdata;
4042 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { 4055 if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
4043 scmd->result = DID_NO_CONNECT << 16; 4056 scmd->result = DID_NO_CONNECT << 16;
@@ -4613,6 +4626,9 @@ _scsih_io_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
4613 if (scmd == NULL) 4626 if (scmd == NULL)
4614 return 1; 4627 return 1;
4615 4628
4629 if (ata_12_16_cmd(scmd))
4630 scsi_internal_device_unblock(scmd->device, SDEV_RUNNING);
4631
4616 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); 4632 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
4617 4633
4618 if (mpi_reply == NULL) { 4634 if (mpi_reply == NULL) {
diff --git a/drivers/scsi/mvsas/mv_sas.c b/drivers/scsi/mvsas/mv_sas.c
index 86eb19902bac..c7cc8035eacb 100644
--- a/drivers/scsi/mvsas/mv_sas.c
+++ b/drivers/scsi/mvsas/mv_sas.c
@@ -791,8 +791,10 @@ static int mvs_task_prep(struct sas_task *task, struct mvs_info *mvi, int is_tmf
791 slot->slot_tag = tag; 791 slot->slot_tag = tag;
792 792
793 slot->buf = pci_pool_alloc(mvi->dma_pool, GFP_ATOMIC, &slot->buf_dma); 793 slot->buf = pci_pool_alloc(mvi->dma_pool, GFP_ATOMIC, &slot->buf_dma);
794 if (!slot->buf) 794 if (!slot->buf) {
795 rc = -ENOMEM;
795 goto err_out_tag; 796 goto err_out_tag;
797 }
796 memset(slot->buf, 0, MVS_SLOT_BUF_SZ); 798 memset(slot->buf, 0, MVS_SLOT_BUF_SZ);
797 799
798 tei.task = task; 800 tei.task = task;
diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
index ace65db1d2a2..56d6142852a5 100644
--- a/drivers/scsi/qla2xxx/qla_os.c
+++ b/drivers/scsi/qla2xxx/qla_os.c
@@ -707,6 +707,11 @@ qla2xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
707 srb_t *sp; 707 srb_t *sp;
708 int rval; 708 int rval;
709 709
710 if (unlikely(test_bit(UNLOADING, &base_vha->dpc_flags))) {
711 cmd->result = DID_NO_CONNECT << 16;
712 goto qc24_fail_command;
713 }
714
710 if (ha->flags.eeh_busy) { 715 if (ha->flags.eeh_busy) {
711 if (ha->flags.pci_channel_io_perm_failure) { 716 if (ha->flags.pci_channel_io_perm_failure) {
712 ql_dbg(ql_dbg_aer, vha, 0x9010, 717 ql_dbg(ql_dbg_aer, vha, 0x9010,
@@ -1451,6 +1456,20 @@ qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
1451 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) { 1456 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) {
1452 sp = req->outstanding_cmds[cnt]; 1457 sp = req->outstanding_cmds[cnt];
1453 if (sp) { 1458 if (sp) {
1459 /* Don't abort commands in adapter during EEH
1460 * recovery as it's not accessible/responding.
1461 */
1462 if (!ha->flags.eeh_busy) {
1463 /* Get a reference to the sp and drop the lock.
1464 * The reference ensures this sp->done() call
1465 * - and not the call in qla2xxx_eh_abort() -
1466 * ends the SCSI command (with result 'res').
1467 */
1468 sp_get(sp);
1469 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1470 qla2xxx_eh_abort(GET_CMD_SP(sp));
1471 spin_lock_irqsave(&ha->hardware_lock, flags);
1472 }
1454 req->outstanding_cmds[cnt] = NULL; 1473 req->outstanding_cmds[cnt] = NULL;
1455 sp->done(vha, sp, res); 1474 sp->done(vha, sp, res);
1456 } 1475 }
@@ -2341,6 +2360,8 @@ qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
2341{ 2360{
2342 scsi_qla_host_t *vha = shost_priv(shost); 2361 scsi_qla_host_t *vha = shost_priv(shost);
2343 2362
2363 if (test_bit(UNLOADING, &vha->dpc_flags))
2364 return 1;
2344 if (!vha->host) 2365 if (!vha->host)
2345 return 1; 2366 return 1;
2346 if (time > vha->hw->loop_reset_delay * HZ) 2367 if (time > vha->hw->loop_reset_delay * HZ)
diff --git a/drivers/scsi/qlogicpti.h b/drivers/scsi/qlogicpti.h
index 4377e87ee79c..892a0b058b99 100644
--- a/drivers/scsi/qlogicpti.h
+++ b/drivers/scsi/qlogicpti.h
@@ -356,8 +356,8 @@ struct qlogicpti {
356 356
357 /* The rest of the elements are unimportant for performance. */ 357 /* The rest of the elements are unimportant for performance. */
358 struct qlogicpti *next; 358 struct qlogicpti *next;
359 __u32 res_dvma; /* Ptr to RESPONSE bufs (DVMA)*/ 359 dma_addr_t res_dvma; /* Ptr to RESPONSE bufs (DVMA)*/
360 __u32 req_dvma; /* Ptr to REQUEST bufs (DVMA) */ 360 dma_addr_t req_dvma; /* Ptr to REQUEST bufs (DVMA) */
361 u_char fware_majrev, fware_minrev, fware_micrev; 361 u_char fware_majrev, fware_minrev, fware_micrev;
362 struct Scsi_Host *qhost; 362 struct Scsi_Host *qhost;
363 int qpti_id; 363 int qpti_id;
diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
index c905709707f0..cf04a364fd8b 100644
--- a/drivers/scsi/scsi_debug.c
+++ b/drivers/scsi/scsi_debug.c
@@ -5134,6 +5134,7 @@ static void __exit scsi_debug_exit(void)
5134 bus_unregister(&pseudo_lld_bus); 5134 bus_unregister(&pseudo_lld_bus);
5135 root_device_unregister(pseudo_primary); 5135 root_device_unregister(pseudo_primary);
5136 5136
5137 vfree(map_storep);
5137 vfree(dif_storep); 5138 vfree(dif_storep);
5138 vfree(fake_storep); 5139 vfree(fake_storep);
5139 kfree(sdebug_q_arr); 5140 kfree(sdebug_q_arr);
diff --git a/drivers/scsi/scsi_dh.c b/drivers/scsi/scsi_dh.c
index 54d446c9f56e..b8d3b97b217a 100644
--- a/drivers/scsi/scsi_dh.c
+++ b/drivers/scsi/scsi_dh.c
@@ -36,9 +36,9 @@ struct scsi_dh_blist {
36}; 36};
37 37
38static const struct scsi_dh_blist scsi_dh_blist[] = { 38static const struct scsi_dh_blist scsi_dh_blist[] = {
39 {"DGC", "RAID", "clariion" }, 39 {"DGC", "RAID", "emc" },
40 {"DGC", "DISK", "clariion" }, 40 {"DGC", "DISK", "emc" },
41 {"DGC", "VRAID", "clariion" }, 41 {"DGC", "VRAID", "emc" },
42 42
43 {"COMPAQ", "MSA1000 VOLUME", "hp_sw" }, 43 {"COMPAQ", "MSA1000 VOLUME", "hp_sw" },
44 {"COMPAQ", "HSV110", "hp_sw" }, 44 {"COMPAQ", "HSV110", "hp_sw" },
diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c
index 212e98d940bc..6f7128f49c30 100644
--- a/drivers/scsi/scsi_scan.c
+++ b/drivers/scsi/scsi_scan.c
@@ -1307,7 +1307,6 @@ static void scsi_sequential_lun_scan(struct scsi_target *starget,
1307static int scsi_report_lun_scan(struct scsi_target *starget, int bflags, 1307static int scsi_report_lun_scan(struct scsi_target *starget, int bflags,
1308 enum scsi_scan_mode rescan) 1308 enum scsi_scan_mode rescan)
1309{ 1309{
1310 char devname[64];
1311 unsigned char scsi_cmd[MAX_COMMAND_SIZE]; 1310 unsigned char scsi_cmd[MAX_COMMAND_SIZE];
1312 unsigned int length; 1311 unsigned int length;
1313 u64 lun; 1312 u64 lun;
@@ -1349,9 +1348,6 @@ static int scsi_report_lun_scan(struct scsi_target *starget, int bflags,
1349 } 1348 }
1350 } 1349 }
1351 1350
1352 sprintf(devname, "host %d channel %d id %d",
1353 shost->host_no, sdev->channel, sdev->id);
1354
1355 /* 1351 /*
1356 * Allocate enough to hold the header (the same size as one scsi_lun) 1352 * Allocate enough to hold the header (the same size as one scsi_lun)
1357 * plus the number of luns we are requesting. 511 was the default 1353 * plus the number of luns we are requesting. 511 was the default
@@ -1470,12 +1466,12 @@ retry:
1470 out_err: 1466 out_err:
1471 kfree(lun_data); 1467 kfree(lun_data);
1472 out: 1468 out:
1473 scsi_device_put(sdev);
1474 if (scsi_device_created(sdev)) 1469 if (scsi_device_created(sdev))
1475 /* 1470 /*
1476 * the sdev we used didn't appear in the report luns scan 1471 * the sdev we used didn't appear in the report luns scan
1477 */ 1472 */
1478 __scsi_remove_device(sdev); 1473 __scsi_remove_device(sdev);
1474 scsi_device_put(sdev);
1479 return ret; 1475 return ret;
1480} 1476}
1481 1477
diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c
index 7af5226aa55b..618422ea3a41 100644
--- a/drivers/scsi/st.c
+++ b/drivers/scsi/st.c
@@ -4922,9 +4922,8 @@ static int sgl_map_user_pages(struct st_buffer *STbp,
4922 res = get_user_pages_unlocked( 4922 res = get_user_pages_unlocked(
4923 uaddr, 4923 uaddr,
4924 nr_pages, 4924 nr_pages,
4925 rw == READ, 4925 pages,
4926 0, /* don't force */ 4926 rw == READ ? FOLL_WRITE : 0); /* don't force */
4927 pages);
4928 4927
4929 /* Errors and no page mapped should return here */ 4928 /* Errors and no page mapped should return here */
4930 if (res < nr_pages) 4929 if (res < nr_pages)
diff --git a/drivers/scsi/vmw_pvscsi.c b/drivers/scsi/vmw_pvscsi.c
index 4a0d3cdc607c..15ca09cd16f3 100644
--- a/drivers/scsi/vmw_pvscsi.c
+++ b/drivers/scsi/vmw_pvscsi.c
@@ -793,6 +793,7 @@ static int pvscsi_abort(struct scsi_cmnd *cmd)
793 unsigned long flags; 793 unsigned long flags;
794 int result = SUCCESS; 794 int result = SUCCESS;
795 DECLARE_COMPLETION_ONSTACK(abort_cmp); 795 DECLARE_COMPLETION_ONSTACK(abort_cmp);
796 int done;
796 797
797 scmd_printk(KERN_DEBUG, cmd, "task abort on host %u, %p\n", 798 scmd_printk(KERN_DEBUG, cmd, "task abort on host %u, %p\n",
798 adapter->host->host_no, cmd); 799 adapter->host->host_no, cmd);
@@ -824,10 +825,10 @@ static int pvscsi_abort(struct scsi_cmnd *cmd)
824 pvscsi_abort_cmd(adapter, ctx); 825 pvscsi_abort_cmd(adapter, ctx);
825 spin_unlock_irqrestore(&adapter->hw_lock, flags); 826 spin_unlock_irqrestore(&adapter->hw_lock, flags);
826 /* Wait for 2 secs for the completion. */ 827 /* Wait for 2 secs for the completion. */
827 wait_for_completion_timeout(&abort_cmp, msecs_to_jiffies(2000)); 828 done = wait_for_completion_timeout(&abort_cmp, msecs_to_jiffies(2000));
828 spin_lock_irqsave(&adapter->hw_lock, flags); 829 spin_lock_irqsave(&adapter->hw_lock, flags);
829 830
830 if (!completion_done(&abort_cmp)) { 831 if (!done) {
831 /* 832 /*
832 * Failed to abort the command, unmark the fact that it 833 * Failed to abort the command, unmark the fact that it
833 * was requested to be aborted. 834 * was requested to be aborted.
diff --git a/drivers/scsi/vmw_pvscsi.h b/drivers/scsi/vmw_pvscsi.h
index c097d2ccbde3..d41292ef85f2 100644
--- a/drivers/scsi/vmw_pvscsi.h
+++ b/drivers/scsi/vmw_pvscsi.h
@@ -26,7 +26,7 @@
26 26
27#include <linux/types.h> 27#include <linux/types.h>
28 28
29#define PVSCSI_DRIVER_VERSION_STRING "1.0.6.0-k" 29#define PVSCSI_DRIVER_VERSION_STRING "1.0.7.0-k"
30 30
31#define PVSCSI_MAX_NUM_SG_ENTRIES_PER_SEGMENT 128 31#define PVSCSI_MAX_NUM_SG_ENTRIES_PER_SEGMENT 128
32 32
diff --git a/drivers/spi/spi-fsl-dspi.c b/drivers/spi/spi-fsl-dspi.c
index 35c0dd945668..a67b0ff6a362 100644
--- a/drivers/spi/spi-fsl-dspi.c
+++ b/drivers/spi/spi-fsl-dspi.c
@@ -70,6 +70,7 @@
70#define SPI_SR 0x2c 70#define SPI_SR 0x2c
71#define SPI_SR_EOQF 0x10000000 71#define SPI_SR_EOQF 0x10000000
72#define SPI_SR_TCFQF 0x80000000 72#define SPI_SR_TCFQF 0x80000000
73#define SPI_SR_CLEAR 0xdaad0000
73 74
74#define SPI_RSER 0x30 75#define SPI_RSER 0x30
75#define SPI_RSER_EOQFE 0x10000000 76#define SPI_RSER_EOQFE 0x10000000
@@ -646,6 +647,11 @@ static const struct regmap_config dspi_regmap_config = {
646 .max_register = 0x88, 647 .max_register = 0x88,
647}; 648};
648 649
650static void dspi_init(struct fsl_dspi *dspi)
651{
652 regmap_write(dspi->regmap, SPI_SR, SPI_SR_CLEAR);
653}
654
649static int dspi_probe(struct platform_device *pdev) 655static int dspi_probe(struct platform_device *pdev)
650{ 656{
651 struct device_node *np = pdev->dev.of_node; 657 struct device_node *np = pdev->dev.of_node;
@@ -709,6 +715,7 @@ static int dspi_probe(struct platform_device *pdev)
709 return PTR_ERR(dspi->regmap); 715 return PTR_ERR(dspi->regmap);
710 } 716 }
711 717
718 dspi_init(dspi);
712 dspi->irq = platform_get_irq(pdev, 0); 719 dspi->irq = platform_get_irq(pdev, 0);
713 if (dspi->irq < 0) { 720 if (dspi->irq < 0) {
714 dev_err(&pdev->dev, "can't get platform irq\n"); 721 dev_err(&pdev->dev, "can't get platform irq\n");
diff --git a/drivers/spi/spi-fsl-espi.c b/drivers/spi/spi-fsl-espi.c
index 7451585a080e..2c175b9495f7 100644
--- a/drivers/spi/spi-fsl-espi.c
+++ b/drivers/spi/spi-fsl-espi.c
@@ -458,7 +458,7 @@ static void fsl_espi_cpu_irq(struct mpc8xxx_spi *mspi, u32 events)
458 458
459 mspi->len -= rx_nr_bytes; 459 mspi->len -= rx_nr_bytes;
460 460
461 if (mspi->rx) 461 if (rx_nr_bytes && mspi->rx)
462 mspi->get_rx(rx_data, mspi); 462 mspi->get_rx(rx_data, mspi);
463 } 463 }
464 464
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 5787b723b593..838783c3fed0 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -1618,9 +1618,11 @@ static void of_register_spi_devices(struct spi_master *master)
1618 if (of_node_test_and_set_flag(nc, OF_POPULATED)) 1618 if (of_node_test_and_set_flag(nc, OF_POPULATED))
1619 continue; 1619 continue;
1620 spi = of_register_spi_device(master, nc); 1620 spi = of_register_spi_device(master, nc);
1621 if (IS_ERR(spi)) 1621 if (IS_ERR(spi)) {
1622 dev_warn(&master->dev, "Failed to create SPI device for %s\n", 1622 dev_warn(&master->dev, "Failed to create SPI device for %s\n",
1623 nc->full_name); 1623 nc->full_name);
1624 of_node_clear_flag(nc, OF_POPULATED);
1625 }
1624 } 1626 }
1625} 1627}
1626#else 1628#else
@@ -3131,6 +3133,7 @@ static int of_spi_notify(struct notifier_block *nb, unsigned long action,
3131 if (IS_ERR(spi)) { 3133 if (IS_ERR(spi)) {
3132 pr_err("%s: failed to create for '%s'\n", 3134 pr_err("%s: failed to create for '%s'\n",
3133 __func__, rd->dn->full_name); 3135 __func__, rd->dn->full_name);
3136 of_node_clear_flag(rd->dn, OF_POPULATED);
3134 return notifier_from_errno(PTR_ERR(spi)); 3137 return notifier_from_errno(PTR_ERR(spi));
3135 } 3138 }
3136 break; 3139 break;
diff --git a/drivers/staging/android/ion/ion.c b/drivers/staging/android/ion/ion.c
index 396ded52ab70..209a8f7ef02b 100644
--- a/drivers/staging/android/ion/ion.c
+++ b/drivers/staging/android/ion/ion.c
@@ -1187,8 +1187,10 @@ int ion_query_heaps(struct ion_client *client, struct ion_heap_query *query)
1187 hdata.type = heap->type; 1187 hdata.type = heap->type;
1188 hdata.heap_id = heap->id; 1188 hdata.heap_id = heap->id;
1189 1189
1190 ret = copy_to_user(&buffer[cnt], 1190 if (copy_to_user(&buffer[cnt], &hdata, sizeof(hdata))) {
1191 &hdata, sizeof(hdata)); 1191 ret = -EFAULT;
1192 goto out;
1193 }
1192 1194
1193 cnt++; 1195 cnt++;
1194 if (cnt >= max_cnt) 1196 if (cnt >= max_cnt)
diff --git a/drivers/staging/android/ion/ion_of.c b/drivers/staging/android/ion/ion_of.c
index 15bac92b7f04..46b2bb99bfd6 100644
--- a/drivers/staging/android/ion/ion_of.c
+++ b/drivers/staging/android/ion/ion_of.c
@@ -107,7 +107,7 @@ struct ion_platform_data *ion_parse_dt(struct platform_device *pdev,
107 107
108 heap_pdev = of_platform_device_create(node, heaps[i].name, 108 heap_pdev = of_platform_device_create(node, heaps[i].name,
109 &pdev->dev); 109 &pdev->dev);
110 if (!pdev) 110 if (!heap_pdev)
111 return ERR_PTR(-ENOMEM); 111 return ERR_PTR(-ENOMEM);
112 heap_pdev->dev.platform_data = &heaps[i]; 112 heap_pdev->dev.platform_data = &heaps[i];
113 113
diff --git a/drivers/staging/comedi/drivers/ni_tio.c b/drivers/staging/comedi/drivers/ni_tio.c
index 7043eb0543f6..5ab49a798164 100644
--- a/drivers/staging/comedi/drivers/ni_tio.c
+++ b/drivers/staging/comedi/drivers/ni_tio.c
@@ -207,7 +207,8 @@ static int ni_tio_clock_period_ps(const struct ni_gpct *counter,
207 * clock period is specified by user with prescaling 207 * clock period is specified by user with prescaling
208 * already taken into account. 208 * already taken into account.
209 */ 209 */
210 return counter->clock_period_ps; 210 *period_ps = counter->clock_period_ps;
211 return 0;
211 } 212 }
212 213
213 switch (generic_clock_source & NI_GPCT_PRESCALE_MODE_CLOCK_SRC_MASK) { 214 switch (generic_clock_source & NI_GPCT_PRESCALE_MODE_CLOCK_SRC_MASK) {
diff --git a/drivers/staging/greybus/arche-platform.c b/drivers/staging/greybus/arche-platform.c
index e36ee984485b..d33d6fe078ad 100644
--- a/drivers/staging/greybus/arche-platform.c
+++ b/drivers/staging/greybus/arche-platform.c
@@ -128,6 +128,7 @@ int arche_platform_change_state(enum arche_platform_state state,
128 pdev = of_find_device_by_node(np); 128 pdev = of_find_device_by_node(np);
129 if (!pdev) { 129 if (!pdev) {
130 pr_err("arche-platform device not found\n"); 130 pr_err("arche-platform device not found\n");
131 of_node_put(np);
131 return -ENODEV; 132 return -ENODEV;
132 } 133 }
133 134
@@ -185,6 +186,7 @@ int arche_platform_change_state(enum arche_platform_state state,
185exit: 186exit:
186 spin_unlock_irqrestore(&arche_pdata->wake_lock, flags); 187 spin_unlock_irqrestore(&arche_pdata->wake_lock, flags);
187 mutex_unlock(&arche_pdata->platform_state_mutex); 188 mutex_unlock(&arche_pdata->platform_state_mutex);
189 put_device(&pdev->dev);
188 of_node_put(np); 190 of_node_put(np);
189 return ret; 191 return ret;
190} 192}
diff --git a/drivers/staging/greybus/es2.c b/drivers/staging/greybus/es2.c
index 071bb1cfd3ae..baab460eeaa3 100644
--- a/drivers/staging/greybus/es2.c
+++ b/drivers/staging/greybus/es2.c
@@ -1548,7 +1548,8 @@ static int ap_probe(struct usb_interface *interface,
1548 INIT_LIST_HEAD(&es2->arpcs); 1548 INIT_LIST_HEAD(&es2->arpcs);
1549 spin_lock_init(&es2->arpc_lock); 1549 spin_lock_init(&es2->arpc_lock);
1550 1550
1551 if (es2_arpc_in_enable(es2)) 1551 retval = es2_arpc_in_enable(es2);
1552 if (retval)
1552 goto error; 1553 goto error;
1553 1554
1554 retval = gb_hd_add(hd); 1555 retval = gb_hd_add(hd);
diff --git a/drivers/staging/greybus/gpio.c b/drivers/staging/greybus/gpio.c
index 5e06e4229e42..250caa00de5e 100644
--- a/drivers/staging/greybus/gpio.c
+++ b/drivers/staging/greybus/gpio.c
@@ -702,15 +702,13 @@ static int gb_gpio_probe(struct gbphy_device *gbphy_dev,
702 ret = gb_gpio_irqchip_add(gpio, irqc, 0, 702 ret = gb_gpio_irqchip_add(gpio, irqc, 0,
703 handle_level_irq, IRQ_TYPE_NONE); 703 handle_level_irq, IRQ_TYPE_NONE);
704 if (ret) { 704 if (ret) {
705 dev_err(&connection->bundle->dev, 705 dev_err(&gbphy_dev->dev, "failed to add irq chip: %d\n", ret);
706 "failed to add irq chip: %d\n", ret);
707 goto exit_line_free; 706 goto exit_line_free;
708 } 707 }
709 708
710 ret = gpiochip_add(gpio); 709 ret = gpiochip_add(gpio);
711 if (ret) { 710 if (ret) {
712 dev_err(&connection->bundle->dev, 711 dev_err(&gbphy_dev->dev, "failed to add gpio chip: %d\n", ret);
713 "failed to add gpio chip: %d\n", ret);
714 goto exit_gpio_irqchip_remove; 712 goto exit_gpio_irqchip_remove;
715 } 713 }
716 714
diff --git a/drivers/staging/greybus/module.c b/drivers/staging/greybus/module.c
index 69f67ddbd4a3..660b4674a76f 100644
--- a/drivers/staging/greybus/module.c
+++ b/drivers/staging/greybus/module.c
@@ -127,7 +127,7 @@ struct gb_module *gb_module_create(struct gb_host_device *hd, u8 module_id,
127 return module; 127 return module;
128 128
129err_put_interfaces: 129err_put_interfaces:
130 for (--i; i > 0; --i) 130 for (--i; i >= 0; --i)
131 gb_interface_put(module->interfaces[i]); 131 gb_interface_put(module->interfaces[i]);
132 132
133 put_device(&module->dev); 133 put_device(&module->dev);
diff --git a/drivers/staging/greybus/uart.c b/drivers/staging/greybus/uart.c
index 5ee7954bd9f9..2633d2bfb1b4 100644
--- a/drivers/staging/greybus/uart.c
+++ b/drivers/staging/greybus/uart.c
@@ -888,7 +888,7 @@ static int gb_uart_probe(struct gbphy_device *gbphy_dev,
888 minor = alloc_minor(gb_tty); 888 minor = alloc_minor(gb_tty);
889 if (minor < 0) { 889 if (minor < 0) {
890 if (minor == -ENOSPC) { 890 if (minor == -ENOSPC) {
891 dev_err(&connection->bundle->dev, 891 dev_err(&gbphy_dev->dev,
892 "no more free minor numbers\n"); 892 "no more free minor numbers\n");
893 retval = -ENODEV; 893 retval = -ENODEV;
894 } else { 894 } else {
diff --git a/drivers/staging/iio/accel/sca3000_core.c b/drivers/staging/iio/accel/sca3000_core.c
index d626125d7af9..564b36d4f648 100644
--- a/drivers/staging/iio/accel/sca3000_core.c
+++ b/drivers/staging/iio/accel/sca3000_core.c
@@ -468,6 +468,8 @@ static inline int __sca3000_get_base_freq(struct sca3000_state *st,
468 case SCA3000_MEAS_MODE_OP_2: 468 case SCA3000_MEAS_MODE_OP_2:
469 *base_freq = info->option_mode_2_freq; 469 *base_freq = info->option_mode_2_freq;
470 break; 470 break;
471 default:
472 ret = -EINVAL;
471 } 473 }
472error_ret: 474error_ret:
473 return ret; 475 return ret;
diff --git a/drivers/staging/iio/impedance-analyzer/ad5933.c b/drivers/staging/iio/impedance-analyzer/ad5933.c
index 5eecf1cb1028..3892a7470410 100644
--- a/drivers/staging/iio/impedance-analyzer/ad5933.c
+++ b/drivers/staging/iio/impedance-analyzer/ad5933.c
@@ -655,6 +655,7 @@ static void ad5933_work(struct work_struct *work)
655 __be16 buf[2]; 655 __be16 buf[2];
656 int val[2]; 656 int val[2];
657 unsigned char status; 657 unsigned char status;
658 int ret;
658 659
659 mutex_lock(&indio_dev->mlock); 660 mutex_lock(&indio_dev->mlock);
660 if (st->state == AD5933_CTRL_INIT_START_FREQ) { 661 if (st->state == AD5933_CTRL_INIT_START_FREQ) {
@@ -662,19 +663,22 @@ static void ad5933_work(struct work_struct *work)
662 ad5933_cmd(st, AD5933_CTRL_START_SWEEP); 663 ad5933_cmd(st, AD5933_CTRL_START_SWEEP);
663 st->state = AD5933_CTRL_START_SWEEP; 664 st->state = AD5933_CTRL_START_SWEEP;
664 schedule_delayed_work(&st->work, st->poll_time_jiffies); 665 schedule_delayed_work(&st->work, st->poll_time_jiffies);
665 mutex_unlock(&indio_dev->mlock); 666 goto out;
666 return;
667 } 667 }
668 668
669 ad5933_i2c_read(st->client, AD5933_REG_STATUS, 1, &status); 669 ret = ad5933_i2c_read(st->client, AD5933_REG_STATUS, 1, &status);
670 if (ret)
671 goto out;
670 672
671 if (status & AD5933_STAT_DATA_VALID) { 673 if (status & AD5933_STAT_DATA_VALID) {
672 int scan_count = bitmap_weight(indio_dev->active_scan_mask, 674 int scan_count = bitmap_weight(indio_dev->active_scan_mask,
673 indio_dev->masklength); 675 indio_dev->masklength);
674 ad5933_i2c_read(st->client, 676 ret = ad5933_i2c_read(st->client,
675 test_bit(1, indio_dev->active_scan_mask) ? 677 test_bit(1, indio_dev->active_scan_mask) ?
676 AD5933_REG_REAL_DATA : AD5933_REG_IMAG_DATA, 678 AD5933_REG_REAL_DATA : AD5933_REG_IMAG_DATA,
677 scan_count * 2, (u8 *)buf); 679 scan_count * 2, (u8 *)buf);
680 if (ret)
681 goto out;
678 682
679 if (scan_count == 2) { 683 if (scan_count == 2) {
680 val[0] = be16_to_cpu(buf[0]); 684 val[0] = be16_to_cpu(buf[0]);
@@ -686,8 +690,7 @@ static void ad5933_work(struct work_struct *work)
686 } else { 690 } else {
687 /* no data available - try again later */ 691 /* no data available - try again later */
688 schedule_delayed_work(&st->work, st->poll_time_jiffies); 692 schedule_delayed_work(&st->work, st->poll_time_jiffies);
689 mutex_unlock(&indio_dev->mlock); 693 goto out;
690 return;
691 } 694 }
692 695
693 if (status & AD5933_STAT_SWEEP_DONE) { 696 if (status & AD5933_STAT_SWEEP_DONE) {
@@ -700,7 +703,7 @@ static void ad5933_work(struct work_struct *work)
700 ad5933_cmd(st, AD5933_CTRL_INC_FREQ); 703 ad5933_cmd(st, AD5933_CTRL_INC_FREQ);
701 schedule_delayed_work(&st->work, st->poll_time_jiffies); 704 schedule_delayed_work(&st->work, st->poll_time_jiffies);
702 } 705 }
703 706out:
704 mutex_unlock(&indio_dev->mlock); 707 mutex_unlock(&indio_dev->mlock);
705} 708}
706 709
diff --git a/drivers/staging/lustre/lustre/llite/lproc_llite.c b/drivers/staging/lustre/lustre/llite/lproc_llite.c
index 6eae60595905..23fda9d98bff 100644
--- a/drivers/staging/lustre/lustre/llite/lproc_llite.c
+++ b/drivers/staging/lustre/lustre/llite/lproc_llite.c
@@ -871,12 +871,10 @@ static ssize_t xattr_cache_store(struct kobject *kobj,
871} 871}
872LUSTRE_RW_ATTR(xattr_cache); 872LUSTRE_RW_ATTR(xattr_cache);
873 873
874static ssize_t unstable_stats_show(struct kobject *kobj, 874static int ll_unstable_stats_seq_show(struct seq_file *m, void *v)
875 struct attribute *attr,
876 char *buf)
877{ 875{
878 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info, 876 struct super_block *sb = m->private;
879 ll_kobj); 877 struct ll_sb_info *sbi = ll_s2sbi(sb);
880 struct cl_client_cache *cache = sbi->ll_cache; 878 struct cl_client_cache *cache = sbi->ll_cache;
881 long pages; 879 long pages;
882 int mb; 880 int mb;
@@ -884,19 +882,21 @@ static ssize_t unstable_stats_show(struct kobject *kobj,
884 pages = atomic_long_read(&cache->ccc_unstable_nr); 882 pages = atomic_long_read(&cache->ccc_unstable_nr);
885 mb = (pages * PAGE_SIZE) >> 20; 883 mb = (pages * PAGE_SIZE) >> 20;
886 884
887 return sprintf(buf, "unstable_check: %8d\n" 885 seq_printf(m,
888 "unstable_pages: %12ld\n" 886 "unstable_check: %8d\n"
889 "unstable_mb: %8d\n", 887 "unstable_pages: %12ld\n"
890 cache->ccc_unstable_check, pages, mb); 888 "unstable_mb: %8d\n",
889 cache->ccc_unstable_check, pages, mb);
890
891 return 0;
891} 892}
892 893
893static ssize_t unstable_stats_store(struct kobject *kobj, 894static ssize_t ll_unstable_stats_seq_write(struct file *file,
894 struct attribute *attr, 895 const char __user *buffer,
895 const char *buffer, 896 size_t count, loff_t *off)
896 size_t count)
897{ 897{
898 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info, 898 struct super_block *sb = ((struct seq_file *)file->private_data)->private;
899 ll_kobj); 899 struct ll_sb_info *sbi = ll_s2sbi(sb);
900 char kernbuf[128]; 900 char kernbuf[128];
901 int val, rc; 901 int val, rc;
902 902
@@ -922,7 +922,7 @@ static ssize_t unstable_stats_store(struct kobject *kobj,
922 922
923 return count; 923 return count;
924} 924}
925LUSTRE_RW_ATTR(unstable_stats); 925LPROC_SEQ_FOPS(ll_unstable_stats);
926 926
927static ssize_t root_squash_show(struct kobject *kobj, struct attribute *attr, 927static ssize_t root_squash_show(struct kobject *kobj, struct attribute *attr,
928 char *buf) 928 char *buf)
@@ -995,6 +995,7 @@ static struct lprocfs_vars lprocfs_llite_obd_vars[] = {
995 /* { "filegroups", lprocfs_rd_filegroups, 0, 0 }, */ 995 /* { "filegroups", lprocfs_rd_filegroups, 0, 0 }, */
996 { "max_cached_mb", &ll_max_cached_mb_fops, NULL }, 996 { "max_cached_mb", &ll_max_cached_mb_fops, NULL },
997 { "statahead_stats", &ll_statahead_stats_fops, NULL, 0 }, 997 { "statahead_stats", &ll_statahead_stats_fops, NULL, 0 },
998 { "unstable_stats", &ll_unstable_stats_fops, NULL },
998 { "sbi_flags", &ll_sbi_flags_fops, NULL, 0 }, 999 { "sbi_flags", &ll_sbi_flags_fops, NULL, 0 },
999 { .name = "nosquash_nids", 1000 { .name = "nosquash_nids",
1000 .fops = &ll_nosquash_nids_fops }, 1001 .fops = &ll_nosquash_nids_fops },
@@ -1026,7 +1027,6 @@ static struct attribute *llite_attrs[] = {
1026 &lustre_attr_max_easize.attr, 1027 &lustre_attr_max_easize.attr,
1027 &lustre_attr_default_easize.attr, 1028 &lustre_attr_default_easize.attr,
1028 &lustre_attr_xattr_cache.attr, 1029 &lustre_attr_xattr_cache.attr,
1029 &lustre_attr_unstable_stats.attr,
1030 &lustre_attr_root_squash.attr, 1030 &lustre_attr_root_squash.attr,
1031 NULL, 1031 NULL,
1032}; 1032};
diff --git a/drivers/staging/media/bcm2048/radio-bcm2048.c b/drivers/staging/media/bcm2048/radio-bcm2048.c
index ea15cc638097..4d9bd02ede47 100644
--- a/drivers/staging/media/bcm2048/radio-bcm2048.c
+++ b/drivers/staging/media/bcm2048/radio-bcm2048.c
@@ -482,6 +482,8 @@ static int bcm2048_set_rds_no_lock(struct bcm2048_device *bdev, u8 rds_on)
482 flags); 482 flags);
483 memset(&bdev->rds_info, 0, sizeof(bdev->rds_info)); 483 memset(&bdev->rds_info, 0, sizeof(bdev->rds_info));
484 } 484 }
485 if (err)
486 return err;
485 487
486 return bcm2048_send_command(bdev, BCM2048_I2C_FM_RDS_SYSTEM, 488 return bcm2048_send_command(bdev, BCM2048_I2C_FM_RDS_SYSTEM,
487 bdev->cache_fm_rds_system); 489 bdev->cache_fm_rds_system);
diff --git a/drivers/staging/nvec/nvec_ps2.c b/drivers/staging/nvec/nvec_ps2.c
index a324322ee0ad..499952c8ef39 100644
--- a/drivers/staging/nvec/nvec_ps2.c
+++ b/drivers/staging/nvec/nvec_ps2.c
@@ -106,13 +106,12 @@ static int nvec_mouse_probe(struct platform_device *pdev)
106{ 106{
107 struct nvec_chip *nvec = dev_get_drvdata(pdev->dev.parent); 107 struct nvec_chip *nvec = dev_get_drvdata(pdev->dev.parent);
108 struct serio *ser_dev; 108 struct serio *ser_dev;
109 char mouse_reset[] = { NVEC_PS2, SEND_COMMAND, PSMOUSE_RST, 3 };
110 109
111 ser_dev = devm_kzalloc(&pdev->dev, sizeof(struct serio), GFP_KERNEL); 110 ser_dev = kzalloc(sizeof(struct serio), GFP_KERNEL);
112 if (!ser_dev) 111 if (!ser_dev)
113 return -ENOMEM; 112 return -ENOMEM;
114 113
115 ser_dev->id.type = SERIO_PS_PSTHRU; 114 ser_dev->id.type = SERIO_8042;
116 ser_dev->write = ps2_sendcommand; 115 ser_dev->write = ps2_sendcommand;
117 ser_dev->start = ps2_startstreaming; 116 ser_dev->start = ps2_startstreaming;
118 ser_dev->stop = ps2_stopstreaming; 117 ser_dev->stop = ps2_stopstreaming;
@@ -127,9 +126,6 @@ static int nvec_mouse_probe(struct platform_device *pdev)
127 126
128 serio_register_port(ser_dev); 127 serio_register_port(ser_dev);
129 128
130 /* mouse reset */
131 nvec_write_async(nvec, mouse_reset, sizeof(mouse_reset));
132
133 return 0; 129 return 0;
134} 130}
135 131
diff --git a/drivers/staging/sm750fb/ddk750_reg.h b/drivers/staging/sm750fb/ddk750_reg.h
index 955247979aaa..4ed6d8d7712a 100644
--- a/drivers/staging/sm750fb/ddk750_reg.h
+++ b/drivers/staging/sm750fb/ddk750_reg.h
@@ -601,13 +601,13 @@
601 601
602#define PANEL_PLANE_TL 0x08001C 602#define PANEL_PLANE_TL 0x08001C
603#define PANEL_PLANE_TL_TOP_SHIFT 16 603#define PANEL_PLANE_TL_TOP_SHIFT 16
604#define PANEL_PLANE_TL_TOP_MASK (0xeff << 16) 604#define PANEL_PLANE_TL_TOP_MASK (0x7ff << 16)
605#define PANEL_PLANE_TL_LEFT_MASK 0xeff 605#define PANEL_PLANE_TL_LEFT_MASK 0x7ff
606 606
607#define PANEL_PLANE_BR 0x080020 607#define PANEL_PLANE_BR 0x080020
608#define PANEL_PLANE_BR_BOTTOM_SHIFT 16 608#define PANEL_PLANE_BR_BOTTOM_SHIFT 16
609#define PANEL_PLANE_BR_BOTTOM_MASK (0xeff << 16) 609#define PANEL_PLANE_BR_BOTTOM_MASK (0x7ff << 16)
610#define PANEL_PLANE_BR_RIGHT_MASK 0xeff 610#define PANEL_PLANE_BR_RIGHT_MASK 0x7ff
611 611
612#define PANEL_HORIZONTAL_TOTAL 0x080024 612#define PANEL_HORIZONTAL_TOTAL 0x080024
613#define PANEL_HORIZONTAL_TOTAL_TOTAL_SHIFT 16 613#define PANEL_HORIZONTAL_TOTAL_TOTAL_SHIFT 16
diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c
index c29040fdf9a7..1091b9f1dd07 100644
--- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c
+++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c
@@ -423,8 +423,7 @@ create_pagelist(char __user *buf, size_t count, unsigned short type,
423 actual_pages = get_user_pages(task, task->mm, 423 actual_pages = get_user_pages(task, task->mm,
424 (unsigned long)buf & ~(PAGE_SIZE - 1), 424 (unsigned long)buf & ~(PAGE_SIZE - 1),
425 num_pages, 425 num_pages,
426 (type == PAGELIST_READ) /*Write */ , 426 (type == PAGELIST_READ) ? FOLL_WRITE : 0,
427 0 /*Force */ ,
428 pages, 427 pages,
429 NULL /*vmas */); 428 NULL /*vmas */);
430 up_read(&task->mm->mmap_sem); 429 up_read(&task->mm->mmap_sem);
diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
index e11c0e07471b..7b6cd4d80621 100644
--- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
+++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
@@ -1477,8 +1477,7 @@ dump_phys_mem(void *virt_addr, uint32_t num_bytes)
1477 current->mm, /* mm */ 1477 current->mm, /* mm */
1478 (unsigned long)virt_addr, /* start */ 1478 (unsigned long)virt_addr, /* start */
1479 num_pages, /* len */ 1479 num_pages, /* len */
1480 0, /* write */ 1480 0, /* gup_flags */
1481 0, /* force */
1482 pages, /* pages (array of page pointers) */ 1481 pages, /* pages (array of page pointers) */
1483 NULL); /* vmas */ 1482 NULL); /* vmas */
1484 up_read(&current->mm->mmap_sem); 1483 up_read(&current->mm->mmap_sem);
diff --git a/drivers/staging/wilc1000/host_interface.c b/drivers/staging/wilc1000/host_interface.c
index 78f5613e9467..6ab7443eabde 100644
--- a/drivers/staging/wilc1000/host_interface.c
+++ b/drivers/staging/wilc1000/host_interface.c
@@ -3388,7 +3388,6 @@ int wilc_init(struct net_device *dev, struct host_if_drv **hif_drv_handler)
3388 3388
3389 clients_count++; 3389 clients_count++;
3390 3390
3391 destroy_workqueue(hif_workqueue);
3392_fail_: 3391_fail_:
3393 return result; 3392 return result;
3394} 3393}
diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c
index 39b928c2849d..b7d747e92c7a 100644
--- a/drivers/target/iscsi/iscsi_target.c
+++ b/drivers/target/iscsi/iscsi_target.c
@@ -1804,6 +1804,10 @@ int iscsit_process_nop_out(struct iscsi_conn *conn, struct iscsi_cmd *cmd,
1804 * Otherwise, initiator is not expecting a NOPIN is response. 1804 * Otherwise, initiator is not expecting a NOPIN is response.
1805 * Just ignore for now. 1805 * Just ignore for now.
1806 */ 1806 */
1807
1808 if (cmd)
1809 iscsit_free_cmd(cmd, false);
1810
1807 return 0; 1811 return 0;
1808} 1812}
1809EXPORT_SYMBOL(iscsit_process_nop_out); 1813EXPORT_SYMBOL(iscsit_process_nop_out);
@@ -2982,7 +2986,7 @@ iscsit_build_nopin_rsp(struct iscsi_cmd *cmd, struct iscsi_conn *conn,
2982 2986
2983 pr_debug("Built NOPIN %s Response ITT: 0x%08x, TTT: 0x%08x," 2987 pr_debug("Built NOPIN %s Response ITT: 0x%08x, TTT: 0x%08x,"
2984 " StatSN: 0x%08x, Length %u\n", (nopout_response) ? 2988 " StatSN: 0x%08x, Length %u\n", (nopout_response) ?
2985 "Solicitied" : "Unsolicitied", cmd->init_task_tag, 2989 "Solicited" : "Unsolicited", cmd->init_task_tag,
2986 cmd->targ_xfer_tag, cmd->stat_sn, cmd->buf_ptr_size); 2990 cmd->targ_xfer_tag, cmd->stat_sn, cmd->buf_ptr_size);
2987} 2991}
2988EXPORT_SYMBOL(iscsit_build_nopin_rsp); 2992EXPORT_SYMBOL(iscsit_build_nopin_rsp);
diff --git a/drivers/target/iscsi/iscsi_target_login.c b/drivers/target/iscsi/iscsi_target_login.c
index adf419fa4291..15f79a2ca34a 100644
--- a/drivers/target/iscsi/iscsi_target_login.c
+++ b/drivers/target/iscsi/iscsi_target_login.c
@@ -434,7 +434,7 @@ static int iscsi_login_zero_tsih_s2(
434 434
435 /* 435 /*
436 * Make MaxRecvDataSegmentLength PAGE_SIZE aligned for 436 * Make MaxRecvDataSegmentLength PAGE_SIZE aligned for
437 * Immediate Data + Unsolicitied Data-OUT if necessary.. 437 * Immediate Data + Unsolicited Data-OUT if necessary..
438 */ 438 */
439 param = iscsi_find_param_from_key("MaxRecvDataSegmentLength", 439 param = iscsi_find_param_from_key("MaxRecvDataSegmentLength",
440 conn->param_list); 440 conn->param_list);
@@ -646,7 +646,7 @@ static void iscsi_post_login_start_timers(struct iscsi_conn *conn)
646{ 646{
647 struct iscsi_session *sess = conn->sess; 647 struct iscsi_session *sess = conn->sess;
648 /* 648 /*
649 * FIXME: Unsolicitied NopIN support for ISER 649 * FIXME: Unsolicited NopIN support for ISER
650 */ 650 */
651 if (conn->conn_transport->transport_type == ISCSI_INFINIBAND) 651 if (conn->conn_transport->transport_type == ISCSI_INFINIBAND)
652 return; 652 return;
diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
index 6094a6beddde..7dfefd66df93 100644
--- a/drivers/target/target_core_transport.c
+++ b/drivers/target/target_core_transport.c
@@ -754,15 +754,7 @@ EXPORT_SYMBOL(target_complete_cmd);
754 754
755void target_complete_cmd_with_length(struct se_cmd *cmd, u8 scsi_status, int length) 755void target_complete_cmd_with_length(struct se_cmd *cmd, u8 scsi_status, int length)
756{ 756{
757 if (scsi_status != SAM_STAT_GOOD) { 757 if (scsi_status == SAM_STAT_GOOD && length < cmd->data_length) {
758 return;
759 }
760
761 /*
762 * Calculate new residual count based upon length of SCSI data
763 * transferred.
764 */
765 if (length < cmd->data_length) {
766 if (cmd->se_cmd_flags & SCF_UNDERFLOW_BIT) { 758 if (cmd->se_cmd_flags & SCF_UNDERFLOW_BIT) {
767 cmd->residual_count += cmd->data_length - length; 759 cmd->residual_count += cmd->data_length - length;
768 } else { 760 } else {
@@ -771,12 +763,6 @@ void target_complete_cmd_with_length(struct se_cmd *cmd, u8 scsi_status, int len
771 } 763 }
772 764
773 cmd->data_length = length; 765 cmd->data_length = length;
774 } else if (length > cmd->data_length) {
775 cmd->se_cmd_flags |= SCF_OVERFLOW_BIT;
776 cmd->residual_count = length - cmd->data_length;
777 } else {
778 cmd->se_cmd_flags &= ~(SCF_OVERFLOW_BIT | SCF_UNDERFLOW_BIT);
779 cmd->residual_count = 0;
780 } 766 }
781 767
782 target_complete_cmd(cmd, scsi_status); 768 target_complete_cmd(cmd, scsi_status);
@@ -1706,6 +1692,7 @@ void transport_generic_request_failure(struct se_cmd *cmd,
1706 case TCM_LOGICAL_BLOCK_GUARD_CHECK_FAILED: 1692 case TCM_LOGICAL_BLOCK_GUARD_CHECK_FAILED:
1707 case TCM_LOGICAL_BLOCK_APP_TAG_CHECK_FAILED: 1693 case TCM_LOGICAL_BLOCK_APP_TAG_CHECK_FAILED:
1708 case TCM_LOGICAL_BLOCK_REF_TAG_CHECK_FAILED: 1694 case TCM_LOGICAL_BLOCK_REF_TAG_CHECK_FAILED:
1695 case TCM_COPY_TARGET_DEVICE_NOT_REACHABLE:
1709 break; 1696 break;
1710 case TCM_OUT_OF_RESOURCES: 1697 case TCM_OUT_OF_RESOURCES:
1711 sense_reason = TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; 1698 sense_reason = TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
@@ -2547,8 +2534,12 @@ int target_get_sess_cmd(struct se_cmd *se_cmd, bool ack_kref)
2547 * fabric acknowledgement that requires two target_put_sess_cmd() 2534 * fabric acknowledgement that requires two target_put_sess_cmd()
2548 * invocations before se_cmd descriptor release. 2535 * invocations before se_cmd descriptor release.
2549 */ 2536 */
2550 if (ack_kref) 2537 if (ack_kref) {
2551 kref_get(&se_cmd->cmd_kref); 2538 if (!kref_get_unless_zero(&se_cmd->cmd_kref))
2539 return -EINVAL;
2540
2541 se_cmd->se_cmd_flags |= SCF_ACK_KREF;
2542 }
2552 2543
2553 spin_lock_irqsave(&se_sess->sess_cmd_lock, flags); 2544 spin_lock_irqsave(&se_sess->sess_cmd_lock, flags);
2554 if (se_sess->sess_tearing_down) { 2545 if (se_sess->sess_tearing_down) {
@@ -2627,7 +2618,7 @@ EXPORT_SYMBOL(target_put_sess_cmd);
2627 */ 2618 */
2628void target_sess_cmd_list_set_waiting(struct se_session *se_sess) 2619void target_sess_cmd_list_set_waiting(struct se_session *se_sess)
2629{ 2620{
2630 struct se_cmd *se_cmd; 2621 struct se_cmd *se_cmd, *tmp_cmd;
2631 unsigned long flags; 2622 unsigned long flags;
2632 int rc; 2623 int rc;
2633 2624
@@ -2639,14 +2630,16 @@ void target_sess_cmd_list_set_waiting(struct se_session *se_sess)
2639 se_sess->sess_tearing_down = 1; 2630 se_sess->sess_tearing_down = 1;
2640 list_splice_init(&se_sess->sess_cmd_list, &se_sess->sess_wait_list); 2631 list_splice_init(&se_sess->sess_cmd_list, &se_sess->sess_wait_list);
2641 2632
2642 list_for_each_entry(se_cmd, &se_sess->sess_wait_list, se_cmd_list) { 2633 list_for_each_entry_safe(se_cmd, tmp_cmd,
2634 &se_sess->sess_wait_list, se_cmd_list) {
2643 rc = kref_get_unless_zero(&se_cmd->cmd_kref); 2635 rc = kref_get_unless_zero(&se_cmd->cmd_kref);
2644 if (rc) { 2636 if (rc) {
2645 se_cmd->cmd_wait_set = 1; 2637 se_cmd->cmd_wait_set = 1;
2646 spin_lock(&se_cmd->t_state_lock); 2638 spin_lock(&se_cmd->t_state_lock);
2647 se_cmd->transport_state |= CMD_T_FABRIC_STOP; 2639 se_cmd->transport_state |= CMD_T_FABRIC_STOP;
2648 spin_unlock(&se_cmd->t_state_lock); 2640 spin_unlock(&se_cmd->t_state_lock);
2649 } 2641 } else
2642 list_del_init(&se_cmd->se_cmd_list);
2650 } 2643 }
2651 2644
2652 spin_unlock_irqrestore(&se_sess->sess_cmd_lock, flags); 2645 spin_unlock_irqrestore(&se_sess->sess_cmd_lock, flags);
@@ -2871,6 +2864,12 @@ static const struct sense_info sense_info_table[] = {
2871 .ascq = 0x03, /* LOGICAL BLOCK REFERENCE TAG CHECK FAILED */ 2864 .ascq = 0x03, /* LOGICAL BLOCK REFERENCE TAG CHECK FAILED */
2872 .add_sector_info = true, 2865 .add_sector_info = true,
2873 }, 2866 },
2867 [TCM_COPY_TARGET_DEVICE_NOT_REACHABLE] = {
2868 .key = COPY_ABORTED,
2869 .asc = 0x0d,
2870 .ascq = 0x02, /* COPY TARGET DEVICE NOT REACHABLE */
2871
2872 },
2874 [TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE] = { 2873 [TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE] = {
2875 /* 2874 /*
2876 * Returning ILLEGAL REQUEST would cause immediate IO errors on 2875 * Returning ILLEGAL REQUEST would cause immediate IO errors on
diff --git a/drivers/target/target_core_user.c b/drivers/target/target_core_user.c
index 62bf4fe5704a..47562509b489 100644
--- a/drivers/target/target_core_user.c
+++ b/drivers/target/target_core_user.c
@@ -96,7 +96,7 @@ struct tcmu_dev {
96 size_t dev_size; 96 size_t dev_size;
97 u32 cmdr_size; 97 u32 cmdr_size;
98 u32 cmdr_last_cleaned; 98 u32 cmdr_last_cleaned;
99 /* Offset of data ring from start of mb */ 99 /* Offset of data area from start of mb */
100 /* Must add data_off and mb_addr to get the address */ 100 /* Must add data_off and mb_addr to get the address */
101 size_t data_off; 101 size_t data_off;
102 size_t data_size; 102 size_t data_size;
@@ -349,7 +349,7 @@ static inline size_t spc_bitmap_free(unsigned long *bitmap)
349 349
350/* 350/*
351 * We can't queue a command until we have space available on the cmd ring *and* 351 * We can't queue a command until we have space available on the cmd ring *and*
352 * space available on the data ring. 352 * space available on the data area.
353 * 353 *
354 * Called with ring lock held. 354 * Called with ring lock held.
355 */ 355 */
@@ -389,7 +389,8 @@ static bool is_ring_space_avail(struct tcmu_dev *udev, size_t cmd_size, size_t d
389 return true; 389 return true;
390} 390}
391 391
392static int tcmu_queue_cmd_ring(struct tcmu_cmd *tcmu_cmd) 392static sense_reason_t
393tcmu_queue_cmd_ring(struct tcmu_cmd *tcmu_cmd)
393{ 394{
394 struct tcmu_dev *udev = tcmu_cmd->tcmu_dev; 395 struct tcmu_dev *udev = tcmu_cmd->tcmu_dev;
395 struct se_cmd *se_cmd = tcmu_cmd->se_cmd; 396 struct se_cmd *se_cmd = tcmu_cmd->se_cmd;
@@ -405,7 +406,7 @@ static int tcmu_queue_cmd_ring(struct tcmu_cmd *tcmu_cmd)
405 DECLARE_BITMAP(old_bitmap, DATA_BLOCK_BITS); 406 DECLARE_BITMAP(old_bitmap, DATA_BLOCK_BITS);
406 407
407 if (test_bit(TCMU_DEV_BIT_BROKEN, &udev->flags)) 408 if (test_bit(TCMU_DEV_BIT_BROKEN, &udev->flags))
408 return -EINVAL; 409 return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
409 410
410 /* 411 /*
411 * Must be a certain minimum size for response sense info, but 412 * Must be a certain minimum size for response sense info, but
@@ -432,11 +433,14 @@ static int tcmu_queue_cmd_ring(struct tcmu_cmd *tcmu_cmd)
432 BUG_ON(!(se_cmd->t_bidi_data_sg && se_cmd->t_bidi_data_nents)); 433 BUG_ON(!(se_cmd->t_bidi_data_sg && se_cmd->t_bidi_data_nents));
433 data_length += se_cmd->t_bidi_data_sg->length; 434 data_length += se_cmd->t_bidi_data_sg->length;
434 } 435 }
435 if ((command_size > (udev->cmdr_size / 2)) 436 if ((command_size > (udev->cmdr_size / 2)) ||
436 || data_length > udev->data_size) 437 data_length > udev->data_size) {
437 pr_warn("TCMU: Request of size %zu/%zu may be too big for %u/%zu " 438 pr_warn("TCMU: Request of size %zu/%zu is too big for %u/%zu "
438 "cmd/data ring buffers\n", command_size, data_length, 439 "cmd ring/data area\n", command_size, data_length,
439 udev->cmdr_size, udev->data_size); 440 udev->cmdr_size, udev->data_size);
441 spin_unlock_irq(&udev->cmdr_lock);
442 return TCM_INVALID_CDB_FIELD;
443 }
440 444
441 while (!is_ring_space_avail(udev, command_size, data_length)) { 445 while (!is_ring_space_avail(udev, command_size, data_length)) {
442 int ret; 446 int ret;
@@ -450,7 +454,7 @@ static int tcmu_queue_cmd_ring(struct tcmu_cmd *tcmu_cmd)
450 finish_wait(&udev->wait_cmdr, &__wait); 454 finish_wait(&udev->wait_cmdr, &__wait);
451 if (!ret) { 455 if (!ret) {
452 pr_warn("tcmu: command timed out\n"); 456 pr_warn("tcmu: command timed out\n");
453 return -ETIMEDOUT; 457 return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
454 } 458 }
455 459
456 spin_lock_irq(&udev->cmdr_lock); 460 spin_lock_irq(&udev->cmdr_lock);
@@ -487,9 +491,7 @@ static int tcmu_queue_cmd_ring(struct tcmu_cmd *tcmu_cmd)
487 491
488 bitmap_copy(old_bitmap, udev->data_bitmap, DATA_BLOCK_BITS); 492 bitmap_copy(old_bitmap, udev->data_bitmap, DATA_BLOCK_BITS);
489 493
490 /* 494 /* Handle allocating space from the data area */
491 * Fix up iovecs, and handle if allocation in data ring wrapped.
492 */
493 iov = &entry->req.iov[0]; 495 iov = &entry->req.iov[0];
494 iov_cnt = 0; 496 iov_cnt = 0;
495 copy_to_data_area = (se_cmd->data_direction == DMA_TO_DEVICE 497 copy_to_data_area = (se_cmd->data_direction == DMA_TO_DEVICE
@@ -526,10 +528,11 @@ static int tcmu_queue_cmd_ring(struct tcmu_cmd *tcmu_cmd)
526 mod_timer(&udev->timeout, 528 mod_timer(&udev->timeout,
527 round_jiffies_up(jiffies + msecs_to_jiffies(TCMU_TIME_OUT))); 529 round_jiffies_up(jiffies + msecs_to_jiffies(TCMU_TIME_OUT)));
528 530
529 return 0; 531 return TCM_NO_SENSE;
530} 532}
531 533
532static int tcmu_queue_cmd(struct se_cmd *se_cmd) 534static sense_reason_t
535tcmu_queue_cmd(struct se_cmd *se_cmd)
533{ 536{
534 struct se_device *se_dev = se_cmd->se_dev; 537 struct se_device *se_dev = se_cmd->se_dev;
535 struct tcmu_dev *udev = TCMU_DEV(se_dev); 538 struct tcmu_dev *udev = TCMU_DEV(se_dev);
@@ -538,10 +541,10 @@ static int tcmu_queue_cmd(struct se_cmd *se_cmd)
538 541
539 tcmu_cmd = tcmu_alloc_cmd(se_cmd); 542 tcmu_cmd = tcmu_alloc_cmd(se_cmd);
540 if (!tcmu_cmd) 543 if (!tcmu_cmd)
541 return -ENOMEM; 544 return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
542 545
543 ret = tcmu_queue_cmd_ring(tcmu_cmd); 546 ret = tcmu_queue_cmd_ring(tcmu_cmd);
544 if (ret < 0) { 547 if (ret != TCM_NO_SENSE) {
545 pr_err("TCMU: Could not queue command\n"); 548 pr_err("TCMU: Could not queue command\n");
546 spin_lock_irq(&udev->commands_lock); 549 spin_lock_irq(&udev->commands_lock);
547 idr_remove(&udev->commands, tcmu_cmd->cmd_id); 550 idr_remove(&udev->commands, tcmu_cmd->cmd_id);
@@ -561,7 +564,7 @@ static void tcmu_handle_completion(struct tcmu_cmd *cmd, struct tcmu_cmd_entry *
561 if (test_bit(TCMU_CMD_BIT_EXPIRED, &cmd->flags)) { 564 if (test_bit(TCMU_CMD_BIT_EXPIRED, &cmd->flags)) {
562 /* 565 /*
563 * cmd has been completed already from timeout, just reclaim 566 * cmd has been completed already from timeout, just reclaim
564 * data ring space and free cmd 567 * data area space and free cmd
565 */ 568 */
566 free_data_area(udev, cmd); 569 free_data_area(udev, cmd);
567 570
@@ -1129,20 +1132,9 @@ static sector_t tcmu_get_blocks(struct se_device *dev)
1129} 1132}
1130 1133
1131static sense_reason_t 1134static sense_reason_t
1132tcmu_pass_op(struct se_cmd *se_cmd)
1133{
1134 int ret = tcmu_queue_cmd(se_cmd);
1135
1136 if (ret != 0)
1137 return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
1138 else
1139 return TCM_NO_SENSE;
1140}
1141
1142static sense_reason_t
1143tcmu_parse_cdb(struct se_cmd *cmd) 1135tcmu_parse_cdb(struct se_cmd *cmd)
1144{ 1136{
1145 return passthrough_parse_cdb(cmd, tcmu_pass_op); 1137 return passthrough_parse_cdb(cmd, tcmu_queue_cmd);
1146} 1138}
1147 1139
1148static const struct target_backend_ops tcmu_ops = { 1140static const struct target_backend_ops tcmu_ops = {
diff --git a/drivers/target/target_core_xcopy.c b/drivers/target/target_core_xcopy.c
index 75cd85426ae3..094a1440eacb 100644
--- a/drivers/target/target_core_xcopy.c
+++ b/drivers/target/target_core_xcopy.c
@@ -104,7 +104,7 @@ static int target_xcopy_locate_se_dev_e4(struct se_cmd *se_cmd, struct xcopy_op
104 } 104 }
105 mutex_unlock(&g_device_mutex); 105 mutex_unlock(&g_device_mutex);
106 106
107 pr_err("Unable to locate 0xe4 descriptor for EXTENDED_COPY\n"); 107 pr_debug_ratelimited("Unable to locate 0xe4 descriptor for EXTENDED_COPY\n");
108 return -EINVAL; 108 return -EINVAL;
109} 109}
110 110
@@ -185,7 +185,7 @@ static int target_xcopy_parse_tiddesc_e4(struct se_cmd *se_cmd, struct xcopy_op
185 185
186static int target_xcopy_parse_target_descriptors(struct se_cmd *se_cmd, 186static int target_xcopy_parse_target_descriptors(struct se_cmd *se_cmd,
187 struct xcopy_op *xop, unsigned char *p, 187 struct xcopy_op *xop, unsigned char *p,
188 unsigned short tdll) 188 unsigned short tdll, sense_reason_t *sense_ret)
189{ 189{
190 struct se_device *local_dev = se_cmd->se_dev; 190 struct se_device *local_dev = se_cmd->se_dev;
191 unsigned char *desc = p; 191 unsigned char *desc = p;
@@ -193,6 +193,8 @@ static int target_xcopy_parse_target_descriptors(struct se_cmd *se_cmd,
193 unsigned short start = 0; 193 unsigned short start = 0;
194 bool src = true; 194 bool src = true;
195 195
196 *sense_ret = TCM_INVALID_PARAMETER_LIST;
197
196 if (offset != 0) { 198 if (offset != 0) {
197 pr_err("XCOPY target descriptor list length is not" 199 pr_err("XCOPY target descriptor list length is not"
198 " multiple of %d\n", XCOPY_TARGET_DESC_LEN); 200 " multiple of %d\n", XCOPY_TARGET_DESC_LEN);
@@ -243,9 +245,16 @@ static int target_xcopy_parse_target_descriptors(struct se_cmd *se_cmd,
243 rc = target_xcopy_locate_se_dev_e4(se_cmd, xop, true); 245 rc = target_xcopy_locate_se_dev_e4(se_cmd, xop, true);
244 else 246 else
245 rc = target_xcopy_locate_se_dev_e4(se_cmd, xop, false); 247 rc = target_xcopy_locate_se_dev_e4(se_cmd, xop, false);
246 248 /*
247 if (rc < 0) 249 * If a matching IEEE NAA 0x83 descriptor for the requested device
250 * is not located on this node, return COPY_ABORTED with ASQ/ASQC
251 * 0x0d/0x02 - COPY_TARGET_DEVICE_NOT_REACHABLE to request the
252 * initiator to fall back to normal copy method.
253 */
254 if (rc < 0) {
255 *sense_ret = TCM_COPY_TARGET_DEVICE_NOT_REACHABLE;
248 goto out; 256 goto out;
257 }
249 258
250 pr_debug("XCOPY TGT desc: Source dev: %p NAA IEEE WWN: 0x%16phN\n", 259 pr_debug("XCOPY TGT desc: Source dev: %p NAA IEEE WWN: 0x%16phN\n",
251 xop->src_dev, &xop->src_tid_wwn[0]); 260 xop->src_dev, &xop->src_tid_wwn[0]);
@@ -653,6 +662,7 @@ static int target_xcopy_read_source(
653 rc = target_xcopy_setup_pt_cmd(xpt_cmd, xop, src_dev, &cdb[0], 662 rc = target_xcopy_setup_pt_cmd(xpt_cmd, xop, src_dev, &cdb[0],
654 remote_port, true); 663 remote_port, true);
655 if (rc < 0) { 664 if (rc < 0) {
665 ec_cmd->scsi_status = xpt_cmd->se_cmd.scsi_status;
656 transport_generic_free_cmd(se_cmd, 0); 666 transport_generic_free_cmd(se_cmd, 0);
657 return rc; 667 return rc;
658 } 668 }
@@ -664,6 +674,7 @@ static int target_xcopy_read_source(
664 674
665 rc = target_xcopy_issue_pt_cmd(xpt_cmd); 675 rc = target_xcopy_issue_pt_cmd(xpt_cmd);
666 if (rc < 0) { 676 if (rc < 0) {
677 ec_cmd->scsi_status = xpt_cmd->se_cmd.scsi_status;
667 transport_generic_free_cmd(se_cmd, 0); 678 transport_generic_free_cmd(se_cmd, 0);
668 return rc; 679 return rc;
669 } 680 }
@@ -714,6 +725,7 @@ static int target_xcopy_write_destination(
714 remote_port, false); 725 remote_port, false);
715 if (rc < 0) { 726 if (rc < 0) {
716 struct se_cmd *src_cmd = &xop->src_pt_cmd->se_cmd; 727 struct se_cmd *src_cmd = &xop->src_pt_cmd->se_cmd;
728 ec_cmd->scsi_status = xpt_cmd->se_cmd.scsi_status;
717 /* 729 /*
718 * If the failure happened before the t_mem_list hand-off in 730 * If the failure happened before the t_mem_list hand-off in
719 * target_xcopy_setup_pt_cmd(), Reset memory + clear flag so that 731 * target_xcopy_setup_pt_cmd(), Reset memory + clear flag so that
@@ -729,6 +741,7 @@ static int target_xcopy_write_destination(
729 741
730 rc = target_xcopy_issue_pt_cmd(xpt_cmd); 742 rc = target_xcopy_issue_pt_cmd(xpt_cmd);
731 if (rc < 0) { 743 if (rc < 0) {
744 ec_cmd->scsi_status = xpt_cmd->se_cmd.scsi_status;
732 se_cmd->se_cmd_flags &= ~SCF_PASSTHROUGH_SG_TO_MEM_NOALLOC; 745 se_cmd->se_cmd_flags &= ~SCF_PASSTHROUGH_SG_TO_MEM_NOALLOC;
733 transport_generic_free_cmd(se_cmd, 0); 746 transport_generic_free_cmd(se_cmd, 0);
734 return rc; 747 return rc;
@@ -815,9 +828,14 @@ static void target_xcopy_do_work(struct work_struct *work)
815out: 828out:
816 xcopy_pt_undepend_remotedev(xop); 829 xcopy_pt_undepend_remotedev(xop);
817 kfree(xop); 830 kfree(xop);
818 831 /*
819 pr_warn("target_xcopy_do_work: Setting X-COPY CHECK_CONDITION -> sending response\n"); 832 * Don't override an error scsi status if it has already been set
820 ec_cmd->scsi_status = SAM_STAT_CHECK_CONDITION; 833 */
834 if (ec_cmd->scsi_status == SAM_STAT_GOOD) {
835 pr_warn_ratelimited("target_xcopy_do_work: rc: %d, Setting X-COPY"
836 " CHECK_CONDITION -> sending response\n", rc);
837 ec_cmd->scsi_status = SAM_STAT_CHECK_CONDITION;
838 }
821 target_complete_cmd(ec_cmd, SAM_STAT_CHECK_CONDITION); 839 target_complete_cmd(ec_cmd, SAM_STAT_CHECK_CONDITION);
822} 840}
823 841
@@ -875,7 +893,7 @@ sense_reason_t target_do_xcopy(struct se_cmd *se_cmd)
875 " tdll: %hu sdll: %u inline_dl: %u\n", list_id, list_id_usage, 893 " tdll: %hu sdll: %u inline_dl: %u\n", list_id, list_id_usage,
876 tdll, sdll, inline_dl); 894 tdll, sdll, inline_dl);
877 895
878 rc = target_xcopy_parse_target_descriptors(se_cmd, xop, &p[16], tdll); 896 rc = target_xcopy_parse_target_descriptors(se_cmd, xop, &p[16], tdll, &ret);
879 if (rc <= 0) 897 if (rc <= 0)
880 goto out; 898 goto out;
881 899
diff --git a/drivers/target/tcm_fc/tfc_cmd.c b/drivers/target/tcm_fc/tfc_cmd.c
index 216e18cc9133..ff5de9a96643 100644
--- a/drivers/target/tcm_fc/tfc_cmd.c
+++ b/drivers/target/tcm_fc/tfc_cmd.c
@@ -572,10 +572,10 @@ static void ft_send_work(struct work_struct *work)
572 if (target_submit_cmd(&cmd->se_cmd, cmd->sess->se_sess, fcp->fc_cdb, 572 if (target_submit_cmd(&cmd->se_cmd, cmd->sess->se_sess, fcp->fc_cdb,
573 &cmd->ft_sense_buffer[0], scsilun_to_int(&fcp->fc_lun), 573 &cmd->ft_sense_buffer[0], scsilun_to_int(&fcp->fc_lun),
574 ntohl(fcp->fc_dl), task_attr, data_dir, 574 ntohl(fcp->fc_dl), task_attr, data_dir,
575 TARGET_SCF_ACK_KREF)) 575 TARGET_SCF_ACK_KREF | TARGET_SCF_USE_CPUID))
576 goto err; 576 goto err;
577 577
578 pr_debug("r_ctl %x alloc target_submit_cmd\n", fh->fh_r_ctl); 578 pr_debug("r_ctl %x target_submit_cmd %p\n", fh->fh_r_ctl, cmd);
579 return; 579 return;
580 580
581err: 581err:
diff --git a/drivers/target/tcm_fc/tfc_sess.c b/drivers/target/tcm_fc/tfc_sess.c
index 6ffbb603d912..fd5c3de79470 100644
--- a/drivers/target/tcm_fc/tfc_sess.c
+++ b/drivers/target/tcm_fc/tfc_sess.c
@@ -39,6 +39,11 @@
39 39
40#include "tcm_fc.h" 40#include "tcm_fc.h"
41 41
42#define TFC_SESS_DBG(lport, fmt, args...) \
43 pr_debug("host%u: rport %6.6x: " fmt, \
44 (lport)->host->host_no, \
45 (lport)->port_id, ##args )
46
42static void ft_sess_delete_all(struct ft_tport *); 47static void ft_sess_delete_all(struct ft_tport *);
43 48
44/* 49/*
@@ -167,24 +172,29 @@ static struct ft_sess *ft_sess_get(struct fc_lport *lport, u32 port_id)
167 struct ft_tport *tport; 172 struct ft_tport *tport;
168 struct hlist_head *head; 173 struct hlist_head *head;
169 struct ft_sess *sess; 174 struct ft_sess *sess;
175 char *reason = "no session created";
170 176
171 rcu_read_lock(); 177 rcu_read_lock();
172 tport = rcu_dereference(lport->prov[FC_TYPE_FCP]); 178 tport = rcu_dereference(lport->prov[FC_TYPE_FCP]);
173 if (!tport) 179 if (!tport) {
180 reason = "not an FCP port";
174 goto out; 181 goto out;
182 }
175 183
176 head = &tport->hash[ft_sess_hash(port_id)]; 184 head = &tport->hash[ft_sess_hash(port_id)];
177 hlist_for_each_entry_rcu(sess, head, hash) { 185 hlist_for_each_entry_rcu(sess, head, hash) {
178 if (sess->port_id == port_id) { 186 if (sess->port_id == port_id) {
179 kref_get(&sess->kref); 187 kref_get(&sess->kref);
180 rcu_read_unlock(); 188 rcu_read_unlock();
181 pr_debug("port_id %x found %p\n", port_id, sess); 189 TFC_SESS_DBG(lport, "port_id %x found %p\n",
190 port_id, sess);
182 return sess; 191 return sess;
183 } 192 }
184 } 193 }
185out: 194out:
186 rcu_read_unlock(); 195 rcu_read_unlock();
187 pr_debug("port_id %x not found\n", port_id); 196 TFC_SESS_DBG(lport, "port_id %x not found, %s\n",
197 port_id, reason);
188 return NULL; 198 return NULL;
189} 199}
190 200
@@ -195,7 +205,7 @@ static int ft_sess_alloc_cb(struct se_portal_group *se_tpg,
195 struct ft_tport *tport = sess->tport; 205 struct ft_tport *tport = sess->tport;
196 struct hlist_head *head = &tport->hash[ft_sess_hash(sess->port_id)]; 206 struct hlist_head *head = &tport->hash[ft_sess_hash(sess->port_id)];
197 207
198 pr_debug("port_id %x sess %p\n", sess->port_id, sess); 208 TFC_SESS_DBG(tport->lport, "port_id %x sess %p\n", sess->port_id, sess);
199 hlist_add_head_rcu(&sess->hash, head); 209 hlist_add_head_rcu(&sess->hash, head);
200 tport->sess_count++; 210 tport->sess_count++;
201 211
@@ -223,7 +233,7 @@ static struct ft_sess *ft_sess_create(struct ft_tport *tport, u32 port_id,
223 233
224 sess = kzalloc(sizeof(*sess), GFP_KERNEL); 234 sess = kzalloc(sizeof(*sess), GFP_KERNEL);
225 if (!sess) 235 if (!sess)
226 return NULL; 236 return ERR_PTR(-ENOMEM);
227 237
228 kref_init(&sess->kref); /* ref for table entry */ 238 kref_init(&sess->kref); /* ref for table entry */
229 sess->tport = tport; 239 sess->tport = tport;
@@ -234,8 +244,9 @@ static struct ft_sess *ft_sess_create(struct ft_tport *tport, u32 port_id,
234 TARGET_PROT_NORMAL, &initiatorname[0], 244 TARGET_PROT_NORMAL, &initiatorname[0],
235 sess, ft_sess_alloc_cb); 245 sess, ft_sess_alloc_cb);
236 if (IS_ERR(sess->se_sess)) { 246 if (IS_ERR(sess->se_sess)) {
247 int rc = PTR_ERR(sess->se_sess);
237 kfree(sess); 248 kfree(sess);
238 return NULL; 249 sess = ERR_PTR(rc);
239 } 250 }
240 return sess; 251 return sess;
241} 252}
@@ -319,7 +330,7 @@ void ft_sess_close(struct se_session *se_sess)
319 mutex_unlock(&ft_lport_lock); 330 mutex_unlock(&ft_lport_lock);
320 return; 331 return;
321 } 332 }
322 pr_debug("port_id %x\n", port_id); 333 TFC_SESS_DBG(sess->tport->lport, "port_id %x close session\n", port_id);
323 ft_sess_unhash(sess); 334 ft_sess_unhash(sess);
324 mutex_unlock(&ft_lport_lock); 335 mutex_unlock(&ft_lport_lock);
325 ft_close_sess(sess); 336 ft_close_sess(sess);
@@ -379,8 +390,13 @@ static int ft_prli_locked(struct fc_rport_priv *rdata, u32 spp_len,
379 if (!(fcp_parm & FCP_SPPF_INIT_FCN)) 390 if (!(fcp_parm & FCP_SPPF_INIT_FCN))
380 return FC_SPP_RESP_CONF; 391 return FC_SPP_RESP_CONF;
381 sess = ft_sess_create(tport, rdata->ids.port_id, rdata); 392 sess = ft_sess_create(tport, rdata->ids.port_id, rdata);
382 if (!sess) 393 if (IS_ERR(sess)) {
383 return FC_SPP_RESP_RES; 394 if (PTR_ERR(sess) == -EACCES) {
395 spp->spp_flags &= ~FC_SPP_EST_IMG_PAIR;
396 return FC_SPP_RESP_CONF;
397 } else
398 return FC_SPP_RESP_RES;
399 }
384 if (!sess->params) 400 if (!sess->params)
385 rdata->prli_count++; 401 rdata->prli_count++;
386 sess->params = fcp_parm; 402 sess->params = fcp_parm;
@@ -423,8 +439,8 @@ static int ft_prli(struct fc_rport_priv *rdata, u32 spp_len,
423 mutex_lock(&ft_lport_lock); 439 mutex_lock(&ft_lport_lock);
424 ret = ft_prli_locked(rdata, spp_len, rspp, spp); 440 ret = ft_prli_locked(rdata, spp_len, rspp, spp);
425 mutex_unlock(&ft_lport_lock); 441 mutex_unlock(&ft_lport_lock);
426 pr_debug("port_id %x flags %x ret %x\n", 442 TFC_SESS_DBG(rdata->local_port, "port_id %x flags %x ret %x\n",
427 rdata->ids.port_id, rspp ? rspp->spp_flags : 0, ret); 443 rdata->ids.port_id, rspp ? rspp->spp_flags : 0, ret);
428 return ret; 444 return ret;
429} 445}
430 446
@@ -477,11 +493,11 @@ static void ft_recv(struct fc_lport *lport, struct fc_frame *fp)
477 struct ft_sess *sess; 493 struct ft_sess *sess;
478 u32 sid = fc_frame_sid(fp); 494 u32 sid = fc_frame_sid(fp);
479 495
480 pr_debug("sid %x\n", sid); 496 TFC_SESS_DBG(lport, "recv sid %x\n", sid);
481 497
482 sess = ft_sess_get(lport, sid); 498 sess = ft_sess_get(lport, sid);
483 if (!sess) { 499 if (!sess) {
484 pr_debug("sid %x sess lookup failed\n", sid); 500 TFC_SESS_DBG(lport, "sid %x sess lookup failed\n", sid);
485 /* TBD XXX - if FCP_CMND, send PRLO */ 501 /* TBD XXX - if FCP_CMND, send PRLO */
486 fc_frame_free(fp); 502 fc_frame_free(fp);
487 return; 503 return;
diff --git a/drivers/thermal/intel_pch_thermal.c b/drivers/thermal/intel_pch_thermal.c
index 9b4815e81b0d..19bf2028e508 100644
--- a/drivers/thermal/intel_pch_thermal.c
+++ b/drivers/thermal/intel_pch_thermal.c
@@ -20,10 +20,13 @@
20#include <linux/types.h> 20#include <linux/types.h>
21#include <linux/init.h> 21#include <linux/init.h>
22#include <linux/pci.h> 22#include <linux/pci.h>
23#include <linux/acpi.h>
23#include <linux/thermal.h> 24#include <linux/thermal.h>
24#include <linux/pm.h> 25#include <linux/pm.h>
25 26
26/* Intel PCH thermal Device IDs */ 27/* Intel PCH thermal Device IDs */
28#define PCH_THERMAL_DID_HSW_1 0x9C24 /* Haswell PCH */
29#define PCH_THERMAL_DID_HSW_2 0x8C24 /* Haswell PCH */
27#define PCH_THERMAL_DID_WPT 0x9CA4 /* Wildcat Point */ 30#define PCH_THERMAL_DID_WPT 0x9CA4 /* Wildcat Point */
28#define PCH_THERMAL_DID_SKL 0x9D31 /* Skylake PCH */ 31#define PCH_THERMAL_DID_SKL 0x9D31 /* Skylake PCH */
29 32
@@ -66,9 +69,53 @@ struct pch_thermal_device {
66 unsigned long crt_temp; 69 unsigned long crt_temp;
67 int hot_trip_id; 70 int hot_trip_id;
68 unsigned long hot_temp; 71 unsigned long hot_temp;
72 int psv_trip_id;
73 unsigned long psv_temp;
69 bool bios_enabled; 74 bool bios_enabled;
70}; 75};
71 76
77#ifdef CONFIG_ACPI
78
79/*
80 * On some platforms, there is a companion ACPI device, which adds
81 * passive trip temperature using _PSV method. There is no specific
82 * passive temperature setting in MMIO interface of this PCI device.
83 */
84static void pch_wpt_add_acpi_psv_trip(struct pch_thermal_device *ptd,
85 int *nr_trips)
86{
87 struct acpi_device *adev;
88
89 ptd->psv_trip_id = -1;
90
91 adev = ACPI_COMPANION(&ptd->pdev->dev);
92 if (adev) {
93 unsigned long long r;
94 acpi_status status;
95
96 status = acpi_evaluate_integer(adev->handle, "_PSV", NULL,
97 &r);
98 if (ACPI_SUCCESS(status)) {
99 unsigned long trip_temp;
100
101 trip_temp = DECI_KELVIN_TO_MILLICELSIUS(r);
102 if (trip_temp) {
103 ptd->psv_temp = trip_temp;
104 ptd->psv_trip_id = *nr_trips;
105 ++(*nr_trips);
106 }
107 }
108 }
109}
110#else
111static void pch_wpt_add_acpi_psv_trip(struct pch_thermal_device *ptd,
112 int *nr_trips)
113{
114 ptd->psv_trip_id = -1;
115
116}
117#endif
118
72static int pch_wpt_init(struct pch_thermal_device *ptd, int *nr_trips) 119static int pch_wpt_init(struct pch_thermal_device *ptd, int *nr_trips)
73{ 120{
74 u8 tsel; 121 u8 tsel;
@@ -119,6 +166,8 @@ read_trips:
119 ++(*nr_trips); 166 ++(*nr_trips);
120 } 167 }
121 168
169 pch_wpt_add_acpi_psv_trip(ptd, nr_trips);
170
122 return 0; 171 return 0;
123} 172}
124 173
@@ -194,6 +243,8 @@ static int pch_get_trip_type(struct thermal_zone_device *tzd, int trip,
194 *type = THERMAL_TRIP_CRITICAL; 243 *type = THERMAL_TRIP_CRITICAL;
195 else if (ptd->hot_trip_id == trip) 244 else if (ptd->hot_trip_id == trip)
196 *type = THERMAL_TRIP_HOT; 245 *type = THERMAL_TRIP_HOT;
246 else if (ptd->psv_trip_id == trip)
247 *type = THERMAL_TRIP_PASSIVE;
197 else 248 else
198 return -EINVAL; 249 return -EINVAL;
199 250
@@ -208,6 +259,8 @@ static int pch_get_trip_temp(struct thermal_zone_device *tzd, int trip, int *tem
208 *temp = ptd->crt_temp; 259 *temp = ptd->crt_temp;
209 else if (ptd->hot_trip_id == trip) 260 else if (ptd->hot_trip_id == trip)
210 *temp = ptd->hot_temp; 261 *temp = ptd->hot_temp;
262 else if (ptd->psv_trip_id == trip)
263 *temp = ptd->psv_temp;
211 else 264 else
212 return -EINVAL; 265 return -EINVAL;
213 266
@@ -242,6 +295,11 @@ static int intel_pch_thermal_probe(struct pci_dev *pdev,
242 ptd->ops = &pch_dev_ops_wpt; 295 ptd->ops = &pch_dev_ops_wpt;
243 dev_name = "pch_skylake"; 296 dev_name = "pch_skylake";
244 break; 297 break;
298 case PCH_THERMAL_DID_HSW_1:
299 case PCH_THERMAL_DID_HSW_2:
300 ptd->ops = &pch_dev_ops_wpt;
301 dev_name = "pch_haswell";
302 break;
245 default: 303 default:
246 dev_err(&pdev->dev, "unknown pch thermal device\n"); 304 dev_err(&pdev->dev, "unknown pch thermal device\n");
247 return -ENODEV; 305 return -ENODEV;
@@ -324,6 +382,8 @@ static int intel_pch_thermal_resume(struct device *device)
324static struct pci_device_id intel_pch_thermal_id[] = { 382static struct pci_device_id intel_pch_thermal_id[] = {
325 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCH_THERMAL_DID_WPT) }, 383 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCH_THERMAL_DID_WPT) },
326 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCH_THERMAL_DID_SKL) }, 384 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCH_THERMAL_DID_SKL) },
385 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCH_THERMAL_DID_HSW_1) },
386 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCH_THERMAL_DID_HSW_2) },
327 { 0, }, 387 { 0, },
328}; 388};
329MODULE_DEVICE_TABLE(pci, intel_pch_thermal_id); 389MODULE_DEVICE_TABLE(pci, intel_pch_thermal_id);
diff --git a/drivers/thermal/intel_powerclamp.c b/drivers/thermal/intel_powerclamp.c
index 0e4dc0afcfd2..afada655f861 100644
--- a/drivers/thermal/intel_powerclamp.c
+++ b/drivers/thermal/intel_powerclamp.c
@@ -669,20 +669,17 @@ static struct thermal_cooling_device_ops powerclamp_cooling_ops = {
669 .set_cur_state = powerclamp_set_cur_state, 669 .set_cur_state = powerclamp_set_cur_state,
670}; 670};
671 671
672static const struct x86_cpu_id intel_powerclamp_ids[] __initconst = { 672static const struct x86_cpu_id __initconst intel_powerclamp_ids[] = {
673 { X86_VENDOR_INTEL, X86_FAMILY_ANY, X86_MODEL_ANY, X86_FEATURE_MWAIT }, 673 { X86_VENDOR_INTEL, X86_FAMILY_ANY, X86_MODEL_ANY, X86_FEATURE_MWAIT },
674 { X86_VENDOR_INTEL, X86_FAMILY_ANY, X86_MODEL_ANY, X86_FEATURE_ARAT },
675 { X86_VENDOR_INTEL, X86_FAMILY_ANY, X86_MODEL_ANY, X86_FEATURE_NONSTOP_TSC },
676 { X86_VENDOR_INTEL, X86_FAMILY_ANY, X86_MODEL_ANY, X86_FEATURE_CONSTANT_TSC},
677 {} 674 {}
678}; 675};
679MODULE_DEVICE_TABLE(x86cpu, intel_powerclamp_ids); 676MODULE_DEVICE_TABLE(x86cpu, intel_powerclamp_ids);
680 677
681static int __init powerclamp_probe(void) 678static int __init powerclamp_probe(void)
682{ 679{
680
683 if (!x86_match_cpu(intel_powerclamp_ids)) { 681 if (!x86_match_cpu(intel_powerclamp_ids)) {
684 pr_err("Intel powerclamp does not run on family %d model %d\n", 682 pr_err("CPU does not support MWAIT");
685 boot_cpu_data.x86, boot_cpu_data.x86_model);
686 return -ENODEV; 683 return -ENODEV;
687 } 684 }
688 685
diff --git a/drivers/tty/serial/8250/8250_lpss.c b/drivers/tty/serial/8250/8250_lpss.c
index 886fcf37f291..b9923464599f 100644
--- a/drivers/tty/serial/8250/8250_lpss.c
+++ b/drivers/tty/serial/8250/8250_lpss.c
@@ -213,7 +213,7 @@ static int qrk_serial_setup(struct lpss8250 *lpss, struct uart_port *port)
213 struct pci_dev *pdev = to_pci_dev(port->dev); 213 struct pci_dev *pdev = to_pci_dev(port->dev);
214 int ret; 214 int ret;
215 215
216 ret = pci_alloc_irq_vectors(pdev, 1, 1, 0); 216 ret = pci_alloc_irq_vectors(pdev, 1, 1, PCI_IRQ_ALL_TYPES);
217 if (ret < 0) 217 if (ret < 0)
218 return ret; 218 return ret;
219 219
diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
index 1bfb6fdbaa20..1731b98d2471 100644
--- a/drivers/tty/serial/8250/8250_port.c
+++ b/drivers/tty/serial/8250/8250_port.c
@@ -83,7 +83,8 @@ static const struct serial8250_config uart_config[] = {
83 .name = "16550A", 83 .name = "16550A",
84 .fifo_size = 16, 84 .fifo_size = 16,
85 .tx_loadsz = 16, 85 .tx_loadsz = 16,
86 .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10, 86 .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10 |
87 UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT,
87 .rxtrig_bytes = {1, 4, 8, 14}, 88 .rxtrig_bytes = {1, 4, 8, 14},
88 .flags = UART_CAP_FIFO, 89 .flags = UART_CAP_FIFO,
89 }, 90 },
diff --git a/drivers/tty/serial/8250/8250_uniphier.c b/drivers/tty/serial/8250/8250_uniphier.c
index b8d9c8c9d02a..417d9e7038e1 100644
--- a/drivers/tty/serial/8250/8250_uniphier.c
+++ b/drivers/tty/serial/8250/8250_uniphier.c
@@ -99,7 +99,7 @@ static void uniphier_serial_out(struct uart_port *p, int offset, int value)
99 case UART_LCR: 99 case UART_LCR:
100 valshift = UNIPHIER_UART_LCR_SHIFT; 100 valshift = UNIPHIER_UART_LCR_SHIFT;
101 /* Divisor latch access bit does not exist. */ 101 /* Divisor latch access bit does not exist. */
102 value &= ~(UART_LCR_DLAB << valshift); 102 value &= ~UART_LCR_DLAB;
103 /* fall through */ 103 /* fall through */
104 case UART_MCR: 104 case UART_MCR:
105 offset = UNIPHIER_UART_LCR_MCR; 105 offset = UNIPHIER_UART_LCR_MCR;
@@ -199,7 +199,7 @@ static int uniphier_uart_probe(struct platform_device *pdev)
199 199
200 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0); 200 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
201 if (!regs) { 201 if (!regs) {
202 dev_err(dev, "failed to get memory resource"); 202 dev_err(dev, "failed to get memory resource\n");
203 return -EINVAL; 203 return -EINVAL;
204 } 204 }
205 205
diff --git a/drivers/tty/serial/Kconfig b/drivers/tty/serial/Kconfig
index c7831407a882..25c1d7bc0100 100644
--- a/drivers/tty/serial/Kconfig
+++ b/drivers/tty/serial/Kconfig
@@ -1625,6 +1625,7 @@ config SERIAL_SPRD_CONSOLE
1625config SERIAL_STM32 1625config SERIAL_STM32
1626 tristate "STMicroelectronics STM32 serial port support" 1626 tristate "STMicroelectronics STM32 serial port support"
1627 select SERIAL_CORE 1627 select SERIAL_CORE
1628 depends on HAS_DMA
1628 depends on ARM || COMPILE_TEST 1629 depends on ARM || COMPILE_TEST
1629 help 1630 help
1630 This driver is for the on-chip Serial Controller on 1631 This driver is for the on-chip Serial Controller on
diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c
index fd8aa1f4ba78..168b10cad47b 100644
--- a/drivers/tty/serial/atmel_serial.c
+++ b/drivers/tty/serial/atmel_serial.c
@@ -2132,11 +2132,29 @@ static void atmel_set_termios(struct uart_port *port, struct ktermios *termios,
2132 mode |= ATMEL_US_USMODE_RS485; 2132 mode |= ATMEL_US_USMODE_RS485;
2133 } else if (termios->c_cflag & CRTSCTS) { 2133 } else if (termios->c_cflag & CRTSCTS) {
2134 /* RS232 with hardware handshake (RTS/CTS) */ 2134 /* RS232 with hardware handshake (RTS/CTS) */
2135 if (atmel_use_dma_rx(port) && !atmel_use_fifo(port)) { 2135 if (atmel_use_fifo(port) &&
2136 dev_info(port->dev, "not enabling hardware flow control because DMA is used"); 2136 !mctrl_gpio_to_gpiod(atmel_port->gpios, UART_GPIO_CTS)) {
2137 termios->c_cflag &= ~CRTSCTS; 2137 /*
2138 } else { 2138 * with ATMEL_US_USMODE_HWHS set, the controller will
2139 * be able to drive the RTS pin high/low when the RX
2140 * FIFO is above RXFTHRES/below RXFTHRES2.
2141 * It will also disable the transmitter when the CTS
2142 * pin is high.
2143 * This mode is not activated if CTS pin is a GPIO
2144 * because in this case, the transmitter is always
2145 * disabled (there must be an internal pull-up
2146 * responsible for this behaviour).
2147 * If the RTS pin is a GPIO, the controller won't be
2148 * able to drive it according to the FIFO thresholds,
2149 * but it will be handled by the driver.
2150 */
2139 mode |= ATMEL_US_USMODE_HWHS; 2151 mode |= ATMEL_US_USMODE_HWHS;
2152 } else {
2153 /*
2154 * For platforms without FIFO, the flow control is
2155 * handled by the driver.
2156 */
2157 mode |= ATMEL_US_USMODE_NORMAL;
2140 } 2158 }
2141 } else { 2159 } else {
2142 /* RS232 without hadware handshake */ 2160 /* RS232 without hadware handshake */
diff --git a/drivers/tty/serial/fsl_lpuart.c b/drivers/tty/serial/fsl_lpuart.c
index de9d5107c00a..76103f2c4a80 100644
--- a/drivers/tty/serial/fsl_lpuart.c
+++ b/drivers/tty/serial/fsl_lpuart.c
@@ -328,7 +328,7 @@ static void lpuart_dma_tx(struct lpuart_port *sport)
328 328
329 sport->dma_tx_bytes = uart_circ_chars_pending(xmit); 329 sport->dma_tx_bytes = uart_circ_chars_pending(xmit);
330 330
331 if (xmit->tail < xmit->head) { 331 if (xmit->tail < xmit->head || xmit->head == 0) {
332 sport->dma_tx_nents = 1; 332 sport->dma_tx_nents = 1;
333 sg_init_one(sgl, xmit->buf + xmit->tail, sport->dma_tx_bytes); 333 sg_init_one(sgl, xmit->buf + xmit->tail, sport->dma_tx_bytes);
334 } else { 334 } else {
@@ -359,7 +359,6 @@ static void lpuart_dma_tx(struct lpuart_port *sport)
359 sport->dma_tx_in_progress = true; 359 sport->dma_tx_in_progress = true;
360 sport->dma_tx_cookie = dmaengine_submit(sport->dma_tx_desc); 360 sport->dma_tx_cookie = dmaengine_submit(sport->dma_tx_desc);
361 dma_async_issue_pending(sport->dma_tx_chan); 361 dma_async_issue_pending(sport->dma_tx_chan);
362
363} 362}
364 363
365static void lpuart_dma_tx_complete(void *arg) 364static void lpuart_dma_tx_complete(void *arg)
diff --git a/drivers/tty/serial/pch_uart.c b/drivers/tty/serial/pch_uart.c
index d391650b82e7..42caccb5e87e 100644
--- a/drivers/tty/serial/pch_uart.c
+++ b/drivers/tty/serial/pch_uart.c
@@ -419,6 +419,7 @@ static struct dmi_system_id pch_uart_dmi_table[] = {
419 }, 419 },
420 (void *)MINNOW_UARTCLK, 420 (void *)MINNOW_UARTCLK,
421 }, 421 },
422 { }
422}; 423};
423 424
424/* Return UART clock, checking for board specific clocks. */ 425/* Return UART clock, checking for board specific clocks. */
diff --git a/drivers/tty/serial/sc16is7xx.c b/drivers/tty/serial/sc16is7xx.c
index 2675792a8f59..fb0672554123 100644
--- a/drivers/tty/serial/sc16is7xx.c
+++ b/drivers/tty/serial/sc16is7xx.c
@@ -1130,9 +1130,13 @@ static int sc16is7xx_gpio_direction_output(struct gpio_chip *chip,
1130{ 1130{
1131 struct sc16is7xx_port *s = gpiochip_get_data(chip); 1131 struct sc16is7xx_port *s = gpiochip_get_data(chip);
1132 struct uart_port *port = &s->p[0].port; 1132 struct uart_port *port = &s->p[0].port;
1133 u8 state = sc16is7xx_port_read(port, SC16IS7XX_IOSTATE_REG);
1133 1134
1134 sc16is7xx_port_update(port, SC16IS7XX_IOSTATE_REG, BIT(offset), 1135 if (val)
1135 val ? BIT(offset) : 0); 1136 state |= BIT(offset);
1137 else
1138 state &= ~BIT(offset);
1139 sc16is7xx_port_write(port, SC16IS7XX_IOSTATE_REG, state);
1136 sc16is7xx_port_update(port, SC16IS7XX_IODIR_REG, BIT(offset), 1140 sc16is7xx_port_update(port, SC16IS7XX_IODIR_REG, BIT(offset),
1137 BIT(offset)); 1141 BIT(offset));
1138 1142
diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index 6e4f63627479..f2303f390345 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -111,7 +111,7 @@ void uart_write_wakeup(struct uart_port *port)
111 * closed. No cookie for you. 111 * closed. No cookie for you.
112 */ 112 */
113 BUG_ON(!state); 113 BUG_ON(!state);
114 tty_wakeup(state->port.tty); 114 tty_port_tty_wakeup(&state->port);
115} 115}
116 116
117static void uart_stop(struct tty_struct *tty) 117static void uart_stop(struct tty_struct *tty)
@@ -632,7 +632,7 @@ static void uart_flush_buffer(struct tty_struct *tty)
632 if (port->ops->flush_buffer) 632 if (port->ops->flush_buffer)
633 port->ops->flush_buffer(port); 633 port->ops->flush_buffer(port);
634 uart_port_unlock(port, flags); 634 uart_port_unlock(port, flags);
635 tty_wakeup(tty); 635 tty_port_tty_wakeup(&state->port);
636} 636}
637 637
638/* 638/*
@@ -2746,8 +2746,6 @@ int uart_add_one_port(struct uart_driver *drv, struct uart_port *uport)
2746 uport->cons = drv->cons; 2746 uport->cons = drv->cons;
2747 uport->minor = drv->tty_driver->minor_start + uport->line; 2747 uport->minor = drv->tty_driver->minor_start + uport->line;
2748 2748
2749 port->console = uart_console(uport);
2750
2751 /* 2749 /*
2752 * If this port is a console, then the spinlock is already 2750 * If this port is a console, then the spinlock is already
2753 * initialised. 2751 * initialised.
@@ -2761,6 +2759,8 @@ int uart_add_one_port(struct uart_driver *drv, struct uart_port *uport)
2761 2759
2762 uart_configure_port(drv, state, uport); 2760 uart_configure_port(drv, state, uport);
2763 2761
2762 port->console = uart_console(uport);
2763
2764 num_groups = 2; 2764 num_groups = 2;
2765 if (uport->attr_group) 2765 if (uport->attr_group)
2766 num_groups++; 2766 num_groups++;
diff --git a/drivers/tty/serial/stm32-usart.h b/drivers/tty/serial/stm32-usart.h
index 41d974923102..cd97ceb76e4f 100644
--- a/drivers/tty/serial/stm32-usart.h
+++ b/drivers/tty/serial/stm32-usart.h
@@ -31,7 +31,7 @@ struct stm32_usart_info {
31 struct stm32_usart_config cfg; 31 struct stm32_usart_config cfg;
32}; 32};
33 33
34#define UNDEF_REG ~0 34#define UNDEF_REG 0xff
35 35
36/* Register offsets */ 36/* Register offsets */
37struct stm32_usart_info stm32f4_info = { 37struct stm32_usart_info stm32f4_info = {
diff --git a/drivers/tty/serial/xilinx_uartps.c b/drivers/tty/serial/xilinx_uartps.c
index f37edaa5ac75..dd4c02fa4820 100644
--- a/drivers/tty/serial/xilinx_uartps.c
+++ b/drivers/tty/serial/xilinx_uartps.c
@@ -1200,6 +1200,7 @@ static int __init cdns_early_console_setup(struct earlycon_device *device,
1200OF_EARLYCON_DECLARE(cdns, "xlnx,xuartps", cdns_early_console_setup); 1200OF_EARLYCON_DECLARE(cdns, "xlnx,xuartps", cdns_early_console_setup);
1201OF_EARLYCON_DECLARE(cdns, "cdns,uart-r1p8", cdns_early_console_setup); 1201OF_EARLYCON_DECLARE(cdns, "cdns,uart-r1p8", cdns_early_console_setup);
1202OF_EARLYCON_DECLARE(cdns, "cdns,uart-r1p12", cdns_early_console_setup); 1202OF_EARLYCON_DECLARE(cdns, "cdns,uart-r1p12", cdns_early_console_setup);
1203OF_EARLYCON_DECLARE(cdns, "xlnx,zynqmp-uart", cdns_early_console_setup);
1203 1204
1204/** 1205/**
1205 * cdns_uart_console_write - perform write operation 1206 * cdns_uart_console_write - perform write operation
@@ -1438,6 +1439,7 @@ static const struct of_device_id cdns_uart_of_match[] = {
1438 { .compatible = "xlnx,xuartps", }, 1439 { .compatible = "xlnx,xuartps", },
1439 { .compatible = "cdns,uart-r1p8", }, 1440 { .compatible = "cdns,uart-r1p8", },
1440 { .compatible = "cdns,uart-r1p12", .data = &zynqmp_uart_def }, 1441 { .compatible = "cdns,uart-r1p12", .data = &zynqmp_uart_def },
1442 { .compatible = "xlnx,zynqmp-uart", .data = &zynqmp_uart_def },
1441 {} 1443 {}
1442}; 1444};
1443MODULE_DEVICE_TABLE(of, cdns_uart_of_match); 1445MODULE_DEVICE_TABLE(of, cdns_uart_of_match);
diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c
index 06fb39c1d6dd..8c3bf3d613c0 100644
--- a/drivers/tty/vt/vt.c
+++ b/drivers/tty/vt/vt.c
@@ -870,10 +870,15 @@ static int vc_do_resize(struct tty_struct *tty, struct vc_data *vc,
870 if (new_cols == vc->vc_cols && new_rows == vc->vc_rows) 870 if (new_cols == vc->vc_cols && new_rows == vc->vc_rows)
871 return 0; 871 return 0;
872 872
873 if (new_screen_size > (4 << 20))
874 return -EINVAL;
873 newscreen = kmalloc(new_screen_size, GFP_USER); 875 newscreen = kmalloc(new_screen_size, GFP_USER);
874 if (!newscreen) 876 if (!newscreen)
875 return -ENOMEM; 877 return -ENOMEM;
876 878
879 if (vc == sel_cons)
880 clear_selection();
881
877 old_rows = vc->vc_rows; 882 old_rows = vc->vc_rows;
878 old_row_size = vc->vc_size_row; 883 old_row_size = vc->vc_size_row;
879 884
@@ -1176,7 +1181,7 @@ static void csi_J(struct vc_data *vc, int vpar)
1176 break; 1181 break;
1177 case 3: /* erase scroll-back buffer (and whole display) */ 1182 case 3: /* erase scroll-back buffer (and whole display) */
1178 scr_memsetw(vc->vc_screenbuf, vc->vc_video_erase_char, 1183 scr_memsetw(vc->vc_screenbuf, vc->vc_video_erase_char,
1179 vc->vc_screenbuf_size >> 1); 1184 vc->vc_screenbuf_size);
1180 set_origin(vc); 1185 set_origin(vc);
1181 if (con_is_visible(vc)) 1186 if (con_is_visible(vc))
1182 update_screen(vc); 1187 update_screen(vc);
diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c
index 69426e644d17..3dbb4a21ab44 100644
--- a/drivers/usb/chipidea/core.c
+++ b/drivers/usb/chipidea/core.c
@@ -914,6 +914,7 @@ static int ci_hdrc_probe(struct platform_device *pdev)
914 if (!ci) 914 if (!ci)
915 return -ENOMEM; 915 return -ENOMEM;
916 916
917 spin_lock_init(&ci->lock);
917 ci->dev = dev; 918 ci->dev = dev;
918 ci->platdata = dev_get_platdata(dev); 919 ci->platdata = dev_get_platdata(dev);
919 ci->imx28_write_fix = !!(ci->platdata->flags & 920 ci->imx28_write_fix = !!(ci->platdata->flags &
diff --git a/drivers/usb/chipidea/host.c b/drivers/usb/chipidea/host.c
index 96ae69502c86..111b0e0b8698 100644
--- a/drivers/usb/chipidea/host.c
+++ b/drivers/usb/chipidea/host.c
@@ -188,6 +188,8 @@ static void host_stop(struct ci_hdrc *ci)
188 188
189 if (hcd) { 189 if (hcd) {
190 usb_remove_hcd(hcd); 190 usb_remove_hcd(hcd);
191 ci->role = CI_ROLE_END;
192 synchronize_irq(ci->irq);
191 usb_put_hcd(hcd); 193 usb_put_hcd(hcd);
192 if (ci->platdata->reg_vbus && !ci_otg_is_fsm_mode(ci) && 194 if (ci->platdata->reg_vbus && !ci_otg_is_fsm_mode(ci) &&
193 (ci->platdata->flags & CI_HDRC_TURN_VBUS_EARLY_ON)) 195 (ci->platdata->flags & CI_HDRC_TURN_VBUS_EARLY_ON))
diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c
index 661f43fe0f9e..c9e80ad48fdc 100644
--- a/drivers/usb/chipidea/udc.c
+++ b/drivers/usb/chipidea/udc.c
@@ -1889,8 +1889,6 @@ static int udc_start(struct ci_hdrc *ci)
1889 struct usb_otg_caps *otg_caps = &ci->platdata->ci_otg_caps; 1889 struct usb_otg_caps *otg_caps = &ci->platdata->ci_otg_caps;
1890 int retval = 0; 1890 int retval = 0;
1891 1891
1892 spin_lock_init(&ci->lock);
1893
1894 ci->gadget.ops = &usb_gadget_ops; 1892 ci->gadget.ops = &usb_gadget_ops;
1895 ci->gadget.speed = USB_SPEED_UNKNOWN; 1893 ci->gadget.speed = USB_SPEED_UNKNOWN;
1896 ci->gadget.max_speed = USB_SPEED_HIGH; 1894 ci->gadget.max_speed = USB_SPEED_HIGH;
diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
index 78f0f85bebdc..fada988512a1 100644
--- a/drivers/usb/class/cdc-acm.c
+++ b/drivers/usb/class/cdc-acm.c
@@ -932,8 +932,6 @@ static int wait_serial_change(struct acm *acm, unsigned long arg)
932 DECLARE_WAITQUEUE(wait, current); 932 DECLARE_WAITQUEUE(wait, current);
933 struct async_icount old, new; 933 struct async_icount old, new;
934 934
935 if (arg & (TIOCM_DSR | TIOCM_RI | TIOCM_CD))
936 return -EINVAL;
937 do { 935 do {
938 spin_lock_irq(&acm->read_lock); 936 spin_lock_irq(&acm->read_lock);
939 old = acm->oldcount; 937 old = acm->oldcount;
@@ -1161,6 +1159,8 @@ static int acm_probe(struct usb_interface *intf,
1161 if (quirks == IGNORE_DEVICE) 1159 if (quirks == IGNORE_DEVICE)
1162 return -ENODEV; 1160 return -ENODEV;
1163 1161
1162 memset(&h, 0x00, sizeof(struct usb_cdc_parsed_header));
1163
1164 num_rx_buf = (quirks == SINGLE_RX_URB) ? 1 : ACM_NR; 1164 num_rx_buf = (quirks == SINGLE_RX_URB) ? 1 : ACM_NR;
1165 1165
1166 /* handle quirks deadly to normal probing*/ 1166 /* handle quirks deadly to normal probing*/
diff --git a/drivers/usb/dwc2/core.c b/drivers/usb/dwc2/core.c
index fa9b26b91507..4c0fa0b17353 100644
--- a/drivers/usb/dwc2/core.c
+++ b/drivers/usb/dwc2/core.c
@@ -463,9 +463,18 @@ static void dwc2_clear_force_mode(struct dwc2_hsotg *hsotg)
463 */ 463 */
464void dwc2_force_dr_mode(struct dwc2_hsotg *hsotg) 464void dwc2_force_dr_mode(struct dwc2_hsotg *hsotg)
465{ 465{
466 bool ret;
467
466 switch (hsotg->dr_mode) { 468 switch (hsotg->dr_mode) {
467 case USB_DR_MODE_HOST: 469 case USB_DR_MODE_HOST:
468 dwc2_force_mode(hsotg, true); 470 ret = dwc2_force_mode(hsotg, true);
471 /*
472 * NOTE: This is required for some rockchip soc based
473 * platforms on their host-only dwc2.
474 */
475 if (!ret)
476 msleep(50);
477
469 break; 478 break;
470 case USB_DR_MODE_PERIPHERAL: 479 case USB_DR_MODE_PERIPHERAL:
471 dwc2_force_mode(hsotg, false); 480 dwc2_force_mode(hsotg, false);
diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h
index aad4107ef927..2a21a0414b1d 100644
--- a/drivers/usb/dwc2/core.h
+++ b/drivers/usb/dwc2/core.h
@@ -259,6 +259,13 @@ enum dwc2_lx_state {
259 DWC2_L3, /* Off state */ 259 DWC2_L3, /* Off state */
260}; 260};
261 261
262/*
263 * Gadget periodic tx fifo sizes as used by legacy driver
264 * EP0 is not included
265 */
266#define DWC2_G_P_LEGACY_TX_FIFO_SIZE {256, 256, 256, 256, 768, 768, 768, \
267 768, 0, 0, 0, 0, 0, 0, 0}
268
262/* Gadget ep0 states */ 269/* Gadget ep0 states */
263enum dwc2_ep0_state { 270enum dwc2_ep0_state {
264 DWC2_EP0_SETUP, 271 DWC2_EP0_SETUP,
diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index 4cd6403a7566..24fbebc9b409 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -186,10 +186,9 @@ static void dwc2_hsotg_ctrl_epint(struct dwc2_hsotg *hsotg,
186 */ 186 */
187static void dwc2_hsotg_init_fifo(struct dwc2_hsotg *hsotg) 187static void dwc2_hsotg_init_fifo(struct dwc2_hsotg *hsotg)
188{ 188{
189 unsigned int fifo; 189 unsigned int ep;
190 unsigned int addr; 190 unsigned int addr;
191 int timeout; 191 int timeout;
192 u32 dptxfsizn;
193 u32 val; 192 u32 val;
194 193
195 /* Reset fifo map if not correctly cleared during previous session */ 194 /* Reset fifo map if not correctly cleared during previous session */
@@ -217,16 +216,16 @@ static void dwc2_hsotg_init_fifo(struct dwc2_hsotg *hsotg)
217 * them to endpoints dynamically according to maxpacket size value of 216 * them to endpoints dynamically according to maxpacket size value of
218 * given endpoint. 217 * given endpoint.
219 */ 218 */
220 for (fifo = 1; fifo < MAX_EPS_CHANNELS; fifo++) { 219 for (ep = 1; ep < MAX_EPS_CHANNELS; ep++) {
221 dptxfsizn = dwc2_readl(hsotg->regs + DPTXFSIZN(fifo)); 220 if (!hsotg->g_tx_fifo_sz[ep])
222 221 continue;
223 val = (dptxfsizn & FIFOSIZE_DEPTH_MASK) | addr; 222 val = addr;
224 addr += dptxfsizn >> FIFOSIZE_DEPTH_SHIFT; 223 val |= hsotg->g_tx_fifo_sz[ep] << FIFOSIZE_DEPTH_SHIFT;
225 224 WARN_ONCE(addr + hsotg->g_tx_fifo_sz[ep] > hsotg->fifo_mem,
226 if (addr > hsotg->fifo_mem) 225 "insufficient fifo memory");
227 break; 226 addr += hsotg->g_tx_fifo_sz[ep];
228 227
229 dwc2_writel(val, hsotg->regs + DPTXFSIZN(fifo)); 228 dwc2_writel(val, hsotg->regs + DPTXFSIZN(ep));
230 } 229 }
231 230
232 /* 231 /*
@@ -3807,10 +3806,36 @@ static void dwc2_hsotg_dump(struct dwc2_hsotg *hsotg)
3807static void dwc2_hsotg_of_probe(struct dwc2_hsotg *hsotg) 3806static void dwc2_hsotg_of_probe(struct dwc2_hsotg *hsotg)
3808{ 3807{
3809 struct device_node *np = hsotg->dev->of_node; 3808 struct device_node *np = hsotg->dev->of_node;
3809 u32 len = 0;
3810 u32 i = 0;
3810 3811
3811 /* Enable dma if requested in device tree */ 3812 /* Enable dma if requested in device tree */
3812 hsotg->g_using_dma = of_property_read_bool(np, "g-use-dma"); 3813 hsotg->g_using_dma = of_property_read_bool(np, "g-use-dma");
3813 3814
3815 /*
3816 * Register TX periodic fifo size per endpoint.
3817 * EP0 is excluded since it has no fifo configuration.
3818 */
3819 if (!of_find_property(np, "g-tx-fifo-size", &len))
3820 goto rx_fifo;
3821
3822 len /= sizeof(u32);
3823
3824 /* Read tx fifo sizes other than ep0 */
3825 if (of_property_read_u32_array(np, "g-tx-fifo-size",
3826 &hsotg->g_tx_fifo_sz[1], len))
3827 goto rx_fifo;
3828
3829 /* Add ep0 */
3830 len++;
3831
3832 /* Make remaining TX fifos unavailable */
3833 if (len < MAX_EPS_CHANNELS) {
3834 for (i = len; i < MAX_EPS_CHANNELS; i++)
3835 hsotg->g_tx_fifo_sz[i] = 0;
3836 }
3837
3838rx_fifo:
3814 /* Register RX fifo size */ 3839 /* Register RX fifo size */
3815 of_property_read_u32(np, "g-rx-fifo-size", &hsotg->g_rx_fifo_sz); 3840 of_property_read_u32(np, "g-rx-fifo-size", &hsotg->g_rx_fifo_sz);
3816 3841
@@ -3832,10 +3857,13 @@ int dwc2_gadget_init(struct dwc2_hsotg *hsotg, int irq)
3832 struct device *dev = hsotg->dev; 3857 struct device *dev = hsotg->dev;
3833 int epnum; 3858 int epnum;
3834 int ret; 3859 int ret;
3860 int i;
3861 u32 p_tx_fifo[] = DWC2_G_P_LEGACY_TX_FIFO_SIZE;
3835 3862
3836 /* Initialize to legacy fifo configuration values */ 3863 /* Initialize to legacy fifo configuration values */
3837 hsotg->g_rx_fifo_sz = 2048; 3864 hsotg->g_rx_fifo_sz = 2048;
3838 hsotg->g_np_g_tx_fifo_sz = 1024; 3865 hsotg->g_np_g_tx_fifo_sz = 1024;
3866 memcpy(&hsotg->g_tx_fifo_sz[1], p_tx_fifo, sizeof(p_tx_fifo));
3839 /* Device tree specific probe */ 3867 /* Device tree specific probe */
3840 dwc2_hsotg_of_probe(hsotg); 3868 dwc2_hsotg_of_probe(hsotg);
3841 3869
@@ -3853,6 +3881,9 @@ int dwc2_gadget_init(struct dwc2_hsotg *hsotg, int irq)
3853 dev_dbg(dev, "NonPeriodic TXFIFO size: %d\n", 3881 dev_dbg(dev, "NonPeriodic TXFIFO size: %d\n",
3854 hsotg->g_np_g_tx_fifo_sz); 3882 hsotg->g_np_g_tx_fifo_sz);
3855 dev_dbg(dev, "RXFIFO size: %d\n", hsotg->g_rx_fifo_sz); 3883 dev_dbg(dev, "RXFIFO size: %d\n", hsotg->g_rx_fifo_sz);
3884 for (i = 0; i < MAX_EPS_CHANNELS; i++)
3885 dev_dbg(dev, "Periodic TXFIFO%2d size: %d\n", i,
3886 hsotg->g_tx_fifo_sz[i]);
3856 3887
3857 hsotg->gadget.max_speed = USB_SPEED_HIGH; 3888 hsotg->gadget.max_speed = USB_SPEED_HIGH;
3858 hsotg->gadget.ops = &dwc2_hsotg_gadget_ops; 3889 hsotg->gadget.ops = &dwc2_hsotg_gadget_ops;
diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index 7287a763cd0c..fea446900cad 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -769,15 +769,14 @@ static int dwc3_core_init(struct dwc3 *dwc)
769 return 0; 769 return 0;
770 770
771err4: 771err4:
772 phy_power_off(dwc->usb2_generic_phy); 772 phy_power_off(dwc->usb3_generic_phy);
773 773
774err3: 774err3:
775 phy_power_off(dwc->usb3_generic_phy); 775 phy_power_off(dwc->usb2_generic_phy);
776 776
777err2: 777err2:
778 usb_phy_set_suspend(dwc->usb2_phy, 1); 778 usb_phy_set_suspend(dwc->usb2_phy, 1);
779 usb_phy_set_suspend(dwc->usb3_phy, 1); 779 usb_phy_set_suspend(dwc->usb3_phy, 1);
780 dwc3_core_exit(dwc);
781 780
782err1: 781err1:
783 usb_phy_shutdown(dwc->usb2_phy); 782 usb_phy_shutdown(dwc->usb2_phy);
diff --git a/drivers/usb/dwc3/dwc3-st.c b/drivers/usb/dwc3/dwc3-st.c
index 89a2f712fdfe..aaaf256f71dd 100644
--- a/drivers/usb/dwc3/dwc3-st.c
+++ b/drivers/usb/dwc3/dwc3-st.c
@@ -31,6 +31,7 @@
31#include <linux/slab.h> 31#include <linux/slab.h>
32#include <linux/regmap.h> 32#include <linux/regmap.h>
33#include <linux/reset.h> 33#include <linux/reset.h>
34#include <linux/pinctrl/consumer.h>
34#include <linux/usb/of.h> 35#include <linux/usb/of.h>
35 36
36#include "core.h" 37#include "core.h"
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 07cc8929f271..1dfa56a5f1c5 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -783,6 +783,7 @@ static void dwc3_prepare_one_trb(struct dwc3_ep *dep,
783 req->trb = trb; 783 req->trb = trb;
784 req->trb_dma = dwc3_trb_dma_offset(dep, trb); 784 req->trb_dma = dwc3_trb_dma_offset(dep, trb);
785 req->first_trb_index = dep->trb_enqueue; 785 req->first_trb_index = dep->trb_enqueue;
786 dep->queued_requests++;
786 } 787 }
787 788
788 dwc3_ep_inc_enq(dep); 789 dwc3_ep_inc_enq(dep);
@@ -833,8 +834,6 @@ static void dwc3_prepare_one_trb(struct dwc3_ep *dep,
833 834
834 trb->ctrl |= DWC3_TRB_CTRL_HWO; 835 trb->ctrl |= DWC3_TRB_CTRL_HWO;
835 836
836 dep->queued_requests++;
837
838 trace_dwc3_prepare_trb(dep, trb); 837 trace_dwc3_prepare_trb(dep, trb);
839} 838}
840 839
@@ -1074,9 +1073,17 @@ static int __dwc3_gadget_ep_queue(struct dwc3_ep *dep, struct dwc3_request *req)
1074 1073
1075 list_add_tail(&req->list, &dep->pending_list); 1074 list_add_tail(&req->list, &dep->pending_list);
1076 1075
1077 if (usb_endpoint_xfer_isoc(dep->endpoint.desc) && 1076 /*
1078 dep->flags & DWC3_EP_PENDING_REQUEST) { 1077 * NOTICE: Isochronous endpoints should NEVER be prestarted. We must
1079 if (list_empty(&dep->started_list)) { 1078 * wait for a XferNotReady event so we will know what's the current
1079 * (micro-)frame number.
1080 *
1081 * Without this trick, we are very, very likely gonna get Bus Expiry
1082 * errors which will force us issue EndTransfer command.
1083 */
1084 if (usb_endpoint_xfer_isoc(dep->endpoint.desc)) {
1085 if ((dep->flags & DWC3_EP_PENDING_REQUEST) &&
1086 list_empty(&dep->started_list)) {
1080 dwc3_stop_active_transfer(dwc, dep->number, true); 1087 dwc3_stop_active_transfer(dwc, dep->number, true);
1081 dep->flags = DWC3_EP_ENABLED; 1088 dep->flags = DWC3_EP_ENABLED;
1082 } 1089 }
@@ -1861,8 +1868,11 @@ static int __dwc3_cleanup_done_trbs(struct dwc3 *dwc, struct dwc3_ep *dep,
1861 unsigned int s_pkt = 0; 1868 unsigned int s_pkt = 0;
1862 unsigned int trb_status; 1869 unsigned int trb_status;
1863 1870
1864 dep->queued_requests--;
1865 dwc3_ep_inc_deq(dep); 1871 dwc3_ep_inc_deq(dep);
1872
1873 if (req->trb == trb)
1874 dep->queued_requests--;
1875
1866 trace_dwc3_complete_trb(dep, trb); 1876 trace_dwc3_complete_trb(dep, trb);
1867 1877
1868 /* 1878 /*
@@ -2980,7 +2990,7 @@ err3:
2980 kfree(dwc->setup_buf); 2990 kfree(dwc->setup_buf);
2981 2991
2982err2: 2992err2:
2983 dma_free_coherent(dwc->dev, sizeof(*dwc->ep0_trb), 2993 dma_free_coherent(dwc->dev, sizeof(*dwc->ep0_trb) * 2,
2984 dwc->ep0_trb, dwc->ep0_trb_addr); 2994 dwc->ep0_trb, dwc->ep0_trb_addr);
2985 2995
2986err1: 2996err1:
@@ -3005,7 +3015,7 @@ void dwc3_gadget_exit(struct dwc3 *dwc)
3005 kfree(dwc->setup_buf); 3015 kfree(dwc->setup_buf);
3006 kfree(dwc->zlp_buf); 3016 kfree(dwc->zlp_buf);
3007 3017
3008 dma_free_coherent(dwc->dev, sizeof(*dwc->ep0_trb), 3018 dma_free_coherent(dwc->dev, sizeof(*dwc->ep0_trb) * 2,
3009 dwc->ep0_trb, dwc->ep0_trb_addr); 3019 dwc->ep0_trb, dwc->ep0_trb_addr);
3010 3020
3011 dma_free_coherent(dwc->dev, sizeof(*dwc->ctrl_req), 3021 dma_free_coherent(dwc->dev, sizeof(*dwc->ctrl_req),
diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c
index 54ad100af35b..17989b72cdae 100644
--- a/drivers/usb/gadget/function/f_fs.c
+++ b/drivers/usb/gadget/function/f_fs.c
@@ -136,8 +136,60 @@ struct ffs_epfile {
136 /* 136 /*
137 * Buffer for holding data from partial reads which may happen since 137 * Buffer for holding data from partial reads which may happen since
138 * we’re rounding user read requests to a multiple of a max packet size. 138 * we’re rounding user read requests to a multiple of a max packet size.
139 *
140 * The pointer is initialised with NULL value and may be set by
141 * __ffs_epfile_read_data function to point to a temporary buffer.
142 *
143 * In normal operation, calls to __ffs_epfile_read_buffered will consume
144 * data from said buffer and eventually free it. Importantly, while the
145 * function is using the buffer, it sets the pointer to NULL. This is
146 * all right since __ffs_epfile_read_data and __ffs_epfile_read_buffered
147 * can never run concurrently (they are synchronised by epfile->mutex)
148 * so the latter will not assign a new value to the pointer.
149 *
150 * Meanwhile ffs_func_eps_disable frees the buffer (if the pointer is
151 * valid) and sets the pointer to READ_BUFFER_DROP value. This special
152 * value is crux of the synchronisation between ffs_func_eps_disable and
153 * __ffs_epfile_read_data.
154 *
155 * Once __ffs_epfile_read_data is about to finish it will try to set the
156 * pointer back to its old value (as described above), but seeing as the
157 * pointer is not-NULL (namely READ_BUFFER_DROP) it will instead free
158 * the buffer.
159 *
160 * == State transitions ==
161 *
162 * • ptr == NULL: (initial state)
163 * â—¦ __ffs_epfile_read_buffer_free: go to ptr == DROP
164 * â—¦ __ffs_epfile_read_buffered: nop
165 * â—¦ __ffs_epfile_read_data allocates temp buffer: go to ptr == buf
166 * ◦ reading finishes: n/a, not in ‘and reading’ state
167 * • ptr == DROP:
168 * â—¦ __ffs_epfile_read_buffer_free: nop
169 * â—¦ __ffs_epfile_read_buffered: go to ptr == NULL
170 * â—¦ __ffs_epfile_read_data allocates temp buffer: free buf, nop
171 * ◦ reading finishes: n/a, not in ‘and reading’ state
172 * • ptr == buf:
173 * â—¦ __ffs_epfile_read_buffer_free: free buf, go to ptr == DROP
174 * â—¦ __ffs_epfile_read_buffered: go to ptr == NULL and reading
175 * â—¦ __ffs_epfile_read_data: n/a, __ffs_epfile_read_buffered
176 * is always called first
177 * ◦ reading finishes: n/a, not in ‘and reading’ state
178 * • ptr == NULL and reading:
179 * â—¦ __ffs_epfile_read_buffer_free: go to ptr == DROP and reading
180 * â—¦ __ffs_epfile_read_buffered: n/a, mutex is held
181 * â—¦ __ffs_epfile_read_data: n/a, mutex is held
182 * ◦ reading finishes and …
183 * … all data read: free buf, go to ptr == NULL
184 * … otherwise: go to ptr == buf and reading
185 * • ptr == DROP and reading:
186 * â—¦ __ffs_epfile_read_buffer_free: nop
187 * â—¦ __ffs_epfile_read_buffered: n/a, mutex is held
188 * â—¦ __ffs_epfile_read_data: n/a, mutex is held
189 * â—¦ reading finishes: free buf, go to ptr == DROP
139 */ 190 */
140 struct ffs_buffer *read_buffer; /* P: epfile->mutex */ 191 struct ffs_buffer *read_buffer;
192#define READ_BUFFER_DROP ((struct ffs_buffer *)ERR_PTR(-ESHUTDOWN))
141 193
142 char name[5]; 194 char name[5];
143 195
@@ -736,25 +788,47 @@ static void ffs_epfile_async_io_complete(struct usb_ep *_ep,
736 schedule_work(&io_data->work); 788 schedule_work(&io_data->work);
737} 789}
738 790
791static void __ffs_epfile_read_buffer_free(struct ffs_epfile *epfile)
792{
793 /*
794 * See comment in struct ffs_epfile for full read_buffer pointer
795 * synchronisation story.
796 */
797 struct ffs_buffer *buf = xchg(&epfile->read_buffer, READ_BUFFER_DROP);
798 if (buf && buf != READ_BUFFER_DROP)
799 kfree(buf);
800}
801
739/* Assumes epfile->mutex is held. */ 802/* Assumes epfile->mutex is held. */
740static ssize_t __ffs_epfile_read_buffered(struct ffs_epfile *epfile, 803static ssize_t __ffs_epfile_read_buffered(struct ffs_epfile *epfile,
741 struct iov_iter *iter) 804 struct iov_iter *iter)
742{ 805{
743 struct ffs_buffer *buf = epfile->read_buffer; 806 /*
807 * Null out epfile->read_buffer so ffs_func_eps_disable does not free
808 * the buffer while we are using it. See comment in struct ffs_epfile
809 * for full read_buffer pointer synchronisation story.
810 */
811 struct ffs_buffer *buf = xchg(&epfile->read_buffer, NULL);
744 ssize_t ret; 812 ssize_t ret;
745 if (!buf) 813 if (!buf || buf == READ_BUFFER_DROP)
746 return 0; 814 return 0;
747 815
748 ret = copy_to_iter(buf->data, buf->length, iter); 816 ret = copy_to_iter(buf->data, buf->length, iter);
749 if (buf->length == ret) { 817 if (buf->length == ret) {
750 kfree(buf); 818 kfree(buf);
751 epfile->read_buffer = NULL; 819 return ret;
752 } else if (unlikely(iov_iter_count(iter))) { 820 }
821
822 if (unlikely(iov_iter_count(iter))) {
753 ret = -EFAULT; 823 ret = -EFAULT;
754 } else { 824 } else {
755 buf->length -= ret; 825 buf->length -= ret;
756 buf->data += ret; 826 buf->data += ret;
757 } 827 }
828
829 if (cmpxchg(&epfile->read_buffer, NULL, buf))
830 kfree(buf);
831
758 return ret; 832 return ret;
759} 833}
760 834
@@ -783,7 +857,15 @@ static ssize_t __ffs_epfile_read_data(struct ffs_epfile *epfile,
783 buf->length = data_len; 857 buf->length = data_len;
784 buf->data = buf->storage; 858 buf->data = buf->storage;
785 memcpy(buf->storage, data + ret, data_len); 859 memcpy(buf->storage, data + ret, data_len);
786 epfile->read_buffer = buf; 860
861 /*
862 * At this point read_buffer is NULL or READ_BUFFER_DROP (if
863 * ffs_func_eps_disable has been called in the meanwhile). See comment
864 * in struct ffs_epfile for full read_buffer pointer synchronisation
865 * story.
866 */
867 if (unlikely(cmpxchg(&epfile->read_buffer, NULL, buf)))
868 kfree(buf);
787 869
788 return ret; 870 return ret;
789} 871}
@@ -1097,8 +1179,7 @@ ffs_epfile_release(struct inode *inode, struct file *file)
1097 1179
1098 ENTER(); 1180 ENTER();
1099 1181
1100 kfree(epfile->read_buffer); 1182 __ffs_epfile_read_buffer_free(epfile);
1101 epfile->read_buffer = NULL;
1102 ffs_data_closed(epfile->ffs); 1183 ffs_data_closed(epfile->ffs);
1103 1184
1104 return 0; 1185 return 0;
@@ -1724,24 +1805,20 @@ static void ffs_func_eps_disable(struct ffs_function *func)
1724 unsigned count = func->ffs->eps_count; 1805 unsigned count = func->ffs->eps_count;
1725 unsigned long flags; 1806 unsigned long flags;
1726 1807
1808 spin_lock_irqsave(&func->ffs->eps_lock, flags);
1727 do { 1809 do {
1728 if (epfile)
1729 mutex_lock(&epfile->mutex);
1730 spin_lock_irqsave(&func->ffs->eps_lock, flags);
1731 /* pending requests get nuked */ 1810 /* pending requests get nuked */
1732 if (likely(ep->ep)) 1811 if (likely(ep->ep))
1733 usb_ep_disable(ep->ep); 1812 usb_ep_disable(ep->ep);
1734 ++ep; 1813 ++ep;
1735 spin_unlock_irqrestore(&func->ffs->eps_lock, flags);
1736 1814
1737 if (epfile) { 1815 if (epfile) {
1738 epfile->ep = NULL; 1816 epfile->ep = NULL;
1739 kfree(epfile->read_buffer); 1817 __ffs_epfile_read_buffer_free(epfile);
1740 epfile->read_buffer = NULL;
1741 mutex_unlock(&epfile->mutex);
1742 ++epfile; 1818 ++epfile;
1743 } 1819 }
1744 } while (--count); 1820 } while (--count);
1821 spin_unlock_irqrestore(&func->ffs->eps_lock, flags);
1745} 1822}
1746 1823
1747static int ffs_func_eps_enable(struct ffs_function *func) 1824static int ffs_func_eps_enable(struct ffs_function *func)
@@ -3148,11 +3225,11 @@ static bool ffs_func_req_match(struct usb_function *f,
3148 3225
3149 switch (creq->bRequestType & USB_RECIP_MASK) { 3226 switch (creq->bRequestType & USB_RECIP_MASK) {
3150 case USB_RECIP_INTERFACE: 3227 case USB_RECIP_INTERFACE:
3151 return ffs_func_revmap_intf(func, 3228 return (ffs_func_revmap_intf(func,
3152 le16_to_cpu(creq->wIndex) >= 0); 3229 le16_to_cpu(creq->wIndex)) >= 0);
3153 case USB_RECIP_ENDPOINT: 3230 case USB_RECIP_ENDPOINT:
3154 return ffs_func_revmap_ep(func, 3231 return (ffs_func_revmap_ep(func,
3155 le16_to_cpu(creq->wIndex) >= 0); 3232 le16_to_cpu(creq->wIndex)) >= 0);
3156 default: 3233 default:
3157 return (bool) (func->ffs->user_flags & 3234 return (bool) (func->ffs->user_flags &
3158 FUNCTIONFS_ALL_CTRL_RECIP); 3235 FUNCTIONFS_ALL_CTRL_RECIP);
diff --git a/drivers/usb/gadget/function/u_ether.c b/drivers/usb/gadget/function/u_ether.c
index 9c8c9ed1dc9e..5d1bd13a56c1 100644
--- a/drivers/usb/gadget/function/u_ether.c
+++ b/drivers/usb/gadget/function/u_ether.c
@@ -588,13 +588,6 @@ static netdev_tx_t eth_start_xmit(struct sk_buff *skb,
588 588
589 req->length = length; 589 req->length = length;
590 590
591 /* throttle high/super speed IRQ rate back slightly */
592 if (gadget_is_dualspeed(dev->gadget))
593 req->no_interrupt = (dev->gadget->speed == USB_SPEED_HIGH ||
594 dev->gadget->speed == USB_SPEED_SUPER)
595 ? ((atomic_read(&dev->tx_qlen) % dev->qmult) != 0)
596 : 0;
597
598 retval = usb_ep_queue(in, req, GFP_ATOMIC); 591 retval = usb_ep_queue(in, req, GFP_ATOMIC);
599 switch (retval) { 592 switch (retval) {
600 default: 593 default:
diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.c b/drivers/usb/gadget/udc/atmel_usba_udc.c
index bb1f6c8f0f01..45bc997d0711 100644
--- a/drivers/usb/gadget/udc/atmel_usba_udc.c
+++ b/drivers/usb/gadget/udc/atmel_usba_udc.c
@@ -1978,7 +1978,7 @@ static struct usba_ep * atmel_udc_of_init(struct platform_device *pdev,
1978 dev_err(&pdev->dev, "of_probe: name error(%d)\n", ret); 1978 dev_err(&pdev->dev, "of_probe: name error(%d)\n", ret);
1979 goto err; 1979 goto err;
1980 } 1980 }
1981 ep->ep.name = name; 1981 ep->ep.name = kasprintf(GFP_KERNEL, "ep%d", ep->index);
1982 1982
1983 ep->ep_regs = udc->regs + USBA_EPT_BASE(i); 1983 ep->ep_regs = udc->regs + USBA_EPT_BASE(i);
1984 ep->dma_regs = udc->regs + USBA_DMA_BASE(i); 1984 ep->dma_regs = udc->regs + USBA_DMA_BASE(i);
diff --git a/drivers/usb/host/ehci-platform.c b/drivers/usb/host/ehci-platform.c
index 876dca4fc216..a268d9e8d6cf 100644
--- a/drivers/usb/host/ehci-platform.c
+++ b/drivers/usb/host/ehci-platform.c
@@ -39,7 +39,7 @@
39 39
40#define DRIVER_DESC "EHCI generic platform driver" 40#define DRIVER_DESC "EHCI generic platform driver"
41#define EHCI_MAX_CLKS 4 41#define EHCI_MAX_CLKS 4
42#define EHCI_MAX_RSTS 3 42#define EHCI_MAX_RSTS 4
43#define hcd_to_ehci_priv(h) ((struct ehci_platform_priv *)hcd_to_ehci(h)->priv) 43#define hcd_to_ehci_priv(h) ((struct ehci_platform_priv *)hcd_to_ehci(h)->priv)
44 44
45struct ehci_platform_priv { 45struct ehci_platform_priv {
diff --git a/drivers/usb/host/ohci-at91.c b/drivers/usb/host/ohci-at91.c
index 5b5880c0ae19..b38a228134df 100644
--- a/drivers/usb/host/ohci-at91.c
+++ b/drivers/usb/host/ohci-at91.c
@@ -221,6 +221,12 @@ static int usb_hcd_at91_probe(const struct hc_driver *driver,
221 ohci->num_ports = board->ports; 221 ohci->num_ports = board->ports;
222 at91_start_hc(pdev); 222 at91_start_hc(pdev);
223 223
224 /*
225 * The RemoteWakeupConnected bit has to be set explicitly
226 * before calling ohci_run. The reset value of this bit is 0.
227 */
228 ohci->hc_control = OHCI_CTRL_RWC;
229
224 retval = usb_add_hcd(hcd, irq, IRQF_SHARED); 230 retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
225 if (retval == 0) { 231 if (retval == 0) {
226 device_wakeup_enable(hcd->self.controller); 232 device_wakeup_enable(hcd->self.controller);
@@ -677,9 +683,6 @@ ohci_hcd_at91_drv_suspend(struct device *dev)
677 * REVISIT: some boards will be able to turn VBUS off... 683 * REVISIT: some boards will be able to turn VBUS off...
678 */ 684 */
679 if (!ohci_at91->wakeup) { 685 if (!ohci_at91->wakeup) {
680 ohci->hc_control = ohci_readl(ohci, &ohci->regs->control);
681 ohci->hc_control &= OHCI_CTRL_RWC;
682 ohci_writel(ohci, ohci->hc_control, &ohci->regs->control);
683 ohci->rh_state = OHCI_RH_HALTED; 686 ohci->rh_state = OHCI_RH_HALTED;
684 687
685 /* flush the writes */ 688 /* flush the writes */
diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c
index 1700908b84ef..86612ac3fda2 100644
--- a/drivers/usb/host/ohci-hcd.c
+++ b/drivers/usb/host/ohci-hcd.c
@@ -72,7 +72,7 @@
72static const char hcd_name [] = "ohci_hcd"; 72static const char hcd_name [] = "ohci_hcd";
73 73
74#define STATECHANGE_DELAY msecs_to_jiffies(300) 74#define STATECHANGE_DELAY msecs_to_jiffies(300)
75#define IO_WATCHDOG_DELAY msecs_to_jiffies(250) 75#define IO_WATCHDOG_DELAY msecs_to_jiffies(275)
76 76
77#include "ohci.h" 77#include "ohci.h"
78#include "pci-quirks.h" 78#include "pci-quirks.h"
diff --git a/drivers/usb/host/pci-quirks.c b/drivers/usb/host/pci-quirks.c
index d793f548dfe2..a9a1e4c40480 100644
--- a/drivers/usb/host/pci-quirks.c
+++ b/drivers/usb/host/pci-quirks.c
@@ -995,6 +995,14 @@ static void quirk_usb_handoff_xhci(struct pci_dev *pdev)
995 } 995 }
996 val = readl(base + ext_cap_offset); 996 val = readl(base + ext_cap_offset);
997 997
998 /* Auto handoff never worked for these devices. Force it and continue */
999 if ((pdev->vendor == PCI_VENDOR_ID_TI && pdev->device == 0x8241) ||
1000 (pdev->vendor == PCI_VENDOR_ID_RENESAS
1001 && pdev->device == 0x0014)) {
1002 val = (val | XHCI_HC_OS_OWNED) & ~XHCI_HC_BIOS_OWNED;
1003 writel(val, base + ext_cap_offset);
1004 }
1005
998 /* If the BIOS owns the HC, signal that the OS wants it, and wait */ 1006 /* If the BIOS owns the HC, signal that the OS wants it, and wait */
999 if (val & XHCI_HC_BIOS_OWNED) { 1007 if (val & XHCI_HC_BIOS_OWNED) {
1000 writel(val | XHCI_HC_OS_OWNED, base + ext_cap_offset); 1008 writel(val | XHCI_HC_OS_OWNED, base + ext_cap_offset);
diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
index 730b9fd26685..0ef16900efed 100644
--- a/drivers/usb/host/xhci-hub.c
+++ b/drivers/usb/host/xhci-hub.c
@@ -1166,7 +1166,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
1166 xhci_set_link_state(xhci, port_array, wIndex, 1166 xhci_set_link_state(xhci, port_array, wIndex,
1167 XDEV_RESUME); 1167 XDEV_RESUME);
1168 spin_unlock_irqrestore(&xhci->lock, flags); 1168 spin_unlock_irqrestore(&xhci->lock, flags);
1169 msleep(20); 1169 msleep(USB_RESUME_TIMEOUT);
1170 spin_lock_irqsave(&xhci->lock, flags); 1170 spin_lock_irqsave(&xhci->lock, flags);
1171 xhci_set_link_state(xhci, port_array, wIndex, 1171 xhci_set_link_state(xhci, port_array, wIndex,
1172 XDEV_U0); 1172 XDEV_U0);
@@ -1355,6 +1355,35 @@ int xhci_bus_suspend(struct usb_hcd *hcd)
1355 return 0; 1355 return 0;
1356} 1356}
1357 1357
1358/*
1359 * Workaround for missing Cold Attach Status (CAS) if device re-plugged in S3.
1360 * warm reset a USB3 device stuck in polling or compliance mode after resume.
1361 * See Intel 100/c230 series PCH specification update Doc #332692-006 Errata #8
1362 */
1363static bool xhci_port_missing_cas_quirk(int port_index,
1364 __le32 __iomem **port_array)
1365{
1366 u32 portsc;
1367
1368 portsc = readl(port_array[port_index]);
1369
1370 /* if any of these are set we are not stuck */
1371 if (portsc & (PORT_CONNECT | PORT_CAS))
1372 return false;
1373
1374 if (((portsc & PORT_PLS_MASK) != XDEV_POLLING) &&
1375 ((portsc & PORT_PLS_MASK) != XDEV_COMP_MODE))
1376 return false;
1377
1378 /* clear wakeup/change bits, and do a warm port reset */
1379 portsc &= ~(PORT_RWC_BITS | PORT_CEC | PORT_WAKE_BITS);
1380 portsc |= PORT_WR;
1381 writel(portsc, port_array[port_index]);
1382 /* flush write */
1383 readl(port_array[port_index]);
1384 return true;
1385}
1386
1358int xhci_bus_resume(struct usb_hcd *hcd) 1387int xhci_bus_resume(struct usb_hcd *hcd)
1359{ 1388{
1360 struct xhci_hcd *xhci = hcd_to_xhci(hcd); 1389 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
@@ -1392,6 +1421,14 @@ int xhci_bus_resume(struct usb_hcd *hcd)
1392 u32 temp; 1421 u32 temp;
1393 1422
1394 temp = readl(port_array[port_index]); 1423 temp = readl(port_array[port_index]);
1424
1425 /* warm reset CAS limited ports stuck in polling/compliance */
1426 if ((xhci->quirks & XHCI_MISSING_CAS) &&
1427 (hcd->speed >= HCD_USB3) &&
1428 xhci_port_missing_cas_quirk(port_index, port_array)) {
1429 xhci_dbg(xhci, "reset stuck port %d\n", port_index);
1430 continue;
1431 }
1395 if (DEV_SUPERSPEED_ANY(temp)) 1432 if (DEV_SUPERSPEED_ANY(temp))
1396 temp &= ~(PORT_RWC_BITS | PORT_CEC | PORT_WAKE_BITS); 1433 temp &= ~(PORT_RWC_BITS | PORT_CEC | PORT_WAKE_BITS);
1397 else 1434 else
@@ -1410,7 +1447,7 @@ int xhci_bus_resume(struct usb_hcd *hcd)
1410 1447
1411 if (need_usb2_u3_exit) { 1448 if (need_usb2_u3_exit) {
1412 spin_unlock_irqrestore(&xhci->lock, flags); 1449 spin_unlock_irqrestore(&xhci->lock, flags);
1413 msleep(20); 1450 msleep(USB_RESUME_TIMEOUT);
1414 spin_lock_irqsave(&xhci->lock, flags); 1451 spin_lock_irqsave(&xhci->lock, flags);
1415 } 1452 }
1416 1453
diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c
index d7b0f97abbad..e96ae80d107e 100644
--- a/drivers/usb/host/xhci-pci.c
+++ b/drivers/usb/host/xhci-pci.c
@@ -45,11 +45,13 @@
45 45
46#define PCI_DEVICE_ID_INTEL_LYNXPOINT_XHCI 0x8c31 46#define PCI_DEVICE_ID_INTEL_LYNXPOINT_XHCI 0x8c31
47#define PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_XHCI 0x9c31 47#define PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_XHCI 0x9c31
48#define PCI_DEVICE_ID_INTEL_WILDCATPOINT_LP_XHCI 0x9cb1
48#define PCI_DEVICE_ID_INTEL_CHERRYVIEW_XHCI 0x22b5 49#define PCI_DEVICE_ID_INTEL_CHERRYVIEW_XHCI 0x22b5
49#define PCI_DEVICE_ID_INTEL_SUNRISEPOINT_H_XHCI 0xa12f 50#define PCI_DEVICE_ID_INTEL_SUNRISEPOINT_H_XHCI 0xa12f
50#define PCI_DEVICE_ID_INTEL_SUNRISEPOINT_LP_XHCI 0x9d2f 51#define PCI_DEVICE_ID_INTEL_SUNRISEPOINT_LP_XHCI 0x9d2f
51#define PCI_DEVICE_ID_INTEL_BROXTON_M_XHCI 0x0aa8 52#define PCI_DEVICE_ID_INTEL_BROXTON_M_XHCI 0x0aa8
52#define PCI_DEVICE_ID_INTEL_BROXTON_B_XHCI 0x1aa8 53#define PCI_DEVICE_ID_INTEL_BROXTON_B_XHCI 0x1aa8
54#define PCI_DEVICE_ID_INTEL_APL_XHCI 0x5aa8
53 55
54static const char hcd_name[] = "xhci_hcd"; 56static const char hcd_name[] = "xhci_hcd";
55 57
@@ -153,7 +155,8 @@ static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci)
153 xhci->quirks |= XHCI_SPURIOUS_REBOOT; 155 xhci->quirks |= XHCI_SPURIOUS_REBOOT;
154 } 156 }
155 if (pdev->vendor == PCI_VENDOR_ID_INTEL && 157 if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
156 pdev->device == PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_XHCI) { 158 (pdev->device == PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_XHCI ||
159 pdev->device == PCI_DEVICE_ID_INTEL_WILDCATPOINT_LP_XHCI)) {
157 xhci->quirks |= XHCI_SPURIOUS_REBOOT; 160 xhci->quirks |= XHCI_SPURIOUS_REBOOT;
158 xhci->quirks |= XHCI_SPURIOUS_WAKEUP; 161 xhci->quirks |= XHCI_SPURIOUS_WAKEUP;
159 } 162 }
@@ -169,6 +172,11 @@ static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci)
169 pdev->device == PCI_DEVICE_ID_INTEL_CHERRYVIEW_XHCI) { 172 pdev->device == PCI_DEVICE_ID_INTEL_CHERRYVIEW_XHCI) {
170 xhci->quirks |= XHCI_SSIC_PORT_UNUSED; 173 xhci->quirks |= XHCI_SSIC_PORT_UNUSED;
171 } 174 }
175 if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
176 (pdev->device == PCI_DEVICE_ID_INTEL_CHERRYVIEW_XHCI ||
177 pdev->device == PCI_DEVICE_ID_INTEL_APL_XHCI))
178 xhci->quirks |= XHCI_MISSING_CAS;
179
172 if (pdev->vendor == PCI_VENDOR_ID_ETRON && 180 if (pdev->vendor == PCI_VENDOR_ID_ETRON &&
173 pdev->device == PCI_DEVICE_ID_EJ168) { 181 pdev->device == PCI_DEVICE_ID_EJ168) {
174 xhci->quirks |= XHCI_RESET_ON_RESUME; 182 xhci->quirks |= XHCI_RESET_ON_RESUME;
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index b2c1dc5dc0f3..f945380035d0 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -314,6 +314,8 @@ struct xhci_op_regs {
314#define XDEV_U2 (0x2 << 5) 314#define XDEV_U2 (0x2 << 5)
315#define XDEV_U3 (0x3 << 5) 315#define XDEV_U3 (0x3 << 5)
316#define XDEV_INACTIVE (0x6 << 5) 316#define XDEV_INACTIVE (0x6 << 5)
317#define XDEV_POLLING (0x7 << 5)
318#define XDEV_COMP_MODE (0xa << 5)
317#define XDEV_RESUME (0xf << 5) 319#define XDEV_RESUME (0xf << 5)
318/* true: port has power (see HCC_PPC) */ 320/* true: port has power (see HCC_PPC) */
319#define PORT_POWER (1 << 9) 321#define PORT_POWER (1 << 9)
@@ -1653,6 +1655,7 @@ struct xhci_hcd {
1653#define XHCI_MTK_HOST (1 << 21) 1655#define XHCI_MTK_HOST (1 << 21)
1654#define XHCI_SSIC_PORT_UNUSED (1 << 22) 1656#define XHCI_SSIC_PORT_UNUSED (1 << 22)
1655#define XHCI_NO_64BIT_SUPPORT (1 << 23) 1657#define XHCI_NO_64BIT_SUPPORT (1 << 23)
1658#define XHCI_MISSING_CAS (1 << 24)
1656 unsigned int num_active_eps; 1659 unsigned int num_active_eps;
1657 unsigned int limit_active_eps; 1660 unsigned int limit_active_eps;
1658 /* There are two roothubs to keep track of bus suspend info for */ 1661 /* There are two roothubs to keep track of bus suspend info for */
diff --git a/drivers/usb/musb/da8xx.c b/drivers/usb/musb/da8xx.c
index 210b7e43a6fd..2440f88e07a3 100644
--- a/drivers/usb/musb/da8xx.c
+++ b/drivers/usb/musb/da8xx.c
@@ -479,7 +479,8 @@ static int da8xx_probe(struct platform_device *pdev)
479 479
480 glue->phy = devm_phy_get(&pdev->dev, "usb-phy"); 480 glue->phy = devm_phy_get(&pdev->dev, "usb-phy");
481 if (IS_ERR(glue->phy)) { 481 if (IS_ERR(glue->phy)) {
482 dev_err(&pdev->dev, "failed to get phy\n"); 482 if (PTR_ERR(glue->phy) != -EPROBE_DEFER)
483 dev_err(&pdev->dev, "failed to get phy\n");
483 return PTR_ERR(glue->phy); 484 return PTR_ERR(glue->phy);
484 } 485 }
485 486
diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index 27dadc0d9114..c3e172e15ec3 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -986,7 +986,7 @@ b_host:
986 } 986 }
987#endif 987#endif
988 988
989 schedule_work(&musb->irq_work); 989 schedule_delayed_work(&musb->irq_work, 0);
990 990
991 return handled; 991 return handled;
992} 992}
@@ -1855,14 +1855,23 @@ static void musb_pm_runtime_check_session(struct musb *musb)
1855 MUSB_DEVCTL_HR; 1855 MUSB_DEVCTL_HR;
1856 switch (devctl & ~s) { 1856 switch (devctl & ~s) {
1857 case MUSB_QUIRK_B_INVALID_VBUS_91: 1857 case MUSB_QUIRK_B_INVALID_VBUS_91:
1858 if (!musb->session && !musb->quirk_invalid_vbus) { 1858 if (musb->quirk_retries--) {
1859 musb->quirk_invalid_vbus = true;
1860 musb_dbg(musb, 1859 musb_dbg(musb,
1861 "First invalid vbus, assume no session"); 1860 "Poll devctl on invalid vbus, assume no session");
1861 schedule_delayed_work(&musb->irq_work,
1862 msecs_to_jiffies(1000));
1863
1862 return; 1864 return;
1863 } 1865 }
1864 break;
1865 case MUSB_QUIRK_A_DISCONNECT_19: 1866 case MUSB_QUIRK_A_DISCONNECT_19:
1867 if (musb->quirk_retries--) {
1868 musb_dbg(musb,
1869 "Poll devctl on possible host mode disconnect");
1870 schedule_delayed_work(&musb->irq_work,
1871 msecs_to_jiffies(1000));
1872
1873 return;
1874 }
1866 if (!musb->session) 1875 if (!musb->session)
1867 break; 1876 break;
1868 musb_dbg(musb, "Allow PM on possible host mode disconnect"); 1877 musb_dbg(musb, "Allow PM on possible host mode disconnect");
@@ -1886,9 +1895,9 @@ static void musb_pm_runtime_check_session(struct musb *musb)
1886 if (error < 0) 1895 if (error < 0)
1887 dev_err(musb->controller, "Could not enable: %i\n", 1896 dev_err(musb->controller, "Could not enable: %i\n",
1888 error); 1897 error);
1898 musb->quirk_retries = 3;
1889 } else { 1899 } else {
1890 musb_dbg(musb, "Allow PM with no session: %02x", devctl); 1900 musb_dbg(musb, "Allow PM with no session: %02x", devctl);
1891 musb->quirk_invalid_vbus = false;
1892 pm_runtime_mark_last_busy(musb->controller); 1901 pm_runtime_mark_last_busy(musb->controller);
1893 pm_runtime_put_autosuspend(musb->controller); 1902 pm_runtime_put_autosuspend(musb->controller);
1894 } 1903 }
@@ -1899,7 +1908,7 @@ static void musb_pm_runtime_check_session(struct musb *musb)
1899/* Only used to provide driver mode change events */ 1908/* Only used to provide driver mode change events */
1900static void musb_irq_work(struct work_struct *data) 1909static void musb_irq_work(struct work_struct *data)
1901{ 1910{
1902 struct musb *musb = container_of(data, struct musb, irq_work); 1911 struct musb *musb = container_of(data, struct musb, irq_work.work);
1903 1912
1904 musb_pm_runtime_check_session(musb); 1913 musb_pm_runtime_check_session(musb);
1905 1914
@@ -1969,6 +1978,7 @@ static struct musb *allocate_instance(struct device *dev,
1969 INIT_LIST_HEAD(&musb->control); 1978 INIT_LIST_HEAD(&musb->control);
1970 INIT_LIST_HEAD(&musb->in_bulk); 1979 INIT_LIST_HEAD(&musb->in_bulk);
1971 INIT_LIST_HEAD(&musb->out_bulk); 1980 INIT_LIST_HEAD(&musb->out_bulk);
1981 INIT_LIST_HEAD(&musb->pending_list);
1972 1982
1973 musb->vbuserr_retry = VBUSERR_RETRY_COUNT; 1983 musb->vbuserr_retry = VBUSERR_RETRY_COUNT;
1974 musb->a_wait_bcon = OTG_TIME_A_WAIT_BCON; 1984 musb->a_wait_bcon = OTG_TIME_A_WAIT_BCON;
@@ -2018,6 +2028,84 @@ static void musb_free(struct musb *musb)
2018 musb_host_free(musb); 2028 musb_host_free(musb);
2019} 2029}
2020 2030
2031struct musb_pending_work {
2032 int (*callback)(struct musb *musb, void *data);
2033 void *data;
2034 struct list_head node;
2035};
2036
2037/*
2038 * Called from musb_runtime_resume(), musb_resume(), and
2039 * musb_queue_resume_work(). Callers must take musb->lock.
2040 */
2041static int musb_run_resume_work(struct musb *musb)
2042{
2043 struct musb_pending_work *w, *_w;
2044 unsigned long flags;
2045 int error = 0;
2046
2047 spin_lock_irqsave(&musb->list_lock, flags);
2048 list_for_each_entry_safe(w, _w, &musb->pending_list, node) {
2049 if (w->callback) {
2050 error = w->callback(musb, w->data);
2051 if (error < 0) {
2052 dev_err(musb->controller,
2053 "resume callback %p failed: %i\n",
2054 w->callback, error);
2055 }
2056 }
2057 list_del(&w->node);
2058 devm_kfree(musb->controller, w);
2059 }
2060 spin_unlock_irqrestore(&musb->list_lock, flags);
2061
2062 return error;
2063}
2064
2065/*
2066 * Called to run work if device is active or else queue the work to happen
2067 * on resume. Caller must take musb->lock and must hold an RPM reference.
2068 *
2069 * Note that we cowardly refuse queuing work after musb PM runtime
2070 * resume is done calling musb_run_resume_work() and return -EINPROGRESS
2071 * instead.
2072 */
2073int musb_queue_resume_work(struct musb *musb,
2074 int (*callback)(struct musb *musb, void *data),
2075 void *data)
2076{
2077 struct musb_pending_work *w;
2078 unsigned long flags;
2079 int error;
2080
2081 if (WARN_ON(!callback))
2082 return -EINVAL;
2083
2084 if (pm_runtime_active(musb->controller))
2085 return callback(musb, data);
2086
2087 w = devm_kzalloc(musb->controller, sizeof(*w), GFP_ATOMIC);
2088 if (!w)
2089 return -ENOMEM;
2090
2091 w->callback = callback;
2092 w->data = data;
2093 spin_lock_irqsave(&musb->list_lock, flags);
2094 if (musb->is_runtime_suspended) {
2095 list_add_tail(&w->node, &musb->pending_list);
2096 error = 0;
2097 } else {
2098 dev_err(musb->controller, "could not add resume work %p\n",
2099 callback);
2100 devm_kfree(musb->controller, w);
2101 error = -EINPROGRESS;
2102 }
2103 spin_unlock_irqrestore(&musb->list_lock, flags);
2104
2105 return error;
2106}
2107EXPORT_SYMBOL_GPL(musb_queue_resume_work);
2108
2021static void musb_deassert_reset(struct work_struct *work) 2109static void musb_deassert_reset(struct work_struct *work)
2022{ 2110{
2023 struct musb *musb; 2111 struct musb *musb;
@@ -2065,6 +2153,7 @@ musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl)
2065 } 2153 }
2066 2154
2067 spin_lock_init(&musb->lock); 2155 spin_lock_init(&musb->lock);
2156 spin_lock_init(&musb->list_lock);
2068 musb->board_set_power = plat->set_power; 2157 musb->board_set_power = plat->set_power;
2069 musb->min_power = plat->min_power; 2158 musb->min_power = plat->min_power;
2070 musb->ops = plat->platform_ops; 2159 musb->ops = plat->platform_ops;
@@ -2114,11 +2203,6 @@ musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl)
2114 musb->io.ep_offset = musb_flat_ep_offset; 2203 musb->io.ep_offset = musb_flat_ep_offset;
2115 musb->io.ep_select = musb_flat_ep_select; 2204 musb->io.ep_select = musb_flat_ep_select;
2116 } 2205 }
2117 /* And override them with platform specific ops if specified. */
2118 if (musb->ops->ep_offset)
2119 musb->io.ep_offset = musb->ops->ep_offset;
2120 if (musb->ops->ep_select)
2121 musb->io.ep_select = musb->ops->ep_select;
2122 2206
2123 /* At least tusb6010 has its own offsets */ 2207 /* At least tusb6010 has its own offsets */
2124 if (musb->ops->ep_offset) 2208 if (musb->ops->ep_offset)
@@ -2213,7 +2297,7 @@ musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl)
2213 musb_generic_disable(musb); 2297 musb_generic_disable(musb);
2214 2298
2215 /* Init IRQ workqueue before request_irq */ 2299 /* Init IRQ workqueue before request_irq */
2216 INIT_WORK(&musb->irq_work, musb_irq_work); 2300 INIT_DELAYED_WORK(&musb->irq_work, musb_irq_work);
2217 INIT_DELAYED_WORK(&musb->deassert_reset_work, musb_deassert_reset); 2301 INIT_DELAYED_WORK(&musb->deassert_reset_work, musb_deassert_reset);
2218 INIT_DELAYED_WORK(&musb->finish_resume_work, musb_host_finish_resume); 2302 INIT_DELAYED_WORK(&musb->finish_resume_work, musb_host_finish_resume);
2219 2303
@@ -2296,6 +2380,7 @@ musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl)
2296 if (status) 2380 if (status)
2297 goto fail5; 2381 goto fail5;
2298 2382
2383 musb->is_initialized = 1;
2299 pm_runtime_mark_last_busy(musb->controller); 2384 pm_runtime_mark_last_busy(musb->controller);
2300 pm_runtime_put_autosuspend(musb->controller); 2385 pm_runtime_put_autosuspend(musb->controller);
2301 2386
@@ -2309,7 +2394,7 @@ fail4:
2309 musb_host_cleanup(musb); 2394 musb_host_cleanup(musb);
2310 2395
2311fail3: 2396fail3:
2312 cancel_work_sync(&musb->irq_work); 2397 cancel_delayed_work_sync(&musb->irq_work);
2313 cancel_delayed_work_sync(&musb->finish_resume_work); 2398 cancel_delayed_work_sync(&musb->finish_resume_work);
2314 cancel_delayed_work_sync(&musb->deassert_reset_work); 2399 cancel_delayed_work_sync(&musb->deassert_reset_work);
2315 if (musb->dma_controller) 2400 if (musb->dma_controller)
@@ -2376,7 +2461,7 @@ static int musb_remove(struct platform_device *pdev)
2376 */ 2461 */
2377 musb_exit_debugfs(musb); 2462 musb_exit_debugfs(musb);
2378 2463
2379 cancel_work_sync(&musb->irq_work); 2464 cancel_delayed_work_sync(&musb->irq_work);
2380 cancel_delayed_work_sync(&musb->finish_resume_work); 2465 cancel_delayed_work_sync(&musb->finish_resume_work);
2381 cancel_delayed_work_sync(&musb->deassert_reset_work); 2466 cancel_delayed_work_sync(&musb->deassert_reset_work);
2382 pm_runtime_get_sync(musb->controller); 2467 pm_runtime_get_sync(musb->controller);
@@ -2562,6 +2647,7 @@ static int musb_suspend(struct device *dev)
2562 2647
2563 musb_platform_disable(musb); 2648 musb_platform_disable(musb);
2564 musb_generic_disable(musb); 2649 musb_generic_disable(musb);
2650 WARN_ON(!list_empty(&musb->pending_list));
2565 2651
2566 spin_lock_irqsave(&musb->lock, flags); 2652 spin_lock_irqsave(&musb->lock, flags);
2567 2653
@@ -2583,9 +2669,11 @@ static int musb_suspend(struct device *dev)
2583 2669
2584static int musb_resume(struct device *dev) 2670static int musb_resume(struct device *dev)
2585{ 2671{
2586 struct musb *musb = dev_to_musb(dev); 2672 struct musb *musb = dev_to_musb(dev);
2587 u8 devctl; 2673 unsigned long flags;
2588 u8 mask; 2674 int error;
2675 u8 devctl;
2676 u8 mask;
2589 2677
2590 /* 2678 /*
2591 * For static cmos like DaVinci, register values were preserved 2679 * For static cmos like DaVinci, register values were preserved
@@ -2619,6 +2707,13 @@ static int musb_resume(struct device *dev)
2619 2707
2620 musb_start(musb); 2708 musb_start(musb);
2621 2709
2710 spin_lock_irqsave(&musb->lock, flags);
2711 error = musb_run_resume_work(musb);
2712 if (error)
2713 dev_err(musb->controller, "resume work failed with %i\n",
2714 error);
2715 spin_unlock_irqrestore(&musb->lock, flags);
2716
2622 return 0; 2717 return 0;
2623} 2718}
2624 2719
@@ -2627,14 +2722,16 @@ static int musb_runtime_suspend(struct device *dev)
2627 struct musb *musb = dev_to_musb(dev); 2722 struct musb *musb = dev_to_musb(dev);
2628 2723
2629 musb_save_context(musb); 2724 musb_save_context(musb);
2725 musb->is_runtime_suspended = 1;
2630 2726
2631 return 0; 2727 return 0;
2632} 2728}
2633 2729
2634static int musb_runtime_resume(struct device *dev) 2730static int musb_runtime_resume(struct device *dev)
2635{ 2731{
2636 struct musb *musb = dev_to_musb(dev); 2732 struct musb *musb = dev_to_musb(dev);
2637 static int first = 1; 2733 unsigned long flags;
2734 int error;
2638 2735
2639 /* 2736 /*
2640 * When pm_runtime_get_sync called for the first time in driver 2737 * When pm_runtime_get_sync called for the first time in driver
@@ -2645,9 +2742,10 @@ static int musb_runtime_resume(struct device *dev)
2645 * Also context restore without save does not make 2742 * Also context restore without save does not make
2646 * any sense 2743 * any sense
2647 */ 2744 */
2648 if (!first) 2745 if (!musb->is_initialized)
2649 musb_restore_context(musb); 2746 return 0;
2650 first = 0; 2747
2748 musb_restore_context(musb);
2651 2749
2652 if (musb->need_finish_resume) { 2750 if (musb->need_finish_resume) {
2653 musb->need_finish_resume = 0; 2751 musb->need_finish_resume = 0;
@@ -2655,6 +2753,14 @@ static int musb_runtime_resume(struct device *dev)
2655 msecs_to_jiffies(USB_RESUME_TIMEOUT)); 2753 msecs_to_jiffies(USB_RESUME_TIMEOUT));
2656 } 2754 }
2657 2755
2756 spin_lock_irqsave(&musb->lock, flags);
2757 error = musb_run_resume_work(musb);
2758 if (error)
2759 dev_err(musb->controller, "resume work failed with %i\n",
2760 error);
2761 musb->is_runtime_suspended = 0;
2762 spin_unlock_irqrestore(&musb->lock, flags);
2763
2658 return 0; 2764 return 0;
2659} 2765}
2660 2766
diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h
index 2cb88a498f8a..91817d77d59c 100644
--- a/drivers/usb/musb/musb_core.h
+++ b/drivers/usb/musb/musb_core.h
@@ -303,13 +303,14 @@ struct musb_context_registers {
303struct musb { 303struct musb {
304 /* device lock */ 304 /* device lock */
305 spinlock_t lock; 305 spinlock_t lock;
306 spinlock_t list_lock; /* resume work list lock */
306 307
307 struct musb_io io; 308 struct musb_io io;
308 const struct musb_platform_ops *ops; 309 const struct musb_platform_ops *ops;
309 struct musb_context_registers context; 310 struct musb_context_registers context;
310 311
311 irqreturn_t (*isr)(int, void *); 312 irqreturn_t (*isr)(int, void *);
312 struct work_struct irq_work; 313 struct delayed_work irq_work;
313 struct delayed_work deassert_reset_work; 314 struct delayed_work deassert_reset_work;
314 struct delayed_work finish_resume_work; 315 struct delayed_work finish_resume_work;
315 struct delayed_work gadget_work; 316 struct delayed_work gadget_work;
@@ -337,6 +338,7 @@ struct musb {
337 struct list_head control; /* of musb_qh */ 338 struct list_head control; /* of musb_qh */
338 struct list_head in_bulk; /* of musb_qh */ 339 struct list_head in_bulk; /* of musb_qh */
339 struct list_head out_bulk; /* of musb_qh */ 340 struct list_head out_bulk; /* of musb_qh */
341 struct list_head pending_list; /* pending work list */
340 342
341 struct timer_list otg_timer; 343 struct timer_list otg_timer;
342 struct notifier_block nb; 344 struct notifier_block nb;
@@ -379,12 +381,15 @@ struct musb {
379 381
380 int port_mode; /* MUSB_PORT_MODE_* */ 382 int port_mode; /* MUSB_PORT_MODE_* */
381 bool session; 383 bool session;
382 bool quirk_invalid_vbus; 384 unsigned long quirk_retries;
383 bool is_host; 385 bool is_host;
384 386
385 int a_wait_bcon; /* VBUS timeout in msecs */ 387 int a_wait_bcon; /* VBUS timeout in msecs */
386 unsigned long idle_timeout; /* Next timeout in jiffies */ 388 unsigned long idle_timeout; /* Next timeout in jiffies */
387 389
390 unsigned is_initialized:1;
391 unsigned is_runtime_suspended:1;
392
388 /* active means connected and not suspended */ 393 /* active means connected and not suspended */
389 unsigned is_active:1; 394 unsigned is_active:1;
390 395
@@ -540,6 +545,10 @@ extern irqreturn_t musb_interrupt(struct musb *);
540 545
541extern void musb_hnp_stop(struct musb *musb); 546extern void musb_hnp_stop(struct musb *musb);
542 547
548int musb_queue_resume_work(struct musb *musb,
549 int (*callback)(struct musb *musb, void *data),
550 void *data);
551
543static inline void musb_platform_set_vbus(struct musb *musb, int is_on) 552static inline void musb_platform_set_vbus(struct musb *musb, int is_on)
544{ 553{
545 if (musb->ops->set_vbus) 554 if (musb->ops->set_vbus)
diff --git a/drivers/usb/musb/musb_dsps.c b/drivers/usb/musb/musb_dsps.c
index 0f17d2140db6..feae1561b9ab 100644
--- a/drivers/usb/musb/musb_dsps.c
+++ b/drivers/usb/musb/musb_dsps.c
@@ -185,24 +185,19 @@ static void dsps_musb_disable(struct musb *musb)
185 musb_writel(reg_base, wrp->coreintr_clear, wrp->usb_bitmap); 185 musb_writel(reg_base, wrp->coreintr_clear, wrp->usb_bitmap);
186 musb_writel(reg_base, wrp->epintr_clear, 186 musb_writel(reg_base, wrp->epintr_clear,
187 wrp->txep_bitmap | wrp->rxep_bitmap); 187 wrp->txep_bitmap | wrp->rxep_bitmap);
188 del_timer_sync(&glue->timer);
188 musb_writeb(musb->mregs, MUSB_DEVCTL, 0); 189 musb_writeb(musb->mregs, MUSB_DEVCTL, 0);
189} 190}
190 191
191static void otg_timer(unsigned long _musb) 192/* Caller must take musb->lock */
193static int dsps_check_status(struct musb *musb, void *unused)
192{ 194{
193 struct musb *musb = (void *)_musb;
194 void __iomem *mregs = musb->mregs; 195 void __iomem *mregs = musb->mregs;
195 struct device *dev = musb->controller; 196 struct device *dev = musb->controller;
196 struct dsps_glue *glue = dev_get_drvdata(dev->parent); 197 struct dsps_glue *glue = dev_get_drvdata(dev->parent);
197 const struct dsps_musb_wrapper *wrp = glue->wrp; 198 const struct dsps_musb_wrapper *wrp = glue->wrp;
198 u8 devctl; 199 u8 devctl;
199 unsigned long flags;
200 int skip_session = 0; 200 int skip_session = 0;
201 int err;
202
203 err = pm_runtime_get_sync(dev);
204 if (err < 0)
205 dev_err(dev, "Poll could not pm_runtime_get: %i\n", err);
206 201
207 /* 202 /*
208 * We poll because DSPS IP's won't expose several OTG-critical 203 * We poll because DSPS IP's won't expose several OTG-critical
@@ -212,7 +207,6 @@ static void otg_timer(unsigned long _musb)
212 dev_dbg(musb->controller, "Poll devctl %02x (%s)\n", devctl, 207 dev_dbg(musb->controller, "Poll devctl %02x (%s)\n", devctl,
213 usb_otg_state_string(musb->xceiv->otg->state)); 208 usb_otg_state_string(musb->xceiv->otg->state));
214 209
215 spin_lock_irqsave(&musb->lock, flags);
216 switch (musb->xceiv->otg->state) { 210 switch (musb->xceiv->otg->state) {
217 case OTG_STATE_A_WAIT_VRISE: 211 case OTG_STATE_A_WAIT_VRISE:
218 mod_timer(&glue->timer, jiffies + 212 mod_timer(&glue->timer, jiffies +
@@ -245,8 +239,30 @@ static void otg_timer(unsigned long _musb)
245 default: 239 default:
246 break; 240 break;
247 } 241 }
248 spin_unlock_irqrestore(&musb->lock, flags);
249 242
243 return 0;
244}
245
246static void otg_timer(unsigned long _musb)
247{
248 struct musb *musb = (void *)_musb;
249 struct device *dev = musb->controller;
250 unsigned long flags;
251 int err;
252
253 err = pm_runtime_get(dev);
254 if ((err != -EINPROGRESS) && err < 0) {
255 dev_err(dev, "Poll could not pm_runtime_get: %i\n", err);
256 pm_runtime_put_noidle(dev);
257
258 return;
259 }
260
261 spin_lock_irqsave(&musb->lock, flags);
262 err = musb_queue_resume_work(musb, dsps_check_status, NULL);
263 if (err < 0)
264 dev_err(dev, "%s resume work: %i\n", __func__, err);
265 spin_unlock_irqrestore(&musb->lock, flags);
250 pm_runtime_mark_last_busy(dev); 266 pm_runtime_mark_last_busy(dev);
251 pm_runtime_put_autosuspend(dev); 267 pm_runtime_put_autosuspend(dev);
252} 268}
@@ -767,28 +783,13 @@ static int dsps_probe(struct platform_device *pdev)
767 783
768 platform_set_drvdata(pdev, glue); 784 platform_set_drvdata(pdev, glue);
769 pm_runtime_enable(&pdev->dev); 785 pm_runtime_enable(&pdev->dev);
770 pm_runtime_use_autosuspend(&pdev->dev);
771 pm_runtime_set_autosuspend_delay(&pdev->dev, 200);
772
773 ret = pm_runtime_get_sync(&pdev->dev);
774 if (ret < 0) {
775 dev_err(&pdev->dev, "pm_runtime_get_sync FAILED");
776 goto err2;
777 }
778
779 ret = dsps_create_musb_pdev(glue, pdev); 786 ret = dsps_create_musb_pdev(glue, pdev);
780 if (ret) 787 if (ret)
781 goto err3; 788 goto err;
782
783 pm_runtime_mark_last_busy(&pdev->dev);
784 pm_runtime_put_autosuspend(&pdev->dev);
785 789
786 return 0; 790 return 0;
787 791
788err3: 792err:
789 pm_runtime_put_sync(&pdev->dev);
790err2:
791 pm_runtime_dont_use_autosuspend(&pdev->dev);
792 pm_runtime_disable(&pdev->dev); 793 pm_runtime_disable(&pdev->dev);
793 return ret; 794 return ret;
794} 795}
@@ -799,9 +800,6 @@ static int dsps_remove(struct platform_device *pdev)
799 800
800 platform_device_unregister(glue->musb); 801 platform_device_unregister(glue->musb);
801 802
802 /* disable usbss clocks */
803 pm_runtime_dont_use_autosuspend(&pdev->dev);
804 pm_runtime_put_sync(&pdev->dev);
805 pm_runtime_disable(&pdev->dev); 803 pm_runtime_disable(&pdev->dev);
806 804
807 return 0; 805 return 0;
diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c
index bff4869a57cd..a55173c9e564 100644
--- a/drivers/usb/musb/musb_gadget.c
+++ b/drivers/usb/musb/musb_gadget.c
@@ -1114,7 +1114,7 @@ static int musb_gadget_enable(struct usb_ep *ep,
1114 musb_ep->dma ? "dma, " : "", 1114 musb_ep->dma ? "dma, " : "",
1115 musb_ep->packet_sz); 1115 musb_ep->packet_sz);
1116 1116
1117 schedule_work(&musb->irq_work); 1117 schedule_delayed_work(&musb->irq_work, 0);
1118 1118
1119fail: 1119fail:
1120 spin_unlock_irqrestore(&musb->lock, flags); 1120 spin_unlock_irqrestore(&musb->lock, flags);
@@ -1158,7 +1158,7 @@ static int musb_gadget_disable(struct usb_ep *ep)
1158 musb_ep->desc = NULL; 1158 musb_ep->desc = NULL;
1159 musb_ep->end_point.desc = NULL; 1159 musb_ep->end_point.desc = NULL;
1160 1160
1161 schedule_work(&musb->irq_work); 1161 schedule_delayed_work(&musb->irq_work, 0);
1162 1162
1163 spin_unlock_irqrestore(&(musb->lock), flags); 1163 spin_unlock_irqrestore(&(musb->lock), flags);
1164 1164
@@ -1222,13 +1222,22 @@ void musb_ep_restart(struct musb *musb, struct musb_request *req)
1222 rxstate(musb, req); 1222 rxstate(musb, req);
1223} 1223}
1224 1224
1225static int musb_ep_restart_resume_work(struct musb *musb, void *data)
1226{
1227 struct musb_request *req = data;
1228
1229 musb_ep_restart(musb, req);
1230
1231 return 0;
1232}
1233
1225static int musb_gadget_queue(struct usb_ep *ep, struct usb_request *req, 1234static int musb_gadget_queue(struct usb_ep *ep, struct usb_request *req,
1226 gfp_t gfp_flags) 1235 gfp_t gfp_flags)
1227{ 1236{
1228 struct musb_ep *musb_ep; 1237 struct musb_ep *musb_ep;
1229 struct musb_request *request; 1238 struct musb_request *request;
1230 struct musb *musb; 1239 struct musb *musb;
1231 int status = 0; 1240 int status;
1232 unsigned long lockflags; 1241 unsigned long lockflags;
1233 1242
1234 if (!ep || !req) 1243 if (!ep || !req)
@@ -1245,6 +1254,17 @@ static int musb_gadget_queue(struct usb_ep *ep, struct usb_request *req,
1245 if (request->ep != musb_ep) 1254 if (request->ep != musb_ep)
1246 return -EINVAL; 1255 return -EINVAL;
1247 1256
1257 status = pm_runtime_get(musb->controller);
1258 if ((status != -EINPROGRESS) && status < 0) {
1259 dev_err(musb->controller,
1260 "pm runtime get failed in %s\n",
1261 __func__);
1262 pm_runtime_put_noidle(musb->controller);
1263
1264 return status;
1265 }
1266 status = 0;
1267
1248 trace_musb_req_enq(request); 1268 trace_musb_req_enq(request);
1249 1269
1250 /* request is mine now... */ 1270 /* request is mine now... */
@@ -1270,11 +1290,20 @@ static int musb_gadget_queue(struct usb_ep *ep, struct usb_request *req,
1270 list_add_tail(&request->list, &musb_ep->req_list); 1290 list_add_tail(&request->list, &musb_ep->req_list);
1271 1291
1272 /* it this is the head of the queue, start i/o ... */ 1292 /* it this is the head of the queue, start i/o ... */
1273 if (!musb_ep->busy && &request->list == musb_ep->req_list.next) 1293 if (!musb_ep->busy && &request->list == musb_ep->req_list.next) {
1274 musb_ep_restart(musb, request); 1294 status = musb_queue_resume_work(musb,
1295 musb_ep_restart_resume_work,
1296 request);
1297 if (status < 0)
1298 dev_err(musb->controller, "%s resume work: %i\n",
1299 __func__, status);
1300 }
1275 1301
1276unlock: 1302unlock:
1277 spin_unlock_irqrestore(&musb->lock, lockflags); 1303 spin_unlock_irqrestore(&musb->lock, lockflags);
1304 pm_runtime_mark_last_busy(musb->controller);
1305 pm_runtime_put_autosuspend(musb->controller);
1306
1278 return status; 1307 return status;
1279} 1308}
1280 1309
@@ -1965,7 +1994,7 @@ static int musb_gadget_stop(struct usb_gadget *g)
1965 */ 1994 */
1966 1995
1967 /* Force check of devctl register for PM runtime */ 1996 /* Force check of devctl register for PM runtime */
1968 schedule_work(&musb->irq_work); 1997 schedule_delayed_work(&musb->irq_work, 0);
1969 1998
1970 pm_runtime_mark_last_busy(musb->controller); 1999 pm_runtime_mark_last_busy(musb->controller);
1971 pm_runtime_put_autosuspend(musb->controller); 2000 pm_runtime_put_autosuspend(musb->controller);
diff --git a/drivers/usb/musb/omap2430.c b/drivers/usb/musb/omap2430.c
index 1ab6973d4f61..e8be8e39ab8f 100644
--- a/drivers/usb/musb/omap2430.c
+++ b/drivers/usb/musb/omap2430.c
@@ -287,6 +287,7 @@ static int omap2430_musb_init(struct musb *musb)
287 } 287 }
288 musb->isr = omap2430_musb_interrupt; 288 musb->isr = omap2430_musb_interrupt;
289 phy_init(musb->phy); 289 phy_init(musb->phy);
290 phy_power_on(musb->phy);
290 291
291 l = musb_readl(musb->mregs, OTG_INTERFSEL); 292 l = musb_readl(musb->mregs, OTG_INTERFSEL);
292 293
@@ -323,8 +324,6 @@ static void omap2430_musb_enable(struct musb *musb)
323 struct musb_hdrc_platform_data *pdata = dev_get_platdata(dev); 324 struct musb_hdrc_platform_data *pdata = dev_get_platdata(dev);
324 struct omap_musb_board_data *data = pdata->board_data; 325 struct omap_musb_board_data *data = pdata->board_data;
325 326
326 if (!WARN_ON(!musb->phy))
327 phy_power_on(musb->phy);
328 327
329 switch (glue->status) { 328 switch (glue->status) {
330 329
@@ -361,9 +360,6 @@ static void omap2430_musb_disable(struct musb *musb)
361 struct device *dev = musb->controller; 360 struct device *dev = musb->controller;
362 struct omap2430_glue *glue = dev_get_drvdata(dev->parent); 361 struct omap2430_glue *glue = dev_get_drvdata(dev->parent);
363 362
364 if (!WARN_ON(!musb->phy))
365 phy_power_off(musb->phy);
366
367 if (glue->status != MUSB_UNKNOWN) 363 if (glue->status != MUSB_UNKNOWN)
368 omap_control_usb_set_mode(glue->control_otghs, 364 omap_control_usb_set_mode(glue->control_otghs,
369 USB_MODE_DISCONNECT); 365 USB_MODE_DISCONNECT);
@@ -375,6 +371,7 @@ static int omap2430_musb_exit(struct musb *musb)
375 struct omap2430_glue *glue = dev_get_drvdata(dev->parent); 371 struct omap2430_glue *glue = dev_get_drvdata(dev->parent);
376 372
377 omap2430_low_level_exit(musb); 373 omap2430_low_level_exit(musb);
374 phy_power_off(musb->phy);
378 phy_exit(musb->phy); 375 phy_exit(musb->phy);
379 musb->phy = NULL; 376 musb->phy = NULL;
380 cancel_work_sync(&glue->omap_musb_mailbox_work); 377 cancel_work_sync(&glue->omap_musb_mailbox_work);
@@ -516,17 +513,18 @@ static int omap2430_probe(struct platform_device *pdev)
516 } 513 }
517 514
518 pm_runtime_enable(glue->dev); 515 pm_runtime_enable(glue->dev);
519 pm_runtime_use_autosuspend(glue->dev);
520 pm_runtime_set_autosuspend_delay(glue->dev, 100);
521 516
522 ret = platform_device_add(musb); 517 ret = platform_device_add(musb);
523 if (ret) { 518 if (ret) {
524 dev_err(&pdev->dev, "failed to register musb device\n"); 519 dev_err(&pdev->dev, "failed to register musb device\n");
525 goto err2; 520 goto err3;
526 } 521 }
527 522
528 return 0; 523 return 0;
529 524
525err3:
526 pm_runtime_disable(glue->dev);
527
530err2: 528err2:
531 platform_device_put(musb); 529 platform_device_put(musb);
532 530
@@ -538,10 +536,7 @@ static int omap2430_remove(struct platform_device *pdev)
538{ 536{
539 struct omap2430_glue *glue = platform_get_drvdata(pdev); 537 struct omap2430_glue *glue = platform_get_drvdata(pdev);
540 538
541 pm_runtime_get_sync(glue->dev);
542 platform_device_unregister(glue->musb); 539 platform_device_unregister(glue->musb);
543 pm_runtime_put_sync(glue->dev);
544 pm_runtime_dont_use_autosuspend(glue->dev);
545 pm_runtime_disable(glue->dev); 540 pm_runtime_disable(glue->dev);
546 541
547 return 0; 542 return 0;
diff --git a/drivers/usb/musb/tusb6010.c b/drivers/usb/musb/tusb6010.c
index df7c9f46be54..e85cc8e4e7a9 100644
--- a/drivers/usb/musb/tusb6010.c
+++ b/drivers/usb/musb/tusb6010.c
@@ -724,7 +724,7 @@ tusb_otg_ints(struct musb *musb, u32 int_src, void __iomem *tbase)
724 dev_dbg(musb->controller, "vbus change, %s, otg %03x\n", 724 dev_dbg(musb->controller, "vbus change, %s, otg %03x\n",
725 usb_otg_state_string(musb->xceiv->otg->state), otg_stat); 725 usb_otg_state_string(musb->xceiv->otg->state), otg_stat);
726 idle_timeout = jiffies + (1 * HZ); 726 idle_timeout = jiffies + (1 * HZ);
727 schedule_work(&musb->irq_work); 727 schedule_delayed_work(&musb->irq_work, 0);
728 728
729 } else /* A-dev state machine */ { 729 } else /* A-dev state machine */ {
730 dev_dbg(musb->controller, "vbus change, %s, otg %03x\n", 730 dev_dbg(musb->controller, "vbus change, %s, otg %03x\n",
@@ -814,7 +814,7 @@ tusb_otg_ints(struct musb *musb, u32 int_src, void __iomem *tbase)
814 break; 814 break;
815 } 815 }
816 } 816 }
817 schedule_work(&musb->irq_work); 817 schedule_delayed_work(&musb->irq_work, 0);
818 818
819 return idle_timeout; 819 return idle_timeout;
820} 820}
@@ -864,7 +864,7 @@ static irqreturn_t tusb_musb_interrupt(int irq, void *__hci)
864 musb_writel(tbase, TUSB_PRCM_WAKEUP_CLEAR, reg); 864 musb_writel(tbase, TUSB_PRCM_WAKEUP_CLEAR, reg);
865 if (reg & ~TUSB_PRCM_WNORCS) { 865 if (reg & ~TUSB_PRCM_WNORCS) {
866 musb->is_active = 1; 866 musb->is_active = 1;
867 schedule_work(&musb->irq_work); 867 schedule_delayed_work(&musb->irq_work, 0);
868 } 868 }
869 dev_dbg(musb->controller, "wake %sactive %02x\n", 869 dev_dbg(musb->controller, "wake %sactive %02x\n",
870 musb->is_active ? "" : "in", reg); 870 musb->is_active ? "" : "in", reg);
diff --git a/drivers/usb/renesas_usbhs/rcar3.c b/drivers/usb/renesas_usbhs/rcar3.c
index 1d70add926f0..d544b331c9f2 100644
--- a/drivers/usb/renesas_usbhs/rcar3.c
+++ b/drivers/usb/renesas_usbhs/rcar3.c
@@ -9,6 +9,7 @@
9 * 9 *
10 */ 10 */
11 11
12#include <linux/delay.h>
12#include <linux/io.h> 13#include <linux/io.h>
13#include "common.h" 14#include "common.h"
14#include "rcar3.h" 15#include "rcar3.h"
@@ -35,10 +36,13 @@ static int usbhs_rcar3_power_ctrl(struct platform_device *pdev,
35 36
36 usbhs_write32(priv, UGCTRL2, UGCTRL2_RESERVED_3 | UGCTRL2_USB0SEL_OTG); 37 usbhs_write32(priv, UGCTRL2, UGCTRL2_RESERVED_3 | UGCTRL2_USB0SEL_OTG);
37 38
38 if (enable) 39 if (enable) {
39 usbhs_bset(priv, LPSTS, LPSTS_SUSPM, LPSTS_SUSPM); 40 usbhs_bset(priv, LPSTS, LPSTS_SUSPM, LPSTS_SUSPM);
40 else 41 /* The controller on R-Car Gen3 needs to wait up to 45 usec */
42 udelay(45);
43 } else {
41 usbhs_bset(priv, LPSTS, LPSTS_SUSPM, 0); 44 usbhs_bset(priv, LPSTS, LPSTS_SUSPM, 0);
45 }
42 46
43 return 0; 47 return 0;
44} 48}
diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c
index 54a4de0efdba..243ac5ebe46a 100644
--- a/drivers/usb/serial/cp210x.c
+++ b/drivers/usb/serial/cp210x.c
@@ -131,6 +131,7 @@ static const struct usb_device_id id_table[] = {
131 { USB_DEVICE(0x10C4, 0x88A4) }, /* MMB Networks ZigBee USB Device */ 131 { USB_DEVICE(0x10C4, 0x88A4) }, /* MMB Networks ZigBee USB Device */
132 { USB_DEVICE(0x10C4, 0x88A5) }, /* Planet Innovation Ingeni ZigBee USB Device */ 132 { USB_DEVICE(0x10C4, 0x88A5) }, /* Planet Innovation Ingeni ZigBee USB Device */
133 { USB_DEVICE(0x10C4, 0x8946) }, /* Ketra N1 Wireless Interface */ 133 { USB_DEVICE(0x10C4, 0x8946) }, /* Ketra N1 Wireless Interface */
134 { USB_DEVICE(0x10C4, 0x8962) }, /* Brim Brothers charging dock */
134 { USB_DEVICE(0x10C4, 0x8977) }, /* CEL MeshWorks DevKit Device */ 135 { USB_DEVICE(0x10C4, 0x8977) }, /* CEL MeshWorks DevKit Device */
135 { USB_DEVICE(0x10C4, 0x8998) }, /* KCF Technologies PRN */ 136 { USB_DEVICE(0x10C4, 0x8998) }, /* KCF Technologies PRN */
136 { USB_DEVICE(0x10C4, 0x8A2A) }, /* HubZ dual ZigBee and Z-Wave dongle */ 137 { USB_DEVICE(0x10C4, 0x8A2A) }, /* HubZ dual ZigBee and Z-Wave dongle */
@@ -1077,7 +1078,9 @@ static int cp210x_tiocmget(struct tty_struct *tty)
1077 u8 control; 1078 u8 control;
1078 int result; 1079 int result;
1079 1080
1080 cp210x_read_u8_reg(port, CP210X_GET_MDMSTS, &control); 1081 result = cp210x_read_u8_reg(port, CP210X_GET_MDMSTS, &control);
1082 if (result)
1083 return result;
1081 1084
1082 result = ((control & CONTROL_DTR) ? TIOCM_DTR : 0) 1085 result = ((control & CONTROL_DTR) ? TIOCM_DTR : 0)
1083 |((control & CONTROL_RTS) ? TIOCM_RTS : 0) 1086 |((control & CONTROL_RTS) ? TIOCM_RTS : 0)
diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index b2d767e743fc..6e9fc8bcc285 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -986,7 +986,8 @@ static const struct usb_device_id id_table_combined[] = {
986 /* ekey Devices */ 986 /* ekey Devices */
987 { USB_DEVICE(FTDI_VID, FTDI_EKEY_CONV_USB_PID) }, 987 { USB_DEVICE(FTDI_VID, FTDI_EKEY_CONV_USB_PID) },
988 /* Infineon Devices */ 988 /* Infineon Devices */
989 { USB_DEVICE_INTERFACE_NUMBER(INFINEON_VID, INFINEON_TRIBOARD_PID, 1) }, 989 { USB_DEVICE_INTERFACE_NUMBER(INFINEON_VID, INFINEON_TRIBOARD_TC1798_PID, 1) },
990 { USB_DEVICE_INTERFACE_NUMBER(INFINEON_VID, INFINEON_TRIBOARD_TC2X7_PID, 1) },
990 /* GE Healthcare devices */ 991 /* GE Healthcare devices */
991 { USB_DEVICE(GE_HEALTHCARE_VID, GE_HEALTHCARE_NEMO_TRACKER_PID) }, 992 { USB_DEVICE(GE_HEALTHCARE_VID, GE_HEALTHCARE_NEMO_TRACKER_PID) },
992 /* Active Research (Actisense) devices */ 993 /* Active Research (Actisense) devices */
@@ -1011,6 +1012,8 @@ static const struct usb_device_id id_table_combined[] = {
1011 { USB_DEVICE(ICPDAS_VID, ICPDAS_I7561U_PID) }, 1012 { USB_DEVICE(ICPDAS_VID, ICPDAS_I7561U_PID) },
1012 { USB_DEVICE(ICPDAS_VID, ICPDAS_I7563U_PID) }, 1013 { USB_DEVICE(ICPDAS_VID, ICPDAS_I7563U_PID) },
1013 { USB_DEVICE(WICED_VID, WICED_USB20706V2_PID) }, 1014 { USB_DEVICE(WICED_VID, WICED_USB20706V2_PID) },
1015 { USB_DEVICE(TI_VID, TI_CC3200_LAUNCHPAD_PID),
1016 .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk },
1014 { } /* Terminating entry */ 1017 { } /* Terminating entry */
1015}; 1018};
1016 1019
diff --git a/drivers/usb/serial/ftdi_sio_ids.h b/drivers/usb/serial/ftdi_sio_ids.h
index f87a938cf005..48ee04c94a75 100644
--- a/drivers/usb/serial/ftdi_sio_ids.h
+++ b/drivers/usb/serial/ftdi_sio_ids.h
@@ -596,6 +596,12 @@
596#define STK541_PID 0x2109 /* Zigbee Controller */ 596#define STK541_PID 0x2109 /* Zigbee Controller */
597 597
598/* 598/*
599 * Texas Instruments
600 */
601#define TI_VID 0x0451
602#define TI_CC3200_LAUNCHPAD_PID 0xC32A /* SimpleLink Wi-Fi CC3200 LaunchPad */
603
604/*
599 * Blackfin gnICE JTAG 605 * Blackfin gnICE JTAG
600 * http://docs.blackfin.uclinux.org/doku.php?id=hw:jtag:gnice 606 * http://docs.blackfin.uclinux.org/doku.php?id=hw:jtag:gnice
601 */ 607 */
@@ -626,8 +632,9 @@
626/* 632/*
627 * Infineon Technologies 633 * Infineon Technologies
628 */ 634 */
629#define INFINEON_VID 0x058b 635#define INFINEON_VID 0x058b
630#define INFINEON_TRIBOARD_PID 0x0028 /* DAS JTAG TriBoard TC1798 V1.0 */ 636#define INFINEON_TRIBOARD_TC1798_PID 0x0028 /* DAS JTAG TriBoard TC1798 V1.0 */
637#define INFINEON_TRIBOARD_TC2X7_PID 0x0043 /* DAS JTAG TriBoard TC2X7 V1.0 */
631 638
632/* 639/*
633 * Acton Research Corp. 640 * Acton Research Corp.
diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
index d213cf44a7e4..4a037b4a79cf 100644
--- a/drivers/usb/serial/usb-serial.c
+++ b/drivers/usb/serial/usb-serial.c
@@ -1078,7 +1078,8 @@ static int usb_serial_probe(struct usb_interface *interface,
1078 1078
1079 serial->disconnected = 0; 1079 serial->disconnected = 0;
1080 1080
1081 usb_serial_console_init(serial->port[0]->minor); 1081 if (num_ports > 0)
1082 usb_serial_console_init(serial->port[0]->minor);
1082exit: 1083exit:
1083 module_put(type->driver.owner); 1084 module_put(type->driver.owner);
1084 return 0; 1085 return 0;
diff --git a/drivers/usb/storage/transport.c b/drivers/usb/storage/transport.c
index ffd086733421..1a59f335b063 100644
--- a/drivers/usb/storage/transport.c
+++ b/drivers/usb/storage/transport.c
@@ -954,10 +954,15 @@ int usb_stor_CB_transport(struct scsi_cmnd *srb, struct us_data *us)
954 954
955 /* COMMAND STAGE */ 955 /* COMMAND STAGE */
956 /* let's send the command via the control pipe */ 956 /* let's send the command via the control pipe */
957 /*
958 * Command is sometime (f.e. after scsi_eh_prep_cmnd) on the stack.
959 * Stack may be vmallocated. So no DMA for us. Make a copy.
960 */
961 memcpy(us->iobuf, srb->cmnd, srb->cmd_len);
957 result = usb_stor_ctrl_transfer(us, us->send_ctrl_pipe, 962 result = usb_stor_ctrl_transfer(us, us->send_ctrl_pipe,
958 US_CBI_ADSC, 963 US_CBI_ADSC,
959 USB_TYPE_CLASS | USB_RECIP_INTERFACE, 0, 964 USB_TYPE_CLASS | USB_RECIP_INTERFACE, 0,
960 us->ifnum, srb->cmnd, srb->cmd_len); 965 us->ifnum, us->iobuf, srb->cmd_len);
961 966
962 /* check the return code for the command */ 967 /* check the return code for the command */
963 usb_stor_dbg(us, "Call to usb_stor_ctrl_transfer() returned %d\n", 968 usb_stor_dbg(us, "Call to usb_stor_ctrl_transfer() returned %d\n",
diff --git a/drivers/usb/wusbcore/crypto.c b/drivers/usb/wusbcore/crypto.c
index 79b2b628066d..79451f7ef1b7 100644
--- a/drivers/usb/wusbcore/crypto.c
+++ b/drivers/usb/wusbcore/crypto.c
@@ -133,6 +133,13 @@ static void bytewise_xor(void *_bo, const void *_bi1, const void *_bi2,
133 bo[itr] = bi1[itr] ^ bi2[itr]; 133 bo[itr] = bi1[itr] ^ bi2[itr];
134} 134}
135 135
136/* Scratch space for MAC calculations. */
137struct wusb_mac_scratch {
138 struct aes_ccm_b0 b0;
139 struct aes_ccm_b1 b1;
140 struct aes_ccm_a ax;
141};
142
136/* 143/*
137 * CC-MAC function WUSB1.0[6.5] 144 * CC-MAC function WUSB1.0[6.5]
138 * 145 *
@@ -197,16 +204,15 @@ static void bytewise_xor(void *_bo, const void *_bi1, const void *_bi2,
197 * what sg[4] is for. Maybe there is a smarter way to do this. 204 * what sg[4] is for. Maybe there is a smarter way to do this.
198 */ 205 */
199static int wusb_ccm_mac(struct crypto_skcipher *tfm_cbc, 206static int wusb_ccm_mac(struct crypto_skcipher *tfm_cbc,
200 struct crypto_cipher *tfm_aes, void *mic, 207 struct crypto_cipher *tfm_aes,
208 struct wusb_mac_scratch *scratch,
209 void *mic,
201 const struct aes_ccm_nonce *n, 210 const struct aes_ccm_nonce *n,
202 const struct aes_ccm_label *a, const void *b, 211 const struct aes_ccm_label *a, const void *b,
203 size_t blen) 212 size_t blen)
204{ 213{
205 int result = 0; 214 int result = 0;
206 SKCIPHER_REQUEST_ON_STACK(req, tfm_cbc); 215 SKCIPHER_REQUEST_ON_STACK(req, tfm_cbc);
207 struct aes_ccm_b0 b0;
208 struct aes_ccm_b1 b1;
209 struct aes_ccm_a ax;
210 struct scatterlist sg[4], sg_dst; 216 struct scatterlist sg[4], sg_dst;
211 void *dst_buf; 217 void *dst_buf;
212 size_t dst_size; 218 size_t dst_size;
@@ -218,16 +224,17 @@ static int wusb_ccm_mac(struct crypto_skcipher *tfm_cbc,
218 * These checks should be compile time optimized out 224 * These checks should be compile time optimized out
219 * ensure @a fills b1's mac_header and following fields 225 * ensure @a fills b1's mac_header and following fields
220 */ 226 */
221 WARN_ON(sizeof(*a) != sizeof(b1) - sizeof(b1.la)); 227 WARN_ON(sizeof(*a) != sizeof(scratch->b1) - sizeof(scratch->b1.la));
222 WARN_ON(sizeof(b0) != sizeof(struct aes_ccm_block)); 228 WARN_ON(sizeof(scratch->b0) != sizeof(struct aes_ccm_block));
223 WARN_ON(sizeof(b1) != sizeof(struct aes_ccm_block)); 229 WARN_ON(sizeof(scratch->b1) != sizeof(struct aes_ccm_block));
224 WARN_ON(sizeof(ax) != sizeof(struct aes_ccm_block)); 230 WARN_ON(sizeof(scratch->ax) != sizeof(struct aes_ccm_block));
225 231
226 result = -ENOMEM; 232 result = -ENOMEM;
227 zero_padding = blen % sizeof(struct aes_ccm_block); 233 zero_padding = blen % sizeof(struct aes_ccm_block);
228 if (zero_padding) 234 if (zero_padding)
229 zero_padding = sizeof(struct aes_ccm_block) - zero_padding; 235 zero_padding = sizeof(struct aes_ccm_block) - zero_padding;
230 dst_size = blen + sizeof(b0) + sizeof(b1) + zero_padding; 236 dst_size = blen + sizeof(scratch->b0) + sizeof(scratch->b1) +
237 zero_padding;
231 dst_buf = kzalloc(dst_size, GFP_KERNEL); 238 dst_buf = kzalloc(dst_size, GFP_KERNEL);
232 if (!dst_buf) 239 if (!dst_buf)
233 goto error_dst_buf; 240 goto error_dst_buf;
@@ -235,9 +242,9 @@ static int wusb_ccm_mac(struct crypto_skcipher *tfm_cbc,
235 memset(iv, 0, sizeof(iv)); 242 memset(iv, 0, sizeof(iv));
236 243
237 /* Setup B0 */ 244 /* Setup B0 */
238 b0.flags = 0x59; /* Format B0 */ 245 scratch->b0.flags = 0x59; /* Format B0 */
239 b0.ccm_nonce = *n; 246 scratch->b0.ccm_nonce = *n;
240 b0.lm = cpu_to_be16(0); /* WUSB1.0[6.5] sez l(m) is 0 */ 247 scratch->b0.lm = cpu_to_be16(0); /* WUSB1.0[6.5] sez l(m) is 0 */
241 248
242 /* Setup B1 249 /* Setup B1
243 * 250 *
@@ -246,12 +253,12 @@ static int wusb_ccm_mac(struct crypto_skcipher *tfm_cbc,
246 * 14'--after clarification, it means to use A's contents 253 * 14'--after clarification, it means to use A's contents
247 * for MAC Header, EO, sec reserved and padding. 254 * for MAC Header, EO, sec reserved and padding.
248 */ 255 */
249 b1.la = cpu_to_be16(blen + 14); 256 scratch->b1.la = cpu_to_be16(blen + 14);
250 memcpy(&b1.mac_header, a, sizeof(*a)); 257 memcpy(&scratch->b1.mac_header, a, sizeof(*a));
251 258
252 sg_init_table(sg, ARRAY_SIZE(sg)); 259 sg_init_table(sg, ARRAY_SIZE(sg));
253 sg_set_buf(&sg[0], &b0, sizeof(b0)); 260 sg_set_buf(&sg[0], &scratch->b0, sizeof(scratch->b0));
254 sg_set_buf(&sg[1], &b1, sizeof(b1)); 261 sg_set_buf(&sg[1], &scratch->b1, sizeof(scratch->b1));
255 sg_set_buf(&sg[2], b, blen); 262 sg_set_buf(&sg[2], b, blen);
256 /* 0 if well behaved :) */ 263 /* 0 if well behaved :) */
257 sg_set_buf(&sg[3], bzero, zero_padding); 264 sg_set_buf(&sg[3], bzero, zero_padding);
@@ -276,11 +283,12 @@ static int wusb_ccm_mac(struct crypto_skcipher *tfm_cbc,
276 * POS Crypto API: size is assumed to be AES's block size. 283 * POS Crypto API: size is assumed to be AES's block size.
277 * Thanks for documenting it -- tip taken from airo.c 284 * Thanks for documenting it -- tip taken from airo.c
278 */ 285 */
279 ax.flags = 0x01; /* as per WUSB 1.0 spec */ 286 scratch->ax.flags = 0x01; /* as per WUSB 1.0 spec */
280 ax.ccm_nonce = *n; 287 scratch->ax.ccm_nonce = *n;
281 ax.counter = 0; 288 scratch->ax.counter = 0;
282 crypto_cipher_encrypt_one(tfm_aes, (void *)&ax, (void *)&ax); 289 crypto_cipher_encrypt_one(tfm_aes, (void *)&scratch->ax,
283 bytewise_xor(mic, &ax, iv, 8); 290 (void *)&scratch->ax);
291 bytewise_xor(mic, &scratch->ax, iv, 8);
284 result = 8; 292 result = 8;
285error_cbc_crypt: 293error_cbc_crypt:
286 kfree(dst_buf); 294 kfree(dst_buf);
@@ -303,6 +311,7 @@ ssize_t wusb_prf(void *out, size_t out_size,
303 struct aes_ccm_nonce n = *_n; 311 struct aes_ccm_nonce n = *_n;
304 struct crypto_skcipher *tfm_cbc; 312 struct crypto_skcipher *tfm_cbc;
305 struct crypto_cipher *tfm_aes; 313 struct crypto_cipher *tfm_aes;
314 struct wusb_mac_scratch *scratch;
306 u64 sfn = 0; 315 u64 sfn = 0;
307 __le64 sfn_le; 316 __le64 sfn_le;
308 317
@@ -329,17 +338,25 @@ ssize_t wusb_prf(void *out, size_t out_size,
329 printk(KERN_ERR "E: can't set AES key: %d\n", (int)result); 338 printk(KERN_ERR "E: can't set AES key: %d\n", (int)result);
330 goto error_setkey_aes; 339 goto error_setkey_aes;
331 } 340 }
341 scratch = kmalloc(sizeof(*scratch), GFP_KERNEL);
342 if (!scratch) {
343 result = -ENOMEM;
344 goto error_alloc_scratch;
345 }
332 346
333 for (bitr = 0; bitr < (len + 63) / 64; bitr++) { 347 for (bitr = 0; bitr < (len + 63) / 64; bitr++) {
334 sfn_le = cpu_to_le64(sfn++); 348 sfn_le = cpu_to_le64(sfn++);
335 memcpy(&n.sfn, &sfn_le, sizeof(n.sfn)); /* n.sfn++... */ 349 memcpy(&n.sfn, &sfn_le, sizeof(n.sfn)); /* n.sfn++... */
336 result = wusb_ccm_mac(tfm_cbc, tfm_aes, out + bytes, 350 result = wusb_ccm_mac(tfm_cbc, tfm_aes, scratch, out + bytes,
337 &n, a, b, blen); 351 &n, a, b, blen);
338 if (result < 0) 352 if (result < 0)
339 goto error_ccm_mac; 353 goto error_ccm_mac;
340 bytes += result; 354 bytes += result;
341 } 355 }
342 result = bytes; 356 result = bytes;
357
358 kfree(scratch);
359error_alloc_scratch:
343error_ccm_mac: 360error_ccm_mac:
344error_setkey_aes: 361error_setkey_aes:
345 crypto_free_cipher(tfm_aes); 362 crypto_free_cipher(tfm_aes);
diff --git a/drivers/uwb/lc-rc.c b/drivers/uwb/lc-rc.c
index d059ad4d0dbd..97ee1b46db69 100644
--- a/drivers/uwb/lc-rc.c
+++ b/drivers/uwb/lc-rc.c
@@ -56,8 +56,11 @@ static struct uwb_rc *uwb_rc_find_by_index(int index)
56 struct uwb_rc *rc = NULL; 56 struct uwb_rc *rc = NULL;
57 57
58 dev = class_find_device(&uwb_rc_class, NULL, &index, uwb_rc_index_match); 58 dev = class_find_device(&uwb_rc_class, NULL, &index, uwb_rc_index_match);
59 if (dev) 59 if (dev) {
60 rc = dev_get_drvdata(dev); 60 rc = dev_get_drvdata(dev);
61 put_device(dev);
62 }
63
61 return rc; 64 return rc;
62} 65}
63 66
@@ -467,7 +470,9 @@ struct uwb_rc *__uwb_rc_try_get(struct uwb_rc *target_rc)
467 if (dev) { 470 if (dev) {
468 rc = dev_get_drvdata(dev); 471 rc = dev_get_drvdata(dev);
469 __uwb_rc_get(rc); 472 __uwb_rc_get(rc);
473 put_device(dev);
470 } 474 }
475
471 return rc; 476 return rc;
472} 477}
473EXPORT_SYMBOL_GPL(__uwb_rc_try_get); 478EXPORT_SYMBOL_GPL(__uwb_rc_try_get);
@@ -520,8 +525,11 @@ struct uwb_rc *uwb_rc_get_by_grandpa(const struct device *grandpa_dev)
520 525
521 dev = class_find_device(&uwb_rc_class, NULL, grandpa_dev, 526 dev = class_find_device(&uwb_rc_class, NULL, grandpa_dev,
522 find_rc_grandpa); 527 find_rc_grandpa);
523 if (dev) 528 if (dev) {
524 rc = dev_get_drvdata(dev); 529 rc = dev_get_drvdata(dev);
530 put_device(dev);
531 }
532
525 return rc; 533 return rc;
526} 534}
527EXPORT_SYMBOL_GPL(uwb_rc_get_by_grandpa); 535EXPORT_SYMBOL_GPL(uwb_rc_get_by_grandpa);
@@ -553,8 +561,10 @@ struct uwb_rc *uwb_rc_get_by_dev(const struct uwb_dev_addr *addr)
553 struct uwb_rc *rc = NULL; 561 struct uwb_rc *rc = NULL;
554 562
555 dev = class_find_device(&uwb_rc_class, NULL, addr, find_rc_dev); 563 dev = class_find_device(&uwb_rc_class, NULL, addr, find_rc_dev);
556 if (dev) 564 if (dev) {
557 rc = dev_get_drvdata(dev); 565 rc = dev_get_drvdata(dev);
566 put_device(dev);
567 }
558 568
559 return rc; 569 return rc;
560} 570}
diff --git a/drivers/uwb/pal.c b/drivers/uwb/pal.c
index c1304b8d4985..678e93741ae1 100644
--- a/drivers/uwb/pal.c
+++ b/drivers/uwb/pal.c
@@ -97,6 +97,8 @@ static bool uwb_rc_class_device_exists(struct uwb_rc *target_rc)
97 97
98 dev = class_find_device(&uwb_rc_class, NULL, target_rc, find_rc); 98 dev = class_find_device(&uwb_rc_class, NULL, target_rc, find_rc);
99 99
100 put_device(dev);
101
100 return (dev != NULL); 102 return (dev != NULL);
101} 103}
102 104
diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c
index d624a527777f..031bc08d000d 100644
--- a/drivers/vfio/pci/vfio_pci.c
+++ b/drivers/vfio/pci/vfio_pci.c
@@ -829,8 +829,9 @@ static long vfio_pci_ioctl(void *device_data,
829 829
830 } else if (cmd == VFIO_DEVICE_SET_IRQS) { 830 } else if (cmd == VFIO_DEVICE_SET_IRQS) {
831 struct vfio_irq_set hdr; 831 struct vfio_irq_set hdr;
832 size_t size;
832 u8 *data = NULL; 833 u8 *data = NULL;
833 int ret = 0; 834 int max, ret = 0;
834 835
835 minsz = offsetofend(struct vfio_irq_set, count); 836 minsz = offsetofend(struct vfio_irq_set, count);
836 837
@@ -838,23 +839,31 @@ static long vfio_pci_ioctl(void *device_data,
838 return -EFAULT; 839 return -EFAULT;
839 840
840 if (hdr.argsz < minsz || hdr.index >= VFIO_PCI_NUM_IRQS || 841 if (hdr.argsz < minsz || hdr.index >= VFIO_PCI_NUM_IRQS ||
842 hdr.count >= (U32_MAX - hdr.start) ||
841 hdr.flags & ~(VFIO_IRQ_SET_DATA_TYPE_MASK | 843 hdr.flags & ~(VFIO_IRQ_SET_DATA_TYPE_MASK |
842 VFIO_IRQ_SET_ACTION_TYPE_MASK)) 844 VFIO_IRQ_SET_ACTION_TYPE_MASK))
843 return -EINVAL; 845 return -EINVAL;
844 846
845 if (!(hdr.flags & VFIO_IRQ_SET_DATA_NONE)) { 847 max = vfio_pci_get_irq_count(vdev, hdr.index);
846 size_t size; 848 if (hdr.start >= max || hdr.start + hdr.count > max)
847 int max = vfio_pci_get_irq_count(vdev, hdr.index); 849 return -EINVAL;
848 850
849 if (hdr.flags & VFIO_IRQ_SET_DATA_BOOL) 851 switch (hdr.flags & VFIO_IRQ_SET_DATA_TYPE_MASK) {
850 size = sizeof(uint8_t); 852 case VFIO_IRQ_SET_DATA_NONE:
851 else if (hdr.flags & VFIO_IRQ_SET_DATA_EVENTFD) 853 size = 0;
852 size = sizeof(int32_t); 854 break;
853 else 855 case VFIO_IRQ_SET_DATA_BOOL:
854 return -EINVAL; 856 size = sizeof(uint8_t);
857 break;
858 case VFIO_IRQ_SET_DATA_EVENTFD:
859 size = sizeof(int32_t);
860 break;
861 default:
862 return -EINVAL;
863 }
855 864
856 if (hdr.argsz - minsz < hdr.count * size || 865 if (size) {
857 hdr.start >= max || hdr.start + hdr.count > max) 866 if (hdr.argsz - minsz < hdr.count * size)
858 return -EINVAL; 867 return -EINVAL;
859 868
860 data = memdup_user((void __user *)(arg + minsz), 869 data = memdup_user((void __user *)(arg + minsz),
diff --git a/drivers/vfio/pci/vfio_pci_intrs.c b/drivers/vfio/pci/vfio_pci_intrs.c
index c2e60893cd09..1c46045b0e7f 100644
--- a/drivers/vfio/pci/vfio_pci_intrs.c
+++ b/drivers/vfio/pci/vfio_pci_intrs.c
@@ -256,7 +256,7 @@ static int vfio_msi_enable(struct vfio_pci_device *vdev, int nvec, bool msix)
256 if (!is_irq_none(vdev)) 256 if (!is_irq_none(vdev))
257 return -EINVAL; 257 return -EINVAL;
258 258
259 vdev->ctx = kzalloc(nvec * sizeof(struct vfio_pci_irq_ctx), GFP_KERNEL); 259 vdev->ctx = kcalloc(nvec, sizeof(struct vfio_pci_irq_ctx), GFP_KERNEL);
260 if (!vdev->ctx) 260 if (!vdev->ctx)
261 return -ENOMEM; 261 return -ENOMEM;
262 262
diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c
index e3b30ea9ece5..a504e2e003da 100644
--- a/drivers/vhost/vsock.c
+++ b/drivers/vhost/vsock.c
@@ -506,7 +506,7 @@ static void vhost_vsock_reset_orphans(struct sock *sk)
506 * executing. 506 * executing.
507 */ 507 */
508 508
509 if (!vhost_vsock_get(vsk->local_addr.svm_cid)) { 509 if (!vhost_vsock_get(vsk->remote_addr.svm_cid)) {
510 sock_set_flag(sk, SOCK_DONE); 510 sock_set_flag(sk, SOCK_DONE);
511 vsk->peer_shutdown = SHUTDOWN_MASK; 511 vsk->peer_shutdown = SHUTDOWN_MASK;
512 sk->sk_state = SS_UNCONNECTED; 512 sk->sk_state = SS_UNCONNECTED;
diff --git a/drivers/video/fbdev/amba-clcd-versatile.c b/drivers/video/fbdev/amba-clcd-versatile.c
index 19ad8645d93c..e5d9bfc1703a 100644
--- a/drivers/video/fbdev/amba-clcd-versatile.c
+++ b/drivers/video/fbdev/amba-clcd-versatile.c
@@ -526,8 +526,8 @@ int versatile_clcd_init_panel(struct clcd_fb *fb,
526 np = of_find_matching_node_and_match(NULL, versatile_clcd_of_match, 526 np = of_find_matching_node_and_match(NULL, versatile_clcd_of_match,
527 &clcd_id); 527 &clcd_id);
528 if (!np) { 528 if (!np) {
529 dev_err(dev, "no Versatile syscon node\n"); 529 /* Vexpress does not have this */
530 return -ENODEV; 530 return 0;
531 } 531 }
532 versatile_clcd_type = (enum versatile_clcd)clcd_id->data; 532 versatile_clcd_type = (enum versatile_clcd)clcd_id->data;
533 533
diff --git a/drivers/video/fbdev/pvr2fb.c b/drivers/video/fbdev/pvr2fb.c
index 3b1ca4411073..a2564ab91e62 100644
--- a/drivers/video/fbdev/pvr2fb.c
+++ b/drivers/video/fbdev/pvr2fb.c
@@ -686,8 +686,8 @@ static ssize_t pvr2fb_write(struct fb_info *info, const char *buf,
686 if (!pages) 686 if (!pages)
687 return -ENOMEM; 687 return -ENOMEM;
688 688
689 ret = get_user_pages_unlocked((unsigned long)buf, nr_pages, WRITE, 689 ret = get_user_pages_unlocked((unsigned long)buf, nr_pages, pages,
690 0, pages); 690 FOLL_WRITE);
691 691
692 if (ret < nr_pages) { 692 if (ret < nr_pages) {
693 nr_pages = ret; 693 nr_pages = ret;
diff --git a/drivers/virt/fsl_hypervisor.c b/drivers/virt/fsl_hypervisor.c
index 60bdad3a689b..150ce2abf6c8 100644
--- a/drivers/virt/fsl_hypervisor.c
+++ b/drivers/virt/fsl_hypervisor.c
@@ -245,8 +245,8 @@ static long ioctl_memcpy(struct fsl_hv_ioctl_memcpy __user *p)
245 /* Get the physical addresses of the source buffer */ 245 /* Get the physical addresses of the source buffer */
246 down_read(&current->mm->mmap_sem); 246 down_read(&current->mm->mmap_sem);
247 num_pinned = get_user_pages(param.local_vaddr - lb_offset, 247 num_pinned = get_user_pages(param.local_vaddr - lb_offset,
248 num_pages, (param.source == -1) ? READ : WRITE, 248 num_pages, (param.source == -1) ? 0 : FOLL_WRITE,
249 0, pages, NULL); 249 pages, NULL);
250 up_read(&current->mm->mmap_sem); 250 up_read(&current->mm->mmap_sem);
251 251
252 if (num_pinned != num_pages) { 252 if (num_pinned != num_pages) {
diff --git a/drivers/virtio/config.c b/drivers/virtio/config.c
deleted file mode 100644
index f70bcd2ff98f..000000000000
--- a/drivers/virtio/config.c
+++ /dev/null
@@ -1,12 +0,0 @@
1/* Configuration space parsing helpers for virtio.
2 *
3 * The configuration is [type][len][... len bytes ...] fields.
4 *
5 * Copyright 2007 Rusty Russell, IBM Corporation.
6 * GPL v2 or later.
7 */
8#include <linux/err.h>
9#include <linux/virtio.h>
10#include <linux/virtio_config.h>
11#include <linux/bug.h>
12
diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
index 4e7003db12c4..181793f07852 100644
--- a/drivers/virtio/virtio_balloon.c
+++ b/drivers/virtio/virtio_balloon.c
@@ -577,6 +577,8 @@ static int virtballoon_probe(struct virtio_device *vdev)
577 577
578 virtio_device_ready(vdev); 578 virtio_device_ready(vdev);
579 579
580 if (towards_target(vb))
581 virtballoon_changed(vdev);
580 return 0; 582 return 0;
581 583
582out_del_vqs: 584out_del_vqs:
diff --git a/drivers/virtio/virtio_pci_legacy.c b/drivers/virtio/virtio_pci_legacy.c
index 8c4e61783441..6d9e5173d5fa 100644
--- a/drivers/virtio/virtio_pci_legacy.c
+++ b/drivers/virtio/virtio_pci_legacy.c
@@ -212,10 +212,18 @@ int virtio_pci_legacy_probe(struct virtio_pci_device *vp_dev)
212 return -ENODEV; 212 return -ENODEV;
213 } 213 }
214 214
215 rc = dma_set_mask_and_coherent(&pci_dev->dev, DMA_BIT_MASK(64)); 215 rc = dma_set_mask(&pci_dev->dev, DMA_BIT_MASK(64));
216 if (rc) 216 if (rc) {
217 rc = dma_set_mask_and_coherent(&pci_dev->dev, 217 rc = dma_set_mask_and_coherent(&pci_dev->dev, DMA_BIT_MASK(32));
218 DMA_BIT_MASK(32)); 218 } else {
219 /*
220 * The virtio ring base address is expressed as a 32-bit PFN,
221 * with a page size of 1 << VIRTIO_PCI_QUEUE_ADDR_SHIFT.
222 */
223 dma_set_coherent_mask(&pci_dev->dev,
224 DMA_BIT_MASK(32 + VIRTIO_PCI_QUEUE_ADDR_SHIFT));
225 }
226
219 if (rc) 227 if (rc)
220 dev_warn(&pci_dev->dev, "Failed to enable 64-bit or 32-bit DMA. Trying to continue, but this might not work.\n"); 228 dev_warn(&pci_dev->dev, "Failed to enable 64-bit or 32-bit DMA. Trying to continue, but this might not work.\n");
221 229
diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
index ed9c9eeedfe5..489bfc61cf30 100644
--- a/drivers/virtio/virtio_ring.c
+++ b/drivers/virtio/virtio_ring.c
@@ -167,7 +167,7 @@ static bool vring_use_dma_api(struct virtio_device *vdev)
167 * making all of the arch DMA ops work on the vring device itself 167 * making all of the arch DMA ops work on the vring device itself
168 * is a mess. For now, we use the parent device for DMA ops. 168 * is a mess. For now, we use the parent device for DMA ops.
169 */ 169 */
170static struct device *vring_dma_dev(const struct vring_virtqueue *vq) 170static inline struct device *vring_dma_dev(const struct vring_virtqueue *vq)
171{ 171{
172 return vq->vq.vdev->dev.parent; 172 return vq->vq.vdev->dev.parent;
173} 173}
@@ -732,7 +732,8 @@ void virtqueue_disable_cb(struct virtqueue *_vq)
732 732
733 if (!(vq->avail_flags_shadow & VRING_AVAIL_F_NO_INTERRUPT)) { 733 if (!(vq->avail_flags_shadow & VRING_AVAIL_F_NO_INTERRUPT)) {
734 vq->avail_flags_shadow |= VRING_AVAIL_F_NO_INTERRUPT; 734 vq->avail_flags_shadow |= VRING_AVAIL_F_NO_INTERRUPT;
735 vq->vring.avail->flags = cpu_to_virtio16(_vq->vdev, vq->avail_flags_shadow); 735 if (!vq->event)
736 vq->vring.avail->flags = cpu_to_virtio16(_vq->vdev, vq->avail_flags_shadow);
736 } 737 }
737 738
738} 739}
@@ -764,7 +765,8 @@ unsigned virtqueue_enable_cb_prepare(struct virtqueue *_vq)
764 * entry. Always do both to keep code simple. */ 765 * entry. Always do both to keep code simple. */
765 if (vq->avail_flags_shadow & VRING_AVAIL_F_NO_INTERRUPT) { 766 if (vq->avail_flags_shadow & VRING_AVAIL_F_NO_INTERRUPT) {
766 vq->avail_flags_shadow &= ~VRING_AVAIL_F_NO_INTERRUPT; 767 vq->avail_flags_shadow &= ~VRING_AVAIL_F_NO_INTERRUPT;
767 vq->vring.avail->flags = cpu_to_virtio16(_vq->vdev, vq->avail_flags_shadow); 768 if (!vq->event)
769 vq->vring.avail->flags = cpu_to_virtio16(_vq->vdev, vq->avail_flags_shadow);
768 } 770 }
769 vring_used_event(&vq->vring) = cpu_to_virtio16(_vq->vdev, last_used_idx = vq->last_used_idx); 771 vring_used_event(&vq->vring) = cpu_to_virtio16(_vq->vdev, last_used_idx = vq->last_used_idx);
770 END_USE(vq); 772 END_USE(vq);
@@ -832,10 +834,11 @@ bool virtqueue_enable_cb_delayed(struct virtqueue *_vq)
832 * more to do. */ 834 * more to do. */
833 /* Depending on the VIRTIO_RING_F_USED_EVENT_IDX feature, we need to 835 /* Depending on the VIRTIO_RING_F_USED_EVENT_IDX feature, we need to
834 * either clear the flags bit or point the event index at the next 836 * either clear the flags bit or point the event index at the next
835 * entry. Always do both to keep code simple. */ 837 * entry. Always update the event index to keep code simple. */
836 if (vq->avail_flags_shadow & VRING_AVAIL_F_NO_INTERRUPT) { 838 if (vq->avail_flags_shadow & VRING_AVAIL_F_NO_INTERRUPT) {
837 vq->avail_flags_shadow &= ~VRING_AVAIL_F_NO_INTERRUPT; 839 vq->avail_flags_shadow &= ~VRING_AVAIL_F_NO_INTERRUPT;
838 vq->vring.avail->flags = cpu_to_virtio16(_vq->vdev, vq->avail_flags_shadow); 840 if (!vq->event)
841 vq->vring.avail->flags = cpu_to_virtio16(_vq->vdev, vq->avail_flags_shadow);
839 } 842 }
840 /* TODO: tune this threshold */ 843 /* TODO: tune this threshold */
841 bufs = (u16)(vq->avail_idx_shadow - vq->last_used_idx) * 3 / 4; 844 bufs = (u16)(vq->avail_idx_shadow - vq->last_used_idx) * 3 / 4;
@@ -953,7 +956,8 @@ struct virtqueue *__vring_new_virtqueue(unsigned int index,
953 /* No callback? Tell other side not to bother us. */ 956 /* No callback? Tell other side not to bother us. */
954 if (!callback) { 957 if (!callback) {
955 vq->avail_flags_shadow |= VRING_AVAIL_F_NO_INTERRUPT; 958 vq->avail_flags_shadow |= VRING_AVAIL_F_NO_INTERRUPT;
956 vq->vring.avail->flags = cpu_to_virtio16(vdev, vq->avail_flags_shadow); 959 if (!vq->event)
960 vq->vring.avail->flags = cpu_to_virtio16(vdev, vq->avail_flags_shadow);
957 } 961 }
958 962
959 /* Put everything in free lists. */ 963 /* Put everything in free lists. */
diff --git a/drivers/vme/vme.c b/drivers/vme/vme.c
index 15b64076bc26..bdbadaa47ef3 100644
--- a/drivers/vme/vme.c
+++ b/drivers/vme/vme.c
@@ -156,12 +156,16 @@ size_t vme_get_size(struct vme_resource *resource)
156 case VME_MASTER: 156 case VME_MASTER:
157 retval = vme_master_get(resource, &enabled, &base, &size, 157 retval = vme_master_get(resource, &enabled, &base, &size,
158 &aspace, &cycle, &dwidth); 158 &aspace, &cycle, &dwidth);
159 if (retval)
160 return 0;
159 161
160 return size; 162 return size;
161 break; 163 break;
162 case VME_SLAVE: 164 case VME_SLAVE:
163 retval = vme_slave_get(resource, &enabled, &base, &size, 165 retval = vme_slave_get(resource, &enabled, &base, &size,
164 &buf_base, &aspace, &cycle); 166 &buf_base, &aspace, &cycle);
167 if (retval)
168 return 0;
165 169
166 return size; 170 return size;
167 break; 171 break;
diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index fdd3228e0678..3eb58cb51e56 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -155,6 +155,7 @@ config TANGOX_WATCHDOG
155config WDAT_WDT 155config WDAT_WDT
156 tristate "ACPI Watchdog Action Table (WDAT)" 156 tristate "ACPI Watchdog Action Table (WDAT)"
157 depends on ACPI 157 depends on ACPI
158 select WATCHDOG_CORE
158 select ACPI_WATCHDOG 159 select ACPI_WATCHDOG
159 help 160 help
160 This driver adds support for systems with ACPI Watchdog Action 161 This driver adds support for systems with ACPI Watchdog Action
diff --git a/drivers/watchdog/wdat_wdt.c b/drivers/watchdog/wdat_wdt.c
index e473e3b23720..6d1fbda0f461 100644
--- a/drivers/watchdog/wdat_wdt.c
+++ b/drivers/watchdog/wdat_wdt.c
@@ -499,6 +499,10 @@ static int wdat_wdt_resume_noirq(struct device *dev)
499 ret = wdat_wdt_enable_reboot(wdat); 499 ret = wdat_wdt_enable_reboot(wdat);
500 if (ret) 500 if (ret)
501 return ret; 501 return ret;
502
503 ret = wdat_wdt_ping(&wdat->wdd);
504 if (ret)
505 return ret;
502 } 506 }
503 507
504 return wdat_wdt_start(&wdat->wdd); 508 return wdat_wdt_start(&wdat->wdd);
diff --git a/drivers/xen/manage.c b/drivers/xen/manage.c
index e12bd3635f83..26e5e8507f03 100644
--- a/drivers/xen/manage.c
+++ b/drivers/xen/manage.c
@@ -168,7 +168,9 @@ out:
168#endif /* CONFIG_HIBERNATE_CALLBACKS */ 168#endif /* CONFIG_HIBERNATE_CALLBACKS */
169 169
170struct shutdown_handler { 170struct shutdown_handler {
171 const char *command; 171#define SHUTDOWN_CMD_SIZE 11
172 const char command[SHUTDOWN_CMD_SIZE];
173 bool flag;
172 void (*cb)(void); 174 void (*cb)(void);
173}; 175};
174 176
@@ -206,22 +208,22 @@ static void do_reboot(void)
206 ctrl_alt_del(); 208 ctrl_alt_del();
207} 209}
208 210
211static struct shutdown_handler shutdown_handlers[] = {
212 { "poweroff", true, do_poweroff },
213 { "halt", false, do_poweroff },
214 { "reboot", true, do_reboot },
215#ifdef CONFIG_HIBERNATE_CALLBACKS
216 { "suspend", true, do_suspend },
217#endif
218};
219
209static void shutdown_handler(struct xenbus_watch *watch, 220static void shutdown_handler(struct xenbus_watch *watch,
210 const char **vec, unsigned int len) 221 const char **vec, unsigned int len)
211{ 222{
212 char *str; 223 char *str;
213 struct xenbus_transaction xbt; 224 struct xenbus_transaction xbt;
214 int err; 225 int err;
215 static struct shutdown_handler handlers[] = { 226 int idx;
216 { "poweroff", do_poweroff },
217 { "halt", do_poweroff },
218 { "reboot", do_reboot },
219#ifdef CONFIG_HIBERNATE_CALLBACKS
220 { "suspend", do_suspend },
221#endif
222 {NULL, NULL},
223 };
224 static struct shutdown_handler *handler;
225 227
226 if (shutting_down != SHUTDOWN_INVALID) 228 if (shutting_down != SHUTDOWN_INVALID)
227 return; 229 return;
@@ -238,13 +240,13 @@ static void shutdown_handler(struct xenbus_watch *watch,
238 return; 240 return;
239 } 241 }
240 242
241 for (handler = &handlers[0]; handler->command; handler++) { 243 for (idx = 0; idx < ARRAY_SIZE(shutdown_handlers); idx++) {
242 if (strcmp(str, handler->command) == 0) 244 if (strcmp(str, shutdown_handlers[idx].command) == 0)
243 break; 245 break;
244 } 246 }
245 247
246 /* Only acknowledge commands which we are prepared to handle. */ 248 /* Only acknowledge commands which we are prepared to handle. */
247 if (handler->cb) 249 if (idx < ARRAY_SIZE(shutdown_handlers))
248 xenbus_write(xbt, "control", "shutdown", ""); 250 xenbus_write(xbt, "control", "shutdown", "");
249 251
250 err = xenbus_transaction_end(xbt, 0); 252 err = xenbus_transaction_end(xbt, 0);
@@ -253,8 +255,8 @@ static void shutdown_handler(struct xenbus_watch *watch,
253 goto again; 255 goto again;
254 } 256 }
255 257
256 if (handler->cb) { 258 if (idx < ARRAY_SIZE(shutdown_handlers)) {
257 handler->cb(); 259 shutdown_handlers[idx].cb();
258 } else { 260 } else {
259 pr_info("Ignoring shutdown request: %s\n", str); 261 pr_info("Ignoring shutdown request: %s\n", str);
260 shutting_down = SHUTDOWN_INVALID; 262 shutting_down = SHUTDOWN_INVALID;
@@ -310,6 +312,9 @@ static struct notifier_block xen_reboot_nb = {
310static int setup_shutdown_watcher(void) 312static int setup_shutdown_watcher(void)
311{ 313{
312 int err; 314 int err;
315 int idx;
316#define FEATURE_PATH_SIZE (SHUTDOWN_CMD_SIZE + sizeof("feature-"))
317 char node[FEATURE_PATH_SIZE];
313 318
314 err = register_xenbus_watch(&shutdown_watch); 319 err = register_xenbus_watch(&shutdown_watch);
315 if (err) { 320 if (err) {
@@ -326,6 +331,14 @@ static int setup_shutdown_watcher(void)
326 } 331 }
327#endif 332#endif
328 333
334 for (idx = 0; idx < ARRAY_SIZE(shutdown_handlers); idx++) {
335 if (!shutdown_handlers[idx].flag)
336 continue;
337 snprintf(node, FEATURE_PATH_SIZE, "feature-%s",
338 shutdown_handlers[idx].command);
339 xenbus_printf(XBT_NIL, "control", node, "%u", 1);
340 }
341
329 return 0; 342 return 0;
330} 343}
331 344
diff --git a/drivers/xen/xenbus/xenbus_dev_frontend.c b/drivers/xen/xenbus/xenbus_dev_frontend.c
index c1010f018bd8..1e8be12ebb55 100644
--- a/drivers/xen/xenbus/xenbus_dev_frontend.c
+++ b/drivers/xen/xenbus/xenbus_dev_frontend.c
@@ -364,7 +364,7 @@ out:
364 364
365static int xenbus_write_watch(unsigned msg_type, struct xenbus_file_priv *u) 365static int xenbus_write_watch(unsigned msg_type, struct xenbus_file_priv *u)
366{ 366{
367 struct watch_adapter *watch, *tmp_watch; 367 struct watch_adapter *watch;
368 char *path, *token; 368 char *path, *token;
369 int err, rc; 369 int err, rc;
370 LIST_HEAD(staging_q); 370 LIST_HEAD(staging_q);
@@ -399,7 +399,7 @@ static int xenbus_write_watch(unsigned msg_type, struct xenbus_file_priv *u)
399 } 399 }
400 list_add(&watch->list, &u->watches); 400 list_add(&watch->list, &u->watches);
401 } else { 401 } else {
402 list_for_each_entry_safe(watch, tmp_watch, &u->watches, list) { 402 list_for_each_entry(watch, &u->watches, list) {
403 if (!strcmp(watch->token, token) && 403 if (!strcmp(watch->token, token) &&
404 !strcmp(watch->watch.node, path)) { 404 !strcmp(watch->watch.node, path)) {
405 unregister_xenbus_watch(&watch->watch); 405 unregister_xenbus_watch(&watch->watch);
diff --git a/drivers/xen/xenbus/xenbus_probe_frontend.c b/drivers/xen/xenbus/xenbus_probe_frontend.c
index 611a23119675..6d40a972ffb2 100644
--- a/drivers/xen/xenbus/xenbus_probe_frontend.c
+++ b/drivers/xen/xenbus/xenbus_probe_frontend.c
@@ -335,7 +335,9 @@ static int backend_state;
335static void xenbus_reset_backend_state_changed(struct xenbus_watch *w, 335static void xenbus_reset_backend_state_changed(struct xenbus_watch *w,
336 const char **v, unsigned int l) 336 const char **v, unsigned int l)
337{ 337{
338 xenbus_scanf(XBT_NIL, v[XS_WATCH_PATH], "", "%i", &backend_state); 338 if (xenbus_scanf(XBT_NIL, v[XS_WATCH_PATH], "", "%i",
339 &backend_state) != 1)
340 backend_state = XenbusStateUnknown;
339 printk(KERN_DEBUG "XENBUS: backend %s %s\n", 341 printk(KERN_DEBUG "XENBUS: backend %s %s\n",
340 v[XS_WATCH_PATH], xenbus_strstate(backend_state)); 342 v[XS_WATCH_PATH], xenbus_strstate(backend_state));
341 wake_up(&backend_state_wq); 343 wake_up(&backend_state_wq);