aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-04-01 15:01:10 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-04-01 15:01:10 -0400
commitef99f3aee9641d10a7c80d4803d2f0f004c797ca (patch)
tree83f14ccef66db48fc4178bd8b973462006de86b8 /drivers
parentcb06ff102e2d79a82cf780aa5e6947b2e0529ac0 (diff)
parent07961ac7c0ee8b546658717034fe692fd12eefa9 (diff)
Merge 3.9-rc5 into tty-next
We need the fixes here as well. Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/acpi/apei/cper.c2
-rw-r--r--drivers/acpi/pci_root.c9
-rw-r--r--drivers/acpi/sleep.c8
-rw-r--r--drivers/amba/tegra-ahb.c2
-rw-r--r--drivers/ata/Kconfig13
-rw-r--r--drivers/ata/ahci.c2
-rw-r--r--drivers/ata/ata_piix.c4
-rw-r--r--drivers/ata/libata-acpi.c2
-rw-r--r--drivers/ata/pata_samsung_cf.c13
-rw-r--r--drivers/ata/sata_fsl.c3
-rw-r--r--drivers/block/Kconfig4
-rw-r--r--drivers/block/cciss.c2
-rw-r--r--drivers/block/loop.c22
-rw-r--r--drivers/block/mg_disk.c4
-rw-r--r--drivers/block/mtip32xx/mtip32xx.c4
-rw-r--r--drivers/block/nvme.c33
-rw-r--r--drivers/block/rbd.c47
-rw-r--r--drivers/block/rsxx/Makefile2
-rw-r--r--drivers/block/rsxx/config.c8
-rw-r--r--drivers/block/rsxx/core.c237
-rw-r--r--drivers/block/rsxx/cregs.c112
-rw-r--r--drivers/block/rsxx/dma.c239
-rw-r--r--drivers/block/rsxx/rsxx.h6
-rw-r--r--drivers/block/rsxx/rsxx_cfg.h2
-rw-r--r--drivers/block/rsxx/rsxx_priv.h34
-rw-r--r--drivers/block/xen-blkback/blkback.c68
-rw-r--r--drivers/block/xen-blkback/common.h40
-rw-r--r--drivers/block/xen-blkback/xenbus.c14
-rw-r--r--drivers/block/xen-blkfront.c154
-rw-r--r--drivers/bluetooth/ath3k.c8
-rw-r--r--drivers/bluetooth/btusb.c4
-rw-r--r--drivers/clk/clk-vt8500.c2
-rw-r--r--drivers/cpufreq/acpi-cpufreq.c2
-rw-r--r--drivers/cpufreq/cpufreq_stats.c12
-rw-r--r--drivers/cpufreq/intel_pstate.c34
-rw-r--r--drivers/crypto/caam/caamalg.c27
-rw-r--r--drivers/crypto/caam/compat.h1
-rw-r--r--drivers/crypto/talitos.c30
-rw-r--r--drivers/dma/dw_dmac.c23
-rw-r--r--drivers/dma/dw_dmac_regs.h1
-rw-r--r--drivers/edac/amd64_edac.c15
-rw-r--r--drivers/edac/edac_mc.c6
-rw-r--r--drivers/edac/edac_mc_sysfs.c17
-rw-r--r--drivers/extcon/extcon-max77693.c103
-rw-r--r--drivers/extcon/extcon-max8997.c56
-rw-r--r--drivers/firmware/Kconfig18
-rw-r--r--drivers/firmware/efivars.c150
-rw-r--r--drivers/gpio/gpiolib-of.c5
-rw-r--r--drivers/gpu/drm/drm_edid.c3
-rw-r--r--drivers/gpu/drm/exynos/exynos_drm_fimd.c21
-rw-r--r--drivers/gpu/drm/exynos/exynos_drm_g2d.c370
-rw-r--r--drivers/gpu/drm/exynos/exynos_drm_gem.c21
-rw-r--r--drivers/gpu/drm/exynos/exynos_drm_gem.h5
-rw-r--r--drivers/gpu/drm/exynos/exynos_drm_vidi.c6
-rw-r--r--drivers/gpu/drm/exynos/exynos_mixer.c2
-rw-r--r--drivers/gpu/drm/i915/i915_debugfs.c2
-rw-r--r--drivers/gpu/drm/i915/i915_drv.c5
-rw-r--r--drivers/gpu/drm/i915/i915_drv.h1
-rw-r--r--drivers/gpu/drm/i915/i915_gem_execbuffer.c11
-rw-r--r--drivers/gpu/drm/i915/intel_display.c10
-rw-r--r--drivers/gpu/drm/i915/intel_dp.c14
-rw-r--r--drivers/gpu/drm/i915/intel_i2c.c11
-rw-r--r--drivers/gpu/drm/i915/intel_panel.c13
-rw-r--r--drivers/gpu/drm/i915/intel_pm.c3
-rw-r--r--drivers/gpu/drm/mgag200/mgag200_mode.c10
-rw-r--r--drivers/gpu/drm/nouveau/core/core/object.c3
-rw-r--r--drivers/gpu/drm/nouveau/core/include/subdev/therm.h2
-rw-r--r--drivers/gpu/drm/nouveau/core/subdev/therm/base.c18
-rw-r--r--drivers/gpu/drm/nouveau/core/subdev/therm/ic.c6
-rw-r--r--drivers/gpu/drm/nouveau/core/subdev/therm/nv40.c67
-rw-r--r--drivers/gpu/drm/nouveau/core/subdev/therm/priv.h3
-rw-r--r--drivers/gpu/drm/nouveau/core/subdev/therm/temp.c30
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_pm.c44
-rw-r--r--drivers/gpu/drm/nouveau/nv50_display.c4
-rw-r--r--drivers/gpu/drm/radeon/ni.c33
-rw-r--r--drivers/gpu/drm/radeon/radeon_benchmark.c21
-rw-r--r--drivers/gpu/drm/radeon/si.c1
-rw-r--r--drivers/hid/hid-ids.h6
-rw-r--r--drivers/hid/hid-multitouch.c6
-rw-r--r--drivers/hid/usbhid/hid-quirks.c2
-rw-r--r--drivers/hwmon/lm75.h2
-rw-r--r--drivers/i2c/Kconfig2
-rw-r--r--drivers/i2c/busses/Kconfig6
-rw-r--r--drivers/i2c/busses/i2c-ismt.c2
-rw-r--r--drivers/i2c/busses/i2c-tegra.c13
-rw-r--r--drivers/i2c/muxes/i2c-mux-pca9541.c2
-rw-r--r--drivers/infiniband/hw/cxgb4/cm.c12
-rw-r--r--drivers/infiniband/hw/cxgb4/qp.c4
-rw-r--r--drivers/infiniband/hw/ipath/ipath_verbs.c2
-rw-r--r--drivers/infiniband/hw/qib/Kconfig6
-rw-r--r--drivers/infiniband/hw/qib/qib_driver.c5
-rw-r--r--drivers/infiniband/hw/qib/qib_iba6120.c3
-rw-r--r--drivers/infiniband/hw/qib/qib_init.c8
-rw-r--r--drivers/infiniband/hw/qib/qib_sd7220.c4
-rw-r--r--drivers/infiniband/hw/qib/qib_verbs.c4
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_cm.c8
-rw-r--r--drivers/input/joystick/analog.c8
-rw-r--r--drivers/iommu/Kconfig2
-rw-r--r--drivers/iommu/amd_iommu.c22
-rw-r--r--drivers/iommu/amd_iommu_init.c2
-rw-r--r--drivers/iommu/irq_remapping.c1
-rw-r--r--drivers/isdn/hisax/Kconfig6
-rw-r--r--drivers/md/dm-bufio.c2
-rw-r--r--drivers/md/dm-cache-metadata.c64
-rw-r--r--drivers/md/dm-cache-metadata.h2
-rw-r--r--drivers/md/dm-cache-policy-cleaner.c7
-rw-r--r--drivers/md/dm-cache-policy-internal.h2
-rw-r--r--drivers/md/dm-cache-policy-mq.c8
-rw-r--r--drivers/md/dm-cache-policy.c8
-rw-r--r--drivers/md/dm-cache-policy.h2
-rw-r--r--drivers/md/dm-cache-target.c169
-rw-r--r--drivers/md/dm-thin.c11
-rw-r--r--drivers/md/dm-verity.c39
-rw-r--r--drivers/md/md.c6
-rw-r--r--drivers/md/md.h4
-rw-r--r--drivers/md/persistent-data/dm-btree-remove.c46
-rw-r--r--drivers/md/raid5.c116
-rw-r--r--drivers/md/raid5.h5
-rw-r--r--drivers/media/i2c/m5mols/m5mols_core.c2
-rw-r--r--drivers/media/pci/bt8xx/bttv-driver.c20
-rw-r--r--drivers/media/platform/exynos-gsc/gsc-core.c8
-rw-r--r--drivers/media/platform/s5p-fimc/fimc-core.c6
-rw-r--r--drivers/media/platform/s5p-fimc/fimc-lite-reg.c8
-rw-r--r--drivers/media/platform/s5p-fimc/fimc-lite.c1
-rw-r--r--drivers/media/platform/s5p-fimc/fimc-mdevice.c39
-rw-r--r--drivers/media/platform/s5p-mfc/s5p_mfc.c2
-rw-r--r--drivers/media/platform/s5p-mfc/s5p_mfc_enc.c1
-rw-r--r--drivers/media/rc/Kconfig2
-rw-r--r--drivers/media/v4l2-core/Makefile2
-rw-r--r--drivers/misc/mei/hw-me.c29
-rw-r--r--drivers/misc/mei/init.c18
-rw-r--r--drivers/misc/mei/mei_dev.h1
-rw-r--r--drivers/misc/mei/pci-me.c52
-rw-r--r--drivers/misc/vmw_vmci/vmci_datagram.c4
-rw-r--r--drivers/mtd/bcm47xxpart.c52
-rw-r--r--drivers/mtd/nand/nand_base.c16
-rw-r--r--drivers/mtd/nand/nand_ids.c80
-rw-r--r--drivers/net/bonding/bond_main.c6
-rw-r--r--drivers/net/bonding/bond_sysfs.c5
-rw-r--r--drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c1
-rw-r--r--drivers/net/ethernet/broadcom/bnx2x/bnx2x_dcb.c18
-rw-r--r--drivers/net/ethernet/broadcom/bnx2x/bnx2x_stats.h3
-rw-r--r--drivers/net/ethernet/broadcom/tg3.c8
-rw-r--r--drivers/net/ethernet/chelsio/cxgb4/t4_hw.c12
-rw-r--r--drivers/net/ethernet/dec/tulip/Kconfig1
-rw-r--r--drivers/net/ethernet/freescale/fec.c33
-rw-r--r--drivers/net/ethernet/freescale/fec.h1
-rw-r--r--drivers/net/ethernet/freescale/fec_ptp.c3
-rw-r--r--drivers/net/ethernet/intel/igb/e1000_82575.c33
-rw-r--r--drivers/net/ethernet/intel/igb/igb_hwmon.c2
-rw-r--r--drivers/net/ethernet/intel/igb/igb_main.c4
-rw-r--r--drivers/net/ethernet/intel/igb/igb_ptp.c2
-rw-r--r--drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c24
-rw-r--r--drivers/net/ethernet/lantiq_etop.c2
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/en_netdev.c22
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/eq.c2
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/resource_tracker.c45
-rw-r--r--drivers/net/ethernet/nxp/lpc_eth.c3
-rw-r--r--drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c4
-rw-r--r--drivers/net/ethernet/renesas/sh_eth.c10
-rw-r--r--drivers/net/ethernet/renesas/sh_eth.h1
-rw-r--r--drivers/net/ethernet/sfc/nic.c3
-rw-r--r--drivers/net/ethernet/ti/cpsw.c4
-rw-r--r--drivers/net/ethernet/ti/davinci_emac.c2
-rw-r--r--drivers/net/netconsole.c15
-rw-r--r--drivers/net/usb/Kconfig2
-rw-r--r--drivers/net/usb/cdc_mbim.c11
-rw-r--r--drivers/net/usb/cdc_ncm.c49
-rw-r--r--drivers/net/usb/qmi_wwan.c49
-rw-r--r--drivers/net/wireless/ath/ath9k/ar9003_calib.c4
-rw-r--r--drivers/net/wireless/ath/ath9k/link.c26
-rw-r--r--drivers/net/wireless/iwlegacy/3945-mac.c22
-rw-r--r--drivers/net/wireless/mwifiex/cmdevt.c22
-rw-r--r--drivers/net/wireless/mwifiex/init.c8
-rw-r--r--drivers/net/wireless/mwifiex/join.c7
-rw-r--r--drivers/net/wireless/mwifiex/main.h4
-rw-r--r--drivers/net/wireless/mwifiex/scan.c8
-rw-r--r--drivers/net/wireless/mwifiex/sta_ioctl.c10
-rw-r--r--drivers/net/wireless/rt2x00/Kconfig4
-rw-r--r--drivers/net/wireless/rt2x00/rt2800pci.c14
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192cu/hw.c89
-rw-r--r--drivers/net/wireless/rtlwifi/usb.c1
-rw-r--r--drivers/pci/rom.c55
-rw-r--r--drivers/pinctrl/mvebu/pinctrl-mvebu.c2
-rw-r--r--drivers/pinctrl/pinconf.c2
-rw-r--r--drivers/pinctrl/pinconf.h2
-rw-r--r--drivers/pinctrl/pinctrl-abx500.c2
-rw-r--r--drivers/pinctrl/pinctrl-at91.c61
-rw-r--r--drivers/pinctrl/pinmux.c5
-rw-r--r--drivers/rtc/rtc-at91rm9200.c50
-rw-r--r--drivers/rtc/rtc-at91rm9200.h1
-rw-r--r--drivers/rtc/rtc-da9052.c8
-rw-r--r--drivers/s390/block/scm_blk.c69
-rw-r--r--drivers/s390/block/scm_blk.h2
-rw-r--r--drivers/s390/block/scm_drv.c23
-rw-r--r--drivers/s390/char/sclp_cmd.c2
-rw-r--r--drivers/s390/cio/chsc.c17
-rw-r--r--drivers/s390/cio/chsc.h2
-rw-r--r--drivers/s390/cio/scm.c18
-rw-r--r--drivers/s390/net/qeth_core.h1
-rw-r--r--drivers/s390/net/qeth_core_main.c45
-rw-r--r--drivers/s390/net/qeth_l3_main.c23
-rw-r--r--drivers/s390/net/qeth_l3_sys.c2
-rw-r--r--drivers/staging/comedi/drivers/s626.c2
-rw-r--r--drivers/staging/zcache/Kconfig2
-rw-r--r--drivers/target/iscsi/iscsi_target_auth.c5
-rw-r--r--drivers/target/target_core_file.h2
-rw-r--r--drivers/target/target_core_pscsi.c11
-rw-r--r--drivers/target/target_core_sbc.c7
-rw-r--r--drivers/target/target_core_tpg.c3
-rw-r--r--drivers/target/target_core_transport.c4
-rw-r--r--drivers/thermal/dove_thermal.c16
-rw-r--r--drivers/thermal/exynos_thermal.c2
-rw-r--r--drivers/thermal/kirkwood_thermal.c8
-rw-r--r--drivers/thermal/rcar_thermal.c29
-rw-r--r--drivers/tty/serial/8250/8250_core.c (renamed from drivers/tty/serial/8250/8250.c)6
-rw-r--r--drivers/tty/serial/8250/8250_pci.c13
-rw-r--r--drivers/tty/serial/8250/Kconfig17
-rw-r--r--drivers/tty/serial/8250/Makefile8
-rw-r--r--drivers/tty/serial/atmel_serial.c11
-rw-r--r--drivers/tty/serial/sunsu.c21
-rw-r--r--drivers/tty/serial/xilinx_uartps.c2
-rw-r--r--drivers/tty/vt/vc_screen.c6
-rw-r--r--drivers/usb/class/cdc-acm.c22
-rw-r--r--drivers/usb/core/hcd-pci.c23
-rw-r--r--drivers/usb/core/hcd.c8
-rw-r--r--drivers/usb/core/usb-acpi.c8
-rw-r--r--drivers/usb/gadget/Kconfig1
-rw-r--r--drivers/usb/gadget/f_rndis.c3
-rw-r--r--drivers/usb/gadget/g_ffs.c4
-rw-r--r--drivers/usb/gadget/net2272.c9
-rw-r--r--drivers/usb/gadget/net2280.c8
-rw-r--r--drivers/usb/gadget/u_serial.c2
-rw-r--r--drivers/usb/gadget/udc-core.c2
-rw-r--r--drivers/usb/host/ehci-hcd.c1
-rw-r--r--drivers/usb/host/ehci-hub.c2
-rw-r--r--drivers/usb/host/ehci-q.c13
-rw-r--r--drivers/usb/host/ehci-sched.c2
-rw-r--r--drivers/usb/host/ehci-timer.c2
-rw-r--r--drivers/usb/host/xhci-mem.c36
-rw-r--r--drivers/usb/host/xhci-pci.c1
-rw-r--r--drivers/usb/host/xhci-ring.c61
-rw-r--r--drivers/usb/host/xhci.c25
-rw-r--r--drivers/usb/host/xhci.h9
-rw-r--r--drivers/usb/musb/da8xx.c2
-rw-r--r--drivers/usb/musb/musb_gadget.c9
-rw-r--r--drivers/usb/phy/Kconfig1
-rw-r--r--drivers/usb/serial/ark3116.c10
-rw-r--r--drivers/usb/serial/ch341.c11
-rw-r--r--drivers/usb/serial/cypress_m8.c14
-rw-r--r--drivers/usb/serial/f81232.c9
-rw-r--r--drivers/usb/serial/ftdi_sio.c20
-rw-r--r--drivers/usb/serial/ftdi_sio_ids.h7
-rw-r--r--drivers/usb/serial/garmin_gps.c7
-rw-r--r--drivers/usb/serial/io_edgeport.c12
-rw-r--r--drivers/usb/serial/io_ti.c13
-rw-r--r--drivers/usb/serial/mct_u232.c13
-rw-r--r--drivers/usb/serial/mos7840.c16
-rw-r--r--drivers/usb/serial/oti6858.c10
-rw-r--r--drivers/usb/serial/pl2303.c11
-rw-r--r--drivers/usb/serial/quatech2.c12
-rw-r--r--drivers/usb/serial/spcp8x5.c9
-rw-r--r--drivers/usb/serial/ssu100.c12
-rw-r--r--drivers/usb/serial/ti_usb_3410_5052.c10
-rw-r--r--drivers/usb/serial/usb-serial.c4
-rw-r--r--drivers/usb/storage/unusual_devs.h7
-rw-r--r--drivers/vfio/pci/vfio_pci_config.c1
-rw-r--r--drivers/vfio/pci/vfio_pci_intrs.c1
-rw-r--r--drivers/vhost/net.c3
-rw-r--r--drivers/vhost/tcm_vhost.c26
-rw-r--r--drivers/video/atmel_lcdfb.c22
-rw-r--r--drivers/video/ep93xx-fb.c1
-rw-r--r--drivers/video/mxsfb.c7
-rw-r--r--drivers/video/omap/omapfb_main.c2
-rw-r--r--drivers/video/omap2/displays/panel-tpo-td043mtea1.c13
-rw-r--r--drivers/video/omap2/dss/dss_features.c6
-rw-r--r--drivers/watchdog/sp5100_tco.c126
-rw-r--r--drivers/watchdog/sp5100_tco.h2
-rw-r--r--drivers/xen/Kconfig2
-rw-r--r--drivers/xen/events.c20
-rw-r--r--drivers/xen/fallback.c3
-rw-r--r--drivers/xen/xen-acpi-processor.c3
-rw-r--r--drivers/xen/xen-pciback/pci_stub.c59
283 files changed, 3493 insertions, 1747 deletions
diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
index 1e5d8a40101e..fefc2ca7cc3e 100644
--- a/drivers/acpi/apei/cper.c
+++ b/drivers/acpi/apei/cper.c
@@ -405,7 +405,7 @@ int apei_estatus_check(const struct acpi_hest_generic_status *estatus)
405 return rc; 405 return rc;
406 data_len = estatus->data_length; 406 data_len = estatus->data_length;
407 gdata = (struct acpi_hest_generic_data *)(estatus + 1); 407 gdata = (struct acpi_hest_generic_data *)(estatus + 1);
408 while (data_len > sizeof(*gdata)) { 408 while (data_len >= sizeof(*gdata)) {
409 gedata_len = gdata->error_data_length; 409 gedata_len = gdata->error_data_length;
410 if (gedata_len > data_len - sizeof(*gdata)) 410 if (gedata_len > data_len - sizeof(*gdata))
411 return -EINVAL; 411 return -EINVAL;
diff --git a/drivers/acpi/pci_root.c b/drivers/acpi/pci_root.c
index 0ac546d5e53f..5ff173066127 100644
--- a/drivers/acpi/pci_root.c
+++ b/drivers/acpi/pci_root.c
@@ -646,6 +646,7 @@ static void handle_root_bridge_insertion(acpi_handle handle)
646 646
647static void handle_root_bridge_removal(struct acpi_device *device) 647static void handle_root_bridge_removal(struct acpi_device *device)
648{ 648{
649 acpi_status status;
649 struct acpi_eject_event *ej_event; 650 struct acpi_eject_event *ej_event;
650 651
651 ej_event = kmalloc(sizeof(*ej_event), GFP_KERNEL); 652 ej_event = kmalloc(sizeof(*ej_event), GFP_KERNEL);
@@ -661,7 +662,9 @@ static void handle_root_bridge_removal(struct acpi_device *device)
661 ej_event->device = device; 662 ej_event->device = device;
662 ej_event->event = ACPI_NOTIFY_EJECT_REQUEST; 663 ej_event->event = ACPI_NOTIFY_EJECT_REQUEST;
663 664
664 acpi_bus_hot_remove_device(ej_event); 665 status = acpi_os_hotplug_execute(acpi_bus_hot_remove_device, ej_event);
666 if (ACPI_FAILURE(status))
667 kfree(ej_event);
665} 668}
666 669
667static void _handle_hotplug_event_root(struct work_struct *work) 670static void _handle_hotplug_event_root(struct work_struct *work)
@@ -676,8 +679,9 @@ static void _handle_hotplug_event_root(struct work_struct *work)
676 handle = hp_work->handle; 679 handle = hp_work->handle;
677 type = hp_work->type; 680 type = hp_work->type;
678 681
679 root = acpi_pci_find_root(handle); 682 acpi_scan_lock_acquire();
680 683
684 root = acpi_pci_find_root(handle);
681 acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer); 685 acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
682 686
683 switch (type) { 687 switch (type) {
@@ -711,6 +715,7 @@ static void _handle_hotplug_event_root(struct work_struct *work)
711 break; 715 break;
712 } 716 }
713 717
718 acpi_scan_lock_release();
714 kfree(hp_work); /* allocated in handle_hotplug_event_bridge */ 719 kfree(hp_work); /* allocated in handle_hotplug_event_bridge */
715 kfree(buffer.pointer); 720 kfree(buffer.pointer);
716} 721}
diff --git a/drivers/acpi/sleep.c b/drivers/acpi/sleep.c
index 24213033fbae..9c1a435d10e6 100644
--- a/drivers/acpi/sleep.c
+++ b/drivers/acpi/sleep.c
@@ -193,6 +193,14 @@ static struct dmi_system_id __initdata acpisleep_dmi_table[] = {
193 }, 193 },
194 { 194 {
195 .callback = init_nvs_nosave, 195 .callback = init_nvs_nosave,
196 .ident = "Sony Vaio VGN-FW21M",
197 .matches = {
198 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
199 DMI_MATCH(DMI_PRODUCT_NAME, "VGN-FW21M"),
200 },
201 },
202 {
203 .callback = init_nvs_nosave,
196 .ident = "Sony Vaio VPCEB17FX", 204 .ident = "Sony Vaio VPCEB17FX",
197 .matches = { 205 .matches = {
198 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"), 206 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
diff --git a/drivers/amba/tegra-ahb.c b/drivers/amba/tegra-ahb.c
index 093c43554963..1f44e56cc65d 100644
--- a/drivers/amba/tegra-ahb.c
+++ b/drivers/amba/tegra-ahb.c
@@ -158,7 +158,7 @@ int tegra_ahb_enable_smmu(struct device_node *dn)
158EXPORT_SYMBOL(tegra_ahb_enable_smmu); 158EXPORT_SYMBOL(tegra_ahb_enable_smmu);
159#endif 159#endif
160 160
161#ifdef CONFIG_PM_SLEEP 161#ifdef CONFIG_PM
162static int tegra_ahb_suspend(struct device *dev) 162static int tegra_ahb_suspend(struct device *dev)
163{ 163{
164 int i; 164 int i;
diff --git a/drivers/ata/Kconfig b/drivers/ata/Kconfig
index 3e751b74615e..a5a3ebcbdd2c 100644
--- a/drivers/ata/Kconfig
+++ b/drivers/ata/Kconfig
@@ -59,15 +59,16 @@ config ATA_ACPI
59 option libata.noacpi=1 59 option libata.noacpi=1
60 60
61config SATA_ZPODD 61config SATA_ZPODD
62 bool "SATA Zero Power ODD Support" 62 bool "SATA Zero Power Optical Disc Drive (ZPODD) support"
63 depends on ATA_ACPI 63 depends on ATA_ACPI
64 default n 64 default n
65 help 65 help
66 This option adds support for SATA ZPODD. It requires both 66 This option adds support for SATA Zero Power Optical Disc
67 ODD and the platform support, and if enabled, will automatically 67 Drive (ZPODD). It requires both the ODD and the platform
68 power on/off the ODD when certain condition is satisfied. This 68 support, and if enabled, will automatically power on/off the
69 does not impact user's experience of the ODD, only power is saved 69 ODD when certain condition is satisfied. This does not impact
70 when ODD is not in use(i.e. no disc inside). 70 end user's experience of the ODD, only power is saved when
71 the ODD is not in use (i.e. no disc inside).
71 72
72 If unsure, say N. 73 If unsure, say N.
73 74
diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
index a99112cfd8b1..6a67b07de494 100644
--- a/drivers/ata/ahci.c
+++ b/drivers/ata/ahci.c
@@ -281,6 +281,8 @@ static const struct pci_device_id ahci_pci_tbl[] = {
281 { PCI_VDEVICE(INTEL, 0x1f37), board_ahci }, /* Avoton RAID */ 281 { PCI_VDEVICE(INTEL, 0x1f37), board_ahci }, /* Avoton RAID */
282 { PCI_VDEVICE(INTEL, 0x1f3e), board_ahci }, /* Avoton RAID */ 282 { PCI_VDEVICE(INTEL, 0x1f3e), board_ahci }, /* Avoton RAID */
283 { PCI_VDEVICE(INTEL, 0x1f3f), board_ahci }, /* Avoton RAID */ 283 { PCI_VDEVICE(INTEL, 0x1f3f), board_ahci }, /* Avoton RAID */
284 { PCI_VDEVICE(INTEL, 0x2823), board_ahci }, /* Wellsburg RAID */
285 { PCI_VDEVICE(INTEL, 0x2827), board_ahci }, /* Wellsburg RAID */
284 { PCI_VDEVICE(INTEL, 0x8d02), board_ahci }, /* Wellsburg AHCI */ 286 { PCI_VDEVICE(INTEL, 0x8d02), board_ahci }, /* Wellsburg AHCI */
285 { PCI_VDEVICE(INTEL, 0x8d04), board_ahci }, /* Wellsburg RAID */ 287 { PCI_VDEVICE(INTEL, 0x8d04), board_ahci }, /* Wellsburg RAID */
286 { PCI_VDEVICE(INTEL, 0x8d06), board_ahci }, /* Wellsburg RAID */ 288 { PCI_VDEVICE(INTEL, 0x8d06), board_ahci }, /* Wellsburg RAID */
diff --git a/drivers/ata/ata_piix.c b/drivers/ata/ata_piix.c
index d2ba439cfe54..ffdd32d22602 100644
--- a/drivers/ata/ata_piix.c
+++ b/drivers/ata/ata_piix.c
@@ -1547,6 +1547,10 @@ static bool piix_broken_system_poweroff(struct pci_dev *pdev)
1547 1547
1548static int prefer_ms_hyperv = 1; 1548static int prefer_ms_hyperv = 1;
1549module_param(prefer_ms_hyperv, int, 0); 1549module_param(prefer_ms_hyperv, int, 0);
1550MODULE_PARM_DESC(prefer_ms_hyperv,
1551 "Prefer Hyper-V paravirtualization drivers instead of ATA, "
1552 "0 - Use ATA drivers, "
1553 "1 (Default) - Use the paravirtualization drivers.");
1550 1554
1551static void piix_ignore_devices_quirk(struct ata_host *host) 1555static void piix_ignore_devices_quirk(struct ata_host *host)
1552{ 1556{
diff --git a/drivers/ata/libata-acpi.c b/drivers/ata/libata-acpi.c
index beea3115577e..8a52dab412e2 100644
--- a/drivers/ata/libata-acpi.c
+++ b/drivers/ata/libata-acpi.c
@@ -1027,7 +1027,7 @@ static void ata_acpi_register_power_resource(struct ata_device *dev)
1027 1027
1028 handle = ata_dev_acpi_handle(dev); 1028 handle = ata_dev_acpi_handle(dev);
1029 if (handle) 1029 if (handle)
1030 acpi_dev_pm_remove_dependent(handle, &sdev->sdev_gendev); 1030 acpi_dev_pm_add_dependent(handle, &sdev->sdev_gendev);
1031} 1031}
1032 1032
1033static void ata_acpi_unregister_power_resource(struct ata_device *dev) 1033static void ata_acpi_unregister_power_resource(struct ata_device *dev)
diff --git a/drivers/ata/pata_samsung_cf.c b/drivers/ata/pata_samsung_cf.c
index 70b0e01372b3..6ef27e98c508 100644
--- a/drivers/ata/pata_samsung_cf.c
+++ b/drivers/ata/pata_samsung_cf.c
@@ -661,18 +661,7 @@ static struct platform_driver pata_s3c_driver = {
661 }, 661 },
662}; 662};
663 663
664static int __init pata_s3c_init(void) 664module_platform_driver_probe(pata_s3c_driver, pata_s3c_probe);
665{
666 return platform_driver_probe(&pata_s3c_driver, pata_s3c_probe);
667}
668
669static void __exit pata_s3c_exit(void)
670{
671 platform_driver_unregister(&pata_s3c_driver);
672}
673
674module_init(pata_s3c_init);
675module_exit(pata_s3c_exit);
676 665
677MODULE_AUTHOR("Abhilash Kesavan, <a.kesavan@samsung.com>"); 666MODULE_AUTHOR("Abhilash Kesavan, <a.kesavan@samsung.com>");
678MODULE_DESCRIPTION("low-level driver for Samsung PATA controller"); 667MODULE_DESCRIPTION("low-level driver for Samsung PATA controller");
diff --git a/drivers/ata/sata_fsl.c b/drivers/ata/sata_fsl.c
index 124b2c1d9c0b..608f82fed632 100644
--- a/drivers/ata/sata_fsl.c
+++ b/drivers/ata/sata_fsl.c
@@ -1511,8 +1511,7 @@ error_exit_with_cleanup:
1511 1511
1512 if (hcr_base) 1512 if (hcr_base)
1513 iounmap(hcr_base); 1513 iounmap(hcr_base);
1514 if (host_priv) 1514 kfree(host_priv);
1515 kfree(host_priv);
1516 1515
1517 return retval; 1516 return retval;
1518} 1517}
diff --git a/drivers/block/Kconfig b/drivers/block/Kconfig
index 5dc0daed8fac..b81ddfea1da0 100644
--- a/drivers/block/Kconfig
+++ b/drivers/block/Kconfig
@@ -532,11 +532,11 @@ config BLK_DEV_RBD
532 If unsure, say N. 532 If unsure, say N.
533 533
534config BLK_DEV_RSXX 534config BLK_DEV_RSXX
535 tristate "RamSam PCIe Flash SSD Device Driver" 535 tristate "IBM FlashSystem 70/80 PCIe SSD Device Driver"
536 depends on PCI 536 depends on PCI
537 help 537 help
538 Device driver for IBM's high speed PCIe SSD 538 Device driver for IBM's high speed PCIe SSD
539 storage devices: RamSan-70 and RamSan-80. 539 storage devices: FlashSystem-70 and FlashSystem-80.
540 540
541 To compile this driver as a module, choose M here: the 541 To compile this driver as a module, choose M here: the
542 module will be called rsxx. 542 module will be called rsxx.
diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
index ade58bc8f3c4..1c1b8e544aa2 100644
--- a/drivers/block/cciss.c
+++ b/drivers/block/cciss.c
@@ -4206,7 +4206,7 @@ static int cciss_find_cfgtables(ctlr_info_t *h)
4206 if (rc) 4206 if (rc)
4207 return rc; 4207 return rc;
4208 h->cfgtable = remap_pci_mem(pci_resource_start(h->pdev, 4208 h->cfgtable = remap_pci_mem(pci_resource_start(h->pdev,
4209 cfg_base_addr_index) + cfg_offset, sizeof(h->cfgtable)); 4209 cfg_base_addr_index) + cfg_offset, sizeof(*h->cfgtable));
4210 if (!h->cfgtable) 4210 if (!h->cfgtable)
4211 return -ENOMEM; 4211 return -ENOMEM;
4212 rc = write_driver_ver_to_cfgtable(h->cfgtable); 4212 rc = write_driver_ver_to_cfgtable(h->cfgtable);
diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index 747bb2af69dc..fe5f6403417f 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -1044,12 +1044,29 @@ static int loop_clr_fd(struct loop_device *lo)
1044 lo->lo_state = Lo_unbound; 1044 lo->lo_state = Lo_unbound;
1045 /* This is safe: open() is still holding a reference. */ 1045 /* This is safe: open() is still holding a reference. */
1046 module_put(THIS_MODULE); 1046 module_put(THIS_MODULE);
1047 if (lo->lo_flags & LO_FLAGS_PARTSCAN && bdev)
1048 ioctl_by_bdev(bdev, BLKRRPART, 0);
1049 lo->lo_flags = 0; 1047 lo->lo_flags = 0;
1050 if (!part_shift) 1048 if (!part_shift)
1051 lo->lo_disk->flags |= GENHD_FL_NO_PART_SCAN; 1049 lo->lo_disk->flags |= GENHD_FL_NO_PART_SCAN;
1052 mutex_unlock(&lo->lo_ctl_mutex); 1050 mutex_unlock(&lo->lo_ctl_mutex);
1051
1052 /*
1053 * Remove all partitions, since BLKRRPART won't remove user
1054 * added partitions when max_part=0
1055 */
1056 if (bdev) {
1057 struct disk_part_iter piter;
1058 struct hd_struct *part;
1059
1060 mutex_lock_nested(&bdev->bd_mutex, 1);
1061 invalidate_partition(bdev->bd_disk, 0);
1062 disk_part_iter_init(&piter, bdev->bd_disk,
1063 DISK_PITER_INCL_EMPTY);
1064 while ((part = disk_part_iter_next(&piter)))
1065 delete_partition(bdev->bd_disk, part->partno);
1066 disk_part_iter_exit(&piter);
1067 mutex_unlock(&bdev->bd_mutex);
1068 }
1069
1053 /* 1070 /*
1054 * Need not hold lo_ctl_mutex to fput backing file. 1071 * Need not hold lo_ctl_mutex to fput backing file.
1055 * Calling fput holding lo_ctl_mutex triggers a circular 1072 * Calling fput holding lo_ctl_mutex triggers a circular
@@ -1623,6 +1640,7 @@ static int loop_add(struct loop_device **l, int i)
1623 goto out_free_dev; 1640 goto out_free_dev;
1624 i = err; 1641 i = err;
1625 1642
1643 err = -ENOMEM;
1626 lo->lo_queue = blk_alloc_queue(GFP_KERNEL); 1644 lo->lo_queue = blk_alloc_queue(GFP_KERNEL);
1627 if (!lo->lo_queue) 1645 if (!lo->lo_queue)
1628 goto out_free_dev; 1646 goto out_free_dev;
diff --git a/drivers/block/mg_disk.c b/drivers/block/mg_disk.c
index 1788f491e0fb..076ae7f1b781 100644
--- a/drivers/block/mg_disk.c
+++ b/drivers/block/mg_disk.c
@@ -890,8 +890,10 @@ static int mg_probe(struct platform_device *plat_dev)
890 gpio_direction_output(host->rst, 1); 890 gpio_direction_output(host->rst, 1);
891 891
892 /* reset out pin */ 892 /* reset out pin */
893 if (!(prv_data->dev_attr & MG_DEV_MASK)) 893 if (!(prv_data->dev_attr & MG_DEV_MASK)) {
894 err = -EINVAL;
894 goto probe_err_3a; 895 goto probe_err_3a;
896 }
895 897
896 if (prv_data->dev_attr != MG_BOOT_DEV) { 898 if (prv_data->dev_attr != MG_BOOT_DEV) {
897 rsc = platform_get_resource_byname(plat_dev, IORESOURCE_IO, 899 rsc = platform_get_resource_byname(plat_dev, IORESOURCE_IO,
diff --git a/drivers/block/mtip32xx/mtip32xx.c b/drivers/block/mtip32xx/mtip32xx.c
index 11cc9522cdd4..92250af84e7d 100644
--- a/drivers/block/mtip32xx/mtip32xx.c
+++ b/drivers/block/mtip32xx/mtip32xx.c
@@ -4224,6 +4224,7 @@ static int mtip_pci_probe(struct pci_dev *pdev,
4224 dd->isr_workq = create_workqueue(dd->workq_name); 4224 dd->isr_workq = create_workqueue(dd->workq_name);
4225 if (!dd->isr_workq) { 4225 if (!dd->isr_workq) {
4226 dev_warn(&pdev->dev, "Can't create wq %d\n", dd->instance); 4226 dev_warn(&pdev->dev, "Can't create wq %d\n", dd->instance);
4227 rv = -ENOMEM;
4227 goto block_initialize_err; 4228 goto block_initialize_err;
4228 } 4229 }
4229 4230
@@ -4282,7 +4283,8 @@ static int mtip_pci_probe(struct pci_dev *pdev,
4282 INIT_WORK(&dd->work[7].work, mtip_workq_sdbf7); 4283 INIT_WORK(&dd->work[7].work, mtip_workq_sdbf7);
4283 4284
4284 pci_set_master(pdev); 4285 pci_set_master(pdev);
4285 if (pci_enable_msi(pdev)) { 4286 rv = pci_enable_msi(pdev);
4287 if (rv) {
4286 dev_warn(&pdev->dev, 4288 dev_warn(&pdev->dev,
4287 "Unable to enable MSI interrupt.\n"); 4289 "Unable to enable MSI interrupt.\n");
4288 goto block_initialize_err; 4290 goto block_initialize_err;
diff --git a/drivers/block/nvme.c b/drivers/block/nvme.c
index 07fb2dfaae13..9dcefe40380b 100644
--- a/drivers/block/nvme.c
+++ b/drivers/block/nvme.c
@@ -135,6 +135,7 @@ static inline void _nvme_check_size(void)
135 BUILD_BUG_ON(sizeof(struct nvme_id_ctrl) != 4096); 135 BUILD_BUG_ON(sizeof(struct nvme_id_ctrl) != 4096);
136 BUILD_BUG_ON(sizeof(struct nvme_id_ns) != 4096); 136 BUILD_BUG_ON(sizeof(struct nvme_id_ns) != 4096);
137 BUILD_BUG_ON(sizeof(struct nvme_lba_range_type) != 64); 137 BUILD_BUG_ON(sizeof(struct nvme_lba_range_type) != 64);
138 BUILD_BUG_ON(sizeof(struct nvme_smart_log) != 512);
138} 139}
139 140
140typedef void (*nvme_completion_fn)(struct nvme_dev *, void *, 141typedef void (*nvme_completion_fn)(struct nvme_dev *, void *,
@@ -237,7 +238,8 @@ static void *free_cmdid(struct nvme_queue *nvmeq, int cmdid,
237 *fn = special_completion; 238 *fn = special_completion;
238 return CMD_CTX_INVALID; 239 return CMD_CTX_INVALID;
239 } 240 }
240 *fn = info[cmdid].fn; 241 if (fn)
242 *fn = info[cmdid].fn;
241 ctx = info[cmdid].ctx; 243 ctx = info[cmdid].ctx;
242 info[cmdid].fn = special_completion; 244 info[cmdid].fn = special_completion;
243 info[cmdid].ctx = CMD_CTX_COMPLETED; 245 info[cmdid].ctx = CMD_CTX_COMPLETED;
@@ -335,6 +337,7 @@ nvme_alloc_iod(unsigned nseg, unsigned nbytes, gfp_t gfp)
335 iod->offset = offsetof(struct nvme_iod, sg[nseg]); 337 iod->offset = offsetof(struct nvme_iod, sg[nseg]);
336 iod->npages = -1; 338 iod->npages = -1;
337 iod->length = nbytes; 339 iod->length = nbytes;
340 iod->nents = 0;
338 } 341 }
339 342
340 return iod; 343 return iod;
@@ -375,7 +378,8 @@ static void bio_completion(struct nvme_dev *dev, void *ctx,
375 struct bio *bio = iod->private; 378 struct bio *bio = iod->private;
376 u16 status = le16_to_cpup(&cqe->status) >> 1; 379 u16 status = le16_to_cpup(&cqe->status) >> 1;
377 380
378 dma_unmap_sg(&dev->pci_dev->dev, iod->sg, iod->nents, 381 if (iod->nents)
382 dma_unmap_sg(&dev->pci_dev->dev, iod->sg, iod->nents,
379 bio_data_dir(bio) ? DMA_TO_DEVICE : DMA_FROM_DEVICE); 383 bio_data_dir(bio) ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
380 nvme_free_iod(dev, iod); 384 nvme_free_iod(dev, iod);
381 if (status) { 385 if (status) {
@@ -589,7 +593,7 @@ static int nvme_submit_bio_queue(struct nvme_queue *nvmeq, struct nvme_ns *ns,
589 593
590 result = nvme_map_bio(nvmeq->q_dmadev, iod, bio, dma_dir, psegs); 594 result = nvme_map_bio(nvmeq->q_dmadev, iod, bio, dma_dir, psegs);
591 if (result < 0) 595 if (result < 0)
592 goto free_iod; 596 goto free_cmdid;
593 length = result; 597 length = result;
594 598
595 cmnd->rw.command_id = cmdid; 599 cmnd->rw.command_id = cmdid;
@@ -609,6 +613,8 @@ static int nvme_submit_bio_queue(struct nvme_queue *nvmeq, struct nvme_ns *ns,
609 613
610 return 0; 614 return 0;
611 615
616 free_cmdid:
617 free_cmdid(nvmeq, cmdid, NULL);
612 free_iod: 618 free_iod:
613 nvme_free_iod(nvmeq->dev, iod); 619 nvme_free_iod(nvmeq->dev, iod);
614 nomem: 620 nomem:
@@ -835,8 +841,8 @@ static int nvme_identify(struct nvme_dev *dev, unsigned nsid, unsigned cns,
835 return nvme_submit_admin_cmd(dev, &c, NULL); 841 return nvme_submit_admin_cmd(dev, &c, NULL);
836} 842}
837 843
838static int nvme_get_features(struct nvme_dev *dev, unsigned fid, 844static int nvme_get_features(struct nvme_dev *dev, unsigned fid, unsigned nsid,
839 unsigned nsid, dma_addr_t dma_addr) 845 dma_addr_t dma_addr, u32 *result)
840{ 846{
841 struct nvme_command c; 847 struct nvme_command c;
842 848
@@ -846,7 +852,7 @@ static int nvme_get_features(struct nvme_dev *dev, unsigned fid,
846 c.features.prp1 = cpu_to_le64(dma_addr); 852 c.features.prp1 = cpu_to_le64(dma_addr);
847 c.features.fid = cpu_to_le32(fid); 853 c.features.fid = cpu_to_le32(fid);
848 854
849 return nvme_submit_admin_cmd(dev, &c, NULL); 855 return nvme_submit_admin_cmd(dev, &c, result);
850} 856}
851 857
852static int nvme_set_features(struct nvme_dev *dev, unsigned fid, 858static int nvme_set_features(struct nvme_dev *dev, unsigned fid,
@@ -906,6 +912,10 @@ static void nvme_free_queue(struct nvme_dev *dev, int qid)
906 912
907 spin_lock_irq(&nvmeq->q_lock); 913 spin_lock_irq(&nvmeq->q_lock);
908 nvme_cancel_ios(nvmeq, false); 914 nvme_cancel_ios(nvmeq, false);
915 while (bio_list_peek(&nvmeq->sq_cong)) {
916 struct bio *bio = bio_list_pop(&nvmeq->sq_cong);
917 bio_endio(bio, -EIO);
918 }
909 spin_unlock_irq(&nvmeq->q_lock); 919 spin_unlock_irq(&nvmeq->q_lock);
910 920
911 irq_set_affinity_hint(vector, NULL); 921 irq_set_affinity_hint(vector, NULL);
@@ -1230,12 +1240,17 @@ static int nvme_user_admin_cmd(struct nvme_dev *dev,
1230 if (length != cmd.data_len) 1240 if (length != cmd.data_len)
1231 status = -ENOMEM; 1241 status = -ENOMEM;
1232 else 1242 else
1233 status = nvme_submit_admin_cmd(dev, &c, NULL); 1243 status = nvme_submit_admin_cmd(dev, &c, &cmd.result);
1234 1244
1235 if (cmd.data_len) { 1245 if (cmd.data_len) {
1236 nvme_unmap_user_pages(dev, cmd.opcode & 1, iod); 1246 nvme_unmap_user_pages(dev, cmd.opcode & 1, iod);
1237 nvme_free_iod(dev, iod); 1247 nvme_free_iod(dev, iod);
1238 } 1248 }
1249
1250 if (!status && copy_to_user(&ucmd->result, &cmd.result,
1251 sizeof(cmd.result)))
1252 status = -EFAULT;
1253
1239 return status; 1254 return status;
1240} 1255}
1241 1256
@@ -1523,9 +1538,9 @@ static int nvme_dev_add(struct nvme_dev *dev)
1523 continue; 1538 continue;
1524 1539
1525 res = nvme_get_features(dev, NVME_FEAT_LBA_RANGE, i, 1540 res = nvme_get_features(dev, NVME_FEAT_LBA_RANGE, i,
1526 dma_addr + 4096); 1541 dma_addr + 4096, NULL);
1527 if (res) 1542 if (res)
1528 continue; 1543 memset(mem + 4096, 0, 4096);
1529 1544
1530 ns = nvme_alloc_ns(dev, i, mem, mem + 4096); 1545 ns = nvme_alloc_ns(dev, i, mem, mem + 4096);
1531 if (ns) 1546 if (ns)
diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index 6c81a4c040b9..f556f8a8b3f9 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -1264,6 +1264,32 @@ static bool obj_request_done_test(struct rbd_obj_request *obj_request)
1264 return atomic_read(&obj_request->done) != 0; 1264 return atomic_read(&obj_request->done) != 0;
1265} 1265}
1266 1266
1267static void
1268rbd_img_obj_request_read_callback(struct rbd_obj_request *obj_request)
1269{
1270 dout("%s: obj %p img %p result %d %llu/%llu\n", __func__,
1271 obj_request, obj_request->img_request, obj_request->result,
1272 obj_request->xferred, obj_request->length);
1273 /*
1274 * ENOENT means a hole in the image. We zero-fill the
1275 * entire length of the request. A short read also implies
1276 * zero-fill to the end of the request. Either way we
1277 * update the xferred count to indicate the whole request
1278 * was satisfied.
1279 */
1280 BUG_ON(obj_request->type != OBJ_REQUEST_BIO);
1281 if (obj_request->result == -ENOENT) {
1282 zero_bio_chain(obj_request->bio_list, 0);
1283 obj_request->result = 0;
1284 obj_request->xferred = obj_request->length;
1285 } else if (obj_request->xferred < obj_request->length &&
1286 !obj_request->result) {
1287 zero_bio_chain(obj_request->bio_list, obj_request->xferred);
1288 obj_request->xferred = obj_request->length;
1289 }
1290 obj_request_done_set(obj_request);
1291}
1292
1267static void rbd_obj_request_complete(struct rbd_obj_request *obj_request) 1293static void rbd_obj_request_complete(struct rbd_obj_request *obj_request)
1268{ 1294{
1269 dout("%s: obj %p cb %p\n", __func__, obj_request, 1295 dout("%s: obj %p cb %p\n", __func__, obj_request,
@@ -1284,23 +1310,10 @@ static void rbd_osd_read_callback(struct rbd_obj_request *obj_request)
1284{ 1310{
1285 dout("%s: obj %p result %d %llu/%llu\n", __func__, obj_request, 1311 dout("%s: obj %p result %d %llu/%llu\n", __func__, obj_request,
1286 obj_request->result, obj_request->xferred, obj_request->length); 1312 obj_request->result, obj_request->xferred, obj_request->length);
1287 /* 1313 if (obj_request->img_request)
1288 * ENOENT means a hole in the object. We zero-fill the 1314 rbd_img_obj_request_read_callback(obj_request);
1289 * entire length of the request. A short read also implies 1315 else
1290 * zero-fill to the end of the request. Either way we 1316 obj_request_done_set(obj_request);
1291 * update the xferred count to indicate the whole request
1292 * was satisfied.
1293 */
1294 if (obj_request->result == -ENOENT) {
1295 zero_bio_chain(obj_request->bio_list, 0);
1296 obj_request->result = 0;
1297 obj_request->xferred = obj_request->length;
1298 } else if (obj_request->xferred < obj_request->length &&
1299 !obj_request->result) {
1300 zero_bio_chain(obj_request->bio_list, obj_request->xferred);
1301 obj_request->xferred = obj_request->length;
1302 }
1303 obj_request_done_set(obj_request);
1304} 1317}
1305 1318
1306static void rbd_osd_write_callback(struct rbd_obj_request *obj_request) 1319static void rbd_osd_write_callback(struct rbd_obj_request *obj_request)
diff --git a/drivers/block/rsxx/Makefile b/drivers/block/rsxx/Makefile
index f35cd0b71f7b..b1c53c0aa450 100644
--- a/drivers/block/rsxx/Makefile
+++ b/drivers/block/rsxx/Makefile
@@ -1,2 +1,2 @@
1obj-$(CONFIG_BLK_DEV_RSXX) += rsxx.o 1obj-$(CONFIG_BLK_DEV_RSXX) += rsxx.o
2rsxx-y := config.o core.o cregs.o dev.o dma.o 2rsxx-objs := config.o core.o cregs.o dev.o dma.o
diff --git a/drivers/block/rsxx/config.c b/drivers/block/rsxx/config.c
index a295e7e9ee41..10cd530d3e10 100644
--- a/drivers/block/rsxx/config.c
+++ b/drivers/block/rsxx/config.c
@@ -29,15 +29,13 @@
29#include "rsxx_priv.h" 29#include "rsxx_priv.h"
30#include "rsxx_cfg.h" 30#include "rsxx_cfg.h"
31 31
32static void initialize_config(void *config) 32static void initialize_config(struct rsxx_card_cfg *cfg)
33{ 33{
34 struct rsxx_card_cfg *cfg = config;
35
36 cfg->hdr.version = RSXX_CFG_VERSION; 34 cfg->hdr.version = RSXX_CFG_VERSION;
37 35
38 cfg->data.block_size = RSXX_HW_BLK_SIZE; 36 cfg->data.block_size = RSXX_HW_BLK_SIZE;
39 cfg->data.stripe_size = RSXX_HW_BLK_SIZE; 37 cfg->data.stripe_size = RSXX_HW_BLK_SIZE;
40 cfg->data.vendor_id = RSXX_VENDOR_ID_TMS_IBM; 38 cfg->data.vendor_id = RSXX_VENDOR_ID_IBM;
41 cfg->data.cache_order = (-1); 39 cfg->data.cache_order = (-1);
42 cfg->data.intr_coal.mode = RSXX_INTR_COAL_DISABLED; 40 cfg->data.intr_coal.mode = RSXX_INTR_COAL_DISABLED;
43 cfg->data.intr_coal.count = 0; 41 cfg->data.intr_coal.count = 0;
@@ -181,7 +179,7 @@ int rsxx_load_config(struct rsxx_cardinfo *card)
181 } else { 179 } else {
182 dev_info(CARD_TO_DEV(card), 180 dev_info(CARD_TO_DEV(card),
183 "Initializing card configuration.\n"); 181 "Initializing card configuration.\n");
184 initialize_config(card); 182 initialize_config(&card->config);
185 st = rsxx_save_config(card); 183 st = rsxx_save_config(card);
186 if (st) 184 if (st)
187 return st; 185 return st;
diff --git a/drivers/block/rsxx/core.c b/drivers/block/rsxx/core.c
index e5162487686a..5af21f2db29c 100644
--- a/drivers/block/rsxx/core.c
+++ b/drivers/block/rsxx/core.c
@@ -30,6 +30,7 @@
30#include <linux/reboot.h> 30#include <linux/reboot.h>
31#include <linux/slab.h> 31#include <linux/slab.h>
32#include <linux/bitops.h> 32#include <linux/bitops.h>
33#include <linux/delay.h>
33 34
34#include <linux/genhd.h> 35#include <linux/genhd.h>
35#include <linux/idr.h> 36#include <linux/idr.h>
@@ -39,8 +40,8 @@
39 40
40#define NO_LEGACY 0 41#define NO_LEGACY 0
41 42
42MODULE_DESCRIPTION("IBM RamSan PCIe Flash SSD Device Driver"); 43MODULE_DESCRIPTION("IBM FlashSystem 70/80 PCIe SSD Device Driver");
43MODULE_AUTHOR("IBM <support@ramsan.com>"); 44MODULE_AUTHOR("Joshua Morris/Philip Kelleher, IBM");
44MODULE_LICENSE("GPL"); 45MODULE_LICENSE("GPL");
45MODULE_VERSION(DRIVER_VERSION); 46MODULE_VERSION(DRIVER_VERSION);
46 47
@@ -52,6 +53,13 @@ static DEFINE_IDA(rsxx_disk_ida);
52static DEFINE_SPINLOCK(rsxx_ida_lock); 53static DEFINE_SPINLOCK(rsxx_ida_lock);
53 54
54/*----------------- Interrupt Control & Handling -------------------*/ 55/*----------------- Interrupt Control & Handling -------------------*/
56
57static void rsxx_mask_interrupts(struct rsxx_cardinfo *card)
58{
59 card->isr_mask = 0;
60 card->ier_mask = 0;
61}
62
55static void __enable_intr(unsigned int *mask, unsigned int intr) 63static void __enable_intr(unsigned int *mask, unsigned int intr)
56{ 64{
57 *mask |= intr; 65 *mask |= intr;
@@ -71,7 +79,8 @@ static void __disable_intr(unsigned int *mask, unsigned int intr)
71 */ 79 */
72void rsxx_enable_ier(struct rsxx_cardinfo *card, unsigned int intr) 80void rsxx_enable_ier(struct rsxx_cardinfo *card, unsigned int intr)
73{ 81{
74 if (unlikely(card->halt)) 82 if (unlikely(card->halt) ||
83 unlikely(card->eeh_state))
75 return; 84 return;
76 85
77 __enable_intr(&card->ier_mask, intr); 86 __enable_intr(&card->ier_mask, intr);
@@ -80,6 +89,9 @@ void rsxx_enable_ier(struct rsxx_cardinfo *card, unsigned int intr)
80 89
81void rsxx_disable_ier(struct rsxx_cardinfo *card, unsigned int intr) 90void rsxx_disable_ier(struct rsxx_cardinfo *card, unsigned int intr)
82{ 91{
92 if (unlikely(card->eeh_state))
93 return;
94
83 __disable_intr(&card->ier_mask, intr); 95 __disable_intr(&card->ier_mask, intr);
84 iowrite32(card->ier_mask, card->regmap + IER); 96 iowrite32(card->ier_mask, card->regmap + IER);
85} 97}
@@ -87,7 +99,8 @@ void rsxx_disable_ier(struct rsxx_cardinfo *card, unsigned int intr)
87void rsxx_enable_ier_and_isr(struct rsxx_cardinfo *card, 99void rsxx_enable_ier_and_isr(struct rsxx_cardinfo *card,
88 unsigned int intr) 100 unsigned int intr)
89{ 101{
90 if (unlikely(card->halt)) 102 if (unlikely(card->halt) ||
103 unlikely(card->eeh_state))
91 return; 104 return;
92 105
93 __enable_intr(&card->isr_mask, intr); 106 __enable_intr(&card->isr_mask, intr);
@@ -97,6 +110,9 @@ void rsxx_enable_ier_and_isr(struct rsxx_cardinfo *card,
97void rsxx_disable_ier_and_isr(struct rsxx_cardinfo *card, 110void rsxx_disable_ier_and_isr(struct rsxx_cardinfo *card,
98 unsigned int intr) 111 unsigned int intr)
99{ 112{
113 if (unlikely(card->eeh_state))
114 return;
115
100 __disable_intr(&card->isr_mask, intr); 116 __disable_intr(&card->isr_mask, intr);
101 __disable_intr(&card->ier_mask, intr); 117 __disable_intr(&card->ier_mask, intr);
102 iowrite32(card->ier_mask, card->regmap + IER); 118 iowrite32(card->ier_mask, card->regmap + IER);
@@ -115,6 +131,9 @@ static irqreturn_t rsxx_isr(int irq, void *pdata)
115 do { 131 do {
116 reread_isr = 0; 132 reread_isr = 0;
117 133
134 if (unlikely(card->eeh_state))
135 break;
136
118 isr = ioread32(card->regmap + ISR); 137 isr = ioread32(card->regmap + ISR);
119 if (isr == 0xffffffff) { 138 if (isr == 0xffffffff) {
120 /* 139 /*
@@ -161,9 +180,9 @@ static irqreturn_t rsxx_isr(int irq, void *pdata)
161} 180}
162 181
163/*----------------- Card Event Handler -------------------*/ 182/*----------------- Card Event Handler -------------------*/
164static char *rsxx_card_state_to_str(unsigned int state) 183static const char * const rsxx_card_state_to_str(unsigned int state)
165{ 184{
166 static char *state_strings[] = { 185 static const char * const state_strings[] = {
167 "Unknown", "Shutdown", "Starting", "Formatting", 186 "Unknown", "Shutdown", "Starting", "Formatting",
168 "Uninitialized", "Good", "Shutting Down", 187 "Uninitialized", "Good", "Shutting Down",
169 "Fault", "Read Only Fault", "dStroying" 188 "Fault", "Read Only Fault", "dStroying"
@@ -304,6 +323,192 @@ static int card_shutdown(struct rsxx_cardinfo *card)
304 return 0; 323 return 0;
305} 324}
306 325
326static int rsxx_eeh_frozen(struct pci_dev *dev)
327{
328 struct rsxx_cardinfo *card = pci_get_drvdata(dev);
329 int i;
330 int st;
331
332 dev_warn(&dev->dev, "IBM FlashSystem PCI: preparing for slot reset.\n");
333
334 card->eeh_state = 1;
335 rsxx_mask_interrupts(card);
336
337 /*
338 * We need to guarantee that the write for eeh_state and masking
339 * interrupts does not become reordered. This will prevent a possible
340 * race condition with the EEH code.
341 */
342 wmb();
343
344 pci_disable_device(dev);
345
346 st = rsxx_eeh_save_issued_dmas(card);
347 if (st)
348 return st;
349
350 rsxx_eeh_save_issued_creg(card);
351
352 for (i = 0; i < card->n_targets; i++) {
353 if (card->ctrl[i].status.buf)
354 pci_free_consistent(card->dev, STATUS_BUFFER_SIZE8,
355 card->ctrl[i].status.buf,
356 card->ctrl[i].status.dma_addr);
357 if (card->ctrl[i].cmd.buf)
358 pci_free_consistent(card->dev, COMMAND_BUFFER_SIZE8,
359 card->ctrl[i].cmd.buf,
360 card->ctrl[i].cmd.dma_addr);
361 }
362
363 return 0;
364}
365
366static void rsxx_eeh_failure(struct pci_dev *dev)
367{
368 struct rsxx_cardinfo *card = pci_get_drvdata(dev);
369 int i;
370
371 dev_err(&dev->dev, "IBM FlashSystem PCI: disabling failed card.\n");
372
373 card->eeh_state = 1;
374
375 for (i = 0; i < card->n_targets; i++)
376 del_timer_sync(&card->ctrl[i].activity_timer);
377
378 rsxx_eeh_cancel_dmas(card);
379}
380
381static int rsxx_eeh_fifo_flush_poll(struct rsxx_cardinfo *card)
382{
383 unsigned int status;
384 int iter = 0;
385
386 /* We need to wait for the hardware to reset */
387 while (iter++ < 10) {
388 status = ioread32(card->regmap + PCI_RECONFIG);
389
390 if (status & RSXX_FLUSH_BUSY) {
391 ssleep(1);
392 continue;
393 }
394
395 if (status & RSXX_FLUSH_TIMEOUT)
396 dev_warn(CARD_TO_DEV(card), "HW: flash controller timeout\n");
397 return 0;
398 }
399
400 /* Hardware failed resetting itself. */
401 return -1;
402}
403
404static pci_ers_result_t rsxx_error_detected(struct pci_dev *dev,
405 enum pci_channel_state error)
406{
407 int st;
408
409 if (dev->revision < RSXX_EEH_SUPPORT)
410 return PCI_ERS_RESULT_NONE;
411
412 if (error == pci_channel_io_perm_failure) {
413 rsxx_eeh_failure(dev);
414 return PCI_ERS_RESULT_DISCONNECT;
415 }
416
417 st = rsxx_eeh_frozen(dev);
418 if (st) {
419 dev_err(&dev->dev, "Slot reset setup failed\n");
420 rsxx_eeh_failure(dev);
421 return PCI_ERS_RESULT_DISCONNECT;
422 }
423
424 return PCI_ERS_RESULT_NEED_RESET;
425}
426
427static pci_ers_result_t rsxx_slot_reset(struct pci_dev *dev)
428{
429 struct rsxx_cardinfo *card = pci_get_drvdata(dev);
430 unsigned long flags;
431 int i;
432 int st;
433
434 dev_warn(&dev->dev,
435 "IBM FlashSystem PCI: recovering from slot reset.\n");
436
437 st = pci_enable_device(dev);
438 if (st)
439 goto failed_hw_setup;
440
441 pci_set_master(dev);
442
443 st = rsxx_eeh_fifo_flush_poll(card);
444 if (st)
445 goto failed_hw_setup;
446
447 rsxx_dma_queue_reset(card);
448
449 for (i = 0; i < card->n_targets; i++) {
450 st = rsxx_hw_buffers_init(dev, &card->ctrl[i]);
451 if (st)
452 goto failed_hw_buffers_init;
453 }
454
455 if (card->config_valid)
456 rsxx_dma_configure(card);
457
458 /* Clears the ISR register from spurious interrupts */
459 st = ioread32(card->regmap + ISR);
460
461 card->eeh_state = 0;
462
463 st = rsxx_eeh_remap_dmas(card);
464 if (st)
465 goto failed_remap_dmas;
466
467 spin_lock_irqsave(&card->irq_lock, flags);
468 if (card->n_targets & RSXX_MAX_TARGETS)
469 rsxx_enable_ier_and_isr(card, CR_INTR_ALL_G);
470 else
471 rsxx_enable_ier_and_isr(card, CR_INTR_ALL_C);
472 spin_unlock_irqrestore(&card->irq_lock, flags);
473
474 rsxx_kick_creg_queue(card);
475
476 for (i = 0; i < card->n_targets; i++) {
477 spin_lock(&card->ctrl[i].queue_lock);
478 if (list_empty(&card->ctrl[i].queue)) {
479 spin_unlock(&card->ctrl[i].queue_lock);
480 continue;
481 }
482 spin_unlock(&card->ctrl[i].queue_lock);
483
484 queue_work(card->ctrl[i].issue_wq,
485 &card->ctrl[i].issue_dma_work);
486 }
487
488 dev_info(&dev->dev, "IBM FlashSystem PCI: recovery complete.\n");
489
490 return PCI_ERS_RESULT_RECOVERED;
491
492failed_hw_buffers_init:
493failed_remap_dmas:
494 for (i = 0; i < card->n_targets; i++) {
495 if (card->ctrl[i].status.buf)
496 pci_free_consistent(card->dev,
497 STATUS_BUFFER_SIZE8,
498 card->ctrl[i].status.buf,
499 card->ctrl[i].status.dma_addr);
500 if (card->ctrl[i].cmd.buf)
501 pci_free_consistent(card->dev,
502 COMMAND_BUFFER_SIZE8,
503 card->ctrl[i].cmd.buf,
504 card->ctrl[i].cmd.dma_addr);
505 }
506failed_hw_setup:
507 rsxx_eeh_failure(dev);
508 return PCI_ERS_RESULT_DISCONNECT;
509
510}
511
307/*----------------- Driver Initialization & Setup -------------------*/ 512/*----------------- Driver Initialization & Setup -------------------*/
308/* Returns: 0 if the driver is compatible with the device 513/* Returns: 0 if the driver is compatible with the device
309 -1 if the driver is NOT compatible with the device */ 514 -1 if the driver is NOT compatible with the device */
@@ -383,6 +588,7 @@ static int rsxx_pci_probe(struct pci_dev *dev,
383 588
384 spin_lock_init(&card->irq_lock); 589 spin_lock_init(&card->irq_lock);
385 card->halt = 0; 590 card->halt = 0;
591 card->eeh_state = 0;
386 592
387 spin_lock_irq(&card->irq_lock); 593 spin_lock_irq(&card->irq_lock);
388 rsxx_disable_ier_and_isr(card, CR_INTR_ALL); 594 rsxx_disable_ier_and_isr(card, CR_INTR_ALL);
@@ -538,9 +744,6 @@ static void rsxx_pci_remove(struct pci_dev *dev)
538 rsxx_disable_ier_and_isr(card, CR_INTR_EVENT); 744 rsxx_disable_ier_and_isr(card, CR_INTR_EVENT);
539 spin_unlock_irqrestore(&card->irq_lock, flags); 745 spin_unlock_irqrestore(&card->irq_lock, flags);
540 746
541 /* Prevent work_structs from re-queuing themselves. */
542 card->halt = 1;
543
544 cancel_work_sync(&card->event_work); 747 cancel_work_sync(&card->event_work);
545 748
546 rsxx_destroy_dev(card); 749 rsxx_destroy_dev(card);
@@ -549,6 +752,10 @@ static void rsxx_pci_remove(struct pci_dev *dev)
549 spin_lock_irqsave(&card->irq_lock, flags); 752 spin_lock_irqsave(&card->irq_lock, flags);
550 rsxx_disable_ier_and_isr(card, CR_INTR_ALL); 753 rsxx_disable_ier_and_isr(card, CR_INTR_ALL);
551 spin_unlock_irqrestore(&card->irq_lock, flags); 754 spin_unlock_irqrestore(&card->irq_lock, flags);
755
756 /* Prevent work_structs from re-queuing themselves. */
757 card->halt = 1;
758
552 free_irq(dev->irq, card); 759 free_irq(dev->irq, card);
553 760
554 if (!force_legacy) 761 if (!force_legacy)
@@ -592,11 +799,14 @@ static void rsxx_pci_shutdown(struct pci_dev *dev)
592 card_shutdown(card); 799 card_shutdown(card);
593} 800}
594 801
802static const struct pci_error_handlers rsxx_err_handler = {
803 .error_detected = rsxx_error_detected,
804 .slot_reset = rsxx_slot_reset,
805};
806
595static DEFINE_PCI_DEVICE_TABLE(rsxx_pci_ids) = { 807static DEFINE_PCI_DEVICE_TABLE(rsxx_pci_ids) = {
596 {PCI_DEVICE(PCI_VENDOR_ID_TMS_IBM, PCI_DEVICE_ID_RS70_FLASH)}, 808 {PCI_DEVICE(PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_FS70_FLASH)},
597 {PCI_DEVICE(PCI_VENDOR_ID_TMS_IBM, PCI_DEVICE_ID_RS70D_FLASH)}, 809 {PCI_DEVICE(PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_FS80_FLASH)},
598 {PCI_DEVICE(PCI_VENDOR_ID_TMS_IBM, PCI_DEVICE_ID_RS80_FLASH)},
599 {PCI_DEVICE(PCI_VENDOR_ID_TMS_IBM, PCI_DEVICE_ID_RS81_FLASH)},
600 {0,}, 810 {0,},
601}; 811};
602 812
@@ -609,6 +819,7 @@ static struct pci_driver rsxx_pci_driver = {
609 .remove = rsxx_pci_remove, 819 .remove = rsxx_pci_remove,
610 .suspend = rsxx_pci_suspend, 820 .suspend = rsxx_pci_suspend,
611 .shutdown = rsxx_pci_shutdown, 821 .shutdown = rsxx_pci_shutdown,
822 .err_handler = &rsxx_err_handler,
612}; 823};
613 824
614static int __init rsxx_core_init(void) 825static int __init rsxx_core_init(void)
diff --git a/drivers/block/rsxx/cregs.c b/drivers/block/rsxx/cregs.c
index 80bbe639fccd..4b5c020a0a65 100644
--- a/drivers/block/rsxx/cregs.c
+++ b/drivers/block/rsxx/cregs.c
@@ -58,7 +58,7 @@ static struct kmem_cache *creg_cmd_pool;
58#error Unknown endianess!!! Aborting... 58#error Unknown endianess!!! Aborting...
59#endif 59#endif
60 60
61static void copy_to_creg_data(struct rsxx_cardinfo *card, 61static int copy_to_creg_data(struct rsxx_cardinfo *card,
62 int cnt8, 62 int cnt8,
63 void *buf, 63 void *buf,
64 unsigned int stream) 64 unsigned int stream)
@@ -66,6 +66,9 @@ static void copy_to_creg_data(struct rsxx_cardinfo *card,
66 int i = 0; 66 int i = 0;
67 u32 *data = buf; 67 u32 *data = buf;
68 68
69 if (unlikely(card->eeh_state))
70 return -EIO;
71
69 for (i = 0; cnt8 > 0; i++, cnt8 -= 4) { 72 for (i = 0; cnt8 > 0; i++, cnt8 -= 4) {
70 /* 73 /*
71 * Firmware implementation makes it necessary to byte swap on 74 * Firmware implementation makes it necessary to byte swap on
@@ -76,10 +79,12 @@ static void copy_to_creg_data(struct rsxx_cardinfo *card,
76 else 79 else
77 iowrite32(data[i], card->regmap + CREG_DATA(i)); 80 iowrite32(data[i], card->regmap + CREG_DATA(i));
78 } 81 }
82
83 return 0;
79} 84}
80 85
81 86
82static void copy_from_creg_data(struct rsxx_cardinfo *card, 87static int copy_from_creg_data(struct rsxx_cardinfo *card,
83 int cnt8, 88 int cnt8,
84 void *buf, 89 void *buf,
85 unsigned int stream) 90 unsigned int stream)
@@ -87,6 +92,9 @@ static void copy_from_creg_data(struct rsxx_cardinfo *card,
87 int i = 0; 92 int i = 0;
88 u32 *data = buf; 93 u32 *data = buf;
89 94
95 if (unlikely(card->eeh_state))
96 return -EIO;
97
90 for (i = 0; cnt8 > 0; i++, cnt8 -= 4) { 98 for (i = 0; cnt8 > 0; i++, cnt8 -= 4) {
91 /* 99 /*
92 * Firmware implementation makes it necessary to byte swap on 100 * Firmware implementation makes it necessary to byte swap on
@@ -97,41 +105,31 @@ static void copy_from_creg_data(struct rsxx_cardinfo *card,
97 else 105 else
98 data[i] = ioread32(card->regmap + CREG_DATA(i)); 106 data[i] = ioread32(card->regmap + CREG_DATA(i));
99 } 107 }
100}
101
102static struct creg_cmd *pop_active_cmd(struct rsxx_cardinfo *card)
103{
104 struct creg_cmd *cmd;
105 108
106 /* 109 return 0;
107 * Spin lock is needed because this can be called in atomic/interrupt
108 * context.
109 */
110 spin_lock_bh(&card->creg_ctrl.lock);
111 cmd = card->creg_ctrl.active_cmd;
112 card->creg_ctrl.active_cmd = NULL;
113 spin_unlock_bh(&card->creg_ctrl.lock);
114
115 return cmd;
116} 110}
117 111
118static void creg_issue_cmd(struct rsxx_cardinfo *card, struct creg_cmd *cmd) 112static void creg_issue_cmd(struct rsxx_cardinfo *card, struct creg_cmd *cmd)
119{ 113{
114 int st;
115
116 if (unlikely(card->eeh_state))
117 return;
118
120 iowrite32(cmd->addr, card->regmap + CREG_ADD); 119 iowrite32(cmd->addr, card->regmap + CREG_ADD);
121 iowrite32(cmd->cnt8, card->regmap + CREG_CNT); 120 iowrite32(cmd->cnt8, card->regmap + CREG_CNT);
122 121
123 if (cmd->op == CREG_OP_WRITE) { 122 if (cmd->op == CREG_OP_WRITE) {
124 if (cmd->buf) 123 if (cmd->buf) {
125 copy_to_creg_data(card, cmd->cnt8, 124 st = copy_to_creg_data(card, cmd->cnt8,
126 cmd->buf, cmd->stream); 125 cmd->buf, cmd->stream);
126 if (st)
127 return;
128 }
127 } 129 }
128 130
129 /* 131 if (unlikely(card->eeh_state))
130 * Data copy must complete before initiating the command. This is 132 return;
131 * needed for weakly ordered processors (i.e. PowerPC), so that all
132 * neccessary registers are written before we kick the hardware.
133 */
134 wmb();
135 133
136 /* Setting the valid bit will kick off the command. */ 134 /* Setting the valid bit will kick off the command. */
137 iowrite32(cmd->op, card->regmap + CREG_CMD); 135 iowrite32(cmd->op, card->regmap + CREG_CMD);
@@ -196,11 +194,11 @@ static int creg_queue_cmd(struct rsxx_cardinfo *card,
196 cmd->cb_private = cb_private; 194 cmd->cb_private = cb_private;
197 cmd->status = 0; 195 cmd->status = 0;
198 196
199 spin_lock(&card->creg_ctrl.lock); 197 spin_lock_bh(&card->creg_ctrl.lock);
200 list_add_tail(&cmd->list, &card->creg_ctrl.queue); 198 list_add_tail(&cmd->list, &card->creg_ctrl.queue);
201 card->creg_ctrl.q_depth++; 199 card->creg_ctrl.q_depth++;
202 creg_kick_queue(card); 200 creg_kick_queue(card);
203 spin_unlock(&card->creg_ctrl.lock); 201 spin_unlock_bh(&card->creg_ctrl.lock);
204 202
205 return 0; 203 return 0;
206} 204}
@@ -210,7 +208,11 @@ static void creg_cmd_timed_out(unsigned long data)
210 struct rsxx_cardinfo *card = (struct rsxx_cardinfo *) data; 208 struct rsxx_cardinfo *card = (struct rsxx_cardinfo *) data;
211 struct creg_cmd *cmd; 209 struct creg_cmd *cmd;
212 210
213 cmd = pop_active_cmd(card); 211 spin_lock(&card->creg_ctrl.lock);
212 cmd = card->creg_ctrl.active_cmd;
213 card->creg_ctrl.active_cmd = NULL;
214 spin_unlock(&card->creg_ctrl.lock);
215
214 if (cmd == NULL) { 216 if (cmd == NULL) {
215 card->creg_ctrl.creg_stats.creg_timeout++; 217 card->creg_ctrl.creg_stats.creg_timeout++;
216 dev_warn(CARD_TO_DEV(card), 218 dev_warn(CARD_TO_DEV(card),
@@ -247,7 +249,11 @@ static void creg_cmd_done(struct work_struct *work)
247 if (del_timer_sync(&card->creg_ctrl.cmd_timer) == 0) 249 if (del_timer_sync(&card->creg_ctrl.cmd_timer) == 0)
248 card->creg_ctrl.creg_stats.failed_cancel_timer++; 250 card->creg_ctrl.creg_stats.failed_cancel_timer++;
249 251
250 cmd = pop_active_cmd(card); 252 spin_lock_bh(&card->creg_ctrl.lock);
253 cmd = card->creg_ctrl.active_cmd;
254 card->creg_ctrl.active_cmd = NULL;
255 spin_unlock_bh(&card->creg_ctrl.lock);
256
251 if (cmd == NULL) { 257 if (cmd == NULL) {
252 dev_err(CARD_TO_DEV(card), 258 dev_err(CARD_TO_DEV(card),
253 "Spurious creg interrupt!\n"); 259 "Spurious creg interrupt!\n");
@@ -287,7 +293,7 @@ static void creg_cmd_done(struct work_struct *work)
287 goto creg_done; 293 goto creg_done;
288 } 294 }
289 295
290 copy_from_creg_data(card, cnt8, cmd->buf, cmd->stream); 296 st = copy_from_creg_data(card, cnt8, cmd->buf, cmd->stream);
291 } 297 }
292 298
293creg_done: 299creg_done:
@@ -296,10 +302,10 @@ creg_done:
296 302
297 kmem_cache_free(creg_cmd_pool, cmd); 303 kmem_cache_free(creg_cmd_pool, cmd);
298 304
299 spin_lock(&card->creg_ctrl.lock); 305 spin_lock_bh(&card->creg_ctrl.lock);
300 card->creg_ctrl.active = 0; 306 card->creg_ctrl.active = 0;
301 creg_kick_queue(card); 307 creg_kick_queue(card);
302 spin_unlock(&card->creg_ctrl.lock); 308 spin_unlock_bh(&card->creg_ctrl.lock);
303} 309}
304 310
305static void creg_reset(struct rsxx_cardinfo *card) 311static void creg_reset(struct rsxx_cardinfo *card)
@@ -324,7 +330,7 @@ static void creg_reset(struct rsxx_cardinfo *card)
324 "Resetting creg interface for recovery\n"); 330 "Resetting creg interface for recovery\n");
325 331
326 /* Cancel outstanding commands */ 332 /* Cancel outstanding commands */
327 spin_lock(&card->creg_ctrl.lock); 333 spin_lock_bh(&card->creg_ctrl.lock);
328 list_for_each_entry_safe(cmd, tmp, &card->creg_ctrl.queue, list) { 334 list_for_each_entry_safe(cmd, tmp, &card->creg_ctrl.queue, list) {
329 list_del(&cmd->list); 335 list_del(&cmd->list);
330 card->creg_ctrl.q_depth--; 336 card->creg_ctrl.q_depth--;
@@ -345,7 +351,7 @@ static void creg_reset(struct rsxx_cardinfo *card)
345 351
346 card->creg_ctrl.active = 0; 352 card->creg_ctrl.active = 0;
347 } 353 }
348 spin_unlock(&card->creg_ctrl.lock); 354 spin_unlock_bh(&card->creg_ctrl.lock);
349 355
350 card->creg_ctrl.reset = 0; 356 card->creg_ctrl.reset = 0;
351 spin_lock_irqsave(&card->irq_lock, flags); 357 spin_lock_irqsave(&card->irq_lock, flags);
@@ -399,12 +405,12 @@ static int __issue_creg_rw(struct rsxx_cardinfo *card,
399 return st; 405 return st;
400 406
401 /* 407 /*
402 * This timeout is neccessary for unresponsive hardware. The additional 408 * This timeout is necessary for unresponsive hardware. The additional
403 * 20 seconds to used to guarantee that each cregs requests has time to 409 * 20 seconds to used to guarantee that each cregs requests has time to
404 * complete. 410 * complete.
405 */ 411 */
406 timeout = msecs_to_jiffies((CREG_TIMEOUT_MSEC * 412 timeout = msecs_to_jiffies(CREG_TIMEOUT_MSEC *
407 card->creg_ctrl.q_depth) + 20000); 413 card->creg_ctrl.q_depth + 20000);
408 414
409 /* 415 /*
410 * The creg interface is guaranteed to complete. It has a timeout 416 * The creg interface is guaranteed to complete. It has a timeout
@@ -690,6 +696,32 @@ int rsxx_reg_access(struct rsxx_cardinfo *card,
690 return 0; 696 return 0;
691} 697}
692 698
699void rsxx_eeh_save_issued_creg(struct rsxx_cardinfo *card)
700{
701 struct creg_cmd *cmd = NULL;
702
703 cmd = card->creg_ctrl.active_cmd;
704 card->creg_ctrl.active_cmd = NULL;
705
706 if (cmd) {
707 del_timer_sync(&card->creg_ctrl.cmd_timer);
708
709 spin_lock_bh(&card->creg_ctrl.lock);
710 list_add(&cmd->list, &card->creg_ctrl.queue);
711 card->creg_ctrl.q_depth++;
712 card->creg_ctrl.active = 0;
713 spin_unlock_bh(&card->creg_ctrl.lock);
714 }
715}
716
717void rsxx_kick_creg_queue(struct rsxx_cardinfo *card)
718{
719 spin_lock_bh(&card->creg_ctrl.lock);
720 if (!list_empty(&card->creg_ctrl.queue))
721 creg_kick_queue(card);
722 spin_unlock_bh(&card->creg_ctrl.lock);
723}
724
693/*------------ Initialization & Setup --------------*/ 725/*------------ Initialization & Setup --------------*/
694int rsxx_creg_setup(struct rsxx_cardinfo *card) 726int rsxx_creg_setup(struct rsxx_cardinfo *card)
695{ 727{
@@ -712,7 +744,7 @@ void rsxx_creg_destroy(struct rsxx_cardinfo *card)
712 int cnt = 0; 744 int cnt = 0;
713 745
714 /* Cancel outstanding commands */ 746 /* Cancel outstanding commands */
715 spin_lock(&card->creg_ctrl.lock); 747 spin_lock_bh(&card->creg_ctrl.lock);
716 list_for_each_entry_safe(cmd, tmp, &card->creg_ctrl.queue, list) { 748 list_for_each_entry_safe(cmd, tmp, &card->creg_ctrl.queue, list) {
717 list_del(&cmd->list); 749 list_del(&cmd->list);
718 if (cmd->cb) 750 if (cmd->cb)
@@ -737,7 +769,7 @@ void rsxx_creg_destroy(struct rsxx_cardinfo *card)
737 "Canceled active creg command\n"); 769 "Canceled active creg command\n");
738 kmem_cache_free(creg_cmd_pool, cmd); 770 kmem_cache_free(creg_cmd_pool, cmd);
739 } 771 }
740 spin_unlock(&card->creg_ctrl.lock); 772 spin_unlock_bh(&card->creg_ctrl.lock);
741 773
742 cancel_work_sync(&card->creg_ctrl.done_work); 774 cancel_work_sync(&card->creg_ctrl.done_work);
743} 775}
diff --git a/drivers/block/rsxx/dma.c b/drivers/block/rsxx/dma.c
index 63176e67662f..0607513cfb41 100644
--- a/drivers/block/rsxx/dma.c
+++ b/drivers/block/rsxx/dma.c
@@ -28,7 +28,7 @@
28struct rsxx_dma { 28struct rsxx_dma {
29 struct list_head list; 29 struct list_head list;
30 u8 cmd; 30 u8 cmd;
31 unsigned int laddr; /* Logical address on the ramsan */ 31 unsigned int laddr; /* Logical address */
32 struct { 32 struct {
33 u32 off; 33 u32 off;
34 u32 cnt; 34 u32 cnt;
@@ -81,9 +81,6 @@ enum rsxx_hw_status {
81 HW_STATUS_FAULT = 0x08, 81 HW_STATUS_FAULT = 0x08,
82}; 82};
83 83
84#define STATUS_BUFFER_SIZE8 4096
85#define COMMAND_BUFFER_SIZE8 4096
86
87static struct kmem_cache *rsxx_dma_pool; 84static struct kmem_cache *rsxx_dma_pool;
88 85
89struct dma_tracker { 86struct dma_tracker {
@@ -122,7 +119,7 @@ static unsigned int rsxx_get_dma_tgt(struct rsxx_cardinfo *card, u64 addr8)
122 return tgt; 119 return tgt;
123} 120}
124 121
125static void rsxx_dma_queue_reset(struct rsxx_cardinfo *card) 122void rsxx_dma_queue_reset(struct rsxx_cardinfo *card)
126{ 123{
127 /* Reset all DMA Command/Status Queues */ 124 /* Reset all DMA Command/Status Queues */
128 iowrite32(DMA_QUEUE_RESET, card->regmap + RESET); 125 iowrite32(DMA_QUEUE_RESET, card->regmap + RESET);
@@ -210,7 +207,8 @@ static void dma_intr_coal_auto_tune(struct rsxx_cardinfo *card)
210 u32 q_depth = 0; 207 u32 q_depth = 0;
211 u32 intr_coal; 208 u32 intr_coal;
212 209
213 if (card->config.data.intr_coal.mode != RSXX_INTR_COAL_AUTO_TUNE) 210 if (card->config.data.intr_coal.mode != RSXX_INTR_COAL_AUTO_TUNE ||
211 unlikely(card->eeh_state))
214 return; 212 return;
215 213
216 for (i = 0; i < card->n_targets; i++) 214 for (i = 0; i < card->n_targets; i++)
@@ -223,31 +221,26 @@ static void dma_intr_coal_auto_tune(struct rsxx_cardinfo *card)
223} 221}
224 222
225/*----------------- RSXX DMA Handling -------------------*/ 223/*----------------- RSXX DMA Handling -------------------*/
226static void rsxx_complete_dma(struct rsxx_cardinfo *card, 224static void rsxx_complete_dma(struct rsxx_dma_ctrl *ctrl,
227 struct rsxx_dma *dma, 225 struct rsxx_dma *dma,
228 unsigned int status) 226 unsigned int status)
229{ 227{
230 if (status & DMA_SW_ERR) 228 if (status & DMA_SW_ERR)
231 printk_ratelimited(KERN_ERR 229 ctrl->stats.dma_sw_err++;
232 "SW Error in DMA(cmd x%02x, laddr x%08x)\n",
233 dma->cmd, dma->laddr);
234 if (status & DMA_HW_FAULT) 230 if (status & DMA_HW_FAULT)
235 printk_ratelimited(KERN_ERR 231 ctrl->stats.dma_hw_fault++;
236 "HW Fault in DMA(cmd x%02x, laddr x%08x)\n",
237 dma->cmd, dma->laddr);
238 if (status & DMA_CANCELLED) 232 if (status & DMA_CANCELLED)
239 printk_ratelimited(KERN_ERR 233 ctrl->stats.dma_cancelled++;
240 "DMA Cancelled(cmd x%02x, laddr x%08x)\n",
241 dma->cmd, dma->laddr);
242 234
243 if (dma->dma_addr) 235 if (dma->dma_addr)
244 pci_unmap_page(card->dev, dma->dma_addr, get_dma_size(dma), 236 pci_unmap_page(ctrl->card->dev, dma->dma_addr,
237 get_dma_size(dma),
245 dma->cmd == HW_CMD_BLK_WRITE ? 238 dma->cmd == HW_CMD_BLK_WRITE ?
246 PCI_DMA_TODEVICE : 239 PCI_DMA_TODEVICE :
247 PCI_DMA_FROMDEVICE); 240 PCI_DMA_FROMDEVICE);
248 241
249 if (dma->cb) 242 if (dma->cb)
250 dma->cb(card, dma->cb_data, status ? 1 : 0); 243 dma->cb(ctrl->card, dma->cb_data, status ? 1 : 0);
251 244
252 kmem_cache_free(rsxx_dma_pool, dma); 245 kmem_cache_free(rsxx_dma_pool, dma);
253} 246}
@@ -330,14 +323,15 @@ static void rsxx_handle_dma_error(struct rsxx_dma_ctrl *ctrl,
330 if (requeue_cmd) 323 if (requeue_cmd)
331 rsxx_requeue_dma(ctrl, dma); 324 rsxx_requeue_dma(ctrl, dma);
332 else 325 else
333 rsxx_complete_dma(ctrl->card, dma, status); 326 rsxx_complete_dma(ctrl, dma, status);
334} 327}
335 328
336static void dma_engine_stalled(unsigned long data) 329static void dma_engine_stalled(unsigned long data)
337{ 330{
338 struct rsxx_dma_ctrl *ctrl = (struct rsxx_dma_ctrl *)data; 331 struct rsxx_dma_ctrl *ctrl = (struct rsxx_dma_ctrl *)data;
339 332
340 if (atomic_read(&ctrl->stats.hw_q_depth) == 0) 333 if (atomic_read(&ctrl->stats.hw_q_depth) == 0 ||
334 unlikely(ctrl->card->eeh_state))
341 return; 335 return;
342 336
343 if (ctrl->cmd.idx != ioread32(ctrl->regmap + SW_CMD_IDX)) { 337 if (ctrl->cmd.idx != ioread32(ctrl->regmap + SW_CMD_IDX)) {
@@ -369,7 +363,8 @@ static void rsxx_issue_dmas(struct work_struct *work)
369 ctrl = container_of(work, struct rsxx_dma_ctrl, issue_dma_work); 363 ctrl = container_of(work, struct rsxx_dma_ctrl, issue_dma_work);
370 hw_cmd_buf = ctrl->cmd.buf; 364 hw_cmd_buf = ctrl->cmd.buf;
371 365
372 if (unlikely(ctrl->card->halt)) 366 if (unlikely(ctrl->card->halt) ||
367 unlikely(ctrl->card->eeh_state))
373 return; 368 return;
374 369
375 while (1) { 370 while (1) {
@@ -397,7 +392,7 @@ static void rsxx_issue_dmas(struct work_struct *work)
397 */ 392 */
398 if (unlikely(ctrl->card->dma_fault)) { 393 if (unlikely(ctrl->card->dma_fault)) {
399 push_tracker(ctrl->trackers, tag); 394 push_tracker(ctrl->trackers, tag);
400 rsxx_complete_dma(ctrl->card, dma, DMA_CANCELLED); 395 rsxx_complete_dma(ctrl, dma, DMA_CANCELLED);
401 continue; 396 continue;
402 } 397 }
403 398
@@ -432,19 +427,15 @@ static void rsxx_issue_dmas(struct work_struct *work)
432 427
433 /* Let HW know we've queued commands. */ 428 /* Let HW know we've queued commands. */
434 if (cmds_pending) { 429 if (cmds_pending) {
435 /*
436 * We must guarantee that the CPU writes to 'ctrl->cmd.buf'
437 * (which is in PCI-consistent system-memory) from the loop
438 * above make it into the coherency domain before the
439 * following PIO "trigger" updating the cmd.idx. A WMB is
440 * sufficient. We need not explicitly CPU cache-flush since
441 * the memory is a PCI-consistent (ie; coherent) mapping.
442 */
443 wmb();
444
445 atomic_add(cmds_pending, &ctrl->stats.hw_q_depth); 430 atomic_add(cmds_pending, &ctrl->stats.hw_q_depth);
446 mod_timer(&ctrl->activity_timer, 431 mod_timer(&ctrl->activity_timer,
447 jiffies + DMA_ACTIVITY_TIMEOUT); 432 jiffies + DMA_ACTIVITY_TIMEOUT);
433
434 if (unlikely(ctrl->card->eeh_state)) {
435 del_timer_sync(&ctrl->activity_timer);
436 return;
437 }
438
448 iowrite32(ctrl->cmd.idx, ctrl->regmap + SW_CMD_IDX); 439 iowrite32(ctrl->cmd.idx, ctrl->regmap + SW_CMD_IDX);
449 } 440 }
450} 441}
@@ -463,7 +454,8 @@ static void rsxx_dma_done(struct work_struct *work)
463 hw_st_buf = ctrl->status.buf; 454 hw_st_buf = ctrl->status.buf;
464 455
465 if (unlikely(ctrl->card->halt) || 456 if (unlikely(ctrl->card->halt) ||
466 unlikely(ctrl->card->dma_fault)) 457 unlikely(ctrl->card->dma_fault) ||
458 unlikely(ctrl->card->eeh_state))
467 return; 459 return;
468 460
469 count = le16_to_cpu(hw_st_buf[ctrl->status.idx].count); 461 count = le16_to_cpu(hw_st_buf[ctrl->status.idx].count);
@@ -508,7 +500,7 @@ static void rsxx_dma_done(struct work_struct *work)
508 if (status) 500 if (status)
509 rsxx_handle_dma_error(ctrl, dma, status); 501 rsxx_handle_dma_error(ctrl, dma, status);
510 else 502 else
511 rsxx_complete_dma(ctrl->card, dma, 0); 503 rsxx_complete_dma(ctrl, dma, 0);
512 504
513 push_tracker(ctrl->trackers, tag); 505 push_tracker(ctrl->trackers, tag);
514 506
@@ -727,20 +719,54 @@ bvec_err:
727 719
728 720
729/*----------------- DMA Engine Initialization & Setup -------------------*/ 721/*----------------- DMA Engine Initialization & Setup -------------------*/
722int rsxx_hw_buffers_init(struct pci_dev *dev, struct rsxx_dma_ctrl *ctrl)
723{
724 ctrl->status.buf = pci_alloc_consistent(dev, STATUS_BUFFER_SIZE8,
725 &ctrl->status.dma_addr);
726 ctrl->cmd.buf = pci_alloc_consistent(dev, COMMAND_BUFFER_SIZE8,
727 &ctrl->cmd.dma_addr);
728 if (ctrl->status.buf == NULL || ctrl->cmd.buf == NULL)
729 return -ENOMEM;
730
731 memset(ctrl->status.buf, 0xac, STATUS_BUFFER_SIZE8);
732 iowrite32(lower_32_bits(ctrl->status.dma_addr),
733 ctrl->regmap + SB_ADD_LO);
734 iowrite32(upper_32_bits(ctrl->status.dma_addr),
735 ctrl->regmap + SB_ADD_HI);
736
737 memset(ctrl->cmd.buf, 0x83, COMMAND_BUFFER_SIZE8);
738 iowrite32(lower_32_bits(ctrl->cmd.dma_addr), ctrl->regmap + CB_ADD_LO);
739 iowrite32(upper_32_bits(ctrl->cmd.dma_addr), ctrl->regmap + CB_ADD_HI);
740
741 ctrl->status.idx = ioread32(ctrl->regmap + HW_STATUS_CNT);
742 if (ctrl->status.idx > RSXX_MAX_OUTSTANDING_CMDS) {
743 dev_crit(&dev->dev, "Failed reading status cnt x%x\n",
744 ctrl->status.idx);
745 return -EINVAL;
746 }
747 iowrite32(ctrl->status.idx, ctrl->regmap + HW_STATUS_CNT);
748 iowrite32(ctrl->status.idx, ctrl->regmap + SW_STATUS_CNT);
749
750 ctrl->cmd.idx = ioread32(ctrl->regmap + HW_CMD_IDX);
751 if (ctrl->cmd.idx > RSXX_MAX_OUTSTANDING_CMDS) {
752 dev_crit(&dev->dev, "Failed reading cmd cnt x%x\n",
753 ctrl->status.idx);
754 return -EINVAL;
755 }
756 iowrite32(ctrl->cmd.idx, ctrl->regmap + HW_CMD_IDX);
757 iowrite32(ctrl->cmd.idx, ctrl->regmap + SW_CMD_IDX);
758
759 return 0;
760}
761
730static int rsxx_dma_ctrl_init(struct pci_dev *dev, 762static int rsxx_dma_ctrl_init(struct pci_dev *dev,
731 struct rsxx_dma_ctrl *ctrl) 763 struct rsxx_dma_ctrl *ctrl)
732{ 764{
733 int i; 765 int i;
766 int st;
734 767
735 memset(&ctrl->stats, 0, sizeof(ctrl->stats)); 768 memset(&ctrl->stats, 0, sizeof(ctrl->stats));
736 769
737 ctrl->status.buf = pci_alloc_consistent(dev, STATUS_BUFFER_SIZE8,
738 &ctrl->status.dma_addr);
739 ctrl->cmd.buf = pci_alloc_consistent(dev, COMMAND_BUFFER_SIZE8,
740 &ctrl->cmd.dma_addr);
741 if (ctrl->status.buf == NULL || ctrl->cmd.buf == NULL)
742 return -ENOMEM;
743
744 ctrl->trackers = vmalloc(DMA_TRACKER_LIST_SIZE8); 770 ctrl->trackers = vmalloc(DMA_TRACKER_LIST_SIZE8);
745 if (!ctrl->trackers) 771 if (!ctrl->trackers)
746 return -ENOMEM; 772 return -ENOMEM;
@@ -770,35 +796,9 @@ static int rsxx_dma_ctrl_init(struct pci_dev *dev,
770 INIT_WORK(&ctrl->issue_dma_work, rsxx_issue_dmas); 796 INIT_WORK(&ctrl->issue_dma_work, rsxx_issue_dmas);
771 INIT_WORK(&ctrl->dma_done_work, rsxx_dma_done); 797 INIT_WORK(&ctrl->dma_done_work, rsxx_dma_done);
772 798
773 memset(ctrl->status.buf, 0xac, STATUS_BUFFER_SIZE8); 799 st = rsxx_hw_buffers_init(dev, ctrl);
774 iowrite32(lower_32_bits(ctrl->status.dma_addr), 800 if (st)
775 ctrl->regmap + SB_ADD_LO); 801 return st;
776 iowrite32(upper_32_bits(ctrl->status.dma_addr),
777 ctrl->regmap + SB_ADD_HI);
778
779 memset(ctrl->cmd.buf, 0x83, COMMAND_BUFFER_SIZE8);
780 iowrite32(lower_32_bits(ctrl->cmd.dma_addr), ctrl->regmap + CB_ADD_LO);
781 iowrite32(upper_32_bits(ctrl->cmd.dma_addr), ctrl->regmap + CB_ADD_HI);
782
783 ctrl->status.idx = ioread32(ctrl->regmap + HW_STATUS_CNT);
784 if (ctrl->status.idx > RSXX_MAX_OUTSTANDING_CMDS) {
785 dev_crit(&dev->dev, "Failed reading status cnt x%x\n",
786 ctrl->status.idx);
787 return -EINVAL;
788 }
789 iowrite32(ctrl->status.idx, ctrl->regmap + HW_STATUS_CNT);
790 iowrite32(ctrl->status.idx, ctrl->regmap + SW_STATUS_CNT);
791
792 ctrl->cmd.idx = ioread32(ctrl->regmap + HW_CMD_IDX);
793 if (ctrl->cmd.idx > RSXX_MAX_OUTSTANDING_CMDS) {
794 dev_crit(&dev->dev, "Failed reading cmd cnt x%x\n",
795 ctrl->status.idx);
796 return -EINVAL;
797 }
798 iowrite32(ctrl->cmd.idx, ctrl->regmap + HW_CMD_IDX);
799 iowrite32(ctrl->cmd.idx, ctrl->regmap + SW_CMD_IDX);
800
801 wmb();
802 802
803 return 0; 803 return 0;
804} 804}
@@ -834,7 +834,7 @@ static int rsxx_dma_stripe_setup(struct rsxx_cardinfo *card,
834 return 0; 834 return 0;
835} 835}
836 836
837static int rsxx_dma_configure(struct rsxx_cardinfo *card) 837int rsxx_dma_configure(struct rsxx_cardinfo *card)
838{ 838{
839 u32 intr_coal; 839 u32 intr_coal;
840 840
@@ -980,6 +980,103 @@ void rsxx_dma_destroy(struct rsxx_cardinfo *card)
980 } 980 }
981} 981}
982 982
983int rsxx_eeh_save_issued_dmas(struct rsxx_cardinfo *card)
984{
985 int i;
986 int j;
987 int cnt;
988 struct rsxx_dma *dma;
989 struct list_head *issued_dmas;
990
991 issued_dmas = kzalloc(sizeof(*issued_dmas) * card->n_targets,
992 GFP_KERNEL);
993 if (!issued_dmas)
994 return -ENOMEM;
995
996 for (i = 0; i < card->n_targets; i++) {
997 INIT_LIST_HEAD(&issued_dmas[i]);
998 cnt = 0;
999 for (j = 0; j < RSXX_MAX_OUTSTANDING_CMDS; j++) {
1000 dma = get_tracker_dma(card->ctrl[i].trackers, j);
1001 if (dma == NULL)
1002 continue;
1003
1004 if (dma->cmd == HW_CMD_BLK_WRITE)
1005 card->ctrl[i].stats.writes_issued--;
1006 else if (dma->cmd == HW_CMD_BLK_DISCARD)
1007 card->ctrl[i].stats.discards_issued--;
1008 else
1009 card->ctrl[i].stats.reads_issued--;
1010
1011 list_add_tail(&dma->list, &issued_dmas[i]);
1012 push_tracker(card->ctrl[i].trackers, j);
1013 cnt++;
1014 }
1015
1016 spin_lock(&card->ctrl[i].queue_lock);
1017 list_splice(&issued_dmas[i], &card->ctrl[i].queue);
1018
1019 atomic_sub(cnt, &card->ctrl[i].stats.hw_q_depth);
1020 card->ctrl[i].stats.sw_q_depth += cnt;
1021 card->ctrl[i].e_cnt = 0;
1022
1023 list_for_each_entry(dma, &card->ctrl[i].queue, list) {
1024 if (dma->dma_addr)
1025 pci_unmap_page(card->dev, dma->dma_addr,
1026 get_dma_size(dma),
1027 dma->cmd == HW_CMD_BLK_WRITE ?
1028 PCI_DMA_TODEVICE :
1029 PCI_DMA_FROMDEVICE);
1030 }
1031 spin_unlock(&card->ctrl[i].queue_lock);
1032 }
1033
1034 kfree(issued_dmas);
1035
1036 return 0;
1037}
1038
1039void rsxx_eeh_cancel_dmas(struct rsxx_cardinfo *card)
1040{
1041 struct rsxx_dma *dma;
1042 struct rsxx_dma *tmp;
1043 int i;
1044
1045 for (i = 0; i < card->n_targets; i++) {
1046 spin_lock(&card->ctrl[i].queue_lock);
1047 list_for_each_entry_safe(dma, tmp, &card->ctrl[i].queue, list) {
1048 list_del(&dma->list);
1049
1050 rsxx_complete_dma(&card->ctrl[i], dma, DMA_CANCELLED);
1051 }
1052 spin_unlock(&card->ctrl[i].queue_lock);
1053 }
1054}
1055
1056int rsxx_eeh_remap_dmas(struct rsxx_cardinfo *card)
1057{
1058 struct rsxx_dma *dma;
1059 int i;
1060
1061 for (i = 0; i < card->n_targets; i++) {
1062 spin_lock(&card->ctrl[i].queue_lock);
1063 list_for_each_entry(dma, &card->ctrl[i].queue, list) {
1064 dma->dma_addr = pci_map_page(card->dev, dma->page,
1065 dma->pg_off, get_dma_size(dma),
1066 dma->cmd == HW_CMD_BLK_WRITE ?
1067 PCI_DMA_TODEVICE :
1068 PCI_DMA_FROMDEVICE);
1069 if (!dma->dma_addr) {
1070 spin_unlock(&card->ctrl[i].queue_lock);
1071 kmem_cache_free(rsxx_dma_pool, dma);
1072 return -ENOMEM;
1073 }
1074 }
1075 spin_unlock(&card->ctrl[i].queue_lock);
1076 }
1077
1078 return 0;
1079}
983 1080
984int rsxx_dma_init(void) 1081int rsxx_dma_init(void)
985{ 1082{
diff --git a/drivers/block/rsxx/rsxx.h b/drivers/block/rsxx/rsxx.h
index 2e50b65902b7..24ba3642bd89 100644
--- a/drivers/block/rsxx/rsxx.h
+++ b/drivers/block/rsxx/rsxx.h
@@ -27,15 +27,17 @@
27 27
28/*----------------- IOCTL Definitions -------------------*/ 28/*----------------- IOCTL Definitions -------------------*/
29 29
30#define RSXX_MAX_DATA 8
31
30struct rsxx_reg_access { 32struct rsxx_reg_access {
31 __u32 addr; 33 __u32 addr;
32 __u32 cnt; 34 __u32 cnt;
33 __u32 stat; 35 __u32 stat;
34 __u32 stream; 36 __u32 stream;
35 __u32 data[8]; 37 __u32 data[RSXX_MAX_DATA];
36}; 38};
37 39
38#define RSXX_MAX_REG_CNT (8 * (sizeof(__u32))) 40#define RSXX_MAX_REG_CNT (RSXX_MAX_DATA * (sizeof(__u32)))
39 41
40#define RSXX_IOC_MAGIC 'r' 42#define RSXX_IOC_MAGIC 'r'
41 43
diff --git a/drivers/block/rsxx/rsxx_cfg.h b/drivers/block/rsxx/rsxx_cfg.h
index c025fe5fdb70..f384c943846d 100644
--- a/drivers/block/rsxx/rsxx_cfg.h
+++ b/drivers/block/rsxx/rsxx_cfg.h
@@ -58,7 +58,7 @@ struct rsxx_card_cfg {
58}; 58};
59 59
60/* Vendor ID Values */ 60/* Vendor ID Values */
61#define RSXX_VENDOR_ID_TMS_IBM 0 61#define RSXX_VENDOR_ID_IBM 0
62#define RSXX_VENDOR_ID_DSI 1 62#define RSXX_VENDOR_ID_DSI 1
63#define RSXX_VENDOR_COUNT 2 63#define RSXX_VENDOR_COUNT 2
64 64
diff --git a/drivers/block/rsxx/rsxx_priv.h b/drivers/block/rsxx/rsxx_priv.h
index a1ac907d8f4c..382e8bf5c03b 100644
--- a/drivers/block/rsxx/rsxx_priv.h
+++ b/drivers/block/rsxx/rsxx_priv.h
@@ -45,16 +45,13 @@
45 45
46struct proc_cmd; 46struct proc_cmd;
47 47
48#define PCI_VENDOR_ID_TMS_IBM 0x15B6 48#define PCI_DEVICE_ID_FS70_FLASH 0x04A9
49#define PCI_DEVICE_ID_RS70_FLASH 0x0019 49#define PCI_DEVICE_ID_FS80_FLASH 0x04AA
50#define PCI_DEVICE_ID_RS70D_FLASH 0x001A
51#define PCI_DEVICE_ID_RS80_FLASH 0x001C
52#define PCI_DEVICE_ID_RS81_FLASH 0x001E
53 50
54#define RS70_PCI_REV_SUPPORTED 4 51#define RS70_PCI_REV_SUPPORTED 4
55 52
56#define DRIVER_NAME "rsxx" 53#define DRIVER_NAME "rsxx"
57#define DRIVER_VERSION "3.7" 54#define DRIVER_VERSION "4.0"
58 55
59/* Block size is 4096 */ 56/* Block size is 4096 */
60#define RSXX_HW_BLK_SHIFT 12 57#define RSXX_HW_BLK_SHIFT 12
@@ -67,6 +64,9 @@ struct proc_cmd;
67#define RSXX_MAX_OUTSTANDING_CMDS 255 64#define RSXX_MAX_OUTSTANDING_CMDS 255
68#define RSXX_CS_IDX_MASK 0xff 65#define RSXX_CS_IDX_MASK 0xff
69 66
67#define STATUS_BUFFER_SIZE8 4096
68#define COMMAND_BUFFER_SIZE8 4096
69
70#define RSXX_MAX_TARGETS 8 70#define RSXX_MAX_TARGETS 8
71 71
72struct dma_tracker_list; 72struct dma_tracker_list;
@@ -91,6 +91,9 @@ struct rsxx_dma_stats {
91 u32 discards_failed; 91 u32 discards_failed;
92 u32 done_rescheduled; 92 u32 done_rescheduled;
93 u32 issue_rescheduled; 93 u32 issue_rescheduled;
94 u32 dma_sw_err;
95 u32 dma_hw_fault;
96 u32 dma_cancelled;
94 u32 sw_q_depth; /* Number of DMAs on the SW queue. */ 97 u32 sw_q_depth; /* Number of DMAs on the SW queue. */
95 atomic_t hw_q_depth; /* Number of DMAs queued to HW. */ 98 atomic_t hw_q_depth; /* Number of DMAs queued to HW. */
96}; 99};
@@ -116,6 +119,7 @@ struct rsxx_dma_ctrl {
116struct rsxx_cardinfo { 119struct rsxx_cardinfo {
117 struct pci_dev *dev; 120 struct pci_dev *dev;
118 unsigned int halt; 121 unsigned int halt;
122 unsigned int eeh_state;
119 123
120 void __iomem *regmap; 124 void __iomem *regmap;
121 spinlock_t irq_lock; 125 spinlock_t irq_lock;
@@ -224,6 +228,7 @@ enum rsxx_pci_regmap {
224 PERF_RD512_HI = 0xac, 228 PERF_RD512_HI = 0xac,
225 PERF_WR512_LO = 0xb0, 229 PERF_WR512_LO = 0xb0,
226 PERF_WR512_HI = 0xb4, 230 PERF_WR512_HI = 0xb4,
231 PCI_RECONFIG = 0xb8,
227}; 232};
228 233
229enum rsxx_intr { 234enum rsxx_intr {
@@ -237,6 +242,8 @@ enum rsxx_intr {
237 CR_INTR_DMA5 = 0x00000080, 242 CR_INTR_DMA5 = 0x00000080,
238 CR_INTR_DMA6 = 0x00000100, 243 CR_INTR_DMA6 = 0x00000100,
239 CR_INTR_DMA7 = 0x00000200, 244 CR_INTR_DMA7 = 0x00000200,
245 CR_INTR_ALL_C = 0x0000003f,
246 CR_INTR_ALL_G = 0x000003ff,
240 CR_INTR_DMA_ALL = 0x000003f5, 247 CR_INTR_DMA_ALL = 0x000003f5,
241 CR_INTR_ALL = 0xffffffff, 248 CR_INTR_ALL = 0xffffffff,
242}; 249};
@@ -253,8 +260,14 @@ enum rsxx_pci_reset {
253 DMA_QUEUE_RESET = 0x00000001, 260 DMA_QUEUE_RESET = 0x00000001,
254}; 261};
255 262
263enum rsxx_hw_fifo_flush {
264 RSXX_FLUSH_BUSY = 0x00000002,
265 RSXX_FLUSH_TIMEOUT = 0x00000004,
266};
267
256enum rsxx_pci_revision { 268enum rsxx_pci_revision {
257 RSXX_DISCARD_SUPPORT = 2, 269 RSXX_DISCARD_SUPPORT = 2,
270 RSXX_EEH_SUPPORT = 3,
258}; 271};
259 272
260enum rsxx_creg_cmd { 273enum rsxx_creg_cmd {
@@ -360,11 +373,17 @@ int rsxx_dma_setup(struct rsxx_cardinfo *card);
360void rsxx_dma_destroy(struct rsxx_cardinfo *card); 373void rsxx_dma_destroy(struct rsxx_cardinfo *card);
361int rsxx_dma_init(void); 374int rsxx_dma_init(void);
362void rsxx_dma_cleanup(void); 375void rsxx_dma_cleanup(void);
376void rsxx_dma_queue_reset(struct rsxx_cardinfo *card);
377int rsxx_dma_configure(struct rsxx_cardinfo *card);
363int rsxx_dma_queue_bio(struct rsxx_cardinfo *card, 378int rsxx_dma_queue_bio(struct rsxx_cardinfo *card,
364 struct bio *bio, 379 struct bio *bio,
365 atomic_t *n_dmas, 380 atomic_t *n_dmas,
366 rsxx_dma_cb cb, 381 rsxx_dma_cb cb,
367 void *cb_data); 382 void *cb_data);
383int rsxx_hw_buffers_init(struct pci_dev *dev, struct rsxx_dma_ctrl *ctrl);
384int rsxx_eeh_save_issued_dmas(struct rsxx_cardinfo *card);
385void rsxx_eeh_cancel_dmas(struct rsxx_cardinfo *card);
386int rsxx_eeh_remap_dmas(struct rsxx_cardinfo *card);
368 387
369/***** cregs.c *****/ 388/***** cregs.c *****/
370int rsxx_creg_write(struct rsxx_cardinfo *card, u32 addr, 389int rsxx_creg_write(struct rsxx_cardinfo *card, u32 addr,
@@ -389,10 +408,11 @@ int rsxx_creg_setup(struct rsxx_cardinfo *card);
389void rsxx_creg_destroy(struct rsxx_cardinfo *card); 408void rsxx_creg_destroy(struct rsxx_cardinfo *card);
390int rsxx_creg_init(void); 409int rsxx_creg_init(void);
391void rsxx_creg_cleanup(void); 410void rsxx_creg_cleanup(void);
392
393int rsxx_reg_access(struct rsxx_cardinfo *card, 411int rsxx_reg_access(struct rsxx_cardinfo *card,
394 struct rsxx_reg_access __user *ucmd, 412 struct rsxx_reg_access __user *ucmd,
395 int read); 413 int read);
414void rsxx_eeh_save_issued_creg(struct rsxx_cardinfo *card);
415void rsxx_kick_creg_queue(struct rsxx_cardinfo *card);
396 416
397 417
398 418
diff --git a/drivers/block/xen-blkback/blkback.c b/drivers/block/xen-blkback/blkback.c
index de1f319f7bd7..dd5b2fed97e9 100644
--- a/drivers/block/xen-blkback/blkback.c
+++ b/drivers/block/xen-blkback/blkback.c
@@ -164,7 +164,7 @@ static void make_response(struct xen_blkif *blkif, u64 id,
164 164
165#define foreach_grant_safe(pos, n, rbtree, node) \ 165#define foreach_grant_safe(pos, n, rbtree, node) \
166 for ((pos) = container_of(rb_first((rbtree)), typeof(*(pos)), node), \ 166 for ((pos) = container_of(rb_first((rbtree)), typeof(*(pos)), node), \
167 (n) = rb_next(&(pos)->node); \ 167 (n) = (&(pos)->node != NULL) ? rb_next(&(pos)->node) : NULL; \
168 &(pos)->node != NULL; \ 168 &(pos)->node != NULL; \
169 (pos) = container_of(n, typeof(*(pos)), node), \ 169 (pos) = container_of(n, typeof(*(pos)), node), \
170 (n) = (&(pos)->node != NULL) ? rb_next(&(pos)->node) : NULL) 170 (n) = (&(pos)->node != NULL) ? rb_next(&(pos)->node) : NULL)
@@ -381,8 +381,8 @@ irqreturn_t xen_blkif_be_int(int irq, void *dev_id)
381 381
382static void print_stats(struct xen_blkif *blkif) 382static void print_stats(struct xen_blkif *blkif)
383{ 383{
384 pr_info("xen-blkback (%s): oo %3d | rd %4d | wr %4d | f %4d" 384 pr_info("xen-blkback (%s): oo %3llu | rd %4llu | wr %4llu | f %4llu"
385 " | ds %4d\n", 385 " | ds %4llu\n",
386 current->comm, blkif->st_oo_req, 386 current->comm, blkif->st_oo_req,
387 blkif->st_rd_req, blkif->st_wr_req, 387 blkif->st_rd_req, blkif->st_wr_req,
388 blkif->st_f_req, blkif->st_ds_req); 388 blkif->st_f_req, blkif->st_ds_req);
@@ -442,7 +442,7 @@ int xen_blkif_schedule(void *arg)
442} 442}
443 443
444struct seg_buf { 444struct seg_buf {
445 unsigned long buf; 445 unsigned int offset;
446 unsigned int nsec; 446 unsigned int nsec;
447}; 447};
448/* 448/*
@@ -621,30 +621,21 @@ static int xen_blkbk_map(struct blkif_request *req,
621 * If this is a new persistent grant 621 * If this is a new persistent grant
622 * save the handler 622 * save the handler
623 */ 623 */
624 persistent_gnts[i]->handle = map[j].handle; 624 persistent_gnts[i]->handle = map[j++].handle;
625 persistent_gnts[i]->dev_bus_addr =
626 map[j++].dev_bus_addr;
627 } 625 }
628 pending_handle(pending_req, i) = 626 pending_handle(pending_req, i) =
629 persistent_gnts[i]->handle; 627 persistent_gnts[i]->handle;
630 628
631 if (ret) 629 if (ret)
632 continue; 630 continue;
633
634 seg[i].buf = persistent_gnts[i]->dev_bus_addr |
635 (req->u.rw.seg[i].first_sect << 9);
636 } else { 631 } else {
637 pending_handle(pending_req, i) = map[j].handle; 632 pending_handle(pending_req, i) = map[j++].handle;
638 bitmap_set(pending_req->unmap_seg, i, 1); 633 bitmap_set(pending_req->unmap_seg, i, 1);
639 634
640 if (ret) { 635 if (ret)
641 j++;
642 continue; 636 continue;
643 }
644
645 seg[i].buf = map[j++].dev_bus_addr |
646 (req->u.rw.seg[i].first_sect << 9);
647 } 637 }
638 seg[i].offset = (req->u.rw.seg[i].first_sect << 9);
648 } 639 }
649 return ret; 640 return ret;
650} 641}
@@ -679,6 +670,16 @@ static int dispatch_discard_io(struct xen_blkif *blkif,
679 return err; 670 return err;
680} 671}
681 672
673static int dispatch_other_io(struct xen_blkif *blkif,
674 struct blkif_request *req,
675 struct pending_req *pending_req)
676{
677 free_req(pending_req);
678 make_response(blkif, req->u.other.id, req->operation,
679 BLKIF_RSP_EOPNOTSUPP);
680 return -EIO;
681}
682
682static void xen_blk_drain_io(struct xen_blkif *blkif) 683static void xen_blk_drain_io(struct xen_blkif *blkif)
683{ 684{
684 atomic_set(&blkif->drain, 1); 685 atomic_set(&blkif->drain, 1);
@@ -800,17 +801,30 @@ __do_block_io_op(struct xen_blkif *blkif)
800 801
801 /* Apply all sanity checks to /private copy/ of request. */ 802 /* Apply all sanity checks to /private copy/ of request. */
802 barrier(); 803 barrier();
803 if (unlikely(req.operation == BLKIF_OP_DISCARD)) { 804
805 switch (req.operation) {
806 case BLKIF_OP_READ:
807 case BLKIF_OP_WRITE:
808 case BLKIF_OP_WRITE_BARRIER:
809 case BLKIF_OP_FLUSH_DISKCACHE:
810 if (dispatch_rw_block_io(blkif, &req, pending_req))
811 goto done;
812 break;
813 case BLKIF_OP_DISCARD:
804 free_req(pending_req); 814 free_req(pending_req);
805 if (dispatch_discard_io(blkif, &req)) 815 if (dispatch_discard_io(blkif, &req))
806 break; 816 goto done;
807 } else if (dispatch_rw_block_io(blkif, &req, pending_req))
808 break; 817 break;
818 default:
819 if (dispatch_other_io(blkif, &req, pending_req))
820 goto done;
821 break;
822 }
809 823
810 /* Yield point for this unbounded loop. */ 824 /* Yield point for this unbounded loop. */
811 cond_resched(); 825 cond_resched();
812 } 826 }
813 827done:
814 return more_to_do; 828 return more_to_do;
815} 829}
816 830
@@ -904,7 +918,8 @@ static int dispatch_rw_block_io(struct xen_blkif *blkif,
904 pr_debug(DRV_PFX "access denied: %s of [%llu,%llu] on dev=%04x\n", 918 pr_debug(DRV_PFX "access denied: %s of [%llu,%llu] on dev=%04x\n",
905 operation == READ ? "read" : "write", 919 operation == READ ? "read" : "write",
906 preq.sector_number, 920 preq.sector_number,
907 preq.sector_number + preq.nr_sects, preq.dev); 921 preq.sector_number + preq.nr_sects,
922 blkif->vbd.pdevice);
908 goto fail_response; 923 goto fail_response;
909 } 924 }
910 925
@@ -947,7 +962,7 @@ static int dispatch_rw_block_io(struct xen_blkif *blkif,
947 (bio_add_page(bio, 962 (bio_add_page(bio,
948 pages[i], 963 pages[i],
949 seg[i].nsec << 9, 964 seg[i].nsec << 9,
950 seg[i].buf & ~PAGE_MASK) == 0)) { 965 seg[i].offset) == 0)) {
951 966
952 bio = bio_alloc(GFP_KERNEL, nseg-i); 967 bio = bio_alloc(GFP_KERNEL, nseg-i);
953 if (unlikely(bio == NULL)) 968 if (unlikely(bio == NULL))
@@ -977,13 +992,7 @@ static int dispatch_rw_block_io(struct xen_blkif *blkif,
977 bio->bi_end_io = end_block_io_op; 992 bio->bi_end_io = end_block_io_op;
978 } 993 }
979 994
980 /*
981 * We set it one so that the last submit_bio does not have to call
982 * atomic_inc.
983 */
984 atomic_set(&pending_req->pendcnt, nbio); 995 atomic_set(&pending_req->pendcnt, nbio);
985
986 /* Get a reference count for the disk queue and start sending I/O */
987 blk_start_plug(&plug); 996 blk_start_plug(&plug);
988 997
989 for (i = 0; i < nbio; i++) 998 for (i = 0; i < nbio; i++)
@@ -1011,6 +1020,7 @@ static int dispatch_rw_block_io(struct xen_blkif *blkif,
1011 fail_put_bio: 1020 fail_put_bio:
1012 for (i = 0; i < nbio; i++) 1021 for (i = 0; i < nbio; i++)
1013 bio_put(biolist[i]); 1022 bio_put(biolist[i]);
1023 atomic_set(&pending_req->pendcnt, 1);
1014 __end_block_io_op(pending_req, -EINVAL); 1024 __end_block_io_op(pending_req, -EINVAL);
1015 msleep(1); /* back off a bit */ 1025 msleep(1); /* back off a bit */
1016 return -EIO; 1026 return -EIO;
diff --git a/drivers/block/xen-blkback/common.h b/drivers/block/xen-blkback/common.h
index 6072390c7f57..60103e2517ba 100644
--- a/drivers/block/xen-blkback/common.h
+++ b/drivers/block/xen-blkback/common.h
@@ -77,11 +77,18 @@ struct blkif_x86_32_request_discard {
77 uint64_t nr_sectors; 77 uint64_t nr_sectors;
78} __attribute__((__packed__)); 78} __attribute__((__packed__));
79 79
80struct blkif_x86_32_request_other {
81 uint8_t _pad1;
82 blkif_vdev_t _pad2;
83 uint64_t id; /* private guest value, echoed in resp */
84} __attribute__((__packed__));
85
80struct blkif_x86_32_request { 86struct blkif_x86_32_request {
81 uint8_t operation; /* BLKIF_OP_??? */ 87 uint8_t operation; /* BLKIF_OP_??? */
82 union { 88 union {
83 struct blkif_x86_32_request_rw rw; 89 struct blkif_x86_32_request_rw rw;
84 struct blkif_x86_32_request_discard discard; 90 struct blkif_x86_32_request_discard discard;
91 struct blkif_x86_32_request_other other;
85 } u; 92 } u;
86} __attribute__((__packed__)); 93} __attribute__((__packed__));
87 94
@@ -113,11 +120,19 @@ struct blkif_x86_64_request_discard {
113 uint64_t nr_sectors; 120 uint64_t nr_sectors;
114} __attribute__((__packed__)); 121} __attribute__((__packed__));
115 122
123struct blkif_x86_64_request_other {
124 uint8_t _pad1;
125 blkif_vdev_t _pad2;
126 uint32_t _pad3; /* offsetof(blkif_..,u.discard.id)==8 */
127 uint64_t id; /* private guest value, echoed in resp */
128} __attribute__((__packed__));
129
116struct blkif_x86_64_request { 130struct blkif_x86_64_request {
117 uint8_t operation; /* BLKIF_OP_??? */ 131 uint8_t operation; /* BLKIF_OP_??? */
118 union { 132 union {
119 struct blkif_x86_64_request_rw rw; 133 struct blkif_x86_64_request_rw rw;
120 struct blkif_x86_64_request_discard discard; 134 struct blkif_x86_64_request_discard discard;
135 struct blkif_x86_64_request_other other;
121 } u; 136 } u;
122} __attribute__((__packed__)); 137} __attribute__((__packed__));
123 138
@@ -172,7 +187,6 @@ struct persistent_gnt {
172 struct page *page; 187 struct page *page;
173 grant_ref_t gnt; 188 grant_ref_t gnt;
174 grant_handle_t handle; 189 grant_handle_t handle;
175 uint64_t dev_bus_addr;
176 struct rb_node node; 190 struct rb_node node;
177}; 191};
178 192
@@ -208,13 +222,13 @@ struct xen_blkif {
208 222
209 /* statistics */ 223 /* statistics */
210 unsigned long st_print; 224 unsigned long st_print;
211 int st_rd_req; 225 unsigned long long st_rd_req;
212 int st_wr_req; 226 unsigned long long st_wr_req;
213 int st_oo_req; 227 unsigned long long st_oo_req;
214 int st_f_req; 228 unsigned long long st_f_req;
215 int st_ds_req; 229 unsigned long long st_ds_req;
216 int st_rd_sect; 230 unsigned long long st_rd_sect;
217 int st_wr_sect; 231 unsigned long long st_wr_sect;
218 232
219 wait_queue_head_t waiting_to_free; 233 wait_queue_head_t waiting_to_free;
220}; 234};
@@ -278,6 +292,11 @@ static inline void blkif_get_x86_32_req(struct blkif_request *dst,
278 dst->u.discard.nr_sectors = src->u.discard.nr_sectors; 292 dst->u.discard.nr_sectors = src->u.discard.nr_sectors;
279 break; 293 break;
280 default: 294 default:
295 /*
296 * Don't know how to translate this op. Only get the
297 * ID so failure can be reported to the frontend.
298 */
299 dst->u.other.id = src->u.other.id;
281 break; 300 break;
282 } 301 }
283} 302}
@@ -309,6 +328,11 @@ static inline void blkif_get_x86_64_req(struct blkif_request *dst,
309 dst->u.discard.nr_sectors = src->u.discard.nr_sectors; 328 dst->u.discard.nr_sectors = src->u.discard.nr_sectors;
310 break; 329 break;
311 default: 330 default:
331 /*
332 * Don't know how to translate this op. Only get the
333 * ID so failure can be reported to the frontend.
334 */
335 dst->u.other.id = src->u.other.id;
312 break; 336 break;
313 } 337 }
314} 338}
diff --git a/drivers/block/xen-blkback/xenbus.c b/drivers/block/xen-blkback/xenbus.c
index 5e237f630c47..8bfd1bcf95ec 100644
--- a/drivers/block/xen-blkback/xenbus.c
+++ b/drivers/block/xen-blkback/xenbus.c
@@ -230,13 +230,13 @@ int __init xen_blkif_interface_init(void)
230 } \ 230 } \
231 static DEVICE_ATTR(name, S_IRUGO, show_##name, NULL) 231 static DEVICE_ATTR(name, S_IRUGO, show_##name, NULL)
232 232
233VBD_SHOW(oo_req, "%d\n", be->blkif->st_oo_req); 233VBD_SHOW(oo_req, "%llu\n", be->blkif->st_oo_req);
234VBD_SHOW(rd_req, "%d\n", be->blkif->st_rd_req); 234VBD_SHOW(rd_req, "%llu\n", be->blkif->st_rd_req);
235VBD_SHOW(wr_req, "%d\n", be->blkif->st_wr_req); 235VBD_SHOW(wr_req, "%llu\n", be->blkif->st_wr_req);
236VBD_SHOW(f_req, "%d\n", be->blkif->st_f_req); 236VBD_SHOW(f_req, "%llu\n", be->blkif->st_f_req);
237VBD_SHOW(ds_req, "%d\n", be->blkif->st_ds_req); 237VBD_SHOW(ds_req, "%llu\n", be->blkif->st_ds_req);
238VBD_SHOW(rd_sect, "%d\n", be->blkif->st_rd_sect); 238VBD_SHOW(rd_sect, "%llu\n", be->blkif->st_rd_sect);
239VBD_SHOW(wr_sect, "%d\n", be->blkif->st_wr_sect); 239VBD_SHOW(wr_sect, "%llu\n", be->blkif->st_wr_sect);
240 240
241static struct attribute *xen_vbdstat_attrs[] = { 241static struct attribute *xen_vbdstat_attrs[] = {
242 &dev_attr_oo_req.attr, 242 &dev_attr_oo_req.attr,
diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c
index c3dae2e0f290..a894f88762d8 100644
--- a/drivers/block/xen-blkfront.c
+++ b/drivers/block/xen-blkfront.c
@@ -44,7 +44,7 @@
44#include <linux/mutex.h> 44#include <linux/mutex.h>
45#include <linux/scatterlist.h> 45#include <linux/scatterlist.h>
46#include <linux/bitmap.h> 46#include <linux/bitmap.h>
47#include <linux/llist.h> 47#include <linux/list.h>
48 48
49#include <xen/xen.h> 49#include <xen/xen.h>
50#include <xen/xenbus.h> 50#include <xen/xenbus.h>
@@ -68,13 +68,12 @@ enum blkif_state {
68struct grant { 68struct grant {
69 grant_ref_t gref; 69 grant_ref_t gref;
70 unsigned long pfn; 70 unsigned long pfn;
71 struct llist_node node; 71 struct list_head node;
72}; 72};
73 73
74struct blk_shadow { 74struct blk_shadow {
75 struct blkif_request req; 75 struct blkif_request req;
76 struct request *request; 76 struct request *request;
77 unsigned long frame[BLKIF_MAX_SEGMENTS_PER_REQUEST];
78 struct grant *grants_used[BLKIF_MAX_SEGMENTS_PER_REQUEST]; 77 struct grant *grants_used[BLKIF_MAX_SEGMENTS_PER_REQUEST];
79}; 78};
80 79
@@ -105,7 +104,7 @@ struct blkfront_info
105 struct work_struct work; 104 struct work_struct work;
106 struct gnttab_free_callback callback; 105 struct gnttab_free_callback callback;
107 struct blk_shadow shadow[BLK_RING_SIZE]; 106 struct blk_shadow shadow[BLK_RING_SIZE];
108 struct llist_head persistent_gnts; 107 struct list_head persistent_gnts;
109 unsigned int persistent_gnts_c; 108 unsigned int persistent_gnts_c;
110 unsigned long shadow_free; 109 unsigned long shadow_free;
111 unsigned int feature_flush; 110 unsigned int feature_flush;
@@ -165,6 +164,69 @@ static int add_id_to_freelist(struct blkfront_info *info,
165 return 0; 164 return 0;
166} 165}
167 166
167static int fill_grant_buffer(struct blkfront_info *info, int num)
168{
169 struct page *granted_page;
170 struct grant *gnt_list_entry, *n;
171 int i = 0;
172
173 while(i < num) {
174 gnt_list_entry = kzalloc(sizeof(struct grant), GFP_NOIO);
175 if (!gnt_list_entry)
176 goto out_of_memory;
177
178 granted_page = alloc_page(GFP_NOIO);
179 if (!granted_page) {
180 kfree(gnt_list_entry);
181 goto out_of_memory;
182 }
183
184 gnt_list_entry->pfn = page_to_pfn(granted_page);
185 gnt_list_entry->gref = GRANT_INVALID_REF;
186 list_add(&gnt_list_entry->node, &info->persistent_gnts);
187 i++;
188 }
189
190 return 0;
191
192out_of_memory:
193 list_for_each_entry_safe(gnt_list_entry, n,
194 &info->persistent_gnts, node) {
195 list_del(&gnt_list_entry->node);
196 __free_page(pfn_to_page(gnt_list_entry->pfn));
197 kfree(gnt_list_entry);
198 i--;
199 }
200 BUG_ON(i != 0);
201 return -ENOMEM;
202}
203
204static struct grant *get_grant(grant_ref_t *gref_head,
205 struct blkfront_info *info)
206{
207 struct grant *gnt_list_entry;
208 unsigned long buffer_mfn;
209
210 BUG_ON(list_empty(&info->persistent_gnts));
211 gnt_list_entry = list_first_entry(&info->persistent_gnts, struct grant,
212 node);
213 list_del(&gnt_list_entry->node);
214
215 if (gnt_list_entry->gref != GRANT_INVALID_REF) {
216 info->persistent_gnts_c--;
217 return gnt_list_entry;
218 }
219
220 /* Assign a gref to this page */
221 gnt_list_entry->gref = gnttab_claim_grant_reference(gref_head);
222 BUG_ON(gnt_list_entry->gref == -ENOSPC);
223 buffer_mfn = pfn_to_mfn(gnt_list_entry->pfn);
224 gnttab_grant_foreign_access_ref(gnt_list_entry->gref,
225 info->xbdev->otherend_id,
226 buffer_mfn, 0);
227 return gnt_list_entry;
228}
229
168static const char *op_name(int op) 230static const char *op_name(int op)
169{ 231{
170 static const char *const names[] = { 232 static const char *const names[] = {
@@ -293,7 +355,6 @@ static int blkif_ioctl(struct block_device *bdev, fmode_t mode,
293static int blkif_queue_request(struct request *req) 355static int blkif_queue_request(struct request *req)
294{ 356{
295 struct blkfront_info *info = req->rq_disk->private_data; 357 struct blkfront_info *info = req->rq_disk->private_data;
296 unsigned long buffer_mfn;
297 struct blkif_request *ring_req; 358 struct blkif_request *ring_req;
298 unsigned long id; 359 unsigned long id;
299 unsigned int fsect, lsect; 360 unsigned int fsect, lsect;
@@ -306,7 +367,6 @@ static int blkif_queue_request(struct request *req)
306 */ 367 */
307 bool new_persistent_gnts; 368 bool new_persistent_gnts;
308 grant_ref_t gref_head; 369 grant_ref_t gref_head;
309 struct page *granted_page;
310 struct grant *gnt_list_entry = NULL; 370 struct grant *gnt_list_entry = NULL;
311 struct scatterlist *sg; 371 struct scatterlist *sg;
312 372
@@ -370,41 +430,8 @@ static int blkif_queue_request(struct request *req)
370 fsect = sg->offset >> 9; 430 fsect = sg->offset >> 9;
371 lsect = fsect + (sg->length >> 9) - 1; 431 lsect = fsect + (sg->length >> 9) - 1;
372 432
373 if (info->persistent_gnts_c) { 433 gnt_list_entry = get_grant(&gref_head, info);
374 BUG_ON(llist_empty(&info->persistent_gnts)); 434 ref = gnt_list_entry->gref;
375 gnt_list_entry = llist_entry(
376 llist_del_first(&info->persistent_gnts),
377 struct grant, node);
378
379 ref = gnt_list_entry->gref;
380 buffer_mfn = pfn_to_mfn(gnt_list_entry->pfn);
381 info->persistent_gnts_c--;
382 } else {
383 ref = gnttab_claim_grant_reference(&gref_head);
384 BUG_ON(ref == -ENOSPC);
385
386 gnt_list_entry =
387 kmalloc(sizeof(struct grant),
388 GFP_ATOMIC);
389 if (!gnt_list_entry)
390 return -ENOMEM;
391
392 granted_page = alloc_page(GFP_ATOMIC);
393 if (!granted_page) {
394 kfree(gnt_list_entry);
395 return -ENOMEM;
396 }
397
398 gnt_list_entry->pfn =
399 page_to_pfn(granted_page);
400 gnt_list_entry->gref = ref;
401
402 buffer_mfn = pfn_to_mfn(page_to_pfn(
403 granted_page));
404 gnttab_grant_foreign_access_ref(ref,
405 info->xbdev->otherend_id,
406 buffer_mfn, 0);
407 }
408 435
409 info->shadow[id].grants_used[i] = gnt_list_entry; 436 info->shadow[id].grants_used[i] = gnt_list_entry;
410 437
@@ -435,7 +462,6 @@ static int blkif_queue_request(struct request *req)
435 kunmap_atomic(shared_data); 462 kunmap_atomic(shared_data);
436 } 463 }
437 464
438 info->shadow[id].frame[i] = mfn_to_pfn(buffer_mfn);
439 ring_req->u.rw.seg[i] = 465 ring_req->u.rw.seg[i] =
440 (struct blkif_request_segment) { 466 (struct blkif_request_segment) {
441 .gref = ref, 467 .gref = ref,
@@ -790,9 +816,8 @@ static void blkif_restart_queue(struct work_struct *work)
790 816
791static void blkif_free(struct blkfront_info *info, int suspend) 817static void blkif_free(struct blkfront_info *info, int suspend)
792{ 818{
793 struct llist_node *all_gnts; 819 struct grant *persistent_gnt;
794 struct grant *persistent_gnt, *tmp; 820 struct grant *n;
795 struct llist_node *n;
796 821
797 /* Prevent new requests being issued until we fix things up. */ 822 /* Prevent new requests being issued until we fix things up. */
798 spin_lock_irq(&info->io_lock); 823 spin_lock_irq(&info->io_lock);
@@ -803,22 +828,20 @@ static void blkif_free(struct blkfront_info *info, int suspend)
803 blk_stop_queue(info->rq); 828 blk_stop_queue(info->rq);
804 829
805 /* Remove all persistent grants */ 830 /* Remove all persistent grants */
806 if (info->persistent_gnts_c) { 831 if (!list_empty(&info->persistent_gnts)) {
807 all_gnts = llist_del_all(&info->persistent_gnts); 832 list_for_each_entry_safe(persistent_gnt, n,
808 persistent_gnt = llist_entry(all_gnts, typeof(*(persistent_gnt)), node); 833 &info->persistent_gnts, node) {
809 while (persistent_gnt) { 834 list_del(&persistent_gnt->node);
810 gnttab_end_foreign_access(persistent_gnt->gref, 0, 0UL); 835 if (persistent_gnt->gref != GRANT_INVALID_REF) {
836 gnttab_end_foreign_access(persistent_gnt->gref,
837 0, 0UL);
838 info->persistent_gnts_c--;
839 }
811 __free_page(pfn_to_page(persistent_gnt->pfn)); 840 __free_page(pfn_to_page(persistent_gnt->pfn));
812 tmp = persistent_gnt; 841 kfree(persistent_gnt);
813 n = persistent_gnt->node.next;
814 if (n)
815 persistent_gnt = llist_entry(n, typeof(*(persistent_gnt)), node);
816 else
817 persistent_gnt = NULL;
818 kfree(tmp);
819 } 842 }
820 info->persistent_gnts_c = 0;
821 } 843 }
844 BUG_ON(info->persistent_gnts_c != 0);
822 845
823 /* No more gnttab callback work. */ 846 /* No more gnttab callback work. */
824 gnttab_cancel_free_callback(&info->callback); 847 gnttab_cancel_free_callback(&info->callback);
@@ -875,7 +898,7 @@ static void blkif_completion(struct blk_shadow *s, struct blkfront_info *info,
875 } 898 }
876 /* Add the persistent grant into the list of free grants */ 899 /* Add the persistent grant into the list of free grants */
877 for (i = 0; i < s->req.u.rw.nr_segments; i++) { 900 for (i = 0; i < s->req.u.rw.nr_segments; i++) {
878 llist_add(&s->grants_used[i]->node, &info->persistent_gnts); 901 list_add(&s->grants_used[i]->node, &info->persistent_gnts);
879 info->persistent_gnts_c++; 902 info->persistent_gnts_c++;
880 } 903 }
881} 904}
@@ -1013,6 +1036,12 @@ static int setup_blkring(struct xenbus_device *dev,
1013 1036
1014 sg_init_table(info->sg, BLKIF_MAX_SEGMENTS_PER_REQUEST); 1037 sg_init_table(info->sg, BLKIF_MAX_SEGMENTS_PER_REQUEST);
1015 1038
1039 /* Allocate memory for grants */
1040 err = fill_grant_buffer(info, BLK_RING_SIZE *
1041 BLKIF_MAX_SEGMENTS_PER_REQUEST);
1042 if (err)
1043 goto fail;
1044
1016 err = xenbus_grant_ring(dev, virt_to_mfn(info->ring.sring)); 1045 err = xenbus_grant_ring(dev, virt_to_mfn(info->ring.sring));
1017 if (err < 0) { 1046 if (err < 0) {
1018 free_page((unsigned long)sring); 1047 free_page((unsigned long)sring);
@@ -1171,7 +1200,7 @@ static int blkfront_probe(struct xenbus_device *dev,
1171 spin_lock_init(&info->io_lock); 1200 spin_lock_init(&info->io_lock);
1172 info->xbdev = dev; 1201 info->xbdev = dev;
1173 info->vdevice = vdevice; 1202 info->vdevice = vdevice;
1174 init_llist_head(&info->persistent_gnts); 1203 INIT_LIST_HEAD(&info->persistent_gnts);
1175 info->persistent_gnts_c = 0; 1204 info->persistent_gnts_c = 0;
1176 info->connected = BLKIF_STATE_DISCONNECTED; 1205 info->connected = BLKIF_STATE_DISCONNECTED;
1177 INIT_WORK(&info->work, blkif_restart_queue); 1206 INIT_WORK(&info->work, blkif_restart_queue);
@@ -1203,11 +1232,10 @@ static int blkif_recover(struct blkfront_info *info)
1203 int j; 1232 int j;
1204 1233
1205 /* Stage 1: Make a safe copy of the shadow state. */ 1234 /* Stage 1: Make a safe copy of the shadow state. */
1206 copy = kmalloc(sizeof(info->shadow), 1235 copy = kmemdup(info->shadow, sizeof(info->shadow),
1207 GFP_NOIO | __GFP_REPEAT | __GFP_HIGH); 1236 GFP_NOIO | __GFP_REPEAT | __GFP_HIGH);
1208 if (!copy) 1237 if (!copy)
1209 return -ENOMEM; 1238 return -ENOMEM;
1210 memcpy(copy, info->shadow, sizeof(info->shadow));
1211 1239
1212 /* Stage 2: Set up free list. */ 1240 /* Stage 2: Set up free list. */
1213 memset(&info->shadow, 0, sizeof(info->shadow)); 1241 memset(&info->shadow, 0, sizeof(info->shadow));
@@ -1236,7 +1264,7 @@ static int blkif_recover(struct blkfront_info *info)
1236 gnttab_grant_foreign_access_ref( 1264 gnttab_grant_foreign_access_ref(
1237 req->u.rw.seg[j].gref, 1265 req->u.rw.seg[j].gref,
1238 info->xbdev->otherend_id, 1266 info->xbdev->otherend_id,
1239 pfn_to_mfn(info->shadow[req->u.rw.id].frame[j]), 1267 pfn_to_mfn(copy[i].grants_used[j]->pfn),
1240 0); 1268 0);
1241 } 1269 }
1242 info->shadow[req->u.rw.id].req = *req; 1270 info->shadow[req->u.rw.id].req = *req;
diff --git a/drivers/bluetooth/ath3k.c b/drivers/bluetooth/ath3k.c
index a8a41e07a221..6aab00ef4379 100644
--- a/drivers/bluetooth/ath3k.c
+++ b/drivers/bluetooth/ath3k.c
@@ -73,9 +73,13 @@ static struct usb_device_id ath3k_table[] = {
73 { USB_DEVICE(0x03F0, 0x311D) }, 73 { USB_DEVICE(0x03F0, 0x311D) },
74 74
75 /* Atheros AR3012 with sflash firmware*/ 75 /* Atheros AR3012 with sflash firmware*/
76 { USB_DEVICE(0x0CF3, 0x0036) },
76 { USB_DEVICE(0x0CF3, 0x3004) }, 77 { USB_DEVICE(0x0CF3, 0x3004) },
78 { USB_DEVICE(0x0CF3, 0x3008) },
77 { USB_DEVICE(0x0CF3, 0x311D) }, 79 { USB_DEVICE(0x0CF3, 0x311D) },
80 { USB_DEVICE(0x0CF3, 0x817a) },
78 { USB_DEVICE(0x13d3, 0x3375) }, 81 { USB_DEVICE(0x13d3, 0x3375) },
82 { USB_DEVICE(0x04CA, 0x3004) },
79 { USB_DEVICE(0x04CA, 0x3005) }, 83 { USB_DEVICE(0x04CA, 0x3005) },
80 { USB_DEVICE(0x04CA, 0x3006) }, 84 { USB_DEVICE(0x04CA, 0x3006) },
81 { USB_DEVICE(0x04CA, 0x3008) }, 85 { USB_DEVICE(0x04CA, 0x3008) },
@@ -105,9 +109,13 @@ MODULE_DEVICE_TABLE(usb, ath3k_table);
105static struct usb_device_id ath3k_blist_tbl[] = { 109static struct usb_device_id ath3k_blist_tbl[] = {
106 110
107 /* Atheros AR3012 with sflash firmware*/ 111 /* Atheros AR3012 with sflash firmware*/
112 { USB_DEVICE(0x0CF3, 0x0036), .driver_info = BTUSB_ATH3012 },
108 { USB_DEVICE(0x0cf3, 0x3004), .driver_info = BTUSB_ATH3012 }, 113 { USB_DEVICE(0x0cf3, 0x3004), .driver_info = BTUSB_ATH3012 },
114 { USB_DEVICE(0x0cf3, 0x3008), .driver_info = BTUSB_ATH3012 },
109 { USB_DEVICE(0x0cf3, 0x311D), .driver_info = BTUSB_ATH3012 }, 115 { USB_DEVICE(0x0cf3, 0x311D), .driver_info = BTUSB_ATH3012 },
116 { USB_DEVICE(0x0CF3, 0x817a), .driver_info = BTUSB_ATH3012 },
110 { USB_DEVICE(0x13d3, 0x3375), .driver_info = BTUSB_ATH3012 }, 117 { USB_DEVICE(0x13d3, 0x3375), .driver_info = BTUSB_ATH3012 },
118 { USB_DEVICE(0x04ca, 0x3004), .driver_info = BTUSB_ATH3012 },
111 { USB_DEVICE(0x04ca, 0x3005), .driver_info = BTUSB_ATH3012 }, 119 { USB_DEVICE(0x04ca, 0x3005), .driver_info = BTUSB_ATH3012 },
112 { USB_DEVICE(0x04ca, 0x3006), .driver_info = BTUSB_ATH3012 }, 120 { USB_DEVICE(0x04ca, 0x3006), .driver_info = BTUSB_ATH3012 },
113 { USB_DEVICE(0x04ca, 0x3008), .driver_info = BTUSB_ATH3012 }, 121 { USB_DEVICE(0x04ca, 0x3008), .driver_info = BTUSB_ATH3012 },
diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
index 7e351e345476..2cc5f774a29c 100644
--- a/drivers/bluetooth/btusb.c
+++ b/drivers/bluetooth/btusb.c
@@ -131,9 +131,13 @@ static struct usb_device_id blacklist_table[] = {
131 { USB_DEVICE(0x03f0, 0x311d), .driver_info = BTUSB_IGNORE }, 131 { USB_DEVICE(0x03f0, 0x311d), .driver_info = BTUSB_IGNORE },
132 132
133 /* Atheros 3012 with sflash firmware */ 133 /* Atheros 3012 with sflash firmware */
134 { USB_DEVICE(0x0cf3, 0x0036), .driver_info = BTUSB_ATH3012 },
134 { USB_DEVICE(0x0cf3, 0x3004), .driver_info = BTUSB_ATH3012 }, 135 { USB_DEVICE(0x0cf3, 0x3004), .driver_info = BTUSB_ATH3012 },
136 { USB_DEVICE(0x0cf3, 0x3008), .driver_info = BTUSB_ATH3012 },
135 { USB_DEVICE(0x0cf3, 0x311d), .driver_info = BTUSB_ATH3012 }, 137 { USB_DEVICE(0x0cf3, 0x311d), .driver_info = BTUSB_ATH3012 },
138 { USB_DEVICE(0x0cf3, 0x817a), .driver_info = BTUSB_ATH3012 },
136 { USB_DEVICE(0x13d3, 0x3375), .driver_info = BTUSB_ATH3012 }, 139 { USB_DEVICE(0x13d3, 0x3375), .driver_info = BTUSB_ATH3012 },
140 { USB_DEVICE(0x04ca, 0x3004), .driver_info = BTUSB_ATH3012 },
137 { USB_DEVICE(0x04ca, 0x3005), .driver_info = BTUSB_ATH3012 }, 141 { USB_DEVICE(0x04ca, 0x3005), .driver_info = BTUSB_ATH3012 },
138 { USB_DEVICE(0x04ca, 0x3006), .driver_info = BTUSB_ATH3012 }, 142 { USB_DEVICE(0x04ca, 0x3006), .driver_info = BTUSB_ATH3012 },
139 { USB_DEVICE(0x04ca, 0x3008), .driver_info = BTUSB_ATH3012 }, 143 { USB_DEVICE(0x04ca, 0x3008), .driver_info = BTUSB_ATH3012 },
diff --git a/drivers/clk/clk-vt8500.c b/drivers/clk/clk-vt8500.c
index b5538bba7a10..09c63315e579 100644
--- a/drivers/clk/clk-vt8500.c
+++ b/drivers/clk/clk-vt8500.c
@@ -157,7 +157,7 @@ static int vt8500_dclk_set_rate(struct clk_hw *hw, unsigned long rate,
157 divisor = parent_rate / rate; 157 divisor = parent_rate / rate;
158 158
159 /* If prate / rate would be decimal, incr the divisor */ 159 /* If prate / rate would be decimal, incr the divisor */
160 if (rate * divisor < *prate) 160 if (rate * divisor < parent_rate)
161 divisor++; 161 divisor++;
162 162
163 if (divisor == cdev->div_mask + 1) 163 if (divisor == cdev->div_mask + 1)
diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
index 937bc286591f..57a8774f0b4e 100644
--- a/drivers/cpufreq/acpi-cpufreq.c
+++ b/drivers/cpufreq/acpi-cpufreq.c
@@ -730,7 +730,6 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
730 policy->shared_type == CPUFREQ_SHARED_TYPE_ANY) { 730 policy->shared_type == CPUFREQ_SHARED_TYPE_ANY) {
731 cpumask_copy(policy->cpus, perf->shared_cpu_map); 731 cpumask_copy(policy->cpus, perf->shared_cpu_map);
732 } 732 }
733 cpumask_copy(policy->related_cpus, perf->shared_cpu_map);
734 733
735#ifdef CONFIG_SMP 734#ifdef CONFIG_SMP
736 dmi_check_system(sw_any_bug_dmi_table); 735 dmi_check_system(sw_any_bug_dmi_table);
@@ -742,7 +741,6 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
742 if (check_amd_hwpstate_cpu(cpu) && !acpi_pstate_strict) { 741 if (check_amd_hwpstate_cpu(cpu) && !acpi_pstate_strict) {
743 cpumask_clear(policy->cpus); 742 cpumask_clear(policy->cpus);
744 cpumask_set_cpu(cpu, policy->cpus); 743 cpumask_set_cpu(cpu, policy->cpus);
745 cpumask_copy(policy->related_cpus, cpu_sibling_mask(cpu));
746 policy->shared_type = CPUFREQ_SHARED_TYPE_HW; 744 policy->shared_type = CPUFREQ_SHARED_TYPE_HW;
747 pr_info_once(PFX "overriding BIOS provided _PSD data\n"); 745 pr_info_once(PFX "overriding BIOS provided _PSD data\n");
748 } 746 }
diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
index 2fd779eb1ed1..bfd6273fd873 100644
--- a/drivers/cpufreq/cpufreq_stats.c
+++ b/drivers/cpufreq/cpufreq_stats.c
@@ -180,15 +180,19 @@ static void cpufreq_stats_free_sysfs(unsigned int cpu)
180{ 180{
181 struct cpufreq_policy *policy = cpufreq_cpu_get(cpu); 181 struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
182 182
183 if (!cpufreq_frequency_get_table(cpu)) 183 if (!policy)
184 return; 184 return;
185 185
186 if (policy && !policy_is_shared(policy)) { 186 if (!cpufreq_frequency_get_table(cpu))
187 goto put_ref;
188
189 if (!policy_is_shared(policy)) {
187 pr_debug("%s: Free sysfs stat\n", __func__); 190 pr_debug("%s: Free sysfs stat\n", __func__);
188 sysfs_remove_group(&policy->kobj, &stats_attr_group); 191 sysfs_remove_group(&policy->kobj, &stats_attr_group);
189 } 192 }
190 if (policy) 193
191 cpufreq_cpu_put(policy); 194put_ref:
195 cpufreq_cpu_put(policy);
192} 196}
193 197
194static int cpufreq_stats_create_table(struct cpufreq_policy *policy, 198static int cpufreq_stats_create_table(struct cpufreq_policy *policy,
diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
index f6dd1e761129..ad72922919ed 100644
--- a/drivers/cpufreq/intel_pstate.c
+++ b/drivers/cpufreq/intel_pstate.c
@@ -358,14 +358,14 @@ static void intel_pstate_sysfs_expose_params(void)
358static int intel_pstate_min_pstate(void) 358static int intel_pstate_min_pstate(void)
359{ 359{
360 u64 value; 360 u64 value;
361 rdmsrl(0xCE, value); 361 rdmsrl(MSR_PLATFORM_INFO, value);
362 return (value >> 40) & 0xFF; 362 return (value >> 40) & 0xFF;
363} 363}
364 364
365static int intel_pstate_max_pstate(void) 365static int intel_pstate_max_pstate(void)
366{ 366{
367 u64 value; 367 u64 value;
368 rdmsrl(0xCE, value); 368 rdmsrl(MSR_PLATFORM_INFO, value);
369 return (value >> 8) & 0xFF; 369 return (value >> 8) & 0xFF;
370} 370}
371 371
@@ -373,7 +373,7 @@ static int intel_pstate_turbo_pstate(void)
373{ 373{
374 u64 value; 374 u64 value;
375 int nont, ret; 375 int nont, ret;
376 rdmsrl(0x1AD, value); 376 rdmsrl(MSR_NHM_TURBO_RATIO_LIMIT, value);
377 nont = intel_pstate_max_pstate(); 377 nont = intel_pstate_max_pstate();
378 ret = ((value) & 255); 378 ret = ((value) & 255);
379 if (ret <= nont) 379 if (ret <= nont)
@@ -454,7 +454,7 @@ static inline void intel_pstate_calc_busy(struct cpudata *cpu,
454 sample->idletime_us * 100, 454 sample->idletime_us * 100,
455 sample->duration_us); 455 sample->duration_us);
456 core_pct = div64_u64(sample->aperf * 100, sample->mperf); 456 core_pct = div64_u64(sample->aperf * 100, sample->mperf);
457 sample->freq = cpu->pstate.turbo_pstate * core_pct * 1000; 457 sample->freq = cpu->pstate.max_pstate * core_pct * 1000;
458 458
459 sample->core_pct_busy = div_s64((sample->pstate_pct_busy * core_pct), 459 sample->core_pct_busy = div_s64((sample->pstate_pct_busy * core_pct),
460 100); 460 100);
@@ -752,6 +752,29 @@ static struct cpufreq_driver intel_pstate_driver = {
752 752
753static int __initdata no_load; 753static int __initdata no_load;
754 754
755static int intel_pstate_msrs_not_valid(void)
756{
757 /* Check that all the msr's we are using are valid. */
758 u64 aperf, mperf, tmp;
759
760 rdmsrl(MSR_IA32_APERF, aperf);
761 rdmsrl(MSR_IA32_MPERF, mperf);
762
763 if (!intel_pstate_min_pstate() ||
764 !intel_pstate_max_pstate() ||
765 !intel_pstate_turbo_pstate())
766 return -ENODEV;
767
768 rdmsrl(MSR_IA32_APERF, tmp);
769 if (!(tmp - aperf))
770 return -ENODEV;
771
772 rdmsrl(MSR_IA32_MPERF, tmp);
773 if (!(tmp - mperf))
774 return -ENODEV;
775
776 return 0;
777}
755static int __init intel_pstate_init(void) 778static int __init intel_pstate_init(void)
756{ 779{
757 int cpu, rc = 0; 780 int cpu, rc = 0;
@@ -764,6 +787,9 @@ static int __init intel_pstate_init(void)
764 if (!id) 787 if (!id)
765 return -ENODEV; 788 return -ENODEV;
766 789
790 if (intel_pstate_msrs_not_valid())
791 return -ENODEV;
792
767 pr_info("Intel P-state driver initializing.\n"); 793 pr_info("Intel P-state driver initializing.\n");
768 794
769 all_cpu_data = vmalloc(sizeof(void *) * num_possible_cpus()); 795 all_cpu_data = vmalloc(sizeof(void *) * num_possible_cpus());
diff --git a/drivers/crypto/caam/caamalg.c b/drivers/crypto/caam/caamalg.c
index b2a0a0726a54..cf268b14ae9a 100644
--- a/drivers/crypto/caam/caamalg.c
+++ b/drivers/crypto/caam/caamalg.c
@@ -1650,11 +1650,7 @@ struct caam_alg_template {
1650}; 1650};
1651 1651
1652static struct caam_alg_template driver_algs[] = { 1652static struct caam_alg_template driver_algs[] = {
1653 /* 1653 /* single-pass ipsec_esp descriptor */
1654 * single-pass ipsec_esp descriptor
1655 * authencesn(*,*) is also registered, although not present
1656 * explicitly here.
1657 */
1658 { 1654 {
1659 .name = "authenc(hmac(md5),cbc(aes))", 1655 .name = "authenc(hmac(md5),cbc(aes))",
1660 .driver_name = "authenc-hmac-md5-cbc-aes-caam", 1656 .driver_name = "authenc-hmac-md5-cbc-aes-caam",
@@ -2217,9 +2213,7 @@ static int __init caam_algapi_init(void)
2217 for (i = 0; i < ARRAY_SIZE(driver_algs); i++) { 2213 for (i = 0; i < ARRAY_SIZE(driver_algs); i++) {
2218 /* TODO: check if h/w supports alg */ 2214 /* TODO: check if h/w supports alg */
2219 struct caam_crypto_alg *t_alg; 2215 struct caam_crypto_alg *t_alg;
2220 bool done = false;
2221 2216
2222authencesn:
2223 t_alg = caam_alg_alloc(ctrldev, &driver_algs[i]); 2217 t_alg = caam_alg_alloc(ctrldev, &driver_algs[i]);
2224 if (IS_ERR(t_alg)) { 2218 if (IS_ERR(t_alg)) {
2225 err = PTR_ERR(t_alg); 2219 err = PTR_ERR(t_alg);
@@ -2233,25 +2227,8 @@ authencesn:
2233 dev_warn(ctrldev, "%s alg registration failed\n", 2227 dev_warn(ctrldev, "%s alg registration failed\n",
2234 t_alg->crypto_alg.cra_driver_name); 2228 t_alg->crypto_alg.cra_driver_name);
2235 kfree(t_alg); 2229 kfree(t_alg);
2236 } else { 2230 } else
2237 list_add_tail(&t_alg->entry, &priv->alg_list); 2231 list_add_tail(&t_alg->entry, &priv->alg_list);
2238 if (driver_algs[i].type == CRYPTO_ALG_TYPE_AEAD &&
2239 !memcmp(driver_algs[i].name, "authenc", 7) &&
2240 !done) {
2241 char *name;
2242
2243 name = driver_algs[i].name;
2244 memmove(name + 10, name + 7, strlen(name) - 7);
2245 memcpy(name + 7, "esn", 3);
2246
2247 name = driver_algs[i].driver_name;
2248 memmove(name + 10, name + 7, strlen(name) - 7);
2249 memcpy(name + 7, "esn", 3);
2250
2251 done = true;
2252 goto authencesn;
2253 }
2254 }
2255 } 2232 }
2256 if (!list_empty(&priv->alg_list)) 2233 if (!list_empty(&priv->alg_list))
2257 dev_info(ctrldev, "%s algorithms registered in /proc/crypto\n", 2234 dev_info(ctrldev, "%s algorithms registered in /proc/crypto\n",
diff --git a/drivers/crypto/caam/compat.h b/drivers/crypto/caam/compat.h
index cf15e7813801..762aeff626ac 100644
--- a/drivers/crypto/caam/compat.h
+++ b/drivers/crypto/caam/compat.h
@@ -23,7 +23,6 @@
23#include <linux/types.h> 23#include <linux/types.h>
24#include <linux/debugfs.h> 24#include <linux/debugfs.h>
25#include <linux/circ_buf.h> 25#include <linux/circ_buf.h>
26#include <linux/string.h>
27#include <net/xfrm.h> 26#include <net/xfrm.h>
28 27
29#include <crypto/algapi.h> 28#include <crypto/algapi.h>
diff --git a/drivers/crypto/talitos.c b/drivers/crypto/talitos.c
index 09b184adf31b..5b2b5e61e4f9 100644
--- a/drivers/crypto/talitos.c
+++ b/drivers/crypto/talitos.c
@@ -38,7 +38,6 @@
38#include <linux/spinlock.h> 38#include <linux/spinlock.h>
39#include <linux/rtnetlink.h> 39#include <linux/rtnetlink.h>
40#include <linux/slab.h> 40#include <linux/slab.h>
41#include <linux/string.h>
42 41
43#include <crypto/algapi.h> 42#include <crypto/algapi.h>
44#include <crypto/aes.h> 43#include <crypto/aes.h>
@@ -1974,11 +1973,7 @@ struct talitos_alg_template {
1974}; 1973};
1975 1974
1976static struct talitos_alg_template driver_algs[] = { 1975static struct talitos_alg_template driver_algs[] = {
1977 /* 1976 /* AEAD algorithms. These use a single-pass ipsec_esp descriptor */
1978 * AEAD algorithms. These use a single-pass ipsec_esp descriptor.
1979 * authencesn(*,*) is also registered, although not present
1980 * explicitly here.
1981 */
1982 { .type = CRYPTO_ALG_TYPE_AEAD, 1977 { .type = CRYPTO_ALG_TYPE_AEAD,
1983 .alg.crypto = { 1978 .alg.crypto = {
1984 .cra_name = "authenc(hmac(sha1),cbc(aes))", 1979 .cra_name = "authenc(hmac(sha1),cbc(aes))",
@@ -2820,9 +2815,7 @@ static int talitos_probe(struct platform_device *ofdev)
2820 if (hw_supports(dev, driver_algs[i].desc_hdr_template)) { 2815 if (hw_supports(dev, driver_algs[i].desc_hdr_template)) {
2821 struct talitos_crypto_alg *t_alg; 2816 struct talitos_crypto_alg *t_alg;
2822 char *name = NULL; 2817 char *name = NULL;
2823 bool authenc = false;
2824 2818
2825authencesn:
2826 t_alg = talitos_alg_alloc(dev, &driver_algs[i]); 2819 t_alg = talitos_alg_alloc(dev, &driver_algs[i]);
2827 if (IS_ERR(t_alg)) { 2820 if (IS_ERR(t_alg)) {
2828 err = PTR_ERR(t_alg); 2821 err = PTR_ERR(t_alg);
@@ -2837,8 +2830,6 @@ authencesn:
2837 err = crypto_register_alg( 2830 err = crypto_register_alg(
2838 &t_alg->algt.alg.crypto); 2831 &t_alg->algt.alg.crypto);
2839 name = t_alg->algt.alg.crypto.cra_driver_name; 2832 name = t_alg->algt.alg.crypto.cra_driver_name;
2840 authenc = authenc ? !authenc :
2841 !(bool)memcmp(name, "authenc", 7);
2842 break; 2833 break;
2843 case CRYPTO_ALG_TYPE_AHASH: 2834 case CRYPTO_ALG_TYPE_AHASH:
2844 err = crypto_register_ahash( 2835 err = crypto_register_ahash(
@@ -2851,25 +2842,8 @@ authencesn:
2851 dev_err(dev, "%s alg registration failed\n", 2842 dev_err(dev, "%s alg registration failed\n",
2852 name); 2843 name);
2853 kfree(t_alg); 2844 kfree(t_alg);
2854 } else { 2845 } else
2855 list_add_tail(&t_alg->entry, &priv->alg_list); 2846 list_add_tail(&t_alg->entry, &priv->alg_list);
2856 if (authenc) {
2857 struct crypto_alg *alg =
2858 &driver_algs[i].alg.crypto;
2859
2860 name = alg->cra_name;
2861 memmove(name + 10, name + 7,
2862 strlen(name) - 7);
2863 memcpy(name + 7, "esn", 3);
2864
2865 name = alg->cra_driver_name;
2866 memmove(name + 10, name + 7,
2867 strlen(name) - 7);
2868 memcpy(name + 7, "esn", 3);
2869
2870 goto authencesn;
2871 }
2872 }
2873 } 2847 }
2874 } 2848 }
2875 if (!list_empty(&priv->alg_list)) 2849 if (!list_empty(&priv->alg_list))
diff --git a/drivers/dma/dw_dmac.c b/drivers/dma/dw_dmac.c
index c599558faeda..43a5329d4483 100644
--- a/drivers/dma/dw_dmac.c
+++ b/drivers/dma/dw_dmac.c
@@ -1001,6 +1001,13 @@ static inline void convert_burst(u32 *maxburst)
1001 *maxburst = 0; 1001 *maxburst = 0;
1002} 1002}
1003 1003
1004static inline void convert_slave_id(struct dw_dma_chan *dwc)
1005{
1006 struct dw_dma *dw = to_dw_dma(dwc->chan.device);
1007
1008 dwc->dma_sconfig.slave_id -= dw->request_line_base;
1009}
1010
1004static int 1011static int
1005set_runtime_config(struct dma_chan *chan, struct dma_slave_config *sconfig) 1012set_runtime_config(struct dma_chan *chan, struct dma_slave_config *sconfig)
1006{ 1013{
@@ -1015,6 +1022,7 @@ set_runtime_config(struct dma_chan *chan, struct dma_slave_config *sconfig)
1015 1022
1016 convert_burst(&dwc->dma_sconfig.src_maxburst); 1023 convert_burst(&dwc->dma_sconfig.src_maxburst);
1017 convert_burst(&dwc->dma_sconfig.dst_maxburst); 1024 convert_burst(&dwc->dma_sconfig.dst_maxburst);
1025 convert_slave_id(dwc);
1018 1026
1019 return 0; 1027 return 0;
1020} 1028}
@@ -1276,9 +1284,9 @@ static struct dma_chan *dw_dma_xlate(struct of_phandle_args *dma_spec,
1276 if (dma_spec->args_count != 3) 1284 if (dma_spec->args_count != 3)
1277 return NULL; 1285 return NULL;
1278 1286
1279 fargs.req = be32_to_cpup(dma_spec->args+0); 1287 fargs.req = dma_spec->args[0];
1280 fargs.src = be32_to_cpup(dma_spec->args+1); 1288 fargs.src = dma_spec->args[1];
1281 fargs.dst = be32_to_cpup(dma_spec->args+2); 1289 fargs.dst = dma_spec->args[2];
1282 1290
1283 if (WARN_ON(fargs.req >= DW_DMA_MAX_NR_REQUESTS || 1291 if (WARN_ON(fargs.req >= DW_DMA_MAX_NR_REQUESTS ||
1284 fargs.src >= dw->nr_masters || 1292 fargs.src >= dw->nr_masters ||
@@ -1628,6 +1636,7 @@ dw_dma_parse_dt(struct platform_device *pdev)
1628 1636
1629static int dw_probe(struct platform_device *pdev) 1637static int dw_probe(struct platform_device *pdev)
1630{ 1638{
1639 const struct platform_device_id *match;
1631 struct dw_dma_platform_data *pdata; 1640 struct dw_dma_platform_data *pdata;
1632 struct resource *io; 1641 struct resource *io;
1633 struct dw_dma *dw; 1642 struct dw_dma *dw;
@@ -1711,6 +1720,11 @@ static int dw_probe(struct platform_device *pdev)
1711 memcpy(dw->data_width, pdata->data_width, 4); 1720 memcpy(dw->data_width, pdata->data_width, 4);
1712 } 1721 }
1713 1722
1723 /* Get the base request line if set */
1724 match = platform_get_device_id(pdev);
1725 if (match)
1726 dw->request_line_base = (unsigned int)match->driver_data;
1727
1714 /* Calculate all channel mask before DMA setup */ 1728 /* Calculate all channel mask before DMA setup */
1715 dw->all_chan_mask = (1 << nr_channels) - 1; 1729 dw->all_chan_mask = (1 << nr_channels) - 1;
1716 1730
@@ -1906,7 +1920,8 @@ MODULE_DEVICE_TABLE(of, dw_dma_id_table);
1906#endif 1920#endif
1907 1921
1908static const struct platform_device_id dw_dma_ids[] = { 1922static const struct platform_device_id dw_dma_ids[] = {
1909 { "INTL9C60", 0 }, 1923 /* Name, Request Line Base */
1924 { "INTL9C60", (kernel_ulong_t)16 },
1910 { } 1925 { }
1911}; 1926};
1912 1927
diff --git a/drivers/dma/dw_dmac_regs.h b/drivers/dma/dw_dmac_regs.h
index cf0ce5c77d60..4d02c3669b75 100644
--- a/drivers/dma/dw_dmac_regs.h
+++ b/drivers/dma/dw_dmac_regs.h
@@ -247,6 +247,7 @@ struct dw_dma {
247 /* hardware configuration */ 247 /* hardware configuration */
248 unsigned char nr_masters; 248 unsigned char nr_masters;
249 unsigned char data_width[4]; 249 unsigned char data_width[4];
250 unsigned int request_line_base;
250 251
251 struct dw_dma_chan chan[0]; 252 struct dw_dma_chan chan[0];
252}; 253};
diff --git a/drivers/edac/amd64_edac.c b/drivers/edac/amd64_edac.c
index 910b0116c128..e1d13c463c90 100644
--- a/drivers/edac/amd64_edac.c
+++ b/drivers/edac/amd64_edac.c
@@ -2048,12 +2048,18 @@ static int init_csrows(struct mem_ctl_info *mci)
2048 edac_dbg(1, "MC node: %d, csrow: %d\n", 2048 edac_dbg(1, "MC node: %d, csrow: %d\n",
2049 pvt->mc_node_id, i); 2049 pvt->mc_node_id, i);
2050 2050
2051 if (row_dct0) 2051 if (row_dct0) {
2052 nr_pages = amd64_csrow_nr_pages(pvt, 0, i); 2052 nr_pages = amd64_csrow_nr_pages(pvt, 0, i);
2053 csrow->channels[0]->dimm->nr_pages = nr_pages;
2054 }
2053 2055
2054 /* K8 has only one DCT */ 2056 /* K8 has only one DCT */
2055 if (boot_cpu_data.x86 != 0xf && row_dct1) 2057 if (boot_cpu_data.x86 != 0xf && row_dct1) {
2056 nr_pages += amd64_csrow_nr_pages(pvt, 1, i); 2058 int row_dct1_pages = amd64_csrow_nr_pages(pvt, 1, i);
2059
2060 csrow->channels[1]->dimm->nr_pages = row_dct1_pages;
2061 nr_pages += row_dct1_pages;
2062 }
2057 2063
2058 mtype = amd64_determine_memory_type(pvt, i); 2064 mtype = amd64_determine_memory_type(pvt, i);
2059 2065
@@ -2072,9 +2078,7 @@ static int init_csrows(struct mem_ctl_info *mci)
2072 dimm = csrow->channels[j]->dimm; 2078 dimm = csrow->channels[j]->dimm;
2073 dimm->mtype = mtype; 2079 dimm->mtype = mtype;
2074 dimm->edac_mode = edac_mode; 2080 dimm->edac_mode = edac_mode;
2075 dimm->nr_pages = nr_pages;
2076 } 2081 }
2077 csrow->nr_pages = nr_pages;
2078 } 2082 }
2079 2083
2080 return empty; 2084 return empty;
@@ -2419,7 +2423,6 @@ static int amd64_init_one_instance(struct pci_dev *F2)
2419 2423
2420 mci->pvt_info = pvt; 2424 mci->pvt_info = pvt;
2421 mci->pdev = &pvt->F2->dev; 2425 mci->pdev = &pvt->F2->dev;
2422 mci->csbased = 1;
2423 2426
2424 setup_mci_misc_attrs(mci, fam_type); 2427 setup_mci_misc_attrs(mci, fam_type);
2425 2428
diff --git a/drivers/edac/edac_mc.c b/drivers/edac/edac_mc.c
index cdb81aa73ab7..27e86d938262 100644
--- a/drivers/edac/edac_mc.c
+++ b/drivers/edac/edac_mc.c
@@ -86,7 +86,7 @@ static void edac_mc_dump_dimm(struct dimm_info *dimm, int number)
86 edac_dimm_info_location(dimm, location, sizeof(location)); 86 edac_dimm_info_location(dimm, location, sizeof(location));
87 87
88 edac_dbg(4, "%s%i: %smapped as virtual row %d, chan %d\n", 88 edac_dbg(4, "%s%i: %smapped as virtual row %d, chan %d\n",
89 dimm->mci->mem_is_per_rank ? "rank" : "dimm", 89 dimm->mci->csbased ? "rank" : "dimm",
90 number, location, dimm->csrow, dimm->cschannel); 90 number, location, dimm->csrow, dimm->cschannel);
91 edac_dbg(4, " dimm = %p\n", dimm); 91 edac_dbg(4, " dimm = %p\n", dimm);
92 edac_dbg(4, " dimm->label = '%s'\n", dimm->label); 92 edac_dbg(4, " dimm->label = '%s'\n", dimm->label);
@@ -341,7 +341,7 @@ struct mem_ctl_info *edac_mc_alloc(unsigned mc_num,
341 memcpy(mci->layers, layers, sizeof(*layer) * n_layers); 341 memcpy(mci->layers, layers, sizeof(*layer) * n_layers);
342 mci->nr_csrows = tot_csrows; 342 mci->nr_csrows = tot_csrows;
343 mci->num_cschannel = tot_channels; 343 mci->num_cschannel = tot_channels;
344 mci->mem_is_per_rank = per_rank; 344 mci->csbased = per_rank;
345 345
346 /* 346 /*
347 * Alocate and fill the csrow/channels structs 347 * Alocate and fill the csrow/channels structs
@@ -1235,7 +1235,7 @@ void edac_mc_handle_error(const enum hw_event_mc_err_type type,
1235 * incrementing the compat API counters 1235 * incrementing the compat API counters
1236 */ 1236 */
1237 edac_dbg(4, "%s csrows map: (%d,%d)\n", 1237 edac_dbg(4, "%s csrows map: (%d,%d)\n",
1238 mci->mem_is_per_rank ? "rank" : "dimm", 1238 mci->csbased ? "rank" : "dimm",
1239 dimm->csrow, dimm->cschannel); 1239 dimm->csrow, dimm->cschannel);
1240 if (row == -1) 1240 if (row == -1)
1241 row = dimm->csrow; 1241 row = dimm->csrow;
diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
index 4f4b6137d74e..5899a76eec3b 100644
--- a/drivers/edac/edac_mc_sysfs.c
+++ b/drivers/edac/edac_mc_sysfs.c
@@ -143,7 +143,7 @@ static const char *edac_caps[] = {
143 * and the per-dimm/per-rank one 143 * and the per-dimm/per-rank one
144 */ 144 */
145#define DEVICE_ATTR_LEGACY(_name, _mode, _show, _store) \ 145#define DEVICE_ATTR_LEGACY(_name, _mode, _show, _store) \
146 struct device_attribute dev_attr_legacy_##_name = __ATTR(_name, _mode, _show, _store) 146 static struct device_attribute dev_attr_legacy_##_name = __ATTR(_name, _mode, _show, _store)
147 147
148struct dev_ch_attribute { 148struct dev_ch_attribute {
149 struct device_attribute attr; 149 struct device_attribute attr;
@@ -180,9 +180,6 @@ static ssize_t csrow_size_show(struct device *dev,
180 int i; 180 int i;
181 u32 nr_pages = 0; 181 u32 nr_pages = 0;
182 182
183 if (csrow->mci->csbased)
184 return sprintf(data, "%u\n", PAGES_TO_MiB(csrow->nr_pages));
185
186 for (i = 0; i < csrow->nr_channels; i++) 183 for (i = 0; i < csrow->nr_channels; i++)
187 nr_pages += csrow->channels[i]->dimm->nr_pages; 184 nr_pages += csrow->channels[i]->dimm->nr_pages;
188 return sprintf(data, "%u\n", PAGES_TO_MiB(nr_pages)); 185 return sprintf(data, "%u\n", PAGES_TO_MiB(nr_pages));
@@ -612,7 +609,7 @@ static int edac_create_dimm_object(struct mem_ctl_info *mci,
612 device_initialize(&dimm->dev); 609 device_initialize(&dimm->dev);
613 610
614 dimm->dev.parent = &mci->dev; 611 dimm->dev.parent = &mci->dev;
615 if (mci->mem_is_per_rank) 612 if (mci->csbased)
616 dev_set_name(&dimm->dev, "rank%d", index); 613 dev_set_name(&dimm->dev, "rank%d", index);
617 else 614 else
618 dev_set_name(&dimm->dev, "dimm%d", index); 615 dev_set_name(&dimm->dev, "dimm%d", index);
@@ -778,14 +775,10 @@ static ssize_t mci_size_mb_show(struct device *dev,
778 for (csrow_idx = 0; csrow_idx < mci->nr_csrows; csrow_idx++) { 775 for (csrow_idx = 0; csrow_idx < mci->nr_csrows; csrow_idx++) {
779 struct csrow_info *csrow = mci->csrows[csrow_idx]; 776 struct csrow_info *csrow = mci->csrows[csrow_idx];
780 777
781 if (csrow->mci->csbased) { 778 for (j = 0; j < csrow->nr_channels; j++) {
782 total_pages += csrow->nr_pages; 779 struct dimm_info *dimm = csrow->channels[j]->dimm;
783 } else {
784 for (j = 0; j < csrow->nr_channels; j++) {
785 struct dimm_info *dimm = csrow->channels[j]->dimm;
786 780
787 total_pages += dimm->nr_pages; 781 total_pages += dimm->nr_pages;
788 }
789 } 782 }
790 } 783 }
791 784
diff --git a/drivers/extcon/extcon-max77693.c b/drivers/extcon/extcon-max77693.c
index b70e3815c459..8f3c947b0029 100644
--- a/drivers/extcon/extcon-max77693.c
+++ b/drivers/extcon/extcon-max77693.c
@@ -32,6 +32,38 @@
32#define DEV_NAME "max77693-muic" 32#define DEV_NAME "max77693-muic"
33#define DELAY_MS_DEFAULT 20000 /* unit: millisecond */ 33#define DELAY_MS_DEFAULT 20000 /* unit: millisecond */
34 34
35/*
36 * Default value of MAX77693 register to bring up MUIC device.
37 * If user don't set some initial value for MUIC device through platform data,
38 * extcon-max77693 driver use 'default_init_data' to bring up base operation
39 * of MAX77693 MUIC device.
40 */
41struct max77693_reg_data default_init_data[] = {
42 {
43 /* STATUS2 - [3]ChgDetRun */
44 .addr = MAX77693_MUIC_REG_STATUS2,
45 .data = STATUS2_CHGDETRUN_MASK,
46 }, {
47 /* INTMASK1 - Unmask [3]ADC1KM,[0]ADCM */
48 .addr = MAX77693_MUIC_REG_INTMASK1,
49 .data = INTMASK1_ADC1K_MASK
50 | INTMASK1_ADC_MASK,
51 }, {
52 /* INTMASK2 - Unmask [0]ChgTypM */
53 .addr = MAX77693_MUIC_REG_INTMASK2,
54 .data = INTMASK2_CHGTYP_MASK,
55 }, {
56 /* INTMASK3 - Mask all of interrupts */
57 .addr = MAX77693_MUIC_REG_INTMASK3,
58 .data = 0x0,
59 }, {
60 /* CDETCTRL2 */
61 .addr = MAX77693_MUIC_REG_CDETCTRL2,
62 .data = CDETCTRL2_VIDRMEN_MASK
63 | CDETCTRL2_DXOVPEN_MASK,
64 },
65};
66
35enum max77693_muic_adc_debounce_time { 67enum max77693_muic_adc_debounce_time {
36 ADC_DEBOUNCE_TIME_5MS = 0, 68 ADC_DEBOUNCE_TIME_5MS = 0,
37 ADC_DEBOUNCE_TIME_10MS, 69 ADC_DEBOUNCE_TIME_10MS,
@@ -1045,8 +1077,9 @@ static int max77693_muic_probe(struct platform_device *pdev)
1045{ 1077{
1046 struct max77693_dev *max77693 = dev_get_drvdata(pdev->dev.parent); 1078 struct max77693_dev *max77693 = dev_get_drvdata(pdev->dev.parent);
1047 struct max77693_platform_data *pdata = dev_get_platdata(max77693->dev); 1079 struct max77693_platform_data *pdata = dev_get_platdata(max77693->dev);
1048 struct max77693_muic_platform_data *muic_pdata = pdata->muic_data;
1049 struct max77693_muic_info *info; 1080 struct max77693_muic_info *info;
1081 struct max77693_reg_data *init_data;
1082 int num_init_data;
1050 int delay_jiffies; 1083 int delay_jiffies;
1051 int ret; 1084 int ret;
1052 int i; 1085 int i;
@@ -1145,15 +1178,25 @@ static int max77693_muic_probe(struct platform_device *pdev)
1145 goto err_irq; 1178 goto err_irq;
1146 } 1179 }
1147 1180
1148 /* Initialize MUIC register by using platform data */ 1181
1149 for (i = 0 ; i < muic_pdata->num_init_data ; i++) { 1182 /* Initialize MUIC register by using platform data or default data */
1150 enum max77693_irq_source irq_src = MAX77693_IRQ_GROUP_NR; 1183 if (pdata->muic_data) {
1184 init_data = pdata->muic_data->init_data;
1185 num_init_data = pdata->muic_data->num_init_data;
1186 } else {
1187 init_data = default_init_data;
1188 num_init_data = ARRAY_SIZE(default_init_data);
1189 }
1190
1191 for (i = 0 ; i < num_init_data ; i++) {
1192 enum max77693_irq_source irq_src
1193 = MAX77693_IRQ_GROUP_NR;
1151 1194
1152 max77693_write_reg(info->max77693->regmap_muic, 1195 max77693_write_reg(info->max77693->regmap_muic,
1153 muic_pdata->init_data[i].addr, 1196 init_data[i].addr,
1154 muic_pdata->init_data[i].data); 1197 init_data[i].data);
1155 1198
1156 switch (muic_pdata->init_data[i].addr) { 1199 switch (init_data[i].addr) {
1157 case MAX77693_MUIC_REG_INTMASK1: 1200 case MAX77693_MUIC_REG_INTMASK1:
1158 irq_src = MUIC_INT1; 1201 irq_src = MUIC_INT1;
1159 break; 1202 break;
@@ -1167,22 +1210,40 @@ static int max77693_muic_probe(struct platform_device *pdev)
1167 1210
1168 if (irq_src < MAX77693_IRQ_GROUP_NR) 1211 if (irq_src < MAX77693_IRQ_GROUP_NR)
1169 info->max77693->irq_masks_cur[irq_src] 1212 info->max77693->irq_masks_cur[irq_src]
1170 = muic_pdata->init_data[i].data; 1213 = init_data[i].data;
1171 } 1214 }
1172 1215
1173 /* 1216 if (pdata->muic_data) {
1174 * Default usb/uart path whether UART/USB or AUX_UART/AUX_USB 1217 struct max77693_muic_platform_data *muic_pdata = pdata->muic_data;
1175 * h/w path of COMP2/COMN1 on CONTROL1 register.
1176 */
1177 if (muic_pdata->path_uart)
1178 info->path_uart = muic_pdata->path_uart;
1179 else
1180 info->path_uart = CONTROL1_SW_UART;
1181 1218
1182 if (muic_pdata->path_usb) 1219 /*
1183 info->path_usb = muic_pdata->path_usb; 1220 * Default usb/uart path whether UART/USB or AUX_UART/AUX_USB
1184 else 1221 * h/w path of COMP2/COMN1 on CONTROL1 register.
1222 */
1223 if (muic_pdata->path_uart)
1224 info->path_uart = muic_pdata->path_uart;
1225 else
1226 info->path_uart = CONTROL1_SW_UART;
1227
1228 if (muic_pdata->path_usb)
1229 info->path_usb = muic_pdata->path_usb;
1230 else
1231 info->path_usb = CONTROL1_SW_USB;
1232
1233 /*
1234 * Default delay time for detecting cable state
1235 * after certain time.
1236 */
1237 if (muic_pdata->detcable_delay_ms)
1238 delay_jiffies =
1239 msecs_to_jiffies(muic_pdata->detcable_delay_ms);
1240 else
1241 delay_jiffies = msecs_to_jiffies(DELAY_MS_DEFAULT);
1242 } else {
1185 info->path_usb = CONTROL1_SW_USB; 1243 info->path_usb = CONTROL1_SW_USB;
1244 info->path_uart = CONTROL1_SW_UART;
1245 delay_jiffies = msecs_to_jiffies(DELAY_MS_DEFAULT);
1246 }
1186 1247
1187 /* Set initial path for UART */ 1248 /* Set initial path for UART */
1188 max77693_muic_set_path(info, info->path_uart, true); 1249 max77693_muic_set_path(info, info->path_uart, true);
@@ -1208,10 +1269,6 @@ static int max77693_muic_probe(struct platform_device *pdev)
1208 * driver should notify cable state to upper layer. 1269 * driver should notify cable state to upper layer.
1209 */ 1270 */
1210 INIT_DELAYED_WORK(&info->wq_detcable, max77693_muic_detect_cable_wq); 1271 INIT_DELAYED_WORK(&info->wq_detcable, max77693_muic_detect_cable_wq);
1211 if (muic_pdata->detcable_delay_ms)
1212 delay_jiffies = msecs_to_jiffies(muic_pdata->detcable_delay_ms);
1213 else
1214 delay_jiffies = msecs_to_jiffies(DELAY_MS_DEFAULT);
1215 schedule_delayed_work(&info->wq_detcable, delay_jiffies); 1272 schedule_delayed_work(&info->wq_detcable, delay_jiffies);
1216 1273
1217 return ret; 1274 return ret;
diff --git a/drivers/extcon/extcon-max8997.c b/drivers/extcon/extcon-max8997.c
index e636d950ad6c..69641bcae325 100644
--- a/drivers/extcon/extcon-max8997.c
+++ b/drivers/extcon/extcon-max8997.c
@@ -712,29 +712,45 @@ static int max8997_muic_probe(struct platform_device *pdev)
712 goto err_irq; 712 goto err_irq;
713 } 713 }
714 714
715 /* Initialize registers according to platform data */
716 if (pdata->muic_pdata) { 715 if (pdata->muic_pdata) {
717 struct max8997_muic_platform_data *mdata = info->muic_pdata; 716 struct max8997_muic_platform_data *muic_pdata
718 717 = pdata->muic_pdata;
719 for (i = 0; i < mdata->num_init_data; i++) { 718
720 max8997_write_reg(info->muic, mdata->init_data[i].addr, 719 /* Initialize registers according to platform data */
721 mdata->init_data[i].data); 720 for (i = 0; i < muic_pdata->num_init_data; i++) {
721 max8997_write_reg(info->muic,
722 muic_pdata->init_data[i].addr,
723 muic_pdata->init_data[i].data);
722 } 724 }
723 }
724 725
725 /* 726 /*
726 * Default usb/uart path whether UART/USB or AUX_UART/AUX_USB 727 * Default usb/uart path whether UART/USB or AUX_UART/AUX_USB
727 * h/w path of COMP2/COMN1 on CONTROL1 register. 728 * h/w path of COMP2/COMN1 on CONTROL1 register.
728 */ 729 */
729 if (pdata->muic_pdata->path_uart) 730 if (muic_pdata->path_uart)
730 info->path_uart = pdata->muic_pdata->path_uart; 731 info->path_uart = muic_pdata->path_uart;
731 else 732 else
732 info->path_uart = CONTROL1_SW_UART; 733 info->path_uart = CONTROL1_SW_UART;
733 734
734 if (pdata->muic_pdata->path_usb) 735 if (muic_pdata->path_usb)
735 info->path_usb = pdata->muic_pdata->path_usb; 736 info->path_usb = muic_pdata->path_usb;
736 else 737 else
738 info->path_usb = CONTROL1_SW_USB;
739
740 /*
741 * Default delay time for detecting cable state
742 * after certain time.
743 */
744 if (muic_pdata->detcable_delay_ms)
745 delay_jiffies =
746 msecs_to_jiffies(muic_pdata->detcable_delay_ms);
747 else
748 delay_jiffies = msecs_to_jiffies(DELAY_MS_DEFAULT);
749 } else {
750 info->path_uart = CONTROL1_SW_UART;
737 info->path_usb = CONTROL1_SW_USB; 751 info->path_usb = CONTROL1_SW_USB;
752 delay_jiffies = msecs_to_jiffies(DELAY_MS_DEFAULT);
753 }
738 754
739 /* Set initial path for UART */ 755 /* Set initial path for UART */
740 max8997_muic_set_path(info, info->path_uart, true); 756 max8997_muic_set_path(info, info->path_uart, true);
@@ -751,10 +767,6 @@ static int max8997_muic_probe(struct platform_device *pdev)
751 * driver should notify cable state to upper layer. 767 * driver should notify cable state to upper layer.
752 */ 768 */
753 INIT_DELAYED_WORK(&info->wq_detcable, max8997_muic_detect_cable_wq); 769 INIT_DELAYED_WORK(&info->wq_detcable, max8997_muic_detect_cable_wq);
754 if (pdata->muic_pdata->detcable_delay_ms)
755 delay_jiffies = msecs_to_jiffies(pdata->muic_pdata->detcable_delay_ms);
756 else
757 delay_jiffies = msecs_to_jiffies(DELAY_MS_DEFAULT);
758 schedule_delayed_work(&info->wq_detcable, delay_jiffies); 770 schedule_delayed_work(&info->wq_detcable, delay_jiffies);
759 771
760 return 0; 772 return 0;
diff --git a/drivers/firmware/Kconfig b/drivers/firmware/Kconfig
index 9b00072a020f..42c759a4d047 100644
--- a/drivers/firmware/Kconfig
+++ b/drivers/firmware/Kconfig
@@ -53,6 +53,24 @@ config EFI_VARS
53 Subsequent efibootmgr releases may be found at: 53 Subsequent efibootmgr releases may be found at:
54 <http://linux.dell.com/efibootmgr> 54 <http://linux.dell.com/efibootmgr>
55 55
56config EFI_VARS_PSTORE
57 bool "Register efivars backend for pstore"
58 depends on EFI_VARS && PSTORE
59 default y
60 help
61 Say Y here to enable use efivars as a backend to pstore. This
62 will allow writing console messages, crash dumps, or anything
63 else supported by pstore to EFI variables.
64
65config EFI_VARS_PSTORE_DEFAULT_DISABLE
66 bool "Disable using efivars as a pstore backend by default"
67 depends on EFI_VARS_PSTORE
68 default n
69 help
70 Saying Y here will disable the use of efivars as a storage
71 backend for pstore by default. This setting can be overridden
72 using the efivars module's pstore_disable parameter.
73
56config EFI_PCDP 74config EFI_PCDP
57 bool "Console device selection via EFI PCDP or HCDP table" 75 bool "Console device selection via EFI PCDP or HCDP table"
58 depends on ACPI && EFI && IA64 76 depends on ACPI && EFI && IA64
diff --git a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c
index fe62aa392239..7acafb80fd4c 100644
--- a/drivers/firmware/efivars.c
+++ b/drivers/firmware/efivars.c
@@ -103,6 +103,11 @@ MODULE_VERSION(EFIVARS_VERSION);
103 */ 103 */
104#define GUID_LEN 36 104#define GUID_LEN 36
105 105
106static bool efivars_pstore_disable =
107 IS_ENABLED(CONFIG_EFI_VARS_PSTORE_DEFAULT_DISABLE);
108
109module_param_named(pstore_disable, efivars_pstore_disable, bool, 0644);
110
106/* 111/*
107 * The maximum size of VariableName + Data = 1024 112 * The maximum size of VariableName + Data = 1024
108 * Therefore, it's reasonable to save that much 113 * Therefore, it's reasonable to save that much
@@ -165,6 +170,7 @@ efivar_create_sysfs_entry(struct efivars *efivars,
165 170
166static void efivar_update_sysfs_entries(struct work_struct *); 171static void efivar_update_sysfs_entries(struct work_struct *);
167static DECLARE_WORK(efivar_work, efivar_update_sysfs_entries); 172static DECLARE_WORK(efivar_work, efivar_update_sysfs_entries);
173static bool efivar_wq_enabled = true;
168 174
169/* Return the number of unicode characters in data */ 175/* Return the number of unicode characters in data */
170static unsigned long 176static unsigned long
@@ -1309,9 +1315,7 @@ static const struct inode_operations efivarfs_dir_inode_operations = {
1309 .create = efivarfs_create, 1315 .create = efivarfs_create,
1310}; 1316};
1311 1317
1312static struct pstore_info efi_pstore_info; 1318#ifdef CONFIG_EFI_VARS_PSTORE
1313
1314#ifdef CONFIG_PSTORE
1315 1319
1316static int efi_pstore_open(struct pstore_info *psi) 1320static int efi_pstore_open(struct pstore_info *psi)
1317{ 1321{
@@ -1441,7 +1445,7 @@ static int efi_pstore_write(enum pstore_type_id type,
1441 1445
1442 spin_unlock_irqrestore(&efivars->lock, flags); 1446 spin_unlock_irqrestore(&efivars->lock, flags);
1443 1447
1444 if (reason == KMSG_DUMP_OOPS) 1448 if (reason == KMSG_DUMP_OOPS && efivar_wq_enabled)
1445 schedule_work(&efivar_work); 1449 schedule_work(&efivar_work);
1446 1450
1447 *id = part; 1451 *id = part;
@@ -1514,38 +1518,6 @@ static int efi_pstore_erase(enum pstore_type_id type, u64 id, int count,
1514 1518
1515 return 0; 1519 return 0;
1516} 1520}
1517#else
1518static int efi_pstore_open(struct pstore_info *psi)
1519{
1520 return 0;
1521}
1522
1523static int efi_pstore_close(struct pstore_info *psi)
1524{
1525 return 0;
1526}
1527
1528static ssize_t efi_pstore_read(u64 *id, enum pstore_type_id *type, int *count,
1529 struct timespec *timespec,
1530 char **buf, struct pstore_info *psi)
1531{
1532 return -1;
1533}
1534
1535static int efi_pstore_write(enum pstore_type_id type,
1536 enum kmsg_dump_reason reason, u64 *id,
1537 unsigned int part, int count, size_t size,
1538 struct pstore_info *psi)
1539{
1540 return 0;
1541}
1542
1543static int efi_pstore_erase(enum pstore_type_id type, u64 id, int count,
1544 struct timespec time, struct pstore_info *psi)
1545{
1546 return 0;
1547}
1548#endif
1549 1521
1550static struct pstore_info efi_pstore_info = { 1522static struct pstore_info efi_pstore_info = {
1551 .owner = THIS_MODULE, 1523 .owner = THIS_MODULE,
@@ -1557,6 +1529,24 @@ static struct pstore_info efi_pstore_info = {
1557 .erase = efi_pstore_erase, 1529 .erase = efi_pstore_erase,
1558}; 1530};
1559 1531
1532static void efivar_pstore_register(struct efivars *efivars)
1533{
1534 efivars->efi_pstore_info = efi_pstore_info;
1535 efivars->efi_pstore_info.buf = kmalloc(4096, GFP_KERNEL);
1536 if (efivars->efi_pstore_info.buf) {
1537 efivars->efi_pstore_info.bufsize = 1024;
1538 efivars->efi_pstore_info.data = efivars;
1539 spin_lock_init(&efivars->efi_pstore_info.buf_lock);
1540 pstore_register(&efivars->efi_pstore_info);
1541 }
1542}
1543#else
1544static void efivar_pstore_register(struct efivars *efivars)
1545{
1546 return;
1547}
1548#endif
1549
1560static ssize_t efivar_create(struct file *filp, struct kobject *kobj, 1550static ssize_t efivar_create(struct file *filp, struct kobject *kobj,
1561 struct bin_attribute *bin_attr, 1551 struct bin_attribute *bin_attr,
1562 char *buf, loff_t pos, size_t count) 1552 char *buf, loff_t pos, size_t count)
@@ -1716,6 +1706,31 @@ static bool variable_is_present(efi_char16_t *variable_name, efi_guid_t *vendor)
1716 return found; 1706 return found;
1717} 1707}
1718 1708
1709/*
1710 * Returns the size of variable_name, in bytes, including the
1711 * terminating NULL character, or variable_name_size if no NULL
1712 * character is found among the first variable_name_size bytes.
1713 */
1714static unsigned long var_name_strnsize(efi_char16_t *variable_name,
1715 unsigned long variable_name_size)
1716{
1717 unsigned long len;
1718 efi_char16_t c;
1719
1720 /*
1721 * The variable name is, by definition, a NULL-terminated
1722 * string, so make absolutely sure that variable_name_size is
1723 * the value we expect it to be. If not, return the real size.
1724 */
1725 for (len = 2; len <= variable_name_size; len += sizeof(c)) {
1726 c = variable_name[(len / sizeof(c)) - 1];
1727 if (!c)
1728 break;
1729 }
1730
1731 return min(len, variable_name_size);
1732}
1733
1719static void efivar_update_sysfs_entries(struct work_struct *work) 1734static void efivar_update_sysfs_entries(struct work_struct *work)
1720{ 1735{
1721 struct efivars *efivars = &__efivars; 1736 struct efivars *efivars = &__efivars;
@@ -1756,10 +1771,13 @@ static void efivar_update_sysfs_entries(struct work_struct *work)
1756 if (!found) { 1771 if (!found) {
1757 kfree(variable_name); 1772 kfree(variable_name);
1758 break; 1773 break;
1759 } else 1774 } else {
1775 variable_name_size = var_name_strnsize(variable_name,
1776 variable_name_size);
1760 efivar_create_sysfs_entry(efivars, 1777 efivar_create_sysfs_entry(efivars,
1761 variable_name_size, 1778 variable_name_size,
1762 variable_name, &vendor); 1779 variable_name, &vendor);
1780 }
1763 } 1781 }
1764} 1782}
1765 1783
@@ -1958,6 +1976,35 @@ void unregister_efivars(struct efivars *efivars)
1958} 1976}
1959EXPORT_SYMBOL_GPL(unregister_efivars); 1977EXPORT_SYMBOL_GPL(unregister_efivars);
1960 1978
1979/*
1980 * Print a warning when duplicate EFI variables are encountered and
1981 * disable the sysfs workqueue since the firmware is buggy.
1982 */
1983static void dup_variable_bug(efi_char16_t *s16, efi_guid_t *vendor_guid,
1984 unsigned long len16)
1985{
1986 size_t i, len8 = len16 / sizeof(efi_char16_t);
1987 char *s8;
1988
1989 /*
1990 * Disable the workqueue since the algorithm it uses for
1991 * detecting new variables won't work with this buggy
1992 * implementation of GetNextVariableName().
1993 */
1994 efivar_wq_enabled = false;
1995
1996 s8 = kzalloc(len8, GFP_KERNEL);
1997 if (!s8)
1998 return;
1999
2000 for (i = 0; i < len8; i++)
2001 s8[i] = s16[i];
2002
2003 printk(KERN_WARNING "efivars: duplicate variable: %s-%pUl\n",
2004 s8, vendor_guid);
2005 kfree(s8);
2006}
2007
1961int register_efivars(struct efivars *efivars, 2008int register_efivars(struct efivars *efivars,
1962 const struct efivar_operations *ops, 2009 const struct efivar_operations *ops,
1963 struct kobject *parent_kobj) 2010 struct kobject *parent_kobj)
@@ -2006,6 +2053,24 @@ int register_efivars(struct efivars *efivars,
2006 &vendor_guid); 2053 &vendor_guid);
2007 switch (status) { 2054 switch (status) {
2008 case EFI_SUCCESS: 2055 case EFI_SUCCESS:
2056 variable_name_size = var_name_strnsize(variable_name,
2057 variable_name_size);
2058
2059 /*
2060 * Some firmware implementations return the
2061 * same variable name on multiple calls to
2062 * get_next_variable(). Terminate the loop
2063 * immediately as there is no guarantee that
2064 * we'll ever see a different variable name,
2065 * and may end up looping here forever.
2066 */
2067 if (variable_is_present(variable_name, &vendor_guid)) {
2068 dup_variable_bug(variable_name, &vendor_guid,
2069 variable_name_size);
2070 status = EFI_NOT_FOUND;
2071 break;
2072 }
2073
2009 efivar_create_sysfs_entry(efivars, 2074 efivar_create_sysfs_entry(efivars,
2010 variable_name_size, 2075 variable_name_size,
2011 variable_name, 2076 variable_name,
@@ -2025,15 +2090,8 @@ int register_efivars(struct efivars *efivars,
2025 if (error) 2090 if (error)
2026 unregister_efivars(efivars); 2091 unregister_efivars(efivars);
2027 2092
2028 efivars->efi_pstore_info = efi_pstore_info; 2093 if (!efivars_pstore_disable)
2029 2094 efivar_pstore_register(efivars);
2030 efivars->efi_pstore_info.buf = kmalloc(4096, GFP_KERNEL);
2031 if (efivars->efi_pstore_info.buf) {
2032 efivars->efi_pstore_info.bufsize = 1024;
2033 efivars->efi_pstore_info.data = efivars;
2034 spin_lock_init(&efivars->efi_pstore_info.buf_lock);
2035 pstore_register(&efivars->efi_pstore_info);
2036 }
2037 2095
2038 register_filesystem(&efivarfs_type); 2096 register_filesystem(&efivarfs_type);
2039 2097
diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
index a71a54a3e3f7..5150df6cba08 100644
--- a/drivers/gpio/gpiolib-of.c
+++ b/drivers/gpio/gpiolib-of.c
@@ -193,7 +193,7 @@ static void of_gpiochip_add_pin_range(struct gpio_chip *chip)
193 if (!np) 193 if (!np)
194 return; 194 return;
195 195
196 do { 196 for (;; index++) {
197 ret = of_parse_phandle_with_args(np, "gpio-ranges", 197 ret = of_parse_phandle_with_args(np, "gpio-ranges",
198 "#gpio-range-cells", index, &pinspec); 198 "#gpio-range-cells", index, &pinspec);
199 if (ret) 199 if (ret)
@@ -222,8 +222,7 @@ static void of_gpiochip_add_pin_range(struct gpio_chip *chip)
222 222
223 if (ret) 223 if (ret)
224 break; 224 break;
225 225 }
226 } while (index++);
227} 226}
228 227
229#else 228#else
diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
index c194f4e680ad..e2acfdbf7d3c 100644
--- a/drivers/gpu/drm/drm_edid.c
+++ b/drivers/gpu/drm/drm_edid.c
@@ -1634,7 +1634,7 @@ static struct drm_display_mode *drm_mode_detailed(struct drm_device *dev,
1634 unsigned vblank = (pt->vactive_vblank_hi & 0xf) << 8 | pt->vblank_lo; 1634 unsigned vblank = (pt->vactive_vblank_hi & 0xf) << 8 | pt->vblank_lo;
1635 unsigned hsync_offset = (pt->hsync_vsync_offset_pulse_width_hi & 0xc0) << 2 | pt->hsync_offset_lo; 1635 unsigned hsync_offset = (pt->hsync_vsync_offset_pulse_width_hi & 0xc0) << 2 | pt->hsync_offset_lo;
1636 unsigned hsync_pulse_width = (pt->hsync_vsync_offset_pulse_width_hi & 0x30) << 4 | pt->hsync_pulse_width_lo; 1636 unsigned hsync_pulse_width = (pt->hsync_vsync_offset_pulse_width_hi & 0x30) << 4 | pt->hsync_pulse_width_lo;
1637 unsigned vsync_offset = (pt->hsync_vsync_offset_pulse_width_hi & 0xc) >> 2 | pt->vsync_offset_pulse_width_lo >> 4; 1637 unsigned vsync_offset = (pt->hsync_vsync_offset_pulse_width_hi & 0xc) << 2 | pt->vsync_offset_pulse_width_lo >> 4;
1638 unsigned vsync_pulse_width = (pt->hsync_vsync_offset_pulse_width_hi & 0x3) << 4 | (pt->vsync_offset_pulse_width_lo & 0xf); 1638 unsigned vsync_pulse_width = (pt->hsync_vsync_offset_pulse_width_hi & 0x3) << 4 | (pt->vsync_offset_pulse_width_lo & 0xf);
1639 1639
1640 /* ignore tiny modes */ 1640 /* ignore tiny modes */
@@ -1715,6 +1715,7 @@ set_size:
1715 } 1715 }
1716 1716
1717 mode->type = DRM_MODE_TYPE_DRIVER; 1717 mode->type = DRM_MODE_TYPE_DRIVER;
1718 mode->vrefresh = drm_mode_vrefresh(mode);
1718 drm_mode_set_name(mode); 1719 drm_mode_set_name(mode);
1719 1720
1720 return mode; 1721 return mode;
diff --git a/drivers/gpu/drm/exynos/exynos_drm_fimd.c b/drivers/gpu/drm/exynos/exynos_drm_fimd.c
index 36493ce71f9a..98cc14725ba9 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_fimd.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_fimd.c
@@ -38,11 +38,12 @@
38/* position control register for hardware window 0, 2 ~ 4.*/ 38/* position control register for hardware window 0, 2 ~ 4.*/
39#define VIDOSD_A(win) (VIDOSD_BASE + 0x00 + (win) * 16) 39#define VIDOSD_A(win) (VIDOSD_BASE + 0x00 + (win) * 16)
40#define VIDOSD_B(win) (VIDOSD_BASE + 0x04 + (win) * 16) 40#define VIDOSD_B(win) (VIDOSD_BASE + 0x04 + (win) * 16)
41/* size control register for hardware window 0. */ 41/*
42#define VIDOSD_C_SIZE_W0 (VIDOSD_BASE + 0x08) 42 * size control register for hardware windows 0 and alpha control register
43/* alpha control register for hardware window 1 ~ 4. */ 43 * for hardware windows 1 ~ 4
44#define VIDOSD_C(win) (VIDOSD_BASE + 0x18 + (win) * 16) 44 */
45/* size control register for hardware window 1 ~ 4. */ 45#define VIDOSD_C(win) (VIDOSD_BASE + 0x08 + (win) * 16)
46/* size control register for hardware windows 1 ~ 2. */
46#define VIDOSD_D(win) (VIDOSD_BASE + 0x0C + (win) * 16) 47#define VIDOSD_D(win) (VIDOSD_BASE + 0x0C + (win) * 16)
47 48
48#define VIDWx_BUF_START(win, buf) (VIDW_BUF_START(buf) + (win) * 8) 49#define VIDWx_BUF_START(win, buf) (VIDW_BUF_START(buf) + (win) * 8)
@@ -50,9 +51,9 @@
50#define VIDWx_BUF_SIZE(win, buf) (VIDW_BUF_SIZE(buf) + (win) * 4) 51#define VIDWx_BUF_SIZE(win, buf) (VIDW_BUF_SIZE(buf) + (win) * 4)
51 52
52/* color key control register for hardware window 1 ~ 4. */ 53/* color key control register for hardware window 1 ~ 4. */
53#define WKEYCON0_BASE(x) ((WKEYCON0 + 0x140) + (x * 8)) 54#define WKEYCON0_BASE(x) ((WKEYCON0 + 0x140) + ((x - 1) * 8))
54/* color key value register for hardware window 1 ~ 4. */ 55/* color key value register for hardware window 1 ~ 4. */
55#define WKEYCON1_BASE(x) ((WKEYCON1 + 0x140) + (x * 8)) 56#define WKEYCON1_BASE(x) ((WKEYCON1 + 0x140) + ((x - 1) * 8))
56 57
57/* FIMD has totally five hardware windows. */ 58/* FIMD has totally five hardware windows. */
58#define WINDOWS_NR 5 59#define WINDOWS_NR 5
@@ -109,9 +110,9 @@ struct fimd_context {
109 110
110#ifdef CONFIG_OF 111#ifdef CONFIG_OF
111static const struct of_device_id fimd_driver_dt_match[] = { 112static const struct of_device_id fimd_driver_dt_match[] = {
112 { .compatible = "samsung,exynos4-fimd", 113 { .compatible = "samsung,exynos4210-fimd",
113 .data = &exynos4_fimd_driver_data }, 114 .data = &exynos4_fimd_driver_data },
114 { .compatible = "samsung,exynos5-fimd", 115 { .compatible = "samsung,exynos5250-fimd",
115 .data = &exynos5_fimd_driver_data }, 116 .data = &exynos5_fimd_driver_data },
116 {}, 117 {},
117}; 118};
@@ -581,7 +582,7 @@ static void fimd_win_commit(struct device *dev, int zpos)
581 if (win != 3 && win != 4) { 582 if (win != 3 && win != 4) {
582 u32 offset = VIDOSD_D(win); 583 u32 offset = VIDOSD_D(win);
583 if (win == 0) 584 if (win == 0)
584 offset = VIDOSD_C_SIZE_W0; 585 offset = VIDOSD_C(win);
585 val = win_data->ovl_width * win_data->ovl_height; 586 val = win_data->ovl_width * win_data->ovl_height;
586 writel(val, ctx->regs + offset); 587 writel(val, ctx->regs + offset);
587 588
diff --git a/drivers/gpu/drm/exynos/exynos_drm_g2d.c b/drivers/gpu/drm/exynos/exynos_drm_g2d.c
index 3b0da0378acf..47a493c8a71f 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_g2d.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_g2d.c
@@ -48,8 +48,14 @@
48 48
49/* registers for base address */ 49/* registers for base address */
50#define G2D_SRC_BASE_ADDR 0x0304 50#define G2D_SRC_BASE_ADDR 0x0304
51#define G2D_SRC_COLOR_MODE 0x030C
52#define G2D_SRC_LEFT_TOP 0x0310
53#define G2D_SRC_RIGHT_BOTTOM 0x0314
51#define G2D_SRC_PLANE2_BASE_ADDR 0x0318 54#define G2D_SRC_PLANE2_BASE_ADDR 0x0318
52#define G2D_DST_BASE_ADDR 0x0404 55#define G2D_DST_BASE_ADDR 0x0404
56#define G2D_DST_COLOR_MODE 0x040C
57#define G2D_DST_LEFT_TOP 0x0410
58#define G2D_DST_RIGHT_BOTTOM 0x0414
53#define G2D_DST_PLANE2_BASE_ADDR 0x0418 59#define G2D_DST_PLANE2_BASE_ADDR 0x0418
54#define G2D_PAT_BASE_ADDR 0x0500 60#define G2D_PAT_BASE_ADDR 0x0500
55#define G2D_MSK_BASE_ADDR 0x0520 61#define G2D_MSK_BASE_ADDR 0x0520
@@ -82,7 +88,7 @@
82#define G2D_DMA_LIST_DONE_COUNT_OFFSET 17 88#define G2D_DMA_LIST_DONE_COUNT_OFFSET 17
83 89
84/* G2D_DMA_HOLD_CMD */ 90/* G2D_DMA_HOLD_CMD */
85#define G2D_USET_HOLD (1 << 2) 91#define G2D_USER_HOLD (1 << 2)
86#define G2D_LIST_HOLD (1 << 1) 92#define G2D_LIST_HOLD (1 << 1)
87#define G2D_BITBLT_HOLD (1 << 0) 93#define G2D_BITBLT_HOLD (1 << 0)
88 94
@@ -91,13 +97,27 @@
91#define G2D_START_NHOLT (1 << 1) 97#define G2D_START_NHOLT (1 << 1)
92#define G2D_START_BITBLT (1 << 0) 98#define G2D_START_BITBLT (1 << 0)
93 99
100/* buffer color format */
101#define G2D_FMT_XRGB8888 0
102#define G2D_FMT_ARGB8888 1
103#define G2D_FMT_RGB565 2
104#define G2D_FMT_XRGB1555 3
105#define G2D_FMT_ARGB1555 4
106#define G2D_FMT_XRGB4444 5
107#define G2D_FMT_ARGB4444 6
108#define G2D_FMT_PACKED_RGB888 7
109#define G2D_FMT_A8 11
110#define G2D_FMT_L8 12
111
112/* buffer valid length */
113#define G2D_LEN_MIN 1
114#define G2D_LEN_MAX 8000
115
94#define G2D_CMDLIST_SIZE (PAGE_SIZE / 4) 116#define G2D_CMDLIST_SIZE (PAGE_SIZE / 4)
95#define G2D_CMDLIST_NUM 64 117#define G2D_CMDLIST_NUM 64
96#define G2D_CMDLIST_POOL_SIZE (G2D_CMDLIST_SIZE * G2D_CMDLIST_NUM) 118#define G2D_CMDLIST_POOL_SIZE (G2D_CMDLIST_SIZE * G2D_CMDLIST_NUM)
97#define G2D_CMDLIST_DATA_NUM (G2D_CMDLIST_SIZE / sizeof(u32) - 2) 119#define G2D_CMDLIST_DATA_NUM (G2D_CMDLIST_SIZE / sizeof(u32) - 2)
98 120
99#define MAX_BUF_ADDR_NR 6
100
101/* maximum buffer pool size of userptr is 64MB as default */ 121/* maximum buffer pool size of userptr is 64MB as default */
102#define MAX_POOL (64 * 1024 * 1024) 122#define MAX_POOL (64 * 1024 * 1024)
103 123
@@ -106,6 +126,17 @@ enum {
106 BUF_TYPE_USERPTR, 126 BUF_TYPE_USERPTR,
107}; 127};
108 128
129enum g2d_reg_type {
130 REG_TYPE_NONE = -1,
131 REG_TYPE_SRC,
132 REG_TYPE_SRC_PLANE2,
133 REG_TYPE_DST,
134 REG_TYPE_DST_PLANE2,
135 REG_TYPE_PAT,
136 REG_TYPE_MSK,
137 MAX_REG_TYPE_NR
138};
139
109/* cmdlist data structure */ 140/* cmdlist data structure */
110struct g2d_cmdlist { 141struct g2d_cmdlist {
111 u32 head; 142 u32 head;
@@ -113,6 +144,42 @@ struct g2d_cmdlist {
113 u32 last; /* last data offset */ 144 u32 last; /* last data offset */
114}; 145};
115 146
147/*
148 * A structure of buffer description
149 *
150 * @format: color format
151 * @left_x: the x coordinates of left top corner
152 * @top_y: the y coordinates of left top corner
153 * @right_x: the x coordinates of right bottom corner
154 * @bottom_y: the y coordinates of right bottom corner
155 *
156 */
157struct g2d_buf_desc {
158 unsigned int format;
159 unsigned int left_x;
160 unsigned int top_y;
161 unsigned int right_x;
162 unsigned int bottom_y;
163};
164
165/*
166 * A structure of buffer information
167 *
168 * @map_nr: manages the number of mapped buffers
169 * @reg_types: stores regitster type in the order of requested command
170 * @handles: stores buffer handle in its reg_type position
171 * @types: stores buffer type in its reg_type position
172 * @descs: stores buffer description in its reg_type position
173 *
174 */
175struct g2d_buf_info {
176 unsigned int map_nr;
177 enum g2d_reg_type reg_types[MAX_REG_TYPE_NR];
178 unsigned long handles[MAX_REG_TYPE_NR];
179 unsigned int types[MAX_REG_TYPE_NR];
180 struct g2d_buf_desc descs[MAX_REG_TYPE_NR];
181};
182
116struct drm_exynos_pending_g2d_event { 183struct drm_exynos_pending_g2d_event {
117 struct drm_pending_event base; 184 struct drm_pending_event base;
118 struct drm_exynos_g2d_event event; 185 struct drm_exynos_g2d_event event;
@@ -131,14 +198,11 @@ struct g2d_cmdlist_userptr {
131 bool in_pool; 198 bool in_pool;
132 bool out_of_list; 199 bool out_of_list;
133}; 200};
134
135struct g2d_cmdlist_node { 201struct g2d_cmdlist_node {
136 struct list_head list; 202 struct list_head list;
137 struct g2d_cmdlist *cmdlist; 203 struct g2d_cmdlist *cmdlist;
138 unsigned int map_nr;
139 unsigned long handles[MAX_BUF_ADDR_NR];
140 unsigned int obj_type[MAX_BUF_ADDR_NR];
141 dma_addr_t dma_addr; 204 dma_addr_t dma_addr;
205 struct g2d_buf_info buf_info;
142 206
143 struct drm_exynos_pending_g2d_event *event; 207 struct drm_exynos_pending_g2d_event *event;
144}; 208};
@@ -188,6 +252,7 @@ static int g2d_init_cmdlist(struct g2d_data *g2d)
188 struct exynos_drm_subdrv *subdrv = &g2d->subdrv; 252 struct exynos_drm_subdrv *subdrv = &g2d->subdrv;
189 int nr; 253 int nr;
190 int ret; 254 int ret;
255 struct g2d_buf_info *buf_info;
191 256
192 init_dma_attrs(&g2d->cmdlist_dma_attrs); 257 init_dma_attrs(&g2d->cmdlist_dma_attrs);
193 dma_set_attr(DMA_ATTR_WRITE_COMBINE, &g2d->cmdlist_dma_attrs); 258 dma_set_attr(DMA_ATTR_WRITE_COMBINE, &g2d->cmdlist_dma_attrs);
@@ -209,11 +274,17 @@ static int g2d_init_cmdlist(struct g2d_data *g2d)
209 } 274 }
210 275
211 for (nr = 0; nr < G2D_CMDLIST_NUM; nr++) { 276 for (nr = 0; nr < G2D_CMDLIST_NUM; nr++) {
277 unsigned int i;
278
212 node[nr].cmdlist = 279 node[nr].cmdlist =
213 g2d->cmdlist_pool_virt + nr * G2D_CMDLIST_SIZE; 280 g2d->cmdlist_pool_virt + nr * G2D_CMDLIST_SIZE;
214 node[nr].dma_addr = 281 node[nr].dma_addr =
215 g2d->cmdlist_pool + nr * G2D_CMDLIST_SIZE; 282 g2d->cmdlist_pool + nr * G2D_CMDLIST_SIZE;
216 283
284 buf_info = &node[nr].buf_info;
285 for (i = 0; i < MAX_REG_TYPE_NR; i++)
286 buf_info->reg_types[i] = REG_TYPE_NONE;
287
217 list_add_tail(&node[nr].list, &g2d->free_cmdlist); 288 list_add_tail(&node[nr].list, &g2d->free_cmdlist);
218 } 289 }
219 290
@@ -450,7 +521,7 @@ static dma_addr_t *g2d_userptr_get_dma_addr(struct drm_device *drm_dev,
450 DMA_BIDIRECTIONAL); 521 DMA_BIDIRECTIONAL);
451 if (ret < 0) { 522 if (ret < 0) {
452 DRM_ERROR("failed to map sgt with dma region.\n"); 523 DRM_ERROR("failed to map sgt with dma region.\n");
453 goto err_free_sgt; 524 goto err_sg_free_table;
454 } 525 }
455 526
456 g2d_userptr->dma_addr = sgt->sgl[0].dma_address; 527 g2d_userptr->dma_addr = sgt->sgl[0].dma_address;
@@ -467,8 +538,10 @@ static dma_addr_t *g2d_userptr_get_dma_addr(struct drm_device *drm_dev,
467 538
468 return &g2d_userptr->dma_addr; 539 return &g2d_userptr->dma_addr;
469 540
470err_free_sgt: 541err_sg_free_table:
471 sg_free_table(sgt); 542 sg_free_table(sgt);
543
544err_free_sgt:
472 kfree(sgt); 545 kfree(sgt);
473 sgt = NULL; 546 sgt = NULL;
474 547
@@ -506,36 +579,172 @@ static void g2d_userptr_free_all(struct drm_device *drm_dev,
506 g2d->current_pool = 0; 579 g2d->current_pool = 0;
507} 580}
508 581
582static enum g2d_reg_type g2d_get_reg_type(int reg_offset)
583{
584 enum g2d_reg_type reg_type;
585
586 switch (reg_offset) {
587 case G2D_SRC_BASE_ADDR:
588 case G2D_SRC_COLOR_MODE:
589 case G2D_SRC_LEFT_TOP:
590 case G2D_SRC_RIGHT_BOTTOM:
591 reg_type = REG_TYPE_SRC;
592 break;
593 case G2D_SRC_PLANE2_BASE_ADDR:
594 reg_type = REG_TYPE_SRC_PLANE2;
595 break;
596 case G2D_DST_BASE_ADDR:
597 case G2D_DST_COLOR_MODE:
598 case G2D_DST_LEFT_TOP:
599 case G2D_DST_RIGHT_BOTTOM:
600 reg_type = REG_TYPE_DST;
601 break;
602 case G2D_DST_PLANE2_BASE_ADDR:
603 reg_type = REG_TYPE_DST_PLANE2;
604 break;
605 case G2D_PAT_BASE_ADDR:
606 reg_type = REG_TYPE_PAT;
607 break;
608 case G2D_MSK_BASE_ADDR:
609 reg_type = REG_TYPE_MSK;
610 break;
611 default:
612 reg_type = REG_TYPE_NONE;
613 DRM_ERROR("Unknown register offset![%d]\n", reg_offset);
614 break;
615 };
616
617 return reg_type;
618}
619
620static unsigned long g2d_get_buf_bpp(unsigned int format)
621{
622 unsigned long bpp;
623
624 switch (format) {
625 case G2D_FMT_XRGB8888:
626 case G2D_FMT_ARGB8888:
627 bpp = 4;
628 break;
629 case G2D_FMT_RGB565:
630 case G2D_FMT_XRGB1555:
631 case G2D_FMT_ARGB1555:
632 case G2D_FMT_XRGB4444:
633 case G2D_FMT_ARGB4444:
634 bpp = 2;
635 break;
636 case G2D_FMT_PACKED_RGB888:
637 bpp = 3;
638 break;
639 default:
640 bpp = 1;
641 break;
642 }
643
644 return bpp;
645}
646
647static bool g2d_check_buf_desc_is_valid(struct g2d_buf_desc *buf_desc,
648 enum g2d_reg_type reg_type,
649 unsigned long size)
650{
651 unsigned int width, height;
652 unsigned long area;
653
654 /*
655 * check source and destination buffers only.
656 * so the others are always valid.
657 */
658 if (reg_type != REG_TYPE_SRC && reg_type != REG_TYPE_DST)
659 return true;
660
661 width = buf_desc->right_x - buf_desc->left_x;
662 if (width < G2D_LEN_MIN || width > G2D_LEN_MAX) {
663 DRM_ERROR("width[%u] is out of range!\n", width);
664 return false;
665 }
666
667 height = buf_desc->bottom_y - buf_desc->top_y;
668 if (height < G2D_LEN_MIN || height > G2D_LEN_MAX) {
669 DRM_ERROR("height[%u] is out of range!\n", height);
670 return false;
671 }
672
673 area = (unsigned long)width * (unsigned long)height *
674 g2d_get_buf_bpp(buf_desc->format);
675 if (area > size) {
676 DRM_ERROR("area[%lu] is out of range[%lu]!\n", area, size);
677 return false;
678 }
679
680 return true;
681}
682
509static int g2d_map_cmdlist_gem(struct g2d_data *g2d, 683static int g2d_map_cmdlist_gem(struct g2d_data *g2d,
510 struct g2d_cmdlist_node *node, 684 struct g2d_cmdlist_node *node,
511 struct drm_device *drm_dev, 685 struct drm_device *drm_dev,
512 struct drm_file *file) 686 struct drm_file *file)
513{ 687{
514 struct g2d_cmdlist *cmdlist = node->cmdlist; 688 struct g2d_cmdlist *cmdlist = node->cmdlist;
689 struct g2d_buf_info *buf_info = &node->buf_info;
515 int offset; 690 int offset;
691 int ret;
516 int i; 692 int i;
517 693
518 for (i = 0; i < node->map_nr; i++) { 694 for (i = 0; i < buf_info->map_nr; i++) {
695 struct g2d_buf_desc *buf_desc;
696 enum g2d_reg_type reg_type;
697 int reg_pos;
519 unsigned long handle; 698 unsigned long handle;
520 dma_addr_t *addr; 699 dma_addr_t *addr;
521 700
522 offset = cmdlist->last - (i * 2 + 1); 701 reg_pos = cmdlist->last - 2 * (i + 1);
523 handle = cmdlist->data[offset]; 702
703 offset = cmdlist->data[reg_pos];
704 handle = cmdlist->data[reg_pos + 1];
705
706 reg_type = g2d_get_reg_type(offset);
707 if (reg_type == REG_TYPE_NONE) {
708 ret = -EFAULT;
709 goto err;
710 }
711
712 buf_desc = &buf_info->descs[reg_type];
713
714 if (buf_info->types[reg_type] == BUF_TYPE_GEM) {
715 unsigned long size;
716
717 size = exynos_drm_gem_get_size(drm_dev, handle, file);
718 if (!size) {
719 ret = -EFAULT;
720 goto err;
721 }
722
723 if (!g2d_check_buf_desc_is_valid(buf_desc, reg_type,
724 size)) {
725 ret = -EFAULT;
726 goto err;
727 }
524 728
525 if (node->obj_type[i] == BUF_TYPE_GEM) {
526 addr = exynos_drm_gem_get_dma_addr(drm_dev, handle, 729 addr = exynos_drm_gem_get_dma_addr(drm_dev, handle,
527 file); 730 file);
528 if (IS_ERR(addr)) { 731 if (IS_ERR(addr)) {
529 node->map_nr = i; 732 ret = -EFAULT;
530 return -EFAULT; 733 goto err;
531 } 734 }
532 } else { 735 } else {
533 struct drm_exynos_g2d_userptr g2d_userptr; 736 struct drm_exynos_g2d_userptr g2d_userptr;
534 737
535 if (copy_from_user(&g2d_userptr, (void __user *)handle, 738 if (copy_from_user(&g2d_userptr, (void __user *)handle,
536 sizeof(struct drm_exynos_g2d_userptr))) { 739 sizeof(struct drm_exynos_g2d_userptr))) {
537 node->map_nr = i; 740 ret = -EFAULT;
538 return -EFAULT; 741 goto err;
742 }
743
744 if (!g2d_check_buf_desc_is_valid(buf_desc, reg_type,
745 g2d_userptr.size)) {
746 ret = -EFAULT;
747 goto err;
539 } 748 }
540 749
541 addr = g2d_userptr_get_dma_addr(drm_dev, 750 addr = g2d_userptr_get_dma_addr(drm_dev,
@@ -544,16 +753,21 @@ static int g2d_map_cmdlist_gem(struct g2d_data *g2d,
544 file, 753 file,
545 &handle); 754 &handle);
546 if (IS_ERR(addr)) { 755 if (IS_ERR(addr)) {
547 node->map_nr = i; 756 ret = -EFAULT;
548 return -EFAULT; 757 goto err;
549 } 758 }
550 } 759 }
551 760
552 cmdlist->data[offset] = *addr; 761 cmdlist->data[reg_pos + 1] = *addr;
553 node->handles[i] = handle; 762 buf_info->reg_types[i] = reg_type;
763 buf_info->handles[reg_type] = handle;
554 } 764 }
555 765
556 return 0; 766 return 0;
767
768err:
769 buf_info->map_nr = i;
770 return ret;
557} 771}
558 772
559static void g2d_unmap_cmdlist_gem(struct g2d_data *g2d, 773static void g2d_unmap_cmdlist_gem(struct g2d_data *g2d,
@@ -561,22 +775,33 @@ static void g2d_unmap_cmdlist_gem(struct g2d_data *g2d,
561 struct drm_file *filp) 775 struct drm_file *filp)
562{ 776{
563 struct exynos_drm_subdrv *subdrv = &g2d->subdrv; 777 struct exynos_drm_subdrv *subdrv = &g2d->subdrv;
778 struct g2d_buf_info *buf_info = &node->buf_info;
564 int i; 779 int i;
565 780
566 for (i = 0; i < node->map_nr; i++) { 781 for (i = 0; i < buf_info->map_nr; i++) {
567 unsigned long handle = node->handles[i]; 782 struct g2d_buf_desc *buf_desc;
783 enum g2d_reg_type reg_type;
784 unsigned long handle;
785
786 reg_type = buf_info->reg_types[i];
787
788 buf_desc = &buf_info->descs[reg_type];
789 handle = buf_info->handles[reg_type];
568 790
569 if (node->obj_type[i] == BUF_TYPE_GEM) 791 if (buf_info->types[reg_type] == BUF_TYPE_GEM)
570 exynos_drm_gem_put_dma_addr(subdrv->drm_dev, handle, 792 exynos_drm_gem_put_dma_addr(subdrv->drm_dev, handle,
571 filp); 793 filp);
572 else 794 else
573 g2d_userptr_put_dma_addr(subdrv->drm_dev, handle, 795 g2d_userptr_put_dma_addr(subdrv->drm_dev, handle,
574 false); 796 false);
575 797
576 node->handles[i] = 0; 798 buf_info->reg_types[i] = REG_TYPE_NONE;
799 buf_info->handles[reg_type] = 0;
800 buf_info->types[reg_type] = 0;
801 memset(buf_desc, 0x00, sizeof(*buf_desc));
577 } 802 }
578 803
579 node->map_nr = 0; 804 buf_info->map_nr = 0;
580} 805}
581 806
582static void g2d_dma_start(struct g2d_data *g2d, 807static void g2d_dma_start(struct g2d_data *g2d,
@@ -589,10 +814,6 @@ static void g2d_dma_start(struct g2d_data *g2d,
589 pm_runtime_get_sync(g2d->dev); 814 pm_runtime_get_sync(g2d->dev);
590 clk_enable(g2d->gate_clk); 815 clk_enable(g2d->gate_clk);
591 816
592 /* interrupt enable */
593 writel_relaxed(G2D_INTEN_ACF | G2D_INTEN_UCF | G2D_INTEN_GCF,
594 g2d->regs + G2D_INTEN);
595
596 writel_relaxed(node->dma_addr, g2d->regs + G2D_DMA_SFR_BASE_ADDR); 817 writel_relaxed(node->dma_addr, g2d->regs + G2D_DMA_SFR_BASE_ADDR);
597 writel_relaxed(G2D_DMA_START, g2d->regs + G2D_DMA_COMMAND); 818 writel_relaxed(G2D_DMA_START, g2d->regs + G2D_DMA_COMMAND);
598} 819}
@@ -643,7 +864,6 @@ static void g2d_runqueue_worker(struct work_struct *work)
643 struct g2d_data *g2d = container_of(work, struct g2d_data, 864 struct g2d_data *g2d = container_of(work, struct g2d_data,
644 runqueue_work); 865 runqueue_work);
645 866
646
647 mutex_lock(&g2d->runqueue_mutex); 867 mutex_lock(&g2d->runqueue_mutex);
648 clk_disable(g2d->gate_clk); 868 clk_disable(g2d->gate_clk);
649 pm_runtime_put_sync(g2d->dev); 869 pm_runtime_put_sync(g2d->dev);
@@ -724,20 +944,14 @@ static int g2d_check_reg_offset(struct device *dev,
724 int i; 944 int i;
725 945
726 for (i = 0; i < nr; i++) { 946 for (i = 0; i < nr; i++) {
727 index = cmdlist->last - 2 * (i + 1); 947 struct g2d_buf_info *buf_info = &node->buf_info;
948 struct g2d_buf_desc *buf_desc;
949 enum g2d_reg_type reg_type;
950 unsigned long value;
728 951
729 if (for_addr) { 952 index = cmdlist->last - 2 * (i + 1);
730 /* check userptr buffer type. */
731 reg_offset = (cmdlist->data[index] &
732 ~0x7fffffff) >> 31;
733 if (reg_offset) {
734 node->obj_type[i] = BUF_TYPE_USERPTR;
735 cmdlist->data[index] &= ~G2D_BUF_USERPTR;
736 }
737 }
738 953
739 reg_offset = cmdlist->data[index] & ~0xfffff000; 954 reg_offset = cmdlist->data[index] & ~0xfffff000;
740
741 if (reg_offset < G2D_VALID_START || reg_offset > G2D_VALID_END) 955 if (reg_offset < G2D_VALID_START || reg_offset > G2D_VALID_END)
742 goto err; 956 goto err;
743 if (reg_offset % 4) 957 if (reg_offset % 4)
@@ -753,8 +967,60 @@ static int g2d_check_reg_offset(struct device *dev,
753 if (!for_addr) 967 if (!for_addr)
754 goto err; 968 goto err;
755 969
756 if (node->obj_type[i] != BUF_TYPE_USERPTR) 970 reg_type = g2d_get_reg_type(reg_offset);
757 node->obj_type[i] = BUF_TYPE_GEM; 971 if (reg_type == REG_TYPE_NONE)
972 goto err;
973
974 /* check userptr buffer type. */
975 if ((cmdlist->data[index] & ~0x7fffffff) >> 31) {
976 buf_info->types[reg_type] = BUF_TYPE_USERPTR;
977 cmdlist->data[index] &= ~G2D_BUF_USERPTR;
978 } else
979 buf_info->types[reg_type] = BUF_TYPE_GEM;
980 break;
981 case G2D_SRC_COLOR_MODE:
982 case G2D_DST_COLOR_MODE:
983 if (for_addr)
984 goto err;
985
986 reg_type = g2d_get_reg_type(reg_offset);
987 if (reg_type == REG_TYPE_NONE)
988 goto err;
989
990 buf_desc = &buf_info->descs[reg_type];
991 value = cmdlist->data[index + 1];
992
993 buf_desc->format = value & 0xf;
994 break;
995 case G2D_SRC_LEFT_TOP:
996 case G2D_DST_LEFT_TOP:
997 if (for_addr)
998 goto err;
999
1000 reg_type = g2d_get_reg_type(reg_offset);
1001 if (reg_type == REG_TYPE_NONE)
1002 goto err;
1003
1004 buf_desc = &buf_info->descs[reg_type];
1005 value = cmdlist->data[index + 1];
1006
1007 buf_desc->left_x = value & 0x1fff;
1008 buf_desc->top_y = (value & 0x1fff0000) >> 16;
1009 break;
1010 case G2D_SRC_RIGHT_BOTTOM:
1011 case G2D_DST_RIGHT_BOTTOM:
1012 if (for_addr)
1013 goto err;
1014
1015 reg_type = g2d_get_reg_type(reg_offset);
1016 if (reg_type == REG_TYPE_NONE)
1017 goto err;
1018
1019 buf_desc = &buf_info->descs[reg_type];
1020 value = cmdlist->data[index + 1];
1021
1022 buf_desc->right_x = value & 0x1fff;
1023 buf_desc->bottom_y = (value & 0x1fff0000) >> 16;
758 break; 1024 break;
759 default: 1025 default:
760 if (for_addr) 1026 if (for_addr)
@@ -860,9 +1126,23 @@ int exynos_g2d_set_cmdlist_ioctl(struct drm_device *drm_dev, void *data,
860 cmdlist->data[cmdlist->last++] = G2D_SRC_BASE_ADDR; 1126 cmdlist->data[cmdlist->last++] = G2D_SRC_BASE_ADDR;
861 cmdlist->data[cmdlist->last++] = 0; 1127 cmdlist->data[cmdlist->last++] = 0;
862 1128
1129 /*
1130 * 'LIST_HOLD' command should be set to the DMA_HOLD_CMD_REG
1131 * and GCF bit should be set to INTEN register if user wants
1132 * G2D interrupt event once current command list execution is
1133 * finished.
1134 * Otherwise only ACF bit should be set to INTEN register so
1135 * that one interrupt is occured after all command lists
1136 * have been completed.
1137 */
863 if (node->event) { 1138 if (node->event) {
1139 cmdlist->data[cmdlist->last++] = G2D_INTEN;
1140 cmdlist->data[cmdlist->last++] = G2D_INTEN_ACF | G2D_INTEN_GCF;
864 cmdlist->data[cmdlist->last++] = G2D_DMA_HOLD_CMD; 1141 cmdlist->data[cmdlist->last++] = G2D_DMA_HOLD_CMD;
865 cmdlist->data[cmdlist->last++] = G2D_LIST_HOLD; 1142 cmdlist->data[cmdlist->last++] = G2D_LIST_HOLD;
1143 } else {
1144 cmdlist->data[cmdlist->last++] = G2D_INTEN;
1145 cmdlist->data[cmdlist->last++] = G2D_INTEN_ACF;
866 } 1146 }
867 1147
868 /* Check size of cmdlist: last 2 is about G2D_BITBLT_START */ 1148 /* Check size of cmdlist: last 2 is about G2D_BITBLT_START */
@@ -887,7 +1167,7 @@ int exynos_g2d_set_cmdlist_ioctl(struct drm_device *drm_dev, void *data,
887 if (ret < 0) 1167 if (ret < 0)
888 goto err_free_event; 1168 goto err_free_event;
889 1169
890 node->map_nr = req->cmd_buf_nr; 1170 node->buf_info.map_nr = req->cmd_buf_nr;
891 if (req->cmd_buf_nr) { 1171 if (req->cmd_buf_nr) {
892 struct drm_exynos_g2d_cmd *cmd_buf; 1172 struct drm_exynos_g2d_cmd *cmd_buf;
893 1173
diff --git a/drivers/gpu/drm/exynos/exynos_drm_gem.c b/drivers/gpu/drm/exynos/exynos_drm_gem.c
index 67e17ce112b6..0e6fe000578c 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_gem.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_gem.c
@@ -164,6 +164,27 @@ out:
164 exynos_gem_obj = NULL; 164 exynos_gem_obj = NULL;
165} 165}
166 166
167unsigned long exynos_drm_gem_get_size(struct drm_device *dev,
168 unsigned int gem_handle,
169 struct drm_file *file_priv)
170{
171 struct exynos_drm_gem_obj *exynos_gem_obj;
172 struct drm_gem_object *obj;
173
174 obj = drm_gem_object_lookup(dev, file_priv, gem_handle);
175 if (!obj) {
176 DRM_ERROR("failed to lookup gem object.\n");
177 return 0;
178 }
179
180 exynos_gem_obj = to_exynos_gem_obj(obj);
181
182 drm_gem_object_unreference_unlocked(obj);
183
184 return exynos_gem_obj->buffer->size;
185}
186
187
167struct exynos_drm_gem_obj *exynos_drm_gem_init(struct drm_device *dev, 188struct exynos_drm_gem_obj *exynos_drm_gem_init(struct drm_device *dev,
168 unsigned long size) 189 unsigned long size)
169{ 190{
diff --git a/drivers/gpu/drm/exynos/exynos_drm_gem.h b/drivers/gpu/drm/exynos/exynos_drm_gem.h
index 35ebac47dc2b..468766bee450 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_gem.h
+++ b/drivers/gpu/drm/exynos/exynos_drm_gem.h
@@ -130,6 +130,11 @@ int exynos_drm_gem_userptr_ioctl(struct drm_device *dev, void *data,
130int exynos_drm_gem_get_ioctl(struct drm_device *dev, void *data, 130int exynos_drm_gem_get_ioctl(struct drm_device *dev, void *data,
131 struct drm_file *file_priv); 131 struct drm_file *file_priv);
132 132
133/* get buffer size to gem handle. */
134unsigned long exynos_drm_gem_get_size(struct drm_device *dev,
135 unsigned int gem_handle,
136 struct drm_file *file_priv);
137
133/* initialize gem object. */ 138/* initialize gem object. */
134int exynos_drm_gem_init_object(struct drm_gem_object *obj); 139int exynos_drm_gem_init_object(struct drm_gem_object *obj);
135 140
diff --git a/drivers/gpu/drm/exynos/exynos_drm_vidi.c b/drivers/gpu/drm/exynos/exynos_drm_vidi.c
index 13ccbd4bcfaa..9504b0cd825a 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_vidi.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_vidi.c
@@ -117,13 +117,12 @@ static struct edid *vidi_get_edid(struct device *dev,
117 } 117 }
118 118
119 edid_len = (1 + ctx->raw_edid->extensions) * EDID_LENGTH; 119 edid_len = (1 + ctx->raw_edid->extensions) * EDID_LENGTH;
120 edid = kzalloc(edid_len, GFP_KERNEL); 120 edid = kmemdup(ctx->raw_edid, edid_len, GFP_KERNEL);
121 if (!edid) { 121 if (!edid) {
122 DRM_DEBUG_KMS("failed to allocate edid\n"); 122 DRM_DEBUG_KMS("failed to allocate edid\n");
123 return ERR_PTR(-ENOMEM); 123 return ERR_PTR(-ENOMEM);
124 } 124 }
125 125
126 memcpy(edid, ctx->raw_edid, edid_len);
127 return edid; 126 return edid;
128} 127}
129 128
@@ -563,12 +562,11 @@ int vidi_connection_ioctl(struct drm_device *drm_dev, void *data,
563 return -EINVAL; 562 return -EINVAL;
564 } 563 }
565 edid_len = (1 + raw_edid->extensions) * EDID_LENGTH; 564 edid_len = (1 + raw_edid->extensions) * EDID_LENGTH;
566 ctx->raw_edid = kzalloc(edid_len, GFP_KERNEL); 565 ctx->raw_edid = kmemdup(raw_edid, edid_len, GFP_KERNEL);
567 if (!ctx->raw_edid) { 566 if (!ctx->raw_edid) {
568 DRM_DEBUG_KMS("failed to allocate raw_edid.\n"); 567 DRM_DEBUG_KMS("failed to allocate raw_edid.\n");
569 return -ENOMEM; 568 return -ENOMEM;
570 } 569 }
571 memcpy(ctx->raw_edid, raw_edid, edid_len);
572 } else { 570 } else {
573 /* 571 /*
574 * with connection = 0, free raw_edid 572 * with connection = 0, free raw_edid
diff --git a/drivers/gpu/drm/exynos/exynos_mixer.c b/drivers/gpu/drm/exynos/exynos_mixer.c
index e919aba29b3d..2f4f72f07047 100644
--- a/drivers/gpu/drm/exynos/exynos_mixer.c
+++ b/drivers/gpu/drm/exynos/exynos_mixer.c
@@ -818,7 +818,7 @@ static void mixer_win_disable(void *ctx, int win)
818 mixer_ctx->win_data[win].enabled = false; 818 mixer_ctx->win_data[win].enabled = false;
819} 819}
820 820
821int mixer_check_timing(void *ctx, struct fb_videomode *timing) 821static int mixer_check_timing(void *ctx, struct fb_videomode *timing)
822{ 822{
823 struct mixer_context *mixer_ctx = ctx; 823 struct mixer_context *mixer_ctx = ctx;
824 u32 w, h; 824 u32 w, h;
diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
index aae31489c893..7299ea45dd03 100644
--- a/drivers/gpu/drm/i915/i915_debugfs.c
+++ b/drivers/gpu/drm/i915/i915_debugfs.c
@@ -103,7 +103,7 @@ static const char *cache_level_str(int type)
103static void 103static void
104describe_obj(struct seq_file *m, struct drm_i915_gem_object *obj) 104describe_obj(struct seq_file *m, struct drm_i915_gem_object *obj)
105{ 105{
106 seq_printf(m, "%p: %s%s %8zdKiB %02x %02x %d %d %d%s%s%s", 106 seq_printf(m, "%pK: %s%s %8zdKiB %02x %02x %d %d %d%s%s%s",
107 &obj->base, 107 &obj->base,
108 get_pin_flag(obj), 108 get_pin_flag(obj),
109 get_tiling_flag(obj), 109 get_tiling_flag(obj),
diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c
index 0a8eceb75902..e9b57893db2b 100644
--- a/drivers/gpu/drm/i915/i915_drv.c
+++ b/drivers/gpu/drm/i915/i915_drv.c
@@ -125,6 +125,11 @@ MODULE_PARM_DESC(preliminary_hw_support,
125 "Enable Haswell and ValleyView Support. " 125 "Enable Haswell and ValleyView Support. "
126 "(default: false)"); 126 "(default: false)");
127 127
128int i915_disable_power_well __read_mostly = 0;
129module_param_named(disable_power_well, i915_disable_power_well, int, 0600);
130MODULE_PARM_DESC(disable_power_well,
131 "Disable the power well when possible (default: false)");
132
128static struct drm_driver driver; 133static struct drm_driver driver;
129extern int intel_agp_enabled; 134extern int intel_agp_enabled;
130 135
diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index e95337c97459..01769e2a9953 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -1398,6 +1398,7 @@ extern int i915_enable_fbc __read_mostly;
1398extern bool i915_enable_hangcheck __read_mostly; 1398extern bool i915_enable_hangcheck __read_mostly;
1399extern int i915_enable_ppgtt __read_mostly; 1399extern int i915_enable_ppgtt __read_mostly;
1400extern unsigned int i915_preliminary_hw_support __read_mostly; 1400extern unsigned int i915_preliminary_hw_support __read_mostly;
1401extern int i915_disable_power_well __read_mostly;
1401 1402
1402extern int i915_suspend(struct drm_device *dev, pm_message_t state); 1403extern int i915_suspend(struct drm_device *dev, pm_message_t state);
1403extern int i915_resume(struct drm_device *dev); 1404extern int i915_resume(struct drm_device *dev);
diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
index 2f2daebd0eef..3b11ab0fbc96 100644
--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
@@ -732,6 +732,8 @@ validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
732 int count) 732 int count)
733{ 733{
734 int i; 734 int i;
735 int relocs_total = 0;
736 int relocs_max = INT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
735 737
736 for (i = 0; i < count; i++) { 738 for (i = 0; i < count; i++) {
737 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr; 739 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
@@ -740,10 +742,13 @@ validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
740 if (exec[i].flags & __EXEC_OBJECT_UNKNOWN_FLAGS) 742 if (exec[i].flags & __EXEC_OBJECT_UNKNOWN_FLAGS)
741 return -EINVAL; 743 return -EINVAL;
742 744
743 /* First check for malicious input causing overflow */ 745 /* First check for malicious input causing overflow in
744 if (exec[i].relocation_count > 746 * the worst case where we need to allocate the entire
745 INT_MAX / sizeof(struct drm_i915_gem_relocation_entry)) 747 * relocation tree as a single array.
748 */
749 if (exec[i].relocation_count > relocs_max - relocs_total)
746 return -EINVAL; 750 return -EINVAL;
751 relocs_total += exec[i].relocation_count;
747 752
748 length = exec[i].relocation_count * 753 length = exec[i].relocation_count *
749 sizeof(struct drm_i915_gem_relocation_entry); 754 sizeof(struct drm_i915_gem_relocation_entry);
diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
index 287b42c9d1a8..b20d50192fcc 100644
--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -5771,6 +5771,11 @@ static int haswell_crtc_mode_set(struct drm_crtc *crtc,
5771 num_connectors++; 5771 num_connectors++;
5772 } 5772 }
5773 5773
5774 if (is_cpu_edp)
5775 intel_crtc->cpu_transcoder = TRANSCODER_EDP;
5776 else
5777 intel_crtc->cpu_transcoder = pipe;
5778
5774 /* We are not sure yet this won't happen. */ 5779 /* We are not sure yet this won't happen. */
5775 WARN(!HAS_PCH_LPT(dev), "Unexpected PCH type %d\n", 5780 WARN(!HAS_PCH_LPT(dev), "Unexpected PCH type %d\n",
5776 INTEL_PCH_TYPE(dev)); 5781 INTEL_PCH_TYPE(dev));
@@ -5837,11 +5842,6 @@ static int intel_crtc_mode_set(struct drm_crtc *crtc,
5837 int pipe = intel_crtc->pipe; 5842 int pipe = intel_crtc->pipe;
5838 int ret; 5843 int ret;
5839 5844
5840 if (IS_HASWELL(dev) && intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))
5841 intel_crtc->cpu_transcoder = TRANSCODER_EDP;
5842 else
5843 intel_crtc->cpu_transcoder = pipe;
5844
5845 drm_vblank_pre_modeset(dev, pipe); 5845 drm_vblank_pre_modeset(dev, pipe);
5846 5846
5847 ret = dev_priv->display.crtc_mode_set(crtc, mode, adjusted_mode, 5847 ret = dev_priv->display.crtc_mode_set(crtc, mode, adjusted_mode,
diff --git a/drivers/gpu/drm/i915/intel_dp.c b/drivers/gpu/drm/i915/intel_dp.c
index 6f728e5ee793..d7d4afe01341 100644
--- a/drivers/gpu/drm/i915/intel_dp.c
+++ b/drivers/gpu/drm/i915/intel_dp.c
@@ -820,6 +820,7 @@ intel_dp_set_m_n(struct drm_crtc *crtc, struct drm_display_mode *mode,
820 struct intel_link_m_n m_n; 820 struct intel_link_m_n m_n;
821 int pipe = intel_crtc->pipe; 821 int pipe = intel_crtc->pipe;
822 enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder; 822 enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
823 int target_clock;
823 824
824 /* 825 /*
825 * Find the lane count in the intel_encoder private 826 * Find the lane count in the intel_encoder private
@@ -835,13 +836,22 @@ intel_dp_set_m_n(struct drm_crtc *crtc, struct drm_display_mode *mode,
835 } 836 }
836 } 837 }
837 838
839 target_clock = mode->clock;
840 for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
841 if (intel_encoder->type == INTEL_OUTPUT_EDP) {
842 target_clock = intel_edp_target_clock(intel_encoder,
843 mode);
844 break;
845 }
846 }
847
838 /* 848 /*
839 * Compute the GMCH and Link ratios. The '3' here is 849 * Compute the GMCH and Link ratios. The '3' here is
840 * the number of bytes_per_pixel post-LUT, which we always 850 * the number of bytes_per_pixel post-LUT, which we always
841 * set up for 8-bits of R/G/B, or 3 bytes total. 851 * set up for 8-bits of R/G/B, or 3 bytes total.
842 */ 852 */
843 intel_link_compute_m_n(intel_crtc->bpp, lane_count, 853 intel_link_compute_m_n(intel_crtc->bpp, lane_count,
844 mode->clock, adjusted_mode->clock, &m_n); 854 target_clock, adjusted_mode->clock, &m_n);
845 855
846 if (IS_HASWELL(dev)) { 856 if (IS_HASWELL(dev)) {
847 I915_WRITE(PIPE_DATA_M1(cpu_transcoder), 857 I915_WRITE(PIPE_DATA_M1(cpu_transcoder),
@@ -1930,7 +1940,7 @@ intel_dp_start_link_train(struct intel_dp *intel_dp)
1930 for (i = 0; i < intel_dp->lane_count; i++) 1940 for (i = 0; i < intel_dp->lane_count; i++)
1931 if ((intel_dp->train_set[i] & DP_TRAIN_MAX_SWING_REACHED) == 0) 1941 if ((intel_dp->train_set[i] & DP_TRAIN_MAX_SWING_REACHED) == 0)
1932 break; 1942 break;
1933 if (i == intel_dp->lane_count && voltage_tries == 5) { 1943 if (i == intel_dp->lane_count) {
1934 ++loop_tries; 1944 ++loop_tries;
1935 if (loop_tries == 5) { 1945 if (loop_tries == 5) {
1936 DRM_DEBUG_KMS("too many full retries, give up\n"); 1946 DRM_DEBUG_KMS("too many full retries, give up\n");
diff --git a/drivers/gpu/drm/i915/intel_i2c.c b/drivers/gpu/drm/i915/intel_i2c.c
index acf8aec9ada7..ef4744e1bf0b 100644
--- a/drivers/gpu/drm/i915/intel_i2c.c
+++ b/drivers/gpu/drm/i915/intel_i2c.c
@@ -203,7 +203,13 @@ intel_gpio_setup(struct intel_gmbus *bus, u32 pin)
203 algo->data = bus; 203 algo->data = bus;
204} 204}
205 205
206#define HAS_GMBUS_IRQ(dev) (INTEL_INFO(dev)->gen >= 4) 206/*
207 * gmbus on gen4 seems to be able to generate legacy interrupts even when in MSI
208 * mode. This results in spurious interrupt warnings if the legacy irq no. is
209 * shared with another device. The kernel then disables that interrupt source
210 * and so prevents the other device from working properly.
211 */
212#define HAS_GMBUS_IRQ(dev) (INTEL_INFO(dev)->gen >= 5)
207static int 213static int
208gmbus_wait_hw_status(struct drm_i915_private *dev_priv, 214gmbus_wait_hw_status(struct drm_i915_private *dev_priv,
209 u32 gmbus2_status, 215 u32 gmbus2_status,
@@ -214,6 +220,9 @@ gmbus_wait_hw_status(struct drm_i915_private *dev_priv,
214 u32 gmbus2 = 0; 220 u32 gmbus2 = 0;
215 DEFINE_WAIT(wait); 221 DEFINE_WAIT(wait);
216 222
223 if (!HAS_GMBUS_IRQ(dev_priv->dev))
224 gmbus4_irq_en = 0;
225
217 /* Important: The hw handles only the first bit, so set only one! Since 226 /* Important: The hw handles only the first bit, so set only one! Since
218 * we also need to check for NAKs besides the hw ready/idle signal, we 227 * we also need to check for NAKs besides the hw ready/idle signal, we
219 * need to wake up periodically and check that ourselves. */ 228 * need to wake up periodically and check that ourselves. */
diff --git a/drivers/gpu/drm/i915/intel_panel.c b/drivers/gpu/drm/i915/intel_panel.c
index a3730e0289e5..bee8cb6108a7 100644
--- a/drivers/gpu/drm/i915/intel_panel.c
+++ b/drivers/gpu/drm/i915/intel_panel.c
@@ -321,9 +321,6 @@ void intel_panel_enable_backlight(struct drm_device *dev,
321 if (dev_priv->backlight_level == 0) 321 if (dev_priv->backlight_level == 0)
322 dev_priv->backlight_level = intel_panel_get_max_backlight(dev); 322 dev_priv->backlight_level = intel_panel_get_max_backlight(dev);
323 323
324 dev_priv->backlight_enabled = true;
325 intel_panel_actually_set_backlight(dev, dev_priv->backlight_level);
326
327 if (INTEL_INFO(dev)->gen >= 4) { 324 if (INTEL_INFO(dev)->gen >= 4) {
328 uint32_t reg, tmp; 325 uint32_t reg, tmp;
329 326
@@ -359,12 +356,12 @@ void intel_panel_enable_backlight(struct drm_device *dev,
359 } 356 }
360 357
361set_level: 358set_level:
362 /* Check the current backlight level and try to set again if it's zero. 359 /* Call below after setting BLC_PWM_CPU_CTL2 and BLC_PWM_PCH_CTL1.
363 * On some machines, BLC_PWM_CPU_CTL is cleared to zero automatically 360 * BLC_PWM_CPU_CTL may be cleared to zero automatically when these
364 * when BLC_PWM_CPU_CTL2 and BLC_PWM_PCH_CTL1 are written. 361 * registers are set.
365 */ 362 */
366 if (!intel_panel_get_backlight(dev)) 363 dev_priv->backlight_enabled = true;
367 intel_panel_actually_set_backlight(dev, dev_priv->backlight_level); 364 intel_panel_actually_set_backlight(dev, dev_priv->backlight_level);
368} 365}
369 366
370static void intel_panel_init_backlight(struct drm_device *dev) 367static void intel_panel_init_backlight(struct drm_device *dev)
diff --git a/drivers/gpu/drm/i915/intel_pm.c b/drivers/gpu/drm/i915/intel_pm.c
index a1794c6df1bf..adca00783e61 100644
--- a/drivers/gpu/drm/i915/intel_pm.c
+++ b/drivers/gpu/drm/i915/intel_pm.c
@@ -4079,6 +4079,9 @@ void intel_set_power_well(struct drm_device *dev, bool enable)
4079 if (!IS_HASWELL(dev)) 4079 if (!IS_HASWELL(dev))
4080 return; 4080 return;
4081 4081
4082 if (!i915_disable_power_well && !enable)
4083 return;
4084
4082 tmp = I915_READ(HSW_PWR_WELL_DRIVER); 4085 tmp = I915_READ(HSW_PWR_WELL_DRIVER);
4083 is_enabled = tmp & HSW_PWR_WELL_STATE; 4086 is_enabled = tmp & HSW_PWR_WELL_STATE;
4084 enable_requested = tmp & HSW_PWR_WELL_ENABLE; 4087 enable_requested = tmp & HSW_PWR_WELL_ENABLE;
diff --git a/drivers/gpu/drm/mgag200/mgag200_mode.c b/drivers/gpu/drm/mgag200/mgag200_mode.c
index a274b9906ef8..fe22bb780e1d 100644
--- a/drivers/gpu/drm/mgag200/mgag200_mode.c
+++ b/drivers/gpu/drm/mgag200/mgag200_mode.c
@@ -382,19 +382,19 @@ static int mga_g200eh_set_plls(struct mga_device *mdev, long clock)
382 m = n = p = 0; 382 m = n = p = 0;
383 vcomax = 800000; 383 vcomax = 800000;
384 vcomin = 400000; 384 vcomin = 400000;
385 pllreffreq = 3333; 385 pllreffreq = 33333;
386 386
387 delta = 0xffffffff; 387 delta = 0xffffffff;
388 permitteddelta = clock * 5 / 1000; 388 permitteddelta = clock * 5 / 1000;
389 389
390 for (testp = 16; testp > 0; testp--) { 390 for (testp = 16; testp > 0; testp >>= 1) {
391 if (clock * testp > vcomax) 391 if (clock * testp > vcomax)
392 continue; 392 continue;
393 if (clock * testp < vcomin) 393 if (clock * testp < vcomin)
394 continue; 394 continue;
395 395
396 for (testm = 1; testm < 33; testm++) { 396 for (testm = 1; testm < 33; testm++) {
397 for (testn = 1; testn < 257; testn++) { 397 for (testn = 17; testn < 257; testn++) {
398 computed = (pllreffreq * testn) / 398 computed = (pllreffreq * testn) /
399 (testm * testp); 399 (testm * testp);
400 if (computed > clock) 400 if (computed > clock)
@@ -404,11 +404,11 @@ static int mga_g200eh_set_plls(struct mga_device *mdev, long clock)
404 if (tmpdelta < delta) { 404 if (tmpdelta < delta) {
405 delta = tmpdelta; 405 delta = tmpdelta;
406 n = testn - 1; 406 n = testn - 1;
407 m = (testm - 1) | ((n >> 1) & 0x80); 407 m = (testm - 1);
408 p = testp - 1; 408 p = testp - 1;
409 } 409 }
410 if ((clock * testp) >= 600000) 410 if ((clock * testp) >= 600000)
411 p |= 80; 411 p |= 0x80;
412 } 412 }
413 } 413 }
414 } 414 }
diff --git a/drivers/gpu/drm/nouveau/core/core/object.c b/drivers/gpu/drm/nouveau/core/core/object.c
index 0daab62ea14c..3b2e7b6304d3 100644
--- a/drivers/gpu/drm/nouveau/core/core/object.c
+++ b/drivers/gpu/drm/nouveau/core/core/object.c
@@ -278,7 +278,6 @@ nouveau_object_del(struct nouveau_object *client, u32 _parent, u32 _handle)
278 struct nouveau_object *parent = NULL; 278 struct nouveau_object *parent = NULL;
279 struct nouveau_object *namedb = NULL; 279 struct nouveau_object *namedb = NULL;
280 struct nouveau_handle *handle = NULL; 280 struct nouveau_handle *handle = NULL;
281 int ret = -EINVAL;
282 281
283 parent = nouveau_handle_ref(client, _parent); 282 parent = nouveau_handle_ref(client, _parent);
284 if (!parent) 283 if (!parent)
@@ -295,7 +294,7 @@ nouveau_object_del(struct nouveau_object *client, u32 _parent, u32 _handle)
295 } 294 }
296 295
297 nouveau_object_ref(NULL, &parent); 296 nouveau_object_ref(NULL, &parent);
298 return ret; 297 return handle ? 0 : -EINVAL;
299} 298}
300 299
301int 300int
diff --git a/drivers/gpu/drm/nouveau/core/include/subdev/therm.h b/drivers/gpu/drm/nouveau/core/include/subdev/therm.h
index 6b17b614629f..0b20fc0d19c1 100644
--- a/drivers/gpu/drm/nouveau/core/include/subdev/therm.h
+++ b/drivers/gpu/drm/nouveau/core/include/subdev/therm.h
@@ -4,7 +4,7 @@
4#include <core/device.h> 4#include <core/device.h>
5#include <core/subdev.h> 5#include <core/subdev.h>
6 6
7enum nouveau_therm_mode { 7enum nouveau_therm_fan_mode {
8 NOUVEAU_THERM_CTRL_NONE = 0, 8 NOUVEAU_THERM_CTRL_NONE = 0,
9 NOUVEAU_THERM_CTRL_MANUAL = 1, 9 NOUVEAU_THERM_CTRL_MANUAL = 1,
10 NOUVEAU_THERM_CTRL_AUTO = 2, 10 NOUVEAU_THERM_CTRL_AUTO = 2,
diff --git a/drivers/gpu/drm/nouveau/core/subdev/therm/base.c b/drivers/gpu/drm/nouveau/core/subdev/therm/base.c
index f794dc89a3b2..a00a5a76e2d6 100644
--- a/drivers/gpu/drm/nouveau/core/subdev/therm/base.c
+++ b/drivers/gpu/drm/nouveau/core/subdev/therm/base.c
@@ -134,7 +134,7 @@ nouveau_therm_alarm(struct nouveau_alarm *alarm)
134} 134}
135 135
136int 136int
137nouveau_therm_mode(struct nouveau_therm *therm, int mode) 137nouveau_therm_fan_mode(struct nouveau_therm *therm, int mode)
138{ 138{
139 struct nouveau_therm_priv *priv = (void *)therm; 139 struct nouveau_therm_priv *priv = (void *)therm;
140 struct nouveau_device *device = nv_device(therm); 140 struct nouveau_device *device = nv_device(therm);
@@ -149,10 +149,15 @@ nouveau_therm_mode(struct nouveau_therm *therm, int mode)
149 (mode != NOUVEAU_THERM_CTRL_NONE && device->card_type >= NV_C0)) 149 (mode != NOUVEAU_THERM_CTRL_NONE && device->card_type >= NV_C0))
150 return -EINVAL; 150 return -EINVAL;
151 151
152 /* do not allow automatic fan management if the thermal sensor is
153 * not available */
154 if (priv->mode == 2 && therm->temp_get(therm) < 0)
155 return -EINVAL;
156
152 if (priv->mode == mode) 157 if (priv->mode == mode)
153 return 0; 158 return 0;
154 159
155 nv_info(therm, "Thermal management: %s\n", name[mode]); 160 nv_info(therm, "fan management: %s\n", name[mode]);
156 nouveau_therm_update(therm, mode); 161 nouveau_therm_update(therm, mode);
157 return 0; 162 return 0;
158} 163}
@@ -213,7 +218,7 @@ nouveau_therm_attr_set(struct nouveau_therm *therm,
213 priv->fan->bios.max_duty = value; 218 priv->fan->bios.max_duty = value;
214 return 0; 219 return 0;
215 case NOUVEAU_THERM_ATTR_FAN_MODE: 220 case NOUVEAU_THERM_ATTR_FAN_MODE:
216 return nouveau_therm_mode(therm, value); 221 return nouveau_therm_fan_mode(therm, value);
217 case NOUVEAU_THERM_ATTR_THRS_FAN_BOOST: 222 case NOUVEAU_THERM_ATTR_THRS_FAN_BOOST:
218 priv->bios_sensor.thrs_fan_boost.temp = value; 223 priv->bios_sensor.thrs_fan_boost.temp = value;
219 priv->sensor.program_alarms(therm); 224 priv->sensor.program_alarms(therm);
@@ -263,7 +268,7 @@ _nouveau_therm_init(struct nouveau_object *object)
263 return ret; 268 return ret;
264 269
265 if (priv->suspend >= 0) 270 if (priv->suspend >= 0)
266 nouveau_therm_mode(therm, priv->mode); 271 nouveau_therm_fan_mode(therm, priv->mode);
267 priv->sensor.program_alarms(therm); 272 priv->sensor.program_alarms(therm);
268 return 0; 273 return 0;
269} 274}
@@ -313,11 +318,12 @@ nouveau_therm_create_(struct nouveau_object *parent,
313int 318int
314nouveau_therm_preinit(struct nouveau_therm *therm) 319nouveau_therm_preinit(struct nouveau_therm *therm)
315{ 320{
316 nouveau_therm_ic_ctor(therm);
317 nouveau_therm_sensor_ctor(therm); 321 nouveau_therm_sensor_ctor(therm);
322 nouveau_therm_ic_ctor(therm);
318 nouveau_therm_fan_ctor(therm); 323 nouveau_therm_fan_ctor(therm);
319 324
320 nouveau_therm_mode(therm, NOUVEAU_THERM_CTRL_NONE); 325 nouveau_therm_fan_mode(therm, NOUVEAU_THERM_CTRL_NONE);
326 nouveau_therm_sensor_preinit(therm);
321 return 0; 327 return 0;
322} 328}
323 329
diff --git a/drivers/gpu/drm/nouveau/core/subdev/therm/ic.c b/drivers/gpu/drm/nouveau/core/subdev/therm/ic.c
index e24090bac195..8b3adec5fbb1 100644
--- a/drivers/gpu/drm/nouveau/core/subdev/therm/ic.c
+++ b/drivers/gpu/drm/nouveau/core/subdev/therm/ic.c
@@ -32,6 +32,7 @@ probe_monitoring_device(struct nouveau_i2c_port *i2c,
32 struct i2c_board_info *info) 32 struct i2c_board_info *info)
33{ 33{
34 struct nouveau_therm_priv *priv = (void *)nouveau_therm(i2c); 34 struct nouveau_therm_priv *priv = (void *)nouveau_therm(i2c);
35 struct nvbios_therm_sensor *sensor = &priv->bios_sensor;
35 struct i2c_client *client; 36 struct i2c_client *client;
36 37
37 request_module("%s%s", I2C_MODULE_PREFIX, info->type); 38 request_module("%s%s", I2C_MODULE_PREFIX, info->type);
@@ -46,8 +47,9 @@ probe_monitoring_device(struct nouveau_i2c_port *i2c,
46 } 47 }
47 48
48 nv_info(priv, 49 nv_info(priv,
49 "Found an %s at address 0x%x (controlled by lm_sensors)\n", 50 "Found an %s at address 0x%x (controlled by lm_sensors, "
50 info->type, info->addr); 51 "temp offset %+i C)\n",
52 info->type, info->addr, sensor->offset_constant);
51 priv->ic = client; 53 priv->ic = client;
52 54
53 return true; 55 return true;
diff --git a/drivers/gpu/drm/nouveau/core/subdev/therm/nv40.c b/drivers/gpu/drm/nouveau/core/subdev/therm/nv40.c
index 0f5363edb964..a70d1b7e397b 100644
--- a/drivers/gpu/drm/nouveau/core/subdev/therm/nv40.c
+++ b/drivers/gpu/drm/nouveau/core/subdev/therm/nv40.c
@@ -29,54 +29,83 @@ struct nv40_therm_priv {
29 struct nouveau_therm_priv base; 29 struct nouveau_therm_priv base;
30}; 30};
31 31
32enum nv40_sensor_style { INVALID_STYLE = -1, OLD_STYLE = 0, NEW_STYLE = 1 };
33
34static enum nv40_sensor_style
35nv40_sensor_style(struct nouveau_therm *therm)
36{
37 struct nouveau_device *device = nv_device(therm);
38
39 switch (device->chipset) {
40 case 0x43:
41 case 0x44:
42 case 0x4a:
43 case 0x47:
44 return OLD_STYLE;
45
46 case 0x46:
47 case 0x49:
48 case 0x4b:
49 case 0x4e:
50 case 0x4c:
51 case 0x67:
52 case 0x68:
53 case 0x63:
54 return NEW_STYLE;
55 default:
56 return INVALID_STYLE;
57 }
58}
59
32static int 60static int
33nv40_sensor_setup(struct nouveau_therm *therm) 61nv40_sensor_setup(struct nouveau_therm *therm)
34{ 62{
35 struct nouveau_device *device = nv_device(therm); 63 enum nv40_sensor_style style = nv40_sensor_style(therm);
36 64
37 /* enable ADC readout and disable the ALARM threshold */ 65 /* enable ADC readout and disable the ALARM threshold */
38 if (device->chipset >= 0x46) { 66 if (style == NEW_STYLE) {
39 nv_mask(therm, 0x15b8, 0x80000000, 0); 67 nv_mask(therm, 0x15b8, 0x80000000, 0);
40 nv_wr32(therm, 0x15b0, 0x80003fff); 68 nv_wr32(therm, 0x15b0, 0x80003fff);
41 mdelay(10); /* wait for the temperature to stabilize */ 69 mdelay(20); /* wait for the temperature to stabilize */
42 return nv_rd32(therm, 0x15b4) & 0x3fff; 70 return nv_rd32(therm, 0x15b4) & 0x3fff;
43 } else { 71 } else if (style == OLD_STYLE) {
44 nv_wr32(therm, 0x15b0, 0xff); 72 nv_wr32(therm, 0x15b0, 0xff);
73 mdelay(20); /* wait for the temperature to stabilize */
45 return nv_rd32(therm, 0x15b4) & 0xff; 74 return nv_rd32(therm, 0x15b4) & 0xff;
46 } 75 } else
76 return -ENODEV;
47} 77}
48 78
49static int 79static int
50nv40_temp_get(struct nouveau_therm *therm) 80nv40_temp_get(struct nouveau_therm *therm)
51{ 81{
52 struct nouveau_therm_priv *priv = (void *)therm; 82 struct nouveau_therm_priv *priv = (void *)therm;
53 struct nouveau_device *device = nv_device(therm);
54 struct nvbios_therm_sensor *sensor = &priv->bios_sensor; 83 struct nvbios_therm_sensor *sensor = &priv->bios_sensor;
84 enum nv40_sensor_style style = nv40_sensor_style(therm);
55 int core_temp; 85 int core_temp;
56 86
57 if (device->chipset >= 0x46) { 87 if (style == NEW_STYLE) {
58 nv_wr32(therm, 0x15b0, 0x80003fff); 88 nv_wr32(therm, 0x15b0, 0x80003fff);
59 core_temp = nv_rd32(therm, 0x15b4) & 0x3fff; 89 core_temp = nv_rd32(therm, 0x15b4) & 0x3fff;
60 } else { 90 } else if (style == OLD_STYLE) {
61 nv_wr32(therm, 0x15b0, 0xff); 91 nv_wr32(therm, 0x15b0, 0xff);
62 core_temp = nv_rd32(therm, 0x15b4) & 0xff; 92 core_temp = nv_rd32(therm, 0x15b4) & 0xff;
63 } 93 } else
64 94 return -ENODEV;
65 /* Setup the sensor if the temperature is 0 */
66 if (core_temp == 0)
67 core_temp = nv40_sensor_setup(therm);
68 95
69 if (sensor->slope_div == 0) 96 /* if the slope or the offset is unset, do no use the sensor */
70 sensor->slope_div = 1; 97 if (!sensor->slope_div || !sensor->slope_mult ||
71 if (sensor->offset_den == 0) 98 !sensor->offset_num || !sensor->offset_den)
72 sensor->offset_den = 1; 99 return -ENODEV;
73 if (sensor->slope_mult < 1)
74 sensor->slope_mult = 1;
75 100
76 core_temp = core_temp * sensor->slope_mult / sensor->slope_div; 101 core_temp = core_temp * sensor->slope_mult / sensor->slope_div;
77 core_temp = core_temp + sensor->offset_num / sensor->offset_den; 102 core_temp = core_temp + sensor->offset_num / sensor->offset_den;
78 core_temp = core_temp + sensor->offset_constant - 8; 103 core_temp = core_temp + sensor->offset_constant - 8;
79 104
105 /* reserve negative temperatures for errors */
106 if (core_temp < 0)
107 core_temp = 0;
108
80 return core_temp; 109 return core_temp;
81} 110}
82 111
diff --git a/drivers/gpu/drm/nouveau/core/subdev/therm/priv.h b/drivers/gpu/drm/nouveau/core/subdev/therm/priv.h
index 06b98706b3fc..438d9824b774 100644
--- a/drivers/gpu/drm/nouveau/core/subdev/therm/priv.h
+++ b/drivers/gpu/drm/nouveau/core/subdev/therm/priv.h
@@ -102,7 +102,7 @@ struct nouveau_therm_priv {
102 struct i2c_client *ic; 102 struct i2c_client *ic;
103}; 103};
104 104
105int nouveau_therm_mode(struct nouveau_therm *therm, int mode); 105int nouveau_therm_fan_mode(struct nouveau_therm *therm, int mode);
106int nouveau_therm_attr_get(struct nouveau_therm *therm, 106int nouveau_therm_attr_get(struct nouveau_therm *therm,
107 enum nouveau_therm_attr_type type); 107 enum nouveau_therm_attr_type type);
108int nouveau_therm_attr_set(struct nouveau_therm *therm, 108int nouveau_therm_attr_set(struct nouveau_therm *therm,
@@ -122,6 +122,7 @@ int nouveau_therm_fan_sense(struct nouveau_therm *therm);
122 122
123int nouveau_therm_preinit(struct nouveau_therm *); 123int nouveau_therm_preinit(struct nouveau_therm *);
124 124
125void nouveau_therm_sensor_preinit(struct nouveau_therm *);
125void nouveau_therm_sensor_set_threshold_state(struct nouveau_therm *therm, 126void nouveau_therm_sensor_set_threshold_state(struct nouveau_therm *therm,
126 enum nouveau_therm_thrs thrs, 127 enum nouveau_therm_thrs thrs,
127 enum nouveau_therm_thrs_state st); 128 enum nouveau_therm_thrs_state st);
diff --git a/drivers/gpu/drm/nouveau/core/subdev/therm/temp.c b/drivers/gpu/drm/nouveau/core/subdev/therm/temp.c
index b37624af8297..470f6a47b656 100644
--- a/drivers/gpu/drm/nouveau/core/subdev/therm/temp.c
+++ b/drivers/gpu/drm/nouveau/core/subdev/therm/temp.c
@@ -34,10 +34,6 @@ nouveau_therm_temp_set_defaults(struct nouveau_therm *therm)
34{ 34{
35 struct nouveau_therm_priv *priv = (void *)therm; 35 struct nouveau_therm_priv *priv = (void *)therm;
36 36
37 priv->bios_sensor.slope_mult = 1;
38 priv->bios_sensor.slope_div = 1;
39 priv->bios_sensor.offset_num = 0;
40 priv->bios_sensor.offset_den = 1;
41 priv->bios_sensor.offset_constant = 0; 37 priv->bios_sensor.offset_constant = 0;
42 38
43 priv->bios_sensor.thrs_fan_boost.temp = 90; 39 priv->bios_sensor.thrs_fan_boost.temp = 90;
@@ -60,11 +56,6 @@ nouveau_therm_temp_safety_checks(struct nouveau_therm *therm)
60 struct nouveau_therm_priv *priv = (void *)therm; 56 struct nouveau_therm_priv *priv = (void *)therm;
61 struct nvbios_therm_sensor *s = &priv->bios_sensor; 57 struct nvbios_therm_sensor *s = &priv->bios_sensor;
62 58
63 if (!priv->bios_sensor.slope_div)
64 priv->bios_sensor.slope_div = 1;
65 if (!priv->bios_sensor.offset_den)
66 priv->bios_sensor.offset_den = 1;
67
68 /* enforce a minimum hysteresis on thresholds */ 59 /* enforce a minimum hysteresis on thresholds */
69 s->thrs_fan_boost.hysteresis = max_t(u8, s->thrs_fan_boost.hysteresis, 2); 60 s->thrs_fan_boost.hysteresis = max_t(u8, s->thrs_fan_boost.hysteresis, 2);
70 s->thrs_down_clock.hysteresis = max_t(u8, s->thrs_down_clock.hysteresis, 2); 61 s->thrs_down_clock.hysteresis = max_t(u8, s->thrs_down_clock.hysteresis, 2);
@@ -106,16 +97,16 @@ void nouveau_therm_sensor_event(struct nouveau_therm *therm,
106 const char *thresolds[] = { 97 const char *thresolds[] = {
107 "fanboost", "downclock", "critical", "shutdown" 98 "fanboost", "downclock", "critical", "shutdown"
108 }; 99 };
109 uint8_t temperature = therm->temp_get(therm); 100 int temperature = therm->temp_get(therm);
110 101
111 if (thrs < 0 || thrs > 3) 102 if (thrs < 0 || thrs > 3)
112 return; 103 return;
113 104
114 if (dir == NOUVEAU_THERM_THRS_FALLING) 105 if (dir == NOUVEAU_THERM_THRS_FALLING)
115 nv_info(therm, "temperature (%u C) went below the '%s' threshold\n", 106 nv_info(therm, "temperature (%i C) went below the '%s' threshold\n",
116 temperature, thresolds[thrs]); 107 temperature, thresolds[thrs]);
117 else 108 else
118 nv_info(therm, "temperature (%u C) hit the '%s' threshold\n", 109 nv_info(therm, "temperature (%i C) hit the '%s' threshold\n",
119 temperature, thresolds[thrs]); 110 temperature, thresolds[thrs]);
120 111
121 active = (dir == NOUVEAU_THERM_THRS_RISING); 112 active = (dir == NOUVEAU_THERM_THRS_RISING);
@@ -123,7 +114,7 @@ void nouveau_therm_sensor_event(struct nouveau_therm *therm,
123 case NOUVEAU_THERM_THRS_FANBOOST: 114 case NOUVEAU_THERM_THRS_FANBOOST:
124 if (active) { 115 if (active) {
125 nouveau_therm_fan_set(therm, true, 100); 116 nouveau_therm_fan_set(therm, true, 100);
126 nouveau_therm_mode(therm, NOUVEAU_THERM_CTRL_AUTO); 117 nouveau_therm_fan_mode(therm, NOUVEAU_THERM_CTRL_AUTO);
127 } 118 }
128 break; 119 break;
129 case NOUVEAU_THERM_THRS_DOWNCLOCK: 120 case NOUVEAU_THERM_THRS_DOWNCLOCK:
@@ -202,7 +193,7 @@ alarm_timer_callback(struct nouveau_alarm *alarm)
202 NOUVEAU_THERM_THRS_SHUTDOWN); 193 NOUVEAU_THERM_THRS_SHUTDOWN);
203 194
204 /* schedule the next poll in one second */ 195 /* schedule the next poll in one second */
205 if (list_empty(&alarm->head)) 196 if (therm->temp_get(therm) >= 0 && list_empty(&alarm->head))
206 ptimer->alarm(ptimer, 1000 * 1000 * 1000, alarm); 197 ptimer->alarm(ptimer, 1000 * 1000 * 1000, alarm);
207 198
208 spin_unlock_irqrestore(&priv->sensor.alarm_program_lock, flags); 199 spin_unlock_irqrestore(&priv->sensor.alarm_program_lock, flags);
@@ -225,6 +216,17 @@ nouveau_therm_program_alarms_polling(struct nouveau_therm *therm)
225 alarm_timer_callback(&priv->sensor.therm_poll_alarm); 216 alarm_timer_callback(&priv->sensor.therm_poll_alarm);
226} 217}
227 218
219void
220nouveau_therm_sensor_preinit(struct nouveau_therm *therm)
221{
222 const char *sensor_avail = "yes";
223
224 if (therm->temp_get(therm) < 0)
225 sensor_avail = "no";
226
227 nv_info(therm, "internal sensor: %s\n", sensor_avail);
228}
229
228int 230int
229nouveau_therm_sensor_ctor(struct nouveau_therm *therm) 231nouveau_therm_sensor_ctor(struct nouveau_therm *therm)
230{ 232{
diff --git a/drivers/gpu/drm/nouveau/nouveau_pm.c b/drivers/gpu/drm/nouveau/nouveau_pm.c
index bb54098c6d97..936b442a6ab7 100644
--- a/drivers/gpu/drm/nouveau/nouveau_pm.c
+++ b/drivers/gpu/drm/nouveau/nouveau_pm.c
@@ -402,8 +402,12 @@ nouveau_hwmon_show_temp(struct device *d, struct device_attribute *a, char *buf)
402 struct drm_device *dev = dev_get_drvdata(d); 402 struct drm_device *dev = dev_get_drvdata(d);
403 struct nouveau_drm *drm = nouveau_drm(dev); 403 struct nouveau_drm *drm = nouveau_drm(dev);
404 struct nouveau_therm *therm = nouveau_therm(drm->device); 404 struct nouveau_therm *therm = nouveau_therm(drm->device);
405 int temp = therm->temp_get(therm);
405 406
406 return snprintf(buf, PAGE_SIZE, "%d\n", therm->temp_get(therm) * 1000); 407 if (temp < 0)
408 return temp;
409
410 return snprintf(buf, PAGE_SIZE, "%d\n", temp * 1000);
407} 411}
408static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, nouveau_hwmon_show_temp, 412static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, nouveau_hwmon_show_temp,
409 NULL, 0); 413 NULL, 0);
@@ -871,7 +875,12 @@ static SENSOR_DEVICE_ATTR(pwm1_max, S_IRUGO | S_IWUSR,
871 nouveau_hwmon_get_pwm1_max, 875 nouveau_hwmon_get_pwm1_max,
872 nouveau_hwmon_set_pwm1_max, 0); 876 nouveau_hwmon_set_pwm1_max, 0);
873 877
874static struct attribute *hwmon_attributes[] = { 878static struct attribute *hwmon_default_attributes[] = {
879 &sensor_dev_attr_name.dev_attr.attr,
880 &sensor_dev_attr_update_rate.dev_attr.attr,
881 NULL
882};
883static struct attribute *hwmon_temp_attributes[] = {
875 &sensor_dev_attr_temp1_input.dev_attr.attr, 884 &sensor_dev_attr_temp1_input.dev_attr.attr,
876 &sensor_dev_attr_temp1_auto_point1_pwm.dev_attr.attr, 885 &sensor_dev_attr_temp1_auto_point1_pwm.dev_attr.attr,
877 &sensor_dev_attr_temp1_auto_point1_temp.dev_attr.attr, 886 &sensor_dev_attr_temp1_auto_point1_temp.dev_attr.attr,
@@ -882,8 +891,6 @@ static struct attribute *hwmon_attributes[] = {
882 &sensor_dev_attr_temp1_crit_hyst.dev_attr.attr, 891 &sensor_dev_attr_temp1_crit_hyst.dev_attr.attr,
883 &sensor_dev_attr_temp1_emergency.dev_attr.attr, 892 &sensor_dev_attr_temp1_emergency.dev_attr.attr,
884 &sensor_dev_attr_temp1_emergency_hyst.dev_attr.attr, 893 &sensor_dev_attr_temp1_emergency_hyst.dev_attr.attr,
885 &sensor_dev_attr_name.dev_attr.attr,
886 &sensor_dev_attr_update_rate.dev_attr.attr,
887 NULL 894 NULL
888}; 895};
889static struct attribute *hwmon_fan_rpm_attributes[] = { 896static struct attribute *hwmon_fan_rpm_attributes[] = {
@@ -898,8 +905,11 @@ static struct attribute *hwmon_pwm_fan_attributes[] = {
898 NULL 905 NULL
899}; 906};
900 907
901static const struct attribute_group hwmon_attrgroup = { 908static const struct attribute_group hwmon_default_attrgroup = {
902 .attrs = hwmon_attributes, 909 .attrs = hwmon_default_attributes,
910};
911static const struct attribute_group hwmon_temp_attrgroup = {
912 .attrs = hwmon_temp_attributes,
903}; 913};
904static const struct attribute_group hwmon_fan_rpm_attrgroup = { 914static const struct attribute_group hwmon_fan_rpm_attrgroup = {
905 .attrs = hwmon_fan_rpm_attributes, 915 .attrs = hwmon_fan_rpm_attributes,
@@ -931,13 +941,22 @@ nouveau_hwmon_init(struct drm_device *dev)
931 } 941 }
932 dev_set_drvdata(hwmon_dev, dev); 942 dev_set_drvdata(hwmon_dev, dev);
933 943
934 /* default sysfs entries */ 944 /* set the default attributes */
935 ret = sysfs_create_group(&hwmon_dev->kobj, &hwmon_attrgroup); 945 ret = sysfs_create_group(&hwmon_dev->kobj, &hwmon_default_attrgroup);
936 if (ret) { 946 if (ret) {
937 if (ret) 947 if (ret)
938 goto error; 948 goto error;
939 } 949 }
940 950
951 /* if the card has a working thermal sensor */
952 if (therm->temp_get(therm) >= 0) {
953 ret = sysfs_create_group(&hwmon_dev->kobj, &hwmon_temp_attrgroup);
954 if (ret) {
955 if (ret)
956 goto error;
957 }
958 }
959
941 /* if the card has a pwm fan */ 960 /* if the card has a pwm fan */
942 /*XXX: incorrect, need better detection for this, some boards have 961 /*XXX: incorrect, need better detection for this, some boards have
943 * the gpio entries for pwm fan control even when there's no 962 * the gpio entries for pwm fan control even when there's no
@@ -979,11 +998,10 @@ nouveau_hwmon_fini(struct drm_device *dev)
979 struct nouveau_pm *pm = nouveau_pm(dev); 998 struct nouveau_pm *pm = nouveau_pm(dev);
980 999
981 if (pm->hwmon) { 1000 if (pm->hwmon) {
982 sysfs_remove_group(&pm->hwmon->kobj, &hwmon_attrgroup); 1001 sysfs_remove_group(&pm->hwmon->kobj, &hwmon_default_attrgroup);
983 sysfs_remove_group(&pm->hwmon->kobj, 1002 sysfs_remove_group(&pm->hwmon->kobj, &hwmon_temp_attrgroup);
984 &hwmon_pwm_fan_attrgroup); 1003 sysfs_remove_group(&pm->hwmon->kobj, &hwmon_pwm_fan_attrgroup);
985 sysfs_remove_group(&pm->hwmon->kobj, 1004 sysfs_remove_group(&pm->hwmon->kobj, &hwmon_fan_rpm_attrgroup);
986 &hwmon_fan_rpm_attrgroup);
987 1005
988 hwmon_device_unregister(pm->hwmon); 1006 hwmon_device_unregister(pm->hwmon);
989 } 1007 }
diff --git a/drivers/gpu/drm/nouveau/nv50_display.c b/drivers/gpu/drm/nouveau/nv50_display.c
index 2db57990f65c..7f0e6c3f37d1 100644
--- a/drivers/gpu/drm/nouveau/nv50_display.c
+++ b/drivers/gpu/drm/nouveau/nv50_display.c
@@ -524,6 +524,8 @@ nv50_display_flip_next(struct drm_crtc *crtc, struct drm_framebuffer *fb,
524 swap_interval <<= 4; 524 swap_interval <<= 4;
525 if (swap_interval == 0) 525 if (swap_interval == 0)
526 swap_interval |= 0x100; 526 swap_interval |= 0x100;
527 if (chan == NULL)
528 evo_sync(crtc->dev);
527 529
528 push = evo_wait(sync, 128); 530 push = evo_wait(sync, 128);
529 if (unlikely(push == NULL)) 531 if (unlikely(push == NULL))
@@ -586,8 +588,6 @@ nv50_display_flip_next(struct drm_crtc *crtc, struct drm_framebuffer *fb,
586 sync->addr ^= 0x10; 588 sync->addr ^= 0x10;
587 sync->data++; 589 sync->data++;
588 FIRE_RING (chan); 590 FIRE_RING (chan);
589 } else {
590 evo_sync(crtc->dev);
591 } 591 }
592 592
593 /* queue the flip */ 593 /* queue the flip */
diff --git a/drivers/gpu/drm/radeon/ni.c b/drivers/gpu/drm/radeon/ni.c
index d4c633e12863..27769e724b6d 100644
--- a/drivers/gpu/drm/radeon/ni.c
+++ b/drivers/gpu/drm/radeon/ni.c
@@ -468,13 +468,19 @@ static void cayman_gpu_init(struct radeon_device *rdev)
468 (rdev->pdev->device == 0x9907) || 468 (rdev->pdev->device == 0x9907) ||
469 (rdev->pdev->device == 0x9908) || 469 (rdev->pdev->device == 0x9908) ||
470 (rdev->pdev->device == 0x9909) || 470 (rdev->pdev->device == 0x9909) ||
471 (rdev->pdev->device == 0x990B) ||
472 (rdev->pdev->device == 0x990C) ||
473 (rdev->pdev->device == 0x990F) ||
471 (rdev->pdev->device == 0x9910) || 474 (rdev->pdev->device == 0x9910) ||
472 (rdev->pdev->device == 0x9917)) { 475 (rdev->pdev->device == 0x9917) ||
476 (rdev->pdev->device == 0x9999)) {
473 rdev->config.cayman.max_simds_per_se = 6; 477 rdev->config.cayman.max_simds_per_se = 6;
474 rdev->config.cayman.max_backends_per_se = 2; 478 rdev->config.cayman.max_backends_per_se = 2;
475 } else if ((rdev->pdev->device == 0x9903) || 479 } else if ((rdev->pdev->device == 0x9903) ||
476 (rdev->pdev->device == 0x9904) || 480 (rdev->pdev->device == 0x9904) ||
477 (rdev->pdev->device == 0x990A) || 481 (rdev->pdev->device == 0x990A) ||
482 (rdev->pdev->device == 0x990D) ||
483 (rdev->pdev->device == 0x990E) ||
478 (rdev->pdev->device == 0x9913) || 484 (rdev->pdev->device == 0x9913) ||
479 (rdev->pdev->device == 0x9918)) { 485 (rdev->pdev->device == 0x9918)) {
480 rdev->config.cayman.max_simds_per_se = 4; 486 rdev->config.cayman.max_simds_per_se = 4;
@@ -483,6 +489,9 @@ static void cayman_gpu_init(struct radeon_device *rdev)
483 (rdev->pdev->device == 0x9990) || 489 (rdev->pdev->device == 0x9990) ||
484 (rdev->pdev->device == 0x9991) || 490 (rdev->pdev->device == 0x9991) ||
485 (rdev->pdev->device == 0x9994) || 491 (rdev->pdev->device == 0x9994) ||
492 (rdev->pdev->device == 0x9995) ||
493 (rdev->pdev->device == 0x9996) ||
494 (rdev->pdev->device == 0x999A) ||
486 (rdev->pdev->device == 0x99A0)) { 495 (rdev->pdev->device == 0x99A0)) {
487 rdev->config.cayman.max_simds_per_se = 3; 496 rdev->config.cayman.max_simds_per_se = 3;
488 rdev->config.cayman.max_backends_per_se = 1; 497 rdev->config.cayman.max_backends_per_se = 1;
@@ -616,11 +625,22 @@ static void cayman_gpu_init(struct radeon_device *rdev)
616 WREG32(DMA_TILING_CONFIG + DMA0_REGISTER_OFFSET, gb_addr_config); 625 WREG32(DMA_TILING_CONFIG + DMA0_REGISTER_OFFSET, gb_addr_config);
617 WREG32(DMA_TILING_CONFIG + DMA1_REGISTER_OFFSET, gb_addr_config); 626 WREG32(DMA_TILING_CONFIG + DMA1_REGISTER_OFFSET, gb_addr_config);
618 627
619 tmp = gb_addr_config & NUM_PIPES_MASK; 628 if ((rdev->config.cayman.max_backends_per_se == 1) &&
620 tmp = r6xx_remap_render_backend(rdev, tmp, 629 (rdev->flags & RADEON_IS_IGP)) {
621 rdev->config.cayman.max_backends_per_se * 630 if ((disabled_rb_mask & 3) == 1) {
622 rdev->config.cayman.max_shader_engines, 631 /* RB0 disabled, RB1 enabled */
623 CAYMAN_MAX_BACKENDS, disabled_rb_mask); 632 tmp = 0x11111111;
633 } else {
634 /* RB1 disabled, RB0 enabled */
635 tmp = 0x00000000;
636 }
637 } else {
638 tmp = gb_addr_config & NUM_PIPES_MASK;
639 tmp = r6xx_remap_render_backend(rdev, tmp,
640 rdev->config.cayman.max_backends_per_se *
641 rdev->config.cayman.max_shader_engines,
642 CAYMAN_MAX_BACKENDS, disabled_rb_mask);
643 }
624 WREG32(GB_BACKEND_MAP, tmp); 644 WREG32(GB_BACKEND_MAP, tmp);
625 645
626 cgts_tcc_disable = 0xffff0000; 646 cgts_tcc_disable = 0xffff0000;
@@ -1771,6 +1791,7 @@ int cayman_resume(struct radeon_device *rdev)
1771int cayman_suspend(struct radeon_device *rdev) 1791int cayman_suspend(struct radeon_device *rdev)
1772{ 1792{
1773 r600_audio_fini(rdev); 1793 r600_audio_fini(rdev);
1794 radeon_vm_manager_fini(rdev);
1774 cayman_cp_enable(rdev, false); 1795 cayman_cp_enable(rdev, false);
1775 cayman_dma_stop(rdev); 1796 cayman_dma_stop(rdev);
1776 evergreen_irq_suspend(rdev); 1797 evergreen_irq_suspend(rdev);
diff --git a/drivers/gpu/drm/radeon/radeon_benchmark.c b/drivers/gpu/drm/radeon/radeon_benchmark.c
index bedda9caadd9..6e05a2e75a46 100644
--- a/drivers/gpu/drm/radeon/radeon_benchmark.c
+++ b/drivers/gpu/drm/radeon/radeon_benchmark.c
@@ -122,10 +122,7 @@ static void radeon_benchmark_move(struct radeon_device *rdev, unsigned size,
122 goto out_cleanup; 122 goto out_cleanup;
123 } 123 }
124 124
125 /* r100 doesn't have dma engine so skip the test */ 125 if (rdev->asic->copy.dma) {
126 /* also, VRAM-to-VRAM test doesn't make much sense for DMA */
127 /* skip it as well if domains are the same */
128 if ((rdev->asic->copy.dma) && (sdomain != ddomain)) {
129 time = radeon_benchmark_do_move(rdev, size, saddr, daddr, 126 time = radeon_benchmark_do_move(rdev, size, saddr, daddr,
130 RADEON_BENCHMARK_COPY_DMA, n); 127 RADEON_BENCHMARK_COPY_DMA, n);
131 if (time < 0) 128 if (time < 0)
@@ -135,13 +132,15 @@ static void radeon_benchmark_move(struct radeon_device *rdev, unsigned size,
135 sdomain, ddomain, "dma"); 132 sdomain, ddomain, "dma");
136 } 133 }
137 134
138 time = radeon_benchmark_do_move(rdev, size, saddr, daddr, 135 if (rdev->asic->copy.blit) {
139 RADEON_BENCHMARK_COPY_BLIT, n); 136 time = radeon_benchmark_do_move(rdev, size, saddr, daddr,
140 if (time < 0) 137 RADEON_BENCHMARK_COPY_BLIT, n);
141 goto out_cleanup; 138 if (time < 0)
142 if (time > 0) 139 goto out_cleanup;
143 radeon_benchmark_log_results(n, size, time, 140 if (time > 0)
144 sdomain, ddomain, "blit"); 141 radeon_benchmark_log_results(n, size, time,
142 sdomain, ddomain, "blit");
143 }
145 144
146out_cleanup: 145out_cleanup:
147 if (sobj) { 146 if (sobj) {
diff --git a/drivers/gpu/drm/radeon/si.c b/drivers/gpu/drm/radeon/si.c
index 9128120da044..bafbe3216952 100644
--- a/drivers/gpu/drm/radeon/si.c
+++ b/drivers/gpu/drm/radeon/si.c
@@ -4469,6 +4469,7 @@ int si_resume(struct radeon_device *rdev)
4469 4469
4470int si_suspend(struct radeon_device *rdev) 4470int si_suspend(struct radeon_device *rdev)
4471{ 4471{
4472 radeon_vm_manager_fini(rdev);
4472 si_cp_enable(rdev, false); 4473 si_cp_enable(rdev, false);
4473 cayman_dma_stop(rdev); 4474 cayman_dma_stop(rdev);
4474 si_irq_suspend(rdev); 4475 si_irq_suspend(rdev);
diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
index 92e47e5c9564..c4388776f4e4 100644
--- a/drivers/hid/hid-ids.h
+++ b/drivers/hid/hid-ids.h
@@ -590,6 +590,9 @@
590#define USB_VENDOR_ID_MONTEREY 0x0566 590#define USB_VENDOR_ID_MONTEREY 0x0566
591#define USB_DEVICE_ID_GENIUS_KB29E 0x3004 591#define USB_DEVICE_ID_GENIUS_KB29E 0x3004
592 592
593#define USB_VENDOR_ID_MSI 0x1770
594#define USB_DEVICE_ID_MSI_GX680R_LED_PANEL 0xff00
595
593#define USB_VENDOR_ID_NATIONAL_SEMICONDUCTOR 0x0400 596#define USB_VENDOR_ID_NATIONAL_SEMICONDUCTOR 0x0400
594#define USB_DEVICE_ID_N_S_HARMONY 0xc359 597#define USB_DEVICE_ID_N_S_HARMONY 0xc359
595 598
@@ -684,6 +687,9 @@
684#define USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH_3001 0x3001 687#define USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH_3001 0x3001
685#define USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH_3008 0x3008 688#define USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH_3008 0x3008
686 689
690#define USB_VENDOR_ID_REALTEK 0x0bda
691#define USB_DEVICE_ID_REALTEK_READER 0x0152
692
687#define USB_VENDOR_ID_ROCCAT 0x1e7d 693#define USB_VENDOR_ID_ROCCAT 0x1e7d
688#define USB_DEVICE_ID_ROCCAT_ARVO 0x30d4 694#define USB_DEVICE_ID_ROCCAT_ARVO 0x30d4
689#define USB_DEVICE_ID_ROCCAT_ISKU 0x319c 695#define USB_DEVICE_ID_ROCCAT_ISKU 0x319c
diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c
index 7a1ebb867cf4..82e9211b3ca9 100644
--- a/drivers/hid/hid-multitouch.c
+++ b/drivers/hid/hid-multitouch.c
@@ -621,6 +621,7 @@ static void mt_process_mt_event(struct hid_device *hid, struct hid_field *field,
621{ 621{
622 struct mt_device *td = hid_get_drvdata(hid); 622 struct mt_device *td = hid_get_drvdata(hid);
623 __s32 quirks = td->mtclass.quirks; 623 __s32 quirks = td->mtclass.quirks;
624 struct input_dev *input = field->hidinput->input;
624 625
625 if (hid->claimed & HID_CLAIMED_INPUT) { 626 if (hid->claimed & HID_CLAIMED_INPUT) {
626 switch (usage->hid) { 627 switch (usage->hid) {
@@ -670,13 +671,16 @@ static void mt_process_mt_event(struct hid_device *hid, struct hid_field *field,
670 break; 671 break;
671 672
672 default: 673 default:
674 if (usage->type)
675 input_event(input, usage->type, usage->code,
676 value);
673 return; 677 return;
674 } 678 }
675 679
676 if (usage->usage_index + 1 == field->report_count) { 680 if (usage->usage_index + 1 == field->report_count) {
677 /* we only take into account the last report. */ 681 /* we only take into account the last report. */
678 if (usage->hid == td->last_slot_field) 682 if (usage->hid == td->last_slot_field)
679 mt_complete_slot(td, field->hidinput->input); 683 mt_complete_slot(td, input);
680 684
681 if (field->index == td->last_field_index 685 if (field->index == td->last_field_index
682 && td->num_received >= td->num_expected) 686 && td->num_received >= td->num_expected)
diff --git a/drivers/hid/usbhid/hid-quirks.c b/drivers/hid/usbhid/hid-quirks.c
index e0e6abf1cd3b..19b8360f2330 100644
--- a/drivers/hid/usbhid/hid-quirks.c
+++ b/drivers/hid/usbhid/hid-quirks.c
@@ -73,6 +73,7 @@ static const struct hid_blacklist {
73 { USB_VENDOR_ID_FORMOSA, USB_DEVICE_ID_FORMOSA_IR_RECEIVER, HID_QUIRK_NO_INIT_REPORTS }, 73 { USB_VENDOR_ID_FORMOSA, USB_DEVICE_ID_FORMOSA_IR_RECEIVER, HID_QUIRK_NO_INIT_REPORTS },
74 { USB_VENDOR_ID_FREESCALE, USB_DEVICE_ID_FREESCALE_MX28, HID_QUIRK_NOGET }, 74 { USB_VENDOR_ID_FREESCALE, USB_DEVICE_ID_FREESCALE_MX28, HID_QUIRK_NOGET },
75 { USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS, HID_QUIRK_NOGET }, 75 { USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS, HID_QUIRK_NOGET },
76 { USB_VENDOR_ID_MSI, USB_DEVICE_ID_MSI_GX680R_LED_PANEL, HID_QUIRK_NO_INIT_REPORTS },
76 { USB_VENDOR_ID_NOVATEK, USB_DEVICE_ID_NOVATEK_MOUSE, HID_QUIRK_NO_INIT_REPORTS }, 77 { USB_VENDOR_ID_NOVATEK, USB_DEVICE_ID_NOVATEK_MOUSE, HID_QUIRK_NO_INIT_REPORTS },
77 { USB_VENDOR_ID_PIXART, USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN, HID_QUIRK_NO_INIT_REPORTS }, 78 { USB_VENDOR_ID_PIXART, USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN, HID_QUIRK_NO_INIT_REPORTS },
78 { USB_VENDOR_ID_PIXART, USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN1, HID_QUIRK_NO_INIT_REPORTS }, 79 { USB_VENDOR_ID_PIXART, USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN1, HID_QUIRK_NO_INIT_REPORTS },
@@ -80,6 +81,7 @@ static const struct hid_blacklist {
80 { USB_VENDOR_ID_PRODIGE, USB_DEVICE_ID_PRODIGE_CORDLESS, HID_QUIRK_NOGET }, 81 { USB_VENDOR_ID_PRODIGE, USB_DEVICE_ID_PRODIGE_CORDLESS, HID_QUIRK_NOGET },
81 { USB_VENDOR_ID_QUANTA, USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH_3001, HID_QUIRK_NOGET }, 82 { USB_VENDOR_ID_QUANTA, USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH_3001, HID_QUIRK_NOGET },
82 { USB_VENDOR_ID_QUANTA, USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH_3008, HID_QUIRK_NOGET }, 83 { USB_VENDOR_ID_QUANTA, USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH_3008, HID_QUIRK_NOGET },
84 { USB_VENDOR_ID_REALTEK, USB_DEVICE_ID_REALTEK_READER, HID_QUIRK_NO_INIT_REPORTS },
83 { USB_VENDOR_ID_SENNHEISER, USB_DEVICE_ID_SENNHEISER_BTD500USB, HID_QUIRK_NOGET }, 85 { USB_VENDOR_ID_SENNHEISER, USB_DEVICE_ID_SENNHEISER_BTD500USB, HID_QUIRK_NOGET },
84 { USB_VENDOR_ID_SIGMATEL, USB_DEVICE_ID_SIGMATEL_STMP3780, HID_QUIRK_NOGET }, 86 { USB_VENDOR_ID_SIGMATEL, USB_DEVICE_ID_SIGMATEL_STMP3780, HID_QUIRK_NOGET },
85 { USB_VENDOR_ID_SUN, USB_DEVICE_ID_RARITAN_KVM_DONGLE, HID_QUIRK_NOGET }, 87 { USB_VENDOR_ID_SUN, USB_DEVICE_ID_RARITAN_KVM_DONGLE, HID_QUIRK_NOGET },
diff --git a/drivers/hwmon/lm75.h b/drivers/hwmon/lm75.h
index 668ff4721323..5cde94e56f17 100644
--- a/drivers/hwmon/lm75.h
+++ b/drivers/hwmon/lm75.h
@@ -25,7 +25,7 @@
25 which contains this code, we don't worry about the wasted space. 25 which contains this code, we don't worry about the wasted space.
26*/ 26*/
27 27
28#include <linux/hwmon.h> 28#include <linux/kernel.h>
29 29
30/* straight from the datasheet */ 30/* straight from the datasheet */
31#define LM75_TEMP_MIN (-55000) 31#define LM75_TEMP_MIN (-55000)
diff --git a/drivers/i2c/Kconfig b/drivers/i2c/Kconfig
index 46cde098c11c..e380c6eef3af 100644
--- a/drivers/i2c/Kconfig
+++ b/drivers/i2c/Kconfig
@@ -4,7 +4,6 @@
4 4
5menuconfig I2C 5menuconfig I2C
6 tristate "I2C support" 6 tristate "I2C support"
7 depends on !S390
8 select RT_MUTEXES 7 select RT_MUTEXES
9 ---help--- 8 ---help---
10 I2C (pronounce: I-squared-C) is a slow serial bus protocol used in 9 I2C (pronounce: I-squared-C) is a slow serial bus protocol used in
@@ -76,6 +75,7 @@ config I2C_HELPER_AUTO
76 75
77config I2C_SMBUS 76config I2C_SMBUS
78 tristate "SMBus-specific protocols" if !I2C_HELPER_AUTO 77 tristate "SMBus-specific protocols" if !I2C_HELPER_AUTO
78 depends on GENERIC_HARDIRQS
79 help 79 help
80 Say Y here if you want support for SMBus extensions to the I2C 80 Say Y here if you want support for SMBus extensions to the I2C
81 specification. At the moment, the only supported extension is 81 specification. At the moment, the only supported extension is
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index a3725de92384..adfee98486b1 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -114,7 +114,7 @@ config I2C_I801
114 114
115config I2C_ISCH 115config I2C_ISCH
116 tristate "Intel SCH SMBus 1.0" 116 tristate "Intel SCH SMBus 1.0"
117 depends on PCI 117 depends on PCI && GENERIC_HARDIRQS
118 select LPC_SCH 118 select LPC_SCH
119 help 119 help
120 Say Y here if you want to use SMBus controller on the Intel SCH 120 Say Y here if you want to use SMBus controller on the Intel SCH
@@ -543,6 +543,7 @@ config I2C_NUC900
543 543
544config I2C_OCORES 544config I2C_OCORES
545 tristate "OpenCores I2C Controller" 545 tristate "OpenCores I2C Controller"
546 depends on GENERIC_HARDIRQS
546 help 547 help
547 If you say yes to this option, support will be included for the 548 If you say yes to this option, support will be included for the
548 OpenCores I2C controller. For details see 549 OpenCores I2C controller. For details see
@@ -777,7 +778,7 @@ config I2C_DIOLAN_U2C
777 778
778config I2C_PARPORT 779config I2C_PARPORT
779 tristate "Parallel port adapter" 780 tristate "Parallel port adapter"
780 depends on PARPORT 781 depends on PARPORT && GENERIC_HARDIRQS
781 select I2C_ALGOBIT 782 select I2C_ALGOBIT
782 select I2C_SMBUS 783 select I2C_SMBUS
783 help 784 help
@@ -802,6 +803,7 @@ config I2C_PARPORT
802 803
803config I2C_PARPORT_LIGHT 804config I2C_PARPORT_LIGHT
804 tristate "Parallel port adapter (light)" 805 tristate "Parallel port adapter (light)"
806 depends on GENERIC_HARDIRQS
805 select I2C_ALGOBIT 807 select I2C_ALGOBIT
806 select I2C_SMBUS 808 select I2C_SMBUS
807 help 809 help
diff --git a/drivers/i2c/busses/i2c-ismt.c b/drivers/i2c/busses/i2c-ismt.c
index e9205ee8cf94..130f02cc9d94 100644
--- a/drivers/i2c/busses/i2c-ismt.c
+++ b/drivers/i2c/busses/i2c-ismt.c
@@ -80,6 +80,7 @@
80/* PCI DIDs for the Intel SMBus Message Transport (SMT) Devices */ 80/* PCI DIDs for the Intel SMBus Message Transport (SMT) Devices */
81#define PCI_DEVICE_ID_INTEL_S1200_SMT0 0x0c59 81#define PCI_DEVICE_ID_INTEL_S1200_SMT0 0x0c59
82#define PCI_DEVICE_ID_INTEL_S1200_SMT1 0x0c5a 82#define PCI_DEVICE_ID_INTEL_S1200_SMT1 0x0c5a
83#define PCI_DEVICE_ID_INTEL_AVOTON_SMT 0x1f15
83 84
84#define ISMT_DESC_ENTRIES 32 /* number of descriptor entries */ 85#define ISMT_DESC_ENTRIES 32 /* number of descriptor entries */
85#define ISMT_MAX_RETRIES 3 /* number of SMBus retries to attempt */ 86#define ISMT_MAX_RETRIES 3 /* number of SMBus retries to attempt */
@@ -185,6 +186,7 @@ struct ismt_priv {
185static const DEFINE_PCI_DEVICE_TABLE(ismt_ids) = { 186static const DEFINE_PCI_DEVICE_TABLE(ismt_ids) = {
186 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_S1200_SMT0) }, 187 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_S1200_SMT0) },
187 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_S1200_SMT1) }, 188 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_S1200_SMT1) },
189 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_AVOTON_SMT) },
188 { 0, } 190 { 0, }
189}; 191};
190 192
diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c
index 36704e3ab3fa..b714776b6ddd 100644
--- a/drivers/i2c/busses/i2c-tegra.c
+++ b/drivers/i2c/busses/i2c-tegra.c
@@ -411,7 +411,11 @@ static int tegra_i2c_init(struct tegra_i2c_dev *i2c_dev)
411 int clk_multiplier = I2C_CLK_MULTIPLIER_STD_FAST_MODE; 411 int clk_multiplier = I2C_CLK_MULTIPLIER_STD_FAST_MODE;
412 u32 clk_divisor; 412 u32 clk_divisor;
413 413
414 tegra_i2c_clock_enable(i2c_dev); 414 err = tegra_i2c_clock_enable(i2c_dev);
415 if (err < 0) {
416 dev_err(i2c_dev->dev, "Clock enable failed %d\n", err);
417 return err;
418 }
415 419
416 tegra_periph_reset_assert(i2c_dev->div_clk); 420 tegra_periph_reset_assert(i2c_dev->div_clk);
417 udelay(2); 421 udelay(2);
@@ -628,7 +632,12 @@ static int tegra_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[],
628 if (i2c_dev->is_suspended) 632 if (i2c_dev->is_suspended)
629 return -EBUSY; 633 return -EBUSY;
630 634
631 tegra_i2c_clock_enable(i2c_dev); 635 ret = tegra_i2c_clock_enable(i2c_dev);
636 if (ret < 0) {
637 dev_err(i2c_dev->dev, "Clock enable failed %d\n", ret);
638 return ret;
639 }
640
632 for (i = 0; i < num; i++) { 641 for (i = 0; i < num; i++) {
633 enum msg_end_type end_type = MSG_END_STOP; 642 enum msg_end_type end_type = MSG_END_STOP;
634 if (i < (num - 1)) { 643 if (i < (num - 1)) {
diff --git a/drivers/i2c/muxes/i2c-mux-pca9541.c b/drivers/i2c/muxes/i2c-mux-pca9541.c
index f3b8f9a6a89b..966a18a5d12d 100644
--- a/drivers/i2c/muxes/i2c-mux-pca9541.c
+++ b/drivers/i2c/muxes/i2c-mux-pca9541.c
@@ -3,7 +3,7 @@
3 * 3 *
4 * Copyright (c) 2010 Ericsson AB. 4 * Copyright (c) 2010 Ericsson AB.
5 * 5 *
6 * Author: Guenter Roeck <guenter.roeck@ericsson.com> 6 * Author: Guenter Roeck <linux@roeck-us.net>
7 * 7 *
8 * Derived from: 8 * Derived from:
9 * pca954x.c 9 * pca954x.c
diff --git a/drivers/infiniband/hw/cxgb4/cm.c b/drivers/infiniband/hw/cxgb4/cm.c
index 565bfb161c1a..a3fde52840ca 100644
--- a/drivers/infiniband/hw/cxgb4/cm.c
+++ b/drivers/infiniband/hw/cxgb4/cm.c
@@ -1575,6 +1575,12 @@ static int c4iw_reconnect(struct c4iw_ep *ep)
1575 1575
1576 neigh = dst_neigh_lookup(ep->dst, 1576 neigh = dst_neigh_lookup(ep->dst,
1577 &ep->com.cm_id->remote_addr.sin_addr.s_addr); 1577 &ep->com.cm_id->remote_addr.sin_addr.s_addr);
1578 if (!neigh) {
1579 pr_err("%s - cannot alloc neigh.\n", __func__);
1580 err = -ENOMEM;
1581 goto fail4;
1582 }
1583
1578 /* get a l2t entry */ 1584 /* get a l2t entry */
1579 if (neigh->dev->flags & IFF_LOOPBACK) { 1585 if (neigh->dev->flags & IFF_LOOPBACK) {
1580 PDBG("%s LOOPBACK\n", __func__); 1586 PDBG("%s LOOPBACK\n", __func__);
@@ -3053,6 +3059,12 @@ static int rx_pkt(struct c4iw_dev *dev, struct sk_buff *skb)
3053 dst = &rt->dst; 3059 dst = &rt->dst;
3054 neigh = dst_neigh_lookup_skb(dst, skb); 3060 neigh = dst_neigh_lookup_skb(dst, skb);
3055 3061
3062 if (!neigh) {
3063 pr_err("%s - failed to allocate neigh!\n",
3064 __func__);
3065 goto free_dst;
3066 }
3067
3056 if (neigh->dev->flags & IFF_LOOPBACK) { 3068 if (neigh->dev->flags & IFF_LOOPBACK) {
3057 pdev = ip_dev_find(&init_net, iph->daddr); 3069 pdev = ip_dev_find(&init_net, iph->daddr);
3058 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh, 3070 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
diff --git a/drivers/infiniband/hw/cxgb4/qp.c b/drivers/infiniband/hw/cxgb4/qp.c
index 17ba4f8bc12d..70b1808a08f4 100644
--- a/drivers/infiniband/hw/cxgb4/qp.c
+++ b/drivers/infiniband/hw/cxgb4/qp.c
@@ -186,8 +186,10 @@ static int create_qp(struct c4iw_rdev *rdev, struct t4_wq *wq,
186 wq->rq.queue = dma_alloc_coherent(&(rdev->lldi.pdev->dev), 186 wq->rq.queue = dma_alloc_coherent(&(rdev->lldi.pdev->dev),
187 wq->rq.memsize, &(wq->rq.dma_addr), 187 wq->rq.memsize, &(wq->rq.dma_addr),
188 GFP_KERNEL); 188 GFP_KERNEL);
189 if (!wq->rq.queue) 189 if (!wq->rq.queue) {
190 ret = -ENOMEM;
190 goto free_sq; 191 goto free_sq;
192 }
191 PDBG("%s sq base va 0x%p pa 0x%llx rq base va 0x%p pa 0x%llx\n", 193 PDBG("%s sq base va 0x%p pa 0x%llx rq base va 0x%p pa 0x%llx\n",
192 __func__, wq->sq.queue, 194 __func__, wq->sq.queue,
193 (unsigned long long)virt_to_phys(wq->sq.queue), 195 (unsigned long long)virt_to_phys(wq->sq.queue),
diff --git a/drivers/infiniband/hw/ipath/ipath_verbs.c b/drivers/infiniband/hw/ipath/ipath_verbs.c
index 439c35d4a669..ea93870266eb 100644
--- a/drivers/infiniband/hw/ipath/ipath_verbs.c
+++ b/drivers/infiniband/hw/ipath/ipath_verbs.c
@@ -620,7 +620,7 @@ void ipath_ib_rcv(struct ipath_ibdev *dev, void *rhdr, void *data,
620 goto bail; 620 goto bail;
621 } 621 }
622 622
623 opcode = be32_to_cpu(ohdr->bth[0]) >> 24; 623 opcode = (be32_to_cpu(ohdr->bth[0]) >> 24) & 0x7f;
624 dev->opstats[opcode].n_bytes += tlen; 624 dev->opstats[opcode].n_bytes += tlen;
625 dev->opstats[opcode].n_packets++; 625 dev->opstats[opcode].n_packets++;
626 626
diff --git a/drivers/infiniband/hw/qib/Kconfig b/drivers/infiniband/hw/qib/Kconfig
index 8349f9c5064c..1e603a375069 100644
--- a/drivers/infiniband/hw/qib/Kconfig
+++ b/drivers/infiniband/hw/qib/Kconfig
@@ -1,7 +1,7 @@
1config INFINIBAND_QIB 1config INFINIBAND_QIB
2 tristate "QLogic PCIe HCA support" 2 tristate "Intel PCIe HCA support"
3 depends on 64BIT 3 depends on 64BIT
4 ---help--- 4 ---help---
5 This is a low-level driver for QLogic PCIe QLE InfiniBand host 5 This is a low-level driver for Intel PCIe QLE InfiniBand host
6 channel adapters. This driver does not support the QLogic 6 channel adapters. This driver does not support the Intel
7 HyperTransport card (model QHT7140). 7 HyperTransport card (model QHT7140).
diff --git a/drivers/infiniband/hw/qib/qib_driver.c b/drivers/infiniband/hw/qib/qib_driver.c
index 5423edcab51f..216092477dfc 100644
--- a/drivers/infiniband/hw/qib/qib_driver.c
+++ b/drivers/infiniband/hw/qib/qib_driver.c
@@ -1,4 +1,5 @@
1/* 1/*
2 * Copyright (c) 2013 Intel Corporation. All rights reserved.
2 * Copyright (c) 2006, 2007, 2008, 2009 QLogic Corporation. All rights reserved. 3 * Copyright (c) 2006, 2007, 2008, 2009 QLogic Corporation. All rights reserved.
3 * Copyright (c) 2003, 2004, 2005, 2006 PathScale, Inc. All rights reserved. 4 * Copyright (c) 2003, 2004, 2005, 2006 PathScale, Inc. All rights reserved.
4 * 5 *
@@ -63,8 +64,8 @@ MODULE_PARM_DESC(compat_ddr_negotiate,
63 "Attempt pre-IBTA 1.2 DDR speed negotiation"); 64 "Attempt pre-IBTA 1.2 DDR speed negotiation");
64 65
65MODULE_LICENSE("Dual BSD/GPL"); 66MODULE_LICENSE("Dual BSD/GPL");
66MODULE_AUTHOR("QLogic <support@qlogic.com>"); 67MODULE_AUTHOR("Intel <ibsupport@intel.com>");
67MODULE_DESCRIPTION("QLogic IB driver"); 68MODULE_DESCRIPTION("Intel IB driver");
68MODULE_VERSION(QIB_DRIVER_VERSION); 69MODULE_VERSION(QIB_DRIVER_VERSION);
69 70
70/* 71/*
diff --git a/drivers/infiniband/hw/qib/qib_iba6120.c b/drivers/infiniband/hw/qib/qib_iba6120.c
index a099ac171e22..0232ae56b1fa 100644
--- a/drivers/infiniband/hw/qib/qib_iba6120.c
+++ b/drivers/infiniband/hw/qib/qib_iba6120.c
@@ -1,4 +1,5 @@
1/* 1/*
2 * Copyright (c) 2013 Intel Corporation. All rights reserved.
2 * Copyright (c) 2006, 2007, 2008, 2009, 2010 QLogic Corporation. 3 * Copyright (c) 2006, 2007, 2008, 2009, 2010 QLogic Corporation.
3 * All rights reserved. 4 * All rights reserved.
4 * Copyright (c) 2003, 2004, 2005, 2006 PathScale, Inc. All rights reserved. 5 * Copyright (c) 2003, 2004, 2005, 2006 PathScale, Inc. All rights reserved.
@@ -51,7 +52,7 @@ static u32 qib_6120_iblink_state(u64);
51 52
52/* 53/*
53 * This file contains all the chip-specific register information and 54 * This file contains all the chip-specific register information and
54 * access functions for the QLogic QLogic_IB PCI-Express chip. 55 * access functions for the Intel Intel_IB PCI-Express chip.
55 * 56 *
56 */ 57 */
57 58
diff --git a/drivers/infiniband/hw/qib/qib_init.c b/drivers/infiniband/hw/qib/qib_init.c
index 50e33aa0b4e3..173f805790da 100644
--- a/drivers/infiniband/hw/qib/qib_init.c
+++ b/drivers/infiniband/hw/qib/qib_init.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2012 Intel Corporation. All rights reserved. 2 * Copyright (c) 2012, 2013 Intel Corporation. All rights reserved.
3 * Copyright (c) 2006 - 2012 QLogic Corporation. All rights reserved. 3 * Copyright (c) 2006 - 2012 QLogic Corporation. All rights reserved.
4 * Copyright (c) 2003, 2004, 2005, 2006 PathScale, Inc. All rights reserved. 4 * Copyright (c) 2003, 2004, 2005, 2006 PathScale, Inc. All rights reserved.
5 * 5 *
@@ -1138,7 +1138,7 @@ void qib_disable_after_error(struct qib_devdata *dd)
1138static void qib_remove_one(struct pci_dev *); 1138static void qib_remove_one(struct pci_dev *);
1139static int qib_init_one(struct pci_dev *, const struct pci_device_id *); 1139static int qib_init_one(struct pci_dev *, const struct pci_device_id *);
1140 1140
1141#define DRIVER_LOAD_MSG "QLogic " QIB_DRV_NAME " loaded: " 1141#define DRIVER_LOAD_MSG "Intel " QIB_DRV_NAME " loaded: "
1142#define PFX QIB_DRV_NAME ": " 1142#define PFX QIB_DRV_NAME ": "
1143 1143
1144static DEFINE_PCI_DEVICE_TABLE(qib_pci_tbl) = { 1144static DEFINE_PCI_DEVICE_TABLE(qib_pci_tbl) = {
@@ -1355,7 +1355,7 @@ static int qib_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
1355 dd = qib_init_iba6120_funcs(pdev, ent); 1355 dd = qib_init_iba6120_funcs(pdev, ent);
1356#else 1356#else
1357 qib_early_err(&pdev->dev, 1357 qib_early_err(&pdev->dev,
1358 "QLogic PCIE device 0x%x cannot work if CONFIG_PCI_MSI is not enabled\n", 1358 "Intel PCIE device 0x%x cannot work if CONFIG_PCI_MSI is not enabled\n",
1359 ent->device); 1359 ent->device);
1360 dd = ERR_PTR(-ENODEV); 1360 dd = ERR_PTR(-ENODEV);
1361#endif 1361#endif
@@ -1371,7 +1371,7 @@ static int qib_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
1371 1371
1372 default: 1372 default:
1373 qib_early_err(&pdev->dev, 1373 qib_early_err(&pdev->dev,
1374 "Failing on unknown QLogic deviceid 0x%x\n", 1374 "Failing on unknown Intel deviceid 0x%x\n",
1375 ent->device); 1375 ent->device);
1376 ret = -ENODEV; 1376 ret = -ENODEV;
1377 } 1377 }
diff --git a/drivers/infiniband/hw/qib/qib_sd7220.c b/drivers/infiniband/hw/qib/qib_sd7220.c
index 50a8a0d4fe67..08a6c6d39e56 100644
--- a/drivers/infiniband/hw/qib/qib_sd7220.c
+++ b/drivers/infiniband/hw/qib/qib_sd7220.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2012 Intel Corporation. All rights reserved. 2 * Copyright (c) 2013 Intel Corporation. All rights reserved.
3 * Copyright (c) 2006 - 2012 QLogic Corporation. All rights reserved. 3 * Copyright (c) 2006 - 2012 QLogic Corporation. All rights reserved.
4 * Copyright (c) 2003, 2004, 2005, 2006 PathScale, Inc. All rights reserved. 4 * Copyright (c) 2003, 2004, 2005, 2006 PathScale, Inc. All rights reserved.
5 * 5 *
@@ -44,7 +44,7 @@
44#include "qib.h" 44#include "qib.h"
45#include "qib_7220.h" 45#include "qib_7220.h"
46 46
47#define SD7220_FW_NAME "qlogic/sd7220.fw" 47#define SD7220_FW_NAME "intel/sd7220.fw"
48MODULE_FIRMWARE(SD7220_FW_NAME); 48MODULE_FIRMWARE(SD7220_FW_NAME);
49 49
50/* 50/*
diff --git a/drivers/infiniband/hw/qib/qib_verbs.c b/drivers/infiniband/hw/qib/qib_verbs.c
index ba51a4715a1d..7c0ab16a2fe2 100644
--- a/drivers/infiniband/hw/qib/qib_verbs.c
+++ b/drivers/infiniband/hw/qib/qib_verbs.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2012 Intel Corporation. All rights reserved. 2 * Copyright (c) 2012, 2013 Intel Corporation. All rights reserved.
3 * Copyright (c) 2006 - 2012 QLogic Corporation. All rights reserved. 3 * Copyright (c) 2006 - 2012 QLogic Corporation. All rights reserved.
4 * Copyright (c) 2005, 2006 PathScale, Inc. All rights reserved. 4 * Copyright (c) 2005, 2006 PathScale, Inc. All rights reserved.
5 * 5 *
@@ -2224,7 +2224,7 @@ int qib_register_ib_device(struct qib_devdata *dd)
2224 ibdev->dma_ops = &qib_dma_mapping_ops; 2224 ibdev->dma_ops = &qib_dma_mapping_ops;
2225 2225
2226 snprintf(ibdev->node_desc, sizeof(ibdev->node_desc), 2226 snprintf(ibdev->node_desc, sizeof(ibdev->node_desc),
2227 "QLogic Infiniband HCA %s", init_utsname()->nodename); 2227 "Intel Infiniband HCA %s", init_utsname()->nodename);
2228 2228
2229 ret = ib_register_device(ibdev, qib_create_port_files); 2229 ret = ib_register_device(ibdev, qib_create_port_files);
2230 if (ret) 2230 if (ret)
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_cm.c b/drivers/infiniband/ulp/ipoib/ipoib_cm.c
index 67b0c1d23678..1ef880de3a41 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_cm.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_cm.c
@@ -758,9 +758,13 @@ void ipoib_cm_send(struct net_device *dev, struct sk_buff *skb, struct ipoib_cm_
758 if (++priv->tx_outstanding == ipoib_sendq_size) { 758 if (++priv->tx_outstanding == ipoib_sendq_size) {
759 ipoib_dbg(priv, "TX ring 0x%x full, stopping kernel net queue\n", 759 ipoib_dbg(priv, "TX ring 0x%x full, stopping kernel net queue\n",
760 tx->qp->qp_num); 760 tx->qp->qp_num);
761 if (ib_req_notify_cq(priv->send_cq, IB_CQ_NEXT_COMP))
762 ipoib_warn(priv, "request notify on send CQ failed\n");
763 netif_stop_queue(dev); 761 netif_stop_queue(dev);
762 rc = ib_req_notify_cq(priv->send_cq,
763 IB_CQ_NEXT_COMP | IB_CQ_REPORT_MISSED_EVENTS);
764 if (rc < 0)
765 ipoib_warn(priv, "request notify on send CQ failed\n");
766 else if (rc)
767 ipoib_send_comp_handler(priv->send_cq, dev);
764 } 768 }
765 } 769 }
766} 770}
diff --git a/drivers/input/joystick/analog.c b/drivers/input/joystick/analog.c
index 7cd74e29cbc8..9135606c8649 100644
--- a/drivers/input/joystick/analog.c
+++ b/drivers/input/joystick/analog.c
@@ -158,14 +158,10 @@ static unsigned int get_time_pit(void)
158#define GET_TIME(x) rdtscl(x) 158#define GET_TIME(x) rdtscl(x)
159#define DELTA(x,y) ((y)-(x)) 159#define DELTA(x,y) ((y)-(x))
160#define TIME_NAME "TSC" 160#define TIME_NAME "TSC"
161#elif defined(__alpha__) 161#elif defined(__alpha__) || defined(CONFIG_MN10300) || defined(CONFIG_ARM) || defined(CONFIG_TILE)
162#define GET_TIME(x) do { x = get_cycles(); } while (0) 162#define GET_TIME(x) do { x = get_cycles(); } while (0)
163#define DELTA(x,y) ((y)-(x)) 163#define DELTA(x,y) ((y)-(x))
164#define TIME_NAME "PCC" 164#define TIME_NAME "get_cycles"
165#elif defined(CONFIG_MN10300) || defined(CONFIG_TILE)
166#define GET_TIME(x) do { x = get_cycles(); } while (0)
167#define DELTA(x, y) ((x) - (y))
168#define TIME_NAME "TSC"
169#else 165#else
170#define FAKE_TIME 166#define FAKE_TIME
171static unsigned long analog_faketime = 0; 167static unsigned long analog_faketime = 0;
diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig
index 5c514d0711d1..c332fb98480d 100644
--- a/drivers/iommu/Kconfig
+++ b/drivers/iommu/Kconfig
@@ -130,7 +130,7 @@ config IRQ_REMAP
130# OMAP IOMMU support 130# OMAP IOMMU support
131config OMAP_IOMMU 131config OMAP_IOMMU
132 bool "OMAP IOMMU Support" 132 bool "OMAP IOMMU Support"
133 depends on ARCH_OMAP 133 depends on ARCH_OMAP2PLUS
134 select IOMMU_API 134 select IOMMU_API
135 135
136config OMAP_IOVMM 136config OMAP_IOVMM
diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
index 98f555dafb55..b287ca33833d 100644
--- a/drivers/iommu/amd_iommu.c
+++ b/drivers/iommu/amd_iommu.c
@@ -2466,18 +2466,16 @@ static int device_change_notifier(struct notifier_block *nb,
2466 2466
2467 /* allocate a protection domain if a device is added */ 2467 /* allocate a protection domain if a device is added */
2468 dma_domain = find_protection_domain(devid); 2468 dma_domain = find_protection_domain(devid);
2469 if (dma_domain) 2469 if (!dma_domain) {
2470 goto out; 2470 dma_domain = dma_ops_domain_alloc();
2471 dma_domain = dma_ops_domain_alloc(); 2471 if (!dma_domain)
2472 if (!dma_domain) 2472 goto out;
2473 goto out; 2473 dma_domain->target_dev = devid;
2474 dma_domain->target_dev = devid; 2474
2475 2475 spin_lock_irqsave(&iommu_pd_list_lock, flags);
2476 spin_lock_irqsave(&iommu_pd_list_lock, flags); 2476 list_add_tail(&dma_domain->list, &iommu_pd_list);
2477 list_add_tail(&dma_domain->list, &iommu_pd_list); 2477 spin_unlock_irqrestore(&iommu_pd_list_lock, flags);
2478 spin_unlock_irqrestore(&iommu_pd_list_lock, flags); 2478 }
2479
2480 dev_data = get_dev_data(dev);
2481 2479
2482 dev->archdata.dma_ops = &amd_iommu_dma_ops; 2480 dev->archdata.dma_ops = &amd_iommu_dma_ops;
2483 2481
diff --git a/drivers/iommu/amd_iommu_init.c b/drivers/iommu/amd_iommu_init.c
index b6ecddb63cd0..e3c2d74b7684 100644
--- a/drivers/iommu/amd_iommu_init.c
+++ b/drivers/iommu/amd_iommu_init.c
@@ -980,7 +980,7 @@ static void __init free_iommu_all(void)
980 * BIOS should disable L2B micellaneous clock gating by setting 980 * BIOS should disable L2B micellaneous clock gating by setting
981 * L2_L2B_CK_GATE_CONTROL[CKGateL2BMiscDisable](D0F2xF4_x90[2]) = 1b 981 * L2_L2B_CK_GATE_CONTROL[CKGateL2BMiscDisable](D0F2xF4_x90[2]) = 1b
982 */ 982 */
983static void __init amd_iommu_erratum_746_workaround(struct amd_iommu *iommu) 983static void amd_iommu_erratum_746_workaround(struct amd_iommu *iommu)
984{ 984{
985 u32 value; 985 u32 value;
986 986
diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
index d56f8c17c5fe..7c11ff368d07 100644
--- a/drivers/iommu/irq_remapping.c
+++ b/drivers/iommu/irq_remapping.c
@@ -2,7 +2,6 @@
2#include <linux/cpumask.h> 2#include <linux/cpumask.h>
3#include <linux/kernel.h> 3#include <linux/kernel.h>
4#include <linux/string.h> 4#include <linux/string.h>
5#include <linux/cpumask.h>
6#include <linux/errno.h> 5#include <linux/errno.h>
7#include <linux/msi.h> 6#include <linux/msi.h>
8#include <linux/irq.h> 7#include <linux/irq.h>
diff --git a/drivers/isdn/hisax/Kconfig b/drivers/isdn/hisax/Kconfig
index 5313c9ea44dc..d9edcc94c2a8 100644
--- a/drivers/isdn/hisax/Kconfig
+++ b/drivers/isdn/hisax/Kconfig
@@ -237,7 +237,8 @@ config HISAX_MIC
237 237
238config HISAX_NETJET 238config HISAX_NETJET
239 bool "NETjet card" 239 bool "NETjet card"
240 depends on PCI && (BROKEN || !(SPARC || PPC || PARISC || M68K || (MIPS && !CPU_LITTLE_ENDIAN) || FRV || (XTENSA && !CPU_LITTLE_ENDIAN))) 240 depends on PCI && (BROKEN || !(PPC || PARISC || M68K || (MIPS && !CPU_LITTLE_ENDIAN) || FRV || (XTENSA && !CPU_LITTLE_ENDIAN)))
241 depends on VIRT_TO_BUS
241 help 242 help
242 This enables HiSax support for the NetJet from Traverse 243 This enables HiSax support for the NetJet from Traverse
243 Technologies. 244 Technologies.
@@ -248,7 +249,8 @@ config HISAX_NETJET
248 249
249config HISAX_NETJET_U 250config HISAX_NETJET_U
250 bool "NETspider U card" 251 bool "NETspider U card"
251 depends on PCI && (BROKEN || !(SPARC || PPC || PARISC || M68K || (MIPS && !CPU_LITTLE_ENDIAN) || FRV || (XTENSA && !CPU_LITTLE_ENDIAN))) 252 depends on PCI && (BROKEN || !(PPC || PARISC || M68K || (MIPS && !CPU_LITTLE_ENDIAN) || FRV || (XTENSA && !CPU_LITTLE_ENDIAN)))
253 depends on VIRT_TO_BUS
252 help 254 help
253 This enables HiSax support for the Netspider U interface ISDN card 255 This enables HiSax support for the Netspider U interface ISDN card
254 from Traverse Technologies. 256 from Traverse Technologies.
diff --git a/drivers/md/dm-bufio.c b/drivers/md/dm-bufio.c
index 3c955e10a618..c6083132c4b8 100644
--- a/drivers/md/dm-bufio.c
+++ b/drivers/md/dm-bufio.c
@@ -1025,6 +1025,8 @@ void dm_bufio_prefetch(struct dm_bufio_client *c,
1025{ 1025{
1026 struct blk_plug plug; 1026 struct blk_plug plug;
1027 1027
1028 BUG_ON(dm_bufio_in_request());
1029
1028 blk_start_plug(&plug); 1030 blk_start_plug(&plug);
1029 dm_bufio_lock(c); 1031 dm_bufio_lock(c);
1030 1032
diff --git a/drivers/md/dm-cache-metadata.c b/drivers/md/dm-cache-metadata.c
index fbd3625f2748..83e995fece88 100644
--- a/drivers/md/dm-cache-metadata.c
+++ b/drivers/md/dm-cache-metadata.c
@@ -83,6 +83,8 @@ struct cache_disk_superblock {
83 __le32 read_misses; 83 __le32 read_misses;
84 __le32 write_hits; 84 __le32 write_hits;
85 __le32 write_misses; 85 __le32 write_misses;
86
87 __le32 policy_version[CACHE_POLICY_VERSION_SIZE];
86} __packed; 88} __packed;
87 89
88struct dm_cache_metadata { 90struct dm_cache_metadata {
@@ -109,6 +111,7 @@ struct dm_cache_metadata {
109 bool clean_when_opened:1; 111 bool clean_when_opened:1;
110 112
111 char policy_name[CACHE_POLICY_NAME_SIZE]; 113 char policy_name[CACHE_POLICY_NAME_SIZE];
114 unsigned policy_version[CACHE_POLICY_VERSION_SIZE];
112 size_t policy_hint_size; 115 size_t policy_hint_size;
113 struct dm_cache_statistics stats; 116 struct dm_cache_statistics stats;
114}; 117};
@@ -268,7 +271,8 @@ static int __write_initial_superblock(struct dm_cache_metadata *cmd)
268 memset(disk_super->uuid, 0, sizeof(disk_super->uuid)); 271 memset(disk_super->uuid, 0, sizeof(disk_super->uuid));
269 disk_super->magic = cpu_to_le64(CACHE_SUPERBLOCK_MAGIC); 272 disk_super->magic = cpu_to_le64(CACHE_SUPERBLOCK_MAGIC);
270 disk_super->version = cpu_to_le32(CACHE_VERSION); 273 disk_super->version = cpu_to_le32(CACHE_VERSION);
271 memset(disk_super->policy_name, 0, CACHE_POLICY_NAME_SIZE); 274 memset(disk_super->policy_name, 0, sizeof(disk_super->policy_name));
275 memset(disk_super->policy_version, 0, sizeof(disk_super->policy_version));
272 disk_super->policy_hint_size = 0; 276 disk_super->policy_hint_size = 0;
273 277
274 r = dm_sm_copy_root(cmd->metadata_sm, &disk_super->metadata_space_map_root, 278 r = dm_sm_copy_root(cmd->metadata_sm, &disk_super->metadata_space_map_root,
@@ -284,7 +288,6 @@ static int __write_initial_superblock(struct dm_cache_metadata *cmd)
284 disk_super->metadata_block_size = cpu_to_le32(DM_CACHE_METADATA_BLOCK_SIZE >> SECTOR_SHIFT); 288 disk_super->metadata_block_size = cpu_to_le32(DM_CACHE_METADATA_BLOCK_SIZE >> SECTOR_SHIFT);
285 disk_super->data_block_size = cpu_to_le32(cmd->data_block_size); 289 disk_super->data_block_size = cpu_to_le32(cmd->data_block_size);
286 disk_super->cache_blocks = cpu_to_le32(0); 290 disk_super->cache_blocks = cpu_to_le32(0);
287 memset(disk_super->policy_name, 0, sizeof(disk_super->policy_name));
288 291
289 disk_super->read_hits = cpu_to_le32(0); 292 disk_super->read_hits = cpu_to_le32(0);
290 disk_super->read_misses = cpu_to_le32(0); 293 disk_super->read_misses = cpu_to_le32(0);
@@ -478,6 +481,9 @@ static void read_superblock_fields(struct dm_cache_metadata *cmd,
478 cmd->data_block_size = le32_to_cpu(disk_super->data_block_size); 481 cmd->data_block_size = le32_to_cpu(disk_super->data_block_size);
479 cmd->cache_blocks = to_cblock(le32_to_cpu(disk_super->cache_blocks)); 482 cmd->cache_blocks = to_cblock(le32_to_cpu(disk_super->cache_blocks));
480 strncpy(cmd->policy_name, disk_super->policy_name, sizeof(cmd->policy_name)); 483 strncpy(cmd->policy_name, disk_super->policy_name, sizeof(cmd->policy_name));
484 cmd->policy_version[0] = le32_to_cpu(disk_super->policy_version[0]);
485 cmd->policy_version[1] = le32_to_cpu(disk_super->policy_version[1]);
486 cmd->policy_version[2] = le32_to_cpu(disk_super->policy_version[2]);
481 cmd->policy_hint_size = le32_to_cpu(disk_super->policy_hint_size); 487 cmd->policy_hint_size = le32_to_cpu(disk_super->policy_hint_size);
482 488
483 cmd->stats.read_hits = le32_to_cpu(disk_super->read_hits); 489 cmd->stats.read_hits = le32_to_cpu(disk_super->read_hits);
@@ -572,6 +578,9 @@ static int __commit_transaction(struct dm_cache_metadata *cmd,
572 disk_super->discard_nr_blocks = cpu_to_le64(from_dblock(cmd->discard_nr_blocks)); 578 disk_super->discard_nr_blocks = cpu_to_le64(from_dblock(cmd->discard_nr_blocks));
573 disk_super->cache_blocks = cpu_to_le32(from_cblock(cmd->cache_blocks)); 579 disk_super->cache_blocks = cpu_to_le32(from_cblock(cmd->cache_blocks));
574 strncpy(disk_super->policy_name, cmd->policy_name, sizeof(disk_super->policy_name)); 580 strncpy(disk_super->policy_name, cmd->policy_name, sizeof(disk_super->policy_name));
581 disk_super->policy_version[0] = cpu_to_le32(cmd->policy_version[0]);
582 disk_super->policy_version[1] = cpu_to_le32(cmd->policy_version[1]);
583 disk_super->policy_version[2] = cpu_to_le32(cmd->policy_version[2]);
575 584
576 disk_super->read_hits = cpu_to_le32(cmd->stats.read_hits); 585 disk_super->read_hits = cpu_to_le32(cmd->stats.read_hits);
577 disk_super->read_misses = cpu_to_le32(cmd->stats.read_misses); 586 disk_super->read_misses = cpu_to_le32(cmd->stats.read_misses);
@@ -854,18 +863,43 @@ struct thunk {
854 bool hints_valid; 863 bool hints_valid;
855}; 864};
856 865
866static bool policy_unchanged(struct dm_cache_metadata *cmd,
867 struct dm_cache_policy *policy)
868{
869 const char *policy_name = dm_cache_policy_get_name(policy);
870 const unsigned *policy_version = dm_cache_policy_get_version(policy);
871 size_t policy_hint_size = dm_cache_policy_get_hint_size(policy);
872
873 /*
874 * Ensure policy names match.
875 */
876 if (strncmp(cmd->policy_name, policy_name, sizeof(cmd->policy_name)))
877 return false;
878
879 /*
880 * Ensure policy major versions match.
881 */
882 if (cmd->policy_version[0] != policy_version[0])
883 return false;
884
885 /*
886 * Ensure policy hint sizes match.
887 */
888 if (cmd->policy_hint_size != policy_hint_size)
889 return false;
890
891 return true;
892}
893
857static bool hints_array_initialized(struct dm_cache_metadata *cmd) 894static bool hints_array_initialized(struct dm_cache_metadata *cmd)
858{ 895{
859 return cmd->hint_root && cmd->policy_hint_size; 896 return cmd->hint_root && cmd->policy_hint_size;
860} 897}
861 898
862static bool hints_array_available(struct dm_cache_metadata *cmd, 899static bool hints_array_available(struct dm_cache_metadata *cmd,
863 const char *policy_name) 900 struct dm_cache_policy *policy)
864{ 901{
865 bool policy_names_match = !strncmp(cmd->policy_name, policy_name, 902 return cmd->clean_when_opened && policy_unchanged(cmd, policy) &&
866 sizeof(cmd->policy_name));
867
868 return cmd->clean_when_opened && policy_names_match &&
869 hints_array_initialized(cmd); 903 hints_array_initialized(cmd);
870} 904}
871 905
@@ -899,7 +933,8 @@ static int __load_mapping(void *context, uint64_t cblock, void *leaf)
899 return r; 933 return r;
900} 934}
901 935
902static int __load_mappings(struct dm_cache_metadata *cmd, const char *policy_name, 936static int __load_mappings(struct dm_cache_metadata *cmd,
937 struct dm_cache_policy *policy,
903 load_mapping_fn fn, void *context) 938 load_mapping_fn fn, void *context)
904{ 939{
905 struct thunk thunk; 940 struct thunk thunk;
@@ -909,18 +944,19 @@ static int __load_mappings(struct dm_cache_metadata *cmd, const char *policy_nam
909 944
910 thunk.cmd = cmd; 945 thunk.cmd = cmd;
911 thunk.respect_dirty_flags = cmd->clean_when_opened; 946 thunk.respect_dirty_flags = cmd->clean_when_opened;
912 thunk.hints_valid = hints_array_available(cmd, policy_name); 947 thunk.hints_valid = hints_array_available(cmd, policy);
913 948
914 return dm_array_walk(&cmd->info, cmd->root, __load_mapping, &thunk); 949 return dm_array_walk(&cmd->info, cmd->root, __load_mapping, &thunk);
915} 950}
916 951
917int dm_cache_load_mappings(struct dm_cache_metadata *cmd, const char *policy_name, 952int dm_cache_load_mappings(struct dm_cache_metadata *cmd,
953 struct dm_cache_policy *policy,
918 load_mapping_fn fn, void *context) 954 load_mapping_fn fn, void *context)
919{ 955{
920 int r; 956 int r;
921 957
922 down_read(&cmd->root_lock); 958 down_read(&cmd->root_lock);
923 r = __load_mappings(cmd, policy_name, fn, context); 959 r = __load_mappings(cmd, policy, fn, context);
924 up_read(&cmd->root_lock); 960 up_read(&cmd->root_lock);
925 961
926 return r; 962 return r;
@@ -979,7 +1015,7 @@ static int __dirty(struct dm_cache_metadata *cmd, dm_cblock_t cblock, bool dirty
979 /* nothing to be done */ 1015 /* nothing to be done */
980 return 0; 1016 return 0;
981 1017
982 value = pack_value(oblock, flags | (dirty ? M_DIRTY : 0)); 1018 value = pack_value(oblock, (flags & ~M_DIRTY) | (dirty ? M_DIRTY : 0));
983 __dm_bless_for_disk(&value); 1019 __dm_bless_for_disk(&value);
984 1020
985 r = dm_array_set_value(&cmd->info, cmd->root, from_cblock(cblock), 1021 r = dm_array_set_value(&cmd->info, cmd->root, from_cblock(cblock),
@@ -1070,13 +1106,15 @@ static int begin_hints(struct dm_cache_metadata *cmd, struct dm_cache_policy *po
1070 __le32 value; 1106 __le32 value;
1071 size_t hint_size; 1107 size_t hint_size;
1072 const char *policy_name = dm_cache_policy_get_name(policy); 1108 const char *policy_name = dm_cache_policy_get_name(policy);
1109 const unsigned *policy_version = dm_cache_policy_get_version(policy);
1073 1110
1074 if (!policy_name[0] || 1111 if (!policy_name[0] ||
1075 (strlen(policy_name) > sizeof(cmd->policy_name) - 1)) 1112 (strlen(policy_name) > sizeof(cmd->policy_name) - 1))
1076 return -EINVAL; 1113 return -EINVAL;
1077 1114
1078 if (strcmp(cmd->policy_name, policy_name)) { 1115 if (!policy_unchanged(cmd, policy)) {
1079 strncpy(cmd->policy_name, policy_name, sizeof(cmd->policy_name)); 1116 strncpy(cmd->policy_name, policy_name, sizeof(cmd->policy_name));
1117 memcpy(cmd->policy_version, policy_version, sizeof(cmd->policy_version));
1080 1118
1081 hint_size = dm_cache_policy_get_hint_size(policy); 1119 hint_size = dm_cache_policy_get_hint_size(policy);
1082 if (!hint_size) 1120 if (!hint_size)
diff --git a/drivers/md/dm-cache-metadata.h b/drivers/md/dm-cache-metadata.h
index 135864ea0eee..f45cef21f3d0 100644
--- a/drivers/md/dm-cache-metadata.h
+++ b/drivers/md/dm-cache-metadata.h
@@ -89,7 +89,7 @@ typedef int (*load_mapping_fn)(void *context, dm_oblock_t oblock,
89 dm_cblock_t cblock, bool dirty, 89 dm_cblock_t cblock, bool dirty,
90 uint32_t hint, bool hint_valid); 90 uint32_t hint, bool hint_valid);
91int dm_cache_load_mappings(struct dm_cache_metadata *cmd, 91int dm_cache_load_mappings(struct dm_cache_metadata *cmd,
92 const char *policy_name, 92 struct dm_cache_policy *policy,
93 load_mapping_fn fn, 93 load_mapping_fn fn,
94 void *context); 94 void *context);
95 95
diff --git a/drivers/md/dm-cache-policy-cleaner.c b/drivers/md/dm-cache-policy-cleaner.c
index cc05d70b3cb8..b04d1f904d07 100644
--- a/drivers/md/dm-cache-policy-cleaner.c
+++ b/drivers/md/dm-cache-policy-cleaner.c
@@ -17,7 +17,6 @@
17/*----------------------------------------------------------------*/ 17/*----------------------------------------------------------------*/
18 18
19#define DM_MSG_PREFIX "cache cleaner" 19#define DM_MSG_PREFIX "cache cleaner"
20#define CLEANER_VERSION "1.0.0"
21 20
22/* Cache entry struct. */ 21/* Cache entry struct. */
23struct wb_cache_entry { 22struct wb_cache_entry {
@@ -434,6 +433,7 @@ static struct dm_cache_policy *wb_create(dm_cblock_t cache_size,
434 433
435static struct dm_cache_policy_type wb_policy_type = { 434static struct dm_cache_policy_type wb_policy_type = {
436 .name = "cleaner", 435 .name = "cleaner",
436 .version = {1, 0, 0},
437 .hint_size = 0, 437 .hint_size = 0,
438 .owner = THIS_MODULE, 438 .owner = THIS_MODULE,
439 .create = wb_create 439 .create = wb_create
@@ -446,7 +446,10 @@ static int __init wb_init(void)
446 if (r < 0) 446 if (r < 0)
447 DMERR("register failed %d", r); 447 DMERR("register failed %d", r);
448 else 448 else
449 DMINFO("version " CLEANER_VERSION " loaded"); 449 DMINFO("version %u.%u.%u loaded",
450 wb_policy_type.version[0],
451 wb_policy_type.version[1],
452 wb_policy_type.version[2]);
450 453
451 return r; 454 return r;
452} 455}
diff --git a/drivers/md/dm-cache-policy-internal.h b/drivers/md/dm-cache-policy-internal.h
index 52a75beeced5..0928abdc49f0 100644
--- a/drivers/md/dm-cache-policy-internal.h
+++ b/drivers/md/dm-cache-policy-internal.h
@@ -117,6 +117,8 @@ void dm_cache_policy_destroy(struct dm_cache_policy *p);
117 */ 117 */
118const char *dm_cache_policy_get_name(struct dm_cache_policy *p); 118const char *dm_cache_policy_get_name(struct dm_cache_policy *p);
119 119
120const unsigned *dm_cache_policy_get_version(struct dm_cache_policy *p);
121
120size_t dm_cache_policy_get_hint_size(struct dm_cache_policy *p); 122size_t dm_cache_policy_get_hint_size(struct dm_cache_policy *p);
121 123
122/*----------------------------------------------------------------*/ 124/*----------------------------------------------------------------*/
diff --git a/drivers/md/dm-cache-policy-mq.c b/drivers/md/dm-cache-policy-mq.c
index 964153255076..dc112a7137fe 100644
--- a/drivers/md/dm-cache-policy-mq.c
+++ b/drivers/md/dm-cache-policy-mq.c
@@ -14,7 +14,6 @@
14#include <linux/vmalloc.h> 14#include <linux/vmalloc.h>
15 15
16#define DM_MSG_PREFIX "cache-policy-mq" 16#define DM_MSG_PREFIX "cache-policy-mq"
17#define MQ_VERSION "1.0.0"
18 17
19static struct kmem_cache *mq_entry_cache; 18static struct kmem_cache *mq_entry_cache;
20 19
@@ -1133,6 +1132,7 @@ bad_cache_alloc:
1133 1132
1134static struct dm_cache_policy_type mq_policy_type = { 1133static struct dm_cache_policy_type mq_policy_type = {
1135 .name = "mq", 1134 .name = "mq",
1135 .version = {1, 0, 0},
1136 .hint_size = 4, 1136 .hint_size = 4,
1137 .owner = THIS_MODULE, 1137 .owner = THIS_MODULE,
1138 .create = mq_create 1138 .create = mq_create
@@ -1140,6 +1140,7 @@ static struct dm_cache_policy_type mq_policy_type = {
1140 1140
1141static struct dm_cache_policy_type default_policy_type = { 1141static struct dm_cache_policy_type default_policy_type = {
1142 .name = "default", 1142 .name = "default",
1143 .version = {1, 0, 0},
1143 .hint_size = 4, 1144 .hint_size = 4,
1144 .owner = THIS_MODULE, 1145 .owner = THIS_MODULE,
1145 .create = mq_create 1146 .create = mq_create
@@ -1164,7 +1165,10 @@ static int __init mq_init(void)
1164 1165
1165 r = dm_cache_policy_register(&default_policy_type); 1166 r = dm_cache_policy_register(&default_policy_type);
1166 if (!r) { 1167 if (!r) {
1167 DMINFO("version " MQ_VERSION " loaded"); 1168 DMINFO("version %u.%u.%u loaded",
1169 mq_policy_type.version[0],
1170 mq_policy_type.version[1],
1171 mq_policy_type.version[2]);
1168 return 0; 1172 return 0;
1169 } 1173 }
1170 1174
diff --git a/drivers/md/dm-cache-policy.c b/drivers/md/dm-cache-policy.c
index 2cbf5fdaac52..21c03c570c06 100644
--- a/drivers/md/dm-cache-policy.c
+++ b/drivers/md/dm-cache-policy.c
@@ -150,6 +150,14 @@ const char *dm_cache_policy_get_name(struct dm_cache_policy *p)
150} 150}
151EXPORT_SYMBOL_GPL(dm_cache_policy_get_name); 151EXPORT_SYMBOL_GPL(dm_cache_policy_get_name);
152 152
153const unsigned *dm_cache_policy_get_version(struct dm_cache_policy *p)
154{
155 struct dm_cache_policy_type *t = p->private;
156
157 return t->version;
158}
159EXPORT_SYMBOL_GPL(dm_cache_policy_get_version);
160
153size_t dm_cache_policy_get_hint_size(struct dm_cache_policy *p) 161size_t dm_cache_policy_get_hint_size(struct dm_cache_policy *p)
154{ 162{
155 struct dm_cache_policy_type *t = p->private; 163 struct dm_cache_policy_type *t = p->private;
diff --git a/drivers/md/dm-cache-policy.h b/drivers/md/dm-cache-policy.h
index f0f51b260544..558bdfdabf5f 100644
--- a/drivers/md/dm-cache-policy.h
+++ b/drivers/md/dm-cache-policy.h
@@ -196,6 +196,7 @@ struct dm_cache_policy {
196 * We maintain a little register of the different policy types. 196 * We maintain a little register of the different policy types.
197 */ 197 */
198#define CACHE_POLICY_NAME_SIZE 16 198#define CACHE_POLICY_NAME_SIZE 16
199#define CACHE_POLICY_VERSION_SIZE 3
199 200
200struct dm_cache_policy_type { 201struct dm_cache_policy_type {
201 /* For use by the register code only. */ 202 /* For use by the register code only. */
@@ -206,6 +207,7 @@ struct dm_cache_policy_type {
206 * what gets passed on the target line to select your policy. 207 * what gets passed on the target line to select your policy.
207 */ 208 */
208 char name[CACHE_POLICY_NAME_SIZE]; 209 char name[CACHE_POLICY_NAME_SIZE];
210 unsigned version[CACHE_POLICY_VERSION_SIZE];
209 211
210 /* 212 /*
211 * Policies may store a hint for each each cache block. 213 * Policies may store a hint for each each cache block.
diff --git a/drivers/md/dm-cache-target.c b/drivers/md/dm-cache-target.c
index 0f4e84b15c30..66120bd46d15 100644
--- a/drivers/md/dm-cache-target.c
+++ b/drivers/md/dm-cache-target.c
@@ -142,6 +142,7 @@ struct cache {
142 spinlock_t lock; 142 spinlock_t lock;
143 struct bio_list deferred_bios; 143 struct bio_list deferred_bios;
144 struct bio_list deferred_flush_bios; 144 struct bio_list deferred_flush_bios;
145 struct bio_list deferred_writethrough_bios;
145 struct list_head quiesced_migrations; 146 struct list_head quiesced_migrations;
146 struct list_head completed_migrations; 147 struct list_head completed_migrations;
147 struct list_head need_commit_migrations; 148 struct list_head need_commit_migrations;
@@ -158,7 +159,7 @@ struct cache {
158 /* 159 /*
159 * origin_blocks entries, discarded if set. 160 * origin_blocks entries, discarded if set.
160 */ 161 */
161 sector_t discard_block_size; /* a power of 2 times sectors per block */ 162 uint32_t discard_block_size; /* a power of 2 times sectors per block */
162 dm_dblock_t discard_nr_blocks; 163 dm_dblock_t discard_nr_blocks;
163 unsigned long *discard_bitset; 164 unsigned long *discard_bitset;
164 165
@@ -199,6 +200,11 @@ struct per_bio_data {
199 bool tick:1; 200 bool tick:1;
200 unsigned req_nr:2; 201 unsigned req_nr:2;
201 struct dm_deferred_entry *all_io_entry; 202 struct dm_deferred_entry *all_io_entry;
203
204 /* writethrough fields */
205 struct cache *cache;
206 dm_cblock_t cblock;
207 bio_end_io_t *saved_bi_end_io;
202}; 208};
203 209
204struct dm_cache_migration { 210struct dm_cache_migration {
@@ -412,17 +418,24 @@ static bool block_size_is_power_of_two(struct cache *cache)
412 return cache->sectors_per_block_shift >= 0; 418 return cache->sectors_per_block_shift >= 0;
413} 419}
414 420
421static dm_block_t block_div(dm_block_t b, uint32_t n)
422{
423 do_div(b, n);
424
425 return b;
426}
427
415static dm_dblock_t oblock_to_dblock(struct cache *cache, dm_oblock_t oblock) 428static dm_dblock_t oblock_to_dblock(struct cache *cache, dm_oblock_t oblock)
416{ 429{
417 sector_t discard_blocks = cache->discard_block_size; 430 uint32_t discard_blocks = cache->discard_block_size;
418 dm_block_t b = from_oblock(oblock); 431 dm_block_t b = from_oblock(oblock);
419 432
420 if (!block_size_is_power_of_two(cache)) 433 if (!block_size_is_power_of_two(cache))
421 (void) sector_div(discard_blocks, cache->sectors_per_block); 434 discard_blocks = discard_blocks / cache->sectors_per_block;
422 else 435 else
423 discard_blocks >>= cache->sectors_per_block_shift; 436 discard_blocks >>= cache->sectors_per_block_shift;
424 437
425 (void) sector_div(b, discard_blocks); 438 b = block_div(b, discard_blocks);
426 439
427 return to_dblock(b); 440 return to_dblock(b);
428} 441}
@@ -609,6 +622,56 @@ static void issue(struct cache *cache, struct bio *bio)
609 spin_unlock_irqrestore(&cache->lock, flags); 622 spin_unlock_irqrestore(&cache->lock, flags);
610} 623}
611 624
625static void defer_writethrough_bio(struct cache *cache, struct bio *bio)
626{
627 unsigned long flags;
628
629 spin_lock_irqsave(&cache->lock, flags);
630 bio_list_add(&cache->deferred_writethrough_bios, bio);
631 spin_unlock_irqrestore(&cache->lock, flags);
632
633 wake_worker(cache);
634}
635
636static void writethrough_endio(struct bio *bio, int err)
637{
638 struct per_bio_data *pb = get_per_bio_data(bio);
639 bio->bi_end_io = pb->saved_bi_end_io;
640
641 if (err) {
642 bio_endio(bio, err);
643 return;
644 }
645
646 remap_to_cache(pb->cache, bio, pb->cblock);
647
648 /*
649 * We can't issue this bio directly, since we're in interrupt
650 * context. So it get's put on a bio list for processing by the
651 * worker thread.
652 */
653 defer_writethrough_bio(pb->cache, bio);
654}
655
656/*
657 * When running in writethrough mode we need to send writes to clean blocks
658 * to both the cache and origin devices. In future we'd like to clone the
659 * bio and send them in parallel, but for now we're doing them in
660 * series as this is easier.
661 */
662static void remap_to_origin_then_cache(struct cache *cache, struct bio *bio,
663 dm_oblock_t oblock, dm_cblock_t cblock)
664{
665 struct per_bio_data *pb = get_per_bio_data(bio);
666
667 pb->cache = cache;
668 pb->cblock = cblock;
669 pb->saved_bi_end_io = bio->bi_end_io;
670 bio->bi_end_io = writethrough_endio;
671
672 remap_to_origin_clear_discard(pb->cache, bio, oblock);
673}
674
612/*---------------------------------------------------------------- 675/*----------------------------------------------------------------
613 * Migration processing 676 * Migration processing
614 * 677 *
@@ -1002,7 +1065,7 @@ static void process_discard_bio(struct cache *cache, struct bio *bio)
1002 dm_block_t end_block = bio->bi_sector + bio_sectors(bio); 1065 dm_block_t end_block = bio->bi_sector + bio_sectors(bio);
1003 dm_block_t b; 1066 dm_block_t b;
1004 1067
1005 (void) sector_div(end_block, cache->discard_block_size); 1068 end_block = block_div(end_block, cache->discard_block_size);
1006 1069
1007 for (b = start_block; b < end_block; b++) 1070 for (b = start_block; b < end_block; b++)
1008 set_discard(cache, to_dblock(b)); 1071 set_discard(cache, to_dblock(b));
@@ -1070,14 +1133,9 @@ static void process_bio(struct cache *cache, struct prealloc *structs,
1070 inc_hit_counter(cache, bio); 1133 inc_hit_counter(cache, bio);
1071 pb->all_io_entry = dm_deferred_entry_inc(cache->all_io_ds); 1134 pb->all_io_entry = dm_deferred_entry_inc(cache->all_io_ds);
1072 1135
1073 if (is_writethrough_io(cache, bio, lookup_result.cblock)) { 1136 if (is_writethrough_io(cache, bio, lookup_result.cblock))
1074 /* 1137 remap_to_origin_then_cache(cache, bio, block, lookup_result.cblock);
1075 * No need to mark anything dirty in write through mode. 1138 else
1076 */
1077 pb->req_nr == 0 ?
1078 remap_to_cache(cache, bio, lookup_result.cblock) :
1079 remap_to_origin_clear_discard(cache, bio, block);
1080 } else
1081 remap_to_cache_dirty(cache, bio, block, lookup_result.cblock); 1139 remap_to_cache_dirty(cache, bio, block, lookup_result.cblock);
1082 1140
1083 issue(cache, bio); 1141 issue(cache, bio);
@@ -1086,17 +1144,8 @@ static void process_bio(struct cache *cache, struct prealloc *structs,
1086 case POLICY_MISS: 1144 case POLICY_MISS:
1087 inc_miss_counter(cache, bio); 1145 inc_miss_counter(cache, bio);
1088 pb->all_io_entry = dm_deferred_entry_inc(cache->all_io_ds); 1146 pb->all_io_entry = dm_deferred_entry_inc(cache->all_io_ds);
1089 1147 remap_to_origin_clear_discard(cache, bio, block);
1090 if (pb->req_nr != 0) { 1148 issue(cache, bio);
1091 /*
1092 * This is a duplicate writethrough io that is no
1093 * longer needed because the block has been demoted.
1094 */
1095 bio_endio(bio, 0);
1096 } else {
1097 remap_to_origin_clear_discard(cache, bio, block);
1098 issue(cache, bio);
1099 }
1100 break; 1149 break;
1101 1150
1102 case POLICY_NEW: 1151 case POLICY_NEW:
@@ -1217,6 +1266,23 @@ static void process_deferred_flush_bios(struct cache *cache, bool submit_bios)
1217 submit_bios ? generic_make_request(bio) : bio_io_error(bio); 1266 submit_bios ? generic_make_request(bio) : bio_io_error(bio);
1218} 1267}
1219 1268
1269static void process_deferred_writethrough_bios(struct cache *cache)
1270{
1271 unsigned long flags;
1272 struct bio_list bios;
1273 struct bio *bio;
1274
1275 bio_list_init(&bios);
1276
1277 spin_lock_irqsave(&cache->lock, flags);
1278 bio_list_merge(&bios, &cache->deferred_writethrough_bios);
1279 bio_list_init(&cache->deferred_writethrough_bios);
1280 spin_unlock_irqrestore(&cache->lock, flags);
1281
1282 while ((bio = bio_list_pop(&bios)))
1283 generic_make_request(bio);
1284}
1285
1220static void writeback_some_dirty_blocks(struct cache *cache) 1286static void writeback_some_dirty_blocks(struct cache *cache)
1221{ 1287{
1222 int r = 0; 1288 int r = 0;
@@ -1313,6 +1379,7 @@ static int more_work(struct cache *cache)
1313 else 1379 else
1314 return !bio_list_empty(&cache->deferred_bios) || 1380 return !bio_list_empty(&cache->deferred_bios) ||
1315 !bio_list_empty(&cache->deferred_flush_bios) || 1381 !bio_list_empty(&cache->deferred_flush_bios) ||
1382 !bio_list_empty(&cache->deferred_writethrough_bios) ||
1316 !list_empty(&cache->quiesced_migrations) || 1383 !list_empty(&cache->quiesced_migrations) ||
1317 !list_empty(&cache->completed_migrations) || 1384 !list_empty(&cache->completed_migrations) ||
1318 !list_empty(&cache->need_commit_migrations); 1385 !list_empty(&cache->need_commit_migrations);
@@ -1331,6 +1398,8 @@ static void do_worker(struct work_struct *ws)
1331 1398
1332 writeback_some_dirty_blocks(cache); 1399 writeback_some_dirty_blocks(cache);
1333 1400
1401 process_deferred_writethrough_bios(cache);
1402
1334 if (commit_if_needed(cache)) { 1403 if (commit_if_needed(cache)) {
1335 process_deferred_flush_bios(cache, false); 1404 process_deferred_flush_bios(cache, false);
1336 1405
@@ -1756,8 +1825,11 @@ static int create_cache_policy(struct cache *cache, struct cache_args *ca,
1756 } 1825 }
1757 1826
1758 r = set_config_values(cache->policy, ca->policy_argc, ca->policy_argv); 1827 r = set_config_values(cache->policy, ca->policy_argc, ca->policy_argv);
1759 if (r) 1828 if (r) {
1829 *error = "Error setting cache policy's config values";
1760 dm_cache_policy_destroy(cache->policy); 1830 dm_cache_policy_destroy(cache->policy);
1831 cache->policy = NULL;
1832 }
1761 1833
1762 return r; 1834 return r;
1763} 1835}
@@ -1793,8 +1865,6 @@ static sector_t calculate_discard_block_size(sector_t cache_block_size,
1793 1865
1794#define DEFAULT_MIGRATION_THRESHOLD (2048 * 100) 1866#define DEFAULT_MIGRATION_THRESHOLD (2048 * 100)
1795 1867
1796static unsigned cache_num_write_bios(struct dm_target *ti, struct bio *bio);
1797
1798static int cache_create(struct cache_args *ca, struct cache **result) 1868static int cache_create(struct cache_args *ca, struct cache **result)
1799{ 1869{
1800 int r = 0; 1870 int r = 0;
@@ -1821,9 +1891,6 @@ static int cache_create(struct cache_args *ca, struct cache **result)
1821 1891
1822 memcpy(&cache->features, &ca->features, sizeof(cache->features)); 1892 memcpy(&cache->features, &ca->features, sizeof(cache->features));
1823 1893
1824 if (cache->features.write_through)
1825 ti->num_write_bios = cache_num_write_bios;
1826
1827 cache->callbacks.congested_fn = cache_is_congested; 1894 cache->callbacks.congested_fn = cache_is_congested;
1828 dm_table_add_target_callbacks(ti->table, &cache->callbacks); 1895 dm_table_add_target_callbacks(ti->table, &cache->callbacks);
1829 1896
@@ -1835,7 +1902,7 @@ static int cache_create(struct cache_args *ca, struct cache **result)
1835 1902
1836 /* FIXME: factor out this whole section */ 1903 /* FIXME: factor out this whole section */
1837 origin_blocks = cache->origin_sectors = ca->origin_sectors; 1904 origin_blocks = cache->origin_sectors = ca->origin_sectors;
1838 (void) sector_div(origin_blocks, ca->block_size); 1905 origin_blocks = block_div(origin_blocks, ca->block_size);
1839 cache->origin_blocks = to_oblock(origin_blocks); 1906 cache->origin_blocks = to_oblock(origin_blocks);
1840 1907
1841 cache->sectors_per_block = ca->block_size; 1908 cache->sectors_per_block = ca->block_size;
@@ -1848,7 +1915,7 @@ static int cache_create(struct cache_args *ca, struct cache **result)
1848 dm_block_t cache_size = ca->cache_sectors; 1915 dm_block_t cache_size = ca->cache_sectors;
1849 1916
1850 cache->sectors_per_block_shift = -1; 1917 cache->sectors_per_block_shift = -1;
1851 (void) sector_div(cache_size, ca->block_size); 1918 cache_size = block_div(cache_size, ca->block_size);
1852 cache->cache_size = to_cblock(cache_size); 1919 cache->cache_size = to_cblock(cache_size);
1853 } else { 1920 } else {
1854 cache->sectors_per_block_shift = __ffs(ca->block_size); 1921 cache->sectors_per_block_shift = __ffs(ca->block_size);
@@ -1873,6 +1940,7 @@ static int cache_create(struct cache_args *ca, struct cache **result)
1873 spin_lock_init(&cache->lock); 1940 spin_lock_init(&cache->lock);
1874 bio_list_init(&cache->deferred_bios); 1941 bio_list_init(&cache->deferred_bios);
1875 bio_list_init(&cache->deferred_flush_bios); 1942 bio_list_init(&cache->deferred_flush_bios);
1943 bio_list_init(&cache->deferred_writethrough_bios);
1876 INIT_LIST_HEAD(&cache->quiesced_migrations); 1944 INIT_LIST_HEAD(&cache->quiesced_migrations);
1877 INIT_LIST_HEAD(&cache->completed_migrations); 1945 INIT_LIST_HEAD(&cache->completed_migrations);
1878 INIT_LIST_HEAD(&cache->need_commit_migrations); 1946 INIT_LIST_HEAD(&cache->need_commit_migrations);
@@ -2002,6 +2070,8 @@ static int cache_ctr(struct dm_target *ti, unsigned argc, char **argv)
2002 goto out; 2070 goto out;
2003 2071
2004 r = cache_create(ca, &cache); 2072 r = cache_create(ca, &cache);
2073 if (r)
2074 goto out;
2005 2075
2006 r = copy_ctr_args(cache, argc - 3, (const char **)argv + 3); 2076 r = copy_ctr_args(cache, argc - 3, (const char **)argv + 3);
2007 if (r) { 2077 if (r) {
@@ -2016,20 +2086,6 @@ out:
2016 return r; 2086 return r;
2017} 2087}
2018 2088
2019static unsigned cache_num_write_bios(struct dm_target *ti, struct bio *bio)
2020{
2021 int r;
2022 struct cache *cache = ti->private;
2023 dm_oblock_t block = get_bio_block(cache, bio);
2024 dm_cblock_t cblock;
2025
2026 r = policy_lookup(cache->policy, block, &cblock);
2027 if (r < 0)
2028 return 2; /* assume the worst */
2029
2030 return (!r && !is_dirty(cache, cblock)) ? 2 : 1;
2031}
2032
2033static int cache_map(struct dm_target *ti, struct bio *bio) 2089static int cache_map(struct dm_target *ti, struct bio *bio)
2034{ 2090{
2035 struct cache *cache = ti->private; 2091 struct cache *cache = ti->private;
@@ -2097,18 +2153,12 @@ static int cache_map(struct dm_target *ti, struct bio *bio)
2097 inc_hit_counter(cache, bio); 2153 inc_hit_counter(cache, bio);
2098 pb->all_io_entry = dm_deferred_entry_inc(cache->all_io_ds); 2154 pb->all_io_entry = dm_deferred_entry_inc(cache->all_io_ds);
2099 2155
2100 if (is_writethrough_io(cache, bio, lookup_result.cblock)) { 2156 if (is_writethrough_io(cache, bio, lookup_result.cblock))
2101 /* 2157 remap_to_origin_then_cache(cache, bio, block, lookup_result.cblock);
2102 * No need to mark anything dirty in write through mode. 2158 else
2103 */
2104 pb->req_nr == 0 ?
2105 remap_to_cache(cache, bio, lookup_result.cblock) :
2106 remap_to_origin_clear_discard(cache, bio, block);
2107 cell_defer(cache, cell, false);
2108 } else {
2109 remap_to_cache_dirty(cache, bio, block, lookup_result.cblock); 2159 remap_to_cache_dirty(cache, bio, block, lookup_result.cblock);
2110 cell_defer(cache, cell, false); 2160
2111 } 2161 cell_defer(cache, cell, false);
2112 break; 2162 break;
2113 2163
2114 case POLICY_MISS: 2164 case POLICY_MISS:
@@ -2319,8 +2369,7 @@ static int cache_preresume(struct dm_target *ti)
2319 } 2369 }
2320 2370
2321 if (!cache->loaded_mappings) { 2371 if (!cache->loaded_mappings) {
2322 r = dm_cache_load_mappings(cache->cmd, 2372 r = dm_cache_load_mappings(cache->cmd, cache->policy,
2323 dm_cache_policy_get_name(cache->policy),
2324 load_mapping, cache); 2373 load_mapping, cache);
2325 if (r) { 2374 if (r) {
2326 DMERR("could not load cache mappings"); 2375 DMERR("could not load cache mappings");
@@ -2535,7 +2584,7 @@ static void cache_io_hints(struct dm_target *ti, struct queue_limits *limits)
2535 2584
2536static struct target_type cache_target = { 2585static struct target_type cache_target = {
2537 .name = "cache", 2586 .name = "cache",
2538 .version = {1, 0, 0}, 2587 .version = {1, 1, 0},
2539 .module = THIS_MODULE, 2588 .module = THIS_MODULE,
2540 .ctr = cache_ctr, 2589 .ctr = cache_ctr,
2541 .dtr = cache_dtr, 2590 .dtr = cache_dtr,
diff --git a/drivers/md/dm-thin.c b/drivers/md/dm-thin.c
index 009339d62828..004ad1652b73 100644
--- a/drivers/md/dm-thin.c
+++ b/drivers/md/dm-thin.c
@@ -1577,6 +1577,11 @@ static bool data_dev_supports_discard(struct pool_c *pt)
1577 return q && blk_queue_discard(q); 1577 return q && blk_queue_discard(q);
1578} 1578}
1579 1579
1580static bool is_factor(sector_t block_size, uint32_t n)
1581{
1582 return !sector_div(block_size, n);
1583}
1584
1580/* 1585/*
1581 * If discard_passdown was enabled verify that the data device 1586 * If discard_passdown was enabled verify that the data device
1582 * supports discards. Disable discard_passdown if not. 1587 * supports discards. Disable discard_passdown if not.
@@ -1602,7 +1607,7 @@ static void disable_passdown_if_not_supported(struct pool_c *pt)
1602 else if (data_limits->discard_granularity > block_size) 1607 else if (data_limits->discard_granularity > block_size)
1603 reason = "discard granularity larger than a block"; 1608 reason = "discard granularity larger than a block";
1604 1609
1605 else if (block_size & (data_limits->discard_granularity - 1)) 1610 else if (!is_factor(block_size, data_limits->discard_granularity))
1606 reason = "discard granularity not a factor of block size"; 1611 reason = "discard granularity not a factor of block size";
1607 1612
1608 if (reason) { 1613 if (reason) {
@@ -2544,7 +2549,7 @@ static struct target_type pool_target = {
2544 .name = "thin-pool", 2549 .name = "thin-pool",
2545 .features = DM_TARGET_SINGLETON | DM_TARGET_ALWAYS_WRITEABLE | 2550 .features = DM_TARGET_SINGLETON | DM_TARGET_ALWAYS_WRITEABLE |
2546 DM_TARGET_IMMUTABLE, 2551 DM_TARGET_IMMUTABLE,
2547 .version = {1, 6, 1}, 2552 .version = {1, 7, 0},
2548 .module = THIS_MODULE, 2553 .module = THIS_MODULE,
2549 .ctr = pool_ctr, 2554 .ctr = pool_ctr,
2550 .dtr = pool_dtr, 2555 .dtr = pool_dtr,
@@ -2831,7 +2836,7 @@ static int thin_iterate_devices(struct dm_target *ti,
2831 2836
2832static struct target_type thin_target = { 2837static struct target_type thin_target = {
2833 .name = "thin", 2838 .name = "thin",
2834 .version = {1, 7, 1}, 2839 .version = {1, 8, 0},
2835 .module = THIS_MODULE, 2840 .module = THIS_MODULE,
2836 .ctr = thin_ctr, 2841 .ctr = thin_ctr,
2837 .dtr = thin_dtr, 2842 .dtr = thin_dtr,
diff --git a/drivers/md/dm-verity.c b/drivers/md/dm-verity.c
index 6ad538375c3c..a746f1d21c66 100644
--- a/drivers/md/dm-verity.c
+++ b/drivers/md/dm-verity.c
@@ -93,6 +93,13 @@ struct dm_verity_io {
93 */ 93 */
94}; 94};
95 95
96struct dm_verity_prefetch_work {
97 struct work_struct work;
98 struct dm_verity *v;
99 sector_t block;
100 unsigned n_blocks;
101};
102
96static struct shash_desc *io_hash_desc(struct dm_verity *v, struct dm_verity_io *io) 103static struct shash_desc *io_hash_desc(struct dm_verity *v, struct dm_verity_io *io)
97{ 104{
98 return (struct shash_desc *)(io + 1); 105 return (struct shash_desc *)(io + 1);
@@ -424,15 +431,18 @@ static void verity_end_io(struct bio *bio, int error)
424 * The root buffer is not prefetched, it is assumed that it will be cached 431 * The root buffer is not prefetched, it is assumed that it will be cached
425 * all the time. 432 * all the time.
426 */ 433 */
427static void verity_prefetch_io(struct dm_verity *v, struct dm_verity_io *io) 434static void verity_prefetch_io(struct work_struct *work)
428{ 435{
436 struct dm_verity_prefetch_work *pw =
437 container_of(work, struct dm_verity_prefetch_work, work);
438 struct dm_verity *v = pw->v;
429 int i; 439 int i;
430 440
431 for (i = v->levels - 2; i >= 0; i--) { 441 for (i = v->levels - 2; i >= 0; i--) {
432 sector_t hash_block_start; 442 sector_t hash_block_start;
433 sector_t hash_block_end; 443 sector_t hash_block_end;
434 verity_hash_at_level(v, io->block, i, &hash_block_start, NULL); 444 verity_hash_at_level(v, pw->block, i, &hash_block_start, NULL);
435 verity_hash_at_level(v, io->block + io->n_blocks - 1, i, &hash_block_end, NULL); 445 verity_hash_at_level(v, pw->block + pw->n_blocks - 1, i, &hash_block_end, NULL);
436 if (!i) { 446 if (!i) {
437 unsigned cluster = ACCESS_ONCE(dm_verity_prefetch_cluster); 447 unsigned cluster = ACCESS_ONCE(dm_verity_prefetch_cluster);
438 448
@@ -452,6 +462,25 @@ no_prefetch_cluster:
452 dm_bufio_prefetch(v->bufio, hash_block_start, 462 dm_bufio_prefetch(v->bufio, hash_block_start,
453 hash_block_end - hash_block_start + 1); 463 hash_block_end - hash_block_start + 1);
454 } 464 }
465
466 kfree(pw);
467}
468
469static void verity_submit_prefetch(struct dm_verity *v, struct dm_verity_io *io)
470{
471 struct dm_verity_prefetch_work *pw;
472
473 pw = kmalloc(sizeof(struct dm_verity_prefetch_work),
474 GFP_NOIO | __GFP_NORETRY | __GFP_NOMEMALLOC | __GFP_NOWARN);
475
476 if (!pw)
477 return;
478
479 INIT_WORK(&pw->work, verity_prefetch_io);
480 pw->v = v;
481 pw->block = io->block;
482 pw->n_blocks = io->n_blocks;
483 queue_work(v->verify_wq, &pw->work);
455} 484}
456 485
457/* 486/*
@@ -498,7 +527,7 @@ static int verity_map(struct dm_target *ti, struct bio *bio)
498 memcpy(io->io_vec, bio_iovec(bio), 527 memcpy(io->io_vec, bio_iovec(bio),
499 io->io_vec_size * sizeof(struct bio_vec)); 528 io->io_vec_size * sizeof(struct bio_vec));
500 529
501 verity_prefetch_io(v, io); 530 verity_submit_prefetch(v, io);
502 531
503 generic_make_request(bio); 532 generic_make_request(bio);
504 533
@@ -858,7 +887,7 @@ bad:
858 887
859static struct target_type verity_target = { 888static struct target_type verity_target = {
860 .name = "verity", 889 .name = "verity",
861 .version = {1, 1, 1}, 890 .version = {1, 2, 0},
862 .module = THIS_MODULE, 891 .module = THIS_MODULE,
863 .ctr = verity_ctr, 892 .ctr = verity_ctr,
864 .dtr = verity_dtr, 893 .dtr = verity_dtr,
diff --git a/drivers/md/md.c b/drivers/md/md.c
index fcb878f88796..aeceedfc530b 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -7663,10 +7663,8 @@ static int remove_and_add_spares(struct mddev *mddev)
7663 removed++; 7663 removed++;
7664 } 7664 }
7665 } 7665 }
7666 if (removed) 7666 if (removed && mddev->kobj.sd)
7667 sysfs_notify(&mddev->kobj, NULL, 7667 sysfs_notify(&mddev->kobj, NULL, "degraded");
7668 "degraded");
7669
7670 7668
7671 rdev_for_each(rdev, mddev) { 7669 rdev_for_each(rdev, mddev) {
7672 if (rdev->raid_disk >= 0 && 7670 if (rdev->raid_disk >= 0 &&
diff --git a/drivers/md/md.h b/drivers/md/md.h
index eca59c3074ef..d90fb1a879e1 100644
--- a/drivers/md/md.h
+++ b/drivers/md/md.h
@@ -506,7 +506,7 @@ static inline char * mdname (struct mddev * mddev)
506static inline int sysfs_link_rdev(struct mddev *mddev, struct md_rdev *rdev) 506static inline int sysfs_link_rdev(struct mddev *mddev, struct md_rdev *rdev)
507{ 507{
508 char nm[20]; 508 char nm[20];
509 if (!test_bit(Replacement, &rdev->flags)) { 509 if (!test_bit(Replacement, &rdev->flags) && mddev->kobj.sd) {
510 sprintf(nm, "rd%d", rdev->raid_disk); 510 sprintf(nm, "rd%d", rdev->raid_disk);
511 return sysfs_create_link(&mddev->kobj, &rdev->kobj, nm); 511 return sysfs_create_link(&mddev->kobj, &rdev->kobj, nm);
512 } else 512 } else
@@ -516,7 +516,7 @@ static inline int sysfs_link_rdev(struct mddev *mddev, struct md_rdev *rdev)
516static inline void sysfs_unlink_rdev(struct mddev *mddev, struct md_rdev *rdev) 516static inline void sysfs_unlink_rdev(struct mddev *mddev, struct md_rdev *rdev)
517{ 517{
518 char nm[20]; 518 char nm[20];
519 if (!test_bit(Replacement, &rdev->flags)) { 519 if (!test_bit(Replacement, &rdev->flags) && mddev->kobj.sd) {
520 sprintf(nm, "rd%d", rdev->raid_disk); 520 sprintf(nm, "rd%d", rdev->raid_disk);
521 sysfs_remove_link(&mddev->kobj, nm); 521 sysfs_remove_link(&mddev->kobj, nm);
522 } 522 }
diff --git a/drivers/md/persistent-data/dm-btree-remove.c b/drivers/md/persistent-data/dm-btree-remove.c
index c4f28133ef82..b88757cd0d1d 100644
--- a/drivers/md/persistent-data/dm-btree-remove.c
+++ b/drivers/md/persistent-data/dm-btree-remove.c
@@ -139,15 +139,8 @@ struct child {
139 struct btree_node *n; 139 struct btree_node *n;
140}; 140};
141 141
142static struct dm_btree_value_type le64_type = { 142static int init_child(struct dm_btree_info *info, struct dm_btree_value_type *vt,
143 .context = NULL, 143 struct btree_node *parent,
144 .size = sizeof(__le64),
145 .inc = NULL,
146 .dec = NULL,
147 .equal = NULL
148};
149
150static int init_child(struct dm_btree_info *info, struct btree_node *parent,
151 unsigned index, struct child *result) 144 unsigned index, struct child *result)
152{ 145{
153 int r, inc; 146 int r, inc;
@@ -164,7 +157,7 @@ static int init_child(struct dm_btree_info *info, struct btree_node *parent,
164 result->n = dm_block_data(result->block); 157 result->n = dm_block_data(result->block);
165 158
166 if (inc) 159 if (inc)
167 inc_children(info->tm, result->n, &le64_type); 160 inc_children(info->tm, result->n, vt);
168 161
169 *((__le64 *) value_ptr(parent, index)) = 162 *((__le64 *) value_ptr(parent, index)) =
170 cpu_to_le64(dm_block_location(result->block)); 163 cpu_to_le64(dm_block_location(result->block));
@@ -236,7 +229,7 @@ static void __rebalance2(struct dm_btree_info *info, struct btree_node *parent,
236} 229}
237 230
238static int rebalance2(struct shadow_spine *s, struct dm_btree_info *info, 231static int rebalance2(struct shadow_spine *s, struct dm_btree_info *info,
239 unsigned left_index) 232 struct dm_btree_value_type *vt, unsigned left_index)
240{ 233{
241 int r; 234 int r;
242 struct btree_node *parent; 235 struct btree_node *parent;
@@ -244,11 +237,11 @@ static int rebalance2(struct shadow_spine *s, struct dm_btree_info *info,
244 237
245 parent = dm_block_data(shadow_current(s)); 238 parent = dm_block_data(shadow_current(s));
246 239
247 r = init_child(info, parent, left_index, &left); 240 r = init_child(info, vt, parent, left_index, &left);
248 if (r) 241 if (r)
249 return r; 242 return r;
250 243
251 r = init_child(info, parent, left_index + 1, &right); 244 r = init_child(info, vt, parent, left_index + 1, &right);
252 if (r) { 245 if (r) {
253 exit_child(info, &left); 246 exit_child(info, &left);
254 return r; 247 return r;
@@ -368,7 +361,7 @@ static void __rebalance3(struct dm_btree_info *info, struct btree_node *parent,
368} 361}
369 362
370static int rebalance3(struct shadow_spine *s, struct dm_btree_info *info, 363static int rebalance3(struct shadow_spine *s, struct dm_btree_info *info,
371 unsigned left_index) 364 struct dm_btree_value_type *vt, unsigned left_index)
372{ 365{
373 int r; 366 int r;
374 struct btree_node *parent = dm_block_data(shadow_current(s)); 367 struct btree_node *parent = dm_block_data(shadow_current(s));
@@ -377,17 +370,17 @@ static int rebalance3(struct shadow_spine *s, struct dm_btree_info *info,
377 /* 370 /*
378 * FIXME: fill out an array? 371 * FIXME: fill out an array?
379 */ 372 */
380 r = init_child(info, parent, left_index, &left); 373 r = init_child(info, vt, parent, left_index, &left);
381 if (r) 374 if (r)
382 return r; 375 return r;
383 376
384 r = init_child(info, parent, left_index + 1, &center); 377 r = init_child(info, vt, parent, left_index + 1, &center);
385 if (r) { 378 if (r) {
386 exit_child(info, &left); 379 exit_child(info, &left);
387 return r; 380 return r;
388 } 381 }
389 382
390 r = init_child(info, parent, left_index + 2, &right); 383 r = init_child(info, vt, parent, left_index + 2, &right);
391 if (r) { 384 if (r) {
392 exit_child(info, &left); 385 exit_child(info, &left);
393 exit_child(info, &center); 386 exit_child(info, &center);
@@ -434,7 +427,8 @@ static int get_nr_entries(struct dm_transaction_manager *tm,
434} 427}
435 428
436static int rebalance_children(struct shadow_spine *s, 429static int rebalance_children(struct shadow_spine *s,
437 struct dm_btree_info *info, uint64_t key) 430 struct dm_btree_info *info,
431 struct dm_btree_value_type *vt, uint64_t key)
438{ 432{
439 int i, r, has_left_sibling, has_right_sibling; 433 int i, r, has_left_sibling, has_right_sibling;
440 uint32_t child_entries; 434 uint32_t child_entries;
@@ -472,13 +466,13 @@ static int rebalance_children(struct shadow_spine *s,
472 has_right_sibling = i < (le32_to_cpu(n->header.nr_entries) - 1); 466 has_right_sibling = i < (le32_to_cpu(n->header.nr_entries) - 1);
473 467
474 if (!has_left_sibling) 468 if (!has_left_sibling)
475 r = rebalance2(s, info, i); 469 r = rebalance2(s, info, vt, i);
476 470
477 else if (!has_right_sibling) 471 else if (!has_right_sibling)
478 r = rebalance2(s, info, i - 1); 472 r = rebalance2(s, info, vt, i - 1);
479 473
480 else 474 else
481 r = rebalance3(s, info, i - 1); 475 r = rebalance3(s, info, vt, i - 1);
482 476
483 return r; 477 return r;
484} 478}
@@ -529,7 +523,7 @@ static int remove_raw(struct shadow_spine *s, struct dm_btree_info *info,
529 if (le32_to_cpu(n->header.flags) & LEAF_NODE) 523 if (le32_to_cpu(n->header.flags) & LEAF_NODE)
530 return do_leaf(n, key, index); 524 return do_leaf(n, key, index);
531 525
532 r = rebalance_children(s, info, key); 526 r = rebalance_children(s, info, vt, key);
533 if (r) 527 if (r)
534 break; 528 break;
535 529
@@ -550,6 +544,14 @@ static int remove_raw(struct shadow_spine *s, struct dm_btree_info *info,
550 return r; 544 return r;
551} 545}
552 546
547static struct dm_btree_value_type le64_type = {
548 .context = NULL,
549 .size = sizeof(__le64),
550 .inc = NULL,
551 .dec = NULL,
552 .equal = NULL
553};
554
553int dm_btree_remove(struct dm_btree_info *info, dm_block_t root, 555int dm_btree_remove(struct dm_btree_info *info, dm_block_t root,
554 uint64_t *keys, dm_block_t *new_root) 556 uint64_t *keys, dm_block_t *new_root)
555{ 557{
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index 3ee2912889e7..24909eb13fec 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -671,9 +671,11 @@ static void ops_run_io(struct stripe_head *sh, struct stripe_head_state *s)
671 bi->bi_next = NULL; 671 bi->bi_next = NULL;
672 if (rrdev) 672 if (rrdev)
673 set_bit(R5_DOUBLE_LOCKED, &sh->dev[i].flags); 673 set_bit(R5_DOUBLE_LOCKED, &sh->dev[i].flags);
674 trace_block_bio_remap(bdev_get_queue(bi->bi_bdev), 674
675 bi, disk_devt(conf->mddev->gendisk), 675 if (conf->mddev->gendisk)
676 sh->dev[i].sector); 676 trace_block_bio_remap(bdev_get_queue(bi->bi_bdev),
677 bi, disk_devt(conf->mddev->gendisk),
678 sh->dev[i].sector);
677 generic_make_request(bi); 679 generic_make_request(bi);
678 } 680 }
679 if (rrdev) { 681 if (rrdev) {
@@ -701,9 +703,10 @@ static void ops_run_io(struct stripe_head *sh, struct stripe_head_state *s)
701 rbi->bi_io_vec[0].bv_offset = 0; 703 rbi->bi_io_vec[0].bv_offset = 0;
702 rbi->bi_size = STRIPE_SIZE; 704 rbi->bi_size = STRIPE_SIZE;
703 rbi->bi_next = NULL; 705 rbi->bi_next = NULL;
704 trace_block_bio_remap(bdev_get_queue(rbi->bi_bdev), 706 if (conf->mddev->gendisk)
705 rbi, disk_devt(conf->mddev->gendisk), 707 trace_block_bio_remap(bdev_get_queue(rbi->bi_bdev),
706 sh->dev[i].sector); 708 rbi, disk_devt(conf->mddev->gendisk),
709 sh->dev[i].sector);
707 generic_make_request(rbi); 710 generic_make_request(rbi);
708 } 711 }
709 if (!rdev && !rrdev) { 712 if (!rdev && !rrdev) {
@@ -2280,17 +2283,6 @@ schedule_reconstruction(struct stripe_head *sh, struct stripe_head_state *s,
2280 int level = conf->level; 2283 int level = conf->level;
2281 2284
2282 if (rcw) { 2285 if (rcw) {
2283 /* if we are not expanding this is a proper write request, and
2284 * there will be bios with new data to be drained into the
2285 * stripe cache
2286 */
2287 if (!expand) {
2288 sh->reconstruct_state = reconstruct_state_drain_run;
2289 set_bit(STRIPE_OP_BIODRAIN, &s->ops_request);
2290 } else
2291 sh->reconstruct_state = reconstruct_state_run;
2292
2293 set_bit(STRIPE_OP_RECONSTRUCT, &s->ops_request);
2294 2286
2295 for (i = disks; i--; ) { 2287 for (i = disks; i--; ) {
2296 struct r5dev *dev = &sh->dev[i]; 2288 struct r5dev *dev = &sh->dev[i];
@@ -2303,6 +2295,21 @@ schedule_reconstruction(struct stripe_head *sh, struct stripe_head_state *s,
2303 s->locked++; 2295 s->locked++;
2304 } 2296 }
2305 } 2297 }
2298 /* if we are not expanding this is a proper write request, and
2299 * there will be bios with new data to be drained into the
2300 * stripe cache
2301 */
2302 if (!expand) {
2303 if (!s->locked)
2304 /* False alarm, nothing to do */
2305 return;
2306 sh->reconstruct_state = reconstruct_state_drain_run;
2307 set_bit(STRIPE_OP_BIODRAIN, &s->ops_request);
2308 } else
2309 sh->reconstruct_state = reconstruct_state_run;
2310
2311 set_bit(STRIPE_OP_RECONSTRUCT, &s->ops_request);
2312
2306 if (s->locked + conf->max_degraded == disks) 2313 if (s->locked + conf->max_degraded == disks)
2307 if (!test_and_set_bit(STRIPE_FULL_WRITE, &sh->state)) 2314 if (!test_and_set_bit(STRIPE_FULL_WRITE, &sh->state))
2308 atomic_inc(&conf->pending_full_writes); 2315 atomic_inc(&conf->pending_full_writes);
@@ -2311,11 +2318,6 @@ schedule_reconstruction(struct stripe_head *sh, struct stripe_head_state *s,
2311 BUG_ON(!(test_bit(R5_UPTODATE, &sh->dev[pd_idx].flags) || 2318 BUG_ON(!(test_bit(R5_UPTODATE, &sh->dev[pd_idx].flags) ||
2312 test_bit(R5_Wantcompute, &sh->dev[pd_idx].flags))); 2319 test_bit(R5_Wantcompute, &sh->dev[pd_idx].flags)));
2313 2320
2314 sh->reconstruct_state = reconstruct_state_prexor_drain_run;
2315 set_bit(STRIPE_OP_PREXOR, &s->ops_request);
2316 set_bit(STRIPE_OP_BIODRAIN, &s->ops_request);
2317 set_bit(STRIPE_OP_RECONSTRUCT, &s->ops_request);
2318
2319 for (i = disks; i--; ) { 2321 for (i = disks; i--; ) {
2320 struct r5dev *dev = &sh->dev[i]; 2322 struct r5dev *dev = &sh->dev[i];
2321 if (i == pd_idx) 2323 if (i == pd_idx)
@@ -2330,6 +2332,13 @@ schedule_reconstruction(struct stripe_head *sh, struct stripe_head_state *s,
2330 s->locked++; 2332 s->locked++;
2331 } 2333 }
2332 } 2334 }
2335 if (!s->locked)
2336 /* False alarm - nothing to do */
2337 return;
2338 sh->reconstruct_state = reconstruct_state_prexor_drain_run;
2339 set_bit(STRIPE_OP_PREXOR, &s->ops_request);
2340 set_bit(STRIPE_OP_BIODRAIN, &s->ops_request);
2341 set_bit(STRIPE_OP_RECONSTRUCT, &s->ops_request);
2333 } 2342 }
2334 2343
2335 /* keep the parity disk(s) locked while asynchronous operations 2344 /* keep the parity disk(s) locked while asynchronous operations
@@ -2564,6 +2573,8 @@ handle_failed_sync(struct r5conf *conf, struct stripe_head *sh,
2564 int i; 2573 int i;
2565 2574
2566 clear_bit(STRIPE_SYNCING, &sh->state); 2575 clear_bit(STRIPE_SYNCING, &sh->state);
2576 if (test_and_clear_bit(R5_Overlap, &sh->dev[sh->pd_idx].flags))
2577 wake_up(&conf->wait_for_overlap);
2567 s->syncing = 0; 2578 s->syncing = 0;
2568 s->replacing = 0; 2579 s->replacing = 0;
2569 /* There is nothing more to do for sync/check/repair. 2580 /* There is nothing more to do for sync/check/repair.
@@ -2737,6 +2748,7 @@ static void handle_stripe_clean_event(struct r5conf *conf,
2737{ 2748{
2738 int i; 2749 int i;
2739 struct r5dev *dev; 2750 struct r5dev *dev;
2751 int discard_pending = 0;
2740 2752
2741 for (i = disks; i--; ) 2753 for (i = disks; i--; )
2742 if (sh->dev[i].written) { 2754 if (sh->dev[i].written) {
@@ -2765,9 +2777,23 @@ static void handle_stripe_clean_event(struct r5conf *conf,
2765 STRIPE_SECTORS, 2777 STRIPE_SECTORS,
2766 !test_bit(STRIPE_DEGRADED, &sh->state), 2778 !test_bit(STRIPE_DEGRADED, &sh->state),
2767 0); 2779 0);
2768 } 2780 } else if (test_bit(R5_Discard, &dev->flags))
2769 } else if (test_bit(R5_Discard, &sh->dev[i].flags)) 2781 discard_pending = 1;
2770 clear_bit(R5_Discard, &sh->dev[i].flags); 2782 }
2783 if (!discard_pending &&
2784 test_bit(R5_Discard, &sh->dev[sh->pd_idx].flags)) {
2785 clear_bit(R5_Discard, &sh->dev[sh->pd_idx].flags);
2786 clear_bit(R5_UPTODATE, &sh->dev[sh->pd_idx].flags);
2787 if (sh->qd_idx >= 0) {
2788 clear_bit(R5_Discard, &sh->dev[sh->qd_idx].flags);
2789 clear_bit(R5_UPTODATE, &sh->dev[sh->qd_idx].flags);
2790 }
2791 /* now that discard is done we can proceed with any sync */
2792 clear_bit(STRIPE_DISCARD, &sh->state);
2793 if (test_bit(STRIPE_SYNC_REQUESTED, &sh->state))
2794 set_bit(STRIPE_HANDLE, &sh->state);
2795
2796 }
2771 2797
2772 if (test_and_clear_bit(STRIPE_FULL_WRITE, &sh->state)) 2798 if (test_and_clear_bit(STRIPE_FULL_WRITE, &sh->state))
2773 if (atomic_dec_and_test(&conf->pending_full_writes)) 2799 if (atomic_dec_and_test(&conf->pending_full_writes))
@@ -2826,8 +2852,10 @@ static void handle_stripe_dirtying(struct r5conf *conf,
2826 set_bit(STRIPE_HANDLE, &sh->state); 2852 set_bit(STRIPE_HANDLE, &sh->state);
2827 if (rmw < rcw && rmw > 0) { 2853 if (rmw < rcw && rmw > 0) {
2828 /* prefer read-modify-write, but need to get some data */ 2854 /* prefer read-modify-write, but need to get some data */
2829 blk_add_trace_msg(conf->mddev->queue, "raid5 rmw %llu %d", 2855 if (conf->mddev->queue)
2830 (unsigned long long)sh->sector, rmw); 2856 blk_add_trace_msg(conf->mddev->queue,
2857 "raid5 rmw %llu %d",
2858 (unsigned long long)sh->sector, rmw);
2831 for (i = disks; i--; ) { 2859 for (i = disks; i--; ) {
2832 struct r5dev *dev = &sh->dev[i]; 2860 struct r5dev *dev = &sh->dev[i];
2833 if ((dev->towrite || i == sh->pd_idx) && 2861 if ((dev->towrite || i == sh->pd_idx) &&
@@ -2877,7 +2905,7 @@ static void handle_stripe_dirtying(struct r5conf *conf,
2877 } 2905 }
2878 } 2906 }
2879 } 2907 }
2880 if (rcw) 2908 if (rcw && conf->mddev->queue)
2881 blk_add_trace_msg(conf->mddev->queue, "raid5 rcw %llu %d %d %d", 2909 blk_add_trace_msg(conf->mddev->queue, "raid5 rcw %llu %d %d %d",
2882 (unsigned long long)sh->sector, 2910 (unsigned long long)sh->sector,
2883 rcw, qread, test_bit(STRIPE_DELAYED, &sh->state)); 2911 rcw, qread, test_bit(STRIPE_DELAYED, &sh->state));
@@ -3417,9 +3445,15 @@ static void handle_stripe(struct stripe_head *sh)
3417 return; 3445 return;
3418 } 3446 }
3419 3447
3420 if (test_and_clear_bit(STRIPE_SYNC_REQUESTED, &sh->state)) { 3448 if (test_bit(STRIPE_SYNC_REQUESTED, &sh->state)) {
3421 set_bit(STRIPE_SYNCING, &sh->state); 3449 spin_lock(&sh->stripe_lock);
3422 clear_bit(STRIPE_INSYNC, &sh->state); 3450 /* Cannot process 'sync' concurrently with 'discard' */
3451 if (!test_bit(STRIPE_DISCARD, &sh->state) &&
3452 test_and_clear_bit(STRIPE_SYNC_REQUESTED, &sh->state)) {
3453 set_bit(STRIPE_SYNCING, &sh->state);
3454 clear_bit(STRIPE_INSYNC, &sh->state);
3455 }
3456 spin_unlock(&sh->stripe_lock);
3423 } 3457 }
3424 clear_bit(STRIPE_DELAYED, &sh->state); 3458 clear_bit(STRIPE_DELAYED, &sh->state);
3425 3459
@@ -3579,6 +3613,8 @@ static void handle_stripe(struct stripe_head *sh)
3579 test_bit(STRIPE_INSYNC, &sh->state)) { 3613 test_bit(STRIPE_INSYNC, &sh->state)) {
3580 md_done_sync(conf->mddev, STRIPE_SECTORS, 1); 3614 md_done_sync(conf->mddev, STRIPE_SECTORS, 1);
3581 clear_bit(STRIPE_SYNCING, &sh->state); 3615 clear_bit(STRIPE_SYNCING, &sh->state);
3616 if (test_and_clear_bit(R5_Overlap, &sh->dev[sh->pd_idx].flags))
3617 wake_up(&conf->wait_for_overlap);
3582 } 3618 }
3583 3619
3584 /* If the failed drives are just a ReadError, then we might need 3620 /* If the failed drives are just a ReadError, then we might need
@@ -3982,9 +4018,10 @@ static int chunk_aligned_read(struct mddev *mddev, struct bio * raid_bio)
3982 atomic_inc(&conf->active_aligned_reads); 4018 atomic_inc(&conf->active_aligned_reads);
3983 spin_unlock_irq(&conf->device_lock); 4019 spin_unlock_irq(&conf->device_lock);
3984 4020
3985 trace_block_bio_remap(bdev_get_queue(align_bi->bi_bdev), 4021 if (mddev->gendisk)
3986 align_bi, disk_devt(mddev->gendisk), 4022 trace_block_bio_remap(bdev_get_queue(align_bi->bi_bdev),
3987 raid_bio->bi_sector); 4023 align_bi, disk_devt(mddev->gendisk),
4024 raid_bio->bi_sector);
3988 generic_make_request(align_bi); 4025 generic_make_request(align_bi);
3989 return 1; 4026 return 1;
3990 } else { 4027 } else {
@@ -4078,7 +4115,8 @@ static void raid5_unplug(struct blk_plug_cb *blk_cb, bool from_schedule)
4078 } 4115 }
4079 spin_unlock_irq(&conf->device_lock); 4116 spin_unlock_irq(&conf->device_lock);
4080 } 4117 }
4081 trace_block_unplug(mddev->queue, cnt, !from_schedule); 4118 if (mddev->queue)
4119 trace_block_unplug(mddev->queue, cnt, !from_schedule);
4082 kfree(cb); 4120 kfree(cb);
4083} 4121}
4084 4122
@@ -4141,6 +4179,13 @@ static void make_discard_request(struct mddev *mddev, struct bio *bi)
4141 sh = get_active_stripe(conf, logical_sector, 0, 0, 0); 4179 sh = get_active_stripe(conf, logical_sector, 0, 0, 0);
4142 prepare_to_wait(&conf->wait_for_overlap, &w, 4180 prepare_to_wait(&conf->wait_for_overlap, &w,
4143 TASK_UNINTERRUPTIBLE); 4181 TASK_UNINTERRUPTIBLE);
4182 set_bit(R5_Overlap, &sh->dev[sh->pd_idx].flags);
4183 if (test_bit(STRIPE_SYNCING, &sh->state)) {
4184 release_stripe(sh);
4185 schedule();
4186 goto again;
4187 }
4188 clear_bit(R5_Overlap, &sh->dev[sh->pd_idx].flags);
4144 spin_lock_irq(&sh->stripe_lock); 4189 spin_lock_irq(&sh->stripe_lock);
4145 for (d = 0; d < conf->raid_disks; d++) { 4190 for (d = 0; d < conf->raid_disks; d++) {
4146 if (d == sh->pd_idx || d == sh->qd_idx) 4191 if (d == sh->pd_idx || d == sh->qd_idx)
@@ -4153,6 +4198,7 @@ static void make_discard_request(struct mddev *mddev, struct bio *bi)
4153 goto again; 4198 goto again;
4154 } 4199 }
4155 } 4200 }
4201 set_bit(STRIPE_DISCARD, &sh->state);
4156 finish_wait(&conf->wait_for_overlap, &w); 4202 finish_wait(&conf->wait_for_overlap, &w);
4157 for (d = 0; d < conf->raid_disks; d++) { 4203 for (d = 0; d < conf->raid_disks; d++) {
4158 if (d == sh->pd_idx || d == sh->qd_idx) 4204 if (d == sh->pd_idx || d == sh->qd_idx)
diff --git a/drivers/md/raid5.h b/drivers/md/raid5.h
index 18b2c4a8a1fd..b0b663b119a8 100644
--- a/drivers/md/raid5.h
+++ b/drivers/md/raid5.h
@@ -221,10 +221,6 @@ struct stripe_head {
221 struct stripe_operations { 221 struct stripe_operations {
222 int target, target2; 222 int target, target2;
223 enum sum_check_flags zero_sum_result; 223 enum sum_check_flags zero_sum_result;
224 #ifdef CONFIG_MULTICORE_RAID456
225 unsigned long request;
226 wait_queue_head_t wait_for_ops;
227 #endif
228 } ops; 224 } ops;
229 struct r5dev { 225 struct r5dev {
230 /* rreq and rvec are used for the replacement device when 226 /* rreq and rvec are used for the replacement device when
@@ -323,6 +319,7 @@ enum {
323 STRIPE_COMPUTE_RUN, 319 STRIPE_COMPUTE_RUN,
324 STRIPE_OPS_REQ_PENDING, 320 STRIPE_OPS_REQ_PENDING,
325 STRIPE_ON_UNPLUG_LIST, 321 STRIPE_ON_UNPLUG_LIST,
322 STRIPE_DISCARD,
326}; 323};
327 324
328/* 325/*
diff --git a/drivers/media/i2c/m5mols/m5mols_core.c b/drivers/media/i2c/m5mols/m5mols_core.c
index d4e7567b367c..0b899cb6cda1 100644
--- a/drivers/media/i2c/m5mols/m5mols_core.c
+++ b/drivers/media/i2c/m5mols/m5mols_core.c
@@ -724,7 +724,7 @@ static int m5mols_s_stream(struct v4l2_subdev *sd, int enable)
724 if (enable) { 724 if (enable) {
725 if (is_code(code, M5MOLS_RESTYPE_MONITOR)) 725 if (is_code(code, M5MOLS_RESTYPE_MONITOR))
726 ret = m5mols_start_monitor(info); 726 ret = m5mols_start_monitor(info);
727 if (is_code(code, M5MOLS_RESTYPE_CAPTURE)) 727 else if (is_code(code, M5MOLS_RESTYPE_CAPTURE))
728 ret = m5mols_start_capture(info); 728 ret = m5mols_start_capture(info);
729 else 729 else
730 ret = -EINVAL; 730 ret = -EINVAL;
diff --git a/drivers/media/pci/bt8xx/bttv-driver.c b/drivers/media/pci/bt8xx/bttv-driver.c
index ccd18e4ee789..54579e4c740b 100644
--- a/drivers/media/pci/bt8xx/bttv-driver.c
+++ b/drivers/media/pci/bt8xx/bttv-driver.c
@@ -250,17 +250,19 @@ static u8 SRAM_Table[][60] =
250 vdelay start of active video in 2 * field lines relative to 250 vdelay start of active video in 2 * field lines relative to
251 trailing edge of /VRESET pulse (VDELAY register). 251 trailing edge of /VRESET pulse (VDELAY register).
252 sheight height of active video in 2 * field lines. 252 sheight height of active video in 2 * field lines.
253 extraheight Added to sheight for cropcap.bounds.height only
253 videostart0 ITU-R frame line number of the line corresponding 254 videostart0 ITU-R frame line number of the line corresponding
254 to vdelay in the first field. */ 255 to vdelay in the first field. */
255#define CROPCAP(minhdelayx1, hdelayx1, swidth, totalwidth, sqwidth, \ 256#define CROPCAP(minhdelayx1, hdelayx1, swidth, totalwidth, sqwidth, \
256 vdelay, sheight, videostart0) \ 257 vdelay, sheight, extraheight, videostart0) \
257 .cropcap.bounds.left = minhdelayx1, \ 258 .cropcap.bounds.left = minhdelayx1, \
258 /* * 2 because vertically we count field lines times two, */ \ 259 /* * 2 because vertically we count field lines times two, */ \
259 /* e.g. 23 * 2 to 23 * 2 + 576 in PAL-BGHI defrect. */ \ 260 /* e.g. 23 * 2 to 23 * 2 + 576 in PAL-BGHI defrect. */ \
260 .cropcap.bounds.top = (videostart0) * 2 - (vdelay) + MIN_VDELAY, \ 261 .cropcap.bounds.top = (videostart0) * 2 - (vdelay) + MIN_VDELAY, \
261 /* 4 is a safety margin at the end of the line. */ \ 262 /* 4 is a safety margin at the end of the line. */ \
262 .cropcap.bounds.width = (totalwidth) - (minhdelayx1) - 4, \ 263 .cropcap.bounds.width = (totalwidth) - (minhdelayx1) - 4, \
263 .cropcap.bounds.height = (sheight) + (vdelay) - MIN_VDELAY, \ 264 .cropcap.bounds.height = (sheight) + (extraheight) + (vdelay) - \
265 MIN_VDELAY, \
264 .cropcap.defrect.left = hdelayx1, \ 266 .cropcap.defrect.left = hdelayx1, \
265 .cropcap.defrect.top = (videostart0) * 2, \ 267 .cropcap.defrect.top = (videostart0) * 2, \
266 .cropcap.defrect.width = swidth, \ 268 .cropcap.defrect.width = swidth, \
@@ -301,9 +303,10 @@ const struct bttv_tvnorm bttv_tvnorms[] = {
301 /* totalwidth */ 1135, 303 /* totalwidth */ 1135,
302 /* sqwidth */ 944, 304 /* sqwidth */ 944,
303 /* vdelay */ 0x20, 305 /* vdelay */ 0x20,
304 /* bt878 (and bt848?) can capture another 306 /* sheight */ 576,
305 line below active video. */ 307 /* bt878 (and bt848?) can capture another
306 /* sheight */ (576 + 2) + 0x20 - 2, 308 line below active video. */
309 /* extraheight */ 2,
307 /* videostart0 */ 23) 310 /* videostart0 */ 23)
308 },{ 311 },{
309 .v4l2_id = V4L2_STD_NTSC_M | V4L2_STD_NTSC_M_KR, 312 .v4l2_id = V4L2_STD_NTSC_M | V4L2_STD_NTSC_M_KR,
@@ -330,6 +333,7 @@ const struct bttv_tvnorm bttv_tvnorms[] = {
330 /* sqwidth */ 780, 333 /* sqwidth */ 780,
331 /* vdelay */ 0x1a, 334 /* vdelay */ 0x1a,
332 /* sheight */ 480, 335 /* sheight */ 480,
336 /* extraheight */ 0,
333 /* videostart0 */ 23) 337 /* videostart0 */ 23)
334 },{ 338 },{
335 .v4l2_id = V4L2_STD_SECAM, 339 .v4l2_id = V4L2_STD_SECAM,
@@ -355,6 +359,7 @@ const struct bttv_tvnorm bttv_tvnorms[] = {
355 /* sqwidth */ 944, 359 /* sqwidth */ 944,
356 /* vdelay */ 0x20, 360 /* vdelay */ 0x20,
357 /* sheight */ 576, 361 /* sheight */ 576,
362 /* extraheight */ 0,
358 /* videostart0 */ 23) 363 /* videostart0 */ 23)
359 },{ 364 },{
360 .v4l2_id = V4L2_STD_PAL_Nc, 365 .v4l2_id = V4L2_STD_PAL_Nc,
@@ -380,6 +385,7 @@ const struct bttv_tvnorm bttv_tvnorms[] = {
380 /* sqwidth */ 780, 385 /* sqwidth */ 780,
381 /* vdelay */ 0x1a, 386 /* vdelay */ 0x1a,
382 /* sheight */ 576, 387 /* sheight */ 576,
388 /* extraheight */ 0,
383 /* videostart0 */ 23) 389 /* videostart0 */ 23)
384 },{ 390 },{
385 .v4l2_id = V4L2_STD_PAL_M, 391 .v4l2_id = V4L2_STD_PAL_M,
@@ -405,6 +411,7 @@ const struct bttv_tvnorm bttv_tvnorms[] = {
405 /* sqwidth */ 780, 411 /* sqwidth */ 780,
406 /* vdelay */ 0x1a, 412 /* vdelay */ 0x1a,
407 /* sheight */ 480, 413 /* sheight */ 480,
414 /* extraheight */ 0,
408 /* videostart0 */ 23) 415 /* videostart0 */ 23)
409 },{ 416 },{
410 .v4l2_id = V4L2_STD_PAL_N, 417 .v4l2_id = V4L2_STD_PAL_N,
@@ -430,6 +437,7 @@ const struct bttv_tvnorm bttv_tvnorms[] = {
430 /* sqwidth */ 944, 437 /* sqwidth */ 944,
431 /* vdelay */ 0x20, 438 /* vdelay */ 0x20,
432 /* sheight */ 576, 439 /* sheight */ 576,
440 /* extraheight */ 0,
433 /* videostart0 */ 23) 441 /* videostart0 */ 23)
434 },{ 442 },{
435 .v4l2_id = V4L2_STD_NTSC_M_JP, 443 .v4l2_id = V4L2_STD_NTSC_M_JP,
@@ -455,6 +463,7 @@ const struct bttv_tvnorm bttv_tvnorms[] = {
455 /* sqwidth */ 780, 463 /* sqwidth */ 780,
456 /* vdelay */ 0x16, 464 /* vdelay */ 0x16,
457 /* sheight */ 480, 465 /* sheight */ 480,
466 /* extraheight */ 0,
458 /* videostart0 */ 23) 467 /* videostart0 */ 23)
459 },{ 468 },{
460 /* that one hopefully works with the strange timing 469 /* that one hopefully works with the strange timing
@@ -484,6 +493,7 @@ const struct bttv_tvnorm bttv_tvnorms[] = {
484 /* sqwidth */ 944, 493 /* sqwidth */ 944,
485 /* vdelay */ 0x1a, 494 /* vdelay */ 0x1a,
486 /* sheight */ 480, 495 /* sheight */ 480,
496 /* extraheight */ 0,
487 /* videostart0 */ 23) 497 /* videostart0 */ 23)
488 } 498 }
489}; 499};
diff --git a/drivers/media/platform/exynos-gsc/gsc-core.c b/drivers/media/platform/exynos-gsc/gsc-core.c
index 82d9f6ac12f3..33b5ffc8d66d 100644
--- a/drivers/media/platform/exynos-gsc/gsc-core.c
+++ b/drivers/media/platform/exynos-gsc/gsc-core.c
@@ -1054,16 +1054,18 @@ static int gsc_m2m_suspend(struct gsc_dev *gsc)
1054 1054
1055static int gsc_m2m_resume(struct gsc_dev *gsc) 1055static int gsc_m2m_resume(struct gsc_dev *gsc)
1056{ 1056{
1057 struct gsc_ctx *ctx;
1057 unsigned long flags; 1058 unsigned long flags;
1058 1059
1059 spin_lock_irqsave(&gsc->slock, flags); 1060 spin_lock_irqsave(&gsc->slock, flags);
1060 /* Clear for full H/W setup in first run after resume */ 1061 /* Clear for full H/W setup in first run after resume */
1062 ctx = gsc->m2m.ctx;
1061 gsc->m2m.ctx = NULL; 1063 gsc->m2m.ctx = NULL;
1062 spin_unlock_irqrestore(&gsc->slock, flags); 1064 spin_unlock_irqrestore(&gsc->slock, flags);
1063 1065
1064 if (test_and_clear_bit(ST_M2M_SUSPENDED, &gsc->state)) 1066 if (test_and_clear_bit(ST_M2M_SUSPENDED, &gsc->state))
1065 gsc_m2m_job_finish(gsc->m2m.ctx, 1067 gsc_m2m_job_finish(ctx, VB2_BUF_STATE_ERROR);
1066 VB2_BUF_STATE_ERROR); 1068
1067 return 0; 1069 return 0;
1068} 1070}
1069 1071
@@ -1204,7 +1206,7 @@ static int gsc_resume(struct device *dev)
1204 /* Do not resume if the device was idle before system suspend */ 1206 /* Do not resume if the device was idle before system suspend */
1205 spin_lock_irqsave(&gsc->slock, flags); 1207 spin_lock_irqsave(&gsc->slock, flags);
1206 if (!test_and_clear_bit(ST_SUSPEND, &gsc->state) || 1208 if (!test_and_clear_bit(ST_SUSPEND, &gsc->state) ||
1207 !gsc_m2m_active(gsc)) { 1209 !gsc_m2m_opened(gsc)) {
1208 spin_unlock_irqrestore(&gsc->slock, flags); 1210 spin_unlock_irqrestore(&gsc->slock, flags);
1209 return 0; 1211 return 0;
1210 } 1212 }
diff --git a/drivers/media/platform/s5p-fimc/fimc-core.c b/drivers/media/platform/s5p-fimc/fimc-core.c
index e3916bde45cf..0f513dd19f86 100644
--- a/drivers/media/platform/s5p-fimc/fimc-core.c
+++ b/drivers/media/platform/s5p-fimc/fimc-core.c
@@ -850,16 +850,18 @@ static int fimc_m2m_suspend(struct fimc_dev *fimc)
850 850
851static int fimc_m2m_resume(struct fimc_dev *fimc) 851static int fimc_m2m_resume(struct fimc_dev *fimc)
852{ 852{
853 struct fimc_ctx *ctx;
853 unsigned long flags; 854 unsigned long flags;
854 855
855 spin_lock_irqsave(&fimc->slock, flags); 856 spin_lock_irqsave(&fimc->slock, flags);
856 /* Clear for full H/W setup in first run after resume */ 857 /* Clear for full H/W setup in first run after resume */
858 ctx = fimc->m2m.ctx;
857 fimc->m2m.ctx = NULL; 859 fimc->m2m.ctx = NULL;
858 spin_unlock_irqrestore(&fimc->slock, flags); 860 spin_unlock_irqrestore(&fimc->slock, flags);
859 861
860 if (test_and_clear_bit(ST_M2M_SUSPENDED, &fimc->state)) 862 if (test_and_clear_bit(ST_M2M_SUSPENDED, &fimc->state))
861 fimc_m2m_job_finish(fimc->m2m.ctx, 863 fimc_m2m_job_finish(ctx, VB2_BUF_STATE_ERROR);
862 VB2_BUF_STATE_ERROR); 864
863 return 0; 865 return 0;
864} 866}
865 867
diff --git a/drivers/media/platform/s5p-fimc/fimc-lite-reg.c b/drivers/media/platform/s5p-fimc/fimc-lite-reg.c
index f0af0754a7b4..ac9663ce2a49 100644
--- a/drivers/media/platform/s5p-fimc/fimc-lite-reg.c
+++ b/drivers/media/platform/s5p-fimc/fimc-lite-reg.c
@@ -128,10 +128,10 @@ static const u32 src_pixfmt_map[8][3] = {
128void flite_hw_set_source_format(struct fimc_lite *dev, struct flite_frame *f) 128void flite_hw_set_source_format(struct fimc_lite *dev, struct flite_frame *f)
129{ 129{
130 enum v4l2_mbus_pixelcode pixelcode = dev->fmt->mbus_code; 130 enum v4l2_mbus_pixelcode pixelcode = dev->fmt->mbus_code;
131 unsigned int i = ARRAY_SIZE(src_pixfmt_map); 131 int i = ARRAY_SIZE(src_pixfmt_map);
132 u32 cfg; 132 u32 cfg;
133 133
134 while (i-- >= 0) { 134 while (--i >= 0) {
135 if (src_pixfmt_map[i][0] == pixelcode) 135 if (src_pixfmt_map[i][0] == pixelcode)
136 break; 136 break;
137 } 137 }
@@ -224,9 +224,9 @@ static void flite_hw_set_out_order(struct fimc_lite *dev, struct flite_frame *f)
224 { V4L2_MBUS_FMT_VYUY8_2X8, FLITE_REG_CIODMAFMT_CRYCBY }, 224 { V4L2_MBUS_FMT_VYUY8_2X8, FLITE_REG_CIODMAFMT_CRYCBY },
225 }; 225 };
226 u32 cfg = readl(dev->regs + FLITE_REG_CIODMAFMT); 226 u32 cfg = readl(dev->regs + FLITE_REG_CIODMAFMT);
227 unsigned int i = ARRAY_SIZE(pixcode); 227 int i = ARRAY_SIZE(pixcode);
228 228
229 while (i-- >= 0) 229 while (--i >= 0)
230 if (pixcode[i][0] == dev->fmt->mbus_code) 230 if (pixcode[i][0] == dev->fmt->mbus_code)
231 break; 231 break;
232 cfg &= ~FLITE_REG_CIODMAFMT_YCBCR_ORDER_MASK; 232 cfg &= ~FLITE_REG_CIODMAFMT_YCBCR_ORDER_MASK;
diff --git a/drivers/media/platform/s5p-fimc/fimc-lite.c b/drivers/media/platform/s5p-fimc/fimc-lite.c
index bfc4206935c8..bbc35de7db27 100644
--- a/drivers/media/platform/s5p-fimc/fimc-lite.c
+++ b/drivers/media/platform/s5p-fimc/fimc-lite.c
@@ -1408,6 +1408,7 @@ static const struct v4l2_ctrl_config fimc_lite_ctrl = {
1408 .id = V4L2_CTRL_CLASS_USER | 0x1001, 1408 .id = V4L2_CTRL_CLASS_USER | 0x1001,
1409 .type = V4L2_CTRL_TYPE_BOOLEAN, 1409 .type = V4L2_CTRL_TYPE_BOOLEAN,
1410 .name = "Test Pattern 640x480", 1410 .name = "Test Pattern 640x480",
1411 .step = 1,
1411}; 1412};
1412 1413
1413static int fimc_lite_create_capture_subdev(struct fimc_lite *fimc) 1414static int fimc_lite_create_capture_subdev(struct fimc_lite *fimc)
diff --git a/drivers/media/platform/s5p-fimc/fimc-mdevice.c b/drivers/media/platform/s5p-fimc/fimc-mdevice.c
index a17fcb2d5d41..cd38d708ab58 100644
--- a/drivers/media/platform/s5p-fimc/fimc-mdevice.c
+++ b/drivers/media/platform/s5p-fimc/fimc-mdevice.c
@@ -827,7 +827,7 @@ static int fimc_md_link_notify(struct media_pad *source,
827 struct fimc_pipeline *pipeline; 827 struct fimc_pipeline *pipeline;
828 struct v4l2_subdev *sd; 828 struct v4l2_subdev *sd;
829 struct mutex *lock; 829 struct mutex *lock;
830 int ret = 0; 830 int i, ret = 0;
831 int ref_count; 831 int ref_count;
832 832
833 if (media_entity_type(sink->entity) != MEDIA_ENT_T_V4L2_SUBDEV) 833 if (media_entity_type(sink->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
@@ -854,29 +854,28 @@ static int fimc_md_link_notify(struct media_pad *source,
854 return 0; 854 return 0;
855 } 855 }
856 856
857 mutex_lock(lock);
858 ref_count = fimc ? fimc->vid_cap.refcnt : fimc_lite->ref_count;
859
857 if (!(flags & MEDIA_LNK_FL_ENABLED)) { 860 if (!(flags & MEDIA_LNK_FL_ENABLED)) {
858 int i; 861 if (ref_count > 0) {
859 mutex_lock(lock); 862 ret = __fimc_pipeline_close(pipeline);
860 ret = __fimc_pipeline_close(pipeline); 863 if (!ret && fimc)
864 fimc_ctrls_delete(fimc->vid_cap.ctx);
865 }
861 for (i = 0; i < IDX_MAX; i++) 866 for (i = 0; i < IDX_MAX; i++)
862 pipeline->subdevs[i] = NULL; 867 pipeline->subdevs[i] = NULL;
863 if (fimc) 868 } else if (ref_count > 0) {
864 fimc_ctrls_delete(fimc->vid_cap.ctx); 869 /*
865 mutex_unlock(lock); 870 * Link activation. Enable power of pipeline elements only if
866 return ret; 871 * the pipeline is already in use, i.e. its video node is open.
872 * Recreate the controls destroyed during the link deactivation.
873 */
874 ret = __fimc_pipeline_open(pipeline,
875 source->entity, true);
876 if (!ret && fimc)
877 ret = fimc_capture_ctrls_create(fimc);
867 } 878 }
868 /*
869 * Link activation. Enable power of pipeline elements only if the
870 * pipeline is already in use, i.e. its video node is opened.
871 * Recreate the controls destroyed during the link deactivation.
872 */
873 mutex_lock(lock);
874
875 ref_count = fimc ? fimc->vid_cap.refcnt : fimc_lite->ref_count;
876 if (ref_count > 0)
877 ret = __fimc_pipeline_open(pipeline, source->entity, true);
878 if (!ret && fimc)
879 ret = fimc_capture_ctrls_create(fimc);
880 879
881 mutex_unlock(lock); 880 mutex_unlock(lock);
882 return ret ? -EPIPE : ret; 881 return ret ? -EPIPE : ret;
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc.c b/drivers/media/platform/s5p-mfc/s5p_mfc.c
index e84703c314ce..1cb6d57987c6 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc.c
@@ -276,7 +276,7 @@ static void s5p_mfc_handle_frame_new(struct s5p_mfc_ctx *ctx, unsigned int err)
276 unsigned int frame_type; 276 unsigned int frame_type;
277 277
278 dspl_y_addr = s5p_mfc_hw_call(dev->mfc_ops, get_dspl_y_adr, dev); 278 dspl_y_addr = s5p_mfc_hw_call(dev->mfc_ops, get_dspl_y_adr, dev);
279 frame_type = s5p_mfc_hw_call(dev->mfc_ops, get_dec_frame_type, dev); 279 frame_type = s5p_mfc_hw_call(dev->mfc_ops, get_disp_frame_type, ctx);
280 280
281 /* If frame is same as previous then skip and do not dequeue */ 281 /* If frame is same as previous then skip and do not dequeue */
282 if (frame_type == S5P_FIMV_DECODE_FRAME_SKIPPED) { 282 if (frame_type == S5P_FIMV_DECODE_FRAME_SKIPPED) {
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c b/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
index 2356fd52a169..4f6b553c4b2d 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
@@ -232,6 +232,7 @@ static struct mfc_control controls[] = {
232 .minimum = 0, 232 .minimum = 0,
233 .maximum = 1, 233 .maximum = 1,
234 .default_value = 0, 234 .default_value = 0,
235 .step = 1,
235 .menu_skip_mask = 0, 236 .menu_skip_mask = 0,
236 }, 237 },
237 { 238 {
diff --git a/drivers/media/rc/Kconfig b/drivers/media/rc/Kconfig
index 19f3563c61da..5a79c333d45e 100644
--- a/drivers/media/rc/Kconfig
+++ b/drivers/media/rc/Kconfig
@@ -291,7 +291,7 @@ config IR_TTUSBIR
291 291
292config IR_RX51 292config IR_RX51
293 tristate "Nokia N900 IR transmitter diode" 293 tristate "Nokia N900 IR transmitter diode"
294 depends on OMAP_DM_TIMER && LIRC && !ARCH_MULTIPLATFORM 294 depends on OMAP_DM_TIMER && ARCH_OMAP2PLUS && LIRC && !ARCH_MULTIPLATFORM
295 ---help--- 295 ---help---
296 Say Y or M here if you want to enable support for the IR 296 Say Y or M here if you want to enable support for the IR
297 transmitter diode built in the Nokia N900 (RX51) device. 297 transmitter diode built in the Nokia N900 (RX51) device.
diff --git a/drivers/media/v4l2-core/Makefile b/drivers/media/v4l2-core/Makefile
index a9d355230e8e..768aaf62d5dc 100644
--- a/drivers/media/v4l2-core/Makefile
+++ b/drivers/media/v4l2-core/Makefile
@@ -10,7 +10,7 @@ ifeq ($(CONFIG_COMPAT),y)
10 videodev-objs += v4l2-compat-ioctl32.o 10 videodev-objs += v4l2-compat-ioctl32.o
11endif 11endif
12 12
13obj-$(CONFIG_VIDEO_DEV) += videodev.o 13obj-$(CONFIG_VIDEO_V4L2) += videodev.o
14obj-$(CONFIG_VIDEO_V4L2_INT_DEVICE) += v4l2-int-device.o 14obj-$(CONFIG_VIDEO_V4L2_INT_DEVICE) += v4l2-int-device.o
15obj-$(CONFIG_VIDEO_V4L2) += v4l2-common.o 15obj-$(CONFIG_VIDEO_V4L2) += v4l2-common.o
16 16
diff --git a/drivers/misc/mei/hw-me.c b/drivers/misc/mei/hw-me.c
index 45ea7185c003..642c6223fa6c 100644
--- a/drivers/misc/mei/hw-me.c
+++ b/drivers/misc/mei/hw-me.c
@@ -152,6 +152,20 @@ static void mei_me_intr_disable(struct mei_device *dev)
152} 152}
153 153
154/** 154/**
155 * mei_me_hw_reset_release - release device from the reset
156 *
157 * @dev: the device structure
158 */
159static void mei_me_hw_reset_release(struct mei_device *dev)
160{
161 struct mei_me_hw *hw = to_me_hw(dev);
162 u32 hcsr = mei_hcsr_read(hw);
163
164 hcsr |= H_IG;
165 hcsr &= ~H_RST;
166 mei_hcsr_set(hw, hcsr);
167}
168/**
155 * mei_me_hw_reset - resets fw via mei csr register. 169 * mei_me_hw_reset - resets fw via mei csr register.
156 * 170 *
157 * @dev: the device structure 171 * @dev: the device structure
@@ -169,18 +183,14 @@ static void mei_me_hw_reset(struct mei_device *dev, bool intr_enable)
169 if (intr_enable) 183 if (intr_enable)
170 hcsr |= H_IE; 184 hcsr |= H_IE;
171 else 185 else
172 hcsr &= ~H_IE; 186 hcsr |= ~H_IE;
173
174 mei_hcsr_set(hw, hcsr);
175
176 hcsr = mei_hcsr_read(hw) | H_IG;
177 hcsr &= ~H_RST;
178 187
179 mei_hcsr_set(hw, hcsr); 188 mei_hcsr_set(hw, hcsr);
180 189
181 hcsr = mei_hcsr_read(hw); 190 if (dev->dev_state == MEI_DEV_POWER_DOWN)
191 mei_me_hw_reset_release(dev);
182 192
183 dev_dbg(&dev->pdev->dev, "current HCSR = 0x%08x.\n", hcsr); 193 dev_dbg(&dev->pdev->dev, "current HCSR = 0x%08x.\n", mei_hcsr_read(hw));
184} 194}
185 195
186/** 196/**
@@ -466,7 +476,8 @@ irqreturn_t mei_me_irq_thread_handler(int irq, void *dev_id)
466 mutex_unlock(&dev->device_lock); 476 mutex_unlock(&dev->device_lock);
467 return IRQ_HANDLED; 477 return IRQ_HANDLED;
468 } else { 478 } else {
469 dev_dbg(&dev->pdev->dev, "FW not ready.\n"); 479 dev_dbg(&dev->pdev->dev, "Reset Completed.\n");
480 mei_me_hw_reset_release(dev);
470 mutex_unlock(&dev->device_lock); 481 mutex_unlock(&dev->device_lock);
471 return IRQ_HANDLED; 482 return IRQ_HANDLED;
472 } 483 }
diff --git a/drivers/misc/mei/init.c b/drivers/misc/mei/init.c
index 6ec530168afb..356179991a2e 100644
--- a/drivers/misc/mei/init.c
+++ b/drivers/misc/mei/init.c
@@ -183,6 +183,24 @@ void mei_reset(struct mei_device *dev, int interrupts_enabled)
183 mei_cl_all_write_clear(dev); 183 mei_cl_all_write_clear(dev);
184} 184}
185 185
186void mei_stop(struct mei_device *dev)
187{
188 dev_dbg(&dev->pdev->dev, "stopping the device.\n");
189
190 mutex_lock(&dev->device_lock);
191
192 cancel_delayed_work(&dev->timer_work);
193
194 mei_wd_stop(dev);
195
196 dev->dev_state = MEI_DEV_POWER_DOWN;
197 mei_reset(dev, 0);
198
199 mutex_unlock(&dev->device_lock);
200
201 flush_scheduled_work();
202}
203
186 204
187 205
188 206
diff --git a/drivers/misc/mei/mei_dev.h b/drivers/misc/mei/mei_dev.h
index cb80166161f0..97873812e33b 100644
--- a/drivers/misc/mei/mei_dev.h
+++ b/drivers/misc/mei/mei_dev.h
@@ -381,6 +381,7 @@ static inline unsigned long mei_secs_to_jiffies(unsigned long sec)
381void mei_device_init(struct mei_device *dev); 381void mei_device_init(struct mei_device *dev);
382void mei_reset(struct mei_device *dev, int interrupts); 382void mei_reset(struct mei_device *dev, int interrupts);
383int mei_hw_init(struct mei_device *dev); 383int mei_hw_init(struct mei_device *dev);
384void mei_stop(struct mei_device *dev);
384 385
385/* 386/*
386 * MEI interrupt functions prototype 387 * MEI interrupt functions prototype
diff --git a/drivers/misc/mei/pci-me.c b/drivers/misc/mei/pci-me.c
index b40ec0601ab0..b8b5c9c3ad03 100644
--- a/drivers/misc/mei/pci-me.c
+++ b/drivers/misc/mei/pci-me.c
@@ -247,44 +247,14 @@ static void mei_remove(struct pci_dev *pdev)
247 247
248 hw = to_me_hw(dev); 248 hw = to_me_hw(dev);
249 249
250 mutex_lock(&dev->device_lock);
251
252 cancel_delayed_work(&dev->timer_work);
253 250
254 mei_wd_stop(dev); 251 dev_err(&pdev->dev, "stop\n");
252 mei_stop(dev);
255 253
256 mei_pdev = NULL; 254 mei_pdev = NULL;
257 255
258 if (dev->iamthif_cl.state == MEI_FILE_CONNECTED) {
259 dev->iamthif_cl.state = MEI_FILE_DISCONNECTING;
260 mei_cl_disconnect(&dev->iamthif_cl);
261 }
262 if (dev->wd_cl.state == MEI_FILE_CONNECTED) {
263 dev->wd_cl.state = MEI_FILE_DISCONNECTING;
264 mei_cl_disconnect(&dev->wd_cl);
265 }
266
267 /* Unregistering watchdog device */
268 mei_watchdog_unregister(dev); 256 mei_watchdog_unregister(dev);
269 257
270 /* remove entry if already in list */
271 dev_dbg(&pdev->dev, "list del iamthif and wd file list.\n");
272
273 if (dev->open_handle_count > 0)
274 dev->open_handle_count--;
275 mei_cl_unlink(&dev->wd_cl);
276
277 if (dev->open_handle_count > 0)
278 dev->open_handle_count--;
279 mei_cl_unlink(&dev->iamthif_cl);
280
281 dev->iamthif_current_cb = NULL;
282 dev->me_clients_num = 0;
283
284 mutex_unlock(&dev->device_lock);
285
286 flush_scheduled_work();
287
288 /* disable interrupts */ 258 /* disable interrupts */
289 mei_disable_interrupts(dev); 259 mei_disable_interrupts(dev);
290 260
@@ -308,28 +278,20 @@ static int mei_pci_suspend(struct device *device)
308{ 278{
309 struct pci_dev *pdev = to_pci_dev(device); 279 struct pci_dev *pdev = to_pci_dev(device);
310 struct mei_device *dev = pci_get_drvdata(pdev); 280 struct mei_device *dev = pci_get_drvdata(pdev);
311 int err;
312 281
313 if (!dev) 282 if (!dev)
314 return -ENODEV; 283 return -ENODEV;
315 mutex_lock(&dev->device_lock);
316 284
317 cancel_delayed_work(&dev->timer_work); 285 dev_err(&pdev->dev, "suspend\n");
318 286
319 /* Stop watchdog if exists */ 287 mei_stop(dev);
320 err = mei_wd_stop(dev); 288
321 /* Set new mei state */ 289 mei_disable_interrupts(dev);
322 if (dev->dev_state == MEI_DEV_ENABLED ||
323 dev->dev_state == MEI_DEV_RECOVERING_FROM_RESET) {
324 dev->dev_state = MEI_DEV_POWER_DOWN;
325 mei_reset(dev, 0);
326 }
327 mutex_unlock(&dev->device_lock);
328 290
329 free_irq(pdev->irq, dev); 291 free_irq(pdev->irq, dev);
330 pci_disable_msi(pdev); 292 pci_disable_msi(pdev);
331 293
332 return err; 294 return 0;
333} 295}
334 296
335static int mei_pci_resume(struct device *device) 297static int mei_pci_resume(struct device *device)
diff --git a/drivers/misc/vmw_vmci/vmci_datagram.c b/drivers/misc/vmw_vmci/vmci_datagram.c
index ed5c433cd493..f3cdd904fe4d 100644
--- a/drivers/misc/vmw_vmci/vmci_datagram.c
+++ b/drivers/misc/vmw_vmci/vmci_datagram.c
@@ -42,9 +42,11 @@ struct datagram_entry {
42 42
43struct delayed_datagram_info { 43struct delayed_datagram_info {
44 struct datagram_entry *entry; 44 struct datagram_entry *entry;
45 struct vmci_datagram msg;
46 struct work_struct work; 45 struct work_struct work;
47 bool in_dg_host_queue; 46 bool in_dg_host_queue;
47 /* msg and msg_payload must be together. */
48 struct vmci_datagram msg;
49 u8 msg_payload[];
48}; 50};
49 51
50/* Number of in-flight host->host datagrams */ 52/* Number of in-flight host->host datagrams */
diff --git a/drivers/mtd/bcm47xxpart.c b/drivers/mtd/bcm47xxpart.c
index 63feb75cc8e0..9279a9174f84 100644
--- a/drivers/mtd/bcm47xxpart.c
+++ b/drivers/mtd/bcm47xxpart.c
@@ -19,6 +19,12 @@
19/* 10 parts were found on sflash on Netgear WNDR4500 */ 19/* 10 parts were found on sflash on Netgear WNDR4500 */
20#define BCM47XXPART_MAX_PARTS 12 20#define BCM47XXPART_MAX_PARTS 12
21 21
22/*
23 * Amount of bytes we read when analyzing each block of flash memory.
24 * Set it big enough to allow detecting partition and reading important data.
25 */
26#define BCM47XXPART_BYTES_TO_READ 0x404
27
22/* Magics */ 28/* Magics */
23#define BOARD_DATA_MAGIC 0x5246504D /* MPFR */ 29#define BOARD_DATA_MAGIC 0x5246504D /* MPFR */
24#define POT_MAGIC1 0x54544f50 /* POTT */ 30#define POT_MAGIC1 0x54544f50 /* POTT */
@@ -57,17 +63,15 @@ static int bcm47xxpart_parse(struct mtd_info *master,
57 struct trx_header *trx; 63 struct trx_header *trx;
58 int trx_part = -1; 64 int trx_part = -1;
59 int last_trx_part = -1; 65 int last_trx_part = -1;
60 int max_bytes_to_read = 0x8004; 66 int possible_nvram_sizes[] = { 0x8000, 0xF000, 0x10000, };
61 67
62 if (blocksize <= 0x10000) 68 if (blocksize <= 0x10000)
63 blocksize = 0x10000; 69 blocksize = 0x10000;
64 if (blocksize == 0x20000)
65 max_bytes_to_read = 0x18004;
66 70
67 /* Alloc */ 71 /* Alloc */
68 parts = kzalloc(sizeof(struct mtd_partition) * BCM47XXPART_MAX_PARTS, 72 parts = kzalloc(sizeof(struct mtd_partition) * BCM47XXPART_MAX_PARTS,
69 GFP_KERNEL); 73 GFP_KERNEL);
70 buf = kzalloc(max_bytes_to_read, GFP_KERNEL); 74 buf = kzalloc(BCM47XXPART_BYTES_TO_READ, GFP_KERNEL);
71 75
72 /* Parse block by block looking for magics */ 76 /* Parse block by block looking for magics */
73 for (offset = 0; offset <= master->size - blocksize; 77 for (offset = 0; offset <= master->size - blocksize;
@@ -82,7 +86,7 @@ static int bcm47xxpart_parse(struct mtd_info *master,
82 } 86 }
83 87
84 /* Read beginning of the block */ 88 /* Read beginning of the block */
85 if (mtd_read(master, offset, max_bytes_to_read, 89 if (mtd_read(master, offset, BCM47XXPART_BYTES_TO_READ,
86 &bytes_read, (uint8_t *)buf) < 0) { 90 &bytes_read, (uint8_t *)buf) < 0) {
87 pr_err("mtd_read error while parsing (offset: 0x%X)!\n", 91 pr_err("mtd_read error while parsing (offset: 0x%X)!\n",
88 offset); 92 offset);
@@ -96,20 +100,6 @@ static int bcm47xxpart_parse(struct mtd_info *master,
96 continue; 100 continue;
97 } 101 }
98 102
99 /* Standard NVRAM */
100 if (buf[0x000 / 4] == NVRAM_HEADER ||
101 buf[0x1000 / 4] == NVRAM_HEADER ||
102 buf[0x8000 / 4] == NVRAM_HEADER ||
103 (blocksize == 0x20000 && (
104 buf[0x10000 / 4] == NVRAM_HEADER ||
105 buf[0x11000 / 4] == NVRAM_HEADER ||
106 buf[0x18000 / 4] == NVRAM_HEADER))) {
107 bcm47xxpart_add_part(&parts[curr_part++], "nvram",
108 offset, 0);
109 offset = rounddown(offset, blocksize);
110 continue;
111 }
112
113 /* 103 /*
114 * board_data starts with board_id which differs across boards, 104 * board_data starts with board_id which differs across boards,
115 * but we can use 'MPFR' (hopefully) magic at 0x100 105 * but we can use 'MPFR' (hopefully) magic at 0x100
@@ -178,6 +168,30 @@ static int bcm47xxpart_parse(struct mtd_info *master,
178 continue; 168 continue;
179 } 169 }
180 } 170 }
171
172 /* Look for NVRAM at the end of the last block. */
173 for (i = 0; i < ARRAY_SIZE(possible_nvram_sizes); i++) {
174 if (curr_part > BCM47XXPART_MAX_PARTS) {
175 pr_warn("Reached maximum number of partitions, scanning stopped!\n");
176 break;
177 }
178
179 offset = master->size - possible_nvram_sizes[i];
180 if (mtd_read(master, offset, 0x4, &bytes_read,
181 (uint8_t *)buf) < 0) {
182 pr_err("mtd_read error while reading at offset 0x%X!\n",
183 offset);
184 continue;
185 }
186
187 /* Standard NVRAM */
188 if (buf[0] == NVRAM_HEADER) {
189 bcm47xxpart_add_part(&parts[curr_part++], "nvram",
190 master->size - blocksize, 0);
191 break;
192 }
193 }
194
181 kfree(buf); 195 kfree(buf);
182 196
183 /* 197 /*
diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index 43214151b882..42c63927609d 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -1523,6 +1523,14 @@ static int nand_do_read_ops(struct mtd_info *mtd, loff_t from,
1523 oobreadlen -= toread; 1523 oobreadlen -= toread;
1524 } 1524 }
1525 } 1525 }
1526
1527 if (chip->options & NAND_NEED_READRDY) {
1528 /* Apply delay or wait for ready/busy pin */
1529 if (!chip->dev_ready)
1530 udelay(chip->chip_delay);
1531 else
1532 nand_wait_ready(mtd);
1533 }
1526 } else { 1534 } else {
1527 memcpy(buf, chip->buffers->databuf + col, bytes); 1535 memcpy(buf, chip->buffers->databuf + col, bytes);
1528 buf += bytes; 1536 buf += bytes;
@@ -1787,6 +1795,14 @@ static int nand_do_read_oob(struct mtd_info *mtd, loff_t from,
1787 len = min(len, readlen); 1795 len = min(len, readlen);
1788 buf = nand_transfer_oob(chip, buf, ops, len); 1796 buf = nand_transfer_oob(chip, buf, ops, len);
1789 1797
1798 if (chip->options & NAND_NEED_READRDY) {
1799 /* Apply delay or wait for ready/busy pin */
1800 if (!chip->dev_ready)
1801 udelay(chip->chip_delay);
1802 else
1803 nand_wait_ready(mtd);
1804 }
1805
1790 readlen -= len; 1806 readlen -= len;
1791 if (!readlen) 1807 if (!readlen)
1792 break; 1808 break;
diff --git a/drivers/mtd/nand/nand_ids.c b/drivers/mtd/nand/nand_ids.c
index e3aa2748a6e7..9c612388e5de 100644
--- a/drivers/mtd/nand/nand_ids.c
+++ b/drivers/mtd/nand/nand_ids.c
@@ -22,49 +22,51 @@
22* 512 512 Byte page size 22* 512 512 Byte page size
23*/ 23*/
24struct nand_flash_dev nand_flash_ids[] = { 24struct nand_flash_dev nand_flash_ids[] = {
25#define SP_OPTIONS NAND_NEED_READRDY
26#define SP_OPTIONS16 (SP_OPTIONS | NAND_BUSWIDTH_16)
25 27
26#ifdef CONFIG_MTD_NAND_MUSEUM_IDS 28#ifdef CONFIG_MTD_NAND_MUSEUM_IDS
27 {"NAND 1MiB 5V 8-bit", 0x6e, 256, 1, 0x1000, 0}, 29 {"NAND 1MiB 5V 8-bit", 0x6e, 256, 1, 0x1000, SP_OPTIONS},
28 {"NAND 2MiB 5V 8-bit", 0x64, 256, 2, 0x1000, 0}, 30 {"NAND 2MiB 5V 8-bit", 0x64, 256, 2, 0x1000, SP_OPTIONS},
29 {"NAND 4MiB 5V 8-bit", 0x6b, 512, 4, 0x2000, 0}, 31 {"NAND 4MiB 5V 8-bit", 0x6b, 512, 4, 0x2000, SP_OPTIONS},
30 {"NAND 1MiB 3,3V 8-bit", 0xe8, 256, 1, 0x1000, 0}, 32 {"NAND 1MiB 3,3V 8-bit", 0xe8, 256, 1, 0x1000, SP_OPTIONS},
31 {"NAND 1MiB 3,3V 8-bit", 0xec, 256, 1, 0x1000, 0}, 33 {"NAND 1MiB 3,3V 8-bit", 0xec, 256, 1, 0x1000, SP_OPTIONS},
32 {"NAND 2MiB 3,3V 8-bit", 0xea, 256, 2, 0x1000, 0}, 34 {"NAND 2MiB 3,3V 8-bit", 0xea, 256, 2, 0x1000, SP_OPTIONS},
33 {"NAND 4MiB 3,3V 8-bit", 0xd5, 512, 4, 0x2000, 0}, 35 {"NAND 4MiB 3,3V 8-bit", 0xd5, 512, 4, 0x2000, SP_OPTIONS},
34 {"NAND 4MiB 3,3V 8-bit", 0xe3, 512, 4, 0x2000, 0}, 36 {"NAND 4MiB 3,3V 8-bit", 0xe3, 512, 4, 0x2000, SP_OPTIONS},
35 {"NAND 4MiB 3,3V 8-bit", 0xe5, 512, 4, 0x2000, 0}, 37 {"NAND 4MiB 3,3V 8-bit", 0xe5, 512, 4, 0x2000, SP_OPTIONS},
36 {"NAND 8MiB 3,3V 8-bit", 0xd6, 512, 8, 0x2000, 0}, 38 {"NAND 8MiB 3,3V 8-bit", 0xd6, 512, 8, 0x2000, SP_OPTIONS},
37 39
38 {"NAND 8MiB 1,8V 8-bit", 0x39, 512, 8, 0x2000, 0}, 40 {"NAND 8MiB 1,8V 8-bit", 0x39, 512, 8, 0x2000, SP_OPTIONS},
39 {"NAND 8MiB 3,3V 8-bit", 0xe6, 512, 8, 0x2000, 0}, 41 {"NAND 8MiB 3,3V 8-bit", 0xe6, 512, 8, 0x2000, SP_OPTIONS},
40 {"NAND 8MiB 1,8V 16-bit", 0x49, 512, 8, 0x2000, NAND_BUSWIDTH_16}, 42 {"NAND 8MiB 1,8V 16-bit", 0x49, 512, 8, 0x2000, SP_OPTIONS16},
41 {"NAND 8MiB 3,3V 16-bit", 0x59, 512, 8, 0x2000, NAND_BUSWIDTH_16}, 43 {"NAND 8MiB 3,3V 16-bit", 0x59, 512, 8, 0x2000, SP_OPTIONS16},
42#endif 44#endif
43 45
44 {"NAND 16MiB 1,8V 8-bit", 0x33, 512, 16, 0x4000, 0}, 46 {"NAND 16MiB 1,8V 8-bit", 0x33, 512, 16, 0x4000, SP_OPTIONS},
45 {"NAND 16MiB 3,3V 8-bit", 0x73, 512, 16, 0x4000, 0}, 47 {"NAND 16MiB 3,3V 8-bit", 0x73, 512, 16, 0x4000, SP_OPTIONS},
46 {"NAND 16MiB 1,8V 16-bit", 0x43, 512, 16, 0x4000, NAND_BUSWIDTH_16}, 48 {"NAND 16MiB 1,8V 16-bit", 0x43, 512, 16, 0x4000, SP_OPTIONS16},
47 {"NAND 16MiB 3,3V 16-bit", 0x53, 512, 16, 0x4000, NAND_BUSWIDTH_16}, 49 {"NAND 16MiB 3,3V 16-bit", 0x53, 512, 16, 0x4000, SP_OPTIONS16},
48 50
49 {"NAND 32MiB 1,8V 8-bit", 0x35, 512, 32, 0x4000, 0}, 51 {"NAND 32MiB 1,8V 8-bit", 0x35, 512, 32, 0x4000, SP_OPTIONS},
50 {"NAND 32MiB 3,3V 8-bit", 0x75, 512, 32, 0x4000, 0}, 52 {"NAND 32MiB 3,3V 8-bit", 0x75, 512, 32, 0x4000, SP_OPTIONS},
51 {"NAND 32MiB 1,8V 16-bit", 0x45, 512, 32, 0x4000, NAND_BUSWIDTH_16}, 53 {"NAND 32MiB 1,8V 16-bit", 0x45, 512, 32, 0x4000, SP_OPTIONS16},
52 {"NAND 32MiB 3,3V 16-bit", 0x55, 512, 32, 0x4000, NAND_BUSWIDTH_16}, 54 {"NAND 32MiB 3,3V 16-bit", 0x55, 512, 32, 0x4000, SP_OPTIONS16},
53 55
54 {"NAND 64MiB 1,8V 8-bit", 0x36, 512, 64, 0x4000, 0}, 56 {"NAND 64MiB 1,8V 8-bit", 0x36, 512, 64, 0x4000, SP_OPTIONS},
55 {"NAND 64MiB 3,3V 8-bit", 0x76, 512, 64, 0x4000, 0}, 57 {"NAND 64MiB 3,3V 8-bit", 0x76, 512, 64, 0x4000, SP_OPTIONS},
56 {"NAND 64MiB 1,8V 16-bit", 0x46, 512, 64, 0x4000, NAND_BUSWIDTH_16}, 58 {"NAND 64MiB 1,8V 16-bit", 0x46, 512, 64, 0x4000, SP_OPTIONS16},
57 {"NAND 64MiB 3,3V 16-bit", 0x56, 512, 64, 0x4000, NAND_BUSWIDTH_16}, 59 {"NAND 64MiB 3,3V 16-bit", 0x56, 512, 64, 0x4000, SP_OPTIONS16},
58 60
59 {"NAND 128MiB 1,8V 8-bit", 0x78, 512, 128, 0x4000, 0}, 61 {"NAND 128MiB 1,8V 8-bit", 0x78, 512, 128, 0x4000, SP_OPTIONS},
60 {"NAND 128MiB 1,8V 8-bit", 0x39, 512, 128, 0x4000, 0}, 62 {"NAND 128MiB 1,8V 8-bit", 0x39, 512, 128, 0x4000, SP_OPTIONS},
61 {"NAND 128MiB 3,3V 8-bit", 0x79, 512, 128, 0x4000, 0}, 63 {"NAND 128MiB 3,3V 8-bit", 0x79, 512, 128, 0x4000, SP_OPTIONS},
62 {"NAND 128MiB 1,8V 16-bit", 0x72, 512, 128, 0x4000, NAND_BUSWIDTH_16}, 64 {"NAND 128MiB 1,8V 16-bit", 0x72, 512, 128, 0x4000, SP_OPTIONS16},
63 {"NAND 128MiB 1,8V 16-bit", 0x49, 512, 128, 0x4000, NAND_BUSWIDTH_16}, 65 {"NAND 128MiB 1,8V 16-bit", 0x49, 512, 128, 0x4000, SP_OPTIONS16},
64 {"NAND 128MiB 3,3V 16-bit", 0x74, 512, 128, 0x4000, NAND_BUSWIDTH_16}, 66 {"NAND 128MiB 3,3V 16-bit", 0x74, 512, 128, 0x4000, SP_OPTIONS16},
65 {"NAND 128MiB 3,3V 16-bit", 0x59, 512, 128, 0x4000, NAND_BUSWIDTH_16}, 67 {"NAND 128MiB 3,3V 16-bit", 0x59, 512, 128, 0x4000, SP_OPTIONS16},
66 68
67 {"NAND 256MiB 3,3V 8-bit", 0x71, 512, 256, 0x4000, 0}, 69 {"NAND 256MiB 3,3V 8-bit", 0x71, 512, 256, 0x4000, SP_OPTIONS},
68 70
69 /* 71 /*
70 * These are the new chips with large page size. The pagesize and the 72 * These are the new chips with large page size. The pagesize and the
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index 8b4e96e01d6c..6bbd90e1123c 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -1746,6 +1746,8 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
1746 1746
1747 bond_compute_features(bond); 1747 bond_compute_features(bond);
1748 1748
1749 bond_update_speed_duplex(new_slave);
1750
1749 read_lock(&bond->lock); 1751 read_lock(&bond->lock);
1750 1752
1751 new_slave->last_arp_rx = jiffies - 1753 new_slave->last_arp_rx = jiffies -
@@ -1798,8 +1800,6 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
1798 new_slave->link == BOND_LINK_DOWN ? "DOWN" : 1800 new_slave->link == BOND_LINK_DOWN ? "DOWN" :
1799 (new_slave->link == BOND_LINK_UP ? "UP" : "BACK")); 1801 (new_slave->link == BOND_LINK_UP ? "UP" : "BACK"));
1800 1802
1801 bond_update_speed_duplex(new_slave);
1802
1803 if (USES_PRIMARY(bond->params.mode) && bond->params.primary[0]) { 1803 if (USES_PRIMARY(bond->params.mode) && bond->params.primary[0]) {
1804 /* if there is a primary slave, remember it */ 1804 /* if there is a primary slave, remember it */
1805 if (strcmp(bond->params.primary, new_slave->dev->name) == 0) { 1805 if (strcmp(bond->params.primary, new_slave->dev->name) == 0) {
@@ -2374,8 +2374,6 @@ static void bond_miimon_commit(struct bonding *bond)
2374 bond_set_backup_slave(slave); 2374 bond_set_backup_slave(slave);
2375 } 2375 }
2376 2376
2377 bond_update_speed_duplex(slave);
2378
2379 pr_info("%s: link status definitely up for interface %s, %u Mbps %s duplex.\n", 2377 pr_info("%s: link status definitely up for interface %s, %u Mbps %s duplex.\n",
2380 bond->dev->name, slave->dev->name, 2378 bond->dev->name, slave->dev->name,
2381 slave->speed, slave->duplex ? "full" : "half"); 2379 slave->speed, slave->duplex ? "full" : "half");
diff --git a/drivers/net/bonding/bond_sysfs.c b/drivers/net/bonding/bond_sysfs.c
index 1c9e09fbdff8..db103e03ba05 100644
--- a/drivers/net/bonding/bond_sysfs.c
+++ b/drivers/net/bonding/bond_sysfs.c
@@ -183,6 +183,11 @@ int bond_create_slave_symlinks(struct net_device *master,
183 sprintf(linkname, "slave_%s", slave->name); 183 sprintf(linkname, "slave_%s", slave->name);
184 ret = sysfs_create_link(&(master->dev.kobj), &(slave->dev.kobj), 184 ret = sysfs_create_link(&(master->dev.kobj), &(slave->dev.kobj),
185 linkname); 185 linkname);
186
187 /* free the master link created earlier in case of error */
188 if (ret)
189 sysfs_remove_link(&(slave->dev.kobj), "master");
190
186 return ret; 191 return ret;
187 192
188} 193}
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
index a923bc4d5a1f..4046f97378c2 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
@@ -2760,6 +2760,7 @@ load_error2:
2760 bp->port.pmf = 0; 2760 bp->port.pmf = 0;
2761load_error1: 2761load_error1:
2762 bnx2x_napi_disable(bp); 2762 bnx2x_napi_disable(bp);
2763 bnx2x_del_all_napi(bp);
2763 2764
2764 /* clear pf_load status, as it was already set */ 2765 /* clear pf_load status, as it was already set */
2765 if (IS_PF(bp)) 2766 if (IS_PF(bp))
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_dcb.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_dcb.c
index 568205436a15..91ecd6a00d05 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_dcb.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_dcb.c
@@ -2139,12 +2139,12 @@ static u8 bnx2x_dcbnl_get_cap(struct net_device *netdev, int capid, u8 *cap)
2139 break; 2139 break;
2140 default: 2140 default:
2141 BNX2X_ERR("Non valid capability ID\n"); 2141 BNX2X_ERR("Non valid capability ID\n");
2142 rval = -EINVAL; 2142 rval = 1;
2143 break; 2143 break;
2144 } 2144 }
2145 } else { 2145 } else {
2146 DP(BNX2X_MSG_DCB, "DCB disabled\n"); 2146 DP(BNX2X_MSG_DCB, "DCB disabled\n");
2147 rval = -EINVAL; 2147 rval = 1;
2148 } 2148 }
2149 2149
2150 DP(BNX2X_MSG_DCB, "capid %d:%x\n", capid, *cap); 2150 DP(BNX2X_MSG_DCB, "capid %d:%x\n", capid, *cap);
@@ -2170,12 +2170,12 @@ static int bnx2x_dcbnl_get_numtcs(struct net_device *netdev, int tcid, u8 *num)
2170 break; 2170 break;
2171 default: 2171 default:
2172 BNX2X_ERR("Non valid TC-ID\n"); 2172 BNX2X_ERR("Non valid TC-ID\n");
2173 rval = -EINVAL; 2173 rval = 1;
2174 break; 2174 break;
2175 } 2175 }
2176 } else { 2176 } else {
2177 DP(BNX2X_MSG_DCB, "DCB disabled\n"); 2177 DP(BNX2X_MSG_DCB, "DCB disabled\n");
2178 rval = -EINVAL; 2178 rval = 1;
2179 } 2179 }
2180 2180
2181 return rval; 2181 return rval;
@@ -2188,7 +2188,7 @@ static int bnx2x_dcbnl_set_numtcs(struct net_device *netdev, int tcid, u8 num)
2188 return -EINVAL; 2188 return -EINVAL;
2189} 2189}
2190 2190
2191static u8 bnx2x_dcbnl_get_pfc_state(struct net_device *netdev) 2191static u8 bnx2x_dcbnl_get_pfc_state(struct net_device *netdev)
2192{ 2192{
2193 struct bnx2x *bp = netdev_priv(netdev); 2193 struct bnx2x *bp = netdev_priv(netdev);
2194 DP(BNX2X_MSG_DCB, "state = %d\n", bp->dcbx_local_feat.pfc.enabled); 2194 DP(BNX2X_MSG_DCB, "state = %d\n", bp->dcbx_local_feat.pfc.enabled);
@@ -2390,12 +2390,12 @@ static u8 bnx2x_dcbnl_get_featcfg(struct net_device *netdev, int featid,
2390 break; 2390 break;
2391 default: 2391 default:
2392 BNX2X_ERR("Non valid featrue-ID\n"); 2392 BNX2X_ERR("Non valid featrue-ID\n");
2393 rval = -EINVAL; 2393 rval = 1;
2394 break; 2394 break;
2395 } 2395 }
2396 } else { 2396 } else {
2397 DP(BNX2X_MSG_DCB, "DCB disabled\n"); 2397 DP(BNX2X_MSG_DCB, "DCB disabled\n");
2398 rval = -EINVAL; 2398 rval = 1;
2399 } 2399 }
2400 2400
2401 return rval; 2401 return rval;
@@ -2431,12 +2431,12 @@ static u8 bnx2x_dcbnl_set_featcfg(struct net_device *netdev, int featid,
2431 break; 2431 break;
2432 default: 2432 default:
2433 BNX2X_ERR("Non valid featrue-ID\n"); 2433 BNX2X_ERR("Non valid featrue-ID\n");
2434 rval = -EINVAL; 2434 rval = 1;
2435 break; 2435 break;
2436 } 2436 }
2437 } else { 2437 } else {
2438 DP(BNX2X_MSG_DCB, "dcbnl call not valid\n"); 2438 DP(BNX2X_MSG_DCB, "dcbnl call not valid\n");
2439 rval = -EINVAL; 2439 rval = 1;
2440 } 2440 }
2441 2441
2442 return rval; 2442 return rval;
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_stats.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_stats.h
index 364e37ecbc5c..198f6f1c9ad5 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_stats.h
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_stats.h
@@ -459,8 +459,9 @@ struct bnx2x_fw_port_stats_old {
459 459
460#define UPDATE_QSTAT(s, t) \ 460#define UPDATE_QSTAT(s, t) \
461 do { \ 461 do { \
462 qstats->t##_hi = qstats_old->t##_hi + le32_to_cpu(s.hi); \
463 qstats->t##_lo = qstats_old->t##_lo + le32_to_cpu(s.lo); \ 462 qstats->t##_lo = qstats_old->t##_lo + le32_to_cpu(s.lo); \
463 qstats->t##_hi = qstats_old->t##_hi + le32_to_cpu(s.hi) \
464 + ((qstats->t##_lo < qstats_old->t##_lo) ? 1 : 0); \
464 } while (0) 465 } while (0)
465 466
466#define UPDATE_QSTAT_OLD(f) \ 467#define UPDATE_QSTAT_OLD(f) \
diff --git a/drivers/net/ethernet/broadcom/tg3.c b/drivers/net/ethernet/broadcom/tg3.c
index 93729f942358..67d2663b3974 100644
--- a/drivers/net/ethernet/broadcom/tg3.c
+++ b/drivers/net/ethernet/broadcom/tg3.c
@@ -4130,6 +4130,14 @@ static void tg3_phy_copper_begin(struct tg3 *tp)
4130 tp->link_config.active_speed = tp->link_config.speed; 4130 tp->link_config.active_speed = tp->link_config.speed;
4131 tp->link_config.active_duplex = tp->link_config.duplex; 4131 tp->link_config.active_duplex = tp->link_config.duplex;
4132 4132
4133 if (tg3_asic_rev(tp) == ASIC_REV_5714) {
4134 /* With autoneg disabled, 5715 only links up when the
4135 * advertisement register has the configured speed
4136 * enabled.
4137 */
4138 tg3_writephy(tp, MII_ADVERTISE, ADVERTISE_ALL);
4139 }
4140
4133 bmcr = 0; 4141 bmcr = 0;
4134 switch (tp->link_config.speed) { 4142 switch (tp->link_config.speed) {
4135 default: 4143 default:
diff --git a/drivers/net/ethernet/chelsio/cxgb4/t4_hw.c b/drivers/net/ethernet/chelsio/cxgb4/t4_hw.c
index 4ce62031f62f..8049268ce0f2 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/t4_hw.c
+++ b/drivers/net/ethernet/chelsio/cxgb4/t4_hw.c
@@ -497,8 +497,9 @@ int t4_memory_write(struct adapter *adap, int mtype, u32 addr, u32 len,
497} 497}
498 498
499#define EEPROM_STAT_ADDR 0x7bfc 499#define EEPROM_STAT_ADDR 0x7bfc
500#define VPD_BASE 0
501#define VPD_LEN 512 500#define VPD_LEN 512
501#define VPD_BASE 0x400
502#define VPD_BASE_OLD 0
502 503
503/** 504/**
504 * t4_seeprom_wp - enable/disable EEPROM write protection 505 * t4_seeprom_wp - enable/disable EEPROM write protection
@@ -524,7 +525,7 @@ int t4_seeprom_wp(struct adapter *adapter, bool enable)
524int get_vpd_params(struct adapter *adapter, struct vpd_params *p) 525int get_vpd_params(struct adapter *adapter, struct vpd_params *p)
525{ 526{
526 u32 cclk_param, cclk_val; 527 u32 cclk_param, cclk_val;
527 int i, ret; 528 int i, ret, addr;
528 int ec, sn; 529 int ec, sn;
529 u8 *vpd, csum; 530 u8 *vpd, csum;
530 unsigned int vpdr_len, kw_offset, id_len; 531 unsigned int vpdr_len, kw_offset, id_len;
@@ -533,7 +534,12 @@ int get_vpd_params(struct adapter *adapter, struct vpd_params *p)
533 if (!vpd) 534 if (!vpd)
534 return -ENOMEM; 535 return -ENOMEM;
535 536
536 ret = pci_read_vpd(adapter->pdev, VPD_BASE, VPD_LEN, vpd); 537 ret = pci_read_vpd(adapter->pdev, VPD_BASE, sizeof(u32), vpd);
538 if (ret < 0)
539 goto out;
540 addr = *vpd == 0x82 ? VPD_BASE : VPD_BASE_OLD;
541
542 ret = pci_read_vpd(adapter->pdev, addr, VPD_LEN, vpd);
537 if (ret < 0) 543 if (ret < 0)
538 goto out; 544 goto out;
539 545
diff --git a/drivers/net/ethernet/dec/tulip/Kconfig b/drivers/net/ethernet/dec/tulip/Kconfig
index 0c37fb2cc867..1df33c799c00 100644
--- a/drivers/net/ethernet/dec/tulip/Kconfig
+++ b/drivers/net/ethernet/dec/tulip/Kconfig
@@ -108,6 +108,7 @@ config TULIP_DM910X
108config DE4X5 108config DE4X5
109 tristate "Generic DECchip & DIGITAL EtherWORKS PCI/EISA" 109 tristate "Generic DECchip & DIGITAL EtherWORKS PCI/EISA"
110 depends on (PCI || EISA) 110 depends on (PCI || EISA)
111 depends on VIRT_TO_BUS || ALPHA || PPC || SPARC
111 select CRC32 112 select CRC32
112 ---help--- 113 ---help---
113 This is support for the DIGITAL series of PCI/EISA Ethernet cards. 114 This is support for the DIGITAL series of PCI/EISA Ethernet cards.
diff --git a/drivers/net/ethernet/freescale/fec.c b/drivers/net/ethernet/freescale/fec.c
index 069a155d16ed..911d0253dbb2 100644
--- a/drivers/net/ethernet/freescale/fec.c
+++ b/drivers/net/ethernet/freescale/fec.c
@@ -934,24 +934,28 @@ static void fec_enet_adjust_link(struct net_device *ndev)
934 goto spin_unlock; 934 goto spin_unlock;
935 } 935 }
936 936
937 /* Duplex link change */
938 if (phy_dev->link) { 937 if (phy_dev->link) {
939 if (fep->full_duplex != phy_dev->duplex) { 938 if (!fep->link) {
940 fec_restart(ndev, phy_dev->duplex);
941 /* prevent unnecessary second fec_restart() below */
942 fep->link = phy_dev->link; 939 fep->link = phy_dev->link;
943 status_change = 1; 940 status_change = 1;
944 } 941 }
945 }
946 942
947 /* Link on or off change */ 943 if (fep->full_duplex != phy_dev->duplex)
948 if (phy_dev->link != fep->link) { 944 status_change = 1;
949 fep->link = phy_dev->link; 945
950 if (phy_dev->link) 946 if (phy_dev->speed != fep->speed) {
947 fep->speed = phy_dev->speed;
948 status_change = 1;
949 }
950
951 /* if any of the above changed restart the FEC */
952 if (status_change)
951 fec_restart(ndev, phy_dev->duplex); 953 fec_restart(ndev, phy_dev->duplex);
952 else 954 } else {
955 if (fep->link) {
953 fec_stop(ndev); 956 fec_stop(ndev);
954 status_change = 1; 957 status_change = 1;
958 }
955 } 959 }
956 960
957spin_unlock: 961spin_unlock:
@@ -1328,7 +1332,7 @@ static int fec_enet_ioctl(struct net_device *ndev, struct ifreq *rq, int cmd)
1328static void fec_enet_free_buffers(struct net_device *ndev) 1332static void fec_enet_free_buffers(struct net_device *ndev)
1329{ 1333{
1330 struct fec_enet_private *fep = netdev_priv(ndev); 1334 struct fec_enet_private *fep = netdev_priv(ndev);
1331 int i; 1335 unsigned int i;
1332 struct sk_buff *skb; 1336 struct sk_buff *skb;
1333 struct bufdesc *bdp; 1337 struct bufdesc *bdp;
1334 1338
@@ -1352,7 +1356,7 @@ static void fec_enet_free_buffers(struct net_device *ndev)
1352static int fec_enet_alloc_buffers(struct net_device *ndev) 1356static int fec_enet_alloc_buffers(struct net_device *ndev)
1353{ 1357{
1354 struct fec_enet_private *fep = netdev_priv(ndev); 1358 struct fec_enet_private *fep = netdev_priv(ndev);
1355 int i; 1359 unsigned int i;
1356 struct sk_buff *skb; 1360 struct sk_buff *skb;
1357 struct bufdesc *bdp; 1361 struct bufdesc *bdp;
1358 1362
@@ -1437,6 +1441,7 @@ fec_enet_close(struct net_device *ndev)
1437 struct fec_enet_private *fep = netdev_priv(ndev); 1441 struct fec_enet_private *fep = netdev_priv(ndev);
1438 1442
1439 /* Don't know what to do yet. */ 1443 /* Don't know what to do yet. */
1444 napi_disable(&fep->napi);
1440 fep->opened = 0; 1445 fep->opened = 0;
1441 netif_stop_queue(ndev); 1446 netif_stop_queue(ndev);
1442 fec_stop(ndev); 1447 fec_stop(ndev);
@@ -1593,7 +1598,7 @@ static int fec_enet_init(struct net_device *ndev)
1593 struct fec_enet_private *fep = netdev_priv(ndev); 1598 struct fec_enet_private *fep = netdev_priv(ndev);
1594 struct bufdesc *cbd_base; 1599 struct bufdesc *cbd_base;
1595 struct bufdesc *bdp; 1600 struct bufdesc *bdp;
1596 int i; 1601 unsigned int i;
1597 1602
1598 /* Allocate memory for buffer descriptors. */ 1603 /* Allocate memory for buffer descriptors. */
1599 cbd_base = dma_alloc_coherent(NULL, PAGE_SIZE, &fep->bd_dma, 1604 cbd_base = dma_alloc_coherent(NULL, PAGE_SIZE, &fep->bd_dma,
diff --git a/drivers/net/ethernet/freescale/fec.h b/drivers/net/ethernet/freescale/fec.h
index f5390071efd0..eb4372962839 100644
--- a/drivers/net/ethernet/freescale/fec.h
+++ b/drivers/net/ethernet/freescale/fec.h
@@ -240,6 +240,7 @@ struct fec_enet_private {
240 phy_interface_t phy_interface; 240 phy_interface_t phy_interface;
241 int link; 241 int link;
242 int full_duplex; 242 int full_duplex;
243 int speed;
243 struct completion mdio_done; 244 struct completion mdio_done;
244 int irq[FEC_IRQ_NUM]; 245 int irq[FEC_IRQ_NUM];
245 int bufdesc_ex; 246 int bufdesc_ex;
diff --git a/drivers/net/ethernet/freescale/fec_ptp.c b/drivers/net/ethernet/freescale/fec_ptp.c
index 1f17ca0f2201..0d8df400a479 100644
--- a/drivers/net/ethernet/freescale/fec_ptp.c
+++ b/drivers/net/ethernet/freescale/fec_ptp.c
@@ -128,6 +128,7 @@ void fec_ptp_start_cyclecounter(struct net_device *ndev)
128 128
129 spin_unlock_irqrestore(&fep->tmreg_lock, flags); 129 spin_unlock_irqrestore(&fep->tmreg_lock, flags);
130} 130}
131EXPORT_SYMBOL(fec_ptp_start_cyclecounter);
131 132
132/** 133/**
133 * fec_ptp_adjfreq - adjust ptp cycle frequency 134 * fec_ptp_adjfreq - adjust ptp cycle frequency
@@ -318,6 +319,7 @@ int fec_ptp_ioctl(struct net_device *ndev, struct ifreq *ifr, int cmd)
318 return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ? 319 return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ?
319 -EFAULT : 0; 320 -EFAULT : 0;
320} 321}
322EXPORT_SYMBOL(fec_ptp_ioctl);
321 323
322/** 324/**
323 * fec_time_keep - call timecounter_read every second to avoid timer overrun 325 * fec_time_keep - call timecounter_read every second to avoid timer overrun
@@ -383,3 +385,4 @@ void fec_ptp_init(struct net_device *ndev, struct platform_device *pdev)
383 pr_info("registered PHC device on %s\n", ndev->name); 385 pr_info("registered PHC device on %s\n", ndev->name);
384 } 386 }
385} 387}
388EXPORT_SYMBOL(fec_ptp_init);
diff --git a/drivers/net/ethernet/intel/igb/e1000_82575.c b/drivers/net/ethernet/intel/igb/e1000_82575.c
index b64542acfa34..12b1d8480808 100644
--- a/drivers/net/ethernet/intel/igb/e1000_82575.c
+++ b/drivers/net/ethernet/intel/igb/e1000_82575.c
@@ -1818,27 +1818,32 @@ out:
1818 **/ 1818 **/
1819void igb_vmdq_set_anti_spoofing_pf(struct e1000_hw *hw, bool enable, int pf) 1819void igb_vmdq_set_anti_spoofing_pf(struct e1000_hw *hw, bool enable, int pf)
1820{ 1820{
1821 u32 dtxswc; 1821 u32 reg_val, reg_offset;
1822 1822
1823 switch (hw->mac.type) { 1823 switch (hw->mac.type) {
1824 case e1000_82576: 1824 case e1000_82576:
1825 reg_offset = E1000_DTXSWC;
1826 break;
1825 case e1000_i350: 1827 case e1000_i350:
1826 dtxswc = rd32(E1000_DTXSWC); 1828 reg_offset = E1000_TXSWC;
1827 if (enable) {
1828 dtxswc |= (E1000_DTXSWC_MAC_SPOOF_MASK |
1829 E1000_DTXSWC_VLAN_SPOOF_MASK);
1830 /* The PF can spoof - it has to in order to
1831 * support emulation mode NICs */
1832 dtxswc ^= (1 << pf | 1 << (pf + MAX_NUM_VFS));
1833 } else {
1834 dtxswc &= ~(E1000_DTXSWC_MAC_SPOOF_MASK |
1835 E1000_DTXSWC_VLAN_SPOOF_MASK);
1836 }
1837 wr32(E1000_DTXSWC, dtxswc);
1838 break; 1829 break;
1839 default: 1830 default:
1840 break; 1831 return;
1832 }
1833
1834 reg_val = rd32(reg_offset);
1835 if (enable) {
1836 reg_val |= (E1000_DTXSWC_MAC_SPOOF_MASK |
1837 E1000_DTXSWC_VLAN_SPOOF_MASK);
1838 /* The PF can spoof - it has to in order to
1839 * support emulation mode NICs
1840 */
1841 reg_val ^= (1 << pf | 1 << (pf + MAX_NUM_VFS));
1842 } else {
1843 reg_val &= ~(E1000_DTXSWC_MAC_SPOOF_MASK |
1844 E1000_DTXSWC_VLAN_SPOOF_MASK);
1841 } 1845 }
1846 wr32(reg_offset, reg_val);
1842} 1847}
1843 1848
1844/** 1849/**
diff --git a/drivers/net/ethernet/intel/igb/igb_hwmon.c b/drivers/net/ethernet/intel/igb/igb_hwmon.c
index 4623502054d5..0478a1abe541 100644
--- a/drivers/net/ethernet/intel/igb/igb_hwmon.c
+++ b/drivers/net/ethernet/intel/igb/igb_hwmon.c
@@ -39,7 +39,7 @@
39#include <linux/pci.h> 39#include <linux/pci.h>
40 40
41#ifdef CONFIG_IGB_HWMON 41#ifdef CONFIG_IGB_HWMON
42struct i2c_board_info i350_sensor_info = { 42static struct i2c_board_info i350_sensor_info = {
43 I2C_BOARD_INFO("i350bb", (0Xf8 >> 1)), 43 I2C_BOARD_INFO("i350bb", (0Xf8 >> 1)),
44}; 44};
45 45
diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c
index 4dbd62968c7a..8496adfc6a68 100644
--- a/drivers/net/ethernet/intel/igb/igb_main.c
+++ b/drivers/net/ethernet/intel/igb/igb_main.c
@@ -2542,8 +2542,8 @@ static void igb_probe_vfs(struct igb_adapter *adapter)
2542 if ((hw->mac.type == e1000_i210) || (hw->mac.type == e1000_i211)) 2542 if ((hw->mac.type == e1000_i210) || (hw->mac.type == e1000_i211))
2543 return; 2543 return;
2544 2544
2545 igb_enable_sriov(pdev, max_vfs);
2546 pci_sriov_set_totalvfs(pdev, 7); 2545 pci_sriov_set_totalvfs(pdev, 7);
2546 igb_enable_sriov(pdev, max_vfs);
2547 2547
2548#endif /* CONFIG_PCI_IOV */ 2548#endif /* CONFIG_PCI_IOV */
2549} 2549}
@@ -2652,7 +2652,7 @@ static int igb_sw_init(struct igb_adapter *adapter)
2652 if (max_vfs > 7) { 2652 if (max_vfs > 7) {
2653 dev_warn(&pdev->dev, 2653 dev_warn(&pdev->dev,
2654 "Maximum of 7 VFs per PF, using max\n"); 2654 "Maximum of 7 VFs per PF, using max\n");
2655 adapter->vfs_allocated_count = 7; 2655 max_vfs = adapter->vfs_allocated_count = 7;
2656 } else 2656 } else
2657 adapter->vfs_allocated_count = max_vfs; 2657 adapter->vfs_allocated_count = max_vfs;
2658 if (adapter->vfs_allocated_count) 2658 if (adapter->vfs_allocated_count)
diff --git a/drivers/net/ethernet/intel/igb/igb_ptp.c b/drivers/net/ethernet/intel/igb/igb_ptp.c
index 0987822359f0..0a237507ee85 100644
--- a/drivers/net/ethernet/intel/igb/igb_ptp.c
+++ b/drivers/net/ethernet/intel/igb/igb_ptp.c
@@ -740,7 +740,7 @@ void igb_ptp_init(struct igb_adapter *adapter)
740 case e1000_82576: 740 case e1000_82576:
741 snprintf(adapter->ptp_caps.name, 16, "%pm", netdev->dev_addr); 741 snprintf(adapter->ptp_caps.name, 16, "%pm", netdev->dev_addr);
742 adapter->ptp_caps.owner = THIS_MODULE; 742 adapter->ptp_caps.owner = THIS_MODULE;
743 adapter->ptp_caps.max_adj = 1000000000; 743 adapter->ptp_caps.max_adj = 999999881;
744 adapter->ptp_caps.n_ext_ts = 0; 744 adapter->ptp_caps.n_ext_ts = 0;
745 adapter->ptp_caps.pps = 0; 745 adapter->ptp_caps.pps = 0;
746 adapter->ptp_caps.adjfreq = igb_ptp_adjfreq_82576; 746 adapter->ptp_caps.adjfreq = igb_ptp_adjfreq_82576;
diff --git a/drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c b/drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c
index c3db6cd69b68..2b6cb5ca48ee 100644
--- a/drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c
+++ b/drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c
@@ -944,9 +944,17 @@ free_queue_irqs:
944 free_irq(adapter->msix_entries[vector].vector, 944 free_irq(adapter->msix_entries[vector].vector,
945 adapter->q_vector[vector]); 945 adapter->q_vector[vector]);
946 } 946 }
947 pci_disable_msix(adapter->pdev); 947 /* This failure is non-recoverable - it indicates the system is
948 kfree(adapter->msix_entries); 948 * out of MSIX vector resources and the VF driver cannot run
949 adapter->msix_entries = NULL; 949 * without them. Set the number of msix vectors to zero
950 * indicating that not enough can be allocated. The error
951 * will be returned to the user indicating device open failed.
952 * Any further attempts to force the driver to open will also
953 * fail. The only way to recover is to unload the driver and
954 * reload it again. If the system has recovered some MSIX
955 * vectors then it may succeed.
956 */
957 adapter->num_msix_vectors = 0;
950 return err; 958 return err;
951} 959}
952 960
@@ -2572,6 +2580,15 @@ static int ixgbevf_open(struct net_device *netdev)
2572 struct ixgbe_hw *hw = &adapter->hw; 2580 struct ixgbe_hw *hw = &adapter->hw;
2573 int err; 2581 int err;
2574 2582
2583 /* A previous failure to open the device because of a lack of
2584 * available MSIX vector resources may have reset the number
2585 * of msix vectors variable to zero. The only way to recover
2586 * is to unload/reload the driver and hope that the system has
2587 * been able to recover some MSIX vector resources.
2588 */
2589 if (!adapter->num_msix_vectors)
2590 return -ENOMEM;
2591
2575 /* disallow open during test */ 2592 /* disallow open during test */
2576 if (test_bit(__IXGBEVF_TESTING, &adapter->state)) 2593 if (test_bit(__IXGBEVF_TESTING, &adapter->state))
2577 return -EBUSY; 2594 return -EBUSY;
@@ -2628,7 +2645,6 @@ static int ixgbevf_open(struct net_device *netdev)
2628 2645
2629err_req_irq: 2646err_req_irq:
2630 ixgbevf_down(adapter); 2647 ixgbevf_down(adapter);
2631 ixgbevf_free_irq(adapter);
2632err_setup_rx: 2648err_setup_rx:
2633 ixgbevf_free_all_rx_resources(adapter); 2649 ixgbevf_free_all_rx_resources(adapter);
2634err_setup_tx: 2650err_setup_tx:
diff --git a/drivers/net/ethernet/lantiq_etop.c b/drivers/net/ethernet/lantiq_etop.c
index 6a2127489af7..bfdb06860397 100644
--- a/drivers/net/ethernet/lantiq_etop.c
+++ b/drivers/net/ethernet/lantiq_etop.c
@@ -769,7 +769,7 @@ ltq_etop_probe(struct platform_device *pdev)
769 return 0; 769 return 0;
770 770
771err_free: 771err_free:
772 kfree(dev); 772 free_netdev(dev);
773err_out: 773err_out:
774 return err; 774 return err;
775} 775}
diff --git a/drivers/net/ethernet/mellanox/mlx4/en_netdev.c b/drivers/net/ethernet/mellanox/mlx4/en_netdev.c
index 995d4b6d5c1e..f278b10ef714 100644
--- a/drivers/net/ethernet/mellanox/mlx4/en_netdev.c
+++ b/drivers/net/ethernet/mellanox/mlx4/en_netdev.c
@@ -1637,6 +1637,17 @@ void mlx4_en_stop_port(struct net_device *dev, int detach)
1637 /* Flush multicast filter */ 1637 /* Flush multicast filter */
1638 mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, 0, 1, MLX4_MCAST_CONFIG); 1638 mlx4_SET_MCAST_FLTR(mdev->dev, priv->port, 0, 1, MLX4_MCAST_CONFIG);
1639 1639
1640 /* Remove flow steering rules for the port*/
1641 if (mdev->dev->caps.steering_mode ==
1642 MLX4_STEERING_MODE_DEVICE_MANAGED) {
1643 ASSERT_RTNL();
1644 list_for_each_entry_safe(flow, tmp_flow,
1645 &priv->ethtool_list, list) {
1646 mlx4_flow_detach(mdev->dev, flow->id);
1647 list_del(&flow->list);
1648 }
1649 }
1650
1640 mlx4_en_destroy_drop_qp(priv); 1651 mlx4_en_destroy_drop_qp(priv);
1641 1652
1642 /* Free TX Rings */ 1653 /* Free TX Rings */
@@ -1657,17 +1668,6 @@ void mlx4_en_stop_port(struct net_device *dev, int detach)
1657 if (!(mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAGS2_REASSIGN_MAC_EN)) 1668 if (!(mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAGS2_REASSIGN_MAC_EN))
1658 mdev->mac_removed[priv->port] = 1; 1669 mdev->mac_removed[priv->port] = 1;
1659 1670
1660 /* Remove flow steering rules for the port*/
1661 if (mdev->dev->caps.steering_mode ==
1662 MLX4_STEERING_MODE_DEVICE_MANAGED) {
1663 ASSERT_RTNL();
1664 list_for_each_entry_safe(flow, tmp_flow,
1665 &priv->ethtool_list, list) {
1666 mlx4_flow_detach(mdev->dev, flow->id);
1667 list_del(&flow->list);
1668 }
1669 }
1670
1671 /* Free RX Rings */ 1671 /* Free RX Rings */
1672 for (i = 0; i < priv->rx_ring_num; i++) { 1672 for (i = 0; i < priv->rx_ring_num; i++) {
1673 mlx4_en_deactivate_rx_ring(priv, &priv->rx_ring[i]); 1673 mlx4_en_deactivate_rx_ring(priv, &priv->rx_ring[i]);
diff --git a/drivers/net/ethernet/mellanox/mlx4/eq.c b/drivers/net/ethernet/mellanox/mlx4/eq.c
index 251ae2f93116..8e3123a1df88 100644
--- a/drivers/net/ethernet/mellanox/mlx4/eq.c
+++ b/drivers/net/ethernet/mellanox/mlx4/eq.c
@@ -771,7 +771,7 @@ int mlx4_MAP_EQ_wrapper(struct mlx4_dev *dev, int slave,
771 struct mlx4_slave_event_eq_info *event_eq = 771 struct mlx4_slave_event_eq_info *event_eq =
772 priv->mfunc.master.slave_state[slave].event_eq; 772 priv->mfunc.master.slave_state[slave].event_eq;
773 u32 in_modifier = vhcr->in_modifier; 773 u32 in_modifier = vhcr->in_modifier;
774 u32 eqn = in_modifier & 0x1FF; 774 u32 eqn = in_modifier & 0x3FF;
775 u64 in_param = vhcr->in_param; 775 u64 in_param = vhcr->in_param;
776 int err = 0; 776 int err = 0;
777 int i; 777 int i;
diff --git a/drivers/net/ethernet/mellanox/mlx4/resource_tracker.c b/drivers/net/ethernet/mellanox/mlx4/resource_tracker.c
index 2995687f1aee..1391b52f443a 100644
--- a/drivers/net/ethernet/mellanox/mlx4/resource_tracker.c
+++ b/drivers/net/ethernet/mellanox/mlx4/resource_tracker.c
@@ -99,6 +99,7 @@ struct res_qp {
99 struct list_head mcg_list; 99 struct list_head mcg_list;
100 spinlock_t mcg_spl; 100 spinlock_t mcg_spl;
101 int local_qpn; 101 int local_qpn;
102 atomic_t ref_count;
102}; 103};
103 104
104enum res_mtt_states { 105enum res_mtt_states {
@@ -197,6 +198,7 @@ enum res_fs_rule_states {
197 198
198struct res_fs_rule { 199struct res_fs_rule {
199 struct res_common com; 200 struct res_common com;
201 int qpn;
200}; 202};
201 203
202static void *res_tracker_lookup(struct rb_root *root, u64 res_id) 204static void *res_tracker_lookup(struct rb_root *root, u64 res_id)
@@ -355,7 +357,7 @@ static int mpt_mask(struct mlx4_dev *dev)
355 return dev->caps.num_mpts - 1; 357 return dev->caps.num_mpts - 1;
356} 358}
357 359
358static void *find_res(struct mlx4_dev *dev, int res_id, 360static void *find_res(struct mlx4_dev *dev, u64 res_id,
359 enum mlx4_resource type) 361 enum mlx4_resource type)
360{ 362{
361 struct mlx4_priv *priv = mlx4_priv(dev); 363 struct mlx4_priv *priv = mlx4_priv(dev);
@@ -447,6 +449,7 @@ static struct res_common *alloc_qp_tr(int id)
447 ret->local_qpn = id; 449 ret->local_qpn = id;
448 INIT_LIST_HEAD(&ret->mcg_list); 450 INIT_LIST_HEAD(&ret->mcg_list);
449 spin_lock_init(&ret->mcg_spl); 451 spin_lock_init(&ret->mcg_spl);
452 atomic_set(&ret->ref_count, 0);
450 453
451 return &ret->com; 454 return &ret->com;
452} 455}
@@ -554,7 +557,7 @@ static struct res_common *alloc_xrcdn_tr(int id)
554 return &ret->com; 557 return &ret->com;
555} 558}
556 559
557static struct res_common *alloc_fs_rule_tr(u64 id) 560static struct res_common *alloc_fs_rule_tr(u64 id, int qpn)
558{ 561{
559 struct res_fs_rule *ret; 562 struct res_fs_rule *ret;
560 563
@@ -564,7 +567,7 @@ static struct res_common *alloc_fs_rule_tr(u64 id)
564 567
565 ret->com.res_id = id; 568 ret->com.res_id = id;
566 ret->com.state = RES_FS_RULE_ALLOCATED; 569 ret->com.state = RES_FS_RULE_ALLOCATED;
567 570 ret->qpn = qpn;
568 return &ret->com; 571 return &ret->com;
569} 572}
570 573
@@ -602,7 +605,7 @@ static struct res_common *alloc_tr(u64 id, enum mlx4_resource type, int slave,
602 ret = alloc_xrcdn_tr(id); 605 ret = alloc_xrcdn_tr(id);
603 break; 606 break;
604 case RES_FS_RULE: 607 case RES_FS_RULE:
605 ret = alloc_fs_rule_tr(id); 608 ret = alloc_fs_rule_tr(id, extra);
606 break; 609 break;
607 default: 610 default:
608 return NULL; 611 return NULL;
@@ -671,10 +674,14 @@ undo:
671 674
672static int remove_qp_ok(struct res_qp *res) 675static int remove_qp_ok(struct res_qp *res)
673{ 676{
674 if (res->com.state == RES_QP_BUSY) 677 if (res->com.state == RES_QP_BUSY || atomic_read(&res->ref_count) ||
678 !list_empty(&res->mcg_list)) {
679 pr_err("resource tracker: fail to remove qp, state %d, ref_count %d\n",
680 res->com.state, atomic_read(&res->ref_count));
675 return -EBUSY; 681 return -EBUSY;
676 else if (res->com.state != RES_QP_RESERVED) 682 } else if (res->com.state != RES_QP_RESERVED) {
677 return -EPERM; 683 return -EPERM;
684 }
678 685
679 return 0; 686 return 0;
680} 687}
@@ -3124,6 +3131,7 @@ int mlx4_QP_FLOW_STEERING_ATTACH_wrapper(struct mlx4_dev *dev, int slave,
3124 struct list_head *rlist = &tracker->slave_list[slave].res_list[RES_MAC]; 3131 struct list_head *rlist = &tracker->slave_list[slave].res_list[RES_MAC];
3125 int err; 3132 int err;
3126 int qpn; 3133 int qpn;
3134 struct res_qp *rqp;
3127 struct mlx4_net_trans_rule_hw_ctrl *ctrl; 3135 struct mlx4_net_trans_rule_hw_ctrl *ctrl;
3128 struct _rule_hw *rule_header; 3136 struct _rule_hw *rule_header;
3129 int header_id; 3137 int header_id;
@@ -3134,7 +3142,7 @@ int mlx4_QP_FLOW_STEERING_ATTACH_wrapper(struct mlx4_dev *dev, int slave,
3134 3142
3135 ctrl = (struct mlx4_net_trans_rule_hw_ctrl *)inbox->buf; 3143 ctrl = (struct mlx4_net_trans_rule_hw_ctrl *)inbox->buf;
3136 qpn = be32_to_cpu(ctrl->qpn) & 0xffffff; 3144 qpn = be32_to_cpu(ctrl->qpn) & 0xffffff;
3137 err = get_res(dev, slave, qpn, RES_QP, NULL); 3145 err = get_res(dev, slave, qpn, RES_QP, &rqp);
3138 if (err) { 3146 if (err) {
3139 pr_err("Steering rule with qpn 0x%x rejected.\n", qpn); 3147 pr_err("Steering rule with qpn 0x%x rejected.\n", qpn);
3140 return err; 3148 return err;
@@ -3175,14 +3183,16 @@ int mlx4_QP_FLOW_STEERING_ATTACH_wrapper(struct mlx4_dev *dev, int slave,
3175 if (err) 3183 if (err)
3176 goto err_put; 3184 goto err_put;
3177 3185
3178 err = add_res_range(dev, slave, vhcr->out_param, 1, RES_FS_RULE, 0); 3186 err = add_res_range(dev, slave, vhcr->out_param, 1, RES_FS_RULE, qpn);
3179 if (err) { 3187 if (err) {
3180 mlx4_err(dev, "Fail to add flow steering resources.\n "); 3188 mlx4_err(dev, "Fail to add flow steering resources.\n ");
3181 /* detach rule*/ 3189 /* detach rule*/
3182 mlx4_cmd(dev, vhcr->out_param, 0, 0, 3190 mlx4_cmd(dev, vhcr->out_param, 0, 0,
3183 MLX4_QP_FLOW_STEERING_DETACH, MLX4_CMD_TIME_CLASS_A, 3191 MLX4_QP_FLOW_STEERING_DETACH, MLX4_CMD_TIME_CLASS_A,
3184 MLX4_CMD_NATIVE); 3192 MLX4_CMD_NATIVE);
3193 goto err_put;
3185 } 3194 }
3195 atomic_inc(&rqp->ref_count);
3186err_put: 3196err_put:
3187 put_res(dev, slave, qpn, RES_QP); 3197 put_res(dev, slave, qpn, RES_QP);
3188 return err; 3198 return err;
@@ -3195,20 +3205,35 @@ int mlx4_QP_FLOW_STEERING_DETACH_wrapper(struct mlx4_dev *dev, int slave,
3195 struct mlx4_cmd_info *cmd) 3205 struct mlx4_cmd_info *cmd)
3196{ 3206{
3197 int err; 3207 int err;
3208 struct res_qp *rqp;
3209 struct res_fs_rule *rrule;
3198 3210
3199 if (dev->caps.steering_mode != 3211 if (dev->caps.steering_mode !=
3200 MLX4_STEERING_MODE_DEVICE_MANAGED) 3212 MLX4_STEERING_MODE_DEVICE_MANAGED)
3201 return -EOPNOTSUPP; 3213 return -EOPNOTSUPP;
3202 3214
3215 err = get_res(dev, slave, vhcr->in_param, RES_FS_RULE, &rrule);
3216 if (err)
3217 return err;
3218 /* Release the rule form busy state before removal */
3219 put_res(dev, slave, vhcr->in_param, RES_FS_RULE);
3220 err = get_res(dev, slave, rrule->qpn, RES_QP, &rqp);
3221 if (err)
3222 return err;
3223
3203 err = rem_res_range(dev, slave, vhcr->in_param, 1, RES_FS_RULE, 0); 3224 err = rem_res_range(dev, slave, vhcr->in_param, 1, RES_FS_RULE, 0);
3204 if (err) { 3225 if (err) {
3205 mlx4_err(dev, "Fail to remove flow steering resources.\n "); 3226 mlx4_err(dev, "Fail to remove flow steering resources.\n ");
3206 return err; 3227 goto out;
3207 } 3228 }
3208 3229
3209 err = mlx4_cmd(dev, vhcr->in_param, 0, 0, 3230 err = mlx4_cmd(dev, vhcr->in_param, 0, 0,
3210 MLX4_QP_FLOW_STEERING_DETACH, MLX4_CMD_TIME_CLASS_A, 3231 MLX4_QP_FLOW_STEERING_DETACH, MLX4_CMD_TIME_CLASS_A,
3211 MLX4_CMD_NATIVE); 3232 MLX4_CMD_NATIVE);
3233 if (!err)
3234 atomic_dec(&rqp->ref_count);
3235out:
3236 put_res(dev, slave, rrule->qpn, RES_QP);
3212 return err; 3237 return err;
3213} 3238}
3214 3239
@@ -3806,6 +3831,7 @@ void mlx4_delete_all_resources_for_slave(struct mlx4_dev *dev, int slave)
3806 mutex_lock(&priv->mfunc.master.res_tracker.slave_list[slave].mutex); 3831 mutex_lock(&priv->mfunc.master.res_tracker.slave_list[slave].mutex);
3807 /*VLAN*/ 3832 /*VLAN*/
3808 rem_slave_macs(dev, slave); 3833 rem_slave_macs(dev, slave);
3834 rem_slave_fs_rule(dev, slave);
3809 rem_slave_qps(dev, slave); 3835 rem_slave_qps(dev, slave);
3810 rem_slave_srqs(dev, slave); 3836 rem_slave_srqs(dev, slave);
3811 rem_slave_cqs(dev, slave); 3837 rem_slave_cqs(dev, slave);
@@ -3814,6 +3840,5 @@ void mlx4_delete_all_resources_for_slave(struct mlx4_dev *dev, int slave)
3814 rem_slave_mtts(dev, slave); 3840 rem_slave_mtts(dev, slave);
3815 rem_slave_counters(dev, slave); 3841 rem_slave_counters(dev, slave);
3816 rem_slave_xrcdns(dev, slave); 3842 rem_slave_xrcdns(dev, slave);
3817 rem_slave_fs_rule(dev, slave);
3818 mutex_unlock(&priv->mfunc.master.res_tracker.slave_list[slave].mutex); 3843 mutex_unlock(&priv->mfunc.master.res_tracker.slave_list[slave].mutex);
3819} 3844}
diff --git a/drivers/net/ethernet/nxp/lpc_eth.c b/drivers/net/ethernet/nxp/lpc_eth.c
index c4122c86f829..efa29b712d5f 100644
--- a/drivers/net/ethernet/nxp/lpc_eth.c
+++ b/drivers/net/ethernet/nxp/lpc_eth.c
@@ -1472,7 +1472,8 @@ static int lpc_eth_drv_probe(struct platform_device *pdev)
1472 } 1472 }
1473 platform_set_drvdata(pdev, ndev); 1473 platform_set_drvdata(pdev, ndev);
1474 1474
1475 if (lpc_mii_init(pldat) != 0) 1475 ret = lpc_mii_init(pldat);
1476 if (ret)
1476 goto err_out_unregister_netdev; 1477 goto err_out_unregister_netdev;
1477 1478
1478 netdev_info(ndev, "LPC mac at 0x%08x irq %d\n", 1479 netdev_info(ndev, "LPC mac at 0x%08x irq %d\n",
diff --git a/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c b/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c
index 39ab4d09faaa..73ce7dd6b954 100644
--- a/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c
+++ b/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c
@@ -1726,9 +1726,9 @@ pch_gbe_clean_rx(struct pch_gbe_adapter *adapter,
1726 1726
1727 skb->protocol = eth_type_trans(skb, netdev); 1727 skb->protocol = eth_type_trans(skb, netdev);
1728 if (tcp_ip_status & PCH_GBE_RXD_ACC_STAT_TCPIPOK) 1728 if (tcp_ip_status & PCH_GBE_RXD_ACC_STAT_TCPIPOK)
1729 skb->ip_summed = CHECKSUM_NONE;
1730 else
1731 skb->ip_summed = CHECKSUM_UNNECESSARY; 1729 skb->ip_summed = CHECKSUM_UNNECESSARY;
1730 else
1731 skb->ip_summed = CHECKSUM_NONE;
1732 1732
1733 napi_gro_receive(&adapter->napi, skb); 1733 napi_gro_receive(&adapter->napi, skb);
1734 (*work_done)++; 1734 (*work_done)++;
diff --git a/drivers/net/ethernet/renesas/sh_eth.c b/drivers/net/ethernet/renesas/sh_eth.c
index 33e96176e4d8..bf5e3cf97c4d 100644
--- a/drivers/net/ethernet/renesas/sh_eth.c
+++ b/drivers/net/ethernet/renesas/sh_eth.c
@@ -2220,6 +2220,7 @@ static void sh_eth_tsu_init(struct sh_eth_private *mdp)
2220/* MDIO bus release function */ 2220/* MDIO bus release function */
2221static int sh_mdio_release(struct net_device *ndev) 2221static int sh_mdio_release(struct net_device *ndev)
2222{ 2222{
2223 struct sh_eth_private *mdp = netdev_priv(ndev);
2223 struct mii_bus *bus = dev_get_drvdata(&ndev->dev); 2224 struct mii_bus *bus = dev_get_drvdata(&ndev->dev);
2224 2225
2225 /* unregister mdio bus */ 2226 /* unregister mdio bus */
@@ -2234,6 +2235,9 @@ static int sh_mdio_release(struct net_device *ndev)
2234 /* free bitbang info */ 2235 /* free bitbang info */
2235 free_mdio_bitbang(bus); 2236 free_mdio_bitbang(bus);
2236 2237
2238 /* free bitbang memory */
2239 kfree(mdp->bitbang);
2240
2237 return 0; 2241 return 0;
2238} 2242}
2239 2243
@@ -2262,6 +2266,7 @@ static int sh_mdio_init(struct net_device *ndev, int id,
2262 bitbang->ctrl.ops = &bb_ops; 2266 bitbang->ctrl.ops = &bb_ops;
2263 2267
2264 /* MII controller setting */ 2268 /* MII controller setting */
2269 mdp->bitbang = bitbang;
2265 mdp->mii_bus = alloc_mdio_bitbang(&bitbang->ctrl); 2270 mdp->mii_bus = alloc_mdio_bitbang(&bitbang->ctrl);
2266 if (!mdp->mii_bus) { 2271 if (!mdp->mii_bus) {
2267 ret = -ENOMEM; 2272 ret = -ENOMEM;
@@ -2441,6 +2446,11 @@ static int sh_eth_drv_probe(struct platform_device *pdev)
2441 } 2446 }
2442 mdp->tsu_addr = ioremap(rtsu->start, 2447 mdp->tsu_addr = ioremap(rtsu->start,
2443 resource_size(rtsu)); 2448 resource_size(rtsu));
2449 if (mdp->tsu_addr == NULL) {
2450 ret = -ENOMEM;
2451 dev_err(&pdev->dev, "TSU ioremap failed.\n");
2452 goto out_release;
2453 }
2444 mdp->port = devno % 2; 2454 mdp->port = devno % 2;
2445 ndev->features = NETIF_F_HW_VLAN_FILTER; 2455 ndev->features = NETIF_F_HW_VLAN_FILTER;
2446 } 2456 }
diff --git a/drivers/net/ethernet/renesas/sh_eth.h b/drivers/net/ethernet/renesas/sh_eth.h
index bae84fd2e73a..e6655678458e 100644
--- a/drivers/net/ethernet/renesas/sh_eth.h
+++ b/drivers/net/ethernet/renesas/sh_eth.h
@@ -705,6 +705,7 @@ struct sh_eth_private {
705 const u16 *reg_offset; 705 const u16 *reg_offset;
706 void __iomem *addr; 706 void __iomem *addr;
707 void __iomem *tsu_addr; 707 void __iomem *tsu_addr;
708 struct bb_info *bitbang;
708 u32 num_rx_ring; 709 u32 num_rx_ring;
709 u32 num_tx_ring; 710 u32 num_tx_ring;
710 dma_addr_t rx_desc_dma; 711 dma_addr_t rx_desc_dma;
diff --git a/drivers/net/ethernet/sfc/nic.c b/drivers/net/ethernet/sfc/nic.c
index 0ad790cc473c..eaa8e874a3cb 100644
--- a/drivers/net/ethernet/sfc/nic.c
+++ b/drivers/net/ethernet/sfc/nic.c
@@ -376,7 +376,8 @@ efx_may_push_tx_desc(struct efx_tx_queue *tx_queue, unsigned int write_count)
376 return false; 376 return false;
377 377
378 tx_queue->empty_read_count = 0; 378 tx_queue->empty_read_count = 0;
379 return ((empty_read_count ^ write_count) & ~EFX_EMPTY_COUNT_VALID) == 0; 379 return ((empty_read_count ^ write_count) & ~EFX_EMPTY_COUNT_VALID) == 0
380 && tx_queue->write_count - write_count == 1;
380} 381}
381 382
382/* For each entry inserted into the software descriptor ring, create a 383/* For each entry inserted into the software descriptor ring, create a
diff --git a/drivers/net/ethernet/ti/cpsw.c b/drivers/net/ethernet/ti/cpsw.c
index 01ffbc486982..df32a090d08e 100644
--- a/drivers/net/ethernet/ti/cpsw.c
+++ b/drivers/net/ethernet/ti/cpsw.c
@@ -905,7 +905,7 @@ static netdev_tx_t cpsw_ndo_start_xmit(struct sk_buff *skb,
905 /* If there is no more tx desc left free then we need to 905 /* If there is no more tx desc left free then we need to
906 * tell the kernel to stop sending us tx frames. 906 * tell the kernel to stop sending us tx frames.
907 */ 907 */
908 if (unlikely(cpdma_check_free_tx_desc(priv->txch))) 908 if (unlikely(!cpdma_check_free_tx_desc(priv->txch)))
909 netif_stop_queue(ndev); 909 netif_stop_queue(ndev);
910 910
911 return NETDEV_TX_OK; 911 return NETDEV_TX_OK;
@@ -1364,7 +1364,7 @@ static int cpsw_probe_dt(struct cpsw_platform_data *data,
1364 struct platform_device *mdio; 1364 struct platform_device *mdio;
1365 1365
1366 parp = of_get_property(slave_node, "phy_id", &lenp); 1366 parp = of_get_property(slave_node, "phy_id", &lenp);
1367 if ((parp == NULL) && (lenp != (sizeof(void *) * 2))) { 1367 if ((parp == NULL) || (lenp != (sizeof(void *) * 2))) {
1368 pr_err("Missing slave[%d] phy_id property\n", i); 1368 pr_err("Missing slave[%d] phy_id property\n", i);
1369 ret = -EINVAL; 1369 ret = -EINVAL;
1370 goto error_ret; 1370 goto error_ret;
diff --git a/drivers/net/ethernet/ti/davinci_emac.c b/drivers/net/ethernet/ti/davinci_emac.c
index 52c05366599a..ae1b77aa199f 100644
--- a/drivers/net/ethernet/ti/davinci_emac.c
+++ b/drivers/net/ethernet/ti/davinci_emac.c
@@ -1102,7 +1102,7 @@ static int emac_dev_xmit(struct sk_buff *skb, struct net_device *ndev)
1102 /* If there is no more tx desc left free then we need to 1102 /* If there is no more tx desc left free then we need to
1103 * tell the kernel to stop sending us tx frames. 1103 * tell the kernel to stop sending us tx frames.
1104 */ 1104 */
1105 if (unlikely(cpdma_check_free_tx_desc(priv->txchan))) 1105 if (unlikely(!cpdma_check_free_tx_desc(priv->txchan)))
1106 netif_stop_queue(ndev); 1106 netif_stop_queue(ndev);
1107 1107
1108 return NETDEV_TX_OK; 1108 return NETDEV_TX_OK;
diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
index 37add21a3d7d..59ac143dec25 100644
--- a/drivers/net/netconsole.c
+++ b/drivers/net/netconsole.c
@@ -666,6 +666,7 @@ static int netconsole_netdev_event(struct notifier_block *this,
666 goto done; 666 goto done;
667 667
668 spin_lock_irqsave(&target_list_lock, flags); 668 spin_lock_irqsave(&target_list_lock, flags);
669restart:
669 list_for_each_entry(nt, &target_list, list) { 670 list_for_each_entry(nt, &target_list, list) {
670 netconsole_target_get(nt); 671 netconsole_target_get(nt);
671 if (nt->np.dev == dev) { 672 if (nt->np.dev == dev) {
@@ -678,15 +679,17 @@ static int netconsole_netdev_event(struct notifier_block *this,
678 case NETDEV_UNREGISTER: 679 case NETDEV_UNREGISTER:
679 /* 680 /*
680 * rtnl_lock already held 681 * rtnl_lock already held
682 * we might sleep in __netpoll_cleanup()
681 */ 683 */
682 if (nt->np.dev) { 684 spin_unlock_irqrestore(&target_list_lock, flags);
683 __netpoll_cleanup(&nt->np); 685 __netpoll_cleanup(&nt->np);
684 dev_put(nt->np.dev); 686 spin_lock_irqsave(&target_list_lock, flags);
685 nt->np.dev = NULL; 687 dev_put(nt->np.dev);
686 } 688 nt->np.dev = NULL;
687 nt->enabled = 0; 689 nt->enabled = 0;
688 stopped = true; 690 stopped = true;
689 break; 691 netconsole_target_put(nt);
692 goto restart;
690 } 693 }
691 } 694 }
692 netconsole_target_put(nt); 695 netconsole_target_put(nt);
diff --git a/drivers/net/usb/Kconfig b/drivers/net/usb/Kconfig
index 3b6e9b83342d..7c769d8e25ad 100644
--- a/drivers/net/usb/Kconfig
+++ b/drivers/net/usb/Kconfig
@@ -268,7 +268,7 @@ config USB_NET_SMSC75XX
268 select CRC16 268 select CRC16
269 select CRC32 269 select CRC32
270 help 270 help
271 This option adds support for SMSC LAN95XX based USB 2.0 271 This option adds support for SMSC LAN75XX based USB 2.0
272 Gigabit Ethernet adapters. 272 Gigabit Ethernet adapters.
273 273
274config USB_NET_SMSC95XX 274config USB_NET_SMSC95XX
diff --git a/drivers/net/usb/cdc_mbim.c b/drivers/net/usb/cdc_mbim.c
index 248d2dc765a5..16c842997291 100644
--- a/drivers/net/usb/cdc_mbim.c
+++ b/drivers/net/usb/cdc_mbim.c
@@ -68,18 +68,9 @@ static int cdc_mbim_bind(struct usbnet *dev, struct usb_interface *intf)
68 struct cdc_ncm_ctx *ctx; 68 struct cdc_ncm_ctx *ctx;
69 struct usb_driver *subdriver = ERR_PTR(-ENODEV); 69 struct usb_driver *subdriver = ERR_PTR(-ENODEV);
70 int ret = -ENODEV; 70 int ret = -ENODEV;
71 u8 data_altsetting = CDC_NCM_DATA_ALTSETTING_NCM; 71 u8 data_altsetting = cdc_ncm_select_altsetting(dev, intf);
72 struct cdc_mbim_state *info = (void *)&dev->data; 72 struct cdc_mbim_state *info = (void *)&dev->data;
73 73
74 /* see if interface supports MBIM alternate setting */
75 if (intf->num_altsetting == 2) {
76 if (!cdc_ncm_comm_intf_is_mbim(intf->cur_altsetting))
77 usb_set_interface(dev->udev,
78 intf->cur_altsetting->desc.bInterfaceNumber,
79 CDC_NCM_COMM_ALTSETTING_MBIM);
80 data_altsetting = CDC_NCM_DATA_ALTSETTING_MBIM;
81 }
82
83 /* Probably NCM, defer for cdc_ncm_bind */ 74 /* Probably NCM, defer for cdc_ncm_bind */
84 if (!cdc_ncm_comm_intf_is_mbim(intf->cur_altsetting)) 75 if (!cdc_ncm_comm_intf_is_mbim(intf->cur_altsetting))
85 goto err; 76 goto err;
diff --git a/drivers/net/usb/cdc_ncm.c b/drivers/net/usb/cdc_ncm.c
index 61b74a2b89ac..4709fa3497cf 100644
--- a/drivers/net/usb/cdc_ncm.c
+++ b/drivers/net/usb/cdc_ncm.c
@@ -55,6 +55,14 @@
55 55
56#define DRIVER_VERSION "14-Mar-2012" 56#define DRIVER_VERSION "14-Mar-2012"
57 57
58#if IS_ENABLED(CONFIG_USB_NET_CDC_MBIM)
59static bool prefer_mbim = true;
60#else
61static bool prefer_mbim;
62#endif
63module_param(prefer_mbim, bool, S_IRUGO | S_IWUSR);
64MODULE_PARM_DESC(prefer_mbim, "Prefer MBIM setting on dual NCM/MBIM functions");
65
58static void cdc_ncm_txpath_bh(unsigned long param); 66static void cdc_ncm_txpath_bh(unsigned long param);
59static void cdc_ncm_tx_timeout_start(struct cdc_ncm_ctx *ctx); 67static void cdc_ncm_tx_timeout_start(struct cdc_ncm_ctx *ctx);
60static enum hrtimer_restart cdc_ncm_tx_timer_cb(struct hrtimer *hr_timer); 68static enum hrtimer_restart cdc_ncm_tx_timer_cb(struct hrtimer *hr_timer);
@@ -550,9 +558,12 @@ void cdc_ncm_unbind(struct usbnet *dev, struct usb_interface *intf)
550} 558}
551EXPORT_SYMBOL_GPL(cdc_ncm_unbind); 559EXPORT_SYMBOL_GPL(cdc_ncm_unbind);
552 560
553static int cdc_ncm_bind(struct usbnet *dev, struct usb_interface *intf) 561/* Select the MBIM altsetting iff it is preferred and available,
562 * returning the number of the corresponding data interface altsetting
563 */
564u8 cdc_ncm_select_altsetting(struct usbnet *dev, struct usb_interface *intf)
554{ 565{
555 int ret; 566 struct usb_host_interface *alt;
556 567
557 /* The MBIM spec defines a NCM compatible default altsetting, 568 /* The MBIM spec defines a NCM compatible default altsetting,
558 * which we may have matched: 569 * which we may have matched:
@@ -568,23 +579,27 @@ static int cdc_ncm_bind(struct usbnet *dev, struct usb_interface *intf)
568 * endpoint descriptors, shall be constructed according to 579 * endpoint descriptors, shall be constructed according to
569 * the rules given in section 6 (USB Device Model) of this 580 * the rules given in section 6 (USB Device Model) of this
570 * specification." 581 * specification."
571 *
572 * Do not bind to such interfaces, allowing cdc_mbim to handle
573 * them
574 */ 582 */
575#if IS_ENABLED(CONFIG_USB_NET_CDC_MBIM) 583 if (prefer_mbim && intf->num_altsetting == 2) {
576 if ((intf->num_altsetting == 2) && 584 alt = usb_altnum_to_altsetting(intf, CDC_NCM_COMM_ALTSETTING_MBIM);
577 !usb_set_interface(dev->udev, 585 if (alt && cdc_ncm_comm_intf_is_mbim(alt) &&
578 intf->cur_altsetting->desc.bInterfaceNumber, 586 !usb_set_interface(dev->udev,
579 CDC_NCM_COMM_ALTSETTING_MBIM)) { 587 intf->cur_altsetting->desc.bInterfaceNumber,
580 if (cdc_ncm_comm_intf_is_mbim(intf->cur_altsetting)) 588 CDC_NCM_COMM_ALTSETTING_MBIM))
581 return -ENODEV; 589 return CDC_NCM_DATA_ALTSETTING_MBIM;
582 else
583 usb_set_interface(dev->udev,
584 intf->cur_altsetting->desc.bInterfaceNumber,
585 CDC_NCM_COMM_ALTSETTING_NCM);
586 } 590 }
587#endif 591 return CDC_NCM_DATA_ALTSETTING_NCM;
592}
593EXPORT_SYMBOL_GPL(cdc_ncm_select_altsetting);
594
595static int cdc_ncm_bind(struct usbnet *dev, struct usb_interface *intf)
596{
597 int ret;
598
599 /* MBIM backwards compatible function? */
600 cdc_ncm_select_altsetting(dev, intf);
601 if (cdc_ncm_comm_intf_is_mbim(intf->cur_altsetting))
602 return -ENODEV;
588 603
589 /* NCM data altsetting is always 1 */ 604 /* NCM data altsetting is always 1 */
590 ret = cdc_ncm_bind_common(dev, intf, 1); 605 ret = cdc_ncm_bind_common(dev, intf, 1);
diff --git a/drivers/net/usb/qmi_wwan.c b/drivers/net/usb/qmi_wwan.c
index efb5c7c33a28..968d5d50751d 100644
--- a/drivers/net/usb/qmi_wwan.c
+++ b/drivers/net/usb/qmi_wwan.c
@@ -139,16 +139,9 @@ static int qmi_wwan_bind(struct usbnet *dev, struct usb_interface *intf)
139 139
140 BUILD_BUG_ON((sizeof(((struct usbnet *)0)->data) < sizeof(struct qmi_wwan_state))); 140 BUILD_BUG_ON((sizeof(((struct usbnet *)0)->data) < sizeof(struct qmi_wwan_state)));
141 141
142 /* control and data is shared? */ 142 /* set up initial state */
143 if (intf->cur_altsetting->desc.bNumEndpoints == 3) { 143 info->control = intf;
144 info->control = intf; 144 info->data = intf;
145 info->data = intf;
146 goto shared;
147 }
148
149 /* else require a single interrupt status endpoint on control intf */
150 if (intf->cur_altsetting->desc.bNumEndpoints != 1)
151 goto err;
152 145
153 /* and a number of CDC descriptors */ 146 /* and a number of CDC descriptors */
154 while (len > 3) { 147 while (len > 3) {
@@ -207,25 +200,14 @@ next_desc:
207 buf += h->bLength; 200 buf += h->bLength;
208 } 201 }
209 202
210 /* did we find all the required ones? */ 203 /* Use separate control and data interfaces if we found a CDC Union */
211 if (!(found & (1 << USB_CDC_HEADER_TYPE)) || 204 if (cdc_union) {
212 !(found & (1 << USB_CDC_UNION_TYPE))) { 205 info->data = usb_ifnum_to_if(dev->udev, cdc_union->bSlaveInterface0);
213 dev_err(&intf->dev, "CDC functional descriptors missing\n"); 206 if (desc->bInterfaceNumber != cdc_union->bMasterInterface0 || !info->data) {
214 goto err; 207 dev_err(&intf->dev, "bogus CDC Union: master=%u, slave=%u\n",
215 } 208 cdc_union->bMasterInterface0, cdc_union->bSlaveInterface0);
216 209 goto err;
217 /* verify CDC Union */ 210 }
218 if (desc->bInterfaceNumber != cdc_union->bMasterInterface0) {
219 dev_err(&intf->dev, "bogus CDC Union: master=%u\n", cdc_union->bMasterInterface0);
220 goto err;
221 }
222
223 /* need to save these for unbind */
224 info->control = intf;
225 info->data = usb_ifnum_to_if(dev->udev, cdc_union->bSlaveInterface0);
226 if (!info->data) {
227 dev_err(&intf->dev, "bogus CDC Union: slave=%u\n", cdc_union->bSlaveInterface0);
228 goto err;
229 } 211 }
230 212
231 /* errors aren't fatal - we can live with the dynamic address */ 213 /* errors aren't fatal - we can live with the dynamic address */
@@ -235,11 +217,12 @@ next_desc:
235 } 217 }
236 218
237 /* claim data interface and set it up */ 219 /* claim data interface and set it up */
238 status = usb_driver_claim_interface(driver, info->data, dev); 220 if (info->control != info->data) {
239 if (status < 0) 221 status = usb_driver_claim_interface(driver, info->data, dev);
240 goto err; 222 if (status < 0)
223 goto err;
224 }
241 225
242shared:
243 status = qmi_wwan_register_subdriver(dev); 226 status = qmi_wwan_register_subdriver(dev);
244 if (status < 0 && info->control != info->data) { 227 if (status < 0 && info->control != info->data) {
245 usb_set_intfdata(info->data, NULL); 228 usb_set_intfdata(info->data, NULL);
diff --git a/drivers/net/wireless/ath/ath9k/ar9003_calib.c b/drivers/net/wireless/ath/ath9k/ar9003_calib.c
index 4cc13940c895..f76c3ca07a45 100644
--- a/drivers/net/wireless/ath/ath9k/ar9003_calib.c
+++ b/drivers/net/wireless/ath/ath9k/ar9003_calib.c
@@ -1023,6 +1023,7 @@ static bool ar9003_hw_init_cal(struct ath_hw *ah,
1023 AR_PHY_AGC_CONTROL_FLTR_CAL | 1023 AR_PHY_AGC_CONTROL_FLTR_CAL |
1024 AR_PHY_AGC_CONTROL_PKDET_CAL; 1024 AR_PHY_AGC_CONTROL_PKDET_CAL;
1025 1025
1026 /* Use chip chainmask only for calibration */
1026 ar9003_hw_set_chain_masks(ah, ah->caps.rx_chainmask, ah->caps.tx_chainmask); 1027 ar9003_hw_set_chain_masks(ah, ah->caps.rx_chainmask, ah->caps.tx_chainmask);
1027 1028
1028 if (rtt) { 1029 if (rtt) {
@@ -1150,6 +1151,9 @@ skip_tx_iqcal:
1150 ar9003_hw_rtt_disable(ah); 1151 ar9003_hw_rtt_disable(ah);
1151 } 1152 }
1152 1153
1154 /* Revert chainmask to runtime parameters */
1155 ar9003_hw_set_chain_masks(ah, ah->rxchainmask, ah->txchainmask);
1156
1153 /* Initialize list pointers */ 1157 /* Initialize list pointers */
1154 ah->cal_list = ah->cal_list_last = ah->cal_list_curr = NULL; 1158 ah->cal_list = ah->cal_list_last = ah->cal_list_curr = NULL;
1155 1159
diff --git a/drivers/net/wireless/ath/ath9k/link.c b/drivers/net/wireless/ath/ath9k/link.c
index ade3afb21f91..39c84ecf6a42 100644
--- a/drivers/net/wireless/ath/ath9k/link.c
+++ b/drivers/net/wireless/ath/ath9k/link.c
@@ -28,21 +28,21 @@ void ath_tx_complete_poll_work(struct work_struct *work)
28 int i; 28 int i;
29 bool needreset = false; 29 bool needreset = false;
30 30
31 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) 31 for (i = 0; i < IEEE80211_NUM_ACS; i++) {
32 if (ATH_TXQ_SETUP(sc, i)) { 32 txq = sc->tx.txq_map[i];
33 txq = &sc->tx.txq[i]; 33
34 ath_txq_lock(sc, txq); 34 ath_txq_lock(sc, txq);
35 if (txq->axq_depth) { 35 if (txq->axq_depth) {
36 if (txq->axq_tx_inprogress) { 36 if (txq->axq_tx_inprogress) {
37 needreset = true; 37 needreset = true;
38 ath_txq_unlock(sc, txq); 38 ath_txq_unlock(sc, txq);
39 break; 39 break;
40 } else { 40 } else {
41 txq->axq_tx_inprogress = true; 41 txq->axq_tx_inprogress = true;
42 }
43 } 42 }
44 ath_txq_unlock_complete(sc, txq);
45 } 43 }
44 ath_txq_unlock_complete(sc, txq);
45 }
46 46
47 if (needreset) { 47 if (needreset) {
48 ath_dbg(ath9k_hw_common(sc->sc_ah), RESET, 48 ath_dbg(ath9k_hw_common(sc->sc_ah), RESET,
diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
index 3630a41df50d..c353b5f19c8c 100644
--- a/drivers/net/wireless/iwlegacy/3945-mac.c
+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
@@ -475,6 +475,7 @@ il3945_tx_skb(struct il_priv *il,
475 dma_addr_t txcmd_phys; 475 dma_addr_t txcmd_phys;
476 int txq_id = skb_get_queue_mapping(skb); 476 int txq_id = skb_get_queue_mapping(skb);
477 u16 len, idx, hdr_len; 477 u16 len, idx, hdr_len;
478 u16 firstlen, secondlen;
478 u8 id; 479 u8 id;
479 u8 unicast; 480 u8 unicast;
480 u8 sta_id; 481 u8 sta_id;
@@ -589,21 +590,22 @@ il3945_tx_skb(struct il_priv *il,
589 len = 590 len =
590 sizeof(struct il3945_tx_cmd) + sizeof(struct il_cmd_header) + 591 sizeof(struct il3945_tx_cmd) + sizeof(struct il_cmd_header) +
591 hdr_len; 592 hdr_len;
592 len = (len + 3) & ~3; 593 firstlen = (len + 3) & ~3;
593 594
594 /* Physical address of this Tx command's header (not MAC header!), 595 /* Physical address of this Tx command's header (not MAC header!),
595 * within command buffer array. */ 596 * within command buffer array. */
596 txcmd_phys = 597 txcmd_phys =
597 pci_map_single(il->pci_dev, &out_cmd->hdr, len, PCI_DMA_TODEVICE); 598 pci_map_single(il->pci_dev, &out_cmd->hdr, firstlen,
599 PCI_DMA_TODEVICE);
598 if (unlikely(pci_dma_mapping_error(il->pci_dev, txcmd_phys))) 600 if (unlikely(pci_dma_mapping_error(il->pci_dev, txcmd_phys)))
599 goto drop_unlock; 601 goto drop_unlock;
600 602
601 /* Set up TFD's 2nd entry to point directly to remainder of skb, 603 /* Set up TFD's 2nd entry to point directly to remainder of skb,
602 * if any (802.11 null frames have no payload). */ 604 * if any (802.11 null frames have no payload). */
603 len = skb->len - hdr_len; 605 secondlen = skb->len - hdr_len;
604 if (len) { 606 if (secondlen > 0) {
605 phys_addr = 607 phys_addr =
606 pci_map_single(il->pci_dev, skb->data + hdr_len, len, 608 pci_map_single(il->pci_dev, skb->data + hdr_len, secondlen,
607 PCI_DMA_TODEVICE); 609 PCI_DMA_TODEVICE);
608 if (unlikely(pci_dma_mapping_error(il->pci_dev, phys_addr))) 610 if (unlikely(pci_dma_mapping_error(il->pci_dev, phys_addr)))
609 goto drop_unlock; 611 goto drop_unlock;
@@ -611,12 +613,12 @@ il3945_tx_skb(struct il_priv *il,
611 613
612 /* Add buffer containing Tx command and MAC(!) header to TFD's 614 /* Add buffer containing Tx command and MAC(!) header to TFD's
613 * first entry */ 615 * first entry */
614 il->ops->txq_attach_buf_to_tfd(il, txq, txcmd_phys, len, 1, 0); 616 il->ops->txq_attach_buf_to_tfd(il, txq, txcmd_phys, firstlen, 1, 0);
615 dma_unmap_addr_set(out_meta, mapping, txcmd_phys); 617 dma_unmap_addr_set(out_meta, mapping, txcmd_phys);
616 dma_unmap_len_set(out_meta, len, len); 618 dma_unmap_len_set(out_meta, len, firstlen);
617 if (len) 619 if (secondlen > 0)
618 il->ops->txq_attach_buf_to_tfd(il, txq, phys_addr, len, 0, 620 il->ops->txq_attach_buf_to_tfd(il, txq, phys_addr, secondlen, 0,
619 U32_PAD(len)); 621 U32_PAD(secondlen));
620 622
621 if (!ieee80211_has_morefrags(hdr->frame_control)) { 623 if (!ieee80211_has_morefrags(hdr->frame_control)) {
622 txq->need_update = 1; 624 txq->need_update = 1;
diff --git a/drivers/net/wireless/mwifiex/cmdevt.c b/drivers/net/wireless/mwifiex/cmdevt.c
index 20a6c5555873..b5c8b962ce12 100644
--- a/drivers/net/wireless/mwifiex/cmdevt.c
+++ b/drivers/net/wireless/mwifiex/cmdevt.c
@@ -157,6 +157,20 @@ static int mwifiex_dnld_cmd_to_fw(struct mwifiex_private *priv,
157 return -1; 157 return -1;
158 } 158 }
159 159
160 cmd_code = le16_to_cpu(host_cmd->command);
161 cmd_size = le16_to_cpu(host_cmd->size);
162
163 if (adapter->hw_status == MWIFIEX_HW_STATUS_RESET &&
164 cmd_code != HostCmd_CMD_FUNC_SHUTDOWN &&
165 cmd_code != HostCmd_CMD_FUNC_INIT) {
166 dev_err(adapter->dev,
167 "DNLD_CMD: FW in reset state, ignore cmd %#x\n",
168 cmd_code);
169 mwifiex_complete_cmd(adapter, cmd_node);
170 mwifiex_insert_cmd_to_free_q(adapter, cmd_node);
171 return -1;
172 }
173
160 /* Set command sequence number */ 174 /* Set command sequence number */
161 adapter->seq_num++; 175 adapter->seq_num++;
162 host_cmd->seq_num = cpu_to_le16(HostCmd_SET_SEQ_NO_BSS_INFO 176 host_cmd->seq_num = cpu_to_le16(HostCmd_SET_SEQ_NO_BSS_INFO
@@ -168,9 +182,6 @@ static int mwifiex_dnld_cmd_to_fw(struct mwifiex_private *priv,
168 adapter->curr_cmd = cmd_node; 182 adapter->curr_cmd = cmd_node;
169 spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags); 183 spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags);
170 184
171 cmd_code = le16_to_cpu(host_cmd->command);
172 cmd_size = le16_to_cpu(host_cmd->size);
173
174 /* Adjust skb length */ 185 /* Adjust skb length */
175 if (cmd_node->cmd_skb->len > cmd_size) 186 if (cmd_node->cmd_skb->len > cmd_size)
176 /* 187 /*
@@ -484,8 +495,6 @@ int mwifiex_send_cmd_sync(struct mwifiex_private *priv, uint16_t cmd_no,
484 495
485 ret = mwifiex_send_cmd_async(priv, cmd_no, cmd_action, cmd_oid, 496 ret = mwifiex_send_cmd_async(priv, cmd_no, cmd_action, cmd_oid,
486 data_buf); 497 data_buf);
487 if (!ret)
488 ret = mwifiex_wait_queue_complete(adapter);
489 498
490 return ret; 499 return ret;
491} 500}
@@ -588,9 +597,10 @@ int mwifiex_send_cmd_async(struct mwifiex_private *priv, uint16_t cmd_no,
588 if (cmd_no == HostCmd_CMD_802_11_SCAN) { 597 if (cmd_no == HostCmd_CMD_802_11_SCAN) {
589 mwifiex_queue_scan_cmd(priv, cmd_node); 598 mwifiex_queue_scan_cmd(priv, cmd_node);
590 } else { 599 } else {
591 adapter->cmd_queued = cmd_node;
592 mwifiex_insert_cmd_to_pending_q(adapter, cmd_node, true); 600 mwifiex_insert_cmd_to_pending_q(adapter, cmd_node, true);
593 queue_work(adapter->workqueue, &adapter->main_work); 601 queue_work(adapter->workqueue, &adapter->main_work);
602 if (cmd_node->wait_q_enabled)
603 ret = mwifiex_wait_queue_complete(adapter, cmd_node);
594 } 604 }
595 605
596 return ret; 606 return ret;
diff --git a/drivers/net/wireless/mwifiex/init.c b/drivers/net/wireless/mwifiex/init.c
index e38aa9b3663d..0ff4c37ab42a 100644
--- a/drivers/net/wireless/mwifiex/init.c
+++ b/drivers/net/wireless/mwifiex/init.c
@@ -709,6 +709,14 @@ mwifiex_shutdown_drv(struct mwifiex_adapter *adapter)
709 return ret; 709 return ret;
710 } 710 }
711 711
712 /* cancel current command */
713 if (adapter->curr_cmd) {
714 dev_warn(adapter->dev, "curr_cmd is still in processing\n");
715 del_timer(&adapter->cmd_timer);
716 mwifiex_insert_cmd_to_free_q(adapter, adapter->curr_cmd);
717 adapter->curr_cmd = NULL;
718 }
719
712 /* shut down mwifiex */ 720 /* shut down mwifiex */
713 dev_dbg(adapter->dev, "info: shutdown mwifiex...\n"); 721 dev_dbg(adapter->dev, "info: shutdown mwifiex...\n");
714 722
diff --git a/drivers/net/wireless/mwifiex/join.c b/drivers/net/wireless/mwifiex/join.c
index 246aa62a4817..2fe0ceba4400 100644
--- a/drivers/net/wireless/mwifiex/join.c
+++ b/drivers/net/wireless/mwifiex/join.c
@@ -1117,10 +1117,9 @@ mwifiex_cmd_802_11_ad_hoc_join(struct mwifiex_private *priv,
1117 adhoc_join->bss_descriptor.bssid, 1117 adhoc_join->bss_descriptor.bssid,
1118 adhoc_join->bss_descriptor.ssid); 1118 adhoc_join->bss_descriptor.ssid);
1119 1119
1120 for (i = 0; bss_desc->supported_rates[i] && 1120 for (i = 0; i < MWIFIEX_SUPPORTED_RATES &&
1121 i < MWIFIEX_SUPPORTED_RATES; 1121 bss_desc->supported_rates[i]; i++)
1122 i++) 1122 ;
1123 ;
1124 rates_size = i; 1123 rates_size = i;
1125 1124
1126 /* Copy Data Rates from the Rates recorded in scan response */ 1125 /* Copy Data Rates from the Rates recorded in scan response */
diff --git a/drivers/net/wireless/mwifiex/main.h b/drivers/net/wireless/mwifiex/main.h
index 553adfb0aa81..7035ade9af74 100644
--- a/drivers/net/wireless/mwifiex/main.h
+++ b/drivers/net/wireless/mwifiex/main.h
@@ -723,7 +723,6 @@ struct mwifiex_adapter {
723 u16 cmd_wait_q_required; 723 u16 cmd_wait_q_required;
724 struct mwifiex_wait_queue cmd_wait_q; 724 struct mwifiex_wait_queue cmd_wait_q;
725 u8 scan_wait_q_woken; 725 u8 scan_wait_q_woken;
726 struct cmd_ctrl_node *cmd_queued;
727 spinlock_t queue_lock; /* lock for tx queues */ 726 spinlock_t queue_lock; /* lock for tx queues */
728 struct completion fw_load; 727 struct completion fw_load;
729 u8 country_code[IEEE80211_COUNTRY_STRING_LEN]; 728 u8 country_code[IEEE80211_COUNTRY_STRING_LEN];
@@ -1018,7 +1017,8 @@ int mwifiex_request_set_multicast_list(struct mwifiex_private *priv,
1018 struct mwifiex_multicast_list *mcast_list); 1017 struct mwifiex_multicast_list *mcast_list);
1019int mwifiex_copy_mcast_addr(struct mwifiex_multicast_list *mlist, 1018int mwifiex_copy_mcast_addr(struct mwifiex_multicast_list *mlist,
1020 struct net_device *dev); 1019 struct net_device *dev);
1021int mwifiex_wait_queue_complete(struct mwifiex_adapter *adapter); 1020int mwifiex_wait_queue_complete(struct mwifiex_adapter *adapter,
1021 struct cmd_ctrl_node *cmd_queued);
1022int mwifiex_bss_start(struct mwifiex_private *priv, struct cfg80211_bss *bss, 1022int mwifiex_bss_start(struct mwifiex_private *priv, struct cfg80211_bss *bss,
1023 struct cfg80211_ssid *req_ssid); 1023 struct cfg80211_ssid *req_ssid);
1024int mwifiex_cancel_hs(struct mwifiex_private *priv, int cmd_type); 1024int mwifiex_cancel_hs(struct mwifiex_private *priv, int cmd_type);
diff --git a/drivers/net/wireless/mwifiex/scan.c b/drivers/net/wireless/mwifiex/scan.c
index bb60c2754a97..d215b4d3c51b 100644
--- a/drivers/net/wireless/mwifiex/scan.c
+++ b/drivers/net/wireless/mwifiex/scan.c
@@ -1388,10 +1388,13 @@ int mwifiex_scan_networks(struct mwifiex_private *priv,
1388 list_del(&cmd_node->list); 1388 list_del(&cmd_node->list);
1389 spin_unlock_irqrestore(&adapter->scan_pending_q_lock, 1389 spin_unlock_irqrestore(&adapter->scan_pending_q_lock,
1390 flags); 1390 flags);
1391 adapter->cmd_queued = cmd_node;
1392 mwifiex_insert_cmd_to_pending_q(adapter, cmd_node, 1391 mwifiex_insert_cmd_to_pending_q(adapter, cmd_node,
1393 true); 1392 true);
1394 queue_work(adapter->workqueue, &adapter->main_work); 1393 queue_work(adapter->workqueue, &adapter->main_work);
1394
1395 /* Perform internal scan synchronously */
1396 if (!priv->scan_request)
1397 mwifiex_wait_queue_complete(adapter, cmd_node);
1395 } else { 1398 } else {
1396 spin_unlock_irqrestore(&adapter->scan_pending_q_lock, 1399 spin_unlock_irqrestore(&adapter->scan_pending_q_lock,
1397 flags); 1400 flags);
@@ -1946,9 +1949,6 @@ int mwifiex_request_scan(struct mwifiex_private *priv,
1946 /* Normal scan */ 1949 /* Normal scan */
1947 ret = mwifiex_scan_networks(priv, NULL); 1950 ret = mwifiex_scan_networks(priv, NULL);
1948 1951
1949 if (!ret)
1950 ret = mwifiex_wait_queue_complete(priv->adapter);
1951
1952 up(&priv->async_sem); 1952 up(&priv->async_sem);
1953 1953
1954 return ret; 1954 return ret;
diff --git a/drivers/net/wireless/mwifiex/sta_ioctl.c b/drivers/net/wireless/mwifiex/sta_ioctl.c
index 9f33c92c90f5..13100f8de3db 100644
--- a/drivers/net/wireless/mwifiex/sta_ioctl.c
+++ b/drivers/net/wireless/mwifiex/sta_ioctl.c
@@ -54,16 +54,10 @@ int mwifiex_copy_mcast_addr(struct mwifiex_multicast_list *mlist,
54 * This function waits on a cmd wait queue. It also cancels the pending 54 * This function waits on a cmd wait queue. It also cancels the pending
55 * request after waking up, in case of errors. 55 * request after waking up, in case of errors.
56 */ 56 */
57int mwifiex_wait_queue_complete(struct mwifiex_adapter *adapter) 57int mwifiex_wait_queue_complete(struct mwifiex_adapter *adapter,
58 struct cmd_ctrl_node *cmd_queued)
58{ 59{
59 int status; 60 int status;
60 struct cmd_ctrl_node *cmd_queued;
61
62 if (!adapter->cmd_queued)
63 return 0;
64
65 cmd_queued = adapter->cmd_queued;
66 adapter->cmd_queued = NULL;
67 61
68 dev_dbg(adapter->dev, "cmd pending\n"); 62 dev_dbg(adapter->dev, "cmd pending\n");
69 atomic_inc(&adapter->cmd_pending); 63 atomic_inc(&adapter->cmd_pending);
diff --git a/drivers/net/wireless/rt2x00/Kconfig b/drivers/net/wireless/rt2x00/Kconfig
index 44d6ead43341..2bf4efa33186 100644
--- a/drivers/net/wireless/rt2x00/Kconfig
+++ b/drivers/net/wireless/rt2x00/Kconfig
@@ -55,10 +55,10 @@ config RT61PCI
55 55
56config RT2800PCI 56config RT2800PCI
57 tristate "Ralink rt27xx/rt28xx/rt30xx (PCI/PCIe/PCMCIA) support" 57 tristate "Ralink rt27xx/rt28xx/rt30xx (PCI/PCIe/PCMCIA) support"
58 depends on PCI || RALINK_RT288X || RALINK_RT305X 58 depends on PCI || SOC_RT288X || SOC_RT305X
59 select RT2800_LIB 59 select RT2800_LIB
60 select RT2X00_LIB_PCI if PCI 60 select RT2X00_LIB_PCI if PCI
61 select RT2X00_LIB_SOC if RALINK_RT288X || RALINK_RT305X 61 select RT2X00_LIB_SOC if SOC_RT288X || SOC_RT305X
62 select RT2X00_LIB_FIRMWARE 62 select RT2X00_LIB_FIRMWARE
63 select RT2X00_LIB_CRYPTO 63 select RT2X00_LIB_CRYPTO
64 select CRC_CCITT 64 select CRC_CCITT
diff --git a/drivers/net/wireless/rt2x00/rt2800pci.c b/drivers/net/wireless/rt2x00/rt2800pci.c
index 48a01aa21f1c..ded73da4de0b 100644
--- a/drivers/net/wireless/rt2x00/rt2800pci.c
+++ b/drivers/net/wireless/rt2x00/rt2800pci.c
@@ -89,7 +89,7 @@ static void rt2800pci_mcu_status(struct rt2x00_dev *rt2x00dev, const u8 token)
89 rt2x00pci_register_write(rt2x00dev, H2M_MAILBOX_CID, ~0); 89 rt2x00pci_register_write(rt2x00dev, H2M_MAILBOX_CID, ~0);
90} 90}
91 91
92#if defined(CONFIG_RALINK_RT288X) || defined(CONFIG_RALINK_RT305X) 92#if defined(CONFIG_SOC_RT288X) || defined(CONFIG_SOC_RT305X)
93static int rt2800pci_read_eeprom_soc(struct rt2x00_dev *rt2x00dev) 93static int rt2800pci_read_eeprom_soc(struct rt2x00_dev *rt2x00dev)
94{ 94{
95 void __iomem *base_addr = ioremap(0x1F040000, EEPROM_SIZE); 95 void __iomem *base_addr = ioremap(0x1F040000, EEPROM_SIZE);
@@ -107,7 +107,7 @@ static inline int rt2800pci_read_eeprom_soc(struct rt2x00_dev *rt2x00dev)
107{ 107{
108 return -ENOMEM; 108 return -ENOMEM;
109} 109}
110#endif /* CONFIG_RALINK_RT288X || CONFIG_RALINK_RT305X */ 110#endif /* CONFIG_SOC_RT288X || CONFIG_SOC_RT305X */
111 111
112#ifdef CONFIG_PCI 112#ifdef CONFIG_PCI
113static void rt2800pci_eepromregister_read(struct eeprom_93cx6 *eeprom) 113static void rt2800pci_eepromregister_read(struct eeprom_93cx6 *eeprom)
@@ -1177,7 +1177,7 @@ MODULE_DEVICE_TABLE(pci, rt2800pci_device_table);
1177#endif /* CONFIG_PCI */ 1177#endif /* CONFIG_PCI */
1178MODULE_LICENSE("GPL"); 1178MODULE_LICENSE("GPL");
1179 1179
1180#if defined(CONFIG_RALINK_RT288X) || defined(CONFIG_RALINK_RT305X) 1180#if defined(CONFIG_SOC_RT288X) || defined(CONFIG_SOC_RT305X)
1181static int rt2800soc_probe(struct platform_device *pdev) 1181static int rt2800soc_probe(struct platform_device *pdev)
1182{ 1182{
1183 return rt2x00soc_probe(pdev, &rt2800pci_ops); 1183 return rt2x00soc_probe(pdev, &rt2800pci_ops);
@@ -1194,7 +1194,7 @@ static struct platform_driver rt2800soc_driver = {
1194 .suspend = rt2x00soc_suspend, 1194 .suspend = rt2x00soc_suspend,
1195 .resume = rt2x00soc_resume, 1195 .resume = rt2x00soc_resume,
1196}; 1196};
1197#endif /* CONFIG_RALINK_RT288X || CONFIG_RALINK_RT305X */ 1197#endif /* CONFIG_SOC_RT288X || CONFIG_SOC_RT305X */
1198 1198
1199#ifdef CONFIG_PCI 1199#ifdef CONFIG_PCI
1200static int rt2800pci_probe(struct pci_dev *pci_dev, 1200static int rt2800pci_probe(struct pci_dev *pci_dev,
@@ -1217,7 +1217,7 @@ static int __init rt2800pci_init(void)
1217{ 1217{
1218 int ret = 0; 1218 int ret = 0;
1219 1219
1220#if defined(CONFIG_RALINK_RT288X) || defined(CONFIG_RALINK_RT305X) 1220#if defined(CONFIG_SOC_RT288X) || defined(CONFIG_SOC_RT305X)
1221 ret = platform_driver_register(&rt2800soc_driver); 1221 ret = platform_driver_register(&rt2800soc_driver);
1222 if (ret) 1222 if (ret)
1223 return ret; 1223 return ret;
@@ -1225,7 +1225,7 @@ static int __init rt2800pci_init(void)
1225#ifdef CONFIG_PCI 1225#ifdef CONFIG_PCI
1226 ret = pci_register_driver(&rt2800pci_driver); 1226 ret = pci_register_driver(&rt2800pci_driver);
1227 if (ret) { 1227 if (ret) {
1228#if defined(CONFIG_RALINK_RT288X) || defined(CONFIG_RALINK_RT305X) 1228#if defined(CONFIG_SOC_RT288X) || defined(CONFIG_SOC_RT305X)
1229 platform_driver_unregister(&rt2800soc_driver); 1229 platform_driver_unregister(&rt2800soc_driver);
1230#endif 1230#endif
1231 return ret; 1231 return ret;
@@ -1240,7 +1240,7 @@ static void __exit rt2800pci_exit(void)
1240#ifdef CONFIG_PCI 1240#ifdef CONFIG_PCI
1241 pci_unregister_driver(&rt2800pci_driver); 1241 pci_unregister_driver(&rt2800pci_driver);
1242#endif 1242#endif
1243#if defined(CONFIG_RALINK_RT288X) || defined(CONFIG_RALINK_RT305X) 1243#if defined(CONFIG_SOC_RT288X) || defined(CONFIG_SOC_RT305X)
1244 platform_driver_unregister(&rt2800soc_driver); 1244 platform_driver_unregister(&rt2800soc_driver);
1245#endif 1245#endif
1246} 1246}
diff --git a/drivers/net/wireless/rtlwifi/rtl8192cu/hw.c b/drivers/net/wireless/rtlwifi/rtl8192cu/hw.c
index b1ccff474c79..c08d0f4c5f3d 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192cu/hw.c
+++ b/drivers/net/wireless/rtlwifi/rtl8192cu/hw.c
@@ -1377,74 +1377,57 @@ void rtl92cu_card_disable(struct ieee80211_hw *hw)
1377 1377
1378void rtl92cu_set_check_bssid(struct ieee80211_hw *hw, bool check_bssid) 1378void rtl92cu_set_check_bssid(struct ieee80211_hw *hw, bool check_bssid)
1379{ 1379{
1380 /* dummy routine needed for callback from rtl_op_configure_filter() */
1381}
1382
1383/*========================================================================== */
1384
1385static void _rtl92cu_set_check_bssid(struct ieee80211_hw *hw,
1386 enum nl80211_iftype type)
1387{
1388 struct rtl_priv *rtlpriv = rtl_priv(hw); 1380 struct rtl_priv *rtlpriv = rtl_priv(hw);
1389 u32 reg_rcr = rtl_read_dword(rtlpriv, REG_RCR);
1390 struct rtl_hal *rtlhal = rtl_hal(rtlpriv); 1381 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
1391 struct rtl_phy *rtlphy = &(rtlpriv->phy); 1382 u32 reg_rcr = rtl_read_dword(rtlpriv, REG_RCR);
1392 u8 filterout_non_associated_bssid = false;
1393 1383
1394 switch (type) { 1384 if (rtlpriv->psc.rfpwr_state != ERFON)
1395 case NL80211_IFTYPE_ADHOC: 1385 return;
1396 case NL80211_IFTYPE_STATION: 1386
1397 filterout_non_associated_bssid = true; 1387 if (check_bssid) {
1398 break; 1388 u8 tmp;
1399 case NL80211_IFTYPE_UNSPECIFIED:
1400 case NL80211_IFTYPE_AP:
1401 default:
1402 break;
1403 }
1404 if (filterout_non_associated_bssid) {
1405 if (IS_NORMAL_CHIP(rtlhal->version)) { 1389 if (IS_NORMAL_CHIP(rtlhal->version)) {
1406 switch (rtlphy->current_io_type) { 1390 reg_rcr |= (RCR_CBSSID_DATA | RCR_CBSSID_BCN);
1407 case IO_CMD_RESUME_DM_BY_SCAN: 1391 tmp = BIT(4);
1408 reg_rcr |= (RCR_CBSSID_DATA | RCR_CBSSID_BCN);
1409 rtlpriv->cfg->ops->set_hw_reg(hw,
1410 HW_VAR_RCR, (u8 *)(&reg_rcr));
1411 /* enable update TSF */
1412 _rtl92cu_set_bcn_ctrl_reg(hw, 0, BIT(4));
1413 break;
1414 case IO_CMD_PAUSE_DM_BY_SCAN:
1415 reg_rcr &= ~(RCR_CBSSID_DATA | RCR_CBSSID_BCN);
1416 rtlpriv->cfg->ops->set_hw_reg(hw,
1417 HW_VAR_RCR, (u8 *)(&reg_rcr));
1418 /* disable update TSF */
1419 _rtl92cu_set_bcn_ctrl_reg(hw, BIT(4), 0);
1420 break;
1421 }
1422 } else { 1392 } else {
1423 reg_rcr |= (RCR_CBSSID); 1393 reg_rcr |= RCR_CBSSID;
1424 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_RCR, 1394 tmp = BIT(4) | BIT(5);
1425 (u8 *)(&reg_rcr));
1426 _rtl92cu_set_bcn_ctrl_reg(hw, 0, (BIT(4)|BIT(5)));
1427 } 1395 }
1428 } else if (filterout_non_associated_bssid == false) { 1396 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_RCR,
1397 (u8 *) (&reg_rcr));
1398 _rtl92cu_set_bcn_ctrl_reg(hw, 0, tmp);
1399 } else {
1400 u8 tmp;
1429 if (IS_NORMAL_CHIP(rtlhal->version)) { 1401 if (IS_NORMAL_CHIP(rtlhal->version)) {
1430 reg_rcr &= (~(RCR_CBSSID_DATA | RCR_CBSSID_BCN)); 1402 reg_rcr &= ~(RCR_CBSSID_DATA | RCR_CBSSID_BCN);
1431 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_RCR, 1403 tmp = BIT(4);
1432 (u8 *)(&reg_rcr));
1433 _rtl92cu_set_bcn_ctrl_reg(hw, BIT(4), 0);
1434 } else { 1404 } else {
1435 reg_rcr &= (~RCR_CBSSID); 1405 reg_rcr &= ~RCR_CBSSID;
1436 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_RCR, 1406 tmp = BIT(4) | BIT(5);
1437 (u8 *)(&reg_rcr));
1438 _rtl92cu_set_bcn_ctrl_reg(hw, (BIT(4)|BIT(5)), 0);
1439 } 1407 }
1408 reg_rcr &= (~(RCR_CBSSID_DATA | RCR_CBSSID_BCN));
1409 rtlpriv->cfg->ops->set_hw_reg(hw,
1410 HW_VAR_RCR, (u8 *) (&reg_rcr));
1411 _rtl92cu_set_bcn_ctrl_reg(hw, tmp, 0);
1440 } 1412 }
1441} 1413}
1442 1414
1415/*========================================================================== */
1416
1443int rtl92cu_set_network_type(struct ieee80211_hw *hw, enum nl80211_iftype type) 1417int rtl92cu_set_network_type(struct ieee80211_hw *hw, enum nl80211_iftype type)
1444{ 1418{
1419 struct rtl_priv *rtlpriv = rtl_priv(hw);
1420
1445 if (_rtl92cu_set_media_status(hw, type)) 1421 if (_rtl92cu_set_media_status(hw, type))
1446 return -EOPNOTSUPP; 1422 return -EOPNOTSUPP;
1447 _rtl92cu_set_check_bssid(hw, type); 1423
1424 if (rtlpriv->mac80211.link_state == MAC80211_LINKED) {
1425 if (type != NL80211_IFTYPE_AP)
1426 rtl92cu_set_check_bssid(hw, true);
1427 } else {
1428 rtl92cu_set_check_bssid(hw, false);
1429 }
1430
1448 return 0; 1431 return 0;
1449} 1432}
1450 1433
@@ -2058,8 +2041,6 @@ void rtl92cu_update_hal_rate_table(struct ieee80211_hw *hw,
2058 (shortgi_rate << 4) | (shortgi_rate); 2041 (shortgi_rate << 4) | (shortgi_rate);
2059 } 2042 }
2060 rtl_write_dword(rtlpriv, REG_ARFR0 + ratr_index * 4, ratr_value); 2043 rtl_write_dword(rtlpriv, REG_ARFR0 + ratr_index * 4, ratr_value);
2061 RT_TRACE(rtlpriv, COMP_RATR, DBG_DMESG, "%x\n",
2062 rtl_read_dword(rtlpriv, REG_ARFR0));
2063} 2044}
2064 2045
2065void rtl92cu_update_hal_rate_mask(struct ieee80211_hw *hw, u8 rssi_level) 2046void rtl92cu_update_hal_rate_mask(struct ieee80211_hw *hw, u8 rssi_level)
diff --git a/drivers/net/wireless/rtlwifi/usb.c b/drivers/net/wireless/rtlwifi/usb.c
index 156b52732f3d..5847d6d0881e 100644
--- a/drivers/net/wireless/rtlwifi/usb.c
+++ b/drivers/net/wireless/rtlwifi/usb.c
@@ -851,6 +851,7 @@ static void _rtl_usb_transmit(struct ieee80211_hw *hw, struct sk_buff *skb,
851 if (unlikely(!_urb)) { 851 if (unlikely(!_urb)) {
852 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, 852 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
853 "Can't allocate urb. Drop skb!\n"); 853 "Can't allocate urb. Drop skb!\n");
854 kfree_skb(skb);
854 return; 855 return;
855 } 856 }
856 _rtl_submit_tx_urb(hw, _urb); 857 _rtl_submit_tx_urb(hw, _urb);
diff --git a/drivers/pci/rom.c b/drivers/pci/rom.c
index ab886b7ee327..b41ac7756a4b 100644
--- a/drivers/pci/rom.c
+++ b/drivers/pci/rom.c
@@ -100,6 +100,27 @@ size_t pci_get_rom_size(struct pci_dev *pdev, void __iomem *rom, size_t size)
100 return min((size_t)(image - rom), size); 100 return min((size_t)(image - rom), size);
101} 101}
102 102
103static loff_t pci_find_rom(struct pci_dev *pdev, size_t *size)
104{
105 struct resource *res = &pdev->resource[PCI_ROM_RESOURCE];
106 loff_t start;
107
108 /* assign the ROM an address if it doesn't have one */
109 if (res->parent == NULL && pci_assign_resource(pdev, PCI_ROM_RESOURCE))
110 return 0;
111 start = pci_resource_start(pdev, PCI_ROM_RESOURCE);
112 *size = pci_resource_len(pdev, PCI_ROM_RESOURCE);
113
114 if (*size == 0)
115 return 0;
116
117 /* Enable ROM space decodes */
118 if (pci_enable_rom(pdev))
119 return 0;
120
121 return start;
122}
123
103/** 124/**
104 * pci_map_rom - map a PCI ROM to kernel space 125 * pci_map_rom - map a PCI ROM to kernel space
105 * @pdev: pointer to pci device struct 126 * @pdev: pointer to pci device struct
@@ -114,21 +135,15 @@ size_t pci_get_rom_size(struct pci_dev *pdev, void __iomem *rom, size_t size)
114void __iomem *pci_map_rom(struct pci_dev *pdev, size_t *size) 135void __iomem *pci_map_rom(struct pci_dev *pdev, size_t *size)
115{ 136{
116 struct resource *res = &pdev->resource[PCI_ROM_RESOURCE]; 137 struct resource *res = &pdev->resource[PCI_ROM_RESOURCE];
117 loff_t start; 138 loff_t start = 0;
118 void __iomem *rom; 139 void __iomem *rom;
119 140
120 /* 141 /*
121 * Some devices may provide ROMs via a source other than the BAR
122 */
123 if (pdev->rom && pdev->romlen) {
124 *size = pdev->romlen;
125 return phys_to_virt(pdev->rom);
126 /*
127 * IORESOURCE_ROM_SHADOW set on x86, x86_64 and IA64 supports legacy 142 * IORESOURCE_ROM_SHADOW set on x86, x86_64 and IA64 supports legacy
128 * memory map if the VGA enable bit of the Bridge Control register is 143 * memory map if the VGA enable bit of the Bridge Control register is
129 * set for embedded VGA. 144 * set for embedded VGA.
130 */ 145 */
131 } else if (res->flags & IORESOURCE_ROM_SHADOW) { 146 if (res->flags & IORESOURCE_ROM_SHADOW) {
132 /* primary video rom always starts here */ 147 /* primary video rom always starts here */
133 start = (loff_t)0xC0000; 148 start = (loff_t)0xC0000;
134 *size = 0x20000; /* cover C000:0 through E000:0 */ 149 *size = 0x20000; /* cover C000:0 through E000:0 */
@@ -139,21 +154,21 @@ void __iomem *pci_map_rom(struct pci_dev *pdev, size_t *size)
139 return (void __iomem *)(unsigned long) 154 return (void __iomem *)(unsigned long)
140 pci_resource_start(pdev, PCI_ROM_RESOURCE); 155 pci_resource_start(pdev, PCI_ROM_RESOURCE);
141 } else { 156 } else {
142 /* assign the ROM an address if it doesn't have one */ 157 start = pci_find_rom(pdev, size);
143 if (res->parent == NULL &&
144 pci_assign_resource(pdev,PCI_ROM_RESOURCE))
145 return NULL;
146 start = pci_resource_start(pdev, PCI_ROM_RESOURCE);
147 *size = pci_resource_len(pdev, PCI_ROM_RESOURCE);
148 if (*size == 0)
149 return NULL;
150
151 /* Enable ROM space decodes */
152 if (pci_enable_rom(pdev))
153 return NULL;
154 } 158 }
155 } 159 }
156 160
161 /*
162 * Some devices may provide ROMs via a source other than the BAR
163 */
164 if (!start && pdev->rom && pdev->romlen) {
165 *size = pdev->romlen;
166 return phys_to_virt(pdev->rom);
167 }
168
169 if (!start)
170 return NULL;
171
157 rom = ioremap(start, *size); 172 rom = ioremap(start, *size);
158 if (!rom) { 173 if (!rom) {
159 /* restore enable if ioremap fails */ 174 /* restore enable if ioremap fails */
diff --git a/drivers/pinctrl/mvebu/pinctrl-mvebu.c b/drivers/pinctrl/mvebu/pinctrl-mvebu.c
index c689c04a4f52..2d2f0a43d36b 100644
--- a/drivers/pinctrl/mvebu/pinctrl-mvebu.c
+++ b/drivers/pinctrl/mvebu/pinctrl-mvebu.c
@@ -620,7 +620,7 @@ int mvebu_pinctrl_probe(struct platform_device *pdev)
620 620
621 /* special soc specific control */ 621 /* special soc specific control */
622 if (ctrl->mpp_get || ctrl->mpp_set) { 622 if (ctrl->mpp_get || ctrl->mpp_set) {
623 if (!ctrl->name || !ctrl->mpp_set || !ctrl->mpp_set) { 623 if (!ctrl->name || !ctrl->mpp_get || !ctrl->mpp_set) {
624 dev_err(&pdev->dev, "wrong soc control info\n"); 624 dev_err(&pdev->dev, "wrong soc control info\n");
625 return -EINVAL; 625 return -EINVAL;
626 } 626 }
diff --git a/drivers/pinctrl/pinconf.c b/drivers/pinctrl/pinconf.c
index ac8d382a79bb..d611ecfcbf70 100644
--- a/drivers/pinctrl/pinconf.c
+++ b/drivers/pinctrl/pinconf.c
@@ -622,7 +622,7 @@ static const struct file_operations pinconf_dbg_pinname_fops = {
622static int pinconf_dbg_state_print(struct seq_file *s, void *d) 622static int pinconf_dbg_state_print(struct seq_file *s, void *d)
623{ 623{
624 if (strlen(dbg_state_name)) 624 if (strlen(dbg_state_name))
625 seq_printf(s, "%s\n", dbg_pinname); 625 seq_printf(s, "%s\n", dbg_state_name);
626 else 626 else
627 seq_printf(s, "No pin state set\n"); 627 seq_printf(s, "No pin state set\n");
628 return 0; 628 return 0;
diff --git a/drivers/pinctrl/pinconf.h b/drivers/pinctrl/pinconf.h
index e3ed8cb072a5..bfda73d64eed 100644
--- a/drivers/pinctrl/pinconf.h
+++ b/drivers/pinctrl/pinconf.h
@@ -90,7 +90,7 @@ static inline void pinconf_init_device_debugfs(struct dentry *devroot,
90 * pin config. 90 * pin config.
91 */ 91 */
92 92
93#ifdef CONFIG_GENERIC_PINCONF 93#if defined(CONFIG_GENERIC_PINCONF) && defined(CONFIG_DEBUG_FS)
94 94
95void pinconf_generic_dump_pin(struct pinctrl_dev *pctldev, 95void pinconf_generic_dump_pin(struct pinctrl_dev *pctldev,
96 struct seq_file *s, unsigned pin); 96 struct seq_file *s, unsigned pin);
diff --git a/drivers/pinctrl/pinctrl-abx500.c b/drivers/pinctrl/pinctrl-abx500.c
index caecdd373061..c542a97c82f3 100644
--- a/drivers/pinctrl/pinctrl-abx500.c
+++ b/drivers/pinctrl/pinctrl-abx500.c
@@ -422,7 +422,7 @@ static u8 abx500_get_mode(struct pinctrl_dev *pctldev, struct gpio_chip *chip,
422 } 422 }
423 423
424 /* check if pin use AlternateFunction register */ 424 /* check if pin use AlternateFunction register */
425 if ((af.alt_bit1 == UNUSED) && (af.alt_bit1 == UNUSED)) 425 if ((af.alt_bit1 == UNUSED) && (af.alt_bit2 == UNUSED))
426 return mode; 426 return mode;
427 /* 427 /*
428 * if pin GPIOSEL bit is set and pin supports alternate function, 428 * if pin GPIOSEL bit is set and pin supports alternate function,
diff --git a/drivers/pinctrl/pinctrl-at91.c b/drivers/pinctrl/pinctrl-at91.c
index 75933a6aa828..efb7f10e902a 100644
--- a/drivers/pinctrl/pinctrl-at91.c
+++ b/drivers/pinctrl/pinctrl-at91.c
@@ -1277,21 +1277,80 @@ static int alt_gpio_irq_type(struct irq_data *d, unsigned type)
1277} 1277}
1278 1278
1279#ifdef CONFIG_PM 1279#ifdef CONFIG_PM
1280
1281static u32 wakeups[MAX_GPIO_BANKS];
1282static u32 backups[MAX_GPIO_BANKS];
1283
1280static int gpio_irq_set_wake(struct irq_data *d, unsigned state) 1284static int gpio_irq_set_wake(struct irq_data *d, unsigned state)
1281{ 1285{
1282 struct at91_gpio_chip *at91_gpio = irq_data_get_irq_chip_data(d); 1286 struct at91_gpio_chip *at91_gpio = irq_data_get_irq_chip_data(d);
1283 unsigned bank = at91_gpio->pioc_idx; 1287 unsigned bank = at91_gpio->pioc_idx;
1288 unsigned mask = 1 << d->hwirq;
1284 1289
1285 if (unlikely(bank >= MAX_GPIO_BANKS)) 1290 if (unlikely(bank >= MAX_GPIO_BANKS))
1286 return -EINVAL; 1291 return -EINVAL;
1287 1292
1293 if (state)
1294 wakeups[bank] |= mask;
1295 else
1296 wakeups[bank] &= ~mask;
1297
1288 irq_set_irq_wake(at91_gpio->pioc_virq, state); 1298 irq_set_irq_wake(at91_gpio->pioc_virq, state);
1289 1299
1290 return 0; 1300 return 0;
1291} 1301}
1302
1303void at91_pinctrl_gpio_suspend(void)
1304{
1305 int i;
1306
1307 for (i = 0; i < gpio_banks; i++) {
1308 void __iomem *pio;
1309
1310 if (!gpio_chips[i])
1311 continue;
1312
1313 pio = gpio_chips[i]->regbase;
1314
1315 backups[i] = __raw_readl(pio + PIO_IMR);
1316 __raw_writel(backups[i], pio + PIO_IDR);
1317 __raw_writel(wakeups[i], pio + PIO_IER);
1318
1319 if (!wakeups[i]) {
1320 clk_unprepare(gpio_chips[i]->clock);
1321 clk_disable(gpio_chips[i]->clock);
1322 } else {
1323 printk(KERN_DEBUG "GPIO-%c may wake for %08x\n",
1324 'A'+i, wakeups[i]);
1325 }
1326 }
1327}
1328
1329void at91_pinctrl_gpio_resume(void)
1330{
1331 int i;
1332
1333 for (i = 0; i < gpio_banks; i++) {
1334 void __iomem *pio;
1335
1336 if (!gpio_chips[i])
1337 continue;
1338
1339 pio = gpio_chips[i]->regbase;
1340
1341 if (!wakeups[i]) {
1342 if (clk_prepare(gpio_chips[i]->clock) == 0)
1343 clk_enable(gpio_chips[i]->clock);
1344 }
1345
1346 __raw_writel(wakeups[i], pio + PIO_IDR);
1347 __raw_writel(backups[i], pio + PIO_IER);
1348 }
1349}
1350
1292#else 1351#else
1293#define gpio_irq_set_wake NULL 1352#define gpio_irq_set_wake NULL
1294#endif 1353#endif /* CONFIG_PM */
1295 1354
1296static struct irq_chip gpio_irqchip = { 1355static struct irq_chip gpio_irqchip = {
1297 .name = "GPIO", 1356 .name = "GPIO",
diff --git a/drivers/pinctrl/pinmux.c b/drivers/pinctrl/pinmux.c
index 1a00658b3ea0..bd83c8b01cd1 100644
--- a/drivers/pinctrl/pinmux.c
+++ b/drivers/pinctrl/pinmux.c
@@ -194,6 +194,11 @@ static const char *pin_free(struct pinctrl_dev *pctldev, int pin,
194 } 194 }
195 195
196 if (!gpio_range) { 196 if (!gpio_range) {
197 /*
198 * A pin should not be freed more times than allocated.
199 */
200 if (WARN_ON(!desc->mux_usecount))
201 return NULL;
197 desc->mux_usecount--; 202 desc->mux_usecount--;
198 if (desc->mux_usecount) 203 if (desc->mux_usecount)
199 return NULL; 204 return NULL;
diff --git a/drivers/rtc/rtc-at91rm9200.c b/drivers/rtc/rtc-at91rm9200.c
index 434ebc3a99dc..0a9f27e094ea 100644
--- a/drivers/rtc/rtc-at91rm9200.c
+++ b/drivers/rtc/rtc-at91rm9200.c
@@ -44,6 +44,7 @@ static DECLARE_COMPLETION(at91_rtc_updated);
44static unsigned int at91_alarm_year = AT91_RTC_EPOCH; 44static unsigned int at91_alarm_year = AT91_RTC_EPOCH;
45static void __iomem *at91_rtc_regs; 45static void __iomem *at91_rtc_regs;
46static int irq; 46static int irq;
47static u32 at91_rtc_imr;
47 48
48/* 49/*
49 * Decode time/date into rtc_time structure 50 * Decode time/date into rtc_time structure
@@ -108,9 +109,11 @@ static int at91_rtc_settime(struct device *dev, struct rtc_time *tm)
108 cr = at91_rtc_read(AT91_RTC_CR); 109 cr = at91_rtc_read(AT91_RTC_CR);
109 at91_rtc_write(AT91_RTC_CR, cr | AT91_RTC_UPDCAL | AT91_RTC_UPDTIM); 110 at91_rtc_write(AT91_RTC_CR, cr | AT91_RTC_UPDCAL | AT91_RTC_UPDTIM);
110 111
112 at91_rtc_imr |= AT91_RTC_ACKUPD;
111 at91_rtc_write(AT91_RTC_IER, AT91_RTC_ACKUPD); 113 at91_rtc_write(AT91_RTC_IER, AT91_RTC_ACKUPD);
112 wait_for_completion(&at91_rtc_updated); /* wait for ACKUPD interrupt */ 114 wait_for_completion(&at91_rtc_updated); /* wait for ACKUPD interrupt */
113 at91_rtc_write(AT91_RTC_IDR, AT91_RTC_ACKUPD); 115 at91_rtc_write(AT91_RTC_IDR, AT91_RTC_ACKUPD);
116 at91_rtc_imr &= ~AT91_RTC_ACKUPD;
114 117
115 at91_rtc_write(AT91_RTC_TIMR, 118 at91_rtc_write(AT91_RTC_TIMR,
116 bin2bcd(tm->tm_sec) << 0 119 bin2bcd(tm->tm_sec) << 0
@@ -142,7 +145,7 @@ static int at91_rtc_readalarm(struct device *dev, struct rtc_wkalrm *alrm)
142 tm->tm_yday = rtc_year_days(tm->tm_mday, tm->tm_mon, tm->tm_year); 145 tm->tm_yday = rtc_year_days(tm->tm_mday, tm->tm_mon, tm->tm_year);
143 tm->tm_year = at91_alarm_year - 1900; 146 tm->tm_year = at91_alarm_year - 1900;
144 147
145 alrm->enabled = (at91_rtc_read(AT91_RTC_IMR) & AT91_RTC_ALARM) 148 alrm->enabled = (at91_rtc_imr & AT91_RTC_ALARM)
146 ? 1 : 0; 149 ? 1 : 0;
147 150
148 dev_dbg(dev, "%s(): %4d-%02d-%02d %02d:%02d:%02d\n", __func__, 151 dev_dbg(dev, "%s(): %4d-%02d-%02d %02d:%02d:%02d\n", __func__,
@@ -168,6 +171,7 @@ static int at91_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
168 tm.tm_sec = alrm->time.tm_sec; 171 tm.tm_sec = alrm->time.tm_sec;
169 172
170 at91_rtc_write(AT91_RTC_IDR, AT91_RTC_ALARM); 173 at91_rtc_write(AT91_RTC_IDR, AT91_RTC_ALARM);
174 at91_rtc_imr &= ~AT91_RTC_ALARM;
171 at91_rtc_write(AT91_RTC_TIMALR, 175 at91_rtc_write(AT91_RTC_TIMALR,
172 bin2bcd(tm.tm_sec) << 0 176 bin2bcd(tm.tm_sec) << 0
173 | bin2bcd(tm.tm_min) << 8 177 | bin2bcd(tm.tm_min) << 8
@@ -180,6 +184,7 @@ static int at91_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
180 184
181 if (alrm->enabled) { 185 if (alrm->enabled) {
182 at91_rtc_write(AT91_RTC_SCCR, AT91_RTC_ALARM); 186 at91_rtc_write(AT91_RTC_SCCR, AT91_RTC_ALARM);
187 at91_rtc_imr |= AT91_RTC_ALARM;
183 at91_rtc_write(AT91_RTC_IER, AT91_RTC_ALARM); 188 at91_rtc_write(AT91_RTC_IER, AT91_RTC_ALARM);
184 } 189 }
185 190
@@ -196,9 +201,12 @@ static int at91_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled)
196 201
197 if (enabled) { 202 if (enabled) {
198 at91_rtc_write(AT91_RTC_SCCR, AT91_RTC_ALARM); 203 at91_rtc_write(AT91_RTC_SCCR, AT91_RTC_ALARM);
204 at91_rtc_imr |= AT91_RTC_ALARM;
199 at91_rtc_write(AT91_RTC_IER, AT91_RTC_ALARM); 205 at91_rtc_write(AT91_RTC_IER, AT91_RTC_ALARM);
200 } else 206 } else {
201 at91_rtc_write(AT91_RTC_IDR, AT91_RTC_ALARM); 207 at91_rtc_write(AT91_RTC_IDR, AT91_RTC_ALARM);
208 at91_rtc_imr &= ~AT91_RTC_ALARM;
209 }
202 210
203 return 0; 211 return 0;
204} 212}
@@ -207,12 +215,10 @@ static int at91_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled)
207 */ 215 */
208static int at91_rtc_proc(struct device *dev, struct seq_file *seq) 216static int at91_rtc_proc(struct device *dev, struct seq_file *seq)
209{ 217{
210 unsigned long imr = at91_rtc_read(AT91_RTC_IMR);
211
212 seq_printf(seq, "update_IRQ\t: %s\n", 218 seq_printf(seq, "update_IRQ\t: %s\n",
213 (imr & AT91_RTC_ACKUPD) ? "yes" : "no"); 219 (at91_rtc_imr & AT91_RTC_ACKUPD) ? "yes" : "no");
214 seq_printf(seq, "periodic_IRQ\t: %s\n", 220 seq_printf(seq, "periodic_IRQ\t: %s\n",
215 (imr & AT91_RTC_SECEV) ? "yes" : "no"); 221 (at91_rtc_imr & AT91_RTC_SECEV) ? "yes" : "no");
216 222
217 return 0; 223 return 0;
218} 224}
@@ -227,7 +233,7 @@ static irqreturn_t at91_rtc_interrupt(int irq, void *dev_id)
227 unsigned int rtsr; 233 unsigned int rtsr;
228 unsigned long events = 0; 234 unsigned long events = 0;
229 235
230 rtsr = at91_rtc_read(AT91_RTC_SR) & at91_rtc_read(AT91_RTC_IMR); 236 rtsr = at91_rtc_read(AT91_RTC_SR) & at91_rtc_imr;
231 if (rtsr) { /* this interrupt is shared! Is it ours? */ 237 if (rtsr) { /* this interrupt is shared! Is it ours? */
232 if (rtsr & AT91_RTC_ALARM) 238 if (rtsr & AT91_RTC_ALARM)
233 events |= (RTC_AF | RTC_IRQF); 239 events |= (RTC_AF | RTC_IRQF);
@@ -291,6 +297,7 @@ static int __init at91_rtc_probe(struct platform_device *pdev)
291 at91_rtc_write(AT91_RTC_IDR, AT91_RTC_ACKUPD | AT91_RTC_ALARM | 297 at91_rtc_write(AT91_RTC_IDR, AT91_RTC_ACKUPD | AT91_RTC_ALARM |
292 AT91_RTC_SECEV | AT91_RTC_TIMEV | 298 AT91_RTC_SECEV | AT91_RTC_TIMEV |
293 AT91_RTC_CALEV); 299 AT91_RTC_CALEV);
300 at91_rtc_imr = 0;
294 301
295 ret = request_irq(irq, at91_rtc_interrupt, 302 ret = request_irq(irq, at91_rtc_interrupt,
296 IRQF_SHARED, 303 IRQF_SHARED,
@@ -329,6 +336,7 @@ static int __exit at91_rtc_remove(struct platform_device *pdev)
329 at91_rtc_write(AT91_RTC_IDR, AT91_RTC_ACKUPD | AT91_RTC_ALARM | 336 at91_rtc_write(AT91_RTC_IDR, AT91_RTC_ACKUPD | AT91_RTC_ALARM |
330 AT91_RTC_SECEV | AT91_RTC_TIMEV | 337 AT91_RTC_SECEV | AT91_RTC_TIMEV |
331 AT91_RTC_CALEV); 338 AT91_RTC_CALEV);
339 at91_rtc_imr = 0;
332 free_irq(irq, pdev); 340 free_irq(irq, pdev);
333 341
334 rtc_device_unregister(rtc); 342 rtc_device_unregister(rtc);
@@ -341,31 +349,35 @@ static int __exit at91_rtc_remove(struct platform_device *pdev)
341 349
342/* AT91RM9200 RTC Power management control */ 350/* AT91RM9200 RTC Power management control */
343 351
344static u32 at91_rtc_imr; 352static u32 at91_rtc_bkpimr;
353
345 354
346static int at91_rtc_suspend(struct device *dev) 355static int at91_rtc_suspend(struct device *dev)
347{ 356{
348 /* this IRQ is shared with DBGU and other hardware which isn't 357 /* this IRQ is shared with DBGU and other hardware which isn't
349 * necessarily doing PM like we are... 358 * necessarily doing PM like we are...
350 */ 359 */
351 at91_rtc_imr = at91_rtc_read(AT91_RTC_IMR) 360 at91_rtc_bkpimr = at91_rtc_imr & (AT91_RTC_ALARM|AT91_RTC_SECEV);
352 & (AT91_RTC_ALARM|AT91_RTC_SECEV); 361 if (at91_rtc_bkpimr) {
353 if (at91_rtc_imr) { 362 if (device_may_wakeup(dev)) {
354 if (device_may_wakeup(dev))
355 enable_irq_wake(irq); 363 enable_irq_wake(irq);
356 else 364 } else {
357 at91_rtc_write(AT91_RTC_IDR, at91_rtc_imr); 365 at91_rtc_write(AT91_RTC_IDR, at91_rtc_bkpimr);
358 } 366 at91_rtc_imr &= ~at91_rtc_bkpimr;
367 }
368}
359 return 0; 369 return 0;
360} 370}
361 371
362static int at91_rtc_resume(struct device *dev) 372static int at91_rtc_resume(struct device *dev)
363{ 373{
364 if (at91_rtc_imr) { 374 if (at91_rtc_bkpimr) {
365 if (device_may_wakeup(dev)) 375 if (device_may_wakeup(dev)) {
366 disable_irq_wake(irq); 376 disable_irq_wake(irq);
367 else 377 } else {
368 at91_rtc_write(AT91_RTC_IER, at91_rtc_imr); 378 at91_rtc_imr |= at91_rtc_bkpimr;
379 at91_rtc_write(AT91_RTC_IER, at91_rtc_bkpimr);
380 }
369 } 381 }
370 return 0; 382 return 0;
371} 383}
diff --git a/drivers/rtc/rtc-at91rm9200.h b/drivers/rtc/rtc-at91rm9200.h
index da1945e5f714..5f940b6844cb 100644
--- a/drivers/rtc/rtc-at91rm9200.h
+++ b/drivers/rtc/rtc-at91rm9200.h
@@ -64,7 +64,6 @@
64#define AT91_RTC_SCCR 0x1c /* Status Clear Command Register */ 64#define AT91_RTC_SCCR 0x1c /* Status Clear Command Register */
65#define AT91_RTC_IER 0x20 /* Interrupt Enable Register */ 65#define AT91_RTC_IER 0x20 /* Interrupt Enable Register */
66#define AT91_RTC_IDR 0x24 /* Interrupt Disable Register */ 66#define AT91_RTC_IDR 0x24 /* Interrupt Disable Register */
67#define AT91_RTC_IMR 0x28 /* Interrupt Mask Register */
68 67
69#define AT91_RTC_VER 0x2c /* Valid Entry Register */ 68#define AT91_RTC_VER 0x2c /* Valid Entry Register */
70#define AT91_RTC_NVTIM (1 << 0) /* Non valid Time */ 69#define AT91_RTC_NVTIM (1 << 0) /* Non valid Time */
diff --git a/drivers/rtc/rtc-da9052.c b/drivers/rtc/rtc-da9052.c
index 0dde688ca09b..969abbad7fe3 100644
--- a/drivers/rtc/rtc-da9052.c
+++ b/drivers/rtc/rtc-da9052.c
@@ -239,11 +239,9 @@ static int da9052_rtc_probe(struct platform_device *pdev)
239 239
240 rtc->da9052 = dev_get_drvdata(pdev->dev.parent); 240 rtc->da9052 = dev_get_drvdata(pdev->dev.parent);
241 platform_set_drvdata(pdev, rtc); 241 platform_set_drvdata(pdev, rtc);
242 rtc->irq = platform_get_irq_byname(pdev, "ALM"); 242 rtc->irq = DA9052_IRQ_ALARM;
243 ret = devm_request_threaded_irq(&pdev->dev, rtc->irq, NULL, 243 ret = da9052_request_irq(rtc->da9052, rtc->irq, "ALM",
244 da9052_rtc_irq, 244 da9052_rtc_irq, rtc);
245 IRQF_TRIGGER_LOW | IRQF_ONESHOT,
246 "ALM", rtc);
247 if (ret != 0) { 245 if (ret != 0) {
248 rtc_err(rtc->da9052, "irq registration failed: %d\n", ret); 246 rtc_err(rtc->da9052, "irq registration failed: %d\n", ret);
249 return ret; 247 return ret;
diff --git a/drivers/s390/block/scm_blk.c b/drivers/s390/block/scm_blk.c
index 9978ad4433cb..5ac9c935c151 100644
--- a/drivers/s390/block/scm_blk.c
+++ b/drivers/s390/block/scm_blk.c
@@ -135,6 +135,11 @@ static const struct block_device_operations scm_blk_devops = {
135 .release = scm_release, 135 .release = scm_release,
136}; 136};
137 137
138static bool scm_permit_request(struct scm_blk_dev *bdev, struct request *req)
139{
140 return rq_data_dir(req) != WRITE || bdev->state != SCM_WR_PROHIBIT;
141}
142
138static void scm_request_prepare(struct scm_request *scmrq) 143static void scm_request_prepare(struct scm_request *scmrq)
139{ 144{
140 struct scm_blk_dev *bdev = scmrq->bdev; 145 struct scm_blk_dev *bdev = scmrq->bdev;
@@ -195,14 +200,18 @@ void scm_request_requeue(struct scm_request *scmrq)
195 200
196 scm_release_cluster(scmrq); 201 scm_release_cluster(scmrq);
197 blk_requeue_request(bdev->rq, scmrq->request); 202 blk_requeue_request(bdev->rq, scmrq->request);
203 atomic_dec(&bdev->queued_reqs);
198 scm_request_done(scmrq); 204 scm_request_done(scmrq);
199 scm_ensure_queue_restart(bdev); 205 scm_ensure_queue_restart(bdev);
200} 206}
201 207
202void scm_request_finish(struct scm_request *scmrq) 208void scm_request_finish(struct scm_request *scmrq)
203{ 209{
210 struct scm_blk_dev *bdev = scmrq->bdev;
211
204 scm_release_cluster(scmrq); 212 scm_release_cluster(scmrq);
205 blk_end_request_all(scmrq->request, scmrq->error); 213 blk_end_request_all(scmrq->request, scmrq->error);
214 atomic_dec(&bdev->queued_reqs);
206 scm_request_done(scmrq); 215 scm_request_done(scmrq);
207} 216}
208 217
@@ -218,6 +227,10 @@ static void scm_blk_request(struct request_queue *rq)
218 if (req->cmd_type != REQ_TYPE_FS) 227 if (req->cmd_type != REQ_TYPE_FS)
219 continue; 228 continue;
220 229
230 if (!scm_permit_request(bdev, req)) {
231 scm_ensure_queue_restart(bdev);
232 return;
233 }
221 scmrq = scm_request_fetch(); 234 scmrq = scm_request_fetch();
222 if (!scmrq) { 235 if (!scmrq) {
223 SCM_LOG(5, "no request"); 236 SCM_LOG(5, "no request");
@@ -231,11 +244,13 @@ static void scm_blk_request(struct request_queue *rq)
231 return; 244 return;
232 } 245 }
233 if (scm_need_cluster_request(scmrq)) { 246 if (scm_need_cluster_request(scmrq)) {
247 atomic_inc(&bdev->queued_reqs);
234 blk_start_request(req); 248 blk_start_request(req);
235 scm_initiate_cluster_request(scmrq); 249 scm_initiate_cluster_request(scmrq);
236 return; 250 return;
237 } 251 }
238 scm_request_prepare(scmrq); 252 scm_request_prepare(scmrq);
253 atomic_inc(&bdev->queued_reqs);
239 blk_start_request(req); 254 blk_start_request(req);
240 255
241 ret = scm_start_aob(scmrq->aob); 256 ret = scm_start_aob(scmrq->aob);
@@ -244,7 +259,6 @@ static void scm_blk_request(struct request_queue *rq)
244 scm_request_requeue(scmrq); 259 scm_request_requeue(scmrq);
245 return; 260 return;
246 } 261 }
247 atomic_inc(&bdev->queued_reqs);
248 } 262 }
249} 263}
250 264
@@ -280,6 +294,38 @@ void scm_blk_irq(struct scm_device *scmdev, void *data, int error)
280 tasklet_hi_schedule(&bdev->tasklet); 294 tasklet_hi_schedule(&bdev->tasklet);
281} 295}
282 296
297static void scm_blk_handle_error(struct scm_request *scmrq)
298{
299 struct scm_blk_dev *bdev = scmrq->bdev;
300 unsigned long flags;
301
302 if (scmrq->error != -EIO)
303 goto restart;
304
305 /* For -EIO the response block is valid. */
306 switch (scmrq->aob->response.eqc) {
307 case EQC_WR_PROHIBIT:
308 spin_lock_irqsave(&bdev->lock, flags);
309 if (bdev->state != SCM_WR_PROHIBIT)
310 pr_info("%lu: Write access to the SCM increment is suspended\n",
311 (unsigned long) bdev->scmdev->address);
312 bdev->state = SCM_WR_PROHIBIT;
313 spin_unlock_irqrestore(&bdev->lock, flags);
314 goto requeue;
315 default:
316 break;
317 }
318
319restart:
320 if (!scm_start_aob(scmrq->aob))
321 return;
322
323requeue:
324 spin_lock_irqsave(&bdev->rq_lock, flags);
325 scm_request_requeue(scmrq);
326 spin_unlock_irqrestore(&bdev->rq_lock, flags);
327}
328
283static void scm_blk_tasklet(struct scm_blk_dev *bdev) 329static void scm_blk_tasklet(struct scm_blk_dev *bdev)
284{ 330{
285 struct scm_request *scmrq; 331 struct scm_request *scmrq;
@@ -293,11 +339,8 @@ static void scm_blk_tasklet(struct scm_blk_dev *bdev)
293 spin_unlock_irqrestore(&bdev->lock, flags); 339 spin_unlock_irqrestore(&bdev->lock, flags);
294 340
295 if (scmrq->error && scmrq->retries-- > 0) { 341 if (scmrq->error && scmrq->retries-- > 0) {
296 if (scm_start_aob(scmrq->aob)) { 342 scm_blk_handle_error(scmrq);
297 spin_lock_irqsave(&bdev->rq_lock, flags); 343
298 scm_request_requeue(scmrq);
299 spin_unlock_irqrestore(&bdev->rq_lock, flags);
300 }
301 /* Request restarted or requeued, handle next. */ 344 /* Request restarted or requeued, handle next. */
302 spin_lock_irqsave(&bdev->lock, flags); 345 spin_lock_irqsave(&bdev->lock, flags);
303 continue; 346 continue;
@@ -310,7 +353,6 @@ static void scm_blk_tasklet(struct scm_blk_dev *bdev)
310 } 353 }
311 354
312 scm_request_finish(scmrq); 355 scm_request_finish(scmrq);
313 atomic_dec(&bdev->queued_reqs);
314 spin_lock_irqsave(&bdev->lock, flags); 356 spin_lock_irqsave(&bdev->lock, flags);
315 } 357 }
316 spin_unlock_irqrestore(&bdev->lock, flags); 358 spin_unlock_irqrestore(&bdev->lock, flags);
@@ -332,6 +374,7 @@ int scm_blk_dev_setup(struct scm_blk_dev *bdev, struct scm_device *scmdev)
332 } 374 }
333 375
334 bdev->scmdev = scmdev; 376 bdev->scmdev = scmdev;
377 bdev->state = SCM_OPER;
335 spin_lock_init(&bdev->rq_lock); 378 spin_lock_init(&bdev->rq_lock);
336 spin_lock_init(&bdev->lock); 379 spin_lock_init(&bdev->lock);
337 INIT_LIST_HEAD(&bdev->finished_requests); 380 INIT_LIST_HEAD(&bdev->finished_requests);
@@ -396,6 +439,18 @@ void scm_blk_dev_cleanup(struct scm_blk_dev *bdev)
396 put_disk(bdev->gendisk); 439 put_disk(bdev->gendisk);
397} 440}
398 441
442void scm_blk_set_available(struct scm_blk_dev *bdev)
443{
444 unsigned long flags;
445
446 spin_lock_irqsave(&bdev->lock, flags);
447 if (bdev->state == SCM_WR_PROHIBIT)
448 pr_info("%lu: Write access to the SCM increment is restored\n",
449 (unsigned long) bdev->scmdev->address);
450 bdev->state = SCM_OPER;
451 spin_unlock_irqrestore(&bdev->lock, flags);
452}
453
399static int __init scm_blk_init(void) 454static int __init scm_blk_init(void)
400{ 455{
401 int ret = -EINVAL; 456 int ret = -EINVAL;
diff --git a/drivers/s390/block/scm_blk.h b/drivers/s390/block/scm_blk.h
index 3c1ccf494647..8b387b32fd62 100644
--- a/drivers/s390/block/scm_blk.h
+++ b/drivers/s390/block/scm_blk.h
@@ -21,6 +21,7 @@ struct scm_blk_dev {
21 spinlock_t rq_lock; /* guard the request queue */ 21 spinlock_t rq_lock; /* guard the request queue */
22 spinlock_t lock; /* guard the rest of the blockdev */ 22 spinlock_t lock; /* guard the rest of the blockdev */
23 atomic_t queued_reqs; 23 atomic_t queued_reqs;
24 enum {SCM_OPER, SCM_WR_PROHIBIT} state;
24 struct list_head finished_requests; 25 struct list_head finished_requests;
25#ifdef CONFIG_SCM_BLOCK_CLUSTER_WRITE 26#ifdef CONFIG_SCM_BLOCK_CLUSTER_WRITE
26 struct list_head cluster_list; 27 struct list_head cluster_list;
@@ -48,6 +49,7 @@ struct scm_request {
48 49
49int scm_blk_dev_setup(struct scm_blk_dev *, struct scm_device *); 50int scm_blk_dev_setup(struct scm_blk_dev *, struct scm_device *);
50void scm_blk_dev_cleanup(struct scm_blk_dev *); 51void scm_blk_dev_cleanup(struct scm_blk_dev *);
52void scm_blk_set_available(struct scm_blk_dev *);
51void scm_blk_irq(struct scm_device *, void *, int); 53void scm_blk_irq(struct scm_device *, void *, int);
52 54
53void scm_request_finish(struct scm_request *); 55void scm_request_finish(struct scm_request *);
diff --git a/drivers/s390/block/scm_drv.c b/drivers/s390/block/scm_drv.c
index 9fa0a908607b..5f6180d6ff08 100644
--- a/drivers/s390/block/scm_drv.c
+++ b/drivers/s390/block/scm_drv.c
@@ -13,12 +13,23 @@
13#include <asm/eadm.h> 13#include <asm/eadm.h>
14#include "scm_blk.h" 14#include "scm_blk.h"
15 15
16static void notify(struct scm_device *scmdev) 16static void scm_notify(struct scm_device *scmdev, enum scm_event event)
17{ 17{
18 pr_info("%lu: The capabilities of the SCM increment changed\n", 18 struct scm_blk_dev *bdev = dev_get_drvdata(&scmdev->dev);
19 (unsigned long) scmdev->address); 19
20 SCM_LOG(2, "State changed"); 20 switch (event) {
21 SCM_LOG_STATE(2, scmdev); 21 case SCM_CHANGE:
22 pr_info("%lu: The capabilities of the SCM increment changed\n",
23 (unsigned long) scmdev->address);
24 SCM_LOG(2, "State changed");
25 SCM_LOG_STATE(2, scmdev);
26 break;
27 case SCM_AVAIL:
28 SCM_LOG(2, "Increment available");
29 SCM_LOG_STATE(2, scmdev);
30 scm_blk_set_available(bdev);
31 break;
32 }
22} 33}
23 34
24static int scm_probe(struct scm_device *scmdev) 35static int scm_probe(struct scm_device *scmdev)
@@ -64,7 +75,7 @@ static struct scm_driver scm_drv = {
64 .name = "scm_block", 75 .name = "scm_block",
65 .owner = THIS_MODULE, 76 .owner = THIS_MODULE,
66 }, 77 },
67 .notify = notify, 78 .notify = scm_notify,
68 .probe = scm_probe, 79 .probe = scm_probe,
69 .remove = scm_remove, 80 .remove = scm_remove,
70 .handler = scm_blk_irq, 81 .handler = scm_blk_irq,
diff --git a/drivers/s390/char/sclp_cmd.c b/drivers/s390/char/sclp_cmd.c
index 30a2255389e5..cd798386b622 100644
--- a/drivers/s390/char/sclp_cmd.c
+++ b/drivers/s390/char/sclp_cmd.c
@@ -627,6 +627,8 @@ static int __init sclp_detect_standby_memory(void)
627 struct read_storage_sccb *sccb; 627 struct read_storage_sccb *sccb;
628 int i, id, assigned, rc; 628 int i, id, assigned, rc;
629 629
630 if (OLDMEM_BASE) /* No standby memory in kdump mode */
631 return 0;
630 if (!early_read_info_sccb_valid) 632 if (!early_read_info_sccb_valid)
631 return 0; 633 return 0;
632 if ((sclp_facilities & 0xe00000000000ULL) != 0xe00000000000ULL) 634 if ((sclp_facilities & 0xe00000000000ULL) != 0xe00000000000ULL)
diff --git a/drivers/s390/cio/chsc.c b/drivers/s390/cio/chsc.c
index 31ceef1beb8b..e16c553f6556 100644
--- a/drivers/s390/cio/chsc.c
+++ b/drivers/s390/cio/chsc.c
@@ -433,6 +433,20 @@ static void chsc_process_sei_scm_change(struct chsc_sei_nt0_area *sei_area)
433 " failed (rc=%d).\n", ret); 433 " failed (rc=%d).\n", ret);
434} 434}
435 435
436static void chsc_process_sei_scm_avail(struct chsc_sei_nt0_area *sei_area)
437{
438 int ret;
439
440 CIO_CRW_EVENT(4, "chsc: scm available information\n");
441 if (sei_area->rs != 7)
442 return;
443
444 ret = scm_process_availability_information();
445 if (ret)
446 CIO_CRW_EVENT(0, "chsc: process availability information"
447 " failed (rc=%d).\n", ret);
448}
449
436static void chsc_process_sei_nt2(struct chsc_sei_nt2_area *sei_area) 450static void chsc_process_sei_nt2(struct chsc_sei_nt2_area *sei_area)
437{ 451{
438 switch (sei_area->cc) { 452 switch (sei_area->cc) {
@@ -468,6 +482,9 @@ static void chsc_process_sei_nt0(struct chsc_sei_nt0_area *sei_area)
468 case 12: /* scm change notification */ 482 case 12: /* scm change notification */
469 chsc_process_sei_scm_change(sei_area); 483 chsc_process_sei_scm_change(sei_area);
470 break; 484 break;
485 case 14: /* scm available notification */
486 chsc_process_sei_scm_avail(sei_area);
487 break;
471 default: /* other stuff */ 488 default: /* other stuff */
472 CIO_CRW_EVENT(2, "chsc: sei nt0 unhandled cc=%d\n", 489 CIO_CRW_EVENT(2, "chsc: sei nt0 unhandled cc=%d\n",
473 sei_area->cc); 490 sei_area->cc);
diff --git a/drivers/s390/cio/chsc.h b/drivers/s390/cio/chsc.h
index 227e05f674b3..349d5fc47196 100644
--- a/drivers/s390/cio/chsc.h
+++ b/drivers/s390/cio/chsc.h
@@ -156,8 +156,10 @@ int chsc_scm_info(struct chsc_scm_info *scm_area, u64 token);
156 156
157#ifdef CONFIG_SCM_BUS 157#ifdef CONFIG_SCM_BUS
158int scm_update_information(void); 158int scm_update_information(void);
159int scm_process_availability_information(void);
159#else /* CONFIG_SCM_BUS */ 160#else /* CONFIG_SCM_BUS */
160static inline int scm_update_information(void) { return 0; } 161static inline int scm_update_information(void) { return 0; }
162static inline int scm_process_availability_information(void) { return 0; }
161#endif /* CONFIG_SCM_BUS */ 163#endif /* CONFIG_SCM_BUS */
162 164
163 165
diff --git a/drivers/s390/cio/scm.c b/drivers/s390/cio/scm.c
index bcf20f3aa51b..46ec25632e8b 100644
--- a/drivers/s390/cio/scm.c
+++ b/drivers/s390/cio/scm.c
@@ -211,7 +211,7 @@ static void scmdev_update(struct scm_device *scmdev, struct sale *sale)
211 goto out; 211 goto out;
212 scmdrv = to_scm_drv(scmdev->dev.driver); 212 scmdrv = to_scm_drv(scmdev->dev.driver);
213 if (changed && scmdrv->notify) 213 if (changed && scmdrv->notify)
214 scmdrv->notify(scmdev); 214 scmdrv->notify(scmdev, SCM_CHANGE);
215out: 215out:
216 device_unlock(&scmdev->dev); 216 device_unlock(&scmdev->dev);
217 if (changed) 217 if (changed)
@@ -297,6 +297,22 @@ int scm_update_information(void)
297 return ret; 297 return ret;
298} 298}
299 299
300static int scm_dev_avail(struct device *dev, void *unused)
301{
302 struct scm_driver *scmdrv = to_scm_drv(dev->driver);
303 struct scm_device *scmdev = to_scm_dev(dev);
304
305 if (dev->driver && scmdrv->notify)
306 scmdrv->notify(scmdev, SCM_AVAIL);
307
308 return 0;
309}
310
311int scm_process_availability_information(void)
312{
313 return bus_for_each_dev(&scm_bus_type, NULL, NULL, scm_dev_avail);
314}
315
300static int __init scm_init(void) 316static int __init scm_init(void)
301{ 317{
302 int ret; 318 int ret;
diff --git a/drivers/s390/net/qeth_core.h b/drivers/s390/net/qeth_core.h
index d87961d4c0de..8c0622399fcd 100644
--- a/drivers/s390/net/qeth_core.h
+++ b/drivers/s390/net/qeth_core.h
@@ -916,6 +916,7 @@ int qeth_send_control_data(struct qeth_card *, int, struct qeth_cmd_buffer *,
916 void *reply_param); 916 void *reply_param);
917int qeth_get_priority_queue(struct qeth_card *, struct sk_buff *, int, int); 917int qeth_get_priority_queue(struct qeth_card *, struct sk_buff *, int, int);
918int qeth_get_elements_no(struct qeth_card *, void *, struct sk_buff *, int); 918int qeth_get_elements_no(struct qeth_card *, void *, struct sk_buff *, int);
919int qeth_get_elements_for_frags(struct sk_buff *);
919int qeth_do_send_packet_fast(struct qeth_card *, struct qeth_qdio_out_q *, 920int qeth_do_send_packet_fast(struct qeth_card *, struct qeth_qdio_out_q *,
920 struct sk_buff *, struct qeth_hdr *, int, int, int); 921 struct sk_buff *, struct qeth_hdr *, int, int, int);
921int qeth_do_send_packet(struct qeth_card *, struct qeth_qdio_out_q *, 922int qeth_do_send_packet(struct qeth_card *, struct qeth_qdio_out_q *,
diff --git a/drivers/s390/net/qeth_core_main.c b/drivers/s390/net/qeth_core_main.c
index 0d8cdff81813..0d73a999983d 100644
--- a/drivers/s390/net/qeth_core_main.c
+++ b/drivers/s390/net/qeth_core_main.c
@@ -3679,6 +3679,25 @@ int qeth_get_priority_queue(struct qeth_card *card, struct sk_buff *skb,
3679} 3679}
3680EXPORT_SYMBOL_GPL(qeth_get_priority_queue); 3680EXPORT_SYMBOL_GPL(qeth_get_priority_queue);
3681 3681
3682int qeth_get_elements_for_frags(struct sk_buff *skb)
3683{
3684 int cnt, length, e, elements = 0;
3685 struct skb_frag_struct *frag;
3686 char *data;
3687
3688 for (cnt = 0; cnt < skb_shinfo(skb)->nr_frags; cnt++) {
3689 frag = &skb_shinfo(skb)->frags[cnt];
3690 data = (char *)page_to_phys(skb_frag_page(frag)) +
3691 frag->page_offset;
3692 length = frag->size;
3693 e = PFN_UP((unsigned long)data + length - 1) -
3694 PFN_DOWN((unsigned long)data);
3695 elements += e;
3696 }
3697 return elements;
3698}
3699EXPORT_SYMBOL_GPL(qeth_get_elements_for_frags);
3700
3682int qeth_get_elements_no(struct qeth_card *card, void *hdr, 3701int qeth_get_elements_no(struct qeth_card *card, void *hdr,
3683 struct sk_buff *skb, int elems) 3702 struct sk_buff *skb, int elems)
3684{ 3703{
@@ -3686,7 +3705,8 @@ int qeth_get_elements_no(struct qeth_card *card, void *hdr,
3686 int elements_needed = PFN_UP((unsigned long)skb->data + dlen - 1) - 3705 int elements_needed = PFN_UP((unsigned long)skb->data + dlen - 1) -
3687 PFN_DOWN((unsigned long)skb->data); 3706 PFN_DOWN((unsigned long)skb->data);
3688 3707
3689 elements_needed += skb_shinfo(skb)->nr_frags; 3708 elements_needed += qeth_get_elements_for_frags(skb);
3709
3690 if ((elements_needed + elems) > QETH_MAX_BUFFER_ELEMENTS(card)) { 3710 if ((elements_needed + elems) > QETH_MAX_BUFFER_ELEMENTS(card)) {
3691 QETH_DBF_MESSAGE(2, "Invalid size of IP packet " 3711 QETH_DBF_MESSAGE(2, "Invalid size of IP packet "
3692 "(Number=%d / Length=%d). Discarded.\n", 3712 "(Number=%d / Length=%d). Discarded.\n",
@@ -3771,12 +3791,23 @@ static inline void __qeth_fill_buffer(struct sk_buff *skb,
3771 3791
3772 for (cnt = 0; cnt < skb_shinfo(skb)->nr_frags; cnt++) { 3792 for (cnt = 0; cnt < skb_shinfo(skb)->nr_frags; cnt++) {
3773 frag = &skb_shinfo(skb)->frags[cnt]; 3793 frag = &skb_shinfo(skb)->frags[cnt];
3774 buffer->element[element].addr = (char *) 3794 data = (char *)page_to_phys(skb_frag_page(frag)) +
3775 page_to_phys(skb_frag_page(frag)) 3795 frag->page_offset;
3776 + frag->page_offset; 3796 length = frag->size;
3777 buffer->element[element].length = frag->size; 3797 while (length > 0) {
3778 buffer->element[element].eflags = SBAL_EFLAGS_MIDDLE_FRAG; 3798 length_here = PAGE_SIZE -
3779 element++; 3799 ((unsigned long) data % PAGE_SIZE);
3800 if (length < length_here)
3801 length_here = length;
3802
3803 buffer->element[element].addr = data;
3804 buffer->element[element].length = length_here;
3805 buffer->element[element].eflags =
3806 SBAL_EFLAGS_MIDDLE_FRAG;
3807 length -= length_here;
3808 data += length_here;
3809 element++;
3810 }
3780 } 3811 }
3781 3812
3782 if (buffer->element[element - 1].eflags) 3813 if (buffer->element[element - 1].eflags)
diff --git a/drivers/s390/net/qeth_l3_main.c b/drivers/s390/net/qeth_l3_main.c
index 091ca0efa1c5..8710337dab3e 100644
--- a/drivers/s390/net/qeth_l3_main.c
+++ b/drivers/s390/net/qeth_l3_main.c
@@ -623,7 +623,7 @@ static int qeth_l3_send_setrouting(struct qeth_card *card,
623 return rc; 623 return rc;
624} 624}
625 625
626static void qeth_l3_correct_routing_type(struct qeth_card *card, 626static int qeth_l3_correct_routing_type(struct qeth_card *card,
627 enum qeth_routing_types *type, enum qeth_prot_versions prot) 627 enum qeth_routing_types *type, enum qeth_prot_versions prot)
628{ 628{
629 if (card->info.type == QETH_CARD_TYPE_IQD) { 629 if (card->info.type == QETH_CARD_TYPE_IQD) {
@@ -632,7 +632,7 @@ static void qeth_l3_correct_routing_type(struct qeth_card *card,
632 case PRIMARY_CONNECTOR: 632 case PRIMARY_CONNECTOR:
633 case SECONDARY_CONNECTOR: 633 case SECONDARY_CONNECTOR:
634 case MULTICAST_ROUTER: 634 case MULTICAST_ROUTER:
635 return; 635 return 0;
636 default: 636 default:
637 goto out_inval; 637 goto out_inval;
638 } 638 }
@@ -641,17 +641,18 @@ static void qeth_l3_correct_routing_type(struct qeth_card *card,
641 case NO_ROUTER: 641 case NO_ROUTER:
642 case PRIMARY_ROUTER: 642 case PRIMARY_ROUTER:
643 case SECONDARY_ROUTER: 643 case SECONDARY_ROUTER:
644 return; 644 return 0;
645 case MULTICAST_ROUTER: 645 case MULTICAST_ROUTER:
646 if (qeth_is_ipafunc_supported(card, prot, 646 if (qeth_is_ipafunc_supported(card, prot,
647 IPA_OSA_MC_ROUTER)) 647 IPA_OSA_MC_ROUTER))
648 return; 648 return 0;
649 default: 649 default:
650 goto out_inval; 650 goto out_inval;
651 } 651 }
652 } 652 }
653out_inval: 653out_inval:
654 *type = NO_ROUTER; 654 *type = NO_ROUTER;
655 return -EINVAL;
655} 656}
656 657
657int qeth_l3_setrouting_v4(struct qeth_card *card) 658int qeth_l3_setrouting_v4(struct qeth_card *card)
@@ -660,8 +661,10 @@ int qeth_l3_setrouting_v4(struct qeth_card *card)
660 661
661 QETH_CARD_TEXT(card, 3, "setrtg4"); 662 QETH_CARD_TEXT(card, 3, "setrtg4");
662 663
663 qeth_l3_correct_routing_type(card, &card->options.route4.type, 664 rc = qeth_l3_correct_routing_type(card, &card->options.route4.type,
664 QETH_PROT_IPV4); 665 QETH_PROT_IPV4);
666 if (rc)
667 return rc;
665 668
666 rc = qeth_l3_send_setrouting(card, card->options.route4.type, 669 rc = qeth_l3_send_setrouting(card, card->options.route4.type,
667 QETH_PROT_IPV4); 670 QETH_PROT_IPV4);
@@ -683,8 +686,10 @@ int qeth_l3_setrouting_v6(struct qeth_card *card)
683 686
684 if (!qeth_is_supported(card, IPA_IPV6)) 687 if (!qeth_is_supported(card, IPA_IPV6))
685 return 0; 688 return 0;
686 qeth_l3_correct_routing_type(card, &card->options.route6.type, 689 rc = qeth_l3_correct_routing_type(card, &card->options.route6.type,
687 QETH_PROT_IPV6); 690 QETH_PROT_IPV6);
691 if (rc)
692 return rc;
688 693
689 rc = qeth_l3_send_setrouting(card, card->options.route6.type, 694 rc = qeth_l3_send_setrouting(card, card->options.route6.type,
690 QETH_PROT_IPV6); 695 QETH_PROT_IPV6);
@@ -2898,7 +2903,9 @@ static inline int qeth_l3_tso_elements(struct sk_buff *skb)
2898 tcp_hdr(skb)->doff * 4; 2903 tcp_hdr(skb)->doff * 4;
2899 int tcpd_len = skb->len - (tcpd - (unsigned long)skb->data); 2904 int tcpd_len = skb->len - (tcpd - (unsigned long)skb->data);
2900 int elements = PFN_UP(tcpd + tcpd_len - 1) - PFN_DOWN(tcpd); 2905 int elements = PFN_UP(tcpd + tcpd_len - 1) - PFN_DOWN(tcpd);
2901 elements += skb_shinfo(skb)->nr_frags; 2906
2907 elements += qeth_get_elements_for_frags(skb);
2908
2902 return elements; 2909 return elements;
2903} 2910}
2904 2911
@@ -3348,7 +3355,6 @@ static int __qeth_l3_set_online(struct ccwgroup_device *gdev, int recovery_mode)
3348 rc = -ENODEV; 3355 rc = -ENODEV;
3349 goto out_remove; 3356 goto out_remove;
3350 } 3357 }
3351 qeth_trace_features(card);
3352 3358
3353 if (!card->dev && qeth_l3_setup_netdev(card)) { 3359 if (!card->dev && qeth_l3_setup_netdev(card)) {
3354 rc = -ENODEV; 3360 rc = -ENODEV;
@@ -3425,6 +3431,7 @@ contin:
3425 qeth_l3_set_multicast_list(card->dev); 3431 qeth_l3_set_multicast_list(card->dev);
3426 rtnl_unlock(); 3432 rtnl_unlock();
3427 } 3433 }
3434 qeth_trace_features(card);
3428 /* let user_space know that device is online */ 3435 /* let user_space know that device is online */
3429 kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE); 3436 kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE);
3430 mutex_unlock(&card->conf_mutex); 3437 mutex_unlock(&card->conf_mutex);
diff --git a/drivers/s390/net/qeth_l3_sys.c b/drivers/s390/net/qeth_l3_sys.c
index ebc379486267..e70af2406ff9 100644
--- a/drivers/s390/net/qeth_l3_sys.c
+++ b/drivers/s390/net/qeth_l3_sys.c
@@ -87,6 +87,8 @@ static ssize_t qeth_l3_dev_route_store(struct qeth_card *card,
87 rc = qeth_l3_setrouting_v6(card); 87 rc = qeth_l3_setrouting_v6(card);
88 } 88 }
89out: 89out:
90 if (rc)
91 route->type = old_route_type;
90 mutex_unlock(&card->conf_mutex); 92 mutex_unlock(&card->conf_mutex);
91 return rc ? rc : count; 93 return rc ? rc : count;
92} 94}
diff --git a/drivers/staging/comedi/drivers/s626.c b/drivers/staging/comedi/drivers/s626.c
index 81a1fe661579..71a73ec5af8d 100644
--- a/drivers/staging/comedi/drivers/s626.c
+++ b/drivers/staging/comedi/drivers/s626.c
@@ -1483,7 +1483,7 @@ static int s626_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
1483 case TRIG_NONE: 1483 case TRIG_NONE:
1484 /* continous acquisition */ 1484 /* continous acquisition */
1485 devpriv->ai_continous = 1; 1485 devpriv->ai_continous = 1;
1486 devpriv->ai_sample_count = 0; 1486 devpriv->ai_sample_count = 1;
1487 break; 1487 break;
1488 } 1488 }
1489 1489
diff --git a/drivers/staging/zcache/Kconfig b/drivers/staging/zcache/Kconfig
index 73582705e8c5..5c3714530961 100644
--- a/drivers/staging/zcache/Kconfig
+++ b/drivers/staging/zcache/Kconfig
@@ -15,7 +15,7 @@ config RAMSTER
15 depends on CONFIGFS_FS=y && SYSFS=y && !HIGHMEM && ZCACHE=y 15 depends on CONFIGFS_FS=y && SYSFS=y && !HIGHMEM && ZCACHE=y
16 depends on NET 16 depends on NET
17 # must ensure struct page is 8-byte aligned 17 # must ensure struct page is 8-byte aligned
18 select HAVE_ALIGNED_STRUCT_PAGE if !64_BIT 18 select HAVE_ALIGNED_STRUCT_PAGE if !64BIT
19 default n 19 default n
20 help 20 help
21 RAMster allows RAM on other machines in a cluster to be utilized 21 RAMster allows RAM on other machines in a cluster to be utilized
diff --git a/drivers/target/iscsi/iscsi_target_auth.c b/drivers/target/iscsi/iscsi_target_auth.c
index db0cf7c8adde..a0fc7b9eea65 100644
--- a/drivers/target/iscsi/iscsi_target_auth.c
+++ b/drivers/target/iscsi/iscsi_target_auth.c
@@ -166,6 +166,7 @@ static int chap_server_compute_md5(
166{ 166{
167 char *endptr; 167 char *endptr;
168 unsigned long id; 168 unsigned long id;
169 unsigned char id_as_uchar;
169 unsigned char digest[MD5_SIGNATURE_SIZE]; 170 unsigned char digest[MD5_SIGNATURE_SIZE];
170 unsigned char type, response[MD5_SIGNATURE_SIZE * 2 + 2]; 171 unsigned char type, response[MD5_SIGNATURE_SIZE * 2 + 2];
171 unsigned char identifier[10], *challenge = NULL; 172 unsigned char identifier[10], *challenge = NULL;
@@ -355,7 +356,9 @@ static int chap_server_compute_md5(
355 goto out; 356 goto out;
356 } 357 }
357 358
358 sg_init_one(&sg, &id, 1); 359 /* To handle both endiannesses */
360 id_as_uchar = id;
361 sg_init_one(&sg, &id_as_uchar, 1);
359 ret = crypto_hash_update(&desc, &sg, 1); 362 ret = crypto_hash_update(&desc, &sg, 1);
360 if (ret < 0) { 363 if (ret < 0) {
361 pr_err("crypto_hash_update() failed for id\n"); 364 pr_err("crypto_hash_update() failed for id\n");
diff --git a/drivers/target/target_core_file.h b/drivers/target/target_core_file.h
index bc02b018ae46..37ffc5bd2399 100644
--- a/drivers/target/target_core_file.h
+++ b/drivers/target/target_core_file.h
@@ -7,7 +7,7 @@
7#define FD_DEVICE_QUEUE_DEPTH 32 7#define FD_DEVICE_QUEUE_DEPTH 32
8#define FD_MAX_DEVICE_QUEUE_DEPTH 128 8#define FD_MAX_DEVICE_QUEUE_DEPTH 128
9#define FD_BLOCKSIZE 512 9#define FD_BLOCKSIZE 512
10#define FD_MAX_SECTORS 1024 10#define FD_MAX_SECTORS 2048
11 11
12#define RRF_EMULATE_CDB 0x01 12#define RRF_EMULATE_CDB 0x01
13#define RRF_GOT_LBA 0x02 13#define RRF_GOT_LBA 0x02
diff --git a/drivers/target/target_core_pscsi.c b/drivers/target/target_core_pscsi.c
index 82e78d72fdb6..e992b27aa090 100644
--- a/drivers/target/target_core_pscsi.c
+++ b/drivers/target/target_core_pscsi.c
@@ -883,7 +883,14 @@ pscsi_map_sg(struct se_cmd *cmd, struct scatterlist *sgl, u32 sgl_nents,
883 pr_debug("PSCSI: i: %d page: %p len: %d off: %d\n", i, 883 pr_debug("PSCSI: i: %d page: %p len: %d off: %d\n", i,
884 page, len, off); 884 page, len, off);
885 885
886 while (len > 0 && data_len > 0) { 886 /*
887 * We only have one page of data in each sg element,
888 * we can not cross a page boundary.
889 */
890 if (off + len > PAGE_SIZE)
891 goto fail;
892
893 if (len > 0 && data_len > 0) {
887 bytes = min_t(unsigned int, len, PAGE_SIZE - off); 894 bytes = min_t(unsigned int, len, PAGE_SIZE - off);
888 bytes = min(bytes, data_len); 895 bytes = min(bytes, data_len);
889 896
@@ -940,9 +947,7 @@ pscsi_map_sg(struct se_cmd *cmd, struct scatterlist *sgl, u32 sgl_nents,
940 bio = NULL; 947 bio = NULL;
941 } 948 }
942 949
943 len -= bytes;
944 data_len -= bytes; 950 data_len -= bytes;
945 off = 0;
946 } 951 }
947 } 952 }
948 953
diff --git a/drivers/target/target_core_sbc.c b/drivers/target/target_core_sbc.c
index 290230de2c53..60d4b5185f32 100644
--- a/drivers/target/target_core_sbc.c
+++ b/drivers/target/target_core_sbc.c
@@ -464,8 +464,11 @@ sbc_parse_cdb(struct se_cmd *cmd, struct sbc_ops *ops)
464 break; 464 break;
465 case SYNCHRONIZE_CACHE: 465 case SYNCHRONIZE_CACHE:
466 case SYNCHRONIZE_CACHE_16: 466 case SYNCHRONIZE_CACHE_16:
467 if (!ops->execute_sync_cache) 467 if (!ops->execute_sync_cache) {
468 return TCM_UNSUPPORTED_SCSI_OPCODE; 468 size = 0;
469 cmd->execute_cmd = sbc_emulate_noop;
470 break;
471 }
469 472
470 /* 473 /*
471 * Extract LBA and range to be flushed for emulated SYNCHRONIZE_CACHE 474 * Extract LBA and range to be flushed for emulated SYNCHRONIZE_CACHE
diff --git a/drivers/target/target_core_tpg.c b/drivers/target/target_core_tpg.c
index 9169d6a5d7e4..aac9d2727e3c 100644
--- a/drivers/target/target_core_tpg.c
+++ b/drivers/target/target_core_tpg.c
@@ -711,7 +711,8 @@ int core_tpg_register(
711 711
712 if (se_tpg->se_tpg_type == TRANSPORT_TPG_TYPE_NORMAL) { 712 if (se_tpg->se_tpg_type == TRANSPORT_TPG_TYPE_NORMAL) {
713 if (core_tpg_setup_virtual_lun0(se_tpg) < 0) { 713 if (core_tpg_setup_virtual_lun0(se_tpg) < 0) {
714 kfree(se_tpg); 714 array_free(se_tpg->tpg_lun_list,
715 TRANSPORT_MAX_LUNS_PER_TPG);
715 return -ENOMEM; 716 return -ENOMEM;
716 } 717 }
717 } 718 }
diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
index 2030b608136d..3243ea790eab 100644
--- a/drivers/target/target_core_transport.c
+++ b/drivers/target/target_core_transport.c
@@ -1139,8 +1139,10 @@ target_setup_cmd_from_cdb(struct se_cmd *cmd, unsigned char *cdb)
1139 return ret; 1139 return ret;
1140 1140
1141 ret = target_check_reservation(cmd); 1141 ret = target_check_reservation(cmd);
1142 if (ret) 1142 if (ret) {
1143 cmd->scsi_status = SAM_STAT_RESERVATION_CONFLICT;
1143 return ret; 1144 return ret;
1145 }
1144 1146
1145 ret = dev->transport->parse_cdb(cmd); 1147 ret = dev->transport->parse_cdb(cmd);
1146 if (ret) 1148 if (ret)
diff --git a/drivers/thermal/dove_thermal.c b/drivers/thermal/dove_thermal.c
index 7b0bfa0e7a9c..3078c403b42d 100644
--- a/drivers/thermal/dove_thermal.c
+++ b/drivers/thermal/dove_thermal.c
@@ -143,22 +143,18 @@ static int dove_thermal_probe(struct platform_device *pdev)
143 if (!priv) 143 if (!priv)
144 return -ENOMEM; 144 return -ENOMEM;
145 145
146 priv->sensor = devm_request_and_ioremap(&pdev->dev, res); 146 priv->sensor = devm_ioremap_resource(&pdev->dev, res);
147 if (!priv->sensor) { 147 if (IS_ERR(priv->sensor))
148 dev_err(&pdev->dev, "Failed to request_ioremap memory\n"); 148 return PTR_ERR(priv->sensor);
149 return -EADDRNOTAVAIL;
150 }
151 149
152 res = platform_get_resource(pdev, IORESOURCE_MEM, 1); 150 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
153 if (!res) { 151 if (!res) {
154 dev_err(&pdev->dev, "Failed to get platform resource\n"); 152 dev_err(&pdev->dev, "Failed to get platform resource\n");
155 return -ENODEV; 153 return -ENODEV;
156 } 154 }
157 priv->control = devm_request_and_ioremap(&pdev->dev, res); 155 priv->control = devm_ioremap_resource(&pdev->dev, res);
158 if (!priv->control) { 156 if (IS_ERR(priv->control))
159 dev_err(&pdev->dev, "Failed to request_ioremap memory\n"); 157 return PTR_ERR(priv->control);
160 return -EADDRNOTAVAIL;
161 }
162 158
163 ret = dove_init_sensor(priv); 159 ret = dove_init_sensor(priv);
164 if (ret) { 160 if (ret) {
diff --git a/drivers/thermal/exynos_thermal.c b/drivers/thermal/exynos_thermal.c
index e04ebd8671ac..46568c078dee 100644
--- a/drivers/thermal/exynos_thermal.c
+++ b/drivers/thermal/exynos_thermal.c
@@ -476,7 +476,7 @@ static int exynos_register_thermal(struct thermal_sensor_conf *sensor_conf)
476 476
477 if (IS_ERR(th_zone->therm_dev)) { 477 if (IS_ERR(th_zone->therm_dev)) {
478 pr_err("Failed to register thermal zone device\n"); 478 pr_err("Failed to register thermal zone device\n");
479 ret = -EINVAL; 479 ret = PTR_ERR(th_zone->therm_dev);
480 goto err_unregister; 480 goto err_unregister;
481 } 481 }
482 th_zone->mode = THERMAL_DEVICE_ENABLED; 482 th_zone->mode = THERMAL_DEVICE_ENABLED;
diff --git a/drivers/thermal/kirkwood_thermal.c b/drivers/thermal/kirkwood_thermal.c
index 65cb4f09e8f6..e5500edb5285 100644
--- a/drivers/thermal/kirkwood_thermal.c
+++ b/drivers/thermal/kirkwood_thermal.c
@@ -85,11 +85,9 @@ static int kirkwood_thermal_probe(struct platform_device *pdev)
85 if (!priv) 85 if (!priv)
86 return -ENOMEM; 86 return -ENOMEM;
87 87
88 priv->sensor = devm_request_and_ioremap(&pdev->dev, res); 88 priv->sensor = devm_ioremap_resource(&pdev->dev, res);
89 if (!priv->sensor) { 89 if (IS_ERR(priv->sensor))
90 dev_err(&pdev->dev, "Failed to request_ioremap memory\n"); 90 return PTR_ERR(priv->sensor);
91 return -EADDRNOTAVAIL;
92 }
93 91
94 thermal = thermal_zone_device_register("kirkwood_thermal", 0, 0, 92 thermal = thermal_zone_device_register("kirkwood_thermal", 0, 0,
95 priv, &ops, NULL, 0, 0); 93 priv, &ops, NULL, 0, 0);
diff --git a/drivers/thermal/rcar_thermal.c b/drivers/thermal/rcar_thermal.c
index 28f091994013..2cc5b6115e3e 100644
--- a/drivers/thermal/rcar_thermal.c
+++ b/drivers/thermal/rcar_thermal.c
@@ -145,6 +145,7 @@ static int rcar_thermal_update_temp(struct rcar_thermal_priv *priv)
145 struct device *dev = rcar_priv_to_dev(priv); 145 struct device *dev = rcar_priv_to_dev(priv);
146 int i; 146 int i;
147 int ctemp, old, new; 147 int ctemp, old, new;
148 int ret = -EINVAL;
148 149
149 mutex_lock(&priv->lock); 150 mutex_lock(&priv->lock);
150 151
@@ -174,7 +175,7 @@ static int rcar_thermal_update_temp(struct rcar_thermal_priv *priv)
174 175
175 if (!ctemp) { 176 if (!ctemp) {
176 dev_err(dev, "thermal sensor was broken\n"); 177 dev_err(dev, "thermal sensor was broken\n");
177 return -EINVAL; 178 goto err_out_unlock;
178 } 179 }
179 180
180 /* 181 /*
@@ -192,10 +193,10 @@ static int rcar_thermal_update_temp(struct rcar_thermal_priv *priv)
192 dev_dbg(dev, "thermal%d %d -> %d\n", priv->id, priv->ctemp, ctemp); 193 dev_dbg(dev, "thermal%d %d -> %d\n", priv->id, priv->ctemp, ctemp);
193 194
194 priv->ctemp = ctemp; 195 priv->ctemp = ctemp;
195 196 ret = 0;
197err_out_unlock:
196 mutex_unlock(&priv->lock); 198 mutex_unlock(&priv->lock);
197 199 return ret;
198 return 0;
199} 200}
200 201
201static int rcar_thermal_get_temp(struct thermal_zone_device *zone, 202static int rcar_thermal_get_temp(struct thermal_zone_device *zone,
@@ -363,6 +364,7 @@ static int rcar_thermal_probe(struct platform_device *pdev)
363 struct resource *res, *irq; 364 struct resource *res, *irq;
364 int mres = 0; 365 int mres = 0;
365 int i; 366 int i;
367 int ret = -ENODEV;
366 int idle = IDLE_INTERVAL; 368 int idle = IDLE_INTERVAL;
367 369
368 common = devm_kzalloc(dev, sizeof(*common), GFP_KERNEL); 370 common = devm_kzalloc(dev, sizeof(*common), GFP_KERNEL);
@@ -399,11 +401,9 @@ static int rcar_thermal_probe(struct platform_device *pdev)
399 /* 401 /*
400 * rcar_has_irq_support() will be enabled 402 * rcar_has_irq_support() will be enabled
401 */ 403 */
402 common->base = devm_request_and_ioremap(dev, res); 404 common->base = devm_ioremap_resource(dev, res);
403 if (!common->base) { 405 if (IS_ERR(common->base))
404 dev_err(dev, "Unable to ioremap thermal register\n"); 406 return PTR_ERR(common->base);
405 return -ENOMEM;
406 }
407 407
408 /* enable temperature comparation */ 408 /* enable temperature comparation */
409 rcar_thermal_common_write(common, ENR, 0x00030303); 409 rcar_thermal_common_write(common, ENR, 0x00030303);
@@ -422,11 +422,9 @@ static int rcar_thermal_probe(struct platform_device *pdev)
422 return -ENOMEM; 422 return -ENOMEM;
423 } 423 }
424 424
425 priv->base = devm_request_and_ioremap(dev, res); 425 priv->base = devm_ioremap_resource(dev, res);
426 if (!priv->base) { 426 if (IS_ERR(priv->base))
427 dev_err(dev, "Unable to ioremap priv register\n"); 427 return PTR_ERR(priv->base);
428 return -ENOMEM;
429 }
430 428
431 priv->common = common; 429 priv->common = common;
432 priv->id = i; 430 priv->id = i;
@@ -441,6 +439,7 @@ static int rcar_thermal_probe(struct platform_device *pdev)
441 idle); 439 idle);
442 if (IS_ERR(priv->zone)) { 440 if (IS_ERR(priv->zone)) {
443 dev_err(dev, "can't register thermal zone\n"); 441 dev_err(dev, "can't register thermal zone\n");
442 ret = PTR_ERR(priv->zone);
444 goto error_unregister; 443 goto error_unregister;
445 } 444 }
446 445
@@ -460,7 +459,7 @@ error_unregister:
460 rcar_thermal_for_each_priv(priv, common) 459 rcar_thermal_for_each_priv(priv, common)
461 thermal_zone_device_unregister(priv->zone); 460 thermal_zone_device_unregister(priv->zone);
462 461
463 return -ENODEV; 462 return ret;
464} 463}
465 464
466static int rcar_thermal_remove(struct platform_device *pdev) 465static int rcar_thermal_remove(struct platform_device *pdev)
diff --git a/drivers/tty/serial/8250/8250.c b/drivers/tty/serial/8250/8250_core.c
index e5ddfd6fc468..46528d57be72 100644
--- a/drivers/tty/serial/8250/8250.c
+++ b/drivers/tty/serial/8250/8250_core.c
@@ -3422,6 +3422,7 @@ MODULE_PARM_DESC(probe_rsa, "Probe I/O ports for RSA");
3422#endif 3422#endif
3423MODULE_ALIAS_CHARDEV_MAJOR(TTY_MAJOR); 3423MODULE_ALIAS_CHARDEV_MAJOR(TTY_MAJOR);
3424 3424
3425#ifdef CONFIG_SERIAL_8250_DEPRECATED_OPTIONS
3425#ifndef MODULE 3426#ifndef MODULE
3426/* This module was renamed to 8250_core in 3.7. Keep the old "8250" name 3427/* This module was renamed to 8250_core in 3.7. Keep the old "8250" name
3427 * working as well for the module options so we don't break people. We 3428 * working as well for the module options so we don't break people. We
@@ -3436,7 +3437,7 @@ MODULE_ALIAS_CHARDEV_MAJOR(TTY_MAJOR);
3436static void __used s8250_options(void) 3437static void __used s8250_options(void)
3437{ 3438{
3438#undef MODULE_PARAM_PREFIX 3439#undef MODULE_PARAM_PREFIX
3439#define MODULE_PARAM_PREFIX "8250." 3440#define MODULE_PARAM_PREFIX "8250_core."
3440 3441
3441 module_param_cb(share_irqs, &param_ops_uint, &share_irqs, 0644); 3442 module_param_cb(share_irqs, &param_ops_uint, &share_irqs, 0644);
3442 module_param_cb(nr_uarts, &param_ops_uint, &nr_uarts, 0644); 3443 module_param_cb(nr_uarts, &param_ops_uint, &nr_uarts, 0644);
@@ -3448,5 +3449,6 @@ static void __used s8250_options(void)
3448#endif 3449#endif
3449} 3450}
3450#else 3451#else
3451MODULE_ALIAS("8250"); 3452MODULE_ALIAS("8250_core");
3453#endif
3452#endif 3454#endif
diff --git a/drivers/tty/serial/8250/8250_pci.c b/drivers/tty/serial/8250/8250_pci.c
index aa76825229dc..26e3a97ab157 100644
--- a/drivers/tty/serial/8250/8250_pci.c
+++ b/drivers/tty/serial/8250/8250_pci.c
@@ -1554,6 +1554,7 @@ pci_wch_ch353_setup(struct serial_private *priv,
1554#define PCI_DEVICE_ID_PLX_CRONYX_OMEGA 0xc001 1554#define PCI_DEVICE_ID_PLX_CRONYX_OMEGA 0xc001
1555#define PCI_DEVICE_ID_INTEL_PATSBURG_KT 0x1d3d 1555#define PCI_DEVICE_ID_INTEL_PATSBURG_KT 0x1d3d
1556#define PCI_VENDOR_ID_WCH 0x4348 1556#define PCI_VENDOR_ID_WCH 0x4348
1557#define PCI_DEVICE_ID_WCH_CH352_2S 0x3253
1557#define PCI_DEVICE_ID_WCH_CH353_4S 0x3453 1558#define PCI_DEVICE_ID_WCH_CH353_4S 0x3453
1558#define PCI_DEVICE_ID_WCH_CH353_2S1PF 0x5046 1559#define PCI_DEVICE_ID_WCH_CH353_2S1PF 0x5046
1559#define PCI_DEVICE_ID_WCH_CH353_2S1P 0x7053 1560#define PCI_DEVICE_ID_WCH_CH353_2S1P 0x7053
@@ -2172,6 +2173,14 @@ static struct pci_serial_quirk pci_serial_quirks[] __refdata = {
2172 .subdevice = PCI_ANY_ID, 2173 .subdevice = PCI_ANY_ID,
2173 .setup = pci_wch_ch353_setup, 2174 .setup = pci_wch_ch353_setup,
2174 }, 2175 },
2176 /* WCH CH352 2S card (16550 clone) */
2177 {
2178 .vendor = PCI_VENDOR_ID_WCH,
2179 .device = PCI_DEVICE_ID_WCH_CH352_2S,
2180 .subvendor = PCI_ANY_ID,
2181 .subdevice = PCI_ANY_ID,
2182 .setup = pci_wch_ch353_setup,
2183 },
2175 /* 2184 /*
2176 * ASIX devices with FIFO bug 2185 * ASIX devices with FIFO bug
2177 */ 2186 */
@@ -4870,6 +4879,10 @@ static struct pci_device_id serial_pci_tbl[] = {
4870 PCI_ANY_ID, PCI_ANY_ID, 4879 PCI_ANY_ID, PCI_ANY_ID,
4871 0, 0, pbn_b0_bt_2_115200 }, 4880 0, 0, pbn_b0_bt_2_115200 },
4872 4881
4882 { PCI_VENDOR_ID_WCH, PCI_DEVICE_ID_WCH_CH352_2S,
4883 PCI_ANY_ID, PCI_ANY_ID,
4884 0, 0, pbn_b0_bt_2_115200 },
4885
4873 /* 4886 /*
4874 * Commtech, Inc. Fastcom adapters 4887 * Commtech, Inc. Fastcom adapters
4875 */ 4888 */
diff --git a/drivers/tty/serial/8250/Kconfig b/drivers/tty/serial/8250/Kconfig
index 2ef9537bcb2c..80fe91e64a52 100644
--- a/drivers/tty/serial/8250/Kconfig
+++ b/drivers/tty/serial/8250/Kconfig
@@ -33,6 +33,23 @@ config SERIAL_8250
33 Most people will say Y or M here, so that they can use serial mice, 33 Most people will say Y or M here, so that they can use serial mice,
34 modems and similar devices connecting to the standard serial ports. 34 modems and similar devices connecting to the standard serial ports.
35 35
36config SERIAL_8250_DEPRECATED_OPTIONS
37 bool "Support 8250_core.* kernel options (DEPRECATED)"
38 depends on SERIAL_8250
39 default y
40 ---help---
41 In 3.7 we renamed 8250 to 8250_core by mistake, so now we have to
42 accept kernel parameters in both forms like 8250_core.nr_uarts=4 and
43 8250.nr_uarts=4. We now renamed the module back to 8250, but if
44 anybody noticed in 3.7 and changed their userspace we still have to
45 keep the 8350_core.* options around until they revert the changes
46 they already did.
47
48 If 8250 is built as a module, this adds 8250_core alias instead.
49
50 If you did not notice yet and/or you have userspace from pre-3.7, it
51 is safe (and recommended) to say N here.
52
36config SERIAL_8250_PNP 53config SERIAL_8250_PNP
37 bool "8250/16550 PNP device support" if EXPERT 54 bool "8250/16550 PNP device support" if EXPERT
38 depends on SERIAL_8250 && PNP 55 depends on SERIAL_8250 && PNP
diff --git a/drivers/tty/serial/8250/Makefile b/drivers/tty/serial/8250/Makefile
index a23838a4d535..36d68d054307 100644
--- a/drivers/tty/serial/8250/Makefile
+++ b/drivers/tty/serial/8250/Makefile
@@ -2,10 +2,10 @@
2# Makefile for the 8250 serial device drivers. 2# Makefile for the 8250 serial device drivers.
3# 3#
4 4
5obj-$(CONFIG_SERIAL_8250) += 8250_core.o 5obj-$(CONFIG_SERIAL_8250) += 8250.o
68250_core-y := 8250.o 68250-y := 8250_core.o
78250_core-$(CONFIG_SERIAL_8250_PNP) += 8250_pnp.o 78250-$(CONFIG_SERIAL_8250_PNP) += 8250_pnp.o
88250_core-$(CONFIG_SERIAL_8250_DMA) += 8250_dma.o 88250-$(CONFIG_SERIAL_8250_DMA) += 8250_dma.o
9obj-$(CONFIG_SERIAL_8250_GSC) += 8250_gsc.o 9obj-$(CONFIG_SERIAL_8250_GSC) += 8250_gsc.o
10obj-$(CONFIG_SERIAL_8250_PCI) += 8250_pci.o 10obj-$(CONFIG_SERIAL_8250_PCI) += 8250_pci.o
11obj-$(CONFIG_SERIAL_8250_HP300) += 8250_hp300.o 11obj-$(CONFIG_SERIAL_8250_HP300) += 8250_hp300.o
diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c
index d4a7c241b751..3467462869ce 100644
--- a/drivers/tty/serial/atmel_serial.c
+++ b/drivers/tty/serial/atmel_serial.c
@@ -158,7 +158,7 @@ struct atmel_uart_port {
158}; 158};
159 159
160static struct atmel_uart_port atmel_ports[ATMEL_MAX_UART]; 160static struct atmel_uart_port atmel_ports[ATMEL_MAX_UART];
161static unsigned long atmel_ports_in_use; 161static DECLARE_BITMAP(atmel_ports_in_use, ATMEL_MAX_UART);
162 162
163#ifdef SUPPORT_SYSRQ 163#ifdef SUPPORT_SYSRQ
164static struct console atmel_console; 164static struct console atmel_console;
@@ -1769,15 +1769,14 @@ static int atmel_serial_probe(struct platform_device *pdev)
1769 if (ret < 0) 1769 if (ret < 0)
1770 /* port id not found in platform data nor device-tree aliases: 1770 /* port id not found in platform data nor device-tree aliases:
1771 * auto-enumerate it */ 1771 * auto-enumerate it */
1772 ret = find_first_zero_bit(&atmel_ports_in_use, 1772 ret = find_first_zero_bit(atmel_ports_in_use, ATMEL_MAX_UART);
1773 sizeof(atmel_ports_in_use));
1774 1773
1775 if (ret > ATMEL_MAX_UART) { 1774 if (ret >= ATMEL_MAX_UART) {
1776 ret = -ENODEV; 1775 ret = -ENODEV;
1777 goto err; 1776 goto err;
1778 } 1777 }
1779 1778
1780 if (test_and_set_bit(ret, &atmel_ports_in_use)) { 1779 if (test_and_set_bit(ret, atmel_ports_in_use)) {
1781 /* port already in use */ 1780 /* port already in use */
1782 ret = -EBUSY; 1781 ret = -EBUSY;
1783 goto err; 1782 goto err;
@@ -1857,7 +1856,7 @@ static int atmel_serial_remove(struct platform_device *pdev)
1857 1856
1858 /* "port" is allocated statically, so we shouldn't free it */ 1857 /* "port" is allocated statically, so we shouldn't free it */
1859 1858
1860 clear_bit(port->line, &atmel_ports_in_use); 1859 clear_bit(port->line, atmel_ports_in_use);
1861 1860
1862 clk_put(atmel_port->clk); 1861 clk_put(atmel_port->clk);
1863 1862
diff --git a/drivers/tty/serial/sunsu.c b/drivers/tty/serial/sunsu.c
index e343d6670854..451687cb9685 100644
--- a/drivers/tty/serial/sunsu.c
+++ b/drivers/tty/serial/sunsu.c
@@ -968,6 +968,7 @@ static struct uart_ops sunsu_pops = {
968#define UART_NR 4 968#define UART_NR 4
969 969
970static struct uart_sunsu_port sunsu_ports[UART_NR]; 970static struct uart_sunsu_port sunsu_ports[UART_NR];
971static int nr_inst; /* Number of already registered ports */
971 972
972#ifdef CONFIG_SERIO 973#ifdef CONFIG_SERIO
973 974
@@ -1337,13 +1338,8 @@ static int __init sunsu_console_setup(struct console *co, char *options)
1337 printk("Console: ttyS%d (SU)\n", 1338 printk("Console: ttyS%d (SU)\n",
1338 (sunsu_reg.minor - 64) + co->index); 1339 (sunsu_reg.minor - 64) + co->index);
1339 1340
1340 /* 1341 if (co->index > nr_inst)
1341 * Check whether an invalid uart number has been specified, and 1342 return -ENODEV;
1342 * if so, search for the first available port that does have
1343 * console support.
1344 */
1345 if (co->index >= UART_NR)
1346 co->index = 0;
1347 port = &sunsu_ports[co->index].port; 1343 port = &sunsu_ports[co->index].port;
1348 1344
1349 /* 1345 /*
@@ -1408,7 +1404,6 @@ static enum su_type su_get_type(struct device_node *dp)
1408 1404
1409static int su_probe(struct platform_device *op) 1405static int su_probe(struct platform_device *op)
1410{ 1406{
1411 static int inst;
1412 struct device_node *dp = op->dev.of_node; 1407 struct device_node *dp = op->dev.of_node;
1413 struct uart_sunsu_port *up; 1408 struct uart_sunsu_port *up;
1414 struct resource *rp; 1409 struct resource *rp;
@@ -1418,16 +1413,16 @@ static int su_probe(struct platform_device *op)
1418 1413
1419 type = su_get_type(dp); 1414 type = su_get_type(dp);
1420 if (type == SU_PORT_PORT) { 1415 if (type == SU_PORT_PORT) {
1421 if (inst >= UART_NR) 1416 if (nr_inst >= UART_NR)
1422 return -EINVAL; 1417 return -EINVAL;
1423 up = &sunsu_ports[inst]; 1418 up = &sunsu_ports[nr_inst];
1424 } else { 1419 } else {
1425 up = kzalloc(sizeof(*up), GFP_KERNEL); 1420 up = kzalloc(sizeof(*up), GFP_KERNEL);
1426 if (!up) 1421 if (!up)
1427 return -ENOMEM; 1422 return -ENOMEM;
1428 } 1423 }
1429 1424
1430 up->port.line = inst; 1425 up->port.line = nr_inst;
1431 1426
1432 spin_lock_init(&up->port.lock); 1427 spin_lock_init(&up->port.lock);
1433 1428
@@ -1461,6 +1456,8 @@ static int su_probe(struct platform_device *op)
1461 } 1456 }
1462 dev_set_drvdata(&op->dev, up); 1457 dev_set_drvdata(&op->dev, up);
1463 1458
1459 nr_inst++;
1460
1464 return 0; 1461 return 0;
1465 } 1462 }
1466 1463
@@ -1488,7 +1485,7 @@ static int su_probe(struct platform_device *op)
1488 1485
1489 dev_set_drvdata(&op->dev, up); 1486 dev_set_drvdata(&op->dev, up);
1490 1487
1491 inst++; 1488 nr_inst++;
1492 1489
1493 return 0; 1490 return 0;
1494 1491
diff --git a/drivers/tty/serial/xilinx_uartps.c b/drivers/tty/serial/xilinx_uartps.c
index 974c361a91fe..4e5c77834c50 100644
--- a/drivers/tty/serial/xilinx_uartps.c
+++ b/drivers/tty/serial/xilinx_uartps.c
@@ -578,6 +578,8 @@ static int xuartps_startup(struct uart_port *port)
578 /* Receive Timeout register is enabled with value of 10 */ 578 /* Receive Timeout register is enabled with value of 10 */
579 xuartps_writel(10, XUARTPS_RXTOUT_OFFSET); 579 xuartps_writel(10, XUARTPS_RXTOUT_OFFSET);
580 580
581 /* Clear out any pending interrupts before enabling them */
582 xuartps_writel(xuartps_readl(XUARTPS_ISR_OFFSET), XUARTPS_ISR_OFFSET);
581 583
582 /* Set the Interrupt Registers with desired interrupts */ 584 /* Set the Interrupt Registers with desired interrupts */
583 xuartps_writel(XUARTPS_IXR_TXEMPTY | XUARTPS_IXR_PARITY | 585 xuartps_writel(XUARTPS_IXR_TXEMPTY | XUARTPS_IXR_PARITY |
diff --git a/drivers/tty/vt/vc_screen.c b/drivers/tty/vt/vc_screen.c
index e4ca345873c3..d7799deacb21 100644
--- a/drivers/tty/vt/vc_screen.c
+++ b/drivers/tty/vt/vc_screen.c
@@ -93,7 +93,7 @@ vcs_poll_data_free(struct vcs_poll_data *poll)
93static struct vcs_poll_data * 93static struct vcs_poll_data *
94vcs_poll_data_get(struct file *file) 94vcs_poll_data_get(struct file *file)
95{ 95{
96 struct vcs_poll_data *poll = file->private_data; 96 struct vcs_poll_data *poll = file->private_data, *kill = NULL;
97 97
98 if (poll) 98 if (poll)
99 return poll; 99 return poll;
@@ -122,10 +122,12 @@ vcs_poll_data_get(struct file *file)
122 file->private_data = poll; 122 file->private_data = poll;
123 } else { 123 } else {
124 /* someone else raced ahead of us */ 124 /* someone else raced ahead of us */
125 vcs_poll_data_free(poll); 125 kill = poll;
126 poll = file->private_data; 126 poll = file->private_data;
127 } 127 }
128 spin_unlock(&file->f_lock); 128 spin_unlock(&file->f_lock);
129 if (kill)
130 vcs_poll_data_free(kill);
129 131
130 return poll; 132 return poll;
131} 133}
diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
index 27a18743275e..c77f7ae48f1c 100644
--- a/drivers/usb/class/cdc-acm.c
+++ b/drivers/usb/class/cdc-acm.c
@@ -582,7 +582,6 @@ static void acm_port_destruct(struct tty_port *port)
582 582
583 dev_dbg(&acm->control->dev, "%s\n", __func__); 583 dev_dbg(&acm->control->dev, "%s\n", __func__);
584 584
585 tty_unregister_device(acm_tty_driver, acm->minor);
586 acm_release_minor(acm); 585 acm_release_minor(acm);
587 usb_put_intf(acm->control); 586 usb_put_intf(acm->control);
588 kfree(acm->country_codes); 587 kfree(acm->country_codes);
@@ -966,6 +965,8 @@ static int acm_probe(struct usb_interface *intf,
966 int num_rx_buf; 965 int num_rx_buf;
967 int i; 966 int i;
968 int combined_interfaces = 0; 967 int combined_interfaces = 0;
968 struct device *tty_dev;
969 int rv = -ENOMEM;
969 970
970 /* normal quirks */ 971 /* normal quirks */
971 quirks = (unsigned long)id->driver_info; 972 quirks = (unsigned long)id->driver_info;
@@ -1328,11 +1329,24 @@ skip_countries:
1328 usb_set_intfdata(data_interface, acm); 1329 usb_set_intfdata(data_interface, acm);
1329 1330
1330 usb_get_intf(control_interface); 1331 usb_get_intf(control_interface);
1331 tty_port_register_device(&acm->port, acm_tty_driver, minor, 1332 tty_dev = tty_port_register_device(&acm->port, acm_tty_driver, minor,
1332 &control_interface->dev); 1333 &control_interface->dev);
1334 if (IS_ERR(tty_dev)) {
1335 rv = PTR_ERR(tty_dev);
1336 goto alloc_fail8;
1337 }
1333 1338
1334 return 0; 1339 return 0;
1340alloc_fail8:
1341 if (acm->country_codes) {
1342 device_remove_file(&acm->control->dev,
1343 &dev_attr_wCountryCodes);
1344 device_remove_file(&acm->control->dev,
1345 &dev_attr_iCountryCodeRelDate);
1346 }
1347 device_remove_file(&acm->control->dev, &dev_attr_bmCapabilities);
1335alloc_fail7: 1348alloc_fail7:
1349 usb_set_intfdata(intf, NULL);
1336 for (i = 0; i < ACM_NW; i++) 1350 for (i = 0; i < ACM_NW; i++)
1337 usb_free_urb(acm->wb[i].urb); 1351 usb_free_urb(acm->wb[i].urb);
1338alloc_fail6: 1352alloc_fail6:
@@ -1348,7 +1362,7 @@ alloc_fail2:
1348 acm_release_minor(acm); 1362 acm_release_minor(acm);
1349 kfree(acm); 1363 kfree(acm);
1350alloc_fail: 1364alloc_fail:
1351 return -ENOMEM; 1365 return rv;
1352} 1366}
1353 1367
1354static void stop_data_traffic(struct acm *acm) 1368static void stop_data_traffic(struct acm *acm)
@@ -1400,6 +1414,8 @@ static void acm_disconnect(struct usb_interface *intf)
1400 1414
1401 stop_data_traffic(acm); 1415 stop_data_traffic(acm);
1402 1416
1417 tty_unregister_device(acm_tty_driver, acm->minor);
1418
1403 usb_free_urb(acm->ctrlurb); 1419 usb_free_urb(acm->ctrlurb);
1404 for (i = 0; i < ACM_NW; i++) 1420 for (i = 0; i < ACM_NW; i++)
1405 usb_free_urb(acm->wb[i].urb); 1421 usb_free_urb(acm->wb[i].urb);
diff --git a/drivers/usb/core/hcd-pci.c b/drivers/usb/core/hcd-pci.c
index 622b4a48e732..2b487d4797bd 100644
--- a/drivers/usb/core/hcd-pci.c
+++ b/drivers/usb/core/hcd-pci.c
@@ -173,6 +173,7 @@ int usb_hcd_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
173 struct hc_driver *driver; 173 struct hc_driver *driver;
174 struct usb_hcd *hcd; 174 struct usb_hcd *hcd;
175 int retval; 175 int retval;
176 int hcd_irq = 0;
176 177
177 if (usb_disabled()) 178 if (usb_disabled())
178 return -ENODEV; 179 return -ENODEV;
@@ -187,15 +188,19 @@ int usb_hcd_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
187 return -ENODEV; 188 return -ENODEV;
188 dev->current_state = PCI_D0; 189 dev->current_state = PCI_D0;
189 190
190 /* The xHCI driver supports MSI and MSI-X, 191 /*
191 * so don't fail if the BIOS doesn't provide a legacy IRQ. 192 * The xHCI driver has its own irq management
193 * make sure irq setup is not touched for xhci in generic hcd code
192 */ 194 */
193 if (!dev->irq && (driver->flags & HCD_MASK) != HCD_USB3) { 195 if ((driver->flags & HCD_MASK) != HCD_USB3) {
194 dev_err(&dev->dev, 196 if (!dev->irq) {
195 "Found HC with no IRQ. Check BIOS/PCI %s setup!\n", 197 dev_err(&dev->dev,
196 pci_name(dev)); 198 "Found HC with no IRQ. Check BIOS/PCI %s setup!\n",
197 retval = -ENODEV; 199 pci_name(dev));
198 goto disable_pci; 200 retval = -ENODEV;
201 goto disable_pci;
202 }
203 hcd_irq = dev->irq;
199 } 204 }
200 205
201 hcd = usb_create_hcd(driver, &dev->dev, pci_name(dev)); 206 hcd = usb_create_hcd(driver, &dev->dev, pci_name(dev));
@@ -245,7 +250,7 @@ int usb_hcd_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
245 250
246 pci_set_master(dev); 251 pci_set_master(dev);
247 252
248 retval = usb_add_hcd(hcd, dev->irq, IRQF_SHARED); 253 retval = usb_add_hcd(hcd, hcd_irq, IRQF_SHARED);
249 if (retval != 0) 254 if (retval != 0)
250 goto unmap_registers; 255 goto unmap_registers;
251 set_hs_companion(dev, hcd); 256 set_hs_companion(dev, hcd);
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index 99b34a30354f..f9ec44cbb82f 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -2412,6 +2412,14 @@ int usb_hcd_is_primary_hcd(struct usb_hcd *hcd)
2412} 2412}
2413EXPORT_SYMBOL_GPL(usb_hcd_is_primary_hcd); 2413EXPORT_SYMBOL_GPL(usb_hcd_is_primary_hcd);
2414 2414
2415int usb_hcd_find_raw_port_number(struct usb_hcd *hcd, int port1)
2416{
2417 if (!hcd->driver->find_raw_port_number)
2418 return port1;
2419
2420 return hcd->driver->find_raw_port_number(hcd, port1);
2421}
2422
2415static int usb_hcd_request_irqs(struct usb_hcd *hcd, 2423static int usb_hcd_request_irqs(struct usb_hcd *hcd,
2416 unsigned int irqnum, unsigned long irqflags) 2424 unsigned int irqnum, unsigned long irqflags)
2417{ 2425{
diff --git a/drivers/usb/core/usb-acpi.c b/drivers/usb/core/usb-acpi.c
index b6f4bad3f756..255c14464bf2 100644
--- a/drivers/usb/core/usb-acpi.c
+++ b/drivers/usb/core/usb-acpi.c
@@ -15,6 +15,7 @@
15#include <linux/kernel.h> 15#include <linux/kernel.h>
16#include <linux/acpi.h> 16#include <linux/acpi.h>
17#include <linux/pci.h> 17#include <linux/pci.h>
18#include <linux/usb/hcd.h>
18#include <acpi/acpi_bus.h> 19#include <acpi/acpi_bus.h>
19 20
20#include "usb.h" 21#include "usb.h"
@@ -188,8 +189,13 @@ static int usb_acpi_find_device(struct device *dev, acpi_handle *handle)
188 * connected to. 189 * connected to.
189 */ 190 */
190 if (!udev->parent) { 191 if (!udev->parent) {
191 *handle = acpi_get_child(DEVICE_ACPI_HANDLE(&udev->dev), 192 struct usb_hcd *hcd = bus_to_hcd(udev->bus);
193 int raw_port_num;
194
195 raw_port_num = usb_hcd_find_raw_port_number(hcd,
192 port_num); 196 port_num);
197 *handle = acpi_get_child(DEVICE_ACPI_HANDLE(&udev->dev),
198 raw_port_num);
193 if (!*handle) 199 if (!*handle)
194 return -ENODEV; 200 return -ENODEV;
195 } else { 201 } else {
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index 5a0c541daf89..c7525b1cad74 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -145,6 +145,7 @@ config USB_LPC32XX
145 tristate "LPC32XX USB Peripheral Controller" 145 tristate "LPC32XX USB Peripheral Controller"
146 depends on ARCH_LPC32XX 146 depends on ARCH_LPC32XX
147 select USB_ISP1301 147 select USB_ISP1301
148 select USB_OTG_UTILS
148 help 149 help
149 This option selects the USB device controller in the LPC32xx SoC. 150 This option selects the USB device controller in the LPC32xx SoC.
150 151
diff --git a/drivers/usb/gadget/f_rndis.c b/drivers/usb/gadget/f_rndis.c
index 71beeb833558..cc9c49c57c80 100644
--- a/drivers/usb/gadget/f_rndis.c
+++ b/drivers/usb/gadget/f_rndis.c
@@ -447,14 +447,13 @@ static void rndis_response_complete(struct usb_ep *ep, struct usb_request *req)
447static void rndis_command_complete(struct usb_ep *ep, struct usb_request *req) 447static void rndis_command_complete(struct usb_ep *ep, struct usb_request *req)
448{ 448{
449 struct f_rndis *rndis = req->context; 449 struct f_rndis *rndis = req->context;
450 struct usb_composite_dev *cdev = rndis->port.func.config->cdev;
451 int status; 450 int status;
452 451
453 /* received RNDIS command from USB_CDC_SEND_ENCAPSULATED_COMMAND */ 452 /* received RNDIS command from USB_CDC_SEND_ENCAPSULATED_COMMAND */
454// spin_lock(&dev->lock); 453// spin_lock(&dev->lock);
455 status = rndis_msg_parser(rndis->config, (u8 *) req->buf); 454 status = rndis_msg_parser(rndis->config, (u8 *) req->buf);
456 if (status < 0) 455 if (status < 0)
457 ERROR(cdev, "RNDIS command error %d, %d/%d\n", 456 pr_err("RNDIS command error %d, %d/%d\n",
458 status, req->actual, req->length); 457 status, req->actual, req->length);
459// spin_unlock(&dev->lock); 458// spin_unlock(&dev->lock);
460} 459}
diff --git a/drivers/usb/gadget/g_ffs.c b/drivers/usb/gadget/g_ffs.c
index 3953dd4d7186..3b343b23e4b0 100644
--- a/drivers/usb/gadget/g_ffs.c
+++ b/drivers/usb/gadget/g_ffs.c
@@ -357,7 +357,7 @@ static int gfs_bind(struct usb_composite_dev *cdev)
357 goto error; 357 goto error;
358 gfs_dev_desc.iProduct = gfs_strings[USB_GADGET_PRODUCT_IDX].id; 358 gfs_dev_desc.iProduct = gfs_strings[USB_GADGET_PRODUCT_IDX].id;
359 359
360 for (i = func_num; --i; ) { 360 for (i = func_num; i--; ) {
361 ret = functionfs_bind(ffs_tab[i].ffs_data, cdev); 361 ret = functionfs_bind(ffs_tab[i].ffs_data, cdev);
362 if (unlikely(ret < 0)) { 362 if (unlikely(ret < 0)) {
363 while (++i < func_num) 363 while (++i < func_num)
@@ -413,7 +413,7 @@ static int gfs_unbind(struct usb_composite_dev *cdev)
413 gether_cleanup(); 413 gether_cleanup();
414 gfs_ether_setup = false; 414 gfs_ether_setup = false;
415 415
416 for (i = func_num; --i; ) 416 for (i = func_num; i--; )
417 if (ffs_tab[i].ffs_data) 417 if (ffs_tab[i].ffs_data)
418 functionfs_unbind(ffs_tab[i].ffs_data); 418 functionfs_unbind(ffs_tab[i].ffs_data);
419 419
diff --git a/drivers/usb/gadget/net2272.c b/drivers/usb/gadget/net2272.c
index d226058e3b88..32524b631959 100644
--- a/drivers/usb/gadget/net2272.c
+++ b/drivers/usb/gadget/net2272.c
@@ -59,7 +59,7 @@ static const char * const ep_name[] = {
59}; 59};
60 60
61#define DMA_ADDR_INVALID (~(dma_addr_t)0) 61#define DMA_ADDR_INVALID (~(dma_addr_t)0)
62#ifdef CONFIG_USB_GADGET_NET2272_DMA 62#ifdef CONFIG_USB_NET2272_DMA
63/* 63/*
64 * use_dma: the NET2272 can use an external DMA controller. 64 * use_dma: the NET2272 can use an external DMA controller.
65 * Note that since there is no generic DMA api, some functions, 65 * Note that since there is no generic DMA api, some functions,
@@ -1495,6 +1495,13 @@ stop_activity(struct net2272 *dev, struct usb_gadget_driver *driver)
1495 for (i = 0; i < 4; ++i) 1495 for (i = 0; i < 4; ++i)
1496 net2272_dequeue_all(&dev->ep[i]); 1496 net2272_dequeue_all(&dev->ep[i]);
1497 1497
1498 /* report disconnect; the driver is already quiesced */
1499 if (driver) {
1500 spin_unlock(&dev->lock);
1501 driver->disconnect(&dev->gadget);
1502 spin_lock(&dev->lock);
1503 }
1504
1498 net2272_usb_reinit(dev); 1505 net2272_usb_reinit(dev);
1499} 1506}
1500 1507
diff --git a/drivers/usb/gadget/net2280.c b/drivers/usb/gadget/net2280.c
index a1b650e11339..3bd0f992fb49 100644
--- a/drivers/usb/gadget/net2280.c
+++ b/drivers/usb/gadget/net2280.c
@@ -1924,7 +1924,6 @@ static int net2280_start(struct usb_gadget *_gadget,
1924err_func: 1924err_func:
1925 device_remove_file (&dev->pdev->dev, &dev_attr_function); 1925 device_remove_file (&dev->pdev->dev, &dev_attr_function);
1926err_unbind: 1926err_unbind:
1927 driver->unbind (&dev->gadget);
1928 dev->gadget.dev.driver = NULL; 1927 dev->gadget.dev.driver = NULL;
1929 dev->driver = NULL; 1928 dev->driver = NULL;
1930 return retval; 1929 return retval;
@@ -1946,6 +1945,13 @@ stop_activity (struct net2280 *dev, struct usb_gadget_driver *driver)
1946 for (i = 0; i < 7; i++) 1945 for (i = 0; i < 7; i++)
1947 nuke (&dev->ep [i]); 1946 nuke (&dev->ep [i]);
1948 1947
1948 /* report disconnect; the driver is already quiesced */
1949 if (driver) {
1950 spin_unlock(&dev->lock);
1951 driver->disconnect(&dev->gadget);
1952 spin_lock(&dev->lock);
1953 }
1954
1949 usb_reinit (dev); 1955 usb_reinit (dev);
1950} 1956}
1951 1957
diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
index c5034d9c946b..b369292d4b90 100644
--- a/drivers/usb/gadget/u_serial.c
+++ b/drivers/usb/gadget/u_serial.c
@@ -136,7 +136,7 @@ static struct portmaster {
136 pr_debug(fmt, ##arg) 136 pr_debug(fmt, ##arg)
137#endif /* pr_vdebug */ 137#endif /* pr_vdebug */
138#else 138#else
139#ifndef pr_vdebig 139#ifndef pr_vdebug
140#define pr_vdebug(fmt, arg...) \ 140#define pr_vdebug(fmt, arg...) \
141 ({ if (0) pr_debug(fmt, ##arg); }) 141 ({ if (0) pr_debug(fmt, ##arg); })
142#endif /* pr_vdebug */ 142#endif /* pr_vdebug */
diff --git a/drivers/usb/gadget/udc-core.c b/drivers/usb/gadget/udc-core.c
index 2a9cd369f71c..f8f62c3ed65e 100644
--- a/drivers/usb/gadget/udc-core.c
+++ b/drivers/usb/gadget/udc-core.c
@@ -216,7 +216,7 @@ static void usb_gadget_remove_driver(struct usb_udc *udc)
216 usb_gadget_disconnect(udc->gadget); 216 usb_gadget_disconnect(udc->gadget);
217 udc->driver->disconnect(udc->gadget); 217 udc->driver->disconnect(udc->gadget);
218 udc->driver->unbind(udc->gadget); 218 udc->driver->unbind(udc->gadget);
219 usb_gadget_udc_stop(udc->gadget, udc->driver); 219 usb_gadget_udc_stop(udc->gadget, NULL);
220 220
221 udc->driver = NULL; 221 udc->driver = NULL;
222 udc->dev.driver = NULL; 222 udc->dev.driver = NULL;
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index 5726cb144abf..416a6dce5e11 100644
--- a/drivers/usb/host/ehci-hcd.c
+++ b/drivers/usb/host/ehci-hcd.c
@@ -302,6 +302,7 @@ static void ehci_quiesce (struct ehci_hcd *ehci)
302 302
303static void end_unlink_async(struct ehci_hcd *ehci); 303static void end_unlink_async(struct ehci_hcd *ehci);
304static void unlink_empty_async(struct ehci_hcd *ehci); 304static void unlink_empty_async(struct ehci_hcd *ehci);
305static void unlink_empty_async_suspended(struct ehci_hcd *ehci);
305static void ehci_work(struct ehci_hcd *ehci); 306static void ehci_work(struct ehci_hcd *ehci);
306static void start_unlink_intr(struct ehci_hcd *ehci, struct ehci_qh *qh); 307static void start_unlink_intr(struct ehci_hcd *ehci, struct ehci_qh *qh);
307static void end_unlink_intr(struct ehci_hcd *ehci, struct ehci_qh *qh); 308static void end_unlink_intr(struct ehci_hcd *ehci, struct ehci_qh *qh);
diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
index 4d3b294f203e..7d06e77f6c4f 100644
--- a/drivers/usb/host/ehci-hub.c
+++ b/drivers/usb/host/ehci-hub.c
@@ -328,7 +328,7 @@ static int ehci_bus_suspend (struct usb_hcd *hcd)
328 ehci->rh_state = EHCI_RH_SUSPENDED; 328 ehci->rh_state = EHCI_RH_SUSPENDED;
329 329
330 end_unlink_async(ehci); 330 end_unlink_async(ehci);
331 unlink_empty_async(ehci); 331 unlink_empty_async_suspended(ehci);
332 ehci_handle_intr_unlinks(ehci); 332 ehci_handle_intr_unlinks(ehci);
333 end_free_itds(ehci); 333 end_free_itds(ehci);
334 334
diff --git a/drivers/usb/host/ehci-q.c b/drivers/usb/host/ehci-q.c
index 5464665f0b6a..23d136904285 100644
--- a/drivers/usb/host/ehci-q.c
+++ b/drivers/usb/host/ehci-q.c
@@ -1316,6 +1316,19 @@ static void unlink_empty_async(struct ehci_hcd *ehci)
1316 } 1316 }
1317} 1317}
1318 1318
1319/* The root hub is suspended; unlink all the async QHs */
1320static void unlink_empty_async_suspended(struct ehci_hcd *ehci)
1321{
1322 struct ehci_qh *qh;
1323
1324 while (ehci->async->qh_next.qh) {
1325 qh = ehci->async->qh_next.qh;
1326 WARN_ON(!list_empty(&qh->qtd_list));
1327 single_unlink_async(ehci, qh);
1328 }
1329 start_iaa_cycle(ehci, false);
1330}
1331
1319/* makes sure the async qh will become idle */ 1332/* makes sure the async qh will become idle */
1320/* caller must own ehci->lock */ 1333/* caller must own ehci->lock */
1321 1334
diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c
index b476daf49f6f..010f686d8881 100644
--- a/drivers/usb/host/ehci-sched.c
+++ b/drivers/usb/host/ehci-sched.c
@@ -1214,6 +1214,7 @@ itd_urb_transaction (
1214 1214
1215 memset (itd, 0, sizeof *itd); 1215 memset (itd, 0, sizeof *itd);
1216 itd->itd_dma = itd_dma; 1216 itd->itd_dma = itd_dma;
1217 itd->frame = 9999; /* an invalid value */
1217 list_add (&itd->itd_list, &sched->td_list); 1218 list_add (&itd->itd_list, &sched->td_list);
1218 } 1219 }
1219 spin_unlock_irqrestore (&ehci->lock, flags); 1220 spin_unlock_irqrestore (&ehci->lock, flags);
@@ -1915,6 +1916,7 @@ sitd_urb_transaction (
1915 1916
1916 memset (sitd, 0, sizeof *sitd); 1917 memset (sitd, 0, sizeof *sitd);
1917 sitd->sitd_dma = sitd_dma; 1918 sitd->sitd_dma = sitd_dma;
1919 sitd->frame = 9999; /* an invalid value */
1918 list_add (&sitd->sitd_list, &iso_sched->td_list); 1920 list_add (&sitd->sitd_list, &iso_sched->td_list);
1919 } 1921 }
1920 1922
diff --git a/drivers/usb/host/ehci-timer.c b/drivers/usb/host/ehci-timer.c
index 20dbdcbe9b0f..c3fa1305f830 100644
--- a/drivers/usb/host/ehci-timer.c
+++ b/drivers/usb/host/ehci-timer.c
@@ -304,7 +304,7 @@ static void ehci_iaa_watchdog(struct ehci_hcd *ehci)
304 * (a) SMP races against real IAA firing and retriggering, and 304 * (a) SMP races against real IAA firing and retriggering, and
305 * (b) clean HC shutdown, when IAA watchdog was pending. 305 * (b) clean HC shutdown, when IAA watchdog was pending.
306 */ 306 */
307 if (ehci->async_iaa) { 307 if (1) {
308 u32 cmd, status; 308 u32 cmd, status;
309 309
310 /* If we get here, IAA is *REALLY* late. It's barely 310 /* If we get here, IAA is *REALLY* late. It's barely
diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index 35616ffbe3ae..6dc238c592bc 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -1022,44 +1022,24 @@ void xhci_copy_ep0_dequeue_into_input_ctx(struct xhci_hcd *xhci,
1022 * is attached to (or the roothub port its ancestor hub is attached to). All we 1022 * is attached to (or the roothub port its ancestor hub is attached to). All we
1023 * know is the index of that port under either the USB 2.0 or the USB 3.0 1023 * know is the index of that port under either the USB 2.0 or the USB 3.0
1024 * roothub, but that doesn't give us the real index into the HW port status 1024 * roothub, but that doesn't give us the real index into the HW port status
1025 * registers. Scan through the xHCI roothub port array, looking for the Nth 1025 * registers. Call xhci_find_raw_port_number() to get real index.
1026 * entry of the correct port speed. Return the port number of that entry.
1027 */ 1026 */
1028static u32 xhci_find_real_port_number(struct xhci_hcd *xhci, 1027static u32 xhci_find_real_port_number(struct xhci_hcd *xhci,
1029 struct usb_device *udev) 1028 struct usb_device *udev)
1030{ 1029{
1031 struct usb_device *top_dev; 1030 struct usb_device *top_dev;
1032 unsigned int num_similar_speed_ports; 1031 struct usb_hcd *hcd;
1033 unsigned int faked_port_num; 1032
1034 int i; 1033 if (udev->speed == USB_SPEED_SUPER)
1034 hcd = xhci->shared_hcd;
1035 else
1036 hcd = xhci->main_hcd;
1035 1037
1036 for (top_dev = udev; top_dev->parent && top_dev->parent->parent; 1038 for (top_dev = udev; top_dev->parent && top_dev->parent->parent;
1037 top_dev = top_dev->parent) 1039 top_dev = top_dev->parent)
1038 /* Found device below root hub */; 1040 /* Found device below root hub */;
1039 faked_port_num = top_dev->portnum;
1040 for (i = 0, num_similar_speed_ports = 0;
1041 i < HCS_MAX_PORTS(xhci->hcs_params1); i++) {
1042 u8 port_speed = xhci->port_array[i];
1043
1044 /*
1045 * Skip ports that don't have known speeds, or have duplicate
1046 * Extended Capabilities port speed entries.
1047 */
1048 if (port_speed == 0 || port_speed == DUPLICATE_ENTRY)
1049 continue;
1050 1041
1051 /* 1042 return xhci_find_raw_port_number(hcd, top_dev->portnum);
1052 * USB 3.0 ports are always under a USB 3.0 hub. USB 2.0 and
1053 * 1.1 ports are under the USB 2.0 hub. If the port speed
1054 * matches the device speed, it's a similar speed port.
1055 */
1056 if ((port_speed == 0x03) == (udev->speed == USB_SPEED_SUPER))
1057 num_similar_speed_ports++;
1058 if (num_similar_speed_ports == faked_port_num)
1059 /* Roothub ports are numbered from 1 to N */
1060 return i+1;
1061 }
1062 return 0;
1063} 1043}
1064 1044
1065/* Setup an xHCI virtual device for a Set Address command */ 1045/* Setup an xHCI virtual device for a Set Address command */
diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c
index af259e0ec172..1a30c380043c 100644
--- a/drivers/usb/host/xhci-pci.c
+++ b/drivers/usb/host/xhci-pci.c
@@ -313,6 +313,7 @@ static const struct hc_driver xhci_pci_hc_driver = {
313 .set_usb2_hw_lpm = xhci_set_usb2_hardware_lpm, 313 .set_usb2_hw_lpm = xhci_set_usb2_hardware_lpm,
314 .enable_usb3_lpm_timeout = xhci_enable_usb3_lpm_timeout, 314 .enable_usb3_lpm_timeout = xhci_enable_usb3_lpm_timeout,
315 .disable_usb3_lpm_timeout = xhci_disable_usb3_lpm_timeout, 315 .disable_usb3_lpm_timeout = xhci_disable_usb3_lpm_timeout,
316 .find_raw_port_number = xhci_find_raw_port_number,
316}; 317};
317 318
318/*-------------------------------------------------------------------------*/ 319/*-------------------------------------------------------------------------*/
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index 882875465301..1969c001b3f9 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -1599,14 +1599,20 @@ static void handle_port_status(struct xhci_hcd *xhci,
1599 max_ports = HCS_MAX_PORTS(xhci->hcs_params1); 1599 max_ports = HCS_MAX_PORTS(xhci->hcs_params1);
1600 if ((port_id <= 0) || (port_id > max_ports)) { 1600 if ((port_id <= 0) || (port_id > max_ports)) {
1601 xhci_warn(xhci, "Invalid port id %d\n", port_id); 1601 xhci_warn(xhci, "Invalid port id %d\n", port_id);
1602 bogus_port_status = true; 1602 inc_deq(xhci, xhci->event_ring);
1603 goto cleanup; 1603 return;
1604 } 1604 }
1605 1605
1606 /* Figure out which usb_hcd this port is attached to: 1606 /* Figure out which usb_hcd this port is attached to:
1607 * is it a USB 3.0 port or a USB 2.0/1.1 port? 1607 * is it a USB 3.0 port or a USB 2.0/1.1 port?
1608 */ 1608 */
1609 major_revision = xhci->port_array[port_id - 1]; 1609 major_revision = xhci->port_array[port_id - 1];
1610
1611 /* Find the right roothub. */
1612 hcd = xhci_to_hcd(xhci);
1613 if ((major_revision == 0x03) != (hcd->speed == HCD_USB3))
1614 hcd = xhci->shared_hcd;
1615
1610 if (major_revision == 0) { 1616 if (major_revision == 0) {
1611 xhci_warn(xhci, "Event for port %u not in " 1617 xhci_warn(xhci, "Event for port %u not in "
1612 "Extended Capabilities, ignoring.\n", 1618 "Extended Capabilities, ignoring.\n",
@@ -1629,10 +1635,6 @@ static void handle_port_status(struct xhci_hcd *xhci,
1629 * into the index into the ports on the correct split roothub, and the 1635 * into the index into the ports on the correct split roothub, and the
1630 * correct bus_state structure. 1636 * correct bus_state structure.
1631 */ 1637 */
1632 /* Find the right roothub. */
1633 hcd = xhci_to_hcd(xhci);
1634 if ((major_revision == 0x03) != (hcd->speed == HCD_USB3))
1635 hcd = xhci->shared_hcd;
1636 bus_state = &xhci->bus_state[hcd_index(hcd)]; 1638 bus_state = &xhci->bus_state[hcd_index(hcd)];
1637 if (hcd->speed == HCD_USB3) 1639 if (hcd->speed == HCD_USB3)
1638 port_array = xhci->usb3_ports; 1640 port_array = xhci->usb3_ports;
@@ -2027,8 +2029,8 @@ static int process_ctrl_td(struct xhci_hcd *xhci, struct xhci_td *td,
2027 if (event_trb != ep_ring->dequeue && 2029 if (event_trb != ep_ring->dequeue &&
2028 event_trb != td->last_trb) 2030 event_trb != td->last_trb)
2029 td->urb->actual_length = 2031 td->urb->actual_length =
2030 td->urb->transfer_buffer_length 2032 td->urb->transfer_buffer_length -
2031 - TRB_LEN(le32_to_cpu(event->transfer_len)); 2033 EVENT_TRB_LEN(le32_to_cpu(event->transfer_len));
2032 else 2034 else
2033 td->urb->actual_length = 0; 2035 td->urb->actual_length = 0;
2034 2036
@@ -2060,7 +2062,7 @@ static int process_ctrl_td(struct xhci_hcd *xhci, struct xhci_td *td,
2060 /* Maybe the event was for the data stage? */ 2062 /* Maybe the event was for the data stage? */
2061 td->urb->actual_length = 2063 td->urb->actual_length =
2062 td->urb->transfer_buffer_length - 2064 td->urb->transfer_buffer_length -
2063 TRB_LEN(le32_to_cpu(event->transfer_len)); 2065 EVENT_TRB_LEN(le32_to_cpu(event->transfer_len));
2064 xhci_dbg(xhci, "Waiting for status " 2066 xhci_dbg(xhci, "Waiting for status "
2065 "stage event\n"); 2067 "stage event\n");
2066 return 0; 2068 return 0;
@@ -2096,7 +2098,7 @@ static int process_isoc_td(struct xhci_hcd *xhci, struct xhci_td *td,
2096 /* handle completion code */ 2098 /* handle completion code */
2097 switch (trb_comp_code) { 2099 switch (trb_comp_code) {
2098 case COMP_SUCCESS: 2100 case COMP_SUCCESS:
2099 if (TRB_LEN(le32_to_cpu(event->transfer_len)) == 0) { 2101 if (EVENT_TRB_LEN(le32_to_cpu(event->transfer_len)) == 0) {
2100 frame->status = 0; 2102 frame->status = 0;
2101 break; 2103 break;
2102 } 2104 }
@@ -2141,7 +2143,7 @@ static int process_isoc_td(struct xhci_hcd *xhci, struct xhci_td *td,
2141 len += TRB_LEN(le32_to_cpu(cur_trb->generic.field[2])); 2143 len += TRB_LEN(le32_to_cpu(cur_trb->generic.field[2]));
2142 } 2144 }
2143 len += TRB_LEN(le32_to_cpu(cur_trb->generic.field[2])) - 2145 len += TRB_LEN(le32_to_cpu(cur_trb->generic.field[2])) -
2144 TRB_LEN(le32_to_cpu(event->transfer_len)); 2146 EVENT_TRB_LEN(le32_to_cpu(event->transfer_len));
2145 2147
2146 if (trb_comp_code != COMP_STOP_INVAL) { 2148 if (trb_comp_code != COMP_STOP_INVAL) {
2147 frame->actual_length = len; 2149 frame->actual_length = len;
@@ -2199,7 +2201,7 @@ static int process_bulk_intr_td(struct xhci_hcd *xhci, struct xhci_td *td,
2199 case COMP_SUCCESS: 2201 case COMP_SUCCESS:
2200 /* Double check that the HW transferred everything. */ 2202 /* Double check that the HW transferred everything. */
2201 if (event_trb != td->last_trb || 2203 if (event_trb != td->last_trb ||
2202 TRB_LEN(le32_to_cpu(event->transfer_len)) != 0) { 2204 EVENT_TRB_LEN(le32_to_cpu(event->transfer_len)) != 0) {
2203 xhci_warn(xhci, "WARN Successful completion " 2205 xhci_warn(xhci, "WARN Successful completion "
2204 "on short TX\n"); 2206 "on short TX\n");
2205 if (td->urb->transfer_flags & URB_SHORT_NOT_OK) 2207 if (td->urb->transfer_flags & URB_SHORT_NOT_OK)
@@ -2227,18 +2229,18 @@ static int process_bulk_intr_td(struct xhci_hcd *xhci, struct xhci_td *td,
2227 "%d bytes untransferred\n", 2229 "%d bytes untransferred\n",
2228 td->urb->ep->desc.bEndpointAddress, 2230 td->urb->ep->desc.bEndpointAddress,
2229 td->urb->transfer_buffer_length, 2231 td->urb->transfer_buffer_length,
2230 TRB_LEN(le32_to_cpu(event->transfer_len))); 2232 EVENT_TRB_LEN(le32_to_cpu(event->transfer_len)));
2231 /* Fast path - was this the last TRB in the TD for this URB? */ 2233 /* Fast path - was this the last TRB in the TD for this URB? */
2232 if (event_trb == td->last_trb) { 2234 if (event_trb == td->last_trb) {
2233 if (TRB_LEN(le32_to_cpu(event->transfer_len)) != 0) { 2235 if (EVENT_TRB_LEN(le32_to_cpu(event->transfer_len)) != 0) {
2234 td->urb->actual_length = 2236 td->urb->actual_length =
2235 td->urb->transfer_buffer_length - 2237 td->urb->transfer_buffer_length -
2236 TRB_LEN(le32_to_cpu(event->transfer_len)); 2238 EVENT_TRB_LEN(le32_to_cpu(event->transfer_len));
2237 if (td->urb->transfer_buffer_length < 2239 if (td->urb->transfer_buffer_length <
2238 td->urb->actual_length) { 2240 td->urb->actual_length) {
2239 xhci_warn(xhci, "HC gave bad length " 2241 xhci_warn(xhci, "HC gave bad length "
2240 "of %d bytes left\n", 2242 "of %d bytes left\n",
2241 TRB_LEN(le32_to_cpu(event->transfer_len))); 2243 EVENT_TRB_LEN(le32_to_cpu(event->transfer_len)));
2242 td->urb->actual_length = 0; 2244 td->urb->actual_length = 0;
2243 if (td->urb->transfer_flags & URB_SHORT_NOT_OK) 2245 if (td->urb->transfer_flags & URB_SHORT_NOT_OK)
2244 *status = -EREMOTEIO; 2246 *status = -EREMOTEIO;
@@ -2280,7 +2282,7 @@ static int process_bulk_intr_td(struct xhci_hcd *xhci, struct xhci_td *td,
2280 if (trb_comp_code != COMP_STOP_INVAL) 2282 if (trb_comp_code != COMP_STOP_INVAL)
2281 td->urb->actual_length += 2283 td->urb->actual_length +=
2282 TRB_LEN(le32_to_cpu(cur_trb->generic.field[2])) - 2284 TRB_LEN(le32_to_cpu(cur_trb->generic.field[2])) -
2283 TRB_LEN(le32_to_cpu(event->transfer_len)); 2285 EVENT_TRB_LEN(le32_to_cpu(event->transfer_len));
2284 } 2286 }
2285 2287
2286 return finish_td(xhci, td, event_trb, event, ep, status, false); 2288 return finish_td(xhci, td, event_trb, event, ep, status, false);
@@ -2368,7 +2370,7 @@ static int handle_tx_event(struct xhci_hcd *xhci,
2368 * transfer type 2370 * transfer type
2369 */ 2371 */
2370 case COMP_SUCCESS: 2372 case COMP_SUCCESS:
2371 if (TRB_LEN(le32_to_cpu(event->transfer_len)) == 0) 2373 if (EVENT_TRB_LEN(le32_to_cpu(event->transfer_len)) == 0)
2372 break; 2374 break;
2373 if (xhci->quirks & XHCI_TRUST_TX_LENGTH) 2375 if (xhci->quirks & XHCI_TRUST_TX_LENGTH)
2374 trb_comp_code = COMP_SHORT_TX; 2376 trb_comp_code = COMP_SHORT_TX;
@@ -2461,14 +2463,21 @@ static int handle_tx_event(struct xhci_hcd *xhci,
2461 * TD list. 2463 * TD list.
2462 */ 2464 */
2463 if (list_empty(&ep_ring->td_list)) { 2465 if (list_empty(&ep_ring->td_list)) {
2464 xhci_warn(xhci, "WARN Event TRB for slot %d ep %d " 2466 /*
2465 "with no TDs queued?\n", 2467 * A stopped endpoint may generate an extra completion
2466 TRB_TO_SLOT_ID(le32_to_cpu(event->flags)), 2468 * event if the device was suspended. Don't print
2467 ep_index); 2469 * warnings.
2468 xhci_dbg(xhci, "Event TRB with TRB type ID %u\n", 2470 */
2469 (le32_to_cpu(event->flags) & 2471 if (!(trb_comp_code == COMP_STOP ||
2470 TRB_TYPE_BITMASK)>>10); 2472 trb_comp_code == COMP_STOP_INVAL)) {
2471 xhci_print_trb_offsets(xhci, (union xhci_trb *) event); 2473 xhci_warn(xhci, "WARN Event TRB for slot %d ep %d with no TDs queued?\n",
2474 TRB_TO_SLOT_ID(le32_to_cpu(event->flags)),
2475 ep_index);
2476 xhci_dbg(xhci, "Event TRB with TRB type ID %u\n",
2477 (le32_to_cpu(event->flags) &
2478 TRB_TYPE_BITMASK)>>10);
2479 xhci_print_trb_offsets(xhci, (union xhci_trb *) event);
2480 }
2472 if (ep->skip) { 2481 if (ep->skip) {
2473 ep->skip = false; 2482 ep->skip = false;
2474 xhci_dbg(xhci, "td_list is empty while skip " 2483 xhci_dbg(xhci, "td_list is empty while skip "
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index f1f01a834ba7..53b8f89a0b1c 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -350,7 +350,7 @@ static int xhci_try_enable_msi(struct usb_hcd *hcd)
350 * generate interrupts. Don't even try to enable MSI. 350 * generate interrupts. Don't even try to enable MSI.
351 */ 351 */
352 if (xhci->quirks & XHCI_BROKEN_MSI) 352 if (xhci->quirks & XHCI_BROKEN_MSI)
353 return 0; 353 goto legacy_irq;
354 354
355 /* unregister the legacy interrupt */ 355 /* unregister the legacy interrupt */
356 if (hcd->irq) 356 if (hcd->irq)
@@ -371,6 +371,7 @@ static int xhci_try_enable_msi(struct usb_hcd *hcd)
371 return -EINVAL; 371 return -EINVAL;
372 } 372 }
373 373
374 legacy_irq:
374 /* fall back to legacy interrupt*/ 375 /* fall back to legacy interrupt*/
375 ret = request_irq(pdev->irq, &usb_hcd_irq, IRQF_SHARED, 376 ret = request_irq(pdev->irq, &usb_hcd_irq, IRQF_SHARED,
376 hcd->irq_descr, hcd); 377 hcd->irq_descr, hcd);
@@ -3778,6 +3779,28 @@ int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev)
3778 return 0; 3779 return 0;
3779} 3780}
3780 3781
3782/*
3783 * Transfer the port index into real index in the HW port status
3784 * registers. Caculate offset between the port's PORTSC register
3785 * and port status base. Divide the number of per port register
3786 * to get the real index. The raw port number bases 1.
3787 */
3788int xhci_find_raw_port_number(struct usb_hcd *hcd, int port1)
3789{
3790 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
3791 __le32 __iomem *base_addr = &xhci->op_regs->port_status_base;
3792 __le32 __iomem *addr;
3793 int raw_port;
3794
3795 if (hcd->speed != HCD_USB3)
3796 addr = xhci->usb2_ports[port1 - 1];
3797 else
3798 addr = xhci->usb3_ports[port1 - 1];
3799
3800 raw_port = (addr - base_addr)/NUM_PORT_REGS + 1;
3801 return raw_port;
3802}
3803
3781#ifdef CONFIG_USB_SUSPEND 3804#ifdef CONFIG_USB_SUSPEND
3782 3805
3783/* BESL to HIRD Encoding array for USB2 LPM */ 3806/* BESL to HIRD Encoding array for USB2 LPM */
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index f791bd0aee6c..63582719e0fb 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -206,8 +206,8 @@ struct xhci_op_regs {
206/* bits 12:31 are reserved (and should be preserved on writes). */ 206/* bits 12:31 are reserved (and should be preserved on writes). */
207 207
208/* IMAN - Interrupt Management Register */ 208/* IMAN - Interrupt Management Register */
209#define IMAN_IP (1 << 1) 209#define IMAN_IE (1 << 1)
210#define IMAN_IE (1 << 0) 210#define IMAN_IP (1 << 0)
211 211
212/* USBSTS - USB status - status bitmasks */ 212/* USBSTS - USB status - status bitmasks */
213/* HC not running - set to 1 when run/stop bit is cleared. */ 213/* HC not running - set to 1 when run/stop bit is cleared. */
@@ -972,6 +972,10 @@ struct xhci_transfer_event {
972 __le32 flags; 972 __le32 flags;
973}; 973};
974 974
975/* Transfer event TRB length bit mask */
976/* bits 0:23 */
977#define EVENT_TRB_LEN(p) ((p) & 0xffffff)
978
975/** Transfer Event bit fields **/ 979/** Transfer Event bit fields **/
976#define TRB_TO_EP_ID(p) (((p) >> 16) & 0x1f) 980#define TRB_TO_EP_ID(p) (((p) >> 16) & 0x1f)
977 981
@@ -1829,6 +1833,7 @@ void xhci_test_and_clear_bit(struct xhci_hcd *xhci, __le32 __iomem **port_array,
1829int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, u16 wIndex, 1833int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, u16 wIndex,
1830 char *buf, u16 wLength); 1834 char *buf, u16 wLength);
1831int xhci_hub_status_data(struct usb_hcd *hcd, char *buf); 1835int xhci_hub_status_data(struct usb_hcd *hcd, char *buf);
1836int xhci_find_raw_port_number(struct usb_hcd *hcd, int port1);
1832 1837
1833#ifdef CONFIG_PM 1838#ifdef CONFIG_PM
1834int xhci_bus_suspend(struct usb_hcd *hcd); 1839int xhci_bus_suspend(struct usb_hcd *hcd);
diff --git a/drivers/usb/musb/da8xx.c b/drivers/usb/musb/da8xx.c
index 7c71769d71ff..41613a2b35e8 100644
--- a/drivers/usb/musb/da8xx.c
+++ b/drivers/usb/musb/da8xx.c
@@ -327,7 +327,7 @@ static irqreturn_t da8xx_musb_interrupt(int irq, void *hci)
327 u8 devctl = musb_readb(mregs, MUSB_DEVCTL); 327 u8 devctl = musb_readb(mregs, MUSB_DEVCTL);
328 int err; 328 int err;
329 329
330 err = musb->int_usb & USB_INTR_VBUSERROR; 330 err = musb->int_usb & MUSB_INTR_VBUSERROR;
331 if (err) { 331 if (err) {
332 /* 332 /*
333 * The Mentor core doesn't debounce VBUS as needed 333 * The Mentor core doesn't debounce VBUS as needed
diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c
index be18537c5f14..83eddedcd9be 100644
--- a/drivers/usb/musb/musb_gadget.c
+++ b/drivers/usb/musb/musb_gadget.c
@@ -141,7 +141,9 @@ static inline void map_dma_buffer(struct musb_request *request,
141static inline void unmap_dma_buffer(struct musb_request *request, 141static inline void unmap_dma_buffer(struct musb_request *request,
142 struct musb *musb) 142 struct musb *musb)
143{ 143{
144 if (!is_buffer_mapped(request)) 144 struct musb_ep *musb_ep = request->ep;
145
146 if (!is_buffer_mapped(request) || !musb_ep->dma)
145 return; 147 return;
146 148
147 if (request->request.dma == DMA_ADDR_INVALID) { 149 if (request->request.dma == DMA_ADDR_INVALID) {
@@ -195,7 +197,10 @@ __acquires(ep->musb->lock)
195 197
196 ep->busy = 1; 198 ep->busy = 1;
197 spin_unlock(&musb->lock); 199 spin_unlock(&musb->lock);
198 unmap_dma_buffer(req, musb); 200
201 if (!dma_mapping_error(&musb->g.dev, request->dma))
202 unmap_dma_buffer(req, musb);
203
199 if (request->status == 0) 204 if (request->status == 0)
200 dev_dbg(musb->controller, "%s done request %p, %d/%d\n", 205 dev_dbg(musb->controller, "%s done request %p, %d/%d\n",
201 ep->end_point.name, request, 206 ep->end_point.name, request,
diff --git a/drivers/usb/phy/Kconfig b/drivers/usb/phy/Kconfig
index 65217a590068..90549382eba5 100644
--- a/drivers/usb/phy/Kconfig
+++ b/drivers/usb/phy/Kconfig
@@ -38,6 +38,7 @@ config USB_ISP1301
38 tristate "NXP ISP1301 USB transceiver support" 38 tristate "NXP ISP1301 USB transceiver support"
39 depends on USB || USB_GADGET 39 depends on USB || USB_GADGET
40 depends on I2C 40 depends on I2C
41 select USB_OTG_UTILS
41 help 42 help
42 Say Y here to add support for the NXP ISP1301 USB transceiver driver. 43 Say Y here to add support for the NXP ISP1301 USB transceiver driver.
43 This chip is typically used as USB transceiver for USB host, gadget 44 This chip is typically used as USB transceiver for USB host, gadget
diff --git a/drivers/usb/serial/ark3116.c b/drivers/usb/serial/ark3116.c
index cbd904b8fba5..4775f8209e55 100644
--- a/drivers/usb/serial/ark3116.c
+++ b/drivers/usb/serial/ark3116.c
@@ -62,7 +62,6 @@ static int is_irda(struct usb_serial *serial)
62} 62}
63 63
64struct ark3116_private { 64struct ark3116_private {
65 wait_queue_head_t delta_msr_wait;
66 struct async_icount icount; 65 struct async_icount icount;
67 int irda; /* 1 for irda device */ 66 int irda; /* 1 for irda device */
68 67
@@ -146,7 +145,6 @@ static int ark3116_port_probe(struct usb_serial_port *port)
146 if (!priv) 145 if (!priv)
147 return -ENOMEM; 146 return -ENOMEM;
148 147
149 init_waitqueue_head(&priv->delta_msr_wait);
150 mutex_init(&priv->hw_lock); 148 mutex_init(&priv->hw_lock);
151 spin_lock_init(&priv->status_lock); 149 spin_lock_init(&priv->status_lock);
152 150
@@ -456,10 +454,14 @@ static int ark3116_ioctl(struct tty_struct *tty,
456 case TIOCMIWAIT: 454 case TIOCMIWAIT:
457 for (;;) { 455 for (;;) {
458 struct async_icount prev = priv->icount; 456 struct async_icount prev = priv->icount;
459 interruptible_sleep_on(&priv->delta_msr_wait); 457 interruptible_sleep_on(&port->delta_msr_wait);
460 /* see if a signal did it */ 458 /* see if a signal did it */
461 if (signal_pending(current)) 459 if (signal_pending(current))
462 return -ERESTARTSYS; 460 return -ERESTARTSYS;
461
462 if (port->serial->disconnected)
463 return -EIO;
464
463 if ((prev.rng == priv->icount.rng) && 465 if ((prev.rng == priv->icount.rng) &&
464 (prev.dsr == priv->icount.dsr) && 466 (prev.dsr == priv->icount.dsr) &&
465 (prev.dcd == priv->icount.dcd) && 467 (prev.dcd == priv->icount.dcd) &&
@@ -580,7 +582,7 @@ static void ark3116_update_msr(struct usb_serial_port *port, __u8 msr)
580 priv->icount.dcd++; 582 priv->icount.dcd++;
581 if (msr & UART_MSR_TERI) 583 if (msr & UART_MSR_TERI)
582 priv->icount.rng++; 584 priv->icount.rng++;
583 wake_up_interruptible(&priv->delta_msr_wait); 585 wake_up_interruptible(&port->delta_msr_wait);
584 } 586 }
585} 587}
586 588
diff --git a/drivers/usb/serial/ch341.c b/drivers/usb/serial/ch341.c
index d255f66e708e..07d4650a32ab 100644
--- a/drivers/usb/serial/ch341.c
+++ b/drivers/usb/serial/ch341.c
@@ -80,7 +80,6 @@ MODULE_DEVICE_TABLE(usb, id_table);
80 80
81struct ch341_private { 81struct ch341_private {
82 spinlock_t lock; /* access lock */ 82 spinlock_t lock; /* access lock */
83 wait_queue_head_t delta_msr_wait; /* wait queue for modem status */
84 unsigned baud_rate; /* set baud rate */ 83 unsigned baud_rate; /* set baud rate */
85 u8 line_control; /* set line control value RTS/DTR */ 84 u8 line_control; /* set line control value RTS/DTR */
86 u8 line_status; /* active status of modem control inputs */ 85 u8 line_status; /* active status of modem control inputs */
@@ -252,7 +251,6 @@ static int ch341_port_probe(struct usb_serial_port *port)
252 return -ENOMEM; 251 return -ENOMEM;
253 252
254 spin_lock_init(&priv->lock); 253 spin_lock_init(&priv->lock);
255 init_waitqueue_head(&priv->delta_msr_wait);
256 priv->baud_rate = DEFAULT_BAUD_RATE; 254 priv->baud_rate = DEFAULT_BAUD_RATE;
257 priv->line_control = CH341_BIT_RTS | CH341_BIT_DTR; 255 priv->line_control = CH341_BIT_RTS | CH341_BIT_DTR;
258 256
@@ -298,7 +296,7 @@ static void ch341_dtr_rts(struct usb_serial_port *port, int on)
298 priv->line_control &= ~(CH341_BIT_RTS | CH341_BIT_DTR); 296 priv->line_control &= ~(CH341_BIT_RTS | CH341_BIT_DTR);
299 spin_unlock_irqrestore(&priv->lock, flags); 297 spin_unlock_irqrestore(&priv->lock, flags);
300 ch341_set_handshake(port->serial->dev, priv->line_control); 298 ch341_set_handshake(port->serial->dev, priv->line_control);
301 wake_up_interruptible(&priv->delta_msr_wait); 299 wake_up_interruptible(&port->delta_msr_wait);
302} 300}
303 301
304static void ch341_close(struct usb_serial_port *port) 302static void ch341_close(struct usb_serial_port *port)
@@ -491,7 +489,7 @@ static void ch341_read_int_callback(struct urb *urb)
491 tty_kref_put(tty); 489 tty_kref_put(tty);
492 } 490 }
493 491
494 wake_up_interruptible(&priv->delta_msr_wait); 492 wake_up_interruptible(&port->delta_msr_wait);
495 } 493 }
496 494
497exit: 495exit:
@@ -517,11 +515,14 @@ static int wait_modem_info(struct usb_serial_port *port, unsigned int arg)
517 spin_unlock_irqrestore(&priv->lock, flags); 515 spin_unlock_irqrestore(&priv->lock, flags);
518 516
519 while (!multi_change) { 517 while (!multi_change) {
520 interruptible_sleep_on(&priv->delta_msr_wait); 518 interruptible_sleep_on(&port->delta_msr_wait);
521 /* see if a signal did it */ 519 /* see if a signal did it */
522 if (signal_pending(current)) 520 if (signal_pending(current))
523 return -ERESTARTSYS; 521 return -ERESTARTSYS;
524 522
523 if (port->serial->disconnected)
524 return -EIO;
525
525 spin_lock_irqsave(&priv->lock, flags); 526 spin_lock_irqsave(&priv->lock, flags);
526 status = priv->line_status; 527 status = priv->line_status;
527 multi_change = priv->multi_status_change; 528 multi_change = priv->multi_status_change;
diff --git a/drivers/usb/serial/cypress_m8.c b/drivers/usb/serial/cypress_m8.c
index 8efa19d0e9fb..ba7352e4187e 100644
--- a/drivers/usb/serial/cypress_m8.c
+++ b/drivers/usb/serial/cypress_m8.c
@@ -111,7 +111,6 @@ struct cypress_private {
111 int baud_rate; /* stores current baud rate in 111 int baud_rate; /* stores current baud rate in
112 integer form */ 112 integer form */
113 int isthrottled; /* if throttled, discard reads */ 113 int isthrottled; /* if throttled, discard reads */
114 wait_queue_head_t delta_msr_wait; /* used for TIOCMIWAIT */
115 char prev_status, diff_status; /* used for TIOCMIWAIT */ 114 char prev_status, diff_status; /* used for TIOCMIWAIT */
116 /* we pass a pointer to this as the argument sent to 115 /* we pass a pointer to this as the argument sent to
117 cypress_set_termios old_termios */ 116 cypress_set_termios old_termios */
@@ -449,7 +448,6 @@ static int cypress_generic_port_probe(struct usb_serial_port *port)
449 kfree(priv); 448 kfree(priv);
450 return -ENOMEM; 449 return -ENOMEM;
451 } 450 }
452 init_waitqueue_head(&priv->delta_msr_wait);
453 451
454 usb_reset_configuration(serial->dev); 452 usb_reset_configuration(serial->dev);
455 453
@@ -868,12 +866,16 @@ static int cypress_ioctl(struct tty_struct *tty,
868 switch (cmd) { 866 switch (cmd) {
869 /* This code comes from drivers/char/serial.c and ftdi_sio.c */ 867 /* This code comes from drivers/char/serial.c and ftdi_sio.c */
870 case TIOCMIWAIT: 868 case TIOCMIWAIT:
871 while (priv != NULL) { 869 for (;;) {
872 interruptible_sleep_on(&priv->delta_msr_wait); 870 interruptible_sleep_on(&port->delta_msr_wait);
873 /* see if a signal did it */ 871 /* see if a signal did it */
874 if (signal_pending(current)) 872 if (signal_pending(current))
875 return -ERESTARTSYS; 873 return -ERESTARTSYS;
876 else { 874
875 if (port->serial->disconnected)
876 return -EIO;
877
878 {
877 char diff = priv->diff_status; 879 char diff = priv->diff_status;
878 if (diff == 0) 880 if (diff == 0)
879 return -EIO; /* no change => error */ 881 return -EIO; /* no change => error */
@@ -1187,7 +1189,7 @@ static void cypress_read_int_callback(struct urb *urb)
1187 if (priv->current_status != priv->prev_status) { 1189 if (priv->current_status != priv->prev_status) {
1188 priv->diff_status |= priv->current_status ^ 1190 priv->diff_status |= priv->current_status ^
1189 priv->prev_status; 1191 priv->prev_status;
1190 wake_up_interruptible(&priv->delta_msr_wait); 1192 wake_up_interruptible(&port->delta_msr_wait);
1191 priv->prev_status = priv->current_status; 1193 priv->prev_status = priv->current_status;
1192 } 1194 }
1193 spin_unlock_irqrestore(&priv->lock, flags); 1195 spin_unlock_irqrestore(&priv->lock, flags);
diff --git a/drivers/usb/serial/f81232.c b/drivers/usb/serial/f81232.c
index b1b2dc64b50b..a172ad5c5ce8 100644
--- a/drivers/usb/serial/f81232.c
+++ b/drivers/usb/serial/f81232.c
@@ -47,7 +47,6 @@ MODULE_DEVICE_TABLE(usb, id_table);
47 47
48struct f81232_private { 48struct f81232_private {
49 spinlock_t lock; 49 spinlock_t lock;
50 wait_queue_head_t delta_msr_wait;
51 u8 line_control; 50 u8 line_control;
52 u8 line_status; 51 u8 line_status;
53}; 52};
@@ -111,7 +110,7 @@ static void f81232_process_read_urb(struct urb *urb)
111 line_status = priv->line_status; 110 line_status = priv->line_status;
112 priv->line_status &= ~UART_STATE_TRANSIENT_MASK; 111 priv->line_status &= ~UART_STATE_TRANSIENT_MASK;
113 spin_unlock_irqrestore(&priv->lock, flags); 112 spin_unlock_irqrestore(&priv->lock, flags);
114 wake_up_interruptible(&priv->delta_msr_wait); 113 wake_up_interruptible(&port->delta_msr_wait);
115 114
116 if (!urb->actual_length) 115 if (!urb->actual_length)
117 return; 116 return;
@@ -256,11 +255,14 @@ static int wait_modem_info(struct usb_serial_port *port, unsigned int arg)
256 spin_unlock_irqrestore(&priv->lock, flags); 255 spin_unlock_irqrestore(&priv->lock, flags);
257 256
258 while (1) { 257 while (1) {
259 interruptible_sleep_on(&priv->delta_msr_wait); 258 interruptible_sleep_on(&port->delta_msr_wait);
260 /* see if a signal did it */ 259 /* see if a signal did it */
261 if (signal_pending(current)) 260 if (signal_pending(current))
262 return -ERESTARTSYS; 261 return -ERESTARTSYS;
263 262
263 if (port->serial->disconnected)
264 return -EIO;
265
264 spin_lock_irqsave(&priv->lock, flags); 266 spin_lock_irqsave(&priv->lock, flags);
265 status = priv->line_status; 267 status = priv->line_status;
266 spin_unlock_irqrestore(&priv->lock, flags); 268 spin_unlock_irqrestore(&priv->lock, flags);
@@ -322,7 +324,6 @@ static int f81232_port_probe(struct usb_serial_port *port)
322 return -ENOMEM; 324 return -ENOMEM;
323 325
324 spin_lock_init(&priv->lock); 326 spin_lock_init(&priv->lock);
325 init_waitqueue_head(&priv->delta_msr_wait);
326 327
327 usb_set_serial_port_data(port, priv); 328 usb_set_serial_port_data(port, priv);
328 329
diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index edd162df49ca..9886180e45f1 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -69,9 +69,7 @@ struct ftdi_private {
69 int flags; /* some ASYNC_xxxx flags are supported */ 69 int flags; /* some ASYNC_xxxx flags are supported */
70 unsigned long last_dtr_rts; /* saved modem control outputs */ 70 unsigned long last_dtr_rts; /* saved modem control outputs */
71 struct async_icount icount; 71 struct async_icount icount;
72 wait_queue_head_t delta_msr_wait; /* Used for TIOCMIWAIT */
73 char prev_status; /* Used for TIOCMIWAIT */ 72 char prev_status; /* Used for TIOCMIWAIT */
74 bool dev_gone; /* Used to abort TIOCMIWAIT */
75 char transmit_empty; /* If transmitter is empty or not */ 73 char transmit_empty; /* If transmitter is empty or not */
76 __u16 interface; /* FT2232C, FT2232H or FT4232H port interface 74 __u16 interface; /* FT2232C, FT2232H or FT4232H port interface
77 (0 for FT232/245) */ 75 (0 for FT232/245) */
@@ -642,6 +640,7 @@ static struct usb_device_id id_table_combined [] = {
642 { USB_DEVICE(FTDI_VID, FTDI_RM_CANVIEW_PID) }, 640 { USB_DEVICE(FTDI_VID, FTDI_RM_CANVIEW_PID) },
643 { USB_DEVICE(ACTON_VID, ACTON_SPECTRAPRO_PID) }, 641 { USB_DEVICE(ACTON_VID, ACTON_SPECTRAPRO_PID) },
644 { USB_DEVICE(CONTEC_VID, CONTEC_COM1USBH_PID) }, 642 { USB_DEVICE(CONTEC_VID, CONTEC_COM1USBH_PID) },
643 { USB_DEVICE(MITSUBISHI_VID, MITSUBISHI_FXUSB_PID) },
645 { USB_DEVICE(BANDB_VID, BANDB_USOTL4_PID) }, 644 { USB_DEVICE(BANDB_VID, BANDB_USOTL4_PID) },
646 { USB_DEVICE(BANDB_VID, BANDB_USTL4_PID) }, 645 { USB_DEVICE(BANDB_VID, BANDB_USTL4_PID) },
647 { USB_DEVICE(BANDB_VID, BANDB_USO9ML2_PID) }, 646 { USB_DEVICE(BANDB_VID, BANDB_USO9ML2_PID) },
@@ -1691,10 +1690,8 @@ static int ftdi_sio_port_probe(struct usb_serial_port *port)
1691 1690
1692 kref_init(&priv->kref); 1691 kref_init(&priv->kref);
1693 mutex_init(&priv->cfg_lock); 1692 mutex_init(&priv->cfg_lock);
1694 init_waitqueue_head(&priv->delta_msr_wait);
1695 1693
1696 priv->flags = ASYNC_LOW_LATENCY; 1694 priv->flags = ASYNC_LOW_LATENCY;
1697 priv->dev_gone = false;
1698 1695
1699 if (quirk && quirk->port_probe) 1696 if (quirk && quirk->port_probe)
1700 quirk->port_probe(priv); 1697 quirk->port_probe(priv);
@@ -1840,8 +1837,7 @@ static int ftdi_sio_port_remove(struct usb_serial_port *port)
1840{ 1837{
1841 struct ftdi_private *priv = usb_get_serial_port_data(port); 1838 struct ftdi_private *priv = usb_get_serial_port_data(port);
1842 1839
1843 priv->dev_gone = true; 1840 wake_up_interruptible(&port->delta_msr_wait);
1844 wake_up_interruptible_all(&priv->delta_msr_wait);
1845 1841
1846 remove_sysfs_attrs(port); 1842 remove_sysfs_attrs(port);
1847 1843
@@ -1989,7 +1985,7 @@ static int ftdi_process_packet(struct usb_serial_port *port,
1989 if (diff_status & FTDI_RS0_RLSD) 1985 if (diff_status & FTDI_RS0_RLSD)
1990 priv->icount.dcd++; 1986 priv->icount.dcd++;
1991 1987
1992 wake_up_interruptible_all(&priv->delta_msr_wait); 1988 wake_up_interruptible(&port->delta_msr_wait);
1993 priv->prev_status = status; 1989 priv->prev_status = status;
1994 } 1990 }
1995 1991
@@ -2440,11 +2436,15 @@ static int ftdi_ioctl(struct tty_struct *tty,
2440 */ 2436 */
2441 case TIOCMIWAIT: 2437 case TIOCMIWAIT:
2442 cprev = priv->icount; 2438 cprev = priv->icount;
2443 while (!priv->dev_gone) { 2439 for (;;) {
2444 interruptible_sleep_on(&priv->delta_msr_wait); 2440 interruptible_sleep_on(&port->delta_msr_wait);
2445 /* see if a signal did it */ 2441 /* see if a signal did it */
2446 if (signal_pending(current)) 2442 if (signal_pending(current))
2447 return -ERESTARTSYS; 2443 return -ERESTARTSYS;
2444
2445 if (port->serial->disconnected)
2446 return -EIO;
2447
2448 cnow = priv->icount; 2448 cnow = priv->icount;
2449 if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) || 2449 if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
2450 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) || 2450 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
@@ -2454,8 +2454,6 @@ static int ftdi_ioctl(struct tty_struct *tty,
2454 } 2454 }
2455 cprev = cnow; 2455 cprev = cnow;
2456 } 2456 }
2457 return -EIO;
2458 break;
2459 case TIOCSERGETLSR: 2457 case TIOCSERGETLSR:
2460 return get_lsr_info(port, (struct serial_struct __user *)arg); 2458 return get_lsr_info(port, (struct serial_struct __user *)arg);
2461 break; 2459 break;
diff --git a/drivers/usb/serial/ftdi_sio_ids.h b/drivers/usb/serial/ftdi_sio_ids.h
index 9d359e189a64..e79861eeed4c 100644
--- a/drivers/usb/serial/ftdi_sio_ids.h
+++ b/drivers/usb/serial/ftdi_sio_ids.h
@@ -584,6 +584,13 @@
584#define CONTEC_COM1USBH_PID 0x8311 /* COM-1(USB)H */ 584#define CONTEC_COM1USBH_PID 0x8311 /* COM-1(USB)H */
585 585
586/* 586/*
587 * Mitsubishi Electric Corp. (http://www.meau.com)
588 * Submitted by Konstantin Holoborodko
589 */
590#define MITSUBISHI_VID 0x06D3
591#define MITSUBISHI_FXUSB_PID 0x0284 /* USB/RS422 converters: FX-USB-AW/-BD */
592
593/*
587 * Definitions for B&B Electronics products. 594 * Definitions for B&B Electronics products.
588 */ 595 */
589#define BANDB_VID 0x0856 /* B&B Electronics Vendor ID */ 596#define BANDB_VID 0x0856 /* B&B Electronics Vendor ID */
diff --git a/drivers/usb/serial/garmin_gps.c b/drivers/usb/serial/garmin_gps.c
index 1a07b12ef341..81caf5623ee2 100644
--- a/drivers/usb/serial/garmin_gps.c
+++ b/drivers/usb/serial/garmin_gps.c
@@ -956,10 +956,7 @@ static void garmin_close(struct usb_serial_port *port)
956 if (!serial) 956 if (!serial)
957 return; 957 return;
958 958
959 mutex_lock(&port->serial->disc_mutex); 959 garmin_clear(garmin_data_p);
960
961 if (!port->serial->disconnected)
962 garmin_clear(garmin_data_p);
963 960
964 /* shutdown our urbs */ 961 /* shutdown our urbs */
965 usb_kill_urb(port->read_urb); 962 usb_kill_urb(port->read_urb);
@@ -968,8 +965,6 @@ static void garmin_close(struct usb_serial_port *port)
968 /* keep reset state so we know that we must start a new session */ 965 /* keep reset state so we know that we must start a new session */
969 if (garmin_data_p->state != STATE_RESET) 966 if (garmin_data_p->state != STATE_RESET)
970 garmin_data_p->state = STATE_DISCONNECTED; 967 garmin_data_p->state = STATE_DISCONNECTED;
971
972 mutex_unlock(&port->serial->disc_mutex);
973} 968}
974 969
975 970
diff --git a/drivers/usb/serial/io_edgeport.c b/drivers/usb/serial/io_edgeport.c
index 44e5208f7c61..cf0b0a2f7b56 100644
--- a/drivers/usb/serial/io_edgeport.c
+++ b/drivers/usb/serial/io_edgeport.c
@@ -110,7 +110,6 @@ struct edgeport_port {
110 wait_queue_head_t wait_chase; /* for handling sleeping while waiting for chase to finish */ 110 wait_queue_head_t wait_chase; /* for handling sleeping while waiting for chase to finish */
111 wait_queue_head_t wait_open; /* for handling sleeping while waiting for open to finish */ 111 wait_queue_head_t wait_open; /* for handling sleeping while waiting for open to finish */
112 wait_queue_head_t wait_command; /* for handling sleeping while waiting for command to finish */ 112 wait_queue_head_t wait_command; /* for handling sleeping while waiting for command to finish */
113 wait_queue_head_t delta_msr_wait; /* for handling sleeping while waiting for msr change to happen */
114 113
115 struct async_icount icount; 114 struct async_icount icount;
116 struct usb_serial_port *port; /* loop back to the owner of this object */ 115 struct usb_serial_port *port; /* loop back to the owner of this object */
@@ -866,7 +865,6 @@ static int edge_open(struct tty_struct *tty, struct usb_serial_port *port)
866 /* initialize our wait queues */ 865 /* initialize our wait queues */
867 init_waitqueue_head(&edge_port->wait_open); 866 init_waitqueue_head(&edge_port->wait_open);
868 init_waitqueue_head(&edge_port->wait_chase); 867 init_waitqueue_head(&edge_port->wait_chase);
869 init_waitqueue_head(&edge_port->delta_msr_wait);
870 init_waitqueue_head(&edge_port->wait_command); 868 init_waitqueue_head(&edge_port->wait_command);
871 869
872 /* initialize our icount structure */ 870 /* initialize our icount structure */
@@ -1651,13 +1649,17 @@ static int edge_ioctl(struct tty_struct *tty,
1651 dev_dbg(&port->dev, "%s (%d) TIOCMIWAIT\n", __func__, port->number); 1649 dev_dbg(&port->dev, "%s (%d) TIOCMIWAIT\n", __func__, port->number);
1652 cprev = edge_port->icount; 1650 cprev = edge_port->icount;
1653 while (1) { 1651 while (1) {
1654 prepare_to_wait(&edge_port->delta_msr_wait, 1652 prepare_to_wait(&port->delta_msr_wait,
1655 &wait, TASK_INTERRUPTIBLE); 1653 &wait, TASK_INTERRUPTIBLE);
1656 schedule(); 1654 schedule();
1657 finish_wait(&edge_port->delta_msr_wait, &wait); 1655 finish_wait(&port->delta_msr_wait, &wait);
1658 /* see if a signal did it */ 1656 /* see if a signal did it */
1659 if (signal_pending(current)) 1657 if (signal_pending(current))
1660 return -ERESTARTSYS; 1658 return -ERESTARTSYS;
1659
1660 if (port->serial->disconnected)
1661 return -EIO;
1662
1661 cnow = edge_port->icount; 1663 cnow = edge_port->icount;
1662 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr && 1664 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
1663 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts) 1665 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts)
@@ -2033,7 +2035,7 @@ static void handle_new_msr(struct edgeport_port *edge_port, __u8 newMsr)
2033 icount->dcd++; 2035 icount->dcd++;
2034 if (newMsr & EDGEPORT_MSR_DELTA_RI) 2036 if (newMsr & EDGEPORT_MSR_DELTA_RI)
2035 icount->rng++; 2037 icount->rng++;
2036 wake_up_interruptible(&edge_port->delta_msr_wait); 2038 wake_up_interruptible(&edge_port->port->delta_msr_wait);
2037 } 2039 }
2038 2040
2039 /* Save the new modem status */ 2041 /* Save the new modem status */
diff --git a/drivers/usb/serial/io_ti.c b/drivers/usb/serial/io_ti.c
index c23776679f70..7777172206de 100644
--- a/drivers/usb/serial/io_ti.c
+++ b/drivers/usb/serial/io_ti.c
@@ -87,9 +87,6 @@ struct edgeport_port {
87 int close_pending; 87 int close_pending;
88 int lsr_event; 88 int lsr_event;
89 struct async_icount icount; 89 struct async_icount icount;
90 wait_queue_head_t delta_msr_wait; /* for handling sleeping while
91 waiting for msr change to
92 happen */
93 struct edgeport_serial *edge_serial; 90 struct edgeport_serial *edge_serial;
94 struct usb_serial_port *port; 91 struct usb_serial_port *port;
95 __u8 bUartMode; /* Port type, 0: RS232, etc. */ 92 __u8 bUartMode; /* Port type, 0: RS232, etc. */
@@ -1459,7 +1456,7 @@ static void handle_new_msr(struct edgeport_port *edge_port, __u8 msr)
1459 icount->dcd++; 1456 icount->dcd++;
1460 if (msr & EDGEPORT_MSR_DELTA_RI) 1457 if (msr & EDGEPORT_MSR_DELTA_RI)
1461 icount->rng++; 1458 icount->rng++;
1462 wake_up_interruptible(&edge_port->delta_msr_wait); 1459 wake_up_interruptible(&edge_port->port->delta_msr_wait);
1463 } 1460 }
1464 1461
1465 /* Save the new modem status */ 1462 /* Save the new modem status */
@@ -1754,7 +1751,6 @@ static int edge_open(struct tty_struct *tty, struct usb_serial_port *port)
1754 dev = port->serial->dev; 1751 dev = port->serial->dev;
1755 1752
1756 memset(&(edge_port->icount), 0x00, sizeof(edge_port->icount)); 1753 memset(&(edge_port->icount), 0x00, sizeof(edge_port->icount));
1757 init_waitqueue_head(&edge_port->delta_msr_wait);
1758 1754
1759 /* turn off loopback */ 1755 /* turn off loopback */
1760 status = ti_do_config(edge_port, UMPC_SET_CLR_LOOPBACK, 0); 1756 status = ti_do_config(edge_port, UMPC_SET_CLR_LOOPBACK, 0);
@@ -2434,10 +2430,14 @@ static int edge_ioctl(struct tty_struct *tty,
2434 dev_dbg(&port->dev, "%s - TIOCMIWAIT\n", __func__); 2430 dev_dbg(&port->dev, "%s - TIOCMIWAIT\n", __func__);
2435 cprev = edge_port->icount; 2431 cprev = edge_port->icount;
2436 while (1) { 2432 while (1) {
2437 interruptible_sleep_on(&edge_port->delta_msr_wait); 2433 interruptible_sleep_on(&port->delta_msr_wait);
2438 /* see if a signal did it */ 2434 /* see if a signal did it */
2439 if (signal_pending(current)) 2435 if (signal_pending(current))
2440 return -ERESTARTSYS; 2436 return -ERESTARTSYS;
2437
2438 if (port->serial->disconnected)
2439 return -EIO;
2440
2441 cnow = edge_port->icount; 2441 cnow = edge_port->icount;
2442 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr && 2442 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
2443 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts) 2443 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts)
@@ -2649,6 +2649,7 @@ static struct usb_serial_driver edgeport_2port_device = {
2649 .set_termios = edge_set_termios, 2649 .set_termios = edge_set_termios,
2650 .tiocmget = edge_tiocmget, 2650 .tiocmget = edge_tiocmget,
2651 .tiocmset = edge_tiocmset, 2651 .tiocmset = edge_tiocmset,
2652 .get_icount = edge_get_icount,
2652 .write = edge_write, 2653 .write = edge_write,
2653 .write_room = edge_write_room, 2654 .write_room = edge_write_room,
2654 .chars_in_buffer = edge_chars_in_buffer, 2655 .chars_in_buffer = edge_chars_in_buffer,
diff --git a/drivers/usb/serial/mct_u232.c b/drivers/usb/serial/mct_u232.c
index a64d420f687b..06d5a60be2c4 100644
--- a/drivers/usb/serial/mct_u232.c
+++ b/drivers/usb/serial/mct_u232.c
@@ -114,8 +114,6 @@ struct mct_u232_private {
114 unsigned char last_msr; /* Modem Status Register */ 114 unsigned char last_msr; /* Modem Status Register */
115 unsigned int rx_flags; /* Throttling flags */ 115 unsigned int rx_flags; /* Throttling flags */
116 struct async_icount icount; 116 struct async_icount icount;
117 wait_queue_head_t msr_wait; /* for handling sleeping while waiting
118 for msr change to happen */
119}; 117};
120 118
121#define THROTTLED 0x01 119#define THROTTLED 0x01
@@ -409,7 +407,6 @@ static int mct_u232_port_probe(struct usb_serial_port *port)
409 return -ENOMEM; 407 return -ENOMEM;
410 408
411 spin_lock_init(&priv->lock); 409 spin_lock_init(&priv->lock);
412 init_waitqueue_head(&priv->msr_wait);
413 410
414 usb_set_serial_port_data(port, priv); 411 usb_set_serial_port_data(port, priv);
415 412
@@ -601,7 +598,7 @@ static void mct_u232_read_int_callback(struct urb *urb)
601 tty_kref_put(tty); 598 tty_kref_put(tty);
602 } 599 }
603#endif 600#endif
604 wake_up_interruptible(&priv->msr_wait); 601 wake_up_interruptible(&port->delta_msr_wait);
605 spin_unlock_irqrestore(&priv->lock, flags); 602 spin_unlock_irqrestore(&priv->lock, flags);
606exit: 603exit:
607 retval = usb_submit_urb(urb, GFP_ATOMIC); 604 retval = usb_submit_urb(urb, GFP_ATOMIC);
@@ -810,13 +807,17 @@ static int mct_u232_ioctl(struct tty_struct *tty,
810 cprev = mct_u232_port->icount; 807 cprev = mct_u232_port->icount;
811 spin_unlock_irqrestore(&mct_u232_port->lock, flags); 808 spin_unlock_irqrestore(&mct_u232_port->lock, flags);
812 for ( ; ; ) { 809 for ( ; ; ) {
813 prepare_to_wait(&mct_u232_port->msr_wait, 810 prepare_to_wait(&port->delta_msr_wait,
814 &wait, TASK_INTERRUPTIBLE); 811 &wait, TASK_INTERRUPTIBLE);
815 schedule(); 812 schedule();
816 finish_wait(&mct_u232_port->msr_wait, &wait); 813 finish_wait(&port->delta_msr_wait, &wait);
817 /* see if a signal did it */ 814 /* see if a signal did it */
818 if (signal_pending(current)) 815 if (signal_pending(current))
819 return -ERESTARTSYS; 816 return -ERESTARTSYS;
817
818 if (port->serial->disconnected)
819 return -EIO;
820
820 spin_lock_irqsave(&mct_u232_port->lock, flags); 821 spin_lock_irqsave(&mct_u232_port->lock, flags);
821 cnow = mct_u232_port->icount; 822 cnow = mct_u232_port->icount;
822 spin_unlock_irqrestore(&mct_u232_port->lock, flags); 823 spin_unlock_irqrestore(&mct_u232_port->lock, flags);
diff --git a/drivers/usb/serial/mos7840.c b/drivers/usb/serial/mos7840.c
index 08284d28e84b..2be376a2e0e3 100644
--- a/drivers/usb/serial/mos7840.c
+++ b/drivers/usb/serial/mos7840.c
@@ -219,7 +219,6 @@ struct moschip_port {
219 char open; 219 char open;
220 char open_ports; 220 char open_ports;
221 wait_queue_head_t wait_chase; /* for handling sleeping while waiting for chase to finish */ 221 wait_queue_head_t wait_chase; /* for handling sleeping while waiting for chase to finish */
222 wait_queue_head_t delta_msr_wait; /* for handling sleeping while waiting for msr change to happen */
223 int delta_msr_cond; 222 int delta_msr_cond;
224 struct async_icount icount; 223 struct async_icount icount;
225 struct usb_serial_port *port; /* loop back to the owner of this object */ 224 struct usb_serial_port *port; /* loop back to the owner of this object */
@@ -423,6 +422,9 @@ static void mos7840_handle_new_msr(struct moschip_port *port, __u8 new_msr)
423 icount->rng++; 422 icount->rng++;
424 smp_wmb(); 423 smp_wmb();
425 } 424 }
425
426 mos7840_port->delta_msr_cond = 1;
427 wake_up_interruptible(&port->port->delta_msr_wait);
426 } 428 }
427} 429}
428 430
@@ -1124,7 +1126,6 @@ static int mos7840_open(struct tty_struct *tty, struct usb_serial_port *port)
1124 1126
1125 /* initialize our wait queues */ 1127 /* initialize our wait queues */
1126 init_waitqueue_head(&mos7840_port->wait_chase); 1128 init_waitqueue_head(&mos7840_port->wait_chase);
1127 init_waitqueue_head(&mos7840_port->delta_msr_wait);
1128 1129
1129 /* initialize our icount structure */ 1130 /* initialize our icount structure */
1130 memset(&(mos7840_port->icount), 0x00, sizeof(mos7840_port->icount)); 1131 memset(&(mos7840_port->icount), 0x00, sizeof(mos7840_port->icount));
@@ -2014,8 +2015,6 @@ static void mos7840_change_port_settings(struct tty_struct *tty,
2014 mos7840_port->read_urb_busy = false; 2015 mos7840_port->read_urb_busy = false;
2015 } 2016 }
2016 } 2017 }
2017 wake_up(&mos7840_port->delta_msr_wait);
2018 mos7840_port->delta_msr_cond = 1;
2019 dev_dbg(&port->dev, "%s - mos7840_port->shadowLCR is End %x\n", __func__, 2018 dev_dbg(&port->dev, "%s - mos7840_port->shadowLCR is End %x\n", __func__,
2020 mos7840_port->shadowLCR); 2019 mos7840_port->shadowLCR);
2021} 2020}
@@ -2216,13 +2215,18 @@ static int mos7840_ioctl(struct tty_struct *tty,
2216 while (1) { 2215 while (1) {
2217 /* interruptible_sleep_on(&mos7840_port->delta_msr_wait); */ 2216 /* interruptible_sleep_on(&mos7840_port->delta_msr_wait); */
2218 mos7840_port->delta_msr_cond = 0; 2217 mos7840_port->delta_msr_cond = 0;
2219 wait_event_interruptible(mos7840_port->delta_msr_wait, 2218 wait_event_interruptible(port->delta_msr_wait,
2220 (mos7840_port-> 2219 (port->serial->disconnected ||
2220 mos7840_port->
2221 delta_msr_cond == 1)); 2221 delta_msr_cond == 1));
2222 2222
2223 /* see if a signal did it */ 2223 /* see if a signal did it */
2224 if (signal_pending(current)) 2224 if (signal_pending(current))
2225 return -ERESTARTSYS; 2225 return -ERESTARTSYS;
2226
2227 if (port->serial->disconnected)
2228 return -EIO;
2229
2226 cnow = mos7840_port->icount; 2230 cnow = mos7840_port->icount;
2227 smp_rmb(); 2231 smp_rmb();
2228 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr && 2232 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
diff --git a/drivers/usb/serial/oti6858.c b/drivers/usb/serial/oti6858.c
index a958fd41b5b3..87c71ccfee87 100644
--- a/drivers/usb/serial/oti6858.c
+++ b/drivers/usb/serial/oti6858.c
@@ -188,7 +188,6 @@ struct oti6858_private {
188 u8 setup_done; 188 u8 setup_done;
189 struct delayed_work delayed_setup_work; 189 struct delayed_work delayed_setup_work;
190 190
191 wait_queue_head_t intr_wait;
192 struct usb_serial_port *port; /* USB port with which associated */ 191 struct usb_serial_port *port; /* USB port with which associated */
193}; 192};
194 193
@@ -339,7 +338,6 @@ static int oti6858_port_probe(struct usb_serial_port *port)
339 return -ENOMEM; 338 return -ENOMEM;
340 339
341 spin_lock_init(&priv->lock); 340 spin_lock_init(&priv->lock);
342 init_waitqueue_head(&priv->intr_wait);
343 priv->port = port; 341 priv->port = port;
344 INIT_DELAYED_WORK(&priv->delayed_setup_work, setup_line); 342 INIT_DELAYED_WORK(&priv->delayed_setup_work, setup_line);
345 INIT_DELAYED_WORK(&priv->delayed_write_work, send_data); 343 INIT_DELAYED_WORK(&priv->delayed_write_work, send_data);
@@ -664,11 +662,15 @@ static int wait_modem_info(struct usb_serial_port *port, unsigned int arg)
664 spin_unlock_irqrestore(&priv->lock, flags); 662 spin_unlock_irqrestore(&priv->lock, flags);
665 663
666 while (1) { 664 while (1) {
667 wait_event_interruptible(priv->intr_wait, 665 wait_event_interruptible(port->delta_msr_wait,
666 port->serial->disconnected ||
668 priv->status.pin_state != prev); 667 priv->status.pin_state != prev);
669 if (signal_pending(current)) 668 if (signal_pending(current))
670 return -ERESTARTSYS; 669 return -ERESTARTSYS;
671 670
671 if (port->serial->disconnected)
672 return -EIO;
673
672 spin_lock_irqsave(&priv->lock, flags); 674 spin_lock_irqsave(&priv->lock, flags);
673 status = priv->status.pin_state & PIN_MASK; 675 status = priv->status.pin_state & PIN_MASK;
674 spin_unlock_irqrestore(&priv->lock, flags); 676 spin_unlock_irqrestore(&priv->lock, flags);
@@ -763,7 +765,7 @@ static void oti6858_read_int_callback(struct urb *urb)
763 765
764 if (!priv->transient) { 766 if (!priv->transient) {
765 if (xs->pin_state != priv->status.pin_state) 767 if (xs->pin_state != priv->status.pin_state)
766 wake_up_interruptible(&priv->intr_wait); 768 wake_up_interruptible(&port->delta_msr_wait);
767 memcpy(&priv->status, xs, OTI6858_CTRL_PKT_SIZE); 769 memcpy(&priv->status, xs, OTI6858_CTRL_PKT_SIZE);
768 } 770 }
769 771
diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c
index 54adc9125e5c..3b10018d89a3 100644
--- a/drivers/usb/serial/pl2303.c
+++ b/drivers/usb/serial/pl2303.c
@@ -139,7 +139,6 @@ struct pl2303_serial_private {
139 139
140struct pl2303_private { 140struct pl2303_private {
141 spinlock_t lock; 141 spinlock_t lock;
142 wait_queue_head_t delta_msr_wait;
143 u8 line_control; 142 u8 line_control;
144 u8 line_status; 143 u8 line_status;
145}; 144};
@@ -233,7 +232,6 @@ static int pl2303_port_probe(struct usb_serial_port *port)
233 return -ENOMEM; 232 return -ENOMEM;
234 233
235 spin_lock_init(&priv->lock); 234 spin_lock_init(&priv->lock);
236 init_waitqueue_head(&priv->delta_msr_wait);
237 235
238 usb_set_serial_port_data(port, priv); 236 usb_set_serial_port_data(port, priv);
239 237
@@ -607,11 +605,14 @@ static int wait_modem_info(struct usb_serial_port *port, unsigned int arg)
607 spin_unlock_irqrestore(&priv->lock, flags); 605 spin_unlock_irqrestore(&priv->lock, flags);
608 606
609 while (1) { 607 while (1) {
610 interruptible_sleep_on(&priv->delta_msr_wait); 608 interruptible_sleep_on(&port->delta_msr_wait);
611 /* see if a signal did it */ 609 /* see if a signal did it */
612 if (signal_pending(current)) 610 if (signal_pending(current))
613 return -ERESTARTSYS; 611 return -ERESTARTSYS;
614 612
613 if (port->serial->disconnected)
614 return -EIO;
615
615 spin_lock_irqsave(&priv->lock, flags); 616 spin_lock_irqsave(&priv->lock, flags);
616 status = priv->line_status; 617 status = priv->line_status;
617 spin_unlock_irqrestore(&priv->lock, flags); 618 spin_unlock_irqrestore(&priv->lock, flags);
@@ -719,7 +720,7 @@ static void pl2303_update_line_status(struct usb_serial_port *port,
719 spin_unlock_irqrestore(&priv->lock, flags); 720 spin_unlock_irqrestore(&priv->lock, flags);
720 if (priv->line_status & UART_BREAK_ERROR) 721 if (priv->line_status & UART_BREAK_ERROR)
721 usb_serial_handle_break(port); 722 usb_serial_handle_break(port);
722 wake_up_interruptible(&priv->delta_msr_wait); 723 wake_up_interruptible(&port->delta_msr_wait);
723 724
724 tty = tty_port_tty_get(&port->port); 725 tty = tty_port_tty_get(&port->port);
725 if (!tty) 726 if (!tty)
@@ -783,7 +784,7 @@ static void pl2303_process_read_urb(struct urb *urb)
783 line_status = priv->line_status; 784 line_status = priv->line_status;
784 priv->line_status &= ~UART_STATE_TRANSIENT_MASK; 785 priv->line_status &= ~UART_STATE_TRANSIENT_MASK;
785 spin_unlock_irqrestore(&priv->lock, flags); 786 spin_unlock_irqrestore(&priv->lock, flags);
786 wake_up_interruptible(&priv->delta_msr_wait); 787 wake_up_interruptible(&port->delta_msr_wait);
787 788
788 if (!urb->actual_length) 789 if (!urb->actual_length)
789 return; 790 return;
diff --git a/drivers/usb/serial/quatech2.c b/drivers/usb/serial/quatech2.c
index d8531047b41a..ef3a7d5eaab4 100644
--- a/drivers/usb/serial/quatech2.c
+++ b/drivers/usb/serial/quatech2.c
@@ -127,7 +127,6 @@ struct qt2_port_private {
127 u8 shadowLSR; 127 u8 shadowLSR;
128 u8 shadowMSR; 128 u8 shadowMSR;
129 129
130 wait_queue_head_t delta_msr_wait; /* Used for TIOCMIWAIT */
131 struct async_icount icount; 130 struct async_icount icount;
132 131
133 struct usb_serial_port *port; 132 struct usb_serial_port *port;
@@ -502,8 +501,9 @@ static int wait_modem_info(struct usb_serial_port *port, unsigned int arg)
502 spin_unlock_irqrestore(&priv->lock, flags); 501 spin_unlock_irqrestore(&priv->lock, flags);
503 502
504 while (1) { 503 while (1) {
505 wait_event_interruptible(priv->delta_msr_wait, 504 wait_event_interruptible(port->delta_msr_wait,
506 ((priv->icount.rng != prev.rng) || 505 (port->serial->disconnected ||
506 (priv->icount.rng != prev.rng) ||
507 (priv->icount.dsr != prev.dsr) || 507 (priv->icount.dsr != prev.dsr) ||
508 (priv->icount.dcd != prev.dcd) || 508 (priv->icount.dcd != prev.dcd) ||
509 (priv->icount.cts != prev.cts))); 509 (priv->icount.cts != prev.cts)));
@@ -511,6 +511,9 @@ static int wait_modem_info(struct usb_serial_port *port, unsigned int arg)
511 if (signal_pending(current)) 511 if (signal_pending(current))
512 return -ERESTARTSYS; 512 return -ERESTARTSYS;
513 513
514 if (port->serial->disconnected)
515 return -EIO;
516
514 spin_lock_irqsave(&priv->lock, flags); 517 spin_lock_irqsave(&priv->lock, flags);
515 cur = priv->icount; 518 cur = priv->icount;
516 spin_unlock_irqrestore(&priv->lock, flags); 519 spin_unlock_irqrestore(&priv->lock, flags);
@@ -820,7 +823,6 @@ static int qt2_port_probe(struct usb_serial_port *port)
820 823
821 spin_lock_init(&port_priv->lock); 824 spin_lock_init(&port_priv->lock);
822 spin_lock_init(&port_priv->urb_lock); 825 spin_lock_init(&port_priv->urb_lock);
823 init_waitqueue_head(&port_priv->delta_msr_wait);
824 port_priv->port = port; 826 port_priv->port = port;
825 827
826 port_priv->write_urb = usb_alloc_urb(0, GFP_KERNEL); 828 port_priv->write_urb = usb_alloc_urb(0, GFP_KERNEL);
@@ -957,7 +959,7 @@ static void qt2_update_msr(struct usb_serial_port *port, unsigned char *ch)
957 if (newMSR & UART_MSR_TERI) 959 if (newMSR & UART_MSR_TERI)
958 port_priv->icount.rng++; 960 port_priv->icount.rng++;
959 961
960 wake_up_interruptible(&port_priv->delta_msr_wait); 962 wake_up_interruptible(&port->delta_msr_wait);
961 } 963 }
962} 964}
963 965
diff --git a/drivers/usb/serial/spcp8x5.c b/drivers/usb/serial/spcp8x5.c
index 91ff8e3bddbd..549ef68ff5fa 100644
--- a/drivers/usb/serial/spcp8x5.c
+++ b/drivers/usb/serial/spcp8x5.c
@@ -149,7 +149,6 @@ enum spcp8x5_type {
149struct spcp8x5_private { 149struct spcp8x5_private {
150 spinlock_t lock; 150 spinlock_t lock;
151 enum spcp8x5_type type; 151 enum spcp8x5_type type;
152 wait_queue_head_t delta_msr_wait;
153 u8 line_control; 152 u8 line_control;
154 u8 line_status; 153 u8 line_status;
155}; 154};
@@ -179,7 +178,6 @@ static int spcp8x5_port_probe(struct usb_serial_port *port)
179 return -ENOMEM; 178 return -ENOMEM;
180 179
181 spin_lock_init(&priv->lock); 180 spin_lock_init(&priv->lock);
182 init_waitqueue_head(&priv->delta_msr_wait);
183 priv->type = type; 181 priv->type = type;
184 182
185 usb_set_serial_port_data(port , priv); 183 usb_set_serial_port_data(port , priv);
@@ -475,7 +473,7 @@ static void spcp8x5_process_read_urb(struct urb *urb)
475 priv->line_status &= ~UART_STATE_TRANSIENT_MASK; 473 priv->line_status &= ~UART_STATE_TRANSIENT_MASK;
476 spin_unlock_irqrestore(&priv->lock, flags); 474 spin_unlock_irqrestore(&priv->lock, flags);
477 /* wake up the wait for termios */ 475 /* wake up the wait for termios */
478 wake_up_interruptible(&priv->delta_msr_wait); 476 wake_up_interruptible(&port->delta_msr_wait);
479 477
480 if (!urb->actual_length) 478 if (!urb->actual_length)
481 return; 479 return;
@@ -526,12 +524,15 @@ static int spcp8x5_wait_modem_info(struct usb_serial_port *port,
526 524
527 while (1) { 525 while (1) {
528 /* wake up in bulk read */ 526 /* wake up in bulk read */
529 interruptible_sleep_on(&priv->delta_msr_wait); 527 interruptible_sleep_on(&port->delta_msr_wait);
530 528
531 /* see if a signal did it */ 529 /* see if a signal did it */
532 if (signal_pending(current)) 530 if (signal_pending(current))
533 return -ERESTARTSYS; 531 return -ERESTARTSYS;
534 532
533 if (port->serial->disconnected)
534 return -EIO;
535
535 spin_lock_irqsave(&priv->lock, flags); 536 spin_lock_irqsave(&priv->lock, flags);
536 status = priv->line_status; 537 status = priv->line_status;
537 spin_unlock_irqrestore(&priv->lock, flags); 538 spin_unlock_irqrestore(&priv->lock, flags);
diff --git a/drivers/usb/serial/ssu100.c b/drivers/usb/serial/ssu100.c
index b57cf841c5b6..4b2a19757b4d 100644
--- a/drivers/usb/serial/ssu100.c
+++ b/drivers/usb/serial/ssu100.c
@@ -61,7 +61,6 @@ struct ssu100_port_private {
61 spinlock_t status_lock; 61 spinlock_t status_lock;
62 u8 shadowLSR; 62 u8 shadowLSR;
63 u8 shadowMSR; 63 u8 shadowMSR;
64 wait_queue_head_t delta_msr_wait; /* Used for TIOCMIWAIT */
65 struct async_icount icount; 64 struct async_icount icount;
66}; 65};
67 66
@@ -355,8 +354,9 @@ static int wait_modem_info(struct usb_serial_port *port, unsigned int arg)
355 spin_unlock_irqrestore(&priv->status_lock, flags); 354 spin_unlock_irqrestore(&priv->status_lock, flags);
356 355
357 while (1) { 356 while (1) {
358 wait_event_interruptible(priv->delta_msr_wait, 357 wait_event_interruptible(port->delta_msr_wait,
359 ((priv->icount.rng != prev.rng) || 358 (port->serial->disconnected ||
359 (priv->icount.rng != prev.rng) ||
360 (priv->icount.dsr != prev.dsr) || 360 (priv->icount.dsr != prev.dsr) ||
361 (priv->icount.dcd != prev.dcd) || 361 (priv->icount.dcd != prev.dcd) ||
362 (priv->icount.cts != prev.cts))); 362 (priv->icount.cts != prev.cts)));
@@ -364,6 +364,9 @@ static int wait_modem_info(struct usb_serial_port *port, unsigned int arg)
364 if (signal_pending(current)) 364 if (signal_pending(current))
365 return -ERESTARTSYS; 365 return -ERESTARTSYS;
366 366
367 if (port->serial->disconnected)
368 return -EIO;
369
367 spin_lock_irqsave(&priv->status_lock, flags); 370 spin_lock_irqsave(&priv->status_lock, flags);
368 cur = priv->icount; 371 cur = priv->icount;
369 spin_unlock_irqrestore(&priv->status_lock, flags); 372 spin_unlock_irqrestore(&priv->status_lock, flags);
@@ -445,7 +448,6 @@ static int ssu100_port_probe(struct usb_serial_port *port)
445 return -ENOMEM; 448 return -ENOMEM;
446 449
447 spin_lock_init(&priv->status_lock); 450 spin_lock_init(&priv->status_lock);
448 init_waitqueue_head(&priv->delta_msr_wait);
449 451
450 usb_set_serial_port_data(port, priv); 452 usb_set_serial_port_data(port, priv);
451 453
@@ -537,7 +539,7 @@ static void ssu100_update_msr(struct usb_serial_port *port, u8 msr)
537 priv->icount.dcd++; 539 priv->icount.dcd++;
538 if (msr & UART_MSR_TERI) 540 if (msr & UART_MSR_TERI)
539 priv->icount.rng++; 541 priv->icount.rng++;
540 wake_up_interruptible(&priv->delta_msr_wait); 542 wake_up_interruptible(&port->delta_msr_wait);
541 } 543 }
542} 544}
543 545
diff --git a/drivers/usb/serial/ti_usb_3410_5052.c b/drivers/usb/serial/ti_usb_3410_5052.c
index 437f2d579cde..19a71a9eecf0 100644
--- a/drivers/usb/serial/ti_usb_3410_5052.c
+++ b/drivers/usb/serial/ti_usb_3410_5052.c
@@ -74,7 +74,6 @@ struct ti_port {
74 int tp_flags; 74 int tp_flags;
75 int tp_closing_wait;/* in .01 secs */ 75 int tp_closing_wait;/* in .01 secs */
76 struct async_icount tp_icount; 76 struct async_icount tp_icount;
77 wait_queue_head_t tp_msr_wait; /* wait for msr change */
78 wait_queue_head_t tp_write_wait; 77 wait_queue_head_t tp_write_wait;
79 struct ti_device *tp_tdev; 78 struct ti_device *tp_tdev;
80 struct usb_serial_port *tp_port; 79 struct usb_serial_port *tp_port;
@@ -432,7 +431,6 @@ static int ti_port_probe(struct usb_serial_port *port)
432 else 431 else
433 tport->tp_uart_base_addr = TI_UART2_BASE_ADDR; 432 tport->tp_uart_base_addr = TI_UART2_BASE_ADDR;
434 tport->tp_closing_wait = closing_wait; 433 tport->tp_closing_wait = closing_wait;
435 init_waitqueue_head(&tport->tp_msr_wait);
436 init_waitqueue_head(&tport->tp_write_wait); 434 init_waitqueue_head(&tport->tp_write_wait);
437 if (kfifo_alloc(&tport->write_fifo, TI_WRITE_BUF_SIZE, GFP_KERNEL)) { 435 if (kfifo_alloc(&tport->write_fifo, TI_WRITE_BUF_SIZE, GFP_KERNEL)) {
438 kfree(tport); 436 kfree(tport);
@@ -784,9 +782,13 @@ static int ti_ioctl(struct tty_struct *tty,
784 dev_dbg(&port->dev, "%s - TIOCMIWAIT\n", __func__); 782 dev_dbg(&port->dev, "%s - TIOCMIWAIT\n", __func__);
785 cprev = tport->tp_icount; 783 cprev = tport->tp_icount;
786 while (1) { 784 while (1) {
787 interruptible_sleep_on(&tport->tp_msr_wait); 785 interruptible_sleep_on(&port->delta_msr_wait);
788 if (signal_pending(current)) 786 if (signal_pending(current))
789 return -ERESTARTSYS; 787 return -ERESTARTSYS;
788
789 if (port->serial->disconnected)
790 return -EIO;
791
790 cnow = tport->tp_icount; 792 cnow = tport->tp_icount;
791 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr && 793 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
792 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts) 794 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts)
@@ -1389,7 +1391,7 @@ static void ti_handle_new_msr(struct ti_port *tport, __u8 msr)
1389 icount->dcd++; 1391 icount->dcd++;
1390 if (msr & TI_MSR_DELTA_RI) 1392 if (msr & TI_MSR_DELTA_RI)
1391 icount->rng++; 1393 icount->rng++;
1392 wake_up_interruptible(&tport->tp_msr_wait); 1394 wake_up_interruptible(&tport->tp_port->delta_msr_wait);
1393 spin_unlock_irqrestore(&tport->tp_lock, flags); 1395 spin_unlock_irqrestore(&tport->tp_lock, flags);
1394 } 1396 }
1395 1397
diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
index 2df84845bafb..650be17a68f2 100644
--- a/drivers/usb/serial/usb-serial.c
+++ b/drivers/usb/serial/usb-serial.c
@@ -151,6 +151,7 @@ static void destroy_serial(struct kref *kref)
151 } 151 }
152 } 152 }
153 153
154 usb_put_intf(serial->interface);
154 usb_put_dev(serial->dev); 155 usb_put_dev(serial->dev);
155 kfree(serial); 156 kfree(serial);
156} 157}
@@ -612,7 +613,7 @@ static struct usb_serial *create_serial(struct usb_device *dev,
612 } 613 }
613 serial->dev = usb_get_dev(dev); 614 serial->dev = usb_get_dev(dev);
614 serial->type = driver; 615 serial->type = driver;
615 serial->interface = interface; 616 serial->interface = usb_get_intf(interface);
616 kref_init(&serial->kref); 617 kref_init(&serial->kref);
617 mutex_init(&serial->disc_mutex); 618 mutex_init(&serial->disc_mutex);
618 serial->minor = SERIAL_TTY_NO_MINOR; 619 serial->minor = SERIAL_TTY_NO_MINOR;
@@ -894,6 +895,7 @@ static int usb_serial_probe(struct usb_interface *interface,
894 port->port.ops = &serial_port_ops; 895 port->port.ops = &serial_port_ops;
895 port->serial = serial; 896 port->serial = serial;
896 spin_lock_init(&port->lock); 897 spin_lock_init(&port->lock);
898 init_waitqueue_head(&port->delta_msr_wait);
897 /* Keep this for private driver use for the moment but 899 /* Keep this for private driver use for the moment but
898 should probably go away */ 900 should probably go away */
899 INIT_WORK(&port->work, usb_serial_port_work); 901 INIT_WORK(&port->work, usb_serial_port_work);
diff --git a/drivers/usb/storage/unusual_devs.h b/drivers/usb/storage/unusual_devs.h
index da04a074e790..1799335288bd 100644
--- a/drivers/usb/storage/unusual_devs.h
+++ b/drivers/usb/storage/unusual_devs.h
@@ -496,6 +496,13 @@ UNUSUAL_DEV( 0x04e8, 0x5122, 0x0000, 0x9999,
496 USB_SC_DEVICE, USB_PR_DEVICE, NULL, 496 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
497 US_FL_MAX_SECTORS_64 | US_FL_BULK_IGNORE_TAG), 497 US_FL_MAX_SECTORS_64 | US_FL_BULK_IGNORE_TAG),
498 498
499/* Added by Dmitry Artamonow <mad_soft@inbox.ru> */
500UNUSUAL_DEV( 0x04e8, 0x5136, 0x0000, 0x9999,
501 "Samsung",
502 "YP-Z3",
503 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
504 US_FL_MAX_SECTORS_64),
505
499/* Entry and supporting patch by Theodore Kilgore <kilgota@auburn.edu>. 506/* Entry and supporting patch by Theodore Kilgore <kilgota@auburn.edu>.
500 * Device uses standards-violating 32-byte Bulk Command Block Wrappers and 507 * Device uses standards-violating 32-byte Bulk Command Block Wrappers and
501 * reports itself as "Proprietary SCSI Bulk." Cf. device entry 0x084d:0x0011. 508 * reports itself as "Proprietary SCSI Bulk." Cf. device entry 0x084d:0x0011.
diff --git a/drivers/vfio/pci/vfio_pci_config.c b/drivers/vfio/pci/vfio_pci_config.c
index 964ff22bf281..aeb00fc2d3be 100644
--- a/drivers/vfio/pci/vfio_pci_config.c
+++ b/drivers/vfio/pci/vfio_pci_config.c
@@ -27,6 +27,7 @@
27#include <linux/pci.h> 27#include <linux/pci.h>
28#include <linux/uaccess.h> 28#include <linux/uaccess.h>
29#include <linux/vfio.h> 29#include <linux/vfio.h>
30#include <linux/slab.h>
30 31
31#include "vfio_pci_private.h" 32#include "vfio_pci_private.h"
32 33
diff --git a/drivers/vfio/pci/vfio_pci_intrs.c b/drivers/vfio/pci/vfio_pci_intrs.c
index 3639371fa697..a96509187deb 100644
--- a/drivers/vfio/pci/vfio_pci_intrs.c
+++ b/drivers/vfio/pci/vfio_pci_intrs.c
@@ -22,6 +22,7 @@
22#include <linux/vfio.h> 22#include <linux/vfio.h>
23#include <linux/wait.h> 23#include <linux/wait.h>
24#include <linux/workqueue.h> 24#include <linux/workqueue.h>
25#include <linux/slab.h>
25 26
26#include "vfio_pci_private.h" 27#include "vfio_pci_private.h"
27 28
diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c
index 959b1cd89e6a..ec6fb3fa59bb 100644
--- a/drivers/vhost/net.c
+++ b/drivers/vhost/net.c
@@ -339,7 +339,8 @@ static void handle_tx(struct vhost_net *net)
339 msg.msg_controllen = 0; 339 msg.msg_controllen = 0;
340 ubufs = NULL; 340 ubufs = NULL;
341 } else { 341 } else {
342 struct ubuf_info *ubuf = &vq->ubuf_info[head]; 342 struct ubuf_info *ubuf;
343 ubuf = vq->ubuf_info + vq->upend_idx;
343 344
344 vq->heads[vq->upend_idx].len = 345 vq->heads[vq->upend_idx].len =
345 VHOST_DMA_IN_PROGRESS; 346 VHOST_DMA_IN_PROGRESS;
diff --git a/drivers/vhost/tcm_vhost.c b/drivers/vhost/tcm_vhost.c
index 9951297b2427..2968b4934659 100644
--- a/drivers/vhost/tcm_vhost.c
+++ b/drivers/vhost/tcm_vhost.c
@@ -60,6 +60,15 @@ enum {
60 VHOST_SCSI_VQ_IO = 2, 60 VHOST_SCSI_VQ_IO = 2,
61}; 61};
62 62
63/*
64 * VIRTIO_RING_F_EVENT_IDX seems broken. Not sure the bug is in
65 * kernel but disabling it helps.
66 * TODO: debug and remove the workaround.
67 */
68enum {
69 VHOST_SCSI_FEATURES = VHOST_FEATURES & (~VIRTIO_RING_F_EVENT_IDX)
70};
71
63#define VHOST_SCSI_MAX_TARGET 256 72#define VHOST_SCSI_MAX_TARGET 256
64#define VHOST_SCSI_MAX_VQ 128 73#define VHOST_SCSI_MAX_VQ 128
65 74
@@ -850,7 +859,7 @@ static int vhost_scsi_clear_endpoint(
850 for (index = 0; index < vs->dev.nvqs; ++index) { 859 for (index = 0; index < vs->dev.nvqs; ++index) {
851 if (!vhost_vq_access_ok(&vs->vqs[index])) { 860 if (!vhost_vq_access_ok(&vs->vqs[index])) {
852 ret = -EFAULT; 861 ret = -EFAULT;
853 goto err; 862 goto err_dev;
854 } 863 }
855 } 864 }
856 for (i = 0; i < VHOST_SCSI_MAX_TARGET; i++) { 865 for (i = 0; i < VHOST_SCSI_MAX_TARGET; i++) {
@@ -860,10 +869,11 @@ static int vhost_scsi_clear_endpoint(
860 if (!tv_tpg) 869 if (!tv_tpg)
861 continue; 870 continue;
862 871
872 mutex_lock(&tv_tpg->tv_tpg_mutex);
863 tv_tport = tv_tpg->tport; 873 tv_tport = tv_tpg->tport;
864 if (!tv_tport) { 874 if (!tv_tport) {
865 ret = -ENODEV; 875 ret = -ENODEV;
866 goto err; 876 goto err_tpg;
867 } 877 }
868 878
869 if (strcmp(tv_tport->tport_name, t->vhost_wwpn)) { 879 if (strcmp(tv_tport->tport_name, t->vhost_wwpn)) {
@@ -872,16 +882,19 @@ static int vhost_scsi_clear_endpoint(
872 tv_tport->tport_name, tv_tpg->tport_tpgt, 882 tv_tport->tport_name, tv_tpg->tport_tpgt,
873 t->vhost_wwpn, t->vhost_tpgt); 883 t->vhost_wwpn, t->vhost_tpgt);
874 ret = -EINVAL; 884 ret = -EINVAL;
875 goto err; 885 goto err_tpg;
876 } 886 }
877 tv_tpg->tv_tpg_vhost_count--; 887 tv_tpg->tv_tpg_vhost_count--;
878 vs->vs_tpg[target] = NULL; 888 vs->vs_tpg[target] = NULL;
879 vs->vs_endpoint = false; 889 vs->vs_endpoint = false;
890 mutex_unlock(&tv_tpg->tv_tpg_mutex);
880 } 891 }
881 mutex_unlock(&vs->dev.mutex); 892 mutex_unlock(&vs->dev.mutex);
882 return 0; 893 return 0;
883 894
884err: 895err_tpg:
896 mutex_unlock(&tv_tpg->tv_tpg_mutex);
897err_dev:
885 mutex_unlock(&vs->dev.mutex); 898 mutex_unlock(&vs->dev.mutex);
886 return ret; 899 return ret;
887} 900}
@@ -937,11 +950,12 @@ static void vhost_scsi_flush(struct vhost_scsi *vs)
937 950
938 for (i = 0; i < VHOST_SCSI_MAX_VQ; i++) 951 for (i = 0; i < VHOST_SCSI_MAX_VQ; i++)
939 vhost_scsi_flush_vq(vs, i); 952 vhost_scsi_flush_vq(vs, i);
953 vhost_work_flush(&vs->dev, &vs->vs_completion_work);
940} 954}
941 955
942static int vhost_scsi_set_features(struct vhost_scsi *vs, u64 features) 956static int vhost_scsi_set_features(struct vhost_scsi *vs, u64 features)
943{ 957{
944 if (features & ~VHOST_FEATURES) 958 if (features & ~VHOST_SCSI_FEATURES)
945 return -EOPNOTSUPP; 959 return -EOPNOTSUPP;
946 960
947 mutex_lock(&vs->dev.mutex); 961 mutex_lock(&vs->dev.mutex);
@@ -987,7 +1001,7 @@ static long vhost_scsi_ioctl(struct file *f, unsigned int ioctl,
987 return -EFAULT; 1001 return -EFAULT;
988 return 0; 1002 return 0;
989 case VHOST_GET_FEATURES: 1003 case VHOST_GET_FEATURES:
990 features = VHOST_FEATURES; 1004 features = VHOST_SCSI_FEATURES;
991 if (copy_to_user(featurep, &features, sizeof features)) 1005 if (copy_to_user(featurep, &features, sizeof features))
992 return -EFAULT; 1006 return -EFAULT;
993 return 0; 1007 return 0;
diff --git a/drivers/video/atmel_lcdfb.c b/drivers/video/atmel_lcdfb.c
index 12cf5f31ee8f..025428e04c33 100644
--- a/drivers/video/atmel_lcdfb.c
+++ b/drivers/video/atmel_lcdfb.c
@@ -422,17 +422,22 @@ static int atmel_lcdfb_check_var(struct fb_var_screeninfo *var,
422 = var->bits_per_pixel; 422 = var->bits_per_pixel;
423 break; 423 break;
424 case 16: 424 case 16:
425 /* Older SOCs use IBGR:555 rather than BGR:565. */
426 if (sinfo->have_intensity_bit)
427 var->green.length = 5;
428 else
429 var->green.length = 6;
430
425 if (sinfo->lcd_wiring_mode == ATMEL_LCDC_WIRING_RGB) { 431 if (sinfo->lcd_wiring_mode == ATMEL_LCDC_WIRING_RGB) {
426 /* RGB:565 mode */ 432 /* RGB:5X5 mode */
427 var->red.offset = 11; 433 var->red.offset = var->green.length + 5;
428 var->blue.offset = 0; 434 var->blue.offset = 0;
429 } else { 435 } else {
430 /* BGR:565 mode */ 436 /* BGR:5X5 mode */
431 var->red.offset = 0; 437 var->red.offset = 0;
432 var->blue.offset = 11; 438 var->blue.offset = var->green.length + 5;
433 } 439 }
434 var->green.offset = 5; 440 var->green.offset = 5;
435 var->green.length = 6;
436 var->red.length = var->blue.length = 5; 441 var->red.length = var->blue.length = 5;
437 break; 442 break;
438 case 32: 443 case 32:
@@ -679,8 +684,7 @@ static int atmel_lcdfb_setcolreg(unsigned int regno, unsigned int red,
679 684
680 case FB_VISUAL_PSEUDOCOLOR: 685 case FB_VISUAL_PSEUDOCOLOR:
681 if (regno < 256) { 686 if (regno < 256) {
682 if (cpu_is_at91sam9261() || cpu_is_at91sam9263() 687 if (sinfo->have_intensity_bit) {
683 || cpu_is_at91sam9rl()) {
684 /* old style I+BGR:555 */ 688 /* old style I+BGR:555 */
685 val = ((red >> 11) & 0x001f); 689 val = ((red >> 11) & 0x001f);
686 val |= ((green >> 6) & 0x03e0); 690 val |= ((green >> 6) & 0x03e0);
@@ -870,6 +874,10 @@ static int __init atmel_lcdfb_probe(struct platform_device *pdev)
870 } 874 }
871 sinfo->info = info; 875 sinfo->info = info;
872 sinfo->pdev = pdev; 876 sinfo->pdev = pdev;
877 if (cpu_is_at91sam9261() || cpu_is_at91sam9263() ||
878 cpu_is_at91sam9rl()) {
879 sinfo->have_intensity_bit = true;
880 }
873 881
874 strcpy(info->fix.id, sinfo->pdev->name); 882 strcpy(info->fix.id, sinfo->pdev->name);
875 info->flags = ATMEL_LCDFB_FBINFO_DEFAULT; 883 info->flags = ATMEL_LCDFB_FBINFO_DEFAULT;
diff --git a/drivers/video/ep93xx-fb.c b/drivers/video/ep93xx-fb.c
index 3f2519d30715..e06cd5d90c97 100644
--- a/drivers/video/ep93xx-fb.c
+++ b/drivers/video/ep93xx-fb.c
@@ -23,6 +23,7 @@
23#include <linux/slab.h> 23#include <linux/slab.h>
24#include <linux/clk.h> 24#include <linux/clk.h>
25#include <linux/fb.h> 25#include <linux/fb.h>
26#include <linux/io.h>
26 27
27#include <linux/platform_data/video-ep93xx.h> 28#include <linux/platform_data/video-ep93xx.h>
28 29
diff --git a/drivers/video/mxsfb.c b/drivers/video/mxsfb.c
index 755556ca5b2d..45169cbaba6e 100644
--- a/drivers/video/mxsfb.c
+++ b/drivers/video/mxsfb.c
@@ -169,6 +169,7 @@ struct mxsfb_info {
169 unsigned dotclk_delay; 169 unsigned dotclk_delay;
170 const struct mxsfb_devdata *devdata; 170 const struct mxsfb_devdata *devdata;
171 int mapped; 171 int mapped;
172 u32 sync;
172}; 173};
173 174
174#define mxsfb_is_v3(host) (host->devdata->ipversion == 3) 175#define mxsfb_is_v3(host) (host->devdata->ipversion == 3)
@@ -456,9 +457,9 @@ static int mxsfb_set_par(struct fb_info *fb_info)
456 vdctrl0 |= VDCTRL0_HSYNC_ACT_HIGH; 457 vdctrl0 |= VDCTRL0_HSYNC_ACT_HIGH;
457 if (fb_info->var.sync & FB_SYNC_VERT_HIGH_ACT) 458 if (fb_info->var.sync & FB_SYNC_VERT_HIGH_ACT)
458 vdctrl0 |= VDCTRL0_VSYNC_ACT_HIGH; 459 vdctrl0 |= VDCTRL0_VSYNC_ACT_HIGH;
459 if (fb_info->var.sync & FB_SYNC_DATA_ENABLE_HIGH_ACT) 460 if (host->sync & MXSFB_SYNC_DATA_ENABLE_HIGH_ACT)
460 vdctrl0 |= VDCTRL0_ENABLE_ACT_HIGH; 461 vdctrl0 |= VDCTRL0_ENABLE_ACT_HIGH;
461 if (fb_info->var.sync & FB_SYNC_DOTCLK_FAILING_ACT) 462 if (host->sync & MXSFB_SYNC_DOTCLK_FAILING_ACT)
462 vdctrl0 |= VDCTRL0_DOTCLK_ACT_FAILING; 463 vdctrl0 |= VDCTRL0_DOTCLK_ACT_FAILING;
463 464
464 writel(vdctrl0, host->base + LCDC_VDCTRL0); 465 writel(vdctrl0, host->base + LCDC_VDCTRL0);
@@ -861,6 +862,8 @@ static int mxsfb_probe(struct platform_device *pdev)
861 862
862 INIT_LIST_HEAD(&fb_info->modelist); 863 INIT_LIST_HEAD(&fb_info->modelist);
863 864
865 host->sync = pdata->sync;
866
864 ret = mxsfb_init_fbinfo(host); 867 ret = mxsfb_init_fbinfo(host);
865 if (ret != 0) 868 if (ret != 0)
866 goto error_init_fb; 869 goto error_init_fb;
diff --git a/drivers/video/omap/omapfb_main.c b/drivers/video/omap/omapfb_main.c
index e31f5b33b501..d40612c31a98 100644
--- a/drivers/video/omap/omapfb_main.c
+++ b/drivers/video/omap/omapfb_main.c
@@ -32,6 +32,8 @@
32 32
33#include <linux/omap-dma.h> 33#include <linux/omap-dma.h>
34 34
35#include <mach/hardware.h>
36
35#include "omapfb.h" 37#include "omapfb.h"
36#include "lcdc.h" 38#include "lcdc.h"
37 39
diff --git a/drivers/video/omap2/displays/panel-tpo-td043mtea1.c b/drivers/video/omap2/displays/panel-tpo-td043mtea1.c
index 6b6643911d29..048c98381ef6 100644
--- a/drivers/video/omap2/displays/panel-tpo-td043mtea1.c
+++ b/drivers/video/omap2/displays/panel-tpo-td043mtea1.c
@@ -63,6 +63,9 @@ struct tpo_td043_device {
63 u32 power_on_resume:1; 63 u32 power_on_resume:1;
64}; 64};
65 65
66/* used to pass spi_device from SPI to DSS portion of the driver */
67static struct tpo_td043_device *g_tpo_td043;
68
66static int tpo_td043_write(struct spi_device *spi, u8 addr, u8 data) 69static int tpo_td043_write(struct spi_device *spi, u8 addr, u8 data)
67{ 70{
68 struct spi_message m; 71 struct spi_message m;
@@ -403,7 +406,7 @@ static void tpo_td043_disable(struct omap_dss_device *dssdev)
403 406
404static int tpo_td043_probe(struct omap_dss_device *dssdev) 407static int tpo_td043_probe(struct omap_dss_device *dssdev)
405{ 408{
406 struct tpo_td043_device *tpo_td043 = dev_get_drvdata(&dssdev->dev); 409 struct tpo_td043_device *tpo_td043 = g_tpo_td043;
407 int nreset_gpio = dssdev->reset_gpio; 410 int nreset_gpio = dssdev->reset_gpio;
408 int ret = 0; 411 int ret = 0;
409 412
@@ -440,6 +443,8 @@ static int tpo_td043_probe(struct omap_dss_device *dssdev)
440 if (ret) 443 if (ret)
441 dev_warn(&dssdev->dev, "failed to create sysfs files\n"); 444 dev_warn(&dssdev->dev, "failed to create sysfs files\n");
442 445
446 dev_set_drvdata(&dssdev->dev, tpo_td043);
447
443 return 0; 448 return 0;
444 449
445fail_gpio_req: 450fail_gpio_req:
@@ -505,6 +510,9 @@ static int tpo_td043_spi_probe(struct spi_device *spi)
505 return -ENODEV; 510 return -ENODEV;
506 } 511 }
507 512
513 if (g_tpo_td043 != NULL)
514 return -EBUSY;
515
508 spi->bits_per_word = 16; 516 spi->bits_per_word = 16;
509 spi->mode = SPI_MODE_0; 517 spi->mode = SPI_MODE_0;
510 518
@@ -521,7 +529,7 @@ static int tpo_td043_spi_probe(struct spi_device *spi)
521 tpo_td043->spi = spi; 529 tpo_td043->spi = spi;
522 tpo_td043->nreset_gpio = dssdev->reset_gpio; 530 tpo_td043->nreset_gpio = dssdev->reset_gpio;
523 dev_set_drvdata(&spi->dev, tpo_td043); 531 dev_set_drvdata(&spi->dev, tpo_td043);
524 dev_set_drvdata(&dssdev->dev, tpo_td043); 532 g_tpo_td043 = tpo_td043;
525 533
526 omap_dss_register_driver(&tpo_td043_driver); 534 omap_dss_register_driver(&tpo_td043_driver);
527 535
@@ -534,6 +542,7 @@ static int tpo_td043_spi_remove(struct spi_device *spi)
534 542
535 omap_dss_unregister_driver(&tpo_td043_driver); 543 omap_dss_unregister_driver(&tpo_td043_driver);
536 kfree(tpo_td043); 544 kfree(tpo_td043);
545 g_tpo_td043 = NULL;
537 546
538 return 0; 547 return 0;
539} 548}
diff --git a/drivers/video/omap2/dss/dss_features.c b/drivers/video/omap2/dss/dss_features.c
index d7d66ef5cb58..7f791aeda4d2 100644
--- a/drivers/video/omap2/dss/dss_features.c
+++ b/drivers/video/omap2/dss/dss_features.c
@@ -202,12 +202,10 @@ static const enum omap_dss_output_id omap3630_dss_supported_outputs[] = {
202 202
203static const enum omap_dss_output_id omap4_dss_supported_outputs[] = { 203static const enum omap_dss_output_id omap4_dss_supported_outputs[] = {
204 /* OMAP_DSS_CHANNEL_LCD */ 204 /* OMAP_DSS_CHANNEL_LCD */
205 OMAP_DSS_OUTPUT_DPI | OMAP_DSS_OUTPUT_DBI | 205 OMAP_DSS_OUTPUT_DBI | OMAP_DSS_OUTPUT_DSI1,
206 OMAP_DSS_OUTPUT_DSI1,
207 206
208 /* OMAP_DSS_CHANNEL_DIGIT */ 207 /* OMAP_DSS_CHANNEL_DIGIT */
209 OMAP_DSS_OUTPUT_VENC | OMAP_DSS_OUTPUT_HDMI | 208 OMAP_DSS_OUTPUT_VENC | OMAP_DSS_OUTPUT_HDMI,
210 OMAP_DSS_OUTPUT_DPI,
211 209
212 /* OMAP_DSS_CHANNEL_LCD2 */ 210 /* OMAP_DSS_CHANNEL_LCD2 */
213 OMAP_DSS_OUTPUT_DPI | OMAP_DSS_OUTPUT_DBI | 211 OMAP_DSS_OUTPUT_DPI | OMAP_DSS_OUTPUT_DBI |
diff --git a/drivers/watchdog/sp5100_tco.c b/drivers/watchdog/sp5100_tco.c
index e3b8f757d2d3..0e9d8c479c35 100644
--- a/drivers/watchdog/sp5100_tco.c
+++ b/drivers/watchdog/sp5100_tco.c
@@ -40,13 +40,12 @@
40#include "sp5100_tco.h" 40#include "sp5100_tco.h"
41 41
42/* Module and version information */ 42/* Module and version information */
43#define TCO_VERSION "0.03" 43#define TCO_VERSION "0.05"
44#define TCO_MODULE_NAME "SP5100 TCO timer" 44#define TCO_MODULE_NAME "SP5100 TCO timer"
45#define TCO_DRIVER_NAME TCO_MODULE_NAME ", v" TCO_VERSION 45#define TCO_DRIVER_NAME TCO_MODULE_NAME ", v" TCO_VERSION
46 46
47/* internal variables */ 47/* internal variables */
48static u32 tcobase_phys; 48static u32 tcobase_phys;
49static u32 resbase_phys;
50static u32 tco_wdt_fired; 49static u32 tco_wdt_fired;
51static void __iomem *tcobase; 50static void __iomem *tcobase;
52static unsigned int pm_iobase; 51static unsigned int pm_iobase;
@@ -54,10 +53,6 @@ static DEFINE_SPINLOCK(tco_lock); /* Guards the hardware */
54static unsigned long timer_alive; 53static unsigned long timer_alive;
55static char tco_expect_close; 54static char tco_expect_close;
56static struct pci_dev *sp5100_tco_pci; 55static struct pci_dev *sp5100_tco_pci;
57static struct resource wdt_res = {
58 .name = "Watchdog Timer",
59 .flags = IORESOURCE_MEM,
60};
61 56
62/* the watchdog platform device */ 57/* the watchdog platform device */
63static struct platform_device *sp5100_tco_platform_device; 58static struct platform_device *sp5100_tco_platform_device;
@@ -75,12 +70,6 @@ module_param(nowayout, bool, 0);
75MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started." 70MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started."
76 " (default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); 71 " (default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
77 72
78static unsigned int force_addr;
79module_param(force_addr, uint, 0);
80MODULE_PARM_DESC(force_addr, "Force the use of specified MMIO address."
81 " ONLY USE THIS PARAMETER IF YOU REALLY KNOW"
82 " WHAT YOU ARE DOING (default=none)");
83
84/* 73/*
85 * Some TCO specific functions 74 * Some TCO specific functions
86 */ 75 */
@@ -176,39 +165,6 @@ static void tco_timer_enable(void)
176 } 165 }
177} 166}
178 167
179static void tco_timer_disable(void)
180{
181 int val;
182
183 if (sp5100_tco_pci->revision >= 0x40) {
184 /* For SB800 or later */
185 /* Enable watchdog decode bit and Disable watchdog timer */
186 outb(SB800_PM_WATCHDOG_CONTROL, SB800_IO_PM_INDEX_REG);
187 val = inb(SB800_IO_PM_DATA_REG);
188 val |= SB800_PCI_WATCHDOG_DECODE_EN;
189 val |= SB800_PM_WATCHDOG_DISABLE;
190 outb(val, SB800_IO_PM_DATA_REG);
191 } else {
192 /* For SP5100 or SB7x0 */
193 /* Enable watchdog decode bit */
194 pci_read_config_dword(sp5100_tco_pci,
195 SP5100_PCI_WATCHDOG_MISC_REG,
196 &val);
197
198 val |= SP5100_PCI_WATCHDOG_DECODE_EN;
199
200 pci_write_config_dword(sp5100_tco_pci,
201 SP5100_PCI_WATCHDOG_MISC_REG,
202 val);
203
204 /* Disable Watchdog timer */
205 outb(SP5100_PM_WATCHDOG_CONTROL, SP5100_IO_PM_INDEX_REG);
206 val = inb(SP5100_IO_PM_DATA_REG);
207 val |= SP5100_PM_WATCHDOG_DISABLE;
208 outb(val, SP5100_IO_PM_DATA_REG);
209 }
210}
211
212/* 168/*
213 * /dev/watchdog handling 169 * /dev/watchdog handling
214 */ 170 */
@@ -361,7 +317,7 @@ static unsigned char sp5100_tco_setupdevice(void)
361{ 317{
362 struct pci_dev *dev = NULL; 318 struct pci_dev *dev = NULL;
363 const char *dev_name = NULL; 319 const char *dev_name = NULL;
364 u32 val, tmp_val; 320 u32 val;
365 u32 index_reg, data_reg, base_addr; 321 u32 index_reg, data_reg, base_addr;
366 322
367 /* Match the PCI device */ 323 /* Match the PCI device */
@@ -459,63 +415,8 @@ static unsigned char sp5100_tco_setupdevice(void)
459 } else 415 } else
460 pr_debug("SBResource_MMIO is disabled(0x%04x)\n", val); 416 pr_debug("SBResource_MMIO is disabled(0x%04x)\n", val);
461 417
462 /* 418 pr_notice("failed to find MMIO address, giving up.\n");
463 * Lastly re-programming the watchdog timer MMIO address, 419 goto unreg_region;
464 * This method is a last resort...
465 *
466 * Before re-programming, to ensure that the watchdog timer
467 * is disabled, disable the watchdog timer.
468 */
469 tco_timer_disable();
470
471 if (force_addr) {
472 /*
473 * Force the use of watchdog timer MMIO address, and aligned to
474 * 8byte boundary.
475 */
476 force_addr &= ~0x7;
477 val = force_addr;
478
479 pr_info("Force the use of 0x%04x as MMIO address\n", val);
480 } else {
481 /*
482 * Get empty slot into the resource tree for watchdog timer.
483 */
484 if (allocate_resource(&iomem_resource,
485 &wdt_res,
486 SP5100_WDT_MEM_MAP_SIZE,
487 0xf0000000,
488 0xfffffff8,
489 0x8,
490 NULL,
491 NULL)) {
492 pr_err("MMIO allocation failed\n");
493 goto unreg_region;
494 }
495
496 val = resbase_phys = wdt_res.start;
497 pr_debug("Got 0x%04x from resource tree\n", val);
498 }
499
500 /* Restore to the low three bits */
501 outb(base_addr+0, index_reg);
502 tmp_val = val | (inb(data_reg) & 0x7);
503
504 /* Re-programming the watchdog timer base address */
505 outb(base_addr+0, index_reg);
506 outb((tmp_val >> 0) & 0xff, data_reg);
507 outb(base_addr+1, index_reg);
508 outb((tmp_val >> 8) & 0xff, data_reg);
509 outb(base_addr+2, index_reg);
510 outb((tmp_val >> 16) & 0xff, data_reg);
511 outb(base_addr+3, index_reg);
512 outb((tmp_val >> 24) & 0xff, data_reg);
513
514 if (!request_mem_region_exclusive(val, SP5100_WDT_MEM_MAP_SIZE,
515 dev_name)) {
516 pr_err("MMIO address 0x%04x already in use\n", val);
517 goto unreg_resource;
518 }
519 420
520setup_wdt: 421setup_wdt:
521 tcobase_phys = val; 422 tcobase_phys = val;
@@ -555,9 +456,6 @@ setup_wdt:
555 456
556unreg_mem_region: 457unreg_mem_region:
557 release_mem_region(tcobase_phys, SP5100_WDT_MEM_MAP_SIZE); 458 release_mem_region(tcobase_phys, SP5100_WDT_MEM_MAP_SIZE);
558unreg_resource:
559 if (resbase_phys)
560 release_resource(&wdt_res);
561unreg_region: 459unreg_region:
562 release_region(pm_iobase, SP5100_PM_IOPORTS_SIZE); 460 release_region(pm_iobase, SP5100_PM_IOPORTS_SIZE);
563exit: 461exit:
@@ -567,7 +465,6 @@ exit:
567static int sp5100_tco_init(struct platform_device *dev) 465static int sp5100_tco_init(struct platform_device *dev)
568{ 466{
569 int ret; 467 int ret;
570 char addr_str[16];
571 468
572 /* 469 /*
573 * Check whether or not the hardware watchdog is there. If found, then 470 * Check whether or not the hardware watchdog is there. If found, then
@@ -599,23 +496,14 @@ static int sp5100_tco_init(struct platform_device *dev)
599 clear_bit(0, &timer_alive); 496 clear_bit(0, &timer_alive);
600 497
601 /* Show module parameters */ 498 /* Show module parameters */
602 if (force_addr == tcobase_phys) 499 pr_info("initialized (0x%p). heartbeat=%d sec (nowayout=%d)\n",
603 /* The force_addr is vaild */ 500 tcobase, heartbeat, nowayout);
604 sprintf(addr_str, "0x%04x", force_addr);
605 else
606 strcpy(addr_str, "none");
607
608 pr_info("initialized (0x%p). heartbeat=%d sec (nowayout=%d, "
609 "force_addr=%s)\n",
610 tcobase, heartbeat, nowayout, addr_str);
611 501
612 return 0; 502 return 0;
613 503
614exit: 504exit:
615 iounmap(tcobase); 505 iounmap(tcobase);
616 release_mem_region(tcobase_phys, SP5100_WDT_MEM_MAP_SIZE); 506 release_mem_region(tcobase_phys, SP5100_WDT_MEM_MAP_SIZE);
617 if (resbase_phys)
618 release_resource(&wdt_res);
619 release_region(pm_iobase, SP5100_PM_IOPORTS_SIZE); 507 release_region(pm_iobase, SP5100_PM_IOPORTS_SIZE);
620 return ret; 508 return ret;
621} 509}
@@ -630,8 +518,6 @@ static void sp5100_tco_cleanup(void)
630 misc_deregister(&sp5100_tco_miscdev); 518 misc_deregister(&sp5100_tco_miscdev);
631 iounmap(tcobase); 519 iounmap(tcobase);
632 release_mem_region(tcobase_phys, SP5100_WDT_MEM_MAP_SIZE); 520 release_mem_region(tcobase_phys, SP5100_WDT_MEM_MAP_SIZE);
633 if (resbase_phys)
634 release_resource(&wdt_res);
635 release_region(pm_iobase, SP5100_PM_IOPORTS_SIZE); 521 release_region(pm_iobase, SP5100_PM_IOPORTS_SIZE);
636} 522}
637 523
diff --git a/drivers/watchdog/sp5100_tco.h b/drivers/watchdog/sp5100_tco.h
index 71594a0c14b7..2b28c00da0df 100644
--- a/drivers/watchdog/sp5100_tco.h
+++ b/drivers/watchdog/sp5100_tco.h
@@ -57,7 +57,7 @@
57#define SB800_PM_WATCHDOG_DISABLE (1 << 2) 57#define SB800_PM_WATCHDOG_DISABLE (1 << 2)
58#define SB800_PM_WATCHDOG_SECOND_RES (3 << 0) 58#define SB800_PM_WATCHDOG_SECOND_RES (3 << 0)
59#define SB800_ACPI_MMIO_DECODE_EN (1 << 0) 59#define SB800_ACPI_MMIO_DECODE_EN (1 << 0)
60#define SB800_ACPI_MMIO_SEL (1 << 2) 60#define SB800_ACPI_MMIO_SEL (1 << 1)
61 61
62 62
63#define SB800_PM_WDT_MMIO_OFFSET 0xB00 63#define SB800_PM_WDT_MMIO_OFFSET 0xB00
diff --git a/drivers/xen/Kconfig b/drivers/xen/Kconfig
index 5a32232cf7c1..67af155cf602 100644
--- a/drivers/xen/Kconfig
+++ b/drivers/xen/Kconfig
@@ -182,7 +182,7 @@ config XEN_PRIVCMD
182 182
183config XEN_STUB 183config XEN_STUB
184 bool "Xen stub drivers" 184 bool "Xen stub drivers"
185 depends on XEN && X86_64 185 depends on XEN && X86_64 && BROKEN
186 default n 186 default n
187 help 187 help
188 Allow kernel to install stub drivers, to reserve space for Xen drivers, 188 Allow kernel to install stub drivers, to reserve space for Xen drivers,
diff --git a/drivers/xen/events.c b/drivers/xen/events.c
index d17aa41a9041..aa85881d17b2 100644
--- a/drivers/xen/events.c
+++ b/drivers/xen/events.c
@@ -403,11 +403,23 @@ static void unmask_evtchn(int port)
403 403
404 if (unlikely((cpu != cpu_from_evtchn(port)))) 404 if (unlikely((cpu != cpu_from_evtchn(port))))
405 do_hypercall = 1; 405 do_hypercall = 1;
406 else 406 else {
407 /*
408 * Need to clear the mask before checking pending to
409 * avoid a race with an event becoming pending.
410 *
411 * EVTCHNOP_unmask will only trigger an upcall if the
412 * mask bit was set, so if a hypercall is needed
413 * remask the event.
414 */
415 sync_clear_bit(port, BM(&s->evtchn_mask[0]));
407 evtchn_pending = sync_test_bit(port, BM(&s->evtchn_pending[0])); 416 evtchn_pending = sync_test_bit(port, BM(&s->evtchn_pending[0]));
408 417
409 if (unlikely(evtchn_pending && xen_hvm_domain())) 418 if (unlikely(evtchn_pending && xen_hvm_domain())) {
410 do_hypercall = 1; 419 sync_set_bit(port, BM(&s->evtchn_mask[0]));
420 do_hypercall = 1;
421 }
422 }
411 423
412 /* Slow path (hypercall) if this is a non-local port or if this is 424 /* Slow path (hypercall) if this is a non-local port or if this is
413 * an hvm domain and an event is pending (hvm domains don't have 425 * an hvm domain and an event is pending (hvm domains don't have
@@ -418,8 +430,6 @@ static void unmask_evtchn(int port)
418 } else { 430 } else {
419 struct vcpu_info *vcpu_info = __this_cpu_read(xen_vcpu); 431 struct vcpu_info *vcpu_info = __this_cpu_read(xen_vcpu);
420 432
421 sync_clear_bit(port, BM(&s->evtchn_mask[0]));
422
423 /* 433 /*
424 * The following is basically the equivalent of 434 * The following is basically the equivalent of
425 * 'hw_resend_irq'. Just like a real IO-APIC we 'lose 435 * 'hw_resend_irq'. Just like a real IO-APIC we 'lose
diff --git a/drivers/xen/fallback.c b/drivers/xen/fallback.c
index 0ef7c4d40f86..b04fb64c5a91 100644
--- a/drivers/xen/fallback.c
+++ b/drivers/xen/fallback.c
@@ -44,7 +44,7 @@ int xen_event_channel_op_compat(int cmd, void *arg)
44} 44}
45EXPORT_SYMBOL_GPL(xen_event_channel_op_compat); 45EXPORT_SYMBOL_GPL(xen_event_channel_op_compat);
46 46
47int HYPERVISOR_physdev_op_compat(int cmd, void *arg) 47int xen_physdev_op_compat(int cmd, void *arg)
48{ 48{
49 struct physdev_op op; 49 struct physdev_op op;
50 int rc; 50 int rc;
@@ -78,3 +78,4 @@ int HYPERVISOR_physdev_op_compat(int cmd, void *arg)
78 78
79 return rc; 79 return rc;
80} 80}
81EXPORT_SYMBOL_GPL(xen_physdev_op_compat);
diff --git a/drivers/xen/xen-acpi-processor.c b/drivers/xen/xen-acpi-processor.c
index f3278a6603ca..90e34ac7e522 100644
--- a/drivers/xen/xen-acpi-processor.c
+++ b/drivers/xen/xen-acpi-processor.c
@@ -505,6 +505,9 @@ static int __init xen_acpi_processor_init(void)
505 505
506 pr = per_cpu(processors, i); 506 pr = per_cpu(processors, i);
507 perf = per_cpu_ptr(acpi_perf_data, i); 507 perf = per_cpu_ptr(acpi_perf_data, i);
508 if (!pr)
509 continue;
510
508 pr->performance = perf; 511 pr->performance = perf;
509 rc = acpi_processor_get_performance_info(pr); 512 rc = acpi_processor_get_performance_info(pr);
510 if (rc) 513 if (rc)
diff --git a/drivers/xen/xen-pciback/pci_stub.c b/drivers/xen/xen-pciback/pci_stub.c
index 9204126f1560..a2278ba7fb27 100644
--- a/drivers/xen/xen-pciback/pci_stub.c
+++ b/drivers/xen/xen-pciback/pci_stub.c
@@ -17,6 +17,7 @@
17#include <xen/events.h> 17#include <xen/events.h>
18#include <asm/xen/pci.h> 18#include <asm/xen/pci.h>
19#include <asm/xen/hypervisor.h> 19#include <asm/xen/hypervisor.h>
20#include <xen/interface/physdev.h>
20#include "pciback.h" 21#include "pciback.h"
21#include "conf_space.h" 22#include "conf_space.h"
22#include "conf_space_quirks.h" 23#include "conf_space_quirks.h"
@@ -85,37 +86,52 @@ static struct pcistub_device *pcistub_device_alloc(struct pci_dev *dev)
85static void pcistub_device_release(struct kref *kref) 86static void pcistub_device_release(struct kref *kref)
86{ 87{
87 struct pcistub_device *psdev; 88 struct pcistub_device *psdev;
89 struct pci_dev *dev;
88 struct xen_pcibk_dev_data *dev_data; 90 struct xen_pcibk_dev_data *dev_data;
89 91
90 psdev = container_of(kref, struct pcistub_device, kref); 92 psdev = container_of(kref, struct pcistub_device, kref);
91 dev_data = pci_get_drvdata(psdev->dev); 93 dev = psdev->dev;
94 dev_data = pci_get_drvdata(dev);
92 95
93 dev_dbg(&psdev->dev->dev, "pcistub_device_release\n"); 96 dev_dbg(&dev->dev, "pcistub_device_release\n");
94 97
95 xen_unregister_device_domain_owner(psdev->dev); 98 xen_unregister_device_domain_owner(dev);
96 99
97 /* Call the reset function which does not take lock as this 100 /* Call the reset function which does not take lock as this
98 * is called from "unbind" which takes a device_lock mutex. 101 * is called from "unbind" which takes a device_lock mutex.
99 */ 102 */
100 __pci_reset_function_locked(psdev->dev); 103 __pci_reset_function_locked(dev);
101 if (pci_load_and_free_saved_state(psdev->dev, 104 if (pci_load_and_free_saved_state(dev, &dev_data->pci_saved_state))
102 &dev_data->pci_saved_state)) { 105 dev_dbg(&dev->dev, "Could not reload PCI state\n");
103 dev_dbg(&psdev->dev->dev, "Could not reload PCI state\n"); 106 else
104 } else 107 pci_restore_state(dev);
105 pci_restore_state(psdev->dev); 108
109 if (pci_find_capability(dev, PCI_CAP_ID_MSIX)) {
110 struct physdev_pci_device ppdev = {
111 .seg = pci_domain_nr(dev->bus),
112 .bus = dev->bus->number,
113 .devfn = dev->devfn
114 };
115 int err = HYPERVISOR_physdev_op(PHYSDEVOP_release_msix,
116 &ppdev);
117
118 if (err)
119 dev_warn(&dev->dev, "MSI-X release failed (%d)\n",
120 err);
121 }
106 122
107 /* Disable the device */ 123 /* Disable the device */
108 xen_pcibk_reset_device(psdev->dev); 124 xen_pcibk_reset_device(dev);
109 125
110 kfree(dev_data); 126 kfree(dev_data);
111 pci_set_drvdata(psdev->dev, NULL); 127 pci_set_drvdata(dev, NULL);
112 128
113 /* Clean-up the device */ 129 /* Clean-up the device */
114 xen_pcibk_config_free_dyn_fields(psdev->dev); 130 xen_pcibk_config_free_dyn_fields(dev);
115 xen_pcibk_config_free_dev(psdev->dev); 131 xen_pcibk_config_free_dev(dev);
116 132
117 psdev->dev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED; 133 dev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
118 pci_dev_put(psdev->dev); 134 pci_dev_put(dev);
119 135
120 kfree(psdev); 136 kfree(psdev);
121} 137}
@@ -355,6 +371,19 @@ static int pcistub_init_device(struct pci_dev *dev)
355 if (err) 371 if (err)
356 goto config_release; 372 goto config_release;
357 373
374 if (pci_find_capability(dev, PCI_CAP_ID_MSIX)) {
375 struct physdev_pci_device ppdev = {
376 .seg = pci_domain_nr(dev->bus),
377 .bus = dev->bus->number,
378 .devfn = dev->devfn
379 };
380
381 err = HYPERVISOR_physdev_op(PHYSDEVOP_prepare_msix, &ppdev);
382 if (err)
383 dev_err(&dev->dev, "MSI-X preparation failed (%d)\n",
384 err);
385 }
386
358 /* We need the device active to save the state. */ 387 /* We need the device active to save the state. */
359 dev_dbg(&dev->dev, "save state of device\n"); 388 dev_dbg(&dev->dev, "save state of device\n");
360 pci_save_state(dev); 389 pci_save_state(dev);