aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/ABI/testing/configfs-usb-gadget-mass-storage31
-rw-r--r--Documentation/connector/ucon.c2
-rw-r--r--Documentation/devicetree/bindings/phy/phy-bindings.txt66
-rw-r--r--Documentation/devicetree/bindings/phy/samsung-phy.txt22
-rw-r--r--Documentation/devicetree/bindings/usb/msm-hsusb.txt17
-rw-r--r--Documentation/devicetree/bindings/usb/omap-usb.txt39
-rw-r--r--Documentation/devicetree/bindings/usb/usb-nop-xceiv.txt7
-rw-r--r--Documentation/devicetree/bindings/usb/usb-phy.txt6
-rw-r--r--Documentation/devicetree/bindings/video/exynos_dp.txt17
-rw-r--r--Documentation/networking/dccp.txt4
-rw-r--r--Documentation/networking/e100.txt2
-rw-r--r--Documentation/networking/ieee802154.txt4
-rw-r--r--Documentation/networking/l2tp.txt2
-rw-r--r--Documentation/networking/netdev-FAQ.txt24
-rw-r--r--Documentation/networking/netlink_mmap.txt6
-rw-r--r--Documentation/networking/operstates.txt4
-rw-r--r--Documentation/networking/rxrpc.txt2
-rw-r--r--Documentation/networking/stmmac.txt8
-rw-r--r--Documentation/networking/vortex.txt4
-rw-r--r--Documentation/networking/x25-iface.txt2
-rw-r--r--Documentation/phy.txt166
-rw-r--r--Documentation/pps/pps.txt15
-rw-r--r--MAINTAINERS147
-rw-r--r--Makefile2
-rw-r--r--arch/arc/mm/fault.c6
-rw-r--r--arch/arm/boot/dts/integratorcp.dts9
-rw-r--r--arch/arm/boot/dts/omap3-beagle-xm.dts2
-rw-r--r--arch/arm/boot/dts/omap3-evm.dts2
-rw-r--r--arch/arm/boot/dts/omap3-overo.dtsi2
-rw-r--r--arch/arm/boot/dts/omap4.dtsi23
-rw-r--r--arch/arm/boot/dts/omap5.dtsi20
-rw-r--r--arch/arm/boot/dts/twl4030.dtsi1
-rw-r--r--arch/arm/configs/ep93xx_defconfig17
-rw-r--r--arch/arm/mach-ep93xx/clock.c2
-rw-r--r--arch/arm/mach-ep93xx/core.c39
-rw-r--r--arch/arm/mach-exynos/include/mach/regs-pmu.h5
-rw-r--r--arch/arm/mach-omap2/board-omap3beagle.c6
-rw-r--r--arch/arm/mach-omap2/twl-common.c11
-rw-r--r--arch/arm/mach-omap2/usb-host.c18
-rw-r--r--arch/arm/mach-omap2/usb.h1
-rw-r--r--arch/arm/mach-s5pv210/include/mach/regs-clock.h4
-rw-r--r--arch/arm/net/bpf_jit_32.c1
-rw-r--r--arch/arm/plat-samsung/Kconfig10
-rw-r--r--arch/arm/plat-samsung/Makefile1
-rw-r--r--arch/arm/plat-samsung/devs.c34
-rw-r--r--arch/arm/plat-samsung/include/plat/devs.h1
-rw-r--r--arch/arm/plat-samsung/setup-mipiphy.c60
-rw-r--r--arch/mips/kernel/perf_event_mipsxx.c4
-rw-r--r--arch/mips/mti-malta/malta-int.c9
-rw-r--r--arch/mips/ralink/timer.c2
-rw-r--r--arch/parisc/configs/712_defconfig2
-rw-r--r--arch/parisc/configs/a500_defconfig2
-rw-r--r--arch/parisc/configs/b180_defconfig3
-rw-r--r--arch/parisc/configs/c3000_defconfig3
-rw-r--r--arch/parisc/configs/c8000_defconfig2
-rw-r--r--arch/parisc/configs/default_defconfig2
-rw-r--r--arch/parisc/kernel/cache.c1
-rw-r--r--arch/parisc/kernel/head.S4
-rw-r--r--arch/powerpc/net/bpf_jit_comp.c1
-rw-r--r--arch/s390/include/asm/pgtable.h4
-rw-r--r--arch/s390/include/asm/timex.h28
-rw-r--r--arch/s390/kernel/compat_signal.c4
-rw-r--r--arch/s390/kernel/debug.c2
-rw-r--r--arch/s390/kvm/interrupt.c6
-rw-r--r--arch/s390/lib/delay.c14
-rw-r--r--arch/s390/net/bpf_jit_comp.c4
-rw-r--r--arch/sparc/net/bpf_jit_comp.c1
-rw-r--r--arch/um/kernel/exitcode.c4
-rw-r--r--arch/x86/include/asm/percpu.h3
-rw-r--r--arch/x86/kernel/cpu/perf_event.c6
-rw-r--r--arch/x86/kernel/kvm.c2
-rw-r--r--arch/x86/kernel/nmi.c4
-rw-r--r--arch/x86/net/bpf_jit_comp.c18
-rw-r--r--arch/xtensa/kernel/entry.S49
-rw-r--r--arch/xtensa/kernel/signal.c2
-rw-r--r--arch/xtensa/platforms/iss/network.c3
-rw-r--r--drivers/Kconfig2
-rw-r--r--drivers/Makefile2
-rw-r--r--drivers/ata/ahci.c2
-rw-r--r--drivers/ata/ahci_platform.c2
-rw-r--r--drivers/ata/libahci.c10
-rw-r--r--drivers/ata/libata-eh.c6
-rw-r--r--drivers/ata/pata_isapnp.c2
-rw-r--r--drivers/clk/clk-nomadik.c21
-rw-r--r--drivers/clk/mvebu/armada-370.c4
-rw-r--r--drivers/clk/socfpga/clk.c2
-rw-r--r--drivers/clk/versatile/clk-icst.c2
-rw-r--r--drivers/connector/cn_proc.c18
-rw-r--r--drivers/connector/connector.c9
-rw-r--r--drivers/cpufreq/acpi-cpufreq.c8
-rw-r--r--drivers/cpufreq/intel_pstate.c38
-rw-r--r--drivers/dma/edma.c2
-rw-r--r--drivers/gpu/drm/drm_drv.c11
-rw-r--r--drivers/gpu/drm/i915/i915_drv.c5
-rw-r--r--drivers/gpu/drm/i915/i915_drv.h8
-rw-r--r--drivers/gpu/drm/i915/i915_gem_gtt.c109
-rw-r--r--drivers/gpu/drm/i915/i915_reg.h6
-rw-r--r--drivers/gpu/drm/i915/intel_crt.c28
-rw-r--r--drivers/gpu/drm/i915/intel_ddi.c21
-rw-r--r--drivers/gpu/drm/i915/intel_display.c131
-rw-r--r--drivers/gpu/drm/i915/intel_dp.c20
-rw-r--r--drivers/gpu/drm/i915/intel_drv.h2
-rw-r--r--drivers/gpu/drm/i915/intel_lvds.c16
-rw-r--r--drivers/gpu/drm/i915/intel_pm.c4
-rw-r--r--drivers/gpu/drm/radeon/atombios_encoders.c54
-rw-r--r--drivers/gpu/drm/radeon/cik.c4
-rw-r--r--drivers/gpu/drm/radeon/dce6_afmt.c3
-rw-r--r--drivers/gpu/drm/radeon/evergreen_hdmi.c4
-rw-r--r--drivers/gpu/drm/radeon/kv_dpm.c2
-rw-r--r--drivers/gpu/drm/radeon/ni.c1
-rw-r--r--drivers/gpu/drm/radeon/r600.c1
-rw-r--r--drivers/gpu/drm/radeon/r600_hdmi.c3
-rw-r--r--drivers/gpu/drm/radeon/radeon.h4
-rw-r--r--drivers/gpu/drm/radeon/radeon_connectors.c33
-rw-r--r--drivers/gpu/drm/radeon/radeon_cs.c3
-rw-r--r--drivers/gpu/drm/radeon/radeon_drv.c4
-rw-r--r--drivers/gpu/drm/radeon/radeon_uvd.c3
-rw-r--r--drivers/gpu/drm/radeon/si.c1
-rw-r--r--drivers/gpu/drm/radeon/uvd_v1_0.c4
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_drv.c17
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_resource.c2
-rw-r--r--drivers/hid/hid-core.c12
-rw-r--r--drivers/hid/hid-ids.h6
-rw-r--r--drivers/hid/hid-input.c13
-rw-r--r--drivers/hid/hid-wiimote-core.c5
-rw-r--r--drivers/hid/usbhid/hid-quirks.c3
-rw-r--r--drivers/infiniband/Kconfig11
-rw-r--r--drivers/infiniband/core/uverbs.h2
-rw-r--r--drivers/infiniband/core/uverbs_cmd.c4
-rw-r--r--drivers/infiniband/core/uverbs_main.c6
-rw-r--r--drivers/infiniband/hw/mlx4/main.c2
-rw-r--r--drivers/infiniband/ulp/isert/ib_isert.c2
-rw-r--r--drivers/input/input.c10
-rw-r--r--drivers/input/keyboard/pxa27x_keypad.c11
-rw-r--r--drivers/input/misc/cm109.c14
-rw-r--r--drivers/input/mouse/alps.c1
-rw-r--r--drivers/input/serio/i8042.c23
-rw-r--r--drivers/input/tablet/wacom_sys.c4
-rw-r--r--drivers/input/tablet/wacom_wac.c8
-rw-r--r--drivers/md/bcache/request.c2
-rw-r--r--drivers/md/md.c5
-rw-r--r--drivers/md/raid1.c1
-rw-r--r--drivers/md/raid10.c1
-rw-r--r--drivers/md/raid5.c20
-rw-r--r--drivers/media/dvb-frontends/tda10071.c9
-rw-r--r--drivers/media/i2c/ad9389b.c15
-rw-r--r--drivers/media/i2c/adv7511.c18
-rw-r--r--drivers/media/i2c/adv7842.c30
-rw-r--r--drivers/media/i2c/ths8200.c12
-rw-r--r--drivers/media/pci/saa7134/saa7134-video.c1
-rw-r--r--drivers/media/platform/exynos4-is/Kconfig2
-rw-r--r--drivers/media/platform/exynos4-is/mipi-csis.c13
-rw-r--r--drivers/media/platform/s5p-jpeg/jpeg-core.c1
-rw-r--r--drivers/media/platform/sh_vou.c2
-rw-r--r--drivers/media/platform/soc_camera/mx3_camera.c5
-rw-r--r--drivers/media/tuners/e4000.c3
-rw-r--r--drivers/media/usb/stkwebcam/stk-webcam.c7
-rw-r--r--drivers/media/usb/uvc/uvc_driver.c18
-rw-r--r--drivers/media/v4l2-core/videobuf2-core.c4
-rw-r--r--drivers/media/v4l2-core/videobuf2-dma-contig.c87
-rw-r--r--drivers/mtd/nand/gpmi-nand/gpmi-nand.c2
-rw-r--r--drivers/mtd/nand/pxa3xx_nand.c7
-rw-r--r--drivers/net/can/at91_can.c4
-rw-r--r--drivers/net/can/c_can/c_can.c6
-rw-r--r--drivers/net/can/dev.c10
-rw-r--r--drivers/net/can/flexcan.c14
-rw-r--r--drivers/net/can/usb/kvaser_usb.c20
-rw-r--r--drivers/net/ethernet/broadcom/bgmac.c20
-rw-r--r--drivers/net/ethernet/broadcom/bnx2x/bnx2x.h15
-rw-r--r--drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c11
-rw-r--r--drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c40
-rw-r--r--drivers/net/ethernet/broadcom/bnx2x/bnx2x_init.h38
-rw-r--r--drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c388
-rw-r--r--drivers/net/ethernet/broadcom/bnx2x/bnx2x_sriov.c45
-rw-r--r--drivers/net/ethernet/broadcom/bnx2x/bnx2x_stats.c2
-rw-r--r--drivers/net/ethernet/broadcom/bnx2x/bnx2x_vfpf.c2
-rw-r--r--drivers/net/ethernet/calxeda/xgmac.c23
-rw-r--r--drivers/net/ethernet/chelsio/cxgb3/sge.c3
-rw-r--r--drivers/net/ethernet/davicom/dm9000.c56
-rw-r--r--drivers/net/ethernet/emulex/benet/be.h9
-rw-r--r--drivers/net/ethernet/emulex/benet/be_cmds.c3
-rw-r--r--drivers/net/ethernet/emulex/benet/be_main.c6
-rw-r--r--drivers/net/ethernet/freescale/gianfar.c38
-rw-r--r--drivers/net/ethernet/ibm/emac/mal.c16
-rw-r--r--drivers/net/ethernet/intel/igb/igb_ethtool.c2
-rw-r--r--drivers/net/ethernet/marvell/mv643xx_eth.c7
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/cmd.c2
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/en_rx.c41
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/mlx4_en.h4
-rw-r--r--drivers/net/ethernet/moxa/moxart_ether.c22
-rw-r--r--drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_hw.c6
-rw-r--r--drivers/net/ethernet/qlogic/qlcnic/qlcnic_ethtool.c2
-rw-r--r--drivers/net/ethernet/qlogic/qlcnic/qlcnic_hw.c7
-rw-r--r--drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c19
-rw-r--r--drivers/net/ethernet/renesas/sh_eth.c4
-rw-r--r--drivers/net/ethernet/sfc/ef10.c87
-rw-r--r--drivers/net/ethernet/sfc/mcdi.c18
-rw-r--r--drivers/net/ethernet/sfc/mcdi_pcol.h56
-rw-r--r--drivers/net/ethernet/sfc/nic.c9
-rw-r--r--drivers/net/ethernet/sfc/nic.h12
-rw-r--r--drivers/net/ethernet/smsc/smc91x.h6
-rw-r--r--drivers/net/ethernet/ti/cpsw.c19
-rw-r--r--drivers/net/ethernet/ti/davinci_emac.c3
-rw-r--r--drivers/net/hamradio/yam.c1
-rw-r--r--drivers/net/ieee802154/mrf24j40.c31
-rw-r--r--drivers/net/netconsole.c18
-rw-r--r--drivers/net/tun.c8
-rw-r--r--drivers/net/usb/ax88179_178a.c34
-rw-r--r--drivers/net/usb/qmi_wwan.c1
-rw-r--r--drivers/net/usb/usbnet.c4
-rw-r--r--drivers/net/virtio_net.c13
-rw-r--r--drivers/net/wan/farsync.c1
-rw-r--r--drivers/net/wan/sbni.c89
-rw-r--r--drivers/net/wan/wanxl.c1
-rw-r--r--drivers/net/wireless/ath/ath9k/main.c23
-rw-r--r--drivers/net/wireless/ath/ath9k/xmit.c9
-rw-r--r--drivers/net/wireless/cw1200/cw1200_spi.c2
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-6000.c6
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-config.h1
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-trans.h6
-rw-r--r--drivers/net/wireless/iwlwifi/mvm/power.c5
-rw-r--r--drivers/net/wireless/iwlwifi/mvm/scan.c12
-rw-r--r--drivers/net/wireless/iwlwifi/pcie/drv.c42
-rw-r--r--drivers/net/wireless/iwlwifi/pcie/trans.c8
-rw-r--r--drivers/net/wireless/iwlwifi/pcie/tx.c2
-rw-r--r--drivers/net/wireless/mwifiex/join.c10
-rw-r--r--drivers/net/wireless/mwifiex/main.c6
-rw-r--r--drivers/net/wireless/mwifiex/sta_event.c3
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00pci.c9
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192cu/trx.c3
-rw-r--r--drivers/net/xen-netback/common.h1
-rw-r--r--drivers/net/xen-netback/interface.c3
-rw-r--r--drivers/net/xen-netback/netback.c10
-rw-r--r--drivers/net/xen-netback/xenbus.c4
-rw-r--r--drivers/pci/hotplug/acpiphp_glue.c6
-rw-r--r--drivers/phy/Kconfig54
-rw-r--r--drivers/phy/Makefile9
-rw-r--r--drivers/phy/phy-core.c698
-rw-r--r--drivers/phy/phy-exynos-dp-video.c111
-rw-r--r--drivers/phy/phy-exynos-mipi-video.c176
-rw-r--r--drivers/phy/phy-omap-usb2.c (renamed from drivers/usb/phy/phy-omap-usb2.c)72
-rw-r--r--drivers/phy/phy-twl4030-usb.c (renamed from drivers/usb/phy/phy-twl4030-usb.c)71
-rw-r--r--drivers/platform/x86/Kconfig1
-rw-r--r--drivers/platform/x86/sony-laptop.c26
-rw-r--r--drivers/s390/block/dasd_eckd.c98
-rw-r--r--drivers/s390/char/sclp.c4
-rw-r--r--drivers/s390/char/vmlogrdr.c2
-rw-r--r--drivers/s390/cio/cio.c4
-rw-r--r--drivers/s390/cio/qdio_main.c10
-rw-r--r--drivers/scsi/BusLogic.c16
-rw-r--r--drivers/scsi/aacraid/linit.c2
-rw-r--r--drivers/scsi/qla2xxx/qla_dbg.c2
-rw-r--r--drivers/scsi/qla2xxx/qla_isr.c9
-rw-r--r--drivers/scsi/sd.c2
-rw-r--r--drivers/scsi/sg.c176
-rw-r--r--drivers/staging/bcm/Bcmchar.c1
-rw-r--r--drivers/staging/media/msi3101/Kconfig1
-rw-r--r--drivers/staging/media/msi3101/sdr-msi3101.c10
-rw-r--r--drivers/staging/ozwpan/ozcdev.c3
-rw-r--r--drivers/staging/sb105x/sb_pci_mp.c2
-rw-r--r--drivers/staging/wlags49_h2/wl_priv.c9
-rw-r--r--drivers/target/target_core_pscsi.c8
-rw-r--r--drivers/target/target_core_sbc.c5
-rw-r--r--drivers/target/target_core_xcopy.c53
-rw-r--r--drivers/thermal/samsung/exynos_thermal_common.c2
-rw-r--r--drivers/thermal/samsung/exynos_tmu.c12
-rw-r--r--drivers/thermal/samsung/exynos_tmu.h7
-rw-r--r--drivers/thermal/samsung/exynos_tmu_data.c30
-rw-r--r--drivers/thermal/samsung/exynos_tmu_data.h13
-rw-r--r--drivers/thermal/thermal_hwmon.c2
-rw-r--r--drivers/thermal/ti-soc-thermal/ti-thermal-common.c1
-rw-r--r--drivers/thermal/x86_pkg_temp_thermal.c14
-rw-r--r--drivers/tty/serial/atmel_serial.c9
-rw-r--r--drivers/uio/uio.c17
-rw-r--r--drivers/usb/atm/usbatm.h14
-rw-r--r--drivers/usb/chipidea/bits.h1
-rw-r--r--drivers/usb/chipidea/ci_hdrc_imx.c21
-rw-r--r--drivers/usb/chipidea/core.c123
-rw-r--r--drivers/usb/chipidea/host.c6
-rw-r--r--drivers/usb/chipidea/udc.c56
-rw-r--r--drivers/usb/class/cdc-wdm.c42
-rw-r--r--drivers/usb/core/devio.c38
-rw-r--r--drivers/usb/core/driver.c7
-rw-r--r--drivers/usb/core/file.c8
-rw-r--r--drivers/usb/core/hcd-pci.c3
-rw-r--r--drivers/usb/core/hcd.c122
-rw-r--r--drivers/usb/core/hub.c182
-rw-r--r--drivers/usb/core/message.c4
-rw-r--r--drivers/usb/core/quirks.c37
-rw-r--r--drivers/usb/core/sysfs.c64
-rw-r--r--drivers/usb/core/urb.c44
-rw-r--r--drivers/usb/core/usb.c2
-rw-r--r--drivers/usb/core/usb.h1
-rw-r--r--drivers/usb/dwc3/core.c3
-rw-r--r--drivers/usb/dwc3/dwc3-pci.c2
-rw-r--r--drivers/usb/dwc3/ep0.c6
-rw-r--r--drivers/usb/early/ehci-dbgp.c4
-rw-r--r--drivers/usb/gadget/Kconfig34
-rw-r--r--drivers/usb/gadget/Makefile5
-rw-r--r--drivers/usb/gadget/acm_ms.c125
-rw-r--r--drivers/usb/gadget/amd5536udc.c2
-rw-r--r--drivers/usb/gadget/composite.c2
-rw-r--r--drivers/usb/gadget/configfs.c10
-rw-r--r--drivers/usb/gadget/configfs.h6
-rw-r--r--drivers/usb/gadget/dummy_hcd.c6
-rw-r--r--drivers/usb/gadget/f_mass_storage.c1254
-rw-r--r--drivers/usb/gadget/f_mass_storage.h166
-rw-r--r--drivers/usb/gadget/g_ffs.c2
-rw-r--r--drivers/usb/gadget/goku_udc.c3
-rw-r--r--drivers/usb/gadget/mass_storage.c125
-rw-r--r--drivers/usb/gadget/multi.c247
-rw-r--r--drivers/usb/gadget/mv_u3d_core.c4
-rw-r--r--drivers/usb/gadget/net2280.c5
-rw-r--r--drivers/usb/gadget/pch_udc.c1
-rw-r--r--drivers/usb/gadget/rndis.c2
-rw-r--r--drivers/usb/gadget/s3c-hsotg.c167
-rw-r--r--drivers/usb/gadget/storage_common.c430
-rw-r--r--drivers/usb/gadget/storage_common.h229
-rw-r--r--drivers/usb/gadget/tcm_usb_gadget.c4
-rw-r--r--drivers/usb/gadget/udc-core.c3
-rw-r--r--drivers/usb/gadget/zero.c25
-rw-r--r--drivers/usb/host/Kconfig59
-rw-r--r--drivers/usb/host/Makefile11
-rw-r--r--drivers/usb/host/ehci-atmel.c16
-rw-r--r--drivers/usb/host/ehci-dbg.c113
-rw-r--r--drivers/usb/host/ehci-exynos.c (renamed from drivers/usb/host/ehci-s5p.c)164
-rw-r--r--drivers/usb/host/ehci-fsl.c4
-rw-r--r--drivers/usb/host/ehci-grlib.c2
-rw-r--r--drivers/usb/host/ehci-hcd.c42
-rw-r--r--drivers/usb/host/ehci-mem.c4
-rw-r--r--drivers/usb/host/ehci-msm.c20
-rw-r--r--drivers/usb/host/ehci-mv.c2
-rw-r--r--drivers/usb/host/ehci-octeon.c2
-rw-r--r--drivers/usb/host/ehci-pci.c24
-rw-r--r--drivers/usb/host/ehci-pmcmsp.c2
-rw-r--r--drivers/usb/host/ehci-ppc-of.c2
-rw-r--r--drivers/usb/host/ehci-ps3.c2
-rw-r--r--drivers/usb/host/ehci-q.c64
-rw-r--r--drivers/usb/host/ehci-sched.c1033
-rw-r--r--drivers/usb/host/ehci-sead3.c2
-rw-r--r--drivers/usb/host/ehci-sh.c2
-rw-r--r--drivers/usb/host/ehci-sysfs.c15
-rw-r--r--drivers/usb/host/ehci-tegra.c4
-rw-r--r--drivers/usb/host/ehci-tilegx.c2
-rw-r--r--drivers/usb/host/ehci-w90x900.c89
-rw-r--r--drivers/usb/host/ehci-xilinx-of.c2
-rw-r--r--drivers/usb/host/ehci.h81
-rw-r--r--drivers/usb/host/fotg210-hcd.c2
-rw-r--r--drivers/usb/host/fusbh200-hcd.c2
-rw-r--r--drivers/usb/host/hwa-hc.c33
-rw-r--r--drivers/usb/host/isp1362-hcd.c2
-rw-r--r--drivers/usb/host/ohci-at91.c156
-rw-r--r--drivers/usb/host/ohci-dbg.c2
-rw-r--r--drivers/usb/host/ohci-ep93xx.c184
-rw-r--r--drivers/usb/host/ohci-exynos.c184
-rw-r--r--drivers/usb/host/ohci-hcd.c159
-rw-r--r--drivers/usb/host/ohci-hub.c9
-rw-r--r--drivers/usb/host/ohci-nxp.c123
-rw-r--r--drivers/usb/host/ohci-omap.c169
-rw-r--r--drivers/usb/host/ohci-omap3.c118
-rw-r--r--drivers/usb/host/ohci-pci.c15
-rw-r--r--drivers/usb/host/ohci-platform.c11
-rw-r--r--drivers/usb/host/ohci-pxa27x.c249
-rw-r--r--drivers/usb/host/ohci-s3c2410.c128
-rw-r--r--drivers/usb/host/ohci-sm501.c11
-rw-r--r--drivers/usb/host/ohci-spear.c140
-rw-r--r--drivers/usb/host/pci-quirks.c137
-rw-r--r--drivers/usb/host/pci-quirks.h2
-rw-r--r--drivers/usb/host/sl811-hcd.c4
-rw-r--r--drivers/usb/host/uhci-debug.c16
-rw-r--r--drivers/usb/host/uhci-hub.c40
-rw-r--r--drivers/usb/host/uhci-pci.c19
-rw-r--r--drivers/usb/host/uhci-platform.c3
-rw-r--r--drivers/usb/host/whci/hcd.c4
-rw-r--r--drivers/usb/host/xhci-hub.c5
-rw-r--r--drivers/usb/host/xhci-mem.c10
-rw-r--r--drivers/usb/host/xhci-ring.c324
-rw-r--r--drivers/usb/host/xhci.c182
-rw-r--r--drivers/usb/host/xhci.h3
-rw-r--r--drivers/usb/misc/usbtest.c172
-rw-r--r--drivers/usb/musb/Kconfig5
-rw-r--r--drivers/usb/musb/am35x.c63
-rw-r--r--drivers/usb/musb/blackfin.c13
-rw-r--r--drivers/usb/musb/da8xx.c49
-rw-r--r--drivers/usb/musb/davinci.c59
-rw-r--r--drivers/usb/musb/musb_am335x.c2
-rw-r--r--drivers/usb/musb/musb_core.c19
-rw-r--r--drivers/usb/musb/musb_core.h2
-rw-r--r--drivers/usb/musb/musb_cppi41.c8
-rw-r--r--drivers/usb/musb/musb_dsps.c96
-rw-r--r--drivers/usb/musb/musb_gadget.c2
-rw-r--r--drivers/usb/musb/musb_host.c2
-rw-r--r--drivers/usb/musb/musb_virthub.c19
-rw-r--r--drivers/usb/musb/omap2430.c54
-rw-r--r--drivers/usb/musb/tusb6010.c49
-rw-r--r--drivers/usb/musb/ux500.c13
-rw-r--r--drivers/usb/phy/Kconfig35
-rw-r--r--drivers/usb/phy/Makefile3
-rw-r--r--drivers/usb/phy/phy-am335x-control.c44
-rw-r--r--drivers/usb/phy/phy-am335x.c44
-rw-r--r--drivers/usb/phy/phy-fsl-usb.c96
-rw-r--r--drivers/usb/phy/phy-fsl-usb.h4
-rw-r--r--drivers/usb/phy/phy-fsm-usb.c72
-rw-r--r--drivers/usb/phy/phy-fsm-usb.h179
-rw-r--r--drivers/usb/phy/phy-generic.c108
-rw-r--r--drivers/usb/phy/phy-generic.h7
-rw-r--r--drivers/usb/phy/phy-omap-control.c208
-rw-r--r--drivers/usb/phy/phy-omap-usb3.c32
-rw-r--r--drivers/usb/phy/phy-rcar-gen2-usb.c248
-rw-r--r--drivers/usb/phy/phy-samsung-usb2.c3
-rw-r--r--drivers/usb/phy/phy-samsung-usb3.c3
-rw-r--r--drivers/usb/phy/phy-tegra-usb.c2
-rw-r--r--drivers/usb/phy/phy-twl6030-usb.c1
-rw-r--r--drivers/usb/phy/phy-ulpi-viewport.c2
-rw-r--r--drivers/usb/phy/phy.c2
-rw-r--r--drivers/usb/serial/cyberjack.c2
-rw-r--r--drivers/usb/serial/ftdi_sio.c11
-rw-r--r--drivers/usb/serial/ftdi_sio_ids.h6
-rw-r--r--drivers/usb/serial/generic.c82
-rw-r--r--drivers/usb/serial/mos7840.c4
-rw-r--r--drivers/usb/serial/option.c17
-rw-r--r--drivers/usb/serial/pl2303.c274
-rw-r--r--drivers/usb/wusbcore/cbaf.c7
-rw-r--r--drivers/usb/wusbcore/devconnect.c2
-rw-r--r--drivers/usb/wusbcore/wa-hc.c18
-rw-r--r--drivers/usb/wusbcore/wa-hc.h42
-rw-r--r--drivers/usb/wusbcore/wa-rpipe.c22
-rw-r--r--drivers/usb/wusbcore/wa-xfer.c1261
-rw-r--r--drivers/uwb/lc-dev.c16
-rw-r--r--drivers/vhost/scsi.c2
-rw-r--r--drivers/video/au1100fb.c26
-rw-r--r--drivers/video/au1200fb.c23
-rw-r--r--drivers/video/exynos/Kconfig3
-rw-r--r--drivers/video/exynos/exynos_dp_core.c132
-rw-r--r--drivers/video/exynos/exynos_dp_core.h110
-rw-r--r--drivers/video/exynos/exynos_dp_reg.c2
-rw-r--r--drivers/video/exynos/exynos_mipi_dsi.c19
-rw-r--r--fs/dcache.c20
-rw-r--r--fs/ecryptfs/crypto.c2
-rw-r--r--fs/ecryptfs/keystore.c3
-rw-r--r--fs/eventpoll.c4
-rw-r--r--fs/file_table.c4
-rw-r--r--fs/jfs/jfs_inode.c3
-rw-r--r--fs/namei.c3
-rw-r--r--fs/select.c3
-rw-r--r--fs/seq_file.c2
-rw-r--r--include/linux/filter.h15
-rw-r--r--include/linux/i2c/twl.h2
-rw-r--r--include/linux/ipc_namespace.h6
-rw-r--r--include/linux/netdevice.h5
-rw-r--r--include/linux/netpoll.h5
-rw-r--r--include/linux/percpu.h8
-rw-r--r--include/linux/phy/phy.h270
-rw-r--r--include/linux/platform_data/mipi-csis.h9
-rw-r--r--include/linux/platform_data/usb-ehci-s5p.h21
-rw-r--r--include/linux/platform_data/usb-ohci-exynos.h21
-rw-r--r--include/linux/platform_data/usb-rcar-gen2-phy.h22
-rw-r--r--include/linux/printk.h16
-rw-r--r--include/linux/usb.h10
-rw-r--r--include/linux/usb/hcd.h16
-rw-r--r--include/linux/usb/intel_mid_otg.h180
-rw-r--r--include/linux/usb/musb.h2
-rw-r--r--include/linux/usb/omap_control_usb.h33
-rw-r--r--include/linux/usb/serial.h2
-rw-r--r--include/linux/usb/usb_phy_gen_xceiv.h3
-rw-r--r--include/linux/usb/wusb-wa.h51
-rw-r--r--include/linux/yam.h2
-rw-r--r--include/net/cipso_ipv4.h6
-rw-r--r--include/net/dst.h12
-rw-r--r--include/net/ip6_fib.h1
-rw-r--r--include/net/ip6_route.h6
-rw-r--r--include/net/mac802154.h2
-rw-r--r--include/net/sock.h6
-rw-r--r--include/sound/rcar_snd.h1
-rw-r--r--include/trace/events/target.h4
-rw-r--r--include/uapi/drm/drm_mode.h2
-rw-r--r--include/uapi/linux/perf_event.h12
-rw-r--r--include/uapi/linux/tc_act/Kbuild1
-rw-r--r--include/uapi/linux/tc_act/tc_defact.h (renamed from include/linux/tc_act/tc_defact.h)2
-rw-r--r--include/uapi/rdma/ib_user_verbs.h6
-rw-r--r--include/video/exynos_dp.h131
-rw-r--r--include/video/exynos_mipi_dsim.h5
-rw-r--r--ipc/ipc_sysctl.c20
-rw-r--r--kernel/cgroup.c14
-rw-r--r--kernel/events/core.c4
-rw-r--r--kernel/events/ring_buffer.c31
-rw-r--r--kernel/mutex.c32
-rw-r--r--kernel/power/hibernate.c2
-rw-r--r--kernel/time/clockevents.c65
-rw-r--r--lib/Kconfig.debug2
-rw-r--r--lib/scatterlist.c3
-rw-r--r--mm/huge_memory.c70
-rw-r--r--mm/list_lru.c3
-rw-r--r--mm/memcontrol.c57
-rw-r--r--mm/memory.c53
-rw-r--r--mm/migrate.c19
-rw-r--r--mm/mprotect.c2
-rw-r--r--mm/pagewalk.c2
-rw-r--r--net/8021q/vlan_netlink.c2
-rw-r--r--net/batman-adv/main.c5
-rw-r--r--net/batman-adv/network-coding.c28
-rw-r--r--net/batman-adv/network-coding.h14
-rw-r--r--net/bridge/br_device.c2
-rw-r--r--net/bridge/br_fdb.c4
-rw-r--r--net/bridge/br_input.c2
-rw-r--r--net/bridge/br_mdb.c2
-rw-r--r--net/bridge/br_multicast.c82
-rw-r--r--net/bridge/br_netlink.c2
-rw-r--r--net/bridge/br_private.h11
-rw-r--r--net/bridge/br_stp_if.c2
-rw-r--r--net/bridge/br_vlan.c125
-rw-r--r--net/bridge/netfilter/ebt_ulog.c9
-rw-r--r--net/compat.c2
-rw-r--r--net/core/dev.c3
-rw-r--r--net/core/filter.c8
-rw-r--r--net/core/flow_dissector.c2
-rw-r--r--net/core/netpoll.c31
-rw-r--r--net/core/secure_seq.c2
-rw-r--r--net/core/sock.c1
-rw-r--r--net/ieee802154/6lowpan.c5
-rw-r--r--net/ipv4/inet_hashtables.c2
-rw-r--r--net/ipv4/ip_output.c13
-rw-r--r--net/ipv4/ip_vti.c14
-rw-r--r--net/ipv4/netfilter/arp_tables.c5
-rw-r--r--net/ipv4/netfilter/ip_tables.c5
-rw-r--r--net/ipv4/netfilter/ipt_ULOG.c7
-rw-r--r--net/ipv4/route.c2
-rw-r--r--net/ipv4/tcp_input.c43
-rw-r--r--net/ipv4/tcp_offload.c13
-rw-r--r--net/ipv4/tcp_output.c14
-rw-r--r--net/ipv4/xfrm4_policy.c7
-rw-r--r--net/ipv6/ah6.c3
-rw-r--r--net/ipv6/esp6.c3
-rw-r--r--net/ipv6/inet6_hashtables.c2
-rw-r--r--net/ipv6/ip6_gre.c6
-rw-r--r--net/ipv6/ip6_output.c29
-rw-r--r--net/ipv6/ip6_tunnel.c12
-rw-r--r--net/ipv6/ipcomp6.c3
-rw-r--r--net/ipv6/netfilter/ip6_tables.c5
-rw-r--r--net/ipv6/route.c55
-rw-r--r--net/ipv6/udp.c5
-rw-r--r--net/ipv6/xfrm6_policy.c7
-rw-r--r--net/key/af_key.c3
-rw-r--r--net/l2tp/l2tp_core.c36
-rw-r--r--net/l2tp/l2tp_core.h3
-rw-r--r--net/l2tp/l2tp_ppp.c4
-rw-r--r--net/mac80211/cfg.c2
-rw-r--r--net/mac80211/ieee80211_i.h3
-rw-r--r--net/mac80211/offchannel.c2
-rw-r--r--net/mac80211/rx.c3
-rw-r--r--net/mac80211/scan.c19
-rw-r--r--net/mac80211/status.c3
-rw-r--r--net/mac80211/tx.c3
-rw-r--r--net/mac80211/util.c9
-rw-r--r--net/netfilter/nf_conntrack_h323_main.c4
-rw-r--r--net/netfilter/x_tables.c7
-rw-r--r--net/netfilter/xt_NFQUEUE.c7
-rw-r--r--net/openvswitch/dp_notify.c7
-rw-r--r--net/openvswitch/vport-netdev.c16
-rw-r--r--net/openvswitch/vport-netdev.h1
-rw-r--r--net/sched/sch_fq.c23
-rw-r--r--net/sched/sch_netem.c17
-rw-r--r--net/sctp/ipv6.c4
-rw-r--r--net/sctp/output.c3
-rw-r--r--net/sctp/sm_sideeffect.c1
-rw-r--r--net/socket.c24
-rw-r--r--net/unix/af_unix.c10
-rw-r--r--net/unix/diag.c1
-rw-r--r--net/wireless/core.c23
-rw-r--r--net/wireless/core.h3
-rw-r--r--net/wireless/ibss.c3
-rw-r--r--net/wireless/nl80211.c4
-rw-r--r--net/wireless/radiotap.c7
-rw-r--r--net/x25/Kconfig4
-rw-r--r--net/xfrm/xfrm_ipcomp.c12
-rw-r--r--net/xfrm/xfrm_policy.c28
-rw-r--r--net/xfrm/xfrm_replay.c54
-rw-r--r--net/xfrm/xfrm_user.c5
-rw-r--r--scripts/kallsyms.c12
-rw-r--r--scripts/link-vmlinux.sh2
-rw-r--r--sound/core/pcm.c4
-rw-r--r--sound/pci/hda/hda_codec.c4
-rw-r--r--sound/pci/hda/hda_generic.c4
-rw-r--r--sound/pci/hda/patch_analog.c18
-rw-r--r--sound/pci/hda/patch_realtek.c1
-rw-r--r--sound/soc/codecs/pcm1681.c2
-rw-r--r--sound/soc/codecs/pcm1792a.c2
-rw-r--r--sound/soc/codecs/tlv320aic3x.c4
-rw-r--r--sound/soc/codecs/wm_hubs.c1
-rw-r--r--sound/soc/fsl/fsl_ssi.c2
-rw-r--r--sound/soc/fsl/imx-mc13783.c2
-rw-r--r--sound/soc/fsl/imx-ssi.c23
-rw-r--r--sound/soc/fsl/imx-ssi.h2
-rw-r--r--sound/soc/omap/Kconfig4
-rw-r--r--sound/soc/sh/rcar/rsnd.h4
-rw-r--r--sound/soc/soc-dapm.c4
-rw-r--r--tools/perf/Documentation/perf-record.txt14
-rw-r--r--tools/perf/Documentation/perf-top.txt18
-rw-r--r--tools/perf/builtin-kvm.c7
-rw-r--r--tools/perf/builtin-record.c73
-rw-r--r--tools/perf/builtin-top.c33
-rw-r--r--tools/perf/builtin-trace.c8
-rw-r--r--tools/perf/tests/code-reading.c1
-rw-r--r--tools/perf/tests/keep-tracking.c1
-rw-r--r--tools/perf/tests/mmap-basic.c1
-rw-r--r--tools/perf/tests/open-syscall-tp-fields.c4
-rw-r--r--tools/perf/tests/perf-record.c2
-rw-r--r--tools/perf/tests/perf-time-to-tsc.c4
-rw-r--r--tools/perf/tests/sw-clock.c4
-rw-r--r--tools/perf/tests/task-exit.c6
-rw-r--r--tools/perf/ui/stdio/hist.c9
-rw-r--r--tools/perf/util/callchain.h3
-rw-r--r--tools/perf/util/event.c32
-rw-r--r--tools/perf/util/evlist.c13
-rw-r--r--tools/perf/util/evlist.h2
-rw-r--r--tools/perf/util/evsel.c1
-rw-r--r--tools/perf/util/hist.h13
-rw-r--r--tools/perf/util/probe-finder.c2
-rw-r--r--tools/perf/util/python.c2
-rw-r--r--tools/perf/util/scripting-engines/trace-event-perl.c2
-rw-r--r--tools/perf/util/scripting-engines/trace-event-python.c37
-rw-r--r--virt/kvm/kvm_main.c2
622 files changed, 12507 insertions, 7123 deletions
diff --git a/Documentation/ABI/testing/configfs-usb-gadget-mass-storage b/Documentation/ABI/testing/configfs-usb-gadget-mass-storage
new file mode 100644
index 000000000000..ad72a37ee9ff
--- /dev/null
+++ b/Documentation/ABI/testing/configfs-usb-gadget-mass-storage
@@ -0,0 +1,31 @@
1What: /config/usb-gadget/gadget/functions/mass_storage.name
2Date: Oct 2013
3KenelVersion: 3.13
4Description:
5 The attributes:
6
7 stall - Set to permit function to halt bulk endpoints.
8 Disabled on some USB devices known not to work
9 correctly. You should set it to true.
10 num_buffers - Number of pipeline buffers. Valid numbers
11 are 2..4. Available only if
12 CONFIG_USB_GADGET_DEBUG_FILES is set.
13
14What: /config/usb-gadget/gadget/functions/mass_storage.name/lun.name
15Date: Oct 2013
16KenelVersion: 3.13
17Description:
18 The attributes:
19
20 file - The path to the backing file for the LUN.
21 Required if LUN is not marked as removable.
22 ro - Flag specifying access to the LUN shall be
23 read-only. This is implied if CD-ROM emulation
24 is enabled as well as when it was impossible
25 to open "filename" in R/W mode.
26 removable - Flag specifying that LUN shall be indicated as
27 being removable.
28 cdrom - Flag specifying that LUN shall be reported as
29 being a CD-ROM.
30 nofua - Flag specifying that FUA flag
31 in SCSI WRITE(10,12)
diff --git a/Documentation/connector/ucon.c b/Documentation/connector/ucon.c
index 4848db8c71ff..8a4da64e02a8 100644
--- a/Documentation/connector/ucon.c
+++ b/Documentation/connector/ucon.c
@@ -71,7 +71,7 @@ static int netlink_send(int s, struct cn_msg *msg)
71 nlh->nlmsg_seq = seq++; 71 nlh->nlmsg_seq = seq++;
72 nlh->nlmsg_pid = getpid(); 72 nlh->nlmsg_pid = getpid();
73 nlh->nlmsg_type = NLMSG_DONE; 73 nlh->nlmsg_type = NLMSG_DONE;
74 nlh->nlmsg_len = NLMSG_LENGTH(size - sizeof(*nlh)); 74 nlh->nlmsg_len = size;
75 nlh->nlmsg_flags = 0; 75 nlh->nlmsg_flags = 0;
76 76
77 m = NLMSG_DATA(nlh); 77 m = NLMSG_DATA(nlh);
diff --git a/Documentation/devicetree/bindings/phy/phy-bindings.txt b/Documentation/devicetree/bindings/phy/phy-bindings.txt
new file mode 100644
index 000000000000..8ae844fc0c60
--- /dev/null
+++ b/Documentation/devicetree/bindings/phy/phy-bindings.txt
@@ -0,0 +1,66 @@
1This document explains only the device tree data binding. For general
2information about PHY subsystem refer to Documentation/phy.txt
3
4PHY device node
5===============
6
7Required Properties:
8#phy-cells: Number of cells in a PHY specifier; The meaning of all those
9 cells is defined by the binding for the phy node. The PHY
10 provider can use the values in cells to find the appropriate
11 PHY.
12
13For example:
14
15phys: phy {
16 compatible = "xxx";
17 reg = <...>;
18 .
19 .
20 #phy-cells = <1>;
21 .
22 .
23};
24
25That node describes an IP block (PHY provider) that implements 2 different PHYs.
26In order to differentiate between these 2 PHYs, an additonal specifier should be
27given while trying to get a reference to it.
28
29PHY user node
30=============
31
32Required Properties:
33phys : the phandle for the PHY device (used by the PHY subsystem)
34phy-names : the names of the PHY corresponding to the PHYs present in the
35 *phys* phandle
36
37Example 1:
38usb1: usb_otg_ss@xxx {
39 compatible = "xxx";
40 reg = <xxx>;
41 .
42 .
43 phys = <&usb2_phy>, <&usb3_phy>;
44 phy-names = "usb2phy", "usb3phy";
45 .
46 .
47};
48
49This node represents a controller that uses two PHYs, one for usb2 and one for
50usb3.
51
52Example 2:
53usb2: usb_otg_ss@xxx {
54 compatible = "xxx";
55 reg = <xxx>;
56 .
57 .
58 phys = <&phys 1>;
59 phy-names = "usbphy";
60 .
61 .
62};
63
64This node represents a controller that uses one of the PHYs of the PHY provider
65device defined previously. Note that the phy handle has an additional specifier
66"1" to differentiate between the two PHYs.
diff --git a/Documentation/devicetree/bindings/phy/samsung-phy.txt b/Documentation/devicetree/bindings/phy/samsung-phy.txt
new file mode 100644
index 000000000000..c0fccaa1671e
--- /dev/null
+++ b/Documentation/devicetree/bindings/phy/samsung-phy.txt
@@ -0,0 +1,22 @@
1Samsung S5P/EXYNOS SoC series MIPI CSIS/DSIM DPHY
2-------------------------------------------------
3
4Required properties:
5- compatible : should be "samsung,s5pv210-mipi-video-phy";
6- reg : offset and length of the MIPI DPHY register set;
7- #phy-cells : from the generic phy bindings, must be 1;
8
9For "samsung,s5pv210-mipi-video-phy" compatible PHYs the second cell in
10the PHY specifier identifies the PHY and its meaning is as follows:
11 0 - MIPI CSIS 0,
12 1 - MIPI DSIM 0,
13 2 - MIPI CSIS 1,
14 3 - MIPI DSIM 1.
15
16Samsung EXYNOS SoC series Display Port PHY
17-------------------------------------------------
18
19Required properties:
20- compatible : should be "samsung,exynos5250-dp-video-phy";
21- reg : offset and length of the Display Port PHY register set;
22- #phy-cells : from the generic PHY bindings, must be 0;
diff --git a/Documentation/devicetree/bindings/usb/msm-hsusb.txt b/Documentation/devicetree/bindings/usb/msm-hsusb.txt
new file mode 100644
index 000000000000..5ea26c631e3a
--- /dev/null
+++ b/Documentation/devicetree/bindings/usb/msm-hsusb.txt
@@ -0,0 +1,17 @@
1MSM SoC HSUSB controllers
2
3EHCI
4
5Required properties:
6- compatible: Should contain "qcom,ehci-host"
7- regs: offset and length of the register set in the memory map
8- usb-phy: phandle for the PHY device
9
10Example EHCI controller device node:
11
12 ehci: ehci@f9a55000 {
13 compatible = "qcom,ehci-host";
14 reg = <0xf9a55000 0x400>;
15 usb-phy = <&usb_otg>;
16 };
17
diff --git a/Documentation/devicetree/bindings/usb/omap-usb.txt b/Documentation/devicetree/bindings/usb/omap-usb.txt
index 9088ab09e200..090e5e22bd2b 100644
--- a/Documentation/devicetree/bindings/usb/omap-usb.txt
+++ b/Documentation/devicetree/bindings/usb/omap-usb.txt
@@ -3,9 +3,6 @@ OMAP GLUE AND OTHER OMAP SPECIFIC COMPONENTS
3OMAP MUSB GLUE 3OMAP MUSB GLUE
4 - compatible : Should be "ti,omap4-musb" or "ti,omap3-musb" 4 - compatible : Should be "ti,omap4-musb" or "ti,omap3-musb"
5 - ti,hwmods : must be "usb_otg_hs" 5 - ti,hwmods : must be "usb_otg_hs"
6 - ti,has-mailbox : to specify that omap uses an external mailbox
7 (in control module) to communicate with the musb core during device connect
8 and disconnect.
9 - multipoint : Should be "1" indicating the musb controller supports 6 - multipoint : Should be "1" indicating the musb controller supports
10 multipoint. This is a MUSB configuration-specific setting. 7 multipoint. This is a MUSB configuration-specific setting.
11 - num-eps : Specifies the number of endpoints. This is also a 8 - num-eps : Specifies the number of endpoints. This is also a
@@ -19,6 +16,9 @@ OMAP MUSB GLUE
19 - power : Should be "50". This signifies the controller can supply up to 16 - power : Should be "50". This signifies the controller can supply up to
20 100mA when operating in host mode. 17 100mA when operating in host mode.
21 - usb-phy : the phandle for the PHY device 18 - usb-phy : the phandle for the PHY device
19 - phys : the phandle for the PHY device (used by generic PHY framework)
20 - phy-names : the names of the PHY corresponding to the PHYs present in the
21 *phy* phandle.
22 22
23Optional properties: 23Optional properties:
24 - ctrl-module : phandle of the control module this glue uses to write to 24 - ctrl-module : phandle of the control module this glue uses to write to
@@ -28,11 +28,12 @@ SOC specific device node entry
28usb_otg_hs: usb_otg_hs@4a0ab000 { 28usb_otg_hs: usb_otg_hs@4a0ab000 {
29 compatible = "ti,omap4-musb"; 29 compatible = "ti,omap4-musb";
30 ti,hwmods = "usb_otg_hs"; 30 ti,hwmods = "usb_otg_hs";
31 ti,has-mailbox;
32 multipoint = <1>; 31 multipoint = <1>;
33 num-eps = <16>; 32 num-eps = <16>;
34 ram-bits = <12>; 33 ram-bits = <12>;
35 ctrl-module = <&omap_control_usb>; 34 ctrl-module = <&omap_control_usb>;
35 phys = <&usb2_phy>;
36 phy-names = "usb2-phy";
36}; 37};
37 38
38Board specific device node entry 39Board specific device node entry
@@ -78,22 +79,22 @@ omap_dwc3 {
78OMAP CONTROL USB 79OMAP CONTROL USB
79 80
80Required properties: 81Required properties:
81 - compatible: Should be "ti,omap-control-usb" 82 - compatible: Should be one of
83 "ti,control-phy-otghs" - if it has otghs_control mailbox register as on OMAP4.
84 "ti,control-phy-usb2" - if it has Power down bit in control_dev_conf register
85 e.g. USB2_PHY on OMAP5.
86 "ti,control-phy-pipe3" - if it has DPLL and individual Rx & Tx power control
87 e.g. USB3 PHY and SATA PHY on OMAP5.
88 "ti,control-phy-dra7usb2" - if it has power down register like USB2 PHY on
89 DRA7 platform.
82 - reg : Address and length of the register set for the device. It contains 90 - reg : Address and length of the register set for the device. It contains
83 the address of "control_dev_conf" and "otghs_control" or "phy_power_usb" 91 the address of "otghs_control" for control-phy-otghs or "power" register
84 depending upon omap4 or omap5. 92 for other types.
85 - reg-names: The names of the register addresses corresponding to the registers 93 - reg-names: should be "otghs_control" control-phy-otghs and "power" for
86 filled in "reg". 94 other types.
87 - ti,type: This is used to differentiate whether the control module has
88 usb mailbox or usb3 phy power. omap4 has usb mailbox in control module to
89 notify events to the musb core and omap5 has usb3 phy power register to
90 power on usb3 phy. Should be "1" if it has mailbox and "2" if it has usb3
91 phy power.
92 95
93omap_control_usb: omap-control-usb@4a002300 { 96omap_control_usb: omap-control-usb@4a002300 {
94 compatible = "ti,omap-control-usb"; 97 compatible = "ti,control-phy-otghs";
95 reg = <0x4a002300 0x4>, 98 reg = <0x4a00233c 0x4>;
96 <0x4a00233c 0x4>; 99 reg-names = "otghs_control";
97 reg-names = "control_dev_conf", "otghs_control";
98 ti,type = <1>;
99}; 100};
diff --git a/Documentation/devicetree/bindings/usb/usb-nop-xceiv.txt b/Documentation/devicetree/bindings/usb/usb-nop-xceiv.txt
index d7e272671c7e..1bd37faba05b 100644
--- a/Documentation/devicetree/bindings/usb/usb-nop-xceiv.txt
+++ b/Documentation/devicetree/bindings/usb/usb-nop-xceiv.txt
@@ -15,7 +15,7 @@ Optional properties:
15 15
16- vcc-supply: phandle to the regulator that provides RESET to the PHY. 16- vcc-supply: phandle to the regulator that provides RESET to the PHY.
17 17
18- reset-supply: phandle to the regulator that provides power to the PHY. 18- reset-gpios: Should specify the GPIO for reset.
19 19
20Example: 20Example:
21 21
@@ -25,10 +25,9 @@ Example:
25 clocks = <&osc 0>; 25 clocks = <&osc 0>;
26 clock-names = "main_clk"; 26 clock-names = "main_clk";
27 vcc-supply = <&hsusb1_vcc_regulator>; 27 vcc-supply = <&hsusb1_vcc_regulator>;
28 reset-supply = <&hsusb1_reset_regulator>; 28 reset-gpios = <&gpio1 7 GPIO_ACTIVE_LOW>;
29 }; 29 };
30 30
31hsusb1_phy is a NOP USB PHY device that gets its clock from an oscillator 31hsusb1_phy is a NOP USB PHY device that gets its clock from an oscillator
32and expects that clock to be configured to 19.2MHz by the NOP PHY driver. 32and expects that clock to be configured to 19.2MHz by the NOP PHY driver.
33hsusb1_vcc_regulator provides power to the PHY and hsusb1_reset_regulator 33hsusb1_vcc_regulator provides power to the PHY and GPIO 7 controls RESET.
34controls RESET.
diff --git a/Documentation/devicetree/bindings/usb/usb-phy.txt b/Documentation/devicetree/bindings/usb/usb-phy.txt
index 61496f5cb095..c0245c888982 100644
--- a/Documentation/devicetree/bindings/usb/usb-phy.txt
+++ b/Documentation/devicetree/bindings/usb/usb-phy.txt
@@ -5,6 +5,8 @@ OMAP USB2 PHY
5Required properties: 5Required properties:
6 - compatible: Should be "ti,omap-usb2" 6 - compatible: Should be "ti,omap-usb2"
7 - reg : Address and length of the register set for the device. 7 - reg : Address and length of the register set for the device.
8 - #phy-cells: determine the number of cells that should be given in the
9 phandle while referencing this phy.
8 10
9Optional properties: 11Optional properties:
10 - ctrl-module : phandle of the control module used by PHY driver to power on 12 - ctrl-module : phandle of the control module used by PHY driver to power on
@@ -16,6 +18,7 @@ usb2phy@4a0ad080 {
16 compatible = "ti,omap-usb2"; 18 compatible = "ti,omap-usb2";
17 reg = <0x4a0ad080 0x58>; 19 reg = <0x4a0ad080 0x58>;
18 ctrl-module = <&omap_control_usb>; 20 ctrl-module = <&omap_control_usb>;
21 #phy-cells = <0>;
19}; 22};
20 23
21OMAP USB3 PHY 24OMAP USB3 PHY
@@ -25,6 +28,8 @@ Required properties:
25 - reg : Address and length of the register set for the device. 28 - reg : Address and length of the register set for the device.
26 - reg-names: The names of the register addresses corresponding to the registers 29 - reg-names: The names of the register addresses corresponding to the registers
27 filled in "reg". 30 filled in "reg".
31 - #phy-cells: determine the number of cells that should be given in the
32 phandle while referencing this phy.
28 33
29Optional properties: 34Optional properties:
30 - ctrl-module : phandle of the control module used by PHY driver to power on 35 - ctrl-module : phandle of the control module used by PHY driver to power on
@@ -39,4 +44,5 @@ usb3phy@4a084400 {
39 <0x4a084c00 0x40>; 44 <0x4a084c00 0x40>;
40 reg-names = "phy_rx", "phy_tx", "pll_ctrl"; 45 reg-names = "phy_rx", "phy_tx", "pll_ctrl";
41 ctrl-module = <&omap_control_usb>; 46 ctrl-module = <&omap_control_usb>;
47 #phy-cells = <0>;
42}; 48};
diff --git a/Documentation/devicetree/bindings/video/exynos_dp.txt b/Documentation/devicetree/bindings/video/exynos_dp.txt
index 84f10c16cb38..3289d76a21d0 100644
--- a/Documentation/devicetree/bindings/video/exynos_dp.txt
+++ b/Documentation/devicetree/bindings/video/exynos_dp.txt
@@ -6,10 +6,10 @@ We use two nodes:
6 -dptx-phy node(defined inside dp-controller node) 6 -dptx-phy node(defined inside dp-controller node)
7 7
8For the DP-PHY initialization, we use the dptx-phy node. 8For the DP-PHY initialization, we use the dptx-phy node.
9Required properties for dptx-phy: 9Required properties for dptx-phy: deprecated, use phys and phy-names
10 -reg: 10 -reg: deprecated
11 Base address of DP PHY register. 11 Base address of DP PHY register.
12 -samsung,enable-mask: 12 -samsung,enable-mask: deprecated
13 The bit-mask used to enable/disable DP PHY. 13 The bit-mask used to enable/disable DP PHY.
14 14
15For the Panel initialization, we read data from dp-controller node. 15For the Panel initialization, we read data from dp-controller node.
@@ -27,6 +27,10 @@ Required properties for dp-controller:
27 from common clock binding: Shall be "dp". 27 from common clock binding: Shall be "dp".
28 -interrupt-parent: 28 -interrupt-parent:
29 phandle to Interrupt combiner node. 29 phandle to Interrupt combiner node.
30 -phys:
31 from general PHY binding: the phandle for the PHY device.
32 -phy-names:
33 from general PHY binding: Should be "dp".
30 -samsung,color-space: 34 -samsung,color-space:
31 input video data format. 35 input video data format.
32 COLOR_RGB = 0, COLOR_YCBCR422 = 1, COLOR_YCBCR444 = 2 36 COLOR_RGB = 0, COLOR_YCBCR422 = 1, COLOR_YCBCR444 = 2
@@ -68,11 +72,8 @@ SOC specific portion:
68 clocks = <&clock 342>; 72 clocks = <&clock 342>;
69 clock-names = "dp"; 73 clock-names = "dp";
70 74
71 dptx-phy { 75 phys = <&dp_phy>;
72 reg = <0x10040720>; 76 phy-names = "dp";
73 samsung,enable-mask = <1>;
74 };
75
76 }; 77 };
77 78
78Board Specific portion: 79Board Specific portion:
diff --git a/Documentation/networking/dccp.txt b/Documentation/networking/dccp.txt
index d718bc2ff1cf..bf5dbe3ab8c5 100644
--- a/Documentation/networking/dccp.txt
+++ b/Documentation/networking/dccp.txt
@@ -18,8 +18,8 @@ Introduction
18Datagram Congestion Control Protocol (DCCP) is an unreliable, connection 18Datagram Congestion Control Protocol (DCCP) is an unreliable, connection
19oriented protocol designed to solve issues present in UDP and TCP, particularly 19oriented protocol designed to solve issues present in UDP and TCP, particularly
20for real-time and multimedia (streaming) traffic. 20for real-time and multimedia (streaming) traffic.
21It divides into a base protocol (RFC 4340) and plugable congestion control 21It divides into a base protocol (RFC 4340) and pluggable congestion control
22modules called CCIDs. Like plugable TCP congestion control, at least one CCID 22modules called CCIDs. Like pluggable TCP congestion control, at least one CCID
23needs to be enabled in order for the protocol to function properly. In the Linux 23needs to be enabled in order for the protocol to function properly. In the Linux
24implementation, this is the TCP-like CCID2 (RFC 4341). Additional CCIDs, such as 24implementation, this is the TCP-like CCID2 (RFC 4341). Additional CCIDs, such as
25the TCP-friendly CCID3 (RFC 4342), are optional. 25the TCP-friendly CCID3 (RFC 4342), are optional.
diff --git a/Documentation/networking/e100.txt b/Documentation/networking/e100.txt
index 13a32124bca0..f862cf3aff34 100644
--- a/Documentation/networking/e100.txt
+++ b/Documentation/networking/e100.txt
@@ -103,7 +103,7 @@ Additional Configurations
103 PRO/100 Family of Adapters is e100. 103 PRO/100 Family of Adapters is e100.
104 104
105 As an example, if you install the e100 driver for two PRO/100 adapters 105 As an example, if you install the e100 driver for two PRO/100 adapters
106 (eth0 and eth1), add the following to a configuraton file in /etc/modprobe.d/ 106 (eth0 and eth1), add the following to a configuration file in /etc/modprobe.d/
107 107
108 alias eth0 e100 108 alias eth0 e100
109 alias eth1 e100 109 alias eth1 e100
diff --git a/Documentation/networking/ieee802154.txt b/Documentation/networking/ieee802154.txt
index 09eb57329f11..22bbc7225f8e 100644
--- a/Documentation/networking/ieee802154.txt
+++ b/Documentation/networking/ieee802154.txt
@@ -4,7 +4,7 @@
4 4
5Introduction 5Introduction
6============ 6============
7The IEEE 802.15.4 working group focuses on standartization of bottom 7The IEEE 802.15.4 working group focuses on standardization of bottom
8two layers: Medium Access Control (MAC) and Physical (PHY). And there 8two layers: Medium Access Control (MAC) and Physical (PHY). And there
9are mainly two options available for upper layers: 9are mainly two options available for upper layers:
10 - ZigBee - proprietary protocol from ZigBee Alliance 10 - ZigBee - proprietary protocol from ZigBee Alliance
@@ -66,7 +66,7 @@ net_device, with .type = ARPHRD_IEEE802154. Data is exchanged with socket family
66code via plain sk_buffs. On skb reception skb->cb must contain additional 66code via plain sk_buffs. On skb reception skb->cb must contain additional
67info as described in the struct ieee802154_mac_cb. During packet transmission 67info as described in the struct ieee802154_mac_cb. During packet transmission
68the skb->cb is used to provide additional data to device's header_ops->create 68the skb->cb is used to provide additional data to device's header_ops->create
69function. Be aware, that this data can be overriden later (when socket code 69function. Be aware that this data can be overridden later (when socket code
70submits skb to qdisc), so if you need something from that cb later, you should 70submits skb to qdisc), so if you need something from that cb later, you should
71store info in the skb->data on your own. 71store info in the skb->data on your own.
72 72
diff --git a/Documentation/networking/l2tp.txt b/Documentation/networking/l2tp.txt
index e63fc1f7bf87..c74434de2fa5 100644
--- a/Documentation/networking/l2tp.txt
+++ b/Documentation/networking/l2tp.txt
@@ -197,7 +197,7 @@ state information because the file format is subject to change. It is
197implemented to provide extra debug information to help diagnose 197implemented to provide extra debug information to help diagnose
198problems.) Users should use the netlink API. 198problems.) Users should use the netlink API.
199 199
200/proc/net/pppol2tp is also provided for backwards compaibility with 200/proc/net/pppol2tp is also provided for backwards compatibility with
201the original pppol2tp driver. It lists information about L2TPv2 201the original pppol2tp driver. It lists information about L2TPv2
202tunnels and sessions only. Its use is discouraged. 202tunnels and sessions only. Its use is discouraged.
203 203
diff --git a/Documentation/networking/netdev-FAQ.txt b/Documentation/networking/netdev-FAQ.txt
index d9112f01c44a..0fe1c6e0dbcd 100644
--- a/Documentation/networking/netdev-FAQ.txt
+++ b/Documentation/networking/netdev-FAQ.txt
@@ -4,23 +4,23 @@ Information you need to know about netdev
4 4
5Q: What is netdev? 5Q: What is netdev?
6 6
7A: It is a mailing list for all network related linux stuff. This includes 7A: It is a mailing list for all network-related Linux stuff. This includes
8 anything found under net/ (i.e. core code like IPv6) and drivers/net 8 anything found under net/ (i.e. core code like IPv6) and drivers/net
9 (i.e. hardware specific drivers) in the linux source tree. 9 (i.e. hardware specific drivers) in the Linux source tree.
10 10
11 Note that some subsystems (e.g. wireless drivers) which have a high volume 11 Note that some subsystems (e.g. wireless drivers) which have a high volume
12 of traffic have their own specific mailing lists. 12 of traffic have their own specific mailing lists.
13 13
14 The netdev list is managed (like many other linux mailing lists) through 14 The netdev list is managed (like many other Linux mailing lists) through
15 VGER ( http://vger.kernel.org/ ) and archives can be found below: 15 VGER ( http://vger.kernel.org/ ) and archives can be found below:
16 16
17 http://marc.info/?l=linux-netdev 17 http://marc.info/?l=linux-netdev
18 http://www.spinics.net/lists/netdev/ 18 http://www.spinics.net/lists/netdev/
19 19
20 Aside from subsystems like that mentioned above, all network related linux 20 Aside from subsystems like that mentioned above, all network-related Linux
21 development (i.e. RFC, review, comments, etc) takes place on netdev. 21 development (i.e. RFC, review, comments, etc.) takes place on netdev.
22 22
23Q: How do the changes posted to netdev make their way into linux? 23Q: How do the changes posted to netdev make their way into Linux?
24 24
25A: There are always two trees (git repositories) in play. Both are driven 25A: There are always two trees (git repositories) in play. Both are driven
26 by David Miller, the main network maintainer. There is the "net" tree, 26 by David Miller, the main network maintainer. There is the "net" tree,
@@ -35,7 +35,7 @@ A: There are always two trees (git repositories) in play. Both are driven
35Q: How often do changes from these trees make it to the mainline Linus tree? 35Q: How often do changes from these trees make it to the mainline Linus tree?
36 36
37A: To understand this, you need to know a bit of background information 37A: To understand this, you need to know a bit of background information
38 on the cadence of linux development. Each new release starts off with 38 on the cadence of Linux development. Each new release starts off with
39 a two week "merge window" where the main maintainers feed their new 39 a two week "merge window" where the main maintainers feed their new
40 stuff to Linus for merging into the mainline tree. After the two weeks, 40 stuff to Linus for merging into the mainline tree. After the two weeks,
41 the merge window is closed, and it is called/tagged "-rc1". No new 41 the merge window is closed, and it is called/tagged "-rc1". No new
@@ -46,7 +46,7 @@ A: To understand this, you need to know a bit of background information
46 things are in a state of churn), and a week after the last vX.Y-rcN 46 things are in a state of churn), and a week after the last vX.Y-rcN
47 was done, the official "vX.Y" is released. 47 was done, the official "vX.Y" is released.
48 48
49 Relating that to netdev: At the beginning of the 2 week merge window, 49 Relating that to netdev: At the beginning of the 2-week merge window,
50 the net-next tree will be closed - no new changes/features. The 50 the net-next tree will be closed - no new changes/features. The
51 accumulated new content of the past ~10 weeks will be passed onto 51 accumulated new content of the past ~10 weeks will be passed onto
52 mainline/Linus via a pull request for vX.Y -- at the same time, 52 mainline/Linus via a pull request for vX.Y -- at the same time,
@@ -59,16 +59,16 @@ A: To understand this, you need to know a bit of background information
59 IMPORTANT: Do not send new net-next content to netdev during the 59 IMPORTANT: Do not send new net-next content to netdev during the
60 period during which net-next tree is closed. 60 period during which net-next tree is closed.
61 61
62 Shortly after the two weeks have passed, (and vX.Y-rc1 is released) the 62 Shortly after the two weeks have passed (and vX.Y-rc1 is released), the
63 tree for net-next reopens to collect content for the next (vX.Y+1) release. 63 tree for net-next reopens to collect content for the next (vX.Y+1) release.
64 64
65 If you aren't subscribed to netdev and/or are simply unsure if net-next 65 If you aren't subscribed to netdev and/or are simply unsure if net-next
66 has re-opened yet, simply check the net-next git repository link above for 66 has re-opened yet, simply check the net-next git repository link above for
67 any new networking related commits. 67 any new networking-related commits.
68 68
69 The "net" tree continues to collect fixes for the vX.Y content, and 69 The "net" tree continues to collect fixes for the vX.Y content, and
70 is fed back to Linus at regular (~weekly) intervals. Meaning that the 70 is fed back to Linus at regular (~weekly) intervals. Meaning that the
71 focus for "net" is on stablilization and bugfixes. 71 focus for "net" is on stabilization and bugfixes.
72 72
73 Finally, the vX.Y gets released, and the whole cycle starts over. 73 Finally, the vX.Y gets released, and the whole cycle starts over.
74 74
@@ -217,7 +217,7 @@ A: Attention to detail. Re-read your own work as if you were the
217 to why it happens, and then if necessary, explain why the fix proposed 217 to why it happens, and then if necessary, explain why the fix proposed
218 is the best way to get things done. Don't mangle whitespace, and as 218 is the best way to get things done. Don't mangle whitespace, and as
219 is common, don't mis-indent function arguments that span multiple lines. 219 is common, don't mis-indent function arguments that span multiple lines.
220 If it is your 1st patch, mail it to yourself so you can test apply 220 If it is your first patch, mail it to yourself so you can test apply
221 it to an unpatched tree to confirm infrastructure didn't mangle it. 221 it to an unpatched tree to confirm infrastructure didn't mangle it.
222 222
223 Finally, go back and read Documentation/SubmittingPatches to be 223 Finally, go back and read Documentation/SubmittingPatches to be
diff --git a/Documentation/networking/netlink_mmap.txt b/Documentation/networking/netlink_mmap.txt
index 533378839546..b26122973525 100644
--- a/Documentation/networking/netlink_mmap.txt
+++ b/Documentation/networking/netlink_mmap.txt
@@ -45,7 +45,7 @@ processing.
45 45
46Conversion of the reception path involves calling poll() on the file 46Conversion of the reception path involves calling poll() on the file
47descriptor, once the socket is readable the frames from the ring are 47descriptor, once the socket is readable the frames from the ring are
48processsed in order until no more messages are available, as indicated by 48processed in order until no more messages are available, as indicated by
49a status word in the frame header. 49a status word in the frame header.
50 50
51On kernel side, in order to make use of memory mapped I/O on receive, the 51On kernel side, in order to make use of memory mapped I/O on receive, the
@@ -56,7 +56,7 @@ Dumps of kernel databases automatically support memory mapped I/O.
56 56
57Conversion of the transmit path involves changing message construction to 57Conversion of the transmit path involves changing message construction to
58use memory from the TX ring instead of (usually) a buffer declared on the 58use memory from the TX ring instead of (usually) a buffer declared on the
59stack and setting up the frame header approriately. Optionally poll() can 59stack and setting up the frame header appropriately. Optionally poll() can
60be used to wait for free frames in the TX ring. 60be used to wait for free frames in the TX ring.
61 61
62Structured and definitions for using memory mapped I/O are contained in 62Structured and definitions for using memory mapped I/O are contained in
@@ -231,7 +231,7 @@ Ring setup:
231 if (setsockopt(fd, NETLINK_TX_RING, &req, sizeof(req)) < 0) 231 if (setsockopt(fd, NETLINK_TX_RING, &req, sizeof(req)) < 0)
232 exit(1) 232 exit(1)
233 233
234 /* Calculate size of each invididual ring */ 234 /* Calculate size of each individual ring */
235 ring_size = req.nm_block_nr * req.nm_block_size; 235 ring_size = req.nm_block_nr * req.nm_block_size;
236 236
237 /* Map RX/TX rings. The TX ring is located after the RX ring */ 237 /* Map RX/TX rings. The TX ring is located after the RX ring */
diff --git a/Documentation/networking/operstates.txt b/Documentation/networking/operstates.txt
index 97694572338b..355c6d8ef8ad 100644
--- a/Documentation/networking/operstates.txt
+++ b/Documentation/networking/operstates.txt
@@ -89,8 +89,8 @@ packets. The name 'carrier' and the inversion are historical, think of
89it as lower layer. 89it as lower layer.
90 90
91Note that for certain kind of soft-devices, which are not managing any 91Note that for certain kind of soft-devices, which are not managing any
92real hardware, there is possible to set this bit from userpsace. 92real hardware, it is possible to set this bit from userspace. One
93One should use TVL IFLA_CARRIER to do so. 93should use TVL IFLA_CARRIER to do so.
94 94
95netif_carrier_ok() can be used to query that bit. 95netif_carrier_ok() can be used to query that bit.
96 96
diff --git a/Documentation/networking/rxrpc.txt b/Documentation/networking/rxrpc.txt
index 60d05eb77c64..b89bc82eed46 100644
--- a/Documentation/networking/rxrpc.txt
+++ b/Documentation/networking/rxrpc.txt
@@ -144,7 +144,7 @@ An overview of the RxRPC protocol:
144 (*) Calls use ACK packets to handle reliability. Data packets are also 144 (*) Calls use ACK packets to handle reliability. Data packets are also
145 explicitly sequenced per call. 145 explicitly sequenced per call.
146 146
147 (*) There are two types of positive acknowledgement: hard-ACKs and soft-ACKs. 147 (*) There are two types of positive acknowledgment: hard-ACKs and soft-ACKs.
148 A hard-ACK indicates to the far side that all the data received to a point 148 A hard-ACK indicates to the far side that all the data received to a point
149 has been received and processed; a soft-ACK indicates that the data has 149 has been received and processed; a soft-ACK indicates that the data has
150 been received but may yet be discarded and re-requested. The sender may 150 been received but may yet be discarded and re-requested. The sender may
diff --git a/Documentation/networking/stmmac.txt b/Documentation/networking/stmmac.txt
index 457b8bbafb08..cdd916da838d 100644
--- a/Documentation/networking/stmmac.txt
+++ b/Documentation/networking/stmmac.txt
@@ -160,7 +160,7 @@ Where:
160 o pmt: core has the embedded power module (optional). 160 o pmt: core has the embedded power module (optional).
161 o force_sf_dma_mode: force DMA to use the Store and Forward mode 161 o force_sf_dma_mode: force DMA to use the Store and Forward mode
162 instead of the Threshold. 162 instead of the Threshold.
163 o force_thresh_dma_mode: force DMA to use the Shreshold mode other than 163 o force_thresh_dma_mode: force DMA to use the Threshold mode other than
164 the Store and Forward mode. 164 the Store and Forward mode.
165 o riwt_off: force to disable the RX watchdog feature and switch to NAPI mode. 165 o riwt_off: force to disable the RX watchdog feature and switch to NAPI mode.
166 o fix_mac_speed: this callback is used for modifying some syscfg registers 166 o fix_mac_speed: this callback is used for modifying some syscfg registers
@@ -175,7 +175,7 @@ Where:
175 registers. 175 registers.
176 o custom_cfg/custom_data: this is a custom configuration that can be passed 176 o custom_cfg/custom_data: this is a custom configuration that can be passed
177 while initializing the resources. 177 while initializing the resources.
178 o bsp_priv: another private poiter. 178 o bsp_priv: another private pointer.
179 179
180For MDIO bus The we have: 180For MDIO bus The we have:
181 181
@@ -271,7 +271,7 @@ reset procedure etc).
271 o dwmac1000_dma.c: dma functions for the GMAC chip; 271 o dwmac1000_dma.c: dma functions for the GMAC chip;
272 o dwmac1000.h: specific header file for the GMAC; 272 o dwmac1000.h: specific header file for the GMAC;
273 o dwmac100_core: MAC 100 core and dma code; 273 o dwmac100_core: MAC 100 core and dma code;
274 o dwmac100_dma.c: dma funtions for the MAC chip; 274 o dwmac100_dma.c: dma functions for the MAC chip;
275 o dwmac1000.h: specific header file for the MAC; 275 o dwmac1000.h: specific header file for the MAC;
276 o dwmac_lib.c: generic DMA functions shared among chips; 276 o dwmac_lib.c: generic DMA functions shared among chips;
277 o enh_desc.c: functions for handling enhanced descriptors; 277 o enh_desc.c: functions for handling enhanced descriptors;
@@ -364,4 +364,4 @@ Auto-negotiated Link Parter Ability.
36410) TODO: 36410) TODO:
365 o XGMAC is not supported. 365 o XGMAC is not supported.
366 o Complete the TBI & RTBI support. 366 o Complete the TBI & RTBI support.
367 o extened VLAN support for 3.70a SYNP GMAC. 367 o extend VLAN support for 3.70a SYNP GMAC.
diff --git a/Documentation/networking/vortex.txt b/Documentation/networking/vortex.txt
index 9a8041dcbb53..97282da82b75 100644
--- a/Documentation/networking/vortex.txt
+++ b/Documentation/networking/vortex.txt
@@ -68,7 +68,7 @@ Module parameters
68 68
69There are several parameters which may be provided to the driver when 69There are several parameters which may be provided to the driver when
70its module is loaded. These are usually placed in /etc/modprobe.d/*.conf 70its module is loaded. These are usually placed in /etc/modprobe.d/*.conf
71configuretion files. Example: 71configuration files. Example:
72 72
73options 3c59x debug=3 rx_copybreak=300 73options 3c59x debug=3 rx_copybreak=300
74 74
@@ -178,7 +178,7 @@ max_interrupt_work=N
178 178
179 The driver's interrupt service routine can handle many receive and 179 The driver's interrupt service routine can handle many receive and
180 transmit packets in a single invocation. It does this in a loop. 180 transmit packets in a single invocation. It does this in a loop.
181 The value of max_interrupt_work governs how mnay times the interrupt 181 The value of max_interrupt_work governs how many times the interrupt
182 service routine will loop. The default value is 32 loops. If this 182 service routine will loop. The default value is 32 loops. If this
183 is exceeded the interrupt service routine gives up and generates a 183 is exceeded the interrupt service routine gives up and generates a
184 warning message "eth0: Too much work in interrupt". 184 warning message "eth0: Too much work in interrupt".
diff --git a/Documentation/networking/x25-iface.txt b/Documentation/networking/x25-iface.txt
index 78f662ee0622..7f213b556e85 100644
--- a/Documentation/networking/x25-iface.txt
+++ b/Documentation/networking/x25-iface.txt
@@ -105,7 +105,7 @@ reduced by the following measures or a combination thereof:
105 later. 105 later.
106 The lapb module interface was modified to support this. Its 106 The lapb module interface was modified to support this. Its
107 data_indication() method should now transparently pass the 107 data_indication() method should now transparently pass the
108 netif_rx() return value to the (lapb mopdule) caller. 108 netif_rx() return value to the (lapb module) caller.
109(2) Drivers for kernel versions 2.2.x should always check the global 109(2) Drivers for kernel versions 2.2.x should always check the global
110 variable netdev_dropping when a new frame is received. The driver 110 variable netdev_dropping when a new frame is received. The driver
111 should only call netif_rx() if netdev_dropping is zero. Otherwise 111 should only call netif_rx() if netdev_dropping is zero. Otherwise
diff --git a/Documentation/phy.txt b/Documentation/phy.txt
new file mode 100644
index 000000000000..0103e4b15b0e
--- /dev/null
+++ b/Documentation/phy.txt
@@ -0,0 +1,166 @@
1 PHY SUBSYSTEM
2 Kishon Vijay Abraham I <kishon@ti.com>
3
4This document explains the Generic PHY Framework along with the APIs provided,
5and how-to-use.
6
71. Introduction
8
9*PHY* is the abbreviation for physical layer. It is used to connect a device
10to the physical medium e.g., the USB controller has a PHY to provide functions
11such as serialization, de-serialization, encoding, decoding and is responsible
12for obtaining the required data transmission rate. Note that some USB
13controllers have PHY functionality embedded into it and others use an external
14PHY. Other peripherals that use PHY include Wireless LAN, Ethernet,
15SATA etc.
16
17The intention of creating this framework is to bring the PHY drivers spread
18all over the Linux kernel to drivers/phy to increase code re-use and for
19better code maintainability.
20
21This framework will be of use only to devices that use external PHY (PHY
22functionality is not embedded within the controller).
23
242. Registering/Unregistering the PHY provider
25
26PHY provider refers to an entity that implements one or more PHY instances.
27For the simple case where the PHY provider implements only a single instance of
28the PHY, the framework provides its own implementation of of_xlate in
29of_phy_simple_xlate. If the PHY provider implements multiple instances, it
30should provide its own implementation of of_xlate. of_xlate is used only for
31dt boot case.
32
33#define of_phy_provider_register(dev, xlate) \
34 __of_phy_provider_register((dev), THIS_MODULE, (xlate))
35
36#define devm_of_phy_provider_register(dev, xlate) \
37 __devm_of_phy_provider_register((dev), THIS_MODULE, (xlate))
38
39of_phy_provider_register and devm_of_phy_provider_register macros can be used to
40register the phy_provider and it takes device and of_xlate as
41arguments. For the dt boot case, all PHY providers should use one of the above
422 macros to register the PHY provider.
43
44void devm_of_phy_provider_unregister(struct device *dev,
45 struct phy_provider *phy_provider);
46void of_phy_provider_unregister(struct phy_provider *phy_provider);
47
48devm_of_phy_provider_unregister and of_phy_provider_unregister can be used to
49unregister the PHY.
50
513. Creating the PHY
52
53The PHY driver should create the PHY in order for other peripheral controllers
54to make use of it. The PHY framework provides 2 APIs to create the PHY.
55
56struct phy *phy_create(struct device *dev, const struct phy_ops *ops,
57 struct phy_init_data *init_data);
58struct phy *devm_phy_create(struct device *dev, const struct phy_ops *ops,
59 struct phy_init_data *init_data);
60
61The PHY drivers can use one of the above 2 APIs to create the PHY by passing
62the device pointer, phy ops and init_data.
63phy_ops is a set of function pointers for performing PHY operations such as
64init, exit, power_on and power_off. *init_data* is mandatory to get a reference
65to the PHY in the case of non-dt boot. See section *Board File Initialization*
66on how init_data should be used.
67
68Inorder to dereference the private data (in phy_ops), the phy provider driver
69can use phy_set_drvdata() after creating the PHY and use phy_get_drvdata() in
70phy_ops to get back the private data.
71
724. Getting a reference to the PHY
73
74Before the controller can make use of the PHY, it has to get a reference to
75it. This framework provides the following APIs to get a reference to the PHY.
76
77struct phy *phy_get(struct device *dev, const char *string);
78struct phy *devm_phy_get(struct device *dev, const char *string);
79
80phy_get and devm_phy_get can be used to get the PHY. In the case of dt boot,
81the string arguments should contain the phy name as given in the dt data and
82in the case of non-dt boot, it should contain the label of the PHY.
83The only difference between the two APIs is that devm_phy_get associates the
84device with the PHY using devres on successful PHY get. On driver detach,
85release function is invoked on the the devres data and devres data is freed.
86
875. Releasing a reference to the PHY
88
89When the controller no longer needs the PHY, it has to release the reference
90to the PHY it has obtained using the APIs mentioned in the above section. The
91PHY framework provides 2 APIs to release a reference to the PHY.
92
93void phy_put(struct phy *phy);
94void devm_phy_put(struct device *dev, struct phy *phy);
95
96Both these APIs are used to release a reference to the PHY and devm_phy_put
97destroys the devres associated with this PHY.
98
996. Destroying the PHY
100
101When the driver that created the PHY is unloaded, it should destroy the PHY it
102created using one of the following 2 APIs.
103
104void phy_destroy(struct phy *phy);
105void devm_phy_destroy(struct device *dev, struct phy *phy);
106
107Both these APIs destroy the PHY and devm_phy_destroy destroys the devres
108associated with this PHY.
109
1107. PM Runtime
111
112This subsystem is pm runtime enabled. So while creating the PHY,
113pm_runtime_enable of the phy device created by this subsystem is called and
114while destroying the PHY, pm_runtime_disable is called. Note that the phy
115device created by this subsystem will be a child of the device that calls
116phy_create (PHY provider device).
117
118So pm_runtime_get_sync of the phy_device created by this subsystem will invoke
119pm_runtime_get_sync of PHY provider device because of parent-child relationship.
120It should also be noted that phy_power_on and phy_power_off performs
121phy_pm_runtime_get_sync and phy_pm_runtime_put respectively.
122There are exported APIs like phy_pm_runtime_get, phy_pm_runtime_get_sync,
123phy_pm_runtime_put, phy_pm_runtime_put_sync, phy_pm_runtime_allow and
124phy_pm_runtime_forbid for performing PM operations.
125
1268. Board File Initialization
127
128Certain board file initialization is necessary in order to get a reference
129to the PHY in the case of non-dt boot.
130Say we have a single device that implements 3 PHYs that of USB, SATA and PCIe,
131then in the board file the following initialization should be done.
132
133struct phy_consumer consumers[] = {
134 PHY_CONSUMER("dwc3.0", "usb"),
135 PHY_CONSUMER("pcie.0", "pcie"),
136 PHY_CONSUMER("sata.0", "sata"),
137};
138PHY_CONSUMER takes 2 parameters, first is the device name of the controller
139(PHY consumer) and second is the port name.
140
141struct phy_init_data init_data = {
142 .consumers = consumers,
143 .num_consumers = ARRAY_SIZE(consumers),
144};
145
146static const struct platform_device pipe3_phy_dev = {
147 .name = "pipe3-phy",
148 .id = -1,
149 .dev = {
150 .platform_data = {
151 .init_data = &init_data,
152 },
153 },
154};
155
156then, while doing phy_create, the PHY driver should pass this init_data
157 phy_create(dev, ops, pdata->init_data);
158
159and the controller driver (phy consumer) should pass the port name along with
160the device to get a reference to the PHY
161 phy_get(dev, "pcie");
162
1639. DeviceTree Binding
164
165The documentation for PHY dt binding can be found @
166Documentation/devicetree/bindings/phy/phy-bindings.txt
diff --git a/Documentation/pps/pps.txt b/Documentation/pps/pps.txt
index d35dcdd82ff6..c03b1be5eb15 100644
--- a/Documentation/pps/pps.txt
+++ b/Documentation/pps/pps.txt
@@ -66,6 +66,21 @@ In LinuxPPS the PPS sources are simply char devices usually mapped
66into files /dev/pps0, /dev/pps1, etc.. 66into files /dev/pps0, /dev/pps1, etc..
67 67
68 68
69PPS with USB to serial devices
70------------------------------
71
72It is possible to grab the PPS from an USB to serial device. However,
73you should take into account the latencies and jitter introduced by
74the USB stack. Users has reported clock instability around +-1ms when
75synchronized with PPS through USB. This isn't suited for time server
76synchronization.
77
78If your device doesn't report PPS, you can check that the feature is
79supported by its driver. Most of the time, you only need to add a call
80to usb_serial_handle_dcd_change after checking the DCD status (see
81ch341 and pl2303 examples).
82
83
69Coding example 84Coding example
70-------------- 85--------------
71 86
diff --git a/MAINTAINERS b/MAINTAINERS
index a7c34ef3509d..64a4ab154af8 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1009,6 +1009,7 @@ ARM/Marvell Armada 370 and Armada XP SOC support
1009M: Jason Cooper <jason@lakedaemon.net> 1009M: Jason Cooper <jason@lakedaemon.net>
1010M: Andrew Lunn <andrew@lunn.ch> 1010M: Andrew Lunn <andrew@lunn.ch>
1011M: Gregory Clement <gregory.clement@free-electrons.com> 1011M: Gregory Clement <gregory.clement@free-electrons.com>
1012M: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
1012L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 1013L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
1013S: Maintained 1014S: Maintained
1014F: arch/arm/mach-mvebu/ 1015F: arch/arm/mach-mvebu/
@@ -1016,6 +1017,7 @@ F: arch/arm/mach-mvebu/
1016ARM/Marvell Dove/Kirkwood/MV78xx0/Orion SOC support 1017ARM/Marvell Dove/Kirkwood/MV78xx0/Orion SOC support
1017M: Jason Cooper <jason@lakedaemon.net> 1018M: Jason Cooper <jason@lakedaemon.net>
1018M: Andrew Lunn <andrew@lunn.ch> 1019M: Andrew Lunn <andrew@lunn.ch>
1020M: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
1019L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 1021L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
1020S: Maintained 1022S: Maintained
1021F: arch/arm/mach-dove/ 1023F: arch/arm/mach-dove/
@@ -1148,6 +1150,13 @@ F: drivers/net/ethernet/i825xx/ether1*
1148F: drivers/net/ethernet/seeq/ether3* 1150F: drivers/net/ethernet/seeq/ether3*
1149F: drivers/scsi/arm/ 1151F: drivers/scsi/arm/
1150 1152
1153ARM/Rockchip SoC support
1154M: Heiko Stuebner <heiko@sntech.de>
1155L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
1156S: Maintained
1157F: arch/arm/mach-rockchip/
1158F: drivers/*/*rockchip*
1159
1151ARM/SHARK MACHINE SUPPORT 1160ARM/SHARK MACHINE SUPPORT
1152M: Alexander Schulz <alex@shark-linux.de> 1161M: Alexander Schulz <alex@shark-linux.de>
1153W: http://www.shark-linux.de/shark.html 1162W: http://www.shark-linux.de/shark.html
@@ -1791,6 +1800,7 @@ F: include/net/bluetooth/
1791 1800
1792BONDING DRIVER 1801BONDING DRIVER
1793M: Jay Vosburgh <fubar@us.ibm.com> 1802M: Jay Vosburgh <fubar@us.ibm.com>
1803M: Veaceslav Falico <vfalico@redhat.com>
1794M: Andy Gospodarek <andy@greyhouse.net> 1804M: Andy Gospodarek <andy@greyhouse.net>
1795L: netdev@vger.kernel.org 1805L: netdev@vger.kernel.org
1796W: http://sourceforge.net/projects/bonding/ 1806W: http://sourceforge.net/projects/bonding/
@@ -2718,6 +2728,8 @@ T: git git://git.linaro.org/people/sumitsemwal/linux-dma-buf.git
2718DMA GENERIC OFFLOAD ENGINE SUBSYSTEM 2728DMA GENERIC OFFLOAD ENGINE SUBSYSTEM
2719M: Vinod Koul <vinod.koul@intel.com> 2729M: Vinod Koul <vinod.koul@intel.com>
2720M: Dan Williams <dan.j.williams@intel.com> 2730M: Dan Williams <dan.j.williams@intel.com>
2731L: dmaengine@vger.kernel.org
2732Q: https://patchwork.kernel.org/project/linux-dmaengine/list/
2721S: Supported 2733S: Supported
2722F: drivers/dma/ 2734F: drivers/dma/
2723F: include/linux/dma* 2735F: include/linux/dma*
@@ -2821,7 +2833,7 @@ M: Terje Bergström <tbergstrom@nvidia.com>
2821L: dri-devel@lists.freedesktop.org 2833L: dri-devel@lists.freedesktop.org
2822L: linux-tegra@vger.kernel.org 2834L: linux-tegra@vger.kernel.org
2823T: git git://anongit.freedesktop.org/tegra/linux.git 2835T: git git://anongit.freedesktop.org/tegra/linux.git
2824S: Maintained 2836S: Supported
2825F: drivers/gpu/host1x/ 2837F: drivers/gpu/host1x/
2826F: include/uapi/drm/tegra_drm.h 2838F: include/uapi/drm/tegra_drm.h
2827F: Documentation/devicetree/bindings/gpu/nvidia,tegra20-host1x.txt 2839F: Documentation/devicetree/bindings/gpu/nvidia,tegra20-host1x.txt
@@ -3679,6 +3691,14 @@ S: Maintained
3679F: include/asm-generic/ 3691F: include/asm-generic/
3680F: include/uapi/asm-generic/ 3692F: include/uapi/asm-generic/
3681 3693
3694GENERIC PHY FRAMEWORK
3695M: Kishon Vijay Abraham I <kishon@ti.com>
3696L: linux-kernel@vger.kernel.org
3697T: git git://git.kernel.org/pub/scm/linux/kernel/git/kishon/linux-phy.git
3698S: Supported
3699F: drivers/phy/
3700F: include/linux/phy/
3701
3682GENERIC UIO DRIVER FOR PCI DEVICES 3702GENERIC UIO DRIVER FOR PCI DEVICES
3683M: "Michael S. Tsirkin" <mst@redhat.com> 3703M: "Michael S. Tsirkin" <mst@redhat.com>
3684L: kvm@vger.kernel.org 3704L: kvm@vger.kernel.org
@@ -4357,7 +4377,10 @@ F: arch/x86/kernel/microcode_intel.c
4357 4377
4358INTEL I/OAT DMA DRIVER 4378INTEL I/OAT DMA DRIVER
4359M: Dan Williams <dan.j.williams@intel.com> 4379M: Dan Williams <dan.j.williams@intel.com>
4360S: Maintained 4380M: Dave Jiang <dave.jiang@intel.com>
4381L: dmaengine@vger.kernel.org
4382Q: https://patchwork.kernel.org/project/linux-dmaengine/list/
4383S: Supported
4361F: drivers/dma/ioat* 4384F: drivers/dma/ioat*
4362 4385
4363INTEL IOMMU (VT-d) 4386INTEL IOMMU (VT-d)
@@ -7822,6 +7845,13 @@ F: Documentation/sound/alsa/soc/
7822F: sound/soc/ 7845F: sound/soc/
7823F: include/sound/soc* 7846F: include/sound/soc*
7824 7847
7848SOUND - DMAENGINE HELPERS
7849M: Lars-Peter Clausen <lars@metafoo.de>
7850S: Supported
7851F: include/sound/dmaengine_pcm.h
7852F: sound/core/pcm_dmaengine.c
7853F: sound/soc/soc-generic-dmaengine-pcm.c
7854
7825SPARC + UltraSPARC (sparc/sparc64) 7855SPARC + UltraSPARC (sparc/sparc64)
7826M: "David S. Miller" <davem@davemloft.net> 7856M: "David S. Miller" <davem@davemloft.net>
7827L: sparclinux@vger.kernel.org 7857L: sparclinux@vger.kernel.org
@@ -8294,14 +8324,72 @@ L: linux-media@vger.kernel.org
8294S: Maintained 8324S: Maintained
8295F: drivers/media/rc/ttusbir.c 8325F: drivers/media/rc/ttusbir.c
8296 8326
8297TEGRA SUPPORT 8327TEGRA ARCHITECTURE SUPPORT
8298M: Stephen Warren <swarren@wwwdotorg.org> 8328M: Stephen Warren <swarren@wwwdotorg.org>
8329M: Thierry Reding <thierry.reding@gmail.com>
8299L: linux-tegra@vger.kernel.org 8330L: linux-tegra@vger.kernel.org
8300Q: http://patchwork.ozlabs.org/project/linux-tegra/list/ 8331Q: http://patchwork.ozlabs.org/project/linux-tegra/list/
8301T: git git://git.kernel.org/pub/scm/linux/kernel/git/swarren/linux-tegra.git 8332T: git git://git.kernel.org/pub/scm/linux/kernel/git/swarren/linux-tegra.git
8302S: Supported 8333S: Supported
8303N: [^a-z]tegra 8334N: [^a-z]tegra
8304 8335
8336TEGRA ASOC DRIVER
8337M: Stephen Warren <swarren@wwwdotorg.org>
8338S: Supported
8339F: sound/soc/tegra/
8340
8341TEGRA CLOCK DRIVER
8342M: Peter De Schrijver <pdeschrijver@nvidia.com>
8343M: Prashant Gaikwad <pgaikwad@nvidia.com>
8344S: Supported
8345F: drivers/clk/tegra/
8346
8347TEGRA DMA DRIVER
8348M: Laxman Dewangan <ldewangan@nvidia.com>
8349S: Supported
8350F: drivers/dma/tegra20-apb-dma.c
8351
8352TEGRA GPIO DRIVER
8353M: Stephen Warren <swarren@wwwdotorg.org>
8354S: Supported
8355F: drivers/gpio/gpio-tegra.c
8356
8357TEGRA I2C DRIVER
8358M: Laxman Dewangan <ldewangan@nvidia.com>
8359S: Supported
8360F: drivers/i2c/busses/i2c-tegra.c
8361
8362TEGRA IOMMU DRIVERS
8363M: Hiroshi Doyu <hdoyu@nvidia.com>
8364S: Supported
8365F: drivers/iommu/tegra*
8366
8367TEGRA KBC DRIVER
8368M: Rakesh Iyer <riyer@nvidia.com>
8369M: Laxman Dewangan <ldewangan@nvidia.com>
8370S: Supported
8371F: drivers/input/keyboard/tegra-kbc.c
8372
8373TEGRA PINCTRL DRIVER
8374M: Stephen Warren <swarren@wwwdotorg.org>
8375S: Supported
8376F: drivers/pinctrl/pinctrl-tegra*
8377
8378TEGRA PWM DRIVER
8379M: Thierry Reding <thierry.reding@gmail.com>
8380S: Supported
8381F: drivers/pwm/pwm-tegra.c
8382
8383TEGRA SERIAL DRIVER
8384M: Laxman Dewangan <ldewangan@nvidia.com>
8385S: Supported
8386F: drivers/tty/serial/serial-tegra.c
8387
8388TEGRA SPI DRIVER
8389M: Laxman Dewangan <ldewangan@nvidia.com>
8390S: Supported
8391F: drivers/spi/spi-tegra*
8392
8305TEHUTI ETHERNET DRIVER 8393TEHUTI ETHERNET DRIVER
8306M: Andy Gospodarek <andy@greyhouse.net> 8394M: Andy Gospodarek <andy@greyhouse.net>
8307L: netdev@vger.kernel.org 8395L: netdev@vger.kernel.org
@@ -8837,61 +8925,14 @@ W: http://pegasus2.sourceforge.net/
8837S: Maintained 8925S: Maintained
8838F: drivers/net/usb/rtl8150.c 8926F: drivers/net/usb/rtl8150.c
8839 8927
8840USB SERIAL BELKIN F5U103 DRIVER 8928USB SERIAL SUBSYSTEM
8841M: William Greathouse <wgreathouse@smva.com> 8929M: Johan Hovold <jhovold@gmail.com>
8842L: linux-usb@vger.kernel.org
8843S: Maintained
8844F: drivers/usb/serial/belkin_sa.*
8845
8846USB SERIAL CYPRESS M8 DRIVER
8847M: Lonnie Mendez <dignome@gmail.com>
8848L: linux-usb@vger.kernel.org 8930L: linux-usb@vger.kernel.org
8849S: Maintained 8931S: Maintained
8850W: http://geocities.com/i0xox0i
8851W: http://firstlight.net/cvs
8852F: drivers/usb/serial/cypress_m8.*
8853
8854USB SERIAL CYBERJACK DRIVER
8855M: Matthias Bruestle and Harald Welte <support@reiner-sct.com>
8856W: http://www.reiner-sct.de/support/treiber_cyberjack.php
8857S: Maintained
8858F: drivers/usb/serial/cyberjack.c
8859
8860USB SERIAL DIGI ACCELEPORT DRIVER
8861M: Peter Berger <pberger@brimson.com>
8862M: Al Borchers <alborchers@steinerpoint.com>
8863L: linux-usb@vger.kernel.org
8864S: Maintained
8865F: drivers/usb/serial/digi_acceleport.c
8866
8867USB SERIAL DRIVER
8868M: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
8869L: linux-usb@vger.kernel.org
8870S: Supported
8871F: Documentation/usb/usb-serial.txt 8932F: Documentation/usb/usb-serial.txt
8872F: drivers/usb/serial/generic.c 8933F: drivers/usb/serial/
8873F: drivers/usb/serial/usb-serial.c
8874F: include/linux/usb/serial.h 8934F: include/linux/usb/serial.h
8875 8935
8876USB SERIAL EMPEG EMPEG-CAR MARK I/II DRIVER
8877M: Gary Brubaker <xavyer@ix.netcom.com>
8878L: linux-usb@vger.kernel.org
8879S: Maintained
8880F: drivers/usb/serial/empeg.c
8881
8882USB SERIAL KEYSPAN DRIVER
8883M: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
8884L: linux-usb@vger.kernel.org
8885S: Maintained
8886F: drivers/usb/serial/*keyspan*
8887
8888USB SERIAL WHITEHEAT DRIVER
8889M: Support Department <support@connecttech.com>
8890L: linux-usb@vger.kernel.org
8891W: http://www.connecttech.com
8892S: Supported
8893F: drivers/usb/serial/whiteheat*
8894
8895USB SMSC75XX ETHERNET DRIVER 8936USB SMSC75XX ETHERNET DRIVER
8896M: Steve Glendinning <steve.glendinning@shawell.net> 8937M: Steve Glendinning <steve.glendinning@shawell.net>
8897L: netdev@vger.kernel.org 8938L: netdev@vger.kernel.org
diff --git a/Makefile b/Makefile
index 126321d2e6ad..67077ad6edbb 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
1VERSION = 3 1VERSION = 3
2PATCHLEVEL = 12 2PATCHLEVEL = 12
3SUBLEVEL = 0 3SUBLEVEL = 0
4EXTRAVERSION = -rc6 4EXTRAVERSION =
5NAME = One Giant Leap for Frogkind 5NAME = One Giant Leap for Frogkind
6 6
7# *DOCUMENTATION* 7# *DOCUMENTATION*
diff --git a/arch/arc/mm/fault.c b/arch/arc/mm/fault.c
index d63f3de0cd5b..0c14d8a52683 100644
--- a/arch/arc/mm/fault.c
+++ b/arch/arc/mm/fault.c
@@ -17,7 +17,7 @@
17#include <asm/pgalloc.h> 17#include <asm/pgalloc.h>
18#include <asm/mmu.h> 18#include <asm/mmu.h>
19 19
20static int handle_vmalloc_fault(struct mm_struct *mm, unsigned long address) 20static int handle_vmalloc_fault(unsigned long address)
21{ 21{
22 /* 22 /*
23 * Synchronize this task's top level page-table 23 * Synchronize this task's top level page-table
@@ -27,7 +27,7 @@ static int handle_vmalloc_fault(struct mm_struct *mm, unsigned long address)
27 pud_t *pud, *pud_k; 27 pud_t *pud, *pud_k;
28 pmd_t *pmd, *pmd_k; 28 pmd_t *pmd, *pmd_k;
29 29
30 pgd = pgd_offset_fast(mm, address); 30 pgd = pgd_offset_fast(current->active_mm, address);
31 pgd_k = pgd_offset_k(address); 31 pgd_k = pgd_offset_k(address);
32 32
33 if (!pgd_present(*pgd_k)) 33 if (!pgd_present(*pgd_k))
@@ -72,7 +72,7 @@ void do_page_fault(struct pt_regs *regs, unsigned long address)
72 * nothing more. 72 * nothing more.
73 */ 73 */
74 if (address >= VMALLOC_START && address <= VMALLOC_END) { 74 if (address >= VMALLOC_START && address <= VMALLOC_END) {
75 ret = handle_vmalloc_fault(mm, address); 75 ret = handle_vmalloc_fault(address);
76 if (unlikely(ret)) 76 if (unlikely(ret))
77 goto bad_area_nosemaphore; 77 goto bad_area_nosemaphore;
78 else 78 else
diff --git a/arch/arm/boot/dts/integratorcp.dts b/arch/arm/boot/dts/integratorcp.dts
index ff1aea0ee043..72693a69f830 100644
--- a/arch/arm/boot/dts/integratorcp.dts
+++ b/arch/arm/boot/dts/integratorcp.dts
@@ -9,11 +9,6 @@
9 model = "ARM Integrator/CP"; 9 model = "ARM Integrator/CP";
10 compatible = "arm,integrator-cp"; 10 compatible = "arm,integrator-cp";
11 11
12 aliases {
13 arm,timer-primary = &timer2;
14 arm,timer-secondary = &timer1;
15 };
16
17 chosen { 12 chosen {
18 bootargs = "root=/dev/ram0 console=ttyAMA0,38400n8 earlyprintk"; 13 bootargs = "root=/dev/ram0 console=ttyAMA0,38400n8 earlyprintk";
19 }; 14 };
@@ -24,14 +19,18 @@
24 }; 19 };
25 20
26 timer0: timer@13000000 { 21 timer0: timer@13000000 {
22 /* TIMER0 runs @ 25MHz */
27 compatible = "arm,integrator-cp-timer"; 23 compatible = "arm,integrator-cp-timer";
24 status = "disabled";
28 }; 25 };
29 26
30 timer1: timer@13000100 { 27 timer1: timer@13000100 {
28 /* TIMER1 runs @ 1MHz */
31 compatible = "arm,integrator-cp-timer"; 29 compatible = "arm,integrator-cp-timer";
32 }; 30 };
33 31
34 timer2: timer@13000200 { 32 timer2: timer@13000200 {
33 /* TIMER2 runs @ 1MHz */
35 compatible = "arm,integrator-cp-timer"; 34 compatible = "arm,integrator-cp-timer";
36 }; 35 };
37 36
diff --git a/arch/arm/boot/dts/omap3-beagle-xm.dts b/arch/arm/boot/dts/omap3-beagle-xm.dts
index 2816bf612672..ba4dcfc6b721 100644
--- a/arch/arm/boot/dts/omap3-beagle-xm.dts
+++ b/arch/arm/boot/dts/omap3-beagle-xm.dts
@@ -144,6 +144,8 @@
144&usb_otg_hs { 144&usb_otg_hs {
145 interface-type = <0>; 145 interface-type = <0>;
146 usb-phy = <&usb2_phy>; 146 usb-phy = <&usb2_phy>;
147 phys = <&usb2_phy>;
148 phy-names = "usb2-phy";
147 mode = <3>; 149 mode = <3>;
148 power = <50>; 150 power = <50>;
149}; 151};
diff --git a/arch/arm/boot/dts/omap3-evm.dts b/arch/arm/boot/dts/omap3-evm.dts
index 7d4329d179c4..4134dd05c3a4 100644
--- a/arch/arm/boot/dts/omap3-evm.dts
+++ b/arch/arm/boot/dts/omap3-evm.dts
@@ -70,6 +70,8 @@
70&usb_otg_hs { 70&usb_otg_hs {
71 interface-type = <0>; 71 interface-type = <0>;
72 usb-phy = <&usb2_phy>; 72 usb-phy = <&usb2_phy>;
73 phys = <&usb2_phy>;
74 phy-names = "usb2-phy";
73 mode = <3>; 75 mode = <3>;
74 power = <50>; 76 power = <50>;
75}; 77};
diff --git a/arch/arm/boot/dts/omap3-overo.dtsi b/arch/arm/boot/dts/omap3-overo.dtsi
index 8f1abec78275..a461d2fd1fb0 100644
--- a/arch/arm/boot/dts/omap3-overo.dtsi
+++ b/arch/arm/boot/dts/omap3-overo.dtsi
@@ -76,6 +76,8 @@
76&usb_otg_hs { 76&usb_otg_hs {
77 interface-type = <0>; 77 interface-type = <0>;
78 usb-phy = <&usb2_phy>; 78 usb-phy = <&usb2_phy>;
79 phys = <&usb2_phy>;
80 phy-names = "usb2-phy";
79 mode = <3>; 81 mode = <3>;
80 power = <50>; 82 power = <50>;
81}; 83};
diff --git a/arch/arm/boot/dts/omap4.dtsi b/arch/arm/boot/dts/omap4.dtsi
index 22d9f2b593d4..ea4054bfdfd4 100644
--- a/arch/arm/boot/dts/omap4.dtsi
+++ b/arch/arm/boot/dts/omap4.dtsi
@@ -519,7 +519,8 @@
519 usb2_phy: usb2phy@4a0ad080 { 519 usb2_phy: usb2phy@4a0ad080 {
520 compatible = "ti,omap-usb2"; 520 compatible = "ti,omap-usb2";
521 reg = <0x4a0ad080 0x58>; 521 reg = <0x4a0ad080 0x58>;
522 ctrl-module = <&omap_control_usb>; 522 ctrl-module = <&omap_control_usb2phy>;
523 #phy-cells = <0>;
523 }; 524 };
524 }; 525 };
525 526
@@ -643,12 +644,16 @@
643 }; 644 };
644 }; 645 };
645 646
646 omap_control_usb: omap-control-usb@4a002300 { 647 omap_control_usb2phy: control-phy@4a002300 {
647 compatible = "ti,omap-control-usb"; 648 compatible = "ti,control-phy-usb2";
648 reg = <0x4a002300 0x4>, 649 reg = <0x4a002300 0x4>;
649 <0x4a00233c 0x4>; 650 reg-names = "power";
650 reg-names = "control_dev_conf", "otghs_control"; 651 };
651 ti,type = <1>; 652
653 omap_control_usbotg: control-phy@4a00233c {
654 compatible = "ti,control-phy-otghs";
655 reg = <0x4a00233c 0x4>;
656 reg-names = "otghs_control";
652 }; 657 };
653 658
654 usb_otg_hs: usb_otg_hs@4a0ab000 { 659 usb_otg_hs: usb_otg_hs@4a0ab000 {
@@ -658,10 +663,12 @@
658 interrupt-names = "mc", "dma"; 663 interrupt-names = "mc", "dma";
659 ti,hwmods = "usb_otg_hs"; 664 ti,hwmods = "usb_otg_hs";
660 usb-phy = <&usb2_phy>; 665 usb-phy = <&usb2_phy>;
666 phys = <&usb2_phy>;
667 phy-names = "usb2-phy";
661 multipoint = <1>; 668 multipoint = <1>;
662 num-eps = <16>; 669 num-eps = <16>;
663 ram-bits = <12>; 670 ram-bits = <12>;
664 ti,has-mailbox; 671 ctrl-module = <&omap_control_usbotg>;
665 }; 672 };
666 }; 673 };
667}; 674};
diff --git a/arch/arm/boot/dts/omap5.dtsi b/arch/arm/boot/dts/omap5.dtsi
index 7cdea1bfea09..c0ec6dce30fe 100644
--- a/arch/arm/boot/dts/omap5.dtsi
+++ b/arch/arm/boot/dts/omap5.dtsi
@@ -626,12 +626,16 @@
626 hw-caps-temp-alert; 626 hw-caps-temp-alert;
627 }; 627 };
628 628
629 omap_control_usb: omap-control-usb@4a002300 { 629 omap_control_usb2phy: control-phy@4a002300 {
630 compatible = "ti,omap-control-usb"; 630 compatible = "ti,control-phy-usb2";
631 reg = <0x4a002300 0x4>, 631 reg = <0x4a002300 0x4>;
632 <0x4a002370 0x4>; 632 reg-names = "power";
633 reg-names = "control_dev_conf", "phy_power_usb"; 633 };
634 ti,type = <2>; 634
635 omap_control_usb3phy: control-phy@4a002370 {
636 compatible = "ti,control-phy-pipe3";
637 reg = <0x4a002370 0x4>;
638 reg-names = "power";
635 }; 639 };
636 640
637 omap_dwc3@4a020000 { 641 omap_dwc3@4a020000 {
@@ -662,7 +666,7 @@
662 usb2_phy: usb2phy@4a084000 { 666 usb2_phy: usb2phy@4a084000 {
663 compatible = "ti,omap-usb2"; 667 compatible = "ti,omap-usb2";
664 reg = <0x4a084000 0x7c>; 668 reg = <0x4a084000 0x7c>;
665 ctrl-module = <&omap_control_usb>; 669 ctrl-module = <&omap_control_usb2phy>;
666 }; 670 };
667 671
668 usb3_phy: usb3phy@4a084400 { 672 usb3_phy: usb3phy@4a084400 {
@@ -671,7 +675,7 @@
671 <0x4a084800 0x64>, 675 <0x4a084800 0x64>,
672 <0x4a084c00 0x40>; 676 <0x4a084c00 0x40>;
673 reg-names = "phy_rx", "phy_tx", "pll_ctrl"; 677 reg-names = "phy_rx", "phy_tx", "pll_ctrl";
674 ctrl-module = <&omap_control_usb>; 678 ctrl-module = <&omap_control_usb3phy>;
675 }; 679 };
676 }; 680 };
677 681
diff --git a/arch/arm/boot/dts/twl4030.dtsi b/arch/arm/boot/dts/twl4030.dtsi
index ae6a17aed9ee..5aba238d1f1e 100644
--- a/arch/arm/boot/dts/twl4030.dtsi
+++ b/arch/arm/boot/dts/twl4030.dtsi
@@ -86,6 +86,7 @@
86 usb1v8-supply = <&vusb1v8>; 86 usb1v8-supply = <&vusb1v8>;
87 usb3v1-supply = <&vusb3v1>; 87 usb3v1-supply = <&vusb3v1>;
88 usb_mode = <1>; 88 usb_mode = <1>;
89 #phy-cells = <0>;
89 }; 90 };
90 91
91 twl_pwm: pwm { 92 twl_pwm: pwm {
diff --git a/arch/arm/configs/ep93xx_defconfig b/arch/arm/configs/ep93xx_defconfig
index 806005a4c4c1..6ac5ea73bd0a 100644
--- a/arch/arm/configs/ep93xx_defconfig
+++ b/arch/arm/configs/ep93xx_defconfig
@@ -1,15 +1,14 @@
1CONFIG_EXPERIMENTAL=y
2CONFIG_SYSVIPC=y 1CONFIG_SYSVIPC=y
3CONFIG_IKCONFIG=y 2CONFIG_IKCONFIG=y
4CONFIG_IKCONFIG_PROC=y 3CONFIG_IKCONFIG_PROC=y
5CONFIG_LOG_BUF_SHIFT=14 4CONFIG_LOG_BUF_SHIFT=14
6CONFIG_SYSFS_DEPRECATED_V2=y
7CONFIG_EXPERT=y 5CONFIG_EXPERT=y
8CONFIG_SLAB=y 6CONFIG_SLAB=y
9CONFIG_MODULES=y 7CONFIG_MODULES=y
10CONFIG_MODULE_UNLOAD=y 8CONFIG_MODULE_UNLOAD=y
11CONFIG_MODULE_FORCE_UNLOAD=y 9CONFIG_MODULE_FORCE_UNLOAD=y
12# CONFIG_BLK_DEV_BSG is not set 10# CONFIG_BLK_DEV_BSG is not set
11CONFIG_PARTITION_ADVANCED=y
13# CONFIG_IOSCHED_CFQ is not set 12# CONFIG_IOSCHED_CFQ is not set
14CONFIG_ARCH_EP93XX=y 13CONFIG_ARCH_EP93XX=y
15CONFIG_CRUNCH=y 14CONFIG_CRUNCH=y
@@ -47,11 +46,8 @@ CONFIG_IPV6=y
47CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug" 46CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
48# CONFIG_FW_LOADER is not set 47# CONFIG_FW_LOADER is not set
49CONFIG_MTD=y 48CONFIG_MTD=y
50CONFIG_MTD_CONCAT=y
51CONFIG_MTD_PARTITIONS=y
52CONFIG_MTD_REDBOOT_PARTS=y 49CONFIG_MTD_REDBOOT_PARTS=y
53CONFIG_MTD_CMDLINE_PARTS=y 50CONFIG_MTD_CMDLINE_PARTS=y
54CONFIG_MTD_CHAR=y
55CONFIG_MTD_BLOCK=y 51CONFIG_MTD_BLOCK=y
56CONFIG_MTD_CFI=y 52CONFIG_MTD_CFI=y
57CONFIG_MTD_CFI_ADV_OPTIONS=y 53CONFIG_MTD_CFI_ADV_OPTIONS=y
@@ -67,15 +63,14 @@ CONFIG_SCSI=y
67# CONFIG_SCSI_PROC_FS is not set 63# CONFIG_SCSI_PROC_FS is not set
68CONFIG_BLK_DEV_SD=y 64CONFIG_BLK_DEV_SD=y
69CONFIG_NETDEVICES=y 65CONFIG_NETDEVICES=y
70CONFIG_NET_ETHERNET=y
71CONFIG_EP93XX_ETH=y 66CONFIG_EP93XX_ETH=y
72CONFIG_USB_RTL8150=y 67CONFIG_USB_RTL8150=y
73# CONFIG_INPUT is not set 68# CONFIG_INPUT is not set
74# CONFIG_SERIO is not set 69# CONFIG_SERIO is not set
75# CONFIG_VT is not set 70# CONFIG_VT is not set
71# CONFIG_LEGACY_PTYS is not set
76CONFIG_SERIAL_AMBA_PL010=y 72CONFIG_SERIAL_AMBA_PL010=y
77CONFIG_SERIAL_AMBA_PL010_CONSOLE=y 73CONFIG_SERIAL_AMBA_PL010_CONSOLE=y
78# CONFIG_LEGACY_PTYS is not set
79# CONFIG_HW_RANDOM is not set 74# CONFIG_HW_RANDOM is not set
80CONFIG_I2C=y 75CONFIG_I2C=y
81CONFIG_I2C_CHARDEV=y 76CONFIG_I2C_CHARDEV=y
@@ -86,9 +81,9 @@ CONFIG_WATCHDOG=y
86CONFIG_EP93XX_WATCHDOG=y 81CONFIG_EP93XX_WATCHDOG=y
87CONFIG_USB=y 82CONFIG_USB=y
88CONFIG_USB_DEBUG=y 83CONFIG_USB_DEBUG=y
89CONFIG_USB_DEVICEFS=y
90CONFIG_USB_DYNAMIC_MINORS=y 84CONFIG_USB_DYNAMIC_MINORS=y
91CONFIG_USB_OHCI_HCD=y 85CONFIG_USB_OHCI_HCD=y
86CONFIG_USB_OHCI_HCD_PLATFORM=y
92CONFIG_USB_STORAGE=y 87CONFIG_USB_STORAGE=y
93CONFIG_USB_SERIAL=y 88CONFIG_USB_SERIAL=y
94CONFIG_USB_SERIAL_CONSOLE=y 89CONFIG_USB_SERIAL_CONSOLE=y
@@ -100,24 +95,18 @@ CONFIG_RTC_DRV_EP93XX=y
100CONFIG_EXT2_FS=y 95CONFIG_EXT2_FS=y
101CONFIG_EXT3_FS=y 96CONFIG_EXT3_FS=y
102# CONFIG_EXT3_FS_XATTR is not set 97# CONFIG_EXT3_FS_XATTR is not set
103CONFIG_INOTIFY=y
104CONFIG_VFAT_FS=y 98CONFIG_VFAT_FS=y
105CONFIG_TMPFS=y 99CONFIG_TMPFS=y
106CONFIG_JFFS2_FS=y 100CONFIG_JFFS2_FS=y
107CONFIG_NFS_FS=y 101CONFIG_NFS_FS=y
108CONFIG_NFS_V3=y
109CONFIG_ROOT_NFS=y 102CONFIG_ROOT_NFS=y
110CONFIG_PARTITION_ADVANCED=y
111CONFIG_NLS_CODEPAGE_437=y 103CONFIG_NLS_CODEPAGE_437=y
112CONFIG_NLS_ISO8859_1=y 104CONFIG_NLS_ISO8859_1=y
113CONFIG_MAGIC_SYSRQ=y 105CONFIG_MAGIC_SYSRQ=y
114CONFIG_DEBUG_KERNEL=y
115CONFIG_DEBUG_SLAB=y 106CONFIG_DEBUG_SLAB=y
116CONFIG_DEBUG_SPINLOCK=y 107CONFIG_DEBUG_SPINLOCK=y
117CONFIG_DEBUG_MUTEXES=y 108CONFIG_DEBUG_MUTEXES=y
118# CONFIG_RCU_CPU_STALL_DETECTOR is not set
119CONFIG_DEBUG_USER=y 109CONFIG_DEBUG_USER=y
120CONFIG_DEBUG_ERRORS=y
121CONFIG_DEBUG_LL=y 110CONFIG_DEBUG_LL=y
122# CONFIG_CRYPTO_ANSI_CPRNG is not set 111# CONFIG_CRYPTO_ANSI_CPRNG is not set
123CONFIG_LIBCRC32C=y 112CONFIG_LIBCRC32C=y
diff --git a/arch/arm/mach-ep93xx/clock.c b/arch/arm/mach-ep93xx/clock.c
index c95dbce2468e..39ef3b613912 100644
--- a/arch/arm/mach-ep93xx/clock.c
+++ b/arch/arm/mach-ep93xx/clock.c
@@ -212,7 +212,7 @@ static struct clk_lookup clocks[] = {
212 INIT_CK(NULL, "hclk", &clk_h), 212 INIT_CK(NULL, "hclk", &clk_h),
213 INIT_CK(NULL, "apb_pclk", &clk_p), 213 INIT_CK(NULL, "apb_pclk", &clk_p),
214 INIT_CK(NULL, "pll2", &clk_pll2), 214 INIT_CK(NULL, "pll2", &clk_pll2),
215 INIT_CK("ep93xx-ohci", NULL, &clk_usb_host), 215 INIT_CK("ohci-platform", NULL, &clk_usb_host),
216 INIT_CK("ep93xx-keypad", NULL, &clk_keypad), 216 INIT_CK("ep93xx-keypad", NULL, &clk_keypad),
217 INIT_CK("ep93xx-fb", NULL, &clk_video), 217 INIT_CK("ep93xx-fb", NULL, &clk_video),
218 INIT_CK("ep93xx-spi.0", NULL, &clk_spi), 218 INIT_CK("ep93xx-spi.0", NULL, &clk_spi),
diff --git a/arch/arm/mach-ep93xx/core.c b/arch/arm/mach-ep93xx/core.c
index 3f12b885c083..d95ee28a616a 100644
--- a/arch/arm/mach-ep93xx/core.c
+++ b/arch/arm/mach-ep93xx/core.c
@@ -36,6 +36,7 @@
36#include <linux/export.h> 36#include <linux/export.h>
37#include <linux/irqchip/arm-vic.h> 37#include <linux/irqchip/arm-vic.h>
38#include <linux/reboot.h> 38#include <linux/reboot.h>
39#include <linux/usb/ohci_pdriver.h>
39 40
40#include <mach/hardware.h> 41#include <mach/hardware.h>
41#include <linux/platform_data/video-ep93xx.h> 42#include <linux/platform_data/video-ep93xx.h>
@@ -297,25 +298,53 @@ static struct platform_device ep93xx_rtc_device = {
297 .resource = ep93xx_rtc_resource, 298 .resource = ep93xx_rtc_resource,
298}; 299};
299 300
301/*************************************************************************
302 * EP93xx OHCI USB Host
303 *************************************************************************/
304
305static struct clk *ep93xx_ohci_host_clock;
306
307static int ep93xx_ohci_power_on(struct platform_device *pdev)
308{
309 if (!ep93xx_ohci_host_clock) {
310 ep93xx_ohci_host_clock = devm_clk_get(&pdev->dev, NULL);
311 if (IS_ERR(ep93xx_ohci_host_clock))
312 return PTR_ERR(ep93xx_ohci_host_clock);
313 }
314
315 return clk_enable(ep93xx_ohci_host_clock);
316}
317
318static void ep93xx_ohci_power_off(struct platform_device *pdev)
319{
320 clk_disable(ep93xx_ohci_host_clock);
321}
322
323static struct usb_ohci_pdata ep93xx_ohci_pdata = {
324 .power_on = ep93xx_ohci_power_on,
325 .power_off = ep93xx_ohci_power_off,
326 .power_suspend = ep93xx_ohci_power_off,
327};
300 328
301static struct resource ep93xx_ohci_resources[] = { 329static struct resource ep93xx_ohci_resources[] = {
302 DEFINE_RES_MEM(EP93XX_USB_PHYS_BASE, 0x1000), 330 DEFINE_RES_MEM(EP93XX_USB_PHYS_BASE, 0x1000),
303 DEFINE_RES_IRQ(IRQ_EP93XX_USB), 331 DEFINE_RES_IRQ(IRQ_EP93XX_USB),
304}; 332};
305 333
334static u64 ep93xx_ohci_dma_mask = DMA_BIT_MASK(32);
306 335
307static struct platform_device ep93xx_ohci_device = { 336static struct platform_device ep93xx_ohci_device = {
308 .name = "ep93xx-ohci", 337 .name = "ohci-platform",
309 .id = -1, 338 .id = -1,
339 .num_resources = ARRAY_SIZE(ep93xx_ohci_resources),
340 .resource = ep93xx_ohci_resources,
310 .dev = { 341 .dev = {
311 .dma_mask = &ep93xx_ohci_device.dev.coherent_dma_mask, 342 .dma_mask = &ep93xx_ohci_dma_mask,
312 .coherent_dma_mask = DMA_BIT_MASK(32), 343 .coherent_dma_mask = DMA_BIT_MASK(32),
344 .platform_data = &ep93xx_ohci_pdata,
313 }, 345 },
314 .num_resources = ARRAY_SIZE(ep93xx_ohci_resources),
315 .resource = ep93xx_ohci_resources,
316}; 346};
317 347
318
319/************************************************************************* 348/*************************************************************************
320 * EP93xx physmap'ed flash 349 * EP93xx physmap'ed flash
321 *************************************************************************/ 350 *************************************************************************/
diff --git a/arch/arm/mach-exynos/include/mach/regs-pmu.h b/arch/arm/mach-exynos/include/mach/regs-pmu.h
index 57344b7e98ce..2cdb63e8ce5c 100644
--- a/arch/arm/mach-exynos/include/mach/regs-pmu.h
+++ b/arch/arm/mach-exynos/include/mach/regs-pmu.h
@@ -44,11 +44,6 @@
44#define S5P_DAC_PHY_CONTROL S5P_PMUREG(0x070C) 44#define S5P_DAC_PHY_CONTROL S5P_PMUREG(0x070C)
45#define S5P_DAC_PHY_ENABLE (1 << 0) 45#define S5P_DAC_PHY_ENABLE (1 << 0)
46 46
47#define S5P_MIPI_DPHY_CONTROL(n) S5P_PMUREG(0x0710 + (n) * 4)
48#define S5P_MIPI_DPHY_ENABLE (1 << 0)
49#define S5P_MIPI_DPHY_SRESETN (1 << 1)
50#define S5P_MIPI_DPHY_MRESETN (1 << 2)
51
52#define S5P_INFORM0 S5P_PMUREG(0x0800) 47#define S5P_INFORM0 S5P_PMUREG(0x0800)
53#define S5P_INFORM1 S5P_PMUREG(0x0804) 48#define S5P_INFORM1 S5P_PMUREG(0x0804)
54#define S5P_INFORM2 S5P_PMUREG(0x0808) 49#define S5P_INFORM2 S5P_PMUREG(0x0808)
diff --git a/arch/arm/mach-omap2/board-omap3beagle.c b/arch/arm/mach-omap2/board-omap3beagle.c
index f26918467efc..8b9cd0690ce7 100644
--- a/arch/arm/mach-omap2/board-omap3beagle.c
+++ b/arch/arm/mach-omap2/board-omap3beagle.c
@@ -289,18 +289,12 @@ static struct regulator_consumer_supply beagle_vsim_supply[] = {
289 289
290static struct gpio_led gpio_leds[]; 290static struct gpio_led gpio_leds[];
291 291
292/* PHY's VCC regulator might be added later, so flag that we need it */
293static struct usb_phy_gen_xceiv_platform_data hsusb2_phy_data = {
294 .needs_vcc = true,
295};
296
297static struct usbhs_phy_data phy_data[] = { 292static struct usbhs_phy_data phy_data[] = {
298 { 293 {
299 .port = 2, 294 .port = 2,
300 .reset_gpio = 147, 295 .reset_gpio = 147,
301 .vcc_gpio = -1, /* updated in beagle_twl_gpio_setup */ 296 .vcc_gpio = -1, /* updated in beagle_twl_gpio_setup */
302 .vcc_polarity = 1, /* updated in beagle_twl_gpio_setup */ 297 .vcc_polarity = 1, /* updated in beagle_twl_gpio_setup */
303 .platform_data = &hsusb2_phy_data,
304 }, 298 },
305}; 299};
306 300
diff --git a/arch/arm/mach-omap2/twl-common.c b/arch/arm/mach-omap2/twl-common.c
index c05898fbd634..b0d54dae1bcb 100644
--- a/arch/arm/mach-omap2/twl-common.c
+++ b/arch/arm/mach-omap2/twl-common.c
@@ -24,6 +24,7 @@
24#include <linux/i2c/twl.h> 24#include <linux/i2c/twl.h>
25#include <linux/gpio.h> 25#include <linux/gpio.h>
26#include <linux/string.h> 26#include <linux/string.h>
27#include <linux/phy/phy.h>
27#include <linux/regulator/machine.h> 28#include <linux/regulator/machine.h>
28#include <linux/regulator/fixed.h> 29#include <linux/regulator/fixed.h>
29 30
@@ -90,8 +91,18 @@ void __init omap_pmic_late_init(void)
90} 91}
91 92
92#if defined(CONFIG_ARCH_OMAP3) 93#if defined(CONFIG_ARCH_OMAP3)
94struct phy_consumer consumers[] = {
95 PHY_CONSUMER("musb-hdrc.0", "usb"),
96};
97
98struct phy_init_data init_data = {
99 .consumers = consumers,
100 .num_consumers = ARRAY_SIZE(consumers),
101};
102
93static struct twl4030_usb_data omap3_usb_pdata = { 103static struct twl4030_usb_data omap3_usb_pdata = {
94 .usb_mode = T2_USB_MODE_ULPI, 104 .usb_mode = T2_USB_MODE_ULPI,
105 .init_data = &init_data,
95}; 106};
96 107
97static int omap3_batt_table[] = { 108static int omap3_batt_table[] = {
diff --git a/arch/arm/mach-omap2/usb-host.c b/arch/arm/mach-omap2/usb-host.c
index e83a6a4b184a..10855eb4ccc1 100644
--- a/arch/arm/mach-omap2/usb-host.c
+++ b/arch/arm/mach-omap2/usb-host.c
@@ -435,6 +435,7 @@ int usbhs_init_phys(struct usbhs_phy_data *phy, int num_phys)
435 struct platform_device *pdev; 435 struct platform_device *pdev;
436 char *phy_id; 436 char *phy_id;
437 struct platform_device_info pdevinfo; 437 struct platform_device_info pdevinfo;
438 struct usb_phy_gen_xceiv_platform_data nop_pdata;
438 439
439 for (i = 0; i < num_phys; i++) { 440 for (i = 0; i < num_phys; i++) {
440 441
@@ -455,11 +456,18 @@ int usbhs_init_phys(struct usbhs_phy_data *phy, int num_phys)
455 return -ENOMEM; 456 return -ENOMEM;
456 } 457 }
457 458
459 /* set platform data */
460 memset(&nop_pdata, 0, sizeof(nop_pdata));
461 if (gpio_is_valid(phy->vcc_gpio))
462 nop_pdata.needs_vcc = true;
463 nop_pdata.gpio_reset = phy->reset_gpio;
464 nop_pdata.type = USB_PHY_TYPE_USB2;
465
458 /* create a NOP PHY device */ 466 /* create a NOP PHY device */
459 memset(&pdevinfo, 0, sizeof(pdevinfo)); 467 memset(&pdevinfo, 0, sizeof(pdevinfo));
460 pdevinfo.name = nop_name; 468 pdevinfo.name = nop_name;
461 pdevinfo.id = phy->port; 469 pdevinfo.id = phy->port;
462 pdevinfo.data = phy->platform_data; 470 pdevinfo.data = &nop_pdata;
463 pdevinfo.size_data = 471 pdevinfo.size_data =
464 sizeof(struct usb_phy_gen_xceiv_platform_data); 472 sizeof(struct usb_phy_gen_xceiv_platform_data);
465 scnprintf(phy_id, MAX_STR, "usb_phy_gen_xceiv.%d", 473 scnprintf(phy_id, MAX_STR, "usb_phy_gen_xceiv.%d",
@@ -474,14 +482,6 @@ int usbhs_init_phys(struct usbhs_phy_data *phy, int num_phys)
474 482
475 usb_bind_phy("ehci-omap.0", phy->port - 1, phy_id); 483 usb_bind_phy("ehci-omap.0", phy->port - 1, phy_id);
476 484
477 /* Do we need RESET regulator ? */
478 if (gpio_is_valid(phy->reset_gpio)) {
479 scnprintf(rail_name, MAX_STR,
480 "hsusb%d_reset", phy->port);
481 usbhs_add_regulator(rail_name, phy_id, "reset",
482 phy->reset_gpio, 1);
483 }
484
485 /* Do we need VCC regulator ? */ 485 /* Do we need VCC regulator ? */
486 if (gpio_is_valid(phy->vcc_gpio)) { 486 if (gpio_is_valid(phy->vcc_gpio)) {
487 scnprintf(rail_name, MAX_STR, "hsusb%d_vcc", phy->port); 487 scnprintf(rail_name, MAX_STR, "hsusb%d_vcc", phy->port);
diff --git a/arch/arm/mach-omap2/usb.h b/arch/arm/mach-omap2/usb.h
index e7261ebcf7b0..4ba2ae759895 100644
--- a/arch/arm/mach-omap2/usb.h
+++ b/arch/arm/mach-omap2/usb.h
@@ -58,7 +58,6 @@ struct usbhs_phy_data {
58 int reset_gpio; 58 int reset_gpio;
59 int vcc_gpio; 59 int vcc_gpio;
60 bool vcc_polarity; /* 1 active high, 0 active low */ 60 bool vcc_polarity; /* 1 active high, 0 active low */
61 void *platform_data;
62}; 61};
63 62
64extern void usb_musb_init(struct omap_musb_board_data *board_data); 63extern void usb_musb_init(struct omap_musb_board_data *board_data);
diff --git a/arch/arm/mach-s5pv210/include/mach/regs-clock.h b/arch/arm/mach-s5pv210/include/mach/regs-clock.h
index 032de66fb8be..e345584d4c34 100644
--- a/arch/arm/mach-s5pv210/include/mach/regs-clock.h
+++ b/arch/arm/mach-s5pv210/include/mach/regs-clock.h
@@ -147,10 +147,6 @@
147#define S5P_HDMI_PHY_CONTROL S5P_CLKREG(0xE804) 147#define S5P_HDMI_PHY_CONTROL S5P_CLKREG(0xE804)
148#define S5P_USB_PHY_CONTROL S5P_CLKREG(0xE80C) 148#define S5P_USB_PHY_CONTROL S5P_CLKREG(0xE80C)
149#define S5P_DAC_PHY_CONTROL S5P_CLKREG(0xE810) 149#define S5P_DAC_PHY_CONTROL S5P_CLKREG(0xE810)
150#define S5P_MIPI_DPHY_CONTROL(x) S5P_CLKREG(0xE814)
151#define S5P_MIPI_DPHY_ENABLE (1 << 0)
152#define S5P_MIPI_DPHY_SRESETN (1 << 1)
153#define S5P_MIPI_DPHY_MRESETN (1 << 2)
154 150
155#define S5P_INFORM0 S5P_CLKREG(0xF000) 151#define S5P_INFORM0 S5P_CLKREG(0xF000)
156#define S5P_INFORM1 S5P_CLKREG(0xF004) 152#define S5P_INFORM1 S5P_CLKREG(0xF004)
diff --git a/arch/arm/net/bpf_jit_32.c b/arch/arm/net/bpf_jit_32.c
index f50d223a0bd3..99b44e0e8d86 100644
--- a/arch/arm/net/bpf_jit_32.c
+++ b/arch/arm/net/bpf_jit_32.c
@@ -930,4 +930,5 @@ void bpf_jit_free(struct sk_filter *fp)
930{ 930{
931 if (fp->bpf_func != sk_run_filter) 931 if (fp->bpf_func != sk_run_filter)
932 module_free(NULL, fp->bpf_func); 932 module_free(NULL, fp->bpf_func);
933 kfree(fp);
933} 934}
diff --git a/arch/arm/plat-samsung/Kconfig b/arch/arm/plat-samsung/Kconfig
index 7dfba937d8fc..6d95d60276d6 100644
--- a/arch/arm/plat-samsung/Kconfig
+++ b/arch/arm/plat-samsung/Kconfig
@@ -382,11 +382,6 @@ config S5P_DEV_TV
382 help 382 help
383 Compile in platform device definition for TV interface 383 Compile in platform device definition for TV interface
384 384
385config S5P_DEV_USB_EHCI
386 bool
387 help
388 Compile in platform device definition for USB EHCI
389
390config S3C24XX_PWM 385config S3C24XX_PWM
391 bool "PWM device support" 386 bool "PWM device support"
392 select PWM 387 select PWM
@@ -395,11 +390,6 @@ config S3C24XX_PWM
395 Support for exporting the PWM timer blocks via the pwm device 390 Support for exporting the PWM timer blocks via the pwm device
396 system 391 system
397 392
398config S5P_SETUP_MIPIPHY
399 bool
400 help
401 Compile in common setup code for MIPI-CSIS and MIPI-DSIM devices
402
403config S3C_SETUP_CAMIF 393config S3C_SETUP_CAMIF
404 bool 394 bool
405 help 395 help
diff --git a/arch/arm/plat-samsung/Makefile b/arch/arm/plat-samsung/Makefile
index 498c7c23e9f4..9267d29549b4 100644
--- a/arch/arm/plat-samsung/Makefile
+++ b/arch/arm/plat-samsung/Makefile
@@ -38,7 +38,6 @@ obj-$(CONFIG_S5P_DEV_UART) += s5p-dev-uart.o
38obj-$(CONFIG_SAMSUNG_DEV_BACKLIGHT) += dev-backlight.o 38obj-$(CONFIG_SAMSUNG_DEV_BACKLIGHT) += dev-backlight.o
39 39
40obj-$(CONFIG_S3C_SETUP_CAMIF) += setup-camif.o 40obj-$(CONFIG_S3C_SETUP_CAMIF) += setup-camif.o
41obj-$(CONFIG_S5P_SETUP_MIPIPHY) += setup-mipiphy.o
42 41
43# DMA support 42# DMA support
44 43
diff --git a/arch/arm/plat-samsung/devs.c b/arch/arm/plat-samsung/devs.c
index 8ce0ac007eb9..25f40c9b7f62 100644
--- a/arch/arm/plat-samsung/devs.c
+++ b/arch/arm/plat-samsung/devs.c
@@ -49,7 +49,6 @@
49#include <plat/devs.h> 49#include <plat/devs.h>
50#include <plat/adc.h> 50#include <plat/adc.h>
51#include <linux/platform_data/ata-samsung_cf.h> 51#include <linux/platform_data/ata-samsung_cf.h>
52#include <linux/platform_data/usb-ehci-s5p.h>
53#include <plat/fb.h> 52#include <plat/fb.h>
54#include <plat/fb-s3c2410.h> 53#include <plat/fb-s3c2410.h>
55#include <plat/hdmi.h> 54#include <plat/hdmi.h>
@@ -1359,39 +1358,6 @@ void __init s3c24xx_udc_set_platdata(struct s3c2410_udc_mach_info *pd)
1359} 1358}
1360#endif /* CONFIG_PLAT_S3C24XX */ 1359#endif /* CONFIG_PLAT_S3C24XX */
1361 1360
1362/* USB EHCI Host Controller */
1363
1364#ifdef CONFIG_S5P_DEV_USB_EHCI
1365static struct resource s5p_ehci_resource[] = {
1366 [0] = DEFINE_RES_MEM(S5P_PA_EHCI, SZ_256),
1367 [1] = DEFINE_RES_IRQ(IRQ_USB_HOST),
1368};
1369
1370struct platform_device s5p_device_ehci = {
1371 .name = "s5p-ehci",
1372 .id = -1,
1373 .num_resources = ARRAY_SIZE(s5p_ehci_resource),
1374 .resource = s5p_ehci_resource,
1375 .dev = {
1376 .dma_mask = &samsung_device_dma_mask,
1377 .coherent_dma_mask = DMA_BIT_MASK(32),
1378 }
1379};
1380
1381void __init s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd)
1382{
1383 struct s5p_ehci_platdata *npd;
1384
1385 npd = s3c_set_platdata(pd, sizeof(struct s5p_ehci_platdata),
1386 &s5p_device_ehci);
1387
1388 if (!npd->phy_init)
1389 npd->phy_init = s5p_usb_phy_init;
1390 if (!npd->phy_exit)
1391 npd->phy_exit = s5p_usb_phy_exit;
1392}
1393#endif /* CONFIG_S5P_DEV_USB_EHCI */
1394
1395/* USB HSOTG */ 1361/* USB HSOTG */
1396 1362
1397#ifdef CONFIG_S3C_DEV_USB_HSOTG 1363#ifdef CONFIG_S3C_DEV_USB_HSOTG
diff --git a/arch/arm/plat-samsung/include/plat/devs.h b/arch/arm/plat-samsung/include/plat/devs.h
index 0dc4ac4909b0..eece188ed188 100644
--- a/arch/arm/plat-samsung/include/plat/devs.h
+++ b/arch/arm/plat-samsung/include/plat/devs.h
@@ -75,7 +75,6 @@ extern struct platform_device s3c_device_usb_hsotg;
75extern struct platform_device s3c_device_usb_hsudc; 75extern struct platform_device s3c_device_usb_hsudc;
76extern struct platform_device s3c_device_wdt; 76extern struct platform_device s3c_device_wdt;
77 77
78extern struct platform_device s5p_device_ehci;
79extern struct platform_device s5p_device_fimc0; 78extern struct platform_device s5p_device_fimc0;
80extern struct platform_device s5p_device_fimc1; 79extern struct platform_device s5p_device_fimc1;
81extern struct platform_device s5p_device_fimc2; 80extern struct platform_device s5p_device_fimc2;
diff --git a/arch/arm/plat-samsung/setup-mipiphy.c b/arch/arm/plat-samsung/setup-mipiphy.c
deleted file mode 100644
index 66df315990a7..000000000000
--- a/arch/arm/plat-samsung/setup-mipiphy.c
+++ /dev/null
@@ -1,60 +0,0 @@
1/*
2 * Copyright (C) 2011 Samsung Electronics Co., Ltd.
3 *
4 * S5P - Helper functions for MIPI-CSIS and MIPI-DSIM D-PHY control
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
11#include <linux/export.h>
12#include <linux/kernel.h>
13#include <linux/platform_device.h>
14#include <linux/io.h>
15#include <linux/spinlock.h>
16#include <mach/regs-clock.h>
17
18static int __s5p_mipi_phy_control(int id, bool on, u32 reset)
19{
20 static DEFINE_SPINLOCK(lock);
21 void __iomem *addr;
22 unsigned long flags;
23 u32 cfg;
24
25 id = max(0, id);
26 if (id > 1)
27 return -EINVAL;
28
29 addr = S5P_MIPI_DPHY_CONTROL(id);
30
31 spin_lock_irqsave(&lock, flags);
32
33 cfg = __raw_readl(addr);
34 cfg = on ? (cfg | reset) : (cfg & ~reset);
35 __raw_writel(cfg, addr);
36
37 if (on) {
38 cfg |= S5P_MIPI_DPHY_ENABLE;
39 } else if (!(cfg & (S5P_MIPI_DPHY_SRESETN |
40 S5P_MIPI_DPHY_MRESETN) & ~reset)) {
41 cfg &= ~S5P_MIPI_DPHY_ENABLE;
42 }
43
44 __raw_writel(cfg, addr);
45 spin_unlock_irqrestore(&lock, flags);
46
47 return 0;
48}
49
50int s5p_csis_phy_enable(int id, bool on)
51{
52 return __s5p_mipi_phy_control(id, on, S5P_MIPI_DPHY_SRESETN);
53}
54EXPORT_SYMBOL(s5p_csis_phy_enable);
55
56int s5p_dsim_phy_enable(struct platform_device *pdev, bool on)
57{
58 return __s5p_mipi_phy_control(pdev->id, on, S5P_MIPI_DPHY_MRESETN);
59}
60EXPORT_SYMBOL(s5p_dsim_phy_enable);
diff --git a/arch/mips/kernel/perf_event_mipsxx.c b/arch/mips/kernel/perf_event_mipsxx.c
index 45f1ffcf1a4b..24cdf64789c3 100644
--- a/arch/mips/kernel/perf_event_mipsxx.c
+++ b/arch/mips/kernel/perf_event_mipsxx.c
@@ -971,11 +971,11 @@ static const struct mips_perf_event mipsxx74Kcore_cache_map
971[C(LL)] = { 971[C(LL)] = {
972 [C(OP_READ)] = { 972 [C(OP_READ)] = {
973 [C(RESULT_ACCESS)] = { 0x1c, CNTR_ODD, P }, 973 [C(RESULT_ACCESS)] = { 0x1c, CNTR_ODD, P },
974 [C(RESULT_MISS)] = { 0x1d, CNTR_EVEN | CNTR_ODD, P }, 974 [C(RESULT_MISS)] = { 0x1d, CNTR_EVEN, P },
975 }, 975 },
976 [C(OP_WRITE)] = { 976 [C(OP_WRITE)] = {
977 [C(RESULT_ACCESS)] = { 0x1c, CNTR_ODD, P }, 977 [C(RESULT_ACCESS)] = { 0x1c, CNTR_ODD, P },
978 [C(RESULT_MISS)] = { 0x1d, CNTR_EVEN | CNTR_ODD, P }, 978 [C(RESULT_MISS)] = { 0x1d, CNTR_EVEN, P },
979 }, 979 },
980}, 980},
981[C(ITLB)] = { 981[C(ITLB)] = {
diff --git a/arch/mips/mti-malta/malta-int.c b/arch/mips/mti-malta/malta-int.c
index c69da3734699..5b28e81d94a0 100644
--- a/arch/mips/mti-malta/malta-int.c
+++ b/arch/mips/mti-malta/malta-int.c
@@ -473,7 +473,7 @@ static void __init fill_ipi_map(void)
473{ 473{
474 int cpu; 474 int cpu;
475 475
476 for (cpu = 0; cpu < NR_CPUS; cpu++) { 476 for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
477 fill_ipi_map1(gic_resched_int_base, cpu, GIC_CPU_INT1); 477 fill_ipi_map1(gic_resched_int_base, cpu, GIC_CPU_INT1);
478 fill_ipi_map1(gic_call_int_base, cpu, GIC_CPU_INT2); 478 fill_ipi_map1(gic_call_int_base, cpu, GIC_CPU_INT2);
479 } 479 }
@@ -574,8 +574,9 @@ void __init arch_init_irq(void)
574 /* FIXME */ 574 /* FIXME */
575 int i; 575 int i;
576#if defined(CONFIG_MIPS_MT_SMP) 576#if defined(CONFIG_MIPS_MT_SMP)
577 gic_call_int_base = GIC_NUM_INTRS - NR_CPUS; 577 gic_call_int_base = GIC_NUM_INTRS -
578 gic_resched_int_base = gic_call_int_base - NR_CPUS; 578 (NR_CPUS - nr_cpu_ids) * 2 - nr_cpu_ids;
579 gic_resched_int_base = gic_call_int_base - nr_cpu_ids;
579 fill_ipi_map(); 580 fill_ipi_map();
580#endif 581#endif
581 gic_init(GIC_BASE_ADDR, GIC_ADDRSPACE_SZ, gic_intr_map, 582 gic_init(GIC_BASE_ADDR, GIC_ADDRSPACE_SZ, gic_intr_map,
@@ -599,7 +600,7 @@ void __init arch_init_irq(void)
599 printk("CPU%d: status register now %08x\n", smp_processor_id(), read_c0_status()); 600 printk("CPU%d: status register now %08x\n", smp_processor_id(), read_c0_status());
600 write_c0_status(0x1100dc00); 601 write_c0_status(0x1100dc00);
601 printk("CPU%d: status register frc %08x\n", smp_processor_id(), read_c0_status()); 602 printk("CPU%d: status register frc %08x\n", smp_processor_id(), read_c0_status());
602 for (i = 0; i < NR_CPUS; i++) { 603 for (i = 0; i < nr_cpu_ids; i++) {
603 arch_init_ipiirq(MIPS_GIC_IRQ_BASE + 604 arch_init_ipiirq(MIPS_GIC_IRQ_BASE +
604 GIC_RESCHED_INT(i), &irq_resched); 605 GIC_RESCHED_INT(i), &irq_resched);
605 arch_init_ipiirq(MIPS_GIC_IRQ_BASE + 606 arch_init_ipiirq(MIPS_GIC_IRQ_BASE +
diff --git a/arch/mips/ralink/timer.c b/arch/mips/ralink/timer.c
index e49241a2c39a..202785709441 100644
--- a/arch/mips/ralink/timer.c
+++ b/arch/mips/ralink/timer.c
@@ -126,7 +126,7 @@ static int rt_timer_probe(struct platform_device *pdev)
126 return -ENOENT; 126 return -ENOENT;
127 } 127 }
128 128
129 rt->membase = devm_request_and_ioremap(&pdev->dev, res); 129 rt->membase = devm_ioremap_resource(&pdev->dev, res);
130 if (IS_ERR(rt->membase)) 130 if (IS_ERR(rt->membase))
131 return PTR_ERR(rt->membase); 131 return PTR_ERR(rt->membase);
132 132
diff --git a/arch/parisc/configs/712_defconfig b/arch/parisc/configs/712_defconfig
index 0f90569b9d85..9387cc2693f6 100644
--- a/arch/parisc/configs/712_defconfig
+++ b/arch/parisc/configs/712_defconfig
@@ -40,6 +40,8 @@ CONFIG_IP_NF_QUEUE=m
40CONFIG_LLC2=m 40CONFIG_LLC2=m
41CONFIG_NET_PKTGEN=m 41CONFIG_NET_PKTGEN=m
42CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug" 42CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
43CONFIG_DEVTMPFS=y
44CONFIG_DEVTMPFS_MOUNT=y
43# CONFIG_STANDALONE is not set 45# CONFIG_STANDALONE is not set
44# CONFIG_PREVENT_FIRMWARE_BUILD is not set 46# CONFIG_PREVENT_FIRMWARE_BUILD is not set
45CONFIG_PARPORT=y 47CONFIG_PARPORT=y
diff --git a/arch/parisc/configs/a500_defconfig b/arch/parisc/configs/a500_defconfig
index b647b182dacc..90025322b75e 100644
--- a/arch/parisc/configs/a500_defconfig
+++ b/arch/parisc/configs/a500_defconfig
@@ -79,6 +79,8 @@ CONFIG_IP_DCCP=m
79CONFIG_LLC2=m 79CONFIG_LLC2=m
80CONFIG_NET_PKTGEN=m 80CONFIG_NET_PKTGEN=m
81CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug" 81CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
82CONFIG_DEVTMPFS=y
83CONFIG_DEVTMPFS_MOUNT=y
82# CONFIG_STANDALONE is not set 84# CONFIG_STANDALONE is not set
83# CONFIG_PREVENT_FIRMWARE_BUILD is not set 85# CONFIG_PREVENT_FIRMWARE_BUILD is not set
84CONFIG_BLK_DEV_UMEM=m 86CONFIG_BLK_DEV_UMEM=m
diff --git a/arch/parisc/configs/b180_defconfig b/arch/parisc/configs/b180_defconfig
index e289f5bf3148..f1a0c25bef8d 100644
--- a/arch/parisc/configs/b180_defconfig
+++ b/arch/parisc/configs/b180_defconfig
@@ -4,6 +4,7 @@ CONFIG_IKCONFIG=y
4CONFIG_IKCONFIG_PROC=y 4CONFIG_IKCONFIG_PROC=y
5CONFIG_LOG_BUF_SHIFT=16 5CONFIG_LOG_BUF_SHIFT=16
6CONFIG_SYSFS_DEPRECATED_V2=y 6CONFIG_SYSFS_DEPRECATED_V2=y
7CONFIG_BLK_DEV_INITRD=y
7CONFIG_SLAB=y 8CONFIG_SLAB=y
8CONFIG_MODULES=y 9CONFIG_MODULES=y
9CONFIG_MODVERSIONS=y 10CONFIG_MODVERSIONS=y
@@ -27,6 +28,8 @@ CONFIG_IP_PNP_BOOTP=y
27# CONFIG_INET_LRO is not set 28# CONFIG_INET_LRO is not set
28CONFIG_IPV6=y 29CONFIG_IPV6=y
29CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug" 30CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
31CONFIG_DEVTMPFS=y
32CONFIG_DEVTMPFS_MOUNT=y
30# CONFIG_PREVENT_FIRMWARE_BUILD is not set 33# CONFIG_PREVENT_FIRMWARE_BUILD is not set
31CONFIG_PARPORT=y 34CONFIG_PARPORT=y
32CONFIG_PARPORT_PC=y 35CONFIG_PARPORT_PC=y
diff --git a/arch/parisc/configs/c3000_defconfig b/arch/parisc/configs/c3000_defconfig
index 311ca367b622..ec1b014952b6 100644
--- a/arch/parisc/configs/c3000_defconfig
+++ b/arch/parisc/configs/c3000_defconfig
@@ -5,6 +5,7 @@ CONFIG_IKCONFIG=y
5CONFIG_IKCONFIG_PROC=y 5CONFIG_IKCONFIG_PROC=y
6CONFIG_LOG_BUF_SHIFT=16 6CONFIG_LOG_BUF_SHIFT=16
7CONFIG_SYSFS_DEPRECATED_V2=y 7CONFIG_SYSFS_DEPRECATED_V2=y
8CONFIG_BLK_DEV_INITRD=y
8# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set 9# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
9CONFIG_EXPERT=y 10CONFIG_EXPERT=y
10CONFIG_KALLSYMS_ALL=y 11CONFIG_KALLSYMS_ALL=y
@@ -39,6 +40,8 @@ CONFIG_NETFILTER_DEBUG=y
39CONFIG_IP_NF_QUEUE=m 40CONFIG_IP_NF_QUEUE=m
40CONFIG_NET_PKTGEN=m 41CONFIG_NET_PKTGEN=m
41CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug" 42CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
43CONFIG_DEVTMPFS=y
44CONFIG_DEVTMPFS_MOUNT=y
42# CONFIG_STANDALONE is not set 45# CONFIG_STANDALONE is not set
43# CONFIG_PREVENT_FIRMWARE_BUILD is not set 46# CONFIG_PREVENT_FIRMWARE_BUILD is not set
44CONFIG_BLK_DEV_UMEM=m 47CONFIG_BLK_DEV_UMEM=m
diff --git a/arch/parisc/configs/c8000_defconfig b/arch/parisc/configs/c8000_defconfig
index f11006361297..e1c8d2015c89 100644
--- a/arch/parisc/configs/c8000_defconfig
+++ b/arch/parisc/configs/c8000_defconfig
@@ -62,6 +62,8 @@ CONFIG_TIPC=m
62CONFIG_LLC2=m 62CONFIG_LLC2=m
63CONFIG_DNS_RESOLVER=y 63CONFIG_DNS_RESOLVER=y
64CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug" 64CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
65CONFIG_DEVTMPFS=y
66CONFIG_DEVTMPFS_MOUNT=y
65# CONFIG_STANDALONE is not set 67# CONFIG_STANDALONE is not set
66CONFIG_PARPORT=y 68CONFIG_PARPORT=y
67CONFIG_PARPORT_PC=y 69CONFIG_PARPORT_PC=y
diff --git a/arch/parisc/configs/default_defconfig b/arch/parisc/configs/default_defconfig
index dfe88f6c95c4..ba61495e1fa4 100644
--- a/arch/parisc/configs/default_defconfig
+++ b/arch/parisc/configs/default_defconfig
@@ -49,6 +49,8 @@ CONFIG_INET6_ESP=y
49CONFIG_INET6_IPCOMP=y 49CONFIG_INET6_IPCOMP=y
50CONFIG_LLC2=m 50CONFIG_LLC2=m
51CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug" 51CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
52CONFIG_DEVTMPFS=y
53CONFIG_DEVTMPFS_MOUNT=y
52# CONFIG_STANDALONE is not set 54# CONFIG_STANDALONE is not set
53# CONFIG_PREVENT_FIRMWARE_BUILD is not set 55# CONFIG_PREVENT_FIRMWARE_BUILD is not set
54CONFIG_PARPORT=y 56CONFIG_PARPORT=y
diff --git a/arch/parisc/kernel/cache.c b/arch/parisc/kernel/cache.c
index b521c0adf4ec..c035673209f7 100644
--- a/arch/parisc/kernel/cache.c
+++ b/arch/parisc/kernel/cache.c
@@ -602,7 +602,6 @@ flush_cache_page(struct vm_area_struct *vma, unsigned long vmaddr, unsigned long
602 __flush_cache_page(vma, vmaddr, PFN_PHYS(pfn)); 602 __flush_cache_page(vma, vmaddr, PFN_PHYS(pfn));
603 } 603 }
604} 604}
605EXPORT_SYMBOL_GPL(flush_cache_page);
606 605
607#ifdef CONFIG_PARISC_TMPALIAS 606#ifdef CONFIG_PARISC_TMPALIAS
608 607
diff --git a/arch/parisc/kernel/head.S b/arch/parisc/kernel/head.S
index 37aabd772fbb..d2d58258aea6 100644
--- a/arch/parisc/kernel/head.S
+++ b/arch/parisc/kernel/head.S
@@ -195,6 +195,8 @@ common_stext:
195 ldw MEM_PDC_HI(%r0),%r6 195 ldw MEM_PDC_HI(%r0),%r6
196 depd %r6, 31, 32, %r3 /* move to upper word */ 196 depd %r6, 31, 32, %r3 /* move to upper word */
197 197
198 mfctl %cr30,%r6 /* PCX-W2 firmware bug */
199
198 ldo PDC_PSW(%r0),%arg0 /* 21 */ 200 ldo PDC_PSW(%r0),%arg0 /* 21 */
199 ldo PDC_PSW_SET_DEFAULTS(%r0),%arg1 /* 2 */ 201 ldo PDC_PSW_SET_DEFAULTS(%r0),%arg1 /* 2 */
200 ldo PDC_PSW_WIDE_BIT(%r0),%arg2 /* 2 */ 202 ldo PDC_PSW_WIDE_BIT(%r0),%arg2 /* 2 */
@@ -203,6 +205,8 @@ common_stext:
203 copy %r0,%arg3 205 copy %r0,%arg3
204 206
205stext_pdc_ret: 207stext_pdc_ret:
208 mtctl %r6,%cr30 /* restore task thread info */
209
206 /* restore rfi target address*/ 210 /* restore rfi target address*/
207 ldd TI_TASK-THREAD_SZ_ALGN(%sp), %r10 211 ldd TI_TASK-THREAD_SZ_ALGN(%sp), %r10
208 tophys_r1 %r10 212 tophys_r1 %r10
diff --git a/arch/powerpc/net/bpf_jit_comp.c b/arch/powerpc/net/bpf_jit_comp.c
index bf56e33f8257..2345bdb4d917 100644
--- a/arch/powerpc/net/bpf_jit_comp.c
+++ b/arch/powerpc/net/bpf_jit_comp.c
@@ -691,4 +691,5 @@ void bpf_jit_free(struct sk_filter *fp)
691{ 691{
692 if (fp->bpf_func != sk_run_filter) 692 if (fp->bpf_func != sk_run_filter)
693 module_free(NULL, fp->bpf_func); 693 module_free(NULL, fp->bpf_func);
694 kfree(fp);
694} 695}
diff --git a/arch/s390/include/asm/pgtable.h b/arch/s390/include/asm/pgtable.h
index 9b60a36c348d..2204400d0bd5 100644
--- a/arch/s390/include/asm/pgtable.h
+++ b/arch/s390/include/asm/pgtable.h
@@ -748,7 +748,9 @@ static inline void pgste_set_key(pte_t *ptep, pgste_t pgste, pte_t entry)
748 748
749static inline void pgste_set_pte(pte_t *ptep, pte_t entry) 749static inline void pgste_set_pte(pte_t *ptep, pte_t entry)
750{ 750{
751 if (!MACHINE_HAS_ESOP && (pte_val(entry) & _PAGE_WRITE)) { 751 if (!MACHINE_HAS_ESOP &&
752 (pte_val(entry) & _PAGE_PRESENT) &&
753 (pte_val(entry) & _PAGE_WRITE)) {
752 /* 754 /*
753 * Without enhanced suppression-on-protection force 755 * Without enhanced suppression-on-protection force
754 * the dirty bit on for all writable ptes. 756 * the dirty bit on for all writable ptes.
diff --git a/arch/s390/include/asm/timex.h b/arch/s390/include/asm/timex.h
index 8ad8af915032..819b94d22720 100644
--- a/arch/s390/include/asm/timex.h
+++ b/arch/s390/include/asm/timex.h
@@ -71,30 +71,30 @@ static inline void local_tick_enable(unsigned long long comp)
71 71
72typedef unsigned long long cycles_t; 72typedef unsigned long long cycles_t;
73 73
74static inline unsigned long long get_tod_clock(void)
75{
76 unsigned long long clk;
77
78#ifdef CONFIG_HAVE_MARCH_Z9_109_FEATURES
79 asm volatile(".insn s,0xb27c0000,%0" : "=Q" (clk) : : "cc");
80#else
81 asm volatile("stck %0" : "=Q" (clk) : : "cc");
82#endif
83 return clk;
84}
85
86static inline void get_tod_clock_ext(char *clk) 74static inline void get_tod_clock_ext(char *clk)
87{ 75{
88 asm volatile("stcke %0" : "=Q" (*clk) : : "cc"); 76 asm volatile("stcke %0" : "=Q" (*clk) : : "cc");
89} 77}
90 78
91static inline unsigned long long get_tod_clock_xt(void) 79static inline unsigned long long get_tod_clock(void)
92{ 80{
93 unsigned char clk[16]; 81 unsigned char clk[16];
94 get_tod_clock_ext(clk); 82 get_tod_clock_ext(clk);
95 return *((unsigned long long *)&clk[1]); 83 return *((unsigned long long *)&clk[1]);
96} 84}
97 85
86static inline unsigned long long get_tod_clock_fast(void)
87{
88#ifdef CONFIG_HAVE_MARCH_Z9_109_FEATURES
89 unsigned long long clk;
90
91 asm volatile("stckf %0" : "=Q" (clk) : : "cc");
92 return clk;
93#else
94 return get_tod_clock();
95#endif
96}
97
98static inline cycles_t get_cycles(void) 98static inline cycles_t get_cycles(void)
99{ 99{
100 return (cycles_t) get_tod_clock() >> 2; 100 return (cycles_t) get_tod_clock() >> 2;
@@ -125,7 +125,7 @@ extern u64 sched_clock_base_cc;
125 */ 125 */
126static inline unsigned long long get_tod_clock_monotonic(void) 126static inline unsigned long long get_tod_clock_monotonic(void)
127{ 127{
128 return get_tod_clock_xt() - sched_clock_base_cc; 128 return get_tod_clock() - sched_clock_base_cc;
129} 129}
130 130
131/** 131/**
diff --git a/arch/s390/kernel/compat_signal.c b/arch/s390/kernel/compat_signal.c
index 1389b637dae5..adaa9e9478d8 100644
--- a/arch/s390/kernel/compat_signal.c
+++ b/arch/s390/kernel/compat_signal.c
@@ -99,7 +99,7 @@ int copy_siginfo_to_user32(compat_siginfo_t __user *to, siginfo_t *from)
99 break; 99 break;
100 } 100 }
101 } 101 }
102 return err; 102 return err ? -EFAULT : 0;
103} 103}
104 104
105int copy_siginfo_from_user32(siginfo_t *to, compat_siginfo_t __user *from) 105int copy_siginfo_from_user32(siginfo_t *to, compat_siginfo_t __user *from)
@@ -148,7 +148,7 @@ int copy_siginfo_from_user32(siginfo_t *to, compat_siginfo_t __user *from)
148 break; 148 break;
149 } 149 }
150 } 150 }
151 return err; 151 return err ? -EFAULT : 0;
152} 152}
153 153
154static int save_sigregs32(struct pt_regs *regs, _sigregs32 __user *sregs) 154static int save_sigregs32(struct pt_regs *regs, _sigregs32 __user *sregs)
diff --git a/arch/s390/kernel/debug.c b/arch/s390/kernel/debug.c
index f1279dc2e1bc..17d62fe5d7b7 100644
--- a/arch/s390/kernel/debug.c
+++ b/arch/s390/kernel/debug.c
@@ -867,7 +867,7 @@ static inline void
867debug_finish_entry(debug_info_t * id, debug_entry_t* active, int level, 867debug_finish_entry(debug_info_t * id, debug_entry_t* active, int level,
868 int exception) 868 int exception)
869{ 869{
870 active->id.stck = get_tod_clock(); 870 active->id.stck = get_tod_clock_fast();
871 active->id.fields.cpuid = smp_processor_id(); 871 active->id.fields.cpuid = smp_processor_id();
872 active->caller = __builtin_return_address(0); 872 active->caller = __builtin_return_address(0);
873 active->id.fields.exception = exception; 873 active->id.fields.exception = exception;
diff --git a/arch/s390/kvm/interrupt.c b/arch/s390/kvm/interrupt.c
index 7f35cb33e510..7f1f7ac5cf7f 100644
--- a/arch/s390/kvm/interrupt.c
+++ b/arch/s390/kvm/interrupt.c
@@ -385,7 +385,7 @@ static int kvm_cpu_has_interrupt(struct kvm_vcpu *vcpu)
385 } 385 }
386 386
387 if ((!rc) && (vcpu->arch.sie_block->ckc < 387 if ((!rc) && (vcpu->arch.sie_block->ckc <
388 get_tod_clock() + vcpu->arch.sie_block->epoch)) { 388 get_tod_clock_fast() + vcpu->arch.sie_block->epoch)) {
389 if ((!psw_extint_disabled(vcpu)) && 389 if ((!psw_extint_disabled(vcpu)) &&
390 (vcpu->arch.sie_block->gcr[0] & 0x800ul)) 390 (vcpu->arch.sie_block->gcr[0] & 0x800ul))
391 rc = 1; 391 rc = 1;
@@ -425,7 +425,7 @@ int kvm_s390_handle_wait(struct kvm_vcpu *vcpu)
425 goto no_timer; 425 goto no_timer;
426 } 426 }
427 427
428 now = get_tod_clock() + vcpu->arch.sie_block->epoch; 428 now = get_tod_clock_fast() + vcpu->arch.sie_block->epoch;
429 if (vcpu->arch.sie_block->ckc < now) { 429 if (vcpu->arch.sie_block->ckc < now) {
430 __unset_cpu_idle(vcpu); 430 __unset_cpu_idle(vcpu);
431 return 0; 431 return 0;
@@ -515,7 +515,7 @@ void kvm_s390_deliver_pending_interrupts(struct kvm_vcpu *vcpu)
515 } 515 }
516 516
517 if ((vcpu->arch.sie_block->ckc < 517 if ((vcpu->arch.sie_block->ckc <
518 get_tod_clock() + vcpu->arch.sie_block->epoch)) 518 get_tod_clock_fast() + vcpu->arch.sie_block->epoch))
519 __try_deliver_ckc_interrupt(vcpu); 519 __try_deliver_ckc_interrupt(vcpu);
520 520
521 if (atomic_read(&fi->active)) { 521 if (atomic_read(&fi->active)) {
diff --git a/arch/s390/lib/delay.c b/arch/s390/lib/delay.c
index 57c87d7d7ede..a9f3d0042d58 100644
--- a/arch/s390/lib/delay.c
+++ b/arch/s390/lib/delay.c
@@ -44,7 +44,7 @@ static void __udelay_disabled(unsigned long long usecs)
44 do { 44 do {
45 set_clock_comparator(end); 45 set_clock_comparator(end);
46 vtime_stop_cpu(); 46 vtime_stop_cpu();
47 } while (get_tod_clock() < end); 47 } while (get_tod_clock_fast() < end);
48 lockdep_on(); 48 lockdep_on();
49 __ctl_load(cr0, 0, 0); 49 __ctl_load(cr0, 0, 0);
50 __ctl_load(cr6, 6, 6); 50 __ctl_load(cr6, 6, 6);
@@ -55,7 +55,7 @@ static void __udelay_enabled(unsigned long long usecs)
55{ 55{
56 u64 clock_saved, end; 56 u64 clock_saved, end;
57 57
58 end = get_tod_clock() + (usecs << 12); 58 end = get_tod_clock_fast() + (usecs << 12);
59 do { 59 do {
60 clock_saved = 0; 60 clock_saved = 0;
61 if (end < S390_lowcore.clock_comparator) { 61 if (end < S390_lowcore.clock_comparator) {
@@ -65,7 +65,7 @@ static void __udelay_enabled(unsigned long long usecs)
65 vtime_stop_cpu(); 65 vtime_stop_cpu();
66 if (clock_saved) 66 if (clock_saved)
67 local_tick_enable(clock_saved); 67 local_tick_enable(clock_saved);
68 } while (get_tod_clock() < end); 68 } while (get_tod_clock_fast() < end);
69} 69}
70 70
71/* 71/*
@@ -109,8 +109,8 @@ void udelay_simple(unsigned long long usecs)
109{ 109{
110 u64 end; 110 u64 end;
111 111
112 end = get_tod_clock() + (usecs << 12); 112 end = get_tod_clock_fast() + (usecs << 12);
113 while (get_tod_clock() < end) 113 while (get_tod_clock_fast() < end)
114 cpu_relax(); 114 cpu_relax();
115} 115}
116 116
@@ -120,10 +120,10 @@ void __ndelay(unsigned long long nsecs)
120 120
121 nsecs <<= 9; 121 nsecs <<= 9;
122 do_div(nsecs, 125); 122 do_div(nsecs, 125);
123 end = get_tod_clock() + nsecs; 123 end = get_tod_clock_fast() + nsecs;
124 if (nsecs & ~0xfffUL) 124 if (nsecs & ~0xfffUL)
125 __udelay(nsecs >> 12); 125 __udelay(nsecs >> 12);
126 while (get_tod_clock() < end) 126 while (get_tod_clock_fast() < end)
127 barrier(); 127 barrier();
128} 128}
129EXPORT_SYMBOL(__ndelay); 129EXPORT_SYMBOL(__ndelay);
diff --git a/arch/s390/net/bpf_jit_comp.c b/arch/s390/net/bpf_jit_comp.c
index 709239285869..a5df511e27a2 100644
--- a/arch/s390/net/bpf_jit_comp.c
+++ b/arch/s390/net/bpf_jit_comp.c
@@ -881,7 +881,9 @@ void bpf_jit_free(struct sk_filter *fp)
881 struct bpf_binary_header *header = (void *)addr; 881 struct bpf_binary_header *header = (void *)addr;
882 882
883 if (fp->bpf_func == sk_run_filter) 883 if (fp->bpf_func == sk_run_filter)
884 return; 884 goto free_filter;
885 set_memory_rw(addr, header->pages); 885 set_memory_rw(addr, header->pages);
886 module_free(NULL, header); 886 module_free(NULL, header);
887free_filter:
888 kfree(fp);
887} 889}
diff --git a/arch/sparc/net/bpf_jit_comp.c b/arch/sparc/net/bpf_jit_comp.c
index 9c7be59e6f5a..218b6b23c378 100644
--- a/arch/sparc/net/bpf_jit_comp.c
+++ b/arch/sparc/net/bpf_jit_comp.c
@@ -808,4 +808,5 @@ void bpf_jit_free(struct sk_filter *fp)
808{ 808{
809 if (fp->bpf_func != sk_run_filter) 809 if (fp->bpf_func != sk_run_filter)
810 module_free(NULL, fp->bpf_func); 810 module_free(NULL, fp->bpf_func);
811 kfree(fp);
811} 812}
diff --git a/arch/um/kernel/exitcode.c b/arch/um/kernel/exitcode.c
index 829df49dee99..41ebbfebb333 100644
--- a/arch/um/kernel/exitcode.c
+++ b/arch/um/kernel/exitcode.c
@@ -40,9 +40,11 @@ static ssize_t exitcode_proc_write(struct file *file,
40 const char __user *buffer, size_t count, loff_t *pos) 40 const char __user *buffer, size_t count, loff_t *pos)
41{ 41{
42 char *end, buf[sizeof("nnnnn\0")]; 42 char *end, buf[sizeof("nnnnn\0")];
43 size_t size;
43 int tmp; 44 int tmp;
44 45
45 if (copy_from_user(buf, buffer, count)) 46 size = min(count, sizeof(buf));
47 if (copy_from_user(buf, buffer, size))
46 return -EFAULT; 48 return -EFAULT;
47 49
48 tmp = simple_strtol(buf, &end, 0); 50 tmp = simple_strtol(buf, &end, 0);
diff --git a/arch/x86/include/asm/percpu.h b/arch/x86/include/asm/percpu.h
index 0da5200ee79d..b3e18f800302 100644
--- a/arch/x86/include/asm/percpu.h
+++ b/arch/x86/include/asm/percpu.h
@@ -128,7 +128,8 @@ do { \
128do { \ 128do { \
129 typedef typeof(var) pao_T__; \ 129 typedef typeof(var) pao_T__; \
130 const int pao_ID__ = (__builtin_constant_p(val) && \ 130 const int pao_ID__ = (__builtin_constant_p(val) && \
131 ((val) == 1 || (val) == -1)) ? (val) : 0; \ 131 ((val) == 1 || (val) == -1)) ? \
132 (int)(val) : 0; \
132 if (0) { \ 133 if (0) { \
133 pao_T__ pao_tmp__; \ 134 pao_T__ pao_tmp__; \
134 pao_tmp__ = (val); \ 135 pao_tmp__ = (val); \
diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
index 9d8449158cf9..8a87a3224121 100644
--- a/arch/x86/kernel/cpu/perf_event.c
+++ b/arch/x86/kernel/cpu/perf_event.c
@@ -1276,16 +1276,16 @@ void perf_events_lapic_init(void)
1276static int __kprobes 1276static int __kprobes
1277perf_event_nmi_handler(unsigned int cmd, struct pt_regs *regs) 1277perf_event_nmi_handler(unsigned int cmd, struct pt_regs *regs)
1278{ 1278{
1279 int ret;
1280 u64 start_clock; 1279 u64 start_clock;
1281 u64 finish_clock; 1280 u64 finish_clock;
1281 int ret;
1282 1282
1283 if (!atomic_read(&active_events)) 1283 if (!atomic_read(&active_events))
1284 return NMI_DONE; 1284 return NMI_DONE;
1285 1285
1286 start_clock = local_clock(); 1286 start_clock = sched_clock();
1287 ret = x86_pmu.handle_irq(regs); 1287 ret = x86_pmu.handle_irq(regs);
1288 finish_clock = local_clock(); 1288 finish_clock = sched_clock();
1289 1289
1290 perf_sample_event_took(finish_clock - start_clock); 1290 perf_sample_event_took(finish_clock - start_clock);
1291 1291
diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
index a0e2a8a80c94..b2046e4d0b59 100644
--- a/arch/x86/kernel/kvm.c
+++ b/arch/x86/kernel/kvm.c
@@ -609,7 +609,7 @@ static struct dentry *d_kvm_debug;
609 609
610struct dentry *kvm_init_debugfs(void) 610struct dentry *kvm_init_debugfs(void)
611{ 611{
612 d_kvm_debug = debugfs_create_dir("kvm", NULL); 612 d_kvm_debug = debugfs_create_dir("kvm-guest", NULL);
613 if (!d_kvm_debug) 613 if (!d_kvm_debug)
614 printk(KERN_WARNING "Could not create 'kvm' debugfs directory\n"); 614 printk(KERN_WARNING "Could not create 'kvm' debugfs directory\n");
615 615
diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
index ba77ebc2c353..6fcb49ce50a1 100644
--- a/arch/x86/kernel/nmi.c
+++ b/arch/x86/kernel/nmi.c
@@ -113,10 +113,10 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
113 u64 before, delta, whole_msecs; 113 u64 before, delta, whole_msecs;
114 int remainder_ns, decimal_msecs, thishandled; 114 int remainder_ns, decimal_msecs, thishandled;
115 115
116 before = local_clock(); 116 before = sched_clock();
117 thishandled = a->handler(type, regs); 117 thishandled = a->handler(type, regs);
118 handled += thishandled; 118 handled += thishandled;
119 delta = local_clock() - before; 119 delta = sched_clock() - before;
120 trace_nmi_handler(a->handler, (int)delta, thishandled); 120 trace_nmi_handler(a->handler, (int)delta, thishandled);
121 121
122 if (delta < nmi_longest_ns) 122 if (delta < nmi_longest_ns)
diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
index 79c216aa0e2b..516593e1ce33 100644
--- a/arch/x86/net/bpf_jit_comp.c
+++ b/arch/x86/net/bpf_jit_comp.c
@@ -772,13 +772,21 @@ out:
772 return; 772 return;
773} 773}
774 774
775static void bpf_jit_free_deferred(struct work_struct *work)
776{
777 struct sk_filter *fp = container_of(work, struct sk_filter, work);
778 unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
779 struct bpf_binary_header *header = (void *)addr;
780
781 set_memory_rw(addr, header->pages);
782 module_free(NULL, header);
783 kfree(fp);
784}
785
775void bpf_jit_free(struct sk_filter *fp) 786void bpf_jit_free(struct sk_filter *fp)
776{ 787{
777 if (fp->bpf_func != sk_run_filter) { 788 if (fp->bpf_func != sk_run_filter) {
778 unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK; 789 INIT_WORK(&fp->work, bpf_jit_free_deferred);
779 struct bpf_binary_header *header = (void *)addr; 790 schedule_work(&fp->work);
780
781 set_memory_rw(addr, header->pages);
782 module_free(NULL, header);
783 } 791 }
784} 792}
diff --git a/arch/xtensa/kernel/entry.S b/arch/xtensa/kernel/entry.S
index de1dfa18d0a1..21dbe6bdb8ed 100644
--- a/arch/xtensa/kernel/entry.S
+++ b/arch/xtensa/kernel/entry.S
@@ -1122,7 +1122,7 @@ ENDPROC(fast_syscall_spill_registers)
1122 * a3: exctable, original value in excsave1 1122 * a3: exctable, original value in excsave1
1123 */ 1123 */
1124 1124
1125fast_syscall_spill_registers_fixup: 1125ENTRY(fast_syscall_spill_registers_fixup)
1126 1126
1127 rsr a2, windowbase # get current windowbase (a2 is saved) 1127 rsr a2, windowbase # get current windowbase (a2 is saved)
1128 xsr a0, depc # restore depc and a0 1128 xsr a0, depc # restore depc and a0
@@ -1134,22 +1134,26 @@ fast_syscall_spill_registers_fixup:
1134 */ 1134 */
1135 1135
1136 xsr a3, excsave1 # get spill-mask 1136 xsr a3, excsave1 # get spill-mask
1137 slli a2, a3, 1 # shift left by one 1137 slli a3, a3, 1 # shift left by one
1138 1138
1139 slli a3, a2, 32-WSBITS 1139 slli a2, a3, 32-WSBITS
1140 src a2, a2, a3 # a1 = xxwww1yyxxxwww1yy...... 1140 src a2, a3, a2 # a2 = xxwww1yyxxxwww1yy......
1141 wsr a2, windowstart # set corrected windowstart 1141 wsr a2, windowstart # set corrected windowstart
1142 1142
1143 rsr a3, excsave1 1143 srli a3, a3, 1
1144 l32i a2, a3, EXC_TABLE_DOUBLE_SAVE # restore a2 1144 rsr a2, excsave1
1145 l32i a3, a3, EXC_TABLE_PARAM # original WB (in user task) 1145 l32i a2, a2, EXC_TABLE_DOUBLE_SAVE # restore a2
1146 xsr a2, excsave1
1147 s32i a3, a2, EXC_TABLE_DOUBLE_SAVE # save a3
1148 l32i a3, a2, EXC_TABLE_PARAM # original WB (in user task)
1149 xsr a2, excsave1
1146 1150
1147 /* Return to the original (user task) WINDOWBASE. 1151 /* Return to the original (user task) WINDOWBASE.
1148 * We leave the following frame behind: 1152 * We leave the following frame behind:
1149 * a0, a1, a2 same 1153 * a0, a1, a2 same
1150 * a3: trashed (saved in excsave_1) 1154 * a3: trashed (saved in EXC_TABLE_DOUBLE_SAVE)
1151 * depc: depc (we have to return to that address) 1155 * depc: depc (we have to return to that address)
1152 * excsave_1: a3 1156 * excsave_1: exctable
1153 */ 1157 */
1154 1158
1155 wsr a3, windowbase 1159 wsr a3, windowbase
@@ -1159,9 +1163,9 @@ fast_syscall_spill_registers_fixup:
1159 * a0: return address 1163 * a0: return address
1160 * a1: used, stack pointer 1164 * a1: used, stack pointer
1161 * a2: kernel stack pointer 1165 * a2: kernel stack pointer
1162 * a3: available, saved in EXCSAVE_1 1166 * a3: available
1163 * depc: exception address 1167 * depc: exception address
1164 * excsave: a3 1168 * excsave: exctable
1165 * Note: This frame might be the same as above. 1169 * Note: This frame might be the same as above.
1166 */ 1170 */
1167 1171
@@ -1181,9 +1185,12 @@ fast_syscall_spill_registers_fixup:
1181 rsr a0, exccause 1185 rsr a0, exccause
1182 addx4 a0, a0, a3 # find entry in table 1186 addx4 a0, a0, a3 # find entry in table
1183 l32i a0, a0, EXC_TABLE_FAST_USER # load handler 1187 l32i a0, a0, EXC_TABLE_FAST_USER # load handler
1188 l32i a3, a3, EXC_TABLE_DOUBLE_SAVE
1184 jx a0 1189 jx a0
1185 1190
1186fast_syscall_spill_registers_fixup_return: 1191ENDPROC(fast_syscall_spill_registers_fixup)
1192
1193ENTRY(fast_syscall_spill_registers_fixup_return)
1187 1194
1188 /* When we return here, all registers have been restored (a2: DEPC) */ 1195 /* When we return here, all registers have been restored (a2: DEPC) */
1189 1196
@@ -1191,13 +1198,13 @@ fast_syscall_spill_registers_fixup_return:
1191 1198
1192 /* Restore fixup handler. */ 1199 /* Restore fixup handler. */
1193 1200
1194 xsr a3, excsave1 1201 rsr a2, excsave1
1195 movi a2, fast_syscall_spill_registers_fixup 1202 s32i a3, a2, EXC_TABLE_DOUBLE_SAVE
1196 s32i a2, a3, EXC_TABLE_FIXUP 1203 movi a3, fast_syscall_spill_registers_fixup
1197 s32i a0, a3, EXC_TABLE_DOUBLE_SAVE 1204 s32i a3, a2, EXC_TABLE_FIXUP
1198 rsr a2, windowbase 1205 rsr a3, windowbase
1199 s32i a2, a3, EXC_TABLE_PARAM 1206 s32i a3, a2, EXC_TABLE_PARAM
1200 l32i a2, a3, EXC_TABLE_KSTK 1207 l32i a2, a2, EXC_TABLE_KSTK
1201 1208
1202 /* Load WB at the time the exception occurred. */ 1209 /* Load WB at the time the exception occurred. */
1203 1210
@@ -1206,8 +1213,12 @@ fast_syscall_spill_registers_fixup_return:
1206 wsr a3, windowbase 1213 wsr a3, windowbase
1207 rsync 1214 rsync
1208 1215
1216 rsr a3, excsave1
1217 l32i a3, a3, EXC_TABLE_DOUBLE_SAVE
1218
1209 rfde 1219 rfde
1210 1220
1221ENDPROC(fast_syscall_spill_registers_fixup_return)
1211 1222
1212/* 1223/*
1213 * spill all registers. 1224 * spill all registers.
diff --git a/arch/xtensa/kernel/signal.c b/arch/xtensa/kernel/signal.c
index 718eca1850bd..98b67d5f1514 100644
--- a/arch/xtensa/kernel/signal.c
+++ b/arch/xtensa/kernel/signal.c
@@ -341,7 +341,7 @@ static int setup_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
341 341
342 sp = regs->areg[1]; 342 sp = regs->areg[1];
343 343
344 if ((ka->sa.sa_flags & SA_ONSTACK) != 0 && ! on_sig_stack(sp)) { 344 if ((ka->sa.sa_flags & SA_ONSTACK) != 0 && sas_ss_flags(sp) == 0) {
345 sp = current->sas_ss_sp + current->sas_ss_size; 345 sp = current->sas_ss_sp + current->sas_ss_size;
346 } 346 }
347 347
diff --git a/arch/xtensa/platforms/iss/network.c b/arch/xtensa/platforms/iss/network.c
index 56f88b7afe2f..e9e1aad8c271 100644
--- a/arch/xtensa/platforms/iss/network.c
+++ b/arch/xtensa/platforms/iss/network.c
@@ -737,7 +737,8 @@ static int __init iss_net_setup(char *str)
737 return 1; 737 return 1;
738 } 738 }
739 739
740 if ((new = alloc_bootmem(sizeof new)) == NULL) { 740 new = alloc_bootmem(sizeof(*new));
741 if (new == NULL) {
741 printk("Alloc_bootmem failed\n"); 742 printk("Alloc_bootmem failed\n");
742 return 1; 743 return 1;
743 } 744 }
diff --git a/drivers/Kconfig b/drivers/Kconfig
index aa43b911ccef..8f451449abd3 100644
--- a/drivers/Kconfig
+++ b/drivers/Kconfig
@@ -166,4 +166,6 @@ source "drivers/reset/Kconfig"
166 166
167source "drivers/fmc/Kconfig" 167source "drivers/fmc/Kconfig"
168 168
169source "drivers/phy/Kconfig"
170
169endmenu 171endmenu
diff --git a/drivers/Makefile b/drivers/Makefile
index ab93de8297f1..687da899cadb 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -8,6 +8,8 @@
8obj-y += irqchip/ 8obj-y += irqchip/
9obj-y += bus/ 9obj-y += bus/
10 10
11obj-$(CONFIG_GENERIC_PHY) += phy/
12
11# GPIO must come after pinctrl as gpios may need to mux pins etc 13# GPIO must come after pinctrl as gpios may need to mux pins etc
12obj-y += pinctrl/ 14obj-y += pinctrl/
13obj-y += gpio/ 15obj-y += gpio/
diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
index 9d715ae5ff6b..8e28f923cf7f 100644
--- a/drivers/ata/ahci.c
+++ b/drivers/ata/ahci.c
@@ -1343,7 +1343,7 @@ static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
1343 if (!(hpriv->cap & HOST_CAP_SSS) || ahci_ignore_sss) 1343 if (!(hpriv->cap & HOST_CAP_SSS) || ahci_ignore_sss)
1344 host->flags |= ATA_HOST_PARALLEL_SCAN; 1344 host->flags |= ATA_HOST_PARALLEL_SCAN;
1345 else 1345 else
1346 printk(KERN_INFO "ahci: SSS flag set, parallel bus scan disabled\n"); 1346 dev_info(&pdev->dev, "SSS flag set, parallel bus scan disabled\n");
1347 1347
1348 if (pi.flags & ATA_FLAG_EM) 1348 if (pi.flags & ATA_FLAG_EM)
1349 ahci_reset_em(host); 1349 ahci_reset_em(host);
diff --git a/drivers/ata/ahci_platform.c b/drivers/ata/ahci_platform.c
index 2daaee05cab1..7d3b85385bfc 100644
--- a/drivers/ata/ahci_platform.c
+++ b/drivers/ata/ahci_platform.c
@@ -184,7 +184,7 @@ static int ahci_probe(struct platform_device *pdev)
184 if (!(hpriv->cap & HOST_CAP_SSS) || ahci_ignore_sss) 184 if (!(hpriv->cap & HOST_CAP_SSS) || ahci_ignore_sss)
185 host->flags |= ATA_HOST_PARALLEL_SCAN; 185 host->flags |= ATA_HOST_PARALLEL_SCAN;
186 else 186 else
187 printk(KERN_INFO "ahci: SSS flag set, parallel bus scan disabled\n"); 187 dev_info(dev, "SSS flag set, parallel bus scan disabled\n");
188 188
189 if (pi.flags & ATA_FLAG_EM) 189 if (pi.flags & ATA_FLAG_EM)
190 ahci_reset_em(host); 190 ahci_reset_em(host);
diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
index acfd0f711069..aaac4fb0d564 100644
--- a/drivers/ata/libahci.c
+++ b/drivers/ata/libahci.c
@@ -778,8 +778,16 @@ static void ahci_start_port(struct ata_port *ap)
778 rc = ap->ops->transmit_led_message(ap, 778 rc = ap->ops->transmit_led_message(ap,
779 emp->led_state, 779 emp->led_state,
780 4); 780 4);
781 /*
782 * If busy, give a breather but do not
783 * release EH ownership by using msleep()
784 * instead of ata_msleep(). EM Transmit
785 * bit is busy for the whole host and
786 * releasing ownership will cause other
787 * ports to fail the same way.
788 */
781 if (rc == -EBUSY) 789 if (rc == -EBUSY)
782 ata_msleep(ap, 1); 790 msleep(1);
783 else 791 else
784 break; 792 break;
785 } 793 }
diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c
index c69fcce505c0..370462fa8e01 100644
--- a/drivers/ata/libata-eh.c
+++ b/drivers/ata/libata-eh.c
@@ -1322,14 +1322,14 @@ void ata_eh_qc_complete(struct ata_queued_cmd *qc)
1322 * should be retried. To be used from EH. 1322 * should be retried. To be used from EH.
1323 * 1323 *
1324 * SCSI midlayer limits the number of retries to scmd->allowed. 1324 * SCSI midlayer limits the number of retries to scmd->allowed.
1325 * scmd->retries is decremented for commands which get retried 1325 * scmd->allowed is incremented for commands which get retried
1326 * due to unrelated failures (qc->err_mask is zero). 1326 * due to unrelated failures (qc->err_mask is zero).
1327 */ 1327 */
1328void ata_eh_qc_retry(struct ata_queued_cmd *qc) 1328void ata_eh_qc_retry(struct ata_queued_cmd *qc)
1329{ 1329{
1330 struct scsi_cmnd *scmd = qc->scsicmd; 1330 struct scsi_cmnd *scmd = qc->scsicmd;
1331 if (!qc->err_mask && scmd->retries) 1331 if (!qc->err_mask)
1332 scmd->retries--; 1332 scmd->allowed++;
1333 __ata_eh_qc_complete(qc); 1333 __ata_eh_qc_complete(qc);
1334} 1334}
1335 1335
diff --git a/drivers/ata/pata_isapnp.c b/drivers/ata/pata_isapnp.c
index 4bceb8803a10..b33d1f99b3a4 100644
--- a/drivers/ata/pata_isapnp.c
+++ b/drivers/ata/pata_isapnp.c
@@ -78,7 +78,7 @@ static int isapnp_init_one(struct pnp_dev *idev, const struct pnp_device_id *dev
78 78
79 ap->ioaddr.cmd_addr = cmd_addr; 79 ap->ioaddr.cmd_addr = cmd_addr;
80 80
81 if (pnp_port_valid(idev, 1) == 0) { 81 if (pnp_port_valid(idev, 1)) {
82 ctl_addr = devm_ioport_map(&idev->dev, 82 ctl_addr = devm_ioport_map(&idev->dev,
83 pnp_port_start(idev, 1), 1); 83 pnp_port_start(idev, 1), 1);
84 ap->ioaddr.altstatus_addr = ctl_addr; 84 ap->ioaddr.altstatus_addr = ctl_addr;
diff --git a/drivers/clk/clk-nomadik.c b/drivers/clk/clk-nomadik.c
index 51410c2ac2cb..4d978a3c88f7 100644
--- a/drivers/clk/clk-nomadik.c
+++ b/drivers/clk/clk-nomadik.c
@@ -27,6 +27,14 @@
27 */ 27 */
28 28
29#define SRC_CR 0x00U 29#define SRC_CR 0x00U
30#define SRC_CR_T0_ENSEL BIT(15)
31#define SRC_CR_T1_ENSEL BIT(17)
32#define SRC_CR_T2_ENSEL BIT(19)
33#define SRC_CR_T3_ENSEL BIT(21)
34#define SRC_CR_T4_ENSEL BIT(23)
35#define SRC_CR_T5_ENSEL BIT(25)
36#define SRC_CR_T6_ENSEL BIT(27)
37#define SRC_CR_T7_ENSEL BIT(29)
30#define SRC_XTALCR 0x0CU 38#define SRC_XTALCR 0x0CU
31#define SRC_XTALCR_XTALTIMEN BIT(20) 39#define SRC_XTALCR_XTALTIMEN BIT(20)
32#define SRC_XTALCR_SXTALDIS BIT(19) 40#define SRC_XTALCR_SXTALDIS BIT(19)
@@ -543,6 +551,19 @@ void __init nomadik_clk_init(void)
543 __func__, np->name); 551 __func__, np->name);
544 return; 552 return;
545 } 553 }
554
555 /* Set all timers to use the 2.4 MHz TIMCLK */
556 val = readl(src_base + SRC_CR);
557 val |= SRC_CR_T0_ENSEL;
558 val |= SRC_CR_T1_ENSEL;
559 val |= SRC_CR_T2_ENSEL;
560 val |= SRC_CR_T3_ENSEL;
561 val |= SRC_CR_T4_ENSEL;
562 val |= SRC_CR_T5_ENSEL;
563 val |= SRC_CR_T6_ENSEL;
564 val |= SRC_CR_T7_ENSEL;
565 writel(val, src_base + SRC_CR);
566
546 val = readl(src_base + SRC_XTALCR); 567 val = readl(src_base + SRC_XTALCR);
547 pr_info("SXTALO is %s\n", 568 pr_info("SXTALO is %s\n",
548 (val & SRC_XTALCR_SXTALDIS) ? "disabled" : "enabled"); 569 (val & SRC_XTALCR_SXTALDIS) ? "disabled" : "enabled");
diff --git a/drivers/clk/mvebu/armada-370.c b/drivers/clk/mvebu/armada-370.c
index fc777bdc1886..81a202d12a7a 100644
--- a/drivers/clk/mvebu/armada-370.c
+++ b/drivers/clk/mvebu/armada-370.c
@@ -39,8 +39,8 @@ static const struct coreclk_ratio a370_coreclk_ratios[] __initconst = {
39}; 39};
40 40
41static const u32 a370_tclk_freqs[] __initconst = { 41static const u32 a370_tclk_freqs[] __initconst = {
42 16600000, 42 166000000,
43 20000000, 43 200000000,
44}; 44};
45 45
46static u32 __init a370_get_tclk_freq(void __iomem *sar) 46static u32 __init a370_get_tclk_freq(void __iomem *sar)
diff --git a/drivers/clk/socfpga/clk.c b/drivers/clk/socfpga/clk.c
index 5bb848cac6ec..81dd31a686df 100644
--- a/drivers/clk/socfpga/clk.c
+++ b/drivers/clk/socfpga/clk.c
@@ -49,7 +49,7 @@
49#define SOCFPGA_L4_SP_CLK "l4_sp_clk" 49#define SOCFPGA_L4_SP_CLK "l4_sp_clk"
50#define SOCFPGA_NAND_CLK "nand_clk" 50#define SOCFPGA_NAND_CLK "nand_clk"
51#define SOCFPGA_NAND_X_CLK "nand_x_clk" 51#define SOCFPGA_NAND_X_CLK "nand_x_clk"
52#define SOCFPGA_MMC_CLK "mmc_clk" 52#define SOCFPGA_MMC_CLK "sdmmc_clk"
53#define SOCFPGA_DB_CLK "gpio_db_clk" 53#define SOCFPGA_DB_CLK "gpio_db_clk"
54 54
55#define div_mask(width) ((1 << (width)) - 1) 55#define div_mask(width) ((1 << (width)) - 1)
diff --git a/drivers/clk/versatile/clk-icst.c b/drivers/clk/versatile/clk-icst.c
index 67ccf4aa7277..f5e4c21b301f 100644
--- a/drivers/clk/versatile/clk-icst.c
+++ b/drivers/clk/versatile/clk-icst.c
@@ -107,7 +107,7 @@ static int icst_set_rate(struct clk_hw *hw, unsigned long rate,
107 107
108 vco = icst_hz_to_vco(icst->params, rate); 108 vco = icst_hz_to_vco(icst->params, rate);
109 icst->rate = icst_hz(icst->params, vco); 109 icst->rate = icst_hz(icst->params, vco);
110 vco_set(icst->vcoreg, icst->lockreg, vco); 110 vco_set(icst->lockreg, icst->vcoreg, vco);
111 return 0; 111 return 0;
112} 112}
113 113
diff --git a/drivers/connector/cn_proc.c b/drivers/connector/cn_proc.c
index 08ae128cce9b..c73fc2b74de2 100644
--- a/drivers/connector/cn_proc.c
+++ b/drivers/connector/cn_proc.c
@@ -65,6 +65,7 @@ void proc_fork_connector(struct task_struct *task)
65 65
66 msg = (struct cn_msg *)buffer; 66 msg = (struct cn_msg *)buffer;
67 ev = (struct proc_event *)msg->data; 67 ev = (struct proc_event *)msg->data;
68 memset(&ev->event_data, 0, sizeof(ev->event_data));
68 get_seq(&msg->seq, &ev->cpu); 69 get_seq(&msg->seq, &ev->cpu);
69 ktime_get_ts(&ts); /* get high res monotonic timestamp */ 70 ktime_get_ts(&ts); /* get high res monotonic timestamp */
70 put_unaligned(timespec_to_ns(&ts), (__u64 *)&ev->timestamp_ns); 71 put_unaligned(timespec_to_ns(&ts), (__u64 *)&ev->timestamp_ns);
@@ -80,6 +81,7 @@ void proc_fork_connector(struct task_struct *task)
80 memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id)); 81 memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id));
81 msg->ack = 0; /* not used */ 82 msg->ack = 0; /* not used */
82 msg->len = sizeof(*ev); 83 msg->len = sizeof(*ev);
84 msg->flags = 0; /* not used */
83 /* If cn_netlink_send() failed, the data is not sent */ 85 /* If cn_netlink_send() failed, the data is not sent */
84 cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL); 86 cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL);
85} 87}
@@ -96,6 +98,7 @@ void proc_exec_connector(struct task_struct *task)
96 98
97 msg = (struct cn_msg *)buffer; 99 msg = (struct cn_msg *)buffer;
98 ev = (struct proc_event *)msg->data; 100 ev = (struct proc_event *)msg->data;
101 memset(&ev->event_data, 0, sizeof(ev->event_data));
99 get_seq(&msg->seq, &ev->cpu); 102 get_seq(&msg->seq, &ev->cpu);
100 ktime_get_ts(&ts); /* get high res monotonic timestamp */ 103 ktime_get_ts(&ts); /* get high res monotonic timestamp */
101 put_unaligned(timespec_to_ns(&ts), (__u64 *)&ev->timestamp_ns); 104 put_unaligned(timespec_to_ns(&ts), (__u64 *)&ev->timestamp_ns);
@@ -106,6 +109,7 @@ void proc_exec_connector(struct task_struct *task)
106 memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id)); 109 memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id));
107 msg->ack = 0; /* not used */ 110 msg->ack = 0; /* not used */
108 msg->len = sizeof(*ev); 111 msg->len = sizeof(*ev);
112 msg->flags = 0; /* not used */
109 cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL); 113 cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL);
110} 114}
111 115
@@ -122,6 +126,7 @@ void proc_id_connector(struct task_struct *task, int which_id)
122 126
123 msg = (struct cn_msg *)buffer; 127 msg = (struct cn_msg *)buffer;
124 ev = (struct proc_event *)msg->data; 128 ev = (struct proc_event *)msg->data;
129 memset(&ev->event_data, 0, sizeof(ev->event_data));
125 ev->what = which_id; 130 ev->what = which_id;
126 ev->event_data.id.process_pid = task->pid; 131 ev->event_data.id.process_pid = task->pid;
127 ev->event_data.id.process_tgid = task->tgid; 132 ev->event_data.id.process_tgid = task->tgid;
@@ -145,6 +150,7 @@ void proc_id_connector(struct task_struct *task, int which_id)
145 memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id)); 150 memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id));
146 msg->ack = 0; /* not used */ 151 msg->ack = 0; /* not used */
147 msg->len = sizeof(*ev); 152 msg->len = sizeof(*ev);
153 msg->flags = 0; /* not used */
148 cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL); 154 cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL);
149} 155}
150 156
@@ -160,6 +166,7 @@ void proc_sid_connector(struct task_struct *task)
160 166
161 msg = (struct cn_msg *)buffer; 167 msg = (struct cn_msg *)buffer;
162 ev = (struct proc_event *)msg->data; 168 ev = (struct proc_event *)msg->data;
169 memset(&ev->event_data, 0, sizeof(ev->event_data));
163 get_seq(&msg->seq, &ev->cpu); 170 get_seq(&msg->seq, &ev->cpu);
164 ktime_get_ts(&ts); /* get high res monotonic timestamp */ 171 ktime_get_ts(&ts); /* get high res monotonic timestamp */
165 put_unaligned(timespec_to_ns(&ts), (__u64 *)&ev->timestamp_ns); 172 put_unaligned(timespec_to_ns(&ts), (__u64 *)&ev->timestamp_ns);
@@ -170,6 +177,7 @@ void proc_sid_connector(struct task_struct *task)
170 memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id)); 177 memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id));
171 msg->ack = 0; /* not used */ 178 msg->ack = 0; /* not used */
172 msg->len = sizeof(*ev); 179 msg->len = sizeof(*ev);
180 msg->flags = 0; /* not used */
173 cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL); 181 cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL);
174} 182}
175 183
@@ -185,6 +193,7 @@ void proc_ptrace_connector(struct task_struct *task, int ptrace_id)
185 193
186 msg = (struct cn_msg *)buffer; 194 msg = (struct cn_msg *)buffer;
187 ev = (struct proc_event *)msg->data; 195 ev = (struct proc_event *)msg->data;
196 memset(&ev->event_data, 0, sizeof(ev->event_data));
188 get_seq(&msg->seq, &ev->cpu); 197 get_seq(&msg->seq, &ev->cpu);
189 ktime_get_ts(&ts); /* get high res monotonic timestamp */ 198 ktime_get_ts(&ts); /* get high res monotonic timestamp */
190 put_unaligned(timespec_to_ns(&ts), (__u64 *)&ev->timestamp_ns); 199 put_unaligned(timespec_to_ns(&ts), (__u64 *)&ev->timestamp_ns);
@@ -203,6 +212,7 @@ void proc_ptrace_connector(struct task_struct *task, int ptrace_id)
203 memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id)); 212 memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id));
204 msg->ack = 0; /* not used */ 213 msg->ack = 0; /* not used */
205 msg->len = sizeof(*ev); 214 msg->len = sizeof(*ev);
215 msg->flags = 0; /* not used */
206 cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL); 216 cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL);
207} 217}
208 218
@@ -218,6 +228,7 @@ void proc_comm_connector(struct task_struct *task)
218 228
219 msg = (struct cn_msg *)buffer; 229 msg = (struct cn_msg *)buffer;
220 ev = (struct proc_event *)msg->data; 230 ev = (struct proc_event *)msg->data;
231 memset(&ev->event_data, 0, sizeof(ev->event_data));
221 get_seq(&msg->seq, &ev->cpu); 232 get_seq(&msg->seq, &ev->cpu);
222 ktime_get_ts(&ts); /* get high res monotonic timestamp */ 233 ktime_get_ts(&ts); /* get high res monotonic timestamp */
223 put_unaligned(timespec_to_ns(&ts), (__u64 *)&ev->timestamp_ns); 234 put_unaligned(timespec_to_ns(&ts), (__u64 *)&ev->timestamp_ns);
@@ -229,6 +240,7 @@ void proc_comm_connector(struct task_struct *task)
229 memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id)); 240 memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id));
230 msg->ack = 0; /* not used */ 241 msg->ack = 0; /* not used */
231 msg->len = sizeof(*ev); 242 msg->len = sizeof(*ev);
243 msg->flags = 0; /* not used */
232 cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL); 244 cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL);
233} 245}
234 246
@@ -244,6 +256,7 @@ void proc_coredump_connector(struct task_struct *task)
244 256
245 msg = (struct cn_msg *)buffer; 257 msg = (struct cn_msg *)buffer;
246 ev = (struct proc_event *)msg->data; 258 ev = (struct proc_event *)msg->data;
259 memset(&ev->event_data, 0, sizeof(ev->event_data));
247 get_seq(&msg->seq, &ev->cpu); 260 get_seq(&msg->seq, &ev->cpu);
248 ktime_get_ts(&ts); /* get high res monotonic timestamp */ 261 ktime_get_ts(&ts); /* get high res monotonic timestamp */
249 put_unaligned(timespec_to_ns(&ts), (__u64 *)&ev->timestamp_ns); 262 put_unaligned(timespec_to_ns(&ts), (__u64 *)&ev->timestamp_ns);
@@ -254,6 +267,7 @@ void proc_coredump_connector(struct task_struct *task)
254 memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id)); 267 memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id));
255 msg->ack = 0; /* not used */ 268 msg->ack = 0; /* not used */
256 msg->len = sizeof(*ev); 269 msg->len = sizeof(*ev);
270 msg->flags = 0; /* not used */
257 cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL); 271 cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL);
258} 272}
259 273
@@ -269,6 +283,7 @@ void proc_exit_connector(struct task_struct *task)
269 283
270 msg = (struct cn_msg *)buffer; 284 msg = (struct cn_msg *)buffer;
271 ev = (struct proc_event *)msg->data; 285 ev = (struct proc_event *)msg->data;
286 memset(&ev->event_data, 0, sizeof(ev->event_data));
272 get_seq(&msg->seq, &ev->cpu); 287 get_seq(&msg->seq, &ev->cpu);
273 ktime_get_ts(&ts); /* get high res monotonic timestamp */ 288 ktime_get_ts(&ts); /* get high res monotonic timestamp */
274 put_unaligned(timespec_to_ns(&ts), (__u64 *)&ev->timestamp_ns); 289 put_unaligned(timespec_to_ns(&ts), (__u64 *)&ev->timestamp_ns);
@@ -281,6 +296,7 @@ void proc_exit_connector(struct task_struct *task)
281 memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id)); 296 memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id));
282 msg->ack = 0; /* not used */ 297 msg->ack = 0; /* not used */
283 msg->len = sizeof(*ev); 298 msg->len = sizeof(*ev);
299 msg->flags = 0; /* not used */
284 cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL); 300 cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL);
285} 301}
286 302
@@ -304,6 +320,7 @@ static void cn_proc_ack(int err, int rcvd_seq, int rcvd_ack)
304 320
305 msg = (struct cn_msg *)buffer; 321 msg = (struct cn_msg *)buffer;
306 ev = (struct proc_event *)msg->data; 322 ev = (struct proc_event *)msg->data;
323 memset(&ev->event_data, 0, sizeof(ev->event_data));
307 msg->seq = rcvd_seq; 324 msg->seq = rcvd_seq;
308 ktime_get_ts(&ts); /* get high res monotonic timestamp */ 325 ktime_get_ts(&ts); /* get high res monotonic timestamp */
309 put_unaligned(timespec_to_ns(&ts), (__u64 *)&ev->timestamp_ns); 326 put_unaligned(timespec_to_ns(&ts), (__u64 *)&ev->timestamp_ns);
@@ -313,6 +330,7 @@ static void cn_proc_ack(int err, int rcvd_seq, int rcvd_ack)
313 memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id)); 330 memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id));
314 msg->ack = rcvd_ack + 1; 331 msg->ack = rcvd_ack + 1;
315 msg->len = sizeof(*ev); 332 msg->len = sizeof(*ev);
333 msg->flags = 0; /* not used */
316 cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL); 334 cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL);
317} 335}
318 336
diff --git a/drivers/connector/connector.c b/drivers/connector/connector.c
index 6ecfa758942c..a36749f1e44a 100644
--- a/drivers/connector/connector.c
+++ b/drivers/connector/connector.c
@@ -109,7 +109,7 @@ int cn_netlink_send(struct cn_msg *msg, u32 __group, gfp_t gfp_mask)
109 109
110 data = nlmsg_data(nlh); 110 data = nlmsg_data(nlh);
111 111
112 memcpy(data, msg, sizeof(*data) + msg->len); 112 memcpy(data, msg, size);
113 113
114 NETLINK_CB(skb).dst_group = group; 114 NETLINK_CB(skb).dst_group = group;
115 115
@@ -157,17 +157,18 @@ static int cn_call_callback(struct sk_buff *skb)
157static void cn_rx_skb(struct sk_buff *__skb) 157static void cn_rx_skb(struct sk_buff *__skb)
158{ 158{
159 struct nlmsghdr *nlh; 159 struct nlmsghdr *nlh;
160 int err;
161 struct sk_buff *skb; 160 struct sk_buff *skb;
161 int len, err;
162 162
163 skb = skb_get(__skb); 163 skb = skb_get(__skb);
164 164
165 if (skb->len >= NLMSG_HDRLEN) { 165 if (skb->len >= NLMSG_HDRLEN) {
166 nlh = nlmsg_hdr(skb); 166 nlh = nlmsg_hdr(skb);
167 len = nlmsg_len(nlh);
167 168
168 if (nlh->nlmsg_len < sizeof(struct cn_msg) || 169 if (len < (int)sizeof(struct cn_msg) ||
169 skb->len < nlh->nlmsg_len || 170 skb->len < nlh->nlmsg_len ||
170 nlh->nlmsg_len > CONNECTOR_MAX_MSG_SIZE) { 171 len > CONNECTOR_MAX_MSG_SIZE) {
171 kfree_skb(skb); 172 kfree_skb(skb);
172 return; 173 return;
173 } 174 }
diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
index d2c3253e015e..506fd23c7550 100644
--- a/drivers/cpufreq/acpi-cpufreq.c
+++ b/drivers/cpufreq/acpi-cpufreq.c
@@ -986,12 +986,12 @@ static int __init acpi_cpufreq_init(void)
986{ 986{
987 int ret; 987 int ret;
988 988
989 if (acpi_disabled)
990 return -ENODEV;
991
989 /* don't keep reloading if cpufreq_driver exists */ 992 /* don't keep reloading if cpufreq_driver exists */
990 if (cpufreq_get_current_driver()) 993 if (cpufreq_get_current_driver())
991 return 0; 994 return -EEXIST;
992
993 if (acpi_disabled)
994 return 0;
995 995
996 pr_debug("acpi_cpufreq_init\n"); 996 pr_debug("acpi_cpufreq_init\n");
997 997
diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
index badf6206b2b2..eb3fdc755000 100644
--- a/drivers/cpufreq/intel_pstate.c
+++ b/drivers/cpufreq/intel_pstate.c
@@ -48,7 +48,7 @@ static inline int32_t div_fp(int32_t x, int32_t y)
48} 48}
49 49
50struct sample { 50struct sample {
51 int core_pct_busy; 51 int32_t core_pct_busy;
52 u64 aperf; 52 u64 aperf;
53 u64 mperf; 53 u64 mperf;
54 int freq; 54 int freq;
@@ -68,7 +68,7 @@ struct _pid {
68 int32_t i_gain; 68 int32_t i_gain;
69 int32_t d_gain; 69 int32_t d_gain;
70 int deadband; 70 int deadband;
71 int last_err; 71 int32_t last_err;
72}; 72};
73 73
74struct cpudata { 74struct cpudata {
@@ -153,16 +153,15 @@ static inline void pid_d_gain_set(struct _pid *pid, int percent)
153 pid->d_gain = div_fp(int_tofp(percent), int_tofp(100)); 153 pid->d_gain = div_fp(int_tofp(percent), int_tofp(100));
154} 154}
155 155
156static signed int pid_calc(struct _pid *pid, int busy) 156static signed int pid_calc(struct _pid *pid, int32_t busy)
157{ 157{
158 signed int err, result; 158 signed int result;
159 int32_t pterm, dterm, fp_error; 159 int32_t pterm, dterm, fp_error;
160 int32_t integral_limit; 160 int32_t integral_limit;
161 161
162 err = pid->setpoint - busy; 162 fp_error = int_tofp(pid->setpoint) - busy;
163 fp_error = int_tofp(err);
164 163
165 if (abs(err) <= pid->deadband) 164 if (abs(fp_error) <= int_tofp(pid->deadband))
166 return 0; 165 return 0;
167 166
168 pterm = mul_fp(pid->p_gain, fp_error); 167 pterm = mul_fp(pid->p_gain, fp_error);
@@ -176,8 +175,8 @@ static signed int pid_calc(struct _pid *pid, int busy)
176 if (pid->integral < -integral_limit) 175 if (pid->integral < -integral_limit)
177 pid->integral = -integral_limit; 176 pid->integral = -integral_limit;
178 177
179 dterm = mul_fp(pid->d_gain, (err - pid->last_err)); 178 dterm = mul_fp(pid->d_gain, fp_error - pid->last_err);
180 pid->last_err = err; 179 pid->last_err = fp_error;
181 180
182 result = pterm + mul_fp(pid->integral, pid->i_gain) + dterm; 181 result = pterm + mul_fp(pid->integral, pid->i_gain) + dterm;
183 182
@@ -367,12 +366,13 @@ static int intel_pstate_turbo_pstate(void)
367static void intel_pstate_get_min_max(struct cpudata *cpu, int *min, int *max) 366static void intel_pstate_get_min_max(struct cpudata *cpu, int *min, int *max)
368{ 367{
369 int max_perf = cpu->pstate.turbo_pstate; 368 int max_perf = cpu->pstate.turbo_pstate;
369 int max_perf_adj;
370 int min_perf; 370 int min_perf;
371 if (limits.no_turbo) 371 if (limits.no_turbo)
372 max_perf = cpu->pstate.max_pstate; 372 max_perf = cpu->pstate.max_pstate;
373 373
374 max_perf = fp_toint(mul_fp(int_tofp(max_perf), limits.max_perf)); 374 max_perf_adj = fp_toint(mul_fp(int_tofp(max_perf), limits.max_perf));
375 *max = clamp_t(int, max_perf, 375 *max = clamp_t(int, max_perf_adj,
376 cpu->pstate.min_pstate, cpu->pstate.turbo_pstate); 376 cpu->pstate.min_pstate, cpu->pstate.turbo_pstate);
377 377
378 min_perf = fp_toint(mul_fp(int_tofp(max_perf), limits.min_perf)); 378 min_perf = fp_toint(mul_fp(int_tofp(max_perf), limits.min_perf));
@@ -436,8 +436,9 @@ static inline void intel_pstate_calc_busy(struct cpudata *cpu,
436 struct sample *sample) 436 struct sample *sample)
437{ 437{
438 u64 core_pct; 438 u64 core_pct;
439 core_pct = div64_u64(sample->aperf * 100, sample->mperf); 439 core_pct = div64_u64(int_tofp(sample->aperf * 100),
440 sample->freq = cpu->pstate.max_pstate * core_pct * 1000; 440 sample->mperf);
441 sample->freq = fp_toint(cpu->pstate.max_pstate * core_pct * 1000);
441 442
442 sample->core_pct_busy = core_pct; 443 sample->core_pct_busy = core_pct;
443} 444}
@@ -469,22 +470,19 @@ static inline void intel_pstate_set_sample_time(struct cpudata *cpu)
469 mod_timer_pinned(&cpu->timer, jiffies + delay); 470 mod_timer_pinned(&cpu->timer, jiffies + delay);
470} 471}
471 472
472static inline int intel_pstate_get_scaled_busy(struct cpudata *cpu) 473static inline int32_t intel_pstate_get_scaled_busy(struct cpudata *cpu)
473{ 474{
474 int32_t busy_scaled;
475 int32_t core_busy, max_pstate, current_pstate; 475 int32_t core_busy, max_pstate, current_pstate;
476 476
477 core_busy = int_tofp(cpu->samples[cpu->sample_ptr].core_pct_busy); 477 core_busy = cpu->samples[cpu->sample_ptr].core_pct_busy;
478 max_pstate = int_tofp(cpu->pstate.max_pstate); 478 max_pstate = int_tofp(cpu->pstate.max_pstate);
479 current_pstate = int_tofp(cpu->pstate.current_pstate); 479 current_pstate = int_tofp(cpu->pstate.current_pstate);
480 busy_scaled = mul_fp(core_busy, div_fp(max_pstate, current_pstate)); 480 return mul_fp(core_busy, div_fp(max_pstate, current_pstate));
481
482 return fp_toint(busy_scaled);
483} 481}
484 482
485static inline void intel_pstate_adjust_busy_pstate(struct cpudata *cpu) 483static inline void intel_pstate_adjust_busy_pstate(struct cpudata *cpu)
486{ 484{
487 int busy_scaled; 485 int32_t busy_scaled;
488 struct _pid *pid; 486 struct _pid *pid;
489 signed int ctl = 0; 487 signed int ctl = 0;
490 int steps; 488 int steps;
diff --git a/drivers/dma/edma.c b/drivers/dma/edma.c
index 3519111c566b..10b577fcf48d 100644
--- a/drivers/dma/edma.c
+++ b/drivers/dma/edma.c
@@ -305,6 +305,7 @@ static struct dma_async_tx_descriptor *edma_prep_slave_sg(
305 edma_alloc_slot(EDMA_CTLR(echan->ch_num), 305 edma_alloc_slot(EDMA_CTLR(echan->ch_num),
306 EDMA_SLOT_ANY); 306 EDMA_SLOT_ANY);
307 if (echan->slot[i] < 0) { 307 if (echan->slot[i] < 0) {
308 kfree(edesc);
308 dev_err(dev, "Failed to allocate slot\n"); 309 dev_err(dev, "Failed to allocate slot\n");
309 kfree(edesc); 310 kfree(edesc);
310 return NULL; 311 return NULL;
@@ -346,6 +347,7 @@ static struct dma_async_tx_descriptor *edma_prep_slave_sg(
346 ccnt = sg_dma_len(sg) / (acnt * bcnt); 347 ccnt = sg_dma_len(sg) / (acnt * bcnt);
347 if (ccnt > (SZ_64K - 1)) { 348 if (ccnt > (SZ_64K - 1)) {
348 dev_err(dev, "Exceeded max SG segment size\n"); 349 dev_err(dev, "Exceeded max SG segment size\n");
350 kfree(edesc);
349 return NULL; 351 return NULL;
350 } 352 }
351 cidx = acnt * bcnt; 353 cidx = acnt * bcnt;
diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
index e572dd20bdee..fe58d0833a11 100644
--- a/drivers/gpu/drm/drm_drv.c
+++ b/drivers/gpu/drm/drm_drv.c
@@ -61,7 +61,7 @@ static int drm_version(struct drm_device *dev, void *data,
61 61
62/** Ioctl table */ 62/** Ioctl table */
63static const struct drm_ioctl_desc drm_ioctls[] = { 63static const struct drm_ioctl_desc drm_ioctls[] = {
64 DRM_IOCTL_DEF(DRM_IOCTL_VERSION, drm_version, DRM_UNLOCKED), 64 DRM_IOCTL_DEF(DRM_IOCTL_VERSION, drm_version, DRM_UNLOCKED|DRM_RENDER_ALLOW),
65 DRM_IOCTL_DEF(DRM_IOCTL_GET_UNIQUE, drm_getunique, 0), 65 DRM_IOCTL_DEF(DRM_IOCTL_GET_UNIQUE, drm_getunique, 0),
66 DRM_IOCTL_DEF(DRM_IOCTL_GET_MAGIC, drm_getmagic, 0), 66 DRM_IOCTL_DEF(DRM_IOCTL_GET_MAGIC, drm_getmagic, 0),
67 DRM_IOCTL_DEF(DRM_IOCTL_IRQ_BUSID, drm_irq_by_busid, DRM_MASTER|DRM_ROOT_ONLY), 67 DRM_IOCTL_DEF(DRM_IOCTL_IRQ_BUSID, drm_irq_by_busid, DRM_MASTER|DRM_ROOT_ONLY),
@@ -402,9 +402,16 @@ long drm_ioctl(struct file *filp,
402 cmd = ioctl->cmd_drv; 402 cmd = ioctl->cmd_drv;
403 } 403 }
404 else if ((nr >= DRM_COMMAND_END) || (nr < DRM_COMMAND_BASE)) { 404 else if ((nr >= DRM_COMMAND_END) || (nr < DRM_COMMAND_BASE)) {
405 u32 drv_size;
406
405 ioctl = &drm_ioctls[nr]; 407 ioctl = &drm_ioctls[nr];
406 cmd = ioctl->cmd; 408
409 drv_size = _IOC_SIZE(ioctl->cmd);
407 usize = asize = _IOC_SIZE(cmd); 410 usize = asize = _IOC_SIZE(cmd);
411 if (drv_size > asize)
412 asize = drv_size;
413
414 cmd = ioctl->cmd;
408 } else 415 } else
409 goto err_i1; 416 goto err_i1;
410 417
diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c
index 69d8ed5416c3..2ad27880cd04 100644
--- a/drivers/gpu/drm/i915/i915_drv.c
+++ b/drivers/gpu/drm/i915/i915_drv.c
@@ -505,6 +505,8 @@ static int i915_drm_freeze(struct drm_device *dev)
505 intel_modeset_suspend_hw(dev); 505 intel_modeset_suspend_hw(dev);
506 } 506 }
507 507
508 i915_gem_suspend_gtt_mappings(dev);
509
508 i915_save_state(dev); 510 i915_save_state(dev);
509 511
510 intel_opregion_fini(dev); 512 intel_opregion_fini(dev);
@@ -648,7 +650,8 @@ static int i915_drm_thaw(struct drm_device *dev)
648 mutex_lock(&dev->struct_mutex); 650 mutex_lock(&dev->struct_mutex);
649 i915_gem_restore_gtt_mappings(dev); 651 i915_gem_restore_gtt_mappings(dev);
650 mutex_unlock(&dev->struct_mutex); 652 mutex_unlock(&dev->struct_mutex);
651 } 653 } else if (drm_core_check_feature(dev, DRIVER_MODESET))
654 i915_check_and_clear_faults(dev);
652 655
653 __i915_drm_thaw(dev); 656 __i915_drm_thaw(dev);
654 657
diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index 35874b3a86dc..ab0f2c0a440c 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -497,10 +497,12 @@ struct i915_address_space {
497 497
498 /* FIXME: Need a more generic return type */ 498 /* FIXME: Need a more generic return type */
499 gen6_gtt_pte_t (*pte_encode)(dma_addr_t addr, 499 gen6_gtt_pte_t (*pte_encode)(dma_addr_t addr,
500 enum i915_cache_level level); 500 enum i915_cache_level level,
501 bool valid); /* Create a valid PTE */
501 void (*clear_range)(struct i915_address_space *vm, 502 void (*clear_range)(struct i915_address_space *vm,
502 unsigned int first_entry, 503 unsigned int first_entry,
503 unsigned int num_entries); 504 unsigned int num_entries,
505 bool use_scratch);
504 void (*insert_entries)(struct i915_address_space *vm, 506 void (*insert_entries)(struct i915_address_space *vm,
505 struct sg_table *st, 507 struct sg_table *st,
506 unsigned int first_entry, 508 unsigned int first_entry,
@@ -2065,6 +2067,8 @@ void i915_ppgtt_bind_object(struct i915_hw_ppgtt *ppgtt,
2065void i915_ppgtt_unbind_object(struct i915_hw_ppgtt *ppgtt, 2067void i915_ppgtt_unbind_object(struct i915_hw_ppgtt *ppgtt,
2066 struct drm_i915_gem_object *obj); 2068 struct drm_i915_gem_object *obj);
2067 2069
2070void i915_check_and_clear_faults(struct drm_device *dev);
2071void i915_gem_suspend_gtt_mappings(struct drm_device *dev);
2068void i915_gem_restore_gtt_mappings(struct drm_device *dev); 2072void i915_gem_restore_gtt_mappings(struct drm_device *dev);
2069int __must_check i915_gem_gtt_prepare_object(struct drm_i915_gem_object *obj); 2073int __must_check i915_gem_gtt_prepare_object(struct drm_i915_gem_object *obj);
2070void i915_gem_gtt_bind_object(struct drm_i915_gem_object *obj, 2074void i915_gem_gtt_bind_object(struct drm_i915_gem_object *obj,
diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c b/drivers/gpu/drm/i915/i915_gem_gtt.c
index 212f6d8c35ec..1f7b4caefb6e 100644
--- a/drivers/gpu/drm/i915/i915_gem_gtt.c
+++ b/drivers/gpu/drm/i915/i915_gem_gtt.c
@@ -58,9 +58,10 @@
58#define HSW_WT_ELLC_LLC_AGE0 HSW_CACHEABILITY_CONTROL(0x6) 58#define HSW_WT_ELLC_LLC_AGE0 HSW_CACHEABILITY_CONTROL(0x6)
59 59
60static gen6_gtt_pte_t snb_pte_encode(dma_addr_t addr, 60static gen6_gtt_pte_t snb_pte_encode(dma_addr_t addr,
61 enum i915_cache_level level) 61 enum i915_cache_level level,
62 bool valid)
62{ 63{
63 gen6_gtt_pte_t pte = GEN6_PTE_VALID; 64 gen6_gtt_pte_t pte = valid ? GEN6_PTE_VALID : 0;
64 pte |= GEN6_PTE_ADDR_ENCODE(addr); 65 pte |= GEN6_PTE_ADDR_ENCODE(addr);
65 66
66 switch (level) { 67 switch (level) {
@@ -79,9 +80,10 @@ static gen6_gtt_pte_t snb_pte_encode(dma_addr_t addr,
79} 80}
80 81
81static gen6_gtt_pte_t ivb_pte_encode(dma_addr_t addr, 82static gen6_gtt_pte_t ivb_pte_encode(dma_addr_t addr,
82 enum i915_cache_level level) 83 enum i915_cache_level level,
84 bool valid)
83{ 85{
84 gen6_gtt_pte_t pte = GEN6_PTE_VALID; 86 gen6_gtt_pte_t pte = valid ? GEN6_PTE_VALID : 0;
85 pte |= GEN6_PTE_ADDR_ENCODE(addr); 87 pte |= GEN6_PTE_ADDR_ENCODE(addr);
86 88
87 switch (level) { 89 switch (level) {
@@ -105,9 +107,10 @@ static gen6_gtt_pte_t ivb_pte_encode(dma_addr_t addr,
105#define BYT_PTE_SNOOPED_BY_CPU_CACHES (1 << 2) 107#define BYT_PTE_SNOOPED_BY_CPU_CACHES (1 << 2)
106 108
107static gen6_gtt_pte_t byt_pte_encode(dma_addr_t addr, 109static gen6_gtt_pte_t byt_pte_encode(dma_addr_t addr,
108 enum i915_cache_level level) 110 enum i915_cache_level level,
111 bool valid)
109{ 112{
110 gen6_gtt_pte_t pte = GEN6_PTE_VALID; 113 gen6_gtt_pte_t pte = valid ? GEN6_PTE_VALID : 0;
111 pte |= GEN6_PTE_ADDR_ENCODE(addr); 114 pte |= GEN6_PTE_ADDR_ENCODE(addr);
112 115
113 /* Mark the page as writeable. Other platforms don't have a 116 /* Mark the page as writeable. Other platforms don't have a
@@ -122,9 +125,10 @@ static gen6_gtt_pte_t byt_pte_encode(dma_addr_t addr,
122} 125}
123 126
124static gen6_gtt_pte_t hsw_pte_encode(dma_addr_t addr, 127static gen6_gtt_pte_t hsw_pte_encode(dma_addr_t addr,
125 enum i915_cache_level level) 128 enum i915_cache_level level,
129 bool valid)
126{ 130{
127 gen6_gtt_pte_t pte = GEN6_PTE_VALID; 131 gen6_gtt_pte_t pte = valid ? GEN6_PTE_VALID : 0;
128 pte |= HSW_PTE_ADDR_ENCODE(addr); 132 pte |= HSW_PTE_ADDR_ENCODE(addr);
129 133
130 if (level != I915_CACHE_NONE) 134 if (level != I915_CACHE_NONE)
@@ -134,9 +138,10 @@ static gen6_gtt_pte_t hsw_pte_encode(dma_addr_t addr,
134} 138}
135 139
136static gen6_gtt_pte_t iris_pte_encode(dma_addr_t addr, 140static gen6_gtt_pte_t iris_pte_encode(dma_addr_t addr,
137 enum i915_cache_level level) 141 enum i915_cache_level level,
142 bool valid)
138{ 143{
139 gen6_gtt_pte_t pte = GEN6_PTE_VALID; 144 gen6_gtt_pte_t pte = valid ? GEN6_PTE_VALID : 0;
140 pte |= HSW_PTE_ADDR_ENCODE(addr); 145 pte |= HSW_PTE_ADDR_ENCODE(addr);
141 146
142 switch (level) { 147 switch (level) {
@@ -236,7 +241,8 @@ static int gen6_ppgtt_enable(struct drm_device *dev)
236/* PPGTT support for Sandybdrige/Gen6 and later */ 241/* PPGTT support for Sandybdrige/Gen6 and later */
237static void gen6_ppgtt_clear_range(struct i915_address_space *vm, 242static void gen6_ppgtt_clear_range(struct i915_address_space *vm,
238 unsigned first_entry, 243 unsigned first_entry,
239 unsigned num_entries) 244 unsigned num_entries,
245 bool use_scratch)
240{ 246{
241 struct i915_hw_ppgtt *ppgtt = 247 struct i915_hw_ppgtt *ppgtt =
242 container_of(vm, struct i915_hw_ppgtt, base); 248 container_of(vm, struct i915_hw_ppgtt, base);
@@ -245,7 +251,7 @@ static void gen6_ppgtt_clear_range(struct i915_address_space *vm,
245 unsigned first_pte = first_entry % I915_PPGTT_PT_ENTRIES; 251 unsigned first_pte = first_entry % I915_PPGTT_PT_ENTRIES;
246 unsigned last_pte, i; 252 unsigned last_pte, i;
247 253
248 scratch_pte = vm->pte_encode(vm->scratch.addr, I915_CACHE_LLC); 254 scratch_pte = vm->pte_encode(vm->scratch.addr, I915_CACHE_LLC, true);
249 255
250 while (num_entries) { 256 while (num_entries) {
251 last_pte = first_pte + num_entries; 257 last_pte = first_pte + num_entries;
@@ -282,7 +288,7 @@ static void gen6_ppgtt_insert_entries(struct i915_address_space *vm,
282 dma_addr_t page_addr; 288 dma_addr_t page_addr;
283 289
284 page_addr = sg_page_iter_dma_address(&sg_iter); 290 page_addr = sg_page_iter_dma_address(&sg_iter);
285 pt_vaddr[act_pte] = vm->pte_encode(page_addr, cache_level); 291 pt_vaddr[act_pte] = vm->pte_encode(page_addr, cache_level, true);
286 if (++act_pte == I915_PPGTT_PT_ENTRIES) { 292 if (++act_pte == I915_PPGTT_PT_ENTRIES) {
287 kunmap_atomic(pt_vaddr); 293 kunmap_atomic(pt_vaddr);
288 act_pt++; 294 act_pt++;
@@ -367,7 +373,7 @@ static int gen6_ppgtt_init(struct i915_hw_ppgtt *ppgtt)
367 } 373 }
368 374
369 ppgtt->base.clear_range(&ppgtt->base, 0, 375 ppgtt->base.clear_range(&ppgtt->base, 0,
370 ppgtt->num_pd_entries * I915_PPGTT_PT_ENTRIES); 376 ppgtt->num_pd_entries * I915_PPGTT_PT_ENTRIES, true);
371 377
372 ppgtt->pd_offset = first_pd_entry_in_global_pt * sizeof(gen6_gtt_pte_t); 378 ppgtt->pd_offset = first_pd_entry_in_global_pt * sizeof(gen6_gtt_pte_t);
373 379
@@ -444,7 +450,8 @@ void i915_ppgtt_unbind_object(struct i915_hw_ppgtt *ppgtt,
444{ 450{
445 ppgtt->base.clear_range(&ppgtt->base, 451 ppgtt->base.clear_range(&ppgtt->base,
446 i915_gem_obj_ggtt_offset(obj) >> PAGE_SHIFT, 452 i915_gem_obj_ggtt_offset(obj) >> PAGE_SHIFT,
447 obj->base.size >> PAGE_SHIFT); 453 obj->base.size >> PAGE_SHIFT,
454 true);
448} 455}
449 456
450extern int intel_iommu_gfx_mapped; 457extern int intel_iommu_gfx_mapped;
@@ -485,15 +492,65 @@ static void undo_idling(struct drm_i915_private *dev_priv, bool interruptible)
485 dev_priv->mm.interruptible = interruptible; 492 dev_priv->mm.interruptible = interruptible;
486} 493}
487 494
495void i915_check_and_clear_faults(struct drm_device *dev)
496{
497 struct drm_i915_private *dev_priv = dev->dev_private;
498 struct intel_ring_buffer *ring;
499 int i;
500
501 if (INTEL_INFO(dev)->gen < 6)
502 return;
503
504 for_each_ring(ring, dev_priv, i) {
505 u32 fault_reg;
506 fault_reg = I915_READ(RING_FAULT_REG(ring));
507 if (fault_reg & RING_FAULT_VALID) {
508 DRM_DEBUG_DRIVER("Unexpected fault\n"
509 "\tAddr: 0x%08lx\\n"
510 "\tAddress space: %s\n"
511 "\tSource ID: %d\n"
512 "\tType: %d\n",
513 fault_reg & PAGE_MASK,
514 fault_reg & RING_FAULT_GTTSEL_MASK ? "GGTT" : "PPGTT",
515 RING_FAULT_SRCID(fault_reg),
516 RING_FAULT_FAULT_TYPE(fault_reg));
517 I915_WRITE(RING_FAULT_REG(ring),
518 fault_reg & ~RING_FAULT_VALID);
519 }
520 }
521 POSTING_READ(RING_FAULT_REG(&dev_priv->ring[RCS]));
522}
523
524void i915_gem_suspend_gtt_mappings(struct drm_device *dev)
525{
526 struct drm_i915_private *dev_priv = dev->dev_private;
527
528 /* Don't bother messing with faults pre GEN6 as we have little
529 * documentation supporting that it's a good idea.
530 */
531 if (INTEL_INFO(dev)->gen < 6)
532 return;
533
534 i915_check_and_clear_faults(dev);
535
536 dev_priv->gtt.base.clear_range(&dev_priv->gtt.base,
537 dev_priv->gtt.base.start / PAGE_SIZE,
538 dev_priv->gtt.base.total / PAGE_SIZE,
539 false);
540}
541
488void i915_gem_restore_gtt_mappings(struct drm_device *dev) 542void i915_gem_restore_gtt_mappings(struct drm_device *dev)
489{ 543{
490 struct drm_i915_private *dev_priv = dev->dev_private; 544 struct drm_i915_private *dev_priv = dev->dev_private;
491 struct drm_i915_gem_object *obj; 545 struct drm_i915_gem_object *obj;
492 546
547 i915_check_and_clear_faults(dev);
548
493 /* First fill our portion of the GTT with scratch pages */ 549 /* First fill our portion of the GTT with scratch pages */
494 dev_priv->gtt.base.clear_range(&dev_priv->gtt.base, 550 dev_priv->gtt.base.clear_range(&dev_priv->gtt.base,
495 dev_priv->gtt.base.start / PAGE_SIZE, 551 dev_priv->gtt.base.start / PAGE_SIZE,
496 dev_priv->gtt.base.total / PAGE_SIZE); 552 dev_priv->gtt.base.total / PAGE_SIZE,
553 true);
497 554
498 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) { 555 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
499 i915_gem_clflush_object(obj, obj->pin_display); 556 i915_gem_clflush_object(obj, obj->pin_display);
@@ -536,7 +593,7 @@ static void gen6_ggtt_insert_entries(struct i915_address_space *vm,
536 593
537 for_each_sg_page(st->sgl, &sg_iter, st->nents, 0) { 594 for_each_sg_page(st->sgl, &sg_iter, st->nents, 0) {
538 addr = sg_page_iter_dma_address(&sg_iter); 595 addr = sg_page_iter_dma_address(&sg_iter);
539 iowrite32(vm->pte_encode(addr, level), &gtt_entries[i]); 596 iowrite32(vm->pte_encode(addr, level, true), &gtt_entries[i]);
540 i++; 597 i++;
541 } 598 }
542 599
@@ -548,7 +605,7 @@ static void gen6_ggtt_insert_entries(struct i915_address_space *vm,
548 */ 605 */
549 if (i != 0) 606 if (i != 0)
550 WARN_ON(readl(&gtt_entries[i-1]) != 607 WARN_ON(readl(&gtt_entries[i-1]) !=
551 vm->pte_encode(addr, level)); 608 vm->pte_encode(addr, level, true));
552 609
553 /* This next bit makes the above posting read even more important. We 610 /* This next bit makes the above posting read even more important. We
554 * want to flush the TLBs only after we're certain all the PTE updates 611 * want to flush the TLBs only after we're certain all the PTE updates
@@ -560,7 +617,8 @@ static void gen6_ggtt_insert_entries(struct i915_address_space *vm,
560 617
561static void gen6_ggtt_clear_range(struct i915_address_space *vm, 618static void gen6_ggtt_clear_range(struct i915_address_space *vm,
562 unsigned int first_entry, 619 unsigned int first_entry,
563 unsigned int num_entries) 620 unsigned int num_entries,
621 bool use_scratch)
564{ 622{
565 struct drm_i915_private *dev_priv = vm->dev->dev_private; 623 struct drm_i915_private *dev_priv = vm->dev->dev_private;
566 gen6_gtt_pte_t scratch_pte, __iomem *gtt_base = 624 gen6_gtt_pte_t scratch_pte, __iomem *gtt_base =
@@ -573,7 +631,8 @@ static void gen6_ggtt_clear_range(struct i915_address_space *vm,
573 first_entry, num_entries, max_entries)) 631 first_entry, num_entries, max_entries))
574 num_entries = max_entries; 632 num_entries = max_entries;
575 633
576 scratch_pte = vm->pte_encode(vm->scratch.addr, I915_CACHE_LLC); 634 scratch_pte = vm->pte_encode(vm->scratch.addr, I915_CACHE_LLC, use_scratch);
635
577 for (i = 0; i < num_entries; i++) 636 for (i = 0; i < num_entries; i++)
578 iowrite32(scratch_pte, &gtt_base[i]); 637 iowrite32(scratch_pte, &gtt_base[i]);
579 readl(gtt_base); 638 readl(gtt_base);
@@ -594,7 +653,8 @@ static void i915_ggtt_insert_entries(struct i915_address_space *vm,
594 653
595static void i915_ggtt_clear_range(struct i915_address_space *vm, 654static void i915_ggtt_clear_range(struct i915_address_space *vm,
596 unsigned int first_entry, 655 unsigned int first_entry,
597 unsigned int num_entries) 656 unsigned int num_entries,
657 bool unused)
598{ 658{
599 intel_gtt_clear_range(first_entry, num_entries); 659 intel_gtt_clear_range(first_entry, num_entries);
600} 660}
@@ -622,7 +682,8 @@ void i915_gem_gtt_unbind_object(struct drm_i915_gem_object *obj)
622 682
623 dev_priv->gtt.base.clear_range(&dev_priv->gtt.base, 683 dev_priv->gtt.base.clear_range(&dev_priv->gtt.base,
624 entry, 684 entry,
625 obj->base.size >> PAGE_SHIFT); 685 obj->base.size >> PAGE_SHIFT,
686 true);
626 687
627 obj->has_global_gtt_mapping = 0; 688 obj->has_global_gtt_mapping = 0;
628} 689}
@@ -709,11 +770,11 @@ void i915_gem_setup_global_gtt(struct drm_device *dev,
709 const unsigned long count = (hole_end - hole_start) / PAGE_SIZE; 770 const unsigned long count = (hole_end - hole_start) / PAGE_SIZE;
710 DRM_DEBUG_KMS("clearing unused GTT space: [%lx, %lx]\n", 771 DRM_DEBUG_KMS("clearing unused GTT space: [%lx, %lx]\n",
711 hole_start, hole_end); 772 hole_start, hole_end);
712 ggtt_vm->clear_range(ggtt_vm, hole_start / PAGE_SIZE, count); 773 ggtt_vm->clear_range(ggtt_vm, hole_start / PAGE_SIZE, count, true);
713 } 774 }
714 775
715 /* And finally clear the reserved guard page */ 776 /* And finally clear the reserved guard page */
716 ggtt_vm->clear_range(ggtt_vm, end / PAGE_SIZE - 1, 1); 777 ggtt_vm->clear_range(ggtt_vm, end / PAGE_SIZE - 1, 1, true);
717} 778}
718 779
719static bool 780static bool
diff --git a/drivers/gpu/drm/i915/i915_reg.h b/drivers/gpu/drm/i915/i915_reg.h
index 38f96f65d87a..ef9b35479f01 100644
--- a/drivers/gpu/drm/i915/i915_reg.h
+++ b/drivers/gpu/drm/i915/i915_reg.h
@@ -604,6 +604,10 @@
604#define ARB_MODE_SWIZZLE_IVB (1<<5) 604#define ARB_MODE_SWIZZLE_IVB (1<<5)
605#define RENDER_HWS_PGA_GEN7 (0x04080) 605#define RENDER_HWS_PGA_GEN7 (0x04080)
606#define RING_FAULT_REG(ring) (0x4094 + 0x100*(ring)->id) 606#define RING_FAULT_REG(ring) (0x4094 + 0x100*(ring)->id)
607#define RING_FAULT_GTTSEL_MASK (1<<11)
608#define RING_FAULT_SRCID(x) ((x >> 3) & 0xff)
609#define RING_FAULT_FAULT_TYPE(x) ((x >> 1) & 0x3)
610#define RING_FAULT_VALID (1<<0)
607#define DONE_REG 0x40b0 611#define DONE_REG 0x40b0
608#define BSD_HWS_PGA_GEN7 (0x04180) 612#define BSD_HWS_PGA_GEN7 (0x04180)
609#define BLT_HWS_PGA_GEN7 (0x04280) 613#define BLT_HWS_PGA_GEN7 (0x04280)
@@ -4279,7 +4283,9 @@
4279#define FDI_RX_CHICKEN(pipe) _PIPE(pipe, _FDI_RXA_CHICKEN, _FDI_RXB_CHICKEN) 4283#define FDI_RX_CHICKEN(pipe) _PIPE(pipe, _FDI_RXA_CHICKEN, _FDI_RXB_CHICKEN)
4280 4284
4281#define SOUTH_DSPCLK_GATE_D 0xc2020 4285#define SOUTH_DSPCLK_GATE_D 0xc2020
4286#define PCH_DPLUNIT_CLOCK_GATE_DISABLE (1<<30)
4282#define PCH_DPLSUNIT_CLOCK_GATE_DISABLE (1<<29) 4287#define PCH_DPLSUNIT_CLOCK_GATE_DISABLE (1<<29)
4288#define PCH_CPUNIT_CLOCK_GATE_DISABLE (1<<14)
4283#define PCH_LP_PARTITION_LEVEL_DISABLE (1<<12) 4289#define PCH_LP_PARTITION_LEVEL_DISABLE (1<<12)
4284 4290
4285/* CPU: FDI_TX */ 4291/* CPU: FDI_TX */
diff --git a/drivers/gpu/drm/i915/intel_crt.c b/drivers/gpu/drm/i915/intel_crt.c
index ea9022ef15d5..10d1de5bce6f 100644
--- a/drivers/gpu/drm/i915/intel_crt.c
+++ b/drivers/gpu/drm/i915/intel_crt.c
@@ -83,8 +83,7 @@ static bool intel_crt_get_hw_state(struct intel_encoder *encoder,
83 return true; 83 return true;
84} 84}
85 85
86static void intel_crt_get_config(struct intel_encoder *encoder, 86static unsigned int intel_crt_get_flags(struct intel_encoder *encoder)
87 struct intel_crtc_config *pipe_config)
88{ 87{
89 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private; 88 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
90 struct intel_crt *crt = intel_encoder_to_crt(encoder); 89 struct intel_crt *crt = intel_encoder_to_crt(encoder);
@@ -102,7 +101,25 @@ static void intel_crt_get_config(struct intel_encoder *encoder,
102 else 101 else
103 flags |= DRM_MODE_FLAG_NVSYNC; 102 flags |= DRM_MODE_FLAG_NVSYNC;
104 103
105 pipe_config->adjusted_mode.flags |= flags; 104 return flags;
105}
106
107static void intel_crt_get_config(struct intel_encoder *encoder,
108 struct intel_crtc_config *pipe_config)
109{
110 pipe_config->adjusted_mode.flags |= intel_crt_get_flags(encoder);
111}
112
113static void hsw_crt_get_config(struct intel_encoder *encoder,
114 struct intel_crtc_config *pipe_config)
115{
116 intel_ddi_get_config(encoder, pipe_config);
117
118 pipe_config->adjusted_mode.flags &= ~(DRM_MODE_FLAG_PHSYNC |
119 DRM_MODE_FLAG_NHSYNC |
120 DRM_MODE_FLAG_PVSYNC |
121 DRM_MODE_FLAG_NVSYNC);
122 pipe_config->adjusted_mode.flags |= intel_crt_get_flags(encoder);
106} 123}
107 124
108/* Note: The caller is required to filter out dpms modes not supported by the 125/* Note: The caller is required to filter out dpms modes not supported by the
@@ -799,7 +816,10 @@ void intel_crt_init(struct drm_device *dev)
799 crt->base.mode_set = intel_crt_mode_set; 816 crt->base.mode_set = intel_crt_mode_set;
800 crt->base.disable = intel_disable_crt; 817 crt->base.disable = intel_disable_crt;
801 crt->base.enable = intel_enable_crt; 818 crt->base.enable = intel_enable_crt;
802 crt->base.get_config = intel_crt_get_config; 819 if (IS_HASWELL(dev))
820 crt->base.get_config = hsw_crt_get_config;
821 else
822 crt->base.get_config = intel_crt_get_config;
803 if (I915_HAS_HOTPLUG(dev)) 823 if (I915_HAS_HOTPLUG(dev))
804 crt->base.hpd_pin = HPD_CRT; 824 crt->base.hpd_pin = HPD_CRT;
805 if (HAS_DDI(dev)) 825 if (HAS_DDI(dev))
diff --git a/drivers/gpu/drm/i915/intel_ddi.c b/drivers/gpu/drm/i915/intel_ddi.c
index 63de2701b974..b53fff84a7d5 100644
--- a/drivers/gpu/drm/i915/intel_ddi.c
+++ b/drivers/gpu/drm/i915/intel_ddi.c
@@ -1249,8 +1249,8 @@ static void intel_ddi_hot_plug(struct intel_encoder *intel_encoder)
1249 intel_dp_check_link_status(intel_dp); 1249 intel_dp_check_link_status(intel_dp);
1250} 1250}
1251 1251
1252static void intel_ddi_get_config(struct intel_encoder *encoder, 1252void intel_ddi_get_config(struct intel_encoder *encoder,
1253 struct intel_crtc_config *pipe_config) 1253 struct intel_crtc_config *pipe_config)
1254{ 1254{
1255 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private; 1255 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
1256 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc); 1256 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
@@ -1268,6 +1268,23 @@ static void intel_ddi_get_config(struct intel_encoder *encoder,
1268 flags |= DRM_MODE_FLAG_NVSYNC; 1268 flags |= DRM_MODE_FLAG_NVSYNC;
1269 1269
1270 pipe_config->adjusted_mode.flags |= flags; 1270 pipe_config->adjusted_mode.flags |= flags;
1271
1272 switch (temp & TRANS_DDI_BPC_MASK) {
1273 case TRANS_DDI_BPC_6:
1274 pipe_config->pipe_bpp = 18;
1275 break;
1276 case TRANS_DDI_BPC_8:
1277 pipe_config->pipe_bpp = 24;
1278 break;
1279 case TRANS_DDI_BPC_10:
1280 pipe_config->pipe_bpp = 30;
1281 break;
1282 case TRANS_DDI_BPC_12:
1283 pipe_config->pipe_bpp = 36;
1284 break;
1285 default:
1286 break;
1287 }
1271} 1288}
1272 1289
1273static void intel_ddi_destroy(struct drm_encoder *encoder) 1290static void intel_ddi_destroy(struct drm_encoder *encoder)
diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
index 581fb4b2f766..d78d33f9337d 100644
--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -2327,9 +2327,10 @@ static void intel_fdi_normal_train(struct drm_crtc *crtc)
2327 FDI_FE_ERRC_ENABLE); 2327 FDI_FE_ERRC_ENABLE);
2328} 2328}
2329 2329
2330static bool pipe_has_enabled_pch(struct intel_crtc *intel_crtc) 2330static bool pipe_has_enabled_pch(struct intel_crtc *crtc)
2331{ 2331{
2332 return intel_crtc->base.enabled && intel_crtc->config.has_pch_encoder; 2332 return crtc->base.enabled && crtc->active &&
2333 crtc->config.has_pch_encoder;
2333} 2334}
2334 2335
2335static void ivb_modeset_global_resources(struct drm_device *dev) 2336static void ivb_modeset_global_resources(struct drm_device *dev)
@@ -2979,6 +2980,48 @@ static void ironlake_pch_transcoder_set_timings(struct intel_crtc *crtc,
2979 I915_READ(VSYNCSHIFT(cpu_transcoder))); 2980 I915_READ(VSYNCSHIFT(cpu_transcoder)));
2980} 2981}
2981 2982
2983static void cpt_enable_fdi_bc_bifurcation(struct drm_device *dev)
2984{
2985 struct drm_i915_private *dev_priv = dev->dev_private;
2986 uint32_t temp;
2987
2988 temp = I915_READ(SOUTH_CHICKEN1);
2989 if (temp & FDI_BC_BIFURCATION_SELECT)
2990 return;
2991
2992 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE);
2993 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE);
2994
2995 temp |= FDI_BC_BIFURCATION_SELECT;
2996 DRM_DEBUG_KMS("enabling fdi C rx\n");
2997 I915_WRITE(SOUTH_CHICKEN1, temp);
2998 POSTING_READ(SOUTH_CHICKEN1);
2999}
3000
3001static void ivybridge_update_fdi_bc_bifurcation(struct intel_crtc *intel_crtc)
3002{
3003 struct drm_device *dev = intel_crtc->base.dev;
3004 struct drm_i915_private *dev_priv = dev->dev_private;
3005
3006 switch (intel_crtc->pipe) {
3007 case PIPE_A:
3008 break;
3009 case PIPE_B:
3010 if (intel_crtc->config.fdi_lanes > 2)
3011 WARN_ON(I915_READ(SOUTH_CHICKEN1) & FDI_BC_BIFURCATION_SELECT);
3012 else
3013 cpt_enable_fdi_bc_bifurcation(dev);
3014
3015 break;
3016 case PIPE_C:
3017 cpt_enable_fdi_bc_bifurcation(dev);
3018
3019 break;
3020 default:
3021 BUG();
3022 }
3023}
3024
2982/* 3025/*
2983 * Enable PCH resources required for PCH ports: 3026 * Enable PCH resources required for PCH ports:
2984 * - PCH PLLs 3027 * - PCH PLLs
@@ -2997,6 +3040,9 @@ static void ironlake_pch_enable(struct drm_crtc *crtc)
2997 3040
2998 assert_pch_transcoder_disabled(dev_priv, pipe); 3041 assert_pch_transcoder_disabled(dev_priv, pipe);
2999 3042
3043 if (IS_IVYBRIDGE(dev))
3044 ivybridge_update_fdi_bc_bifurcation(intel_crtc);
3045
3000 /* Write the TU size bits before fdi link training, so that error 3046 /* Write the TU size bits before fdi link training, so that error
3001 * detection works. */ 3047 * detection works. */
3002 I915_WRITE(FDI_RX_TUSIZE1(pipe), 3048 I915_WRITE(FDI_RX_TUSIZE1(pipe),
@@ -4983,6 +5029,22 @@ static bool i9xx_get_pipe_config(struct intel_crtc *crtc,
4983 if (!(tmp & PIPECONF_ENABLE)) 5029 if (!(tmp & PIPECONF_ENABLE))
4984 return false; 5030 return false;
4985 5031
5032 if (IS_G4X(dev) || IS_VALLEYVIEW(dev)) {
5033 switch (tmp & PIPECONF_BPC_MASK) {
5034 case PIPECONF_6BPC:
5035 pipe_config->pipe_bpp = 18;
5036 break;
5037 case PIPECONF_8BPC:
5038 pipe_config->pipe_bpp = 24;
5039 break;
5040 case PIPECONF_10BPC:
5041 pipe_config->pipe_bpp = 30;
5042 break;
5043 default:
5044 break;
5045 }
5046 }
5047
4986 intel_get_pipe_timings(crtc, pipe_config); 5048 intel_get_pipe_timings(crtc, pipe_config);
4987 5049
4988 i9xx_get_pfit_config(crtc, pipe_config); 5050 i9xx_get_pfit_config(crtc, pipe_config);
@@ -5576,48 +5638,6 @@ static bool ironlake_compute_clocks(struct drm_crtc *crtc,
5576 return true; 5638 return true;
5577} 5639}
5578 5640
5579static void cpt_enable_fdi_bc_bifurcation(struct drm_device *dev)
5580{
5581 struct drm_i915_private *dev_priv = dev->dev_private;
5582 uint32_t temp;
5583
5584 temp = I915_READ(SOUTH_CHICKEN1);
5585 if (temp & FDI_BC_BIFURCATION_SELECT)
5586 return;
5587
5588 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE);
5589 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE);
5590
5591 temp |= FDI_BC_BIFURCATION_SELECT;
5592 DRM_DEBUG_KMS("enabling fdi C rx\n");
5593 I915_WRITE(SOUTH_CHICKEN1, temp);
5594 POSTING_READ(SOUTH_CHICKEN1);
5595}
5596
5597static void ivybridge_update_fdi_bc_bifurcation(struct intel_crtc *intel_crtc)
5598{
5599 struct drm_device *dev = intel_crtc->base.dev;
5600 struct drm_i915_private *dev_priv = dev->dev_private;
5601
5602 switch (intel_crtc->pipe) {
5603 case PIPE_A:
5604 break;
5605 case PIPE_B:
5606 if (intel_crtc->config.fdi_lanes > 2)
5607 WARN_ON(I915_READ(SOUTH_CHICKEN1) & FDI_BC_BIFURCATION_SELECT);
5608 else
5609 cpt_enable_fdi_bc_bifurcation(dev);
5610
5611 break;
5612 case PIPE_C:
5613 cpt_enable_fdi_bc_bifurcation(dev);
5614
5615 break;
5616 default:
5617 BUG();
5618 }
5619}
5620
5621int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp) 5641int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp)
5622{ 5642{
5623 /* 5643 /*
@@ -5811,9 +5831,6 @@ static int ironlake_crtc_mode_set(struct drm_crtc *crtc,
5811 &intel_crtc->config.fdi_m_n); 5831 &intel_crtc->config.fdi_m_n);
5812 } 5832 }
5813 5833
5814 if (IS_IVYBRIDGE(dev))
5815 ivybridge_update_fdi_bc_bifurcation(intel_crtc);
5816
5817 ironlake_set_pipeconf(crtc); 5834 ironlake_set_pipeconf(crtc);
5818 5835
5819 /* Set up the display plane register */ 5836 /* Set up the display plane register */
@@ -5881,6 +5898,23 @@ static bool ironlake_get_pipe_config(struct intel_crtc *crtc,
5881 if (!(tmp & PIPECONF_ENABLE)) 5898 if (!(tmp & PIPECONF_ENABLE))
5882 return false; 5899 return false;
5883 5900
5901 switch (tmp & PIPECONF_BPC_MASK) {
5902 case PIPECONF_6BPC:
5903 pipe_config->pipe_bpp = 18;
5904 break;
5905 case PIPECONF_8BPC:
5906 pipe_config->pipe_bpp = 24;
5907 break;
5908 case PIPECONF_10BPC:
5909 pipe_config->pipe_bpp = 30;
5910 break;
5911 case PIPECONF_12BPC:
5912 pipe_config->pipe_bpp = 36;
5913 break;
5914 default:
5915 break;
5916 }
5917
5884 if (I915_READ(PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) { 5918 if (I915_READ(PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) {
5885 struct intel_shared_dpll *pll; 5919 struct intel_shared_dpll *pll;
5886 5920
@@ -8612,6 +8646,9 @@ intel_pipe_config_compare(struct drm_device *dev,
8612 PIPE_CONF_CHECK_X(dpll_hw_state.fp0); 8646 PIPE_CONF_CHECK_X(dpll_hw_state.fp0);
8613 PIPE_CONF_CHECK_X(dpll_hw_state.fp1); 8647 PIPE_CONF_CHECK_X(dpll_hw_state.fp1);
8614 8648
8649 if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5)
8650 PIPE_CONF_CHECK_I(pipe_bpp);
8651
8615#undef PIPE_CONF_CHECK_X 8652#undef PIPE_CONF_CHECK_X
8616#undef PIPE_CONF_CHECK_I 8653#undef PIPE_CONF_CHECK_I
8617#undef PIPE_CONF_CHECK_FLAGS 8654#undef PIPE_CONF_CHECK_FLAGS
diff --git a/drivers/gpu/drm/i915/intel_dp.c b/drivers/gpu/drm/i915/intel_dp.c
index 2c555f91bfae..1a431377d83b 100644
--- a/drivers/gpu/drm/i915/intel_dp.c
+++ b/drivers/gpu/drm/i915/intel_dp.c
@@ -1401,6 +1401,26 @@ static void intel_dp_get_config(struct intel_encoder *encoder,
1401 else 1401 else
1402 pipe_config->port_clock = 270000; 1402 pipe_config->port_clock = 270000;
1403 } 1403 }
1404
1405 if (is_edp(intel_dp) && dev_priv->vbt.edp_bpp &&
1406 pipe_config->pipe_bpp > dev_priv->vbt.edp_bpp) {
1407 /*
1408 * This is a big fat ugly hack.
1409 *
1410 * Some machines in UEFI boot mode provide us a VBT that has 18
1411 * bpp and 1.62 GHz link bandwidth for eDP, which for reasons
1412 * unknown we fail to light up. Yet the same BIOS boots up with
1413 * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as
1414 * max, not what it tells us to use.
1415 *
1416 * Note: This will still be broken if the eDP panel is not lit
1417 * up by the BIOS, and thus we can't get the mode at module
1418 * load.
1419 */
1420 DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
1421 pipe_config->pipe_bpp, dev_priv->vbt.edp_bpp);
1422 dev_priv->vbt.edp_bpp = pipe_config->pipe_bpp;
1423 }
1404} 1424}
1405 1425
1406static bool is_edp_psr(struct intel_dp *intel_dp) 1426static bool is_edp_psr(struct intel_dp *intel_dp)
diff --git a/drivers/gpu/drm/i915/intel_drv.h b/drivers/gpu/drm/i915/intel_drv.h
index 9b7b68fd5d47..7f2b384ac939 100644
--- a/drivers/gpu/drm/i915/intel_drv.h
+++ b/drivers/gpu/drm/i915/intel_drv.h
@@ -765,6 +765,8 @@ extern void intel_ddi_prepare_link_retrain(struct drm_encoder *encoder);
765extern bool 765extern bool
766intel_ddi_connector_get_hw_state(struct intel_connector *intel_connector); 766intel_ddi_connector_get_hw_state(struct intel_connector *intel_connector);
767extern void intel_ddi_fdi_disable(struct drm_crtc *crtc); 767extern void intel_ddi_fdi_disable(struct drm_crtc *crtc);
768extern void intel_ddi_get_config(struct intel_encoder *encoder,
769 struct intel_crtc_config *pipe_config);
768 770
769extern void intel_display_handle_reset(struct drm_device *dev); 771extern void intel_display_handle_reset(struct drm_device *dev);
770extern bool intel_set_cpu_fifo_underrun_reporting(struct drm_device *dev, 772extern bool intel_set_cpu_fifo_underrun_reporting(struct drm_device *dev,
diff --git a/drivers/gpu/drm/i915/intel_lvds.c b/drivers/gpu/drm/i915/intel_lvds.c
index 831a5c021c4b..b8af94a5be39 100644
--- a/drivers/gpu/drm/i915/intel_lvds.c
+++ b/drivers/gpu/drm/i915/intel_lvds.c
@@ -700,6 +700,22 @@ static const struct dmi_system_id intel_no_lvds[] = {
700 }, 700 },
701 { 701 {
702 .callback = intel_no_lvds_dmi_callback, 702 .callback = intel_no_lvds_dmi_callback,
703 .ident = "Intel D410PT",
704 .matches = {
705 DMI_MATCH(DMI_BOARD_VENDOR, "Intel"),
706 DMI_MATCH(DMI_BOARD_NAME, "D410PT"),
707 },
708 },
709 {
710 .callback = intel_no_lvds_dmi_callback,
711 .ident = "Intel D425KT",
712 .matches = {
713 DMI_MATCH(DMI_BOARD_VENDOR, "Intel"),
714 DMI_EXACT_MATCH(DMI_BOARD_NAME, "D425KT"),
715 },
716 },
717 {
718 .callback = intel_no_lvds_dmi_callback,
703 .ident = "Intel D510MO", 719 .ident = "Intel D510MO",
704 .matches = { 720 .matches = {
705 DMI_MATCH(DMI_BOARD_VENDOR, "Intel"), 721 DMI_MATCH(DMI_BOARD_VENDOR, "Intel"),
diff --git a/drivers/gpu/drm/i915/intel_pm.c b/drivers/gpu/drm/i915/intel_pm.c
index f4c5e95b2d6f..26c2ea3e985c 100644
--- a/drivers/gpu/drm/i915/intel_pm.c
+++ b/drivers/gpu/drm/i915/intel_pm.c
@@ -4759,7 +4759,9 @@ static void cpt_init_clock_gating(struct drm_device *dev)
4759 * gating for the panel power sequencer or it will fail to 4759 * gating for the panel power sequencer or it will fail to
4760 * start up when no ports are active. 4760 * start up when no ports are active.
4761 */ 4761 */
4762 I915_WRITE(SOUTH_DSPCLK_GATE_D, PCH_DPLSUNIT_CLOCK_GATE_DISABLE); 4762 I915_WRITE(SOUTH_DSPCLK_GATE_D, PCH_DPLSUNIT_CLOCK_GATE_DISABLE |
4763 PCH_DPLUNIT_CLOCK_GATE_DISABLE |
4764 PCH_CPUNIT_CLOCK_GATE_DISABLE);
4763 I915_WRITE(SOUTH_CHICKEN2, I915_READ(SOUTH_CHICKEN2) | 4765 I915_WRITE(SOUTH_CHICKEN2, I915_READ(SOUTH_CHICKEN2) |
4764 DPLS_EDP_PPS_FIX_DIS); 4766 DPLS_EDP_PPS_FIX_DIS);
4765 /* The below fixes the weird display corruption, a few pixels shifted 4767 /* The below fixes the weird display corruption, a few pixels shifted
diff --git a/drivers/gpu/drm/radeon/atombios_encoders.c b/drivers/gpu/drm/radeon/atombios_encoders.c
index 32923d2f6002..5e891b226acf 100644
--- a/drivers/gpu/drm/radeon/atombios_encoders.c
+++ b/drivers/gpu/drm/radeon/atombios_encoders.c
@@ -707,24 +707,37 @@ atombios_get_encoder_mode(struct drm_encoder *encoder)
707 switch (connector->connector_type) { 707 switch (connector->connector_type) {
708 case DRM_MODE_CONNECTOR_DVII: 708 case DRM_MODE_CONNECTOR_DVII:
709 case DRM_MODE_CONNECTOR_HDMIB: /* HDMI-B is basically DL-DVI; analog works fine */ 709 case DRM_MODE_CONNECTOR_HDMIB: /* HDMI-B is basically DL-DVI; analog works fine */
710 if ((radeon_connector->audio == RADEON_AUDIO_ENABLE) || 710 if (radeon_audio != 0) {
711 (drm_detect_hdmi_monitor(radeon_connector->edid) && 711 if (radeon_connector->use_digital &&
712 (radeon_connector->audio == RADEON_AUDIO_AUTO))) 712 (radeon_connector->audio == RADEON_AUDIO_ENABLE))
713 return ATOM_ENCODER_MODE_HDMI; 713 return ATOM_ENCODER_MODE_HDMI;
714 else if (radeon_connector->use_digital) 714 else if (drm_detect_hdmi_monitor(radeon_connector->edid) &&
715 (radeon_connector->audio == RADEON_AUDIO_AUTO))
716 return ATOM_ENCODER_MODE_HDMI;
717 else if (radeon_connector->use_digital)
718 return ATOM_ENCODER_MODE_DVI;
719 else
720 return ATOM_ENCODER_MODE_CRT;
721 } else if (radeon_connector->use_digital) {
715 return ATOM_ENCODER_MODE_DVI; 722 return ATOM_ENCODER_MODE_DVI;
716 else 723 } else {
717 return ATOM_ENCODER_MODE_CRT; 724 return ATOM_ENCODER_MODE_CRT;
725 }
718 break; 726 break;
719 case DRM_MODE_CONNECTOR_DVID: 727 case DRM_MODE_CONNECTOR_DVID:
720 case DRM_MODE_CONNECTOR_HDMIA: 728 case DRM_MODE_CONNECTOR_HDMIA:
721 default: 729 default:
722 if ((radeon_connector->audio == RADEON_AUDIO_ENABLE) || 730 if (radeon_audio != 0) {
723 (drm_detect_hdmi_monitor(radeon_connector->edid) && 731 if (radeon_connector->audio == RADEON_AUDIO_ENABLE)
724 (radeon_connector->audio == RADEON_AUDIO_AUTO))) 732 return ATOM_ENCODER_MODE_HDMI;
725 return ATOM_ENCODER_MODE_HDMI; 733 else if (drm_detect_hdmi_monitor(radeon_connector->edid) &&
726 else 734 (radeon_connector->audio == RADEON_AUDIO_AUTO))
735 return ATOM_ENCODER_MODE_HDMI;
736 else
737 return ATOM_ENCODER_MODE_DVI;
738 } else {
727 return ATOM_ENCODER_MODE_DVI; 739 return ATOM_ENCODER_MODE_DVI;
740 }
728 break; 741 break;
729 case DRM_MODE_CONNECTOR_LVDS: 742 case DRM_MODE_CONNECTOR_LVDS:
730 return ATOM_ENCODER_MODE_LVDS; 743 return ATOM_ENCODER_MODE_LVDS;
@@ -732,14 +745,19 @@ atombios_get_encoder_mode(struct drm_encoder *encoder)
732 case DRM_MODE_CONNECTOR_DisplayPort: 745 case DRM_MODE_CONNECTOR_DisplayPort:
733 dig_connector = radeon_connector->con_priv; 746 dig_connector = radeon_connector->con_priv;
734 if ((dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) || 747 if ((dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) ||
735 (dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_eDP)) 748 (dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_eDP)) {
736 return ATOM_ENCODER_MODE_DP; 749 return ATOM_ENCODER_MODE_DP;
737 else if ((radeon_connector->audio == RADEON_AUDIO_ENABLE) || 750 } else if (radeon_audio != 0) {
738 (drm_detect_hdmi_monitor(radeon_connector->edid) && 751 if (radeon_connector->audio == RADEON_AUDIO_ENABLE)
739 (radeon_connector->audio == RADEON_AUDIO_AUTO))) 752 return ATOM_ENCODER_MODE_HDMI;
740 return ATOM_ENCODER_MODE_HDMI; 753 else if (drm_detect_hdmi_monitor(radeon_connector->edid) &&
741 else 754 (radeon_connector->audio == RADEON_AUDIO_AUTO))
755 return ATOM_ENCODER_MODE_HDMI;
756 else
757 return ATOM_ENCODER_MODE_DVI;
758 } else {
742 return ATOM_ENCODER_MODE_DVI; 759 return ATOM_ENCODER_MODE_DVI;
760 }
743 break; 761 break;
744 case DRM_MODE_CONNECTOR_eDP: 762 case DRM_MODE_CONNECTOR_eDP:
745 return ATOM_ENCODER_MODE_DP; 763 return ATOM_ENCODER_MODE_DP;
@@ -1655,7 +1673,7 @@ radeon_atom_encoder_dpms_dig(struct drm_encoder *encoder, int mode)
1655 * does the same thing and more. 1673 * does the same thing and more.
1656 */ 1674 */
1657 if ((rdev->family != CHIP_RV710) && (rdev->family != CHIP_RV730) && 1675 if ((rdev->family != CHIP_RV710) && (rdev->family != CHIP_RV730) &&
1658 (rdev->family != CHIP_RS880)) 1676 (rdev->family != CHIP_RS780) && (rdev->family != CHIP_RS880))
1659 atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_ENABLE_OUTPUT, 0, 0); 1677 atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_ENABLE_OUTPUT, 0, 0);
1660 } 1678 }
1661 if (ENCODER_MODE_IS_DP(atombios_get_encoder_mode(encoder)) && connector) { 1679 if (ENCODER_MODE_IS_DP(atombios_get_encoder_mode(encoder)) && connector) {
diff --git a/drivers/gpu/drm/radeon/cik.c b/drivers/gpu/drm/radeon/cik.c
index b874ccdf52f7..9cd2bc989ac7 100644
--- a/drivers/gpu/drm/radeon/cik.c
+++ b/drivers/gpu/drm/radeon/cik.c
@@ -1694,6 +1694,7 @@ static int cik_init_microcode(struct radeon_device *rdev)
1694 fw_name); 1694 fw_name);
1695 release_firmware(rdev->smc_fw); 1695 release_firmware(rdev->smc_fw);
1696 rdev->smc_fw = NULL; 1696 rdev->smc_fw = NULL;
1697 err = 0;
1697 } else if (rdev->smc_fw->size != smc_req_size) { 1698 } else if (rdev->smc_fw->size != smc_req_size) {
1698 printk(KERN_ERR 1699 printk(KERN_ERR
1699 "cik_smc: Bogus length %zu in firmware \"%s\"\n", 1700 "cik_smc: Bogus length %zu in firmware \"%s\"\n",
@@ -3182,6 +3183,7 @@ int cik_ib_test(struct radeon_device *rdev, struct radeon_ring *ring)
3182 r = radeon_ib_get(rdev, ring->idx, &ib, NULL, 256); 3183 r = radeon_ib_get(rdev, ring->idx, &ib, NULL, 256);
3183 if (r) { 3184 if (r) {
3184 DRM_ERROR("radeon: failed to get ib (%d).\n", r); 3185 DRM_ERROR("radeon: failed to get ib (%d).\n", r);
3186 radeon_scratch_free(rdev, scratch);
3185 return r; 3187 return r;
3186 } 3188 }
3187 ib.ptr[0] = PACKET3(PACKET3_SET_UCONFIG_REG, 1); 3189 ib.ptr[0] = PACKET3(PACKET3_SET_UCONFIG_REG, 1);
@@ -3198,6 +3200,8 @@ int cik_ib_test(struct radeon_device *rdev, struct radeon_ring *ring)
3198 r = radeon_fence_wait(ib.fence, false); 3200 r = radeon_fence_wait(ib.fence, false);
3199 if (r) { 3201 if (r) {
3200 DRM_ERROR("radeon: fence wait failed (%d).\n", r); 3202 DRM_ERROR("radeon: fence wait failed (%d).\n", r);
3203 radeon_scratch_free(rdev, scratch);
3204 radeon_ib_free(rdev, &ib);
3201 return r; 3205 return r;
3202 } 3206 }
3203 for (i = 0; i < rdev->usec_timeout; i++) { 3207 for (i = 0; i < rdev->usec_timeout; i++) {
diff --git a/drivers/gpu/drm/radeon/dce6_afmt.c b/drivers/gpu/drm/radeon/dce6_afmt.c
index 85a69d2ea3d2..9fcd338c0fcf 100644
--- a/drivers/gpu/drm/radeon/dce6_afmt.c
+++ b/drivers/gpu/drm/radeon/dce6_afmt.c
@@ -113,6 +113,9 @@ void dce6_afmt_write_speaker_allocation(struct drm_encoder *encoder)
113 u8 *sadb; 113 u8 *sadb;
114 int sad_count; 114 int sad_count;
115 115
116 /* XXX: setting this register causes hangs on some asics */
117 return;
118
116 if (!dig->afmt->pin) 119 if (!dig->afmt->pin)
117 return; 120 return;
118 121
diff --git a/drivers/gpu/drm/radeon/evergreen_hdmi.c b/drivers/gpu/drm/radeon/evergreen_hdmi.c
index f815c20640bd..57fcc4b16a52 100644
--- a/drivers/gpu/drm/radeon/evergreen_hdmi.c
+++ b/drivers/gpu/drm/radeon/evergreen_hdmi.c
@@ -67,6 +67,9 @@ static void dce4_afmt_write_speaker_allocation(struct drm_encoder *encoder)
67 u8 *sadb; 67 u8 *sadb;
68 int sad_count; 68 int sad_count;
69 69
70 /* XXX: setting this register causes hangs on some asics */
71 return;
72
70 list_for_each_entry(connector, &encoder->dev->mode_config.connector_list, head) { 73 list_for_each_entry(connector, &encoder->dev->mode_config.connector_list, head) {
71 if (connector->encoder == encoder) 74 if (connector->encoder == encoder)
72 radeon_connector = to_radeon_connector(connector); 75 radeon_connector = to_radeon_connector(connector);
@@ -288,6 +291,7 @@ void evergreen_hdmi_setmode(struct drm_encoder *encoder, struct drm_display_mode
288 /* fglrx clears sth in AFMT_AUDIO_PACKET_CONTROL2 here */ 291 /* fglrx clears sth in AFMT_AUDIO_PACKET_CONTROL2 here */
289 292
290 WREG32(HDMI_ACR_PACKET_CONTROL + offset, 293 WREG32(HDMI_ACR_PACKET_CONTROL + offset,
294 HDMI_ACR_SOURCE | /* select SW CTS value */
291 HDMI_ACR_AUTO_SEND); /* allow hw to sent ACR packets when required */ 295 HDMI_ACR_AUTO_SEND); /* allow hw to sent ACR packets when required */
292 296
293 evergreen_hdmi_update_ACR(encoder, mode->clock); 297 evergreen_hdmi_update_ACR(encoder, mode->clock);
diff --git a/drivers/gpu/drm/radeon/kv_dpm.c b/drivers/gpu/drm/radeon/kv_dpm.c
index 71399065db04..b41905573cd2 100644
--- a/drivers/gpu/drm/radeon/kv_dpm.c
+++ b/drivers/gpu/drm/radeon/kv_dpm.c
@@ -2635,7 +2635,7 @@ int kv_dpm_init(struct radeon_device *rdev)
2635 pi->caps_sclk_ds = true; 2635 pi->caps_sclk_ds = true;
2636 pi->enable_auto_thermal_throttling = true; 2636 pi->enable_auto_thermal_throttling = true;
2637 pi->disable_nb_ps3_in_battery = false; 2637 pi->disable_nb_ps3_in_battery = false;
2638 pi->bapm_enable = true; 2638 pi->bapm_enable = false;
2639 pi->voltage_drop_t = 0; 2639 pi->voltage_drop_t = 0;
2640 pi->caps_sclk_throttle_low_notification = false; 2640 pi->caps_sclk_throttle_low_notification = false;
2641 pi->caps_fps = false; /* true? */ 2641 pi->caps_fps = false; /* true? */
diff --git a/drivers/gpu/drm/radeon/ni.c b/drivers/gpu/drm/radeon/ni.c
index 93c1f9ef5da9..cac2866d79da 100644
--- a/drivers/gpu/drm/radeon/ni.c
+++ b/drivers/gpu/drm/radeon/ni.c
@@ -804,6 +804,7 @@ int ni_init_microcode(struct radeon_device *rdev)
804 fw_name); 804 fw_name);
805 release_firmware(rdev->smc_fw); 805 release_firmware(rdev->smc_fw);
806 rdev->smc_fw = NULL; 806 rdev->smc_fw = NULL;
807 err = 0;
807 } else if (rdev->smc_fw->size != smc_req_size) { 808 } else if (rdev->smc_fw->size != smc_req_size) {
808 printk(KERN_ERR 809 printk(KERN_ERR
809 "ni_mc: Bogus length %zu in firmware \"%s\"\n", 810 "ni_mc: Bogus length %zu in firmware \"%s\"\n",
diff --git a/drivers/gpu/drm/radeon/r600.c b/drivers/gpu/drm/radeon/r600.c
index 2a1b1876b431..f9be22062df1 100644
--- a/drivers/gpu/drm/radeon/r600.c
+++ b/drivers/gpu/drm/radeon/r600.c
@@ -2302,6 +2302,7 @@ int r600_init_microcode(struct radeon_device *rdev)
2302 fw_name); 2302 fw_name);
2303 release_firmware(rdev->smc_fw); 2303 release_firmware(rdev->smc_fw);
2304 rdev->smc_fw = NULL; 2304 rdev->smc_fw = NULL;
2305 err = 0;
2305 } else if (rdev->smc_fw->size != smc_req_size) { 2306 } else if (rdev->smc_fw->size != smc_req_size) {
2306 printk(KERN_ERR 2307 printk(KERN_ERR
2307 "smc: Bogus length %zu in firmware \"%s\"\n", 2308 "smc: Bogus length %zu in firmware \"%s\"\n",
diff --git a/drivers/gpu/drm/radeon/r600_hdmi.c b/drivers/gpu/drm/radeon/r600_hdmi.c
index 5b729319f27b..06022e3b9c3b 100644
--- a/drivers/gpu/drm/radeon/r600_hdmi.c
+++ b/drivers/gpu/drm/radeon/r600_hdmi.c
@@ -309,6 +309,9 @@ static void dce3_2_afmt_write_speaker_allocation(struct drm_encoder *encoder)
309 u8 *sadb; 309 u8 *sadb;
310 int sad_count; 310 int sad_count;
311 311
312 /* XXX: setting this register causes hangs on some asics */
313 return;
314
312 list_for_each_entry(connector, &encoder->dev->mode_config.connector_list, head) { 315 list_for_each_entry(connector, &encoder->dev->mode_config.connector_list, head) {
313 if (connector->encoder == encoder) 316 if (connector->encoder == encoder)
314 radeon_connector = to_radeon_connector(connector); 317 radeon_connector = to_radeon_connector(connector);
diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
index a400ac1c4147..24f4960f59ee 100644
--- a/drivers/gpu/drm/radeon/radeon.h
+++ b/drivers/gpu/drm/radeon/radeon.h
@@ -1272,8 +1272,8 @@ struct radeon_blacklist_clocks
1272struct radeon_clock_and_voltage_limits { 1272struct radeon_clock_and_voltage_limits {
1273 u32 sclk; 1273 u32 sclk;
1274 u32 mclk; 1274 u32 mclk;
1275 u32 vddc; 1275 u16 vddc;
1276 u32 vddci; 1276 u16 vddci;
1277}; 1277};
1278 1278
1279struct radeon_clock_array { 1279struct radeon_clock_array {
diff --git a/drivers/gpu/drm/radeon/radeon_connectors.c b/drivers/gpu/drm/radeon/radeon_connectors.c
index 79159b5da05b..64565732cb98 100644
--- a/drivers/gpu/drm/radeon/radeon_connectors.c
+++ b/drivers/gpu/drm/radeon/radeon_connectors.c
@@ -1658,9 +1658,12 @@ radeon_add_atom_connector(struct drm_device *dev,
1658 drm_object_attach_property(&radeon_connector->base.base, 1658 drm_object_attach_property(&radeon_connector->base.base,
1659 rdev->mode_info.underscan_vborder_property, 1659 rdev->mode_info.underscan_vborder_property,
1660 0); 1660 0);
1661 drm_object_attach_property(&radeon_connector->base.base, 1661 if (radeon_audio != 0)
1662 rdev->mode_info.audio_property, 1662 drm_object_attach_property(&radeon_connector->base.base,
1663 RADEON_AUDIO_DISABLE); 1663 rdev->mode_info.audio_property,
1664 (radeon_audio == 1) ?
1665 RADEON_AUDIO_AUTO :
1666 RADEON_AUDIO_DISABLE);
1664 subpixel_order = SubPixelHorizontalRGB; 1667 subpixel_order = SubPixelHorizontalRGB;
1665 connector->interlace_allowed = true; 1668 connector->interlace_allowed = true;
1666 if (connector_type == DRM_MODE_CONNECTOR_HDMIB) 1669 if (connector_type == DRM_MODE_CONNECTOR_HDMIB)
@@ -1754,10 +1757,12 @@ radeon_add_atom_connector(struct drm_device *dev,
1754 rdev->mode_info.underscan_vborder_property, 1757 rdev->mode_info.underscan_vborder_property,
1755 0); 1758 0);
1756 } 1759 }
1757 if (ASIC_IS_DCE2(rdev)) { 1760 if (ASIC_IS_DCE2(rdev) && (radeon_audio != 0)) {
1758 drm_object_attach_property(&radeon_connector->base.base, 1761 drm_object_attach_property(&radeon_connector->base.base,
1759 rdev->mode_info.audio_property, 1762 rdev->mode_info.audio_property,
1760 RADEON_AUDIO_DISABLE); 1763 (radeon_audio == 1) ?
1764 RADEON_AUDIO_AUTO :
1765 RADEON_AUDIO_DISABLE);
1761 } 1766 }
1762 if (connector_type == DRM_MODE_CONNECTOR_DVII) { 1767 if (connector_type == DRM_MODE_CONNECTOR_DVII) {
1763 radeon_connector->dac_load_detect = true; 1768 radeon_connector->dac_load_detect = true;
@@ -1799,10 +1804,12 @@ radeon_add_atom_connector(struct drm_device *dev,
1799 rdev->mode_info.underscan_vborder_property, 1804 rdev->mode_info.underscan_vborder_property,
1800 0); 1805 0);
1801 } 1806 }
1802 if (ASIC_IS_DCE2(rdev)) { 1807 if (ASIC_IS_DCE2(rdev) && (radeon_audio != 0)) {
1803 drm_object_attach_property(&radeon_connector->base.base, 1808 drm_object_attach_property(&radeon_connector->base.base,
1804 rdev->mode_info.audio_property, 1809 rdev->mode_info.audio_property,
1805 RADEON_AUDIO_DISABLE); 1810 (radeon_audio == 1) ?
1811 RADEON_AUDIO_AUTO :
1812 RADEON_AUDIO_DISABLE);
1806 } 1813 }
1807 subpixel_order = SubPixelHorizontalRGB; 1814 subpixel_order = SubPixelHorizontalRGB;
1808 connector->interlace_allowed = true; 1815 connector->interlace_allowed = true;
@@ -1843,10 +1850,12 @@ radeon_add_atom_connector(struct drm_device *dev,
1843 rdev->mode_info.underscan_vborder_property, 1850 rdev->mode_info.underscan_vborder_property,
1844 0); 1851 0);
1845 } 1852 }
1846 if (ASIC_IS_DCE2(rdev)) { 1853 if (ASIC_IS_DCE2(rdev) && (radeon_audio != 0)) {
1847 drm_object_attach_property(&radeon_connector->base.base, 1854 drm_object_attach_property(&radeon_connector->base.base,
1848 rdev->mode_info.audio_property, 1855 rdev->mode_info.audio_property,
1849 RADEON_AUDIO_DISABLE); 1856 (radeon_audio == 1) ?
1857 RADEON_AUDIO_AUTO :
1858 RADEON_AUDIO_DISABLE);
1850 } 1859 }
1851 connector->interlace_allowed = true; 1860 connector->interlace_allowed = true;
1852 /* in theory with a DP to VGA converter... */ 1861 /* in theory with a DP to VGA converter... */
diff --git a/drivers/gpu/drm/radeon/radeon_cs.c b/drivers/gpu/drm/radeon/radeon_cs.c
index 66c222836631..80285e35bc65 100644
--- a/drivers/gpu/drm/radeon/radeon_cs.c
+++ b/drivers/gpu/drm/radeon/radeon_cs.c
@@ -85,9 +85,8 @@ static int radeon_cs_parser_relocs(struct radeon_cs_parser *p)
85 VRAM, also but everything into VRAM on AGP cards to avoid 85 VRAM, also but everything into VRAM on AGP cards to avoid
86 image corruptions */ 86 image corruptions */
87 if (p->ring == R600_RING_TYPE_UVD_INDEX && 87 if (p->ring == R600_RING_TYPE_UVD_INDEX &&
88 p->rdev->family < CHIP_PALM &&
89 (i == 0 || drm_pci_device_is_agp(p->rdev->ddev))) { 88 (i == 0 || drm_pci_device_is_agp(p->rdev->ddev))) {
90 89 /* TODO: is this still needed for NI+ ? */
91 p->relocs[i].lobj.domain = 90 p->relocs[i].lobj.domain =
92 RADEON_GEM_DOMAIN_VRAM; 91 RADEON_GEM_DOMAIN_VRAM;
93 92
diff --git a/drivers/gpu/drm/radeon/radeon_drv.c b/drivers/gpu/drm/radeon/radeon_drv.c
index cdd12dcd988b..9c14a1ba1de4 100644
--- a/drivers/gpu/drm/radeon/radeon_drv.c
+++ b/drivers/gpu/drm/radeon/radeon_drv.c
@@ -153,7 +153,7 @@ int radeon_benchmarking = 0;
153int radeon_testing = 0; 153int radeon_testing = 0;
154int radeon_connector_table = 0; 154int radeon_connector_table = 0;
155int radeon_tv = 1; 155int radeon_tv = 1;
156int radeon_audio = 1; 156int radeon_audio = -1;
157int radeon_disp_priority = 0; 157int radeon_disp_priority = 0;
158int radeon_hw_i2c = 0; 158int radeon_hw_i2c = 0;
159int radeon_pcie_gen2 = -1; 159int radeon_pcie_gen2 = -1;
@@ -196,7 +196,7 @@ module_param_named(connector_table, radeon_connector_table, int, 0444);
196MODULE_PARM_DESC(tv, "TV enable (0 = disable)"); 196MODULE_PARM_DESC(tv, "TV enable (0 = disable)");
197module_param_named(tv, radeon_tv, int, 0444); 197module_param_named(tv, radeon_tv, int, 0444);
198 198
199MODULE_PARM_DESC(audio, "Audio enable (1 = enable)"); 199MODULE_PARM_DESC(audio, "Audio enable (-1 = auto, 0 = disable, 1 = enable)");
200module_param_named(audio, radeon_audio, int, 0444); 200module_param_named(audio, radeon_audio, int, 0444);
201 201
202MODULE_PARM_DESC(disp_priority, "Display Priority (0 = auto, 1 = normal, 2 = high)"); 202MODULE_PARM_DESC(disp_priority, "Display Priority (0 = auto, 1 = normal, 2 = high)");
diff --git a/drivers/gpu/drm/radeon/radeon_uvd.c b/drivers/gpu/drm/radeon/radeon_uvd.c
index 4f2e73f79638..308eff5be1b4 100644
--- a/drivers/gpu/drm/radeon/radeon_uvd.c
+++ b/drivers/gpu/drm/radeon/radeon_uvd.c
@@ -476,7 +476,8 @@ static int radeon_uvd_cs_reloc(struct radeon_cs_parser *p,
476 return -EINVAL; 476 return -EINVAL;
477 } 477 }
478 478
479 if (p->rdev->family < CHIP_PALM && (cmd == 0 || cmd == 0x3) && 479 /* TODO: is this still necessary on NI+ ? */
480 if ((cmd == 0 || cmd == 0x3) &&
480 (start >> 28) != (p->rdev->uvd.gpu_addr >> 28)) { 481 (start >> 28) != (p->rdev->uvd.gpu_addr >> 28)) {
481 DRM_ERROR("msg/fb buffer %LX-%LX out of 256MB segment!\n", 482 DRM_ERROR("msg/fb buffer %LX-%LX out of 256MB segment!\n",
482 start, end); 483 start, end);
diff --git a/drivers/gpu/drm/radeon/si.c b/drivers/gpu/drm/radeon/si.c
index d4652af425b8..d96f7cbca0a1 100644
--- a/drivers/gpu/drm/radeon/si.c
+++ b/drivers/gpu/drm/radeon/si.c
@@ -1681,6 +1681,7 @@ static int si_init_microcode(struct radeon_device *rdev)
1681 fw_name); 1681 fw_name);
1682 release_firmware(rdev->smc_fw); 1682 release_firmware(rdev->smc_fw);
1683 rdev->smc_fw = NULL; 1683 rdev->smc_fw = NULL;
1684 err = 0;
1684 } else if (rdev->smc_fw->size != smc_req_size) { 1685 } else if (rdev->smc_fw->size != smc_req_size) {
1685 printk(KERN_ERR 1686 printk(KERN_ERR
1686 "si_smc: Bogus length %zu in firmware \"%s\"\n", 1687 "si_smc: Bogus length %zu in firmware \"%s\"\n",
diff --git a/drivers/gpu/drm/radeon/uvd_v1_0.c b/drivers/gpu/drm/radeon/uvd_v1_0.c
index 3100fa9cb52f..7266805d9786 100644
--- a/drivers/gpu/drm/radeon/uvd_v1_0.c
+++ b/drivers/gpu/drm/radeon/uvd_v1_0.c
@@ -212,8 +212,8 @@ int uvd_v1_0_start(struct radeon_device *rdev)
212 /* enable VCPU clock */ 212 /* enable VCPU clock */
213 WREG32(UVD_VCPU_CNTL, 1 << 9); 213 WREG32(UVD_VCPU_CNTL, 1 << 9);
214 214
215 /* enable UMC and NC0 */ 215 /* enable UMC */
216 WREG32_P(UVD_LMI_CTRL2, 1 << 13, ~((1 << 8) | (1 << 13))); 216 WREG32_P(UVD_LMI_CTRL2, 0, ~(1 << 8));
217 217
218 /* boot up the VCPU */ 218 /* boot up the VCPU */
219 WREG32(UVD_SOFT_RESET, 0); 219 WREG32(UVD_SOFT_RESET, 0);
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
index 1a90f0a2f7e5..0508f93b9795 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
@@ -740,9 +740,17 @@ static void vmw_postclose(struct drm_device *dev,
740 struct vmw_fpriv *vmw_fp; 740 struct vmw_fpriv *vmw_fp;
741 741
742 vmw_fp = vmw_fpriv(file_priv); 742 vmw_fp = vmw_fpriv(file_priv);
743 ttm_object_file_release(&vmw_fp->tfile); 743
744 if (vmw_fp->locked_master) 744 if (vmw_fp->locked_master) {
745 struct vmw_master *vmaster =
746 vmw_master(vmw_fp->locked_master);
747
748 ttm_lock_set_kill(&vmaster->lock, true, SIGTERM);
749 ttm_vt_unlock(&vmaster->lock);
745 drm_master_put(&vmw_fp->locked_master); 750 drm_master_put(&vmw_fp->locked_master);
751 }
752
753 ttm_object_file_release(&vmw_fp->tfile);
746 kfree(vmw_fp); 754 kfree(vmw_fp);
747} 755}
748 756
@@ -925,14 +933,13 @@ static void vmw_master_drop(struct drm_device *dev,
925 933
926 vmw_fp->locked_master = drm_master_get(file_priv->master); 934 vmw_fp->locked_master = drm_master_get(file_priv->master);
927 ret = ttm_vt_lock(&vmaster->lock, false, vmw_fp->tfile); 935 ret = ttm_vt_lock(&vmaster->lock, false, vmw_fp->tfile);
928 vmw_execbuf_release_pinned_bo(dev_priv);
929
930 if (unlikely((ret != 0))) { 936 if (unlikely((ret != 0))) {
931 DRM_ERROR("Unable to lock TTM at VT switch.\n"); 937 DRM_ERROR("Unable to lock TTM at VT switch.\n");
932 drm_master_put(&vmw_fp->locked_master); 938 drm_master_put(&vmw_fp->locked_master);
933 } 939 }
934 940
935 ttm_lock_set_kill(&vmaster->lock, true, SIGTERM); 941 ttm_lock_set_kill(&vmaster->lock, false, SIGTERM);
942 vmw_execbuf_release_pinned_bo(dev_priv);
936 943
937 if (!dev_priv->enable_fb) { 944 if (!dev_priv->enable_fb) {
938 ret = ttm_bo_evict_mm(&dev_priv->bdev, TTM_PL_VRAM); 945 ret = ttm_bo_evict_mm(&dev_priv->bdev, TTM_PL_VRAM);
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c b/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c
index 0e67cf41065d..37fb4befec82 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c
@@ -970,7 +970,7 @@ void vmw_resource_unreserve(struct vmw_resource *res,
970 if (new_backup) 970 if (new_backup)
971 res->backup_offset = new_backup_offset; 971 res->backup_offset = new_backup_offset;
972 972
973 if (!res->func->may_evict) 973 if (!res->func->may_evict || res->id == -1)
974 return; 974 return;
975 975
976 write_lock(&dev_priv->resource_lock); 976 write_lock(&dev_priv->resource_lock);
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index 5a8c01112a23..e80da62363bc 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -319,7 +319,7 @@ static s32 item_sdata(struct hid_item *item)
319 319
320static int hid_parser_global(struct hid_parser *parser, struct hid_item *item) 320static int hid_parser_global(struct hid_parser *parser, struct hid_item *item)
321{ 321{
322 __u32 raw_value; 322 __s32 raw_value;
323 switch (item->tag) { 323 switch (item->tag) {
324 case HID_GLOBAL_ITEM_TAG_PUSH: 324 case HID_GLOBAL_ITEM_TAG_PUSH:
325 325
@@ -370,10 +370,11 @@ static int hid_parser_global(struct hid_parser *parser, struct hid_item *item)
370 return 0; 370 return 0;
371 371
372 case HID_GLOBAL_ITEM_TAG_UNIT_EXPONENT: 372 case HID_GLOBAL_ITEM_TAG_UNIT_EXPONENT:
373 /* Units exponent negative numbers are given through a 373 /* Many devices provide unit exponent as a two's complement
374 * two's complement. 374 * nibble due to the common misunderstanding of HID
375 * See "6.2.2.7 Global Items" for more information. */ 375 * specification 1.11, 6.2.2.7 Global Items. Attempt to handle
376 raw_value = item_udata(item); 376 * both this and the standard encoding. */
377 raw_value = item_sdata(item);
377 if (!(raw_value & 0xfffffff0)) 378 if (!(raw_value & 0xfffffff0))
378 parser->global.unit_exponent = hid_snto32(raw_value, 4); 379 parser->global.unit_exponent = hid_snto32(raw_value, 4);
379 else 380 else
@@ -1870,6 +1871,7 @@ static const struct hid_device_id hid_have_special_driver[] = {
1870 1871
1871 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_BT) }, 1872 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_BT) },
1872 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_NINTENDO, USB_DEVICE_ID_NINTENDO_WIIMOTE) }, 1873 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_NINTENDO, USB_DEVICE_ID_NINTENDO_WIIMOTE) },
1874 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_NINTENDO2, USB_DEVICE_ID_NINTENDO_WIIMOTE) },
1873 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_NINTENDO, USB_DEVICE_ID_NINTENDO_WIIMOTE2) }, 1875 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_NINTENDO, USB_DEVICE_ID_NINTENDO_WIIMOTE2) },
1874 { } 1876 { }
1875}; 1877};
diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
index 9cbc7ab07dfa..f0296a50be5f 100644
--- a/drivers/hid/hid-ids.h
+++ b/drivers/hid/hid-ids.h
@@ -633,6 +633,7 @@
633#define USB_DEVICE_ID_NEXTWINDOW_TOUCHSCREEN 0x0003 633#define USB_DEVICE_ID_NEXTWINDOW_TOUCHSCREEN 0x0003
634 634
635#define USB_VENDOR_ID_NINTENDO 0x057e 635#define USB_VENDOR_ID_NINTENDO 0x057e
636#define USB_VENDOR_ID_NINTENDO2 0x054c
636#define USB_DEVICE_ID_NINTENDO_WIIMOTE 0x0306 637#define USB_DEVICE_ID_NINTENDO_WIIMOTE 0x0306
637#define USB_DEVICE_ID_NINTENDO_WIIMOTE2 0x0330 638#define USB_DEVICE_ID_NINTENDO_WIIMOTE2 0x0330
638 639
@@ -792,6 +793,8 @@
792#define USB_DEVICE_ID_SYNAPTICS_COMP_TP 0x0009 793#define USB_DEVICE_ID_SYNAPTICS_COMP_TP 0x0009
793#define USB_DEVICE_ID_SYNAPTICS_WTP 0x0010 794#define USB_DEVICE_ID_SYNAPTICS_WTP 0x0010
794#define USB_DEVICE_ID_SYNAPTICS_DPAD 0x0013 795#define USB_DEVICE_ID_SYNAPTICS_DPAD 0x0013
796#define USB_DEVICE_ID_SYNAPTICS_LTS1 0x0af8
797#define USB_DEVICE_ID_SYNAPTICS_LTS2 0x1d10
795 798
796#define USB_VENDOR_ID_THINGM 0x27b8 799#define USB_VENDOR_ID_THINGM 0x27b8
797#define USB_DEVICE_ID_BLINK1 0x01ed 800#define USB_DEVICE_ID_BLINK1 0x01ed
@@ -919,4 +922,7 @@
919#define USB_VENDOR_ID_PRIMAX 0x0461 922#define USB_VENDOR_ID_PRIMAX 0x0461
920#define USB_DEVICE_ID_PRIMAX_KEYBOARD 0x4e05 923#define USB_DEVICE_ID_PRIMAX_KEYBOARD 0x4e05
921 924
925#define USB_VENDOR_ID_SIS 0x0457
926#define USB_DEVICE_ID_SIS_TS 0x1013
927
922#endif 928#endif
diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c
index 8741d953dcc8..d97f2323af57 100644
--- a/drivers/hid/hid-input.c
+++ b/drivers/hid/hid-input.c
@@ -192,6 +192,7 @@ static int hidinput_setkeycode(struct input_dev *dev,
192 return -EINVAL; 192 return -EINVAL;
193} 193}
194 194
195
195/** 196/**
196 * hidinput_calc_abs_res - calculate an absolute axis resolution 197 * hidinput_calc_abs_res - calculate an absolute axis resolution
197 * @field: the HID report field to calculate resolution for 198 * @field: the HID report field to calculate resolution for
@@ -234,23 +235,17 @@ __s32 hidinput_calc_abs_res(const struct hid_field *field, __u16 code)
234 case ABS_MT_TOOL_Y: 235 case ABS_MT_TOOL_Y:
235 case ABS_MT_TOUCH_MAJOR: 236 case ABS_MT_TOUCH_MAJOR:
236 case ABS_MT_TOUCH_MINOR: 237 case ABS_MT_TOUCH_MINOR:
237 if (field->unit & 0xffffff00) /* Not a length */ 238 if (field->unit == 0x11) { /* If centimeters */
238 return 0;
239 unit_exponent += hid_snto32(field->unit >> 4, 4) - 1;
240 switch (field->unit & 0xf) {
241 case 0x1: /* If centimeters */
242 /* Convert to millimeters */ 239 /* Convert to millimeters */
243 unit_exponent += 1; 240 unit_exponent += 1;
244 break; 241 } else if (field->unit == 0x13) { /* If inches */
245 case 0x3: /* If inches */
246 /* Convert to millimeters */ 242 /* Convert to millimeters */
247 prev = physical_extents; 243 prev = physical_extents;
248 physical_extents *= 254; 244 physical_extents *= 254;
249 if (physical_extents < prev) 245 if (physical_extents < prev)
250 return 0; 246 return 0;
251 unit_exponent -= 1; 247 unit_exponent -= 1;
252 break; 248 } else {
253 default:
254 return 0; 249 return 0;
255 } 250 }
256 break; 251 break;
diff --git a/drivers/hid/hid-wiimote-core.c b/drivers/hid/hid-wiimote-core.c
index abb20db2b443..1446f526ee8b 100644
--- a/drivers/hid/hid-wiimote-core.c
+++ b/drivers/hid/hid-wiimote-core.c
@@ -834,7 +834,8 @@ static void wiimote_init_set_type(struct wiimote_data *wdata,
834 goto done; 834 goto done;
835 } 835 }
836 836
837 if (vendor == USB_VENDOR_ID_NINTENDO) { 837 if (vendor == USB_VENDOR_ID_NINTENDO ||
838 vendor == USB_VENDOR_ID_NINTENDO2) {
838 if (product == USB_DEVICE_ID_NINTENDO_WIIMOTE) { 839 if (product == USB_DEVICE_ID_NINTENDO_WIIMOTE) {
839 devtype = WIIMOTE_DEV_GEN10; 840 devtype = WIIMOTE_DEV_GEN10;
840 goto done; 841 goto done;
@@ -1855,6 +1856,8 @@ static void wiimote_hid_remove(struct hid_device *hdev)
1855static const struct hid_device_id wiimote_hid_devices[] = { 1856static const struct hid_device_id wiimote_hid_devices[] = {
1856 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_NINTENDO, 1857 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_NINTENDO,
1857 USB_DEVICE_ID_NINTENDO_WIIMOTE) }, 1858 USB_DEVICE_ID_NINTENDO_WIIMOTE) },
1859 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_NINTENDO2,
1860 USB_DEVICE_ID_NINTENDO_WIIMOTE) },
1858 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_NINTENDO, 1861 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_NINTENDO,
1859 USB_DEVICE_ID_NINTENDO_WIIMOTE2) }, 1862 USB_DEVICE_ID_NINTENDO_WIIMOTE2) },
1860 { } 1863 { }
diff --git a/drivers/hid/usbhid/hid-quirks.c b/drivers/hid/usbhid/hid-quirks.c
index 07345521f421..3fca3be08337 100644
--- a/drivers/hid/usbhid/hid-quirks.c
+++ b/drivers/hid/usbhid/hid-quirks.c
@@ -110,6 +110,9 @@ static const struct hid_blacklist {
110 { USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_MOUSEPEN_I608X, HID_QUIRK_MULTI_INPUT }, 110 { USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_MOUSEPEN_I608X, HID_QUIRK_MULTI_INPUT },
111 { USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_EASYPEN_M610X, HID_QUIRK_MULTI_INPUT }, 111 { USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_EASYPEN_M610X, HID_QUIRK_MULTI_INPUT },
112 { USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_DUOSENSE, HID_QUIRK_NO_INIT_REPORTS }, 112 { USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_DUOSENSE, HID_QUIRK_NO_INIT_REPORTS },
113 { USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_LTS1, HID_QUIRK_NO_INIT_REPORTS },
114 { USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_LTS2, HID_QUIRK_NO_INIT_REPORTS },
115 { USB_VENDOR_ID_SIS, USB_DEVICE_ID_SIS_TS, HID_QUIRK_NO_INIT_REPORTS },
113 116
114 { 0, 0 } 117 { 0, 0 }
115}; 118};
diff --git a/drivers/infiniband/Kconfig b/drivers/infiniband/Kconfig
index 5ceda710f516..b84791f03a27 100644
--- a/drivers/infiniband/Kconfig
+++ b/drivers/infiniband/Kconfig
@@ -31,6 +31,17 @@ config INFINIBAND_USER_ACCESS
31 libibverbs, libibcm and a hardware driver library from 31 libibverbs, libibcm and a hardware driver library from
32 <http://www.openfabrics.org/git/>. 32 <http://www.openfabrics.org/git/>.
33 33
34config INFINIBAND_EXPERIMENTAL_UVERBS_FLOW_STEERING
35 bool "Experimental and unstable ABI for userspace access to flow steering verbs"
36 depends on INFINIBAND_USER_ACCESS
37 depends on STAGING
38 ---help---
39 The final ABI for userspace access to flow steering verbs
40 has not been defined. To use the current ABI, *WHICH WILL
41 CHANGE IN THE FUTURE*, say Y here.
42
43 If unsure, say N.
44
34config INFINIBAND_USER_MEM 45config INFINIBAND_USER_MEM
35 bool 46 bool
36 depends on INFINIBAND_USER_ACCESS != n 47 depends on INFINIBAND_USER_ACCESS != n
diff --git a/drivers/infiniband/core/uverbs.h b/drivers/infiniband/core/uverbs.h
index d040b877475f..d8f9c6c272d7 100644
--- a/drivers/infiniband/core/uverbs.h
+++ b/drivers/infiniband/core/uverbs.h
@@ -217,7 +217,9 @@ IB_UVERBS_DECLARE_CMD(destroy_srq);
217IB_UVERBS_DECLARE_CMD(create_xsrq); 217IB_UVERBS_DECLARE_CMD(create_xsrq);
218IB_UVERBS_DECLARE_CMD(open_xrcd); 218IB_UVERBS_DECLARE_CMD(open_xrcd);
219IB_UVERBS_DECLARE_CMD(close_xrcd); 219IB_UVERBS_DECLARE_CMD(close_xrcd);
220#ifdef CONFIG_INFINIBAND_EXPERIMENTAL_UVERBS_FLOW_STEERING
220IB_UVERBS_DECLARE_CMD(create_flow); 221IB_UVERBS_DECLARE_CMD(create_flow);
221IB_UVERBS_DECLARE_CMD(destroy_flow); 222IB_UVERBS_DECLARE_CMD(destroy_flow);
223#endif /* CONFIG_INFINIBAND_EXPERIMENTAL_UVERBS_FLOW_STEERING */
222 224
223#endif /* UVERBS_H */ 225#endif /* UVERBS_H */
diff --git a/drivers/infiniband/core/uverbs_cmd.c b/drivers/infiniband/core/uverbs_cmd.c
index f2b81b9ee0d6..2f0f01b70e3b 100644
--- a/drivers/infiniband/core/uverbs_cmd.c
+++ b/drivers/infiniband/core/uverbs_cmd.c
@@ -54,7 +54,9 @@ static struct uverbs_lock_class qp_lock_class = { .name = "QP-uobj" };
54static struct uverbs_lock_class ah_lock_class = { .name = "AH-uobj" }; 54static struct uverbs_lock_class ah_lock_class = { .name = "AH-uobj" };
55static struct uverbs_lock_class srq_lock_class = { .name = "SRQ-uobj" }; 55static struct uverbs_lock_class srq_lock_class = { .name = "SRQ-uobj" };
56static struct uverbs_lock_class xrcd_lock_class = { .name = "XRCD-uobj" }; 56static struct uverbs_lock_class xrcd_lock_class = { .name = "XRCD-uobj" };
57#ifdef CONFIG_INFINIBAND_EXPERIMENTAL_UVERBS_FLOW_STEERING
57static struct uverbs_lock_class rule_lock_class = { .name = "RULE-uobj" }; 58static struct uverbs_lock_class rule_lock_class = { .name = "RULE-uobj" };
59#endif /* CONFIG_INFINIBAND_EXPERIMENTAL_UVERBS_FLOW_STEERING */
58 60
59#define INIT_UDATA(udata, ibuf, obuf, ilen, olen) \ 61#define INIT_UDATA(udata, ibuf, obuf, ilen, olen) \
60 do { \ 62 do { \
@@ -2599,6 +2601,7 @@ out_put:
2599 return ret ? ret : in_len; 2601 return ret ? ret : in_len;
2600} 2602}
2601 2603
2604#ifdef CONFIG_INFINIBAND_EXPERIMENTAL_UVERBS_FLOW_STEERING
2602static int kern_spec_to_ib_spec(struct ib_kern_spec *kern_spec, 2605static int kern_spec_to_ib_spec(struct ib_kern_spec *kern_spec,
2603 union ib_flow_spec *ib_spec) 2606 union ib_flow_spec *ib_spec)
2604{ 2607{
@@ -2824,6 +2827,7 @@ ssize_t ib_uverbs_destroy_flow(struct ib_uverbs_file *file,
2824 2827
2825 return ret ? ret : in_len; 2828 return ret ? ret : in_len;
2826} 2829}
2830#endif /* CONFIG_INFINIBAND_EXPERIMENTAL_UVERBS_FLOW_STEERING */
2827 2831
2828static int __uverbs_create_xsrq(struct ib_uverbs_file *file, 2832static int __uverbs_create_xsrq(struct ib_uverbs_file *file,
2829 struct ib_uverbs_create_xsrq *cmd, 2833 struct ib_uverbs_create_xsrq *cmd,
diff --git a/drivers/infiniband/core/uverbs_main.c b/drivers/infiniband/core/uverbs_main.c
index 75ad86c4abf8..2df31f68ea09 100644
--- a/drivers/infiniband/core/uverbs_main.c
+++ b/drivers/infiniband/core/uverbs_main.c
@@ -115,8 +115,10 @@ static ssize_t (*uverbs_cmd_table[])(struct ib_uverbs_file *file,
115 [IB_USER_VERBS_CMD_CLOSE_XRCD] = ib_uverbs_close_xrcd, 115 [IB_USER_VERBS_CMD_CLOSE_XRCD] = ib_uverbs_close_xrcd,
116 [IB_USER_VERBS_CMD_CREATE_XSRQ] = ib_uverbs_create_xsrq, 116 [IB_USER_VERBS_CMD_CREATE_XSRQ] = ib_uverbs_create_xsrq,
117 [IB_USER_VERBS_CMD_OPEN_QP] = ib_uverbs_open_qp, 117 [IB_USER_VERBS_CMD_OPEN_QP] = ib_uverbs_open_qp,
118#ifdef CONFIG_INFINIBAND_EXPERIMENTAL_UVERBS_FLOW_STEERING
118 [IB_USER_VERBS_CMD_CREATE_FLOW] = ib_uverbs_create_flow, 119 [IB_USER_VERBS_CMD_CREATE_FLOW] = ib_uverbs_create_flow,
119 [IB_USER_VERBS_CMD_DESTROY_FLOW] = ib_uverbs_destroy_flow 120 [IB_USER_VERBS_CMD_DESTROY_FLOW] = ib_uverbs_destroy_flow
121#endif /* CONFIG_INFINIBAND_EXPERIMENTAL_UVERBS_FLOW_STEERING */
120}; 122};
121 123
122static void ib_uverbs_add_one(struct ib_device *device); 124static void ib_uverbs_add_one(struct ib_device *device);
@@ -605,6 +607,7 @@ static ssize_t ib_uverbs_write(struct file *filp, const char __user *buf,
605 if (!(file->device->ib_dev->uverbs_cmd_mask & (1ull << hdr.command))) 607 if (!(file->device->ib_dev->uverbs_cmd_mask & (1ull << hdr.command)))
606 return -ENOSYS; 608 return -ENOSYS;
607 609
610#ifdef CONFIG_INFINIBAND_EXPERIMENTAL_UVERBS_FLOW_STEERING
608 if (hdr.command >= IB_USER_VERBS_CMD_THRESHOLD) { 611 if (hdr.command >= IB_USER_VERBS_CMD_THRESHOLD) {
609 struct ib_uverbs_cmd_hdr_ex hdr_ex; 612 struct ib_uverbs_cmd_hdr_ex hdr_ex;
610 613
@@ -621,6 +624,7 @@ static ssize_t ib_uverbs_write(struct file *filp, const char __user *buf,
621 (hdr_ex.out_words + 624 (hdr_ex.out_words +
622 hdr_ex.provider_out_words) * 4); 625 hdr_ex.provider_out_words) * 4);
623 } else { 626 } else {
627#endif /* CONFIG_INFINIBAND_EXPERIMENTAL_UVERBS_FLOW_STEERING */
624 if (hdr.in_words * 4 != count) 628 if (hdr.in_words * 4 != count)
625 return -EINVAL; 629 return -EINVAL;
626 630
@@ -628,7 +632,9 @@ static ssize_t ib_uverbs_write(struct file *filp, const char __user *buf,
628 buf + sizeof(hdr), 632 buf + sizeof(hdr),
629 hdr.in_words * 4, 633 hdr.in_words * 4,
630 hdr.out_words * 4); 634 hdr.out_words * 4);
635#ifdef CONFIG_INFINIBAND_EXPERIMENTAL_UVERBS_FLOW_STEERING
631 } 636 }
637#endif /* CONFIG_INFINIBAND_EXPERIMENTAL_UVERBS_FLOW_STEERING */
632} 638}
633 639
634static int ib_uverbs_mmap(struct file *filp, struct vm_area_struct *vma) 640static int ib_uverbs_mmap(struct file *filp, struct vm_area_struct *vma)
diff --git a/drivers/infiniband/hw/mlx4/main.c b/drivers/infiniband/hw/mlx4/main.c
index d6c5a73becf4..f0612645de99 100644
--- a/drivers/infiniband/hw/mlx4/main.c
+++ b/drivers/infiniband/hw/mlx4/main.c
@@ -1691,9 +1691,11 @@ static void *mlx4_ib_add(struct mlx4_dev *dev)
1691 ibdev->ib_dev.create_flow = mlx4_ib_create_flow; 1691 ibdev->ib_dev.create_flow = mlx4_ib_create_flow;
1692 ibdev->ib_dev.destroy_flow = mlx4_ib_destroy_flow; 1692 ibdev->ib_dev.destroy_flow = mlx4_ib_destroy_flow;
1693 1693
1694#ifdef CONFIG_INFINIBAND_EXPERIMENTAL_UVERBS_FLOW_STEERING
1694 ibdev->ib_dev.uverbs_cmd_mask |= 1695 ibdev->ib_dev.uverbs_cmd_mask |=
1695 (1ull << IB_USER_VERBS_CMD_CREATE_FLOW) | 1696 (1ull << IB_USER_VERBS_CMD_CREATE_FLOW) |
1696 (1ull << IB_USER_VERBS_CMD_DESTROY_FLOW); 1697 (1ull << IB_USER_VERBS_CMD_DESTROY_FLOW);
1698#endif /* CONFIG_INFINIBAND_EXPERIMENTAL_UVERBS_FLOW_STEERING */
1697 } 1699 }
1698 1700
1699 mlx4_ib_alloc_eqs(dev, ibdev); 1701 mlx4_ib_alloc_eqs(dev, ibdev);
diff --git a/drivers/infiniband/ulp/isert/ib_isert.c b/drivers/infiniband/ulp/isert/ib_isert.c
index 3591855cc5b5..6df23502059a 100644
--- a/drivers/infiniband/ulp/isert/ib_isert.c
+++ b/drivers/infiniband/ulp/isert/ib_isert.c
@@ -594,7 +594,7 @@ isert_connect_release(struct isert_conn *isert_conn)
594 594
595 pr_debug("Entering isert_connect_release(): >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n"); 595 pr_debug("Entering isert_connect_release(): >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
596 596
597 if (device->use_frwr) 597 if (device && device->use_frwr)
598 isert_conn_free_frwr_pool(isert_conn); 598 isert_conn_free_frwr_pool(isert_conn);
599 599
600 if (isert_conn->conn_qp) { 600 if (isert_conn->conn_qp) {
diff --git a/drivers/input/input.c b/drivers/input/input.c
index c04469928925..e75d015024a1 100644
--- a/drivers/input/input.c
+++ b/drivers/input/input.c
@@ -1734,6 +1734,7 @@ EXPORT_SYMBOL_GPL(input_class);
1734 */ 1734 */
1735struct input_dev *input_allocate_device(void) 1735struct input_dev *input_allocate_device(void)
1736{ 1736{
1737 static atomic_t input_no = ATOMIC_INIT(0);
1737 struct input_dev *dev; 1738 struct input_dev *dev;
1738 1739
1739 dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL); 1740 dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL);
@@ -1743,9 +1744,13 @@ struct input_dev *input_allocate_device(void)
1743 device_initialize(&dev->dev); 1744 device_initialize(&dev->dev);
1744 mutex_init(&dev->mutex); 1745 mutex_init(&dev->mutex);
1745 spin_lock_init(&dev->event_lock); 1746 spin_lock_init(&dev->event_lock);
1747 init_timer(&dev->timer);
1746 INIT_LIST_HEAD(&dev->h_list); 1748 INIT_LIST_HEAD(&dev->h_list);
1747 INIT_LIST_HEAD(&dev->node); 1749 INIT_LIST_HEAD(&dev->node);
1748 1750
1751 dev_set_name(&dev->dev, "input%ld",
1752 (unsigned long) atomic_inc_return(&input_no) - 1);
1753
1749 __module_get(THIS_MODULE); 1754 __module_get(THIS_MODULE);
1750 } 1755 }
1751 1756
@@ -2019,7 +2024,6 @@ static void devm_input_device_unregister(struct device *dev, void *res)
2019 */ 2024 */
2020int input_register_device(struct input_dev *dev) 2025int input_register_device(struct input_dev *dev)
2021{ 2026{
2022 static atomic_t input_no = ATOMIC_INIT(0);
2023 struct input_devres *devres = NULL; 2027 struct input_devres *devres = NULL;
2024 struct input_handler *handler; 2028 struct input_handler *handler;
2025 unsigned int packet_size; 2029 unsigned int packet_size;
@@ -2059,7 +2063,6 @@ int input_register_device(struct input_dev *dev)
2059 * If delay and period are pre-set by the driver, then autorepeating 2063 * If delay and period are pre-set by the driver, then autorepeating
2060 * is handled by the driver itself and we don't do it in input.c. 2064 * is handled by the driver itself and we don't do it in input.c.
2061 */ 2065 */
2062 init_timer(&dev->timer);
2063 if (!dev->rep[REP_DELAY] && !dev->rep[REP_PERIOD]) { 2066 if (!dev->rep[REP_DELAY] && !dev->rep[REP_PERIOD]) {
2064 dev->timer.data = (long) dev; 2067 dev->timer.data = (long) dev;
2065 dev->timer.function = input_repeat_key; 2068 dev->timer.function = input_repeat_key;
@@ -2073,9 +2076,6 @@ int input_register_device(struct input_dev *dev)
2073 if (!dev->setkeycode) 2076 if (!dev->setkeycode)
2074 dev->setkeycode = input_default_setkeycode; 2077 dev->setkeycode = input_default_setkeycode;
2075 2078
2076 dev_set_name(&dev->dev, "input%ld",
2077 (unsigned long) atomic_inc_return(&input_no) - 1);
2078
2079 error = device_add(&dev->dev); 2079 error = device_add(&dev->dev);
2080 if (error) 2080 if (error)
2081 goto err_free_vals; 2081 goto err_free_vals;
diff --git a/drivers/input/keyboard/pxa27x_keypad.c b/drivers/input/keyboard/pxa27x_keypad.c
index 134c3b404a54..a2e758d27584 100644
--- a/drivers/input/keyboard/pxa27x_keypad.c
+++ b/drivers/input/keyboard/pxa27x_keypad.c
@@ -786,10 +786,17 @@ static int pxa27x_keypad_probe(struct platform_device *pdev)
786 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP); 786 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP);
787 input_set_capability(input_dev, EV_MSC, MSC_SCAN); 787 input_set_capability(input_dev, EV_MSC, MSC_SCAN);
788 788
789 if (pdata) 789 if (pdata) {
790 error = pxa27x_keypad_build_keycode(keypad); 790 error = pxa27x_keypad_build_keycode(keypad);
791 else 791 } else {
792 error = pxa27x_keypad_build_keycode_from_dt(keypad); 792 error = pxa27x_keypad_build_keycode_from_dt(keypad);
793 /*
794 * Data that we get from DT resides in dynamically
795 * allocated memory so we need to update our pdata
796 * pointer.
797 */
798 pdata = keypad->pdata;
799 }
793 if (error) { 800 if (error) {
794 dev_err(&pdev->dev, "failed to build keycode\n"); 801 dev_err(&pdev->dev, "failed to build keycode\n");
795 goto failed_put_clk; 802 goto failed_put_clk;
diff --git a/drivers/input/misc/cm109.c b/drivers/input/misc/cm109.c
index 082684e7f390..9365535ba7f1 100644
--- a/drivers/input/misc/cm109.c
+++ b/drivers/input/misc/cm109.c
@@ -351,7 +351,9 @@ static void cm109_urb_irq_callback(struct urb *urb)
351 if (status) { 351 if (status) {
352 if (status == -ESHUTDOWN) 352 if (status == -ESHUTDOWN)
353 return; 353 return;
354 dev_err(&dev->intf->dev, "%s: urb status %d\n", __func__, status); 354 dev_err_ratelimited(&dev->intf->dev, "%s: urb status %d\n",
355 __func__, status);
356 goto out;
355 } 357 }
356 358
357 /* Special keys */ 359 /* Special keys */
@@ -418,8 +420,12 @@ static void cm109_urb_ctl_callback(struct urb *urb)
418 dev->ctl_data->byte[2], 420 dev->ctl_data->byte[2],
419 dev->ctl_data->byte[3]); 421 dev->ctl_data->byte[3]);
420 422
421 if (status) 423 if (status) {
422 dev_err(&dev->intf->dev, "%s: urb status %d\n", __func__, status); 424 if (status == -ESHUTDOWN)
425 return;
426 dev_err_ratelimited(&dev->intf->dev, "%s: urb status %d\n",
427 __func__, status);
428 }
423 429
424 spin_lock(&dev->ctl_submit_lock); 430 spin_lock(&dev->ctl_submit_lock);
425 431
@@ -427,7 +433,7 @@ static void cm109_urb_ctl_callback(struct urb *urb)
427 433
428 if (likely(!dev->shutdown)) { 434 if (likely(!dev->shutdown)) {
429 435
430 if (dev->buzzer_pending) { 436 if (dev->buzzer_pending || status) {
431 dev->buzzer_pending = 0; 437 dev->buzzer_pending = 0;
432 dev->ctl_urb_pending = 1; 438 dev->ctl_urb_pending = 1;
433 cm109_submit_buzz_toggle(dev); 439 cm109_submit_buzz_toggle(dev);
diff --git a/drivers/input/mouse/alps.c b/drivers/input/mouse/alps.c
index 7c5d72a6a26a..83658472ad25 100644
--- a/drivers/input/mouse/alps.c
+++ b/drivers/input/mouse/alps.c
@@ -103,6 +103,7 @@ static const struct alps_model_info alps_model_data[] = {
103 /* Dell Latitude E5500, E6400, E6500, Precision M4400 */ 103 /* Dell Latitude E5500, E6400, E6500, Precision M4400 */
104 { { 0x62, 0x02, 0x14 }, 0x00, ALPS_PROTO_V2, 0xcf, 0xcf, 104 { { 0x62, 0x02, 0x14 }, 0x00, ALPS_PROTO_V2, 0xcf, 0xcf,
105 ALPS_PASS | ALPS_DUALPOINT | ALPS_PS2_INTERLEAVED }, 105 ALPS_PASS | ALPS_DUALPOINT | ALPS_PS2_INTERLEAVED },
106 { { 0x73, 0x00, 0x14 }, 0x00, ALPS_PROTO_V2, 0xcf, 0xcf, ALPS_DUALPOINT }, /* Dell XT2 */
106 { { 0x73, 0x02, 0x50 }, 0x00, ALPS_PROTO_V2, 0xcf, 0xcf, ALPS_FOUR_BUTTONS }, /* Dell Vostro 1400 */ 107 { { 0x73, 0x02, 0x50 }, 0x00, ALPS_PROTO_V2, 0xcf, 0xcf, ALPS_FOUR_BUTTONS }, /* Dell Vostro 1400 */
107 { { 0x52, 0x01, 0x14 }, 0x00, ALPS_PROTO_V2, 0xff, 0xff, 108 { { 0x52, 0x01, 0x14 }, 0x00, ALPS_PROTO_V2, 0xff, 0xff,
108 ALPS_PASS | ALPS_DUALPOINT | ALPS_PS2_INTERLEAVED }, /* Toshiba Tecra A11-11L */ 109 ALPS_PASS | ALPS_DUALPOINT | ALPS_PS2_INTERLEAVED }, /* Toshiba Tecra A11-11L */
diff --git a/drivers/input/serio/i8042.c b/drivers/input/serio/i8042.c
index 78e4de42efaa..52c9ebf94729 100644
--- a/drivers/input/serio/i8042.c
+++ b/drivers/input/serio/i8042.c
@@ -223,21 +223,26 @@ static int i8042_flush(void)
223{ 223{
224 unsigned long flags; 224 unsigned long flags;
225 unsigned char data, str; 225 unsigned char data, str;
226 int i = 0; 226 int count = 0;
227 int retval = 0;
227 228
228 spin_lock_irqsave(&i8042_lock, flags); 229 spin_lock_irqsave(&i8042_lock, flags);
229 230
230 while (((str = i8042_read_status()) & I8042_STR_OBF) && (i < I8042_BUFFER_SIZE)) { 231 while ((str = i8042_read_status()) & I8042_STR_OBF) {
231 udelay(50); 232 if (count++ < I8042_BUFFER_SIZE) {
232 data = i8042_read_data(); 233 udelay(50);
233 i++; 234 data = i8042_read_data();
234 dbg("%02x <- i8042 (flush, %s)\n", 235 dbg("%02x <- i8042 (flush, %s)\n",
235 data, str & I8042_STR_AUXDATA ? "aux" : "kbd"); 236 data, str & I8042_STR_AUXDATA ? "aux" : "kbd");
237 } else {
238 retval = -EIO;
239 break;
240 }
236 } 241 }
237 242
238 spin_unlock_irqrestore(&i8042_lock, flags); 243 spin_unlock_irqrestore(&i8042_lock, flags);
239 244
240 return i; 245 return retval;
241} 246}
242 247
243/* 248/*
@@ -849,7 +854,7 @@ static int __init i8042_check_aux(void)
849 854
850static int i8042_controller_check(void) 855static int i8042_controller_check(void)
851{ 856{
852 if (i8042_flush() == I8042_BUFFER_SIZE) { 857 if (i8042_flush()) {
853 pr_err("No controller found\n"); 858 pr_err("No controller found\n");
854 return -ENODEV; 859 return -ENODEV;
855 } 860 }
diff --git a/drivers/input/tablet/wacom_sys.c b/drivers/input/tablet/wacom_sys.c
index 79b69ea47f74..e53416a4d7f3 100644
--- a/drivers/input/tablet/wacom_sys.c
+++ b/drivers/input/tablet/wacom_sys.c
@@ -1031,6 +1031,7 @@ static void wacom_destroy_leds(struct wacom *wacom)
1031} 1031}
1032 1032
1033static enum power_supply_property wacom_battery_props[] = { 1033static enum power_supply_property wacom_battery_props[] = {
1034 POWER_SUPPLY_PROP_SCOPE,
1034 POWER_SUPPLY_PROP_CAPACITY 1035 POWER_SUPPLY_PROP_CAPACITY
1035}; 1036};
1036 1037
@@ -1042,6 +1043,9 @@ static int wacom_battery_get_property(struct power_supply *psy,
1042 int ret = 0; 1043 int ret = 0;
1043 1044
1044 switch (psp) { 1045 switch (psp) {
1046 case POWER_SUPPLY_PROP_SCOPE:
1047 val->intval = POWER_SUPPLY_SCOPE_DEVICE;
1048 break;
1045 case POWER_SUPPLY_PROP_CAPACITY: 1049 case POWER_SUPPLY_PROP_CAPACITY:
1046 val->intval = 1050 val->intval =
1047 wacom->wacom_wac.battery_capacity * 100 / 31; 1051 wacom->wacom_wac.battery_capacity * 100 / 31;
diff --git a/drivers/input/tablet/wacom_wac.c b/drivers/input/tablet/wacom_wac.c
index b2aa503c16b1..c59b797eeafa 100644
--- a/drivers/input/tablet/wacom_wac.c
+++ b/drivers/input/tablet/wacom_wac.c
@@ -2054,6 +2054,12 @@ static const struct wacom_features wacom_features_0x101 =
2054static const struct wacom_features wacom_features_0x10D = 2054static const struct wacom_features wacom_features_0x10D =
2055 { "Wacom ISDv4 10D", WACOM_PKGLEN_MTTPC, 26202, 16325, 255, 2055 { "Wacom ISDv4 10D", WACOM_PKGLEN_MTTPC, 26202, 16325, 255,
2056 0, MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES }; 2056 0, MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
2057static const struct wacom_features wacom_features_0x10E =
2058 { "Wacom ISDv4 10E", WACOM_PKGLEN_MTTPC, 27760, 15694, 255,
2059 0, MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
2060static const struct wacom_features wacom_features_0x10F =
2061 { "Wacom ISDv4 10F", WACOM_PKGLEN_MTTPC, 27760, 15694, 255,
2062 0, MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
2057static const struct wacom_features wacom_features_0x4001 = 2063static const struct wacom_features wacom_features_0x4001 =
2058 { "Wacom ISDv4 4001", WACOM_PKGLEN_MTTPC, 26202, 16325, 255, 2064 { "Wacom ISDv4 4001", WACOM_PKGLEN_MTTPC, 26202, 16325, 255,
2059 0, MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES }; 2065 0, MTTPC, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
@@ -2248,6 +2254,8 @@ const struct usb_device_id wacom_ids[] = {
2248 { USB_DEVICE_WACOM(0x100) }, 2254 { USB_DEVICE_WACOM(0x100) },
2249 { USB_DEVICE_WACOM(0x101) }, 2255 { USB_DEVICE_WACOM(0x101) },
2250 { USB_DEVICE_WACOM(0x10D) }, 2256 { USB_DEVICE_WACOM(0x10D) },
2257 { USB_DEVICE_WACOM(0x10E) },
2258 { USB_DEVICE_WACOM(0x10F) },
2251 { USB_DEVICE_WACOM(0x300) }, 2259 { USB_DEVICE_WACOM(0x300) },
2252 { USB_DEVICE_WACOM(0x301) }, 2260 { USB_DEVICE_WACOM(0x301) },
2253 { USB_DEVICE_WACOM(0x304) }, 2261 { USB_DEVICE_WACOM(0x304) },
diff --git a/drivers/md/bcache/request.c b/drivers/md/bcache/request.c
index b6a74bcbb08f..2a7f0dd6abab 100644
--- a/drivers/md/bcache/request.c
+++ b/drivers/md/bcache/request.c
@@ -1000,7 +1000,7 @@ static void request_write(struct cached_dev *dc, struct search *s)
1000 1000
1001 if (bio->bi_rw & REQ_FLUSH) { 1001 if (bio->bi_rw & REQ_FLUSH) {
1002 /* Also need to send a flush to the backing device */ 1002 /* Also need to send a flush to the backing device */
1003 struct bio *flush = bio_alloc_bioset(0, GFP_NOIO, 1003 struct bio *flush = bio_alloc_bioset(GFP_NOIO, 0,
1004 dc->disk.bio_split); 1004 dc->disk.bio_split);
1005 1005
1006 flush->bi_rw = WRITE_FLUSH; 1006 flush->bi_rw = WRITE_FLUSH;
diff --git a/drivers/md/md.c b/drivers/md/md.c
index adf4d7e1d5e1..561a65f82e26 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -8111,6 +8111,7 @@ static int md_set_badblocks(struct badblocks *bb, sector_t s, int sectors,
8111 u64 *p; 8111 u64 *p;
8112 int lo, hi; 8112 int lo, hi;
8113 int rv = 1; 8113 int rv = 1;
8114 unsigned long flags;
8114 8115
8115 if (bb->shift < 0) 8116 if (bb->shift < 0)
8116 /* badblocks are disabled */ 8117 /* badblocks are disabled */
@@ -8125,7 +8126,7 @@ static int md_set_badblocks(struct badblocks *bb, sector_t s, int sectors,
8125 sectors = next - s; 8126 sectors = next - s;
8126 } 8127 }
8127 8128
8128 write_seqlock_irq(&bb->lock); 8129 write_seqlock_irqsave(&bb->lock, flags);
8129 8130
8130 p = bb->page; 8131 p = bb->page;
8131 lo = 0; 8132 lo = 0;
@@ -8241,7 +8242,7 @@ static int md_set_badblocks(struct badblocks *bb, sector_t s, int sectors,
8241 bb->changed = 1; 8242 bb->changed = 1;
8242 if (!acknowledged) 8243 if (!acknowledged)
8243 bb->unacked_exist = 1; 8244 bb->unacked_exist = 1;
8244 write_sequnlock_irq(&bb->lock); 8245 write_sequnlock_irqrestore(&bb->lock, flags);
8245 8246
8246 return rv; 8247 return rv;
8247} 8248}
diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index d60412c7f995..aacf6bf352d8 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -1479,6 +1479,7 @@ static int raid1_spare_active(struct mddev *mddev)
1479 } 1479 }
1480 } 1480 }
1481 if (rdev 1481 if (rdev
1482 && rdev->recovery_offset == MaxSector
1482 && !test_bit(Faulty, &rdev->flags) 1483 && !test_bit(Faulty, &rdev->flags)
1483 && !test_and_set_bit(In_sync, &rdev->flags)) { 1484 && !test_and_set_bit(In_sync, &rdev->flags)) {
1484 count++; 1485 count++;
diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index df7b0a06b0ea..73dc8a377522 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -1782,6 +1782,7 @@ static int raid10_spare_active(struct mddev *mddev)
1782 } 1782 }
1783 sysfs_notify_dirent_safe(tmp->replacement->sysfs_state); 1783 sysfs_notify_dirent_safe(tmp->replacement->sysfs_state);
1784 } else if (tmp->rdev 1784 } else if (tmp->rdev
1785 && tmp->rdev->recovery_offset == MaxSector
1785 && !test_bit(Faulty, &tmp->rdev->flags) 1786 && !test_bit(Faulty, &tmp->rdev->flags)
1786 && !test_and_set_bit(In_sync, &tmp->rdev->flags)) { 1787 && !test_and_set_bit(In_sync, &tmp->rdev->flags)) {
1787 count++; 1788 count++;
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index 7ff4f252ca1a..f8b906843926 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -778,6 +778,12 @@ static void ops_run_io(struct stripe_head *sh, struct stripe_head_state *s)
778 bi->bi_io_vec[0].bv_len = STRIPE_SIZE; 778 bi->bi_io_vec[0].bv_len = STRIPE_SIZE;
779 bi->bi_io_vec[0].bv_offset = 0; 779 bi->bi_io_vec[0].bv_offset = 0;
780 bi->bi_size = STRIPE_SIZE; 780 bi->bi_size = STRIPE_SIZE;
781 /*
782 * If this is discard request, set bi_vcnt 0. We don't
783 * want to confuse SCSI because SCSI will replace payload
784 */
785 if (rw & REQ_DISCARD)
786 bi->bi_vcnt = 0;
781 if (rrdev) 787 if (rrdev)
782 set_bit(R5_DOUBLE_LOCKED, &sh->dev[i].flags); 788 set_bit(R5_DOUBLE_LOCKED, &sh->dev[i].flags);
783 789
@@ -816,6 +822,12 @@ static void ops_run_io(struct stripe_head *sh, struct stripe_head_state *s)
816 rbi->bi_io_vec[0].bv_len = STRIPE_SIZE; 822 rbi->bi_io_vec[0].bv_len = STRIPE_SIZE;
817 rbi->bi_io_vec[0].bv_offset = 0; 823 rbi->bi_io_vec[0].bv_offset = 0;
818 rbi->bi_size = STRIPE_SIZE; 824 rbi->bi_size = STRIPE_SIZE;
825 /*
826 * If this is discard request, set bi_vcnt 0. We don't
827 * want to confuse SCSI because SCSI will replace payload
828 */
829 if (rw & REQ_DISCARD)
830 rbi->bi_vcnt = 0;
819 if (conf->mddev->gendisk) 831 if (conf->mddev->gendisk)
820 trace_block_bio_remap(bdev_get_queue(rbi->bi_bdev), 832 trace_block_bio_remap(bdev_get_queue(rbi->bi_bdev),
821 rbi, disk_devt(conf->mddev->gendisk), 833 rbi, disk_devt(conf->mddev->gendisk),
@@ -2910,6 +2922,14 @@ static void handle_stripe_clean_event(struct r5conf *conf,
2910 } 2922 }
2911 /* now that discard is done we can proceed with any sync */ 2923 /* now that discard is done we can proceed with any sync */
2912 clear_bit(STRIPE_DISCARD, &sh->state); 2924 clear_bit(STRIPE_DISCARD, &sh->state);
2925 /*
2926 * SCSI discard will change some bio fields and the stripe has
2927 * no updated data, so remove it from hash list and the stripe
2928 * will be reinitialized
2929 */
2930 spin_lock_irq(&conf->device_lock);
2931 remove_hash(sh);
2932 spin_unlock_irq(&conf->device_lock);
2913 if (test_bit(STRIPE_SYNC_REQUESTED, &sh->state)) 2933 if (test_bit(STRIPE_SYNC_REQUESTED, &sh->state))
2914 set_bit(STRIPE_HANDLE, &sh->state); 2934 set_bit(STRIPE_HANDLE, &sh->state);
2915 2935
diff --git a/drivers/media/dvb-frontends/tda10071.c b/drivers/media/dvb-frontends/tda10071.c
index 2521f7e23018..e79749cfec81 100644
--- a/drivers/media/dvb-frontends/tda10071.c
+++ b/drivers/media/dvb-frontends/tda10071.c
@@ -912,14 +912,8 @@ static int tda10071_init(struct dvb_frontend *fe)
912 { 0xd5, 0x03, 0x03 }, 912 { 0xd5, 0x03, 0x03 },
913 }; 913 };
914 914
915 /* firmware status */ 915 if (priv->warm) {
916 ret = tda10071_rd_reg(priv, 0x51, &tmp);
917 if (ret)
918 goto error;
919
920 if (!tmp) {
921 /* warm state - wake up device from sleep */ 916 /* warm state - wake up device from sleep */
922 priv->warm = 1;
923 917
924 for (i = 0; i < ARRAY_SIZE(tab); i++) { 918 for (i = 0; i < ARRAY_SIZE(tab); i++) {
925 ret = tda10071_wr_reg_mask(priv, tab[i].reg, 919 ret = tda10071_wr_reg_mask(priv, tab[i].reg,
@@ -937,7 +931,6 @@ static int tda10071_init(struct dvb_frontend *fe)
937 goto error; 931 goto error;
938 } else { 932 } else {
939 /* cold state - try to download firmware */ 933 /* cold state - try to download firmware */
940 priv->warm = 0;
941 934
942 /* request the firmware, this will block and timeout */ 935 /* request the firmware, this will block and timeout */
943 ret = request_firmware(&fw, fw_file, priv->i2c->dev.parent); 936 ret = request_firmware(&fw, fw_file, priv->i2c->dev.parent);
diff --git a/drivers/media/i2c/ad9389b.c b/drivers/media/i2c/ad9389b.c
index bb0c99d7a4f1..b06a7e54ee0d 100644
--- a/drivers/media/i2c/ad9389b.c
+++ b/drivers/media/i2c/ad9389b.c
@@ -628,16 +628,13 @@ static int ad9389b_s_stream(struct v4l2_subdev *sd, int enable)
628 628
629static const struct v4l2_dv_timings_cap ad9389b_timings_cap = { 629static const struct v4l2_dv_timings_cap ad9389b_timings_cap = {
630 .type = V4L2_DV_BT_656_1120, 630 .type = V4L2_DV_BT_656_1120,
631 .bt = { 631 /* keep this initialization for compatibility with GCC < 4.4.6 */
632 .max_width = 1920, 632 .reserved = { 0 },
633 .max_height = 1200, 633 V4L2_INIT_BT_TIMINGS(0, 1920, 0, 1200, 25000000, 170000000,
634 .min_pixelclock = 25000000, 634 V4L2_DV_BT_STD_CEA861 | V4L2_DV_BT_STD_DMT |
635 .max_pixelclock = 170000000,
636 .standards = V4L2_DV_BT_STD_CEA861 | V4L2_DV_BT_STD_DMT |
637 V4L2_DV_BT_STD_GTF | V4L2_DV_BT_STD_CVT, 635 V4L2_DV_BT_STD_GTF | V4L2_DV_BT_STD_CVT,
638 .capabilities = V4L2_DV_BT_CAP_PROGRESSIVE | 636 V4L2_DV_BT_CAP_PROGRESSIVE | V4L2_DV_BT_CAP_REDUCED_BLANKING |
639 V4L2_DV_BT_CAP_REDUCED_BLANKING | V4L2_DV_BT_CAP_CUSTOM, 637 V4L2_DV_BT_CAP_CUSTOM)
640 },
641}; 638};
642 639
643static int ad9389b_s_dv_timings(struct v4l2_subdev *sd, 640static int ad9389b_s_dv_timings(struct v4l2_subdev *sd,
diff --git a/drivers/media/i2c/adv7511.c b/drivers/media/i2c/adv7511.c
index 7a576097471f..7c8d971f1f61 100644
--- a/drivers/media/i2c/adv7511.c
+++ b/drivers/media/i2c/adv7511.c
@@ -119,16 +119,14 @@ static int adv7511_s_clock_freq(struct v4l2_subdev *sd, u32 freq);
119 119
120static const struct v4l2_dv_timings_cap adv7511_timings_cap = { 120static const struct v4l2_dv_timings_cap adv7511_timings_cap = {
121 .type = V4L2_DV_BT_656_1120, 121 .type = V4L2_DV_BT_656_1120,
122 .bt = { 122 /* keep this initialization for compatibility with GCC < 4.4.6 */
123 .max_width = ADV7511_MAX_WIDTH, 123 .reserved = { 0 },
124 .max_height = ADV7511_MAX_HEIGHT, 124 V4L2_INIT_BT_TIMINGS(0, ADV7511_MAX_WIDTH, 0, ADV7511_MAX_HEIGHT,
125 .min_pixelclock = ADV7511_MIN_PIXELCLOCK, 125 ADV7511_MIN_PIXELCLOCK, ADV7511_MAX_PIXELCLOCK,
126 .max_pixelclock = ADV7511_MAX_PIXELCLOCK, 126 V4L2_DV_BT_STD_CEA861 | V4L2_DV_BT_STD_DMT |
127 .standards = V4L2_DV_BT_STD_CEA861 | V4L2_DV_BT_STD_DMT |
128 V4L2_DV_BT_STD_GTF | V4L2_DV_BT_STD_CVT, 127 V4L2_DV_BT_STD_GTF | V4L2_DV_BT_STD_CVT,
129 .capabilities = V4L2_DV_BT_CAP_PROGRESSIVE | 128 V4L2_DV_BT_CAP_PROGRESSIVE | V4L2_DV_BT_CAP_REDUCED_BLANKING |
130 V4L2_DV_BT_CAP_REDUCED_BLANKING | V4L2_DV_BT_CAP_CUSTOM, 129 V4L2_DV_BT_CAP_CUSTOM)
131 },
132}; 130};
133 131
134static inline struct adv7511_state *get_adv7511_state(struct v4l2_subdev *sd) 132static inline struct adv7511_state *get_adv7511_state(struct v4l2_subdev *sd)
@@ -1126,6 +1124,7 @@ static int adv7511_probe(struct i2c_client *client, const struct i2c_device_id *
1126 state->i2c_edid = i2c_new_dummy(client->adapter, state->i2c_edid_addr >> 1); 1124 state->i2c_edid = i2c_new_dummy(client->adapter, state->i2c_edid_addr >> 1);
1127 if (state->i2c_edid == NULL) { 1125 if (state->i2c_edid == NULL) {
1128 v4l2_err(sd, "failed to register edid i2c client\n"); 1126 v4l2_err(sd, "failed to register edid i2c client\n");
1127 err = -ENOMEM;
1129 goto err_entity; 1128 goto err_entity;
1130 } 1129 }
1131 1130
@@ -1133,6 +1132,7 @@ static int adv7511_probe(struct i2c_client *client, const struct i2c_device_id *
1133 state->work_queue = create_singlethread_workqueue(sd->name); 1132 state->work_queue = create_singlethread_workqueue(sd->name);
1134 if (state->work_queue == NULL) { 1133 if (state->work_queue == NULL) {
1135 v4l2_err(sd, "could not create workqueue\n"); 1134 v4l2_err(sd, "could not create workqueue\n");
1135 err = -ENOMEM;
1136 goto err_unreg_cec; 1136 goto err_unreg_cec;
1137 } 1137 }
1138 1138
diff --git a/drivers/media/i2c/adv7842.c b/drivers/media/i2c/adv7842.c
index d1748901337c..22f729d66a96 100644
--- a/drivers/media/i2c/adv7842.c
+++ b/drivers/media/i2c/adv7842.c
@@ -546,30 +546,24 @@ static inline bool is_digital_input(struct v4l2_subdev *sd)
546 546
547static const struct v4l2_dv_timings_cap adv7842_timings_cap_analog = { 547static const struct v4l2_dv_timings_cap adv7842_timings_cap_analog = {
548 .type = V4L2_DV_BT_656_1120, 548 .type = V4L2_DV_BT_656_1120,
549 .bt = { 549 /* keep this initialization for compatibility with GCC < 4.4.6 */
550 .max_width = 1920, 550 .reserved = { 0 },
551 .max_height = 1200, 551 V4L2_INIT_BT_TIMINGS(0, 1920, 0, 1200, 25000000, 170000000,
552 .min_pixelclock = 25000000, 552 V4L2_DV_BT_STD_CEA861 | V4L2_DV_BT_STD_DMT |
553 .max_pixelclock = 170000000,
554 .standards = V4L2_DV_BT_STD_CEA861 | V4L2_DV_BT_STD_DMT |
555 V4L2_DV_BT_STD_GTF | V4L2_DV_BT_STD_CVT, 553 V4L2_DV_BT_STD_GTF | V4L2_DV_BT_STD_CVT,
556 .capabilities = V4L2_DV_BT_CAP_PROGRESSIVE | 554 V4L2_DV_BT_CAP_PROGRESSIVE | V4L2_DV_BT_CAP_REDUCED_BLANKING |
557 V4L2_DV_BT_CAP_REDUCED_BLANKING | V4L2_DV_BT_CAP_CUSTOM, 555 V4L2_DV_BT_CAP_CUSTOM)
558 },
559}; 556};
560 557
561static const struct v4l2_dv_timings_cap adv7842_timings_cap_digital = { 558static const struct v4l2_dv_timings_cap adv7842_timings_cap_digital = {
562 .type = V4L2_DV_BT_656_1120, 559 .type = V4L2_DV_BT_656_1120,
563 .bt = { 560 /* keep this initialization for compatibility with GCC < 4.4.6 */
564 .max_width = 1920, 561 .reserved = { 0 },
565 .max_height = 1200, 562 V4L2_INIT_BT_TIMINGS(0, 1920, 0, 1200, 25000000, 225000000,
566 .min_pixelclock = 25000000, 563 V4L2_DV_BT_STD_CEA861 | V4L2_DV_BT_STD_DMT |
567 .max_pixelclock = 225000000,
568 .standards = V4L2_DV_BT_STD_CEA861 | V4L2_DV_BT_STD_DMT |
569 V4L2_DV_BT_STD_GTF | V4L2_DV_BT_STD_CVT, 564 V4L2_DV_BT_STD_GTF | V4L2_DV_BT_STD_CVT,
570 .capabilities = V4L2_DV_BT_CAP_PROGRESSIVE | 565 V4L2_DV_BT_CAP_PROGRESSIVE | V4L2_DV_BT_CAP_REDUCED_BLANKING |
571 V4L2_DV_BT_CAP_REDUCED_BLANKING | V4L2_DV_BT_CAP_CUSTOM, 566 V4L2_DV_BT_CAP_CUSTOM)
572 },
573}; 567};
574 568
575static inline const struct v4l2_dv_timings_cap * 569static inline const struct v4l2_dv_timings_cap *
diff --git a/drivers/media/i2c/ths8200.c b/drivers/media/i2c/ths8200.c
index a58a8f663ffb..d9f65d7e3e58 100644
--- a/drivers/media/i2c/ths8200.c
+++ b/drivers/media/i2c/ths8200.c
@@ -46,14 +46,10 @@ struct ths8200_state {
46 46
47static const struct v4l2_dv_timings_cap ths8200_timings_cap = { 47static const struct v4l2_dv_timings_cap ths8200_timings_cap = {
48 .type = V4L2_DV_BT_656_1120, 48 .type = V4L2_DV_BT_656_1120,
49 .bt = { 49 /* keep this initialization for compatibility with GCC < 4.4.6 */
50 .max_width = 1920, 50 .reserved = { 0 },
51 .max_height = 1080, 51 V4L2_INIT_BT_TIMINGS(0, 1920, 0, 1080, 25000000, 148500000,
52 .min_pixelclock = 25000000, 52 V4L2_DV_BT_STD_CEA861, V4L2_DV_BT_CAP_PROGRESSIVE)
53 .max_pixelclock = 148500000,
54 .standards = V4L2_DV_BT_STD_CEA861,
55 .capabilities = V4L2_DV_BT_CAP_PROGRESSIVE,
56 },
57}; 53};
58 54
59static inline struct ths8200_state *to_state(struct v4l2_subdev *sd) 55static inline struct ths8200_state *to_state(struct v4l2_subdev *sd)
diff --git a/drivers/media/pci/saa7134/saa7134-video.c b/drivers/media/pci/saa7134/saa7134-video.c
index e12bbd8c3f0b..fb60da85bc2c 100644
--- a/drivers/media/pci/saa7134/saa7134-video.c
+++ b/drivers/media/pci/saa7134/saa7134-video.c
@@ -1455,6 +1455,7 @@ static int video_release(struct file *file)
1455 1455
1456 /* stop video capture */ 1456 /* stop video capture */
1457 if (res_check(fh, RESOURCE_VIDEO)) { 1457 if (res_check(fh, RESOURCE_VIDEO)) {
1458 pm_qos_remove_request(&dev->qos_request);
1458 videobuf_streamoff(&fh->cap); 1459 videobuf_streamoff(&fh->cap);
1459 res_free(dev,fh,RESOURCE_VIDEO); 1460 res_free(dev,fh,RESOURCE_VIDEO);
1460 } 1461 }
diff --git a/drivers/media/platform/exynos4-is/Kconfig b/drivers/media/platform/exynos4-is/Kconfig
index 53ad0f080179..d2d3b4b61435 100644
--- a/drivers/media/platform/exynos4-is/Kconfig
+++ b/drivers/media/platform/exynos4-is/Kconfig
@@ -29,7 +29,7 @@ config VIDEO_S5P_FIMC
29config VIDEO_S5P_MIPI_CSIS 29config VIDEO_S5P_MIPI_CSIS
30 tristate "S5P/EXYNOS MIPI-CSI2 receiver (MIPI-CSIS) driver" 30 tristate "S5P/EXYNOS MIPI-CSI2 receiver (MIPI-CSIS) driver"
31 depends on REGULATOR 31 depends on REGULATOR
32 select S5P_SETUP_MIPIPHY 32 select GENERIC_PHY
33 help 33 help
34 This is a V4L2 driver for Samsung S5P and EXYNOS4 SoC MIPI-CSI2 34 This is a V4L2 driver for Samsung S5P and EXYNOS4 SoC MIPI-CSI2
35 receiver (MIPI-CSIS) devices. 35 receiver (MIPI-CSIS) devices.
diff --git a/drivers/media/platform/exynos4-is/mipi-csis.c b/drivers/media/platform/exynos4-is/mipi-csis.c
index 0914230b42de..9fc2af6a0446 100644
--- a/drivers/media/platform/exynos4-is/mipi-csis.c
+++ b/drivers/media/platform/exynos4-is/mipi-csis.c
@@ -20,6 +20,7 @@
20#include <linux/memory.h> 20#include <linux/memory.h>
21#include <linux/module.h> 21#include <linux/module.h>
22#include <linux/of.h> 22#include <linux/of.h>
23#include <linux/phy/phy.h>
23#include <linux/platform_data/mipi-csis.h> 24#include <linux/platform_data/mipi-csis.h>
24#include <linux/platform_device.h> 25#include <linux/platform_device.h>
25#include <linux/pm_runtime.h> 26#include <linux/pm_runtime.h>
@@ -180,6 +181,7 @@ struct csis_drvdata {
180 * @sd: v4l2_subdev associated with CSIS device instance 181 * @sd: v4l2_subdev associated with CSIS device instance
181 * @index: the hardware instance index 182 * @index: the hardware instance index
182 * @pdev: CSIS platform device 183 * @pdev: CSIS platform device
184 * @phy: pointer to the CSIS generic PHY
183 * @regs: mmaped I/O registers memory 185 * @regs: mmaped I/O registers memory
184 * @supplies: CSIS regulator supplies 186 * @supplies: CSIS regulator supplies
185 * @clock: CSIS clocks 187 * @clock: CSIS clocks
@@ -203,6 +205,7 @@ struct csis_state {
203 struct v4l2_subdev sd; 205 struct v4l2_subdev sd;
204 u8 index; 206 u8 index;
205 struct platform_device *pdev; 207 struct platform_device *pdev;
208 struct phy *phy;
206 void __iomem *regs; 209 void __iomem *regs;
207 struct regulator_bulk_data supplies[CSIS_NUM_SUPPLIES]; 210 struct regulator_bulk_data supplies[CSIS_NUM_SUPPLIES];
208 struct clk *clock[NUM_CSIS_CLOCKS]; 211 struct clk *clock[NUM_CSIS_CLOCKS];
@@ -779,8 +782,8 @@ static int s5pcsis_parse_dt(struct platform_device *pdev,
779 "samsung,csis-wclk"); 782 "samsung,csis-wclk");
780 783
781 state->num_lanes = endpoint.bus.mipi_csi2.num_data_lanes; 784 state->num_lanes = endpoint.bus.mipi_csi2.num_data_lanes;
782
783 of_node_put(node); 785 of_node_put(node);
786
784 return 0; 787 return 0;
785} 788}
786#else 789#else
@@ -829,6 +832,10 @@ static int s5pcsis_probe(struct platform_device *pdev)
829 return -EINVAL; 832 return -EINVAL;
830 } 833 }
831 834
835 state->phy = devm_phy_get(dev, "csis");
836 if (IS_ERR(state->phy))
837 return PTR_ERR(state->phy);
838
832 mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 839 mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
833 state->regs = devm_ioremap_resource(dev, mem_res); 840 state->regs = devm_ioremap_resource(dev, mem_res);
834 if (IS_ERR(state->regs)) 841 if (IS_ERR(state->regs))
@@ -922,7 +929,7 @@ static int s5pcsis_pm_suspend(struct device *dev, bool runtime)
922 mutex_lock(&state->lock); 929 mutex_lock(&state->lock);
923 if (state->flags & ST_POWERED) { 930 if (state->flags & ST_POWERED) {
924 s5pcsis_stop_stream(state); 931 s5pcsis_stop_stream(state);
925 ret = s5p_csis_phy_enable(state->index, false); 932 ret = phy_power_off(state->phy);
926 if (ret) 933 if (ret)
927 goto unlock; 934 goto unlock;
928 ret = regulator_bulk_disable(CSIS_NUM_SUPPLIES, 935 ret = regulator_bulk_disable(CSIS_NUM_SUPPLIES,
@@ -958,7 +965,7 @@ static int s5pcsis_pm_resume(struct device *dev, bool runtime)
958 state->supplies); 965 state->supplies);
959 if (ret) 966 if (ret)
960 goto unlock; 967 goto unlock;
961 ret = s5p_csis_phy_enable(state->index, true); 968 ret = phy_power_on(state->phy);
962 if (!ret) { 969 if (!ret) {
963 state->flags |= ST_POWERED; 970 state->flags |= ST_POWERED;
964 } else { 971 } else {
diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.c b/drivers/media/platform/s5p-jpeg/jpeg-core.c
index 15d23968d1de..9b88a4601007 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c
@@ -1423,6 +1423,7 @@ static int s5p_jpeg_probe(struct platform_device *pdev)
1423 jpeg->vfd_decoder->release = video_device_release; 1423 jpeg->vfd_decoder->release = video_device_release;
1424 jpeg->vfd_decoder->lock = &jpeg->lock; 1424 jpeg->vfd_decoder->lock = &jpeg->lock;
1425 jpeg->vfd_decoder->v4l2_dev = &jpeg->v4l2_dev; 1425 jpeg->vfd_decoder->v4l2_dev = &jpeg->v4l2_dev;
1426 jpeg->vfd_decoder->vfl_dir = VFL_DIR_M2M;
1426 1427
1427 ret = video_register_device(jpeg->vfd_decoder, VFL_TYPE_GRABBER, -1); 1428 ret = video_register_device(jpeg->vfd_decoder, VFL_TYPE_GRABBER, -1);
1428 if (ret) { 1429 if (ret) {
diff --git a/drivers/media/platform/sh_vou.c b/drivers/media/platform/sh_vou.c
index 7a9c5e9329f2..4f30341dc2ab 100644
--- a/drivers/media/platform/sh_vou.c
+++ b/drivers/media/platform/sh_vou.c
@@ -776,7 +776,7 @@ static int sh_vou_try_fmt_vid_out(struct file *file, void *priv,
776 v4l_bound_align_image(&pix->width, 0, VOU_MAX_IMAGE_WIDTH, 1, 776 v4l_bound_align_image(&pix->width, 0, VOU_MAX_IMAGE_WIDTH, 1,
777 &pix->height, 0, VOU_MAX_IMAGE_HEIGHT, 1, 0); 777 &pix->height, 0, VOU_MAX_IMAGE_HEIGHT, 1, 0);
778 778
779 for (i = 0; ARRAY_SIZE(vou_fmt); i++) 779 for (i = 0; i < ARRAY_SIZE(vou_fmt); i++)
780 if (vou_fmt[i].pfmt == pix->pixelformat) 780 if (vou_fmt[i].pfmt == pix->pixelformat)
781 return 0; 781 return 0;
782 782
diff --git a/drivers/media/platform/soc_camera/mx3_camera.c b/drivers/media/platform/soc_camera/mx3_camera.c
index 8f9f6211c52e..f975b7008692 100644
--- a/drivers/media/platform/soc_camera/mx3_camera.c
+++ b/drivers/media/platform/soc_camera/mx3_camera.c
@@ -266,7 +266,6 @@ static void mx3_videobuf_queue(struct vb2_buffer *vb)
266 struct idmac_channel *ichan = mx3_cam->idmac_channel[0]; 266 struct idmac_channel *ichan = mx3_cam->idmac_channel[0];
267 struct idmac_video_param *video = &ichan->params.video; 267 struct idmac_video_param *video = &ichan->params.video;
268 const struct soc_mbus_pixelfmt *host_fmt = icd->current_fmt->host_fmt; 268 const struct soc_mbus_pixelfmt *host_fmt = icd->current_fmt->host_fmt;
269 unsigned long flags;
270 dma_cookie_t cookie; 269 dma_cookie_t cookie;
271 size_t new_size; 270 size_t new_size;
272 271
@@ -328,7 +327,7 @@ static void mx3_videobuf_queue(struct vb2_buffer *vb)
328 memset(vb2_plane_vaddr(vb, 0), 0xaa, vb2_get_plane_payload(vb, 0)); 327 memset(vb2_plane_vaddr(vb, 0), 0xaa, vb2_get_plane_payload(vb, 0));
329#endif 328#endif
330 329
331 spin_lock_irqsave(&mx3_cam->lock, flags); 330 spin_lock_irq(&mx3_cam->lock);
332 list_add_tail(&buf->queue, &mx3_cam->capture); 331 list_add_tail(&buf->queue, &mx3_cam->capture);
333 332
334 if (!mx3_cam->active) 333 if (!mx3_cam->active)
@@ -351,7 +350,7 @@ static void mx3_videobuf_queue(struct vb2_buffer *vb)
351 if (mx3_cam->active == buf) 350 if (mx3_cam->active == buf)
352 mx3_cam->active = NULL; 351 mx3_cam->active = NULL;
353 352
354 spin_unlock_irqrestore(&mx3_cam->lock, flags); 353 spin_unlock_irq(&mx3_cam->lock);
355error: 354error:
356 vb2_buffer_done(vb, VB2_BUF_STATE_ERROR); 355 vb2_buffer_done(vb, VB2_BUF_STATE_ERROR);
357} 356}
diff --git a/drivers/media/tuners/e4000.c b/drivers/media/tuners/e4000.c
index ad9309da4a91..6c96e4898777 100644
--- a/drivers/media/tuners/e4000.c
+++ b/drivers/media/tuners/e4000.c
@@ -19,6 +19,7 @@
19 */ 19 */
20 20
21#include "e4000_priv.h" 21#include "e4000_priv.h"
22#include <linux/math64.h>
22 23
23/* write multiple registers */ 24/* write multiple registers */
24static int e4000_wr_regs(struct e4000_priv *priv, u8 reg, u8 *val, int len) 25static int e4000_wr_regs(struct e4000_priv *priv, u8 reg, u8 *val, int len)
@@ -233,7 +234,7 @@ static int e4000_set_params(struct dvb_frontend *fe)
233 * or more. 234 * or more.
234 */ 235 */
235 f_vco = c->frequency * e4000_pll_lut[i].mul; 236 f_vco = c->frequency * e4000_pll_lut[i].mul;
236 sigma_delta = 0x10000UL * (f_vco % priv->cfg->clock) / priv->cfg->clock; 237 sigma_delta = div_u64(0x10000ULL * (f_vco % priv->cfg->clock), priv->cfg->clock);
237 buf[0] = f_vco / priv->cfg->clock; 238 buf[0] = f_vco / priv->cfg->clock;
238 buf[1] = (sigma_delta >> 0) & 0xff; 239 buf[1] = (sigma_delta >> 0) & 0xff;
239 buf[2] = (sigma_delta >> 8) & 0xff; 240 buf[2] = (sigma_delta >> 8) & 0xff;
diff --git a/drivers/media/usb/stkwebcam/stk-webcam.c b/drivers/media/usb/stkwebcam/stk-webcam.c
index c43c8d32be40..be77482c3070 100644
--- a/drivers/media/usb/stkwebcam/stk-webcam.c
+++ b/drivers/media/usb/stkwebcam/stk-webcam.c
@@ -111,6 +111,13 @@ static const struct dmi_system_id stk_upside_down_dmi_table[] = {
111 DMI_MATCH(DMI_PRODUCT_NAME, "F3JC") 111 DMI_MATCH(DMI_PRODUCT_NAME, "F3JC")
112 } 112 }
113 }, 113 },
114 {
115 .ident = "T12Rg-H",
116 .matches = {
117 DMI_MATCH(DMI_SYS_VENDOR, "HCL Infosystems Limited"),
118 DMI_MATCH(DMI_PRODUCT_NAME, "T12Rg-H")
119 }
120 },
114 {} 121 {}
115}; 122};
116 123
diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c
index 81695d48c13e..c3bb2502225b 100644
--- a/drivers/media/usb/uvc/uvc_driver.c
+++ b/drivers/media/usb/uvc/uvc_driver.c
@@ -2090,6 +2090,15 @@ static struct usb_device_id uvc_ids[] = {
2090 .bInterfaceSubClass = 1, 2090 .bInterfaceSubClass = 1,
2091 .bInterfaceProtocol = 0, 2091 .bInterfaceProtocol = 0,
2092 .driver_info = UVC_QUIRK_PROBE_MINMAX }, 2092 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2093 /* Microsoft Lifecam NX-3000 */
2094 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2095 | USB_DEVICE_ID_MATCH_INT_INFO,
2096 .idVendor = 0x045e,
2097 .idProduct = 0x0721,
2098 .bInterfaceClass = USB_CLASS_VIDEO,
2099 .bInterfaceSubClass = 1,
2100 .bInterfaceProtocol = 0,
2101 .driver_info = UVC_QUIRK_PROBE_DEF },
2093 /* Microsoft Lifecam VX-7000 */ 2102 /* Microsoft Lifecam VX-7000 */
2094 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE 2103 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2095 | USB_DEVICE_ID_MATCH_INT_INFO, 2104 | USB_DEVICE_ID_MATCH_INT_INFO,
@@ -2174,6 +2183,15 @@ static struct usb_device_id uvc_ids[] = {
2174 .bInterfaceSubClass = 1, 2183 .bInterfaceSubClass = 1,
2175 .bInterfaceProtocol = 0, 2184 .bInterfaceProtocol = 0,
2176 .driver_info = UVC_QUIRK_PROBE_DEF }, 2185 .driver_info = UVC_QUIRK_PROBE_DEF },
2186 /* Dell SP2008WFP Monitor */
2187 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2188 | USB_DEVICE_ID_MATCH_INT_INFO,
2189 .idVendor = 0x05a9,
2190 .idProduct = 0x2641,
2191 .bInterfaceClass = USB_CLASS_VIDEO,
2192 .bInterfaceSubClass = 1,
2193 .bInterfaceProtocol = 0,
2194 .driver_info = UVC_QUIRK_PROBE_DEF },
2177 /* Dell Alienware X51 */ 2195 /* Dell Alienware X51 */
2178 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE 2196 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2179 | USB_DEVICE_ID_MATCH_INT_INFO, 2197 | USB_DEVICE_ID_MATCH_INT_INFO,
diff --git a/drivers/media/v4l2-core/videobuf2-core.c b/drivers/media/v4l2-core/videobuf2-core.c
index 594c75eab5a5..de0e87f0b2c3 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-core.c
@@ -353,7 +353,9 @@ static int __verify_length(struct vb2_buffer *vb, const struct v4l2_buffer *b)
353 353
354 if (b->m.planes[plane].bytesused > length) 354 if (b->m.planes[plane].bytesused > length)
355 return -EINVAL; 355 return -EINVAL;
356 if (b->m.planes[plane].data_offset >= 356
357 if (b->m.planes[plane].data_offset > 0 &&
358 b->m.planes[plane].data_offset >=
357 b->m.planes[plane].bytesused) 359 b->m.planes[plane].bytesused)
358 return -EINVAL; 360 return -EINVAL;
359 } 361 }
diff --git a/drivers/media/v4l2-core/videobuf2-dma-contig.c b/drivers/media/v4l2-core/videobuf2-dma-contig.c
index fd56f2563201..646f08f4f504 100644
--- a/drivers/media/v4l2-core/videobuf2-dma-contig.c
+++ b/drivers/media/v4l2-core/videobuf2-dma-contig.c
@@ -423,6 +423,39 @@ static inline int vma_is_io(struct vm_area_struct *vma)
423 return !!(vma->vm_flags & (VM_IO | VM_PFNMAP)); 423 return !!(vma->vm_flags & (VM_IO | VM_PFNMAP));
424} 424}
425 425
426static int vb2_dc_get_user_pfn(unsigned long start, int n_pages,
427 struct vm_area_struct *vma, unsigned long *res)
428{
429 unsigned long pfn, start_pfn, prev_pfn;
430 unsigned int i;
431 int ret;
432
433 if (!vma_is_io(vma))
434 return -EFAULT;
435
436 ret = follow_pfn(vma, start, &pfn);
437 if (ret)
438 return ret;
439
440 start_pfn = pfn;
441 start += PAGE_SIZE;
442
443 for (i = 1; i < n_pages; ++i, start += PAGE_SIZE) {
444 prev_pfn = pfn;
445 ret = follow_pfn(vma, start, &pfn);
446
447 if (ret) {
448 pr_err("no page for address %lu\n", start);
449 return ret;
450 }
451 if (pfn != prev_pfn + 1)
452 return -EINVAL;
453 }
454
455 *res = start_pfn;
456 return 0;
457}
458
426static int vb2_dc_get_user_pages(unsigned long start, struct page **pages, 459static int vb2_dc_get_user_pages(unsigned long start, struct page **pages,
427 int n_pages, struct vm_area_struct *vma, int write) 460 int n_pages, struct vm_area_struct *vma, int write)
428{ 461{
@@ -433,6 +466,9 @@ static int vb2_dc_get_user_pages(unsigned long start, struct page **pages,
433 unsigned long pfn; 466 unsigned long pfn;
434 int ret = follow_pfn(vma, start, &pfn); 467 int ret = follow_pfn(vma, start, &pfn);
435 468
469 if (!pfn_valid(pfn))
470 return -EINVAL;
471
436 if (ret) { 472 if (ret) {
437 pr_err("no page for address %lu\n", start); 473 pr_err("no page for address %lu\n", start);
438 return ret; 474 return ret;
@@ -468,16 +504,49 @@ static void vb2_dc_put_userptr(void *buf_priv)
468 struct vb2_dc_buf *buf = buf_priv; 504 struct vb2_dc_buf *buf = buf_priv;
469 struct sg_table *sgt = buf->dma_sgt; 505 struct sg_table *sgt = buf->dma_sgt;
470 506
471 dma_unmap_sg(buf->dev, sgt->sgl, sgt->orig_nents, buf->dma_dir); 507 if (sgt) {
472 if (!vma_is_io(buf->vma)) 508 dma_unmap_sg(buf->dev, sgt->sgl, sgt->orig_nents, buf->dma_dir);
473 vb2_dc_sgt_foreach_page(sgt, vb2_dc_put_dirty_page); 509 if (!vma_is_io(buf->vma))
510 vb2_dc_sgt_foreach_page(sgt, vb2_dc_put_dirty_page);
474 511
475 sg_free_table(sgt); 512 sg_free_table(sgt);
476 kfree(sgt); 513 kfree(sgt);
514 }
477 vb2_put_vma(buf->vma); 515 vb2_put_vma(buf->vma);
478 kfree(buf); 516 kfree(buf);
479} 517}
480 518
519/*
520 * For some kind of reserved memory there might be no struct page available,
521 * so all that can be done to support such 'pages' is to try to convert
522 * pfn to dma address or at the last resort just assume that
523 * dma address == physical address (like it has been assumed in earlier version
524 * of videobuf2-dma-contig
525 */
526
527#ifdef __arch_pfn_to_dma
528static inline dma_addr_t vb2_dc_pfn_to_dma(struct device *dev, unsigned long pfn)
529{
530 return (dma_addr_t)__arch_pfn_to_dma(dev, pfn);
531}
532#elif defined(__pfn_to_bus)
533static inline dma_addr_t vb2_dc_pfn_to_dma(struct device *dev, unsigned long pfn)
534{
535 return (dma_addr_t)__pfn_to_bus(pfn);
536}
537#elif defined(__pfn_to_phys)
538static inline dma_addr_t vb2_dc_pfn_to_dma(struct device *dev, unsigned long pfn)
539{
540 return (dma_addr_t)__pfn_to_phys(pfn);
541}
542#else
543static inline dma_addr_t vb2_dc_pfn_to_dma(struct device *dev, unsigned long pfn)
544{
545 /* really, we cannot do anything better at this point */
546 return (dma_addr_t)(pfn) << PAGE_SHIFT;
547}
548#endif
549
481static void *vb2_dc_get_userptr(void *alloc_ctx, unsigned long vaddr, 550static void *vb2_dc_get_userptr(void *alloc_ctx, unsigned long vaddr,
482 unsigned long size, int write) 551 unsigned long size, int write)
483{ 552{
@@ -548,6 +617,14 @@ static void *vb2_dc_get_userptr(void *alloc_ctx, unsigned long vaddr,
548 /* extract page list from userspace mapping */ 617 /* extract page list from userspace mapping */
549 ret = vb2_dc_get_user_pages(start, pages, n_pages, vma, write); 618 ret = vb2_dc_get_user_pages(start, pages, n_pages, vma, write);
550 if (ret) { 619 if (ret) {
620 unsigned long pfn;
621 if (vb2_dc_get_user_pfn(start, n_pages, vma, &pfn) == 0) {
622 buf->dma_addr = vb2_dc_pfn_to_dma(buf->dev, pfn);
623 buf->size = size;
624 kfree(pages);
625 return buf;
626 }
627
551 pr_err("failed to get user pages\n"); 628 pr_err("failed to get user pages\n");
552 goto fail_vma; 629 goto fail_vma;
553 } 630 }
diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
index 59ab0692f0b9..a9830ff8e3f3 100644
--- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
+++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
@@ -349,7 +349,7 @@ static int legacy_set_geometry(struct gpmi_nand_data *this)
349 349
350int common_nfc_set_geometry(struct gpmi_nand_data *this) 350int common_nfc_set_geometry(struct gpmi_nand_data *this)
351{ 351{
352 return set_geometry_by_ecc_info(this) ? 0 : legacy_set_geometry(this); 352 return legacy_set_geometry(this);
353} 353}
354 354
355struct dma_chan *get_dma_chan(struct gpmi_nand_data *this) 355struct dma_chan *get_dma_chan(struct gpmi_nand_data *this)
diff --git a/drivers/mtd/nand/pxa3xx_nand.c b/drivers/mtd/nand/pxa3xx_nand.c
index dd03dfdfb0d6..c28d4e29af1a 100644
--- a/drivers/mtd/nand/pxa3xx_nand.c
+++ b/drivers/mtd/nand/pxa3xx_nand.c
@@ -1320,7 +1320,12 @@ static int pxa3xx_nand_probe(struct platform_device *pdev)
1320 for (cs = 0; cs < pdata->num_cs; cs++) { 1320 for (cs = 0; cs < pdata->num_cs; cs++) {
1321 struct mtd_info *mtd = info->host[cs]->mtd; 1321 struct mtd_info *mtd = info->host[cs]->mtd;
1322 1322
1323 mtd->name = pdev->name; 1323 /*
1324 * The mtd name matches the one used in 'mtdparts' kernel
1325 * parameter. This name cannot be changed or otherwise
1326 * user's mtd partitions configuration would get broken.
1327 */
1328 mtd->name = "pxa3xx_nand-0";
1324 info->cs = cs; 1329 info->cs = cs;
1325 ret = pxa3xx_nand_scan(mtd); 1330 ret = pxa3xx_nand_scan(mtd);
1326 if (ret) { 1331 if (ret) {
diff --git a/drivers/net/can/at91_can.c b/drivers/net/can/at91_can.c
index 3b1ff6148702..693d8ffe4653 100644
--- a/drivers/net/can/at91_can.c
+++ b/drivers/net/can/at91_can.c
@@ -1405,10 +1405,10 @@ static int at91_can_remove(struct platform_device *pdev)
1405 1405
1406static const struct platform_device_id at91_can_id_table[] = { 1406static const struct platform_device_id at91_can_id_table[] = {
1407 { 1407 {
1408 .name = "at91_can", 1408 .name = "at91sam9x5_can",
1409 .driver_data = (kernel_ulong_t)&at91_at91sam9x5_data, 1409 .driver_data = (kernel_ulong_t)&at91_at91sam9x5_data,
1410 }, { 1410 }, {
1411 .name = "at91sam9x5_can", 1411 .name = "at91_can",
1412 .driver_data = (kernel_ulong_t)&at91_at91sam9263_data, 1412 .driver_data = (kernel_ulong_t)&at91_at91sam9263_data,
1413 }, { 1413 }, {
1414 /* sentinel */ 1414 /* sentinel */
diff --git a/drivers/net/can/c_can/c_can.c b/drivers/net/can/c_can/c_can.c
index a668cd491cb3..e3fc07cf2f62 100644
--- a/drivers/net/can/c_can/c_can.c
+++ b/drivers/net/can/c_can/c_can.c
@@ -814,9 +814,6 @@ static int c_can_do_rx_poll(struct net_device *dev, int quota)
814 msg_ctrl_save = priv->read_reg(priv, 814 msg_ctrl_save = priv->read_reg(priv,
815 C_CAN_IFACE(MSGCTRL_REG, 0)); 815 C_CAN_IFACE(MSGCTRL_REG, 0));
816 816
817 if (msg_ctrl_save & IF_MCONT_EOB)
818 return num_rx_pkts;
819
820 if (msg_ctrl_save & IF_MCONT_MSGLST) { 817 if (msg_ctrl_save & IF_MCONT_MSGLST) {
821 c_can_handle_lost_msg_obj(dev, 0, msg_obj); 818 c_can_handle_lost_msg_obj(dev, 0, msg_obj);
822 num_rx_pkts++; 819 num_rx_pkts++;
@@ -824,6 +821,9 @@ static int c_can_do_rx_poll(struct net_device *dev, int quota)
824 continue; 821 continue;
825 } 822 }
826 823
824 if (msg_ctrl_save & IF_MCONT_EOB)
825 return num_rx_pkts;
826
827 if (!(msg_ctrl_save & IF_MCONT_NEWDAT)) 827 if (!(msg_ctrl_save & IF_MCONT_NEWDAT))
828 continue; 828 continue;
829 829
diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c
index f9cba4123c66..1870c4731a57 100644
--- a/drivers/net/can/dev.c
+++ b/drivers/net/can/dev.c
@@ -705,14 +705,14 @@ static size_t can_get_size(const struct net_device *dev)
705 size_t size; 705 size_t size;
706 706
707 size = nla_total_size(sizeof(u32)); /* IFLA_CAN_STATE */ 707 size = nla_total_size(sizeof(u32)); /* IFLA_CAN_STATE */
708 size += sizeof(struct can_ctrlmode); /* IFLA_CAN_CTRLMODE */ 708 size += nla_total_size(sizeof(struct can_ctrlmode)); /* IFLA_CAN_CTRLMODE */
709 size += nla_total_size(sizeof(u32)); /* IFLA_CAN_RESTART_MS */ 709 size += nla_total_size(sizeof(u32)); /* IFLA_CAN_RESTART_MS */
710 size += sizeof(struct can_bittiming); /* IFLA_CAN_BITTIMING */ 710 size += nla_total_size(sizeof(struct can_bittiming)); /* IFLA_CAN_BITTIMING */
711 size += sizeof(struct can_clock); /* IFLA_CAN_CLOCK */ 711 size += nla_total_size(sizeof(struct can_clock)); /* IFLA_CAN_CLOCK */
712 if (priv->do_get_berr_counter) /* IFLA_CAN_BERR_COUNTER */ 712 if (priv->do_get_berr_counter) /* IFLA_CAN_BERR_COUNTER */
713 size += sizeof(struct can_berr_counter); 713 size += nla_total_size(sizeof(struct can_berr_counter));
714 if (priv->bittiming_const) /* IFLA_CAN_BITTIMING_CONST */ 714 if (priv->bittiming_const) /* IFLA_CAN_BITTIMING_CONST */
715 size += sizeof(struct can_bittiming_const); 715 size += nla_total_size(sizeof(struct can_bittiming_const));
716 716
717 return size; 717 return size;
718} 718}
diff --git a/drivers/net/can/flexcan.c b/drivers/net/can/flexcan.c
index 3f21142138b7..8f5ce747feb5 100644
--- a/drivers/net/can/flexcan.c
+++ b/drivers/net/can/flexcan.c
@@ -62,7 +62,7 @@
62#define FLEXCAN_MCR_BCC BIT(16) 62#define FLEXCAN_MCR_BCC BIT(16)
63#define FLEXCAN_MCR_LPRIO_EN BIT(13) 63#define FLEXCAN_MCR_LPRIO_EN BIT(13)
64#define FLEXCAN_MCR_AEN BIT(12) 64#define FLEXCAN_MCR_AEN BIT(12)
65#define FLEXCAN_MCR_MAXMB(x) ((x) & 0xf) 65#define FLEXCAN_MCR_MAXMB(x) ((x) & 0x1f)
66#define FLEXCAN_MCR_IDAM_A (0 << 8) 66#define FLEXCAN_MCR_IDAM_A (0 << 8)
67#define FLEXCAN_MCR_IDAM_B (1 << 8) 67#define FLEXCAN_MCR_IDAM_B (1 << 8)
68#define FLEXCAN_MCR_IDAM_C (2 << 8) 68#define FLEXCAN_MCR_IDAM_C (2 << 8)
@@ -735,9 +735,11 @@ static int flexcan_chip_start(struct net_device *dev)
735 * 735 *
736 */ 736 */
737 reg_mcr = flexcan_read(&regs->mcr); 737 reg_mcr = flexcan_read(&regs->mcr);
738 reg_mcr &= ~FLEXCAN_MCR_MAXMB(0xff);
738 reg_mcr |= FLEXCAN_MCR_FRZ | FLEXCAN_MCR_FEN | FLEXCAN_MCR_HALT | 739 reg_mcr |= FLEXCAN_MCR_FRZ | FLEXCAN_MCR_FEN | FLEXCAN_MCR_HALT |
739 FLEXCAN_MCR_SUPV | FLEXCAN_MCR_WRN_EN | 740 FLEXCAN_MCR_SUPV | FLEXCAN_MCR_WRN_EN |
740 FLEXCAN_MCR_IDAM_C | FLEXCAN_MCR_SRX_DIS; 741 FLEXCAN_MCR_IDAM_C | FLEXCAN_MCR_SRX_DIS |
742 FLEXCAN_MCR_MAXMB(FLEXCAN_TX_BUF_ID);
741 netdev_dbg(dev, "%s: writing mcr=0x%08x", __func__, reg_mcr); 743 netdev_dbg(dev, "%s: writing mcr=0x%08x", __func__, reg_mcr);
742 flexcan_write(reg_mcr, &regs->mcr); 744 flexcan_write(reg_mcr, &regs->mcr);
743 745
@@ -771,6 +773,10 @@ static int flexcan_chip_start(struct net_device *dev)
771 netdev_dbg(dev, "%s: writing ctrl=0x%08x", __func__, reg_ctrl); 773 netdev_dbg(dev, "%s: writing ctrl=0x%08x", __func__, reg_ctrl);
772 flexcan_write(reg_ctrl, &regs->ctrl); 774 flexcan_write(reg_ctrl, &regs->ctrl);
773 775
776 /* Abort any pending TX, mark Mailbox as INACTIVE */
777 flexcan_write(FLEXCAN_MB_CNT_CODE(0x4),
778 &regs->cantxfg[FLEXCAN_TX_BUF_ID].can_ctrl);
779
774 /* acceptance mask/acceptance code (accept everything) */ 780 /* acceptance mask/acceptance code (accept everything) */
775 flexcan_write(0x0, &regs->rxgmask); 781 flexcan_write(0x0, &regs->rxgmask);
776 flexcan_write(0x0, &regs->rx14mask); 782 flexcan_write(0x0, &regs->rx14mask);
@@ -979,9 +985,9 @@ static void unregister_flexcandev(struct net_device *dev)
979} 985}
980 986
981static const struct of_device_id flexcan_of_match[] = { 987static const struct of_device_id flexcan_of_match[] = {
982 { .compatible = "fsl,p1010-flexcan", .data = &fsl_p1010_devtype_data, },
983 { .compatible = "fsl,imx28-flexcan", .data = &fsl_imx28_devtype_data, },
984 { .compatible = "fsl,imx6q-flexcan", .data = &fsl_imx6q_devtype_data, }, 988 { .compatible = "fsl,imx6q-flexcan", .data = &fsl_imx6q_devtype_data, },
989 { .compatible = "fsl,imx28-flexcan", .data = &fsl_imx28_devtype_data, },
990 { .compatible = "fsl,p1010-flexcan", .data = &fsl_p1010_devtype_data, },
985 { /* sentinel */ }, 991 { /* sentinel */ },
986}; 992};
987MODULE_DEVICE_TABLE(of, flexcan_of_match); 993MODULE_DEVICE_TABLE(of, flexcan_of_match);
diff --git a/drivers/net/can/usb/kvaser_usb.c b/drivers/net/can/usb/kvaser_usb.c
index 3b9546588240..4b2d5ed62b11 100644
--- a/drivers/net/can/usb/kvaser_usb.c
+++ b/drivers/net/can/usb/kvaser_usb.c
@@ -1544,9 +1544,9 @@ static int kvaser_usb_init_one(struct usb_interface *intf,
1544 return 0; 1544 return 0;
1545} 1545}
1546 1546
1547static void kvaser_usb_get_endpoints(const struct usb_interface *intf, 1547static int kvaser_usb_get_endpoints(const struct usb_interface *intf,
1548 struct usb_endpoint_descriptor **in, 1548 struct usb_endpoint_descriptor **in,
1549 struct usb_endpoint_descriptor **out) 1549 struct usb_endpoint_descriptor **out)
1550{ 1550{
1551 const struct usb_host_interface *iface_desc; 1551 const struct usb_host_interface *iface_desc;
1552 struct usb_endpoint_descriptor *endpoint; 1552 struct usb_endpoint_descriptor *endpoint;
@@ -1557,12 +1557,18 @@ static void kvaser_usb_get_endpoints(const struct usb_interface *intf,
1557 for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) { 1557 for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
1558 endpoint = &iface_desc->endpoint[i].desc; 1558 endpoint = &iface_desc->endpoint[i].desc;
1559 1559
1560 if (usb_endpoint_is_bulk_in(endpoint)) 1560 if (!*in && usb_endpoint_is_bulk_in(endpoint))
1561 *in = endpoint; 1561 *in = endpoint;
1562 1562
1563 if (usb_endpoint_is_bulk_out(endpoint)) 1563 if (!*out && usb_endpoint_is_bulk_out(endpoint))
1564 *out = endpoint; 1564 *out = endpoint;
1565
1566 /* use first bulk endpoint for in and out */
1567 if (*in && *out)
1568 return 0;
1565 } 1569 }
1570
1571 return -ENODEV;
1566} 1572}
1567 1573
1568static int kvaser_usb_probe(struct usb_interface *intf, 1574static int kvaser_usb_probe(struct usb_interface *intf,
@@ -1576,8 +1582,8 @@ static int kvaser_usb_probe(struct usb_interface *intf,
1576 if (!dev) 1582 if (!dev)
1577 return -ENOMEM; 1583 return -ENOMEM;
1578 1584
1579 kvaser_usb_get_endpoints(intf, &dev->bulk_in, &dev->bulk_out); 1585 err = kvaser_usb_get_endpoints(intf, &dev->bulk_in, &dev->bulk_out);
1580 if (!dev->bulk_in || !dev->bulk_out) { 1586 if (err) {
1581 dev_err(&intf->dev, "Cannot get usb endpoint(s)"); 1587 dev_err(&intf->dev, "Cannot get usb endpoint(s)");
1582 return err; 1588 return err;
1583 } 1589 }
diff --git a/drivers/net/ethernet/broadcom/bgmac.c b/drivers/net/ethernet/broadcom/bgmac.c
index 249468f95365..9e8a3e024e01 100644
--- a/drivers/net/ethernet/broadcom/bgmac.c
+++ b/drivers/net/ethernet/broadcom/bgmac.c
@@ -244,25 +244,33 @@ static int bgmac_dma_rx_skb_for_slot(struct bgmac *bgmac,
244 struct bgmac_slot_info *slot) 244 struct bgmac_slot_info *slot)
245{ 245{
246 struct device *dma_dev = bgmac->core->dma_dev; 246 struct device *dma_dev = bgmac->core->dma_dev;
247 struct sk_buff *skb;
248 dma_addr_t dma_addr;
247 struct bgmac_rx_header *rx; 249 struct bgmac_rx_header *rx;
248 250
249 /* Alloc skb */ 251 /* Alloc skb */
250 slot->skb = netdev_alloc_skb(bgmac->net_dev, BGMAC_RX_BUF_SIZE); 252 skb = netdev_alloc_skb(bgmac->net_dev, BGMAC_RX_BUF_SIZE);
251 if (!slot->skb) 253 if (!skb)
252 return -ENOMEM; 254 return -ENOMEM;
253 255
254 /* Poison - if everything goes fine, hardware will overwrite it */ 256 /* Poison - if everything goes fine, hardware will overwrite it */
255 rx = (struct bgmac_rx_header *)slot->skb->data; 257 rx = (struct bgmac_rx_header *)skb->data;
256 rx->len = cpu_to_le16(0xdead); 258 rx->len = cpu_to_le16(0xdead);
257 rx->flags = cpu_to_le16(0xbeef); 259 rx->flags = cpu_to_le16(0xbeef);
258 260
259 /* Map skb for the DMA */ 261 /* Map skb for the DMA */
260 slot->dma_addr = dma_map_single(dma_dev, slot->skb->data, 262 dma_addr = dma_map_single(dma_dev, skb->data,
261 BGMAC_RX_BUF_SIZE, DMA_FROM_DEVICE); 263 BGMAC_RX_BUF_SIZE, DMA_FROM_DEVICE);
262 if (dma_mapping_error(dma_dev, slot->dma_addr)) { 264 if (dma_mapping_error(dma_dev, dma_addr)) {
263 bgmac_err(bgmac, "DMA mapping error\n"); 265 bgmac_err(bgmac, "DMA mapping error\n");
266 dev_kfree_skb(skb);
264 return -ENOMEM; 267 return -ENOMEM;
265 } 268 }
269
270 /* Update the slot */
271 slot->skb = skb;
272 slot->dma_addr = dma_addr;
273
266 if (slot->dma_addr & 0xC0000000) 274 if (slot->dma_addr & 0xC0000000)
267 bgmac_warn(bgmac, "DMA address using 0xC0000000 bit(s), it may need translation trick\n"); 275 bgmac_warn(bgmac, "DMA address using 0xC0000000 bit(s), it may need translation trick\n");
268 276
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x.h
index 97b3d32a98bd..c5e375ddd6c0 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x.h
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x.h
@@ -1197,8 +1197,9 @@ union cdu_context {
1197/* TM (timers) host DB constants */ 1197/* TM (timers) host DB constants */
1198#define TM_ILT_PAGE_SZ_HW 0 1198#define TM_ILT_PAGE_SZ_HW 0
1199#define TM_ILT_PAGE_SZ (4096 << TM_ILT_PAGE_SZ_HW) /* 4K */ 1199#define TM_ILT_PAGE_SZ (4096 << TM_ILT_PAGE_SZ_HW) /* 4K */
1200/* #define TM_CONN_NUM (CNIC_STARTING_CID+CNIC_ISCSI_CXT_MAX) */ 1200#define TM_CONN_NUM (BNX2X_FIRST_VF_CID + \
1201#define TM_CONN_NUM 1024 1201 BNX2X_VF_CIDS + \
1202 CNIC_ISCSI_CID_MAX)
1202#define TM_ILT_SZ (8 * TM_CONN_NUM) 1203#define TM_ILT_SZ (8 * TM_CONN_NUM)
1203#define TM_ILT_LINES DIV_ROUND_UP(TM_ILT_SZ, TM_ILT_PAGE_SZ) 1204#define TM_ILT_LINES DIV_ROUND_UP(TM_ILT_SZ, TM_ILT_PAGE_SZ)
1204 1205
@@ -1527,7 +1528,6 @@ struct bnx2x {
1527#define PCI_32BIT_FLAG (1 << 1) 1528#define PCI_32BIT_FLAG (1 << 1)
1528#define ONE_PORT_FLAG (1 << 2) 1529#define ONE_PORT_FLAG (1 << 2)
1529#define NO_WOL_FLAG (1 << 3) 1530#define NO_WOL_FLAG (1 << 3)
1530#define USING_DAC_FLAG (1 << 4)
1531#define USING_MSIX_FLAG (1 << 5) 1531#define USING_MSIX_FLAG (1 << 5)
1532#define USING_MSI_FLAG (1 << 6) 1532#define USING_MSI_FLAG (1 << 6)
1533#define DISABLE_MSI_FLAG (1 << 7) 1533#define DISABLE_MSI_FLAG (1 << 7)
@@ -1621,7 +1621,7 @@ struct bnx2x {
1621 u16 rx_ticks_int; 1621 u16 rx_ticks_int;
1622 u16 rx_ticks; 1622 u16 rx_ticks;
1623/* Maximal coalescing timeout in us */ 1623/* Maximal coalescing timeout in us */
1624#define BNX2X_MAX_COALESCE_TOUT (0xf0*12) 1624#define BNX2X_MAX_COALESCE_TOUT (0xff*BNX2X_BTR)
1625 1625
1626 u32 lin_cnt; 1626 u32 lin_cnt;
1627 1627
@@ -2072,7 +2072,8 @@ u32 bnx2x_dmae_opcode(struct bnx2x *bp, u8 src_type, u8 dst_type,
2072 2072
2073void bnx2x_prep_dmae_with_comp(struct bnx2x *bp, struct dmae_command *dmae, 2073void bnx2x_prep_dmae_with_comp(struct bnx2x *bp, struct dmae_command *dmae,
2074 u8 src_type, u8 dst_type); 2074 u8 src_type, u8 dst_type);
2075int bnx2x_issue_dmae_with_comp(struct bnx2x *bp, struct dmae_command *dmae); 2075int bnx2x_issue_dmae_with_comp(struct bnx2x *bp, struct dmae_command *dmae,
2076 u32 *comp);
2076 2077
2077/* FLR related routines */ 2078/* FLR related routines */
2078u32 bnx2x_flr_clnup_poll_count(struct bnx2x *bp); 2079u32 bnx2x_flr_clnup_poll_count(struct bnx2x *bp);
@@ -2498,4 +2499,8 @@ enum bnx2x_pci_bus_speed {
2498}; 2499};
2499 2500
2500void bnx2x_set_local_cmng(struct bnx2x *bp); 2501void bnx2x_set_local_cmng(struct bnx2x *bp);
2502
2503#define MCPR_SCRATCH_BASE(bp) \
2504 (CHIP_IS_E1x(bp) ? MCP_REG_MCPR_SCRATCH : MCP_A_REG_MCPR_SCRATCH)
2505
2501#endif /* bnx2x.h */ 2506#endif /* bnx2x.h */
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
index e66beff2704d..74d6486fccfd 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
@@ -681,6 +681,7 @@ static void bnx2x_gro_receive(struct bnx2x *bp, struct bnx2x_fastpath *fp,
681 } 681 }
682 } 682 }
683#endif 683#endif
684 skb_record_rx_queue(skb, fp->rx_queue);
684 napi_gro_receive(&fp->napi, skb); 685 napi_gro_receive(&fp->napi, skb);
685} 686}
686 687
@@ -2544,10 +2545,6 @@ int bnx2x_nic_load(struct bnx2x *bp, int load_mode)
2544 } 2545 }
2545 } 2546 }
2546 2547
2547 /* Allocated memory for FW statistics */
2548 if (bnx2x_alloc_fw_stats_mem(bp))
2549 LOAD_ERROR_EXIT(bp, load_error0);
2550
2551 /* need to be done after alloc mem, since it's self adjusting to amount 2548 /* need to be done after alloc mem, since it's self adjusting to amount
2552 * of memory available for RSS queues 2549 * of memory available for RSS queues
2553 */ 2550 */
@@ -2557,6 +2554,10 @@ int bnx2x_nic_load(struct bnx2x *bp, int load_mode)
2557 LOAD_ERROR_EXIT(bp, load_error0); 2554 LOAD_ERROR_EXIT(bp, load_error0);
2558 } 2555 }
2559 2556
2557 /* Allocated memory for FW statistics */
2558 if (bnx2x_alloc_fw_stats_mem(bp))
2559 LOAD_ERROR_EXIT(bp, load_error0);
2560
2560 /* request pf to initialize status blocks */ 2561 /* request pf to initialize status blocks */
2561 if (IS_VF(bp)) { 2562 if (IS_VF(bp)) {
2562 rc = bnx2x_vfpf_init(bp); 2563 rc = bnx2x_vfpf_init(bp);
@@ -2811,8 +2812,8 @@ load_error1:
2811 if (IS_PF(bp)) 2812 if (IS_PF(bp))
2812 bnx2x_clear_pf_load(bp); 2813 bnx2x_clear_pf_load(bp);
2813load_error0: 2814load_error0:
2814 bnx2x_free_fp_mem(bp);
2815 bnx2x_free_fw_stats_mem(bp); 2815 bnx2x_free_fw_stats_mem(bp);
2816 bnx2x_free_fp_mem(bp);
2816 bnx2x_free_mem(bp); 2817 bnx2x_free_mem(bp);
2817 2818
2818 return rc; 2819 return rc;
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c
index 324de5f05332..e8efa1c93ffe 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c
@@ -891,17 +891,8 @@ static void bnx2x_get_regs(struct net_device *dev,
891 * will re-enable parity attentions right after the dump. 891 * will re-enable parity attentions right after the dump.
892 */ 892 */
893 893
894 /* Disable parity on path 0 */
895 bnx2x_pretend_func(bp, 0);
896 bnx2x_disable_blocks_parity(bp); 894 bnx2x_disable_blocks_parity(bp);
897 895
898 /* Disable parity on path 1 */
899 bnx2x_pretend_func(bp, 1);
900 bnx2x_disable_blocks_parity(bp);
901
902 /* Return to current function */
903 bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
904
905 dump_hdr.header_size = (sizeof(struct dump_header) / 4) - 1; 896 dump_hdr.header_size = (sizeof(struct dump_header) / 4) - 1;
906 dump_hdr.preset = DUMP_ALL_PRESETS; 897 dump_hdr.preset = DUMP_ALL_PRESETS;
907 dump_hdr.version = BNX2X_DUMP_VERSION; 898 dump_hdr.version = BNX2X_DUMP_VERSION;
@@ -928,18 +919,9 @@ static void bnx2x_get_regs(struct net_device *dev,
928 /* Actually read the registers */ 919 /* Actually read the registers */
929 __bnx2x_get_regs(bp, p); 920 __bnx2x_get_regs(bp, p);
930 921
931 /* Re-enable parity attentions on path 0 */ 922 /* Re-enable parity attentions */
932 bnx2x_pretend_func(bp, 0);
933 bnx2x_clear_blocks_parity(bp); 923 bnx2x_clear_blocks_parity(bp);
934 bnx2x_enable_blocks_parity(bp); 924 bnx2x_enable_blocks_parity(bp);
935
936 /* Re-enable parity attentions on path 1 */
937 bnx2x_pretend_func(bp, 1);
938 bnx2x_clear_blocks_parity(bp);
939 bnx2x_enable_blocks_parity(bp);
940
941 /* Return to current function */
942 bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
943} 925}
944 926
945static int bnx2x_get_preset_regs_len(struct net_device *dev, u32 preset) 927static int bnx2x_get_preset_regs_len(struct net_device *dev, u32 preset)
@@ -993,17 +975,8 @@ static int bnx2x_get_dump_data(struct net_device *dev,
993 * will re-enable parity attentions right after the dump. 975 * will re-enable parity attentions right after the dump.
994 */ 976 */
995 977
996 /* Disable parity on path 0 */
997 bnx2x_pretend_func(bp, 0);
998 bnx2x_disable_blocks_parity(bp); 978 bnx2x_disable_blocks_parity(bp);
999 979
1000 /* Disable parity on path 1 */
1001 bnx2x_pretend_func(bp, 1);
1002 bnx2x_disable_blocks_parity(bp);
1003
1004 /* Return to current function */
1005 bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
1006
1007 dump_hdr.header_size = (sizeof(struct dump_header) / 4) - 1; 980 dump_hdr.header_size = (sizeof(struct dump_header) / 4) - 1;
1008 dump_hdr.preset = bp->dump_preset_idx; 981 dump_hdr.preset = bp->dump_preset_idx;
1009 dump_hdr.version = BNX2X_DUMP_VERSION; 982 dump_hdr.version = BNX2X_DUMP_VERSION;
@@ -1032,19 +1005,10 @@ static int bnx2x_get_dump_data(struct net_device *dev,
1032 /* Actually read the registers */ 1005 /* Actually read the registers */
1033 __bnx2x_get_preset_regs(bp, p, dump_hdr.preset); 1006 __bnx2x_get_preset_regs(bp, p, dump_hdr.preset);
1034 1007
1035 /* Re-enable parity attentions on path 0 */ 1008 /* Re-enable parity attentions */
1036 bnx2x_pretend_func(bp, 0);
1037 bnx2x_clear_blocks_parity(bp); 1009 bnx2x_clear_blocks_parity(bp);
1038 bnx2x_enable_blocks_parity(bp); 1010 bnx2x_enable_blocks_parity(bp);
1039 1011
1040 /* Re-enable parity attentions on path 1 */
1041 bnx2x_pretend_func(bp, 1);
1042 bnx2x_clear_blocks_parity(bp);
1043 bnx2x_enable_blocks_parity(bp);
1044
1045 /* Return to current function */
1046 bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
1047
1048 return 0; 1012 return 0;
1049} 1013}
1050 1014
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_init.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_init.h
index 76df015f486a..c2dfea7968f4 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_init.h
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_init.h
@@ -640,23 +640,35 @@ static const struct {
640 * [30] MCP Latched ump_tx_parity 640 * [30] MCP Latched ump_tx_parity
641 * [31] MCP Latched scpad_parity 641 * [31] MCP Latched scpad_parity
642 */ 642 */
643#define MISC_AEU_ENABLE_MCP_PRTY_BITS \ 643#define MISC_AEU_ENABLE_MCP_PRTY_SUB_BITS \
644 (AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY | \ 644 (AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY | \
645 AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY | \ 645 AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY | \
646 AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY | \ 646 AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY)
647
648#define MISC_AEU_ENABLE_MCP_PRTY_BITS \
649 (MISC_AEU_ENABLE_MCP_PRTY_SUB_BITS | \
647 AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY) 650 AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY)
648 651
649/* Below registers control the MCP parity attention output. When 652/* Below registers control the MCP parity attention output. When
650 * MISC_AEU_ENABLE_MCP_PRTY_BITS are set - attentions are 653 * MISC_AEU_ENABLE_MCP_PRTY_BITS are set - attentions are
651 * enabled, when cleared - disabled. 654 * enabled, when cleared - disabled.
652 */ 655 */
653static const u32 mcp_attn_ctl_regs[] = { 656static const struct {
654 MISC_REG_AEU_ENABLE4_FUNC_0_OUT_0, 657 u32 addr;
655 MISC_REG_AEU_ENABLE4_NIG_0, 658 u32 bits;
656 MISC_REG_AEU_ENABLE4_PXP_0, 659} mcp_attn_ctl_regs[] = {
657 MISC_REG_AEU_ENABLE4_FUNC_1_OUT_0, 660 { MISC_REG_AEU_ENABLE4_FUNC_0_OUT_0,
658 MISC_REG_AEU_ENABLE4_NIG_1, 661 MISC_AEU_ENABLE_MCP_PRTY_BITS },
659 MISC_REG_AEU_ENABLE4_PXP_1 662 { MISC_REG_AEU_ENABLE4_NIG_0,
663 MISC_AEU_ENABLE_MCP_PRTY_SUB_BITS },
664 { MISC_REG_AEU_ENABLE4_PXP_0,
665 MISC_AEU_ENABLE_MCP_PRTY_SUB_BITS },
666 { MISC_REG_AEU_ENABLE4_FUNC_1_OUT_0,
667 MISC_AEU_ENABLE_MCP_PRTY_BITS },
668 { MISC_REG_AEU_ENABLE4_NIG_1,
669 MISC_AEU_ENABLE_MCP_PRTY_SUB_BITS },
670 { MISC_REG_AEU_ENABLE4_PXP_1,
671 MISC_AEU_ENABLE_MCP_PRTY_SUB_BITS }
660}; 672};
661 673
662static inline void bnx2x_set_mcp_parity(struct bnx2x *bp, u8 enable) 674static inline void bnx2x_set_mcp_parity(struct bnx2x *bp, u8 enable)
@@ -665,14 +677,14 @@ static inline void bnx2x_set_mcp_parity(struct bnx2x *bp, u8 enable)
665 u32 reg_val; 677 u32 reg_val;
666 678
667 for (i = 0; i < ARRAY_SIZE(mcp_attn_ctl_regs); i++) { 679 for (i = 0; i < ARRAY_SIZE(mcp_attn_ctl_regs); i++) {
668 reg_val = REG_RD(bp, mcp_attn_ctl_regs[i]); 680 reg_val = REG_RD(bp, mcp_attn_ctl_regs[i].addr);
669 681
670 if (enable) 682 if (enable)
671 reg_val |= MISC_AEU_ENABLE_MCP_PRTY_BITS; 683 reg_val |= mcp_attn_ctl_regs[i].bits;
672 else 684 else
673 reg_val &= ~MISC_AEU_ENABLE_MCP_PRTY_BITS; 685 reg_val &= ~mcp_attn_ctl_regs[i].bits;
674 686
675 REG_WR(bp, mcp_attn_ctl_regs[i], reg_val); 687 REG_WR(bp, mcp_attn_ctl_regs[i].addr, reg_val);
676 } 688 }
677} 689}
678 690
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
index 82b658d8c04c..b42f89ce02ef 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
@@ -503,9 +503,9 @@ void bnx2x_prep_dmae_with_comp(struct bnx2x *bp,
503} 503}
504 504
505/* issue a dmae command over the init-channel and wait for completion */ 505/* issue a dmae command over the init-channel and wait for completion */
506int bnx2x_issue_dmae_with_comp(struct bnx2x *bp, struct dmae_command *dmae) 506int bnx2x_issue_dmae_with_comp(struct bnx2x *bp, struct dmae_command *dmae,
507 u32 *comp)
507{ 508{
508 u32 *wb_comp = bnx2x_sp(bp, wb_comp);
509 int cnt = CHIP_REV_IS_SLOW(bp) ? (400000) : 4000; 509 int cnt = CHIP_REV_IS_SLOW(bp) ? (400000) : 4000;
510 int rc = 0; 510 int rc = 0;
511 511
@@ -518,14 +518,14 @@ int bnx2x_issue_dmae_with_comp(struct bnx2x *bp, struct dmae_command *dmae)
518 spin_lock_bh(&bp->dmae_lock); 518 spin_lock_bh(&bp->dmae_lock);
519 519
520 /* reset completion */ 520 /* reset completion */
521 *wb_comp = 0; 521 *comp = 0;
522 522
523 /* post the command on the channel used for initializations */ 523 /* post the command on the channel used for initializations */
524 bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp)); 524 bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp));
525 525
526 /* wait for completion */ 526 /* wait for completion */
527 udelay(5); 527 udelay(5);
528 while ((*wb_comp & ~DMAE_PCI_ERR_FLAG) != DMAE_COMP_VAL) { 528 while ((*comp & ~DMAE_PCI_ERR_FLAG) != DMAE_COMP_VAL) {
529 529
530 if (!cnt || 530 if (!cnt ||
531 (bp->recovery_state != BNX2X_RECOVERY_DONE && 531 (bp->recovery_state != BNX2X_RECOVERY_DONE &&
@@ -537,7 +537,7 @@ int bnx2x_issue_dmae_with_comp(struct bnx2x *bp, struct dmae_command *dmae)
537 cnt--; 537 cnt--;
538 udelay(50); 538 udelay(50);
539 } 539 }
540 if (*wb_comp & DMAE_PCI_ERR_FLAG) { 540 if (*comp & DMAE_PCI_ERR_FLAG) {
541 BNX2X_ERR("DMAE PCI error!\n"); 541 BNX2X_ERR("DMAE PCI error!\n");
542 rc = DMAE_PCI_ERROR; 542 rc = DMAE_PCI_ERROR;
543 } 543 }
@@ -574,7 +574,7 @@ void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr,
574 dmae.len = len32; 574 dmae.len = len32;
575 575
576 /* issue the command and wait for completion */ 576 /* issue the command and wait for completion */
577 rc = bnx2x_issue_dmae_with_comp(bp, &dmae); 577 rc = bnx2x_issue_dmae_with_comp(bp, &dmae, bnx2x_sp(bp, wb_comp));
578 if (rc) { 578 if (rc) {
579 BNX2X_ERR("DMAE returned failure %d\n", rc); 579 BNX2X_ERR("DMAE returned failure %d\n", rc);
580 bnx2x_panic(); 580 bnx2x_panic();
@@ -611,7 +611,7 @@ void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32)
611 dmae.len = len32; 611 dmae.len = len32;
612 612
613 /* issue the command and wait for completion */ 613 /* issue the command and wait for completion */
614 rc = bnx2x_issue_dmae_with_comp(bp, &dmae); 614 rc = bnx2x_issue_dmae_with_comp(bp, &dmae, bnx2x_sp(bp, wb_comp));
615 if (rc) { 615 if (rc) {
616 BNX2X_ERR("DMAE returned failure %d\n", rc); 616 BNX2X_ERR("DMAE returned failure %d\n", rc);
617 bnx2x_panic(); 617 bnx2x_panic();
@@ -751,6 +751,10 @@ static int bnx2x_mc_assert(struct bnx2x *bp)
751 return rc; 751 return rc;
752} 752}
753 753
754#define MCPR_TRACE_BUFFER_SIZE (0x800)
755#define SCRATCH_BUFFER_SIZE(bp) \
756 (CHIP_IS_E1(bp) ? 0x10000 : (CHIP_IS_E1H(bp) ? 0x20000 : 0x28000))
757
754void bnx2x_fw_dump_lvl(struct bnx2x *bp, const char *lvl) 758void bnx2x_fw_dump_lvl(struct bnx2x *bp, const char *lvl)
755{ 759{
756 u32 addr, val; 760 u32 addr, val;
@@ -775,7 +779,17 @@ void bnx2x_fw_dump_lvl(struct bnx2x *bp, const char *lvl)
775 trace_shmem_base = bp->common.shmem_base; 779 trace_shmem_base = bp->common.shmem_base;
776 else 780 else
777 trace_shmem_base = SHMEM2_RD(bp, other_shmem_base_addr); 781 trace_shmem_base = SHMEM2_RD(bp, other_shmem_base_addr);
778 addr = trace_shmem_base - 0x800; 782
783 /* sanity */
784 if (trace_shmem_base < MCPR_SCRATCH_BASE(bp) + MCPR_TRACE_BUFFER_SIZE ||
785 trace_shmem_base >= MCPR_SCRATCH_BASE(bp) +
786 SCRATCH_BUFFER_SIZE(bp)) {
787 BNX2X_ERR("Unable to dump trace buffer (mark %x)\n",
788 trace_shmem_base);
789 return;
790 }
791
792 addr = trace_shmem_base - MCPR_TRACE_BUFFER_SIZE;
779 793
780 /* validate TRCB signature */ 794 /* validate TRCB signature */
781 mark = REG_RD(bp, addr); 795 mark = REG_RD(bp, addr);
@@ -787,14 +801,17 @@ void bnx2x_fw_dump_lvl(struct bnx2x *bp, const char *lvl)
787 /* read cyclic buffer pointer */ 801 /* read cyclic buffer pointer */
788 addr += 4; 802 addr += 4;
789 mark = REG_RD(bp, addr); 803 mark = REG_RD(bp, addr);
790 mark = (CHIP_IS_E1x(bp) ? MCP_REG_MCPR_SCRATCH : MCP_A_REG_MCPR_SCRATCH) 804 mark = MCPR_SCRATCH_BASE(bp) + ((mark + 0x3) & ~0x3) - 0x08000000;
791 + ((mark + 0x3) & ~0x3) - 0x08000000; 805 if (mark >= trace_shmem_base || mark < addr + 4) {
806 BNX2X_ERR("Mark doesn't fall inside Trace Buffer\n");
807 return;
808 }
792 printk("%s" "begin fw dump (mark 0x%x)\n", lvl, mark); 809 printk("%s" "begin fw dump (mark 0x%x)\n", lvl, mark);
793 810
794 printk("%s", lvl); 811 printk("%s", lvl);
795 812
796 /* dump buffer after the mark */ 813 /* dump buffer after the mark */
797 for (offset = mark; offset <= trace_shmem_base; offset += 0x8*4) { 814 for (offset = mark; offset < trace_shmem_base; offset += 0x8*4) {
798 for (word = 0; word < 8; word++) 815 for (word = 0; word < 8; word++)
799 data[word] = htonl(REG_RD(bp, offset + 4*word)); 816 data[word] = htonl(REG_RD(bp, offset + 4*word));
800 data[8] = 0x0; 817 data[8] = 0x0;
@@ -4280,65 +4297,60 @@ static void _print_next_block(int idx, const char *blk)
4280 pr_cont("%s%s", idx ? ", " : "", blk); 4297 pr_cont("%s%s", idx ? ", " : "", blk);
4281} 4298}
4282 4299
4283static int bnx2x_check_blocks_with_parity0(struct bnx2x *bp, u32 sig, 4300static bool bnx2x_check_blocks_with_parity0(struct bnx2x *bp, u32 sig,
4284 int par_num, bool print) 4301 int *par_num, bool print)
4285{ 4302{
4286 int i = 0; 4303 u32 cur_bit;
4287 u32 cur_bit = 0; 4304 bool res;
4305 int i;
4306
4307 res = false;
4308
4288 for (i = 0; sig; i++) { 4309 for (i = 0; sig; i++) {
4289 cur_bit = ((u32)0x1 << i); 4310 cur_bit = (0x1UL << i);
4290 if (sig & cur_bit) { 4311 if (sig & cur_bit) {
4291 switch (cur_bit) { 4312 res |= true; /* Each bit is real error! */
4292 case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR: 4313
4293 if (print) { 4314 if (print) {
4294 _print_next_block(par_num++, "BRB"); 4315 switch (cur_bit) {
4316 case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR:
4317 _print_next_block((*par_num)++, "BRB");
4295 _print_parity(bp, 4318 _print_parity(bp,
4296 BRB1_REG_BRB1_PRTY_STS); 4319 BRB1_REG_BRB1_PRTY_STS);
4297 } 4320 break;
4298 break; 4321 case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR:
4299 case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR: 4322 _print_next_block((*par_num)++,
4300 if (print) { 4323 "PARSER");
4301 _print_next_block(par_num++, "PARSER");
4302 _print_parity(bp, PRS_REG_PRS_PRTY_STS); 4324 _print_parity(bp, PRS_REG_PRS_PRTY_STS);
4303 } 4325 break;
4304 break; 4326 case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR:
4305 case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR: 4327 _print_next_block((*par_num)++, "TSDM");
4306 if (print) {
4307 _print_next_block(par_num++, "TSDM");
4308 _print_parity(bp, 4328 _print_parity(bp,
4309 TSDM_REG_TSDM_PRTY_STS); 4329 TSDM_REG_TSDM_PRTY_STS);
4310 } 4330 break;
4311 break; 4331 case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR:
4312 case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR: 4332 _print_next_block((*par_num)++,
4313 if (print) {
4314 _print_next_block(par_num++,
4315 "SEARCHER"); 4333 "SEARCHER");
4316 _print_parity(bp, SRC_REG_SRC_PRTY_STS); 4334 _print_parity(bp, SRC_REG_SRC_PRTY_STS);
4317 } 4335 break;
4318 break; 4336 case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR:
4319 case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR: 4337 _print_next_block((*par_num)++, "TCM");
4320 if (print) { 4338 _print_parity(bp, TCM_REG_TCM_PRTY_STS);
4321 _print_next_block(par_num++, "TCM"); 4339 break;
4322 _print_parity(bp, 4340 case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR:
4323 TCM_REG_TCM_PRTY_STS); 4341 _print_next_block((*par_num)++,
4324 } 4342 "TSEMI");
4325 break;
4326 case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR:
4327 if (print) {
4328 _print_next_block(par_num++, "TSEMI");
4329 _print_parity(bp, 4343 _print_parity(bp,
4330 TSEM_REG_TSEM_PRTY_STS_0); 4344 TSEM_REG_TSEM_PRTY_STS_0);
4331 _print_parity(bp, 4345 _print_parity(bp,
4332 TSEM_REG_TSEM_PRTY_STS_1); 4346 TSEM_REG_TSEM_PRTY_STS_1);
4333 } 4347 break;
4334 break; 4348 case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR:
4335 case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR: 4349 _print_next_block((*par_num)++, "XPB");
4336 if (print) {
4337 _print_next_block(par_num++, "XPB");
4338 _print_parity(bp, GRCBASE_XPB + 4350 _print_parity(bp, GRCBASE_XPB +
4339 PB_REG_PB_PRTY_STS); 4351 PB_REG_PB_PRTY_STS);
4352 break;
4340 } 4353 }
4341 break;
4342 } 4354 }
4343 4355
4344 /* Clear the bit */ 4356 /* Clear the bit */
@@ -4346,53 +4358,59 @@ static int bnx2x_check_blocks_with_parity0(struct bnx2x *bp, u32 sig,
4346 } 4358 }
4347 } 4359 }
4348 4360
4349 return par_num; 4361 return res;
4350} 4362}
4351 4363
4352static int bnx2x_check_blocks_with_parity1(struct bnx2x *bp, u32 sig, 4364static bool bnx2x_check_blocks_with_parity1(struct bnx2x *bp, u32 sig,
4353 int par_num, bool *global, 4365 int *par_num, bool *global,
4354 bool print) 4366 bool print)
4355{ 4367{
4356 int i = 0; 4368 u32 cur_bit;
4357 u32 cur_bit = 0; 4369 bool res;
4370 int i;
4371
4372 res = false;
4373
4358 for (i = 0; sig; i++) { 4374 for (i = 0; sig; i++) {
4359 cur_bit = ((u32)0x1 << i); 4375 cur_bit = (0x1UL << i);
4360 if (sig & cur_bit) { 4376 if (sig & cur_bit) {
4377 res |= true; /* Each bit is real error! */
4361 switch (cur_bit) { 4378 switch (cur_bit) {
4362 case AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR: 4379 case AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR:
4363 if (print) { 4380 if (print) {
4364 _print_next_block(par_num++, "PBF"); 4381 _print_next_block((*par_num)++, "PBF");
4365 _print_parity(bp, PBF_REG_PBF_PRTY_STS); 4382 _print_parity(bp, PBF_REG_PBF_PRTY_STS);
4366 } 4383 }
4367 break; 4384 break;
4368 case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR: 4385 case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR:
4369 if (print) { 4386 if (print) {
4370 _print_next_block(par_num++, "QM"); 4387 _print_next_block((*par_num)++, "QM");
4371 _print_parity(bp, QM_REG_QM_PRTY_STS); 4388 _print_parity(bp, QM_REG_QM_PRTY_STS);
4372 } 4389 }
4373 break; 4390 break;
4374 case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR: 4391 case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR:
4375 if (print) { 4392 if (print) {
4376 _print_next_block(par_num++, "TM"); 4393 _print_next_block((*par_num)++, "TM");
4377 _print_parity(bp, TM_REG_TM_PRTY_STS); 4394 _print_parity(bp, TM_REG_TM_PRTY_STS);
4378 } 4395 }
4379 break; 4396 break;
4380 case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR: 4397 case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR:
4381 if (print) { 4398 if (print) {
4382 _print_next_block(par_num++, "XSDM"); 4399 _print_next_block((*par_num)++, "XSDM");
4383 _print_parity(bp, 4400 _print_parity(bp,
4384 XSDM_REG_XSDM_PRTY_STS); 4401 XSDM_REG_XSDM_PRTY_STS);
4385 } 4402 }
4386 break; 4403 break;
4387 case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR: 4404 case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR:
4388 if (print) { 4405 if (print) {
4389 _print_next_block(par_num++, "XCM"); 4406 _print_next_block((*par_num)++, "XCM");
4390 _print_parity(bp, XCM_REG_XCM_PRTY_STS); 4407 _print_parity(bp, XCM_REG_XCM_PRTY_STS);
4391 } 4408 }
4392 break; 4409 break;
4393 case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR: 4410 case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR:
4394 if (print) { 4411 if (print) {
4395 _print_next_block(par_num++, "XSEMI"); 4412 _print_next_block((*par_num)++,
4413 "XSEMI");
4396 _print_parity(bp, 4414 _print_parity(bp,
4397 XSEM_REG_XSEM_PRTY_STS_0); 4415 XSEM_REG_XSEM_PRTY_STS_0);
4398 _print_parity(bp, 4416 _print_parity(bp,
@@ -4401,7 +4419,7 @@ static int bnx2x_check_blocks_with_parity1(struct bnx2x *bp, u32 sig,
4401 break; 4419 break;
4402 case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR: 4420 case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR:
4403 if (print) { 4421 if (print) {
4404 _print_next_block(par_num++, 4422 _print_next_block((*par_num)++,
4405 "DOORBELLQ"); 4423 "DOORBELLQ");
4406 _print_parity(bp, 4424 _print_parity(bp,
4407 DORQ_REG_DORQ_PRTY_STS); 4425 DORQ_REG_DORQ_PRTY_STS);
@@ -4409,7 +4427,7 @@ static int bnx2x_check_blocks_with_parity1(struct bnx2x *bp, u32 sig,
4409 break; 4427 break;
4410 case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR: 4428 case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR:
4411 if (print) { 4429 if (print) {
4412 _print_next_block(par_num++, "NIG"); 4430 _print_next_block((*par_num)++, "NIG");
4413 if (CHIP_IS_E1x(bp)) { 4431 if (CHIP_IS_E1x(bp)) {
4414 _print_parity(bp, 4432 _print_parity(bp,
4415 NIG_REG_NIG_PRTY_STS); 4433 NIG_REG_NIG_PRTY_STS);
@@ -4423,32 +4441,34 @@ static int bnx2x_check_blocks_with_parity1(struct bnx2x *bp, u32 sig,
4423 break; 4441 break;
4424 case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR: 4442 case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR:
4425 if (print) 4443 if (print)
4426 _print_next_block(par_num++, 4444 _print_next_block((*par_num)++,
4427 "VAUX PCI CORE"); 4445 "VAUX PCI CORE");
4428 *global = true; 4446 *global = true;
4429 break; 4447 break;
4430 case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR: 4448 case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR:
4431 if (print) { 4449 if (print) {
4432 _print_next_block(par_num++, "DEBUG"); 4450 _print_next_block((*par_num)++,
4451 "DEBUG");
4433 _print_parity(bp, DBG_REG_DBG_PRTY_STS); 4452 _print_parity(bp, DBG_REG_DBG_PRTY_STS);
4434 } 4453 }
4435 break; 4454 break;
4436 case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR: 4455 case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR:
4437 if (print) { 4456 if (print) {
4438 _print_next_block(par_num++, "USDM"); 4457 _print_next_block((*par_num)++, "USDM");
4439 _print_parity(bp, 4458 _print_parity(bp,
4440 USDM_REG_USDM_PRTY_STS); 4459 USDM_REG_USDM_PRTY_STS);
4441 } 4460 }
4442 break; 4461 break;
4443 case AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR: 4462 case AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR:
4444 if (print) { 4463 if (print) {
4445 _print_next_block(par_num++, "UCM"); 4464 _print_next_block((*par_num)++, "UCM");
4446 _print_parity(bp, UCM_REG_UCM_PRTY_STS); 4465 _print_parity(bp, UCM_REG_UCM_PRTY_STS);
4447 } 4466 }
4448 break; 4467 break;
4449 case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR: 4468 case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR:
4450 if (print) { 4469 if (print) {
4451 _print_next_block(par_num++, "USEMI"); 4470 _print_next_block((*par_num)++,
4471 "USEMI");
4452 _print_parity(bp, 4472 _print_parity(bp,
4453 USEM_REG_USEM_PRTY_STS_0); 4473 USEM_REG_USEM_PRTY_STS_0);
4454 _print_parity(bp, 4474 _print_parity(bp,
@@ -4457,21 +4477,21 @@ static int bnx2x_check_blocks_with_parity1(struct bnx2x *bp, u32 sig,
4457 break; 4477 break;
4458 case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR: 4478 case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR:
4459 if (print) { 4479 if (print) {
4460 _print_next_block(par_num++, "UPB"); 4480 _print_next_block((*par_num)++, "UPB");
4461 _print_parity(bp, GRCBASE_UPB + 4481 _print_parity(bp, GRCBASE_UPB +
4462 PB_REG_PB_PRTY_STS); 4482 PB_REG_PB_PRTY_STS);
4463 } 4483 }
4464 break; 4484 break;
4465 case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR: 4485 case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR:
4466 if (print) { 4486 if (print) {
4467 _print_next_block(par_num++, "CSDM"); 4487 _print_next_block((*par_num)++, "CSDM");
4468 _print_parity(bp, 4488 _print_parity(bp,
4469 CSDM_REG_CSDM_PRTY_STS); 4489 CSDM_REG_CSDM_PRTY_STS);
4470 } 4490 }
4471 break; 4491 break;
4472 case AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR: 4492 case AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR:
4473 if (print) { 4493 if (print) {
4474 _print_next_block(par_num++, "CCM"); 4494 _print_next_block((*par_num)++, "CCM");
4475 _print_parity(bp, CCM_REG_CCM_PRTY_STS); 4495 _print_parity(bp, CCM_REG_CCM_PRTY_STS);
4476 } 4496 }
4477 break; 4497 break;
@@ -4482,80 +4502,73 @@ static int bnx2x_check_blocks_with_parity1(struct bnx2x *bp, u32 sig,
4482 } 4502 }
4483 } 4503 }
4484 4504
4485 return par_num; 4505 return res;
4486} 4506}
4487 4507
4488static int bnx2x_check_blocks_with_parity2(struct bnx2x *bp, u32 sig, 4508static bool bnx2x_check_blocks_with_parity2(struct bnx2x *bp, u32 sig,
4489 int par_num, bool print) 4509 int *par_num, bool print)
4490{ 4510{
4491 int i = 0; 4511 u32 cur_bit;
4492 u32 cur_bit = 0; 4512 bool res;
4513 int i;
4514
4515 res = false;
4516
4493 for (i = 0; sig; i++) { 4517 for (i = 0; sig; i++) {
4494 cur_bit = ((u32)0x1 << i); 4518 cur_bit = (0x1UL << i);
4495 if (sig & cur_bit) { 4519 if (sig & cur_bit) {
4496 switch (cur_bit) { 4520 res |= true; /* Each bit is real error! */
4497 case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR: 4521 if (print) {
4498 if (print) { 4522 switch (cur_bit) {
4499 _print_next_block(par_num++, "CSEMI"); 4523 case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR:
4524 _print_next_block((*par_num)++,
4525 "CSEMI");
4500 _print_parity(bp, 4526 _print_parity(bp,
4501 CSEM_REG_CSEM_PRTY_STS_0); 4527 CSEM_REG_CSEM_PRTY_STS_0);
4502 _print_parity(bp, 4528 _print_parity(bp,
4503 CSEM_REG_CSEM_PRTY_STS_1); 4529 CSEM_REG_CSEM_PRTY_STS_1);
4504 } 4530 break;
4505 break; 4531 case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR:
4506 case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR: 4532 _print_next_block((*par_num)++, "PXP");
4507 if (print) {
4508 _print_next_block(par_num++, "PXP");
4509 _print_parity(bp, PXP_REG_PXP_PRTY_STS); 4533 _print_parity(bp, PXP_REG_PXP_PRTY_STS);
4510 _print_parity(bp, 4534 _print_parity(bp,
4511 PXP2_REG_PXP2_PRTY_STS_0); 4535 PXP2_REG_PXP2_PRTY_STS_0);
4512 _print_parity(bp, 4536 _print_parity(bp,
4513 PXP2_REG_PXP2_PRTY_STS_1); 4537 PXP2_REG_PXP2_PRTY_STS_1);
4514 } 4538 break;
4515 break; 4539 case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR:
4516 case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR: 4540 _print_next_block((*par_num)++,
4517 if (print) 4541 "PXPPCICLOCKCLIENT");
4518 _print_next_block(par_num++, 4542 break;
4519 "PXPPCICLOCKCLIENT"); 4543 case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR:
4520 break; 4544 _print_next_block((*par_num)++, "CFC");
4521 case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR:
4522 if (print) {
4523 _print_next_block(par_num++, "CFC");
4524 _print_parity(bp, 4545 _print_parity(bp,
4525 CFC_REG_CFC_PRTY_STS); 4546 CFC_REG_CFC_PRTY_STS);
4526 } 4547 break;
4527 break; 4548 case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR:
4528 case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR: 4549 _print_next_block((*par_num)++, "CDU");
4529 if (print) {
4530 _print_next_block(par_num++, "CDU");
4531 _print_parity(bp, CDU_REG_CDU_PRTY_STS); 4550 _print_parity(bp, CDU_REG_CDU_PRTY_STS);
4532 } 4551 break;
4533 break; 4552 case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR:
4534 case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR: 4553 _print_next_block((*par_num)++, "DMAE");
4535 if (print) {
4536 _print_next_block(par_num++, "DMAE");
4537 _print_parity(bp, 4554 _print_parity(bp,
4538 DMAE_REG_DMAE_PRTY_STS); 4555 DMAE_REG_DMAE_PRTY_STS);
4539 } 4556 break;
4540 break; 4557 case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR:
4541 case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR: 4558 _print_next_block((*par_num)++, "IGU");
4542 if (print) {
4543 _print_next_block(par_num++, "IGU");
4544 if (CHIP_IS_E1x(bp)) 4559 if (CHIP_IS_E1x(bp))
4545 _print_parity(bp, 4560 _print_parity(bp,
4546 HC_REG_HC_PRTY_STS); 4561 HC_REG_HC_PRTY_STS);
4547 else 4562 else
4548 _print_parity(bp, 4563 _print_parity(bp,
4549 IGU_REG_IGU_PRTY_STS); 4564 IGU_REG_IGU_PRTY_STS);
4550 } 4565 break;
4551 break; 4566 case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR:
4552 case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR: 4567 _print_next_block((*par_num)++, "MISC");
4553 if (print) {
4554 _print_next_block(par_num++, "MISC");
4555 _print_parity(bp, 4568 _print_parity(bp,
4556 MISC_REG_MISC_PRTY_STS); 4569 MISC_REG_MISC_PRTY_STS);
4570 break;
4557 } 4571 }
4558 break;
4559 } 4572 }
4560 4573
4561 /* Clear the bit */ 4574 /* Clear the bit */
@@ -4563,40 +4576,49 @@ static int bnx2x_check_blocks_with_parity2(struct bnx2x *bp, u32 sig,
4563 } 4576 }
4564 } 4577 }
4565 4578
4566 return par_num; 4579 return res;
4567} 4580}
4568 4581
4569static int bnx2x_check_blocks_with_parity3(u32 sig, int par_num, 4582static bool bnx2x_check_blocks_with_parity3(struct bnx2x *bp, u32 sig,
4570 bool *global, bool print) 4583 int *par_num, bool *global,
4584 bool print)
4571{ 4585{
4572 int i = 0; 4586 bool res = false;
4573 u32 cur_bit = 0; 4587 u32 cur_bit;
4588 int i;
4589
4574 for (i = 0; sig; i++) { 4590 for (i = 0; sig; i++) {
4575 cur_bit = ((u32)0x1 << i); 4591 cur_bit = (0x1UL << i);
4576 if (sig & cur_bit) { 4592 if (sig & cur_bit) {
4577 switch (cur_bit) { 4593 switch (cur_bit) {
4578 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY: 4594 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY:
4579 if (print) 4595 if (print)
4580 _print_next_block(par_num++, "MCP ROM"); 4596 _print_next_block((*par_num)++,
4597 "MCP ROM");
4581 *global = true; 4598 *global = true;
4599 res |= true;
4582 break; 4600 break;
4583 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY: 4601 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY:
4584 if (print) 4602 if (print)
4585 _print_next_block(par_num++, 4603 _print_next_block((*par_num)++,
4586 "MCP UMP RX"); 4604 "MCP UMP RX");
4587 *global = true; 4605 *global = true;
4606 res |= true;
4588 break; 4607 break;
4589 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY: 4608 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY:
4590 if (print) 4609 if (print)
4591 _print_next_block(par_num++, 4610 _print_next_block((*par_num)++,
4592 "MCP UMP TX"); 4611 "MCP UMP TX");
4593 *global = true; 4612 *global = true;
4613 res |= true;
4594 break; 4614 break;
4595 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY: 4615 case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY:
4596 if (print) 4616 if (print)
4597 _print_next_block(par_num++, 4617 _print_next_block((*par_num)++,
4598 "MCP SCPAD"); 4618 "MCP SCPAD");
4599 *global = true; 4619 /* clear latched SCPAD PATIRY from MCP */
4620 REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL,
4621 1UL << 10);
4600 break; 4622 break;
4601 } 4623 }
4602 4624
@@ -4605,45 +4627,50 @@ static int bnx2x_check_blocks_with_parity3(u32 sig, int par_num,
4605 } 4627 }
4606 } 4628 }
4607 4629
4608 return par_num; 4630 return res;
4609} 4631}
4610 4632
4611static int bnx2x_check_blocks_with_parity4(struct bnx2x *bp, u32 sig, 4633static bool bnx2x_check_blocks_with_parity4(struct bnx2x *bp, u32 sig,
4612 int par_num, bool print) 4634 int *par_num, bool print)
4613{ 4635{
4614 int i = 0; 4636 u32 cur_bit;
4615 u32 cur_bit = 0; 4637 bool res;
4638 int i;
4639
4640 res = false;
4641
4616 for (i = 0; sig; i++) { 4642 for (i = 0; sig; i++) {
4617 cur_bit = ((u32)0x1 << i); 4643 cur_bit = (0x1UL << i);
4618 if (sig & cur_bit) { 4644 if (sig & cur_bit) {
4619 switch (cur_bit) { 4645 res |= true; /* Each bit is real error! */
4620 case AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR: 4646 if (print) {
4621 if (print) { 4647 switch (cur_bit) {
4622 _print_next_block(par_num++, "PGLUE_B"); 4648 case AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR:
4649 _print_next_block((*par_num)++,
4650 "PGLUE_B");
4623 _print_parity(bp, 4651 _print_parity(bp,
4624 PGLUE_B_REG_PGLUE_B_PRTY_STS); 4652 PGLUE_B_REG_PGLUE_B_PRTY_STS);
4625 } 4653 break;
4626 break; 4654 case AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR:
4627 case AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR: 4655 _print_next_block((*par_num)++, "ATC");
4628 if (print) {
4629 _print_next_block(par_num++, "ATC");
4630 _print_parity(bp, 4656 _print_parity(bp,
4631 ATC_REG_ATC_PRTY_STS); 4657 ATC_REG_ATC_PRTY_STS);
4658 break;
4632 } 4659 }
4633 break;
4634 } 4660 }
4635
4636 /* Clear the bit */ 4661 /* Clear the bit */
4637 sig &= ~cur_bit; 4662 sig &= ~cur_bit;
4638 } 4663 }
4639 } 4664 }
4640 4665
4641 return par_num; 4666 return res;
4642} 4667}
4643 4668
4644static bool bnx2x_parity_attn(struct bnx2x *bp, bool *global, bool print, 4669static bool bnx2x_parity_attn(struct bnx2x *bp, bool *global, bool print,
4645 u32 *sig) 4670 u32 *sig)
4646{ 4671{
4672 bool res = false;
4673
4647 if ((sig[0] & HW_PRTY_ASSERT_SET_0) || 4674 if ((sig[0] & HW_PRTY_ASSERT_SET_0) ||
4648 (sig[1] & HW_PRTY_ASSERT_SET_1) || 4675 (sig[1] & HW_PRTY_ASSERT_SET_1) ||
4649 (sig[2] & HW_PRTY_ASSERT_SET_2) || 4676 (sig[2] & HW_PRTY_ASSERT_SET_2) ||
@@ -4660,23 +4687,22 @@ static bool bnx2x_parity_attn(struct bnx2x *bp, bool *global, bool print,
4660 if (print) 4687 if (print)
4661 netdev_err(bp->dev, 4688 netdev_err(bp->dev,
4662 "Parity errors detected in blocks: "); 4689 "Parity errors detected in blocks: ");
4663 par_num = bnx2x_check_blocks_with_parity0(bp, 4690 res |= bnx2x_check_blocks_with_parity0(bp,
4664 sig[0] & HW_PRTY_ASSERT_SET_0, par_num, print); 4691 sig[0] & HW_PRTY_ASSERT_SET_0, &par_num, print);
4665 par_num = bnx2x_check_blocks_with_parity1(bp, 4692 res |= bnx2x_check_blocks_with_parity1(bp,
4666 sig[1] & HW_PRTY_ASSERT_SET_1, par_num, global, print); 4693 sig[1] & HW_PRTY_ASSERT_SET_1, &par_num, global, print);
4667 par_num = bnx2x_check_blocks_with_parity2(bp, 4694 res |= bnx2x_check_blocks_with_parity2(bp,
4668 sig[2] & HW_PRTY_ASSERT_SET_2, par_num, print); 4695 sig[2] & HW_PRTY_ASSERT_SET_2, &par_num, print);
4669 par_num = bnx2x_check_blocks_with_parity3( 4696 res |= bnx2x_check_blocks_with_parity3(bp,
4670 sig[3] & HW_PRTY_ASSERT_SET_3, par_num, global, print); 4697 sig[3] & HW_PRTY_ASSERT_SET_3, &par_num, global, print);
4671 par_num = bnx2x_check_blocks_with_parity4(bp, 4698 res |= bnx2x_check_blocks_with_parity4(bp,
4672 sig[4] & HW_PRTY_ASSERT_SET_4, par_num, print); 4699 sig[4] & HW_PRTY_ASSERT_SET_4, &par_num, print);
4673 4700
4674 if (print) 4701 if (print)
4675 pr_cont("\n"); 4702 pr_cont("\n");
4703 }
4676 4704
4677 return true; 4705 return res;
4678 } else
4679 return false;
4680} 4706}
4681 4707
4682/** 4708/**
@@ -7126,7 +7152,7 @@ static int bnx2x_init_hw_port(struct bnx2x *bp)
7126 int port = BP_PORT(bp); 7152 int port = BP_PORT(bp);
7127 int init_phase = port ? PHASE_PORT1 : PHASE_PORT0; 7153 int init_phase = port ? PHASE_PORT1 : PHASE_PORT0;
7128 u32 low, high; 7154 u32 low, high;
7129 u32 val; 7155 u32 val, reg;
7130 7156
7131 DP(NETIF_MSG_HW, "starting port init port %d\n", port); 7157 DP(NETIF_MSG_HW, "starting port init port %d\n", port);
7132 7158
@@ -7271,6 +7297,17 @@ static int bnx2x_init_hw_port(struct bnx2x *bp)
7271 val |= CHIP_IS_E1(bp) ? 0 : 0x10; 7297 val |= CHIP_IS_E1(bp) ? 0 : 0x10;
7272 REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, val); 7298 REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, val);
7273 7299
7300 /* SCPAD_PARITY should NOT trigger close the gates */
7301 reg = port ? MISC_REG_AEU_ENABLE4_NIG_1 : MISC_REG_AEU_ENABLE4_NIG_0;
7302 REG_WR(bp, reg,
7303 REG_RD(bp, reg) &
7304 ~AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY);
7305
7306 reg = port ? MISC_REG_AEU_ENABLE4_PXP_1 : MISC_REG_AEU_ENABLE4_PXP_0;
7307 REG_WR(bp, reg,
7308 REG_RD(bp, reg) &
7309 ~AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY);
7310
7274 bnx2x_init_block(bp, BLOCK_NIG, init_phase); 7311 bnx2x_init_block(bp, BLOCK_NIG, init_phase);
7275 7312
7276 if (!CHIP_IS_E1x(bp)) { 7313 if (!CHIP_IS_E1x(bp)) {
@@ -11685,9 +11722,6 @@ static int bnx2x_init_bp(struct bnx2x *bp)
11685static int bnx2x_open(struct net_device *dev) 11722static int bnx2x_open(struct net_device *dev)
11686{ 11723{
11687 struct bnx2x *bp = netdev_priv(dev); 11724 struct bnx2x *bp = netdev_priv(dev);
11688 bool global = false;
11689 int other_engine = BP_PATH(bp) ? 0 : 1;
11690 bool other_load_status, load_status;
11691 int rc; 11725 int rc;
11692 11726
11693 bp->stats_init = true; 11727 bp->stats_init = true;
@@ -11703,6 +11737,10 @@ static int bnx2x_open(struct net_device *dev)
11703 * Parity recovery is only relevant for PF driver. 11737 * Parity recovery is only relevant for PF driver.
11704 */ 11738 */
11705 if (IS_PF(bp)) { 11739 if (IS_PF(bp)) {
11740 int other_engine = BP_PATH(bp) ? 0 : 1;
11741 bool other_load_status, load_status;
11742 bool global = false;
11743
11706 other_load_status = bnx2x_get_load_status(bp, other_engine); 11744 other_load_status = bnx2x_get_load_status(bp, other_engine);
11707 load_status = bnx2x_get_load_status(bp, BP_PATH(bp)); 11745 load_status = bnx2x_get_load_status(bp, BP_PATH(bp));
11708 if (!bnx2x_reset_is_done(bp, BP_PATH(bp)) || 11746 if (!bnx2x_reset_is_done(bp, BP_PATH(bp)) ||
@@ -12080,7 +12118,6 @@ static int bnx2x_set_coherency_mask(struct bnx2x *bp)
12080 struct device *dev = &bp->pdev->dev; 12118 struct device *dev = &bp->pdev->dev;
12081 12119
12082 if (dma_set_mask(dev, DMA_BIT_MASK(64)) == 0) { 12120 if (dma_set_mask(dev, DMA_BIT_MASK(64)) == 0) {
12083 bp->flags |= USING_DAC_FLAG;
12084 if (dma_set_coherent_mask(dev, DMA_BIT_MASK(64)) != 0) { 12121 if (dma_set_coherent_mask(dev, DMA_BIT_MASK(64)) != 0) {
12085 dev_err(dev, "dma_set_coherent_mask failed, aborting\n"); 12122 dev_err(dev, "dma_set_coherent_mask failed, aborting\n");
12086 return -EIO; 12123 return -EIO;
@@ -12248,8 +12285,7 @@ static int bnx2x_init_dev(struct bnx2x *bp, struct pci_dev *pdev,
12248 NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_HIGHDMA; 12285 NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_HIGHDMA;
12249 12286
12250 dev->features |= dev->hw_features | NETIF_F_HW_VLAN_CTAG_RX; 12287 dev->features |= dev->hw_features | NETIF_F_HW_VLAN_CTAG_RX;
12251 if (bp->flags & USING_DAC_FLAG) 12288 dev->features |= NETIF_F_HIGHDMA;
12252 dev->features |= NETIF_F_HIGHDMA;
12253 12289
12254 /* Add Loopback capability to the device */ 12290 /* Add Loopback capability to the device */
12255 dev->hw_features |= NETIF_F_LOOPBACK; 12291 dev->hw_features |= NETIF_F_LOOPBACK;
@@ -12612,24 +12648,24 @@ static int set_max_cos_est(int chip_id)
12612 return BNX2X_MULTI_TX_COS_E1X; 12648 return BNX2X_MULTI_TX_COS_E1X;
12613 case BCM57712: 12649 case BCM57712:
12614 case BCM57712_MF: 12650 case BCM57712_MF:
12615 case BCM57712_VF:
12616 return BNX2X_MULTI_TX_COS_E2_E3A0; 12651 return BNX2X_MULTI_TX_COS_E2_E3A0;
12617 case BCM57800: 12652 case BCM57800:
12618 case BCM57800_MF: 12653 case BCM57800_MF:
12619 case BCM57800_VF:
12620 case BCM57810: 12654 case BCM57810:
12621 case BCM57810_MF: 12655 case BCM57810_MF:
12622 case BCM57840_4_10: 12656 case BCM57840_4_10:
12623 case BCM57840_2_20: 12657 case BCM57840_2_20:
12624 case BCM57840_O: 12658 case BCM57840_O:
12625 case BCM57840_MFO: 12659 case BCM57840_MFO:
12626 case BCM57810_VF:
12627 case BCM57840_MF: 12660 case BCM57840_MF:
12628 case BCM57840_VF:
12629 case BCM57811: 12661 case BCM57811:
12630 case BCM57811_MF: 12662 case BCM57811_MF:
12631 case BCM57811_VF:
12632 return BNX2X_MULTI_TX_COS_E3B0; 12663 return BNX2X_MULTI_TX_COS_E3B0;
12664 case BCM57712_VF:
12665 case BCM57800_VF:
12666 case BCM57810_VF:
12667 case BCM57840_VF:
12668 case BCM57811_VF:
12633 return 1; 12669 return 1;
12634 default: 12670 default:
12635 pr_err("Unknown board_type (%d), aborting\n", chip_id); 12671 pr_err("Unknown board_type (%d), aborting\n", chip_id);
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sriov.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sriov.c
index 9ad012bdd915..5e07efb6ec13 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sriov.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sriov.c
@@ -470,10 +470,10 @@ static int bnx2x_vfop_qdtor_cmd(struct bnx2x *bp,
470 bnx2x_vfop_qdtor, cmd->done); 470 bnx2x_vfop_qdtor, cmd->done);
471 return bnx2x_vfop_transition(bp, vf, bnx2x_vfop_qdtor, 471 return bnx2x_vfop_transition(bp, vf, bnx2x_vfop_qdtor,
472 cmd->block); 472 cmd->block);
473 } else {
474 BNX2X_ERR("VF[%d] failed to add a vfop\n", vf->abs_vfid);
475 return -ENOMEM;
473 } 476 }
474 DP(BNX2X_MSG_IOV, "VF[%d] failed to add a vfop. rc %d\n",
475 vf->abs_vfid, vfop->rc);
476 return -ENOMEM;
477} 477}
478 478
479static void 479static void
@@ -2018,6 +2018,8 @@ failed:
2018 2018
2019void bnx2x_iov_remove_one(struct bnx2x *bp) 2019void bnx2x_iov_remove_one(struct bnx2x *bp)
2020{ 2020{
2021 int vf_idx;
2022
2021 /* if SRIOV is not enabled there's nothing to do */ 2023 /* if SRIOV is not enabled there's nothing to do */
2022 if (!IS_SRIOV(bp)) 2024 if (!IS_SRIOV(bp))
2023 return; 2025 return;
@@ -2026,6 +2028,18 @@ void bnx2x_iov_remove_one(struct bnx2x *bp)
2026 pci_disable_sriov(bp->pdev); 2028 pci_disable_sriov(bp->pdev);
2027 DP(BNX2X_MSG_IOV, "sriov disabled\n"); 2029 DP(BNX2X_MSG_IOV, "sriov disabled\n");
2028 2030
2031 /* disable access to all VFs */
2032 for (vf_idx = 0; vf_idx < bp->vfdb->sriov.total; vf_idx++) {
2033 bnx2x_pretend_func(bp,
2034 HW_VF_HANDLE(bp,
2035 bp->vfdb->sriov.first_vf_in_pf +
2036 vf_idx));
2037 DP(BNX2X_MSG_IOV, "disabling internal access for vf %d\n",
2038 bp->vfdb->sriov.first_vf_in_pf + vf_idx);
2039 bnx2x_vf_enable_internal(bp, 0);
2040 bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
2041 }
2042
2029 /* free vf database */ 2043 /* free vf database */
2030 __bnx2x_iov_free_vfdb(bp); 2044 __bnx2x_iov_free_vfdb(bp);
2031} 2045}
@@ -3197,7 +3211,7 @@ int bnx2x_enable_sriov(struct bnx2x *bp)
3197 * the "acquire" messages to appear on the VF PF channel. 3211 * the "acquire" messages to appear on the VF PF channel.
3198 */ 3212 */
3199 DP(BNX2X_MSG_IOV, "about to call enable sriov\n"); 3213 DP(BNX2X_MSG_IOV, "about to call enable sriov\n");
3200 pci_disable_sriov(bp->pdev); 3214 bnx2x_disable_sriov(bp);
3201 rc = pci_enable_sriov(bp->pdev, req_vfs); 3215 rc = pci_enable_sriov(bp->pdev, req_vfs);
3202 if (rc) { 3216 if (rc) {
3203 BNX2X_ERR("pci_enable_sriov failed with %d\n", rc); 3217 BNX2X_ERR("pci_enable_sriov failed with %d\n", rc);
@@ -3390,14 +3404,16 @@ int bnx2x_set_vf_mac(struct net_device *dev, int vfidx, u8 *mac)
3390 rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_ETH_MAC, true); 3404 rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_ETH_MAC, true);
3391 if (rc) { 3405 if (rc) {
3392 BNX2X_ERR("failed to delete eth macs\n"); 3406 BNX2X_ERR("failed to delete eth macs\n");
3393 return -EINVAL; 3407 rc = -EINVAL;
3408 goto out;
3394 } 3409 }
3395 3410
3396 /* remove existing uc list macs */ 3411 /* remove existing uc list macs */
3397 rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_UC_LIST_MAC, true); 3412 rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_UC_LIST_MAC, true);
3398 if (rc) { 3413 if (rc) {
3399 BNX2X_ERR("failed to delete uc_list macs\n"); 3414 BNX2X_ERR("failed to delete uc_list macs\n");
3400 return -EINVAL; 3415 rc = -EINVAL;
3416 goto out;
3401 } 3417 }
3402 3418
3403 /* configure the new mac to device */ 3419 /* configure the new mac to device */
@@ -3405,6 +3421,7 @@ int bnx2x_set_vf_mac(struct net_device *dev, int vfidx, u8 *mac)
3405 bnx2x_set_mac_one(bp, (u8 *)&bulletin->mac, mac_obj, true, 3421 bnx2x_set_mac_one(bp, (u8 *)&bulletin->mac, mac_obj, true,
3406 BNX2X_ETH_MAC, &ramrod_flags); 3422 BNX2X_ETH_MAC, &ramrod_flags);
3407 3423
3424out:
3408 bnx2x_unlock_vf_pf_channel(bp, vf, CHANNEL_TLV_PF_SET_MAC); 3425 bnx2x_unlock_vf_pf_channel(bp, vf, CHANNEL_TLV_PF_SET_MAC);
3409 } 3426 }
3410 3427
@@ -3467,7 +3484,8 @@ int bnx2x_set_vf_vlan(struct net_device *dev, int vfidx, u16 vlan, u8 qos)
3467 &ramrod_flags); 3484 &ramrod_flags);
3468 if (rc) { 3485 if (rc) {
3469 BNX2X_ERR("failed to delete vlans\n"); 3486 BNX2X_ERR("failed to delete vlans\n");
3470 return -EINVAL; 3487 rc = -EINVAL;
3488 goto out;
3471 } 3489 }
3472 3490
3473 /* send queue update ramrod to configure default vlan and silent 3491 /* send queue update ramrod to configure default vlan and silent
@@ -3501,7 +3519,8 @@ int bnx2x_set_vf_vlan(struct net_device *dev, int vfidx, u16 vlan, u8 qos)
3501 rc = bnx2x_config_vlan_mac(bp, &ramrod_param); 3519 rc = bnx2x_config_vlan_mac(bp, &ramrod_param);
3502 if (rc) { 3520 if (rc) {
3503 BNX2X_ERR("failed to configure vlan\n"); 3521 BNX2X_ERR("failed to configure vlan\n");
3504 return -EINVAL; 3522 rc = -EINVAL;
3523 goto out;
3505 } 3524 }
3506 3525
3507 /* configure default vlan to vf queue and set silent 3526 /* configure default vlan to vf queue and set silent
@@ -3519,18 +3538,18 @@ int bnx2x_set_vf_vlan(struct net_device *dev, int vfidx, u16 vlan, u8 qos)
3519 rc = bnx2x_queue_state_change(bp, &q_params); 3538 rc = bnx2x_queue_state_change(bp, &q_params);
3520 if (rc) { 3539 if (rc) {
3521 BNX2X_ERR("Failed to configure default VLAN\n"); 3540 BNX2X_ERR("Failed to configure default VLAN\n");
3522 return rc; 3541 goto out;
3523 } 3542 }
3524 3543
3525 /* clear the flag indicating that this VF needs its vlan 3544 /* clear the flag indicating that this VF needs its vlan
3526 * (will only be set if the HV configured th Vlan before vf was 3545 * (will only be set if the HV configured the Vlan before vf was
3527 * and we were called because the VF came up later 3546 * up and we were called because the VF came up later
3528 */ 3547 */
3548out:
3529 vf->cfg_flags &= ~VF_CFG_VLAN; 3549 vf->cfg_flags &= ~VF_CFG_VLAN;
3530
3531 bnx2x_unlock_vf_pf_channel(bp, vf, CHANNEL_TLV_PF_SET_VLAN); 3550 bnx2x_unlock_vf_pf_channel(bp, vf, CHANNEL_TLV_PF_SET_VLAN);
3532 } 3551 }
3533 return 0; 3552 return rc;
3534} 3553}
3535 3554
3536/* crc is the first field in the bulletin board. Compute the crc over the 3555/* crc is the first field in the bulletin board. Compute the crc over the
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_stats.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_stats.c
index 86436c77af03..3b75070411aa 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_stats.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_stats.c
@@ -196,7 +196,7 @@ static void bnx2x_hw_stats_post(struct bnx2x *bp)
196 196
197 } else if (bp->func_stx) { 197 } else if (bp->func_stx) {
198 *stats_comp = 0; 198 *stats_comp = 0;
199 bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp)); 199 bnx2x_issue_dmae_with_comp(bp, dmae, stats_comp);
200 } 200 }
201} 201}
202 202
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_vfpf.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_vfpf.c
index da16953eb2ec..28757dfacf0d 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_vfpf.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_vfpf.c
@@ -980,7 +980,7 @@ static int bnx2x_copy32_vf_dmae(struct bnx2x *bp, u8 from_vf,
980 dmae.len = len32; 980 dmae.len = len32;
981 981
982 /* issue the command and wait for completion */ 982 /* issue the command and wait for completion */
983 return bnx2x_issue_dmae_with_comp(bp, &dmae); 983 return bnx2x_issue_dmae_with_comp(bp, &dmae, bnx2x_sp(bp, wb_comp));
984} 984}
985 985
986static void bnx2x_vf_mbx_resp(struct bnx2x *bp, struct bnx2x_virtf *vf) 986static void bnx2x_vf_mbx_resp(struct bnx2x *bp, struct bnx2x_virtf *vf)
diff --git a/drivers/net/ethernet/calxeda/xgmac.c b/drivers/net/ethernet/calxeda/xgmac.c
index 78d6d6b970e1..48f52882a22b 100644
--- a/drivers/net/ethernet/calxeda/xgmac.c
+++ b/drivers/net/ethernet/calxeda/xgmac.c
@@ -106,7 +106,6 @@
106#define XGMAC_DMA_HW_FEATURE 0x00000f58 /* Enabled Hardware Features */ 106#define XGMAC_DMA_HW_FEATURE 0x00000f58 /* Enabled Hardware Features */
107 107
108#define XGMAC_ADDR_AE 0x80000000 108#define XGMAC_ADDR_AE 0x80000000
109#define XGMAC_MAX_FILTER_ADDR 31
110 109
111/* PMT Control and Status */ 110/* PMT Control and Status */
112#define XGMAC_PMT_POINTER_RESET 0x80000000 111#define XGMAC_PMT_POINTER_RESET 0x80000000
@@ -384,6 +383,7 @@ struct xgmac_priv {
384 struct device *device; 383 struct device *device;
385 struct napi_struct napi; 384 struct napi_struct napi;
386 385
386 int max_macs;
387 struct xgmac_extra_stats xstats; 387 struct xgmac_extra_stats xstats;
388 388
389 spinlock_t stats_lock; 389 spinlock_t stats_lock;
@@ -1291,14 +1291,12 @@ static void xgmac_set_rx_mode(struct net_device *dev)
1291 netdev_dbg(priv->dev, "# mcasts %d, # unicast %d\n", 1291 netdev_dbg(priv->dev, "# mcasts %d, # unicast %d\n",
1292 netdev_mc_count(dev), netdev_uc_count(dev)); 1292 netdev_mc_count(dev), netdev_uc_count(dev));
1293 1293
1294 if (dev->flags & IFF_PROMISC) { 1294 if (dev->flags & IFF_PROMISC)
1295 writel(XGMAC_FRAME_FILTER_PR, ioaddr + XGMAC_FRAME_FILTER); 1295 value |= XGMAC_FRAME_FILTER_PR;
1296 return;
1297 }
1298 1296
1299 memset(hash_filter, 0, sizeof(hash_filter)); 1297 memset(hash_filter, 0, sizeof(hash_filter));
1300 1298
1301 if (netdev_uc_count(dev) > XGMAC_MAX_FILTER_ADDR) { 1299 if (netdev_uc_count(dev) > priv->max_macs) {
1302 use_hash = true; 1300 use_hash = true;
1303 value |= XGMAC_FRAME_FILTER_HUC | XGMAC_FRAME_FILTER_HPF; 1301 value |= XGMAC_FRAME_FILTER_HUC | XGMAC_FRAME_FILTER_HPF;
1304 } 1302 }
@@ -1321,7 +1319,7 @@ static void xgmac_set_rx_mode(struct net_device *dev)
1321 goto out; 1319 goto out;
1322 } 1320 }
1323 1321
1324 if ((netdev_mc_count(dev) + reg - 1) > XGMAC_MAX_FILTER_ADDR) { 1322 if ((netdev_mc_count(dev) + reg - 1) > priv->max_macs) {
1325 use_hash = true; 1323 use_hash = true;
1326 value |= XGMAC_FRAME_FILTER_HMC | XGMAC_FRAME_FILTER_HPF; 1324 value |= XGMAC_FRAME_FILTER_HMC | XGMAC_FRAME_FILTER_HPF;
1327 } else { 1325 } else {
@@ -1342,8 +1340,8 @@ static void xgmac_set_rx_mode(struct net_device *dev)
1342 } 1340 }
1343 1341
1344out: 1342out:
1345 for (i = reg; i < XGMAC_MAX_FILTER_ADDR; i++) 1343 for (i = reg; i <= priv->max_macs; i++)
1346 xgmac_set_mac_addr(ioaddr, NULL, reg); 1344 xgmac_set_mac_addr(ioaddr, NULL, i);
1347 for (i = 0; i < XGMAC_NUM_HASH; i++) 1345 for (i = 0; i < XGMAC_NUM_HASH; i++)
1348 writel(hash_filter[i], ioaddr + XGMAC_HASH(i)); 1346 writel(hash_filter[i], ioaddr + XGMAC_HASH(i));
1349 1347
@@ -1761,6 +1759,13 @@ static int xgmac_probe(struct platform_device *pdev)
1761 uid = readl(priv->base + XGMAC_VERSION); 1759 uid = readl(priv->base + XGMAC_VERSION);
1762 netdev_info(ndev, "h/w version is 0x%x\n", uid); 1760 netdev_info(ndev, "h/w version is 0x%x\n", uid);
1763 1761
1762 /* Figure out how many valid mac address filter registers we have */
1763 writel(1, priv->base + XGMAC_ADDR_HIGH(31));
1764 if (readl(priv->base + XGMAC_ADDR_HIGH(31)) == 1)
1765 priv->max_macs = 31;
1766 else
1767 priv->max_macs = 7;
1768
1764 writel(0, priv->base + XGMAC_DMA_INTR_ENA); 1769 writel(0, priv->base + XGMAC_DMA_INTR_ENA);
1765 ndev->irq = platform_get_irq(pdev, 0); 1770 ndev->irq = platform_get_irq(pdev, 0);
1766 if (ndev->irq == -ENXIO) { 1771 if (ndev->irq == -ENXIO) {
diff --git a/drivers/net/ethernet/chelsio/cxgb3/sge.c b/drivers/net/ethernet/chelsio/cxgb3/sge.c
index 9c89dc8fe105..632b318eb38a 100644
--- a/drivers/net/ethernet/chelsio/cxgb3/sge.c
+++ b/drivers/net/ethernet/chelsio/cxgb3/sge.c
@@ -1599,7 +1599,8 @@ static void write_ofld_wr(struct adapter *adap, struct sk_buff *skb,
1599 flits = skb_transport_offset(skb) / 8; 1599 flits = skb_transport_offset(skb) / 8;
1600 sgp = ndesc == 1 ? (struct sg_ent *)&d->flit[flits] : sgl; 1600 sgp = ndesc == 1 ? (struct sg_ent *)&d->flit[flits] : sgl;
1601 sgl_flits = make_sgl(skb, sgp, skb_transport_header(skb), 1601 sgl_flits = make_sgl(skb, sgp, skb_transport_header(skb),
1602 skb->tail - skb->transport_header, 1602 skb_tail_pointer(skb) -
1603 skb_transport_header(skb),
1603 adap->pdev); 1604 adap->pdev);
1604 if (need_skb_unmap()) { 1605 if (need_skb_unmap()) {
1605 setup_deferred_unmapping(skb, adap->pdev, sgp, sgl_flits); 1606 setup_deferred_unmapping(skb, adap->pdev, sgp, sgl_flits);
diff --git a/drivers/net/ethernet/davicom/dm9000.c b/drivers/net/ethernet/davicom/dm9000.c
index 5f5896e522d2..a7a941b1a655 100644
--- a/drivers/net/ethernet/davicom/dm9000.c
+++ b/drivers/net/ethernet/davicom/dm9000.c
@@ -158,18 +158,6 @@ static inline board_info_t *to_dm9000_board(struct net_device *dev)
158 158
159/* DM9000 network board routine ---------------------------- */ 159/* DM9000 network board routine ---------------------------- */
160 160
161static void
162dm9000_reset(board_info_t * db)
163{
164 dev_dbg(db->dev, "resetting device\n");
165
166 /* RESET device */
167 writeb(DM9000_NCR, db->io_addr);
168 udelay(200);
169 writeb(NCR_RST, db->io_data);
170 udelay(200);
171}
172
173/* 161/*
174 * Read a byte from I/O port 162 * Read a byte from I/O port
175 */ 163 */
@@ -191,6 +179,27 @@ iow(board_info_t * db, int reg, int value)
191 writeb(value, db->io_data); 179 writeb(value, db->io_data);
192} 180}
193 181
182static void
183dm9000_reset(board_info_t *db)
184{
185 dev_dbg(db->dev, "resetting device\n");
186
187 /* Reset DM9000, see DM9000 Application Notes V1.22 Jun 11, 2004 page 29
188 * The essential point is that we have to do a double reset, and the
189 * instruction is to set LBK into MAC internal loopback mode.
190 */
191 iow(db, DM9000_NCR, 0x03);
192 udelay(100); /* Application note says at least 20 us */
193 if (ior(db, DM9000_NCR) & 1)
194 dev_err(db->dev, "dm9000 did not respond to first reset\n");
195
196 iow(db, DM9000_NCR, 0);
197 iow(db, DM9000_NCR, 0x03);
198 udelay(100);
199 if (ior(db, DM9000_NCR) & 1)
200 dev_err(db->dev, "dm9000 did not respond to second reset\n");
201}
202
194/* routines for sending block to chip */ 203/* routines for sending block to chip */
195 204
196static void dm9000_outblk_8bit(void __iomem *reg, void *data, int count) 205static void dm9000_outblk_8bit(void __iomem *reg, void *data, int count)
@@ -744,15 +753,20 @@ static const struct ethtool_ops dm9000_ethtool_ops = {
744static void dm9000_show_carrier(board_info_t *db, 753static void dm9000_show_carrier(board_info_t *db,
745 unsigned carrier, unsigned nsr) 754 unsigned carrier, unsigned nsr)
746{ 755{
756 int lpa;
747 struct net_device *ndev = db->ndev; 757 struct net_device *ndev = db->ndev;
758 struct mii_if_info *mii = &db->mii;
748 unsigned ncr = dm9000_read_locked(db, DM9000_NCR); 759 unsigned ncr = dm9000_read_locked(db, DM9000_NCR);
749 760
750 if (carrier) 761 if (carrier) {
751 dev_info(db->dev, "%s: link up, %dMbps, %s-duplex, no LPA\n", 762 lpa = mii->mdio_read(mii->dev, mii->phy_id, MII_LPA);
763 dev_info(db->dev,
764 "%s: link up, %dMbps, %s-duplex, lpa 0x%04X\n",
752 ndev->name, (nsr & NSR_SPEED) ? 10 : 100, 765 ndev->name, (nsr & NSR_SPEED) ? 10 : 100,
753 (ncr & NCR_FDX) ? "full" : "half"); 766 (ncr & NCR_FDX) ? "full" : "half", lpa);
754 else 767 } else {
755 dev_info(db->dev, "%s: link down\n", ndev->name); 768 dev_info(db->dev, "%s: link down\n", ndev->name);
769 }
756} 770}
757 771
758static void 772static void
@@ -890,9 +904,15 @@ dm9000_init_dm9000(struct net_device *dev)
890 (dev->features & NETIF_F_RXCSUM) ? RCSR_CSUM : 0); 904 (dev->features & NETIF_F_RXCSUM) ? RCSR_CSUM : 0);
891 905
892 iow(db, DM9000_GPCR, GPCR_GEP_CNTL); /* Let GPIO0 output */ 906 iow(db, DM9000_GPCR, GPCR_GEP_CNTL); /* Let GPIO0 output */
907 iow(db, DM9000_GPR, 0);
893 908
894 dm9000_phy_write(dev, 0, MII_BMCR, BMCR_RESET); /* PHY RESET */ 909 /* If we are dealing with DM9000B, some extra steps are required: a
895 dm9000_phy_write(dev, 0, MII_DM_DSPCR, DSPCR_INIT_PARAM); /* Init */ 910 * manual phy reset, and setting init params.
911 */
912 if (db->type == TYPE_DM9000B) {
913 dm9000_phy_write(dev, 0, MII_BMCR, BMCR_RESET);
914 dm9000_phy_write(dev, 0, MII_DM_DSPCR, DSPCR_INIT_PARAM);
915 }
896 916
897 ncr = (db->flags & DM9000_PLATF_EXT_PHY) ? NCR_EXT_PHY : 0; 917 ncr = (db->flags & DM9000_PLATF_EXT_PHY) ? NCR_EXT_PHY : 0;
898 918
diff --git a/drivers/net/ethernet/emulex/benet/be.h b/drivers/net/ethernet/emulex/benet/be.h
index db020230bd0b..c99dac6a9ddf 100644
--- a/drivers/net/ethernet/emulex/benet/be.h
+++ b/drivers/net/ethernet/emulex/benet/be.h
@@ -696,6 +696,15 @@ static inline int qnq_async_evt_rcvd(struct be_adapter *adapter)
696 return adapter->flags & BE_FLAGS_QNQ_ASYNC_EVT_RCVD; 696 return adapter->flags & BE_FLAGS_QNQ_ASYNC_EVT_RCVD;
697} 697}
698 698
699static inline int fw_major_num(const char *fw_ver)
700{
701 int fw_major = 0;
702
703 sscanf(fw_ver, "%d.", &fw_major);
704
705 return fw_major;
706}
707
699extern void be_cq_notify(struct be_adapter *adapter, u16 qid, bool arm, 708extern void be_cq_notify(struct be_adapter *adapter, u16 qid, bool arm,
700 u16 num_popped); 709 u16 num_popped);
701extern void be_link_status_update(struct be_adapter *adapter, u8 link_status); 710extern void be_link_status_update(struct be_adapter *adapter, u8 link_status);
diff --git a/drivers/net/ethernet/emulex/benet/be_cmds.c b/drivers/net/ethernet/emulex/benet/be_cmds.c
index bd0e0c0bbcd8..c08fd32bb8e5 100644
--- a/drivers/net/ethernet/emulex/benet/be_cmds.c
+++ b/drivers/net/ethernet/emulex/benet/be_cmds.c
@@ -1198,7 +1198,6 @@ int be_cmd_txq_create(struct be_adapter *adapter, struct be_tx_obj *txo)
1198 1198
1199 if (lancer_chip(adapter)) { 1199 if (lancer_chip(adapter)) {
1200 req->hdr.version = 1; 1200 req->hdr.version = 1;
1201 req->if_id = cpu_to_le16(adapter->if_handle);
1202 } else if (BEx_chip(adapter)) { 1201 } else if (BEx_chip(adapter)) {
1203 if (adapter->function_caps & BE_FUNCTION_CAPS_SUPER_NIC) 1202 if (adapter->function_caps & BE_FUNCTION_CAPS_SUPER_NIC)
1204 req->hdr.version = 2; 1203 req->hdr.version = 2;
@@ -1206,6 +1205,8 @@ int be_cmd_txq_create(struct be_adapter *adapter, struct be_tx_obj *txo)
1206 req->hdr.version = 2; 1205 req->hdr.version = 2;
1207 } 1206 }
1208 1207
1208 if (req->hdr.version > 0)
1209 req->if_id = cpu_to_le16(adapter->if_handle);
1209 req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size); 1210 req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
1210 req->ulp_num = BE_ULP1_NUM; 1211 req->ulp_num = BE_ULP1_NUM;
1211 req->type = BE_ETH_TX_RING_TYPE_STANDARD; 1212 req->type = BE_ETH_TX_RING_TYPE_STANDARD;
diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
index 2c38cc402119..53ed58b492c8 100644
--- a/drivers/net/ethernet/emulex/benet/be_main.c
+++ b/drivers/net/ethernet/emulex/benet/be_main.c
@@ -3247,6 +3247,12 @@ static int be_setup(struct be_adapter *adapter)
3247 3247
3248 be_cmd_get_fw_ver(adapter, adapter->fw_ver, adapter->fw_on_flash); 3248 be_cmd_get_fw_ver(adapter, adapter->fw_ver, adapter->fw_on_flash);
3249 3249
3250 if (BE2_chip(adapter) && fw_major_num(adapter->fw_ver) < 4) {
3251 dev_err(dev, "Firmware on card is old(%s), IRQs may not work.",
3252 adapter->fw_ver);
3253 dev_err(dev, "Please upgrade firmware to version >= 4.0\n");
3254 }
3255
3250 if (adapter->vlans_added) 3256 if (adapter->vlans_added)
3251 be_vid_config(adapter); 3257 be_vid_config(adapter);
3252 3258
diff --git a/drivers/net/ethernet/freescale/gianfar.c b/drivers/net/ethernet/freescale/gianfar.c
index c4eaadeb572f..9fbe4dda7a0e 100644
--- a/drivers/net/ethernet/freescale/gianfar.c
+++ b/drivers/net/ethernet/freescale/gianfar.c
@@ -88,6 +88,7 @@
88 88
89#include <asm/io.h> 89#include <asm/io.h>
90#include <asm/reg.h> 90#include <asm/reg.h>
91#include <asm/mpc85xx.h>
91#include <asm/irq.h> 92#include <asm/irq.h>
92#include <asm/uaccess.h> 93#include <asm/uaccess.h>
93#include <linux/module.h> 94#include <linux/module.h>
@@ -939,9 +940,8 @@ static void gfar_init_filer_table(struct gfar_private *priv)
939 } 940 }
940} 941}
941 942
942static void gfar_detect_errata(struct gfar_private *priv) 943static void __gfar_detect_errata_83xx(struct gfar_private *priv)
943{ 944{
944 struct device *dev = &priv->ofdev->dev;
945 unsigned int pvr = mfspr(SPRN_PVR); 945 unsigned int pvr = mfspr(SPRN_PVR);
946 unsigned int svr = mfspr(SPRN_SVR); 946 unsigned int svr = mfspr(SPRN_SVR);
947 unsigned int mod = (svr >> 16) & 0xfff6; /* w/o E suffix */ 947 unsigned int mod = (svr >> 16) & 0xfff6; /* w/o E suffix */
@@ -957,15 +957,33 @@ static void gfar_detect_errata(struct gfar_private *priv)
957 (pvr == 0x80861010 && (mod & 0xfff9) == 0x80c0)) 957 (pvr == 0x80861010 && (mod & 0xfff9) == 0x80c0))
958 priv->errata |= GFAR_ERRATA_76; 958 priv->errata |= GFAR_ERRATA_76;
959 959
960 /* MPC8313 and MPC837x all rev */ 960 /* MPC8313 Rev < 2.0 */
961 if ((pvr == 0x80850010 && mod == 0x80b0) || 961 if (pvr == 0x80850010 && mod == 0x80b0 && rev < 0x0020)
962 (pvr == 0x80861010 && (mod & 0xfff9) == 0x80c0)) 962 priv->errata |= GFAR_ERRATA_12;
963 priv->errata |= GFAR_ERRATA_A002; 963}
964 964
965 /* MPC8313 Rev < 2.0, MPC8548 rev 2.0 */ 965static void __gfar_detect_errata_85xx(struct gfar_private *priv)
966 if ((pvr == 0x80850010 && mod == 0x80b0 && rev < 0x0020) || 966{
967 (pvr == 0x80210020 && mod == 0x8030 && rev == 0x0020)) 967 unsigned int svr = mfspr(SPRN_SVR);
968
969 if ((SVR_SOC_VER(svr) == SVR_8548) && (SVR_REV(svr) == 0x20))
968 priv->errata |= GFAR_ERRATA_12; 970 priv->errata |= GFAR_ERRATA_12;
971 if (((SVR_SOC_VER(svr) == SVR_P2020) && (SVR_REV(svr) < 0x20)) ||
972 ((SVR_SOC_VER(svr) == SVR_P2010) && (SVR_REV(svr) < 0x20)))
973 priv->errata |= GFAR_ERRATA_76; /* aka eTSEC 20 */
974}
975
976static void gfar_detect_errata(struct gfar_private *priv)
977{
978 struct device *dev = &priv->ofdev->dev;
979
980 /* no plans to fix */
981 priv->errata |= GFAR_ERRATA_A002;
982
983 if (pvr_version_is(PVR_VER_E500V1) || pvr_version_is(PVR_VER_E500V2))
984 __gfar_detect_errata_85xx(priv);
985 else /* non-mpc85xx parts, i.e. e300 core based */
986 __gfar_detect_errata_83xx(priv);
969 987
970 if (priv->errata) 988 if (priv->errata)
971 dev_info(dev, "enabled errata workarounds, flags: 0x%x\n", 989 dev_info(dev, "enabled errata workarounds, flags: 0x%x\n",
@@ -1599,7 +1617,7 @@ static int __gfar_is_rx_idle(struct gfar_private *priv)
1599 /* Normaly TSEC should not hang on GRS commands, so we should 1617 /* Normaly TSEC should not hang on GRS commands, so we should
1600 * actually wait for IEVENT_GRSC flag. 1618 * actually wait for IEVENT_GRSC flag.
1601 */ 1619 */
1602 if (likely(!gfar_has_errata(priv, GFAR_ERRATA_A002))) 1620 if (!gfar_has_errata(priv, GFAR_ERRATA_A002))
1603 return 0; 1621 return 0;
1604 1622
1605 /* Read the eTSEC register at offset 0xD1C. If bits 7-14 are 1623 /* Read the eTSEC register at offset 0xD1C. If bits 7-14 are
diff --git a/drivers/net/ethernet/ibm/emac/mal.c b/drivers/net/ethernet/ibm/emac/mal.c
index dac564c25440..e7847510eda2 100644
--- a/drivers/net/ethernet/ibm/emac/mal.c
+++ b/drivers/net/ethernet/ibm/emac/mal.c
@@ -263,7 +263,9 @@ static inline void mal_schedule_poll(struct mal_instance *mal)
263{ 263{
264 if (likely(napi_schedule_prep(&mal->napi))) { 264 if (likely(napi_schedule_prep(&mal->napi))) {
265 MAL_DBG2(mal, "schedule_poll" NL); 265 MAL_DBG2(mal, "schedule_poll" NL);
266 spin_lock(&mal->lock);
266 mal_disable_eob_irq(mal); 267 mal_disable_eob_irq(mal);
268 spin_unlock(&mal->lock);
267 __napi_schedule(&mal->napi); 269 __napi_schedule(&mal->napi);
268 } else 270 } else
269 MAL_DBG2(mal, "already in poll" NL); 271 MAL_DBG2(mal, "already in poll" NL);
@@ -442,15 +444,13 @@ static int mal_poll(struct napi_struct *napi, int budget)
442 if (unlikely(mc->ops->peek_rx(mc->dev) || 444 if (unlikely(mc->ops->peek_rx(mc->dev) ||
443 test_bit(MAL_COMMAC_RX_STOPPED, &mc->flags))) { 445 test_bit(MAL_COMMAC_RX_STOPPED, &mc->flags))) {
444 MAL_DBG2(mal, "rotting packet" NL); 446 MAL_DBG2(mal, "rotting packet" NL);
445 if (napi_reschedule(napi)) 447 if (!napi_reschedule(napi))
446 mal_disable_eob_irq(mal);
447 else
448 MAL_DBG2(mal, "already in poll list" NL);
449
450 if (budget > 0)
451 goto again;
452 else
453 goto more_work; 448 goto more_work;
449
450 spin_lock_irqsave(&mal->lock, flags);
451 mal_disable_eob_irq(mal);
452 spin_unlock_irqrestore(&mal->lock, flags);
453 goto again;
454 } 454 }
455 mc->ops->poll_tx(mc->dev); 455 mc->ops->poll_tx(mc->dev);
456 } 456 }
diff --git a/drivers/net/ethernet/intel/igb/igb_ethtool.c b/drivers/net/ethernet/intel/igb/igb_ethtool.c
index 86d51429a189..151e00cad113 100644
--- a/drivers/net/ethernet/intel/igb/igb_ethtool.c
+++ b/drivers/net/ethernet/intel/igb/igb_ethtool.c
@@ -2655,6 +2655,8 @@ static int igb_set_eee(struct net_device *netdev,
2655 (hw->phy.media_type != e1000_media_type_copper)) 2655 (hw->phy.media_type != e1000_media_type_copper))
2656 return -EOPNOTSUPP; 2656 return -EOPNOTSUPP;
2657 2657
2658 memset(&eee_curr, 0, sizeof(struct ethtool_eee));
2659
2658 ret_val = igb_get_eee(netdev, &eee_curr); 2660 ret_val = igb_get_eee(netdev, &eee_curr);
2659 if (ret_val) 2661 if (ret_val)
2660 return ret_val; 2662 return ret_val;
diff --git a/drivers/net/ethernet/marvell/mv643xx_eth.c b/drivers/net/ethernet/marvell/mv643xx_eth.c
index 7fb5677451f9..2c210ec35d59 100644
--- a/drivers/net/ethernet/marvell/mv643xx_eth.c
+++ b/drivers/net/ethernet/marvell/mv643xx_eth.c
@@ -1131,15 +1131,13 @@ static void mib_counters_update(struct mv643xx_eth_private *mp)
1131 p->rx_discard += rdlp(mp, RX_DISCARD_FRAME_CNT); 1131 p->rx_discard += rdlp(mp, RX_DISCARD_FRAME_CNT);
1132 p->rx_overrun += rdlp(mp, RX_OVERRUN_FRAME_CNT); 1132 p->rx_overrun += rdlp(mp, RX_OVERRUN_FRAME_CNT);
1133 spin_unlock_bh(&mp->mib_counters_lock); 1133 spin_unlock_bh(&mp->mib_counters_lock);
1134
1135 mod_timer(&mp->mib_counters_timer, jiffies + 30 * HZ);
1136} 1134}
1137 1135
1138static void mib_counters_timer_wrapper(unsigned long _mp) 1136static void mib_counters_timer_wrapper(unsigned long _mp)
1139{ 1137{
1140 struct mv643xx_eth_private *mp = (void *)_mp; 1138 struct mv643xx_eth_private *mp = (void *)_mp;
1141
1142 mib_counters_update(mp); 1139 mib_counters_update(mp);
1140 mod_timer(&mp->mib_counters_timer, jiffies + 30 * HZ);
1143} 1141}
1144 1142
1145 1143
@@ -2237,6 +2235,7 @@ static int mv643xx_eth_open(struct net_device *dev)
2237 mp->int_mask |= INT_TX_END_0 << i; 2235 mp->int_mask |= INT_TX_END_0 << i;
2238 } 2236 }
2239 2237
2238 add_timer(&mp->mib_counters_timer);
2240 port_start(mp); 2239 port_start(mp);
2241 2240
2242 wrlp(mp, INT_MASK_EXT, INT_EXT_LINK_PHY | INT_EXT_TX); 2241 wrlp(mp, INT_MASK_EXT, INT_EXT_LINK_PHY | INT_EXT_TX);
@@ -2534,6 +2533,7 @@ static int mv643xx_eth_shared_of_add_port(struct platform_device *pdev,
2534 if (!ppdev) 2533 if (!ppdev)
2535 return -ENOMEM; 2534 return -ENOMEM;
2536 ppdev->dev.coherent_dma_mask = DMA_BIT_MASK(32); 2535 ppdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
2536 ppdev->dev.of_node = pnp;
2537 2537
2538 ret = platform_device_add_resources(ppdev, &res, 1); 2538 ret = platform_device_add_resources(ppdev, &res, 1);
2539 if (ret) 2539 if (ret)
@@ -2916,7 +2916,6 @@ static int mv643xx_eth_probe(struct platform_device *pdev)
2916 mp->mib_counters_timer.data = (unsigned long)mp; 2916 mp->mib_counters_timer.data = (unsigned long)mp;
2917 mp->mib_counters_timer.function = mib_counters_timer_wrapper; 2917 mp->mib_counters_timer.function = mib_counters_timer_wrapper;
2918 mp->mib_counters_timer.expires = jiffies + 30 * HZ; 2918 mp->mib_counters_timer.expires = jiffies + 30 * HZ;
2919 add_timer(&mp->mib_counters_timer);
2920 2919
2921 spin_lock_init(&mp->mib_counters_lock); 2920 spin_lock_init(&mp->mib_counters_lock);
2922 2921
diff --git a/drivers/net/ethernet/mellanox/mlx4/cmd.c b/drivers/net/ethernet/mellanox/mlx4/cmd.c
index ea20182c6969..bb11624a1f39 100644
--- a/drivers/net/ethernet/mellanox/mlx4/cmd.c
+++ b/drivers/net/ethernet/mellanox/mlx4/cmd.c
@@ -1691,7 +1691,7 @@ static void mlx4_master_deactivate_admin_state(struct mlx4_priv *priv, int slave
1691 vp_oper->vlan_idx = NO_INDX; 1691 vp_oper->vlan_idx = NO_INDX;
1692 } 1692 }
1693 if (NO_INDX != vp_oper->mac_idx) { 1693 if (NO_INDX != vp_oper->mac_idx) {
1694 __mlx4_unregister_mac(&priv->dev, port, vp_oper->mac_idx); 1694 __mlx4_unregister_mac(&priv->dev, port, vp_oper->state.mac);
1695 vp_oper->mac_idx = NO_INDX; 1695 vp_oper->mac_idx = NO_INDX;
1696 } 1696 }
1697 } 1697 }
diff --git a/drivers/net/ethernet/mellanox/mlx4/en_rx.c b/drivers/net/ethernet/mellanox/mlx4/en_rx.c
index dec455c8f627..afe2efa69c86 100644
--- a/drivers/net/ethernet/mellanox/mlx4/en_rx.c
+++ b/drivers/net/ethernet/mellanox/mlx4/en_rx.c
@@ -70,14 +70,15 @@ static int mlx4_alloc_pages(struct mlx4_en_priv *priv,
70 put_page(page); 70 put_page(page);
71 return -ENOMEM; 71 return -ENOMEM;
72 } 72 }
73 page_alloc->size = PAGE_SIZE << order; 73 page_alloc->page_size = PAGE_SIZE << order;
74 page_alloc->page = page; 74 page_alloc->page = page;
75 page_alloc->dma = dma; 75 page_alloc->dma = dma;
76 page_alloc->offset = frag_info->frag_align; 76 page_alloc->page_offset = frag_info->frag_align;
77 /* Not doing get_page() for each frag is a big win 77 /* Not doing get_page() for each frag is a big win
78 * on asymetric workloads. 78 * on asymetric workloads.
79 */ 79 */
80 atomic_set(&page->_count, page_alloc->size / frag_info->frag_stride); 80 atomic_set(&page->_count,
81 page_alloc->page_size / frag_info->frag_stride);
81 return 0; 82 return 0;
82} 83}
83 84
@@ -96,16 +97,19 @@ static int mlx4_en_alloc_frags(struct mlx4_en_priv *priv,
96 for (i = 0; i < priv->num_frags; i++) { 97 for (i = 0; i < priv->num_frags; i++) {
97 frag_info = &priv->frag_info[i]; 98 frag_info = &priv->frag_info[i];
98 page_alloc[i] = ring_alloc[i]; 99 page_alloc[i] = ring_alloc[i];
99 page_alloc[i].offset += frag_info->frag_stride; 100 page_alloc[i].page_offset += frag_info->frag_stride;
100 if (page_alloc[i].offset + frag_info->frag_stride <= ring_alloc[i].size) 101
102 if (page_alloc[i].page_offset + frag_info->frag_stride <=
103 ring_alloc[i].page_size)
101 continue; 104 continue;
105
102 if (mlx4_alloc_pages(priv, &page_alloc[i], frag_info, gfp)) 106 if (mlx4_alloc_pages(priv, &page_alloc[i], frag_info, gfp))
103 goto out; 107 goto out;
104 } 108 }
105 109
106 for (i = 0; i < priv->num_frags; i++) { 110 for (i = 0; i < priv->num_frags; i++) {
107 frags[i] = ring_alloc[i]; 111 frags[i] = ring_alloc[i];
108 dma = ring_alloc[i].dma + ring_alloc[i].offset; 112 dma = ring_alloc[i].dma + ring_alloc[i].page_offset;
109 ring_alloc[i] = page_alloc[i]; 113 ring_alloc[i] = page_alloc[i];
110 rx_desc->data[i].addr = cpu_to_be64(dma); 114 rx_desc->data[i].addr = cpu_to_be64(dma);
111 } 115 }
@@ -117,7 +121,7 @@ out:
117 frag_info = &priv->frag_info[i]; 121 frag_info = &priv->frag_info[i];
118 if (page_alloc[i].page != ring_alloc[i].page) { 122 if (page_alloc[i].page != ring_alloc[i].page) {
119 dma_unmap_page(priv->ddev, page_alloc[i].dma, 123 dma_unmap_page(priv->ddev, page_alloc[i].dma,
120 page_alloc[i].size, PCI_DMA_FROMDEVICE); 124 page_alloc[i].page_size, PCI_DMA_FROMDEVICE);
121 page = page_alloc[i].page; 125 page = page_alloc[i].page;
122 atomic_set(&page->_count, 1); 126 atomic_set(&page->_count, 1);
123 put_page(page); 127 put_page(page);
@@ -131,10 +135,12 @@ static void mlx4_en_free_frag(struct mlx4_en_priv *priv,
131 int i) 135 int i)
132{ 136{
133 const struct mlx4_en_frag_info *frag_info = &priv->frag_info[i]; 137 const struct mlx4_en_frag_info *frag_info = &priv->frag_info[i];
138 u32 next_frag_end = frags[i].page_offset + 2 * frag_info->frag_stride;
139
134 140
135 if (frags[i].offset + frag_info->frag_stride > frags[i].size) 141 if (next_frag_end > frags[i].page_size)
136 dma_unmap_page(priv->ddev, frags[i].dma, frags[i].size, 142 dma_unmap_page(priv->ddev, frags[i].dma, frags[i].page_size,
137 PCI_DMA_FROMDEVICE); 143 PCI_DMA_FROMDEVICE);
138 144
139 if (frags[i].page) 145 if (frags[i].page)
140 put_page(frags[i].page); 146 put_page(frags[i].page);
@@ -161,7 +167,7 @@ out:
161 167
162 page_alloc = &ring->page_alloc[i]; 168 page_alloc = &ring->page_alloc[i];
163 dma_unmap_page(priv->ddev, page_alloc->dma, 169 dma_unmap_page(priv->ddev, page_alloc->dma,
164 page_alloc->size, PCI_DMA_FROMDEVICE); 170 page_alloc->page_size, PCI_DMA_FROMDEVICE);
165 page = page_alloc->page; 171 page = page_alloc->page;
166 atomic_set(&page->_count, 1); 172 atomic_set(&page->_count, 1);
167 put_page(page); 173 put_page(page);
@@ -184,10 +190,11 @@ static void mlx4_en_destroy_allocator(struct mlx4_en_priv *priv,
184 i, page_count(page_alloc->page)); 190 i, page_count(page_alloc->page));
185 191
186 dma_unmap_page(priv->ddev, page_alloc->dma, 192 dma_unmap_page(priv->ddev, page_alloc->dma,
187 page_alloc->size, PCI_DMA_FROMDEVICE); 193 page_alloc->page_size, PCI_DMA_FROMDEVICE);
188 while (page_alloc->offset + frag_info->frag_stride < page_alloc->size) { 194 while (page_alloc->page_offset + frag_info->frag_stride <
195 page_alloc->page_size) {
189 put_page(page_alloc->page); 196 put_page(page_alloc->page);
190 page_alloc->offset += frag_info->frag_stride; 197 page_alloc->page_offset += frag_info->frag_stride;
191 } 198 }
192 page_alloc->page = NULL; 199 page_alloc->page = NULL;
193 } 200 }
@@ -478,7 +485,7 @@ static int mlx4_en_complete_rx_desc(struct mlx4_en_priv *priv,
478 /* Save page reference in skb */ 485 /* Save page reference in skb */
479 __skb_frag_set_page(&skb_frags_rx[nr], frags[nr].page); 486 __skb_frag_set_page(&skb_frags_rx[nr], frags[nr].page);
480 skb_frag_size_set(&skb_frags_rx[nr], frag_info->frag_size); 487 skb_frag_size_set(&skb_frags_rx[nr], frag_info->frag_size);
481 skb_frags_rx[nr].page_offset = frags[nr].offset; 488 skb_frags_rx[nr].page_offset = frags[nr].page_offset;
482 skb->truesize += frag_info->frag_stride; 489 skb->truesize += frag_info->frag_stride;
483 frags[nr].page = NULL; 490 frags[nr].page = NULL;
484 } 491 }
@@ -517,7 +524,7 @@ static struct sk_buff *mlx4_en_rx_skb(struct mlx4_en_priv *priv,
517 524
518 /* Get pointer to first fragment so we could copy the headers into the 525 /* Get pointer to first fragment so we could copy the headers into the
519 * (linear part of the) skb */ 526 * (linear part of the) skb */
520 va = page_address(frags[0].page) + frags[0].offset; 527 va = page_address(frags[0].page) + frags[0].page_offset;
521 528
522 if (length <= SMALL_PACKET_SIZE) { 529 if (length <= SMALL_PACKET_SIZE) {
523 /* We are copying all relevant data to the skb - temporarily 530 /* We are copying all relevant data to the skb - temporarily
@@ -645,7 +652,7 @@ int mlx4_en_process_rx_cq(struct net_device *dev, struct mlx4_en_cq *cq, int bud
645 dma_sync_single_for_cpu(priv->ddev, dma, sizeof(*ethh), 652 dma_sync_single_for_cpu(priv->ddev, dma, sizeof(*ethh),
646 DMA_FROM_DEVICE); 653 DMA_FROM_DEVICE);
647 ethh = (struct ethhdr *)(page_address(frags[0].page) + 654 ethh = (struct ethhdr *)(page_address(frags[0].page) +
648 frags[0].offset); 655 frags[0].page_offset);
649 656
650 if (is_multicast_ether_addr(ethh->h_dest)) { 657 if (is_multicast_ether_addr(ethh->h_dest)) {
651 struct mlx4_mac_entry *entry; 658 struct mlx4_mac_entry *entry;
diff --git a/drivers/net/ethernet/mellanox/mlx4/mlx4_en.h b/drivers/net/ethernet/mellanox/mlx4/mlx4_en.h
index 5e0aa569306a..bf06e3610d27 100644
--- a/drivers/net/ethernet/mellanox/mlx4/mlx4_en.h
+++ b/drivers/net/ethernet/mellanox/mlx4/mlx4_en.h
@@ -237,8 +237,8 @@ struct mlx4_en_tx_desc {
237struct mlx4_en_rx_alloc { 237struct mlx4_en_rx_alloc {
238 struct page *page; 238 struct page *page;
239 dma_addr_t dma; 239 dma_addr_t dma;
240 u32 offset; 240 u32 page_offset;
241 u32 size; 241 u32 page_size;
242}; 242};
243 243
244struct mlx4_en_tx_ring { 244struct mlx4_en_tx_ring {
diff --git a/drivers/net/ethernet/moxa/moxart_ether.c b/drivers/net/ethernet/moxa/moxart_ether.c
index bd1a2d2bc2ae..ea54d95e5b9f 100644
--- a/drivers/net/ethernet/moxa/moxart_ether.c
+++ b/drivers/net/ethernet/moxa/moxart_ether.c
@@ -448,7 +448,8 @@ static int moxart_mac_probe(struct platform_device *pdev)
448 irq = irq_of_parse_and_map(node, 0); 448 irq = irq_of_parse_and_map(node, 0);
449 if (irq <= 0) { 449 if (irq <= 0) {
450 netdev_err(ndev, "irq_of_parse_and_map failed\n"); 450 netdev_err(ndev, "irq_of_parse_and_map failed\n");
451 return -EINVAL; 451 ret = -EINVAL;
452 goto irq_map_fail;
452 } 453 }
453 454
454 priv = netdev_priv(ndev); 455 priv = netdev_priv(ndev);
@@ -472,24 +473,32 @@ static int moxart_mac_probe(struct platform_device *pdev)
472 priv->tx_desc_base = dma_alloc_coherent(NULL, TX_REG_DESC_SIZE * 473 priv->tx_desc_base = dma_alloc_coherent(NULL, TX_REG_DESC_SIZE *
473 TX_DESC_NUM, &priv->tx_base, 474 TX_DESC_NUM, &priv->tx_base,
474 GFP_DMA | GFP_KERNEL); 475 GFP_DMA | GFP_KERNEL);
475 if (priv->tx_desc_base == NULL) 476 if (priv->tx_desc_base == NULL) {
477 ret = -ENOMEM;
476 goto init_fail; 478 goto init_fail;
479 }
477 480
478 priv->rx_desc_base = dma_alloc_coherent(NULL, RX_REG_DESC_SIZE * 481 priv->rx_desc_base = dma_alloc_coherent(NULL, RX_REG_DESC_SIZE *
479 RX_DESC_NUM, &priv->rx_base, 482 RX_DESC_NUM, &priv->rx_base,
480 GFP_DMA | GFP_KERNEL); 483 GFP_DMA | GFP_KERNEL);
481 if (priv->rx_desc_base == NULL) 484 if (priv->rx_desc_base == NULL) {
485 ret = -ENOMEM;
482 goto init_fail; 486 goto init_fail;
487 }
483 488
484 priv->tx_buf_base = kmalloc(priv->tx_buf_size * TX_DESC_NUM, 489 priv->tx_buf_base = kmalloc(priv->tx_buf_size * TX_DESC_NUM,
485 GFP_ATOMIC); 490 GFP_ATOMIC);
486 if (!priv->tx_buf_base) 491 if (!priv->tx_buf_base) {
492 ret = -ENOMEM;
487 goto init_fail; 493 goto init_fail;
494 }
488 495
489 priv->rx_buf_base = kmalloc(priv->rx_buf_size * RX_DESC_NUM, 496 priv->rx_buf_base = kmalloc(priv->rx_buf_size * RX_DESC_NUM,
490 GFP_ATOMIC); 497 GFP_ATOMIC);
491 if (!priv->rx_buf_base) 498 if (!priv->rx_buf_base) {
499 ret = -ENOMEM;
492 goto init_fail; 500 goto init_fail;
501 }
493 502
494 platform_set_drvdata(pdev, ndev); 503 platform_set_drvdata(pdev, ndev);
495 504
@@ -522,7 +531,8 @@ static int moxart_mac_probe(struct platform_device *pdev)
522init_fail: 531init_fail:
523 netdev_err(ndev, "init failed\n"); 532 netdev_err(ndev, "init failed\n");
524 moxart_mac_free_memory(ndev); 533 moxart_mac_free_memory(ndev);
525 534irq_map_fail:
535 free_netdev(ndev);
526 return ret; 536 return ret;
527} 537}
528 538
diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_hw.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_hw.c
index 3ca00e05f23d..ace217c447dd 100644
--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_hw.c
+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_hw.c
@@ -2276,9 +2276,9 @@ int qlcnic_83xx_get_nic_info(struct qlcnic_adapter *adapter,
2276 temp = (cmd.rsp.arg[8] & 0x7FFE0000) >> 17; 2276 temp = (cmd.rsp.arg[8] & 0x7FFE0000) >> 17;
2277 npar_info->max_linkspeed_reg_offset = temp; 2277 npar_info->max_linkspeed_reg_offset = temp;
2278 } 2278 }
2279 if (npar_info->capabilities & QLCNIC_FW_CAPABILITY_MORE_CAPS) 2279
2280 memcpy(ahw->extra_capability, &cmd.rsp.arg[16], 2280 memcpy(ahw->extra_capability, &cmd.rsp.arg[16],
2281 sizeof(ahw->extra_capability)); 2281 sizeof(ahw->extra_capability));
2282 2282
2283out: 2283out:
2284 qlcnic_free_mbx_args(&cmd); 2284 qlcnic_free_mbx_args(&cmd);
diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ethtool.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ethtool.c
index ebe4c86e5230..ff83a9fcd4c5 100644
--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ethtool.c
+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ethtool.c
@@ -665,7 +665,7 @@ static int qlcnic_set_channels(struct net_device *dev,
665 return err; 665 return err;
666 } 666 }
667 667
668 if (channel->tx_count) { 668 if (qlcnic_82xx_check(adapter) && channel->tx_count) {
669 err = qlcnic_validate_max_tx_rings(adapter, channel->tx_count); 669 err = qlcnic_validate_max_tx_rings(adapter, channel->tx_count);
670 if (err) 670 if (err)
671 return err; 671 return err;
diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_hw.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_hw.c
index f8adc7b01f1f..b64e2bef9428 100644
--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_hw.c
+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_hw.c
@@ -785,8 +785,6 @@ void qlcnic_82xx_config_intr_coalesce(struct qlcnic_adapter *adapter)
785 785
786#define QLCNIC_ENABLE_IPV4_LRO 1 786#define QLCNIC_ENABLE_IPV4_LRO 1
787#define QLCNIC_ENABLE_IPV6_LRO 2 787#define QLCNIC_ENABLE_IPV6_LRO 2
788#define QLCNIC_NO_DEST_IPV4_CHECK (1 << 8)
789#define QLCNIC_NO_DEST_IPV6_CHECK (2 << 8)
790 788
791int qlcnic_82xx_config_hw_lro(struct qlcnic_adapter *adapter, int enable) 789int qlcnic_82xx_config_hw_lro(struct qlcnic_adapter *adapter, int enable)
792{ 790{
@@ -806,11 +804,10 @@ int qlcnic_82xx_config_hw_lro(struct qlcnic_adapter *adapter, int enable)
806 804
807 word = 0; 805 word = 0;
808 if (enable) { 806 if (enable) {
809 word = QLCNIC_ENABLE_IPV4_LRO | QLCNIC_NO_DEST_IPV4_CHECK; 807 word = QLCNIC_ENABLE_IPV4_LRO;
810 if (adapter->ahw->extra_capability[0] & 808 if (adapter->ahw->extra_capability[0] &
811 QLCNIC_FW_CAP2_HW_LRO_IPV6) 809 QLCNIC_FW_CAP2_HW_LRO_IPV6)
812 word |= QLCNIC_ENABLE_IPV6_LRO | 810 word |= QLCNIC_ENABLE_IPV6_LRO;
813 QLCNIC_NO_DEST_IPV6_CHECK;
814 } 811 }
815 812
816 req.words[0] = cpu_to_le64(word); 813 req.words[0] = cpu_to_le64(word);
diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c
index 21d00a0449a1..d8f4897e9e82 100644
--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c
+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c
@@ -1131,7 +1131,10 @@ qlcnic_initialize_nic(struct qlcnic_adapter *adapter)
1131 if (err == -EIO) 1131 if (err == -EIO)
1132 return err; 1132 return err;
1133 adapter->ahw->extra_capability[0] = temp; 1133 adapter->ahw->extra_capability[0] = temp;
1134 } else {
1135 adapter->ahw->extra_capability[0] = 0;
1134 } 1136 }
1137
1135 adapter->ahw->max_mac_filters = nic_info.max_mac_filters; 1138 adapter->ahw->max_mac_filters = nic_info.max_mac_filters;
1136 adapter->ahw->max_mtu = nic_info.max_mtu; 1139 adapter->ahw->max_mtu = nic_info.max_mtu;
1137 1140
@@ -2159,8 +2162,7 @@ void qlcnic_set_drv_version(struct qlcnic_adapter *adapter)
2159 else if (qlcnic_83xx_check(adapter)) 2162 else if (qlcnic_83xx_check(adapter))
2160 fw_cmd = QLCNIC_CMD_83XX_SET_DRV_VER; 2163 fw_cmd = QLCNIC_CMD_83XX_SET_DRV_VER;
2161 2164
2162 if ((ahw->capabilities & QLCNIC_FW_CAPABILITY_MORE_CAPS) && 2165 if (ahw->extra_capability[0] & QLCNIC_FW_CAPABILITY_SET_DRV_VER)
2163 (ahw->extra_capability[0] & QLCNIC_FW_CAPABILITY_SET_DRV_VER))
2164 qlcnic_fw_cmd_set_drv_version(adapter, fw_cmd); 2166 qlcnic_fw_cmd_set_drv_version(adapter, fw_cmd);
2165} 2167}
2166 2168
@@ -2257,7 +2259,7 @@ qlcnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
2257 2259
2258 err = qlcnic_alloc_adapter_resources(adapter); 2260 err = qlcnic_alloc_adapter_resources(adapter);
2259 if (err) 2261 if (err)
2260 goto err_out_free_netdev; 2262 goto err_out_free_wq;
2261 2263
2262 adapter->dev_rst_time = jiffies; 2264 adapter->dev_rst_time = jiffies;
2263 adapter->ahw->revision_id = pdev->revision; 2265 adapter->ahw->revision_id = pdev->revision;
@@ -2396,6 +2398,9 @@ err_out_disable_msi:
2396err_out_free_hw: 2398err_out_free_hw:
2397 qlcnic_free_adapter_resources(adapter); 2399 qlcnic_free_adapter_resources(adapter);
2398 2400
2401err_out_free_wq:
2402 destroy_workqueue(adapter->qlcnic_wq);
2403
2399err_out_free_netdev: 2404err_out_free_netdev:
2400 free_netdev(netdev); 2405 free_netdev(netdev);
2401 2406
@@ -3648,11 +3653,6 @@ int qlcnic_validate_max_tx_rings(struct qlcnic_adapter *adapter, u32 txq)
3648 u8 max_hw = QLCNIC_MAX_TX_RINGS; 3653 u8 max_hw = QLCNIC_MAX_TX_RINGS;
3649 u32 max_allowed; 3654 u32 max_allowed;
3650 3655
3651 if (!qlcnic_82xx_check(adapter)) {
3652 netdev_err(netdev, "No Multi TX-Q support\n");
3653 return -EINVAL;
3654 }
3655
3656 if (!qlcnic_use_msi_x && !qlcnic_use_msi) { 3656 if (!qlcnic_use_msi_x && !qlcnic_use_msi) {
3657 netdev_err(netdev, "No Multi TX-Q support in INT-x mode\n"); 3657 netdev_err(netdev, "No Multi TX-Q support in INT-x mode\n");
3658 return -EINVAL; 3658 return -EINVAL;
@@ -3692,8 +3692,7 @@ int qlcnic_validate_max_rss(struct qlcnic_adapter *adapter,
3692 u8 max_hw = adapter->ahw->max_rx_ques; 3692 u8 max_hw = adapter->ahw->max_rx_ques;
3693 u32 max_allowed; 3693 u32 max_allowed;
3694 3694
3695 if (qlcnic_82xx_check(adapter) && !qlcnic_use_msi_x && 3695 if (!qlcnic_use_msi_x && !qlcnic_use_msi) {
3696 !qlcnic_use_msi) {
3697 netdev_err(netdev, "No RSS support in INT-x mode\n"); 3696 netdev_err(netdev, "No RSS support in INT-x mode\n");
3698 return -EINVAL; 3697 return -EINVAL;
3699 } 3698 }
diff --git a/drivers/net/ethernet/renesas/sh_eth.c b/drivers/net/ethernet/renesas/sh_eth.c
index 5cd831ebfa83..b57c278d3b46 100644
--- a/drivers/net/ethernet/renesas/sh_eth.c
+++ b/drivers/net/ethernet/renesas/sh_eth.c
@@ -688,12 +688,16 @@ static struct sh_eth_cpu_data r8a7740_data = {
688 .eesr_err_check = EESR_TWB1 | EESR_TWB | EESR_TABT | EESR_RABT | 688 .eesr_err_check = EESR_TWB1 | EESR_TWB | EESR_TABT | EESR_RABT |
689 EESR_RFE | EESR_RDE | EESR_RFRMER | EESR_TFE | 689 EESR_RFE | EESR_RDE | EESR_RFRMER | EESR_TFE |
690 EESR_TDE | EESR_ECI, 690 EESR_TDE | EESR_ECI,
691 .fdr_value = 0x0000070f,
692 .rmcr_value = 0x00000001,
691 693
692 .apr = 1, 694 .apr = 1,
693 .mpr = 1, 695 .mpr = 1,
694 .tpauser = 1, 696 .tpauser = 1,
695 .bculr = 1, 697 .bculr = 1,
696 .hw_swap = 1, 698 .hw_swap = 1,
699 .rpadir = 1,
700 .rpadir_value = 2 << 16,
697 .no_trimd = 1, 701 .no_trimd = 1,
698 .no_ade = 1, 702 .no_ade = 1,
699 .tsu = 1, 703 .tsu = 1,
diff --git a/drivers/net/ethernet/sfc/ef10.c b/drivers/net/ethernet/sfc/ef10.c
index 9f18ae984f9e..21f9ad6392e9 100644
--- a/drivers/net/ethernet/sfc/ef10.c
+++ b/drivers/net/ethernet/sfc/ef10.c
@@ -444,6 +444,18 @@ static const struct efx_hw_stat_desc efx_ef10_stat_desc[EF10_STAT_COUNT] = {
444 EF10_DMA_STAT(rx_align_error, RX_ALIGN_ERROR_PKTS), 444 EF10_DMA_STAT(rx_align_error, RX_ALIGN_ERROR_PKTS),
445 EF10_DMA_STAT(rx_length_error, RX_LENGTH_ERROR_PKTS), 445 EF10_DMA_STAT(rx_length_error, RX_LENGTH_ERROR_PKTS),
446 EF10_DMA_STAT(rx_nodesc_drops, RX_NODESC_DROPS), 446 EF10_DMA_STAT(rx_nodesc_drops, RX_NODESC_DROPS),
447 EF10_DMA_STAT(rx_pm_trunc_bb_overflow, PM_TRUNC_BB_OVERFLOW),
448 EF10_DMA_STAT(rx_pm_discard_bb_overflow, PM_DISCARD_BB_OVERFLOW),
449 EF10_DMA_STAT(rx_pm_trunc_vfifo_full, PM_TRUNC_VFIFO_FULL),
450 EF10_DMA_STAT(rx_pm_discard_vfifo_full, PM_DISCARD_VFIFO_FULL),
451 EF10_DMA_STAT(rx_pm_trunc_qbb, PM_TRUNC_QBB),
452 EF10_DMA_STAT(rx_pm_discard_qbb, PM_DISCARD_QBB),
453 EF10_DMA_STAT(rx_pm_discard_mapping, PM_DISCARD_MAPPING),
454 EF10_DMA_STAT(rx_dp_q_disabled_packets, RXDP_Q_DISABLED_PKTS),
455 EF10_DMA_STAT(rx_dp_di_dropped_packets, RXDP_DI_DROPPED_PKTS),
456 EF10_DMA_STAT(rx_dp_streaming_packets, RXDP_STREAMING_PKTS),
457 EF10_DMA_STAT(rx_dp_emerg_fetch, RXDP_EMERGENCY_FETCH_CONDITIONS),
458 EF10_DMA_STAT(rx_dp_emerg_wait, RXDP_EMERGENCY_WAIT_CONDITIONS),
447}; 459};
448 460
449#define HUNT_COMMON_STAT_MASK ((1ULL << EF10_STAT_tx_bytes) | \ 461#define HUNT_COMMON_STAT_MASK ((1ULL << EF10_STAT_tx_bytes) | \
@@ -498,44 +510,72 @@ static const struct efx_hw_stat_desc efx_ef10_stat_desc[EF10_STAT_COUNT] = {
498#define HUNT_40G_EXTRA_STAT_MASK ((1ULL << EF10_STAT_rx_align_error) | \ 510#define HUNT_40G_EXTRA_STAT_MASK ((1ULL << EF10_STAT_rx_align_error) | \
499 (1ULL << EF10_STAT_rx_length_error)) 511 (1ULL << EF10_STAT_rx_length_error))
500 512
501#if BITS_PER_LONG == 64 513/* These statistics are only provided if the firmware supports the
502#define STAT_MASK_BITMAP(bits) (bits) 514 * capability PM_AND_RXDP_COUNTERS.
503#else 515 */
504#define STAT_MASK_BITMAP(bits) (bits) & 0xffffffff, (bits) >> 32 516#define HUNT_PM_AND_RXDP_STAT_MASK ( \
505#endif 517 (1ULL << EF10_STAT_rx_pm_trunc_bb_overflow) | \
506 518 (1ULL << EF10_STAT_rx_pm_discard_bb_overflow) | \
507static const unsigned long *efx_ef10_stat_mask(struct efx_nic *efx) 519 (1ULL << EF10_STAT_rx_pm_trunc_vfifo_full) | \
508{ 520 (1ULL << EF10_STAT_rx_pm_discard_vfifo_full) | \
509 static const unsigned long hunt_40g_stat_mask[] = { 521 (1ULL << EF10_STAT_rx_pm_trunc_qbb) | \
510 STAT_MASK_BITMAP(HUNT_COMMON_STAT_MASK | 522 (1ULL << EF10_STAT_rx_pm_discard_qbb) | \
511 HUNT_40G_EXTRA_STAT_MASK) 523 (1ULL << EF10_STAT_rx_pm_discard_mapping) | \
512 }; 524 (1ULL << EF10_STAT_rx_dp_q_disabled_packets) | \
513 static const unsigned long hunt_10g_only_stat_mask[] = { 525 (1ULL << EF10_STAT_rx_dp_di_dropped_packets) | \
514 STAT_MASK_BITMAP(HUNT_COMMON_STAT_MASK | 526 (1ULL << EF10_STAT_rx_dp_streaming_packets) | \
515 HUNT_10G_ONLY_STAT_MASK) 527 (1ULL << EF10_STAT_rx_dp_emerg_fetch) | \
516 }; 528 (1ULL << EF10_STAT_rx_dp_emerg_wait))
529
530static u64 efx_ef10_raw_stat_mask(struct efx_nic *efx)
531{
532 u64 raw_mask = HUNT_COMMON_STAT_MASK;
517 u32 port_caps = efx_mcdi_phy_get_caps(efx); 533 u32 port_caps = efx_mcdi_phy_get_caps(efx);
534 struct efx_ef10_nic_data *nic_data = efx->nic_data;
518 535
519 if (port_caps & (1 << MC_CMD_PHY_CAP_40000FDX_LBN)) 536 if (port_caps & (1 << MC_CMD_PHY_CAP_40000FDX_LBN))
520 return hunt_40g_stat_mask; 537 raw_mask |= HUNT_40G_EXTRA_STAT_MASK;
521 else 538 else
522 return hunt_10g_only_stat_mask; 539 raw_mask |= HUNT_10G_ONLY_STAT_MASK;
540
541 if (nic_data->datapath_caps &
542 (1 << MC_CMD_GET_CAPABILITIES_OUT_PM_AND_RXDP_COUNTERS_LBN))
543 raw_mask |= HUNT_PM_AND_RXDP_STAT_MASK;
544
545 return raw_mask;
546}
547
548static void efx_ef10_get_stat_mask(struct efx_nic *efx, unsigned long *mask)
549{
550 u64 raw_mask = efx_ef10_raw_stat_mask(efx);
551
552#if BITS_PER_LONG == 64
553 mask[0] = raw_mask;
554#else
555 mask[0] = raw_mask & 0xffffffff;
556 mask[1] = raw_mask >> 32;
557#endif
523} 558}
524 559
525static size_t efx_ef10_describe_stats(struct efx_nic *efx, u8 *names) 560static size_t efx_ef10_describe_stats(struct efx_nic *efx, u8 *names)
526{ 561{
562 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
563
564 efx_ef10_get_stat_mask(efx, mask);
527 return efx_nic_describe_stats(efx_ef10_stat_desc, EF10_STAT_COUNT, 565 return efx_nic_describe_stats(efx_ef10_stat_desc, EF10_STAT_COUNT,
528 efx_ef10_stat_mask(efx), names); 566 mask, names);
529} 567}
530 568
531static int efx_ef10_try_update_nic_stats(struct efx_nic *efx) 569static int efx_ef10_try_update_nic_stats(struct efx_nic *efx)
532{ 570{
533 struct efx_ef10_nic_data *nic_data = efx->nic_data; 571 struct efx_ef10_nic_data *nic_data = efx->nic_data;
534 const unsigned long *stats_mask = efx_ef10_stat_mask(efx); 572 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
535 __le64 generation_start, generation_end; 573 __le64 generation_start, generation_end;
536 u64 *stats = nic_data->stats; 574 u64 *stats = nic_data->stats;
537 __le64 *dma_stats; 575 __le64 *dma_stats;
538 576
577 efx_ef10_get_stat_mask(efx, mask);
578
539 dma_stats = efx->stats_buffer.addr; 579 dma_stats = efx->stats_buffer.addr;
540 nic_data = efx->nic_data; 580 nic_data = efx->nic_data;
541 581
@@ -543,8 +583,9 @@ static int efx_ef10_try_update_nic_stats(struct efx_nic *efx)
543 if (generation_end == EFX_MC_STATS_GENERATION_INVALID) 583 if (generation_end == EFX_MC_STATS_GENERATION_INVALID)
544 return 0; 584 return 0;
545 rmb(); 585 rmb();
546 efx_nic_update_stats(efx_ef10_stat_desc, EF10_STAT_COUNT, stats_mask, 586 efx_nic_update_stats(efx_ef10_stat_desc, EF10_STAT_COUNT, mask,
547 stats, efx->stats_buffer.addr, false); 587 stats, efx->stats_buffer.addr, false);
588 rmb();
548 generation_start = dma_stats[MC_CMD_MAC_GENERATION_START]; 589 generation_start = dma_stats[MC_CMD_MAC_GENERATION_START];
549 if (generation_end != generation_start) 590 if (generation_end != generation_start)
550 return -EAGAIN; 591 return -EAGAIN;
@@ -563,12 +604,14 @@ static int efx_ef10_try_update_nic_stats(struct efx_nic *efx)
563static size_t efx_ef10_update_stats(struct efx_nic *efx, u64 *full_stats, 604static size_t efx_ef10_update_stats(struct efx_nic *efx, u64 *full_stats,
564 struct rtnl_link_stats64 *core_stats) 605 struct rtnl_link_stats64 *core_stats)
565{ 606{
566 const unsigned long *mask = efx_ef10_stat_mask(efx); 607 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
567 struct efx_ef10_nic_data *nic_data = efx->nic_data; 608 struct efx_ef10_nic_data *nic_data = efx->nic_data;
568 u64 *stats = nic_data->stats; 609 u64 *stats = nic_data->stats;
569 size_t stats_count = 0, index; 610 size_t stats_count = 0, index;
570 int retry; 611 int retry;
571 612
613 efx_ef10_get_stat_mask(efx, mask);
614
572 /* If we're unlucky enough to read statistics during the DMA, wait 615 /* If we're unlucky enough to read statistics during the DMA, wait
573 * up to 10ms for it to finish (typically takes <500us) 616 * up to 10ms for it to finish (typically takes <500us)
574 */ 617 */
diff --git a/drivers/net/ethernet/sfc/mcdi.c b/drivers/net/ethernet/sfc/mcdi.c
index c082562dbf4e..366c8e3e3784 100644
--- a/drivers/net/ethernet/sfc/mcdi.c
+++ b/drivers/net/ethernet/sfc/mcdi.c
@@ -963,7 +963,7 @@ static int efx_mcdi_drv_attach(struct efx_nic *efx, bool driver_operating,
963 bool *was_attached) 963 bool *was_attached)
964{ 964{
965 MCDI_DECLARE_BUF(inbuf, MC_CMD_DRV_ATTACH_IN_LEN); 965 MCDI_DECLARE_BUF(inbuf, MC_CMD_DRV_ATTACH_IN_LEN);
966 MCDI_DECLARE_BUF(outbuf, MC_CMD_DRV_ATTACH_OUT_LEN); 966 MCDI_DECLARE_BUF(outbuf, MC_CMD_DRV_ATTACH_EXT_OUT_LEN);
967 size_t outlen; 967 size_t outlen;
968 int rc; 968 int rc;
969 969
@@ -981,6 +981,22 @@ static int efx_mcdi_drv_attach(struct efx_nic *efx, bool driver_operating,
981 goto fail; 981 goto fail;
982 } 982 }
983 983
984 /* We currently assume we have control of the external link
985 * and are completely trusted by firmware. Abort probing
986 * if that's not true for this function.
987 */
988 if (driver_operating &&
989 outlen >= MC_CMD_DRV_ATTACH_EXT_OUT_LEN &&
990 (MCDI_DWORD(outbuf, DRV_ATTACH_EXT_OUT_FUNC_FLAGS) &
991 (1 << MC_CMD_DRV_ATTACH_EXT_OUT_FLAG_LINKCTRL |
992 1 << MC_CMD_DRV_ATTACH_EXT_OUT_FLAG_TRUSTED)) !=
993 (1 << MC_CMD_DRV_ATTACH_EXT_OUT_FLAG_LINKCTRL |
994 1 << MC_CMD_DRV_ATTACH_EXT_OUT_FLAG_TRUSTED)) {
995 netif_err(efx, probe, efx->net_dev,
996 "This driver version only supports one function per port\n");
997 return -ENODEV;
998 }
999
984 if (was_attached != NULL) 1000 if (was_attached != NULL)
985 *was_attached = MCDI_DWORD(outbuf, DRV_ATTACH_OUT_OLD_STATE); 1001 *was_attached = MCDI_DWORD(outbuf, DRV_ATTACH_OUT_OLD_STATE);
986 return 0; 1002 return 0;
diff --git a/drivers/net/ethernet/sfc/mcdi_pcol.h b/drivers/net/ethernet/sfc/mcdi_pcol.h
index b5cf62492f8e..e0a63ddb7a6c 100644
--- a/drivers/net/ethernet/sfc/mcdi_pcol.h
+++ b/drivers/net/ethernet/sfc/mcdi_pcol.h
@@ -2574,8 +2574,58 @@
2574#define MC_CMD_MAC_RX_LANES01_DISP_ERR 0x39 /* enum */ 2574#define MC_CMD_MAC_RX_LANES01_DISP_ERR 0x39 /* enum */
2575#define MC_CMD_MAC_RX_LANES23_DISP_ERR 0x3a /* enum */ 2575#define MC_CMD_MAC_RX_LANES23_DISP_ERR 0x3a /* enum */
2576#define MC_CMD_MAC_RX_MATCH_FAULT 0x3b /* enum */ 2576#define MC_CMD_MAC_RX_MATCH_FAULT 0x3b /* enum */
2577#define MC_CMD_GMAC_DMABUF_START 0x40 /* enum */ 2577/* enum: PM trunc_bb_overflow counter. Valid for EF10 with PM_AND_RXDP_COUNTERS
2578#define MC_CMD_GMAC_DMABUF_END 0x5f /* enum */ 2578 * capability only.
2579 */
2580#define MC_CMD_MAC_PM_TRUNC_BB_OVERFLOW 0x3c
2581/* enum: PM discard_bb_overflow counter. Valid for EF10 with
2582 * PM_AND_RXDP_COUNTERS capability only.
2583 */
2584#define MC_CMD_MAC_PM_DISCARD_BB_OVERFLOW 0x3d
2585/* enum: PM trunc_vfifo_full counter. Valid for EF10 with PM_AND_RXDP_COUNTERS
2586 * capability only.
2587 */
2588#define MC_CMD_MAC_PM_TRUNC_VFIFO_FULL 0x3e
2589/* enum: PM discard_vfifo_full counter. Valid for EF10 with
2590 * PM_AND_RXDP_COUNTERS capability only.
2591 */
2592#define MC_CMD_MAC_PM_DISCARD_VFIFO_FULL 0x3f
2593/* enum: PM trunc_qbb counter. Valid for EF10 with PM_AND_RXDP_COUNTERS
2594 * capability only.
2595 */
2596#define MC_CMD_MAC_PM_TRUNC_QBB 0x40
2597/* enum: PM discard_qbb counter. Valid for EF10 with PM_AND_RXDP_COUNTERS
2598 * capability only.
2599 */
2600#define MC_CMD_MAC_PM_DISCARD_QBB 0x41
2601/* enum: PM discard_mapping counter. Valid for EF10 with PM_AND_RXDP_COUNTERS
2602 * capability only.
2603 */
2604#define MC_CMD_MAC_PM_DISCARD_MAPPING 0x42
2605/* enum: RXDP counter: Number of packets dropped due to the queue being
2606 * disabled. Valid for EF10 with PM_AND_RXDP_COUNTERS capability only.
2607 */
2608#define MC_CMD_MAC_RXDP_Q_DISABLED_PKTS 0x43
2609/* enum: RXDP counter: Number of packets dropped by the DICPU. Valid for EF10
2610 * with PM_AND_RXDP_COUNTERS capability only.
2611 */
2612#define MC_CMD_MAC_RXDP_DI_DROPPED_PKTS 0x45
2613/* enum: RXDP counter: Number of non-host packets. Valid for EF10 with
2614 * PM_AND_RXDP_COUNTERS capability only.
2615 */
2616#define MC_CMD_MAC_RXDP_STREAMING_PKTS 0x46
2617/* enum: RXDP counter: Number of times an emergency descriptor fetch was
2618 * performed. Valid for EF10 with PM_AND_RXDP_COUNTERS capability only.
2619 */
2620#define MC_CMD_MAC_RXDP_EMERGENCY_FETCH_CONDITIONS 0x47
2621/* enum: RXDP counter: Number of times the DPCPU waited for an existing
2622 * descriptor fetch. Valid for EF10 with PM_AND_RXDP_COUNTERS capability only.
2623 */
2624#define MC_CMD_MAC_RXDP_EMERGENCY_WAIT_CONDITIONS 0x48
2625/* enum: Start of GMAC stats buffer space, for Siena only. */
2626#define MC_CMD_GMAC_DMABUF_START 0x40
2627/* enum: End of GMAC stats buffer space, for Siena only. */
2628#define MC_CMD_GMAC_DMABUF_END 0x5f
2579#define MC_CMD_MAC_GENERATION_END 0x60 /* enum */ 2629#define MC_CMD_MAC_GENERATION_END 0x60 /* enum */
2580#define MC_CMD_MAC_NSTATS 0x61 /* enum */ 2630#define MC_CMD_MAC_NSTATS 0x61 /* enum */
2581 2631
@@ -5065,6 +5115,8 @@
5065#define MC_CMD_GET_CAPABILITIES_OUT_RX_BATCHING_WIDTH 1 5115#define MC_CMD_GET_CAPABILITIES_OUT_RX_BATCHING_WIDTH 1
5066#define MC_CMD_GET_CAPABILITIES_OUT_MCAST_FILTER_CHAINING_LBN 26 5116#define MC_CMD_GET_CAPABILITIES_OUT_MCAST_FILTER_CHAINING_LBN 26
5067#define MC_CMD_GET_CAPABILITIES_OUT_MCAST_FILTER_CHAINING_WIDTH 1 5117#define MC_CMD_GET_CAPABILITIES_OUT_MCAST_FILTER_CHAINING_WIDTH 1
5118#define MC_CMD_GET_CAPABILITIES_OUT_PM_AND_RXDP_COUNTERS_LBN 27
5119#define MC_CMD_GET_CAPABILITIES_OUT_PM_AND_RXDP_COUNTERS_WIDTH 1
5068/* RxDPCPU firmware id. */ 5120/* RxDPCPU firmware id. */
5069#define MC_CMD_GET_CAPABILITIES_OUT_RX_DPCPU_FW_ID_OFST 4 5121#define MC_CMD_GET_CAPABILITIES_OUT_RX_DPCPU_FW_ID_OFST 4
5070#define MC_CMD_GET_CAPABILITIES_OUT_RX_DPCPU_FW_ID_LEN 2 5122#define MC_CMD_GET_CAPABILITIES_OUT_RX_DPCPU_FW_ID_LEN 2
diff --git a/drivers/net/ethernet/sfc/nic.c b/drivers/net/ethernet/sfc/nic.c
index e7dbd2dd202e..9826594c8a48 100644
--- a/drivers/net/ethernet/sfc/nic.c
+++ b/drivers/net/ethernet/sfc/nic.c
@@ -469,8 +469,7 @@ size_t efx_nic_describe_stats(const struct efx_hw_stat_desc *desc, size_t count,
469 * @count: Length of the @desc array 469 * @count: Length of the @desc array
470 * @mask: Bitmask of which elements of @desc are enabled 470 * @mask: Bitmask of which elements of @desc are enabled
471 * @stats: Buffer to update with the converted statistics. The length 471 * @stats: Buffer to update with the converted statistics. The length
472 * of this array must be at least the number of set bits in the 472 * of this array must be at least @count.
473 * first @count bits of @mask.
474 * @dma_buf: DMA buffer containing hardware statistics 473 * @dma_buf: DMA buffer containing hardware statistics
475 * @accumulate: If set, the converted values will be added rather than 474 * @accumulate: If set, the converted values will be added rather than
476 * directly stored to the corresponding elements of @stats 475 * directly stored to the corresponding elements of @stats
@@ -503,11 +502,9 @@ void efx_nic_update_stats(const struct efx_hw_stat_desc *desc, size_t count,
503 } 502 }
504 503
505 if (accumulate) 504 if (accumulate)
506 *stats += val; 505 stats[index] += val;
507 else 506 else
508 *stats = val; 507 stats[index] = val;
509 } 508 }
510
511 ++stats;
512 } 509 }
513} 510}
diff --git a/drivers/net/ethernet/sfc/nic.h b/drivers/net/ethernet/sfc/nic.h
index fda29d39032f..890bbbe8320e 100644
--- a/drivers/net/ethernet/sfc/nic.h
+++ b/drivers/net/ethernet/sfc/nic.h
@@ -386,6 +386,18 @@ enum {
386 EF10_STAT_rx_align_error, 386 EF10_STAT_rx_align_error,
387 EF10_STAT_rx_length_error, 387 EF10_STAT_rx_length_error,
388 EF10_STAT_rx_nodesc_drops, 388 EF10_STAT_rx_nodesc_drops,
389 EF10_STAT_rx_pm_trunc_bb_overflow,
390 EF10_STAT_rx_pm_discard_bb_overflow,
391 EF10_STAT_rx_pm_trunc_vfifo_full,
392 EF10_STAT_rx_pm_discard_vfifo_full,
393 EF10_STAT_rx_pm_trunc_qbb,
394 EF10_STAT_rx_pm_discard_qbb,
395 EF10_STAT_rx_pm_discard_mapping,
396 EF10_STAT_rx_dp_q_disabled_packets,
397 EF10_STAT_rx_dp_di_dropped_packets,
398 EF10_STAT_rx_dp_streaming_packets,
399 EF10_STAT_rx_dp_emerg_fetch,
400 EF10_STAT_rx_dp_emerg_wait,
389 EF10_STAT_COUNT 401 EF10_STAT_COUNT
390}; 402};
391 403
diff --git a/drivers/net/ethernet/smsc/smc91x.h b/drivers/net/ethernet/smsc/smc91x.h
index 5730fe2445a6..98eedb90cdc3 100644
--- a/drivers/net/ethernet/smsc/smc91x.h
+++ b/drivers/net/ethernet/smsc/smc91x.h
@@ -1124,8 +1124,7 @@ static const char * chip_ids[ 16 ] = {
1124 void __iomem *__ioaddr = ioaddr; \ 1124 void __iomem *__ioaddr = ioaddr; \
1125 if (__len >= 2 && (unsigned long)__ptr & 2) { \ 1125 if (__len >= 2 && (unsigned long)__ptr & 2) { \
1126 __len -= 2; \ 1126 __len -= 2; \
1127 SMC_outw(*(u16 *)__ptr, ioaddr, \ 1127 SMC_outsw(ioaddr, DATA_REG(lp), __ptr, 1); \
1128 DATA_REG(lp)); \
1129 __ptr += 2; \ 1128 __ptr += 2; \
1130 } \ 1129 } \
1131 if (SMC_CAN_USE_DATACS && lp->datacs) \ 1130 if (SMC_CAN_USE_DATACS && lp->datacs) \
@@ -1133,8 +1132,7 @@ static const char * chip_ids[ 16 ] = {
1133 SMC_outsl(__ioaddr, DATA_REG(lp), __ptr, __len>>2); \ 1132 SMC_outsl(__ioaddr, DATA_REG(lp), __ptr, __len>>2); \
1134 if (__len & 2) { \ 1133 if (__len & 2) { \
1135 __ptr += (__len & ~3); \ 1134 __ptr += (__len & ~3); \
1136 SMC_outw(*((u16 *)__ptr), ioaddr, \ 1135 SMC_outsw(ioaddr, DATA_REG(lp), __ptr, 1); \
1137 DATA_REG(lp)); \
1138 } \ 1136 } \
1139 } else if (SMC_16BIT(lp)) \ 1137 } else if (SMC_16BIT(lp)) \
1140 SMC_outsw(ioaddr, DATA_REG(lp), p, (l) >> 1); \ 1138 SMC_outsw(ioaddr, DATA_REG(lp), p, (l) >> 1); \
diff --git a/drivers/net/ethernet/ti/cpsw.c b/drivers/net/ethernet/ti/cpsw.c
index 79974e31187a..cc3ce557e4aa 100644
--- a/drivers/net/ethernet/ti/cpsw.c
+++ b/drivers/net/ethernet/ti/cpsw.c
@@ -639,13 +639,6 @@ void cpsw_rx_handler(void *token, int len, int status)
639static irqreturn_t cpsw_interrupt(int irq, void *dev_id) 639static irqreturn_t cpsw_interrupt(int irq, void *dev_id)
640{ 640{
641 struct cpsw_priv *priv = dev_id; 641 struct cpsw_priv *priv = dev_id;
642 u32 rx, tx, rx_thresh;
643
644 rx_thresh = __raw_readl(&priv->wr_regs->rx_thresh_stat);
645 rx = __raw_readl(&priv->wr_regs->rx_stat);
646 tx = __raw_readl(&priv->wr_regs->tx_stat);
647 if (!rx_thresh && !rx && !tx)
648 return IRQ_NONE;
649 642
650 cpsw_intr_disable(priv); 643 cpsw_intr_disable(priv);
651 if (priv->irq_enabled == true) { 644 if (priv->irq_enabled == true) {
@@ -1169,9 +1162,9 @@ static int cpsw_ndo_open(struct net_device *ndev)
1169 } 1162 }
1170 } 1163 }
1171 1164
1165 napi_enable(&priv->napi);
1172 cpdma_ctlr_start(priv->dma); 1166 cpdma_ctlr_start(priv->dma);
1173 cpsw_intr_enable(priv); 1167 cpsw_intr_enable(priv);
1174 napi_enable(&priv->napi);
1175 cpdma_ctlr_eoi(priv->dma, CPDMA_EOI_RX); 1168 cpdma_ctlr_eoi(priv->dma, CPDMA_EOI_RX);
1176 cpdma_ctlr_eoi(priv->dma, CPDMA_EOI_TX); 1169 cpdma_ctlr_eoi(priv->dma, CPDMA_EOI_TX);
1177 1170
@@ -1771,8 +1764,8 @@ static int cpsw_probe_dt(struct cpsw_platform_data *data,
1771 } 1764 }
1772 data->mac_control = prop; 1765 data->mac_control = prop;
1773 1766
1774 if (!of_property_read_u32(node, "dual_emac", &prop)) 1767 if (of_property_read_bool(node, "dual_emac"))
1775 data->dual_emac = prop; 1768 data->dual_emac = 1;
1776 1769
1777 /* 1770 /*
1778 * Populate all the child nodes here... 1771 * Populate all the child nodes here...
@@ -1782,7 +1775,7 @@ static int cpsw_probe_dt(struct cpsw_platform_data *data,
1782 if (ret) 1775 if (ret)
1783 pr_warn("Doesn't have any child node\n"); 1776 pr_warn("Doesn't have any child node\n");
1784 1777
1785 for_each_node_by_name(slave_node, "slave") { 1778 for_each_child_of_node(node, slave_node) {
1786 struct cpsw_slave_data *slave_data = data->slave_data + i; 1779 struct cpsw_slave_data *slave_data = data->slave_data + i;
1787 const void *mac_addr = NULL; 1780 const void *mac_addr = NULL;
1788 u32 phyid; 1781 u32 phyid;
@@ -1791,6 +1784,10 @@ static int cpsw_probe_dt(struct cpsw_platform_data *data,
1791 struct device_node *mdio_node; 1784 struct device_node *mdio_node;
1792 struct platform_device *mdio; 1785 struct platform_device *mdio;
1793 1786
1787 /* This is no slave child node, continue */
1788 if (strcmp(slave_node->name, "slave"))
1789 continue;
1790
1794 parp = of_get_property(slave_node, "phy_id", &lenp); 1791 parp = of_get_property(slave_node, "phy_id", &lenp);
1795 if ((parp == NULL) || (lenp != (sizeof(void *) * 2))) { 1792 if ((parp == NULL) || (lenp != (sizeof(void *) * 2))) {
1796 pr_err("Missing slave[%d] phy_id property\n", i); 1793 pr_err("Missing slave[%d] phy_id property\n", i);
diff --git a/drivers/net/ethernet/ti/davinci_emac.c b/drivers/net/ethernet/ti/davinci_emac.c
index 67df09ea9d04..6a32ef9d63ae 100644
--- a/drivers/net/ethernet/ti/davinci_emac.c
+++ b/drivers/net/ethernet/ti/davinci_emac.c
@@ -876,8 +876,7 @@ static void emac_dev_mcast_set(struct net_device *ndev)
876 netdev_mc_count(ndev) > EMAC_DEF_MAX_MULTICAST_ADDRESSES) { 876 netdev_mc_count(ndev) > EMAC_DEF_MAX_MULTICAST_ADDRESSES) {
877 mbp_enable = (mbp_enable | EMAC_MBP_RXMCAST); 877 mbp_enable = (mbp_enable | EMAC_MBP_RXMCAST);
878 emac_add_mcast(priv, EMAC_ALL_MULTI_SET, NULL); 878 emac_add_mcast(priv, EMAC_ALL_MULTI_SET, NULL);
879 } 879 } else if (!netdev_mc_empty(ndev)) {
880 if (!netdev_mc_empty(ndev)) {
881 struct netdev_hw_addr *ha; 880 struct netdev_hw_addr *ha;
882 881
883 mbp_enable = (mbp_enable | EMAC_MBP_RXMCAST); 882 mbp_enable = (mbp_enable | EMAC_MBP_RXMCAST);
diff --git a/drivers/net/hamradio/yam.c b/drivers/net/hamradio/yam.c
index 0721e72f9299..5af1c3e5032a 100644
--- a/drivers/net/hamradio/yam.c
+++ b/drivers/net/hamradio/yam.c
@@ -975,7 +975,6 @@ static int yam_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
975 return -EINVAL; /* Cannot change this parameter when up */ 975 return -EINVAL; /* Cannot change this parameter when up */
976 if ((ym = kmalloc(sizeof(struct yamdrv_ioctl_mcs), GFP_KERNEL)) == NULL) 976 if ((ym = kmalloc(sizeof(struct yamdrv_ioctl_mcs), GFP_KERNEL)) == NULL)
977 return -ENOBUFS; 977 return -ENOBUFS;
978 ym->bitrate = 9600;
979 if (copy_from_user(ym, ifr->ifr_data, sizeof(struct yamdrv_ioctl_mcs))) { 978 if (copy_from_user(ym, ifr->ifr_data, sizeof(struct yamdrv_ioctl_mcs))) {
980 kfree(ym); 979 kfree(ym);
981 return -EFAULT; 980 return -EFAULT;
diff --git a/drivers/net/ieee802154/mrf24j40.c b/drivers/net/ieee802154/mrf24j40.c
index 42e6deee6db5..0632d34905c7 100644
--- a/drivers/net/ieee802154/mrf24j40.c
+++ b/drivers/net/ieee802154/mrf24j40.c
@@ -82,7 +82,6 @@ struct mrf24j40 {
82 82
83 struct mutex buffer_mutex; /* only used to protect buf */ 83 struct mutex buffer_mutex; /* only used to protect buf */
84 struct completion tx_complete; 84 struct completion tx_complete;
85 struct work_struct irqwork;
86 u8 *buf; /* 3 bytes. Used for SPI single-register transfers. */ 85 u8 *buf; /* 3 bytes. Used for SPI single-register transfers. */
87}; 86};
88 87
@@ -344,6 +343,8 @@ static int mrf24j40_tx(struct ieee802154_dev *dev, struct sk_buff *skb)
344 if (ret) 343 if (ret)
345 goto err; 344 goto err;
346 345
346 INIT_COMPLETION(devrec->tx_complete);
347
347 /* Set TXNTRIG bit of TXNCON to send packet */ 348 /* Set TXNTRIG bit of TXNCON to send packet */
348 ret = read_short_reg(devrec, REG_TXNCON, &val); 349 ret = read_short_reg(devrec, REG_TXNCON, &val);
349 if (ret) 350 if (ret)
@@ -354,8 +355,6 @@ static int mrf24j40_tx(struct ieee802154_dev *dev, struct sk_buff *skb)
354 val |= 0x4; 355 val |= 0x4;
355 write_short_reg(devrec, REG_TXNCON, val); 356 write_short_reg(devrec, REG_TXNCON, val);
356 357
357 INIT_COMPLETION(devrec->tx_complete);
358
359 /* Wait for the device to send the TX complete interrupt. */ 358 /* Wait for the device to send the TX complete interrupt. */
360 ret = wait_for_completion_interruptible_timeout( 359 ret = wait_for_completion_interruptible_timeout(
361 &devrec->tx_complete, 360 &devrec->tx_complete,
@@ -590,17 +589,6 @@ static struct ieee802154_ops mrf24j40_ops = {
590static irqreturn_t mrf24j40_isr(int irq, void *data) 589static irqreturn_t mrf24j40_isr(int irq, void *data)
591{ 590{
592 struct mrf24j40 *devrec = data; 591 struct mrf24j40 *devrec = data;
593
594 disable_irq_nosync(irq);
595
596 schedule_work(&devrec->irqwork);
597
598 return IRQ_HANDLED;
599}
600
601static void mrf24j40_isrwork(struct work_struct *work)
602{
603 struct mrf24j40 *devrec = container_of(work, struct mrf24j40, irqwork);
604 u8 intstat; 592 u8 intstat;
605 int ret; 593 int ret;
606 594
@@ -618,7 +606,7 @@ static void mrf24j40_isrwork(struct work_struct *work)
618 mrf24j40_handle_rx(devrec); 606 mrf24j40_handle_rx(devrec);
619 607
620out: 608out:
621 enable_irq(devrec->spi->irq); 609 return IRQ_HANDLED;
622} 610}
623 611
624static int mrf24j40_probe(struct spi_device *spi) 612static int mrf24j40_probe(struct spi_device *spi)
@@ -642,7 +630,6 @@ static int mrf24j40_probe(struct spi_device *spi)
642 630
643 mutex_init(&devrec->buffer_mutex); 631 mutex_init(&devrec->buffer_mutex);
644 init_completion(&devrec->tx_complete); 632 init_completion(&devrec->tx_complete);
645 INIT_WORK(&devrec->irqwork, mrf24j40_isrwork);
646 devrec->spi = spi; 633 devrec->spi = spi;
647 spi_set_drvdata(spi, devrec); 634 spi_set_drvdata(spi, devrec);
648 635
@@ -688,11 +675,12 @@ static int mrf24j40_probe(struct spi_device *spi)
688 val &= ~0x3; /* Clear RX mode (normal) */ 675 val &= ~0x3; /* Clear RX mode (normal) */
689 write_short_reg(devrec, REG_RXMCR, val); 676 write_short_reg(devrec, REG_RXMCR, val);
690 677
691 ret = request_irq(spi->irq, 678 ret = request_threaded_irq(spi->irq,
692 mrf24j40_isr, 679 NULL,
693 IRQF_TRIGGER_FALLING, 680 mrf24j40_isr,
694 dev_name(&spi->dev), 681 IRQF_TRIGGER_LOW|IRQF_ONESHOT,
695 devrec); 682 dev_name(&spi->dev),
683 devrec);
696 684
697 if (ret) { 685 if (ret) {
698 dev_err(printdev(devrec), "Unable to get IRQ"); 686 dev_err(printdev(devrec), "Unable to get IRQ");
@@ -721,7 +709,6 @@ static int mrf24j40_remove(struct spi_device *spi)
721 dev_dbg(printdev(devrec), "remove\n"); 709 dev_dbg(printdev(devrec), "remove\n");
722 710
723 free_irq(spi->irq, devrec); 711 free_irq(spi->irq, devrec);
724 flush_work(&devrec->irqwork); /* TODO: Is this the right call? */
725 ieee802154_unregister_device(devrec->dev); 712 ieee802154_unregister_device(devrec->dev);
726 ieee802154_free_device(devrec->dev); 713 ieee802154_free_device(devrec->dev);
727 /* TODO: Will ieee802154_free_device() wait until ->xmit() is 714 /* TODO: Will ieee802154_free_device() wait until ->xmit() is
diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
index adeee615dd19..c9a15925a1f7 100644
--- a/drivers/net/netconsole.c
+++ b/drivers/net/netconsole.c
@@ -310,6 +310,7 @@ static ssize_t store_enabled(struct netconsole_target *nt,
310 const char *buf, 310 const char *buf,
311 size_t count) 311 size_t count)
312{ 312{
313 unsigned long flags;
313 int enabled; 314 int enabled;
314 int err; 315 int err;
315 316
@@ -324,9 +325,7 @@ static ssize_t store_enabled(struct netconsole_target *nt,
324 return -EINVAL; 325 return -EINVAL;
325 } 326 }
326 327
327 mutex_lock(&nt->mutex);
328 if (enabled) { /* 1 */ 328 if (enabled) { /* 1 */
329
330 /* 329 /*
331 * Skip netpoll_parse_options() -- all the attributes are 330 * Skip netpoll_parse_options() -- all the attributes are
332 * already configured via configfs. Just print them out. 331 * already configured via configfs. Just print them out.
@@ -334,19 +333,22 @@ static ssize_t store_enabled(struct netconsole_target *nt,
334 netpoll_print_options(&nt->np); 333 netpoll_print_options(&nt->np);
335 334
336 err = netpoll_setup(&nt->np); 335 err = netpoll_setup(&nt->np);
337 if (err) { 336 if (err)
338 mutex_unlock(&nt->mutex);
339 return err; 337 return err;
340 }
341 338
342 printk(KERN_INFO "netconsole: network logging started\n"); 339 printk(KERN_INFO "netconsole: network logging started\n");
343
344 } else { /* 0 */ 340 } else { /* 0 */
341 /* We need to disable the netconsole before cleaning it up
342 * otherwise we might end up in write_msg() with
343 * nt->np.dev == NULL and nt->enabled == 1
344 */
345 spin_lock_irqsave(&target_list_lock, flags);
346 nt->enabled = 0;
347 spin_unlock_irqrestore(&target_list_lock, flags);
345 netpoll_cleanup(&nt->np); 348 netpoll_cleanup(&nt->np);
346 } 349 }
347 350
348 nt->enabled = enabled; 351 nt->enabled = enabled;
349 mutex_unlock(&nt->mutex);
350 352
351 return strnlen(buf, count); 353 return strnlen(buf, count);
352} 354}
@@ -563,8 +565,10 @@ static ssize_t netconsole_target_attr_store(struct config_item *item,
563 struct netconsole_target_attr *na = 565 struct netconsole_target_attr *na =
564 container_of(attr, struct netconsole_target_attr, attr); 566 container_of(attr, struct netconsole_target_attr, attr);
565 567
568 mutex_lock(&nt->mutex);
566 if (na->store) 569 if (na->store)
567 ret = na->store(nt, buf, count); 570 ret = na->store(nt, buf, count);
571 mutex_unlock(&nt->mutex);
568 572
569 return ret; 573 return ret;
570} 574}
diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index 807815fc9968..7cb105c103fe 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -1293,7 +1293,8 @@ static ssize_t tun_do_read(struct tun_struct *tun, struct tun_file *tfile,
1293 if (unlikely(!noblock)) 1293 if (unlikely(!noblock))
1294 add_wait_queue(&tfile->wq.wait, &wait); 1294 add_wait_queue(&tfile->wq.wait, &wait);
1295 while (len) { 1295 while (len) {
1296 current->state = TASK_INTERRUPTIBLE; 1296 if (unlikely(!noblock))
1297 current->state = TASK_INTERRUPTIBLE;
1297 1298
1298 /* Read frames from the queue */ 1299 /* Read frames from the queue */
1299 if (!(skb = skb_dequeue(&tfile->socket.sk->sk_receive_queue))) { 1300 if (!(skb = skb_dequeue(&tfile->socket.sk->sk_receive_queue))) {
@@ -1320,9 +1321,10 @@ static ssize_t tun_do_read(struct tun_struct *tun, struct tun_file *tfile,
1320 break; 1321 break;
1321 } 1322 }
1322 1323
1323 current->state = TASK_RUNNING; 1324 if (unlikely(!noblock)) {
1324 if (unlikely(!noblock)) 1325 current->state = TASK_RUNNING;
1325 remove_wait_queue(&tfile->wq.wait, &wait); 1326 remove_wait_queue(&tfile->wq.wait, &wait);
1327 }
1326 1328
1327 return ret; 1329 return ret;
1328} 1330}
diff --git a/drivers/net/usb/ax88179_178a.c b/drivers/net/usb/ax88179_178a.c
index 3569293df872..8e8d0fcd4979 100644
--- a/drivers/net/usb/ax88179_178a.c
+++ b/drivers/net/usb/ax88179_178a.c
@@ -36,8 +36,8 @@
36#define AX_RXHDR_L4_TYPE_TCP 16 36#define AX_RXHDR_L4_TYPE_TCP 16
37#define AX_RXHDR_L3CSUM_ERR 2 37#define AX_RXHDR_L3CSUM_ERR 2
38#define AX_RXHDR_L4CSUM_ERR 1 38#define AX_RXHDR_L4CSUM_ERR 1
39#define AX_RXHDR_CRC_ERR ((u32)BIT(31)) 39#define AX_RXHDR_CRC_ERR ((u32)BIT(29))
40#define AX_RXHDR_DROP_ERR ((u32)BIT(30)) 40#define AX_RXHDR_DROP_ERR ((u32)BIT(31))
41#define AX_ACCESS_MAC 0x01 41#define AX_ACCESS_MAC 0x01
42#define AX_ACCESS_PHY 0x02 42#define AX_ACCESS_PHY 0x02
43#define AX_ACCESS_EEPROM 0x04 43#define AX_ACCESS_EEPROM 0x04
@@ -78,7 +78,6 @@
78#define AX_MEDIUM_STATUS_MODE 0x22 78#define AX_MEDIUM_STATUS_MODE 0x22
79 #define AX_MEDIUM_GIGAMODE 0x01 79 #define AX_MEDIUM_GIGAMODE 0x01
80 #define AX_MEDIUM_FULL_DUPLEX 0x02 80 #define AX_MEDIUM_FULL_DUPLEX 0x02
81 #define AX_MEDIUM_ALWAYS_ONE 0x04
82 #define AX_MEDIUM_EN_125MHZ 0x08 81 #define AX_MEDIUM_EN_125MHZ 0x08
83 #define AX_MEDIUM_RXFLOW_CTRLEN 0x10 82 #define AX_MEDIUM_RXFLOW_CTRLEN 0x10
84 #define AX_MEDIUM_TXFLOW_CTRLEN 0x20 83 #define AX_MEDIUM_TXFLOW_CTRLEN 0x20
@@ -1065,8 +1064,8 @@ static int ax88179_bind(struct usbnet *dev, struct usb_interface *intf)
1065 1064
1066 /* Configure default medium type => giga */ 1065 /* Configure default medium type => giga */
1067 *tmp16 = AX_MEDIUM_RECEIVE_EN | AX_MEDIUM_TXFLOW_CTRLEN | 1066 *tmp16 = AX_MEDIUM_RECEIVE_EN | AX_MEDIUM_TXFLOW_CTRLEN |
1068 AX_MEDIUM_RXFLOW_CTRLEN | AX_MEDIUM_ALWAYS_ONE | 1067 AX_MEDIUM_RXFLOW_CTRLEN | AX_MEDIUM_FULL_DUPLEX |
1069 AX_MEDIUM_FULL_DUPLEX | AX_MEDIUM_GIGAMODE; 1068 AX_MEDIUM_GIGAMODE;
1070 ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE, 1069 ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE,
1071 2, 2, tmp16); 1070 2, 2, tmp16);
1072 1071
@@ -1225,7 +1224,7 @@ static int ax88179_link_reset(struct usbnet *dev)
1225 } 1224 }
1226 1225
1227 mode = AX_MEDIUM_RECEIVE_EN | AX_MEDIUM_TXFLOW_CTRLEN | 1226 mode = AX_MEDIUM_RECEIVE_EN | AX_MEDIUM_TXFLOW_CTRLEN |
1228 AX_MEDIUM_RXFLOW_CTRLEN | AX_MEDIUM_ALWAYS_ONE; 1227 AX_MEDIUM_RXFLOW_CTRLEN;
1229 1228
1230 ax88179_read_cmd(dev, AX_ACCESS_MAC, PHYSICAL_LINK_STATUS, 1229 ax88179_read_cmd(dev, AX_ACCESS_MAC, PHYSICAL_LINK_STATUS,
1231 1, 1, &link_sts); 1230 1, 1, &link_sts);
@@ -1339,8 +1338,8 @@ static int ax88179_reset(struct usbnet *dev)
1339 1338
1340 /* Configure default medium type => giga */ 1339 /* Configure default medium type => giga */
1341 *tmp16 = AX_MEDIUM_RECEIVE_EN | AX_MEDIUM_TXFLOW_CTRLEN | 1340 *tmp16 = AX_MEDIUM_RECEIVE_EN | AX_MEDIUM_TXFLOW_CTRLEN |
1342 AX_MEDIUM_RXFLOW_CTRLEN | AX_MEDIUM_ALWAYS_ONE | 1341 AX_MEDIUM_RXFLOW_CTRLEN | AX_MEDIUM_FULL_DUPLEX |
1343 AX_MEDIUM_FULL_DUPLEX | AX_MEDIUM_GIGAMODE; 1342 AX_MEDIUM_GIGAMODE;
1344 ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE, 1343 ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE,
1345 2, 2, tmp16); 1344 2, 2, tmp16);
1346 1345
@@ -1406,6 +1405,19 @@ static const struct driver_info sitecom_info = {
1406 .tx_fixup = ax88179_tx_fixup, 1405 .tx_fixup = ax88179_tx_fixup,
1407}; 1406};
1408 1407
1408static const struct driver_info samsung_info = {
1409 .description = "Samsung USB Ethernet Adapter",
1410 .bind = ax88179_bind,
1411 .unbind = ax88179_unbind,
1412 .status = ax88179_status,
1413 .link_reset = ax88179_link_reset,
1414 .reset = ax88179_reset,
1415 .stop = ax88179_stop,
1416 .flags = FLAG_ETHER | FLAG_FRAMING_AX,
1417 .rx_fixup = ax88179_rx_fixup,
1418 .tx_fixup = ax88179_tx_fixup,
1419};
1420
1409static const struct usb_device_id products[] = { 1421static const struct usb_device_id products[] = {
1410{ 1422{
1411 /* ASIX AX88179 10/100/1000 */ 1423 /* ASIX AX88179 10/100/1000 */
@@ -1418,7 +1430,11 @@ static const struct usb_device_id products[] = {
1418}, { 1430}, {
1419 /* Sitecom USB 3.0 to Gigabit Adapter */ 1431 /* Sitecom USB 3.0 to Gigabit Adapter */
1420 USB_DEVICE(0x0df6, 0x0072), 1432 USB_DEVICE(0x0df6, 0x0072),
1421 .driver_info = (unsigned long) &sitecom_info, 1433 .driver_info = (unsigned long)&sitecom_info,
1434}, {
1435 /* Samsung USB Ethernet Adapter */
1436 USB_DEVICE(0x04e8, 0xa100),
1437 .driver_info = (unsigned long)&samsung_info,
1422}, 1438},
1423 { }, 1439 { },
1424}; 1440};
diff --git a/drivers/net/usb/qmi_wwan.c b/drivers/net/usb/qmi_wwan.c
index 3d6aaf79d8b2..818ce90185b5 100644
--- a/drivers/net/usb/qmi_wwan.c
+++ b/drivers/net/usb/qmi_wwan.c
@@ -714,6 +714,7 @@ static const struct usb_device_id products[] = {
714 {QMI_FIXED_INTF(0x2357, 0x0201, 4)}, /* TP-LINK HSUPA Modem MA180 */ 714 {QMI_FIXED_INTF(0x2357, 0x0201, 4)}, /* TP-LINK HSUPA Modem MA180 */
715 {QMI_FIXED_INTF(0x2357, 0x9000, 4)}, /* TP-LINK MA260 */ 715 {QMI_FIXED_INTF(0x2357, 0x9000, 4)}, /* TP-LINK MA260 */
716 {QMI_FIXED_INTF(0x1bc7, 0x1200, 5)}, /* Telit LE920 */ 716 {QMI_FIXED_INTF(0x1bc7, 0x1200, 5)}, /* Telit LE920 */
717 {QMI_FIXED_INTF(0x0b3c, 0xc005, 6)}, /* Olivetti Olicard 200 */
717 {QMI_FIXED_INTF(0x1e2d, 0x0060, 4)}, /* Cinterion PLxx */ 718 {QMI_FIXED_INTF(0x1e2d, 0x0060, 4)}, /* Cinterion PLxx */
718 719
719 /* 4. Gobi 1000 devices */ 720 /* 4. Gobi 1000 devices */
diff --git a/drivers/net/usb/usbnet.c b/drivers/net/usb/usbnet.c
index bf94e10a37c8..90a429b7ebad 100644
--- a/drivers/net/usb/usbnet.c
+++ b/drivers/net/usb/usbnet.c
@@ -1688,8 +1688,10 @@ usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod)
1688 if (dev->can_dma_sg && !(info->flags & FLAG_SEND_ZLP) && 1688 if (dev->can_dma_sg && !(info->flags & FLAG_SEND_ZLP) &&
1689 !(info->flags & FLAG_MULTI_PACKET)) { 1689 !(info->flags & FLAG_MULTI_PACKET)) {
1690 dev->padding_pkt = kzalloc(1, GFP_KERNEL); 1690 dev->padding_pkt = kzalloc(1, GFP_KERNEL);
1691 if (!dev->padding_pkt) 1691 if (!dev->padding_pkt) {
1692 status = -ENOMEM;
1692 goto out4; 1693 goto out4;
1694 }
1693 } 1695 }
1694 1696
1695 status = register_netdev (net); 1697 status = register_netdev (net);
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index defec2b3c5a4..bbc9cb84ec1f 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -938,7 +938,9 @@ static int virtnet_set_queues(struct virtnet_info *vi, u16 queue_pairs)
938 return -EINVAL; 938 return -EINVAL;
939 } else { 939 } else {
940 vi->curr_queue_pairs = queue_pairs; 940 vi->curr_queue_pairs = queue_pairs;
941 schedule_delayed_work(&vi->refill, 0); 941 /* virtnet_open() will refill when device is going to up. */
942 if (dev->flags & IFF_UP)
943 schedule_delayed_work(&vi->refill, 0);
942 } 944 }
943 945
944 return 0; 946 return 0;
@@ -1128,6 +1130,7 @@ static int virtnet_cpu_callback(struct notifier_block *nfb,
1128 default: 1130 default:
1129 break; 1131 break;
1130 } 1132 }
1133
1131 return NOTIFY_OK; 1134 return NOTIFY_OK;
1132} 1135}
1133 1136
@@ -1689,6 +1692,8 @@ static int virtnet_freeze(struct virtio_device *vdev)
1689 struct virtnet_info *vi = vdev->priv; 1692 struct virtnet_info *vi = vdev->priv;
1690 int i; 1693 int i;
1691 1694
1695 unregister_hotcpu_notifier(&vi->nb);
1696
1692 /* Prevent config work handler from accessing the device */ 1697 /* Prevent config work handler from accessing the device */
1693 mutex_lock(&vi->config_lock); 1698 mutex_lock(&vi->config_lock);
1694 vi->config_enable = false; 1699 vi->config_enable = false;
@@ -1733,7 +1738,13 @@ static int virtnet_restore(struct virtio_device *vdev)
1733 vi->config_enable = true; 1738 vi->config_enable = true;
1734 mutex_unlock(&vi->config_lock); 1739 mutex_unlock(&vi->config_lock);
1735 1740
1741 rtnl_lock();
1736 virtnet_set_queues(vi, vi->curr_queue_pairs); 1742 virtnet_set_queues(vi, vi->curr_queue_pairs);
1743 rtnl_unlock();
1744
1745 err = register_hotcpu_notifier(&vi->nb);
1746 if (err)
1747 return err;
1737 1748
1738 return 0; 1749 return 0;
1739} 1750}
diff --git a/drivers/net/wan/farsync.c b/drivers/net/wan/farsync.c
index 3f0c4f268751..bcfff0d62de4 100644
--- a/drivers/net/wan/farsync.c
+++ b/drivers/net/wan/farsync.c
@@ -1972,6 +1972,7 @@ fst_get_iface(struct fst_card_info *card, struct fst_port_info *port,
1972 } 1972 }
1973 1973
1974 i = port->index; 1974 i = port->index;
1975 memset(&sync, 0, sizeof(sync));
1975 sync.clock_rate = FST_RDL(card, portConfig[i].lineSpeed); 1976 sync.clock_rate = FST_RDL(card, portConfig[i].lineSpeed);
1976 /* Lucky card and linux use same encoding here */ 1977 /* Lucky card and linux use same encoding here */
1977 sync.clock_type = FST_RDB(card, portConfig[i].internalClock) == 1978 sync.clock_type = FST_RDB(card, portConfig[i].internalClock) ==
diff --git a/drivers/net/wan/sbni.c b/drivers/net/wan/sbni.c
index 5bbcb5e3ee0c..388ddf60a66d 100644
--- a/drivers/net/wan/sbni.c
+++ b/drivers/net/wan/sbni.c
@@ -148,10 +148,6 @@ static int enslave( struct net_device *, struct net_device * );
148static int emancipate( struct net_device * ); 148static int emancipate( struct net_device * );
149#endif 149#endif
150 150
151#ifdef __i386__
152#define ASM_CRC 1
153#endif
154
155static const char version[] = 151static const char version[] =
156 "Granch SBNI12 driver ver 5.0.1 Jun 22 2001 Denis I.Timofeev.\n"; 152 "Granch SBNI12 driver ver 5.0.1 Jun 22 2001 Denis I.Timofeev.\n";
157 153
@@ -1551,88 +1547,6 @@ __setup( "sbni=", sbni_setup );
1551 1547
1552/* -------------------------------------------------------------------------- */ 1548/* -------------------------------------------------------------------------- */
1553 1549
1554#ifdef ASM_CRC
1555
1556static u32
1557calc_crc32( u32 crc, u8 *p, u32 len )
1558{
1559 register u32 _crc;
1560 _crc = crc;
1561
1562 __asm__ __volatile__ (
1563 "xorl %%ebx, %%ebx\n"
1564 "movl %2, %%esi\n"
1565 "movl %3, %%ecx\n"
1566 "movl $crc32tab, %%edi\n"
1567 "shrl $2, %%ecx\n"
1568 "jz 1f\n"
1569
1570 ".align 4\n"
1571 "0:\n"
1572 "movb %%al, %%bl\n"
1573 "movl (%%esi), %%edx\n"
1574 "shrl $8, %%eax\n"
1575 "xorb %%dl, %%bl\n"
1576 "shrl $8, %%edx\n"
1577 "xorl (%%edi,%%ebx,4), %%eax\n"
1578
1579 "movb %%al, %%bl\n"
1580 "shrl $8, %%eax\n"
1581 "xorb %%dl, %%bl\n"
1582 "shrl $8, %%edx\n"
1583 "xorl (%%edi,%%ebx,4), %%eax\n"
1584
1585 "movb %%al, %%bl\n"
1586 "shrl $8, %%eax\n"
1587 "xorb %%dl, %%bl\n"
1588 "movb %%dh, %%dl\n"
1589 "xorl (%%edi,%%ebx,4), %%eax\n"
1590
1591 "movb %%al, %%bl\n"
1592 "shrl $8, %%eax\n"
1593 "xorb %%dl, %%bl\n"
1594 "addl $4, %%esi\n"
1595 "xorl (%%edi,%%ebx,4), %%eax\n"
1596
1597 "decl %%ecx\n"
1598 "jnz 0b\n"
1599
1600 "1:\n"
1601 "movl %3, %%ecx\n"
1602 "andl $3, %%ecx\n"
1603 "jz 2f\n"
1604
1605 "movb %%al, %%bl\n"
1606 "shrl $8, %%eax\n"
1607 "xorb (%%esi), %%bl\n"
1608 "xorl (%%edi,%%ebx,4), %%eax\n"
1609
1610 "decl %%ecx\n"
1611 "jz 2f\n"
1612
1613 "movb %%al, %%bl\n"
1614 "shrl $8, %%eax\n"
1615 "xorb 1(%%esi), %%bl\n"
1616 "xorl (%%edi,%%ebx,4), %%eax\n"
1617
1618 "decl %%ecx\n"
1619 "jz 2f\n"
1620
1621 "movb %%al, %%bl\n"
1622 "shrl $8, %%eax\n"
1623 "xorb 2(%%esi), %%bl\n"
1624 "xorl (%%edi,%%ebx,4), %%eax\n"
1625 "2:\n"
1626 : "=a" (_crc)
1627 : "0" (_crc), "g" (p), "g" (len)
1628 : "bx", "cx", "dx", "si", "di"
1629 );
1630
1631 return _crc;
1632}
1633
1634#else /* ASM_CRC */
1635
1636static u32 1550static u32
1637calc_crc32( u32 crc, u8 *p, u32 len ) 1551calc_crc32( u32 crc, u8 *p, u32 len )
1638{ 1552{
@@ -1642,9 +1556,6 @@ calc_crc32( u32 crc, u8 *p, u32 len )
1642 return crc; 1556 return crc;
1643} 1557}
1644 1558
1645#endif /* ASM_CRC */
1646
1647
1648static u32 crc32tab[] __attribute__ ((aligned(8))) = { 1559static u32 crc32tab[] __attribute__ ((aligned(8))) = {
1649 0xD202EF8D, 0xA505DF1B, 0x3C0C8EA1, 0x4B0BBE37, 1560 0xD202EF8D, 0xA505DF1B, 0x3C0C8EA1, 0x4B0BBE37,
1650 0xD56F2B94, 0xA2681B02, 0x3B614AB8, 0x4C667A2E, 1561 0xD56F2B94, 0xA2681B02, 0x3B614AB8, 0x4C667A2E,
diff --git a/drivers/net/wan/wanxl.c b/drivers/net/wan/wanxl.c
index 6a24a5a70cc7..4c0a69779b89 100644
--- a/drivers/net/wan/wanxl.c
+++ b/drivers/net/wan/wanxl.c
@@ -355,6 +355,7 @@ static int wanxl_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
355 ifr->ifr_settings.size = size; /* data size wanted */ 355 ifr->ifr_settings.size = size; /* data size wanted */
356 return -ENOBUFS; 356 return -ENOBUFS;
357 } 357 }
358 memset(&line, 0, sizeof(line));
358 line.clock_type = get_status(port)->clocking; 359 line.clock_type = get_status(port)->clocking;
359 line.clock_rate = 0; 360 line.clock_rate = 0;
360 line.loopback = 0; 361 line.loopback = 0;
diff --git a/drivers/net/wireless/ath/ath9k/main.c b/drivers/net/wireless/ath/ath9k/main.c
index e4f65900132d..709301f88dcd 100644
--- a/drivers/net/wireless/ath/ath9k/main.c
+++ b/drivers/net/wireless/ath/ath9k/main.c
@@ -208,6 +208,7 @@ static bool ath_complete_reset(struct ath_softc *sc, bool start)
208 struct ath_hw *ah = sc->sc_ah; 208 struct ath_hw *ah = sc->sc_ah;
209 struct ath_common *common = ath9k_hw_common(ah); 209 struct ath_common *common = ath9k_hw_common(ah);
210 unsigned long flags; 210 unsigned long flags;
211 int i;
211 212
212 if (ath_startrecv(sc) != 0) { 213 if (ath_startrecv(sc) != 0) {
213 ath_err(common, "Unable to restart recv logic\n"); 214 ath_err(common, "Unable to restart recv logic\n");
@@ -235,6 +236,15 @@ static bool ath_complete_reset(struct ath_softc *sc, bool start)
235 } 236 }
236 work: 237 work:
237 ath_restart_work(sc); 238 ath_restart_work(sc);
239
240 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
241 if (!ATH_TXQ_SETUP(sc, i))
242 continue;
243
244 spin_lock_bh(&sc->tx.txq[i].axq_lock);
245 ath_txq_schedule(sc, &sc->tx.txq[i]);
246 spin_unlock_bh(&sc->tx.txq[i].axq_lock);
247 }
238 } 248 }
239 249
240 ieee80211_wake_queues(sc->hw); 250 ieee80211_wake_queues(sc->hw);
@@ -539,21 +549,10 @@ chip_reset:
539 549
540static int ath_reset(struct ath_softc *sc) 550static int ath_reset(struct ath_softc *sc)
541{ 551{
542 int i, r; 552 int r;
543 553
544 ath9k_ps_wakeup(sc); 554 ath9k_ps_wakeup(sc);
545
546 r = ath_reset_internal(sc, NULL); 555 r = ath_reset_internal(sc, NULL);
547
548 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
549 if (!ATH_TXQ_SETUP(sc, i))
550 continue;
551
552 spin_lock_bh(&sc->tx.txq[i].axq_lock);
553 ath_txq_schedule(sc, &sc->tx.txq[i]);
554 spin_unlock_bh(&sc->tx.txq[i].axq_lock);
555 }
556
557 ath9k_ps_restore(sc); 556 ath9k_ps_restore(sc);
558 557
559 return r; 558 return r;
diff --git a/drivers/net/wireless/ath/ath9k/xmit.c b/drivers/net/wireless/ath/ath9k/xmit.c
index 5ac713d2ff5d..dd30452df966 100644
--- a/drivers/net/wireless/ath/ath9k/xmit.c
+++ b/drivers/net/wireless/ath/ath9k/xmit.c
@@ -1969,15 +1969,18 @@ static void ath_tx_txqaddbuf(struct ath_softc *sc, struct ath_txq *txq,
1969static void ath_tx_send_normal(struct ath_softc *sc, struct ath_txq *txq, 1969static void ath_tx_send_normal(struct ath_softc *sc, struct ath_txq *txq,
1970 struct ath_atx_tid *tid, struct sk_buff *skb) 1970 struct ath_atx_tid *tid, struct sk_buff *skb)
1971{ 1971{
1972 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
1972 struct ath_frame_info *fi = get_frame_info(skb); 1973 struct ath_frame_info *fi = get_frame_info(skb);
1973 struct list_head bf_head; 1974 struct list_head bf_head;
1974 struct ath_buf *bf; 1975 struct ath_buf *bf = fi->bf;
1975
1976 bf = fi->bf;
1977 1976
1978 INIT_LIST_HEAD(&bf_head); 1977 INIT_LIST_HEAD(&bf_head);
1979 list_add_tail(&bf->list, &bf_head); 1978 list_add_tail(&bf->list, &bf_head);
1980 bf->bf_state.bf_type = 0; 1979 bf->bf_state.bf_type = 0;
1980 if (tid && (tx_info->flags & IEEE80211_TX_CTL_AMPDU)) {
1981 bf->bf_state.bf_type = BUF_AMPDU;
1982 ath_tx_addto_baw(sc, tid, bf);
1983 }
1981 1984
1982 bf->bf_next = NULL; 1985 bf->bf_next = NULL;
1983 bf->bf_lastbf = bf; 1986 bf->bf_lastbf = bf;
diff --git a/drivers/net/wireless/cw1200/cw1200_spi.c b/drivers/net/wireless/cw1200/cw1200_spi.c
index 899cad34ccd3..755a0c8edfe1 100644
--- a/drivers/net/wireless/cw1200/cw1200_spi.c
+++ b/drivers/net/wireless/cw1200/cw1200_spi.c
@@ -237,7 +237,9 @@ static irqreturn_t cw1200_spi_irq_handler(int irq, void *dev_id)
237 struct hwbus_priv *self = dev_id; 237 struct hwbus_priv *self = dev_id;
238 238
239 if (self->core) { 239 if (self->core) {
240 cw1200_spi_lock(self);
240 cw1200_irq_handler(self->core); 241 cw1200_irq_handler(self->core);
242 cw1200_spi_unlock(self);
241 return IRQ_HANDLED; 243 return IRQ_HANDLED;
242 } else { 244 } else {
243 return IRQ_NONE; 245 return IRQ_NONE;
diff --git a/drivers/net/wireless/iwlwifi/iwl-6000.c b/drivers/net/wireless/iwlwifi/iwl-6000.c
index 30d45e2fc193..8ac305be68f4 100644
--- a/drivers/net/wireless/iwlwifi/iwl-6000.c
+++ b/drivers/net/wireless/iwlwifi/iwl-6000.c
@@ -240,6 +240,12 @@ const struct iwl_cfg iwl6035_2agn_cfg = {
240 .ht_params = &iwl6000_ht_params, 240 .ht_params = &iwl6000_ht_params,
241}; 241};
242 242
243const struct iwl_cfg iwl6035_2agn_sff_cfg = {
244 .name = "Intel(R) Centrino(R) Ultimate-N 6235 AGN",
245 IWL_DEVICE_6035,
246 .ht_params = &iwl6000_ht_params,
247};
248
243const struct iwl_cfg iwl1030_bgn_cfg = { 249const struct iwl_cfg iwl1030_bgn_cfg = {
244 .name = "Intel(R) Centrino(R) Wireless-N 1030 BGN", 250 .name = "Intel(R) Centrino(R) Wireless-N 1030 BGN",
245 IWL_DEVICE_6030, 251 IWL_DEVICE_6030,
diff --git a/drivers/net/wireless/iwlwifi/iwl-config.h b/drivers/net/wireless/iwlwifi/iwl-config.h
index e4d370bff306..b03c25e14903 100644
--- a/drivers/net/wireless/iwlwifi/iwl-config.h
+++ b/drivers/net/wireless/iwlwifi/iwl-config.h
@@ -280,6 +280,7 @@ extern const struct iwl_cfg iwl2000_2bgn_cfg;
280extern const struct iwl_cfg iwl2000_2bgn_d_cfg; 280extern const struct iwl_cfg iwl2000_2bgn_d_cfg;
281extern const struct iwl_cfg iwl2030_2bgn_cfg; 281extern const struct iwl_cfg iwl2030_2bgn_cfg;
282extern const struct iwl_cfg iwl6035_2agn_cfg; 282extern const struct iwl_cfg iwl6035_2agn_cfg;
283extern const struct iwl_cfg iwl6035_2agn_sff_cfg;
283extern const struct iwl_cfg iwl105_bgn_cfg; 284extern const struct iwl_cfg iwl105_bgn_cfg;
284extern const struct iwl_cfg iwl105_bgn_d_cfg; 285extern const struct iwl_cfg iwl105_bgn_d_cfg;
285extern const struct iwl_cfg iwl135_bgn_cfg; 286extern const struct iwl_cfg iwl135_bgn_cfg;
diff --git a/drivers/net/wireless/iwlwifi/iwl-trans.h b/drivers/net/wireless/iwlwifi/iwl-trans.h
index dd57a36ecb10..80b47508647c 100644
--- a/drivers/net/wireless/iwlwifi/iwl-trans.h
+++ b/drivers/net/wireless/iwlwifi/iwl-trans.h
@@ -601,8 +601,10 @@ static inline int iwl_trans_send_cmd(struct iwl_trans *trans,
601{ 601{
602 int ret; 602 int ret;
603 603
604 WARN_ONCE(trans->state != IWL_TRANS_FW_ALIVE, 604 if (trans->state != IWL_TRANS_FW_ALIVE) {
605 "%s bad state = %d", __func__, trans->state); 605 IWL_ERR(trans, "%s bad state = %d", __func__, trans->state);
606 return -EIO;
607 }
606 608
607 if (!(cmd->flags & CMD_ASYNC)) 609 if (!(cmd->flags & CMD_ASYNC))
608 lock_map_acquire_read(&trans->sync_cmd_lockdep_map); 610 lock_map_acquire_read(&trans->sync_cmd_lockdep_map);
diff --git a/drivers/net/wireless/iwlwifi/mvm/power.c b/drivers/net/wireless/iwlwifi/mvm/power.c
index 21407a353a3b..d58e393324ef 100644
--- a/drivers/net/wireless/iwlwifi/mvm/power.c
+++ b/drivers/net/wireless/iwlwifi/mvm/power.c
@@ -273,7 +273,10 @@ static void iwl_mvm_power_build_cmd(struct iwl_mvm *mvm,
273 if (!mvmvif->queue_params[ac].uapsd) 273 if (!mvmvif->queue_params[ac].uapsd)
274 continue; 274 continue;
275 275
276 cmd->flags |= cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK); 276 if (mvm->cur_ucode != IWL_UCODE_WOWLAN)
277 cmd->flags |=
278 cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK);
279
277 cmd->uapsd_ac_flags |= BIT(ac); 280 cmd->uapsd_ac_flags |= BIT(ac);
278 281
279 /* QNDP TID - the highest TID with no admission control */ 282 /* QNDP TID - the highest TID with no admission control */
diff --git a/drivers/net/wireless/iwlwifi/mvm/scan.c b/drivers/net/wireless/iwlwifi/mvm/scan.c
index 9a7ab8495300..621fb71f282a 100644
--- a/drivers/net/wireless/iwlwifi/mvm/scan.c
+++ b/drivers/net/wireless/iwlwifi/mvm/scan.c
@@ -394,6 +394,11 @@ static bool iwl_mvm_scan_abort_notif(struct iwl_notif_wait_data *notif_wait,
394 return false; 394 return false;
395 } 395 }
396 396
397 /*
398 * If scan cannot be aborted, it means that we had a
399 * SCAN_COMPLETE_NOTIFICATION in the pipe and it called
400 * ieee80211_scan_completed already.
401 */
397 IWL_DEBUG_SCAN(mvm, "Scan cannot be aborted, exit now: %d\n", 402 IWL_DEBUG_SCAN(mvm, "Scan cannot be aborted, exit now: %d\n",
398 *resp); 403 *resp);
399 return true; 404 return true;
@@ -417,14 +422,19 @@ void iwl_mvm_cancel_scan(struct iwl_mvm *mvm)
417 SCAN_COMPLETE_NOTIFICATION }; 422 SCAN_COMPLETE_NOTIFICATION };
418 int ret; 423 int ret;
419 424
425 if (mvm->scan_status == IWL_MVM_SCAN_NONE)
426 return;
427
420 iwl_init_notification_wait(&mvm->notif_wait, &wait_scan_abort, 428 iwl_init_notification_wait(&mvm->notif_wait, &wait_scan_abort,
421 scan_abort_notif, 429 scan_abort_notif,
422 ARRAY_SIZE(scan_abort_notif), 430 ARRAY_SIZE(scan_abort_notif),
423 iwl_mvm_scan_abort_notif, NULL); 431 iwl_mvm_scan_abort_notif, NULL);
424 432
425 ret = iwl_mvm_send_cmd_pdu(mvm, SCAN_ABORT_CMD, CMD_SYNC, 0, NULL); 433 ret = iwl_mvm_send_cmd_pdu(mvm, SCAN_ABORT_CMD,
434 CMD_SYNC | CMD_SEND_IN_RFKILL, 0, NULL);
426 if (ret) { 435 if (ret) {
427 IWL_ERR(mvm, "Couldn't send SCAN_ABORT_CMD: %d\n", ret); 436 IWL_ERR(mvm, "Couldn't send SCAN_ABORT_CMD: %d\n", ret);
437 /* mac80211's state will be cleaned in the fw_restart flow */
428 goto out_remove_notif; 438 goto out_remove_notif;
429 } 439 }
430 440
diff --git a/drivers/net/wireless/iwlwifi/pcie/drv.c b/drivers/net/wireless/iwlwifi/pcie/drv.c
index dc02cb9792af..26108a1a29fa 100644
--- a/drivers/net/wireless/iwlwifi/pcie/drv.c
+++ b/drivers/net/wireless/iwlwifi/pcie/drv.c
@@ -139,13 +139,16 @@ static DEFINE_PCI_DEVICE_TABLE(iwl_hw_card_ids) = {
139 139
140/* 6x00 Series */ 140/* 6x00 Series */
141 {IWL_PCI_DEVICE(0x422B, 0x1101, iwl6000_3agn_cfg)}, 141 {IWL_PCI_DEVICE(0x422B, 0x1101, iwl6000_3agn_cfg)},
142 {IWL_PCI_DEVICE(0x422B, 0x1108, iwl6000_3agn_cfg)},
142 {IWL_PCI_DEVICE(0x422B, 0x1121, iwl6000_3agn_cfg)}, 143 {IWL_PCI_DEVICE(0x422B, 0x1121, iwl6000_3agn_cfg)},
144 {IWL_PCI_DEVICE(0x422B, 0x1128, iwl6000_3agn_cfg)},
143 {IWL_PCI_DEVICE(0x422C, 0x1301, iwl6000i_2agn_cfg)}, 145 {IWL_PCI_DEVICE(0x422C, 0x1301, iwl6000i_2agn_cfg)},
144 {IWL_PCI_DEVICE(0x422C, 0x1306, iwl6000i_2abg_cfg)}, 146 {IWL_PCI_DEVICE(0x422C, 0x1306, iwl6000i_2abg_cfg)},
145 {IWL_PCI_DEVICE(0x422C, 0x1307, iwl6000i_2bg_cfg)}, 147 {IWL_PCI_DEVICE(0x422C, 0x1307, iwl6000i_2bg_cfg)},
146 {IWL_PCI_DEVICE(0x422C, 0x1321, iwl6000i_2agn_cfg)}, 148 {IWL_PCI_DEVICE(0x422C, 0x1321, iwl6000i_2agn_cfg)},
147 {IWL_PCI_DEVICE(0x422C, 0x1326, iwl6000i_2abg_cfg)}, 149 {IWL_PCI_DEVICE(0x422C, 0x1326, iwl6000i_2abg_cfg)},
148 {IWL_PCI_DEVICE(0x4238, 0x1111, iwl6000_3agn_cfg)}, 150 {IWL_PCI_DEVICE(0x4238, 0x1111, iwl6000_3agn_cfg)},
151 {IWL_PCI_DEVICE(0x4238, 0x1118, iwl6000_3agn_cfg)},
149 {IWL_PCI_DEVICE(0x4239, 0x1311, iwl6000i_2agn_cfg)}, 152 {IWL_PCI_DEVICE(0x4239, 0x1311, iwl6000i_2agn_cfg)},
150 {IWL_PCI_DEVICE(0x4239, 0x1316, iwl6000i_2abg_cfg)}, 153 {IWL_PCI_DEVICE(0x4239, 0x1316, iwl6000i_2abg_cfg)},
151 154
@@ -153,12 +156,16 @@ static DEFINE_PCI_DEVICE_TABLE(iwl_hw_card_ids) = {
153 {IWL_PCI_DEVICE(0x0082, 0x1301, iwl6005_2agn_cfg)}, 156 {IWL_PCI_DEVICE(0x0082, 0x1301, iwl6005_2agn_cfg)},
154 {IWL_PCI_DEVICE(0x0082, 0x1306, iwl6005_2abg_cfg)}, 157 {IWL_PCI_DEVICE(0x0082, 0x1306, iwl6005_2abg_cfg)},
155 {IWL_PCI_DEVICE(0x0082, 0x1307, iwl6005_2bg_cfg)}, 158 {IWL_PCI_DEVICE(0x0082, 0x1307, iwl6005_2bg_cfg)},
159 {IWL_PCI_DEVICE(0x0082, 0x1308, iwl6005_2agn_cfg)},
156 {IWL_PCI_DEVICE(0x0082, 0x1321, iwl6005_2agn_cfg)}, 160 {IWL_PCI_DEVICE(0x0082, 0x1321, iwl6005_2agn_cfg)},
157 {IWL_PCI_DEVICE(0x0082, 0x1326, iwl6005_2abg_cfg)}, 161 {IWL_PCI_DEVICE(0x0082, 0x1326, iwl6005_2abg_cfg)},
162 {IWL_PCI_DEVICE(0x0082, 0x1328, iwl6005_2agn_cfg)},
158 {IWL_PCI_DEVICE(0x0085, 0x1311, iwl6005_2agn_cfg)}, 163 {IWL_PCI_DEVICE(0x0085, 0x1311, iwl6005_2agn_cfg)},
164 {IWL_PCI_DEVICE(0x0085, 0x1318, iwl6005_2agn_cfg)},
159 {IWL_PCI_DEVICE(0x0085, 0x1316, iwl6005_2abg_cfg)}, 165 {IWL_PCI_DEVICE(0x0085, 0x1316, iwl6005_2abg_cfg)},
160 {IWL_PCI_DEVICE(0x0082, 0xC020, iwl6005_2agn_sff_cfg)}, 166 {IWL_PCI_DEVICE(0x0082, 0xC020, iwl6005_2agn_sff_cfg)},
161 {IWL_PCI_DEVICE(0x0085, 0xC220, iwl6005_2agn_sff_cfg)}, 167 {IWL_PCI_DEVICE(0x0085, 0xC220, iwl6005_2agn_sff_cfg)},
168 {IWL_PCI_DEVICE(0x0085, 0xC228, iwl6005_2agn_sff_cfg)},
162 {IWL_PCI_DEVICE(0x0082, 0x4820, iwl6005_2agn_d_cfg)}, 169 {IWL_PCI_DEVICE(0x0082, 0x4820, iwl6005_2agn_d_cfg)},
163 {IWL_PCI_DEVICE(0x0082, 0x1304, iwl6005_2agn_mow1_cfg)},/* low 5GHz active */ 170 {IWL_PCI_DEVICE(0x0082, 0x1304, iwl6005_2agn_mow1_cfg)},/* low 5GHz active */
164 {IWL_PCI_DEVICE(0x0082, 0x1305, iwl6005_2agn_mow2_cfg)},/* high 5GHz active */ 171 {IWL_PCI_DEVICE(0x0082, 0x1305, iwl6005_2agn_mow2_cfg)},/* high 5GHz active */
@@ -240,8 +247,11 @@ static DEFINE_PCI_DEVICE_TABLE(iwl_hw_card_ids) = {
240 247
241/* 6x35 Series */ 248/* 6x35 Series */
242 {IWL_PCI_DEVICE(0x088E, 0x4060, iwl6035_2agn_cfg)}, 249 {IWL_PCI_DEVICE(0x088E, 0x4060, iwl6035_2agn_cfg)},
250 {IWL_PCI_DEVICE(0x088E, 0x406A, iwl6035_2agn_sff_cfg)},
243 {IWL_PCI_DEVICE(0x088F, 0x4260, iwl6035_2agn_cfg)}, 251 {IWL_PCI_DEVICE(0x088F, 0x4260, iwl6035_2agn_cfg)},
252 {IWL_PCI_DEVICE(0x088F, 0x426A, iwl6035_2agn_sff_cfg)},
244 {IWL_PCI_DEVICE(0x088E, 0x4460, iwl6035_2agn_cfg)}, 253 {IWL_PCI_DEVICE(0x088E, 0x4460, iwl6035_2agn_cfg)},
254 {IWL_PCI_DEVICE(0x088E, 0x446A, iwl6035_2agn_sff_cfg)},
245 {IWL_PCI_DEVICE(0x088E, 0x4860, iwl6035_2agn_cfg)}, 255 {IWL_PCI_DEVICE(0x088E, 0x4860, iwl6035_2agn_cfg)},
246 {IWL_PCI_DEVICE(0x088F, 0x5260, iwl6035_2agn_cfg)}, 256 {IWL_PCI_DEVICE(0x088F, 0x5260, iwl6035_2agn_cfg)},
247 257
@@ -260,54 +270,86 @@ static DEFINE_PCI_DEVICE_TABLE(iwl_hw_card_ids) = {
260#if IS_ENABLED(CONFIG_IWLMVM) 270#if IS_ENABLED(CONFIG_IWLMVM)
261/* 7000 Series */ 271/* 7000 Series */
262 {IWL_PCI_DEVICE(0x08B1, 0x4070, iwl7260_2ac_cfg)}, 272 {IWL_PCI_DEVICE(0x08B1, 0x4070, iwl7260_2ac_cfg)},
273 {IWL_PCI_DEVICE(0x08B1, 0x4072, iwl7260_2ac_cfg)},
263 {IWL_PCI_DEVICE(0x08B1, 0x4170, iwl7260_2ac_cfg)}, 274 {IWL_PCI_DEVICE(0x08B1, 0x4170, iwl7260_2ac_cfg)},
264 {IWL_PCI_DEVICE(0x08B1, 0x4060, iwl7260_2n_cfg)}, 275 {IWL_PCI_DEVICE(0x08B1, 0x4060, iwl7260_2n_cfg)},
276 {IWL_PCI_DEVICE(0x08B1, 0x406A, iwl7260_2n_cfg)},
265 {IWL_PCI_DEVICE(0x08B1, 0x4160, iwl7260_2n_cfg)}, 277 {IWL_PCI_DEVICE(0x08B1, 0x4160, iwl7260_2n_cfg)},
266 {IWL_PCI_DEVICE(0x08B1, 0x4062, iwl7260_n_cfg)}, 278 {IWL_PCI_DEVICE(0x08B1, 0x4062, iwl7260_n_cfg)},
267 {IWL_PCI_DEVICE(0x08B1, 0x4162, iwl7260_n_cfg)}, 279 {IWL_PCI_DEVICE(0x08B1, 0x4162, iwl7260_n_cfg)},
268 {IWL_PCI_DEVICE(0x08B2, 0x4270, iwl7260_2ac_cfg)}, 280 {IWL_PCI_DEVICE(0x08B2, 0x4270, iwl7260_2ac_cfg)},
281 {IWL_PCI_DEVICE(0x08B2, 0x4272, iwl7260_2ac_cfg)},
269 {IWL_PCI_DEVICE(0x08B2, 0x4260, iwl7260_2n_cfg)}, 282 {IWL_PCI_DEVICE(0x08B2, 0x4260, iwl7260_2n_cfg)},
283 {IWL_PCI_DEVICE(0x08B2, 0x426A, iwl7260_2n_cfg)},
270 {IWL_PCI_DEVICE(0x08B2, 0x4262, iwl7260_n_cfg)}, 284 {IWL_PCI_DEVICE(0x08B2, 0x4262, iwl7260_n_cfg)},
271 {IWL_PCI_DEVICE(0x08B1, 0x4470, iwl7260_2ac_cfg)}, 285 {IWL_PCI_DEVICE(0x08B1, 0x4470, iwl7260_2ac_cfg)},
286 {IWL_PCI_DEVICE(0x08B1, 0x4472, iwl7260_2ac_cfg)},
272 {IWL_PCI_DEVICE(0x08B1, 0x4460, iwl7260_2n_cfg)}, 287 {IWL_PCI_DEVICE(0x08B1, 0x4460, iwl7260_2n_cfg)},
288 {IWL_PCI_DEVICE(0x08B1, 0x446A, iwl7260_2n_cfg)},
273 {IWL_PCI_DEVICE(0x08B1, 0x4462, iwl7260_n_cfg)}, 289 {IWL_PCI_DEVICE(0x08B1, 0x4462, iwl7260_n_cfg)},
274 {IWL_PCI_DEVICE(0x08B1, 0x4870, iwl7260_2ac_cfg)}, 290 {IWL_PCI_DEVICE(0x08B1, 0x4870, iwl7260_2ac_cfg)},
275 {IWL_PCI_DEVICE(0x08B1, 0x486E, iwl7260_2ac_cfg)}, 291 {IWL_PCI_DEVICE(0x08B1, 0x486E, iwl7260_2ac_cfg)},
276 {IWL_PCI_DEVICE(0x08B1, 0x4A70, iwl7260_2ac_cfg_high_temp)}, 292 {IWL_PCI_DEVICE(0x08B1, 0x4A70, iwl7260_2ac_cfg_high_temp)},
277 {IWL_PCI_DEVICE(0x08B1, 0x4A6E, iwl7260_2ac_cfg_high_temp)}, 293 {IWL_PCI_DEVICE(0x08B1, 0x4A6E, iwl7260_2ac_cfg_high_temp)},
278 {IWL_PCI_DEVICE(0x08B1, 0x4A6C, iwl7260_2ac_cfg_high_temp)}, 294 {IWL_PCI_DEVICE(0x08B1, 0x4A6C, iwl7260_2ac_cfg_high_temp)},
295 {IWL_PCI_DEVICE(0x08B1, 0x4570, iwl7260_2ac_cfg)},
296 {IWL_PCI_DEVICE(0x08B1, 0x4560, iwl7260_2n_cfg)},
297 {IWL_PCI_DEVICE(0x08B2, 0x4370, iwl7260_2ac_cfg)},
298 {IWL_PCI_DEVICE(0x08B2, 0x4360, iwl7260_2n_cfg)},
299 {IWL_PCI_DEVICE(0x08B1, 0x5070, iwl7260_2ac_cfg)},
279 {IWL_PCI_DEVICE(0x08B1, 0x4020, iwl7260_2n_cfg)}, 300 {IWL_PCI_DEVICE(0x08B1, 0x4020, iwl7260_2n_cfg)},
301 {IWL_PCI_DEVICE(0x08B1, 0x402A, iwl7260_2n_cfg)},
280 {IWL_PCI_DEVICE(0x08B2, 0x4220, iwl7260_2n_cfg)}, 302 {IWL_PCI_DEVICE(0x08B2, 0x4220, iwl7260_2n_cfg)},
281 {IWL_PCI_DEVICE(0x08B1, 0x4420, iwl7260_2n_cfg)}, 303 {IWL_PCI_DEVICE(0x08B1, 0x4420, iwl7260_2n_cfg)},
282 {IWL_PCI_DEVICE(0x08B1, 0xC070, iwl7260_2ac_cfg)}, 304 {IWL_PCI_DEVICE(0x08B1, 0xC070, iwl7260_2ac_cfg)},
305 {IWL_PCI_DEVICE(0x08B1, 0xC072, iwl7260_2ac_cfg)},
283 {IWL_PCI_DEVICE(0x08B1, 0xC170, iwl7260_2ac_cfg)}, 306 {IWL_PCI_DEVICE(0x08B1, 0xC170, iwl7260_2ac_cfg)},
284 {IWL_PCI_DEVICE(0x08B1, 0xC060, iwl7260_2n_cfg)}, 307 {IWL_PCI_DEVICE(0x08B1, 0xC060, iwl7260_2n_cfg)},
308 {IWL_PCI_DEVICE(0x08B1, 0xC06A, iwl7260_2n_cfg)},
285 {IWL_PCI_DEVICE(0x08B1, 0xC160, iwl7260_2n_cfg)}, 309 {IWL_PCI_DEVICE(0x08B1, 0xC160, iwl7260_2n_cfg)},
286 {IWL_PCI_DEVICE(0x08B1, 0xC062, iwl7260_n_cfg)}, 310 {IWL_PCI_DEVICE(0x08B1, 0xC062, iwl7260_n_cfg)},
287 {IWL_PCI_DEVICE(0x08B1, 0xC162, iwl7260_n_cfg)}, 311 {IWL_PCI_DEVICE(0x08B1, 0xC162, iwl7260_n_cfg)},
312 {IWL_PCI_DEVICE(0x08B1, 0xC770, iwl7260_2ac_cfg)},
313 {IWL_PCI_DEVICE(0x08B1, 0xC760, iwl7260_2n_cfg)},
288 {IWL_PCI_DEVICE(0x08B2, 0xC270, iwl7260_2ac_cfg)}, 314 {IWL_PCI_DEVICE(0x08B2, 0xC270, iwl7260_2ac_cfg)},
315 {IWL_PCI_DEVICE(0x08B2, 0xC272, iwl7260_2ac_cfg)},
289 {IWL_PCI_DEVICE(0x08B2, 0xC260, iwl7260_2n_cfg)}, 316 {IWL_PCI_DEVICE(0x08B2, 0xC260, iwl7260_2n_cfg)},
317 {IWL_PCI_DEVICE(0x08B2, 0xC26A, iwl7260_n_cfg)},
290 {IWL_PCI_DEVICE(0x08B2, 0xC262, iwl7260_n_cfg)}, 318 {IWL_PCI_DEVICE(0x08B2, 0xC262, iwl7260_n_cfg)},
291 {IWL_PCI_DEVICE(0x08B1, 0xC470, iwl7260_2ac_cfg)}, 319 {IWL_PCI_DEVICE(0x08B1, 0xC470, iwl7260_2ac_cfg)},
320 {IWL_PCI_DEVICE(0x08B1, 0xC472, iwl7260_2ac_cfg)},
292 {IWL_PCI_DEVICE(0x08B1, 0xC460, iwl7260_2n_cfg)}, 321 {IWL_PCI_DEVICE(0x08B1, 0xC460, iwl7260_2n_cfg)},
293 {IWL_PCI_DEVICE(0x08B1, 0xC462, iwl7260_n_cfg)}, 322 {IWL_PCI_DEVICE(0x08B1, 0xC462, iwl7260_n_cfg)},
323 {IWL_PCI_DEVICE(0x08B1, 0xC570, iwl7260_2ac_cfg)},
324 {IWL_PCI_DEVICE(0x08B1, 0xC560, iwl7260_2n_cfg)},
325 {IWL_PCI_DEVICE(0x08B2, 0xC370, iwl7260_2ac_cfg)},
326 {IWL_PCI_DEVICE(0x08B1, 0xC360, iwl7260_2n_cfg)},
294 {IWL_PCI_DEVICE(0x08B1, 0xC020, iwl7260_2n_cfg)}, 327 {IWL_PCI_DEVICE(0x08B1, 0xC020, iwl7260_2n_cfg)},
328 {IWL_PCI_DEVICE(0x08B1, 0xC02A, iwl7260_2n_cfg)},
295 {IWL_PCI_DEVICE(0x08B2, 0xC220, iwl7260_2n_cfg)}, 329 {IWL_PCI_DEVICE(0x08B2, 0xC220, iwl7260_2n_cfg)},
296 {IWL_PCI_DEVICE(0x08B1, 0xC420, iwl7260_2n_cfg)}, 330 {IWL_PCI_DEVICE(0x08B1, 0xC420, iwl7260_2n_cfg)},
297 331
298/* 3160 Series */ 332/* 3160 Series */
299 {IWL_PCI_DEVICE(0x08B3, 0x0070, iwl3160_2ac_cfg)}, 333 {IWL_PCI_DEVICE(0x08B3, 0x0070, iwl3160_2ac_cfg)},
334 {IWL_PCI_DEVICE(0x08B3, 0x0072, iwl3160_2ac_cfg)},
300 {IWL_PCI_DEVICE(0x08B3, 0x0170, iwl3160_2ac_cfg)}, 335 {IWL_PCI_DEVICE(0x08B3, 0x0170, iwl3160_2ac_cfg)},
336 {IWL_PCI_DEVICE(0x08B3, 0x0172, iwl3160_2ac_cfg)},
301 {IWL_PCI_DEVICE(0x08B3, 0x0060, iwl3160_2n_cfg)}, 337 {IWL_PCI_DEVICE(0x08B3, 0x0060, iwl3160_2n_cfg)},
302 {IWL_PCI_DEVICE(0x08B3, 0x0062, iwl3160_n_cfg)}, 338 {IWL_PCI_DEVICE(0x08B3, 0x0062, iwl3160_n_cfg)},
303 {IWL_PCI_DEVICE(0x08B4, 0x0270, iwl3160_2ac_cfg)}, 339 {IWL_PCI_DEVICE(0x08B4, 0x0270, iwl3160_2ac_cfg)},
340 {IWL_PCI_DEVICE(0x08B4, 0x0272, iwl3160_2ac_cfg)},
304 {IWL_PCI_DEVICE(0x08B3, 0x0470, iwl3160_2ac_cfg)}, 341 {IWL_PCI_DEVICE(0x08B3, 0x0470, iwl3160_2ac_cfg)},
342 {IWL_PCI_DEVICE(0x08B3, 0x0472, iwl3160_2ac_cfg)},
343 {IWL_PCI_DEVICE(0x08B4, 0x0370, iwl3160_2ac_cfg)},
305 {IWL_PCI_DEVICE(0x08B3, 0x8070, iwl3160_2ac_cfg)}, 344 {IWL_PCI_DEVICE(0x08B3, 0x8070, iwl3160_2ac_cfg)},
345 {IWL_PCI_DEVICE(0x08B3, 0x8072, iwl3160_2ac_cfg)},
306 {IWL_PCI_DEVICE(0x08B3, 0x8170, iwl3160_2ac_cfg)}, 346 {IWL_PCI_DEVICE(0x08B3, 0x8170, iwl3160_2ac_cfg)},
347 {IWL_PCI_DEVICE(0x08B3, 0x8172, iwl3160_2ac_cfg)},
307 {IWL_PCI_DEVICE(0x08B3, 0x8060, iwl3160_2n_cfg)}, 348 {IWL_PCI_DEVICE(0x08B3, 0x8060, iwl3160_2n_cfg)},
308 {IWL_PCI_DEVICE(0x08B3, 0x8062, iwl3160_n_cfg)}, 349 {IWL_PCI_DEVICE(0x08B3, 0x8062, iwl3160_n_cfg)},
309 {IWL_PCI_DEVICE(0x08B4, 0x8270, iwl3160_2ac_cfg)}, 350 {IWL_PCI_DEVICE(0x08B4, 0x8270, iwl3160_2ac_cfg)},
310 {IWL_PCI_DEVICE(0x08B3, 0x8470, iwl3160_2ac_cfg)}, 351 {IWL_PCI_DEVICE(0x08B3, 0x8470, iwl3160_2ac_cfg)},
352 {IWL_PCI_DEVICE(0x08B3, 0x8570, iwl3160_2ac_cfg)},
311#endif /* CONFIG_IWLMVM */ 353#endif /* CONFIG_IWLMVM */
312 354
313 {0} 355 {0}
diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
index bad95d28d50d..c3f904d422b0 100644
--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
@@ -1401,6 +1401,10 @@ struct iwl_trans *iwl_trans_pcie_alloc(struct pci_dev *pdev,
1401 spin_lock_init(&trans_pcie->reg_lock); 1401 spin_lock_init(&trans_pcie->reg_lock);
1402 init_waitqueue_head(&trans_pcie->ucode_write_waitq); 1402 init_waitqueue_head(&trans_pcie->ucode_write_waitq);
1403 1403
1404 err = pci_enable_device(pdev);
1405 if (err)
1406 goto out_no_pci;
1407
1404 if (!cfg->base_params->pcie_l1_allowed) { 1408 if (!cfg->base_params->pcie_l1_allowed) {
1405 /* 1409 /*
1406 * W/A - seems to solve weird behavior. We need to remove this 1410 * W/A - seems to solve weird behavior. We need to remove this
@@ -1412,10 +1416,6 @@ struct iwl_trans *iwl_trans_pcie_alloc(struct pci_dev *pdev,
1412 PCIE_LINK_STATE_CLKPM); 1416 PCIE_LINK_STATE_CLKPM);
1413 } 1417 }
1414 1418
1415 err = pci_enable_device(pdev);
1416 if (err)
1417 goto out_no_pci;
1418
1419 pci_set_master(pdev); 1419 pci_set_master(pdev);
1420 1420
1421 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(36)); 1421 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(36));
diff --git a/drivers/net/wireless/iwlwifi/pcie/tx.c b/drivers/net/wireless/iwlwifi/pcie/tx.c
index f45eb29c2ede..1424335163b9 100644
--- a/drivers/net/wireless/iwlwifi/pcie/tx.c
+++ b/drivers/net/wireless/iwlwifi/pcie/tx.c
@@ -1102,6 +1102,8 @@ void iwl_trans_pcie_txq_enable(struct iwl_trans *trans, int txq_id, int fifo,
1102 * non-AGG queue. 1102 * non-AGG queue.
1103 */ 1103 */
1104 iwl_clear_bits_prph(trans, SCD_AGGR_SEL, BIT(txq_id)); 1104 iwl_clear_bits_prph(trans, SCD_AGGR_SEL, BIT(txq_id));
1105
1106 ssn = trans_pcie->txq[txq_id].q.read_ptr;
1105 } 1107 }
1106 1108
1107 /* Place first TFD at index corresponding to start sequence number. 1109 /* Place first TFD at index corresponding to start sequence number.
diff --git a/drivers/net/wireless/mwifiex/join.c b/drivers/net/wireless/mwifiex/join.c
index 9d7c0e6c4fc7..37f873bb342f 100644
--- a/drivers/net/wireless/mwifiex/join.c
+++ b/drivers/net/wireless/mwifiex/join.c
@@ -1422,13 +1422,19 @@ static int mwifiex_deauthenticate_infra(struct mwifiex_private *priv, u8 *mac)
1422 */ 1422 */
1423int mwifiex_deauthenticate(struct mwifiex_private *priv, u8 *mac) 1423int mwifiex_deauthenticate(struct mwifiex_private *priv, u8 *mac)
1424{ 1424{
1425 int ret = 0;
1426
1425 if (!priv->media_connected) 1427 if (!priv->media_connected)
1426 return 0; 1428 return 0;
1427 1429
1428 switch (priv->bss_mode) { 1430 switch (priv->bss_mode) {
1429 case NL80211_IFTYPE_STATION: 1431 case NL80211_IFTYPE_STATION:
1430 case NL80211_IFTYPE_P2P_CLIENT: 1432 case NL80211_IFTYPE_P2P_CLIENT:
1431 return mwifiex_deauthenticate_infra(priv, mac); 1433 ret = mwifiex_deauthenticate_infra(priv, mac);
1434 if (ret)
1435 cfg80211_disconnected(priv->netdev, 0, NULL, 0,
1436 GFP_KERNEL);
1437 break;
1432 case NL80211_IFTYPE_ADHOC: 1438 case NL80211_IFTYPE_ADHOC:
1433 return mwifiex_send_cmd_sync(priv, 1439 return mwifiex_send_cmd_sync(priv,
1434 HostCmd_CMD_802_11_AD_HOC_STOP, 1440 HostCmd_CMD_802_11_AD_HOC_STOP,
@@ -1440,7 +1446,7 @@ int mwifiex_deauthenticate(struct mwifiex_private *priv, u8 *mac)
1440 break; 1446 break;
1441 } 1447 }
1442 1448
1443 return 0; 1449 return ret;
1444} 1450}
1445EXPORT_SYMBOL_GPL(mwifiex_deauthenticate); 1451EXPORT_SYMBOL_GPL(mwifiex_deauthenticate);
1446 1452
diff --git a/drivers/net/wireless/mwifiex/main.c b/drivers/net/wireless/mwifiex/main.c
index fd778337deee..c2b91f566e05 100644
--- a/drivers/net/wireless/mwifiex/main.c
+++ b/drivers/net/wireless/mwifiex/main.c
@@ -358,10 +358,12 @@ process_start:
358 } 358 }
359 } while (true); 359 } while (true);
360 360
361 if ((adapter->int_status) || IS_CARD_RX_RCVD(adapter)) 361 spin_lock_irqsave(&adapter->main_proc_lock, flags);
362 if ((adapter->int_status) || IS_CARD_RX_RCVD(adapter)) {
363 spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
362 goto process_start; 364 goto process_start;
365 }
363 366
364 spin_lock_irqsave(&adapter->main_proc_lock, flags);
365 adapter->mwifiex_processing = false; 367 adapter->mwifiex_processing = false;
366 spin_unlock_irqrestore(&adapter->main_proc_lock, flags); 368 spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
367 369
diff --git a/drivers/net/wireless/mwifiex/sta_event.c b/drivers/net/wireless/mwifiex/sta_event.c
index 8b057524b252..8c351f71f72f 100644
--- a/drivers/net/wireless/mwifiex/sta_event.c
+++ b/drivers/net/wireless/mwifiex/sta_event.c
@@ -118,7 +118,8 @@ mwifiex_reset_connect_state(struct mwifiex_private *priv, u16 reason_code)
118 dev_dbg(adapter->dev, 118 dev_dbg(adapter->dev,
119 "info: successfully disconnected from %pM: reason code %d\n", 119 "info: successfully disconnected from %pM: reason code %d\n",
120 priv->cfg_bssid, reason_code); 120 priv->cfg_bssid, reason_code);
121 if (priv->bss_mode == NL80211_IFTYPE_STATION) { 121 if (priv->bss_mode == NL80211_IFTYPE_STATION ||
122 priv->bss_mode == NL80211_IFTYPE_P2P_CLIENT) {
122 cfg80211_disconnected(priv->netdev, reason_code, NULL, 0, 123 cfg80211_disconnected(priv->netdev, reason_code, NULL, 0,
123 GFP_KERNEL); 124 GFP_KERNEL);
124 } 125 }
diff --git a/drivers/net/wireless/rt2x00/rt2x00pci.c b/drivers/net/wireless/rt2x00/rt2x00pci.c
index 76d95deb274b..dc49e525ae5e 100644
--- a/drivers/net/wireless/rt2x00/rt2x00pci.c
+++ b/drivers/net/wireless/rt2x00/rt2x00pci.c
@@ -105,13 +105,11 @@ int rt2x00pci_probe(struct pci_dev *pci_dev, const struct rt2x00_ops *ops)
105 goto exit_release_regions; 105 goto exit_release_regions;
106 } 106 }
107 107
108 pci_enable_msi(pci_dev);
109
110 hw = ieee80211_alloc_hw(sizeof(struct rt2x00_dev), ops->hw); 108 hw = ieee80211_alloc_hw(sizeof(struct rt2x00_dev), ops->hw);
111 if (!hw) { 109 if (!hw) {
112 rt2x00_probe_err("Failed to allocate hardware\n"); 110 rt2x00_probe_err("Failed to allocate hardware\n");
113 retval = -ENOMEM; 111 retval = -ENOMEM;
114 goto exit_disable_msi; 112 goto exit_release_regions;
115 } 113 }
116 114
117 pci_set_drvdata(pci_dev, hw); 115 pci_set_drvdata(pci_dev, hw);
@@ -152,9 +150,6 @@ exit_free_reg:
152exit_free_device: 150exit_free_device:
153 ieee80211_free_hw(hw); 151 ieee80211_free_hw(hw);
154 152
155exit_disable_msi:
156 pci_disable_msi(pci_dev);
157
158exit_release_regions: 153exit_release_regions:
159 pci_release_regions(pci_dev); 154 pci_release_regions(pci_dev);
160 155
@@ -179,8 +174,6 @@ void rt2x00pci_remove(struct pci_dev *pci_dev)
179 rt2x00pci_free_reg(rt2x00dev); 174 rt2x00pci_free_reg(rt2x00dev);
180 ieee80211_free_hw(hw); 175 ieee80211_free_hw(hw);
181 176
182 pci_disable_msi(pci_dev);
183
184 /* 177 /*
185 * Free the PCI device data. 178 * Free the PCI device data.
186 */ 179 */
diff --git a/drivers/net/wireless/rtlwifi/rtl8192cu/trx.c b/drivers/net/wireless/rtlwifi/rtl8192cu/trx.c
index 763cf1defab5..5a060e537fbe 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192cu/trx.c
+++ b/drivers/net/wireless/rtlwifi/rtl8192cu/trx.c
@@ -343,7 +343,8 @@ bool rtl92cu_rx_query_desc(struct ieee80211_hw *hw,
343 (bool)GET_RX_DESC_PAGGR(pdesc)); 343 (bool)GET_RX_DESC_PAGGR(pdesc));
344 rx_status->mactime = GET_RX_DESC_TSFL(pdesc); 344 rx_status->mactime = GET_RX_DESC_TSFL(pdesc);
345 if (phystatus) { 345 if (phystatus) {
346 p_drvinfo = (struct rx_fwinfo_92c *)(pdesc + RTL_RX_DESC_SIZE); 346 p_drvinfo = (struct rx_fwinfo_92c *)(skb->data +
347 stats->rx_bufshift);
347 rtl92c_translate_rx_signal_stuff(hw, skb, stats, pdesc, 348 rtl92c_translate_rx_signal_stuff(hw, skb, stats, pdesc,
348 p_drvinfo); 349 p_drvinfo);
349 } 350 }
diff --git a/drivers/net/xen-netback/common.h b/drivers/net/xen-netback/common.h
index 5715318d6bab..400fea1de080 100644
--- a/drivers/net/xen-netback/common.h
+++ b/drivers/net/xen-netback/common.h
@@ -163,6 +163,7 @@ struct xenvif {
163 unsigned long credit_usec; 163 unsigned long credit_usec;
164 unsigned long remaining_credit; 164 unsigned long remaining_credit;
165 struct timer_list credit_timeout; 165 struct timer_list credit_timeout;
166 u64 credit_window_start;
166 167
167 /* Statistics */ 168 /* Statistics */
168 unsigned long rx_gso_checksum_fixup; 169 unsigned long rx_gso_checksum_fixup;
diff --git a/drivers/net/xen-netback/interface.c b/drivers/net/xen-netback/interface.c
index 01bb854c7f62..459935a6bfae 100644
--- a/drivers/net/xen-netback/interface.c
+++ b/drivers/net/xen-netback/interface.c
@@ -312,8 +312,7 @@ struct xenvif *xenvif_alloc(struct device *parent, domid_t domid,
312 vif->credit_bytes = vif->remaining_credit = ~0UL; 312 vif->credit_bytes = vif->remaining_credit = ~0UL;
313 vif->credit_usec = 0UL; 313 vif->credit_usec = 0UL;
314 init_timer(&vif->credit_timeout); 314 init_timer(&vif->credit_timeout);
315 /* Initialize 'expires' now: it's used to track the credit window. */ 315 vif->credit_window_start = get_jiffies_64();
316 vif->credit_timeout.expires = jiffies;
317 316
318 dev->netdev_ops = &xenvif_netdev_ops; 317 dev->netdev_ops = &xenvif_netdev_ops;
319 dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO; 318 dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO;
diff --git a/drivers/net/xen-netback/netback.c b/drivers/net/xen-netback/netback.c
index f3e591c611de..900da4b243ad 100644
--- a/drivers/net/xen-netback/netback.c
+++ b/drivers/net/xen-netback/netback.c
@@ -1185,9 +1185,8 @@ out:
1185 1185
1186static bool tx_credit_exceeded(struct xenvif *vif, unsigned size) 1186static bool tx_credit_exceeded(struct xenvif *vif, unsigned size)
1187{ 1187{
1188 unsigned long now = jiffies; 1188 u64 now = get_jiffies_64();
1189 unsigned long next_credit = 1189 u64 next_credit = vif->credit_window_start +
1190 vif->credit_timeout.expires +
1191 msecs_to_jiffies(vif->credit_usec / 1000); 1190 msecs_to_jiffies(vif->credit_usec / 1000);
1192 1191
1193 /* Timer could already be pending in rare cases. */ 1192 /* Timer could already be pending in rare cases. */
@@ -1195,8 +1194,8 @@ static bool tx_credit_exceeded(struct xenvif *vif, unsigned size)
1195 return true; 1194 return true;
1196 1195
1197 /* Passed the point where we can replenish credit? */ 1196 /* Passed the point where we can replenish credit? */
1198 if (time_after_eq(now, next_credit)) { 1197 if (time_after_eq64(now, next_credit)) {
1199 vif->credit_timeout.expires = now; 1198 vif->credit_window_start = now;
1200 tx_add_credit(vif); 1199 tx_add_credit(vif);
1201 } 1200 }
1202 1201
@@ -1208,6 +1207,7 @@ static bool tx_credit_exceeded(struct xenvif *vif, unsigned size)
1208 tx_credit_callback; 1207 tx_credit_callback;
1209 mod_timer(&vif->credit_timeout, 1208 mod_timer(&vif->credit_timeout,
1210 next_credit); 1209 next_credit);
1210 vif->credit_window_start = next_credit;
1211 1211
1212 return true; 1212 return true;
1213 } 1213 }
diff --git a/drivers/net/xen-netback/xenbus.c b/drivers/net/xen-netback/xenbus.c
index b45bce20ad76..1b08d8798372 100644
--- a/drivers/net/xen-netback/xenbus.c
+++ b/drivers/net/xen-netback/xenbus.c
@@ -39,11 +39,15 @@ static int connect_rings(struct backend_info *);
39static void connect(struct backend_info *); 39static void connect(struct backend_info *);
40static void backend_create_xenvif(struct backend_info *be); 40static void backend_create_xenvif(struct backend_info *be);
41static void unregister_hotplug_status_watch(struct backend_info *be); 41static void unregister_hotplug_status_watch(struct backend_info *be);
42static void set_backend_state(struct backend_info *be,
43 enum xenbus_state state);
42 44
43static int netback_remove(struct xenbus_device *dev) 45static int netback_remove(struct xenbus_device *dev)
44{ 46{
45 struct backend_info *be = dev_get_drvdata(&dev->dev); 47 struct backend_info *be = dev_get_drvdata(&dev->dev);
46 48
49 set_backend_state(be, XenbusStateClosed);
50
47 unregister_hotplug_status_watch(be); 51 unregister_hotplug_status_watch(be);
48 if (be->vif) { 52 if (be->vif) {
49 kobject_uevent(&dev->dev.kobj, KOBJ_OFFLINE); 53 kobject_uevent(&dev->dev.kobj, KOBJ_OFFLINE);
diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c
index be12fbfcae10..1ea75236a15f 100644
--- a/drivers/pci/hotplug/acpiphp_glue.c
+++ b/drivers/pci/hotplug/acpiphp_glue.c
@@ -552,9 +552,8 @@ static void __ref enable_slot(struct acpiphp_slot *slot)
552 struct acpiphp_func *func; 552 struct acpiphp_func *func;
553 int max, pass; 553 int max, pass;
554 LIST_HEAD(add_list); 554 LIST_HEAD(add_list);
555 int nr_found;
556 555
557 nr_found = acpiphp_rescan_slot(slot); 556 acpiphp_rescan_slot(slot);
558 max = acpiphp_max_busnr(bus); 557 max = acpiphp_max_busnr(bus);
559 for (pass = 0; pass < 2; pass++) { 558 for (pass = 0; pass < 2; pass++) {
560 list_for_each_entry(dev, &bus->devices, bus_list) { 559 list_for_each_entry(dev, &bus->devices, bus_list) {
@@ -574,9 +573,6 @@ static void __ref enable_slot(struct acpiphp_slot *slot)
574 } 573 }
575 } 574 }
576 __pci_bus_assign_resources(bus, &add_list, NULL); 575 __pci_bus_assign_resources(bus, &add_list, NULL);
577 /* Nothing more to do here if there are no new devices on this bus. */
578 if (!nr_found && (slot->flags & SLOT_ENABLED))
579 return;
580 576
581 acpiphp_sanitize_bus(bus); 577 acpiphp_sanitize_bus(bus);
582 acpiphp_set_hpp_values(bus); 578 acpiphp_set_hpp_values(bus);
diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
new file mode 100644
index 000000000000..a344f3d52361
--- /dev/null
+++ b/drivers/phy/Kconfig
@@ -0,0 +1,54 @@
1#
2# PHY
3#
4
5menu "PHY Subsystem"
6
7config GENERIC_PHY
8 tristate "PHY Core"
9 help
10 Generic PHY support.
11
12 This framework is designed to provide a generic interface for PHY
13 devices present in the kernel. This layer will have the generic
14 API by which phy drivers can create PHY using the phy framework and
15 phy users can obtain reference to the PHY. All the users of this
16 framework should select this config.
17
18config PHY_EXYNOS_MIPI_VIDEO
19 tristate "S5P/EXYNOS SoC series MIPI CSI-2/DSI PHY driver"
20 help
21 Support for MIPI CSI-2 and MIPI DSI DPHY found on Samsung S5P
22 and EXYNOS SoCs.
23
24config OMAP_USB2
25 tristate "OMAP USB2 PHY Driver"
26 depends on ARCH_OMAP2PLUS
27 select GENERIC_PHY
28 select USB_PHY
29 select OMAP_CONTROL_USB
30 help
31 Enable this to support the transceiver that is part of SOC. This
32 driver takes care of all the PHY functionality apart from comparator.
33 The USB OTG controller communicates with the comparator using this
34 driver.
35
36config TWL4030_USB
37 tristate "TWL4030 USB Transceiver Driver"
38 depends on TWL4030_CORE && REGULATOR_TWL4030 && USB_MUSB_OMAP2PLUS
39 select GENERIC_PHY
40 select USB_PHY
41 help
42 Enable this to support the USB OTG transceiver on TWL4030
43 family chips (including the TWL5030 and TPS659x0 devices).
44 This transceiver supports high and full speed devices plus,
45 in host mode, low speed.
46
47config PHY_EXYNOS_DP_VIDEO
48 tristate "EXYNOS SoC series Display Port PHY driver"
49 depends on OF
50 select GENERIC_PHY
51 help
52 Support for Display Port PHY found on Samsung EXYNOS SoCs.
53
54endmenu
diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
new file mode 100644
index 000000000000..d0caae9cfb83
--- /dev/null
+++ b/drivers/phy/Makefile
@@ -0,0 +1,9 @@
1#
2# Makefile for the phy drivers.
3#
4
5obj-$(CONFIG_GENERIC_PHY) += phy-core.o
6obj-$(CONFIG_PHY_EXYNOS_DP_VIDEO) += phy-exynos-dp-video.o
7obj-$(CONFIG_PHY_EXYNOS_MIPI_VIDEO) += phy-exynos-mipi-video.o
8obj-$(CONFIG_OMAP_USB2) += phy-omap-usb2.o
9obj-$(CONFIG_TWL4030_USB) += phy-twl4030-usb.o
diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
new file mode 100644
index 000000000000..03cf8fb81554
--- /dev/null
+++ b/drivers/phy/phy-core.c
@@ -0,0 +1,698 @@
1/*
2 * phy-core.c -- Generic Phy framework.
3 *
4 * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com
5 *
6 * Author: Kishon Vijay Abraham I <kishon@ti.com>
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
12 */
13
14#include <linux/kernel.h>
15#include <linux/export.h>
16#include <linux/module.h>
17#include <linux/err.h>
18#include <linux/device.h>
19#include <linux/slab.h>
20#include <linux/of.h>
21#include <linux/phy/phy.h>
22#include <linux/idr.h>
23#include <linux/pm_runtime.h>
24
25static struct class *phy_class;
26static DEFINE_MUTEX(phy_provider_mutex);
27static LIST_HEAD(phy_provider_list);
28static DEFINE_IDA(phy_ida);
29
30static void devm_phy_release(struct device *dev, void *res)
31{
32 struct phy *phy = *(struct phy **)res;
33
34 phy_put(phy);
35}
36
37static void devm_phy_provider_release(struct device *dev, void *res)
38{
39 struct phy_provider *phy_provider = *(struct phy_provider **)res;
40
41 of_phy_provider_unregister(phy_provider);
42}
43
44static void devm_phy_consume(struct device *dev, void *res)
45{
46 struct phy *phy = *(struct phy **)res;
47
48 phy_destroy(phy);
49}
50
51static int devm_phy_match(struct device *dev, void *res, void *match_data)
52{
53 return res == match_data;
54}
55
56static struct phy *phy_lookup(struct device *device, const char *port)
57{
58 unsigned int count;
59 struct phy *phy;
60 struct device *dev;
61 struct phy_consumer *consumers;
62 struct class_dev_iter iter;
63
64 class_dev_iter_init(&iter, phy_class, NULL, NULL);
65 while ((dev = class_dev_iter_next(&iter))) {
66 phy = to_phy(dev);
67 count = phy->init_data->num_consumers;
68 consumers = phy->init_data->consumers;
69 while (count--) {
70 if (!strcmp(consumers->dev_name, dev_name(device)) &&
71 !strcmp(consumers->port, port)) {
72 class_dev_iter_exit(&iter);
73 return phy;
74 }
75 consumers++;
76 }
77 }
78
79 class_dev_iter_exit(&iter);
80 return ERR_PTR(-ENODEV);
81}
82
83static struct phy_provider *of_phy_provider_lookup(struct device_node *node)
84{
85 struct phy_provider *phy_provider;
86
87 list_for_each_entry(phy_provider, &phy_provider_list, list) {
88 if (phy_provider->dev->of_node == node)
89 return phy_provider;
90 }
91
92 return ERR_PTR(-EPROBE_DEFER);
93}
94
95int phy_pm_runtime_get(struct phy *phy)
96{
97 if (!pm_runtime_enabled(&phy->dev))
98 return -ENOTSUPP;
99
100 return pm_runtime_get(&phy->dev);
101}
102EXPORT_SYMBOL_GPL(phy_pm_runtime_get);
103
104int phy_pm_runtime_get_sync(struct phy *phy)
105{
106 if (!pm_runtime_enabled(&phy->dev))
107 return -ENOTSUPP;
108
109 return pm_runtime_get_sync(&phy->dev);
110}
111EXPORT_SYMBOL_GPL(phy_pm_runtime_get_sync);
112
113int phy_pm_runtime_put(struct phy *phy)
114{
115 if (!pm_runtime_enabled(&phy->dev))
116 return -ENOTSUPP;
117
118 return pm_runtime_put(&phy->dev);
119}
120EXPORT_SYMBOL_GPL(phy_pm_runtime_put);
121
122int phy_pm_runtime_put_sync(struct phy *phy)
123{
124 if (!pm_runtime_enabled(&phy->dev))
125 return -ENOTSUPP;
126
127 return pm_runtime_put_sync(&phy->dev);
128}
129EXPORT_SYMBOL_GPL(phy_pm_runtime_put_sync);
130
131void phy_pm_runtime_allow(struct phy *phy)
132{
133 if (!pm_runtime_enabled(&phy->dev))
134 return;
135
136 pm_runtime_allow(&phy->dev);
137}
138EXPORT_SYMBOL_GPL(phy_pm_runtime_allow);
139
140void phy_pm_runtime_forbid(struct phy *phy)
141{
142 if (!pm_runtime_enabled(&phy->dev))
143 return;
144
145 pm_runtime_forbid(&phy->dev);
146}
147EXPORT_SYMBOL_GPL(phy_pm_runtime_forbid);
148
149int phy_init(struct phy *phy)
150{
151 int ret;
152
153 ret = phy_pm_runtime_get_sync(phy);
154 if (ret < 0 && ret != -ENOTSUPP)
155 return ret;
156
157 mutex_lock(&phy->mutex);
158 if (phy->init_count++ == 0 && phy->ops->init) {
159 ret = phy->ops->init(phy);
160 if (ret < 0) {
161 dev_err(&phy->dev, "phy init failed --> %d\n", ret);
162 goto out;
163 }
164 }
165
166out:
167 mutex_unlock(&phy->mutex);
168 phy_pm_runtime_put(phy);
169 return ret;
170}
171EXPORT_SYMBOL_GPL(phy_init);
172
173int phy_exit(struct phy *phy)
174{
175 int ret;
176
177 ret = phy_pm_runtime_get_sync(phy);
178 if (ret < 0 && ret != -ENOTSUPP)
179 return ret;
180
181 mutex_lock(&phy->mutex);
182 if (--phy->init_count == 0 && phy->ops->exit) {
183 ret = phy->ops->exit(phy);
184 if (ret < 0) {
185 dev_err(&phy->dev, "phy exit failed --> %d\n", ret);
186 goto out;
187 }
188 }
189
190out:
191 mutex_unlock(&phy->mutex);
192 phy_pm_runtime_put(phy);
193 return ret;
194}
195EXPORT_SYMBOL_GPL(phy_exit);
196
197int phy_power_on(struct phy *phy)
198{
199 int ret = -ENOTSUPP;
200
201 ret = phy_pm_runtime_get_sync(phy);
202 if (ret < 0 && ret != -ENOTSUPP)
203 return ret;
204
205 mutex_lock(&phy->mutex);
206 if (phy->power_count++ == 0 && phy->ops->power_on) {
207 ret = phy->ops->power_on(phy);
208 if (ret < 0) {
209 dev_err(&phy->dev, "phy poweron failed --> %d\n", ret);
210 goto out;
211 }
212 }
213
214out:
215 mutex_unlock(&phy->mutex);
216
217 return ret;
218}
219EXPORT_SYMBOL_GPL(phy_power_on);
220
221int phy_power_off(struct phy *phy)
222{
223 int ret = -ENOTSUPP;
224
225 mutex_lock(&phy->mutex);
226 if (--phy->power_count == 0 && phy->ops->power_off) {
227 ret = phy->ops->power_off(phy);
228 if (ret < 0) {
229 dev_err(&phy->dev, "phy poweroff failed --> %d\n", ret);
230 goto out;
231 }
232 }
233
234out:
235 mutex_unlock(&phy->mutex);
236 phy_pm_runtime_put(phy);
237
238 return ret;
239}
240EXPORT_SYMBOL_GPL(phy_power_off);
241
242/**
243 * of_phy_get() - lookup and obtain a reference to a phy by phandle
244 * @dev: device that requests this phy
245 * @index: the index of the phy
246 *
247 * Returns the phy associated with the given phandle value,
248 * after getting a refcount to it or -ENODEV if there is no such phy or
249 * -EPROBE_DEFER if there is a phandle to the phy, but the device is
250 * not yet loaded. This function uses of_xlate call back function provided
251 * while registering the phy_provider to find the phy instance.
252 */
253static struct phy *of_phy_get(struct device *dev, int index)
254{
255 int ret;
256 struct phy_provider *phy_provider;
257 struct phy *phy = NULL;
258 struct of_phandle_args args;
259
260 ret = of_parse_phandle_with_args(dev->of_node, "phys", "#phy-cells",
261 index, &args);
262 if (ret) {
263 dev_dbg(dev, "failed to get phy in %s node\n",
264 dev->of_node->full_name);
265 return ERR_PTR(-ENODEV);
266 }
267
268 mutex_lock(&phy_provider_mutex);
269 phy_provider = of_phy_provider_lookup(args.np);
270 if (IS_ERR(phy_provider) || !try_module_get(phy_provider->owner)) {
271 phy = ERR_PTR(-EPROBE_DEFER);
272 goto err0;
273 }
274
275 phy = phy_provider->of_xlate(phy_provider->dev, &args);
276 module_put(phy_provider->owner);
277
278err0:
279 mutex_unlock(&phy_provider_mutex);
280 of_node_put(args.np);
281
282 return phy;
283}
284
285/**
286 * phy_put() - release the PHY
287 * @phy: the phy returned by phy_get()
288 *
289 * Releases a refcount the caller received from phy_get().
290 */
291void phy_put(struct phy *phy)
292{
293 if (IS_ERR(phy))
294 return;
295
296 module_put(phy->ops->owner);
297 put_device(&phy->dev);
298}
299EXPORT_SYMBOL_GPL(phy_put);
300
301/**
302 * devm_phy_put() - release the PHY
303 * @dev: device that wants to release this phy
304 * @phy: the phy returned by devm_phy_get()
305 *
306 * destroys the devres associated with this phy and invokes phy_put
307 * to release the phy.
308 */
309void devm_phy_put(struct device *dev, struct phy *phy)
310{
311 int r;
312
313 r = devres_destroy(dev, devm_phy_release, devm_phy_match, phy);
314 dev_WARN_ONCE(dev, r, "couldn't find PHY resource\n");
315}
316EXPORT_SYMBOL_GPL(devm_phy_put);
317
318/**
319 * of_phy_simple_xlate() - returns the phy instance from phy provider
320 * @dev: the PHY provider device
321 * @args: of_phandle_args (not used here)
322 *
323 * Intended to be used by phy provider for the common case where #phy-cells is
324 * 0. For other cases where #phy-cells is greater than '0', the phy provider
325 * should provide a custom of_xlate function that reads the *args* and returns
326 * the appropriate phy.
327 */
328struct phy *of_phy_simple_xlate(struct device *dev, struct of_phandle_args
329 *args)
330{
331 struct phy *phy;
332 struct class_dev_iter iter;
333 struct device_node *node = dev->of_node;
334
335 class_dev_iter_init(&iter, phy_class, NULL, NULL);
336 while ((dev = class_dev_iter_next(&iter))) {
337 phy = to_phy(dev);
338 if (node != phy->dev.of_node)
339 continue;
340
341 class_dev_iter_exit(&iter);
342 return phy;
343 }
344
345 class_dev_iter_exit(&iter);
346 return ERR_PTR(-ENODEV);
347}
348EXPORT_SYMBOL_GPL(of_phy_simple_xlate);
349
350/**
351 * phy_get() - lookup and obtain a reference to a phy.
352 * @dev: device that requests this phy
353 * @string: the phy name as given in the dt data or the name of the controller
354 * port for non-dt case
355 *
356 * Returns the phy driver, after getting a refcount to it; or
357 * -ENODEV if there is no such phy. The caller is responsible for
358 * calling phy_put() to release that count.
359 */
360struct phy *phy_get(struct device *dev, const char *string)
361{
362 int index = 0;
363 struct phy *phy = NULL;
364
365 if (string == NULL) {
366 dev_WARN(dev, "missing string\n");
367 return ERR_PTR(-EINVAL);
368 }
369
370 if (dev->of_node) {
371 index = of_property_match_string(dev->of_node, "phy-names",
372 string);
373 phy = of_phy_get(dev, index);
374 if (IS_ERR(phy)) {
375 dev_err(dev, "unable to find phy\n");
376 return phy;
377 }
378 } else {
379 phy = phy_lookup(dev, string);
380 if (IS_ERR(phy)) {
381 dev_err(dev, "unable to find phy\n");
382 return phy;
383 }
384 }
385
386 if (!try_module_get(phy->ops->owner))
387 return ERR_PTR(-EPROBE_DEFER);
388
389 get_device(&phy->dev);
390
391 return phy;
392}
393EXPORT_SYMBOL_GPL(phy_get);
394
395/**
396 * devm_phy_get() - lookup and obtain a reference to a phy.
397 * @dev: device that requests this phy
398 * @string: the phy name as given in the dt data or phy device name
399 * for non-dt case
400 *
401 * Gets the phy using phy_get(), and associates a device with it using
402 * devres. On driver detach, release function is invoked on the devres data,
403 * then, devres data is freed.
404 */
405struct phy *devm_phy_get(struct device *dev, const char *string)
406{
407 struct phy **ptr, *phy;
408
409 ptr = devres_alloc(devm_phy_release, sizeof(*ptr), GFP_KERNEL);
410 if (!ptr)
411 return ERR_PTR(-ENOMEM);
412
413 phy = phy_get(dev, string);
414 if (!IS_ERR(phy)) {
415 *ptr = phy;
416 devres_add(dev, ptr);
417 } else {
418 devres_free(ptr);
419 }
420
421 return phy;
422}
423EXPORT_SYMBOL_GPL(devm_phy_get);
424
425/**
426 * phy_create() - create a new phy
427 * @dev: device that is creating the new phy
428 * @ops: function pointers for performing phy operations
429 * @init_data: contains the list of PHY consumers or NULL
430 *
431 * Called to create a phy using phy framework.
432 */
433struct phy *phy_create(struct device *dev, const struct phy_ops *ops,
434 struct phy_init_data *init_data)
435{
436 int ret;
437 int id;
438 struct phy *phy;
439
440 if (!dev) {
441 dev_WARN(dev, "no device provided for PHY\n");
442 ret = -EINVAL;
443 goto err0;
444 }
445
446 phy = kzalloc(sizeof(*phy), GFP_KERNEL);
447 if (!phy) {
448 ret = -ENOMEM;
449 goto err0;
450 }
451
452 id = ida_simple_get(&phy_ida, 0, 0, GFP_KERNEL);
453 if (id < 0) {
454 dev_err(dev, "unable to get id\n");
455 ret = id;
456 goto err0;
457 }
458
459 device_initialize(&phy->dev);
460 mutex_init(&phy->mutex);
461
462 phy->dev.class = phy_class;
463 phy->dev.parent = dev;
464 phy->dev.of_node = dev->of_node;
465 phy->id = id;
466 phy->ops = ops;
467 phy->init_data = init_data;
468
469 ret = dev_set_name(&phy->dev, "phy-%s.%d", dev_name(dev), id);
470 if (ret)
471 goto err1;
472
473 ret = device_add(&phy->dev);
474 if (ret)
475 goto err1;
476
477 if (pm_runtime_enabled(dev)) {
478 pm_runtime_enable(&phy->dev);
479 pm_runtime_no_callbacks(&phy->dev);
480 }
481
482 return phy;
483
484err1:
485 ida_remove(&phy_ida, phy->id);
486 put_device(&phy->dev);
487 kfree(phy);
488
489err0:
490 return ERR_PTR(ret);
491}
492EXPORT_SYMBOL_GPL(phy_create);
493
494/**
495 * devm_phy_create() - create a new phy
496 * @dev: device that is creating the new phy
497 * @ops: function pointers for performing phy operations
498 * @init_data: contains the list of PHY consumers or NULL
499 *
500 * Creates a new PHY device adding it to the PHY class.
501 * While at that, it also associates the device with the phy using devres.
502 * On driver detach, release function is invoked on the devres data,
503 * then, devres data is freed.
504 */
505struct phy *devm_phy_create(struct device *dev, const struct phy_ops *ops,
506 struct phy_init_data *init_data)
507{
508 struct phy **ptr, *phy;
509
510 ptr = devres_alloc(devm_phy_consume, sizeof(*ptr), GFP_KERNEL);
511 if (!ptr)
512 return ERR_PTR(-ENOMEM);
513
514 phy = phy_create(dev, ops, init_data);
515 if (!IS_ERR(phy)) {
516 *ptr = phy;
517 devres_add(dev, ptr);
518 } else {
519 devres_free(ptr);
520 }
521
522 return phy;
523}
524EXPORT_SYMBOL_GPL(devm_phy_create);
525
526/**
527 * phy_destroy() - destroy the phy
528 * @phy: the phy to be destroyed
529 *
530 * Called to destroy the phy.
531 */
532void phy_destroy(struct phy *phy)
533{
534 pm_runtime_disable(&phy->dev);
535 device_unregister(&phy->dev);
536}
537EXPORT_SYMBOL_GPL(phy_destroy);
538
539/**
540 * devm_phy_destroy() - destroy the PHY
541 * @dev: device that wants to release this phy
542 * @phy: the phy returned by devm_phy_get()
543 *
544 * destroys the devres associated with this phy and invokes phy_destroy
545 * to destroy the phy.
546 */
547void devm_phy_destroy(struct device *dev, struct phy *phy)
548{
549 int r;
550
551 r = devres_destroy(dev, devm_phy_consume, devm_phy_match, phy);
552 dev_WARN_ONCE(dev, r, "couldn't find PHY resource\n");
553}
554EXPORT_SYMBOL_GPL(devm_phy_destroy);
555
556/**
557 * __of_phy_provider_register() - create/register phy provider with the framework
558 * @dev: struct device of the phy provider
559 * @owner: the module owner containing of_xlate
560 * @of_xlate: function pointer to obtain phy instance from phy provider
561 *
562 * Creates struct phy_provider from dev and of_xlate function pointer.
563 * This is used in the case of dt boot for finding the phy instance from
564 * phy provider.
565 */
566struct phy_provider *__of_phy_provider_register(struct device *dev,
567 struct module *owner, struct phy * (*of_xlate)(struct device *dev,
568 struct of_phandle_args *args))
569{
570 struct phy_provider *phy_provider;
571
572 phy_provider = kzalloc(sizeof(*phy_provider), GFP_KERNEL);
573 if (!phy_provider)
574 return ERR_PTR(-ENOMEM);
575
576 phy_provider->dev = dev;
577 phy_provider->owner = owner;
578 phy_provider->of_xlate = of_xlate;
579
580 mutex_lock(&phy_provider_mutex);
581 list_add_tail(&phy_provider->list, &phy_provider_list);
582 mutex_unlock(&phy_provider_mutex);
583
584 return phy_provider;
585}
586EXPORT_SYMBOL_GPL(__of_phy_provider_register);
587
588/**
589 * __devm_of_phy_provider_register() - create/register phy provider with the
590 * framework
591 * @dev: struct device of the phy provider
592 * @owner: the module owner containing of_xlate
593 * @of_xlate: function pointer to obtain phy instance from phy provider
594 *
595 * Creates struct phy_provider from dev and of_xlate function pointer.
596 * This is used in the case of dt boot for finding the phy instance from
597 * phy provider. While at that, it also associates the device with the
598 * phy provider using devres. On driver detach, release function is invoked
599 * on the devres data, then, devres data is freed.
600 */
601struct phy_provider *__devm_of_phy_provider_register(struct device *dev,
602 struct module *owner, struct phy * (*of_xlate)(struct device *dev,
603 struct of_phandle_args *args))
604{
605 struct phy_provider **ptr, *phy_provider;
606
607 ptr = devres_alloc(devm_phy_provider_release, sizeof(*ptr), GFP_KERNEL);
608 if (!ptr)
609 return ERR_PTR(-ENOMEM);
610
611 phy_provider = __of_phy_provider_register(dev, owner, of_xlate);
612 if (!IS_ERR(phy_provider)) {
613 *ptr = phy_provider;
614 devres_add(dev, ptr);
615 } else {
616 devres_free(ptr);
617 }
618
619 return phy_provider;
620}
621EXPORT_SYMBOL_GPL(__devm_of_phy_provider_register);
622
623/**
624 * of_phy_provider_unregister() - unregister phy provider from the framework
625 * @phy_provider: phy provider returned by of_phy_provider_register()
626 *
627 * Removes the phy_provider created using of_phy_provider_register().
628 */
629void of_phy_provider_unregister(struct phy_provider *phy_provider)
630{
631 if (IS_ERR(phy_provider))
632 return;
633
634 mutex_lock(&phy_provider_mutex);
635 list_del(&phy_provider->list);
636 kfree(phy_provider);
637 mutex_unlock(&phy_provider_mutex);
638}
639EXPORT_SYMBOL_GPL(of_phy_provider_unregister);
640
641/**
642 * devm_of_phy_provider_unregister() - remove phy provider from the framework
643 * @dev: struct device of the phy provider
644 *
645 * destroys the devres associated with this phy provider and invokes
646 * of_phy_provider_unregister to unregister the phy provider.
647 */
648void devm_of_phy_provider_unregister(struct device *dev,
649 struct phy_provider *phy_provider) {
650 int r;
651
652 r = devres_destroy(dev, devm_phy_provider_release, devm_phy_match,
653 phy_provider);
654 dev_WARN_ONCE(dev, r, "couldn't find PHY provider device resource\n");
655}
656EXPORT_SYMBOL_GPL(devm_of_phy_provider_unregister);
657
658/**
659 * phy_release() - release the phy
660 * @dev: the dev member within phy
661 *
662 * When the last reference to the device is removed, it is called
663 * from the embedded kobject as release method.
664 */
665static void phy_release(struct device *dev)
666{
667 struct phy *phy;
668
669 phy = to_phy(dev);
670 dev_vdbg(dev, "releasing '%s'\n", dev_name(dev));
671 ida_remove(&phy_ida, phy->id);
672 kfree(phy);
673}
674
675static int __init phy_core_init(void)
676{
677 phy_class = class_create(THIS_MODULE, "phy");
678 if (IS_ERR(phy_class)) {
679 pr_err("failed to create phy class --> %ld\n",
680 PTR_ERR(phy_class));
681 return PTR_ERR(phy_class);
682 }
683
684 phy_class->dev_release = phy_release;
685
686 return 0;
687}
688module_init(phy_core_init);
689
690static void __exit phy_core_exit(void)
691{
692 class_destroy(phy_class);
693}
694module_exit(phy_core_exit);
695
696MODULE_DESCRIPTION("Generic PHY Framework");
697MODULE_AUTHOR("Kishon Vijay Abraham I <kishon@ti.com>");
698MODULE_LICENSE("GPL v2");
diff --git a/drivers/phy/phy-exynos-dp-video.c b/drivers/phy/phy-exynos-dp-video.c
new file mode 100644
index 000000000000..1dbe6ce7b2ce
--- /dev/null
+++ b/drivers/phy/phy-exynos-dp-video.c
@@ -0,0 +1,111 @@
1/*
2 * Samsung EXYNOS SoC series Display Port PHY driver
3 *
4 * Copyright (C) 2013 Samsung Electronics Co., Ltd.
5 * Author: Jingoo Han <jg1.han@samsung.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#include <linux/io.h>
13#include <linux/kernel.h>
14#include <linux/module.h>
15#include <linux/of.h>
16#include <linux/of_address.h>
17#include <linux/phy/phy.h>
18#include <linux/platform_device.h>
19
20/* DPTX_PHY_CONTROL register */
21#define EXYNOS_DPTX_PHY_ENABLE (1 << 0)
22
23struct exynos_dp_video_phy {
24 void __iomem *regs;
25};
26
27static int __set_phy_state(struct exynos_dp_video_phy *state, unsigned int on)
28{
29 u32 reg;
30
31 reg = readl(state->regs);
32 if (on)
33 reg |= EXYNOS_DPTX_PHY_ENABLE;
34 else
35 reg &= ~EXYNOS_DPTX_PHY_ENABLE;
36 writel(reg, state->regs);
37
38 return 0;
39}
40
41static int exynos_dp_video_phy_power_on(struct phy *phy)
42{
43 struct exynos_dp_video_phy *state = phy_get_drvdata(phy);
44
45 return __set_phy_state(state, 1);
46}
47
48static int exynos_dp_video_phy_power_off(struct phy *phy)
49{
50 struct exynos_dp_video_phy *state = phy_get_drvdata(phy);
51
52 return __set_phy_state(state, 0);
53}
54
55static struct phy_ops exynos_dp_video_phy_ops = {
56 .power_on = exynos_dp_video_phy_power_on,
57 .power_off = exynos_dp_video_phy_power_off,
58 .owner = THIS_MODULE,
59};
60
61static int exynos_dp_video_phy_probe(struct platform_device *pdev)
62{
63 struct exynos_dp_video_phy *state;
64 struct device *dev = &pdev->dev;
65 struct resource *res;
66 struct phy_provider *phy_provider;
67 struct phy *phy;
68
69 state = devm_kzalloc(dev, sizeof(*state), GFP_KERNEL);
70 if (!state)
71 return -ENOMEM;
72
73 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
74
75 state->regs = devm_ioremap_resource(dev, res);
76 if (IS_ERR(state->regs))
77 return PTR_ERR(state->regs);
78
79 phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
80 if (IS_ERR(phy_provider))
81 return PTR_ERR(phy_provider);
82
83 phy = devm_phy_create(dev, &exynos_dp_video_phy_ops, NULL);
84 if (IS_ERR(phy)) {
85 dev_err(dev, "failed to create Display Port PHY\n");
86 return PTR_ERR(phy);
87 }
88 phy_set_drvdata(phy, state);
89
90 return 0;
91}
92
93static const struct of_device_id exynos_dp_video_phy_of_match[] = {
94 { .compatible = "samsung,exynos5250-dp-video-phy" },
95 { },
96};
97MODULE_DEVICE_TABLE(of, exynos_dp_video_phy_of_match);
98
99static struct platform_driver exynos_dp_video_phy_driver = {
100 .probe = exynos_dp_video_phy_probe,
101 .driver = {
102 .name = "exynos-dp-video-phy",
103 .owner = THIS_MODULE,
104 .of_match_table = exynos_dp_video_phy_of_match,
105 }
106};
107module_platform_driver(exynos_dp_video_phy_driver);
108
109MODULE_AUTHOR("Jingoo Han <jg1.han@samsung.com>");
110MODULE_DESCRIPTION("Samsung EXYNOS SoC DP PHY driver");
111MODULE_LICENSE("GPL v2");
diff --git a/drivers/phy/phy-exynos-mipi-video.c b/drivers/phy/phy-exynos-mipi-video.c
new file mode 100644
index 000000000000..0c5efab11af1
--- /dev/null
+++ b/drivers/phy/phy-exynos-mipi-video.c
@@ -0,0 +1,176 @@
1/*
2 * Samsung S5P/EXYNOS SoC series MIPI CSIS/DSIM DPHY driver
3 *
4 * Copyright (C) 2013 Samsung Electronics Co., Ltd.
5 * Author: Sylwester Nawrocki <s.nawrocki@samsung.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#include <linux/io.h>
13#include <linux/kernel.h>
14#include <linux/module.h>
15#include <linux/of.h>
16#include <linux/of_address.h>
17#include <linux/phy/phy.h>
18#include <linux/platform_device.h>
19#include <linux/spinlock.h>
20
21/* MIPI_PHYn_CONTROL register offset: n = 0..1 */
22#define EXYNOS_MIPI_PHY_CONTROL(n) ((n) * 4)
23#define EXYNOS_MIPI_PHY_ENABLE (1 << 0)
24#define EXYNOS_MIPI_PHY_SRESETN (1 << 1)
25#define EXYNOS_MIPI_PHY_MRESETN (1 << 2)
26#define EXYNOS_MIPI_PHY_RESET_MASK (3 << 1)
27
28enum exynos_mipi_phy_id {
29 EXYNOS_MIPI_PHY_ID_CSIS0,
30 EXYNOS_MIPI_PHY_ID_DSIM0,
31 EXYNOS_MIPI_PHY_ID_CSIS1,
32 EXYNOS_MIPI_PHY_ID_DSIM1,
33 EXYNOS_MIPI_PHYS_NUM
34};
35
36#define is_mipi_dsim_phy_id(id) \
37 ((id) == EXYNOS_MIPI_PHY_ID_DSIM0 || (id) == EXYNOS_MIPI_PHY_ID_DSIM1)
38
39struct exynos_mipi_video_phy {
40 spinlock_t slock;
41 struct video_phy_desc {
42 struct phy *phy;
43 unsigned int index;
44 } phys[EXYNOS_MIPI_PHYS_NUM];
45 void __iomem *regs;
46};
47
48static int __set_phy_state(struct exynos_mipi_video_phy *state,
49 enum exynos_mipi_phy_id id, unsigned int on)
50{
51 void __iomem *addr;
52 u32 reg, reset;
53
54 addr = state->regs + EXYNOS_MIPI_PHY_CONTROL(id / 2);
55
56 if (is_mipi_dsim_phy_id(id))
57 reset = EXYNOS_MIPI_PHY_MRESETN;
58 else
59 reset = EXYNOS_MIPI_PHY_SRESETN;
60
61 spin_lock(&state->slock);
62 reg = readl(addr);
63 if (on)
64 reg |= reset;
65 else
66 reg &= ~reset;
67 writel(reg, addr);
68
69 /* Clear ENABLE bit only if MRESETN, SRESETN bits are not set. */
70 if (on)
71 reg |= EXYNOS_MIPI_PHY_ENABLE;
72 else if (!(reg & EXYNOS_MIPI_PHY_RESET_MASK))
73 reg &= ~EXYNOS_MIPI_PHY_ENABLE;
74
75 writel(reg, addr);
76 spin_unlock(&state->slock);
77 return 0;
78}
79
80#define to_mipi_video_phy(desc) \
81 container_of((desc), struct exynos_mipi_video_phy, phys[(desc)->index]);
82
83static int exynos_mipi_video_phy_power_on(struct phy *phy)
84{
85 struct video_phy_desc *phy_desc = phy_get_drvdata(phy);
86 struct exynos_mipi_video_phy *state = to_mipi_video_phy(phy_desc);
87
88 return __set_phy_state(state, phy_desc->index, 1);
89}
90
91static int exynos_mipi_video_phy_power_off(struct phy *phy)
92{
93 struct video_phy_desc *phy_desc = phy_get_drvdata(phy);
94 struct exynos_mipi_video_phy *state = to_mipi_video_phy(phy_desc);
95
96 return __set_phy_state(state, phy_desc->index, 0);
97}
98
99static struct phy *exynos_mipi_video_phy_xlate(struct device *dev,
100 struct of_phandle_args *args)
101{
102 struct exynos_mipi_video_phy *state = dev_get_drvdata(dev);
103
104 if (WARN_ON(args->args[0] > EXYNOS_MIPI_PHYS_NUM))
105 return ERR_PTR(-ENODEV);
106
107 return state->phys[args->args[0]].phy;
108}
109
110static struct phy_ops exynos_mipi_video_phy_ops = {
111 .power_on = exynos_mipi_video_phy_power_on,
112 .power_off = exynos_mipi_video_phy_power_off,
113 .owner = THIS_MODULE,
114};
115
116static int exynos_mipi_video_phy_probe(struct platform_device *pdev)
117{
118 struct exynos_mipi_video_phy *state;
119 struct device *dev = &pdev->dev;
120 struct resource *res;
121 struct phy_provider *phy_provider;
122 unsigned int i;
123
124 state = devm_kzalloc(dev, sizeof(*state), GFP_KERNEL);
125 if (!state)
126 return -ENOMEM;
127
128 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
129
130 state->regs = devm_ioremap_resource(dev, res);
131 if (IS_ERR(state->regs))
132 return PTR_ERR(state->regs);
133
134 dev_set_drvdata(dev, state);
135 spin_lock_init(&state->slock);
136
137 phy_provider = devm_of_phy_provider_register(dev,
138 exynos_mipi_video_phy_xlate);
139 if (IS_ERR(phy_provider))
140 return PTR_ERR(phy_provider);
141
142 for (i = 0; i < EXYNOS_MIPI_PHYS_NUM; i++) {
143 struct phy *phy = devm_phy_create(dev,
144 &exynos_mipi_video_phy_ops, NULL);
145 if (IS_ERR(phy)) {
146 dev_err(dev, "failed to create PHY %d\n", i);
147 return PTR_ERR(phy);
148 }
149
150 state->phys[i].phy = phy;
151 state->phys[i].index = i;
152 phy_set_drvdata(phy, &state->phys[i]);
153 }
154
155 return 0;
156}
157
158static const struct of_device_id exynos_mipi_video_phy_of_match[] = {
159 { .compatible = "samsung,s5pv210-mipi-video-phy" },
160 { },
161};
162MODULE_DEVICE_TABLE(of, exynos_mipi_video_phy_of_match);
163
164static struct platform_driver exynos_mipi_video_phy_driver = {
165 .probe = exynos_mipi_video_phy_probe,
166 .driver = {
167 .of_match_table = exynos_mipi_video_phy_of_match,
168 .name = "exynos-mipi-video-phy",
169 .owner = THIS_MODULE,
170 }
171};
172module_platform_driver(exynos_mipi_video_phy_driver);
173
174MODULE_DESCRIPTION("Samsung S5P/EXYNOS SoC MIPI CSI-2/DSI PHY driver");
175MODULE_AUTHOR("Sylwester Nawrocki <s.nawrocki@samsung.com>");
176MODULE_LICENSE("GPL v2");
diff --git a/drivers/usb/phy/phy-omap-usb2.c b/drivers/phy/phy-omap-usb2.c
index d266861d24f7..bfc5c337f99a 100644
--- a/drivers/usb/phy/phy-omap-usb2.c
+++ b/drivers/phy/phy-omap-usb2.c
@@ -28,6 +28,8 @@
28#include <linux/pm_runtime.h> 28#include <linux/pm_runtime.h>
29#include <linux/delay.h> 29#include <linux/delay.h>
30#include <linux/usb/omap_control_usb.h> 30#include <linux/usb/omap_control_usb.h>
31#include <linux/phy/phy.h>
32#include <linux/of_platform.h>
31 33
32/** 34/**
33 * omap_usb2_set_comparator - links the comparator present in the sytem with 35 * omap_usb2_set_comparator - links the comparator present in the sytem with
@@ -118,10 +120,42 @@ static int omap_usb2_suspend(struct usb_phy *x, int suspend)
118 return 0; 120 return 0;
119} 121}
120 122
123static int omap_usb_power_off(struct phy *x)
124{
125 struct omap_usb *phy = phy_get_drvdata(x);
126
127 omap_control_usb_phy_power(phy->control_dev, 0);
128
129 return 0;
130}
131
132static int omap_usb_power_on(struct phy *x)
133{
134 struct omap_usb *phy = phy_get_drvdata(x);
135
136 omap_control_usb_phy_power(phy->control_dev, 1);
137
138 return 0;
139}
140
141static struct phy_ops ops = {
142 .power_on = omap_usb_power_on,
143 .power_off = omap_usb_power_off,
144 .owner = THIS_MODULE,
145};
146
121static int omap_usb2_probe(struct platform_device *pdev) 147static int omap_usb2_probe(struct platform_device *pdev)
122{ 148{
123 struct omap_usb *phy; 149 struct omap_usb *phy;
124 struct usb_otg *otg; 150 struct phy *generic_phy;
151 struct phy_provider *phy_provider;
152 struct usb_otg *otg;
153 struct device_node *node = pdev->dev.of_node;
154 struct device_node *control_node;
155 struct platform_device *control_pdev;
156
157 if (!node)
158 return -EINVAL;
125 159
126 phy = devm_kzalloc(&pdev->dev, sizeof(*phy), GFP_KERNEL); 160 phy = devm_kzalloc(&pdev->dev, sizeof(*phy), GFP_KERNEL);
127 if (!phy) { 161 if (!phy) {
@@ -143,12 +177,25 @@ static int omap_usb2_probe(struct platform_device *pdev)
143 phy->phy.otg = otg; 177 phy->phy.otg = otg;
144 phy->phy.type = USB_PHY_TYPE_USB2; 178 phy->phy.type = USB_PHY_TYPE_USB2;
145 179
146 phy->control_dev = omap_get_control_dev(); 180 phy_provider = devm_of_phy_provider_register(phy->dev,
147 if (IS_ERR(phy->control_dev)) { 181 of_phy_simple_xlate);
148 dev_dbg(&pdev->dev, "Failed to get control device\n"); 182 if (IS_ERR(phy_provider))
149 return -ENODEV; 183 return PTR_ERR(phy_provider);
184
185 control_node = of_parse_phandle(node, "ctrl-module", 0);
186 if (!control_node) {
187 dev_err(&pdev->dev, "Failed to get control device phandle\n");
188 return -EINVAL;
189 }
190
191 control_pdev = of_find_device_by_node(control_node);
192 if (!control_pdev) {
193 dev_err(&pdev->dev, "Failed to get control device\n");
194 return -EINVAL;
150 } 195 }
151 196
197 phy->control_dev = &control_pdev->dev;
198
152 phy->is_suspended = 1; 199 phy->is_suspended = 1;
153 omap_control_usb_phy_power(phy->control_dev, 0); 200 omap_control_usb_phy_power(phy->control_dev, 0);
154 201
@@ -158,6 +205,15 @@ static int omap_usb2_probe(struct platform_device *pdev)
158 otg->start_srp = omap_usb_start_srp; 205 otg->start_srp = omap_usb_start_srp;
159 otg->phy = &phy->phy; 206 otg->phy = &phy->phy;
160 207
208 platform_set_drvdata(pdev, phy);
209 pm_runtime_enable(phy->dev);
210
211 generic_phy = devm_phy_create(phy->dev, &ops, NULL);
212 if (IS_ERR(generic_phy))
213 return PTR_ERR(generic_phy);
214
215 phy_set_drvdata(generic_phy, phy);
216
161 phy->wkupclk = devm_clk_get(phy->dev, "usb_phy_cm_clk32k"); 217 phy->wkupclk = devm_clk_get(phy->dev, "usb_phy_cm_clk32k");
162 if (IS_ERR(phy->wkupclk)) { 218 if (IS_ERR(phy->wkupclk)) {
163 dev_err(&pdev->dev, "unable to get usb_phy_cm_clk32k\n"); 219 dev_err(&pdev->dev, "unable to get usb_phy_cm_clk32k\n");
@@ -173,10 +229,6 @@ static int omap_usb2_probe(struct platform_device *pdev)
173 229
174 usb_add_phy_dev(&phy->phy); 230 usb_add_phy_dev(&phy->phy);
175 231
176 platform_set_drvdata(pdev, phy);
177
178 pm_runtime_enable(phy->dev);
179
180 return 0; 232 return 0;
181} 233}
182 234
diff --git a/drivers/usb/phy/phy-twl4030-usb.c b/drivers/phy/phy-twl4030-usb.c
index 90730c8762b8..daf65e68aaab 100644
--- a/drivers/usb/phy/phy-twl4030-usb.c
+++ b/drivers/phy/phy-twl4030-usb.c
@@ -33,6 +33,7 @@
33#include <linux/io.h> 33#include <linux/io.h>
34#include <linux/delay.h> 34#include <linux/delay.h>
35#include <linux/usb/otg.h> 35#include <linux/usb/otg.h>
36#include <linux/phy/phy.h>
36#include <linux/usb/musb-omap.h> 37#include <linux/usb/musb-omap.h>
37#include <linux/usb/ulpi.h> 38#include <linux/usb/ulpi.h>
38#include <linux/i2c/twl.h> 39#include <linux/i2c/twl.h>
@@ -421,17 +422,20 @@ static void twl4030_phy_power(struct twl4030_usb *twl, int on)
421 } 422 }
422} 423}
423 424
424static void twl4030_phy_suspend(struct twl4030_usb *twl, int controller_off) 425static int twl4030_phy_power_off(struct phy *phy)
425{ 426{
427 struct twl4030_usb *twl = phy_get_drvdata(phy);
428
426 if (twl->asleep) 429 if (twl->asleep)
427 return; 430 return 0;
428 431
429 twl4030_phy_power(twl, 0); 432 twl4030_phy_power(twl, 0);
430 twl->asleep = 1; 433 twl->asleep = 1;
431 dev_dbg(twl->dev, "%s\n", __func__); 434 dev_dbg(twl->dev, "%s\n", __func__);
435 return 0;
432} 436}
433 437
434static void __twl4030_phy_resume(struct twl4030_usb *twl) 438static void __twl4030_phy_power_on(struct twl4030_usb *twl)
435{ 439{
436 twl4030_phy_power(twl, 1); 440 twl4030_phy_power(twl, 1);
437 twl4030_i2c_access(twl, 1); 441 twl4030_i2c_access(twl, 1);
@@ -440,11 +444,13 @@ static void __twl4030_phy_resume(struct twl4030_usb *twl)
440 twl4030_i2c_access(twl, 0); 444 twl4030_i2c_access(twl, 0);
441} 445}
442 446
443static void twl4030_phy_resume(struct twl4030_usb *twl) 447static int twl4030_phy_power_on(struct phy *phy)
444{ 448{
449 struct twl4030_usb *twl = phy_get_drvdata(phy);
450
445 if (!twl->asleep) 451 if (!twl->asleep)
446 return; 452 return 0;
447 __twl4030_phy_resume(twl); 453 __twl4030_phy_power_on(twl);
448 twl->asleep = 0; 454 twl->asleep = 0;
449 dev_dbg(twl->dev, "%s\n", __func__); 455 dev_dbg(twl->dev, "%s\n", __func__);
450 456
@@ -457,6 +463,7 @@ static void twl4030_phy_resume(struct twl4030_usb *twl)
457 cancel_delayed_work(&twl->id_workaround_work); 463 cancel_delayed_work(&twl->id_workaround_work);
458 schedule_delayed_work(&twl->id_workaround_work, HZ); 464 schedule_delayed_work(&twl->id_workaround_work, HZ);
459 } 465 }
466 return 0;
460} 467}
461 468
462static int twl4030_usb_ldo_init(struct twl4030_usb *twl) 469static int twl4030_usb_ldo_init(struct twl4030_usb *twl)
@@ -587,9 +594,9 @@ static void twl4030_id_workaround_work(struct work_struct *work)
587 } 594 }
588} 595}
589 596
590static int twl4030_usb_phy_init(struct usb_phy *phy) 597static int twl4030_phy_init(struct phy *phy)
591{ 598{
592 struct twl4030_usb *twl = phy_to_twl(phy); 599 struct twl4030_usb *twl = phy_get_drvdata(phy);
593 enum omap_musb_vbus_id_status status; 600 enum omap_musb_vbus_id_status status;
594 601
595 /* 602 /*
@@ -602,25 +609,15 @@ static int twl4030_usb_phy_init(struct usb_phy *phy)
602 status = twl4030_usb_linkstat(twl); 609 status = twl4030_usb_linkstat(twl);
603 twl->linkstat = status; 610 twl->linkstat = status;
604 611
605 if (status == OMAP_MUSB_ID_GROUND || status == OMAP_MUSB_VBUS_VALID) 612 if (status == OMAP_MUSB_ID_GROUND || status == OMAP_MUSB_VBUS_VALID) {
606 omap_musb_mailbox(twl->linkstat); 613 omap_musb_mailbox(twl->linkstat);
614 twl4030_phy_power_on(phy);
615 }
607 616
608 sysfs_notify(&twl->dev->kobj, NULL, "vbus"); 617 sysfs_notify(&twl->dev->kobj, NULL, "vbus");
609 return 0; 618 return 0;
610} 619}
611 620
612static int twl4030_set_suspend(struct usb_phy *x, int suspend)
613{
614 struct twl4030_usb *twl = phy_to_twl(x);
615
616 if (suspend)
617 twl4030_phy_suspend(twl, 1);
618 else
619 twl4030_phy_resume(twl);
620
621 return 0;
622}
623
624static int twl4030_set_peripheral(struct usb_otg *otg, 621static int twl4030_set_peripheral(struct usb_otg *otg,
625 struct usb_gadget *gadget) 622 struct usb_gadget *gadget)
626{ 623{
@@ -646,13 +643,23 @@ static int twl4030_set_host(struct usb_otg *otg, struct usb_bus *host)
646 return 0; 643 return 0;
647} 644}
648 645
646static const struct phy_ops ops = {
647 .init = twl4030_phy_init,
648 .power_on = twl4030_phy_power_on,
649 .power_off = twl4030_phy_power_off,
650 .owner = THIS_MODULE,
651};
652
649static int twl4030_usb_probe(struct platform_device *pdev) 653static int twl4030_usb_probe(struct platform_device *pdev)
650{ 654{
651 struct twl4030_usb_data *pdata = dev_get_platdata(&pdev->dev); 655 struct twl4030_usb_data *pdata = dev_get_platdata(&pdev->dev);
652 struct twl4030_usb *twl; 656 struct twl4030_usb *twl;
657 struct phy *phy;
653 int status, err; 658 int status, err;
654 struct usb_otg *otg; 659 struct usb_otg *otg;
655 struct device_node *np = pdev->dev.of_node; 660 struct device_node *np = pdev->dev.of_node;
661 struct phy_provider *phy_provider;
662 struct phy_init_data *init_data = NULL;
656 663
657 twl = devm_kzalloc(&pdev->dev, sizeof *twl, GFP_KERNEL); 664 twl = devm_kzalloc(&pdev->dev, sizeof *twl, GFP_KERNEL);
658 if (!twl) 665 if (!twl)
@@ -661,9 +668,10 @@ static int twl4030_usb_probe(struct platform_device *pdev)
661 if (np) 668 if (np)
662 of_property_read_u32(np, "usb_mode", 669 of_property_read_u32(np, "usb_mode",
663 (enum twl4030_usb_mode *)&twl->usb_mode); 670 (enum twl4030_usb_mode *)&twl->usb_mode);
664 else if (pdata) 671 else if (pdata) {
665 twl->usb_mode = pdata->usb_mode; 672 twl->usb_mode = pdata->usb_mode;
666 else { 673 init_data = pdata->init_data;
674 } else {
667 dev_err(&pdev->dev, "twl4030 initialized without pdata\n"); 675 dev_err(&pdev->dev, "twl4030 initialized without pdata\n");
668 return -EINVAL; 676 return -EINVAL;
669 } 677 }
@@ -682,13 +690,24 @@ static int twl4030_usb_probe(struct platform_device *pdev)
682 twl->phy.label = "twl4030"; 690 twl->phy.label = "twl4030";
683 twl->phy.otg = otg; 691 twl->phy.otg = otg;
684 twl->phy.type = USB_PHY_TYPE_USB2; 692 twl->phy.type = USB_PHY_TYPE_USB2;
685 twl->phy.set_suspend = twl4030_set_suspend;
686 twl->phy.init = twl4030_usb_phy_init;
687 693
688 otg->phy = &twl->phy; 694 otg->phy = &twl->phy;
689 otg->set_host = twl4030_set_host; 695 otg->set_host = twl4030_set_host;
690 otg->set_peripheral = twl4030_set_peripheral; 696 otg->set_peripheral = twl4030_set_peripheral;
691 697
698 phy_provider = devm_of_phy_provider_register(twl->dev,
699 of_phy_simple_xlate);
700 if (IS_ERR(phy_provider))
701 return PTR_ERR(phy_provider);
702
703 phy = devm_phy_create(twl->dev, &ops, init_data);
704 if (IS_ERR(phy)) {
705 dev_dbg(&pdev->dev, "Failed to create PHY\n");
706 return PTR_ERR(phy);
707 }
708
709 phy_set_drvdata(phy, twl);
710
692 /* init spinlock for workqueue */ 711 /* init spinlock for workqueue */
693 spin_lock_init(&twl->lock); 712 spin_lock_init(&twl->lock);
694 713
@@ -705,6 +724,8 @@ static int twl4030_usb_probe(struct platform_device *pdev)
705 if (device_create_file(&pdev->dev, &dev_attr_vbus)) 724 if (device_create_file(&pdev->dev, &dev_attr_vbus))
706 dev_warn(&pdev->dev, "could not create sysfs file\n"); 725 dev_warn(&pdev->dev, "could not create sysfs file\n");
707 726
727 ATOMIC_INIT_NOTIFIER_HEAD(&twl->phy.notifier);
728
708 /* Our job is to use irqs and status from the power module 729 /* Our job is to use irqs and status from the power module
709 * to keep the transceiver disabled when nothing's connected. 730 * to keep the transceiver disabled when nothing's connected.
710 * 731 *
diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig
index 96d6b2eef4f2..b51a7460cc49 100644
--- a/drivers/platform/x86/Kconfig
+++ b/drivers/platform/x86/Kconfig
@@ -504,6 +504,7 @@ config ASUS_WMI
504 depends on BACKLIGHT_CLASS_DEVICE 504 depends on BACKLIGHT_CLASS_DEVICE
505 depends on RFKILL || RFKILL = n 505 depends on RFKILL || RFKILL = n
506 depends on HOTPLUG_PCI 506 depends on HOTPLUG_PCI
507 depends on ACPI_VIDEO || ACPI_VIDEO = n
507 select INPUT_SPARSEKMAP 508 select INPUT_SPARSEKMAP
508 select LEDS_CLASS 509 select LEDS_CLASS
509 select NEW_LEDS 510 select NEW_LEDS
diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
index d3fd52036fd6..13ec195f0ca6 100644
--- a/drivers/platform/x86/sony-laptop.c
+++ b/drivers/platform/x86/sony-laptop.c
@@ -127,18 +127,17 @@ MODULE_PARM_DESC(minor,
127 "default is -1 (automatic)"); 127 "default is -1 (automatic)");
128#endif 128#endif
129 129
130static int kbd_backlight = 1; 130static int kbd_backlight = -1;
131module_param(kbd_backlight, int, 0444); 131module_param(kbd_backlight, int, 0444);
132MODULE_PARM_DESC(kbd_backlight, 132MODULE_PARM_DESC(kbd_backlight,
133 "set this to 0 to disable keyboard backlight, " 133 "set this to 0 to disable keyboard backlight, "
134 "1 to enable it (default: 0)"); 134 "1 to enable it (default: no change from current value)");
135 135
136static int kbd_backlight_timeout; /* = 0 */ 136static int kbd_backlight_timeout = -1;
137module_param(kbd_backlight_timeout, int, 0444); 137module_param(kbd_backlight_timeout, int, 0444);
138MODULE_PARM_DESC(kbd_backlight_timeout, 138MODULE_PARM_DESC(kbd_backlight_timeout,
139 "set this to 0 to set the default 10 seconds timeout, " 139 "meaningful values vary from 0 to 3 and their meaning depends "
140 "1 for 30 seconds, 2 for 60 seconds and 3 to disable timeout " 140 "on the model (default: no change from current value)");
141 "(default: 0)");
142 141
143#ifdef CONFIG_PM_SLEEP 142#ifdef CONFIG_PM_SLEEP
144static void sony_nc_kbd_backlight_resume(void); 143static void sony_nc_kbd_backlight_resume(void);
@@ -1844,6 +1843,8 @@ static int sony_nc_kbd_backlight_setup(struct platform_device *pd,
1844 if (!kbdbl_ctl) 1843 if (!kbdbl_ctl)
1845 return -ENOMEM; 1844 return -ENOMEM;
1846 1845
1846 kbdbl_ctl->mode = kbd_backlight;
1847 kbdbl_ctl->timeout = kbd_backlight_timeout;
1847 kbdbl_ctl->handle = handle; 1848 kbdbl_ctl->handle = handle;
1848 if (handle == 0x0137) 1849 if (handle == 0x0137)
1849 kbdbl_ctl->base = 0x0C00; 1850 kbdbl_ctl->base = 0x0C00;
@@ -1870,8 +1871,8 @@ static int sony_nc_kbd_backlight_setup(struct platform_device *pd,
1870 if (ret) 1871 if (ret)
1871 goto outmode; 1872 goto outmode;
1872 1873
1873 __sony_nc_kbd_backlight_mode_set(kbd_backlight); 1874 __sony_nc_kbd_backlight_mode_set(kbdbl_ctl->mode);
1874 __sony_nc_kbd_backlight_timeout_set(kbd_backlight_timeout); 1875 __sony_nc_kbd_backlight_timeout_set(kbdbl_ctl->timeout);
1875 1876
1876 return 0; 1877 return 0;
1877 1878
@@ -1886,17 +1887,8 @@ outkzalloc:
1886static void sony_nc_kbd_backlight_cleanup(struct platform_device *pd) 1887static void sony_nc_kbd_backlight_cleanup(struct platform_device *pd)
1887{ 1888{
1888 if (kbdbl_ctl) { 1889 if (kbdbl_ctl) {
1889 int result;
1890
1891 device_remove_file(&pd->dev, &kbdbl_ctl->mode_attr); 1890 device_remove_file(&pd->dev, &kbdbl_ctl->mode_attr);
1892 device_remove_file(&pd->dev, &kbdbl_ctl->timeout_attr); 1891 device_remove_file(&pd->dev, &kbdbl_ctl->timeout_attr);
1893
1894 /* restore the default hw behaviour */
1895 sony_call_snc_handle(kbdbl_ctl->handle,
1896 kbdbl_ctl->base | 0x10000, &result);
1897 sony_call_snc_handle(kbdbl_ctl->handle,
1898 kbdbl_ctl->base + 0x200, &result);
1899
1900 kfree(kbdbl_ctl); 1892 kfree(kbdbl_ctl);
1901 kbdbl_ctl = NULL; 1893 kbdbl_ctl = NULL;
1902 } 1894 }
diff --git a/drivers/s390/block/dasd_eckd.c b/drivers/s390/block/dasd_eckd.c
index 5adb2042e824..cee7e2708a1f 100644
--- a/drivers/s390/block/dasd_eckd.c
+++ b/drivers/s390/block/dasd_eckd.c
@@ -2077,6 +2077,7 @@ dasd_eckd_build_format(struct dasd_device *base,
2077 int intensity = 0; 2077 int intensity = 0;
2078 int r0_perm; 2078 int r0_perm;
2079 int nr_tracks; 2079 int nr_tracks;
2080 int use_prefix;
2080 2081
2081 startdev = dasd_alias_get_start_dev(base); 2082 startdev = dasd_alias_get_start_dev(base);
2082 if (!startdev) 2083 if (!startdev)
@@ -2106,28 +2107,46 @@ dasd_eckd_build_format(struct dasd_device *base,
2106 intensity = fdata->intensity; 2107 intensity = fdata->intensity;
2107 } 2108 }
2108 2109
2110 use_prefix = base_priv->features.feature[8] & 0x01;
2111
2109 switch (intensity) { 2112 switch (intensity) {
2110 case 0x00: /* Normal format */ 2113 case 0x00: /* Normal format */
2111 case 0x08: /* Normal format, use cdl. */ 2114 case 0x08: /* Normal format, use cdl. */
2112 cplength = 2 + (rpt*nr_tracks); 2115 cplength = 2 + (rpt*nr_tracks);
2113 datasize = sizeof(struct PFX_eckd_data) + 2116 if (use_prefix)
2114 sizeof(struct LO_eckd_data) + 2117 datasize = sizeof(struct PFX_eckd_data) +
2115 rpt * nr_tracks * sizeof(struct eckd_count); 2118 sizeof(struct LO_eckd_data) +
2119 rpt * nr_tracks * sizeof(struct eckd_count);
2120 else
2121 datasize = sizeof(struct DE_eckd_data) +
2122 sizeof(struct LO_eckd_data) +
2123 rpt * nr_tracks * sizeof(struct eckd_count);
2116 break; 2124 break;
2117 case 0x01: /* Write record zero and format track. */ 2125 case 0x01: /* Write record zero and format track. */
2118 case 0x09: /* Write record zero and format track, use cdl. */ 2126 case 0x09: /* Write record zero and format track, use cdl. */
2119 cplength = 2 + rpt * nr_tracks; 2127 cplength = 2 + rpt * nr_tracks;
2120 datasize = sizeof(struct PFX_eckd_data) + 2128 if (use_prefix)
2121 sizeof(struct LO_eckd_data) + 2129 datasize = sizeof(struct PFX_eckd_data) +
2122 sizeof(struct eckd_count) + 2130 sizeof(struct LO_eckd_data) +
2123 rpt * nr_tracks * sizeof(struct eckd_count); 2131 sizeof(struct eckd_count) +
2132 rpt * nr_tracks * sizeof(struct eckd_count);
2133 else
2134 datasize = sizeof(struct DE_eckd_data) +
2135 sizeof(struct LO_eckd_data) +
2136 sizeof(struct eckd_count) +
2137 rpt * nr_tracks * sizeof(struct eckd_count);
2124 break; 2138 break;
2125 case 0x04: /* Invalidate track. */ 2139 case 0x04: /* Invalidate track. */
2126 case 0x0c: /* Invalidate track, use cdl. */ 2140 case 0x0c: /* Invalidate track, use cdl. */
2127 cplength = 3; 2141 cplength = 3;
2128 datasize = sizeof(struct PFX_eckd_data) + 2142 if (use_prefix)
2129 sizeof(struct LO_eckd_data) + 2143 datasize = sizeof(struct PFX_eckd_data) +
2130 sizeof(struct eckd_count); 2144 sizeof(struct LO_eckd_data) +
2145 sizeof(struct eckd_count);
2146 else
2147 datasize = sizeof(struct DE_eckd_data) +
2148 sizeof(struct LO_eckd_data) +
2149 sizeof(struct eckd_count);
2131 break; 2150 break;
2132 default: 2151 default:
2133 dev_warn(&startdev->cdev->dev, 2152 dev_warn(&startdev->cdev->dev,
@@ -2147,14 +2166,25 @@ dasd_eckd_build_format(struct dasd_device *base,
2147 2166
2148 switch (intensity & ~0x08) { 2167 switch (intensity & ~0x08) {
2149 case 0x00: /* Normal format. */ 2168 case 0x00: /* Normal format. */
2150 prefix(ccw++, (struct PFX_eckd_data *) data, 2169 if (use_prefix) {
2151 fdata->start_unit, fdata->stop_unit, 2170 prefix(ccw++, (struct PFX_eckd_data *) data,
2152 DASD_ECKD_CCW_WRITE_CKD, base, startdev); 2171 fdata->start_unit, fdata->stop_unit,
2153 /* grant subsystem permission to format R0 */ 2172 DASD_ECKD_CCW_WRITE_CKD, base, startdev);
2154 if (r0_perm) 2173 /* grant subsystem permission to format R0 */
2155 ((struct PFX_eckd_data *)data) 2174 if (r0_perm)
2156 ->define_extent.ga_extended |= 0x04; 2175 ((struct PFX_eckd_data *)data)
2157 data += sizeof(struct PFX_eckd_data); 2176 ->define_extent.ga_extended |= 0x04;
2177 data += sizeof(struct PFX_eckd_data);
2178 } else {
2179 define_extent(ccw++, (struct DE_eckd_data *) data,
2180 fdata->start_unit, fdata->stop_unit,
2181 DASD_ECKD_CCW_WRITE_CKD, startdev);
2182 /* grant subsystem permission to format R0 */
2183 if (r0_perm)
2184 ((struct DE_eckd_data *) data)
2185 ->ga_extended |= 0x04;
2186 data += sizeof(struct DE_eckd_data);
2187 }
2158 ccw[-1].flags |= CCW_FLAG_CC; 2188 ccw[-1].flags |= CCW_FLAG_CC;
2159 locate_record(ccw++, (struct LO_eckd_data *) data, 2189 locate_record(ccw++, (struct LO_eckd_data *) data,
2160 fdata->start_unit, 0, rpt*nr_tracks, 2190 fdata->start_unit, 0, rpt*nr_tracks,
@@ -2163,11 +2193,18 @@ dasd_eckd_build_format(struct dasd_device *base,
2163 data += sizeof(struct LO_eckd_data); 2193 data += sizeof(struct LO_eckd_data);
2164 break; 2194 break;
2165 case 0x01: /* Write record zero + format track. */ 2195 case 0x01: /* Write record zero + format track. */
2166 prefix(ccw++, (struct PFX_eckd_data *) data, 2196 if (use_prefix) {
2167 fdata->start_unit, fdata->stop_unit, 2197 prefix(ccw++, (struct PFX_eckd_data *) data,
2168 DASD_ECKD_CCW_WRITE_RECORD_ZERO, 2198 fdata->start_unit, fdata->stop_unit,
2169 base, startdev); 2199 DASD_ECKD_CCW_WRITE_RECORD_ZERO,
2170 data += sizeof(struct PFX_eckd_data); 2200 base, startdev);
2201 data += sizeof(struct PFX_eckd_data);
2202 } else {
2203 define_extent(ccw++, (struct DE_eckd_data *) data,
2204 fdata->start_unit, fdata->stop_unit,
2205 DASD_ECKD_CCW_WRITE_RECORD_ZERO, startdev);
2206 data += sizeof(struct DE_eckd_data);
2207 }
2171 ccw[-1].flags |= CCW_FLAG_CC; 2208 ccw[-1].flags |= CCW_FLAG_CC;
2172 locate_record(ccw++, (struct LO_eckd_data *) data, 2209 locate_record(ccw++, (struct LO_eckd_data *) data,
2173 fdata->start_unit, 0, rpt * nr_tracks + 1, 2210 fdata->start_unit, 0, rpt * nr_tracks + 1,
@@ -2176,10 +2213,17 @@ dasd_eckd_build_format(struct dasd_device *base,
2176 data += sizeof(struct LO_eckd_data); 2213 data += sizeof(struct LO_eckd_data);
2177 break; 2214 break;
2178 case 0x04: /* Invalidate track. */ 2215 case 0x04: /* Invalidate track. */
2179 prefix(ccw++, (struct PFX_eckd_data *) data, 2216 if (use_prefix) {
2180 fdata->start_unit, fdata->stop_unit, 2217 prefix(ccw++, (struct PFX_eckd_data *) data,
2181 DASD_ECKD_CCW_WRITE_CKD, base, startdev); 2218 fdata->start_unit, fdata->stop_unit,
2182 data += sizeof(struct PFX_eckd_data); 2219 DASD_ECKD_CCW_WRITE_CKD, base, startdev);
2220 data += sizeof(struct PFX_eckd_data);
2221 } else {
2222 define_extent(ccw++, (struct DE_eckd_data *) data,
2223 fdata->start_unit, fdata->stop_unit,
2224 DASD_ECKD_CCW_WRITE_CKD, startdev);
2225 data += sizeof(struct DE_eckd_data);
2226 }
2183 ccw[-1].flags |= CCW_FLAG_CC; 2227 ccw[-1].flags |= CCW_FLAG_CC;
2184 locate_record(ccw++, (struct LO_eckd_data *) data, 2228 locate_record(ccw++, (struct LO_eckd_data *) data,
2185 fdata->start_unit, 0, 1, 2229 fdata->start_unit, 0, 1,
diff --git a/drivers/s390/char/sclp.c b/drivers/s390/char/sclp.c
index a3aa374799dc..1fe264379e0d 100644
--- a/drivers/s390/char/sclp.c
+++ b/drivers/s390/char/sclp.c
@@ -486,7 +486,7 @@ sclp_sync_wait(void)
486 timeout = 0; 486 timeout = 0;
487 if (timer_pending(&sclp_request_timer)) { 487 if (timer_pending(&sclp_request_timer)) {
488 /* Get timeout TOD value */ 488 /* Get timeout TOD value */
489 timeout = get_tod_clock() + 489 timeout = get_tod_clock_fast() +
490 sclp_tod_from_jiffies(sclp_request_timer.expires - 490 sclp_tod_from_jiffies(sclp_request_timer.expires -
491 jiffies); 491 jiffies);
492 } 492 }
@@ -508,7 +508,7 @@ sclp_sync_wait(void)
508 while (sclp_running_state != sclp_running_state_idle) { 508 while (sclp_running_state != sclp_running_state_idle) {
509 /* Check for expired request timer */ 509 /* Check for expired request timer */
510 if (timer_pending(&sclp_request_timer) && 510 if (timer_pending(&sclp_request_timer) &&
511 get_tod_clock() > timeout && 511 get_tod_clock_fast() > timeout &&
512 del_timer(&sclp_request_timer)) 512 del_timer(&sclp_request_timer))
513 sclp_request_timer.function(sclp_request_timer.data); 513 sclp_request_timer.function(sclp_request_timer.data);
514 cpu_relax(); 514 cpu_relax();
diff --git a/drivers/s390/char/vmlogrdr.c b/drivers/s390/char/vmlogrdr.c
index 9b3a24e8d3a0..cf31d3321dab 100644
--- a/drivers/s390/char/vmlogrdr.c
+++ b/drivers/s390/char/vmlogrdr.c
@@ -313,7 +313,7 @@ static int vmlogrdr_open (struct inode *inode, struct file *filp)
313 int ret; 313 int ret;
314 314
315 dev_num = iminor(inode); 315 dev_num = iminor(inode);
316 if (dev_num > MAXMINOR) 316 if (dev_num >= MAXMINOR)
317 return -ENODEV; 317 return -ENODEV;
318 logptr = &sys_ser[dev_num]; 318 logptr = &sys_ser[dev_num];
319 319
diff --git a/drivers/s390/cio/cio.c b/drivers/s390/cio/cio.c
index d7da67a31c77..88e35d85d205 100644
--- a/drivers/s390/cio/cio.c
+++ b/drivers/s390/cio/cio.c
@@ -878,9 +878,9 @@ static void css_reset(void)
878 atomic_inc(&chpid_reset_count); 878 atomic_inc(&chpid_reset_count);
879 } 879 }
880 /* Wait for machine check for all channel paths. */ 880 /* Wait for machine check for all channel paths. */
881 timeout = get_tod_clock() + (RCHP_TIMEOUT << 12); 881 timeout = get_tod_clock_fast() + (RCHP_TIMEOUT << 12);
882 while (atomic_read(&chpid_reset_count) != 0) { 882 while (atomic_read(&chpid_reset_count) != 0) {
883 if (get_tod_clock() > timeout) 883 if (get_tod_clock_fast() > timeout)
884 break; 884 break;
885 cpu_relax(); 885 cpu_relax();
886 } 886 }
diff --git a/drivers/s390/cio/qdio_main.c b/drivers/s390/cio/qdio_main.c
index 8ed52aa49122..bbd3e511c771 100644
--- a/drivers/s390/cio/qdio_main.c
+++ b/drivers/s390/cio/qdio_main.c
@@ -338,10 +338,10 @@ again:
338 retries++; 338 retries++;
339 339
340 if (!start_time) { 340 if (!start_time) {
341 start_time = get_tod_clock(); 341 start_time = get_tod_clock_fast();
342 goto again; 342 goto again;
343 } 343 }
344 if ((get_tod_clock() - start_time) < QDIO_BUSY_BIT_PATIENCE) 344 if (get_tod_clock_fast() - start_time < QDIO_BUSY_BIT_PATIENCE)
345 goto again; 345 goto again;
346 } 346 }
347 if (retries) { 347 if (retries) {
@@ -504,7 +504,7 @@ static int get_inbound_buffer_frontier(struct qdio_q *q)
504 int count, stop; 504 int count, stop;
505 unsigned char state = 0; 505 unsigned char state = 0;
506 506
507 q->timestamp = get_tod_clock(); 507 q->timestamp = get_tod_clock_fast();
508 508
509 /* 509 /*
510 * Don't check 128 buffers, as otherwise qdio_inbound_q_moved 510 * Don't check 128 buffers, as otherwise qdio_inbound_q_moved
@@ -595,7 +595,7 @@ static inline int qdio_inbound_q_done(struct qdio_q *q)
595 * At this point we know, that inbound first_to_check 595 * At this point we know, that inbound first_to_check
596 * has (probably) not moved (see qdio_inbound_processing). 596 * has (probably) not moved (see qdio_inbound_processing).
597 */ 597 */
598 if (get_tod_clock() > q->u.in.timestamp + QDIO_INPUT_THRESHOLD) { 598 if (get_tod_clock_fast() > q->u.in.timestamp + QDIO_INPUT_THRESHOLD) {
599 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "in done:%02x", 599 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "in done:%02x",
600 q->first_to_check); 600 q->first_to_check);
601 return 1; 601 return 1;
@@ -728,7 +728,7 @@ static int get_outbound_buffer_frontier(struct qdio_q *q)
728 int count, stop; 728 int count, stop;
729 unsigned char state = 0; 729 unsigned char state = 0;
730 730
731 q->timestamp = get_tod_clock(); 731 q->timestamp = get_tod_clock_fast();
732 732
733 if (need_siga_sync(q)) 733 if (need_siga_sync(q))
734 if (((queue_type(q) != QDIO_IQDIO_QFMT) && 734 if (((queue_type(q) != QDIO_IQDIO_QFMT) &&
diff --git a/drivers/scsi/BusLogic.c b/drivers/scsi/BusLogic.c
index feab3a5e50b5..757eb0716d45 100644
--- a/drivers/scsi/BusLogic.c
+++ b/drivers/scsi/BusLogic.c
@@ -696,7 +696,7 @@ static int __init blogic_init_mm_probeinfo(struct blogic_adapter *adapter)
696 while ((pci_device = pci_get_device(PCI_VENDOR_ID_BUSLOGIC, 696 while ((pci_device = pci_get_device(PCI_VENDOR_ID_BUSLOGIC,
697 PCI_DEVICE_ID_BUSLOGIC_MULTIMASTER, 697 PCI_DEVICE_ID_BUSLOGIC_MULTIMASTER,
698 pci_device)) != NULL) { 698 pci_device)) != NULL) {
699 struct blogic_adapter *adapter = adapter; 699 struct blogic_adapter *host_adapter = adapter;
700 struct blogic_adapter_info adapter_info; 700 struct blogic_adapter_info adapter_info;
701 enum blogic_isa_ioport mod_ioaddr_req; 701 enum blogic_isa_ioport mod_ioaddr_req;
702 unsigned char bus; 702 unsigned char bus;
@@ -744,9 +744,9 @@ static int __init blogic_init_mm_probeinfo(struct blogic_adapter *adapter)
744 known and enabled, note that the particular Standard ISA I/O 744 known and enabled, note that the particular Standard ISA I/O
745 Address should not be probed. 745 Address should not be probed.
746 */ 746 */
747 adapter->io_addr = io_addr; 747 host_adapter->io_addr = io_addr;
748 blogic_intreset(adapter); 748 blogic_intreset(host_adapter);
749 if (blogic_cmd(adapter, BLOGIC_INQ_PCI_INFO, NULL, 0, 749 if (blogic_cmd(host_adapter, BLOGIC_INQ_PCI_INFO, NULL, 0,
750 &adapter_info, sizeof(adapter_info)) == 750 &adapter_info, sizeof(adapter_info)) ==
751 sizeof(adapter_info)) { 751 sizeof(adapter_info)) {
752 if (adapter_info.isa_port < 6) 752 if (adapter_info.isa_port < 6)
@@ -762,7 +762,7 @@ static int __init blogic_init_mm_probeinfo(struct blogic_adapter *adapter)
762 I/O Address assigned at system initialization. 762 I/O Address assigned at system initialization.
763 */ 763 */
764 mod_ioaddr_req = BLOGIC_IO_DISABLE; 764 mod_ioaddr_req = BLOGIC_IO_DISABLE;
765 blogic_cmd(adapter, BLOGIC_MOD_IOADDR, &mod_ioaddr_req, 765 blogic_cmd(host_adapter, BLOGIC_MOD_IOADDR, &mod_ioaddr_req,
766 sizeof(mod_ioaddr_req), NULL, 0); 766 sizeof(mod_ioaddr_req), NULL, 0);
767 /* 767 /*
768 For the first MultiMaster Host Adapter enumerated, 768 For the first MultiMaster Host Adapter enumerated,
@@ -779,12 +779,12 @@ static int __init blogic_init_mm_probeinfo(struct blogic_adapter *adapter)
779 779
780 fetch_localram.offset = BLOGIC_AUTOSCSI_BASE + 45; 780 fetch_localram.offset = BLOGIC_AUTOSCSI_BASE + 45;
781 fetch_localram.count = sizeof(autoscsi_byte45); 781 fetch_localram.count = sizeof(autoscsi_byte45);
782 blogic_cmd(adapter, BLOGIC_FETCH_LOCALRAM, 782 blogic_cmd(host_adapter, BLOGIC_FETCH_LOCALRAM,
783 &fetch_localram, sizeof(fetch_localram), 783 &fetch_localram, sizeof(fetch_localram),
784 &autoscsi_byte45, 784 &autoscsi_byte45,
785 sizeof(autoscsi_byte45)); 785 sizeof(autoscsi_byte45));
786 blogic_cmd(adapter, BLOGIC_GET_BOARD_ID, NULL, 0, &id, 786 blogic_cmd(host_adapter, BLOGIC_GET_BOARD_ID, NULL, 0,
787 sizeof(id)); 787 &id, sizeof(id));
788 if (id.fw_ver_digit1 == '5') 788 if (id.fw_ver_digit1 == '5')
789 force_scan_order = 789 force_scan_order =
790 autoscsi_byte45.force_scan_order; 790 autoscsi_byte45.force_scan_order;
diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
index 408a42ef787a..f0d432c139d0 100644
--- a/drivers/scsi/aacraid/linit.c
+++ b/drivers/scsi/aacraid/linit.c
@@ -771,6 +771,8 @@ static long aac_compat_do_ioctl(struct aac_dev *dev, unsigned cmd, unsigned long
771static int aac_compat_ioctl(struct scsi_device *sdev, int cmd, void __user *arg) 771static int aac_compat_ioctl(struct scsi_device *sdev, int cmd, void __user *arg)
772{ 772{
773 struct aac_dev *dev = (struct aac_dev *)sdev->host->hostdata; 773 struct aac_dev *dev = (struct aac_dev *)sdev->host->hostdata;
774 if (!capable(CAP_SYS_RAWIO))
775 return -EPERM;
774 return aac_compat_do_ioctl(dev, cmd, (unsigned long)arg); 776 return aac_compat_do_ioctl(dev, cmd, (unsigned long)arg);
775} 777}
776 778
diff --git a/drivers/scsi/qla2xxx/qla_dbg.c b/drivers/scsi/qla2xxx/qla_dbg.c
index 2ef497ebadc0..ee5c1833eb73 100644
--- a/drivers/scsi/qla2xxx/qla_dbg.c
+++ b/drivers/scsi/qla2xxx/qla_dbg.c
@@ -20,7 +20,7 @@
20 * | Device Discovery | 0x2095 | 0x2020-0x2022, | 20 * | Device Discovery | 0x2095 | 0x2020-0x2022, |
21 * | | | 0x2011-0x2012, | 21 * | | | 0x2011-0x2012, |
22 * | | | 0x2016 | 22 * | | | 0x2016 |
23 * | Queue Command and IO tracing | 0x3058 | 0x3006-0x300b | 23 * | Queue Command and IO tracing | 0x3059 | 0x3006-0x300b |
24 * | | | 0x3027-0x3028 | 24 * | | | 0x3027-0x3028 |
25 * | | | 0x303d-0x3041 | 25 * | | | 0x303d-0x3041 |
26 * | | | 0x302d,0x3033 | 26 * | | | 0x302d,0x3033 |
diff --git a/drivers/scsi/qla2xxx/qla_isr.c b/drivers/scsi/qla2xxx/qla_isr.c
index df1b30ba938c..ff9c86b1a0d8 100644
--- a/drivers/scsi/qla2xxx/qla_isr.c
+++ b/drivers/scsi/qla2xxx/qla_isr.c
@@ -1957,6 +1957,15 @@ qla2x00_status_entry(scsi_qla_host_t *vha, struct rsp_que *rsp, void *pkt)
1957 que = MSW(sts->handle); 1957 que = MSW(sts->handle);
1958 req = ha->req_q_map[que]; 1958 req = ha->req_q_map[que];
1959 1959
1960 /* Check for invalid queue pointer */
1961 if (req == NULL ||
1962 que >= find_first_zero_bit(ha->req_qid_map, ha->max_req_queues)) {
1963 ql_dbg(ql_dbg_io, vha, 0x3059,
1964 "Invalid status handle (0x%x): Bad req pointer. req=%p, "
1965 "que=%u.\n", sts->handle, req, que);
1966 return;
1967 }
1968
1960 /* Validate handle. */ 1969 /* Validate handle. */
1961 if (handle < req->num_outstanding_cmds) 1970 if (handle < req->num_outstanding_cmds)
1962 sp = req->outstanding_cmds[handle]; 1971 sp = req->outstanding_cmds[handle];
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index e62d17d41d4e..5693f6d7eddb 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -2854,6 +2854,7 @@ static void sd_probe_async(void *data, async_cookie_t cookie)
2854 gd->events |= DISK_EVENT_MEDIA_CHANGE; 2854 gd->events |= DISK_EVENT_MEDIA_CHANGE;
2855 } 2855 }
2856 2856
2857 blk_pm_runtime_init(sdp->request_queue, dev);
2857 add_disk(gd); 2858 add_disk(gd);
2858 if (sdkp->capacity) 2859 if (sdkp->capacity)
2859 sd_dif_config_host(sdkp); 2860 sd_dif_config_host(sdkp);
@@ -2862,7 +2863,6 @@ static void sd_probe_async(void *data, async_cookie_t cookie)
2862 2863
2863 sd_printk(KERN_NOTICE, sdkp, "Attached SCSI %sdisk\n", 2864 sd_printk(KERN_NOTICE, sdkp, "Attached SCSI %sdisk\n",
2864 sdp->removable ? "removable " : ""); 2865 sdp->removable ? "removable " : "");
2865 blk_pm_runtime_init(sdp->request_queue, dev);
2866 scsi_autopm_put_device(sdp); 2866 scsi_autopm_put_device(sdp);
2867 put_device(&sdkp->dev); 2867 put_device(&sdkp->dev);
2868} 2868}
diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index 5cbc4bb1b395..df5e961484e1 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -105,8 +105,11 @@ static int scatter_elem_sz_prev = SG_SCATTER_SZ;
105static int sg_add(struct device *, struct class_interface *); 105static int sg_add(struct device *, struct class_interface *);
106static void sg_remove(struct device *, struct class_interface *); 106static void sg_remove(struct device *, struct class_interface *);
107 107
108static DEFINE_SPINLOCK(sg_open_exclusive_lock);
109
108static DEFINE_IDR(sg_index_idr); 110static DEFINE_IDR(sg_index_idr);
109static DEFINE_RWLOCK(sg_index_lock); 111static DEFINE_RWLOCK(sg_index_lock); /* Also used to lock
112 file descriptor list for device */
110 113
111static struct class_interface sg_interface = { 114static struct class_interface sg_interface = {
112 .add_dev = sg_add, 115 .add_dev = sg_add,
@@ -143,7 +146,8 @@ typedef struct sg_request { /* SG_MAX_QUEUE requests outstanding per file */
143} Sg_request; 146} Sg_request;
144 147
145typedef struct sg_fd { /* holds the state of a file descriptor */ 148typedef struct sg_fd { /* holds the state of a file descriptor */
146 struct list_head sfd_siblings; /* protected by sfd_lock of device */ 149 /* sfd_siblings is protected by sg_index_lock */
150 struct list_head sfd_siblings;
147 struct sg_device *parentdp; /* owning device */ 151 struct sg_device *parentdp; /* owning device */
148 wait_queue_head_t read_wait; /* queue read until command done */ 152 wait_queue_head_t read_wait; /* queue read until command done */
149 rwlock_t rq_list_lock; /* protect access to list in req_arr */ 153 rwlock_t rq_list_lock; /* protect access to list in req_arr */
@@ -166,12 +170,13 @@ typedef struct sg_fd { /* holds the state of a file descriptor */
166 170
167typedef struct sg_device { /* holds the state of each scsi generic device */ 171typedef struct sg_device { /* holds the state of each scsi generic device */
168 struct scsi_device *device; 172 struct scsi_device *device;
173 wait_queue_head_t o_excl_wait; /* queue open() when O_EXCL in use */
169 int sg_tablesize; /* adapter's max scatter-gather table size */ 174 int sg_tablesize; /* adapter's max scatter-gather table size */
170 u32 index; /* device index number */ 175 u32 index; /* device index number */
171 spinlock_t sfd_lock; /* protect file descriptor list for device */ 176 /* sfds is protected by sg_index_lock */
172 struct list_head sfds; 177 struct list_head sfds;
173 struct rw_semaphore o_sem; /* exclude open should hold this rwsem */
174 volatile char detached; /* 0->attached, 1->detached pending removal */ 178 volatile char detached; /* 0->attached, 1->detached pending removal */
179 /* exclude protected by sg_open_exclusive_lock */
175 char exclude; /* opened for exclusive access */ 180 char exclude; /* opened for exclusive access */
176 char sgdebug; /* 0->off, 1->sense, 9->dump dev, 10-> all devs */ 181 char sgdebug; /* 0->off, 1->sense, 9->dump dev, 10-> all devs */
177 struct gendisk *disk; 182 struct gendisk *disk;
@@ -220,14 +225,35 @@ static int sg_allow_access(struct file *filp, unsigned char *cmd)
220 return blk_verify_command(cmd, filp->f_mode & FMODE_WRITE); 225 return blk_verify_command(cmd, filp->f_mode & FMODE_WRITE);
221} 226}
222 227
228static int get_exclude(Sg_device *sdp)
229{
230 unsigned long flags;
231 int ret;
232
233 spin_lock_irqsave(&sg_open_exclusive_lock, flags);
234 ret = sdp->exclude;
235 spin_unlock_irqrestore(&sg_open_exclusive_lock, flags);
236 return ret;
237}
238
239static int set_exclude(Sg_device *sdp, char val)
240{
241 unsigned long flags;
242
243 spin_lock_irqsave(&sg_open_exclusive_lock, flags);
244 sdp->exclude = val;
245 spin_unlock_irqrestore(&sg_open_exclusive_lock, flags);
246 return val;
247}
248
223static int sfds_list_empty(Sg_device *sdp) 249static int sfds_list_empty(Sg_device *sdp)
224{ 250{
225 unsigned long flags; 251 unsigned long flags;
226 int ret; 252 int ret;
227 253
228 spin_lock_irqsave(&sdp->sfd_lock, flags); 254 read_lock_irqsave(&sg_index_lock, flags);
229 ret = list_empty(&sdp->sfds); 255 ret = list_empty(&sdp->sfds);
230 spin_unlock_irqrestore(&sdp->sfd_lock, flags); 256 read_unlock_irqrestore(&sg_index_lock, flags);
231 return ret; 257 return ret;
232} 258}
233 259
@@ -239,6 +265,7 @@ sg_open(struct inode *inode, struct file *filp)
239 struct request_queue *q; 265 struct request_queue *q;
240 Sg_device *sdp; 266 Sg_device *sdp;
241 Sg_fd *sfp; 267 Sg_fd *sfp;
268 int res;
242 int retval; 269 int retval;
243 270
244 nonseekable_open(inode, filp); 271 nonseekable_open(inode, filp);
@@ -267,52 +294,54 @@ sg_open(struct inode *inode, struct file *filp)
267 goto error_out; 294 goto error_out;
268 } 295 }
269 296
270 if ((flags & O_EXCL) && (O_RDONLY == (flags & O_ACCMODE))) { 297 if (flags & O_EXCL) {
271 retval = -EPERM; /* Can't lock it with read only access */ 298 if (O_RDONLY == (flags & O_ACCMODE)) {
272 goto error_out; 299 retval = -EPERM; /* Can't lock it with read only access */
273 } 300 goto error_out;
274 if (flags & O_NONBLOCK) { 301 }
275 if (flags & O_EXCL) { 302 if (!sfds_list_empty(sdp) && (flags & O_NONBLOCK)) {
276 if (!down_write_trylock(&sdp->o_sem)) { 303 retval = -EBUSY;
277 retval = -EBUSY; 304 goto error_out;
278 goto error_out; 305 }
279 } 306 res = wait_event_interruptible(sdp->o_excl_wait,
280 } else { 307 ((!sfds_list_empty(sdp) || get_exclude(sdp)) ? 0 : set_exclude(sdp, 1)));
281 if (!down_read_trylock(&sdp->o_sem)) { 308 if (res) {
282 retval = -EBUSY; 309 retval = res; /* -ERESTARTSYS because signal hit process */
283 goto error_out; 310 goto error_out;
284 } 311 }
312 } else if (get_exclude(sdp)) { /* some other fd has an exclusive lock on dev */
313 if (flags & O_NONBLOCK) {
314 retval = -EBUSY;
315 goto error_out;
316 }
317 res = wait_event_interruptible(sdp->o_excl_wait, !get_exclude(sdp));
318 if (res) {
319 retval = res; /* -ERESTARTSYS because signal hit process */
320 goto error_out;
285 } 321 }
286 } else {
287 if (flags & O_EXCL)
288 down_write(&sdp->o_sem);
289 else
290 down_read(&sdp->o_sem);
291 } 322 }
292 /* Since write lock is held, no need to check sfd_list */ 323 if (sdp->detached) {
293 if (flags & O_EXCL) 324 retval = -ENODEV;
294 sdp->exclude = 1; /* used by release lock */ 325 goto error_out;
295 326 }
296 if (sfds_list_empty(sdp)) { /* no existing opens on this device */ 327 if (sfds_list_empty(sdp)) { /* no existing opens on this device */
297 sdp->sgdebug = 0; 328 sdp->sgdebug = 0;
298 q = sdp->device->request_queue; 329 q = sdp->device->request_queue;
299 sdp->sg_tablesize = queue_max_segments(q); 330 sdp->sg_tablesize = queue_max_segments(q);
300 } 331 }
301 sfp = sg_add_sfp(sdp, dev); 332 if ((sfp = sg_add_sfp(sdp, dev)))
302 if (!IS_ERR(sfp))
303 filp->private_data = sfp; 333 filp->private_data = sfp;
304 /* retval is already provably zero at this point because of the
305 * check after retval = scsi_autopm_get_device(sdp->device))
306 */
307 else { 334 else {
308 retval = PTR_ERR(sfp);
309
310 if (flags & O_EXCL) { 335 if (flags & O_EXCL) {
311 sdp->exclude = 0; /* undo if error */ 336 set_exclude(sdp, 0); /* undo if error */
312 up_write(&sdp->o_sem); 337 wake_up_interruptible(&sdp->o_excl_wait);
313 } else 338 }
314 up_read(&sdp->o_sem); 339 retval = -ENOMEM;
340 goto error_out;
341 }
342 retval = 0;
315error_out: 343error_out:
344 if (retval) {
316 scsi_autopm_put_device(sdp->device); 345 scsi_autopm_put_device(sdp->device);
317sdp_put: 346sdp_put:
318 scsi_device_put(sdp->device); 347 scsi_device_put(sdp->device);
@@ -329,18 +358,13 @@ sg_release(struct inode *inode, struct file *filp)
329{ 358{
330 Sg_device *sdp; 359 Sg_device *sdp;
331 Sg_fd *sfp; 360 Sg_fd *sfp;
332 int excl;
333 361
334 if ((!(sfp = (Sg_fd *) filp->private_data)) || (!(sdp = sfp->parentdp))) 362 if ((!(sfp = (Sg_fd *) filp->private_data)) || (!(sdp = sfp->parentdp)))
335 return -ENXIO; 363 return -ENXIO;
336 SCSI_LOG_TIMEOUT(3, printk("sg_release: %s\n", sdp->disk->disk_name)); 364 SCSI_LOG_TIMEOUT(3, printk("sg_release: %s\n", sdp->disk->disk_name));
337 365
338 excl = sdp->exclude; 366 set_exclude(sdp, 0);
339 sdp->exclude = 0; 367 wake_up_interruptible(&sdp->o_excl_wait);
340 if (excl)
341 up_write(&sdp->o_sem);
342 else
343 up_read(&sdp->o_sem);
344 368
345 scsi_autopm_put_device(sdp->device); 369 scsi_autopm_put_device(sdp->device);
346 kref_put(&sfp->f_ref, sg_remove_sfp); 370 kref_put(&sfp->f_ref, sg_remove_sfp);
@@ -1391,9 +1415,8 @@ static Sg_device *sg_alloc(struct gendisk *disk, struct scsi_device *scsidp)
1391 disk->first_minor = k; 1415 disk->first_minor = k;
1392 sdp->disk = disk; 1416 sdp->disk = disk;
1393 sdp->device = scsidp; 1417 sdp->device = scsidp;
1394 spin_lock_init(&sdp->sfd_lock);
1395 INIT_LIST_HEAD(&sdp->sfds); 1418 INIT_LIST_HEAD(&sdp->sfds);
1396 init_rwsem(&sdp->o_sem); 1419 init_waitqueue_head(&sdp->o_excl_wait);
1397 sdp->sg_tablesize = queue_max_segments(q); 1420 sdp->sg_tablesize = queue_max_segments(q);
1398 sdp->index = k; 1421 sdp->index = k;
1399 kref_init(&sdp->d_ref); 1422 kref_init(&sdp->d_ref);
@@ -1526,13 +1549,11 @@ static void sg_remove(struct device *cl_dev, struct class_interface *cl_intf)
1526 1549
1527 /* Need a write lock to set sdp->detached. */ 1550 /* Need a write lock to set sdp->detached. */
1528 write_lock_irqsave(&sg_index_lock, iflags); 1551 write_lock_irqsave(&sg_index_lock, iflags);
1529 spin_lock(&sdp->sfd_lock);
1530 sdp->detached = 1; 1552 sdp->detached = 1;
1531 list_for_each_entry(sfp, &sdp->sfds, sfd_siblings) { 1553 list_for_each_entry(sfp, &sdp->sfds, sfd_siblings) {
1532 wake_up_interruptible(&sfp->read_wait); 1554 wake_up_interruptible(&sfp->read_wait);
1533 kill_fasync(&sfp->async_qp, SIGPOLL, POLL_HUP); 1555 kill_fasync(&sfp->async_qp, SIGPOLL, POLL_HUP);
1534 } 1556 }
1535 spin_unlock(&sdp->sfd_lock);
1536 write_unlock_irqrestore(&sg_index_lock, iflags); 1557 write_unlock_irqrestore(&sg_index_lock, iflags);
1537 1558
1538 sysfs_remove_link(&scsidp->sdev_gendev.kobj, "generic"); 1559 sysfs_remove_link(&scsidp->sdev_gendev.kobj, "generic");
@@ -2043,7 +2064,7 @@ sg_add_sfp(Sg_device * sdp, int dev)
2043 2064
2044 sfp = kzalloc(sizeof(*sfp), GFP_ATOMIC | __GFP_NOWARN); 2065 sfp = kzalloc(sizeof(*sfp), GFP_ATOMIC | __GFP_NOWARN);
2045 if (!sfp) 2066 if (!sfp)
2046 return ERR_PTR(-ENOMEM); 2067 return NULL;
2047 2068
2048 init_waitqueue_head(&sfp->read_wait); 2069 init_waitqueue_head(&sfp->read_wait);
2049 rwlock_init(&sfp->rq_list_lock); 2070 rwlock_init(&sfp->rq_list_lock);
@@ -2057,13 +2078,9 @@ sg_add_sfp(Sg_device * sdp, int dev)
2057 sfp->cmd_q = SG_DEF_COMMAND_Q; 2078 sfp->cmd_q = SG_DEF_COMMAND_Q;
2058 sfp->keep_orphan = SG_DEF_KEEP_ORPHAN; 2079 sfp->keep_orphan = SG_DEF_KEEP_ORPHAN;
2059 sfp->parentdp = sdp; 2080 sfp->parentdp = sdp;
2060 spin_lock_irqsave(&sdp->sfd_lock, iflags); 2081 write_lock_irqsave(&sg_index_lock, iflags);
2061 if (sdp->detached) {
2062 spin_unlock_irqrestore(&sdp->sfd_lock, iflags);
2063 return ERR_PTR(-ENODEV);
2064 }
2065 list_add_tail(&sfp->sfd_siblings, &sdp->sfds); 2082 list_add_tail(&sfp->sfd_siblings, &sdp->sfds);
2066 spin_unlock_irqrestore(&sdp->sfd_lock, iflags); 2083 write_unlock_irqrestore(&sg_index_lock, iflags);
2067 SCSI_LOG_TIMEOUT(3, printk("sg_add_sfp: sfp=0x%p\n", sfp)); 2084 SCSI_LOG_TIMEOUT(3, printk("sg_add_sfp: sfp=0x%p\n", sfp));
2068 if (unlikely(sg_big_buff != def_reserved_size)) 2085 if (unlikely(sg_big_buff != def_reserved_size))
2069 sg_big_buff = def_reserved_size; 2086 sg_big_buff = def_reserved_size;
@@ -2113,9 +2130,10 @@ static void sg_remove_sfp(struct kref *kref)
2113 struct sg_device *sdp = sfp->parentdp; 2130 struct sg_device *sdp = sfp->parentdp;
2114 unsigned long iflags; 2131 unsigned long iflags;
2115 2132
2116 spin_lock_irqsave(&sdp->sfd_lock, iflags); 2133 write_lock_irqsave(&sg_index_lock, iflags);
2117 list_del(&sfp->sfd_siblings); 2134 list_del(&sfp->sfd_siblings);
2118 spin_unlock_irqrestore(&sdp->sfd_lock, iflags); 2135 write_unlock_irqrestore(&sg_index_lock, iflags);
2136 wake_up_interruptible(&sdp->o_excl_wait);
2119 2137
2120 INIT_WORK(&sfp->ew.work, sg_remove_sfp_usercontext); 2138 INIT_WORK(&sfp->ew.work, sg_remove_sfp_usercontext);
2121 schedule_work(&sfp->ew.work); 2139 schedule_work(&sfp->ew.work);
@@ -2502,7 +2520,7 @@ static int sg_proc_seq_show_devstrs(struct seq_file *s, void *v)
2502 return 0; 2520 return 0;
2503} 2521}
2504 2522
2505/* must be called while holding sg_index_lock and sfd_lock */ 2523/* must be called while holding sg_index_lock */
2506static void sg_proc_debug_helper(struct seq_file *s, Sg_device * sdp) 2524static void sg_proc_debug_helper(struct seq_file *s, Sg_device * sdp)
2507{ 2525{
2508 int k, m, new_interface, blen, usg; 2526 int k, m, new_interface, blen, usg;
@@ -2587,26 +2605,22 @@ static int sg_proc_seq_show_debug(struct seq_file *s, void *v)
2587 2605
2588 read_lock_irqsave(&sg_index_lock, iflags); 2606 read_lock_irqsave(&sg_index_lock, iflags);
2589 sdp = it ? sg_lookup_dev(it->index) : NULL; 2607 sdp = it ? sg_lookup_dev(it->index) : NULL;
2590 if (sdp) { 2608 if (sdp && !list_empty(&sdp->sfds)) {
2591 spin_lock(&sdp->sfd_lock); 2609 struct scsi_device *scsidp = sdp->device;
2592 if (!list_empty(&sdp->sfds)) {
2593 struct scsi_device *scsidp = sdp->device;
2594 2610
2595 seq_printf(s, " >>> device=%s ", sdp->disk->disk_name); 2611 seq_printf(s, " >>> device=%s ", sdp->disk->disk_name);
2596 if (sdp->detached) 2612 if (sdp->detached)
2597 seq_printf(s, "detached pending close "); 2613 seq_printf(s, "detached pending close ");
2598 else 2614 else
2599 seq_printf 2615 seq_printf
2600 (s, "scsi%d chan=%d id=%d lun=%d em=%d", 2616 (s, "scsi%d chan=%d id=%d lun=%d em=%d",
2601 scsidp->host->host_no, 2617 scsidp->host->host_no,
2602 scsidp->channel, scsidp->id, 2618 scsidp->channel, scsidp->id,
2603 scsidp->lun, 2619 scsidp->lun,
2604 scsidp->host->hostt->emulated); 2620 scsidp->host->hostt->emulated);
2605 seq_printf(s, " sg_tablesize=%d excl=%d\n", 2621 seq_printf(s, " sg_tablesize=%d excl=%d\n",
2606 sdp->sg_tablesize, sdp->exclude); 2622 sdp->sg_tablesize, get_exclude(sdp));
2607 sg_proc_debug_helper(s, sdp); 2623 sg_proc_debug_helper(s, sdp);
2608 }
2609 spin_unlock(&sdp->sfd_lock);
2610 } 2624 }
2611 read_unlock_irqrestore(&sg_index_lock, iflags); 2625 read_unlock_irqrestore(&sg_index_lock, iflags);
2612 return 0; 2626 return 0;
diff --git a/drivers/staging/bcm/Bcmchar.c b/drivers/staging/bcm/Bcmchar.c
index f91bc1fdd895..639ba96adb36 100644
--- a/drivers/staging/bcm/Bcmchar.c
+++ b/drivers/staging/bcm/Bcmchar.c
@@ -1960,6 +1960,7 @@ cntrlEnd:
1960 1960
1961 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Called IOCTL_BCM_GET_DEVICE_DRIVER_INFO\n"); 1961 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Called IOCTL_BCM_GET_DEVICE_DRIVER_INFO\n");
1962 1962
1963 memset(&DevInfo, 0, sizeof(DevInfo));
1963 DevInfo.MaxRDMBufferSize = BUFFER_4K; 1964 DevInfo.MaxRDMBufferSize = BUFFER_4K;
1964 DevInfo.u32DSDStartOffset = EEPROM_CALPARAM_START; 1965 DevInfo.u32DSDStartOffset = EEPROM_CALPARAM_START;
1965 DevInfo.u32RxAlignmentCorrection = 0; 1966 DevInfo.u32RxAlignmentCorrection = 0;
diff --git a/drivers/staging/media/msi3101/Kconfig b/drivers/staging/media/msi3101/Kconfig
index b94a95a597d6..76d5bbd4d93c 100644
--- a/drivers/staging/media/msi3101/Kconfig
+++ b/drivers/staging/media/msi3101/Kconfig
@@ -1,3 +1,4 @@
1config USB_MSI3101 1config USB_MSI3101
2 tristate "Mirics MSi3101 SDR Dongle" 2 tristate "Mirics MSi3101 SDR Dongle"
3 depends on USB && VIDEO_DEV && VIDEO_V4L2 3 depends on USB && VIDEO_DEV && VIDEO_V4L2
4 select VIDEOBUF2_VMALLOC
diff --git a/drivers/staging/media/msi3101/sdr-msi3101.c b/drivers/staging/media/msi3101/sdr-msi3101.c
index 24c7b70a6cbf..4c3bf776bb20 100644
--- a/drivers/staging/media/msi3101/sdr-msi3101.c
+++ b/drivers/staging/media/msi3101/sdr-msi3101.c
@@ -1131,7 +1131,13 @@ static int msi3101_queue_setup(struct vb2_queue *vq,
1131 /* Absolute min and max number of buffers available for mmap() */ 1131 /* Absolute min and max number of buffers available for mmap() */
1132 *nbuffers = 32; 1132 *nbuffers = 32;
1133 *nplanes = 1; 1133 *nplanes = 1;
1134 sizes[0] = PAGE_ALIGN(3 * 3072); /* 3 * 768 * 4 */ 1134 /*
1135 * 3, wMaxPacketSize 3x 1024 bytes
1136 * 504, max IQ sample pairs per 1024 frame
1137 * 2, two samples, I and Q
1138 * 4, 32-bit float
1139 */
1140 sizes[0] = PAGE_ALIGN(3 * 504 * 2 * 4); /* = 12096 */
1135 dev_dbg(&s->udev->dev, "%s: nbuffers=%d sizes[0]=%d\n", 1141 dev_dbg(&s->udev->dev, "%s: nbuffers=%d sizes[0]=%d\n",
1136 __func__, *nbuffers, sizes[0]); 1142 __func__, *nbuffers, sizes[0]);
1137 return 0; 1143 return 0;
@@ -1657,7 +1663,7 @@ static int vidioc_s_frequency(struct file *file, void *priv,
1657 f->frequency * 625UL / 10UL); 1663 f->frequency * 625UL / 10UL);
1658} 1664}
1659 1665
1660const struct v4l2_ioctl_ops msi3101_ioctl_ops = { 1666static const struct v4l2_ioctl_ops msi3101_ioctl_ops = {
1661 .vidioc_querycap = msi3101_querycap, 1667 .vidioc_querycap = msi3101_querycap,
1662 1668
1663 .vidioc_enum_input = msi3101_enum_input, 1669 .vidioc_enum_input = msi3101_enum_input,
diff --git a/drivers/staging/ozwpan/ozcdev.c b/drivers/staging/ozwpan/ozcdev.c
index 6ccb64fb0786..6ce0af9977d8 100644
--- a/drivers/staging/ozwpan/ozcdev.c
+++ b/drivers/staging/ozwpan/ozcdev.c
@@ -155,6 +155,9 @@ static ssize_t oz_cdev_write(struct file *filp, const char __user *buf,
155 struct oz_app_hdr *app_hdr; 155 struct oz_app_hdr *app_hdr;
156 struct oz_serial_ctx *ctx; 156 struct oz_serial_ctx *ctx;
157 157
158 if (count > sizeof(ei->data) - sizeof(*elt) - sizeof(*app_hdr))
159 return -EINVAL;
160
158 spin_lock_bh(&g_cdev.lock); 161 spin_lock_bh(&g_cdev.lock);
159 pd = g_cdev.active_pd; 162 pd = g_cdev.active_pd;
160 if (pd) 163 if (pd)
diff --git a/drivers/staging/sb105x/sb_pci_mp.c b/drivers/staging/sb105x/sb_pci_mp.c
index 23db32f07fd5..a10cdb17038b 100644
--- a/drivers/staging/sb105x/sb_pci_mp.c
+++ b/drivers/staging/sb105x/sb_pci_mp.c
@@ -1063,7 +1063,7 @@ static int mp_wait_modem_status(struct sb_uart_state *state, unsigned long arg)
1063 1063
1064static int mp_get_count(struct sb_uart_state *state, struct serial_icounter_struct *icnt) 1064static int mp_get_count(struct sb_uart_state *state, struct serial_icounter_struct *icnt)
1065{ 1065{
1066 struct serial_icounter_struct icount; 1066 struct serial_icounter_struct icount = {};
1067 struct sb_uart_icount cnow; 1067 struct sb_uart_icount cnow;
1068 struct sb_uart_port *port = state->port; 1068 struct sb_uart_port *port = state->port;
1069 1069
diff --git a/drivers/staging/wlags49_h2/wl_priv.c b/drivers/staging/wlags49_h2/wl_priv.c
index c97e0e154d28..7e10dcdc3090 100644
--- a/drivers/staging/wlags49_h2/wl_priv.c
+++ b/drivers/staging/wlags49_h2/wl_priv.c
@@ -570,6 +570,7 @@ int wvlan_uil_put_info(struct uilreq *urq, struct wl_private *lp)
570 ltv_t *pLtv; 570 ltv_t *pLtv;
571 bool_t ltvAllocated = FALSE; 571 bool_t ltvAllocated = FALSE;
572 ENCSTRCT sEncryption; 572 ENCSTRCT sEncryption;
573 size_t len;
573 574
574#ifdef USE_WDS 575#ifdef USE_WDS
575 hcf_16 hcfPort = HCF_PORT_0; 576 hcf_16 hcfPort = HCF_PORT_0;
@@ -686,7 +687,8 @@ int wvlan_uil_put_info(struct uilreq *urq, struct wl_private *lp)
686 break; 687 break;
687 case CFG_CNF_OWN_NAME: 688 case CFG_CNF_OWN_NAME:
688 memset(lp->StationName, 0, sizeof(lp->StationName)); 689 memset(lp->StationName, 0, sizeof(lp->StationName));
689 memcpy((void *)lp->StationName, (void *)&pLtv->u.u8[2], (size_t)pLtv->u.u16[0]); 690 len = min_t(size_t, pLtv->u.u16[0], sizeof(lp->StationName));
691 strlcpy(lp->StationName, &pLtv->u.u8[2], len);
690 pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]); 692 pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]);
691 break; 693 break;
692 case CFG_CNF_LOAD_BALANCING: 694 case CFG_CNF_LOAD_BALANCING:
@@ -1783,6 +1785,7 @@ int wvlan_set_station_nickname(struct net_device *dev,
1783{ 1785{
1784 struct wl_private *lp = wl_priv(dev); 1786 struct wl_private *lp = wl_priv(dev);
1785 unsigned long flags; 1787 unsigned long flags;
1788 size_t len;
1786 int ret = 0; 1789 int ret = 0;
1787 /*------------------------------------------------------------------------*/ 1790 /*------------------------------------------------------------------------*/
1788 1791
@@ -1793,8 +1796,8 @@ int wvlan_set_station_nickname(struct net_device *dev,
1793 wl_lock(lp, &flags); 1796 wl_lock(lp, &flags);
1794 1797
1795 memset(lp->StationName, 0, sizeof(lp->StationName)); 1798 memset(lp->StationName, 0, sizeof(lp->StationName));
1796 1799 len = min_t(size_t, wrqu->data.length, sizeof(lp->StationName));
1797 memcpy(lp->StationName, extra, wrqu->data.length); 1800 strlcpy(lp->StationName, extra, len);
1798 1801
1799 /* Commit the adapter parameters */ 1802 /* Commit the adapter parameters */
1800 wl_apply(lp); 1803 wl_apply(lp);
diff --git a/drivers/target/target_core_pscsi.c b/drivers/target/target_core_pscsi.c
index 551c96ca60ac..0f199f6a0738 100644
--- a/drivers/target/target_core_pscsi.c
+++ b/drivers/target/target_core_pscsi.c
@@ -134,10 +134,10 @@ static int pscsi_pmode_enable_hba(struct se_hba *hba, unsigned long mode_flag)
134 * pSCSI Host ID and enable for phba mode 134 * pSCSI Host ID and enable for phba mode
135 */ 135 */
136 sh = scsi_host_lookup(phv->phv_host_id); 136 sh = scsi_host_lookup(phv->phv_host_id);
137 if (IS_ERR(sh)) { 137 if (!sh) {
138 pr_err("pSCSI: Unable to locate SCSI Host for" 138 pr_err("pSCSI: Unable to locate SCSI Host for"
139 " phv_host_id: %d\n", phv->phv_host_id); 139 " phv_host_id: %d\n", phv->phv_host_id);
140 return PTR_ERR(sh); 140 return -EINVAL;
141 } 141 }
142 142
143 phv->phv_lld_host = sh; 143 phv->phv_lld_host = sh;
@@ -515,10 +515,10 @@ static int pscsi_configure_device(struct se_device *dev)
515 sh = phv->phv_lld_host; 515 sh = phv->phv_lld_host;
516 } else { 516 } else {
517 sh = scsi_host_lookup(pdv->pdv_host_id); 517 sh = scsi_host_lookup(pdv->pdv_host_id);
518 if (IS_ERR(sh)) { 518 if (!sh) {
519 pr_err("pSCSI: Unable to locate" 519 pr_err("pSCSI: Unable to locate"
520 " pdv_host_id: %d\n", pdv->pdv_host_id); 520 " pdv_host_id: %d\n", pdv->pdv_host_id);
521 return PTR_ERR(sh); 521 return -EINVAL;
522 } 522 }
523 } 523 }
524 } else { 524 } else {
diff --git a/drivers/target/target_core_sbc.c b/drivers/target/target_core_sbc.c
index 4714c6f8da4b..d9b92b2c524d 100644
--- a/drivers/target/target_core_sbc.c
+++ b/drivers/target/target_core_sbc.c
@@ -263,6 +263,11 @@ sbc_setup_write_same(struct se_cmd *cmd, unsigned char *flags, struct sbc_ops *o
263 sectors, cmd->se_dev->dev_attrib.max_write_same_len); 263 sectors, cmd->se_dev->dev_attrib.max_write_same_len);
264 return TCM_INVALID_CDB_FIELD; 264 return TCM_INVALID_CDB_FIELD;
265 } 265 }
266 /* We always have ANC_SUP == 0 so setting ANCHOR is always an error */
267 if (flags[0] & 0x10) {
268 pr_warn("WRITE SAME with ANCHOR not supported\n");
269 return TCM_INVALID_CDB_FIELD;
270 }
266 /* 271 /*
267 * Special case for WRITE_SAME w/ UNMAP=1 that ends up getting 272 * Special case for WRITE_SAME w/ UNMAP=1 that ends up getting
268 * translated into block discard requests within backend code. 273 * translated into block discard requests within backend code.
diff --git a/drivers/target/target_core_xcopy.c b/drivers/target/target_core_xcopy.c
index 3da4fd10b9f8..474cd44fac14 100644
--- a/drivers/target/target_core_xcopy.c
+++ b/drivers/target/target_core_xcopy.c
@@ -82,6 +82,9 @@ static int target_xcopy_locate_se_dev_e4(struct se_cmd *se_cmd, struct xcopy_op
82 mutex_lock(&g_device_mutex); 82 mutex_lock(&g_device_mutex);
83 list_for_each_entry(se_dev, &g_device_list, g_dev_node) { 83 list_for_each_entry(se_dev, &g_device_list, g_dev_node) {
84 84
85 if (!se_dev->dev_attrib.emulate_3pc)
86 continue;
87
85 memset(&tmp_dev_wwn[0], 0, XCOPY_NAA_IEEE_REGEX_LEN); 88 memset(&tmp_dev_wwn[0], 0, XCOPY_NAA_IEEE_REGEX_LEN);
86 target_xcopy_gen_naa_ieee(se_dev, &tmp_dev_wwn[0]); 89 target_xcopy_gen_naa_ieee(se_dev, &tmp_dev_wwn[0]);
87 90
@@ -357,6 +360,7 @@ struct xcopy_pt_cmd {
357 struct se_cmd se_cmd; 360 struct se_cmd se_cmd;
358 struct xcopy_op *xcopy_op; 361 struct xcopy_op *xcopy_op;
359 struct completion xpt_passthrough_sem; 362 struct completion xpt_passthrough_sem;
363 unsigned char sense_buffer[TRANSPORT_SENSE_BUFFER];
360}; 364};
361 365
362static struct se_port xcopy_pt_port; 366static struct se_port xcopy_pt_port;
@@ -675,7 +679,8 @@ static int target_xcopy_issue_pt_cmd(struct xcopy_pt_cmd *xpt_cmd)
675 679
676 pr_debug("target_xcopy_issue_pt_cmd(): SCSI status: 0x%02x\n", 680 pr_debug("target_xcopy_issue_pt_cmd(): SCSI status: 0x%02x\n",
677 se_cmd->scsi_status); 681 se_cmd->scsi_status);
678 return 0; 682
683 return (se_cmd->scsi_status) ? -EINVAL : 0;
679} 684}
680 685
681static int target_xcopy_read_source( 686static int target_xcopy_read_source(
@@ -708,7 +713,7 @@ static int target_xcopy_read_source(
708 (unsigned long long)src_lba, src_sectors, length); 713 (unsigned long long)src_lba, src_sectors, length);
709 714
710 transport_init_se_cmd(se_cmd, &xcopy_pt_tfo, NULL, length, 715 transport_init_se_cmd(se_cmd, &xcopy_pt_tfo, NULL, length,
711 DMA_FROM_DEVICE, 0, NULL); 716 DMA_FROM_DEVICE, 0, &xpt_cmd->sense_buffer[0]);
712 xop->src_pt_cmd = xpt_cmd; 717 xop->src_pt_cmd = xpt_cmd;
713 718
714 rc = target_xcopy_setup_pt_cmd(xpt_cmd, xop, src_dev, &cdb[0], 719 rc = target_xcopy_setup_pt_cmd(xpt_cmd, xop, src_dev, &cdb[0],
@@ -768,7 +773,7 @@ static int target_xcopy_write_destination(
768 (unsigned long long)dst_lba, dst_sectors, length); 773 (unsigned long long)dst_lba, dst_sectors, length);
769 774
770 transport_init_se_cmd(se_cmd, &xcopy_pt_tfo, NULL, length, 775 transport_init_se_cmd(se_cmd, &xcopy_pt_tfo, NULL, length,
771 DMA_TO_DEVICE, 0, NULL); 776 DMA_TO_DEVICE, 0, &xpt_cmd->sense_buffer[0]);
772 xop->dst_pt_cmd = xpt_cmd; 777 xop->dst_pt_cmd = xpt_cmd;
773 778
774 rc = target_xcopy_setup_pt_cmd(xpt_cmd, xop, dst_dev, &cdb[0], 779 rc = target_xcopy_setup_pt_cmd(xpt_cmd, xop, dst_dev, &cdb[0],
@@ -884,30 +889,42 @@ out:
884 889
885sense_reason_t target_do_xcopy(struct se_cmd *se_cmd) 890sense_reason_t target_do_xcopy(struct se_cmd *se_cmd)
886{ 891{
892 struct se_device *dev = se_cmd->se_dev;
887 struct xcopy_op *xop = NULL; 893 struct xcopy_op *xop = NULL;
888 unsigned char *p = NULL, *seg_desc; 894 unsigned char *p = NULL, *seg_desc;
889 unsigned int list_id, list_id_usage, sdll, inline_dl, sa; 895 unsigned int list_id, list_id_usage, sdll, inline_dl, sa;
896 sense_reason_t ret = TCM_INVALID_PARAMETER_LIST;
890 int rc; 897 int rc;
891 unsigned short tdll; 898 unsigned short tdll;
892 899
900 if (!dev->dev_attrib.emulate_3pc) {
901 pr_err("EXTENDED_COPY operation explicitly disabled\n");
902 return TCM_UNSUPPORTED_SCSI_OPCODE;
903 }
904
893 sa = se_cmd->t_task_cdb[1] & 0x1f; 905 sa = se_cmd->t_task_cdb[1] & 0x1f;
894 if (sa != 0x00) { 906 if (sa != 0x00) {
895 pr_err("EXTENDED_COPY(LID4) not supported\n"); 907 pr_err("EXTENDED_COPY(LID4) not supported\n");
896 return TCM_UNSUPPORTED_SCSI_OPCODE; 908 return TCM_UNSUPPORTED_SCSI_OPCODE;
897 } 909 }
898 910
911 xop = kzalloc(sizeof(struct xcopy_op), GFP_KERNEL);
912 if (!xop) {
913 pr_err("Unable to allocate xcopy_op\n");
914 return TCM_OUT_OF_RESOURCES;
915 }
916 xop->xop_se_cmd = se_cmd;
917
899 p = transport_kmap_data_sg(se_cmd); 918 p = transport_kmap_data_sg(se_cmd);
900 if (!p) { 919 if (!p) {
901 pr_err("transport_kmap_data_sg() failed in target_do_xcopy\n"); 920 pr_err("transport_kmap_data_sg() failed in target_do_xcopy\n");
921 kfree(xop);
902 return TCM_OUT_OF_RESOURCES; 922 return TCM_OUT_OF_RESOURCES;
903 } 923 }
904 924
905 list_id = p[0]; 925 list_id = p[0];
906 if (list_id != 0x00) { 926 list_id_usage = (p[1] & 0x18) >> 3;
907 pr_err("XCOPY with non zero list_id: 0x%02x\n", list_id); 927
908 goto out;
909 }
910 list_id_usage = (p[1] & 0x18);
911 /* 928 /*
912 * Determine TARGET DESCRIPTOR LIST LENGTH + SEGMENT DESCRIPTOR LIST LENGTH 929 * Determine TARGET DESCRIPTOR LIST LENGTH + SEGMENT DESCRIPTOR LIST LENGTH
913 */ 930 */
@@ -920,13 +937,6 @@ sense_reason_t target_do_xcopy(struct se_cmd *se_cmd)
920 goto out; 937 goto out;
921 } 938 }
922 939
923 xop = kzalloc(sizeof(struct xcopy_op), GFP_KERNEL);
924 if (!xop) {
925 pr_err("Unable to allocate xcopy_op\n");
926 goto out;
927 }
928 xop->xop_se_cmd = se_cmd;
929
930 pr_debug("Processing XCOPY with list_id: 0x%02x list_id_usage: 0x%02x" 940 pr_debug("Processing XCOPY with list_id: 0x%02x list_id_usage: 0x%02x"
931 " tdll: %hu sdll: %u inline_dl: %u\n", list_id, list_id_usage, 941 " tdll: %hu sdll: %u inline_dl: %u\n", list_id, list_id_usage,
932 tdll, sdll, inline_dl); 942 tdll, sdll, inline_dl);
@@ -935,6 +945,17 @@ sense_reason_t target_do_xcopy(struct se_cmd *se_cmd)
935 if (rc <= 0) 945 if (rc <= 0)
936 goto out; 946 goto out;
937 947
948 if (xop->src_dev->dev_attrib.block_size !=
949 xop->dst_dev->dev_attrib.block_size) {
950 pr_err("XCOPY: Non matching src_dev block_size: %u + dst_dev"
951 " block_size: %u currently unsupported\n",
952 xop->src_dev->dev_attrib.block_size,
953 xop->dst_dev->dev_attrib.block_size);
954 xcopy_pt_undepend_remotedev(xop);
955 ret = TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
956 goto out;
957 }
958
938 pr_debug("XCOPY: Processed %d target descriptors, length: %u\n", rc, 959 pr_debug("XCOPY: Processed %d target descriptors, length: %u\n", rc,
939 rc * XCOPY_TARGET_DESC_LEN); 960 rc * XCOPY_TARGET_DESC_LEN);
940 seg_desc = &p[16]; 961 seg_desc = &p[16];
@@ -957,7 +978,7 @@ out:
957 if (p) 978 if (p)
958 transport_kunmap_data_sg(se_cmd); 979 transport_kunmap_data_sg(se_cmd);
959 kfree(xop); 980 kfree(xop);
960 return TCM_INVALID_CDB_FIELD; 981 return ret;
961} 982}
962 983
963static sense_reason_t target_rcr_operating_parameters(struct se_cmd *se_cmd) 984static sense_reason_t target_rcr_operating_parameters(struct se_cmd *se_cmd)
diff --git a/drivers/thermal/samsung/exynos_thermal_common.c b/drivers/thermal/samsung/exynos_thermal_common.c
index f10a6ad37c06..c2301da08ac7 100644
--- a/drivers/thermal/samsung/exynos_thermal_common.c
+++ b/drivers/thermal/samsung/exynos_thermal_common.c
@@ -310,8 +310,6 @@ void exynos_report_trigger(struct thermal_sensor_conf *conf)
310 } 310 }
311 311
312 th_zone = conf->pzone_data; 312 th_zone = conf->pzone_data;
313 if (th_zone->therm_dev)
314 return;
315 313
316 if (th_zone->bind == false) { 314 if (th_zone->bind == false) {
317 for (i = 0; i < th_zone->cool_dev_size; i++) { 315 for (i = 0; i < th_zone->cool_dev_size; i++) {
diff --git a/drivers/thermal/samsung/exynos_tmu.c b/drivers/thermal/samsung/exynos_tmu.c
index b43afda8acd1..32f38b90c4f6 100644
--- a/drivers/thermal/samsung/exynos_tmu.c
+++ b/drivers/thermal/samsung/exynos_tmu.c
@@ -317,6 +317,9 @@ static void exynos_tmu_control(struct platform_device *pdev, bool on)
317 317
318 con = readl(data->base + reg->tmu_ctrl); 318 con = readl(data->base + reg->tmu_ctrl);
319 319
320 if (pdata->test_mux)
321 con |= (pdata->test_mux << reg->test_mux_addr_shift);
322
320 if (pdata->reference_voltage) { 323 if (pdata->reference_voltage) {
321 con &= ~(reg->buf_vref_sel_mask << reg->buf_vref_sel_shift); 324 con &= ~(reg->buf_vref_sel_mask << reg->buf_vref_sel_shift);
322 con |= pdata->reference_voltage << reg->buf_vref_sel_shift; 325 con |= pdata->reference_voltage << reg->buf_vref_sel_shift;
@@ -488,7 +491,7 @@ static const struct of_device_id exynos_tmu_match[] = {
488 }, 491 },
489 { 492 {
490 .compatible = "samsung,exynos4412-tmu", 493 .compatible = "samsung,exynos4412-tmu",
491 .data = (void *)EXYNOS5250_TMU_DRV_DATA, 494 .data = (void *)EXYNOS4412_TMU_DRV_DATA,
492 }, 495 },
493 { 496 {
494 .compatible = "samsung,exynos5250-tmu", 497 .compatible = "samsung,exynos5250-tmu",
@@ -629,9 +632,10 @@ static int exynos_tmu_probe(struct platform_device *pdev)
629 if (ret) 632 if (ret)
630 return ret; 633 return ret;
631 634
632 if (pdata->type == SOC_ARCH_EXYNOS || 635 if (pdata->type == SOC_ARCH_EXYNOS4210 ||
633 pdata->type == SOC_ARCH_EXYNOS4210 || 636 pdata->type == SOC_ARCH_EXYNOS4412 ||
634 pdata->type == SOC_ARCH_EXYNOS5440) 637 pdata->type == SOC_ARCH_EXYNOS5250 ||
638 pdata->type == SOC_ARCH_EXYNOS5440)
635 data->soc = pdata->type; 639 data->soc = pdata->type;
636 else { 640 else {
637 ret = -EINVAL; 641 ret = -EINVAL;
diff --git a/drivers/thermal/samsung/exynos_tmu.h b/drivers/thermal/samsung/exynos_tmu.h
index b364c9eee701..3fb65547e64c 100644
--- a/drivers/thermal/samsung/exynos_tmu.h
+++ b/drivers/thermal/samsung/exynos_tmu.h
@@ -41,7 +41,8 @@ enum calibration_mode {
41 41
42enum soc_type { 42enum soc_type {
43 SOC_ARCH_EXYNOS4210 = 1, 43 SOC_ARCH_EXYNOS4210 = 1,
44 SOC_ARCH_EXYNOS, 44 SOC_ARCH_EXYNOS4412,
45 SOC_ARCH_EXYNOS5250,
45 SOC_ARCH_EXYNOS5440, 46 SOC_ARCH_EXYNOS5440,
46}; 47};
47 48
@@ -84,6 +85,7 @@ enum soc_type {
84 * @triminfo_reload_shift: shift of triminfo reload enable bit in triminfo_ctrl 85 * @triminfo_reload_shift: shift of triminfo reload enable bit in triminfo_ctrl
85 reg. 86 reg.
86 * @tmu_ctrl: TMU main controller register. 87 * @tmu_ctrl: TMU main controller register.
88 * @test_mux_addr_shift: shift bits of test mux address.
87 * @buf_vref_sel_shift: shift bits of reference voltage in tmu_ctrl register. 89 * @buf_vref_sel_shift: shift bits of reference voltage in tmu_ctrl register.
88 * @buf_vref_sel_mask: mask bits of reference voltage in tmu_ctrl register. 90 * @buf_vref_sel_mask: mask bits of reference voltage in tmu_ctrl register.
89 * @therm_trip_mode_shift: shift bits of tripping mode in tmu_ctrl register. 91 * @therm_trip_mode_shift: shift bits of tripping mode in tmu_ctrl register.
@@ -150,6 +152,7 @@ struct exynos_tmu_registers {
150 u32 triminfo_reload_shift; 152 u32 triminfo_reload_shift;
151 153
152 u32 tmu_ctrl; 154 u32 tmu_ctrl;
155 u32 test_mux_addr_shift;
153 u32 buf_vref_sel_shift; 156 u32 buf_vref_sel_shift;
154 u32 buf_vref_sel_mask; 157 u32 buf_vref_sel_mask;
155 u32 therm_trip_mode_shift; 158 u32 therm_trip_mode_shift;
@@ -257,6 +260,7 @@ struct exynos_tmu_registers {
257 * @first_point_trim: temp value of the first point trimming 260 * @first_point_trim: temp value of the first point trimming
258 * @second_point_trim: temp value of the second point trimming 261 * @second_point_trim: temp value of the second point trimming
259 * @default_temp_offset: default temperature offset in case of no trimming 262 * @default_temp_offset: default temperature offset in case of no trimming
263 * @test_mux; information if SoC supports test MUX
260 * @cal_type: calibration type for temperature 264 * @cal_type: calibration type for temperature
261 * @cal_mode: calibration mode for temperature 265 * @cal_mode: calibration mode for temperature
262 * @freq_clip_table: Table representing frequency reduction percentage. 266 * @freq_clip_table: Table representing frequency reduction percentage.
@@ -286,6 +290,7 @@ struct exynos_tmu_platform_data {
286 u8 first_point_trim; 290 u8 first_point_trim;
287 u8 second_point_trim; 291 u8 second_point_trim;
288 u8 default_temp_offset; 292 u8 default_temp_offset;
293 u8 test_mux;
289 294
290 enum calibration_type cal_type; 295 enum calibration_type cal_type;
291 enum calibration_mode cal_mode; 296 enum calibration_mode cal_mode;
diff --git a/drivers/thermal/samsung/exynos_tmu_data.c b/drivers/thermal/samsung/exynos_tmu_data.c
index 9002499c1f69..073c292baa53 100644
--- a/drivers/thermal/samsung/exynos_tmu_data.c
+++ b/drivers/thermal/samsung/exynos_tmu_data.c
@@ -90,14 +90,15 @@ struct exynos_tmu_init_data const exynos4210_default_tmu_data = {
90}; 90};
91#endif 91#endif
92 92
93#if defined(CONFIG_SOC_EXYNOS5250) || defined(CONFIG_SOC_EXYNOS4412) 93#if defined(CONFIG_SOC_EXYNOS4412) || defined(CONFIG_SOC_EXYNOS5250)
94static const struct exynos_tmu_registers exynos5250_tmu_registers = { 94static const struct exynos_tmu_registers exynos4412_tmu_registers = {
95 .triminfo_data = EXYNOS_TMU_REG_TRIMINFO, 95 .triminfo_data = EXYNOS_TMU_REG_TRIMINFO,
96 .triminfo_25_shift = EXYNOS_TRIMINFO_25_SHIFT, 96 .triminfo_25_shift = EXYNOS_TRIMINFO_25_SHIFT,
97 .triminfo_85_shift = EXYNOS_TRIMINFO_85_SHIFT, 97 .triminfo_85_shift = EXYNOS_TRIMINFO_85_SHIFT,
98 .triminfo_ctrl = EXYNOS_TMU_TRIMINFO_CON, 98 .triminfo_ctrl = EXYNOS_TMU_TRIMINFO_CON,
99 .triminfo_reload_shift = EXYNOS_TRIMINFO_RELOAD_SHIFT, 99 .triminfo_reload_shift = EXYNOS_TRIMINFO_RELOAD_SHIFT,
100 .tmu_ctrl = EXYNOS_TMU_REG_CONTROL, 100 .tmu_ctrl = EXYNOS_TMU_REG_CONTROL,
101 .test_mux_addr_shift = EXYNOS4412_MUX_ADDR_SHIFT,
101 .buf_vref_sel_shift = EXYNOS_TMU_REF_VOLTAGE_SHIFT, 102 .buf_vref_sel_shift = EXYNOS_TMU_REF_VOLTAGE_SHIFT,
102 .buf_vref_sel_mask = EXYNOS_TMU_REF_VOLTAGE_MASK, 103 .buf_vref_sel_mask = EXYNOS_TMU_REF_VOLTAGE_MASK,
103 .therm_trip_mode_shift = EXYNOS_TMU_TRIP_MODE_SHIFT, 104 .therm_trip_mode_shift = EXYNOS_TMU_TRIP_MODE_SHIFT,
@@ -128,7 +129,7 @@ static const struct exynos_tmu_registers exynos5250_tmu_registers = {
128 .emul_time_mask = EXYNOS_EMUL_TIME_MASK, 129 .emul_time_mask = EXYNOS_EMUL_TIME_MASK,
129}; 130};
130 131
131#define EXYNOS5250_TMU_DATA \ 132#define EXYNOS4412_TMU_DATA \
132 .threshold_falling = 10, \ 133 .threshold_falling = 10, \
133 .trigger_levels[0] = 85, \ 134 .trigger_levels[0] = 85, \
134 .trigger_levels[1] = 103, \ 135 .trigger_levels[1] = 103, \
@@ -162,15 +163,32 @@ static const struct exynos_tmu_registers exynos5250_tmu_registers = {
162 .temp_level = 103, \ 163 .temp_level = 103, \
163 }, \ 164 }, \
164 .freq_tab_count = 2, \ 165 .freq_tab_count = 2, \
165 .type = SOC_ARCH_EXYNOS, \ 166 .registers = &exynos4412_tmu_registers, \
166 .registers = &exynos5250_tmu_registers, \
167 .features = (TMU_SUPPORT_EMULATION | TMU_SUPPORT_TRIM_RELOAD | \ 167 .features = (TMU_SUPPORT_EMULATION | TMU_SUPPORT_TRIM_RELOAD | \
168 TMU_SUPPORT_FALLING_TRIP | TMU_SUPPORT_READY_STATUS | \ 168 TMU_SUPPORT_FALLING_TRIP | TMU_SUPPORT_READY_STATUS | \
169 TMU_SUPPORT_EMUL_TIME) 169 TMU_SUPPORT_EMUL_TIME)
170#endif
170 171
172#if defined(CONFIG_SOC_EXYNOS4412)
173struct exynos_tmu_init_data const exynos4412_default_tmu_data = {
174 .tmu_data = {
175 {
176 EXYNOS4412_TMU_DATA,
177 .type = SOC_ARCH_EXYNOS4412,
178 .test_mux = EXYNOS4412_MUX_ADDR_VALUE,
179 },
180 },
181 .tmu_count = 1,
182};
183#endif
184
185#if defined(CONFIG_SOC_EXYNOS5250)
171struct exynos_tmu_init_data const exynos5250_default_tmu_data = { 186struct exynos_tmu_init_data const exynos5250_default_tmu_data = {
172 .tmu_data = { 187 .tmu_data = {
173 { EXYNOS5250_TMU_DATA }, 188 {
189 EXYNOS4412_TMU_DATA,
190 .type = SOC_ARCH_EXYNOS5250,
191 },
174 }, 192 },
175 .tmu_count = 1, 193 .tmu_count = 1,
176}; 194};
diff --git a/drivers/thermal/samsung/exynos_tmu_data.h b/drivers/thermal/samsung/exynos_tmu_data.h
index dc7feb51099b..a1ea19d9e0a6 100644
--- a/drivers/thermal/samsung/exynos_tmu_data.h
+++ b/drivers/thermal/samsung/exynos_tmu_data.h
@@ -95,6 +95,10 @@
95 95
96#define EXYNOS_MAX_TRIGGER_PER_REG 4 96#define EXYNOS_MAX_TRIGGER_PER_REG 4
97 97
98/* Exynos4412 specific */
99#define EXYNOS4412_MUX_ADDR_VALUE 6
100#define EXYNOS4412_MUX_ADDR_SHIFT 20
101
98/*exynos5440 specific registers*/ 102/*exynos5440 specific registers*/
99#define EXYNOS5440_TMU_S0_7_TRIM 0x000 103#define EXYNOS5440_TMU_S0_7_TRIM 0x000
100#define EXYNOS5440_TMU_S0_7_CTRL 0x020 104#define EXYNOS5440_TMU_S0_7_CTRL 0x020
@@ -138,7 +142,14 @@ extern struct exynos_tmu_init_data const exynos4210_default_tmu_data;
138#define EXYNOS4210_TMU_DRV_DATA (NULL) 142#define EXYNOS4210_TMU_DRV_DATA (NULL)
139#endif 143#endif
140 144
141#if (defined(CONFIG_SOC_EXYNOS5250) || defined(CONFIG_SOC_EXYNOS4412)) 145#if defined(CONFIG_SOC_EXYNOS4412)
146extern struct exynos_tmu_init_data const exynos4412_default_tmu_data;
147#define EXYNOS4412_TMU_DRV_DATA (&exynos4412_default_tmu_data)
148#else
149#define EXYNOS4412_TMU_DRV_DATA (NULL)
150#endif
151
152#if defined(CONFIG_SOC_EXYNOS5250)
142extern struct exynos_tmu_init_data const exynos5250_default_tmu_data; 153extern struct exynos_tmu_init_data const exynos5250_default_tmu_data;
143#define EXYNOS5250_TMU_DRV_DATA (&exynos5250_default_tmu_data) 154#define EXYNOS5250_TMU_DRV_DATA (&exynos5250_default_tmu_data)
144#else 155#else
diff --git a/drivers/thermal/thermal_hwmon.c b/drivers/thermal/thermal_hwmon.c
index eeef0e2498ca..fdb07199d9c2 100644
--- a/drivers/thermal/thermal_hwmon.c
+++ b/drivers/thermal/thermal_hwmon.c
@@ -159,7 +159,7 @@ int thermal_add_hwmon_sysfs(struct thermal_zone_device *tz)
159 159
160 INIT_LIST_HEAD(&hwmon->tz_list); 160 INIT_LIST_HEAD(&hwmon->tz_list);
161 strlcpy(hwmon->type, tz->type, THERMAL_NAME_LENGTH); 161 strlcpy(hwmon->type, tz->type, THERMAL_NAME_LENGTH);
162 hwmon->device = hwmon_device_register(&tz->device); 162 hwmon->device = hwmon_device_register(NULL);
163 if (IS_ERR(hwmon->device)) { 163 if (IS_ERR(hwmon->device)) {
164 result = PTR_ERR(hwmon->device); 164 result = PTR_ERR(hwmon->device);
165 goto free_mem; 165 goto free_mem;
diff --git a/drivers/thermal/ti-soc-thermal/ti-thermal-common.c b/drivers/thermal/ti-soc-thermal/ti-thermal-common.c
index 4f8b9af54a5a..5a47cc8c8f85 100644
--- a/drivers/thermal/ti-soc-thermal/ti-thermal-common.c
+++ b/drivers/thermal/ti-soc-thermal/ti-thermal-common.c
@@ -110,6 +110,7 @@ static inline int ti_thermal_get_temp(struct thermal_zone_device *thermal,
110 } else { 110 } else {
111 dev_err(bgp->dev, 111 dev_err(bgp->dev,
112 "Failed to read PCB state. Using defaults\n"); 112 "Failed to read PCB state. Using defaults\n");
113 ret = 0;
113 } 114 }
114 } 115 }
115 *temp = ti_thermal_hotspot_temperature(tmp, slope, constant); 116 *temp = ti_thermal_hotspot_temperature(tmp, slope, constant);
diff --git a/drivers/thermal/x86_pkg_temp_thermal.c b/drivers/thermal/x86_pkg_temp_thermal.c
index f36950e4134f..7722cb9d5a80 100644
--- a/drivers/thermal/x86_pkg_temp_thermal.c
+++ b/drivers/thermal/x86_pkg_temp_thermal.c
@@ -316,18 +316,19 @@ static void pkg_temp_thermal_threshold_work_fn(struct work_struct *work)
316 int phy_id = topology_physical_package_id(cpu); 316 int phy_id = topology_physical_package_id(cpu);
317 struct phy_dev_entry *phdev = pkg_temp_thermal_get_phy_entry(cpu); 317 struct phy_dev_entry *phdev = pkg_temp_thermal_get_phy_entry(cpu);
318 bool notify = false; 318 bool notify = false;
319 unsigned long flags;
319 320
320 if (!phdev) 321 if (!phdev)
321 return; 322 return;
322 323
323 spin_lock(&pkg_work_lock); 324 spin_lock_irqsave(&pkg_work_lock, flags);
324 ++pkg_work_cnt; 325 ++pkg_work_cnt;
325 if (unlikely(phy_id > max_phy_id)) { 326 if (unlikely(phy_id > max_phy_id)) {
326 spin_unlock(&pkg_work_lock); 327 spin_unlock_irqrestore(&pkg_work_lock, flags);
327 return; 328 return;
328 } 329 }
329 pkg_work_scheduled[phy_id] = 0; 330 pkg_work_scheduled[phy_id] = 0;
330 spin_unlock(&pkg_work_lock); 331 spin_unlock_irqrestore(&pkg_work_lock, flags);
331 332
332 enable_pkg_thres_interrupt(); 333 enable_pkg_thres_interrupt();
333 rdmsrl(MSR_IA32_PACKAGE_THERM_STATUS, msr_val); 334 rdmsrl(MSR_IA32_PACKAGE_THERM_STATUS, msr_val);
@@ -397,6 +398,7 @@ static int pkg_temp_thermal_device_add(unsigned int cpu)
397 int thres_count; 398 int thres_count;
398 u32 eax, ebx, ecx, edx; 399 u32 eax, ebx, ecx, edx;
399 u8 *temp; 400 u8 *temp;
401 unsigned long flags;
400 402
401 cpuid(6, &eax, &ebx, &ecx, &edx); 403 cpuid(6, &eax, &ebx, &ecx, &edx);
402 thres_count = ebx & 0x07; 404 thres_count = ebx & 0x07;
@@ -420,19 +422,19 @@ static int pkg_temp_thermal_device_add(unsigned int cpu)
420 goto err_ret_unlock; 422 goto err_ret_unlock;
421 } 423 }
422 424
423 spin_lock(&pkg_work_lock); 425 spin_lock_irqsave(&pkg_work_lock, flags);
424 if (topology_physical_package_id(cpu) > max_phy_id) 426 if (topology_physical_package_id(cpu) > max_phy_id)
425 max_phy_id = topology_physical_package_id(cpu); 427 max_phy_id = topology_physical_package_id(cpu);
426 temp = krealloc(pkg_work_scheduled, 428 temp = krealloc(pkg_work_scheduled,
427 (max_phy_id+1) * sizeof(u8), GFP_ATOMIC); 429 (max_phy_id+1) * sizeof(u8), GFP_ATOMIC);
428 if (!temp) { 430 if (!temp) {
429 spin_unlock(&pkg_work_lock); 431 spin_unlock_irqrestore(&pkg_work_lock, flags);
430 err = -ENOMEM; 432 err = -ENOMEM;
431 goto err_ret_free; 433 goto err_ret_free;
432 } 434 }
433 pkg_work_scheduled = temp; 435 pkg_work_scheduled = temp;
434 pkg_work_scheduled[topology_physical_package_id(cpu)] = 0; 436 pkg_work_scheduled[topology_physical_package_id(cpu)] = 0;
435 spin_unlock(&pkg_work_lock); 437 spin_unlock_irqrestore(&pkg_work_lock, flags);
436 438
437 phy_dev_entry->phys_proc_id = topology_physical_package_id(cpu); 439 phy_dev_entry->phys_proc_id = topology_physical_package_id(cpu);
438 phy_dev_entry->first_cpu = cpu; 440 phy_dev_entry->first_cpu = cpu;
diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c
index d067285a2d20..6b0f75eac8a2 100644
--- a/drivers/tty/serial/atmel_serial.c
+++ b/drivers/tty/serial/atmel_serial.c
@@ -1499,7 +1499,7 @@ static void atmel_set_ops(struct uart_port *port)
1499/* 1499/*
1500 * Get ip name usart or uart 1500 * Get ip name usart or uart
1501 */ 1501 */
1502static int atmel_get_ip_name(struct uart_port *port) 1502static void atmel_get_ip_name(struct uart_port *port)
1503{ 1503{
1504 struct atmel_uart_port *atmel_port = to_atmel_uart_port(port); 1504 struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
1505 int name = UART_GET_IP_NAME(port); 1505 int name = UART_GET_IP_NAME(port);
@@ -1518,10 +1518,7 @@ static int atmel_get_ip_name(struct uart_port *port)
1518 atmel_port->is_usart = false; 1518 atmel_port->is_usart = false;
1519 } else { 1519 } else {
1520 dev_err(port->dev, "Not supported ip name, set to uart\n"); 1520 dev_err(port->dev, "Not supported ip name, set to uart\n");
1521 return -EINVAL;
1522 } 1521 }
1523
1524 return 0;
1525} 1522}
1526 1523
1527/* 1524/*
@@ -2405,9 +2402,7 @@ static int atmel_serial_probe(struct platform_device *pdev)
2405 /* 2402 /*
2406 * Get port name of usart or uart 2403 * Get port name of usart or uart
2407 */ 2404 */
2408 ret = atmel_get_ip_name(&port->uart); 2405 atmel_get_ip_name(&port->uart);
2409 if (ret < 0)
2410 goto err_add_port;
2411 2406
2412 return 0; 2407 return 0;
2413 2408
diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
index e221f13fcb61..67beb8444930 100644
--- a/drivers/uio/uio.c
+++ b/drivers/uio/uio.c
@@ -648,16 +648,29 @@ static int uio_mmap_physical(struct vm_area_struct *vma)
648{ 648{
649 struct uio_device *idev = vma->vm_private_data; 649 struct uio_device *idev = vma->vm_private_data;
650 int mi = uio_find_mem_index(vma); 650 int mi = uio_find_mem_index(vma);
651 struct uio_mem *mem;
651 if (mi < 0) 652 if (mi < 0)
652 return -EINVAL; 653 return -EINVAL;
654 mem = idev->info->mem + mi;
653 655
654 vma->vm_ops = &uio_physical_vm_ops; 656 if (vma->vm_end - vma->vm_start > mem->size)
657 return -EINVAL;
655 658
659 vma->vm_ops = &uio_physical_vm_ops;
656 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); 660 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
657 661
662 /*
663 * We cannot use the vm_iomap_memory() helper here,
664 * because vma->vm_pgoff is the map index we looked
665 * up above in uio_find_mem_index(), rather than an
666 * actual page offset into the mmap.
667 *
668 * So we just do the physical mmap without a page
669 * offset.
670 */
658 return remap_pfn_range(vma, 671 return remap_pfn_range(vma,
659 vma->vm_start, 672 vma->vm_start,
660 idev->info->mem[mi].addr >> PAGE_SHIFT, 673 mem->addr >> PAGE_SHIFT,
661 vma->vm_end - vma->vm_start, 674 vma->vm_end - vma->vm_start,
662 vma->vm_page_prot); 675 vma->vm_page_prot);
663} 676}
diff --git a/drivers/usb/atm/usbatm.h b/drivers/usb/atm/usbatm.h
index 5651231a7437..f3eecd967a8a 100644
--- a/drivers/usb/atm/usbatm.h
+++ b/drivers/usb/atm/usbatm.h
@@ -34,6 +34,7 @@
34#include <linux/stringify.h> 34#include <linux/stringify.h>
35#include <linux/usb.h> 35#include <linux/usb.h>
36#include <linux/mutex.h> 36#include <linux/mutex.h>
37#include <linux/ratelimit.h>
37 38
38/* 39/*
39#define VERBOSE_DEBUG 40#define VERBOSE_DEBUG
@@ -59,13 +60,12 @@
59 atm_printk(KERN_INFO, instance , format , ## arg) 60 atm_printk(KERN_INFO, instance , format , ## arg)
60#define atm_warn(instance, format, arg...) \ 61#define atm_warn(instance, format, arg...) \
61 atm_printk(KERN_WARNING, instance , format , ## arg) 62 atm_printk(KERN_WARNING, instance , format , ## arg)
62#define atm_dbg(instance, format, arg...) \ 63#define atm_dbg(instance, format, ...) \
63 dynamic_pr_debug("ATM dev %d: " format , \ 64 pr_debug("ATM dev %d: " format, \
64 (instance)->atm_dev->number , ## arg) 65 (instance)->atm_dev->number, ##__VA_ARGS__)
65#define atm_rldbg(instance, format, arg...) \ 66#define atm_rldbg(instance, format, ...) \
66 if (printk_ratelimit()) \ 67 pr_debug_ratelimited("ATM dev %d: " format, \
67 atm_dbg(instance , format , ## arg) 68 (instance)->atm_dev->number, ##__VA_ARGS__)
68
69 69
70/* flags, set by mini-driver in bind() */ 70/* flags, set by mini-driver in bind() */
71 71
diff --git a/drivers/usb/chipidea/bits.h b/drivers/usb/chipidea/bits.h
index 464584c6ccae..a85713165688 100644
--- a/drivers/usb/chipidea/bits.h
+++ b/drivers/usb/chipidea/bits.h
@@ -48,6 +48,7 @@
48#define PORTSC_SUSP BIT(7) 48#define PORTSC_SUSP BIT(7)
49#define PORTSC_HSP BIT(9) 49#define PORTSC_HSP BIT(9)
50#define PORTSC_PTC (0x0FUL << 16) 50#define PORTSC_PTC (0x0FUL << 16)
51#define PORTSC_PHCD(d) ((d) ? BIT(22) : BIT(23))
51/* PTS and PTW for non lpm version only */ 52/* PTS and PTW for non lpm version only */
52#define PORTSC_PTS(d) \ 53#define PORTSC_PTS(d) \
53 (u32)((((d) & 0x3) << 30) | (((d) & 0x4) ? BIT(25) : 0)) 54 (u32)((((d) & 0x3) << 30) | (((d) & 0x4) ? BIT(25) : 0))
diff --git a/drivers/usb/chipidea/ci_hdrc_imx.c b/drivers/usb/chipidea/ci_hdrc_imx.c
index be822a2c1776..023d3cb6aa0a 100644
--- a/drivers/usb/chipidea/ci_hdrc_imx.c
+++ b/drivers/usb/chipidea/ci_hdrc_imx.c
@@ -108,14 +108,8 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev)
108 } 108 }
109 109
110 data->phy = devm_usb_get_phy_by_phandle(&pdev->dev, "fsl,usbphy", 0); 110 data->phy = devm_usb_get_phy_by_phandle(&pdev->dev, "fsl,usbphy", 0);
111 if (!IS_ERR(data->phy)) { 111 if (IS_ERR(data->phy)) {
112 ret = usb_phy_init(data->phy); 112 ret = PTR_ERR(data->phy);
113 if (ret) {
114 dev_err(&pdev->dev, "unable to init phy: %d\n", ret);
115 goto err_clk;
116 }
117 } else if (PTR_ERR(data->phy) == -EPROBE_DEFER) {
118 ret = -EPROBE_DEFER;
119 goto err_clk; 113 goto err_clk;
120 } 114 }
121 115
@@ -131,7 +125,7 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev)
131 if (ret) { 125 if (ret) {
132 dev_err(&pdev->dev, "usbmisc init failed, ret=%d\n", 126 dev_err(&pdev->dev, "usbmisc init failed, ret=%d\n",
133 ret); 127 ret);
134 goto err_phy; 128 goto err_clk;
135 } 129 }
136 } 130 }
137 131
@@ -143,7 +137,7 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev)
143 dev_err(&pdev->dev, 137 dev_err(&pdev->dev,
144 "Can't register ci_hdrc platform device, err=%d\n", 138 "Can't register ci_hdrc platform device, err=%d\n",
145 ret); 139 ret);
146 goto err_phy; 140 goto err_clk;
147 } 141 }
148 142
149 if (data->usbmisc_data) { 143 if (data->usbmisc_data) {
@@ -164,9 +158,6 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev)
164 158
165disable_device: 159disable_device:
166 ci_hdrc_remove_device(data->ci_pdev); 160 ci_hdrc_remove_device(data->ci_pdev);
167err_phy:
168 if (data->phy)
169 usb_phy_shutdown(data->phy);
170err_clk: 161err_clk:
171 clk_disable_unprepare(data->clk); 162 clk_disable_unprepare(data->clk);
172 return ret; 163 return ret;
@@ -178,10 +169,6 @@ static int ci_hdrc_imx_remove(struct platform_device *pdev)
178 169
179 pm_runtime_disable(&pdev->dev); 170 pm_runtime_disable(&pdev->dev);
180 ci_hdrc_remove_device(data->ci_pdev); 171 ci_hdrc_remove_device(data->ci_pdev);
181
182 if (data->phy)
183 usb_phy_shutdown(data->phy);
184
185 clk_disable_unprepare(data->clk); 172 clk_disable_unprepare(data->clk);
186 173
187 return 0; 174 return 0;
diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c
index 23763dcec069..5d8981c5235e 100644
--- a/drivers/usb/chipidea/core.c
+++ b/drivers/usb/chipidea/core.c
@@ -172,6 +172,27 @@ u8 hw_port_test_get(struct ci_hdrc *ci)
172 return hw_read(ci, OP_PORTSC, PORTSC_PTC) >> __ffs(PORTSC_PTC); 172 return hw_read(ci, OP_PORTSC, PORTSC_PTC) >> __ffs(PORTSC_PTC);
173} 173}
174 174
175/* The PHY enters/leaves low power mode */
176static void ci_hdrc_enter_lpm(struct ci_hdrc *ci, bool enable)
177{
178 enum ci_hw_regs reg = ci->hw_bank.lpm ? OP_DEVLC : OP_PORTSC;
179 bool lpm = !!(hw_read(ci, reg, PORTSC_PHCD(ci->hw_bank.lpm)));
180
181 if (enable && !lpm) {
182 hw_write(ci, reg, PORTSC_PHCD(ci->hw_bank.lpm),
183 PORTSC_PHCD(ci->hw_bank.lpm));
184 } else if (!enable && lpm) {
185 hw_write(ci, reg, PORTSC_PHCD(ci->hw_bank.lpm),
186 0);
187 /*
188 * The controller needs at least 1ms to reflect
189 * PHY's status, the PHY also needs some time (less
190 * than 1ms) to leave low power mode.
191 */
192 usleep_range(1500, 2000);
193 }
194}
195
175static int hw_device_init(struct ci_hdrc *ci, void __iomem *base) 196static int hw_device_init(struct ci_hdrc *ci, void __iomem *base)
176{ 197{
177 u32 reg; 198 u32 reg;
@@ -199,6 +220,8 @@ static int hw_device_init(struct ci_hdrc *ci, void __iomem *base)
199 if (ci->hw_ep_max > ENDPT_MAX) 220 if (ci->hw_ep_max > ENDPT_MAX)
200 return -ENODEV; 221 return -ENODEV;
201 222
223 ci_hdrc_enter_lpm(ci, false);
224
202 /* Disable all interrupts bits */ 225 /* Disable all interrupts bits */
203 hw_write(ci, OP_USBINTR, 0xffffffff, 0); 226 hw_write(ci, OP_USBINTR, 0xffffffff, 0);
204 227
@@ -369,16 +392,28 @@ static irqreturn_t ci_irq(int irq, void *data)
369static int ci_get_platdata(struct device *dev, 392static int ci_get_platdata(struct device *dev,
370 struct ci_hdrc_platform_data *platdata) 393 struct ci_hdrc_platform_data *platdata)
371{ 394{
372 /* Get the vbus regulator */ 395 if (!platdata->phy_mode)
373 platdata->reg_vbus = devm_regulator_get(dev, "vbus"); 396 platdata->phy_mode = of_usb_get_phy_mode(dev->of_node);
374 if (PTR_ERR(platdata->reg_vbus) == -EPROBE_DEFER) { 397
375 return -EPROBE_DEFER; 398 if (!platdata->dr_mode)
376 } else if (PTR_ERR(platdata->reg_vbus) == -ENODEV) { 399 platdata->dr_mode = of_usb_get_dr_mode(dev->of_node);
377 platdata->reg_vbus = NULL; /* no vbus regualator is needed */ 400
378 } else if (IS_ERR(platdata->reg_vbus)) { 401 if (platdata->dr_mode == USB_DR_MODE_UNKNOWN)
379 dev_err(dev, "Getting regulator error: %ld\n", 402 platdata->dr_mode = USB_DR_MODE_OTG;
380 PTR_ERR(platdata->reg_vbus)); 403
381 return PTR_ERR(platdata->reg_vbus); 404 if (platdata->dr_mode != USB_DR_MODE_PERIPHERAL) {
405 /* Get the vbus regulator */
406 platdata->reg_vbus = devm_regulator_get(dev, "vbus");
407 if (PTR_ERR(platdata->reg_vbus) == -EPROBE_DEFER) {
408 return -EPROBE_DEFER;
409 } else if (PTR_ERR(platdata->reg_vbus) == -ENODEV) {
410 /* no vbus regualator is needed */
411 platdata->reg_vbus = NULL;
412 } else if (IS_ERR(platdata->reg_vbus)) {
413 dev_err(dev, "Getting regulator error: %ld\n",
414 PTR_ERR(platdata->reg_vbus));
415 return PTR_ERR(platdata->reg_vbus);
416 }
382 } 417 }
383 418
384 return 0; 419 return 0;
@@ -465,6 +500,33 @@ static void ci_get_otg_capable(struct ci_hdrc *ci)
465 } 500 }
466} 501}
467 502
503static int ci_usb_phy_init(struct ci_hdrc *ci)
504{
505 if (ci->platdata->phy) {
506 ci->transceiver = ci->platdata->phy;
507 return usb_phy_init(ci->transceiver);
508 } else {
509 ci->global_phy = true;
510 ci->transceiver = usb_get_phy(USB_PHY_TYPE_USB2);
511 if (IS_ERR(ci->transceiver))
512 ci->transceiver = NULL;
513
514 return 0;
515 }
516}
517
518static void ci_usb_phy_destroy(struct ci_hdrc *ci)
519{
520 if (!ci->transceiver)
521 return;
522
523 otg_set_peripheral(ci->transceiver->otg, NULL);
524 if (ci->global_phy)
525 usb_put_phy(ci->transceiver);
526 else
527 usb_phy_shutdown(ci->transceiver);
528}
529
468static int ci_hdrc_probe(struct platform_device *pdev) 530static int ci_hdrc_probe(struct platform_device *pdev)
469{ 531{
470 struct device *dev = &pdev->dev; 532 struct device *dev = &pdev->dev;
@@ -473,7 +535,6 @@ static int ci_hdrc_probe(struct platform_device *pdev)
473 void __iomem *base; 535 void __iomem *base;
474 int ret; 536 int ret;
475 enum usb_dr_mode dr_mode; 537 enum usb_dr_mode dr_mode;
476 struct device_node *of_node = dev->of_node ?: dev->parent->of_node;
477 538
478 if (!dev->platform_data) { 539 if (!dev->platform_data) {
479 dev_err(dev, "platform data missing\n"); 540 dev_err(dev, "platform data missing\n");
@@ -493,10 +554,6 @@ static int ci_hdrc_probe(struct platform_device *pdev)
493 554
494 ci->dev = dev; 555 ci->dev = dev;
495 ci->platdata = dev->platform_data; 556 ci->platdata = dev->platform_data;
496 if (ci->platdata->phy)
497 ci->transceiver = ci->platdata->phy;
498 else
499 ci->global_phy = true;
500 557
501 ret = hw_device_init(ci, base); 558 ret = hw_device_init(ci, base);
502 if (ret < 0) { 559 if (ret < 0) {
@@ -504,27 +561,25 @@ static int ci_hdrc_probe(struct platform_device *pdev)
504 return -ENODEV; 561 return -ENODEV;
505 } 562 }
506 563
564 ret = ci_usb_phy_init(ci);
565 if (ret) {
566 dev_err(dev, "unable to init phy: %d\n", ret);
567 return ret;
568 }
569
507 ci->hw_bank.phys = res->start; 570 ci->hw_bank.phys = res->start;
508 571
509 ci->irq = platform_get_irq(pdev, 0); 572 ci->irq = platform_get_irq(pdev, 0);
510 if (ci->irq < 0) { 573 if (ci->irq < 0) {
511 dev_err(dev, "missing IRQ\n"); 574 dev_err(dev, "missing IRQ\n");
512 return -ENODEV; 575 ret = -ENODEV;
576 goto destroy_phy;
513 } 577 }
514 578
515 ci_get_otg_capable(ci); 579 ci_get_otg_capable(ci);
516 580
517 if (!ci->platdata->phy_mode)
518 ci->platdata->phy_mode = of_usb_get_phy_mode(of_node);
519
520 hw_phymode_configure(ci); 581 hw_phymode_configure(ci);
521 582
522 if (!ci->platdata->dr_mode)
523 ci->platdata->dr_mode = of_usb_get_dr_mode(of_node);
524
525 if (ci->platdata->dr_mode == USB_DR_MODE_UNKNOWN)
526 ci->platdata->dr_mode = USB_DR_MODE_OTG;
527
528 dr_mode = ci->platdata->dr_mode; 583 dr_mode = ci->platdata->dr_mode;
529 /* initialize role(s) before the interrupt is requested */ 584 /* initialize role(s) before the interrupt is requested */
530 if (dr_mode == USB_DR_MODE_OTG || dr_mode == USB_DR_MODE_HOST) { 585 if (dr_mode == USB_DR_MODE_OTG || dr_mode == USB_DR_MODE_HOST) {
@@ -537,11 +592,23 @@ static int ci_hdrc_probe(struct platform_device *pdev)
537 ret = ci_hdrc_gadget_init(ci); 592 ret = ci_hdrc_gadget_init(ci);
538 if (ret) 593 if (ret)
539 dev_info(dev, "doesn't support gadget\n"); 594 dev_info(dev, "doesn't support gadget\n");
595 if (!ret && ci->transceiver) {
596 ret = otg_set_peripheral(ci->transceiver->otg,
597 &ci->gadget);
598 /*
599 * If we implement all USB functions using chipidea drivers,
600 * it doesn't need to call above API, meanwhile, if we only
601 * use gadget function, calling above API is useless.
602 */
603 if (ret && ret != -ENOTSUPP)
604 goto destroy_phy;
605 }
540 } 606 }
541 607
542 if (!ci->roles[CI_ROLE_HOST] && !ci->roles[CI_ROLE_GADGET]) { 608 if (!ci->roles[CI_ROLE_HOST] && !ci->roles[CI_ROLE_GADGET]) {
543 dev_err(dev, "no supported roles\n"); 609 dev_err(dev, "no supported roles\n");
544 return -ENODEV; 610 ret = -ENODEV;
611 goto destroy_phy;
545 } 612 }
546 613
547 if (ci->is_otg) { 614 if (ci->is_otg) {
@@ -594,6 +661,8 @@ static int ci_hdrc_probe(struct platform_device *pdev)
594 free_irq(ci->irq, ci); 661 free_irq(ci->irq, ci);
595stop: 662stop:
596 ci_role_destroy(ci); 663 ci_role_destroy(ci);
664destroy_phy:
665 ci_usb_phy_destroy(ci);
597 666
598 return ret; 667 return ret;
599} 668}
@@ -605,6 +674,8 @@ static int ci_hdrc_remove(struct platform_device *pdev)
605 dbg_remove_files(ci); 674 dbg_remove_files(ci);
606 free_irq(ci->irq, ci); 675 free_irq(ci->irq, ci);
607 ci_role_destroy(ci); 676 ci_role_destroy(ci);
677 ci_hdrc_enter_lpm(ci, true);
678 ci_usb_phy_destroy(ci);
608 kfree(ci->hw_bank.regmap); 679 kfree(ci->hw_bank.regmap);
609 680
610 return 0; 681 return 0;
diff --git a/drivers/usb/chipidea/host.c b/drivers/usb/chipidea/host.c
index 64d7a6d9a1ad..59e6020ea753 100644
--- a/drivers/usb/chipidea/host.c
+++ b/drivers/usb/chipidea/host.c
@@ -103,15 +103,15 @@ static void host_stop(struct ci_hdrc *ci)
103 if (hcd) { 103 if (hcd) {
104 usb_remove_hcd(hcd); 104 usb_remove_hcd(hcd);
105 usb_put_hcd(hcd); 105 usb_put_hcd(hcd);
106 if (ci->platdata->reg_vbus)
107 regulator_disable(ci->platdata->reg_vbus);
106 } 108 }
107 if (ci->platdata->reg_vbus)
108 regulator_disable(ci->platdata->reg_vbus);
109} 109}
110 110
111 111
112void ci_hdrc_host_destroy(struct ci_hdrc *ci) 112void ci_hdrc_host_destroy(struct ci_hdrc *ci)
113{ 113{
114 if (ci->role == CI_ROLE_HOST) 114 if (ci->role == CI_ROLE_HOST && ci->hcd)
115 host_stop(ci); 115 host_stop(ci);
116} 116}
117 117
diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c
index 9333083dd111..b34c81969cba 100644
--- a/drivers/usb/chipidea/udc.c
+++ b/drivers/usb/chipidea/udc.c
@@ -20,7 +20,6 @@
20#include <linux/pm_runtime.h> 20#include <linux/pm_runtime.h>
21#include <linux/usb/ch9.h> 21#include <linux/usb/ch9.h>
22#include <linux/usb/gadget.h> 22#include <linux/usb/gadget.h>
23#include <linux/usb/otg.h>
24#include <linux/usb/chipidea.h> 23#include <linux/usb/chipidea.h>
25 24
26#include "ci.h" 25#include "ci.h"
@@ -686,9 +685,6 @@ static int _gadget_stop_activity(struct usb_gadget *gadget)
686 usb_ep_fifo_flush(&ci->ep0out->ep); 685 usb_ep_fifo_flush(&ci->ep0out->ep);
687 usb_ep_fifo_flush(&ci->ep0in->ep); 686 usb_ep_fifo_flush(&ci->ep0in->ep);
688 687
689 if (ci->driver)
690 ci->driver->disconnect(gadget);
691
692 /* make sure to disable all endpoints */ 688 /* make sure to disable all endpoints */
693 gadget_for_each_ep(ep, gadget) { 689 gadget_for_each_ep(ep, gadget) {
694 usb_ep_disable(ep); 690 usb_ep_disable(ep);
@@ -718,6 +714,11 @@ __acquires(ci->lock)
718 int retval; 714 int retval;
719 715
720 spin_unlock(&ci->lock); 716 spin_unlock(&ci->lock);
717 if (ci->gadget.speed != USB_SPEED_UNKNOWN) {
718 if (ci->driver)
719 ci->driver->disconnect(&ci->gadget);
720 }
721
721 retval = _gadget_stop_activity(&ci->gadget); 722 retval = _gadget_stop_activity(&ci->gadget);
722 if (retval) 723 if (retval)
723 goto done; 724 goto done;
@@ -1461,6 +1462,8 @@ static int ci_udc_vbus_session(struct usb_gadget *_gadget, int is_active)
1461 hw_device_state(ci, ci->ep0out->qh.dma); 1462 hw_device_state(ci, ci->ep0out->qh.dma);
1462 dev_dbg(ci->dev, "Connected to host\n"); 1463 dev_dbg(ci->dev, "Connected to host\n");
1463 } else { 1464 } else {
1465 if (ci->driver)
1466 ci->driver->disconnect(&ci->gadget);
1464 hw_device_state(ci, 0); 1467 hw_device_state(ci, 0);
1465 if (ci->platdata->notify_event) 1468 if (ci->platdata->notify_event)
1466 ci->platdata->notify_event(ci, 1469 ci->platdata->notify_event(ci,
@@ -1633,23 +1636,22 @@ static int ci_udc_start(struct usb_gadget *gadget,
1633 retval = usb_ep_enable(&ci->ep0in->ep); 1636 retval = usb_ep_enable(&ci->ep0in->ep);
1634 if (retval) 1637 if (retval)
1635 return retval; 1638 return retval;
1636 spin_lock_irqsave(&ci->lock, flags);
1637 1639
1638 ci->driver = driver; 1640 ci->driver = driver;
1639 pm_runtime_get_sync(&ci->gadget.dev); 1641 pm_runtime_get_sync(&ci->gadget.dev);
1640 if (ci->vbus_active) { 1642 if (ci->vbus_active) {
1643 spin_lock_irqsave(&ci->lock, flags);
1641 hw_device_reset(ci, USBMODE_CM_DC); 1644 hw_device_reset(ci, USBMODE_CM_DC);
1642 } else { 1645 } else {
1643 pm_runtime_put_sync(&ci->gadget.dev); 1646 pm_runtime_put_sync(&ci->gadget.dev);
1644 goto done; 1647 return retval;
1645 } 1648 }
1646 1649
1647 retval = hw_device_state(ci, ci->ep0out->qh.dma); 1650 retval = hw_device_state(ci, ci->ep0out->qh.dma);
1651 spin_unlock_irqrestore(&ci->lock, flags);
1648 if (retval) 1652 if (retval)
1649 pm_runtime_put_sync(&ci->gadget.dev); 1653 pm_runtime_put_sync(&ci->gadget.dev);
1650 1654
1651 done:
1652 spin_unlock_irqrestore(&ci->lock, flags);
1653 return retval; 1655 return retval;
1654} 1656}
1655 1657
@@ -1786,34 +1788,9 @@ static int udc_start(struct ci_hdrc *ci)
1786 1788
1787 ci->gadget.ep0 = &ci->ep0in->ep; 1789 ci->gadget.ep0 = &ci->ep0in->ep;
1788 1790
1789 if (ci->global_phy) {
1790 ci->transceiver = usb_get_phy(USB_PHY_TYPE_USB2);
1791 if (IS_ERR(ci->transceiver))
1792 ci->transceiver = NULL;
1793 }
1794
1795 if (ci->platdata->flags & CI_HDRC_REQUIRE_TRANSCEIVER) {
1796 if (ci->transceiver == NULL) {
1797 retval = -ENODEV;
1798 goto destroy_eps;
1799 }
1800 }
1801
1802 if (ci->transceiver) {
1803 retval = otg_set_peripheral(ci->transceiver->otg,
1804 &ci->gadget);
1805 /*
1806 * If we implement all USB functions using chipidea drivers,
1807 * it doesn't need to call above API, meanwhile, if we only
1808 * use gadget function, calling above API is useless.
1809 */
1810 if (retval && retval != -ENOTSUPP)
1811 goto put_transceiver;
1812 }
1813
1814 retval = usb_add_gadget_udc(dev, &ci->gadget); 1791 retval = usb_add_gadget_udc(dev, &ci->gadget);
1815 if (retval) 1792 if (retval)
1816 goto remove_trans; 1793 goto destroy_eps;
1817 1794
1818 pm_runtime_no_callbacks(&ci->gadget.dev); 1795 pm_runtime_no_callbacks(&ci->gadget.dev);
1819 pm_runtime_enable(&ci->gadget.dev); 1796 pm_runtime_enable(&ci->gadget.dev);
@@ -1823,17 +1800,6 @@ static int udc_start(struct ci_hdrc *ci)
1823 1800
1824 return retval; 1801 return retval;
1825 1802
1826remove_trans:
1827 if (ci->transceiver) {
1828 otg_set_peripheral(ci->transceiver->otg, NULL);
1829 if (ci->global_phy)
1830 usb_put_phy(ci->transceiver);
1831 }
1832
1833 dev_err(dev, "error = %i\n", retval);
1834put_transceiver:
1835 if (ci->transceiver && ci->global_phy)
1836 usb_put_phy(ci->transceiver);
1837destroy_eps: 1803destroy_eps:
1838 destroy_eps(ci); 1804 destroy_eps(ci);
1839free_pools: 1805free_pools:
diff --git a/drivers/usb/class/cdc-wdm.c b/drivers/usb/class/cdc-wdm.c
index d3318a0df8ee..4d387596f3f0 100644
--- a/drivers/usb/class/cdc-wdm.c
+++ b/drivers/usb/class/cdc-wdm.c
@@ -101,6 +101,7 @@ struct wdm_device {
101 struct work_struct rxwork; 101 struct work_struct rxwork;
102 int werr; 102 int werr;
103 int rerr; 103 int rerr;
104 int resp_count;
104 105
105 struct list_head device_list; 106 struct list_head device_list;
106 int (*manage_power)(struct usb_interface *, int); 107 int (*manage_power)(struct usb_interface *, int);
@@ -253,6 +254,10 @@ static void wdm_int_callback(struct urb *urb)
253 "NOTIFY_NETWORK_CONNECTION %s network", 254 "NOTIFY_NETWORK_CONNECTION %s network",
254 dr->wValue ? "connected to" : "disconnected from"); 255 dr->wValue ? "connected to" : "disconnected from");
255 goto exit; 256 goto exit;
257 case USB_CDC_NOTIFY_SPEED_CHANGE:
258 dev_dbg(&desc->intf->dev, "SPEED_CHANGE received (len %u)",
259 urb->actual_length);
260 goto exit;
256 default: 261 default:
257 clear_bit(WDM_POLL_RUNNING, &desc->flags); 262 clear_bit(WDM_POLL_RUNNING, &desc->flags);
258 dev_err(&desc->intf->dev, 263 dev_err(&desc->intf->dev,
@@ -262,9 +267,9 @@ static void wdm_int_callback(struct urb *urb)
262 } 267 }
263 268
264 spin_lock(&desc->iuspin); 269 spin_lock(&desc->iuspin);
265 clear_bit(WDM_READ, &desc->flags);
266 responding = test_and_set_bit(WDM_RESPONDING, &desc->flags); 270 responding = test_and_set_bit(WDM_RESPONDING, &desc->flags);
267 if (!responding && !test_bit(WDM_DISCONNECTING, &desc->flags) 271 if (!desc->resp_count++ && !responding
272 && !test_bit(WDM_DISCONNECTING, &desc->flags)
268 && !test_bit(WDM_SUSPENDING, &desc->flags)) { 273 && !test_bit(WDM_SUSPENDING, &desc->flags)) {
269 rv = usb_submit_urb(desc->response, GFP_ATOMIC); 274 rv = usb_submit_urb(desc->response, GFP_ATOMIC);
270 dev_dbg(&desc->intf->dev, "%s: usb_submit_urb %d", 275 dev_dbg(&desc->intf->dev, "%s: usb_submit_urb %d",
@@ -521,10 +526,36 @@ retry:
521 526
522 desc->length -= cntr; 527 desc->length -= cntr;
523 /* in case we had outstanding data */ 528 /* in case we had outstanding data */
524 if (!desc->length) 529 if (!desc->length) {
525 clear_bit(WDM_READ, &desc->flags); 530 clear_bit(WDM_READ, &desc->flags);
526 531
527 spin_unlock_irq(&desc->iuspin); 532 if (--desc->resp_count) {
533 set_bit(WDM_RESPONDING, &desc->flags);
534 spin_unlock_irq(&desc->iuspin);
535
536 rv = usb_submit_urb(desc->response, GFP_KERNEL);
537 if (rv) {
538 dev_err(&desc->intf->dev,
539 "%s: usb_submit_urb failed with result %d\n",
540 __func__, rv);
541 spin_lock_irq(&desc->iuspin);
542 clear_bit(WDM_RESPONDING, &desc->flags);
543 spin_unlock_irq(&desc->iuspin);
544
545 if (rv == -ENOMEM) {
546 rv = schedule_work(&desc->rxwork);
547 if (rv)
548 dev_err(&desc->intf->dev, "Cannot schedule work\n");
549 } else {
550 spin_lock_irq(&desc->iuspin);
551 desc->resp_count = 0;
552 spin_unlock_irq(&desc->iuspin);
553 }
554 }
555 } else
556 spin_unlock_irq(&desc->iuspin);
557 } else
558 spin_unlock_irq(&desc->iuspin);
528 559
529 rv = cntr; 560 rv = cntr;
530 561
@@ -635,6 +666,9 @@ static int wdm_release(struct inode *inode, struct file *file)
635 if (!test_bit(WDM_DISCONNECTING, &desc->flags)) { 666 if (!test_bit(WDM_DISCONNECTING, &desc->flags)) {
636 dev_dbg(&desc->intf->dev, "wdm_release: cleanup"); 667 dev_dbg(&desc->intf->dev, "wdm_release: cleanup");
637 kill_urbs(desc); 668 kill_urbs(desc);
669 spin_lock_irq(&desc->iuspin);
670 desc->resp_count = 0;
671 spin_unlock_irq(&desc->iuspin);
638 desc->manage_power(desc->intf, 0); 672 desc->manage_power(desc->intf, 0);
639 } else { 673 } else {
640 /* must avoid dev_printk here as desc->intf is invalid */ 674 /* must avoid dev_printk here as desc->intf is invalid */
diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index 71dc5d768fa5..967152a63bd3 100644
--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -914,10 +914,8 @@ static int proc_control(struct dev_state *ps, void __user *arg)
914 snoop(&dev->dev, "control urb: bRequestType=%02x " 914 snoop(&dev->dev, "control urb: bRequestType=%02x "
915 "bRequest=%02x wValue=%04x " 915 "bRequest=%02x wValue=%04x "
916 "wIndex=%04x wLength=%04x\n", 916 "wIndex=%04x wLength=%04x\n",
917 ctrl.bRequestType, ctrl.bRequest, 917 ctrl.bRequestType, ctrl.bRequest, ctrl.wValue,
918 __le16_to_cpup(&ctrl.wValue), 918 ctrl.wIndex, ctrl.wLength);
919 __le16_to_cpup(&ctrl.wIndex),
920 __le16_to_cpup(&ctrl.wLength));
921 if (ctrl.bRequestType & 0x80) { 919 if (ctrl.bRequestType & 0x80) {
922 if (ctrl.wLength && !access_ok(VERIFY_WRITE, ctrl.data, 920 if (ctrl.wLength && !access_ok(VERIFY_WRITE, ctrl.data,
923 ctrl.wLength)) { 921 ctrl.wLength)) {
@@ -1636,32 +1634,32 @@ static int proc_reapurbnonblock(struct dev_state *ps, void __user *arg)
1636static int proc_control_compat(struct dev_state *ps, 1634static int proc_control_compat(struct dev_state *ps,
1637 struct usbdevfs_ctrltransfer32 __user *p32) 1635 struct usbdevfs_ctrltransfer32 __user *p32)
1638{ 1636{
1639 struct usbdevfs_ctrltransfer __user *p; 1637 struct usbdevfs_ctrltransfer __user *p;
1640 __u32 udata; 1638 __u32 udata;
1641 p = compat_alloc_user_space(sizeof(*p)); 1639 p = compat_alloc_user_space(sizeof(*p));
1642 if (copy_in_user(p, p32, (sizeof(*p32) - sizeof(compat_caddr_t))) || 1640 if (copy_in_user(p, p32, (sizeof(*p32) - sizeof(compat_caddr_t))) ||
1643 get_user(udata, &p32->data) || 1641 get_user(udata, &p32->data) ||
1644 put_user(compat_ptr(udata), &p->data)) 1642 put_user(compat_ptr(udata), &p->data))
1645 return -EFAULT; 1643 return -EFAULT;
1646 return proc_control(ps, p); 1644 return proc_control(ps, p);
1647} 1645}
1648 1646
1649static int proc_bulk_compat(struct dev_state *ps, 1647static int proc_bulk_compat(struct dev_state *ps,
1650 struct usbdevfs_bulktransfer32 __user *p32) 1648 struct usbdevfs_bulktransfer32 __user *p32)
1651{ 1649{
1652 struct usbdevfs_bulktransfer __user *p; 1650 struct usbdevfs_bulktransfer __user *p;
1653 compat_uint_t n; 1651 compat_uint_t n;
1654 compat_caddr_t addr; 1652 compat_caddr_t addr;
1655 1653
1656 p = compat_alloc_user_space(sizeof(*p)); 1654 p = compat_alloc_user_space(sizeof(*p));
1657 1655
1658 if (get_user(n, &p32->ep) || put_user(n, &p->ep) || 1656 if (get_user(n, &p32->ep) || put_user(n, &p->ep) ||
1659 get_user(n, &p32->len) || put_user(n, &p->len) || 1657 get_user(n, &p32->len) || put_user(n, &p->len) ||
1660 get_user(n, &p32->timeout) || put_user(n, &p->timeout) || 1658 get_user(n, &p32->timeout) || put_user(n, &p->timeout) ||
1661 get_user(addr, &p32->data) || put_user(compat_ptr(addr), &p->data)) 1659 get_user(addr, &p32->data) || put_user(compat_ptr(addr), &p->data))
1662 return -EFAULT; 1660 return -EFAULT;
1663 1661
1664 return proc_bulk(ps, p); 1662 return proc_bulk(ps, p);
1665} 1663}
1666static int proc_disconnectsignal_compat(struct dev_state *ps, void __user *arg) 1664static int proc_disconnectsignal_compat(struct dev_state *ps, void __user *arg)
1667{ 1665{
diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c
index f7841d44feda..47aade2a5e74 100644
--- a/drivers/usb/core/driver.c
+++ b/drivers/usb/core/driver.c
@@ -1179,8 +1179,8 @@ static int usb_resume_interface(struct usb_device *udev,
1179 "reset_resume", status); 1179 "reset_resume", status);
1180 } else { 1180 } else {
1181 intf->needs_binding = 1; 1181 intf->needs_binding = 1;
1182 dev_warn(&intf->dev, "no %s for driver %s?\n", 1182 dev_dbg(&intf->dev, "no reset_resume for driver %s?\n",
1183 "reset_resume", driver->name); 1183 driver->name);
1184 } 1184 }
1185 } else { 1185 } else {
1186 status = driver->resume(intf); 1186 status = driver->resume(intf);
@@ -1790,6 +1790,9 @@ int usb_set_usb2_hardware_lpm(struct usb_device *udev, int enable)
1790 struct usb_hcd *hcd = bus_to_hcd(udev->bus); 1790 struct usb_hcd *hcd = bus_to_hcd(udev->bus);
1791 int ret = -EPERM; 1791 int ret = -EPERM;
1792 1792
1793 if (enable && !udev->usb2_hw_lpm_allowed)
1794 return 0;
1795
1793 if (hcd->driver->set_usb2_hw_lpm) { 1796 if (hcd->driver->set_usb2_hw_lpm) {
1794 ret = hcd->driver->set_usb2_hw_lpm(hcd, udev, enable); 1797 ret = hcd->driver->set_usb2_hw_lpm(hcd, udev, enable);
1795 if (!ret) 1798 if (!ret)
diff --git a/drivers/usb/core/file.c b/drivers/usb/core/file.c
index 7421888087a3..3bdfbf88a0ae 100644
--- a/drivers/usb/core/file.c
+++ b/drivers/usb/core/file.c
@@ -8,7 +8,7 @@
8 * (C) Copyright Deti Fliegl 1999 (new USB architecture) 8 * (C) Copyright Deti Fliegl 1999 (new USB architecture)
9 * (C) Copyright Randy Dunlap 2000 9 * (C) Copyright Randy Dunlap 2000
10 * (C) Copyright David Brownell 2000-2001 (kernel hotplug, usb_device_id, 10 * (C) Copyright David Brownell 2000-2001 (kernel hotplug, usb_device_id,
11 more docs, etc) 11 * more docs, etc)
12 * (C) Copyright Yggdrasil Computing, Inc. 2000 12 * (C) Copyright Yggdrasil Computing, Inc. 2000
13 * (usb_device_id matching changes by Adam J. Richter) 13 * (usb_device_id matching changes by Adam J. Richter)
14 * (C) Copyright Greg Kroah-Hartman 2002-2003 14 * (C) Copyright Greg Kroah-Hartman 2002-2003
@@ -27,7 +27,7 @@
27static const struct file_operations *usb_minors[MAX_USB_MINORS]; 27static const struct file_operations *usb_minors[MAX_USB_MINORS];
28static DECLARE_RWSEM(minor_rwsem); 28static DECLARE_RWSEM(minor_rwsem);
29 29
30static int usb_open(struct inode * inode, struct file * file) 30static int usb_open(struct inode *inode, struct file *file)
31{ 31{
32 int minor = iminor(inode); 32 int minor = iminor(inode);
33 const struct file_operations *c; 33 const struct file_operations *c;
@@ -44,7 +44,7 @@ static int usb_open(struct inode * inode, struct file * file)
44 file->f_op = new_fops; 44 file->f_op = new_fops;
45 /* Curiouser and curiouser... NULL ->open() as "no device" ? */ 45 /* Curiouser and curiouser... NULL ->open() as "no device" ? */
46 if (file->f_op->open) 46 if (file->f_op->open)
47 err = file->f_op->open(inode,file); 47 err = file->f_op->open(inode, file);
48 if (err) { 48 if (err) {
49 fops_put(file->f_op); 49 fops_put(file->f_op);
50 file->f_op = fops_get(old_fops); 50 file->f_op = fops_get(old_fops);
@@ -166,7 +166,7 @@ int usb_register_dev(struct usb_interface *intf,
166 char *temp; 166 char *temp;
167 167
168#ifdef CONFIG_USB_DYNAMIC_MINORS 168#ifdef CONFIG_USB_DYNAMIC_MINORS
169 /* 169 /*
170 * We don't care what the device tries to start at, we want to start 170 * We don't care what the device tries to start at, we want to start
171 * at zero to pack the devices into the smallest available space with 171 * at zero to pack the devices into the smallest available space with
172 * no holes in the minor range. 172 * no holes in the minor range.
diff --git a/drivers/usb/core/hcd-pci.c b/drivers/usb/core/hcd-pci.c
index b9d3c43e3859..dfe9d0f22978 100644
--- a/drivers/usb/core/hcd-pci.c
+++ b/drivers/usb/core/hcd-pci.c
@@ -215,6 +215,9 @@ int usb_hcd_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
215 goto disable_pci; 215 goto disable_pci;
216 } 216 }
217 217
218 hcd->amd_resume_bug = (usb_hcd_amd_remote_wakeup_quirk(dev) &&
219 driver->flags & (HCD_USB11 | HCD_USB3)) ? 1 : 0;
220
218 if (driver->flags & HCD_MEMORY) { 221 if (driver->flags & HCD_MEMORY) {
219 /* EHCI, OHCI */ 222 /* EHCI, OHCI */
220 hcd->rsrc_start = pci_resource_start(dev, 0); 223 hcd->rsrc_start = pci_resource_start(dev, 0);
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index d6a8d23f047b..6bffb8c87bc9 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -6,7 +6,7 @@
6 * (C) Copyright Deti Fliegl 1999 6 * (C) Copyright Deti Fliegl 1999
7 * (C) Copyright Randy Dunlap 2000 7 * (C) Copyright Randy Dunlap 2000
8 * (C) Copyright David Brownell 2000-2002 8 * (C) Copyright David Brownell 2000-2002
9 * 9 *
10 * This program is free software; you can redistribute it and/or modify it 10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the 11 * under the terms of the GNU General Public License as published by the
12 * Free Software Foundation; either version 2 of the License, or (at your 12 * Free Software Foundation; either version 2 of the License, or (at your
@@ -40,6 +40,7 @@
40#include <linux/platform_device.h> 40#include <linux/platform_device.h>
41#include <linux/workqueue.h> 41#include <linux/workqueue.h>
42#include <linux/pm_runtime.h> 42#include <linux/pm_runtime.h>
43#include <linux/types.h>
43 44
44#include <linux/usb.h> 45#include <linux/usb.h>
45#include <linux/usb/hcd.h> 46#include <linux/usb/hcd.h>
@@ -92,10 +93,7 @@ EXPORT_SYMBOL_GPL (usb_bus_list);
92 93
93/* used when allocating bus numbers */ 94/* used when allocating bus numbers */
94#define USB_MAXBUS 64 95#define USB_MAXBUS 64
95struct usb_busmap { 96static DECLARE_BITMAP(busmap, USB_MAXBUS);
96 unsigned long busmap [USB_MAXBUS / (8*sizeof (unsigned long))];
97};
98static struct usb_busmap busmap;
99 97
100/* used when updating list of hcds */ 98/* used when updating list of hcds */
101DEFINE_MUTEX(usb_bus_list_lock); /* exported only for usbfs */ 99DEFINE_MUTEX(usb_bus_list_lock); /* exported only for usbfs */
@@ -171,7 +169,7 @@ static const u8 usb25_rh_dev_descriptor[18] = {
171}; 169};
172 170
173/* usb 2.0 root hub device descriptor */ 171/* usb 2.0 root hub device descriptor */
174static const u8 usb2_rh_dev_descriptor [18] = { 172static const u8 usb2_rh_dev_descriptor[18] = {
175 0x12, /* __u8 bLength; */ 173 0x12, /* __u8 bLength; */
176 0x01, /* __u8 bDescriptorType; Device */ 174 0x01, /* __u8 bDescriptorType; Device */
177 0x00, 0x02, /* __le16 bcdUSB; v2.0 */ 175 0x00, 0x02, /* __le16 bcdUSB; v2.0 */
@@ -194,7 +192,7 @@ static const u8 usb2_rh_dev_descriptor [18] = {
194/* no usb 2.0 root hub "device qualifier" descriptor: one speed only */ 192/* no usb 2.0 root hub "device qualifier" descriptor: one speed only */
195 193
196/* usb 1.1 root hub device descriptor */ 194/* usb 1.1 root hub device descriptor */
197static const u8 usb11_rh_dev_descriptor [18] = { 195static const u8 usb11_rh_dev_descriptor[18] = {
198 0x12, /* __u8 bLength; */ 196 0x12, /* __u8 bLength; */
199 0x01, /* __u8 bDescriptorType; Device */ 197 0x01, /* __u8 bDescriptorType; Device */
200 0x10, 0x01, /* __le16 bcdUSB; v1.1 */ 198 0x10, 0x01, /* __le16 bcdUSB; v1.1 */
@@ -219,7 +217,7 @@ static const u8 usb11_rh_dev_descriptor [18] = {
219 217
220/* Configuration descriptors for our root hubs */ 218/* Configuration descriptors for our root hubs */
221 219
222static const u8 fs_rh_config_descriptor [] = { 220static const u8 fs_rh_config_descriptor[] = {
223 221
224 /* one configuration */ 222 /* one configuration */
225 0x09, /* __u8 bLength; */ 223 0x09, /* __u8 bLength; */
@@ -228,13 +226,13 @@ static const u8 fs_rh_config_descriptor [] = {
228 0x01, /* __u8 bNumInterfaces; (1) */ 226 0x01, /* __u8 bNumInterfaces; (1) */
229 0x01, /* __u8 bConfigurationValue; */ 227 0x01, /* __u8 bConfigurationValue; */
230 0x00, /* __u8 iConfiguration; */ 228 0x00, /* __u8 iConfiguration; */
231 0xc0, /* __u8 bmAttributes; 229 0xc0, /* __u8 bmAttributes;
232 Bit 7: must be set, 230 Bit 7: must be set,
233 6: Self-powered, 231 6: Self-powered,
234 5: Remote wakeup, 232 5: Remote wakeup,
235 4..0: resvd */ 233 4..0: resvd */
236 0x00, /* __u8 MaxPower; */ 234 0x00, /* __u8 MaxPower; */
237 235
238 /* USB 1.1: 236 /* USB 1.1:
239 * USB 2.0, single TT organization (mandatory): 237 * USB 2.0, single TT organization (mandatory):
240 * one interface, protocol 0 238 * one interface, protocol 0
@@ -256,17 +254,17 @@ static const u8 fs_rh_config_descriptor [] = {
256 0x00, /* __u8 if_bInterfaceSubClass; */ 254 0x00, /* __u8 if_bInterfaceSubClass; */
257 0x00, /* __u8 if_bInterfaceProtocol; [usb1.1 or single tt] */ 255 0x00, /* __u8 if_bInterfaceProtocol; [usb1.1 or single tt] */
258 0x00, /* __u8 if_iInterface; */ 256 0x00, /* __u8 if_iInterface; */
259 257
260 /* one endpoint (status change endpoint) */ 258 /* one endpoint (status change endpoint) */
261 0x07, /* __u8 ep_bLength; */ 259 0x07, /* __u8 ep_bLength; */
262 0x05, /* __u8 ep_bDescriptorType; Endpoint */ 260 0x05, /* __u8 ep_bDescriptorType; Endpoint */
263 0x81, /* __u8 ep_bEndpointAddress; IN Endpoint 1 */ 261 0x81, /* __u8 ep_bEndpointAddress; IN Endpoint 1 */
264 0x03, /* __u8 ep_bmAttributes; Interrupt */ 262 0x03, /* __u8 ep_bmAttributes; Interrupt */
265 0x02, 0x00, /* __le16 ep_wMaxPacketSize; 1 + (MAX_ROOT_PORTS / 8) */ 263 0x02, 0x00, /* __le16 ep_wMaxPacketSize; 1 + (MAX_ROOT_PORTS / 8) */
266 0xff /* __u8 ep_bInterval; (255ms -- usb 2.0 spec) */ 264 0xff /* __u8 ep_bInterval; (255ms -- usb 2.0 spec) */
267}; 265};
268 266
269static const u8 hs_rh_config_descriptor [] = { 267static const u8 hs_rh_config_descriptor[] = {
270 268
271 /* one configuration */ 269 /* one configuration */
272 0x09, /* __u8 bLength; */ 270 0x09, /* __u8 bLength; */
@@ -275,13 +273,13 @@ static const u8 hs_rh_config_descriptor [] = {
275 0x01, /* __u8 bNumInterfaces; (1) */ 273 0x01, /* __u8 bNumInterfaces; (1) */
276 0x01, /* __u8 bConfigurationValue; */ 274 0x01, /* __u8 bConfigurationValue; */
277 0x00, /* __u8 iConfiguration; */ 275 0x00, /* __u8 iConfiguration; */
278 0xc0, /* __u8 bmAttributes; 276 0xc0, /* __u8 bmAttributes;
279 Bit 7: must be set, 277 Bit 7: must be set,
280 6: Self-powered, 278 6: Self-powered,
281 5: Remote wakeup, 279 5: Remote wakeup,
282 4..0: resvd */ 280 4..0: resvd */
283 0x00, /* __u8 MaxPower; */ 281 0x00, /* __u8 MaxPower; */
284 282
285 /* USB 1.1: 283 /* USB 1.1:
286 * USB 2.0, single TT organization (mandatory): 284 * USB 2.0, single TT organization (mandatory):
287 * one interface, protocol 0 285 * one interface, protocol 0
@@ -303,12 +301,12 @@ static const u8 hs_rh_config_descriptor [] = {
303 0x00, /* __u8 if_bInterfaceSubClass; */ 301 0x00, /* __u8 if_bInterfaceSubClass; */
304 0x00, /* __u8 if_bInterfaceProtocol; [usb1.1 or single tt] */ 302 0x00, /* __u8 if_bInterfaceProtocol; [usb1.1 or single tt] */
305 0x00, /* __u8 if_iInterface; */ 303 0x00, /* __u8 if_iInterface; */
306 304
307 /* one endpoint (status change endpoint) */ 305 /* one endpoint (status change endpoint) */
308 0x07, /* __u8 ep_bLength; */ 306 0x07, /* __u8 ep_bLength; */
309 0x05, /* __u8 ep_bDescriptorType; Endpoint */ 307 0x05, /* __u8 ep_bDescriptorType; Endpoint */
310 0x81, /* __u8 ep_bEndpointAddress; IN Endpoint 1 */ 308 0x81, /* __u8 ep_bEndpointAddress; IN Endpoint 1 */
311 0x03, /* __u8 ep_bmAttributes; Interrupt */ 309 0x03, /* __u8 ep_bmAttributes; Interrupt */
312 /* __le16 ep_wMaxPacketSize; 1 + (MAX_ROOT_PORTS / 8) 310 /* __le16 ep_wMaxPacketSize; 1 + (MAX_ROOT_PORTS / 8)
313 * see hub.c:hub_configure() for details. */ 311 * see hub.c:hub_configure() for details. */
314 (USB_MAXCHILDREN + 1 + 7) / 8, 0x00, 312 (USB_MAXCHILDREN + 1 + 7) / 8, 0x00,
@@ -428,7 +426,7 @@ rh_string(int id, struct usb_hcd const *hcd, u8 *data, unsigned len)
428 char const *s; 426 char const *s;
429 static char const langids[4] = {4, USB_DT_STRING, 0x09, 0x04}; 427 static char const langids[4] = {4, USB_DT_STRING, 0x09, 0x04};
430 428
431 // language ids 429 /* language ids */
432 switch (id) { 430 switch (id) {
433 case 0: 431 case 0:
434 /* Array of LANGID codes (0x0409 is MSFT-speak for "en-us") */ 432 /* Array of LANGID codes (0x0409 is MSFT-speak for "en-us") */
@@ -464,7 +462,7 @@ rh_string(int id, struct usb_hcd const *hcd, u8 *data, unsigned len)
464static int rh_call_control (struct usb_hcd *hcd, struct urb *urb) 462static int rh_call_control (struct usb_hcd *hcd, struct urb *urb)
465{ 463{
466 struct usb_ctrlrequest *cmd; 464 struct usb_ctrlrequest *cmd;
467 u16 typeReq, wValue, wIndex, wLength; 465 u16 typeReq, wValue, wIndex, wLength;
468 u8 *ubuf = urb->transfer_buffer; 466 u8 *ubuf = urb->transfer_buffer;
469 unsigned len = 0; 467 unsigned len = 0;
470 int status; 468 int status;
@@ -526,10 +524,10 @@ static int rh_call_control (struct usb_hcd *hcd, struct urb *urb)
526 */ 524 */
527 525
528 case DeviceRequest | USB_REQ_GET_STATUS: 526 case DeviceRequest | USB_REQ_GET_STATUS:
529 tbuf [0] = (device_may_wakeup(&hcd->self.root_hub->dev) 527 tbuf[0] = (device_may_wakeup(&hcd->self.root_hub->dev)
530 << USB_DEVICE_REMOTE_WAKEUP) 528 << USB_DEVICE_REMOTE_WAKEUP)
531 | (1 << USB_DEVICE_SELF_POWERED); 529 | (1 << USB_DEVICE_SELF_POWERED);
532 tbuf [1] = 0; 530 tbuf[1] = 0;
533 len = 2; 531 len = 2;
534 break; 532 break;
535 case DeviceOutRequest | USB_REQ_CLEAR_FEATURE: 533 case DeviceOutRequest | USB_REQ_CLEAR_FEATURE:
@@ -546,7 +544,7 @@ static int rh_call_control (struct usb_hcd *hcd, struct urb *urb)
546 goto error; 544 goto error;
547 break; 545 break;
548 case DeviceRequest | USB_REQ_GET_CONFIGURATION: 546 case DeviceRequest | USB_REQ_GET_CONFIGURATION:
549 tbuf [0] = 1; 547 tbuf[0] = 1;
550 len = 1; 548 len = 1;
551 /* FALLTHROUGH */ 549 /* FALLTHROUGH */
552 case DeviceOutRequest | USB_REQ_SET_CONFIGURATION: 550 case DeviceOutRequest | USB_REQ_SET_CONFIGURATION:
@@ -609,13 +607,13 @@ static int rh_call_control (struct usb_hcd *hcd, struct urb *urb)
609 } 607 }
610 break; 608 break;
611 case DeviceRequest | USB_REQ_GET_INTERFACE: 609 case DeviceRequest | USB_REQ_GET_INTERFACE:
612 tbuf [0] = 0; 610 tbuf[0] = 0;
613 len = 1; 611 len = 1;
614 /* FALLTHROUGH */ 612 /* FALLTHROUGH */
615 case DeviceOutRequest | USB_REQ_SET_INTERFACE: 613 case DeviceOutRequest | USB_REQ_SET_INTERFACE:
616 break; 614 break;
617 case DeviceOutRequest | USB_REQ_SET_ADDRESS: 615 case DeviceOutRequest | USB_REQ_SET_ADDRESS:
618 // wValue == urb->dev->devaddr 616 /* wValue == urb->dev->devaddr */
619 dev_dbg (hcd->self.controller, "root hub device address %d\n", 617 dev_dbg (hcd->self.controller, "root hub device address %d\n",
620 wValue); 618 wValue);
621 break; 619 break;
@@ -625,9 +623,9 @@ static int rh_call_control (struct usb_hcd *hcd, struct urb *urb)
625 /* ENDPOINT REQUESTS */ 623 /* ENDPOINT REQUESTS */
626 624
627 case EndpointRequest | USB_REQ_GET_STATUS: 625 case EndpointRequest | USB_REQ_GET_STATUS:
628 // ENDPOINT_HALT flag 626 /* ENDPOINT_HALT flag */
629 tbuf [0] = 0; 627 tbuf[0] = 0;
630 tbuf [1] = 0; 628 tbuf[1] = 0;
631 len = 2; 629 len = 2;
632 /* FALLTHROUGH */ 630 /* FALLTHROUGH */
633 case EndpointOutRequest | USB_REQ_CLEAR_FEATURE: 631 case EndpointOutRequest | USB_REQ_CLEAR_FEATURE:
@@ -683,7 +681,7 @@ error:
683 if (urb->transfer_buffer_length < len) 681 if (urb->transfer_buffer_length < len)
684 len = urb->transfer_buffer_length; 682 len = urb->transfer_buffer_length;
685 urb->actual_length = len; 683 urb->actual_length = len;
686 // always USB_DIR_IN, toward host 684 /* always USB_DIR_IN, toward host */
687 memcpy (ubuf, bufp, len); 685 memcpy (ubuf, bufp, len);
688 686
689 /* report whether RH hardware supports remote wakeup */ 687 /* report whether RH hardware supports remote wakeup */
@@ -877,11 +875,11 @@ static ssize_t authorized_default_store(struct device *dev,
877 usb_hcd = bus_to_hcd(usb_bus); 875 usb_hcd = bus_to_hcd(usb_bus);
878 result = sscanf(buf, "%u\n", &val); 876 result = sscanf(buf, "%u\n", &val);
879 if (result == 1) { 877 if (result == 1) {
880 usb_hcd->authorized_default = val? 1 : 0; 878 usb_hcd->authorized_default = val ? 1 : 0;
881 result = size; 879 result = size;
882 } 880 } else {
883 else
884 result = -EINVAL; 881 result = -EINVAL;
882 }
885 return result; 883 return result;
886} 884}
887static DEVICE_ATTR_RW(authorized_default); 885static DEVICE_ATTR_RW(authorized_default);
@@ -941,12 +939,12 @@ static int usb_register_bus(struct usb_bus *bus)
941 int busnum; 939 int busnum;
942 940
943 mutex_lock(&usb_bus_list_lock); 941 mutex_lock(&usb_bus_list_lock);
944 busnum = find_next_zero_bit (busmap.busmap, USB_MAXBUS, 1); 942 busnum = find_next_zero_bit(busmap, USB_MAXBUS, 1);
945 if (busnum >= USB_MAXBUS) { 943 if (busnum >= USB_MAXBUS) {
946 printk (KERN_ERR "%s: too many buses\n", usbcore_name); 944 printk (KERN_ERR "%s: too many buses\n", usbcore_name);
947 goto error_find_busnum; 945 goto error_find_busnum;
948 } 946 }
949 set_bit (busnum, busmap.busmap); 947 set_bit(busnum, busmap);
950 bus->busnum = busnum; 948 bus->busnum = busnum;
951 949
952 /* Add it to the local list of buses */ 950 /* Add it to the local list of buses */
@@ -987,7 +985,7 @@ static void usb_deregister_bus (struct usb_bus *bus)
987 985
988 usb_notify_remove_bus(bus); 986 usb_notify_remove_bus(bus);
989 987
990 clear_bit (bus->busnum, busmap.busmap); 988 clear_bit(bus->busnum, busmap);
991} 989}
992 990
993/** 991/**
@@ -1033,6 +1031,7 @@ static int register_root_hub(struct usb_hcd *hcd)
1033 dev_name(&usb_dev->dev), retval); 1031 dev_name(&usb_dev->dev), retval);
1034 return retval; 1032 return retval;
1035 } 1033 }
1034 usb_dev->lpm_capable = usb_device_supports_lpm(usb_dev);
1036 } 1035 }
1037 1036
1038 retval = usb_new_device (usb_dev); 1037 retval = usb_new_device (usb_dev);
@@ -1120,21 +1119,21 @@ long usb_calc_bus_time (int speed, int is_input, int isoc, int bytecount)
1120 case USB_SPEED_LOW: /* INTR only */ 1119 case USB_SPEED_LOW: /* INTR only */
1121 if (is_input) { 1120 if (is_input) {
1122 tmp = (67667L * (31L + 10L * BitTime (bytecount))) / 1000L; 1121 tmp = (67667L * (31L + 10L * BitTime (bytecount))) / 1000L;
1123 return (64060L + (2 * BW_HUB_LS_SETUP) + BW_HOST_DELAY + tmp); 1122 return 64060L + (2 * BW_HUB_LS_SETUP) + BW_HOST_DELAY + tmp;
1124 } else { 1123 } else {
1125 tmp = (66700L * (31L + 10L * BitTime (bytecount))) / 1000L; 1124 tmp = (66700L * (31L + 10L * BitTime (bytecount))) / 1000L;
1126 return (64107L + (2 * BW_HUB_LS_SETUP) + BW_HOST_DELAY + tmp); 1125 return 64107L + (2 * BW_HUB_LS_SETUP) + BW_HOST_DELAY + tmp;
1127 } 1126 }
1128 case USB_SPEED_FULL: /* ISOC or INTR */ 1127 case USB_SPEED_FULL: /* ISOC or INTR */
1129 if (isoc) { 1128 if (isoc) {
1130 tmp = (8354L * (31L + 10L * BitTime (bytecount))) / 1000L; 1129 tmp = (8354L * (31L + 10L * BitTime (bytecount))) / 1000L;
1131 return (((is_input) ? 7268L : 6265L) + BW_HOST_DELAY + tmp); 1130 return ((is_input) ? 7268L : 6265L) + BW_HOST_DELAY + tmp;
1132 } else { 1131 } else {
1133 tmp = (8354L * (31L + 10L * BitTime (bytecount))) / 1000L; 1132 tmp = (8354L * (31L + 10L * BitTime (bytecount))) / 1000L;
1134 return (9107L + BW_HOST_DELAY + tmp); 1133 return 9107L + BW_HOST_DELAY + tmp;
1135 } 1134 }
1136 case USB_SPEED_HIGH: /* ISOC or INTR */ 1135 case USB_SPEED_HIGH: /* ISOC or INTR */
1137 // FIXME adjust for input vs output 1136 /* FIXME adjust for input vs output */
1138 if (isoc) 1137 if (isoc)
1139 tmp = HS_NSECS_ISO (bytecount); 1138 tmp = HS_NSECS_ISO (bytecount);
1140 else 1139 else
@@ -1651,6 +1650,7 @@ int usb_hcd_unlink_urb (struct urb *urb, int status)
1651static void __usb_hcd_giveback_urb(struct urb *urb) 1650static void __usb_hcd_giveback_urb(struct urb *urb)
1652{ 1651{
1653 struct usb_hcd *hcd = bus_to_hcd(urb->dev->bus); 1652 struct usb_hcd *hcd = bus_to_hcd(urb->dev->bus);
1653 struct usb_anchor *anchor = urb->anchor;
1654 int status = urb->unlinked; 1654 int status = urb->unlinked;
1655 unsigned long flags; 1655 unsigned long flags;
1656 1656
@@ -1662,6 +1662,7 @@ static void __usb_hcd_giveback_urb(struct urb *urb)
1662 1662
1663 unmap_urb_for_dma(hcd, urb); 1663 unmap_urb_for_dma(hcd, urb);
1664 usbmon_urb_complete(&hcd->self, urb, status); 1664 usbmon_urb_complete(&hcd->self, urb, status);
1665 usb_anchor_suspend_wakeups(anchor);
1665 usb_unanchor_urb(urb); 1666 usb_unanchor_urb(urb);
1666 1667
1667 /* pass ownership to the completion handler */ 1668 /* pass ownership to the completion handler */
@@ -1681,6 +1682,7 @@ static void __usb_hcd_giveback_urb(struct urb *urb)
1681 urb->complete(urb); 1682 urb->complete(urb);
1682 local_irq_restore(flags); 1683 local_irq_restore(flags);
1683 1684
1685 usb_anchor_resume_wakeups(anchor);
1684 atomic_dec(&urb->use_count); 1686 atomic_dec(&urb->use_count);
1685 if (unlikely(atomic_read(&urb->reject))) 1687 if (unlikely(atomic_read(&urb->reject)))
1686 wake_up(&usb_kill_urb_queue); 1688 wake_up(&usb_kill_urb_queue);
@@ -1703,7 +1705,9 @@ static void usb_giveback_urb_bh(unsigned long param)
1703 1705
1704 urb = list_entry(local_list.next, struct urb, urb_list); 1706 urb = list_entry(local_list.next, struct urb, urb_list);
1705 list_del_init(&urb->urb_list); 1707 list_del_init(&urb->urb_list);
1708 bh->completing_ep = urb->ep;
1706 __usb_hcd_giveback_urb(urb); 1709 __usb_hcd_giveback_urb(urb);
1710 bh->completing_ep = NULL;
1707 } 1711 }
1708 1712
1709 /* check if there are new URBs to giveback */ 1713 /* check if there are new URBs to giveback */
@@ -1812,7 +1816,7 @@ rescan:
1812 case USB_ENDPOINT_XFER_INT: 1816 case USB_ENDPOINT_XFER_INT:
1813 s = "-intr"; break; 1817 s = "-intr"; break;
1814 default: 1818 default:
1815 s = "-iso"; break; 1819 s = "-iso"; break;
1816 }; 1820 };
1817 s; 1821 s;
1818 })); 1822 }));
@@ -2073,8 +2077,11 @@ EXPORT_SYMBOL_GPL(usb_alloc_streams);
2073 * 2077 *
2074 * Reverts a group of bulk endpoints back to not using stream IDs. 2078 * Reverts a group of bulk endpoints back to not using stream IDs.
2075 * Can fail if we are given bad arguments, or HCD is broken. 2079 * Can fail if we are given bad arguments, or HCD is broken.
2080 *
2081 * Return: On success, the number of allocated streams. On failure, a negative
2082 * error code.
2076 */ 2083 */
2077void usb_free_streams(struct usb_interface *interface, 2084int usb_free_streams(struct usb_interface *interface,
2078 struct usb_host_endpoint **eps, unsigned int num_eps, 2085 struct usb_host_endpoint **eps, unsigned int num_eps,
2079 gfp_t mem_flags) 2086 gfp_t mem_flags)
2080{ 2087{
@@ -2085,14 +2092,14 @@ void usb_free_streams(struct usb_interface *interface,
2085 dev = interface_to_usbdev(interface); 2092 dev = interface_to_usbdev(interface);
2086 hcd = bus_to_hcd(dev->bus); 2093 hcd = bus_to_hcd(dev->bus);
2087 if (dev->speed != USB_SPEED_SUPER) 2094 if (dev->speed != USB_SPEED_SUPER)
2088 return; 2095 return -EINVAL;
2089 2096
2090 /* Streams only apply to bulk endpoints. */ 2097 /* Streams only apply to bulk endpoints. */
2091 for (i = 0; i < num_eps; i++) 2098 for (i = 0; i < num_eps; i++)
2092 if (!eps[i] || !usb_endpoint_xfer_bulk(&eps[i]->desc)) 2099 if (!eps[i] || !usb_endpoint_xfer_bulk(&eps[i]->desc))
2093 return; 2100 return -EINVAL;
2094 2101
2095 hcd->driver->free_streams(hcd, dev, eps, num_eps, mem_flags); 2102 return hcd->driver->free_streams(hcd, dev, eps, num_eps, mem_flags);
2096} 2103}
2097EXPORT_SYMBOL_GPL(usb_free_streams); 2104EXPORT_SYMBOL_GPL(usb_free_streams);
2098 2105
@@ -2245,7 +2252,7 @@ static void hcd_resume_work(struct work_struct *work)
2245} 2252}
2246 2253
2247/** 2254/**
2248 * usb_hcd_resume_root_hub - called by HCD to resume its root hub 2255 * usb_hcd_resume_root_hub - called by HCD to resume its root hub
2249 * @hcd: host controller for this root hub 2256 * @hcd: host controller for this root hub
2250 * 2257 *
2251 * The USB host controller calls this function when its root hub is 2258 * The USB host controller calls this function when its root hub is
@@ -2324,15 +2331,8 @@ EXPORT_SYMBOL_GPL(usb_bus_start_enum);
2324irqreturn_t usb_hcd_irq (int irq, void *__hcd) 2331irqreturn_t usb_hcd_irq (int irq, void *__hcd)
2325{ 2332{
2326 struct usb_hcd *hcd = __hcd; 2333 struct usb_hcd *hcd = __hcd;
2327 unsigned long flags;
2328 irqreturn_t rc; 2334 irqreturn_t rc;
2329 2335
2330 /* IRQF_DISABLED doesn't work correctly with shared IRQs
2331 * when the first handler doesn't use it. So let's just
2332 * assume it's never used.
2333 */
2334 local_irq_save(flags);
2335
2336 if (unlikely(HCD_DEAD(hcd) || !HCD_HW_ACCESSIBLE(hcd))) 2336 if (unlikely(HCD_DEAD(hcd) || !HCD_HW_ACCESSIBLE(hcd)))
2337 rc = IRQ_NONE; 2337 rc = IRQ_NONE;
2338 else if (hcd->driver->irq(hcd) == IRQ_NONE) 2338 else if (hcd->driver->irq(hcd) == IRQ_NONE)
@@ -2340,7 +2340,6 @@ irqreturn_t usb_hcd_irq (int irq, void *__hcd)
2340 else 2340 else
2341 rc = IRQ_HANDLED; 2341 rc = IRQ_HANDLED;
2342 2342
2343 local_irq_restore(flags);
2344 return rc; 2343 return rc;
2345} 2344}
2346EXPORT_SYMBOL_GPL(usb_hcd_irq); 2345EXPORT_SYMBOL_GPL(usb_hcd_irq);
@@ -2547,13 +2546,6 @@ static int usb_hcd_request_irqs(struct usb_hcd *hcd,
2547 2546
2548 if (hcd->driver->irq) { 2547 if (hcd->driver->irq) {
2549 2548
2550 /* IRQF_DISABLED doesn't work as advertised when used together
2551 * with IRQF_SHARED. As usb_hcd_irq() will always disable
2552 * interrupts we can remove it here.
2553 */
2554 if (irqflags & IRQF_SHARED)
2555 irqflags &= ~IRQF_DISABLED;
2556
2557 snprintf(hcd->irq_descr, sizeof(hcd->irq_descr), "%s:usb%d", 2549 snprintf(hcd->irq_descr, sizeof(hcd->irq_descr), "%s:usb%d",
2558 hcd->driver->description, hcd->self.busnum); 2550 hcd->driver->description, hcd->self.busnum);
2559 retval = request_irq(irqnum, &usb_hcd_irq, irqflags, 2551 retval = request_irq(irqnum, &usb_hcd_irq, irqflags,
@@ -2600,7 +2592,7 @@ int usb_add_hcd(struct usb_hcd *hcd,
2600 2592
2601 /* Keep old behaviour if authorized_default is not in [0, 1]. */ 2593 /* Keep old behaviour if authorized_default is not in [0, 1]. */
2602 if (authorized_default < 0 || authorized_default > 1) 2594 if (authorized_default < 0 || authorized_default > 1)
2603 hcd->authorized_default = hcd->wireless? 0 : 1; 2595 hcd->authorized_default = hcd->wireless ? 0 : 1;
2604 else 2596 else
2605 hcd->authorized_default = authorized_default; 2597 hcd->authorized_default = authorized_default;
2606 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); 2598 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
@@ -2743,7 +2735,7 @@ err_allocate_root_hub:
2743err_register_bus: 2735err_register_bus:
2744 hcd_buffer_destroy(hcd); 2736 hcd_buffer_destroy(hcd);
2745 return retval; 2737 return retval;
2746} 2738}
2747EXPORT_SYMBOL_GPL(usb_add_hcd); 2739EXPORT_SYMBOL_GPL(usb_add_hcd);
2748 2740
2749/** 2741/**
@@ -2818,7 +2810,7 @@ void usb_remove_hcd(struct usb_hcd *hcd)
2818EXPORT_SYMBOL_GPL(usb_remove_hcd); 2810EXPORT_SYMBOL_GPL(usb_remove_hcd);
2819 2811
2820void 2812void
2821usb_hcd_platform_shutdown(struct platform_device* dev) 2813usb_hcd_platform_shutdown(struct platform_device *dev)
2822{ 2814{
2823 struct usb_hcd *hcd = platform_get_drvdata(dev); 2815 struct usb_hcd *hcd = platform_get_drvdata(dev);
2824 2816
@@ -2840,7 +2832,7 @@ struct usb_mon_operations *mon_ops;
2840 * Notice that the code is minimally error-proof. Because usbmon needs 2832 * Notice that the code is minimally error-proof. Because usbmon needs
2841 * symbols from usbcore, usbcore gets referenced and cannot be unloaded first. 2833 * symbols from usbcore, usbcore gets referenced and cannot be unloaded first.
2842 */ 2834 */
2843 2835
2844int usb_mon_register (struct usb_mon_operations *ops) 2836int usb_mon_register (struct usb_mon_operations *ops)
2845{ 2837{
2846 2838
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index e6b682c6c236..06cec635e703 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -120,7 +120,7 @@ static inline char *portspeed(struct usb_hub *hub, int portstatus)
120 if (hub_is_superspeed(hub->hdev)) 120 if (hub_is_superspeed(hub->hdev))
121 return "5.0 Gb/s"; 121 return "5.0 Gb/s";
122 if (portstatus & USB_PORT_STAT_HIGH_SPEED) 122 if (portstatus & USB_PORT_STAT_HIGH_SPEED)
123 return "480 Mb/s"; 123 return "480 Mb/s";
124 else if (portstatus & USB_PORT_STAT_LOW_SPEED) 124 else if (portstatus & USB_PORT_STAT_LOW_SPEED)
125 return "1.5 Mb/s"; 125 return "1.5 Mb/s";
126 else 126 else
@@ -135,7 +135,7 @@ struct usb_hub *usb_hub_to_struct_hub(struct usb_device *hdev)
135 return usb_get_intfdata(hdev->actconfig->interface[0]); 135 return usb_get_intfdata(hdev->actconfig->interface[0]);
136} 136}
137 137
138static int usb_device_supports_lpm(struct usb_device *udev) 138int usb_device_supports_lpm(struct usb_device *udev)
139{ 139{
140 /* USB 2.1 (and greater) devices indicate LPM support through 140 /* USB 2.1 (and greater) devices indicate LPM support through
141 * their USB 2.0 Extended Capabilities BOS descriptor. 141 * their USB 2.0 Extended Capabilities BOS descriptor.
@@ -156,6 +156,11 @@ static int usb_device_supports_lpm(struct usb_device *udev)
156 "Power management will be impacted.\n"); 156 "Power management will be impacted.\n");
157 return 0; 157 return 0;
158 } 158 }
159
160 /* udev is root hub */
161 if (!udev->parent)
162 return 1;
163
159 if (udev->parent->lpm_capable) 164 if (udev->parent->lpm_capable)
160 return 1; 165 return 1;
161 166
@@ -310,9 +315,9 @@ static void usb_set_lpm_parameters(struct usb_device *udev)
310 return; 315 return;
311 316
312 udev_u1_del = udev->bos->ss_cap->bU1devExitLat; 317 udev_u1_del = udev->bos->ss_cap->bU1devExitLat;
313 udev_u2_del = udev->bos->ss_cap->bU2DevExitLat; 318 udev_u2_del = le16_to_cpu(udev->bos->ss_cap->bU2DevExitLat);
314 hub_u1_del = udev->parent->bos->ss_cap->bU1devExitLat; 319 hub_u1_del = udev->parent->bos->ss_cap->bU1devExitLat;
315 hub_u2_del = udev->parent->bos->ss_cap->bU2DevExitLat; 320 hub_u2_del = le16_to_cpu(udev->parent->bos->ss_cap->bU2DevExitLat);
316 321
317 usb_set_lpm_mel(udev, &udev->u1_params, udev_u1_del, 322 usb_set_lpm_mel(udev, &udev->u1_params, udev_u1_del,
318 hub, &udev->parent->u1_params, hub_u1_del); 323 hub, &udev->parent->u1_params, hub_u1_del);
@@ -433,7 +438,7 @@ static void set_port_led(
433 case HUB_LED_OFF: s = "off"; break; 438 case HUB_LED_OFF: s = "off"; break;
434 case HUB_LED_AUTO: s = "auto"; break; 439 case HUB_LED_AUTO: s = "auto"; break;
435 default: s = "??"; break; 440 default: s = "??"; break;
436 }; s; }), 441 } s; }),
437 status); 442 status);
438} 443}
439 444
@@ -857,7 +862,7 @@ static int hub_hub_status(struct usb_hub *hub,
857 "%s failed (err = %d)\n", __func__, ret); 862 "%s failed (err = %d)\n", __func__, ret);
858 } else { 863 } else {
859 *status = le16_to_cpu(hub->status->hub.wHubStatus); 864 *status = le16_to_cpu(hub->status->hub.wHubStatus);
860 *change = le16_to_cpu(hub->status->hub.wHubChange); 865 *change = le16_to_cpu(hub->status->hub.wHubChange);
861 ret = 0; 866 ret = 0;
862 } 867 }
863 mutex_unlock(&hub->status_mutex); 868 mutex_unlock(&hub->status_mutex);
@@ -956,7 +961,7 @@ static void hub_port_logical_disconnect(struct usb_hub *hub, int port1)
956 */ 961 */
957 962
958 set_bit(port1, hub->change_bits); 963 set_bit(port1, hub->change_bits);
959 kick_khubd(hub); 964 kick_khubd(hub);
960} 965}
961 966
962/** 967/**
@@ -1107,16 +1112,13 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type)
1107 /* 1112 /*
1108 * USB3 protocol ports will automatically transition 1113 * USB3 protocol ports will automatically transition
1109 * to Enabled state when detect an USB3.0 device attach. 1114 * to Enabled state when detect an USB3.0 device attach.
1110 * Do not disable USB3 protocol ports. 1115 * Do not disable USB3 protocol ports, just pretend
1116 * power was lost
1111 */ 1117 */
1112 if (!hub_is_superspeed(hdev)) { 1118 portstatus &= ~USB_PORT_STAT_ENABLE;
1119 if (!hub_is_superspeed(hdev))
1113 usb_clear_port_feature(hdev, port1, 1120 usb_clear_port_feature(hdev, port1,
1114 USB_PORT_FEAT_ENABLE); 1121 USB_PORT_FEAT_ENABLE);
1115 portstatus &= ~USB_PORT_STAT_ENABLE;
1116 } else {
1117 /* Pretend that power was lost for USB3 devs */
1118 portstatus &= ~USB_PORT_STAT_ENABLE;
1119 }
1120 } 1122 }
1121 1123
1122 /* Clear status-change flags; we'll debounce later */ 1124 /* Clear status-change flags; we'll debounce later */
@@ -1130,6 +1132,11 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type)
1130 usb_clear_port_feature(hub->hdev, port1, 1132 usb_clear_port_feature(hub->hdev, port1,
1131 USB_PORT_FEAT_C_ENABLE); 1133 USB_PORT_FEAT_C_ENABLE);
1132 } 1134 }
1135 if (portchange & USB_PORT_STAT_C_RESET) {
1136 need_debounce_delay = true;
1137 usb_clear_port_feature(hub->hdev, port1,
1138 USB_PORT_FEAT_C_RESET);
1139 }
1133 if ((portchange & USB_PORT_STAT_C_BH_RESET) && 1140 if ((portchange & USB_PORT_STAT_C_BH_RESET) &&
1134 hub_is_superspeed(hub->hdev)) { 1141 hub_is_superspeed(hub->hdev)) {
1135 need_debounce_delay = true; 1142 need_debounce_delay = true;
@@ -1361,7 +1368,7 @@ static int hub_configure(struct usb_hub *hub,
1361 if ((wHubCharacteristics & HUB_CHAR_COMPOUND) && 1368 if ((wHubCharacteristics & HUB_CHAR_COMPOUND) &&
1362 !(hub_is_superspeed(hdev))) { 1369 !(hub_is_superspeed(hdev))) {
1363 int i; 1370 int i;
1364 char portstr [USB_MAXCHILDREN + 1]; 1371 char portstr[USB_MAXCHILDREN + 1];
1365 1372
1366 for (i = 0; i < hdev->maxchild; i++) 1373 for (i = 0; i < hdev->maxchild; i++)
1367 portstr[i] = hub->descriptor->u.hs.DeviceRemovable 1374 portstr[i] = hub->descriptor->u.hs.DeviceRemovable
@@ -1429,32 +1436,32 @@ static int hub_configure(struct usb_hub *hub,
1429 1436
1430 /* Note 8 FS bit times == (8 bits / 12000000 bps) ~= 666ns */ 1437 /* Note 8 FS bit times == (8 bits / 12000000 bps) ~= 666ns */
1431 switch (wHubCharacteristics & HUB_CHAR_TTTT) { 1438 switch (wHubCharacteristics & HUB_CHAR_TTTT) {
1432 case HUB_TTTT_8_BITS: 1439 case HUB_TTTT_8_BITS:
1433 if (hdev->descriptor.bDeviceProtocol != 0) { 1440 if (hdev->descriptor.bDeviceProtocol != 0) {
1434 hub->tt.think_time = 666; 1441 hub->tt.think_time = 666;
1435 dev_dbg(hub_dev, "TT requires at most %d "
1436 "FS bit times (%d ns)\n",
1437 8, hub->tt.think_time);
1438 }
1439 break;
1440 case HUB_TTTT_16_BITS:
1441 hub->tt.think_time = 666 * 2;
1442 dev_dbg(hub_dev, "TT requires at most %d "
1443 "FS bit times (%d ns)\n",
1444 16, hub->tt.think_time);
1445 break;
1446 case HUB_TTTT_24_BITS:
1447 hub->tt.think_time = 666 * 3;
1448 dev_dbg(hub_dev, "TT requires at most %d " 1442 dev_dbg(hub_dev, "TT requires at most %d "
1449 "FS bit times (%d ns)\n", 1443 "FS bit times (%d ns)\n",
1450 24, hub->tt.think_time); 1444 8, hub->tt.think_time);
1451 break; 1445 }
1452 case HUB_TTTT_32_BITS: 1446 break;
1453 hub->tt.think_time = 666 * 4; 1447 case HUB_TTTT_16_BITS:
1454 dev_dbg(hub_dev, "TT requires at most %d " 1448 hub->tt.think_time = 666 * 2;
1455 "FS bit times (%d ns)\n", 1449 dev_dbg(hub_dev, "TT requires at most %d "
1456 32, hub->tt.think_time); 1450 "FS bit times (%d ns)\n",
1457 break; 1451 16, hub->tt.think_time);
1452 break;
1453 case HUB_TTTT_24_BITS:
1454 hub->tt.think_time = 666 * 3;
1455 dev_dbg(hub_dev, "TT requires at most %d "
1456 "FS bit times (%d ns)\n",
1457 24, hub->tt.think_time);
1458 break;
1459 case HUB_TTTT_32_BITS:
1460 hub->tt.think_time = 666 * 4;
1461 dev_dbg(hub_dev, "TT requires at most %d "
1462 "FS bit times (%d ns)\n",
1463 32, hub->tt.think_time);
1464 break;
1458 } 1465 }
1459 1466
1460 /* probe() zeroes hub->indicator[] */ 1467 /* probe() zeroes hub->indicator[] */
@@ -1560,7 +1567,7 @@ static int hub_configure(struct usb_hub *hub,
1560 1567
1561 /* maybe cycle the hub leds */ 1568 /* maybe cycle the hub leds */
1562 if (hub->has_indicators && blinkenlights) 1569 if (hub->has_indicators && blinkenlights)
1563 hub->indicator [0] = INDICATOR_CYCLE; 1570 hub->indicator[0] = INDICATOR_CYCLE;
1564 1571
1565 for (i = 0; i < hdev->maxchild; i++) { 1572 for (i = 0; i < hdev->maxchild; i++) {
1566 ret = usb_hub_create_port_device(hub, i + 1); 1573 ret = usb_hub_create_port_device(hub, i + 1);
@@ -1978,7 +1985,7 @@ static void choose_devnum(struct usb_device *udev)
1978 if (devnum >= 128) 1985 if (devnum >= 128)
1979 devnum = find_next_zero_bit(bus->devmap.devicemap, 1986 devnum = find_next_zero_bit(bus->devmap.devicemap,
1980 128, 1); 1987 128, 1);
1981 bus->devnum_next = ( devnum >= 127 ? 1 : devnum + 1); 1988 bus->devnum_next = (devnum >= 127 ? 1 : devnum + 1);
1982 } 1989 }
1983 if (devnum < 128) { 1990 if (devnum < 128) {
1984 set_bit(devnum, bus->devmap.devicemap); 1991 set_bit(devnum, bus->devmap.devicemap);
@@ -2018,8 +2025,8 @@ static void hub_free_dev(struct usb_device *udev)
2018 * Something got disconnected. Get rid of it and all of its children. 2025 * Something got disconnected. Get rid of it and all of its children.
2019 * 2026 *
2020 * If *pdev is a normal device then the parent hub must already be locked. 2027 * If *pdev is a normal device then the parent hub must already be locked.
2021 * If *pdev is a root hub then this routine will acquire the 2028 * If *pdev is a root hub then the caller must hold the usb_bus_list_lock,
2022 * usb_bus_list_lock on behalf of the caller. 2029 * which protects the set of root hubs as well as the list of buses.
2023 * 2030 *
2024 * Only hub drivers (including virtual root hub drivers for host 2031 * Only hub drivers (including virtual root hub drivers for host
2025 * controllers) should ever call this. 2032 * controllers) should ever call this.
@@ -2232,8 +2239,7 @@ static int usb_enumerate_device(struct usb_device *udev)
2232 udev->product = kstrdup("n/a (unauthorized)", GFP_KERNEL); 2239 udev->product = kstrdup("n/a (unauthorized)", GFP_KERNEL);
2233 udev->manufacturer = kstrdup("n/a (unauthorized)", GFP_KERNEL); 2240 udev->manufacturer = kstrdup("n/a (unauthorized)", GFP_KERNEL);
2234 udev->serial = kstrdup("n/a (unauthorized)", GFP_KERNEL); 2241 udev->serial = kstrdup("n/a (unauthorized)", GFP_KERNEL);
2235 } 2242 } else {
2236 else {
2237 /* read the standard strings and cache them if present */ 2243 /* read the standard strings and cache them if present */
2238 udev->product = usb_cache_string(udev, udev->descriptor.iProduct); 2244 udev->product = usb_cache_string(udev, udev->descriptor.iProduct);
2239 udev->manufacturer = usb_cache_string(udev, 2245 udev->manufacturer = usb_cache_string(udev,
@@ -2489,7 +2495,7 @@ error_device_descriptor:
2489 usb_autosuspend_device(usb_dev); 2495 usb_autosuspend_device(usb_dev);
2490error_autoresume: 2496error_autoresume:
2491out_authorized: 2497out_authorized:
2492 usb_unlock_device(usb_dev); // complements locktree 2498 usb_unlock_device(usb_dev); /* complements locktree */
2493 return result; 2499 return result;
2494} 2500}
2495 2501
@@ -3108,8 +3114,8 @@ static int finish_port_resume(struct usb_device *udev)
3108 retry_reset_resume: 3114 retry_reset_resume:
3109 status = usb_reset_and_verify_device(udev); 3115 status = usb_reset_and_verify_device(udev);
3110 3116
3111 /* 10.5.4.5 says be sure devices in the tree are still there. 3117 /* 10.5.4.5 says be sure devices in the tree are still there.
3112 * For now let's assume the device didn't go crazy on resume, 3118 * For now let's assume the device didn't go crazy on resume,
3113 * and device drivers will know about any resume quirks. 3119 * and device drivers will know about any resume quirks.
3114 */ 3120 */
3115 if (status == 0) { 3121 if (status == 0) {
@@ -3211,7 +3217,7 @@ int usb_port_resume(struct usb_device *udev, pm_message_t msg)
3211 if (status == 0 && !port_is_suspended(hub, portstatus)) 3217 if (status == 0 && !port_is_suspended(hub, portstatus))
3212 goto SuspendCleared; 3218 goto SuspendCleared;
3213 3219
3214 // dev_dbg(hub->intfdev, "resume port %d\n", port1); 3220 /* dev_dbg(hub->intfdev, "resume port %d\n", port1); */
3215 3221
3216 set_bit(port1, hub->busy_bits); 3222 set_bit(port1, hub->busy_bits);
3217 3223
@@ -3855,7 +3861,7 @@ EXPORT_SYMBOL_GPL(usb_enable_ltm);
3855 * Between connect detection and reset signaling there must be a delay 3861 * Between connect detection and reset signaling there must be a delay
3856 * of 100ms at least for debounce and power-settling. The corresponding 3862 * of 100ms at least for debounce and power-settling. The corresponding
3857 * timer shall restart whenever the downstream port detects a disconnect. 3863 * timer shall restart whenever the downstream port detects a disconnect.
3858 * 3864 *
3859 * Apparently there are some bluetooth and irda-dongles and a number of 3865 * Apparently there are some bluetooth and irda-dongles and a number of
3860 * low-speed devices for which this debounce period may last over a second. 3866 * low-speed devices for which this debounce period may last over a second.
3861 * Not covered by the spec - but easy to deal with. 3867 * Not covered by the spec - but easy to deal with.
@@ -3949,6 +3955,32 @@ static int hub_set_address(struct usb_device *udev, int devnum)
3949 return retval; 3955 return retval;
3950} 3956}
3951 3957
3958/*
3959 * There are reports of USB 3.0 devices that say they support USB 2.0 Link PM
3960 * when they're plugged into a USB 2.0 port, but they don't work when LPM is
3961 * enabled.
3962 *
3963 * Only enable USB 2.0 Link PM if the port is internal (hardwired), or the
3964 * device says it supports the new USB 2.0 Link PM errata by setting the BESL
3965 * support bit in the BOS descriptor.
3966 */
3967static void hub_set_initial_usb2_lpm_policy(struct usb_device *udev)
3968{
3969 int connect_type;
3970
3971 if (!udev->usb2_hw_lpm_capable)
3972 return;
3973
3974 connect_type = usb_get_hub_port_connect_type(udev->parent,
3975 udev->portnum);
3976
3977 if ((udev->bos->ext_cap->bmAttributes & USB_BESL_SUPPORT) ||
3978 connect_type == USB_PORT_CONNECT_TYPE_HARD_WIRED) {
3979 udev->usb2_hw_lpm_allowed = 1;
3980 usb_set_usb2_hardware_lpm(udev, 1);
3981 }
3982}
3983
3952/* Reset device, (re)assign address, get device descriptor. 3984/* Reset device, (re)assign address, get device descriptor.
3953 * Device connection must be stable, no more debouncing needed. 3985 * Device connection must be stable, no more debouncing needed.
3954 * Returns device in USB_STATE_ADDRESS, except on error. 3986 * Returns device in USB_STATE_ADDRESS, except on error.
@@ -4055,7 +4087,7 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
4055 udev->tt = &hub->tt; 4087 udev->tt = &hub->tt;
4056 udev->ttport = port1; 4088 udev->ttport = port1;
4057 } 4089 }
4058 4090
4059 /* Why interleave GET_DESCRIPTOR and SET_ADDRESS this way? 4091 /* Why interleave GET_DESCRIPTOR and SET_ADDRESS this way?
4060 * Because device hardware and firmware is sometimes buggy in 4092 * Because device hardware and firmware is sometimes buggy in
4061 * this area, and this is how Linux has done it for ages. 4093 * this area, and this is how Linux has done it for ages.
@@ -4130,11 +4162,11 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
4130#undef GET_DESCRIPTOR_BUFSIZE 4162#undef GET_DESCRIPTOR_BUFSIZE
4131 } 4163 }
4132 4164
4133 /* 4165 /*
4134 * If device is WUSB, we already assigned an 4166 * If device is WUSB, we already assigned an
4135 * unauthorized address in the Connect Ack sequence; 4167 * unauthorized address in the Connect Ack sequence;
4136 * authorization will assign the final address. 4168 * authorization will assign the final address.
4137 */ 4169 */
4138 if (udev->wusb == 0) { 4170 if (udev->wusb == 0) {
4139 for (j = 0; j < SET_ADDRESS_TRIES; ++j) { 4171 for (j = 0; j < SET_ADDRESS_TRIES; ++j) {
4140 retval = hub_set_address(udev, devnum); 4172 retval = hub_set_address(udev, devnum);
@@ -4163,7 +4195,7 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
4163 msleep(10); 4195 msleep(10);
4164 if (USE_NEW_SCHEME(retry_counter) && !(hcd->driver->flags & HCD_USB3)) 4196 if (USE_NEW_SCHEME(retry_counter) && !(hcd->driver->flags & HCD_USB3))
4165 break; 4197 break;
4166 } 4198 }
4167 4199
4168 retval = usb_get_device_descriptor(udev, 8); 4200 retval = usb_get_device_descriptor(udev, 8);
4169 if (retval < 8) { 4201 if (retval < 8) {
@@ -4219,7 +4251,7 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
4219 udev->ep0.desc.wMaxPacketSize = cpu_to_le16(i); 4251 udev->ep0.desc.wMaxPacketSize = cpu_to_le16(i);
4220 usb_ep0_reinit(udev); 4252 usb_ep0_reinit(udev);
4221 } 4253 }
4222 4254
4223 retval = usb_get_device_descriptor(udev, USB_DT_DEVICE_SIZE); 4255 retval = usb_get_device_descriptor(udev, USB_DT_DEVICE_SIZE);
4224 if (retval < (signed)sizeof(udev->descriptor)) { 4256 if (retval < (signed)sizeof(udev->descriptor)) {
4225 if (retval != -ENODEV) 4257 if (retval != -ENODEV)
@@ -4242,6 +4274,7 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
4242 /* notify HCD that we have a device connected and addressed */ 4274 /* notify HCD that we have a device connected and addressed */
4243 if (hcd->driver->update_device) 4275 if (hcd->driver->update_device)
4244 hcd->driver->update_device(hcd, udev); 4276 hcd->driver->update_device(hcd, udev);
4277 hub_set_initial_usb2_lpm_policy(udev);
4245fail: 4278fail:
4246 if (retval) { 4279 if (retval) {
4247 hub_port_disable(hub, port1, 0); 4280 hub_port_disable(hub, port1, 0);
@@ -4316,7 +4349,7 @@ hub_power_remaining (struct usb_hub *hub)
4316 } 4349 }
4317 if (remaining < 0) { 4350 if (remaining < 0) {
4318 dev_warn(hub->intfdev, "%dmA over power budget!\n", 4351 dev_warn(hub->intfdev, "%dmA over power budget!\n",
4319 - remaining); 4352 -remaining);
4320 remaining = 0; 4353 remaining = 0;
4321 } 4354 }
4322 return remaining; 4355 return remaining;
@@ -4427,7 +4460,7 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
4427 set_port_feature(hdev, port1, USB_PORT_FEAT_POWER); 4460 set_port_feature(hdev, port1, USB_PORT_FEAT_POWER);
4428 4461
4429 if (portstatus & USB_PORT_STAT_ENABLE) 4462 if (portstatus & USB_PORT_STAT_ENABLE)
4430 goto done; 4463 goto done;
4431 return; 4464 return;
4432 } 4465 }
4433 if (hub_is_superspeed(hub->hdev)) 4466 if (hub_is_superspeed(hub->hdev))
@@ -4450,7 +4483,7 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
4450 } 4483 }
4451 4484
4452 usb_set_device_state(udev, USB_STATE_POWERED); 4485 usb_set_device_state(udev, USB_STATE_POWERED);
4453 udev->bus_mA = hub->mA_per_port; 4486 udev->bus_mA = hub->mA_per_port;
4454 udev->level = hdev->level + 1; 4487 udev->level = hdev->level + 1;
4455 udev->wusb = hub_is_wusb(hub); 4488 udev->wusb = hub_is_wusb(hub);
4456 4489
@@ -4504,7 +4537,7 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
4504 goto loop_disable; 4537 goto loop_disable;
4505 } 4538 }
4506 } 4539 }
4507 4540
4508 /* check for devices running slower than they could */ 4541 /* check for devices running slower than they could */
4509 if (le16_to_cpu(udev->descriptor.bcdUSB) >= 0x0200 4542 if (le16_to_cpu(udev->descriptor.bcdUSB) >= 0x0200
4510 && udev->speed == USB_SPEED_FULL 4543 && udev->speed == USB_SPEED_FULL
@@ -4564,7 +4597,7 @@ loop:
4564 dev_err(hub_dev, "unable to enumerate USB device on port %d\n", 4597 dev_err(hub_dev, "unable to enumerate USB device on port %d\n",
4565 port1); 4598 port1);
4566 } 4599 }
4567 4600
4568done: 4601done:
4569 hub_port_disable(hub, port1, 1); 4602 hub_port_disable(hub, port1, 1);
4570 if (hcd->driver->relinquish_port && !hub->hdev->parent) 4603 if (hcd->driver->relinquish_port && !hub->hdev->parent)
@@ -4729,7 +4762,7 @@ static void hub_events(void)
4729 * EM interference sometimes causes badly 4762 * EM interference sometimes causes badly
4730 * shielded USB devices to be shutdown by 4763 * shielded USB devices to be shutdown by
4731 * the hub, this hack enables them again. 4764 * the hub, this hack enables them again.
4732 * Works at least with mouse driver. 4765 * Works at least with mouse driver.
4733 */ 4766 */
4734 if (!(portstatus & USB_PORT_STAT_ENABLE) 4767 if (!(portstatus & USB_PORT_STAT_ENABLE)
4735 && !connect_change 4768 && !connect_change
@@ -4841,7 +4874,7 @@ static void hub_events(void)
4841 dev_dbg(hub_dev, "over-current change\n"); 4874 dev_dbg(hub_dev, "over-current change\n");
4842 clear_hub_feature(hdev, C_HUB_OVER_CURRENT); 4875 clear_hub_feature(hdev, C_HUB_OVER_CURRENT);
4843 msleep(500); /* Cool down */ 4876 msleep(500); /* Cool down */
4844 hub_power_on(hub, true); 4877 hub_power_on(hub, true);
4845 hub_hub_status(hub, &status, &unused); 4878 hub_hub_status(hub, &status, &unused);
4846 if (status & HUB_STATUS_OVERCURRENT) 4879 if (status & HUB_STATUS_OVERCURRENT)
4847 dev_err(hub_dev, "over-current " 4880 dev_err(hub_dev, "over-current "
@@ -4861,7 +4894,7 @@ static void hub_events(void)
4861 usb_unlock_device(hdev); 4894 usb_unlock_device(hdev);
4862 kref_put(&hub->kref, hub_release); 4895 kref_put(&hub->kref, hub_release);
4863 4896
4864 } /* end while (1) */ 4897 } /* end while (1) */
4865} 4898}
4866 4899
4867static int hub_thread(void *__unused) 4900static int hub_thread(void *__unused)
@@ -4886,7 +4919,7 @@ static int hub_thread(void *__unused)
4886 4919
4887static const struct usb_device_id hub_id_table[] = { 4920static const struct usb_device_id hub_id_table[] = {
4888 { .match_flags = USB_DEVICE_ID_MATCH_VENDOR 4921 { .match_flags = USB_DEVICE_ID_MATCH_VENDOR
4889 | USB_DEVICE_ID_MATCH_INT_CLASS, 4922 | USB_DEVICE_ID_MATCH_INT_CLASS,
4890 .idVendor = USB_VENDOR_GENESYS_LOGIC, 4923 .idVendor = USB_VENDOR_GENESYS_LOGIC,
4891 .bInterfaceClass = USB_CLASS_HUB, 4924 .bInterfaceClass = USB_CLASS_HUB,
4892 .driver_info = HUB_QUIRK_CHECK_PORT_AUTOSUSPEND}, 4925 .driver_info = HUB_QUIRK_CHECK_PORT_AUTOSUSPEND},
@@ -5086,6 +5119,12 @@ static int usb_reset_and_verify_device(struct usb_device *udev)
5086 } 5119 }
5087 parent_hub = usb_hub_to_struct_hub(parent_hdev); 5120 parent_hub = usb_hub_to_struct_hub(parent_hdev);
5088 5121
5122 /* Disable USB2 hardware LPM.
5123 * It will be re-enabled by the enumeration process.
5124 */
5125 if (udev->usb2_hw_lpm_enabled == 1)
5126 usb_set_usb2_hardware_lpm(udev, 0);
5127
5089 bos = udev->bos; 5128 bos = udev->bos;
5090 udev->bos = NULL; 5129 udev->bos = NULL;
5091 5130
@@ -5120,13 +5159,13 @@ static int usb_reset_and_verify_device(struct usb_device *udev)
5120 5159
5121 if (ret < 0) 5160 if (ret < 0)
5122 goto re_enumerate; 5161 goto re_enumerate;
5123 5162
5124 /* Device might have changed firmware (DFU or similar) */ 5163 /* Device might have changed firmware (DFU or similar) */
5125 if (descriptors_changed(udev, &descriptor, bos)) { 5164 if (descriptors_changed(udev, &descriptor, bos)) {
5126 dev_info(&udev->dev, "device firmware changed\n"); 5165 dev_info(&udev->dev, "device firmware changed\n");
5127 udev->descriptor = descriptor; /* for disconnect() calls */ 5166 udev->descriptor = descriptor; /* for disconnect() calls */
5128 goto re_enumerate; 5167 goto re_enumerate;
5129 } 5168 }
5130 5169
5131 /* Restore the device's previous configuration */ 5170 /* Restore the device's previous configuration */
5132 if (!udev->actconfig) 5171 if (!udev->actconfig)
@@ -5151,7 +5190,7 @@ static int usb_reset_and_verify_device(struct usb_device *udev)
5151 udev->actconfig->desc.bConfigurationValue, ret); 5190 udev->actconfig->desc.bConfigurationValue, ret);
5152 mutex_unlock(hcd->bandwidth_mutex); 5191 mutex_unlock(hcd->bandwidth_mutex);
5153 goto re_enumerate; 5192 goto re_enumerate;
5154 } 5193 }
5155 mutex_unlock(hcd->bandwidth_mutex); 5194 mutex_unlock(hcd->bandwidth_mutex);
5156 usb_set_device_state(udev, USB_STATE_CONFIGURED); 5195 usb_set_device_state(udev, USB_STATE_CONFIGURED);
5157 5196
@@ -5193,12 +5232,13 @@ static int usb_reset_and_verify_device(struct usb_device *udev)
5193 5232
5194done: 5233done:
5195 /* Now that the alt settings are re-installed, enable LTM and LPM. */ 5234 /* Now that the alt settings are re-installed, enable LTM and LPM. */
5235 usb_set_usb2_hardware_lpm(udev, 1);
5196 usb_unlocked_enable_lpm(udev); 5236 usb_unlocked_enable_lpm(udev);
5197 usb_enable_ltm(udev); 5237 usb_enable_ltm(udev);
5198 usb_release_bos_descriptor(udev); 5238 usb_release_bos_descriptor(udev);
5199 udev->bos = bos; 5239 udev->bos = bos;
5200 return 0; 5240 return 0;
5201 5241
5202re_enumerate: 5242re_enumerate:
5203 /* LPM state doesn't matter when we're about to destroy the device. */ 5243 /* LPM state doesn't matter when we're about to destroy the device. */
5204 hub_port_logical_disconnect(parent_hub, port1); 5244 hub_port_logical_disconnect(parent_hub, port1);
diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
index 82927e1ed27d..bb315970e475 100644
--- a/drivers/usb/core/message.c
+++ b/drivers/usb/core/message.c
@@ -1182,8 +1182,12 @@ void usb_disable_device(struct usb_device *dev, int skip_ep0)
1182 put_device(&dev->actconfig->interface[i]->dev); 1182 put_device(&dev->actconfig->interface[i]->dev);
1183 dev->actconfig->interface[i] = NULL; 1183 dev->actconfig->interface[i] = NULL;
1184 } 1184 }
1185
1186 if (dev->usb2_hw_lpm_enabled == 1)
1187 usb_set_usb2_hardware_lpm(dev, 0);
1185 usb_unlocked_disable_lpm(dev); 1188 usb_unlocked_disable_lpm(dev);
1186 usb_disable_ltm(dev); 1189 usb_disable_ltm(dev);
1190
1187 dev->actconfig = NULL; 1191 dev->actconfig = NULL;
1188 if (dev->state == USB_STATE_CONFIGURED) 1192 if (dev->state == USB_STATE_CONFIGURED)
1189 usb_set_device_state(dev, USB_STATE_ADDRESS); 1193 usb_set_device_state(dev, USB_STATE_ADDRESS);
diff --git a/drivers/usb/core/quirks.c b/drivers/usb/core/quirks.c
index 01fe36273f3b..12924dbfdc2c 100644
--- a/drivers/usb/core/quirks.c
+++ b/drivers/usb/core/quirks.c
@@ -13,6 +13,7 @@
13 13
14#include <linux/usb.h> 14#include <linux/usb.h>
15#include <linux/usb/quirks.h> 15#include <linux/usb/quirks.h>
16#include <linux/usb/hcd.h>
16#include "usb.h" 17#include "usb.h"
17 18
18/* Lists of quirky USB devices, split in device quirks and interface quirks. 19/* Lists of quirky USB devices, split in device quirks and interface quirks.
@@ -161,6 +162,21 @@ static const struct usb_device_id usb_interface_quirk_list[] = {
161 { } /* terminating entry must be last */ 162 { } /* terminating entry must be last */
162}; 163};
163 164
165static const struct usb_device_id usb_amd_resume_quirk_list[] = {
166 /* Lenovo Mouse with Pixart controller */
167 { USB_DEVICE(0x17ef, 0x602e), .driver_info = USB_QUIRK_RESET_RESUME },
168
169 /* Pixart Mouse */
170 { USB_DEVICE(0x093a, 0x2500), .driver_info = USB_QUIRK_RESET_RESUME },
171 { USB_DEVICE(0x093a, 0x2510), .driver_info = USB_QUIRK_RESET_RESUME },
172 { USB_DEVICE(0x093a, 0x2521), .driver_info = USB_QUIRK_RESET_RESUME },
173
174 /* Logitech Optical Mouse M90/M100 */
175 { USB_DEVICE(0x046d, 0xc05a), .driver_info = USB_QUIRK_RESET_RESUME },
176
177 { } /* terminating entry must be last */
178};
179
164static bool usb_match_any_interface(struct usb_device *udev, 180static bool usb_match_any_interface(struct usb_device *udev,
165 const struct usb_device_id *id) 181 const struct usb_device_id *id)
166{ 182{
@@ -187,6 +203,18 @@ static bool usb_match_any_interface(struct usb_device *udev,
187 return false; 203 return false;
188} 204}
189 205
206static int usb_amd_resume_quirk(struct usb_device *udev)
207{
208 struct usb_hcd *hcd;
209
210 hcd = bus_to_hcd(udev->bus);
211 /* The device should be attached directly to root hub */
212 if (udev->level == 1 && hcd->amd_resume_bug == 1)
213 return 1;
214
215 return 0;
216}
217
190static u32 __usb_detect_quirks(struct usb_device *udev, 218static u32 __usb_detect_quirks(struct usb_device *udev,
191 const struct usb_device_id *id) 219 const struct usb_device_id *id)
192{ 220{
@@ -212,6 +240,15 @@ static u32 __usb_detect_quirks(struct usb_device *udev,
212void usb_detect_quirks(struct usb_device *udev) 240void usb_detect_quirks(struct usb_device *udev)
213{ 241{
214 udev->quirks = __usb_detect_quirks(udev, usb_quirk_list); 242 udev->quirks = __usb_detect_quirks(udev, usb_quirk_list);
243
244 /*
245 * Pixart-based mice would trigger remote wakeup issue on AMD
246 * Yangtze chipset, so set them as RESET_RESUME flag.
247 */
248 if (usb_amd_resume_quirk(udev))
249 udev->quirks |= __usb_detect_quirks(udev,
250 usb_amd_resume_quirk_list);
251
215 if (udev->quirks) 252 if (udev->quirks)
216 dev_dbg(&udev->dev, "USB quirks for this device: %x\n", 253 dev_dbg(&udev->dev, "USB quirks for this device: %x\n",
217 udev->quirks); 254 udev->quirks);
diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
index 6d2c8edb1ffe..52a97adf02a0 100644
--- a/drivers/usb/core/sysfs.c
+++ b/drivers/usb/core/sysfs.c
@@ -23,14 +23,16 @@ static ssize_t field##_show(struct device *dev, \
23{ \ 23{ \
24 struct usb_device *udev; \ 24 struct usb_device *udev; \
25 struct usb_host_config *actconfig; \ 25 struct usb_host_config *actconfig; \
26 ssize_t rc = 0; \
26 \ 27 \
27 udev = to_usb_device(dev); \ 28 udev = to_usb_device(dev); \
29 usb_lock_device(udev); \
28 actconfig = udev->actconfig; \ 30 actconfig = udev->actconfig; \
29 if (actconfig) \ 31 if (actconfig) \
30 return sprintf(buf, format_string, \ 32 rc = sprintf(buf, format_string, \
31 actconfig->desc.field); \ 33 actconfig->desc.field); \
32 else \ 34 usb_unlock_device(udev); \
33 return 0; \ 35 return rc; \
34} \ 36} \
35 37
36#define usb_actconfig_attr(field, format_string) \ 38#define usb_actconfig_attr(field, format_string) \
@@ -45,12 +47,15 @@ static ssize_t bMaxPower_show(struct device *dev,
45{ 47{
46 struct usb_device *udev; 48 struct usb_device *udev;
47 struct usb_host_config *actconfig; 49 struct usb_host_config *actconfig;
50 ssize_t rc = 0;
48 51
49 udev = to_usb_device(dev); 52 udev = to_usb_device(dev);
53 usb_lock_device(udev);
50 actconfig = udev->actconfig; 54 actconfig = udev->actconfig;
51 if (!actconfig) 55 if (actconfig)
52 return 0; 56 rc = sprintf(buf, "%dmA\n", usb_get_max_power(udev, actconfig));
53 return sprintf(buf, "%dmA\n", usb_get_max_power(udev, actconfig)); 57 usb_unlock_device(udev);
58 return rc;
54} 59}
55static DEVICE_ATTR_RO(bMaxPower); 60static DEVICE_ATTR_RO(bMaxPower);
56 61
@@ -59,12 +64,15 @@ static ssize_t configuration_show(struct device *dev,
59{ 64{
60 struct usb_device *udev; 65 struct usb_device *udev;
61 struct usb_host_config *actconfig; 66 struct usb_host_config *actconfig;
67 ssize_t rc = 0;
62 68
63 udev = to_usb_device(dev); 69 udev = to_usb_device(dev);
70 usb_lock_device(udev);
64 actconfig = udev->actconfig; 71 actconfig = udev->actconfig;
65 if ((!actconfig) || (!actconfig->string)) 72 if (actconfig && actconfig->string)
66 return 0; 73 rc = sprintf(buf, "%s\n", actconfig->string);
67 return sprintf(buf, "%s\n", actconfig->string); 74 usb_unlock_device(udev);
75 return rc;
68} 76}
69static DEVICE_ATTR_RO(configuration); 77static DEVICE_ATTR_RO(configuration);
70 78
@@ -390,7 +398,8 @@ static DEVICE_ATTR_RW(autosuspend);
390static const char on_string[] = "on"; 398static const char on_string[] = "on";
391static const char auto_string[] = "auto"; 399static const char auto_string[] = "auto";
392 400
393static void warn_level(void) { 401static void warn_level(void)
402{
394 static int level_warned; 403 static int level_warned;
395 404
396 if (!level_warned) { 405 if (!level_warned) {
@@ -449,7 +458,7 @@ static ssize_t usb2_hardware_lpm_show(struct device *dev,
449 struct usb_device *udev = to_usb_device(dev); 458 struct usb_device *udev = to_usb_device(dev);
450 const char *p; 459 const char *p;
451 460
452 if (udev->usb2_hw_lpm_enabled == 1) 461 if (udev->usb2_hw_lpm_allowed == 1)
453 p = "enabled"; 462 p = "enabled";
454 else 463 else
455 p = "disabled"; 464 p = "disabled";
@@ -469,8 +478,10 @@ static ssize_t usb2_hardware_lpm_store(struct device *dev,
469 478
470 ret = strtobool(buf, &value); 479 ret = strtobool(buf, &value);
471 480
472 if (!ret) 481 if (!ret) {
482 udev->usb2_hw_lpm_allowed = value;
473 ret = usb_set_usb2_hardware_lpm(udev, value); 483 ret = usb_set_usb2_hardware_lpm(udev, value);
484 }
474 485
475 usb_unlock_device(udev); 486 usb_unlock_device(udev);
476 487
@@ -644,7 +655,7 @@ static ssize_t authorized_store(struct device *dev,
644 result = usb_deauthorize_device(usb_dev); 655 result = usb_deauthorize_device(usb_dev);
645 else 656 else
646 result = usb_authorize_device(usb_dev); 657 result = usb_authorize_device(usb_dev);
647 return result < 0? result : size; 658 return result < 0 ? result : size;
648} 659}
649static DEVICE_ATTR_IGNORE_LOCKDEP(authorized, S_IRUGO | S_IWUSR, 660static DEVICE_ATTR_IGNORE_LOCKDEP(authorized, S_IRUGO | S_IWUSR,
650 authorized_show, authorized_store); 661 authorized_show, authorized_store);
@@ -764,6 +775,7 @@ read_descriptors(struct file *filp, struct kobject *kobj,
764 * Following that are the raw descriptor entries for all the 775 * Following that are the raw descriptor entries for all the
765 * configurations (config plus subsidiary descriptors). 776 * configurations (config plus subsidiary descriptors).
766 */ 777 */
778 usb_lock_device(udev);
767 for (cfgno = -1; cfgno < udev->descriptor.bNumConfigurations && 779 for (cfgno = -1; cfgno < udev->descriptor.bNumConfigurations &&
768 nleft > 0; ++cfgno) { 780 nleft > 0; ++cfgno) {
769 if (cfgno < 0) { 781 if (cfgno < 0) {
@@ -784,6 +796,7 @@ read_descriptors(struct file *filp, struct kobject *kobj,
784 off -= srclen; 796 off -= srclen;
785 } 797 }
786 } 798 }
799 usb_unlock_device(udev);
787 return count - nleft; 800 return count - nleft;
788} 801}
789 802
@@ -870,9 +883,7 @@ static ssize_t interface_show(struct device *dev, struct device_attribute *attr,
870 char *string; 883 char *string;
871 884
872 intf = to_usb_interface(dev); 885 intf = to_usb_interface(dev);
873 string = intf->cur_altsetting->string; 886 string = ACCESS_ONCE(intf->cur_altsetting->string);
874 barrier(); /* The altsetting might change! */
875
876 if (!string) 887 if (!string)
877 return 0; 888 return 0;
878 return sprintf(buf, "%s\n", string); 889 return sprintf(buf, "%s\n", string);
@@ -888,7 +899,7 @@ static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
888 899
889 intf = to_usb_interface(dev); 900 intf = to_usb_interface(dev);
890 udev = interface_to_usbdev(intf); 901 udev = interface_to_usbdev(intf);
891 alt = intf->cur_altsetting; 902 alt = ACCESS_ONCE(intf->cur_altsetting);
892 903
893 return sprintf(buf, "usb:v%04Xp%04Xd%04Xdc%02Xdsc%02Xdp%02X" 904 return sprintf(buf, "usb:v%04Xp%04Xd%04Xdc%02Xdsc%02Xdp%02X"
894 "ic%02Xisc%02Xip%02Xin%02X\n", 905 "ic%02Xisc%02Xip%02Xin%02X\n",
@@ -909,23 +920,14 @@ static ssize_t supports_autosuspend_show(struct device *dev,
909 struct device_attribute *attr, 920 struct device_attribute *attr,
910 char *buf) 921 char *buf)
911{ 922{
912 struct usb_interface *intf; 923 int s;
913 struct usb_device *udev;
914 int ret;
915 924
916 intf = to_usb_interface(dev); 925 device_lock(dev);
917 udev = interface_to_usbdev(intf);
918
919 usb_lock_device(udev);
920 /* Devices will be autosuspended even when an interface isn't claimed */ 926 /* Devices will be autosuspended even when an interface isn't claimed */
921 if (!intf->dev.driver || 927 s = (!dev->driver || to_usb_driver(dev->driver)->supports_autosuspend);
922 to_usb_driver(intf->dev.driver)->supports_autosuspend) 928 device_unlock(dev);
923 ret = sprintf(buf, "%u\n", 1);
924 else
925 ret = sprintf(buf, "%u\n", 0);
926 usb_unlock_device(udev);
927 929
928 return ret; 930 return sprintf(buf, "%u\n", s);
929} 931}
930static DEVICE_ATTR_RO(supports_autosuspend); 932static DEVICE_ATTR_RO(supports_autosuspend);
931 933
diff --git a/drivers/usb/core/urb.c b/drivers/usb/core/urb.c
index c12bc790a6a7..e62208356c89 100644
--- a/drivers/usb/core/urb.c
+++ b/drivers/usb/core/urb.c
@@ -138,13 +138,19 @@ void usb_anchor_urb(struct urb *urb, struct usb_anchor *anchor)
138} 138}
139EXPORT_SYMBOL_GPL(usb_anchor_urb); 139EXPORT_SYMBOL_GPL(usb_anchor_urb);
140 140
141static int usb_anchor_check_wakeup(struct usb_anchor *anchor)
142{
143 return atomic_read(&anchor->suspend_wakeups) == 0 &&
144 list_empty(&anchor->urb_list);
145}
146
141/* Callers must hold anchor->lock */ 147/* Callers must hold anchor->lock */
142static void __usb_unanchor_urb(struct urb *urb, struct usb_anchor *anchor) 148static void __usb_unanchor_urb(struct urb *urb, struct usb_anchor *anchor)
143{ 149{
144 urb->anchor = NULL; 150 urb->anchor = NULL;
145 list_del(&urb->anchor_list); 151 list_del(&urb->anchor_list);
146 usb_put_urb(urb); 152 usb_put_urb(urb);
147 if (list_empty(&anchor->urb_list)) 153 if (usb_anchor_check_wakeup(anchor))
148 wake_up(&anchor->wait); 154 wake_up(&anchor->wait);
149} 155}
150 156
@@ -846,6 +852,39 @@ void usb_unlink_anchored_urbs(struct usb_anchor *anchor)
846EXPORT_SYMBOL_GPL(usb_unlink_anchored_urbs); 852EXPORT_SYMBOL_GPL(usb_unlink_anchored_urbs);
847 853
848/** 854/**
855 * usb_anchor_suspend_wakeups
856 * @anchor: the anchor you want to suspend wakeups on
857 *
858 * Call this to stop the last urb being unanchored from waking up any
859 * usb_wait_anchor_empty_timeout waiters. This is used in the hcd urb give-
860 * back path to delay waking up until after the completion handler has run.
861 */
862void usb_anchor_suspend_wakeups(struct usb_anchor *anchor)
863{
864 if (anchor)
865 atomic_inc(&anchor->suspend_wakeups);
866}
867EXPORT_SYMBOL_GPL(usb_anchor_suspend_wakeups);
868
869/**
870 * usb_anchor_resume_wakeups
871 * @anchor: the anchor you want to resume wakeups on
872 *
873 * Allow usb_wait_anchor_empty_timeout waiters to be woken up again, and
874 * wake up any current waiters if the anchor is empty.
875 */
876void usb_anchor_resume_wakeups(struct usb_anchor *anchor)
877{
878 if (!anchor)
879 return;
880
881 atomic_dec(&anchor->suspend_wakeups);
882 if (usb_anchor_check_wakeup(anchor))
883 wake_up(&anchor->wait);
884}
885EXPORT_SYMBOL_GPL(usb_anchor_resume_wakeups);
886
887/**
849 * usb_wait_anchor_empty_timeout - wait for an anchor to be unused 888 * usb_wait_anchor_empty_timeout - wait for an anchor to be unused
850 * @anchor: the anchor you want to become unused 889 * @anchor: the anchor you want to become unused
851 * @timeout: how long you are willing to wait in milliseconds 890 * @timeout: how long you are willing to wait in milliseconds
@@ -858,7 +897,8 @@ EXPORT_SYMBOL_GPL(usb_unlink_anchored_urbs);
858int usb_wait_anchor_empty_timeout(struct usb_anchor *anchor, 897int usb_wait_anchor_empty_timeout(struct usb_anchor *anchor,
859 unsigned int timeout) 898 unsigned int timeout)
860{ 899{
861 return wait_event_timeout(anchor->wait, list_empty(&anchor->urb_list), 900 return wait_event_timeout(anchor->wait,
901 usb_anchor_check_wakeup(anchor),
862 msecs_to_jiffies(timeout)); 902 msecs_to_jiffies(timeout));
863} 903}
864EXPORT_SYMBOL_GPL(usb_wait_anchor_empty_timeout); 904EXPORT_SYMBOL_GPL(usb_wait_anchor_empty_timeout);
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index 0a6ee2e70b25..4d1144990d4c 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -497,7 +497,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
497 dev->authorized = 1; 497 dev->authorized = 1;
498 else { 498 else {
499 dev->authorized = usb_hcd->authorized_default; 499 dev->authorized = usb_hcd->authorized_default;
500 dev->wusb = usb_bus_is_wusb(bus)? 1 : 0; 500 dev->wusb = usb_bus_is_wusb(bus) ? 1 : 0;
501 } 501 }
502 return dev; 502 return dev;
503} 503}
diff --git a/drivers/usb/core/usb.h b/drivers/usb/core/usb.h
index 823857767a16..c49383669cd8 100644
--- a/drivers/usb/core/usb.h
+++ b/drivers/usb/core/usb.h
@@ -35,6 +35,7 @@ extern int usb_get_device_descriptor(struct usb_device *dev,
35 unsigned int size); 35 unsigned int size);
36extern int usb_get_bos_descriptor(struct usb_device *dev); 36extern int usb_get_bos_descriptor(struct usb_device *dev);
37extern void usb_release_bos_descriptor(struct usb_device *dev); 37extern void usb_release_bos_descriptor(struct usb_device *dev);
38extern int usb_device_supports_lpm(struct usb_device *udev);
38extern char *usb_cache_string(struct usb_device *udev, int index); 39extern char *usb_cache_string(struct usb_device *udev, int index);
39extern int usb_set_configuration(struct usb_device *dev, int configuration); 40extern int usb_set_configuration(struct usb_device *dev, int configuration);
40extern int usb_choose_configuration(struct usb_device *udev); 41extern int usb_choose_configuration(struct usb_device *udev);
diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index 474162e9d01d..74f9cf02da07 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -584,7 +584,7 @@ static int dwc3_remove(struct platform_device *pdev)
584 usb_phy_set_suspend(dwc->usb2_phy, 1); 584 usb_phy_set_suspend(dwc->usb2_phy, 1);
585 usb_phy_set_suspend(dwc->usb3_phy, 1); 585 usb_phy_set_suspend(dwc->usb3_phy, 1);
586 586
587 pm_runtime_put(&pdev->dev); 587 pm_runtime_put_sync(&pdev->dev);
588 pm_runtime_disable(&pdev->dev); 588 pm_runtime_disable(&pdev->dev);
589 589
590 dwc3_debugfs_exit(dwc); 590 dwc3_debugfs_exit(dwc);
@@ -691,7 +691,6 @@ static int dwc3_resume(struct device *dev)
691 691
692 usb_phy_init(dwc->usb3_phy); 692 usb_phy_init(dwc->usb3_phy);
693 usb_phy_init(dwc->usb2_phy); 693 usb_phy_init(dwc->usb2_phy);
694 msleep(100);
695 694
696 spin_lock_irqsave(&dwc->lock, flags); 695 spin_lock_irqsave(&dwc->lock, flags);
697 696
diff --git a/drivers/usb/dwc3/dwc3-pci.c b/drivers/usb/dwc3/dwc3-pci.c
index 2e252aae51ca..31443aeedcdb 100644
--- a/drivers/usb/dwc3/dwc3-pci.c
+++ b/drivers/usb/dwc3/dwc3-pci.c
@@ -165,7 +165,6 @@ static int dwc3_pci_probe(struct pci_dev *pci,
165 return 0; 165 return 0;
166 166
167err3: 167err3:
168 pci_set_drvdata(pci, NULL);
169 platform_device_put(dwc3); 168 platform_device_put(dwc3);
170err1: 169err1:
171 pci_disable_device(pci); 170 pci_disable_device(pci);
@@ -180,7 +179,6 @@ static void dwc3_pci_remove(struct pci_dev *pci)
180 platform_device_unregister(glue->dwc3); 179 platform_device_unregister(glue->dwc3);
181 platform_device_unregister(glue->usb2_phy); 180 platform_device_unregister(glue->usb2_phy);
182 platform_device_unregister(glue->usb3_phy); 181 platform_device_unregister(glue->usb3_phy);
183 pci_set_drvdata(pci, NULL);
184 pci_disable_device(pci); 182 pci_disable_device(pci);
185} 183}
186 184
diff --git a/drivers/usb/dwc3/ep0.c b/drivers/usb/dwc3/ep0.c
index 7fa93f4bc507..95f7649c71a7 100644
--- a/drivers/usb/dwc3/ep0.c
+++ b/drivers/usb/dwc3/ep0.c
@@ -352,7 +352,7 @@ static int dwc3_ep0_handle_status(struct dwc3 *dwc,
352 break; 352 break;
353 default: 353 default:
354 return -EINVAL; 354 return -EINVAL;
355 }; 355 }
356 356
357 response_pkt = (__le16 *) dwc->setup_buf; 357 response_pkt = (__le16 *) dwc->setup_buf;
358 *response_pkt = cpu_to_le16(usb_status); 358 *response_pkt = cpu_to_le16(usb_status);
@@ -470,7 +470,7 @@ static int dwc3_ep0_handle_feature(struct dwc3 *dwc,
470 470
471 default: 471 default:
472 return -EINVAL; 472 return -EINVAL;
473 }; 473 }
474 474
475 return 0; 475 return 0;
476} 476}
@@ -709,7 +709,7 @@ static int dwc3_ep0_std_request(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl)
709 dev_vdbg(dwc->dev, "Forwarding to gadget driver\n"); 709 dev_vdbg(dwc->dev, "Forwarding to gadget driver\n");
710 ret = dwc3_ep0_delegate_req(dwc, ctrl); 710 ret = dwc3_ep0_delegate_req(dwc, ctrl);
711 break; 711 break;
712 }; 712 }
713 713
714 return ret; 714 return ret;
715} 715}
diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
index 5e29ddeb4d33..8cfc3191be50 100644
--- a/drivers/usb/early/ehci-dbgp.c
+++ b/drivers/usb/early/ehci-dbgp.c
@@ -568,10 +568,6 @@ try_again:
568 dbgp_printk("Could not find attached debug device\n"); 568 dbgp_printk("Could not find attached debug device\n");
569 goto err; 569 goto err;
570 } 570 }
571 if (ret < 0) {
572 dbgp_printk("Attached device is not a debug device\n");
573 goto err;
574 }
575 dbgp_endpoint_out = dbgp_desc.bDebugOutEndpoint; 571 dbgp_endpoint_out = dbgp_desc.bDebugOutEndpoint;
576 dbgp_endpoint_in = dbgp_desc.bDebugInEndpoint; 572 dbgp_endpoint_in = dbgp_desc.bDebugInEndpoint;
577 573
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index 48cddf3cd6b8..a91e6422f930 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -58,6 +58,20 @@ config USB_GADGET_DEBUG
58 trying to track down. Never enable these messages for a 58 trying to track down. Never enable these messages for a
59 production build. 59 production build.
60 60
61config USB_GADGET_VERBOSE
62 bool "Verbose debugging Messages (DEVELOPMENT)"
63 depends on USB_GADGET_DEBUG
64 help
65 Many controller and gadget drivers will print verbose debugging
66 messages if you use this option to ask for those messages.
67
68 Avoid enabling these messages, even if you're actively
69 debugging such a driver. Many drivers will emit so many
70 messages that the driver timings are affected, which will
71 either create new failure modes or remove the one you're
72 trying to track down. Never enable these messages for a
73 production build.
74
61config USB_GADGET_DEBUG_FILES 75config USB_GADGET_DEBUG_FILES
62 boolean "Debugging information files (DEVELOPMENT)" 76 boolean "Debugging information files (DEVELOPMENT)"
63 depends on PROC_FS 77 depends on PROC_FS
@@ -525,6 +539,9 @@ config USB_F_SUBSET
525config USB_F_RNDIS 539config USB_F_RNDIS
526 tristate 540 tristate
527 541
542config USB_F_MASS_STORAGE
543 tristate
544
528choice 545choice
529 tristate "USB Gadget Drivers" 546 tristate "USB Gadget Drivers"
530 default USB_ETH 547 default USB_ETH
@@ -662,6 +679,16 @@ config USB_CONFIGFS_PHONET
662 help 679 help
663 The Phonet protocol implementation for USB device. 680 The Phonet protocol implementation for USB device.
664 681
682config USB_CONFIGFS_MASS_STORAGE
683 boolean "Mass storage"
684 depends on USB_CONFIGFS
685 select USB_F_MASS_STORAGE
686 help
687 The Mass Storage Gadget acts as a USB Mass Storage disk drive.
688 As its storage repository it can use a regular file or a block
689 device (in much the same way as the "loop" device driver),
690 specified as a module parameter or sysfs option.
691
665config USB_ZERO 692config USB_ZERO
666 tristate "Gadget Zero (DEVELOPMENT)" 693 tristate "Gadget Zero (DEVELOPMENT)"
667 select USB_LIBCOMPOSITE 694 select USB_LIBCOMPOSITE
@@ -878,6 +905,7 @@ config USB_MASS_STORAGE
878 tristate "Mass Storage Gadget" 905 tristate "Mass Storage Gadget"
879 depends on BLOCK 906 depends on BLOCK
880 select USB_LIBCOMPOSITE 907 select USB_LIBCOMPOSITE
908 select USB_F_MASS_STORAGE
881 help 909 help
882 The Mass Storage Gadget acts as a USB Mass Storage disk drive. 910 The Mass Storage Gadget acts as a USB Mass Storage disk drive.
883 As its storage repository it can use a regular file or a block 911 As its storage repository it can use a regular file or a block
@@ -1001,6 +1029,7 @@ config USB_G_ACM_MS
1001 select USB_LIBCOMPOSITE 1029 select USB_LIBCOMPOSITE
1002 select USB_U_SERIAL 1030 select USB_U_SERIAL
1003 select USB_F_ACM 1031 select USB_F_ACM
1032 select USB_F_MASS_STORAGE
1004 help 1033 help
1005 This driver provides two functions in one configuration: 1034 This driver provides two functions in one configuration:
1006 a mass storage, and a CDC ACM (serial port) link. 1035 a mass storage, and a CDC ACM (serial port) link.
@@ -1015,8 +1044,8 @@ config USB_G_MULTI
1015 select USB_LIBCOMPOSITE 1044 select USB_LIBCOMPOSITE
1016 select USB_U_SERIAL 1045 select USB_U_SERIAL
1017 select USB_U_ETHER 1046 select USB_U_ETHER
1018 select USB_U_RNDIS
1019 select USB_F_ACM 1047 select USB_F_ACM
1048 select USB_F_MASS_STORAGE
1020 help 1049 help
1021 The Multifunction Composite Gadget provides Ethernet (RNDIS 1050 The Multifunction Composite Gadget provides Ethernet (RNDIS
1022 and/or CDC Ethernet), mass storage and ACM serial link 1051 and/or CDC Ethernet), mass storage and ACM serial link
@@ -1035,6 +1064,8 @@ config USB_G_MULTI
1035config USB_G_MULTI_RNDIS 1064config USB_G_MULTI_RNDIS
1036 bool "RNDIS + CDC Serial + Storage configuration" 1065 bool "RNDIS + CDC Serial + Storage configuration"
1037 depends on USB_G_MULTI 1066 depends on USB_G_MULTI
1067 select USB_U_RNDIS
1068 select USB_F_RNDIS
1038 default y 1069 default y
1039 help 1070 help
1040 This option enables a configuration with RNDIS, CDC Serial and 1071 This option enables a configuration with RNDIS, CDC Serial and
@@ -1048,6 +1079,7 @@ config USB_G_MULTI_CDC
1048 bool "CDC Ethernet + CDC Serial + Storage configuration" 1079 bool "CDC Ethernet + CDC Serial + Storage configuration"
1049 depends on USB_G_MULTI 1080 depends on USB_G_MULTI
1050 default n 1081 default n
1082 select USB_F_ECM
1051 help 1083 help
1052 This option enables a configuration with CDC Ethernet (ECM), CDC 1084 This option enables a configuration with CDC Ethernet (ECM), CDC
1053 Serial and Mass Storage functions available in the Multifunction 1085 Serial and Mass Storage functions available in the Multifunction
diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile
index 386db9daf1d9..f1af39603d4d 100644
--- a/drivers/usb/gadget/Makefile
+++ b/drivers/usb/gadget/Makefile
@@ -1,7 +1,8 @@
1# 1#
2# USB peripheral controller drivers 2# USB peripheral controller drivers
3# 3#
4ccflags-$(CONFIG_USB_GADGET_DEBUG) := -DDEBUG 4ccflags-$(CONFIG_USB_GADGET_DEBUG) := -DDEBUG
5ccflags-$(CONFIG_USB_GADGET_VERBOSE) += -DVERBOSE_DEBUG
5 6
6obj-$(CONFIG_USB_GADGET) += udc-core.o 7obj-$(CONFIG_USB_GADGET) += udc-core.o
7obj-$(CONFIG_USB_LIBCOMPOSITE) += libcomposite.o 8obj-$(CONFIG_USB_LIBCOMPOSITE) += libcomposite.o
@@ -60,6 +61,8 @@ usb_f_ecm_subset-y := f_subset.o
60obj-$(CONFIG_USB_F_SUBSET) += usb_f_ecm_subset.o 61obj-$(CONFIG_USB_F_SUBSET) += usb_f_ecm_subset.o
61usb_f_rndis-y := f_rndis.o 62usb_f_rndis-y := f_rndis.o
62obj-$(CONFIG_USB_F_RNDIS) += usb_f_rndis.o 63obj-$(CONFIG_USB_F_RNDIS) += usb_f_rndis.o
64usb_f_mass_storage-y := f_mass_storage.o storage_common.o
65obj-$(CONFIG_USB_F_MASS_STORAGE)+= usb_f_mass_storage.o
63 66
64# 67#
65# USB gadget drivers 68# USB gadget drivers
diff --git a/drivers/usb/gadget/acm_ms.c b/drivers/usb/gadget/acm_ms.c
index 4b947bb50f62..7bfa134fe0e3 100644
--- a/drivers/usb/gadget/acm_ms.c
+++ b/drivers/usb/gadget/acm_ms.c
@@ -31,16 +31,7 @@
31#define ACM_MS_VENDOR_NUM 0x1d6b /* Linux Foundation */ 31#define ACM_MS_VENDOR_NUM 0x1d6b /* Linux Foundation */
32#define ACM_MS_PRODUCT_NUM 0x0106 /* Composite Gadget: ACM + MS*/ 32#define ACM_MS_PRODUCT_NUM 0x0106 /* Composite Gadget: ACM + MS*/
33 33
34/*-------------------------------------------------------------------------*/ 34#include "f_mass_storage.h"
35
36/*
37 * Kbuild is not very cooperative with respect to linking separately
38 * compiled library objects into one module. So for now we won't use
39 * separate compilation ... ensuring init/exit sections work to shrink
40 * the runtime footprint, and giving us at least some parts of what
41 * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
42 */
43#include "f_mass_storage.c"
44 35
45/*-------------------------------------------------------------------------*/ 36/*-------------------------------------------------------------------------*/
46USB_GADGET_COMPOSITE_OPTIONS(); 37USB_GADGET_COMPOSITE_OPTIONS();
@@ -104,18 +95,35 @@ static struct usb_gadget_strings *dev_strings[] = {
104/****************************** Configurations ******************************/ 95/****************************** Configurations ******************************/
105 96
106static struct fsg_module_parameters fsg_mod_data = { .stall = 1 }; 97static struct fsg_module_parameters fsg_mod_data = { .stall = 1 };
107FSG_MODULE_PARAMETERS(/* no prefix */, fsg_mod_data); 98#ifdef CONFIG_USB_GADGET_DEBUG_FILES
108 99
109static struct fsg_common fsg_common; 100static unsigned int fsg_num_buffers = CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS;
101
102#else
103
104/*
105 * Number of buffers we will use.
106 * 2 is usually enough for good buffering pipeline
107 */
108#define fsg_num_buffers CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS
109
110#endif /* CONFIG_USB_DEBUG */
111
112FSG_MODULE_PARAMETERS(/* no prefix */, fsg_mod_data);
110 113
111/*-------------------------------------------------------------------------*/ 114/*-------------------------------------------------------------------------*/
112static struct usb_function *f_acm; 115static struct usb_function *f_acm;
113static struct usb_function_instance *f_acm_inst; 116static struct usb_function_instance *f_acm_inst;
117
118static struct usb_function_instance *fi_msg;
119static struct usb_function *f_msg;
120
114/* 121/*
115 * We _always_ have both ACM and mass storage functions. 122 * We _always_ have both ACM and mass storage functions.
116 */ 123 */
117static int __init acm_ms_do_config(struct usb_configuration *c) 124static int __init acm_ms_do_config(struct usb_configuration *c)
118{ 125{
126 struct fsg_opts *opts;
119 int status; 127 int status;
120 128
121 if (gadget_is_otg(c->cdev->gadget)) { 129 if (gadget_is_otg(c->cdev->gadget)) {
@@ -123,31 +131,37 @@ static int __init acm_ms_do_config(struct usb_configuration *c)
123 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; 131 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
124 } 132 }
125 133
126 f_acm_inst = usb_get_function_instance("acm"); 134 opts = fsg_opts_from_func_inst(fi_msg);
127 if (IS_ERR(f_acm_inst))
128 return PTR_ERR(f_acm_inst);
129 135
130 f_acm = usb_get_function(f_acm_inst); 136 f_acm = usb_get_function(f_acm_inst);
131 if (IS_ERR(f_acm)) { 137 if (IS_ERR(f_acm))
132 status = PTR_ERR(f_acm); 138 return PTR_ERR(f_acm);
133 goto err_func; 139
140 f_msg = usb_get_function(fi_msg);
141 if (IS_ERR(f_msg)) {
142 status = PTR_ERR(f_msg);
143 goto put_acm;
134 } 144 }
135 145
136 status = usb_add_function(c, f_acm); 146 status = usb_add_function(c, f_acm);
137 if (status < 0) 147 if (status < 0)
138 goto err_conf; 148 goto put_msg;
139 149
140 status = fsg_bind_config(c->cdev, c, &fsg_common); 150 status = fsg_common_run_thread(opts->common);
141 if (status < 0) 151 if (status)
142 goto err_fsg; 152 goto remove_acm;
153
154 status = usb_add_function(c, f_msg);
155 if (status)
156 goto remove_acm;
143 157
144 return 0; 158 return 0;
145err_fsg: 159remove_acm:
146 usb_remove_function(c, f_acm); 160 usb_remove_function(c, f_acm);
147err_conf: 161put_msg:
162 usb_put_function(f_msg);
163put_acm:
148 usb_put_function(f_acm); 164 usb_put_function(f_acm);
149err_func:
150 usb_put_function_instance(f_acm_inst);
151 return status; 165 return status;
152} 166}
153 167
@@ -163,45 +177,82 @@ static struct usb_configuration acm_ms_config_driver = {
163static int __init acm_ms_bind(struct usb_composite_dev *cdev) 177static int __init acm_ms_bind(struct usb_composite_dev *cdev)
164{ 178{
165 struct usb_gadget *gadget = cdev->gadget; 179 struct usb_gadget *gadget = cdev->gadget;
180 struct fsg_opts *opts;
181 struct fsg_config config;
166 int status; 182 int status;
167 void *retp;
168 183
169 /* set up mass storage function */ 184 f_acm_inst = usb_get_function_instance("acm");
170 retp = fsg_common_from_params(&fsg_common, cdev, &fsg_mod_data); 185 if (IS_ERR(f_acm_inst))
171 if (IS_ERR(retp)) { 186 return PTR_ERR(f_acm_inst);
172 status = PTR_ERR(retp); 187
173 return PTR_ERR(retp); 188 fi_msg = usb_get_function_instance("mass_storage");
189 if (IS_ERR(fi_msg)) {
190 status = PTR_ERR(fi_msg);
191 goto fail_get_msg;
174 } 192 }
175 193
194 /* set up mass storage function */
195 fsg_config_from_params(&config, &fsg_mod_data, fsg_num_buffers);
196 opts = fsg_opts_from_func_inst(fi_msg);
197
198 opts->no_configfs = true;
199 status = fsg_common_set_num_buffers(opts->common, fsg_num_buffers);
200 if (status)
201 goto fail;
202
203 status = fsg_common_set_nluns(opts->common, config.nluns);
204 if (status)
205 goto fail_set_nluns;
206
207 status = fsg_common_set_cdev(opts->common, cdev, config.can_stall);
208 if (status)
209 goto fail_set_cdev;
210
211 fsg_common_set_sysfs(opts->common, true);
212 status = fsg_common_create_luns(opts->common, &config);
213 if (status)
214 goto fail_set_cdev;
215
216 fsg_common_set_inquiry_string(opts->common, config.vendor_name,
217 config.product_name);
176 /* 218 /*
177 * Allocate string descriptor numbers ... note that string 219 * Allocate string descriptor numbers ... note that string
178 * contents can be overridden by the composite_dev glue. 220 * contents can be overridden by the composite_dev glue.
179 */ 221 */
180 status = usb_string_ids_tab(cdev, strings_dev); 222 status = usb_string_ids_tab(cdev, strings_dev);
181 if (status < 0) 223 if (status < 0)
182 goto fail1; 224 goto fail_string_ids;
183 device_desc.iManufacturer = strings_dev[USB_GADGET_MANUFACTURER_IDX].id; 225 device_desc.iManufacturer = strings_dev[USB_GADGET_MANUFACTURER_IDX].id;
184 device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id; 226 device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id;
185 227
186 /* register our configuration */ 228 /* register our configuration */
187 status = usb_add_config(cdev, &acm_ms_config_driver, acm_ms_do_config); 229 status = usb_add_config(cdev, &acm_ms_config_driver, acm_ms_do_config);
188 if (status < 0) 230 if (status < 0)
189 goto fail1; 231 goto fail_string_ids;
190 232
191 usb_composite_overwrite_options(cdev, &coverwrite); 233 usb_composite_overwrite_options(cdev, &coverwrite);
192 dev_info(&gadget->dev, "%s, version: " DRIVER_VERSION "\n", 234 dev_info(&gadget->dev, "%s, version: " DRIVER_VERSION "\n",
193 DRIVER_DESC); 235 DRIVER_DESC);
194 fsg_common_put(&fsg_common);
195 return 0; 236 return 0;
196 237
197 /* error recovery */ 238 /* error recovery */
198fail1: 239fail_string_ids:
199 fsg_common_put(&fsg_common); 240 fsg_common_remove_luns(opts->common);
241fail_set_cdev:
242 fsg_common_free_luns(opts->common);
243fail_set_nluns:
244 fsg_common_free_buffers(opts->common);
245fail:
246 usb_put_function_instance(fi_msg);
247fail_get_msg:
248 usb_put_function_instance(f_acm_inst);
200 return status; 249 return status;
201} 250}
202 251
203static int __exit acm_ms_unbind(struct usb_composite_dev *cdev) 252static int __exit acm_ms_unbind(struct usb_composite_dev *cdev)
204{ 253{
254 usb_put_function(f_msg);
255 usb_put_function_instance(fi_msg);
205 usb_put_function(f_acm); 256 usb_put_function(f_acm);
206 usb_put_function_instance(f_acm_inst); 257 usb_put_function_instance(f_acm_inst);
207 return 0; 258 return 0;
diff --git a/drivers/usb/gadget/amd5536udc.c b/drivers/usb/gadget/amd5536udc.c
index a9a4346c83aa..54a1e2954cea 100644
--- a/drivers/usb/gadget/amd5536udc.c
+++ b/drivers/usb/gadget/amd5536udc.c
@@ -3078,8 +3078,6 @@ static void udc_pci_remove(struct pci_dev *pdev)
3078 if (dev->active) 3078 if (dev->active)
3079 pci_disable_device(pdev); 3079 pci_disable_device(pdev);
3080 3080
3081 pci_set_drvdata(pdev, NULL);
3082
3083 udc_remove(dev); 3081 udc_remove(dev);
3084} 3082}
3085 3083
diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index d4f0f3305759..3e7ae707f691 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -354,7 +354,7 @@ static u8 encode_bMaxPower(enum usb_device_speed speed,
354 return DIV_ROUND_UP(val, 8); 354 return DIV_ROUND_UP(val, 8);
355 default: 355 default:
356 return DIV_ROUND_UP(val, 2); 356 return DIV_ROUND_UP(val, 2);
357 }; 357 }
358} 358}
359 359
360static int config_buf(struct usb_configuration *config, 360static int config_buf(struct usb_configuration *config,
diff --git a/drivers/usb/gadget/configfs.c b/drivers/usb/gadget/configfs.c
index 8f0d6141e5e6..25885112fa35 100644
--- a/drivers/usb/gadget/configfs.c
+++ b/drivers/usb/gadget/configfs.c
@@ -557,7 +557,7 @@ static struct config_group *function_make(
557 557
558 fi = usb_get_function_instance(func_name); 558 fi = usb_get_function_instance(func_name);
559 if (IS_ERR(fi)) 559 if (IS_ERR(fi))
560 return ERR_PTR(PTR_ERR(fi)); 560 return ERR_CAST(fi);
561 561
562 ret = config_item_set_name(&fi->group.cg_item, name); 562 ret = config_item_set_name(&fi->group.cg_item, name);
563 if (ret) { 563 if (ret) {
@@ -991,6 +991,14 @@ static struct configfs_subsystem gadget_subsys = {
991 .su_mutex = __MUTEX_INITIALIZER(gadget_subsys.su_mutex), 991 .su_mutex = __MUTEX_INITIALIZER(gadget_subsys.su_mutex),
992}; 992};
993 993
994void unregister_gadget_item(struct config_item *item)
995{
996 struct gadget_info *gi = to_gadget_info(item);
997
998 unregister_gadget(gi);
999}
1000EXPORT_SYMBOL(unregister_gadget_item);
1001
994static int __init gadget_cfs_init(void) 1002static int __init gadget_cfs_init(void)
995{ 1003{
996 int ret; 1004 int ret;
diff --git a/drivers/usb/gadget/configfs.h b/drivers/usb/gadget/configfs.h
new file mode 100644
index 000000000000..a7b564a913d1
--- /dev/null
+++ b/drivers/usb/gadget/configfs.h
@@ -0,0 +1,6 @@
1#ifndef USB__GADGET__CONFIGFS__H
2#define USB__GADGET__CONFIGFS__H
3
4void unregister_gadget_item(struct config_item *item);
5
6#endif /* USB__GADGET__CONFIGFS__H */
diff --git a/drivers/usb/gadget/dummy_hcd.c b/drivers/usb/gadget/dummy_hcd.c
index b8a2376971a4..8f4dae310923 100644
--- a/drivers/usb/gadget/dummy_hcd.c
+++ b/drivers/usb/gadget/dummy_hcd.c
@@ -544,7 +544,7 @@ static int dummy_enable(struct usb_ep *_ep,
544 default: 544 default:
545 val = "ctrl"; 545 val = "ctrl";
546 break; 546 break;
547 }; val; }), 547 } val; }),
548 max, ep->stream_en ? "enabled" : "disabled"); 548 max, ep->stream_en ? "enabled" : "disabled");
549 549
550 /* at this point real hardware should be NAKing transfers 550 /* at this point real hardware should be NAKing transfers
@@ -2271,7 +2271,7 @@ static inline ssize_t show_urb(char *buf, size_t size, struct urb *urb)
2271 default: 2271 default:
2272 s = "?"; 2272 s = "?";
2273 break; 2273 break;
2274 }; s; }), 2274 } s; }),
2275 ep, ep ? (usb_pipein(urb->pipe) ? "in" : "out") : "", 2275 ep, ep ? (usb_pipein(urb->pipe) ? "in" : "out") : "",
2276 ({ char *s; \ 2276 ({ char *s; \
2277 switch (usb_pipetype(urb->pipe)) { \ 2277 switch (usb_pipetype(urb->pipe)) { \
@@ -2287,7 +2287,7 @@ static inline ssize_t show_urb(char *buf, size_t size, struct urb *urb)
2287 default: \ 2287 default: \
2288 s = "-iso"; \ 2288 s = "-iso"; \
2289 break; \ 2289 break; \
2290 }; s; }), 2290 } s; }),
2291 urb->actual_length, urb->transfer_buffer_length); 2291 urb->actual_length, urb->transfer_buffer_length);
2292} 2292}
2293 2293
diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c
index a01d7d38c016..a03ba2c83589 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -213,12 +213,14 @@
213#include <linux/spinlock.h> 213#include <linux/spinlock.h>
214#include <linux/string.h> 214#include <linux/string.h>
215#include <linux/freezer.h> 215#include <linux/freezer.h>
216#include <linux/module.h>
216 217
217#include <linux/usb/ch9.h> 218#include <linux/usb/ch9.h>
218#include <linux/usb/gadget.h> 219#include <linux/usb/gadget.h>
219#include <linux/usb/composite.h> 220#include <linux/usb/composite.h>
220 221
221#include "gadget_chips.h" 222#include "gadget_chips.h"
223#include "configfs.h"
222 224
223 225
224/*------------------------------------------------------------------------*/ 226/*------------------------------------------------------------------------*/
@@ -228,26 +230,30 @@
228 230
229static const char fsg_string_interface[] = "Mass Storage"; 231static const char fsg_string_interface[] = "Mass Storage";
230 232
231#include "storage_common.c" 233#include "storage_common.h"
234#include "f_mass_storage.h"
232 235
236/* Static strings, in UTF-8 (for simplicity we use only ASCII characters) */
237static struct usb_string fsg_strings[] = {
238 {FSG_STRING_INTERFACE, fsg_string_interface},
239 {}
240};
241
242static struct usb_gadget_strings fsg_stringtab = {
243 .language = 0x0409, /* en-us */
244 .strings = fsg_strings,
245};
246
247static struct usb_gadget_strings *fsg_strings_array[] = {
248 &fsg_stringtab,
249 NULL,
250};
233 251
234/*-------------------------------------------------------------------------*/ 252/*-------------------------------------------------------------------------*/
235 253
236struct fsg_dev; 254struct fsg_dev;
237struct fsg_common; 255struct fsg_common;
238 256
239/* FSF callback functions */
240struct fsg_operations {
241 /*
242 * Callback function to call when thread exits. If no
243 * callback is set or it returns value lower then zero MSF
244 * will force eject all LUNs it operates on (including those
245 * marked as non-removable or with prevent_medium_removal flag
246 * set).
247 */
248 int (*thread_exits)(struct fsg_common *common);
249};
250
251/* Data shared by all the FSG instances. */ 257/* Data shared by all the FSG instances. */
252struct fsg_common { 258struct fsg_common {
253 struct usb_gadget *gadget; 259 struct usb_gadget *gadget;
@@ -268,13 +274,14 @@ struct fsg_common {
268 struct fsg_buffhd *next_buffhd_to_fill; 274 struct fsg_buffhd *next_buffhd_to_fill;
269 struct fsg_buffhd *next_buffhd_to_drain; 275 struct fsg_buffhd *next_buffhd_to_drain;
270 struct fsg_buffhd *buffhds; 276 struct fsg_buffhd *buffhds;
277 unsigned int fsg_num_buffers;
271 278
272 int cmnd_size; 279 int cmnd_size;
273 u8 cmnd[MAX_COMMAND_SIZE]; 280 u8 cmnd[MAX_COMMAND_SIZE];
274 281
275 unsigned int nluns; 282 unsigned int nluns;
276 unsigned int lun; 283 unsigned int lun;
277 struct fsg_lun *luns; 284 struct fsg_lun **luns;
278 struct fsg_lun *curlun; 285 struct fsg_lun *curlun;
279 286
280 unsigned int bulk_out_maxpacket; 287 unsigned int bulk_out_maxpacket;
@@ -294,6 +301,7 @@ struct fsg_common {
294 unsigned int short_packet_received:1; 301 unsigned int short_packet_received:1;
295 unsigned int bad_lun_okay:1; 302 unsigned int bad_lun_okay:1;
296 unsigned int running:1; 303 unsigned int running:1;
304 unsigned int sysfs:1;
297 305
298 int thread_wakeup_needed; 306 int thread_wakeup_needed;
299 struct completion thread_notifier; 307 struct completion thread_notifier;
@@ -313,27 +321,6 @@ struct fsg_common {
313 struct kref ref; 321 struct kref ref;
314}; 322};
315 323
316struct fsg_config {
317 unsigned nluns;
318 struct fsg_lun_config {
319 const char *filename;
320 char ro;
321 char removable;
322 char cdrom;
323 char nofua;
324 } luns[FSG_MAX_LUNS];
325
326 /* Callback functions. */
327 const struct fsg_operations *ops;
328 /* Gadget's private data. */
329 void *private_data;
330
331 const char *vendor_name; /* 8 characters or less */
332 const char *product_name; /* 16 characters or less */
333
334 char can_stall;
335};
336
337struct fsg_dev { 324struct fsg_dev {
338 struct usb_function function; 325 struct usb_function function;
339 struct usb_gadget *gadget; /* Copy of cdev->gadget */ 326 struct usb_gadget *gadget; /* Copy of cdev->gadget */
@@ -2172,7 +2159,7 @@ static int received_cbw(struct fsg_dev *fsg, struct fsg_buffhd *bh)
2172 common->data_dir = DATA_DIR_NONE; 2159 common->data_dir = DATA_DIR_NONE;
2173 common->lun = cbw->Lun; 2160 common->lun = cbw->Lun;
2174 if (common->lun < common->nluns) 2161 if (common->lun < common->nluns)
2175 common->curlun = &common->luns[common->lun]; 2162 common->curlun = common->luns[common->lun];
2176 else 2163 else
2177 common->curlun = NULL; 2164 common->curlun = NULL;
2178 common->tag = cbw->Tag; 2165 common->tag = cbw->Tag;
@@ -2244,7 +2231,7 @@ reset:
2244 if (common->fsg) { 2231 if (common->fsg) {
2245 fsg = common->fsg; 2232 fsg = common->fsg;
2246 2233
2247 for (i = 0; i < fsg_num_buffers; ++i) { 2234 for (i = 0; i < common->fsg_num_buffers; ++i) {
2248 struct fsg_buffhd *bh = &common->buffhds[i]; 2235 struct fsg_buffhd *bh = &common->buffhds[i];
2249 2236
2250 if (bh->inreq) { 2237 if (bh->inreq) {
@@ -2303,7 +2290,7 @@ reset:
2303 clear_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags); 2290 clear_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags);
2304 2291
2305 /* Allocate the requests */ 2292 /* Allocate the requests */
2306 for (i = 0; i < fsg_num_buffers; ++i) { 2293 for (i = 0; i < common->fsg_num_buffers; ++i) {
2307 struct fsg_buffhd *bh = &common->buffhds[i]; 2294 struct fsg_buffhd *bh = &common->buffhds[i];
2308 2295
2309 rc = alloc_request(common, fsg->bulk_in, &bh->inreq); 2296 rc = alloc_request(common, fsg->bulk_in, &bh->inreq);
@@ -2320,7 +2307,9 @@ reset:
2320 2307
2321 common->running = 1; 2308 common->running = 1;
2322 for (i = 0; i < common->nluns; ++i) 2309 for (i = 0; i < common->nluns; ++i)
2323 common->luns[i].unit_attention_data = SS_RESET_OCCURRED; 2310 if (common->luns[i])
2311 common->luns[i]->unit_attention_data =
2312 SS_RESET_OCCURRED;
2324 return rc; 2313 return rc;
2325} 2314}
2326 2315
@@ -2372,7 +2361,7 @@ static void handle_exception(struct fsg_common *common)
2372 2361
2373 /* Cancel all the pending transfers */ 2362 /* Cancel all the pending transfers */
2374 if (likely(common->fsg)) { 2363 if (likely(common->fsg)) {
2375 for (i = 0; i < fsg_num_buffers; ++i) { 2364 for (i = 0; i < common->fsg_num_buffers; ++i) {
2376 bh = &common->buffhds[i]; 2365 bh = &common->buffhds[i];
2377 if (bh->inreq_busy) 2366 if (bh->inreq_busy)
2378 usb_ep_dequeue(common->fsg->bulk_in, bh->inreq); 2367 usb_ep_dequeue(common->fsg->bulk_in, bh->inreq);
@@ -2384,7 +2373,7 @@ static void handle_exception(struct fsg_common *common)
2384 /* Wait until everything is idle */ 2373 /* Wait until everything is idle */
2385 for (;;) { 2374 for (;;) {
2386 int num_active = 0; 2375 int num_active = 0;
2387 for (i = 0; i < fsg_num_buffers; ++i) { 2376 for (i = 0; i < common->fsg_num_buffers; ++i) {
2388 bh = &common->buffhds[i]; 2377 bh = &common->buffhds[i];
2389 num_active += bh->inreq_busy + bh->outreq_busy; 2378 num_active += bh->inreq_busy + bh->outreq_busy;
2390 } 2379 }
@@ -2407,7 +2396,7 @@ static void handle_exception(struct fsg_common *common)
2407 */ 2396 */
2408 spin_lock_irq(&common->lock); 2397 spin_lock_irq(&common->lock);
2409 2398
2410 for (i = 0; i < fsg_num_buffers; ++i) { 2399 for (i = 0; i < common->fsg_num_buffers; ++i) {
2411 bh = &common->buffhds[i]; 2400 bh = &common->buffhds[i];
2412 bh->state = BUF_STATE_EMPTY; 2401 bh->state = BUF_STATE_EMPTY;
2413 } 2402 }
@@ -2420,7 +2409,9 @@ static void handle_exception(struct fsg_common *common)
2420 common->state = FSG_STATE_STATUS_PHASE; 2409 common->state = FSG_STATE_STATUS_PHASE;
2421 else { 2410 else {
2422 for (i = 0; i < common->nluns; ++i) { 2411 for (i = 0; i < common->nluns; ++i) {
2423 curlun = &common->luns[i]; 2412 curlun = common->luns[i];
2413 if (!curlun)
2414 continue;
2424 curlun->prevent_medium_removal = 0; 2415 curlun->prevent_medium_removal = 0;
2425 curlun->sense_data = SS_NO_SENSE; 2416 curlun->sense_data = SS_NO_SENSE;
2426 curlun->unit_attention_data = SS_NO_SENSE; 2417 curlun->unit_attention_data = SS_NO_SENSE;
@@ -2462,8 +2453,9 @@ static void handle_exception(struct fsg_common *common)
2462 * CONFIG_CHANGE cases. 2453 * CONFIG_CHANGE cases.
2463 */ 2454 */
2464 /* for (i = 0; i < common->nluns; ++i) */ 2455 /* for (i = 0; i < common->nluns; ++i) */
2465 /* common->luns[i].unit_attention_data = */ 2456 /* if (common->luns[i]) */
2466 /* SS_RESET_OCCURRED; */ 2457 /* common->luns[i]->unit_attention_data = */
2458 /* SS_RESET_OCCURRED; */
2467 break; 2459 break;
2468 2460
2469 case FSG_STATE_CONFIG_CHANGE: 2461 case FSG_STATE_CONFIG_CHANGE:
@@ -2559,12 +2551,13 @@ static int fsg_main_thread(void *common_)
2559 2551
2560 if (!common->ops || !common->ops->thread_exits 2552 if (!common->ops || !common->ops->thread_exits
2561 || common->ops->thread_exits(common) < 0) { 2553 || common->ops->thread_exits(common) < 0) {
2562 struct fsg_lun *curlun = common->luns; 2554 struct fsg_lun **curlun_it = common->luns;
2563 unsigned i = common->nluns; 2555 unsigned i = common->nluns;
2564 2556
2565 down_write(&common->filesem); 2557 down_write(&common->filesem);
2566 for (; i--; ++curlun) { 2558 for (; i--; ++curlun_it) {
2567 if (!fsg_lun_is_open(curlun)) 2559 struct fsg_lun *curlun = *curlun_it;
2560 if (!curlun || !fsg_lun_is_open(curlun))
2568 continue; 2561 continue;
2569 2562
2570 fsg_lun_close(curlun); 2563 fsg_lun_close(curlun);
@@ -2580,6 +2573,56 @@ static int fsg_main_thread(void *common_)
2580 2573
2581/*************************** DEVICE ATTRIBUTES ***************************/ 2574/*************************** DEVICE ATTRIBUTES ***************************/
2582 2575
2576static ssize_t ro_show(struct device *dev, struct device_attribute *attr, char *buf)
2577{
2578 struct fsg_lun *curlun = fsg_lun_from_dev(dev);
2579
2580 return fsg_show_ro(curlun, buf);
2581}
2582
2583static ssize_t nofua_show(struct device *dev, struct device_attribute *attr,
2584 char *buf)
2585{
2586 struct fsg_lun *curlun = fsg_lun_from_dev(dev);
2587
2588 return fsg_show_nofua(curlun, buf);
2589}
2590
2591static ssize_t file_show(struct device *dev, struct device_attribute *attr,
2592 char *buf)
2593{
2594 struct fsg_lun *curlun = fsg_lun_from_dev(dev);
2595 struct rw_semaphore *filesem = dev_get_drvdata(dev);
2596
2597 return fsg_show_file(curlun, filesem, buf);
2598}
2599
2600static ssize_t ro_store(struct device *dev, struct device_attribute *attr,
2601 const char *buf, size_t count)
2602{
2603 struct fsg_lun *curlun = fsg_lun_from_dev(dev);
2604 struct rw_semaphore *filesem = dev_get_drvdata(dev);
2605
2606 return fsg_store_ro(curlun, filesem, buf, count);
2607}
2608
2609static ssize_t nofua_store(struct device *dev, struct device_attribute *attr,
2610 const char *buf, size_t count)
2611{
2612 struct fsg_lun *curlun = fsg_lun_from_dev(dev);
2613
2614 return fsg_store_nofua(curlun, buf, count);
2615}
2616
2617static ssize_t file_store(struct device *dev, struct device_attribute *attr,
2618 const char *buf, size_t count)
2619{
2620 struct fsg_lun *curlun = fsg_lun_from_dev(dev);
2621 struct rw_semaphore *filesem = dev_get_drvdata(dev);
2622
2623 return fsg_store_file(curlun, filesem, buf, count);
2624}
2625
2583static DEVICE_ATTR_RW(ro); 2626static DEVICE_ATTR_RW(ro);
2584static DEVICE_ATTR_RW(nofua); 2627static DEVICE_ATTR_RW(nofua);
2585static DEVICE_ATTR_RW(file); 2628static DEVICE_ATTR_RW(file);
@@ -2597,221 +2640,422 @@ static void fsg_lun_release(struct device *dev)
2597 /* Nothing needs to be done */ 2640 /* Nothing needs to be done */
2598} 2641}
2599 2642
2600static inline void fsg_common_get(struct fsg_common *common) 2643void fsg_common_get(struct fsg_common *common)
2601{ 2644{
2602 kref_get(&common->ref); 2645 kref_get(&common->ref);
2603} 2646}
2647EXPORT_SYMBOL_GPL(fsg_common_get);
2604 2648
2605static inline void fsg_common_put(struct fsg_common *common) 2649void fsg_common_put(struct fsg_common *common)
2606{ 2650{
2607 kref_put(&common->ref, fsg_common_release); 2651 kref_put(&common->ref, fsg_common_release);
2608} 2652}
2653EXPORT_SYMBOL_GPL(fsg_common_put);
2609 2654
2610static struct fsg_common *fsg_common_init(struct fsg_common *common, 2655/* check if fsg_num_buffers is within a valid range */
2611 struct usb_composite_dev *cdev, 2656static inline int fsg_num_buffers_validate(unsigned int fsg_num_buffers)
2612 struct fsg_config *cfg)
2613{ 2657{
2614 struct usb_gadget *gadget = cdev->gadget; 2658 if (fsg_num_buffers >= 2 && fsg_num_buffers <= 4)
2615 struct fsg_buffhd *bh; 2659 return 0;
2616 struct fsg_lun *curlun; 2660 pr_err("fsg_num_buffers %u is out of range (%d to %d)\n",
2617 struct fsg_lun_config *lcfg; 2661 fsg_num_buffers, 2, 4);
2618 int nluns, i, rc; 2662 return -EINVAL;
2619 char *pathbuf; 2663}
2620
2621 rc = fsg_num_buffers_validate();
2622 if (rc != 0)
2623 return ERR_PTR(rc);
2624
2625 /* Find out how many LUNs there should be */
2626 nluns = cfg->nluns;
2627 if (nluns < 1 || nluns > FSG_MAX_LUNS) {
2628 dev_err(&gadget->dev, "invalid number of LUNs: %u\n", nluns);
2629 return ERR_PTR(-EINVAL);
2630 }
2631 2664
2632 /* Allocate? */ 2665static struct fsg_common *fsg_common_setup(struct fsg_common *common)
2666{
2633 if (!common) { 2667 if (!common) {
2634 common = kzalloc(sizeof *common, GFP_KERNEL); 2668 common = kzalloc(sizeof(*common), GFP_KERNEL);
2635 if (!common) 2669 if (!common)
2636 return ERR_PTR(-ENOMEM); 2670 return ERR_PTR(-ENOMEM);
2637 common->free_storage_on_release = 1; 2671 common->free_storage_on_release = 1;
2638 } else { 2672 } else {
2639 memset(common, 0, sizeof *common);
2640 common->free_storage_on_release = 0; 2673 common->free_storage_on_release = 0;
2641 } 2674 }
2675 init_rwsem(&common->filesem);
2676 spin_lock_init(&common->lock);
2677 kref_init(&common->ref);
2678 init_completion(&common->thread_notifier);
2679 init_waitqueue_head(&common->fsg_wait);
2680 common->state = FSG_STATE_TERMINATED;
2642 2681
2643 common->buffhds = kcalloc(fsg_num_buffers, 2682 return common;
2644 sizeof *(common->buffhds), GFP_KERNEL); 2683}
2645 if (!common->buffhds) { 2684
2646 if (common->free_storage_on_release) 2685void fsg_common_set_sysfs(struct fsg_common *common, bool sysfs)
2647 kfree(common); 2686{
2648 return ERR_PTR(-ENOMEM); 2687 common->sysfs = sysfs;
2688}
2689EXPORT_SYMBOL_GPL(fsg_common_set_sysfs);
2690
2691static void _fsg_common_free_buffers(struct fsg_buffhd *buffhds, unsigned n)
2692{
2693 if (buffhds) {
2694 struct fsg_buffhd *bh = buffhds;
2695 while (n--) {
2696 kfree(bh->buf);
2697 ++bh;
2698 }
2699 kfree(buffhds);
2649 } 2700 }
2701}
2650 2702
2651 common->ops = cfg->ops; 2703int fsg_common_set_num_buffers(struct fsg_common *common, unsigned int n)
2652 common->private_data = cfg->private_data; 2704{
2705 struct fsg_buffhd *bh, *buffhds;
2706 int i, rc;
2653 2707
2654 common->gadget = gadget; 2708 rc = fsg_num_buffers_validate(n);
2655 common->ep0 = gadget->ep0; 2709 if (rc != 0)
2656 common->ep0req = cdev->req; 2710 return rc;
2657 common->cdev = cdev; 2711
2712 buffhds = kcalloc(n, sizeof(*buffhds), GFP_KERNEL);
2713 if (!buffhds)
2714 return -ENOMEM;
2658 2715
2659 /* Maybe allocate device-global string IDs, and patch descriptors */ 2716 /* Data buffers cyclic list */
2660 if (fsg_strings[FSG_STRING_INTERFACE].id == 0) { 2717 bh = buffhds;
2661 rc = usb_string_id(cdev); 2718 i = n;
2662 if (unlikely(rc < 0)) 2719 goto buffhds_first_it;
2720 do {
2721 bh->next = bh + 1;
2722 ++bh;
2723buffhds_first_it:
2724 bh->buf = kmalloc(FSG_BUFLEN, GFP_KERNEL);
2725 if (unlikely(!bh->buf))
2663 goto error_release; 2726 goto error_release;
2664 fsg_strings[FSG_STRING_INTERFACE].id = rc; 2727 } while (--i);
2665 fsg_intf_desc.iInterface = rc; 2728 bh->next = buffhds;
2666 }
2667 2729
2730 _fsg_common_free_buffers(common->buffhds, common->fsg_num_buffers);
2731 common->fsg_num_buffers = n;
2732 common->buffhds = buffhds;
2733
2734 return 0;
2735
2736error_release:
2668 /* 2737 /*
2669 * Create the LUNs, open their backing files, and register the 2738 * "buf"s pointed to by heads after n - i are NULL
2670 * LUN devices in sysfs. 2739 * so releasing them won't hurt
2671 */ 2740 */
2672 curlun = kcalloc(nluns, sizeof(*curlun), GFP_KERNEL); 2741 _fsg_common_free_buffers(buffhds, n);
2673 if (unlikely(!curlun)) { 2742
2674 rc = -ENOMEM; 2743 return -ENOMEM;
2675 goto error_release; 2744}
2745EXPORT_SYMBOL_GPL(fsg_common_set_num_buffers);
2746
2747static inline void fsg_common_remove_sysfs(struct fsg_lun *lun)
2748{
2749 device_remove_file(&lun->dev, &dev_attr_nofua);
2750 /*
2751 * device_remove_file() =>
2752 *
2753 * here the attr (e.g. dev_attr_ro) is only used to be passed to:
2754 *
2755 * sysfs_remove_file() =>
2756 *
2757 * here e.g. both dev_attr_ro_cdrom and dev_attr_ro are in
2758 * the same namespace and
2759 * from here only attr->name is passed to:
2760 *
2761 * sysfs_hash_and_remove()
2762 *
2763 * attr->name is the same for dev_attr_ro_cdrom and
2764 * dev_attr_ro
2765 * attr->name is the same for dev_attr_file and
2766 * dev_attr_file_nonremovable
2767 *
2768 * so we don't differentiate between removing e.g. dev_attr_ro_cdrom
2769 * and dev_attr_ro
2770 */
2771 device_remove_file(&lun->dev, &dev_attr_ro);
2772 device_remove_file(&lun->dev, &dev_attr_file);
2773}
2774
2775void fsg_common_remove_lun(struct fsg_lun *lun, bool sysfs)
2776{
2777 if (sysfs) {
2778 fsg_common_remove_sysfs(lun);
2779 device_unregister(&lun->dev);
2676 } 2780 }
2677 common->luns = curlun; 2781 fsg_lun_close(lun);
2782 kfree(lun);
2783}
2784EXPORT_SYMBOL_GPL(fsg_common_remove_lun);
2678 2785
2679 init_rwsem(&common->filesem); 2786static void _fsg_common_remove_luns(struct fsg_common *common, int n)
2787{
2788 int i;
2680 2789
2681 for (i = 0, lcfg = cfg->luns; i < nluns; ++i, ++curlun, ++lcfg) { 2790 for (i = 0; i < n; ++i)
2682 curlun->cdrom = !!lcfg->cdrom; 2791 if (common->luns[i]) {
2683 curlun->ro = lcfg->cdrom || lcfg->ro; 2792 fsg_common_remove_lun(common->luns[i], common->sysfs);
2684 curlun->initially_ro = curlun->ro; 2793 common->luns[i] = NULL;
2685 curlun->removable = lcfg->removable;
2686 curlun->dev.release = fsg_lun_release;
2687 curlun->dev.parent = &gadget->dev;
2688 /* curlun->dev.driver = &fsg_driver.driver; XXX */
2689 dev_set_drvdata(&curlun->dev, &common->filesem);
2690 dev_set_name(&curlun->dev, "lun%d", i);
2691
2692 rc = device_register(&curlun->dev);
2693 if (rc) {
2694 INFO(common, "failed to register LUN%d: %d\n", i, rc);
2695 common->nluns = i;
2696 put_device(&curlun->dev);
2697 goto error_release;
2698 } 2794 }
2795}
2796EXPORT_SYMBOL_GPL(fsg_common_remove_luns);
2699 2797
2700 rc = device_create_file(&curlun->dev, 2798void fsg_common_remove_luns(struct fsg_common *common)
2701 curlun->cdrom 2799{
2702 ? &dev_attr_ro_cdrom 2800 _fsg_common_remove_luns(common, common->nluns);
2703 : &dev_attr_ro); 2801}
2704 if (rc)
2705 goto error_luns;
2706 rc = device_create_file(&curlun->dev,
2707 curlun->removable
2708 ? &dev_attr_file
2709 : &dev_attr_file_nonremovable);
2710 if (rc)
2711 goto error_luns;
2712 rc = device_create_file(&curlun->dev, &dev_attr_nofua);
2713 if (rc)
2714 goto error_luns;
2715 2802
2716 if (lcfg->filename) { 2803void fsg_common_free_luns(struct fsg_common *common)
2717 rc = fsg_lun_open(curlun, lcfg->filename); 2804{
2718 if (rc) 2805 fsg_common_remove_luns(common);
2719 goto error_luns; 2806 kfree(common->luns);
2720 } else if (!curlun->removable) { 2807 common->luns = NULL;
2721 ERROR(common, "no file given for LUN%d\n", i); 2808}
2722 rc = -EINVAL; 2809EXPORT_SYMBOL_GPL(fsg_common_free_luns);
2723 goto error_luns; 2810
2724 } 2811int fsg_common_set_nluns(struct fsg_common *common, int nluns)
2812{
2813 struct fsg_lun **curlun;
2814
2815 /* Find out how many LUNs there should be */
2816 if (nluns < 1 || nluns > FSG_MAX_LUNS) {
2817 pr_err("invalid number of LUNs: %u\n", nluns);
2818 return -EINVAL;
2725 } 2819 }
2820
2821 curlun = kcalloc(nluns, sizeof(*curlun), GFP_KERNEL);
2822 if (unlikely(!curlun))
2823 return -ENOMEM;
2824
2825 if (common->luns)
2826 fsg_common_free_luns(common);
2827
2828 common->luns = curlun;
2726 common->nluns = nluns; 2829 common->nluns = nluns;
2727 2830
2728 /* Data buffers cyclic list */ 2831 pr_info("Number of LUNs=%d\n", common->nluns);
2729 bh = common->buffhds;
2730 i = fsg_num_buffers;
2731 goto buffhds_first_it;
2732 do {
2733 bh->next = bh + 1;
2734 ++bh;
2735buffhds_first_it:
2736 bh->buf = kmalloc(FSG_BUFLEN, GFP_KERNEL);
2737 if (unlikely(!bh->buf)) {
2738 rc = -ENOMEM;
2739 goto error_release;
2740 }
2741 } while (--i);
2742 bh->next = common->buffhds;
2743 2832
2744 /* Prepare inquiryString */ 2833 return 0;
2745 i = get_default_bcdDevice(); 2834}
2746 snprintf(common->inquiry_string, sizeof common->inquiry_string, 2835EXPORT_SYMBOL_GPL(fsg_common_set_nluns);
2747 "%-8s%-16s%04x", cfg->vendor_name ?: "Linux", 2836
2748 /* Assume product name dependent on the first LUN */ 2837void fsg_common_set_ops(struct fsg_common *common,
2749 cfg->product_name ?: (common->luns->cdrom 2838 const struct fsg_operations *ops)
2750 ? "File-CD Gadget" 2839{
2751 : "File-Stor Gadget"), 2840 common->ops = ops;
2752 i); 2841}
2842EXPORT_SYMBOL_GPL(fsg_common_set_ops);
2843
2844void fsg_common_free_buffers(struct fsg_common *common)
2845{
2846 _fsg_common_free_buffers(common->buffhds, common->fsg_num_buffers);
2847 common->buffhds = NULL;
2848}
2849EXPORT_SYMBOL_GPL(fsg_common_free_buffers);
2850
2851int fsg_common_set_cdev(struct fsg_common *common,
2852 struct usb_composite_dev *cdev, bool can_stall)
2853{
2854 struct usb_string *us;
2855
2856 common->gadget = cdev->gadget;
2857 common->ep0 = cdev->gadget->ep0;
2858 common->ep0req = cdev->req;
2859 common->cdev = cdev;
2860
2861 us = usb_gstrings_attach(cdev, fsg_strings_array,
2862 ARRAY_SIZE(fsg_strings));
2863 if (IS_ERR(us))
2864 return PTR_ERR(us);
2865
2866 fsg_intf_desc.iInterface = us[FSG_STRING_INTERFACE].id;
2753 2867
2754 /* 2868 /*
2755 * Some peripheral controllers are known not to be able to 2869 * Some peripheral controllers are known not to be able to
2756 * halt bulk endpoints correctly. If one of them is present, 2870 * halt bulk endpoints correctly. If one of them is present,
2757 * disable stalls. 2871 * disable stalls.
2758 */ 2872 */
2759 common->can_stall = cfg->can_stall && 2873 common->can_stall = can_stall && !(gadget_is_at91(common->gadget));
2760 !(gadget_is_at91(common->gadget));
2761 2874
2762 spin_lock_init(&common->lock); 2875 return 0;
2763 kref_init(&common->ref); 2876}
2877EXPORT_SYMBOL_GPL(fsg_common_set_cdev);
2764 2878
2765 /* Tell the thread to start working */ 2879static inline int fsg_common_add_sysfs(struct fsg_common *common,
2766 common->thread_task = 2880 struct fsg_lun *lun)
2767 kthread_create(fsg_main_thread, common, "file-storage"); 2881{
2768 if (IS_ERR(common->thread_task)) { 2882 int rc;
2769 rc = PTR_ERR(common->thread_task); 2883
2770 goto error_release; 2884 rc = device_register(&lun->dev);
2885 if (rc) {
2886 put_device(&lun->dev);
2887 return rc;
2771 } 2888 }
2772 init_completion(&common->thread_notifier);
2773 init_waitqueue_head(&common->fsg_wait);
2774 2889
2775 /* Information */ 2890 rc = device_create_file(&lun->dev,
2776 INFO(common, FSG_DRIVER_DESC ", version: " FSG_DRIVER_VERSION "\n"); 2891 lun->cdrom
2777 INFO(common, "Number of LUNs=%d\n", common->nluns); 2892 ? &dev_attr_ro_cdrom
2893 : &dev_attr_ro);
2894 if (rc)
2895 goto error;
2896 rc = device_create_file(&lun->dev,
2897 lun->removable
2898 ? &dev_attr_file
2899 : &dev_attr_file_nonremovable);
2900 if (rc)
2901 goto error;
2902 rc = device_create_file(&lun->dev, &dev_attr_nofua);
2903 if (rc)
2904 goto error;
2905
2906 return 0;
2907
2908error:
2909 /* removing nonexistent files is a no-op */
2910 fsg_common_remove_sysfs(lun);
2911 device_unregister(&lun->dev);
2912 return rc;
2913}
2914
2915int fsg_common_create_lun(struct fsg_common *common, struct fsg_lun_config *cfg,
2916 unsigned int id, const char *name,
2917 const char **name_pfx)
2918{
2919 struct fsg_lun *lun;
2920 char *pathbuf, *p;
2921 int rc = -ENOMEM;
2922
2923 if (!common->nluns || !common->luns)
2924 return -ENODEV;
2925
2926 if (common->luns[id])
2927 return -EBUSY;
2928
2929 if (!cfg->filename && !cfg->removable) {
2930 pr_err("no file given for LUN%d\n", id);
2931 return -EINVAL;
2932 }
2933
2934 lun = kzalloc(sizeof(*lun), GFP_KERNEL);
2935 if (!lun)
2936 return -ENOMEM;
2937
2938 lun->name_pfx = name_pfx;
2939
2940 lun->cdrom = !!cfg->cdrom;
2941 lun->ro = cfg->cdrom || cfg->ro;
2942 lun->initially_ro = lun->ro;
2943 lun->removable = !!cfg->removable;
2944
2945 if (!common->sysfs) {
2946 /* we DON'T own the name!*/
2947 lun->name = name;
2948 } else {
2949 lun->dev.release = fsg_lun_release;
2950 lun->dev.parent = &common->gadget->dev;
2951 dev_set_drvdata(&lun->dev, &common->filesem);
2952 dev_set_name(&lun->dev, "%s", name);
2953 lun->name = dev_name(&lun->dev);
2954
2955 rc = fsg_common_add_sysfs(common, lun);
2956 if (rc) {
2957 pr_info("failed to register LUN%d: %d\n", id, rc);
2958 goto error_sysfs;
2959 }
2960 }
2961
2962 common->luns[id] = lun;
2963
2964 if (cfg->filename) {
2965 rc = fsg_lun_open(lun, cfg->filename);
2966 if (rc)
2967 goto error_lun;
2968 }
2778 2969
2779 pathbuf = kmalloc(PATH_MAX, GFP_KERNEL); 2970 pathbuf = kmalloc(PATH_MAX, GFP_KERNEL);
2780 for (i = 0, nluns = common->nluns, curlun = common->luns; 2971 p = "(no medium)";
2781 i < nluns; 2972 if (fsg_lun_is_open(lun)) {
2782 ++curlun, ++i) { 2973 p = "(error)";
2783 char *p = "(no medium)"; 2974 if (pathbuf) {
2784 if (fsg_lun_is_open(curlun)) { 2975 p = d_path(&lun->filp->f_path, pathbuf, PATH_MAX);
2785 p = "(error)"; 2976 if (IS_ERR(p))
2786 if (pathbuf) { 2977 p = "(error)";
2787 p = d_path(&curlun->filp->f_path,
2788 pathbuf, PATH_MAX);
2789 if (IS_ERR(p))
2790 p = "(error)";
2791 }
2792 } 2978 }
2793 LINFO(curlun, "LUN: %s%s%sfile: %s\n",
2794 curlun->removable ? "removable " : "",
2795 curlun->ro ? "read only " : "",
2796 curlun->cdrom ? "CD-ROM " : "",
2797 p);
2798 } 2979 }
2980 pr_info("LUN: %s%s%sfile: %s\n",
2981 lun->removable ? "removable " : "",
2982 lun->ro ? "read only " : "",
2983 lun->cdrom ? "CD-ROM " : "",
2984 p);
2799 kfree(pathbuf); 2985 kfree(pathbuf);
2800 2986
2987 return 0;
2988
2989error_lun:
2990 if (common->sysfs) {
2991 fsg_common_remove_sysfs(lun);
2992 device_unregister(&lun->dev);
2993 }
2994 fsg_lun_close(lun);
2995 common->luns[id] = NULL;
2996error_sysfs:
2997 kfree(lun);
2998 return rc;
2999}
3000EXPORT_SYMBOL_GPL(fsg_common_create_lun);
3001
3002int fsg_common_create_luns(struct fsg_common *common, struct fsg_config *cfg)
3003{
3004 char buf[8]; /* enough for 100000000 different numbers, decimal */
3005 int i, rc;
3006
3007 for (i = 0; i < common->nluns; ++i) {
3008 snprintf(buf, sizeof(buf), "lun%d", i);
3009 rc = fsg_common_create_lun(common, &cfg->luns[i], i, buf, NULL);
3010 if (rc)
3011 goto fail;
3012 }
3013
3014 pr_info("Number of LUNs=%d\n", common->nluns);
3015
3016 return 0;
3017
3018fail:
3019 _fsg_common_remove_luns(common, i);
3020 return rc;
3021}
3022EXPORT_SYMBOL_GPL(fsg_common_create_luns);
3023
3024void fsg_common_set_inquiry_string(struct fsg_common *common, const char *vn,
3025 const char *pn)
3026{
3027 int i;
3028
3029 /* Prepare inquiryString */
3030 i = get_default_bcdDevice();
3031 snprintf(common->inquiry_string, sizeof(common->inquiry_string),
3032 "%-8s%-16s%04x", vn ?: "Linux",
3033 /* Assume product name dependent on the first LUN */
3034 pn ?: ((*common->luns)->cdrom
3035 ? "File-CD Gadget"
3036 : "File-Stor Gadget"),
3037 i);
3038}
3039EXPORT_SYMBOL_GPL(fsg_common_set_inquiry_string);
3040
3041int fsg_common_run_thread(struct fsg_common *common)
3042{
3043 common->state = FSG_STATE_IDLE;
3044 /* Tell the thread to start working */
3045 common->thread_task =
3046 kthread_create(fsg_main_thread, common, "file-storage");
3047 if (IS_ERR(common->thread_task)) {
3048 common->state = FSG_STATE_TERMINATED;
3049 return PTR_ERR(common->thread_task);
3050 }
3051
2801 DBG(common, "I/O thread pid: %d\n", task_pid_nr(common->thread_task)); 3052 DBG(common, "I/O thread pid: %d\n", task_pid_nr(common->thread_task));
2802 3053
2803 wake_up_process(common->thread_task); 3054 wake_up_process(common->thread_task);
2804 3055
2805 return common; 3056 return 0;
2806
2807error_luns:
2808 common->nluns = i + 1;
2809error_release:
2810 common->state = FSG_STATE_TERMINATED; /* The thread is dead */
2811 /* Call fsg_common_release() directly, ref might be not initialised. */
2812 fsg_common_release(&common->ref);
2813 return ERR_PTR(rc);
2814} 3057}
3058EXPORT_SYMBOL_GPL(fsg_common_run_thread);
2815 3059
2816static void fsg_common_release(struct kref *ref) 3060static void fsg_common_release(struct kref *ref)
2817{ 3061{
@@ -2824,36 +3068,26 @@ static void fsg_common_release(struct kref *ref)
2824 } 3068 }
2825 3069
2826 if (likely(common->luns)) { 3070 if (likely(common->luns)) {
2827 struct fsg_lun *lun = common->luns; 3071 struct fsg_lun **lun_it = common->luns;
2828 unsigned i = common->nluns; 3072 unsigned i = common->nluns;
2829 3073
2830 /* In error recovery common->nluns may be zero. */ 3074 /* In error recovery common->nluns may be zero. */
2831 for (; i; --i, ++lun) { 3075 for (; i; --i, ++lun_it) {
2832 device_remove_file(&lun->dev, &dev_attr_nofua); 3076 struct fsg_lun *lun = *lun_it;
2833 device_remove_file(&lun->dev, 3077 if (!lun)
2834 lun->cdrom 3078 continue;
2835 ? &dev_attr_ro_cdrom 3079 if (common->sysfs)
2836 : &dev_attr_ro); 3080 fsg_common_remove_sysfs(lun);
2837 device_remove_file(&lun->dev,
2838 lun->removable
2839 ? &dev_attr_file
2840 : &dev_attr_file_nonremovable);
2841 fsg_lun_close(lun); 3081 fsg_lun_close(lun);
2842 device_unregister(&lun->dev); 3082 if (common->sysfs)
3083 device_unregister(&lun->dev);
3084 kfree(lun);
2843 } 3085 }
2844 3086
2845 kfree(common->luns); 3087 kfree(common->luns);
2846 } 3088 }
2847 3089
2848 { 3090 _fsg_common_free_buffers(common->buffhds, common->fsg_num_buffers);
2849 struct fsg_buffhd *bh = common->buffhds;
2850 unsigned i = fsg_num_buffers;
2851 do {
2852 kfree(bh->buf);
2853 } while (++bh, --i);
2854 }
2855
2856 kfree(common->buffhds);
2857 if (common->free_storage_on_release) 3091 if (common->free_storage_on_release)
2858 kfree(common); 3092 kfree(common);
2859} 3093}
@@ -2861,24 +3095,6 @@ static void fsg_common_release(struct kref *ref)
2861 3095
2862/*-------------------------------------------------------------------------*/ 3096/*-------------------------------------------------------------------------*/
2863 3097
2864static void fsg_unbind(struct usb_configuration *c, struct usb_function *f)
2865{
2866 struct fsg_dev *fsg = fsg_from_func(f);
2867 struct fsg_common *common = fsg->common;
2868
2869 DBG(fsg, "unbind\n");
2870 if (fsg->common->fsg == fsg) {
2871 fsg->common->new_fsg = NULL;
2872 raise_exception(fsg->common, FSG_STATE_CONFIG_CHANGE);
2873 /* FIXME: make interruptible or killable somehow? */
2874 wait_event(common->fsg_wait, common->fsg != fsg);
2875 }
2876
2877 fsg_common_put(common);
2878 usb_free_all_descriptors(&fsg->function);
2879 kfree(fsg);
2880}
2881
2882static int fsg_bind(struct usb_configuration *c, struct usb_function *f) 3098static int fsg_bind(struct usb_configuration *c, struct usb_function *f)
2883{ 3099{
2884 struct fsg_dev *fsg = fsg_from_func(f); 3100 struct fsg_dev *fsg = fsg_from_func(f);
@@ -2887,6 +3103,19 @@ static int fsg_bind(struct usb_configuration *c, struct usb_function *f)
2887 struct usb_ep *ep; 3103 struct usb_ep *ep;
2888 unsigned max_burst; 3104 unsigned max_burst;
2889 int ret; 3105 int ret;
3106 struct fsg_opts *opts;
3107
3108 opts = fsg_opts_from_func_inst(f->fi);
3109 if (!opts->no_configfs) {
3110 ret = fsg_common_set_cdev(fsg->common, c->cdev,
3111 fsg->common->can_stall);
3112 if (ret)
3113 return ret;
3114 fsg_common_set_inquiry_string(fsg->common, 0, 0);
3115 ret = fsg_common_run_thread(fsg->common);
3116 if (ret)
3117 return ret;
3118 }
2890 3119
2891 fsg->gadget = gadget; 3120 fsg->gadget = gadget;
2892 3121
@@ -2939,95 +3168,472 @@ autoconf_fail:
2939 return -ENOTSUPP; 3168 return -ENOTSUPP;
2940} 3169}
2941 3170
2942/****************************** ADD FUNCTION ******************************/ 3171/****************************** ALLOCATE FUNCTION *************************/
2943 3172
2944static struct usb_gadget_strings *fsg_strings_array[] = { 3173static void fsg_unbind(struct usb_configuration *c, struct usb_function *f)
2945 &fsg_stringtab, 3174{
3175 struct fsg_dev *fsg = fsg_from_func(f);
3176 struct fsg_common *common = fsg->common;
3177
3178 DBG(fsg, "unbind\n");
3179 if (fsg->common->fsg == fsg) {
3180 fsg->common->new_fsg = NULL;
3181 raise_exception(fsg->common, FSG_STATE_CONFIG_CHANGE);
3182 /* FIXME: make interruptible or killable somehow? */
3183 wait_event(common->fsg_wait, common->fsg != fsg);
3184 }
3185
3186 usb_free_all_descriptors(&fsg->function);
3187}
3188
3189static inline struct fsg_lun_opts *to_fsg_lun_opts(struct config_item *item)
3190{
3191 return container_of(to_config_group(item), struct fsg_lun_opts, group);
3192}
3193
3194static inline struct fsg_opts *to_fsg_opts(struct config_item *item)
3195{
3196 return container_of(to_config_group(item), struct fsg_opts,
3197 func_inst.group);
3198}
3199
3200CONFIGFS_ATTR_STRUCT(fsg_lun_opts);
3201CONFIGFS_ATTR_OPS(fsg_lun_opts);
3202
3203static void fsg_lun_attr_release(struct config_item *item)
3204{
3205 struct fsg_lun_opts *lun_opts;
3206
3207 lun_opts = to_fsg_lun_opts(item);
3208 kfree(lun_opts);
3209}
3210
3211static struct configfs_item_operations fsg_lun_item_ops = {
3212 .release = fsg_lun_attr_release,
3213 .show_attribute = fsg_lun_opts_attr_show,
3214 .store_attribute = fsg_lun_opts_attr_store,
3215};
3216
3217static ssize_t fsg_lun_opts_file_show(struct fsg_lun_opts *opts, char *page)
3218{
3219 struct fsg_opts *fsg_opts;
3220
3221 fsg_opts = to_fsg_opts(opts->group.cg_item.ci_parent);
3222
3223 return fsg_show_file(opts->lun, &fsg_opts->common->filesem, page);
3224}
3225
3226static ssize_t fsg_lun_opts_file_store(struct fsg_lun_opts *opts,
3227 const char *page, size_t len)
3228{
3229 struct fsg_opts *fsg_opts;
3230
3231 fsg_opts = to_fsg_opts(opts->group.cg_item.ci_parent);
3232
3233 return fsg_store_file(opts->lun, &fsg_opts->common->filesem, page, len);
3234}
3235
3236static struct fsg_lun_opts_attribute fsg_lun_opts_file =
3237 __CONFIGFS_ATTR(file, S_IRUGO | S_IWUSR, fsg_lun_opts_file_show,
3238 fsg_lun_opts_file_store);
3239
3240static ssize_t fsg_lun_opts_ro_show(struct fsg_lun_opts *opts, char *page)
3241{
3242 return fsg_show_ro(opts->lun, page);
3243}
3244
3245static ssize_t fsg_lun_opts_ro_store(struct fsg_lun_opts *opts,
3246 const char *page, size_t len)
3247{
3248 struct fsg_opts *fsg_opts;
3249
3250 fsg_opts = to_fsg_opts(opts->group.cg_item.ci_parent);
3251
3252 return fsg_store_ro(opts->lun, &fsg_opts->common->filesem, page, len);
3253}
3254
3255static struct fsg_lun_opts_attribute fsg_lun_opts_ro =
3256 __CONFIGFS_ATTR(ro, S_IRUGO | S_IWUSR, fsg_lun_opts_ro_show,
3257 fsg_lun_opts_ro_store);
3258
3259static ssize_t fsg_lun_opts_removable_show(struct fsg_lun_opts *opts,
3260 char *page)
3261{
3262 return fsg_show_removable(opts->lun, page);
3263}
3264
3265static ssize_t fsg_lun_opts_removable_store(struct fsg_lun_opts *opts,
3266 const char *page, size_t len)
3267{
3268 return fsg_store_removable(opts->lun, page, len);
3269}
3270
3271static struct fsg_lun_opts_attribute fsg_lun_opts_removable =
3272 __CONFIGFS_ATTR(removable, S_IRUGO | S_IWUSR,
3273 fsg_lun_opts_removable_show,
3274 fsg_lun_opts_removable_store);
3275
3276static ssize_t fsg_lun_opts_cdrom_show(struct fsg_lun_opts *opts, char *page)
3277{
3278 return fsg_show_cdrom(opts->lun, page);
3279}
3280
3281static ssize_t fsg_lun_opts_cdrom_store(struct fsg_lun_opts *opts,
3282 const char *page, size_t len)
3283{
3284 struct fsg_opts *fsg_opts;
3285
3286 fsg_opts = to_fsg_opts(opts->group.cg_item.ci_parent);
3287
3288 return fsg_store_cdrom(opts->lun, &fsg_opts->common->filesem, page,
3289 len);
3290}
3291
3292static struct fsg_lun_opts_attribute fsg_lun_opts_cdrom =
3293 __CONFIGFS_ATTR(cdrom, S_IRUGO | S_IWUSR, fsg_lun_opts_cdrom_show,
3294 fsg_lun_opts_cdrom_store);
3295
3296static ssize_t fsg_lun_opts_nofua_show(struct fsg_lun_opts *opts, char *page)
3297{
3298 return fsg_show_nofua(opts->lun, page);
3299}
3300
3301static ssize_t fsg_lun_opts_nofua_store(struct fsg_lun_opts *opts,
3302 const char *page, size_t len)
3303{
3304 return fsg_store_nofua(opts->lun, page, len);
3305}
3306
3307static struct fsg_lun_opts_attribute fsg_lun_opts_nofua =
3308 __CONFIGFS_ATTR(nofua, S_IRUGO | S_IWUSR, fsg_lun_opts_nofua_show,
3309 fsg_lun_opts_nofua_store);
3310
3311static struct configfs_attribute *fsg_lun_attrs[] = {
3312 &fsg_lun_opts_file.attr,
3313 &fsg_lun_opts_ro.attr,
3314 &fsg_lun_opts_removable.attr,
3315 &fsg_lun_opts_cdrom.attr,
3316 &fsg_lun_opts_nofua.attr,
2946 NULL, 3317 NULL,
2947}; 3318};
2948 3319
2949static int fsg_bind_config(struct usb_composite_dev *cdev, 3320static struct config_item_type fsg_lun_type = {
2950 struct usb_configuration *c, 3321 .ct_item_ops = &fsg_lun_item_ops,
2951 struct fsg_common *common) 3322 .ct_attrs = fsg_lun_attrs,
3323 .ct_owner = THIS_MODULE,
3324};
3325
3326static struct config_group *fsg_lun_make(struct config_group *group,
3327 const char *name)
2952{ 3328{
2953 struct fsg_dev *fsg; 3329 struct fsg_lun_opts *opts;
3330 struct fsg_opts *fsg_opts;
3331 struct fsg_lun_config config;
3332 char *num_str;
3333 u8 num;
3334 int ret;
3335
3336 num_str = strchr(name, '.');
3337 if (!num_str) {
3338 pr_err("Unable to locate . in LUN.NUMBER\n");
3339 return ERR_PTR(-EINVAL);
3340 }
3341 num_str++;
3342
3343 ret = kstrtou8(num_str, 0, &num);
3344 if (ret)
3345 return ERR_PTR(ret);
3346
3347 fsg_opts = to_fsg_opts(&group->cg_item);
3348 if (num >= FSG_MAX_LUNS)
3349 return ERR_PTR(-ERANGE);
3350
3351 mutex_lock(&fsg_opts->lock);
3352 if (fsg_opts->refcnt || fsg_opts->common->luns[num]) {
3353 ret = -EBUSY;
3354 goto out;
3355 }
3356
3357 opts = kzalloc(sizeof(*opts), GFP_KERNEL);
3358 if (!opts) {
3359 ret = -ENOMEM;
3360 goto out;
3361 }
3362
3363 memset(&config, 0, sizeof(config));
3364 config.removable = true;
3365
3366 ret = fsg_common_create_lun(fsg_opts->common, &config, num, name,
3367 (const char **)&group->cg_item.ci_name);
3368 if (ret) {
3369 kfree(opts);
3370 goto out;
3371 }
3372 opts->lun = fsg_opts->common->luns[num];
3373 opts->lun_id = num;
3374 mutex_unlock(&fsg_opts->lock);
3375
3376 config_group_init_type_name(&opts->group, name, &fsg_lun_type);
3377
3378 return &opts->group;
3379out:
3380 mutex_unlock(&fsg_opts->lock);
3381 return ERR_PTR(ret);
3382}
3383
3384static void fsg_lun_drop(struct config_group *group, struct config_item *item)
3385{
3386 struct fsg_lun_opts *lun_opts;
3387 struct fsg_opts *fsg_opts;
3388
3389 lun_opts = to_fsg_lun_opts(item);
3390 fsg_opts = to_fsg_opts(&group->cg_item);
3391
3392 mutex_lock(&fsg_opts->lock);
3393 if (fsg_opts->refcnt) {
3394 struct config_item *gadget;
3395
3396 gadget = group->cg_item.ci_parent->ci_parent;
3397 unregister_gadget_item(gadget);
3398 }
3399
3400 fsg_common_remove_lun(lun_opts->lun, fsg_opts->common->sysfs);
3401 fsg_opts->common->luns[lun_opts->lun_id] = NULL;
3402 lun_opts->lun_id = 0;
3403 mutex_unlock(&fsg_opts->lock);
3404
3405 config_item_put(item);
3406}
3407
3408CONFIGFS_ATTR_STRUCT(fsg_opts);
3409CONFIGFS_ATTR_OPS(fsg_opts);
3410
3411static void fsg_attr_release(struct config_item *item)
3412{
3413 struct fsg_opts *opts = to_fsg_opts(item);
3414
3415 usb_put_function_instance(&opts->func_inst);
3416}
3417
3418static struct configfs_item_operations fsg_item_ops = {
3419 .release = fsg_attr_release,
3420 .show_attribute = fsg_opts_attr_show,
3421 .store_attribute = fsg_opts_attr_store,
3422};
3423
3424static ssize_t fsg_opts_stall_show(struct fsg_opts *opts, char *page)
3425{
3426 int result;
3427
3428 mutex_lock(&opts->lock);
3429 result = sprintf(page, "%d", opts->common->can_stall);
3430 mutex_unlock(&opts->lock);
3431
3432 return result;
3433}
3434
3435static ssize_t fsg_opts_stall_store(struct fsg_opts *opts, const char *page,
3436 size_t len)
3437{
3438 int ret;
3439 bool stall;
3440
3441 mutex_lock(&opts->lock);
3442
3443 if (opts->refcnt) {
3444 mutex_unlock(&opts->lock);
3445 return -EBUSY;
3446 }
3447
3448 ret = strtobool(page, &stall);
3449 if (!ret) {
3450 opts->common->can_stall = stall;
3451 ret = len;
3452 }
3453
3454 mutex_unlock(&opts->lock);
3455
3456 return ret;
3457}
3458
3459static struct fsg_opts_attribute fsg_opts_stall =
3460 __CONFIGFS_ATTR(stall, S_IRUGO | S_IWUSR, fsg_opts_stall_show,
3461 fsg_opts_stall_store);
3462
3463#ifdef CONFIG_USB_GADGET_DEBUG_FILES
3464static ssize_t fsg_opts_num_buffers_show(struct fsg_opts *opts, char *page)
3465{
3466 int result;
3467
3468 mutex_lock(&opts->lock);
3469 result = sprintf(page, "%d", opts->common->fsg_num_buffers);
3470 mutex_unlock(&opts->lock);
3471
3472 return result;
3473}
3474
3475static ssize_t fsg_opts_num_buffers_store(struct fsg_opts *opts,
3476 const char *page, size_t len)
3477{
3478 int ret;
3479 u8 num;
3480
3481 mutex_lock(&opts->lock);
3482 if (opts->refcnt) {
3483 ret = -EBUSY;
3484 goto end;
3485 }
3486 ret = kstrtou8(page, 0, &num);
3487 if (ret)
3488 goto end;
3489
3490 ret = fsg_num_buffers_validate(num);
3491 if (ret)
3492 goto end;
3493
3494 fsg_common_set_num_buffers(opts->common, num);
3495 ret = len;
3496
3497end:
3498 mutex_unlock(&opts->lock);
3499 return ret;
3500}
3501
3502static struct fsg_opts_attribute fsg_opts_num_buffers =
3503 __CONFIGFS_ATTR(num_buffers, S_IRUGO | S_IWUSR,
3504 fsg_opts_num_buffers_show,
3505 fsg_opts_num_buffers_store);
3506
3507#endif
3508
3509static struct configfs_attribute *fsg_attrs[] = {
3510 &fsg_opts_stall.attr,
3511#ifdef CONFIG_USB_GADGET_DEBUG_FILES
3512 &fsg_opts_num_buffers.attr,
3513#endif
3514 NULL,
3515};
3516
3517static struct configfs_group_operations fsg_group_ops = {
3518 .make_group = fsg_lun_make,
3519 .drop_item = fsg_lun_drop,
3520};
3521
3522static struct config_item_type fsg_func_type = {
3523 .ct_item_ops = &fsg_item_ops,
3524 .ct_group_ops = &fsg_group_ops,
3525 .ct_attrs = fsg_attrs,
3526 .ct_owner = THIS_MODULE,
3527};
3528
3529static void fsg_free_inst(struct usb_function_instance *fi)
3530{
3531 struct fsg_opts *opts;
3532
3533 opts = fsg_opts_from_func_inst(fi);
3534 fsg_common_put(opts->common);
3535 kfree(opts);
3536}
3537
3538static struct usb_function_instance *fsg_alloc_inst(void)
3539{
3540 struct fsg_opts *opts;
3541 struct fsg_lun_config config;
2954 int rc; 3542 int rc;
2955 3543
2956 fsg = kzalloc(sizeof *fsg, GFP_KERNEL); 3544 opts = kzalloc(sizeof(*opts), GFP_KERNEL);
3545 if (!opts)
3546 return ERR_PTR(-ENOMEM);
3547 mutex_init(&opts->lock);
3548 opts->func_inst.free_func_inst = fsg_free_inst;
3549 opts->common = fsg_common_setup(opts->common);
3550 if (IS_ERR(opts->common)) {
3551 rc = PTR_ERR(opts->common);
3552 goto release_opts;
3553 }
3554 rc = fsg_common_set_nluns(opts->common, FSG_MAX_LUNS);
3555 if (rc)
3556 goto release_opts;
3557
3558 rc = fsg_common_set_num_buffers(opts->common,
3559 CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS);
3560 if (rc)
3561 goto release_luns;
3562
3563 pr_info(FSG_DRIVER_DESC ", version: " FSG_DRIVER_VERSION "\n");
3564
3565 memset(&config, 0, sizeof(config));
3566 config.removable = true;
3567 rc = fsg_common_create_lun(opts->common, &config, 0, "lun.0",
3568 (const char **)&opts->func_inst.group.cg_item.ci_name);
3569 opts->lun0.lun = opts->common->luns[0];
3570 opts->lun0.lun_id = 0;
3571 config_group_init_type_name(&opts->lun0.group, "lun.0", &fsg_lun_type);
3572 opts->default_groups[0] = &opts->lun0.group;
3573 opts->func_inst.group.default_groups = opts->default_groups;
3574
3575 config_group_init_type_name(&opts->func_inst.group, "", &fsg_func_type);
3576
3577 return &opts->func_inst;
3578
3579release_luns:
3580 kfree(opts->common->luns);
3581release_opts:
3582 kfree(opts);
3583 return ERR_PTR(rc);
3584}
3585
3586static void fsg_free(struct usb_function *f)
3587{
3588 struct fsg_dev *fsg;
3589 struct fsg_opts *opts;
3590
3591 fsg = container_of(f, struct fsg_dev, function);
3592 opts = container_of(f->fi, struct fsg_opts, func_inst);
3593
3594 mutex_lock(&opts->lock);
3595 opts->refcnt--;
3596 mutex_unlock(&opts->lock);
3597
3598 kfree(fsg);
3599}
3600
3601static struct usb_function *fsg_alloc(struct usb_function_instance *fi)
3602{
3603 struct fsg_opts *opts = fsg_opts_from_func_inst(fi);
3604 struct fsg_common *common = opts->common;
3605 struct fsg_dev *fsg;
3606
3607 fsg = kzalloc(sizeof(*fsg), GFP_KERNEL);
2957 if (unlikely(!fsg)) 3608 if (unlikely(!fsg))
2958 return -ENOMEM; 3609 return ERR_PTR(-ENOMEM);
2959 3610
2960 fsg->function.name = FSG_DRIVER_DESC; 3611 mutex_lock(&opts->lock);
2961 fsg->function.strings = fsg_strings_array; 3612 opts->refcnt++;
2962 fsg->function.bind = fsg_bind; 3613 mutex_unlock(&opts->lock);
2963 fsg->function.unbind = fsg_unbind; 3614 fsg->function.name = FSG_DRIVER_DESC;
2964 fsg->function.setup = fsg_setup; 3615 fsg->function.bind = fsg_bind;
2965 fsg->function.set_alt = fsg_set_alt; 3616 fsg->function.unbind = fsg_unbind;
2966 fsg->function.disable = fsg_disable; 3617 fsg->function.setup = fsg_setup;
3618 fsg->function.set_alt = fsg_set_alt;
3619 fsg->function.disable = fsg_disable;
3620 fsg->function.free_func = fsg_free;
2967 3621
2968 fsg->common = common; 3622 fsg->common = common;
2969 /*
2970 * Our caller holds a reference to common structure so we
2971 * don't have to be worry about it being freed until we return
2972 * from this function. So instead of incrementing counter now
2973 * and decrement in error recovery we increment it only when
2974 * call to usb_add_function() was successful.
2975 */
2976 3623
2977 rc = usb_add_function(c, &fsg->function); 3624 return &fsg->function;
2978 if (unlikely(rc))
2979 kfree(fsg);
2980 else
2981 fsg_common_get(fsg->common);
2982 return rc;
2983} 3625}
2984 3626
3627DECLARE_USB_FUNCTION_INIT(mass_storage, fsg_alloc_inst, fsg_alloc);
3628MODULE_LICENSE("GPL");
3629MODULE_AUTHOR("Michal Nazarewicz");
2985 3630
2986/************************* Module parameters *************************/ 3631/************************* Module parameters *************************/
2987 3632
2988struct fsg_module_parameters {
2989 char *file[FSG_MAX_LUNS];
2990 bool ro[FSG_MAX_LUNS];
2991 bool removable[FSG_MAX_LUNS];
2992 bool cdrom[FSG_MAX_LUNS];
2993 bool nofua[FSG_MAX_LUNS];
2994
2995 unsigned int file_count, ro_count, removable_count, cdrom_count;
2996 unsigned int nofua_count;
2997 unsigned int luns; /* nluns */
2998 bool stall; /* can_stall */
2999};
3000 3633
3001#define _FSG_MODULE_PARAM_ARRAY(prefix, params, name, type, desc) \ 3634void fsg_config_from_params(struct fsg_config *cfg,
3002 module_param_array_named(prefix ## name, params.name, type, \ 3635 const struct fsg_module_parameters *params,
3003 &prefix ## params.name ## _count, \ 3636 unsigned int fsg_num_buffers)
3004 S_IRUGO); \
3005 MODULE_PARM_DESC(prefix ## name, desc)
3006
3007#define _FSG_MODULE_PARAM(prefix, params, name, type, desc) \
3008 module_param_named(prefix ## name, params.name, type, \
3009 S_IRUGO); \
3010 MODULE_PARM_DESC(prefix ## name, desc)
3011
3012#define FSG_MODULE_PARAMETERS(prefix, params) \
3013 _FSG_MODULE_PARAM_ARRAY(prefix, params, file, charp, \
3014 "names of backing files or devices"); \
3015 _FSG_MODULE_PARAM_ARRAY(prefix, params, ro, bool, \
3016 "true to force read-only"); \
3017 _FSG_MODULE_PARAM_ARRAY(prefix, params, removable, bool, \
3018 "true to simulate removable media"); \
3019 _FSG_MODULE_PARAM_ARRAY(prefix, params, cdrom, bool, \
3020 "true to simulate CD-ROM instead of disk"); \
3021 _FSG_MODULE_PARAM_ARRAY(prefix, params, nofua, bool, \
3022 "true to ignore SCSI WRITE(10,12) FUA bit"); \
3023 _FSG_MODULE_PARAM(prefix, params, luns, uint, \
3024 "number of LUNs"); \
3025 _FSG_MODULE_PARAM(prefix, params, stall, bool, \
3026 "false to prevent bulk stalls")
3027
3028static void
3029fsg_config_from_params(struct fsg_config *cfg,
3030 const struct fsg_module_parameters *params)
3031{ 3637{
3032 struct fsg_lun_config *lun; 3638 struct fsg_lun_config *lun;
3033 unsigned i; 3639 unsigned i;
@@ -3055,19 +3661,7 @@ fsg_config_from_params(struct fsg_config *cfg,
3055 3661
3056 /* Finalise */ 3662 /* Finalise */
3057 cfg->can_stall = params->stall; 3663 cfg->can_stall = params->stall;
3664 cfg->fsg_num_buffers = fsg_num_buffers;
3058} 3665}
3666EXPORT_SYMBOL_GPL(fsg_config_from_params);
3059 3667
3060static inline struct fsg_common *
3061fsg_common_from_params(struct fsg_common *common,
3062 struct usb_composite_dev *cdev,
3063 const struct fsg_module_parameters *params)
3064 __attribute__((unused));
3065static inline struct fsg_common *
3066fsg_common_from_params(struct fsg_common *common,
3067 struct usb_composite_dev *cdev,
3068 const struct fsg_module_parameters *params)
3069{
3070 struct fsg_config cfg;
3071 fsg_config_from_params(&cfg, params);
3072 return fsg_common_init(common, cdev, &cfg);
3073}
diff --git a/drivers/usb/gadget/f_mass_storage.h b/drivers/usb/gadget/f_mass_storage.h
new file mode 100644
index 000000000000..b4866fcef30b
--- /dev/null
+++ b/drivers/usb/gadget/f_mass_storage.h
@@ -0,0 +1,166 @@
1#ifndef USB_F_MASS_STORAGE_H
2#define USB_F_MASS_STORAGE_H
3
4#include <linux/usb/composite.h>
5#include "storage_common.h"
6
7struct fsg_module_parameters {
8 char *file[FSG_MAX_LUNS];
9 bool ro[FSG_MAX_LUNS];
10 bool removable[FSG_MAX_LUNS];
11 bool cdrom[FSG_MAX_LUNS];
12 bool nofua[FSG_MAX_LUNS];
13
14 unsigned int file_count, ro_count, removable_count, cdrom_count;
15 unsigned int nofua_count;
16 unsigned int luns; /* nluns */
17 bool stall; /* can_stall */
18};
19
20#define _FSG_MODULE_PARAM_ARRAY(prefix, params, name, type, desc) \
21 module_param_array_named(prefix ## name, params.name, type, \
22 &prefix ## params.name ## _count, \
23 S_IRUGO); \
24 MODULE_PARM_DESC(prefix ## name, desc)
25
26#define _FSG_MODULE_PARAM(prefix, params, name, type, desc) \
27 module_param_named(prefix ## name, params.name, type, \
28 S_IRUGO); \
29 MODULE_PARM_DESC(prefix ## name, desc)
30
31#define __FSG_MODULE_PARAMETERS(prefix, params) \
32 _FSG_MODULE_PARAM_ARRAY(prefix, params, file, charp, \
33 "names of backing files or devices"); \
34 _FSG_MODULE_PARAM_ARRAY(prefix, params, ro, bool, \
35 "true to force read-only"); \
36 _FSG_MODULE_PARAM_ARRAY(prefix, params, removable, bool, \
37 "true to simulate removable media"); \
38 _FSG_MODULE_PARAM_ARRAY(prefix, params, cdrom, bool, \
39 "true to simulate CD-ROM instead of disk"); \
40 _FSG_MODULE_PARAM_ARRAY(prefix, params, nofua, bool, \
41 "true to ignore SCSI WRITE(10,12) FUA bit"); \
42 _FSG_MODULE_PARAM(prefix, params, luns, uint, \
43 "number of LUNs"); \
44 _FSG_MODULE_PARAM(prefix, params, stall, bool, \
45 "false to prevent bulk stalls")
46
47#ifdef CONFIG_USB_GADGET_DEBUG_FILES
48
49#define FSG_MODULE_PARAMETERS(prefix, params) \
50 __FSG_MODULE_PARAMETERS(prefix, params); \
51 module_param_named(num_buffers, fsg_num_buffers, uint, S_IRUGO);\
52 MODULE_PARM_DESC(num_buffers, "Number of pipeline buffers")
53#else
54
55#define FSG_MODULE_PARAMETERS(prefix, params) \
56 __FSG_MODULE_PARAMETERS(prefix, params)
57
58#endif
59
60struct fsg_common;
61
62/* FSF callback functions */
63struct fsg_operations {
64 /*
65 * Callback function to call when thread exits. If no
66 * callback is set or it returns value lower then zero MSF
67 * will force eject all LUNs it operates on (including those
68 * marked as non-removable or with prevent_medium_removal flag
69 * set).
70 */
71 int (*thread_exits)(struct fsg_common *common);
72};
73
74struct fsg_lun_opts {
75 struct config_group group;
76 struct fsg_lun *lun;
77 int lun_id;
78};
79
80struct fsg_opts {
81 struct fsg_common *common;
82 struct usb_function_instance func_inst;
83 struct fsg_lun_opts lun0;
84 struct config_group *default_groups[2];
85 bool no_configfs; /* for legacy gadgets */
86
87 /*
88 * Read/write access to configfs attributes is handled by configfs.
89 *
90 * This is to protect the data from concurrent access by read/write
91 * and create symlink/remove symlink.
92 */
93 struct mutex lock;
94 int refcnt;
95};
96
97struct fsg_lun_config {
98 const char *filename;
99 char ro;
100 char removable;
101 char cdrom;
102 char nofua;
103};
104
105struct fsg_config {
106 unsigned nluns;
107 struct fsg_lun_config luns[FSG_MAX_LUNS];
108
109 /* Callback functions. */
110 const struct fsg_operations *ops;
111 /* Gadget's private data. */
112 void *private_data;
113
114 const char *vendor_name; /* 8 characters or less */
115 const char *product_name; /* 16 characters or less */
116
117 char can_stall;
118 unsigned int fsg_num_buffers;
119};
120
121static inline struct fsg_opts *
122fsg_opts_from_func_inst(const struct usb_function_instance *fi)
123{
124 return container_of(fi, struct fsg_opts, func_inst);
125}
126
127void fsg_common_get(struct fsg_common *common);
128
129void fsg_common_put(struct fsg_common *common);
130
131void fsg_common_set_sysfs(struct fsg_common *common, bool sysfs);
132
133int fsg_common_set_num_buffers(struct fsg_common *common, unsigned int n);
134
135void fsg_common_free_buffers(struct fsg_common *common);
136
137int fsg_common_set_cdev(struct fsg_common *common,
138 struct usb_composite_dev *cdev, bool can_stall);
139
140void fsg_common_remove_lun(struct fsg_lun *lun, bool sysfs);
141
142void fsg_common_remove_luns(struct fsg_common *common);
143
144void fsg_common_free_luns(struct fsg_common *common);
145
146int fsg_common_set_nluns(struct fsg_common *common, int nluns);
147
148void fsg_common_set_ops(struct fsg_common *common,
149 const struct fsg_operations *ops);
150
151int fsg_common_create_lun(struct fsg_common *common, struct fsg_lun_config *cfg,
152 unsigned int id, const char *name,
153 const char **name_pfx);
154
155int fsg_common_create_luns(struct fsg_common *common, struct fsg_config *cfg);
156
157void fsg_common_set_inquiry_string(struct fsg_common *common, const char *vn,
158 const char *pn);
159
160int fsg_common_run_thread(struct fsg_common *common);
161
162void fsg_config_from_params(struct fsg_config *cfg,
163 const struct fsg_module_parameters *params,
164 unsigned int fsg_num_buffers);
165
166#endif /* USB_F_MASS_STORAGE_H */
diff --git a/drivers/usb/gadget/g_ffs.c b/drivers/usb/gadget/g_ffs.c
index 5327c82472ed..2344efe4f4ce 100644
--- a/drivers/usb/gadget/g_ffs.c
+++ b/drivers/usb/gadget/g_ffs.c
@@ -76,7 +76,9 @@ struct gfs_ffs_obj {
76 76
77USB_GADGET_COMPOSITE_OPTIONS(); 77USB_GADGET_COMPOSITE_OPTIONS();
78 78
79#if defined CONFIG_USB_FUNCTIONFS_ETH || defined CONFIG_USB_FUNCTIONFS_RNDIS
79USB_ETHERNET_MODULE_PARAMETERS(); 80USB_ETHERNET_MODULE_PARAMETERS();
81#endif
80 82
81static struct usb_device_descriptor gfs_dev_desc = { 83static struct usb_device_descriptor gfs_dev_desc = {
82 .bLength = sizeof gfs_dev_desc, 84 .bLength = sizeof gfs_dev_desc,
diff --git a/drivers/usb/gadget/goku_udc.c b/drivers/usb/gadget/goku_udc.c
index c64deb9e3d62..f82768015715 100644
--- a/drivers/usb/gadget/goku_udc.c
+++ b/drivers/usb/gadget/goku_udc.c
@@ -1165,7 +1165,7 @@ static int udc_proc_read(struct seq_file *m, void *v)
1165 s = "invalid"; break; 1165 s = "invalid"; break;
1166 default: 1166 default:
1167 s = "?"; break; 1167 s = "?"; break;
1168 }; s; }), 1168 } s; }),
1169 (tmp & EPxSTATUS_TOGGLE) ? "data1" : "data0", 1169 (tmp & EPxSTATUS_TOGGLE) ? "data1" : "data0",
1170 (tmp & EPxSTATUS_SUSPEND) ? " suspend" : "", 1170 (tmp & EPxSTATUS_SUSPEND) ? " suspend" : "",
1171 (tmp & EPxSTATUS_FIFO_DISABLE) ? " disable" : "", 1171 (tmp & EPxSTATUS_FIFO_DISABLE) ? " disable" : "",
@@ -1701,7 +1701,6 @@ static void goku_remove(struct pci_dev *pdev)
1701 if (dev->enabled) 1701 if (dev->enabled)
1702 pci_disable_device(pdev); 1702 pci_disable_device(pdev);
1703 1703
1704 pci_set_drvdata(pdev, NULL);
1705 dev->regs = NULL; 1704 dev->regs = NULL;
1706 1705
1707 INFO(dev, "unbind\n"); 1706 INFO(dev, "unbind\n");
diff --git a/drivers/usb/gadget/mass_storage.c b/drivers/usb/gadget/mass_storage.c
index 080e577773d5..8e27a8c96444 100644
--- a/drivers/usb/gadget/mass_storage.c
+++ b/drivers/usb/gadget/mass_storage.c
@@ -37,16 +37,16 @@
37#define DRIVER_DESC "Mass Storage Gadget" 37#define DRIVER_DESC "Mass Storage Gadget"
38#define DRIVER_VERSION "2009/09/11" 38#define DRIVER_VERSION "2009/09/11"
39 39
40/*-------------------------------------------------------------------------*/
41
42/* 40/*
43 * kbuild is not very cooperative with respect to linking separately 41 * Thanks to NetChip Technologies for donating this product ID.
44 * compiled library objects into one module. So for now we won't use 42 *
45 * separate compilation ... ensuring init/exit sections work to shrink 43 * DO NOT REUSE THESE IDs with any other driver!! Ever!!
46 * the runtime footprint, and giving us at least some parts of what 44 * Instead: allocate your own, using normal USB-IF procedures.
47 * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
48 */ 45 */
49#include "f_mass_storage.c" 46#define FSG_VENDOR_ID 0x0525 /* NetChip */
47#define FSG_PRODUCT_ID 0xa4a5 /* Linux-USB File-backed Storage Gadget */
48
49#include "f_mass_storage.h"
50 50
51/*-------------------------------------------------------------------------*/ 51/*-------------------------------------------------------------------------*/
52USB_GADGET_COMPOSITE_OPTIONS(); 52USB_GADGET_COMPOSITE_OPTIONS();
@@ -97,11 +97,28 @@ static struct usb_gadget_strings *dev_strings[] = {
97 NULL, 97 NULL,
98}; 98};
99 99
100static struct usb_function_instance *fi_msg;
101static struct usb_function *f_msg;
102
100/****************************** Configurations ******************************/ 103/****************************** Configurations ******************************/
101 104
102static struct fsg_module_parameters mod_data = { 105static struct fsg_module_parameters mod_data = {
103 .stall = 1 106 .stall = 1
104}; 107};
108#ifdef CONFIG_USB_GADGET_DEBUG_FILES
109
110static unsigned int fsg_num_buffers = CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS;
111
112#else
113
114/*
115 * Number of buffers we will use.
116 * 2 is usually enough for good buffering pipeline
117 */
118#define fsg_num_buffers CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS
119
120#endif /* CONFIG_USB_GADGET_DEBUG_FILES */
121
105FSG_MODULE_PARAMETERS(/* no prefix */, mod_data); 122FSG_MODULE_PARAMETERS(/* no prefix */, mod_data);
106 123
107static unsigned long msg_registered; 124static unsigned long msg_registered;
@@ -115,13 +132,7 @@ static int msg_thread_exits(struct fsg_common *common)
115 132
116static int __init msg_do_config(struct usb_configuration *c) 133static int __init msg_do_config(struct usb_configuration *c)
117{ 134{
118 static const struct fsg_operations ops = { 135 struct fsg_opts *opts;
119 .thread_exits = msg_thread_exits,
120 };
121 static struct fsg_common common;
122
123 struct fsg_common *retp;
124 struct fsg_config config;
125 int ret; 136 int ret;
126 137
127 if (gadget_is_otg(c->cdev->gadget)) { 138 if (gadget_is_otg(c->cdev->gadget)) {
@@ -129,15 +140,24 @@ static int __init msg_do_config(struct usb_configuration *c)
129 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; 140 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
130 } 141 }
131 142
132 fsg_config_from_params(&config, &mod_data); 143 opts = fsg_opts_from_func_inst(fi_msg);
133 config.ops = &ops; 144
145 f_msg = usb_get_function(fi_msg);
146 if (IS_ERR(f_msg))
147 return PTR_ERR(f_msg);
148
149 ret = fsg_common_run_thread(opts->common);
150 if (ret)
151 goto put_func;
152
153 ret = usb_add_function(c, f_msg);
154 if (ret)
155 goto put_func;
134 156
135 retp = fsg_common_init(&common, c->cdev, &config); 157 return 0;
136 if (IS_ERR(retp))
137 return PTR_ERR(retp);
138 158
139 ret = fsg_bind_config(c->cdev, c, &common); 159put_func:
140 fsg_common_put(&common); 160 usb_put_function(f_msg);
141 return ret; 161 return ret;
142} 162}
143 163
@@ -152,23 +172,79 @@ static struct usb_configuration msg_config_driver = {
152 172
153static int __init msg_bind(struct usb_composite_dev *cdev) 173static int __init msg_bind(struct usb_composite_dev *cdev)
154{ 174{
175 static const struct fsg_operations ops = {
176 .thread_exits = msg_thread_exits,
177 };
178 struct fsg_opts *opts;
179 struct fsg_config config;
155 int status; 180 int status;
156 181
182 fi_msg = usb_get_function_instance("mass_storage");
183 if (IS_ERR(fi_msg))
184 return PTR_ERR(fi_msg);
185
186 fsg_config_from_params(&config, &mod_data, fsg_num_buffers);
187 opts = fsg_opts_from_func_inst(fi_msg);
188
189 opts->no_configfs = true;
190 status = fsg_common_set_num_buffers(opts->common, fsg_num_buffers);
191 if (status)
192 goto fail;
193
194 status = fsg_common_set_nluns(opts->common, config.nluns);
195 if (status)
196 goto fail_set_nluns;
197
198 fsg_common_set_ops(opts->common, &ops);
199
200 status = fsg_common_set_cdev(opts->common, cdev, config.can_stall);
201 if (status)
202 goto fail_set_cdev;
203
204 fsg_common_set_sysfs(opts->common, true);
205 status = fsg_common_create_luns(opts->common, &config);
206 if (status)
207 goto fail_set_cdev;
208
209 fsg_common_set_inquiry_string(opts->common, config.vendor_name,
210 config.product_name);
211
157 status = usb_string_ids_tab(cdev, strings_dev); 212 status = usb_string_ids_tab(cdev, strings_dev);
158 if (status < 0) 213 if (status < 0)
159 return status; 214 goto fail_string_ids;
160 msg_device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id; 215 msg_device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id;
161 216
162 status = usb_add_config(cdev, &msg_config_driver, msg_do_config); 217 status = usb_add_config(cdev, &msg_config_driver, msg_do_config);
163 if (status < 0) 218 if (status < 0)
164 return status; 219 goto fail_string_ids;
220
165 usb_composite_overwrite_options(cdev, &coverwrite); 221 usb_composite_overwrite_options(cdev, &coverwrite);
166 dev_info(&cdev->gadget->dev, 222 dev_info(&cdev->gadget->dev,
167 DRIVER_DESC ", version: " DRIVER_VERSION "\n"); 223 DRIVER_DESC ", version: " DRIVER_VERSION "\n");
168 set_bit(0, &msg_registered); 224 set_bit(0, &msg_registered);
169 return 0; 225 return 0;
226
227fail_string_ids:
228 fsg_common_remove_luns(opts->common);
229fail_set_cdev:
230 fsg_common_free_luns(opts->common);
231fail_set_nluns:
232 fsg_common_free_buffers(opts->common);
233fail:
234 usb_put_function_instance(fi_msg);
235 return status;
170} 236}
171 237
238static int msg_unbind(struct usb_composite_dev *cdev)
239{
240 if (!IS_ERR(f_msg))
241 usb_put_function(f_msg);
242
243 if (!IS_ERR(fi_msg))
244 usb_put_function_instance(fi_msg);
245
246 return 0;
247}
172 248
173/****************************** Some noise ******************************/ 249/****************************** Some noise ******************************/
174 250
@@ -179,6 +255,7 @@ static __refdata struct usb_composite_driver msg_driver = {
179 .needs_serial = 1, 255 .needs_serial = 1,
180 .strings = dev_strings, 256 .strings = dev_strings,
181 .bind = msg_bind, 257 .bind = msg_bind,
258 .unbind = msg_unbind,
182}; 259};
183 260
184MODULE_DESCRIPTION(DRIVER_DESC); 261MODULE_DESCRIPTION(DRIVER_DESC);
diff --git a/drivers/usb/gadget/multi.c b/drivers/usb/gadget/multi.c
index 23393254a8a3..4fdaa54a2a2a 100644
--- a/drivers/usb/gadget/multi.c
+++ b/drivers/usb/gadget/multi.c
@@ -15,6 +15,7 @@
15 15
16#include <linux/kernel.h> 16#include <linux/kernel.h>
17#include <linux/module.h> 17#include <linux/module.h>
18#include <linux/netdevice.h>
18 19
19#include "u_serial.h" 20#include "u_serial.h"
20#if defined USB_ETH_RNDIS 21#if defined USB_ETH_RNDIS
@@ -32,22 +33,11 @@ MODULE_AUTHOR("Michal Nazarewicz");
32MODULE_LICENSE("GPL"); 33MODULE_LICENSE("GPL");
33 34
34 35
35/***************************** All the files... *****************************/ 36#include "f_mass_storage.h"
36 37
37/* 38#include "u_ecm.h"
38 * kbuild is not very cooperative with respect to linking separately
39 * compiled library objects into one module. So for now we won't use
40 * separate compilation ... ensuring init/exit sections work to shrink
41 * the runtime footprint, and giving us at least some parts of what
42 * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
43 */
44#include "f_mass_storage.c"
45
46#define USBF_ECM_INCLUDED
47#include "f_ecm.c"
48#ifdef USB_ETH_RNDIS 39#ifdef USB_ETH_RNDIS
49# define USB_FRNDIS_INCLUDED 40# include "u_rndis.h"
50# include "f_rndis.c"
51# include "rndis.h" 41# include "rndis.h"
52#endif 42#endif
53#include "u_ether.h" 43#include "u_ether.h"
@@ -132,22 +122,36 @@ static struct usb_gadget_strings *dev_strings[] = {
132/****************************** Configurations ******************************/ 122/****************************** Configurations ******************************/
133 123
134static struct fsg_module_parameters fsg_mod_data = { .stall = 1 }; 124static struct fsg_module_parameters fsg_mod_data = { .stall = 1 };
135FSG_MODULE_PARAMETERS(/* no prefix */, fsg_mod_data); 125#ifdef CONFIG_USB_GADGET_DEBUG_FILES
126
127static unsigned int fsg_num_buffers = CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS;
136 128
137static struct fsg_common fsg_common; 129#else
130
131/*
132 * Number of buffers we will use.
133 * 2 is usually enough for good buffering pipeline
134 */
135#define fsg_num_buffers CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS
138 136
139static u8 host_mac[ETH_ALEN]; 137#endif /* CONFIG_USB_DEBUG */
138
139FSG_MODULE_PARAMETERS(/* no prefix */, fsg_mod_data);
140 140
141static struct usb_function_instance *fi_acm; 141static struct usb_function_instance *fi_acm;
142static struct eth_dev *the_dev; 142static struct usb_function_instance *fi_msg;
143 143
144/********** RNDIS **********/ 144/********** RNDIS **********/
145 145
146#ifdef USB_ETH_RNDIS 146#ifdef USB_ETH_RNDIS
147static struct usb_function_instance *fi_rndis;
147static struct usb_function *f_acm_rndis; 148static struct usb_function *f_acm_rndis;
149static struct usb_function *f_rndis;
150static struct usb_function *f_msg_rndis;
148 151
149static __init int rndis_do_config(struct usb_configuration *c) 152static __init int rndis_do_config(struct usb_configuration *c)
150{ 153{
154 struct fsg_opts *fsg_opts;
151 int ret; 155 int ret;
152 156
153 if (gadget_is_otg(c->cdev->gadget)) { 157 if (gadget_is_otg(c->cdev->gadget)) {
@@ -155,27 +159,50 @@ static __init int rndis_do_config(struct usb_configuration *c)
155 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; 159 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
156 } 160 }
157 161
158 ret = rndis_bind_config(c, host_mac, the_dev); 162 f_rndis = usb_get_function(fi_rndis);
163 if (IS_ERR(f_rndis))
164 return PTR_ERR(f_rndis);
165
166 ret = usb_add_function(c, f_rndis);
159 if (ret < 0) 167 if (ret < 0)
160 return ret; 168 goto err_func_rndis;
161 169
162 f_acm_rndis = usb_get_function(fi_acm); 170 f_acm_rndis = usb_get_function(fi_acm);
163 if (IS_ERR(f_acm_rndis)) 171 if (IS_ERR(f_acm_rndis)) {
164 return PTR_ERR(f_acm_rndis); 172 ret = PTR_ERR(f_acm_rndis);
173 goto err_func_acm;
174 }
165 175
166 ret = usb_add_function(c, f_acm_rndis); 176 ret = usb_add_function(c, f_acm_rndis);
167 if (ret) 177 if (ret)
168 goto err_conf; 178 goto err_conf;
169 179
170 ret = fsg_bind_config(c->cdev, c, &fsg_common); 180 f_msg_rndis = usb_get_function(fi_msg);
171 if (ret < 0) 181 if (IS_ERR(f_msg_rndis)) {
182 ret = PTR_ERR(f_msg_rndis);
172 goto err_fsg; 183 goto err_fsg;
184 }
185
186 fsg_opts = fsg_opts_from_func_inst(fi_msg);
187 ret = fsg_common_run_thread(fsg_opts->common);
188 if (ret)
189 goto err_run;
190
191 ret = usb_add_function(c, f_msg_rndis);
192 if (ret)
193 goto err_run;
173 194
174 return 0; 195 return 0;
196err_run:
197 usb_put_function(f_msg_rndis);
175err_fsg: 198err_fsg:
176 usb_remove_function(c, f_acm_rndis); 199 usb_remove_function(c, f_acm_rndis);
177err_conf: 200err_conf:
178 usb_put_function(f_acm_rndis); 201 usb_put_function(f_acm_rndis);
202err_func_acm:
203 usb_remove_function(c, f_rndis);
204err_func_rndis:
205 usb_put_function(f_rndis);
179 return ret; 206 return ret;
180} 207}
181 208
@@ -205,10 +232,14 @@ static __ref int rndis_config_register(struct usb_composite_dev *cdev)
205/********** CDC ECM **********/ 232/********** CDC ECM **********/
206 233
207#ifdef CONFIG_USB_G_MULTI_CDC 234#ifdef CONFIG_USB_G_MULTI_CDC
235static struct usb_function_instance *fi_ecm;
208static struct usb_function *f_acm_multi; 236static struct usb_function *f_acm_multi;
237static struct usb_function *f_ecm;
238static struct usb_function *f_msg_multi;
209 239
210static __init int cdc_do_config(struct usb_configuration *c) 240static __init int cdc_do_config(struct usb_configuration *c)
211{ 241{
242 struct fsg_opts *fsg_opts;
212 int ret; 243 int ret;
213 244
214 if (gadget_is_otg(c->cdev->gadget)) { 245 if (gadget_is_otg(c->cdev->gadget)) {
@@ -216,28 +247,51 @@ static __init int cdc_do_config(struct usb_configuration *c)
216 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; 247 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
217 } 248 }
218 249
219 ret = ecm_bind_config(c, host_mac, the_dev); 250 f_ecm = usb_get_function(fi_ecm);
251 if (IS_ERR(f_ecm))
252 return PTR_ERR(f_ecm);
253
254 ret = usb_add_function(c, f_ecm);
220 if (ret < 0) 255 if (ret < 0)
221 return ret; 256 goto err_func_ecm;
222 257
223 /* implicit port_num is zero */ 258 /* implicit port_num is zero */
224 f_acm_multi = usb_get_function(fi_acm); 259 f_acm_multi = usb_get_function(fi_acm);
225 if (IS_ERR(f_acm_multi)) 260 if (IS_ERR(f_acm_multi)) {
226 return PTR_ERR(f_acm_multi); 261 ret = PTR_ERR(f_acm_multi);
262 goto err_func_acm;
263 }
227 264
228 ret = usb_add_function(c, f_acm_multi); 265 ret = usb_add_function(c, f_acm_multi);
229 if (ret) 266 if (ret)
230 goto err_conf; 267 goto err_conf;
231 268
232 ret = fsg_bind_config(c->cdev, c, &fsg_common); 269 f_msg_multi = usb_get_function(fi_msg);
233 if (ret < 0) 270 if (IS_ERR(f_msg_multi)) {
271 ret = PTR_ERR(f_msg_multi);
234 goto err_fsg; 272 goto err_fsg;
273 }
274
275 fsg_opts = fsg_opts_from_func_inst(fi_msg);
276 ret = fsg_common_run_thread(fsg_opts->common);
277 if (ret)
278 goto err_run;
279
280 ret = usb_add_function(c, f_msg_multi);
281 if (ret)
282 goto err_run;
235 283
236 return 0; 284 return 0;
285err_run:
286 usb_put_function(f_msg_multi);
237err_fsg: 287err_fsg:
238 usb_remove_function(c, f_acm_multi); 288 usb_remove_function(c, f_acm_multi);
239err_conf: 289err_conf:
240 usb_put_function(f_acm_multi); 290 usb_put_function(f_acm_multi);
291err_func_acm:
292 usb_remove_function(c, f_ecm);
293err_func_ecm:
294 usb_put_function(f_ecm);
241 return ret; 295 return ret;
242} 296}
243 297
@@ -270,19 +324,67 @@ static __ref int cdc_config_register(struct usb_composite_dev *cdev)
270static int __ref multi_bind(struct usb_composite_dev *cdev) 324static int __ref multi_bind(struct usb_composite_dev *cdev)
271{ 325{
272 struct usb_gadget *gadget = cdev->gadget; 326 struct usb_gadget *gadget = cdev->gadget;
327#ifdef CONFIG_USB_G_MULTI_CDC
328 struct f_ecm_opts *ecm_opts;
329#endif
330#ifdef USB_ETH_RNDIS
331 struct f_rndis_opts *rndis_opts;
332#endif
333 struct fsg_opts *fsg_opts;
334 struct fsg_config config;
273 int status; 335 int status;
274 336
275 if (!can_support_ecm(cdev->gadget)) { 337 if (!can_support_ecm(cdev->gadget)) {
276 dev_err(&gadget->dev, "controller '%s' not usable\n", 338 dev_err(&gadget->dev, "controller '%s' not usable\n",
277 gadget->name); 339 gadget->name);
278 return -EINVAL; 340 return -EINVAL;
279 } 341 }
280 342
281 /* set up network link layer */ 343#ifdef CONFIG_USB_G_MULTI_CDC
282 the_dev = gether_setup(cdev->gadget, dev_addr, host_addr, host_mac, 344 fi_ecm = usb_get_function_instance("ecm");
283 qmult); 345 if (IS_ERR(fi_ecm))
284 if (IS_ERR(the_dev)) 346 return PTR_ERR(fi_ecm);
285 return PTR_ERR(the_dev); 347
348 ecm_opts = container_of(fi_ecm, struct f_ecm_opts, func_inst);
349
350 gether_set_qmult(ecm_opts->net, qmult);
351 if (!gether_set_host_addr(ecm_opts->net, host_addr))
352 pr_info("using host ethernet address: %s", host_addr);
353 if (!gether_set_dev_addr(ecm_opts->net, dev_addr))
354 pr_info("using self ethernet address: %s", dev_addr);
355#endif
356
357#ifdef USB_ETH_RNDIS
358 fi_rndis = usb_get_function_instance("rndis");
359 if (IS_ERR(fi_rndis)) {
360 status = PTR_ERR(fi_rndis);
361 goto fail;
362 }
363
364 rndis_opts = container_of(fi_rndis, struct f_rndis_opts, func_inst);
365
366 gether_set_qmult(rndis_opts->net, qmult);
367 if (!gether_set_host_addr(rndis_opts->net, host_addr))
368 pr_info("using host ethernet address: %s", host_addr);
369 if (!gether_set_dev_addr(rndis_opts->net, dev_addr))
370 pr_info("using self ethernet address: %s", dev_addr);
371#endif
372
373#if (defined CONFIG_USB_G_MULTI_CDC && defined USB_ETH_RNDIS)
374 /*
375 * If both ecm and rndis are selected then:
376 * 1) rndis borrows the net interface from ecm
377 * 2) since the interface is shared it must not be bound
378 * twice - in ecm's _and_ rndis' binds, so do it here.
379 */
380 gether_set_gadget(ecm_opts->net, cdev->gadget);
381 status = gether_register_netdev(ecm_opts->net);
382 if (status)
383 goto fail0;
384
385 rndis_borrow_net(fi_rndis, ecm_opts->net);
386 ecm_opts->bound = true;
387#endif
286 388
287 /* set up serial link layer */ 389 /* set up serial link layer */
288 fi_acm = usb_get_function_instance("acm"); 390 fi_acm = usb_get_function_instance("acm");
@@ -292,57 +394,102 @@ static int __ref multi_bind(struct usb_composite_dev *cdev)
292 } 394 }
293 395
294 /* set up mass storage function */ 396 /* set up mass storage function */
295 { 397 fi_msg = usb_get_function_instance("mass_storage");
296 void *retp; 398 if (IS_ERR(fi_msg)) {
297 retp = fsg_common_from_params(&fsg_common, cdev, &fsg_mod_data); 399 status = PTR_ERR(fi_msg);
298 if (IS_ERR(retp)) { 400 goto fail1;
299 status = PTR_ERR(retp);
300 goto fail1;
301 }
302 } 401 }
402 fsg_config_from_params(&config, &fsg_mod_data, fsg_num_buffers);
403 fsg_opts = fsg_opts_from_func_inst(fi_msg);
404
405 fsg_opts->no_configfs = true;
406 status = fsg_common_set_num_buffers(fsg_opts->common, fsg_num_buffers);
407 if (status)
408 goto fail2;
409
410 status = fsg_common_set_nluns(fsg_opts->common, config.nluns);
411 if (status)
412 goto fail_set_nluns;
413
414 status = fsg_common_set_cdev(fsg_opts->common, cdev, config.can_stall);
415 if (status)
416 goto fail_set_cdev;
417
418 fsg_common_set_sysfs(fsg_opts->common, true);
419 status = fsg_common_create_luns(fsg_opts->common, &config);
420 if (status)
421 goto fail_set_cdev;
422
423 fsg_common_set_inquiry_string(fsg_opts->common, config.vendor_name,
424 config.product_name);
303 425
304 /* allocate string IDs */ 426 /* allocate string IDs */
305 status = usb_string_ids_tab(cdev, strings_dev); 427 status = usb_string_ids_tab(cdev, strings_dev);
306 if (unlikely(status < 0)) 428 if (unlikely(status < 0))
307 goto fail2; 429 goto fail_string_ids;
308 device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id; 430 device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id;
309 431
310 /* register configurations */ 432 /* register configurations */
311 status = rndis_config_register(cdev); 433 status = rndis_config_register(cdev);
312 if (unlikely(status < 0)) 434 if (unlikely(status < 0))
313 goto fail2; 435 goto fail_string_ids;
314 436
315 status = cdc_config_register(cdev); 437 status = cdc_config_register(cdev);
316 if (unlikely(status < 0)) 438 if (unlikely(status < 0))
317 goto fail2; 439 goto fail_string_ids;
318 usb_composite_overwrite_options(cdev, &coverwrite); 440 usb_composite_overwrite_options(cdev, &coverwrite);
319 441
320 /* we're done */ 442 /* we're done */
321 dev_info(&gadget->dev, DRIVER_DESC "\n"); 443 dev_info(&gadget->dev, DRIVER_DESC "\n");
322 fsg_common_put(&fsg_common);
323 return 0; 444 return 0;
324 445
325 446
326 /* error recovery */ 447 /* error recovery */
448fail_string_ids:
449 fsg_common_remove_luns(fsg_opts->common);
450fail_set_cdev:
451 fsg_common_free_luns(fsg_opts->common);
452fail_set_nluns:
453 fsg_common_free_buffers(fsg_opts->common);
327fail2: 454fail2:
328 fsg_common_put(&fsg_common); 455 usb_put_function_instance(fi_msg);
329fail1: 456fail1:
330 usb_put_function_instance(fi_acm); 457 usb_put_function_instance(fi_acm);
331fail0: 458fail0:
332 gether_cleanup(the_dev); 459#ifdef USB_ETH_RNDIS
460 usb_put_function_instance(fi_rndis);
461fail:
462#endif
463#ifdef CONFIG_USB_G_MULTI_CDC
464 usb_put_function_instance(fi_ecm);
465#endif
333 return status; 466 return status;
334} 467}
335 468
336static int __exit multi_unbind(struct usb_composite_dev *cdev) 469static int __exit multi_unbind(struct usb_composite_dev *cdev)
337{ 470{
338#ifdef CONFIG_USB_G_MULTI_CDC 471#ifdef CONFIG_USB_G_MULTI_CDC
472 usb_put_function(f_msg_multi);
473#endif
474#ifdef USB_ETH_RNDIS
475 usb_put_function(f_msg_rndis);
476#endif
477 usb_put_function_instance(fi_msg);
478#ifdef CONFIG_USB_G_MULTI_CDC
339 usb_put_function(f_acm_multi); 479 usb_put_function(f_acm_multi);
340#endif 480#endif
341#ifdef USB_ETH_RNDIS 481#ifdef USB_ETH_RNDIS
342 usb_put_function(f_acm_rndis); 482 usb_put_function(f_acm_rndis);
343#endif 483#endif
344 usb_put_function_instance(fi_acm); 484 usb_put_function_instance(fi_acm);
345 gether_cleanup(the_dev); 485#ifdef USB_ETH_RNDIS
486 usb_put_function(f_rndis);
487 usb_put_function_instance(fi_rndis);
488#endif
489#ifdef CONFIG_USB_G_MULTI_CDC
490 usb_put_function(f_ecm);
491 usb_put_function_instance(fi_ecm);
492#endif
346 return 0; 493 return 0;
347} 494}
348 495
diff --git a/drivers/usb/gadget/mv_u3d_core.c b/drivers/usb/gadget/mv_u3d_core.c
index 561b30efb8ee..234711eabea1 100644
--- a/drivers/usb/gadget/mv_u3d_core.c
+++ b/drivers/usb/gadget/mv_u3d_core.c
@@ -310,6 +310,7 @@ static struct mv_u3d_trb *mv_u3d_build_trb_one(struct mv_u3d_req *req,
310 */ 310 */
311 trb_hw = dma_pool_alloc(u3d->trb_pool, GFP_ATOMIC, dma); 311 trb_hw = dma_pool_alloc(u3d->trb_pool, GFP_ATOMIC, dma);
312 if (!trb_hw) { 312 if (!trb_hw) {
313 kfree(trb);
313 dev_err(u3d->dev, 314 dev_err(u3d->dev,
314 "%s, dma_pool_alloc fail\n", __func__); 315 "%s, dma_pool_alloc fail\n", __func__);
315 return NULL; 316 return NULL;
@@ -454,6 +455,7 @@ static int mv_u3d_req_to_trb(struct mv_u3d_req *req)
454 455
455 trb_hw = kcalloc(trb_num, sizeof(*trb_hw), GFP_ATOMIC); 456 trb_hw = kcalloc(trb_num, sizeof(*trb_hw), GFP_ATOMIC);
456 if (!trb_hw) { 457 if (!trb_hw) {
458 kfree(trb);
457 dev_err(u3d->dev, 459 dev_err(u3d->dev,
458 "%s, trb_hw alloc fail\n", __func__); 460 "%s, trb_hw alloc fail\n", __func__);
459 return -ENOMEM; 461 return -ENOMEM;
@@ -1936,7 +1938,7 @@ static int mv_u3d_probe(struct platform_device *dev)
1936 } 1938 }
1937 u3d->irq = r->start; 1939 u3d->irq = r->start;
1938 if (request_irq(u3d->irq, mv_u3d_irq, 1940 if (request_irq(u3d->irq, mv_u3d_irq,
1939 IRQF_DISABLED | IRQF_SHARED, driver_name, u3d)) { 1941 IRQF_SHARED, driver_name, u3d)) {
1940 u3d->irq = 0; 1942 u3d->irq = 0;
1941 dev_err(&dev->dev, "Request irq %d for u3d failed\n", 1943 dev_err(&dev->dev, "Request irq %d for u3d failed\n",
1942 u3d->irq); 1944 u3d->irq);
diff --git a/drivers/usb/gadget/net2280.c b/drivers/usb/gadget/net2280.c
index 0781bff70015..fc852177c087 100644
--- a/drivers/usb/gadget/net2280.c
+++ b/drivers/usb/gadget/net2280.c
@@ -129,7 +129,7 @@ static char *type_string (u8 bmAttributes)
129 case USB_ENDPOINT_XFER_BULK: return "bulk"; 129 case USB_ENDPOINT_XFER_BULK: return "bulk";
130 case USB_ENDPOINT_XFER_ISOC: return "iso"; 130 case USB_ENDPOINT_XFER_ISOC: return "iso";
131 case USB_ENDPOINT_XFER_INT: return "intr"; 131 case USB_ENDPOINT_XFER_INT: return "intr";
132 }; 132 }
133 return "control"; 133 return "control";
134} 134}
135#endif 135#endif
@@ -1630,7 +1630,7 @@ static ssize_t queues_show(struct device *_dev, struct device_attribute *attr,
1630 val = "intr"; break; 1630 val = "intr"; break;
1631 default: 1631 default:
1632 val = "iso"; break; 1632 val = "iso"; break;
1633 }; val; }), 1633 } val; }),
1634 usb_endpoint_maxp (d) & 0x1fff, 1634 usb_endpoint_maxp (d) & 0x1fff,
1635 ep->dma ? "dma" : "pio", ep->fifo_size 1635 ep->dma ? "dma" : "pio", ep->fifo_size
1636 ); 1636 );
@@ -2680,7 +2680,6 @@ static void net2280_remove (struct pci_dev *pdev)
2680 if (dev->enabled) 2680 if (dev->enabled)
2681 pci_disable_device (pdev); 2681 pci_disable_device (pdev);
2682 device_remove_file (&pdev->dev, &dev_attr_registers); 2682 device_remove_file (&pdev->dev, &dev_attr_registers);
2683 pci_set_drvdata (pdev, NULL);
2684 2683
2685 INFO (dev, "unbind\n"); 2684 INFO (dev, "unbind\n");
2686} 2685}
diff --git a/drivers/usb/gadget/pch_udc.c b/drivers/usb/gadget/pch_udc.c
index 24174e1d1564..32d5e923750b 100644
--- a/drivers/usb/gadget/pch_udc.c
+++ b/drivers/usb/gadget/pch_udc.c
@@ -3080,7 +3080,6 @@ static void pch_udc_remove(struct pci_dev *pdev)
3080 if (dev->active) 3080 if (dev->active)
3081 pci_disable_device(pdev); 3081 pci_disable_device(pdev);
3082 kfree(dev); 3082 kfree(dev);
3083 pci_set_drvdata(pdev, NULL);
3084} 3083}
3085 3084
3086#ifdef CONFIG_PM 3085#ifdef CONFIG_PM
diff --git a/drivers/usb/gadget/rndis.c b/drivers/usb/gadget/rndis.c
index 9575085ded81..a3ad732bc812 100644
--- a/drivers/usb/gadget/rndis.c
+++ b/drivers/usb/gadget/rndis.c
@@ -1068,7 +1068,7 @@ static int rndis_proc_show(struct seq_file *m, void *v)
1068 s = "RNDIS_INITIALIZED"; break; 1068 s = "RNDIS_INITIALIZED"; break;
1069 case RNDIS_DATA_INITIALIZED: 1069 case RNDIS_DATA_INITIALIZED:
1070 s = "RNDIS_DATA_INITIALIZED"; break; 1070 s = "RNDIS_DATA_INITIALIZED"; break;
1071 }; s; }), 1071 } s; }),
1072 param->medium, 1072 param->medium,
1073 (param->media_state) ? 0 : param->speed*100, 1073 (param->media_state) ? 0 : param->speed*100,
1074 (param->media_state) ? "disconnected" : "connected", 1074 (param->media_state) ? "disconnected" : "connected",
diff --git a/drivers/usb/gadget/s3c-hsotg.c b/drivers/usb/gadget/s3c-hsotg.c
index a8a99e4748d5..9875d9c0823f 100644
--- a/drivers/usb/gadget/s3c-hsotg.c
+++ b/drivers/usb/gadget/s3c-hsotg.c
@@ -83,9 +83,12 @@ struct s3c_hsotg_req;
83 * @dir_in: Set to true if this endpoint is of the IN direction, which 83 * @dir_in: Set to true if this endpoint is of the IN direction, which
84 * means that it is sending data to the Host. 84 * means that it is sending data to the Host.
85 * @index: The index for the endpoint registers. 85 * @index: The index for the endpoint registers.
86 * @mc: Multi Count - number of transactions per microframe
87 * @interval - Interval for periodic endpoints
86 * @name: The name array passed to the USB core. 88 * @name: The name array passed to the USB core.
87 * @halted: Set if the endpoint has been halted. 89 * @halted: Set if the endpoint has been halted.
88 * @periodic: Set if this is a periodic ep, such as Interrupt 90 * @periodic: Set if this is a periodic ep, such as Interrupt
91 * @isochronous: Set if this is a isochronous ep
89 * @sent_zlp: Set if we've sent a zero-length packet. 92 * @sent_zlp: Set if we've sent a zero-length packet.
90 * @total_data: The total number of data bytes done. 93 * @total_data: The total number of data bytes done.
91 * @fifo_size: The size of the FIFO (for periodic IN endpoints) 94 * @fifo_size: The size of the FIFO (for periodic IN endpoints)
@@ -121,9 +124,12 @@ struct s3c_hsotg_ep {
121 124
122 unsigned char dir_in; 125 unsigned char dir_in;
123 unsigned char index; 126 unsigned char index;
127 unsigned char mc;
128 unsigned char interval;
124 129
125 unsigned int halted:1; 130 unsigned int halted:1;
126 unsigned int periodic:1; 131 unsigned int periodic:1;
132 unsigned int isochronous:1;
127 unsigned int sent_zlp:1; 133 unsigned int sent_zlp:1;
128 134
129 char name[10]; 135 char name[10];
@@ -468,6 +474,7 @@ static int s3c_hsotg_write_fifo(struct s3c_hsotg *hsotg,
468 void *data; 474 void *data;
469 int can_write; 475 int can_write;
470 int pkt_round; 476 int pkt_round;
477 int max_transfer;
471 478
472 to_write -= (buf_pos - hs_ep->last_load); 479 to_write -= (buf_pos - hs_ep->last_load);
473 480
@@ -535,8 +542,10 @@ static int s3c_hsotg_write_fifo(struct s3c_hsotg *hsotg,
535 can_write *= 4; /* fifo size is in 32bit quantities. */ 542 can_write *= 4; /* fifo size is in 32bit quantities. */
536 } 543 }
537 544
538 dev_dbg(hsotg->dev, "%s: GNPTXSTS=%08x, can=%d, to=%d, mps %d\n", 545 max_transfer = hs_ep->ep.maxpacket * hs_ep->mc;
539 __func__, gnptxsts, can_write, to_write, hs_ep->ep.maxpacket); 546
547 dev_dbg(hsotg->dev, "%s: GNPTXSTS=%08x, can=%d, to=%d, max_transfer %d\n",
548 __func__, gnptxsts, can_write, to_write, max_transfer);
540 549
541 /* 550 /*
542 * limit to 512 bytes of data, it seems at least on the non-periodic 551 * limit to 512 bytes of data, it seems at least on the non-periodic
@@ -551,19 +560,21 @@ static int s3c_hsotg_write_fifo(struct s3c_hsotg *hsotg,
551 * the transfer to return that it did not run out of fifo space 560 * the transfer to return that it did not run out of fifo space
552 * doing it. 561 * doing it.
553 */ 562 */
554 if (to_write > hs_ep->ep.maxpacket) { 563 if (to_write > max_transfer) {
555 to_write = hs_ep->ep.maxpacket; 564 to_write = max_transfer;
556 565
557 s3c_hsotg_en_gsint(hsotg, 566 /* it's needed only when we do not use dedicated fifos */
558 periodic ? GINTSTS_PTxFEmp : 567 if (!hsotg->dedicated_fifos)
559 GINTSTS_NPTxFEmp); 568 s3c_hsotg_en_gsint(hsotg,
569 periodic ? GINTSTS_PTxFEmp :
570 GINTSTS_NPTxFEmp);
560 } 571 }
561 572
562 /* see if we can write data */ 573 /* see if we can write data */
563 574
564 if (to_write > can_write) { 575 if (to_write > can_write) {
565 to_write = can_write; 576 to_write = can_write;
566 pkt_round = to_write % hs_ep->ep.maxpacket; 577 pkt_round = to_write % max_transfer;
567 578
568 /* 579 /*
569 * Round the write down to an 580 * Round the write down to an
@@ -581,9 +592,11 @@ static int s3c_hsotg_write_fifo(struct s3c_hsotg *hsotg,
581 * is more room left. 592 * is more room left.
582 */ 593 */
583 594
584 s3c_hsotg_en_gsint(hsotg, 595 /* it's needed only when we do not use dedicated fifos */
585 periodic ? GINTSTS_PTxFEmp : 596 if (!hsotg->dedicated_fifos)
586 GINTSTS_NPTxFEmp); 597 s3c_hsotg_en_gsint(hsotg,
598 periodic ? GINTSTS_PTxFEmp :
599 GINTSTS_NPTxFEmp);
587 } 600 }
588 601
589 dev_dbg(hsotg->dev, "write %d/%d, can_write %d, done %d\n", 602 dev_dbg(hsotg->dev, "write %d/%d, can_write %d, done %d\n",
@@ -727,8 +740,16 @@ static void s3c_hsotg_start_req(struct s3c_hsotg *hsotg,
727 else 740 else
728 packets = 1; /* send one packet if length is zero. */ 741 packets = 1; /* send one packet if length is zero. */
729 742
743 if (hs_ep->isochronous && length > (hs_ep->mc * hs_ep->ep.maxpacket)) {
744 dev_err(hsotg->dev, "req length > maxpacket*mc\n");
745 return;
746 }
747
730 if (dir_in && index != 0) 748 if (dir_in && index != 0)
731 epsize = DxEPTSIZ_MC(1); 749 if (hs_ep->isochronous)
750 epsize = DxEPTSIZ_MC(packets);
751 else
752 epsize = DxEPTSIZ_MC(1);
732 else 753 else
733 epsize = 0; 754 epsize = 0;
734 755
@@ -820,6 +841,9 @@ static void s3c_hsotg_start_req(struct s3c_hsotg *hsotg,
820 841
821 dev_dbg(hsotg->dev, "%s: DxEPCTL=0x%08x\n", 842 dev_dbg(hsotg->dev, "%s: DxEPCTL=0x%08x\n",
822 __func__, readl(hsotg->regs + epctrl_reg)); 843 __func__, readl(hsotg->regs + epctrl_reg));
844
845 /* enable ep interrupts */
846 s3c_hsotg_ctrl_epint(hsotg, hs_ep->index, hs_ep->dir_in, 1);
823} 847}
824 848
825/** 849/**
@@ -1091,6 +1115,7 @@ static int s3c_hsotg_process_req_feature(struct s3c_hsotg *hsotg,
1091 bool set = (ctrl->bRequest == USB_REQ_SET_FEATURE); 1115 bool set = (ctrl->bRequest == USB_REQ_SET_FEATURE);
1092 struct s3c_hsotg_ep *ep; 1116 struct s3c_hsotg_ep *ep;
1093 int ret; 1117 int ret;
1118 bool halted;
1094 1119
1095 dev_dbg(hsotg->dev, "%s: %s_FEATURE\n", 1120 dev_dbg(hsotg->dev, "%s: %s_FEATURE\n",
1096 __func__, set ? "SET" : "CLEAR"); 1121 __func__, set ? "SET" : "CLEAR");
@@ -1105,6 +1130,8 @@ static int s3c_hsotg_process_req_feature(struct s3c_hsotg *hsotg,
1105 1130
1106 switch (le16_to_cpu(ctrl->wValue)) { 1131 switch (le16_to_cpu(ctrl->wValue)) {
1107 case USB_ENDPOINT_HALT: 1132 case USB_ENDPOINT_HALT:
1133 halted = ep->halted;
1134
1108 s3c_hsotg_ep_sethalt(&ep->ep, set); 1135 s3c_hsotg_ep_sethalt(&ep->ep, set);
1109 1136
1110 ret = s3c_hsotg_send_reply(hsotg, ep0, NULL, 0); 1137 ret = s3c_hsotg_send_reply(hsotg, ep0, NULL, 0);
@@ -1114,7 +1141,12 @@ static int s3c_hsotg_process_req_feature(struct s3c_hsotg *hsotg,
1114 return ret; 1141 return ret;
1115 } 1142 }
1116 1143
1117 if (!set) { 1144 /*
1145 * we have to complete all requests for ep if it was
1146 * halted, and the halt was cleared by CLEAR_FEATURE
1147 */
1148
1149 if (!set && halted) {
1118 /* 1150 /*
1119 * If we have request in progress, 1151 * If we have request in progress,
1120 * then complete it 1152 * then complete it
@@ -1147,6 +1179,8 @@ static int s3c_hsotg_process_req_feature(struct s3c_hsotg *hsotg,
1147 return 1; 1179 return 1;
1148} 1180}
1149 1181
1182static void s3c_hsotg_enqueue_setup(struct s3c_hsotg *hsotg);
1183
1150/** 1184/**
1151 * s3c_hsotg_process_control - process a control request 1185 * s3c_hsotg_process_control - process a control request
1152 * @hsotg: The device state 1186 * @hsotg: The device state
@@ -1246,11 +1280,15 @@ static void s3c_hsotg_process_control(struct s3c_hsotg *hsotg,
1246 * don't believe we need to anything more to get the EP 1280 * don't believe we need to anything more to get the EP
1247 * to reply with a STALL packet 1281 * to reply with a STALL packet
1248 */ 1282 */
1283
1284 /*
1285 * complete won't be called, so we enqueue
1286 * setup request here
1287 */
1288 s3c_hsotg_enqueue_setup(hsotg);
1249 } 1289 }
1250} 1290}
1251 1291
1252static void s3c_hsotg_enqueue_setup(struct s3c_hsotg *hsotg);
1253
1254/** 1292/**
1255 * s3c_hsotg_complete_setup - completion of a setup transfer 1293 * s3c_hsotg_complete_setup - completion of a setup transfer
1256 * @ep: The endpoint the request was on. 1294 * @ep: The endpoint the request was on.
@@ -1698,6 +1736,7 @@ static void s3c_hsotg_set_ep_maxpacket(struct s3c_hsotg *hsotg,
1698 struct s3c_hsotg_ep *hs_ep = &hsotg->eps[ep]; 1736 struct s3c_hsotg_ep *hs_ep = &hsotg->eps[ep];
1699 void __iomem *regs = hsotg->regs; 1737 void __iomem *regs = hsotg->regs;
1700 u32 mpsval; 1738 u32 mpsval;
1739 u32 mcval;
1701 u32 reg; 1740 u32 reg;
1702 1741
1703 if (ep == 0) { 1742 if (ep == 0) {
@@ -1705,15 +1744,19 @@ static void s3c_hsotg_set_ep_maxpacket(struct s3c_hsotg *hsotg,
1705 mpsval = s3c_hsotg_ep0_mps(mps); 1744 mpsval = s3c_hsotg_ep0_mps(mps);
1706 if (mpsval > 3) 1745 if (mpsval > 3)
1707 goto bad_mps; 1746 goto bad_mps;
1747 hs_ep->ep.maxpacket = mps;
1748 hs_ep->mc = 1;
1708 } else { 1749 } else {
1709 if (mps >= DxEPCTL_MPS_LIMIT+1) 1750 mpsval = mps & DxEPCTL_MPS_MASK;
1751 if (mpsval > 1024)
1710 goto bad_mps; 1752 goto bad_mps;
1711 1753 mcval = ((mps >> 11) & 0x3) + 1;
1712 mpsval = mps; 1754 hs_ep->mc = mcval;
1755 if (mcval > 3)
1756 goto bad_mps;
1757 hs_ep->ep.maxpacket = mpsval;
1713 } 1758 }
1714 1759
1715 hs_ep->ep.maxpacket = mps;
1716
1717 /* 1760 /*
1718 * update both the in and out endpoint controldir_ registers, even 1761 * update both the in and out endpoint controldir_ registers, even
1719 * if one of the directions may not be in use. 1762 * if one of the directions may not be in use.
@@ -1782,8 +1825,16 @@ static int s3c_hsotg_trytx(struct s3c_hsotg *hsotg,
1782{ 1825{
1783 struct s3c_hsotg_req *hs_req = hs_ep->req; 1826 struct s3c_hsotg_req *hs_req = hs_ep->req;
1784 1827
1785 if (!hs_ep->dir_in || !hs_req) 1828 if (!hs_ep->dir_in || !hs_req) {
1829 /**
1830 * if request is not enqueued, we disable interrupts
1831 * for endpoints, excepting ep0
1832 */
1833 if (hs_ep->index != 0)
1834 s3c_hsotg_ctrl_epint(hsotg, hs_ep->index,
1835 hs_ep->dir_in, 0);
1786 return 0; 1836 return 0;
1837 }
1787 1838
1788 if (hs_req->req.actual < hs_req->req.length) { 1839 if (hs_req->req.actual < hs_req->req.length) {
1789 dev_dbg(hsotg->dev, "trying to write more for ep%d\n", 1840 dev_dbg(hsotg->dev, "trying to write more for ep%d\n",
@@ -1887,8 +1938,10 @@ static void s3c_hsotg_epint(struct s3c_hsotg *hsotg, unsigned int idx,
1887 u32 epctl_reg = dir_in ? DIEPCTL(idx) : DOEPCTL(idx); 1938 u32 epctl_reg = dir_in ? DIEPCTL(idx) : DOEPCTL(idx);
1888 u32 epsiz_reg = dir_in ? DIEPTSIZ(idx) : DOEPTSIZ(idx); 1939 u32 epsiz_reg = dir_in ? DIEPTSIZ(idx) : DOEPTSIZ(idx);
1889 u32 ints; 1940 u32 ints;
1941 u32 ctrl;
1890 1942
1891 ints = readl(hsotg->regs + epint_reg); 1943 ints = readl(hsotg->regs + epint_reg);
1944 ctrl = readl(hsotg->regs + epctl_reg);
1892 1945
1893 /* Clear endpoint interrupts */ 1946 /* Clear endpoint interrupts */
1894 writel(ints, hsotg->regs + epint_reg); 1947 writel(ints, hsotg->regs + epint_reg);
@@ -1897,6 +1950,14 @@ static void s3c_hsotg_epint(struct s3c_hsotg *hsotg, unsigned int idx,
1897 __func__, idx, dir_in ? "in" : "out", ints); 1950 __func__, idx, dir_in ? "in" : "out", ints);
1898 1951
1899 if (ints & DxEPINT_XferCompl) { 1952 if (ints & DxEPINT_XferCompl) {
1953 if (hs_ep->isochronous && hs_ep->interval == 1) {
1954 if (ctrl & DxEPCTL_EOFrNum)
1955 ctrl |= DxEPCTL_SetEvenFr;
1956 else
1957 ctrl |= DxEPCTL_SetOddFr;
1958 writel(ctrl, hsotg->regs + epctl_reg);
1959 }
1960
1900 dev_dbg(hsotg->dev, 1961 dev_dbg(hsotg->dev,
1901 "%s: XferCompl: DxEPCTL=0x%08x, DxEPTSIZ=%08x\n", 1962 "%s: XferCompl: DxEPCTL=0x%08x, DxEPTSIZ=%08x\n",
1902 __func__, readl(hsotg->regs + epctl_reg), 1963 __func__, readl(hsotg->regs + epctl_reg),
@@ -1963,7 +2024,7 @@ static void s3c_hsotg_epint(struct s3c_hsotg *hsotg, unsigned int idx,
1963 if (ints & DxEPINT_Back2BackSetup) 2024 if (ints & DxEPINT_Back2BackSetup)
1964 dev_dbg(hsotg->dev, "%s: B2BSetup/INEPNakEff\n", __func__); 2025 dev_dbg(hsotg->dev, "%s: B2BSetup/INEPNakEff\n", __func__);
1965 2026
1966 if (dir_in) { 2027 if (dir_in && !hs_ep->isochronous) {
1967 /* not sure if this is important, but we'll clear it anyway */ 2028 /* not sure if this is important, but we'll clear it anyway */
1968 if (ints & DIEPMSK_INTknTXFEmpMsk) { 2029 if (ints & DIEPMSK_INTknTXFEmpMsk) {
1969 dev_dbg(hsotg->dev, "%s: ep%d: INTknTXFEmpMsk\n", 2030 dev_dbg(hsotg->dev, "%s: ep%d: INTknTXFEmpMsk\n",
@@ -2092,12 +2153,14 @@ static void kill_all_requests(struct s3c_hsotg *hsotg,
2092} 2153}
2093 2154
2094#define call_gadget(_hs, _entry) \ 2155#define call_gadget(_hs, _entry) \
2156do { \
2095 if ((_hs)->gadget.speed != USB_SPEED_UNKNOWN && \ 2157 if ((_hs)->gadget.speed != USB_SPEED_UNKNOWN && \
2096 (_hs)->driver && (_hs)->driver->_entry) { \ 2158 (_hs)->driver && (_hs)->driver->_entry) { \
2097 spin_unlock(&_hs->lock); \ 2159 spin_unlock(&_hs->lock); \
2098 (_hs)->driver->_entry(&(_hs)->gadget); \ 2160 (_hs)->driver->_entry(&(_hs)->gadget); \
2099 spin_lock(&_hs->lock); \ 2161 spin_lock(&_hs->lock); \
2100 } 2162 } \
2163} while (0)
2101 2164
2102/** 2165/**
2103 * s3c_hsotg_disconnect - disconnect service 2166 * s3c_hsotg_disconnect - disconnect service
@@ -2241,15 +2304,19 @@ static void s3c_hsotg_core_init(struct s3c_hsotg *hsotg)
2241 GAHBCFG_HBstLen_Incr4, 2304 GAHBCFG_HBstLen_Incr4,
2242 hsotg->regs + GAHBCFG); 2305 hsotg->regs + GAHBCFG);
2243 else 2306 else
2244 writel(GAHBCFG_GlblIntrEn, hsotg->regs + GAHBCFG); 2307 writel(((hsotg->dedicated_fifos) ? (GAHBCFG_NPTxFEmpLvl |
2308 GAHBCFG_PTxFEmpLvl) : 0) |
2309 GAHBCFG_GlblIntrEn,
2310 hsotg->regs + GAHBCFG);
2245 2311
2246 /* 2312 /*
2247 * Enabling INTknTXFEmpMsk here seems to be a big mistake, we end 2313 * If INTknTXFEmpMsk is enabled, it's important to disable ep interrupts
2248 * up being flooded with interrupts if the host is polling the 2314 * when we have no data to transfer. Otherwise we get being flooded by
2249 * endpoint to try and read data. 2315 * interrupts.
2250 */ 2316 */
2251 2317
2252 writel(((hsotg->dedicated_fifos) ? DIEPMSK_TxFIFOEmpty : 0) | 2318 writel(((hsotg->dedicated_fifos) ? DIEPMSK_TxFIFOEmpty |
2319 DIEPMSK_INTknTXFEmpMsk : 0) |
2253 DIEPMSK_EPDisbldMsk | DIEPMSK_XferComplMsk | 2320 DIEPMSK_EPDisbldMsk | DIEPMSK_XferComplMsk |
2254 DIEPMSK_TimeOUTMsk | DIEPMSK_AHBErrMsk | 2321 DIEPMSK_TimeOUTMsk | DIEPMSK_AHBErrMsk |
2255 DIEPMSK_INTknEPMisMsk, 2322 DIEPMSK_INTknEPMisMsk,
@@ -2378,10 +2445,14 @@ irq_retry:
2378 2445
2379 if (gintsts & (GINTSTS_OEPInt | GINTSTS_IEPInt)) { 2446 if (gintsts & (GINTSTS_OEPInt | GINTSTS_IEPInt)) {
2380 u32 daint = readl(hsotg->regs + DAINT); 2447 u32 daint = readl(hsotg->regs + DAINT);
2381 u32 daint_out = daint >> DAINT_OutEP_SHIFT; 2448 u32 daintmsk = readl(hsotg->regs + DAINTMSK);
2382 u32 daint_in = daint & ~(daint_out << DAINT_OutEP_SHIFT); 2449 u32 daint_out, daint_in;
2383 int ep; 2450 int ep;
2384 2451
2452 daint &= daintmsk;
2453 daint_out = daint >> DAINT_OutEP_SHIFT;
2454 daint_in = daint & ~(daint_out << DAINT_OutEP_SHIFT);
2455
2385 dev_dbg(hsotg->dev, "%s: daint=%08x\n", __func__, daint); 2456 dev_dbg(hsotg->dev, "%s: daint=%08x\n", __func__, daint);
2386 2457
2387 for (ep = 0; ep < 15 && daint_out; ep++, daint_out >>= 1) { 2458 for (ep = 0; ep < 15 && daint_out; ep++, daint_out >>= 1) {
@@ -2577,16 +2648,25 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep,
2577 epctrl |= DxEPCTL_SNAK; 2648 epctrl |= DxEPCTL_SNAK;
2578 2649
2579 /* update the endpoint state */ 2650 /* update the endpoint state */
2580 hs_ep->ep.maxpacket = mps; 2651 s3c_hsotg_set_ep_maxpacket(hsotg, hs_ep->index, mps);
2581 2652
2582 /* default, set to non-periodic */ 2653 /* default, set to non-periodic */
2654 hs_ep->isochronous = 0;
2583 hs_ep->periodic = 0; 2655 hs_ep->periodic = 0;
2656 hs_ep->halted = 0;
2657 hs_ep->interval = desc->bInterval;
2658
2659 if (hs_ep->interval > 1 && hs_ep->mc > 1)
2660 dev_err(hsotg->dev, "MC > 1 when interval is not 1\n");
2584 2661
2585 switch (desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) { 2662 switch (desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) {
2586 case USB_ENDPOINT_XFER_ISOC: 2663 case USB_ENDPOINT_XFER_ISOC:
2587 dev_err(hsotg->dev, "no current ISOC support\n"); 2664 epctrl |= DxEPCTL_EPType_Iso;
2588 ret = -EINVAL; 2665 epctrl |= DxEPCTL_SetEvenFr;
2589 goto out; 2666 hs_ep->isochronous = 1;
2667 if (dir_in)
2668 hs_ep->periodic = 1;
2669 break;
2590 2670
2591 case USB_ENDPOINT_XFER_BULK: 2671 case USB_ENDPOINT_XFER_BULK:
2592 epctrl |= DxEPCTL_EPType_Bulk; 2672 epctrl |= DxEPCTL_EPType_Bulk;
@@ -2634,7 +2714,6 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep,
2634 /* enable the endpoint interrupt */ 2714 /* enable the endpoint interrupt */
2635 s3c_hsotg_ctrl_epint(hsotg, index, dir_in, 1); 2715 s3c_hsotg_ctrl_epint(hsotg, index, dir_in, 1);
2636 2716
2637out:
2638 spin_unlock_irqrestore(&hsotg->lock, flags); 2717 spin_unlock_irqrestore(&hsotg->lock, flags);
2639 return ret; 2718 return ret;
2640} 2719}
@@ -2776,6 +2855,8 @@ static int s3c_hsotg_ep_sethalt(struct usb_ep *ep, int value)
2776 2855
2777 writel(epctl, hs->regs + epreg); 2856 writel(epctl, hs->regs + epreg);
2778 2857
2858 hs_ep->halted = value;
2859
2779 return 0; 2860 return 0;
2780} 2861}
2781 2862
@@ -2903,7 +2984,7 @@ static int s3c_hsotg_udc_start(struct usb_gadget *gadget,
2903 int ret; 2984 int ret;
2904 2985
2905 if (!hsotg) { 2986 if (!hsotg) {
2906 printk(KERN_ERR "%s: called with no device\n", __func__); 2987 pr_err("%s: called with no device\n", __func__);
2907 return -ENODEV; 2988 return -ENODEV;
2908 } 2989 }
2909 2990
@@ -3066,7 +3147,7 @@ static void s3c_hsotg_initep(struct s3c_hsotg *hsotg,
3066 3147
3067 hs_ep->parent = hsotg; 3148 hs_ep->parent = hsotg;
3068 hs_ep->ep.name = hs_ep->name; 3149 hs_ep->ep.name = hs_ep->name;
3069 hs_ep->ep.maxpacket = epnum ? 512 : EP0_MPS_LIMIT; 3150 hs_ep->ep.maxpacket = epnum ? 1024 : EP0_MPS_LIMIT;
3070 hs_ep->ep.ops = &s3c_hsotg_ep_ops; 3151 hs_ep->ep.ops = &s3c_hsotg_ep_ops;
3071 3152
3072 /* 3153 /*
@@ -3200,7 +3281,7 @@ static int state_show(struct seq_file *seq, void *v)
3200 readl(regs + GNPTXSTS), 3281 readl(regs + GNPTXSTS),
3201 readl(regs + GRXSTSR)); 3282 readl(regs + GRXSTSR));
3202 3283
3203 seq_printf(seq, "\nEndpoint status:\n"); 3284 seq_puts(seq, "\nEndpoint status:\n");
3204 3285
3205 for (idx = 0; idx < 15; idx++) { 3286 for (idx = 0; idx < 15; idx++) {
3206 u32 in, out; 3287 u32 in, out;
@@ -3217,7 +3298,7 @@ static int state_show(struct seq_file *seq, void *v)
3217 seq_printf(seq, ", DIEPTSIZ=0x%08x, DOEPTSIZ=0x%08x", 3298 seq_printf(seq, ", DIEPTSIZ=0x%08x, DOEPTSIZ=0x%08x",
3218 in, out); 3299 in, out);
3219 3300
3220 seq_printf(seq, "\n"); 3301 seq_puts(seq, "\n");
3221 } 3302 }
3222 3303
3223 return 0; 3304 return 0;
@@ -3251,7 +3332,7 @@ static int fifo_show(struct seq_file *seq, void *v)
3251 u32 val; 3332 u32 val;
3252 int idx; 3333 int idx;
3253 3334
3254 seq_printf(seq, "Non-periodic FIFOs:\n"); 3335 seq_puts(seq, "Non-periodic FIFOs:\n");
3255 seq_printf(seq, "RXFIFO: Size %d\n", readl(regs + GRXFSIZ)); 3336 seq_printf(seq, "RXFIFO: Size %d\n", readl(regs + GRXFSIZ));
3256 3337
3257 val = readl(regs + GNPTXFSIZ); 3338 val = readl(regs + GNPTXFSIZ);
@@ -3259,7 +3340,7 @@ static int fifo_show(struct seq_file *seq, void *v)
3259 val >> GNPTXFSIZ_NPTxFDep_SHIFT, 3340 val >> GNPTXFSIZ_NPTxFDep_SHIFT,
3260 val & GNPTXFSIZ_NPTxFStAddr_MASK); 3341 val & GNPTXFSIZ_NPTxFStAddr_MASK);
3261 3342
3262 seq_printf(seq, "\nPeriodic TXFIFOs:\n"); 3343 seq_puts(seq, "\nPeriodic TXFIFOs:\n");
3263 3344
3264 for (idx = 1; idx <= 15; idx++) { 3345 for (idx = 1; idx <= 15; idx++) {
3265 val = readl(regs + DPTXFSIZn(idx)); 3346 val = readl(regs + DPTXFSIZn(idx));
@@ -3330,7 +3411,7 @@ static int ep_show(struct seq_file *seq, void *v)
3330 readl(regs + DIEPTSIZ(index)), 3411 readl(regs + DIEPTSIZ(index)),
3331 readl(regs + DOEPTSIZ(index))); 3412 readl(regs + DOEPTSIZ(index)));
3332 3413
3333 seq_printf(seq, "\n"); 3414 seq_puts(seq, "\n");
3334 seq_printf(seq, "mps %d\n", ep->ep.maxpacket); 3415 seq_printf(seq, "mps %d\n", ep->ep.maxpacket);
3335 seq_printf(seq, "total_data=%ld\n", ep->total_data); 3416 seq_printf(seq, "total_data=%ld\n", ep->total_data);
3336 3417
@@ -3341,7 +3422,7 @@ static int ep_show(struct seq_file *seq, void *v)
3341 3422
3342 list_for_each_entry(req, &ep->queue, queue) { 3423 list_for_each_entry(req, &ep->queue, queue) {
3343 if (--show_limit < 0) { 3424 if (--show_limit < 0) {
3344 seq_printf(seq, "not showing more requests...\n"); 3425 seq_puts(seq, "not showing more requests...\n");
3345 break; 3426 break;
3346 } 3427 }
3347 3428
diff --git a/drivers/usb/gadget/storage_common.c b/drivers/usb/gadget/storage_common.c
index 08a1a3210a21..ec20a1f50c2d 100644
--- a/drivers/usb/gadget/storage_common.c
+++ b/drivers/usb/gadget/storage_common.c
@@ -23,242 +23,17 @@
23 * The valid range of num_buffers is: num >= 2 && num <= 4. 23 * The valid range of num_buffers is: num >= 2 && num <= 4.
24 */ 24 */
25 25
26#include <linux/module.h>
27#include <linux/blkdev.h>
28#include <linux/file.h>
29#include <linux/fs.h>
30#include <linux/usb/composite.h>
26 31
27#include <linux/usb/storage.h> 32#include "storage_common.h"
28#include <scsi/scsi.h>
29#include <asm/unaligned.h>
30
31
32/*
33 * Thanks to NetChip Technologies for donating this product ID.
34 *
35 * DO NOT REUSE THESE IDs with any other driver!! Ever!!
36 * Instead: allocate your own, using normal USB-IF procedures.
37 */
38#define FSG_VENDOR_ID 0x0525 /* NetChip */
39#define FSG_PRODUCT_ID 0xa4a5 /* Linux-USB File-backed Storage Gadget */
40
41
42/*-------------------------------------------------------------------------*/
43
44
45#ifndef DEBUG
46#undef VERBOSE_DEBUG
47#undef DUMP_MSGS
48#endif /* !DEBUG */
49
50#ifdef VERBOSE_DEBUG
51#define VLDBG LDBG
52#else
53#define VLDBG(lun, fmt, args...) do { } while (0)
54#endif /* VERBOSE_DEBUG */
55
56#define LDBG(lun, fmt, args...) dev_dbg (&(lun)->dev, fmt, ## args)
57#define LERROR(lun, fmt, args...) dev_err (&(lun)->dev, fmt, ## args)
58#define LWARN(lun, fmt, args...) dev_warn(&(lun)->dev, fmt, ## args)
59#define LINFO(lun, fmt, args...) dev_info(&(lun)->dev, fmt, ## args)
60
61
62#ifdef DUMP_MSGS
63
64# define dump_msg(fsg, /* const char * */ label, \
65 /* const u8 * */ buf, /* unsigned */ length) do { \
66 if (length < 512) { \
67 DBG(fsg, "%s, length %u:\n", label, length); \
68 print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, \
69 16, 1, buf, length, 0); \
70 } \
71} while (0)
72
73# define dump_cdb(fsg) do { } while (0)
74
75#else
76
77# define dump_msg(fsg, /* const char * */ label, \
78 /* const u8 * */ buf, /* unsigned */ length) do { } while (0)
79
80# ifdef VERBOSE_DEBUG
81
82# define dump_cdb(fsg) \
83 print_hex_dump(KERN_DEBUG, "SCSI CDB: ", DUMP_PREFIX_NONE, \
84 16, 1, (fsg)->cmnd, (fsg)->cmnd_size, 0) \
85
86# else
87
88# define dump_cdb(fsg) do { } while (0)
89
90# endif /* VERBOSE_DEBUG */
91
92#endif /* DUMP_MSGS */
93
94/*-------------------------------------------------------------------------*/
95
96/* Length of a SCSI Command Data Block */
97#define MAX_COMMAND_SIZE 16
98
99/* SCSI Sense Key/Additional Sense Code/ASC Qualifier values */
100#define SS_NO_SENSE 0
101#define SS_COMMUNICATION_FAILURE 0x040800
102#define SS_INVALID_COMMAND 0x052000
103#define SS_INVALID_FIELD_IN_CDB 0x052400
104#define SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE 0x052100
105#define SS_LOGICAL_UNIT_NOT_SUPPORTED 0x052500
106#define SS_MEDIUM_NOT_PRESENT 0x023a00
107#define SS_MEDIUM_REMOVAL_PREVENTED 0x055302
108#define SS_NOT_READY_TO_READY_TRANSITION 0x062800
109#define SS_RESET_OCCURRED 0x062900
110#define SS_SAVING_PARAMETERS_NOT_SUPPORTED 0x053900
111#define SS_UNRECOVERED_READ_ERROR 0x031100
112#define SS_WRITE_ERROR 0x030c02
113#define SS_WRITE_PROTECTED 0x072700
114
115#define SK(x) ((u8) ((x) >> 16)) /* Sense Key byte, etc. */
116#define ASC(x) ((u8) ((x) >> 8))
117#define ASCQ(x) ((u8) (x))
118
119
120/*-------------------------------------------------------------------------*/
121
122
123struct fsg_lun {
124 struct file *filp;
125 loff_t file_length;
126 loff_t num_sectors;
127
128 unsigned int initially_ro:1;
129 unsigned int ro:1;
130 unsigned int removable:1;
131 unsigned int cdrom:1;
132 unsigned int prevent_medium_removal:1;
133 unsigned int registered:1;
134 unsigned int info_valid:1;
135 unsigned int nofua:1;
136
137 u32 sense_data;
138 u32 sense_data_info;
139 u32 unit_attention_data;
140
141 unsigned int blkbits; /* Bits of logical block size of bound block device */
142 unsigned int blksize; /* logical block size of bound block device */
143 struct device dev;
144};
145
146static inline bool fsg_lun_is_open(struct fsg_lun *curlun)
147{
148 return curlun->filp != NULL;
149}
150
151static inline struct fsg_lun *fsg_lun_from_dev(struct device *dev)
152{
153 return container_of(dev, struct fsg_lun, dev);
154}
155
156
157/* Big enough to hold our biggest descriptor */
158#define EP0_BUFSIZE 256
159#define DELAYED_STATUS (EP0_BUFSIZE + 999) /* An impossibly large value */
160
161#ifdef CONFIG_USB_GADGET_DEBUG_FILES
162
163static unsigned int fsg_num_buffers = CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS;
164module_param_named(num_buffers, fsg_num_buffers, uint, S_IRUGO);
165MODULE_PARM_DESC(num_buffers, "Number of pipeline buffers");
166
167#else
168
169/*
170 * Number of buffers we will use.
171 * 2 is usually enough for good buffering pipeline
172 */
173#define fsg_num_buffers CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS
174
175#endif /* CONFIG_USB_GADGET_DEBUG_FILES */
176
177/* check if fsg_num_buffers is within a valid range */
178static inline int fsg_num_buffers_validate(void)
179{
180 if (fsg_num_buffers >= 2 && fsg_num_buffers <= 4)
181 return 0;
182 pr_err("fsg_num_buffers %u is out of range (%d to %d)\n",
183 fsg_num_buffers, 2 ,4);
184 return -EINVAL;
185}
186
187/* Default size of buffer length. */
188#define FSG_BUFLEN ((u32)16384)
189
190/* Maximal number of LUNs supported in mass storage function */
191#define FSG_MAX_LUNS 8
192
193enum fsg_buffer_state {
194 BUF_STATE_EMPTY = 0,
195 BUF_STATE_FULL,
196 BUF_STATE_BUSY
197};
198
199struct fsg_buffhd {
200 void *buf;
201 enum fsg_buffer_state state;
202 struct fsg_buffhd *next;
203
204 /*
205 * The NetChip 2280 is faster, and handles some protocol faults
206 * better, if we don't submit any short bulk-out read requests.
207 * So we will record the intended request length here.
208 */
209 unsigned int bulk_out_intended_length;
210
211 struct usb_request *inreq;
212 int inreq_busy;
213 struct usb_request *outreq;
214 int outreq_busy;
215};
216
217enum fsg_state {
218 /* This one isn't used anywhere */
219 FSG_STATE_COMMAND_PHASE = -10,
220 FSG_STATE_DATA_PHASE,
221 FSG_STATE_STATUS_PHASE,
222
223 FSG_STATE_IDLE = 0,
224 FSG_STATE_ABORT_BULK_OUT,
225 FSG_STATE_RESET,
226 FSG_STATE_INTERFACE_CHANGE,
227 FSG_STATE_CONFIG_CHANGE,
228 FSG_STATE_DISCONNECT,
229 FSG_STATE_EXIT,
230 FSG_STATE_TERMINATED
231};
232
233enum data_direction {
234 DATA_DIR_UNKNOWN = 0,
235 DATA_DIR_FROM_HOST,
236 DATA_DIR_TO_HOST,
237 DATA_DIR_NONE
238};
239
240
241/*-------------------------------------------------------------------------*/
242
243
244static inline u32 get_unaligned_be24(u8 *buf)
245{
246 return 0xffffff & (u32) get_unaligned_be32(buf - 1);
247}
248
249
250/*-------------------------------------------------------------------------*/
251
252
253enum {
254 FSG_STRING_INTERFACE
255};
256
257 33
258/* There is only one interface. */ 34/* There is only one interface. */
259 35
260static struct usb_interface_descriptor 36struct usb_interface_descriptor fsg_intf_desc = {
261fsg_intf_desc = {
262 .bLength = sizeof fsg_intf_desc, 37 .bLength = sizeof fsg_intf_desc,
263 .bDescriptorType = USB_DT_INTERFACE, 38 .bDescriptorType = USB_DT_INTERFACE,
264 39
@@ -268,14 +43,14 @@ fsg_intf_desc = {
268 .bInterfaceProtocol = USB_PR_BULK, /* Adjusted during fsg_bind() */ 43 .bInterfaceProtocol = USB_PR_BULK, /* Adjusted during fsg_bind() */
269 .iInterface = FSG_STRING_INTERFACE, 44 .iInterface = FSG_STRING_INTERFACE,
270}; 45};
46EXPORT_SYMBOL(fsg_intf_desc);
271 47
272/* 48/*
273 * Three full-speed endpoint descriptors: bulk-in, bulk-out, and 49 * Three full-speed endpoint descriptors: bulk-in, bulk-out, and
274 * interrupt-in. 50 * interrupt-in.
275 */ 51 */
276 52
277static struct usb_endpoint_descriptor 53struct usb_endpoint_descriptor fsg_fs_bulk_in_desc = {
278fsg_fs_bulk_in_desc = {
279 .bLength = USB_DT_ENDPOINT_SIZE, 54 .bLength = USB_DT_ENDPOINT_SIZE,
280 .bDescriptorType = USB_DT_ENDPOINT, 55 .bDescriptorType = USB_DT_ENDPOINT,
281 56
@@ -283,9 +58,9 @@ fsg_fs_bulk_in_desc = {
283 .bmAttributes = USB_ENDPOINT_XFER_BULK, 58 .bmAttributes = USB_ENDPOINT_XFER_BULK,
284 /* wMaxPacketSize set by autoconfiguration */ 59 /* wMaxPacketSize set by autoconfiguration */
285}; 60};
61EXPORT_SYMBOL(fsg_fs_bulk_in_desc);
286 62
287static struct usb_endpoint_descriptor 63struct usb_endpoint_descriptor fsg_fs_bulk_out_desc = {
288fsg_fs_bulk_out_desc = {
289 .bLength = USB_DT_ENDPOINT_SIZE, 64 .bLength = USB_DT_ENDPOINT_SIZE,
290 .bDescriptorType = USB_DT_ENDPOINT, 65 .bDescriptorType = USB_DT_ENDPOINT,
291 66
@@ -293,13 +68,15 @@ fsg_fs_bulk_out_desc = {
293 .bmAttributes = USB_ENDPOINT_XFER_BULK, 68 .bmAttributes = USB_ENDPOINT_XFER_BULK,
294 /* wMaxPacketSize set by autoconfiguration */ 69 /* wMaxPacketSize set by autoconfiguration */
295}; 70};
71EXPORT_SYMBOL(fsg_fs_bulk_out_desc);
296 72
297static struct usb_descriptor_header *fsg_fs_function[] = { 73struct usb_descriptor_header *fsg_fs_function[] = {
298 (struct usb_descriptor_header *) &fsg_intf_desc, 74 (struct usb_descriptor_header *) &fsg_intf_desc,
299 (struct usb_descriptor_header *) &fsg_fs_bulk_in_desc, 75 (struct usb_descriptor_header *) &fsg_fs_bulk_in_desc,
300 (struct usb_descriptor_header *) &fsg_fs_bulk_out_desc, 76 (struct usb_descriptor_header *) &fsg_fs_bulk_out_desc,
301 NULL, 77 NULL,
302}; 78};
79EXPORT_SYMBOL(fsg_fs_function);
303 80
304 81
305/* 82/*
@@ -310,8 +87,7 @@ static struct usb_descriptor_header *fsg_fs_function[] = {
310 * and a "device qualifier" ... plus more construction options 87 * and a "device qualifier" ... plus more construction options
311 * for the configuration descriptor. 88 * for the configuration descriptor.
312 */ 89 */
313static struct usb_endpoint_descriptor 90struct usb_endpoint_descriptor fsg_hs_bulk_in_desc = {
314fsg_hs_bulk_in_desc = {
315 .bLength = USB_DT_ENDPOINT_SIZE, 91 .bLength = USB_DT_ENDPOINT_SIZE,
316 .bDescriptorType = USB_DT_ENDPOINT, 92 .bDescriptorType = USB_DT_ENDPOINT,
317 93
@@ -319,9 +95,9 @@ fsg_hs_bulk_in_desc = {
319 .bmAttributes = USB_ENDPOINT_XFER_BULK, 95 .bmAttributes = USB_ENDPOINT_XFER_BULK,
320 .wMaxPacketSize = cpu_to_le16(512), 96 .wMaxPacketSize = cpu_to_le16(512),
321}; 97};
98EXPORT_SYMBOL(fsg_hs_bulk_in_desc);
322 99
323static struct usb_endpoint_descriptor 100struct usb_endpoint_descriptor fsg_hs_bulk_out_desc = {
324fsg_hs_bulk_out_desc = {
325 .bLength = USB_DT_ENDPOINT_SIZE, 101 .bLength = USB_DT_ENDPOINT_SIZE,
326 .bDescriptorType = USB_DT_ENDPOINT, 102 .bDescriptorType = USB_DT_ENDPOINT,
327 103
@@ -330,17 +106,18 @@ fsg_hs_bulk_out_desc = {
330 .wMaxPacketSize = cpu_to_le16(512), 106 .wMaxPacketSize = cpu_to_le16(512),
331 .bInterval = 1, /* NAK every 1 uframe */ 107 .bInterval = 1, /* NAK every 1 uframe */
332}; 108};
109EXPORT_SYMBOL(fsg_hs_bulk_out_desc);
333 110
334 111
335static struct usb_descriptor_header *fsg_hs_function[] = { 112struct usb_descriptor_header *fsg_hs_function[] = {
336 (struct usb_descriptor_header *) &fsg_intf_desc, 113 (struct usb_descriptor_header *) &fsg_intf_desc,
337 (struct usb_descriptor_header *) &fsg_hs_bulk_in_desc, 114 (struct usb_descriptor_header *) &fsg_hs_bulk_in_desc,
338 (struct usb_descriptor_header *) &fsg_hs_bulk_out_desc, 115 (struct usb_descriptor_header *) &fsg_hs_bulk_out_desc,
339 NULL, 116 NULL,
340}; 117};
118EXPORT_SYMBOL(fsg_hs_function);
341 119
342static struct usb_endpoint_descriptor 120struct usb_endpoint_descriptor fsg_ss_bulk_in_desc = {
343fsg_ss_bulk_in_desc = {
344 .bLength = USB_DT_ENDPOINT_SIZE, 121 .bLength = USB_DT_ENDPOINT_SIZE,
345 .bDescriptorType = USB_DT_ENDPOINT, 122 .bDescriptorType = USB_DT_ENDPOINT,
346 123
@@ -348,16 +125,17 @@ fsg_ss_bulk_in_desc = {
348 .bmAttributes = USB_ENDPOINT_XFER_BULK, 125 .bmAttributes = USB_ENDPOINT_XFER_BULK,
349 .wMaxPacketSize = cpu_to_le16(1024), 126 .wMaxPacketSize = cpu_to_le16(1024),
350}; 127};
128EXPORT_SYMBOL(fsg_ss_bulk_in_desc);
351 129
352static struct usb_ss_ep_comp_descriptor fsg_ss_bulk_in_comp_desc = { 130struct usb_ss_ep_comp_descriptor fsg_ss_bulk_in_comp_desc = {
353 .bLength = sizeof(fsg_ss_bulk_in_comp_desc), 131 .bLength = sizeof(fsg_ss_bulk_in_comp_desc),
354 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, 132 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
355 133
356 /*.bMaxBurst = DYNAMIC, */ 134 /*.bMaxBurst = DYNAMIC, */
357}; 135};
136EXPORT_SYMBOL(fsg_ss_bulk_in_comp_desc);
358 137
359static struct usb_endpoint_descriptor 138struct usb_endpoint_descriptor fsg_ss_bulk_out_desc = {
360fsg_ss_bulk_out_desc = {
361 .bLength = USB_DT_ENDPOINT_SIZE, 139 .bLength = USB_DT_ENDPOINT_SIZE,
362 .bDescriptorType = USB_DT_ENDPOINT, 140 .bDescriptorType = USB_DT_ENDPOINT,
363 141
@@ -365,15 +143,17 @@ fsg_ss_bulk_out_desc = {
365 .bmAttributes = USB_ENDPOINT_XFER_BULK, 143 .bmAttributes = USB_ENDPOINT_XFER_BULK,
366 .wMaxPacketSize = cpu_to_le16(1024), 144 .wMaxPacketSize = cpu_to_le16(1024),
367}; 145};
146EXPORT_SYMBOL(fsg_ss_bulk_out_desc);
368 147
369static struct usb_ss_ep_comp_descriptor fsg_ss_bulk_out_comp_desc = { 148struct usb_ss_ep_comp_descriptor fsg_ss_bulk_out_comp_desc = {
370 .bLength = sizeof(fsg_ss_bulk_in_comp_desc), 149 .bLength = sizeof(fsg_ss_bulk_in_comp_desc),
371 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, 150 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
372 151
373 /*.bMaxBurst = DYNAMIC, */ 152 /*.bMaxBurst = DYNAMIC, */
374}; 153};
154EXPORT_SYMBOL(fsg_ss_bulk_out_comp_desc);
375 155
376static struct usb_descriptor_header *fsg_ss_function[] = { 156struct usb_descriptor_header *fsg_ss_function[] = {
377 (struct usb_descriptor_header *) &fsg_intf_desc, 157 (struct usb_descriptor_header *) &fsg_intf_desc,
378 (struct usb_descriptor_header *) &fsg_ss_bulk_in_desc, 158 (struct usb_descriptor_header *) &fsg_ss_bulk_in_desc,
379 (struct usb_descriptor_header *) &fsg_ss_bulk_in_comp_desc, 159 (struct usb_descriptor_header *) &fsg_ss_bulk_in_comp_desc,
@@ -381,17 +161,7 @@ static struct usb_descriptor_header *fsg_ss_function[] = {
381 (struct usb_descriptor_header *) &fsg_ss_bulk_out_comp_desc, 161 (struct usb_descriptor_header *) &fsg_ss_bulk_out_comp_desc,
382 NULL, 162 NULL,
383}; 163};
384 164EXPORT_SYMBOL(fsg_ss_function);
385/* Static strings, in UTF-8 (for simplicity we use only ASCII characters) */
386static struct usb_string fsg_strings[] = {
387 {FSG_STRING_INTERFACE, fsg_string_interface},
388 {}
389};
390
391static struct usb_gadget_strings fsg_stringtab = {
392 .language = 0x0409, /* en-us */
393 .strings = fsg_strings,
394};
395 165
396 166
397 /*-------------------------------------------------------------------------*/ 167 /*-------------------------------------------------------------------------*/
@@ -401,7 +171,7 @@ static struct usb_gadget_strings fsg_stringtab = {
401 * the caller must own fsg->filesem for writing. 171 * the caller must own fsg->filesem for writing.
402 */ 172 */
403 173
404static void fsg_lun_close(struct fsg_lun *curlun) 174void fsg_lun_close(struct fsg_lun *curlun)
405{ 175{
406 if (curlun->filp) { 176 if (curlun->filp) {
407 LDBG(curlun, "close backing file\n"); 177 LDBG(curlun, "close backing file\n");
@@ -409,9 +179,9 @@ static void fsg_lun_close(struct fsg_lun *curlun)
409 curlun->filp = NULL; 179 curlun->filp = NULL;
410 } 180 }
411} 181}
182EXPORT_SYMBOL(fsg_lun_close);
412 183
413 184int fsg_lun_open(struct fsg_lun *curlun, const char *filename)
414static int fsg_lun_open(struct fsg_lun *curlun, const char *filename)
415{ 185{
416 int ro; 186 int ro;
417 struct file *filp = NULL; 187 struct file *filp = NULL;
@@ -508,6 +278,7 @@ out:
508 fput(filp); 278 fput(filp);
509 return rc; 279 return rc;
510} 280}
281EXPORT_SYMBOL(fsg_lun_open);
511 282
512 283
513/*-------------------------------------------------------------------------*/ 284/*-------------------------------------------------------------------------*/
@@ -516,7 +287,7 @@ out:
516 * Sync the file data, don't bother with the metadata. 287 * Sync the file data, don't bother with the metadata.
517 * This code was copied from fs/buffer.c:sys_fdatasync(). 288 * This code was copied from fs/buffer.c:sys_fdatasync().
518 */ 289 */
519static int fsg_lun_fsync_sub(struct fsg_lun *curlun) 290int fsg_lun_fsync_sub(struct fsg_lun *curlun)
520{ 291{
521 struct file *filp = curlun->filp; 292 struct file *filp = curlun->filp;
522 293
@@ -524,8 +295,9 @@ static int fsg_lun_fsync_sub(struct fsg_lun *curlun)
524 return 0; 295 return 0;
525 return vfs_fsync(filp, 1); 296 return vfs_fsync(filp, 1);
526} 297}
298EXPORT_SYMBOL(fsg_lun_fsync_sub);
527 299
528static void store_cdrom_address(u8 *dest, int msf, u32 addr) 300void store_cdrom_address(u8 *dest, int msf, u32 addr)
529{ 301{
530 if (msf) { 302 if (msf) {
531 /* Convert to Minutes-Seconds-Frames */ 303 /* Convert to Minutes-Seconds-Frames */
@@ -542,34 +314,28 @@ static void store_cdrom_address(u8 *dest, int msf, u32 addr)
542 put_unaligned_be32(addr, dest); 314 put_unaligned_be32(addr, dest);
543 } 315 }
544} 316}
545 317EXPORT_SYMBOL(store_cdrom_address);
546 318
547/*-------------------------------------------------------------------------*/ 319/*-------------------------------------------------------------------------*/
548 320
549 321
550static ssize_t ro_show(struct device *dev, struct device_attribute *attr, 322ssize_t fsg_show_ro(struct fsg_lun *curlun, char *buf)
551 char *buf)
552{ 323{
553 struct fsg_lun *curlun = fsg_lun_from_dev(dev);
554
555 return sprintf(buf, "%d\n", fsg_lun_is_open(curlun) 324 return sprintf(buf, "%d\n", fsg_lun_is_open(curlun)
556 ? curlun->ro 325 ? curlun->ro
557 : curlun->initially_ro); 326 : curlun->initially_ro);
558} 327}
328EXPORT_SYMBOL(fsg_show_ro);
559 329
560static ssize_t nofua_show(struct device *dev, struct device_attribute *attr, 330ssize_t fsg_show_nofua(struct fsg_lun *curlun, char *buf)
561 char *buf)
562{ 331{
563 struct fsg_lun *curlun = fsg_lun_from_dev(dev);
564
565 return sprintf(buf, "%u\n", curlun->nofua); 332 return sprintf(buf, "%u\n", curlun->nofua);
566} 333}
334EXPORT_SYMBOL(fsg_show_nofua);
567 335
568static ssize_t file_show(struct device *dev, struct device_attribute *attr, 336ssize_t fsg_show_file(struct fsg_lun *curlun, struct rw_semaphore *filesem,
569 char *buf) 337 char *buf)
570{ 338{
571 struct fsg_lun *curlun = fsg_lun_from_dev(dev);
572 struct rw_semaphore *filesem = dev_get_drvdata(dev);
573 char *p; 339 char *p;
574 ssize_t rc; 340 ssize_t rc;
575 341
@@ -591,17 +357,44 @@ static ssize_t file_show(struct device *dev, struct device_attribute *attr,
591 up_read(filesem); 357 up_read(filesem);
592 return rc; 358 return rc;
593} 359}
360EXPORT_SYMBOL(fsg_show_file);
594 361
362ssize_t fsg_show_cdrom(struct fsg_lun *curlun, char *buf)
363{
364 return sprintf(buf, "%u\n", curlun->cdrom);
365}
366EXPORT_SYMBOL(fsg_show_cdrom);
595 367
596static ssize_t ro_store(struct device *dev, struct device_attribute *attr, 368ssize_t fsg_show_removable(struct fsg_lun *curlun, char *buf)
597 const char *buf, size_t count) 369{
370 return sprintf(buf, "%u\n", curlun->removable);
371}
372EXPORT_SYMBOL(fsg_show_removable);
373
374/*
375 * The caller must hold fsg->filesem for reading when calling this function.
376 */
377static ssize_t _fsg_store_ro(struct fsg_lun *curlun, bool ro)
378{
379 if (fsg_lun_is_open(curlun)) {
380 LDBG(curlun, "read-only status change prevented\n");
381 return -EBUSY;
382 }
383
384 curlun->ro = ro;
385 curlun->initially_ro = ro;
386 LDBG(curlun, "read-only status set to %d\n", curlun->ro);
387
388 return 0;
389}
390
391ssize_t fsg_store_ro(struct fsg_lun *curlun, struct rw_semaphore *filesem,
392 const char *buf, size_t count)
598{ 393{
599 ssize_t rc; 394 ssize_t rc;
600 struct fsg_lun *curlun = fsg_lun_from_dev(dev); 395 bool ro;
601 struct rw_semaphore *filesem = dev_get_drvdata(dev);
602 unsigned ro;
603 396
604 rc = kstrtouint(buf, 2, &ro); 397 rc = strtobool(buf, &ro);
605 if (rc) 398 if (rc)
606 return rc; 399 return rc;
607 400
@@ -610,27 +403,21 @@ static ssize_t ro_store(struct device *dev, struct device_attribute *attr,
610 * backing file is closed. 403 * backing file is closed.
611 */ 404 */
612 down_read(filesem); 405 down_read(filesem);
613 if (fsg_lun_is_open(curlun)) { 406 rc = _fsg_store_ro(curlun, ro);
614 LDBG(curlun, "read-only status change prevented\n"); 407 if (!rc)
615 rc = -EBUSY;
616 } else {
617 curlun->ro = ro;
618 curlun->initially_ro = ro;
619 LDBG(curlun, "read-only status set to %d\n", curlun->ro);
620 rc = count; 408 rc = count;
621 }
622 up_read(filesem); 409 up_read(filesem);
410
623 return rc; 411 return rc;
624} 412}
413EXPORT_SYMBOL(fsg_store_ro);
625 414
626static ssize_t nofua_store(struct device *dev, struct device_attribute *attr, 415ssize_t fsg_store_nofua(struct fsg_lun *curlun, const char *buf, size_t count)
627 const char *buf, size_t count)
628{ 416{
629 struct fsg_lun *curlun = fsg_lun_from_dev(dev); 417 bool nofua;
630 unsigned nofua;
631 int ret; 418 int ret;
632 419
633 ret = kstrtouint(buf, 2, &nofua); 420 ret = strtobool(buf, &nofua);
634 if (ret) 421 if (ret)
635 return ret; 422 return ret;
636 423
@@ -642,12 +429,11 @@ static ssize_t nofua_store(struct device *dev, struct device_attribute *attr,
642 429
643 return count; 430 return count;
644} 431}
432EXPORT_SYMBOL(fsg_store_nofua);
645 433
646static ssize_t file_store(struct device *dev, struct device_attribute *attr, 434ssize_t fsg_store_file(struct fsg_lun *curlun, struct rw_semaphore *filesem,
647 const char *buf, size_t count) 435 const char *buf, size_t count)
648{ 436{
649 struct fsg_lun *curlun = fsg_lun_from_dev(dev);
650 struct rw_semaphore *filesem = dev_get_drvdata(dev);
651 int rc = 0; 437 int rc = 0;
652 438
653 if (curlun->prevent_medium_removal && fsg_lun_is_open(curlun)) { 439 if (curlun->prevent_medium_removal && fsg_lun_is_open(curlun)) {
@@ -674,3 +460,45 @@ static ssize_t file_store(struct device *dev, struct device_attribute *attr,
674 up_write(filesem); 460 up_write(filesem);
675 return (rc < 0 ? rc : count); 461 return (rc < 0 ? rc : count);
676} 462}
463EXPORT_SYMBOL(fsg_store_file);
464
465ssize_t fsg_store_cdrom(struct fsg_lun *curlun, struct rw_semaphore *filesem,
466 const char *buf, size_t count)
467{
468 bool cdrom;
469 int ret;
470
471 ret = strtobool(buf, &cdrom);
472 if (ret)
473 return ret;
474
475 down_read(filesem);
476 ret = cdrom ? _fsg_store_ro(curlun, true) : 0;
477
478 if (!ret) {
479 curlun->cdrom = cdrom;
480 ret = count;
481 }
482 up_read(filesem);
483
484 return ret;
485}
486EXPORT_SYMBOL(fsg_store_cdrom);
487
488ssize_t fsg_store_removable(struct fsg_lun *curlun, const char *buf,
489 size_t count)
490{
491 bool removable;
492 int ret;
493
494 ret = strtobool(buf, &removable);
495 if (ret)
496 return ret;
497
498 curlun->removable = removable;
499
500 return count;
501}
502EXPORT_SYMBOL(fsg_store_removable);
503
504MODULE_LICENSE("GPL");
diff --git a/drivers/usb/gadget/storage_common.h b/drivers/usb/gadget/storage_common.h
new file mode 100644
index 000000000000..c74c2fdbd56e
--- /dev/null
+++ b/drivers/usb/gadget/storage_common.h
@@ -0,0 +1,229 @@
1#ifndef USB_STORAGE_COMMON_H
2#define USB_STORAGE_COMMON_H
3
4#include <linux/device.h>
5#include <linux/usb/storage.h>
6#include <scsi/scsi.h>
7#include <asm/unaligned.h>
8
9#ifndef DEBUG
10#undef VERBOSE_DEBUG
11#undef DUMP_MSGS
12#endif /* !DEBUG */
13
14#ifdef VERBOSE_DEBUG
15#define VLDBG LDBG
16#else
17#define VLDBG(lun, fmt, args...) do { } while (0)
18#endif /* VERBOSE_DEBUG */
19
20#define _LMSG(func, lun, fmt, args...) \
21 do { \
22 if ((lun)->name_pfx && *(lun)->name_pfx) \
23 func("%s/%s: " fmt, *(lun)->name_pfx, \
24 (lun)->name, ## args); \
25 else \
26 func("%s: " fmt, (lun)->name, ## args); \
27 } while (0)
28
29#define LDBG(lun, fmt, args...) _LMSG(pr_debug, lun, fmt, ## args)
30#define LERROR(lun, fmt, args...) _LMSG(pr_err, lun, fmt, ## args)
31#define LWARN(lun, fmt, args...) _LMSG(pr_warn, lun, fmt, ## args)
32#define LINFO(lun, fmt, args...) _LMSG(pr_info, lun, fmt, ## args)
33
34
35#ifdef DUMP_MSGS
36
37# define dump_msg(fsg, /* const char * */ label, \
38 /* const u8 * */ buf, /* unsigned */ length) \
39do { \
40 if (length < 512) { \
41 DBG(fsg, "%s, length %u:\n", label, length); \
42 print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, \
43 16, 1, buf, length, 0); \
44 } \
45} while (0)
46
47# define dump_cdb(fsg) do { } while (0)
48
49#else
50
51# define dump_msg(fsg, /* const char * */ label, \
52 /* const u8 * */ buf, /* unsigned */ length) do { } while (0)
53
54# ifdef VERBOSE_DEBUG
55
56# define dump_cdb(fsg) \
57 print_hex_dump(KERN_DEBUG, "SCSI CDB: ", DUMP_PREFIX_NONE, \
58 16, 1, (fsg)->cmnd, (fsg)->cmnd_size, 0) \
59
60# else
61
62# define dump_cdb(fsg) do { } while (0)
63
64# endif /* VERBOSE_DEBUG */
65
66#endif /* DUMP_MSGS */
67
68/* Length of a SCSI Command Data Block */
69#define MAX_COMMAND_SIZE 16
70
71/* SCSI Sense Key/Additional Sense Code/ASC Qualifier values */
72#define SS_NO_SENSE 0
73#define SS_COMMUNICATION_FAILURE 0x040800
74#define SS_INVALID_COMMAND 0x052000
75#define SS_INVALID_FIELD_IN_CDB 0x052400
76#define SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE 0x052100
77#define SS_LOGICAL_UNIT_NOT_SUPPORTED 0x052500
78#define SS_MEDIUM_NOT_PRESENT 0x023a00
79#define SS_MEDIUM_REMOVAL_PREVENTED 0x055302
80#define SS_NOT_READY_TO_READY_TRANSITION 0x062800
81#define SS_RESET_OCCURRED 0x062900
82#define SS_SAVING_PARAMETERS_NOT_SUPPORTED 0x053900
83#define SS_UNRECOVERED_READ_ERROR 0x031100
84#define SS_WRITE_ERROR 0x030c02
85#define SS_WRITE_PROTECTED 0x072700
86
87#define SK(x) ((u8) ((x) >> 16)) /* Sense Key byte, etc. */
88#define ASC(x) ((u8) ((x) >> 8))
89#define ASCQ(x) ((u8) (x))
90
91struct fsg_lun {
92 struct file *filp;
93 loff_t file_length;
94 loff_t num_sectors;
95
96 unsigned int initially_ro:1;
97 unsigned int ro:1;
98 unsigned int removable:1;
99 unsigned int cdrom:1;
100 unsigned int prevent_medium_removal:1;
101 unsigned int registered:1;
102 unsigned int info_valid:1;
103 unsigned int nofua:1;
104
105 u32 sense_data;
106 u32 sense_data_info;
107 u32 unit_attention_data;
108
109 unsigned int blkbits; /* Bits of logical block size
110 of bound block device */
111 unsigned int blksize; /* logical block size of bound block device */
112 struct device dev;
113 const char *name; /* "lun.name" */
114 const char **name_pfx; /* "function.name" */
115};
116
117static inline bool fsg_lun_is_open(struct fsg_lun *curlun)
118{
119 return curlun->filp != NULL;
120}
121
122/* Big enough to hold our biggest descriptor */
123#define EP0_BUFSIZE 256
124#define DELAYED_STATUS (EP0_BUFSIZE + 999) /* An impossibly large value */
125
126/* Default size of buffer length. */
127#define FSG_BUFLEN ((u32)16384)
128
129/* Maximal number of LUNs supported in mass storage function */
130#define FSG_MAX_LUNS 8
131
132enum fsg_buffer_state {
133 BUF_STATE_EMPTY = 0,
134 BUF_STATE_FULL,
135 BUF_STATE_BUSY
136};
137
138struct fsg_buffhd {
139 void *buf;
140 enum fsg_buffer_state state;
141 struct fsg_buffhd *next;
142
143 /*
144 * The NetChip 2280 is faster, and handles some protocol faults
145 * better, if we don't submit any short bulk-out read requests.
146 * So we will record the intended request length here.
147 */
148 unsigned int bulk_out_intended_length;
149
150 struct usb_request *inreq;
151 int inreq_busy;
152 struct usb_request *outreq;
153 int outreq_busy;
154};
155
156enum fsg_state {
157 /* This one isn't used anywhere */
158 FSG_STATE_COMMAND_PHASE = -10,
159 FSG_STATE_DATA_PHASE,
160 FSG_STATE_STATUS_PHASE,
161
162 FSG_STATE_IDLE = 0,
163 FSG_STATE_ABORT_BULK_OUT,
164 FSG_STATE_RESET,
165 FSG_STATE_INTERFACE_CHANGE,
166 FSG_STATE_CONFIG_CHANGE,
167 FSG_STATE_DISCONNECT,
168 FSG_STATE_EXIT,
169 FSG_STATE_TERMINATED
170};
171
172enum data_direction {
173 DATA_DIR_UNKNOWN = 0,
174 DATA_DIR_FROM_HOST,
175 DATA_DIR_TO_HOST,
176 DATA_DIR_NONE
177};
178
179static inline u32 get_unaligned_be24(u8 *buf)
180{
181 return 0xffffff & (u32) get_unaligned_be32(buf - 1);
182}
183
184static inline struct fsg_lun *fsg_lun_from_dev(struct device *dev)
185{
186 return container_of(dev, struct fsg_lun, dev);
187}
188
189enum {
190 FSG_STRING_INTERFACE
191};
192
193extern struct usb_interface_descriptor fsg_intf_desc;
194
195extern struct usb_endpoint_descriptor fsg_fs_bulk_in_desc;
196extern struct usb_endpoint_descriptor fsg_fs_bulk_out_desc;
197extern struct usb_descriptor_header *fsg_fs_function[];
198
199extern struct usb_endpoint_descriptor fsg_hs_bulk_in_desc;
200extern struct usb_endpoint_descriptor fsg_hs_bulk_out_desc;
201extern struct usb_descriptor_header *fsg_hs_function[];
202
203extern struct usb_endpoint_descriptor fsg_ss_bulk_in_desc;
204extern struct usb_ss_ep_comp_descriptor fsg_ss_bulk_in_comp_desc;
205extern struct usb_endpoint_descriptor fsg_ss_bulk_out_desc;
206extern struct usb_ss_ep_comp_descriptor fsg_ss_bulk_out_comp_desc;
207extern struct usb_descriptor_header *fsg_ss_function[];
208
209void fsg_lun_close(struct fsg_lun *curlun);
210int fsg_lun_open(struct fsg_lun *curlun, const char *filename);
211int fsg_lun_fsync_sub(struct fsg_lun *curlun);
212void store_cdrom_address(u8 *dest, int msf, u32 addr);
213ssize_t fsg_show_ro(struct fsg_lun *curlun, char *buf);
214ssize_t fsg_show_nofua(struct fsg_lun *curlun, char *buf);
215ssize_t fsg_show_file(struct fsg_lun *curlun, struct rw_semaphore *filesem,
216 char *buf);
217ssize_t fsg_show_cdrom(struct fsg_lun *curlun, char *buf);
218ssize_t fsg_show_removable(struct fsg_lun *curlun, char *buf);
219ssize_t fsg_store_ro(struct fsg_lun *curlun, struct rw_semaphore *filesem,
220 const char *buf, size_t count);
221ssize_t fsg_store_nofua(struct fsg_lun *curlun, const char *buf, size_t count);
222ssize_t fsg_store_file(struct fsg_lun *curlun, struct rw_semaphore *filesem,
223 const char *buf, size_t count);
224ssize_t fsg_store_cdrom(struct fsg_lun *curlun, struct rw_semaphore *filesem,
225 const char *buf, size_t count);
226ssize_t fsg_store_removable(struct fsg_lun *curlun, const char *buf,
227 size_t count);
228
229#endif /* USB_STORAGE_COMMON_H */
diff --git a/drivers/usb/gadget/tcm_usb_gadget.c b/drivers/usb/gadget/tcm_usb_gadget.c
index 0ff33396eef3..eccea1df702d 100644
--- a/drivers/usb/gadget/tcm_usb_gadget.c
+++ b/drivers/usb/gadget/tcm_usb_gadget.c
@@ -472,7 +472,7 @@ static int usbg_bot_setup(struct usb_function *f,
472 bot_enqueue_cmd_cbw(fu); 472 bot_enqueue_cmd_cbw(fu);
473 return 0; 473 return 0;
474 break; 474 break;
475 }; 475 }
476 return -ENOTSUPP; 476 return -ENOTSUPP;
477} 477}
478 478
@@ -617,7 +617,7 @@ static void uasp_status_data_cmpl(struct usb_ep *ep, struct usb_request *req)
617 617
618 default: 618 default:
619 BUG(); 619 BUG();
620 }; 620 }
621 return; 621 return;
622 622
623cleanup: 623cleanup:
diff --git a/drivers/usb/gadget/udc-core.c b/drivers/usb/gadget/udc-core.c
index 59891b1c48fc..27768a7d986a 100644
--- a/drivers/usb/gadget/udc-core.c
+++ b/drivers/usb/gadget/udc-core.c
@@ -356,7 +356,8 @@ static int udc_bind_to_driver(struct usb_udc *udc, struct usb_gadget_driver *dri
356 kobject_uevent(&udc->dev.kobj, KOBJ_CHANGE); 356 kobject_uevent(&udc->dev.kobj, KOBJ_CHANGE);
357 return 0; 357 return 0;
358err1: 358err1:
359 dev_err(&udc->dev, "failed to start %s: %d\n", 359 if (ret != -EISNAM)
360 dev_err(&udc->dev, "failed to start %s: %d\n",
360 udc->driver->function, ret); 361 udc->driver->function, ret);
361 udc->driver = NULL; 362 udc->driver = NULL;
362 udc->dev.driver = NULL; 363 udc->dev.driver = NULL;
diff --git a/drivers/usb/gadget/zero.c b/drivers/usb/gadget/zero.c
index 0deb9d6cde26..0dd07ae1555d 100644
--- a/drivers/usb/gadget/zero.c
+++ b/drivers/usb/gadget/zero.c
@@ -95,6 +95,18 @@ unsigned autoresume = DEFAULT_AUTORESUME;
95module_param(autoresume, uint, S_IRUGO); 95module_param(autoresume, uint, S_IRUGO);
96MODULE_PARM_DESC(autoresume, "zero, or seconds before remote wakeup"); 96MODULE_PARM_DESC(autoresume, "zero, or seconds before remote wakeup");
97 97
98/* Maximum Autoresume time */
99unsigned max_autoresume;
100module_param(max_autoresume, uint, S_IRUGO);
101MODULE_PARM_DESC(max_autoresume, "maximum seconds before remote wakeup");
102
103/* Interval between two remote wakeups */
104unsigned autoresume_interval_ms;
105module_param(autoresume_interval_ms, uint, S_IRUGO);
106MODULE_PARM_DESC(autoresume_interval_ms,
107 "milliseconds to increase successive wakeup delays");
108
109static unsigned autoresume_step_ms;
98/*-------------------------------------------------------------------------*/ 110/*-------------------------------------------------------------------------*/
99 111
100static struct usb_device_descriptor device_desc = { 112static struct usb_device_descriptor device_desc = {
@@ -183,8 +195,16 @@ static void zero_suspend(struct usb_composite_dev *cdev)
183 return; 195 return;
184 196
185 if (autoresume) { 197 if (autoresume) {
186 mod_timer(&autoresume_timer, jiffies + (HZ * autoresume)); 198 if (max_autoresume &&
187 DBG(cdev, "suspend, wakeup in %d seconds\n", autoresume); 199 (autoresume_step_ms > max_autoresume * 1000))
200 autoresume_step_ms = autoresume * 1000;
201
202 mod_timer(&autoresume_timer, jiffies +
203 msecs_to_jiffies(autoresume_step_ms));
204 DBG(cdev, "suspend, wakeup in %d milliseconds\n",
205 autoresume_step_ms);
206
207 autoresume_step_ms += autoresume_interval_ms;
188 } else 208 } else
189 DBG(cdev, "%s\n", __func__); 209 DBG(cdev, "%s\n", __func__);
190} 210}
@@ -316,6 +336,7 @@ static int __init zero_bind(struct usb_composite_dev *cdev)
316 if (autoresume) { 336 if (autoresume) {
317 sourcesink_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP; 337 sourcesink_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
318 loopback_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP; 338 loopback_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
339 autoresume_step_ms = autoresume * 1000;
319 } 340 }
320 341
321 /* support OTG systems */ 342 /* support OTG systems */
diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
index b3f20d7f15de..a9707da7da0b 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -54,7 +54,7 @@ config USB_EHCI_HCD
54 54
55config USB_EHCI_ROOT_HUB_TT 55config USB_EHCI_ROOT_HUB_TT
56 bool "Root Hub Transaction Translators" 56 bool "Root Hub Transaction Translators"
57 depends on USB_EHCI_HCD || USB_CHIPIDEA_HOST 57 depends on USB_EHCI_HCD
58 ---help--- 58 ---help---
59 Some EHCI chips have vendor-specific extensions to integrate 59 Some EHCI chips have vendor-specific extensions to integrate
60 transaction translators, so that no OHCI or UHCI companion 60 transaction translators, so that no OHCI or UHCI companion
@@ -66,7 +66,7 @@ config USB_EHCI_ROOT_HUB_TT
66 66
67config USB_EHCI_TT_NEWSCHED 67config USB_EHCI_TT_NEWSCHED
68 bool "Improved Transaction Translator scheduling" 68 bool "Improved Transaction Translator scheduling"
69 depends on USB_EHCI_HCD || USB_CHIPIDEA_HOST 69 depends on USB_EHCI_HCD
70 default y 70 default y
71 ---help--- 71 ---help---
72 This changes the periodic scheduling code to fill more of the low 72 This changes the periodic scheduling code to fill more of the low
@@ -203,12 +203,11 @@ config USB_EHCI_SH
203 Enables support for the on-chip EHCI controller on the SuperH. 203 Enables support for the on-chip EHCI controller on the SuperH.
204 If you use the PCI EHCI controller, this option is not necessary. 204 If you use the PCI EHCI controller, this option is not necessary.
205 205
206config USB_EHCI_S5P 206config USB_EHCI_EXYNOS
207 tristate "EHCI support for Samsung S5P/EXYNOS SoC Series" 207 tristate "EHCI support for Samsung S5P/EXYNOS SoC Series"
208 depends on PLAT_S5P || ARCH_EXYNOS 208 depends on PLAT_S5P || ARCH_EXYNOS
209 help 209 help
210 Enable support for the Samsung S5Pxxxx and Exynos3/4/5 SOC's 210 Enable support for the Samsung Exynos SOC's on-chip EHCI controller.
211 on-chip EHCI controller.
212 211
213config USB_EHCI_MV 212config USB_EHCI_MV
214 bool "EHCI support for Marvell PXA/MMP USB controller" 213 bool "EHCI support for Marvell PXA/MMP USB controller"
@@ -224,7 +223,7 @@ config USB_EHCI_MV
224 on-chip EHCI USB controller" for those. 223 on-chip EHCI USB controller" for those.
225 224
226config USB_W90X900_EHCI 225config USB_W90X900_EHCI
227 bool "W90X900(W90P910) EHCI support" 226 tristate "W90X900(W90P910) EHCI support"
228 depends on ARCH_W90X900 227 depends on ARCH_W90X900
229 ---help--- 228 ---help---
230 Enables support for the W90X900 USB controller 229 Enables support for the W90X900 USB controller
@@ -367,14 +366,54 @@ config USB_OHCI_HCD
367if USB_OHCI_HCD 366if USB_OHCI_HCD
368 367
369config USB_OHCI_HCD_OMAP1 368config USB_OHCI_HCD_OMAP1
370 bool "OHCI support for OMAP1/2 chips" 369 tristate "OHCI support for OMAP1/2 chips"
371 depends on ARCH_OMAP1 370 depends on ARCH_OMAP1
372 default y 371 default y
373 ---help--- 372 ---help---
374 Enables support for the OHCI controller on OMAP1/2 chips. 373 Enables support for the OHCI controller on OMAP1/2 chips.
375 374
375config USB_OHCI_HCD_SPEAR
376 tristate "Support for ST SPEAr on-chip OHCI USB controller"
377 depends on USB_OHCI_HCD && PLAT_SPEAR
378 default y
379 ---help---
380 Enables support for the on-chip OHCI controller on
381 ST SPEAr chips.
382
383config USB_OHCI_HCD_S3C2410
384 tristate "OHCI support for Samsung S3C24xx/S3C64xx SoC series"
385 depends on USB_OHCI_HCD && (ARCH_S3C24XX || ARCH_S3C64XX)
386 default y
387 ---help---
388 Enables support for the on-chip OHCI controller on
389 S3C24xx/S3C64xx chips.
390
391config USB_OHCI_HCD_LPC32XX
392 tristate "Support for LPC on-chip OHCI USB controller"
393 depends on USB_OHCI_HCD && ARCH_LPC32XX
394 default y
395 ---help---
396 Enables support for the on-chip OHCI controller on
397 NXP chips.
398
399config USB_OHCI_HCD_PXA27X
400 tristate "Support for PXA27X/PXA3XX on-chip OHCI USB controller"
401 depends on USB_OHCI_HCD && (PXA27x || PXA3xx)
402 default y
403 ---help---
404 Enables support for the on-chip OHCI controller on
405 PXA27x/PXA3xx chips.
406
407config USB_OHCI_HCD_AT91
408 tristate "Support for Atmel on-chip OHCI USB controller"
409 depends on USB_OHCI_HCD && ARCH_AT91
410 default y
411 ---help---
412 Enables support for the on-chip OHCI controller on
413 Atmel chips.
414
376config USB_OHCI_HCD_OMAP3 415config USB_OHCI_HCD_OMAP3
377 bool "OHCI support for OMAP3 and later chips" 416 tristate "OHCI support for OMAP3 and later chips"
378 depends on (ARCH_OMAP3 || ARCH_OMAP4) 417 depends on (ARCH_OMAP3 || ARCH_OMAP4)
379 default y 418 default y
380 ---help--- 419 ---help---
@@ -454,8 +493,8 @@ config USB_OHCI_SH
454 If you use the PCI OHCI controller, this option is not necessary. 493 If you use the PCI OHCI controller, this option is not necessary.
455 494
456config USB_OHCI_EXYNOS 495config USB_OHCI_EXYNOS
457 boolean "OHCI support for Samsung EXYNOS SoC Series" 496 tristate "OHCI support for Samsung S5P/EXYNOS SoC Series"
458 depends on ARCH_EXYNOS 497 depends on PLAT_S5P || ARCH_EXYNOS
459 help 498 help
460 Enable support for the Samsung Exynos SOC's on-chip OHCI controller. 499 Enable support for the Samsung Exynos SOC's on-chip OHCI controller.
461 500
diff --git a/drivers/usb/host/Makefile b/drivers/usb/host/Makefile
index 50b0041c09a9..01e879ef3654 100644
--- a/drivers/usb/host/Makefile
+++ b/drivers/usb/host/Makefile
@@ -34,10 +34,11 @@ obj-$(CONFIG_USB_EHCI_MXC) += ehci-mxc.o
34obj-$(CONFIG_USB_EHCI_HCD_OMAP) += ehci-omap.o 34obj-$(CONFIG_USB_EHCI_HCD_OMAP) += ehci-omap.o
35obj-$(CONFIG_USB_EHCI_HCD_ORION) += ehci-orion.o 35obj-$(CONFIG_USB_EHCI_HCD_ORION) += ehci-orion.o
36obj-$(CONFIG_USB_EHCI_HCD_SPEAR) += ehci-spear.o 36obj-$(CONFIG_USB_EHCI_HCD_SPEAR) += ehci-spear.o
37obj-$(CONFIG_USB_EHCI_S5P) += ehci-s5p.o 37obj-$(CONFIG_USB_EHCI_EXYNOS) += ehci-exynos.o
38obj-$(CONFIG_USB_EHCI_HCD_AT91) += ehci-atmel.o 38obj-$(CONFIG_USB_EHCI_HCD_AT91) += ehci-atmel.o
39obj-$(CONFIG_USB_EHCI_MSM) += ehci-msm.o 39obj-$(CONFIG_USB_EHCI_MSM) += ehci-msm.o
40obj-$(CONFIG_USB_EHCI_TEGRA) += ehci-tegra.o 40obj-$(CONFIG_USB_EHCI_TEGRA) += ehci-tegra.o
41obj-$(CONFIG_USB_W90X900_EHCI) += ehci-w90x900.o
41 42
42obj-$(CONFIG_USB_OXU210HP_HCD) += oxu210hp-hcd.o 43obj-$(CONFIG_USB_OXU210HP_HCD) += oxu210hp-hcd.o
43obj-$(CONFIG_USB_ISP116X_HCD) += isp116x-hcd.o 44obj-$(CONFIG_USB_ISP116X_HCD) += isp116x-hcd.o
@@ -46,6 +47,14 @@ obj-$(CONFIG_USB_ISP1362_HCD) += isp1362-hcd.o
46obj-$(CONFIG_USB_OHCI_HCD) += ohci-hcd.o 47obj-$(CONFIG_USB_OHCI_HCD) += ohci-hcd.o
47obj-$(CONFIG_USB_OHCI_HCD_PCI) += ohci-pci.o 48obj-$(CONFIG_USB_OHCI_HCD_PCI) += ohci-pci.o
48obj-$(CONFIG_USB_OHCI_HCD_PLATFORM) += ohci-platform.o 49obj-$(CONFIG_USB_OHCI_HCD_PLATFORM) += ohci-platform.o
50obj-$(CONFIG_USB_OHCI_EXYNOS) += ohci-exynos.o
51obj-$(CONFIG_USB_OHCI_HCD_OMAP1) += ohci-omap.o
52obj-$(CONFIG_USB_OHCI_HCD_OMAP3) += ohci-omap3.o
53obj-$(CONFIG_USB_OHCI_HCD_SPEAR) += ohci-spear.o
54obj-$(CONFIG_USB_OHCI_HCD_AT91) += ohci-at91.o
55obj-$(CONFIG_USB_OHCI_HCD_S3C2410) += ohci-s3c2410.o
56obj-$(CONFIG_USB_OHCI_HCD_LPC32XX) += ohci-nxp.o
57obj-$(CONFIG_USB_OHCI_HCD_PXA27X) += ohci-pxa27x.o
49 58
50obj-$(CONFIG_USB_UHCI_HCD) += uhci-hcd.o 59obj-$(CONFIG_USB_UHCI_HCD) += uhci-hcd.o
51obj-$(CONFIG_USB_FHCI_HCD) += fhci.o 60obj-$(CONFIG_USB_FHCI_HCD) += fhci.o
diff --git a/drivers/usb/host/ehci-atmel.c b/drivers/usb/host/ehci-atmel.c
index 3b645ff46f7b..f417526fb1f4 100644
--- a/drivers/usb/host/ehci-atmel.c
+++ b/drivers/usb/host/ehci-atmel.c
@@ -30,13 +30,17 @@ static const char hcd_name[] = "ehci-atmel";
30static struct hc_driver __read_mostly ehci_atmel_hc_driver; 30static struct hc_driver __read_mostly ehci_atmel_hc_driver;
31 31
32/* interface and function clocks */ 32/* interface and function clocks */
33static struct clk *iclk, *fclk; 33static struct clk *iclk, *fclk, *uclk;
34static int clocked; 34static int clocked;
35 35
36/*-------------------------------------------------------------------------*/ 36/*-------------------------------------------------------------------------*/
37 37
38static void atmel_start_clock(void) 38static void atmel_start_clock(void)
39{ 39{
40 if (IS_ENABLED(CONFIG_COMMON_CLK)) {
41 clk_set_rate(uclk, 48000000);
42 clk_prepare_enable(uclk);
43 }
40 clk_prepare_enable(iclk); 44 clk_prepare_enable(iclk);
41 clk_prepare_enable(fclk); 45 clk_prepare_enable(fclk);
42 clocked = 1; 46 clocked = 1;
@@ -46,6 +50,8 @@ static void atmel_stop_clock(void)
46{ 50{
47 clk_disable_unprepare(fclk); 51 clk_disable_unprepare(fclk);
48 clk_disable_unprepare(iclk); 52 clk_disable_unprepare(iclk);
53 if (IS_ENABLED(CONFIG_COMMON_CLK))
54 clk_disable_unprepare(uclk);
49 clocked = 0; 55 clocked = 0;
50} 56}
51 57
@@ -130,6 +136,14 @@ static int ehci_atmel_drv_probe(struct platform_device *pdev)
130 retval = -ENOENT; 136 retval = -ENOENT;
131 goto fail_request_resource; 137 goto fail_request_resource;
132 } 138 }
139 if (IS_ENABLED(CONFIG_COMMON_CLK)) {
140 uclk = devm_clk_get(&pdev->dev, "usb_clk");
141 if (IS_ERR(uclk)) {
142 dev_err(&pdev->dev, "failed to get uclk\n");
143 retval = PTR_ERR(uclk);
144 goto fail_request_resource;
145 }
146 }
133 147
134 ehci = hcd_to_ehci(hcd); 148 ehci = hcd_to_ehci(hcd);
135 /* registers start at offset 0x0 */ 149 /* registers start at offset 0x0 */
diff --git a/drivers/usb/host/ehci-dbg.c b/drivers/usb/host/ehci-dbg.c
index aa5b603f3933..4a9c2edbcb2b 100644
--- a/drivers/usb/host/ehci-dbg.c
+++ b/drivers/usb/host/ehci-dbg.c
@@ -334,6 +334,7 @@ static inline void remove_debug_files (struct ehci_hcd *bus) { }
334/* troubleshooting help: expose state in debugfs */ 334/* troubleshooting help: expose state in debugfs */
335 335
336static int debug_async_open(struct inode *, struct file *); 336static int debug_async_open(struct inode *, struct file *);
337static int debug_bandwidth_open(struct inode *, struct file *);
337static int debug_periodic_open(struct inode *, struct file *); 338static int debug_periodic_open(struct inode *, struct file *);
338static int debug_registers_open(struct inode *, struct file *); 339static int debug_registers_open(struct inode *, struct file *);
339 340
@@ -347,6 +348,13 @@ static const struct file_operations debug_async_fops = {
347 .release = debug_close, 348 .release = debug_close,
348 .llseek = default_llseek, 349 .llseek = default_llseek,
349}; 350};
351static const struct file_operations debug_bandwidth_fops = {
352 .owner = THIS_MODULE,
353 .open = debug_bandwidth_open,
354 .read = debug_output,
355 .release = debug_close,
356 .llseek = default_llseek,
357};
350static const struct file_operations debug_periodic_fops = { 358static const struct file_operations debug_periodic_fops = {
351 .owner = THIS_MODULE, 359 .owner = THIS_MODULE,
352 .open = debug_periodic_open, 360 .open = debug_periodic_open,
@@ -379,7 +387,7 @@ struct debug_buffer {
379 case QH_LOW_SPEED: tmp = 'l'; break; \ 387 case QH_LOW_SPEED: tmp = 'l'; break; \
380 case QH_HIGH_SPEED: tmp = 'h'; break; \ 388 case QH_HIGH_SPEED: tmp = 'h'; break; \
381 default: tmp = '?'; break; \ 389 default: tmp = '?'; break; \
382 }; tmp; }) 390 } tmp; })
383 391
384static inline char token_mark(struct ehci_hcd *ehci, __hc32 token) 392static inline char token_mark(struct ehci_hcd *ehci, __hc32 token)
385{ 393{
@@ -525,6 +533,89 @@ static ssize_t fill_async_buffer(struct debug_buffer *buf)
525 return strlen(buf->output_buf); 533 return strlen(buf->output_buf);
526} 534}
527 535
536static ssize_t fill_bandwidth_buffer(struct debug_buffer *buf)
537{
538 struct ehci_hcd *ehci;
539 struct ehci_tt *tt;
540 struct ehci_per_sched *ps;
541 unsigned temp, size;
542 char *next;
543 unsigned i;
544 u8 *bw;
545 u16 *bf;
546 u8 budget[EHCI_BANDWIDTH_SIZE];
547
548 ehci = hcd_to_ehci(bus_to_hcd(buf->bus));
549 next = buf->output_buf;
550 size = buf->alloc_size;
551
552 *next = 0;
553
554 spin_lock_irq(&ehci->lock);
555
556 /* Dump the HS bandwidth table */
557 temp = scnprintf(next, size,
558 "HS bandwidth allocation (us per microframe)\n");
559 size -= temp;
560 next += temp;
561 for (i = 0; i < EHCI_BANDWIDTH_SIZE; i += 8) {
562 bw = &ehci->bandwidth[i];
563 temp = scnprintf(next, size,
564 "%2u: %4u%4u%4u%4u%4u%4u%4u%4u\n",
565 i, bw[0], bw[1], bw[2], bw[3],
566 bw[4], bw[5], bw[6], bw[7]);
567 size -= temp;
568 next += temp;
569 }
570
571 /* Dump all the FS/LS tables */
572 list_for_each_entry(tt, &ehci->tt_list, tt_list) {
573 temp = scnprintf(next, size,
574 "\nTT %s port %d FS/LS bandwidth allocation (us per frame)\n",
575 dev_name(&tt->usb_tt->hub->dev),
576 tt->tt_port + !!tt->usb_tt->multi);
577 size -= temp;
578 next += temp;
579
580 bf = tt->bandwidth;
581 temp = scnprintf(next, size,
582 " %5u%5u%5u%5u%5u%5u%5u%5u\n",
583 bf[0], bf[1], bf[2], bf[3],
584 bf[4], bf[5], bf[6], bf[7]);
585 size -= temp;
586 next += temp;
587
588 temp = scnprintf(next, size,
589 "FS/LS budget (us per microframe)\n");
590 size -= temp;
591 next += temp;
592 compute_tt_budget(budget, tt);
593 for (i = 0; i < EHCI_BANDWIDTH_SIZE; i += 8) {
594 bw = &budget[i];
595 temp = scnprintf(next, size,
596 "%2u: %4u%4u%4u%4u%4u%4u%4u%4u\n",
597 i, bw[0], bw[1], bw[2], bw[3],
598 bw[4], bw[5], bw[6], bw[7]);
599 size -= temp;
600 next += temp;
601 }
602 list_for_each_entry(ps, &tt->ps_list, ps_list) {
603 temp = scnprintf(next, size,
604 "%s ep %02x: %4u @ %2u.%u+%u mask %04x\n",
605 dev_name(&ps->udev->dev),
606 ps->ep->desc.bEndpointAddress,
607 ps->tt_usecs,
608 ps->bw_phase, ps->phase_uf,
609 ps->bw_period, ps->cs_mask);
610 size -= temp;
611 next += temp;
612 }
613 }
614 spin_unlock_irq(&ehci->lock);
615
616 return next - buf->output_buf;
617}
618
528#define DBG_SCHED_LIMIT 64 619#define DBG_SCHED_LIMIT 64
529static ssize_t fill_periodic_buffer(struct debug_buffer *buf) 620static ssize_t fill_periodic_buffer(struct debug_buffer *buf)
530{ 621{
@@ -571,7 +662,7 @@ static ssize_t fill_periodic_buffer(struct debug_buffer *buf)
571 case Q_TYPE_QH: 662 case Q_TYPE_QH:
572 hw = p.qh->hw; 663 hw = p.qh->hw;
573 temp = scnprintf (next, size, " qh%d-%04x/%p", 664 temp = scnprintf (next, size, " qh%d-%04x/%p",
574 p.qh->period, 665 p.qh->ps.period,
575 hc32_to_cpup(ehci, 666 hc32_to_cpup(ehci,
576 &hw->hw_info2) 667 &hw->hw_info2)
577 /* uframe masks */ 668 /* uframe masks */
@@ -618,7 +709,8 @@ static ssize_t fill_periodic_buffer(struct debug_buffer *buf)
618 speed_char (scratch), 709 speed_char (scratch),
619 scratch & 0x007f, 710 scratch & 0x007f,
620 (scratch >> 8) & 0x000f, type, 711 (scratch >> 8) & 0x000f, type,
621 p.qh->usecs, p.qh->c_usecs, 712 p.qh->ps.usecs,
713 p.qh->ps.c_usecs,
622 temp, 714 temp,
623 0x7ff & (scratch >> 16)); 715 0x7ff & (scratch >> 16));
624 716
@@ -645,7 +737,7 @@ static ssize_t fill_periodic_buffer(struct debug_buffer *buf)
645 case Q_TYPE_SITD: 737 case Q_TYPE_SITD:
646 temp = scnprintf (next, size, 738 temp = scnprintf (next, size,
647 " sitd%d-%04x/%p", 739 " sitd%d-%04x/%p",
648 p.sitd->stream->interval, 740 p.sitd->stream->ps.period,
649 hc32_to_cpup(ehci, &p.sitd->hw_uframe) 741 hc32_to_cpup(ehci, &p.sitd->hw_uframe)
650 & 0x0000ffff, 742 & 0x0000ffff,
651 p.sitd); 743 p.sitd);
@@ -918,6 +1010,7 @@ static int debug_close(struct inode *inode, struct file *file)
918 1010
919 return 0; 1011 return 0;
920} 1012}
1013
921static int debug_async_open(struct inode *inode, struct file *file) 1014static int debug_async_open(struct inode *inode, struct file *file)
922{ 1015{
923 file->private_data = alloc_buffer(inode->i_private, fill_async_buffer); 1016 file->private_data = alloc_buffer(inode->i_private, fill_async_buffer);
@@ -925,6 +1018,14 @@ static int debug_async_open(struct inode *inode, struct file *file)
925 return file->private_data ? 0 : -ENOMEM; 1018 return file->private_data ? 0 : -ENOMEM;
926} 1019}
927 1020
1021static int debug_bandwidth_open(struct inode *inode, struct file *file)
1022{
1023 file->private_data = alloc_buffer(inode->i_private,
1024 fill_bandwidth_buffer);
1025
1026 return file->private_data ? 0 : -ENOMEM;
1027}
1028
928static int debug_periodic_open(struct inode *inode, struct file *file) 1029static int debug_periodic_open(struct inode *inode, struct file *file)
929{ 1030{
930 struct debug_buffer *buf; 1031 struct debug_buffer *buf;
@@ -957,6 +1058,10 @@ static inline void create_debug_files (struct ehci_hcd *ehci)
957 &debug_async_fops)) 1058 &debug_async_fops))
958 goto file_error; 1059 goto file_error;
959 1060
1061 if (!debugfs_create_file("bandwidth", S_IRUGO, ehci->debug_dir, bus,
1062 &debug_bandwidth_fops))
1063 goto file_error;
1064
960 if (!debugfs_create_file("periodic", S_IRUGO, ehci->debug_dir, bus, 1065 if (!debugfs_create_file("periodic", S_IRUGO, ehci->debug_dir, bus,
961 &debug_periodic_fops)) 1066 &debug_periodic_fops))
962 goto file_error; 1067 goto file_error;
diff --git a/drivers/usb/host/ehci-s5p.c b/drivers/usb/host/ehci-exynos.c
index 7c3de95c7054..016352e0f5a7 100644
--- a/drivers/usb/host/ehci-s5p.c
+++ b/drivers/usb/host/ehci-exynos.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * SAMSUNG S5P USB HOST EHCI Controller 2 * SAMSUNG EXYNOS USB HOST EHCI Controller
3 * 3 *
4 * Copyright (C) 2011 Samsung Electronics Co.Ltd 4 * Copyright (C) 2011 Samsung Electronics Co.Ltd
5 * Author: Jingoo Han <jg1.han@samsung.com> 5 * Author: Jingoo Han <jg1.han@samsung.com>
@@ -20,7 +20,6 @@
20#include <linux/of.h> 20#include <linux/of.h>
21#include <linux/of_gpio.h> 21#include <linux/of_gpio.h>
22#include <linux/platform_device.h> 22#include <linux/platform_device.h>
23#include <linux/platform_data/usb-ehci-s5p.h>
24#include <linux/usb/phy.h> 23#include <linux/usb/phy.h>
25#include <linux/usb/samsung_usb_phy.h> 24#include <linux/usb/samsung_usb_phy.h>
26#include <linux/usb.h> 25#include <linux/usb.h>
@@ -29,7 +28,7 @@
29 28
30#include "ehci.h" 29#include "ehci.h"
31 30
32#define DRIVER_DESC "EHCI s5p driver" 31#define DRIVER_DESC "EHCI EXYNOS driver"
33 32
34#define EHCI_INSNREG00(base) (base + 0x90) 33#define EHCI_INSNREG00(base) (base + 0x90)
35#define EHCI_INSNREG00_ENA_INCR16 (0x1 << 25) 34#define EHCI_INSNREG00_ENA_INCR16 (0x1 << 25)
@@ -40,21 +39,18 @@
40 (EHCI_INSNREG00_ENA_INCR16 | EHCI_INSNREG00_ENA_INCR8 | \ 39 (EHCI_INSNREG00_ENA_INCR16 | EHCI_INSNREG00_ENA_INCR8 | \
41 EHCI_INSNREG00_ENA_INCR4 | EHCI_INSNREG00_ENA_INCRX_ALIGN) 40 EHCI_INSNREG00_ENA_INCR4 | EHCI_INSNREG00_ENA_INCRX_ALIGN)
42 41
43static const char hcd_name[] = "ehci-s5p"; 42static const char hcd_name[] = "ehci-exynos";
44static struct hc_driver __read_mostly s5p_ehci_hc_driver; 43static struct hc_driver __read_mostly exynos_ehci_hc_driver;
45 44
46struct s5p_ehci_hcd { 45struct exynos_ehci_hcd {
47 struct clk *clk; 46 struct clk *clk;
48 struct usb_phy *phy; 47 struct usb_phy *phy;
49 struct usb_otg *otg; 48 struct usb_otg *otg;
50 struct s5p_ehci_platdata *pdata;
51}; 49};
52 50
53static struct s5p_ehci_platdata empty_platdata; 51#define to_exynos_ehci(hcd) (struct exynos_ehci_hcd *)(hcd_to_ehci(hcd)->priv)
54 52
55#define to_s5p_ehci(hcd) (struct s5p_ehci_hcd *)(hcd_to_ehci(hcd)->priv) 53static void exynos_setup_vbus_gpio(struct platform_device *pdev)
56
57static void s5p_setup_vbus_gpio(struct platform_device *pdev)
58{ 54{
59 struct device *dev = &pdev->dev; 55 struct device *dev = &pdev->dev;
60 int err; 56 int err;
@@ -73,10 +69,9 @@ static void s5p_setup_vbus_gpio(struct platform_device *pdev)
73 dev_err(dev, "can't request ehci vbus gpio %d", gpio); 69 dev_err(dev, "can't request ehci vbus gpio %d", gpio);
74} 70}
75 71
76static int s5p_ehci_probe(struct platform_device *pdev) 72static int exynos_ehci_probe(struct platform_device *pdev)
77{ 73{
78 struct s5p_ehci_platdata *pdata = dev_get_platdata(&pdev->dev); 74 struct exynos_ehci_hcd *exynos_ehci;
79 struct s5p_ehci_hcd *s5p_ehci;
80 struct usb_hcd *hcd; 75 struct usb_hcd *hcd;
81 struct ehci_hcd *ehci; 76 struct ehci_hcd *ehci;
82 struct resource *res; 77 struct resource *res;
@@ -94,48 +89,41 @@ static int s5p_ehci_probe(struct platform_device *pdev)
94 if (!pdev->dev.coherent_dma_mask) 89 if (!pdev->dev.coherent_dma_mask)
95 pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32); 90 pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
96 91
97 s5p_setup_vbus_gpio(pdev); 92 exynos_setup_vbus_gpio(pdev);
98 93
99 hcd = usb_create_hcd(&s5p_ehci_hc_driver, 94 hcd = usb_create_hcd(&exynos_ehci_hc_driver,
100 &pdev->dev, dev_name(&pdev->dev)); 95 &pdev->dev, dev_name(&pdev->dev));
101 if (!hcd) { 96 if (!hcd) {
102 dev_err(&pdev->dev, "Unable to create HCD\n"); 97 dev_err(&pdev->dev, "Unable to create HCD\n");
103 return -ENOMEM; 98 return -ENOMEM;
104 } 99 }
105 s5p_ehci = to_s5p_ehci(hcd); 100 exynos_ehci = to_exynos_ehci(hcd);
106 101
107 if (of_device_is_compatible(pdev->dev.of_node, 102 if (of_device_is_compatible(pdev->dev.of_node,
108 "samsung,exynos5440-ehci")) { 103 "samsung,exynos5440-ehci"))
109 s5p_ehci->pdata = &empty_platdata;
110 goto skip_phy; 104 goto skip_phy;
111 }
112 105
113 phy = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2); 106 phy = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2);
114 if (IS_ERR(phy)) { 107 if (IS_ERR(phy)) {
115 /* Fallback to pdata */ 108 usb_put_hcd(hcd);
116 if (!pdata) { 109 dev_warn(&pdev->dev, "no platform data or transceiver defined\n");
117 usb_put_hcd(hcd); 110 return -EPROBE_DEFER;
118 dev_warn(&pdev->dev, "no platform data or transceiver defined\n");
119 return -EPROBE_DEFER;
120 } else {
121 s5p_ehci->pdata = pdata;
122 }
123 } else { 111 } else {
124 s5p_ehci->phy = phy; 112 exynos_ehci->phy = phy;
125 s5p_ehci->otg = phy->otg; 113 exynos_ehci->otg = phy->otg;
126 } 114 }
127 115
128skip_phy: 116skip_phy:
129 117
130 s5p_ehci->clk = devm_clk_get(&pdev->dev, "usbhost"); 118 exynos_ehci->clk = devm_clk_get(&pdev->dev, "usbhost");
131 119
132 if (IS_ERR(s5p_ehci->clk)) { 120 if (IS_ERR(exynos_ehci->clk)) {
133 dev_err(&pdev->dev, "Failed to get usbhost clock\n"); 121 dev_err(&pdev->dev, "Failed to get usbhost clock\n");
134 err = PTR_ERR(s5p_ehci->clk); 122 err = PTR_ERR(exynos_ehci->clk);
135 goto fail_clk; 123 goto fail_clk;
136 } 124 }
137 125
138 err = clk_prepare_enable(s5p_ehci->clk); 126 err = clk_prepare_enable(exynos_ehci->clk);
139 if (err) 127 if (err)
140 goto fail_clk; 128 goto fail_clk;
141 129
@@ -162,13 +150,11 @@ skip_phy:
162 goto fail_io; 150 goto fail_io;
163 } 151 }
164 152
165 if (s5p_ehci->otg) 153 if (exynos_ehci->otg)
166 s5p_ehci->otg->set_host(s5p_ehci->otg, &hcd->self); 154 exynos_ehci->otg->set_host(exynos_ehci->otg, &hcd->self);
167 155
168 if (s5p_ehci->phy) 156 if (exynos_ehci->phy)
169 usb_phy_init(s5p_ehci->phy); 157 usb_phy_init(exynos_ehci->phy);
170 else if (s5p_ehci->pdata->phy_init)
171 s5p_ehci->pdata->phy_init(pdev, USB_PHY_TYPE_HOST);
172 158
173 ehci = hcd_to_ehci(hcd); 159 ehci = hcd_to_ehci(hcd);
174 ehci->caps = hcd->regs; 160 ehci->caps = hcd->regs;
@@ -187,33 +173,29 @@ skip_phy:
187 return 0; 173 return 0;
188 174
189fail_add_hcd: 175fail_add_hcd:
190 if (s5p_ehci->phy) 176 if (exynos_ehci->phy)
191 usb_phy_shutdown(s5p_ehci->phy); 177 usb_phy_shutdown(exynos_ehci->phy);
192 else if (s5p_ehci->pdata->phy_exit)
193 s5p_ehci->pdata->phy_exit(pdev, USB_PHY_TYPE_HOST);
194fail_io: 178fail_io:
195 clk_disable_unprepare(s5p_ehci->clk); 179 clk_disable_unprepare(exynos_ehci->clk);
196fail_clk: 180fail_clk:
197 usb_put_hcd(hcd); 181 usb_put_hcd(hcd);
198 return err; 182 return err;
199} 183}
200 184
201static int s5p_ehci_remove(struct platform_device *pdev) 185static int exynos_ehci_remove(struct platform_device *pdev)
202{ 186{
203 struct usb_hcd *hcd = platform_get_drvdata(pdev); 187 struct usb_hcd *hcd = platform_get_drvdata(pdev);
204 struct s5p_ehci_hcd *s5p_ehci = to_s5p_ehci(hcd); 188 struct exynos_ehci_hcd *exynos_ehci = to_exynos_ehci(hcd);
205 189
206 usb_remove_hcd(hcd); 190 usb_remove_hcd(hcd);
207 191
208 if (s5p_ehci->otg) 192 if (exynos_ehci->otg)
209 s5p_ehci->otg->set_host(s5p_ehci->otg, &hcd->self); 193 exynos_ehci->otg->set_host(exynos_ehci->otg, &hcd->self);
210 194
211 if (s5p_ehci->phy) 195 if (exynos_ehci->phy)
212 usb_phy_shutdown(s5p_ehci->phy); 196 usb_phy_shutdown(exynos_ehci->phy);
213 else if (s5p_ehci->pdata->phy_exit)
214 s5p_ehci->pdata->phy_exit(pdev, USB_PHY_TYPE_HOST);
215 197
216 clk_disable_unprepare(s5p_ehci->clk); 198 clk_disable_unprepare(exynos_ehci->clk);
217 199
218 usb_put_hcd(hcd); 200 usb_put_hcd(hcd);
219 201
@@ -221,45 +203,39 @@ static int s5p_ehci_remove(struct platform_device *pdev)
221} 203}
222 204
223#ifdef CONFIG_PM 205#ifdef CONFIG_PM
224static int s5p_ehci_suspend(struct device *dev) 206static int exynos_ehci_suspend(struct device *dev)
225{ 207{
226 struct usb_hcd *hcd = dev_get_drvdata(dev); 208 struct usb_hcd *hcd = dev_get_drvdata(dev);
227 struct s5p_ehci_hcd *s5p_ehci = to_s5p_ehci(hcd); 209 struct exynos_ehci_hcd *exynos_ehci = to_exynos_ehci(hcd);
228 struct platform_device *pdev = to_platform_device(dev);
229 210
230 bool do_wakeup = device_may_wakeup(dev); 211 bool do_wakeup = device_may_wakeup(dev);
231 int rc; 212 int rc;
232 213
233 rc = ehci_suspend(hcd, do_wakeup); 214 rc = ehci_suspend(hcd, do_wakeup);
234 215
235 if (s5p_ehci->otg) 216 if (exynos_ehci->otg)
236 s5p_ehci->otg->set_host(s5p_ehci->otg, &hcd->self); 217 exynos_ehci->otg->set_host(exynos_ehci->otg, &hcd->self);
237 218
238 if (s5p_ehci->phy) 219 if (exynos_ehci->phy)
239 usb_phy_shutdown(s5p_ehci->phy); 220 usb_phy_shutdown(exynos_ehci->phy);
240 else if (s5p_ehci->pdata->phy_exit)
241 s5p_ehci->pdata->phy_exit(pdev, USB_PHY_TYPE_HOST);
242 221
243 clk_disable_unprepare(s5p_ehci->clk); 222 clk_disable_unprepare(exynos_ehci->clk);
244 223
245 return rc; 224 return rc;
246} 225}
247 226
248static int s5p_ehci_resume(struct device *dev) 227static int exynos_ehci_resume(struct device *dev)
249{ 228{
250 struct usb_hcd *hcd = dev_get_drvdata(dev); 229 struct usb_hcd *hcd = dev_get_drvdata(dev);
251 struct s5p_ehci_hcd *s5p_ehci = to_s5p_ehci(hcd); 230 struct exynos_ehci_hcd *exynos_ehci = to_exynos_ehci(hcd);
252 struct platform_device *pdev = to_platform_device(dev);
253 231
254 clk_prepare_enable(s5p_ehci->clk); 232 clk_prepare_enable(exynos_ehci->clk);
255 233
256 if (s5p_ehci->otg) 234 if (exynos_ehci->otg)
257 s5p_ehci->otg->set_host(s5p_ehci->otg, &hcd->self); 235 exynos_ehci->otg->set_host(exynos_ehci->otg, &hcd->self);
258 236
259 if (s5p_ehci->phy) 237 if (exynos_ehci->phy)
260 usb_phy_init(s5p_ehci->phy); 238 usb_phy_init(exynos_ehci->phy);
261 else if (s5p_ehci->pdata->phy_init)
262 s5p_ehci->pdata->phy_init(pdev, USB_PHY_TYPE_HOST);
263 239
264 /* DMA burst Enable */ 240 /* DMA burst Enable */
265 writel(EHCI_INSNREG00_ENABLE_DMA_BURST, EHCI_INSNREG00(hcd->regs)); 241 writel(EHCI_INSNREG00_ENABLE_DMA_BURST, EHCI_INSNREG00(hcd->regs));
@@ -268,13 +244,13 @@ static int s5p_ehci_resume(struct device *dev)
268 return 0; 244 return 0;
269} 245}
270#else 246#else
271#define s5p_ehci_suspend NULL 247#define exynos_ehci_suspend NULL
272#define s5p_ehci_resume NULL 248#define exynos_ehci_resume NULL
273#endif 249#endif
274 250
275static const struct dev_pm_ops s5p_ehci_pm_ops = { 251static const struct dev_pm_ops exynos_ehci_pm_ops = {
276 .suspend = s5p_ehci_suspend, 252 .suspend = exynos_ehci_suspend,
277 .resume = s5p_ehci_resume, 253 .resume = exynos_ehci_resume,
278}; 254};
279 255
280#ifdef CONFIG_OF 256#ifdef CONFIG_OF
@@ -286,40 +262,40 @@ static const struct of_device_id exynos_ehci_match[] = {
286MODULE_DEVICE_TABLE(of, exynos_ehci_match); 262MODULE_DEVICE_TABLE(of, exynos_ehci_match);
287#endif 263#endif
288 264
289static struct platform_driver s5p_ehci_driver = { 265static struct platform_driver exynos_ehci_driver = {
290 .probe = s5p_ehci_probe, 266 .probe = exynos_ehci_probe,
291 .remove = s5p_ehci_remove, 267 .remove = exynos_ehci_remove,
292 .shutdown = usb_hcd_platform_shutdown, 268 .shutdown = usb_hcd_platform_shutdown,
293 .driver = { 269 .driver = {
294 .name = "s5p-ehci", 270 .name = "exynos-ehci",
295 .owner = THIS_MODULE, 271 .owner = THIS_MODULE,
296 .pm = &s5p_ehci_pm_ops, 272 .pm = &exynos_ehci_pm_ops,
297 .of_match_table = of_match_ptr(exynos_ehci_match), 273 .of_match_table = of_match_ptr(exynos_ehci_match),
298 } 274 }
299}; 275};
300static const struct ehci_driver_overrides s5p_overrides __initdata = { 276static const struct ehci_driver_overrides exynos_overrides __initdata = {
301 .extra_priv_size = sizeof(struct s5p_ehci_hcd), 277 .extra_priv_size = sizeof(struct exynos_ehci_hcd),
302}; 278};
303 279
304static int __init ehci_s5p_init(void) 280static int __init ehci_exynos_init(void)
305{ 281{
306 if (usb_disabled()) 282 if (usb_disabled())
307 return -ENODEV; 283 return -ENODEV;
308 284
309 pr_info("%s: " DRIVER_DESC "\n", hcd_name); 285 pr_info("%s: " DRIVER_DESC "\n", hcd_name);
310 ehci_init_driver(&s5p_ehci_hc_driver, &s5p_overrides); 286 ehci_init_driver(&exynos_ehci_hc_driver, &exynos_overrides);
311 return platform_driver_register(&s5p_ehci_driver); 287 return platform_driver_register(&exynos_ehci_driver);
312} 288}
313module_init(ehci_s5p_init); 289module_init(ehci_exynos_init);
314 290
315static void __exit ehci_s5p_cleanup(void) 291static void __exit ehci_exynos_cleanup(void)
316{ 292{
317 platform_driver_unregister(&s5p_ehci_driver); 293 platform_driver_unregister(&exynos_ehci_driver);
318} 294}
319module_exit(ehci_s5p_cleanup); 295module_exit(ehci_exynos_cleanup);
320 296
321MODULE_DESCRIPTION(DRIVER_DESC); 297MODULE_DESCRIPTION(DRIVER_DESC);
322MODULE_ALIAS("platform:s5p-ehci"); 298MODULE_ALIAS("platform:exynos-ehci");
323MODULE_AUTHOR("Jingoo Han"); 299MODULE_AUTHOR("Jingoo Han");
324MODULE_AUTHOR("Joonyoung Shim"); 300MODULE_AUTHOR("Joonyoung Shim");
325MODULE_LICENSE("GPL v2"); 301MODULE_LICENSE("GPL v2");
diff --git a/drivers/usb/host/ehci-fsl.c b/drivers/usb/host/ehci-fsl.c
index f2407b2e8a99..a06d5012201f 100644
--- a/drivers/usb/host/ehci-fsl.c
+++ b/drivers/usb/host/ehci-fsl.c
@@ -57,7 +57,7 @@ static int usb_hcd_fsl_probe(const struct hc_driver *driver,
57 pr_debug("initializing FSL-SOC USB Controller\n"); 57 pr_debug("initializing FSL-SOC USB Controller\n");
58 58
59 /* Need platform data for setup */ 59 /* Need platform data for setup */
60 pdata = (struct fsl_usb2_platform_data *)dev_get_platdata(&pdev->dev); 60 pdata = dev_get_platdata(&pdev->dev);
61 if (!pdata) { 61 if (!pdata) {
62 dev_err(&pdev->dev, 62 dev_err(&pdev->dev,
63 "No platform data for %s.\n", dev_name(&pdev->dev)); 63 "No platform data for %s.\n", dev_name(&pdev->dev));
@@ -664,7 +664,7 @@ static const struct hc_driver ehci_fsl_hc_driver = {
664 * generic hardware linkage 664 * generic hardware linkage
665 */ 665 */
666 .irq = ehci_irq, 666 .irq = ehci_irq,
667 .flags = HCD_USB2 | HCD_MEMORY, 667 .flags = HCD_USB2 | HCD_MEMORY | HCD_BH,
668 668
669 /* 669 /*
670 * basic lifecycle operations 670 * basic lifecycle operations
diff --git a/drivers/usb/host/ehci-grlib.c b/drivers/usb/host/ehci-grlib.c
index 83ab51af250f..b52a66ce92e8 100644
--- a/drivers/usb/host/ehci-grlib.c
+++ b/drivers/usb/host/ehci-grlib.c
@@ -43,7 +43,7 @@ static const struct hc_driver ehci_grlib_hc_driver = {
43 * generic hardware linkage 43 * generic hardware linkage
44 */ 44 */
45 .irq = ehci_irq, 45 .irq = ehci_irq,
46 .flags = HCD_MEMORY | HCD_USB2, 46 .flags = HCD_MEMORY | HCD_USB2 | HCD_BH,
47 47
48 /* 48 /*
49 * basic lifecycle operations 49 * basic lifecycle operations
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index 86ab9fd9fe9e..e8ba4c44223a 100644
--- a/drivers/usb/host/ehci-hcd.c
+++ b/drivers/usb/host/ehci-hcd.c
@@ -110,6 +110,9 @@ MODULE_PARM_DESC (ignore_oc, "ignore bogus hardware overcurrent indications");
110#include "ehci.h" 110#include "ehci.h"
111#include "pci-quirks.h" 111#include "pci-quirks.h"
112 112
113static void compute_tt_budget(u8 budget_table[EHCI_BANDWIDTH_SIZE],
114 struct ehci_tt *tt);
115
113/* 116/*
114 * The MosChip MCS9990 controller updates its microframe counter 117 * The MosChip MCS9990 controller updates its microframe counter
115 * a little before the frame counter, and occasionally we will read 118 * a little before the frame counter, and occasionally we will read
@@ -484,6 +487,7 @@ static int ehci_init(struct usb_hcd *hcd)
484 INIT_LIST_HEAD(&ehci->intr_qh_list); 487 INIT_LIST_HEAD(&ehci->intr_qh_list);
485 INIT_LIST_HEAD(&ehci->cached_itd_list); 488 INIT_LIST_HEAD(&ehci->cached_itd_list);
486 INIT_LIST_HEAD(&ehci->cached_sitd_list); 489 INIT_LIST_HEAD(&ehci->cached_sitd_list);
490 INIT_LIST_HEAD(&ehci->tt_list);
487 491
488 if (HCC_PGM_FRAMELISTLEN(hcc_params)) { 492 if (HCC_PGM_FRAMELISTLEN(hcc_params)) {
489 /* periodic schedule size can be smaller than default */ 493 /* periodic schedule size can be smaller than default */
@@ -956,6 +960,7 @@ rescan:
956 goto idle_timeout; 960 goto idle_timeout;
957 961
958 /* BUG_ON(!list_empty(&stream->free_list)); */ 962 /* BUG_ON(!list_empty(&stream->free_list)); */
963 reserve_release_iso_bandwidth(ehci, stream, -1);
959 kfree(stream); 964 kfree(stream);
960 goto done; 965 goto done;
961 } 966 }
@@ -982,6 +987,8 @@ idle_timeout:
982 if (qh->clearing_tt) 987 if (qh->clearing_tt)
983 goto idle_timeout; 988 goto idle_timeout;
984 if (list_empty (&qh->qtd_list)) { 989 if (list_empty (&qh->qtd_list)) {
990 if (qh->ps.bw_uperiod)
991 reserve_release_intr_bandwidth(ehci, qh, -1);
985 qh_destroy(ehci, qh); 992 qh_destroy(ehci, qh);
986 break; 993 break;
987 } 994 }
@@ -1022,7 +1029,6 @@ ehci_endpoint_reset(struct usb_hcd *hcd, struct usb_host_endpoint *ep)
1022 * the toggle bit in the QH. 1029 * the toggle bit in the QH.
1023 */ 1030 */
1024 if (qh) { 1031 if (qh) {
1025 usb_settoggle(qh->dev, epnum, is_out, 0);
1026 if (!list_empty(&qh->qtd_list)) { 1032 if (!list_empty(&qh->qtd_list)) {
1027 WARN_ONCE(1, "clear_halt for a busy endpoint\n"); 1033 WARN_ONCE(1, "clear_halt for a busy endpoint\n");
1028 } else { 1034 } else {
@@ -1030,6 +1036,7 @@ ehci_endpoint_reset(struct usb_hcd *hcd, struct usb_host_endpoint *ep)
1030 * while the QH is active. Unlink it now; 1036 * while the QH is active. Unlink it now;
1031 * re-linking will call qh_refresh(). 1037 * re-linking will call qh_refresh().
1032 */ 1038 */
1039 usb_settoggle(qh->ps.udev, epnum, is_out, 0);
1033 qh->exception = 1; 1040 qh->exception = 1;
1034 if (eptype == USB_ENDPOINT_XFER_BULK) 1041 if (eptype == USB_ENDPOINT_XFER_BULK)
1035 start_unlink_async(ehci, qh); 1042 start_unlink_async(ehci, qh);
@@ -1048,6 +1055,19 @@ static int ehci_get_frame (struct usb_hcd *hcd)
1048 1055
1049/*-------------------------------------------------------------------------*/ 1056/*-------------------------------------------------------------------------*/
1050 1057
1058/* Device addition and removal */
1059
1060static void ehci_remove_device(struct usb_hcd *hcd, struct usb_device *udev)
1061{
1062 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
1063
1064 spin_lock_irq(&ehci->lock);
1065 drop_tt(udev);
1066 spin_unlock_irq(&ehci->lock);
1067}
1068
1069/*-------------------------------------------------------------------------*/
1070
1051#ifdef CONFIG_PM 1071#ifdef CONFIG_PM
1052 1072
1053/* suspend/resume, section 4.3 */ 1073/* suspend/resume, section 4.3 */
@@ -1075,6 +1095,14 @@ int ehci_suspend(struct usb_hcd *hcd, bool do_wakeup)
1075 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); 1095 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
1076 spin_unlock_irq(&ehci->lock); 1096 spin_unlock_irq(&ehci->lock);
1077 1097
1098 synchronize_irq(hcd->irq);
1099
1100 /* Check for race with a wakeup request */
1101 if (do_wakeup && HCD_WAKEUP_PENDING(hcd)) {
1102 ehci_resume(hcd, false);
1103 return -EBUSY;
1104 }
1105
1078 return 0; 1106 return 0;
1079} 1107}
1080EXPORT_SYMBOL_GPL(ehci_suspend); 1108EXPORT_SYMBOL_GPL(ehci_suspend);
@@ -1158,7 +1186,7 @@ static const struct hc_driver ehci_hc_driver = {
1158 * generic hardware linkage 1186 * generic hardware linkage
1159 */ 1187 */
1160 .irq = ehci_irq, 1188 .irq = ehci_irq,
1161 .flags = HCD_MEMORY | HCD_USB2, 1189 .flags = HCD_MEMORY | HCD_USB2 | HCD_BH,
1162 1190
1163 /* 1191 /*
1164 * basic lifecycle operations 1192 * basic lifecycle operations
@@ -1191,6 +1219,11 @@ static const struct hc_driver ehci_hc_driver = {
1191 .bus_resume = ehci_bus_resume, 1219 .bus_resume = ehci_bus_resume,
1192 .relinquish_port = ehci_relinquish_port, 1220 .relinquish_port = ehci_relinquish_port,
1193 .port_handed_over = ehci_port_handed_over, 1221 .port_handed_over = ehci_port_handed_over,
1222
1223 /*
1224 * device support
1225 */
1226 .free_dev = ehci_remove_device,
1194}; 1227};
1195 1228
1196void ehci_init_driver(struct hc_driver *drv, 1229void ehci_init_driver(struct hc_driver *drv,
@@ -1238,11 +1271,6 @@ MODULE_LICENSE ("GPL");
1238#define XILINX_OF_PLATFORM_DRIVER ehci_hcd_xilinx_of_driver 1271#define XILINX_OF_PLATFORM_DRIVER ehci_hcd_xilinx_of_driver
1239#endif 1272#endif
1240 1273
1241#ifdef CONFIG_USB_W90X900_EHCI
1242#include "ehci-w90x900.c"
1243#define PLATFORM_DRIVER ehci_hcd_w90x900_driver
1244#endif
1245
1246#ifdef CONFIG_USB_OCTEON_EHCI 1274#ifdef CONFIG_USB_OCTEON_EHCI
1247#include "ehci-octeon.c" 1275#include "ehci-octeon.c"
1248#define PLATFORM_DRIVER ehci_octeon_driver 1276#define PLATFORM_DRIVER ehci_octeon_driver
diff --git a/drivers/usb/host/ehci-mem.c b/drivers/usb/host/ehci-mem.c
index 52a77734a225..c0fb6a8ae6a3 100644
--- a/drivers/usb/host/ehci-mem.c
+++ b/drivers/usb/host/ehci-mem.c
@@ -224,11 +224,11 @@ static int ehci_mem_init (struct ehci_hcd *ehci, gfp_t flags)
224 hw->hw_next = EHCI_LIST_END(ehci); 224 hw->hw_next = EHCI_LIST_END(ehci);
225 hw->hw_qtd_next = EHCI_LIST_END(ehci); 225 hw->hw_qtd_next = EHCI_LIST_END(ehci);
226 hw->hw_alt_next = EHCI_LIST_END(ehci); 226 hw->hw_alt_next = EHCI_LIST_END(ehci);
227 hw->hw_token &= ~QTD_STS_ACTIVE;
228 ehci->dummy->hw = hw; 227 ehci->dummy->hw = hw;
229 228
230 for (i = 0; i < ehci->periodic_size; i++) 229 for (i = 0; i < ehci->periodic_size; i++)
231 ehci->periodic[i] = ehci->dummy->qh_dma; 230 ehci->periodic[i] = cpu_to_hc32(ehci,
231 ehci->dummy->qh_dma);
232 } else { 232 } else {
233 for (i = 0; i < ehci->periodic_size; i++) 233 for (i = 0; i < ehci->periodic_size; i++)
234 ehci->periodic[i] = EHCI_LIST_END(ehci); 234 ehci->periodic[i] = EHCI_LIST_END(ehci);
diff --git a/drivers/usb/host/ehci-msm.c b/drivers/usb/host/ehci-msm.c
index 0f717dc688b7..f341651d6f6c 100644
--- a/drivers/usb/host/ehci-msm.c
+++ b/drivers/usb/host/ehci-msm.c
@@ -42,7 +42,6 @@
42 42
43static const char hcd_name[] = "ehci-msm"; 43static const char hcd_name[] = "ehci-msm";
44static struct hc_driver __read_mostly msm_hc_driver; 44static struct hc_driver __read_mostly msm_hc_driver;
45static struct usb_phy *phy;
46 45
47static int ehci_msm_reset(struct usb_hcd *hcd) 46static int ehci_msm_reset(struct usb_hcd *hcd)
48{ 47{
@@ -70,6 +69,7 @@ static int ehci_msm_probe(struct platform_device *pdev)
70{ 69{
71 struct usb_hcd *hcd; 70 struct usb_hcd *hcd;
72 struct resource *res; 71 struct resource *res;
72 struct usb_phy *phy;
73 int ret; 73 int ret;
74 74
75 dev_dbg(&pdev->dev, "ehci_msm proble\n"); 75 dev_dbg(&pdev->dev, "ehci_msm proble\n");
@@ -108,10 +108,14 @@ static int ehci_msm_probe(struct platform_device *pdev)
108 * powering up VBUS, mapping of registers address space and power 108 * powering up VBUS, mapping of registers address space and power
109 * management. 109 * management.
110 */ 110 */
111 phy = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2); 111 if (pdev->dev.of_node)
112 phy = devm_usb_get_phy_by_phandle(&pdev->dev, "usb-phy", 0);
113 else
114 phy = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2);
115
112 if (IS_ERR(phy)) { 116 if (IS_ERR(phy)) {
113 dev_err(&pdev->dev, "unable to find transceiver\n"); 117 dev_err(&pdev->dev, "unable to find transceiver\n");
114 ret = -ENODEV; 118 ret = -EPROBE_DEFER;
115 goto put_hcd; 119 goto put_hcd;
116 } 120 }
117 121
@@ -121,6 +125,7 @@ static int ehci_msm_probe(struct platform_device *pdev)
121 goto put_hcd; 125 goto put_hcd;
122 } 126 }
123 127
128 hcd->phy = phy;
124 device_init_wakeup(&pdev->dev, 1); 129 device_init_wakeup(&pdev->dev, 1);
125 /* 130 /*
126 * OTG device parent of HCD takes care of putting 131 * OTG device parent of HCD takes care of putting
@@ -147,7 +152,7 @@ static int ehci_msm_remove(struct platform_device *pdev)
147 pm_runtime_disable(&pdev->dev); 152 pm_runtime_disable(&pdev->dev);
148 pm_runtime_set_suspended(&pdev->dev); 153 pm_runtime_set_suspended(&pdev->dev);
149 154
150 otg_set_host(phy->otg, NULL); 155 otg_set_host(hcd->phy->otg, NULL);
151 156
152 /* FIXME: need to call usb_remove_hcd() here? */ 157 /* FIXME: need to call usb_remove_hcd() here? */
153 158
@@ -186,12 +191,19 @@ static const struct dev_pm_ops ehci_msm_dev_pm_ops = {
186 .resume = ehci_msm_pm_resume, 191 .resume = ehci_msm_pm_resume,
187}; 192};
188 193
194static struct of_device_id msm_ehci_dt_match[] = {
195 { .compatible = "qcom,ehci-host", },
196 {}
197};
198MODULE_DEVICE_TABLE(of, msm_ehci_dt_match);
199
189static struct platform_driver ehci_msm_driver = { 200static struct platform_driver ehci_msm_driver = {
190 .probe = ehci_msm_probe, 201 .probe = ehci_msm_probe,
191 .remove = ehci_msm_remove, 202 .remove = ehci_msm_remove,
192 .driver = { 203 .driver = {
193 .name = "msm_hsusb_host", 204 .name = "msm_hsusb_host",
194 .pm = &ehci_msm_dev_pm_ops, 205 .pm = &ehci_msm_dev_pm_ops,
206 .of_match_table = msm_ehci_dt_match,
195 }, 207 },
196}; 208};
197 209
diff --git a/drivers/usb/host/ehci-mv.c b/drivers/usb/host/ehci-mv.c
index 35cdbd88bbbe..417c10da9450 100644
--- a/drivers/usb/host/ehci-mv.c
+++ b/drivers/usb/host/ehci-mv.c
@@ -96,7 +96,7 @@ static const struct hc_driver mv_ehci_hc_driver = {
96 * generic hardware linkage 96 * generic hardware linkage
97 */ 97 */
98 .irq = ehci_irq, 98 .irq = ehci_irq,
99 .flags = HCD_MEMORY | HCD_USB2, 99 .flags = HCD_MEMORY | HCD_USB2 | HCD_BH,
100 100
101 /* 101 /*
102 * basic lifecycle operations 102 * basic lifecycle operations
diff --git a/drivers/usb/host/ehci-octeon.c b/drivers/usb/host/ehci-octeon.c
index 45cc00158412..ab0397e4d8f3 100644
--- a/drivers/usb/host/ehci-octeon.c
+++ b/drivers/usb/host/ehci-octeon.c
@@ -51,7 +51,7 @@ static const struct hc_driver ehci_octeon_hc_driver = {
51 * generic hardware linkage 51 * generic hardware linkage
52 */ 52 */
53 .irq = ehci_irq, 53 .irq = ehci_irq,
54 .flags = HCD_MEMORY | HCD_USB2, 54 .flags = HCD_MEMORY | HCD_USB2 | HCD_BH,
55 55
56 /* 56 /*
57 * basic lifecycle operations 57 * basic lifecycle operations
diff --git a/drivers/usb/host/ehci-pci.c b/drivers/usb/host/ehci-pci.c
index 854c2ec7b699..3e86bf4371b3 100644
--- a/drivers/usb/host/ehci-pci.c
+++ b/drivers/usb/host/ehci-pci.c
@@ -58,8 +58,6 @@ static int ehci_pci_setup(struct usb_hcd *hcd)
58{ 58{
59 struct ehci_hcd *ehci = hcd_to_ehci(hcd); 59 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
60 struct pci_dev *pdev = to_pci_dev(hcd->self.controller); 60 struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
61 struct pci_dev *p_smbus;
62 u8 rev;
63 u32 temp; 61 u32 temp;
64 int retval; 62 int retval;
65 63
@@ -175,22 +173,12 @@ static int ehci_pci_setup(struct usb_hcd *hcd)
175 /* SB600 and old version of SB700 have a bug in EHCI controller, 173 /* SB600 and old version of SB700 have a bug in EHCI controller,
176 * which causes usb devices lose response in some cases. 174 * which causes usb devices lose response in some cases.
177 */ 175 */
178 if ((pdev->device == 0x4386) || (pdev->device == 0x4396)) { 176 if ((pdev->device == 0x4386 || pdev->device == 0x4396) &&
179 p_smbus = pci_get_device(PCI_VENDOR_ID_ATI, 177 usb_amd_hang_symptom_quirk()) {
180 PCI_DEVICE_ID_ATI_SBX00_SMBUS, 178 u8 tmp;
181 NULL); 179 ehci_info(ehci, "applying AMD SB600/SB700 USB freeze workaround\n");
182 if (!p_smbus) 180 pci_read_config_byte(pdev, 0x53, &tmp);
183 break; 181 pci_write_config_byte(pdev, 0x53, tmp | (1<<3));
184 rev = p_smbus->revision;
185 if ((pdev->device == 0x4386) || (rev == 0x3a)
186 || (rev == 0x3b)) {
187 u8 tmp;
188 ehci_info(ehci, "applying AMD SB600/SB700 USB "
189 "freeze workaround\n");
190 pci_read_config_byte(pdev, 0x53, &tmp);
191 pci_write_config_byte(pdev, 0x53, tmp | (1<<3));
192 }
193 pci_dev_put(p_smbus);
194 } 182 }
195 break; 183 break;
196 case PCI_VENDOR_ID_NETMOS: 184 case PCI_VENDOR_ID_NETMOS:
diff --git a/drivers/usb/host/ehci-pmcmsp.c b/drivers/usb/host/ehci-pmcmsp.c
index 601e208bd782..893b707f0000 100644
--- a/drivers/usb/host/ehci-pmcmsp.c
+++ b/drivers/usb/host/ehci-pmcmsp.c
@@ -286,7 +286,7 @@ static const struct hc_driver ehci_msp_hc_driver = {
286#else 286#else
287 .irq = ehci_irq, 287 .irq = ehci_irq,
288#endif 288#endif
289 .flags = HCD_MEMORY | HCD_USB2, 289 .flags = HCD_MEMORY | HCD_USB2 | HCD_BH,
290 290
291 /* 291 /*
292 * basic lifecycle operations 292 * basic lifecycle operations
diff --git a/drivers/usb/host/ehci-ppc-of.c b/drivers/usb/host/ehci-ppc-of.c
index 932293fa32de..6cc5567bf9c8 100644
--- a/drivers/usb/host/ehci-ppc-of.c
+++ b/drivers/usb/host/ehci-ppc-of.c
@@ -28,7 +28,7 @@ static const struct hc_driver ehci_ppc_of_hc_driver = {
28 * generic hardware linkage 28 * generic hardware linkage
29 */ 29 */
30 .irq = ehci_irq, 30 .irq = ehci_irq,
31 .flags = HCD_MEMORY | HCD_USB2, 31 .flags = HCD_MEMORY | HCD_USB2 | HCD_BH,
32 32
33 /* 33 /*
34 * basic lifecycle operations 34 * basic lifecycle operations
diff --git a/drivers/usb/host/ehci-ps3.c b/drivers/usb/host/ehci-ps3.c
index fd983771b025..8188542ba17e 100644
--- a/drivers/usb/host/ehci-ps3.c
+++ b/drivers/usb/host/ehci-ps3.c
@@ -71,7 +71,7 @@ static const struct hc_driver ps3_ehci_hc_driver = {
71 .product_desc = "PS3 EHCI Host Controller", 71 .product_desc = "PS3 EHCI Host Controller",
72 .hcd_priv_size = sizeof(struct ehci_hcd), 72 .hcd_priv_size = sizeof(struct ehci_hcd),
73 .irq = ehci_irq, 73 .irq = ehci_irq,
74 .flags = HCD_MEMORY | HCD_USB2, 74 .flags = HCD_MEMORY | HCD_USB2 | HCD_BH,
75 .reset = ps3_ehci_hc_reset, 75 .reset = ps3_ehci_hc_reset,
76 .start = ehci_run, 76 .start = ehci_run,
77 .stop = ehci_stop, 77 .stop = ehci_stop,
diff --git a/drivers/usb/host/ehci-q.c b/drivers/usb/host/ehci-q.c
index a7f776a13eb1..db05bd8ee9d5 100644
--- a/drivers/usb/host/ehci-q.c
+++ b/drivers/usb/host/ehci-q.c
@@ -105,9 +105,9 @@ qh_update (struct ehci_hcd *ehci, struct ehci_qh *qh, struct ehci_qtd *qtd)
105 105
106 is_out = qh->is_out; 106 is_out = qh->is_out;
107 epnum = (hc32_to_cpup(ehci, &hw->hw_info1) >> 8) & 0x0f; 107 epnum = (hc32_to_cpup(ehci, &hw->hw_info1) >> 8) & 0x0f;
108 if (unlikely (!usb_gettoggle (qh->dev, epnum, is_out))) { 108 if (unlikely(!usb_gettoggle(qh->ps.udev, epnum, is_out))) {
109 hw->hw_token &= ~cpu_to_hc32(ehci, QTD_TOGGLE); 109 hw->hw_token &= ~cpu_to_hc32(ehci, QTD_TOGGLE);
110 usb_settoggle (qh->dev, epnum, is_out, 1); 110 usb_settoggle(qh->ps.udev, epnum, is_out, 1);
111 } 111 }
112 } 112 }
113 113
@@ -247,8 +247,6 @@ static int qtd_copy_status (
247 247
248static void 248static void
249ehci_urb_done(struct ehci_hcd *ehci, struct urb *urb, int status) 249ehci_urb_done(struct ehci_hcd *ehci, struct urb *urb, int status)
250__releases(ehci->lock)
251__acquires(ehci->lock)
252{ 250{
253 if (usb_pipetype(urb->pipe) == PIPE_INTERRUPT) { 251 if (usb_pipetype(urb->pipe) == PIPE_INTERRUPT) {
254 /* ... update hc-wide periodic stats */ 252 /* ... update hc-wide periodic stats */
@@ -274,11 +272,8 @@ __acquires(ehci->lock)
274 urb->actual_length, urb->transfer_buffer_length); 272 urb->actual_length, urb->transfer_buffer_length);
275#endif 273#endif
276 274
277 /* complete() can reenter this HCD */
278 usb_hcd_unlink_urb_from_ep(ehci_to_hcd(ehci), urb); 275 usb_hcd_unlink_urb_from_ep(ehci_to_hcd(ehci), urb);
279 spin_unlock (&ehci->lock);
280 usb_hcd_giveback_urb(ehci_to_hcd(ehci), urb, status); 276 usb_hcd_giveback_urb(ehci_to_hcd(ehci), urb, status);
281 spin_lock (&ehci->lock);
282} 277}
283 278
284static int qh_schedule (struct ehci_hcd *ehci, struct ehci_qh *qh); 279static int qh_schedule (struct ehci_hcd *ehci, struct ehci_qh *qh);
@@ -802,26 +797,35 @@ qh_make (
802 * For control/bulk requests, the HC or TT handles these. 797 * For control/bulk requests, the HC or TT handles these.
803 */ 798 */
804 if (type == PIPE_INTERRUPT) { 799 if (type == PIPE_INTERRUPT) {
805 qh->usecs = NS_TO_US(usb_calc_bus_time(USB_SPEED_HIGH, 800 unsigned tmp;
801
802 qh->ps.usecs = NS_TO_US(usb_calc_bus_time(USB_SPEED_HIGH,
806 is_input, 0, 803 is_input, 0,
807 hb_mult(maxp) * max_packet(maxp))); 804 hb_mult(maxp) * max_packet(maxp)));
808 qh->start = NO_FRAME; 805 qh->ps.phase = NO_FRAME;
809 806
810 if (urb->dev->speed == USB_SPEED_HIGH) { 807 if (urb->dev->speed == USB_SPEED_HIGH) {
811 qh->c_usecs = 0; 808 qh->ps.c_usecs = 0;
812 qh->gap_uf = 0; 809 qh->gap_uf = 0;
813 810
814 qh->period = urb->interval >> 3; 811 if (urb->interval > 1 && urb->interval < 8) {
815 if (qh->period == 0 && urb->interval != 1) {
816 /* NOTE interval 2 or 4 uframes could work. 812 /* NOTE interval 2 or 4 uframes could work.
817 * But interval 1 scheduling is simpler, and 813 * But interval 1 scheduling is simpler, and
818 * includes high bandwidth. 814 * includes high bandwidth.
819 */ 815 */
820 urb->interval = 1; 816 urb->interval = 1;
821 } else if (qh->period > ehci->periodic_size) { 817 } else if (urb->interval > ehci->periodic_size << 3) {
822 qh->period = ehci->periodic_size; 818 urb->interval = ehci->periodic_size << 3;
823 urb->interval = qh->period << 3;
824 } 819 }
820 qh->ps.period = urb->interval >> 3;
821
822 /* period for bandwidth allocation */
823 tmp = min_t(unsigned, EHCI_BANDWIDTH_SIZE,
824 1 << (urb->ep->desc.bInterval - 1));
825
826 /* Allow urb->interval to override */
827 qh->ps.bw_uperiod = min_t(unsigned, tmp, urb->interval);
828 qh->ps.bw_period = qh->ps.bw_uperiod >> 3;
825 } else { 829 } else {
826 int think_time; 830 int think_time;
827 831
@@ -831,27 +835,35 @@ qh_make (
831 835
832 /* FIXME this just approximates SPLIT/CSPLIT times */ 836 /* FIXME this just approximates SPLIT/CSPLIT times */
833 if (is_input) { // SPLIT, gap, CSPLIT+DATA 837 if (is_input) { // SPLIT, gap, CSPLIT+DATA
834 qh->c_usecs = qh->usecs + HS_USECS (0); 838 qh->ps.c_usecs = qh->ps.usecs + HS_USECS(0);
835 qh->usecs = HS_USECS (1); 839 qh->ps.usecs = HS_USECS(1);
836 } else { // SPLIT+DATA, gap, CSPLIT 840 } else { // SPLIT+DATA, gap, CSPLIT
837 qh->usecs += HS_USECS (1); 841 qh->ps.usecs += HS_USECS(1);
838 qh->c_usecs = HS_USECS (0); 842 qh->ps.c_usecs = HS_USECS(0);
839 } 843 }
840 844
841 think_time = tt ? tt->think_time : 0; 845 think_time = tt ? tt->think_time : 0;
842 qh->tt_usecs = NS_TO_US (think_time + 846 qh->ps.tt_usecs = NS_TO_US(think_time +
843 usb_calc_bus_time (urb->dev->speed, 847 usb_calc_bus_time (urb->dev->speed,
844 is_input, 0, max_packet (maxp))); 848 is_input, 0, max_packet (maxp)));
845 qh->period = urb->interval; 849 if (urb->interval > ehci->periodic_size)
846 if (qh->period > ehci->periodic_size) { 850 urb->interval = ehci->periodic_size;
847 qh->period = ehci->periodic_size; 851 qh->ps.period = urb->interval;
848 urb->interval = qh->period; 852
849 } 853 /* period for bandwidth allocation */
854 tmp = min_t(unsigned, EHCI_BANDWIDTH_FRAMES,
855 urb->ep->desc.bInterval);
856 tmp = rounddown_pow_of_two(tmp);
857
858 /* Allow urb->interval to override */
859 qh->ps.bw_period = min_t(unsigned, tmp, urb->interval);
860 qh->ps.bw_uperiod = qh->ps.bw_period << 3;
850 } 861 }
851 } 862 }
852 863
853 /* support for tt scheduling, and access to toggles */ 864 /* support for tt scheduling, and access to toggles */
854 qh->dev = urb->dev; 865 qh->ps.udev = urb->dev;
866 qh->ps.ep = urb->ep;
855 867
856 /* using TT? */ 868 /* using TT? */
857 switch (urb->dev->speed) { 869 switch (urb->dev->speed) {
diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c
index 85dd24ed97a6..e113fd73aeae 100644
--- a/drivers/usb/host/ehci-sched.c
+++ b/drivers/usb/host/ehci-sched.c
@@ -103,83 +103,210 @@ static void periodic_unlink (struct ehci_hcd *ehci, unsigned frame, void *ptr)
103 *hw_p = *shadow_next_periodic(ehci, &here, 103 *hw_p = *shadow_next_periodic(ehci, &here,
104 Q_NEXT_TYPE(ehci, *hw_p)); 104 Q_NEXT_TYPE(ehci, *hw_p));
105 else 105 else
106 *hw_p = ehci->dummy->qh_dma; 106 *hw_p = cpu_to_hc32(ehci, ehci->dummy->qh_dma);
107} 107}
108 108
109/* how many of the uframe's 125 usecs are allocated? */ 109/*-------------------------------------------------------------------------*/
110static unsigned short 110
111periodic_usecs (struct ehci_hcd *ehci, unsigned frame, unsigned uframe) 111/* Bandwidth and TT management */
112
113/* Find the TT data structure for this device; create it if necessary */
114static struct ehci_tt *find_tt(struct usb_device *udev)
112{ 115{
113 __hc32 *hw_p = &ehci->periodic [frame]; 116 struct usb_tt *utt = udev->tt;
114 union ehci_shadow *q = &ehci->pshadow [frame]; 117 struct ehci_tt *tt, **tt_index, **ptt;
115 unsigned usecs = 0; 118 unsigned port;
116 struct ehci_qh_hw *hw; 119 bool allocated_index = false;
117 120
118 while (q->ptr) { 121 if (!utt)
119 switch (hc32_to_cpu(ehci, Q_NEXT_TYPE(ehci, *hw_p))) { 122 return NULL; /* Not below a TT */
120 case Q_TYPE_QH: 123
121 hw = q->qh->hw; 124 /*
122 /* is it in the S-mask? */ 125 * Find/create our data structure.
123 if (hw->hw_info2 & cpu_to_hc32(ehci, 1 << uframe)) 126 * For hubs with a single TT, we get it directly.
124 usecs += q->qh->usecs; 127 * For hubs with multiple TTs, there's an extra level of pointers.
125 /* ... or C-mask? */ 128 */
126 if (hw->hw_info2 & cpu_to_hc32(ehci, 129 tt_index = NULL;
127 1 << (8 + uframe))) 130 if (utt->multi) {
128 usecs += q->qh->c_usecs; 131 tt_index = utt->hcpriv;
129 hw_p = &hw->hw_next; 132 if (!tt_index) { /* Create the index array */
130 q = &q->qh->qh_next; 133 tt_index = kzalloc(utt->hub->maxchild *
131 break; 134 sizeof(*tt_index), GFP_ATOMIC);
132 // case Q_TYPE_FSTN: 135 if (!tt_index)
133 default: 136 return ERR_PTR(-ENOMEM);
134 /* for "save place" FSTNs, count the relevant INTR 137 utt->hcpriv = tt_index;
135 * bandwidth from the previous frame 138 allocated_index = true;
136 */ 139 }
137 if (q->fstn->hw_prev != EHCI_LIST_END(ehci)) { 140 port = udev->ttport - 1;
138 ehci_dbg (ehci, "ignoring FSTN cost ...\n"); 141 ptt = &tt_index[port];
139 } 142 } else {
140 hw_p = &q->fstn->hw_next; 143 port = 0;
141 q = &q->fstn->fstn_next; 144 ptt = (struct ehci_tt **) &utt->hcpriv;
142 break; 145 }
143 case Q_TYPE_ITD: 146
144 if (q->itd->hw_transaction[uframe]) 147 tt = *ptt;
145 usecs += q->itd->stream->usecs; 148 if (!tt) { /* Create the ehci_tt */
146 hw_p = &q->itd->hw_next; 149 struct ehci_hcd *ehci =
147 q = &q->itd->itd_next; 150 hcd_to_ehci(bus_to_hcd(udev->bus));
148 break;
149 case Q_TYPE_SITD:
150 /* is it in the S-mask? (count SPLIT, DATA) */
151 if (q->sitd->hw_uframe & cpu_to_hc32(ehci,
152 1 << uframe)) {
153 if (q->sitd->hw_fullspeed_ep &
154 cpu_to_hc32(ehci, 1<<31))
155 usecs += q->sitd->stream->usecs;
156 else /* worst case for OUT start-split */
157 usecs += HS_USECS_ISO (188);
158 }
159 151
160 /* ... C-mask? (count CSPLIT, DATA) */ 152 tt = kzalloc(sizeof(*tt), GFP_ATOMIC);
161 if (q->sitd->hw_uframe & 153 if (!tt) {
162 cpu_to_hc32(ehci, 1 << (8 + uframe))) { 154 if (allocated_index) {
163 /* worst case for IN complete-split */ 155 utt->hcpriv = NULL;
164 usecs += q->sitd->stream->c_usecs; 156 kfree(tt_index);
165 } 157 }
158 return ERR_PTR(-ENOMEM);
159 }
160 list_add_tail(&tt->tt_list, &ehci->tt_list);
161 INIT_LIST_HEAD(&tt->ps_list);
162 tt->usb_tt = utt;
163 tt->tt_port = port;
164 *ptt = tt;
165 }
166 166
167 hw_p = &q->sitd->hw_next; 167 return tt;
168 q = &q->sitd->sitd_next; 168}
169 break; 169
170/* Release the TT above udev, if it's not in use */
171static void drop_tt(struct usb_device *udev)
172{
173 struct usb_tt *utt = udev->tt;
174 struct ehci_tt *tt, **tt_index, **ptt;
175 int cnt, i;
176
177 if (!utt || !utt->hcpriv)
178 return; /* Not below a TT, or never allocated */
179
180 cnt = 0;
181 if (utt->multi) {
182 tt_index = utt->hcpriv;
183 ptt = &tt_index[udev->ttport - 1];
184
185 /* How many entries are left in tt_index? */
186 for (i = 0; i < utt->hub->maxchild; ++i)
187 cnt += !!tt_index[i];
188 } else {
189 tt_index = NULL;
190 ptt = (struct ehci_tt **) &utt->hcpriv;
191 }
192
193 tt = *ptt;
194 if (!tt || !list_empty(&tt->ps_list))
195 return; /* never allocated, or still in use */
196
197 list_del(&tt->tt_list);
198 *ptt = NULL;
199 kfree(tt);
200 if (cnt == 1) {
201 utt->hcpriv = NULL;
202 kfree(tt_index);
203 }
204}
205
206static void bandwidth_dbg(struct ehci_hcd *ehci, int sign, char *type,
207 struct ehci_per_sched *ps)
208{
209 dev_dbg(&ps->udev->dev,
210 "ep %02x: %s %s @ %u+%u (%u.%u+%u) [%u/%u us] mask %04x\n",
211 ps->ep->desc.bEndpointAddress,
212 (sign >= 0 ? "reserve" : "release"), type,
213 (ps->bw_phase << 3) + ps->phase_uf, ps->bw_uperiod,
214 ps->phase, ps->phase_uf, ps->period,
215 ps->usecs, ps->c_usecs, ps->cs_mask);
216}
217
218static void reserve_release_intr_bandwidth(struct ehci_hcd *ehci,
219 struct ehci_qh *qh, int sign)
220{
221 unsigned start_uf;
222 unsigned i, j, m;
223 int usecs = qh->ps.usecs;
224 int c_usecs = qh->ps.c_usecs;
225 int tt_usecs = qh->ps.tt_usecs;
226 struct ehci_tt *tt;
227
228 if (qh->ps.phase == NO_FRAME) /* Bandwidth wasn't reserved */
229 return;
230 start_uf = qh->ps.bw_phase << 3;
231
232 bandwidth_dbg(ehci, sign, "intr", &qh->ps);
233
234 if (sign < 0) { /* Release bandwidth */
235 usecs = -usecs;
236 c_usecs = -c_usecs;
237 tt_usecs = -tt_usecs;
238 }
239
240 /* Entire transaction (high speed) or start-split (full/low speed) */
241 for (i = start_uf + qh->ps.phase_uf; i < EHCI_BANDWIDTH_SIZE;
242 i += qh->ps.bw_uperiod)
243 ehci->bandwidth[i] += usecs;
244
245 /* Complete-split (full/low speed) */
246 if (qh->ps.c_usecs) {
247 /* NOTE: adjustments needed for FSTN */
248 for (i = start_uf; i < EHCI_BANDWIDTH_SIZE;
249 i += qh->ps.bw_uperiod) {
250 for ((j = 2, m = 1 << (j+8)); j < 8; (++j, m <<= 1)) {
251 if (qh->ps.cs_mask & m)
252 ehci->bandwidth[i+j] += c_usecs;
253 }
170 } 254 }
171 } 255 }
172#if defined(DEBUG) || defined(CONFIG_DYNAMIC_DEBUG) 256
173 if (usecs > ehci->uframe_periodic_max) 257 /* FS/LS bus bandwidth */
174 ehci_err (ehci, "uframe %d sched overrun: %d usecs\n", 258 if (tt_usecs) {
175 frame * 8 + uframe, usecs); 259 tt = find_tt(qh->ps.udev);
176#endif 260 if (sign > 0)
177 return usecs; 261 list_add_tail(&qh->ps.ps_list, &tt->ps_list);
262 else
263 list_del(&qh->ps.ps_list);
264
265 for (i = start_uf >> 3; i < EHCI_BANDWIDTH_FRAMES;
266 i += qh->ps.bw_period)
267 tt->bandwidth[i] += tt_usecs;
268 }
178} 269}
179 270
180/*-------------------------------------------------------------------------*/ 271/*-------------------------------------------------------------------------*/
181 272
182static int same_tt (struct usb_device *dev1, struct usb_device *dev2) 273static void compute_tt_budget(u8 budget_table[EHCI_BANDWIDTH_SIZE],
274 struct ehci_tt *tt)
275{
276 struct ehci_per_sched *ps;
277 unsigned uframe, uf, x;
278 u8 *budget_line;
279
280 if (!tt)
281 return;
282 memset(budget_table, 0, EHCI_BANDWIDTH_SIZE);
283
284 /* Add up the contributions from all the endpoints using this TT */
285 list_for_each_entry(ps, &tt->ps_list, ps_list) {
286 for (uframe = ps->bw_phase << 3; uframe < EHCI_BANDWIDTH_SIZE;
287 uframe += ps->bw_uperiod) {
288 budget_line = &budget_table[uframe];
289 x = ps->tt_usecs;
290
291 /* propagate the time forward */
292 for (uf = ps->phase_uf; uf < 8; ++uf) {
293 x += budget_line[uf];
294
295 /* Each microframe lasts 125 us */
296 if (x <= 125) {
297 budget_line[uf] = x;
298 break;
299 } else {
300 budget_line[uf] = 125;
301 x -= 125;
302 }
303 }
304 }
305 }
306}
307
308static int __maybe_unused same_tt(struct usb_device *dev1,
309 struct usb_device *dev2)
183{ 310{
184 if (!dev1->tt || !dev2->tt) 311 if (!dev1->tt || !dev2->tt)
185 return 0; 312 return 0;
@@ -227,68 +354,6 @@ static inline void carryover_tt_bandwidth(unsigned short tt_usecs[8])
227 } 354 }
228} 355}
229 356
230/* How many of the tt's periodic downstream 1000 usecs are allocated?
231 *
232 * While this measures the bandwidth in terms of usecs/uframe,
233 * the low/fullspeed bus has no notion of uframes, so any particular
234 * low/fullspeed transfer can "carry over" from one uframe to the next,
235 * since the TT just performs downstream transfers in sequence.
236 *
237 * For example two separate 100 usec transfers can start in the same uframe,
238 * and the second one would "carry over" 75 usecs into the next uframe.
239 */
240static void
241periodic_tt_usecs (
242 struct ehci_hcd *ehci,
243 struct usb_device *dev,
244 unsigned frame,
245 unsigned short tt_usecs[8]
246)
247{
248 __hc32 *hw_p = &ehci->periodic [frame];
249 union ehci_shadow *q = &ehci->pshadow [frame];
250 unsigned char uf;
251
252 memset(tt_usecs, 0, 16);
253
254 while (q->ptr) {
255 switch (hc32_to_cpu(ehci, Q_NEXT_TYPE(ehci, *hw_p))) {
256 case Q_TYPE_ITD:
257 hw_p = &q->itd->hw_next;
258 q = &q->itd->itd_next;
259 continue;
260 case Q_TYPE_QH:
261 if (same_tt(dev, q->qh->dev)) {
262 uf = tt_start_uframe(ehci, q->qh->hw->hw_info2);
263 tt_usecs[uf] += q->qh->tt_usecs;
264 }
265 hw_p = &q->qh->hw->hw_next;
266 q = &q->qh->qh_next;
267 continue;
268 case Q_TYPE_SITD:
269 if (same_tt(dev, q->sitd->urb->dev)) {
270 uf = tt_start_uframe(ehci, q->sitd->hw_uframe);
271 tt_usecs[uf] += q->sitd->stream->tt_usecs;
272 }
273 hw_p = &q->sitd->hw_next;
274 q = &q->sitd->sitd_next;
275 continue;
276 // case Q_TYPE_FSTN:
277 default:
278 ehci_dbg(ehci, "ignoring periodic frame %d FSTN\n",
279 frame);
280 hw_p = &q->fstn->hw_next;
281 q = &q->fstn->fstn_next;
282 }
283 }
284
285 carryover_tt_bandwidth(tt_usecs);
286
287 if (max_tt_usecs[7] < tt_usecs[7])
288 ehci_err(ehci, "frame %d tt sched overrun: %d usecs\n",
289 frame, tt_usecs[7] - max_tt_usecs[7]);
290}
291
292/* 357/*
293 * Return true if the device's tt's downstream bus is available for a 358 * Return true if the device's tt's downstream bus is available for a
294 * periodic transfer of the specified length (usecs), starting at the 359 * periodic transfer of the specified length (usecs), starting at the
@@ -312,20 +377,29 @@ periodic_tt_usecs (
312 */ 377 */
313static int tt_available ( 378static int tt_available (
314 struct ehci_hcd *ehci, 379 struct ehci_hcd *ehci,
315 unsigned period, 380 struct ehci_per_sched *ps,
316 struct usb_device *dev, 381 struct ehci_tt *tt,
317 unsigned frame, 382 unsigned frame,
318 unsigned uframe, 383 unsigned uframe
319 u16 usecs
320) 384)
321{ 385{
386 unsigned period = ps->bw_period;
387 unsigned usecs = ps->tt_usecs;
388
322 if ((period == 0) || (uframe >= 7)) /* error */ 389 if ((period == 0) || (uframe >= 7)) /* error */
323 return 0; 390 return 0;
324 391
325 for (; frame < ehci->periodic_size; frame += period) { 392 for (frame &= period - 1; frame < EHCI_BANDWIDTH_FRAMES;
326 unsigned short tt_usecs[8]; 393 frame += period) {
394 unsigned i, uf;
395 unsigned short tt_usecs[8];
327 396
328 periodic_tt_usecs (ehci, dev, frame, tt_usecs); 397 if (tt->bandwidth[frame] + usecs > 900)
398 return 0;
399
400 uf = frame << 3;
401 for (i = 0; i < 8; (++i, ++uf))
402 tt_usecs[i] = ehci->tt_budget[uf];
329 403
330 if (max_tt_usecs[uframe] <= tt_usecs[uframe]) 404 if (max_tt_usecs[uframe] <= tt_usecs[uframe])
331 return 0; 405 return 0;
@@ -337,7 +411,7 @@ static int tt_available (
337 */ 411 */
338 if (125 < usecs) { 412 if (125 < usecs) {
339 int ufs = (usecs / 125); 413 int ufs = (usecs / 125);
340 int i; 414
341 for (i = uframe; i < (uframe + ufs) && i < 8; i++) 415 for (i = uframe; i < (uframe + ufs) && i < 8; i++)
342 if (0 < tt_usecs[i]) 416 if (0 < tt_usecs[i])
343 return 0; 417 return 0;
@@ -391,7 +465,7 @@ static int tt_no_collision (
391 continue; 465 continue;
392 case Q_TYPE_QH: 466 case Q_TYPE_QH:
393 hw = here.qh->hw; 467 hw = here.qh->hw;
394 if (same_tt (dev, here.qh->dev)) { 468 if (same_tt(dev, here.qh->ps.udev)) {
395 u32 mask; 469 u32 mask;
396 470
397 mask = hc32_to_cpu(ehci, 471 mask = hc32_to_cpu(ehci,
@@ -471,19 +545,19 @@ static void disable_periodic(struct ehci_hcd *ehci)
471static void qh_link_periodic(struct ehci_hcd *ehci, struct ehci_qh *qh) 545static void qh_link_periodic(struct ehci_hcd *ehci, struct ehci_qh *qh)
472{ 546{
473 unsigned i; 547 unsigned i;
474 unsigned period = qh->period; 548 unsigned period = qh->ps.period;
475 549
476 dev_dbg (&qh->dev->dev, 550 dev_dbg(&qh->ps.udev->dev,
477 "link qh%d-%04x/%p start %d [%d/%d us]\n", 551 "link qh%d-%04x/%p start %d [%d/%d us]\n",
478 period, hc32_to_cpup(ehci, &qh->hw->hw_info2) 552 period, hc32_to_cpup(ehci, &qh->hw->hw_info2)
479 & (QH_CMASK | QH_SMASK), 553 & (QH_CMASK | QH_SMASK),
480 qh, qh->start, qh->usecs, qh->c_usecs); 554 qh, qh->ps.phase, qh->ps.usecs, qh->ps.c_usecs);
481 555
482 /* high bandwidth, or otherwise every microframe */ 556 /* high bandwidth, or otherwise every microframe */
483 if (period == 0) 557 if (period == 0)
484 period = 1; 558 period = 1;
485 559
486 for (i = qh->start; i < ehci->periodic_size; i += period) { 560 for (i = qh->ps.phase; i < ehci->periodic_size; i += period) {
487 union ehci_shadow *prev = &ehci->pshadow[i]; 561 union ehci_shadow *prev = &ehci->pshadow[i];
488 __hc32 *hw_p = &ehci->periodic[i]; 562 __hc32 *hw_p = &ehci->periodic[i];
489 union ehci_shadow here = *prev; 563 union ehci_shadow here = *prev;
@@ -503,7 +577,7 @@ static void qh_link_periodic(struct ehci_hcd *ehci, struct ehci_qh *qh)
503 * enables sharing interior tree nodes 577 * enables sharing interior tree nodes
504 */ 578 */
505 while (here.ptr && qh != here.qh) { 579 while (here.ptr && qh != here.qh) {
506 if (qh->period > here.qh->period) 580 if (qh->ps.period > here.qh->ps.period)
507 break; 581 break;
508 prev = &here.qh->qh_next; 582 prev = &here.qh->qh_next;
509 hw_p = &here.qh->hw->hw_next; 583 hw_p = &here.qh->hw->hw_next;
@@ -523,10 +597,10 @@ static void qh_link_periodic(struct ehci_hcd *ehci, struct ehci_qh *qh)
523 qh->xacterrs = 0; 597 qh->xacterrs = 0;
524 qh->exception = 0; 598 qh->exception = 0;
525 599
526 /* update per-qh bandwidth for usbfs */ 600 /* update per-qh bandwidth for debugfs */
527 ehci_to_hcd(ehci)->self.bandwidth_allocated += qh->period 601 ehci_to_hcd(ehci)->self.bandwidth_allocated += qh->ps.bw_period
528 ? ((qh->usecs + qh->c_usecs) / qh->period) 602 ? ((qh->ps.usecs + qh->ps.c_usecs) / qh->ps.bw_period)
529 : (qh->usecs * 8); 603 : (qh->ps.usecs * 8);
530 604
531 list_add(&qh->intr_node, &ehci->intr_qh_list); 605 list_add(&qh->intr_node, &ehci->intr_qh_list);
532 606
@@ -556,22 +630,21 @@ static void qh_unlink_periodic(struct ehci_hcd *ehci, struct ehci_qh *qh)
556 */ 630 */
557 631
558 /* high bandwidth, or otherwise part of every microframe */ 632 /* high bandwidth, or otherwise part of every microframe */
559 if ((period = qh->period) == 0) 633 period = qh->ps.period ? : 1;
560 period = 1;
561 634
562 for (i = qh->start; i < ehci->periodic_size; i += period) 635 for (i = qh->ps.phase; i < ehci->periodic_size; i += period)
563 periodic_unlink (ehci, i, qh); 636 periodic_unlink (ehci, i, qh);
564 637
565 /* update per-qh bandwidth for usbfs */ 638 /* update per-qh bandwidth for debugfs */
566 ehci_to_hcd(ehci)->self.bandwidth_allocated -= qh->period 639 ehci_to_hcd(ehci)->self.bandwidth_allocated -= qh->ps.bw_period
567 ? ((qh->usecs + qh->c_usecs) / qh->period) 640 ? ((qh->ps.usecs + qh->ps.c_usecs) / qh->ps.bw_period)
568 : (qh->usecs * 8); 641 : (qh->ps.usecs * 8);
569 642
570 dev_dbg (&qh->dev->dev, 643 dev_dbg(&qh->ps.udev->dev,
571 "unlink qh%d-%04x/%p start %d [%d/%d us]\n", 644 "unlink qh%d-%04x/%p start %d [%d/%d us]\n",
572 qh->period, 645 qh->ps.period,
573 hc32_to_cpup(ehci, &qh->hw->hw_info2) & (QH_CMASK | QH_SMASK), 646 hc32_to_cpup(ehci, &qh->hw->hw_info2) & (QH_CMASK | QH_SMASK),
574 qh, qh->start, qh->usecs, qh->c_usecs); 647 qh, qh->ps.phase, qh->ps.usecs, qh->ps.c_usecs);
575 648
576 /* qh->qh_next still "live" to HC */ 649 /* qh->qh_next still "live" to HC */
577 qh->qh_state = QH_STATE_UNLINK; 650 qh->qh_state = QH_STATE_UNLINK;
@@ -694,11 +767,9 @@ static int check_period (
694 struct ehci_hcd *ehci, 767 struct ehci_hcd *ehci,
695 unsigned frame, 768 unsigned frame,
696 unsigned uframe, 769 unsigned uframe,
697 unsigned period, 770 unsigned uperiod,
698 unsigned usecs 771 unsigned usecs
699) { 772) {
700 int claimed;
701
702 /* complete split running into next frame? 773 /* complete split running into next frame?
703 * given FSTN support, we could sometimes check... 774 * given FSTN support, we could sometimes check...
704 */ 775 */
@@ -708,25 +779,10 @@ static int check_period (
708 /* convert "usecs we need" to "max already claimed" */ 779 /* convert "usecs we need" to "max already claimed" */
709 usecs = ehci->uframe_periodic_max - usecs; 780 usecs = ehci->uframe_periodic_max - usecs;
710 781
711 /* we "know" 2 and 4 uframe intervals were rejected; so 782 for (uframe += frame << 3; uframe < EHCI_BANDWIDTH_SIZE;
712 * for period 0, check _every_ microframe in the schedule. 783 uframe += uperiod) {
713 */ 784 if (ehci->bandwidth[uframe] > usecs)
714 if (unlikely (period == 0)) { 785 return 0;
715 do {
716 for (uframe = 0; uframe < 7; uframe++) {
717 claimed = periodic_usecs (ehci, frame, uframe);
718 if (claimed > usecs)
719 return 0;
720 }
721 } while ((frame += 1) < ehci->periodic_size);
722
723 /* just check the specified uframe, at that period */
724 } else {
725 do {
726 claimed = periodic_usecs (ehci, frame, uframe);
727 if (claimed > usecs)
728 return 0;
729 } while ((frame += period) < ehci->periodic_size);
730 } 786 }
731 787
732 // success! 788 // success!
@@ -737,40 +793,40 @@ static int check_intr_schedule (
737 struct ehci_hcd *ehci, 793 struct ehci_hcd *ehci,
738 unsigned frame, 794 unsigned frame,
739 unsigned uframe, 795 unsigned uframe,
740 const struct ehci_qh *qh, 796 struct ehci_qh *qh,
741 __hc32 *c_maskp 797 unsigned *c_maskp,
798 struct ehci_tt *tt
742) 799)
743{ 800{
744 int retval = -ENOSPC; 801 int retval = -ENOSPC;
745 u8 mask = 0; 802 u8 mask = 0;
746 803
747 if (qh->c_usecs && uframe >= 6) /* FSTN territory? */ 804 if (qh->ps.c_usecs && uframe >= 6) /* FSTN territory? */
748 goto done; 805 goto done;
749 806
750 if (!check_period (ehci, frame, uframe, qh->period, qh->usecs)) 807 if (!check_period(ehci, frame, uframe, qh->ps.bw_uperiod, qh->ps.usecs))
751 goto done; 808 goto done;
752 if (!qh->c_usecs) { 809 if (!qh->ps.c_usecs) {
753 retval = 0; 810 retval = 0;
754 *c_maskp = 0; 811 *c_maskp = 0;
755 goto done; 812 goto done;
756 } 813 }
757 814
758#ifdef CONFIG_USB_EHCI_TT_NEWSCHED 815#ifdef CONFIG_USB_EHCI_TT_NEWSCHED
759 if (tt_available (ehci, qh->period, qh->dev, frame, uframe, 816 if (tt_available(ehci, &qh->ps, tt, frame, uframe)) {
760 qh->tt_usecs)) {
761 unsigned i; 817 unsigned i;
762 818
763 /* TODO : this may need FSTN for SSPLIT in uframe 5. */ 819 /* TODO : this may need FSTN for SSPLIT in uframe 5. */
764 for (i=uframe+1; i<8 && i<uframe+4; i++) 820 for (i = uframe+2; i < 8 && i <= uframe+4; i++)
765 if (!check_period (ehci, frame, i, 821 if (!check_period(ehci, frame, i,
766 qh->period, qh->c_usecs)) 822 qh->ps.bw_uperiod, qh->ps.c_usecs))
767 goto done; 823 goto done;
768 else 824 else
769 mask |= 1 << i; 825 mask |= 1 << i;
770 826
771 retval = 0; 827 retval = 0;
772 828
773 *c_maskp = cpu_to_hc32(ehci, mask << 8); 829 *c_maskp = mask;
774 } 830 }
775#else 831#else
776 /* Make sure this tt's buffer is also available for CSPLITs. 832 /* Make sure this tt's buffer is also available for CSPLITs.
@@ -781,15 +837,15 @@ static int check_intr_schedule (
781 * one smart pass... 837 * one smart pass...
782 */ 838 */
783 mask = 0x03 << (uframe + qh->gap_uf); 839 mask = 0x03 << (uframe + qh->gap_uf);
784 *c_maskp = cpu_to_hc32(ehci, mask << 8); 840 *c_maskp = mask;
785 841
786 mask |= 1 << uframe; 842 mask |= 1 << uframe;
787 if (tt_no_collision (ehci, qh->period, qh->dev, frame, mask)) { 843 if (tt_no_collision(ehci, qh->ps.bw_period, qh->ps.udev, frame, mask)) {
788 if (!check_period (ehci, frame, uframe + qh->gap_uf + 1, 844 if (!check_period(ehci, frame, uframe + qh->gap_uf + 1,
789 qh->period, qh->c_usecs)) 845 qh->ps.bw_uperiod, qh->ps.c_usecs))
790 goto done; 846 goto done;
791 if (!check_period (ehci, frame, uframe + qh->gap_uf, 847 if (!check_period(ehci, frame, uframe + qh->gap_uf,
792 qh->period, qh->c_usecs)) 848 qh->ps.bw_uperiod, qh->ps.c_usecs))
793 goto done; 849 goto done;
794 retval = 0; 850 retval = 0;
795 } 851 }
@@ -803,62 +859,67 @@ done:
803 */ 859 */
804static int qh_schedule(struct ehci_hcd *ehci, struct ehci_qh *qh) 860static int qh_schedule(struct ehci_hcd *ehci, struct ehci_qh *qh)
805{ 861{
806 int status; 862 int status = 0;
807 unsigned uframe; 863 unsigned uframe;
808 __hc32 c_mask; 864 unsigned c_mask;
809 unsigned frame; /* 0..(qh->period - 1), or NO_FRAME */
810 struct ehci_qh_hw *hw = qh->hw; 865 struct ehci_qh_hw *hw = qh->hw;
866 struct ehci_tt *tt;
811 867
812 hw->hw_next = EHCI_LIST_END(ehci); 868 hw->hw_next = EHCI_LIST_END(ehci);
813 frame = qh->start;
814 869
815 /* reuse the previous schedule slots, if we can */ 870 /* reuse the previous schedule slots, if we can */
816 if (frame < qh->period) { 871 if (qh->ps.phase != NO_FRAME) {
817 uframe = ffs(hc32_to_cpup(ehci, &hw->hw_info2) & QH_SMASK); 872 ehci_dbg(ehci, "reused qh %p schedule\n", qh);
818 status = check_intr_schedule (ehci, frame, --uframe, 873 return 0;
819 qh, &c_mask); 874 }
820 } else { 875
821 uframe = 0; 876 uframe = 0;
822 c_mask = 0; 877 c_mask = 0;
823 status = -ENOSPC; 878 tt = find_tt(qh->ps.udev);
879 if (IS_ERR(tt)) {
880 status = PTR_ERR(tt);
881 goto done;
824 } 882 }
883 compute_tt_budget(ehci->tt_budget, tt);
825 884
826 /* else scan the schedule to find a group of slots such that all 885 /* else scan the schedule to find a group of slots such that all
827 * uframes have enough periodic bandwidth available. 886 * uframes have enough periodic bandwidth available.
828 */ 887 */
829 if (status) { 888 /* "normal" case, uframing flexible except with splits */
830 /* "normal" case, uframing flexible except with splits */ 889 if (qh->ps.bw_period) {
831 if (qh->period) { 890 int i;
832 int i; 891 unsigned frame;
833 892
834 for (i = qh->period; status && i > 0; --i) { 893 for (i = qh->ps.bw_period; i > 0; --i) {
835 frame = ++ehci->random_frame % qh->period; 894 frame = ++ehci->random_frame & (qh->ps.bw_period - 1);
836 for (uframe = 0; uframe < 8; uframe++) { 895 for (uframe = 0; uframe < 8; uframe++) {
837 status = check_intr_schedule (ehci, 896 status = check_intr_schedule(ehci,
838 frame, uframe, qh, 897 frame, uframe, qh, &c_mask, tt);
839 &c_mask); 898 if (status == 0)
840 if (status == 0) 899 goto got_it;
841 break;
842 }
843 } 900 }
844
845 /* qh->period == 0 means every uframe */
846 } else {
847 frame = 0;
848 status = check_intr_schedule (ehci, 0, 0, qh, &c_mask);
849 } 901 }
850 if (status)
851 goto done;
852 qh->start = frame;
853 902
854 /* reset S-frame and (maybe) C-frame masks */ 903 /* qh->ps.bw_period == 0 means every uframe */
855 hw->hw_info2 &= cpu_to_hc32(ehci, ~(QH_CMASK | QH_SMASK)); 904 } else {
856 hw->hw_info2 |= qh->period 905 status = check_intr_schedule(ehci, 0, 0, qh, &c_mask, tt);
857 ? cpu_to_hc32(ehci, 1 << uframe) 906 }
858 : cpu_to_hc32(ehci, QH_SMASK); 907 if (status)
859 hw->hw_info2 |= c_mask; 908 goto done;
860 } else 909
861 ehci_dbg (ehci, "reused qh %p schedule\n", qh); 910 got_it:
911 qh->ps.phase = (qh->ps.period ? ehci->random_frame &
912 (qh->ps.period - 1) : 0);
913 qh->ps.bw_phase = qh->ps.phase & (qh->ps.bw_period - 1);
914 qh->ps.phase_uf = uframe;
915 qh->ps.cs_mask = qh->ps.period ?
916 (c_mask << 8) | (1 << uframe) :
917 QH_SMASK;
918
919 /* reset S-frame and (maybe) C-frame masks */
920 hw->hw_info2 &= cpu_to_hc32(ehci, ~(QH_CMASK | QH_SMASK));
921 hw->hw_info2 |= cpu_to_hc32(ehci, qh->ps.cs_mask);
922 reserve_release_intr_bandwidth(ehci, qh, 1);
862 923
863done: 924done:
864 return status; 925 return status;
@@ -969,7 +1030,8 @@ iso_stream_alloc (gfp_t mem_flags)
969 if (likely (stream != NULL)) { 1030 if (likely (stream != NULL)) {
970 INIT_LIST_HEAD(&stream->td_list); 1031 INIT_LIST_HEAD(&stream->td_list);
971 INIT_LIST_HEAD(&stream->free_list); 1032 INIT_LIST_HEAD(&stream->free_list);
972 stream->next_uframe = -1; 1033 stream->next_uframe = NO_FRAME;
1034 stream->ps.phase = NO_FRAME;
973 } 1035 }
974 return stream; 1036 return stream;
975} 1037}
@@ -978,25 +1040,24 @@ static void
978iso_stream_init ( 1040iso_stream_init (
979 struct ehci_hcd *ehci, 1041 struct ehci_hcd *ehci,
980 struct ehci_iso_stream *stream, 1042 struct ehci_iso_stream *stream,
981 struct usb_device *dev, 1043 struct urb *urb
982 int pipe,
983 unsigned interval
984) 1044)
985{ 1045{
986 static const u8 smask_out [] = { 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f }; 1046 static const u8 smask_out [] = { 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f };
987 1047
1048 struct usb_device *dev = urb->dev;
988 u32 buf1; 1049 u32 buf1;
989 unsigned epnum, maxp; 1050 unsigned epnum, maxp;
990 int is_input; 1051 int is_input;
991 long bandwidth; 1052 unsigned tmp;
992 1053
993 /* 1054 /*
994 * this might be a "high bandwidth" highspeed endpoint, 1055 * this might be a "high bandwidth" highspeed endpoint,
995 * as encoded in the ep descriptor's wMaxPacket field 1056 * as encoded in the ep descriptor's wMaxPacket field
996 */ 1057 */
997 epnum = usb_pipeendpoint (pipe); 1058 epnum = usb_pipeendpoint(urb->pipe);
998 is_input = usb_pipein (pipe) ? USB_DIR_IN : 0; 1059 is_input = usb_pipein(urb->pipe) ? USB_DIR_IN : 0;
999 maxp = usb_maxpacket(dev, pipe, !is_input); 1060 maxp = usb_endpoint_maxp(&urb->ep->desc);
1000 if (is_input) { 1061 if (is_input) {
1001 buf1 = (1 << 11); 1062 buf1 = (1 << 11);
1002 } else { 1063 } else {
@@ -1020,9 +1081,19 @@ iso_stream_init (
1020 /* usbfs wants to report the average usecs per frame tied up 1081 /* usbfs wants to report the average usecs per frame tied up
1021 * when transfers on this endpoint are scheduled ... 1082 * when transfers on this endpoint are scheduled ...
1022 */ 1083 */
1023 stream->usecs = HS_USECS_ISO (maxp); 1084 stream->ps.usecs = HS_USECS_ISO(maxp);
1024 bandwidth = stream->usecs * 8; 1085
1025 bandwidth /= interval; 1086 /* period for bandwidth allocation */
1087 tmp = min_t(unsigned, EHCI_BANDWIDTH_SIZE,
1088 1 << (urb->ep->desc.bInterval - 1));
1089
1090 /* Allow urb->interval to override */
1091 stream->ps.bw_uperiod = min_t(unsigned, tmp, urb->interval);
1092
1093 stream->uperiod = urb->interval;
1094 stream->ps.period = urb->interval >> 3;
1095 stream->bandwidth = stream->ps.usecs * 8 /
1096 stream->ps.bw_uperiod;
1026 1097
1027 } else { 1098 } else {
1028 u32 addr; 1099 u32 addr;
@@ -1036,36 +1107,46 @@ iso_stream_init (
1036 addr |= dev->tt->hub->devnum << 16; 1107 addr |= dev->tt->hub->devnum << 16;
1037 addr |= epnum << 8; 1108 addr |= epnum << 8;
1038 addr |= dev->devnum; 1109 addr |= dev->devnum;
1039 stream->usecs = HS_USECS_ISO (maxp); 1110 stream->ps.usecs = HS_USECS_ISO(maxp);
1040 think_time = dev->tt ? dev->tt->think_time : 0; 1111 think_time = dev->tt ? dev->tt->think_time : 0;
1041 stream->tt_usecs = NS_TO_US (think_time + usb_calc_bus_time ( 1112 stream->ps.tt_usecs = NS_TO_US(think_time + usb_calc_bus_time(
1042 dev->speed, is_input, 1, maxp)); 1113 dev->speed, is_input, 1, maxp));
1043 hs_transfers = max (1u, (maxp + 187) / 188); 1114 hs_transfers = max (1u, (maxp + 187) / 188);
1044 if (is_input) { 1115 if (is_input) {
1045 u32 tmp; 1116 u32 tmp;
1046 1117
1047 addr |= 1 << 31; 1118 addr |= 1 << 31;
1048 stream->c_usecs = stream->usecs; 1119 stream->ps.c_usecs = stream->ps.usecs;
1049 stream->usecs = HS_USECS_ISO (1); 1120 stream->ps.usecs = HS_USECS_ISO(1);
1050 stream->raw_mask = 1; 1121 stream->ps.cs_mask = 1;
1051 1122
1052 /* c-mask as specified in USB 2.0 11.18.4 3.c */ 1123 /* c-mask as specified in USB 2.0 11.18.4 3.c */
1053 tmp = (1 << (hs_transfers + 2)) - 1; 1124 tmp = (1 << (hs_transfers + 2)) - 1;
1054 stream->raw_mask |= tmp << (8 + 2); 1125 stream->ps.cs_mask |= tmp << (8 + 2);
1055 } else 1126 } else
1056 stream->raw_mask = smask_out [hs_transfers - 1]; 1127 stream->ps.cs_mask = smask_out[hs_transfers - 1];
1057 bandwidth = stream->usecs + stream->c_usecs; 1128
1058 bandwidth /= interval << 3; 1129 /* period for bandwidth allocation */
1130 tmp = min_t(unsigned, EHCI_BANDWIDTH_FRAMES,
1131 1 << (urb->ep->desc.bInterval - 1));
1132
1133 /* Allow urb->interval to override */
1134 stream->ps.bw_period = min_t(unsigned, tmp, urb->interval);
1135 stream->ps.bw_uperiod = stream->ps.bw_period << 3;
1059 1136
1060 /* stream->splits gets created from raw_mask later */ 1137 stream->ps.period = urb->interval;
1138 stream->uperiod = urb->interval << 3;
1139 stream->bandwidth = (stream->ps.usecs + stream->ps.c_usecs) /
1140 stream->ps.bw_period;
1141
1142 /* stream->splits gets created from cs_mask later */
1061 stream->address = cpu_to_hc32(ehci, addr); 1143 stream->address = cpu_to_hc32(ehci, addr);
1062 } 1144 }
1063 stream->bandwidth = bandwidth;
1064 1145
1065 stream->udev = dev; 1146 stream->ps.udev = dev;
1147 stream->ps.ep = urb->ep;
1066 1148
1067 stream->bEndpointAddress = is_input | epnum; 1149 stream->bEndpointAddress = is_input | epnum;
1068 stream->interval = interval;
1069 stream->maxp = maxp; 1150 stream->maxp = maxp;
1070} 1151}
1071 1152
@@ -1090,9 +1171,7 @@ iso_stream_find (struct ehci_hcd *ehci, struct urb *urb)
1090 stream = iso_stream_alloc(GFP_ATOMIC); 1171 stream = iso_stream_alloc(GFP_ATOMIC);
1091 if (likely (stream != NULL)) { 1172 if (likely (stream != NULL)) {
1092 ep->hcpriv = stream; 1173 ep->hcpriv = stream;
1093 stream->ep = ep; 1174 iso_stream_init(ehci, stream, urb);
1094 iso_stream_init(ehci, stream, urb->dev, urb->pipe,
1095 urb->interval);
1096 } 1175 }
1097 1176
1098 /* if dev->ep [epnum] is a QH, hw is set */ 1177 /* if dev->ep [epnum] is a QH, hw is set */
@@ -1137,7 +1216,7 @@ itd_sched_init(
1137 dma_addr_t dma = urb->transfer_dma; 1216 dma_addr_t dma = urb->transfer_dma;
1138 1217
1139 /* how many uframes are needed for these transfers */ 1218 /* how many uframes are needed for these transfers */
1140 iso_sched->span = urb->number_of_packets * stream->interval; 1219 iso_sched->span = urb->number_of_packets * stream->uperiod;
1141 1220
1142 /* figure out per-uframe itd fields that we'll need later 1221 /* figure out per-uframe itd fields that we'll need later
1143 * when we fit new itds into the schedule. 1222 * when we fit new itds into the schedule.
@@ -1236,7 +1315,7 @@ itd_urb_transaction (
1236 1315
1237 memset (itd, 0, sizeof *itd); 1316 memset (itd, 0, sizeof *itd);
1238 itd->itd_dma = itd_dma; 1317 itd->itd_dma = itd_dma;
1239 itd->frame = 9999; /* an invalid value */ 1318 itd->frame = NO_FRAME;
1240 list_add (&itd->itd_list, &sched->td_list); 1319 list_add (&itd->itd_list, &sched->td_list);
1241 } 1320 }
1242 spin_unlock_irqrestore (&ehci->lock, flags); 1321 spin_unlock_irqrestore (&ehci->lock, flags);
@@ -1249,49 +1328,106 @@ itd_urb_transaction (
1249 1328
1250/*-------------------------------------------------------------------------*/ 1329/*-------------------------------------------------------------------------*/
1251 1330
1331static void reserve_release_iso_bandwidth(struct ehci_hcd *ehci,
1332 struct ehci_iso_stream *stream, int sign)
1333{
1334 unsigned uframe;
1335 unsigned i, j;
1336 unsigned s_mask, c_mask, m;
1337 int usecs = stream->ps.usecs;
1338 int c_usecs = stream->ps.c_usecs;
1339 int tt_usecs = stream->ps.tt_usecs;
1340 struct ehci_tt *tt;
1341
1342 if (stream->ps.phase == NO_FRAME) /* Bandwidth wasn't reserved */
1343 return;
1344 uframe = stream->ps.bw_phase << 3;
1345
1346 bandwidth_dbg(ehci, sign, "iso", &stream->ps);
1347
1348 if (sign < 0) { /* Release bandwidth */
1349 usecs = -usecs;
1350 c_usecs = -c_usecs;
1351 tt_usecs = -tt_usecs;
1352 }
1353
1354 if (!stream->splits) { /* High speed */
1355 for (i = uframe + stream->ps.phase_uf; i < EHCI_BANDWIDTH_SIZE;
1356 i += stream->ps.bw_uperiod)
1357 ehci->bandwidth[i] += usecs;
1358
1359 } else { /* Full speed */
1360 s_mask = stream->ps.cs_mask;
1361 c_mask = s_mask >> 8;
1362
1363 /* NOTE: adjustment needed for frame overflow */
1364 for (i = uframe; i < EHCI_BANDWIDTH_SIZE;
1365 i += stream->ps.bw_uperiod) {
1366 for ((j = stream->ps.phase_uf, m = 1 << j); j < 8;
1367 (++j, m <<= 1)) {
1368 if (s_mask & m)
1369 ehci->bandwidth[i+j] += usecs;
1370 else if (c_mask & m)
1371 ehci->bandwidth[i+j] += c_usecs;
1372 }
1373 }
1374
1375 tt = find_tt(stream->ps.udev);
1376 if (sign > 0)
1377 list_add_tail(&stream->ps.ps_list, &tt->ps_list);
1378 else
1379 list_del(&stream->ps.ps_list);
1380
1381 for (i = uframe >> 3; i < EHCI_BANDWIDTH_FRAMES;
1382 i += stream->ps.bw_period)
1383 tt->bandwidth[i] += tt_usecs;
1384 }
1385}
1386
1252static inline int 1387static inline int
1253itd_slot_ok ( 1388itd_slot_ok (
1254 struct ehci_hcd *ehci, 1389 struct ehci_hcd *ehci,
1255 u32 mod, 1390 struct ehci_iso_stream *stream,
1256 u32 uframe, 1391 unsigned uframe
1257 u8 usecs,
1258 u32 period
1259) 1392)
1260{ 1393{
1261 uframe %= period; 1394 unsigned usecs;
1262 do { 1395
1263 /* can't commit more than uframe_periodic_max usec */ 1396 /* convert "usecs we need" to "max already claimed" */
1264 if (periodic_usecs (ehci, uframe >> 3, uframe & 0x7) 1397 usecs = ehci->uframe_periodic_max - stream->ps.usecs;
1265 > (ehci->uframe_periodic_max - usecs))
1266 return 0;
1267 1398
1268 /* we know urb->interval is 2^N uframes */ 1399 for (uframe &= stream->ps.bw_uperiod - 1; uframe < EHCI_BANDWIDTH_SIZE;
1269 uframe += period; 1400 uframe += stream->ps.bw_uperiod) {
1270 } while (uframe < mod); 1401 if (ehci->bandwidth[uframe] > usecs)
1402 return 0;
1403 }
1271 return 1; 1404 return 1;
1272} 1405}
1273 1406
1274static inline int 1407static inline int
1275sitd_slot_ok ( 1408sitd_slot_ok (
1276 struct ehci_hcd *ehci, 1409 struct ehci_hcd *ehci,
1277 u32 mod,
1278 struct ehci_iso_stream *stream, 1410 struct ehci_iso_stream *stream,
1279 u32 uframe, 1411 unsigned uframe,
1280 struct ehci_iso_sched *sched, 1412 struct ehci_iso_sched *sched,
1281 u32 period_uframes 1413 struct ehci_tt *tt
1282) 1414)
1283{ 1415{
1284 u32 mask, tmp; 1416 unsigned mask, tmp;
1285 u32 frame, uf; 1417 unsigned frame, uf;
1418
1419 mask = stream->ps.cs_mask << (uframe & 7);
1286 1420
1287 mask = stream->raw_mask << (uframe & 7); 1421 /* for OUT, don't wrap SSPLIT into H-microframe 7 */
1422 if (((stream->ps.cs_mask & 0xff) << (uframe & 7)) >= (1 << 7))
1423 return 0;
1288 1424
1289 /* for IN, don't wrap CSPLIT into the next frame */ 1425 /* for IN, don't wrap CSPLIT into the next frame */
1290 if (mask & ~0xffff) 1426 if (mask & ~0xffff)
1291 return 0; 1427 return 0;
1292 1428
1293 /* check bandwidth */ 1429 /* check bandwidth */
1294 uframe %= period_uframes; 1430 uframe &= stream->ps.bw_uperiod - 1;
1295 frame = uframe >> 3; 1431 frame = uframe >> 3;
1296 1432
1297#ifdef CONFIG_USB_EHCI_TT_NEWSCHED 1433#ifdef CONFIG_USB_EHCI_TT_NEWSCHED
@@ -1299,54 +1435,48 @@ sitd_slot_ok (
1299 * tt_available scheduling guarantees 10+% for control/bulk. 1435 * tt_available scheduling guarantees 10+% for control/bulk.
1300 */ 1436 */
1301 uf = uframe & 7; 1437 uf = uframe & 7;
1302 if (!tt_available(ehci, period_uframes >> 3, 1438 if (!tt_available(ehci, &stream->ps, tt, frame, uf))
1303 stream->udev, frame, uf, stream->tt_usecs))
1304 return 0; 1439 return 0;
1305#else 1440#else
1306 /* tt must be idle for start(s), any gap, and csplit. 1441 /* tt must be idle for start(s), any gap, and csplit.
1307 * assume scheduling slop leaves 10+% for control/bulk. 1442 * assume scheduling slop leaves 10+% for control/bulk.
1308 */ 1443 */
1309 if (!tt_no_collision(ehci, period_uframes >> 3, 1444 if (!tt_no_collision(ehci, stream->ps.bw_period,
1310 stream->udev, frame, mask)) 1445 stream->ps.udev, frame, mask))
1311 return 0; 1446 return 0;
1312#endif 1447#endif
1313 1448
1314 /* this multi-pass logic is simple, but performance may
1315 * suffer when the schedule data isn't cached.
1316 */
1317 do { 1449 do {
1318 u32 max_used; 1450 unsigned max_used;
1319 1451 unsigned i;
1320 frame = uframe >> 3;
1321 uf = uframe & 7;
1322 1452
1323 /* check starts (OUT uses more than one) */ 1453 /* check starts (OUT uses more than one) */
1324 max_used = ehci->uframe_periodic_max - stream->usecs; 1454 uf = uframe;
1325 for (tmp = stream->raw_mask & 0xff; tmp; tmp >>= 1, uf++) { 1455 max_used = ehci->uframe_periodic_max - stream->ps.usecs;
1326 if (periodic_usecs (ehci, frame, uf) > max_used) 1456 for (tmp = stream->ps.cs_mask & 0xff; tmp; tmp >>= 1, uf++) {
1457 if (ehci->bandwidth[uf] > max_used)
1327 return 0; 1458 return 0;
1328 } 1459 }
1329 1460
1330 /* for IN, check CSPLIT */ 1461 /* for IN, check CSPLIT */
1331 if (stream->c_usecs) { 1462 if (stream->ps.c_usecs) {
1332 uf = uframe & 7; 1463 max_used = ehci->uframe_periodic_max -
1333 max_used = ehci->uframe_periodic_max - stream->c_usecs; 1464 stream->ps.c_usecs;
1334 do { 1465 uf = uframe & ~7;
1335 tmp = 1 << uf; 1466 tmp = 1 << (2+8);
1336 tmp <<= 8; 1467 for (i = (uframe & 7) + 2; i < 8; (++i, tmp <<= 1)) {
1337 if ((stream->raw_mask & tmp) == 0) 1468 if ((stream->ps.cs_mask & tmp) == 0)
1338 continue; 1469 continue;
1339 if (periodic_usecs (ehci, frame, uf) 1470 if (ehci->bandwidth[uf+i] > max_used)
1340 > max_used)
1341 return 0; 1471 return 0;
1342 } while (++uf < 8); 1472 }
1343 } 1473 }
1344 1474
1345 /* we know urb->interval is 2^N uframes */ 1475 uframe += stream->ps.bw_uperiod;
1346 uframe += period_uframes; 1476 } while (uframe < EHCI_BANDWIDTH_SIZE);
1347 } while (uframe < mod);
1348 1477
1349 stream->splits = cpu_to_hc32(ehci, stream->raw_mask << (uframe & 7)); 1478 stream->ps.cs_mask <<= uframe & 7;
1479 stream->splits = cpu_to_hc32(ehci, stream->ps.cs_mask);
1350 return 1; 1480 return 1;
1351} 1481}
1352 1482
@@ -1361,8 +1491,6 @@ sitd_slot_ok (
1361 * given EHCI_TUNE_FLS and the slop). Or, write a smarter scheduler! 1491 * given EHCI_TUNE_FLS and the slop). Or, write a smarter scheduler!
1362 */ 1492 */
1363 1493
1364#define SCHEDULING_DELAY 40 /* microframes */
1365
1366static int 1494static int
1367iso_stream_schedule ( 1495iso_stream_schedule (
1368 struct ehci_hcd *ehci, 1496 struct ehci_hcd *ehci,
@@ -1370,134 +1498,184 @@ iso_stream_schedule (
1370 struct ehci_iso_stream *stream 1498 struct ehci_iso_stream *stream
1371) 1499)
1372{ 1500{
1373 u32 now, base, next, start, period, span; 1501 u32 now, base, next, start, period, span, now2;
1374 int status; 1502 u32 wrap = 0, skip = 0;
1503 int status = 0;
1375 unsigned mod = ehci->periodic_size << 3; 1504 unsigned mod = ehci->periodic_size << 3;
1376 struct ehci_iso_sched *sched = urb->hcpriv; 1505 struct ehci_iso_sched *sched = urb->hcpriv;
1506 bool empty = list_empty(&stream->td_list);
1507 bool new_stream = false;
1377 1508
1378 period = urb->interval; 1509 period = stream->uperiod;
1379 span = sched->span; 1510 span = sched->span;
1380 if (!stream->highspeed) { 1511 if (!stream->highspeed)
1381 period <<= 3;
1382 span <<= 3; 1512 span <<= 3;
1383 }
1384 1513
1385 now = ehci_read_frame_index(ehci) & (mod - 1); 1514 /* Start a new isochronous stream? */
1515 if (unlikely(empty && !hcd_periodic_completion_in_progress(
1516 ehci_to_hcd(ehci), urb->ep))) {
1386 1517
1387 /* Typical case: reuse current schedule, stream is still active. 1518 /* Schedule the endpoint */
1388 * Hopefully there are no gaps from the host falling behind 1519 if (stream->ps.phase == NO_FRAME) {
1389 * (irq delays etc). If there are, the behavior depends on 1520 int done = 0;
1390 * whether URB_ISO_ASAP is set. 1521 struct ehci_tt *tt = find_tt(stream->ps.udev);
1391 */
1392 if (likely (!list_empty (&stream->td_list))) {
1393 1522
1394 /* Take the isochronous scheduling threshold into account */ 1523 if (IS_ERR(tt)) {
1395 if (ehci->i_thresh) 1524 status = PTR_ERR(tt);
1396 next = now + ehci->i_thresh; /* uframe cache */ 1525 goto fail;
1397 else 1526 }
1398 next = (now + 2 + 7) & ~0x07; /* full frame cache */ 1527 compute_tt_budget(ehci->tt_budget, tt);
1399
1400 /*
1401 * Use ehci->last_iso_frame as the base. There can't be any
1402 * TDs scheduled for earlier than that.
1403 */
1404 base = ehci->last_iso_frame << 3;
1405 next = (next - base) & (mod - 1);
1406 start = (stream->next_uframe - base) & (mod - 1);
1407
1408 /* Is the schedule already full? */
1409 if (unlikely(start < period)) {
1410 ehci_dbg(ehci, "iso sched full %p (%u-%u < %u mod %u)\n",
1411 urb, stream->next_uframe, base,
1412 period, mod);
1413 status = -ENOSPC;
1414 goto fail;
1415 }
1416
1417 /* Behind the scheduling threshold? */
1418 if (unlikely(start < next)) {
1419 unsigned now2 = (now - base) & (mod - 1);
1420 1528
1421 /* USB_ISO_ASAP: Round up to the first available slot */ 1529 start = ((-(++ehci->random_frame)) << 3) & (period - 1);
1422 if (urb->transfer_flags & URB_ISO_ASAP)
1423 start += (next - start + period - 1) & -period;
1424 1530
1425 /* 1531 /* find a uframe slot with enough bandwidth.
1426 * Not ASAP: Use the next slot in the stream, 1532 * Early uframes are more precious because full-speed
1427 * no matter what. 1533 * iso IN transfers can't use late uframes,
1534 * and therefore they should be allocated last.
1428 */ 1535 */
1429 else if (start + span - period < now2) { 1536 next = start;
1430 ehci_dbg(ehci, "iso underrun %p (%u+%u < %u)\n", 1537 start += period;
1431 urb, start + base, 1538 do {
1432 span - period, now2 + base); 1539 start--;
1540 /* check schedule: enough space? */
1541 if (stream->highspeed) {
1542 if (itd_slot_ok(ehci, stream, start))
1543 done = 1;
1544 } else {
1545 if ((start % 8) >= 6)
1546 continue;
1547 if (sitd_slot_ok(ehci, stream, start,
1548 sched, tt))
1549 done = 1;
1550 }
1551 } while (start > next && !done);
1552
1553 /* no room in the schedule */
1554 if (!done) {
1555 ehci_dbg(ehci, "iso sched full %p", urb);
1556 status = -ENOSPC;
1557 goto fail;
1433 } 1558 }
1559 stream->ps.phase = (start >> 3) &
1560 (stream->ps.period - 1);
1561 stream->ps.bw_phase = stream->ps.phase &
1562 (stream->ps.bw_period - 1);
1563 stream->ps.phase_uf = start & 7;
1564 reserve_release_iso_bandwidth(ehci, stream, 1);
1565 }
1566
1567 /* New stream is already scheduled; use the upcoming slot */
1568 else {
1569 start = (stream->ps.phase << 3) + stream->ps.phase_uf;
1434 } 1570 }
1435 1571
1436 start += base; 1572 stream->next_uframe = start;
1573 new_stream = true;
1437 } 1574 }
1438 1575
1439 /* need to schedule; when's the next (u)frame we could start? 1576 now = ehci_read_frame_index(ehci) & (mod - 1);
1440 * this is bigger than ehci->i_thresh allows; scheduling itself 1577
1441 * isn't free, the delay should handle reasonably slow cpus. it 1578 /* Take the isochronous scheduling threshold into account */
1442 * can also help high bandwidth if the dma and irq loads don't 1579 if (ehci->i_thresh)
1443 * jump until after the queue is primed. 1580 next = now + ehci->i_thresh; /* uframe cache */
1581 else
1582 next = (now + 2 + 7) & ~0x07; /* full frame cache */
1583
1584 /*
1585 * Use ehci->last_iso_frame as the base. There can't be any
1586 * TDs scheduled for earlier than that.
1444 */ 1587 */
1445 else { 1588 base = ehci->last_iso_frame << 3;
1446 int done = 0; 1589 next = (next - base) & (mod - 1);
1590 start = (stream->next_uframe - base) & (mod - 1);
1447 1591
1448 base = now & ~0x07; 1592 if (unlikely(new_stream))
1449 start = base + SCHEDULING_DELAY; 1593 goto do_ASAP;
1450 1594
1451 /* find a uframe slot with enough bandwidth. 1595 /*
1452 * Early uframes are more precious because full-speed 1596 * Typical case: reuse current schedule, stream may still be active.
1453 * iso IN transfers can't use late uframes, 1597 * Hopefully there are no gaps from the host falling behind
1454 * and therefore they should be allocated last. 1598 * (irq delays etc). If there are, the behavior depends on
1455 */ 1599 * whether URB_ISO_ASAP is set.
1456 next = start; 1600 */
1457 start += period; 1601 now2 = (now - base) & (mod - 1);
1458 do { 1602
1459 start--; 1603 /* Is the schedule already full? */
1460 /* check schedule: enough space? */ 1604 if (unlikely(!empty && start < period)) {
1461 if (stream->highspeed) { 1605 ehci_dbg(ehci, "iso sched full %p (%u-%u < %u mod %u)\n",
1462 if (itd_slot_ok(ehci, mod, start, 1606 urb, stream->next_uframe, base, period, mod);
1463 stream->usecs, period)) 1607 status = -ENOSPC;
1464 done = 1; 1608 goto fail;
1465 } else { 1609 }
1466 if ((start % 8) >= 6) 1610
1467 continue; 1611 /* Is the next packet scheduled after the base time? */
1468 if (sitd_slot_ok(ehci, mod, stream, 1612 if (likely(!empty || start <= now2 + period)) {
1469 start, sched, period)) 1613
1470 done = 1; 1614 /* URB_ISO_ASAP: make sure that start >= next */
1471 } 1615 if (unlikely(start < next &&
1472 } while (start > next && !done); 1616 (urb->transfer_flags & URB_ISO_ASAP)))
1617 goto do_ASAP;
1618
1619 /* Otherwise use start, if it's not in the past */
1620 if (likely(start >= now2))
1621 goto use_start;
1473 1622
1474 /* no room in the schedule */ 1623 /* Otherwise we got an underrun while the queue was empty */
1475 if (!done) { 1624 } else {
1476 ehci_dbg(ehci, "iso sched full %p", urb); 1625 if (urb->transfer_flags & URB_ISO_ASAP)
1477 status = -ENOSPC; 1626 goto do_ASAP;
1478 goto fail; 1627 wrap = mod;
1628 now2 += mod;
1629 }
1630
1631 /* How many uframes and packets do we need to skip? */
1632 skip = (now2 - start + period - 1) & -period;
1633 if (skip >= span) { /* Entirely in the past? */
1634 ehci_dbg(ehci, "iso underrun %p (%u+%u < %u) [%u]\n",
1635 urb, start + base, span - period, now2 + base,
1636 base);
1637
1638 /* Try to keep the last TD intact for scanning later */
1639 skip = span - period;
1640
1641 /* Will it come before the current scan position? */
1642 if (empty) {
1643 skip = span; /* Skip the entire URB */
1644 status = 1; /* and give it back immediately */
1645 iso_sched_free(stream, sched);
1646 sched = NULL;
1479 } 1647 }
1480 } 1648 }
1649 urb->error_count = skip / period;
1650 if (sched)
1651 sched->first_packet = urb->error_count;
1652 goto use_start;
1481 1653
1654 do_ASAP:
1655 /* Use the first slot after "next" */
1656 start = next + ((start - next) & (period - 1));
1657
1658 use_start:
1482 /* Tried to schedule too far into the future? */ 1659 /* Tried to schedule too far into the future? */
1483 if (unlikely(start - base + span - period >= mod)) { 1660 if (unlikely(start + span - period >= mod + wrap)) {
1484 ehci_dbg(ehci, "request %p would overflow (%u+%u >= %u)\n", 1661 ehci_dbg(ehci, "request %p would overflow (%u+%u >= %u)\n",
1485 urb, start - base, span - period, mod); 1662 urb, start, span - period, mod + wrap);
1486 status = -EFBIG; 1663 status = -EFBIG;
1487 goto fail; 1664 goto fail;
1488 } 1665 }
1489 1666
1490 stream->next_uframe = start & (mod - 1); 1667 start += base;
1668 stream->next_uframe = (start + skip) & (mod - 1);
1491 1669
1492 /* report high speed start in uframes; full speed, in frames */ 1670 /* report high speed start in uframes; full speed, in frames */
1493 urb->start_frame = stream->next_uframe; 1671 urb->start_frame = start & (mod - 1);
1494 if (!stream->highspeed) 1672 if (!stream->highspeed)
1495 urb->start_frame >>= 3; 1673 urb->start_frame >>= 3;
1496 1674
1497 /* Make sure scan_isoc() sees these */ 1675 /* Make sure scan_isoc() sees these */
1498 if (ehci->isoc_count == 0) 1676 if (ehci->isoc_count == 0)
1499 ehci->last_iso_frame = now >> 3; 1677 ehci->last_iso_frame = now >> 3;
1500 return 0; 1678 return status;
1501 1679
1502 fail: 1680 fail:
1503 iso_sched_free(stream, sched); 1681 iso_sched_free(stream, sched);
@@ -1610,7 +1788,8 @@ static void itd_link_urb(
1610 ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs++; 1788 ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs++;
1611 1789
1612 /* fill iTDs uframe by uframe */ 1790 /* fill iTDs uframe by uframe */
1613 for (packet = 0, itd = NULL; packet < urb->number_of_packets; ) { 1791 for (packet = iso_sched->first_packet, itd = NULL;
1792 packet < urb->number_of_packets;) {
1614 if (itd == NULL) { 1793 if (itd == NULL) {
1615 /* ASSERT: we have all necessary itds */ 1794 /* ASSERT: we have all necessary itds */
1616 // BUG_ON (list_empty (&iso_sched->td_list)); 1795 // BUG_ON (list_empty (&iso_sched->td_list));
@@ -1630,7 +1809,7 @@ static void itd_link_urb(
1630 1809
1631 itd_patch(ehci, itd, iso_sched, packet, uframe); 1810 itd_patch(ehci, itd, iso_sched, packet, uframe);
1632 1811
1633 next_uframe += stream->interval; 1812 next_uframe += stream->uperiod;
1634 next_uframe &= mod - 1; 1813 next_uframe &= mod - 1;
1635 packet++; 1814 packet++;
1636 1815
@@ -1770,9 +1949,9 @@ static int itd_submit (struct ehci_hcd *ehci, struct urb *urb,
1770 ehci_dbg (ehci, "can't get iso stream\n"); 1949 ehci_dbg (ehci, "can't get iso stream\n");
1771 return -ENOMEM; 1950 return -ENOMEM;
1772 } 1951 }
1773 if (unlikely (urb->interval != stream->interval)) { 1952 if (unlikely(urb->interval != stream->uperiod)) {
1774 ehci_dbg (ehci, "can't change iso interval %d --> %d\n", 1953 ehci_dbg (ehci, "can't change iso interval %d --> %d\n",
1775 stream->interval, urb->interval); 1954 stream->uperiod, urb->interval);
1776 goto done; 1955 goto done;
1777 } 1956 }
1778 1957
@@ -1804,10 +1983,14 @@ static int itd_submit (struct ehci_hcd *ehci, struct urb *urb,
1804 if (unlikely(status)) 1983 if (unlikely(status))
1805 goto done_not_linked; 1984 goto done_not_linked;
1806 status = iso_stream_schedule(ehci, urb, stream); 1985 status = iso_stream_schedule(ehci, urb, stream);
1807 if (likely (status == 0)) 1986 if (likely(status == 0)) {
1808 itd_link_urb (ehci, urb, ehci->periodic_size << 3, stream); 1987 itd_link_urb (ehci, urb, ehci->periodic_size << 3, stream);
1809 else 1988 } else if (status > 0) {
1989 status = 0;
1990 ehci_urb_done(ehci, urb, 0);
1991 } else {
1810 usb_hcd_unlink_urb_from_ep(ehci_to_hcd(ehci), urb); 1992 usb_hcd_unlink_urb_from_ep(ehci_to_hcd(ehci), urb);
1993 }
1811 done_not_linked: 1994 done_not_linked:
1812 spin_unlock_irqrestore (&ehci->lock, flags); 1995 spin_unlock_irqrestore (&ehci->lock, flags);
1813 done: 1996 done:
@@ -1833,7 +2016,7 @@ sitd_sched_init(
1833 dma_addr_t dma = urb->transfer_dma; 2016 dma_addr_t dma = urb->transfer_dma;
1834 2017
1835 /* how many frames are needed for these transfers */ 2018 /* how many frames are needed for these transfers */
1836 iso_sched->span = urb->number_of_packets * stream->interval; 2019 iso_sched->span = urb->number_of_packets * stream->ps.period;
1837 2020
1838 /* figure out per-frame sitd fields that we'll need later 2021 /* figure out per-frame sitd fields that we'll need later
1839 * when we fit new sitds into the schedule. 2022 * when we fit new sitds into the schedule.
@@ -1925,7 +2108,7 @@ sitd_urb_transaction (
1925 2108
1926 memset (sitd, 0, sizeof *sitd); 2109 memset (sitd, 0, sizeof *sitd);
1927 sitd->sitd_dma = sitd_dma; 2110 sitd->sitd_dma = sitd_dma;
1928 sitd->frame = 9999; /* an invalid value */ 2111 sitd->frame = NO_FRAME;
1929 list_add (&sitd->sitd_list, &iso_sched->td_list); 2112 list_add (&sitd->sitd_list, &iso_sched->td_list);
1930 } 2113 }
1931 2114
@@ -2008,7 +2191,7 @@ static void sitd_link_urb(
2008 ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs++; 2191 ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs++;
2009 2192
2010 /* fill sITDs frame by frame */ 2193 /* fill sITDs frame by frame */
2011 for (packet = 0, sitd = NULL; 2194 for (packet = sched->first_packet, sitd = NULL;
2012 packet < urb->number_of_packets; 2195 packet < urb->number_of_packets;
2013 packet++) { 2196 packet++) {
2014 2197
@@ -2027,7 +2210,7 @@ static void sitd_link_urb(
2027 sitd_link(ehci, (next_uframe >> 3) & (ehci->periodic_size - 1), 2210 sitd_link(ehci, (next_uframe >> 3) & (ehci->periodic_size - 1),
2028 sitd); 2211 sitd);
2029 2212
2030 next_uframe += stream->interval << 3; 2213 next_uframe += stream->uperiod;
2031 } 2214 }
2032 stream->next_uframe = next_uframe & (mod - 1); 2215 stream->next_uframe = next_uframe & (mod - 1);
2033 2216
@@ -2146,9 +2329,9 @@ static int sitd_submit (struct ehci_hcd *ehci, struct urb *urb,
2146 ehci_dbg (ehci, "can't get iso stream\n"); 2329 ehci_dbg (ehci, "can't get iso stream\n");
2147 return -ENOMEM; 2330 return -ENOMEM;
2148 } 2331 }
2149 if (urb->interval != stream->interval) { 2332 if (urb->interval != stream->ps.period) {
2150 ehci_dbg (ehci, "can't change iso interval %d --> %d\n", 2333 ehci_dbg (ehci, "can't change iso interval %d --> %d\n",
2151 stream->interval, urb->interval); 2334 stream->ps.period, urb->interval);
2152 goto done; 2335 goto done;
2153 } 2336 }
2154 2337
@@ -2178,10 +2361,14 @@ static int sitd_submit (struct ehci_hcd *ehci, struct urb *urb,
2178 if (unlikely(status)) 2361 if (unlikely(status))
2179 goto done_not_linked; 2362 goto done_not_linked;
2180 status = iso_stream_schedule(ehci, urb, stream); 2363 status = iso_stream_schedule(ehci, urb, stream);
2181 if (status == 0) 2364 if (likely(status == 0)) {
2182 sitd_link_urb (ehci, urb, ehci->periodic_size << 3, stream); 2365 sitd_link_urb (ehci, urb, ehci->periodic_size << 3, stream);
2183 else 2366 } else if (status > 0) {
2367 status = 0;
2368 ehci_urb_done(ehci, urb, 0);
2369 } else {
2184 usb_hcd_unlink_urb_from_ep(ehci_to_hcd(ehci), urb); 2370 usb_hcd_unlink_urb_from_ep(ehci_to_hcd(ehci), urb);
2371 }
2185 done_not_linked: 2372 done_not_linked:
2186 spin_unlock_irqrestore (&ehci->lock, flags); 2373 spin_unlock_irqrestore (&ehci->lock, flags);
2187 done: 2374 done:
@@ -2259,7 +2446,8 @@ restart:
2259 q.itd->hw_next != EHCI_LIST_END(ehci)) 2446 q.itd->hw_next != EHCI_LIST_END(ehci))
2260 *hw_p = q.itd->hw_next; 2447 *hw_p = q.itd->hw_next;
2261 else 2448 else
2262 *hw_p = ehci->dummy->qh_dma; 2449 *hw_p = cpu_to_hc32(ehci,
2450 ehci->dummy->qh_dma);
2263 type = Q_NEXT_TYPE(ehci, q.itd->hw_next); 2451 type = Q_NEXT_TYPE(ehci, q.itd->hw_next);
2264 wmb(); 2452 wmb();
2265 modified = itd_complete (ehci, q.itd); 2453 modified = itd_complete (ehci, q.itd);
@@ -2294,7 +2482,8 @@ restart:
2294 q.sitd->hw_next != EHCI_LIST_END(ehci)) 2482 q.sitd->hw_next != EHCI_LIST_END(ehci))
2295 *hw_p = q.sitd->hw_next; 2483 *hw_p = q.sitd->hw_next;
2296 else 2484 else
2297 *hw_p = ehci->dummy->qh_dma; 2485 *hw_p = cpu_to_hc32(ehci,
2486 ehci->dummy->qh_dma);
2298 type = Q_NEXT_TYPE(ehci, q.sitd->hw_next); 2487 type = Q_NEXT_TYPE(ehci, q.sitd->hw_next);
2299 wmb(); 2488 wmb();
2300 modified = sitd_complete (ehci, q.sitd); 2489 modified = sitd_complete (ehci, q.sitd);
diff --git a/drivers/usb/host/ehci-sead3.c b/drivers/usb/host/ehci-sead3.c
index b2de52d39614..8a734498079b 100644
--- a/drivers/usb/host/ehci-sead3.c
+++ b/drivers/usb/host/ehci-sead3.c
@@ -55,7 +55,7 @@ const struct hc_driver ehci_sead3_hc_driver = {
55 * generic hardware linkage 55 * generic hardware linkage
56 */ 56 */
57 .irq = ehci_irq, 57 .irq = ehci_irq,
58 .flags = HCD_MEMORY | HCD_USB2, 58 .flags = HCD_MEMORY | HCD_USB2 | HCD_BH,
59 59
60 /* 60 /*
61 * basic lifecycle operations 61 * basic lifecycle operations
diff --git a/drivers/usb/host/ehci-sh.c b/drivers/usb/host/ehci-sh.c
index 93e59a13bc1f..dc899eb2b861 100644
--- a/drivers/usb/host/ehci-sh.c
+++ b/drivers/usb/host/ehci-sh.c
@@ -36,7 +36,7 @@ static const struct hc_driver ehci_sh_hc_driver = {
36 * generic hardware linkage 36 * generic hardware linkage
37 */ 37 */
38 .irq = ehci_irq, 38 .irq = ehci_irq,
39 .flags = HCD_USB2 | HCD_MEMORY, 39 .flags = HCD_USB2 | HCD_MEMORY | HCD_BH,
40 40
41 /* 41 /*
42 * basic lifecycle operations 42 * basic lifecycle operations
diff --git a/drivers/usb/host/ehci-sysfs.c b/drivers/usb/host/ehci-sysfs.c
index 14ced00ba220..f6459dfb6f54 100644
--- a/drivers/usb/host/ehci-sysfs.c
+++ b/drivers/usb/host/ehci-sysfs.c
@@ -97,8 +97,7 @@ static ssize_t store_uframe_periodic_max(struct device *dev,
97{ 97{
98 struct ehci_hcd *ehci; 98 struct ehci_hcd *ehci;
99 unsigned uframe_periodic_max; 99 unsigned uframe_periodic_max;
100 unsigned frame, uframe; 100 unsigned uframe;
101 unsigned short allocated_max;
102 unsigned long flags; 101 unsigned long flags;
103 ssize_t ret; 102 ssize_t ret;
104 103
@@ -122,16 +121,14 @@ static ssize_t store_uframe_periodic_max(struct device *dev,
122 121
123 /* 122 /*
124 * for request to decrease max periodic bandwidth, we have to check 123 * for request to decrease max periodic bandwidth, we have to check
125 * every microframe in the schedule to see whether the decrease is 124 * to see whether the decrease is possible.
126 * possible.
127 */ 125 */
128 if (uframe_periodic_max < ehci->uframe_periodic_max) { 126 if (uframe_periodic_max < ehci->uframe_periodic_max) {
129 allocated_max = 0; 127 u8 allocated_max = 0;
130 128
131 for (frame = 0; frame < ehci->periodic_size; ++frame) 129 for (uframe = 0; uframe < EHCI_BANDWIDTH_SIZE; ++uframe)
132 for (uframe = 0; uframe < 7; ++uframe) 130 allocated_max = max(allocated_max,
133 allocated_max = max(allocated_max, 131 ehci->bandwidth[uframe]);
134 periodic_usecs (ehci, frame, uframe));
135 132
136 if (allocated_max > uframe_periodic_max) { 133 if (allocated_max > uframe_periodic_max) {
137 ehci_info(ehci, 134 ehci_info(ehci,
diff --git a/drivers/usb/host/ehci-tegra.c b/drivers/usb/host/ehci-tegra.c
index 78fa76da3324..e6d8e26e48cc 100644
--- a/drivers/usb/host/ehci-tegra.c
+++ b/drivers/usb/host/ehci-tegra.c
@@ -388,7 +388,7 @@ static int tegra_ehci_probe(struct platform_device *pdev)
388 388
389 err = clk_prepare_enable(tegra->clk); 389 err = clk_prepare_enable(tegra->clk);
390 if (err) 390 if (err)
391 goto cleanup_clk_get; 391 goto cleanup_hcd_create;
392 392
393 tegra_periph_reset_assert(tegra->clk); 393 tegra_periph_reset_assert(tegra->clk);
394 udelay(1); 394 udelay(1);
@@ -465,8 +465,6 @@ cleanup_phy:
465 usb_phy_shutdown(hcd->phy); 465 usb_phy_shutdown(hcd->phy);
466cleanup_clk_en: 466cleanup_clk_en:
467 clk_disable_unprepare(tegra->clk); 467 clk_disable_unprepare(tegra->clk);
468cleanup_clk_get:
469 clk_put(tegra->clk);
470cleanup_hcd_create: 468cleanup_hcd_create:
471 usb_put_hcd(hcd); 469 usb_put_hcd(hcd);
472 return err; 470 return err;
diff --git a/drivers/usb/host/ehci-tilegx.c b/drivers/usb/host/ehci-tilegx.c
index cca4be90a864..67026ffbf9a8 100644
--- a/drivers/usb/host/ehci-tilegx.c
+++ b/drivers/usb/host/ehci-tilegx.c
@@ -61,7 +61,7 @@ static const struct hc_driver ehci_tilegx_hc_driver = {
61 * Generic hardware linkage. 61 * Generic hardware linkage.
62 */ 62 */
63 .irq = ehci_irq, 63 .irq = ehci_irq,
64 .flags = HCD_MEMORY | HCD_USB2, 64 .flags = HCD_MEMORY | HCD_USB2 | HCD_BH,
65 65
66 /* 66 /*
67 * Basic lifecycle operations. 67 * Basic lifecycle operations.
diff --git a/drivers/usb/host/ehci-w90x900.c b/drivers/usb/host/ehci-w90x900.c
index 59e0e24c753f..cdad8438c02b 100644
--- a/drivers/usb/host/ehci-w90x900.c
+++ b/drivers/usb/host/ehci-w90x900.c
@@ -11,13 +11,28 @@
11 * 11 *
12 */ 12 */
13 13
14#include <linux/dma-mapping.h>
15#include <linux/io.h>
16#include <linux/kernel.h>
17#include <linux/module.h>
18#include <linux/of.h>
14#include <linux/platform_device.h> 19#include <linux/platform_device.h>
20#include <linux/usb.h>
21#include <linux/usb/hcd.h>
22
23#include "ehci.h"
15 24
16/* enable phy0 and phy1 for w90p910 */ 25/* enable phy0 and phy1 for w90p910 */
17#define ENPHY (0x01<<8) 26#define ENPHY (0x01<<8)
18#define PHY0_CTR (0xA4) 27#define PHY0_CTR (0xA4)
19#define PHY1_CTR (0xA8) 28#define PHY1_CTR (0xA8)
20 29
30#define DRIVER_DESC "EHCI w90x900 driver"
31
32static const char hcd_name[] = "ehci-w90x900 ";
33
34static struct hc_driver __read_mostly ehci_w90x900_hc_driver;
35
21static int usb_w90x900_probe(const struct hc_driver *driver, 36static int usb_w90x900_probe(const struct hc_driver *driver,
22 struct platform_device *pdev) 37 struct platform_device *pdev)
23{ 38{
@@ -90,8 +105,8 @@ err1:
90 return retval; 105 return retval;
91} 106}
92 107
93static 108static void usb_w90x900_remove(struct usb_hcd *hcd,
94void usb_w90x900_remove(struct usb_hcd *hcd, struct platform_device *pdev) 109 struct platform_device *pdev)
95{ 110{
96 usb_remove_hcd(hcd); 111 usb_remove_hcd(hcd);
97 iounmap(hcd->regs); 112 iounmap(hcd->regs);
@@ -99,54 +114,6 @@ void usb_w90x900_remove(struct usb_hcd *hcd, struct platform_device *pdev)
99 usb_put_hcd(hcd); 114 usb_put_hcd(hcd);
100} 115}
101 116
102static const struct hc_driver ehci_w90x900_hc_driver = {
103 .description = hcd_name,
104 .product_desc = "Nuvoton w90x900 EHCI Host Controller",
105 .hcd_priv_size = sizeof(struct ehci_hcd),
106
107 /*
108 * generic hardware linkage
109 */
110 .irq = ehci_irq,
111 .flags = HCD_USB2|HCD_MEMORY,
112
113 /*
114 * basic lifecycle operations
115 */
116 .reset = ehci_setup,
117 .start = ehci_run,
118
119 .stop = ehci_stop,
120 .shutdown = ehci_shutdown,
121
122 /*
123 * managing i/o requests and associated device resources
124 */
125 .urb_enqueue = ehci_urb_enqueue,
126 .urb_dequeue = ehci_urb_dequeue,
127 .endpoint_disable = ehci_endpoint_disable,
128 .endpoint_reset = ehci_endpoint_reset,
129
130 /*
131 * scheduling support
132 */
133 .get_frame_number = ehci_get_frame,
134
135 /*
136 * root hub support
137 */
138 .hub_status_data = ehci_hub_status_data,
139 .hub_control = ehci_hub_control,
140#ifdef CONFIG_PM
141 .bus_suspend = ehci_bus_suspend,
142 .bus_resume = ehci_bus_resume,
143#endif
144 .relinquish_port = ehci_relinquish_port,
145 .port_handed_over = ehci_port_handed_over,
146
147 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
148};
149
150static int ehci_w90x900_probe(struct platform_device *pdev) 117static int ehci_w90x900_probe(struct platform_device *pdev)
151{ 118{
152 if (usb_disabled()) 119 if (usb_disabled())
@@ -173,7 +140,25 @@ static struct platform_driver ehci_hcd_w90x900_driver = {
173 }, 140 },
174}; 141};
175 142
143static int __init ehci_w90X900_init(void)
144{
145 if (usb_disabled())
146 return -ENODEV;
147
148 pr_info("%s: " DRIVER_DESC "\n", hcd_name);
149
150 ehci_init_driver(&ehci_w90x900_hc_driver, NULL);
151 return platform_driver_register(&ehci_hcd_w90x900_driver);
152}
153module_init(ehci_w90X900_init);
154
155static void __exit ehci_w90X900_cleanup(void)
156{
157 platform_driver_unregister(&ehci_hcd_w90x900_driver);
158}
159module_exit(ehci_w90X900_cleanup);
160
161MODULE_DESCRIPTION(DRIVER_DESC);
176MODULE_AUTHOR("Wan ZongShun <mcuos.com@gmail.com>"); 162MODULE_AUTHOR("Wan ZongShun <mcuos.com@gmail.com>");
177MODULE_DESCRIPTION("w90p910 usb ehci driver!");
178MODULE_LICENSE("GPL");
179MODULE_ALIAS("platform:w90p910-ehci"); 163MODULE_ALIAS("platform:w90p910-ehci");
164MODULE_LICENSE("GPL v2");
diff --git a/drivers/usb/host/ehci-xilinx-of.c b/drivers/usb/host/ehci-xilinx-of.c
index eba962e6ebfb..95979f9f4381 100644
--- a/drivers/usb/host/ehci-xilinx-of.c
+++ b/drivers/usb/host/ehci-xilinx-of.c
@@ -79,7 +79,7 @@ static const struct hc_driver ehci_xilinx_of_hc_driver = {
79 * generic hardware linkage 79 * generic hardware linkage
80 */ 80 */
81 .irq = ehci_irq, 81 .irq = ehci_irq,
82 .flags = HCD_MEMORY | HCD_USB2, 82 .flags = HCD_MEMORY | HCD_USB2 | HCD_BH,
83 83
84 /* 84 /*
85 * basic lifecycle operations 85 * basic lifecycle operations
diff --git a/drivers/usb/host/ehci.h b/drivers/usb/host/ehci.h
index 291db7d09f22..e8f41c5e771b 100644
--- a/drivers/usb/host/ehci.h
+++ b/drivers/usb/host/ehci.h
@@ -54,6 +54,28 @@ struct ehci_stats {
54 unsigned long unlink; 54 unsigned long unlink;
55}; 55};
56 56
57/*
58 * Scheduling and budgeting information for periodic transfers, for both
59 * high-speed devices and full/low-speed devices lying behind a TT.
60 */
61struct ehci_per_sched {
62 struct usb_device *udev; /* access to the TT */
63 struct usb_host_endpoint *ep;
64 struct list_head ps_list; /* node on ehci_tt's ps_list */
65 u16 tt_usecs; /* time on the FS/LS bus */
66 u16 cs_mask; /* C-mask and S-mask bytes */
67 u16 period; /* actual period in frames */
68 u16 phase; /* actual phase, frame part */
69 u8 bw_phase; /* same, for bandwidth
70 reservation */
71 u8 phase_uf; /* uframe part of the phase */
72 u8 usecs, c_usecs; /* times on the HS bus */
73 u8 bw_uperiod; /* period in microframes, for
74 bandwidth reservation */
75 u8 bw_period; /* same, in frames */
76};
77#define NO_FRAME 29999 /* frame not assigned yet */
78
57/* ehci_hcd->lock guards shared data against other CPUs: 79/* ehci_hcd->lock guards shared data against other CPUs:
58 * ehci_hcd: async, unlink, periodic (and shadow), ... 80 * ehci_hcd: async, unlink, periodic (and shadow), ...
59 * usb_host_endpoint: hcpriv 81 * usb_host_endpoint: hcpriv
@@ -230,6 +252,15 @@ struct ehci_hcd { /* one per controller */
230 struct dentry *debug_dir; 252 struct dentry *debug_dir;
231#endif 253#endif
232 254
255 /* bandwidth usage */
256#define EHCI_BANDWIDTH_SIZE 64
257#define EHCI_BANDWIDTH_FRAMES (EHCI_BANDWIDTH_SIZE >> 3)
258 u8 bandwidth[EHCI_BANDWIDTH_SIZE];
259 /* us allocated per uframe */
260 u8 tt_budget[EHCI_BANDWIDTH_SIZE];
261 /* us budgeted per uframe */
262 struct list_head tt_list;
263
233 /* platform-specific data -- must come last */ 264 /* platform-specific data -- must come last */
234 unsigned long priv[0] __aligned(sizeof(s64)); 265 unsigned long priv[0] __aligned(sizeof(s64));
235}; 266};
@@ -385,6 +416,7 @@ struct ehci_qh {
385 struct list_head intr_node; /* list of intr QHs */ 416 struct list_head intr_node; /* list of intr QHs */
386 struct ehci_qtd *dummy; 417 struct ehci_qtd *dummy;
387 struct list_head unlink_node; 418 struct list_head unlink_node;
419 struct ehci_per_sched ps; /* scheduling info */
388 420
389 unsigned unlink_cycle; 421 unsigned unlink_cycle;
390 422
@@ -398,16 +430,8 @@ struct ehci_qh {
398 u8 xacterrs; /* XactErr retry counter */ 430 u8 xacterrs; /* XactErr retry counter */
399#define QH_XACTERR_MAX 32 /* XactErr retry limit */ 431#define QH_XACTERR_MAX 32 /* XactErr retry limit */
400 432
401 /* periodic schedule info */
402 u8 usecs; /* intr bandwidth */
403 u8 gap_uf; /* uframes split/csplit gap */ 433 u8 gap_uf; /* uframes split/csplit gap */
404 u8 c_usecs; /* ... split completion bw */
405 u16 tt_usecs; /* tt downstream bandwidth */
406 unsigned short period; /* polling interval */
407 unsigned short start; /* where polling starts */
408#define NO_FRAME ((unsigned short)~0) /* pick new start */
409 434
410 struct usb_device *dev; /* access to TT */
411 unsigned is_out:1; /* bulk or intr OUT */ 435 unsigned is_out:1; /* bulk or intr OUT */
412 unsigned clearing_tt:1; /* Clear-TT-Buf in progress */ 436 unsigned clearing_tt:1; /* Clear-TT-Buf in progress */
413 unsigned dequeue_during_giveback:1; 437 unsigned dequeue_during_giveback:1;
@@ -434,6 +458,7 @@ struct ehci_iso_packet {
434struct ehci_iso_sched { 458struct ehci_iso_sched {
435 struct list_head td_list; 459 struct list_head td_list;
436 unsigned span; 460 unsigned span;
461 unsigned first_packet;
437 struct ehci_iso_packet packet [0]; 462 struct ehci_iso_packet packet [0];
438}; 463};
439 464
@@ -449,22 +474,17 @@ struct ehci_iso_stream {
449 u8 highspeed; 474 u8 highspeed;
450 struct list_head td_list; /* queued itds/sitds */ 475 struct list_head td_list; /* queued itds/sitds */
451 struct list_head free_list; /* list of unused itds/sitds */ 476 struct list_head free_list; /* list of unused itds/sitds */
452 struct usb_device *udev;
453 struct usb_host_endpoint *ep;
454 477
455 /* output of (re)scheduling */ 478 /* output of (re)scheduling */
456 int next_uframe; 479 struct ehci_per_sched ps; /* scheduling info */
480 unsigned next_uframe;
457 __hc32 splits; 481 __hc32 splits;
458 482
459 /* the rest is derived from the endpoint descriptor, 483 /* the rest is derived from the endpoint descriptor,
460 * trusting urb->interval == f(epdesc->bInterval) and
461 * including the extra info for hw_bufp[0..2] 484 * including the extra info for hw_bufp[0..2]
462 */ 485 */
463 u8 usecs, c_usecs; 486 u16 uperiod; /* period in uframes */
464 u16 interval;
465 u16 tt_usecs;
466 u16 maxp; 487 u16 maxp;
467 u16 raw_mask;
468 unsigned bandwidth; 488 unsigned bandwidth;
469 489
470 /* This is used to initialize iTD's hw_bufp fields */ 490 /* This is used to initialize iTD's hw_bufp fields */
@@ -579,6 +599,35 @@ struct ehci_fstn {
579 599
580/*-------------------------------------------------------------------------*/ 600/*-------------------------------------------------------------------------*/
581 601
602/*
603 * USB-2.0 Specification Sections 11.14 and 11.18
604 * Scheduling and budgeting split transactions using TTs
605 *
606 * A hub can have a single TT for all its ports, or multiple TTs (one for each
607 * port). The bandwidth and budgeting information for the full/low-speed bus
608 * below each TT is self-contained and independent of the other TTs or the
609 * high-speed bus.
610 *
611 * "Bandwidth" refers to the number of microseconds on the FS/LS bus allocated
612 * to an interrupt or isochronous endpoint for each frame. "Budget" refers to
613 * the best-case estimate of the number of full-speed bytes allocated to an
614 * endpoint for each microframe within an allocated frame.
615 *
616 * Removal of an endpoint invalidates a TT's budget. Instead of trying to
617 * keep an up-to-date record, we recompute the budget when it is needed.
618 */
619
620struct ehci_tt {
621 u16 bandwidth[EHCI_BANDWIDTH_FRAMES];
622
623 struct list_head tt_list; /* List of all ehci_tt's */
624 struct list_head ps_list; /* Items using this TT */
625 struct usb_tt *usb_tt;
626 int tt_port; /* TT port number */
627};
628
629/*-------------------------------------------------------------------------*/
630
582/* Prepare the PORTSC wakeup flags during controller suspend/resume */ 631/* Prepare the PORTSC wakeup flags during controller suspend/resume */
583 632
584#define ehci_prepare_ports_for_controller_suspend(ehci, do_wakeup) \ 633#define ehci_prepare_ports_for_controller_suspend(ehci, do_wakeup) \
diff --git a/drivers/usb/host/fotg210-hcd.c b/drivers/usb/host/fotg210-hcd.c
index fce13bcc4a3e..55486bd23cf1 100644
--- a/drivers/usb/host/fotg210-hcd.c
+++ b/drivers/usb/host/fotg210-hcd.c
@@ -412,7 +412,7 @@ struct debug_buffer {
412 tmp = 'h'; break; \ 412 tmp = 'h'; break; \
413 default: \ 413 default: \
414 tmp = '?'; break; \ 414 tmp = '?'; break; \
415 }; tmp; }) 415 } tmp; })
416 416
417static inline char token_mark(struct fotg210_hcd *fotg210, __hc32 token) 417static inline char token_mark(struct fotg210_hcd *fotg210, __hc32 token)
418{ 418{
diff --git a/drivers/usb/host/fusbh200-hcd.c b/drivers/usb/host/fusbh200-hcd.c
index 299253c826c7..e1c6d850a7e1 100644
--- a/drivers/usb/host/fusbh200-hcd.c
+++ b/drivers/usb/host/fusbh200-hcd.c
@@ -402,7 +402,7 @@ struct debug_buffer {
402 case QH_LOW_SPEED: tmp = 'l'; break; \ 402 case QH_LOW_SPEED: tmp = 'l'; break; \
403 case QH_HIGH_SPEED: tmp = 'h'; break; \ 403 case QH_HIGH_SPEED: tmp = 'h'; break; \
404 default: tmp = '?'; break; \ 404 default: tmp = '?'; break; \
405 }; tmp; }) 405 } tmp; })
406 406
407static inline char token_mark(struct fusbh200_hcd *fusbh200, __hc32 token) 407static inline char token_mark(struct fusbh200_hcd *fusbh200, __hc32 token)
408{ 408{
diff --git a/drivers/usb/host/hwa-hc.c b/drivers/usb/host/hwa-hc.c
index 5b86ffb88f1c..ada0a52797b1 100644
--- a/drivers/usb/host/hwa-hc.c
+++ b/drivers/usb/host/hwa-hc.c
@@ -199,10 +199,14 @@ static int hwahc_op_get_frame_number(struct usb_hcd *usb_hcd)
199{ 199{
200 struct wusbhc *wusbhc = usb_hcd_to_wusbhc(usb_hcd); 200 struct wusbhc *wusbhc = usb_hcd_to_wusbhc(usb_hcd);
201 struct hwahc *hwahc = container_of(wusbhc, struct hwahc, wusbhc); 201 struct hwahc *hwahc = container_of(wusbhc, struct hwahc, wusbhc);
202 struct wahc *wa = &hwahc->wa;
202 203
203 dev_err(wusbhc->dev, "%s (%p [%p]) UNIMPLEMENTED\n", __func__, 204 /*
204 usb_hcd, hwahc); 205 * We cannot query the HWA for the WUSB time since that requires sending
205 return -ENOSYS; 206 * a synchronous URB and this function can be called in_interrupt.
207 * Instead, query the USB frame number for our parent and use that.
208 */
209 return usb_get_current_frame_number(wa->usb_dev);
206} 210}
207 211
208static int hwahc_op_urb_enqueue(struct usb_hcd *usb_hcd, struct urb *urb, 212static int hwahc_op_urb_enqueue(struct usb_hcd *usb_hcd, struct urb *urb,
@@ -566,14 +570,10 @@ found:
566 goto error; 570 goto error;
567 } 571 }
568 wa->wa_descr = wa_descr = (struct usb_wa_descriptor *) hdr; 572 wa->wa_descr = wa_descr = (struct usb_wa_descriptor *) hdr;
569 /* Make LE fields CPU order */ 573 if (le16_to_cpu(wa_descr->bcdWAVersion) > 0x0100)
570 wa_descr->bcdWAVersion = le16_to_cpu(wa_descr->bcdWAVersion);
571 wa_descr->wNumRPipes = le16_to_cpu(wa_descr->wNumRPipes);
572 wa_descr->wRPipeMaxBlock = le16_to_cpu(wa_descr->wRPipeMaxBlock);
573 if (wa_descr->bcdWAVersion > 0x0100)
574 dev_warn(dev, "Wire Adapter v%d.%d newer than groked v1.0\n", 574 dev_warn(dev, "Wire Adapter v%d.%d newer than groked v1.0\n",
575 wa_descr->bcdWAVersion & 0xff00 >> 8, 575 le16_to_cpu(wa_descr->bcdWAVersion) & 0xff00 >> 8,
576 wa_descr->bcdWAVersion & 0x00ff); 576 le16_to_cpu(wa_descr->bcdWAVersion) & 0x00ff);
577 result = 0; 577 result = 0;
578error: 578error:
579 return result; 579 return result;
@@ -679,7 +679,8 @@ static void hwahc_security_release(struct hwahc *hwahc)
679 /* nothing to do here so far... */ 679 /* nothing to do here so far... */
680} 680}
681 681
682static int hwahc_create(struct hwahc *hwahc, struct usb_interface *iface) 682static int hwahc_create(struct hwahc *hwahc, struct usb_interface *iface,
683 kernel_ulong_t quirks)
683{ 684{
684 int result; 685 int result;
685 struct device *dev = &iface->dev; 686 struct device *dev = &iface->dev;
@@ -724,7 +725,7 @@ static int hwahc_create(struct hwahc *hwahc, struct usb_interface *iface)
724 dev_err(dev, "Can't create WUSB HC structures: %d\n", result); 725 dev_err(dev, "Can't create WUSB HC structures: %d\n", result);
725 goto error_wusbhc_create; 726 goto error_wusbhc_create;
726 } 727 }
727 result = wa_create(&hwahc->wa, iface); 728 result = wa_create(&hwahc->wa, iface, quirks);
728 if (result < 0) 729 if (result < 0)
729 goto error_wa_create; 730 goto error_wa_create;
730 return 0; 731 return 0;
@@ -780,7 +781,7 @@ static int hwahc_probe(struct usb_interface *usb_iface,
780 wusbhc = usb_hcd_to_wusbhc(usb_hcd); 781 wusbhc = usb_hcd_to_wusbhc(usb_hcd);
781 hwahc = container_of(wusbhc, struct hwahc, wusbhc); 782 hwahc = container_of(wusbhc, struct hwahc, wusbhc);
782 hwahc_init(hwahc); 783 hwahc_init(hwahc);
783 result = hwahc_create(hwahc, usb_iface); 784 result = hwahc_create(hwahc, usb_iface, id->driver_info);
784 if (result < 0) { 785 if (result < 0) {
785 dev_err(dev, "Cannot initialize internals: %d\n", result); 786 dev_err(dev, "Cannot initialize internals: %d\n", result);
786 goto error_hwahc_create; 787 goto error_hwahc_create;
@@ -824,6 +825,12 @@ static void hwahc_disconnect(struct usb_interface *usb_iface)
824} 825}
825 826
826static struct usb_device_id hwahc_id_table[] = { 827static struct usb_device_id hwahc_id_table[] = {
828 /* Alereon 5310 */
829 { USB_DEVICE_AND_INTERFACE_INFO(0x13dc, 0x5310, 0xe0, 0x02, 0x01),
830 .driver_info = WUSB_QUIRK_ALEREON_HWA_CONCAT_ISOC },
831 /* Alereon 5611 */
832 { USB_DEVICE_AND_INTERFACE_INFO(0x13dc, 0x5611, 0xe0, 0x02, 0x01),
833 .driver_info = WUSB_QUIRK_ALEREON_HWA_CONCAT_ISOC },
827 /* FIXME: use class labels for this */ 834 /* FIXME: use class labels for this */
828 { USB_INTERFACE_INFO(0xe0, 0x02, 0x01), }, 835 { USB_INTERFACE_INFO(0xe0, 0x02, 0x01), },
829 {}, 836 {},
diff --git a/drivers/usb/host/isp1362-hcd.c b/drivers/usb/host/isp1362-hcd.c
index 6f29abad6815..935a2dd367a8 100644
--- a/drivers/usb/host/isp1362-hcd.c
+++ b/drivers/usb/host/isp1362-hcd.c
@@ -2108,7 +2108,7 @@ static int isp1362_show(struct seq_file *s, void *unused)
2108 default: 2108 default:
2109 s = "?"; 2109 s = "?";
2110 break; 2110 break;
2111 }; 2111 }
2112 s;}), ep->maxpacket) ; 2112 s;}), ep->maxpacket) ;
2113 list_for_each_entry(urb, &ep->hep->urb_list, urb_list) { 2113 list_for_each_entry(urb, &ep->hep->urb_list, urb_list) {
2114 seq_printf(s, " urb%p, %d/%d\n", urb, 2114 seq_printf(s, " urb%p, %d/%d\n", urb,
diff --git a/drivers/usb/host/ohci-at91.c b/drivers/usb/host/ohci-at91.c
index caa3764a3407..476b5a5baf25 100644
--- a/drivers/usb/host/ohci-at91.c
+++ b/drivers/usb/host/ohci-at91.c
@@ -13,19 +13,24 @@
13 */ 13 */
14 14
15#include <linux/clk.h> 15#include <linux/clk.h>
16#include <linux/platform_device.h> 16#include <linux/dma-mapping.h>
17#include <linux/of_platform.h> 17#include <linux/of_platform.h>
18#include <linux/of_gpio.h> 18#include <linux/of_gpio.h>
19#include <linux/platform_device.h>
19#include <linux/platform_data/atmel.h> 20#include <linux/platform_data/atmel.h>
21#include <linux/io.h>
22#include <linux/kernel.h>
23#include <linux/module.h>
24#include <linux/usb.h>
25#include <linux/usb/hcd.h>
20 26
21#include <mach/hardware.h> 27#include <mach/hardware.h>
22#include <asm/gpio.h> 28#include <asm/gpio.h>
23 29
24#include <mach/cpu.h> 30#include <mach/cpu.h>
25 31
26#ifndef CONFIG_ARCH_AT91 32
27#error "CONFIG_ARCH_AT91 must be defined." 33#include "ohci.h"
28#endif
29 34
30#define valid_port(index) ((index) >= 0 && (index) < AT91_MAX_USBH_PORTS) 35#define valid_port(index) ((index) >= 0 && (index) < AT91_MAX_USBH_PORTS)
31#define at91_for_each_port(index) \ 36#define at91_for_each_port(index) \
@@ -33,7 +38,17 @@
33 38
34/* interface, function and usb clocks; sometimes also an AHB clock */ 39/* interface, function and usb clocks; sometimes also an AHB clock */
35static struct clk *iclk, *fclk, *uclk, *hclk; 40static struct clk *iclk, *fclk, *uclk, *hclk;
41/* interface and function clocks; sometimes also an AHB clock */
42
43#define DRIVER_DESC "OHCI Atmel driver"
44
45static const char hcd_name[] = "ohci-atmel";
46
47static struct hc_driver __read_mostly ohci_at91_hc_driver;
36static int clocked; 48static int clocked;
49static int (*orig_ohci_hub_control)(struct usb_hcd *hcd, u16 typeReq,
50 u16 wValue, u16 wIndex, char *buf, u16 wLength);
51static int (*orig_ohci_hub_status_data)(struct usb_hcd *hcd, char *buf);
37 52
38extern int usb_disabled(void); 53extern int usb_disabled(void);
39 54
@@ -117,6 +132,8 @@ static void usb_hcd_at91_remove (struct usb_hcd *, struct platform_device *);
117static int usb_hcd_at91_probe(const struct hc_driver *driver, 132static int usb_hcd_at91_probe(const struct hc_driver *driver,
118 struct platform_device *pdev) 133 struct platform_device *pdev)
119{ 134{
135 struct at91_usbh_data *board;
136 struct ohci_hcd *ohci;
120 int retval; 137 int retval;
121 struct usb_hcd *hcd = NULL; 138 struct usb_hcd *hcd = NULL;
122 139
@@ -177,8 +194,10 @@ static int usb_hcd_at91_probe(const struct hc_driver *driver,
177 } 194 }
178 } 195 }
179 196
197 board = hcd->self.controller->platform_data;
198 ohci = hcd_to_ohci(hcd);
199 ohci->num_ports = board->ports;
180 at91_start_hc(pdev); 200 at91_start_hc(pdev);
181 ohci_hcd_init(hcd_to_ohci(hcd));
182 201
183 retval = usb_add_hcd(hcd, pdev->resource[1].start, IRQF_SHARED); 202 retval = usb_add_hcd(hcd, pdev->resource[1].start, IRQF_SHARED);
184 if (retval == 0) 203 if (retval == 0)
@@ -238,36 +257,6 @@ static void usb_hcd_at91_remove(struct usb_hcd *hcd,
238} 257}
239 258
240/*-------------------------------------------------------------------------*/ 259/*-------------------------------------------------------------------------*/
241
242static int
243ohci_at91_reset (struct usb_hcd *hcd)
244{
245 struct at91_usbh_data *board = dev_get_platdata(hcd->self.controller);
246 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
247 int ret;
248
249 if ((ret = ohci_init(ohci)) < 0)
250 return ret;
251
252 ohci->num_ports = board->ports;
253 return 0;
254}
255
256static int
257ohci_at91_start (struct usb_hcd *hcd)
258{
259 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
260 int ret;
261
262 if ((ret = ohci_run(ohci)) < 0) {
263 dev_err(hcd->self.controller, "can't start %s\n",
264 hcd->self.bus_name);
265 ohci_stop(hcd);
266 return ret;
267 }
268 return 0;
269}
270
271static void ohci_at91_usb_set_power(struct at91_usbh_data *pdata, int port, int enable) 260static void ohci_at91_usb_set_power(struct at91_usbh_data *pdata, int port, int enable)
272{ 261{
273 if (!valid_port(port)) 262 if (!valid_port(port))
@@ -297,8 +286,8 @@ static int ohci_at91_usb_get_power(struct at91_usbh_data *pdata, int port)
297 */ 286 */
298static int ohci_at91_hub_status_data(struct usb_hcd *hcd, char *buf) 287static int ohci_at91_hub_status_data(struct usb_hcd *hcd, char *buf)
299{ 288{
300 struct at91_usbh_data *pdata = dev_get_platdata(hcd->self.controller); 289 struct at91_usbh_data *pdata = hcd->self.controller->platform_data;
301 int length = ohci_hub_status_data(hcd, buf); 290 int length = orig_ohci_hub_status_data(hcd, buf);
302 int port; 291 int port;
303 292
304 at91_for_each_port(port) { 293 at91_for_each_port(port) {
@@ -376,7 +365,8 @@ static int ohci_at91_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
376 break; 365 break;
377 } 366 }
378 367
379 ret = ohci_hub_control(hcd, typeReq, wValue, wIndex + 1, buf, wLength); 368 ret = orig_ohci_hub_control(hcd, typeReq, wValue, wIndex + 1,
369 buf, wLength);
380 if (ret) 370 if (ret)
381 goto out; 371 goto out;
382 372
@@ -430,51 +420,6 @@ static int ohci_at91_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
430 420
431/*-------------------------------------------------------------------------*/ 421/*-------------------------------------------------------------------------*/
432 422
433static const struct hc_driver ohci_at91_hc_driver = {
434 .description = hcd_name,
435 .product_desc = "AT91 OHCI",
436 .hcd_priv_size = sizeof(struct ohci_hcd),
437
438 /*
439 * generic hardware linkage
440 */
441 .irq = ohci_irq,
442 .flags = HCD_USB11 | HCD_MEMORY,
443
444 /*
445 * basic lifecycle operations
446 */
447 .reset = ohci_at91_reset,
448 .start = ohci_at91_start,
449 .stop = ohci_stop,
450 .shutdown = ohci_shutdown,
451
452 /*
453 * managing i/o requests and associated device resources
454 */
455 .urb_enqueue = ohci_urb_enqueue,
456 .urb_dequeue = ohci_urb_dequeue,
457 .endpoint_disable = ohci_endpoint_disable,
458
459 /*
460 * scheduling support
461 */
462 .get_frame_number = ohci_get_frame,
463
464 /*
465 * root hub support
466 */
467 .hub_status_data = ohci_at91_hub_status_data,
468 .hub_control = ohci_at91_hub_control,
469#ifdef CONFIG_PM
470 .bus_suspend = ohci_bus_suspend,
471 .bus_resume = ohci_bus_resume,
472#endif
473 .start_port_reset = ohci_start_port_reset,
474};
475
476/*-------------------------------------------------------------------------*/
477
478static irqreturn_t ohci_hcd_at91_overcurrent_irq(int irq, void *data) 423static irqreturn_t ohci_hcd_at91_overcurrent_irq(int irq, void *data)
479{ 424{
480 struct platform_device *pdev = data; 425 struct platform_device *pdev = data;
@@ -703,7 +648,11 @@ ohci_hcd_at91_drv_suspend(struct platform_device *pdev, pm_message_t mesg)
703 * REVISIT: some boards will be able to turn VBUS off... 648 * REVISIT: some boards will be able to turn VBUS off...
704 */ 649 */
705 if (at91_suspend_entering_slow_clock()) { 650 if (at91_suspend_entering_slow_clock()) {
706 ohci_usb_reset (ohci); 651 ohci->hc_control = ohci_readl(ohci, &ohci->regs->control);
652 ohci->hc_control &= OHCI_CTRL_RWC;
653 ohci_writel(ohci, ohci->hc_control, &ohci->regs->control);
654 ohci->rh_state = OHCI_RH_HALTED;
655
707 /* flush the writes */ 656 /* flush the writes */
708 (void) ohci_readl (ohci, &ohci->regs->control); 657 (void) ohci_readl (ohci, &ohci->regs->control);
709 at91_stop_clock(); 658 at91_stop_clock();
@@ -730,8 +679,6 @@ static int ohci_hcd_at91_drv_resume(struct platform_device *pdev)
730#define ohci_hcd_at91_drv_resume NULL 679#define ohci_hcd_at91_drv_resume NULL
731#endif 680#endif
732 681
733MODULE_ALIAS("platform:at91_ohci");
734
735static struct platform_driver ohci_hcd_at91_driver = { 682static struct platform_driver ohci_hcd_at91_driver = {
736 .probe = ohci_hcd_at91_drv_probe, 683 .probe = ohci_hcd_at91_drv_probe,
737 .remove = ohci_hcd_at91_drv_remove, 684 .remove = ohci_hcd_at91_drv_remove,
@@ -744,3 +691,40 @@ static struct platform_driver ohci_hcd_at91_driver = {
744 .of_match_table = of_match_ptr(at91_ohci_dt_ids), 691 .of_match_table = of_match_ptr(at91_ohci_dt_ids),
745 }, 692 },
746}; 693};
694
695static int __init ohci_at91_init(void)
696{
697 if (usb_disabled())
698 return -ENODEV;
699
700 pr_info("%s: " DRIVER_DESC "\n", hcd_name);
701 ohci_init_driver(&ohci_at91_hc_driver, NULL);
702
703 /*
704 * The Atmel HW has some unusual quirks, which require Atmel-specific
705 * workarounds. We override certain hc_driver functions here to
706 * achieve that. We explicitly do not enhance ohci_driver_overrides to
707 * allow this more easily, since this is an unusual case, and we don't
708 * want to encourage others to override these functions by making it
709 * too easy.
710 */
711
712 orig_ohci_hub_control = ohci_at91_hc_driver.hub_control;
713 orig_ohci_hub_status_data = ohci_at91_hc_driver.hub_status_data;
714
715 ohci_at91_hc_driver.hub_status_data = ohci_at91_hub_status_data;
716 ohci_at91_hc_driver.hub_control = ohci_at91_hub_control;
717
718 return platform_driver_register(&ohci_hcd_at91_driver);
719}
720module_init(ohci_at91_init);
721
722static void __exit ohci_at91_cleanup(void)
723{
724 platform_driver_unregister(&ohci_hcd_at91_driver);
725}
726module_exit(ohci_at91_cleanup);
727
728MODULE_DESCRIPTION(DRIVER_DESC);
729MODULE_LICENSE("GPL");
730MODULE_ALIAS("platform:at91_ohci");
diff --git a/drivers/usb/host/ohci-dbg.c b/drivers/usb/host/ohci-dbg.c
index 31b81f9eacdc..3fca52ec02ac 100644
--- a/drivers/usb/host/ohci-dbg.c
+++ b/drivers/usb/host/ohci-dbg.c
@@ -17,7 +17,7 @@
17 case PIPE_BULK: temp = "bulk"; break; \ 17 case PIPE_BULK: temp = "bulk"; break; \
18 case PIPE_INTERRUPT: temp = "intr"; break; \ 18 case PIPE_INTERRUPT: temp = "intr"; break; \
19 default: temp = "isoc"; break; \ 19 default: temp = "isoc"; break; \
20 }; temp;}) 20 } temp;})
21#define pipestring(pipe) edstring(usb_pipetype(pipe)) 21#define pipestring(pipe) edstring(usb_pipetype(pipe))
22 22
23/* debug| print the main components of an URB 23/* debug| print the main components of an URB
diff --git a/drivers/usb/host/ohci-ep93xx.c b/drivers/usb/host/ohci-ep93xx.c
deleted file mode 100644
index 84a20d5223b9..000000000000
--- a/drivers/usb/host/ohci-ep93xx.c
+++ /dev/null
@@ -1,184 +0,0 @@
1/*
2 * OHCI HCD (Host Controller Driver) for USB.
3 *
4 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
5 * (C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net>
6 * (C) Copyright 2002 Hewlett-Packard Company
7 *
8 * Bus Glue for ep93xx.
9 *
10 * Written by Christopher Hoover <ch@hpl.hp.com>
11 * Based on fragments of previous driver by Russell King et al.
12 *
13 * Modified for LH7A404 from ohci-sa1111.c
14 * by Durgesh Pattamatta <pattamattad@sharpsec.com>
15 *
16 * Modified for pxa27x from ohci-lh7a404.c
17 * by Nick Bane <nick@cecomputing.co.uk> 26-8-2004
18 *
19 * Modified for ep93xx from ohci-pxa27x.c
20 * by Lennert Buytenhek <buytenh@wantstofly.org> 28-2-2006
21 * Based on an earlier driver by Ray Lehtiniemi
22 *
23 * This file is licenced under the GPL.
24 */
25
26#include <linux/clk.h>
27#include <linux/device.h>
28#include <linux/signal.h>
29#include <linux/platform_device.h>
30
31static struct clk *usb_host_clock;
32
33static int ohci_ep93xx_start(struct usb_hcd *hcd)
34{
35 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
36 int ret;
37
38 if ((ret = ohci_init(ohci)) < 0)
39 return ret;
40
41 if ((ret = ohci_run(ohci)) < 0) {
42 dev_err(hcd->self.controller, "can't start %s\n",
43 hcd->self.bus_name);
44 ohci_stop(hcd);
45 return ret;
46 }
47
48 return 0;
49}
50
51static struct hc_driver ohci_ep93xx_hc_driver = {
52 .description = hcd_name,
53 .product_desc = "EP93xx OHCI",
54 .hcd_priv_size = sizeof(struct ohci_hcd),
55 .irq = ohci_irq,
56 .flags = HCD_USB11 | HCD_MEMORY,
57 .start = ohci_ep93xx_start,
58 .stop = ohci_stop,
59 .shutdown = ohci_shutdown,
60 .urb_enqueue = ohci_urb_enqueue,
61 .urb_dequeue = ohci_urb_dequeue,
62 .endpoint_disable = ohci_endpoint_disable,
63 .get_frame_number = ohci_get_frame,
64 .hub_status_data = ohci_hub_status_data,
65 .hub_control = ohci_hub_control,
66#ifdef CONFIG_PM
67 .bus_suspend = ohci_bus_suspend,
68 .bus_resume = ohci_bus_resume,
69#endif
70 .start_port_reset = ohci_start_port_reset,
71};
72
73static int ohci_hcd_ep93xx_drv_probe(struct platform_device *pdev)
74{
75 struct usb_hcd *hcd;
76 struct resource *res;
77 int irq;
78 int ret;
79
80 if (usb_disabled())
81 return -ENODEV;
82
83 irq = platform_get_irq(pdev, 0);
84 if (irq < 0)
85 return irq;
86
87 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
88 if (!res)
89 return -ENXIO;
90
91 hcd = usb_create_hcd(&ohci_ep93xx_hc_driver, &pdev->dev, "ep93xx");
92 if (!hcd)
93 return -ENOMEM;
94
95 hcd->rsrc_start = res->start;
96 hcd->rsrc_len = resource_size(res);
97
98 hcd->regs = devm_ioremap_resource(&pdev->dev, res);
99 if (IS_ERR(hcd->regs)) {
100 ret = PTR_ERR(hcd->regs);
101 goto err_put_hcd;
102 }
103
104 usb_host_clock = devm_clk_get(&pdev->dev, NULL);
105 if (IS_ERR(usb_host_clock)) {
106 ret = PTR_ERR(usb_host_clock);
107 goto err_put_hcd;
108 }
109
110 clk_enable(usb_host_clock);
111
112 ohci_hcd_init(hcd_to_ohci(hcd));
113
114 ret = usb_add_hcd(hcd, irq, 0);
115 if (ret)
116 goto err_clk_disable;
117
118 return 0;
119
120err_clk_disable:
121 clk_disable(usb_host_clock);
122err_put_hcd:
123 usb_put_hcd(hcd);
124
125 return ret;
126}
127
128static int ohci_hcd_ep93xx_drv_remove(struct platform_device *pdev)
129{
130 struct usb_hcd *hcd = platform_get_drvdata(pdev);
131
132 usb_remove_hcd(hcd);
133 clk_disable(usb_host_clock);
134 usb_put_hcd(hcd);
135
136 return 0;
137}
138
139#ifdef CONFIG_PM
140static int ohci_hcd_ep93xx_drv_suspend(struct platform_device *pdev, pm_message_t state)
141{
142 struct usb_hcd *hcd = platform_get_drvdata(pdev);
143 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
144
145 if (time_before(jiffies, ohci->next_statechange))
146 msleep(5);
147 ohci->next_statechange = jiffies;
148
149 clk_disable(usb_host_clock);
150 return 0;
151}
152
153static int ohci_hcd_ep93xx_drv_resume(struct platform_device *pdev)
154{
155 struct usb_hcd *hcd = platform_get_drvdata(pdev);
156 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
157
158 if (time_before(jiffies, ohci->next_statechange))
159 msleep(5);
160 ohci->next_statechange = jiffies;
161
162 clk_enable(usb_host_clock);
163
164 ohci_resume(hcd, false);
165 return 0;
166}
167#endif
168
169
170static struct platform_driver ohci_hcd_ep93xx_driver = {
171 .probe = ohci_hcd_ep93xx_drv_probe,
172 .remove = ohci_hcd_ep93xx_drv_remove,
173 .shutdown = usb_hcd_platform_shutdown,
174#ifdef CONFIG_PM
175 .suspend = ohci_hcd_ep93xx_drv_suspend,
176 .resume = ohci_hcd_ep93xx_drv_resume,
177#endif
178 .driver = {
179 .name = "ep93xx-ohci",
180 .owner = THIS_MODULE,
181 },
182};
183
184MODULE_ALIAS("platform:ep93xx-ohci");
diff --git a/drivers/usb/host/ohci-exynos.c b/drivers/usb/host/ohci-exynos.c
index dc6ee9adacf5..a87baedc0aa7 100644
--- a/drivers/usb/host/ohci-exynos.c
+++ b/drivers/usb/host/ohci-exynos.c
@@ -12,98 +12,55 @@
12 */ 12 */
13 13
14#include <linux/clk.h> 14#include <linux/clk.h>
15#include <linux/dma-mapping.h>
16#include <linux/io.h>
17#include <linux/kernel.h>
18#include <linux/module.h>
15#include <linux/of.h> 19#include <linux/of.h>
16#include <linux/platform_device.h> 20#include <linux/platform_device.h>
17#include <linux/platform_data/usb-ohci-exynos.h>
18#include <linux/usb/phy.h> 21#include <linux/usb/phy.h>
19#include <linux/usb/samsung_usb_phy.h> 22#include <linux/usb/samsung_usb_phy.h>
23#include <linux/usb.h>
24#include <linux/usb/hcd.h>
25#include <linux/usb/otg.h>
26
27#include "ohci.h"
28
29#define DRIVER_DESC "OHCI EXYNOS driver"
30
31static const char hcd_name[] = "ohci-exynos";
32static struct hc_driver __read_mostly exynos_ohci_hc_driver;
33
34#define to_exynos_ohci(hcd) (struct exynos_ohci_hcd *)(hcd_to_ohci(hcd)->priv)
20 35
21struct exynos_ohci_hcd { 36struct exynos_ohci_hcd {
22 struct device *dev;
23 struct usb_hcd *hcd;
24 struct clk *clk; 37 struct clk *clk;
25 struct usb_phy *phy; 38 struct usb_phy *phy;
26 struct usb_otg *otg; 39 struct usb_otg *otg;
27 struct exynos4_ohci_platdata *pdata;
28}; 40};
29 41
30static void exynos_ohci_phy_enable(struct exynos_ohci_hcd *exynos_ohci) 42static void exynos_ohci_phy_enable(struct platform_device *pdev)
31{ 43{
32 struct platform_device *pdev = to_platform_device(exynos_ohci->dev); 44 struct usb_hcd *hcd = platform_get_drvdata(pdev);
45 struct exynos_ohci_hcd *exynos_ohci = to_exynos_ohci(hcd);
33 46
34 if (exynos_ohci->phy) 47 if (exynos_ohci->phy)
35 usb_phy_init(exynos_ohci->phy); 48 usb_phy_init(exynos_ohci->phy);
36 else if (exynos_ohci->pdata && exynos_ohci->pdata->phy_init)
37 exynos_ohci->pdata->phy_init(pdev, USB_PHY_TYPE_HOST);
38} 49}
39 50
40static void exynos_ohci_phy_disable(struct exynos_ohci_hcd *exynos_ohci) 51static void exynos_ohci_phy_disable(struct platform_device *pdev)
41{ 52{
42 struct platform_device *pdev = to_platform_device(exynos_ohci->dev); 53 struct usb_hcd *hcd = platform_get_drvdata(pdev);
54 struct exynos_ohci_hcd *exynos_ohci = to_exynos_ohci(hcd);
43 55
44 if (exynos_ohci->phy) 56 if (exynos_ohci->phy)
45 usb_phy_shutdown(exynos_ohci->phy); 57 usb_phy_shutdown(exynos_ohci->phy);
46 else if (exynos_ohci->pdata && exynos_ohci->pdata->phy_exit)
47 exynos_ohci->pdata->phy_exit(pdev, USB_PHY_TYPE_HOST);
48}
49
50static int ohci_exynos_reset(struct usb_hcd *hcd)
51{
52 return ohci_init(hcd_to_ohci(hcd));
53} 58}
54 59
55static int ohci_exynos_start(struct usb_hcd *hcd)
56{
57 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
58 int ret;
59
60 ohci_dbg(ohci, "ohci_exynos_start, ohci:%p", ohci);
61
62 ret = ohci_run(ohci);
63 if (ret < 0) {
64 dev_err(hcd->self.controller, "can't start %s\n",
65 hcd->self.bus_name);
66 ohci_stop(hcd);
67 return ret;
68 }
69
70 return 0;
71}
72
73static const struct hc_driver exynos_ohci_hc_driver = {
74 .description = hcd_name,
75 .product_desc = "EXYNOS OHCI Host Controller",
76 .hcd_priv_size = sizeof(struct ohci_hcd),
77
78 .irq = ohci_irq,
79 .flags = HCD_MEMORY|HCD_USB11,
80
81 .reset = ohci_exynos_reset,
82 .start = ohci_exynos_start,
83 .stop = ohci_stop,
84 .shutdown = ohci_shutdown,
85
86 .get_frame_number = ohci_get_frame,
87
88 .urb_enqueue = ohci_urb_enqueue,
89 .urb_dequeue = ohci_urb_dequeue,
90 .endpoint_disable = ohci_endpoint_disable,
91
92 .hub_status_data = ohci_hub_status_data,
93 .hub_control = ohci_hub_control,
94#ifdef CONFIG_PM
95 .bus_suspend = ohci_bus_suspend,
96 .bus_resume = ohci_bus_resume,
97#endif
98 .start_port_reset = ohci_start_port_reset,
99};
100
101static int exynos_ohci_probe(struct platform_device *pdev) 60static int exynos_ohci_probe(struct platform_device *pdev)
102{ 61{
103 struct exynos4_ohci_platdata *pdata = dev_get_platdata(&pdev->dev);
104 struct exynos_ohci_hcd *exynos_ohci; 62 struct exynos_ohci_hcd *exynos_ohci;
105 struct usb_hcd *hcd; 63 struct usb_hcd *hcd;
106 struct ohci_hcd *ohci;
107 struct resource *res; 64 struct resource *res;
108 struct usb_phy *phy; 65 struct usb_phy *phy;
109 int irq; 66 int irq;
@@ -119,10 +76,14 @@ static int exynos_ohci_probe(struct platform_device *pdev)
119 if (!pdev->dev.coherent_dma_mask) 76 if (!pdev->dev.coherent_dma_mask)
120 pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32); 77 pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
121 78
122 exynos_ohci = devm_kzalloc(&pdev->dev, sizeof(struct exynos_ohci_hcd), 79 hcd = usb_create_hcd(&exynos_ohci_hc_driver,
123 GFP_KERNEL); 80 &pdev->dev, dev_name(&pdev->dev));
124 if (!exynos_ohci) 81 if (!hcd) {
82 dev_err(&pdev->dev, "Unable to create HCD\n");
125 return -ENOMEM; 83 return -ENOMEM;
84 }
85
86 exynos_ohci = to_exynos_ohci(hcd);
126 87
127 if (of_device_is_compatible(pdev->dev.of_node, 88 if (of_device_is_compatible(pdev->dev.of_node,
128 "samsung,exynos5440-ohci")) 89 "samsung,exynos5440-ohci"))
@@ -130,30 +91,15 @@ static int exynos_ohci_probe(struct platform_device *pdev)
130 91
131 phy = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2); 92 phy = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2);
132 if (IS_ERR(phy)) { 93 if (IS_ERR(phy)) {
133 /* Fallback to pdata */ 94 usb_put_hcd(hcd);
134 if (!pdata) { 95 dev_warn(&pdev->dev, "no platform data or transceiver defined\n");
135 dev_warn(&pdev->dev, "no platform data or transceiver defined\n"); 96 return -EPROBE_DEFER;
136 return -EPROBE_DEFER;
137 } else {
138 exynos_ohci->pdata = pdata;
139 }
140 } else { 97 } else {
141 exynos_ohci->phy = phy; 98 exynos_ohci->phy = phy;
142 exynos_ohci->otg = phy->otg; 99 exynos_ohci->otg = phy->otg;
143 } 100 }
144 101
145skip_phy: 102skip_phy:
146
147 exynos_ohci->dev = &pdev->dev;
148
149 hcd = usb_create_hcd(&exynos_ohci_hc_driver, &pdev->dev,
150 dev_name(&pdev->dev));
151 if (!hcd) {
152 dev_err(&pdev->dev, "Unable to create HCD\n");
153 return -ENOMEM;
154 }
155
156 exynos_ohci->hcd = hcd;
157 exynos_ohci->clk = devm_clk_get(&pdev->dev, "usbhost"); 103 exynos_ohci->clk = devm_clk_get(&pdev->dev, "usbhost");
158 104
159 if (IS_ERR(exynos_ohci->clk)) { 105 if (IS_ERR(exynos_ohci->clk)) {
@@ -190,26 +136,21 @@ skip_phy:
190 } 136 }
191 137
192 if (exynos_ohci->otg) 138 if (exynos_ohci->otg)
193 exynos_ohci->otg->set_host(exynos_ohci->otg, 139 exynos_ohci->otg->set_host(exynos_ohci->otg, &hcd->self);
194 &exynos_ohci->hcd->self);
195 140
196 exynos_ohci_phy_enable(exynos_ohci); 141 platform_set_drvdata(pdev, hcd);
197 142
198 ohci = hcd_to_ohci(hcd); 143 exynos_ohci_phy_enable(pdev);
199 ohci_hcd_init(ohci);
200 144
201 err = usb_add_hcd(hcd, irq, IRQF_SHARED); 145 err = usb_add_hcd(hcd, irq, IRQF_SHARED);
202 if (err) { 146 if (err) {
203 dev_err(&pdev->dev, "Failed to add USB HCD\n"); 147 dev_err(&pdev->dev, "Failed to add USB HCD\n");
204 goto fail_add_hcd; 148 goto fail_add_hcd;
205 } 149 }
206
207 platform_set_drvdata(pdev, exynos_ohci);
208
209 return 0; 150 return 0;
210 151
211fail_add_hcd: 152fail_add_hcd:
212 exynos_ohci_phy_disable(exynos_ohci); 153 exynos_ohci_phy_disable(pdev);
213fail_io: 154fail_io:
214 clk_disable_unprepare(exynos_ohci->clk); 155 clk_disable_unprepare(exynos_ohci->clk);
215fail_clk: 156fail_clk:
@@ -219,16 +160,15 @@ fail_clk:
219 160
220static int exynos_ohci_remove(struct platform_device *pdev) 161static int exynos_ohci_remove(struct platform_device *pdev)
221{ 162{
222 struct exynos_ohci_hcd *exynos_ohci = platform_get_drvdata(pdev); 163 struct usb_hcd *hcd = platform_get_drvdata(pdev);
223 struct usb_hcd *hcd = exynos_ohci->hcd; 164 struct exynos_ohci_hcd *exynos_ohci = to_exynos_ohci(hcd);
224 165
225 usb_remove_hcd(hcd); 166 usb_remove_hcd(hcd);
226 167
227 if (exynos_ohci->otg) 168 if (exynos_ohci->otg)
228 exynos_ohci->otg->set_host(exynos_ohci->otg, 169 exynos_ohci->otg->set_host(exynos_ohci->otg, &hcd->self);
229 &exynos_ohci->hcd->self);
230 170
231 exynos_ohci_phy_disable(exynos_ohci); 171 exynos_ohci_phy_disable(pdev);
232 172
233 clk_disable_unprepare(exynos_ohci->clk); 173 clk_disable_unprepare(exynos_ohci->clk);
234 174
@@ -239,8 +179,7 @@ static int exynos_ohci_remove(struct platform_device *pdev)
239 179
240static void exynos_ohci_shutdown(struct platform_device *pdev) 180static void exynos_ohci_shutdown(struct platform_device *pdev)
241{ 181{
242 struct exynos_ohci_hcd *exynos_ohci = platform_get_drvdata(pdev); 182 struct usb_hcd *hcd = platform_get_drvdata(pdev);
243 struct usb_hcd *hcd = exynos_ohci->hcd;
244 183
245 if (hcd->driver->shutdown) 184 if (hcd->driver->shutdown)
246 hcd->driver->shutdown(hcd); 185 hcd->driver->shutdown(hcd);
@@ -249,9 +188,10 @@ static void exynos_ohci_shutdown(struct platform_device *pdev)
249#ifdef CONFIG_PM 188#ifdef CONFIG_PM
250static int exynos_ohci_suspend(struct device *dev) 189static int exynos_ohci_suspend(struct device *dev)
251{ 190{
252 struct exynos_ohci_hcd *exynos_ohci = dev_get_drvdata(dev); 191 struct usb_hcd *hcd = dev_get_drvdata(dev);
253 struct usb_hcd *hcd = exynos_ohci->hcd; 192 struct exynos_ohci_hcd *exynos_ohci = to_exynos_ohci(hcd);
254 struct ohci_hcd *ohci = hcd_to_ohci(hcd); 193 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
194 struct platform_device *pdev = to_platform_device(dev);
255 unsigned long flags; 195 unsigned long flags;
256 int rc = 0; 196 int rc = 0;
257 197
@@ -271,10 +211,9 @@ static int exynos_ohci_suspend(struct device *dev)
271 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); 211 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
272 212
273 if (exynos_ohci->otg) 213 if (exynos_ohci->otg)
274 exynos_ohci->otg->set_host(exynos_ohci->otg, 214 exynos_ohci->otg->set_host(exynos_ohci->otg, &hcd->self);
275 &exynos_ohci->hcd->self);
276 215
277 exynos_ohci_phy_disable(exynos_ohci); 216 exynos_ohci_phy_disable(pdev);
278 217
279 clk_disable_unprepare(exynos_ohci->clk); 218 clk_disable_unprepare(exynos_ohci->clk);
280 219
@@ -286,16 +225,16 @@ fail:
286 225
287static int exynos_ohci_resume(struct device *dev) 226static int exynos_ohci_resume(struct device *dev)
288{ 227{
289 struct exynos_ohci_hcd *exynos_ohci = dev_get_drvdata(dev); 228 struct usb_hcd *hcd = dev_get_drvdata(dev);
290 struct usb_hcd *hcd = exynos_ohci->hcd; 229 struct exynos_ohci_hcd *exynos_ohci = to_exynos_ohci(hcd);
230 struct platform_device *pdev = to_platform_device(dev);
291 231
292 clk_prepare_enable(exynos_ohci->clk); 232 clk_prepare_enable(exynos_ohci->clk);
293 233
294 if (exynos_ohci->otg) 234 if (exynos_ohci->otg)
295 exynos_ohci->otg->set_host(exynos_ohci->otg, 235 exynos_ohci->otg->set_host(exynos_ohci->otg, &hcd->self);
296 &exynos_ohci->hcd->self);
297 236
298 exynos_ohci_phy_enable(exynos_ohci); 237 exynos_ohci_phy_enable(pdev);
299 238
300 ohci_resume(hcd, false); 239 ohci_resume(hcd, false);
301 240
@@ -306,6 +245,10 @@ static int exynos_ohci_resume(struct device *dev)
306#define exynos_ohci_resume NULL 245#define exynos_ohci_resume NULL
307#endif 246#endif
308 247
248static const struct ohci_driver_overrides exynos_overrides __initconst = {
249 .extra_priv_size = sizeof(struct exynos_ohci_hcd),
250};
251
309static const struct dev_pm_ops exynos_ohci_pm_ops = { 252static const struct dev_pm_ops exynos_ohci_pm_ops = {
310 .suspend = exynos_ohci_suspend, 253 .suspend = exynos_ohci_suspend,
311 .resume = exynos_ohci_resume, 254 .resume = exynos_ohci_resume,
@@ -331,6 +274,23 @@ static struct platform_driver exynos_ohci_driver = {
331 .of_match_table = of_match_ptr(exynos_ohci_match), 274 .of_match_table = of_match_ptr(exynos_ohci_match),
332 } 275 }
333}; 276};
277static int __init ohci_exynos_init(void)
278{
279 if (usb_disabled())
280 return -ENODEV;
281
282 pr_info("%s: " DRIVER_DESC "\n", hcd_name);
283 ohci_init_driver(&exynos_ohci_hc_driver, &exynos_overrides);
284 return platform_driver_register(&exynos_ohci_driver);
285}
286module_init(ohci_exynos_init);
287
288static void __exit ohci_exynos_cleanup(void)
289{
290 platform_driver_unregister(&exynos_ohci_driver);
291}
292module_exit(ohci_exynos_cleanup);
334 293
335MODULE_ALIAS("platform:exynos-ohci"); 294MODULE_ALIAS("platform:exynos-ohci");
336MODULE_AUTHOR("Jingoo Han <jg1.han@samsung.com>"); 295MODULE_AUTHOR("Jingoo Han <jg1.han@samsung.com>");
296MODULE_LICENSE("GPL v2");
diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c
index 604cad1bcf9c..8ada13f8dde2 100644
--- a/drivers/usb/host/ohci-hcd.c
+++ b/drivers/usb/host/ohci-hcd.c
@@ -1161,10 +1161,12 @@ void ohci_init_driver(struct hc_driver *drv,
1161 /* Copy the generic table to drv and then apply the overrides */ 1161 /* Copy the generic table to drv and then apply the overrides */
1162 *drv = ohci_hc_driver; 1162 *drv = ohci_hc_driver;
1163 1163
1164 drv->product_desc = over->product_desc; 1164 if (over) {
1165 drv->hcd_priv_size += over->extra_priv_size; 1165 drv->product_desc = over->product_desc;
1166 if (over->reset) 1166 drv->hcd_priv_size += over->extra_priv_size;
1167 drv->reset = over->reset; 1167 if (over->reset)
1168 drv->reset = over->reset;
1169 }
1168} 1170}
1169EXPORT_SYMBOL_GPL(ohci_init_driver); 1171EXPORT_SYMBOL_GPL(ohci_init_driver);
1170 1172
@@ -1179,46 +1181,6 @@ MODULE_LICENSE ("GPL");
1179#define SA1111_DRIVER ohci_hcd_sa1111_driver 1181#define SA1111_DRIVER ohci_hcd_sa1111_driver
1180#endif 1182#endif
1181 1183
1182#if defined(CONFIG_ARCH_S3C24XX) || defined(CONFIG_ARCH_S3C64XX)
1183#include "ohci-s3c2410.c"
1184#define S3C2410_PLATFORM_DRIVER ohci_hcd_s3c2410_driver
1185#endif
1186
1187#ifdef CONFIG_USB_OHCI_EXYNOS
1188#include "ohci-exynos.c"
1189#define EXYNOS_PLATFORM_DRIVER exynos_ohci_driver
1190#endif
1191
1192#ifdef CONFIG_USB_OHCI_HCD_OMAP1
1193#include "ohci-omap.c"
1194#define OMAP1_PLATFORM_DRIVER ohci_hcd_omap_driver
1195#endif
1196
1197#ifdef CONFIG_USB_OHCI_HCD_OMAP3
1198#include "ohci-omap3.c"
1199#define OMAP3_PLATFORM_DRIVER ohci_hcd_omap3_driver
1200#endif
1201
1202#if defined(CONFIG_PXA27x) || defined(CONFIG_PXA3xx)
1203#include "ohci-pxa27x.c"
1204#define PLATFORM_DRIVER ohci_hcd_pxa27x_driver
1205#endif
1206
1207#ifdef CONFIG_ARCH_EP93XX
1208#include "ohci-ep93xx.c"
1209#define EP93XX_PLATFORM_DRIVER ohci_hcd_ep93xx_driver
1210#endif
1211
1212#ifdef CONFIG_ARCH_AT91
1213#include "ohci-at91.c"
1214#define AT91_PLATFORM_DRIVER ohci_hcd_at91_driver
1215#endif
1216
1217#ifdef CONFIG_ARCH_LPC32XX
1218#include "ohci-nxp.c"
1219#define NXP_PLATFORM_DRIVER usb_hcd_nxp_driver
1220#endif
1221
1222#ifdef CONFIG_ARCH_DAVINCI_DA8XX 1184#ifdef CONFIG_ARCH_DAVINCI_DA8XX
1223#include "ohci-da8xx.c" 1185#include "ohci-da8xx.c"
1224#define DAVINCI_PLATFORM_DRIVER ohci_hcd_da8xx_driver 1186#define DAVINCI_PLATFORM_DRIVER ohci_hcd_da8xx_driver
@@ -1229,11 +1191,6 @@ MODULE_LICENSE ("GPL");
1229#define OF_PLATFORM_DRIVER ohci_hcd_ppc_of_driver 1191#define OF_PLATFORM_DRIVER ohci_hcd_ppc_of_driver
1230#endif 1192#endif
1231 1193
1232#ifdef CONFIG_PLAT_SPEAR
1233#include "ohci-spear.c"
1234#define SPEAR_PLATFORM_DRIVER spear_ohci_hcd_driver
1235#endif
1236
1237#ifdef CONFIG_PPC_PS3 1194#ifdef CONFIG_PPC_PS3
1238#include "ohci-ps3.c" 1195#include "ohci-ps3.c"
1239#define PS3_SYSTEM_BUS_DRIVER ps3_ohci_driver 1196#define PS3_SYSTEM_BUS_DRIVER ps3_ohci_driver
@@ -1296,18 +1253,6 @@ static int __init ohci_hcd_mod_init(void)
1296 goto error_platform; 1253 goto error_platform;
1297#endif 1254#endif
1298 1255
1299#ifdef OMAP1_PLATFORM_DRIVER
1300 retval = platform_driver_register(&OMAP1_PLATFORM_DRIVER);
1301 if (retval < 0)
1302 goto error_omap1_platform;
1303#endif
1304
1305#ifdef OMAP3_PLATFORM_DRIVER
1306 retval = platform_driver_register(&OMAP3_PLATFORM_DRIVER);
1307 if (retval < 0)
1308 goto error_omap3_platform;
1309#endif
1310
1311#ifdef OF_PLATFORM_DRIVER 1256#ifdef OF_PLATFORM_DRIVER
1312 retval = platform_driver_register(&OF_PLATFORM_DRIVER); 1257 retval = platform_driver_register(&OF_PLATFORM_DRIVER);
1313 if (retval < 0) 1258 if (retval < 0)
@@ -1332,79 +1277,19 @@ static int __init ohci_hcd_mod_init(void)
1332 goto error_tmio; 1277 goto error_tmio;
1333#endif 1278#endif
1334 1279
1335#ifdef S3C2410_PLATFORM_DRIVER
1336 retval = platform_driver_register(&S3C2410_PLATFORM_DRIVER);
1337 if (retval < 0)
1338 goto error_s3c2410;
1339#endif
1340
1341#ifdef EXYNOS_PLATFORM_DRIVER
1342 retval = platform_driver_register(&EXYNOS_PLATFORM_DRIVER);
1343 if (retval < 0)
1344 goto error_exynos;
1345#endif
1346
1347#ifdef EP93XX_PLATFORM_DRIVER
1348 retval = platform_driver_register(&EP93XX_PLATFORM_DRIVER);
1349 if (retval < 0)
1350 goto error_ep93xx;
1351#endif
1352
1353#ifdef AT91_PLATFORM_DRIVER
1354 retval = platform_driver_register(&AT91_PLATFORM_DRIVER);
1355 if (retval < 0)
1356 goto error_at91;
1357#endif
1358
1359#ifdef NXP_PLATFORM_DRIVER
1360 retval = platform_driver_register(&NXP_PLATFORM_DRIVER);
1361 if (retval < 0)
1362 goto error_nxp;
1363#endif
1364
1365#ifdef DAVINCI_PLATFORM_DRIVER 1280#ifdef DAVINCI_PLATFORM_DRIVER
1366 retval = platform_driver_register(&DAVINCI_PLATFORM_DRIVER); 1281 retval = platform_driver_register(&DAVINCI_PLATFORM_DRIVER);
1367 if (retval < 0) 1282 if (retval < 0)
1368 goto error_davinci; 1283 goto error_davinci;
1369#endif 1284#endif
1370 1285
1371#ifdef SPEAR_PLATFORM_DRIVER
1372 retval = platform_driver_register(&SPEAR_PLATFORM_DRIVER);
1373 if (retval < 0)
1374 goto error_spear;
1375#endif
1376
1377 return retval; 1286 return retval;
1378 1287
1379 /* Error path */ 1288 /* Error path */
1380#ifdef SPEAR_PLATFORM_DRIVER
1381 platform_driver_unregister(&SPEAR_PLATFORM_DRIVER);
1382 error_spear:
1383#endif
1384#ifdef DAVINCI_PLATFORM_DRIVER 1289#ifdef DAVINCI_PLATFORM_DRIVER
1385 platform_driver_unregister(&DAVINCI_PLATFORM_DRIVER); 1290 platform_driver_unregister(&DAVINCI_PLATFORM_DRIVER);
1386 error_davinci: 1291 error_davinci:
1387#endif 1292#endif
1388#ifdef NXP_PLATFORM_DRIVER
1389 platform_driver_unregister(&NXP_PLATFORM_DRIVER);
1390 error_nxp:
1391#endif
1392#ifdef AT91_PLATFORM_DRIVER
1393 platform_driver_unregister(&AT91_PLATFORM_DRIVER);
1394 error_at91:
1395#endif
1396#ifdef EP93XX_PLATFORM_DRIVER
1397 platform_driver_unregister(&EP93XX_PLATFORM_DRIVER);
1398 error_ep93xx:
1399#endif
1400#ifdef EXYNOS_PLATFORM_DRIVER
1401 platform_driver_unregister(&EXYNOS_PLATFORM_DRIVER);
1402 error_exynos:
1403#endif
1404#ifdef S3C2410_PLATFORM_DRIVER
1405 platform_driver_unregister(&S3C2410_PLATFORM_DRIVER);
1406 error_s3c2410:
1407#endif
1408#ifdef TMIO_OHCI_DRIVER 1293#ifdef TMIO_OHCI_DRIVER
1409 platform_driver_unregister(&TMIO_OHCI_DRIVER); 1294 platform_driver_unregister(&TMIO_OHCI_DRIVER);
1410 error_tmio: 1295 error_tmio:
@@ -1421,14 +1306,6 @@ static int __init ohci_hcd_mod_init(void)
1421 platform_driver_unregister(&OF_PLATFORM_DRIVER); 1306 platform_driver_unregister(&OF_PLATFORM_DRIVER);
1422 error_of_platform: 1307 error_of_platform:
1423#endif 1308#endif
1424#ifdef OMAP3_PLATFORM_DRIVER
1425 platform_driver_unregister(&OMAP3_PLATFORM_DRIVER);
1426 error_omap3_platform:
1427#endif
1428#ifdef OMAP1_PLATFORM_DRIVER
1429 platform_driver_unregister(&OMAP1_PLATFORM_DRIVER);
1430 error_omap1_platform:
1431#endif
1432#ifdef PLATFORM_DRIVER 1309#ifdef PLATFORM_DRIVER
1433 platform_driver_unregister(&PLATFORM_DRIVER); 1310 platform_driver_unregister(&PLATFORM_DRIVER);
1434 error_platform: 1311 error_platform:
@@ -1450,27 +1327,9 @@ module_init(ohci_hcd_mod_init);
1450 1327
1451static void __exit ohci_hcd_mod_exit(void) 1328static void __exit ohci_hcd_mod_exit(void)
1452{ 1329{
1453#ifdef SPEAR_PLATFORM_DRIVER
1454 platform_driver_unregister(&SPEAR_PLATFORM_DRIVER);
1455#endif
1456#ifdef DAVINCI_PLATFORM_DRIVER 1330#ifdef DAVINCI_PLATFORM_DRIVER
1457 platform_driver_unregister(&DAVINCI_PLATFORM_DRIVER); 1331 platform_driver_unregister(&DAVINCI_PLATFORM_DRIVER);
1458#endif 1332#endif
1459#ifdef NXP_PLATFORM_DRIVER
1460 platform_driver_unregister(&NXP_PLATFORM_DRIVER);
1461#endif
1462#ifdef AT91_PLATFORM_DRIVER
1463 platform_driver_unregister(&AT91_PLATFORM_DRIVER);
1464#endif
1465#ifdef EP93XX_PLATFORM_DRIVER
1466 platform_driver_unregister(&EP93XX_PLATFORM_DRIVER);
1467#endif
1468#ifdef EXYNOS_PLATFORM_DRIVER
1469 platform_driver_unregister(&EXYNOS_PLATFORM_DRIVER);
1470#endif
1471#ifdef S3C2410_PLATFORM_DRIVER
1472 platform_driver_unregister(&S3C2410_PLATFORM_DRIVER);
1473#endif
1474#ifdef TMIO_OHCI_DRIVER 1333#ifdef TMIO_OHCI_DRIVER
1475 platform_driver_unregister(&TMIO_OHCI_DRIVER); 1334 platform_driver_unregister(&TMIO_OHCI_DRIVER);
1476#endif 1335#endif
@@ -1483,12 +1342,6 @@ static void __exit ohci_hcd_mod_exit(void)
1483#ifdef OF_PLATFORM_DRIVER 1342#ifdef OF_PLATFORM_DRIVER
1484 platform_driver_unregister(&OF_PLATFORM_DRIVER); 1343 platform_driver_unregister(&OF_PLATFORM_DRIVER);
1485#endif 1344#endif
1486#ifdef OMAP3_PLATFORM_DRIVER
1487 platform_driver_unregister(&OMAP3_PLATFORM_DRIVER);
1488#endif
1489#ifdef OMAP1_PLATFORM_DRIVER
1490 platform_driver_unregister(&OMAP1_PLATFORM_DRIVER);
1491#endif
1492#ifdef PLATFORM_DRIVER 1345#ifdef PLATFORM_DRIVER
1493 platform_driver_unregister(&PLATFORM_DRIVER); 1346 platform_driver_unregister(&PLATFORM_DRIVER);
1494#endif 1347#endif
diff --git a/drivers/usb/host/ohci-hub.c b/drivers/usb/host/ohci-hub.c
index 2347ab83f046..61705a760e7d 100644
--- a/drivers/usb/host/ohci-hub.c
+++ b/drivers/usb/host/ohci-hub.c
@@ -212,10 +212,11 @@ __acquires(ohci->lock)
212 /* Sometimes PCI D3 suspend trashes frame timings ... */ 212 /* Sometimes PCI D3 suspend trashes frame timings ... */
213 periodic_reinit (ohci); 213 periodic_reinit (ohci);
214 214
215 /* the following code is executed with ohci->lock held and 215 /*
216 * irqs disabled if and only if autostopped is true 216 * The following code is executed with ohci->lock held and
217 * irqs disabled if and only if autostopped is true. This
218 * will cause sparse to warn about a "context imbalance".
217 */ 219 */
218
219skip_resume: 220skip_resume:
220 /* interrupts might have been disabled */ 221 /* interrupts might have been disabled */
221 ohci_writel (ohci, OHCI_INTR_INIT, &ohci->regs->intrenable); 222 ohci_writel (ohci, OHCI_INTR_INIT, &ohci->regs->intrenable);
@@ -531,7 +532,7 @@ ohci_hub_descriptor (
531 temp |= 0x0010; 532 temp |= 0x0010;
532 else if (rh & RH_A_OCPM) /* per-port overcurrent reporting? */ 533 else if (rh & RH_A_OCPM) /* per-port overcurrent reporting? */
533 temp |= 0x0008; 534 temp |= 0x0008;
534 desc->wHubCharacteristics = (__force __u16)cpu_to_hc16(ohci, temp); 535 desc->wHubCharacteristics = cpu_to_le16(temp);
535 536
536 /* ports removable, and usb 1.0 legacy PortPwrCtrlMask */ 537 /* ports removable, and usb 1.0 legacy PortPwrCtrlMask */
537 rh = roothub_b (ohci); 538 rh = roothub_b (ohci);
diff --git a/drivers/usb/host/ohci-nxp.c b/drivers/usb/host/ohci-nxp.c
index 7d7d507d54e8..9ab7e24ba65d 100644
--- a/drivers/usb/host/ohci-nxp.c
+++ b/drivers/usb/host/ohci-nxp.c
@@ -19,10 +19,19 @@
19 * or implied. 19 * or implied.
20 */ 20 */
21#include <linux/clk.h> 21#include <linux/clk.h>
22#include <linux/platform_device.h> 22#include <linux/dma-mapping.h>
23#include <linux/io.h>
23#include <linux/i2c.h> 24#include <linux/i2c.h>
25#include <linux/kernel.h>
26#include <linux/module.h>
24#include <linux/of.h> 27#include <linux/of.h>
28#include <linux/platform_device.h>
25#include <linux/usb/isp1301.h> 29#include <linux/usb/isp1301.h>
30#include <linux/usb.h>
31#include <linux/usb/hcd.h>
32
33#include "ohci.h"
34
26 35
27#include <mach/hardware.h> 36#include <mach/hardware.h>
28#include <asm/mach-types.h> 37#include <asm/mach-types.h>
@@ -57,6 +66,11 @@
57#define start_int_umask(irq) 66#define start_int_umask(irq)
58#endif 67#endif
59 68
69#define DRIVER_DESC "OHCI NXP driver"
70
71static const char hcd_name[] = "ohci-nxp";
72static struct hc_driver __read_mostly ohci_nxp_hc_driver;
73
60static struct i2c_client *isp1301_i2c_client; 74static struct i2c_client *isp1301_i2c_client;
61 75
62extern int usb_disabled(void); 76extern int usb_disabled(void);
@@ -132,14 +146,14 @@ static inline void isp1301_vbus_off(void)
132 OTG1_VBUS_DRV); 146 OTG1_VBUS_DRV);
133} 147}
134 148
135static void nxp_start_hc(void) 149static void ohci_nxp_start_hc(void)
136{ 150{
137 unsigned long tmp = __raw_readl(USB_OTG_STAT_CONTROL) | HOST_EN; 151 unsigned long tmp = __raw_readl(USB_OTG_STAT_CONTROL) | HOST_EN;
138 __raw_writel(tmp, USB_OTG_STAT_CONTROL); 152 __raw_writel(tmp, USB_OTG_STAT_CONTROL);
139 isp1301_vbus_on(); 153 isp1301_vbus_on();
140} 154}
141 155
142static void nxp_stop_hc(void) 156static void ohci_nxp_stop_hc(void)
143{ 157{
144 unsigned long tmp; 158 unsigned long tmp;
145 isp1301_vbus_off(); 159 isp1301_vbus_off();
@@ -147,68 +161,9 @@ static void nxp_stop_hc(void)
147 __raw_writel(tmp, USB_OTG_STAT_CONTROL); 161 __raw_writel(tmp, USB_OTG_STAT_CONTROL);
148} 162}
149 163
150static int ohci_nxp_start(struct usb_hcd *hcd) 164static int ohci_hcd_nxp_probe(struct platform_device *pdev)
151{
152 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
153 int ret;
154
155 if ((ret = ohci_init(ohci)) < 0)
156 return ret;
157
158 if ((ret = ohci_run(ohci)) < 0) {
159 dev_err(hcd->self.controller, "can't start\n");
160 ohci_stop(hcd);
161 return ret;
162 }
163 return 0;
164}
165
166static const struct hc_driver ohci_nxp_hc_driver = {
167 .description = hcd_name,
168 .product_desc = "nxp OHCI",
169
170 /*
171 * generic hardware linkage
172 */
173 .irq = ohci_irq,
174 .flags = HCD_USB11 | HCD_MEMORY,
175
176 .hcd_priv_size = sizeof(struct ohci_hcd),
177 /*
178 * basic lifecycle operations
179 */
180 .start = ohci_nxp_start,
181 .stop = ohci_stop,
182 .shutdown = ohci_shutdown,
183
184 /*
185 * managing i/o requests and associated device resources
186 */
187 .urb_enqueue = ohci_urb_enqueue,
188 .urb_dequeue = ohci_urb_dequeue,
189 .endpoint_disable = ohci_endpoint_disable,
190
191 /*
192 * scheduling support
193 */
194 .get_frame_number = ohci_get_frame,
195
196 /*
197 * root hub support
198 */
199 .hub_status_data = ohci_hub_status_data,
200 .hub_control = ohci_hub_control,
201#ifdef CONFIG_PM
202 .bus_suspend = ohci_bus_suspend,
203 .bus_resume = ohci_bus_resume,
204#endif
205 .start_port_reset = ohci_start_port_reset,
206};
207
208static int usb_hcd_nxp_probe(struct platform_device *pdev)
209{ 165{
210 struct usb_hcd *hcd = 0; 166 struct usb_hcd *hcd = 0;
211 struct ohci_hcd *ohci;
212 const struct hc_driver *driver = &ohci_nxp_hc_driver; 167 const struct hc_driver *driver = &ohci_nxp_hc_driver;
213 struct resource *res; 168 struct resource *res;
214 int ret = 0, irq; 169 int ret = 0, irq;
@@ -313,17 +268,15 @@ static int usb_hcd_nxp_probe(struct platform_device *pdev)
313 goto fail_resource; 268 goto fail_resource;
314 } 269 }
315 270
316 nxp_start_hc(); 271 ohci_nxp_start_hc();
317 platform_set_drvdata(pdev, hcd); 272 platform_set_drvdata(pdev, hcd);
318 ohci = hcd_to_ohci(hcd);
319 ohci_hcd_init(ohci);
320 273
321 dev_info(&pdev->dev, "at 0x%p, irq %d\n", hcd->regs, hcd->irq); 274 dev_info(&pdev->dev, "at 0x%p, irq %d\n", hcd->regs, hcd->irq);
322 ret = usb_add_hcd(hcd, irq, 0); 275 ret = usb_add_hcd(hcd, irq, 0);
323 if (ret == 0) 276 if (ret == 0)
324 return ret; 277 return ret;
325 278
326 nxp_stop_hc(); 279 ohci_nxp_stop_hc();
327fail_resource: 280fail_resource:
328 usb_put_hcd(hcd); 281 usb_put_hcd(hcd);
329fail_hcd: 282fail_hcd:
@@ -345,12 +298,12 @@ fail_disable:
345 return ret; 298 return ret;
346} 299}
347 300
348static int usb_hcd_nxp_remove(struct platform_device *pdev) 301static int ohci_hcd_nxp_remove(struct platform_device *pdev)
349{ 302{
350 struct usb_hcd *hcd = platform_get_drvdata(pdev); 303 struct usb_hcd *hcd = platform_get_drvdata(pdev);
351 304
352 usb_remove_hcd(hcd); 305 usb_remove_hcd(hcd);
353 nxp_stop_hc(); 306 ohci_nxp_stop_hc();
354 usb_put_hcd(hcd); 307 usb_put_hcd(hcd);
355 clk_disable(usb_pll_clk); 308 clk_disable(usb_pll_clk);
356 clk_put(usb_pll_clk); 309 clk_put(usb_pll_clk);
@@ -366,20 +319,40 @@ static int usb_hcd_nxp_remove(struct platform_device *pdev)
366MODULE_ALIAS("platform:usb-ohci"); 319MODULE_ALIAS("platform:usb-ohci");
367 320
368#ifdef CONFIG_OF 321#ifdef CONFIG_OF
369static const struct of_device_id usb_hcd_nxp_match[] = { 322static const struct of_device_id ohci_hcd_nxp_match[] = {
370 { .compatible = "nxp,ohci-nxp" }, 323 { .compatible = "nxp,ohci-nxp" },
371 {}, 324 {},
372}; 325};
373MODULE_DEVICE_TABLE(of, usb_hcd_nxp_match); 326MODULE_DEVICE_TABLE(of, ohci_hcd_nxp_match);
374#endif 327#endif
375 328
376static struct platform_driver usb_hcd_nxp_driver = { 329static struct platform_driver ohci_hcd_nxp_driver = {
377 .driver = { 330 .driver = {
378 .name = "usb-ohci", 331 .name = "usb-ohci",
379 .owner = THIS_MODULE, 332 .owner = THIS_MODULE,
380 .of_match_table = of_match_ptr(usb_hcd_nxp_match), 333 .of_match_table = of_match_ptr(ohci_hcd_nxp_match),
381 }, 334 },
382 .probe = usb_hcd_nxp_probe, 335 .probe = ohci_hcd_nxp_probe,
383 .remove = usb_hcd_nxp_remove, 336 .remove = ohci_hcd_nxp_remove,
384}; 337};
385 338
339static int __init ohci_nxp_init(void)
340{
341 if (usb_disabled())
342 return -ENODEV;
343
344 pr_info("%s: " DRIVER_DESC "\n", hcd_name);
345
346 ohci_init_driver(&ohci_nxp_hc_driver, NULL);
347 return platform_driver_register(&ohci_hcd_nxp_driver);
348}
349module_init(ohci_nxp_init);
350
351static void __exit ohci_nxp_cleanup(void)
352{
353 platform_driver_unregister(&ohci_hcd_nxp_driver);
354}
355module_exit(ohci_nxp_cleanup);
356
357MODULE_DESCRIPTION(DRIVER_DESC);
358MODULE_LICENSE("GPL v2");
diff --git a/drivers/usb/host/ohci-omap.c b/drivers/usb/host/ohci-omap.c
index 31d3a12eb486..f253214741ba 100644
--- a/drivers/usb/host/ohci-omap.c
+++ b/drivers/usb/host/ohci-omap.c
@@ -14,12 +14,21 @@
14 * This file is licenced under the GPL. 14 * This file is licenced under the GPL.
15 */ 15 */
16 16
17#include <linux/signal.h>
18#include <linux/jiffies.h>
19#include <linux/platform_device.h>
20#include <linux/clk.h> 17#include <linux/clk.h>
18#include <linux/dma-mapping.h>
21#include <linux/err.h> 19#include <linux/err.h>
22#include <linux/gpio.h> 20#include <linux/gpio.h>
21#include <linux/io.h>
22#include <linux/jiffies.h>
23#include <linux/kernel.h>
24#include <linux/module.h>
25#include <linux/usb/otg.h>
26#include <linux/platform_device.h>
27#include <linux/signal.h>
28#include <linux/usb.h>
29#include <linux/usb/hcd.h>
30
31#include "ohci.h"
23 32
24#include <asm/io.h> 33#include <asm/io.h>
25#include <asm/mach-types.h> 34#include <asm/mach-types.h>
@@ -42,10 +51,7 @@
42#define OMAP1510_LB_MMU_RAM_H 0xfffec234 51#define OMAP1510_LB_MMU_RAM_H 0xfffec234
43#define OMAP1510_LB_MMU_RAM_L 0xfffec238 52#define OMAP1510_LB_MMU_RAM_L 0xfffec238
44 53
45 54#define DRIVER_DESC "OHCI OMAP driver"
46#ifndef CONFIG_ARCH_OMAP
47#error "This file is OMAP bus glue. CONFIG_OMAP must be defined."
48#endif
49 55
50#ifdef CONFIG_TPS65010 56#ifdef CONFIG_TPS65010
51#include <linux/i2c/tps65010.h> 57#include <linux/i2c/tps65010.h>
@@ -68,8 +74,9 @@ extern int ocpi_enable(void);
68 74
69static struct clk *usb_host_ck; 75static struct clk *usb_host_ck;
70static struct clk *usb_dc_ck; 76static struct clk *usb_dc_ck;
71static int host_enabled; 77
72static int host_initialized; 78static const char hcd_name[] = "ohci-omap";
79static struct hc_driver __read_mostly ohci_omap_hc_driver;
73 80
74static void omap_ohci_clock_power(int on) 81static void omap_ohci_clock_power(int on)
75{ 82{
@@ -188,7 +195,7 @@ static void start_hnp(struct ohci_hcd *ohci)
188 195
189/*-------------------------------------------------------------------------*/ 196/*-------------------------------------------------------------------------*/
190 197
191static int ohci_omap_init(struct usb_hcd *hcd) 198static int ohci_omap_reset(struct usb_hcd *hcd)
192{ 199{
193 struct ohci_hcd *ohci = hcd_to_ohci(hcd); 200 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
194 struct omap_usb_config *config = dev_get_platdata(hcd->self.controller); 201 struct omap_usb_config *config = dev_get_platdata(hcd->self.controller);
@@ -198,9 +205,9 @@ static int ohci_omap_init(struct usb_hcd *hcd)
198 dev_dbg(hcd->self.controller, "starting USB Controller\n"); 205 dev_dbg(hcd->self.controller, "starting USB Controller\n");
199 206
200 if (config->otg) { 207 if (config->otg) {
201 ohci_to_hcd(ohci)->self.otg_port = config->otg; 208 hcd->self.otg_port = config->otg;
202 /* default/minimum OTG power budget: 8 mA */ 209 /* default/minimum OTG power budget: 8 mA */
203 ohci_to_hcd(ohci)->power_budget = 8; 210 hcd->power_budget = 8;
204 } 211 }
205 212
206 /* boards can use OTG transceivers in non-OTG modes */ 213 /* boards can use OTG transceivers in non-OTG modes */
@@ -238,9 +245,15 @@ static int ohci_omap_init(struct usb_hcd *hcd)
238 omap_1510_local_bus_init(); 245 omap_1510_local_bus_init();
239 } 246 }
240 247
241 if ((ret = ohci_init(ohci)) < 0) 248 ret = ohci_setup(hcd);
249 if (ret < 0)
242 return ret; 250 return ret;
243 251
252 if (config->otg || config->rwc) {
253 ohci->hc_control = OHCI_CTRL_RWC;
254 writel(OHCI_CTRL_RWC, &ohci->regs->control);
255 }
256
244 /* board-specific power switching and overcurrent support */ 257 /* board-specific power switching and overcurrent support */
245 if (machine_is_omap_osk() || machine_is_omap_innovator()) { 258 if (machine_is_omap_osk() || machine_is_omap_innovator()) {
246 u32 rh = roothub_a (ohci); 259 u32 rh = roothub_a (ohci);
@@ -281,14 +294,6 @@ static int ohci_omap_init(struct usb_hcd *hcd)
281 return 0; 294 return 0;
282} 295}
283 296
284static void ohci_omap_stop(struct usb_hcd *hcd)
285{
286 dev_dbg(hcd->self.controller, "stopping USB Controller\n");
287 ohci_stop(hcd);
288 omap_ohci_clock_power(0);
289}
290
291
292/*-------------------------------------------------------------------------*/ 297/*-------------------------------------------------------------------------*/
293 298
294/** 299/**
@@ -304,7 +309,6 @@ static int usb_hcd_omap_probe (const struct hc_driver *driver,
304{ 309{
305 int retval, irq; 310 int retval, irq;
306 struct usb_hcd *hcd = 0; 311 struct usb_hcd *hcd = 0;
307 struct ohci_hcd *ohci;
308 312
309 if (pdev->num_resources != 2) { 313 if (pdev->num_resources != 2) {
310 printk(KERN_ERR "hcd probe: invalid num_resources: %i\n", 314 printk(KERN_ERR "hcd probe: invalid num_resources: %i\n",
@@ -354,12 +358,6 @@ static int usb_hcd_omap_probe (const struct hc_driver *driver,
354 goto err2; 358 goto err2;
355 } 359 }
356 360
357 ohci = hcd_to_ohci(hcd);
358 ohci_hcd_init(ohci);
359
360 host_initialized = 0;
361 host_enabled = 1;
362
363 irq = platform_get_irq(pdev, 0); 361 irq = platform_get_irq(pdev, 0);
364 if (irq < 0) { 362 if (irq < 0) {
365 retval = -ENXIO; 363 retval = -ENXIO;
@@ -369,11 +367,6 @@ static int usb_hcd_omap_probe (const struct hc_driver *driver,
369 if (retval) 367 if (retval)
370 goto err3; 368 goto err3;
371 369
372 host_initialized = 1;
373
374 if (!host_enabled)
375 omap_ohci_clock_power(0);
376
377 return 0; 370 return 0;
378err3: 371err3:
379 iounmap(hcd->regs); 372 iounmap(hcd->regs);
@@ -402,7 +395,9 @@ err0:
402static inline void 395static inline void
403usb_hcd_omap_remove (struct usb_hcd *hcd, struct platform_device *pdev) 396usb_hcd_omap_remove (struct usb_hcd *hcd, struct platform_device *pdev)
404{ 397{
398 dev_dbg(hcd->self.controller, "stopping USB Controller\n");
405 usb_remove_hcd(hcd); 399 usb_remove_hcd(hcd);
400 omap_ohci_clock_power(0);
406 if (!IS_ERR_OR_NULL(hcd->phy)) { 401 if (!IS_ERR_OR_NULL(hcd->phy)) {
407 (void) otg_set_host(hcd->phy->otg, 0); 402 (void) otg_set_host(hcd->phy->otg, 0);
408 usb_put_phy(hcd->phy); 403 usb_put_phy(hcd->phy);
@@ -418,76 +413,6 @@ usb_hcd_omap_remove (struct usb_hcd *hcd, struct platform_device *pdev)
418 413
419/*-------------------------------------------------------------------------*/ 414/*-------------------------------------------------------------------------*/
420 415
421static int
422ohci_omap_start (struct usb_hcd *hcd)
423{
424 struct omap_usb_config *config;
425 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
426 int ret;
427
428 if (!host_enabled)
429 return 0;
430 config = dev_get_platdata(hcd->self.controller);
431 if (config->otg || config->rwc) {
432 ohci->hc_control = OHCI_CTRL_RWC;
433 writel(OHCI_CTRL_RWC, &ohci->regs->control);
434 }
435
436 if ((ret = ohci_run (ohci)) < 0) {
437 dev_err(hcd->self.controller, "can't start\n");
438 ohci_stop (hcd);
439 return ret;
440 }
441 return 0;
442}
443
444/*-------------------------------------------------------------------------*/
445
446static const struct hc_driver ohci_omap_hc_driver = {
447 .description = hcd_name,
448 .product_desc = "OMAP OHCI",
449 .hcd_priv_size = sizeof(struct ohci_hcd),
450
451 /*
452 * generic hardware linkage
453 */
454 .irq = ohci_irq,
455 .flags = HCD_USB11 | HCD_MEMORY,
456
457 /*
458 * basic lifecycle operations
459 */
460 .reset = ohci_omap_init,
461 .start = ohci_omap_start,
462 .stop = ohci_omap_stop,
463 .shutdown = ohci_shutdown,
464
465 /*
466 * managing i/o requests and associated device resources
467 */
468 .urb_enqueue = ohci_urb_enqueue,
469 .urb_dequeue = ohci_urb_dequeue,
470 .endpoint_disable = ohci_endpoint_disable,
471
472 /*
473 * scheduling support
474 */
475 .get_frame_number = ohci_get_frame,
476
477 /*
478 * root hub support
479 */
480 .hub_status_data = ohci_hub_status_data,
481 .hub_control = ohci_hub_control,
482#ifdef CONFIG_PM
483 .bus_suspend = ohci_bus_suspend,
484 .bus_resume = ohci_bus_resume,
485#endif
486 .start_port_reset = ohci_start_port_reset,
487};
488
489/*-------------------------------------------------------------------------*/
490
491static int ohci_hcd_omap_drv_probe(struct platform_device *dev) 416static int ohci_hcd_omap_drv_probe(struct platform_device *dev)
492{ 417{
493 return usb_hcd_omap_probe(&ohci_omap_hc_driver, dev); 418 return usb_hcd_omap_probe(&ohci_omap_hc_driver, dev);
@@ -506,16 +431,23 @@ static int ohci_hcd_omap_drv_remove(struct platform_device *dev)
506 431
507#ifdef CONFIG_PM 432#ifdef CONFIG_PM
508 433
509static int ohci_omap_suspend(struct platform_device *dev, pm_message_t message) 434static int ohci_omap_suspend(struct platform_device *pdev, pm_message_t message)
510{ 435{
511 struct ohci_hcd *ohci = hcd_to_ohci(platform_get_drvdata(dev)); 436 struct usb_hcd *hcd = platform_get_drvdata(pdev);
437 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
438 bool do_wakeup = device_may_wakeup(&pdev->dev);
439 int ret;
512 440
513 if (time_before(jiffies, ohci->next_statechange)) 441 if (time_before(jiffies, ohci->next_statechange))
514 msleep(5); 442 msleep(5);
515 ohci->next_statechange = jiffies; 443 ohci->next_statechange = jiffies;
516 444
445 ret = ohci_suspend(hcd, do_wakeup);
446 if (ret)
447 return ret;
448
517 omap_ohci_clock_power(0); 449 omap_ohci_clock_power(0);
518 return 0; 450 return ret;
519} 451}
520 452
521static int ohci_omap_resume(struct platform_device *dev) 453static int ohci_omap_resume(struct platform_device *dev)
@@ -553,4 +485,29 @@ static struct platform_driver ohci_hcd_omap_driver = {
553 }, 485 },
554}; 486};
555 487
488static const struct ohci_driver_overrides omap_overrides __initconst = {
489 .product_desc = "OMAP OHCI",
490 .reset = ohci_omap_reset
491};
492
493static int __init ohci_omap_init(void)
494{
495 if (usb_disabled())
496 return -ENODEV;
497
498 pr_info("%s: " DRIVER_DESC "\n", hcd_name);
499
500 ohci_init_driver(&ohci_omap_hc_driver, &omap_overrides);
501 return platform_driver_register(&ohci_hcd_omap_driver);
502}
503module_init(ohci_omap_init);
504
505static void __exit ohci_omap_cleanup(void)
506{
507 platform_driver_unregister(&ohci_hcd_omap_driver);
508}
509module_exit(ohci_omap_cleanup);
510
511MODULE_DESCRIPTION(DRIVER_DESC);
556MODULE_ALIAS("platform:ohci"); 512MODULE_ALIAS("platform:ohci");
513MODULE_LICENSE("GPL");
diff --git a/drivers/usb/host/ohci-omap3.c b/drivers/usb/host/ohci-omap3.c
index a09af26f69ed..408d06a68571 100644
--- a/drivers/usb/host/ohci-omap3.c
+++ b/drivers/usb/host/ohci-omap3.c
@@ -29,90 +29,22 @@
29 * - add kernel-doc 29 * - add kernel-doc
30 */ 30 */
31 31
32#include <linux/dma-mapping.h>
33#include <linux/kernel.h>
34#include <linux/module.h>
35#include <linux/of.h>
36#include <linux/usb/otg.h>
32#include <linux/platform_device.h> 37#include <linux/platform_device.h>
33#include <linux/pm_runtime.h> 38#include <linux/pm_runtime.h>
34#include <linux/of.h> 39#include <linux/usb.h>
35#include <linux/dma-mapping.h> 40#include <linux/usb/hcd.h>
36
37/*-------------------------------------------------------------------------*/
38
39static int ohci_omap3_init(struct usb_hcd *hcd)
40{
41 dev_dbg(hcd->self.controller, "starting OHCI controller\n");
42
43 return ohci_init(hcd_to_ohci(hcd));
44}
45
46/*-------------------------------------------------------------------------*/
47
48static int ohci_omap3_start(struct usb_hcd *hcd)
49{
50 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
51 int ret;
52
53 /*
54 * RemoteWakeupConnected has to be set explicitly before
55 * calling ohci_run. The reset value of RWC is 0.
56 */
57 ohci->hc_control = OHCI_CTRL_RWC;
58 writel(OHCI_CTRL_RWC, &ohci->regs->control);
59
60 ret = ohci_run(ohci);
61
62 if (ret < 0) {
63 dev_err(hcd->self.controller, "can't start\n");
64 ohci_stop(hcd);
65 }
66 41
67 return ret; 42#include "ohci.h"
68}
69 43
70/*-------------------------------------------------------------------------*/ 44#define DRIVER_DESC "OHCI OMAP3 driver"
71 45
72static const struct hc_driver ohci_omap3_hc_driver = { 46static const char hcd_name[] = "ohci-omap3";
73 .description = hcd_name, 47static struct hc_driver __read_mostly ohci_omap3_hc_driver;
74 .product_desc = "OMAP3 OHCI Host Controller",
75 .hcd_priv_size = sizeof(struct ohci_hcd),
76
77 /*
78 * generic hardware linkage
79 */
80 .irq = ohci_irq,
81 .flags = HCD_USB11 | HCD_MEMORY,
82
83 /*
84 * basic lifecycle operations
85 */
86 .reset = ohci_omap3_init,
87 .start = ohci_omap3_start,
88 .stop = ohci_stop,
89 .shutdown = ohci_shutdown,
90
91 /*
92 * managing i/o requests and associated device resources
93 */
94 .urb_enqueue = ohci_urb_enqueue,
95 .urb_dequeue = ohci_urb_dequeue,
96 .endpoint_disable = ohci_endpoint_disable,
97
98 /*
99 * scheduling support
100 */
101 .get_frame_number = ohci_get_frame,
102
103 /*
104 * root hub support
105 */
106 .hub_status_data = ohci_hub_status_data,
107 .hub_control = ohci_hub_control,
108#ifdef CONFIG_PM
109 .bus_suspend = ohci_bus_suspend,
110 .bus_resume = ohci_bus_resume,
111#endif
112 .start_port_reset = ohci_start_port_reset,
113};
114
115/*-------------------------------------------------------------------------*/
116 48
117/* 49/*
118 * configure so an HC device and id are always provided 50 * configure so an HC device and id are always provided
@@ -129,6 +61,7 @@ static const struct hc_driver ohci_omap3_hc_driver = {
129static int ohci_hcd_omap3_probe(struct platform_device *pdev) 61static int ohci_hcd_omap3_probe(struct platform_device *pdev)
130{ 62{
131 struct device *dev = &pdev->dev; 63 struct device *dev = &pdev->dev;
64 struct ohci_hcd *ohci;
132 struct usb_hcd *hcd = NULL; 65 struct usb_hcd *hcd = NULL;
133 void __iomem *regs = NULL; 66 void __iomem *regs = NULL;
134 struct resource *res; 67 struct resource *res;
@@ -185,7 +118,12 @@ static int ohci_hcd_omap3_probe(struct platform_device *pdev)
185 pm_runtime_enable(dev); 118 pm_runtime_enable(dev);
186 pm_runtime_get_sync(dev); 119 pm_runtime_get_sync(dev);
187 120
188 ohci_hcd_init(hcd_to_ohci(hcd)); 121 ohci = hcd_to_ohci(hcd);
122 /*
123 * RemoteWakeupConnected has to be set explicitly before
124 * calling ohci_run. The reset value of RWC is 0.
125 */
126 ohci->hc_control = OHCI_CTRL_RWC;
189 127
190 ret = usb_add_hcd(hcd, irq, 0); 128 ret = usb_add_hcd(hcd, irq, 0);
191 if (ret) { 129 if (ret) {
@@ -248,5 +186,25 @@ static struct platform_driver ohci_hcd_omap3_driver = {
248 }, 186 },
249}; 187};
250 188
189static int __init ohci_omap3_init(void)
190{
191 if (usb_disabled())
192 return -ENODEV;
193
194 pr_info("%s: " DRIVER_DESC "\n", hcd_name);
195
196 ohci_init_driver(&ohci_omap3_hc_driver, NULL);
197 return platform_driver_register(&ohci_hcd_omap3_driver);
198}
199module_init(ohci_omap3_init);
200
201static void __exit ohci_omap3_cleanup(void)
202{
203 platform_driver_unregister(&ohci_hcd_omap3_driver);
204}
205module_exit(ohci_omap3_cleanup);
206
207MODULE_DESCRIPTION(DRIVER_DESC);
251MODULE_ALIAS("platform:ohci-omap3"); 208MODULE_ALIAS("platform:ohci-omap3");
252MODULE_AUTHOR("Anand Gadiyar <gadiyar@ti.com>"); 209MODULE_AUTHOR("Anand Gadiyar <gadiyar@ti.com>");
210MODULE_LICENSE("GPL");
diff --git a/drivers/usb/host/ohci-pci.c b/drivers/usb/host/ohci-pci.c
index ec337c2bd5e0..90879e9ccbec 100644
--- a/drivers/usb/host/ohci-pci.c
+++ b/drivers/usb/host/ohci-pci.c
@@ -150,28 +150,16 @@ static int ohci_quirk_nec(struct usb_hcd *hcd)
150static int ohci_quirk_amd700(struct usb_hcd *hcd) 150static int ohci_quirk_amd700(struct usb_hcd *hcd)
151{ 151{
152 struct ohci_hcd *ohci = hcd_to_ohci(hcd); 152 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
153 struct pci_dev *amd_smbus_dev;
154 u8 rev;
155 153
156 if (usb_amd_find_chipset_info()) 154 if (usb_amd_find_chipset_info())
157 ohci->flags |= OHCI_QUIRK_AMD_PLL; 155 ohci->flags |= OHCI_QUIRK_AMD_PLL;
158 156
159 amd_smbus_dev = pci_get_device(PCI_VENDOR_ID_ATI,
160 PCI_DEVICE_ID_ATI_SBX00_SMBUS, NULL);
161 if (!amd_smbus_dev)
162 return 0;
163
164 rev = amd_smbus_dev->revision;
165
166 /* SB800 needs pre-fetch fix */ 157 /* SB800 needs pre-fetch fix */
167 if ((rev >= 0x40) && (rev <= 0x4f)) { 158 if (usb_amd_prefetch_quirk()) {
168 ohci->flags |= OHCI_QUIRK_AMD_PREFETCH; 159 ohci->flags |= OHCI_QUIRK_AMD_PREFETCH;
169 ohci_dbg(ohci, "enabled AMD prefetch quirk\n"); 160 ohci_dbg(ohci, "enabled AMD prefetch quirk\n");
170 } 161 }
171 162
172 pci_dev_put(amd_smbus_dev);
173 amd_smbus_dev = NULL;
174
175 return 0; 163 return 0;
176} 164}
177 165
@@ -323,3 +311,4 @@ module_exit(ohci_pci_cleanup);
323 311
324MODULE_DESCRIPTION(DRIVER_DESC); 312MODULE_DESCRIPTION(DRIVER_DESC);
325MODULE_LICENSE("GPL"); 313MODULE_LICENSE("GPL");
314MODULE_SOFTDEP("pre: ehci_pci");
diff --git a/drivers/usb/host/ohci-platform.c b/drivers/usb/host/ohci-platform.c
index a4c6410f0ed4..f351ff5b171f 100644
--- a/drivers/usb/host/ohci-platform.c
+++ b/drivers/usb/host/ohci-platform.c
@@ -139,14 +139,21 @@ static int ohci_platform_remove(struct platform_device *dev)
139 139
140static int ohci_platform_suspend(struct device *dev) 140static int ohci_platform_suspend(struct device *dev)
141{ 141{
142 struct usb_ohci_pdata *pdata = dev_get_platdata(dev); 142 struct usb_hcd *hcd = dev_get_drvdata(dev);
143 struct usb_ohci_pdata *pdata = dev->platform_data;
143 struct platform_device *pdev = 144 struct platform_device *pdev =
144 container_of(dev, struct platform_device, dev); 145 container_of(dev, struct platform_device, dev);
146 bool do_wakeup = device_may_wakeup(dev);
147 int ret;
148
149 ret = ohci_suspend(hcd, do_wakeup);
150 if (ret)
151 return ret;
145 152
146 if (pdata->power_suspend) 153 if (pdata->power_suspend)
147 pdata->power_suspend(pdev); 154 pdata->power_suspend(pdev);
148 155
149 return 0; 156 return ret;
150} 157}
151 158
152static int ohci_platform_resume(struct device *dev) 159static int ohci_platform_resume(struct device *dev)
diff --git a/drivers/usb/host/ohci-pxa27x.c b/drivers/usb/host/ohci-pxa27x.c
index 93371a235e82..deea5d1d6394 100644
--- a/drivers/usb/host/ohci-pxa27x.c
+++ b/drivers/usb/host/ohci-pxa27x.c
@@ -19,15 +19,26 @@
19 * This file is licenced under the GPL. 19 * This file is licenced under the GPL.
20 */ 20 */
21 21
22#include <linux/device.h>
23#include <linux/signal.h>
24#include <linux/platform_device.h>
25#include <linux/clk.h> 22#include <linux/clk.h>
23#include <linux/device.h>
24#include <linux/io.h>
25#include <linux/kernel.h>
26#include <linux/module.h>
26#include <linux/of_platform.h> 27#include <linux/of_platform.h>
27#include <linux/of_gpio.h> 28#include <linux/of_gpio.h>
28#include <mach/hardware.h>
29#include <linux/platform_data/usb-ohci-pxa27x.h> 29#include <linux/platform_data/usb-ohci-pxa27x.h>
30#include <linux/platform_data/usb-pxa3xx-ulpi.h> 30#include <linux/platform_data/usb-pxa3xx-ulpi.h>
31#include <linux/platform_device.h>
32#include <linux/signal.h>
33#include <linux/usb.h>
34#include <linux/usb/hcd.h>
35#include <linux/usb/otg.h>
36
37#include <mach/hardware.h>
38
39#include "ohci.h"
40
41#define DRIVER_DESC "OHCI PXA27x/PXA3x driver"
31 42
32/* 43/*
33 * UHC: USB Host Controller (OHCI-like) register definitions 44 * UHC: USB Host Controller (OHCI-like) register definitions
@@ -101,16 +112,16 @@
101 112
102#define PXA_UHC_MAX_PORTNUM 3 113#define PXA_UHC_MAX_PORTNUM 3
103 114
104struct pxa27x_ohci { 115static const char hcd_name[] = "ohci-pxa27x";
105 /* must be 1st member here for hcd_to_ohci() to work */ 116
106 struct ohci_hcd ohci; 117static struct hc_driver __read_mostly ohci_pxa27x_hc_driver;
107 118
108 struct device *dev; 119struct pxa27x_ohci {
109 struct clk *clk; 120 struct clk *clk;
110 void __iomem *mmio_base; 121 void __iomem *mmio_base;
111}; 122};
112 123
113#define to_pxa27x_ohci(hcd) (struct pxa27x_ohci *)hcd_to_ohci(hcd) 124#define to_pxa27x_ohci(hcd) (struct pxa27x_ohci *)(hcd_to_ohci(hcd)->priv)
114 125
115/* 126/*
116 PMM_NPS_MODE -- PMM Non-power switching mode 127 PMM_NPS_MODE -- PMM Non-power switching mode
@@ -122,10 +133,10 @@ struct pxa27x_ohci {
122 PMM_PERPORT_MODE -- PMM per port switching mode 133 PMM_PERPORT_MODE -- PMM per port switching mode
123 Ports are powered individually. 134 Ports are powered individually.
124 */ 135 */
125static int pxa27x_ohci_select_pmm(struct pxa27x_ohci *ohci, int mode) 136static int pxa27x_ohci_select_pmm(struct pxa27x_ohci *pxa_ohci, int mode)
126{ 137{
127 uint32_t uhcrhda = __raw_readl(ohci->mmio_base + UHCRHDA); 138 uint32_t uhcrhda = __raw_readl(pxa_ohci->mmio_base + UHCRHDA);
128 uint32_t uhcrhdb = __raw_readl(ohci->mmio_base + UHCRHDB); 139 uint32_t uhcrhdb = __raw_readl(pxa_ohci->mmio_base + UHCRHDB);
129 140
130 switch (mode) { 141 switch (mode) {
131 case PMM_NPS_MODE: 142 case PMM_NPS_MODE:
@@ -149,20 +160,18 @@ static int pxa27x_ohci_select_pmm(struct pxa27x_ohci *ohci, int mode)
149 uhcrhda |= RH_A_NPS; 160 uhcrhda |= RH_A_NPS;
150 } 161 }
151 162
152 __raw_writel(uhcrhda, ohci->mmio_base + UHCRHDA); 163 __raw_writel(uhcrhda, pxa_ohci->mmio_base + UHCRHDA);
153 __raw_writel(uhcrhdb, ohci->mmio_base + UHCRHDB); 164 __raw_writel(uhcrhdb, pxa_ohci->mmio_base + UHCRHDB);
154 return 0; 165 return 0;
155} 166}
156 167
157extern int usb_disabled(void);
158
159/*-------------------------------------------------------------------------*/ 168/*-------------------------------------------------------------------------*/
160 169
161static inline void pxa27x_setup_hc(struct pxa27x_ohci *ohci, 170static inline void pxa27x_setup_hc(struct pxa27x_ohci *pxa_ohci,
162 struct pxaohci_platform_data *inf) 171 struct pxaohci_platform_data *inf)
163{ 172{
164 uint32_t uhchr = __raw_readl(ohci->mmio_base + UHCHR); 173 uint32_t uhchr = __raw_readl(pxa_ohci->mmio_base + UHCHR);
165 uint32_t uhcrhda = __raw_readl(ohci->mmio_base + UHCRHDA); 174 uint32_t uhcrhda = __raw_readl(pxa_ohci->mmio_base + UHCRHDA);
166 175
167 if (inf->flags & ENABLE_PORT1) 176 if (inf->flags & ENABLE_PORT1)
168 uhchr &= ~UHCHR_SSEP1; 177 uhchr &= ~UHCHR_SSEP1;
@@ -194,17 +203,17 @@ static inline void pxa27x_setup_hc(struct pxa27x_ohci *ohci,
194 uhcrhda |= UHCRHDA_POTPGT(inf->power_on_delay / 2); 203 uhcrhda |= UHCRHDA_POTPGT(inf->power_on_delay / 2);
195 } 204 }
196 205
197 __raw_writel(uhchr, ohci->mmio_base + UHCHR); 206 __raw_writel(uhchr, pxa_ohci->mmio_base + UHCHR);
198 __raw_writel(uhcrhda, ohci->mmio_base + UHCRHDA); 207 __raw_writel(uhcrhda, pxa_ohci->mmio_base + UHCRHDA);
199} 208}
200 209
201static inline void pxa27x_reset_hc(struct pxa27x_ohci *ohci) 210static inline void pxa27x_reset_hc(struct pxa27x_ohci *pxa_ohci)
202{ 211{
203 uint32_t uhchr = __raw_readl(ohci->mmio_base + UHCHR); 212 uint32_t uhchr = __raw_readl(pxa_ohci->mmio_base + UHCHR);
204 213
205 __raw_writel(uhchr | UHCHR_FHR, ohci->mmio_base + UHCHR); 214 __raw_writel(uhchr | UHCHR_FHR, pxa_ohci->mmio_base + UHCHR);
206 udelay(11); 215 udelay(11);
207 __raw_writel(uhchr & ~UHCHR_FHR, ohci->mmio_base + UHCHR); 216 __raw_writel(uhchr & ~UHCHR_FHR, pxa_ohci->mmio_base + UHCHR);
208} 217}
209 218
210#ifdef CONFIG_PXA27x 219#ifdef CONFIG_PXA27x
@@ -213,25 +222,26 @@ extern void pxa27x_clear_otgph(void);
213#define pxa27x_clear_otgph() do {} while (0) 222#define pxa27x_clear_otgph() do {} while (0)
214#endif 223#endif
215 224
216static int pxa27x_start_hc(struct pxa27x_ohci *ohci, struct device *dev) 225static int pxa27x_start_hc(struct pxa27x_ohci *pxa_ohci, struct device *dev)
217{ 226{
218 int retval = 0; 227 int retval = 0;
219 struct pxaohci_platform_data *inf; 228 struct pxaohci_platform_data *inf;
220 uint32_t uhchr; 229 uint32_t uhchr;
230 struct usb_hcd *hcd = dev_get_drvdata(dev);
221 231
222 inf = dev_get_platdata(dev); 232 inf = dev_get_platdata(dev);
223 233
224 clk_prepare_enable(ohci->clk); 234 clk_prepare_enable(pxa_ohci->clk);
225 235
226 pxa27x_reset_hc(ohci); 236 pxa27x_reset_hc(pxa_ohci);
227 237
228 uhchr = __raw_readl(ohci->mmio_base + UHCHR) | UHCHR_FSBIR; 238 uhchr = __raw_readl(pxa_ohci->mmio_base + UHCHR) | UHCHR_FSBIR;
229 __raw_writel(uhchr, ohci->mmio_base + UHCHR); 239 __raw_writel(uhchr, pxa_ohci->mmio_base + UHCHR);
230 240
231 while (__raw_readl(ohci->mmio_base + UHCHR) & UHCHR_FSBIR) 241 while (__raw_readl(pxa_ohci->mmio_base + UHCHR) & UHCHR_FSBIR)
232 cpu_relax(); 242 cpu_relax();
233 243
234 pxa27x_setup_hc(ohci, inf); 244 pxa27x_setup_hc(pxa_ohci, inf);
235 245
236 if (inf->init) 246 if (inf->init)
237 retval = inf->init(dev); 247 retval = inf->init(dev);
@@ -240,38 +250,39 @@ static int pxa27x_start_hc(struct pxa27x_ohci *ohci, struct device *dev)
240 return retval; 250 return retval;
241 251
242 if (cpu_is_pxa3xx()) 252 if (cpu_is_pxa3xx())
243 pxa3xx_u2d_start_hc(&ohci_to_hcd(&ohci->ohci)->self); 253 pxa3xx_u2d_start_hc(&hcd->self);
244 254
245 uhchr = __raw_readl(ohci->mmio_base + UHCHR) & ~UHCHR_SSE; 255 uhchr = __raw_readl(pxa_ohci->mmio_base + UHCHR) & ~UHCHR_SSE;
246 __raw_writel(uhchr, ohci->mmio_base + UHCHR); 256 __raw_writel(uhchr, pxa_ohci->mmio_base + UHCHR);
247 __raw_writel(UHCHIE_UPRIE | UHCHIE_RWIE, ohci->mmio_base + UHCHIE); 257 __raw_writel(UHCHIE_UPRIE | UHCHIE_RWIE, pxa_ohci->mmio_base + UHCHIE);
248 258
249 /* Clear any OTG Pin Hold */ 259 /* Clear any OTG Pin Hold */
250 pxa27x_clear_otgph(); 260 pxa27x_clear_otgph();
251 return 0; 261 return 0;
252} 262}
253 263
254static void pxa27x_stop_hc(struct pxa27x_ohci *ohci, struct device *dev) 264static void pxa27x_stop_hc(struct pxa27x_ohci *pxa_ohci, struct device *dev)
255{ 265{
256 struct pxaohci_platform_data *inf; 266 struct pxaohci_platform_data *inf;
267 struct usb_hcd *hcd = dev_get_drvdata(dev);
257 uint32_t uhccoms; 268 uint32_t uhccoms;
258 269
259 inf = dev_get_platdata(dev); 270 inf = dev_get_platdata(dev);
260 271
261 if (cpu_is_pxa3xx()) 272 if (cpu_is_pxa3xx())
262 pxa3xx_u2d_stop_hc(&ohci_to_hcd(&ohci->ohci)->self); 273 pxa3xx_u2d_stop_hc(&hcd->self);
263 274
264 if (inf->exit) 275 if (inf->exit)
265 inf->exit(dev); 276 inf->exit(dev);
266 277
267 pxa27x_reset_hc(ohci); 278 pxa27x_reset_hc(pxa_ohci);
268 279
269 /* Host Controller Reset */ 280 /* Host Controller Reset */
270 uhccoms = __raw_readl(ohci->mmio_base + UHCCOMS) | 0x01; 281 uhccoms = __raw_readl(pxa_ohci->mmio_base + UHCCOMS) | 0x01;
271 __raw_writel(uhccoms, ohci->mmio_base + UHCCOMS); 282 __raw_writel(uhccoms, pxa_ohci->mmio_base + UHCCOMS);
272 udelay(10); 283 udelay(10);
273 284
274 clk_disable_unprepare(ohci->clk); 285 clk_disable_unprepare(pxa_ohci->clk);
275} 286}
276 287
277#ifdef CONFIG_OF 288#ifdef CONFIG_OF
@@ -356,7 +367,8 @@ int usb_hcd_pxa27x_probe (const struct hc_driver *driver, struct platform_device
356 int retval, irq; 367 int retval, irq;
357 struct usb_hcd *hcd; 368 struct usb_hcd *hcd;
358 struct pxaohci_platform_data *inf; 369 struct pxaohci_platform_data *inf;
359 struct pxa27x_ohci *ohci; 370 struct pxa27x_ohci *pxa_ohci;
371 struct ohci_hcd *ohci;
360 struct resource *r; 372 struct resource *r;
361 struct clk *usb_clk; 373 struct clk *usb_clk;
362 374
@@ -409,29 +421,31 @@ int usb_hcd_pxa27x_probe (const struct hc_driver *driver, struct platform_device
409 } 421 }
410 422
411 /* initialize "struct pxa27x_ohci" */ 423 /* initialize "struct pxa27x_ohci" */
412 ohci = (struct pxa27x_ohci *)hcd_to_ohci(hcd); 424 pxa_ohci = to_pxa27x_ohci(hcd);
413 ohci->dev = &pdev->dev; 425 pxa_ohci->clk = usb_clk;
414 ohci->clk = usb_clk; 426 pxa_ohci->mmio_base = (void __iomem *)hcd->regs;
415 ohci->mmio_base = (void __iomem *)hcd->regs;
416 427
417 if ((retval = pxa27x_start_hc(ohci, &pdev->dev)) < 0) { 428 retval = pxa27x_start_hc(pxa_ohci, &pdev->dev);
429 if (retval < 0) {
418 pr_debug("pxa27x_start_hc failed"); 430 pr_debug("pxa27x_start_hc failed");
419 goto err3; 431 goto err3;
420 } 432 }
421 433
422 /* Select Power Management Mode */ 434 /* Select Power Management Mode */
423 pxa27x_ohci_select_pmm(ohci, inf->port_mode); 435 pxa27x_ohci_select_pmm(pxa_ohci, inf->port_mode);
424 436
425 if (inf->power_budget) 437 if (inf->power_budget)
426 hcd->power_budget = inf->power_budget; 438 hcd->power_budget = inf->power_budget;
427 439
428 ohci_hcd_init(hcd_to_ohci(hcd)); 440 /* The value of NDP in roothub_a is incorrect on this hardware */
441 ohci = hcd_to_ohci(hcd);
442 ohci->num_ports = 3;
429 443
430 retval = usb_add_hcd(hcd, irq, 0); 444 retval = usb_add_hcd(hcd, irq, 0);
431 if (retval == 0) 445 if (retval == 0)
432 return retval; 446 return retval;
433 447
434 pxa27x_stop_hc(ohci, &pdev->dev); 448 pxa27x_stop_hc(pxa_ohci, &pdev->dev);
435 err3: 449 err3:
436 iounmap(hcd->regs); 450 iounmap(hcd->regs);
437 err2: 451 err2:
@@ -459,88 +473,18 @@ int usb_hcd_pxa27x_probe (const struct hc_driver *driver, struct platform_device
459 */ 473 */
460void usb_hcd_pxa27x_remove (struct usb_hcd *hcd, struct platform_device *pdev) 474void usb_hcd_pxa27x_remove (struct usb_hcd *hcd, struct platform_device *pdev)
461{ 475{
462 struct pxa27x_ohci *ohci = to_pxa27x_ohci(hcd); 476 struct pxa27x_ohci *pxa_ohci = to_pxa27x_ohci(hcd);
463 477
464 usb_remove_hcd(hcd); 478 usb_remove_hcd(hcd);
465 pxa27x_stop_hc(ohci, &pdev->dev); 479 pxa27x_stop_hc(pxa_ohci, &pdev->dev);
466 iounmap(hcd->regs); 480 iounmap(hcd->regs);
467 release_mem_region(hcd->rsrc_start, hcd->rsrc_len); 481 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
482 clk_put(pxa_ohci->clk);
468 usb_put_hcd(hcd); 483 usb_put_hcd(hcd);
469 clk_put(ohci->clk);
470}
471
472/*-------------------------------------------------------------------------*/
473
474static int
475ohci_pxa27x_start (struct usb_hcd *hcd)
476{
477 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
478 int ret;
479
480 ohci_dbg (ohci, "ohci_pxa27x_start, ohci:%p", ohci);
481
482 /* The value of NDP in roothub_a is incorrect on this hardware */
483 ohci->num_ports = 3;
484
485 if ((ret = ohci_init(ohci)) < 0)
486 return ret;
487
488 if ((ret = ohci_run (ohci)) < 0) {
489 dev_err(hcd->self.controller, "can't start %s",
490 hcd->self.bus_name);
491 ohci_stop (hcd);
492 return ret;
493 }
494
495 return 0;
496} 484}
497 485
498/*-------------------------------------------------------------------------*/ 486/*-------------------------------------------------------------------------*/
499 487
500static const struct hc_driver ohci_pxa27x_hc_driver = {
501 .description = hcd_name,
502 .product_desc = "PXA27x OHCI",
503 .hcd_priv_size = sizeof(struct pxa27x_ohci),
504
505 /*
506 * generic hardware linkage
507 */
508 .irq = ohci_irq,
509 .flags = HCD_USB11 | HCD_MEMORY,
510
511 /*
512 * basic lifecycle operations
513 */
514 .start = ohci_pxa27x_start,
515 .stop = ohci_stop,
516 .shutdown = ohci_shutdown,
517
518 /*
519 * managing i/o requests and associated device resources
520 */
521 .urb_enqueue = ohci_urb_enqueue,
522 .urb_dequeue = ohci_urb_dequeue,
523 .endpoint_disable = ohci_endpoint_disable,
524
525 /*
526 * scheduling support
527 */
528 .get_frame_number = ohci_get_frame,
529
530 /*
531 * root hub support
532 */
533 .hub_status_data = ohci_hub_status_data,
534 .hub_control = ohci_hub_control,
535#ifdef CONFIG_PM
536 .bus_suspend = ohci_bus_suspend,
537 .bus_resume = ohci_bus_resume,
538#endif
539 .start_port_reset = ohci_start_port_reset,
540};
541
542/*-------------------------------------------------------------------------*/
543
544static int ohci_hcd_pxa27x_drv_probe(struct platform_device *pdev) 488static int ohci_hcd_pxa27x_drv_probe(struct platform_device *pdev)
545{ 489{
546 pr_debug ("In ohci_hcd_pxa27x_drv_probe"); 490 pr_debug ("In ohci_hcd_pxa27x_drv_probe");
@@ -563,32 +507,42 @@ static int ohci_hcd_pxa27x_drv_remove(struct platform_device *pdev)
563static int ohci_hcd_pxa27x_drv_suspend(struct device *dev) 507static int ohci_hcd_pxa27x_drv_suspend(struct device *dev)
564{ 508{
565 struct usb_hcd *hcd = dev_get_drvdata(dev); 509 struct usb_hcd *hcd = dev_get_drvdata(dev);
566 struct pxa27x_ohci *ohci = to_pxa27x_ohci(hcd); 510 struct pxa27x_ohci *pxa_ohci = to_pxa27x_ohci(hcd);
511 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
512 bool do_wakeup = device_may_wakeup(dev);
513 int ret;
514
567 515
568 if (time_before(jiffies, ohci->ohci.next_statechange)) 516 if (time_before(jiffies, ohci->next_statechange))
569 msleep(5); 517 msleep(5);
570 ohci->ohci.next_statechange = jiffies; 518 ohci->next_statechange = jiffies;
571 519
572 pxa27x_stop_hc(ohci, dev); 520 ret = ohci_suspend(hcd, do_wakeup);
573 return 0; 521 if (ret)
522 return ret;
523
524 pxa27x_stop_hc(pxa_ohci, dev);
525 return ret;
574} 526}
575 527
576static int ohci_hcd_pxa27x_drv_resume(struct device *dev) 528static int ohci_hcd_pxa27x_drv_resume(struct device *dev)
577{ 529{
578 struct usb_hcd *hcd = dev_get_drvdata(dev); 530 struct usb_hcd *hcd = dev_get_drvdata(dev);
579 struct pxa27x_ohci *ohci = to_pxa27x_ohci(hcd); 531 struct pxa27x_ohci *pxa_ohci = to_pxa27x_ohci(hcd);
580 struct pxaohci_platform_data *inf = dev_get_platdata(dev); 532 struct pxaohci_platform_data *inf = dev_get_platdata(dev);
533 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
581 int status; 534 int status;
582 535
583 if (time_before(jiffies, ohci->ohci.next_statechange)) 536 if (time_before(jiffies, ohci->next_statechange))
584 msleep(5); 537 msleep(5);
585 ohci->ohci.next_statechange = jiffies; 538 ohci->next_statechange = jiffies;
586 539
587 if ((status = pxa27x_start_hc(ohci, dev)) < 0) 540 status = pxa27x_start_hc(pxa_ohci, dev);
541 if (status < 0)
588 return status; 542 return status;
589 543
590 /* Select Power Management Mode */ 544 /* Select Power Management Mode */
591 pxa27x_ohci_select_pmm(ohci, inf->port_mode); 545 pxa27x_ohci_select_pmm(pxa_ohci, inf->port_mode);
592 546
593 ohci_resume(hcd, false); 547 ohci_resume(hcd, false);
594 return 0; 548 return 0;
@@ -600,9 +554,6 @@ static const struct dev_pm_ops ohci_hcd_pxa27x_pm_ops = {
600}; 554};
601#endif 555#endif
602 556
603/* work with hotplug and coldplug */
604MODULE_ALIAS("platform:pxa27x-ohci");
605
606static struct platform_driver ohci_hcd_pxa27x_driver = { 557static struct platform_driver ohci_hcd_pxa27x_driver = {
607 .probe = ohci_hcd_pxa27x_drv_probe, 558 .probe = ohci_hcd_pxa27x_drv_probe,
608 .remove = ohci_hcd_pxa27x_drv_remove, 559 .remove = ohci_hcd_pxa27x_drv_remove,
@@ -617,3 +568,27 @@ static struct platform_driver ohci_hcd_pxa27x_driver = {
617 }, 568 },
618}; 569};
619 570
571static const struct ohci_driver_overrides pxa27x_overrides __initconst = {
572 .extra_priv_size = sizeof(struct pxa27x_ohci),
573};
574
575static int __init ohci_pxa27x_init(void)
576{
577 if (usb_disabled())
578 return -ENODEV;
579
580 pr_info("%s: " DRIVER_DESC "\n", hcd_name);
581 ohci_init_driver(&ohci_pxa27x_hc_driver, &pxa27x_overrides);
582 return platform_driver_register(&ohci_hcd_pxa27x_driver);
583}
584module_init(ohci_pxa27x_init);
585
586static void __exit ohci_pxa27x_cleanup(void)
587{
588 platform_driver_unregister(&ohci_hcd_pxa27x_driver);
589}
590module_exit(ohci_pxa27x_cleanup);
591
592MODULE_DESCRIPTION(DRIVER_DESC);
593MODULE_LICENSE("GPL");
594MODULE_ALIAS("platform:pxa27x-ohci");
diff --git a/drivers/usb/host/ohci-s3c2410.c b/drivers/usb/host/ohci-s3c2410.c
index 4919afa4125e..be3429e08d90 100644
--- a/drivers/usb/host/ohci-s3c2410.c
+++ b/drivers/usb/host/ohci-s3c2410.c
@@ -19,19 +19,36 @@
19 * This file is licenced under the GPL. 19 * This file is licenced under the GPL.
20*/ 20*/
21 21
22#include <linux/platform_device.h>
23#include <linux/clk.h> 22#include <linux/clk.h>
23#include <linux/io.h>
24#include <linux/kernel.h>
25#include <linux/module.h>
26#include <linux/platform_device.h>
24#include <linux/platform_data/usb-ohci-s3c2410.h> 27#include <linux/platform_data/usb-ohci-s3c2410.h>
28#include <linux/usb.h>
29#include <linux/usb/hcd.h>
30
31#include "ohci.h"
32
25 33
26#define valid_port(idx) ((idx) == 1 || (idx) == 2) 34#define valid_port(idx) ((idx) == 1 || (idx) == 2)
27 35
28/* clock device associated with the hcd */ 36/* clock device associated with the hcd */
29 37
38
39#define DRIVER_DESC "OHCI S3C2410 driver"
40
41static const char hcd_name[] = "ohci-s3c2410";
42
30static struct clk *clk; 43static struct clk *clk;
31static struct clk *usb_clk; 44static struct clk *usb_clk;
32 45
33/* forward definitions */ 46/* forward definitions */
34 47
48static int (*orig_ohci_hub_control)(struct usb_hcd *hcd, u16 typeReq,
49 u16 wValue, u16 wIndex, char *buf, u16 wLength);
50static int (*orig_ohci_hub_status_data)(struct usb_hcd *hcd, char *buf);
51
35static void s3c2410_hcd_oc(struct s3c2410_hcd_info *info, int port_oc); 52static void s3c2410_hcd_oc(struct s3c2410_hcd_info *info, int port_oc);
36 53
37/* conversion functions */ 54/* conversion functions */
@@ -93,7 +110,7 @@ ohci_s3c2410_hub_status_data(struct usb_hcd *hcd, char *buf)
93 int orig; 110 int orig;
94 int portno; 111 int portno;
95 112
96 orig = ohci_hub_status_data(hcd, buf); 113 orig = orig_ohci_hub_status_data(hcd, buf);
97 114
98 if (info == NULL) 115 if (info == NULL)
99 return orig; 116 return orig;
@@ -164,7 +181,7 @@ static int ohci_s3c2410_hub_control(
164 * process the request straight away and exit */ 181 * process the request straight away and exit */
165 182
166 if (info == NULL) { 183 if (info == NULL) {
167 ret = ohci_hub_control(hcd, typeReq, wValue, 184 ret = orig_ohci_hub_control(hcd, typeReq, wValue,
168 wIndex, buf, wLength); 185 wIndex, buf, wLength);
169 goto out; 186 goto out;
170 } 187 }
@@ -214,7 +231,7 @@ static int ohci_s3c2410_hub_control(
214 break; 231 break;
215 } 232 }
216 233
217 ret = ohci_hub_control(hcd, typeReq, wValue, wIndex, buf, wLength); 234 ret = orig_ohci_hub_control(hcd, typeReq, wValue, wIndex, buf, wLength);
218 if (ret) 235 if (ret)
219 goto out; 236 goto out;
220 237
@@ -374,8 +391,6 @@ static int usb_hcd_s3c2410_probe(const struct hc_driver *driver,
374 391
375 s3c2410_start_hc(dev, hcd); 392 s3c2410_start_hc(dev, hcd);
376 393
377 ohci_hcd_init(hcd_to_ohci(hcd));
378
379 retval = usb_add_hcd(hcd, dev->resource[1].start, 0); 394 retval = usb_add_hcd(hcd, dev->resource[1].start, 0);
380 if (retval != 0) 395 if (retval != 0)
381 goto err_ioremap; 396 goto err_ioremap;
@@ -392,71 +407,7 @@ static int usb_hcd_s3c2410_probe(const struct hc_driver *driver,
392 407
393/*-------------------------------------------------------------------------*/ 408/*-------------------------------------------------------------------------*/
394 409
395static int 410static struct hc_driver __read_mostly ohci_s3c2410_hc_driver;
396ohci_s3c2410_start(struct usb_hcd *hcd)
397{
398 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
399 int ret;
400
401 ret = ohci_init(ohci);
402 if (ret < 0)
403 return ret;
404
405 ret = ohci_run(ohci);
406 if (ret < 0) {
407 dev_err(hcd->self.controller, "can't start %s\n",
408 hcd->self.bus_name);
409 ohci_stop(hcd);
410 return ret;
411 }
412
413 return 0;
414}
415
416
417static const struct hc_driver ohci_s3c2410_hc_driver = {
418 .description = hcd_name,
419 .product_desc = "S3C24XX OHCI",
420 .hcd_priv_size = sizeof(struct ohci_hcd),
421
422 /*
423 * generic hardware linkage
424 */
425 .irq = ohci_irq,
426 .flags = HCD_USB11 | HCD_MEMORY,
427
428 /*
429 * basic lifecycle operations
430 */
431 .start = ohci_s3c2410_start,
432 .stop = ohci_stop,
433 .shutdown = ohci_shutdown,
434
435 /*
436 * managing i/o requests and associated device resources
437 */
438 .urb_enqueue = ohci_urb_enqueue,
439 .urb_dequeue = ohci_urb_dequeue,
440 .endpoint_disable = ohci_endpoint_disable,
441
442 /*
443 * scheduling support
444 */
445 .get_frame_number = ohci_get_frame,
446
447 /*
448 * root hub support
449 */
450 .hub_status_data = ohci_s3c2410_hub_status_data,
451 .hub_control = ohci_s3c2410_hub_control,
452#ifdef CONFIG_PM
453 .bus_suspend = ohci_bus_suspend,
454 .bus_resume = ohci_bus_resume,
455#endif
456 .start_port_reset = ohci_start_port_reset,
457};
458
459/* device driver */
460 411
461static int ohci_hcd_s3c2410_drv_probe(struct platform_device *pdev) 412static int ohci_hcd_s3c2410_drv_probe(struct platform_device *pdev)
462{ 413{
@@ -533,4 +484,39 @@ static struct platform_driver ohci_hcd_s3c2410_driver = {
533 }, 484 },
534}; 485};
535 486
487static int __init ohci_s3c2410_init(void)
488{
489 if (usb_disabled())
490 return -ENODEV;
491
492 pr_info("%s: " DRIVER_DESC "\n", hcd_name);
493 ohci_init_driver(&ohci_s3c2410_hc_driver, NULL);
494
495 /*
496 * The Samsung HW has some unusual quirks, which require
497 * Sumsung-specific workarounds. We override certain hc_driver
498 * functions here to achieve that. We explicitly do not enhance
499 * ohci_driver_overrides to allow this more easily, since this
500 * is an unusual case, and we don't want to encourage others to
501 * override these functions by making it too easy.
502 */
503
504 orig_ohci_hub_control = ohci_s3c2410_hc_driver.hub_control;
505 orig_ohci_hub_status_data = ohci_s3c2410_hc_driver.hub_status_data;
506
507 ohci_s3c2410_hc_driver.hub_status_data = ohci_s3c2410_hub_status_data;
508 ohci_s3c2410_hc_driver.hub_control = ohci_s3c2410_hub_control;
509
510 return platform_driver_register(&ohci_hcd_s3c2410_driver);
511}
512module_init(ohci_s3c2410_init);
513
514static void __exit ohci_s3c2410_cleanup(void)
515{
516 platform_driver_unregister(&ohci_hcd_s3c2410_driver);
517}
518module_exit(ohci_s3c2410_cleanup);
519
520MODULE_DESCRIPTION(DRIVER_DESC);
521MODULE_LICENSE("GPL");
536MODULE_ALIAS("platform:s3c2410-ohci"); 522MODULE_ALIAS("platform:s3c2410-ohci");
diff --git a/drivers/usb/host/ohci-sm501.c b/drivers/usb/host/ohci-sm501.c
index d479d5ddab88..2a5de5fecd8f 100644
--- a/drivers/usb/host/ohci-sm501.c
+++ b/drivers/usb/host/ohci-sm501.c
@@ -216,14 +216,21 @@ static int ohci_hcd_sm501_drv_remove(struct platform_device *pdev)
216static int ohci_sm501_suspend(struct platform_device *pdev, pm_message_t msg) 216static int ohci_sm501_suspend(struct platform_device *pdev, pm_message_t msg)
217{ 217{
218 struct device *dev = &pdev->dev; 218 struct device *dev = &pdev->dev;
219 struct ohci_hcd *ohci = hcd_to_ohci(platform_get_drvdata(pdev)); 219 struct usb_hcd *hcd = platform_get_drvdata(pdev);
220 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
221 bool do_wakeup = device_may_wakeup(dev);
222 int ret;
220 223
221 if (time_before(jiffies, ohci->next_statechange)) 224 if (time_before(jiffies, ohci->next_statechange))
222 msleep(5); 225 msleep(5);
223 ohci->next_statechange = jiffies; 226 ohci->next_statechange = jiffies;
224 227
228 ret = ohci_suspend(hcd, do_wakeup);
229 if (ret)
230 return ret;
231
225 sm501_unit_power(dev->parent, SM501_GATE_USB_HOST, 0); 232 sm501_unit_power(dev->parent, SM501_GATE_USB_HOST, 0);
226 return 0; 233 return ret;
227} 234}
228 235
229static int ohci_sm501_resume(struct platform_device *pdev) 236static int ohci_sm501_resume(struct platform_device *pdev)
diff --git a/drivers/usb/host/ohci-spear.c b/drivers/usb/host/ohci-spear.c
index cc9dd9e4f05e..31ff3fc4e26f 100644
--- a/drivers/usb/host/ohci-spear.c
+++ b/drivers/usb/host/ohci-spear.c
@@ -11,92 +11,37 @@
11* warranty of any kind, whether express or implied. 11* warranty of any kind, whether express or implied.
12*/ 12*/
13 13
14#include <linux/signal.h>
15#include <linux/platform_device.h>
16#include <linux/clk.h> 14#include <linux/clk.h>
15#include <linux/dma-mapping.h>
16#include <linux/io.h>
17#include <linux/kernel.h>
18#include <linux/module.h>
17#include <linux/of.h> 19#include <linux/of.h>
20#include <linux/platform_device.h>
21#include <linux/signal.h>
22#include <linux/usb.h>
23#include <linux/usb/hcd.h>
24
25#include "ohci.h"
18 26
27#define DRIVER_DESC "OHCI SPEAr driver"
28
29static const char hcd_name[] = "SPEAr-ohci";
19struct spear_ohci { 30struct spear_ohci {
20 struct ohci_hcd ohci;
21 struct clk *clk; 31 struct clk *clk;
22}; 32};
23 33
24#define to_spear_ohci(hcd) (struct spear_ohci *)hcd_to_ohci(hcd) 34#define to_spear_ohci(hcd) (struct spear_ohci *)(hcd_to_ohci(hcd)->priv)
25
26static void spear_start_ohci(struct spear_ohci *ohci)
27{
28 clk_prepare_enable(ohci->clk);
29}
30
31static void spear_stop_ohci(struct spear_ohci *ohci)
32{
33 clk_disable_unprepare(ohci->clk);
34}
35
36static int ohci_spear_start(struct usb_hcd *hcd)
37{
38 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
39 int ret;
40
41 ret = ohci_init(ohci);
42 if (ret < 0)
43 return ret;
44 ohci->regs = hcd->regs;
45
46 ret = ohci_run(ohci);
47 if (ret < 0) {
48 dev_err(hcd->self.controller, "can't start\n");
49 ohci_stop(hcd);
50 return ret;
51 }
52
53 create_debug_files(ohci);
54
55#ifdef DEBUG
56 ohci_dump(ohci, 1);
57#endif
58 return 0;
59}
60
61static const struct hc_driver ohci_spear_hc_driver = {
62 .description = hcd_name,
63 .product_desc = "SPEAr OHCI",
64 .hcd_priv_size = sizeof(struct spear_ohci),
65
66 /* generic hardware linkage */
67 .irq = ohci_irq,
68 .flags = HCD_USB11 | HCD_MEMORY,
69
70 /* basic lifecycle operations */
71 .start = ohci_spear_start,
72 .stop = ohci_stop,
73 .shutdown = ohci_shutdown,
74#ifdef CONFIG_PM
75 .bus_suspend = ohci_bus_suspend,
76 .bus_resume = ohci_bus_resume,
77#endif
78
79 /* managing i/o requests and associated device resources */
80 .urb_enqueue = ohci_urb_enqueue,
81 .urb_dequeue = ohci_urb_dequeue,
82 .endpoint_disable = ohci_endpoint_disable,
83
84 /* scheduling support */
85 .get_frame_number = ohci_get_frame,
86 35
87 /* root hub support */ 36static struct hc_driver __read_mostly ohci_spear_hc_driver;
88 .hub_status_data = ohci_hub_status_data,
89 .hub_control = ohci_hub_control,
90
91 .start_port_reset = ohci_start_port_reset,
92};
93 37
94static int spear_ohci_hcd_drv_probe(struct platform_device *pdev) 38static int spear_ohci_hcd_drv_probe(struct platform_device *pdev)
95{ 39{
96 const struct hc_driver *driver = &ohci_spear_hc_driver; 40 const struct hc_driver *driver = &ohci_spear_hc_driver;
41 struct ohci_hcd *ohci;
97 struct usb_hcd *hcd = NULL; 42 struct usb_hcd *hcd = NULL;
98 struct clk *usbh_clk; 43 struct clk *usbh_clk;
99 struct spear_ohci *ohci_p; 44 struct spear_ohci *sohci_p;
100 struct resource *res; 45 struct resource *res;
101 int retval, irq; 46 int retval, irq;
102 47
@@ -151,16 +96,18 @@ static int spear_ohci_hcd_drv_probe(struct platform_device *pdev)
151 goto err_put_hcd; 96 goto err_put_hcd;
152 } 97 }
153 98
154 ohci_p = (struct spear_ohci *)hcd_to_ohci(hcd); 99 sohci_p = to_spear_ohci(hcd);
155 ohci_p->clk = usbh_clk; 100 sohci_p->clk = usbh_clk;
156 spear_start_ohci(ohci_p); 101
157 ohci_hcd_init(hcd_to_ohci(hcd)); 102 clk_prepare_enable(sohci_p->clk);
103
104 ohci = hcd_to_ohci(hcd);
158 105
159 retval = usb_add_hcd(hcd, platform_get_irq(pdev, 0), 0); 106 retval = usb_add_hcd(hcd, platform_get_irq(pdev, 0), 0);
160 if (retval == 0) 107 if (retval == 0)
161 return retval; 108 return retval;
162 109
163 spear_stop_ohci(ohci_p); 110 clk_disable_unprepare(sohci_p->clk);
164err_put_hcd: 111err_put_hcd:
165 usb_put_hcd(hcd); 112 usb_put_hcd(hcd);
166fail: 113fail:
@@ -172,11 +119,11 @@ fail:
172static int spear_ohci_hcd_drv_remove(struct platform_device *pdev) 119static int spear_ohci_hcd_drv_remove(struct platform_device *pdev)
173{ 120{
174 struct usb_hcd *hcd = platform_get_drvdata(pdev); 121 struct usb_hcd *hcd = platform_get_drvdata(pdev);
175 struct spear_ohci *ohci_p = to_spear_ohci(hcd); 122 struct spear_ohci *sohci_p = to_spear_ohci(hcd);
176 123
177 usb_remove_hcd(hcd); 124 usb_remove_hcd(hcd);
178 if (ohci_p->clk) 125 if (sohci_p->clk)
179 spear_stop_ohci(ohci_p); 126 clk_disable_unprepare(sohci_p->clk);
180 127
181 usb_put_hcd(hcd); 128 usb_put_hcd(hcd);
182 return 0; 129 return 0;
@@ -188,13 +135,14 @@ static int spear_ohci_hcd_drv_suspend(struct platform_device *dev,
188{ 135{
189 struct usb_hcd *hcd = platform_get_drvdata(dev); 136 struct usb_hcd *hcd = platform_get_drvdata(dev);
190 struct ohci_hcd *ohci = hcd_to_ohci(hcd); 137 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
191 struct spear_ohci *ohci_p = to_spear_ohci(hcd); 138 struct spear_ohci *sohci_p = to_spear_ohci(hcd);
192 139
193 if (time_before(jiffies, ohci->next_statechange)) 140 if (time_before(jiffies, ohci->next_statechange))
194 msleep(5); 141 msleep(5);
195 ohci->next_statechange = jiffies; 142 ohci->next_statechange = jiffies;
196 143
197 spear_stop_ohci(ohci_p); 144 clk_disable_unprepare(sohci_p->clk);
145
198 return 0; 146 return 0;
199} 147}
200 148
@@ -202,13 +150,13 @@ static int spear_ohci_hcd_drv_resume(struct platform_device *dev)
202{ 150{
203 struct usb_hcd *hcd = platform_get_drvdata(dev); 151 struct usb_hcd *hcd = platform_get_drvdata(dev);
204 struct ohci_hcd *ohci = hcd_to_ohci(hcd); 152 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
205 struct spear_ohci *ohci_p = to_spear_ohci(hcd); 153 struct spear_ohci *sohci_p = to_spear_ohci(hcd);
206 154
207 if (time_before(jiffies, ohci->next_statechange)) 155 if (time_before(jiffies, ohci->next_statechange))
208 msleep(5); 156 msleep(5);
209 ohci->next_statechange = jiffies; 157 ohci->next_statechange = jiffies;
210 158
211 spear_start_ohci(ohci_p); 159 clk_prepare_enable(sohci_p->clk);
212 ohci_resume(hcd, false); 160 ohci_resume(hcd, false);
213 return 0; 161 return 0;
214} 162}
@@ -234,4 +182,28 @@ static struct platform_driver spear_ohci_hcd_driver = {
234 }, 182 },
235}; 183};
236 184
185static const struct ohci_driver_overrides spear_overrides __initconst = {
186 .extra_priv_size = sizeof(struct spear_ohci),
187};
188static int __init ohci_spear_init(void)
189{
190 if (usb_disabled())
191 return -ENODEV;
192
193 pr_info("%s: " DRIVER_DESC "\n", hcd_name);
194
195 ohci_init_driver(&ohci_spear_hc_driver, &spear_overrides);
196 return platform_driver_register(&spear_ohci_hcd_driver);
197}
198module_init(ohci_spear_init);
199
200static void __exit ohci_spear_cleanup(void)
201{
202 platform_driver_unregister(&spear_ohci_hcd_driver);
203}
204module_exit(ohci_spear_cleanup);
205
206MODULE_DESCRIPTION(DRIVER_DESC);
207MODULE_AUTHOR("Deepak Sikri");
208MODULE_LICENSE("GPL v2");
237MODULE_ALIAS("platform:spear-ohci"); 209MODULE_ALIAS("platform:spear-ohci");
diff --git a/drivers/usb/host/pci-quirks.c b/drivers/usb/host/pci-quirks.c
index 08ef2829a7e2..dfbdd3aefe98 100644
--- a/drivers/usb/host/pci-quirks.c
+++ b/drivers/usb/host/pci-quirks.c
@@ -79,11 +79,30 @@
79#define USB_INTEL_USB3_PSSEN 0xD8 79#define USB_INTEL_USB3_PSSEN 0xD8
80#define USB_INTEL_USB3PRM 0xDC 80#define USB_INTEL_USB3PRM 0xDC
81 81
82/*
83 * amd_chipset_gen values represent AMD different chipset generations
84 */
85enum amd_chipset_gen {
86 NOT_AMD_CHIPSET = 0,
87 AMD_CHIPSET_SB600,
88 AMD_CHIPSET_SB700,
89 AMD_CHIPSET_SB800,
90 AMD_CHIPSET_HUDSON2,
91 AMD_CHIPSET_BOLTON,
92 AMD_CHIPSET_YANGTZE,
93 AMD_CHIPSET_UNKNOWN,
94};
95
96struct amd_chipset_type {
97 enum amd_chipset_gen gen;
98 u8 rev;
99};
100
82static struct amd_chipset_info { 101static struct amd_chipset_info {
83 struct pci_dev *nb_dev; 102 struct pci_dev *nb_dev;
84 struct pci_dev *smbus_dev; 103 struct pci_dev *smbus_dev;
85 int nb_type; 104 int nb_type;
86 int sb_type; 105 struct amd_chipset_type sb_type;
87 int isoc_reqs; 106 int isoc_reqs;
88 int probe_count; 107 int probe_count;
89 int probe_result; 108 int probe_result;
@@ -91,6 +110,51 @@ static struct amd_chipset_info {
91 110
92static DEFINE_SPINLOCK(amd_lock); 111static DEFINE_SPINLOCK(amd_lock);
93 112
113/*
114 * amd_chipset_sb_type_init - initialize amd chipset southbridge type
115 *
116 * AMD FCH/SB generation and revision is identified by SMBus controller
117 * vendor, device and revision IDs.
118 *
119 * Returns: 1 if it is an AMD chipset, 0 otherwise.
120 */
121static int amd_chipset_sb_type_init(struct amd_chipset_info *pinfo)
122{
123 u8 rev = 0;
124 pinfo->sb_type.gen = AMD_CHIPSET_UNKNOWN;
125
126 pinfo->smbus_dev = pci_get_device(PCI_VENDOR_ID_ATI,
127 PCI_DEVICE_ID_ATI_SBX00_SMBUS, NULL);
128 if (pinfo->smbus_dev) {
129 rev = pinfo->smbus_dev->revision;
130 if (rev >= 0x10 && rev <= 0x1f)
131 pinfo->sb_type.gen = AMD_CHIPSET_SB600;
132 else if (rev >= 0x30 && rev <= 0x3f)
133 pinfo->sb_type.gen = AMD_CHIPSET_SB700;
134 else if (rev >= 0x40 && rev <= 0x4f)
135 pinfo->sb_type.gen = AMD_CHIPSET_SB800;
136 } else {
137 pinfo->smbus_dev = pci_get_device(PCI_VENDOR_ID_AMD,
138 PCI_DEVICE_ID_AMD_HUDSON2_SMBUS, NULL);
139
140 if (!pinfo->smbus_dev) {
141 pinfo->sb_type.gen = NOT_AMD_CHIPSET;
142 return 0;
143 }
144
145 rev = pinfo->smbus_dev->revision;
146 if (rev >= 0x11 && rev <= 0x14)
147 pinfo->sb_type.gen = AMD_CHIPSET_HUDSON2;
148 else if (rev >= 0x15 && rev <= 0x18)
149 pinfo->sb_type.gen = AMD_CHIPSET_BOLTON;
150 else if (rev >= 0x39 && rev <= 0x3a)
151 pinfo->sb_type.gen = AMD_CHIPSET_YANGTZE;
152 }
153
154 pinfo->sb_type.rev = rev;
155 return 1;
156}
157
94void sb800_prefetch(struct device *dev, int on) 158void sb800_prefetch(struct device *dev, int on)
95{ 159{
96 u16 misc; 160 u16 misc;
@@ -106,7 +170,6 @@ EXPORT_SYMBOL_GPL(sb800_prefetch);
106 170
107int usb_amd_find_chipset_info(void) 171int usb_amd_find_chipset_info(void)
108{ 172{
109 u8 rev = 0;
110 unsigned long flags; 173 unsigned long flags;
111 struct amd_chipset_info info; 174 struct amd_chipset_info info;
112 int ret; 175 int ret;
@@ -122,27 +185,17 @@ int usb_amd_find_chipset_info(void)
122 memset(&info, 0, sizeof(info)); 185 memset(&info, 0, sizeof(info));
123 spin_unlock_irqrestore(&amd_lock, flags); 186 spin_unlock_irqrestore(&amd_lock, flags);
124 187
125 info.smbus_dev = pci_get_device(PCI_VENDOR_ID_ATI, 0x4385, NULL); 188 if (!amd_chipset_sb_type_init(&info)) {
126 if (info.smbus_dev) { 189 ret = 0;
127 rev = info.smbus_dev->revision; 190 goto commit;
128 if (rev >= 0x40)
129 info.sb_type = 1;
130 else if (rev >= 0x30 && rev <= 0x3b)
131 info.sb_type = 3;
132 } else {
133 info.smbus_dev = pci_get_device(PCI_VENDOR_ID_AMD,
134 0x780b, NULL);
135 if (!info.smbus_dev) {
136 ret = 0;
137 goto commit;
138 }
139
140 rev = info.smbus_dev->revision;
141 if (rev >= 0x11 && rev <= 0x18)
142 info.sb_type = 2;
143 } 191 }
144 192
145 if (info.sb_type == 0) { 193 /* Below chipset generations needn't enable AMD PLL quirk */
194 if (info.sb_type.gen == AMD_CHIPSET_UNKNOWN ||
195 info.sb_type.gen == AMD_CHIPSET_SB600 ||
196 info.sb_type.gen == AMD_CHIPSET_YANGTZE ||
197 (info.sb_type.gen == AMD_CHIPSET_SB700 &&
198 info.sb_type.rev > 0x3b)) {
146 if (info.smbus_dev) { 199 if (info.smbus_dev) {
147 pci_dev_put(info.smbus_dev); 200 pci_dev_put(info.smbus_dev);
148 info.smbus_dev = NULL; 201 info.smbus_dev = NULL;
@@ -197,6 +250,39 @@ commit:
197} 250}
198EXPORT_SYMBOL_GPL(usb_amd_find_chipset_info); 251EXPORT_SYMBOL_GPL(usb_amd_find_chipset_info);
199 252
253int usb_hcd_amd_remote_wakeup_quirk(struct pci_dev *pdev)
254{
255 /* Make sure amd chipset type has already been initialized */
256 usb_amd_find_chipset_info();
257 if (amd_chipset.sb_type.gen != AMD_CHIPSET_YANGTZE)
258 return 0;
259
260 dev_dbg(&pdev->dev, "QUIRK: Enable AMD remote wakeup fix\n");
261 return 1;
262}
263EXPORT_SYMBOL_GPL(usb_hcd_amd_remote_wakeup_quirk);
264
265bool usb_amd_hang_symptom_quirk(void)
266{
267 u8 rev;
268
269 usb_amd_find_chipset_info();
270 rev = amd_chipset.sb_type.rev;
271 /* SB600 and old version of SB700 have hang symptom bug */
272 return amd_chipset.sb_type.gen == AMD_CHIPSET_SB600 ||
273 (amd_chipset.sb_type.gen == AMD_CHIPSET_SB700 &&
274 rev >= 0x3a && rev <= 0x3b);
275}
276EXPORT_SYMBOL_GPL(usb_amd_hang_symptom_quirk);
277
278bool usb_amd_prefetch_quirk(void)
279{
280 usb_amd_find_chipset_info();
281 /* SB800 needs pre-fetch fix */
282 return amd_chipset.sb_type.gen == AMD_CHIPSET_SB800;
283}
284EXPORT_SYMBOL_GPL(usb_amd_prefetch_quirk);
285
200/* 286/*
201 * The hardware normally enables the A-link power management feature, which 287 * The hardware normally enables the A-link power management feature, which
202 * lets the system lower the power consumption in idle states. 288 * lets the system lower the power consumption in idle states.
@@ -229,7 +315,9 @@ static void usb_amd_quirk_pll(int disable)
229 } 315 }
230 } 316 }
231 317
232 if (amd_chipset.sb_type == 1 || amd_chipset.sb_type == 2) { 318 if (amd_chipset.sb_type.gen == AMD_CHIPSET_SB800 ||
319 amd_chipset.sb_type.gen == AMD_CHIPSET_HUDSON2 ||
320 amd_chipset.sb_type.gen == AMD_CHIPSET_BOLTON) {
233 outb_p(AB_REG_BAR_LOW, 0xcd6); 321 outb_p(AB_REG_BAR_LOW, 0xcd6);
234 addr_low = inb_p(0xcd7); 322 addr_low = inb_p(0xcd7);
235 outb_p(AB_REG_BAR_HIGH, 0xcd6); 323 outb_p(AB_REG_BAR_HIGH, 0xcd6);
@@ -240,7 +328,8 @@ static void usb_amd_quirk_pll(int disable)
240 outl_p(0x40, AB_DATA(addr)); 328 outl_p(0x40, AB_DATA(addr));
241 outl_p(0x34, AB_INDX(addr)); 329 outl_p(0x34, AB_INDX(addr));
242 val = inl_p(AB_DATA(addr)); 330 val = inl_p(AB_DATA(addr));
243 } else if (amd_chipset.sb_type == 3) { 331 } else if (amd_chipset.sb_type.gen == AMD_CHIPSET_SB700 &&
332 amd_chipset.sb_type.rev <= 0x3b) {
244 pci_read_config_dword(amd_chipset.smbus_dev, 333 pci_read_config_dword(amd_chipset.smbus_dev,
245 AB_REG_BAR_SB700, &addr); 334 AB_REG_BAR_SB700, &addr);
246 outl(AX_INDXC, AB_INDX(addr)); 335 outl(AX_INDXC, AB_INDX(addr));
@@ -353,7 +442,7 @@ void usb_amd_dev_put(void)
353 amd_chipset.nb_dev = NULL; 442 amd_chipset.nb_dev = NULL;
354 amd_chipset.smbus_dev = NULL; 443 amd_chipset.smbus_dev = NULL;
355 amd_chipset.nb_type = 0; 444 amd_chipset.nb_type = 0;
356 amd_chipset.sb_type = 0; 445 memset(&amd_chipset.sb_type, 0, sizeof(amd_chipset.sb_type));
357 amd_chipset.isoc_reqs = 0; 446 amd_chipset.isoc_reqs = 0;
358 amd_chipset.probe_result = 0; 447 amd_chipset.probe_result = 0;
359 448
diff --git a/drivers/usb/host/pci-quirks.h b/drivers/usb/host/pci-quirks.h
index ed6700d00fe6..638e88f7a28b 100644
--- a/drivers/usb/host/pci-quirks.h
+++ b/drivers/usb/host/pci-quirks.h
@@ -5,6 +5,8 @@
5void uhci_reset_hc(struct pci_dev *pdev, unsigned long base); 5void uhci_reset_hc(struct pci_dev *pdev, unsigned long base);
6int uhci_check_and_reset_hc(struct pci_dev *pdev, unsigned long base); 6int uhci_check_and_reset_hc(struct pci_dev *pdev, unsigned long base);
7int usb_amd_find_chipset_info(void); 7int usb_amd_find_chipset_info(void);
8bool usb_amd_hang_symptom_quirk(void);
9bool usb_amd_prefetch_quirk(void);
8void usb_amd_dev_put(void); 10void usb_amd_dev_put(void);
9void usb_amd_quirk_pll_disable(void); 11void usb_amd_quirk_pll_disable(void);
10void usb_amd_quirk_pll_enable(void); 12void usb_amd_quirk_pll_enable(void);
diff --git a/drivers/usb/host/sl811-hcd.c b/drivers/usb/host/sl811-hcd.c
index 5477bf5df218..79620c39217e 100644
--- a/drivers/usb/host/sl811-hcd.c
+++ b/drivers/usb/host/sl811-hcd.c
@@ -1413,7 +1413,7 @@ static int sl811h_show(struct seq_file *s, void *unused)
1413 case SL11H_CTL1MASK_SE0: s = " se0/reset"; break; 1413 case SL11H_CTL1MASK_SE0: s = " se0/reset"; break;
1414 case SL11H_CTL1MASK_K: s = " k/resume"; break; 1414 case SL11H_CTL1MASK_K: s = " k/resume"; break;
1415 default: s = "j"; break; 1415 default: s = "j"; break;
1416 }; s; }), 1416 } s; }),
1417 (t & SL11H_CTL1MASK_LSPD) ? " lowspeed" : "", 1417 (t & SL11H_CTL1MASK_LSPD) ? " lowspeed" : "",
1418 (t & SL11H_CTL1MASK_SUSPEND) ? " suspend" : ""); 1418 (t & SL11H_CTL1MASK_SUSPEND) ? " suspend" : "");
1419 1419
@@ -1446,7 +1446,7 @@ static int sl811h_show(struct seq_file *s, void *unused)
1446 case USB_PID_SETUP: s = "setup"; break; 1446 case USB_PID_SETUP: s = "setup"; break;
1447 case USB_PID_ACK: s = "status"; break; 1447 case USB_PID_ACK: s = "status"; break;
1448 default: s = "?"; break; 1448 default: s = "?"; break;
1449 }; s;}), 1449 } s;}),
1450 ep->maxpacket, 1450 ep->maxpacket,
1451 ep->nak_count, ep->error_count); 1451 ep->nak_count, ep->error_count);
1452 list_for_each_entry (urb, &ep->hep->urb_list, urb_list) { 1452 list_for_each_entry (urb, &ep->hep->urb_list, urb_list) {
diff --git a/drivers/usb/host/uhci-debug.c b/drivers/usb/host/uhci-debug.c
index 455737546525..8e239cdd95d5 100644
--- a/drivers/usb/host/uhci-debug.c
+++ b/drivers/usb/host/uhci-debug.c
@@ -310,14 +310,14 @@ static int uhci_show_status(struct uhci_hcd *uhci, char *buf, int len)
310 unsigned short portsc1, portsc2; 310 unsigned short portsc1, portsc2;
311 311
312 312
313 usbcmd = uhci_readw(uhci, 0); 313 usbcmd = uhci_readw(uhci, USBCMD);
314 usbstat = uhci_readw(uhci, 2); 314 usbstat = uhci_readw(uhci, USBSTS);
315 usbint = uhci_readw(uhci, 4); 315 usbint = uhci_readw(uhci, USBINTR);
316 usbfrnum = uhci_readw(uhci, 6); 316 usbfrnum = uhci_readw(uhci, USBFRNUM);
317 flbaseadd = uhci_readl(uhci, 8); 317 flbaseadd = uhci_readl(uhci, USBFLBASEADD);
318 sof = uhci_readb(uhci, 12); 318 sof = uhci_readb(uhci, USBSOF);
319 portsc1 = uhci_readw(uhci, 16); 319 portsc1 = uhci_readw(uhci, USBPORTSC1);
320 portsc2 = uhci_readw(uhci, 18); 320 portsc2 = uhci_readw(uhci, USBPORTSC2);
321 321
322 out += sprintf(out, " usbcmd = %04x %s%s%s%s%s%s%s%s\n", 322 out += sprintf(out, " usbcmd = %04x %s%s%s%s%s%s%s%s\n",
323 usbcmd, 323 usbcmd,
diff --git a/drivers/usb/host/uhci-hub.c b/drivers/usb/host/uhci-hub.c
index 9189bc984c98..93e17b12fb33 100644
--- a/drivers/usb/host/uhci-hub.c
+++ b/drivers/usb/host/uhci-hub.c
@@ -75,8 +75,6 @@ static inline int get_hub_status_data(struct uhci_hcd *uhci, char *buf)
75 return !!*buf; 75 return !!*buf;
76} 76}
77 77
78#define OK(x) len = (x); break
79
80#define CLR_RH_PORTSTAT(x) \ 78#define CLR_RH_PORTSTAT(x) \
81 status = uhci_readw(uhci, port_addr); \ 79 status = uhci_readw(uhci, port_addr); \
82 status &= ~(RWC_BITS|WZ_BITS); \ 80 status &= ~(RWC_BITS|WZ_BITS); \
@@ -244,7 +242,7 @@ static int uhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
244 u16 wIndex, char *buf, u16 wLength) 242 u16 wIndex, char *buf, u16 wLength)
245{ 243{
246 struct uhci_hcd *uhci = hcd_to_uhci(hcd); 244 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
247 int status, lstatus, retval = 0, len = 0; 245 int status, lstatus, retval = 0;
248 unsigned int port = wIndex - 1; 246 unsigned int port = wIndex - 1;
249 unsigned long port_addr = USBPORTSC1 + 2 * port; 247 unsigned long port_addr = USBPORTSC1 + 2 * port;
250 u16 wPortChange, wPortStatus; 248 u16 wPortChange, wPortStatus;
@@ -258,7 +256,8 @@ static int uhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
258 256
259 case GetHubStatus: 257 case GetHubStatus:
260 *(__le32 *)buf = cpu_to_le32(0); 258 *(__le32 *)buf = cpu_to_le32(0);
261 OK(4); /* hub power */ 259 retval = 4; /* hub power */
260 break;
262 case GetPortStatus: 261 case GetPortStatus:
263 if (port >= uhci->rh_numports) 262 if (port >= uhci->rh_numports)
264 goto err; 263 goto err;
@@ -311,13 +310,14 @@ static int uhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
311 310
312 *(__le16 *)buf = cpu_to_le16(wPortStatus); 311 *(__le16 *)buf = cpu_to_le16(wPortStatus);
313 *(__le16 *)(buf + 2) = cpu_to_le16(wPortChange); 312 *(__le16 *)(buf + 2) = cpu_to_le16(wPortChange);
314 OK(4); 313 retval = 4;
314 break;
315 case SetHubFeature: /* We don't implement these */ 315 case SetHubFeature: /* We don't implement these */
316 case ClearHubFeature: 316 case ClearHubFeature:
317 switch (wValue) { 317 switch (wValue) {
318 case C_HUB_OVER_CURRENT: 318 case C_HUB_OVER_CURRENT:
319 case C_HUB_LOCAL_POWER: 319 case C_HUB_LOCAL_POWER:
320 OK(0); 320 break;
321 default: 321 default:
322 goto err; 322 goto err;
323 } 323 }
@@ -329,7 +329,7 @@ static int uhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
329 switch (wValue) { 329 switch (wValue) {
330 case USB_PORT_FEAT_SUSPEND: 330 case USB_PORT_FEAT_SUSPEND:
331 SET_RH_PORTSTAT(USBPORTSC_SUSP); 331 SET_RH_PORTSTAT(USBPORTSC_SUSP);
332 OK(0); 332 break;
333 case USB_PORT_FEAT_RESET: 333 case USB_PORT_FEAT_RESET:
334 SET_RH_PORTSTAT(USBPORTSC_PR); 334 SET_RH_PORTSTAT(USBPORTSC_PR);
335 335
@@ -338,10 +338,10 @@ static int uhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
338 338
339 /* USB v2.0 7.1.7.5 */ 339 /* USB v2.0 7.1.7.5 */
340 uhci->ports_timeout = jiffies + msecs_to_jiffies(50); 340 uhci->ports_timeout = jiffies + msecs_to_jiffies(50);
341 OK(0); 341 break;
342 case USB_PORT_FEAT_POWER: 342 case USB_PORT_FEAT_POWER:
343 /* UHCI has no power switching */ 343 /* UHCI has no power switching */
344 OK(0); 344 break;
345 default: 345 default:
346 goto err; 346 goto err;
347 } 347 }
@@ -356,10 +356,10 @@ static int uhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
356 356
357 /* Disable terminates Resume signalling */ 357 /* Disable terminates Resume signalling */
358 uhci_finish_suspend(uhci, port, port_addr); 358 uhci_finish_suspend(uhci, port, port_addr);
359 OK(0); 359 break;
360 case USB_PORT_FEAT_C_ENABLE: 360 case USB_PORT_FEAT_C_ENABLE:
361 CLR_RH_PORTSTAT(USBPORTSC_PEC); 361 CLR_RH_PORTSTAT(USBPORTSC_PEC);
362 OK(0); 362 break;
363 case USB_PORT_FEAT_SUSPEND: 363 case USB_PORT_FEAT_SUSPEND:
364 if (!(uhci_readw(uhci, port_addr) & USBPORTSC_SUSP)) { 364 if (!(uhci_readw(uhci, port_addr) & USBPORTSC_SUSP)) {
365 365
@@ -382,32 +382,32 @@ static int uhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
382 uhci->ports_timeout = jiffies + 382 uhci->ports_timeout = jiffies +
383 msecs_to_jiffies(20); 383 msecs_to_jiffies(20);
384 } 384 }
385 OK(0); 385 break;
386 case USB_PORT_FEAT_C_SUSPEND: 386 case USB_PORT_FEAT_C_SUSPEND:
387 clear_bit(port, &uhci->port_c_suspend); 387 clear_bit(port, &uhci->port_c_suspend);
388 OK(0); 388 break;
389 case USB_PORT_FEAT_POWER: 389 case USB_PORT_FEAT_POWER:
390 /* UHCI has no power switching */ 390 /* UHCI has no power switching */
391 goto err; 391 goto err;
392 case USB_PORT_FEAT_C_CONNECTION: 392 case USB_PORT_FEAT_C_CONNECTION:
393 CLR_RH_PORTSTAT(USBPORTSC_CSC); 393 CLR_RH_PORTSTAT(USBPORTSC_CSC);
394 OK(0); 394 break;
395 case USB_PORT_FEAT_C_OVER_CURRENT: 395 case USB_PORT_FEAT_C_OVER_CURRENT:
396 CLR_RH_PORTSTAT(USBPORTSC_OCC); 396 CLR_RH_PORTSTAT(USBPORTSC_OCC);
397 OK(0); 397 break;
398 case USB_PORT_FEAT_C_RESET: 398 case USB_PORT_FEAT_C_RESET:
399 /* this driver won't report these */ 399 /* this driver won't report these */
400 OK(0); 400 break;
401 default: 401 default:
402 goto err; 402 goto err;
403 } 403 }
404 break; 404 break;
405 case GetHubDescriptor: 405 case GetHubDescriptor:
406 len = min_t(unsigned int, sizeof(root_hub_hub_des), wLength); 406 retval = min_t(unsigned int, sizeof(root_hub_hub_des), wLength);
407 memcpy(buf, root_hub_hub_des, len); 407 memcpy(buf, root_hub_hub_des, retval);
408 if (len > 2) 408 if (retval > 2)
409 buf[2] = uhci->rh_numports; 409 buf[2] = uhci->rh_numports;
410 OK(len); 410 break;
411 default: 411 default:
412err: 412err:
413 retval = -EPIPE; 413 retval = -EPIPE;
diff --git a/drivers/usb/host/uhci-pci.c b/drivers/usb/host/uhci-pci.c
index 0f228c46eeda..4cd79888804b 100644
--- a/drivers/usb/host/uhci-pci.c
+++ b/drivers/usb/host/uhci-pci.c
@@ -162,6 +162,8 @@ static void uhci_shutdown(struct pci_dev *pdev)
162 162
163#ifdef CONFIG_PM 163#ifdef CONFIG_PM
164 164
165static int uhci_pci_resume(struct usb_hcd *hcd, bool hibernated);
166
165static int uhci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup) 167static int uhci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup)
166{ 168{
167 struct uhci_hcd *uhci = hcd_to_uhci(hcd); 169 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
@@ -174,12 +176,6 @@ static int uhci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup)
174 if (!HCD_HW_ACCESSIBLE(hcd) || uhci->dead) 176 if (!HCD_HW_ACCESSIBLE(hcd) || uhci->dead)
175 goto done_okay; /* Already suspended or dead */ 177 goto done_okay; /* Already suspended or dead */
176 178
177 if (uhci->rh_state > UHCI_RH_SUSPENDED) {
178 dev_warn(uhci_dev(uhci), "Root hub isn't suspended!\n");
179 rc = -EBUSY;
180 goto done;
181 };
182
183 /* All PCI host controllers are required to disable IRQ generation 179 /* All PCI host controllers are required to disable IRQ generation
184 * at the source, so we must turn off PIRQ. 180 * at the source, so we must turn off PIRQ.
185 */ 181 */
@@ -195,8 +191,15 @@ static int uhci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup)
195 191
196done_okay: 192done_okay:
197 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); 193 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
198done:
199 spin_unlock_irq(&uhci->lock); 194 spin_unlock_irq(&uhci->lock);
195
196 synchronize_irq(hcd->irq);
197
198 /* Check for race with a wakeup request */
199 if (do_wakeup && HCD_WAKEUP_PENDING(hcd)) {
200 uhci_pci_resume(hcd, false);
201 rc = -EBUSY;
202 }
200 return rc; 203 return rc;
201} 204}
202 205
@@ -299,3 +302,5 @@ static struct pci_driver uhci_pci_driver = {
299 }, 302 },
300#endif 303#endif
301}; 304};
305
306MODULE_SOFTDEP("pre: ehci_pci");
diff --git a/drivers/usb/host/uhci-platform.c b/drivers/usb/host/uhci-platform.c
index d033a0ec7f0d..ded842bc6578 100644
--- a/drivers/usb/host/uhci-platform.c
+++ b/drivers/usb/host/uhci-platform.c
@@ -105,8 +105,7 @@ static int uhci_hcd_platform_probe(struct platform_device *pdev)
105 105
106 uhci->regs = hcd->regs; 106 uhci->regs = hcd->regs;
107 107
108 ret = usb_add_hcd(hcd, pdev->resource[1].start, IRQF_DISABLED | 108 ret = usb_add_hcd(hcd, pdev->resource[1].start, IRQF_SHARED);
109 IRQF_SHARED);
110 if (ret) 109 if (ret)
111 goto err_uhci; 110 goto err_uhci;
112 111
diff --git a/drivers/usb/host/whci/hcd.c b/drivers/usb/host/whci/hcd.c
index ecc88db804e0..1b0888f8da9a 100644
--- a/drivers/usb/host/whci/hcd.c
+++ b/drivers/usb/host/whci/hcd.c
@@ -134,7 +134,7 @@ static int whc_urb_enqueue(struct usb_hcd *usb_hcd, struct urb *urb,
134 default: 134 default:
135 ret = asl_urb_enqueue(whc, urb, mem_flags); 135 ret = asl_urb_enqueue(whc, urb, mem_flags);
136 break; 136 break;
137 }; 137 }
138 138
139 return ret; 139 return ret;
140} 140}
@@ -160,7 +160,7 @@ static int whc_urb_dequeue(struct usb_hcd *usb_hcd, struct urb *urb, int status)
160 default: 160 default:
161 ret = asl_urb_dequeue(whc, urb, status); 161 ret = asl_urb_dequeue(whc, urb, status);
162 break; 162 break;
163 }; 163 }
164 164
165 return ret; 165 return ret;
166} 166}
diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
index e8b4c56dcf62..805f2348eeba 100644
--- a/drivers/usb/host/xhci-hub.c
+++ b/drivers/usb/host/xhci-hub.c
@@ -296,7 +296,7 @@ static int xhci_stop_device(struct xhci_hcd *xhci, int slot_id, int suspend)
296 /* Wait for last stop endpoint command to finish */ 296 /* Wait for last stop endpoint command to finish */
297 timeleft = wait_for_completion_interruptible_timeout( 297 timeleft = wait_for_completion_interruptible_timeout(
298 cmd->completion, 298 cmd->completion,
299 USB_CTRL_SET_TIMEOUT); 299 XHCI_CMD_DEFAULT_TIMEOUT);
300 if (timeleft <= 0) { 300 if (timeleft <= 0) {
301 xhci_warn(xhci, "%s while waiting for stop endpoint command\n", 301 xhci_warn(xhci, "%s while waiting for stop endpoint command\n",
302 timeleft == 0 ? "Timeout" : "Signal"); 302 timeleft == 0 ? "Timeout" : "Signal");
@@ -524,7 +524,8 @@ static void xhci_hub_report_usb3_link_state(u32 *status, u32 status_reg)
524 * the compliance mode timer is deleted. A port won't enter 524 * the compliance mode timer is deleted. A port won't enter
525 * compliance mode if it has previously entered U0. 525 * compliance mode if it has previously entered U0.
526 */ 526 */
527void xhci_del_comp_mod_timer(struct xhci_hcd *xhci, u32 status, u16 wIndex) 527static void xhci_del_comp_mod_timer(struct xhci_hcd *xhci, u32 status,
528 u16 wIndex)
528{ 529{
529 u32 all_ports_seen_u0 = ((1 << xhci->num_usb3_ports)-1); 530 u32 all_ports_seen_u0 = ((1 << xhci->num_usb3_ports)-1);
530 bool port_in_u0 = ((status & PORT_PLS_MASK) == XDEV_U0); 531 bool port_in_u0 = ((status & PORT_PLS_MASK) == XDEV_U0);
diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index 83bcd13622c3..49b8bd063fab 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -1693,9 +1693,7 @@ void xhci_free_command(struct xhci_hcd *xhci,
1693void xhci_mem_cleanup(struct xhci_hcd *xhci) 1693void xhci_mem_cleanup(struct xhci_hcd *xhci)
1694{ 1694{
1695 struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller); 1695 struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller);
1696 struct dev_info *dev_info, *next;
1697 struct xhci_cd *cur_cd, *next_cd; 1696 struct xhci_cd *cur_cd, *next_cd;
1698 unsigned long flags;
1699 int size; 1697 int size;
1700 int i, j, num_ports; 1698 int i, j, num_ports;
1701 1699
@@ -1756,13 +1754,6 @@ void xhci_mem_cleanup(struct xhci_hcd *xhci)
1756 1754
1757 scratchpad_free(xhci); 1755 scratchpad_free(xhci);
1758 1756
1759 spin_lock_irqsave(&xhci->lock, flags);
1760 list_for_each_entry_safe(dev_info, next, &xhci->lpm_failed_devs, list) {
1761 list_del(&dev_info->list);
1762 kfree(dev_info);
1763 }
1764 spin_unlock_irqrestore(&xhci->lock, flags);
1765
1766 if (!xhci->rh_bw) 1757 if (!xhci->rh_bw)
1767 goto no_bw; 1758 goto no_bw;
1768 1759
@@ -2231,7 +2222,6 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
2231 u32 page_size, temp; 2222 u32 page_size, temp;
2232 int i; 2223 int i;
2233 2224
2234 INIT_LIST_HEAD(&xhci->lpm_failed_devs);
2235 INIT_LIST_HEAD(&xhci->cancel_cmd_list); 2225 INIT_LIST_HEAD(&xhci->cancel_cmd_list);
2236 2226
2237 page_size = xhci_readl(xhci, &xhci->op_regs->page_size); 2227 page_size = xhci_readl(xhci, &xhci->op_regs->page_size);
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index 6bfbd80ec2b9..1e2f3f495843 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -178,7 +178,7 @@ static void inc_deq(struct xhci_hcd *xhci, struct xhci_ring *ring)
178 if (ring->type == TYPE_EVENT && 178 if (ring->type == TYPE_EVENT &&
179 last_trb_on_last_seg(xhci, ring, 179 last_trb_on_last_seg(xhci, ring,
180 ring->deq_seg, ring->dequeue)) { 180 ring->deq_seg, ring->dequeue)) {
181 ring->cycle_state = (ring->cycle_state ? 0 : 1); 181 ring->cycle_state ^= 1;
182 } 182 }
183 ring->deq_seg = ring->deq_seg->next; 183 ring->deq_seg = ring->deq_seg->next;
184 ring->dequeue = ring->deq_seg->trbs; 184 ring->dequeue = ring->deq_seg->trbs;
@@ -726,7 +726,7 @@ static void xhci_stop_watchdog_timer_in_irq(struct xhci_hcd *xhci,
726 726
727/* Must be called with xhci->lock held in interrupt context */ 727/* Must be called with xhci->lock held in interrupt context */
728static void xhci_giveback_urb_in_irq(struct xhci_hcd *xhci, 728static void xhci_giveback_urb_in_irq(struct xhci_hcd *xhci,
729 struct xhci_td *cur_td, int status, char *adjective) 729 struct xhci_td *cur_td, int status)
730{ 730{
731 struct usb_hcd *hcd; 731 struct usb_hcd *hcd;
732 struct urb *urb; 732 struct urb *urb;
@@ -765,10 +765,9 @@ static void xhci_giveback_urb_in_irq(struct xhci_hcd *xhci,
765 * 2. Otherwise, we turn all the TRBs in the TD into No-op TRBs (with the chain 765 * 2. Otherwise, we turn all the TRBs in the TD into No-op TRBs (with the chain
766 * bit cleared) so that the HW will skip over them. 766 * bit cleared) so that the HW will skip over them.
767 */ 767 */
768static void handle_stopped_endpoint(struct xhci_hcd *xhci, 768static void xhci_handle_cmd_stop_ep(struct xhci_hcd *xhci, int slot_id,
769 union xhci_trb *trb, struct xhci_event_cmd *event) 769 union xhci_trb *trb, struct xhci_event_cmd *event)
770{ 770{
771 unsigned int slot_id;
772 unsigned int ep_index; 771 unsigned int ep_index;
773 struct xhci_virt_device *virt_dev; 772 struct xhci_virt_device *virt_dev;
774 struct xhci_ring *ep_ring; 773 struct xhci_ring *ep_ring;
@@ -779,10 +778,7 @@ static void handle_stopped_endpoint(struct xhci_hcd *xhci,
779 778
780 struct xhci_dequeue_state deq_state; 779 struct xhci_dequeue_state deq_state;
781 780
782 if (unlikely(TRB_TO_SUSPEND_PORT( 781 if (unlikely(TRB_TO_SUSPEND_PORT(le32_to_cpu(trb->generic.field[3])))) {
783 le32_to_cpu(xhci->cmd_ring->dequeue->generic.field[3])))) {
784 slot_id = TRB_TO_SLOT_ID(
785 le32_to_cpu(xhci->cmd_ring->dequeue->generic.field[3]));
786 virt_dev = xhci->devs[slot_id]; 782 virt_dev = xhci->devs[slot_id];
787 if (virt_dev) 783 if (virt_dev)
788 handle_cmd_in_cmd_wait_list(xhci, virt_dev, 784 handle_cmd_in_cmd_wait_list(xhci, virt_dev,
@@ -795,7 +791,6 @@ static void handle_stopped_endpoint(struct xhci_hcd *xhci,
795 } 791 }
796 792
797 memset(&deq_state, 0, sizeof(deq_state)); 793 memset(&deq_state, 0, sizeof(deq_state));
798 slot_id = TRB_TO_SLOT_ID(le32_to_cpu(trb->generic.field[3]));
799 ep_index = TRB_TO_EP_INDEX(le32_to_cpu(trb->generic.field[3])); 794 ep_index = TRB_TO_EP_INDEX(le32_to_cpu(trb->generic.field[3]));
800 ep = &xhci->devs[slot_id]->eps[ep_index]; 795 ep = &xhci->devs[slot_id]->eps[ep_index];
801 796
@@ -891,7 +886,7 @@ remove_finished_td:
891 /* Doesn't matter what we pass for status, since the core will 886 /* Doesn't matter what we pass for status, since the core will
892 * just overwrite it (because the URB has been unlinked). 887 * just overwrite it (because the URB has been unlinked).
893 */ 888 */
894 xhci_giveback_urb_in_irq(xhci, cur_td, 0, "cancelled"); 889 xhci_giveback_urb_in_irq(xhci, cur_td, 0);
895 890
896 /* Stop processing the cancelled list if the watchdog timer is 891 /* Stop processing the cancelled list if the watchdog timer is
897 * running. 892 * running.
@@ -1001,7 +996,7 @@ void xhci_stop_endpoint_command_watchdog(unsigned long arg)
1001 if (!list_empty(&cur_td->cancelled_td_list)) 996 if (!list_empty(&cur_td->cancelled_td_list))
1002 list_del_init(&cur_td->cancelled_td_list); 997 list_del_init(&cur_td->cancelled_td_list);
1003 xhci_giveback_urb_in_irq(xhci, cur_td, 998 xhci_giveback_urb_in_irq(xhci, cur_td,
1004 -ESHUTDOWN, "killed"); 999 -ESHUTDOWN);
1005 } 1000 }
1006 while (!list_empty(&temp_ep->cancelled_td_list)) { 1001 while (!list_empty(&temp_ep->cancelled_td_list)) {
1007 cur_td = list_first_entry( 1002 cur_td = list_first_entry(
@@ -1010,7 +1005,7 @@ void xhci_stop_endpoint_command_watchdog(unsigned long arg)
1010 cancelled_td_list); 1005 cancelled_td_list);
1011 list_del_init(&cur_td->cancelled_td_list); 1006 list_del_init(&cur_td->cancelled_td_list);
1012 xhci_giveback_urb_in_irq(xhci, cur_td, 1007 xhci_giveback_urb_in_irq(xhci, cur_td,
1013 -ESHUTDOWN, "killed"); 1008 -ESHUTDOWN);
1014 } 1009 }
1015 } 1010 }
1016 } 1011 }
@@ -1077,11 +1072,9 @@ static void update_ring_for_set_deq_completion(struct xhci_hcd *xhci,
1077 * endpoint doorbell to restart the ring, but only if there aren't more 1072 * endpoint doorbell to restart the ring, but only if there aren't more
1078 * cancellations pending. 1073 * cancellations pending.
1079 */ 1074 */
1080static void handle_set_deq_completion(struct xhci_hcd *xhci, 1075static void xhci_handle_cmd_set_deq(struct xhci_hcd *xhci, int slot_id,
1081 struct xhci_event_cmd *event, 1076 union xhci_trb *trb, u32 cmd_comp_code)
1082 union xhci_trb *trb)
1083{ 1077{
1084 unsigned int slot_id;
1085 unsigned int ep_index; 1078 unsigned int ep_index;
1086 unsigned int stream_id; 1079 unsigned int stream_id;
1087 struct xhci_ring *ep_ring; 1080 struct xhci_ring *ep_ring;
@@ -1089,7 +1082,6 @@ static void handle_set_deq_completion(struct xhci_hcd *xhci,
1089 struct xhci_ep_ctx *ep_ctx; 1082 struct xhci_ep_ctx *ep_ctx;
1090 struct xhci_slot_ctx *slot_ctx; 1083 struct xhci_slot_ctx *slot_ctx;
1091 1084
1092 slot_id = TRB_TO_SLOT_ID(le32_to_cpu(trb->generic.field[3]));
1093 ep_index = TRB_TO_EP_INDEX(le32_to_cpu(trb->generic.field[3])); 1085 ep_index = TRB_TO_EP_INDEX(le32_to_cpu(trb->generic.field[3]));
1094 stream_id = TRB_TO_STREAM_ID(le32_to_cpu(trb->generic.field[2])); 1086 stream_id = TRB_TO_STREAM_ID(le32_to_cpu(trb->generic.field[2]));
1095 dev = xhci->devs[slot_id]; 1087 dev = xhci->devs[slot_id];
@@ -1107,11 +1099,11 @@ static void handle_set_deq_completion(struct xhci_hcd *xhci,
1107 ep_ctx = xhci_get_ep_ctx(xhci, dev->out_ctx, ep_index); 1099 ep_ctx = xhci_get_ep_ctx(xhci, dev->out_ctx, ep_index);
1108 slot_ctx = xhci_get_slot_ctx(xhci, dev->out_ctx); 1100 slot_ctx = xhci_get_slot_ctx(xhci, dev->out_ctx);
1109 1101
1110 if (GET_COMP_CODE(le32_to_cpu(event->status)) != COMP_SUCCESS) { 1102 if (cmd_comp_code != COMP_SUCCESS) {
1111 unsigned int ep_state; 1103 unsigned int ep_state;
1112 unsigned int slot_state; 1104 unsigned int slot_state;
1113 1105
1114 switch (GET_COMP_CODE(le32_to_cpu(event->status))) { 1106 switch (cmd_comp_code) {
1115 case COMP_TRB_ERR: 1107 case COMP_TRB_ERR:
1116 xhci_warn(xhci, "WARN Set TR Deq Ptr cmd invalid because " 1108 xhci_warn(xhci, "WARN Set TR Deq Ptr cmd invalid because "
1117 "of stream ID configuration\n"); 1109 "of stream ID configuration\n");
@@ -1134,7 +1126,7 @@ static void handle_set_deq_completion(struct xhci_hcd *xhci,
1134 default: 1126 default:
1135 xhci_warn(xhci, "WARN Set TR Deq Ptr cmd with unknown " 1127 xhci_warn(xhci, "WARN Set TR Deq Ptr cmd with unknown "
1136 "completion code of %u.\n", 1128 "completion code of %u.\n",
1137 GET_COMP_CODE(le32_to_cpu(event->status))); 1129 cmd_comp_code);
1138 break; 1130 break;
1139 } 1131 }
1140 /* OK what do we do now? The endpoint state is hosed, and we 1132 /* OK what do we do now? The endpoint state is hosed, and we
@@ -1171,21 +1163,17 @@ static void handle_set_deq_completion(struct xhci_hcd *xhci,
1171 ring_doorbell_for_active_rings(xhci, slot_id, ep_index); 1163 ring_doorbell_for_active_rings(xhci, slot_id, ep_index);
1172} 1164}
1173 1165
1174static void handle_reset_ep_completion(struct xhci_hcd *xhci, 1166static void xhci_handle_cmd_reset_ep(struct xhci_hcd *xhci, int slot_id,
1175 struct xhci_event_cmd *event, 1167 union xhci_trb *trb, u32 cmd_comp_code)
1176 union xhci_trb *trb)
1177{ 1168{
1178 int slot_id;
1179 unsigned int ep_index; 1169 unsigned int ep_index;
1180 1170
1181 slot_id = TRB_TO_SLOT_ID(le32_to_cpu(trb->generic.field[3]));
1182 ep_index = TRB_TO_EP_INDEX(le32_to_cpu(trb->generic.field[3])); 1171 ep_index = TRB_TO_EP_INDEX(le32_to_cpu(trb->generic.field[3]));
1183 /* This command will only fail if the endpoint wasn't halted, 1172 /* This command will only fail if the endpoint wasn't halted,
1184 * but we don't care. 1173 * but we don't care.
1185 */ 1174 */
1186 xhci_dbg_trace(xhci, trace_xhci_dbg_reset_ep, 1175 xhci_dbg_trace(xhci, trace_xhci_dbg_reset_ep,
1187 "Ignoring reset ep completion code of %u", 1176 "Ignoring reset ep completion code of %u", cmd_comp_code);
1188 GET_COMP_CODE(le32_to_cpu(event->status)));
1189 1177
1190 /* HW with the reset endpoint quirk needs to have a configure endpoint 1178 /* HW with the reset endpoint quirk needs to have a configure endpoint
1191 * command complete before the endpoint can be used. Queue that here 1179 * command complete before the endpoint can be used. Queue that here
@@ -1386,21 +1374,149 @@ static int handle_stopped_cmd_ring(struct xhci_hcd *xhci,
1386 return cur_trb_is_good; 1374 return cur_trb_is_good;
1387} 1375}
1388 1376
1377static void xhci_handle_cmd_enable_slot(struct xhci_hcd *xhci, int slot_id,
1378 u32 cmd_comp_code)
1379{
1380 if (cmd_comp_code == COMP_SUCCESS)
1381 xhci->slot_id = slot_id;
1382 else
1383 xhci->slot_id = 0;
1384 complete(&xhci->addr_dev);
1385}
1386
1387static void xhci_handle_cmd_disable_slot(struct xhci_hcd *xhci, int slot_id)
1388{
1389 struct xhci_virt_device *virt_dev;
1390
1391 virt_dev = xhci->devs[slot_id];
1392 if (!virt_dev)
1393 return;
1394 if (xhci->quirks & XHCI_EP_LIMIT_QUIRK)
1395 /* Delete default control endpoint resources */
1396 xhci_free_device_endpoint_resources(xhci, virt_dev, true);
1397 xhci_free_virt_device(xhci, slot_id);
1398}
1399
1400static void xhci_handle_cmd_config_ep(struct xhci_hcd *xhci, int slot_id,
1401 struct xhci_event_cmd *event, u32 cmd_comp_code)
1402{
1403 struct xhci_virt_device *virt_dev;
1404 struct xhci_input_control_ctx *ctrl_ctx;
1405 unsigned int ep_index;
1406 unsigned int ep_state;
1407 u32 add_flags, drop_flags;
1408
1409 virt_dev = xhci->devs[slot_id];
1410 if (handle_cmd_in_cmd_wait_list(xhci, virt_dev, event))
1411 return;
1412 /*
1413 * Configure endpoint commands can come from the USB core
1414 * configuration or alt setting changes, or because the HW
1415 * needed an extra configure endpoint command after a reset
1416 * endpoint command or streams were being configured.
1417 * If the command was for a halted endpoint, the xHCI driver
1418 * is not waiting on the configure endpoint command.
1419 */
1420 ctrl_ctx = xhci_get_input_control_ctx(xhci, virt_dev->in_ctx);
1421 if (!ctrl_ctx) {
1422 xhci_warn(xhci, "Could not get input context, bad type.\n");
1423 return;
1424 }
1425
1426 add_flags = le32_to_cpu(ctrl_ctx->add_flags);
1427 drop_flags = le32_to_cpu(ctrl_ctx->drop_flags);
1428 /* Input ctx add_flags are the endpoint index plus one */
1429 ep_index = xhci_last_valid_endpoint(add_flags) - 1;
1430
1431 /* A usb_set_interface() call directly after clearing a halted
1432 * condition may race on this quirky hardware. Not worth
1433 * worrying about, since this is prototype hardware. Not sure
1434 * if this will work for streams, but streams support was
1435 * untested on this prototype.
1436 */
1437 if (xhci->quirks & XHCI_RESET_EP_QUIRK &&
1438 ep_index != (unsigned int) -1 &&
1439 add_flags - SLOT_FLAG == drop_flags) {
1440 ep_state = virt_dev->eps[ep_index].ep_state;
1441 if (!(ep_state & EP_HALTED))
1442 goto bandwidth_change;
1443 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
1444 "Completed config ep cmd - "
1445 "last ep index = %d, state = %d",
1446 ep_index, ep_state);
1447 /* Clear internal halted state and restart ring(s) */
1448 virt_dev->eps[ep_index].ep_state &= ~EP_HALTED;
1449 ring_doorbell_for_active_rings(xhci, slot_id, ep_index);
1450 return;
1451 }
1452bandwidth_change:
1453 xhci_dbg_trace(xhci, trace_xhci_dbg_context_change,
1454 "Completed config ep cmd");
1455 virt_dev->cmd_status = cmd_comp_code;
1456 complete(&virt_dev->cmd_completion);
1457 return;
1458}
1459
1460static void xhci_handle_cmd_eval_ctx(struct xhci_hcd *xhci, int slot_id,
1461 struct xhci_event_cmd *event, u32 cmd_comp_code)
1462{
1463 struct xhci_virt_device *virt_dev;
1464
1465 virt_dev = xhci->devs[slot_id];
1466 if (handle_cmd_in_cmd_wait_list(xhci, virt_dev, event))
1467 return;
1468 virt_dev->cmd_status = cmd_comp_code;
1469 complete(&virt_dev->cmd_completion);
1470}
1471
1472static void xhci_handle_cmd_addr_dev(struct xhci_hcd *xhci, int slot_id,
1473 u32 cmd_comp_code)
1474{
1475 xhci->devs[slot_id]->cmd_status = cmd_comp_code;
1476 complete(&xhci->addr_dev);
1477}
1478
1479static void xhci_handle_cmd_reset_dev(struct xhci_hcd *xhci, int slot_id,
1480 struct xhci_event_cmd *event)
1481{
1482 struct xhci_virt_device *virt_dev;
1483
1484 xhci_dbg(xhci, "Completed reset device command.\n");
1485 virt_dev = xhci->devs[slot_id];
1486 if (virt_dev)
1487 handle_cmd_in_cmd_wait_list(xhci, virt_dev, event);
1488 else
1489 xhci_warn(xhci, "Reset device command completion "
1490 "for disabled slot %u\n", slot_id);
1491}
1492
1493static void xhci_handle_cmd_nec_get_fw(struct xhci_hcd *xhci,
1494 struct xhci_event_cmd *event)
1495{
1496 if (!(xhci->quirks & XHCI_NEC_HOST)) {
1497 xhci->error_bitmask |= 1 << 6;
1498 return;
1499 }
1500 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
1501 "NEC firmware version %2x.%02x",
1502 NEC_FW_MAJOR(le32_to_cpu(event->status)),
1503 NEC_FW_MINOR(le32_to_cpu(event->status)));
1504}
1505
1389static void handle_cmd_completion(struct xhci_hcd *xhci, 1506static void handle_cmd_completion(struct xhci_hcd *xhci,
1390 struct xhci_event_cmd *event) 1507 struct xhci_event_cmd *event)
1391{ 1508{
1392 int slot_id = TRB_TO_SLOT_ID(le32_to_cpu(event->flags)); 1509 int slot_id = TRB_TO_SLOT_ID(le32_to_cpu(event->flags));
1393 u64 cmd_dma; 1510 u64 cmd_dma;
1394 dma_addr_t cmd_dequeue_dma; 1511 dma_addr_t cmd_dequeue_dma;
1395 struct xhci_input_control_ctx *ctrl_ctx; 1512 u32 cmd_comp_code;
1396 struct xhci_virt_device *virt_dev; 1513 union xhci_trb *cmd_trb;
1397 unsigned int ep_index; 1514 u32 cmd_type;
1398 struct xhci_ring *ep_ring;
1399 unsigned int ep_state;
1400 1515
1401 cmd_dma = le64_to_cpu(event->cmd_trb); 1516 cmd_dma = le64_to_cpu(event->cmd_trb);
1517 cmd_trb = xhci->cmd_ring->dequeue;
1402 cmd_dequeue_dma = xhci_trb_virt_to_dma(xhci->cmd_ring->deq_seg, 1518 cmd_dequeue_dma = xhci_trb_virt_to_dma(xhci->cmd_ring->deq_seg,
1403 xhci->cmd_ring->dequeue); 1519 cmd_trb);
1404 /* Is the command ring deq ptr out of sync with the deq seg ptr? */ 1520 /* Is the command ring deq ptr out of sync with the deq seg ptr? */
1405 if (cmd_dequeue_dma == 0) { 1521 if (cmd_dequeue_dma == 0) {
1406 xhci->error_bitmask |= 1 << 4; 1522 xhci->error_bitmask |= 1 << 4;
@@ -1412,19 +1528,17 @@ static void handle_cmd_completion(struct xhci_hcd *xhci,
1412 return; 1528 return;
1413 } 1529 }
1414 1530
1415 trace_xhci_cmd_completion(&xhci->cmd_ring->dequeue->generic, 1531 trace_xhci_cmd_completion(cmd_trb, (struct xhci_generic_trb *) event);
1416 (struct xhci_generic_trb *) event);
1417 1532
1418 if ((GET_COMP_CODE(le32_to_cpu(event->status)) == COMP_CMD_ABORT) || 1533 cmd_comp_code = GET_COMP_CODE(le32_to_cpu(event->status));
1419 (GET_COMP_CODE(le32_to_cpu(event->status)) == COMP_CMD_STOP)) { 1534 if (cmd_comp_code == COMP_CMD_ABORT || cmd_comp_code == COMP_CMD_STOP) {
1420 /* If the return value is 0, we think the trb pointed by 1535 /* If the return value is 0, we think the trb pointed by
1421 * command ring dequeue pointer is a good trb. The good 1536 * command ring dequeue pointer is a good trb. The good
1422 * trb means we don't want to cancel the trb, but it have 1537 * trb means we don't want to cancel the trb, but it have
1423 * been stopped by host. So we should handle it normally. 1538 * been stopped by host. So we should handle it normally.
1424 * Otherwise, driver should invoke inc_deq() and return. 1539 * Otherwise, driver should invoke inc_deq() and return.
1425 */ 1540 */
1426 if (handle_stopped_cmd_ring(xhci, 1541 if (handle_stopped_cmd_ring(xhci, cmd_comp_code)) {
1427 GET_COMP_CODE(le32_to_cpu(event->status)))) {
1428 inc_deq(xhci, xhci->cmd_ring); 1542 inc_deq(xhci, xhci->cmd_ring);
1429 return; 1543 return;
1430 } 1544 }
@@ -1436,117 +1550,47 @@ static void handle_cmd_completion(struct xhci_hcd *xhci,
1436 return; 1550 return;
1437 } 1551 }
1438 1552
1439 switch (le32_to_cpu(xhci->cmd_ring->dequeue->generic.field[3]) 1553 cmd_type = TRB_FIELD_TO_TYPE(le32_to_cpu(cmd_trb->generic.field[3]));
1440 & TRB_TYPE_BITMASK) { 1554 switch (cmd_type) {
1441 case TRB_TYPE(TRB_ENABLE_SLOT): 1555 case TRB_ENABLE_SLOT:
1442 if (GET_COMP_CODE(le32_to_cpu(event->status)) == COMP_SUCCESS) 1556 xhci_handle_cmd_enable_slot(xhci, slot_id, cmd_comp_code);
1443 xhci->slot_id = slot_id;
1444 else
1445 xhci->slot_id = 0;
1446 complete(&xhci->addr_dev);
1447 break; 1557 break;
1448 case TRB_TYPE(TRB_DISABLE_SLOT): 1558 case TRB_DISABLE_SLOT:
1449 if (xhci->devs[slot_id]) { 1559 xhci_handle_cmd_disable_slot(xhci, slot_id);
1450 if (xhci->quirks & XHCI_EP_LIMIT_QUIRK)
1451 /* Delete default control endpoint resources */
1452 xhci_free_device_endpoint_resources(xhci,
1453 xhci->devs[slot_id], true);
1454 xhci_free_virt_device(xhci, slot_id);
1455 }
1456 break; 1560 break;
1457 case TRB_TYPE(TRB_CONFIG_EP): 1561 case TRB_CONFIG_EP:
1458 virt_dev = xhci->devs[slot_id]; 1562 xhci_handle_cmd_config_ep(xhci, slot_id, event, cmd_comp_code);
1459 if (handle_cmd_in_cmd_wait_list(xhci, virt_dev, event))
1460 break;
1461 /*
1462 * Configure endpoint commands can come from the USB core
1463 * configuration or alt setting changes, or because the HW
1464 * needed an extra configure endpoint command after a reset
1465 * endpoint command or streams were being configured.
1466 * If the command was for a halted endpoint, the xHCI driver
1467 * is not waiting on the configure endpoint command.
1468 */
1469 ctrl_ctx = xhci_get_input_control_ctx(xhci,
1470 virt_dev->in_ctx);
1471 if (!ctrl_ctx) {
1472 xhci_warn(xhci, "Could not get input context, bad type.\n");
1473 break;
1474 }
1475 /* Input ctx add_flags are the endpoint index plus one */
1476 ep_index = xhci_last_valid_endpoint(le32_to_cpu(ctrl_ctx->add_flags)) - 1;
1477 /* A usb_set_interface() call directly after clearing a halted
1478 * condition may race on this quirky hardware. Not worth
1479 * worrying about, since this is prototype hardware. Not sure
1480 * if this will work for streams, but streams support was
1481 * untested on this prototype.
1482 */
1483 if (xhci->quirks & XHCI_RESET_EP_QUIRK &&
1484 ep_index != (unsigned int) -1 &&
1485 le32_to_cpu(ctrl_ctx->add_flags) - SLOT_FLAG ==
1486 le32_to_cpu(ctrl_ctx->drop_flags)) {
1487 ep_ring = xhci->devs[slot_id]->eps[ep_index].ring;
1488 ep_state = xhci->devs[slot_id]->eps[ep_index].ep_state;
1489 if (!(ep_state & EP_HALTED))
1490 goto bandwidth_change;
1491 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
1492 "Completed config ep cmd - "
1493 "last ep index = %d, state = %d",
1494 ep_index, ep_state);
1495 /* Clear internal halted state and restart ring(s) */
1496 xhci->devs[slot_id]->eps[ep_index].ep_state &=
1497 ~EP_HALTED;
1498 ring_doorbell_for_active_rings(xhci, slot_id, ep_index);
1499 break;
1500 }
1501bandwidth_change:
1502 xhci_dbg_trace(xhci, trace_xhci_dbg_context_change,
1503 "Completed config ep cmd");
1504 xhci->devs[slot_id]->cmd_status =
1505 GET_COMP_CODE(le32_to_cpu(event->status));
1506 complete(&xhci->devs[slot_id]->cmd_completion);
1507 break; 1563 break;
1508 case TRB_TYPE(TRB_EVAL_CONTEXT): 1564 case TRB_EVAL_CONTEXT:
1509 virt_dev = xhci->devs[slot_id]; 1565 xhci_handle_cmd_eval_ctx(xhci, slot_id, event, cmd_comp_code);
1510 if (handle_cmd_in_cmd_wait_list(xhci, virt_dev, event))
1511 break;
1512 xhci->devs[slot_id]->cmd_status = GET_COMP_CODE(le32_to_cpu(event->status));
1513 complete(&xhci->devs[slot_id]->cmd_completion);
1514 break; 1566 break;
1515 case TRB_TYPE(TRB_ADDR_DEV): 1567 case TRB_ADDR_DEV:
1516 xhci->devs[slot_id]->cmd_status = GET_COMP_CODE(le32_to_cpu(event->status)); 1568 xhci_handle_cmd_addr_dev(xhci, slot_id, cmd_comp_code);
1517 complete(&xhci->addr_dev);
1518 break; 1569 break;
1519 case TRB_TYPE(TRB_STOP_RING): 1570 case TRB_STOP_RING:
1520 handle_stopped_endpoint(xhci, xhci->cmd_ring->dequeue, event); 1571 WARN_ON(slot_id != TRB_TO_SLOT_ID(
1572 le32_to_cpu(cmd_trb->generic.field[3])));
1573 xhci_handle_cmd_stop_ep(xhci, slot_id, cmd_trb, event);
1521 break; 1574 break;
1522 case TRB_TYPE(TRB_SET_DEQ): 1575 case TRB_SET_DEQ:
1523 handle_set_deq_completion(xhci, event, xhci->cmd_ring->dequeue); 1576 WARN_ON(slot_id != TRB_TO_SLOT_ID(
1577 le32_to_cpu(cmd_trb->generic.field[3])));
1578 xhci_handle_cmd_set_deq(xhci, slot_id, cmd_trb, cmd_comp_code);
1524 break; 1579 break;
1525 case TRB_TYPE(TRB_CMD_NOOP): 1580 case TRB_CMD_NOOP:
1526 break; 1581 break;
1527 case TRB_TYPE(TRB_RESET_EP): 1582 case TRB_RESET_EP:
1528 handle_reset_ep_completion(xhci, event, xhci->cmd_ring->dequeue); 1583 WARN_ON(slot_id != TRB_TO_SLOT_ID(
1584 le32_to_cpu(cmd_trb->generic.field[3])));
1585 xhci_handle_cmd_reset_ep(xhci, slot_id, cmd_trb, cmd_comp_code);
1529 break; 1586 break;
1530 case TRB_TYPE(TRB_RESET_DEV): 1587 case TRB_RESET_DEV:
1531 xhci_dbg(xhci, "Completed reset device command.\n"); 1588 WARN_ON(slot_id != TRB_TO_SLOT_ID(
1532 slot_id = TRB_TO_SLOT_ID( 1589 le32_to_cpu(cmd_trb->generic.field[3])));
1533 le32_to_cpu(xhci->cmd_ring->dequeue->generic.field[3])); 1590 xhci_handle_cmd_reset_dev(xhci, slot_id, event);
1534 virt_dev = xhci->devs[slot_id];
1535 if (virt_dev)
1536 handle_cmd_in_cmd_wait_list(xhci, virt_dev, event);
1537 else
1538 xhci_warn(xhci, "Reset device command completion "
1539 "for disabled slot %u\n", slot_id);
1540 break; 1591 break;
1541 case TRB_TYPE(TRB_NEC_GET_FW): 1592 case TRB_NEC_GET_FW:
1542 if (!(xhci->quirks & XHCI_NEC_HOST)) { 1593 xhci_handle_cmd_nec_get_fw(xhci, event);
1543 xhci->error_bitmask |= 1 << 6;
1544 break;
1545 }
1546 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
1547 "NEC firmware version %2x.%02x",
1548 NEC_FW_MAJOR(le32_to_cpu(event->status)),
1549 NEC_FW_MINOR(le32_to_cpu(event->status)));
1550 break; 1594 break;
1551 default: 1595 default:
1552 /* Skip over unknown commands on the event ring */ 1596 /* Skip over unknown commands on the event ring */
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index 6e0d886bcce5..4265b48856f6 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -3459,7 +3459,7 @@ int xhci_discover_or_reset_device(struct usb_hcd *hcd, struct usb_device *udev)
3459 /* Wait for the Reset Device command to finish */ 3459 /* Wait for the Reset Device command to finish */
3460 timeleft = wait_for_completion_interruptible_timeout( 3460 timeleft = wait_for_completion_interruptible_timeout(
3461 reset_device_cmd->completion, 3461 reset_device_cmd->completion,
3462 USB_CTRL_SET_TIMEOUT); 3462 XHCI_CMD_DEFAULT_TIMEOUT);
3463 if (timeleft <= 0) { 3463 if (timeleft <= 0) {
3464 xhci_warn(xhci, "%s while waiting for reset device command\n", 3464 xhci_warn(xhci, "%s while waiting for reset device command\n",
3465 timeleft == 0 ? "Timeout" : "Signal"); 3465 timeleft == 0 ? "Timeout" : "Signal");
@@ -3583,11 +3583,6 @@ void xhci_free_dev(struct usb_hcd *hcd, struct usb_device *udev)
3583 del_timer_sync(&virt_dev->eps[i].stop_cmd_timer); 3583 del_timer_sync(&virt_dev->eps[i].stop_cmd_timer);
3584 } 3584 }
3585 3585
3586 if (udev->usb2_hw_lpm_enabled) {
3587 xhci_set_usb2_hardware_lpm(hcd, udev, 0);
3588 udev->usb2_hw_lpm_enabled = 0;
3589 }
3590
3591 spin_lock_irqsave(&xhci->lock, flags); 3586 spin_lock_irqsave(&xhci->lock, flags);
3592 /* Don't disable the slot if the host controller is dead. */ 3587 /* Don't disable the slot if the host controller is dead. */
3593 state = xhci_readl(xhci, &xhci->op_regs->status); 3588 state = xhci_readl(xhci, &xhci->op_regs->status);
@@ -3721,9 +3716,6 @@ disable_slot:
3721 * the device). 3716 * the device).
3722 * We should be protected by the usb_address0_mutex in khubd's hub_port_init, so 3717 * We should be protected by the usb_address0_mutex in khubd's hub_port_init, so
3723 * we should only issue and wait on one address command at the same time. 3718 * we should only issue and wait on one address command at the same time.
3724 *
3725 * We add one to the device address issued by the hardware because the USB core
3726 * uses address 1 for the root hubs (even though they're not really devices).
3727 */ 3719 */
3728int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev) 3720int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev)
3729{ 3721{
@@ -3868,16 +3860,13 @@ int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev)
3868 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->out_ctx); 3860 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->out_ctx);
3869 trace_xhci_address_ctx(xhci, virt_dev->out_ctx, 3861 trace_xhci_address_ctx(xhci, virt_dev->out_ctx,
3870 slot_ctx->dev_info >> 27); 3862 slot_ctx->dev_info >> 27);
3871 /* Use kernel assigned address for devices; store xHC assigned
3872 * address locally. */
3873 virt_dev->address = (le32_to_cpu(slot_ctx->dev_state) & DEV_ADDR_MASK)
3874 + 1;
3875 /* Zero the input context control for later use */ 3863 /* Zero the input context control for later use */
3876 ctrl_ctx->add_flags = 0; 3864 ctrl_ctx->add_flags = 0;
3877 ctrl_ctx->drop_flags = 0; 3865 ctrl_ctx->drop_flags = 0;
3878 3866
3879 xhci_dbg_trace(xhci, trace_xhci_dbg_address, 3867 xhci_dbg_trace(xhci, trace_xhci_dbg_address,
3880 "Internal device address = %d", virt_dev->address); 3868 "Internal device address = %d",
3869 le32_to_cpu(slot_ctx->dev_state) & DEV_ADDR_MASK);
3881 3870
3882 return 0; 3871 return 0;
3883} 3872}
@@ -4025,133 +4014,6 @@ static int xhci_calculate_usb2_hw_lpm_params(struct usb_device *udev)
4025 return PORT_BESLD(besld) | PORT_L1_TIMEOUT(l1) | PORT_HIRDM(hirdm); 4014 return PORT_BESLD(besld) | PORT_L1_TIMEOUT(l1) | PORT_HIRDM(hirdm);
4026} 4015}
4027 4016
4028static int xhci_usb2_software_lpm_test(struct usb_hcd *hcd,
4029 struct usb_device *udev)
4030{
4031 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
4032 struct dev_info *dev_info;
4033 __le32 __iomem **port_array;
4034 __le32 __iomem *addr, *pm_addr;
4035 u32 temp, dev_id;
4036 unsigned int port_num;
4037 unsigned long flags;
4038 int hird;
4039 int ret;
4040
4041 if (hcd->speed == HCD_USB3 || !xhci->sw_lpm_support ||
4042 !udev->lpm_capable)
4043 return -EINVAL;
4044
4045 /* we only support lpm for non-hub device connected to root hub yet */
4046 if (!udev->parent || udev->parent->parent ||
4047 udev->descriptor.bDeviceClass == USB_CLASS_HUB)
4048 return -EINVAL;
4049
4050 spin_lock_irqsave(&xhci->lock, flags);
4051
4052 /* Look for devices in lpm_failed_devs list */
4053 dev_id = le16_to_cpu(udev->descriptor.idVendor) << 16 |
4054 le16_to_cpu(udev->descriptor.idProduct);
4055 list_for_each_entry(dev_info, &xhci->lpm_failed_devs, list) {
4056 if (dev_info->dev_id == dev_id) {
4057 ret = -EINVAL;
4058 goto finish;
4059 }
4060 }
4061
4062 port_array = xhci->usb2_ports;
4063 port_num = udev->portnum - 1;
4064
4065 if (port_num > HCS_MAX_PORTS(xhci->hcs_params1)) {
4066 xhci_dbg(xhci, "invalid port number %d\n", udev->portnum);
4067 ret = -EINVAL;
4068 goto finish;
4069 }
4070
4071 /*
4072 * Test USB 2.0 software LPM.
4073 * FIXME: some xHCI 1.0 hosts may implement a new register to set up
4074 * hardware-controlled USB 2.0 LPM. See section 5.4.11 and 4.23.5.1.1.1
4075 * in the June 2011 errata release.
4076 */
4077 xhci_dbg(xhci, "test port %d software LPM\n", port_num);
4078 /*
4079 * Set L1 Device Slot and HIRD/BESL.
4080 * Check device's USB 2.0 extension descriptor to determine whether
4081 * HIRD or BESL shoule be used. See USB2.0 LPM errata.
4082 */
4083 pm_addr = port_array[port_num] + PORTPMSC;
4084 hird = xhci_calculate_hird_besl(xhci, udev);
4085 temp = PORT_L1DS(udev->slot_id) | PORT_HIRD(hird);
4086 xhci_writel(xhci, temp, pm_addr);
4087
4088 /* Set port link state to U2(L1) */
4089 addr = port_array[port_num];
4090 xhci_set_link_state(xhci, port_array, port_num, XDEV_U2);
4091
4092 /* wait for ACK */
4093 spin_unlock_irqrestore(&xhci->lock, flags);
4094 msleep(10);
4095 spin_lock_irqsave(&xhci->lock, flags);
4096
4097 /* Check L1 Status */
4098 ret = xhci_handshake(xhci, pm_addr,
4099 PORT_L1S_MASK, PORT_L1S_SUCCESS, 125);
4100 if (ret != -ETIMEDOUT) {
4101 /* enter L1 successfully */
4102 temp = xhci_readl(xhci, addr);
4103 xhci_dbg(xhci, "port %d entered L1 state, port status 0x%x\n",
4104 port_num, temp);
4105 ret = 0;
4106 } else {
4107 temp = xhci_readl(xhci, pm_addr);
4108 xhci_dbg(xhci, "port %d software lpm failed, L1 status %d\n",
4109 port_num, temp & PORT_L1S_MASK);
4110 ret = -EINVAL;
4111 }
4112
4113 /* Resume the port */
4114 xhci_set_link_state(xhci, port_array, port_num, XDEV_U0);
4115
4116 spin_unlock_irqrestore(&xhci->lock, flags);
4117 msleep(10);
4118 spin_lock_irqsave(&xhci->lock, flags);
4119
4120 /* Clear PLC */
4121 xhci_test_and_clear_bit(xhci, port_array, port_num, PORT_PLC);
4122
4123 /* Check PORTSC to make sure the device is in the right state */
4124 if (!ret) {
4125 temp = xhci_readl(xhci, addr);
4126 xhci_dbg(xhci, "resumed port %d status 0x%x\n", port_num, temp);
4127 if (!(temp & PORT_CONNECT) || !(temp & PORT_PE) ||
4128 (temp & PORT_PLS_MASK) != XDEV_U0) {
4129 xhci_dbg(xhci, "port L1 resume fail\n");
4130 ret = -EINVAL;
4131 }
4132 }
4133
4134 if (ret) {
4135 /* Insert dev to lpm_failed_devs list */
4136 xhci_warn(xhci, "device LPM test failed, may disconnect and "
4137 "re-enumerate\n");
4138 dev_info = kzalloc(sizeof(struct dev_info), GFP_ATOMIC);
4139 if (!dev_info) {
4140 ret = -ENOMEM;
4141 goto finish;
4142 }
4143 dev_info->dev_id = dev_id;
4144 INIT_LIST_HEAD(&dev_info->list);
4145 list_add(&dev_info->list, &xhci->lpm_failed_devs);
4146 } else {
4147 xhci_ring_device(xhci, udev->slot_id);
4148 }
4149
4150finish:
4151 spin_unlock_irqrestore(&xhci->lock, flags);
4152 return ret;
4153}
4154
4155int xhci_set_usb2_hardware_lpm(struct usb_hcd *hcd, 4017int xhci_set_usb2_hardware_lpm(struct usb_hcd *hcd,
4156 struct usb_device *udev, int enable) 4018 struct usb_device *udev, int enable)
4157{ 4019{
@@ -4228,7 +4090,7 @@ int xhci_set_usb2_hardware_lpm(struct usb_hcd *hcd,
4228 } 4090 }
4229 4091
4230 pm_val &= ~PORT_HIRD_MASK; 4092 pm_val &= ~PORT_HIRD_MASK;
4231 pm_val |= PORT_HIRD(hird) | PORT_RWE; 4093 pm_val |= PORT_HIRD(hird) | PORT_RWE | PORT_L1DS(udev->slot_id);
4232 xhci_writel(xhci, pm_val, pm_addr); 4094 xhci_writel(xhci, pm_val, pm_addr);
4233 pm_val = xhci_readl(xhci, pm_addr); 4095 pm_val = xhci_readl(xhci, pm_addr);
4234 pm_val |= PORT_HLE; 4096 pm_val |= PORT_HLE;
@@ -4236,7 +4098,7 @@ int xhci_set_usb2_hardware_lpm(struct usb_hcd *hcd,
4236 /* flush write */ 4098 /* flush write */
4237 xhci_readl(xhci, pm_addr); 4099 xhci_readl(xhci, pm_addr);
4238 } else { 4100 } else {
4239 pm_val &= ~(PORT_HLE | PORT_RWE | PORT_HIRD_MASK); 4101 pm_val &= ~(PORT_HLE | PORT_RWE | PORT_HIRD_MASK | PORT_L1DS_MASK);
4240 xhci_writel(xhci, pm_val, pm_addr); 4102 xhci_writel(xhci, pm_val, pm_addr);
4241 /* flush write */ 4103 /* flush write */
4242 xhci_readl(xhci, pm_addr); 4104 xhci_readl(xhci, pm_addr);
@@ -4279,24 +4141,26 @@ static int xhci_check_usb2_port_capability(struct xhci_hcd *xhci, int port,
4279int xhci_update_device(struct usb_hcd *hcd, struct usb_device *udev) 4141int xhci_update_device(struct usb_hcd *hcd, struct usb_device *udev)
4280{ 4142{
4281 struct xhci_hcd *xhci = hcd_to_xhci(hcd); 4143 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
4282 int ret;
4283 int portnum = udev->portnum - 1; 4144 int portnum = udev->portnum - 1;
4284 4145
4285 ret = xhci_usb2_software_lpm_test(hcd, udev); 4146 if (hcd->speed == HCD_USB3 || !xhci->sw_lpm_support ||
4286 if (!ret) { 4147 !udev->lpm_capable)
4287 xhci_dbg(xhci, "software LPM test succeed\n"); 4148 return 0;
4288 if (xhci->hw_lpm_support == 1 && 4149
4289 xhci_check_usb2_port_capability(xhci, portnum, XHCI_HLC)) { 4150 /* we only support lpm for non-hub device connected to root hub yet */
4290 udev->usb2_hw_lpm_capable = 1; 4151 if (!udev->parent || udev->parent->parent ||
4291 udev->l1_params.timeout = XHCI_L1_TIMEOUT; 4152 udev->descriptor.bDeviceClass == USB_CLASS_HUB)
4292 udev->l1_params.besl = XHCI_DEFAULT_BESL; 4153 return 0;
4293 if (xhci_check_usb2_port_capability(xhci, portnum, 4154
4294 XHCI_BLC)) 4155 if (xhci->hw_lpm_support == 1 &&
4295 udev->usb2_hw_lpm_besl_capable = 1; 4156 xhci_check_usb2_port_capability(
4296 ret = xhci_set_usb2_hardware_lpm(hcd, udev, 1); 4157 xhci, portnum, XHCI_HLC)) {
4297 if (!ret) 4158 udev->usb2_hw_lpm_capable = 1;
4298 udev->usb2_hw_lpm_enabled = 1; 4159 udev->l1_params.timeout = XHCI_L1_TIMEOUT;
4299 } 4160 udev->l1_params.besl = XHCI_DEFAULT_BESL;
4161 if (xhci_check_usb2_port_capability(xhci, portnum,
4162 XHCI_BLC))
4163 udev->usb2_hw_lpm_besl_capable = 1;
4300 } 4164 }
4301 4165
4302 return 0; 4166 return 0;
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index 941d5f59e4dc..03c74b7965f8 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -383,6 +383,7 @@ struct xhci_op_regs {
383#define PORT_RWE (1 << 3) 383#define PORT_RWE (1 << 3)
384#define PORT_HIRD(p) (((p) & 0xf) << 4) 384#define PORT_HIRD(p) (((p) & 0xf) << 4)
385#define PORT_HIRD_MASK (0xf << 4) 385#define PORT_HIRD_MASK (0xf << 4)
386#define PORT_L1DS_MASK (0xff << 8)
386#define PORT_L1DS(p) (((p) & 0xff) << 8) 387#define PORT_L1DS(p) (((p) & 0xff) << 8)
387#define PORT_HLE (1 << 16) 388#define PORT_HLE (1 << 16)
388 389
@@ -934,8 +935,6 @@ struct xhci_virt_device {
934 /* Rings saved to ensure old alt settings can be re-instated */ 935 /* Rings saved to ensure old alt settings can be re-instated */
935 struct xhci_ring **ring_cache; 936 struct xhci_ring **ring_cache;
936 int num_rings_cached; 937 int num_rings_cached;
937 /* Store xHC assigned device address */
938 int address;
939#define XHCI_MAX_RINGS_CACHED 31 938#define XHCI_MAX_RINGS_CACHED 31
940 struct xhci_virt_ep eps[31]; 939 struct xhci_virt_ep eps[31];
941 struct completion cmd_completion; 940 struct completion cmd_completion;
diff --git a/drivers/usb/misc/usbtest.c b/drivers/usb/misc/usbtest.c
index aa28ac8c7607..b4152820d655 100644
--- a/drivers/usb/misc/usbtest.c
+++ b/drivers/usb/misc/usbtest.c
@@ -120,7 +120,7 @@ get_endpoints(struct usbtest_dev *dev, struct usb_interface *intf)
120 struct usb_host_endpoint *e; 120 struct usb_host_endpoint *e;
121 121
122 e = alt->endpoint + ep; 122 e = alt->endpoint + ep;
123 switch (e->desc.bmAttributes) { 123 switch (usb_endpoint_type(&e->desc)) {
124 case USB_ENDPOINT_XFER_BULK: 124 case USB_ENDPOINT_XFER_BULK:
125 break; 125 break;
126 case USB_ENDPOINT_XFER_ISOC: 126 case USB_ENDPOINT_XFER_ISOC:
@@ -437,7 +437,7 @@ alloc_sglist(int nents, int max, int vary)
437 if (max == 0) 437 if (max == 0)
438 return NULL; 438 return NULL;
439 439
440 sg = kmalloc_array(nents, sizeof *sg, GFP_KERNEL); 440 sg = kmalloc_array(nents, sizeof(*sg), GFP_KERNEL);
441 if (!sg) 441 if (!sg)
442 return NULL; 442 return NULL;
443 sg_init_table(sg, nents); 443 sg_init_table(sg, nents);
@@ -573,7 +573,7 @@ static int is_good_config(struct usbtest_dev *tdev, int len)
573{ 573{
574 struct usb_config_descriptor *config; 574 struct usb_config_descriptor *config;
575 575
576 if (len < sizeof *config) 576 if (len < sizeof(*config))
577 return 0; 577 return 0;
578 config = (struct usb_config_descriptor *) tdev->buf; 578 config = (struct usb_config_descriptor *) tdev->buf;
579 579
@@ -606,6 +606,76 @@ static int is_good_config(struct usbtest_dev *tdev, int len)
606 return 0; 606 return 0;
607} 607}
608 608
609static int is_good_ext(struct usbtest_dev *tdev, u8 *buf)
610{
611 struct usb_ext_cap_descriptor *ext;
612 u32 attr;
613
614 ext = (struct usb_ext_cap_descriptor *) buf;
615
616 if (ext->bLength != USB_DT_USB_EXT_CAP_SIZE) {
617 ERROR(tdev, "bogus usb 2.0 extension descriptor length\n");
618 return 0;
619 }
620
621 attr = le32_to_cpu(ext->bmAttributes);
622 /* bits[1:4] is used and others are reserved */
623 if (attr & ~0x1e) { /* reserved == 0 */
624 ERROR(tdev, "reserved bits set\n");
625 return 0;
626 }
627
628 return 1;
629}
630
631static int is_good_ss_cap(struct usbtest_dev *tdev, u8 *buf)
632{
633 struct usb_ss_cap_descriptor *ss;
634
635 ss = (struct usb_ss_cap_descriptor *) buf;
636
637 if (ss->bLength != USB_DT_USB_SS_CAP_SIZE) {
638 ERROR(tdev, "bogus superspeed device capability descriptor length\n");
639 return 0;
640 }
641
642 /*
643 * only bit[1] of bmAttributes is used for LTM and others are
644 * reserved
645 */
646 if (ss->bmAttributes & ~0x02) { /* reserved == 0 */
647 ERROR(tdev, "reserved bits set in bmAttributes\n");
648 return 0;
649 }
650
651 /* bits[0:3] of wSpeedSupported is used and others are reserved */
652 if (le16_to_cpu(ss->wSpeedSupported) & ~0x0f) { /* reserved == 0 */
653 ERROR(tdev, "reserved bits set in wSpeedSupported\n");
654 return 0;
655 }
656
657 return 1;
658}
659
660static int is_good_con_id(struct usbtest_dev *tdev, u8 *buf)
661{
662 struct usb_ss_container_id_descriptor *con_id;
663
664 con_id = (struct usb_ss_container_id_descriptor *) buf;
665
666 if (con_id->bLength != USB_DT_USB_SS_CONTN_ID_SIZE) {
667 ERROR(tdev, "bogus container id descriptor length\n");
668 return 0;
669 }
670
671 if (con_id->bReserved) { /* reserved == 0 */
672 ERROR(tdev, "reserved bits set\n");
673 return 0;
674 }
675
676 return 1;
677}
678
609/* sanity test for standard requests working with usb_control_mesg() and some 679/* sanity test for standard requests working with usb_control_mesg() and some
610 * of the utility functions which use it. 680 * of the utility functions which use it.
611 * 681 *
@@ -683,12 +753,96 @@ static int ch9_postconfig(struct usbtest_dev *dev)
683 753
684 /* there's always [9.4.3] a device descriptor [9.6.1] */ 754 /* there's always [9.4.3] a device descriptor [9.6.1] */
685 retval = usb_get_descriptor(udev, USB_DT_DEVICE, 0, 755 retval = usb_get_descriptor(udev, USB_DT_DEVICE, 0,
686 dev->buf, sizeof udev->descriptor); 756 dev->buf, sizeof(udev->descriptor));
687 if (retval != sizeof udev->descriptor) { 757 if (retval != sizeof(udev->descriptor)) {
688 dev_err(&iface->dev, "dev descriptor --> %d\n", retval); 758 dev_err(&iface->dev, "dev descriptor --> %d\n", retval);
689 return (retval < 0) ? retval : -EDOM; 759 return (retval < 0) ? retval : -EDOM;
690 } 760 }
691 761
762 /*
763 * there's always [9.4.3] a bos device descriptor [9.6.2] in USB
764 * 3.0 spec
765 */
766 if (le16_to_cpu(udev->descriptor.bcdUSB) >= 0x0300) {
767 struct usb_bos_descriptor *bos = NULL;
768 struct usb_dev_cap_header *header = NULL;
769 unsigned total, num, length;
770 u8 *buf;
771
772 retval = usb_get_descriptor(udev, USB_DT_BOS, 0, dev->buf,
773 sizeof(*udev->bos->desc));
774 if (retval != sizeof(*udev->bos->desc)) {
775 dev_err(&iface->dev, "bos descriptor --> %d\n", retval);
776 return (retval < 0) ? retval : -EDOM;
777 }
778
779 bos = (struct usb_bos_descriptor *)dev->buf;
780 total = le16_to_cpu(bos->wTotalLength);
781 num = bos->bNumDeviceCaps;
782
783 if (total > TBUF_SIZE)
784 total = TBUF_SIZE;
785
786 /*
787 * get generic device-level capability descriptors [9.6.2]
788 * in USB 3.0 spec
789 */
790 retval = usb_get_descriptor(udev, USB_DT_BOS, 0, dev->buf,
791 total);
792 if (retval != total) {
793 dev_err(&iface->dev, "bos descriptor set --> %d\n",
794 retval);
795 return (retval < 0) ? retval : -EDOM;
796 }
797
798 length = sizeof(*udev->bos->desc);
799 buf = dev->buf;
800 for (i = 0; i < num; i++) {
801 buf += length;
802 if (buf + sizeof(struct usb_dev_cap_header) >
803 dev->buf + total)
804 break;
805
806 header = (struct usb_dev_cap_header *)buf;
807 length = header->bLength;
808
809 if (header->bDescriptorType !=
810 USB_DT_DEVICE_CAPABILITY) {
811 dev_warn(&udev->dev, "not device capability descriptor, skip\n");
812 continue;
813 }
814
815 switch (header->bDevCapabilityType) {
816 case USB_CAP_TYPE_EXT:
817 if (buf + USB_DT_USB_EXT_CAP_SIZE >
818 dev->buf + total ||
819 !is_good_ext(dev, buf)) {
820 dev_err(&iface->dev, "bogus usb 2.0 extension descriptor\n");
821 return -EDOM;
822 }
823 break;
824 case USB_SS_CAP_TYPE:
825 if (buf + USB_DT_USB_SS_CAP_SIZE >
826 dev->buf + total ||
827 !is_good_ss_cap(dev, buf)) {
828 dev_err(&iface->dev, "bogus superspeed device capability descriptor\n");
829 return -EDOM;
830 }
831 break;
832 case CONTAINER_ID_TYPE:
833 if (buf + USB_DT_USB_SS_CONTN_ID_SIZE >
834 dev->buf + total ||
835 !is_good_con_id(dev, buf)) {
836 dev_err(&iface->dev, "bogus container id descriptor\n");
837 return -EDOM;
838 }
839 break;
840 default:
841 break;
842 }
843 }
844 }
845
692 /* there's always [9.4.3] at least one config descriptor [9.6.3] */ 846 /* there's always [9.4.3] at least one config descriptor [9.6.3] */
693 for (i = 0; i < udev->descriptor.bNumConfigurations; i++) { 847 for (i = 0; i < udev->descriptor.bNumConfigurations; i++) {
694 retval = usb_get_descriptor(udev, USB_DT_CONFIG, i, 848 retval = usb_get_descriptor(udev, USB_DT_CONFIG, i,
@@ -954,7 +1108,7 @@ test_ctrl_queue(struct usbtest_dev *dev, struct usbtest_param *param)
954 * device, but some are chosen to trigger protocol stalls 1108 * device, but some are chosen to trigger protocol stalls
955 * or short reads. 1109 * or short reads.
956 */ 1110 */
957 memset(&req, 0, sizeof req); 1111 memset(&req, 0, sizeof(req));
958 req.bRequest = USB_REQ_GET_DESCRIPTOR; 1112 req.bRequest = USB_REQ_GET_DESCRIPTOR;
959 req.bRequestType = USB_DIR_IN|USB_RECIP_DEVICE; 1113 req.bRequestType = USB_DIR_IN|USB_RECIP_DEVICE;
960 1114
@@ -1074,7 +1228,7 @@ test_ctrl_queue(struct usbtest_dev *dev, struct usbtest_param *param)
1074 if (!u) 1228 if (!u)
1075 goto cleanup; 1229 goto cleanup;
1076 1230
1077 reqp = kmalloc(sizeof *reqp, GFP_KERNEL); 1231 reqp = kmalloc(sizeof(*reqp), GFP_KERNEL);
1078 if (!reqp) 1232 if (!reqp)
1079 goto cleanup; 1233 goto cleanup;
1080 reqp->setup = req; 1234 reqp->setup = req;
@@ -1667,13 +1821,13 @@ test_iso_queue(struct usbtest_dev *dev, struct usbtest_param *param,
1667 if (param->sglen > 10) 1821 if (param->sglen > 10)
1668 return -EDOM; 1822 return -EDOM;
1669 1823
1670 memset(&context, 0, sizeof context); 1824 memset(&context, 0, sizeof(context));
1671 context.count = param->iterations * param->sglen; 1825 context.count = param->iterations * param->sglen;
1672 context.dev = dev; 1826 context.dev = dev;
1673 init_completion(&context.done); 1827 init_completion(&context.done);
1674 spin_lock_init(&context.lock); 1828 spin_lock_init(&context.lock);
1675 1829
1676 memset(urbs, 0, sizeof urbs); 1830 memset(urbs, 0, sizeof(urbs));
1677 udev = testdev_to_usbdev(dev); 1831 udev = testdev_to_usbdev(dev);
1678 dev_info(&dev->intf->dev, 1832 dev_info(&dev->intf->dev,
1679 "... iso period %d %sframes, wMaxPacket %04x\n", 1833 "... iso period %d %sframes, wMaxPacket %04x\n",
diff --git a/drivers/usb/musb/Kconfig b/drivers/usb/musb/Kconfig
index c258a97ef1b0..57dfc0cedb00 100644
--- a/drivers/usb/musb/Kconfig
+++ b/drivers/usb/musb/Kconfig
@@ -75,6 +75,7 @@ config USB_MUSB_TUSB6010
75config USB_MUSB_OMAP2PLUS 75config USB_MUSB_OMAP2PLUS
76 tristate "OMAP2430 and onwards" 76 tristate "OMAP2430 and onwards"
77 depends on ARCH_OMAP2PLUS 77 depends on ARCH_OMAP2PLUS
78 select GENERIC_PHY
78 79
79config USB_MUSB_AM35X 80config USB_MUSB_AM35X
80 tristate "AM35x" 81 tristate "AM35x"
@@ -90,7 +91,7 @@ config USB_MUSB_BLACKFIN
90 depends on (BF54x && !BF544) || (BF52x && ! BF522 && !BF523) 91 depends on (BF54x && !BF544) || (BF52x && ! BF522 && !BF523)
91 92
92config USB_MUSB_UX500 93config USB_MUSB_UX500
93 tristate "U8500 and U5500" 94 tristate "Ux500 platforms"
94 95
95endchoice 96endchoice
96 97
@@ -112,7 +113,7 @@ choice
112 allow using DMA on multiplatform kernels. 113 allow using DMA on multiplatform kernels.
113 114
114config USB_UX500_DMA 115config USB_UX500_DMA
115 bool 'ST Ericsson U8500 and U5500' 116 bool 'ST Ericsson Ux500'
116 depends on USB_MUSB_UX500 117 depends on USB_MUSB_UX500
117 help 118 help
118 Enable DMA transfers on UX500 platforms. 119 Enable DMA transfers on UX500 platforms.
diff --git a/drivers/usb/musb/am35x.c b/drivers/usb/musb/am35x.c
index 5c310c664218..ca45b39db5b9 100644
--- a/drivers/usb/musb/am35x.c
+++ b/drivers/usb/musb/am35x.c
@@ -89,7 +89,6 @@ struct am35x_glue {
89 struct clk *phy_clk; 89 struct clk *phy_clk;
90 struct clk *clk; 90 struct clk *clk;
91}; 91};
92#define glue_to_musb(g) platform_get_drvdata(g->musb)
93 92
94/* 93/*
95 * am35x_musb_enable - enable interrupts 94 * am35x_musb_enable - enable interrupts
@@ -452,14 +451,18 @@ static const struct musb_platform_ops am35x_ops = {
452 .set_vbus = am35x_musb_set_vbus, 451 .set_vbus = am35x_musb_set_vbus,
453}; 452};
454 453
455static u64 am35x_dmamask = DMA_BIT_MASK(32); 454static const struct platform_device_info am35x_dev_info = {
455 .name = "musb-hdrc",
456 .id = PLATFORM_DEVID_AUTO,
457 .dma_mask = DMA_BIT_MASK(32),
458};
456 459
457static int am35x_probe(struct platform_device *pdev) 460static int am35x_probe(struct platform_device *pdev)
458{ 461{
459 struct musb_hdrc_platform_data *pdata = dev_get_platdata(&pdev->dev); 462 struct musb_hdrc_platform_data *pdata = dev_get_platdata(&pdev->dev);
460 struct platform_device *musb; 463 struct platform_device *musb;
461 struct am35x_glue *glue; 464 struct am35x_glue *glue;
462 465 struct platform_device_info pinfo;
463 struct clk *phy_clk; 466 struct clk *phy_clk;
464 struct clk *clk; 467 struct clk *clk;
465 468
@@ -471,12 +474,6 @@ static int am35x_probe(struct platform_device *pdev)
471 goto err0; 474 goto err0;
472 } 475 }
473 476
474 musb = platform_device_alloc("musb-hdrc", PLATFORM_DEVID_AUTO);
475 if (!musb) {
476 dev_err(&pdev->dev, "failed to allocate musb device\n");
477 goto err1;
478 }
479
480 phy_clk = clk_get(&pdev->dev, "fck"); 477 phy_clk = clk_get(&pdev->dev, "fck");
481 if (IS_ERR(phy_clk)) { 478 if (IS_ERR(phy_clk)) {
482 dev_err(&pdev->dev, "failed to get PHY clock\n"); 479 dev_err(&pdev->dev, "failed to get PHY clock\n");
@@ -503,12 +500,7 @@ static int am35x_probe(struct platform_device *pdev)
503 goto err6; 500 goto err6;
504 } 501 }
505 502
506 musb->dev.parent = &pdev->dev;
507 musb->dev.dma_mask = &am35x_dmamask;
508 musb->dev.coherent_dma_mask = am35x_dmamask;
509
510 glue->dev = &pdev->dev; 503 glue->dev = &pdev->dev;
511 glue->musb = musb;
512 glue->phy_clk = phy_clk; 504 glue->phy_clk = phy_clk;
513 glue->clk = clk; 505 glue->clk = clk;
514 506
@@ -516,22 +508,17 @@ static int am35x_probe(struct platform_device *pdev)
516 508
517 platform_set_drvdata(pdev, glue); 509 platform_set_drvdata(pdev, glue);
518 510
519 ret = platform_device_add_resources(musb, pdev->resource, 511 pinfo = am35x_dev_info;
520 pdev->num_resources); 512 pinfo.parent = &pdev->dev;
521 if (ret) { 513 pinfo.res = pdev->resource;
522 dev_err(&pdev->dev, "failed to add resources\n"); 514 pinfo.num_res = pdev->num_resources;
523 goto err7; 515 pinfo.data = pdata;
524 } 516 pinfo.size_data = sizeof(*pdata);
525 517
526 ret = platform_device_add_data(musb, pdata, sizeof(*pdata)); 518 glue->musb = musb = platform_device_register_full(&pinfo);
527 if (ret) { 519 if (IS_ERR(musb)) {
528 dev_err(&pdev->dev, "failed to add platform_data\n"); 520 ret = PTR_ERR(musb);
529 goto err7; 521 dev_err(&pdev->dev, "failed to register musb device: %d\n", ret);
530 }
531
532 ret = platform_device_add(musb);
533 if (ret) {
534 dev_err(&pdev->dev, "failed to register musb device\n");
535 goto err7; 522 goto err7;
536 } 523 }
537 524
@@ -550,9 +537,6 @@ err4:
550 clk_put(phy_clk); 537 clk_put(phy_clk);
551 538
552err3: 539err3:
553 platform_device_put(musb);
554
555err1:
556 kfree(glue); 540 kfree(glue);
557 541
558err0: 542err0:
@@ -615,23 +599,16 @@ static int am35x_resume(struct device *dev)
615 599
616 return 0; 600 return 0;
617} 601}
618
619static struct dev_pm_ops am35x_pm_ops = {
620 .suspend = am35x_suspend,
621 .resume = am35x_resume,
622};
623
624#define DEV_PM_OPS &am35x_pm_ops
625#else
626#define DEV_PM_OPS NULL
627#endif 602#endif
628 603
604static SIMPLE_DEV_PM_OPS(am35x_pm_ops, am35x_suspend, am35x_resume);
605
629static struct platform_driver am35x_driver = { 606static struct platform_driver am35x_driver = {
630 .probe = am35x_probe, 607 .probe = am35x_probe,
631 .remove = am35x_remove, 608 .remove = am35x_remove,
632 .driver = { 609 .driver = {
633 .name = "musb-am35x", 610 .name = "musb-am35x",
634 .pm = DEV_PM_OPS, 611 .pm = &am35x_pm_ops,
635 }, 612 },
636}; 613};
637 614
diff --git a/drivers/usb/musb/blackfin.c b/drivers/usb/musb/blackfin.c
index 72e2056b6082..d9692f78e227 100644
--- a/drivers/usb/musb/blackfin.c
+++ b/drivers/usb/musb/blackfin.c
@@ -561,23 +561,16 @@ static int bfin_resume(struct device *dev)
561 561
562 return 0; 562 return 0;
563} 563}
564
565static struct dev_pm_ops bfin_pm_ops = {
566 .suspend = bfin_suspend,
567 .resume = bfin_resume,
568};
569
570#define DEV_PM_OPS &bfin_pm_ops
571#else
572#define DEV_PM_OPS NULL
573#endif 564#endif
574 565
566static SIMPLE_DEV_PM_OPS(bfin_pm_ops, bfin_suspend, bfin_resume);
567
575static struct platform_driver bfin_driver = { 568static struct platform_driver bfin_driver = {
576 .probe = bfin_probe, 569 .probe = bfin_probe,
577 .remove = __exit_p(bfin_remove), 570 .remove = __exit_p(bfin_remove),
578 .driver = { 571 .driver = {
579 .name = "musb-blackfin", 572 .name = "musb-blackfin",
580 .pm = DEV_PM_OPS, 573 .pm = &bfin_pm_ops,
581 }, 574 },
582}; 575};
583 576
diff --git a/drivers/usb/musb/da8xx.c b/drivers/usb/musb/da8xx.c
index d9ddf4122f37..2f2c1cb36421 100644
--- a/drivers/usb/musb/da8xx.c
+++ b/drivers/usb/musb/da8xx.c
@@ -472,7 +472,11 @@ static const struct musb_platform_ops da8xx_ops = {
472 .set_vbus = da8xx_musb_set_vbus, 472 .set_vbus = da8xx_musb_set_vbus,
473}; 473};
474 474
475static u64 da8xx_dmamask = DMA_BIT_MASK(32); 475static const struct platform_device_info da8xx_dev_info = {
476 .name = "musb-hdrc",
477 .id = PLATFORM_DEVID_AUTO,
478 .dma_mask = DMA_BIT_MASK(32),
479};
476 480
477static int da8xx_probe(struct platform_device *pdev) 481static int da8xx_probe(struct platform_device *pdev)
478{ 482{
@@ -480,7 +484,7 @@ static int da8xx_probe(struct platform_device *pdev)
480 struct musb_hdrc_platform_data *pdata = dev_get_platdata(&pdev->dev); 484 struct musb_hdrc_platform_data *pdata = dev_get_platdata(&pdev->dev);
481 struct platform_device *musb; 485 struct platform_device *musb;
482 struct da8xx_glue *glue; 486 struct da8xx_glue *glue;
483 487 struct platform_device_info pinfo;
484 struct clk *clk; 488 struct clk *clk;
485 489
486 int ret = -ENOMEM; 490 int ret = -ENOMEM;
@@ -491,12 +495,6 @@ static int da8xx_probe(struct platform_device *pdev)
491 goto err0; 495 goto err0;
492 } 496 }
493 497
494 musb = platform_device_alloc("musb-hdrc", PLATFORM_DEVID_AUTO);
495 if (!musb) {
496 dev_err(&pdev->dev, "failed to allocate musb device\n");
497 goto err1;
498 }
499
500 clk = clk_get(&pdev->dev, "usb20"); 498 clk = clk_get(&pdev->dev, "usb20");
501 if (IS_ERR(clk)) { 499 if (IS_ERR(clk)) {
502 dev_err(&pdev->dev, "failed to get clock\n"); 500 dev_err(&pdev->dev, "failed to get clock\n");
@@ -510,12 +508,7 @@ static int da8xx_probe(struct platform_device *pdev)
510 goto err4; 508 goto err4;
511 } 509 }
512 510
513 musb->dev.parent = &pdev->dev;
514 musb->dev.dma_mask = &da8xx_dmamask;
515 musb->dev.coherent_dma_mask = da8xx_dmamask;
516
517 glue->dev = &pdev->dev; 511 glue->dev = &pdev->dev;
518 glue->musb = musb;
519 glue->clk = clk; 512 glue->clk = clk;
520 513
521 pdata->platform_ops = &da8xx_ops; 514 pdata->platform_ops = &da8xx_ops;
@@ -535,22 +528,17 @@ static int da8xx_probe(struct platform_device *pdev)
535 musb_resources[1].end = pdev->resource[1].end; 528 musb_resources[1].end = pdev->resource[1].end;
536 musb_resources[1].flags = pdev->resource[1].flags; 529 musb_resources[1].flags = pdev->resource[1].flags;
537 530
538 ret = platform_device_add_resources(musb, musb_resources, 531 pinfo = da8xx_dev_info;
539 ARRAY_SIZE(musb_resources)); 532 pinfo.parent = &pdev->dev;
540 if (ret) { 533 pinfo.res = musb_resources;
541 dev_err(&pdev->dev, "failed to add resources\n"); 534 pinfo.num_res = ARRAY_SIZE(musb_resources);
542 goto err5; 535 pinfo.data = pdata;
543 } 536 pinfo.size_data = sizeof(*pdata);
544 537
545 ret = platform_device_add_data(musb, pdata, sizeof(*pdata)); 538 glue->musb = musb = platform_device_register_full(&pinfo);
546 if (ret) { 539 if (IS_ERR(musb)) {
547 dev_err(&pdev->dev, "failed to add platform_data\n"); 540 ret = PTR_ERR(musb);
548 goto err5; 541 dev_err(&pdev->dev, "failed to register musb device: %d\n", ret);
549 }
550
551 ret = platform_device_add(musb);
552 if (ret) {
553 dev_err(&pdev->dev, "failed to register musb device\n");
554 goto err5; 542 goto err5;
555 } 543 }
556 544
@@ -563,9 +551,6 @@ err4:
563 clk_put(clk); 551 clk_put(clk);
564 552
565err3: 553err3:
566 platform_device_put(musb);
567
568err1:
569 kfree(glue); 554 kfree(glue);
570 555
571err0: 556err0:
diff --git a/drivers/usb/musb/davinci.c b/drivers/usb/musb/davinci.c
index ed0834e2b72e..1121fd741bf8 100644
--- a/drivers/usb/musb/davinci.c
+++ b/drivers/usb/musb/davinci.c
@@ -505,14 +505,19 @@ static const struct musb_platform_ops davinci_ops = {
505 .set_vbus = davinci_musb_set_vbus, 505 .set_vbus = davinci_musb_set_vbus,
506}; 506};
507 507
508static u64 davinci_dmamask = DMA_BIT_MASK(32); 508static const struct platform_device_info davinci_dev_info = {
509 .name = "musb-hdrc",
510 .id = PLATFORM_DEVID_AUTO,
511 .dma_mask = DMA_BIT_MASK(32),
512};
509 513
510static int davinci_probe(struct platform_device *pdev) 514static int davinci_probe(struct platform_device *pdev)
511{ 515{
512 struct resource musb_resources[2]; 516 struct resource musb_resources[3];
513 struct musb_hdrc_platform_data *pdata = dev_get_platdata(&pdev->dev); 517 struct musb_hdrc_platform_data *pdata = dev_get_platdata(&pdev->dev);
514 struct platform_device *musb; 518 struct platform_device *musb;
515 struct davinci_glue *glue; 519 struct davinci_glue *glue;
520 struct platform_device_info pinfo;
516 struct clk *clk; 521 struct clk *clk;
517 522
518 int ret = -ENOMEM; 523 int ret = -ENOMEM;
@@ -523,12 +528,6 @@ static int davinci_probe(struct platform_device *pdev)
523 goto err0; 528 goto err0;
524 } 529 }
525 530
526 musb = platform_device_alloc("musb-hdrc", PLATFORM_DEVID_AUTO);
527 if (!musb) {
528 dev_err(&pdev->dev, "failed to allocate musb device\n");
529 goto err1;
530 }
531
532 clk = clk_get(&pdev->dev, "usb"); 531 clk = clk_get(&pdev->dev, "usb");
533 if (IS_ERR(clk)) { 532 if (IS_ERR(clk)) {
534 dev_err(&pdev->dev, "failed to get clock\n"); 533 dev_err(&pdev->dev, "failed to get clock\n");
@@ -542,12 +541,7 @@ static int davinci_probe(struct platform_device *pdev)
542 goto err4; 541 goto err4;
543 } 542 }
544 543
545 musb->dev.parent = &pdev->dev;
546 musb->dev.dma_mask = &davinci_dmamask;
547 musb->dev.coherent_dma_mask = davinci_dmamask;
548
549 glue->dev = &pdev->dev; 544 glue->dev = &pdev->dev;
550 glue->musb = musb;
551 glue->clk = clk; 545 glue->clk = clk;
552 546
553 pdata->platform_ops = &davinci_ops; 547 pdata->platform_ops = &davinci_ops;
@@ -567,22 +561,26 @@ static int davinci_probe(struct platform_device *pdev)
567 musb_resources[1].end = pdev->resource[1].end; 561 musb_resources[1].end = pdev->resource[1].end;
568 musb_resources[1].flags = pdev->resource[1].flags; 562 musb_resources[1].flags = pdev->resource[1].flags;
569 563
570 ret = platform_device_add_resources(musb, musb_resources, 564 /*
571 ARRAY_SIZE(musb_resources)); 565 * For DM6467 3 resources are passed. A placeholder for the 3rd
572 if (ret) { 566 * resource is always there, so it's safe to always copy it...
573 dev_err(&pdev->dev, "failed to add resources\n"); 567 */
574 goto err5; 568 musb_resources[2].name = pdev->resource[2].name;
575 } 569 musb_resources[2].start = pdev->resource[2].start;
576 570 musb_resources[2].end = pdev->resource[2].end;
577 ret = platform_device_add_data(musb, pdata, sizeof(*pdata)); 571 musb_resources[2].flags = pdev->resource[2].flags;
578 if (ret) { 572
579 dev_err(&pdev->dev, "failed to add platform_data\n"); 573 pinfo = davinci_dev_info;
580 goto err5; 574 pinfo.parent = &pdev->dev;
581 } 575 pinfo.res = musb_resources;
582 576 pinfo.num_res = ARRAY_SIZE(musb_resources);
583 ret = platform_device_add(musb); 577 pinfo.data = pdata;
584 if (ret) { 578 pinfo.size_data = sizeof(*pdata);
585 dev_err(&pdev->dev, "failed to register musb device\n"); 579
580 glue->musb = musb = platform_device_register_full(&pinfo);
581 if (IS_ERR(musb)) {
582 ret = PTR_ERR(musb);
583 dev_err(&pdev->dev, "failed to register musb device: %d\n", ret);
586 goto err5; 584 goto err5;
587 } 585 }
588 586
@@ -595,9 +593,6 @@ err4:
595 clk_put(clk); 593 clk_put(clk);
596 594
597err3: 595err3:
598 platform_device_put(musb);
599
600err1:
601 kfree(glue); 596 kfree(glue);
602 597
603err0: 598err0:
diff --git a/drivers/usb/musb/musb_am335x.c b/drivers/usb/musb/musb_am335x.c
index 41ac5b5b57ce..8be9b02c3cc2 100644
--- a/drivers/usb/musb/musb_am335x.c
+++ b/drivers/usb/musb/musb_am335x.c
@@ -46,7 +46,7 @@ static struct platform_driver am335x_child_driver = {
46 .remove = am335x_child_remove, 46 .remove = am335x_child_remove,
47 .driver = { 47 .driver = {
48 .name = "am335x-usb-childs", 48 .name = "am335x-usb-childs",
49 .of_match_table = of_match_ptr(am335x_child_of_match), 49 .of_match_table = am335x_child_of_match,
50 }, 50 },
51}; 51};
52 52
diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index cd70cc886171..0a43329569d1 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -617,7 +617,7 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
617 /* case 3 << MUSB_DEVCTL_VBUS_SHIFT: */ 617 /* case 3 << MUSB_DEVCTL_VBUS_SHIFT: */
618 default: 618 default:
619 s = "VALID"; break; 619 s = "VALID"; break;
620 }; s; }), 620 } s; }),
621 VBUSERR_RETRY_COUNT - musb->vbuserr_retry, 621 VBUSERR_RETRY_COUNT - musb->vbuserr_retry,
622 musb->port1_status); 622 musb->port1_status);
623 623
@@ -1809,8 +1809,7 @@ static void musb_free(struct musb *musb)
1809 disable_irq_wake(musb->nIrq); 1809 disable_irq_wake(musb->nIrq);
1810 free_irq(musb->nIrq, musb); 1810 free_irq(musb->nIrq, musb);
1811 } 1811 }
1812 if (musb->dma_controller) 1812 cancel_work_sync(&musb->irq_work);
1813 dma_controller_destroy(musb->dma_controller);
1814 1813
1815 musb_host_free(musb); 1814 musb_host_free(musb);
1816} 1815}
@@ -1885,8 +1884,13 @@ musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl)
1885 1884
1886 pm_runtime_get_sync(musb->controller); 1885 pm_runtime_get_sync(musb->controller);
1887 1886
1888 if (use_dma && dev->dma_mask) 1887 if (use_dma && dev->dma_mask) {
1889 musb->dma_controller = dma_controller_create(musb, musb->mregs); 1888 musb->dma_controller = dma_controller_create(musb, musb->mregs);
1889 if (IS_ERR(musb->dma_controller)) {
1890 status = PTR_ERR(musb->dma_controller);
1891 goto fail2_5;
1892 }
1893 }
1890 1894
1891 /* be sure interrupts are disabled before connecting ISR */ 1895 /* be sure interrupts are disabled before connecting ISR */
1892 musb_platform_disable(musb); 1896 musb_platform_disable(musb);
@@ -1946,6 +1950,8 @@ musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl)
1946 if (status < 0) 1950 if (status < 0)
1947 goto fail3; 1951 goto fail3;
1948 status = musb_gadget_setup(musb); 1952 status = musb_gadget_setup(musb);
1953 if (status)
1954 musb_host_cleanup(musb);
1949 break; 1955 break;
1950 default: 1956 default:
1951 dev_err(dev, "unsupported port mode %d\n", musb->port_mode); 1957 dev_err(dev, "unsupported port mode %d\n", musb->port_mode);
@@ -1972,10 +1978,12 @@ fail5:
1972 1978
1973fail4: 1979fail4:
1974 musb_gadget_cleanup(musb); 1980 musb_gadget_cleanup(musb);
1981 musb_host_cleanup(musb);
1975 1982
1976fail3: 1983fail3:
1977 if (musb->dma_controller) 1984 if (musb->dma_controller)
1978 dma_controller_destroy(musb->dma_controller); 1985 dma_controller_destroy(musb->dma_controller);
1986fail2_5:
1979 pm_runtime_put_sync(musb->controller); 1987 pm_runtime_put_sync(musb->controller);
1980 1988
1981fail2: 1989fail2:
@@ -2032,6 +2040,9 @@ static int musb_remove(struct platform_device *pdev)
2032 musb_exit_debugfs(musb); 2040 musb_exit_debugfs(musb);
2033 musb_shutdown(pdev); 2041 musb_shutdown(pdev);
2034 2042
2043 if (musb->dma_controller)
2044 dma_controller_destroy(musb->dma_controller);
2045
2035 musb_free(musb); 2046 musb_free(musb);
2036 device_init_wakeup(dev, 0); 2047 device_init_wakeup(dev, 0);
2037 return 0; 2048 return 0;
diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h
index 1c5bf75ee8ff..29f7cd7c7964 100644
--- a/drivers/usb/musb/musb_core.h
+++ b/drivers/usb/musb/musb_core.h
@@ -46,6 +46,7 @@
46#include <linux/usb.h> 46#include <linux/usb.h>
47#include <linux/usb/otg.h> 47#include <linux/usb/otg.h>
48#include <linux/usb/musb.h> 48#include <linux/usb/musb.h>
49#include <linux/phy/phy.h>
49 50
50struct musb; 51struct musb;
51struct musb_hw_ep; 52struct musb_hw_ep;
@@ -341,6 +342,7 @@ struct musb {
341 u16 int_tx; 342 u16 int_tx;
342 343
343 struct usb_phy *xceiv; 344 struct usb_phy *xceiv;
345 struct phy *phy;
344 346
345 int nIrq; 347 int nIrq;
346 unsigned irq_wake:1; 348 unsigned irq_wake:1;
diff --git a/drivers/usb/musb/musb_cppi41.c b/drivers/usb/musb/musb_cppi41.c
index ae959746f77f..ff9d6de2b746 100644
--- a/drivers/usb/musb/musb_cppi41.c
+++ b/drivers/usb/musb/musb_cppi41.c
@@ -484,6 +484,7 @@ static int cppi41_dma_controller_start(struct cppi41_dma_controller *controller)
484 if (ret) 484 if (ret)
485 goto err; 485 goto err;
486 486
487 ret = -EINVAL;
487 if (port > MUSB_DMA_NUM_CHANNELS || !port) 488 if (port > MUSB_DMA_NUM_CHANNELS || !port)
488 goto err; 489 goto err;
489 if (is_tx) 490 if (is_tx)
@@ -503,6 +504,7 @@ static int cppi41_dma_controller_start(struct cppi41_dma_controller *controller)
503 dc = dma_request_slave_channel(dev, str); 504 dc = dma_request_slave_channel(dev, str);
504 if (!dc) { 505 if (!dc) {
505 dev_err(dev, "Falied to request %s.\n", str); 506 dev_err(dev, "Falied to request %s.\n", str);
507 ret = -EPROBE_DEFER;
506 goto err; 508 goto err;
507 } 509 }
508 cppi41_channel->dc = dc; 510 cppi41_channel->dc = dc;
@@ -510,7 +512,7 @@ static int cppi41_dma_controller_start(struct cppi41_dma_controller *controller)
510 return 0; 512 return 0;
511err: 513err:
512 cppi41_release_all_dma_chans(controller); 514 cppi41_release_all_dma_chans(controller);
513 return -EINVAL; 515 return ret;
514} 516}
515 517
516void dma_controller_destroy(struct dma_controller *c) 518void dma_controller_destroy(struct dma_controller *c)
@@ -526,7 +528,7 @@ struct dma_controller *dma_controller_create(struct musb *musb,
526 void __iomem *base) 528 void __iomem *base)
527{ 529{
528 struct cppi41_dma_controller *controller; 530 struct cppi41_dma_controller *controller;
529 int ret; 531 int ret = 0;
530 532
531 if (!musb->controller->of_node) { 533 if (!musb->controller->of_node) {
532 dev_err(musb->controller, "Need DT for the DMA engine.\n"); 534 dev_err(musb->controller, "Need DT for the DMA engine.\n");
@@ -553,5 +555,7 @@ struct dma_controller *dma_controller_create(struct musb *musb,
553plat_get_fail: 555plat_get_fail:
554 kfree(controller); 556 kfree(controller);
555kzalloc_fail: 557kzalloc_fail:
558 if (ret == -EPROBE_DEFER)
559 return ERR_PTR(ret);
556 return NULL; 560 return NULL;
557} 561}
diff --git a/drivers/usb/musb/musb_dsps.c b/drivers/usb/musb/musb_dsps.c
index bd4138d80a48..1901f6fe5807 100644
--- a/drivers/usb/musb/musb_dsps.c
+++ b/drivers/usb/musb/musb_dsps.c
@@ -121,6 +121,43 @@ struct dsps_glue {
121 unsigned long last_timer; /* last timer data for each instance */ 121 unsigned long last_timer; /* last timer data for each instance */
122}; 122};
123 123
124static void dsps_musb_try_idle(struct musb *musb, unsigned long timeout)
125{
126 struct device *dev = musb->controller;
127 struct dsps_glue *glue = dev_get_drvdata(dev->parent);
128
129 if (timeout == 0)
130 timeout = jiffies + msecs_to_jiffies(3);
131
132 /* Never idle if active, or when VBUS timeout is not set as host */
133 if (musb->is_active || (musb->a_wait_bcon == 0 &&
134 musb->xceiv->state == OTG_STATE_A_WAIT_BCON)) {
135 dev_dbg(musb->controller, "%s active, deleting timer\n",
136 usb_otg_state_string(musb->xceiv->state));
137 del_timer(&glue->timer);
138 glue->last_timer = jiffies;
139 return;
140 }
141 if (musb->port_mode != MUSB_PORT_MODE_DUAL_ROLE)
142 return;
143
144 if (!musb->g.dev.driver)
145 return;
146
147 if (time_after(glue->last_timer, timeout) &&
148 timer_pending(&glue->timer)) {
149 dev_dbg(musb->controller,
150 "Longer idle timer already pending, ignoring...\n");
151 return;
152 }
153 glue->last_timer = timeout;
154
155 dev_dbg(musb->controller, "%s inactive, starting idle timer for %u ms\n",
156 usb_otg_state_string(musb->xceiv->state),
157 jiffies_to_msecs(timeout - jiffies));
158 mod_timer(&glue->timer, timeout);
159}
160
124/** 161/**
125 * dsps_musb_enable - enable interrupts 162 * dsps_musb_enable - enable interrupts
126 */ 163 */
@@ -143,6 +180,7 @@ static void dsps_musb_enable(struct musb *musb)
143 /* Force the DRVVBUS IRQ so we can start polling for ID change. */ 180 /* Force the DRVVBUS IRQ so we can start polling for ID change. */
144 dsps_writel(reg_base, wrp->coreintr_set, 181 dsps_writel(reg_base, wrp->coreintr_set,
145 (1 << wrp->drvvbus) << wrp->usb_shift); 182 (1 << wrp->drvvbus) << wrp->usb_shift);
183 dsps_musb_try_idle(musb, 0);
146} 184}
147 185
148/** 186/**
@@ -171,6 +209,7 @@ static void otg_timer(unsigned long _musb)
171 const struct dsps_musb_wrapper *wrp = glue->wrp; 209 const struct dsps_musb_wrapper *wrp = glue->wrp;
172 u8 devctl; 210 u8 devctl;
173 unsigned long flags; 211 unsigned long flags;
212 int skip_session = 0;
174 213
175 /* 214 /*
176 * We poll because DSPS IP's won't expose several OTG-critical 215 * We poll because DSPS IP's won't expose several OTG-critical
@@ -183,10 +222,12 @@ static void otg_timer(unsigned long _musb)
183 spin_lock_irqsave(&musb->lock, flags); 222 spin_lock_irqsave(&musb->lock, flags);
184 switch (musb->xceiv->state) { 223 switch (musb->xceiv->state) {
185 case OTG_STATE_A_WAIT_BCON: 224 case OTG_STATE_A_WAIT_BCON:
186 devctl &= ~MUSB_DEVCTL_SESSION; 225 dsps_writeb(musb->mregs, MUSB_DEVCTL, 0);
187 dsps_writeb(musb->mregs, MUSB_DEVCTL, devctl); 226 skip_session = 1;
227 /* fall */
188 228
189 devctl = dsps_readb(musb->mregs, MUSB_DEVCTL); 229 case OTG_STATE_A_IDLE:
230 case OTG_STATE_B_IDLE:
190 if (devctl & MUSB_DEVCTL_BDEVICE) { 231 if (devctl & MUSB_DEVCTL_BDEVICE) {
191 musb->xceiv->state = OTG_STATE_B_IDLE; 232 musb->xceiv->state = OTG_STATE_B_IDLE;
192 MUSB_DEV_MODE(musb); 233 MUSB_DEV_MODE(musb);
@@ -194,60 +235,21 @@ static void otg_timer(unsigned long _musb)
194 musb->xceiv->state = OTG_STATE_A_IDLE; 235 musb->xceiv->state = OTG_STATE_A_IDLE;
195 MUSB_HST_MODE(musb); 236 MUSB_HST_MODE(musb);
196 } 237 }
238 if (!(devctl & MUSB_DEVCTL_SESSION) && !skip_session)
239 dsps_writeb(mregs, MUSB_DEVCTL, MUSB_DEVCTL_SESSION);
240 mod_timer(&glue->timer, jiffies + wrp->poll_seconds * HZ);
197 break; 241 break;
198 case OTG_STATE_A_WAIT_VFALL: 242 case OTG_STATE_A_WAIT_VFALL:
199 musb->xceiv->state = OTG_STATE_A_WAIT_VRISE; 243 musb->xceiv->state = OTG_STATE_A_WAIT_VRISE;
200 dsps_writel(musb->ctrl_base, wrp->coreintr_set, 244 dsps_writel(musb->ctrl_base, wrp->coreintr_set,
201 MUSB_INTR_VBUSERROR << wrp->usb_shift); 245 MUSB_INTR_VBUSERROR << wrp->usb_shift);
202 break; 246 break;
203 case OTG_STATE_B_IDLE:
204 devctl = dsps_readb(mregs, MUSB_DEVCTL);
205 if (devctl & MUSB_DEVCTL_BDEVICE)
206 mod_timer(&glue->timer,
207 jiffies + wrp->poll_seconds * HZ);
208 else
209 musb->xceiv->state = OTG_STATE_A_IDLE;
210 break;
211 default: 247 default:
212 break; 248 break;
213 } 249 }
214 spin_unlock_irqrestore(&musb->lock, flags); 250 spin_unlock_irqrestore(&musb->lock, flags);
215} 251}
216 252
217static void dsps_musb_try_idle(struct musb *musb, unsigned long timeout)
218{
219 struct device *dev = musb->controller;
220 struct dsps_glue *glue = dev_get_drvdata(dev->parent);
221
222 if (timeout == 0)
223 timeout = jiffies + msecs_to_jiffies(3);
224
225 /* Never idle if active, or when VBUS timeout is not set as host */
226 if (musb->is_active || (musb->a_wait_bcon == 0 &&
227 musb->xceiv->state == OTG_STATE_A_WAIT_BCON)) {
228 dev_dbg(musb->controller, "%s active, deleting timer\n",
229 usb_otg_state_string(musb->xceiv->state));
230 del_timer(&glue->timer);
231 glue->last_timer = jiffies;
232 return;
233 }
234 if (musb->port_mode == MUSB_PORT_MODE_HOST)
235 return;
236
237 if (time_after(glue->last_timer, timeout) &&
238 timer_pending(&glue->timer)) {
239 dev_dbg(musb->controller,
240 "Longer idle timer already pending, ignoring...\n");
241 return;
242 }
243 glue->last_timer = timeout;
244
245 dev_dbg(musb->controller, "%s inactive, starting idle timer for %u ms\n",
246 usb_otg_state_string(musb->xceiv->state),
247 jiffies_to_msecs(timeout - jiffies));
248 mod_timer(&glue->timer, timeout);
249}
250
251static irqreturn_t dsps_interrupt(int irq, void *hci) 253static irqreturn_t dsps_interrupt(int irq, void *hci)
252{ 254{
253 struct musb *musb = hci; 255 struct musb *musb = hci;
@@ -443,7 +445,7 @@ static int get_musb_port_mode(struct device *dev)
443 case USB_DR_MODE_OTG: 445 case USB_DR_MODE_OTG:
444 default: 446 default:
445 return MUSB_PORT_MODE_DUAL_ROLE; 447 return MUSB_PORT_MODE_DUAL_ROLE;
446 }; 448 }
447} 449}
448 450
449static int dsps_create_musb_pdev(struct dsps_glue *glue, 451static int dsps_create_musb_pdev(struct dsps_glue *glue,
@@ -631,7 +633,7 @@ static struct platform_driver dsps_usbss_driver = {
631 .remove = dsps_remove, 633 .remove = dsps_remove,
632 .driver = { 634 .driver = {
633 .name = "musb-dsps", 635 .name = "musb-dsps",
634 .of_match_table = of_match_ptr(musb_dsps_of_match), 636 .of_match_table = musb_dsps_of_match,
635 }, 637 },
636}; 638};
637 639
diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c
index 3671898a4535..d2d3a173b315 100644
--- a/drivers/usb/musb/musb_gadget.c
+++ b/drivers/usb/musb/musb_gadget.c
@@ -1121,7 +1121,7 @@ static int musb_gadget_enable(struct usb_ep *ep,
1121 case USB_ENDPOINT_XFER_BULK: s = "bulk"; break; 1121 case USB_ENDPOINT_XFER_BULK: s = "bulk"; break;
1122 case USB_ENDPOINT_XFER_INT: s = "int"; break; 1122 case USB_ENDPOINT_XFER_INT: s = "int"; break;
1123 default: s = "iso"; break; 1123 default: s = "iso"; break;
1124 }; s; }), 1124 } s; }),
1125 musb_ep->is_in ? "IN" : "OUT", 1125 musb_ep->is_in ? "IN" : "OUT",
1126 musb_ep->dma ? "dma, " : "", 1126 musb_ep->dma ? "dma, " : "",
1127 musb_ep->packet_sz); 1127 musb_ep->packet_sz);
diff --git a/drivers/usb/musb/musb_host.c b/drivers/usb/musb/musb_host.c
index 9a2b8c85f19a..6582a20bec05 100644
--- a/drivers/usb/musb/musb_host.c
+++ b/drivers/usb/musb/musb_host.c
@@ -253,7 +253,7 @@ musb_start_urb(struct musb *musb, int is_in, struct musb_qh *qh)
253 case USB_ENDPOINT_XFER_BULK: s = "-bulk"; break; 253 case USB_ENDPOINT_XFER_BULK: s = "-bulk"; break;
254 case USB_ENDPOINT_XFER_ISOC: s = "-iso"; break; 254 case USB_ENDPOINT_XFER_ISOC: s = "-iso"; break;
255 default: s = "-intr"; break; 255 default: s = "-intr"; break;
256 }; s; }), 256 } s; }),
257 epnum, buf + offset, len); 257 epnum, buf + offset, len);
258 258
259 /* Configure endpoint */ 259 /* Configure endpoint */
diff --git a/drivers/usb/musb/musb_virthub.c b/drivers/usb/musb/musb_virthub.c
index d1d6b83aabca..9af6bba5eac9 100644
--- a/drivers/usb/musb/musb_virthub.c
+++ b/drivers/usb/musb/musb_virthub.c
@@ -220,6 +220,23 @@ int musb_hub_status_data(struct usb_hcd *hcd, char *buf)
220 return retval; 220 return retval;
221} 221}
222 222
223static int musb_has_gadget(struct musb *musb)
224{
225 /*
226 * In host-only mode we start a connection right away. In OTG mode
227 * we have to wait until we loaded a gadget. We don't really need a
228 * gadget if we operate as a host but we should not start a session
229 * as a device without a gadget or else we explode.
230 */
231#ifdef CONFIG_USB_MUSB_HOST
232 return 1;
233#else
234 if (musb->port_mode == MUSB_PORT_MODE_HOST)
235 return 1;
236 return musb->g.dev.driver != NULL;
237#endif
238}
239
223int musb_hub_control( 240int musb_hub_control(
224 struct usb_hcd *hcd, 241 struct usb_hcd *hcd,
225 u16 typeReq, 242 u16 typeReq,
@@ -362,7 +379,7 @@ int musb_hub_control(
362 * initialization logic, e.g. for OTG, or change any 379 * initialization logic, e.g. for OTG, or change any
363 * logic relating to VBUS power-up. 380 * logic relating to VBUS power-up.
364 */ 381 */
365 if (!hcd->self.is_b_host) 382 if (!hcd->self.is_b_host && musb_has_gadget(musb))
366 musb_start(musb); 383 musb_start(musb);
367 break; 384 break;
368 case USB_PORT_FEAT_RESET: 385 case USB_PORT_FEAT_RESET:
diff --git a/drivers/usb/musb/omap2430.c b/drivers/usb/musb/omap2430.c
index 59d2245db1c8..2a408cdaf7b2 100644
--- a/drivers/usb/musb/omap2430.c
+++ b/drivers/usb/musb/omap2430.c
@@ -38,6 +38,7 @@
38#include <linux/delay.h> 38#include <linux/delay.h>
39#include <linux/usb/musb-omap.h> 39#include <linux/usb/musb-omap.h>
40#include <linux/usb/omap_control_usb.h> 40#include <linux/usb/omap_control_usb.h>
41#include <linux/of_platform.h>
41 42
42#include "musb_core.h" 43#include "musb_core.h"
43#include "omap2430.h" 44#include "omap2430.h"
@@ -305,6 +306,9 @@ static void omap_musb_set_mailbox(struct omap2430_glue *glue)
305 default: 306 default:
306 dev_dbg(dev, "ID float\n"); 307 dev_dbg(dev, "ID float\n");
307 } 308 }
309
310 atomic_notifier_call_chain(&musb->xceiv->notifier,
311 musb->xceiv->last_event, NULL);
308} 312}
309 313
310 314
@@ -348,11 +352,21 @@ static int omap2430_musb_init(struct musb *musb)
348 * up through ULPI. TWL4030-family PMICs include one, 352 * up through ULPI. TWL4030-family PMICs include one,
349 * which needs a driver, drivers aren't always needed. 353 * which needs a driver, drivers aren't always needed.
350 */ 354 */
351 if (dev->parent->of_node) 355 if (dev->parent->of_node) {
356 musb->phy = devm_phy_get(dev->parent, "usb2-phy");
357
358 /* We can't totally remove musb->xceiv as of now because
359 * musb core uses xceiv.state and xceiv.otg. Once we have
360 * a separate state machine to handle otg, these can be moved
361 * out of xceiv and then we can start using the generic PHY
362 * framework
363 */
352 musb->xceiv = devm_usb_get_phy_by_phandle(dev->parent, 364 musb->xceiv = devm_usb_get_phy_by_phandle(dev->parent,
353 "usb-phy", 0); 365 "usb-phy", 0);
354 else 366 } else {
355 musb->xceiv = devm_usb_get_phy_dev(dev, 0); 367 musb->xceiv = devm_usb_get_phy_dev(dev, 0);
368 musb->phy = devm_phy_get(dev, "usb");
369 }
356 370
357 if (IS_ERR(musb->xceiv)) { 371 if (IS_ERR(musb->xceiv)) {
358 status = PTR_ERR(musb->xceiv); 372 status = PTR_ERR(musb->xceiv);
@@ -364,6 +378,10 @@ static int omap2430_musb_init(struct musb *musb)
364 return -EPROBE_DEFER; 378 return -EPROBE_DEFER;
365 } 379 }
366 380
381 if (IS_ERR(musb->phy)) {
382 pr_err("HS USB OTG: no PHY configured\n");
383 return PTR_ERR(musb->phy);
384 }
367 musb->isr = omap2430_musb_interrupt; 385 musb->isr = omap2430_musb_interrupt;
368 386
369 status = pm_runtime_get_sync(dev); 387 status = pm_runtime_get_sync(dev);
@@ -397,7 +415,7 @@ static int omap2430_musb_init(struct musb *musb)
397 if (glue->status != OMAP_MUSB_UNKNOWN) 415 if (glue->status != OMAP_MUSB_UNKNOWN)
398 omap_musb_set_mailbox(glue); 416 omap_musb_set_mailbox(glue);
399 417
400 usb_phy_init(musb->xceiv); 418 phy_init(musb->phy);
401 419
402 pm_runtime_put_noidle(musb->controller); 420 pm_runtime_put_noidle(musb->controller);
403 return 0; 421 return 0;
@@ -460,6 +478,7 @@ static int omap2430_musb_exit(struct musb *musb)
460 del_timer_sync(&musb_idle_timer); 478 del_timer_sync(&musb_idle_timer);
461 479
462 omap2430_low_level_exit(musb); 480 omap2430_low_level_exit(musb);
481 phy_exit(musb->phy);
463 482
464 return 0; 483 return 0;
465} 484}
@@ -509,8 +528,12 @@ static int omap2430_probe(struct platform_device *pdev)
509 glue->dev = &pdev->dev; 528 glue->dev = &pdev->dev;
510 glue->musb = musb; 529 glue->musb = musb;
511 glue->status = OMAP_MUSB_UNKNOWN; 530 glue->status = OMAP_MUSB_UNKNOWN;
531 glue->control_otghs = ERR_PTR(-ENODEV);
512 532
513 if (np) { 533 if (np) {
534 struct device_node *control_node;
535 struct platform_device *control_pdev;
536
514 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); 537 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
515 if (!pdata) { 538 if (!pdata) {
516 dev_err(&pdev->dev, 539 dev_err(&pdev->dev,
@@ -539,22 +562,20 @@ static int omap2430_probe(struct platform_device *pdev)
539 of_property_read_u32(np, "ram-bits", (u32 *)&config->ram_bits); 562 of_property_read_u32(np, "ram-bits", (u32 *)&config->ram_bits);
540 of_property_read_u32(np, "power", (u32 *)&pdata->power); 563 of_property_read_u32(np, "power", (u32 *)&pdata->power);
541 config->multipoint = of_property_read_bool(np, "multipoint"); 564 config->multipoint = of_property_read_bool(np, "multipoint");
542 pdata->has_mailbox = of_property_read_bool(np,
543 "ti,has-mailbox");
544 565
545 pdata->board_data = data; 566 pdata->board_data = data;
546 pdata->config = config; 567 pdata->config = config;
547 }
548 568
549 if (pdata->has_mailbox) { 569 control_node = of_parse_phandle(np, "ctrl-module", 0);
550 glue->control_otghs = omap_get_control_dev(); 570 if (control_node) {
551 if (IS_ERR(glue->control_otghs)) { 571 control_pdev = of_find_device_by_node(control_node);
552 dev_vdbg(&pdev->dev, "Failed to get control device\n"); 572 if (!control_pdev) {
553 ret = PTR_ERR(glue->control_otghs); 573 dev_err(&pdev->dev, "Failed to get control device\n");
554 goto err2; 574 ret = -EINVAL;
575 goto err2;
576 }
577 glue->control_otghs = &control_pdev->dev;
555 } 578 }
556 } else {
557 glue->control_otghs = ERR_PTR(-ENODEV);
558 } 579 }
559 pdata->platform_ops = &omap2430_ops; 580 pdata->platform_ops = &omap2430_ops;
560 581
@@ -638,7 +659,7 @@ static int omap2430_runtime_suspend(struct device *dev)
638 OTG_INTERFSEL); 659 OTG_INTERFSEL);
639 660
640 omap2430_low_level_exit(musb); 661 omap2430_low_level_exit(musb);
641 usb_phy_set_suspend(musb->xceiv, 1); 662 phy_power_off(musb->phy);
642 } 663 }
643 664
644 return 0; 665 return 0;
@@ -653,8 +674,7 @@ static int omap2430_runtime_resume(struct device *dev)
653 omap2430_low_level_init(musb); 674 omap2430_low_level_init(musb);
654 musb_writel(musb->mregs, OTG_INTERFSEL, 675 musb_writel(musb->mregs, OTG_INTERFSEL,
655 musb->context.otg_interfsel); 676 musb->context.otg_interfsel);
656 677 phy_power_on(musb->phy);
657 usb_phy_set_suspend(musb->xceiv, 0);
658 } 678 }
659 679
660 return 0; 680 return 0;
diff --git a/drivers/usb/musb/tusb6010.c b/drivers/usb/musb/tusb6010.c
index b3b3ed723882..4432314d70ee 100644
--- a/drivers/usb/musb/tusb6010.c
+++ b/drivers/usb/musb/tusb6010.c
@@ -1152,7 +1152,11 @@ static const struct musb_platform_ops tusb_ops = {
1152 .set_vbus = tusb_musb_set_vbus, 1152 .set_vbus = tusb_musb_set_vbus,
1153}; 1153};
1154 1154
1155static u64 tusb_dmamask = DMA_BIT_MASK(32); 1155static const struct platform_device_info tusb_dev_info = {
1156 .name = "musb-hdrc",
1157 .id = PLATFORM_DEVID_AUTO,
1158 .dma_mask = DMA_BIT_MASK(32),
1159};
1156 1160
1157static int tusb_probe(struct platform_device *pdev) 1161static int tusb_probe(struct platform_device *pdev)
1158{ 1162{
@@ -1160,7 +1164,7 @@ static int tusb_probe(struct platform_device *pdev)
1160 struct musb_hdrc_platform_data *pdata = dev_get_platdata(&pdev->dev); 1164 struct musb_hdrc_platform_data *pdata = dev_get_platdata(&pdev->dev);
1161 struct platform_device *musb; 1165 struct platform_device *musb;
1162 struct tusb6010_glue *glue; 1166 struct tusb6010_glue *glue;
1163 1167 struct platform_device_info pinfo;
1164 int ret = -ENOMEM; 1168 int ret = -ENOMEM;
1165 1169
1166 glue = kzalloc(sizeof(*glue), GFP_KERNEL); 1170 glue = kzalloc(sizeof(*glue), GFP_KERNEL);
@@ -1169,18 +1173,7 @@ static int tusb_probe(struct platform_device *pdev)
1169 goto err0; 1173 goto err0;
1170 } 1174 }
1171 1175
1172 musb = platform_device_alloc("musb-hdrc", PLATFORM_DEVID_AUTO);
1173 if (!musb) {
1174 dev_err(&pdev->dev, "failed to allocate musb device\n");
1175 goto err1;
1176 }
1177
1178 musb->dev.parent = &pdev->dev;
1179 musb->dev.dma_mask = &tusb_dmamask;
1180 musb->dev.coherent_dma_mask = tusb_dmamask;
1181
1182 glue->dev = &pdev->dev; 1176 glue->dev = &pdev->dev;
1183 glue->musb = musb;
1184 1177
1185 pdata->platform_ops = &tusb_ops; 1178 pdata->platform_ops = &tusb_ops;
1186 1179
@@ -1204,31 +1197,23 @@ static int tusb_probe(struct platform_device *pdev)
1204 musb_resources[2].end = pdev->resource[2].end; 1197 musb_resources[2].end = pdev->resource[2].end;
1205 musb_resources[2].flags = pdev->resource[2].flags; 1198 musb_resources[2].flags = pdev->resource[2].flags;
1206 1199
1207 ret = platform_device_add_resources(musb, musb_resources, 1200 pinfo = tusb_dev_info;
1208 ARRAY_SIZE(musb_resources)); 1201 pinfo.parent = &pdev->dev;
1209 if (ret) { 1202 pinfo.res = musb_resources;
1210 dev_err(&pdev->dev, "failed to add resources\n"); 1203 pinfo.num_res = ARRAY_SIZE(musb_resources);
1211 goto err3; 1204 pinfo.data = pdata;
1212 } 1205 pinfo.size_data = sizeof(*pdata);
1213 1206
1214 ret = platform_device_add_data(musb, pdata, sizeof(*pdata)); 1207 glue->musb = musb = platform_device_register_full(&pinfo);
1215 if (ret) { 1208 if (IS_ERR(musb)) {
1216 dev_err(&pdev->dev, "failed to add platform_data\n"); 1209 ret = PTR_ERR(musb);
1217 goto err3; 1210 dev_err(&pdev->dev, "failed to register musb device: %d\n", ret);
1218 }
1219
1220 ret = platform_device_add(musb);
1221 if (ret) {
1222 dev_err(&pdev->dev, "failed to register musb device\n");
1223 goto err3; 1211 goto err3;
1224 } 1212 }
1225 1213
1226 return 0; 1214 return 0;
1227 1215
1228err3: 1216err3:
1229 platform_device_put(musb);
1230
1231err1:
1232 kfree(glue); 1217 kfree(glue);
1233 1218
1234err0: 1219err0:
diff --git a/drivers/usb/musb/ux500.c b/drivers/usb/musb/ux500.c
index 59256b12f746..f483d1924c28 100644
--- a/drivers/usb/musb/ux500.c
+++ b/drivers/usb/musb/ux500.c
@@ -376,17 +376,10 @@ static int ux500_resume(struct device *dev)
376 376
377 return 0; 377 return 0;
378} 378}
379
380static const struct dev_pm_ops ux500_pm_ops = {
381 .suspend = ux500_suspend,
382 .resume = ux500_resume,
383};
384
385#define DEV_PM_OPS (&ux500_pm_ops)
386#else
387#define DEV_PM_OPS NULL
388#endif 379#endif
389 380
381static SIMPLE_DEV_PM_OPS(ux500_pm_ops, ux500_suspend, ux500_resume);
382
390static const struct of_device_id ux500_match[] = { 383static const struct of_device_id ux500_match[] = {
391 { .compatible = "stericsson,db8500-musb", }, 384 { .compatible = "stericsson,db8500-musb", },
392 {} 385 {}
@@ -397,7 +390,7 @@ static struct platform_driver ux500_driver = {
397 .remove = ux500_remove, 390 .remove = ux500_remove,
398 .driver = { 391 .driver = {
399 .name = "musb-ux500", 392 .name = "musb-ux500",
400 .pm = DEV_PM_OPS, 393 .pm = &ux500_pm_ops,
401 .of_match_table = ux500_match, 394 .of_match_table = ux500_match,
402 }, 395 },
403}; 396};
diff --git a/drivers/usb/phy/Kconfig b/drivers/usb/phy/Kconfig
index d5589f9c60a9..08e2f39027ec 100644
--- a/drivers/usb/phy/Kconfig
+++ b/drivers/usb/phy/Kconfig
@@ -66,17 +66,6 @@ config OMAP_CONTROL_USB
66 power on the USB2 PHY is present in OMAP4 and OMAP5. OMAP5 has an 66 power on the USB2 PHY is present in OMAP4 and OMAP5. OMAP5 has an
67 additional register to power on USB3 PHY. 67 additional register to power on USB3 PHY.
68 68
69config OMAP_USB2
70 tristate "OMAP USB2 PHY Driver"
71 depends on ARCH_OMAP2PLUS
72 select OMAP_CONTROL_USB
73 select USB_PHY
74 help
75 Enable this to support the transceiver that is part of SOC. This
76 driver takes care of all the PHY functionality apart from comparator.
77 The USB OTG controller communicates with the comparator using this
78 driver.
79
80config OMAP_USB3 69config OMAP_USB3
81 tristate "OMAP USB3 PHY Driver" 70 tristate "OMAP USB3 PHY Driver"
82 depends on ARCH_OMAP2PLUS || COMPILE_TEST 71 depends on ARCH_OMAP2PLUS || COMPILE_TEST
@@ -93,6 +82,7 @@ config AM335X_CONTROL_USB
93 82
94config AM335X_PHY_USB 83config AM335X_PHY_USB
95 tristate "AM335x USB PHY Driver" 84 tristate "AM335x USB PHY Driver"
85 depends on ARM || COMPILE_TEST
96 select USB_PHY 86 select USB_PHY
97 select AM335X_CONTROL_USB 87 select AM335X_CONTROL_USB
98 select NOP_USB_XCEIV 88 select NOP_USB_XCEIV
@@ -123,16 +113,6 @@ config SAMSUNG_USB3PHY
123 Enable this to support Samsung USB 3.0 (Super Speed) phy controller 113 Enable this to support Samsung USB 3.0 (Super Speed) phy controller
124 for samsung SoCs. 114 for samsung SoCs.
125 115
126config TWL4030_USB
127 tristate "TWL4030 USB Transceiver Driver"
128 depends on TWL4030_CORE && REGULATOR_TWL4030 && USB_MUSB_OMAP2PLUS
129 select USB_PHY
130 help
131 Enable this to support the USB OTG transceiver on TWL4030
132 family chips (including the TWL5030 and TPS659x0 devices).
133 This transceiver supports high and full speed devices plus,
134 in host mode, low speed.
135
136config TWL6030_USB 116config TWL6030_USB
137 tristate "TWL6030 USB Transceiver Driver" 117 tristate "TWL6030 USB Transceiver Driver"
138 depends on TWL4030_CORE && OMAP_USB2 && USB_MUSB_OMAP2PLUS 118 depends on TWL4030_CORE && OMAP_USB2 && USB_MUSB_OMAP2PLUS
@@ -214,6 +194,19 @@ config USB_RCAR_PHY
214 To compile this driver as a module, choose M here: the 194 To compile this driver as a module, choose M here: the
215 module will be called phy-rcar-usb. 195 module will be called phy-rcar-usb.
216 196
197config USB_RCAR_GEN2_PHY
198 tristate "Renesas R-Car Gen2 USB PHY support"
199 depends on ARCH_R8A7790 || ARCH_R8A7791 || COMPILE_TEST
200 select USB_PHY
201 help
202 Say Y here to add support for the Renesas R-Car Gen2 USB PHY driver.
203 It is typically used to control internal USB PHY for USBHS,
204 and to configure shared USB channels 0 and 2.
205 This driver supports R8A7790 and R8A7791.
206
207 To compile this driver as a module, choose M here: the
208 module will be called phy-rcar-gen2-usb.
209
217config USB_ULPI 210config USB_ULPI
218 bool "Generic ULPI Transceiver Driver" 211 bool "Generic ULPI Transceiver Driver"
219 depends on ARM 212 depends on ARM
diff --git a/drivers/usb/phy/Makefile b/drivers/usb/phy/Makefile
index 2135e85f46ed..022c1da7fb78 100644
--- a/drivers/usb/phy/Makefile
+++ b/drivers/usb/phy/Makefile
@@ -15,12 +15,10 @@ obj-$(CONFIG_NOP_USB_XCEIV) += phy-generic.o
15obj-$(CONFIG_OMAP_CONTROL_USB) += phy-omap-control.o 15obj-$(CONFIG_OMAP_CONTROL_USB) += phy-omap-control.o
16obj-$(CONFIG_AM335X_CONTROL_USB) += phy-am335x-control.o 16obj-$(CONFIG_AM335X_CONTROL_USB) += phy-am335x-control.o
17obj-$(CONFIG_AM335X_PHY_USB) += phy-am335x.o 17obj-$(CONFIG_AM335X_PHY_USB) += phy-am335x.o
18obj-$(CONFIG_OMAP_USB2) += phy-omap-usb2.o
19obj-$(CONFIG_OMAP_USB3) += phy-omap-usb3.o 18obj-$(CONFIG_OMAP_USB3) += phy-omap-usb3.o
20obj-$(CONFIG_SAMSUNG_USBPHY) += phy-samsung-usb.o 19obj-$(CONFIG_SAMSUNG_USBPHY) += phy-samsung-usb.o
21obj-$(CONFIG_SAMSUNG_USB2PHY) += phy-samsung-usb2.o 20obj-$(CONFIG_SAMSUNG_USB2PHY) += phy-samsung-usb2.o
22obj-$(CONFIG_SAMSUNG_USB3PHY) += phy-samsung-usb3.o 21obj-$(CONFIG_SAMSUNG_USB3PHY) += phy-samsung-usb3.o
23obj-$(CONFIG_TWL4030_USB) += phy-twl4030-usb.o
24obj-$(CONFIG_TWL6030_USB) += phy-twl6030-usb.o 22obj-$(CONFIG_TWL6030_USB) += phy-twl6030-usb.o
25obj-$(CONFIG_USB_EHCI_TEGRA) += phy-tegra-usb.o 23obj-$(CONFIG_USB_EHCI_TEGRA) += phy-tegra-usb.o
26obj-$(CONFIG_USB_GPIO_VBUS) += phy-gpio-vbus-usb.o 24obj-$(CONFIG_USB_GPIO_VBUS) += phy-gpio-vbus-usb.o
@@ -29,5 +27,6 @@ obj-$(CONFIG_USB_MSM_OTG) += phy-msm-usb.o
29obj-$(CONFIG_USB_MV_OTG) += phy-mv-usb.o 27obj-$(CONFIG_USB_MV_OTG) += phy-mv-usb.o
30obj-$(CONFIG_USB_MXS_PHY) += phy-mxs-usb.o 28obj-$(CONFIG_USB_MXS_PHY) += phy-mxs-usb.o
31obj-$(CONFIG_USB_RCAR_PHY) += phy-rcar-usb.o 29obj-$(CONFIG_USB_RCAR_PHY) += phy-rcar-usb.o
30obj-$(CONFIG_USB_RCAR_GEN2_PHY) += phy-rcar-gen2-usb.o
32obj-$(CONFIG_USB_ULPI) += phy-ulpi.o 31obj-$(CONFIG_USB_ULPI) += phy-ulpi.o
33obj-$(CONFIG_USB_ULPI_VIEWPORT) += phy-ulpi-viewport.o 32obj-$(CONFIG_USB_ULPI_VIEWPORT) += phy-ulpi-viewport.o
diff --git a/drivers/usb/phy/phy-am335x-control.c b/drivers/usb/phy/phy-am335x-control.c
index 22cf07d62e4c..634f49acd20e 100644
--- a/drivers/usb/phy/phy-am335x-control.c
+++ b/drivers/usb/phy/phy-am335x-control.c
@@ -26,6 +26,41 @@ struct am335x_control_usb {
26#define USBPHY_OTGVDET_EN (1 << 19) 26#define USBPHY_OTGVDET_EN (1 << 19)
27#define USBPHY_OTGSESSEND_EN (1 << 20) 27#define USBPHY_OTGSESSEND_EN (1 << 20)
28 28
29#define AM335X_PHY0_WK_EN (1 << 0)
30#define AM335X_PHY1_WK_EN (1 << 8)
31
32static void am335x_phy_wkup(struct phy_control *phy_ctrl, u32 id, bool on)
33{
34 struct am335x_control_usb *usb_ctrl;
35 u32 val;
36 u32 reg;
37
38 usb_ctrl = container_of(phy_ctrl, struct am335x_control_usb, phy_ctrl);
39
40 switch (id) {
41 case 0:
42 reg = AM335X_PHY0_WK_EN;
43 break;
44 case 1:
45 reg = AM335X_PHY1_WK_EN;
46 break;
47 default:
48 WARN_ON(1);
49 return;
50 }
51
52 spin_lock(&usb_ctrl->lock);
53 val = readl(usb_ctrl->wkup);
54
55 if (on)
56 val |= reg;
57 else
58 val &= ~reg;
59
60 writel(val, usb_ctrl->wkup);
61 spin_unlock(&usb_ctrl->lock);
62}
63
29static void am335x_phy_power(struct phy_control *phy_ctrl, u32 id, bool on) 64static void am335x_phy_power(struct phy_control *phy_ctrl, u32 id, bool on)
30{ 65{
31 struct am335x_control_usb *usb_ctrl; 66 struct am335x_control_usb *usb_ctrl;
@@ -59,6 +94,7 @@ static void am335x_phy_power(struct phy_control *phy_ctrl, u32 id, bool on)
59 94
60static const struct phy_control ctrl_am335x = { 95static const struct phy_control ctrl_am335x = {
61 .phy_power = am335x_phy_power, 96 .phy_power = am335x_phy_power,
97 .phy_wkup = am335x_phy_wkup,
62}; 98};
63 99
64static const struct of_device_id omap_control_usb_id_table[] = { 100static const struct of_device_id omap_control_usb_id_table[] = {
@@ -117,6 +153,12 @@ static int am335x_control_usb_probe(struct platform_device *pdev)
117 ctrl_usb->phy_reg = devm_ioremap_resource(&pdev->dev, res); 153 ctrl_usb->phy_reg = devm_ioremap_resource(&pdev->dev, res);
118 if (IS_ERR(ctrl_usb->phy_reg)) 154 if (IS_ERR(ctrl_usb->phy_reg))
119 return PTR_ERR(ctrl_usb->phy_reg); 155 return PTR_ERR(ctrl_usb->phy_reg);
156
157 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "wakeup");
158 ctrl_usb->wkup = devm_ioremap_resource(&pdev->dev, res);
159 if (IS_ERR(ctrl_usb->wkup))
160 return PTR_ERR(ctrl_usb->wkup);
161
120 spin_lock_init(&ctrl_usb->lock); 162 spin_lock_init(&ctrl_usb->lock);
121 ctrl_usb->phy_ctrl = *phy_ctrl; 163 ctrl_usb->phy_ctrl = *phy_ctrl;
122 164
@@ -129,7 +171,7 @@ static struct platform_driver am335x_control_driver = {
129 .driver = { 171 .driver = {
130 .name = "am335x-control-usb", 172 .name = "am335x-control-usb",
131 .owner = THIS_MODULE, 173 .owner = THIS_MODULE,
132 .of_match_table = of_match_ptr(omap_control_usb_id_table), 174 .of_match_table = omap_control_usb_id_table,
133 }, 175 },
134}; 176};
135 177
diff --git a/drivers/usb/phy/phy-am335x.c b/drivers/usb/phy/phy-am335x.c
index c4d614d1f173..6370e50649d7 100644
--- a/drivers/usb/phy/phy-am335x.c
+++ b/drivers/usb/phy/phy-am335x.c
@@ -53,21 +53,20 @@ static int am335x_phy_probe(struct platform_device *pdev)
53 } 53 }
54 54
55 ret = usb_phy_gen_create_phy(dev, &am_phy->usb_phy_gen, 55 ret = usb_phy_gen_create_phy(dev, &am_phy->usb_phy_gen,
56 USB_PHY_TYPE_USB2, 0, false, false); 56 USB_PHY_TYPE_USB2, 0, false);
57 if (ret) 57 if (ret)
58 return ret; 58 return ret;
59 59
60 ret = usb_add_phy_dev(&am_phy->usb_phy_gen.phy); 60 ret = usb_add_phy_dev(&am_phy->usb_phy_gen.phy);
61 if (ret) 61 if (ret)
62 goto err_add; 62 return ret;
63 am_phy->usb_phy_gen.phy.init = am335x_init; 63 am_phy->usb_phy_gen.phy.init = am335x_init;
64 am_phy->usb_phy_gen.phy.shutdown = am335x_shutdown; 64 am_phy->usb_phy_gen.phy.shutdown = am335x_shutdown;
65 65
66 platform_set_drvdata(pdev, am_phy); 66 platform_set_drvdata(pdev, am_phy);
67
67 return 0; 68 return 0;
68 69
69err_add:
70 usb_phy_gen_cleanup_phy(&am_phy->usb_phy_gen);
71 return ret; 70 return ret;
72} 71}
73 72
@@ -79,6 +78,40 @@ static int am335x_phy_remove(struct platform_device *pdev)
79 return 0; 78 return 0;
80} 79}
81 80
81#ifdef CONFIG_PM_RUNTIME
82
83static int am335x_phy_runtime_suspend(struct device *dev)
84{
85 struct platform_device *pdev = to_platform_device(dev);
86 struct am335x_phy *am_phy = platform_get_drvdata(pdev);
87
88 if (device_may_wakeup(dev))
89 phy_ctrl_wkup(am_phy->phy_ctrl, am_phy->id, true);
90 phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, false);
91 return 0;
92}
93
94static int am335x_phy_runtime_resume(struct device *dev)
95{
96 struct platform_device *pdev = to_platform_device(dev);
97 struct am335x_phy *am_phy = platform_get_drvdata(pdev);
98
99 phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, true);
100 if (device_may_wakeup(dev))
101 phy_ctrl_wkup(am_phy->phy_ctrl, am_phy->id, false);
102 return 0;
103}
104
105static const struct dev_pm_ops am335x_pm_ops = {
106 SET_RUNTIME_PM_OPS(am335x_phy_runtime_suspend,
107 am335x_phy_runtime_resume, NULL)
108};
109
110#define DEV_PM_OPS (&am335x_pm_ops)
111#else
112#define DEV_PM_OPS NULL
113#endif
114
82static const struct of_device_id am335x_phy_ids[] = { 115static const struct of_device_id am335x_phy_ids[] = {
83 { .compatible = "ti,am335x-usb-phy" }, 116 { .compatible = "ti,am335x-usb-phy" },
84 { } 117 { }
@@ -91,7 +124,8 @@ static struct platform_driver am335x_phy_driver = {
91 .driver = { 124 .driver = {
92 .name = "am335x-phy-driver", 125 .name = "am335x-phy-driver",
93 .owner = THIS_MODULE, 126 .owner = THIS_MODULE,
94 .of_match_table = of_match_ptr(am335x_phy_ids), 127 .pm = DEV_PM_OPS,
128 .of_match_table = am335x_phy_ids,
95 }, 129 },
96}; 130};
97 131
diff --git a/drivers/usb/phy/phy-fsl-usb.c b/drivers/usb/phy/phy-fsl-usb.c
index fa7c9f9628b5..7f3c73b967ce 100644
--- a/drivers/usb/phy/phy-fsl-usb.c
+++ b/drivers/usb/phy/phy-fsl-usb.c
@@ -134,7 +134,7 @@ int write_ulpi(u8 addr, u8 data)
134/* Operations that will be called from OTG Finite State Machine */ 134/* Operations that will be called from OTG Finite State Machine */
135 135
136/* Charge vbus for vbus pulsing in SRP */ 136/* Charge vbus for vbus pulsing in SRP */
137void fsl_otg_chrg_vbus(int on) 137void fsl_otg_chrg_vbus(struct otg_fsm *fsm, int on)
138{ 138{
139 u32 tmp; 139 u32 tmp;
140 140
@@ -170,7 +170,7 @@ void fsl_otg_dischrg_vbus(int on)
170} 170}
171 171
172/* A-device driver vbus, controlled through PP bit in PORTSC */ 172/* A-device driver vbus, controlled through PP bit in PORTSC */
173void fsl_otg_drv_vbus(int on) 173void fsl_otg_drv_vbus(struct otg_fsm *fsm, int on)
174{ 174{
175 u32 tmp; 175 u32 tmp;
176 176
@@ -188,7 +188,7 @@ void fsl_otg_drv_vbus(int on)
188 * Pull-up D+, signalling connect by periperal. Also used in 188 * Pull-up D+, signalling connect by periperal. Also used in
189 * data-line pulsing in SRP 189 * data-line pulsing in SRP
190 */ 190 */
191void fsl_otg_loc_conn(int on) 191void fsl_otg_loc_conn(struct otg_fsm *fsm, int on)
192{ 192{
193 u32 tmp; 193 u32 tmp;
194 194
@@ -207,7 +207,7 @@ void fsl_otg_loc_conn(int on)
207 * port. In host mode, controller will automatically send SOF. 207 * port. In host mode, controller will automatically send SOF.
208 * Suspend will block the data on the port. 208 * Suspend will block the data on the port.
209 */ 209 */
210void fsl_otg_loc_sof(int on) 210void fsl_otg_loc_sof(struct otg_fsm *fsm, int on)
211{ 211{
212 u32 tmp; 212 u32 tmp;
213 213
@@ -222,7 +222,7 @@ void fsl_otg_loc_sof(int on)
222} 222}
223 223
224/* Start SRP pulsing by data-line pulsing, followed with v-bus pulsing. */ 224/* Start SRP pulsing by data-line pulsing, followed with v-bus pulsing. */
225void fsl_otg_start_pulse(void) 225void fsl_otg_start_pulse(struct otg_fsm *fsm)
226{ 226{
227 u32 tmp; 227 u32 tmp;
228 228
@@ -235,7 +235,7 @@ void fsl_otg_start_pulse(void)
235 fsl_otg_loc_conn(1); 235 fsl_otg_loc_conn(1);
236#endif 236#endif
237 237
238 fsl_otg_add_timer(b_data_pulse_tmr); 238 fsl_otg_add_timer(fsm, b_data_pulse_tmr);
239} 239}
240 240
241void b_data_pulse_end(unsigned long foo) 241void b_data_pulse_end(unsigned long foo)
@@ -252,14 +252,14 @@ void b_data_pulse_end(unsigned long foo)
252void fsl_otg_pulse_vbus(void) 252void fsl_otg_pulse_vbus(void)
253{ 253{
254 srp_wait_done = 0; 254 srp_wait_done = 0;
255 fsl_otg_chrg_vbus(1); 255 fsl_otg_chrg_vbus(&fsl_otg_dev->fsm, 1);
256 /* start the timer to end vbus charge */ 256 /* start the timer to end vbus charge */
257 fsl_otg_add_timer(b_vbus_pulse_tmr); 257 fsl_otg_add_timer(&fsl_otg_dev->fsm, b_vbus_pulse_tmr);
258} 258}
259 259
260void b_vbus_pulse_end(unsigned long foo) 260void b_vbus_pulse_end(unsigned long foo)
261{ 261{
262 fsl_otg_chrg_vbus(0); 262 fsl_otg_chrg_vbus(&fsl_otg_dev->fsm, 0);
263 263
264 /* 264 /*
265 * As USB3300 using the same a_sess_vld and b_sess_vld voltage 265 * As USB3300 using the same a_sess_vld and b_sess_vld voltage
@@ -267,7 +267,7 @@ void b_vbus_pulse_end(unsigned long foo)
267 * residual voltage of vbus pulsing and A device pull up 267 * residual voltage of vbus pulsing and A device pull up
268 */ 268 */
269 fsl_otg_dischrg_vbus(1); 269 fsl_otg_dischrg_vbus(1);
270 fsl_otg_add_timer(b_srp_wait_tmr); 270 fsl_otg_add_timer(&fsl_otg_dev->fsm, b_srp_wait_tmr);
271} 271}
272 272
273void b_srp_end(unsigned long foo) 273void b_srp_end(unsigned long foo)
@@ -289,7 +289,7 @@ void a_wait_enum(unsigned long foo)
289{ 289{
290 VDBG("a_wait_enum timeout\n"); 290 VDBG("a_wait_enum timeout\n");
291 if (!fsl_otg_dev->phy.otg->host->b_hnp_enable) 291 if (!fsl_otg_dev->phy.otg->host->b_hnp_enable)
292 fsl_otg_add_timer(a_wait_enum_tmr); 292 fsl_otg_add_timer(&fsl_otg_dev->fsm, a_wait_enum_tmr);
293 else 293 else
294 otg_statemachine(&fsl_otg_dev->fsm); 294 otg_statemachine(&fsl_otg_dev->fsm);
295} 295}
@@ -375,8 +375,42 @@ void fsl_otg_uninit_timers(void)
375 kfree(b_vbus_pulse_tmr); 375 kfree(b_vbus_pulse_tmr);
376} 376}
377 377
378static struct fsl_otg_timer *fsl_otg_get_timer(enum otg_fsm_timer t)
379{
380 struct fsl_otg_timer *timer;
381
382 /* REVISIT: use array of pointers to timers instead */
383 switch (t) {
384 case A_WAIT_VRISE:
385 timer = a_wait_vrise_tmr;
386 break;
387 case A_WAIT_BCON:
388 timer = a_wait_vrise_tmr;
389 break;
390 case A_AIDL_BDIS:
391 timer = a_wait_vrise_tmr;
392 break;
393 case B_ASE0_BRST:
394 timer = a_wait_vrise_tmr;
395 break;
396 case B_SE0_SRP:
397 timer = a_wait_vrise_tmr;
398 break;
399 case B_SRP_FAIL:
400 timer = a_wait_vrise_tmr;
401 break;
402 case A_WAIT_ENUM:
403 timer = a_wait_vrise_tmr;
404 break;
405 default:
406 timer = NULL;
407 }
408
409 return timer;
410}
411
378/* Add timer to timer list */ 412/* Add timer to timer list */
379void fsl_otg_add_timer(void *gtimer) 413void fsl_otg_add_timer(struct otg_fsm *fsm, void *gtimer)
380{ 414{
381 struct fsl_otg_timer *timer = gtimer; 415 struct fsl_otg_timer *timer = gtimer;
382 struct fsl_otg_timer *tmp_timer; 416 struct fsl_otg_timer *tmp_timer;
@@ -394,8 +428,19 @@ void fsl_otg_add_timer(void *gtimer)
394 list_add_tail(&timer->list, &active_timers); 428 list_add_tail(&timer->list, &active_timers);
395} 429}
396 430
431static void fsl_otg_fsm_add_timer(struct otg_fsm *fsm, enum otg_fsm_timer t)
432{
433 struct fsl_otg_timer *timer;
434
435 timer = fsl_otg_get_timer(t);
436 if (!timer)
437 return;
438
439 fsl_otg_add_timer(fsm, timer);
440}
441
397/* Remove timer from the timer list; clear timeout status */ 442/* Remove timer from the timer list; clear timeout status */
398void fsl_otg_del_timer(void *gtimer) 443void fsl_otg_del_timer(struct otg_fsm *fsm, void *gtimer)
399{ 444{
400 struct fsl_otg_timer *timer = gtimer; 445 struct fsl_otg_timer *timer = gtimer;
401 struct fsl_otg_timer *tmp_timer, *del_tmp; 446 struct fsl_otg_timer *tmp_timer, *del_tmp;
@@ -405,6 +450,17 @@ void fsl_otg_del_timer(void *gtimer)
405 list_del(&timer->list); 450 list_del(&timer->list);
406} 451}
407 452
453static void fsl_otg_fsm_del_timer(struct otg_fsm *fsm, enum otg_fsm_timer t)
454{
455 struct fsl_otg_timer *timer;
456
457 timer = fsl_otg_get_timer(t);
458 if (!timer)
459 return;
460
461 fsl_otg_del_timer(fsm, timer);
462}
463
408/* 464/*
409 * Reduce timer count by 1, and find timeout conditions. 465 * Reduce timer count by 1, and find timeout conditions.
410 * Called by fsl_otg 1ms timer interrupt 466 * Called by fsl_otg 1ms timer interrupt
@@ -468,7 +524,7 @@ int fsl_otg_start_host(struct otg_fsm *fsm, int on)
468 retval = dev->driver->pm->resume(dev); 524 retval = dev->driver->pm->resume(dev);
469 if (fsm->id) { 525 if (fsm->id) {
470 /* default-b */ 526 /* default-b */
471 fsl_otg_drv_vbus(1); 527 fsl_otg_drv_vbus(fsm, 1);
472 /* 528 /*
473 * Workaround: b_host can't driver 529 * Workaround: b_host can't driver
474 * vbus, but PP in PORTSC needs to 530 * vbus, but PP in PORTSC needs to
@@ -493,7 +549,7 @@ int fsl_otg_start_host(struct otg_fsm *fsm, int on)
493 retval = dev->driver->pm->suspend(dev); 549 retval = dev->driver->pm->suspend(dev);
494 if (fsm->id) 550 if (fsm->id)
495 /* default-b */ 551 /* default-b */
496 fsl_otg_drv_vbus(0); 552 fsl_otg_drv_vbus(fsm, 0);
497 } 553 }
498 otg_dev->host_working = 0; 554 otg_dev->host_working = 0;
499 } 555 }
@@ -757,8 +813,8 @@ static struct otg_fsm_ops fsl_otg_ops = {
757 .loc_sof = fsl_otg_loc_sof, 813 .loc_sof = fsl_otg_loc_sof,
758 .start_pulse = fsl_otg_start_pulse, 814 .start_pulse = fsl_otg_start_pulse,
759 815
760 .add_timer = fsl_otg_add_timer, 816 .add_timer = fsl_otg_fsm_add_timer,
761 .del_timer = fsl_otg_del_timer, 817 .del_timer = fsl_otg_fsm_del_timer,
762 818
763 .start_host = fsl_otg_start_host, 819 .start_host = fsl_otg_start_host,
764 .start_gadget = fsl_otg_start_gadget, 820 .start_gadget = fsl_otg_start_gadget,
@@ -1011,7 +1067,7 @@ static int show_fsl_usb2_otg_state(struct device *dev,
1011 "b_bus_suspend: %d\n" 1067 "b_bus_suspend: %d\n"
1012 "b_conn: %d\n" 1068 "b_conn: %d\n"
1013 "b_se0_srp: %d\n" 1069 "b_se0_srp: %d\n"
1014 "b_sess_end: %d\n" 1070 "b_ssend_srp: %d\n"
1015 "b_sess_vld: %d\n" 1071 "b_sess_vld: %d\n"
1016 "id: %d\n", 1072 "id: %d\n",
1017 fsm->a_bus_req, 1073 fsm->a_bus_req,
@@ -1026,7 +1082,7 @@ static int show_fsl_usb2_otg_state(struct device *dev,
1026 fsm->b_bus_suspend, 1082 fsm->b_bus_suspend,
1027 fsm->b_conn, 1083 fsm->b_conn,
1028 fsm->b_se0_srp, 1084 fsm->b_se0_srp,
1029 fsm->b_sess_end, 1085 fsm->b_ssend_srp,
1030 fsm->b_sess_vld, 1086 fsm->b_sess_vld,
1031 fsm->id); 1087 fsm->id);
1032 size -= t; 1088 size -= t;
@@ -1057,7 +1113,7 @@ static long fsl_otg_ioctl(struct file *file, unsigned int cmd,
1057 break; 1113 break;
1058 1114
1059 case SET_A_SUSPEND_REQ: 1115 case SET_A_SUSPEND_REQ:
1060 fsl_otg_dev->fsm.a_suspend_req = arg; 1116 fsl_otg_dev->fsm.a_suspend_req_inf = arg;
1061 break; 1117 break;
1062 1118
1063 case SET_A_BUS_DROP: 1119 case SET_A_BUS_DROP:
diff --git a/drivers/usb/phy/phy-fsl-usb.h b/drivers/usb/phy/phy-fsl-usb.h
index e1859b8ef567..7365170a2f23 100644
--- a/drivers/usb/phy/phy-fsl-usb.h
+++ b/drivers/usb/phy/phy-fsl-usb.h
@@ -401,6 +401,6 @@ struct fsl_otg_config {
401#define GET_A_BUS_REQ _IOR(OTG_IOCTL_MAGIC, 8, int) 401#define GET_A_BUS_REQ _IOR(OTG_IOCTL_MAGIC, 8, int)
402#define GET_B_BUS_REQ _IOR(OTG_IOCTL_MAGIC, 9, int) 402#define GET_B_BUS_REQ _IOR(OTG_IOCTL_MAGIC, 9, int)
403 403
404void fsl_otg_add_timer(void *timer); 404void fsl_otg_add_timer(struct otg_fsm *fsm, void *timer);
405void fsl_otg_del_timer(void *timer); 405void fsl_otg_del_timer(struct otg_fsm *fsm, void *timer);
406void fsl_otg_pulse_vbus(void); 406void fsl_otg_pulse_vbus(void);
diff --git a/drivers/usb/phy/phy-fsm-usb.c b/drivers/usb/phy/phy-fsm-usb.c
index 7f4596606e18..329c2d2f8595 100644
--- a/drivers/usb/phy/phy-fsm-usb.c
+++ b/drivers/usb/phy/phy-fsm-usb.c
@@ -41,17 +41,17 @@ static int otg_set_protocol(struct otg_fsm *fsm, int protocol)
41 fsm->protocol, protocol); 41 fsm->protocol, protocol);
42 /* stop old protocol */ 42 /* stop old protocol */
43 if (fsm->protocol == PROTO_HOST) 43 if (fsm->protocol == PROTO_HOST)
44 ret = fsm->ops->start_host(fsm, 0); 44 ret = otg_start_host(fsm, 0);
45 else if (fsm->protocol == PROTO_GADGET) 45 else if (fsm->protocol == PROTO_GADGET)
46 ret = fsm->ops->start_gadget(fsm, 0); 46 ret = otg_start_gadget(fsm, 0);
47 if (ret) 47 if (ret)
48 return ret; 48 return ret;
49 49
50 /* start new protocol */ 50 /* start new protocol */
51 if (protocol == PROTO_HOST) 51 if (protocol == PROTO_HOST)
52 ret = fsm->ops->start_host(fsm, 1); 52 ret = otg_start_host(fsm, 1);
53 else if (protocol == PROTO_GADGET) 53 else if (protocol == PROTO_GADGET)
54 ret = fsm->ops->start_gadget(fsm, 1); 54 ret = otg_start_gadget(fsm, 1);
55 if (ret) 55 if (ret)
56 return ret; 56 return ret;
57 57
@@ -69,42 +69,50 @@ void otg_leave_state(struct otg_fsm *fsm, enum usb_otg_state old_state)
69{ 69{
70 switch (old_state) { 70 switch (old_state) {
71 case OTG_STATE_B_IDLE: 71 case OTG_STATE_B_IDLE:
72 otg_del_timer(fsm, b_se0_srp_tmr); 72 otg_del_timer(fsm, B_SE0_SRP);
73 fsm->b_se0_srp = 0; 73 fsm->b_se0_srp = 0;
74 fsm->adp_sns = 0;
75 fsm->adp_prb = 0;
74 break; 76 break;
75 case OTG_STATE_B_SRP_INIT: 77 case OTG_STATE_B_SRP_INIT:
78 fsm->data_pulse = 0;
76 fsm->b_srp_done = 0; 79 fsm->b_srp_done = 0;
77 break; 80 break;
78 case OTG_STATE_B_PERIPHERAL: 81 case OTG_STATE_B_PERIPHERAL:
79 break; 82 break;
80 case OTG_STATE_B_WAIT_ACON: 83 case OTG_STATE_B_WAIT_ACON:
81 otg_del_timer(fsm, b_ase0_brst_tmr); 84 otg_del_timer(fsm, B_ASE0_BRST);
82 fsm->b_ase0_brst_tmout = 0; 85 fsm->b_ase0_brst_tmout = 0;
83 break; 86 break;
84 case OTG_STATE_B_HOST: 87 case OTG_STATE_B_HOST:
85 break; 88 break;
86 case OTG_STATE_A_IDLE: 89 case OTG_STATE_A_IDLE:
90 fsm->adp_prb = 0;
87 break; 91 break;
88 case OTG_STATE_A_WAIT_VRISE: 92 case OTG_STATE_A_WAIT_VRISE:
89 otg_del_timer(fsm, a_wait_vrise_tmr); 93 otg_del_timer(fsm, A_WAIT_VRISE);
90 fsm->a_wait_vrise_tmout = 0; 94 fsm->a_wait_vrise_tmout = 0;
91 break; 95 break;
92 case OTG_STATE_A_WAIT_BCON: 96 case OTG_STATE_A_WAIT_BCON:
93 otg_del_timer(fsm, a_wait_bcon_tmr); 97 otg_del_timer(fsm, A_WAIT_BCON);
94 fsm->a_wait_bcon_tmout = 0; 98 fsm->a_wait_bcon_tmout = 0;
95 break; 99 break;
96 case OTG_STATE_A_HOST: 100 case OTG_STATE_A_HOST:
97 otg_del_timer(fsm, a_wait_enum_tmr); 101 otg_del_timer(fsm, A_WAIT_ENUM);
98 break; 102 break;
99 case OTG_STATE_A_SUSPEND: 103 case OTG_STATE_A_SUSPEND:
100 otg_del_timer(fsm, a_aidl_bdis_tmr); 104 otg_del_timer(fsm, A_AIDL_BDIS);
101 fsm->a_aidl_bdis_tmout = 0; 105 fsm->a_aidl_bdis_tmout = 0;
102 fsm->a_suspend_req = 0; 106 fsm->a_suspend_req_inf = 0;
103 break; 107 break;
104 case OTG_STATE_A_PERIPHERAL: 108 case OTG_STATE_A_PERIPHERAL:
109 otg_del_timer(fsm, A_BIDL_ADIS);
110 fsm->a_bidl_adis_tmout = 0;
105 break; 111 break;
106 case OTG_STATE_A_WAIT_VFALL: 112 case OTG_STATE_A_WAIT_VFALL:
107 otg_del_timer(fsm, a_wait_vrise_tmr); 113 otg_del_timer(fsm, A_WAIT_VFALL);
114 fsm->a_wait_vfall_tmout = 0;
115 otg_del_timer(fsm, A_WAIT_VRISE);
108 break; 116 break;
109 case OTG_STATE_A_VBUS_ERR: 117 case OTG_STATE_A_VBUS_ERR:
110 break; 118 break;
@@ -127,14 +135,19 @@ int otg_set_state(struct otg_fsm *fsm, enum usb_otg_state new_state)
127 otg_chrg_vbus(fsm, 0); 135 otg_chrg_vbus(fsm, 0);
128 otg_loc_conn(fsm, 0); 136 otg_loc_conn(fsm, 0);
129 otg_loc_sof(fsm, 0); 137 otg_loc_sof(fsm, 0);
138 /*
139 * Driver is responsible for starting ADP probing
140 * if ADP sensing times out.
141 */
142 otg_start_adp_sns(fsm);
130 otg_set_protocol(fsm, PROTO_UNDEF); 143 otg_set_protocol(fsm, PROTO_UNDEF);
131 otg_add_timer(fsm, b_se0_srp_tmr); 144 otg_add_timer(fsm, B_SE0_SRP);
132 break; 145 break;
133 case OTG_STATE_B_SRP_INIT: 146 case OTG_STATE_B_SRP_INIT:
134 otg_start_pulse(fsm); 147 otg_start_pulse(fsm);
135 otg_loc_sof(fsm, 0); 148 otg_loc_sof(fsm, 0);
136 otg_set_protocol(fsm, PROTO_UNDEF); 149 otg_set_protocol(fsm, PROTO_UNDEF);
137 otg_add_timer(fsm, b_srp_fail_tmr); 150 otg_add_timer(fsm, B_SRP_FAIL);
138 break; 151 break;
139 case OTG_STATE_B_PERIPHERAL: 152 case OTG_STATE_B_PERIPHERAL:
140 otg_chrg_vbus(fsm, 0); 153 otg_chrg_vbus(fsm, 0);
@@ -147,7 +160,7 @@ int otg_set_state(struct otg_fsm *fsm, enum usb_otg_state new_state)
147 otg_loc_conn(fsm, 0); 160 otg_loc_conn(fsm, 0);
148 otg_loc_sof(fsm, 0); 161 otg_loc_sof(fsm, 0);
149 otg_set_protocol(fsm, PROTO_HOST); 162 otg_set_protocol(fsm, PROTO_HOST);
150 otg_add_timer(fsm, b_ase0_brst_tmr); 163 otg_add_timer(fsm, B_ASE0_BRST);
151 fsm->a_bus_suspend = 0; 164 fsm->a_bus_suspend = 0;
152 break; 165 break;
153 case OTG_STATE_B_HOST: 166 case OTG_STATE_B_HOST:
@@ -163,6 +176,7 @@ int otg_set_state(struct otg_fsm *fsm, enum usb_otg_state new_state)
163 otg_chrg_vbus(fsm, 0); 176 otg_chrg_vbus(fsm, 0);
164 otg_loc_conn(fsm, 0); 177 otg_loc_conn(fsm, 0);
165 otg_loc_sof(fsm, 0); 178 otg_loc_sof(fsm, 0);
179 otg_start_adp_prb(fsm);
166 otg_set_protocol(fsm, PROTO_HOST); 180 otg_set_protocol(fsm, PROTO_HOST);
167 break; 181 break;
168 case OTG_STATE_A_WAIT_VRISE: 182 case OTG_STATE_A_WAIT_VRISE:
@@ -170,14 +184,14 @@ int otg_set_state(struct otg_fsm *fsm, enum usb_otg_state new_state)
170 otg_loc_conn(fsm, 0); 184 otg_loc_conn(fsm, 0);
171 otg_loc_sof(fsm, 0); 185 otg_loc_sof(fsm, 0);
172 otg_set_protocol(fsm, PROTO_HOST); 186 otg_set_protocol(fsm, PROTO_HOST);
173 otg_add_timer(fsm, a_wait_vrise_tmr); 187 otg_add_timer(fsm, A_WAIT_VRISE);
174 break; 188 break;
175 case OTG_STATE_A_WAIT_BCON: 189 case OTG_STATE_A_WAIT_BCON:
176 otg_drv_vbus(fsm, 1); 190 otg_drv_vbus(fsm, 1);
177 otg_loc_conn(fsm, 0); 191 otg_loc_conn(fsm, 0);
178 otg_loc_sof(fsm, 0); 192 otg_loc_sof(fsm, 0);
179 otg_set_protocol(fsm, PROTO_HOST); 193 otg_set_protocol(fsm, PROTO_HOST);
180 otg_add_timer(fsm, a_wait_bcon_tmr); 194 otg_add_timer(fsm, A_WAIT_BCON);
181 break; 195 break;
182 case OTG_STATE_A_HOST: 196 case OTG_STATE_A_HOST:
183 otg_drv_vbus(fsm, 1); 197 otg_drv_vbus(fsm, 1);
@@ -188,15 +202,15 @@ int otg_set_state(struct otg_fsm *fsm, enum usb_otg_state new_state)
188 * When HNP is triggered while a_bus_req = 0, a_host will 202 * When HNP is triggered while a_bus_req = 0, a_host will
189 * suspend too fast to complete a_set_b_hnp_en 203 * suspend too fast to complete a_set_b_hnp_en
190 */ 204 */
191 if (!fsm->a_bus_req || fsm->a_suspend_req) 205 if (!fsm->a_bus_req || fsm->a_suspend_req_inf)
192 otg_add_timer(fsm, a_wait_enum_tmr); 206 otg_add_timer(fsm, A_WAIT_ENUM);
193 break; 207 break;
194 case OTG_STATE_A_SUSPEND: 208 case OTG_STATE_A_SUSPEND:
195 otg_drv_vbus(fsm, 1); 209 otg_drv_vbus(fsm, 1);
196 otg_loc_conn(fsm, 0); 210 otg_loc_conn(fsm, 0);
197 otg_loc_sof(fsm, 0); 211 otg_loc_sof(fsm, 0);
198 otg_set_protocol(fsm, PROTO_HOST); 212 otg_set_protocol(fsm, PROTO_HOST);
199 otg_add_timer(fsm, a_aidl_bdis_tmr); 213 otg_add_timer(fsm, A_AIDL_BDIS);
200 214
201 break; 215 break;
202 case OTG_STATE_A_PERIPHERAL: 216 case OTG_STATE_A_PERIPHERAL:
@@ -204,12 +218,14 @@ int otg_set_state(struct otg_fsm *fsm, enum usb_otg_state new_state)
204 otg_loc_sof(fsm, 0); 218 otg_loc_sof(fsm, 0);
205 otg_set_protocol(fsm, PROTO_GADGET); 219 otg_set_protocol(fsm, PROTO_GADGET);
206 otg_drv_vbus(fsm, 1); 220 otg_drv_vbus(fsm, 1);
221 otg_add_timer(fsm, A_BIDL_ADIS);
207 break; 222 break;
208 case OTG_STATE_A_WAIT_VFALL: 223 case OTG_STATE_A_WAIT_VFALL:
209 otg_drv_vbus(fsm, 0); 224 otg_drv_vbus(fsm, 0);
210 otg_loc_conn(fsm, 0); 225 otg_loc_conn(fsm, 0);
211 otg_loc_sof(fsm, 0); 226 otg_loc_sof(fsm, 0);
212 otg_set_protocol(fsm, PROTO_HOST); 227 otg_set_protocol(fsm, PROTO_HOST);
228 otg_add_timer(fsm, A_WAIT_VFALL);
213 break; 229 break;
214 case OTG_STATE_A_VBUS_ERR: 230 case OTG_STATE_A_VBUS_ERR:
215 otg_drv_vbus(fsm, 0); 231 otg_drv_vbus(fsm, 0);
@@ -250,7 +266,8 @@ int otg_statemachine(struct otg_fsm *fsm)
250 otg_set_state(fsm, OTG_STATE_A_IDLE); 266 otg_set_state(fsm, OTG_STATE_A_IDLE);
251 else if (fsm->b_sess_vld && fsm->otg->gadget) 267 else if (fsm->b_sess_vld && fsm->otg->gadget)
252 otg_set_state(fsm, OTG_STATE_B_PERIPHERAL); 268 otg_set_state(fsm, OTG_STATE_B_PERIPHERAL);
253 else if (fsm->b_bus_req && fsm->b_sess_end && fsm->b_se0_srp) 269 else if ((fsm->b_bus_req || fsm->adp_change || fsm->power_up) &&
270 fsm->b_ssend_srp && fsm->b_se0_srp)
254 otg_set_state(fsm, OTG_STATE_B_SRP_INIT); 271 otg_set_state(fsm, OTG_STATE_B_SRP_INIT);
255 break; 272 break;
256 case OTG_STATE_B_SRP_INIT: 273 case OTG_STATE_B_SRP_INIT:
@@ -277,13 +294,14 @@ int otg_statemachine(struct otg_fsm *fsm)
277 case OTG_STATE_B_HOST: 294 case OTG_STATE_B_HOST:
278 if (!fsm->id || !fsm->b_sess_vld) 295 if (!fsm->id || !fsm->b_sess_vld)
279 otg_set_state(fsm, OTG_STATE_B_IDLE); 296 otg_set_state(fsm, OTG_STATE_B_IDLE);
280 else if (!fsm->b_bus_req || !fsm->a_conn) 297 else if (!fsm->b_bus_req || !fsm->a_conn || fsm->test_device)
281 otg_set_state(fsm, OTG_STATE_B_PERIPHERAL); 298 otg_set_state(fsm, OTG_STATE_B_PERIPHERAL);
282 break; 299 break;
283 case OTG_STATE_A_IDLE: 300 case OTG_STATE_A_IDLE:
284 if (fsm->id) 301 if (fsm->id)
285 otg_set_state(fsm, OTG_STATE_B_IDLE); 302 otg_set_state(fsm, OTG_STATE_B_IDLE);
286 else if (!fsm->a_bus_drop && (fsm->a_bus_req || fsm->a_srp_det)) 303 else if (!fsm->a_bus_drop && (fsm->a_bus_req ||
304 fsm->a_srp_det || fsm->adp_change || fsm->power_up))
287 otg_set_state(fsm, OTG_STATE_A_WAIT_VRISE); 305 otg_set_state(fsm, OTG_STATE_A_WAIT_VRISE);
288 break; 306 break;
289 case OTG_STATE_A_WAIT_VRISE: 307 case OTG_STATE_A_WAIT_VRISE:
@@ -301,7 +319,7 @@ int otg_statemachine(struct otg_fsm *fsm)
301 otg_set_state(fsm, OTG_STATE_A_WAIT_VFALL); 319 otg_set_state(fsm, OTG_STATE_A_WAIT_VFALL);
302 break; 320 break;
303 case OTG_STATE_A_HOST: 321 case OTG_STATE_A_HOST:
304 if ((!fsm->a_bus_req || fsm->a_suspend_req) && 322 if ((!fsm->a_bus_req || fsm->a_suspend_req_inf) &&
305 fsm->otg->host->b_hnp_enable) 323 fsm->otg->host->b_hnp_enable)
306 otg_set_state(fsm, OTG_STATE_A_SUSPEND); 324 otg_set_state(fsm, OTG_STATE_A_SUSPEND);
307 else if (fsm->id || !fsm->b_conn || fsm->a_bus_drop) 325 else if (fsm->id || !fsm->b_conn || fsm->a_bus_drop)
@@ -324,14 +342,14 @@ int otg_statemachine(struct otg_fsm *fsm)
324 case OTG_STATE_A_PERIPHERAL: 342 case OTG_STATE_A_PERIPHERAL:
325 if (fsm->id || fsm->a_bus_drop) 343 if (fsm->id || fsm->a_bus_drop)
326 otg_set_state(fsm, OTG_STATE_A_WAIT_VFALL); 344 otg_set_state(fsm, OTG_STATE_A_WAIT_VFALL);
327 else if (fsm->b_bus_suspend) 345 else if (fsm->a_bidl_adis_tmout || fsm->b_bus_suspend)
328 otg_set_state(fsm, OTG_STATE_A_WAIT_BCON); 346 otg_set_state(fsm, OTG_STATE_A_WAIT_BCON);
329 else if (!fsm->a_vbus_vld) 347 else if (!fsm->a_vbus_vld)
330 otg_set_state(fsm, OTG_STATE_A_VBUS_ERR); 348 otg_set_state(fsm, OTG_STATE_A_VBUS_ERR);
331 break; 349 break;
332 case OTG_STATE_A_WAIT_VFALL: 350 case OTG_STATE_A_WAIT_VFALL:
333 if (fsm->id || fsm->a_bus_req || (!fsm->a_sess_vld && 351 if (fsm->a_wait_vfall_tmout || fsm->id || fsm->a_bus_req ||
334 !fsm->b_conn)) 352 (!fsm->a_sess_vld && !fsm->b_conn))
335 otg_set_state(fsm, OTG_STATE_A_IDLE); 353 otg_set_state(fsm, OTG_STATE_A_IDLE);
336 break; 354 break;
337 case OTG_STATE_A_VBUS_ERR: 355 case OTG_STATE_A_VBUS_ERR:
diff --git a/drivers/usb/phy/phy-fsm-usb.h b/drivers/usb/phy/phy-fsm-usb.h
index fbe586206f33..7441b46a27f1 100644
--- a/drivers/usb/phy/phy-fsm-usb.h
+++ b/drivers/usb/phy/phy-fsm-usb.h
@@ -34,45 +34,76 @@
34#define PROTO_HOST (1) 34#define PROTO_HOST (1)
35#define PROTO_GADGET (2) 35#define PROTO_GADGET (2)
36 36
37enum otg_fsm_timer {
38 /* Standard OTG timers */
39 A_WAIT_VRISE,
40 A_WAIT_VFALL,
41 A_WAIT_BCON,
42 A_AIDL_BDIS,
43 B_ASE0_BRST,
44 A_BIDL_ADIS,
45
46 /* Auxiliary timers */
47 B_SE0_SRP,
48 B_SRP_FAIL,
49 A_WAIT_ENUM,
50
51 NUM_OTG_FSM_TIMERS,
52};
53
37/* OTG state machine according to the OTG spec */ 54/* OTG state machine according to the OTG spec */
38struct otg_fsm { 55struct otg_fsm {
39 /* Input */ 56 /* Input */
57 int id;
58 int adp_change;
59 int power_up;
60 int test_device;
61 int a_bus_drop;
62 int a_bus_req;
63 int a_srp_det;
64 int a_vbus_vld;
65 int b_conn;
40 int a_bus_resume; 66 int a_bus_resume;
41 int a_bus_suspend; 67 int a_bus_suspend;
42 int a_conn; 68 int a_conn;
69 int b_bus_req;
70 int b_se0_srp;
71 int b_ssend_srp;
72 int b_sess_vld;
73 /* Auxilary inputs */
43 int a_sess_vld; 74 int a_sess_vld;
44 int a_srp_det;
45 int a_vbus_vld;
46 int b_bus_resume; 75 int b_bus_resume;
47 int b_bus_suspend; 76 int b_bus_suspend;
48 int b_conn; 77
49 int b_se0_srp; 78 /* Output */
50 int b_sess_end; 79 int data_pulse;
51 int b_sess_vld; 80 int drv_vbus;
52 int id; 81 int loc_conn;
82 int loc_sof;
83 int adp_prb;
84 int adp_sns;
53 85
54 /* Internal variables */ 86 /* Internal variables */
55 int a_set_b_hnp_en; 87 int a_set_b_hnp_en;
56 int b_srp_done; 88 int b_srp_done;
57 int b_hnp_enable; 89 int b_hnp_enable;
90 int a_clr_err;
91
92 /* Informative variables */
93 int a_bus_drop_inf;
94 int a_bus_req_inf;
95 int a_clr_err_inf;
96 int b_bus_req_inf;
97 /* Auxilary informative variables */
98 int a_suspend_req_inf;
58 99
59 /* Timeout indicator for timers */ 100 /* Timeout indicator for timers */
60 int a_wait_vrise_tmout; 101 int a_wait_vrise_tmout;
102 int a_wait_vfall_tmout;
61 int a_wait_bcon_tmout; 103 int a_wait_bcon_tmout;
62 int a_aidl_bdis_tmout; 104 int a_aidl_bdis_tmout;
63 int b_ase0_brst_tmout; 105 int b_ase0_brst_tmout;
64 106 int a_bidl_adis_tmout;
65 /* Informative variables */
66 int a_bus_drop;
67 int a_bus_req;
68 int a_clr_err;
69 int a_suspend_req;
70 int b_bus_req;
71
72 /* Output */
73 int drv_vbus;
74 int loc_conn;
75 int loc_sof;
76 107
77 struct otg_fsm_ops *ops; 108 struct otg_fsm_ops *ops;
78 struct usb_otg *otg; 109 struct usb_otg *otg;
@@ -83,65 +114,123 @@ struct otg_fsm {
83}; 114};
84 115
85struct otg_fsm_ops { 116struct otg_fsm_ops {
86 void (*chrg_vbus)(int on); 117 void (*chrg_vbus)(struct otg_fsm *fsm, int on);
87 void (*drv_vbus)(int on); 118 void (*drv_vbus)(struct otg_fsm *fsm, int on);
88 void (*loc_conn)(int on); 119 void (*loc_conn)(struct otg_fsm *fsm, int on);
89 void (*loc_sof)(int on); 120 void (*loc_sof)(struct otg_fsm *fsm, int on);
90 void (*start_pulse)(void); 121 void (*start_pulse)(struct otg_fsm *fsm);
91 void (*add_timer)(void *timer); 122 void (*start_adp_prb)(struct otg_fsm *fsm);
92 void (*del_timer)(void *timer); 123 void (*start_adp_sns)(struct otg_fsm *fsm);
124 void (*add_timer)(struct otg_fsm *fsm, enum otg_fsm_timer timer);
125 void (*del_timer)(struct otg_fsm *fsm, enum otg_fsm_timer timer);
93 int (*start_host)(struct otg_fsm *fsm, int on); 126 int (*start_host)(struct otg_fsm *fsm, int on);
94 int (*start_gadget)(struct otg_fsm *fsm, int on); 127 int (*start_gadget)(struct otg_fsm *fsm, int on);
95}; 128};
96 129
97 130
98static inline void otg_chrg_vbus(struct otg_fsm *fsm, int on) 131static inline int otg_chrg_vbus(struct otg_fsm *fsm, int on)
99{ 132{
100 fsm->ops->chrg_vbus(on); 133 if (!fsm->ops->chrg_vbus)
134 return -EOPNOTSUPP;
135 fsm->ops->chrg_vbus(fsm, on);
136 return 0;
101} 137}
102 138
103static inline void otg_drv_vbus(struct otg_fsm *fsm, int on) 139static inline int otg_drv_vbus(struct otg_fsm *fsm, int on)
104{ 140{
141 if (!fsm->ops->drv_vbus)
142 return -EOPNOTSUPP;
105 if (fsm->drv_vbus != on) { 143 if (fsm->drv_vbus != on) {
106 fsm->drv_vbus = on; 144 fsm->drv_vbus = on;
107 fsm->ops->drv_vbus(on); 145 fsm->ops->drv_vbus(fsm, on);
108 } 146 }
147 return 0;
109} 148}
110 149
111static inline void otg_loc_conn(struct otg_fsm *fsm, int on) 150static inline int otg_loc_conn(struct otg_fsm *fsm, int on)
112{ 151{
152 if (!fsm->ops->loc_conn)
153 return -EOPNOTSUPP;
113 if (fsm->loc_conn != on) { 154 if (fsm->loc_conn != on) {
114 fsm->loc_conn = on; 155 fsm->loc_conn = on;
115 fsm->ops->loc_conn(on); 156 fsm->ops->loc_conn(fsm, on);
116 } 157 }
158 return 0;
117} 159}
118 160
119static inline void otg_loc_sof(struct otg_fsm *fsm, int on) 161static inline int otg_loc_sof(struct otg_fsm *fsm, int on)
120{ 162{
163 if (!fsm->ops->loc_sof)
164 return -EOPNOTSUPP;
121 if (fsm->loc_sof != on) { 165 if (fsm->loc_sof != on) {
122 fsm->loc_sof = on; 166 fsm->loc_sof = on;
123 fsm->ops->loc_sof(on); 167 fsm->ops->loc_sof(fsm, on);
168 }
169 return 0;
170}
171
172static inline int otg_start_pulse(struct otg_fsm *fsm)
173{
174 if (!fsm->ops->start_pulse)
175 return -EOPNOTSUPP;
176 if (!fsm->data_pulse) {
177 fsm->data_pulse = 1;
178 fsm->ops->start_pulse(fsm);
124 } 179 }
180 return 0;
125} 181}
126 182
127static inline void otg_start_pulse(struct otg_fsm *fsm) 183static inline int otg_start_adp_prb(struct otg_fsm *fsm)
128{ 184{
129 fsm->ops->start_pulse(); 185 if (!fsm->ops->start_adp_prb)
186 return -EOPNOTSUPP;
187 if (!fsm->adp_prb) {
188 fsm->adp_sns = 0;
189 fsm->adp_prb = 1;
190 fsm->ops->start_adp_prb(fsm);
191 }
192 return 0;
130} 193}
131 194
132static inline void otg_add_timer(struct otg_fsm *fsm, void *timer) 195static inline int otg_start_adp_sns(struct otg_fsm *fsm)
133{ 196{
134 fsm->ops->add_timer(timer); 197 if (!fsm->ops->start_adp_sns)
198 return -EOPNOTSUPP;
199 if (!fsm->adp_sns) {
200 fsm->adp_sns = 1;
201 fsm->ops->start_adp_sns(fsm);
202 }
203 return 0;
135} 204}
136 205
137static inline void otg_del_timer(struct otg_fsm *fsm, void *timer) 206static inline int otg_add_timer(struct otg_fsm *fsm, enum otg_fsm_timer timer)
138{ 207{
139 fsm->ops->del_timer(timer); 208 if (!fsm->ops->add_timer)
209 return -EOPNOTSUPP;
210 fsm->ops->add_timer(fsm, timer);
211 return 0;
140} 212}
141 213
142int otg_statemachine(struct otg_fsm *fsm); 214static inline int otg_del_timer(struct otg_fsm *fsm, enum otg_fsm_timer timer)
215{
216 if (!fsm->ops->del_timer)
217 return -EOPNOTSUPP;
218 fsm->ops->del_timer(fsm, timer);
219 return 0;
220}
143 221
144/* Defined by device specific driver, for different timer implementation */ 222static inline int otg_start_host(struct otg_fsm *fsm, int on)
145extern struct fsl_otg_timer *a_wait_vrise_tmr, *a_wait_bcon_tmr, 223{
146 *a_aidl_bdis_tmr, *b_ase0_brst_tmr, *b_se0_srp_tmr, *b_srp_fail_tmr, 224 if (!fsm->ops->start_host)
147 *a_wait_enum_tmr; 225 return -EOPNOTSUPP;
226 return fsm->ops->start_host(fsm, on);
227}
228
229static inline int otg_start_gadget(struct otg_fsm *fsm, int on)
230{
231 if (!fsm->ops->start_gadget)
232 return -EOPNOTSUPP;
233 return fsm->ops->start_gadget(fsm, on);
234}
235
236int otg_statemachine(struct otg_fsm *fsm);
diff --git a/drivers/usb/phy/phy-generic.c b/drivers/usb/phy/phy-generic.c
index efe59f3f7fda..fce3a9e9bb5d 100644
--- a/drivers/usb/phy/phy-generic.c
+++ b/drivers/usb/phy/phy-generic.c
@@ -35,6 +35,9 @@
35#include <linux/clk.h> 35#include <linux/clk.h>
36#include <linux/regulator/consumer.h> 36#include <linux/regulator/consumer.h>
37#include <linux/of.h> 37#include <linux/of.h>
38#include <linux/of_gpio.h>
39#include <linux/gpio.h>
40#include <linux/delay.h>
38 41
39#include "phy-generic.h" 42#include "phy-generic.h"
40 43
@@ -64,6 +67,23 @@ static int nop_set_suspend(struct usb_phy *x, int suspend)
64 return 0; 67 return 0;
65} 68}
66 69
70static void nop_reset_set(struct usb_phy_gen_xceiv *nop, int asserted)
71{
72 int value;
73
74 if (!gpio_is_valid(nop->gpio_reset))
75 return;
76
77 value = asserted;
78 if (nop->reset_active_low)
79 value = !value;
80
81 gpio_set_value_cansleep(nop->gpio_reset, value);
82
83 if (!asserted)
84 usleep_range(10000, 20000);
85}
86
67int usb_gen_phy_init(struct usb_phy *phy) 87int usb_gen_phy_init(struct usb_phy *phy)
68{ 88{
69 struct usb_phy_gen_xceiv *nop = dev_get_drvdata(phy->dev); 89 struct usb_phy_gen_xceiv *nop = dev_get_drvdata(phy->dev);
@@ -74,13 +94,10 @@ int usb_gen_phy_init(struct usb_phy *phy)
74 } 94 }
75 95
76 if (!IS_ERR(nop->clk)) 96 if (!IS_ERR(nop->clk))
77 clk_enable(nop->clk); 97 clk_prepare_enable(nop->clk);
78 98
79 if (!IS_ERR(nop->reset)) { 99 /* De-assert RESET */
80 /* De-assert RESET */ 100 nop_reset_set(nop, 0);
81 if (regulator_enable(nop->reset))
82 dev_err(phy->dev, "Failed to de-assert reset\n");
83 }
84 101
85 return 0; 102 return 0;
86} 103}
@@ -90,14 +107,11 @@ void usb_gen_phy_shutdown(struct usb_phy *phy)
90{ 107{
91 struct usb_phy_gen_xceiv *nop = dev_get_drvdata(phy->dev); 108 struct usb_phy_gen_xceiv *nop = dev_get_drvdata(phy->dev);
92 109
93 if (!IS_ERR(nop->reset)) { 110 /* Assert RESET */
94 /* Assert RESET */ 111 nop_reset_set(nop, 1);
95 if (regulator_disable(nop->reset))
96 dev_err(phy->dev, "Failed to assert reset\n");
97 }
98 112
99 if (!IS_ERR(nop->clk)) 113 if (!IS_ERR(nop->clk))
100 clk_disable(nop->clk); 114 clk_disable_unprepare(nop->clk);
101 115
102 if (!IS_ERR(nop->vcc)) { 116 if (!IS_ERR(nop->vcc)) {
103 if (regulator_disable(nop->vcc)) 117 if (regulator_disable(nop->vcc))
@@ -136,8 +150,7 @@ static int nop_set_host(struct usb_otg *otg, struct usb_bus *host)
136} 150}
137 151
138int usb_phy_gen_create_phy(struct device *dev, struct usb_phy_gen_xceiv *nop, 152int usb_phy_gen_create_phy(struct device *dev, struct usb_phy_gen_xceiv *nop,
139 enum usb_phy_type type, u32 clk_rate, bool needs_vcc, 153 enum usb_phy_type type, u32 clk_rate, bool needs_vcc)
140 bool needs_reset)
141{ 154{
142 int err; 155 int err;
143 156
@@ -160,14 +173,6 @@ int usb_phy_gen_create_phy(struct device *dev, struct usb_phy_gen_xceiv *nop,
160 } 173 }
161 } 174 }
162 175
163 if (!IS_ERR(nop->clk)) {
164 err = clk_prepare(nop->clk);
165 if (err) {
166 dev_err(dev, "Error preparing clock\n");
167 return err;
168 }
169 }
170
171 nop->vcc = devm_regulator_get(dev, "vcc"); 176 nop->vcc = devm_regulator_get(dev, "vcc");
172 if (IS_ERR(nop->vcc)) { 177 if (IS_ERR(nop->vcc)) {
173 dev_dbg(dev, "Error getting vcc regulator: %ld\n", 178 dev_dbg(dev, "Error getting vcc regulator: %ld\n",
@@ -176,12 +181,22 @@ int usb_phy_gen_create_phy(struct device *dev, struct usb_phy_gen_xceiv *nop,
176 return -EPROBE_DEFER; 181 return -EPROBE_DEFER;
177 } 182 }
178 183
179 nop->reset = devm_regulator_get(dev, "reset"); 184 if (gpio_is_valid(nop->gpio_reset)) {
180 if (IS_ERR(nop->reset)) { 185 unsigned long gpio_flags;
181 dev_dbg(dev, "Error getting reset regulator: %ld\n", 186
182 PTR_ERR(nop->reset)); 187 /* Assert RESET */
183 if (needs_reset) 188 if (nop->reset_active_low)
184 return -EPROBE_DEFER; 189 gpio_flags = GPIOF_OUT_INIT_LOW;
190 else
191 gpio_flags = GPIOF_OUT_INIT_HIGH;
192
193 err = devm_gpio_request_one(dev, nop->gpio_reset,
194 gpio_flags, dev_name(dev));
195 if (err) {
196 dev_err(dev, "Error requesting RESET GPIO %d\n",
197 nop->gpio_reset);
198 return err;
199 }
185 } 200 }
186 201
187 nop->dev = dev; 202 nop->dev = dev;
@@ -200,13 +215,6 @@ int usb_phy_gen_create_phy(struct device *dev, struct usb_phy_gen_xceiv *nop,
200} 215}
201EXPORT_SYMBOL_GPL(usb_phy_gen_create_phy); 216EXPORT_SYMBOL_GPL(usb_phy_gen_create_phy);
202 217
203void usb_phy_gen_cleanup_phy(struct usb_phy_gen_xceiv *nop)
204{
205 if (!IS_ERR(nop->clk))
206 clk_unprepare(nop->clk);
207}
208EXPORT_SYMBOL_GPL(usb_phy_gen_cleanup_phy);
209
210static int usb_phy_gen_xceiv_probe(struct platform_device *pdev) 218static int usb_phy_gen_xceiv_probe(struct platform_device *pdev)
211{ 219{
212 struct device *dev = &pdev->dev; 220 struct device *dev = &pdev->dev;
@@ -217,31 +225,36 @@ static int usb_phy_gen_xceiv_probe(struct platform_device *pdev)
217 int err; 225 int err;
218 u32 clk_rate = 0; 226 u32 clk_rate = 0;
219 bool needs_vcc = false; 227 bool needs_vcc = false;
220 bool needs_reset = false; 228
229 nop = devm_kzalloc(dev, sizeof(*nop), GFP_KERNEL);
230 if (!nop)
231 return -ENOMEM;
232
233 nop->reset_active_low = true; /* default behaviour */
221 234
222 if (dev->of_node) { 235 if (dev->of_node) {
223 struct device_node *node = dev->of_node; 236 struct device_node *node = dev->of_node;
237 enum of_gpio_flags flags;
224 238
225 if (of_property_read_u32(node, "clock-frequency", &clk_rate)) 239 if (of_property_read_u32(node, "clock-frequency", &clk_rate))
226 clk_rate = 0; 240 clk_rate = 0;
227 241
228 needs_vcc = of_property_read_bool(node, "vcc-supply"); 242 needs_vcc = of_property_read_bool(node, "vcc-supply");
229 needs_reset = of_property_read_bool(node, "reset-supply"); 243 nop->gpio_reset = of_get_named_gpio_flags(node, "reset-gpios",
244 0, &flags);
245 if (nop->gpio_reset == -EPROBE_DEFER)
246 return -EPROBE_DEFER;
247
248 nop->reset_active_low = flags & OF_GPIO_ACTIVE_LOW;
230 249
231 } else if (pdata) { 250 } else if (pdata) {
232 type = pdata->type; 251 type = pdata->type;
233 clk_rate = pdata->clk_rate; 252 clk_rate = pdata->clk_rate;
234 needs_vcc = pdata->needs_vcc; 253 needs_vcc = pdata->needs_vcc;
235 needs_reset = pdata->needs_reset; 254 nop->gpio_reset = pdata->gpio_reset;
236 } 255 }
237 256
238 nop = devm_kzalloc(dev, sizeof(*nop), GFP_KERNEL); 257 err = usb_phy_gen_create_phy(dev, nop, type, clk_rate, needs_vcc);
239 if (!nop)
240 return -ENOMEM;
241
242
243 err = usb_phy_gen_create_phy(dev, nop, type, clk_rate, needs_vcc,
244 needs_reset);
245 if (err) 258 if (err)
246 return err; 259 return err;
247 260
@@ -252,15 +265,13 @@ static int usb_phy_gen_xceiv_probe(struct platform_device *pdev)
252 if (err) { 265 if (err) {
253 dev_err(&pdev->dev, "can't register transceiver, err: %d\n", 266 dev_err(&pdev->dev, "can't register transceiver, err: %d\n",
254 err); 267 err);
255 goto err_add; 268 return err;
256 } 269 }
257 270
258 platform_set_drvdata(pdev, nop); 271 platform_set_drvdata(pdev, nop);
259 272
260 return 0; 273 return 0;
261 274
262err_add:
263 usb_phy_gen_cleanup_phy(nop);
264 return err; 275 return err;
265} 276}
266 277
@@ -268,7 +279,6 @@ static int usb_phy_gen_xceiv_remove(struct platform_device *pdev)
268{ 279{
269 struct usb_phy_gen_xceiv *nop = platform_get_drvdata(pdev); 280 struct usb_phy_gen_xceiv *nop = platform_get_drvdata(pdev);
270 281
271 usb_phy_gen_cleanup_phy(nop);
272 usb_remove_phy(&nop->phy); 282 usb_remove_phy(&nop->phy);
273 283
274 return 0; 284 return 0;
diff --git a/drivers/usb/phy/phy-generic.h b/drivers/usb/phy/phy-generic.h
index 61687d5a965b..d2a220d81734 100644
--- a/drivers/usb/phy/phy-generic.h
+++ b/drivers/usb/phy/phy-generic.h
@@ -6,15 +6,14 @@ struct usb_phy_gen_xceiv {
6 struct device *dev; 6 struct device *dev;
7 struct clk *clk; 7 struct clk *clk;
8 struct regulator *vcc; 8 struct regulator *vcc;
9 struct regulator *reset; 9 int gpio_reset;
10 bool reset_active_low;
10}; 11};
11 12
12int usb_gen_phy_init(struct usb_phy *phy); 13int usb_gen_phy_init(struct usb_phy *phy);
13void usb_gen_phy_shutdown(struct usb_phy *phy); 14void usb_gen_phy_shutdown(struct usb_phy *phy);
14 15
15int usb_phy_gen_create_phy(struct device *dev, struct usb_phy_gen_xceiv *nop, 16int usb_phy_gen_create_phy(struct device *dev, struct usb_phy_gen_xceiv *nop,
16 enum usb_phy_type type, u32 clk_rate, bool needs_vcc, 17 enum usb_phy_type type, u32 clk_rate, bool needs_vcc);
17 bool needs_reset);
18void usb_phy_gen_cleanup_phy(struct usb_phy_gen_xceiv *nop);
19 18
20#endif 19#endif
diff --git a/drivers/usb/phy/phy-omap-control.c b/drivers/usb/phy/phy-omap-control.c
index a4dda8e12562..09c5ace1edd8 100644
--- a/drivers/usb/phy/phy-omap-control.c
+++ b/drivers/usb/phy/phy-omap-control.c
@@ -20,87 +20,77 @@
20#include <linux/platform_device.h> 20#include <linux/platform_device.h>
21#include <linux/slab.h> 21#include <linux/slab.h>
22#include <linux/of.h> 22#include <linux/of.h>
23#include <linux/of_device.h>
23#include <linux/err.h> 24#include <linux/err.h>
24#include <linux/io.h> 25#include <linux/io.h>
25#include <linux/clk.h> 26#include <linux/clk.h>
26#include <linux/usb/omap_control_usb.h> 27#include <linux/usb/omap_control_usb.h>
27 28
28static struct omap_control_usb *control_usb;
29
30/**
31 * omap_get_control_dev - returns the device pointer for this control device
32 *
33 * This API should be called to get the device pointer for this control
34 * module device. This device pointer should be used for called other
35 * exported API's in this driver.
36 *
37 * To be used by PHY driver and glue driver.
38 */
39struct device *omap_get_control_dev(void)
40{
41 if (!control_usb)
42 return ERR_PTR(-ENODEV);
43
44 return control_usb->dev;
45}
46EXPORT_SYMBOL_GPL(omap_get_control_dev);
47
48/** 29/**
49 * omap_control_usb3_phy_power - power on/off the serializer using control 30 * omap_control_usb_phy_power - power on/off the phy using control module reg
50 * module
51 * @dev: the control module device 31 * @dev: the control module device
52 * @on: 0 to off and 1 to on based on powering on or off the PHY 32 * @on: 0 or 1, based on powering on or off the PHY
53 *
54 * usb3 PHY driver should call this API to power on or off the PHY.
55 */ 33 */
56void omap_control_usb3_phy_power(struct device *dev, bool on) 34void omap_control_usb_phy_power(struct device *dev, int on)
57{ 35{
58 u32 val; 36 u32 val;
59 unsigned long rate; 37 unsigned long rate;
60 struct omap_control_usb *control_usb = dev_get_drvdata(dev); 38 struct omap_control_usb *control_usb;
61 39
62 if (control_usb->type != OMAP_CTRL_DEV_TYPE2) 40 if (IS_ERR(dev) || !dev) {
41 pr_err("%s: invalid device\n", __func__);
63 return; 42 return;
43 }
64 44
65 rate = clk_get_rate(control_usb->sys_clk); 45 control_usb = dev_get_drvdata(dev);
66 rate = rate/1000000; 46 if (!control_usb) {
67 47 dev_err(dev, "%s: invalid control usb device\n", __func__);
68 val = readl(control_usb->phy_power); 48 return;
69
70 if (on) {
71 val &= ~(OMAP_CTRL_USB_PWRCTL_CLK_CMD_MASK |
72 OMAP_CTRL_USB_PWRCTL_CLK_FREQ_MASK);
73 val |= OMAP_CTRL_USB3_PHY_TX_RX_POWERON <<
74 OMAP_CTRL_USB_PWRCTL_CLK_CMD_SHIFT;
75 val |= rate << OMAP_CTRL_USB_PWRCTL_CLK_FREQ_SHIFT;
76 } else {
77 val &= ~OMAP_CTRL_USB_PWRCTL_CLK_CMD_MASK;
78 val |= OMAP_CTRL_USB3_PHY_TX_RX_POWEROFF <<
79 OMAP_CTRL_USB_PWRCTL_CLK_CMD_SHIFT;
80 } 49 }
81 50
82 writel(val, control_usb->phy_power); 51 if (control_usb->type == OMAP_CTRL_TYPE_OTGHS)
83} 52 return;
84EXPORT_SYMBOL_GPL(omap_control_usb3_phy_power);
85 53
86/** 54 val = readl(control_usb->power);
87 * omap_control_usb_phy_power - power on/off the phy using control module reg
88 * @dev: the control module device
89 * @on: 0 or 1, based on powering on or off the PHY
90 */
91void omap_control_usb_phy_power(struct device *dev, int on)
92{
93 u32 val;
94 struct omap_control_usb *control_usb = dev_get_drvdata(dev);
95 55
96 val = readl(control_usb->dev_conf); 56 switch (control_usb->type) {
57 case OMAP_CTRL_TYPE_USB2:
58 if (on)
59 val &= ~OMAP_CTRL_DEV_PHY_PD;
60 else
61 val |= OMAP_CTRL_DEV_PHY_PD;
62 break;
97 63
98 if (on) 64 case OMAP_CTRL_TYPE_PIPE3:
99 val &= ~OMAP_CTRL_DEV_PHY_PD; 65 rate = clk_get_rate(control_usb->sys_clk);
100 else 66 rate = rate/1000000;
101 val |= OMAP_CTRL_DEV_PHY_PD; 67
68 if (on) {
69 val &= ~(OMAP_CTRL_USB_PWRCTL_CLK_CMD_MASK |
70 OMAP_CTRL_USB_PWRCTL_CLK_FREQ_MASK);
71 val |= OMAP_CTRL_USB3_PHY_TX_RX_POWERON <<
72 OMAP_CTRL_USB_PWRCTL_CLK_CMD_SHIFT;
73 val |= rate << OMAP_CTRL_USB_PWRCTL_CLK_FREQ_SHIFT;
74 } else {
75 val &= ~OMAP_CTRL_USB_PWRCTL_CLK_CMD_MASK;
76 val |= OMAP_CTRL_USB3_PHY_TX_RX_POWEROFF <<
77 OMAP_CTRL_USB_PWRCTL_CLK_CMD_SHIFT;
78 }
79 break;
102 80
103 writel(val, control_usb->dev_conf); 81 case OMAP_CTRL_TYPE_DRA7USB2:
82 if (on)
83 val &= ~OMAP_CTRL_USB2_PHY_PD;
84 else
85 val |= OMAP_CTRL_USB2_PHY_PD;
86 break;
87 default:
88 dev_err(dev, "%s: type %d not recognized\n",
89 __func__, control_usb->type);
90 break;
91 }
92
93 writel(val, control_usb->power);
104} 94}
105EXPORT_SYMBOL_GPL(omap_control_usb_phy_power); 95EXPORT_SYMBOL_GPL(omap_control_usb_phy_power);
106 96
@@ -172,11 +162,19 @@ void omap_control_usb_set_mode(struct device *dev,
172{ 162{
173 struct omap_control_usb *ctrl_usb; 163 struct omap_control_usb *ctrl_usb;
174 164
175 if (IS_ERR(dev) || control_usb->type != OMAP_CTRL_DEV_TYPE1) 165 if (IS_ERR(dev) || !dev)
176 return; 166 return;
177 167
178 ctrl_usb = dev_get_drvdata(dev); 168 ctrl_usb = dev_get_drvdata(dev);
179 169
170 if (!ctrl_usb) {
171 dev_err(dev, "Invalid control usb device\n");
172 return;
173 }
174
175 if (ctrl_usb->type != OMAP_CTRL_TYPE_OTGHS)
176 return;
177
180 switch (mode) { 178 switch (mode) {
181 case USB_MODE_HOST: 179 case USB_MODE_HOST:
182 omap_control_usb_host_mode(ctrl_usb); 180 omap_control_usb_host_mode(ctrl_usb);
@@ -193,12 +191,46 @@ void omap_control_usb_set_mode(struct device *dev,
193} 191}
194EXPORT_SYMBOL_GPL(omap_control_usb_set_mode); 192EXPORT_SYMBOL_GPL(omap_control_usb_set_mode);
195 193
194#ifdef CONFIG_OF
195
196static const enum omap_control_usb_type otghs_data = OMAP_CTRL_TYPE_OTGHS;
197static const enum omap_control_usb_type usb2_data = OMAP_CTRL_TYPE_USB2;
198static const enum omap_control_usb_type pipe3_data = OMAP_CTRL_TYPE_PIPE3;
199static const enum omap_control_usb_type dra7usb2_data = OMAP_CTRL_TYPE_DRA7USB2;
200
201static const struct of_device_id omap_control_usb_id_table[] = {
202 {
203 .compatible = "ti,control-phy-otghs",
204 .data = &otghs_data,
205 },
206 {
207 .compatible = "ti,control-phy-usb2",
208 .data = &usb2_data,
209 },
210 {
211 .compatible = "ti,control-phy-pipe3",
212 .data = &pipe3_data,
213 },
214 {
215 .compatible = "ti,control-phy-dra7usb2",
216 .data = &dra7usb2_data,
217 },
218 {},
219};
220MODULE_DEVICE_TABLE(of, omap_control_usb_id_table);
221#endif
222
223
196static int omap_control_usb_probe(struct platform_device *pdev) 224static int omap_control_usb_probe(struct platform_device *pdev)
197{ 225{
198 struct resource *res; 226 struct resource *res;
199 struct device_node *np = pdev->dev.of_node; 227 const struct of_device_id *of_id;
200 struct omap_control_usb_platform_data *pdata = 228 struct omap_control_usb *control_usb;
201 dev_get_platdata(&pdev->dev); 229
230 of_id = of_match_device(of_match_ptr(omap_control_usb_id_table),
231 &pdev->dev);
232 if (!of_id)
233 return -EINVAL;
202 234
203 control_usb = devm_kzalloc(&pdev->dev, sizeof(*control_usb), 235 control_usb = devm_kzalloc(&pdev->dev, sizeof(*control_usb),
204 GFP_KERNEL); 236 GFP_KERNEL);
@@ -207,40 +239,27 @@ static int omap_control_usb_probe(struct platform_device *pdev)
207 return -ENOMEM; 239 return -ENOMEM;
208 } 240 }
209 241
210 if (np) { 242 control_usb->dev = &pdev->dev;
211 of_property_read_u32(np, "ti,type", &control_usb->type); 243 control_usb->type = *(enum omap_control_usb_type *)of_id->data;
212 } else if (pdata) {
213 control_usb->type = pdata->type;
214 } else {
215 dev_err(&pdev->dev, "no pdata present\n");
216 return -EINVAL;
217 }
218
219 control_usb->dev = &pdev->dev;
220
221 res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
222 "control_dev_conf");
223 control_usb->dev_conf = devm_ioremap_resource(&pdev->dev, res);
224 if (IS_ERR(control_usb->dev_conf))
225 return PTR_ERR(control_usb->dev_conf);
226 244
227 if (control_usb->type == OMAP_CTRL_DEV_TYPE1) { 245 if (control_usb->type == OMAP_CTRL_TYPE_OTGHS) {
228 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, 246 res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
229 "otghs_control"); 247 "otghs_control");
230 control_usb->otghs_control = devm_ioremap_resource( 248 control_usb->otghs_control = devm_ioremap_resource(
231 &pdev->dev, res); 249 &pdev->dev, res);
232 if (IS_ERR(control_usb->otghs_control)) 250 if (IS_ERR(control_usb->otghs_control))
233 return PTR_ERR(control_usb->otghs_control); 251 return PTR_ERR(control_usb->otghs_control);
234 } 252 } else {
235
236 if (control_usb->type == OMAP_CTRL_DEV_TYPE2) {
237 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, 253 res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
238 "phy_power_usb"); 254 "power");
239 control_usb->phy_power = devm_ioremap_resource( 255 control_usb->power = devm_ioremap_resource(&pdev->dev, res);
240 &pdev->dev, res); 256 if (IS_ERR(control_usb->power)) {
241 if (IS_ERR(control_usb->phy_power)) 257 dev_err(&pdev->dev, "Couldn't get power register\n");
242 return PTR_ERR(control_usb->phy_power); 258 return PTR_ERR(control_usb->power);
259 }
260 }
243 261
262 if (control_usb->type == OMAP_CTRL_TYPE_PIPE3) {
244 control_usb->sys_clk = devm_clk_get(control_usb->dev, 263 control_usb->sys_clk = devm_clk_get(control_usb->dev,
245 "sys_clkin"); 264 "sys_clkin");
246 if (IS_ERR(control_usb->sys_clk)) { 265 if (IS_ERR(control_usb->sys_clk)) {
@@ -249,20 +268,11 @@ static int omap_control_usb_probe(struct platform_device *pdev)
249 } 268 }
250 } 269 }
251 270
252
253 dev_set_drvdata(control_usb->dev, control_usb); 271 dev_set_drvdata(control_usb->dev, control_usb);
254 272
255 return 0; 273 return 0;
256} 274}
257 275
258#ifdef CONFIG_OF
259static const struct of_device_id omap_control_usb_id_table[] = {
260 { .compatible = "ti,omap-control-usb" },
261 {}
262};
263MODULE_DEVICE_TABLE(of, omap_control_usb_id_table);
264#endif
265
266static struct platform_driver omap_control_usb_driver = { 276static struct platform_driver omap_control_usb_driver = {
267 .probe = omap_control_usb_probe, 277 .probe = omap_control_usb_probe,
268 .driver = { 278 .driver = {
diff --git a/drivers/usb/phy/phy-omap-usb3.c b/drivers/usb/phy/phy-omap-usb3.c
index 4e8a0405f956..0c6ba29bdddd 100644
--- a/drivers/usb/phy/phy-omap-usb3.c
+++ b/drivers/usb/phy/phy-omap-usb3.c
@@ -26,6 +26,7 @@
26#include <linux/pm_runtime.h> 26#include <linux/pm_runtime.h>
27#include <linux/delay.h> 27#include <linux/delay.h>
28#include <linux/usb/omap_control_usb.h> 28#include <linux/usb/omap_control_usb.h>
29#include <linux/of_platform.h>
29 30
30#define PLL_STATUS 0x00000004 31#define PLL_STATUS 0x00000004
31#define PLL_GO 0x00000008 32#define PLL_GO 0x00000008
@@ -100,7 +101,7 @@ static int omap_usb3_suspend(struct usb_phy *x, int suspend)
100 udelay(1); 101 udelay(1);
101 } while (--timeout); 102 } while (--timeout);
102 103
103 omap_control_usb3_phy_power(phy->control_dev, 0); 104 omap_control_usb_phy_power(phy->control_dev, 0);
104 105
105 phy->is_suspended = 1; 106 phy->is_suspended = 1;
106 } else if (!suspend && phy->is_suspended) { 107 } else if (!suspend && phy->is_suspended) {
@@ -189,15 +190,21 @@ static int omap_usb3_init(struct usb_phy *x)
189 if (ret) 190 if (ret)
190 return ret; 191 return ret;
191 192
192 omap_control_usb3_phy_power(phy->control_dev, 1); 193 omap_control_usb_phy_power(phy->control_dev, 1);
193 194
194 return 0; 195 return 0;
195} 196}
196 197
197static int omap_usb3_probe(struct platform_device *pdev) 198static int omap_usb3_probe(struct platform_device *pdev)
198{ 199{
199 struct omap_usb *phy; 200 struct omap_usb *phy;
200 struct resource *res; 201 struct resource *res;
202 struct device_node *node = pdev->dev.of_node;
203 struct device_node *control_node;
204 struct platform_device *control_pdev;
205
206 if (!node)
207 return -EINVAL;
201 208
202 phy = devm_kzalloc(&pdev->dev, sizeof(*phy), GFP_KERNEL); 209 phy = devm_kzalloc(&pdev->dev, sizeof(*phy), GFP_KERNEL);
203 if (!phy) { 210 if (!phy) {
@@ -239,13 +246,20 @@ static int omap_usb3_probe(struct platform_device *pdev)
239 return -EINVAL; 246 return -EINVAL;
240 } 247 }
241 248
242 phy->control_dev = omap_get_control_dev(); 249 control_node = of_parse_phandle(node, "ctrl-module", 0);
243 if (IS_ERR(phy->control_dev)) { 250 if (!control_node) {
244 dev_dbg(&pdev->dev, "Failed to get control device\n"); 251 dev_err(&pdev->dev, "Failed to get control device phandle\n");
245 return -ENODEV; 252 return -EINVAL;
246 } 253 }
254 control_pdev = of_find_device_by_node(control_node);
255 if (!control_pdev) {
256 dev_err(&pdev->dev, "Failed to get control device\n");
257 return -EINVAL;
258 }
259
260 phy->control_dev = &control_pdev->dev;
247 261
248 omap_control_usb3_phy_power(phy->control_dev, 0); 262 omap_control_usb_phy_power(phy->control_dev, 0);
249 usb_add_phy_dev(&phy->phy); 263 usb_add_phy_dev(&phy->phy);
250 264
251 platform_set_drvdata(pdev, phy); 265 platform_set_drvdata(pdev, phy);
diff --git a/drivers/usb/phy/phy-rcar-gen2-usb.c b/drivers/usb/phy/phy-rcar-gen2-usb.c
new file mode 100644
index 000000000000..a99a6953f11c
--- /dev/null
+++ b/drivers/usb/phy/phy-rcar-gen2-usb.c
@@ -0,0 +1,248 @@
1/*
2 * Renesas R-Car Gen2 USB phy driver
3 *
4 * Copyright (C) 2013 Renesas Solutions Corp.
5 * Copyright (C) 2013 Cogent Embedded, Inc.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#include <linux/clk.h>
13#include <linux/delay.h>
14#include <linux/io.h>
15#include <linux/module.h>
16#include <linux/platform_data/usb-rcar-gen2-phy.h>
17#include <linux/platform_device.h>
18#include <linux/spinlock.h>
19#include <linux/usb/otg.h>
20
21struct rcar_gen2_usb_phy_priv {
22 struct usb_phy phy;
23 void __iomem *base;
24 struct clk *clk;
25 spinlock_t lock;
26 int usecount;
27 u32 ugctrl2;
28};
29
30#define usb_phy_to_priv(p) container_of(p, struct rcar_gen2_usb_phy_priv, phy)
31
32/* Low Power Status register */
33#define USBHS_LPSTS_REG 0x02
34#define USBHS_LPSTS_SUSPM (1 << 14)
35
36/* USB General control register */
37#define USBHS_UGCTRL_REG 0x80
38#define USBHS_UGCTRL_CONNECT (1 << 2)
39#define USBHS_UGCTRL_PLLRESET (1 << 0)
40
41/* USB General control register 2 */
42#define USBHS_UGCTRL2_REG 0x84
43#define USBHS_UGCTRL2_USB0_PCI (1 << 4)
44#define USBHS_UGCTRL2_USB0_HS (3 << 4)
45#define USBHS_UGCTRL2_USB2_PCI (0 << 31)
46#define USBHS_UGCTRL2_USB2_SS (1 << 31)
47
48/* USB General status register */
49#define USBHS_UGSTS_REG 0x88
50#define USBHS_UGSTS_LOCK (3 << 8)
51
52/* Enable USBHS internal phy */
53static int __rcar_gen2_usbhs_phy_enable(void __iomem *base)
54{
55 u32 val;
56 int i;
57
58 /* USBHS PHY power on */
59 val = ioread32(base + USBHS_UGCTRL_REG);
60 val &= ~USBHS_UGCTRL_PLLRESET;
61 iowrite32(val, base + USBHS_UGCTRL_REG);
62
63 val = ioread16(base + USBHS_LPSTS_REG);
64 val |= USBHS_LPSTS_SUSPM;
65 iowrite16(val, base + USBHS_LPSTS_REG);
66
67 for (i = 0; i < 20; i++) {
68 val = ioread32(base + USBHS_UGSTS_REG);
69 if ((val & USBHS_UGSTS_LOCK) == USBHS_UGSTS_LOCK) {
70 val = ioread32(base + USBHS_UGCTRL_REG);
71 val |= USBHS_UGCTRL_CONNECT;
72 iowrite32(val, base + USBHS_UGCTRL_REG);
73 return 0;
74 }
75 udelay(1);
76 }
77
78 /* Timed out waiting for the PLL lock */
79 return -ETIMEDOUT;
80}
81
82/* Disable USBHS internal phy */
83static int __rcar_gen2_usbhs_phy_disable(void __iomem *base)
84{
85 u32 val;
86
87 /* USBHS PHY power off */
88 val = ioread32(base + USBHS_UGCTRL_REG);
89 val &= ~USBHS_UGCTRL_CONNECT;
90 iowrite32(val, base + USBHS_UGCTRL_REG);
91
92 val = ioread16(base + USBHS_LPSTS_REG);
93 val &= ~USBHS_LPSTS_SUSPM;
94 iowrite16(val, base + USBHS_LPSTS_REG);
95
96 val = ioread32(base + USBHS_UGCTRL_REG);
97 val |= USBHS_UGCTRL_PLLRESET;
98 iowrite32(val, base + USBHS_UGCTRL_REG);
99 return 0;
100}
101
102/* Setup USB channels */
103static void __rcar_gen2_usb_phy_init(struct rcar_gen2_usb_phy_priv *priv)
104{
105 u32 val;
106
107 clk_prepare_enable(priv->clk);
108
109 /* Set USB channels in the USBHS UGCTRL2 register */
110 val = ioread32(priv->base);
111 val &= ~(USBHS_UGCTRL2_USB0_HS | USBHS_UGCTRL2_USB2_SS);
112 val |= priv->ugctrl2;
113 iowrite32(val, priv->base);
114}
115
116/* Shutdown USB channels */
117static void __rcar_gen2_usb_phy_shutdown(struct rcar_gen2_usb_phy_priv *priv)
118{
119 __rcar_gen2_usbhs_phy_disable(priv->base);
120 clk_disable_unprepare(priv->clk);
121}
122
123static int rcar_gen2_usb_phy_set_suspend(struct usb_phy *phy, int suspend)
124{
125 struct rcar_gen2_usb_phy_priv *priv = usb_phy_to_priv(phy);
126 unsigned long flags;
127 int retval;
128
129 spin_lock_irqsave(&priv->lock, flags);
130 retval = suspend ? __rcar_gen2_usbhs_phy_disable(priv->base) :
131 __rcar_gen2_usbhs_phy_enable(priv->base);
132 spin_unlock_irqrestore(&priv->lock, flags);
133 return retval;
134}
135
136static int rcar_gen2_usb_phy_init(struct usb_phy *phy)
137{
138 struct rcar_gen2_usb_phy_priv *priv = usb_phy_to_priv(phy);
139 unsigned long flags;
140
141 spin_lock_irqsave(&priv->lock, flags);
142 /*
143 * Enable the clock and setup USB channels
144 * if it's the first user
145 */
146 if (!priv->usecount++)
147 __rcar_gen2_usb_phy_init(priv);
148 spin_unlock_irqrestore(&priv->lock, flags);
149 return 0;
150}
151
152static void rcar_gen2_usb_phy_shutdown(struct usb_phy *phy)
153{
154 struct rcar_gen2_usb_phy_priv *priv = usb_phy_to_priv(phy);
155 unsigned long flags;
156
157 spin_lock_irqsave(&priv->lock, flags);
158 if (!priv->usecount) {
159 dev_warn(phy->dev, "Trying to disable phy with 0 usecount\n");
160 goto out;
161 }
162
163 /* Disable everything if it's the last user */
164 if (!--priv->usecount)
165 __rcar_gen2_usb_phy_shutdown(priv);
166out:
167 spin_unlock_irqrestore(&priv->lock, flags);
168}
169
170static int rcar_gen2_usb_phy_probe(struct platform_device *pdev)
171{
172 struct device *dev = &pdev->dev;
173 struct rcar_gen2_phy_platform_data *pdata;
174 struct rcar_gen2_usb_phy_priv *priv;
175 struct resource *res;
176 void __iomem *base;
177 struct clk *clk;
178 int retval;
179
180 pdata = dev_get_platdata(&pdev->dev);
181 if (!pdata) {
182 dev_err(dev, "No platform data\n");
183 return -EINVAL;
184 }
185
186 clk = devm_clk_get(&pdev->dev, "usbhs");
187 if (IS_ERR(clk)) {
188 dev_err(&pdev->dev, "Can't get the clock\n");
189 return PTR_ERR(clk);
190 }
191
192 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
193 base = devm_ioremap_resource(dev, res);
194 if (IS_ERR(base))
195 return PTR_ERR(base);
196
197 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
198 if (!priv) {
199 dev_err(dev, "Memory allocation failed\n");
200 return -ENOMEM;
201 }
202
203 spin_lock_init(&priv->lock);
204 priv->clk = clk;
205 priv->base = base;
206 priv->ugctrl2 = pdata->chan0_pci ?
207 USBHS_UGCTRL2_USB0_PCI : USBHS_UGCTRL2_USB0_HS;
208 priv->ugctrl2 |= pdata->chan2_pci ?
209 USBHS_UGCTRL2_USB2_PCI : USBHS_UGCTRL2_USB2_SS;
210 priv->phy.dev = dev;
211 priv->phy.label = dev_name(dev);
212 priv->phy.init = rcar_gen2_usb_phy_init;
213 priv->phy.shutdown = rcar_gen2_usb_phy_shutdown;
214 priv->phy.set_suspend = rcar_gen2_usb_phy_set_suspend;
215
216 retval = usb_add_phy(&priv->phy, USB_PHY_TYPE_USB2);
217 if (retval < 0) {
218 dev_err(dev, "Failed to add USB phy\n");
219 return retval;
220 }
221
222 platform_set_drvdata(pdev, priv);
223
224 return retval;
225}
226
227static int rcar_gen2_usb_phy_remove(struct platform_device *pdev)
228{
229 struct rcar_gen2_usb_phy_priv *priv = platform_get_drvdata(pdev);
230
231 usb_remove_phy(&priv->phy);
232
233 return 0;
234}
235
236static struct platform_driver rcar_gen2_usb_phy_driver = {
237 .driver = {
238 .name = "usb_phy_rcar_gen2",
239 },
240 .probe = rcar_gen2_usb_phy_probe,
241 .remove = rcar_gen2_usb_phy_remove,
242};
243
244module_platform_driver(rcar_gen2_usb_phy_driver);
245
246MODULE_LICENSE("GPL v2");
247MODULE_DESCRIPTION("Renesas R-Car Gen2 USB phy");
248MODULE_AUTHOR("Valentine Barshak <valentine.barshak@cogentembedded.com>");
diff --git a/drivers/usb/phy/phy-samsung-usb2.c b/drivers/usb/phy/phy-samsung-usb2.c
index ff70e4b19b97..b3ba86627b72 100644
--- a/drivers/usb/phy/phy-samsung-usb2.c
+++ b/drivers/usb/phy/phy-samsung-usb2.c
@@ -411,6 +411,7 @@ static int samsung_usb2phy_probe(struct platform_device *pdev)
411 sphy->drv_data = drv_data; 411 sphy->drv_data = drv_data;
412 sphy->phy.dev = sphy->dev; 412 sphy->phy.dev = sphy->dev;
413 sphy->phy.label = "samsung-usb2phy"; 413 sphy->phy.label = "samsung-usb2phy";
414 sphy->phy.type = USB_PHY_TYPE_USB2;
414 sphy->phy.init = samsung_usb2phy_init; 415 sphy->phy.init = samsung_usb2phy_init;
415 sphy->phy.shutdown = samsung_usb2phy_shutdown; 416 sphy->phy.shutdown = samsung_usb2phy_shutdown;
416 417
@@ -426,7 +427,7 @@ static int samsung_usb2phy_probe(struct platform_device *pdev)
426 427
427 platform_set_drvdata(pdev, sphy); 428 platform_set_drvdata(pdev, sphy);
428 429
429 return usb_add_phy(&sphy->phy, USB_PHY_TYPE_USB2); 430 return usb_add_phy_dev(&sphy->phy);
430} 431}
431 432
432static int samsung_usb2phy_remove(struct platform_device *pdev) 433static int samsung_usb2phy_remove(struct platform_device *pdev)
diff --git a/drivers/usb/phy/phy-samsung-usb3.c b/drivers/usb/phy/phy-samsung-usb3.c
index c6eb22213de6..cc0819248acf 100644
--- a/drivers/usb/phy/phy-samsung-usb3.c
+++ b/drivers/usb/phy/phy-samsung-usb3.c
@@ -271,6 +271,7 @@ static int samsung_usb3phy_probe(struct platform_device *pdev)
271 sphy->clk = clk; 271 sphy->clk = clk;
272 sphy->phy.dev = sphy->dev; 272 sphy->phy.dev = sphy->dev;
273 sphy->phy.label = "samsung-usb3phy"; 273 sphy->phy.label = "samsung-usb3phy";
274 sphy->phy.type = USB_PHY_TYPE_USB3;
274 sphy->phy.init = samsung_usb3phy_init; 275 sphy->phy.init = samsung_usb3phy_init;
275 sphy->phy.shutdown = samsung_usb3phy_shutdown; 276 sphy->phy.shutdown = samsung_usb3phy_shutdown;
276 sphy->drv_data = samsung_usbphy_get_driver_data(pdev); 277 sphy->drv_data = samsung_usbphy_get_driver_data(pdev);
@@ -283,7 +284,7 @@ static int samsung_usb3phy_probe(struct platform_device *pdev)
283 284
284 platform_set_drvdata(pdev, sphy); 285 platform_set_drvdata(pdev, sphy);
285 286
286 return usb_add_phy(&sphy->phy, USB_PHY_TYPE_USB3); 287 return usb_add_phy_dev(&sphy->phy);
287} 288}
288 289
289static int samsung_usb3phy_remove(struct platform_device *pdev) 290static int samsung_usb3phy_remove(struct platform_device *pdev)
diff --git a/drivers/usb/phy/phy-tegra-usb.c b/drivers/usb/phy/phy-tegra-usb.c
index e9cb1cb8abc7..82232acf1ab6 100644
--- a/drivers/usb/phy/phy-tegra-usb.c
+++ b/drivers/usb/phy/phy-tegra-usb.c
@@ -1090,7 +1090,7 @@ static struct platform_driver tegra_usb_phy_driver = {
1090 .driver = { 1090 .driver = {
1091 .name = "tegra-phy", 1091 .name = "tegra-phy",
1092 .owner = THIS_MODULE, 1092 .owner = THIS_MODULE,
1093 .of_match_table = of_match_ptr(tegra_usb_phy_id_table), 1093 .of_match_table = tegra_usb_phy_id_table,
1094 }, 1094 },
1095}; 1095};
1096module_platform_driver(tegra_usb_phy_driver); 1096module_platform_driver(tegra_usb_phy_driver);
diff --git a/drivers/usb/phy/phy-twl6030-usb.c b/drivers/usb/phy/phy-twl6030-usb.c
index 16dbc9382678..30e8a61552d4 100644
--- a/drivers/usb/phy/phy-twl6030-usb.c
+++ b/drivers/usb/phy/phy-twl6030-usb.c
@@ -33,6 +33,7 @@
33#include <linux/err.h> 33#include <linux/err.h>
34#include <linux/slab.h> 34#include <linux/slab.h>
35#include <linux/delay.h> 35#include <linux/delay.h>
36#include <linux/of.h>
36 37
37/* usb register definitions */ 38/* usb register definitions */
38#define USB_VENDOR_ID_LSB 0x00 39#define USB_VENDOR_ID_LSB 0x00
diff --git a/drivers/usb/phy/phy-ulpi-viewport.c b/drivers/usb/phy/phy-ulpi-viewport.c
index 7c22a5390fc3..18bb8264b5a0 100644
--- a/drivers/usb/phy/phy-ulpi-viewport.c
+++ b/drivers/usb/phy/phy-ulpi-viewport.c
@@ -36,7 +36,7 @@ static int ulpi_viewport_wait(void __iomem *view, u32 mask)
36 return 0; 36 return 0;
37 37
38 udelay(1); 38 udelay(1);
39 }; 39 }
40 40
41 return -ETIMEDOUT; 41 return -ETIMEDOUT;
42} 42}
diff --git a/drivers/usb/phy/phy.c b/drivers/usb/phy/phy.c
index a9984c700d2c..1b74523e1fee 100644
--- a/drivers/usb/phy/phy.c
+++ b/drivers/usb/phy/phy.c
@@ -98,7 +98,7 @@ struct usb_phy *devm_usb_get_phy(struct device *dev, enum usb_phy_type type)
98 98
99 ptr = devres_alloc(devm_usb_phy_release, sizeof(*ptr), GFP_KERNEL); 99 ptr = devres_alloc(devm_usb_phy_release, sizeof(*ptr), GFP_KERNEL);
100 if (!ptr) 100 if (!ptr)
101 return NULL; 101 return ERR_PTR(-ENOMEM);
102 102
103 phy = usb_get_phy(type); 103 phy = usb_get_phy(type);
104 if (!IS_ERR(phy)) { 104 if (!IS_ERR(phy)) {
diff --git a/drivers/usb/serial/cyberjack.c b/drivers/usb/serial/cyberjack.c
index 781426230d69..6e1b69d0f5f5 100644
--- a/drivers/usb/serial/cyberjack.c
+++ b/drivers/usb/serial/cyberjack.c
@@ -279,7 +279,7 @@ static void cyberjack_read_int_callback(struct urb *urb)
279 279
280 old_rdtodo = priv->rdtodo; 280 old_rdtodo = priv->rdtodo;
281 281
282 if (old_rdtodo + size < old_rdtodo) { 282 if (old_rdtodo > SHRT_MAX - size) {
283 dev_dbg(dev, "To many bulk_in urbs to do.\n"); 283 dev_dbg(dev, "To many bulk_in urbs to do.\n");
284 spin_unlock(&priv->lock); 284 spin_unlock(&priv->lock);
285 goto resubmit; 285 goto resubmit;
diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index c45f9c0a1b34..9ced8937a8f3 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -904,6 +904,7 @@ static struct usb_device_id id_table_combined [] = {
904 { USB_DEVICE(FTDI_VID, FTDI_LUMEL_PD12_PID) }, 904 { USB_DEVICE(FTDI_VID, FTDI_LUMEL_PD12_PID) },
905 /* Crucible Devices */ 905 /* Crucible Devices */
906 { USB_DEVICE(FTDI_VID, FTDI_CT_COMET_PID) }, 906 { USB_DEVICE(FTDI_VID, FTDI_CT_COMET_PID) },
907 { USB_DEVICE(FTDI_VID, FTDI_Z3X_PID) },
907 { } /* Terminating entry */ 908 { } /* Terminating entry */
908}; 909};
909 910
@@ -1966,8 +1967,16 @@ static int ftdi_process_packet(struct usb_serial_port *port,
1966 port->icount.dsr++; 1967 port->icount.dsr++;
1967 if (diff_status & FTDI_RS0_RI) 1968 if (diff_status & FTDI_RS0_RI)
1968 port->icount.rng++; 1969 port->icount.rng++;
1969 if (diff_status & FTDI_RS0_RLSD) 1970 if (diff_status & FTDI_RS0_RLSD) {
1971 struct tty_struct *tty;
1972
1970 port->icount.dcd++; 1973 port->icount.dcd++;
1974 tty = tty_port_tty_get(&port->port);
1975 if (tty)
1976 usb_serial_handle_dcd_change(port, tty,
1977 status & FTDI_RS0_RLSD);
1978 tty_kref_put(tty);
1979 }
1971 1980
1972 wake_up_interruptible(&port->port.delta_msr_wait); 1981 wake_up_interruptible(&port->port.delta_msr_wait);
1973 priv->prev_status = status; 1982 priv->prev_status = status;
diff --git a/drivers/usb/serial/ftdi_sio_ids.h b/drivers/usb/serial/ftdi_sio_ids.h
index 1b8af461b522..a7019d1e3058 100644
--- a/drivers/usb/serial/ftdi_sio_ids.h
+++ b/drivers/usb/serial/ftdi_sio_ids.h
@@ -1307,3 +1307,9 @@
1307 * Manufacturer: Crucible Technologies 1307 * Manufacturer: Crucible Technologies
1308 */ 1308 */
1309#define FTDI_CT_COMET_PID 0x8e08 1309#define FTDI_CT_COMET_PID 0x8e08
1310
1311/*
1312 * Product: Z3X Box
1313 * Manufacturer: Smart GSM Team
1314 */
1315#define FTDI_Z3X_PID 0x0011
diff --git a/drivers/usb/serial/generic.c b/drivers/usb/serial/generic.c
index 1f31e6b4c251..2b01ec8651c2 100644
--- a/drivers/usb/serial/generic.c
+++ b/drivers/usb/serial/generic.c
@@ -7,7 +7,6 @@
7 * This program is free software; you can redistribute it and/or 7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License version 8 * modify it under the terms of the GNU General Public License version
9 * 2 as published by the Free Software Foundation. 9 * 2 as published by the Free Software Foundation.
10 *
11 */ 10 */
12 11
13#include <linux/kernel.h> 12#include <linux/kernel.h>
@@ -37,7 +36,6 @@ MODULE_PARM_DESC(product, "User specified USB idProduct");
37 36
38static struct usb_device_id generic_device_ids[2]; /* Initially all zeroes. */ 37static struct usb_device_id generic_device_ids[2]; /* Initially all zeroes. */
39 38
40/* All of the device info needed for the Generic Serial Converter */
41struct usb_serial_driver usb_serial_generic_device = { 39struct usb_serial_driver usb_serial_generic_device = {
42 .driver = { 40 .driver = {
43 .owner = THIS_MODULE, 41 .owner = THIS_MODULE,
@@ -66,7 +64,6 @@ int usb_serial_generic_register(void)
66 generic_device_ids[0].match_flags = 64 generic_device_ids[0].match_flags =
67 USB_DEVICE_ID_MATCH_VENDOR | USB_DEVICE_ID_MATCH_PRODUCT; 65 USB_DEVICE_ID_MATCH_VENDOR | USB_DEVICE_ID_MATCH_PRODUCT;
68 66
69 /* register our generic driver with ourselves */
70 retval = usb_serial_register_drivers(serial_drivers, 67 retval = usb_serial_register_drivers(serial_drivers,
71 "usbserial_generic", generic_device_ids); 68 "usbserial_generic", generic_device_ids);
72#endif 69#endif
@@ -76,7 +73,6 @@ int usb_serial_generic_register(void)
76void usb_serial_generic_deregister(void) 73void usb_serial_generic_deregister(void)
77{ 74{
78#ifdef CONFIG_USB_SERIAL_GENERIC 75#ifdef CONFIG_USB_SERIAL_GENERIC
79 /* remove our generic driver */
80 usb_serial_deregister_drivers(serial_drivers); 76 usb_serial_deregister_drivers(serial_drivers);
81#endif 77#endif
82} 78}
@@ -86,13 +82,11 @@ int usb_serial_generic_open(struct tty_struct *tty, struct usb_serial_port *port
86 int result = 0; 82 int result = 0;
87 unsigned long flags; 83 unsigned long flags;
88 84
89 /* clear the throttle flags */
90 spin_lock_irqsave(&port->lock, flags); 85 spin_lock_irqsave(&port->lock, flags);
91 port->throttled = 0; 86 port->throttled = 0;
92 port->throttle_req = 0; 87 port->throttle_req = 0;
93 spin_unlock_irqrestore(&port->lock, flags); 88 spin_unlock_irqrestore(&port->lock, flags);
94 89
95 /* if we have a bulk endpoint, start reading from it */
96 if (port->bulk_in_size) 90 if (port->bulk_in_size)
97 result = usb_serial_generic_submit_read_urbs(port, GFP_KERNEL); 91 result = usb_serial_generic_submit_read_urbs(port, GFP_KERNEL);
98 92
@@ -127,12 +121,16 @@ int usb_serial_generic_prepare_write_buffer(struct usb_serial_port *port,
127} 121}
128 122
129/** 123/**
130 * usb_serial_generic_write_start - kick off an URB write 124 * usb_serial_generic_write_start - start writing buffered data
131 * @port: Pointer to the &struct usb_serial_port data 125 * @port: usb-serial port
126 * @mem_flags: flags to use for memory allocations
127 *
128 * Serialised using USB_SERIAL_WRITE_BUSY flag.
132 * 129 *
133 * Returns zero on success, or a negative errno value 130 * Return: Zero on success or if busy, otherwise a negative errno value.
134 */ 131 */
135static int usb_serial_generic_write_start(struct usb_serial_port *port) 132int usb_serial_generic_write_start(struct usb_serial_port *port,
133 gfp_t mem_flags)
136{ 134{
137 struct urb *urb; 135 struct urb *urb;
138 int count, result; 136 int count, result;
@@ -163,7 +161,7 @@ retry:
163 spin_unlock_irqrestore(&port->lock, flags); 161 spin_unlock_irqrestore(&port->lock, flags);
164 162
165 clear_bit(i, &port->write_urbs_free); 163 clear_bit(i, &port->write_urbs_free);
166 result = usb_submit_urb(urb, GFP_ATOMIC); 164 result = usb_submit_urb(urb, mem_flags);
167 if (result) { 165 if (result) {
168 dev_err_console(port, "%s - error submitting urb: %d\n", 166 dev_err_console(port, "%s - error submitting urb: %d\n",
169 __func__, result); 167 __func__, result);
@@ -175,34 +173,34 @@ retry:
175 clear_bit_unlock(USB_SERIAL_WRITE_BUSY, &port->flags); 173 clear_bit_unlock(USB_SERIAL_WRITE_BUSY, &port->flags);
176 return result; 174 return result;
177 } 175 }
178 176 /*
179 /* Try sending off another urb, unless in irq context (in which case 177 * Try sending off another urb, unless called from completion handler
180 * there will be no free urb). */ 178 * (in which case there will be no free urb or no data).
181 if (!in_irq()) 179 */
180 if (mem_flags != GFP_ATOMIC)
182 goto retry; 181 goto retry;
183 182
184 clear_bit_unlock(USB_SERIAL_WRITE_BUSY, &port->flags); 183 clear_bit_unlock(USB_SERIAL_WRITE_BUSY, &port->flags);
185 184
186 return 0; 185 return 0;
187} 186}
187EXPORT_SYMBOL_GPL(usb_serial_generic_write_start);
188 188
189/** 189/**
190 * usb_serial_generic_write - generic write function for serial USB devices 190 * usb_serial_generic_write - generic write function
191 * @tty: Pointer to &struct tty_struct for the device 191 * @tty: tty for the port
192 * @port: Pointer to the &usb_serial_port structure for the device 192 * @port: usb-serial port
193 * @buf: Pointer to the data to write 193 * @buf: data to write
194 * @count: Number of bytes to write 194 * @count: number of bytes to write
195 * 195 *
196 * Returns the number of characters actually written, which may be anything 196 * Return: The number of characters buffered, which may be anything from
197 * from zero to @count. If an error occurs, it returns the negative errno 197 * zero to @count, or a negative errno value.
198 * value.
199 */ 198 */
200int usb_serial_generic_write(struct tty_struct *tty, 199int usb_serial_generic_write(struct tty_struct *tty,
201 struct usb_serial_port *port, const unsigned char *buf, int count) 200 struct usb_serial_port *port, const unsigned char *buf, int count)
202{ 201{
203 int result; 202 int result;
204 203
205 /* only do something if we have a bulk out endpoint */
206 if (!port->bulk_out_size) 204 if (!port->bulk_out_size)
207 return -ENODEV; 205 return -ENODEV;
208 206
@@ -210,7 +208,7 @@ int usb_serial_generic_write(struct tty_struct *tty,
210 return 0; 208 return 0;
211 209
212 count = kfifo_in_locked(&port->write_fifo, buf, count, &port->lock); 210 count = kfifo_in_locked(&port->write_fifo, buf, count, &port->lock);
213 result = usb_serial_generic_write_start(port); 211 result = usb_serial_generic_write_start(port, GFP_KERNEL);
214 if (result) 212 if (result)
215 return result; 213 return result;
216 214
@@ -337,10 +335,11 @@ void usb_serial_generic_process_read_urb(struct urb *urb)
337 335
338 if (!urb->actual_length) 336 if (!urb->actual_length)
339 return; 337 return;
340 338 /*
341 /* The per character mucking around with sysrq path it too slow for 339 * The per character mucking around with sysrq path it too slow for
342 stuff like 3G modems, so shortcircuit it in the 99.9999999% of cases 340 * stuff like 3G modems, so shortcircuit it in the 99.9999999% of
343 where the USB serial is not a console anyway */ 341 * cases where the USB serial is not a console anyway.
342 */
344 if (!port->port.console || !port->sysrq) 343 if (!port->port.console || !port->sysrq)
345 tty_insert_flip_string(&port->port, ch, urb->actual_length); 344 tty_insert_flip_string(&port->port, ch, urb->actual_length);
346 else { 345 else {
@@ -413,7 +412,7 @@ void usb_serial_generic_write_bulk_callback(struct urb *urb)
413 kfifo_reset_out(&port->write_fifo); 412 kfifo_reset_out(&port->write_fifo);
414 spin_unlock_irqrestore(&port->lock, flags); 413 spin_unlock_irqrestore(&port->lock, flags);
415 } else { 414 } else {
416 usb_serial_generic_write_start(port); 415 usb_serial_generic_write_start(port, GFP_ATOMIC);
417 } 416 }
418 417
419 usb_serial_port_softint(port); 418 usb_serial_port_softint(port);
@@ -425,8 +424,6 @@ void usb_serial_generic_throttle(struct tty_struct *tty)
425 struct usb_serial_port *port = tty->driver_data; 424 struct usb_serial_port *port = tty->driver_data;
426 unsigned long flags; 425 unsigned long flags;
427 426
428 /* Set the throttle request flag. It will be picked up
429 * by usb_serial_generic_read_bulk_callback(). */
430 spin_lock_irqsave(&port->lock, flags); 427 spin_lock_irqsave(&port->lock, flags);
431 port->throttle_req = 1; 428 port->throttle_req = 1;
432 spin_unlock_irqrestore(&port->lock, flags); 429 spin_unlock_irqrestore(&port->lock, flags);
@@ -438,7 +435,6 @@ void usb_serial_generic_unthrottle(struct tty_struct *tty)
438 struct usb_serial_port *port = tty->driver_data; 435 struct usb_serial_port *port = tty->driver_data;
439 int was_throttled; 436 int was_throttled;
440 437
441 /* Clear the throttle flags */
442 spin_lock_irq(&port->lock); 438 spin_lock_irq(&port->lock);
443 was_throttled = port->throttled; 439 was_throttled = port->throttled;
444 port->throttled = port->throttle_req = 0; 440 port->throttled = port->throttle_req = 0;
@@ -558,10 +554,10 @@ int usb_serial_handle_break(struct usb_serial_port *port)
558EXPORT_SYMBOL_GPL(usb_serial_handle_break); 554EXPORT_SYMBOL_GPL(usb_serial_handle_break);
559 555
560/** 556/**
561 * usb_serial_handle_dcd_change - handle a change of carrier detect state 557 * usb_serial_handle_dcd_change - handle a change of carrier detect state
562 * @port: usb_serial_port structure for the open port 558 * @port: usb-serial port
563 * @tty: tty_struct structure for the port 559 * @tty: tty for the port
564 * @status: new carrier detect status, nonzero if active 560 * @status: new carrier detect status, nonzero if active
565 */ 561 */
566void usb_serial_handle_dcd_change(struct usb_serial_port *usb_port, 562void usb_serial_handle_dcd_change(struct usb_serial_port *usb_port,
567 struct tty_struct *tty, unsigned int status) 563 struct tty_struct *tty, unsigned int status)
@@ -570,6 +566,16 @@ void usb_serial_handle_dcd_change(struct usb_serial_port *usb_port,
570 566
571 dev_dbg(&usb_port->dev, "%s - status %d\n", __func__, status); 567 dev_dbg(&usb_port->dev, "%s - status %d\n", __func__, status);
572 568
569 if (tty) {
570 struct tty_ldisc *ld = tty_ldisc_ref(tty);
571
572 if (ld) {
573 if (ld->ops->dcd_change)
574 ld->ops->dcd_change(tty, status);
575 tty_ldisc_deref(ld);
576 }
577 }
578
573 if (status) 579 if (status)
574 wake_up_interruptible(&port->open_wait); 580 wake_up_interruptible(&port->open_wait);
575 else if (tty && !C_CLOCAL(tty)) 581 else if (tty && !C_CLOCAL(tty))
@@ -595,7 +601,7 @@ int usb_serial_generic_resume(struct usb_serial *serial)
595 } 601 }
596 602
597 if (port->bulk_out_size) { 603 if (port->bulk_out_size) {
598 r = usb_serial_generic_write_start(port); 604 r = usb_serial_generic_write_start(port, GFP_NOIO);
599 if (r < 0) 605 if (r < 0)
600 c++; 606 c++;
601 } 607 }
diff --git a/drivers/usb/serial/mos7840.c b/drivers/usb/serial/mos7840.c
index fdf953539c62..e5bdd987b9e8 100644
--- a/drivers/usb/serial/mos7840.c
+++ b/drivers/usb/serial/mos7840.c
@@ -1532,7 +1532,11 @@ static int mos7840_tiocmget(struct tty_struct *tty)
1532 return -ENODEV; 1532 return -ENODEV;
1533 1533
1534 status = mos7840_get_uart_reg(port, MODEM_STATUS_REGISTER, &msr); 1534 status = mos7840_get_uart_reg(port, MODEM_STATUS_REGISTER, &msr);
1535 if (status != 1)
1536 return -EIO;
1535 status = mos7840_get_uart_reg(port, MODEM_CONTROL_REGISTER, &mcr); 1537 status = mos7840_get_uart_reg(port, MODEM_CONTROL_REGISTER, &mcr);
1538 if (status != 1)
1539 return -EIO;
1536 result = ((mcr & MCR_DTR) ? TIOCM_DTR : 0) 1540 result = ((mcr & MCR_DTR) ? TIOCM_DTR : 0)
1537 | ((mcr & MCR_RTS) ? TIOCM_RTS : 0) 1541 | ((mcr & MCR_RTS) ? TIOCM_RTS : 0)
1538 | ((mcr & MCR_LOOPBACK) ? TIOCM_LOOP : 0) 1542 | ((mcr & MCR_LOOPBACK) ? TIOCM_LOOP : 0)
diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c
index acaee066b99a..c3d94853b4ab 100644
--- a/drivers/usb/serial/option.c
+++ b/drivers/usb/serial/option.c
@@ -1376,6 +1376,23 @@ static const struct usb_device_id option_ids[] = {
1376 .driver_info = (kernel_ulong_t)&net_intf2_blacklist }, 1376 .driver_info = (kernel_ulong_t)&net_intf2_blacklist },
1377 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1426, 0xff, 0xff, 0xff), /* ZTE MF91 */ 1377 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1426, 0xff, 0xff, 0xff), /* ZTE MF91 */
1378 .driver_info = (kernel_ulong_t)&net_intf2_blacklist }, 1378 .driver_info = (kernel_ulong_t)&net_intf2_blacklist },
1379 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1533, 0xff, 0xff, 0xff) },
1380 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1534, 0xff, 0xff, 0xff) },
1381 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1535, 0xff, 0xff, 0xff) },
1382 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1545, 0xff, 0xff, 0xff) },
1383 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1546, 0xff, 0xff, 0xff) },
1384 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1547, 0xff, 0xff, 0xff) },
1385 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1565, 0xff, 0xff, 0xff) },
1386 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1566, 0xff, 0xff, 0xff) },
1387 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1567, 0xff, 0xff, 0xff) },
1388 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1589, 0xff, 0xff, 0xff) },
1389 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1590, 0xff, 0xff, 0xff) },
1390 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1591, 0xff, 0xff, 0xff) },
1391 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1592, 0xff, 0xff, 0xff) },
1392 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1594, 0xff, 0xff, 0xff) },
1393 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1596, 0xff, 0xff, 0xff) },
1394 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1598, 0xff, 0xff, 0xff) },
1395 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1600, 0xff, 0xff, 0xff) },
1379 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x2002, 0xff, 1396 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x2002, 0xff,
1380 0xff, 0xff), .driver_info = (kernel_ulong_t)&zte_k3765_z_blacklist }, 1397 0xff, 0xff), .driver_info = (kernel_ulong_t)&zte_k3765_z_blacklist },
1381 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x2003, 0xff, 0xff, 0xff) }, 1398 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x2003, 0xff, 0xff, 0xff) },
diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c
index bedf8e47713b..1e6de4cd079d 100644
--- a/drivers/usb/serial/pl2303.c
+++ b/drivers/usb/serial/pl2303.c
@@ -4,11 +4,6 @@
4 * Copyright (C) 2001-2007 Greg Kroah-Hartman (greg@kroah.com) 4 * Copyright (C) 2001-2007 Greg Kroah-Hartman (greg@kroah.com)
5 * Copyright (C) 2003 IBM Corp. 5 * Copyright (C) 2003 IBM Corp.
6 * 6 *
7 * Copyright (C) 2009, 2013 Frank Schäfer <fschaefer.oss@googlemail.com>
8 * - fixes, improvements and documentation for the baud rate encoding methods
9 * Copyright (C) 2013 Reinhard Max <max@suse.de>
10 * - fixes and improvements for the divisor based baud rate encoding method
11 *
12 * Original driver for 2.2.x by anonymous 7 * Original driver for 2.2.x by anonymous
13 * 8 *
14 * This program is free software; you can redistribute it and/or 9 * This program is free software; you can redistribute it and/or
@@ -134,18 +129,10 @@ MODULE_DEVICE_TABLE(usb, id_table);
134 129
135 130
136enum pl2303_type { 131enum pl2303_type {
137 type_0, /* H version ? */ 132 type_0, /* don't know the difference between type 0 and */
138 type_1, /* H version ? */ 133 type_1, /* type 1, until someone from prolific tells us... */
139 HX_TA, /* HX(A) / X(A) / TA version */ /* TODO: improve */ 134 HX, /* HX version of the pl2303 chip */
140 HXD_EA_RA_SA, /* HXD / EA / RA / SA version */ /* TODO: improve */
141 TB, /* TB version */
142 HX_CLONE, /* Cheap and less functional clone of the HX chip */
143}; 135};
144/*
145 * NOTE: don't know the difference between type 0 and type 1,
146 * until someone from Prolific tells us...
147 * TODO: distinguish between X/HX, TA and HXD, EA, RA, SA variants
148 */
149 136
150struct pl2303_serial_private { 137struct pl2303_serial_private {
151 enum pl2303_type type; 138 enum pl2303_type type;
@@ -185,7 +172,6 @@ static int pl2303_startup(struct usb_serial *serial)
185{ 172{
186 struct pl2303_serial_private *spriv; 173 struct pl2303_serial_private *spriv;
187 enum pl2303_type type = type_0; 174 enum pl2303_type type = type_0;
188 char *type_str = "unknown (treating as type_0)";
189 unsigned char *buf; 175 unsigned char *buf;
190 176
191 spriv = kzalloc(sizeof(*spriv), GFP_KERNEL); 177 spriv = kzalloc(sizeof(*spriv), GFP_KERNEL);
@@ -198,53 +184,15 @@ static int pl2303_startup(struct usb_serial *serial)
198 return -ENOMEM; 184 return -ENOMEM;
199 } 185 }
200 186
201 if (serial->dev->descriptor.bDeviceClass == 0x02) { 187 if (serial->dev->descriptor.bDeviceClass == 0x02)
202 type = type_0; 188 type = type_0;
203 type_str = "type_0"; 189 else if (serial->dev->descriptor.bMaxPacketSize0 == 0x40)
204 } else if (serial->dev->descriptor.bMaxPacketSize0 == 0x40) { 190 type = HX;
205 /* 191 else if (serial->dev->descriptor.bDeviceClass == 0x00)
206 * NOTE: The bcdDevice version is the only difference between
207 * the device descriptors of the X/HX, HXD, EA, RA, SA, TA, TB
208 */
209 if (le16_to_cpu(serial->dev->descriptor.bcdDevice) == 0x300) {
210 /* Check if the device is a clone */
211 pl2303_vendor_read(0x9494, 0, serial, buf);
212 /*
213 * NOTE: Not sure if this read is really needed.
214 * The HX returns 0x00, the clone 0x02, but the Windows
215 * driver seems to ignore the value and continues.
216 */
217 pl2303_vendor_write(0x0606, 0xaa, serial);
218 pl2303_vendor_read(0x8686, 0, serial, buf);
219 if (buf[0] != 0xaa) {
220 type = HX_CLONE;
221 type_str = "X/HX clone (limited functionality)";
222 } else {
223 type = HX_TA;
224 type_str = "X/HX/TA";
225 }
226 pl2303_vendor_write(0x0606, 0x00, serial);
227 } else if (le16_to_cpu(serial->dev->descriptor.bcdDevice)
228 == 0x400) {
229 type = HXD_EA_RA_SA;
230 type_str = "HXD/EA/RA/SA";
231 } else if (le16_to_cpu(serial->dev->descriptor.bcdDevice)
232 == 0x500) {
233 type = TB;
234 type_str = "TB";
235 } else {
236 dev_info(&serial->interface->dev,
237 "unknown/unsupported device type\n");
238 kfree(spriv);
239 kfree(buf);
240 return -ENODEV;
241 }
242 } else if (serial->dev->descriptor.bDeviceClass == 0x00
243 || serial->dev->descriptor.bDeviceClass == 0xFF) {
244 type = type_1; 192 type = type_1;
245 type_str = "type_1"; 193 else if (serial->dev->descriptor.bDeviceClass == 0xFF)
246 } 194 type = type_1;
247 dev_dbg(&serial->interface->dev, "device type: %s\n", type_str); 195 dev_dbg(&serial->interface->dev, "device type: %d\n", type);
248 196
249 spriv->type = type; 197 spriv->type = type;
250 usb_set_serial_data(serial, spriv); 198 usb_set_serial_data(serial, spriv);
@@ -259,10 +207,10 @@ static int pl2303_startup(struct usb_serial *serial)
259 pl2303_vendor_read(0x8383, 0, serial, buf); 207 pl2303_vendor_read(0x8383, 0, serial, buf);
260 pl2303_vendor_write(0, 1, serial); 208 pl2303_vendor_write(0, 1, serial);
261 pl2303_vendor_write(1, 0, serial); 209 pl2303_vendor_write(1, 0, serial);
262 if (type == type_0 || type == type_1) 210 if (type == HX)
263 pl2303_vendor_write(2, 0x24, serial);
264 else
265 pl2303_vendor_write(2, 0x44, serial); 211 pl2303_vendor_write(2, 0x44, serial);
212 else
213 pl2303_vendor_write(2, 0x24, serial);
266 214
267 kfree(buf); 215 kfree(buf);
268 return 0; 216 return 0;
@@ -316,174 +264,65 @@ static int pl2303_set_control_lines(struct usb_serial_port *port, u8 value)
316 return retval; 264 return retval;
317} 265}
318 266
319static int pl2303_baudrate_encode_direct(int baud, enum pl2303_type type, 267static void pl2303_encode_baudrate(struct tty_struct *tty,
320 u8 buf[4]) 268 struct usb_serial_port *port,
269 u8 buf[4])
321{ 270{
322 /*
323 * NOTE: Only the values defined in baud_sup are supported !
324 * => if unsupported values are set, the PL2303 uses 9600 baud instead
325 * => HX clones just don't work at unsupported baud rates < 115200 baud,
326 * for baud rates > 115200 they run at 115200 baud
327 */
328 const int baud_sup[] = { 75, 150, 300, 600, 1200, 1800, 2400, 3600, 271 const int baud_sup[] = { 75, 150, 300, 600, 1200, 1800, 2400, 3600,
329 4800, 7200, 9600, 14400, 19200, 28800, 38400, 272 4800, 7200, 9600, 14400, 19200, 28800, 38400,
330 57600, 115200, 230400, 460800, 614400, 921600, 273 57600, 115200, 230400, 460800, 500000, 614400,
331 1228800, 2457600, 3000000, 6000000, 12000000 }; 274 921600, 1228800, 2457600, 3000000, 6000000 };
275
276 struct usb_serial *serial = port->serial;
277 struct pl2303_serial_private *spriv = usb_get_serial_data(serial);
278 int baud;
279 int i;
280
332 /* 281 /*
333 * NOTE: With the exception of type_0/1 devices, the following 282 * NOTE: Only the values defined in baud_sup are supported!
334 * additional baud rates are supported (tested with HX rev. 3A only): 283 * => if unsupported values are set, the PL2303 seems to use
335 * 110*, 56000*, 128000, 134400, 161280, 201600, 256000*, 268800, 284 * 9600 baud (at least my PL2303X always does)
336 * 403200, 806400. (*: not HX and HX clones)
337 *
338 * Maximum values: HXD, TB: 12000000; HX, TA: 6000000;
339 * type_0+1: 1228800; RA: 921600; HX clones, SA: 115200
340 *
341 * As long as we are not using this encoding method for anything else
342 * than the type_0+1, HX and HX clone chips, there is no point in
343 * complicating the code to support them.
344 */ 285 */
345 int i; 286 baud = tty_get_baud_rate(tty);
287 dev_dbg(&port->dev, "baud requested = %d\n", baud);
288 if (!baud)
289 return;
346 290
347 /* Set baudrate to nearest supported value */ 291 /* Set baudrate to nearest supported value */
348 for (i = 0; i < ARRAY_SIZE(baud_sup); ++i) { 292 for (i = 0; i < ARRAY_SIZE(baud_sup); ++i) {
349 if (baud_sup[i] > baud) 293 if (baud_sup[i] > baud)
350 break; 294 break;
351 } 295 }
296
352 if (i == ARRAY_SIZE(baud_sup)) 297 if (i == ARRAY_SIZE(baud_sup))
353 baud = baud_sup[i - 1]; 298 baud = baud_sup[i - 1];
354 else if (i > 0 && (baud_sup[i] - baud) > (baud - baud_sup[i - 1])) 299 else if (i > 0 && (baud_sup[i] - baud) > (baud - baud_sup[i - 1]))
355 baud = baud_sup[i - 1]; 300 baud = baud_sup[i - 1];
356 else 301 else
357 baud = baud_sup[i]; 302 baud = baud_sup[i];
358 /* Respect the chip type specific baud rate limits */
359 /*
360 * FIXME: as long as we don't know how to distinguish between the
361 * HXD, EA, RA, and SA chip variants, allow the max. value of 12M.
362 */
363 if (type == HX_TA)
364 baud = min_t(int, baud, 6000000);
365 else if (type == type_0 || type == type_1)
366 baud = min_t(int, baud, 1228800);
367 else if (type == HX_CLONE)
368 baud = min_t(int, baud, 115200);
369 /* Direct (standard) baud rate encoding method */
370 put_unaligned_le32(baud, buf);
371
372 return baud;
373}
374 303
375static int pl2303_baudrate_encode_divisor(int baud, enum pl2303_type type, 304 /* type_0, type_1 only support up to 1228800 baud */
376 u8 buf[4]) 305 if (spriv->type != HX)
377{ 306 baud = min_t(int, baud, 1228800);
378 /*
379 * Divisor based baud rate encoding method
380 *
381 * NOTE: HX clones do NOT support this method.
382 * It's not clear if the type_0/1 chips support it.
383 *
384 * divisor = 12MHz * 32 / baudrate = 2^A * B
385 *
386 * with
387 *
388 * A = buf[1] & 0x0e
389 * B = buf[0] + (buf[1] & 0x01) << 8
390 *
391 * Special cases:
392 * => 8 < B < 16: device seems to work not properly
393 * => B <= 8: device uses the max. value B = 512 instead
394 */
395 unsigned int A, B;
396 307
397 /* 308 if (baud <= 115200) {
398 * NOTE: The Windows driver allows maximum baud rates of 110% of the 309 put_unaligned_le32(baud, buf);
399 * specified maximium value.
400 * Quick tests with early (2004) HX (rev. A) chips suggest, that even
401 * higher baud rates (up to the maximum of 24M baud !) are working fine,
402 * but that should really be tested carefully in "real life" scenarios
403 * before removing the upper limit completely.
404 * Baud rates smaller than the specified 75 baud are definitely working
405 * fine.
406 */
407 if (type == type_0 || type == type_1)
408 baud = min_t(int, baud, 1228800 * 1.1);
409 else if (type == HX_TA)
410 baud = min_t(int, baud, 6000000 * 1.1);
411 else if (type == HXD_EA_RA_SA)
412 /* HXD, EA: 12Mbps; RA: 1Mbps; SA: 115200 bps */
413 /*
414 * FIXME: as long as we don't know how to distinguish between
415 * these chip variants, allow the max. of these values
416 */
417 baud = min_t(int, baud, 12000000 * 1.1);
418 else if (type == TB)
419 baud = min_t(int, baud, 12000000 * 1.1);
420 /* Determine factors A and B */
421 A = 0;
422 B = 12000000 * 32 / baud; /* 12MHz */
423 B <<= 1; /* Add one bit for rounding */
424 while (B > (512 << 1) && A <= 14) {
425 A += 2;
426 B >>= 2;
427 }
428 if (A > 14) { /* max. divisor = min. baudrate reached */
429 A = 14;
430 B = 512;
431 /* => ~45.78 baud */
432 } else { 310 } else {
433 B = (B + 1) >> 1; /* Round the last bit */
434 }
435 /* Handle special cases */
436 if (B == 512)
437 B = 0; /* also: 1 to 8 */
438 else if (B < 16)
439 /* 311 /*
440 * NOTE: With the current algorithm this happens 312 * Apparently the formula for higher speeds is:
441 * only for A=0 and means that the min. divisor 313 * baudrate = 12M * 32 / (2^buf[1]) / buf[0]
442 * (respectively: the max. baudrate) is reached.
443 */ 314 */
444 B = 16; /* => 24 MBaud */ 315 unsigned tmp = 12000000 * 32 / baud;
445 /* Encode the baud rate */ 316 buf[3] = 0x80;
446 buf[3] = 0x80; /* Select divisor encoding method */ 317 buf[2] = 0;
447 buf[2] = 0; 318 buf[1] = (tmp >= 256);
448 buf[1] = (A & 0x0e); /* A */ 319 while (tmp >= 256) {
449 buf[1] |= ((B & 0x100) >> 8); /* MSB of B */ 320 tmp >>= 2;
450 buf[0] = B & 0xff; /* 8 LSBs of B */ 321 buf[1] <<= 1;
451 /* Calculate the actual/resulting baud rate */ 322 }
452 if (B <= 8) 323 buf[0] = tmp;
453 B = 512; 324 }
454 baud = 12000000 * 32 / ((1 << A) * B);
455
456 return baud;
457}
458
459static void pl2303_encode_baudrate(struct tty_struct *tty,
460 struct usb_serial_port *port,
461 enum pl2303_type type,
462 u8 buf[4])
463{
464 int baud;
465 325
466 baud = tty_get_baud_rate(tty);
467 dev_dbg(&port->dev, "baud requested = %d\n", baud);
468 if (!baud)
469 return;
470 /*
471 * There are two methods for setting/encoding the baud rate
472 * 1) Direct method: encodes the baud rate value directly
473 * => supported by all chip types
474 * 2) Divisor based method: encodes a divisor to a base value (12MHz*32)
475 * => not supported by HX clones (and likely type_0/1 chips)
476 *
477 * NOTE: Although the divisor based baud rate encoding method is much
478 * more flexible, some of the standard baud rate values can not be
479 * realized exactly. But the difference is very small (max. 0.2%) and
480 * the device likely uses the same baud rate generator for both methods
481 * so that there is likley no difference.
482 */
483 if (type == type_0 || type == type_1 || type == HX_CLONE)
484 baud = pl2303_baudrate_encode_direct(baud, type, buf);
485 else
486 baud = pl2303_baudrate_encode_divisor(baud, type, buf);
487 /* Save resulting baud rate */ 326 /* Save resulting baud rate */
488 tty_encode_baud_rate(tty, baud, baud); 327 tty_encode_baud_rate(tty, baud, baud);
489 dev_dbg(&port->dev, "baud set = %d\n", baud); 328 dev_dbg(&port->dev, "baud set = %d\n", baud);
@@ -540,8 +379,8 @@ static void pl2303_set_termios(struct tty_struct *tty,
540 dev_dbg(&port->dev, "data bits = %d\n", buf[6]); 379 dev_dbg(&port->dev, "data bits = %d\n", buf[6]);
541 } 380 }
542 381
543 /* For reference: buf[0]:buf[3] baud rate value */ 382 /* For reference buf[0]:buf[3] baud rate value */
544 pl2303_encode_baudrate(tty, port, spriv->type, buf); 383 pl2303_encode_baudrate(tty, port, &buf[0]);
545 384
546 /* For reference buf[4]=0 is 1 stop bits */ 385 /* For reference buf[4]=0 is 1 stop bits */
547 /* For reference buf[4]=1 is 1.5 stop bits */ 386 /* For reference buf[4]=1 is 1.5 stop bits */
@@ -618,10 +457,10 @@ static void pl2303_set_termios(struct tty_struct *tty,
618 dev_dbg(&port->dev, "0xa1:0x21:0:0 %d - %7ph\n", i, buf); 457 dev_dbg(&port->dev, "0xa1:0x21:0:0 %d - %7ph\n", i, buf);
619 458
620 if (C_CRTSCTS(tty)) { 459 if (C_CRTSCTS(tty)) {
621 if (spriv->type == type_0 || spriv->type == type_1) 460 if (spriv->type == HX)
622 pl2303_vendor_write(0x0, 0x41, serial);
623 else
624 pl2303_vendor_write(0x0, 0x61, serial); 461 pl2303_vendor_write(0x0, 0x61, serial);
462 else
463 pl2303_vendor_write(0x0, 0x41, serial);
625 } else { 464 } else {
626 pl2303_vendor_write(0x0, 0x0, serial); 465 pl2303_vendor_write(0x0, 0x0, serial);
627 } 466 }
@@ -658,7 +497,7 @@ static int pl2303_open(struct tty_struct *tty, struct usb_serial_port *port)
658 struct pl2303_serial_private *spriv = usb_get_serial_data(serial); 497 struct pl2303_serial_private *spriv = usb_get_serial_data(serial);
659 int result; 498 int result;
660 499
661 if (spriv->type == type_0 || spriv->type == type_1) { 500 if (spriv->type != HX) {
662 usb_clear_halt(serial->dev, port->write_urb->pipe); 501 usb_clear_halt(serial->dev, port->write_urb->pipe);
663 usb_clear_halt(serial->dev, port->read_urb->pipe); 502 usb_clear_halt(serial->dev, port->read_urb->pipe);
664 } else { 503 } else {
@@ -833,7 +672,6 @@ static void pl2303_break_ctl(struct tty_struct *tty, int break_state)
833 result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), 672 result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
834 BREAK_REQUEST, BREAK_REQUEST_TYPE, state, 673 BREAK_REQUEST, BREAK_REQUEST_TYPE, state,
835 0, NULL, 0, 100); 674 0, NULL, 0, 100);
836 /* NOTE: HX clones don't support sending breaks, -EPIPE is returned */
837 if (result) 675 if (result)
838 dev_err(&port->dev, "error sending break = %d\n", result); 676 dev_err(&port->dev, "error sending break = %d\n", result);
839} 677}
diff --git a/drivers/usb/wusbcore/cbaf.c b/drivers/usb/wusbcore/cbaf.c
index 7f78f300f8fb..f06ed82e63d1 100644
--- a/drivers/usb/wusbcore/cbaf.c
+++ b/drivers/usb/wusbcore/cbaf.c
@@ -208,9 +208,9 @@ static int cbaf_check(struct cbaf *cbaf)
208 ar_name = "ASSOCIATE"; 208 ar_name = "ASSOCIATE";
209 ar_assoc = 1; 209 ar_assoc = 1;
210 break; 210 break;
211 }; 211 }
212 break; 212 break;
213 }; 213 }
214 214
215 dev_dbg(dev, "Association request #%02u: 0x%04x/%04x " 215 dev_dbg(dev, "Association request #%02u: 0x%04x/%04x "
216 "(%zu bytes): %s\n", 216 "(%zu bytes): %s\n",
@@ -623,6 +623,8 @@ static int cbaf_probe(struct usb_interface *iface,
623 623
624error_create_group: 624error_create_group:
625error_check: 625error_check:
626 usb_put_intf(iface);
627 usb_put_dev(cbaf->usb_dev);
626 kfree(cbaf->buffer); 628 kfree(cbaf->buffer);
627error_kmalloc_buffer: 629error_kmalloc_buffer:
628 kfree(cbaf); 630 kfree(cbaf);
@@ -637,6 +639,7 @@ static void cbaf_disconnect(struct usb_interface *iface)
637 sysfs_remove_group(&dev->kobj, &cbaf_dev_attr_group); 639 sysfs_remove_group(&dev->kobj, &cbaf_dev_attr_group);
638 usb_set_intfdata(iface, NULL); 640 usb_set_intfdata(iface, NULL);
639 usb_put_intf(iface); 641 usb_put_intf(iface);
642 usb_put_dev(cbaf->usb_dev);
640 kfree(cbaf->buffer); 643 kfree(cbaf->buffer);
641 /* paranoia: clean up crypto keys */ 644 /* paranoia: clean up crypto keys */
642 kzfree(cbaf); 645 kzfree(cbaf);
diff --git a/drivers/usb/wusbcore/devconnect.c b/drivers/usb/wusbcore/devconnect.c
index 33a12788f9ca..e538b72c4e3a 100644
--- a/drivers/usb/wusbcore/devconnect.c
+++ b/drivers/usb/wusbcore/devconnect.c
@@ -973,7 +973,7 @@ int wusb_usb_ncb(struct notifier_block *nb, unsigned long val,
973 default: 973 default:
974 WARN_ON(1); 974 WARN_ON(1);
975 result = NOTIFY_BAD; 975 result = NOTIFY_BAD;
976 }; 976 }
977 return result; 977 return result;
978} 978}
979 979
diff --git a/drivers/usb/wusbcore/wa-hc.c b/drivers/usb/wusbcore/wa-hc.c
index a09b65ebd9bb..368360f9a93a 100644
--- a/drivers/usb/wusbcore/wa-hc.c
+++ b/drivers/usb/wusbcore/wa-hc.c
@@ -33,7 +33,8 @@
33 * wa->usb_dev and wa->usb_iface initialized and refcounted, 33 * wa->usb_dev and wa->usb_iface initialized and refcounted,
34 * wa->wa_descr initialized. 34 * wa->wa_descr initialized.
35 */ 35 */
36int wa_create(struct wahc *wa, struct usb_interface *iface) 36int wa_create(struct wahc *wa, struct usb_interface *iface,
37 kernel_ulong_t quirks)
37{ 38{
38 int result; 39 int result;
39 struct device *dev = &iface->dev; 40 struct device *dev = &iface->dev;
@@ -41,14 +42,15 @@ int wa_create(struct wahc *wa, struct usb_interface *iface)
41 result = wa_rpipes_create(wa); 42 result = wa_rpipes_create(wa);
42 if (result < 0) 43 if (result < 0)
43 goto error_rpipes_create; 44 goto error_rpipes_create;
45 wa->quirks = quirks;
44 /* Fill up Data Transfer EP pointers */ 46 /* Fill up Data Transfer EP pointers */
45 wa->dti_epd = &iface->cur_altsetting->endpoint[1].desc; 47 wa->dti_epd = &iface->cur_altsetting->endpoint[1].desc;
46 wa->dto_epd = &iface->cur_altsetting->endpoint[2].desc; 48 wa->dto_epd = &iface->cur_altsetting->endpoint[2].desc;
47 wa->xfer_result_size = usb_endpoint_maxp(wa->dti_epd); 49 wa->dti_buf_size = usb_endpoint_maxp(wa->dti_epd);
48 wa->xfer_result = kmalloc(wa->xfer_result_size, GFP_KERNEL); 50 wa->dti_buf = kmalloc(wa->dti_buf_size, GFP_KERNEL);
49 if (wa->xfer_result == NULL) { 51 if (wa->dti_buf == NULL) {
50 result = -ENOMEM; 52 result = -ENOMEM;
51 goto error_xfer_result_alloc; 53 goto error_dti_buf_alloc;
52 } 54 }
53 result = wa_nep_create(wa, iface); 55 result = wa_nep_create(wa, iface);
54 if (result < 0) { 56 if (result < 0) {
@@ -59,8 +61,8 @@ int wa_create(struct wahc *wa, struct usb_interface *iface)
59 return 0; 61 return 0;
60 62
61error_nep_create: 63error_nep_create:
62 kfree(wa->xfer_result); 64 kfree(wa->dti_buf);
63error_xfer_result_alloc: 65error_dti_buf_alloc:
64 wa_rpipes_destroy(wa); 66 wa_rpipes_destroy(wa);
65error_rpipes_create: 67error_rpipes_create:
66 return result; 68 return result;
@@ -76,7 +78,7 @@ void __wa_destroy(struct wahc *wa)
76 usb_kill_urb(wa->buf_in_urb); 78 usb_kill_urb(wa->buf_in_urb);
77 usb_put_urb(wa->buf_in_urb); 79 usb_put_urb(wa->buf_in_urb);
78 } 80 }
79 kfree(wa->xfer_result); 81 kfree(wa->dti_buf);
80 wa_nep_destroy(wa); 82 wa_nep_destroy(wa);
81 wa_rpipes_destroy(wa); 83 wa_rpipes_destroy(wa);
82} 84}
diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
index cf250c21e946..e614f02f0cf2 100644
--- a/drivers/usb/wusbcore/wa-hc.h
+++ b/drivers/usb/wusbcore/wa-hc.h
@@ -117,11 +117,25 @@ struct wa_rpipe {
117 struct wahc *wa; 117 struct wahc *wa;
118 spinlock_t seg_lock; 118 spinlock_t seg_lock;
119 struct list_head seg_list; 119 struct list_head seg_list;
120 struct list_head list_node;
120 atomic_t segs_available; 121 atomic_t segs_available;
121 u8 buffer[1]; /* For reads/writes on USB */ 122 u8 buffer[1]; /* For reads/writes on USB */
122}; 123};
123 124
124 125
126enum wa_dti_state {
127 WA_DTI_TRANSFER_RESULT_PENDING,
128 WA_DTI_ISOC_PACKET_STATUS_PENDING
129};
130
131enum wa_quirks {
132 /*
133 * The Alereon HWA expects the data frames in isochronous transfer
134 * requests to be concatenated and not sent as separate packets.
135 */
136 WUSB_QUIRK_ALEREON_HWA_CONCAT_ISOC = 0x01,
137};
138
125/** 139/**
126 * Instance of a HWA Host Controller 140 * Instance of a HWA Host Controller
127 * 141 *
@@ -178,14 +192,26 @@ struct wahc {
178 192
179 u16 rpipes; 193 u16 rpipes;
180 unsigned long *rpipe_bm; /* rpipe usage bitmap */ 194 unsigned long *rpipe_bm; /* rpipe usage bitmap */
181 spinlock_t rpipe_bm_lock; /* protect rpipe_bm */ 195 struct list_head rpipe_delayed_list; /* delayed RPIPES. */
196 spinlock_t rpipe_lock; /* protect rpipe_bm and delayed list */
182 struct mutex rpipe_mutex; /* assigning resources to endpoints */ 197 struct mutex rpipe_mutex; /* assigning resources to endpoints */
183 198
199 /*
200 * dti_state is used to track the state of the dti_urb. When dti_state
201 * is WA_DTI_ISOC_PACKET_STATUS_PENDING, dti_isoc_xfer_in_progress and
202 * dti_isoc_xfer_seg identify which xfer the incoming isoc packet status
203 * refers to.
204 */
205 enum wa_dti_state dti_state;
206 u32 dti_isoc_xfer_in_progress;
207 u8 dti_isoc_xfer_seg;
184 struct urb *dti_urb; /* URB for reading xfer results */ 208 struct urb *dti_urb; /* URB for reading xfer results */
185 struct urb *buf_in_urb; /* URB for reading data in */ 209 struct urb *buf_in_urb; /* URB for reading data in */
186 struct edc dti_edc; /* DTI error density counter */ 210 struct edc dti_edc; /* DTI error density counter */
187 struct wa_xfer_result *xfer_result; /* real size = dti_ep maxpktsize */ 211 void *dti_buf;
188 size_t xfer_result_size; 212 size_t dti_buf_size;
213
214 unsigned long dto_in_use; /* protect dto endoint serialization. */
189 215
190 s32 status; /* For reading status */ 216 s32 status; /* For reading status */
191 217
@@ -200,10 +226,13 @@ struct wahc {
200 struct work_struct xfer_enqueue_work; 226 struct work_struct xfer_enqueue_work;
201 struct work_struct xfer_error_work; 227 struct work_struct xfer_error_work;
202 atomic_t xfer_id_count; 228 atomic_t xfer_id_count;
229
230 kernel_ulong_t quirks;
203}; 231};
204 232
205 233
206extern int wa_create(struct wahc *wa, struct usb_interface *iface); 234extern int wa_create(struct wahc *wa, struct usb_interface *iface,
235 kernel_ulong_t);
207extern void __wa_destroy(struct wahc *wa); 236extern void __wa_destroy(struct wahc *wa);
208void wa_reset_all(struct wahc *wa); 237void wa_reset_all(struct wahc *wa);
209 238
@@ -239,7 +268,8 @@ static inline void wa_nep_disarm(struct wahc *wa)
239/* RPipes */ 268/* RPipes */
240static inline void wa_rpipe_init(struct wahc *wa) 269static inline void wa_rpipe_init(struct wahc *wa)
241{ 270{
242 spin_lock_init(&wa->rpipe_bm_lock); 271 INIT_LIST_HEAD(&wa->rpipe_delayed_list);
272 spin_lock_init(&wa->rpipe_lock);
243 mutex_init(&wa->rpipe_mutex); 273 mutex_init(&wa->rpipe_mutex);
244} 274}
245 275
@@ -247,6 +277,7 @@ static inline void wa_init(struct wahc *wa)
247{ 277{
248 edc_init(&wa->nep_edc); 278 edc_init(&wa->nep_edc);
249 atomic_set(&wa->notifs_queued, 0); 279 atomic_set(&wa->notifs_queued, 0);
280 wa->dti_state = WA_DTI_TRANSFER_RESULT_PENDING;
250 wa_rpipe_init(wa); 281 wa_rpipe_init(wa);
251 edc_init(&wa->dti_edc); 282 edc_init(&wa->dti_edc);
252 INIT_LIST_HEAD(&wa->xfer_list); 283 INIT_LIST_HEAD(&wa->xfer_list);
@@ -255,6 +286,7 @@ static inline void wa_init(struct wahc *wa)
255 spin_lock_init(&wa->xfer_list_lock); 286 spin_lock_init(&wa->xfer_list_lock);
256 INIT_WORK(&wa->xfer_enqueue_work, wa_urb_enqueue_run); 287 INIT_WORK(&wa->xfer_enqueue_work, wa_urb_enqueue_run);
257 INIT_WORK(&wa->xfer_error_work, wa_process_errored_transfers_run); 288 INIT_WORK(&wa->xfer_error_work, wa_process_errored_transfers_run);
289 wa->dto_in_use = 0;
258 atomic_set(&wa->xfer_id_count, 1); 290 atomic_set(&wa->xfer_id_count, 1);
259} 291}
260 292
diff --git a/drivers/usb/wusbcore/wa-rpipe.c b/drivers/usb/wusbcore/wa-rpipe.c
index fd4f1ce6256a..b48e74cc54d7 100644
--- a/drivers/usb/wusbcore/wa-rpipe.c
+++ b/drivers/usb/wusbcore/wa-rpipe.c
@@ -143,17 +143,18 @@ static void rpipe_init(struct wa_rpipe *rpipe)
143 kref_init(&rpipe->refcnt); 143 kref_init(&rpipe->refcnt);
144 spin_lock_init(&rpipe->seg_lock); 144 spin_lock_init(&rpipe->seg_lock);
145 INIT_LIST_HEAD(&rpipe->seg_list); 145 INIT_LIST_HEAD(&rpipe->seg_list);
146 INIT_LIST_HEAD(&rpipe->list_node);
146} 147}
147 148
148static unsigned rpipe_get_idx(struct wahc *wa, unsigned rpipe_idx) 149static unsigned rpipe_get_idx(struct wahc *wa, unsigned rpipe_idx)
149{ 150{
150 unsigned long flags; 151 unsigned long flags;
151 152
152 spin_lock_irqsave(&wa->rpipe_bm_lock, flags); 153 spin_lock_irqsave(&wa->rpipe_lock, flags);
153 rpipe_idx = find_next_zero_bit(wa->rpipe_bm, wa->rpipes, rpipe_idx); 154 rpipe_idx = find_next_zero_bit(wa->rpipe_bm, wa->rpipes, rpipe_idx);
154 if (rpipe_idx < wa->rpipes) 155 if (rpipe_idx < wa->rpipes)
155 set_bit(rpipe_idx, wa->rpipe_bm); 156 set_bit(rpipe_idx, wa->rpipe_bm);
156 spin_unlock_irqrestore(&wa->rpipe_bm_lock, flags); 157 spin_unlock_irqrestore(&wa->rpipe_lock, flags);
157 158
158 return rpipe_idx; 159 return rpipe_idx;
159} 160}
@@ -162,9 +163,9 @@ static void rpipe_put_idx(struct wahc *wa, unsigned rpipe_idx)
162{ 163{
163 unsigned long flags; 164 unsigned long flags;
164 165
165 spin_lock_irqsave(&wa->rpipe_bm_lock, flags); 166 spin_lock_irqsave(&wa->rpipe_lock, flags);
166 clear_bit(rpipe_idx, wa->rpipe_bm); 167 clear_bit(rpipe_idx, wa->rpipe_bm);
167 spin_unlock_irqrestore(&wa->rpipe_bm_lock, flags); 168 spin_unlock_irqrestore(&wa->rpipe_lock, flags);
168} 169}
169 170
170void rpipe_destroy(struct kref *_rpipe) 171void rpipe_destroy(struct kref *_rpipe)
@@ -333,7 +334,10 @@ static int rpipe_aim(struct wa_rpipe *rpipe, struct wahc *wa,
333 /* FIXME: compute so seg_size > ep->maxpktsize */ 334 /* FIXME: compute so seg_size > ep->maxpktsize */
334 rpipe->descr.wBlocks = cpu_to_le16(16); /* given */ 335 rpipe->descr.wBlocks = cpu_to_le16(16); /* given */
335 /* ep0 maxpktsize is 0x200 (WUSB1.0[4.8.1]) */ 336 /* ep0 maxpktsize is 0x200 (WUSB1.0[4.8.1]) */
336 rpipe->descr.wMaxPacketSize = cpu_to_le16(ep->desc.wMaxPacketSize); 337 if (usb_endpoint_xfer_isoc(&ep->desc))
338 rpipe->descr.wMaxPacketSize = epcd->wOverTheAirPacketSize;
339 else
340 rpipe->descr.wMaxPacketSize = ep->desc.wMaxPacketSize;
337 341
338 rpipe->descr.hwa_bMaxBurst = max(min_t(unsigned int, 342 rpipe->descr.hwa_bMaxBurst = max(min_t(unsigned int,
339 epcd->bMaxBurst, 16U), 1U); 343 epcd->bMaxBurst, 16U), 1U);
@@ -361,8 +365,10 @@ static int rpipe_aim(struct wa_rpipe *rpipe, struct wahc *wa,
361 epcd->bMaxSequence, 32U), 2U); 365 epcd->bMaxSequence, 32U), 2U);
362 rpipe->descr.bMaxDataSequence = epcd_max_sequence - 1; 366 rpipe->descr.bMaxDataSequence = epcd_max_sequence - 1;
363 rpipe->descr.bInterval = ep->desc.bInterval; 367 rpipe->descr.bInterval = ep->desc.bInterval;
364 /* FIXME: bOverTheAirInterval */ 368 if (usb_endpoint_xfer_isoc(&ep->desc))
365 rpipe->descr.bOverTheAirInterval = 0; /* 0 if not isoc */ 369 rpipe->descr.bOverTheAirInterval = epcd->bOverTheAirInterval;
370 else
371 rpipe->descr.bOverTheAirInterval = 0; /* 0 if not isoc */
366 /* FIXME: xmit power & preamble blah blah */ 372 /* FIXME: xmit power & preamble blah blah */
367 rpipe->descr.bmAttribute = (ep->desc.bmAttributes & 373 rpipe->descr.bmAttribute = (ep->desc.bmAttributes &
368 USB_ENDPOINT_XFERTYPE_MASK); 374 USB_ENDPOINT_XFERTYPE_MASK);
@@ -477,7 +483,7 @@ error:
477 */ 483 */
478int wa_rpipes_create(struct wahc *wa) 484int wa_rpipes_create(struct wahc *wa)
479{ 485{
480 wa->rpipes = wa->wa_descr->wNumRPipes; 486 wa->rpipes = le16_to_cpu(wa->wa_descr->wNumRPipes);
481 wa->rpipe_bm = kzalloc(BITS_TO_LONGS(wa->rpipes)*sizeof(unsigned long), 487 wa->rpipe_bm = kzalloc(BITS_TO_LONGS(wa->rpipes)*sizeof(unsigned long),
482 GFP_KERNEL); 488 GFP_KERNEL);
483 if (wa->rpipe_bm == NULL) 489 if (wa->rpipe_bm == NULL)
diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
index 6ad02f57c366..ed5abe87b049 100644
--- a/drivers/usb/wusbcore/wa-xfer.c
+++ b/drivers/usb/wusbcore/wa-xfer.c
@@ -91,7 +91,8 @@
91#include "wusbhc.h" 91#include "wusbhc.h"
92 92
93enum { 93enum {
94 WA_SEGS_MAX = 255, 94 /* [WUSB] section 8.3.3 allocates 7 bits for the segment index. */
95 WA_SEGS_MAX = 128,
95}; 96};
96 97
97enum wa_seg_status { 98enum wa_seg_status {
@@ -107,6 +108,7 @@ enum wa_seg_status {
107}; 108};
108 109
109static void wa_xfer_delayed_run(struct wa_rpipe *); 110static void wa_xfer_delayed_run(struct wa_rpipe *);
111static int __wa_xfer_delayed_run(struct wa_rpipe *rpipe, int *dto_waiting);
110 112
111/* 113/*
112 * Life cycle governed by 'struct urb' (the refcount of the struct is 114 * Life cycle governed by 'struct urb' (the refcount of the struct is
@@ -114,24 +116,27 @@ static void wa_xfer_delayed_run(struct wa_rpipe *);
114 * struct). 116 * struct).
115 */ 117 */
116struct wa_seg { 118struct wa_seg {
117 struct urb urb; 119 struct urb tr_urb; /* transfer request urb. */
118 struct urb *dto_urb; /* for data output? */ 120 struct urb *isoc_pack_desc_urb; /* for isoc packet descriptor. */
121 struct urb *dto_urb; /* for data output. */
119 struct list_head list_node; /* for rpipe->req_list */ 122 struct list_head list_node; /* for rpipe->req_list */
120 struct wa_xfer *xfer; /* out xfer */ 123 struct wa_xfer *xfer; /* out xfer */
121 u8 index; /* which segment we are */ 124 u8 index; /* which segment we are */
125 int isoc_frame_count; /* number of isoc frames in this segment. */
126 int isoc_frame_offset; /* starting frame offset in the xfer URB. */
127 int isoc_size; /* size of all isoc frames sent by this seg. */
122 enum wa_seg_status status; 128 enum wa_seg_status status;
123 ssize_t result; /* bytes xfered or error */ 129 ssize_t result; /* bytes xfered or error */
124 struct wa_xfer_hdr xfer_hdr; 130 struct wa_xfer_hdr xfer_hdr;
125 u8 xfer_extra[]; /* xtra space for xfer_hdr_ctl */
126}; 131};
127 132
128static inline void wa_seg_init(struct wa_seg *seg) 133static inline void wa_seg_init(struct wa_seg *seg)
129{ 134{
130 usb_init_urb(&seg->urb); 135 usb_init_urb(&seg->tr_urb);
131 136
132 /* set the remaining memory to 0. */ 137 /* set the remaining memory to 0. */
133 memset(((void *)seg) + sizeof(seg->urb), 0, 138 memset(((void *)seg) + sizeof(seg->tr_urb), 0,
134 sizeof(*seg) - sizeof(seg->urb)); 139 sizeof(*seg) - sizeof(seg->tr_urb));
135} 140}
136 141
137/* 142/*
@@ -153,12 +158,17 @@ struct wa_xfer {
153 unsigned is_dma:1; 158 unsigned is_dma:1;
154 size_t seg_size; 159 size_t seg_size;
155 int result; 160 int result;
161 /* Isoc frame that the current transfer buffer corresponds to. */
162 int dto_isoc_frame_index;
156 163
157 gfp_t gfp; /* allocation mask */ 164 gfp_t gfp; /* allocation mask */
158 165
159 struct wusb_dev *wusb_dev; /* for activity timestamps */ 166 struct wusb_dev *wusb_dev; /* for activity timestamps */
160}; 167};
161 168
169static void __wa_populate_dto_urb_isoc(struct wa_xfer *xfer,
170 struct wa_seg *seg, int curr_iso_frame);
171
162static inline void wa_xfer_init(struct wa_xfer *xfer) 172static inline void wa_xfer_init(struct wa_xfer *xfer)
163{ 173{
164 kref_init(&xfer->refcnt); 174 kref_init(&xfer->refcnt);
@@ -169,7 +179,7 @@ static inline void wa_xfer_init(struct wa_xfer *xfer)
169/* 179/*
170 * Destroy a transfer structure 180 * Destroy a transfer structure
171 * 181 *
172 * Note that freeing xfer->seg[cnt]->urb will free the containing 182 * Note that freeing xfer->seg[cnt]->tr_urb will free the containing
173 * xfer->seg[cnt] memory that was allocated by __wa_xfer_setup_segs. 183 * xfer->seg[cnt] memory that was allocated by __wa_xfer_setup_segs.
174 */ 184 */
175static void wa_xfer_destroy(struct kref *_xfer) 185static void wa_xfer_destroy(struct kref *_xfer)
@@ -178,9 +188,17 @@ static void wa_xfer_destroy(struct kref *_xfer)
178 if (xfer->seg) { 188 if (xfer->seg) {
179 unsigned cnt; 189 unsigned cnt;
180 for (cnt = 0; cnt < xfer->segs; cnt++) { 190 for (cnt = 0; cnt < xfer->segs; cnt++) {
181 usb_free_urb(xfer->seg[cnt]->dto_urb); 191 struct wa_seg *seg = xfer->seg[cnt];
182 usb_free_urb(&xfer->seg[cnt]->urb); 192 if (seg) {
193 usb_free_urb(seg->isoc_pack_desc_urb);
194 if (seg->dto_urb) {
195 kfree(seg->dto_urb->sg);
196 usb_free_urb(seg->dto_urb);
197 }
198 usb_free_urb(&seg->tr_urb);
199 }
183 } 200 }
201 kfree(xfer->seg);
184 } 202 }
185 kfree(xfer); 203 kfree(xfer);
186} 204}
@@ -196,6 +214,59 @@ static void wa_xfer_put(struct wa_xfer *xfer)
196} 214}
197 215
198/* 216/*
217 * Try to get exclusive access to the DTO endpoint resource. Return true
218 * if successful.
219 */
220static inline int __wa_dto_try_get(struct wahc *wa)
221{
222 return (test_and_set_bit(0, &wa->dto_in_use) == 0);
223}
224
225/* Release the DTO endpoint resource. */
226static inline void __wa_dto_put(struct wahc *wa)
227{
228 clear_bit_unlock(0, &wa->dto_in_use);
229}
230
231/* Service RPIPEs that are waiting on the DTO resource. */
232static void wa_check_for_delayed_rpipes(struct wahc *wa)
233{
234 unsigned long flags;
235 int dto_waiting = 0;
236 struct wa_rpipe *rpipe;
237
238 spin_lock_irqsave(&wa->rpipe_lock, flags);
239 while (!list_empty(&wa->rpipe_delayed_list) && !dto_waiting) {
240 rpipe = list_first_entry(&wa->rpipe_delayed_list,
241 struct wa_rpipe, list_node);
242 __wa_xfer_delayed_run(rpipe, &dto_waiting);
243 /* remove this RPIPE from the list if it is not waiting. */
244 if (!dto_waiting) {
245 pr_debug("%s: RPIPE %d serviced and removed from delayed list.\n",
246 __func__,
247 le16_to_cpu(rpipe->descr.wRPipeIndex));
248 list_del_init(&rpipe->list_node);
249 }
250 }
251 spin_unlock_irqrestore(&wa->rpipe_lock, flags);
252}
253
254/* add this RPIPE to the end of the delayed RPIPE list. */
255static void wa_add_delayed_rpipe(struct wahc *wa, struct wa_rpipe *rpipe)
256{
257 unsigned long flags;
258
259 spin_lock_irqsave(&wa->rpipe_lock, flags);
260 /* add rpipe to the list if it is not already on it. */
261 if (list_empty(&rpipe->list_node)) {
262 pr_debug("%s: adding RPIPE %d to the delayed list.\n",
263 __func__, le16_to_cpu(rpipe->descr.wRPipeIndex));
264 list_add_tail(&rpipe->list_node, &wa->rpipe_delayed_list);
265 }
266 spin_unlock_irqrestore(&wa->rpipe_lock, flags);
267}
268
269/*
199 * xfer is referenced 270 * xfer is referenced
200 * 271 *
201 * xfer->lock has to be unlocked 272 * xfer->lock has to be unlocked
@@ -232,6 +303,31 @@ static void wa_xfer_completion(struct wa_xfer *xfer)
232} 303}
233 304
234/* 305/*
306 * Initialize a transfer's ID
307 *
308 * We need to use a sequential number; if we use the pointer or the
309 * hash of the pointer, it can repeat over sequential transfers and
310 * then it will confuse the HWA....wonder why in hell they put a 32
311 * bit handle in there then.
312 */
313static void wa_xfer_id_init(struct wa_xfer *xfer)
314{
315 xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
316}
317
318/* Return the xfer's ID. */
319static inline u32 wa_xfer_id(struct wa_xfer *xfer)
320{
321 return xfer->id;
322}
323
324/* Return the xfer's ID in transport format (little endian). */
325static inline __le32 wa_xfer_id_le32(struct wa_xfer *xfer)
326{
327 return cpu_to_le32(xfer->id);
328}
329
330/*
235 * If transfer is done, wrap it up and return true 331 * If transfer is done, wrap it up and return true
236 * 332 *
237 * xfer->lock has to be locked 333 * xfer->lock has to be locked
@@ -253,33 +349,37 @@ static unsigned __wa_xfer_is_done(struct wa_xfer *xfer)
253 switch (seg->status) { 349 switch (seg->status) {
254 case WA_SEG_DONE: 350 case WA_SEG_DONE:
255 if (found_short && seg->result > 0) { 351 if (found_short && seg->result > 0) {
256 dev_dbg(dev, "xfer %p#%u: bad short segments (%zu)\n", 352 dev_dbg(dev, "xfer %p ID %08X#%u: bad short segments (%zu)\n",
257 xfer, cnt, seg->result); 353 xfer, wa_xfer_id(xfer), cnt,
354 seg->result);
258 urb->status = -EINVAL; 355 urb->status = -EINVAL;
259 goto out; 356 goto out;
260 } 357 }
261 urb->actual_length += seg->result; 358 urb->actual_length += seg->result;
262 if (seg->result < xfer->seg_size 359 if (!(usb_pipeisoc(xfer->urb->pipe))
360 && seg->result < xfer->seg_size
263 && cnt != xfer->segs-1) 361 && cnt != xfer->segs-1)
264 found_short = 1; 362 found_short = 1;
265 dev_dbg(dev, "xfer %p#%u: DONE short %d " 363 dev_dbg(dev, "xfer %p ID %08X#%u: DONE short %d "
266 "result %zu urb->actual_length %d\n", 364 "result %zu urb->actual_length %d\n",
267 xfer, seg->index, found_short, seg->result, 365 xfer, wa_xfer_id(xfer), seg->index, found_short,
268 urb->actual_length); 366 seg->result, urb->actual_length);
269 break; 367 break;
270 case WA_SEG_ERROR: 368 case WA_SEG_ERROR:
271 xfer->result = seg->result; 369 xfer->result = seg->result;
272 dev_dbg(dev, "xfer %p#%u: ERROR result %zu\n", 370 dev_dbg(dev, "xfer %p ID %08X#%u: ERROR result %zu(0x%08zX)\n",
273 xfer, seg->index, seg->result); 371 xfer, wa_xfer_id(xfer), seg->index, seg->result,
372 seg->result);
274 goto out; 373 goto out;
275 case WA_SEG_ABORTED: 374 case WA_SEG_ABORTED:
276 dev_dbg(dev, "xfer %p#%u ABORTED: result %d\n", 375 dev_dbg(dev, "xfer %p ID %08X#%u ABORTED: result %d\n",
277 xfer, seg->index, urb->status); 376 xfer, wa_xfer_id(xfer), seg->index,
377 urb->status);
278 xfer->result = urb->status; 378 xfer->result = urb->status;
279 goto out; 379 goto out;
280 default: 380 default:
281 dev_warn(dev, "xfer %p#%u: is_done bad state %d\n", 381 dev_warn(dev, "xfer %p ID %08X#%u: is_done bad state %d\n",
282 xfer, cnt, seg->status); 382 xfer, wa_xfer_id(xfer), cnt, seg->status);
283 xfer->result = -EINVAL; 383 xfer->result = -EINVAL;
284 goto out; 384 goto out;
285 } 385 }
@@ -290,29 +390,6 @@ out:
290} 390}
291 391
292/* 392/*
293 * Initialize a transfer's ID
294 *
295 * We need to use a sequential number; if we use the pointer or the
296 * hash of the pointer, it can repeat over sequential transfers and
297 * then it will confuse the HWA....wonder why in hell they put a 32
298 * bit handle in there then.
299 */
300static void wa_xfer_id_init(struct wa_xfer *xfer)
301{
302 xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
303}
304
305/*
306 * Return the xfer's ID associated with xfer
307 *
308 * Need to generate a
309 */
310static u32 wa_xfer_id(struct wa_xfer *xfer)
311{
312 return xfer->id;
313}
314
315/*
316 * Search for a transfer list ID on the HCD's URB list 393 * Search for a transfer list ID on the HCD's URB list
317 * 394 *
318 * For 32 bit architectures, we use the pointer itself; for 64 bits, a 395 * For 32 bit architectures, we use the pointer itself; for 64 bits, a
@@ -356,15 +433,11 @@ static void __wa_xfer_abort_cb(struct urb *urb)
356 * 433 *
357 * The callback (see above) does nothing but freeing up the data by 434 * The callback (see above) does nothing but freeing up the data by
358 * putting the URB. Because the URB is allocated at the head of the 435 * putting the URB. Because the URB is allocated at the head of the
359 * struct, the whole space we allocated is kfreed. 436 * struct, the whole space we allocated is kfreed. *
360 *
361 * We'll get an 'aborted transaction' xfer result on DTI, that'll
362 * politely ignore because at this point the transaction has been
363 * marked as aborted already.
364 */ 437 */
365static void __wa_xfer_abort(struct wa_xfer *xfer) 438static int __wa_xfer_abort(struct wa_xfer *xfer)
366{ 439{
367 int result; 440 int result = -ENOMEM;
368 struct device *dev = &xfer->wa->usb_iface->dev; 441 struct device *dev = &xfer->wa->usb_iface->dev;
369 struct wa_xfer_abort_buffer *b; 442 struct wa_xfer_abort_buffer *b;
370 struct wa_rpipe *rpipe = xfer->ep->hcpriv; 443 struct wa_rpipe *rpipe = xfer->ep->hcpriv;
@@ -375,7 +448,7 @@ static void __wa_xfer_abort(struct wa_xfer *xfer)
375 b->cmd.bLength = sizeof(b->cmd); 448 b->cmd.bLength = sizeof(b->cmd);
376 b->cmd.bRequestType = WA_XFER_ABORT; 449 b->cmd.bRequestType = WA_XFER_ABORT;
377 b->cmd.wRPipe = rpipe->descr.wRPipeIndex; 450 b->cmd.wRPipe = rpipe->descr.wRPipeIndex;
378 b->cmd.dwTransferID = wa_xfer_id(xfer); 451 b->cmd.dwTransferID = wa_xfer_id_le32(xfer);
379 452
380 usb_init_urb(&b->urb); 453 usb_init_urb(&b->urb);
381 usb_fill_bulk_urb(&b->urb, xfer->wa->usb_dev, 454 usb_fill_bulk_urb(&b->urb, xfer->wa->usb_dev,
@@ -385,7 +458,7 @@ static void __wa_xfer_abort(struct wa_xfer *xfer)
385 result = usb_submit_urb(&b->urb, GFP_ATOMIC); 458 result = usb_submit_urb(&b->urb, GFP_ATOMIC);
386 if (result < 0) 459 if (result < 0)
387 goto error_submit; 460 goto error_submit;
388 return; /* callback frees! */ 461 return result; /* callback frees! */
389 462
390 463
391error_submit: 464error_submit:
@@ -394,11 +467,52 @@ error_submit:
394 xfer, result); 467 xfer, result);
395 kfree(b); 468 kfree(b);
396error_kmalloc: 469error_kmalloc:
397 return; 470 return result;
398 471
399} 472}
400 473
401/* 474/*
475 * Calculate the number of isoc frames starting from isoc_frame_offset
476 * that will fit a in transfer segment.
477 */
478static int __wa_seg_calculate_isoc_frame_count(struct wa_xfer *xfer,
479 int isoc_frame_offset, int *total_size)
480{
481 int segment_size = 0, frame_count = 0;
482 int index = isoc_frame_offset;
483 struct usb_iso_packet_descriptor *iso_frame_desc =
484 xfer->urb->iso_frame_desc;
485
486 while ((index < xfer->urb->number_of_packets)
487 && ((segment_size + iso_frame_desc[index].length)
488 <= xfer->seg_size)) {
489 /*
490 * For Alereon HWA devices, only include an isoc frame in a
491 * segment if it is physically contiguous with the previous
492 * frame. This is required because those devices expect
493 * the isoc frames to be sent as a single USB transaction as
494 * opposed to one transaction per frame with standard HWA.
495 */
496 if ((xfer->wa->quirks & WUSB_QUIRK_ALEREON_HWA_CONCAT_ISOC)
497 && (index > isoc_frame_offset)
498 && ((iso_frame_desc[index - 1].offset +
499 iso_frame_desc[index - 1].length) !=
500 iso_frame_desc[index].offset))
501 break;
502
503 /* this frame fits. count it. */
504 ++frame_count;
505 segment_size += iso_frame_desc[index].length;
506
507 /* move to the next isoc frame. */
508 ++index;
509 }
510
511 *total_size = segment_size;
512 return frame_count;
513}
514
515/*
402 * 516 *
403 * @returns < 0 on error, transfer segment request size if ok 517 * @returns < 0 on error, transfer segment request size if ok
404 */ 518 */
@@ -422,43 +536,92 @@ static ssize_t __wa_xfer_setup_sizes(struct wa_xfer *xfer,
422 result = sizeof(struct wa_xfer_bi); 536 result = sizeof(struct wa_xfer_bi);
423 break; 537 break;
424 case USB_ENDPOINT_XFER_ISOC: 538 case USB_ENDPOINT_XFER_ISOC:
425 dev_err(dev, "FIXME: ISOC not implemented\n"); 539 if (usb_pipeout(urb->pipe)) {
426 result = -ENOSYS; 540 *pxfer_type = WA_XFER_TYPE_ISO;
427 goto error; 541 result = sizeof(struct wa_xfer_hwaiso);
542 } else {
543 dev_err(dev, "FIXME: ISOC IN not implemented\n");
544 result = -ENOSYS;
545 goto error;
546 }
547 break;
428 default: 548 default:
429 /* never happens */ 549 /* never happens */
430 BUG(); 550 BUG();
431 result = -EINVAL; /* shut gcc up */ 551 result = -EINVAL; /* shut gcc up */
432 }; 552 }
433 xfer->is_inbound = urb->pipe & USB_DIR_IN ? 1 : 0; 553 xfer->is_inbound = urb->pipe & USB_DIR_IN ? 1 : 0;
434 xfer->is_dma = urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP ? 1 : 0; 554 xfer->is_dma = urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP ? 1 : 0;
435 xfer->seg_size = le16_to_cpu(rpipe->descr.wBlocks) 555
436 * 1 << (xfer->wa->wa_descr->bRPipeBlockSize - 1);
437 /* Compute the segment size and make sure it is a multiple of
438 * the maxpktsize (WUSB1.0[8.3.3.1])...not really too much of
439 * a check (FIXME) */
440 maxpktsize = le16_to_cpu(rpipe->descr.wMaxPacketSize); 556 maxpktsize = le16_to_cpu(rpipe->descr.wMaxPacketSize);
441 if (xfer->seg_size < maxpktsize) { 557 if ((rpipe->descr.bmAttribute & 0x3) == USB_ENDPOINT_XFER_ISOC) {
442 dev_err(dev, "HW BUG? seg_size %zu smaller than maxpktsize " 558 int index = 0;
443 "%zu\n", xfer->seg_size, maxpktsize); 559
444 result = -EINVAL; 560 xfer->seg_size = maxpktsize;
445 goto error; 561 xfer->segs = 0;
562 /*
563 * loop over urb->number_of_packets to determine how many
564 * xfer segments will be needed to send the isoc frames.
565 */
566 while (index < urb->number_of_packets) {
567 int seg_size; /* don't care. */
568 index += __wa_seg_calculate_isoc_frame_count(xfer,
569 index, &seg_size);
570 ++xfer->segs;
571 }
572 } else {
573 xfer->seg_size = le16_to_cpu(rpipe->descr.wBlocks)
574 * 1 << (xfer->wa->wa_descr->bRPipeBlockSize - 1);
575 /* Compute the segment size and make sure it is a multiple of
576 * the maxpktsize (WUSB1.0[8.3.3.1])...not really too much of
577 * a check (FIXME) */
578 if (xfer->seg_size < maxpktsize) {
579 dev_err(dev,
580 "HW BUG? seg_size %zu smaller than maxpktsize %zu\n",
581 xfer->seg_size, maxpktsize);
582 result = -EINVAL;
583 goto error;
584 }
585 xfer->seg_size = (xfer->seg_size / maxpktsize) * maxpktsize;
586 xfer->segs = DIV_ROUND_UP(urb->transfer_buffer_length,
587 xfer->seg_size);
588 if (xfer->segs == 0 && *pxfer_type == WA_XFER_TYPE_CTL)
589 xfer->segs = 1;
446 } 590 }
447 xfer->seg_size = (xfer->seg_size / maxpktsize) * maxpktsize; 591
448 xfer->segs = DIV_ROUND_UP(urb->transfer_buffer_length, xfer->seg_size); 592 if (xfer->segs > WA_SEGS_MAX) {
449 if (xfer->segs >= WA_SEGS_MAX) { 593 dev_err(dev, "BUG? oops, number of segments %zu bigger than %d\n",
450 dev_err(dev, "BUG? ops, number of segments %d bigger than %d\n", 594 (urb->transfer_buffer_length/xfer->seg_size),
451 (int)(urb->transfer_buffer_length / xfer->seg_size),
452 WA_SEGS_MAX); 595 WA_SEGS_MAX);
453 result = -EINVAL; 596 result = -EINVAL;
454 goto error; 597 goto error;
455 } 598 }
456 if (xfer->segs == 0 && *pxfer_type == WA_XFER_TYPE_CTL)
457 xfer->segs = 1;
458error: 599error:
459 return result; 600 return result;
460} 601}
461 602
603static void __wa_setup_isoc_packet_descr(
604 struct wa_xfer_packet_info_hwaiso *packet_desc,
605 struct wa_xfer *xfer,
606 struct wa_seg *seg) {
607 struct usb_iso_packet_descriptor *iso_frame_desc =
608 xfer->urb->iso_frame_desc;
609 int frame_index;
610
611 /* populate isoc packet descriptor. */
612 packet_desc->bPacketType = WA_XFER_ISO_PACKET_INFO;
613 packet_desc->wLength = cpu_to_le16(sizeof(*packet_desc) +
614 (sizeof(packet_desc->PacketLength[0]) *
615 seg->isoc_frame_count));
616 for (frame_index = 0; frame_index < seg->isoc_frame_count;
617 ++frame_index) {
618 int offset_index = frame_index + seg->isoc_frame_offset;
619 packet_desc->PacketLength[frame_index] =
620 cpu_to_le16(iso_frame_desc[offset_index].length);
621 }
622}
623
624
462/* Fill in the common request header and xfer-type specific data. */ 625/* Fill in the common request header and xfer-type specific data. */
463static void __wa_xfer_setup_hdr0(struct wa_xfer *xfer, 626static void __wa_xfer_setup_hdr0(struct wa_xfer *xfer,
464 struct wa_xfer_hdr *xfer_hdr0, 627 struct wa_xfer_hdr *xfer_hdr0,
@@ -466,12 +629,13 @@ static void __wa_xfer_setup_hdr0(struct wa_xfer *xfer,
466 size_t xfer_hdr_size) 629 size_t xfer_hdr_size)
467{ 630{
468 struct wa_rpipe *rpipe = xfer->ep->hcpriv; 631 struct wa_rpipe *rpipe = xfer->ep->hcpriv;
632 struct wa_seg *seg = xfer->seg[0];
469 633
470 xfer_hdr0 = &xfer->seg[0]->xfer_hdr; 634 xfer_hdr0 = &seg->xfer_hdr;
471 xfer_hdr0->bLength = xfer_hdr_size; 635 xfer_hdr0->bLength = xfer_hdr_size;
472 xfer_hdr0->bRequestType = xfer_type; 636 xfer_hdr0->bRequestType = xfer_type;
473 xfer_hdr0->wRPipe = rpipe->descr.wRPipeIndex; 637 xfer_hdr0->wRPipe = rpipe->descr.wRPipeIndex;
474 xfer_hdr0->dwTransferID = wa_xfer_id(xfer); 638 xfer_hdr0->dwTransferID = wa_xfer_id_le32(xfer);
475 xfer_hdr0->bTransferSegment = 0; 639 xfer_hdr0->bTransferSegment = 0;
476 switch (xfer_type) { 640 switch (xfer_type) {
477 case WA_XFER_TYPE_CTL: { 641 case WA_XFER_TYPE_CTL: {
@@ -484,8 +648,18 @@ static void __wa_xfer_setup_hdr0(struct wa_xfer *xfer,
484 } 648 }
485 case WA_XFER_TYPE_BI: 649 case WA_XFER_TYPE_BI:
486 break; 650 break;
487 case WA_XFER_TYPE_ISO: 651 case WA_XFER_TYPE_ISO: {
488 printk(KERN_ERR "FIXME: ISOC not implemented\n"); 652 struct wa_xfer_hwaiso *xfer_iso =
653 container_of(xfer_hdr0, struct wa_xfer_hwaiso, hdr);
654 struct wa_xfer_packet_info_hwaiso *packet_desc =
655 ((void *)xfer_iso) + xfer_hdr_size;
656
657 /* populate the isoc section of the transfer request. */
658 xfer_iso->dwNumOfPackets = cpu_to_le32(seg->isoc_frame_count);
659 /* populate isoc packet descriptor. */
660 __wa_setup_isoc_packet_descr(packet_desc, xfer, seg);
661 break;
662 }
489 default: 663 default:
490 BUG(); 664 BUG();
491 }; 665 };
@@ -494,12 +668,12 @@ static void __wa_xfer_setup_hdr0(struct wa_xfer *xfer,
494/* 668/*
495 * Callback for the OUT data phase of the segment request 669 * Callback for the OUT data phase of the segment request
496 * 670 *
497 * Check wa_seg_cb(); most comments also apply here because this 671 * Check wa_seg_tr_cb(); most comments also apply here because this
498 * function does almost the same thing and they work closely 672 * function does almost the same thing and they work closely
499 * together. 673 * together.
500 * 674 *
501 * If the seg request has failed but this DTO phase has succeeded, 675 * If the seg request has failed but this DTO phase has succeeded,
502 * wa_seg_cb() has already failed the segment and moved the 676 * wa_seg_tr_cb() has already failed the segment and moved the
503 * status to WA_SEG_ERROR, so this will go through 'case 0' and 677 * status to WA_SEG_ERROR, so this will go through 'case 0' and
504 * effectively do nothing. 678 * effectively do nothing.
505 */ 679 */
@@ -512,6 +686,139 @@ static void wa_seg_dto_cb(struct urb *urb)
512 struct wa_rpipe *rpipe; 686 struct wa_rpipe *rpipe;
513 unsigned long flags; 687 unsigned long flags;
514 unsigned rpipe_ready = 0; 688 unsigned rpipe_ready = 0;
689 int data_send_done = 1, release_dto = 0, holding_dto = 0;
690 u8 done = 0;
691 int result;
692
693 /* free the sg if it was used. */
694 kfree(urb->sg);
695 urb->sg = NULL;
696
697 spin_lock_irqsave(&xfer->lock, flags);
698 wa = xfer->wa;
699 dev = &wa->usb_iface->dev;
700 if (usb_pipeisoc(xfer->urb->pipe)) {
701 /* Alereon HWA sends all isoc frames in a single transfer. */
702 if (wa->quirks & WUSB_QUIRK_ALEREON_HWA_CONCAT_ISOC)
703 xfer->dto_isoc_frame_index += seg->isoc_frame_count;
704 else
705 xfer->dto_isoc_frame_index += 1;
706 if (xfer->dto_isoc_frame_index < seg->isoc_frame_count) {
707 data_send_done = 0;
708 holding_dto = 1; /* checked in error cases. */
709 /*
710 * if this is the last isoc frame of the segment, we
711 * can release DTO after sending this frame.
712 */
713 if ((xfer->dto_isoc_frame_index + 1) >=
714 seg->isoc_frame_count)
715 release_dto = 1;
716 }
717 dev_dbg(dev, "xfer 0x%08X#%u: isoc frame = %d, holding_dto = %d, release_dto = %d.\n",
718 wa_xfer_id(xfer), seg->index,
719 xfer->dto_isoc_frame_index, holding_dto, release_dto);
720 }
721 spin_unlock_irqrestore(&xfer->lock, flags);
722
723 switch (urb->status) {
724 case 0:
725 spin_lock_irqsave(&xfer->lock, flags);
726 seg->result += urb->actual_length;
727 if (data_send_done) {
728 dev_dbg(dev, "xfer 0x%08X#%u: data out done (%zu bytes)\n",
729 wa_xfer_id(xfer), seg->index, seg->result);
730 if (seg->status < WA_SEG_PENDING)
731 seg->status = WA_SEG_PENDING;
732 } else {
733 /* should only hit this for isoc xfers. */
734 /*
735 * Populate the dto URB with the next isoc frame buffer,
736 * send the URB and release DTO if we no longer need it.
737 */
738 __wa_populate_dto_urb_isoc(xfer, seg,
739 seg->isoc_frame_offset +
740 xfer->dto_isoc_frame_index);
741
742 /* resubmit the URB with the next isoc frame. */
743 result = usb_submit_urb(seg->dto_urb, GFP_ATOMIC);
744 if (result < 0) {
745 dev_err(dev, "xfer 0x%08X#%u: DTO submit failed: %d\n",
746 wa_xfer_id(xfer), seg->index, result);
747 spin_unlock_irqrestore(&xfer->lock, flags);
748 goto error_dto_submit;
749 }
750 }
751 spin_unlock_irqrestore(&xfer->lock, flags);
752 if (release_dto) {
753 __wa_dto_put(wa);
754 wa_check_for_delayed_rpipes(wa);
755 }
756 break;
757 case -ECONNRESET: /* URB unlinked; no need to do anything */
758 case -ENOENT: /* as it was done by the who unlinked us */
759 if (holding_dto) {
760 __wa_dto_put(wa);
761 wa_check_for_delayed_rpipes(wa);
762 }
763 break;
764 default: /* Other errors ... */
765 dev_err(dev, "xfer 0x%08X#%u: data out error %d\n",
766 wa_xfer_id(xfer), seg->index, urb->status);
767 goto error_default;
768 }
769
770 return;
771
772error_dto_submit:
773error_default:
774 spin_lock_irqsave(&xfer->lock, flags);
775 rpipe = xfer->ep->hcpriv;
776 if (edc_inc(&wa->nep_edc, EDC_MAX_ERRORS,
777 EDC_ERROR_TIMEFRAME)){
778 dev_err(dev, "DTO: URB max acceptable errors exceeded, resetting device\n");
779 wa_reset_all(wa);
780 }
781 if (seg->status != WA_SEG_ERROR) {
782 seg->status = WA_SEG_ERROR;
783 seg->result = urb->status;
784 xfer->segs_done++;
785 __wa_xfer_abort(xfer);
786 rpipe_ready = rpipe_avail_inc(rpipe);
787 done = __wa_xfer_is_done(xfer);
788 }
789 spin_unlock_irqrestore(&xfer->lock, flags);
790 if (holding_dto) {
791 __wa_dto_put(wa);
792 wa_check_for_delayed_rpipes(wa);
793 }
794 if (done)
795 wa_xfer_completion(xfer);
796 if (rpipe_ready)
797 wa_xfer_delayed_run(rpipe);
798
799}
800
801/*
802 * Callback for the isoc packet descriptor phase of the segment request
803 *
804 * Check wa_seg_tr_cb(); most comments also apply here because this
805 * function does almost the same thing and they work closely
806 * together.
807 *
808 * If the seg request has failed but this phase has succeeded,
809 * wa_seg_tr_cb() has already failed the segment and moved the
810 * status to WA_SEG_ERROR, so this will go through 'case 0' and
811 * effectively do nothing.
812 */
813static void wa_seg_iso_pack_desc_cb(struct urb *urb)
814{
815 struct wa_seg *seg = urb->context;
816 struct wa_xfer *xfer = seg->xfer;
817 struct wahc *wa;
818 struct device *dev;
819 struct wa_rpipe *rpipe;
820 unsigned long flags;
821 unsigned rpipe_ready = 0;
515 u8 done = 0; 822 u8 done = 0;
516 823
517 switch (urb->status) { 824 switch (urb->status) {
@@ -519,11 +826,10 @@ static void wa_seg_dto_cb(struct urb *urb)
519 spin_lock_irqsave(&xfer->lock, flags); 826 spin_lock_irqsave(&xfer->lock, flags);
520 wa = xfer->wa; 827 wa = xfer->wa;
521 dev = &wa->usb_iface->dev; 828 dev = &wa->usb_iface->dev;
522 dev_dbg(dev, "xfer %p#%u: data out done (%d bytes)\n", 829 dev_dbg(dev, "iso xfer %08X#%u: packet descriptor done\n",
523 xfer, seg->index, urb->actual_length); 830 wa_xfer_id(xfer), seg->index);
524 if (seg->status < WA_SEG_PENDING) 831 if (xfer->is_inbound && seg->status < WA_SEG_PENDING)
525 seg->status = WA_SEG_PENDING; 832 seg->status = WA_SEG_PENDING;
526 seg->result = urb->actual_length;
527 spin_unlock_irqrestore(&xfer->lock, flags); 833 spin_unlock_irqrestore(&xfer->lock, flags);
528 break; 834 break;
529 case -ECONNRESET: /* URB unlinked; no need to do anything */ 835 case -ECONNRESET: /* URB unlinked; no need to do anything */
@@ -534,15 +840,15 @@ static void wa_seg_dto_cb(struct urb *urb)
534 wa = xfer->wa; 840 wa = xfer->wa;
535 dev = &wa->usb_iface->dev; 841 dev = &wa->usb_iface->dev;
536 rpipe = xfer->ep->hcpriv; 842 rpipe = xfer->ep->hcpriv;
537 dev_dbg(dev, "xfer %p#%u: data out error %d\n", 843 pr_err_ratelimited("iso xfer %08X#%u: packet descriptor error %d\n",
538 xfer, seg->index, urb->status); 844 wa_xfer_id(xfer), seg->index, urb->status);
539 if (edc_inc(&wa->nep_edc, EDC_MAX_ERRORS, 845 if (edc_inc(&wa->nep_edc, EDC_MAX_ERRORS,
540 EDC_ERROR_TIMEFRAME)){ 846 EDC_ERROR_TIMEFRAME)){
541 dev_err(dev, "DTO: URB max acceptable errors " 847 dev_err(dev, "DTO: URB max acceptable errors exceeded, resetting device\n");
542 "exceeded, resetting device\n");
543 wa_reset_all(wa); 848 wa_reset_all(wa);
544 } 849 }
545 if (seg->status != WA_SEG_ERROR) { 850 if (seg->status != WA_SEG_ERROR) {
851 usb_unlink_urb(seg->dto_urb);
546 seg->status = WA_SEG_ERROR; 852 seg->status = WA_SEG_ERROR;
547 seg->result = urb->status; 853 seg->result = urb->status;
548 xfer->segs_done++; 854 xfer->segs_done++;
@@ -572,11 +878,11 @@ static void wa_seg_dto_cb(struct urb *urb)
572 * We have to check before setting the status to WA_SEG_PENDING 878 * We have to check before setting the status to WA_SEG_PENDING
573 * because sometimes the xfer result callback arrives before this 879 * because sometimes the xfer result callback arrives before this
574 * callback (geeeeeeze), so it might happen that we are already in 880 * callback (geeeeeeze), so it might happen that we are already in
575 * another state. As well, we don't set it if the transfer is inbound, 881 * another state. As well, we don't set it if the transfer is not inbound,
576 * as in that case, wa_seg_dto_cb will do it when the OUT data phase 882 * as in that case, wa_seg_dto_cb will do it when the OUT data phase
577 * finishes. 883 * finishes.
578 */ 884 */
579static void wa_seg_cb(struct urb *urb) 885static void wa_seg_tr_cb(struct urb *urb)
580{ 886{
581 struct wa_seg *seg = urb->context; 887 struct wa_seg *seg = urb->context;
582 struct wa_xfer *xfer = seg->xfer; 888 struct wa_xfer *xfer = seg->xfer;
@@ -592,8 +898,11 @@ static void wa_seg_cb(struct urb *urb)
592 spin_lock_irqsave(&xfer->lock, flags); 898 spin_lock_irqsave(&xfer->lock, flags);
593 wa = xfer->wa; 899 wa = xfer->wa;
594 dev = &wa->usb_iface->dev; 900 dev = &wa->usb_iface->dev;
595 dev_dbg(dev, "xfer %p#%u: request done\n", xfer, seg->index); 901 dev_dbg(dev, "xfer %p ID 0x%08X#%u: request done\n",
596 if (xfer->is_inbound && seg->status < WA_SEG_PENDING) 902 xfer, wa_xfer_id(xfer), seg->index);
903 if (xfer->is_inbound &&
904 seg->status < WA_SEG_PENDING &&
905 !(usb_pipeisoc(xfer->urb->pipe)))
597 seg->status = WA_SEG_PENDING; 906 seg->status = WA_SEG_PENDING;
598 spin_unlock_irqrestore(&xfer->lock, flags); 907 spin_unlock_irqrestore(&xfer->lock, flags);
599 break; 908 break;
@@ -606,14 +915,16 @@ static void wa_seg_cb(struct urb *urb)
606 dev = &wa->usb_iface->dev; 915 dev = &wa->usb_iface->dev;
607 rpipe = xfer->ep->hcpriv; 916 rpipe = xfer->ep->hcpriv;
608 if (printk_ratelimit()) 917 if (printk_ratelimit())
609 dev_err(dev, "xfer %p#%u: request error %d\n", 918 dev_err(dev, "xfer %p ID 0x%08X#%u: request error %d\n",
610 xfer, seg->index, urb->status); 919 xfer, wa_xfer_id(xfer), seg->index,
920 urb->status);
611 if (edc_inc(&wa->nep_edc, EDC_MAX_ERRORS, 921 if (edc_inc(&wa->nep_edc, EDC_MAX_ERRORS,
612 EDC_ERROR_TIMEFRAME)){ 922 EDC_ERROR_TIMEFRAME)){
613 dev_err(dev, "DTO: URB max acceptable errors " 923 dev_err(dev, "DTO: URB max acceptable errors "
614 "exceeded, resetting device\n"); 924 "exceeded, resetting device\n");
615 wa_reset_all(wa); 925 wa_reset_all(wa);
616 } 926 }
927 usb_unlink_urb(seg->isoc_pack_desc_urb);
617 usb_unlink_urb(seg->dto_urb); 928 usb_unlink_urb(seg->dto_urb);
618 seg->status = WA_SEG_ERROR; 929 seg->status = WA_SEG_ERROR;
619 seg->result = urb->status; 930 seg->result = urb->status;
@@ -629,9 +940,11 @@ static void wa_seg_cb(struct urb *urb)
629 } 940 }
630} 941}
631 942
632/* allocate an SG list to store bytes_to_transfer bytes and copy the 943/*
944 * Allocate an SG list to store bytes_to_transfer bytes and copy the
633 * subset of the in_sg that matches the buffer subset 945 * subset of the in_sg that matches the buffer subset
634 * we are about to transfer. */ 946 * we are about to transfer.
947 */
635static struct scatterlist *wa_xfer_create_subset_sg(struct scatterlist *in_sg, 948static struct scatterlist *wa_xfer_create_subset_sg(struct scatterlist *in_sg,
636 const unsigned int bytes_transferred, 949 const unsigned int bytes_transferred,
637 const unsigned int bytes_to_transfer, unsigned int *out_num_sgs) 950 const unsigned int bytes_to_transfer, unsigned int *out_num_sgs)
@@ -710,6 +1023,75 @@ static struct scatterlist *wa_xfer_create_subset_sg(struct scatterlist *in_sg,
710} 1023}
711 1024
712/* 1025/*
1026 * Populate DMA buffer info for the isoc dto urb.
1027 */
1028static void __wa_populate_dto_urb_isoc(struct wa_xfer *xfer,
1029 struct wa_seg *seg, int curr_iso_frame)
1030{
1031 seg->dto_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
1032 seg->dto_urb->sg = NULL;
1033 seg->dto_urb->num_sgs = 0;
1034 /* dto urb buffer address pulled from iso_frame_desc. */
1035 seg->dto_urb->transfer_dma = xfer->urb->transfer_dma +
1036 xfer->urb->iso_frame_desc[curr_iso_frame].offset;
1037 /* The Alereon HWA sends a single URB with all isoc segs. */
1038 if (xfer->wa->quirks & WUSB_QUIRK_ALEREON_HWA_CONCAT_ISOC)
1039 seg->dto_urb->transfer_buffer_length = seg->isoc_size;
1040 else
1041 seg->dto_urb->transfer_buffer_length =
1042 xfer->urb->iso_frame_desc[curr_iso_frame].length;
1043}
1044
1045/*
1046 * Populate buffer ptr and size, DMA buffer or SG list for the dto urb.
1047 */
1048static int __wa_populate_dto_urb(struct wa_xfer *xfer,
1049 struct wa_seg *seg, size_t buf_itr_offset, size_t buf_itr_size)
1050{
1051 int result = 0;
1052
1053 if (xfer->is_dma) {
1054 seg->dto_urb->transfer_dma =
1055 xfer->urb->transfer_dma + buf_itr_offset;
1056 seg->dto_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
1057 seg->dto_urb->sg = NULL;
1058 seg->dto_urb->num_sgs = 0;
1059 } else {
1060 /* do buffer or SG processing. */
1061 seg->dto_urb->transfer_flags &=
1062 ~URB_NO_TRANSFER_DMA_MAP;
1063 /* this should always be 0 before a resubmit. */
1064 seg->dto_urb->num_mapped_sgs = 0;
1065
1066 if (xfer->urb->transfer_buffer) {
1067 seg->dto_urb->transfer_buffer =
1068 xfer->urb->transfer_buffer +
1069 buf_itr_offset;
1070 seg->dto_urb->sg = NULL;
1071 seg->dto_urb->num_sgs = 0;
1072 } else {
1073 seg->dto_urb->transfer_buffer = NULL;
1074
1075 /*
1076 * allocate an SG list to store seg_size bytes
1077 * and copy the subset of the xfer->urb->sg that
1078 * matches the buffer subset we are about to
1079 * read.
1080 */
1081 seg->dto_urb->sg = wa_xfer_create_subset_sg(
1082 xfer->urb->sg,
1083 buf_itr_offset, buf_itr_size,
1084 &(seg->dto_urb->num_sgs));
1085 if (!(seg->dto_urb->sg))
1086 result = -ENOMEM;
1087 }
1088 }
1089 seg->dto_urb->transfer_buffer_length = buf_itr_size;
1090
1091 return result;
1092}
1093
1094/*
713 * Allocate the segs array and initialize each of them 1095 * Allocate the segs array and initialize each of them
714 * 1096 *
715 * The segments are freed by wa_xfer_destroy() when the xfer use count 1097 * The segments are freed by wa_xfer_destroy() when the xfer use count
@@ -719,13 +1101,14 @@ static struct scatterlist *wa_xfer_create_subset_sg(struct scatterlist *in_sg,
719 */ 1101 */
720static int __wa_xfer_setup_segs(struct wa_xfer *xfer, size_t xfer_hdr_size) 1102static int __wa_xfer_setup_segs(struct wa_xfer *xfer, size_t xfer_hdr_size)
721{ 1103{
722 int result, cnt; 1104 int result, cnt, iso_frame_offset;
723 size_t alloc_size = sizeof(*xfer->seg[0]) 1105 size_t alloc_size = sizeof(*xfer->seg[0])
724 - sizeof(xfer->seg[0]->xfer_hdr) + xfer_hdr_size; 1106 - sizeof(xfer->seg[0]->xfer_hdr) + xfer_hdr_size;
725 struct usb_device *usb_dev = xfer->wa->usb_dev; 1107 struct usb_device *usb_dev = xfer->wa->usb_dev;
726 const struct usb_endpoint_descriptor *dto_epd = xfer->wa->dto_epd; 1108 const struct usb_endpoint_descriptor *dto_epd = xfer->wa->dto_epd;
727 struct wa_seg *seg; 1109 struct wa_seg *seg;
728 size_t buf_itr, buf_size, buf_itr_size; 1110 size_t buf_itr, buf_size, buf_itr_size;
1111 int xfer_isoc_frame_offset = 0;
729 1112
730 result = -ENOMEM; 1113 result = -ENOMEM;
731 xfer->seg = kcalloc(xfer->segs, sizeof(xfer->seg[0]), GFP_ATOMIC); 1114 xfer->seg = kcalloc(xfer->segs, sizeof(xfer->seg[0]), GFP_ATOMIC);
@@ -733,18 +1116,35 @@ static int __wa_xfer_setup_segs(struct wa_xfer *xfer, size_t xfer_hdr_size)
733 goto error_segs_kzalloc; 1116 goto error_segs_kzalloc;
734 buf_itr = 0; 1117 buf_itr = 0;
735 buf_size = xfer->urb->transfer_buffer_length; 1118 buf_size = xfer->urb->transfer_buffer_length;
1119 iso_frame_offset = 0;
736 for (cnt = 0; cnt < xfer->segs; cnt++) { 1120 for (cnt = 0; cnt < xfer->segs; cnt++) {
737 seg = xfer->seg[cnt] = kmalloc(alloc_size, GFP_ATOMIC); 1121 size_t iso_pkt_descr_size = 0;
1122 int seg_isoc_frame_count = 0, seg_isoc_size = 0;
1123
1124 if (usb_pipeisoc(xfer->urb->pipe)) {
1125 seg_isoc_frame_count =
1126 __wa_seg_calculate_isoc_frame_count(xfer,
1127 xfer_isoc_frame_offset, &seg_isoc_size);
1128
1129 iso_pkt_descr_size =
1130 sizeof(struct wa_xfer_packet_info_hwaiso) +
1131 (seg_isoc_frame_count * sizeof(__le16));
1132 }
1133 seg = xfer->seg[cnt] = kmalloc(alloc_size + iso_pkt_descr_size,
1134 GFP_ATOMIC);
738 if (seg == NULL) 1135 if (seg == NULL)
739 goto error_seg_kmalloc; 1136 goto error_seg_kmalloc;
740 wa_seg_init(seg); 1137 wa_seg_init(seg);
741 seg->xfer = xfer; 1138 seg->xfer = xfer;
742 seg->index = cnt; 1139 seg->index = cnt;
743 usb_fill_bulk_urb(&seg->urb, usb_dev, 1140 seg->isoc_frame_count = seg_isoc_frame_count;
1141 seg->isoc_frame_offset = xfer_isoc_frame_offset;
1142 seg->isoc_size = seg_isoc_size;
1143 usb_fill_bulk_urb(&seg->tr_urb, usb_dev,
744 usb_sndbulkpipe(usb_dev, 1144 usb_sndbulkpipe(usb_dev,
745 dto_epd->bEndpointAddress), 1145 dto_epd->bEndpointAddress),
746 &seg->xfer_hdr, xfer_hdr_size, 1146 &seg->xfer_hdr, xfer_hdr_size,
747 wa_seg_cb, seg); 1147 wa_seg_tr_cb, seg);
748 buf_itr_size = min(buf_size, xfer->seg_size); 1148 buf_itr_size = min(buf_size, xfer->seg_size);
749 if (xfer->is_inbound == 0 && buf_size > 0) { 1149 if (xfer->is_inbound == 0 && buf_size > 0) {
750 /* outbound data. */ 1150 /* outbound data. */
@@ -756,69 +1156,64 @@ static int __wa_xfer_setup_segs(struct wa_xfer *xfer, size_t xfer_hdr_size)
756 usb_sndbulkpipe(usb_dev, 1156 usb_sndbulkpipe(usb_dev,
757 dto_epd->bEndpointAddress), 1157 dto_epd->bEndpointAddress),
758 NULL, 0, wa_seg_dto_cb, seg); 1158 NULL, 0, wa_seg_dto_cb, seg);
759 if (xfer->is_dma) { 1159
760 seg->dto_urb->transfer_dma = 1160 if (usb_pipeisoc(xfer->urb->pipe)) {
761 xfer->urb->transfer_dma + buf_itr; 1161 /* iso packet descriptor. */
762 seg->dto_urb->transfer_flags |= 1162 seg->isoc_pack_desc_urb =
763 URB_NO_TRANSFER_DMA_MAP; 1163 usb_alloc_urb(0, GFP_ATOMIC);
764 seg->dto_urb->transfer_buffer = NULL; 1164 if (seg->isoc_pack_desc_urb == NULL)
765 seg->dto_urb->sg = NULL; 1165 goto error_iso_pack_desc_alloc;
766 seg->dto_urb->num_sgs = 0; 1166 /*
1167 * The buffer for the isoc packet descriptor
1168 * after the transfer request header in the
1169 * segment object memory buffer.
1170 */
1171 usb_fill_bulk_urb(
1172 seg->isoc_pack_desc_urb, usb_dev,
1173 usb_sndbulkpipe(usb_dev,
1174 dto_epd->bEndpointAddress),
1175 (void *)(&seg->xfer_hdr) +
1176 xfer_hdr_size,
1177 iso_pkt_descr_size,
1178 wa_seg_iso_pack_desc_cb, seg);
1179
1180 /*
1181 * Fill in the xfer buffer information for the
1182 * first isoc frame. Subsequent frames in this
1183 * segment will be filled in and sent from the
1184 * DTO completion routine, if needed.
1185 */
1186 __wa_populate_dto_urb_isoc(xfer, seg,
1187 xfer_isoc_frame_offset);
1188 /* adjust starting frame offset for next seg. */
1189 xfer_isoc_frame_offset += seg_isoc_frame_count;
767 } else { 1190 } else {
768 /* do buffer or SG processing. */ 1191 /* fill in the xfer buffer information. */
769 seg->dto_urb->transfer_flags &= 1192 result = __wa_populate_dto_urb(xfer, seg,
770 ~URB_NO_TRANSFER_DMA_MAP; 1193 buf_itr, buf_itr_size);
771 /* this should always be 0 before a resubmit. */ 1194 if (result < 0)
772 seg->dto_urb->num_mapped_sgs = 0; 1195 goto error_seg_outbound_populate;
773 1196
774 if (xfer->urb->transfer_buffer) { 1197 buf_itr += buf_itr_size;
775 seg->dto_urb->transfer_buffer = 1198 buf_size -= buf_itr_size;
776 xfer->urb->transfer_buffer +
777 buf_itr;
778 seg->dto_urb->sg = NULL;
779 seg->dto_urb->num_sgs = 0;
780 } else {
781 /* allocate an SG list to store seg_size
782 bytes and copy the subset of the
783 xfer->urb->sg that matches the
784 buffer subset we are about to read.
785 */
786 seg->dto_urb->sg =
787 wa_xfer_create_subset_sg(
788 xfer->urb->sg,
789 buf_itr, buf_itr_size,
790 &(seg->dto_urb->num_sgs));
791
792 if (!(seg->dto_urb->sg)) {
793 seg->dto_urb->num_sgs = 0;
794 goto error_sg_alloc;
795 }
796
797 seg->dto_urb->transfer_buffer = NULL;
798 }
799 } 1199 }
800 seg->dto_urb->transfer_buffer_length = buf_itr_size;
801 } 1200 }
802 seg->status = WA_SEG_READY; 1201 seg->status = WA_SEG_READY;
803 buf_itr += buf_itr_size;
804 buf_size -= buf_itr_size;
805 } 1202 }
806 return 0; 1203 return 0;
807 1204
808error_sg_alloc: 1205 /*
1206 * Free the memory for the current segment which failed to init.
1207 * Use the fact that cnt is left at were it failed. The remaining
1208 * segments will be cleaned up by wa_xfer_destroy.
1209 */
1210error_iso_pack_desc_alloc:
1211error_seg_outbound_populate:
809 usb_free_urb(xfer->seg[cnt]->dto_urb); 1212 usb_free_urb(xfer->seg[cnt]->dto_urb);
810error_dto_alloc: 1213error_dto_alloc:
811 kfree(xfer->seg[cnt]); 1214 kfree(xfer->seg[cnt]);
812 cnt--; 1215 xfer->seg[cnt] = NULL;
813error_seg_kmalloc: 1216error_seg_kmalloc:
814 /* use the fact that cnt is left at were it failed */
815 for (; cnt >= 0; cnt--) {
816 if (xfer->seg[cnt] && xfer->is_inbound == 0) {
817 usb_free_urb(xfer->seg[cnt]->dto_urb);
818 kfree(xfer->seg[cnt]->dto_urb->sg);
819 }
820 kfree(xfer->seg[cnt]);
821 }
822error_segs_kzalloc: 1217error_segs_kzalloc:
823 return result; 1218 return result;
824} 1219}
@@ -856,21 +1251,45 @@ static int __wa_xfer_setup(struct wa_xfer *xfer, struct urb *urb)
856 wa_xfer_id_init(xfer); 1251 wa_xfer_id_init(xfer);
857 __wa_xfer_setup_hdr0(xfer, xfer_hdr0, xfer_type, xfer_hdr_size); 1252 __wa_xfer_setup_hdr0(xfer, xfer_hdr0, xfer_type, xfer_hdr_size);
858 1253
859 /* Fill remainig headers */ 1254 /* Fill remaining headers */
860 xfer_hdr = xfer_hdr0; 1255 xfer_hdr = xfer_hdr0;
861 transfer_size = urb->transfer_buffer_length; 1256 if (xfer_type == WA_XFER_TYPE_ISO) {
862 xfer_hdr0->dwTransferLength = transfer_size > xfer->seg_size ? 1257 xfer_hdr0->dwTransferLength =
863 xfer->seg_size : transfer_size; 1258 cpu_to_le32(xfer->seg[0]->isoc_size);
864 transfer_size -= xfer->seg_size; 1259 for (cnt = 1; cnt < xfer->segs; cnt++) {
865 for (cnt = 1; cnt < xfer->segs; cnt++) { 1260 struct wa_xfer_packet_info_hwaiso *packet_desc;
866 xfer_hdr = &xfer->seg[cnt]->xfer_hdr; 1261 struct wa_seg *seg = xfer->seg[cnt];
867 memcpy(xfer_hdr, xfer_hdr0, xfer_hdr_size); 1262
868 xfer_hdr->bTransferSegment = cnt; 1263 xfer_hdr = &seg->xfer_hdr;
869 xfer_hdr->dwTransferLength = transfer_size > xfer->seg_size ? 1264 packet_desc = ((void *)xfer_hdr) + xfer_hdr_size;
870 cpu_to_le32(xfer->seg_size) 1265 /*
871 : cpu_to_le32(transfer_size); 1266 * Copy values from the 0th header. Segment specific
872 xfer->seg[cnt]->status = WA_SEG_READY; 1267 * values are set below.
1268 */
1269 memcpy(xfer_hdr, xfer_hdr0, xfer_hdr_size);
1270 xfer_hdr->bTransferSegment = cnt;
1271 xfer_hdr->dwTransferLength =
1272 cpu_to_le32(seg->isoc_size);
1273 __wa_setup_isoc_packet_descr(packet_desc, xfer, seg);
1274 seg->status = WA_SEG_READY;
1275 }
1276 } else {
1277 transfer_size = urb->transfer_buffer_length;
1278 xfer_hdr0->dwTransferLength = transfer_size > xfer->seg_size ?
1279 cpu_to_le32(xfer->seg_size) :
1280 cpu_to_le32(transfer_size);
873 transfer_size -= xfer->seg_size; 1281 transfer_size -= xfer->seg_size;
1282 for (cnt = 1; cnt < xfer->segs; cnt++) {
1283 xfer_hdr = &xfer->seg[cnt]->xfer_hdr;
1284 memcpy(xfer_hdr, xfer_hdr0, xfer_hdr_size);
1285 xfer_hdr->bTransferSegment = cnt;
1286 xfer_hdr->dwTransferLength =
1287 transfer_size > xfer->seg_size ?
1288 cpu_to_le32(xfer->seg_size)
1289 : cpu_to_le32(transfer_size);
1290 xfer->seg[cnt]->status = WA_SEG_READY;
1291 transfer_size -= xfer->seg_size;
1292 }
874 } 1293 }
875 xfer_hdr->bTransferSegment |= 0x80; /* this is the last segment */ 1294 xfer_hdr->bTransferSegment |= 0x80; /* this is the last segment */
876 result = 0; 1295 result = 0;
@@ -885,20 +1304,46 @@ error_setup_sizes:
885 * rpipe->seg_lock is held! 1304 * rpipe->seg_lock is held!
886 */ 1305 */
887static int __wa_seg_submit(struct wa_rpipe *rpipe, struct wa_xfer *xfer, 1306static int __wa_seg_submit(struct wa_rpipe *rpipe, struct wa_xfer *xfer,
888 struct wa_seg *seg) 1307 struct wa_seg *seg, int *dto_done)
889{ 1308{
890 int result; 1309 int result;
891 result = usb_submit_urb(&seg->urb, GFP_ATOMIC); 1310
1311 /* default to done unless we encounter a multi-frame isoc segment. */
1312 *dto_done = 1;
1313
1314 /* submit the transfer request. */
1315 result = usb_submit_urb(&seg->tr_urb, GFP_ATOMIC);
892 if (result < 0) { 1316 if (result < 0) {
893 printk(KERN_ERR "xfer %p#%u: REQ submit failed: %d\n", 1317 pr_err("%s: xfer %p#%u: REQ submit failed: %d\n",
894 xfer, seg->index, result); 1318 __func__, xfer, seg->index, result);
895 goto error_seg_submit; 1319 goto error_seg_submit;
896 } 1320 }
1321 /* submit the isoc packet descriptor if present. */
1322 if (seg->isoc_pack_desc_urb) {
1323 struct wahc *wa = xfer->wa;
1324
1325 result = usb_submit_urb(seg->isoc_pack_desc_urb, GFP_ATOMIC);
1326 if (result < 0) {
1327 pr_err("%s: xfer %p#%u: ISO packet descriptor submit failed: %d\n",
1328 __func__, xfer, seg->index, result);
1329 goto error_iso_pack_desc_submit;
1330 }
1331 xfer->dto_isoc_frame_index = 0;
1332 /*
1333 * If this segment contains more than one isoc frame, hold
1334 * onto the dto resource until we send all frames.
1335 * Only applies to non-Alereon devices.
1336 */
1337 if (((wa->quirks & WUSB_QUIRK_ALEREON_HWA_CONCAT_ISOC) == 0)
1338 && (seg->isoc_frame_count > 1))
1339 *dto_done = 0;
1340 }
1341 /* submit the out data if this is an out request. */
897 if (seg->dto_urb) { 1342 if (seg->dto_urb) {
898 result = usb_submit_urb(seg->dto_urb, GFP_ATOMIC); 1343 result = usb_submit_urb(seg->dto_urb, GFP_ATOMIC);
899 if (result < 0) { 1344 if (result < 0) {
900 printk(KERN_ERR "xfer %p#%u: DTO submit failed: %d\n", 1345 pr_err("%s: xfer %p#%u: DTO submit failed: %d\n",
901 xfer, seg->index, result); 1346 __func__, xfer, seg->index, result);
902 goto error_dto_submit; 1347 goto error_dto_submit;
903 } 1348 }
904 } 1349 }
@@ -907,38 +1352,48 @@ static int __wa_seg_submit(struct wa_rpipe *rpipe, struct wa_xfer *xfer,
907 return 0; 1352 return 0;
908 1353
909error_dto_submit: 1354error_dto_submit:
910 usb_unlink_urb(&seg->urb); 1355 usb_unlink_urb(seg->isoc_pack_desc_urb);
1356error_iso_pack_desc_submit:
1357 usb_unlink_urb(&seg->tr_urb);
911error_seg_submit: 1358error_seg_submit:
912 seg->status = WA_SEG_ERROR; 1359 seg->status = WA_SEG_ERROR;
913 seg->result = result; 1360 seg->result = result;
1361 *dto_done = 1;
914 return result; 1362 return result;
915} 1363}
916 1364
917/* 1365/*
918 * Execute more queued request segments until the maximum concurrent allowed 1366 * Execute more queued request segments until the maximum concurrent allowed.
1367 * Return true if the DTO resource was acquired and released.
919 * 1368 *
920 * The ugly unlock/lock sequence on the error path is needed as the 1369 * The ugly unlock/lock sequence on the error path is needed as the
921 * xfer->lock normally nests the seg_lock and not viceversa. 1370 * xfer->lock normally nests the seg_lock and not viceversa.
922 *
923 */ 1371 */
924static void wa_xfer_delayed_run(struct wa_rpipe *rpipe) 1372static int __wa_xfer_delayed_run(struct wa_rpipe *rpipe, int *dto_waiting)
925{ 1373{
926 int result; 1374 int result, dto_acquired = 0, dto_done = 0;
927 struct device *dev = &rpipe->wa->usb_iface->dev; 1375 struct device *dev = &rpipe->wa->usb_iface->dev;
928 struct wa_seg *seg; 1376 struct wa_seg *seg;
929 struct wa_xfer *xfer; 1377 struct wa_xfer *xfer;
930 unsigned long flags; 1378 unsigned long flags;
931 1379
1380 *dto_waiting = 0;
1381
932 spin_lock_irqsave(&rpipe->seg_lock, flags); 1382 spin_lock_irqsave(&rpipe->seg_lock, flags);
933 while (atomic_read(&rpipe->segs_available) > 0 1383 while (atomic_read(&rpipe->segs_available) > 0
934 && !list_empty(&rpipe->seg_list)) { 1384 && !list_empty(&rpipe->seg_list)
1385 && (dto_acquired = __wa_dto_try_get(rpipe->wa))) {
935 seg = list_first_entry(&(rpipe->seg_list), struct wa_seg, 1386 seg = list_first_entry(&(rpipe->seg_list), struct wa_seg,
936 list_node); 1387 list_node);
937 list_del(&seg->list_node); 1388 list_del(&seg->list_node);
938 xfer = seg->xfer; 1389 xfer = seg->xfer;
939 result = __wa_seg_submit(rpipe, xfer, seg); 1390 result = __wa_seg_submit(rpipe, xfer, seg, &dto_done);
940 dev_dbg(dev, "xfer %p#%u submitted from delayed [%d segments available] %d\n", 1391 /* release the dto resource if this RPIPE is done with it. */
941 xfer, seg->index, atomic_read(&rpipe->segs_available), result); 1392 if (dto_done)
1393 __wa_dto_put(rpipe->wa);
1394 dev_dbg(dev, "xfer %p ID %08X#%u submitted from delayed [%d segments available] %d\n",
1395 xfer, wa_xfer_id(xfer), seg->index,
1396 atomic_read(&rpipe->segs_available), result);
942 if (unlikely(result < 0)) { 1397 if (unlikely(result < 0)) {
943 spin_unlock_irqrestore(&rpipe->seg_lock, flags); 1398 spin_unlock_irqrestore(&rpipe->seg_lock, flags);
944 spin_lock_irqsave(&xfer->lock, flags); 1399 spin_lock_irqsave(&xfer->lock, flags);
@@ -948,7 +1403,37 @@ static void wa_xfer_delayed_run(struct wa_rpipe *rpipe)
948 spin_lock_irqsave(&rpipe->seg_lock, flags); 1403 spin_lock_irqsave(&rpipe->seg_lock, flags);
949 } 1404 }
950 } 1405 }
1406 /*
1407 * Mark this RPIPE as waiting if dto was not acquired, there are
1408 * delayed segs and no active transfers to wake us up later.
1409 */
1410 if (!dto_acquired && !list_empty(&rpipe->seg_list)
1411 && (atomic_read(&rpipe->segs_available) ==
1412 le16_to_cpu(rpipe->descr.wRequests)))
1413 *dto_waiting = 1;
1414
951 spin_unlock_irqrestore(&rpipe->seg_lock, flags); 1415 spin_unlock_irqrestore(&rpipe->seg_lock, flags);
1416
1417 return dto_done;
1418}
1419
1420static void wa_xfer_delayed_run(struct wa_rpipe *rpipe)
1421{
1422 int dto_waiting;
1423 int dto_done = __wa_xfer_delayed_run(rpipe, &dto_waiting);
1424
1425 /*
1426 * If this RPIPE is waiting on the DTO resource, add it to the tail of
1427 * the waiting list.
1428 * Otherwise, if the WA DTO resource was acquired and released by
1429 * __wa_xfer_delayed_run, another RPIPE may have attempted to acquire
1430 * DTO and failed during that time. Check the delayed list and process
1431 * any waiters. Start searching from the next RPIPE index.
1432 */
1433 if (dto_waiting)
1434 wa_add_delayed_rpipe(rpipe->wa, rpipe);
1435 else if (dto_done)
1436 wa_check_for_delayed_rpipes(rpipe->wa);
952} 1437}
953 1438
954/* 1439/*
@@ -960,7 +1445,7 @@ static void wa_xfer_delayed_run(struct wa_rpipe *rpipe)
960 */ 1445 */
961static int __wa_xfer_submit(struct wa_xfer *xfer) 1446static int __wa_xfer_submit(struct wa_xfer *xfer)
962{ 1447{
963 int result; 1448 int result, dto_acquired = 0, dto_done = 0, dto_waiting = 0;
964 struct wahc *wa = xfer->wa; 1449 struct wahc *wa = xfer->wa;
965 struct device *dev = &wa->usb_iface->dev; 1450 struct device *dev = &wa->usb_iface->dev;
966 unsigned cnt; 1451 unsigned cnt;
@@ -979,27 +1464,58 @@ static int __wa_xfer_submit(struct wa_xfer *xfer)
979 result = 0; 1464 result = 0;
980 spin_lock_irqsave(&rpipe->seg_lock, flags); 1465 spin_lock_irqsave(&rpipe->seg_lock, flags);
981 for (cnt = 0; cnt < xfer->segs; cnt++) { 1466 for (cnt = 0; cnt < xfer->segs; cnt++) {
1467 int delay_seg = 1;
1468
982 available = atomic_read(&rpipe->segs_available); 1469 available = atomic_read(&rpipe->segs_available);
983 empty = list_empty(&rpipe->seg_list); 1470 empty = list_empty(&rpipe->seg_list);
984 seg = xfer->seg[cnt]; 1471 seg = xfer->seg[cnt];
985 dev_dbg(dev, "xfer %p#%u: available %u empty %u (%s)\n", 1472 if (available && empty) {
986 xfer, cnt, available, empty, 1473 /*
987 available == 0 || !empty ? "delayed" : "submitted"); 1474 * Only attempt to acquire DTO if we have a segment
988 if (available == 0 || !empty) { 1475 * to send.
989 dev_dbg(dev, "xfer %p#%u: delayed\n", xfer, cnt); 1476 */
1477 dto_acquired = __wa_dto_try_get(rpipe->wa);
1478 if (dto_acquired) {
1479 delay_seg = 0;
1480 result = __wa_seg_submit(rpipe, xfer, seg,
1481 &dto_done);
1482 dev_dbg(dev, "xfer %p ID 0x%08X#%u: available %u empty %u submitted\n",
1483 xfer, wa_xfer_id(xfer), cnt, available,
1484 empty);
1485 if (dto_done)
1486 __wa_dto_put(rpipe->wa);
1487
1488 if (result < 0) {
1489 __wa_xfer_abort(xfer);
1490 goto error_seg_submit;
1491 }
1492 }
1493 }
1494
1495 if (delay_seg) {
1496 dev_dbg(dev, "xfer %p ID 0x%08X#%u: available %u empty %u delayed\n",
1497 xfer, wa_xfer_id(xfer), cnt, available, empty);
990 seg->status = WA_SEG_DELAYED; 1498 seg->status = WA_SEG_DELAYED;
991 list_add_tail(&seg->list_node, &rpipe->seg_list); 1499 list_add_tail(&seg->list_node, &rpipe->seg_list);
992 } else {
993 result = __wa_seg_submit(rpipe, xfer, seg);
994 if (result < 0) {
995 __wa_xfer_abort(xfer);
996 goto error_seg_submit;
997 }
998 } 1500 }
999 xfer->segs_submitted++; 1501 xfer->segs_submitted++;
1000 } 1502 }
1001error_seg_submit: 1503error_seg_submit:
1504 /*
1505 * Mark this RPIPE as waiting if dto was not acquired, there are
1506 * delayed segs and no active transfers to wake us up later.
1507 */
1508 if (!dto_acquired && !list_empty(&rpipe->seg_list)
1509 && (atomic_read(&rpipe->segs_available) ==
1510 le16_to_cpu(rpipe->descr.wRequests)))
1511 dto_waiting = 1;
1002 spin_unlock_irqrestore(&rpipe->seg_lock, flags); 1512 spin_unlock_irqrestore(&rpipe->seg_lock, flags);
1513
1514 if (dto_waiting)
1515 wa_add_delayed_rpipe(rpipe->wa, rpipe);
1516 else if (dto_done)
1517 wa_check_for_delayed_rpipes(rpipe->wa);
1518
1003 return result; 1519 return result;
1004} 1520}
1005 1521
@@ -1025,7 +1541,7 @@ error_seg_submit:
1025 * result never kicks in, the xfer will timeout from the USB code and 1541 * result never kicks in, the xfer will timeout from the USB code and
1026 * dequeue() will be called. 1542 * dequeue() will be called.
1027 */ 1543 */
1028static void wa_urb_enqueue_b(struct wa_xfer *xfer) 1544static int wa_urb_enqueue_b(struct wa_xfer *xfer)
1029{ 1545{
1030 int result; 1546 int result;
1031 unsigned long flags; 1547 unsigned long flags;
@@ -1036,18 +1552,22 @@ static void wa_urb_enqueue_b(struct wa_xfer *xfer)
1036 unsigned done; 1552 unsigned done;
1037 1553
1038 result = rpipe_get_by_ep(wa, xfer->ep, urb, xfer->gfp); 1554 result = rpipe_get_by_ep(wa, xfer->ep, urb, xfer->gfp);
1039 if (result < 0) 1555 if (result < 0) {
1556 pr_err("%s: error_rpipe_get\n", __func__);
1040 goto error_rpipe_get; 1557 goto error_rpipe_get;
1558 }
1041 result = -ENODEV; 1559 result = -ENODEV;
1042 /* FIXME: segmentation broken -- kills DWA */ 1560 /* FIXME: segmentation broken -- kills DWA */
1043 mutex_lock(&wusbhc->mutex); /* get a WUSB dev */ 1561 mutex_lock(&wusbhc->mutex); /* get a WUSB dev */
1044 if (urb->dev == NULL) { 1562 if (urb->dev == NULL) {
1045 mutex_unlock(&wusbhc->mutex); 1563 mutex_unlock(&wusbhc->mutex);
1564 pr_err("%s: error usb dev gone\n", __func__);
1046 goto error_dev_gone; 1565 goto error_dev_gone;
1047 } 1566 }
1048 wusb_dev = __wusb_dev_get_by_usb_dev(wusbhc, urb->dev); 1567 wusb_dev = __wusb_dev_get_by_usb_dev(wusbhc, urb->dev);
1049 if (wusb_dev == NULL) { 1568 if (wusb_dev == NULL) {
1050 mutex_unlock(&wusbhc->mutex); 1569 mutex_unlock(&wusbhc->mutex);
1570 pr_err("%s: error wusb dev gone\n", __func__);
1051 goto error_dev_gone; 1571 goto error_dev_gone;
1052 } 1572 }
1053 mutex_unlock(&wusbhc->mutex); 1573 mutex_unlock(&wusbhc->mutex);
@@ -1055,21 +1575,28 @@ static void wa_urb_enqueue_b(struct wa_xfer *xfer)
1055 spin_lock_irqsave(&xfer->lock, flags); 1575 spin_lock_irqsave(&xfer->lock, flags);
1056 xfer->wusb_dev = wusb_dev; 1576 xfer->wusb_dev = wusb_dev;
1057 result = urb->status; 1577 result = urb->status;
1058 if (urb->status != -EINPROGRESS) 1578 if (urb->status != -EINPROGRESS) {
1579 pr_err("%s: error_dequeued\n", __func__);
1059 goto error_dequeued; 1580 goto error_dequeued;
1581 }
1060 1582
1061 result = __wa_xfer_setup(xfer, urb); 1583 result = __wa_xfer_setup(xfer, urb);
1062 if (result < 0) 1584 if (result < 0) {
1585 pr_err("%s: error_xfer_setup\n", __func__);
1063 goto error_xfer_setup; 1586 goto error_xfer_setup;
1587 }
1064 result = __wa_xfer_submit(xfer); 1588 result = __wa_xfer_submit(xfer);
1065 if (result < 0) 1589 if (result < 0) {
1590 pr_err("%s: error_xfer_submit\n", __func__);
1066 goto error_xfer_submit; 1591 goto error_xfer_submit;
1592 }
1067 spin_unlock_irqrestore(&xfer->lock, flags); 1593 spin_unlock_irqrestore(&xfer->lock, flags);
1068 return; 1594 return 0;
1069 1595
1070 /* this is basically wa_xfer_completion() broken up wa_xfer_giveback() 1596 /*
1071 * does a wa_xfer_put() that will call wa_xfer_destroy() and clean 1597 * this is basically wa_xfer_completion() broken up wa_xfer_giveback()
1072 * upundo setup(). 1598 * does a wa_xfer_put() that will call wa_xfer_destroy() and undo
1599 * setup().
1073 */ 1600 */
1074error_xfer_setup: 1601error_xfer_setup:
1075error_dequeued: 1602error_dequeued:
@@ -1081,8 +1608,7 @@ error_dev_gone:
1081 rpipe_put(xfer->ep->hcpriv); 1608 rpipe_put(xfer->ep->hcpriv);
1082error_rpipe_get: 1609error_rpipe_get:
1083 xfer->result = result; 1610 xfer->result = result;
1084 wa_xfer_giveback(xfer); 1611 return result;
1085 return;
1086 1612
1087error_xfer_submit: 1613error_xfer_submit:
1088 done = __wa_xfer_is_done(xfer); 1614 done = __wa_xfer_is_done(xfer);
@@ -1090,6 +1616,8 @@ error_xfer_submit:
1090 spin_unlock_irqrestore(&xfer->lock, flags); 1616 spin_unlock_irqrestore(&xfer->lock, flags);
1091 if (done) 1617 if (done)
1092 wa_xfer_completion(xfer); 1618 wa_xfer_completion(xfer);
1619 /* return success since the completion routine will run. */
1620 return 0;
1093} 1621}
1094 1622
1095/* 1623/*
@@ -1123,7 +1651,8 @@ void wa_urb_enqueue_run(struct work_struct *ws)
1123 list_del_init(&xfer->list_node); 1651 list_del_init(&xfer->list_node);
1124 1652
1125 urb = xfer->urb; 1653 urb = xfer->urb;
1126 wa_urb_enqueue_b(xfer); 1654 if (wa_urb_enqueue_b(xfer) < 0)
1655 wa_xfer_giveback(xfer);
1127 usb_put_urb(urb); /* taken when queuing */ 1656 usb_put_urb(urb); /* taken when queuing */
1128 } 1657 }
1129} 1658}
@@ -1229,7 +1758,19 @@ int wa_urb_enqueue(struct wahc *wa, struct usb_host_endpoint *ep,
1229 spin_unlock_irqrestore(&wa->xfer_list_lock, my_flags); 1758 spin_unlock_irqrestore(&wa->xfer_list_lock, my_flags);
1230 queue_work(wusbd, &wa->xfer_enqueue_work); 1759 queue_work(wusbd, &wa->xfer_enqueue_work);
1231 } else { 1760 } else {
1232 wa_urb_enqueue_b(xfer); 1761 result = wa_urb_enqueue_b(xfer);
1762 if (result < 0) {
1763 /*
1764 * URB submit/enqueue failed. Clean up, return an
1765 * error and do not run the callback. This avoids
1766 * an infinite submit/complete loop.
1767 */
1768 dev_err(dev, "%s: URB enqueue failed: %d\n",
1769 __func__, result);
1770 wa_put(xfer->wa);
1771 wa_xfer_put(xfer);
1772 return result;
1773 }
1233 } 1774 }
1234 return 0; 1775 return 0;
1235 1776
@@ -1264,7 +1805,7 @@ int wa_urb_dequeue(struct wahc *wa, struct urb *urb)
1264 struct wa_xfer *xfer; 1805 struct wa_xfer *xfer;
1265 struct wa_seg *seg; 1806 struct wa_seg *seg;
1266 struct wa_rpipe *rpipe; 1807 struct wa_rpipe *rpipe;
1267 unsigned cnt; 1808 unsigned cnt, done = 0, xfer_abort_pending;
1268 unsigned rpipe_ready = 0; 1809 unsigned rpipe_ready = 0;
1269 1810
1270 xfer = urb->hcpriv; 1811 xfer = urb->hcpriv;
@@ -1278,6 +1819,7 @@ int wa_urb_dequeue(struct wahc *wa, struct urb *urb)
1278 goto out; 1819 goto out;
1279 } 1820 }
1280 spin_lock_irqsave(&xfer->lock, flags); 1821 spin_lock_irqsave(&xfer->lock, flags);
1822 pr_debug("%s: DEQUEUE xfer id 0x%08X\n", __func__, wa_xfer_id(xfer));
1281 rpipe = xfer->ep->hcpriv; 1823 rpipe = xfer->ep->hcpriv;
1282 if (rpipe == NULL) { 1824 if (rpipe == NULL) {
1283 pr_debug("%s: xfer id 0x%08X has no RPIPE. %s", 1825 pr_debug("%s: xfer id 0x%08X has no RPIPE. %s",
@@ -1293,9 +1835,11 @@ int wa_urb_dequeue(struct wahc *wa, struct urb *urb)
1293 if (xfer->seg == NULL) /* still hasn't reached */ 1835 if (xfer->seg == NULL) /* still hasn't reached */
1294 goto out_unlock; /* setup(), enqueue_b() completes */ 1836 goto out_unlock; /* setup(), enqueue_b() completes */
1295 /* Ok, the xfer is in flight already, it's been setup and submitted.*/ 1837 /* Ok, the xfer is in flight already, it's been setup and submitted.*/
1296 __wa_xfer_abort(xfer); 1838 xfer_abort_pending = __wa_xfer_abort(xfer) >= 0;
1297 for (cnt = 0; cnt < xfer->segs; cnt++) { 1839 for (cnt = 0; cnt < xfer->segs; cnt++) {
1298 seg = xfer->seg[cnt]; 1840 seg = xfer->seg[cnt];
1841 pr_debug("%s: xfer id 0x%08X#%d status = %d\n",
1842 __func__, wa_xfer_id(xfer), cnt, seg->status);
1299 switch (seg->status) { 1843 switch (seg->status) {
1300 case WA_SEG_NOTREADY: 1844 case WA_SEG_NOTREADY:
1301 case WA_SEG_READY: 1845 case WA_SEG_READY:
@@ -1304,42 +1848,50 @@ int wa_urb_dequeue(struct wahc *wa, struct urb *urb)
1304 WARN_ON(1); 1848 WARN_ON(1);
1305 break; 1849 break;
1306 case WA_SEG_DELAYED: 1850 case WA_SEG_DELAYED:
1851 /*
1852 * delete from rpipe delayed list. If no segments on
1853 * this xfer have been submitted, __wa_xfer_is_done will
1854 * trigger a giveback below. Otherwise, the submitted
1855 * segments will be completed in the DTI interrupt.
1856 */
1307 seg->status = WA_SEG_ABORTED; 1857 seg->status = WA_SEG_ABORTED;
1308 spin_lock_irqsave(&rpipe->seg_lock, flags2); 1858 spin_lock_irqsave(&rpipe->seg_lock, flags2);
1309 list_del(&seg->list_node); 1859 list_del(&seg->list_node);
1310 xfer->segs_done++; 1860 xfer->segs_done++;
1311 rpipe_ready = rpipe_avail_inc(rpipe);
1312 spin_unlock_irqrestore(&rpipe->seg_lock, flags2); 1861 spin_unlock_irqrestore(&rpipe->seg_lock, flags2);
1313 break; 1862 break;
1314 case WA_SEG_SUBMITTED:
1315 seg->status = WA_SEG_ABORTED;
1316 usb_unlink_urb(&seg->urb);
1317 if (xfer->is_inbound == 0)
1318 usb_unlink_urb(seg->dto_urb);
1319 xfer->segs_done++;
1320 rpipe_ready = rpipe_avail_inc(rpipe);
1321 break;
1322 case WA_SEG_PENDING:
1323 seg->status = WA_SEG_ABORTED;
1324 xfer->segs_done++;
1325 rpipe_ready = rpipe_avail_inc(rpipe);
1326 break;
1327 case WA_SEG_DTI_PENDING:
1328 usb_unlink_urb(wa->dti_urb);
1329 seg->status = WA_SEG_ABORTED;
1330 xfer->segs_done++;
1331 rpipe_ready = rpipe_avail_inc(rpipe);
1332 break;
1333 case WA_SEG_DONE: 1863 case WA_SEG_DONE:
1334 case WA_SEG_ERROR: 1864 case WA_SEG_ERROR:
1335 case WA_SEG_ABORTED: 1865 case WA_SEG_ABORTED:
1336 break; 1866 break;
1867 /*
1868 * In the states below, the HWA device already knows
1869 * about the transfer. If an abort request was sent,
1870 * allow the HWA to process it and wait for the
1871 * results. Otherwise, the DTI state and seg completed
1872 * counts can get out of sync.
1873 */
1874 case WA_SEG_SUBMITTED:
1875 case WA_SEG_PENDING:
1876 case WA_SEG_DTI_PENDING:
1877 /*
1878 * Check if the abort was successfully sent. This could
1879 * be false if the HWA has been removed but we haven't
1880 * gotten the disconnect notification yet.
1881 */
1882 if (!xfer_abort_pending) {
1883 seg->status = WA_SEG_ABORTED;
1884 rpipe_ready = rpipe_avail_inc(rpipe);
1885 xfer->segs_done++;
1886 }
1887 break;
1337 } 1888 }
1338 } 1889 }
1339 xfer->result = urb->status; /* -ENOENT or -ECONNRESET */ 1890 xfer->result = urb->status; /* -ENOENT or -ECONNRESET */
1340 __wa_xfer_is_done(xfer); 1891 done = __wa_xfer_is_done(xfer);
1341 spin_unlock_irqrestore(&xfer->lock, flags); 1892 spin_unlock_irqrestore(&xfer->lock, flags);
1342 wa_xfer_completion(xfer); 1893 if (done)
1894 wa_xfer_completion(xfer);
1343 if (rpipe_ready) 1895 if (rpipe_ready)
1344 wa_xfer_delayed_run(rpipe); 1896 wa_xfer_delayed_run(rpipe);
1345 return 0; 1897 return 0;
@@ -1410,13 +1962,56 @@ static int wa_xfer_status_to_errno(u8 status)
1410} 1962}
1411 1963
1412/* 1964/*
1965 * If a last segment flag and/or a transfer result error is encountered,
1966 * no other segment transfer results will be returned from the device.
1967 * Mark the remaining submitted or pending xfers as completed so that
1968 * the xfer will complete cleanly.
1969 */
1970static void wa_complete_remaining_xfer_segs(struct wa_xfer *xfer,
1971 struct wa_seg *incoming_seg)
1972{
1973 int index;
1974 struct wa_rpipe *rpipe = xfer->ep->hcpriv;
1975
1976 for (index = incoming_seg->index + 1; index < xfer->segs_submitted;
1977 index++) {
1978 struct wa_seg *current_seg = xfer->seg[index];
1979
1980 BUG_ON(current_seg == NULL);
1981
1982 switch (current_seg->status) {
1983 case WA_SEG_SUBMITTED:
1984 case WA_SEG_PENDING:
1985 case WA_SEG_DTI_PENDING:
1986 rpipe_avail_inc(rpipe);
1987 /*
1988 * do not increment RPIPE avail for the WA_SEG_DELAYED case
1989 * since it has not been submitted to the RPIPE.
1990 */
1991 case WA_SEG_DELAYED:
1992 xfer->segs_done++;
1993 current_seg->status = incoming_seg->status;
1994 break;
1995 case WA_SEG_ABORTED:
1996 break;
1997 default:
1998 WARN(1, "%s: xfer 0x%08X#%d. bad seg status = %d\n",
1999 __func__, wa_xfer_id(xfer), index,
2000 current_seg->status);
2001 break;
2002 }
2003 }
2004}
2005
2006/*
1413 * Process a xfer result completion message 2007 * Process a xfer result completion message
1414 * 2008 *
1415 * inbound transfers: need to schedule a DTI read 2009 * inbound transfers: need to schedule a buf_in_urb read
1416 * 2010 *
1417 * FIXME: this function needs to be broken up in parts 2011 * FIXME: this function needs to be broken up in parts
1418 */ 2012 */
1419static void wa_xfer_result_chew(struct wahc *wa, struct wa_xfer *xfer) 2013static void wa_xfer_result_chew(struct wahc *wa, struct wa_xfer *xfer,
2014 struct wa_xfer_result *xfer_result)
1420{ 2015{
1421 int result; 2016 int result;
1422 struct device *dev = &wa->usb_iface->dev; 2017 struct device *dev = &wa->usb_iface->dev;
@@ -1424,8 +2019,7 @@ static void wa_xfer_result_chew(struct wahc *wa, struct wa_xfer *xfer)
1424 u8 seg_idx; 2019 u8 seg_idx;
1425 struct wa_seg *seg; 2020 struct wa_seg *seg;
1426 struct wa_rpipe *rpipe; 2021 struct wa_rpipe *rpipe;
1427 struct wa_xfer_result *xfer_result = wa->xfer_result; 2022 unsigned done = 0;
1428 u8 done = 0;
1429 u8 usb_status; 2023 u8 usb_status;
1430 unsigned rpipe_ready = 0; 2024 unsigned rpipe_ready = 0;
1431 2025
@@ -1436,8 +2030,8 @@ static void wa_xfer_result_chew(struct wahc *wa, struct wa_xfer *xfer)
1436 seg = xfer->seg[seg_idx]; 2030 seg = xfer->seg[seg_idx];
1437 rpipe = xfer->ep->hcpriv; 2031 rpipe = xfer->ep->hcpriv;
1438 usb_status = xfer_result->bTransferStatus; 2032 usb_status = xfer_result->bTransferStatus;
1439 dev_dbg(dev, "xfer %p#%u: bTransferStatus 0x%02x (seg status %u)\n", 2033 dev_dbg(dev, "xfer %p ID 0x%08X#%u: bTransferStatus 0x%02x (seg status %u)\n",
1440 xfer, seg_idx, usb_status, seg->status); 2034 xfer, wa_xfer_id(xfer), seg_idx, usb_status, seg->status);
1441 if (seg->status == WA_SEG_ABORTED 2035 if (seg->status == WA_SEG_ABORTED
1442 || seg->status == WA_SEG_ERROR) /* already handled */ 2036 || seg->status == WA_SEG_ERROR) /* already handled */
1443 goto segment_aborted; 2037 goto segment_aborted;
@@ -1453,12 +2047,19 @@ static void wa_xfer_result_chew(struct wahc *wa, struct wa_xfer *xfer)
1453 seg->result = wa_xfer_status_to_errno(usb_status); 2047 seg->result = wa_xfer_status_to_errno(usb_status);
1454 dev_err(dev, "DTI: xfer %p#:%08X:%u failed (0x%02x)\n", 2048 dev_err(dev, "DTI: xfer %p#:%08X:%u failed (0x%02x)\n",
1455 xfer, xfer->id, seg->index, usb_status); 2049 xfer, xfer->id, seg->index, usb_status);
2050 seg->status = ((usb_status & 0x7F) == WA_XFER_STATUS_ABORTED) ?
2051 WA_SEG_ABORTED : WA_SEG_ERROR;
1456 goto error_complete; 2052 goto error_complete;
1457 } 2053 }
1458 /* FIXME: we ignore warnings, tally them for stats */ 2054 /* FIXME: we ignore warnings, tally them for stats */
1459 if (usb_status & 0x40) /* Warning?... */ 2055 if (usb_status & 0x40) /* Warning?... */
1460 usb_status = 0; /* ... pass */ 2056 usb_status = 0; /* ... pass */
1461 if (xfer->is_inbound) { /* IN data phase: read to buffer */ 2057 if (usb_pipeisoc(xfer->urb->pipe)) {
2058 /* set up WA state to read the isoc packet status next. */
2059 wa->dti_isoc_xfer_in_progress = wa_xfer_id(xfer);
2060 wa->dti_isoc_xfer_seg = seg_idx;
2061 wa->dti_state = WA_DTI_ISOC_PACKET_STATUS_PENDING;
2062 } else if (xfer->is_inbound) { /* IN data phase: read to buffer */
1462 seg->status = WA_SEG_DTI_PENDING; 2063 seg->status = WA_SEG_DTI_PENDING;
1463 BUG_ON(wa->buf_in_urb->status == -EINPROGRESS); 2064 BUG_ON(wa->buf_in_urb->status == -EINPROGRESS);
1464 /* this should always be 0 before a resubmit. */ 2065 /* this should always be 0 before a resubmit. */
@@ -1535,12 +2136,14 @@ error_submit_buf_in:
1535 xfer, seg_idx, result); 2136 xfer, seg_idx, result);
1536 seg->result = result; 2137 seg->result = result;
1537 kfree(wa->buf_in_urb->sg); 2138 kfree(wa->buf_in_urb->sg);
2139 wa->buf_in_urb->sg = NULL;
1538error_sg_alloc: 2140error_sg_alloc:
1539 __wa_xfer_abort(xfer); 2141 __wa_xfer_abort(xfer);
1540error_complete:
1541 seg->status = WA_SEG_ERROR; 2142 seg->status = WA_SEG_ERROR;
2143error_complete:
1542 xfer->segs_done++; 2144 xfer->segs_done++;
1543 rpipe_ready = rpipe_avail_inc(rpipe); 2145 rpipe_ready = rpipe_avail_inc(rpipe);
2146 wa_complete_remaining_xfer_segs(xfer, seg);
1544 done = __wa_xfer_is_done(xfer); 2147 done = __wa_xfer_is_done(xfer);
1545 /* 2148 /*
1546 * queue work item to clear STALL for control endpoints. 2149 * queue work item to clear STALL for control endpoints.
@@ -1552,10 +2155,8 @@ error_complete:
1552 2155
1553 dev_info(dev, "Control EP stall. Queue delayed work.\n"); 2156 dev_info(dev, "Control EP stall. Queue delayed work.\n");
1554 spin_lock_irq(&wa->xfer_list_lock); 2157 spin_lock_irq(&wa->xfer_list_lock);
1555 /* remove xfer from xfer_list. */ 2158 /* move xfer from xfer_list to xfer_errored_list. */
1556 list_del(&xfer->list_node); 2159 list_move_tail(&xfer->list_node, &wa->xfer_errored_list);
1557 /* add xfer to xfer_errored_list. */
1558 list_add_tail(&xfer->list_node, &wa->xfer_errored_list);
1559 spin_unlock_irq(&wa->xfer_list_lock); 2160 spin_unlock_irq(&wa->xfer_list_lock);
1560 spin_unlock_irqrestore(&xfer->lock, flags); 2161 spin_unlock_irqrestore(&xfer->lock, flags);
1561 queue_work(wusbd, &wa->xfer_error_work); 2162 queue_work(wusbd, &wa->xfer_error_work);
@@ -1587,6 +2188,90 @@ segment_aborted:
1587} 2188}
1588 2189
1589/* 2190/*
2191 * Process a isochronous packet status message
2192 *
2193 * inbound transfers: need to schedule a buf_in_urb read
2194 */
2195static void wa_process_iso_packet_status(struct wahc *wa, struct urb *urb)
2196{
2197 struct device *dev = &wa->usb_iface->dev;
2198 struct wa_xfer_packet_status_hwaiso *packet_status;
2199 struct wa_xfer_packet_status_len_hwaiso *status_array;
2200 struct wa_xfer *xfer;
2201 unsigned long flags;
2202 struct wa_seg *seg;
2203 struct wa_rpipe *rpipe;
2204 unsigned done = 0;
2205 unsigned rpipe_ready = 0, seg_index;
2206 int expected_size;
2207
2208 /* We have a xfer result buffer; check it */
2209 dev_dbg(dev, "DTI: isoc packet status %d bytes at %p\n",
2210 urb->actual_length, urb->transfer_buffer);
2211 packet_status = (struct wa_xfer_packet_status_hwaiso *)(wa->dti_buf);
2212 if (packet_status->bPacketType != WA_XFER_ISO_PACKET_STATUS) {
2213 dev_err(dev, "DTI Error: isoc packet status--bad type 0x%02x\n",
2214 packet_status->bPacketType);
2215 goto error_parse_buffer;
2216 }
2217 xfer = wa_xfer_get_by_id(wa, wa->dti_isoc_xfer_in_progress);
2218 if (xfer == NULL) {
2219 dev_err(dev, "DTI Error: isoc packet status--unknown xfer 0x%08x\n",
2220 wa->dti_isoc_xfer_in_progress);
2221 goto error_parse_buffer;
2222 }
2223 spin_lock_irqsave(&xfer->lock, flags);
2224 if (unlikely(wa->dti_isoc_xfer_seg >= xfer->segs))
2225 goto error_bad_seg;
2226 seg = xfer->seg[wa->dti_isoc_xfer_seg];
2227 rpipe = xfer->ep->hcpriv;
2228 expected_size = sizeof(*packet_status) +
2229 (sizeof(packet_status->PacketStatus[0]) *
2230 seg->isoc_frame_count);
2231 if (urb->actual_length != expected_size) {
2232 dev_err(dev, "DTI Error: isoc packet status--bad urb length (%d bytes vs %d needed)\n",
2233 urb->actual_length, expected_size);
2234 goto error_bad_seg;
2235 }
2236 if (le16_to_cpu(packet_status->wLength) != expected_size) {
2237 dev_err(dev, "DTI Error: isoc packet status--bad length %u\n",
2238 le16_to_cpu(packet_status->wLength));
2239 goto error_bad_seg;
2240 }
2241 /* isoc packet status and lengths back xfer urb. */
2242 status_array = packet_status->PacketStatus;
2243 for (seg_index = 0; seg_index < seg->isoc_frame_count; ++seg_index) {
2244 xfer->urb->iso_frame_desc[seg->index].status =
2245 wa_xfer_status_to_errno(
2246 le16_to_cpu(status_array[seg_index].PacketStatus));
2247 xfer->urb->iso_frame_desc[seg->index].actual_length =
2248 le16_to_cpu(status_array[seg_index].PacketLength);
2249 }
2250
2251 if (!xfer->is_inbound) {
2252 /* OUT transfer, complete it -- */
2253 seg->status = WA_SEG_DONE;
2254 xfer->segs_done++;
2255 rpipe_ready = rpipe_avail_inc(rpipe);
2256 done = __wa_xfer_is_done(xfer);
2257 }
2258 spin_unlock_irqrestore(&xfer->lock, flags);
2259 wa->dti_state = WA_DTI_TRANSFER_RESULT_PENDING;
2260 if (done)
2261 wa_xfer_completion(xfer);
2262 if (rpipe_ready)
2263 wa_xfer_delayed_run(rpipe);
2264 wa_xfer_put(xfer);
2265 return;
2266
2267error_bad_seg:
2268 spin_unlock_irqrestore(&xfer->lock, flags);
2269 wa_xfer_put(xfer);
2270error_parse_buffer:
2271 return;
2272}
2273
2274/*
1590 * Callback for the IN data phase 2275 * Callback for the IN data phase
1591 * 2276 *
1592 * If successful transition state; otherwise, take a note of the 2277 * If successful transition state; otherwise, take a note of the
@@ -1687,56 +2372,61 @@ static void wa_buf_in_cb(struct urb *urb)
1687 * We go back to OFF when we detect a ENOENT or ESHUTDOWN (or too many 2372 * We go back to OFF when we detect a ENOENT or ESHUTDOWN (or too many
1688 * errors) in the URBs. 2373 * errors) in the URBs.
1689 */ 2374 */
1690static void wa_xfer_result_cb(struct urb *urb) 2375static void wa_dti_cb(struct urb *urb)
1691{ 2376{
1692 int result; 2377 int result;
1693 struct wahc *wa = urb->context; 2378 struct wahc *wa = urb->context;
1694 struct device *dev = &wa->usb_iface->dev; 2379 struct device *dev = &wa->usb_iface->dev;
1695 struct wa_xfer_result *xfer_result;
1696 u32 xfer_id; 2380 u32 xfer_id;
1697 struct wa_xfer *xfer;
1698 u8 usb_status; 2381 u8 usb_status;
1699 2382
1700 BUG_ON(wa->dti_urb != urb); 2383 BUG_ON(wa->dti_urb != urb);
1701 switch (wa->dti_urb->status) { 2384 switch (wa->dti_urb->status) {
1702 case 0: 2385 case 0:
1703 /* We have a xfer result buffer; check it */ 2386 if (wa->dti_state == WA_DTI_TRANSFER_RESULT_PENDING) {
1704 dev_dbg(dev, "DTI: xfer result %d bytes at %p\n", 2387 struct wa_xfer_result *xfer_result;
1705 urb->actual_length, urb->transfer_buffer); 2388 struct wa_xfer *xfer;
1706 if (wa->dti_urb->actual_length != sizeof(*xfer_result)) { 2389
1707 dev_err(dev, "DTI Error: xfer result--bad size " 2390 /* We have a xfer result buffer; check it */
1708 "xfer result (%d bytes vs %zu needed)\n", 2391 dev_dbg(dev, "DTI: xfer result %d bytes at %p\n",
1709 urb->actual_length, sizeof(*xfer_result)); 2392 urb->actual_length, urb->transfer_buffer);
1710 break; 2393 if (urb->actual_length != sizeof(*xfer_result)) {
1711 } 2394 dev_err(dev, "DTI Error: xfer result--bad size xfer result (%d bytes vs %zu needed)\n",
1712 xfer_result = wa->xfer_result; 2395 urb->actual_length,
1713 if (xfer_result->hdr.bLength != sizeof(*xfer_result)) { 2396 sizeof(*xfer_result));
1714 dev_err(dev, "DTI Error: xfer result--" 2397 break;
1715 "bad header length %u\n", 2398 }
1716 xfer_result->hdr.bLength); 2399 xfer_result = (struct wa_xfer_result *)(wa->dti_buf);
1717 break; 2400 if (xfer_result->hdr.bLength != sizeof(*xfer_result)) {
1718 } 2401 dev_err(dev, "DTI Error: xfer result--bad header length %u\n",
1719 if (xfer_result->hdr.bNotifyType != WA_XFER_RESULT) { 2402 xfer_result->hdr.bLength);
1720 dev_err(dev, "DTI Error: xfer result--" 2403 break;
1721 "bad header type 0x%02x\n", 2404 }
1722 xfer_result->hdr.bNotifyType); 2405 if (xfer_result->hdr.bNotifyType != WA_XFER_RESULT) {
1723 break; 2406 dev_err(dev, "DTI Error: xfer result--bad header type 0x%02x\n",
1724 } 2407 xfer_result->hdr.bNotifyType);
1725 usb_status = xfer_result->bTransferStatus & 0x3f; 2408 break;
1726 if (usb_status == WA_XFER_STATUS_NOT_FOUND) 2409 }
1727 /* taken care of already */ 2410 usb_status = xfer_result->bTransferStatus & 0x3f;
1728 break; 2411 if (usb_status == WA_XFER_STATUS_NOT_FOUND)
1729 xfer_id = xfer_result->dwTransferID; 2412 /* taken care of already */
1730 xfer = wa_xfer_get_by_id(wa, xfer_id); 2413 break;
1731 if (xfer == NULL) { 2414 xfer_id = le32_to_cpu(xfer_result->dwTransferID);
1732 /* FIXME: transaction might have been cancelled */ 2415 xfer = wa_xfer_get_by_id(wa, xfer_id);
1733 dev_err(dev, "DTI Error: xfer result--" 2416 if (xfer == NULL) {
1734 "unknown xfer 0x%08x (status 0x%02x)\n", 2417 /* FIXME: transaction not found. */
1735 xfer_id, usb_status); 2418 dev_err(dev, "DTI Error: xfer result--unknown xfer 0x%08x (status 0x%02x)\n",
1736 break; 2419 xfer_id, usb_status);
2420 break;
2421 }
2422 wa_xfer_result_chew(wa, xfer, xfer_result);
2423 wa_xfer_put(xfer);
2424 } else if (wa->dti_state == WA_DTI_ISOC_PACKET_STATUS_PENDING) {
2425 wa_process_iso_packet_status(wa, urb);
2426 } else {
2427 dev_err(dev, "DTI Error: unexpected EP state = %d\n",
2428 wa->dti_state);
1737 } 2429 }
1738 wa_xfer_result_chew(wa, xfer);
1739 wa_xfer_put(xfer);
1740 break; 2430 break;
1741 case -ENOENT: /* (we killed the URB)...so, no broadcast */ 2431 case -ENOENT: /* (we killed the URB)...so, no broadcast */
1742 case -ESHUTDOWN: /* going away! */ 2432 case -ESHUTDOWN: /* going away! */
@@ -1777,7 +2467,7 @@ out:
1777 * don't really set it up and start it until the first xfer complete 2467 * don't really set it up and start it until the first xfer complete
1778 * notification arrives, which is what we do here. 2468 * notification arrives, which is what we do here.
1779 * 2469 *
1780 * Follow up in wa_xfer_result_cb(), as that's where the whole state 2470 * Follow up in wa_dti_cb(), as that's where the whole state
1781 * machine starts. 2471 * machine starts.
1782 * 2472 *
1783 * So here we just initialize the DTI URB for reading transfer result 2473 * So here we just initialize the DTI URB for reading transfer result
@@ -1813,8 +2503,8 @@ void wa_handle_notif_xfer(struct wahc *wa, struct wa_notif_hdr *notif_hdr)
1813 usb_fill_bulk_urb( 2503 usb_fill_bulk_urb(
1814 wa->dti_urb, wa->usb_dev, 2504 wa->dti_urb, wa->usb_dev,
1815 usb_rcvbulkpipe(wa->usb_dev, 0x80 | notif_xfer->bEndpoint), 2505 usb_rcvbulkpipe(wa->usb_dev, 0x80 | notif_xfer->bEndpoint),
1816 wa->xfer_result, wa->xfer_result_size, 2506 wa->dti_buf, wa->dti_buf_size,
1817 wa_xfer_result_cb, wa); 2507 wa_dti_cb, wa);
1818 2508
1819 wa->buf_in_urb = usb_alloc_urb(0, GFP_KERNEL); 2509 wa->buf_in_urb = usb_alloc_urb(0, GFP_KERNEL);
1820 if (wa->buf_in_urb == NULL) { 2510 if (wa->buf_in_urb == NULL) {
@@ -1836,6 +2526,7 @@ out:
1836 2526
1837error_dti_urb_submit: 2527error_dti_urb_submit:
1838 usb_put_urb(wa->buf_in_urb); 2528 usb_put_urb(wa->buf_in_urb);
2529 wa->buf_in_urb = NULL;
1839error_buf_in_urb_alloc: 2530error_buf_in_urb_alloc:
1840 usb_put_urb(wa->dti_urb); 2531 usb_put_urb(wa->dti_urb);
1841 wa->dti_urb = NULL; 2532 wa->dti_urb = NULL;
diff --git a/drivers/uwb/lc-dev.c b/drivers/uwb/lc-dev.c
index 9209eafc75b1..80079b8fed15 100644
--- a/drivers/uwb/lc-dev.c
+++ b/drivers/uwb/lc-dev.c
@@ -244,7 +244,7 @@ static ssize_t uwb_dev_RSSI_store(struct device *dev,
244static DEVICE_ATTR(RSSI, S_IRUGO | S_IWUSR, uwb_dev_RSSI_show, uwb_dev_RSSI_store); 244static DEVICE_ATTR(RSSI, S_IRUGO | S_IWUSR, uwb_dev_RSSI_show, uwb_dev_RSSI_store);
245 245
246 246
247static struct attribute *dev_attrs[] = { 247static struct attribute *uwb_dev_attrs[] = {
248 &dev_attr_EUI_48.attr, 248 &dev_attr_EUI_48.attr,
249 &dev_attr_DevAddr.attr, 249 &dev_attr_DevAddr.attr,
250 &dev_attr_BPST.attr, 250 &dev_attr_BPST.attr,
@@ -253,20 +253,10 @@ static struct attribute *dev_attrs[] = {
253 &dev_attr_RSSI.attr, 253 &dev_attr_RSSI.attr,
254 NULL, 254 NULL,
255}; 255};
256 256ATTRIBUTE_GROUPS(uwb_dev);
257static struct attribute_group dev_attr_group = {
258 .attrs = dev_attrs,
259};
260
261static const struct attribute_group *groups[] = {
262 &dev_attr_group,
263 NULL,
264};
265 257
266/** 258/**
267 * Device SYSFS registration 259 * Device SYSFS registration
268 *
269 *
270 */ 260 */
271static int __uwb_dev_sys_add(struct uwb_dev *uwb_dev, struct device *parent_dev) 261static int __uwb_dev_sys_add(struct uwb_dev *uwb_dev, struct device *parent_dev)
272{ 262{
@@ -276,7 +266,7 @@ static int __uwb_dev_sys_add(struct uwb_dev *uwb_dev, struct device *parent_dev)
276 /* Device sysfs files are only useful for neighbor devices not 266 /* Device sysfs files are only useful for neighbor devices not
277 local radio controllers. */ 267 local radio controllers. */
278 if (&uwb_dev->rc->uwb_dev != uwb_dev) 268 if (&uwb_dev->rc->uwb_dev != uwb_dev)
279 dev->groups = groups; 269 dev->groups = uwb_dev_groups;
280 dev->parent = parent_dev; 270 dev->parent = parent_dev;
281 dev_set_drvdata(dev, uwb_dev); 271 dev_set_drvdata(dev, uwb_dev);
282 272
diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c
index ce5221fa393a..e663921eebb6 100644
--- a/drivers/vhost/scsi.c
+++ b/drivers/vhost/scsi.c
@@ -1056,7 +1056,7 @@ vhost_scsi_handle_vq(struct vhost_scsi *vs, struct vhost_virtqueue *vq)
1056 if (data_direction != DMA_NONE) { 1056 if (data_direction != DMA_NONE) {
1057 ret = vhost_scsi_map_iov_to_sgl(cmd, 1057 ret = vhost_scsi_map_iov_to_sgl(cmd,
1058 &vq->iov[data_first], data_num, 1058 &vq->iov[data_first], data_num,
1059 data_direction == DMA_TO_DEVICE); 1059 data_direction == DMA_FROM_DEVICE);
1060 if (unlikely(ret)) { 1060 if (unlikely(ret)) {
1061 vq_err(vq, "Failed to map iov to sgl\n"); 1061 vq_err(vq, "Failed to map iov to sgl\n");
1062 goto err_free; 1062 goto err_free;
diff --git a/drivers/video/au1100fb.c b/drivers/video/au1100fb.c
index a54ccdc4d661..22ad85242e5b 100644
--- a/drivers/video/au1100fb.c
+++ b/drivers/video/au1100fb.c
@@ -361,37 +361,13 @@ void au1100fb_fb_rotate(struct fb_info *fbi, int angle)
361int au1100fb_fb_mmap(struct fb_info *fbi, struct vm_area_struct *vma) 361int au1100fb_fb_mmap(struct fb_info *fbi, struct vm_area_struct *vma)
362{ 362{
363 struct au1100fb_device *fbdev; 363 struct au1100fb_device *fbdev;
364 unsigned int len;
365 unsigned long start=0, off;
366 364
367 fbdev = to_au1100fb_device(fbi); 365 fbdev = to_au1100fb_device(fbi);
368 366
369 if (vma->vm_pgoff > (~0UL >> PAGE_SHIFT)) {
370 return -EINVAL;
371 }
372
373 start = fbdev->fb_phys & PAGE_MASK;
374 len = PAGE_ALIGN((start & ~PAGE_MASK) + fbdev->fb_len);
375
376 off = vma->vm_pgoff << PAGE_SHIFT;
377
378 if ((vma->vm_end - vma->vm_start + off) > len) {
379 return -EINVAL;
380 }
381
382 off += start;
383 vma->vm_pgoff = off >> PAGE_SHIFT;
384
385 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); 367 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
386 pgprot_val(vma->vm_page_prot) |= (6 << 9); //CCA=6 368 pgprot_val(vma->vm_page_prot) |= (6 << 9); //CCA=6
387 369
388 if (io_remap_pfn_range(vma, vma->vm_start, off >> PAGE_SHIFT, 370 return vm_iomap_memory(vma, fbdev->fb_phys, fbdev->fb_len);
389 vma->vm_end - vma->vm_start,
390 vma->vm_page_prot)) {
391 return -EAGAIN;
392 }
393
394 return 0;
395} 371}
396 372
397static struct fb_ops au1100fb_ops = 373static struct fb_ops au1100fb_ops =
diff --git a/drivers/video/au1200fb.c b/drivers/video/au1200fb.c
index 301224ecc950..1d02897d17f2 100644
--- a/drivers/video/au1200fb.c
+++ b/drivers/video/au1200fb.c
@@ -1233,34 +1233,13 @@ static int au1200fb_fb_blank(int blank_mode, struct fb_info *fbi)
1233 * method mainly to allow the use of the TLB streaming flag (CCA=6) 1233 * method mainly to allow the use of the TLB streaming flag (CCA=6)
1234 */ 1234 */
1235static int au1200fb_fb_mmap(struct fb_info *info, struct vm_area_struct *vma) 1235static int au1200fb_fb_mmap(struct fb_info *info, struct vm_area_struct *vma)
1236
1237{ 1236{
1238 unsigned int len;
1239 unsigned long start=0, off;
1240 struct au1200fb_device *fbdev = info->par; 1237 struct au1200fb_device *fbdev = info->par;
1241 1238
1242 if (vma->vm_pgoff > (~0UL >> PAGE_SHIFT)) {
1243 return -EINVAL;
1244 }
1245
1246 start = fbdev->fb_phys & PAGE_MASK;
1247 len = PAGE_ALIGN((start & ~PAGE_MASK) + fbdev->fb_len);
1248
1249 off = vma->vm_pgoff << PAGE_SHIFT;
1250
1251 if ((vma->vm_end - vma->vm_start + off) > len) {
1252 return -EINVAL;
1253 }
1254
1255 off += start;
1256 vma->vm_pgoff = off >> PAGE_SHIFT;
1257
1258 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); 1239 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
1259 pgprot_val(vma->vm_page_prot) |= _CACHE_MASK; /* CCA=7 */ 1240 pgprot_val(vma->vm_page_prot) |= _CACHE_MASK; /* CCA=7 */
1260 1241
1261 return io_remap_pfn_range(vma, vma->vm_start, off >> PAGE_SHIFT, 1242 return vm_iomap_memory(vma, fbdev->fb_phys, fbdev->fb_len);
1262 vma->vm_end - vma->vm_start,
1263 vma->vm_page_prot);
1264} 1243}
1265 1244
1266static void set_global(u_int cmd, struct au1200_lcd_global_regs_t *pdata) 1245static void set_global(u_int cmd, struct au1200_lcd_global_regs_t *pdata)
diff --git a/drivers/video/exynos/Kconfig b/drivers/video/exynos/Kconfig
index 1b035b2eb6b6..1129d0e9e640 100644
--- a/drivers/video/exynos/Kconfig
+++ b/drivers/video/exynos/Kconfig
@@ -16,6 +16,7 @@ if EXYNOS_VIDEO
16config EXYNOS_MIPI_DSI 16config EXYNOS_MIPI_DSI
17 bool "EXYNOS MIPI DSI driver support." 17 bool "EXYNOS MIPI DSI driver support."
18 depends on ARCH_S5PV210 || ARCH_EXYNOS 18 depends on ARCH_S5PV210 || ARCH_EXYNOS
19 select GENERIC_PHY
19 help 20 help
20 This enables support for MIPI-DSI device. 21 This enables support for MIPI-DSI device.
21 22
@@ -29,7 +30,7 @@ config EXYNOS_LCD_S6E8AX0
29 30
30config EXYNOS_DP 31config EXYNOS_DP
31 bool "EXYNOS DP driver support" 32 bool "EXYNOS DP driver support"
32 depends on ARCH_EXYNOS 33 depends on OF && ARCH_EXYNOS
33 default n 34 default n
34 help 35 help
35 This enables support for DP device. 36 This enables support for DP device.
diff --git a/drivers/video/exynos/exynos_dp_core.c b/drivers/video/exynos/exynos_dp_core.c
index 12bbede3b091..5e1a71580051 100644
--- a/drivers/video/exynos/exynos_dp_core.c
+++ b/drivers/video/exynos/exynos_dp_core.c
@@ -19,8 +19,7 @@
19#include <linux/interrupt.h> 19#include <linux/interrupt.h>
20#include <linux/delay.h> 20#include <linux/delay.h>
21#include <linux/of.h> 21#include <linux/of.h>
22 22#include <linux/phy/phy.h>
23#include <video/exynos_dp.h>
24 23
25#include "exynos_dp_core.h" 24#include "exynos_dp_core.h"
26 25
@@ -894,26 +893,17 @@ static void exynos_dp_hotplug(struct work_struct *work)
894 dev_err(dp->dev, "unable to config video\n"); 893 dev_err(dp->dev, "unable to config video\n");
895} 894}
896 895
897#ifdef CONFIG_OF 896static struct video_info *exynos_dp_dt_parse_pdata(struct device *dev)
898static struct exynos_dp_platdata *exynos_dp_dt_parse_pdata(struct device *dev)
899{ 897{
900 struct device_node *dp_node = dev->of_node; 898 struct device_node *dp_node = dev->of_node;
901 struct exynos_dp_platdata *pd;
902 struct video_info *dp_video_config; 899 struct video_info *dp_video_config;
903 900
904 pd = devm_kzalloc(dev, sizeof(*pd), GFP_KERNEL);
905 if (!pd) {
906 dev_err(dev, "memory allocation for pdata failed\n");
907 return ERR_PTR(-ENOMEM);
908 }
909 dp_video_config = devm_kzalloc(dev, 901 dp_video_config = devm_kzalloc(dev,
910 sizeof(*dp_video_config), GFP_KERNEL); 902 sizeof(*dp_video_config), GFP_KERNEL);
911
912 if (!dp_video_config) { 903 if (!dp_video_config) {
913 dev_err(dev, "memory allocation for video config failed\n"); 904 dev_err(dev, "memory allocation for video config failed\n");
914 return ERR_PTR(-ENOMEM); 905 return ERR_PTR(-ENOMEM);
915 } 906 }
916 pd->video_info = dp_video_config;
917 907
918 dp_video_config->h_sync_polarity = 908 dp_video_config->h_sync_polarity =
919 of_property_read_bool(dp_node, "hsync-active-high"); 909 of_property_read_bool(dp_node, "hsync-active-high");
@@ -960,7 +950,7 @@ static struct exynos_dp_platdata *exynos_dp_dt_parse_pdata(struct device *dev)
960 return ERR_PTR(-EINVAL); 950 return ERR_PTR(-EINVAL);
961 } 951 }
962 952
963 return pd; 953 return dp_video_config;
964} 954}
965 955
966static int exynos_dp_dt_parse_phydata(struct exynos_dp_device *dp) 956static int exynos_dp_dt_parse_phydata(struct exynos_dp_device *dp)
@@ -971,8 +961,11 @@ static int exynos_dp_dt_parse_phydata(struct exynos_dp_device *dp)
971 961
972 dp_phy_node = of_find_node_by_name(dp_phy_node, "dptx-phy"); 962 dp_phy_node = of_find_node_by_name(dp_phy_node, "dptx-phy");
973 if (!dp_phy_node) { 963 if (!dp_phy_node) {
974 dev_err(dp->dev, "could not find dptx-phy node\n"); 964 dp->phy = devm_phy_get(dp->dev, "dp");
975 return -ENODEV; 965 if (IS_ERR(dp->phy))
966 return PTR_ERR(dp->phy);
967 else
968 return 0;
976 } 969 }
977 970
978 if (of_property_read_u32(dp_phy_node, "reg", &phy_base)) { 971 if (of_property_read_u32(dp_phy_node, "reg", &phy_base)) {
@@ -1003,48 +996,34 @@ err:
1003 996
1004static void exynos_dp_phy_init(struct exynos_dp_device *dp) 997static void exynos_dp_phy_init(struct exynos_dp_device *dp)
1005{ 998{
1006 u32 reg; 999 if (dp->phy) {
1007 1000 phy_power_on(dp->phy);
1008 reg = __raw_readl(dp->phy_addr); 1001 } else if (dp->phy_addr) {
1009 reg |= dp->enable_mask; 1002 u32 reg;
1010 __raw_writel(reg, dp->phy_addr); 1003
1011} 1004 reg = __raw_readl(dp->phy_addr);
1012 1005 reg |= dp->enable_mask;
1013static void exynos_dp_phy_exit(struct exynos_dp_device *dp) 1006 __raw_writel(reg, dp->phy_addr);
1014{ 1007 }
1015 u32 reg;
1016
1017 reg = __raw_readl(dp->phy_addr);
1018 reg &= ~(dp->enable_mask);
1019 __raw_writel(reg, dp->phy_addr);
1020}
1021#else
1022static struct exynos_dp_platdata *exynos_dp_dt_parse_pdata(struct device *dev)
1023{
1024 return NULL;
1025}
1026
1027static int exynos_dp_dt_parse_phydata(struct exynos_dp_device *dp)
1028{
1029 return -EINVAL;
1030}
1031
1032static void exynos_dp_phy_init(struct exynos_dp_device *dp)
1033{
1034 return;
1035} 1008}
1036 1009
1037static void exynos_dp_phy_exit(struct exynos_dp_device *dp) 1010static void exynos_dp_phy_exit(struct exynos_dp_device *dp)
1038{ 1011{
1039 return; 1012 if (dp->phy) {
1013 phy_power_off(dp->phy);
1014 } else if (dp->phy_addr) {
1015 u32 reg;
1016
1017 reg = __raw_readl(dp->phy_addr);
1018 reg &= ~(dp->enable_mask);
1019 __raw_writel(reg, dp->phy_addr);
1020 }
1040} 1021}
1041#endif /* CONFIG_OF */
1042 1022
1043static int exynos_dp_probe(struct platform_device *pdev) 1023static int exynos_dp_probe(struct platform_device *pdev)
1044{ 1024{
1045 struct resource *res; 1025 struct resource *res;
1046 struct exynos_dp_device *dp; 1026 struct exynos_dp_device *dp;
1047 struct exynos_dp_platdata *pdata;
1048 1027
1049 int ret = 0; 1028 int ret = 0;
1050 1029
@@ -1057,21 +1036,13 @@ static int exynos_dp_probe(struct platform_device *pdev)
1057 1036
1058 dp->dev = &pdev->dev; 1037 dp->dev = &pdev->dev;
1059 1038
1060 if (pdev->dev.of_node) { 1039 dp->video_info = exynos_dp_dt_parse_pdata(&pdev->dev);
1061 pdata = exynos_dp_dt_parse_pdata(&pdev->dev); 1040 if (IS_ERR(dp->video_info))
1062 if (IS_ERR(pdata)) 1041 return PTR_ERR(dp->video_info);
1063 return PTR_ERR(pdata);
1064 1042
1065 ret = exynos_dp_dt_parse_phydata(dp); 1043 ret = exynos_dp_dt_parse_phydata(dp);
1066 if (ret) 1044 if (ret)
1067 return ret; 1045 return ret;
1068 } else {
1069 pdata = pdev->dev.platform_data;
1070 if (!pdata) {
1071 dev_err(&pdev->dev, "no platform data\n");
1072 return -EINVAL;
1073 }
1074 }
1075 1046
1076 dp->clock = devm_clk_get(&pdev->dev, "dp"); 1047 dp->clock = devm_clk_get(&pdev->dev, "dp");
1077 if (IS_ERR(dp->clock)) { 1048 if (IS_ERR(dp->clock)) {
@@ -1095,15 +1066,7 @@ static int exynos_dp_probe(struct platform_device *pdev)
1095 1066
1096 INIT_WORK(&dp->hotplug_work, exynos_dp_hotplug); 1067 INIT_WORK(&dp->hotplug_work, exynos_dp_hotplug);
1097 1068
1098 dp->video_info = pdata->video_info; 1069 exynos_dp_phy_init(dp);
1099
1100 if (pdev->dev.of_node) {
1101 if (dp->phy_addr)
1102 exynos_dp_phy_init(dp);
1103 } else {
1104 if (pdata->phy_init)
1105 pdata->phy_init();
1106 }
1107 1070
1108 exynos_dp_init_dp(dp); 1071 exynos_dp_init_dp(dp);
1109 1072
@@ -1121,18 +1084,11 @@ static int exynos_dp_probe(struct platform_device *pdev)
1121 1084
1122static int exynos_dp_remove(struct platform_device *pdev) 1085static int exynos_dp_remove(struct platform_device *pdev)
1123{ 1086{
1124 struct exynos_dp_platdata *pdata = pdev->dev.platform_data;
1125 struct exynos_dp_device *dp = platform_get_drvdata(pdev); 1087 struct exynos_dp_device *dp = platform_get_drvdata(pdev);
1126 1088
1127 flush_work(&dp->hotplug_work); 1089 flush_work(&dp->hotplug_work);
1128 1090
1129 if (pdev->dev.of_node) { 1091 exynos_dp_phy_exit(dp);
1130 if (dp->phy_addr)
1131 exynos_dp_phy_exit(dp);
1132 } else {
1133 if (pdata->phy_exit)
1134 pdata->phy_exit();
1135 }
1136 1092
1137 clk_disable_unprepare(dp->clock); 1093 clk_disable_unprepare(dp->clock);
1138 1094
@@ -1143,20 +1099,13 @@ static int exynos_dp_remove(struct platform_device *pdev)
1143#ifdef CONFIG_PM_SLEEP 1099#ifdef CONFIG_PM_SLEEP
1144static int exynos_dp_suspend(struct device *dev) 1100static int exynos_dp_suspend(struct device *dev)
1145{ 1101{
1146 struct exynos_dp_platdata *pdata = dev->platform_data;
1147 struct exynos_dp_device *dp = dev_get_drvdata(dev); 1102 struct exynos_dp_device *dp = dev_get_drvdata(dev);
1148 1103
1149 disable_irq(dp->irq); 1104 disable_irq(dp->irq);
1150 1105
1151 flush_work(&dp->hotplug_work); 1106 flush_work(&dp->hotplug_work);
1152 1107
1153 if (dev->of_node) { 1108 exynos_dp_phy_exit(dp);
1154 if (dp->phy_addr)
1155 exynos_dp_phy_exit(dp);
1156 } else {
1157 if (pdata->phy_exit)
1158 pdata->phy_exit();
1159 }
1160 1109
1161 clk_disable_unprepare(dp->clock); 1110 clk_disable_unprepare(dp->clock);
1162 1111
@@ -1165,16 +1114,9 @@ static int exynos_dp_suspend(struct device *dev)
1165 1114
1166static int exynos_dp_resume(struct device *dev) 1115static int exynos_dp_resume(struct device *dev)
1167{ 1116{
1168 struct exynos_dp_platdata *pdata = dev->platform_data;
1169 struct exynos_dp_device *dp = dev_get_drvdata(dev); 1117 struct exynos_dp_device *dp = dev_get_drvdata(dev);
1170 1118
1171 if (dev->of_node) { 1119 exynos_dp_phy_init(dp);
1172 if (dp->phy_addr)
1173 exynos_dp_phy_init(dp);
1174 } else {
1175 if (pdata->phy_init)
1176 pdata->phy_init();
1177 }
1178 1120
1179 clk_prepare_enable(dp->clock); 1121 clk_prepare_enable(dp->clock);
1180 1122
@@ -1203,7 +1145,7 @@ static struct platform_driver exynos_dp_driver = {
1203 .name = "exynos-dp", 1145 .name = "exynos-dp",
1204 .owner = THIS_MODULE, 1146 .owner = THIS_MODULE,
1205 .pm = &exynos_dp_pm_ops, 1147 .pm = &exynos_dp_pm_ops,
1206 .of_match_table = of_match_ptr(exynos_dp_match), 1148 .of_match_table = exynos_dp_match,
1207 }, 1149 },
1208}; 1150};
1209 1151
diff --git a/drivers/video/exynos/exynos_dp_core.h b/drivers/video/exynos/exynos_dp_core.h
index 6c567bbf2fb8..607e36d0c147 100644
--- a/drivers/video/exynos/exynos_dp_core.h
+++ b/drivers/video/exynos/exynos_dp_core.h
@@ -13,6 +13,99 @@
13#ifndef _EXYNOS_DP_CORE_H 13#ifndef _EXYNOS_DP_CORE_H
14#define _EXYNOS_DP_CORE_H 14#define _EXYNOS_DP_CORE_H
15 15
16#define DP_TIMEOUT_LOOP_COUNT 100
17#define MAX_CR_LOOP 5
18#define MAX_EQ_LOOP 5
19
20enum link_rate_type {
21 LINK_RATE_1_62GBPS = 0x06,
22 LINK_RATE_2_70GBPS = 0x0a
23};
24
25enum link_lane_count_type {
26 LANE_COUNT1 = 1,
27 LANE_COUNT2 = 2,
28 LANE_COUNT4 = 4
29};
30
31enum link_training_state {
32 START,
33 CLOCK_RECOVERY,
34 EQUALIZER_TRAINING,
35 FINISHED,
36 FAILED
37};
38
39enum voltage_swing_level {
40 VOLTAGE_LEVEL_0,
41 VOLTAGE_LEVEL_1,
42 VOLTAGE_LEVEL_2,
43 VOLTAGE_LEVEL_3,
44};
45
46enum pre_emphasis_level {
47 PRE_EMPHASIS_LEVEL_0,
48 PRE_EMPHASIS_LEVEL_1,
49 PRE_EMPHASIS_LEVEL_2,
50 PRE_EMPHASIS_LEVEL_3,
51};
52
53enum pattern_set {
54 PRBS7,
55 D10_2,
56 TRAINING_PTN1,
57 TRAINING_PTN2,
58 DP_NONE
59};
60
61enum color_space {
62 COLOR_RGB,
63 COLOR_YCBCR422,
64 COLOR_YCBCR444
65};
66
67enum color_depth {
68 COLOR_6,
69 COLOR_8,
70 COLOR_10,
71 COLOR_12
72};
73
74enum color_coefficient {
75 COLOR_YCBCR601,
76 COLOR_YCBCR709
77};
78
79enum dynamic_range {
80 VESA,
81 CEA
82};
83
84enum pll_status {
85 PLL_UNLOCKED,
86 PLL_LOCKED
87};
88
89enum clock_recovery_m_value_type {
90 CALCULATED_M,
91 REGISTER_M
92};
93
94enum video_timing_recognition_type {
95 VIDEO_TIMING_FROM_CAPTURE,
96 VIDEO_TIMING_FROM_REGISTER
97};
98
99enum analog_power_block {
100 AUX_BLOCK,
101 CH0_BLOCK,
102 CH1_BLOCK,
103 CH2_BLOCK,
104 CH3_BLOCK,
105 ANALOG_TOTAL,
106 POWER_ALL
107};
108
16enum dp_irq_type { 109enum dp_irq_type {
17 DP_IRQ_TYPE_HP_CABLE_IN, 110 DP_IRQ_TYPE_HP_CABLE_IN,
18 DP_IRQ_TYPE_HP_CABLE_OUT, 111 DP_IRQ_TYPE_HP_CABLE_OUT,
@@ -20,6 +113,22 @@ enum dp_irq_type {
20 DP_IRQ_TYPE_UNKNOWN, 113 DP_IRQ_TYPE_UNKNOWN,
21}; 114};
22 115
116struct video_info {
117 char *name;
118
119 bool h_sync_polarity;
120 bool v_sync_polarity;
121 bool interlaced;
122
123 enum color_space color_space;
124 enum dynamic_range dynamic_range;
125 enum color_coefficient ycbcr_coeff;
126 enum color_depth color_depth;
127
128 enum link_rate_type link_rate;
129 enum link_lane_count_type lane_count;
130};
131
23struct link_train { 132struct link_train {
24 int eq_loop; 133 int eq_loop;
25 int cr_loop[4]; 134 int cr_loop[4];
@@ -42,6 +151,7 @@ struct exynos_dp_device {
42 struct video_info *video_info; 151 struct video_info *video_info;
43 struct link_train link_train; 152 struct link_train link_train;
44 struct work_struct hotplug_work; 153 struct work_struct hotplug_work;
154 struct phy *phy;
45}; 155};
46 156
47/* exynos_dp_reg.c */ 157/* exynos_dp_reg.c */
diff --git a/drivers/video/exynos/exynos_dp_reg.c b/drivers/video/exynos/exynos_dp_reg.c
index 29d9d035c73a..b70da5052ff0 100644
--- a/drivers/video/exynos/exynos_dp_reg.c
+++ b/drivers/video/exynos/exynos_dp_reg.c
@@ -14,8 +14,6 @@
14#include <linux/io.h> 14#include <linux/io.h>
15#include <linux/delay.h> 15#include <linux/delay.h>
16 16
17#include <video/exynos_dp.h>
18
19#include "exynos_dp_core.h" 17#include "exynos_dp_core.h"
20#include "exynos_dp_reg.h" 18#include "exynos_dp_reg.h"
21 19
diff --git a/drivers/video/exynos/exynos_mipi_dsi.c b/drivers/video/exynos/exynos_mipi_dsi.c
index 32e540600f99..00b3a52c1d68 100644
--- a/drivers/video/exynos/exynos_mipi_dsi.c
+++ b/drivers/video/exynos/exynos_mipi_dsi.c
@@ -30,6 +30,7 @@
30#include <linux/interrupt.h> 30#include <linux/interrupt.h>
31#include <linux/kthread.h> 31#include <linux/kthread.h>
32#include <linux/notifier.h> 32#include <linux/notifier.h>
33#include <linux/phy/phy.h>
33#include <linux/regulator/consumer.h> 34#include <linux/regulator/consumer.h>
34#include <linux/pm_runtime.h> 35#include <linux/pm_runtime.h>
35#include <linux/err.h> 36#include <linux/err.h>
@@ -156,8 +157,7 @@ static int exynos_mipi_dsi_blank_mode(struct mipi_dsim_device *dsim, int power)
156 exynos_mipi_regulator_enable(dsim); 157 exynos_mipi_regulator_enable(dsim);
157 158
158 /* enable MIPI-DSI PHY. */ 159 /* enable MIPI-DSI PHY. */
159 if (dsim->pd->phy_enable) 160 phy_power_on(dsim->phy);
160 dsim->pd->phy_enable(pdev, true);
161 161
162 clk_enable(dsim->clock); 162 clk_enable(dsim->clock);
163 163
@@ -373,6 +373,10 @@ static int exynos_mipi_dsi_probe(struct platform_device *pdev)
373 return ret; 373 return ret;
374 } 374 }
375 375
376 dsim->phy = devm_phy_get(&pdev->dev, "dsim");
377 if (IS_ERR(dsim->phy))
378 return PTR_ERR(dsim->phy);
379
376 dsim->clock = devm_clk_get(&pdev->dev, "dsim0"); 380 dsim->clock = devm_clk_get(&pdev->dev, "dsim0");
377 if (IS_ERR(dsim->clock)) { 381 if (IS_ERR(dsim->clock)) {
378 dev_err(&pdev->dev, "failed to get dsim clock source\n"); 382 dev_err(&pdev->dev, "failed to get dsim clock source\n");
@@ -439,8 +443,7 @@ static int exynos_mipi_dsi_probe(struct platform_device *pdev)
439 exynos_mipi_regulator_enable(dsim); 443 exynos_mipi_regulator_enable(dsim);
440 444
441 /* enable MIPI-DSI PHY. */ 445 /* enable MIPI-DSI PHY. */
442 if (dsim->pd->phy_enable) 446 phy_power_on(dsim->phy);
443 dsim->pd->phy_enable(pdev, true);
444 447
445 exynos_mipi_update_cfg(dsim); 448 exynos_mipi_update_cfg(dsim);
446 449
@@ -504,9 +507,8 @@ static int exynos_mipi_dsi_suspend(struct device *dev)
504 if (client_drv && client_drv->suspend) 507 if (client_drv && client_drv->suspend)
505 client_drv->suspend(client_dev); 508 client_drv->suspend(client_dev);
506 509
507 /* enable MIPI-DSI PHY. */ 510 /* disable MIPI-DSI PHY. */
508 if (dsim->pd->phy_enable) 511 phy_power_off(dsim->phy);
509 dsim->pd->phy_enable(pdev, false);
510 512
511 clk_disable(dsim->clock); 513 clk_disable(dsim->clock);
512 514
@@ -536,8 +538,7 @@ static int exynos_mipi_dsi_resume(struct device *dev)
536 exynos_mipi_regulator_enable(dsim); 538 exynos_mipi_regulator_enable(dsim);
537 539
538 /* enable MIPI-DSI PHY. */ 540 /* enable MIPI-DSI PHY. */
539 if (dsim->pd->phy_enable) 541 phy_power_on(dsim->phy);
540 dsim->pd->phy_enable(pdev, true);
541 542
542 clk_enable(dsim->clock); 543 clk_enable(dsim->clock);
543 544
diff --git a/fs/dcache.c b/fs/dcache.c
index 41000305d716..ae6ebb88ceff 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -542,7 +542,7 @@ EXPORT_SYMBOL(d_drop);
542 * If ref is non-zero, then decrement the refcount too. 542 * If ref is non-zero, then decrement the refcount too.
543 * Returns dentry requiring refcount drop, or NULL if we're done. 543 * Returns dentry requiring refcount drop, or NULL if we're done.
544 */ 544 */
545static inline struct dentry * 545static struct dentry *
546dentry_kill(struct dentry *dentry, int unlock_on_failure) 546dentry_kill(struct dentry *dentry, int unlock_on_failure)
547 __releases(dentry->d_lock) 547 __releases(dentry->d_lock)
548{ 548{
@@ -630,7 +630,8 @@ repeat:
630 goto kill_it; 630 goto kill_it;
631 } 631 }
632 632
633 dentry->d_flags |= DCACHE_REFERENCED; 633 if (!(dentry->d_flags & DCACHE_REFERENCED))
634 dentry->d_flags |= DCACHE_REFERENCED;
634 dentry_lru_add(dentry); 635 dentry_lru_add(dentry);
635 636
636 dentry->d_lockref.count--; 637 dentry->d_lockref.count--;
@@ -1331,14 +1332,6 @@ rename_retry:
1331 * list is non-empty and continue searching. 1332 * list is non-empty and continue searching.
1332 */ 1333 */
1333 1334
1334/**
1335 * have_submounts - check for mounts over a dentry
1336 * @parent: dentry to check.
1337 *
1338 * Return true if the parent or its subdirectories contain
1339 * a mount point
1340 */
1341
1342static enum d_walk_ret check_mount(void *data, struct dentry *dentry) 1335static enum d_walk_ret check_mount(void *data, struct dentry *dentry)
1343{ 1336{
1344 int *ret = data; 1337 int *ret = data;
@@ -1349,6 +1342,13 @@ static enum d_walk_ret check_mount(void *data, struct dentry *dentry)
1349 return D_WALK_CONTINUE; 1342 return D_WALK_CONTINUE;
1350} 1343}
1351 1344
1345/**
1346 * have_submounts - check for mounts over a dentry
1347 * @parent: dentry to check.
1348 *
1349 * Return true if the parent or its subdirectories contain
1350 * a mount point
1351 */
1352int have_submounts(struct dentry *parent) 1352int have_submounts(struct dentry *parent)
1353{ 1353{
1354 int ret = 0; 1354 int ret = 0;
diff --git a/fs/ecryptfs/crypto.c b/fs/ecryptfs/crypto.c
index c88e355f7635..000eae2782b6 100644
--- a/fs/ecryptfs/crypto.c
+++ b/fs/ecryptfs/crypto.c
@@ -408,7 +408,7 @@ static loff_t lower_offset_for_page(struct ecryptfs_crypt_stat *crypt_stat,
408 struct page *page) 408 struct page *page)
409{ 409{
410 return ecryptfs_lower_header_size(crypt_stat) + 410 return ecryptfs_lower_header_size(crypt_stat) +
411 (page->index << PAGE_CACHE_SHIFT); 411 ((loff_t)page->index << PAGE_CACHE_SHIFT);
412} 412}
413 413
414/** 414/**
diff --git a/fs/ecryptfs/keystore.c b/fs/ecryptfs/keystore.c
index 7d52806c2119..4725a07f003c 100644
--- a/fs/ecryptfs/keystore.c
+++ b/fs/ecryptfs/keystore.c
@@ -1149,7 +1149,7 @@ decrypt_pki_encrypted_session_key(struct ecryptfs_auth_tok *auth_tok,
1149 struct ecryptfs_msg_ctx *msg_ctx; 1149 struct ecryptfs_msg_ctx *msg_ctx;
1150 struct ecryptfs_message *msg = NULL; 1150 struct ecryptfs_message *msg = NULL;
1151 char *auth_tok_sig; 1151 char *auth_tok_sig;
1152 char *payload; 1152 char *payload = NULL;
1153 size_t payload_len = 0; 1153 size_t payload_len = 0;
1154 int rc; 1154 int rc;
1155 1155
@@ -1203,6 +1203,7 @@ decrypt_pki_encrypted_session_key(struct ecryptfs_auth_tok *auth_tok,
1203 } 1203 }
1204out: 1204out:
1205 kfree(msg); 1205 kfree(msg);
1206 kfree(payload);
1206 return rc; 1207 return rc;
1207} 1208}
1208 1209
diff --git a/fs/eventpoll.c b/fs/eventpoll.c
index 473e09da7d02..810c28fb8c3c 100644
--- a/fs/eventpoll.c
+++ b/fs/eventpoll.c
@@ -34,7 +34,6 @@
34#include <linux/mutex.h> 34#include <linux/mutex.h>
35#include <linux/anon_inodes.h> 35#include <linux/anon_inodes.h>
36#include <linux/device.h> 36#include <linux/device.h>
37#include <linux/freezer.h>
38#include <asm/uaccess.h> 37#include <asm/uaccess.h>
39#include <asm/io.h> 38#include <asm/io.h>
40#include <asm/mman.h> 39#include <asm/mman.h>
@@ -1605,8 +1604,7 @@ fetch_events:
1605 } 1604 }
1606 1605
1607 spin_unlock_irqrestore(&ep->lock, flags); 1606 spin_unlock_irqrestore(&ep->lock, flags);
1608 if (!freezable_schedule_hrtimeout_range(to, slack, 1607 if (!schedule_hrtimeout_range(to, slack, HRTIMER_MODE_ABS))
1609 HRTIMER_MODE_ABS))
1610 timed_out = 1; 1608 timed_out = 1;
1611 1609
1612 spin_lock_irqsave(&ep->lock, flags); 1610 spin_lock_irqsave(&ep->lock, flags);
diff --git a/fs/file_table.c b/fs/file_table.c
index abdd15ad13c9..e900ca518635 100644
--- a/fs/file_table.c
+++ b/fs/file_table.c
@@ -297,7 +297,7 @@ void flush_delayed_fput(void)
297 delayed_fput(NULL); 297 delayed_fput(NULL);
298} 298}
299 299
300static DECLARE_WORK(delayed_fput_work, delayed_fput); 300static DECLARE_DELAYED_WORK(delayed_fput_work, delayed_fput);
301 301
302void fput(struct file *file) 302void fput(struct file *file)
303{ 303{
@@ -317,7 +317,7 @@ void fput(struct file *file)
317 } 317 }
318 318
319 if (llist_add(&file->f_u.fu_llist, &delayed_fput_list)) 319 if (llist_add(&file->f_u.fu_llist, &delayed_fput_list))
320 schedule_work(&delayed_fput_work); 320 schedule_delayed_work(&delayed_fput_work, 1);
321 } 321 }
322} 322}
323 323
diff --git a/fs/jfs/jfs_inode.c b/fs/jfs/jfs_inode.c
index c1a3e603279c..7f464c513ba0 100644
--- a/fs/jfs/jfs_inode.c
+++ b/fs/jfs/jfs_inode.c
@@ -95,7 +95,7 @@ struct inode *ialloc(struct inode *parent, umode_t mode)
95 95
96 if (insert_inode_locked(inode) < 0) { 96 if (insert_inode_locked(inode) < 0) {
97 rc = -EINVAL; 97 rc = -EINVAL;
98 goto fail_unlock; 98 goto fail_put;
99 } 99 }
100 100
101 inode_init_owner(inode, parent, mode); 101 inode_init_owner(inode, parent, mode);
@@ -156,7 +156,6 @@ struct inode *ialloc(struct inode *parent, umode_t mode)
156fail_drop: 156fail_drop:
157 dquot_drop(inode); 157 dquot_drop(inode);
158 inode->i_flags |= S_NOQUOTA; 158 inode->i_flags |= S_NOQUOTA;
159fail_unlock:
160 clear_nlink(inode); 159 clear_nlink(inode);
161 unlock_new_inode(inode); 160 unlock_new_inode(inode);
162fail_put: 161fail_put:
diff --git a/fs/namei.c b/fs/namei.c
index 645268f23eb6..caa28051e197 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -2294,10 +2294,11 @@ out:
2294 * path_mountpoint - look up a path to be umounted 2294 * path_mountpoint - look up a path to be umounted
2295 * @dfd: directory file descriptor to start walk from 2295 * @dfd: directory file descriptor to start walk from
2296 * @name: full pathname to walk 2296 * @name: full pathname to walk
2297 * @path: pointer to container for result
2297 * @flags: lookup flags 2298 * @flags: lookup flags
2298 * 2299 *
2299 * Look up the given name, but don't attempt to revalidate the last component. 2300 * Look up the given name, but don't attempt to revalidate the last component.
2300 * Returns 0 and "path" will be valid on success; Retuns error otherwise. 2301 * Returns 0 and "path" will be valid on success; Returns error otherwise.
2301 */ 2302 */
2302static int 2303static int
2303path_mountpoint(int dfd, const char *name, struct path *path, unsigned int flags) 2304path_mountpoint(int dfd, const char *name, struct path *path, unsigned int flags)
diff --git a/fs/select.c b/fs/select.c
index 35d4adc749d9..dfd5cb18c012 100644
--- a/fs/select.c
+++ b/fs/select.c
@@ -238,8 +238,7 @@ int poll_schedule_timeout(struct poll_wqueues *pwq, int state,
238 238
239 set_current_state(state); 239 set_current_state(state);
240 if (!pwq->triggered) 240 if (!pwq->triggered)
241 rc = freezable_schedule_hrtimeout_range(expires, slack, 241 rc = schedule_hrtimeout_range(expires, slack, HRTIMER_MODE_ABS);
242 HRTIMER_MODE_ABS);
243 __set_current_state(TASK_RUNNING); 242 __set_current_state(TASK_RUNNING);
244 243
245 /* 244 /*
diff --git a/fs/seq_file.c b/fs/seq_file.c
index 3135c2525c76..a290157265ef 100644
--- a/fs/seq_file.c
+++ b/fs/seq_file.c
@@ -328,6 +328,8 @@ loff_t seq_lseek(struct file *file, loff_t offset, int whence)
328 m->read_pos = offset; 328 m->read_pos = offset;
329 retval = file->f_pos = offset; 329 retval = file->f_pos = offset;
330 } 330 }
331 } else {
332 file->f_pos = offset;
331 } 333 }
332 } 334 }
333 file->f_version = m->version; 335 file->f_version = m->version;
diff --git a/include/linux/filter.h b/include/linux/filter.h
index a6ac84871d6d..ff4e40cd45b1 100644
--- a/include/linux/filter.h
+++ b/include/linux/filter.h
@@ -6,6 +6,7 @@
6 6
7#include <linux/atomic.h> 7#include <linux/atomic.h>
8#include <linux/compat.h> 8#include <linux/compat.h>
9#include <linux/workqueue.h>
9#include <uapi/linux/filter.h> 10#include <uapi/linux/filter.h>
10 11
11#ifdef CONFIG_COMPAT 12#ifdef CONFIG_COMPAT
@@ -25,15 +26,19 @@ struct sk_filter
25{ 26{
26 atomic_t refcnt; 27 atomic_t refcnt;
27 unsigned int len; /* Number of filter blocks */ 28 unsigned int len; /* Number of filter blocks */
29 struct rcu_head rcu;
28 unsigned int (*bpf_func)(const struct sk_buff *skb, 30 unsigned int (*bpf_func)(const struct sk_buff *skb,
29 const struct sock_filter *filter); 31 const struct sock_filter *filter);
30 struct rcu_head rcu; 32 union {
31 struct sock_filter insns[0]; 33 struct sock_filter insns[0];
34 struct work_struct work;
35 };
32}; 36};
33 37
34static inline unsigned int sk_filter_len(const struct sk_filter *fp) 38static inline unsigned int sk_filter_size(unsigned int proglen)
35{ 39{
36 return fp->len * sizeof(struct sock_filter) + sizeof(*fp); 40 return max(sizeof(struct sk_filter),
41 offsetof(struct sk_filter, insns[proglen]));
37} 42}
38 43
39extern int sk_filter(struct sock *sk, struct sk_buff *skb); 44extern int sk_filter(struct sock *sk, struct sk_buff *skb);
@@ -67,11 +72,13 @@ static inline void bpf_jit_dump(unsigned int flen, unsigned int proglen,
67} 72}
68#define SK_RUN_FILTER(FILTER, SKB) (*FILTER->bpf_func)(SKB, FILTER->insns) 73#define SK_RUN_FILTER(FILTER, SKB) (*FILTER->bpf_func)(SKB, FILTER->insns)
69#else 74#else
75#include <linux/slab.h>
70static inline void bpf_jit_compile(struct sk_filter *fp) 76static inline void bpf_jit_compile(struct sk_filter *fp)
71{ 77{
72} 78}
73static inline void bpf_jit_free(struct sk_filter *fp) 79static inline void bpf_jit_free(struct sk_filter *fp)
74{ 80{
81 kfree(fp);
75} 82}
76#define SK_RUN_FILTER(FILTER, SKB) sk_run_filter(SKB, FILTER->insns) 83#define SK_RUN_FILTER(FILTER, SKB) sk_run_filter(SKB, FILTER->insns)
77#endif 84#endif
diff --git a/include/linux/i2c/twl.h b/include/linux/i2c/twl.h
index 81cbbdb96aae..673a3ce67f31 100644
--- a/include/linux/i2c/twl.h
+++ b/include/linux/i2c/twl.h
@@ -26,6 +26,7 @@
26#define __TWL_H_ 26#define __TWL_H_
27 27
28#include <linux/types.h> 28#include <linux/types.h>
29#include <linux/phy/phy.h>
29#include <linux/input/matrix_keypad.h> 30#include <linux/input/matrix_keypad.h>
30 31
31/* 32/*
@@ -615,6 +616,7 @@ enum twl4030_usb_mode {
615struct twl4030_usb_data { 616struct twl4030_usb_data {
616 enum twl4030_usb_mode usb_mode; 617 enum twl4030_usb_mode usb_mode;
617 unsigned long features; 618 unsigned long features;
619 struct phy_init_data *init_data;
618 620
619 int (*phy_init)(struct device *dev); 621 int (*phy_init)(struct device *dev);
620 int (*phy_exit)(struct device *dev); 622 int (*phy_exit)(struct device *dev);
diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h
index 19c19a5eee29..f6c82de12541 100644
--- a/include/linux/ipc_namespace.h
+++ b/include/linux/ipc_namespace.h
@@ -34,9 +34,9 @@ struct ipc_namespace {
34 int sem_ctls[4]; 34 int sem_ctls[4];
35 int used_sems; 35 int used_sems;
36 36
37 int msg_ctlmax; 37 unsigned int msg_ctlmax;
38 int msg_ctlmnb; 38 unsigned int msg_ctlmnb;
39 int msg_ctlmni; 39 unsigned int msg_ctlmni;
40 atomic_t msg_bytes; 40 atomic_t msg_bytes;
41 atomic_t msg_hdrs; 41 atomic_t msg_hdrs;
42 int auto_msgmni; 42 int auto_msgmni;
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 3de49aca4519..25f5d2d11e7c 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -2264,11 +2264,12 @@ static inline void netif_wake_subqueue(struct net_device *dev, u16 queue_index)
2264} 2264}
2265 2265
2266#ifdef CONFIG_XPS 2266#ifdef CONFIG_XPS
2267extern int netif_set_xps_queue(struct net_device *dev, struct cpumask *mask, 2267extern int netif_set_xps_queue(struct net_device *dev,
2268 const struct cpumask *mask,
2268 u16 index); 2269 u16 index);
2269#else 2270#else
2270static inline int netif_set_xps_queue(struct net_device *dev, 2271static inline int netif_set_xps_queue(struct net_device *dev,
2271 struct cpumask *mask, 2272 const struct cpumask *mask,
2272 u16 index) 2273 u16 index)
2273{ 2274{
2274 return 0; 2275 return 0;
diff --git a/include/linux/netpoll.h b/include/linux/netpoll.h
index f3c7c24bec1c..fbfdb9d8d3a7 100644
--- a/include/linux/netpoll.h
+++ b/include/linux/netpoll.h
@@ -24,7 +24,8 @@ struct netpoll {
24 struct net_device *dev; 24 struct net_device *dev;
25 char dev_name[IFNAMSIZ]; 25 char dev_name[IFNAMSIZ];
26 const char *name; 26 const char *name;
27 void (*rx_hook)(struct netpoll *, int, char *, int); 27 void (*rx_skb_hook)(struct netpoll *np, int source, struct sk_buff *skb,
28 int offset, int len);
28 29
29 union inet_addr local_ip, remote_ip; 30 union inet_addr local_ip, remote_ip;
30 bool ipv6; 31 bool ipv6;
@@ -41,7 +42,7 @@ struct netpoll_info {
41 unsigned long rx_flags; 42 unsigned long rx_flags;
42 spinlock_t rx_lock; 43 spinlock_t rx_lock;
43 struct semaphore dev_lock; 44 struct semaphore dev_lock;
44 struct list_head rx_np; /* netpolls that registered an rx_hook */ 45 struct list_head rx_np; /* netpolls that registered an rx_skb_hook */
45 46
46 struct sk_buff_head neigh_tx; /* list of neigh requests to reply to */ 47 struct sk_buff_head neigh_tx; /* list of neigh requests to reply to */
47 struct sk_buff_head txq; 48 struct sk_buff_head txq;
diff --git a/include/linux/percpu.h b/include/linux/percpu.h
index cc88172c7d9a..c74088ab103b 100644
--- a/include/linux/percpu.h
+++ b/include/linux/percpu.h
@@ -332,7 +332,7 @@ do { \
332#endif 332#endif
333 333
334#ifndef this_cpu_sub 334#ifndef this_cpu_sub
335# define this_cpu_sub(pcp, val) this_cpu_add((pcp), -(val)) 335# define this_cpu_sub(pcp, val) this_cpu_add((pcp), -(typeof(pcp))(val))
336#endif 336#endif
337 337
338#ifndef this_cpu_inc 338#ifndef this_cpu_inc
@@ -418,7 +418,7 @@ do { \
418# define this_cpu_add_return(pcp, val) __pcpu_size_call_return2(this_cpu_add_return_, pcp, val) 418# define this_cpu_add_return(pcp, val) __pcpu_size_call_return2(this_cpu_add_return_, pcp, val)
419#endif 419#endif
420 420
421#define this_cpu_sub_return(pcp, val) this_cpu_add_return(pcp, -(val)) 421#define this_cpu_sub_return(pcp, val) this_cpu_add_return(pcp, -(typeof(pcp))(val))
422#define this_cpu_inc_return(pcp) this_cpu_add_return(pcp, 1) 422#define this_cpu_inc_return(pcp) this_cpu_add_return(pcp, 1)
423#define this_cpu_dec_return(pcp) this_cpu_add_return(pcp, -1) 423#define this_cpu_dec_return(pcp) this_cpu_add_return(pcp, -1)
424 424
@@ -586,7 +586,7 @@ do { \
586#endif 586#endif
587 587
588#ifndef __this_cpu_sub 588#ifndef __this_cpu_sub
589# define __this_cpu_sub(pcp, val) __this_cpu_add((pcp), -(val)) 589# define __this_cpu_sub(pcp, val) __this_cpu_add((pcp), -(typeof(pcp))(val))
590#endif 590#endif
591 591
592#ifndef __this_cpu_inc 592#ifndef __this_cpu_inc
@@ -668,7 +668,7 @@ do { \
668 __pcpu_size_call_return2(__this_cpu_add_return_, pcp, val) 668 __pcpu_size_call_return2(__this_cpu_add_return_, pcp, val)
669#endif 669#endif
670 670
671#define __this_cpu_sub_return(pcp, val) __this_cpu_add_return(pcp, -(val)) 671#define __this_cpu_sub_return(pcp, val) __this_cpu_add_return(pcp, -(typeof(pcp))(val))
672#define __this_cpu_inc_return(pcp) __this_cpu_add_return(pcp, 1) 672#define __this_cpu_inc_return(pcp) __this_cpu_add_return(pcp, 1)
673#define __this_cpu_dec_return(pcp) __this_cpu_add_return(pcp, -1) 673#define __this_cpu_dec_return(pcp) __this_cpu_add_return(pcp, -1)
674 674
diff --git a/include/linux/phy/phy.h b/include/linux/phy/phy.h
new file mode 100644
index 000000000000..6d722695e027
--- /dev/null
+++ b/include/linux/phy/phy.h
@@ -0,0 +1,270 @@
1/*
2 * phy.h -- generic phy header file
3 *
4 * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com
5 *
6 * Author: Kishon Vijay Abraham I <kishon@ti.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 */
13
14#ifndef __DRIVERS_PHY_H
15#define __DRIVERS_PHY_H
16
17#include <linux/err.h>
18#include <linux/of.h>
19#include <linux/device.h>
20#include <linux/pm_runtime.h>
21
22struct phy;
23
24/**
25 * struct phy_ops - set of function pointers for performing phy operations
26 * @init: operation to be performed for initializing phy
27 * @exit: operation to be performed while exiting
28 * @power_on: powering on the phy
29 * @power_off: powering off the phy
30 * @owner: the module owner containing the ops
31 */
32struct phy_ops {
33 int (*init)(struct phy *phy);
34 int (*exit)(struct phy *phy);
35 int (*power_on)(struct phy *phy);
36 int (*power_off)(struct phy *phy);
37 struct module *owner;
38};
39
40/**
41 * struct phy - represents the phy device
42 * @dev: phy device
43 * @id: id of the phy device
44 * @ops: function pointers for performing phy operations
45 * @init_data: list of PHY consumers (non-dt only)
46 * @mutex: mutex to protect phy_ops
47 * @init_count: used to protect when the PHY is used by multiple consumers
48 * @power_count: used to protect when the PHY is used by multiple consumers
49 */
50struct phy {
51 struct device dev;
52 int id;
53 const struct phy_ops *ops;
54 struct phy_init_data *init_data;
55 struct mutex mutex;
56 int init_count;
57 int power_count;
58};
59
60/**
61 * struct phy_provider - represents the phy provider
62 * @dev: phy provider device
63 * @owner: the module owner having of_xlate
64 * @of_xlate: function pointer to obtain phy instance from phy pointer
65 * @list: to maintain a linked list of PHY providers
66 */
67struct phy_provider {
68 struct device *dev;
69 struct module *owner;
70 struct list_head list;
71 struct phy * (*of_xlate)(struct device *dev,
72 struct of_phandle_args *args);
73};
74
75/**
76 * struct phy_consumer - represents the phy consumer
77 * @dev_name: the device name of the controller that will use this PHY device
78 * @port: name given to the consumer port
79 */
80struct phy_consumer {
81 const char *dev_name;
82 const char *port;
83};
84
85/**
86 * struct phy_init_data - contains the list of PHY consumers
87 * @num_consumers: number of consumers for this PHY device
88 * @consumers: list of PHY consumers
89 */
90struct phy_init_data {
91 unsigned int num_consumers;
92 struct phy_consumer *consumers;
93};
94
95#define PHY_CONSUMER(_dev_name, _port) \
96{ \
97 .dev_name = _dev_name, \
98 .port = _port, \
99}
100
101#define to_phy(dev) (container_of((dev), struct phy, dev))
102
103#define of_phy_provider_register(dev, xlate) \
104 __of_phy_provider_register((dev), THIS_MODULE, (xlate))
105
106#define devm_of_phy_provider_register(dev, xlate) \
107 __devm_of_phy_provider_register((dev), THIS_MODULE, (xlate))
108
109static inline void phy_set_drvdata(struct phy *phy, void *data)
110{
111 dev_set_drvdata(&phy->dev, data);
112}
113
114static inline void *phy_get_drvdata(struct phy *phy)
115{
116 return dev_get_drvdata(&phy->dev);
117}
118
119#if IS_ENABLED(CONFIG_GENERIC_PHY)
120int phy_pm_runtime_get(struct phy *phy);
121int phy_pm_runtime_get_sync(struct phy *phy);
122int phy_pm_runtime_put(struct phy *phy);
123int phy_pm_runtime_put_sync(struct phy *phy);
124void phy_pm_runtime_allow(struct phy *phy);
125void phy_pm_runtime_forbid(struct phy *phy);
126int phy_init(struct phy *phy);
127int phy_exit(struct phy *phy);
128int phy_power_on(struct phy *phy);
129int phy_power_off(struct phy *phy);
130struct phy *phy_get(struct device *dev, const char *string);
131struct phy *devm_phy_get(struct device *dev, const char *string);
132void phy_put(struct phy *phy);
133void devm_phy_put(struct device *dev, struct phy *phy);
134struct phy *of_phy_simple_xlate(struct device *dev,
135 struct of_phandle_args *args);
136struct phy *phy_create(struct device *dev, const struct phy_ops *ops,
137 struct phy_init_data *init_data);
138struct phy *devm_phy_create(struct device *dev,
139 const struct phy_ops *ops, struct phy_init_data *init_data);
140void phy_destroy(struct phy *phy);
141void devm_phy_destroy(struct device *dev, struct phy *phy);
142struct phy_provider *__of_phy_provider_register(struct device *dev,
143 struct module *owner, struct phy * (*of_xlate)(struct device *dev,
144 struct of_phandle_args *args));
145struct phy_provider *__devm_of_phy_provider_register(struct device *dev,
146 struct module *owner, struct phy * (*of_xlate)(struct device *dev,
147 struct of_phandle_args *args));
148void of_phy_provider_unregister(struct phy_provider *phy_provider);
149void devm_of_phy_provider_unregister(struct device *dev,
150 struct phy_provider *phy_provider);
151#else
152static inline int phy_pm_runtime_get(struct phy *phy)
153{
154 return -ENOSYS;
155}
156
157static inline int phy_pm_runtime_get_sync(struct phy *phy)
158{
159 return -ENOSYS;
160}
161
162static inline int phy_pm_runtime_put(struct phy *phy)
163{
164 return -ENOSYS;
165}
166
167static inline int phy_pm_runtime_put_sync(struct phy *phy)
168{
169 return -ENOSYS;
170}
171
172static inline void phy_pm_runtime_allow(struct phy *phy)
173{
174 return;
175}
176
177static inline void phy_pm_runtime_forbid(struct phy *phy)
178{
179 return;
180}
181
182static inline int phy_init(struct phy *phy)
183{
184 return -ENOSYS;
185}
186
187static inline int phy_exit(struct phy *phy)
188{
189 return -ENOSYS;
190}
191
192static inline int phy_power_on(struct phy *phy)
193{
194 return -ENOSYS;
195}
196
197static inline int phy_power_off(struct phy *phy)
198{
199 return -ENOSYS;
200}
201
202static inline struct phy *phy_get(struct device *dev, const char *string)
203{
204 return ERR_PTR(-ENOSYS);
205}
206
207static inline struct phy *devm_phy_get(struct device *dev, const char *string)
208{
209 return ERR_PTR(-ENOSYS);
210}
211
212static inline void phy_put(struct phy *phy)
213{
214}
215
216static inline void devm_phy_put(struct device *dev, struct phy *phy)
217{
218}
219
220static inline struct phy *of_phy_simple_xlate(struct device *dev,
221 struct of_phandle_args *args)
222{
223 return ERR_PTR(-ENOSYS);
224}
225
226static inline struct phy *phy_create(struct device *dev,
227 const struct phy_ops *ops, struct phy_init_data *init_data)
228{
229 return ERR_PTR(-ENOSYS);
230}
231
232static inline struct phy *devm_phy_create(struct device *dev,
233 const struct phy_ops *ops, struct phy_init_data *init_data)
234{
235 return ERR_PTR(-ENOSYS);
236}
237
238static inline void phy_destroy(struct phy *phy)
239{
240}
241
242static inline void devm_phy_destroy(struct device *dev, struct phy *phy)
243{
244}
245
246static inline struct phy_provider *__of_phy_provider_register(
247 struct device *dev, struct module *owner, struct phy * (*of_xlate)(
248 struct device *dev, struct of_phandle_args *args))
249{
250 return ERR_PTR(-ENOSYS);
251}
252
253static inline struct phy_provider *__devm_of_phy_provider_register(struct device
254 *dev, struct module *owner, struct phy * (*of_xlate)(struct device *dev,
255 struct of_phandle_args *args))
256{
257 return ERR_PTR(-ENOSYS);
258}
259
260static inline void of_phy_provider_unregister(struct phy_provider *phy_provider)
261{
262}
263
264static inline void devm_of_phy_provider_unregister(struct device *dev,
265 struct phy_provider *phy_provider)
266{
267}
268#endif
269
270#endif /* __DRIVERS_PHY_H */
diff --git a/include/linux/platform_data/mipi-csis.h b/include/linux/platform_data/mipi-csis.h
index bf34e17cee7f..c2fd9024717c 100644
--- a/include/linux/platform_data/mipi-csis.h
+++ b/include/linux/platform_data/mipi-csis.h
@@ -25,13 +25,4 @@ struct s5p_platform_mipi_csis {
25 u8 hs_settle; 25 u8 hs_settle;
26}; 26};
27 27
28/**
29 * s5p_csis_phy_enable - global MIPI-CSI receiver D-PHY control
30 * @id: MIPI-CSIS harware instance index (0...1)
31 * @on: true to enable D-PHY and deassert its reset
32 * false to disable D-PHY
33 * @return: 0 on success, or negative error code on failure
34 */
35int s5p_csis_phy_enable(int id, bool on);
36
37#endif /* __PLAT_SAMSUNG_MIPI_CSIS_H_ */ 28#endif /* __PLAT_SAMSUNG_MIPI_CSIS_H_ */
diff --git a/include/linux/platform_data/usb-ehci-s5p.h b/include/linux/platform_data/usb-ehci-s5p.h
deleted file mode 100644
index 5f28cae18582..000000000000
--- a/include/linux/platform_data/usb-ehci-s5p.h
+++ /dev/null
@@ -1,21 +0,0 @@
1/*
2 * Copyright (C) 2011 Samsung Electronics Co.Ltd
3 * Author: Joonyoung Shim <jy0922.shim@samsung.com>
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version.
9 */
10
11#ifndef __PLAT_SAMSUNG_EHCI_H
12#define __PLAT_SAMSUNG_EHCI_H __FILE__
13
14struct s5p_ehci_platdata {
15 int (*phy_init)(struct platform_device *pdev, int type);
16 int (*phy_exit)(struct platform_device *pdev, int type);
17};
18
19extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
20
21#endif /* __PLAT_SAMSUNG_EHCI_H */
diff --git a/include/linux/platform_data/usb-ohci-exynos.h b/include/linux/platform_data/usb-ohci-exynos.h
deleted file mode 100644
index c256c595be5e..000000000000
--- a/include/linux/platform_data/usb-ohci-exynos.h
+++ /dev/null
@@ -1,21 +0,0 @@
1/*
2 * Copyright (C) 2011 Samsung Electronics Co.Ltd
3 * http://www.samsung.com/
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version.
9 */
10
11#ifndef __MACH_EXYNOS_OHCI_H
12#define __MACH_EXYNOS_OHCI_H
13
14struct exynos4_ohci_platdata {
15 int (*phy_init)(struct platform_device *pdev, int type);
16 int (*phy_exit)(struct platform_device *pdev, int type);
17};
18
19extern void exynos4_ohci_set_platdata(struct exynos4_ohci_platdata *pd);
20
21#endif /* __MACH_EXYNOS_OHCI_H */
diff --git a/include/linux/platform_data/usb-rcar-gen2-phy.h b/include/linux/platform_data/usb-rcar-gen2-phy.h
new file mode 100644
index 000000000000..dd3ba46c0d90
--- /dev/null
+++ b/include/linux/platform_data/usb-rcar-gen2-phy.h
@@ -0,0 +1,22 @@
1/*
2 * Copyright (C) 2013 Renesas Solutions Corp.
3 * Copyright (C) 2013 Cogent Embedded, Inc.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 */
9
10#ifndef __USB_RCAR_GEN2_PHY_H
11#define __USB_RCAR_GEN2_PHY_H
12
13#include <linux/types.h>
14
15struct rcar_gen2_phy_platform_data {
16 /* USB channel 0 configuration */
17 bool chan0_pci:1; /* true: PCI USB host 0, false: USBHS */
18 /* USB channel 2 configuration */
19 bool chan2_pci:1; /* true: PCI USB host 2, false: USBSS */
20};
21
22#endif
diff --git a/include/linux/printk.h b/include/linux/printk.h
index e6131a782481..694925837a16 100644
--- a/include/linux/printk.h
+++ b/include/linux/printk.h
@@ -233,6 +233,8 @@ extern asmlinkage void dump_stack(void) __cold;
233 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) 233 no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
234#endif 234#endif
235 235
236#include <linux/dynamic_debug.h>
237
236/* If you are writing a driver, please use dev_dbg instead */ 238/* If you are writing a driver, please use dev_dbg instead */
237#if defined(CONFIG_DYNAMIC_DEBUG) 239#if defined(CONFIG_DYNAMIC_DEBUG)
238/* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */ 240/* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */
@@ -343,7 +345,19 @@ extern asmlinkage void dump_stack(void) __cold;
343#endif 345#endif
344 346
345/* If you are writing a driver, please use dev_dbg instead */ 347/* If you are writing a driver, please use dev_dbg instead */
346#if defined(DEBUG) 348#if defined(CONFIG_DYNAMIC_DEBUG)
349/* descriptor check is first to prevent flooding with "callbacks suppressed" */
350#define pr_debug_ratelimited(fmt, ...) \
351do { \
352 static DEFINE_RATELIMIT_STATE(_rs, \
353 DEFAULT_RATELIMIT_INTERVAL, \
354 DEFAULT_RATELIMIT_BURST); \
355 DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \
356 if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT) && \
357 __ratelimit(&_rs)) \
358 __dynamic_pr_debug(&descriptor, fmt, ##__VA_ARGS__); \
359} while (0)
360#elif defined(DEBUG)
347#define pr_debug_ratelimited(fmt, ...) \ 361#define pr_debug_ratelimited(fmt, ...) \
348 printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) 362 printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
349#else 363#else
diff --git a/include/linux/usb.h b/include/linux/usb.h
index 001629cd1a97..7454865ad148 100644
--- a/include/linux/usb.h
+++ b/include/linux/usb.h
@@ -475,7 +475,8 @@ struct usb3_lpm_parameters {
475 * @lpm_capable: device supports LPM 475 * @lpm_capable: device supports LPM
476 * @usb2_hw_lpm_capable: device can perform USB2 hardware LPM 476 * @usb2_hw_lpm_capable: device can perform USB2 hardware LPM
477 * @usb2_hw_lpm_besl_capable: device can perform USB2 hardware BESL LPM 477 * @usb2_hw_lpm_besl_capable: device can perform USB2 hardware BESL LPM
478 * @usb2_hw_lpm_enabled: USB2 hardware LPM enabled 478 * @usb2_hw_lpm_enabled: USB2 hardware LPM is enabled
479 * @usb2_hw_lpm_allowed: Userspace allows USB 2.0 LPM to be enabled
479 * @usb3_lpm_enabled: USB3 hardware LPM enabled 480 * @usb3_lpm_enabled: USB3 hardware LPM enabled
480 * @string_langid: language ID for strings 481 * @string_langid: language ID for strings
481 * @product: iProduct string, if present (static) 482 * @product: iProduct string, if present (static)
@@ -548,6 +549,7 @@ struct usb_device {
548 unsigned usb2_hw_lpm_capable:1; 549 unsigned usb2_hw_lpm_capable:1;
549 unsigned usb2_hw_lpm_besl_capable:1; 550 unsigned usb2_hw_lpm_besl_capable:1;
550 unsigned usb2_hw_lpm_enabled:1; 551 unsigned usb2_hw_lpm_enabled:1;
552 unsigned usb2_hw_lpm_allowed:1;
551 unsigned usb3_lpm_enabled:1; 553 unsigned usb3_lpm_enabled:1;
552 int string_langid; 554 int string_langid;
553 555
@@ -702,7 +704,7 @@ extern int usb_alloc_streams(struct usb_interface *interface,
702 unsigned int num_streams, gfp_t mem_flags); 704 unsigned int num_streams, gfp_t mem_flags);
703 705
704/* Reverts a group of bulk endpoints back to not using stream IDs. */ 706/* Reverts a group of bulk endpoints back to not using stream IDs. */
705extern void usb_free_streams(struct usb_interface *interface, 707extern int usb_free_streams(struct usb_interface *interface,
706 struct usb_host_endpoint **eps, unsigned int num_eps, 708 struct usb_host_endpoint **eps, unsigned int num_eps,
707 gfp_t mem_flags); 709 gfp_t mem_flags);
708 710
@@ -1209,11 +1211,13 @@ struct usb_anchor {
1209 struct list_head urb_list; 1211 struct list_head urb_list;
1210 wait_queue_head_t wait; 1212 wait_queue_head_t wait;
1211 spinlock_t lock; 1213 spinlock_t lock;
1214 atomic_t suspend_wakeups;
1212 unsigned int poisoned:1; 1215 unsigned int poisoned:1;
1213}; 1216};
1214 1217
1215static inline void init_usb_anchor(struct usb_anchor *anchor) 1218static inline void init_usb_anchor(struct usb_anchor *anchor)
1216{ 1219{
1220 memset(anchor, 0, sizeof(*anchor));
1217 INIT_LIST_HEAD(&anchor->urb_list); 1221 INIT_LIST_HEAD(&anchor->urb_list);
1218 init_waitqueue_head(&anchor->wait); 1222 init_waitqueue_head(&anchor->wait);
1219 spin_lock_init(&anchor->lock); 1223 spin_lock_init(&anchor->lock);
@@ -1574,6 +1578,8 @@ extern void usb_kill_anchored_urbs(struct usb_anchor *anchor);
1574extern void usb_poison_anchored_urbs(struct usb_anchor *anchor); 1578extern void usb_poison_anchored_urbs(struct usb_anchor *anchor);
1575extern void usb_unpoison_anchored_urbs(struct usb_anchor *anchor); 1579extern void usb_unpoison_anchored_urbs(struct usb_anchor *anchor);
1576extern void usb_unlink_anchored_urbs(struct usb_anchor *anchor); 1580extern void usb_unlink_anchored_urbs(struct usb_anchor *anchor);
1581extern void usb_anchor_suspend_wakeups(struct usb_anchor *anchor);
1582extern void usb_anchor_resume_wakeups(struct usb_anchor *anchor);
1577extern void usb_anchor_urb(struct urb *urb, struct usb_anchor *anchor); 1583extern void usb_anchor_urb(struct urb *urb, struct usb_anchor *anchor);
1578extern void usb_unanchor_urb(struct urb *urb); 1584extern void usb_unanchor_urb(struct urb *urb);
1579extern int usb_wait_anchor_empty_timeout(struct usb_anchor *anchor, 1585extern int usb_wait_anchor_empty_timeout(struct usb_anchor *anchor,
diff --git a/include/linux/usb/hcd.h b/include/linux/usb/hcd.h
index 75efc45eaa2f..b8aba196f7f1 100644
--- a/include/linux/usb/hcd.h
+++ b/include/linux/usb/hcd.h
@@ -73,6 +73,7 @@ struct giveback_urb_bh {
73 spinlock_t lock; 73 spinlock_t lock;
74 struct list_head head; 74 struct list_head head;
75 struct tasklet_struct bh; 75 struct tasklet_struct bh;
76 struct usb_host_endpoint *completing_ep;
76}; 77};
77 78
78struct usb_hcd { 79struct usb_hcd {
@@ -140,6 +141,7 @@ struct usb_hcd {
140 unsigned wireless:1; /* Wireless USB HCD */ 141 unsigned wireless:1; /* Wireless USB HCD */
141 unsigned authorized_default:1; 142 unsigned authorized_default:1;
142 unsigned has_tt:1; /* Integrated TT in root hub */ 143 unsigned has_tt:1; /* Integrated TT in root hub */
144 unsigned amd_resume_bug:1; /* AMD remote wakeup quirk */
143 145
144 unsigned int irq; /* irq allocated */ 146 unsigned int irq; /* irq allocated */
145 void __iomem *regs; /* device memory/io */ 147 void __iomem *regs; /* device memory/io */
@@ -378,6 +380,12 @@ static inline int hcd_giveback_urb_in_bh(struct usb_hcd *hcd)
378 return hcd->driver->flags & HCD_BH; 380 return hcd->driver->flags & HCD_BH;
379} 381}
380 382
383static inline bool hcd_periodic_completion_in_progress(struct usb_hcd *hcd,
384 struct usb_host_endpoint *ep)
385{
386 return hcd->high_prio_bh.completing_ep == ep;
387}
388
381extern int usb_hcd_link_urb_to_ep(struct usb_hcd *hcd, struct urb *urb); 389extern int usb_hcd_link_urb_to_ep(struct usb_hcd *hcd, struct urb *urb);
382extern int usb_hcd_check_unlink_urb(struct usb_hcd *hcd, struct urb *urb, 390extern int usb_hcd_check_unlink_urb(struct usb_hcd *hcd, struct urb *urb,
383 int status); 391 int status);
@@ -428,6 +436,8 @@ extern int usb_hcd_pci_probe(struct pci_dev *dev,
428extern void usb_hcd_pci_remove(struct pci_dev *dev); 436extern void usb_hcd_pci_remove(struct pci_dev *dev);
429extern void usb_hcd_pci_shutdown(struct pci_dev *dev); 437extern void usb_hcd_pci_shutdown(struct pci_dev *dev);
430 438
439extern int usb_hcd_amd_remote_wakeup_quirk(struct pci_dev *dev);
440
431#ifdef CONFIG_PM 441#ifdef CONFIG_PM
432extern const struct dev_pm_ops usb_hcd_pci_pm_ops; 442extern const struct dev_pm_ops usb_hcd_pci_pm_ops;
433#endif 443#endif
@@ -496,6 +506,7 @@ struct usb_tt {
496 struct usb_device *hub; /* upstream highspeed hub */ 506 struct usb_device *hub; /* upstream highspeed hub */
497 int multi; /* true means one TT per port */ 507 int multi; /* true means one TT per port */
498 unsigned think_time; /* think time in ns */ 508 unsigned think_time; /* think time in ns */
509 void *hcpriv; /* HCD private data */
499 510
500 /* for control/bulk error recovery (CLEAR_TT_BUFFER) */ 511 /* for control/bulk error recovery (CLEAR_TT_BUFFER) */
501 spinlock_t lock; 512 spinlock_t lock;
@@ -554,9 +565,8 @@ extern void usb_ep0_reinit(struct usb_device *);
554 * of (7/6 * 8 * bytecount) = 9.33 * bytecount */ 565 * of (7/6 * 8 * bytecount) = 9.33 * bytecount */
555 /* bytecount = data payload byte count */ 566 /* bytecount = data payload byte count */
556 567
557#define NS_TO_US(ns) ((ns + 500L) / 1000L) 568#define NS_TO_US(ns) DIV_ROUND_UP(ns, 1000L)
558 /* convert & round nanoseconds to microseconds */ 569 /* convert nanoseconds to microseconds, rounding up */
559
560 570
561/* 571/*
562 * Full/low speed bandwidth allocation constants/support. 572 * Full/low speed bandwidth allocation constants/support.
diff --git a/include/linux/usb/intel_mid_otg.h b/include/linux/usb/intel_mid_otg.h
deleted file mode 100644
index 756cf5543ffd..000000000000
--- a/include/linux/usb/intel_mid_otg.h
+++ /dev/null
@@ -1,180 +0,0 @@
1/*
2 * Intel MID (Langwell/Penwell) USB OTG Transceiver driver
3 * Copyright (C) 2008 - 2010, Intel Corporation.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
17 *
18 */
19
20#ifndef __INTEL_MID_OTG_H
21#define __INTEL_MID_OTG_H
22
23#include <linux/pm.h>
24#include <linux/usb/otg.h>
25#include <linux/notifier.h>
26
27struct intel_mid_otg_xceiv;
28
29/* This is a common data structure for Intel MID platform to
30 * save values of the OTG state machine */
31struct otg_hsm {
32 /* Input */
33 int a_bus_resume;
34 int a_bus_suspend;
35 int a_conn;
36 int a_sess_vld;
37 int a_srp_det;
38 int a_vbus_vld;
39 int b_bus_resume;
40 int b_bus_suspend;
41 int b_conn;
42 int b_se0_srp;
43 int b_ssend_srp;
44 int b_sess_end;
45 int b_sess_vld;
46 int id;
47/* id values */
48#define ID_B 0x05
49#define ID_A 0x04
50#define ID_ACA_C 0x03
51#define ID_ACA_B 0x02
52#define ID_ACA_A 0x01
53 int power_up;
54 int adp_change;
55 int test_device;
56
57 /* Internal variables */
58 int a_set_b_hnp_en;
59 int b_srp_done;
60 int b_hnp_enable;
61 int hnp_poll_enable;
62
63 /* Timeout indicator for timers */
64 int a_wait_vrise_tmout;
65 int a_wait_bcon_tmout;
66 int a_aidl_bdis_tmout;
67 int a_bidl_adis_tmout;
68 int a_bidl_adis_tmr;
69 int a_wait_vfall_tmout;
70 int b_ase0_brst_tmout;
71 int b_bus_suspend_tmout;
72 int b_srp_init_tmout;
73 int b_srp_fail_tmout;
74 int b_srp_fail_tmr;
75 int b_adp_sense_tmout;
76
77 /* Informative variables */
78 int a_bus_drop;
79 int a_bus_req;
80 int a_clr_err;
81 int b_bus_req;
82 int a_suspend_req;
83 int b_bus_suspend_vld;
84
85 /* Output */
86 int drv_vbus;
87 int loc_conn;
88 int loc_sof;
89
90 /* Others */
91 int vbus_srp_up;
92};
93
94/* must provide ULPI access function to read/write registers implemented in
95 * ULPI address space */
96struct iotg_ulpi_access_ops {
97 int (*read)(struct intel_mid_otg_xceiv *iotg, u8 reg, u8 *val);
98 int (*write)(struct intel_mid_otg_xceiv *iotg, u8 reg, u8 val);
99};
100
101#define OTG_A_DEVICE 0x0
102#define OTG_B_DEVICE 0x1
103
104/*
105 * the Intel MID (Langwell/Penwell) otg transceiver driver needs to interact
106 * with device and host drivers to implement the USB OTG related feature. More
107 * function members are added based on usb_phy data structure for this
108 * purpose.
109 */
110struct intel_mid_otg_xceiv {
111 struct usb_phy otg;
112 struct otg_hsm hsm;
113
114 /* base address */
115 void __iomem *base;
116
117 /* ops to access ulpi */
118 struct iotg_ulpi_access_ops ulpi_ops;
119
120 /* atomic notifier for interrupt context */
121 struct atomic_notifier_head iotg_notifier;
122
123 /* start/stop USB Host function */
124 int (*start_host)(struct intel_mid_otg_xceiv *iotg);
125 int (*stop_host)(struct intel_mid_otg_xceiv *iotg);
126
127 /* start/stop USB Peripheral function */
128 int (*start_peripheral)(struct intel_mid_otg_xceiv *iotg);
129 int (*stop_peripheral)(struct intel_mid_otg_xceiv *iotg);
130
131 /* start/stop ADP sense/probe function */
132 int (*set_adp_probe)(struct intel_mid_otg_xceiv *iotg,
133 bool enabled, int dev);
134 int (*set_adp_sense)(struct intel_mid_otg_xceiv *iotg,
135 bool enabled);
136
137#ifdef CONFIG_PM
138 /* suspend/resume USB host function */
139 int (*suspend_host)(struct intel_mid_otg_xceiv *iotg,
140 pm_message_t message);
141 int (*resume_host)(struct intel_mid_otg_xceiv *iotg);
142
143 int (*suspend_peripheral)(struct intel_mid_otg_xceiv *iotg,
144 pm_message_t message);
145 int (*resume_peripheral)(struct intel_mid_otg_xceiv *iotg);
146#endif
147
148};
149static inline
150struct intel_mid_otg_xceiv *otg_to_mid_xceiv(struct usb_phy *otg)
151{
152 return container_of(otg, struct intel_mid_otg_xceiv, otg);
153}
154
155#define MID_OTG_NOTIFY_CONNECT 0x0001
156#define MID_OTG_NOTIFY_DISCONN 0x0002
157#define MID_OTG_NOTIFY_HSUSPEND 0x0003
158#define MID_OTG_NOTIFY_HRESUME 0x0004
159#define MID_OTG_NOTIFY_CSUSPEND 0x0005
160#define MID_OTG_NOTIFY_CRESUME 0x0006
161#define MID_OTG_NOTIFY_HOSTADD 0x0007
162#define MID_OTG_NOTIFY_HOSTREMOVE 0x0008
163#define MID_OTG_NOTIFY_CLIENTADD 0x0009
164#define MID_OTG_NOTIFY_CLIENTREMOVE 0x000a
165
166static inline int
167intel_mid_otg_register_notifier(struct intel_mid_otg_xceiv *iotg,
168 struct notifier_block *nb)
169{
170 return atomic_notifier_chain_register(&iotg->iotg_notifier, nb);
171}
172
173static inline void
174intel_mid_otg_unregister_notifier(struct intel_mid_otg_xceiv *iotg,
175 struct notifier_block *nb)
176{
177 atomic_notifier_chain_unregister(&iotg->iotg_notifier, nb);
178}
179
180#endif /* __INTEL_MID_OTG_H */
diff --git a/include/linux/usb/musb.h b/include/linux/usb/musb.h
index 053c26841cc3..eb505250940a 100644
--- a/include/linux/usb/musb.h
+++ b/include/linux/usb/musb.h
@@ -99,8 +99,6 @@ struct musb_hdrc_platform_data {
99 /* MUSB_HOST, MUSB_PERIPHERAL, or MUSB_OTG */ 99 /* MUSB_HOST, MUSB_PERIPHERAL, or MUSB_OTG */
100 u8 mode; 100 u8 mode;
101 101
102 u8 has_mailbox:1;
103
104 /* for clk_get() */ 102 /* for clk_get() */
105 const char *clock; 103 const char *clock;
106 104
diff --git a/include/linux/usb/omap_control_usb.h b/include/linux/usb/omap_control_usb.h
index 27b5b8c931b0..596b01918813 100644
--- a/include/linux/usb/omap_control_usb.h
+++ b/include/linux/usb/omap_control_usb.h
@@ -19,20 +19,23 @@
19#ifndef __OMAP_CONTROL_USB_H__ 19#ifndef __OMAP_CONTROL_USB_H__
20#define __OMAP_CONTROL_USB_H__ 20#define __OMAP_CONTROL_USB_H__
21 21
22enum omap_control_usb_type {
23 OMAP_CTRL_TYPE_OTGHS = 1, /* Mailbox OTGHS_CONTROL */
24 OMAP_CTRL_TYPE_USB2, /* USB2_PHY, power down in CONTROL_DEV_CONF */
25 OMAP_CTRL_TYPE_PIPE3, /* PIPE3 PHY, DPLL & seperate Rx/Tx power */
26 OMAP_CTRL_TYPE_DRA7USB2, /* USB2 PHY, power and power_aux e.g. DRA7 */
27};
28
22struct omap_control_usb { 29struct omap_control_usb {
23 struct device *dev; 30 struct device *dev;
24 31
25 u32 __iomem *dev_conf;
26 u32 __iomem *otghs_control; 32 u32 __iomem *otghs_control;
27 u32 __iomem *phy_power; 33 u32 __iomem *power;
34 u32 __iomem *power_aux;
28 35
29 struct clk *sys_clk; 36 struct clk *sys_clk;
30 37
31 u32 type; 38 enum omap_control_usb_type type;
32};
33
34struct omap_control_usb_platform_data {
35 u8 type;
36}; 39};
37 40
38enum omap_control_usb_mode { 41enum omap_control_usb_mode {
@@ -42,10 +45,6 @@ enum omap_control_usb_mode {
42 USB_MODE_DISCONNECT, 45 USB_MODE_DISCONNECT,
43}; 46};
44 47
45/* To differentiate ctrl module IP having either mailbox or USB3 PHY power */
46#define OMAP_CTRL_DEV_TYPE1 0x1
47#define OMAP_CTRL_DEV_TYPE2 0x2
48
49#define OMAP_CTRL_DEV_PHY_PD BIT(0) 48#define OMAP_CTRL_DEV_PHY_PD BIT(0)
50 49
51#define OMAP_CTRL_DEV_AVALID BIT(0) 50#define OMAP_CTRL_DEV_AVALID BIT(0)
@@ -63,26 +62,18 @@ enum omap_control_usb_mode {
63#define OMAP_CTRL_USB3_PHY_TX_RX_POWERON 0x3 62#define OMAP_CTRL_USB3_PHY_TX_RX_POWERON 0x3
64#define OMAP_CTRL_USB3_PHY_TX_RX_POWEROFF 0x0 63#define OMAP_CTRL_USB3_PHY_TX_RX_POWEROFF 0x0
65 64
65#define OMAP_CTRL_USB2_PHY_PD BIT(28)
66
66#if IS_ENABLED(CONFIG_OMAP_CONTROL_USB) 67#if IS_ENABLED(CONFIG_OMAP_CONTROL_USB)
67extern struct device *omap_get_control_dev(void);
68extern void omap_control_usb_phy_power(struct device *dev, int on); 68extern void omap_control_usb_phy_power(struct device *dev, int on);
69extern void omap_control_usb3_phy_power(struct device *dev, bool on);
70extern void omap_control_usb_set_mode(struct device *dev, 69extern void omap_control_usb_set_mode(struct device *dev,
71 enum omap_control_usb_mode mode); 70 enum omap_control_usb_mode mode);
72#else 71#else
73static inline struct device *omap_get_control_dev(void)
74{
75 return ERR_PTR(-ENODEV);
76}
77 72
78static inline void omap_control_usb_phy_power(struct device *dev, int on) 73static inline void omap_control_usb_phy_power(struct device *dev, int on)
79{ 74{
80} 75}
81 76
82static inline void omap_control_usb3_phy_power(struct device *dev, int on)
83{
84}
85
86static inline void omap_control_usb_set_mode(struct device *dev, 77static inline void omap_control_usb_set_mode(struct device *dev,
87 enum omap_control_usb_mode mode) 78 enum omap_control_usb_mode mode)
88{ 79{
diff --git a/include/linux/usb/serial.h b/include/linux/usb/serial.h
index d528b8045150..704a1ab8240c 100644
--- a/include/linux/usb/serial.h
+++ b/include/linux/usb/serial.h
@@ -320,6 +320,8 @@ extern struct usb_serial_port *usb_serial_port_get_by_minor(unsigned int minor);
320extern void usb_serial_put(struct usb_serial *serial); 320extern void usb_serial_put(struct usb_serial *serial);
321extern int usb_serial_generic_open(struct tty_struct *tty, 321extern int usb_serial_generic_open(struct tty_struct *tty,
322 struct usb_serial_port *port); 322 struct usb_serial_port *port);
323extern int usb_serial_generic_write_start(struct usb_serial_port *port,
324 gfp_t mem_flags);
323extern int usb_serial_generic_write(struct tty_struct *tty, 325extern int usb_serial_generic_write(struct tty_struct *tty,
324 struct usb_serial_port *port, const unsigned char *buf, int count); 326 struct usb_serial_port *port, const unsigned char *buf, int count);
325extern void usb_serial_generic_close(struct usb_serial_port *port); 327extern void usb_serial_generic_close(struct usb_serial_port *port);
diff --git a/include/linux/usb/usb_phy_gen_xceiv.h b/include/linux/usb/usb_phy_gen_xceiv.h
index 11d85b9c1b08..cc8d818a83be 100644
--- a/include/linux/usb/usb_phy_gen_xceiv.h
+++ b/include/linux/usb/usb_phy_gen_xceiv.h
@@ -9,7 +9,8 @@ struct usb_phy_gen_xceiv_platform_data {
9 9
10 /* if set fails with -EPROBE_DEFER if can't get regulator */ 10 /* if set fails with -EPROBE_DEFER if can't get regulator */
11 unsigned int needs_vcc:1; 11 unsigned int needs_vcc:1;
12 unsigned int needs_reset:1; 12 unsigned int needs_reset:1; /* deprecated */
13 int gpio_reset;
13}; 14};
14 15
15#if defined(CONFIG_NOP_USB_XCEIV) || (defined(CONFIG_NOP_USB_XCEIV_MODULE) && defined(MODULE)) 16#if defined(CONFIG_NOP_USB_XCEIV) || (defined(CONFIG_NOP_USB_XCEIV_MODULE) && defined(MODULE))
diff --git a/include/linux/usb/wusb-wa.h b/include/linux/usb/wusb-wa.h
index 4ff744e2b678..c1257130769b 100644
--- a/include/linux/usb/wusb-wa.h
+++ b/include/linux/usb/wusb-wa.h
@@ -142,7 +142,7 @@ enum wa_notif_type {
142struct wa_notif_hdr { 142struct wa_notif_hdr {
143 u8 bLength; 143 u8 bLength;
144 u8 bNotifyType; /* enum wa_notif_type */ 144 u8 bNotifyType; /* enum wa_notif_type */
145} __attribute__((packed)); 145} __packed;
146 146
147/** 147/**
148 * HWA DN Received notification [(WUSB] section 8.5.4.2) 148 * HWA DN Received notification [(WUSB] section 8.5.4.2)
@@ -158,7 +158,7 @@ struct hwa_notif_dn {
158 u8 bSourceDeviceAddr; /* from errata 2005/07 */ 158 u8 bSourceDeviceAddr; /* from errata 2005/07 */
159 u8 bmAttributes; 159 u8 bmAttributes;
160 struct wusb_dn_hdr dndata[]; 160 struct wusb_dn_hdr dndata[];
161} __attribute__((packed)); 161} __packed;
162 162
163/* [WUSB] section 8.3.3 */ 163/* [WUSB] section 8.3.3 */
164enum wa_xfer_type { 164enum wa_xfer_type {
@@ -167,6 +167,8 @@ enum wa_xfer_type {
167 WA_XFER_TYPE_ISO = 0x82, 167 WA_XFER_TYPE_ISO = 0x82,
168 WA_XFER_RESULT = 0x83, 168 WA_XFER_RESULT = 0x83,
169 WA_XFER_ABORT = 0x84, 169 WA_XFER_ABORT = 0x84,
170 WA_XFER_ISO_PACKET_INFO = 0xA0,
171 WA_XFER_ISO_PACKET_STATUS = 0xA1,
170}; 172};
171 173
172/* [WUSB] section 8.3.3 */ 174/* [WUSB] section 8.3.3 */
@@ -177,28 +179,47 @@ struct wa_xfer_hdr {
177 __le32 dwTransferID; /* Host-assigned ID */ 179 __le32 dwTransferID; /* Host-assigned ID */
178 __le32 dwTransferLength; /* Length of data to xfer */ 180 __le32 dwTransferLength; /* Length of data to xfer */
179 u8 bTransferSegment; 181 u8 bTransferSegment;
180} __attribute__((packed)); 182} __packed;
181 183
182struct wa_xfer_ctl { 184struct wa_xfer_ctl {
183 struct wa_xfer_hdr hdr; 185 struct wa_xfer_hdr hdr;
184 u8 bmAttribute; 186 u8 bmAttribute;
185 __le16 wReserved; 187 __le16 wReserved;
186 struct usb_ctrlrequest baSetupData; 188 struct usb_ctrlrequest baSetupData;
187} __attribute__((packed)); 189} __packed;
188 190
189struct wa_xfer_bi { 191struct wa_xfer_bi {
190 struct wa_xfer_hdr hdr; 192 struct wa_xfer_hdr hdr;
191 u8 bReserved; 193 u8 bReserved;
192 __le16 wReserved; 194 __le16 wReserved;
193} __attribute__((packed)); 195} __packed;
194 196
197/* [WUSB] section 8.5.5 */
195struct wa_xfer_hwaiso { 198struct wa_xfer_hwaiso {
196 struct wa_xfer_hdr hdr; 199 struct wa_xfer_hdr hdr;
197 u8 bReserved; 200 u8 bReserved;
198 __le16 wPresentationTime; 201 __le16 wPresentationTime;
199 __le32 dwNumOfPackets; 202 __le32 dwNumOfPackets;
200 /* FIXME: u8 pktdata[]? */ 203} __packed;
201} __attribute__((packed)); 204
205struct wa_xfer_packet_info_hwaiso {
206 __le16 wLength;
207 u8 bPacketType;
208 u8 bReserved;
209 __le16 PacketLength[0];
210} __packed;
211
212struct wa_xfer_packet_status_len_hwaiso {
213 __le16 PacketLength;
214 __le16 PacketStatus;
215} __packed;
216
217struct wa_xfer_packet_status_hwaiso {
218 __le16 wLength;
219 u8 bPacketType;
220 u8 bReserved;
221 struct wa_xfer_packet_status_len_hwaiso PacketStatus[0];
222} __packed;
202 223
203/* [WUSB] section 8.3.3.5 */ 224/* [WUSB] section 8.3.3.5 */
204struct wa_xfer_abort { 225struct wa_xfer_abort {
@@ -206,7 +227,7 @@ struct wa_xfer_abort {
206 u8 bRequestType; 227 u8 bRequestType;
207 __le16 wRPipe; /* RPipe index */ 228 __le16 wRPipe; /* RPipe index */
208 __le32 dwTransferID; /* Host-assigned ID */ 229 __le32 dwTransferID; /* Host-assigned ID */
209} __attribute__((packed)); 230} __packed;
210 231
211/** 232/**
212 * WA Transfer Complete notification ([WUSB] section 8.3.3.3) 233 * WA Transfer Complete notification ([WUSB] section 8.3.3.3)
@@ -216,7 +237,7 @@ struct wa_notif_xfer {
216 struct wa_notif_hdr hdr; 237 struct wa_notif_hdr hdr;
217 u8 bEndpoint; 238 u8 bEndpoint;
218 u8 Reserved; 239 u8 Reserved;
219} __attribute__((packed)); 240} __packed;
220 241
221/** Transfer result basic codes [WUSB] table 8-15 */ 242/** Transfer result basic codes [WUSB] table 8-15 */
222enum { 243enum {
@@ -243,7 +264,7 @@ struct wa_xfer_result {
243 u8 bTransferSegment; 264 u8 bTransferSegment;
244 u8 bTransferStatus; 265 u8 bTransferStatus;
245 __le32 dwNumOfPackets; 266 __le32 dwNumOfPackets;
246} __attribute__((packed)); 267} __packed;
247 268
248/** 269/**
249 * Wire Adapter Class Descriptor ([WUSB] section 8.5.2.7). 270 * Wire Adapter Class Descriptor ([WUSB] section 8.5.2.7).
@@ -258,16 +279,16 @@ struct wa_xfer_result {
258struct usb_wa_descriptor { 279struct usb_wa_descriptor {
259 u8 bLength; 280 u8 bLength;
260 u8 bDescriptorType; 281 u8 bDescriptorType;
261 u16 bcdWAVersion; 282 __le16 bcdWAVersion;
262 u8 bNumPorts; /* don't use!! */ 283 u8 bNumPorts; /* don't use!! */
263 u8 bmAttributes; /* Reserved == 0 */ 284 u8 bmAttributes; /* Reserved == 0 */
264 u16 wNumRPipes; 285 __le16 wNumRPipes;
265 u16 wRPipeMaxBlock; 286 __le16 wRPipeMaxBlock;
266 u8 bRPipeBlockSize; 287 u8 bRPipeBlockSize;
267 u8 bPwrOn2PwrGood; 288 u8 bPwrOn2PwrGood;
268 u8 bNumMMCIEs; 289 u8 bNumMMCIEs;
269 u8 DeviceRemovable; /* FIXME: in DWA this is up to 16 bytes */ 290 u8 DeviceRemovable; /* FIXME: in DWA this is up to 16 bytes */
270} __attribute__((packed)); 291} __packed;
271 292
272/** 293/**
273 * HWA Device Information Buffer (WUSB1.0[T8.54]) 294 * HWA Device Information Buffer (WUSB1.0[T8.54])
@@ -277,6 +298,6 @@ struct hwa_dev_info {
277 u8 bDeviceAddress; 298 u8 bDeviceAddress;
278 __le16 wPHYRates; 299 __le16 wPHYRates;
279 u8 bmDeviceAttribute; 300 u8 bmDeviceAttribute;
280} __attribute__((packed)); 301} __packed;
281 302
282#endif /* #ifndef __LINUX_USB_WUSB_WA_H */ 303#endif /* #ifndef __LINUX_USB_WUSB_WA_H */
diff --git a/include/linux/yam.h b/include/linux/yam.h
index 7fe28228b274..512cdc2fb80f 100644
--- a/include/linux/yam.h
+++ b/include/linux/yam.h
@@ -77,6 +77,6 @@ struct yamdrv_ioctl_cfg {
77 77
78struct yamdrv_ioctl_mcs { 78struct yamdrv_ioctl_mcs {
79 int cmd; 79 int cmd;
80 int bitrate; 80 unsigned int bitrate;
81 unsigned char bits[YAM_FPGA_SIZE]; 81 unsigned char bits[YAM_FPGA_SIZE];
82}; 82};
diff --git a/include/net/cipso_ipv4.h b/include/net/cipso_ipv4.h
index a7a683e30b64..a8c2ef6d3b93 100644
--- a/include/net/cipso_ipv4.h
+++ b/include/net/cipso_ipv4.h
@@ -290,6 +290,7 @@ static inline int cipso_v4_validate(const struct sk_buff *skb,
290 unsigned char err_offset = 0; 290 unsigned char err_offset = 0;
291 u8 opt_len = opt[1]; 291 u8 opt_len = opt[1];
292 u8 opt_iter; 292 u8 opt_iter;
293 u8 tag_len;
293 294
294 if (opt_len < 8) { 295 if (opt_len < 8) {
295 err_offset = 1; 296 err_offset = 1;
@@ -302,11 +303,12 @@ static inline int cipso_v4_validate(const struct sk_buff *skb,
302 } 303 }
303 304
304 for (opt_iter = 6; opt_iter < opt_len;) { 305 for (opt_iter = 6; opt_iter < opt_len;) {
305 if (opt[opt_iter + 1] > (opt_len - opt_iter)) { 306 tag_len = opt[opt_iter + 1];
307 if ((tag_len == 0) || (opt[opt_iter + 1] > (opt_len - opt_iter))) {
306 err_offset = opt_iter + 1; 308 err_offset = opt_iter + 1;
307 goto out; 309 goto out;
308 } 310 }
309 opt_iter += opt[opt_iter + 1]; 311 opt_iter += tag_len;
310 } 312 }
311 313
312out: 314out:
diff --git a/include/net/dst.h b/include/net/dst.h
index 3bc4865f8267..3c4c944096c9 100644
--- a/include/net/dst.h
+++ b/include/net/dst.h
@@ -479,10 +479,22 @@ static inline struct dst_entry *xfrm_lookup(struct net *net,
479{ 479{
480 return dst_orig; 480 return dst_orig;
481} 481}
482
483static inline struct xfrm_state *dst_xfrm(const struct dst_entry *dst)
484{
485 return NULL;
486}
487
482#else 488#else
483extern struct dst_entry *xfrm_lookup(struct net *net, struct dst_entry *dst_orig, 489extern struct dst_entry *xfrm_lookup(struct net *net, struct dst_entry *dst_orig,
484 const struct flowi *fl, struct sock *sk, 490 const struct flowi *fl, struct sock *sk,
485 int flags); 491 int flags);
492
493/* skb attached with this dst needs transformation if dst->xfrm is valid */
494static inline struct xfrm_state *dst_xfrm(const struct dst_entry *dst)
495{
496 return dst->xfrm;
497}
486#endif 498#endif
487 499
488#endif /* _NET_DST_H */ 500#endif /* _NET_DST_H */
diff --git a/include/net/ip6_fib.h b/include/net/ip6_fib.h
index 48ec25a7fcb6..5e661a979694 100644
--- a/include/net/ip6_fib.h
+++ b/include/net/ip6_fib.h
@@ -165,6 +165,7 @@ static inline struct inet6_dev *ip6_dst_idev(struct dst_entry *dst)
165static inline void rt6_clean_expires(struct rt6_info *rt) 165static inline void rt6_clean_expires(struct rt6_info *rt)
166{ 166{
167 rt->rt6i_flags &= ~RTF_EXPIRES; 167 rt->rt6i_flags &= ~RTF_EXPIRES;
168 rt->dst.expires = 0;
168} 169}
169 170
170static inline void rt6_set_expires(struct rt6_info *rt, unsigned long expires) 171static inline void rt6_set_expires(struct rt6_info *rt, unsigned long expires)
diff --git a/include/net/ip6_route.h b/include/net/ip6_route.h
index f525e7038cca..2b786b7e3585 100644
--- a/include/net/ip6_route.h
+++ b/include/net/ip6_route.h
@@ -194,11 +194,9 @@ static inline int ip6_skb_dst_mtu(struct sk_buff *skb)
194 skb_dst(skb)->dev->mtu : dst_mtu(skb_dst(skb)); 194 skb_dst(skb)->dev->mtu : dst_mtu(skb_dst(skb));
195} 195}
196 196
197static inline struct in6_addr *rt6_nexthop(struct rt6_info *rt, struct in6_addr *dest) 197static inline struct in6_addr *rt6_nexthop(struct rt6_info *rt)
198{ 198{
199 if (rt->rt6i_flags & RTF_GATEWAY) 199 return &rt->rt6i_gateway;
200 return &rt->rt6i_gateway;
201 return dest;
202} 200}
203 201
204#endif 202#endif
diff --git a/include/net/mac802154.h b/include/net/mac802154.h
index d0d11df9cba1..807d6b7a943f 100644
--- a/include/net/mac802154.h
+++ b/include/net/mac802154.h
@@ -133,7 +133,7 @@ struct ieee802154_ops {
133 133
134/* Basic interface to register ieee802154 device */ 134/* Basic interface to register ieee802154 device */
135struct ieee802154_dev * 135struct ieee802154_dev *
136ieee802154_alloc_device(size_t priv_data_lex, struct ieee802154_ops *ops); 136ieee802154_alloc_device(size_t priv_data_len, struct ieee802154_ops *ops);
137void ieee802154_free_device(struct ieee802154_dev *dev); 137void ieee802154_free_device(struct ieee802154_dev *dev);
138int ieee802154_register_device(struct ieee802154_dev *dev); 138int ieee802154_register_device(struct ieee802154_dev *dev);
139void ieee802154_unregister_device(struct ieee802154_dev *dev); 139void ieee802154_unregister_device(struct ieee802154_dev *dev);
diff --git a/include/net/sock.h b/include/net/sock.h
index 1d37a8086bed..808cbc2ec6c1 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -1630,16 +1630,14 @@ static inline void sk_filter_release(struct sk_filter *fp)
1630 1630
1631static inline void sk_filter_uncharge(struct sock *sk, struct sk_filter *fp) 1631static inline void sk_filter_uncharge(struct sock *sk, struct sk_filter *fp)
1632{ 1632{
1633 unsigned int size = sk_filter_len(fp); 1633 atomic_sub(sk_filter_size(fp->len), &sk->sk_omem_alloc);
1634
1635 atomic_sub(size, &sk->sk_omem_alloc);
1636 sk_filter_release(fp); 1634 sk_filter_release(fp);
1637} 1635}
1638 1636
1639static inline void sk_filter_charge(struct sock *sk, struct sk_filter *fp) 1637static inline void sk_filter_charge(struct sock *sk, struct sk_filter *fp)
1640{ 1638{
1641 atomic_inc(&fp->refcnt); 1639 atomic_inc(&fp->refcnt);
1642 atomic_add(sk_filter_len(fp), &sk->sk_omem_alloc); 1640 atomic_add(sk_filter_size(fp->len), &sk->sk_omem_alloc);
1643} 1641}
1644 1642
1645/* 1643/*
diff --git a/include/sound/rcar_snd.h b/include/sound/rcar_snd.h
index fe66533e9b7a..fb0a312bcb81 100644
--- a/include/sound/rcar_snd.h
+++ b/include/sound/rcar_snd.h
@@ -68,6 +68,7 @@ struct rsnd_scu_platform_info {
68 * 68 *
69 * A : generation 69 * A : generation
70 */ 70 */
71#define RSND_GEN_MASK (0xF << 0)
71#define RSND_GEN1 (1 << 0) /* fixme */ 72#define RSND_GEN1 (1 << 0) /* fixme */
72#define RSND_GEN2 (2 << 0) /* fixme */ 73#define RSND_GEN2 (2 << 0) /* fixme */
73 74
diff --git a/include/trace/events/target.h b/include/trace/events/target.h
index aef8fc354025..da9cc0f05c93 100644
--- a/include/trace/events/target.h
+++ b/include/trace/events/target.h
@@ -144,7 +144,7 @@ TRACE_EVENT(target_sequencer_start,
144 ), 144 ),
145 145
146 TP_fast_assign( 146 TP_fast_assign(
147 __entry->unpacked_lun = cmd->se_lun->unpacked_lun; 147 __entry->unpacked_lun = cmd->orig_fe_lun;
148 __entry->opcode = cmd->t_task_cdb[0]; 148 __entry->opcode = cmd->t_task_cdb[0];
149 __entry->data_length = cmd->data_length; 149 __entry->data_length = cmd->data_length;
150 __entry->task_attribute = cmd->sam_task_attr; 150 __entry->task_attribute = cmd->sam_task_attr;
@@ -182,7 +182,7 @@ TRACE_EVENT(target_cmd_complete,
182 ), 182 ),
183 183
184 TP_fast_assign( 184 TP_fast_assign(
185 __entry->unpacked_lun = cmd->se_lun->unpacked_lun; 185 __entry->unpacked_lun = cmd->orig_fe_lun;
186 __entry->opcode = cmd->t_task_cdb[0]; 186 __entry->opcode = cmd->t_task_cdb[0];
187 __entry->data_length = cmd->data_length; 187 __entry->data_length = cmd->data_length;
188 __entry->task_attribute = cmd->sam_task_attr; 188 __entry->task_attribute = cmd->sam_task_attr;
diff --git a/include/uapi/drm/drm_mode.h b/include/uapi/drm/drm_mode.h
index 550811712f78..28acbaf4a81e 100644
--- a/include/uapi/drm/drm_mode.h
+++ b/include/uapi/drm/drm_mode.h
@@ -223,6 +223,8 @@ struct drm_mode_get_connector {
223 __u32 connection; 223 __u32 connection;
224 __u32 mm_width, mm_height; /**< HxW in millimeters */ 224 __u32 mm_width, mm_height; /**< HxW in millimeters */
225 __u32 subpixel; 225 __u32 subpixel;
226
227 __u32 pad;
226}; 228};
227 229
228#define DRM_MODE_PROP_PENDING (1<<0) 230#define DRM_MODE_PROP_PENDING (1<<0)
diff --git a/include/uapi/linux/perf_event.h b/include/uapi/linux/perf_event.h
index 009a655a5d35..2fc1602e23bb 100644
--- a/include/uapi/linux/perf_event.h
+++ b/include/uapi/linux/perf_event.h
@@ -456,13 +456,15 @@ struct perf_event_mmap_page {
456 /* 456 /*
457 * Control data for the mmap() data buffer. 457 * Control data for the mmap() data buffer.
458 * 458 *
459 * User-space reading the @data_head value should issue an rmb(), on 459 * User-space reading the @data_head value should issue an smp_rmb(),
460 * SMP capable platforms, after reading this value -- see 460 * after reading this value.
461 * perf_event_wakeup().
462 * 461 *
463 * When the mapping is PROT_WRITE the @data_tail value should be 462 * When the mapping is PROT_WRITE the @data_tail value should be
464 * written by userspace to reflect the last read data. In this case 463 * written by userspace to reflect the last read data, after issueing
465 * the kernel will not over-write unread data. 464 * an smp_mb() to separate the data read from the ->data_tail store.
465 * In this case the kernel will not over-write unread data.
466 *
467 * See perf_output_put_handle() for the data ordering.
466 */ 468 */
467 __u64 data_head; /* head in the data section */ 469 __u64 data_head; /* head in the data section */
468 __u64 data_tail; /* user-space written tail */ 470 __u64 data_tail; /* user-space written tail */
diff --git a/include/uapi/linux/tc_act/Kbuild b/include/uapi/linux/tc_act/Kbuild
index 0623ec4e728f..56f121605c99 100644
--- a/include/uapi/linux/tc_act/Kbuild
+++ b/include/uapi/linux/tc_act/Kbuild
@@ -1,5 +1,6 @@
1# UAPI Header export list 1# UAPI Header export list
2header-y += tc_csum.h 2header-y += tc_csum.h
3header-y += tc_defact.h
3header-y += tc_gact.h 4header-y += tc_gact.h
4header-y += tc_ipt.h 5header-y += tc_ipt.h
5header-y += tc_mirred.h 6header-y += tc_mirred.h
diff --git a/include/linux/tc_act/tc_defact.h b/include/uapi/linux/tc_act/tc_defact.h
index 6f65d07c7ce2..17dddb40f740 100644
--- a/include/linux/tc_act/tc_defact.h
+++ b/include/uapi/linux/tc_act/tc_defact.h
@@ -6,7 +6,7 @@
6struct tc_defact { 6struct tc_defact {
7 tc_gen; 7 tc_gen;
8}; 8};
9 9
10enum { 10enum {
11 TCA_DEF_UNSPEC, 11 TCA_DEF_UNSPEC,
12 TCA_DEF_TM, 12 TCA_DEF_TM,
diff --git a/include/uapi/rdma/ib_user_verbs.h b/include/uapi/rdma/ib_user_verbs.h
index 0b233c56b0e4..e3ddd86c90a6 100644
--- a/include/uapi/rdma/ib_user_verbs.h
+++ b/include/uapi/rdma/ib_user_verbs.h
@@ -87,8 +87,10 @@ enum {
87 IB_USER_VERBS_CMD_CLOSE_XRCD, 87 IB_USER_VERBS_CMD_CLOSE_XRCD,
88 IB_USER_VERBS_CMD_CREATE_XSRQ, 88 IB_USER_VERBS_CMD_CREATE_XSRQ,
89 IB_USER_VERBS_CMD_OPEN_QP, 89 IB_USER_VERBS_CMD_OPEN_QP,
90#ifdef CONFIG_INFINIBAND_EXPERIMENTAL_UVERBS_FLOW_STEERING
90 IB_USER_VERBS_CMD_CREATE_FLOW = IB_USER_VERBS_CMD_THRESHOLD, 91 IB_USER_VERBS_CMD_CREATE_FLOW = IB_USER_VERBS_CMD_THRESHOLD,
91 IB_USER_VERBS_CMD_DESTROY_FLOW 92 IB_USER_VERBS_CMD_DESTROY_FLOW
93#endif /* CONFIG_INFINIBAND_EXPERIMENTAL_UVERBS_FLOW_STEERING */
92}; 94};
93 95
94/* 96/*
@@ -126,6 +128,7 @@ struct ib_uverbs_cmd_hdr {
126 __u16 out_words; 128 __u16 out_words;
127}; 129};
128 130
131#ifdef CONFIG_INFINIBAND_EXPERIMENTAL_UVERBS_FLOW_STEERING
129struct ib_uverbs_cmd_hdr_ex { 132struct ib_uverbs_cmd_hdr_ex {
130 __u32 command; 133 __u32 command;
131 __u16 in_words; 134 __u16 in_words;
@@ -134,6 +137,7 @@ struct ib_uverbs_cmd_hdr_ex {
134 __u16 provider_out_words; 137 __u16 provider_out_words;
135 __u32 cmd_hdr_reserved; 138 __u32 cmd_hdr_reserved;
136}; 139};
140#endif /* CONFIG_INFINIBAND_EXPERIMENTAL_UVERBS_FLOW_STEERING */
137 141
138struct ib_uverbs_get_context { 142struct ib_uverbs_get_context {
139 __u64 response; 143 __u64 response;
@@ -696,6 +700,7 @@ struct ib_uverbs_detach_mcast {
696 __u64 driver_data[0]; 700 __u64 driver_data[0];
697}; 701};
698 702
703#ifdef CONFIG_INFINIBAND_EXPERIMENTAL_UVERBS_FLOW_STEERING
699struct ib_kern_eth_filter { 704struct ib_kern_eth_filter {
700 __u8 dst_mac[6]; 705 __u8 dst_mac[6];
701 __u8 src_mac[6]; 706 __u8 src_mac[6];
@@ -780,6 +785,7 @@ struct ib_uverbs_destroy_flow {
780 __u32 comp_mask; 785 __u32 comp_mask;
781 __u32 flow_handle; 786 __u32 flow_handle;
782}; 787};
788#endif /* CONFIG_INFINIBAND_EXPERIMENTAL_UVERBS_FLOW_STEERING */
783 789
784struct ib_uverbs_create_srq { 790struct ib_uverbs_create_srq {
785 __u64 response; 791 __u64 response;
diff --git a/include/video/exynos_dp.h b/include/video/exynos_dp.h
deleted file mode 100644
index bd8cabd344db..000000000000
--- a/include/video/exynos_dp.h
+++ /dev/null
@@ -1,131 +0,0 @@
1/*
2 * Samsung SoC DP device support
3 *
4 * Copyright (C) 2012 Samsung Electronics Co., Ltd.
5 * Author: Jingoo Han <jg1.han@samsung.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#ifndef _EXYNOS_DP_H
13#define _EXYNOS_DP_H
14
15#define DP_TIMEOUT_LOOP_COUNT 100
16#define MAX_CR_LOOP 5
17#define MAX_EQ_LOOP 5
18
19enum link_rate_type {
20 LINK_RATE_1_62GBPS = 0x06,
21 LINK_RATE_2_70GBPS = 0x0a
22};
23
24enum link_lane_count_type {
25 LANE_COUNT1 = 1,
26 LANE_COUNT2 = 2,
27 LANE_COUNT4 = 4
28};
29
30enum link_training_state {
31 START,
32 CLOCK_RECOVERY,
33 EQUALIZER_TRAINING,
34 FINISHED,
35 FAILED
36};
37
38enum voltage_swing_level {
39 VOLTAGE_LEVEL_0,
40 VOLTAGE_LEVEL_1,
41 VOLTAGE_LEVEL_2,
42 VOLTAGE_LEVEL_3,
43};
44
45enum pre_emphasis_level {
46 PRE_EMPHASIS_LEVEL_0,
47 PRE_EMPHASIS_LEVEL_1,
48 PRE_EMPHASIS_LEVEL_2,
49 PRE_EMPHASIS_LEVEL_3,
50};
51
52enum pattern_set {
53 PRBS7,
54 D10_2,
55 TRAINING_PTN1,
56 TRAINING_PTN2,
57 DP_NONE
58};
59
60enum color_space {
61 COLOR_RGB,
62 COLOR_YCBCR422,
63 COLOR_YCBCR444
64};
65
66enum color_depth {
67 COLOR_6,
68 COLOR_8,
69 COLOR_10,
70 COLOR_12
71};
72
73enum color_coefficient {
74 COLOR_YCBCR601,
75 COLOR_YCBCR709
76};
77
78enum dynamic_range {
79 VESA,
80 CEA
81};
82
83enum pll_status {
84 PLL_UNLOCKED,
85 PLL_LOCKED
86};
87
88enum clock_recovery_m_value_type {
89 CALCULATED_M,
90 REGISTER_M
91};
92
93enum video_timing_recognition_type {
94 VIDEO_TIMING_FROM_CAPTURE,
95 VIDEO_TIMING_FROM_REGISTER
96};
97
98enum analog_power_block {
99 AUX_BLOCK,
100 CH0_BLOCK,
101 CH1_BLOCK,
102 CH2_BLOCK,
103 CH3_BLOCK,
104 ANALOG_TOTAL,
105 POWER_ALL
106};
107
108struct video_info {
109 char *name;
110
111 bool h_sync_polarity;
112 bool v_sync_polarity;
113 bool interlaced;
114
115 enum color_space color_space;
116 enum dynamic_range dynamic_range;
117 enum color_coefficient ycbcr_coeff;
118 enum color_depth color_depth;
119
120 enum link_rate_type link_rate;
121 enum link_lane_count_type lane_count;
122};
123
124struct exynos_dp_platdata {
125 struct video_info *video_info;
126
127 void (*phy_init)(void);
128 void (*phy_exit)(void);
129};
130
131#endif /* _EXYNOS_DP_H */
diff --git a/include/video/exynos_mipi_dsim.h b/include/video/exynos_mipi_dsim.h
index 89dc88a171af..6a578f8a1b3e 100644
--- a/include/video/exynos_mipi_dsim.h
+++ b/include/video/exynos_mipi_dsim.h
@@ -216,6 +216,7 @@ struct mipi_dsim_config {
216 * automatically. 216 * automatically.
217 * @e_clk_src: select byte clock source. 217 * @e_clk_src: select byte clock source.
218 * @pd: pointer to MIPI-DSI driver platform data. 218 * @pd: pointer to MIPI-DSI driver platform data.
219 * @phy: pointer to the MIPI-DSI PHY
219 */ 220 */
220struct mipi_dsim_device { 221struct mipi_dsim_device {
221 struct device *dev; 222 struct device *dev;
@@ -236,6 +237,7 @@ struct mipi_dsim_device {
236 bool suspended; 237 bool suspended;
237 238
238 struct mipi_dsim_platform_data *pd; 239 struct mipi_dsim_platform_data *pd;
240 struct phy *phy;
239}; 241};
240 242
241/* 243/*
@@ -248,7 +250,6 @@ struct mipi_dsim_device {
248 * @enabled: indicate whether mipi controller got enabled or not. 250 * @enabled: indicate whether mipi controller got enabled or not.
249 * @lcd_panel_info: pointer for lcd panel specific structure. 251 * @lcd_panel_info: pointer for lcd panel specific structure.
250 * this structure specifies width, height, timing and polarity and so on. 252 * this structure specifies width, height, timing and polarity and so on.
251 * @phy_enable: pointer to a callback controlling D-PHY enable/reset
252 */ 253 */
253struct mipi_dsim_platform_data { 254struct mipi_dsim_platform_data {
254 char lcd_panel_name[PANEL_NAME_SIZE]; 255 char lcd_panel_name[PANEL_NAME_SIZE];
@@ -256,8 +257,6 @@ struct mipi_dsim_platform_data {
256 struct mipi_dsim_config *dsim_config; 257 struct mipi_dsim_config *dsim_config;
257 unsigned int enabled; 258 unsigned int enabled;
258 void *lcd_panel_info; 259 void *lcd_panel_info;
259
260 int (*phy_enable)(struct platform_device *pdev, bool on);
261}; 260};
262 261
263/* 262/*
diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
index 130dfece27ac..b0e99deb6d05 100644
--- a/ipc/ipc_sysctl.c
+++ b/ipc/ipc_sysctl.c
@@ -62,7 +62,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
62 return err; 62 return err;
63} 63}
64 64
65static int proc_ipc_callback_dointvec(ctl_table *table, int write, 65static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
66 void __user *buffer, size_t *lenp, loff_t *ppos) 66 void __user *buffer, size_t *lenp, loff_t *ppos)
67{ 67{
68 struct ctl_table ipc_table; 68 struct ctl_table ipc_table;
@@ -72,7 +72,7 @@ static int proc_ipc_callback_dointvec(ctl_table *table, int write,
72 memcpy(&ipc_table, table, sizeof(ipc_table)); 72 memcpy(&ipc_table, table, sizeof(ipc_table));
73 ipc_table.data = get_ipc(table); 73 ipc_table.data = get_ipc(table);
74 74
75 rc = proc_dointvec(&ipc_table, write, buffer, lenp, ppos); 75 rc = proc_dointvec_minmax(&ipc_table, write, buffer, lenp, ppos);
76 76
77 if (write && !rc && lenp_bef == *lenp) 77 if (write && !rc && lenp_bef == *lenp)
78 /* 78 /*
@@ -152,15 +152,13 @@ static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
152#define proc_ipc_dointvec NULL 152#define proc_ipc_dointvec NULL
153#define proc_ipc_dointvec_minmax NULL 153#define proc_ipc_dointvec_minmax NULL
154#define proc_ipc_dointvec_minmax_orphans NULL 154#define proc_ipc_dointvec_minmax_orphans NULL
155#define proc_ipc_callback_dointvec NULL 155#define proc_ipc_callback_dointvec_minmax NULL
156#define proc_ipcauto_dointvec_minmax NULL 156#define proc_ipcauto_dointvec_minmax NULL
157#endif 157#endif
158 158
159static int zero; 159static int zero;
160static int one = 1; 160static int one = 1;
161#ifdef CONFIG_CHECKPOINT_RESTORE
162static int int_max = INT_MAX; 161static int int_max = INT_MAX;
163#endif
164 162
165static struct ctl_table ipc_kern_table[] = { 163static struct ctl_table ipc_kern_table[] = {
166 { 164 {
@@ -198,21 +196,27 @@ static struct ctl_table ipc_kern_table[] = {
198 .data = &init_ipc_ns.msg_ctlmax, 196 .data = &init_ipc_ns.msg_ctlmax,
199 .maxlen = sizeof (init_ipc_ns.msg_ctlmax), 197 .maxlen = sizeof (init_ipc_ns.msg_ctlmax),
200 .mode = 0644, 198 .mode = 0644,
201 .proc_handler = proc_ipc_dointvec, 199 .proc_handler = proc_ipc_dointvec_minmax,
200 .extra1 = &zero,
201 .extra2 = &int_max,
202 }, 202 },
203 { 203 {
204 .procname = "msgmni", 204 .procname = "msgmni",
205 .data = &init_ipc_ns.msg_ctlmni, 205 .data = &init_ipc_ns.msg_ctlmni,
206 .maxlen = sizeof (init_ipc_ns.msg_ctlmni), 206 .maxlen = sizeof (init_ipc_ns.msg_ctlmni),
207 .mode = 0644, 207 .mode = 0644,
208 .proc_handler = proc_ipc_callback_dointvec, 208 .proc_handler = proc_ipc_callback_dointvec_minmax,
209 .extra1 = &zero,
210 .extra2 = &int_max,
209 }, 211 },
210 { 212 {
211 .procname = "msgmnb", 213 .procname = "msgmnb",
212 .data = &init_ipc_ns.msg_ctlmnb, 214 .data = &init_ipc_ns.msg_ctlmnb,
213 .maxlen = sizeof (init_ipc_ns.msg_ctlmnb), 215 .maxlen = sizeof (init_ipc_ns.msg_ctlmnb),
214 .mode = 0644, 216 .mode = 0644,
215 .proc_handler = proc_ipc_dointvec, 217 .proc_handler = proc_ipc_dointvec_minmax,
218 .extra1 = &zero,
219 .extra2 = &int_max,
216 }, 220 },
217 { 221 {
218 .procname = "sem", 222 .procname = "sem",
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 2418b6e71a85..8bd9cfdc70d7 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -2039,7 +2039,7 @@ static int cgroup_attach_task(struct cgroup *cgrp, struct task_struct *tsk,
2039 2039
2040 /* @tsk either already exited or can't exit until the end */ 2040 /* @tsk either already exited or can't exit until the end */
2041 if (tsk->flags & PF_EXITING) 2041 if (tsk->flags & PF_EXITING)
2042 continue; 2042 goto next;
2043 2043
2044 /* as per above, nr_threads may decrease, but not increase. */ 2044 /* as per above, nr_threads may decrease, but not increase. */
2045 BUG_ON(i >= group_size); 2045 BUG_ON(i >= group_size);
@@ -2047,7 +2047,7 @@ static int cgroup_attach_task(struct cgroup *cgrp, struct task_struct *tsk,
2047 ent.cgrp = task_cgroup_from_root(tsk, root); 2047 ent.cgrp = task_cgroup_from_root(tsk, root);
2048 /* nothing to do if this task is already in the cgroup */ 2048 /* nothing to do if this task is already in the cgroup */
2049 if (ent.cgrp == cgrp) 2049 if (ent.cgrp == cgrp)
2050 continue; 2050 goto next;
2051 /* 2051 /*
2052 * saying GFP_ATOMIC has no effect here because we did prealloc 2052 * saying GFP_ATOMIC has no effect here because we did prealloc
2053 * earlier, but it's good form to communicate our expectations. 2053 * earlier, but it's good form to communicate our expectations.
@@ -2055,7 +2055,7 @@ static int cgroup_attach_task(struct cgroup *cgrp, struct task_struct *tsk,
2055 retval = flex_array_put(group, i, &ent, GFP_ATOMIC); 2055 retval = flex_array_put(group, i, &ent, GFP_ATOMIC);
2056 BUG_ON(retval != 0); 2056 BUG_ON(retval != 0);
2057 i++; 2057 i++;
2058 2058 next:
2059 if (!threadgroup) 2059 if (!threadgroup)
2060 break; 2060 break;
2061 } while_each_thread(leader, tsk); 2061 } while_each_thread(leader, tsk);
@@ -3188,11 +3188,9 @@ css_next_descendant_post(struct cgroup_subsys_state *pos,
3188 3188
3189 WARN_ON_ONCE(!rcu_read_lock_held()); 3189 WARN_ON_ONCE(!rcu_read_lock_held());
3190 3190
3191 /* if first iteration, visit the leftmost descendant */ 3191 /* if first iteration, visit leftmost descendant which may be @root */
3192 if (!pos) { 3192 if (!pos)
3193 next = css_leftmost_descendant(root); 3193 return css_leftmost_descendant(root);
3194 return next != root ? next : NULL;
3195 }
3196 3194
3197 /* if we visited @root, we're done */ 3195 /* if we visited @root, we're done */
3198 if (pos == root) 3196 if (pos == root)
diff --git a/kernel/events/core.c b/kernel/events/core.c
index d49a9d29334c..953c14348375 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -6767,6 +6767,10 @@ static int perf_copy_attr(struct perf_event_attr __user *uattr,
6767 if (ret) 6767 if (ret)
6768 return -EFAULT; 6768 return -EFAULT;
6769 6769
6770 /* disabled for now */
6771 if (attr->mmap2)
6772 return -EINVAL;
6773
6770 if (attr->__reserved_1) 6774 if (attr->__reserved_1)
6771 return -EINVAL; 6775 return -EINVAL;
6772 6776
diff --git a/kernel/events/ring_buffer.c b/kernel/events/ring_buffer.c
index cd55144270b5..9c2ddfbf4525 100644
--- a/kernel/events/ring_buffer.c
+++ b/kernel/events/ring_buffer.c
@@ -87,10 +87,31 @@ again:
87 goto out; 87 goto out;
88 88
89 /* 89 /*
90 * Publish the known good head. Rely on the full barrier implied 90 * Since the mmap() consumer (userspace) can run on a different CPU:
91 * by atomic_dec_and_test() order the rb->head read and this 91 *
92 * write. 92 * kernel user
93 *
94 * READ ->data_tail READ ->data_head
95 * smp_mb() (A) smp_rmb() (C)
96 * WRITE $data READ $data
97 * smp_wmb() (B) smp_mb() (D)
98 * STORE ->data_head WRITE ->data_tail
99 *
100 * Where A pairs with D, and B pairs with C.
101 *
102 * I don't think A needs to be a full barrier because we won't in fact
103 * write data until we see the store from userspace. So we simply don't
104 * issue the data WRITE until we observe it. Be conservative for now.
105 *
106 * OTOH, D needs to be a full barrier since it separates the data READ
107 * from the tail WRITE.
108 *
109 * For B a WMB is sufficient since it separates two WRITEs, and for C
110 * an RMB is sufficient since it separates two READs.
111 *
112 * See perf_output_begin().
93 */ 113 */
114 smp_wmb();
94 rb->user_page->data_head = head; 115 rb->user_page->data_head = head;
95 116
96 /* 117 /*
@@ -154,9 +175,11 @@ int perf_output_begin(struct perf_output_handle *handle,
154 * Userspace could choose to issue a mb() before updating the 175 * Userspace could choose to issue a mb() before updating the
155 * tail pointer. So that all reads will be completed before the 176 * tail pointer. So that all reads will be completed before the
156 * write is issued. 177 * write is issued.
178 *
179 * See perf_output_put_handle().
157 */ 180 */
158 tail = ACCESS_ONCE(rb->user_page->data_tail); 181 tail = ACCESS_ONCE(rb->user_page->data_tail);
159 smp_rmb(); 182 smp_mb();
160 offset = head = local_read(&rb->head); 183 offset = head = local_read(&rb->head);
161 head += size; 184 head += size;
162 if (unlikely(!perf_output_space(rb, tail, offset, head))) 185 if (unlikely(!perf_output_space(rb, tail, offset, head)))
diff --git a/kernel/mutex.c b/kernel/mutex.c
index 6d647aedffea..d24105b1b794 100644
--- a/kernel/mutex.c
+++ b/kernel/mutex.c
@@ -410,7 +410,7 @@ ww_mutex_set_context_fastpath(struct ww_mutex *lock,
410static __always_inline int __sched 410static __always_inline int __sched
411__mutex_lock_common(struct mutex *lock, long state, unsigned int subclass, 411__mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
412 struct lockdep_map *nest_lock, unsigned long ip, 412 struct lockdep_map *nest_lock, unsigned long ip,
413 struct ww_acquire_ctx *ww_ctx) 413 struct ww_acquire_ctx *ww_ctx, const bool use_ww_ctx)
414{ 414{
415 struct task_struct *task = current; 415 struct task_struct *task = current;
416 struct mutex_waiter waiter; 416 struct mutex_waiter waiter;
@@ -450,7 +450,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
450 struct task_struct *owner; 450 struct task_struct *owner;
451 struct mspin_node node; 451 struct mspin_node node;
452 452
453 if (!__builtin_constant_p(ww_ctx == NULL) && ww_ctx->acquired > 0) { 453 if (use_ww_ctx && ww_ctx->acquired > 0) {
454 struct ww_mutex *ww; 454 struct ww_mutex *ww;
455 455
456 ww = container_of(lock, struct ww_mutex, base); 456 ww = container_of(lock, struct ww_mutex, base);
@@ -480,7 +480,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
480 if ((atomic_read(&lock->count) == 1) && 480 if ((atomic_read(&lock->count) == 1) &&
481 (atomic_cmpxchg(&lock->count, 1, 0) == 1)) { 481 (atomic_cmpxchg(&lock->count, 1, 0) == 1)) {
482 lock_acquired(&lock->dep_map, ip); 482 lock_acquired(&lock->dep_map, ip);
483 if (!__builtin_constant_p(ww_ctx == NULL)) { 483 if (use_ww_ctx) {
484 struct ww_mutex *ww; 484 struct ww_mutex *ww;
485 ww = container_of(lock, struct ww_mutex, base); 485 ww = container_of(lock, struct ww_mutex, base);
486 486
@@ -551,7 +551,7 @@ slowpath:
551 goto err; 551 goto err;
552 } 552 }
553 553
554 if (!__builtin_constant_p(ww_ctx == NULL) && ww_ctx->acquired > 0) { 554 if (use_ww_ctx && ww_ctx->acquired > 0) {
555 ret = __mutex_lock_check_stamp(lock, ww_ctx); 555 ret = __mutex_lock_check_stamp(lock, ww_ctx);
556 if (ret) 556 if (ret)
557 goto err; 557 goto err;
@@ -575,7 +575,7 @@ skip_wait:
575 lock_acquired(&lock->dep_map, ip); 575 lock_acquired(&lock->dep_map, ip);
576 mutex_set_owner(lock); 576 mutex_set_owner(lock);
577 577
578 if (!__builtin_constant_p(ww_ctx == NULL)) { 578 if (use_ww_ctx) {
579 struct ww_mutex *ww = container_of(lock, struct ww_mutex, base); 579 struct ww_mutex *ww = container_of(lock, struct ww_mutex, base);
580 struct mutex_waiter *cur; 580 struct mutex_waiter *cur;
581 581
@@ -615,7 +615,7 @@ mutex_lock_nested(struct mutex *lock, unsigned int subclass)
615{ 615{
616 might_sleep(); 616 might_sleep();
617 __mutex_lock_common(lock, TASK_UNINTERRUPTIBLE, 617 __mutex_lock_common(lock, TASK_UNINTERRUPTIBLE,
618 subclass, NULL, _RET_IP_, NULL); 618 subclass, NULL, _RET_IP_, NULL, 0);
619} 619}
620 620
621EXPORT_SYMBOL_GPL(mutex_lock_nested); 621EXPORT_SYMBOL_GPL(mutex_lock_nested);
@@ -625,7 +625,7 @@ _mutex_lock_nest_lock(struct mutex *lock, struct lockdep_map *nest)
625{ 625{
626 might_sleep(); 626 might_sleep();
627 __mutex_lock_common(lock, TASK_UNINTERRUPTIBLE, 627 __mutex_lock_common(lock, TASK_UNINTERRUPTIBLE,
628 0, nest, _RET_IP_, NULL); 628 0, nest, _RET_IP_, NULL, 0);
629} 629}
630 630
631EXPORT_SYMBOL_GPL(_mutex_lock_nest_lock); 631EXPORT_SYMBOL_GPL(_mutex_lock_nest_lock);
@@ -635,7 +635,7 @@ mutex_lock_killable_nested(struct mutex *lock, unsigned int subclass)
635{ 635{
636 might_sleep(); 636 might_sleep();
637 return __mutex_lock_common(lock, TASK_KILLABLE, 637 return __mutex_lock_common(lock, TASK_KILLABLE,
638 subclass, NULL, _RET_IP_, NULL); 638 subclass, NULL, _RET_IP_, NULL, 0);
639} 639}
640EXPORT_SYMBOL_GPL(mutex_lock_killable_nested); 640EXPORT_SYMBOL_GPL(mutex_lock_killable_nested);
641 641
@@ -644,7 +644,7 @@ mutex_lock_interruptible_nested(struct mutex *lock, unsigned int subclass)
644{ 644{
645 might_sleep(); 645 might_sleep();
646 return __mutex_lock_common(lock, TASK_INTERRUPTIBLE, 646 return __mutex_lock_common(lock, TASK_INTERRUPTIBLE,
647 subclass, NULL, _RET_IP_, NULL); 647 subclass, NULL, _RET_IP_, NULL, 0);
648} 648}
649 649
650EXPORT_SYMBOL_GPL(mutex_lock_interruptible_nested); 650EXPORT_SYMBOL_GPL(mutex_lock_interruptible_nested);
@@ -682,7 +682,7 @@ __ww_mutex_lock(struct ww_mutex *lock, struct ww_acquire_ctx *ctx)
682 682
683 might_sleep(); 683 might_sleep();
684 ret = __mutex_lock_common(&lock->base, TASK_UNINTERRUPTIBLE, 684 ret = __mutex_lock_common(&lock->base, TASK_UNINTERRUPTIBLE,
685 0, &ctx->dep_map, _RET_IP_, ctx); 685 0, &ctx->dep_map, _RET_IP_, ctx, 1);
686 if (!ret && ctx->acquired > 1) 686 if (!ret && ctx->acquired > 1)
687 return ww_mutex_deadlock_injection(lock, ctx); 687 return ww_mutex_deadlock_injection(lock, ctx);
688 688
@@ -697,7 +697,7 @@ __ww_mutex_lock_interruptible(struct ww_mutex *lock, struct ww_acquire_ctx *ctx)
697 697
698 might_sleep(); 698 might_sleep();
699 ret = __mutex_lock_common(&lock->base, TASK_INTERRUPTIBLE, 699 ret = __mutex_lock_common(&lock->base, TASK_INTERRUPTIBLE,
700 0, &ctx->dep_map, _RET_IP_, ctx); 700 0, &ctx->dep_map, _RET_IP_, ctx, 1);
701 701
702 if (!ret && ctx->acquired > 1) 702 if (!ret && ctx->acquired > 1)
703 return ww_mutex_deadlock_injection(lock, ctx); 703 return ww_mutex_deadlock_injection(lock, ctx);
@@ -809,28 +809,28 @@ __mutex_lock_slowpath(atomic_t *lock_count)
809 struct mutex *lock = container_of(lock_count, struct mutex, count); 809 struct mutex *lock = container_of(lock_count, struct mutex, count);
810 810
811 __mutex_lock_common(lock, TASK_UNINTERRUPTIBLE, 0, 811 __mutex_lock_common(lock, TASK_UNINTERRUPTIBLE, 0,
812 NULL, _RET_IP_, NULL); 812 NULL, _RET_IP_, NULL, 0);
813} 813}
814 814
815static noinline int __sched 815static noinline int __sched
816__mutex_lock_killable_slowpath(struct mutex *lock) 816__mutex_lock_killable_slowpath(struct mutex *lock)
817{ 817{
818 return __mutex_lock_common(lock, TASK_KILLABLE, 0, 818 return __mutex_lock_common(lock, TASK_KILLABLE, 0,
819 NULL, _RET_IP_, NULL); 819 NULL, _RET_IP_, NULL, 0);
820} 820}
821 821
822static noinline int __sched 822static noinline int __sched
823__mutex_lock_interruptible_slowpath(struct mutex *lock) 823__mutex_lock_interruptible_slowpath(struct mutex *lock)
824{ 824{
825 return __mutex_lock_common(lock, TASK_INTERRUPTIBLE, 0, 825 return __mutex_lock_common(lock, TASK_INTERRUPTIBLE, 0,
826 NULL, _RET_IP_, NULL); 826 NULL, _RET_IP_, NULL, 0);
827} 827}
828 828
829static noinline int __sched 829static noinline int __sched
830__ww_mutex_lock_slowpath(struct ww_mutex *lock, struct ww_acquire_ctx *ctx) 830__ww_mutex_lock_slowpath(struct ww_mutex *lock, struct ww_acquire_ctx *ctx)
831{ 831{
832 return __mutex_lock_common(&lock->base, TASK_UNINTERRUPTIBLE, 0, 832 return __mutex_lock_common(&lock->base, TASK_UNINTERRUPTIBLE, 0,
833 NULL, _RET_IP_, ctx); 833 NULL, _RET_IP_, ctx, 1);
834} 834}
835 835
836static noinline int __sched 836static noinline int __sched
@@ -838,7 +838,7 @@ __ww_mutex_lock_interruptible_slowpath(struct ww_mutex *lock,
838 struct ww_acquire_ctx *ctx) 838 struct ww_acquire_ctx *ctx)
839{ 839{
840 return __mutex_lock_common(&lock->base, TASK_INTERRUPTIBLE, 0, 840 return __mutex_lock_common(&lock->base, TASK_INTERRUPTIBLE, 0,
841 NULL, _RET_IP_, ctx); 841 NULL, _RET_IP_, ctx, 1);
842} 842}
843 843
844#endif 844#endif
diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c
index c9c759d5a15c..0121dab83f43 100644
--- a/kernel/power/hibernate.c
+++ b/kernel/power/hibernate.c
@@ -846,7 +846,7 @@ static int software_resume(void)
846 goto Finish; 846 goto Finish;
847} 847}
848 848
849late_initcall(software_resume); 849late_initcall_sync(software_resume);
850 850
851 851
852static const char * const hibernation_modes[] = { 852static const char * const hibernation_modes[] = {
diff --git a/kernel/time/clockevents.c b/kernel/time/clockevents.c
index 38959c866789..662c5798a685 100644
--- a/kernel/time/clockevents.c
+++ b/kernel/time/clockevents.c
@@ -33,29 +33,64 @@ struct ce_unbind {
33 int res; 33 int res;
34}; 34};
35 35
36/** 36static u64 cev_delta2ns(unsigned long latch, struct clock_event_device *evt,
37 * clockevents_delta2ns - Convert a latch value (device ticks) to nanoseconds 37 bool ismax)
38 * @latch: value to convert
39 * @evt: pointer to clock event device descriptor
40 *
41 * Math helper, returns latch value converted to nanoseconds (bound checked)
42 */
43u64 clockevent_delta2ns(unsigned long latch, struct clock_event_device *evt)
44{ 38{
45 u64 clc = (u64) latch << evt->shift; 39 u64 clc = (u64) latch << evt->shift;
40 u64 rnd;
46 41
47 if (unlikely(!evt->mult)) { 42 if (unlikely(!evt->mult)) {
48 evt->mult = 1; 43 evt->mult = 1;
49 WARN_ON(1); 44 WARN_ON(1);
50 } 45 }
46 rnd = (u64) evt->mult - 1;
47
48 /*
49 * Upper bound sanity check. If the backwards conversion is
50 * not equal latch, we know that the above shift overflowed.
51 */
52 if ((clc >> evt->shift) != (u64)latch)
53 clc = ~0ULL;
54
55 /*
56 * Scaled math oddities:
57 *
58 * For mult <= (1 << shift) we can safely add mult - 1 to
59 * prevent integer rounding loss. So the backwards conversion
60 * from nsec to device ticks will be correct.
61 *
62 * For mult > (1 << shift), i.e. device frequency is > 1GHz we
63 * need to be careful. Adding mult - 1 will result in a value
64 * which when converted back to device ticks can be larger
65 * than latch by up to (mult - 1) >> shift. For the min_delta
66 * calculation we still want to apply this in order to stay
67 * above the minimum device ticks limit. For the upper limit
68 * we would end up with a latch value larger than the upper
69 * limit of the device, so we omit the add to stay below the
70 * device upper boundary.
71 *
72 * Also omit the add if it would overflow the u64 boundary.
73 */
74 if ((~0ULL - clc > rnd) &&
75 (!ismax || evt->mult <= (1U << evt->shift)))
76 clc += rnd;
51 77
52 do_div(clc, evt->mult); 78 do_div(clc, evt->mult);
53 if (clc < 1000)
54 clc = 1000;
55 if (clc > KTIME_MAX)
56 clc = KTIME_MAX;
57 79
58 return clc; 80 /* Deltas less than 1usec are pointless noise */
81 return clc > 1000 ? clc : 1000;
82}
83
84/**
85 * clockevents_delta2ns - Convert a latch value (device ticks) to nanoseconds
86 * @latch: value to convert
87 * @evt: pointer to clock event device descriptor
88 *
89 * Math helper, returns latch value converted to nanoseconds (bound checked)
90 */
91u64 clockevent_delta2ns(unsigned long latch, struct clock_event_device *evt)
92{
93 return cev_delta2ns(latch, evt, false);
59} 94}
60EXPORT_SYMBOL_GPL(clockevent_delta2ns); 95EXPORT_SYMBOL_GPL(clockevent_delta2ns);
61 96
@@ -380,8 +415,8 @@ void clockevents_config(struct clock_event_device *dev, u32 freq)
380 sec = 600; 415 sec = 600;
381 416
382 clockevents_calc_mult_shift(dev, freq, sec); 417 clockevents_calc_mult_shift(dev, freq, sec);
383 dev->min_delta_ns = clockevent_delta2ns(dev->min_delta_ticks, dev); 418 dev->min_delta_ns = cev_delta2ns(dev->min_delta_ticks, dev, false);
384 dev->max_delta_ns = clockevent_delta2ns(dev->max_delta_ticks, dev); 419 dev->max_delta_ns = cev_delta2ns(dev->max_delta_ticks, dev, true);
385} 420}
386 421
387/** 422/**
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 06344d986eb9..094f3152ec2b 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -983,7 +983,7 @@ config DEBUG_KOBJECT
983 983
984config DEBUG_KOBJECT_RELEASE 984config DEBUG_KOBJECT_RELEASE
985 bool "kobject release debugging" 985 bool "kobject release debugging"
986 depends on DEBUG_KERNEL 986 depends on DEBUG_OBJECTS_TIMERS
987 help 987 help
988 kobjects are reference counted objects. This means that their 988 kobjects are reference counted objects. This means that their
989 last reference count put is not predictable, and the kobject can 989 last reference count put is not predictable, and the kobject can
diff --git a/lib/scatterlist.c b/lib/scatterlist.c
index a685c8a79578..d16fa295ae1d 100644
--- a/lib/scatterlist.c
+++ b/lib/scatterlist.c
@@ -577,7 +577,8 @@ void sg_miter_stop(struct sg_mapping_iter *miter)
577 miter->__offset += miter->consumed; 577 miter->__offset += miter->consumed;
578 miter->__remaining -= miter->consumed; 578 miter->__remaining -= miter->consumed;
579 579
580 if (miter->__flags & SG_MITER_TO_SG) 580 if ((miter->__flags & SG_MITER_TO_SG) &&
581 !PageSlab(miter->page))
581 flush_kernel_dcache_page(miter->page); 582 flush_kernel_dcache_page(miter->page);
582 583
583 if (miter->__flags & SG_MITER_ATOMIC) { 584 if (miter->__flags & SG_MITER_ATOMIC) {
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 610e3df2768a..cca80d96e509 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -1278,64 +1278,90 @@ out:
1278int do_huge_pmd_numa_page(struct mm_struct *mm, struct vm_area_struct *vma, 1278int do_huge_pmd_numa_page(struct mm_struct *mm, struct vm_area_struct *vma,
1279 unsigned long addr, pmd_t pmd, pmd_t *pmdp) 1279 unsigned long addr, pmd_t pmd, pmd_t *pmdp)
1280{ 1280{
1281 struct anon_vma *anon_vma = NULL;
1281 struct page *page; 1282 struct page *page;
1282 unsigned long haddr = addr & HPAGE_PMD_MASK; 1283 unsigned long haddr = addr & HPAGE_PMD_MASK;
1284 int page_nid = -1, this_nid = numa_node_id();
1283 int target_nid; 1285 int target_nid;
1284 int current_nid = -1; 1286 bool page_locked;
1285 bool migrated; 1287 bool migrated = false;
1286 1288
1287 spin_lock(&mm->page_table_lock); 1289 spin_lock(&mm->page_table_lock);
1288 if (unlikely(!pmd_same(pmd, *pmdp))) 1290 if (unlikely(!pmd_same(pmd, *pmdp)))
1289 goto out_unlock; 1291 goto out_unlock;
1290 1292
1291 page = pmd_page(pmd); 1293 page = pmd_page(pmd);
1292 get_page(page); 1294 page_nid = page_to_nid(page);
1293 current_nid = page_to_nid(page);
1294 count_vm_numa_event(NUMA_HINT_FAULTS); 1295 count_vm_numa_event(NUMA_HINT_FAULTS);
1295 if (current_nid == numa_node_id()) 1296 if (page_nid == this_nid)
1296 count_vm_numa_event(NUMA_HINT_FAULTS_LOCAL); 1297 count_vm_numa_event(NUMA_HINT_FAULTS_LOCAL);
1297 1298
1299 /*
1300 * Acquire the page lock to serialise THP migrations but avoid dropping
1301 * page_table_lock if at all possible
1302 */
1303 page_locked = trylock_page(page);
1298 target_nid = mpol_misplaced(page, vma, haddr); 1304 target_nid = mpol_misplaced(page, vma, haddr);
1299 if (target_nid == -1) { 1305 if (target_nid == -1) {
1300 put_page(page); 1306 /* If the page was locked, there are no parallel migrations */
1301 goto clear_pmdnuma; 1307 if (page_locked)
1308 goto clear_pmdnuma;
1309
1310 /*
1311 * Otherwise wait for potential migrations and retry. We do
1312 * relock and check_same as the page may no longer be mapped.
1313 * As the fault is being retried, do not account for it.
1314 */
1315 spin_unlock(&mm->page_table_lock);
1316 wait_on_page_locked(page);
1317 page_nid = -1;
1318 goto out;
1302 } 1319 }
1303 1320
1304 /* Acquire the page lock to serialise THP migrations */ 1321 /* Page is misplaced, serialise migrations and parallel THP splits */
1322 get_page(page);
1305 spin_unlock(&mm->page_table_lock); 1323 spin_unlock(&mm->page_table_lock);
1306 lock_page(page); 1324 if (!page_locked)
1325 lock_page(page);
1326 anon_vma = page_lock_anon_vma_read(page);
1307 1327
1308 /* Confirm the PTE did not while locked */ 1328 /* Confirm the PTE did not while locked */
1309 spin_lock(&mm->page_table_lock); 1329 spin_lock(&mm->page_table_lock);
1310 if (unlikely(!pmd_same(pmd, *pmdp))) { 1330 if (unlikely(!pmd_same(pmd, *pmdp))) {
1311 unlock_page(page); 1331 unlock_page(page);
1312 put_page(page); 1332 put_page(page);
1333 page_nid = -1;
1313 goto out_unlock; 1334 goto out_unlock;
1314 } 1335 }
1315 spin_unlock(&mm->page_table_lock);
1316 1336
1317 /* Migrate the THP to the requested node */ 1337 /*
1338 * Migrate the THP to the requested node, returns with page unlocked
1339 * and pmd_numa cleared.
1340 */
1341 spin_unlock(&mm->page_table_lock);
1318 migrated = migrate_misplaced_transhuge_page(mm, vma, 1342 migrated = migrate_misplaced_transhuge_page(mm, vma,
1319 pmdp, pmd, addr, page, target_nid); 1343 pmdp, pmd, addr, page, target_nid);
1320 if (!migrated) 1344 if (migrated)
1321 goto check_same; 1345 page_nid = target_nid;
1322
1323 task_numa_fault(target_nid, HPAGE_PMD_NR, true);
1324 return 0;
1325 1346
1326check_same: 1347 goto out;
1327 spin_lock(&mm->page_table_lock);
1328 if (unlikely(!pmd_same(pmd, *pmdp)))
1329 goto out_unlock;
1330clear_pmdnuma: 1348clear_pmdnuma:
1349 BUG_ON(!PageLocked(page));
1331 pmd = pmd_mknonnuma(pmd); 1350 pmd = pmd_mknonnuma(pmd);
1332 set_pmd_at(mm, haddr, pmdp, pmd); 1351 set_pmd_at(mm, haddr, pmdp, pmd);
1333 VM_BUG_ON(pmd_numa(*pmdp)); 1352 VM_BUG_ON(pmd_numa(*pmdp));
1334 update_mmu_cache_pmd(vma, addr, pmdp); 1353 update_mmu_cache_pmd(vma, addr, pmdp);
1354 unlock_page(page);
1335out_unlock: 1355out_unlock:
1336 spin_unlock(&mm->page_table_lock); 1356 spin_unlock(&mm->page_table_lock);
1337 if (current_nid != -1) 1357
1338 task_numa_fault(current_nid, HPAGE_PMD_NR, false); 1358out:
1359 if (anon_vma)
1360 page_unlock_anon_vma_read(anon_vma);
1361
1362 if (page_nid != -1)
1363 task_numa_fault(page_nid, HPAGE_PMD_NR, migrated);
1364
1339 return 0; 1365 return 0;
1340} 1366}
1341 1367
diff --git a/mm/list_lru.c b/mm/list_lru.c
index 72467914b856..72f9decb0104 100644
--- a/mm/list_lru.c
+++ b/mm/list_lru.c
@@ -81,8 +81,9 @@ restart:
81 * decrement nr_to_walk first so that we don't livelock if we 81 * decrement nr_to_walk first so that we don't livelock if we
82 * get stuck on large numbesr of LRU_RETRY items 82 * get stuck on large numbesr of LRU_RETRY items
83 */ 83 */
84 if (--(*nr_to_walk) == 0) 84 if (!*nr_to_walk)
85 break; 85 break;
86 --*nr_to_walk;
86 87
87 ret = isolate(item, &nlru->lock, cb_arg); 88 ret = isolate(item, &nlru->lock, cb_arg);
88 switch (ret) { 89 switch (ret) {
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 34d3ca9572d6..13b9d0f221b8 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -54,6 +54,7 @@
54#include <linux/page_cgroup.h> 54#include <linux/page_cgroup.h>
55#include <linux/cpu.h> 55#include <linux/cpu.h>
56#include <linux/oom.h> 56#include <linux/oom.h>
57#include <linux/lockdep.h>
57#include "internal.h" 58#include "internal.h"
58#include <net/sock.h> 59#include <net/sock.h>
59#include <net/ip.h> 60#include <net/ip.h>
@@ -2046,6 +2047,12 @@ static int mem_cgroup_soft_reclaim(struct mem_cgroup *root_memcg,
2046 return total; 2047 return total;
2047} 2048}
2048 2049
2050#ifdef CONFIG_LOCKDEP
2051static struct lockdep_map memcg_oom_lock_dep_map = {
2052 .name = "memcg_oom_lock",
2053};
2054#endif
2055
2049static DEFINE_SPINLOCK(memcg_oom_lock); 2056static DEFINE_SPINLOCK(memcg_oom_lock);
2050 2057
2051/* 2058/*
@@ -2083,7 +2090,8 @@ static bool mem_cgroup_oom_trylock(struct mem_cgroup *memcg)
2083 } 2090 }
2084 iter->oom_lock = false; 2091 iter->oom_lock = false;
2085 } 2092 }
2086 } 2093 } else
2094 mutex_acquire(&memcg_oom_lock_dep_map, 0, 1, _RET_IP_);
2087 2095
2088 spin_unlock(&memcg_oom_lock); 2096 spin_unlock(&memcg_oom_lock);
2089 2097
@@ -2095,6 +2103,7 @@ static void mem_cgroup_oom_unlock(struct mem_cgroup *memcg)
2095 struct mem_cgroup *iter; 2103 struct mem_cgroup *iter;
2096 2104
2097 spin_lock(&memcg_oom_lock); 2105 spin_lock(&memcg_oom_lock);
2106 mutex_release(&memcg_oom_lock_dep_map, 1, _RET_IP_);
2098 for_each_mem_cgroup_tree(iter, memcg) 2107 for_each_mem_cgroup_tree(iter, memcg)
2099 iter->oom_lock = false; 2108 iter->oom_lock = false;
2100 spin_unlock(&memcg_oom_lock); 2109 spin_unlock(&memcg_oom_lock);
@@ -2765,10 +2774,10 @@ done:
2765 *ptr = memcg; 2774 *ptr = memcg;
2766 return 0; 2775 return 0;
2767nomem: 2776nomem:
2768 *ptr = NULL; 2777 if (!(gfp_mask & __GFP_NOFAIL)) {
2769 if (gfp_mask & __GFP_NOFAIL) 2778 *ptr = NULL;
2770 return 0; 2779 return -ENOMEM;
2771 return -ENOMEM; 2780 }
2772bypass: 2781bypass:
2773 *ptr = root_mem_cgroup; 2782 *ptr = root_mem_cgroup;
2774 return -EINTR; 2783 return -EINTR;
@@ -3773,8 +3782,7 @@ void mem_cgroup_move_account_page_stat(struct mem_cgroup *from,
3773{ 3782{
3774 /* Update stat data for mem_cgroup */ 3783 /* Update stat data for mem_cgroup */
3775 preempt_disable(); 3784 preempt_disable();
3776 WARN_ON_ONCE(from->stat->count[idx] < nr_pages); 3785 __this_cpu_sub(from->stat->count[idx], nr_pages);
3777 __this_cpu_add(from->stat->count[idx], -nr_pages);
3778 __this_cpu_add(to->stat->count[idx], nr_pages); 3786 __this_cpu_add(to->stat->count[idx], nr_pages);
3779 preempt_enable(); 3787 preempt_enable();
3780} 3788}
@@ -4950,31 +4958,18 @@ static void mem_cgroup_reparent_charges(struct mem_cgroup *memcg)
4950 } while (usage > 0); 4958 } while (usage > 0);
4951} 4959}
4952 4960
4953/*
4954 * This mainly exists for tests during the setting of set of use_hierarchy.
4955 * Since this is the very setting we are changing, the current hierarchy value
4956 * is meaningless
4957 */
4958static inline bool __memcg_has_children(struct mem_cgroup *memcg)
4959{
4960 struct cgroup_subsys_state *pos;
4961
4962 /* bounce at first found */
4963 css_for_each_child(pos, &memcg->css)
4964 return true;
4965 return false;
4966}
4967
4968/*
4969 * Must be called with memcg_create_mutex held, unless the cgroup is guaranteed
4970 * to be already dead (as in mem_cgroup_force_empty, for instance). This is
4971 * from mem_cgroup_count_children(), in the sense that we don't really care how
4972 * many children we have; we only need to know if we have any. It also counts
4973 * any memcg without hierarchy as infertile.
4974 */
4975static inline bool memcg_has_children(struct mem_cgroup *memcg) 4961static inline bool memcg_has_children(struct mem_cgroup *memcg)
4976{ 4962{
4977 return memcg->use_hierarchy && __memcg_has_children(memcg); 4963 lockdep_assert_held(&memcg_create_mutex);
4964 /*
4965 * The lock does not prevent addition or deletion to the list
4966 * of children, but it prevents a new child from being
4967 * initialized based on this parent in css_online(), so it's
4968 * enough to decide whether hierarchically inherited
4969 * attributes can still be changed or not.
4970 */
4971 return memcg->use_hierarchy &&
4972 !list_empty(&memcg->css.cgroup->children);
4978} 4973}
4979 4974
4980/* 4975/*
@@ -5054,7 +5049,7 @@ static int mem_cgroup_hierarchy_write(struct cgroup_subsys_state *css,
5054 */ 5049 */
5055 if ((!parent_memcg || !parent_memcg->use_hierarchy) && 5050 if ((!parent_memcg || !parent_memcg->use_hierarchy) &&
5056 (val == 1 || val == 0)) { 5051 (val == 1 || val == 0)) {
5057 if (!__memcg_has_children(memcg)) 5052 if (list_empty(&memcg->css.cgroup->children))
5058 memcg->use_hierarchy = val; 5053 memcg->use_hierarchy = val;
5059 else 5054 else
5060 retval = -EBUSY; 5055 retval = -EBUSY;
diff --git a/mm/memory.c b/mm/memory.c
index 1311f26497e6..d176154c243f 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -3521,12 +3521,12 @@ static int do_nonlinear_fault(struct mm_struct *mm, struct vm_area_struct *vma,
3521} 3521}
3522 3522
3523int numa_migrate_prep(struct page *page, struct vm_area_struct *vma, 3523int numa_migrate_prep(struct page *page, struct vm_area_struct *vma,
3524 unsigned long addr, int current_nid) 3524 unsigned long addr, int page_nid)
3525{ 3525{
3526 get_page(page); 3526 get_page(page);
3527 3527
3528 count_vm_numa_event(NUMA_HINT_FAULTS); 3528 count_vm_numa_event(NUMA_HINT_FAULTS);
3529 if (current_nid == numa_node_id()) 3529 if (page_nid == numa_node_id())
3530 count_vm_numa_event(NUMA_HINT_FAULTS_LOCAL); 3530 count_vm_numa_event(NUMA_HINT_FAULTS_LOCAL);
3531 3531
3532 return mpol_misplaced(page, vma, addr); 3532 return mpol_misplaced(page, vma, addr);
@@ -3537,7 +3537,7 @@ int do_numa_page(struct mm_struct *mm, struct vm_area_struct *vma,
3537{ 3537{
3538 struct page *page = NULL; 3538 struct page *page = NULL;
3539 spinlock_t *ptl; 3539 spinlock_t *ptl;
3540 int current_nid = -1; 3540 int page_nid = -1;
3541 int target_nid; 3541 int target_nid;
3542 bool migrated = false; 3542 bool migrated = false;
3543 3543
@@ -3567,15 +3567,10 @@ int do_numa_page(struct mm_struct *mm, struct vm_area_struct *vma,
3567 return 0; 3567 return 0;
3568 } 3568 }
3569 3569
3570 current_nid = page_to_nid(page); 3570 page_nid = page_to_nid(page);
3571 target_nid = numa_migrate_prep(page, vma, addr, current_nid); 3571 target_nid = numa_migrate_prep(page, vma, addr, page_nid);
3572 pte_unmap_unlock(ptep, ptl); 3572 pte_unmap_unlock(ptep, ptl);
3573 if (target_nid == -1) { 3573 if (target_nid == -1) {
3574 /*
3575 * Account for the fault against the current node if it not
3576 * being replaced regardless of where the page is located.
3577 */
3578 current_nid = numa_node_id();
3579 put_page(page); 3574 put_page(page);
3580 goto out; 3575 goto out;
3581 } 3576 }
@@ -3583,11 +3578,11 @@ int do_numa_page(struct mm_struct *mm, struct vm_area_struct *vma,
3583 /* Migrate to the requested node */ 3578 /* Migrate to the requested node */
3584 migrated = migrate_misplaced_page(page, target_nid); 3579 migrated = migrate_misplaced_page(page, target_nid);
3585 if (migrated) 3580 if (migrated)
3586 current_nid = target_nid; 3581 page_nid = target_nid;
3587 3582
3588out: 3583out:
3589 if (current_nid != -1) 3584 if (page_nid != -1)
3590 task_numa_fault(current_nid, 1, migrated); 3585 task_numa_fault(page_nid, 1, migrated);
3591 return 0; 3586 return 0;
3592} 3587}
3593 3588
@@ -3602,7 +3597,6 @@ static int do_pmd_numa_page(struct mm_struct *mm, struct vm_area_struct *vma,
3602 unsigned long offset; 3597 unsigned long offset;
3603 spinlock_t *ptl; 3598 spinlock_t *ptl;
3604 bool numa = false; 3599 bool numa = false;
3605 int local_nid = numa_node_id();
3606 3600
3607 spin_lock(&mm->page_table_lock); 3601 spin_lock(&mm->page_table_lock);
3608 pmd = *pmdp; 3602 pmd = *pmdp;
@@ -3625,9 +3619,10 @@ static int do_pmd_numa_page(struct mm_struct *mm, struct vm_area_struct *vma,
3625 for (addr = _addr + offset; addr < _addr + PMD_SIZE; pte++, addr += PAGE_SIZE) { 3619 for (addr = _addr + offset; addr < _addr + PMD_SIZE; pte++, addr += PAGE_SIZE) {
3626 pte_t pteval = *pte; 3620 pte_t pteval = *pte;
3627 struct page *page; 3621 struct page *page;
3628 int curr_nid = local_nid; 3622 int page_nid = -1;
3629 int target_nid; 3623 int target_nid;
3630 bool migrated; 3624 bool migrated = false;
3625
3631 if (!pte_present(pteval)) 3626 if (!pte_present(pteval))
3632 continue; 3627 continue;
3633 if (!pte_numa(pteval)) 3628 if (!pte_numa(pteval))
@@ -3649,25 +3644,19 @@ static int do_pmd_numa_page(struct mm_struct *mm, struct vm_area_struct *vma,
3649 if (unlikely(page_mapcount(page) != 1)) 3644 if (unlikely(page_mapcount(page) != 1))
3650 continue; 3645 continue;
3651 3646
3652 /* 3647 page_nid = page_to_nid(page);
3653 * Note that the NUMA fault is later accounted to either 3648 target_nid = numa_migrate_prep(page, vma, addr, page_nid);
3654 * the node that is currently running or where the page is 3649 pte_unmap_unlock(pte, ptl);
3655 * migrated to. 3650 if (target_nid != -1) {
3656 */ 3651 migrated = migrate_misplaced_page(page, target_nid);
3657 curr_nid = local_nid; 3652 if (migrated)
3658 target_nid = numa_migrate_prep(page, vma, addr, 3653 page_nid = target_nid;
3659 page_to_nid(page)); 3654 } else {
3660 if (target_nid == -1) {
3661 put_page(page); 3655 put_page(page);
3662 continue;
3663 } 3656 }
3664 3657
3665 /* Migrate to the requested node */ 3658 if (page_nid != -1)
3666 pte_unmap_unlock(pte, ptl); 3659 task_numa_fault(page_nid, 1, migrated);
3667 migrated = migrate_misplaced_page(page, target_nid);
3668 if (migrated)
3669 curr_nid = target_nid;
3670 task_numa_fault(curr_nid, 1, migrated);
3671 3660
3672 pte = pte_offset_map_lock(mm, pmdp, addr, &ptl); 3661 pte = pte_offset_map_lock(mm, pmdp, addr, &ptl);
3673 } 3662 }
diff --git a/mm/migrate.c b/mm/migrate.c
index 7a7325ee1d08..c04692774e88 100644
--- a/mm/migrate.c
+++ b/mm/migrate.c
@@ -1715,12 +1715,12 @@ int migrate_misplaced_transhuge_page(struct mm_struct *mm,
1715 unlock_page(new_page); 1715 unlock_page(new_page);
1716 put_page(new_page); /* Free it */ 1716 put_page(new_page); /* Free it */
1717 1717
1718 unlock_page(page); 1718 /* Retake the callers reference and putback on LRU */
1719 get_page(page);
1719 putback_lru_page(page); 1720 putback_lru_page(page);
1720 1721 mod_zone_page_state(page_zone(page),
1721 count_vm_events(PGMIGRATE_FAIL, HPAGE_PMD_NR); 1722 NR_ISOLATED_ANON + page_lru, -HPAGE_PMD_NR);
1722 isolated = 0; 1723 goto out_fail;
1723 goto out;
1724 } 1724 }
1725 1725
1726 /* 1726 /*
@@ -1737,9 +1737,9 @@ int migrate_misplaced_transhuge_page(struct mm_struct *mm,
1737 entry = maybe_pmd_mkwrite(pmd_mkdirty(entry), vma); 1737 entry = maybe_pmd_mkwrite(pmd_mkdirty(entry), vma);
1738 entry = pmd_mkhuge(entry); 1738 entry = pmd_mkhuge(entry);
1739 1739
1740 page_add_new_anon_rmap(new_page, vma, haddr); 1740 pmdp_clear_flush(vma, haddr, pmd);
1741
1742 set_pmd_at(mm, haddr, pmd, entry); 1741 set_pmd_at(mm, haddr, pmd, entry);
1742 page_add_new_anon_rmap(new_page, vma, haddr);
1743 update_mmu_cache_pmd(vma, address, &entry); 1743 update_mmu_cache_pmd(vma, address, &entry);
1744 page_remove_rmap(page); 1744 page_remove_rmap(page);
1745 /* 1745 /*
@@ -1758,7 +1758,6 @@ int migrate_misplaced_transhuge_page(struct mm_struct *mm,
1758 count_vm_events(PGMIGRATE_SUCCESS, HPAGE_PMD_NR); 1758 count_vm_events(PGMIGRATE_SUCCESS, HPAGE_PMD_NR);
1759 count_vm_numa_events(NUMA_PAGE_MIGRATE, HPAGE_PMD_NR); 1759 count_vm_numa_events(NUMA_PAGE_MIGRATE, HPAGE_PMD_NR);
1760 1760
1761out:
1762 mod_zone_page_state(page_zone(page), 1761 mod_zone_page_state(page_zone(page),
1763 NR_ISOLATED_ANON + page_lru, 1762 NR_ISOLATED_ANON + page_lru,
1764 -HPAGE_PMD_NR); 1763 -HPAGE_PMD_NR);
@@ -1767,6 +1766,10 @@ out:
1767out_fail: 1766out_fail:
1768 count_vm_events(PGMIGRATE_FAIL, HPAGE_PMD_NR); 1767 count_vm_events(PGMIGRATE_FAIL, HPAGE_PMD_NR);
1769out_dropref: 1768out_dropref:
1769 entry = pmd_mknonnuma(entry);
1770 set_pmd_at(mm, haddr, pmd, entry);
1771 update_mmu_cache_pmd(vma, address, &entry);
1772
1770 unlock_page(page); 1773 unlock_page(page);
1771 put_page(page); 1774 put_page(page);
1772 return 0; 1775 return 0;
diff --git a/mm/mprotect.c b/mm/mprotect.c
index a3af058f68e4..412ba2b7326a 100644
--- a/mm/mprotect.c
+++ b/mm/mprotect.c
@@ -148,7 +148,7 @@ static inline unsigned long change_pmd_range(struct vm_area_struct *vma,
148 split_huge_page_pmd(vma, addr, pmd); 148 split_huge_page_pmd(vma, addr, pmd);
149 else if (change_huge_pmd(vma, pmd, addr, newprot, 149 else if (change_huge_pmd(vma, pmd, addr, newprot,
150 prot_numa)) { 150 prot_numa)) {
151 pages += HPAGE_PMD_NR; 151 pages++;
152 continue; 152 continue;
153 } 153 }
154 /* fall through */ 154 /* fall through */
diff --git a/mm/pagewalk.c b/mm/pagewalk.c
index 5da2cbcfdbb5..2beeabf502c5 100644
--- a/mm/pagewalk.c
+++ b/mm/pagewalk.c
@@ -242,7 +242,7 @@ int walk_page_range(unsigned long addr, unsigned long end,
242 if (err) 242 if (err)
243 break; 243 break;
244 pgd++; 244 pgd++;
245 } while (addr = next, addr != end); 245 } while (addr = next, addr < end);
246 246
247 return err; 247 return err;
248} 248}
diff --git a/net/8021q/vlan_netlink.c b/net/8021q/vlan_netlink.c
index 309129732285..c7e634af8516 100644
--- a/net/8021q/vlan_netlink.c
+++ b/net/8021q/vlan_netlink.c
@@ -171,7 +171,7 @@ static size_t vlan_get_size(const struct net_device *dev)
171 171
172 return nla_total_size(2) + /* IFLA_VLAN_PROTOCOL */ 172 return nla_total_size(2) + /* IFLA_VLAN_PROTOCOL */
173 nla_total_size(2) + /* IFLA_VLAN_ID */ 173 nla_total_size(2) + /* IFLA_VLAN_ID */
174 sizeof(struct ifla_vlan_flags) + /* IFLA_VLAN_FLAGS */ 174 nla_total_size(sizeof(struct ifla_vlan_flags)) + /* IFLA_VLAN_FLAGS */
175 vlan_qos_map_size(vlan->nr_ingress_mappings) + 175 vlan_qos_map_size(vlan->nr_ingress_mappings) +
176 vlan_qos_map_size(vlan->nr_egress_mappings); 176 vlan_qos_map_size(vlan->nr_egress_mappings);
177} 177}
diff --git a/net/batman-adv/main.c b/net/batman-adv/main.c
index c72d1bcdcf49..1356af660b5b 100644
--- a/net/batman-adv/main.c
+++ b/net/batman-adv/main.c
@@ -65,6 +65,7 @@ static int __init batadv_init(void)
65 batadv_recv_handler_init(); 65 batadv_recv_handler_init();
66 66
67 batadv_iv_init(); 67 batadv_iv_init();
68 batadv_nc_init();
68 69
69 batadv_event_workqueue = create_singlethread_workqueue("bat_events"); 70 batadv_event_workqueue = create_singlethread_workqueue("bat_events");
70 71
@@ -142,7 +143,7 @@ int batadv_mesh_init(struct net_device *soft_iface)
142 if (ret < 0) 143 if (ret < 0)
143 goto err; 144 goto err;
144 145
145 ret = batadv_nc_init(bat_priv); 146 ret = batadv_nc_mesh_init(bat_priv);
146 if (ret < 0) 147 if (ret < 0)
147 goto err; 148 goto err;
148 149
@@ -167,7 +168,7 @@ void batadv_mesh_free(struct net_device *soft_iface)
167 batadv_vis_quit(bat_priv); 168 batadv_vis_quit(bat_priv);
168 169
169 batadv_gw_node_purge(bat_priv); 170 batadv_gw_node_purge(bat_priv);
170 batadv_nc_free(bat_priv); 171 batadv_nc_mesh_free(bat_priv);
171 batadv_dat_free(bat_priv); 172 batadv_dat_free(bat_priv);
172 batadv_bla_free(bat_priv); 173 batadv_bla_free(bat_priv);
173 174
diff --git a/net/batman-adv/network-coding.c b/net/batman-adv/network-coding.c
index a487d46e0aec..4ecc0b6bf8ab 100644
--- a/net/batman-adv/network-coding.c
+++ b/net/batman-adv/network-coding.c
@@ -35,6 +35,20 @@ static int batadv_nc_recv_coded_packet(struct sk_buff *skb,
35 struct batadv_hard_iface *recv_if); 35 struct batadv_hard_iface *recv_if);
36 36
37/** 37/**
38 * batadv_nc_init - one-time initialization for network coding
39 */
40int __init batadv_nc_init(void)
41{
42 int ret;
43
44 /* Register our packet type */
45 ret = batadv_recv_handler_register(BATADV_CODED,
46 batadv_nc_recv_coded_packet);
47
48 return ret;
49}
50
51/**
38 * batadv_nc_start_timer - initialise the nc periodic worker 52 * batadv_nc_start_timer - initialise the nc periodic worker
39 * @bat_priv: the bat priv with all the soft interface information 53 * @bat_priv: the bat priv with all the soft interface information
40 */ 54 */
@@ -45,10 +59,10 @@ static void batadv_nc_start_timer(struct batadv_priv *bat_priv)
45} 59}
46 60
47/** 61/**
48 * batadv_nc_init - initialise coding hash table and start house keeping 62 * batadv_nc_mesh_init - initialise coding hash table and start house keeping
49 * @bat_priv: the bat priv with all the soft interface information 63 * @bat_priv: the bat priv with all the soft interface information
50 */ 64 */
51int batadv_nc_init(struct batadv_priv *bat_priv) 65int batadv_nc_mesh_init(struct batadv_priv *bat_priv)
52{ 66{
53 bat_priv->nc.timestamp_fwd_flush = jiffies; 67 bat_priv->nc.timestamp_fwd_flush = jiffies;
54 bat_priv->nc.timestamp_sniffed_purge = jiffies; 68 bat_priv->nc.timestamp_sniffed_purge = jiffies;
@@ -70,11 +84,6 @@ int batadv_nc_init(struct batadv_priv *bat_priv)
70 batadv_hash_set_lock_class(bat_priv->nc.coding_hash, 84 batadv_hash_set_lock_class(bat_priv->nc.coding_hash,
71 &batadv_nc_decoding_hash_lock_class_key); 85 &batadv_nc_decoding_hash_lock_class_key);
72 86
73 /* Register our packet type */
74 if (batadv_recv_handler_register(BATADV_CODED,
75 batadv_nc_recv_coded_packet) < 0)
76 goto err;
77
78 INIT_DELAYED_WORK(&bat_priv->nc.work, batadv_nc_worker); 87 INIT_DELAYED_WORK(&bat_priv->nc.work, batadv_nc_worker);
79 batadv_nc_start_timer(bat_priv); 88 batadv_nc_start_timer(bat_priv);
80 89
@@ -1721,12 +1730,11 @@ free_nc_packet:
1721} 1730}
1722 1731
1723/** 1732/**
1724 * batadv_nc_free - clean up network coding memory 1733 * batadv_nc_mesh_free - clean up network coding memory
1725 * @bat_priv: the bat priv with all the soft interface information 1734 * @bat_priv: the bat priv with all the soft interface information
1726 */ 1735 */
1727void batadv_nc_free(struct batadv_priv *bat_priv) 1736void batadv_nc_mesh_free(struct batadv_priv *bat_priv)
1728{ 1737{
1729 batadv_recv_handler_unregister(BATADV_CODED);
1730 cancel_delayed_work_sync(&bat_priv->nc.work); 1738 cancel_delayed_work_sync(&bat_priv->nc.work);
1731 1739
1732 batadv_nc_purge_paths(bat_priv, bat_priv->nc.coding_hash, NULL); 1740 batadv_nc_purge_paths(bat_priv, bat_priv->nc.coding_hash, NULL);
diff --git a/net/batman-adv/network-coding.h b/net/batman-adv/network-coding.h
index 85a4ec81ad50..ddfa618e80bf 100644
--- a/net/batman-adv/network-coding.h
+++ b/net/batman-adv/network-coding.h
@@ -22,8 +22,9 @@
22 22
23#ifdef CONFIG_BATMAN_ADV_NC 23#ifdef CONFIG_BATMAN_ADV_NC
24 24
25int batadv_nc_init(struct batadv_priv *bat_priv); 25int batadv_nc_init(void);
26void batadv_nc_free(struct batadv_priv *bat_priv); 26int batadv_nc_mesh_init(struct batadv_priv *bat_priv);
27void batadv_nc_mesh_free(struct batadv_priv *bat_priv);
27void batadv_nc_update_nc_node(struct batadv_priv *bat_priv, 28void batadv_nc_update_nc_node(struct batadv_priv *bat_priv,
28 struct batadv_orig_node *orig_node, 29 struct batadv_orig_node *orig_node,
29 struct batadv_orig_node *orig_neigh_node, 30 struct batadv_orig_node *orig_neigh_node,
@@ -46,12 +47,17 @@ int batadv_nc_init_debugfs(struct batadv_priv *bat_priv);
46 47
47#else /* ifdef CONFIG_BATMAN_ADV_NC */ 48#else /* ifdef CONFIG_BATMAN_ADV_NC */
48 49
49static inline int batadv_nc_init(struct batadv_priv *bat_priv) 50static inline int batadv_nc_init(void)
50{ 51{
51 return 0; 52 return 0;
52} 53}
53 54
54static inline void batadv_nc_free(struct batadv_priv *bat_priv) 55static inline int batadv_nc_mesh_init(struct batadv_priv *bat_priv)
56{
57 return 0;
58}
59
60static inline void batadv_nc_mesh_free(struct batadv_priv *bat_priv)
55{ 61{
56 return; 62 return;
57} 63}
diff --git a/net/bridge/br_device.c b/net/bridge/br_device.c
index ca04163635da..e6b7fecb3af1 100644
--- a/net/bridge/br_device.c
+++ b/net/bridge/br_device.c
@@ -64,7 +64,7 @@ netdev_tx_t br_dev_xmit(struct sk_buff *skb, struct net_device *dev)
64 br_flood_deliver(br, skb, false); 64 br_flood_deliver(br, skb, false);
65 goto out; 65 goto out;
66 } 66 }
67 if (br_multicast_rcv(br, NULL, skb)) { 67 if (br_multicast_rcv(br, NULL, skb, vid)) {
68 kfree_skb(skb); 68 kfree_skb(skb);
69 goto out; 69 goto out;
70 } 70 }
diff --git a/net/bridge/br_fdb.c b/net/bridge/br_fdb.c
index ffd5874f2592..33e8f23acddd 100644
--- a/net/bridge/br_fdb.c
+++ b/net/bridge/br_fdb.c
@@ -700,7 +700,7 @@ int br_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
700 700
701 vid = nla_get_u16(tb[NDA_VLAN]); 701 vid = nla_get_u16(tb[NDA_VLAN]);
702 702
703 if (vid >= VLAN_N_VID) { 703 if (!vid || vid >= VLAN_VID_MASK) {
704 pr_info("bridge: RTM_NEWNEIGH with invalid vlan id %d\n", 704 pr_info("bridge: RTM_NEWNEIGH with invalid vlan id %d\n",
705 vid); 705 vid);
706 return -EINVAL; 706 return -EINVAL;
@@ -794,7 +794,7 @@ int br_fdb_delete(struct ndmsg *ndm, struct nlattr *tb[],
794 794
795 vid = nla_get_u16(tb[NDA_VLAN]); 795 vid = nla_get_u16(tb[NDA_VLAN]);
796 796
797 if (vid >= VLAN_N_VID) { 797 if (!vid || vid >= VLAN_VID_MASK) {
798 pr_info("bridge: RTM_NEWNEIGH with invalid vlan id %d\n", 798 pr_info("bridge: RTM_NEWNEIGH with invalid vlan id %d\n",
799 vid); 799 vid);
800 return -EINVAL; 800 return -EINVAL;
diff --git a/net/bridge/br_input.c b/net/bridge/br_input.c
index a2fd37ec35f7..7e73c32e205d 100644
--- a/net/bridge/br_input.c
+++ b/net/bridge/br_input.c
@@ -80,7 +80,7 @@ int br_handle_frame_finish(struct sk_buff *skb)
80 br_fdb_update(br, p, eth_hdr(skb)->h_source, vid); 80 br_fdb_update(br, p, eth_hdr(skb)->h_source, vid);
81 81
82 if (!is_broadcast_ether_addr(dest) && is_multicast_ether_addr(dest) && 82 if (!is_broadcast_ether_addr(dest) && is_multicast_ether_addr(dest) &&
83 br_multicast_rcv(br, p, skb)) 83 br_multicast_rcv(br, p, skb, vid))
84 goto drop; 84 goto drop;
85 85
86 if (p->state == BR_STATE_LEARNING) 86 if (p->state == BR_STATE_LEARNING)
diff --git a/net/bridge/br_mdb.c b/net/bridge/br_mdb.c
index 85a09bb5ca51..b7b1914dfa25 100644
--- a/net/bridge/br_mdb.c
+++ b/net/bridge/br_mdb.c
@@ -453,7 +453,7 @@ static int __br_mdb_del(struct net_bridge *br, struct br_mdb_entry *entry)
453 call_rcu_bh(&p->rcu, br_multicast_free_pg); 453 call_rcu_bh(&p->rcu, br_multicast_free_pg);
454 err = 0; 454 err = 0;
455 455
456 if (!mp->ports && !mp->mglist && mp->timer_armed && 456 if (!mp->ports && !mp->mglist &&
457 netif_running(br->dev)) 457 netif_running(br->dev))
458 mod_timer(&mp->timer, jiffies); 458 mod_timer(&mp->timer, jiffies);
459 break; 459 break;
diff --git a/net/bridge/br_multicast.c b/net/bridge/br_multicast.c
index d1c578630678..686284ff3d6a 100644
--- a/net/bridge/br_multicast.c
+++ b/net/bridge/br_multicast.c
@@ -272,7 +272,7 @@ static void br_multicast_del_pg(struct net_bridge *br,
272 del_timer(&p->timer); 272 del_timer(&p->timer);
273 call_rcu_bh(&p->rcu, br_multicast_free_pg); 273 call_rcu_bh(&p->rcu, br_multicast_free_pg);
274 274
275 if (!mp->ports && !mp->mglist && mp->timer_armed && 275 if (!mp->ports && !mp->mglist &&
276 netif_running(br->dev)) 276 netif_running(br->dev))
277 mod_timer(&mp->timer, jiffies); 277 mod_timer(&mp->timer, jiffies);
278 278
@@ -620,7 +620,6 @@ rehash:
620 620
621 mp->br = br; 621 mp->br = br;
622 mp->addr = *group; 622 mp->addr = *group;
623
624 setup_timer(&mp->timer, br_multicast_group_expired, 623 setup_timer(&mp->timer, br_multicast_group_expired,
625 (unsigned long)mp); 624 (unsigned long)mp);
626 625
@@ -660,6 +659,7 @@ static int br_multicast_add_group(struct net_bridge *br,
660 struct net_bridge_mdb_entry *mp; 659 struct net_bridge_mdb_entry *mp;
661 struct net_bridge_port_group *p; 660 struct net_bridge_port_group *p;
662 struct net_bridge_port_group __rcu **pp; 661 struct net_bridge_port_group __rcu **pp;
662 unsigned long now = jiffies;
663 int err; 663 int err;
664 664
665 spin_lock(&br->multicast_lock); 665 spin_lock(&br->multicast_lock);
@@ -674,6 +674,7 @@ static int br_multicast_add_group(struct net_bridge *br,
674 674
675 if (!port) { 675 if (!port) {
676 mp->mglist = true; 676 mp->mglist = true;
677 mod_timer(&mp->timer, now + br->multicast_membership_interval);
677 goto out; 678 goto out;
678 } 679 }
679 680
@@ -681,7 +682,7 @@ static int br_multicast_add_group(struct net_bridge *br,
681 (p = mlock_dereference(*pp, br)) != NULL; 682 (p = mlock_dereference(*pp, br)) != NULL;
682 pp = &p->next) { 683 pp = &p->next) {
683 if (p->port == port) 684 if (p->port == port)
684 goto out; 685 goto found;
685 if ((unsigned long)p->port < (unsigned long)port) 686 if ((unsigned long)p->port < (unsigned long)port)
686 break; 687 break;
687 } 688 }
@@ -692,6 +693,8 @@ static int br_multicast_add_group(struct net_bridge *br,
692 rcu_assign_pointer(*pp, p); 693 rcu_assign_pointer(*pp, p);
693 br_mdb_notify(br->dev, port, group, RTM_NEWMDB); 694 br_mdb_notify(br->dev, port, group, RTM_NEWMDB);
694 695
696found:
697 mod_timer(&p->timer, now + br->multicast_membership_interval);
695out: 698out:
696 err = 0; 699 err = 0;
697 700
@@ -944,7 +947,8 @@ void br_multicast_disable_port(struct net_bridge_port *port)
944 947
945static int br_ip4_multicast_igmp3_report(struct net_bridge *br, 948static int br_ip4_multicast_igmp3_report(struct net_bridge *br,
946 struct net_bridge_port *port, 949 struct net_bridge_port *port,
947 struct sk_buff *skb) 950 struct sk_buff *skb,
951 u16 vid)
948{ 952{
949 struct igmpv3_report *ih; 953 struct igmpv3_report *ih;
950 struct igmpv3_grec *grec; 954 struct igmpv3_grec *grec;
@@ -954,12 +958,10 @@ static int br_ip4_multicast_igmp3_report(struct net_bridge *br,
954 int type; 958 int type;
955 int err = 0; 959 int err = 0;
956 __be32 group; 960 __be32 group;
957 u16 vid = 0;
958 961
959 if (!pskb_may_pull(skb, sizeof(*ih))) 962 if (!pskb_may_pull(skb, sizeof(*ih)))
960 return -EINVAL; 963 return -EINVAL;
961 964
962 br_vlan_get_tag(skb, &vid);
963 ih = igmpv3_report_hdr(skb); 965 ih = igmpv3_report_hdr(skb);
964 num = ntohs(ih->ngrec); 966 num = ntohs(ih->ngrec);
965 len = sizeof(*ih); 967 len = sizeof(*ih);
@@ -1002,7 +1004,8 @@ static int br_ip4_multicast_igmp3_report(struct net_bridge *br,
1002#if IS_ENABLED(CONFIG_IPV6) 1004#if IS_ENABLED(CONFIG_IPV6)
1003static int br_ip6_multicast_mld2_report(struct net_bridge *br, 1005static int br_ip6_multicast_mld2_report(struct net_bridge *br,
1004 struct net_bridge_port *port, 1006 struct net_bridge_port *port,
1005 struct sk_buff *skb) 1007 struct sk_buff *skb,
1008 u16 vid)
1006{ 1009{
1007 struct icmp6hdr *icmp6h; 1010 struct icmp6hdr *icmp6h;
1008 struct mld2_grec *grec; 1011 struct mld2_grec *grec;
@@ -1010,12 +1013,10 @@ static int br_ip6_multicast_mld2_report(struct net_bridge *br,
1010 int len; 1013 int len;
1011 int num; 1014 int num;
1012 int err = 0; 1015 int err = 0;
1013 u16 vid = 0;
1014 1016
1015 if (!pskb_may_pull(skb, sizeof(*icmp6h))) 1017 if (!pskb_may_pull(skb, sizeof(*icmp6h)))
1016 return -EINVAL; 1018 return -EINVAL;
1017 1019
1018 br_vlan_get_tag(skb, &vid);
1019 icmp6h = icmp6_hdr(skb); 1020 icmp6h = icmp6_hdr(skb);
1020 num = ntohs(icmp6h->icmp6_dataun.un_data16[1]); 1021 num = ntohs(icmp6h->icmp6_dataun.un_data16[1]);
1021 len = sizeof(*icmp6h); 1022 len = sizeof(*icmp6h);
@@ -1138,7 +1139,8 @@ static void br_multicast_query_received(struct net_bridge *br,
1138 1139
1139static int br_ip4_multicast_query(struct net_bridge *br, 1140static int br_ip4_multicast_query(struct net_bridge *br,
1140 struct net_bridge_port *port, 1141 struct net_bridge_port *port,
1141 struct sk_buff *skb) 1142 struct sk_buff *skb,
1143 u16 vid)
1142{ 1144{
1143 const struct iphdr *iph = ip_hdr(skb); 1145 const struct iphdr *iph = ip_hdr(skb);
1144 struct igmphdr *ih = igmp_hdr(skb); 1146 struct igmphdr *ih = igmp_hdr(skb);
@@ -1150,7 +1152,6 @@ static int br_ip4_multicast_query(struct net_bridge *br,
1150 unsigned long now = jiffies; 1152 unsigned long now = jiffies;
1151 __be32 group; 1153 __be32 group;
1152 int err = 0; 1154 int err = 0;
1153 u16 vid = 0;
1154 1155
1155 spin_lock(&br->multicast_lock); 1156 spin_lock(&br->multicast_lock);
1156 if (!netif_running(br->dev) || 1157 if (!netif_running(br->dev) ||
@@ -1186,14 +1187,10 @@ static int br_ip4_multicast_query(struct net_bridge *br,
1186 if (!group) 1187 if (!group)
1187 goto out; 1188 goto out;
1188 1189
1189 br_vlan_get_tag(skb, &vid);
1190 mp = br_mdb_ip4_get(mlock_dereference(br->mdb, br), group, vid); 1190 mp = br_mdb_ip4_get(mlock_dereference(br->mdb, br), group, vid);
1191 if (!mp) 1191 if (!mp)
1192 goto out; 1192 goto out;
1193 1193
1194 mod_timer(&mp->timer, now + br->multicast_membership_interval);
1195 mp->timer_armed = true;
1196
1197 max_delay *= br->multicast_last_member_count; 1194 max_delay *= br->multicast_last_member_count;
1198 1195
1199 if (mp->mglist && 1196 if (mp->mglist &&
@@ -1219,7 +1216,8 @@ out:
1219#if IS_ENABLED(CONFIG_IPV6) 1216#if IS_ENABLED(CONFIG_IPV6)
1220static int br_ip6_multicast_query(struct net_bridge *br, 1217static int br_ip6_multicast_query(struct net_bridge *br,
1221 struct net_bridge_port *port, 1218 struct net_bridge_port *port,
1222 struct sk_buff *skb) 1219 struct sk_buff *skb,
1220 u16 vid)
1223{ 1221{
1224 const struct ipv6hdr *ip6h = ipv6_hdr(skb); 1222 const struct ipv6hdr *ip6h = ipv6_hdr(skb);
1225 struct mld_msg *mld; 1223 struct mld_msg *mld;
@@ -1231,7 +1229,6 @@ static int br_ip6_multicast_query(struct net_bridge *br,
1231 unsigned long now = jiffies; 1229 unsigned long now = jiffies;
1232 const struct in6_addr *group = NULL; 1230 const struct in6_addr *group = NULL;
1233 int err = 0; 1231 int err = 0;
1234 u16 vid = 0;
1235 1232
1236 spin_lock(&br->multicast_lock); 1233 spin_lock(&br->multicast_lock);
1237 if (!netif_running(br->dev) || 1234 if (!netif_running(br->dev) ||
@@ -1265,14 +1262,10 @@ static int br_ip6_multicast_query(struct net_bridge *br,
1265 if (!group) 1262 if (!group)
1266 goto out; 1263 goto out;
1267 1264
1268 br_vlan_get_tag(skb, &vid);
1269 mp = br_mdb_ip6_get(mlock_dereference(br->mdb, br), group, vid); 1265 mp = br_mdb_ip6_get(mlock_dereference(br->mdb, br), group, vid);
1270 if (!mp) 1266 if (!mp)
1271 goto out; 1267 goto out;
1272 1268
1273 mod_timer(&mp->timer, now + br->multicast_membership_interval);
1274 mp->timer_armed = true;
1275
1276 max_delay *= br->multicast_last_member_count; 1269 max_delay *= br->multicast_last_member_count;
1277 if (mp->mglist && 1270 if (mp->mglist &&
1278 (timer_pending(&mp->timer) ? 1271 (timer_pending(&mp->timer) ?
@@ -1358,7 +1351,7 @@ static void br_multicast_leave_group(struct net_bridge *br,
1358 call_rcu_bh(&p->rcu, br_multicast_free_pg); 1351 call_rcu_bh(&p->rcu, br_multicast_free_pg);
1359 br_mdb_notify(br->dev, port, group, RTM_DELMDB); 1352 br_mdb_notify(br->dev, port, group, RTM_DELMDB);
1360 1353
1361 if (!mp->ports && !mp->mglist && mp->timer_armed && 1354 if (!mp->ports && !mp->mglist &&
1362 netif_running(br->dev)) 1355 netif_running(br->dev))
1363 mod_timer(&mp->timer, jiffies); 1356 mod_timer(&mp->timer, jiffies);
1364 } 1357 }
@@ -1370,12 +1363,30 @@ static void br_multicast_leave_group(struct net_bridge *br,
1370 br->multicast_last_member_interval; 1363 br->multicast_last_member_interval;
1371 1364
1372 if (!port) { 1365 if (!port) {
1373 if (mp->mglist && mp->timer_armed && 1366 if (mp->mglist &&
1374 (timer_pending(&mp->timer) ? 1367 (timer_pending(&mp->timer) ?
1375 time_after(mp->timer.expires, time) : 1368 time_after(mp->timer.expires, time) :
1376 try_to_del_timer_sync(&mp->timer) >= 0)) { 1369 try_to_del_timer_sync(&mp->timer) >= 0)) {
1377 mod_timer(&mp->timer, time); 1370 mod_timer(&mp->timer, time);
1378 } 1371 }
1372
1373 goto out;
1374 }
1375
1376 for (p = mlock_dereference(mp->ports, br);
1377 p != NULL;
1378 p = mlock_dereference(p->next, br)) {
1379 if (p->port != port)
1380 continue;
1381
1382 if (!hlist_unhashed(&p->mglist) &&
1383 (timer_pending(&p->timer) ?
1384 time_after(p->timer.expires, time) :
1385 try_to_del_timer_sync(&p->timer) >= 0)) {
1386 mod_timer(&p->timer, time);
1387 }
1388
1389 break;
1379 } 1390 }
1380out: 1391out:
1381 spin_unlock(&br->multicast_lock); 1392 spin_unlock(&br->multicast_lock);
@@ -1424,7 +1435,8 @@ static void br_ip6_multicast_leave_group(struct net_bridge *br,
1424 1435
1425static int br_multicast_ipv4_rcv(struct net_bridge *br, 1436static int br_multicast_ipv4_rcv(struct net_bridge *br,
1426 struct net_bridge_port *port, 1437 struct net_bridge_port *port,
1427 struct sk_buff *skb) 1438 struct sk_buff *skb,
1439 u16 vid)
1428{ 1440{
1429 struct sk_buff *skb2 = skb; 1441 struct sk_buff *skb2 = skb;
1430 const struct iphdr *iph; 1442 const struct iphdr *iph;
@@ -1432,7 +1444,6 @@ static int br_multicast_ipv4_rcv(struct net_bridge *br,
1432 unsigned int len; 1444 unsigned int len;
1433 unsigned int offset; 1445 unsigned int offset;
1434 int err; 1446 int err;
1435 u16 vid = 0;
1436 1447
1437 /* We treat OOM as packet loss for now. */ 1448 /* We treat OOM as packet loss for now. */
1438 if (!pskb_may_pull(skb, sizeof(*iph))) 1449 if (!pskb_may_pull(skb, sizeof(*iph)))
@@ -1493,7 +1504,6 @@ static int br_multicast_ipv4_rcv(struct net_bridge *br,
1493 1504
1494 err = 0; 1505 err = 0;
1495 1506
1496 br_vlan_get_tag(skb2, &vid);
1497 BR_INPUT_SKB_CB(skb)->igmp = 1; 1507 BR_INPUT_SKB_CB(skb)->igmp = 1;
1498 ih = igmp_hdr(skb2); 1508 ih = igmp_hdr(skb2);
1499 1509
@@ -1504,10 +1514,10 @@ static int br_multicast_ipv4_rcv(struct net_bridge *br,
1504 err = br_ip4_multicast_add_group(br, port, ih->group, vid); 1514 err = br_ip4_multicast_add_group(br, port, ih->group, vid);
1505 break; 1515 break;
1506 case IGMPV3_HOST_MEMBERSHIP_REPORT: 1516 case IGMPV3_HOST_MEMBERSHIP_REPORT:
1507 err = br_ip4_multicast_igmp3_report(br, port, skb2); 1517 err = br_ip4_multicast_igmp3_report(br, port, skb2, vid);
1508 break; 1518 break;
1509 case IGMP_HOST_MEMBERSHIP_QUERY: 1519 case IGMP_HOST_MEMBERSHIP_QUERY:
1510 err = br_ip4_multicast_query(br, port, skb2); 1520 err = br_ip4_multicast_query(br, port, skb2, vid);
1511 break; 1521 break;
1512 case IGMP_HOST_LEAVE_MESSAGE: 1522 case IGMP_HOST_LEAVE_MESSAGE:
1513 br_ip4_multicast_leave_group(br, port, ih->group, vid); 1523 br_ip4_multicast_leave_group(br, port, ih->group, vid);
@@ -1525,7 +1535,8 @@ err_out:
1525#if IS_ENABLED(CONFIG_IPV6) 1535#if IS_ENABLED(CONFIG_IPV6)
1526static int br_multicast_ipv6_rcv(struct net_bridge *br, 1536static int br_multicast_ipv6_rcv(struct net_bridge *br,
1527 struct net_bridge_port *port, 1537 struct net_bridge_port *port,
1528 struct sk_buff *skb) 1538 struct sk_buff *skb,
1539 u16 vid)
1529{ 1540{
1530 struct sk_buff *skb2; 1541 struct sk_buff *skb2;
1531 const struct ipv6hdr *ip6h; 1542 const struct ipv6hdr *ip6h;
@@ -1535,7 +1546,6 @@ static int br_multicast_ipv6_rcv(struct net_bridge *br,
1535 unsigned int len; 1546 unsigned int len;
1536 int offset; 1547 int offset;
1537 int err; 1548 int err;
1538 u16 vid = 0;
1539 1549
1540 if (!pskb_may_pull(skb, sizeof(*ip6h))) 1550 if (!pskb_may_pull(skb, sizeof(*ip6h)))
1541 return -EINVAL; 1551 return -EINVAL;
@@ -1625,7 +1635,6 @@ static int br_multicast_ipv6_rcv(struct net_bridge *br,
1625 1635
1626 err = 0; 1636 err = 0;
1627 1637
1628 br_vlan_get_tag(skb, &vid);
1629 BR_INPUT_SKB_CB(skb)->igmp = 1; 1638 BR_INPUT_SKB_CB(skb)->igmp = 1;
1630 1639
1631 switch (icmp6_type) { 1640 switch (icmp6_type) {
@@ -1642,10 +1651,10 @@ static int br_multicast_ipv6_rcv(struct net_bridge *br,
1642 break; 1651 break;
1643 } 1652 }
1644 case ICMPV6_MLD2_REPORT: 1653 case ICMPV6_MLD2_REPORT:
1645 err = br_ip6_multicast_mld2_report(br, port, skb2); 1654 err = br_ip6_multicast_mld2_report(br, port, skb2, vid);
1646 break; 1655 break;
1647 case ICMPV6_MGM_QUERY: 1656 case ICMPV6_MGM_QUERY:
1648 err = br_ip6_multicast_query(br, port, skb2); 1657 err = br_ip6_multicast_query(br, port, skb2, vid);
1649 break; 1658 break;
1650 case ICMPV6_MGM_REDUCTION: 1659 case ICMPV6_MGM_REDUCTION:
1651 { 1660 {
@@ -1666,7 +1675,7 @@ out:
1666#endif 1675#endif
1667 1676
1668int br_multicast_rcv(struct net_bridge *br, struct net_bridge_port *port, 1677int br_multicast_rcv(struct net_bridge *br, struct net_bridge_port *port,
1669 struct sk_buff *skb) 1678 struct sk_buff *skb, u16 vid)
1670{ 1679{
1671 BR_INPUT_SKB_CB(skb)->igmp = 0; 1680 BR_INPUT_SKB_CB(skb)->igmp = 0;
1672 BR_INPUT_SKB_CB(skb)->mrouters_only = 0; 1681 BR_INPUT_SKB_CB(skb)->mrouters_only = 0;
@@ -1676,10 +1685,10 @@ int br_multicast_rcv(struct net_bridge *br, struct net_bridge_port *port,
1676 1685
1677 switch (skb->protocol) { 1686 switch (skb->protocol) {
1678 case htons(ETH_P_IP): 1687 case htons(ETH_P_IP):
1679 return br_multicast_ipv4_rcv(br, port, skb); 1688 return br_multicast_ipv4_rcv(br, port, skb, vid);
1680#if IS_ENABLED(CONFIG_IPV6) 1689#if IS_ENABLED(CONFIG_IPV6)
1681 case htons(ETH_P_IPV6): 1690 case htons(ETH_P_IPV6):
1682 return br_multicast_ipv6_rcv(br, port, skb); 1691 return br_multicast_ipv6_rcv(br, port, skb, vid);
1683#endif 1692#endif
1684 } 1693 }
1685 1694
@@ -1798,7 +1807,6 @@ void br_multicast_stop(struct net_bridge *br)
1798 hlist_for_each_entry_safe(mp, n, &mdb->mhash[i], 1807 hlist_for_each_entry_safe(mp, n, &mdb->mhash[i],
1799 hlist[ver]) { 1808 hlist[ver]) {
1800 del_timer(&mp->timer); 1809 del_timer(&mp->timer);
1801 mp->timer_armed = false;
1802 call_rcu_bh(&mp->rcu, br_multicast_free_group); 1810 call_rcu_bh(&mp->rcu, br_multicast_free_group);
1803 } 1811 }
1804 } 1812 }
diff --git a/net/bridge/br_netlink.c b/net/bridge/br_netlink.c
index e74ddc1c29a8..f75d92e4f96b 100644
--- a/net/bridge/br_netlink.c
+++ b/net/bridge/br_netlink.c
@@ -243,7 +243,7 @@ static int br_afspec(struct net_bridge *br,
243 243
244 vinfo = nla_data(tb[IFLA_BRIDGE_VLAN_INFO]); 244 vinfo = nla_data(tb[IFLA_BRIDGE_VLAN_INFO]);
245 245
246 if (vinfo->vid >= VLAN_N_VID) 246 if (!vinfo->vid || vinfo->vid >= VLAN_VID_MASK)
247 return -EINVAL; 247 return -EINVAL;
248 248
249 switch (cmd) { 249 switch (cmd) {
diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h
index efb57d911569..2e8244efb262 100644
--- a/net/bridge/br_private.h
+++ b/net/bridge/br_private.h
@@ -126,7 +126,6 @@ struct net_bridge_mdb_entry
126 struct timer_list timer; 126 struct timer_list timer;
127 struct br_ip addr; 127 struct br_ip addr;
128 bool mglist; 128 bool mglist;
129 bool timer_armed;
130}; 129};
131 130
132struct net_bridge_mdb_htable 131struct net_bridge_mdb_htable
@@ -452,7 +451,8 @@ extern int br_ioctl_deviceless_stub(struct net *net, unsigned int cmd, void __us
452extern unsigned int br_mdb_rehash_seq; 451extern unsigned int br_mdb_rehash_seq;
453extern int br_multicast_rcv(struct net_bridge *br, 452extern int br_multicast_rcv(struct net_bridge *br,
454 struct net_bridge_port *port, 453 struct net_bridge_port *port,
455 struct sk_buff *skb); 454 struct sk_buff *skb,
455 u16 vid);
456extern struct net_bridge_mdb_entry *br_mdb_get(struct net_bridge *br, 456extern struct net_bridge_mdb_entry *br_mdb_get(struct net_bridge *br,
457 struct sk_buff *skb, u16 vid); 457 struct sk_buff *skb, u16 vid);
458extern void br_multicast_add_port(struct net_bridge_port *port); 458extern void br_multicast_add_port(struct net_bridge_port *port);
@@ -523,7 +523,8 @@ static inline bool br_multicast_querier_exists(struct net_bridge *br,
523#else 523#else
524static inline int br_multicast_rcv(struct net_bridge *br, 524static inline int br_multicast_rcv(struct net_bridge *br,
525 struct net_bridge_port *port, 525 struct net_bridge_port *port,
526 struct sk_buff *skb) 526 struct sk_buff *skb,
527 u16 vid)
527{ 528{
528 return 0; 529 return 0;
529} 530}
@@ -643,9 +644,7 @@ static inline u16 br_get_pvid(const struct net_port_vlans *v)
643 * vid wasn't set 644 * vid wasn't set
644 */ 645 */
645 smp_rmb(); 646 smp_rmb();
646 return (v->pvid & VLAN_TAG_PRESENT) ? 647 return v->pvid ?: VLAN_N_VID;
647 (v->pvid & ~VLAN_TAG_PRESENT) :
648 VLAN_N_VID;
649} 648}
650 649
651#else 650#else
diff --git a/net/bridge/br_stp_if.c b/net/bridge/br_stp_if.c
index 108084a04671..656a6f3e40de 100644
--- a/net/bridge/br_stp_if.c
+++ b/net/bridge/br_stp_if.c
@@ -134,7 +134,7 @@ static void br_stp_start(struct net_bridge *br)
134 134
135 if (br->bridge_forward_delay < BR_MIN_FORWARD_DELAY) 135 if (br->bridge_forward_delay < BR_MIN_FORWARD_DELAY)
136 __br_set_forward_delay(br, BR_MIN_FORWARD_DELAY); 136 __br_set_forward_delay(br, BR_MIN_FORWARD_DELAY);
137 else if (br->bridge_forward_delay < BR_MAX_FORWARD_DELAY) 137 else if (br->bridge_forward_delay > BR_MAX_FORWARD_DELAY)
138 __br_set_forward_delay(br, BR_MAX_FORWARD_DELAY); 138 __br_set_forward_delay(br, BR_MAX_FORWARD_DELAY);
139 139
140 if (r == 0) { 140 if (r == 0) {
diff --git a/net/bridge/br_vlan.c b/net/bridge/br_vlan.c
index 9a9ffe7e4019..53f0990eab58 100644
--- a/net/bridge/br_vlan.c
+++ b/net/bridge/br_vlan.c
@@ -45,37 +45,34 @@ static int __vlan_add(struct net_port_vlans *v, u16 vid, u16 flags)
45 return 0; 45 return 0;
46 } 46 }
47 47
48 if (vid) { 48 if (v->port_idx) {
49 if (v->port_idx) { 49 p = v->parent.port;
50 p = v->parent.port; 50 br = p->br;
51 br = p->br; 51 dev = p->dev;
52 dev = p->dev; 52 } else {
53 } else { 53 br = v->parent.br;
54 br = v->parent.br; 54 dev = br->dev;
55 dev = br->dev; 55 }
56 } 56 ops = dev->netdev_ops;
57 ops = dev->netdev_ops; 57
58 58 if (p && (dev->features & NETIF_F_HW_VLAN_CTAG_FILTER)) {
59 if (p && (dev->features & NETIF_F_HW_VLAN_CTAG_FILTER)) { 59 /* Add VLAN to the device filter if it is supported.
60 /* Add VLAN to the device filter if it is supported. 60 * Stricly speaking, this is not necessary now, since
61 * Stricly speaking, this is not necessary now, since 61 * devices are made promiscuous by the bridge, but if
62 * devices are made promiscuous by the bridge, but if 62 * that ever changes this code will allow tagged
63 * that ever changes this code will allow tagged 63 * traffic to enter the bridge.
64 * traffic to enter the bridge. 64 */
65 */ 65 err = ops->ndo_vlan_rx_add_vid(dev, htons(ETH_P_8021Q),
66 err = ops->ndo_vlan_rx_add_vid(dev, htons(ETH_P_8021Q), 66 vid);
67 vid); 67 if (err)
68 if (err) 68 return err;
69 return err; 69 }
70 }
71
72 err = br_fdb_insert(br, p, dev->dev_addr, vid);
73 if (err) {
74 br_err(br, "failed insert local address into bridge "
75 "forwarding table\n");
76 goto out_filt;
77 }
78 70
71 err = br_fdb_insert(br, p, dev->dev_addr, vid);
72 if (err) {
73 br_err(br, "failed insert local address into bridge "
74 "forwarding table\n");
75 goto out_filt;
79 } 76 }
80 77
81 set_bit(vid, v->vlan_bitmap); 78 set_bit(vid, v->vlan_bitmap);
@@ -98,7 +95,7 @@ static int __vlan_del(struct net_port_vlans *v, u16 vid)
98 __vlan_delete_pvid(v, vid); 95 __vlan_delete_pvid(v, vid);
99 clear_bit(vid, v->untagged_bitmap); 96 clear_bit(vid, v->untagged_bitmap);
100 97
101 if (v->port_idx && vid) { 98 if (v->port_idx) {
102 struct net_device *dev = v->parent.port->dev; 99 struct net_device *dev = v->parent.port->dev;
103 const struct net_device_ops *ops = dev->netdev_ops; 100 const struct net_device_ops *ops = dev->netdev_ops;
104 101
@@ -192,6 +189,8 @@ out:
192bool br_allowed_ingress(struct net_bridge *br, struct net_port_vlans *v, 189bool br_allowed_ingress(struct net_bridge *br, struct net_port_vlans *v,
193 struct sk_buff *skb, u16 *vid) 190 struct sk_buff *skb, u16 *vid)
194{ 191{
192 int err;
193
195 /* If VLAN filtering is disabled on the bridge, all packets are 194 /* If VLAN filtering is disabled on the bridge, all packets are
196 * permitted. 195 * permitted.
197 */ 196 */
@@ -204,20 +203,32 @@ bool br_allowed_ingress(struct net_bridge *br, struct net_port_vlans *v,
204 if (!v) 203 if (!v)
205 return false; 204 return false;
206 205
207 if (br_vlan_get_tag(skb, vid)) { 206 err = br_vlan_get_tag(skb, vid);
207 if (!*vid) {
208 u16 pvid = br_get_pvid(v); 208 u16 pvid = br_get_pvid(v);
209 209
210 /* Frame did not have a tag. See if pvid is set 210 /* Frame had a tag with VID 0 or did not have a tag.
211 * on this port. That tells us which vlan untagged 211 * See if pvid is set on this port. That tells us which
212 * traffic belongs to. 212 * vlan untagged or priority-tagged traffic belongs to.
213 */ 213 */
214 if (pvid == VLAN_N_VID) 214 if (pvid == VLAN_N_VID)
215 return false; 215 return false;
216 216
217 /* PVID is set on this port. Any untagged ingress 217 /* PVID is set on this port. Any untagged or priority-tagged
218 * frame is considered to belong to this vlan. 218 * ingress frame is considered to belong to this vlan.
219 */ 219 */
220 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), pvid); 220 *vid = pvid;
221 if (likely(err))
222 /* Untagged Frame. */
223 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), pvid);
224 else
225 /* Priority-tagged Frame.
226 * At this point, We know that skb->vlan_tci had
227 * VLAN_TAG_PRESENT bit and its VID field was 0x000.
228 * We update only VID field and preserve PCP field.
229 */
230 skb->vlan_tci |= pvid;
231
221 return true; 232 return true;
222 } 233 }
223 234
@@ -248,7 +259,9 @@ bool br_allowed_egress(struct net_bridge *br,
248 return false; 259 return false;
249} 260}
250 261
251/* Must be protected by RTNL */ 262/* Must be protected by RTNL.
263 * Must be called with vid in range from 1 to 4094 inclusive.
264 */
252int br_vlan_add(struct net_bridge *br, u16 vid, u16 flags) 265int br_vlan_add(struct net_bridge *br, u16 vid, u16 flags)
253{ 266{
254 struct net_port_vlans *pv = NULL; 267 struct net_port_vlans *pv = NULL;
@@ -278,7 +291,9 @@ out:
278 return err; 291 return err;
279} 292}
280 293
281/* Must be protected by RTNL */ 294/* Must be protected by RTNL.
295 * Must be called with vid in range from 1 to 4094 inclusive.
296 */
282int br_vlan_delete(struct net_bridge *br, u16 vid) 297int br_vlan_delete(struct net_bridge *br, u16 vid)
283{ 298{
284 struct net_port_vlans *pv; 299 struct net_port_vlans *pv;
@@ -289,14 +304,9 @@ int br_vlan_delete(struct net_bridge *br, u16 vid)
289 if (!pv) 304 if (!pv)
290 return -EINVAL; 305 return -EINVAL;
291 306
292 if (vid) { 307 spin_lock_bh(&br->hash_lock);
293 /* If the VID !=0 remove fdb for this vid. VID 0 is special 308 fdb_delete_by_addr(br, br->dev->dev_addr, vid);
294 * in that it's the default and is always there in the fdb. 309 spin_unlock_bh(&br->hash_lock);
295 */
296 spin_lock_bh(&br->hash_lock);
297 fdb_delete_by_addr(br, br->dev->dev_addr, vid);
298 spin_unlock_bh(&br->hash_lock);
299 }
300 310
301 __vlan_del(pv, vid); 311 __vlan_del(pv, vid);
302 return 0; 312 return 0;
@@ -329,7 +339,9 @@ unlock:
329 return 0; 339 return 0;
330} 340}
331 341
332/* Must be protected by RTNL */ 342/* Must be protected by RTNL.
343 * Must be called with vid in range from 1 to 4094 inclusive.
344 */
333int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags) 345int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags)
334{ 346{
335 struct net_port_vlans *pv = NULL; 347 struct net_port_vlans *pv = NULL;
@@ -363,7 +375,9 @@ clean_up:
363 return err; 375 return err;
364} 376}
365 377
366/* Must be protected by RTNL */ 378/* Must be protected by RTNL.
379 * Must be called with vid in range from 1 to 4094 inclusive.
380 */
367int nbp_vlan_delete(struct net_bridge_port *port, u16 vid) 381int nbp_vlan_delete(struct net_bridge_port *port, u16 vid)
368{ 382{
369 struct net_port_vlans *pv; 383 struct net_port_vlans *pv;
@@ -374,14 +388,9 @@ int nbp_vlan_delete(struct net_bridge_port *port, u16 vid)
374 if (!pv) 388 if (!pv)
375 return -EINVAL; 389 return -EINVAL;
376 390
377 if (vid) { 391 spin_lock_bh(&port->br->hash_lock);
378 /* If the VID !=0 remove fdb for this vid. VID 0 is special 392 fdb_delete_by_addr(port->br, port->dev->dev_addr, vid);
379 * in that it's the default and is always there in the fdb. 393 spin_unlock_bh(&port->br->hash_lock);
380 */
381 spin_lock_bh(&port->br->hash_lock);
382 fdb_delete_by_addr(port->br, port->dev->dev_addr, vid);
383 spin_unlock_bh(&port->br->hash_lock);
384 }
385 394
386 return __vlan_del(pv, vid); 395 return __vlan_del(pv, vid);
387} 396}
diff --git a/net/bridge/netfilter/ebt_ulog.c b/net/bridge/netfilter/ebt_ulog.c
index 518093802d1d..7c470c371e14 100644
--- a/net/bridge/netfilter/ebt_ulog.c
+++ b/net/bridge/netfilter/ebt_ulog.c
@@ -181,6 +181,7 @@ static void ebt_ulog_packet(struct net *net, unsigned int hooknr,
181 ub->qlen++; 181 ub->qlen++;
182 182
183 pm = nlmsg_data(nlh); 183 pm = nlmsg_data(nlh);
184 memset(pm, 0, sizeof(*pm));
184 185
185 /* Fill in the ulog data */ 186 /* Fill in the ulog data */
186 pm->version = EBT_ULOG_VERSION; 187 pm->version = EBT_ULOG_VERSION;
@@ -193,8 +194,6 @@ static void ebt_ulog_packet(struct net *net, unsigned int hooknr,
193 pm->hook = hooknr; 194 pm->hook = hooknr;
194 if (uloginfo->prefix != NULL) 195 if (uloginfo->prefix != NULL)
195 strcpy(pm->prefix, uloginfo->prefix); 196 strcpy(pm->prefix, uloginfo->prefix);
196 else
197 *(pm->prefix) = '\0';
198 197
199 if (in) { 198 if (in) {
200 strcpy(pm->physindev, in->name); 199 strcpy(pm->physindev, in->name);
@@ -204,16 +203,14 @@ static void ebt_ulog_packet(struct net *net, unsigned int hooknr,
204 strcpy(pm->indev, br_port_get_rcu(in)->br->dev->name); 203 strcpy(pm->indev, br_port_get_rcu(in)->br->dev->name);
205 else 204 else
206 strcpy(pm->indev, in->name); 205 strcpy(pm->indev, in->name);
207 } else 206 }
208 pm->indev[0] = pm->physindev[0] = '\0';
209 207
210 if (out) { 208 if (out) {
211 /* If out exists, then out is a bridge port */ 209 /* If out exists, then out is a bridge port */
212 strcpy(pm->physoutdev, out->name); 210 strcpy(pm->physoutdev, out->name);
213 /* rcu_read_lock()ed by nf_hook_slow */ 211 /* rcu_read_lock()ed by nf_hook_slow */
214 strcpy(pm->outdev, br_port_get_rcu(out)->br->dev->name); 212 strcpy(pm->outdev, br_port_get_rcu(out)->br->dev->name);
215 } else 213 }
216 pm->outdev[0] = pm->physoutdev[0] = '\0';
217 214
218 if (skb_copy_bits(skb, -ETH_HLEN, pm->data, copy_len) < 0) 215 if (skb_copy_bits(skb, -ETH_HLEN, pm->data, copy_len) < 0)
219 BUG(); 216 BUG();
diff --git a/net/compat.c b/net/compat.c
index f0a1ba6c8086..89032580bd1d 100644
--- a/net/compat.c
+++ b/net/compat.c
@@ -71,6 +71,8 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
71 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) || 71 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
72 __get_user(kmsg->msg_flags, &umsg->msg_flags)) 72 __get_user(kmsg->msg_flags, &umsg->msg_flags))
73 return -EFAULT; 73 return -EFAULT;
74 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
75 return -EINVAL;
74 kmsg->msg_name = compat_ptr(tmp1); 76 kmsg->msg_name = compat_ptr(tmp1);
75 kmsg->msg_iov = compat_ptr(tmp2); 77 kmsg->msg_iov = compat_ptr(tmp2);
76 kmsg->msg_control = compat_ptr(tmp3); 78 kmsg->msg_control = compat_ptr(tmp3);
diff --git a/net/core/dev.c b/net/core/dev.c
index 65f829cfd928..3430b1ed12e5 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -1917,7 +1917,8 @@ static struct xps_map *expand_xps_map(struct xps_map *map,
1917 return new_map; 1917 return new_map;
1918} 1918}
1919 1919
1920int netif_set_xps_queue(struct net_device *dev, struct cpumask *mask, u16 index) 1920int netif_set_xps_queue(struct net_device *dev, const struct cpumask *mask,
1921 u16 index)
1921{ 1922{
1922 struct xps_dev_maps *dev_maps, *new_dev_maps = NULL; 1923 struct xps_dev_maps *dev_maps, *new_dev_maps = NULL;
1923 struct xps_map *map, *new_map; 1924 struct xps_map *map, *new_map;
diff --git a/net/core/filter.c b/net/core/filter.c
index 6438f29ff266..01b780856db2 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -644,7 +644,6 @@ void sk_filter_release_rcu(struct rcu_head *rcu)
644 struct sk_filter *fp = container_of(rcu, struct sk_filter, rcu); 644 struct sk_filter *fp = container_of(rcu, struct sk_filter, rcu);
645 645
646 bpf_jit_free(fp); 646 bpf_jit_free(fp);
647 kfree(fp);
648} 647}
649EXPORT_SYMBOL(sk_filter_release_rcu); 648EXPORT_SYMBOL(sk_filter_release_rcu);
650 649
@@ -683,7 +682,7 @@ int sk_unattached_filter_create(struct sk_filter **pfp,
683 if (fprog->filter == NULL) 682 if (fprog->filter == NULL)
684 return -EINVAL; 683 return -EINVAL;
685 684
686 fp = kmalloc(fsize + sizeof(*fp), GFP_KERNEL); 685 fp = kmalloc(sk_filter_size(fprog->len), GFP_KERNEL);
687 if (!fp) 686 if (!fp)
688 return -ENOMEM; 687 return -ENOMEM;
689 memcpy(fp->insns, fprog->filter, fsize); 688 memcpy(fp->insns, fprog->filter, fsize);
@@ -723,6 +722,7 @@ int sk_attach_filter(struct sock_fprog *fprog, struct sock *sk)
723{ 722{
724 struct sk_filter *fp, *old_fp; 723 struct sk_filter *fp, *old_fp;
725 unsigned int fsize = sizeof(struct sock_filter) * fprog->len; 724 unsigned int fsize = sizeof(struct sock_filter) * fprog->len;
725 unsigned int sk_fsize = sk_filter_size(fprog->len);
726 int err; 726 int err;
727 727
728 if (sock_flag(sk, SOCK_FILTER_LOCKED)) 728 if (sock_flag(sk, SOCK_FILTER_LOCKED))
@@ -732,11 +732,11 @@ int sk_attach_filter(struct sock_fprog *fprog, struct sock *sk)
732 if (fprog->filter == NULL) 732 if (fprog->filter == NULL)
733 return -EINVAL; 733 return -EINVAL;
734 734
735 fp = sock_kmalloc(sk, fsize+sizeof(*fp), GFP_KERNEL); 735 fp = sock_kmalloc(sk, sk_fsize, GFP_KERNEL);
736 if (!fp) 736 if (!fp)
737 return -ENOMEM; 737 return -ENOMEM;
738 if (copy_from_user(fp->insns, fprog->filter, fsize)) { 738 if (copy_from_user(fp->insns, fprog->filter, fsize)) {
739 sock_kfree_s(sk, fp, fsize+sizeof(*fp)); 739 sock_kfree_s(sk, fp, sk_fsize);
740 return -EFAULT; 740 return -EFAULT;
741 } 741 }
742 742
diff --git a/net/core/flow_dissector.c b/net/core/flow_dissector.c
index 8d7d0dd72db2..143b6fdb9647 100644
--- a/net/core/flow_dissector.c
+++ b/net/core/flow_dissector.c
@@ -40,7 +40,7 @@ again:
40 struct iphdr _iph; 40 struct iphdr _iph;
41ip: 41ip:
42 iph = skb_header_pointer(skb, nhoff, sizeof(_iph), &_iph); 42 iph = skb_header_pointer(skb, nhoff, sizeof(_iph), &_iph);
43 if (!iph) 43 if (!iph || iph->ihl < 5)
44 return false; 44 return false;
45 45
46 if (ip_is_fragment(iph)) 46 if (ip_is_fragment(iph))
diff --git a/net/core/netpoll.c b/net/core/netpoll.c
index fc75c9e461b8..8f971990677c 100644
--- a/net/core/netpoll.c
+++ b/net/core/netpoll.c
@@ -636,8 +636,9 @@ static void netpoll_neigh_reply(struct sk_buff *skb, struct netpoll_info *npinfo
636 636
637 netpoll_send_skb(np, send_skb); 637 netpoll_send_skb(np, send_skb);
638 638
639 /* If there are several rx_hooks for the same address, 639 /* If there are several rx_skb_hooks for the same
640 we're fine by sending a single reply */ 640 * address we're fine by sending a single reply
641 */
641 break; 642 break;
642 } 643 }
643 spin_unlock_irqrestore(&npinfo->rx_lock, flags); 644 spin_unlock_irqrestore(&npinfo->rx_lock, flags);
@@ -719,8 +720,9 @@ static void netpoll_neigh_reply(struct sk_buff *skb, struct netpoll_info *npinfo
719 720
720 netpoll_send_skb(np, send_skb); 721 netpoll_send_skb(np, send_skb);
721 722
722 /* If there are several rx_hooks for the same address, 723 /* If there are several rx_skb_hooks for the same
723 we're fine by sending a single reply */ 724 * address, we're fine by sending a single reply
725 */
724 break; 726 break;
725 } 727 }
726 spin_unlock_irqrestore(&npinfo->rx_lock, flags); 728 spin_unlock_irqrestore(&npinfo->rx_lock, flags);
@@ -756,11 +758,12 @@ static bool pkt_is_ns(struct sk_buff *skb)
756 758
757int __netpoll_rx(struct sk_buff *skb, struct netpoll_info *npinfo) 759int __netpoll_rx(struct sk_buff *skb, struct netpoll_info *npinfo)
758{ 760{
759 int proto, len, ulen; 761 int proto, len, ulen, data_len;
760 int hits = 0; 762 int hits = 0, offset;
761 const struct iphdr *iph; 763 const struct iphdr *iph;
762 struct udphdr *uh; 764 struct udphdr *uh;
763 struct netpoll *np, *tmp; 765 struct netpoll *np, *tmp;
766 uint16_t source;
764 767
765 if (list_empty(&npinfo->rx_np)) 768 if (list_empty(&npinfo->rx_np))
766 goto out; 769 goto out;
@@ -820,7 +823,10 @@ int __netpoll_rx(struct sk_buff *skb, struct netpoll_info *npinfo)
820 823
821 len -= iph->ihl*4; 824 len -= iph->ihl*4;
822 uh = (struct udphdr *)(((char *)iph) + iph->ihl*4); 825 uh = (struct udphdr *)(((char *)iph) + iph->ihl*4);
826 offset = (unsigned char *)(uh + 1) - skb->data;
823 ulen = ntohs(uh->len); 827 ulen = ntohs(uh->len);
828 data_len = skb->len - offset;
829 source = ntohs(uh->source);
824 830
825 if (ulen != len) 831 if (ulen != len)
826 goto out; 832 goto out;
@@ -834,9 +840,7 @@ int __netpoll_rx(struct sk_buff *skb, struct netpoll_info *npinfo)
834 if (np->local_port && np->local_port != ntohs(uh->dest)) 840 if (np->local_port && np->local_port != ntohs(uh->dest))
835 continue; 841 continue;
836 842
837 np->rx_hook(np, ntohs(uh->source), 843 np->rx_skb_hook(np, source, skb, offset, data_len);
838 (char *)(uh+1),
839 ulen - sizeof(struct udphdr));
840 hits++; 844 hits++;
841 } 845 }
842 } else { 846 } else {
@@ -859,7 +863,10 @@ int __netpoll_rx(struct sk_buff *skb, struct netpoll_info *npinfo)
859 if (!pskb_may_pull(skb, sizeof(struct udphdr))) 863 if (!pskb_may_pull(skb, sizeof(struct udphdr)))
860 goto out; 864 goto out;
861 uh = udp_hdr(skb); 865 uh = udp_hdr(skb);
866 offset = (unsigned char *)(uh + 1) - skb->data;
862 ulen = ntohs(uh->len); 867 ulen = ntohs(uh->len);
868 data_len = skb->len - offset;
869 source = ntohs(uh->source);
863 if (ulen != skb->len) 870 if (ulen != skb->len)
864 goto out; 871 goto out;
865 if (udp6_csum_init(skb, uh, IPPROTO_UDP)) 872 if (udp6_csum_init(skb, uh, IPPROTO_UDP))
@@ -872,9 +879,7 @@ int __netpoll_rx(struct sk_buff *skb, struct netpoll_info *npinfo)
872 if (np->local_port && np->local_port != ntohs(uh->dest)) 879 if (np->local_port && np->local_port != ntohs(uh->dest))
873 continue; 880 continue;
874 881
875 np->rx_hook(np, ntohs(uh->source), 882 np->rx_skb_hook(np, source, skb, offset, data_len);
876 (char *)(uh+1),
877 ulen - sizeof(struct udphdr));
878 hits++; 883 hits++;
879 } 884 }
880#endif 885#endif
@@ -1062,7 +1067,7 @@ int __netpoll_setup(struct netpoll *np, struct net_device *ndev, gfp_t gfp)
1062 1067
1063 npinfo->netpoll = np; 1068 npinfo->netpoll = np;
1064 1069
1065 if (np->rx_hook) { 1070 if (np->rx_skb_hook) {
1066 spin_lock_irqsave(&npinfo->rx_lock, flags); 1071 spin_lock_irqsave(&npinfo->rx_lock, flags);
1067 npinfo->rx_flags |= NETPOLL_RX_ENABLED; 1072 npinfo->rx_flags |= NETPOLL_RX_ENABLED;
1068 list_add_tail(&np->rx, &npinfo->rx_np); 1073 list_add_tail(&np->rx, &npinfo->rx_np);
diff --git a/net/core/secure_seq.c b/net/core/secure_seq.c
index 3f1ec1586ae1..8d9d05edd2eb 100644
--- a/net/core/secure_seq.c
+++ b/net/core/secure_seq.c
@@ -10,6 +10,7 @@
10 10
11#include <net/secure_seq.h> 11#include <net/secure_seq.h>
12 12
13#if IS_ENABLED(CONFIG_IPV6) || IS_ENABLED(CONFIG_INET)
13#define NET_SECRET_SIZE (MD5_MESSAGE_BYTES / 4) 14#define NET_SECRET_SIZE (MD5_MESSAGE_BYTES / 4)
14 15
15static u32 net_secret[NET_SECRET_SIZE] ____cacheline_aligned; 16static u32 net_secret[NET_SECRET_SIZE] ____cacheline_aligned;
@@ -29,6 +30,7 @@ static void net_secret_init(void)
29 cmpxchg(&net_secret[--i], 0, tmp); 30 cmpxchg(&net_secret[--i], 0, tmp);
30 } 31 }
31} 32}
33#endif
32 34
33#ifdef CONFIG_INET 35#ifdef CONFIG_INET
34static u32 seq_scale(u32 seq) 36static u32 seq_scale(u32 seq)
diff --git a/net/core/sock.c b/net/core/sock.c
index 5b6beba494a3..0b39e7ae4383 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -2319,6 +2319,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
2319 sk->sk_ll_usec = sysctl_net_busy_read; 2319 sk->sk_ll_usec = sysctl_net_busy_read;
2320#endif 2320#endif
2321 2321
2322 sk->sk_pacing_rate = ~0U;
2322 /* 2323 /*
2323 * Before updating sk_refcnt, we must commit prior changes to memory 2324 * Before updating sk_refcnt, we must commit prior changes to memory
2324 * (Documentation/RCU/rculist_nulls.txt for details) 2325 * (Documentation/RCU/rculist_nulls.txt for details)
diff --git a/net/ieee802154/6lowpan.c b/net/ieee802154/6lowpan.c
index c85e71e0c7ff..ff41b4d60d30 100644
--- a/net/ieee802154/6lowpan.c
+++ b/net/ieee802154/6lowpan.c
@@ -1372,6 +1372,8 @@ static int lowpan_newlink(struct net *src_net, struct net_device *dev,
1372 real_dev = dev_get_by_index(src_net, nla_get_u32(tb[IFLA_LINK])); 1372 real_dev = dev_get_by_index(src_net, nla_get_u32(tb[IFLA_LINK]));
1373 if (!real_dev) 1373 if (!real_dev)
1374 return -ENODEV; 1374 return -ENODEV;
1375 if (real_dev->type != ARPHRD_IEEE802154)
1376 return -EINVAL;
1375 1377
1376 lowpan_dev_info(dev)->real_dev = real_dev; 1378 lowpan_dev_info(dev)->real_dev = real_dev;
1377 lowpan_dev_info(dev)->fragment_tag = 0; 1379 lowpan_dev_info(dev)->fragment_tag = 0;
@@ -1386,6 +1388,9 @@ static int lowpan_newlink(struct net *src_net, struct net_device *dev,
1386 1388
1387 entry->ldev = dev; 1389 entry->ldev = dev;
1388 1390
1391 /* Set the lowpan harware address to the wpan hardware address. */
1392 memcpy(dev->dev_addr, real_dev->dev_addr, IEEE802154_ADDR_LEN);
1393
1389 mutex_lock(&lowpan_dev_info(dev)->dev_list_mtx); 1394 mutex_lock(&lowpan_dev_info(dev)->dev_list_mtx);
1390 INIT_LIST_HEAD(&entry->list); 1395 INIT_LIST_HEAD(&entry->list);
1391 list_add_tail(&entry->list, &lowpan_devices); 1396 list_add_tail(&entry->list, &lowpan_devices);
diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
index 7bd8983dbfcf..96da9c77deca 100644
--- a/net/ipv4/inet_hashtables.c
+++ b/net/ipv4/inet_hashtables.c
@@ -287,7 +287,7 @@ begintw:
287 if (unlikely(!INET_TW_MATCH(sk, net, acookie, 287 if (unlikely(!INET_TW_MATCH(sk, net, acookie,
288 saddr, daddr, ports, 288 saddr, daddr, ports,
289 dif))) { 289 dif))) {
290 sock_put(sk); 290 inet_twsk_put(inet_twsk(sk));
291 goto begintw; 291 goto begintw;
292 } 292 }
293 goto out; 293 goto out;
diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c
index a04d872c54f9..3982eabf61e1 100644
--- a/net/ipv4/ip_output.c
+++ b/net/ipv4/ip_output.c
@@ -772,15 +772,20 @@ static inline int ip_ufo_append_data(struct sock *sk,
772 /* initialize protocol header pointer */ 772 /* initialize protocol header pointer */
773 skb->transport_header = skb->network_header + fragheaderlen; 773 skb->transport_header = skb->network_header + fragheaderlen;
774 774
775 skb->ip_summed = CHECKSUM_PARTIAL;
776 skb->csum = 0; 775 skb->csum = 0;
777 776
778 /* specify the length of each IP datagram fragment */ 777
779 skb_shinfo(skb)->gso_size = maxfraglen - fragheaderlen;
780 skb_shinfo(skb)->gso_type = SKB_GSO_UDP;
781 __skb_queue_tail(queue, skb); 778 __skb_queue_tail(queue, skb);
779 } else if (skb_is_gso(skb)) {
780 goto append;
782 } 781 }
783 782
783 skb->ip_summed = CHECKSUM_PARTIAL;
784 /* specify the length of each IP datagram fragment */
785 skb_shinfo(skb)->gso_size = maxfraglen - fragheaderlen;
786 skb_shinfo(skb)->gso_type = SKB_GSO_UDP;
787
788append:
784 return skb_append_datato_frags(sk, skb, getfrag, from, 789 return skb_append_datato_frags(sk, skb, getfrag, from,
785 (length - transhdrlen)); 790 (length - transhdrlen));
786} 791}
diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
index e805e7b3030e..6e87f853d033 100644
--- a/net/ipv4/ip_vti.c
+++ b/net/ipv4/ip_vti.c
@@ -125,8 +125,17 @@ static int vti_rcv(struct sk_buff *skb)
125 iph->saddr, iph->daddr, 0); 125 iph->saddr, iph->daddr, 0);
126 if (tunnel != NULL) { 126 if (tunnel != NULL) {
127 struct pcpu_tstats *tstats; 127 struct pcpu_tstats *tstats;
128 u32 oldmark = skb->mark;
129 int ret;
128 130
129 if (!xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb)) 131
132 /* temporarily mark the skb with the tunnel o_key, to
133 * only match policies with this mark.
134 */
135 skb->mark = be32_to_cpu(tunnel->parms.o_key);
136 ret = xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb);
137 skb->mark = oldmark;
138 if (!ret)
130 return -1; 139 return -1;
131 140
132 tstats = this_cpu_ptr(tunnel->dev->tstats); 141 tstats = this_cpu_ptr(tunnel->dev->tstats);
@@ -135,7 +144,6 @@ static int vti_rcv(struct sk_buff *skb)
135 tstats->rx_bytes += skb->len; 144 tstats->rx_bytes += skb->len;
136 u64_stats_update_end(&tstats->syncp); 145 u64_stats_update_end(&tstats->syncp);
137 146
138 skb->mark = 0;
139 secpath_reset(skb); 147 secpath_reset(skb);
140 skb->dev = tunnel->dev; 148 skb->dev = tunnel->dev;
141 return 1; 149 return 1;
@@ -167,7 +175,7 @@ static netdev_tx_t vti_tunnel_xmit(struct sk_buff *skb, struct net_device *dev)
167 175
168 memset(&fl4, 0, sizeof(fl4)); 176 memset(&fl4, 0, sizeof(fl4));
169 flowi4_init_output(&fl4, tunnel->parms.link, 177 flowi4_init_output(&fl4, tunnel->parms.link,
170 be32_to_cpu(tunnel->parms.i_key), RT_TOS(tos), 178 be32_to_cpu(tunnel->parms.o_key), RT_TOS(tos),
171 RT_SCOPE_UNIVERSE, 179 RT_SCOPE_UNIVERSE,
172 IPPROTO_IPIP, 0, 180 IPPROTO_IPIP, 0,
173 dst, tiph->saddr, 0, 0); 181 dst, tiph->saddr, 0, 0);
diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
index 85a4f21aac1a..59da7cde0724 100644
--- a/net/ipv4/netfilter/arp_tables.c
+++ b/net/ipv4/netfilter/arp_tables.c
@@ -271,6 +271,11 @@ unsigned int arpt_do_table(struct sk_buff *skb,
271 local_bh_disable(); 271 local_bh_disable();
272 addend = xt_write_recseq_begin(); 272 addend = xt_write_recseq_begin();
273 private = table->private; 273 private = table->private;
274 /*
275 * Ensure we load private-> members after we've fetched the base
276 * pointer.
277 */
278 smp_read_barrier_depends();
274 table_base = private->entries[smp_processor_id()]; 279 table_base = private->entries[smp_processor_id()];
275 280
276 e = get_entry(table_base, private->hook_entry[hook]); 281 e = get_entry(table_base, private->hook_entry[hook]);
diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
index d23118d95ff9..718dfbd30cbe 100644
--- a/net/ipv4/netfilter/ip_tables.c
+++ b/net/ipv4/netfilter/ip_tables.c
@@ -327,6 +327,11 @@ ipt_do_table(struct sk_buff *skb,
327 addend = xt_write_recseq_begin(); 327 addend = xt_write_recseq_begin();
328 private = table->private; 328 private = table->private;
329 cpu = smp_processor_id(); 329 cpu = smp_processor_id();
330 /*
331 * Ensure we load private-> members after we've fetched the base
332 * pointer.
333 */
334 smp_read_barrier_depends();
330 table_base = private->entries[cpu]; 335 table_base = private->entries[cpu];
331 jumpstack = (struct ipt_entry **)private->jumpstack[cpu]; 336 jumpstack = (struct ipt_entry **)private->jumpstack[cpu];
332 stackptr = per_cpu_ptr(private->stackptr, cpu); 337 stackptr = per_cpu_ptr(private->stackptr, cpu);
diff --git a/net/ipv4/netfilter/ipt_ULOG.c b/net/ipv4/netfilter/ipt_ULOG.c
index cbc22158af49..9cb993cd224b 100644
--- a/net/ipv4/netfilter/ipt_ULOG.c
+++ b/net/ipv4/netfilter/ipt_ULOG.c
@@ -220,6 +220,7 @@ static void ipt_ulog_packet(struct net *net,
220 ub->qlen++; 220 ub->qlen++;
221 221
222 pm = nlmsg_data(nlh); 222 pm = nlmsg_data(nlh);
223 memset(pm, 0, sizeof(*pm));
223 224
224 /* We might not have a timestamp, get one */ 225 /* We might not have a timestamp, get one */
225 if (skb->tstamp.tv64 == 0) 226 if (skb->tstamp.tv64 == 0)
@@ -238,8 +239,6 @@ static void ipt_ulog_packet(struct net *net,
238 } 239 }
239 else if (loginfo->prefix[0] != '\0') 240 else if (loginfo->prefix[0] != '\0')
240 strncpy(pm->prefix, loginfo->prefix, sizeof(pm->prefix)); 241 strncpy(pm->prefix, loginfo->prefix, sizeof(pm->prefix));
241 else
242 *(pm->prefix) = '\0';
243 242
244 if (in && in->hard_header_len > 0 && 243 if (in && in->hard_header_len > 0 &&
245 skb->mac_header != skb->network_header && 244 skb->mac_header != skb->network_header &&
@@ -251,13 +250,9 @@ static void ipt_ulog_packet(struct net *net,
251 250
252 if (in) 251 if (in)
253 strncpy(pm->indev_name, in->name, sizeof(pm->indev_name)); 252 strncpy(pm->indev_name, in->name, sizeof(pm->indev_name));
254 else
255 pm->indev_name[0] = '\0';
256 253
257 if (out) 254 if (out)
258 strncpy(pm->outdev_name, out->name, sizeof(pm->outdev_name)); 255 strncpy(pm->outdev_name, out->name, sizeof(pm->outdev_name));
259 else
260 pm->outdev_name[0] = '\0';
261 256
262 /* copy_len <= skb->len, so can't fail. */ 257 /* copy_len <= skb->len, so can't fail. */
263 if (skb_copy_bits(skb, 0, pm->payload, copy_len) < 0) 258 if (skb_copy_bits(skb, 0, pm->payload, copy_len) < 0)
diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index 727f4365bcdf..6011615e810d 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -2072,7 +2072,7 @@ struct rtable *__ip_route_output_key(struct net *net, struct flowi4 *fl4)
2072 RT_SCOPE_LINK); 2072 RT_SCOPE_LINK);
2073 goto make_route; 2073 goto make_route;
2074 } 2074 }
2075 if (fl4->saddr) { 2075 if (!fl4->saddr) {
2076 if (ipv4_is_multicast(fl4->daddr)) 2076 if (ipv4_is_multicast(fl4->daddr))
2077 fl4->saddr = inet_select_addr(dev_out, 0, 2077 fl4->saddr = inet_select_addr(dev_out, 0,
2078 fl4->flowi4_scope); 2078 fl4->flowi4_scope);
diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index 25a89eaa669d..068c8fb0d158 100644
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -1284,7 +1284,10 @@ static bool tcp_shifted_skb(struct sock *sk, struct sk_buff *skb,
1284 tp->lost_cnt_hint -= tcp_skb_pcount(prev); 1284 tp->lost_cnt_hint -= tcp_skb_pcount(prev);
1285 } 1285 }
1286 1286
1287 TCP_SKB_CB(skb)->tcp_flags |= TCP_SKB_CB(prev)->tcp_flags; 1287 TCP_SKB_CB(prev)->tcp_flags |= TCP_SKB_CB(skb)->tcp_flags;
1288 if (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_FIN)
1289 TCP_SKB_CB(prev)->end_seq++;
1290
1288 if (skb == tcp_highest_sack(sk)) 1291 if (skb == tcp_highest_sack(sk))
1289 tcp_advance_highest_sack(sk, skb); 1292 tcp_advance_highest_sack(sk, skb);
1290 1293
@@ -2853,7 +2856,8 @@ static inline bool tcp_ack_update_rtt(struct sock *sk, const int flag,
2853 * left edge of the send window. 2856 * left edge of the send window.
2854 * See draft-ietf-tcplw-high-performance-00, section 3.3. 2857 * See draft-ietf-tcplw-high-performance-00, section 3.3.
2855 */ 2858 */
2856 if (seq_rtt < 0 && tp->rx_opt.saw_tstamp && tp->rx_opt.rcv_tsecr) 2859 if (seq_rtt < 0 && tp->rx_opt.saw_tstamp && tp->rx_opt.rcv_tsecr &&
2860 flag & FLAG_ACKED)
2857 seq_rtt = tcp_time_stamp - tp->rx_opt.rcv_tsecr; 2861 seq_rtt = tcp_time_stamp - tp->rx_opt.rcv_tsecr;
2858 2862
2859 if (seq_rtt < 0) 2863 if (seq_rtt < 0)
@@ -2868,14 +2872,19 @@ static inline bool tcp_ack_update_rtt(struct sock *sk, const int flag,
2868} 2872}
2869 2873
2870/* Compute time elapsed between (last) SYNACK and the ACK completing 3WHS. */ 2874/* Compute time elapsed between (last) SYNACK and the ACK completing 3WHS. */
2871static void tcp_synack_rtt_meas(struct sock *sk, struct request_sock *req) 2875static void tcp_synack_rtt_meas(struct sock *sk, const u32 synack_stamp)
2872{ 2876{
2873 struct tcp_sock *tp = tcp_sk(sk); 2877 struct tcp_sock *tp = tcp_sk(sk);
2874 s32 seq_rtt = -1; 2878 s32 seq_rtt = -1;
2875 2879
2876 if (tp->lsndtime && !tp->total_retrans) 2880 if (synack_stamp && !tp->total_retrans)
2877 seq_rtt = tcp_time_stamp - tp->lsndtime; 2881 seq_rtt = tcp_time_stamp - synack_stamp;
2878 tcp_ack_update_rtt(sk, FLAG_SYN_ACKED, seq_rtt, -1); 2882
2883 /* If the ACK acks both the SYNACK and the (Fast Open'd) data packets
2884 * sent in SYN_RECV, SYNACK RTT is the smooth RTT computed in tcp_ack()
2885 */
2886 if (!tp->srtt)
2887 tcp_ack_update_rtt(sk, FLAG_SYN_ACKED, seq_rtt, -1);
2879} 2888}
2880 2889
2881static void tcp_cong_avoid(struct sock *sk, u32 ack, u32 in_flight) 2890static void tcp_cong_avoid(struct sock *sk, u32 ack, u32 in_flight)
@@ -2978,6 +2987,7 @@ static int tcp_clean_rtx_queue(struct sock *sk, int prior_fackets,
2978 s32 seq_rtt = -1; 2987 s32 seq_rtt = -1;
2979 s32 ca_seq_rtt = -1; 2988 s32 ca_seq_rtt = -1;
2980 ktime_t last_ackt = net_invalid_timestamp(); 2989 ktime_t last_ackt = net_invalid_timestamp();
2990 bool rtt_update;
2981 2991
2982 while ((skb = tcp_write_queue_head(sk)) && skb != tcp_send_head(sk)) { 2992 while ((skb = tcp_write_queue_head(sk)) && skb != tcp_send_head(sk)) {
2983 struct tcp_skb_cb *scb = TCP_SKB_CB(skb); 2993 struct tcp_skb_cb *scb = TCP_SKB_CB(skb);
@@ -3054,14 +3064,13 @@ static int tcp_clean_rtx_queue(struct sock *sk, int prior_fackets,
3054 if (skb && (TCP_SKB_CB(skb)->sacked & TCPCB_SACKED_ACKED)) 3064 if (skb && (TCP_SKB_CB(skb)->sacked & TCPCB_SACKED_ACKED))
3055 flag |= FLAG_SACK_RENEGING; 3065 flag |= FLAG_SACK_RENEGING;
3056 3066
3057 if (tcp_ack_update_rtt(sk, flag, seq_rtt, sack_rtt) || 3067 rtt_update = tcp_ack_update_rtt(sk, flag, seq_rtt, sack_rtt);
3058 (flag & FLAG_ACKED))
3059 tcp_rearm_rto(sk);
3060 3068
3061 if (flag & FLAG_ACKED) { 3069 if (flag & FLAG_ACKED) {
3062 const struct tcp_congestion_ops *ca_ops 3070 const struct tcp_congestion_ops *ca_ops
3063 = inet_csk(sk)->icsk_ca_ops; 3071 = inet_csk(sk)->icsk_ca_ops;
3064 3072
3073 tcp_rearm_rto(sk);
3065 if (unlikely(icsk->icsk_mtup.probe_size && 3074 if (unlikely(icsk->icsk_mtup.probe_size &&
3066 !after(tp->mtu_probe.probe_seq_end, tp->snd_una))) { 3075 !after(tp->mtu_probe.probe_seq_end, tp->snd_una))) {
3067 tcp_mtup_probe_success(sk); 3076 tcp_mtup_probe_success(sk);
@@ -3100,6 +3109,13 @@ static int tcp_clean_rtx_queue(struct sock *sk, int prior_fackets,
3100 3109
3101 ca_ops->pkts_acked(sk, pkts_acked, rtt_us); 3110 ca_ops->pkts_acked(sk, pkts_acked, rtt_us);
3102 } 3111 }
3112 } else if (skb && rtt_update && sack_rtt >= 0 &&
3113 sack_rtt > (s32)(now - TCP_SKB_CB(skb)->when)) {
3114 /* Do not re-arm RTO if the sack RTT is measured from data sent
3115 * after when the head was last (re)transmitted. Otherwise the
3116 * timeout may continue to extend in loss recovery.
3117 */
3118 tcp_rearm_rto(sk);
3103 } 3119 }
3104 3120
3105#if FASTRETRANS_DEBUG > 0 3121#if FASTRETRANS_DEBUG > 0
@@ -3288,7 +3304,7 @@ static void tcp_process_tlp_ack(struct sock *sk, u32 ack, int flag)
3288 tcp_init_cwnd_reduction(sk, true); 3304 tcp_init_cwnd_reduction(sk, true);
3289 tcp_set_ca_state(sk, TCP_CA_CWR); 3305 tcp_set_ca_state(sk, TCP_CA_CWR);
3290 tcp_end_cwnd_reduction(sk); 3306 tcp_end_cwnd_reduction(sk);
3291 tcp_set_ca_state(sk, TCP_CA_Open); 3307 tcp_try_keep_open(sk);
3292 NET_INC_STATS_BH(sock_net(sk), 3308 NET_INC_STATS_BH(sock_net(sk),
3293 LINUX_MIB_TCPLOSSPROBERECOVERY); 3309 LINUX_MIB_TCPLOSSPROBERECOVERY);
3294 } 3310 }
@@ -5584,6 +5600,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
5584 struct request_sock *req; 5600 struct request_sock *req;
5585 int queued = 0; 5601 int queued = 0;
5586 bool acceptable; 5602 bool acceptable;
5603 u32 synack_stamp;
5587 5604
5588 tp->rx_opt.saw_tstamp = 0; 5605 tp->rx_opt.saw_tstamp = 0;
5589 5606
@@ -5666,9 +5683,11 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
5666 * so release it. 5683 * so release it.
5667 */ 5684 */
5668 if (req) { 5685 if (req) {
5686 synack_stamp = tcp_rsk(req)->snt_synack;
5669 tp->total_retrans = req->num_retrans; 5687 tp->total_retrans = req->num_retrans;
5670 reqsk_fastopen_remove(sk, req, false); 5688 reqsk_fastopen_remove(sk, req, false);
5671 } else { 5689 } else {
5690 synack_stamp = tp->lsndtime;
5672 /* Make sure socket is routed, for correct metrics. */ 5691 /* Make sure socket is routed, for correct metrics. */
5673 icsk->icsk_af_ops->rebuild_header(sk); 5692 icsk->icsk_af_ops->rebuild_header(sk);
5674 tcp_init_congestion_control(sk); 5693 tcp_init_congestion_control(sk);
@@ -5691,7 +5710,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
5691 tp->snd_una = TCP_SKB_CB(skb)->ack_seq; 5710 tp->snd_una = TCP_SKB_CB(skb)->ack_seq;
5692 tp->snd_wnd = ntohs(th->window) << tp->rx_opt.snd_wscale; 5711 tp->snd_wnd = ntohs(th->window) << tp->rx_opt.snd_wscale;
5693 tcp_init_wl(tp, TCP_SKB_CB(skb)->seq); 5712 tcp_init_wl(tp, TCP_SKB_CB(skb)->seq);
5694 tcp_synack_rtt_meas(sk, req); 5713 tcp_synack_rtt_meas(sk, synack_stamp);
5695 5714
5696 if (tp->rx_opt.tstamp_ok) 5715 if (tp->rx_opt.tstamp_ok)
5697 tp->advmss -= TCPOLEN_TSTAMP_ALIGNED; 5716 tp->advmss -= TCPOLEN_TSTAMP_ALIGNED;
@@ -5709,6 +5728,8 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
5709 } else 5728 } else
5710 tcp_init_metrics(sk); 5729 tcp_init_metrics(sk);
5711 5730
5731 tcp_update_pacing_rate(sk);
5732
5712 /* Prevent spurious tcp_cwnd_restart() on first data packet */ 5733 /* Prevent spurious tcp_cwnd_restart() on first data packet */
5713 tp->lsndtime = tcp_time_stamp; 5734 tp->lsndtime = tcp_time_stamp;
5714 5735
diff --git a/net/ipv4/tcp_offload.c b/net/ipv4/tcp_offload.c
index 3a7525e6c086..533c58a5cfb7 100644
--- a/net/ipv4/tcp_offload.c
+++ b/net/ipv4/tcp_offload.c
@@ -18,6 +18,7 @@ struct sk_buff *tcp_tso_segment(struct sk_buff *skb,
18 netdev_features_t features) 18 netdev_features_t features)
19{ 19{
20 struct sk_buff *segs = ERR_PTR(-EINVAL); 20 struct sk_buff *segs = ERR_PTR(-EINVAL);
21 unsigned int sum_truesize = 0;
21 struct tcphdr *th; 22 struct tcphdr *th;
22 unsigned int thlen; 23 unsigned int thlen;
23 unsigned int seq; 24 unsigned int seq;
@@ -102,13 +103,7 @@ struct sk_buff *tcp_tso_segment(struct sk_buff *skb,
102 if (copy_destructor) { 103 if (copy_destructor) {
103 skb->destructor = gso_skb->destructor; 104 skb->destructor = gso_skb->destructor;
104 skb->sk = gso_skb->sk; 105 skb->sk = gso_skb->sk;
105 /* {tcp|sock}_wfree() use exact truesize accounting : 106 sum_truesize += skb->truesize;
106 * sum(skb->truesize) MUST be exactly be gso_skb->truesize
107 * So we account mss bytes of 'true size' for each segment.
108 * The last segment will contain the remaining.
109 */
110 skb->truesize = mss;
111 gso_skb->truesize -= mss;
112 } 107 }
113 skb = skb->next; 108 skb = skb->next;
114 th = tcp_hdr(skb); 109 th = tcp_hdr(skb);
@@ -125,7 +120,9 @@ struct sk_buff *tcp_tso_segment(struct sk_buff *skb,
125 if (copy_destructor) { 120 if (copy_destructor) {
126 swap(gso_skb->sk, skb->sk); 121 swap(gso_skb->sk, skb->sk);
127 swap(gso_skb->destructor, skb->destructor); 122 swap(gso_skb->destructor, skb->destructor);
128 swap(gso_skb->truesize, skb->truesize); 123 sum_truesize += skb->truesize;
124 atomic_add(sum_truesize - gso_skb->truesize,
125 &skb->sk->sk_wmem_alloc);
129 } 126 }
130 127
131 delta = htonl(oldlen + (skb_tail_pointer(skb) - 128 delta = htonl(oldlen + (skb_tail_pointer(skb) -
diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
index e6bb8256e59f..d46f2143305c 100644
--- a/net/ipv4/tcp_output.c
+++ b/net/ipv4/tcp_output.c
@@ -637,6 +637,8 @@ static unsigned int tcp_established_options(struct sock *sk, struct sk_buff *skb
637 unsigned int size = 0; 637 unsigned int size = 0;
638 unsigned int eff_sacks; 638 unsigned int eff_sacks;
639 639
640 opts->options = 0;
641
640#ifdef CONFIG_TCP_MD5SIG 642#ifdef CONFIG_TCP_MD5SIG
641 *md5 = tp->af_specific->md5_lookup(sk, sk); 643 *md5 = tp->af_specific->md5_lookup(sk, sk);
642 if (unlikely(*md5)) { 644 if (unlikely(*md5)) {
@@ -984,8 +986,10 @@ static void tcp_queue_skb(struct sock *sk, struct sk_buff *skb)
984static void tcp_set_skb_tso_segs(const struct sock *sk, struct sk_buff *skb, 986static void tcp_set_skb_tso_segs(const struct sock *sk, struct sk_buff *skb,
985 unsigned int mss_now) 987 unsigned int mss_now)
986{ 988{
987 if (skb->len <= mss_now || !sk_can_gso(sk) || 989 /* Make sure we own this skb before messing gso_size/gso_segs */
988 skb->ip_summed == CHECKSUM_NONE) { 990 WARN_ON_ONCE(skb_cloned(skb));
991
992 if (skb->len <= mss_now || skb->ip_summed == CHECKSUM_NONE) {
989 /* Avoid the costly divide in the normal 993 /* Avoid the costly divide in the normal
990 * non-TSO case. 994 * non-TSO case.
991 */ 995 */
@@ -1065,9 +1069,7 @@ int tcp_fragment(struct sock *sk, struct sk_buff *skb, u32 len,
1065 if (nsize < 0) 1069 if (nsize < 0)
1066 nsize = 0; 1070 nsize = 0;
1067 1071
1068 if (skb_cloned(skb) && 1072 if (skb_unclone(skb, GFP_ATOMIC))
1069 skb_is_nonlinear(skb) &&
1070 pskb_expand_head(skb, 0, 0, GFP_ATOMIC))
1071 return -ENOMEM; 1073 return -ENOMEM;
1072 1074
1073 /* Get a new skb... force flag on. */ 1075 /* Get a new skb... force flag on. */
@@ -2342,6 +2344,8 @@ int __tcp_retransmit_skb(struct sock *sk, struct sk_buff *skb)
2342 int oldpcount = tcp_skb_pcount(skb); 2344 int oldpcount = tcp_skb_pcount(skb);
2343 2345
2344 if (unlikely(oldpcount > 1)) { 2346 if (unlikely(oldpcount > 1)) {
2347 if (skb_unclone(skb, GFP_ATOMIC))
2348 return -ENOMEM;
2345 tcp_init_tso_segs(sk, skb, cur_mss); 2349 tcp_init_tso_segs(sk, skb, cur_mss);
2346 tcp_adjust_pcount(sk, skb, oldpcount - tcp_skb_pcount(skb)); 2350 tcp_adjust_pcount(sk, skb, oldpcount - tcp_skb_pcount(skb));
2347 } 2351 }
diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
index 9a459be24af7..e1a63930a967 100644
--- a/net/ipv4/xfrm4_policy.c
+++ b/net/ipv4/xfrm4_policy.c
@@ -104,9 +104,14 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
104 const struct iphdr *iph = ip_hdr(skb); 104 const struct iphdr *iph = ip_hdr(skb);
105 u8 *xprth = skb_network_header(skb) + iph->ihl * 4; 105 u8 *xprth = skb_network_header(skb) + iph->ihl * 4;
106 struct flowi4 *fl4 = &fl->u.ip4; 106 struct flowi4 *fl4 = &fl->u.ip4;
107 int oif = 0;
108
109 if (skb_dst(skb))
110 oif = skb_dst(skb)->dev->ifindex;
107 111
108 memset(fl4, 0, sizeof(struct flowi4)); 112 memset(fl4, 0, sizeof(struct flowi4));
109 fl4->flowi4_mark = skb->mark; 113 fl4->flowi4_mark = skb->mark;
114 fl4->flowi4_oif = reverse ? skb->skb_iif : oif;
110 115
111 if (!ip_is_fragment(iph)) { 116 if (!ip_is_fragment(iph)) {
112 switch (iph->protocol) { 117 switch (iph->protocol) {
@@ -235,7 +240,7 @@ static struct dst_ops xfrm4_dst_ops = {
235 .destroy = xfrm4_dst_destroy, 240 .destroy = xfrm4_dst_destroy,
236 .ifdown = xfrm4_dst_ifdown, 241 .ifdown = xfrm4_dst_ifdown,
237 .local_out = __ip_local_out, 242 .local_out = __ip_local_out,
238 .gc_thresh = 1024, 243 .gc_thresh = 32768,
239}; 244};
240 245
241static struct xfrm_policy_afinfo xfrm4_policy_afinfo = { 246static struct xfrm_policy_afinfo xfrm4_policy_afinfo = {
diff --git a/net/ipv6/ah6.c b/net/ipv6/ah6.c
index 73784c3d4642..82e1da3a40b9 100644
--- a/net/ipv6/ah6.c
+++ b/net/ipv6/ah6.c
@@ -618,8 +618,7 @@ static void ah6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
618 struct ip_auth_hdr *ah = (struct ip_auth_hdr*)(skb->data+offset); 618 struct ip_auth_hdr *ah = (struct ip_auth_hdr*)(skb->data+offset);
619 struct xfrm_state *x; 619 struct xfrm_state *x;
620 620
621 if (type != ICMPV6_DEST_UNREACH && 621 if (type != ICMPV6_PKT_TOOBIG &&
622 type != ICMPV6_PKT_TOOBIG &&
623 type != NDISC_REDIRECT) 622 type != NDISC_REDIRECT)
624 return; 623 return;
625 624
diff --git a/net/ipv6/esp6.c b/net/ipv6/esp6.c
index d3618a78fcac..e67e63f9858d 100644
--- a/net/ipv6/esp6.c
+++ b/net/ipv6/esp6.c
@@ -436,8 +436,7 @@ static void esp6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
436 struct ip_esp_hdr *esph = (struct ip_esp_hdr *)(skb->data + offset); 436 struct ip_esp_hdr *esph = (struct ip_esp_hdr *)(skb->data + offset);
437 struct xfrm_state *x; 437 struct xfrm_state *x;
438 438
439 if (type != ICMPV6_DEST_UNREACH && 439 if (type != ICMPV6_PKT_TOOBIG &&
440 type != ICMPV6_PKT_TOOBIG &&
441 type != NDISC_REDIRECT) 440 type != NDISC_REDIRECT)
442 return; 441 return;
443 442
diff --git a/net/ipv6/inet6_hashtables.c b/net/ipv6/inet6_hashtables.c
index 32b4a1675d82..066640e0ba8e 100644
--- a/net/ipv6/inet6_hashtables.c
+++ b/net/ipv6/inet6_hashtables.c
@@ -116,7 +116,7 @@ begintw:
116 } 116 }
117 if (unlikely(!INET6_TW_MATCH(sk, net, saddr, daddr, 117 if (unlikely(!INET6_TW_MATCH(sk, net, saddr, daddr,
118 ports, dif))) { 118 ports, dif))) {
119 sock_put(sk); 119 inet_twsk_put(inet_twsk(sk));
120 goto begintw; 120 goto begintw;
121 } 121 }
122 goto out; 122 goto out;
diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
index 7bb5446b9d73..bf4a9a084de5 100644
--- a/net/ipv6/ip6_gre.c
+++ b/net/ipv6/ip6_gre.c
@@ -976,6 +976,7 @@ static void ip6gre_tnl_link_config(struct ip6_tnl *t, int set_mtu)
976 if (t->parms.o_flags&GRE_SEQ) 976 if (t->parms.o_flags&GRE_SEQ)
977 addend += 4; 977 addend += 4;
978 } 978 }
979 t->hlen = addend;
979 980
980 if (p->flags & IP6_TNL_F_CAP_XMIT) { 981 if (p->flags & IP6_TNL_F_CAP_XMIT) {
981 int strict = (ipv6_addr_type(&p->raddr) & 982 int strict = (ipv6_addr_type(&p->raddr) &
@@ -1002,8 +1003,6 @@ static void ip6gre_tnl_link_config(struct ip6_tnl *t, int set_mtu)
1002 } 1003 }
1003 ip6_rt_put(rt); 1004 ip6_rt_put(rt);
1004 } 1005 }
1005
1006 t->hlen = addend;
1007} 1006}
1008 1007
1009static int ip6gre_tnl_change(struct ip6_tnl *t, 1008static int ip6gre_tnl_change(struct ip6_tnl *t,
@@ -1173,9 +1172,8 @@ done:
1173 1172
1174static int ip6gre_tunnel_change_mtu(struct net_device *dev, int new_mtu) 1173static int ip6gre_tunnel_change_mtu(struct net_device *dev, int new_mtu)
1175{ 1174{
1176 struct ip6_tnl *tunnel = netdev_priv(dev);
1177 if (new_mtu < 68 || 1175 if (new_mtu < 68 ||
1178 new_mtu > 0xFFF8 - dev->hard_header_len - tunnel->hlen) 1176 new_mtu > 0xFFF8 - dev->hard_header_len)
1179 return -EINVAL; 1177 return -EINVAL;
1180 dev->mtu = new_mtu; 1178 dev->mtu = new_mtu;
1181 return 0; 1179 return 0;
diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c
index a54c45ce4a48..91fb4e8212f5 100644
--- a/net/ipv6/ip6_output.c
+++ b/net/ipv6/ip6_output.c
@@ -105,7 +105,7 @@ static int ip6_finish_output2(struct sk_buff *skb)
105 } 105 }
106 106
107 rcu_read_lock_bh(); 107 rcu_read_lock_bh();
108 nexthop = rt6_nexthop((struct rt6_info *)dst, &ipv6_hdr(skb)->daddr); 108 nexthop = rt6_nexthop((struct rt6_info *)dst);
109 neigh = __ipv6_neigh_lookup_noref(dst->dev, nexthop); 109 neigh = __ipv6_neigh_lookup_noref(dst->dev, nexthop);
110 if (unlikely(!neigh)) 110 if (unlikely(!neigh))
111 neigh = __neigh_create(&nd_tbl, nexthop, dst->dev, false); 111 neigh = __neigh_create(&nd_tbl, nexthop, dst->dev, false);
@@ -874,7 +874,7 @@ static int ip6_dst_lookup_tail(struct sock *sk,
874 */ 874 */
875 rt = (struct rt6_info *) *dst; 875 rt = (struct rt6_info *) *dst;
876 rcu_read_lock_bh(); 876 rcu_read_lock_bh();
877 n = __ipv6_neigh_lookup_noref(rt->dst.dev, rt6_nexthop(rt, &fl6->daddr)); 877 n = __ipv6_neigh_lookup_noref(rt->dst.dev, rt6_nexthop(rt));
878 err = n && !(n->nud_state & NUD_VALID) ? -EINVAL : 0; 878 err = n && !(n->nud_state & NUD_VALID) ? -EINVAL : 0;
879 rcu_read_unlock_bh(); 879 rcu_read_unlock_bh();
880 880
@@ -1008,6 +1008,7 @@ static inline int ip6_ufo_append_data(struct sock *sk,
1008 1008
1009{ 1009{
1010 struct sk_buff *skb; 1010 struct sk_buff *skb;
1011 struct frag_hdr fhdr;
1011 int err; 1012 int err;
1012 1013
1013 /* There is support for UDP large send offload by network 1014 /* There is support for UDP large send offload by network
@@ -1015,8 +1016,6 @@ static inline int ip6_ufo_append_data(struct sock *sk,
1015 * udp datagram 1016 * udp datagram
1016 */ 1017 */
1017 if ((skb = skb_peek_tail(&sk->sk_write_queue)) == NULL) { 1018 if ((skb = skb_peek_tail(&sk->sk_write_queue)) == NULL) {
1018 struct frag_hdr fhdr;
1019
1020 skb = sock_alloc_send_skb(sk, 1019 skb = sock_alloc_send_skb(sk,
1021 hh_len + fragheaderlen + transhdrlen + 20, 1020 hh_len + fragheaderlen + transhdrlen + 20,
1022 (flags & MSG_DONTWAIT), &err); 1021 (flags & MSG_DONTWAIT), &err);
@@ -1036,20 +1035,24 @@ static inline int ip6_ufo_append_data(struct sock *sk,
1036 skb->transport_header = skb->network_header + fragheaderlen; 1035 skb->transport_header = skb->network_header + fragheaderlen;
1037 1036
1038 skb->protocol = htons(ETH_P_IPV6); 1037 skb->protocol = htons(ETH_P_IPV6);
1039 skb->ip_summed = CHECKSUM_PARTIAL;
1040 skb->csum = 0; 1038 skb->csum = 0;
1041 1039
1042 /* Specify the length of each IPv6 datagram fragment.
1043 * It has to be a multiple of 8.
1044 */
1045 skb_shinfo(skb)->gso_size = (mtu - fragheaderlen -
1046 sizeof(struct frag_hdr)) & ~7;
1047 skb_shinfo(skb)->gso_type = SKB_GSO_UDP;
1048 ipv6_select_ident(&fhdr, rt);
1049 skb_shinfo(skb)->ip6_frag_id = fhdr.identification;
1050 __skb_queue_tail(&sk->sk_write_queue, skb); 1040 __skb_queue_tail(&sk->sk_write_queue, skb);
1041 } else if (skb_is_gso(skb)) {
1042 goto append;
1051 } 1043 }
1052 1044
1045 skb->ip_summed = CHECKSUM_PARTIAL;
1046 /* Specify the length of each IPv6 datagram fragment.
1047 * It has to be a multiple of 8.
1048 */
1049 skb_shinfo(skb)->gso_size = (mtu - fragheaderlen -
1050 sizeof(struct frag_hdr)) & ~7;
1051 skb_shinfo(skb)->gso_type = SKB_GSO_UDP;
1052 ipv6_select_ident(&fhdr, rt);
1053 skb_shinfo(skb)->ip6_frag_id = fhdr.identification;
1054
1055append:
1053 return skb_append_datato_frags(sk, skb, getfrag, from, 1056 return skb_append_datato_frags(sk, skb, getfrag, from,
1054 (length - transhdrlen)); 1057 (length - transhdrlen));
1055} 1058}
diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
index a791552e0422..583b77e2f69b 100644
--- a/net/ipv6/ip6_tunnel.c
+++ b/net/ipv6/ip6_tunnel.c
@@ -1430,9 +1430,17 @@ ip6_tnl_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
1430static int 1430static int
1431ip6_tnl_change_mtu(struct net_device *dev, int new_mtu) 1431ip6_tnl_change_mtu(struct net_device *dev, int new_mtu)
1432{ 1432{
1433 if (new_mtu < IPV6_MIN_MTU) { 1433 struct ip6_tnl *tnl = netdev_priv(dev);
1434 return -EINVAL; 1434
1435 if (tnl->parms.proto == IPPROTO_IPIP) {
1436 if (new_mtu < 68)
1437 return -EINVAL;
1438 } else {
1439 if (new_mtu < IPV6_MIN_MTU)
1440 return -EINVAL;
1435 } 1441 }
1442 if (new_mtu > 0xFFF8 - dev->hard_header_len)
1443 return -EINVAL;
1436 dev->mtu = new_mtu; 1444 dev->mtu = new_mtu;
1437 return 0; 1445 return 0;
1438} 1446}
diff --git a/net/ipv6/ipcomp6.c b/net/ipv6/ipcomp6.c
index 5636a912074a..ce507d9e1c90 100644
--- a/net/ipv6/ipcomp6.c
+++ b/net/ipv6/ipcomp6.c
@@ -64,8 +64,7 @@ static void ipcomp6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
64 (struct ip_comp_hdr *)(skb->data + offset); 64 (struct ip_comp_hdr *)(skb->data + offset);
65 struct xfrm_state *x; 65 struct xfrm_state *x;
66 66
67 if (type != ICMPV6_DEST_UNREACH && 67 if (type != ICMPV6_PKT_TOOBIG &&
68 type != ICMPV6_PKT_TOOBIG &&
69 type != NDISC_REDIRECT) 68 type != NDISC_REDIRECT)
70 return; 69 return;
71 70
diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
index 44400c216dc6..710238f58aa9 100644
--- a/net/ipv6/netfilter/ip6_tables.c
+++ b/net/ipv6/netfilter/ip6_tables.c
@@ -349,6 +349,11 @@ ip6t_do_table(struct sk_buff *skb,
349 local_bh_disable(); 349 local_bh_disable();
350 addend = xt_write_recseq_begin(); 350 addend = xt_write_recseq_begin();
351 private = table->private; 351 private = table->private;
352 /*
353 * Ensure we load private-> members after we've fetched the base
354 * pointer.
355 */
356 smp_read_barrier_depends();
352 cpu = smp_processor_id(); 357 cpu = smp_processor_id();
353 table_base = private->entries[cpu]; 358 table_base = private->entries[cpu];
354 jumpstack = (struct ip6t_entry **)private->jumpstack[cpu]; 359 jumpstack = (struct ip6t_entry **)private->jumpstack[cpu];
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index c979dd96d82a..04e17b3309fb 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -476,6 +476,24 @@ out:
476} 476}
477 477
478#ifdef CONFIG_IPV6_ROUTER_PREF 478#ifdef CONFIG_IPV6_ROUTER_PREF
479struct __rt6_probe_work {
480 struct work_struct work;
481 struct in6_addr target;
482 struct net_device *dev;
483};
484
485static void rt6_probe_deferred(struct work_struct *w)
486{
487 struct in6_addr mcaddr;
488 struct __rt6_probe_work *work =
489 container_of(w, struct __rt6_probe_work, work);
490
491 addrconf_addr_solict_mult(&work->target, &mcaddr);
492 ndisc_send_ns(work->dev, NULL, &work->target, &mcaddr, NULL);
493 dev_put(work->dev);
494 kfree(w);
495}
496
479static void rt6_probe(struct rt6_info *rt) 497static void rt6_probe(struct rt6_info *rt)
480{ 498{
481 struct neighbour *neigh; 499 struct neighbour *neigh;
@@ -499,17 +517,23 @@ static void rt6_probe(struct rt6_info *rt)
499 517
500 if (!neigh || 518 if (!neigh ||
501 time_after(jiffies, neigh->updated + rt->rt6i_idev->cnf.rtr_probe_interval)) { 519 time_after(jiffies, neigh->updated + rt->rt6i_idev->cnf.rtr_probe_interval)) {
502 struct in6_addr mcaddr; 520 struct __rt6_probe_work *work;
503 struct in6_addr *target; 521
522 work = kmalloc(sizeof(*work), GFP_ATOMIC);
504 523
505 if (neigh) { 524 if (neigh && work)
506 neigh->updated = jiffies; 525 neigh->updated = jiffies;
526
527 if (neigh)
507 write_unlock(&neigh->lock); 528 write_unlock(&neigh->lock);
508 }
509 529
510 target = (struct in6_addr *)&rt->rt6i_gateway; 530 if (work) {
511 addrconf_addr_solict_mult(target, &mcaddr); 531 INIT_WORK(&work->work, rt6_probe_deferred);
512 ndisc_send_ns(rt->dst.dev, NULL, target, &mcaddr, NULL); 532 work->target = rt->rt6i_gateway;
533 dev_hold(rt->dst.dev);
534 work->dev = rt->dst.dev;
535 schedule_work(&work->work);
536 }
513 } else { 537 } else {
514out: 538out:
515 write_unlock(&neigh->lock); 539 write_unlock(&neigh->lock);
@@ -851,7 +875,6 @@ static struct rt6_info *rt6_alloc_cow(struct rt6_info *ort,
851 if (ort->rt6i_dst.plen != 128 && 875 if (ort->rt6i_dst.plen != 128 &&
852 ipv6_addr_equal(&ort->rt6i_dst.addr, daddr)) 876 ipv6_addr_equal(&ort->rt6i_dst.addr, daddr))
853 rt->rt6i_flags |= RTF_ANYCAST; 877 rt->rt6i_flags |= RTF_ANYCAST;
854 rt->rt6i_gateway = *daddr;
855 } 878 }
856 879
857 rt->rt6i_flags |= RTF_CACHE; 880 rt->rt6i_flags |= RTF_CACHE;
@@ -1064,10 +1087,13 @@ static struct dst_entry *ip6_dst_check(struct dst_entry *dst, u32 cookie)
1064 if (rt->rt6i_genid != rt_genid_ipv6(dev_net(rt->dst.dev))) 1087 if (rt->rt6i_genid != rt_genid_ipv6(dev_net(rt->dst.dev)))
1065 return NULL; 1088 return NULL;
1066 1089
1067 if (rt->rt6i_node && (rt->rt6i_node->fn_sernum == cookie)) 1090 if (!rt->rt6i_node || (rt->rt6i_node->fn_sernum != cookie))
1068 return dst; 1091 return NULL;
1069 1092
1070 return NULL; 1093 if (rt6_check_expired(rt))
1094 return NULL;
1095
1096 return dst;
1071} 1097}
1072 1098
1073static struct dst_entry *ip6_negative_advice(struct dst_entry *dst) 1099static struct dst_entry *ip6_negative_advice(struct dst_entry *dst)
@@ -1338,6 +1364,7 @@ struct dst_entry *icmp6_dst_alloc(struct net_device *dev,
1338 rt->dst.flags |= DST_HOST; 1364 rt->dst.flags |= DST_HOST;
1339 rt->dst.output = ip6_output; 1365 rt->dst.output = ip6_output;
1340 atomic_set(&rt->dst.__refcnt, 1); 1366 atomic_set(&rt->dst.__refcnt, 1);
1367 rt->rt6i_gateway = fl6->daddr;
1341 rt->rt6i_dst.addr = fl6->daddr; 1368 rt->rt6i_dst.addr = fl6->daddr;
1342 rt->rt6i_dst.plen = 128; 1369 rt->rt6i_dst.plen = 128;
1343 rt->rt6i_idev = idev; 1370 rt->rt6i_idev = idev;
@@ -1873,7 +1900,10 @@ static struct rt6_info *ip6_rt_copy(struct rt6_info *ort,
1873 in6_dev_hold(rt->rt6i_idev); 1900 in6_dev_hold(rt->rt6i_idev);
1874 rt->dst.lastuse = jiffies; 1901 rt->dst.lastuse = jiffies;
1875 1902
1876 rt->rt6i_gateway = ort->rt6i_gateway; 1903 if (ort->rt6i_flags & RTF_GATEWAY)
1904 rt->rt6i_gateway = ort->rt6i_gateway;
1905 else
1906 rt->rt6i_gateway = *dest;
1877 rt->rt6i_flags = ort->rt6i_flags; 1907 rt->rt6i_flags = ort->rt6i_flags;
1878 if ((ort->rt6i_flags & (RTF_DEFAULT | RTF_ADDRCONF)) == 1908 if ((ort->rt6i_flags & (RTF_DEFAULT | RTF_ADDRCONF)) ==
1879 (RTF_DEFAULT | RTF_ADDRCONF)) 1909 (RTF_DEFAULT | RTF_ADDRCONF))
@@ -2160,6 +2190,7 @@ struct rt6_info *addrconf_dst_alloc(struct inet6_dev *idev,
2160 else 2190 else
2161 rt->rt6i_flags |= RTF_LOCAL; 2191 rt->rt6i_flags |= RTF_LOCAL;
2162 2192
2193 rt->rt6i_gateway = *addr;
2163 rt->rt6i_dst.addr = *addr; 2194 rt->rt6i_dst.addr = *addr;
2164 rt->rt6i_dst.plen = 128; 2195 rt->rt6i_dst.plen = 128;
2165 rt->rt6i_table = fib6_get_table(net, RT6_TABLE_LOCAL); 2196 rt->rt6i_table = fib6_get_table(net, RT6_TABLE_LOCAL);
diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
index 72b7eaaf3ca0..18786098fd41 100644
--- a/net/ipv6/udp.c
+++ b/net/ipv6/udp.c
@@ -1225,9 +1225,6 @@ do_udp_sendmsg:
1225 if (tclass < 0) 1225 if (tclass < 0)
1226 tclass = np->tclass; 1226 tclass = np->tclass;
1227 1227
1228 if (dontfrag < 0)
1229 dontfrag = np->dontfrag;
1230
1231 if (msg->msg_flags&MSG_CONFIRM) 1228 if (msg->msg_flags&MSG_CONFIRM)
1232 goto do_confirm; 1229 goto do_confirm;
1233back_from_confirm: 1230back_from_confirm:
@@ -1246,6 +1243,8 @@ back_from_confirm:
1246 up->pending = AF_INET6; 1243 up->pending = AF_INET6;
1247 1244
1248do_append_data: 1245do_append_data:
1246 if (dontfrag < 0)
1247 dontfrag = np->dontfrag;
1249 up->len += ulen; 1248 up->len += ulen;
1250 getfrag = is_udplite ? udplite_getfrag : ip_generic_getfrag; 1249 getfrag = is_udplite ? udplite_getfrag : ip_generic_getfrag;
1251 err = ip6_append_data(sk, getfrag, msg->msg_iov, ulen, 1250 err = ip6_append_data(sk, getfrag, msg->msg_iov, ulen,
diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
index 23ed03d786c8..5f8e128c512d 100644
--- a/net/ipv6/xfrm6_policy.c
+++ b/net/ipv6/xfrm6_policy.c
@@ -135,9 +135,14 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
135 struct ipv6_opt_hdr *exthdr; 135 struct ipv6_opt_hdr *exthdr;
136 const unsigned char *nh = skb_network_header(skb); 136 const unsigned char *nh = skb_network_header(skb);
137 u8 nexthdr = nh[IP6CB(skb)->nhoff]; 137 u8 nexthdr = nh[IP6CB(skb)->nhoff];
138 int oif = 0;
139
140 if (skb_dst(skb))
141 oif = skb_dst(skb)->dev->ifindex;
138 142
139 memset(fl6, 0, sizeof(struct flowi6)); 143 memset(fl6, 0, sizeof(struct flowi6));
140 fl6->flowi6_mark = skb->mark; 144 fl6->flowi6_mark = skb->mark;
145 fl6->flowi6_oif = reverse ? skb->skb_iif : oif;
141 146
142 fl6->daddr = reverse ? hdr->saddr : hdr->daddr; 147 fl6->daddr = reverse ? hdr->saddr : hdr->daddr;
143 fl6->saddr = reverse ? hdr->daddr : hdr->saddr; 148 fl6->saddr = reverse ? hdr->daddr : hdr->saddr;
@@ -284,7 +289,7 @@ static struct dst_ops xfrm6_dst_ops = {
284 .destroy = xfrm6_dst_destroy, 289 .destroy = xfrm6_dst_destroy,
285 .ifdown = xfrm6_dst_ifdown, 290 .ifdown = xfrm6_dst_ifdown,
286 .local_out = __ip6_local_out, 291 .local_out = __ip6_local_out,
287 .gc_thresh = 1024, 292 .gc_thresh = 32768,
288}; 293};
289 294
290static struct xfrm_policy_afinfo xfrm6_policy_afinfo = { 295static struct xfrm_policy_afinfo xfrm6_policy_afinfo = {
diff --git a/net/key/af_key.c b/net/key/af_key.c
index 9d585370c5b4..911ef03bf8fb 100644
--- a/net/key/af_key.c
+++ b/net/key/af_key.c
@@ -1098,7 +1098,8 @@ static struct xfrm_state * pfkey_msg2xfrm_state(struct net *net,
1098 1098
1099 x->id.proto = proto; 1099 x->id.proto = proto;
1100 x->id.spi = sa->sadb_sa_spi; 1100 x->id.spi = sa->sadb_sa_spi;
1101 x->props.replay_window = sa->sadb_sa_replay; 1101 x->props.replay_window = min_t(unsigned int, sa->sadb_sa_replay,
1102 (sizeof(x->replay.bitmap) * 8));
1102 if (sa->sadb_sa_flags & SADB_SAFLAGS_NOECN) 1103 if (sa->sadb_sa_flags & SADB_SAFLAGS_NOECN)
1103 x->props.flags |= XFRM_STATE_NOECN; 1104 x->props.flags |= XFRM_STATE_NOECN;
1104 if (sa->sadb_sa_flags & SADB_SAFLAGS_DECAP_DSCP) 1105 if (sa->sadb_sa_flags & SADB_SAFLAGS_DECAP_DSCP)
diff --git a/net/l2tp/l2tp_core.c b/net/l2tp/l2tp_core.c
index feae495a0a30..b076e8309bc2 100644
--- a/net/l2tp/l2tp_core.c
+++ b/net/l2tp/l2tp_core.c
@@ -115,6 +115,11 @@ struct l2tp_net {
115static void l2tp_session_set_header_len(struct l2tp_session *session, int version); 115static void l2tp_session_set_header_len(struct l2tp_session *session, int version);
116static void l2tp_tunnel_free(struct l2tp_tunnel *tunnel); 116static void l2tp_tunnel_free(struct l2tp_tunnel *tunnel);
117 117
118static inline struct l2tp_tunnel *l2tp_tunnel(struct sock *sk)
119{
120 return sk->sk_user_data;
121}
122
118static inline struct l2tp_net *l2tp_pernet(struct net *net) 123static inline struct l2tp_net *l2tp_pernet(struct net *net)
119{ 124{
120 BUG_ON(!net); 125 BUG_ON(!net);
@@ -504,7 +509,7 @@ static inline int l2tp_verify_udp_checksum(struct sock *sk,
504 return 0; 509 return 0;
505 510
506#if IS_ENABLED(CONFIG_IPV6) 511#if IS_ENABLED(CONFIG_IPV6)
507 if (sk->sk_family == PF_INET6) { 512 if (sk->sk_family == PF_INET6 && !l2tp_tunnel(sk)->v4mapped) {
508 if (!uh->check) { 513 if (!uh->check) {
509 LIMIT_NETDEBUG(KERN_INFO "L2TP: IPv6: checksum is 0\n"); 514 LIMIT_NETDEBUG(KERN_INFO "L2TP: IPv6: checksum is 0\n");
510 return 1; 515 return 1;
@@ -1128,7 +1133,7 @@ static int l2tp_xmit_core(struct l2tp_session *session, struct sk_buff *skb,
1128 /* Queue the packet to IP for output */ 1133 /* Queue the packet to IP for output */
1129 skb->local_df = 1; 1134 skb->local_df = 1;
1130#if IS_ENABLED(CONFIG_IPV6) 1135#if IS_ENABLED(CONFIG_IPV6)
1131 if (skb->sk->sk_family == PF_INET6) 1136 if (skb->sk->sk_family == PF_INET6 && !tunnel->v4mapped)
1132 error = inet6_csk_xmit(skb, NULL); 1137 error = inet6_csk_xmit(skb, NULL);
1133 else 1138 else
1134#endif 1139#endif
@@ -1255,7 +1260,7 @@ int l2tp_xmit_skb(struct l2tp_session *session, struct sk_buff *skb, int hdr_len
1255 1260
1256 /* Calculate UDP checksum if configured to do so */ 1261 /* Calculate UDP checksum if configured to do so */
1257#if IS_ENABLED(CONFIG_IPV6) 1262#if IS_ENABLED(CONFIG_IPV6)
1258 if (sk->sk_family == PF_INET6) 1263 if (sk->sk_family == PF_INET6 && !tunnel->v4mapped)
1259 l2tp_xmit_ipv6_csum(sk, skb, udp_len); 1264 l2tp_xmit_ipv6_csum(sk, skb, udp_len);
1260 else 1265 else
1261#endif 1266#endif
@@ -1304,10 +1309,9 @@ EXPORT_SYMBOL_GPL(l2tp_xmit_skb);
1304 */ 1309 */
1305static void l2tp_tunnel_destruct(struct sock *sk) 1310static void l2tp_tunnel_destruct(struct sock *sk)
1306{ 1311{
1307 struct l2tp_tunnel *tunnel; 1312 struct l2tp_tunnel *tunnel = l2tp_tunnel(sk);
1308 struct l2tp_net *pn; 1313 struct l2tp_net *pn;
1309 1314
1310 tunnel = sk->sk_user_data;
1311 if (tunnel == NULL) 1315 if (tunnel == NULL)
1312 goto end; 1316 goto end;
1313 1317
@@ -1675,7 +1679,7 @@ int l2tp_tunnel_create(struct net *net, int fd, int version, u32 tunnel_id, u32
1675 } 1679 }
1676 1680
1677 /* Check if this socket has already been prepped */ 1681 /* Check if this socket has already been prepped */
1678 tunnel = (struct l2tp_tunnel *)sk->sk_user_data; 1682 tunnel = l2tp_tunnel(sk);
1679 if (tunnel != NULL) { 1683 if (tunnel != NULL) {
1680 /* This socket has already been prepped */ 1684 /* This socket has already been prepped */
1681 err = -EBUSY; 1685 err = -EBUSY;
@@ -1704,6 +1708,24 @@ int l2tp_tunnel_create(struct net *net, int fd, int version, u32 tunnel_id, u32
1704 if (cfg != NULL) 1708 if (cfg != NULL)
1705 tunnel->debug = cfg->debug; 1709 tunnel->debug = cfg->debug;
1706 1710
1711#if IS_ENABLED(CONFIG_IPV6)
1712 if (sk->sk_family == PF_INET6) {
1713 struct ipv6_pinfo *np = inet6_sk(sk);
1714
1715 if (ipv6_addr_v4mapped(&np->saddr) &&
1716 ipv6_addr_v4mapped(&np->daddr)) {
1717 struct inet_sock *inet = inet_sk(sk);
1718
1719 tunnel->v4mapped = true;
1720 inet->inet_saddr = np->saddr.s6_addr32[3];
1721 inet->inet_rcv_saddr = np->rcv_saddr.s6_addr32[3];
1722 inet->inet_daddr = np->daddr.s6_addr32[3];
1723 } else {
1724 tunnel->v4mapped = false;
1725 }
1726 }
1727#endif
1728
1707 /* Mark socket as an encapsulation socket. See net/ipv4/udp.c */ 1729 /* Mark socket as an encapsulation socket. See net/ipv4/udp.c */
1708 tunnel->encap = encap; 1730 tunnel->encap = encap;
1709 if (encap == L2TP_ENCAPTYPE_UDP) { 1731 if (encap == L2TP_ENCAPTYPE_UDP) {
@@ -1712,7 +1734,7 @@ int l2tp_tunnel_create(struct net *net, int fd, int version, u32 tunnel_id, u32
1712 udp_sk(sk)->encap_rcv = l2tp_udp_encap_recv; 1734 udp_sk(sk)->encap_rcv = l2tp_udp_encap_recv;
1713 udp_sk(sk)->encap_destroy = l2tp_udp_encap_destroy; 1735 udp_sk(sk)->encap_destroy = l2tp_udp_encap_destroy;
1714#if IS_ENABLED(CONFIG_IPV6) 1736#if IS_ENABLED(CONFIG_IPV6)
1715 if (sk->sk_family == PF_INET6) 1737 if (sk->sk_family == PF_INET6 && !tunnel->v4mapped)
1716 udpv6_encap_enable(); 1738 udpv6_encap_enable();
1717 else 1739 else
1718#endif 1740#endif
diff --git a/net/l2tp/l2tp_core.h b/net/l2tp/l2tp_core.h
index 66a559b104b6..6f251cbc2ed7 100644
--- a/net/l2tp/l2tp_core.h
+++ b/net/l2tp/l2tp_core.h
@@ -194,6 +194,9 @@ struct l2tp_tunnel {
194 struct sock *sock; /* Parent socket */ 194 struct sock *sock; /* Parent socket */
195 int fd; /* Parent fd, if tunnel socket 195 int fd; /* Parent fd, if tunnel socket
196 * was created by userspace */ 196 * was created by userspace */
197#if IS_ENABLED(CONFIG_IPV6)
198 bool v4mapped;
199#endif
197 200
198 struct work_struct del_work; 201 struct work_struct del_work;
199 202
diff --git a/net/l2tp/l2tp_ppp.c b/net/l2tp/l2tp_ppp.c
index 5ebee2ded9e9..8c46b271064a 100644
--- a/net/l2tp/l2tp_ppp.c
+++ b/net/l2tp/l2tp_ppp.c
@@ -353,7 +353,9 @@ static int pppol2tp_sendmsg(struct kiocb *iocb, struct socket *sock, struct msgh
353 goto error_put_sess_tun; 353 goto error_put_sess_tun;
354 } 354 }
355 355
356 local_bh_disable();
356 l2tp_xmit_skb(session, skb, session->hdr_len); 357 l2tp_xmit_skb(session, skb, session->hdr_len);
358 local_bh_enable();
357 359
358 sock_put(ps->tunnel_sock); 360 sock_put(ps->tunnel_sock);
359 sock_put(sk); 361 sock_put(sk);
@@ -422,7 +424,9 @@ static int pppol2tp_xmit(struct ppp_channel *chan, struct sk_buff *skb)
422 skb->data[0] = ppph[0]; 424 skb->data[0] = ppph[0];
423 skb->data[1] = ppph[1]; 425 skb->data[1] = ppph[1];
424 426
427 local_bh_disable();
425 l2tp_xmit_skb(session, skb, session->hdr_len); 428 l2tp_xmit_skb(session, skb, session->hdr_len);
429 local_bh_enable();
426 430
427 sock_put(sk_tun); 431 sock_put(sk_tun);
428 sock_put(sk); 432 sock_put(sk);
diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
index 2e7855a1b10d..629dee7ec9bf 100644
--- a/net/mac80211/cfg.c
+++ b/net/mac80211/cfg.c
@@ -3518,7 +3518,7 @@ static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev,
3518 return -EINVAL; 3518 return -EINVAL;
3519 } 3519 }
3520 band = chanctx_conf->def.chan->band; 3520 band = chanctx_conf->def.chan->band;
3521 sta = sta_info_get(sdata, peer); 3521 sta = sta_info_get_bss(sdata, peer);
3522 if (sta) { 3522 if (sta) {
3523 qos = test_sta_flag(sta, WLAN_STA_WME); 3523 qos = test_sta_flag(sta, WLAN_STA_WME);
3524 } else { 3524 } else {
diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
index b6186517ec56..611abfcfb5eb 100644
--- a/net/mac80211/ieee80211_i.h
+++ b/net/mac80211/ieee80211_i.h
@@ -893,6 +893,8 @@ struct tpt_led_trigger {
893 * that the scan completed. 893 * that the scan completed.
894 * @SCAN_ABORTED: Set for our scan work function when the driver reported 894 * @SCAN_ABORTED: Set for our scan work function when the driver reported
895 * a scan complete for an aborted scan. 895 * a scan complete for an aborted scan.
896 * @SCAN_HW_CANCELLED: Set for our scan work function when the scan is being
897 * cancelled.
896 */ 898 */
897enum { 899enum {
898 SCAN_SW_SCANNING, 900 SCAN_SW_SCANNING,
@@ -900,6 +902,7 @@ enum {
900 SCAN_ONCHANNEL_SCANNING, 902 SCAN_ONCHANNEL_SCANNING,
901 SCAN_COMPLETED, 903 SCAN_COMPLETED,
902 SCAN_ABORTED, 904 SCAN_ABORTED,
905 SCAN_HW_CANCELLED,
903}; 906};
904 907
905/** 908/**
diff --git a/net/mac80211/offchannel.c b/net/mac80211/offchannel.c
index acd1f71adc03..0c2a29484c07 100644
--- a/net/mac80211/offchannel.c
+++ b/net/mac80211/offchannel.c
@@ -394,6 +394,8 @@ void ieee80211_sw_roc_work(struct work_struct *work)
394 394
395 if (started) 395 if (started)
396 ieee80211_start_next_roc(local); 396 ieee80211_start_next_roc(local);
397 else if (list_empty(&local->roc_list))
398 ieee80211_run_deferred_scan(local);
397 } 399 }
398 400
399 out_unlock: 401 out_unlock:
diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c
index 54395d7583ba..674eac1f996c 100644
--- a/net/mac80211/rx.c
+++ b/net/mac80211/rx.c
@@ -3056,6 +3056,9 @@ static int prepare_for_handlers(struct ieee80211_rx_data *rx,
3056 case NL80211_IFTYPE_ADHOC: 3056 case NL80211_IFTYPE_ADHOC:
3057 if (!bssid) 3057 if (!bssid)
3058 return 0; 3058 return 0;
3059 if (ether_addr_equal(sdata->vif.addr, hdr->addr2) ||
3060 ether_addr_equal(sdata->u.ibss.bssid, hdr->addr2))
3061 return 0;
3059 if (ieee80211_is_beacon(hdr->frame_control)) { 3062 if (ieee80211_is_beacon(hdr->frame_control)) {
3060 return 1; 3063 return 1;
3061 } else if (!ieee80211_bssid_match(bssid, sdata->u.ibss.bssid)) { 3064 } else if (!ieee80211_bssid_match(bssid, sdata->u.ibss.bssid)) {
diff --git a/net/mac80211/scan.c b/net/mac80211/scan.c
index 08afe74b98f4..d2d17a449224 100644
--- a/net/mac80211/scan.c
+++ b/net/mac80211/scan.c
@@ -238,6 +238,9 @@ static bool ieee80211_prep_hw_scan(struct ieee80211_local *local)
238 enum ieee80211_band band; 238 enum ieee80211_band band;
239 int i, ielen, n_chans; 239 int i, ielen, n_chans;
240 240
241 if (test_bit(SCAN_HW_CANCELLED, &local->scanning))
242 return false;
243
241 do { 244 do {
242 if (local->hw_scan_band == IEEE80211_NUM_BANDS) 245 if (local->hw_scan_band == IEEE80211_NUM_BANDS)
243 return false; 246 return false;
@@ -940,7 +943,23 @@ void ieee80211_scan_cancel(struct ieee80211_local *local)
940 if (!local->scan_req) 943 if (!local->scan_req)
941 goto out; 944 goto out;
942 945
946 /*
947 * We have a scan running and the driver already reported completion,
948 * but the worker hasn't run yet or is stuck on the mutex - mark it as
949 * cancelled.
950 */
951 if (test_bit(SCAN_HW_SCANNING, &local->scanning) &&
952 test_bit(SCAN_COMPLETED, &local->scanning)) {
953 set_bit(SCAN_HW_CANCELLED, &local->scanning);
954 goto out;
955 }
956
943 if (test_bit(SCAN_HW_SCANNING, &local->scanning)) { 957 if (test_bit(SCAN_HW_SCANNING, &local->scanning)) {
958 /*
959 * Make sure that __ieee80211_scan_completed doesn't trigger a
960 * scan on another band.
961 */
962 set_bit(SCAN_HW_CANCELLED, &local->scanning);
944 if (local->ops->cancel_hw_scan) 963 if (local->ops->cancel_hw_scan)
945 drv_cancel_hw_scan(local, 964 drv_cancel_hw_scan(local,
946 rcu_dereference_protected(local->scan_sdata, 965 rcu_dereference_protected(local->scan_sdata,
diff --git a/net/mac80211/status.c b/net/mac80211/status.c
index 368837fe3b80..78dc2e99027e 100644
--- a/net/mac80211/status.c
+++ b/net/mac80211/status.c
@@ -180,6 +180,9 @@ static void ieee80211_frame_acked(struct sta_info *sta, struct sk_buff *skb)
180 struct ieee80211_local *local = sta->local; 180 struct ieee80211_local *local = sta->local;
181 struct ieee80211_sub_if_data *sdata = sta->sdata; 181 struct ieee80211_sub_if_data *sdata = sta->sdata;
182 182
183 if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
184 sta->last_rx = jiffies;
185
183 if (ieee80211_is_data_qos(mgmt->frame_control)) { 186 if (ieee80211_is_data_qos(mgmt->frame_control)) {
184 struct ieee80211_hdr *hdr = (void *) skb->data; 187 struct ieee80211_hdr *hdr = (void *) skb->data;
185 u8 *qc = ieee80211_get_qos_ctl(hdr); 188 u8 *qc = ieee80211_get_qos_ctl(hdr);
diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c
index 3456c0486b48..70b5a05c0a4e 100644
--- a/net/mac80211/tx.c
+++ b/net/mac80211/tx.c
@@ -1120,7 +1120,8 @@ ieee80211_tx_prepare(struct ieee80211_sub_if_data *sdata,
1120 tx->sta = rcu_dereference(sdata->u.vlan.sta); 1120 tx->sta = rcu_dereference(sdata->u.vlan.sta);
1121 if (!tx->sta && sdata->dev->ieee80211_ptr->use_4addr) 1121 if (!tx->sta && sdata->dev->ieee80211_ptr->use_4addr)
1122 return TX_DROP; 1122 return TX_DROP;
1123 } else if (info->flags & IEEE80211_TX_CTL_INJECTED || 1123 } else if (info->flags & (IEEE80211_TX_CTL_INJECTED |
1124 IEEE80211_TX_INTFL_NL80211_FRAME_TX) ||
1124 tx->sdata->control_port_protocol == tx->skb->protocol) { 1125 tx->sdata->control_port_protocol == tx->skb->protocol) {
1125 tx->sta = sta_info_get_bss(sdata, hdr->addr1); 1126 tx->sta = sta_info_get_bss(sdata, hdr->addr1);
1126 } 1127 }
diff --git a/net/mac80211/util.c b/net/mac80211/util.c
index e1b34a18b243..69e4ef5348a0 100644
--- a/net/mac80211/util.c
+++ b/net/mac80211/util.c
@@ -2103,7 +2103,7 @@ int ieee80211_add_ext_srates_ie(struct ieee80211_sub_if_data *sdata,
2103{ 2103{
2104 struct ieee80211_local *local = sdata->local; 2104 struct ieee80211_local *local = sdata->local;
2105 struct ieee80211_supported_band *sband; 2105 struct ieee80211_supported_band *sband;
2106 int rate, skip, shift; 2106 int rate, shift;
2107 u8 i, exrates, *pos; 2107 u8 i, exrates, *pos;
2108 u32 basic_rates = sdata->vif.bss_conf.basic_rates; 2108 u32 basic_rates = sdata->vif.bss_conf.basic_rates;
2109 u32 rate_flags; 2109 u32 rate_flags;
@@ -2131,14 +2131,11 @@ int ieee80211_add_ext_srates_ie(struct ieee80211_sub_if_data *sdata,
2131 pos = skb_put(skb, exrates + 2); 2131 pos = skb_put(skb, exrates + 2);
2132 *pos++ = WLAN_EID_EXT_SUPP_RATES; 2132 *pos++ = WLAN_EID_EXT_SUPP_RATES;
2133 *pos++ = exrates; 2133 *pos++ = exrates;
2134 skip = 0;
2135 for (i = 8; i < sband->n_bitrates; i++) { 2134 for (i = 8; i < sband->n_bitrates; i++) {
2136 u8 basic = 0; 2135 u8 basic = 0;
2137 if ((rate_flags & sband->bitrates[i].flags) 2136 if ((rate_flags & sband->bitrates[i].flags)
2138 != rate_flags) 2137 != rate_flags)
2139 continue; 2138 continue;
2140 if (skip++ < 8)
2141 continue;
2142 if (need_basic && basic_rates & BIT(i)) 2139 if (need_basic && basic_rates & BIT(i))
2143 basic = 0x80; 2140 basic = 0x80;
2144 rate = DIV_ROUND_UP(sband->bitrates[i].bitrate, 2141 rate = DIV_ROUND_UP(sband->bitrates[i].bitrate,
@@ -2241,6 +2238,10 @@ u64 ieee80211_calculate_rx_timestamp(struct ieee80211_local *local,
2241 } 2238 }
2242 2239
2243 rate = cfg80211_calculate_bitrate(&ri); 2240 rate = cfg80211_calculate_bitrate(&ri);
2241 if (WARN_ONCE(!rate,
2242 "Invalid bitrate: flags=0x%x, idx=%d, vht_nss=%d\n",
2243 status->flag, status->rate_idx, status->vht_nss))
2244 return 0;
2244 2245
2245 /* rewind from end of MPDU */ 2246 /* rewind from end of MPDU */
2246 if (status->flag & RX_FLAG_MACTIME_END) 2247 if (status->flag & RX_FLAG_MACTIME_END)
diff --git a/net/netfilter/nf_conntrack_h323_main.c b/net/netfilter/nf_conntrack_h323_main.c
index bdebd03bc8cd..70866d192efc 100644
--- a/net/netfilter/nf_conntrack_h323_main.c
+++ b/net/netfilter/nf_conntrack_h323_main.c
@@ -778,8 +778,8 @@ static int callforward_do_filter(const union nf_inet_addr *src,
778 flowi6_to_flowi(&fl1), false)) { 778 flowi6_to_flowi(&fl1), false)) {
779 if (!afinfo->route(&init_net, (struct dst_entry **)&rt2, 779 if (!afinfo->route(&init_net, (struct dst_entry **)&rt2,
780 flowi6_to_flowi(&fl2), false)) { 780 flowi6_to_flowi(&fl2), false)) {
781 if (!memcmp(&rt1->rt6i_gateway, &rt2->rt6i_gateway, 781 if (ipv6_addr_equal(rt6_nexthop(rt1),
782 sizeof(rt1->rt6i_gateway)) && 782 rt6_nexthop(rt2)) &&
783 rt1->dst.dev == rt2->dst.dev) 783 rt1->dst.dev == rt2->dst.dev)
784 ret = 1; 784 ret = 1;
785 dst_release(&rt2->dst); 785 dst_release(&rt2->dst);
diff --git a/net/netfilter/x_tables.c b/net/netfilter/x_tables.c
index 8b03028cca69..227aa11e8409 100644
--- a/net/netfilter/x_tables.c
+++ b/net/netfilter/x_tables.c
@@ -845,8 +845,13 @@ xt_replace_table(struct xt_table *table,
845 return NULL; 845 return NULL;
846 } 846 }
847 847
848 table->private = newinfo;
849 newinfo->initial_entries = private->initial_entries; 848 newinfo->initial_entries = private->initial_entries;
849 /*
850 * Ensure contents of newinfo are visible before assigning to
851 * private.
852 */
853 smp_wmb();
854 table->private = newinfo;
850 855
851 /* 856 /*
852 * Even though table entries have now been swapped, other CPU's 857 * Even though table entries have now been swapped, other CPU's
diff --git a/net/netfilter/xt_NFQUEUE.c b/net/netfilter/xt_NFQUEUE.c
index 1e2fae32f81b..ed00fef58996 100644
--- a/net/netfilter/xt_NFQUEUE.c
+++ b/net/netfilter/xt_NFQUEUE.c
@@ -147,6 +147,7 @@ nfqueue_tg_v3(struct sk_buff *skb, const struct xt_action_param *par)
147{ 147{
148 const struct xt_NFQ_info_v3 *info = par->targinfo; 148 const struct xt_NFQ_info_v3 *info = par->targinfo;
149 u32 queue = info->queuenum; 149 u32 queue = info->queuenum;
150 int ret;
150 151
151 if (info->queues_total > 1) { 152 if (info->queues_total > 1) {
152 if (info->flags & NFQ_FLAG_CPU_FANOUT) { 153 if (info->flags & NFQ_FLAG_CPU_FANOUT) {
@@ -157,7 +158,11 @@ nfqueue_tg_v3(struct sk_buff *skb, const struct xt_action_param *par)
157 queue = nfqueue_hash(skb, par); 158 queue = nfqueue_hash(skb, par);
158 } 159 }
159 160
160 return NF_QUEUE_NR(queue); 161 ret = NF_QUEUE_NR(queue);
162 if (info->flags & NFQ_FLAG_BYPASS)
163 ret |= NF_VERDICT_FLAG_QUEUE_BYPASS;
164
165 return ret;
161} 166}
162 167
163static struct xt_target nfqueue_tg_reg[] __read_mostly = { 168static struct xt_target nfqueue_tg_reg[] __read_mostly = {
diff --git a/net/openvswitch/dp_notify.c b/net/openvswitch/dp_notify.c
index c3235675f359..5c2dab276109 100644
--- a/net/openvswitch/dp_notify.c
+++ b/net/openvswitch/dp_notify.c
@@ -65,8 +65,7 @@ void ovs_dp_notify_wq(struct work_struct *work)
65 continue; 65 continue;
66 66
67 netdev_vport = netdev_vport_priv(vport); 67 netdev_vport = netdev_vport_priv(vport);
68 if (netdev_vport->dev->reg_state == NETREG_UNREGISTERED || 68 if (!(netdev_vport->dev->priv_flags & IFF_OVS_DATAPATH))
69 netdev_vport->dev->reg_state == NETREG_UNREGISTERING)
70 dp_detach_port_notify(vport); 69 dp_detach_port_notify(vport);
71 } 70 }
72 } 71 }
@@ -88,6 +87,10 @@ static int dp_device_event(struct notifier_block *unused, unsigned long event,
88 return NOTIFY_DONE; 87 return NOTIFY_DONE;
89 88
90 if (event == NETDEV_UNREGISTER) { 89 if (event == NETDEV_UNREGISTER) {
90 /* upper_dev_unlink and decrement promisc immediately */
91 ovs_netdev_detach_dev(vport);
92
93 /* schedule vport destroy, dev_put and genl notification */
91 ovs_net = net_generic(dev_net(dev), ovs_net_id); 94 ovs_net = net_generic(dev_net(dev), ovs_net_id);
92 queue_work(system_wq, &ovs_net->dp_notify_work); 95 queue_work(system_wq, &ovs_net->dp_notify_work);
93 } 96 }
diff --git a/net/openvswitch/vport-netdev.c b/net/openvswitch/vport-netdev.c
index 09d93c13cfd6..d21f77d875ba 100644
--- a/net/openvswitch/vport-netdev.c
+++ b/net/openvswitch/vport-netdev.c
@@ -150,15 +150,25 @@ static void free_port_rcu(struct rcu_head *rcu)
150 ovs_vport_free(vport_from_priv(netdev_vport)); 150 ovs_vport_free(vport_from_priv(netdev_vport));
151} 151}
152 152
153static void netdev_destroy(struct vport *vport) 153void ovs_netdev_detach_dev(struct vport *vport)
154{ 154{
155 struct netdev_vport *netdev_vport = netdev_vport_priv(vport); 155 struct netdev_vport *netdev_vport = netdev_vport_priv(vport);
156 156
157 rtnl_lock(); 157 ASSERT_RTNL();
158 netdev_vport->dev->priv_flags &= ~IFF_OVS_DATAPATH; 158 netdev_vport->dev->priv_flags &= ~IFF_OVS_DATAPATH;
159 netdev_rx_handler_unregister(netdev_vport->dev); 159 netdev_rx_handler_unregister(netdev_vport->dev);
160 netdev_upper_dev_unlink(netdev_vport->dev, get_dpdev(vport->dp)); 160 netdev_upper_dev_unlink(netdev_vport->dev,
161 netdev_master_upper_dev_get(netdev_vport->dev));
161 dev_set_promiscuity(netdev_vport->dev, -1); 162 dev_set_promiscuity(netdev_vport->dev, -1);
163}
164
165static void netdev_destroy(struct vport *vport)
166{
167 struct netdev_vport *netdev_vport = netdev_vport_priv(vport);
168
169 rtnl_lock();
170 if (netdev_vport->dev->priv_flags & IFF_OVS_DATAPATH)
171 ovs_netdev_detach_dev(vport);
162 rtnl_unlock(); 172 rtnl_unlock();
163 173
164 call_rcu(&netdev_vport->rcu, free_port_rcu); 174 call_rcu(&netdev_vport->rcu, free_port_rcu);
diff --git a/net/openvswitch/vport-netdev.h b/net/openvswitch/vport-netdev.h
index dd298b5c5cdb..8df01c1127e5 100644
--- a/net/openvswitch/vport-netdev.h
+++ b/net/openvswitch/vport-netdev.h
@@ -39,5 +39,6 @@ netdev_vport_priv(const struct vport *vport)
39} 39}
40 40
41const char *ovs_netdev_get_name(const struct vport *); 41const char *ovs_netdev_get_name(const struct vport *);
42void ovs_netdev_detach_dev(struct vport *);
42 43
43#endif /* vport_netdev.h */ 44#endif /* vport_netdev.h */
diff --git a/net/sched/sch_fq.c b/net/sched/sch_fq.c
index a2fef8b10b96..fdc041c57853 100644
--- a/net/sched/sch_fq.c
+++ b/net/sched/sch_fq.c
@@ -255,6 +255,7 @@ static struct fq_flow *fq_classify(struct sk_buff *skb, struct fq_sched_data *q)
255 f->socket_hash != sk->sk_hash)) { 255 f->socket_hash != sk->sk_hash)) {
256 f->credit = q->initial_quantum; 256 f->credit = q->initial_quantum;
257 f->socket_hash = sk->sk_hash; 257 f->socket_hash = sk->sk_hash;
258 f->time_next_packet = 0ULL;
258 } 259 }
259 return f; 260 return f;
260 } 261 }
@@ -472,20 +473,16 @@ begin:
472 if (f->credit > 0 || !q->rate_enable) 473 if (f->credit > 0 || !q->rate_enable)
473 goto out; 474 goto out;
474 475
475 if (skb->sk && skb->sk->sk_state != TCP_TIME_WAIT) { 476 rate = q->flow_max_rate;
476 rate = skb->sk->sk_pacing_rate ?: q->flow_default_rate; 477 if (skb->sk && skb->sk->sk_state != TCP_TIME_WAIT)
478 rate = min(skb->sk->sk_pacing_rate, rate);
477 479
478 rate = min(rate, q->flow_max_rate); 480 if (rate != ~0U) {
479 } else {
480 rate = q->flow_max_rate;
481 if (rate == ~0U)
482 goto out;
483 }
484 if (rate) {
485 u32 plen = max(qdisc_pkt_len(skb), q->quantum); 481 u32 plen = max(qdisc_pkt_len(skb), q->quantum);
486 u64 len = (u64)plen * NSEC_PER_SEC; 482 u64 len = (u64)plen * NSEC_PER_SEC;
487 483
488 do_div(len, rate); 484 if (likely(rate))
485 do_div(len, rate);
489 /* Since socket rate can change later, 486 /* Since socket rate can change later,
490 * clamp the delay to 125 ms. 487 * clamp the delay to 125 ms.
491 * TODO: maybe segment the too big skb, as in commit 488 * TODO: maybe segment the too big skb, as in commit
@@ -656,7 +653,7 @@ static int fq_change(struct Qdisc *sch, struct nlattr *opt)
656 q->quantum = nla_get_u32(tb[TCA_FQ_QUANTUM]); 653 q->quantum = nla_get_u32(tb[TCA_FQ_QUANTUM]);
657 654
658 if (tb[TCA_FQ_INITIAL_QUANTUM]) 655 if (tb[TCA_FQ_INITIAL_QUANTUM])
659 q->quantum = nla_get_u32(tb[TCA_FQ_INITIAL_QUANTUM]); 656 q->initial_quantum = nla_get_u32(tb[TCA_FQ_INITIAL_QUANTUM]);
660 657
661 if (tb[TCA_FQ_FLOW_DEFAULT_RATE]) 658 if (tb[TCA_FQ_FLOW_DEFAULT_RATE])
662 q->flow_default_rate = nla_get_u32(tb[TCA_FQ_FLOW_DEFAULT_RATE]); 659 q->flow_default_rate = nla_get_u32(tb[TCA_FQ_FLOW_DEFAULT_RATE]);
@@ -735,12 +732,14 @@ static int fq_dump(struct Qdisc *sch, struct sk_buff *skb)
735 if (opts == NULL) 732 if (opts == NULL)
736 goto nla_put_failure; 733 goto nla_put_failure;
737 734
735 /* TCA_FQ_FLOW_DEFAULT_RATE is not used anymore,
736 * do not bother giving its value
737 */
738 if (nla_put_u32(skb, TCA_FQ_PLIMIT, sch->limit) || 738 if (nla_put_u32(skb, TCA_FQ_PLIMIT, sch->limit) ||
739 nla_put_u32(skb, TCA_FQ_FLOW_PLIMIT, q->flow_plimit) || 739 nla_put_u32(skb, TCA_FQ_FLOW_PLIMIT, q->flow_plimit) ||
740 nla_put_u32(skb, TCA_FQ_QUANTUM, q->quantum) || 740 nla_put_u32(skb, TCA_FQ_QUANTUM, q->quantum) ||
741 nla_put_u32(skb, TCA_FQ_INITIAL_QUANTUM, q->initial_quantum) || 741 nla_put_u32(skb, TCA_FQ_INITIAL_QUANTUM, q->initial_quantum) ||
742 nla_put_u32(skb, TCA_FQ_RATE_ENABLE, q->rate_enable) || 742 nla_put_u32(skb, TCA_FQ_RATE_ENABLE, q->rate_enable) ||
743 nla_put_u32(skb, TCA_FQ_FLOW_DEFAULT_RATE, q->flow_default_rate) ||
744 nla_put_u32(skb, TCA_FQ_FLOW_MAX_RATE, q->flow_max_rate) || 743 nla_put_u32(skb, TCA_FQ_FLOW_MAX_RATE, q->flow_max_rate) ||
745 nla_put_u32(skb, TCA_FQ_BUCKETS_LOG, q->fq_trees_log)) 744 nla_put_u32(skb, TCA_FQ_BUCKETS_LOG, q->fq_trees_log))
746 goto nla_put_failure; 745 goto nla_put_failure;
diff --git a/net/sched/sch_netem.c b/net/sched/sch_netem.c
index a6d788d45216..b87e83d07478 100644
--- a/net/sched/sch_netem.c
+++ b/net/sched/sch_netem.c
@@ -358,6 +358,21 @@ static psched_time_t packet_len_2_sched_time(unsigned int len, struct netem_sche
358 return PSCHED_NS2TICKS(ticks); 358 return PSCHED_NS2TICKS(ticks);
359} 359}
360 360
361static void tfifo_reset(struct Qdisc *sch)
362{
363 struct netem_sched_data *q = qdisc_priv(sch);
364 struct rb_node *p;
365
366 while ((p = rb_first(&q->t_root))) {
367 struct sk_buff *skb = netem_rb_to_skb(p);
368
369 rb_erase(p, &q->t_root);
370 skb->next = NULL;
371 skb->prev = NULL;
372 kfree_skb(skb);
373 }
374}
375
361static void tfifo_enqueue(struct sk_buff *nskb, struct Qdisc *sch) 376static void tfifo_enqueue(struct sk_buff *nskb, struct Qdisc *sch)
362{ 377{
363 struct netem_sched_data *q = qdisc_priv(sch); 378 struct netem_sched_data *q = qdisc_priv(sch);
@@ -520,6 +535,7 @@ static unsigned int netem_drop(struct Qdisc *sch)
520 skb->next = NULL; 535 skb->next = NULL;
521 skb->prev = NULL; 536 skb->prev = NULL;
522 len = qdisc_pkt_len(skb); 537 len = qdisc_pkt_len(skb);
538 sch->qstats.backlog -= len;
523 kfree_skb(skb); 539 kfree_skb(skb);
524 } 540 }
525 } 541 }
@@ -609,6 +625,7 @@ static void netem_reset(struct Qdisc *sch)
609 struct netem_sched_data *q = qdisc_priv(sch); 625 struct netem_sched_data *q = qdisc_priv(sch);
610 626
611 qdisc_reset_queue(sch); 627 qdisc_reset_queue(sch);
628 tfifo_reset(sch);
612 if (q->qdisc) 629 if (q->qdisc)
613 qdisc_reset(q->qdisc); 630 qdisc_reset(q->qdisc);
614 qdisc_watchdog_cancel(&q->watchdog); 631 qdisc_watchdog_cancel(&q->watchdog);
diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c
index e7b2d4fe2b6a..96a55910262c 100644
--- a/net/sctp/ipv6.c
+++ b/net/sctp/ipv6.c
@@ -279,7 +279,9 @@ static void sctp_v6_get_dst(struct sctp_transport *t, union sctp_addr *saddr,
279 sctp_v6_to_addr(&dst_saddr, &fl6->saddr, htons(bp->port)); 279 sctp_v6_to_addr(&dst_saddr, &fl6->saddr, htons(bp->port));
280 rcu_read_lock(); 280 rcu_read_lock();
281 list_for_each_entry_rcu(laddr, &bp->address_list, list) { 281 list_for_each_entry_rcu(laddr, &bp->address_list, list) {
282 if (!laddr->valid || (laddr->state != SCTP_ADDR_SRC)) 282 if (!laddr->valid || laddr->state == SCTP_ADDR_DEL ||
283 (laddr->state != SCTP_ADDR_SRC &&
284 !asoc->src_out_of_asoc_ok))
283 continue; 285 continue;
284 286
285 /* Do not compare against v4 addrs */ 287 /* Do not compare against v4 addrs */
diff --git a/net/sctp/output.c b/net/sctp/output.c
index 0ac3a65daccb..319137340d15 100644
--- a/net/sctp/output.c
+++ b/net/sctp/output.c
@@ -536,7 +536,8 @@ int sctp_packet_transmit(struct sctp_packet *packet)
536 * by CRC32-C as described in <draft-ietf-tsvwg-sctpcsum-02.txt>. 536 * by CRC32-C as described in <draft-ietf-tsvwg-sctpcsum-02.txt>.
537 */ 537 */
538 if (!sctp_checksum_disable) { 538 if (!sctp_checksum_disable) {
539 if (!(dst->dev->features & NETIF_F_SCTP_CSUM)) { 539 if (!(dst->dev->features & NETIF_F_SCTP_CSUM) ||
540 (dst_xfrm(dst) != NULL) || packet->ipfragok) {
540 __u32 crc32 = sctp_start_cksum((__u8 *)sh, cksum_buf_len); 541 __u32 crc32 = sctp_start_cksum((__u8 *)sh, cksum_buf_len);
541 542
542 /* 3) Put the resultant value into the checksum field in the 543 /* 3) Put the resultant value into the checksum field in the
diff --git a/net/sctp/sm_sideeffect.c b/net/sctp/sm_sideeffect.c
index 666c66842799..1a6eef39ab2f 100644
--- a/net/sctp/sm_sideeffect.c
+++ b/net/sctp/sm_sideeffect.c
@@ -860,7 +860,6 @@ static void sctp_cmd_delete_tcb(sctp_cmd_seq_t *cmds,
860 (!asoc->temp) && (sk->sk_shutdown != SHUTDOWN_MASK)) 860 (!asoc->temp) && (sk->sk_shutdown != SHUTDOWN_MASK))
861 return; 861 return;
862 862
863 BUG_ON(asoc->peer.primary_path == NULL);
864 sctp_unhash_established(asoc); 863 sctp_unhash_established(asoc);
865 sctp_association_free(asoc); 864 sctp_association_free(asoc);
866} 865}
diff --git a/net/socket.c b/net/socket.c
index ebed4b68f768..c226aceee65b 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -1964,6 +1964,16 @@ struct used_address {
1964 unsigned int name_len; 1964 unsigned int name_len;
1965}; 1965};
1966 1966
1967static int copy_msghdr_from_user(struct msghdr *kmsg,
1968 struct msghdr __user *umsg)
1969{
1970 if (copy_from_user(kmsg, umsg, sizeof(struct msghdr)))
1971 return -EFAULT;
1972 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
1973 return -EINVAL;
1974 return 0;
1975}
1976
1967static int ___sys_sendmsg(struct socket *sock, struct msghdr __user *msg, 1977static int ___sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
1968 struct msghdr *msg_sys, unsigned int flags, 1978 struct msghdr *msg_sys, unsigned int flags,
1969 struct used_address *used_address) 1979 struct used_address *used_address)
@@ -1982,8 +1992,11 @@ static int ___sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
1982 if (MSG_CMSG_COMPAT & flags) { 1992 if (MSG_CMSG_COMPAT & flags) {
1983 if (get_compat_msghdr(msg_sys, msg_compat)) 1993 if (get_compat_msghdr(msg_sys, msg_compat))
1984 return -EFAULT; 1994 return -EFAULT;
1985 } else if (copy_from_user(msg_sys, msg, sizeof(struct msghdr))) 1995 } else {
1986 return -EFAULT; 1996 err = copy_msghdr_from_user(msg_sys, msg);
1997 if (err)
1998 return err;
1999 }
1987 2000
1988 if (msg_sys->msg_iovlen > UIO_FASTIOV) { 2001 if (msg_sys->msg_iovlen > UIO_FASTIOV) {
1989 err = -EMSGSIZE; 2002 err = -EMSGSIZE;
@@ -2191,8 +2204,11 @@ static int ___sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
2191 if (MSG_CMSG_COMPAT & flags) { 2204 if (MSG_CMSG_COMPAT & flags) {
2192 if (get_compat_msghdr(msg_sys, msg_compat)) 2205 if (get_compat_msghdr(msg_sys, msg_compat))
2193 return -EFAULT; 2206 return -EFAULT;
2194 } else if (copy_from_user(msg_sys, msg, sizeof(struct msghdr))) 2207 } else {
2195 return -EFAULT; 2208 err = copy_msghdr_from_user(msg_sys, msg);
2209 if (err)
2210 return err;
2211 }
2196 2212
2197 if (msg_sys->msg_iovlen > UIO_FASTIOV) { 2213 if (msg_sys->msg_iovlen > UIO_FASTIOV) {
2198 err = -EMSGSIZE; 2214 err = -EMSGSIZE;
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index 86de99ad2976..c1f403bed683 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -1246,6 +1246,15 @@ static int unix_socketpair(struct socket *socka, struct socket *sockb)
1246 return 0; 1246 return 0;
1247} 1247}
1248 1248
1249static void unix_sock_inherit_flags(const struct socket *old,
1250 struct socket *new)
1251{
1252 if (test_bit(SOCK_PASSCRED, &old->flags))
1253 set_bit(SOCK_PASSCRED, &new->flags);
1254 if (test_bit(SOCK_PASSSEC, &old->flags))
1255 set_bit(SOCK_PASSSEC, &new->flags);
1256}
1257
1249static int unix_accept(struct socket *sock, struct socket *newsock, int flags) 1258static int unix_accept(struct socket *sock, struct socket *newsock, int flags)
1250{ 1259{
1251 struct sock *sk = sock->sk; 1260 struct sock *sk = sock->sk;
@@ -1280,6 +1289,7 @@ static int unix_accept(struct socket *sock, struct socket *newsock, int flags)
1280 /* attach accepted sock to socket */ 1289 /* attach accepted sock to socket */
1281 unix_state_lock(tsk); 1290 unix_state_lock(tsk);
1282 newsock->state = SS_CONNECTED; 1291 newsock->state = SS_CONNECTED;
1292 unix_sock_inherit_flags(sock, newsock);
1283 sock_graft(tsk, newsock); 1293 sock_graft(tsk, newsock);
1284 unix_state_unlock(tsk); 1294 unix_state_unlock(tsk);
1285 return 0; 1295 return 0;
diff --git a/net/unix/diag.c b/net/unix/diag.c
index d591091603bf..86fa0f3b2caf 100644
--- a/net/unix/diag.c
+++ b/net/unix/diag.c
@@ -124,6 +124,7 @@ static int sk_diag_fill(struct sock *sk, struct sk_buff *skb, struct unix_diag_r
124 rep->udiag_family = AF_UNIX; 124 rep->udiag_family = AF_UNIX;
125 rep->udiag_type = sk->sk_type; 125 rep->udiag_type = sk->sk_type;
126 rep->udiag_state = sk->sk_state; 126 rep->udiag_state = sk->sk_state;
127 rep->pad = 0;
127 rep->udiag_ino = sk_ino; 128 rep->udiag_ino = sk_ino;
128 sock_diag_save_cookie(sk, rep->udiag_cookie); 129 sock_diag_save_cookie(sk, rep->udiag_cookie);
129 130
diff --git a/net/wireless/core.c b/net/wireless/core.c
index 67153964aad2..aff959e5a1b3 100644
--- a/net/wireless/core.c
+++ b/net/wireless/core.c
@@ -566,18 +566,13 @@ int wiphy_register(struct wiphy *wiphy)
566 /* check and set up bitrates */ 566 /* check and set up bitrates */
567 ieee80211_set_bitrate_flags(wiphy); 567 ieee80211_set_bitrate_flags(wiphy);
568 568
569 569 rtnl_lock();
570 res = device_add(&rdev->wiphy.dev); 570 res = device_add(&rdev->wiphy.dev);
571 if (res)
572 return res;
573
574 res = rfkill_register(rdev->rfkill);
575 if (res) { 571 if (res) {
576 device_del(&rdev->wiphy.dev); 572 rtnl_unlock();
577 return res; 573 return res;
578 } 574 }
579 575
580 rtnl_lock();
581 /* set up regulatory info */ 576 /* set up regulatory info */
582 wiphy_regulatory_register(wiphy); 577 wiphy_regulatory_register(wiphy);
583 578
@@ -606,6 +601,15 @@ int wiphy_register(struct wiphy *wiphy)
606 601
607 rdev->wiphy.registered = true; 602 rdev->wiphy.registered = true;
608 rtnl_unlock(); 603 rtnl_unlock();
604
605 res = rfkill_register(rdev->rfkill);
606 if (res) {
607 rfkill_destroy(rdev->rfkill);
608 rdev->rfkill = NULL;
609 wiphy_unregister(&rdev->wiphy);
610 return res;
611 }
612
609 return 0; 613 return 0;
610} 614}
611EXPORT_SYMBOL(wiphy_register); 615EXPORT_SYMBOL(wiphy_register);
@@ -640,7 +644,8 @@ void wiphy_unregister(struct wiphy *wiphy)
640 rtnl_unlock(); 644 rtnl_unlock();
641 __count == 0; })); 645 __count == 0; }));
642 646
643 rfkill_unregister(rdev->rfkill); 647 if (rdev->rfkill)
648 rfkill_unregister(rdev->rfkill);
644 649
645 rtnl_lock(); 650 rtnl_lock();
646 rdev->wiphy.registered = false; 651 rdev->wiphy.registered = false;
@@ -953,8 +958,6 @@ static int cfg80211_netdev_notifier_call(struct notifier_block *nb,
953 case NETDEV_PRE_UP: 958 case NETDEV_PRE_UP:
954 if (!(wdev->wiphy->interface_modes & BIT(wdev->iftype))) 959 if (!(wdev->wiphy->interface_modes & BIT(wdev->iftype)))
955 return notifier_from_errno(-EOPNOTSUPP); 960 return notifier_from_errno(-EOPNOTSUPP);
956 if (rfkill_blocked(rdev->rfkill))
957 return notifier_from_errno(-ERFKILL);
958 ret = cfg80211_can_add_interface(rdev, wdev->iftype); 961 ret = cfg80211_can_add_interface(rdev, wdev->iftype);
959 if (ret) 962 if (ret)
960 return notifier_from_errno(ret); 963 return notifier_from_errno(ret);
diff --git a/net/wireless/core.h b/net/wireless/core.h
index 9ad43c619c54..3159e9c284c5 100644
--- a/net/wireless/core.h
+++ b/net/wireless/core.h
@@ -411,6 +411,9 @@ static inline int
411cfg80211_can_add_interface(struct cfg80211_registered_device *rdev, 411cfg80211_can_add_interface(struct cfg80211_registered_device *rdev,
412 enum nl80211_iftype iftype) 412 enum nl80211_iftype iftype)
413{ 413{
414 if (rfkill_blocked(rdev->rfkill))
415 return -ERFKILL;
416
414 return cfg80211_can_change_interface(rdev, NULL, iftype); 417 return cfg80211_can_change_interface(rdev, NULL, iftype);
415} 418}
416 419
diff --git a/net/wireless/ibss.c b/net/wireless/ibss.c
index 39bff7d36768..403fe29c024d 100644
--- a/net/wireless/ibss.c
+++ b/net/wireless/ibss.c
@@ -263,6 +263,8 @@ int cfg80211_ibss_wext_join(struct cfg80211_registered_device *rdev,
263 if (chan->flags & IEEE80211_CHAN_DISABLED) 263 if (chan->flags & IEEE80211_CHAN_DISABLED)
264 continue; 264 continue;
265 wdev->wext.ibss.chandef.chan = chan; 265 wdev->wext.ibss.chandef.chan = chan;
266 wdev->wext.ibss.chandef.center_freq1 =
267 chan->center_freq;
266 break; 268 break;
267 } 269 }
268 270
@@ -347,6 +349,7 @@ int cfg80211_ibss_wext_siwfreq(struct net_device *dev,
347 if (chan) { 349 if (chan) {
348 wdev->wext.ibss.chandef.chan = chan; 350 wdev->wext.ibss.chandef.chan = chan;
349 wdev->wext.ibss.chandef.width = NL80211_CHAN_WIDTH_20_NOHT; 351 wdev->wext.ibss.chandef.width = NL80211_CHAN_WIDTH_20_NOHT;
352 wdev->wext.ibss.chandef.center_freq1 = freq;
350 wdev->wext.ibss.channel_fixed = true; 353 wdev->wext.ibss.channel_fixed = true;
351 } else { 354 } else {
352 /* cfg80211_ibss_wext_join will pick one if needed */ 355 /* cfg80211_ibss_wext_join will pick one if needed */
diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
index af8d84a4a5b2..626dc3b5fd8d 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -2421,7 +2421,7 @@ static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2421 change = true; 2421 change = true;
2422 } 2422 }
2423 2423
2424 if (flags && (*flags & NL80211_MNTR_FLAG_ACTIVE) && 2424 if (flags && (*flags & MONITOR_FLAG_ACTIVE) &&
2425 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) 2425 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2426 return -EOPNOTSUPP; 2426 return -EOPNOTSUPP;
2427 2427
@@ -2483,7 +2483,7 @@ static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2483 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, 2483 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2484 &flags); 2484 &flags);
2485 2485
2486 if (!err && (flags & NL80211_MNTR_FLAG_ACTIVE) && 2486 if (!err && (flags & MONITOR_FLAG_ACTIVE) &&
2487 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) 2487 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2488 return -EOPNOTSUPP; 2488 return -EOPNOTSUPP;
2489 2489
diff --git a/net/wireless/radiotap.c b/net/wireless/radiotap.c
index 7d604c06c3dc..a271c27fac77 100644
--- a/net/wireless/radiotap.c
+++ b/net/wireless/radiotap.c
@@ -97,6 +97,10 @@ int ieee80211_radiotap_iterator_init(
97 struct ieee80211_radiotap_header *radiotap_header, 97 struct ieee80211_radiotap_header *radiotap_header,
98 int max_length, const struct ieee80211_radiotap_vendor_namespaces *vns) 98 int max_length, const struct ieee80211_radiotap_vendor_namespaces *vns)
99{ 99{
100 /* check the radiotap header can actually be present */
101 if (max_length < sizeof(struct ieee80211_radiotap_header))
102 return -EINVAL;
103
100 /* Linux only supports version 0 radiotap format */ 104 /* Linux only supports version 0 radiotap format */
101 if (radiotap_header->it_version) 105 if (radiotap_header->it_version)
102 return -EINVAL; 106 return -EINVAL;
@@ -131,7 +135,8 @@ int ieee80211_radiotap_iterator_init(
131 */ 135 */
132 136
133 if ((unsigned long)iterator->_arg - 137 if ((unsigned long)iterator->_arg -
134 (unsigned long)iterator->_rtheader > 138 (unsigned long)iterator->_rtheader +
139 sizeof(uint32_t) >
135 (unsigned long)iterator->_max_length) 140 (unsigned long)iterator->_max_length)
136 return -EINVAL; 141 return -EINVAL;
137 } 142 }
diff --git a/net/x25/Kconfig b/net/x25/Kconfig
index c959312c45e3..e2fa133f9fba 100644
--- a/net/x25/Kconfig
+++ b/net/x25/Kconfig
@@ -16,8 +16,8 @@ config X25
16 if you want that) and the lower level data link layer protocol LAPB 16 if you want that) and the lower level data link layer protocol LAPB
17 (say Y to "LAPB Data Link Driver" below if you want that). 17 (say Y to "LAPB Data Link Driver" below if you want that).
18 18
19 You can read more about X.25 at <http://www.sangoma.com/x25.htm> and 19 You can read more about X.25 at <http://www.sangoma.com/tutorials/x25/> and
20 <http://www.cisco.com/univercd/cc/td/doc/product/software/ios11/cbook/cx25.htm>. 20 <http://docwiki.cisco.com/wiki/X.25>.
21 Information about X.25 for Linux is contained in the files 21 Information about X.25 for Linux is contained in the files
22 <file:Documentation/networking/x25.txt> and 22 <file:Documentation/networking/x25.txt> and
23 <file:Documentation/networking/x25-iface.txt>. 23 <file:Documentation/networking/x25-iface.txt>.
diff --git a/net/xfrm/xfrm_ipcomp.c b/net/xfrm/xfrm_ipcomp.c
index 2906d520eea7..3be02b680268 100644
--- a/net/xfrm/xfrm_ipcomp.c
+++ b/net/xfrm/xfrm_ipcomp.c
@@ -141,14 +141,14 @@ static int ipcomp_compress(struct xfrm_state *x, struct sk_buff *skb)
141 const int plen = skb->len; 141 const int plen = skb->len;
142 int dlen = IPCOMP_SCRATCH_SIZE; 142 int dlen = IPCOMP_SCRATCH_SIZE;
143 u8 *start = skb->data; 143 u8 *start = skb->data;
144 const int cpu = get_cpu(); 144 struct crypto_comp *tfm;
145 u8 *scratch = *per_cpu_ptr(ipcomp_scratches, cpu); 145 u8 *scratch;
146 struct crypto_comp *tfm = *per_cpu_ptr(ipcd->tfms, cpu);
147 int err; 146 int err;
148 147
149 local_bh_disable(); 148 local_bh_disable();
149 scratch = *this_cpu_ptr(ipcomp_scratches);
150 tfm = *this_cpu_ptr(ipcd->tfms);
150 err = crypto_comp_compress(tfm, start, plen, scratch, &dlen); 151 err = crypto_comp_compress(tfm, start, plen, scratch, &dlen);
151 local_bh_enable();
152 if (err) 152 if (err)
153 goto out; 153 goto out;
154 154
@@ -158,13 +158,13 @@ static int ipcomp_compress(struct xfrm_state *x, struct sk_buff *skb)
158 } 158 }
159 159
160 memcpy(start + sizeof(struct ip_comp_hdr), scratch, dlen); 160 memcpy(start + sizeof(struct ip_comp_hdr), scratch, dlen);
161 put_cpu(); 161 local_bh_enable();
162 162
163 pskb_trim(skb, dlen + sizeof(struct ip_comp_hdr)); 163 pskb_trim(skb, dlen + sizeof(struct ip_comp_hdr));
164 return 0; 164 return 0;
165 165
166out: 166out:
167 put_cpu(); 167 local_bh_enable();
168 return err; 168 return err;
169} 169}
170 170
diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
index ed38d5d81f9e..76e1873811d4 100644
--- a/net/xfrm/xfrm_policy.c
+++ b/net/xfrm/xfrm_policy.c
@@ -334,7 +334,8 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
334 334
335 atomic_inc(&policy->genid); 335 atomic_inc(&policy->genid);
336 336
337 del_timer(&policy->polq.hold_timer); 337 if (del_timer(&policy->polq.hold_timer))
338 xfrm_pol_put(policy);
338 xfrm_queue_purge(&policy->polq.hold_queue); 339 xfrm_queue_purge(&policy->polq.hold_queue);
339 340
340 if (del_timer(&policy->timer)) 341 if (del_timer(&policy->timer))
@@ -589,7 +590,8 @@ static void xfrm_policy_requeue(struct xfrm_policy *old,
589 590
590 spin_lock_bh(&pq->hold_queue.lock); 591 spin_lock_bh(&pq->hold_queue.lock);
591 skb_queue_splice_init(&pq->hold_queue, &list); 592 skb_queue_splice_init(&pq->hold_queue, &list);
592 del_timer(&pq->hold_timer); 593 if (del_timer(&pq->hold_timer))
594 xfrm_pol_put(old);
593 spin_unlock_bh(&pq->hold_queue.lock); 595 spin_unlock_bh(&pq->hold_queue.lock);
594 596
595 if (skb_queue_empty(&list)) 597 if (skb_queue_empty(&list))
@@ -600,7 +602,8 @@ static void xfrm_policy_requeue(struct xfrm_policy *old,
600 spin_lock_bh(&pq->hold_queue.lock); 602 spin_lock_bh(&pq->hold_queue.lock);
601 skb_queue_splice(&list, &pq->hold_queue); 603 skb_queue_splice(&list, &pq->hold_queue);
602 pq->timeout = XFRM_QUEUE_TMO_MIN; 604 pq->timeout = XFRM_QUEUE_TMO_MIN;
603 mod_timer(&pq->hold_timer, jiffies); 605 if (!mod_timer(&pq->hold_timer, jiffies))
606 xfrm_pol_hold(new);
604 spin_unlock_bh(&pq->hold_queue.lock); 607 spin_unlock_bh(&pq->hold_queue.lock);
605} 608}
606 609
@@ -1769,6 +1772,10 @@ static void xfrm_policy_queue_process(unsigned long arg)
1769 1772
1770 spin_lock(&pq->hold_queue.lock); 1773 spin_lock(&pq->hold_queue.lock);
1771 skb = skb_peek(&pq->hold_queue); 1774 skb = skb_peek(&pq->hold_queue);
1775 if (!skb) {
1776 spin_unlock(&pq->hold_queue.lock);
1777 goto out;
1778 }
1772 dst = skb_dst(skb); 1779 dst = skb_dst(skb);
1773 sk = skb->sk; 1780 sk = skb->sk;
1774 xfrm_decode_session(skb, &fl, dst->ops->family); 1781 xfrm_decode_session(skb, &fl, dst->ops->family);
@@ -1787,8 +1794,9 @@ static void xfrm_policy_queue_process(unsigned long arg)
1787 goto purge_queue; 1794 goto purge_queue;
1788 1795
1789 pq->timeout = pq->timeout << 1; 1796 pq->timeout = pq->timeout << 1;
1790 mod_timer(&pq->hold_timer, jiffies + pq->timeout); 1797 if (!mod_timer(&pq->hold_timer, jiffies + pq->timeout))
1791 return; 1798 xfrm_pol_hold(pol);
1799 goto out;
1792 } 1800 }
1793 1801
1794 dst_release(dst); 1802 dst_release(dst);
@@ -1819,11 +1827,14 @@ static void xfrm_policy_queue_process(unsigned long arg)
1819 err = dst_output(skb); 1827 err = dst_output(skb);
1820 } 1828 }
1821 1829
1830out:
1831 xfrm_pol_put(pol);
1822 return; 1832 return;
1823 1833
1824purge_queue: 1834purge_queue:
1825 pq->timeout = 0; 1835 pq->timeout = 0;
1826 xfrm_queue_purge(&pq->hold_queue); 1836 xfrm_queue_purge(&pq->hold_queue);
1837 xfrm_pol_put(pol);
1827} 1838}
1828 1839
1829static int xdst_queue_output(struct sk_buff *skb) 1840static int xdst_queue_output(struct sk_buff *skb)
@@ -1831,7 +1842,8 @@ static int xdst_queue_output(struct sk_buff *skb)
1831 unsigned long sched_next; 1842 unsigned long sched_next;
1832 struct dst_entry *dst = skb_dst(skb); 1843 struct dst_entry *dst = skb_dst(skb);
1833 struct xfrm_dst *xdst = (struct xfrm_dst *) dst; 1844 struct xfrm_dst *xdst = (struct xfrm_dst *) dst;
1834 struct xfrm_policy_queue *pq = &xdst->pols[0]->polq; 1845 struct xfrm_policy *pol = xdst->pols[0];
1846 struct xfrm_policy_queue *pq = &pol->polq;
1835 1847
1836 if (pq->hold_queue.qlen > XFRM_MAX_QUEUE_LEN) { 1848 if (pq->hold_queue.qlen > XFRM_MAX_QUEUE_LEN) {
1837 kfree_skb(skb); 1849 kfree_skb(skb);
@@ -1850,10 +1862,12 @@ static int xdst_queue_output(struct sk_buff *skb)
1850 if (del_timer(&pq->hold_timer)) { 1862 if (del_timer(&pq->hold_timer)) {
1851 if (time_before(pq->hold_timer.expires, sched_next)) 1863 if (time_before(pq->hold_timer.expires, sched_next))
1852 sched_next = pq->hold_timer.expires; 1864 sched_next = pq->hold_timer.expires;
1865 xfrm_pol_put(pol);
1853 } 1866 }
1854 1867
1855 __skb_queue_tail(&pq->hold_queue, skb); 1868 __skb_queue_tail(&pq->hold_queue, skb);
1856 mod_timer(&pq->hold_timer, sched_next); 1869 if (!mod_timer(&pq->hold_timer, sched_next))
1870 xfrm_pol_hold(pol);
1857 1871
1858 spin_unlock_bh(&pq->hold_queue.lock); 1872 spin_unlock_bh(&pq->hold_queue.lock);
1859 1873
diff --git a/net/xfrm/xfrm_replay.c b/net/xfrm/xfrm_replay.c
index 8dafe6d3c6e4..dab57daae408 100644
--- a/net/xfrm/xfrm_replay.c
+++ b/net/xfrm/xfrm_replay.c
@@ -61,9 +61,9 @@ static void xfrm_replay_notify(struct xfrm_state *x, int event)
61 61
62 switch (event) { 62 switch (event) {
63 case XFRM_REPLAY_UPDATE: 63 case XFRM_REPLAY_UPDATE:
64 if (x->replay_maxdiff && 64 if (!x->replay_maxdiff ||
65 (x->replay.seq - x->preplay.seq < x->replay_maxdiff) && 65 ((x->replay.seq - x->preplay.seq < x->replay_maxdiff) &&
66 (x->replay.oseq - x->preplay.oseq < x->replay_maxdiff)) { 66 (x->replay.oseq - x->preplay.oseq < x->replay_maxdiff))) {
67 if (x->xflags & XFRM_TIME_DEFER) 67 if (x->xflags & XFRM_TIME_DEFER)
68 event = XFRM_REPLAY_TIMEOUT; 68 event = XFRM_REPLAY_TIMEOUT;
69 else 69 else
@@ -129,8 +129,7 @@ static int xfrm_replay_check(struct xfrm_state *x,
129 return 0; 129 return 0;
130 130
131 diff = x->replay.seq - seq; 131 diff = x->replay.seq - seq;
132 if (diff >= min_t(unsigned int, x->props.replay_window, 132 if (diff >= x->props.replay_window) {
133 sizeof(x->replay.bitmap) * 8)) {
134 x->stats.replay_window++; 133 x->stats.replay_window++;
135 goto err; 134 goto err;
136 } 135 }
@@ -302,9 +301,10 @@ static void xfrm_replay_notify_bmp(struct xfrm_state *x, int event)
302 301
303 switch (event) { 302 switch (event) {
304 case XFRM_REPLAY_UPDATE: 303 case XFRM_REPLAY_UPDATE:
305 if (x->replay_maxdiff && 304 if (!x->replay_maxdiff ||
306 (replay_esn->seq - preplay_esn->seq < x->replay_maxdiff) && 305 ((replay_esn->seq - preplay_esn->seq < x->replay_maxdiff) &&
307 (replay_esn->oseq - preplay_esn->oseq < x->replay_maxdiff)) { 306 (replay_esn->oseq - preplay_esn->oseq
307 < x->replay_maxdiff))) {
308 if (x->xflags & XFRM_TIME_DEFER) 308 if (x->xflags & XFRM_TIME_DEFER)
309 event = XFRM_REPLAY_TIMEOUT; 309 event = XFRM_REPLAY_TIMEOUT;
310 else 310 else
@@ -353,28 +353,30 @@ static void xfrm_replay_notify_esn(struct xfrm_state *x, int event)
353 353
354 switch (event) { 354 switch (event) {
355 case XFRM_REPLAY_UPDATE: 355 case XFRM_REPLAY_UPDATE:
356 if (!x->replay_maxdiff) 356 if (x->replay_maxdiff) {
357 break; 357 if (replay_esn->seq_hi == preplay_esn->seq_hi)
358 358 seq_diff = replay_esn->seq - preplay_esn->seq;
359 if (replay_esn->seq_hi == preplay_esn->seq_hi) 359 else
360 seq_diff = replay_esn->seq - preplay_esn->seq; 360 seq_diff = ~preplay_esn->seq + replay_esn->seq
361 else 361 + 1;
362 seq_diff = ~preplay_esn->seq + replay_esn->seq + 1;
363
364 if (replay_esn->oseq_hi == preplay_esn->oseq_hi)
365 oseq_diff = replay_esn->oseq - preplay_esn->oseq;
366 else
367 oseq_diff = ~preplay_esn->oseq + replay_esn->oseq + 1;
368
369 if (seq_diff < x->replay_maxdiff &&
370 oseq_diff < x->replay_maxdiff) {
371 362
372 if (x->xflags & XFRM_TIME_DEFER) 363 if (replay_esn->oseq_hi == preplay_esn->oseq_hi)
373 event = XFRM_REPLAY_TIMEOUT; 364 oseq_diff = replay_esn->oseq
365 - preplay_esn->oseq;
374 else 366 else
375 return; 367 oseq_diff = ~preplay_esn->oseq
368 + replay_esn->oseq + 1;
369
370 if (seq_diff >= x->replay_maxdiff ||
371 oseq_diff >= x->replay_maxdiff)
372 break;
376 } 373 }
377 374
375 if (x->xflags & XFRM_TIME_DEFER)
376 event = XFRM_REPLAY_TIMEOUT;
377 else
378 return;
379
378 break; 380 break;
379 381
380 case XFRM_REPLAY_TIMEOUT: 382 case XFRM_REPLAY_TIMEOUT:
diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c
index 3f565e495ac6..f964d4c00ffb 100644
--- a/net/xfrm/xfrm_user.c
+++ b/net/xfrm/xfrm_user.c
@@ -446,7 +446,8 @@ static void copy_from_user_state(struct xfrm_state *x, struct xfrm_usersa_info *
446 memcpy(&x->sel, &p->sel, sizeof(x->sel)); 446 memcpy(&x->sel, &p->sel, sizeof(x->sel));
447 memcpy(&x->lft, &p->lft, sizeof(x->lft)); 447 memcpy(&x->lft, &p->lft, sizeof(x->lft));
448 x->props.mode = p->mode; 448 x->props.mode = p->mode;
449 x->props.replay_window = p->replay_window; 449 x->props.replay_window = min_t(unsigned int, p->replay_window,
450 sizeof(x->replay.bitmap) * 8);
450 x->props.reqid = p->reqid; 451 x->props.reqid = p->reqid;
451 x->props.family = p->family; 452 x->props.family = p->family;
452 memcpy(&x->props.saddr, &p->saddr, sizeof(x->props.saddr)); 453 memcpy(&x->props.saddr, &p->saddr, sizeof(x->props.saddr));
@@ -1856,7 +1857,7 @@ static int xfrm_new_ae(struct sk_buff *skb, struct nlmsghdr *nlh,
1856 if (x->km.state != XFRM_STATE_VALID) 1857 if (x->km.state != XFRM_STATE_VALID)
1857 goto out; 1858 goto out;
1858 1859
1859 err = xfrm_replay_verify_len(x->replay_esn, rp); 1860 err = xfrm_replay_verify_len(x->replay_esn, re);
1860 if (err) 1861 if (err)
1861 goto out; 1862 goto out;
1862 1863
diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c
index 487ac6f37ca2..9a11f9f799f4 100644
--- a/scripts/kallsyms.c
+++ b/scripts/kallsyms.c
@@ -55,6 +55,7 @@ static struct sym_entry *table;
55static unsigned int table_size, table_cnt; 55static unsigned int table_size, table_cnt;
56static int all_symbols = 0; 56static int all_symbols = 0;
57static char symbol_prefix_char = '\0'; 57static char symbol_prefix_char = '\0';
58static unsigned long long kernel_start_addr = 0;
58 59
59int token_profit[0x10000]; 60int token_profit[0x10000];
60 61
@@ -65,7 +66,10 @@ unsigned char best_table_len[256];
65 66
66static void usage(void) 67static void usage(void)
67{ 68{
68 fprintf(stderr, "Usage: kallsyms [--all-symbols] [--symbol-prefix=<prefix char>] < in.map > out.S\n"); 69 fprintf(stderr, "Usage: kallsyms [--all-symbols] "
70 "[--symbol-prefix=<prefix char>] "
71 "[--page-offset=<CONFIG_PAGE_OFFSET>] "
72 "< in.map > out.S\n");
69 exit(1); 73 exit(1);
70} 74}
71 75
@@ -194,6 +198,9 @@ static int symbol_valid(struct sym_entry *s)
194 int i; 198 int i;
195 int offset = 1; 199 int offset = 1;
196 200
201 if (s->addr < kernel_start_addr)
202 return 0;
203
197 /* skip prefix char */ 204 /* skip prefix char */
198 if (symbol_prefix_char && *(s->sym + 1) == symbol_prefix_char) 205 if (symbol_prefix_char && *(s->sym + 1) == symbol_prefix_char)
199 offset++; 206 offset++;
@@ -646,6 +653,9 @@ int main(int argc, char **argv)
646 if ((*p == '"' && *(p+2) == '"') || (*p == '\'' && *(p+2) == '\'')) 653 if ((*p == '"' && *(p+2) == '"') || (*p == '\'' && *(p+2) == '\''))
647 p++; 654 p++;
648 symbol_prefix_char = *p; 655 symbol_prefix_char = *p;
656 } else if (strncmp(argv[i], "--page-offset=", 14) == 0) {
657 const char *p = &argv[i][14];
658 kernel_start_addr = strtoull(p, NULL, 16);
649 } else 659 } else
650 usage(); 660 usage();
651 } 661 }
diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
index 014994936b1c..32b10f53d0b4 100644
--- a/scripts/link-vmlinux.sh
+++ b/scripts/link-vmlinux.sh
@@ -82,6 +82,8 @@ kallsyms()
82 kallsymopt="${kallsymopt} --all-symbols" 82 kallsymopt="${kallsymopt} --all-symbols"
83 fi 83 fi
84 84
85 kallsymopt="${kallsymopt} --page-offset=$CONFIG_PAGE_OFFSET"
86
85 local aflags="${KBUILD_AFLAGS} ${KBUILD_AFLAGS_KERNEL} \ 87 local aflags="${KBUILD_AFLAGS} ${KBUILD_AFLAGS_KERNEL} \
86 ${NOSTDINC_FLAGS} ${LINUXINCLUDE} ${KBUILD_CPPFLAGS}" 88 ${NOSTDINC_FLAGS} ${LINUXINCLUDE} ${KBUILD_CPPFLAGS}"
87 89
diff --git a/sound/core/pcm.c b/sound/core/pcm.c
index 17f45e8aa89c..e1e9e0c999fe 100644
--- a/sound/core/pcm.c
+++ b/sound/core/pcm.c
@@ -49,6 +49,8 @@ static struct snd_pcm *snd_pcm_get(struct snd_card *card, int device)
49 struct snd_pcm *pcm; 49 struct snd_pcm *pcm;
50 50
51 list_for_each_entry(pcm, &snd_pcm_devices, list) { 51 list_for_each_entry(pcm, &snd_pcm_devices, list) {
52 if (pcm->internal)
53 continue;
52 if (pcm->card == card && pcm->device == device) 54 if (pcm->card == card && pcm->device == device)
53 return pcm; 55 return pcm;
54 } 56 }
@@ -60,6 +62,8 @@ static int snd_pcm_next(struct snd_card *card, int device)
60 struct snd_pcm *pcm; 62 struct snd_pcm *pcm;
61 63
62 list_for_each_entry(pcm, &snd_pcm_devices, list) { 64 list_for_each_entry(pcm, &snd_pcm_devices, list) {
65 if (pcm->internal)
66 continue;
63 if (pcm->card == card && pcm->device > device) 67 if (pcm->card == card && pcm->device > device)
64 return pcm->device; 68 return pcm->device;
65 else if (pcm->card->number > card->number) 69 else if (pcm->card->number > card->number)
diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
index 5b6c4e3c92ca..748c6a941963 100644
--- a/sound/pci/hda/hda_codec.c
+++ b/sound/pci/hda/hda_codec.c
@@ -4864,8 +4864,8 @@ static void hda_power_work(struct work_struct *work)
4864 spin_unlock(&codec->power_lock); 4864 spin_unlock(&codec->power_lock);
4865 4865
4866 state = hda_call_codec_suspend(codec, true); 4866 state = hda_call_codec_suspend(codec, true);
4867 codec->pm_down_notified = 0; 4867 if (!codec->pm_down_notified &&
4868 if (!bus->power_keep_link_on && (state & AC_PWRST_CLK_STOP_OK)) { 4868 !bus->power_keep_link_on && (state & AC_PWRST_CLK_STOP_OK)) {
4869 codec->pm_down_notified = 1; 4869 codec->pm_down_notified = 1;
4870 hda_call_pm_notify(bus, false); 4870 hda_call_pm_notify(bus, false);
4871 } 4871 }
diff --git a/sound/pci/hda/hda_generic.c b/sound/pci/hda/hda_generic.c
index 26ad4f0aade3..b7c89dff7066 100644
--- a/sound/pci/hda/hda_generic.c
+++ b/sound/pci/hda/hda_generic.c
@@ -4475,9 +4475,11 @@ int snd_hda_gen_build_controls(struct hda_codec *codec)
4475 true, &spec->vmaster_mute.sw_kctl); 4475 true, &spec->vmaster_mute.sw_kctl);
4476 if (err < 0) 4476 if (err < 0)
4477 return err; 4477 return err;
4478 if (spec->vmaster_mute.hook) 4478 if (spec->vmaster_mute.hook) {
4479 snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, 4479 snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute,
4480 spec->vmaster_mute_enum); 4480 spec->vmaster_mute_enum);
4481 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
4482 }
4481 } 4483 }
4482 4484
4483 free_kctls(spec); /* no longer needed */ 4485 free_kctls(spec); /* no longer needed */
diff --git a/sound/pci/hda/patch_analog.c b/sound/pci/hda/patch_analog.c
index 0cbdd87dde6d..2aa2f579b4d6 100644
--- a/sound/pci/hda/patch_analog.c
+++ b/sound/pci/hda/patch_analog.c
@@ -968,6 +968,15 @@ static void ad1884_fixup_hp_eapd(struct hda_codec *codec,
968 } 968 }
969} 969}
970 970
971static void ad1884_fixup_thinkpad(struct hda_codec *codec,
972 const struct hda_fixup *fix, int action)
973{
974 struct ad198x_spec *spec = codec->spec;
975
976 if (action == HDA_FIXUP_ACT_PRE_PROBE)
977 spec->gen.keep_eapd_on = 1;
978}
979
971/* set magic COEFs for dmic */ 980/* set magic COEFs for dmic */
972static const struct hda_verb ad1884_dmic_init_verbs[] = { 981static const struct hda_verb ad1884_dmic_init_verbs[] = {
973 {0x01, AC_VERB_SET_COEF_INDEX, 0x13f7}, 982 {0x01, AC_VERB_SET_COEF_INDEX, 0x13f7},
@@ -979,6 +988,7 @@ enum {
979 AD1884_FIXUP_AMP_OVERRIDE, 988 AD1884_FIXUP_AMP_OVERRIDE,
980 AD1884_FIXUP_HP_EAPD, 989 AD1884_FIXUP_HP_EAPD,
981 AD1884_FIXUP_DMIC_COEF, 990 AD1884_FIXUP_DMIC_COEF,
991 AD1884_FIXUP_THINKPAD,
982 AD1884_FIXUP_HP_TOUCHSMART, 992 AD1884_FIXUP_HP_TOUCHSMART,
983}; 993};
984 994
@@ -997,6 +1007,12 @@ static const struct hda_fixup ad1884_fixups[] = {
997 .type = HDA_FIXUP_VERBS, 1007 .type = HDA_FIXUP_VERBS,
998 .v.verbs = ad1884_dmic_init_verbs, 1008 .v.verbs = ad1884_dmic_init_verbs,
999 }, 1009 },
1010 [AD1884_FIXUP_THINKPAD] = {
1011 .type = HDA_FIXUP_FUNC,
1012 .v.func = ad1884_fixup_thinkpad,
1013 .chained = true,
1014 .chain_id = AD1884_FIXUP_DMIC_COEF,
1015 },
1000 [AD1884_FIXUP_HP_TOUCHSMART] = { 1016 [AD1884_FIXUP_HP_TOUCHSMART] = {
1001 .type = HDA_FIXUP_VERBS, 1017 .type = HDA_FIXUP_VERBS,
1002 .v.verbs = ad1884_dmic_init_verbs, 1018 .v.verbs = ad1884_dmic_init_verbs,
@@ -1008,7 +1024,7 @@ static const struct hda_fixup ad1884_fixups[] = {
1008static const struct snd_pci_quirk ad1884_fixup_tbl[] = { 1024static const struct snd_pci_quirk ad1884_fixup_tbl[] = {
1009 SND_PCI_QUIRK(0x103c, 0x2a82, "HP Touchsmart", AD1884_FIXUP_HP_TOUCHSMART), 1025 SND_PCI_QUIRK(0x103c, 0x2a82, "HP Touchsmart", AD1884_FIXUP_HP_TOUCHSMART),
1010 SND_PCI_QUIRK_VENDOR(0x103c, "HP", AD1884_FIXUP_HP_EAPD), 1026 SND_PCI_QUIRK_VENDOR(0x103c, "HP", AD1884_FIXUP_HP_EAPD),
1011 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo Thinkpad", AD1884_FIXUP_DMIC_COEF), 1027 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo Thinkpad", AD1884_FIXUP_THINKPAD),
1012 {} 1028 {}
1013}; 1029};
1014 1030
diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
index bf313bea7085..8ad554312b69 100644
--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -4623,6 +4623,7 @@ static const struct snd_pci_quirk alc662_fixup_tbl[] = {
4623 SND_PCI_QUIRK(0x1028, 0x05db, "Dell", ALC668_FIXUP_DELL_MIC_NO_PRESENCE), 4623 SND_PCI_QUIRK(0x1028, 0x05db, "Dell", ALC668_FIXUP_DELL_MIC_NO_PRESENCE),
4624 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800), 4624 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
4625 SND_PCI_QUIRK(0x1043, 0x1477, "ASUS N56VZ", ALC662_FIXUP_ASUS_MODE4), 4625 SND_PCI_QUIRK(0x1043, 0x1477, "ASUS N56VZ", ALC662_FIXUP_ASUS_MODE4),
4626 SND_PCI_QUIRK(0x1043, 0x1bf3, "ASUS N76VZ", ALC662_FIXUP_ASUS_MODE4),
4626 SND_PCI_QUIRK(0x1043, 0x8469, "ASUS mobo", ALC662_FIXUP_NO_JACK_DETECT), 4627 SND_PCI_QUIRK(0x1043, 0x8469, "ASUS mobo", ALC662_FIXUP_NO_JACK_DETECT),
4627 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2), 4628 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
4628 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD), 4629 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
diff --git a/sound/soc/codecs/pcm1681.c b/sound/soc/codecs/pcm1681.c
index 651ce0923675..c91eba504f92 100644
--- a/sound/soc/codecs/pcm1681.c
+++ b/sound/soc/codecs/pcm1681.c
@@ -270,7 +270,7 @@ MODULE_DEVICE_TABLE(of, pcm1681_dt_ids);
270static const struct regmap_config pcm1681_regmap = { 270static const struct regmap_config pcm1681_regmap = {
271 .reg_bits = 8, 271 .reg_bits = 8,
272 .val_bits = 8, 272 .val_bits = 8,
273 .max_register = ARRAY_SIZE(pcm1681_reg_defaults) + 1, 273 .max_register = 0x13,
274 .reg_defaults = pcm1681_reg_defaults, 274 .reg_defaults = pcm1681_reg_defaults,
275 .num_reg_defaults = ARRAY_SIZE(pcm1681_reg_defaults), 275 .num_reg_defaults = ARRAY_SIZE(pcm1681_reg_defaults),
276 .writeable_reg = pcm1681_writeable_reg, 276 .writeable_reg = pcm1681_writeable_reg,
diff --git a/sound/soc/codecs/pcm1792a.c b/sound/soc/codecs/pcm1792a.c
index 2a8eccf64c76..7613181123fe 100644
--- a/sound/soc/codecs/pcm1792a.c
+++ b/sound/soc/codecs/pcm1792a.c
@@ -188,7 +188,7 @@ MODULE_DEVICE_TABLE(of, pcm1792a_of_match);
188static const struct regmap_config pcm1792a_regmap = { 188static const struct regmap_config pcm1792a_regmap = {
189 .reg_bits = 8, 189 .reg_bits = 8,
190 .val_bits = 8, 190 .val_bits = 8,
191 .max_register = 24, 191 .max_register = 23,
192 .reg_defaults = pcm1792a_reg_defaults, 192 .reg_defaults = pcm1792a_reg_defaults,
193 .num_reg_defaults = ARRAY_SIZE(pcm1792a_reg_defaults), 193 .num_reg_defaults = ARRAY_SIZE(pcm1792a_reg_defaults),
194 .writeable_reg = pcm1792a_writeable_reg, 194 .writeable_reg = pcm1792a_writeable_reg,
diff --git a/sound/soc/codecs/tlv320aic3x.c b/sound/soc/codecs/tlv320aic3x.c
index 6e3f269243e0..64ad84d8a306 100644
--- a/sound/soc/codecs/tlv320aic3x.c
+++ b/sound/soc/codecs/tlv320aic3x.c
@@ -674,6 +674,8 @@ static const struct snd_soc_dapm_route intercon[] = {
674 /* Left Input */ 674 /* Left Input */
675 {"Left Line1L Mux", "single-ended", "LINE1L"}, 675 {"Left Line1L Mux", "single-ended", "LINE1L"},
676 {"Left Line1L Mux", "differential", "LINE1L"}, 676 {"Left Line1L Mux", "differential", "LINE1L"},
677 {"Left Line1R Mux", "single-ended", "LINE1R"},
678 {"Left Line1R Mux", "differential", "LINE1R"},
677 679
678 {"Left Line2L Mux", "single-ended", "LINE2L"}, 680 {"Left Line2L Mux", "single-ended", "LINE2L"},
679 {"Left Line2L Mux", "differential", "LINE2L"}, 681 {"Left Line2L Mux", "differential", "LINE2L"},
@@ -690,6 +692,8 @@ static const struct snd_soc_dapm_route intercon[] = {
690 /* Right Input */ 692 /* Right Input */
691 {"Right Line1R Mux", "single-ended", "LINE1R"}, 693 {"Right Line1R Mux", "single-ended", "LINE1R"},
692 {"Right Line1R Mux", "differential", "LINE1R"}, 694 {"Right Line1R Mux", "differential", "LINE1R"},
695 {"Right Line1L Mux", "single-ended", "LINE1L"},
696 {"Right Line1L Mux", "differential", "LINE1L"},
693 697
694 {"Right Line2R Mux", "single-ended", "LINE2R"}, 698 {"Right Line2R Mux", "single-ended", "LINE2R"},
695 {"Right Line2R Mux", "differential", "LINE2R"}, 699 {"Right Line2R Mux", "differential", "LINE2R"},
diff --git a/sound/soc/codecs/wm_hubs.c b/sound/soc/codecs/wm_hubs.c
index 8b50e5958de5..01daf655e20b 100644
--- a/sound/soc/codecs/wm_hubs.c
+++ b/sound/soc/codecs/wm_hubs.c
@@ -530,6 +530,7 @@ static int hp_supply_event(struct snd_soc_dapm_widget *w,
530 hubs->hp_startup_mode); 530 hubs->hp_startup_mode);
531 break; 531 break;
532 } 532 }
533 break;
533 534
534 case SND_SOC_DAPM_PRE_PMD: 535 case SND_SOC_DAPM_PRE_PMD:
535 snd_soc_update_bits(codec, WM8993_CHARGE_PUMP_1, 536 snd_soc_update_bits(codec, WM8993_CHARGE_PUMP_1,
diff --git a/sound/soc/fsl/fsl_ssi.c b/sound/soc/fsl/fsl_ssi.c
index c6b743978d5e..6b81d0ce2c44 100644
--- a/sound/soc/fsl/fsl_ssi.c
+++ b/sound/soc/fsl/fsl_ssi.c
@@ -936,7 +936,7 @@ static int fsl_ssi_probe(struct platform_device *pdev)
936 ssi_private->ssi_phys = res.start; 936 ssi_private->ssi_phys = res.start;
937 937
938 ssi_private->irq = irq_of_parse_and_map(np, 0); 938 ssi_private->irq = irq_of_parse_and_map(np, 0);
939 if (ssi_private->irq == NO_IRQ) { 939 if (ssi_private->irq == 0) {
940 dev_err(&pdev->dev, "no irq for node %s\n", np->full_name); 940 dev_err(&pdev->dev, "no irq for node %s\n", np->full_name);
941 return -ENXIO; 941 return -ENXIO;
942 } 942 }
diff --git a/sound/soc/fsl/imx-mc13783.c b/sound/soc/fsl/imx-mc13783.c
index a3d60d4bea4c..a2fd7321b5a9 100644
--- a/sound/soc/fsl/imx-mc13783.c
+++ b/sound/soc/fsl/imx-mc13783.c
@@ -112,7 +112,7 @@ static int imx_mc13783_probe(struct platform_device *pdev)
112 return ret; 112 return ret;
113 } 113 }
114 114
115 if (machine_is_mx31_3ds()) { 115 if (machine_is_mx31_3ds() || machine_is_mx31moboard()) {
116 imx_audmux_v2_configure_port(MX31_AUDMUX_PORT4_SSI_PINS_4, 116 imx_audmux_v2_configure_port(MX31_AUDMUX_PORT4_SSI_PINS_4,
117 IMX_AUDMUX_V2_PTCR_SYN, 117 IMX_AUDMUX_V2_PTCR_SYN,
118 IMX_AUDMUX_V2_PDCR_RXDSEL(MX31_AUDMUX_PORT1_SSI0) | 118 IMX_AUDMUX_V2_PDCR_RXDSEL(MX31_AUDMUX_PORT1_SSI0) |
diff --git a/sound/soc/fsl/imx-ssi.c b/sound/soc/fsl/imx-ssi.c
index f58bcd85c07f..57d6941676ff 100644
--- a/sound/soc/fsl/imx-ssi.c
+++ b/sound/soc/fsl/imx-ssi.c
@@ -600,19 +600,17 @@ static int imx_ssi_probe(struct platform_device *pdev)
600 ssi->fiq_params.dma_params_rx = &ssi->dma_params_rx; 600 ssi->fiq_params.dma_params_rx = &ssi->dma_params_rx;
601 ssi->fiq_params.dma_params_tx = &ssi->dma_params_tx; 601 ssi->fiq_params.dma_params_tx = &ssi->dma_params_tx;
602 602
603 ret = imx_pcm_fiq_init(pdev, &ssi->fiq_params); 603 ssi->fiq_init = imx_pcm_fiq_init(pdev, &ssi->fiq_params);
604 if (ret) 604 ssi->dma_init = imx_pcm_dma_init(pdev);
605 goto failed_pcm_fiq;
606 605
607 ret = imx_pcm_dma_init(pdev); 606 if (ssi->fiq_init && ssi->dma_init) {
608 if (ret) 607 ret = ssi->fiq_init;
609 goto failed_pcm_dma; 608 goto failed_pcm;
609 }
610 610
611 return 0; 611 return 0;
612 612
613failed_pcm_dma: 613failed_pcm:
614 imx_pcm_fiq_exit(pdev);
615failed_pcm_fiq:
616 snd_soc_unregister_component(&pdev->dev); 614 snd_soc_unregister_component(&pdev->dev);
617failed_register: 615failed_register:
618 release_mem_region(res->start, resource_size(res)); 616 release_mem_region(res->start, resource_size(res));
@@ -628,8 +626,11 @@ static int imx_ssi_remove(struct platform_device *pdev)
628 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 626 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
629 struct imx_ssi *ssi = platform_get_drvdata(pdev); 627 struct imx_ssi *ssi = platform_get_drvdata(pdev);
630 628
631 imx_pcm_dma_exit(pdev); 629 if (!ssi->dma_init)
632 imx_pcm_fiq_exit(pdev); 630 imx_pcm_dma_exit(pdev);
631
632 if (!ssi->fiq_init)
633 imx_pcm_fiq_exit(pdev);
633 634
634 snd_soc_unregister_component(&pdev->dev); 635 snd_soc_unregister_component(&pdev->dev);
635 636
diff --git a/sound/soc/fsl/imx-ssi.h b/sound/soc/fsl/imx-ssi.h
index fb1616ba8c59..560c40fc9ebb 100644
--- a/sound/soc/fsl/imx-ssi.h
+++ b/sound/soc/fsl/imx-ssi.h
@@ -211,6 +211,8 @@ struct imx_ssi {
211 struct imx_dma_data filter_data_rx; 211 struct imx_dma_data filter_data_rx;
212 struct imx_pcm_fiq_params fiq_params; 212 struct imx_pcm_fiq_params fiq_params;
213 213
214 int fiq_init;
215 int dma_init;
214 int enabled; 216 int enabled;
215}; 217};
216 218
diff --git a/sound/soc/omap/Kconfig b/sound/soc/omap/Kconfig
index daa78a0095fa..4a07f7179690 100644
--- a/sound/soc/omap/Kconfig
+++ b/sound/soc/omap/Kconfig
@@ -1,6 +1,6 @@
1config SND_OMAP_SOC 1config SND_OMAP_SOC
2 tristate "SoC Audio for the Texas Instruments OMAP chips" 2 tristate "SoC Audio for the Texas Instruments OMAP chips"
3 depends on (ARCH_OMAP && DMA_OMAP) || (ARCH_ARM && COMPILE_TEST) 3 depends on (ARCH_OMAP && DMA_OMAP) || (ARM && COMPILE_TEST)
4 select SND_DMAENGINE_PCM 4 select SND_DMAENGINE_PCM
5 5
6config SND_OMAP_SOC_DMIC 6config SND_OMAP_SOC_DMIC
@@ -26,7 +26,7 @@ config SND_OMAP_SOC_N810
26 26
27config SND_OMAP_SOC_RX51 27config SND_OMAP_SOC_RX51
28 tristate "SoC Audio support for Nokia RX-51" 28 tristate "SoC Audio support for Nokia RX-51"
29 depends on SND_OMAP_SOC && ARCH_ARM && (MACH_NOKIA_RX51 || COMPILE_TEST) 29 depends on SND_OMAP_SOC && ARM && (MACH_NOKIA_RX51 || COMPILE_TEST)
30 select SND_OMAP_SOC_MCBSP 30 select SND_OMAP_SOC_MCBSP
31 select SND_SOC_TLV320AIC3X 31 select SND_SOC_TLV320AIC3X
32 select SND_SOC_TPA6130A2 32 select SND_SOC_TPA6130A2
diff --git a/sound/soc/sh/rcar/rsnd.h b/sound/soc/sh/rcar/rsnd.h
index 9cc6986a8cfb..5dd87f4c919e 100644
--- a/sound/soc/sh/rcar/rsnd.h
+++ b/sound/soc/sh/rcar/rsnd.h
@@ -220,8 +220,8 @@ int rsnd_gen_path_exit(struct rsnd_priv *priv,
220void __iomem *rsnd_gen_reg_get(struct rsnd_priv *priv, 220void __iomem *rsnd_gen_reg_get(struct rsnd_priv *priv,
221 struct rsnd_mod *mod, 221 struct rsnd_mod *mod,
222 enum rsnd_reg reg); 222 enum rsnd_reg reg);
223#define rsnd_is_gen1(s) ((s)->info->flags & RSND_GEN1) 223#define rsnd_is_gen1(s) (((s)->info->flags & RSND_GEN_MASK) == RSND_GEN1)
224#define rsnd_is_gen2(s) ((s)->info->flags & RSND_GEN2) 224#define rsnd_is_gen2(s) (((s)->info->flags & RSND_GEN_MASK) == RSND_GEN2)
225 225
226/* 226/*
227 * R-Car ADG 227 * R-Car ADG
diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
index c17c14c394df..b2949aed1ac2 100644
--- a/sound/soc/soc-dapm.c
+++ b/sound/soc/soc-dapm.c
@@ -1949,7 +1949,7 @@ static ssize_t dapm_widget_power_read_file(struct file *file,
1949 w->active ? "active" : "inactive"); 1949 w->active ? "active" : "inactive");
1950 1950
1951 list_for_each_entry(p, &w->sources, list_sink) { 1951 list_for_each_entry(p, &w->sources, list_sink) {
1952 if (p->connected && !p->connected(w, p->sink)) 1952 if (p->connected && !p->connected(w, p->source))
1953 continue; 1953 continue;
1954 1954
1955 if (p->connect) 1955 if (p->connect)
@@ -3495,6 +3495,7 @@ int snd_soc_dapm_new_dai_widgets(struct snd_soc_dapm_context *dapm,
3495 if (!w) { 3495 if (!w) {
3496 dev_err(dapm->dev, "ASoC: Failed to create %s widget\n", 3496 dev_err(dapm->dev, "ASoC: Failed to create %s widget\n",
3497 dai->driver->playback.stream_name); 3497 dai->driver->playback.stream_name);
3498 return -ENOMEM;
3498 } 3499 }
3499 3500
3500 w->priv = dai; 3501 w->priv = dai;
@@ -3513,6 +3514,7 @@ int snd_soc_dapm_new_dai_widgets(struct snd_soc_dapm_context *dapm,
3513 if (!w) { 3514 if (!w) {
3514 dev_err(dapm->dev, "ASoC: Failed to create %s widget\n", 3515 dev_err(dapm->dev, "ASoC: Failed to create %s widget\n",
3515 dai->driver->capture.stream_name); 3516 dai->driver->capture.stream_name);
3517 return -ENOMEM;
3516 } 3518 }
3517 3519
3518 w->priv = dai; 3520 w->priv = dai;
diff --git a/tools/perf/Documentation/perf-record.txt b/tools/perf/Documentation/perf-record.txt
index e297b74471b8..ca0d3d9f4bac 100644
--- a/tools/perf/Documentation/perf-record.txt
+++ b/tools/perf/Documentation/perf-record.txt
@@ -90,8 +90,20 @@ OPTIONS
90 Number of mmap data pages. Must be a power of two. 90 Number of mmap data pages. Must be a power of two.
91 91
92-g:: 92-g::
93 Enables call-graph (stack chain/backtrace) recording.
94
93--call-graph:: 95--call-graph::
94 Do call-graph (stack chain/backtrace) recording. 96 Setup and enable call-graph (stack chain/backtrace) recording,
97 implies -g.
98
99 Allows specifying "fp" (frame pointer) or "dwarf"
100 (DWARF's CFI - Call Frame Information) as the method to collect
101 the information used to show the call graphs.
102
103 In some systems, where binaries are build with gcc
104 --fomit-frame-pointer, using the "fp" method will produce bogus
105 call graphs, using "dwarf", if available (perf tools linked to
106 the libunwind library) should be used instead.
95 107
96-q:: 108-q::
97--quiet:: 109--quiet::
diff --git a/tools/perf/Documentation/perf-top.txt b/tools/perf/Documentation/perf-top.txt
index 58d6598a9686..6a118e71d003 100644
--- a/tools/perf/Documentation/perf-top.txt
+++ b/tools/perf/Documentation/perf-top.txt
@@ -140,20 +140,12 @@ Default is to monitor all CPUS.
140--asm-raw:: 140--asm-raw::
141 Show raw instruction encoding of assembly instructions. 141 Show raw instruction encoding of assembly instructions.
142 142
143-G [type,min,order]:: 143-G::
144 Enables call-graph (stack chain/backtrace) recording.
145
144--call-graph:: 146--call-graph::
145 Display call chains using type, min percent threshold and order. 147 Setup and enable call-graph (stack chain/backtrace) recording,
146 type can be either: 148 implies -G.
147 - flat: single column, linear exposure of call chains.
148 - graph: use a graph tree, displaying absolute overhead rates.
149 - fractal: like graph, but displays relative rates. Each branch of
150 the tree is considered as a new profiled object.
151
152 order can be either:
153 - callee: callee based call graph.
154 - caller: inverted caller based call graph.
155
156 Default: fractal,0.5,callee.
157 149
158--ignore-callees=<regex>:: 150--ignore-callees=<regex>::
159 Ignore callees of the function(s) matching the given regex. 151 Ignore callees of the function(s) matching the given regex.
diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index 935d52216c89..fbc2888d6495 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -888,11 +888,18 @@ static s64 perf_kvm__mmap_read_idx(struct perf_kvm_stat *kvm, int idx,
888 while ((event = perf_evlist__mmap_read(kvm->evlist, idx)) != NULL) { 888 while ((event = perf_evlist__mmap_read(kvm->evlist, idx)) != NULL) {
889 err = perf_evlist__parse_sample(kvm->evlist, event, &sample); 889 err = perf_evlist__parse_sample(kvm->evlist, event, &sample);
890 if (err) { 890 if (err) {
891 perf_evlist__mmap_consume(kvm->evlist, idx);
891 pr_err("Failed to parse sample\n"); 892 pr_err("Failed to parse sample\n");
892 return -1; 893 return -1;
893 } 894 }
894 895
895 err = perf_session_queue_event(kvm->session, event, &sample, 0); 896 err = perf_session_queue_event(kvm->session, event, &sample, 0);
897 /*
898 * FIXME: Here we can't consume the event, as perf_session_queue_event will
899 * point to it, and it'll get possibly overwritten by the kernel.
900 */
901 perf_evlist__mmap_consume(kvm->evlist, idx);
902
896 if (err) { 903 if (err) {
897 pr_err("Failed to enqueue sample: %d\n", err); 904 pr_err("Failed to enqueue sample: %d\n", err);
898 return -1; 905 return -1;
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index a41ac41546c9..d04651484640 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -712,21 +712,12 @@ static int get_stack_size(char *str, unsigned long *_size)
712} 712}
713#endif /* LIBUNWIND_SUPPORT */ 713#endif /* LIBUNWIND_SUPPORT */
714 714
715int record_parse_callchain_opt(const struct option *opt, 715int record_parse_callchain(const char *arg, struct perf_record_opts *opts)
716 const char *arg, int unset)
717{ 716{
718 struct perf_record_opts *opts = opt->value;
719 char *tok, *name, *saveptr = NULL; 717 char *tok, *name, *saveptr = NULL;
720 char *buf; 718 char *buf;
721 int ret = -1; 719 int ret = -1;
722 720
723 /* --no-call-graph */
724 if (unset)
725 return 0;
726
727 /* We specified default option if none is provided. */
728 BUG_ON(!arg);
729
730 /* We need buffer that we know we can write to. */ 721 /* We need buffer that we know we can write to. */
731 buf = malloc(strlen(arg) + 1); 722 buf = malloc(strlen(arg) + 1);
732 if (!buf) 723 if (!buf)
@@ -764,13 +755,9 @@ int record_parse_callchain_opt(const struct option *opt,
764 ret = get_stack_size(tok, &size); 755 ret = get_stack_size(tok, &size);
765 opts->stack_dump_size = size; 756 opts->stack_dump_size = size;
766 } 757 }
767
768 if (!ret)
769 pr_debug("callchain: stack dump size %d\n",
770 opts->stack_dump_size);
771#endif /* LIBUNWIND_SUPPORT */ 758#endif /* LIBUNWIND_SUPPORT */
772 } else { 759 } else {
773 pr_err("callchain: Unknown -g option " 760 pr_err("callchain: Unknown --call-graph option "
774 "value: %s\n", arg); 761 "value: %s\n", arg);
775 break; 762 break;
776 } 763 }
@@ -778,13 +765,52 @@ int record_parse_callchain_opt(const struct option *opt,
778 } while (0); 765 } while (0);
779 766
780 free(buf); 767 free(buf);
768 return ret;
769}
770
771static void callchain_debug(struct perf_record_opts *opts)
772{
773 pr_debug("callchain: type %d\n", opts->call_graph);
781 774
775 if (opts->call_graph == CALLCHAIN_DWARF)
776 pr_debug("callchain: stack dump size %d\n",
777 opts->stack_dump_size);
778}
779
780int record_parse_callchain_opt(const struct option *opt,
781 const char *arg,
782 int unset)
783{
784 struct perf_record_opts *opts = opt->value;
785 int ret;
786
787 /* --no-call-graph */
788 if (unset) {
789 opts->call_graph = CALLCHAIN_NONE;
790 pr_debug("callchain: disabled\n");
791 return 0;
792 }
793
794 ret = record_parse_callchain(arg, opts);
782 if (!ret) 795 if (!ret)
783 pr_debug("callchain: type %d\n", opts->call_graph); 796 callchain_debug(opts);
784 797
785 return ret; 798 return ret;
786} 799}
787 800
801int record_callchain_opt(const struct option *opt,
802 const char *arg __maybe_unused,
803 int unset __maybe_unused)
804{
805 struct perf_record_opts *opts = opt->value;
806
807 if (opts->call_graph == CALLCHAIN_NONE)
808 opts->call_graph = CALLCHAIN_FP;
809
810 callchain_debug(opts);
811 return 0;
812}
813
788static const char * const record_usage[] = { 814static const char * const record_usage[] = {
789 "perf record [<options>] [<command>]", 815 "perf record [<options>] [<command>]",
790 "perf record [<options>] -- <command> [<options>]", 816 "perf record [<options>] -- <command> [<options>]",
@@ -813,12 +839,12 @@ static struct perf_record record = {
813 }, 839 },
814}; 840};
815 841
816#define CALLCHAIN_HELP "do call-graph (stack chain/backtrace) recording: " 842#define CALLCHAIN_HELP "setup and enables call-graph (stack chain/backtrace) recording: "
817 843
818#ifdef LIBUNWIND_SUPPORT 844#ifdef LIBUNWIND_SUPPORT
819const char record_callchain_help[] = CALLCHAIN_HELP "[fp] dwarf"; 845const char record_callchain_help[] = CALLCHAIN_HELP "fp dwarf";
820#else 846#else
821const char record_callchain_help[] = CALLCHAIN_HELP "[fp]"; 847const char record_callchain_help[] = CALLCHAIN_HELP "fp";
822#endif 848#endif
823 849
824/* 850/*
@@ -858,9 +884,12 @@ const struct option record_options[] = {
858 "number of mmap data pages"), 884 "number of mmap data pages"),
859 OPT_BOOLEAN(0, "group", &record.opts.group, 885 OPT_BOOLEAN(0, "group", &record.opts.group,
860 "put the counters into a counter group"), 886 "put the counters into a counter group"),
861 OPT_CALLBACK_DEFAULT('g', "call-graph", &record.opts, 887 OPT_CALLBACK_NOOPT('g', NULL, &record.opts,
862 "mode[,dump_size]", record_callchain_help, 888 NULL, "enables call-graph recording" ,
863 &record_parse_callchain_opt, "fp"), 889 &record_callchain_opt),
890 OPT_CALLBACK(0, "call-graph", &record.opts,
891 "mode[,dump_size]", record_callchain_help,
892 &record_parse_callchain_opt),
864 OPT_INCR('v', "verbose", &verbose, 893 OPT_INCR('v', "verbose", &verbose,
865 "be more verbose (show counter open errors, etc)"), 894 "be more verbose (show counter open errors, etc)"),
866 OPT_BOOLEAN('q', "quiet", &quiet, "don't print any message"), 895 OPT_BOOLEAN('q', "quiet", &quiet, "don't print any message"),
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 212214162bb2..5a11f13e56f9 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -810,7 +810,7 @@ static void perf_top__mmap_read_idx(struct perf_top *top, int idx)
810 ret = perf_evlist__parse_sample(top->evlist, event, &sample); 810 ret = perf_evlist__parse_sample(top->evlist, event, &sample);
811 if (ret) { 811 if (ret) {
812 pr_err("Can't parse sample, err = %d\n", ret); 812 pr_err("Can't parse sample, err = %d\n", ret);
813 continue; 813 goto next_event;
814 } 814 }
815 815
816 evsel = perf_evlist__id2evsel(session->evlist, sample.id); 816 evsel = perf_evlist__id2evsel(session->evlist, sample.id);
@@ -825,13 +825,13 @@ static void perf_top__mmap_read_idx(struct perf_top *top, int idx)
825 case PERF_RECORD_MISC_USER: 825 case PERF_RECORD_MISC_USER:
826 ++top->us_samples; 826 ++top->us_samples;
827 if (top->hide_user_symbols) 827 if (top->hide_user_symbols)
828 continue; 828 goto next_event;
829 machine = &session->machines.host; 829 machine = &session->machines.host;
830 break; 830 break;
831 case PERF_RECORD_MISC_KERNEL: 831 case PERF_RECORD_MISC_KERNEL:
832 ++top->kernel_samples; 832 ++top->kernel_samples;
833 if (top->hide_kernel_symbols) 833 if (top->hide_kernel_symbols)
834 continue; 834 goto next_event;
835 machine = &session->machines.host; 835 machine = &session->machines.host;
836 break; 836 break;
837 case PERF_RECORD_MISC_GUEST_KERNEL: 837 case PERF_RECORD_MISC_GUEST_KERNEL:
@@ -847,7 +847,7 @@ static void perf_top__mmap_read_idx(struct perf_top *top, int idx)
847 */ 847 */
848 /* Fall thru */ 848 /* Fall thru */
849 default: 849 default:
850 continue; 850 goto next_event;
851 } 851 }
852 852
853 853
@@ -859,6 +859,8 @@ static void perf_top__mmap_read_idx(struct perf_top *top, int idx)
859 machine__process_event(machine, event); 859 machine__process_event(machine, event);
860 } else 860 } else
861 ++session->stats.nr_unknown_events; 861 ++session->stats.nr_unknown_events;
862next_event:
863 perf_evlist__mmap_consume(top->evlist, idx);
862 } 864 }
863} 865}
864 866
@@ -1016,16 +1018,16 @@ out_delete:
1016} 1018}
1017 1019
1018static int 1020static int
1019parse_callchain_opt(const struct option *opt, const char *arg, int unset) 1021callchain_opt(const struct option *opt, const char *arg, int unset)
1020{ 1022{
1021 /*
1022 * --no-call-graph
1023 */
1024 if (unset)
1025 return 0;
1026
1027 symbol_conf.use_callchain = true; 1023 symbol_conf.use_callchain = true;
1024 return record_callchain_opt(opt, arg, unset);
1025}
1028 1026
1027static int
1028parse_callchain_opt(const struct option *opt, const char *arg, int unset)
1029{
1030 symbol_conf.use_callchain = true;
1029 return record_parse_callchain_opt(opt, arg, unset); 1031 return record_parse_callchain_opt(opt, arg, unset);
1030} 1032}
1031 1033
@@ -1106,9 +1108,12 @@ int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused)
1106 "sort by key(s): pid, comm, dso, symbol, parent, weight, local_weight"), 1108 "sort by key(s): pid, comm, dso, symbol, parent, weight, local_weight"),
1107 OPT_BOOLEAN('n', "show-nr-samples", &symbol_conf.show_nr_samples, 1109 OPT_BOOLEAN('n', "show-nr-samples", &symbol_conf.show_nr_samples,
1108 "Show a column with the number of samples"), 1110 "Show a column with the number of samples"),
1109 OPT_CALLBACK_DEFAULT('G', "call-graph", &top.record_opts, 1111 OPT_CALLBACK_NOOPT('G', NULL, &top.record_opts,
1110 "mode[,dump_size]", record_callchain_help, 1112 NULL, "enables call-graph recording",
1111 &parse_callchain_opt, "fp"), 1113 &callchain_opt),
1114 OPT_CALLBACK(0, "call-graph", &top.record_opts,
1115 "mode[,dump_size]", record_callchain_help,
1116 &parse_callchain_opt),
1112 OPT_CALLBACK(0, "ignore-callees", NULL, "regex", 1117 OPT_CALLBACK(0, "ignore-callees", NULL, "regex",
1113 "ignore callees of these functions in call graphs", 1118 "ignore callees of these functions in call graphs",
1114 report_parse_ignore_callees_opt), 1119 report_parse_ignore_callees_opt),
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 71aa3e35406b..99c8d9ad6729 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -987,7 +987,7 @@ again:
987 err = perf_evlist__parse_sample(evlist, event, &sample); 987 err = perf_evlist__parse_sample(evlist, event, &sample);
988 if (err) { 988 if (err) {
989 fprintf(trace->output, "Can't parse sample, err = %d, skipping...\n", err); 989 fprintf(trace->output, "Can't parse sample, err = %d, skipping...\n", err);
990 continue; 990 goto next_event;
991 } 991 }
992 992
993 if (trace->base_time == 0) 993 if (trace->base_time == 0)
@@ -1001,18 +1001,20 @@ again:
1001 evsel = perf_evlist__id2evsel(evlist, sample.id); 1001 evsel = perf_evlist__id2evsel(evlist, sample.id);
1002 if (evsel == NULL) { 1002 if (evsel == NULL) {
1003 fprintf(trace->output, "Unknown tp ID %" PRIu64 ", skipping...\n", sample.id); 1003 fprintf(trace->output, "Unknown tp ID %" PRIu64 ", skipping...\n", sample.id);
1004 continue; 1004 goto next_event;
1005 } 1005 }
1006 1006
1007 if (sample.raw_data == NULL) { 1007 if (sample.raw_data == NULL) {
1008 fprintf(trace->output, "%s sample with no payload for tid: %d, cpu %d, raw_size=%d, skipping...\n", 1008 fprintf(trace->output, "%s sample with no payload for tid: %d, cpu %d, raw_size=%d, skipping...\n",
1009 perf_evsel__name(evsel), sample.tid, 1009 perf_evsel__name(evsel), sample.tid,
1010 sample.cpu, sample.raw_size); 1010 sample.cpu, sample.raw_size);
1011 continue; 1011 goto next_event;
1012 } 1012 }
1013 1013
1014 handler = evsel->handler.func; 1014 handler = evsel->handler.func;
1015 handler(trace, evsel, &sample); 1015 handler(trace, evsel, &sample);
1016next_event:
1017 perf_evlist__mmap_consume(evlist, i);
1016 1018
1017 if (done) 1019 if (done)
1018 goto out_unmap_evlist; 1020 goto out_unmap_evlist;
diff --git a/tools/perf/tests/code-reading.c b/tools/perf/tests/code-reading.c
index 6fb781d5586c..e3fedfa2906e 100644
--- a/tools/perf/tests/code-reading.c
+++ b/tools/perf/tests/code-reading.c
@@ -290,6 +290,7 @@ static int process_events(struct machine *machine, struct perf_evlist *evlist,
290 for (i = 0; i < evlist->nr_mmaps; i++) { 290 for (i = 0; i < evlist->nr_mmaps; i++) {
291 while ((event = perf_evlist__mmap_read(evlist, i)) != NULL) { 291 while ((event = perf_evlist__mmap_read(evlist, i)) != NULL) {
292 ret = process_event(machine, evlist, event, state); 292 ret = process_event(machine, evlist, event, state);
293 perf_evlist__mmap_consume(evlist, i);
293 if (ret < 0) 294 if (ret < 0)
294 return ret; 295 return ret;
295 } 296 }
diff --git a/tools/perf/tests/keep-tracking.c b/tools/perf/tests/keep-tracking.c
index d444ea2c47d9..376c35608534 100644
--- a/tools/perf/tests/keep-tracking.c
+++ b/tools/perf/tests/keep-tracking.c
@@ -36,6 +36,7 @@ static int find_comm(struct perf_evlist *evlist, const char *comm)
36 (pid_t)event->comm.tid == getpid() && 36 (pid_t)event->comm.tid == getpid() &&
37 strcmp(event->comm.comm, comm) == 0) 37 strcmp(event->comm.comm, comm) == 0)
38 found += 1; 38 found += 1;
39 perf_evlist__mmap_consume(evlist, i);
39 } 40 }
40 } 41 }
41 return found; 42 return found;
diff --git a/tools/perf/tests/mmap-basic.c b/tools/perf/tests/mmap-basic.c
index c4185b9aeb80..a7232c204eb9 100644
--- a/tools/perf/tests/mmap-basic.c
+++ b/tools/perf/tests/mmap-basic.c
@@ -122,6 +122,7 @@ int test__basic_mmap(void)
122 goto out_munmap; 122 goto out_munmap;
123 } 123 }
124 nr_events[evsel->idx]++; 124 nr_events[evsel->idx]++;
125 perf_evlist__mmap_consume(evlist, 0);
125 } 126 }
126 127
127 err = 0; 128 err = 0;
diff --git a/tools/perf/tests/open-syscall-tp-fields.c b/tools/perf/tests/open-syscall-tp-fields.c
index fc5b9fca8b47..524b221b829b 100644
--- a/tools/perf/tests/open-syscall-tp-fields.c
+++ b/tools/perf/tests/open-syscall-tp-fields.c
@@ -77,8 +77,10 @@ int test__syscall_open_tp_fields(void)
77 77
78 ++nr_events; 78 ++nr_events;
79 79
80 if (type != PERF_RECORD_SAMPLE) 80 if (type != PERF_RECORD_SAMPLE) {
81 perf_evlist__mmap_consume(evlist, i);
81 continue; 82 continue;
83 }
82 84
83 err = perf_evsel__parse_sample(evsel, event, &sample); 85 err = perf_evsel__parse_sample(evsel, event, &sample);
84 if (err) { 86 if (err) {
diff --git a/tools/perf/tests/perf-record.c b/tools/perf/tests/perf-record.c
index b8a7056519ac..7923b06ffc91 100644
--- a/tools/perf/tests/perf-record.c
+++ b/tools/perf/tests/perf-record.c
@@ -263,6 +263,8 @@ int test__PERF_RECORD(void)
263 type); 263 type);
264 ++errs; 264 ++errs;
265 } 265 }
266
267 perf_evlist__mmap_consume(evlist, i);
266 } 268 }
267 } 269 }
268 270
diff --git a/tools/perf/tests/perf-time-to-tsc.c b/tools/perf/tests/perf-time-to-tsc.c
index 0ab61b1f408e..4ca1b938f6a6 100644
--- a/tools/perf/tests/perf-time-to-tsc.c
+++ b/tools/perf/tests/perf-time-to-tsc.c
@@ -122,7 +122,7 @@ int test__perf_time_to_tsc(void)
122 if (event->header.type != PERF_RECORD_COMM || 122 if (event->header.type != PERF_RECORD_COMM ||
123 (pid_t)event->comm.pid != getpid() || 123 (pid_t)event->comm.pid != getpid() ||
124 (pid_t)event->comm.tid != getpid()) 124 (pid_t)event->comm.tid != getpid())
125 continue; 125 goto next_event;
126 126
127 if (strcmp(event->comm.comm, comm1) == 0) { 127 if (strcmp(event->comm.comm, comm1) == 0) {
128 CHECK__(perf_evsel__parse_sample(evsel, event, 128 CHECK__(perf_evsel__parse_sample(evsel, event,
@@ -134,6 +134,8 @@ int test__perf_time_to_tsc(void)
134 &sample)); 134 &sample));
135 comm2_time = sample.time; 135 comm2_time = sample.time;
136 } 136 }
137next_event:
138 perf_evlist__mmap_consume(evlist, i);
137 } 139 }
138 } 140 }
139 141
diff --git a/tools/perf/tests/sw-clock.c b/tools/perf/tests/sw-clock.c
index 2e41e2d32ccc..6e2b44ec0749 100644
--- a/tools/perf/tests/sw-clock.c
+++ b/tools/perf/tests/sw-clock.c
@@ -78,7 +78,7 @@ static int __test__sw_clock_freq(enum perf_sw_ids clock_id)
78 struct perf_sample sample; 78 struct perf_sample sample;
79 79
80 if (event->header.type != PERF_RECORD_SAMPLE) 80 if (event->header.type != PERF_RECORD_SAMPLE)
81 continue; 81 goto next_event;
82 82
83 err = perf_evlist__parse_sample(evlist, event, &sample); 83 err = perf_evlist__parse_sample(evlist, event, &sample);
84 if (err < 0) { 84 if (err < 0) {
@@ -88,6 +88,8 @@ static int __test__sw_clock_freq(enum perf_sw_ids clock_id)
88 88
89 total_periods += sample.period; 89 total_periods += sample.period;
90 nr_samples++; 90 nr_samples++;
91next_event:
92 perf_evlist__mmap_consume(evlist, 0);
91 } 93 }
92 94
93 if ((u64) nr_samples == total_periods) { 95 if ((u64) nr_samples == total_periods) {
diff --git a/tools/perf/tests/task-exit.c b/tools/perf/tests/task-exit.c
index 28fe5894b061..a3e64876e940 100644
--- a/tools/perf/tests/task-exit.c
+++ b/tools/perf/tests/task-exit.c
@@ -96,10 +96,10 @@ int test__task_exit(void)
96 96
97retry: 97retry:
98 while ((event = perf_evlist__mmap_read(evlist, 0)) != NULL) { 98 while ((event = perf_evlist__mmap_read(evlist, 0)) != NULL) {
99 if (event->header.type != PERF_RECORD_EXIT) 99 if (event->header.type == PERF_RECORD_EXIT)
100 continue; 100 nr_exit++;
101 101
102 nr_exit++; 102 perf_evlist__mmap_consume(evlist, 0);
103 } 103 }
104 104
105 if (!exited || !nr_exit) { 105 if (!exited || !nr_exit) {
diff --git a/tools/perf/ui/stdio/hist.c b/tools/perf/ui/stdio/hist.c
index 194e2f42ff5d..6c152686e837 100644
--- a/tools/perf/ui/stdio/hist.c
+++ b/tools/perf/ui/stdio/hist.c
@@ -315,8 +315,7 @@ static inline void advance_hpp(struct perf_hpp *hpp, int inc)
315} 315}
316 316
317static int hist_entry__period_snprintf(struct perf_hpp *hpp, 317static int hist_entry__period_snprintf(struct perf_hpp *hpp,
318 struct hist_entry *he, 318 struct hist_entry *he)
319 bool color)
320{ 319{
321 const char *sep = symbol_conf.field_sep; 320 const char *sep = symbol_conf.field_sep;
322 struct perf_hpp_fmt *fmt; 321 struct perf_hpp_fmt *fmt;
@@ -338,7 +337,7 @@ static int hist_entry__period_snprintf(struct perf_hpp *hpp,
338 } else 337 } else
339 first = false; 338 first = false;
340 339
341 if (color && fmt->color) 340 if (perf_hpp__use_color() && fmt->color)
342 ret = fmt->color(fmt, hpp, he); 341 ret = fmt->color(fmt, hpp, he);
343 else 342 else
344 ret = fmt->entry(fmt, hpp, he); 343 ret = fmt->entry(fmt, hpp, he);
@@ -358,12 +357,11 @@ static int hist_entry__fprintf(struct hist_entry *he, size_t size,
358 .buf = bf, 357 .buf = bf,
359 .size = size, 358 .size = size,
360 }; 359 };
361 bool color = !symbol_conf.field_sep;
362 360
363 if (size == 0 || size > bfsz) 361 if (size == 0 || size > bfsz)
364 size = hpp.size = bfsz; 362 size = hpp.size = bfsz;
365 363
366 ret = hist_entry__period_snprintf(&hpp, he, color); 364 ret = hist_entry__period_snprintf(&hpp, he);
367 hist_entry__sort_snprintf(he, bf + ret, size - ret, hists); 365 hist_entry__sort_snprintf(he, bf + ret, size - ret, hists);
368 366
369 ret = fprintf(fp, "%s\n", bf); 367 ret = fprintf(fp, "%s\n", bf);
@@ -482,6 +480,7 @@ size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows,
482 480
483print_entries: 481print_entries:
484 linesz = hists__sort_list_width(hists) + 3 + 1; 482 linesz = hists__sort_list_width(hists) + 3 + 1;
483 linesz += perf_hpp__color_overhead();
485 line = malloc(linesz); 484 line = malloc(linesz);
486 if (line == NULL) { 485 if (line == NULL) {
487 ret = -1; 486 ret = -1;
diff --git a/tools/perf/util/callchain.h b/tools/perf/util/callchain.h
index 2b585bc308cf..9e99060408ae 100644
--- a/tools/perf/util/callchain.h
+++ b/tools/perf/util/callchain.h
@@ -147,6 +147,9 @@ static inline void callchain_cursor_advance(struct callchain_cursor *cursor)
147 147
148struct option; 148struct option;
149 149
150int record_parse_callchain(const char *arg, struct perf_record_opts *opts);
150int record_parse_callchain_opt(const struct option *opt, const char *arg, int unset); 151int record_parse_callchain_opt(const struct option *opt, const char *arg, int unset);
152int record_callchain_opt(const struct option *opt, const char *arg, int unset);
153
151extern const char record_callchain_help[]; 154extern const char record_callchain_help[];
152#endif /* __PERF_CALLCHAIN_H */ 155#endif /* __PERF_CALLCHAIN_H */
diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index 9b393e7dca6f..49096ea58a15 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -187,7 +187,7 @@ static int perf_event__synthesize_mmap_events(struct perf_tool *tool,
187 return -1; 187 return -1;
188 } 188 }
189 189
190 event->header.type = PERF_RECORD_MMAP2; 190 event->header.type = PERF_RECORD_MMAP;
191 /* 191 /*
192 * Just like the kernel, see __perf_event_mmap in kernel/perf_event.c 192 * Just like the kernel, see __perf_event_mmap in kernel/perf_event.c
193 */ 193 */
@@ -198,7 +198,6 @@ static int perf_event__synthesize_mmap_events(struct perf_tool *tool,
198 char prot[5]; 198 char prot[5];
199 char execname[PATH_MAX]; 199 char execname[PATH_MAX];
200 char anonstr[] = "//anon"; 200 char anonstr[] = "//anon";
201 unsigned int ino;
202 size_t size; 201 size_t size;
203 ssize_t n; 202 ssize_t n;
204 203
@@ -209,15 +208,12 @@ static int perf_event__synthesize_mmap_events(struct perf_tool *tool,
209 strcpy(execname, ""); 208 strcpy(execname, "");
210 209
211 /* 00400000-0040c000 r-xp 00000000 fd:01 41038 /bin/cat */ 210 /* 00400000-0040c000 r-xp 00000000 fd:01 41038 /bin/cat */
212 n = sscanf(bf, "%"PRIx64"-%"PRIx64" %s %"PRIx64" %x:%x %u %s\n", 211 n = sscanf(bf, "%"PRIx64"-%"PRIx64" %s %"PRIx64" %*x:%*x %*u %s\n",
213 &event->mmap2.start, &event->mmap2.len, prot, 212 &event->mmap.start, &event->mmap.len, prot,
214 &event->mmap2.pgoff, &event->mmap2.maj, 213 &event->mmap.pgoff,
215 &event->mmap2.min, 214 execname);
216 &ino, execname);
217
218 event->mmap2.ino = (u64)ino;
219 215
220 if (n != 8) 216 if (n != 5)
221 continue; 217 continue;
222 218
223 if (prot[2] != 'x') 219 if (prot[2] != 'x')
@@ -227,15 +223,15 @@ static int perf_event__synthesize_mmap_events(struct perf_tool *tool,
227 strcpy(execname, anonstr); 223 strcpy(execname, anonstr);
228 224
229 size = strlen(execname) + 1; 225 size = strlen(execname) + 1;
230 memcpy(event->mmap2.filename, execname, size); 226 memcpy(event->mmap.filename, execname, size);
231 size = PERF_ALIGN(size, sizeof(u64)); 227 size = PERF_ALIGN(size, sizeof(u64));
232 event->mmap2.len -= event->mmap.start; 228 event->mmap.len -= event->mmap.start;
233 event->mmap2.header.size = (sizeof(event->mmap2) - 229 event->mmap.header.size = (sizeof(event->mmap) -
234 (sizeof(event->mmap2.filename) - size)); 230 (sizeof(event->mmap.filename) - size));
235 memset(event->mmap2.filename + size, 0, machine->id_hdr_size); 231 memset(event->mmap.filename + size, 0, machine->id_hdr_size);
236 event->mmap2.header.size += machine->id_hdr_size; 232 event->mmap.header.size += machine->id_hdr_size;
237 event->mmap2.pid = tgid; 233 event->mmap.pid = tgid;
238 event->mmap2.tid = pid; 234 event->mmap.tid = pid;
239 235
240 if (process(tool, event, &synth_sample, machine) != 0) { 236 if (process(tool, event, &synth_sample, machine) != 0) {
241 rc = -1; 237 rc = -1;
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index f9f77bee0b1b..e584cd30b0f2 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -545,12 +545,19 @@ union perf_event *perf_evlist__mmap_read(struct perf_evlist *evlist, int idx)
545 545
546 md->prev = old; 546 md->prev = old;
547 547
548 if (!evlist->overwrite)
549 perf_mmap__write_tail(md, old);
550
551 return event; 548 return event;
552} 549}
553 550
551void perf_evlist__mmap_consume(struct perf_evlist *evlist, int idx)
552{
553 if (!evlist->overwrite) {
554 struct perf_mmap *md = &evlist->mmap[idx];
555 unsigned int old = md->prev;
556
557 perf_mmap__write_tail(md, old);
558 }
559}
560
554static void __perf_evlist__munmap(struct perf_evlist *evlist, int idx) 561static void __perf_evlist__munmap(struct perf_evlist *evlist, int idx)
555{ 562{
556 if (evlist->mmap[idx].base != NULL) { 563 if (evlist->mmap[idx].base != NULL) {
diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h
index 880d7139d2fb..206d09339306 100644
--- a/tools/perf/util/evlist.h
+++ b/tools/perf/util/evlist.h
@@ -89,6 +89,8 @@ struct perf_sample_id *perf_evlist__id2sid(struct perf_evlist *evlist, u64 id);
89 89
90union perf_event *perf_evlist__mmap_read(struct perf_evlist *self, int idx); 90union perf_event *perf_evlist__mmap_read(struct perf_evlist *self, int idx);
91 91
92void perf_evlist__mmap_consume(struct perf_evlist *evlist, int idx);
93
92int perf_evlist__open(struct perf_evlist *evlist); 94int perf_evlist__open(struct perf_evlist *evlist);
93void perf_evlist__close(struct perf_evlist *evlist); 95void perf_evlist__close(struct perf_evlist *evlist);
94 96
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 0ce9febf1ba0..9f1ef9bee2d0 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -678,7 +678,6 @@ void perf_evsel__config(struct perf_evsel *evsel,
678 attr->sample_type |= PERF_SAMPLE_WEIGHT; 678 attr->sample_type |= PERF_SAMPLE_WEIGHT;
679 679
680 attr->mmap = track; 680 attr->mmap = track;
681 attr->mmap2 = track && !perf_missing_features.mmap2;
682 attr->comm = track; 681 attr->comm = track;
683 682
684 /* 683 /*
diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h
index 1329b6b6ffe6..ce8dc61ce2c3 100644
--- a/tools/perf/util/hist.h
+++ b/tools/perf/util/hist.h
@@ -5,6 +5,7 @@
5#include <pthread.h> 5#include <pthread.h>
6#include "callchain.h" 6#include "callchain.h"
7#include "header.h" 7#include "header.h"
8#include "color.h"
8 9
9extern struct callchain_param callchain_param; 10extern struct callchain_param callchain_param;
10 11
@@ -175,6 +176,18 @@ void perf_hpp__init(void);
175void perf_hpp__column_register(struct perf_hpp_fmt *format); 176void perf_hpp__column_register(struct perf_hpp_fmt *format);
176void perf_hpp__column_enable(unsigned col); 177void perf_hpp__column_enable(unsigned col);
177 178
179static inline size_t perf_hpp__use_color(void)
180{
181 return !symbol_conf.field_sep;
182}
183
184static inline size_t perf_hpp__color_overhead(void)
185{
186 return perf_hpp__use_color() ?
187 (COLOR_MAXLEN + sizeof(PERF_COLOR_RESET)) * PERF_HPP__MAX_INDEX
188 : 0;
189}
190
178struct perf_evlist; 191struct perf_evlist;
179 192
180struct hist_browser_timer { 193struct hist_browser_timer {
diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
index c09e0a9fdf4c..f0692737ebf1 100644
--- a/tools/perf/util/probe-finder.c
+++ b/tools/perf/util/probe-finder.c
@@ -1357,10 +1357,10 @@ int debuginfo__find_probe_point(struct debuginfo *self, unsigned long addr,
1357 goto post; 1357 goto post;
1358 } 1358 }
1359 1359
1360 fname = dwarf_decl_file(&spdie);
1360 if (addr == (unsigned long)baseaddr) { 1361 if (addr == (unsigned long)baseaddr) {
1361 /* Function entry - Relative line number is 0 */ 1362 /* Function entry - Relative line number is 0 */
1362 lineno = baseline; 1363 lineno = baseline;
1363 fname = dwarf_decl_file(&spdie);
1364 goto post; 1364 goto post;
1365 } 1365 }
1366 1366
diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c
index 71b5412bbbb9..2ac4bc92bb1f 100644
--- a/tools/perf/util/python.c
+++ b/tools/perf/util/python.c
@@ -822,6 +822,8 @@ static PyObject *pyrf_evlist__read_on_cpu(struct pyrf_evlist *pevlist,
822 PyObject *pyevent = pyrf_event__new(event); 822 PyObject *pyevent = pyrf_event__new(event);
823 struct pyrf_event *pevent = (struct pyrf_event *)pyevent; 823 struct pyrf_event *pevent = (struct pyrf_event *)pyevent;
824 824
825 perf_evlist__mmap_consume(evlist, cpu);
826
825 if (pyevent == NULL) 827 if (pyevent == NULL)
826 return PyErr_NoMemory(); 828 return PyErr_NoMemory();
827 829
diff --git a/tools/perf/util/scripting-engines/trace-event-perl.c b/tools/perf/util/scripting-engines/trace-event-perl.c
index a85e4ae5f3ac..c0c9795c4f02 100644
--- a/tools/perf/util/scripting-engines/trace-event-perl.c
+++ b/tools/perf/util/scripting-engines/trace-event-perl.c
@@ -282,7 +282,7 @@ static void perl_process_tracepoint(union perf_event *perf_event __maybe_unused,
282 282
283 event = find_cache_event(evsel); 283 event = find_cache_event(evsel);
284 if (!event) 284 if (!event)
285 die("ug! no event found for type %" PRIu64, evsel->attr.config); 285 die("ug! no event found for type %" PRIu64, (u64)evsel->attr.config);
286 286
287 pid = raw_field_value(event, "common_pid", data); 287 pid = raw_field_value(event, "common_pid", data);
288 288
diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c
index cc75a3cef388..95d91a0b23af 100644
--- a/tools/perf/util/scripting-engines/trace-event-python.c
+++ b/tools/perf/util/scripting-engines/trace-event-python.c
@@ -56,6 +56,17 @@ static void handler_call_die(const char *handler_name)
56 Py_FatalError("problem in Python trace event handler"); 56 Py_FatalError("problem in Python trace event handler");
57} 57}
58 58
59/*
60 * Insert val into into the dictionary and decrement the reference counter.
61 * This is necessary for dictionaries since PyDict_SetItemString() does not
62 * steal a reference, as opposed to PyTuple_SetItem().
63 */
64static void pydict_set_item_string_decref(PyObject *dict, const char *key, PyObject *val)
65{
66 PyDict_SetItemString(dict, key, val);
67 Py_DECREF(val);
68}
69
59static void define_value(enum print_arg_type field_type, 70static void define_value(enum print_arg_type field_type,
60 const char *ev_name, 71 const char *ev_name,
61 const char *field_name, 72 const char *field_name,
@@ -279,11 +290,11 @@ static void python_process_tracepoint(union perf_event *perf_event
279 PyTuple_SetItem(t, n++, PyInt_FromLong(pid)); 290 PyTuple_SetItem(t, n++, PyInt_FromLong(pid));
280 PyTuple_SetItem(t, n++, PyString_FromString(comm)); 291 PyTuple_SetItem(t, n++, PyString_FromString(comm));
281 } else { 292 } else {
282 PyDict_SetItemString(dict, "common_cpu", PyInt_FromLong(cpu)); 293 pydict_set_item_string_decref(dict, "common_cpu", PyInt_FromLong(cpu));
283 PyDict_SetItemString(dict, "common_s", PyInt_FromLong(s)); 294 pydict_set_item_string_decref(dict, "common_s", PyInt_FromLong(s));
284 PyDict_SetItemString(dict, "common_ns", PyInt_FromLong(ns)); 295 pydict_set_item_string_decref(dict, "common_ns", PyInt_FromLong(ns));
285 PyDict_SetItemString(dict, "common_pid", PyInt_FromLong(pid)); 296 pydict_set_item_string_decref(dict, "common_pid", PyInt_FromLong(pid));
286 PyDict_SetItemString(dict, "common_comm", PyString_FromString(comm)); 297 pydict_set_item_string_decref(dict, "common_comm", PyString_FromString(comm));
287 } 298 }
288 for (field = event->format.fields; field; field = field->next) { 299 for (field = event->format.fields; field; field = field->next) {
289 if (field->flags & FIELD_IS_STRING) { 300 if (field->flags & FIELD_IS_STRING) {
@@ -313,7 +324,7 @@ static void python_process_tracepoint(union perf_event *perf_event
313 if (handler) 324 if (handler)
314 PyTuple_SetItem(t, n++, obj); 325 PyTuple_SetItem(t, n++, obj);
315 else 326 else
316 PyDict_SetItemString(dict, field->name, obj); 327 pydict_set_item_string_decref(dict, field->name, obj);
317 328
318 } 329 }
319 if (!handler) 330 if (!handler)
@@ -370,21 +381,21 @@ static void python_process_general_event(union perf_event *perf_event
370 if (!handler || !PyCallable_Check(handler)) 381 if (!handler || !PyCallable_Check(handler))
371 goto exit; 382 goto exit;
372 383
373 PyDict_SetItemString(dict, "ev_name", PyString_FromString(perf_evsel__name(evsel))); 384 pydict_set_item_string_decref(dict, "ev_name", PyString_FromString(perf_evsel__name(evsel)));
374 PyDict_SetItemString(dict, "attr", PyString_FromStringAndSize( 385 pydict_set_item_string_decref(dict, "attr", PyString_FromStringAndSize(
375 (const char *)&evsel->attr, sizeof(evsel->attr))); 386 (const char *)&evsel->attr, sizeof(evsel->attr)));
376 PyDict_SetItemString(dict, "sample", PyString_FromStringAndSize( 387 pydict_set_item_string_decref(dict, "sample", PyString_FromStringAndSize(
377 (const char *)sample, sizeof(*sample))); 388 (const char *)sample, sizeof(*sample)));
378 PyDict_SetItemString(dict, "raw_buf", PyString_FromStringAndSize( 389 pydict_set_item_string_decref(dict, "raw_buf", PyString_FromStringAndSize(
379 (const char *)sample->raw_data, sample->raw_size)); 390 (const char *)sample->raw_data, sample->raw_size));
380 PyDict_SetItemString(dict, "comm", 391 pydict_set_item_string_decref(dict, "comm",
381 PyString_FromString(thread->comm)); 392 PyString_FromString(thread->comm));
382 if (al->map) { 393 if (al->map) {
383 PyDict_SetItemString(dict, "dso", 394 pydict_set_item_string_decref(dict, "dso",
384 PyString_FromString(al->map->dso->name)); 395 PyString_FromString(al->map->dso->name));
385 } 396 }
386 if (al->sym) { 397 if (al->sym) {
387 PyDict_SetItemString(dict, "symbol", 398 pydict_set_item_string_decref(dict, "symbol",
388 PyString_FromString(al->sym->name)); 399 PyString_FromString(al->sym->name));
389 } 400 }
390 401
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index a9dd682cf5e3..1cf9ccb01013 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -3091,7 +3091,7 @@ static const struct file_operations *stat_fops[] = {
3091 3091
3092static int kvm_init_debug(void) 3092static int kvm_init_debug(void)
3093{ 3093{
3094 int r = -EFAULT; 3094 int r = -EEXIST;
3095 struct kvm_stats_debugfs_item *p; 3095 struct kvm_stats_debugfs_item *p;
3096 3096
3097 kvm_debugfs_dir = debugfs_create_dir("kvm", NULL); 3097 kvm_debugfs_dir = debugfs_create_dir("kvm", NULL);