aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/acpi/Kconfig18
-rw-r--r--drivers/acpi/Makefile2
-rw-r--r--drivers/acpi/ac.c20
-rw-r--r--drivers/acpi/battery.c24
-rw-r--r--drivers/acpi/dispatcher/dsobject.c91
-rw-r--r--drivers/acpi/ec.c100
-rw-r--r--drivers/acpi/numa.c4
-rw-r--r--drivers/acpi/osl.c25
-rw-r--r--drivers/acpi/pci_bind.c3
-rw-r--r--drivers/acpi/processor_core.c33
-rw-r--r--drivers/acpi/processor_idle.c131
-rw-r--r--drivers/acpi/processor_throttling.c318
-rw-r--r--drivers/acpi/sbs.c70
-rw-r--r--drivers/acpi/sbshc.c17
-rw-r--r--drivers/acpi/sbshc.h6
-rw-r--r--drivers/acpi/tables/tbutils.c2
-rw-r--r--drivers/acpi/video.c159
-rw-r--r--drivers/ata/ahci.c100
-rw-r--r--drivers/ata/ata_piix.c128
-rw-r--r--drivers/ata/libata-acpi.c387
-rw-r--r--drivers/ata/libata-core.c235
-rw-r--r--drivers/ata/libata-eh.c141
-rw-r--r--drivers/ata/libata-scsi.c38
-rw-r--r--drivers/ata/libata.h8
-rw-r--r--drivers/ata/pata_ali.c20
-rw-r--r--drivers/ata/pata_amd.c5
-rw-r--r--drivers/ata/pata_at32.c61
-rw-r--r--drivers/ata/pata_bf54x.c13
-rw-r--r--drivers/ata/pata_hpt37x.c4
-rw-r--r--drivers/ata/pata_isapnp.c11
-rw-r--r--drivers/ata/pata_jmicron.c9
-rw-r--r--drivers/ata/pata_sil680.c32
-rw-r--r--drivers/ata/pata_sis.c1
-rw-r--r--drivers/ata/pata_via.c4
-rw-r--r--drivers/ata/sata_mv.c93
-rw-r--r--drivers/ata/sata_nv.c32
-rw-r--r--drivers/ata/sata_sil.c18
-rw-r--r--drivers/ata/sata_sil24.c26
-rw-r--r--drivers/atm/firestream.c4
-rw-r--r--drivers/atm/fore200e.c3
-rw-r--r--drivers/atm/he.c10
-rw-r--r--drivers/base/core.c4
-rw-r--r--drivers/base/power/Makefile3
-rw-r--r--drivers/base/power/main.c8
-rw-r--r--drivers/base/power/power.h28
-rw-r--r--drivers/block/aoe/aoeblk.c26
-rw-r--r--drivers/block/pktcdvd.c4
-rw-r--r--drivers/block/umem.c240
-rw-r--r--drivers/block/virtio_blk.c10
-rw-r--r--drivers/char/Kconfig24
-rw-r--r--drivers/char/apm-emulation.c15
-rw-r--r--drivers/char/cs5535_gpio.c5
-rw-r--r--drivers/char/ipmi/ipmi_watchdog.c2
-rw-r--r--drivers/char/sonypi.c8
-rw-r--r--drivers/char/tipar.c557
-rw-r--r--drivers/char/tpm/tpm_tis.c10
-rw-r--r--drivers/char/tty_ioctl.c2
-rw-r--r--drivers/cpufreq/cpufreq.c12
-rw-r--r--drivers/cpufreq/cpufreq_stats.c2
-rw-r--r--drivers/crypto/Kconfig2
-rw-r--r--drivers/dma/Kconfig8
-rw-r--r--drivers/dma/ioat_dma.c144
-rw-r--r--drivers/dma/ioatdma.h2
-rw-r--r--drivers/firewire/fw-ohci.c175
-rw-r--r--drivers/hwmon/coretemp.c5
-rw-r--r--drivers/i2c/busses/i2c-davinci.c4
-rw-r--r--drivers/i2c/busses/i2c-gpio.c1
-rw-r--r--drivers/i2c/busses/i2c-omap.c6
-rw-r--r--drivers/i2c/chips/isp1301_omap.c2
-rw-r--r--drivers/ide/Kconfig53
-rw-r--r--drivers/ide/Makefile2
-rw-r--r--drivers/ide/cris/ide-cris.c7
-rw-r--r--drivers/ide/ide-cd.c101
-rw-r--r--drivers/ide/ide-cd.h3
-rw-r--r--drivers/ide/ide-disk.c33
-rw-r--r--drivers/ide/ide-dma.c67
-rw-r--r--drivers/ide/ide-io.c3
-rw-r--r--drivers/ide/ide-iops.c16
-rw-r--r--drivers/ide/ide-lib.c55
-rw-r--r--drivers/ide/ide-probe.c51
-rw-r--r--drivers/ide/ide.c30
-rw-r--r--drivers/ide/legacy/ali14xx.c7
-rw-r--r--drivers/ide/legacy/macide.c2
-rw-r--r--drivers/ide/legacy/q40ide.c2
-rw-r--r--drivers/ide/pci/aec62xx.c11
-rw-r--r--drivers/ide/pci/alim15x3.c5
-rw-r--r--drivers/ide/pci/cmd64x.c4
-rw-r--r--drivers/ide/pci/cs5535.c2
-rw-r--r--drivers/ide/pci/hpt366.c71
-rw-r--r--drivers/ide/pci/pdc202xx_new.c3
-rw-r--r--drivers/ide/pci/piix.c1
-rw-r--r--drivers/ide/pci/siimage.c45
-rw-r--r--drivers/ide/pci/sis5513.c1
-rw-r--r--drivers/ide/pci/trm290.c3
-rw-r--r--drivers/ide/ppc/pmac.c2
-rw-r--r--drivers/ide/setup-pci.c31
-rw-r--r--drivers/infiniband/hw/ehca/ehca_av.c8
-rw-r--r--drivers/infiniband/hw/ehca/ehca_classes.h1
-rw-r--r--drivers/infiniband/hw/ehca/ehca_main.c15
-rw-r--r--drivers/infiniband/hw/ehca/ehca_qp.c8
-rw-r--r--drivers/infiniband/hw/ehca/hcp_if.c27
-rw-r--r--drivers/infiniband/hw/ehca/hipz_hw.h1
-rw-r--r--drivers/infiniband/hw/ipath/ipath_cq.c19
-rw-r--r--drivers/infiniband/hw/ipath/ipath_qp.c15
-rw-r--r--drivers/infiniband/hw/ipath/ipath_srq.c44
-rw-r--r--drivers/infiniband/hw/ipath/ipath_verbs.c8
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_main.c3
-rw-r--r--drivers/infiniband/ulp/iser/iser_memory.c6
-rw-r--r--drivers/input/keyboard/Kconfig2
-rw-r--r--drivers/input/keyboard/gpio_keys.c38
-rw-r--r--drivers/input/serio/Kconfig2
-rw-r--r--drivers/input/serio/i8042-x86ia64io.h8
-rw-r--r--drivers/input/touchscreen/ads7846.c13
-rw-r--r--drivers/isdn/hisax/hfcscard.c3
-rw-r--r--drivers/isdn/i4l/isdn_common.c5
-rw-r--r--drivers/isdn/i4l/isdn_net.c8
-rw-r--r--drivers/kvm/kvm_main.c3
-rw-r--r--drivers/kvm/svm.c1
-rw-r--r--drivers/kvm/x86_emulate.c6
-rw-r--r--drivers/leds/led-class.c6
-rw-r--r--drivers/leds/led-triggers.c49
-rw-r--r--drivers/lguest/lguest_device.c2
-rw-r--r--drivers/macintosh/via-pmu.c1
-rw-r--r--drivers/md/Kconfig2
-rw-r--r--drivers/md/dm-crypt.c31
-rw-r--r--drivers/md/dm-ioctl.c12
-rw-r--r--drivers/md/dm-table.c16
-rw-r--r--drivers/md/dm.c31
-rw-r--r--drivers/md/dm.h7
-rw-r--r--drivers/media/Makefile2
-rw-r--r--drivers/media/common/saa7146_video.c11
-rw-r--r--drivers/media/dvb/dvb-usb/Makefile3
-rw-r--r--drivers/media/dvb/dvb-usb/dibusb-common.c4
-rw-r--r--drivers/media/dvb/frontends/s5h1409.c11
-rw-r--r--drivers/media/dvb/frontends/tda10086.c14
-rw-r--r--drivers/media/dvb/frontends/zl10353.c4
-rw-r--r--drivers/media/dvb/frontends/zl10353.h2
-rw-r--r--drivers/media/video/bt866.c1
-rw-r--r--drivers/media/video/bt8xx/bttv-cards.c2
-rw-r--r--drivers/media/video/bt8xx/bttv-driver.c9
-rw-r--r--drivers/media/video/cx23885/Kconfig1
-rw-r--r--drivers/media/video/cx88/cx88-blackbird.c5
-rw-r--r--drivers/media/video/cx88/cx88-video.c5
-rw-r--r--drivers/media/video/em28xx/em28xx-video.c7
-rw-r--r--drivers/media/video/ivtv/ivtv-i2c.c5
-rw-r--r--drivers/media/video/ivtv/ivtv-i2c.h2
-rw-r--r--drivers/media/video/ivtv/ivtv-streams.c2
-rw-r--r--drivers/media/video/saa5246a.c10
-rw-r--r--drivers/media/video/saa5249.c8
-rw-r--r--drivers/media/video/saa7134/saa7134-alsa.c16
-rw-r--r--drivers/media/video/saa7134/saa7134-cards.c3
-rw-r--r--drivers/media/video/saa7134/saa7134-core.c21
-rw-r--r--drivers/media/video/saa7134/saa7134-dvb.c1
-rw-r--r--drivers/media/video/saa7134/saa7134-empress.c5
-rw-r--r--drivers/media/video/saa7134/saa7134-video.c5
-rw-r--r--drivers/media/video/tvp5150.c11
-rw-r--r--drivers/media/video/videobuf-core.c263
-rw-r--r--drivers/media/video/videobuf-vmalloc.c6
-rw-r--r--drivers/media/video/vivi.c1
-rw-r--r--drivers/mfd/sm501.c2
-rw-r--r--drivers/misc/sony-laptop.c10
-rw-r--r--drivers/misc/thinkpad_acpi.c235
-rw-r--r--drivers/misc/thinkpad_acpi.h4
-rw-r--r--drivers/mmc/card/block.c22
-rw-r--r--drivers/mmc/card/queue.c3
-rw-r--r--drivers/mmc/card/sdio_uart.c2
-rw-r--r--drivers/mmc/host/mmc_spi.c10
-rw-r--r--drivers/mmc/host/sdhci.c63
-rw-r--r--drivers/mmc/host/sdhci.h3
-rw-r--r--drivers/mmc/host/tifm_sd.c18
-rw-r--r--drivers/net/Kconfig4
-rw-r--r--drivers/net/amd8111e.c6
-rw-r--r--drivers/net/bfin_mac.c4
-rw-r--r--drivers/net/bfin_mac.h2
-rw-r--r--drivers/net/bnx2.c35
-rw-r--r--drivers/net/bnx2.h1
-rw-r--r--drivers/net/bonding/bond_main.c116
-rw-r--r--drivers/net/bonding/bond_sysfs.c94
-rw-r--r--drivers/net/bonding/bonding.h4
-rw-r--r--drivers/net/chelsio/cxgb2.c70
-rw-r--r--drivers/net/chelsio/pm3393.c112
-rw-r--r--drivers/net/chelsio/sge.c44
-rw-r--r--drivers/net/chelsio/sge.h3
-rw-r--r--drivers/net/cxgb3/regs.h27
-rw-r--r--drivers/net/cxgb3/t3_hw.c6
-rw-r--r--drivers/net/cxgb3/xgmac.c44
-rw-r--r--drivers/net/dl2k.c51
-rw-r--r--drivers/net/dl2k.h6
-rw-r--r--drivers/net/e100.c11
-rw-r--r--drivers/net/e1000/e1000_ethtool.c2
-rw-r--r--drivers/net/e1000/e1000_main.c2
-rw-r--r--drivers/net/e1000e/ethtool.c2
-rw-r--r--drivers/net/ehea/ehea.h2
-rw-r--r--drivers/net/ehea/ehea_main.c20
-rw-r--r--drivers/net/ehea/ehea_qmr.h4
-rw-r--r--drivers/net/fec_mpc52xx.c11
-rw-r--r--drivers/net/forcedeth.c38
-rw-r--r--drivers/net/fs_enet/mac-scc.c2
-rw-r--r--drivers/net/gianfar.c2
-rw-r--r--drivers/net/hamachi.c70
-rw-r--r--drivers/net/ibm_newemac/core.c87
-rw-r--r--drivers/net/ibm_newemac/core.h12
-rw-r--r--drivers/net/ibm_newemac/debug.c7
-rw-r--r--drivers/net/ibm_newemac/debug.h5
-rw-r--r--drivers/net/ibm_newemac/emac.h5
-rw-r--r--drivers/net/ibm_newemac/mal.c5
-rw-r--r--drivers/net/ibm_newemac/mal.h5
-rw-r--r--drivers/net/ibm_newemac/phy.c81
-rw-r--r--drivers/net/ibm_newemac/phy.h5
-rw-r--r--drivers/net/ibm_newemac/rgmii.c25
-rw-r--r--drivers/net/ibm_newemac/rgmii.h10
-rw-r--r--drivers/net/ibm_newemac/tah.c8
-rw-r--r--drivers/net/ibm_newemac/tah.h5
-rw-r--r--drivers/net/ibm_newemac/zmii.c9
-rw-r--r--drivers/net/ibm_newemac/zmii.h5
-rw-r--r--drivers/net/irda/irda-usb.c5
-rw-r--r--drivers/net/irda/mcs7780.c2
-rw-r--r--drivers/net/irda/stir4200.c10
-rw-r--r--drivers/net/ixgb/ixgb_main.c16
-rw-r--r--drivers/net/lib82596.c50
-rw-r--r--drivers/net/macb.c25
-rw-r--r--drivers/net/mlx4/qp.c2
-rw-r--r--drivers/net/myri10ge/myri10ge.c1
-rw-r--r--drivers/net/niu.c22
-rw-r--r--drivers/net/pasemi_mac.c4
-rw-r--r--drivers/net/pcmcia/3c574_cs.c10
-rw-r--r--drivers/net/pcmcia/3c589_cs.c9
-rw-r--r--drivers/net/pcmcia/pcnet_cs.c1
-rw-r--r--drivers/net/phy/marvell.c26
-rw-r--r--drivers/net/phy/mdio_bus.c9
-rw-r--r--drivers/net/phy/phy.c3
-rw-r--r--drivers/net/phy/phy_device.c12
-rw-r--r--drivers/net/plip.c4
-rw-r--r--drivers/net/r8169.c4
-rw-r--r--drivers/net/rrunner.c49
-rw-r--r--drivers/net/rrunner.h2
-rw-r--r--drivers/net/s2io-regs.h1
-rw-r--r--drivers/net/s2io.c52
-rw-r--r--drivers/net/sis190.c10
-rw-r--r--drivers/net/skge.c108
-rw-r--r--drivers/net/sky2.c136
-rw-r--r--drivers/net/sky2.h21
-rw-r--r--drivers/net/smc911x.c21
-rw-r--r--drivers/net/smc911x.h4
-rw-r--r--drivers/net/smc91x.h2
-rw-r--r--drivers/net/starfire.c2
-rw-r--r--drivers/net/sundance.c34
-rw-r--r--drivers/net/sungem.c11
-rw-r--r--drivers/net/tg3.c98
-rw-r--r--drivers/net/tokenring/3c359.c90
-rw-r--r--drivers/net/tokenring/3c359.h38
-rw-r--r--drivers/net/tulip/dmfe.c4
-rw-r--r--drivers/net/tun.c2
-rw-r--r--drivers/net/typhoon.c45
-rw-r--r--drivers/net/typhoon.h15
-rw-r--r--drivers/net/ucc_geth.c12
-rw-r--r--drivers/net/ucc_geth_mii.h2
-rw-r--r--drivers/net/usb/asix.c235
-rw-r--r--drivers/net/usb/dm9601.c2
-rw-r--r--drivers/net/veth.c2
-rw-r--r--drivers/net/via-velocity.c11
-rw-r--r--drivers/net/virtio_net.c12
-rw-r--r--drivers/net/wan/cycx_x25.c12
-rw-r--r--drivers/net/wan/syncppp.c35
-rw-r--r--drivers/net/wireless/Kconfig52
-rw-r--r--drivers/net/wireless/b43/leds.c4
-rw-r--r--drivers/net/wireless/b43/main.c24
-rw-r--r--drivers/net/wireless/b43/phy.c2
-rw-r--r--drivers/net/wireless/b43/rfkill.c37
-rw-r--r--drivers/net/wireless/b43legacy/dma.c2
-rw-r--r--drivers/net/wireless/b43legacy/main.c2
-rw-r--r--drivers/net/wireless/b43legacy/phy.c2
-rw-r--r--drivers/net/wireless/bcm43xx/bcm43xx_debugfs.c2
-rw-r--r--drivers/net/wireless/bcm43xx/bcm43xx_phy.c2
-rw-r--r--drivers/net/wireless/ipw2200.c20
-rw-r--r--drivers/net/wireless/iwlwifi/iwl3945-base.c39
-rw-r--r--drivers/net/wireless/iwlwifi/iwl4965-base.c36
-rw-r--r--drivers/net/wireless/libertas/if_cs.c3
-rw-r--r--drivers/net/wireless/libertas/main.c4
-rw-r--r--drivers/net/wireless/libertas/wext.c2
-rw-r--r--drivers/net/wireless/netwave_cs.c2
-rw-r--r--drivers/net/wireless/p54usb.c2
-rw-r--r--drivers/net/wireless/rt2x00/rt2500usb.c7
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00.h7
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00usb.c9
-rw-r--r--drivers/net/wireless/rt2x00/rt73usb.c4
-rw-r--r--drivers/net/wireless/rtl8187_dev.c2
-rw-r--r--drivers/net/wireless/zd1211rw/zd_mac.c10
-rw-r--r--drivers/net/yellowfin.c25
-rw-r--r--drivers/parisc/lba_pci.c10
-rw-r--r--drivers/parport/procfs.c2
-rw-r--r--drivers/pci/hotplug/acpiphp.h8
-rw-r--r--drivers/pci/hotplug/acpiphp_core.c29
-rw-r--r--drivers/pci/hotplug/acpiphp_glue.c36
-rw-r--r--drivers/pci/hotplug/acpiphp_ibm.c47
-rw-r--r--drivers/pci/hotplug/cpqphp_core.c41
-rw-r--r--drivers/pci/hotplug/cpqphp_ctrl.c96
-rw-r--r--drivers/pci/hotplug/fakephp.c14
-rw-r--r--drivers/pci/hotplug/pciehp_ctrl.c16
-rw-r--r--drivers/pci/hotplug/rpadlpar_core.c19
-rw-r--r--drivers/pci/hotplug/rpaphp_core.c15
-rw-r--r--drivers/pci/hotplug/rpaphp_pci.c1
-rw-r--r--drivers/pci/hotplug/shpchp_ctrl.c16
-rw-r--r--drivers/pci/pci-sysfs.c4
-rw-r--r--drivers/pci/pcie/aer/aerdrv_core.c29
-rw-r--r--drivers/pci/pcie/portdrv_pci.c2
-rw-r--r--drivers/pci/probe.c69
-rw-r--r--drivers/pcmcia/cs.c8
-rw-r--r--drivers/pcmcia/ds.c6
-rw-r--r--drivers/pcmcia/pxa2xx_lubbock.c2
-rw-r--r--drivers/pcmcia/ti113x.h2
-rw-r--r--drivers/pcmcia/yenta_socket.c6
-rw-r--r--drivers/pnp/pnpacpi/rsparser.c39
-rw-r--r--drivers/pnp/resource.c4
-rw-r--r--drivers/ps3/Makefile4
-rw-r--r--drivers/ps3/ps3-sys-manager.c (renamed from drivers/ps3/sys-manager.c)0
-rw-r--r--drivers/ps3/ps3-vuart.c (renamed from drivers/ps3/vuart.c)1
-rw-r--r--drivers/rtc/Kconfig2
-rw-r--r--drivers/rtc/interface.c4
-rw-r--r--drivers/rtc/rtc-at32ap700x.c20
-rw-r--r--drivers/rtc/rtc-dev.c12
-rw-r--r--drivers/rtc/rtc-max6902.c12
-rw-r--r--drivers/s390/block/dcssblk.c4
-rw-r--r--drivers/s390/cio/css.c3
-rw-r--r--drivers/s390/cio/device_fsm.c2
-rw-r--r--drivers/s390/cio/device_id.c8
-rw-r--r--drivers/s390/net/ctcmain.c50
-rw-r--r--drivers/s390/net/netiucv.c4
-rw-r--r--drivers/s390/scsi/zfcp_erp.c18
-rw-r--r--drivers/sbus/char/cpwatchdog.c2
-rw-r--r--drivers/scsi/aacraid/commsup.c8
-rw-r--r--drivers/scsi/aacraid/linit.c7
-rw-r--r--drivers/scsi/atari_scsi.c10
-rw-r--r--drivers/scsi/dpt_i2o.c135
-rw-r--r--drivers/scsi/dpti.h9
-rw-r--r--drivers/scsi/dtc.c5
-rw-r--r--drivers/scsi/esp_scsi.c4
-rw-r--r--drivers/scsi/g_NCR5380.c5
-rw-r--r--drivers/scsi/ide-scsi.c17
-rw-r--r--drivers/scsi/initio.c2
-rw-r--r--drivers/scsi/iscsi_tcp.c139
-rw-r--r--drivers/scsi/iscsi_tcp.h34
-rw-r--r--drivers/scsi/libiscsi.c3
-rw-r--r--drivers/scsi/mac_scsi.c4
-rw-r--r--drivers/scsi/pas16.c5
-rw-r--r--drivers/scsi/qla1280.c387
-rw-r--r--drivers/scsi/scsi.c31
-rw-r--r--drivers/scsi/st.c1
-rw-r--r--drivers/scsi/sun3_scsi.c4
-rw-r--r--drivers/scsi/sun3_scsi_vme.c4
-rw-r--r--drivers/scsi/sym53c8xx_2/sym_glue.c2
-rw-r--r--drivers/scsi/sym53c8xx_2/sym_hipd.c2
-rw-r--r--drivers/scsi/t128.c5
-rw-r--r--drivers/scsi/zorro7xx.c3
-rw-r--r--drivers/serial/Kconfig2
-rw-r--r--drivers/serial/ip22zilog.c247
-rw-r--r--drivers/serial/pxa.c4
-rw-r--r--drivers/serial/suncore.c33
-rw-r--r--drivers/serial/suncore.h3
-rw-r--r--drivers/serial/sunhv.c14
-rw-r--r--drivers/serial/sunsab.c16
-rw-r--r--drivers/serial/sunsu.c16
-rw-r--r--drivers/serial/sunzilog.c41
-rw-r--r--drivers/serial/uartlite.c1
-rw-r--r--drivers/spi/Kconfig2
-rw-r--r--drivers/spi/at25.c7
-rw-r--r--drivers/spi/atmel_spi.c4
-rw-r--r--drivers/spi/pxa2xx_spi.c2
-rw-r--r--drivers/spi/spi.c19
-rw-r--r--drivers/spi/spi_bfin5xx.c866
-rw-r--r--drivers/spi/spi_imx.c2
-rw-r--r--drivers/spi/spi_s3c24xx_gpio.c21
-rw-r--r--drivers/usb/README6
-rw-r--r--drivers/usb/core/driver.c11
-rw-r--r--drivers/usb/core/hcd-pci.c2
-rw-r--r--drivers/usb/core/hcd.c3
-rw-r--r--drivers/usb/core/hub.c8
-rw-r--r--drivers/usb/core/message.c36
-rw-r--r--drivers/usb/core/sysfs.c6
-rw-r--r--drivers/usb/core/usb.c25
-rw-r--r--drivers/usb/gadget/at91_udc.c2
-rw-r--r--drivers/usb/gadget/fsl_usb2_udc.c2
-rw-r--r--drivers/usb/gadget/omap_udc.c6
-rw-r--r--drivers/usb/gadget/s3c2410_udc.c16
-rw-r--r--drivers/usb/host/Kconfig2
-rw-r--r--drivers/usb/host/ehci-fsl.c2
-rw-r--r--drivers/usb/host/ehci-hcd.c5
-rw-r--r--drivers/usb/host/ohci-hcd.c23
-rw-r--r--drivers/usb/host/ohci-ppc-of.c2
-rw-r--r--drivers/usb/host/ohci-ssb.c2
-rw-r--r--drivers/usb/host/r8a66597-hcd.c2
-rw-r--r--drivers/usb/host/uhci-hcd.c9
-rw-r--r--drivers/usb/image/microtek.c2
-rw-r--r--drivers/usb/misc/adutux.c262
-rw-r--r--drivers/usb/misc/usbled.c4
-rw-r--r--drivers/usb/serial/cp2101.c6
-rw-r--r--drivers/usb/serial/generic.c5
-rw-r--r--drivers/usb/serial/keyspan.c32
-rw-r--r--drivers/usb/serial/mos7840.c2
-rw-r--r--drivers/usb/serial/option.c4
-rw-r--r--drivers/usb/serial/pl2303.c1
-rw-r--r--drivers/usb/serial/pl2303.h3
-rw-r--r--drivers/usb/serial/sierra.c4
-rw-r--r--drivers/usb/storage/scsiglue.c16
-rw-r--r--drivers/usb/storage/unusual_devs.h32
-rw-r--r--drivers/video/Kconfig11
-rw-r--r--drivers/video/Makefile1
-rw-r--r--drivers/video/atmel_lcdfb.c4
-rw-r--r--drivers/video/aty/radeon_base.c1
-rw-r--r--drivers/video/console/Kconfig2
-rw-r--r--drivers/video/efifb.c232
-rw-r--r--drivers/video/fb_ddc.c8
-rw-r--r--drivers/video/imacfb.c4
-rw-r--r--drivers/video/ps3fb.c39
-rw-r--r--drivers/virtio/virtio.c13
-rw-r--r--drivers/watchdog/Kconfig23
-rw-r--r--drivers/watchdog/Makefile2
-rw-r--r--drivers/watchdog/at32ap700x_wdt.c69
-rw-r--r--drivers/watchdog/bfin_wdt.c2
-rw-r--r--drivers/watchdog/it8712f_wdt.c400
-rw-r--r--drivers/watchdog/sbc7240_wdt.c324
-rw-r--r--drivers/watchdog/w83697hf_wdt.c4
-rw-r--r--drivers/zorro/zorro-driver.c15
423 files changed, 7424 insertions, 5258 deletions
diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig
index 087a7028ae84..b9f923ef173d 100644
--- a/drivers/acpi/Kconfig
+++ b/drivers/acpi/Kconfig
@@ -50,7 +50,6 @@ config ACPI_SLEEP
50config ACPI_PROCFS 50config ACPI_PROCFS
51 bool "Deprecated /proc/acpi files" 51 bool "Deprecated /proc/acpi files"
52 depends on PROC_FS 52 depends on PROC_FS
53 default y
54 ---help--- 53 ---help---
55 For backwards compatibility, this option allows 54 For backwards compatibility, this option allows
56 deprecated /proc/acpi/ files to exist, even when 55 deprecated /proc/acpi/ files to exist, even when
@@ -61,7 +60,6 @@ config ACPI_PROCFS
61 /proc/acpi/info (/sys/modules/acpi/parameters/acpica_version) 60 /proc/acpi/info (/sys/modules/acpi/parameters/acpica_version)
62 /proc/acpi/dsdt (/sys/firmware/acpi/tables/DSDT) 61 /proc/acpi/dsdt (/sys/firmware/acpi/tables/DSDT)
63 /proc/acpi/fadt (/sys/firmware/acpi/tables/FACP) 62 /proc/acpi/fadt (/sys/firmware/acpi/tables/FACP)
64 /proc/acpi/battery (/sys/class/power_supply)
65 /proc/acpi/debug_layer (/sys/module/acpi/parameters/debug_layer) 63 /proc/acpi/debug_layer (/sys/module/acpi/parameters/debug_layer)
66 /proc/acpi/debug_level (/sys/module/acpi/parameters/debug_level) 64 /proc/acpi/debug_level (/sys/module/acpi/parameters/debug_level)
67 65
@@ -69,7 +67,21 @@ config ACPI_PROCFS
69 and functions which do not yet exist in /sys. 67 and functions which do not yet exist in /sys.
70 68
71 Say N to delete /proc/acpi/ files that have moved to /sys/ 69 Say N to delete /proc/acpi/ files that have moved to /sys/
72 70config ACPI_PROCFS_POWER
71 bool "Deprecated power /proc/acpi folders"
72 depends on PROC_FS
73 default y
74 ---help---
75 For backwards compatibility, this option allows
76 deprecated power /proc/acpi/ folders to exist, even when
77 they have been replaced by functions in /sys.
78 The deprecated folders (and their replacements) include:
79 /proc/acpi/battery/* (/sys/class/power_supply/*)
80 /proc/acpi/ac_adapter/* (sys/class/power_supply/*)
81 This option has no effect on /proc/acpi/ folders
82 and functions, which do not yet exist in /sys
83
84 Say N to delete power /proc/acpi/ folders that have moved to /sys/
73config ACPI_PROC_EVENT 85config ACPI_PROC_EVENT
74 bool "Deprecated /proc/acpi/event support" 86 bool "Deprecated /proc/acpi/event support"
75 depends on PROC_FS 87 depends on PROC_FS
diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
index 54e3ab0e5fc0..456446f90077 100644
--- a/drivers/acpi/Makefile
+++ b/drivers/acpi/Makefile
@@ -58,6 +58,6 @@ obj-$(CONFIG_ACPI_NUMA) += numa.o
58obj-$(CONFIG_ACPI_ASUS) += asus_acpi.o 58obj-$(CONFIG_ACPI_ASUS) += asus_acpi.o
59obj-$(CONFIG_ACPI_TOSHIBA) += toshiba_acpi.o 59obj-$(CONFIG_ACPI_TOSHIBA) += toshiba_acpi.o
60obj-$(CONFIG_ACPI_HOTPLUG_MEMORY) += acpi_memhotplug.o 60obj-$(CONFIG_ACPI_HOTPLUG_MEMORY) += acpi_memhotplug.o
61obj-y += cm_sbs.o 61obj-$(CONFIG_ACPI_PROCFS_POWER) += cm_sbs.o
62obj-$(CONFIG_ACPI_SBS) += sbs.o 62obj-$(CONFIG_ACPI_SBS) += sbs.o
63obj-$(CONFIG_ACPI_SBS) += sbshc.o 63obj-$(CONFIG_ACPI_SBS) += sbshc.o
diff --git a/drivers/acpi/ac.c b/drivers/acpi/ac.c
index 30238f6ff232..76ed4f52bebd 100644
--- a/drivers/acpi/ac.c
+++ b/drivers/acpi/ac.c
@@ -27,7 +27,7 @@
27#include <linux/module.h> 27#include <linux/module.h>
28#include <linux/init.h> 28#include <linux/init.h>
29#include <linux/types.h> 29#include <linux/types.h>
30#ifdef CONFIG_ACPI_PROCFS 30#ifdef CONFIG_ACPI_PROCFS_POWER
31#include <linux/proc_fs.h> 31#include <linux/proc_fs.h>
32#include <linux/seq_file.h> 32#include <linux/seq_file.h>
33#endif 33#endif
@@ -51,7 +51,7 @@ MODULE_AUTHOR("Paul Diefenbaugh");
51MODULE_DESCRIPTION("ACPI AC Adapter Driver"); 51MODULE_DESCRIPTION("ACPI AC Adapter Driver");
52MODULE_LICENSE("GPL"); 52MODULE_LICENSE("GPL");
53 53
54#ifdef CONFIG_ACPI_PROCFS 54#ifdef CONFIG_ACPI_PROCFS_POWER
55extern struct proc_dir_entry *acpi_lock_ac_dir(void); 55extern struct proc_dir_entry *acpi_lock_ac_dir(void);
56extern void *acpi_unlock_ac_dir(struct proc_dir_entry *acpi_ac_dir); 56extern void *acpi_unlock_ac_dir(struct proc_dir_entry *acpi_ac_dir);
57static int acpi_ac_open_fs(struct inode *inode, struct file *file); 57static int acpi_ac_open_fs(struct inode *inode, struct file *file);
@@ -86,7 +86,7 @@ struct acpi_ac {
86 86
87#define to_acpi_ac(x) container_of(x, struct acpi_ac, charger); 87#define to_acpi_ac(x) container_of(x, struct acpi_ac, charger);
88 88
89#ifdef CONFIG_ACPI_PROCFS 89#ifdef CONFIG_ACPI_PROCFS_POWER
90static const struct file_operations acpi_ac_fops = { 90static const struct file_operations acpi_ac_fops = {
91 .open = acpi_ac_open_fs, 91 .open = acpi_ac_open_fs,
92 .read = seq_read, 92 .read = seq_read,
@@ -136,7 +136,7 @@ static int acpi_ac_get_state(struct acpi_ac *ac)
136 return 0; 136 return 0;
137} 137}
138 138
139#ifdef CONFIG_ACPI_PROCFS 139#ifdef CONFIG_ACPI_PROCFS_POWER
140/* -------------------------------------------------------------------------- 140/* --------------------------------------------------------------------------
141 FS Interface (/proc) 141 FS Interface (/proc)
142 -------------------------------------------------------------------------- */ 142 -------------------------------------------------------------------------- */
@@ -275,7 +275,7 @@ static int acpi_ac_add(struct acpi_device *device)
275 if (result) 275 if (result)
276 goto end; 276 goto end;
277 277
278#ifdef CONFIG_ACPI_PROCFS 278#ifdef CONFIG_ACPI_PROCFS_POWER
279 result = acpi_ac_add_fs(device); 279 result = acpi_ac_add_fs(device);
280#endif 280#endif
281 if (result) 281 if (result)
@@ -300,7 +300,7 @@ static int acpi_ac_add(struct acpi_device *device)
300 300
301 end: 301 end:
302 if (result) { 302 if (result) {
303#ifdef CONFIG_ACPI_PROCFS 303#ifdef CONFIG_ACPI_PROCFS_POWER
304 acpi_ac_remove_fs(device); 304 acpi_ac_remove_fs(device);
305#endif 305#endif
306 kfree(ac); 306 kfree(ac);
@@ -339,7 +339,7 @@ static int acpi_ac_remove(struct acpi_device *device, int type)
339 ACPI_ALL_NOTIFY, acpi_ac_notify); 339 ACPI_ALL_NOTIFY, acpi_ac_notify);
340 if (ac->charger.dev) 340 if (ac->charger.dev)
341 power_supply_unregister(&ac->charger); 341 power_supply_unregister(&ac->charger);
342#ifdef CONFIG_ACPI_PROCFS 342#ifdef CONFIG_ACPI_PROCFS_POWER
343 acpi_ac_remove_fs(device); 343 acpi_ac_remove_fs(device);
344#endif 344#endif
345 345
@@ -355,7 +355,7 @@ static int __init acpi_ac_init(void)
355 if (acpi_disabled) 355 if (acpi_disabled)
356 return -ENODEV; 356 return -ENODEV;
357 357
358#ifdef CONFIG_ACPI_PROCFS 358#ifdef CONFIG_ACPI_PROCFS_POWER
359 acpi_ac_dir = acpi_lock_ac_dir(); 359 acpi_ac_dir = acpi_lock_ac_dir();
360 if (!acpi_ac_dir) 360 if (!acpi_ac_dir)
361 return -ENODEV; 361 return -ENODEV;
@@ -363,7 +363,7 @@ static int __init acpi_ac_init(void)
363 363
364 result = acpi_bus_register_driver(&acpi_ac_driver); 364 result = acpi_bus_register_driver(&acpi_ac_driver);
365 if (result < 0) { 365 if (result < 0) {
366#ifdef CONFIG_ACPI_PROCFS 366#ifdef CONFIG_ACPI_PROCFS_POWER
367 acpi_unlock_ac_dir(acpi_ac_dir); 367 acpi_unlock_ac_dir(acpi_ac_dir);
368#endif 368#endif
369 return -ENODEV; 369 return -ENODEV;
@@ -377,7 +377,7 @@ static void __exit acpi_ac_exit(void)
377 377
378 acpi_bus_unregister_driver(&acpi_ac_driver); 378 acpi_bus_unregister_driver(&acpi_ac_driver);
379 379
380#ifdef CONFIG_ACPI_PROCFS 380#ifdef CONFIG_ACPI_PROCFS_POWER
381 acpi_unlock_ac_dir(acpi_ac_dir); 381 acpi_unlock_ac_dir(acpi_ac_dir);
382#endif 382#endif
383 383
diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
index 192c244f6190..8f7505d304b5 100644
--- a/drivers/acpi/battery.c
+++ b/drivers/acpi/battery.c
@@ -31,7 +31,7 @@
31#include <linux/types.h> 31#include <linux/types.h>
32#include <linux/jiffies.h> 32#include <linux/jiffies.h>
33 33
34#ifdef CONFIG_ACPI_PROCFS 34#ifdef CONFIG_ACPI_PROCFS_POWER
35#include <linux/proc_fs.h> 35#include <linux/proc_fs.h>
36#include <linux/seq_file.h> 36#include <linux/seq_file.h>
37#include <asm/uaccess.h> 37#include <asm/uaccess.h>
@@ -63,7 +63,7 @@ static unsigned int cache_time = 1000;
63module_param(cache_time, uint, 0644); 63module_param(cache_time, uint, 0644);
64MODULE_PARM_DESC(cache_time, "cache time in milliseconds"); 64MODULE_PARM_DESC(cache_time, "cache time in milliseconds");
65 65
66#ifdef CONFIG_ACPI_PROCFS 66#ifdef CONFIG_ACPI_PROCFS_POWER
67extern struct proc_dir_entry *acpi_lock_battery_dir(void); 67extern struct proc_dir_entry *acpi_lock_battery_dir(void);
68extern void *acpi_unlock_battery_dir(struct proc_dir_entry *acpi_battery_dir); 68extern void *acpi_unlock_battery_dir(struct proc_dir_entry *acpi_battery_dir);
69 69
@@ -125,7 +125,7 @@ static int acpi_battery_technology(struct acpi_battery *battery)
125 return POWER_SUPPLY_TECHNOLOGY_NiMH; 125 return POWER_SUPPLY_TECHNOLOGY_NiMH;
126 if (!strcasecmp("LION", battery->type)) 126 if (!strcasecmp("LION", battery->type))
127 return POWER_SUPPLY_TECHNOLOGY_LION; 127 return POWER_SUPPLY_TECHNOLOGY_LION;
128 if (!strcasecmp("LI-ION", battery->type)) 128 if (!strncasecmp("LI-ION", battery->type, 6))
129 return POWER_SUPPLY_TECHNOLOGY_LION; 129 return POWER_SUPPLY_TECHNOLOGY_LION;
130 if (!strcasecmp("LiP", battery->type)) 130 if (!strcasecmp("LiP", battery->type))
131 return POWER_SUPPLY_TECHNOLOGY_LIPO; 131 return POWER_SUPPLY_TECHNOLOGY_LIPO;
@@ -153,6 +153,8 @@ static int acpi_battery_get_property(struct power_supply *psy,
153 val->intval = POWER_SUPPLY_STATUS_CHARGING; 153 val->intval = POWER_SUPPLY_STATUS_CHARGING;
154 else if (battery->state == 0) 154 else if (battery->state == 0)
155 val->intval = POWER_SUPPLY_STATUS_FULL; 155 val->intval = POWER_SUPPLY_STATUS_FULL;
156 else
157 val->intval = POWER_SUPPLY_STATUS_UNKNOWN;
156 break; 158 break;
157 case POWER_SUPPLY_PROP_PRESENT: 159 case POWER_SUPPLY_PROP_PRESENT:
158 val->intval = acpi_battery_present(battery); 160 val->intval = acpi_battery_present(battery);
@@ -221,7 +223,7 @@ static enum power_supply_property energy_battery_props[] = {
221 POWER_SUPPLY_PROP_MANUFACTURER, 223 POWER_SUPPLY_PROP_MANUFACTURER,
222}; 224};
223 225
224#ifdef CONFIG_ACPI_PROCFS 226#ifdef CONFIG_ACPI_PROCFS_POWER
225inline char *acpi_battery_units(struct acpi_battery *battery) 227inline char *acpi_battery_units(struct acpi_battery *battery)
226{ 228{
227 return (battery->power_unit)?"mA":"mW"; 229 return (battery->power_unit)?"mA":"mW";
@@ -479,7 +481,7 @@ static int acpi_battery_update(struct acpi_battery *battery)
479 FS Interface (/proc) 481 FS Interface (/proc)
480 -------------------------------------------------------------------------- */ 482 -------------------------------------------------------------------------- */
481 483
482#ifdef CONFIG_ACPI_PROCFS 484#ifdef CONFIG_ACPI_PROCFS_POWER
483static struct proc_dir_entry *acpi_battery_dir; 485static struct proc_dir_entry *acpi_battery_dir;
484 486
485static int acpi_battery_print_info(struct seq_file *seq, int result) 487static int acpi_battery_print_info(struct seq_file *seq, int result)
@@ -786,7 +788,7 @@ static int acpi_battery_add(struct acpi_device *device)
786 acpi_driver_data(device) = battery; 788 acpi_driver_data(device) = battery;
787 mutex_init(&battery->lock); 789 mutex_init(&battery->lock);
788 acpi_battery_update(battery); 790 acpi_battery_update(battery);
789#ifdef CONFIG_ACPI_PROCFS 791#ifdef CONFIG_ACPI_PROCFS_POWER
790 result = acpi_battery_add_fs(device); 792 result = acpi_battery_add_fs(device);
791 if (result) 793 if (result)
792 goto end; 794 goto end;
@@ -804,7 +806,7 @@ static int acpi_battery_add(struct acpi_device *device)
804 device->status.battery_present ? "present" : "absent"); 806 device->status.battery_present ? "present" : "absent");
805 end: 807 end:
806 if (result) { 808 if (result) {
807#ifdef CONFIG_ACPI_PROCFS 809#ifdef CONFIG_ACPI_PROCFS_POWER
808 acpi_battery_remove_fs(device); 810 acpi_battery_remove_fs(device);
809#endif 811#endif
810 kfree(battery); 812 kfree(battery);
@@ -823,7 +825,7 @@ static int acpi_battery_remove(struct acpi_device *device, int type)
823 status = acpi_remove_notify_handler(device->handle, 825 status = acpi_remove_notify_handler(device->handle,
824 ACPI_ALL_NOTIFY, 826 ACPI_ALL_NOTIFY,
825 acpi_battery_notify); 827 acpi_battery_notify);
826#ifdef CONFIG_ACPI_PROCFS 828#ifdef CONFIG_ACPI_PROCFS_POWER
827 acpi_battery_remove_fs(device); 829 acpi_battery_remove_fs(device);
828#endif 830#endif
829 sysfs_remove_battery(battery); 831 sysfs_remove_battery(battery);
@@ -859,13 +861,13 @@ static int __init acpi_battery_init(void)
859{ 861{
860 if (acpi_disabled) 862 if (acpi_disabled)
861 return -ENODEV; 863 return -ENODEV;
862#ifdef CONFIG_ACPI_PROCFS 864#ifdef CONFIG_ACPI_PROCFS_POWER
863 acpi_battery_dir = acpi_lock_battery_dir(); 865 acpi_battery_dir = acpi_lock_battery_dir();
864 if (!acpi_battery_dir) 866 if (!acpi_battery_dir)
865 return -ENODEV; 867 return -ENODEV;
866#endif 868#endif
867 if (acpi_bus_register_driver(&acpi_battery_driver) < 0) { 869 if (acpi_bus_register_driver(&acpi_battery_driver) < 0) {
868#ifdef CONFIG_ACPI_PROCFS 870#ifdef CONFIG_ACPI_PROCFS_POWER
869 acpi_unlock_battery_dir(acpi_battery_dir); 871 acpi_unlock_battery_dir(acpi_battery_dir);
870#endif 872#endif
871 return -ENODEV; 873 return -ENODEV;
@@ -876,7 +878,7 @@ static int __init acpi_battery_init(void)
876static void __exit acpi_battery_exit(void) 878static void __exit acpi_battery_exit(void)
877{ 879{
878 acpi_bus_unregister_driver(&acpi_battery_driver); 880 acpi_bus_unregister_driver(&acpi_battery_driver);
879#ifdef CONFIG_ACPI_PROCFS 881#ifdef CONFIG_ACPI_PROCFS_POWER
880 acpi_unlock_battery_dir(acpi_battery_dir); 882 acpi_unlock_battery_dir(acpi_battery_dir);
881#endif 883#endif
882} 884}
diff --git a/drivers/acpi/dispatcher/dsobject.c b/drivers/acpi/dispatcher/dsobject.c
index a474ca2334d5..954ac8ce958a 100644
--- a/drivers/acpi/dispatcher/dsobject.c
+++ b/drivers/acpi/dispatcher/dsobject.c
@@ -137,6 +137,71 @@ acpi_ds_build_internal_object(struct acpi_walk_state *walk_state,
137 return_ACPI_STATUS(status); 137 return_ACPI_STATUS(status);
138 } 138 }
139 } 139 }
140
141 /* Special object resolution for elements of a package */
142
143 if ((op->common.parent->common.aml_opcode == AML_PACKAGE_OP) ||
144 (op->common.parent->common.aml_opcode ==
145 AML_VAR_PACKAGE_OP)) {
146 /*
147 * Attempt to resolve the node to a value before we insert it into
148 * the package. If this is a reference to a common data type,
149 * resolve it immediately. According to the ACPI spec, package
150 * elements can only be "data objects" or method references.
151 * Attempt to resolve to an Integer, Buffer, String or Package.
152 * If cannot, return the named reference (for things like Devices,
153 * Methods, etc.) Buffer Fields and Fields will resolve to simple
154 * objects (int/buf/str/pkg).
155 *
156 * NOTE: References to things like Devices, Methods, Mutexes, etc.
157 * will remain as named references. This behavior is not described
158 * in the ACPI spec, but it appears to be an oversight.
159 */
160 obj_desc = (union acpi_operand_object *)op->common.node;
161
162 status =
163 acpi_ex_resolve_node_to_value(ACPI_CAST_INDIRECT_PTR
164 (struct
165 acpi_namespace_node,
166 &obj_desc),
167 walk_state);
168 if (ACPI_FAILURE(status)) {
169 return_ACPI_STATUS(status);
170 }
171
172 switch (op->common.node->type) {
173 /*
174 * For these types, we need the actual node, not the subobject.
175 * However, the subobject got an extra reference count above.
176 */
177 case ACPI_TYPE_MUTEX:
178 case ACPI_TYPE_METHOD:
179 case ACPI_TYPE_POWER:
180 case ACPI_TYPE_PROCESSOR:
181 case ACPI_TYPE_EVENT:
182 case ACPI_TYPE_REGION:
183 case ACPI_TYPE_DEVICE:
184 case ACPI_TYPE_THERMAL:
185
186 obj_desc =
187 (union acpi_operand_object *)op->common.
188 node;
189 break;
190
191 default:
192 break;
193 }
194
195 /*
196 * If above resolved to an operand object, we are done. Otherwise,
197 * we have a NS node, we must create the package entry as a named
198 * reference.
199 */
200 if (ACPI_GET_DESCRIPTOR_TYPE(obj_desc) !=
201 ACPI_DESC_TYPE_NAMED) {
202 goto exit;
203 }
204 }
140 } 205 }
141 206
142 /* Create and init a new internal ACPI object */ 207 /* Create and init a new internal ACPI object */
@@ -156,6 +221,7 @@ acpi_ds_build_internal_object(struct acpi_walk_state *walk_state,
156 return_ACPI_STATUS(status); 221 return_ACPI_STATUS(status);
157 } 222 }
158 223
224 exit:
159 *obj_desc_ptr = obj_desc; 225 *obj_desc_ptr = obj_desc;
160 return_ACPI_STATUS(AE_OK); 226 return_ACPI_STATUS(AE_OK);
161} 227}
@@ -356,12 +422,25 @@ acpi_ds_build_internal_package_obj(struct acpi_walk_state *walk_state,
356 arg = arg->common.next; 422 arg = arg->common.next;
357 for (i = 0; arg && (i < element_count); i++) { 423 for (i = 0; arg && (i < element_count); i++) {
358 if (arg->common.aml_opcode == AML_INT_RETURN_VALUE_OP) { 424 if (arg->common.aml_opcode == AML_INT_RETURN_VALUE_OP) {
359 425 if (arg->common.node->type == ACPI_TYPE_METHOD) {
360 /* This package element is already built, just get it */ 426 /*
361 427 * A method reference "looks" to the parser to be a method
362 obj_desc->package.elements[i] = 428 * invocation, so we special case it here
363 ACPI_CAST_PTR(union acpi_operand_object, 429 */
364 arg->common.node); 430 arg->common.aml_opcode = AML_INT_NAMEPATH_OP;
431 status =
432 acpi_ds_build_internal_object(walk_state,
433 arg,
434 &obj_desc->
435 package.
436 elements[i]);
437 } else {
438 /* This package element is already built, just get it */
439
440 obj_desc->package.elements[i] =
441 ACPI_CAST_PTR(union acpi_operand_object,
442 arg->common.node);
443 }
365 } else { 444 } else {
366 status = acpi_ds_build_internal_object(walk_state, arg, 445 status = acpi_ds_build_internal_object(walk_state, arg,
367 &obj_desc-> 446 &obj_desc->
diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c
index 06b78e5e33a1..d411017f8c06 100644
--- a/drivers/acpi/ec.c
+++ b/drivers/acpi/ec.c
@@ -47,6 +47,9 @@
47#undef PREFIX 47#undef PREFIX
48#define PREFIX "ACPI: EC: " 48#define PREFIX "ACPI: EC: "
49 49
50/* Uncomment next line to get verbose print outs*/
51/* #define DEBUG */
52
50/* EC status register */ 53/* EC status register */
51#define ACPI_EC_FLAG_OBF 0x01 /* Output buffer full */ 54#define ACPI_EC_FLAG_OBF 0x01 /* Output buffer full */
52#define ACPI_EC_FLAG_IBF 0x02 /* Input buffer full */ 55#define ACPI_EC_FLAG_IBF 0x02 /* Input buffer full */
@@ -75,7 +78,10 @@ enum {
75 EC_FLAGS_WAIT_GPE = 0, /* Don't check status until GPE arrives */ 78 EC_FLAGS_WAIT_GPE = 0, /* Don't check status until GPE arrives */
76 EC_FLAGS_QUERY_PENDING, /* Query is pending */ 79 EC_FLAGS_QUERY_PENDING, /* Query is pending */
77 EC_FLAGS_GPE_MODE, /* Expect GPE to be sent for status change */ 80 EC_FLAGS_GPE_MODE, /* Expect GPE to be sent for status change */
78 EC_FLAGS_ONLY_IBF_GPE, /* Expect GPE only for IBF = 0 event */ 81 EC_FLAGS_NO_ADDRESS_GPE, /* Expect GPE only for non-address event */
82 EC_FLAGS_ADDRESS, /* Address is being written */
83 EC_FLAGS_NO_WDATA_GPE, /* Don't expect WDATA GPE event */
84 EC_FLAGS_WDATA, /* Data is being written */
79}; 85};
80 86
81static int acpi_ec_remove(struct acpi_device *device, int type); 87static int acpi_ec_remove(struct acpi_device *device, int type);
@@ -131,21 +137,27 @@ static struct acpi_ec {
131 137
132static inline u8 acpi_ec_read_status(struct acpi_ec *ec) 138static inline u8 acpi_ec_read_status(struct acpi_ec *ec)
133{ 139{
134 return inb(ec->command_addr); 140 u8 x = inb(ec->command_addr);
141 pr_debug(PREFIX "---> status = 0x%2x\n", x);
142 return x;
135} 143}
136 144
137static inline u8 acpi_ec_read_data(struct acpi_ec *ec) 145static inline u8 acpi_ec_read_data(struct acpi_ec *ec)
138{ 146{
147 u8 x = inb(ec->data_addr);
148 pr_debug(PREFIX "---> data = 0x%2x\n", x);
139 return inb(ec->data_addr); 149 return inb(ec->data_addr);
140} 150}
141 151
142static inline void acpi_ec_write_cmd(struct acpi_ec *ec, u8 command) 152static inline void acpi_ec_write_cmd(struct acpi_ec *ec, u8 command)
143{ 153{
154 pr_debug(PREFIX "<--- command = 0x%2x\n", command);
144 outb(command, ec->command_addr); 155 outb(command, ec->command_addr);
145} 156}
146 157
147static inline void acpi_ec_write_data(struct acpi_ec *ec, u8 data) 158static inline void acpi_ec_write_data(struct acpi_ec *ec, u8 data)
148{ 159{
160 pr_debug(PREFIX "<--- data = 0x%2x\n", data);
149 outb(data, ec->data_addr); 161 outb(data, ec->data_addr);
150} 162}
151 163
@@ -166,38 +178,54 @@ static inline int acpi_ec_check_status(struct acpi_ec *ec, enum ec_event event)
166 178
167static int acpi_ec_wait(struct acpi_ec *ec, enum ec_event event, int force_poll) 179static int acpi_ec_wait(struct acpi_ec *ec, enum ec_event event, int force_poll)
168{ 180{
181 int ret = 0;
182 if (unlikely(test_bit(EC_FLAGS_ADDRESS, &ec->flags) &&
183 test_bit(EC_FLAGS_NO_ADDRESS_GPE, &ec->flags)))
184 force_poll = 1;
185 if (unlikely(test_bit(EC_FLAGS_WDATA, &ec->flags) &&
186 test_bit(EC_FLAGS_NO_WDATA_GPE, &ec->flags)))
187 force_poll = 1;
169 if (likely(test_bit(EC_FLAGS_GPE_MODE, &ec->flags)) && 188 if (likely(test_bit(EC_FLAGS_GPE_MODE, &ec->flags)) &&
170 likely(!force_poll)) { 189 likely(!force_poll)) {
171 if (wait_event_timeout(ec->wait, acpi_ec_check_status(ec, event), 190 if (wait_event_timeout(ec->wait, acpi_ec_check_status(ec, event),
172 msecs_to_jiffies(ACPI_EC_DELAY))) 191 msecs_to_jiffies(ACPI_EC_DELAY)))
173 return 0; 192 goto end;
174 clear_bit(EC_FLAGS_WAIT_GPE, &ec->flags); 193 clear_bit(EC_FLAGS_WAIT_GPE, &ec->flags);
175 if (acpi_ec_check_status(ec, event)) { 194 if (acpi_ec_check_status(ec, event)) {
176 if (event == ACPI_EC_EVENT_OBF_1) { 195 if (test_bit(EC_FLAGS_ADDRESS, &ec->flags)) {
177 /* miss OBF = 1 GPE, don't expect it anymore */ 196 /* miss address GPE, don't expect it anymore */
178 printk(KERN_INFO PREFIX "missing OBF_1 confirmation," 197 pr_info(PREFIX "missing address confirmation, "
179 "switching to degraded mode.\n"); 198 "don't expect it any longer.\n");
180 set_bit(EC_FLAGS_ONLY_IBF_GPE, &ec->flags); 199 set_bit(EC_FLAGS_NO_ADDRESS_GPE, &ec->flags);
200 } else if (test_bit(EC_FLAGS_WDATA, &ec->flags)) {
201 /* miss write data GPE, don't expect it */
202 pr_info(PREFIX "missing write data confirmation, "
203 "don't expect it any longer.\n");
204 set_bit(EC_FLAGS_NO_WDATA_GPE, &ec->flags);
181 } else { 205 } else {
182 /* missing GPEs, switch back to poll mode */ 206 /* missing GPEs, switch back to poll mode */
183 printk(KERN_INFO PREFIX "missing IBF_1 confirmations," 207 if (printk_ratelimit())
184 "switch off interrupt mode.\n"); 208 pr_info(PREFIX "missing confirmations, "
209 "switch off interrupt mode.\n");
185 clear_bit(EC_FLAGS_GPE_MODE, &ec->flags); 210 clear_bit(EC_FLAGS_GPE_MODE, &ec->flags);
186 } 211 }
187 return 0; 212 goto end;
188 } 213 }
189 } else { 214 } else {
190 unsigned long delay = jiffies + msecs_to_jiffies(ACPI_EC_DELAY); 215 unsigned long delay = jiffies + msecs_to_jiffies(ACPI_EC_DELAY);
191 clear_bit(EC_FLAGS_WAIT_GPE, &ec->flags); 216 clear_bit(EC_FLAGS_WAIT_GPE, &ec->flags);
192 while (time_before(jiffies, delay)) { 217 while (time_before(jiffies, delay)) {
193 if (acpi_ec_check_status(ec, event)) 218 if (acpi_ec_check_status(ec, event))
194 return 0; 219 goto end;
195 } 220 }
196 } 221 }
197 printk(KERN_ERR PREFIX "acpi_ec_wait timeout," 222 pr_err(PREFIX "acpi_ec_wait timeout,"
198 " status = %d, expect_event = %d\n", 223 " status = %d, expect_event = %d\n",
199 acpi_ec_read_status(ec), event); 224 acpi_ec_read_status(ec), event);
200 return -ETIME; 225 ret = -ETIME;
226 end:
227 clear_bit(EC_FLAGS_ADDRESS, &ec->flags);
228 return ret;
201} 229}
202 230
203static int acpi_ec_transaction_unlocked(struct acpi_ec *ec, u8 command, 231static int acpi_ec_transaction_unlocked(struct acpi_ec *ec, u8 command,
@@ -208,22 +236,26 @@ static int acpi_ec_transaction_unlocked(struct acpi_ec *ec, u8 command,
208 int result = 0; 236 int result = 0;
209 set_bit(EC_FLAGS_WAIT_GPE, &ec->flags); 237 set_bit(EC_FLAGS_WAIT_GPE, &ec->flags);
210 acpi_ec_write_cmd(ec, command); 238 acpi_ec_write_cmd(ec, command);
211 239 pr_debug(PREFIX "transaction start\n");
212 for (; wdata_len > 0; --wdata_len) { 240 for (; wdata_len > 0; --wdata_len) {
213 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, force_poll); 241 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, force_poll);
214 if (result) { 242 if (result) {
215 printk(KERN_ERR PREFIX 243 pr_err(PREFIX
216 "write_cmd timeout, command = %d\n", command); 244 "write_cmd timeout, command = %d\n", command);
217 goto end; 245 goto end;
218 } 246 }
247 /* mark the address byte written to EC */
248 if (rdata_len + wdata_len > 1)
249 set_bit(EC_FLAGS_ADDRESS, &ec->flags);
219 set_bit(EC_FLAGS_WAIT_GPE, &ec->flags); 250 set_bit(EC_FLAGS_WAIT_GPE, &ec->flags);
220 acpi_ec_write_data(ec, *(wdata++)); 251 acpi_ec_write_data(ec, *(wdata++));
221 } 252 }
222 253
223 if (!rdata_len) { 254 if (!rdata_len) {
255 set_bit(EC_FLAGS_WDATA, &ec->flags);
224 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, force_poll); 256 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, force_poll);
225 if (result) { 257 if (result) {
226 printk(KERN_ERR PREFIX 258 pr_err(PREFIX
227 "finish-write timeout, command = %d\n", command); 259 "finish-write timeout, command = %d\n", command);
228 goto end; 260 goto end;
229 } 261 }
@@ -231,12 +263,9 @@ static int acpi_ec_transaction_unlocked(struct acpi_ec *ec, u8 command,
231 clear_bit(EC_FLAGS_QUERY_PENDING, &ec->flags); 263 clear_bit(EC_FLAGS_QUERY_PENDING, &ec->flags);
232 264
233 for (; rdata_len > 0; --rdata_len) { 265 for (; rdata_len > 0; --rdata_len) {
234 if (test_bit(EC_FLAGS_ONLY_IBF_GPE, &ec->flags))
235 force_poll = 1;
236 result = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF_1, force_poll); 266 result = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF_1, force_poll);
237 if (result) { 267 if (result) {
238 printk(KERN_ERR PREFIX "read timeout, command = %d\n", 268 pr_err(PREFIX "read timeout, command = %d\n", command);
239 command);
240 goto end; 269 goto end;
241 } 270 }
242 /* Don't expect GPE after last read */ 271 /* Don't expect GPE after last read */
@@ -245,6 +274,7 @@ static int acpi_ec_transaction_unlocked(struct acpi_ec *ec, u8 command,
245 *(rdata++) = acpi_ec_read_data(ec); 274 *(rdata++) = acpi_ec_read_data(ec);
246 } 275 }
247 end: 276 end:
277 pr_debug(PREFIX "transaction end\n");
248 return result; 278 return result;
249} 279}
250 280
@@ -273,8 +303,8 @@ static int acpi_ec_transaction(struct acpi_ec *ec, u8 command,
273 303
274 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, 0); 304 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, 0);
275 if (status) { 305 if (status) {
276 printk(KERN_ERR PREFIX 306 pr_err(PREFIX "input buffer is not empty, "
277 "input buffer is not empty, aborting transaction\n"); 307 "aborting transaction\n");
278 goto end; 308 goto end;
279 } 309 }
280 310
@@ -488,6 +518,7 @@ static u32 acpi_ec_gpe_handler(void *data)
488 acpi_status status = AE_OK; 518 acpi_status status = AE_OK;
489 struct acpi_ec *ec = data; 519 struct acpi_ec *ec = data;
490 520
521 pr_debug(PREFIX "~~~> interrupt\n");
491 clear_bit(EC_FLAGS_WAIT_GPE, &ec->flags); 522 clear_bit(EC_FLAGS_WAIT_GPE, &ec->flags);
492 if (test_bit(EC_FLAGS_GPE_MODE, &ec->flags)) 523 if (test_bit(EC_FLAGS_GPE_MODE, &ec->flags))
493 wake_up(&ec->wait); 524 wake_up(&ec->wait);
@@ -498,8 +529,9 @@ static u32 acpi_ec_gpe_handler(void *data)
498 acpi_ec_gpe_query, ec); 529 acpi_ec_gpe_query, ec);
499 } else if (unlikely(!test_bit(EC_FLAGS_GPE_MODE, &ec->flags))) { 530 } else if (unlikely(!test_bit(EC_FLAGS_GPE_MODE, &ec->flags))) {
500 /* this is non-query, must be confirmation */ 531 /* this is non-query, must be confirmation */
501 printk(KERN_INFO PREFIX "non-query interrupt received," 532 if (printk_ratelimit())
502 " switching to interrupt mode\n"); 533 pr_info(PREFIX "non-query interrupt received,"
534 " switching to interrupt mode\n");
503 set_bit(EC_FLAGS_GPE_MODE, &ec->flags); 535 set_bit(EC_FLAGS_GPE_MODE, &ec->flags);
504 } 536 }
505 537
@@ -701,10 +733,10 @@ static void ec_remove_handlers(struct acpi_ec *ec)
701{ 733{
702 if (ACPI_FAILURE(acpi_remove_address_space_handler(ec->handle, 734 if (ACPI_FAILURE(acpi_remove_address_space_handler(ec->handle,
703 ACPI_ADR_SPACE_EC, &acpi_ec_space_handler))) 735 ACPI_ADR_SPACE_EC, &acpi_ec_space_handler)))
704 printk(KERN_ERR PREFIX "failed to remove space handler\n"); 736 pr_err(PREFIX "failed to remove space handler\n");
705 if (ACPI_FAILURE(acpi_remove_gpe_handler(NULL, ec->gpe, 737 if (ACPI_FAILURE(acpi_remove_gpe_handler(NULL, ec->gpe,
706 &acpi_ec_gpe_handler))) 738 &acpi_ec_gpe_handler)))
707 printk(KERN_ERR PREFIX "failed to remove gpe handler\n"); 739 pr_err(PREFIX "failed to remove gpe handler\n");
708 ec->handlers_installed = 0; 740 ec->handlers_installed = 0;
709} 741}
710 742
@@ -747,9 +779,9 @@ static int acpi_ec_add(struct acpi_device *device)
747 first_ec = ec; 779 first_ec = ec;
748 acpi_driver_data(device) = ec; 780 acpi_driver_data(device) = ec;
749 acpi_ec_add_fs(device); 781 acpi_ec_add_fs(device);
750 printk(KERN_INFO PREFIX "GPE = 0x%lx, I/O: command/status = 0x%lx, data = 0x%lx\n", 782 pr_info(PREFIX "GPE = 0x%lx, I/O: command/status = 0x%lx, data = 0x%lx\n",
751 ec->gpe, ec->command_addr, ec->data_addr); 783 ec->gpe, ec->command_addr, ec->data_addr);
752 printk(KERN_INFO PREFIX "driver started in %s mode\n", 784 pr_info(PREFIX "driver started in %s mode\n",
753 (test_bit(EC_FLAGS_GPE_MODE, &ec->flags))?"interrupt":"poll"); 785 (test_bit(EC_FLAGS_GPE_MODE, &ec->flags))?"interrupt":"poll");
754 return 0; 786 return 0;
755} 787}
@@ -875,18 +907,26 @@ int __init acpi_ec_ecdt_probe(void)
875 status = acpi_get_table(ACPI_SIG_ECDT, 1, 907 status = acpi_get_table(ACPI_SIG_ECDT, 1,
876 (struct acpi_table_header **)&ecdt_ptr); 908 (struct acpi_table_header **)&ecdt_ptr);
877 if (ACPI_SUCCESS(status)) { 909 if (ACPI_SUCCESS(status)) {
878 printk(KERN_INFO PREFIX "EC description table is found, configuring boot EC\n"); 910 pr_info(PREFIX "EC description table is found, configuring boot EC\n");
879 boot_ec->command_addr = ecdt_ptr->control.address; 911 boot_ec->command_addr = ecdt_ptr->control.address;
880 boot_ec->data_addr = ecdt_ptr->data.address; 912 boot_ec->data_addr = ecdt_ptr->data.address;
881 boot_ec->gpe = ecdt_ptr->gpe; 913 boot_ec->gpe = ecdt_ptr->gpe;
882 boot_ec->handle = ACPI_ROOT_OBJECT; 914 boot_ec->handle = ACPI_ROOT_OBJECT;
883 } else { 915 } else {
916 /* This workaround is needed only on some broken machines,
917 * which require early EC, but fail to provide ECDT */
918 acpi_handle x;
884 printk(KERN_DEBUG PREFIX "Look up EC in DSDT\n"); 919 printk(KERN_DEBUG PREFIX "Look up EC in DSDT\n");
885 status = acpi_get_devices(ec_device_ids[0].id, ec_parse_device, 920 status = acpi_get_devices(ec_device_ids[0].id, ec_parse_device,
886 boot_ec, NULL); 921 boot_ec, NULL);
887 /* Check that acpi_get_devices actually find something */ 922 /* Check that acpi_get_devices actually find something */
888 if (ACPI_FAILURE(status) || !boot_ec->handle) 923 if (ACPI_FAILURE(status) || !boot_ec->handle)
889 goto error; 924 goto error;
925 /* We really need to limit this workaround, the only ASUS,
926 * which needs it, has fake EC._INI method, so use it as flag.
927 */
928 if (ACPI_FAILURE(acpi_get_handle(boot_ec->handle, "_INI", &x)))
929 goto error;
890 } 930 }
891 931
892 ret = ec_install_handlers(boot_ec); 932 ret = ec_install_handlers(boot_ec);
diff --git a/drivers/acpi/numa.c b/drivers/acpi/numa.c
index ab04d848b19d..0822d9fc1cb4 100644
--- a/drivers/acpi/numa.c
+++ b/drivers/acpi/numa.c
@@ -38,9 +38,9 @@ ACPI_MODULE_NAME("numa");
38static nodemask_t nodes_found_map = NODE_MASK_NONE; 38static nodemask_t nodes_found_map = NODE_MASK_NONE;
39 39
40/* maps to convert between proximity domain and logical node ID */ 40/* maps to convert between proximity domain and logical node ID */
41static int __cpuinitdata pxm_to_node_map[MAX_PXM_DOMAINS] 41static int pxm_to_node_map[MAX_PXM_DOMAINS]
42 = { [0 ... MAX_PXM_DOMAINS - 1] = NID_INVAL }; 42 = { [0 ... MAX_PXM_DOMAINS - 1] = NID_INVAL };
43static int __cpuinitdata node_to_pxm_map[MAX_NUMNODES] 43static int node_to_pxm_map[MAX_NUMNODES]
44 = { [0 ... MAX_NUMNODES - 1] = PXM_INVAL }; 44 = { [0 ... MAX_NUMNODES - 1] = PXM_INVAL };
45 45
46int pxm_to_node(int pxm) 46int pxm_to_node(int pxm)
diff --git a/drivers/acpi/osl.c b/drivers/acpi/osl.c
index aabc6ca4a81c..e3a673a00845 100644
--- a/drivers/acpi/osl.c
+++ b/drivers/acpi/osl.c
@@ -387,17 +387,14 @@ acpi_status acpi_os_read_port(acpi_io_address port, u32 * value, u32 width)
387 if (!value) 387 if (!value)
388 value = &dummy; 388 value = &dummy;
389 389
390 switch (width) { 390 *value = 0;
391 case 8: 391 if (width <= 8) {
392 *(u8 *) value = inb(port); 392 *(u8 *) value = inb(port);
393 break; 393 } else if (width <= 16) {
394 case 16:
395 *(u16 *) value = inw(port); 394 *(u16 *) value = inw(port);
396 break; 395 } else if (width <= 32) {
397 case 32:
398 *(u32 *) value = inl(port); 396 *(u32 *) value = inl(port);
399 break; 397 } else {
400 default:
401 BUG(); 398 BUG();
402 } 399 }
403 400
@@ -408,17 +405,13 @@ EXPORT_SYMBOL(acpi_os_read_port);
408 405
409acpi_status acpi_os_write_port(acpi_io_address port, u32 value, u32 width) 406acpi_status acpi_os_write_port(acpi_io_address port, u32 value, u32 width)
410{ 407{
411 switch (width) { 408 if (width <= 8) {
412 case 8:
413 outb(value, port); 409 outb(value, port);
414 break; 410 } else if (width <= 16) {
415 case 16:
416 outw(value, port); 411 outw(value, port);
417 break; 412 } else if (width <= 32) {
418 case 32:
419 outl(value, port); 413 outl(value, port);
420 break; 414 } else {
421 default:
422 BUG(); 415 BUG();
423 } 416 }
424 417
diff --git a/drivers/acpi/pci_bind.c b/drivers/acpi/pci_bind.c
index 028969370bbf..388300de005d 100644
--- a/drivers/acpi/pci_bind.c
+++ b/drivers/acpi/pci_bind.c
@@ -294,9 +294,6 @@ int acpi_pci_unbind(struct acpi_device *device)
294 acpi_get_data(device->handle, acpi_pci_data_handler, 294 acpi_get_data(device->handle, acpi_pci_data_handler,
295 (void **)&data); 295 (void **)&data);
296 if (ACPI_FAILURE(status)) { 296 if (ACPI_FAILURE(status)) {
297 ACPI_EXCEPTION((AE_INFO, status,
298 "Unable to get data from device %s",
299 acpi_device_bid(device)));
300 result = -ENODEV; 297 result = -ENODEV;
301 goto end; 298 goto end;
302 } 299 }
diff --git a/drivers/acpi/processor_core.c b/drivers/acpi/processor_core.c
index 235a51e328c3..e48ee4f8749f 100644
--- a/drivers/acpi/processor_core.c
+++ b/drivers/acpi/processor_core.c
@@ -494,7 +494,7 @@ static int get_cpu_id(acpi_handle handle, u32 acpi_id)
494 if (apic_id == -1) 494 if (apic_id == -1)
495 return apic_id; 495 return apic_id;
496 496
497 for (i = 0; i < NR_CPUS; ++i) { 497 for_each_possible_cpu(i) {
498 if (cpu_physical_id(i) == apic_id) 498 if (cpu_physical_id(i) == apic_id)
499 return i; 499 return i;
500 } 500 }
@@ -612,12 +612,6 @@ static int acpi_processor_get_info(struct acpi_processor *pr, unsigned has_uid)
612 request_region(pr->throttling.address, 6, "ACPI CPU throttle"); 612 request_region(pr->throttling.address, 6, "ACPI CPU throttle");
613 } 613 }
614 614
615#ifdef CONFIG_CPU_FREQ
616 acpi_processor_ppc_has_changed(pr);
617#endif
618 acpi_processor_get_throttling_info(pr);
619 acpi_processor_get_limit_info(pr);
620
621 return 0; 615 return 0;
622} 616}
623 617
@@ -638,7 +632,7 @@ static int __cpuinit acpi_processor_start(struct acpi_device *device)
638 return 0; 632 return 0;
639 } 633 }
640 634
641 BUG_ON((pr->id >= NR_CPUS) || (pr->id < 0)); 635 BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
642 636
643 /* 637 /*
644 * Buggy BIOS check 638 * Buggy BIOS check
@@ -647,7 +641,7 @@ static int __cpuinit acpi_processor_start(struct acpi_device *device)
647 */ 641 */
648 if (processor_device_array[pr->id] != NULL && 642 if (processor_device_array[pr->id] != NULL &&
649 processor_device_array[pr->id] != device) { 643 processor_device_array[pr->id] != device) {
650 printk(KERN_WARNING "BIOS reported wrong ACPI id" 644 printk(KERN_WARNING "BIOS reported wrong ACPI id "
651 "for the processor\n"); 645 "for the processor\n");
652 return -ENODEV; 646 return -ENODEV;
653 } 647 }
@@ -665,6 +659,12 @@ static int __cpuinit acpi_processor_start(struct acpi_device *device)
665 /* _PDC call should be done before doing anything else (if reqd.). */ 659 /* _PDC call should be done before doing anything else (if reqd.). */
666 arch_acpi_processor_init_pdc(pr); 660 arch_acpi_processor_init_pdc(pr);
667 acpi_processor_set_pdc(pr); 661 acpi_processor_set_pdc(pr);
662#ifdef CONFIG_CPU_FREQ
663 acpi_processor_ppc_has_changed(pr);
664#endif
665 acpi_processor_get_throttling_info(pr);
666 acpi_processor_get_limit_info(pr);
667
668 668
669 acpi_processor_power_init(pr, device); 669 acpi_processor_power_init(pr, device);
670 670
@@ -684,7 +684,7 @@ static void acpi_processor_notify(acpi_handle handle, u32 event, void *data)
684{ 684{
685 struct acpi_processor *pr = data; 685 struct acpi_processor *pr = data;
686 struct acpi_device *device = NULL; 686 struct acpi_device *device = NULL;
687 687 int saved;
688 688
689 if (!pr) 689 if (!pr)
690 return; 690 return;
@@ -694,7 +694,10 @@ static void acpi_processor_notify(acpi_handle handle, u32 event, void *data)
694 694
695 switch (event) { 695 switch (event) {
696 case ACPI_PROCESSOR_NOTIFY_PERFORMANCE: 696 case ACPI_PROCESSOR_NOTIFY_PERFORMANCE:
697 saved = pr->performance_platform_limit;
697 acpi_processor_ppc_has_changed(pr); 698 acpi_processor_ppc_has_changed(pr);
699 if (saved == pr->performance_platform_limit)
700 break;
698 acpi_bus_generate_proc_event(device, event, 701 acpi_bus_generate_proc_event(device, event,
699 pr->performance_platform_limit); 702 pr->performance_platform_limit);
700 acpi_bus_generate_netlink_event(device->pnp.device_class, 703 acpi_bus_generate_netlink_event(device->pnp.device_class,
@@ -771,7 +774,7 @@ static int acpi_processor_remove(struct acpi_device *device, int type)
771 774
772 pr = acpi_driver_data(device); 775 pr = acpi_driver_data(device);
773 776
774 if (pr->id >= NR_CPUS) { 777 if (pr->id >= nr_cpu_ids) {
775 kfree(pr); 778 kfree(pr);
776 return 0; 779 return 0;
777 } 780 }
@@ -842,7 +845,7 @@ int acpi_processor_device_add(acpi_handle handle, struct acpi_device **device)
842 if (!pr) 845 if (!pr)
843 return -ENODEV; 846 return -ENODEV;
844 847
845 if ((pr->id >= 0) && (pr->id < NR_CPUS)) { 848 if ((pr->id >= 0) && (pr->id < nr_cpu_ids)) {
846 kobject_uevent(&(*device)->dev.kobj, KOBJ_ONLINE); 849 kobject_uevent(&(*device)->dev.kobj, KOBJ_ONLINE);
847 } 850 }
848 return 0; 851 return 0;
@@ -880,13 +883,13 @@ acpi_processor_hotplug_notify(acpi_handle handle, u32 event, void *data)
880 break; 883 break;
881 } 884 }
882 885
883 if (pr->id >= 0 && (pr->id < NR_CPUS)) { 886 if (pr->id >= 0 && (pr->id < nr_cpu_ids)) {
884 kobject_uevent(&device->dev.kobj, KOBJ_OFFLINE); 887 kobject_uevent(&device->dev.kobj, KOBJ_OFFLINE);
885 break; 888 break;
886 } 889 }
887 890
888 result = acpi_processor_start(device); 891 result = acpi_processor_start(device);
889 if ((!result) && ((pr->id >= 0) && (pr->id < NR_CPUS))) { 892 if ((!result) && ((pr->id >= 0) && (pr->id < nr_cpu_ids))) {
890 kobject_uevent(&device->dev.kobj, KOBJ_ONLINE); 893 kobject_uevent(&device->dev.kobj, KOBJ_ONLINE);
891 } else { 894 } else {
892 printk(KERN_ERR PREFIX "Device [%s] failed to start\n", 895 printk(KERN_ERR PREFIX "Device [%s] failed to start\n",
@@ -909,7 +912,7 @@ acpi_processor_hotplug_notify(acpi_handle handle, u32 event, void *data)
909 return; 912 return;
910 } 913 }
911 914
912 if ((pr->id < NR_CPUS) && (cpu_present(pr->id))) 915 if ((pr->id < nr_cpu_ids) && (cpu_present(pr->id)))
913 kobject_uevent(&device->dev.kobj, KOBJ_OFFLINE); 916 kobject_uevent(&device->dev.kobj, KOBJ_OFFLINE);
914 break; 917 break;
915 default: 918 default:
diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
index f996d0e37689..2fe34cc73c13 100644
--- a/drivers/acpi/processor_idle.c
+++ b/drivers/acpi/processor_idle.c
@@ -197,6 +197,19 @@ static inline u32 ticks_elapsed_in_us(u32 t1, u32 t2)
197 return PM_TIMER_TICKS_TO_US((0xFFFFFFFF - t1) + t2); 197 return PM_TIMER_TICKS_TO_US((0xFFFFFFFF - t1) + t2);
198} 198}
199 199
200static void acpi_safe_halt(void)
201{
202 current_thread_info()->status &= ~TS_POLLING;
203 /*
204 * TS_POLLING-cleared state must be visible before we
205 * test NEED_RESCHED:
206 */
207 smp_mb();
208 if (!need_resched())
209 safe_halt();
210 current_thread_info()->status |= TS_POLLING;
211}
212
200#ifndef CONFIG_CPU_IDLE 213#ifndef CONFIG_CPU_IDLE
201 214
202static void 215static void
@@ -239,19 +252,6 @@ acpi_processor_power_activate(struct acpi_processor *pr,
239 return; 252 return;
240} 253}
241 254
242static void acpi_safe_halt(void)
243{
244 current_thread_info()->status &= ~TS_POLLING;
245 /*
246 * TS_POLLING-cleared state must be visible before we
247 * test NEED_RESCHED:
248 */
249 smp_mb();
250 if (!need_resched())
251 safe_halt();
252 current_thread_info()->status |= TS_POLLING;
253}
254
255static atomic_t c3_cpu_count; 255static atomic_t c3_cpu_count;
256 256
257/* Common C-state entry for C2, C3, .. */ 257/* Common C-state entry for C2, C3, .. */
@@ -531,6 +531,11 @@ static void acpi_processor_idle(void)
531 531
532 case ACPI_STATE_C3: 532 case ACPI_STATE_C3:
533 /* 533 /*
534 * Must be done before busmaster disable as we might
535 * need to access HPET !
536 */
537 acpi_state_timer_broadcast(pr, cx, 1);
538 /*
534 * disable bus master 539 * disable bus master
535 * bm_check implies we need ARB_DIS 540 * bm_check implies we need ARB_DIS
536 * !bm_check implies we need cache flush 541 * !bm_check implies we need cache flush
@@ -557,7 +562,6 @@ static void acpi_processor_idle(void)
557 /* Get start time (ticks) */ 562 /* Get start time (ticks) */
558 t1 = inl(acpi_gbl_FADT.xpm_timer_block.address); 563 t1 = inl(acpi_gbl_FADT.xpm_timer_block.address);
559 /* Invoke C3 */ 564 /* Invoke C3 */
560 acpi_state_timer_broadcast(pr, cx, 1);
561 /* Tell the scheduler that we are going deep-idle: */ 565 /* Tell the scheduler that we are going deep-idle: */
562 sched_clock_idle_sleep_event(); 566 sched_clock_idle_sleep_event();
563 acpi_cstate_enter(cx); 567 acpi_cstate_enter(cx);
@@ -1373,15 +1377,7 @@ static int acpi_idle_enter_c1(struct cpuidle_device *dev,
1373 if (pr->flags.bm_check) 1377 if (pr->flags.bm_check)
1374 acpi_idle_update_bm_rld(pr, cx); 1378 acpi_idle_update_bm_rld(pr, cx);
1375 1379
1376 current_thread_info()->status &= ~TS_POLLING; 1380 acpi_safe_halt();
1377 /*
1378 * TS_POLLING-cleared state must be visible before we test
1379 * NEED_RESCHED:
1380 */
1381 smp_mb();
1382 if (!need_resched())
1383 safe_halt();
1384 current_thread_info()->status |= TS_POLLING;
1385 1381
1386 cx->usage++; 1382 cx->usage++;
1387 1383
@@ -1399,6 +1395,8 @@ static int acpi_idle_enter_simple(struct cpuidle_device *dev,
1399 struct acpi_processor *pr; 1395 struct acpi_processor *pr;
1400 struct acpi_processor_cx *cx = cpuidle_get_statedata(state); 1396 struct acpi_processor_cx *cx = cpuidle_get_statedata(state);
1401 u32 t1, t2; 1397 u32 t1, t2;
1398 int sleep_ticks = 0;
1399
1402 pr = processors[smp_processor_id()]; 1400 pr = processors[smp_processor_id()];
1403 1401
1404 if (unlikely(!pr)) 1402 if (unlikely(!pr))
@@ -1407,9 +1405,6 @@ static int acpi_idle_enter_simple(struct cpuidle_device *dev,
1407 if (acpi_idle_suspend) 1405 if (acpi_idle_suspend)
1408 return(acpi_idle_enter_c1(dev, state)); 1406 return(acpi_idle_enter_c1(dev, state));
1409 1407
1410 if (pr->flags.bm_check)
1411 acpi_idle_update_bm_rld(pr, cx);
1412
1413 local_irq_disable(); 1408 local_irq_disable();
1414 current_thread_info()->status &= ~TS_POLLING; 1409 current_thread_info()->status &= ~TS_POLLING;
1415 /* 1410 /*
@@ -1424,11 +1419,21 @@ static int acpi_idle_enter_simple(struct cpuidle_device *dev,
1424 return 0; 1419 return 0;
1425 } 1420 }
1426 1421
1422 /*
1423 * Must be done before busmaster disable as we might need to
1424 * access HPET !
1425 */
1426 acpi_state_timer_broadcast(pr, cx, 1);
1427
1428 if (pr->flags.bm_check)
1429 acpi_idle_update_bm_rld(pr, cx);
1430
1427 if (cx->type == ACPI_STATE_C3) 1431 if (cx->type == ACPI_STATE_C3)
1428 ACPI_FLUSH_CPU_CACHE(); 1432 ACPI_FLUSH_CPU_CACHE();
1429 1433
1430 t1 = inl(acpi_gbl_FADT.xpm_timer_block.address); 1434 t1 = inl(acpi_gbl_FADT.xpm_timer_block.address);
1431 acpi_state_timer_broadcast(pr, cx, 1); 1435 /* Tell the scheduler that we are going deep-idle: */
1436 sched_clock_idle_sleep_event();
1432 acpi_idle_do_entry(cx); 1437 acpi_idle_do_entry(cx);
1433 t2 = inl(acpi_gbl_FADT.xpm_timer_block.address); 1438 t2 = inl(acpi_gbl_FADT.xpm_timer_block.address);
1434 1439
@@ -1436,6 +1441,10 @@ static int acpi_idle_enter_simple(struct cpuidle_device *dev,
1436 /* TSC could halt in idle, so notify users */ 1441 /* TSC could halt in idle, so notify users */
1437 mark_tsc_unstable("TSC halts in idle");; 1442 mark_tsc_unstable("TSC halts in idle");;
1438#endif 1443#endif
1444 sleep_ticks = ticks_elapsed(t1, t2);
1445
1446 /* Tell the scheduler how much we idled: */
1447 sched_clock_idle_wakeup_event(sleep_ticks*PM_TIMER_TICK_NS);
1439 1448
1440 local_irq_enable(); 1449 local_irq_enable();
1441 current_thread_info()->status |= TS_POLLING; 1450 current_thread_info()->status |= TS_POLLING;
@@ -1443,7 +1452,7 @@ static int acpi_idle_enter_simple(struct cpuidle_device *dev,
1443 cx->usage++; 1452 cx->usage++;
1444 1453
1445 acpi_state_timer_broadcast(pr, cx, 0); 1454 acpi_state_timer_broadcast(pr, cx, 0);
1446 cx->time += ticks_elapsed(t1, t2); 1455 cx->time += sleep_ticks;
1447 return ticks_elapsed_in_us(t1, t2); 1456 return ticks_elapsed_in_us(t1, t2);
1448} 1457}
1449 1458
@@ -1463,6 +1472,8 @@ static int acpi_idle_enter_bm(struct cpuidle_device *dev,
1463 struct acpi_processor *pr; 1472 struct acpi_processor *pr;
1464 struct acpi_processor_cx *cx = cpuidle_get_statedata(state); 1473 struct acpi_processor_cx *cx = cpuidle_get_statedata(state);
1465 u32 t1, t2; 1474 u32 t1, t2;
1475 int sleep_ticks = 0;
1476
1466 pr = processors[smp_processor_id()]; 1477 pr = processors[smp_processor_id()];
1467 1478
1468 if (unlikely(!pr)) 1479 if (unlikely(!pr))
@@ -1471,6 +1482,15 @@ static int acpi_idle_enter_bm(struct cpuidle_device *dev,
1471 if (acpi_idle_suspend) 1482 if (acpi_idle_suspend)
1472 return(acpi_idle_enter_c1(dev, state)); 1483 return(acpi_idle_enter_c1(dev, state));
1473 1484
1485 if (acpi_idle_bm_check()) {
1486 if (dev->safe_state) {
1487 return dev->safe_state->enter(dev, dev->safe_state);
1488 } else {
1489 acpi_safe_halt();
1490 return 0;
1491 }
1492 }
1493
1474 local_irq_disable(); 1494 local_irq_disable();
1475 current_thread_info()->status &= ~TS_POLLING; 1495 current_thread_info()->status &= ~TS_POLLING;
1476 /* 1496 /*
@@ -1485,38 +1505,45 @@ static int acpi_idle_enter_bm(struct cpuidle_device *dev,
1485 return 0; 1505 return 0;
1486 } 1506 }
1487 1507
1508 /* Tell the scheduler that we are going deep-idle: */
1509 sched_clock_idle_sleep_event();
1488 /* 1510 /*
1489 * Must be done before busmaster disable as we might need to 1511 * Must be done before busmaster disable as we might need to
1490 * access HPET ! 1512 * access HPET !
1491 */ 1513 */
1492 acpi_state_timer_broadcast(pr, cx, 1); 1514 acpi_state_timer_broadcast(pr, cx, 1);
1493 1515
1494 if (acpi_idle_bm_check()) { 1516 acpi_idle_update_bm_rld(pr, cx);
1495 cx = pr->power.bm_state;
1496
1497 acpi_idle_update_bm_rld(pr, cx);
1498
1499 t1 = inl(acpi_gbl_FADT.xpm_timer_block.address);
1500 acpi_idle_do_entry(cx);
1501 t2 = inl(acpi_gbl_FADT.xpm_timer_block.address);
1502 } else {
1503 acpi_idle_update_bm_rld(pr, cx);
1504 1517
1518 /*
1519 * disable bus master
1520 * bm_check implies we need ARB_DIS
1521 * !bm_check implies we need cache flush
1522 * bm_control implies whether we can do ARB_DIS
1523 *
1524 * That leaves a case where bm_check is set and bm_control is
1525 * not set. In that case we cannot do much, we enter C3
1526 * without doing anything.
1527 */
1528 if (pr->flags.bm_check && pr->flags.bm_control) {
1505 spin_lock(&c3_lock); 1529 spin_lock(&c3_lock);
1506 c3_cpu_count++; 1530 c3_cpu_count++;
1507 /* Disable bus master arbitration when all CPUs are in C3 */ 1531 /* Disable bus master arbitration when all CPUs are in C3 */
1508 if (c3_cpu_count == num_online_cpus()) 1532 if (c3_cpu_count == num_online_cpus())
1509 acpi_set_register(ACPI_BITREG_ARB_DISABLE, 1); 1533 acpi_set_register(ACPI_BITREG_ARB_DISABLE, 1);
1510 spin_unlock(&c3_lock); 1534 spin_unlock(&c3_lock);
1535 } else if (!pr->flags.bm_check) {
1536 ACPI_FLUSH_CPU_CACHE();
1537 }
1511 1538
1512 t1 = inl(acpi_gbl_FADT.xpm_timer_block.address); 1539 t1 = inl(acpi_gbl_FADT.xpm_timer_block.address);
1513 acpi_idle_do_entry(cx); 1540 acpi_idle_do_entry(cx);
1514 t2 = inl(acpi_gbl_FADT.xpm_timer_block.address); 1541 t2 = inl(acpi_gbl_FADT.xpm_timer_block.address);
1515 1542
1543 /* Re-enable bus master arbitration */
1544 if (pr->flags.bm_check && pr->flags.bm_control) {
1516 spin_lock(&c3_lock); 1545 spin_lock(&c3_lock);
1517 /* Re-enable bus master arbitration */ 1546 acpi_set_register(ACPI_BITREG_ARB_DISABLE, 0);
1518 if (c3_cpu_count == num_online_cpus())
1519 acpi_set_register(ACPI_BITREG_ARB_DISABLE, 0);
1520 c3_cpu_count--; 1547 c3_cpu_count--;
1521 spin_unlock(&c3_lock); 1548 spin_unlock(&c3_lock);
1522 } 1549 }
@@ -1525,6 +1552,9 @@ static int acpi_idle_enter_bm(struct cpuidle_device *dev,
1525 /* TSC could halt in idle, so notify users */ 1552 /* TSC could halt in idle, so notify users */
1526 mark_tsc_unstable("TSC halts in idle"); 1553 mark_tsc_unstable("TSC halts in idle");
1527#endif 1554#endif
1555 sleep_ticks = ticks_elapsed(t1, t2);
1556 /* Tell the scheduler how much we idled: */
1557 sched_clock_idle_wakeup_event(sleep_ticks*PM_TIMER_TICK_NS);
1528 1558
1529 local_irq_enable(); 1559 local_irq_enable();
1530 current_thread_info()->status |= TS_POLLING; 1560 current_thread_info()->status |= TS_POLLING;
@@ -1532,7 +1562,7 @@ static int acpi_idle_enter_bm(struct cpuidle_device *dev,
1532 cx->usage++; 1562 cx->usage++;
1533 1563
1534 acpi_state_timer_broadcast(pr, cx, 0); 1564 acpi_state_timer_broadcast(pr, cx, 0);
1535 cx->time += ticks_elapsed(t1, t2); 1565 cx->time += sleep_ticks;
1536 return ticks_elapsed_in_us(t1, t2); 1566 return ticks_elapsed_in_us(t1, t2);
1537} 1567}
1538 1568
@@ -1584,12 +1614,14 @@ static int acpi_processor_setup_cpuidle(struct acpi_processor *pr)
1584 case ACPI_STATE_C1: 1614 case ACPI_STATE_C1:
1585 state->flags |= CPUIDLE_FLAG_SHALLOW; 1615 state->flags |= CPUIDLE_FLAG_SHALLOW;
1586 state->enter = acpi_idle_enter_c1; 1616 state->enter = acpi_idle_enter_c1;
1617 dev->safe_state = state;
1587 break; 1618 break;
1588 1619
1589 case ACPI_STATE_C2: 1620 case ACPI_STATE_C2:
1590 state->flags |= CPUIDLE_FLAG_BALANCED; 1621 state->flags |= CPUIDLE_FLAG_BALANCED;
1591 state->flags |= CPUIDLE_FLAG_TIME_VALID; 1622 state->flags |= CPUIDLE_FLAG_TIME_VALID;
1592 state->enter = acpi_idle_enter_simple; 1623 state->enter = acpi_idle_enter_simple;
1624 dev->safe_state = state;
1593 break; 1625 break;
1594 1626
1595 case ACPI_STATE_C3: 1627 case ACPI_STATE_C3:
@@ -1610,14 +1642,6 @@ static int acpi_processor_setup_cpuidle(struct acpi_processor *pr)
1610 if (!count) 1642 if (!count)
1611 return -EINVAL; 1643 return -EINVAL;
1612 1644
1613 /* find the deepest state that can handle active BM */
1614 if (pr->flags.bm_check) {
1615 for (i = 1; i < ACPI_PROCESSOR_MAX_POWER && i <= max_cstate; i++)
1616 if (pr->power.states[i].type == ACPI_STATE_C3)
1617 break;
1618 pr->power.bm_state = &pr->power.states[i-1];
1619 }
1620
1621 return 0; 1645 return 0;
1622} 1646}
1623 1647
@@ -1658,6 +1682,7 @@ int __cpuinit acpi_processor_power_init(struct acpi_processor *pr,
1658 1682
1659 if (!first_run) { 1683 if (!first_run) {
1660 dmi_check_system(processor_power_dmi_table); 1684 dmi_check_system(processor_power_dmi_table);
1685 max_cstate = acpi_processor_cstate_check(max_cstate);
1661 if (max_cstate < ACPI_C_STATES_MAX) 1686 if (max_cstate < ACPI_C_STATES_MAX)
1662 printk(KERN_NOTICE 1687 printk(KERN_NOTICE
1663 "ACPI: processor limited to max C-state %d\n", 1688 "ACPI: processor limited to max C-state %d\n",
diff --git a/drivers/acpi/processor_throttling.c b/drivers/acpi/processor_throttling.c
index 0b8204e7082a..6742d7bc4777 100644
--- a/drivers/acpi/processor_throttling.c
+++ b/drivers/acpi/processor_throttling.c
@@ -29,6 +29,7 @@
29#include <linux/kernel.h> 29#include <linux/kernel.h>
30#include <linux/module.h> 30#include <linux/module.h>
31#include <linux/init.h> 31#include <linux/init.h>
32#include <linux/sched.h>
32#include <linux/cpufreq.h> 33#include <linux/cpufreq.h>
33#include <linux/proc_fs.h> 34#include <linux/proc_fs.h>
34#include <linux/seq_file.h> 35#include <linux/seq_file.h>
@@ -70,7 +71,55 @@ static int acpi_processor_get_platform_limit(struct acpi_processor *pr)
70 71
71int acpi_processor_tstate_has_changed(struct acpi_processor *pr) 72int acpi_processor_tstate_has_changed(struct acpi_processor *pr)
72{ 73{
73 return acpi_processor_get_platform_limit(pr); 74 int result = 0;
75 int throttling_limit;
76 int current_state;
77 struct acpi_processor_limit *limit;
78 int target_state;
79
80 result = acpi_processor_get_platform_limit(pr);
81 if (result) {
82 /* Throttling Limit is unsupported */
83 return result;
84 }
85
86 throttling_limit = pr->throttling_platform_limit;
87 if (throttling_limit >= pr->throttling.state_count) {
88 /* Uncorrect Throttling Limit */
89 return -EINVAL;
90 }
91
92 current_state = pr->throttling.state;
93 if (current_state > throttling_limit) {
94 /*
95 * The current state can meet the requirement of
96 * _TPC limit. But it is reasonable that OSPM changes
97 * t-states from high to low for better performance.
98 * Of course the limit condition of thermal
99 * and user should be considered.
100 */
101 limit = &pr->limit;
102 target_state = throttling_limit;
103 if (limit->thermal.tx > target_state)
104 target_state = limit->thermal.tx;
105 if (limit->user.tx > target_state)
106 target_state = limit->user.tx;
107 } else if (current_state == throttling_limit) {
108 /*
109 * Unnecessary to change the throttling state
110 */
111 return 0;
112 } else {
113 /*
114 * If the current state is lower than the limit of _TPC, it
115 * will be forced to switch to the throttling state defined
116 * by throttling_platfor_limit.
117 * Because the previous state meets with the limit condition
118 * of thermal and user, it is unnecessary to check it again.
119 */
120 target_state = throttling_limit;
121 }
122 return acpi_processor_set_throttling(pr, target_state);
74} 123}
75 124
76/* 125/*
@@ -83,6 +132,7 @@ static int acpi_processor_get_throttling_control(struct acpi_processor *pr)
83 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; 132 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
84 union acpi_object *ptc = NULL; 133 union acpi_object *ptc = NULL;
85 union acpi_object obj = { 0 }; 134 union acpi_object obj = { 0 };
135 struct acpi_processor_throttling *throttling;
86 136
87 status = acpi_evaluate_object(pr->handle, "_PTC", NULL, &buffer); 137 status = acpi_evaluate_object(pr->handle, "_PTC", NULL, &buffer);
88 if (ACPI_FAILURE(status)) { 138 if (ACPI_FAILURE(status)) {
@@ -134,6 +184,22 @@ static int acpi_processor_get_throttling_control(struct acpi_processor *pr)
134 memcpy(&pr->throttling.status_register, obj.buffer.pointer, 184 memcpy(&pr->throttling.status_register, obj.buffer.pointer,
135 sizeof(struct acpi_ptc_register)); 185 sizeof(struct acpi_ptc_register));
136 186
187 throttling = &pr->throttling;
188
189 if ((throttling->control_register.bit_width +
190 throttling->control_register.bit_offset) > 32) {
191 printk(KERN_ERR PREFIX "Invalid _PTC control register\n");
192 result = -EFAULT;
193 goto end;
194 }
195
196 if ((throttling->status_register.bit_width +
197 throttling->status_register.bit_offset) > 32) {
198 printk(KERN_ERR PREFIX "Invalid _PTC status register\n");
199 result = -EFAULT;
200 goto end;
201 }
202
137 end: 203 end:
138 kfree(buffer.pointer); 204 kfree(buffer.pointer);
139 205
@@ -328,44 +394,132 @@ static int acpi_processor_get_throttling_fadt(struct acpi_processor *pr)
328 return 0; 394 return 0;
329} 395}
330 396
331static int acpi_read_throttling_status(struct acpi_processor_throttling 397#ifdef CONFIG_X86
332 *throttling) 398static int acpi_throttling_rdmsr(struct acpi_processor *pr,
399 acpi_integer * value)
400{
401 struct cpuinfo_x86 *c;
402 u64 msr_high, msr_low;
403 unsigned int cpu;
404 u64 msr = 0;
405 int ret = -1;
406
407 cpu = pr->id;
408 c = &cpu_data(cpu);
409
410 if ((c->x86_vendor != X86_VENDOR_INTEL) ||
411 !cpu_has(c, X86_FEATURE_ACPI)) {
412 printk(KERN_ERR PREFIX
413 "HARDWARE addr space,NOT supported yet\n");
414 } else {
415 msr_low = 0;
416 msr_high = 0;
417 rdmsr_safe(MSR_IA32_THERM_CONTROL,
418 (u32 *)&msr_low , (u32 *) &msr_high);
419 msr = (msr_high << 32) | msr_low;
420 *value = (acpi_integer) msr;
421 ret = 0;
422 }
423 return ret;
424}
425
426static int acpi_throttling_wrmsr(struct acpi_processor *pr, acpi_integer value)
333{ 427{
334 int value = -1; 428 struct cpuinfo_x86 *c;
429 unsigned int cpu;
430 int ret = -1;
431 u64 msr;
432
433 cpu = pr->id;
434 c = &cpu_data(cpu);
435
436 if ((c->x86_vendor != X86_VENDOR_INTEL) ||
437 !cpu_has(c, X86_FEATURE_ACPI)) {
438 printk(KERN_ERR PREFIX
439 "HARDWARE addr space,NOT supported yet\n");
440 } else {
441 msr = value;
442 wrmsr_safe(MSR_IA32_THERM_CONTROL,
443 msr & 0xffffffff, msr >> 32);
444 ret = 0;
445 }
446 return ret;
447}
448#else
449static int acpi_throttling_rdmsr(struct acpi_processor *pr,
450 acpi_integer * value)
451{
452 printk(KERN_ERR PREFIX
453 "HARDWARE addr space,NOT supported yet\n");
454 return -1;
455}
456
457static int acpi_throttling_wrmsr(struct acpi_processor *pr, acpi_integer value)
458{
459 printk(KERN_ERR PREFIX
460 "HARDWARE addr space,NOT supported yet\n");
461 return -1;
462}
463#endif
464
465static int acpi_read_throttling_status(struct acpi_processor *pr,
466 acpi_integer *value)
467{
468 u32 bit_width, bit_offset;
469 u64 ptc_value;
470 u64 ptc_mask;
471 struct acpi_processor_throttling *throttling;
472 int ret = -1;
473
474 throttling = &pr->throttling;
335 switch (throttling->status_register.space_id) { 475 switch (throttling->status_register.space_id) {
336 case ACPI_ADR_SPACE_SYSTEM_IO: 476 case ACPI_ADR_SPACE_SYSTEM_IO:
477 ptc_value = 0;
478 bit_width = throttling->status_register.bit_width;
479 bit_offset = throttling->status_register.bit_offset;
480
337 acpi_os_read_port((acpi_io_address) throttling->status_register. 481 acpi_os_read_port((acpi_io_address) throttling->status_register.
338 address, &value, 482 address, (u32 *) &ptc_value,
339 (u32) throttling->status_register.bit_width * 483 (u32) (bit_width + bit_offset));
340 8); 484 ptc_mask = (1 << bit_width) - 1;
485 *value = (acpi_integer) ((ptc_value >> bit_offset) & ptc_mask);
486 ret = 0;
341 break; 487 break;
342 case ACPI_ADR_SPACE_FIXED_HARDWARE: 488 case ACPI_ADR_SPACE_FIXED_HARDWARE:
343 printk(KERN_ERR PREFIX 489 ret = acpi_throttling_rdmsr(pr, value);
344 "HARDWARE addr space,NOT supported yet\n");
345 break; 490 break;
346 default: 491 default:
347 printk(KERN_ERR PREFIX "Unknown addr space %d\n", 492 printk(KERN_ERR PREFIX "Unknown addr space %d\n",
348 (u32) (throttling->status_register.space_id)); 493 (u32) (throttling->status_register.space_id));
349 } 494 }
350 return value; 495 return ret;
351} 496}
352 497
353static int acpi_write_throttling_state(struct acpi_processor_throttling 498static int acpi_write_throttling_state(struct acpi_processor *pr,
354 *throttling, int value) 499 acpi_integer value)
355{ 500{
501 u32 bit_width, bit_offset;
502 u64 ptc_value;
503 u64 ptc_mask;
504 struct acpi_processor_throttling *throttling;
356 int ret = -1; 505 int ret = -1;
357 506
507 throttling = &pr->throttling;
358 switch (throttling->control_register.space_id) { 508 switch (throttling->control_register.space_id) {
359 case ACPI_ADR_SPACE_SYSTEM_IO: 509 case ACPI_ADR_SPACE_SYSTEM_IO:
510 bit_width = throttling->control_register.bit_width;
511 bit_offset = throttling->control_register.bit_offset;
512 ptc_mask = (1 << bit_width) - 1;
513 ptc_value = value & ptc_mask;
514
360 acpi_os_write_port((acpi_io_address) throttling-> 515 acpi_os_write_port((acpi_io_address) throttling->
361 control_register.address, value, 516 control_register.address,
362 (u32) throttling->control_register. 517 (u32) (ptc_value << bit_offset),
363 bit_width * 8); 518 (u32) (bit_width + bit_offset));
364 ret = 0; 519 ret = 0;
365 break; 520 break;
366 case ACPI_ADR_SPACE_FIXED_HARDWARE: 521 case ACPI_ADR_SPACE_FIXED_HARDWARE:
367 printk(KERN_ERR PREFIX 522 ret = acpi_throttling_wrmsr(pr, value);
368 "HARDWARE addr space,NOT supported yet\n");
369 break; 523 break;
370 default: 524 default:
371 printk(KERN_ERR PREFIX "Unknown addr space %d\n", 525 printk(KERN_ERR PREFIX "Unknown addr space %d\n",
@@ -374,7 +528,8 @@ static int acpi_write_throttling_state(struct acpi_processor_throttling
374 return ret; 528 return ret;
375} 529}
376 530
377static int acpi_get_throttling_state(struct acpi_processor *pr, int value) 531static int acpi_get_throttling_state(struct acpi_processor *pr,
532 acpi_integer value)
378{ 533{
379 int i; 534 int i;
380 535
@@ -390,22 +545,26 @@ static int acpi_get_throttling_state(struct acpi_processor *pr, int value)
390 return i; 545 return i;
391} 546}
392 547
393static int acpi_get_throttling_value(struct acpi_processor *pr, int state) 548static int acpi_get_throttling_value(struct acpi_processor *pr,
549 int state, acpi_integer *value)
394{ 550{
395 int value = -1; 551 int ret = -1;
552
396 if (state >= 0 && state <= pr->throttling.state_count) { 553 if (state >= 0 && state <= pr->throttling.state_count) {
397 struct acpi_processor_tx_tss *tx = 554 struct acpi_processor_tx_tss *tx =
398 (struct acpi_processor_tx_tss *)&(pr->throttling. 555 (struct acpi_processor_tx_tss *)&(pr->throttling.
399 states_tss[state]); 556 states_tss[state]);
400 value = tx->control; 557 *value = tx->control;
558 ret = 0;
401 } 559 }
402 return value; 560 return ret;
403} 561}
404 562
405static int acpi_processor_get_throttling_ptc(struct acpi_processor *pr) 563static int acpi_processor_get_throttling_ptc(struct acpi_processor *pr)
406{ 564{
407 int state = 0; 565 int state = 0;
408 u32 value = 0; 566 int ret;
567 acpi_integer value;
409 568
410 if (!pr) 569 if (!pr)
411 return -EINVAL; 570 return -EINVAL;
@@ -414,20 +573,66 @@ static int acpi_processor_get_throttling_ptc(struct acpi_processor *pr)
414 return -ENODEV; 573 return -ENODEV;
415 574
416 pr->throttling.state = 0; 575 pr->throttling.state = 0;
417 local_irq_disable(); 576
418 value = acpi_read_throttling_status(&pr->throttling); 577 value = 0;
419 if (value >= 0) { 578 ret = acpi_read_throttling_status(pr, &value);
579 if (ret >= 0) {
420 state = acpi_get_throttling_state(pr, value); 580 state = acpi_get_throttling_state(pr, value);
421 pr->throttling.state = state; 581 pr->throttling.state = state;
422 } 582 }
423 local_irq_enable();
424 583
425 return 0; 584 return 0;
426} 585}
427 586
428static int acpi_processor_get_throttling(struct acpi_processor *pr) 587static int acpi_processor_get_throttling(struct acpi_processor *pr)
429{ 588{
430 return pr->throttling.acpi_processor_get_throttling(pr); 589 cpumask_t saved_mask;
590 int ret;
591
592 /*
593 * Migrate task to the cpu pointed by pr.
594 */
595 saved_mask = current->cpus_allowed;
596 set_cpus_allowed(current, cpumask_of_cpu(pr->id));
597 ret = pr->throttling.acpi_processor_get_throttling(pr);
598 /* restore the previous state */
599 set_cpus_allowed(current, saved_mask);
600
601 return ret;
602}
603
604static int acpi_processor_get_fadt_info(struct acpi_processor *pr)
605{
606 int i, step;
607
608 if (!pr->throttling.address) {
609 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No throttling register\n"));
610 return -EINVAL;
611 } else if (!pr->throttling.duty_width) {
612 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No throttling states\n"));
613 return -EINVAL;
614 }
615 /* TBD: Support duty_cycle values that span bit 4. */
616 else if ((pr->throttling.duty_offset + pr->throttling.duty_width) > 4) {
617 printk(KERN_WARNING PREFIX "duty_cycle spans bit 4\n");
618 return -EINVAL;
619 }
620
621 pr->throttling.state_count = 1 << acpi_gbl_FADT.duty_width;
622
623 /*
624 * Compute state values. Note that throttling displays a linear power
625 * performance relationship (at 50% performance the CPU will consume
626 * 50% power). Values are in 1/10th of a percent to preserve accuracy.
627 */
628
629 step = (1000 / pr->throttling.state_count);
630
631 for (i = 0; i < pr->throttling.state_count; i++) {
632 pr->throttling.states[i].performance = 1000 - step * i;
633 pr->throttling.states[i].power = 1000 - step * i;
634 }
635 return 0;
431} 636}
432 637
433static int acpi_processor_set_throttling_fadt(struct acpi_processor *pr, 638static int acpi_processor_set_throttling_fadt(struct acpi_processor *pr,
@@ -506,7 +711,8 @@ static int acpi_processor_set_throttling_fadt(struct acpi_processor *pr,
506static int acpi_processor_set_throttling_ptc(struct acpi_processor *pr, 711static int acpi_processor_set_throttling_ptc(struct acpi_processor *pr,
507 int state) 712 int state)
508{ 713{
509 u32 value = 0; 714 int ret;
715 acpi_integer value;
510 716
511 if (!pr) 717 if (!pr)
512 return -EINVAL; 718 return -EINVAL;
@@ -523,28 +729,34 @@ static int acpi_processor_set_throttling_ptc(struct acpi_processor *pr,
523 if (state < pr->throttling_platform_limit) 729 if (state < pr->throttling_platform_limit)
524 return -EPERM; 730 return -EPERM;
525 731
526 local_irq_disable(); 732 value = 0;
527 733 ret = acpi_get_throttling_value(pr, state, &value);
528 value = acpi_get_throttling_value(pr, state); 734 if (ret >= 0) {
529 if (value >= 0) { 735 acpi_write_throttling_state(pr, value);
530 acpi_write_throttling_state(&pr->throttling, value);
531 pr->throttling.state = state; 736 pr->throttling.state = state;
532 } 737 }
533 local_irq_enable();
534 738
535 return 0; 739 return 0;
536} 740}
537 741
538int acpi_processor_set_throttling(struct acpi_processor *pr, int state) 742int acpi_processor_set_throttling(struct acpi_processor *pr, int state)
539{ 743{
540 return pr->throttling.acpi_processor_set_throttling(pr, state); 744 cpumask_t saved_mask;
745 int ret;
746 /*
747 * Migrate task to the cpu pointed by pr.
748 */
749 saved_mask = current->cpus_allowed;
750 set_cpus_allowed(current, cpumask_of_cpu(pr->id));
751 ret = pr->throttling.acpi_processor_set_throttling(pr, state);
752 /* restore the previous state */
753 set_cpus_allowed(current, saved_mask);
754 return ret;
541} 755}
542 756
543int acpi_processor_get_throttling_info(struct acpi_processor *pr) 757int acpi_processor_get_throttling_info(struct acpi_processor *pr)
544{ 758{
545 int result = 0; 759 int result = 0;
546 int step = 0;
547 int i = 0;
548 760
549 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 761 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
550 "pblk_address[0x%08x] duty_offset[%d] duty_width[%d]\n", 762 "pblk_address[0x%08x] duty_offset[%d] duty_width[%d]\n",
@@ -563,6 +775,8 @@ int acpi_processor_get_throttling_info(struct acpi_processor *pr)
563 acpi_processor_get_throttling_states(pr) || 775 acpi_processor_get_throttling_states(pr) ||
564 acpi_processor_get_platform_limit(pr)) 776 acpi_processor_get_platform_limit(pr))
565 { 777 {
778 if (acpi_processor_get_fadt_info(pr))
779 return 0;
566 pr->throttling.acpi_processor_get_throttling = 780 pr->throttling.acpi_processor_get_throttling =
567 &acpi_processor_get_throttling_fadt; 781 &acpi_processor_get_throttling_fadt;
568 pr->throttling.acpi_processor_set_throttling = 782 pr->throttling.acpi_processor_set_throttling =
@@ -576,19 +790,6 @@ int acpi_processor_get_throttling_info(struct acpi_processor *pr)
576 790
577 acpi_processor_get_tsd(pr); 791 acpi_processor_get_tsd(pr);
578 792
579 if (!pr->throttling.address) {
580 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No throttling register\n"));
581 return 0;
582 } else if (!pr->throttling.duty_width) {
583 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No throttling states\n"));
584 return 0;
585 }
586 /* TBD: Support duty_cycle values that span bit 4. */
587 else if ((pr->throttling.duty_offset + pr->throttling.duty_width) > 4) {
588 printk(KERN_WARNING PREFIX "duty_cycle spans bit 4\n");
589 return 0;
590 }
591
592 /* 793 /*
593 * PIIX4 Errata: We don't support throttling on the original PIIX4. 794 * PIIX4 Errata: We don't support throttling on the original PIIX4.
594 * This shouldn't be an issue as few (if any) mobile systems ever 795 * This shouldn't be an issue as few (if any) mobile systems ever
@@ -600,21 +801,6 @@ int acpi_processor_get_throttling_info(struct acpi_processor *pr)
600 return 0; 801 return 0;
601 } 802 }
602 803
603 pr->throttling.state_count = 1 << acpi_gbl_FADT.duty_width;
604
605 /*
606 * Compute state values. Note that throttling displays a linear power/
607 * performance relationship (at 50% performance the CPU will consume
608 * 50% power). Values are in 1/10th of a percent to preserve accuracy.
609 */
610
611 step = (1000 / pr->throttling.state_count);
612
613 for (i = 0; i < pr->throttling.state_count; i++) {
614 pr->throttling.states[i].performance = step * i;
615 pr->throttling.states[i].power = step * i;
616 }
617
618 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d throttling states\n", 804 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d throttling states\n",
619 pr->throttling.state_count)); 805 pr->throttling.state_count));
620 806
diff --git a/drivers/acpi/sbs.c b/drivers/acpi/sbs.c
index 90fd09c65f95..22cb95b349e4 100644
--- a/drivers/acpi/sbs.c
+++ b/drivers/acpi/sbs.c
@@ -29,7 +29,7 @@
29#include <linux/moduleparam.h> 29#include <linux/moduleparam.h>
30#include <linux/kernel.h> 30#include <linux/kernel.h>
31 31
32#ifdef CONFIG_ACPI_PROCFS 32#ifdef CONFIG_ACPI_PROCFS_POWER
33#include <linux/proc_fs.h> 33#include <linux/proc_fs.h>
34#include <linux/seq_file.h> 34#include <linux/seq_file.h>
35#include <asm/uaccess.h> 35#include <asm/uaccess.h>
@@ -54,12 +54,6 @@
54#define ACPI_BATTERY_DIR_NAME "BAT%i" 54#define ACPI_BATTERY_DIR_NAME "BAT%i"
55#define ACPI_AC_DIR_NAME "AC0" 55#define ACPI_AC_DIR_NAME "AC0"
56 56
57enum acpi_sbs_device_addr {
58 ACPI_SBS_CHARGER = 0x9,
59 ACPI_SBS_MANAGER = 0xa,
60 ACPI_SBS_BATTERY = 0xb,
61};
62
63#define ACPI_SBS_NOTIFY_STATUS 0x80 57#define ACPI_SBS_NOTIFY_STATUS 0x80
64#define ACPI_SBS_NOTIFY_INFO 0x81 58#define ACPI_SBS_NOTIFY_INFO 0x81
65 59
@@ -88,7 +82,7 @@ MODULE_DEVICE_TABLE(acpi, sbs_device_ids);
88struct acpi_battery { 82struct acpi_battery {
89 struct power_supply bat; 83 struct power_supply bat;
90 struct acpi_sbs *sbs; 84 struct acpi_sbs *sbs;
91#ifdef CONFIG_ACPI_PROCFS 85#ifdef CONFIG_ACPI_PROCFS_POWER
92 struct proc_dir_entry *proc_entry; 86 struct proc_dir_entry *proc_entry;
93#endif 87#endif
94 unsigned long update_time; 88 unsigned long update_time;
@@ -113,6 +107,7 @@ struct acpi_battery {
113 u16 spec; 107 u16 spec;
114 u8 id; 108 u8 id;
115 u8 present:1; 109 u8 present:1;
110 u8 have_sysfs_alarm:1;
116}; 111};
117 112
118#define to_acpi_battery(x) container_of(x, struct acpi_battery, bat); 113#define to_acpi_battery(x) container_of(x, struct acpi_battery, bat);
@@ -122,7 +117,7 @@ struct acpi_sbs {
122 struct acpi_device *device; 117 struct acpi_device *device;
123 struct acpi_smb_hc *hc; 118 struct acpi_smb_hc *hc;
124 struct mutex lock; 119 struct mutex lock;
125#ifdef CONFIG_ACPI_PROCFS 120#ifdef CONFIG_ACPI_PROCFS_POWER
126 struct proc_dir_entry *charger_entry; 121 struct proc_dir_entry *charger_entry;
127#endif 122#endif
128 struct acpi_battery battery[MAX_SBS_BAT]; 123 struct acpi_battery battery[MAX_SBS_BAT];
@@ -468,7 +463,7 @@ static struct device_attribute alarm_attr = {
468 FS Interface (/proc/acpi) 463 FS Interface (/proc/acpi)
469 -------------------------------------------------------------------------- */ 464 -------------------------------------------------------------------------- */
470 465
471#ifdef CONFIG_ACPI_PROCFS 466#ifdef CONFIG_ACPI_PROCFS_POWER
472/* Generic Routines */ 467/* Generic Routines */
473static int 468static int
474acpi_sbs_add_fs(struct proc_dir_entry **dir, 469acpi_sbs_add_fs(struct proc_dir_entry **dir,
@@ -538,7 +533,7 @@ static struct proc_dir_entry *acpi_battery_dir = NULL;
538 533
539static inline char *acpi_battery_units(struct acpi_battery *battery) 534static inline char *acpi_battery_units(struct acpi_battery *battery)
540{ 535{
541 return acpi_battery_mode(battery) ? " mWh" : " mAh"; 536 return acpi_battery_mode(battery) ? " mW" : " mA";
542} 537}
543 538
544 539
@@ -555,10 +550,10 @@ static int acpi_battery_read_info(struct seq_file *seq, void *offset)
555 if (!battery->present) 550 if (!battery->present)
556 goto end; 551 goto end;
557 552
558 seq_printf(seq, "design capacity: %i%s\n", 553 seq_printf(seq, "design capacity: %i%sh\n",
559 battery->design_capacity * acpi_battery_scale(battery), 554 battery->design_capacity * acpi_battery_scale(battery),
560 acpi_battery_units(battery)); 555 acpi_battery_units(battery));
561 seq_printf(seq, "last full capacity: %i%s\n", 556 seq_printf(seq, "last full capacity: %i%sh\n",
562 battery->full_charge_capacity * acpi_battery_scale(battery), 557 battery->full_charge_capacity * acpi_battery_scale(battery),
563 acpi_battery_units(battery)); 558 acpi_battery_units(battery));
564 seq_printf(seq, "battery technology: rechargeable\n"); 559 seq_printf(seq, "battery technology: rechargeable\n");
@@ -589,7 +584,7 @@ static int acpi_battery_read_state(struct seq_file *seq, void *offset)
589{ 584{
590 struct acpi_battery *battery = seq->private; 585 struct acpi_battery *battery = seq->private;
591 struct acpi_sbs *sbs = battery->sbs; 586 struct acpi_sbs *sbs = battery->sbs;
592 int result = 0; 587 int rate;
593 588
594 mutex_lock(&sbs->lock); 589 mutex_lock(&sbs->lock);
595 seq_printf(seq, "present: %s\n", 590 seq_printf(seq, "present: %s\n",
@@ -603,9 +598,12 @@ static int acpi_battery_read_state(struct seq_file *seq, void *offset)
603 seq_printf(seq, "charging state: %s\n", 598 seq_printf(seq, "charging state: %s\n",
604 (battery->current_now < 0) ? "discharging" : 599 (battery->current_now < 0) ? "discharging" :
605 ((battery->current_now > 0) ? "charging" : "charged")); 600 ((battery->current_now > 0) ? "charging" : "charged"));
606 seq_printf(seq, "present rate: %d mA\n", 601 rate = abs(battery->current_now) * acpi_battery_ipscale(battery);
607 abs(battery->current_now) * acpi_battery_ipscale(battery)); 602 rate *= (acpi_battery_mode(battery))?(battery->voltage_now *
608 seq_printf(seq, "remaining capacity: %i%s\n", 603 acpi_battery_vscale(battery)/1000):1;
604 seq_printf(seq, "present rate: %d%s\n", rate,
605 acpi_battery_units(battery));
606 seq_printf(seq, "remaining capacity: %i%sh\n",
609 battery->capacity_now * acpi_battery_scale(battery), 607 battery->capacity_now * acpi_battery_scale(battery),
610 acpi_battery_units(battery)); 608 acpi_battery_units(battery));
611 seq_printf(seq, "present voltage: %i mV\n", 609 seq_printf(seq, "present voltage: %i mV\n",
@@ -613,7 +611,7 @@ static int acpi_battery_read_state(struct seq_file *seq, void *offset)
613 611
614 end: 612 end:
615 mutex_unlock(&sbs->lock); 613 mutex_unlock(&sbs->lock);
616 return result; 614 return 0;
617} 615}
618 616
619static int acpi_battery_state_open_fs(struct inode *inode, struct file *file) 617static int acpi_battery_state_open_fs(struct inode *inode, struct file *file)
@@ -637,7 +635,7 @@ static int acpi_battery_read_alarm(struct seq_file *seq, void *offset)
637 acpi_battery_get_alarm(battery); 635 acpi_battery_get_alarm(battery);
638 seq_printf(seq, "alarm: "); 636 seq_printf(seq, "alarm: ");
639 if (battery->alarm_capacity) 637 if (battery->alarm_capacity)
640 seq_printf(seq, "%i%s\n", 638 seq_printf(seq, "%i%sh\n",
641 battery->alarm_capacity * 639 battery->alarm_capacity *
642 acpi_battery_scale(battery), 640 acpi_battery_scale(battery),
643 acpi_battery_units(battery)); 641 acpi_battery_units(battery));
@@ -789,7 +787,7 @@ static int acpi_battery_add(struct acpi_sbs *sbs, int id)
789 return result; 787 return result;
790 788
791 sprintf(battery->name, ACPI_BATTERY_DIR_NAME, id); 789 sprintf(battery->name, ACPI_BATTERY_DIR_NAME, id);
792#ifdef CONFIG_ACPI_PROCFS 790#ifdef CONFIG_ACPI_PROCFS_POWER
793 acpi_sbs_add_fs(&battery->proc_entry, acpi_battery_dir, 791 acpi_sbs_add_fs(&battery->proc_entry, acpi_battery_dir,
794 battery->name, &acpi_battery_info_fops, 792 battery->name, &acpi_battery_info_fops,
795 &acpi_battery_state_fops, &acpi_battery_alarm_fops, 793 &acpi_battery_state_fops, &acpi_battery_alarm_fops,
@@ -808,7 +806,13 @@ static int acpi_battery_add(struct acpi_sbs *sbs, int id)
808 } 806 }
809 battery->bat.get_property = acpi_sbs_battery_get_property; 807 battery->bat.get_property = acpi_sbs_battery_get_property;
810 result = power_supply_register(&sbs->device->dev, &battery->bat); 808 result = power_supply_register(&sbs->device->dev, &battery->bat);
811 device_create_file(battery->bat.dev, &alarm_attr); 809 if (result)
810 goto end;
811 result = device_create_file(battery->bat.dev, &alarm_attr);
812 if (result)
813 goto end;
814 battery->have_sysfs_alarm = 1;
815 end:
812 printk(KERN_INFO PREFIX "%s [%s]: Battery Slot [%s] (battery %s)\n", 816 printk(KERN_INFO PREFIX "%s [%s]: Battery Slot [%s] (battery %s)\n",
813 ACPI_SBS_DEVICE_NAME, acpi_device_bid(sbs->device), 817 ACPI_SBS_DEVICE_NAME, acpi_device_bid(sbs->device),
814 battery->name, sbs->battery->present ? "present" : "absent"); 818 battery->name, sbs->battery->present ? "present" : "absent");
@@ -817,14 +821,16 @@ static int acpi_battery_add(struct acpi_sbs *sbs, int id)
817 821
818static void acpi_battery_remove(struct acpi_sbs *sbs, int id) 822static void acpi_battery_remove(struct acpi_sbs *sbs, int id)
819{ 823{
820 if (sbs->battery[id].bat.dev) 824 struct acpi_battery *battery = &sbs->battery[id];
821 device_remove_file(sbs->battery[id].bat.dev, &alarm_attr); 825
822 power_supply_unregister(&sbs->battery[id].bat); 826 if (battery->bat.dev) {
823#ifdef CONFIG_ACPI_PROCFS 827 if (battery->have_sysfs_alarm)
824 if (sbs->battery[id].proc_entry) { 828 device_remove_file(battery->bat.dev, &alarm_attr);
825 acpi_sbs_remove_fs(&(sbs->battery[id].proc_entry), 829 power_supply_unregister(&battery->bat);
826 acpi_battery_dir);
827 } 830 }
831#ifdef CONFIG_ACPI_PROCFS_POWER
832 if (battery->proc_entry)
833 acpi_sbs_remove_fs(&battery->proc_entry, acpi_battery_dir);
828#endif 834#endif
829} 835}
830 836
@@ -835,7 +841,7 @@ static int acpi_charger_add(struct acpi_sbs *sbs)
835 result = acpi_ac_get_present(sbs); 841 result = acpi_ac_get_present(sbs);
836 if (result) 842 if (result)
837 goto end; 843 goto end;
838#ifdef CONFIG_ACPI_PROCFS 844#ifdef CONFIG_ACPI_PROCFS_POWER
839 result = acpi_sbs_add_fs(&sbs->charger_entry, acpi_ac_dir, 845 result = acpi_sbs_add_fs(&sbs->charger_entry, acpi_ac_dir,
840 ACPI_AC_DIR_NAME, NULL, 846 ACPI_AC_DIR_NAME, NULL,
841 &acpi_ac_state_fops, NULL, sbs); 847 &acpi_ac_state_fops, NULL, sbs);
@@ -859,7 +865,7 @@ static void acpi_charger_remove(struct acpi_sbs *sbs)
859{ 865{
860 if (sbs->charger.dev) 866 if (sbs->charger.dev)
861 power_supply_unregister(&sbs->charger); 867 power_supply_unregister(&sbs->charger);
862#ifdef CONFIG_ACPI_PROCFS 868#ifdef CONFIG_ACPI_PROCFS_POWER
863 if (sbs->charger_entry) 869 if (sbs->charger_entry)
864 acpi_sbs_remove_fs(&sbs->charger_entry, acpi_ac_dir); 870 acpi_sbs_remove_fs(&sbs->charger_entry, acpi_ac_dir);
865#endif 871#endif
@@ -965,7 +971,7 @@ static int acpi_sbs_remove(struct acpi_device *device, int type)
965 971
966static void acpi_sbs_rmdirs(void) 972static void acpi_sbs_rmdirs(void)
967{ 973{
968#ifdef CONFIG_ACPI_PROCFS 974#ifdef CONFIG_ACPI_PROCFS_POWER
969 if (acpi_ac_dir) { 975 if (acpi_ac_dir) {
970 acpi_unlock_ac_dir(acpi_ac_dir); 976 acpi_unlock_ac_dir(acpi_ac_dir);
971 acpi_ac_dir = NULL; 977 acpi_ac_dir = NULL;
@@ -1004,7 +1010,7 @@ static int __init acpi_sbs_init(void)
1004 1010
1005 if (acpi_disabled) 1011 if (acpi_disabled)
1006 return -ENODEV; 1012 return -ENODEV;
1007#ifdef CONFIG_ACPI_PROCFS 1013#ifdef CONFIG_ACPI_PROCFS_POWER
1008 acpi_ac_dir = acpi_lock_ac_dir(); 1014 acpi_ac_dir = acpi_lock_ac_dir();
1009 if (!acpi_ac_dir) 1015 if (!acpi_ac_dir)
1010 return -ENODEV; 1016 return -ENODEV;
diff --git a/drivers/acpi/sbshc.c b/drivers/acpi/sbshc.c
index 046d7c3ed356..fd40b6a1d639 100644
--- a/drivers/acpi/sbshc.c
+++ b/drivers/acpi/sbshc.c
@@ -202,10 +202,9 @@ int acpi_smbus_unregister_callback(struct acpi_smb_hc *hc)
202 202
203EXPORT_SYMBOL_GPL(acpi_smbus_unregister_callback); 203EXPORT_SYMBOL_GPL(acpi_smbus_unregister_callback);
204 204
205static void acpi_smbus_callback(void *context) 205static inline void acpi_smbus_callback(void *context)
206{ 206{
207 struct acpi_smb_hc *hc = context; 207 struct acpi_smb_hc *hc = context;
208
209 if (hc->callback) 208 if (hc->callback)
210 hc->callback(hc->context); 209 hc->callback(hc->context);
211} 210}
@@ -214,6 +213,7 @@ static int smbus_alarm(void *context)
214{ 213{
215 struct acpi_smb_hc *hc = context; 214 struct acpi_smb_hc *hc = context;
216 union acpi_smb_status status; 215 union acpi_smb_status status;
216 u8 address;
217 if (smb_hc_read(hc, ACPI_SMB_STATUS, &status.raw)) 217 if (smb_hc_read(hc, ACPI_SMB_STATUS, &status.raw))
218 return 0; 218 return 0;
219 /* Check if it is only a completion notify */ 219 /* Check if it is only a completion notify */
@@ -222,9 +222,18 @@ static int smbus_alarm(void *context)
222 if (!status.fields.alarm) 222 if (!status.fields.alarm)
223 return 0; 223 return 0;
224 mutex_lock(&hc->lock); 224 mutex_lock(&hc->lock);
225 smb_hc_read(hc, ACPI_SMB_ALARM_ADDRESS, &address);
226 status.fields.alarm = 0;
225 smb_hc_write(hc, ACPI_SMB_STATUS, status.raw); 227 smb_hc_write(hc, ACPI_SMB_STATUS, status.raw);
226 if (hc->callback) 228 /* We are only interested in events coming from known devices */
227 acpi_os_execute(OSL_GPE_HANDLER, acpi_smbus_callback, hc); 229 switch (address >> 1) {
230 case ACPI_SBS_CHARGER:
231 case ACPI_SBS_MANAGER:
232 case ACPI_SBS_BATTERY:
233 acpi_os_execute(OSL_GPE_HANDLER,
234 acpi_smbus_callback, hc);
235 default:;
236 }
228 mutex_unlock(&hc->lock); 237 mutex_unlock(&hc->lock);
229 return 0; 238 return 0;
230} 239}
diff --git a/drivers/acpi/sbshc.h b/drivers/acpi/sbshc.h
index 3bda3491a97b..a57b0762dd7f 100644
--- a/drivers/acpi/sbshc.h
+++ b/drivers/acpi/sbshc.h
@@ -16,6 +16,12 @@ enum acpi_smb_protocol {
16 16
17static const u8 SMBUS_PEC = 0x80; 17static const u8 SMBUS_PEC = 0x80;
18 18
19enum acpi_sbs_device_addr {
20 ACPI_SBS_CHARGER = 0x9,
21 ACPI_SBS_MANAGER = 0xa,
22 ACPI_SBS_BATTERY = 0xb,
23};
24
19typedef void (*smbus_alarm_callback)(void *context); 25typedef void (*smbus_alarm_callback)(void *context);
20 26
21extern int acpi_smbus_read(struct acpi_smb_hc *hc, u8 protocol, u8 address, 27extern int acpi_smbus_read(struct acpi_smb_hc *hc, u8 protocol, u8 address,
diff --git a/drivers/acpi/tables/tbutils.c b/drivers/acpi/tables/tbutils.c
index 5f1d85f2ffe4..010f19652f80 100644
--- a/drivers/acpi/tables/tbutils.c
+++ b/drivers/acpi/tables/tbutils.c
@@ -449,7 +449,7 @@ acpi_tb_parse_root_table(acpi_physical_address rsdp_address, u8 flags)
449 /* XSDT has NULL entry, RSDT is used */ 449 /* XSDT has NULL entry, RSDT is used */
450 address = rsdt_address; 450 address = rsdt_address;
451 table_entry_size = sizeof(u32); 451 table_entry_size = sizeof(u32);
452 ACPI_WARNING((AE_INFO, "BIOS XSDT has NULL entry," 452 ACPI_WARNING((AE_INFO, "BIOS XSDT has NULL entry, "
453 "using RSDT")); 453 "using RSDT"));
454 } 454 }
455 } 455 }
diff --git a/drivers/acpi/video.c b/drivers/acpi/video.c
index bac956b30c57..bd77e81e81c1 100644
--- a/drivers/acpi/video.c
+++ b/drivers/acpi/video.c
@@ -29,6 +29,7 @@
29#include <linux/init.h> 29#include <linux/init.h>
30#include <linux/types.h> 30#include <linux/types.h>
31#include <linux/list.h> 31#include <linux/list.h>
32#include <linux/mutex.h>
32#include <linux/proc_fs.h> 33#include <linux/proc_fs.h>
33#include <linux/seq_file.h> 34#include <linux/seq_file.h>
34#include <linux/input.h> 35#include <linux/input.h>
@@ -135,8 +136,8 @@ struct acpi_video_bus {
135 u8 attached_count; 136 u8 attached_count;
136 struct acpi_video_bus_cap cap; 137 struct acpi_video_bus_cap cap;
137 struct acpi_video_bus_flags flags; 138 struct acpi_video_bus_flags flags;
138 struct semaphore sem;
139 struct list_head video_device_list; 139 struct list_head video_device_list;
140 struct mutex device_list_lock; /* protects video_device_list */
140 struct proc_dir_entry *dir; 141 struct proc_dir_entry *dir;
141 struct input_dev *input; 142 struct input_dev *input;
142 char phys[32]; /* for input device */ 143 char phys[32]; /* for input device */
@@ -576,7 +577,7 @@ static void acpi_video_device_find_cap(struct acpi_video_device *device)
576 struct acpi_video_device_brightness *br = NULL; 577 struct acpi_video_device_brightness *br = NULL;
577 578
578 579
579 memset(&device->cap, 0, 4); 580 memset(&device->cap, 0, sizeof(device->cap));
580 581
581 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_ADR", &h_dummy1))) { 582 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_ADR", &h_dummy1))) {
582 device->cap._ADR = 1; 583 device->cap._ADR = 1;
@@ -696,7 +697,7 @@ static void acpi_video_bus_find_cap(struct acpi_video_bus *video)
696{ 697{
697 acpi_handle h_dummy1; 698 acpi_handle h_dummy1;
698 699
699 memset(&video->cap, 0, 4); 700 memset(&video->cap, 0, sizeof(video->cap));
700 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOS", &h_dummy1))) { 701 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOS", &h_dummy1))) {
701 video->cap._DOS = 1; 702 video->cap._DOS = 1;
702 } 703 }
@@ -896,7 +897,7 @@ acpi_video_device_write_brightness(struct file *file,
896{ 897{
897 struct seq_file *m = file->private_data; 898 struct seq_file *m = file->private_data;
898 struct acpi_video_device *dev = m->private; 899 struct acpi_video_device *dev = m->private;
899 char str[4] = { 0 }; 900 char str[5] = { 0 };
900 unsigned int level = 0; 901 unsigned int level = 0;
901 int i; 902 int i;
902 903
@@ -1436,9 +1437,9 @@ acpi_video_bus_get_one_device(struct acpi_device *device,
1436 return -ENODEV; 1437 return -ENODEV;
1437 } 1438 }
1438 1439
1439 down(&video->sem); 1440 mutex_lock(&video->device_list_lock);
1440 list_add_tail(&data->entry, &video->video_device_list); 1441 list_add_tail(&data->entry, &video->video_device_list);
1441 up(&video->sem); 1442 mutex_unlock(&video->device_list_lock);
1442 1443
1443 acpi_video_device_add_fs(device); 1444 acpi_video_device_add_fs(device);
1444 1445
@@ -1462,12 +1463,14 @@ acpi_video_bus_get_one_device(struct acpi_device *device,
1462 1463
1463static void acpi_video_device_rebind(struct acpi_video_bus *video) 1464static void acpi_video_device_rebind(struct acpi_video_bus *video)
1464{ 1465{
1465 struct list_head *node, *next; 1466 struct acpi_video_device *dev;
1466 list_for_each_safe(node, next, &video->video_device_list) { 1467
1467 struct acpi_video_device *dev = 1468 mutex_lock(&video->device_list_lock);
1468 container_of(node, struct acpi_video_device, entry); 1469
1470 list_for_each_entry(dev, &video->video_device_list, entry)
1469 acpi_video_device_bind(video, dev); 1471 acpi_video_device_bind(video, dev);
1470 } 1472
1473 mutex_unlock(&video->device_list_lock);
1471} 1474}
1472 1475
1473/* 1476/*
@@ -1592,30 +1595,33 @@ static int acpi_video_device_enumerate(struct acpi_video_bus *video)
1592 1595
1593static int acpi_video_switch_output(struct acpi_video_bus *video, int event) 1596static int acpi_video_switch_output(struct acpi_video_bus *video, int event)
1594{ 1597{
1595 struct list_head *node, *next; 1598 struct list_head *node;
1596 struct acpi_video_device *dev = NULL; 1599 struct acpi_video_device *dev = NULL;
1597 struct acpi_video_device *dev_next = NULL; 1600 struct acpi_video_device *dev_next = NULL;
1598 struct acpi_video_device *dev_prev = NULL; 1601 struct acpi_video_device *dev_prev = NULL;
1599 unsigned long state; 1602 unsigned long state;
1600 int status = 0; 1603 int status = 0;
1601 1604
1605 mutex_lock(&video->device_list_lock);
1602 1606
1603 list_for_each_safe(node, next, &video->video_device_list) { 1607 list_for_each(node, &video->video_device_list) {
1604 dev = container_of(node, struct acpi_video_device, entry); 1608 dev = container_of(node, struct acpi_video_device, entry);
1605 status = acpi_video_device_get_state(dev, &state); 1609 status = acpi_video_device_get_state(dev, &state);
1606 if (state & 0x2) { 1610 if (state & 0x2) {
1607 dev_next = 1611 dev_next = container_of(node->next,
1608 container_of(node->next, struct acpi_video_device, 1612 struct acpi_video_device, entry);
1609 entry); 1613 dev_prev = container_of(node->prev,
1610 dev_prev = 1614 struct acpi_video_device, entry);
1611 container_of(node->prev, struct acpi_video_device,
1612 entry);
1613 goto out; 1615 goto out;
1614 } 1616 }
1615 } 1617 }
1618
1616 dev_next = container_of(node->next, struct acpi_video_device, entry); 1619 dev_next = container_of(node->next, struct acpi_video_device, entry);
1617 dev_prev = container_of(node->prev, struct acpi_video_device, entry); 1620 dev_prev = container_of(node->prev, struct acpi_video_device, entry);
1618 out: 1621
1622 out:
1623 mutex_unlock(&video->device_list_lock);
1624
1619 switch (event) { 1625 switch (event) {
1620 case ACPI_VIDEO_NOTIFY_CYCLE: 1626 case ACPI_VIDEO_NOTIFY_CYCLE:
1621 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT: 1627 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT:
@@ -1691,24 +1697,17 @@ acpi_video_bus_get_devices(struct acpi_video_bus *video,
1691 struct acpi_device *device) 1697 struct acpi_device *device)
1692{ 1698{
1693 int status = 0; 1699 int status = 0;
1694 struct list_head *node, *next; 1700 struct acpi_device *dev;
1695
1696 1701
1697 acpi_video_device_enumerate(video); 1702 acpi_video_device_enumerate(video);
1698 1703
1699 list_for_each_safe(node, next, &device->children) { 1704 list_for_each_entry(dev, &device->children, node) {
1700 struct acpi_device *dev =
1701 list_entry(node, struct acpi_device, node);
1702
1703 if (!dev)
1704 continue;
1705 1705
1706 status = acpi_video_bus_get_one_device(dev, video); 1706 status = acpi_video_bus_get_one_device(dev, video);
1707 if (ACPI_FAILURE(status)) { 1707 if (ACPI_FAILURE(status)) {
1708 ACPI_EXCEPTION((AE_INFO, status, "Cant attach device")); 1708 ACPI_EXCEPTION((AE_INFO, status, "Cant attach device"));
1709 continue; 1709 continue;
1710 } 1710 }
1711
1712 } 1711 }
1713 return status; 1712 return status;
1714} 1713}
@@ -1724,9 +1723,6 @@ static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
1724 1723
1725 video = device->video; 1724 video = device->video;
1726 1725
1727 down(&video->sem);
1728 list_del(&device->entry);
1729 up(&video->sem);
1730 acpi_video_device_remove_fs(device->dev); 1726 acpi_video_device_remove_fs(device->dev);
1731 1727
1732 status = acpi_remove_notify_handler(device->dev->handle, 1728 status = acpi_remove_notify_handler(device->dev->handle,
@@ -1734,32 +1730,34 @@ static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
1734 acpi_video_device_notify); 1730 acpi_video_device_notify);
1735 backlight_device_unregister(device->backlight); 1731 backlight_device_unregister(device->backlight);
1736 video_output_unregister(device->output_dev); 1732 video_output_unregister(device->output_dev);
1733
1737 return 0; 1734 return 0;
1738} 1735}
1739 1736
1740static int acpi_video_bus_put_devices(struct acpi_video_bus *video) 1737static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
1741{ 1738{
1742 int status; 1739 int status;
1743 struct list_head *node, *next; 1740 struct acpi_video_device *dev, *next;
1744 1741
1742 mutex_lock(&video->device_list_lock);
1745 1743
1746 list_for_each_safe(node, next, &video->video_device_list) { 1744 list_for_each_entry_safe(dev, next, &video->video_device_list, entry) {
1747 struct acpi_video_device *data =
1748 list_entry(node, struct acpi_video_device, entry);
1749 if (!data)
1750 continue;
1751 1745
1752 status = acpi_video_bus_put_one_device(data); 1746 status = acpi_video_bus_put_one_device(dev);
1753 if (ACPI_FAILURE(status)) 1747 if (ACPI_FAILURE(status))
1754 printk(KERN_WARNING PREFIX 1748 printk(KERN_WARNING PREFIX
1755 "hhuuhhuu bug in acpi video driver.\n"); 1749 "hhuuhhuu bug in acpi video driver.\n");
1756 1750
1757 if (data->brightness) 1751 if (dev->brightness) {
1758 kfree(data->brightness->levels); 1752 kfree(dev->brightness->levels);
1759 kfree(data->brightness); 1753 kfree(dev->brightness);
1760 kfree(data); 1754 }
1755 list_del(&dev->entry);
1756 kfree(dev);
1761 } 1757 }
1762 1758
1759 mutex_unlock(&video->device_list_lock);
1760
1763 return 0; 1761 return 0;
1764} 1762}
1765 1763
@@ -1782,9 +1780,6 @@ static void acpi_video_bus_notify(acpi_handle handle, u32 event, void *data)
1782 struct input_dev *input; 1780 struct input_dev *input;
1783 int keycode; 1781 int keycode;
1784 1782
1785
1786 printk("video bus notify\n");
1787
1788 if (!video) 1783 if (!video)
1789 return; 1784 return;
1790 1785
@@ -1897,14 +1892,10 @@ static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data)
1897static int instance; 1892static int instance;
1898static int acpi_video_bus_add(struct acpi_device *device) 1893static int acpi_video_bus_add(struct acpi_device *device)
1899{ 1894{
1900 int result = 0; 1895 acpi_status status;
1901 acpi_status status = 0; 1896 struct acpi_video_bus *video;
1902 struct acpi_video_bus *video = NULL;
1903 struct input_dev *input; 1897 struct input_dev *input;
1904 1898 int error;
1905
1906 if (!device)
1907 return -EINVAL;
1908 1899
1909 video = kzalloc(sizeof(struct acpi_video_bus), GFP_KERNEL); 1900 video = kzalloc(sizeof(struct acpi_video_bus), GFP_KERNEL);
1910 if (!video) 1901 if (!video)
@@ -1923,15 +1914,15 @@ static int acpi_video_bus_add(struct acpi_device *device)
1923 acpi_driver_data(device) = video; 1914 acpi_driver_data(device) = video;
1924 1915
1925 acpi_video_bus_find_cap(video); 1916 acpi_video_bus_find_cap(video);
1926 result = acpi_video_bus_check(video); 1917 error = acpi_video_bus_check(video);
1927 if (result) 1918 if (error)
1928 goto end; 1919 goto err_free_video;
1929 1920
1930 result = acpi_video_bus_add_fs(device); 1921 error = acpi_video_bus_add_fs(device);
1931 if (result) 1922 if (error)
1932 goto end; 1923 goto err_free_video;
1933 1924
1934 init_MUTEX(&video->sem); 1925 mutex_init(&video->device_list_lock);
1935 INIT_LIST_HEAD(&video->video_device_list); 1926 INIT_LIST_HEAD(&video->video_device_list);
1936 1927
1937 acpi_video_bus_get_devices(video, device); 1928 acpi_video_bus_get_devices(video, device);
@@ -1943,16 +1934,15 @@ static int acpi_video_bus_add(struct acpi_device *device)
1943 if (ACPI_FAILURE(status)) { 1934 if (ACPI_FAILURE(status)) {
1944 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1935 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1945 "Error installing notify handler\n")); 1936 "Error installing notify handler\n"));
1946 acpi_video_bus_stop_devices(video); 1937 error = -ENODEV;
1947 acpi_video_bus_put_devices(video); 1938 goto err_stop_video;
1948 kfree(video->attached_array);
1949 acpi_video_bus_remove_fs(device);
1950 result = -ENODEV;
1951 goto end;
1952 } 1939 }
1953 1940
1954
1955 video->input = input = input_allocate_device(); 1941 video->input = input = input_allocate_device();
1942 if (!input) {
1943 error = -ENOMEM;
1944 goto err_uninstall_notify;
1945 }
1956 1946
1957 snprintf(video->phys, sizeof(video->phys), 1947 snprintf(video->phys, sizeof(video->phys),
1958 "%s/video/input0", acpi_device_hid(video->device)); 1948 "%s/video/input0", acpi_device_hid(video->device));
@@ -1961,6 +1951,7 @@ static int acpi_video_bus_add(struct acpi_device *device)
1961 input->phys = video->phys; 1951 input->phys = video->phys;
1962 input->id.bustype = BUS_HOST; 1952 input->id.bustype = BUS_HOST;
1963 input->id.product = 0x06; 1953 input->id.product = 0x06;
1954 input->dev.parent = &device->dev;
1964 input->evbit[0] = BIT(EV_KEY); 1955 input->evbit[0] = BIT(EV_KEY);
1965 set_bit(KEY_SWITCHVIDEOMODE, input->keybit); 1956 set_bit(KEY_SWITCHVIDEOMODE, input->keybit);
1966 set_bit(KEY_VIDEO_NEXT, input->keybit); 1957 set_bit(KEY_VIDEO_NEXT, input->keybit);
@@ -1971,18 +1962,10 @@ static int acpi_video_bus_add(struct acpi_device *device)
1971 set_bit(KEY_BRIGHTNESS_ZERO, input->keybit); 1962 set_bit(KEY_BRIGHTNESS_ZERO, input->keybit);
1972 set_bit(KEY_DISPLAY_OFF, input->keybit); 1963 set_bit(KEY_DISPLAY_OFF, input->keybit);
1973 set_bit(KEY_UNKNOWN, input->keybit); 1964 set_bit(KEY_UNKNOWN, input->keybit);
1974 result = input_register_device(input);
1975 if (result) {
1976 acpi_remove_notify_handler(video->device->handle,
1977 ACPI_DEVICE_NOTIFY,
1978 acpi_video_bus_notify);
1979 acpi_video_bus_stop_devices(video);
1980 acpi_video_bus_put_devices(video);
1981 kfree(video->attached_array);
1982 acpi_video_bus_remove_fs(device);
1983 goto end;
1984 }
1985 1965
1966 error = input_register_device(input);
1967 if (error)
1968 goto err_free_input_dev;
1986 1969
1987 printk(KERN_INFO PREFIX "%s [%s] (multi-head: %s rom: %s post: %s)\n", 1970 printk(KERN_INFO PREFIX "%s [%s] (multi-head: %s rom: %s post: %s)\n",
1988 ACPI_VIDEO_DEVICE_NAME, acpi_device_bid(device), 1971 ACPI_VIDEO_DEVICE_NAME, acpi_device_bid(device),
@@ -1990,11 +1973,23 @@ static int acpi_video_bus_add(struct acpi_device *device)
1990 video->flags.rom ? "yes" : "no", 1973 video->flags.rom ? "yes" : "no",
1991 video->flags.post ? "yes" : "no"); 1974 video->flags.post ? "yes" : "no");
1992 1975
1993 end: 1976 return 0;
1994 if (result) 1977
1995 kfree(video); 1978 err_free_input_dev:
1979 input_free_device(input);
1980 err_uninstall_notify:
1981 acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
1982 acpi_video_bus_notify);
1983 err_stop_video:
1984 acpi_video_bus_stop_devices(video);
1985 acpi_video_bus_put_devices(video);
1986 kfree(video->attached_array);
1987 acpi_video_bus_remove_fs(device);
1988 err_free_video:
1989 kfree(video);
1990 acpi_driver_data(device) = NULL;
1996 1991
1997 return result; 1992 return error;
1998} 1993}
1999 1994
2000static int acpi_video_bus_remove(struct acpi_device *device, int type) 1995static int acpi_video_bus_remove(struct acpi_device *device, int type)
diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
index ed9b407e42d4..54f38c21dd95 100644
--- a/drivers/ata/ahci.c
+++ b/drivers/ata/ahci.c
@@ -193,6 +193,8 @@ enum {
193 ATA_FLAG_ACPI_SATA | ATA_FLAG_AN | 193 ATA_FLAG_ACPI_SATA | ATA_FLAG_AN |
194 ATA_FLAG_IPM, 194 ATA_FLAG_IPM,
195 AHCI_LFLAG_COMMON = ATA_LFLAG_SKIP_D2H_BSY, 195 AHCI_LFLAG_COMMON = ATA_LFLAG_SKIP_D2H_BSY,
196
197 ICH_MAP = 0x90, /* ICH MAP register */
196}; 198};
197 199
198struct ahci_cmd_hdr { 200struct ahci_cmd_hdr {
@@ -536,6 +538,10 @@ static const struct pci_device_id ahci_pci_tbl[] = {
536 { PCI_VDEVICE(NVIDIA, 0x0ad9), board_ahci }, /* MCP77 */ 538 { PCI_VDEVICE(NVIDIA, 0x0ad9), board_ahci }, /* MCP77 */
537 { PCI_VDEVICE(NVIDIA, 0x0ada), board_ahci }, /* MCP77 */ 539 { PCI_VDEVICE(NVIDIA, 0x0ada), board_ahci }, /* MCP77 */
538 { PCI_VDEVICE(NVIDIA, 0x0adb), board_ahci }, /* MCP77 */ 540 { PCI_VDEVICE(NVIDIA, 0x0adb), board_ahci }, /* MCP77 */
541 { PCI_VDEVICE(NVIDIA, 0x0ab4), board_ahci }, /* MCP79 */
542 { PCI_VDEVICE(NVIDIA, 0x0ab5), board_ahci }, /* MCP79 */
543 { PCI_VDEVICE(NVIDIA, 0x0ab6), board_ahci }, /* MCP79 */
544 { PCI_VDEVICE(NVIDIA, 0x0ab7), board_ahci }, /* MCP79 */
539 { PCI_VDEVICE(NVIDIA, 0x0ab8), board_ahci }, /* MCP79 */ 545 { PCI_VDEVICE(NVIDIA, 0x0ab8), board_ahci }, /* MCP79 */
540 { PCI_VDEVICE(NVIDIA, 0x0ab9), board_ahci }, /* MCP79 */ 546 { PCI_VDEVICE(NVIDIA, 0x0ab9), board_ahci }, /* MCP79 */
541 { PCI_VDEVICE(NVIDIA, 0x0aba), board_ahci }, /* MCP79 */ 547 { PCI_VDEVICE(NVIDIA, 0x0aba), board_ahci }, /* MCP79 */
@@ -1267,9 +1273,9 @@ static int ahci_do_softreset(struct ata_link *link, unsigned int *class,
1267 1273
1268 /* prepare for SRST (AHCI-1.1 10.4.1) */ 1274 /* prepare for SRST (AHCI-1.1 10.4.1) */
1269 rc = ahci_kick_engine(ap, 1); 1275 rc = ahci_kick_engine(ap, 1);
1270 if (rc) 1276 if (rc && rc != -EOPNOTSUPP)
1271 ata_link_printk(link, KERN_WARNING, 1277 ata_link_printk(link, KERN_WARNING,
1272 "failed to reset engine (errno=%d)", rc); 1278 "failed to reset engine (errno=%d)\n", rc);
1273 1279
1274 ata_tf_init(link->device, &tf); 1280 ata_tf_init(link->device, &tf);
1275 1281
@@ -1634,7 +1640,7 @@ static void ahci_port_intr(struct ata_port *ap)
1634 struct ahci_host_priv *hpriv = ap->host->private_data; 1640 struct ahci_host_priv *hpriv = ap->host->private_data;
1635 int resetting = !!(ap->pflags & ATA_PFLAG_RESETTING); 1641 int resetting = !!(ap->pflags & ATA_PFLAG_RESETTING);
1636 u32 status, qc_active; 1642 u32 status, qc_active;
1637 int rc, known_irq = 0; 1643 int rc;
1638 1644
1639 status = readl(port_mmio + PORT_IRQ_STAT); 1645 status = readl(port_mmio + PORT_IRQ_STAT);
1640 writel(status, port_mmio + PORT_IRQ_STAT); 1646 writel(status, port_mmio + PORT_IRQ_STAT);
@@ -1692,80 +1698,12 @@ static void ahci_port_intr(struct ata_port *ap)
1692 1698
1693 rc = ata_qc_complete_multiple(ap, qc_active, NULL); 1699 rc = ata_qc_complete_multiple(ap, qc_active, NULL);
1694 1700
1695 /* If resetting, spurious or invalid completions are expected, 1701 /* while resetting, invalid completions are expected */
1696 * return unconditionally. 1702 if (unlikely(rc < 0 && !resetting)) {
1697 */
1698 if (resetting)
1699 return;
1700
1701 if (rc > 0)
1702 return;
1703 if (rc < 0) {
1704 ehi->err_mask |= AC_ERR_HSM; 1703 ehi->err_mask |= AC_ERR_HSM;
1705 ehi->action |= ATA_EH_SOFTRESET; 1704 ehi->action |= ATA_EH_SOFTRESET;
1706 ata_port_freeze(ap); 1705 ata_port_freeze(ap);
1707 return;
1708 } 1706 }
1709
1710 /* hmmm... a spurious interrupt */
1711
1712 /* if !NCQ, ignore. No modern ATA device has broken HSM
1713 * implementation for non-NCQ commands.
1714 */
1715 if (!ap->link.sactive)
1716 return;
1717
1718 if (status & PORT_IRQ_D2H_REG_FIS) {
1719 if (!pp->ncq_saw_d2h)
1720 ata_port_printk(ap, KERN_INFO,
1721 "D2H reg with I during NCQ, "
1722 "this message won't be printed again\n");
1723 pp->ncq_saw_d2h = 1;
1724 known_irq = 1;
1725 }
1726
1727 if (status & PORT_IRQ_DMAS_FIS) {
1728 if (!pp->ncq_saw_dmas)
1729 ata_port_printk(ap, KERN_INFO,
1730 "DMAS FIS during NCQ, "
1731 "this message won't be printed again\n");
1732 pp->ncq_saw_dmas = 1;
1733 known_irq = 1;
1734 }
1735
1736 if (status & PORT_IRQ_SDB_FIS) {
1737 const __le32 *f = pp->rx_fis + RX_FIS_SDB;
1738
1739 if (le32_to_cpu(f[1])) {
1740 /* SDB FIS containing spurious completions
1741 * might be dangerous, whine and fail commands
1742 * with HSM violation. EH will turn off NCQ
1743 * after several such failures.
1744 */
1745 ata_ehi_push_desc(ehi,
1746 "spurious completions during NCQ "
1747 "issue=0x%x SAct=0x%x FIS=%08x:%08x",
1748 readl(port_mmio + PORT_CMD_ISSUE),
1749 readl(port_mmio + PORT_SCR_ACT),
1750 le32_to_cpu(f[0]), le32_to_cpu(f[1]));
1751 ehi->err_mask |= AC_ERR_HSM;
1752 ehi->action |= ATA_EH_SOFTRESET;
1753 ata_port_freeze(ap);
1754 } else {
1755 if (!pp->ncq_saw_sdb)
1756 ata_port_printk(ap, KERN_INFO,
1757 "spurious SDB FIS %08x:%08x during NCQ, "
1758 "this message won't be printed again\n",
1759 le32_to_cpu(f[0]), le32_to_cpu(f[1]));
1760 pp->ncq_saw_sdb = 1;
1761 }
1762 known_irq = 1;
1763 }
1764
1765 if (!known_irq)
1766 ata_port_printk(ap, KERN_INFO, "spurious interrupt "
1767 "(irq_stat 0x%x active_tag 0x%x sactive 0x%x)\n",
1768 status, ap->link.active_tag, ap->link.sactive);
1769} 1707}
1770 1708
1771static void ahci_irq_clear(struct ata_port *ap) 1709static void ahci_irq_clear(struct ata_port *ap)
@@ -2269,6 +2207,22 @@ static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
2269 if (rc) 2207 if (rc)
2270 return rc; 2208 return rc;
2271 2209
2210 if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
2211 (pdev->device == 0x2652 || pdev->device == 0x2653)) {
2212 u8 map;
2213
2214 /* ICH6s share the same PCI ID for both piix and ahci
2215 * modes. Enabling ahci mode while MAP indicates
2216 * combined mode is a bad idea. Yield to ata_piix.
2217 */
2218 pci_read_config_byte(pdev, ICH_MAP, &map);
2219 if (map & 0x3) {
2220 dev_printk(KERN_INFO, &pdev->dev, "controller is in "
2221 "combined mode, can't enable AHCI mode\n");
2222 return -ENODEV;
2223 }
2224 }
2225
2272 hpriv = devm_kzalloc(dev, sizeof(*hpriv), GFP_KERNEL); 2226 hpriv = devm_kzalloc(dev, sizeof(*hpriv), GFP_KERNEL);
2273 if (!hpriv) 2227 if (!hpriv)
2274 return -ENOMEM; 2228 return -ENOMEM;
diff --git a/drivers/ata/ata_piix.c b/drivers/ata/ata_piix.c
index 328ce8a08426..bb62a588f489 100644
--- a/drivers/ata/ata_piix.c
+++ b/drivers/ata/ata_piix.c
@@ -119,18 +119,19 @@ enum {
119 PIIX_80C_SEC = (1 << 7) | (1 << 6), 119 PIIX_80C_SEC = (1 << 7) | (1 << 6),
120 120
121 /* controller IDs */ 121 /* controller IDs */
122 piix_pata_33 = 0, /* PIIX4 at 33Mhz */ 122 piix_pata_mwdma = 0, /* PIIX3 MWDMA only */
123 ich_pata_33 = 1, /* ICH up to UDMA 33 only */ 123 piix_pata_33, /* PIIX4 at 33Mhz */
124 ich_pata_66 = 2, /* ICH up to 66 Mhz */ 124 ich_pata_33, /* ICH up to UDMA 33 only */
125 ich_pata_100 = 3, /* ICH up to UDMA 100 */ 125 ich_pata_66, /* ICH up to 66 Mhz */
126 ich5_sata = 5, 126 ich_pata_100, /* ICH up to UDMA 100 */
127 ich6_sata = 6, 127 ich5_sata,
128 ich6_sata_ahci = 7, 128 ich6_sata,
129 ich6m_sata_ahci = 8, 129 ich6_sata_ahci,
130 ich8_sata_ahci = 9, 130 ich6m_sata_ahci,
131 piix_pata_mwdma = 10, /* PIIX3 MWDMA only */ 131 ich8_sata_ahci,
132 tolapai_sata_ahci = 11, 132 ich8_2port_sata,
133 ich9_2port_sata = 12, 133 ich8m_apple_sata_ahci, /* locks up on second port enable */
134 tolapai_sata_ahci,
134 135
135 /* constants for mapping table */ 136 /* constants for mapping table */
136 P0 = 0, /* port 0 */ 137 P0 = 0, /* port 0 */
@@ -239,19 +240,21 @@ static const struct pci_device_id piix_pci_tbl[] = {
239 /* SATA Controller 1 IDE (ICH8) */ 240 /* SATA Controller 1 IDE (ICH8) */
240 { 0x8086, 0x2820, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata_ahci }, 241 { 0x8086, 0x2820, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata_ahci },
241 /* SATA Controller 2 IDE (ICH8) */ 242 /* SATA Controller 2 IDE (ICH8) */
242 { 0x8086, 0x2825, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich9_2port_sata }, 243 { 0x8086, 0x2825, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_2port_sata },
243 /* Mobile SATA Controller IDE (ICH8M) */ 244 /* Mobile SATA Controller IDE (ICH8M) */
244 { 0x8086, 0x2828, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata_ahci }, 245 { 0x8086, 0x2828, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata_ahci },
246 /* Mobile SATA Controller IDE (ICH8M), Apple */
247 { 0x8086, 0x2828, 0x106b, 0x00a0, 0, 0, ich8m_apple_sata_ahci },
245 /* SATA Controller IDE (ICH9) */ 248 /* SATA Controller IDE (ICH9) */
246 { 0x8086, 0x2920, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata_ahci }, 249 { 0x8086, 0x2920, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata_ahci },
247 /* SATA Controller IDE (ICH9) */ 250 /* SATA Controller IDE (ICH9) */
248 { 0x8086, 0x2921, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich9_2port_sata }, 251 { 0x8086, 0x2921, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_2port_sata },
249 /* SATA Controller IDE (ICH9) */ 252 /* SATA Controller IDE (ICH9) */
250 { 0x8086, 0x2926, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich9_2port_sata }, 253 { 0x8086, 0x2926, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_2port_sata },
251 /* SATA Controller IDE (ICH9M) */ 254 /* SATA Controller IDE (ICH9M) */
252 { 0x8086, 0x2928, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich9_2port_sata }, 255 { 0x8086, 0x2928, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_2port_sata },
253 /* SATA Controller IDE (ICH9M) */ 256 /* SATA Controller IDE (ICH9M) */
254 { 0x8086, 0x292d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich9_2port_sata }, 257 { 0x8086, 0x292d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_2port_sata },
255 /* SATA Controller IDE (ICH9M) */ 258 /* SATA Controller IDE (ICH9M) */
256 { 0x8086, 0x292e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata_ahci }, 259 { 0x8086, 0x292e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata_ahci },
257 /* SATA Controller IDE (Tolapai) */ 260 /* SATA Controller IDE (Tolapai) */
@@ -427,7 +430,7 @@ static const struct piix_map_db ich6m_map_db = {
427 430
428static const struct piix_map_db ich8_map_db = { 431static const struct piix_map_db ich8_map_db = {
429 .mask = 0x3, 432 .mask = 0x3,
430 .port_enable = 0x3, 433 .port_enable = 0xf,
431 .map = { 434 .map = {
432 /* PM PS SM SS MAP */ 435 /* PM PS SM SS MAP */
433 { P0, P2, P1, P3 }, /* 00b (hardwired when in AHCI) */ 436 { P0, P2, P1, P3 }, /* 00b (hardwired when in AHCI) */
@@ -437,7 +440,7 @@ static const struct piix_map_db ich8_map_db = {
437 }, 440 },
438}; 441};
439 442
440static const struct piix_map_db tolapai_map_db = { 443static const struct piix_map_db ich8_2port_map_db = {
441 .mask = 0x3, 444 .mask = 0x3,
442 .port_enable = 0x3, 445 .port_enable = 0x3,
443 .map = { 446 .map = {
@@ -449,7 +452,19 @@ static const struct piix_map_db tolapai_map_db = {
449 }, 452 },
450}; 453};
451 454
452static const struct piix_map_db ich9_2port_map_db = { 455static const struct piix_map_db ich8m_apple_map_db = {
456 .mask = 0x3,
457 .port_enable = 0x1,
458 .map = {
459 /* PM PS SM SS MAP */
460 { P0, NA, NA, NA }, /* 00b */
461 { RV, RV, RV, RV },
462 { P0, P2, IDE, IDE }, /* 10b */
463 { RV, RV, RV, RV },
464 },
465};
466
467static const struct piix_map_db tolapai_map_db = {
453 .mask = 0x3, 468 .mask = 0x3,
454 .port_enable = 0x3, 469 .port_enable = 0x3,
455 .map = { 470 .map = {
@@ -467,11 +482,21 @@ static const struct piix_map_db *piix_map_db_table[] = {
467 [ich6_sata_ahci] = &ich6_map_db, 482 [ich6_sata_ahci] = &ich6_map_db,
468 [ich6m_sata_ahci] = &ich6m_map_db, 483 [ich6m_sata_ahci] = &ich6m_map_db,
469 [ich8_sata_ahci] = &ich8_map_db, 484 [ich8_sata_ahci] = &ich8_map_db,
485 [ich8_2port_sata] = &ich8_2port_map_db,
486 [ich8m_apple_sata_ahci] = &ich8m_apple_map_db,
470 [tolapai_sata_ahci] = &tolapai_map_db, 487 [tolapai_sata_ahci] = &tolapai_map_db,
471 [ich9_2port_sata] = &ich9_2port_map_db,
472}; 488};
473 489
474static struct ata_port_info piix_port_info[] = { 490static struct ata_port_info piix_port_info[] = {
491 [piix_pata_mwdma] = /* PIIX3 MWDMA only */
492 {
493 .sht = &piix_sht,
494 .flags = PIIX_PATA_FLAGS,
495 .pio_mask = 0x1f, /* pio0-4 */
496 .mwdma_mask = 0x06, /* mwdma1-2 ?? CHECK 0 should be ok but slow */
497 .port_ops = &piix_pata_ops,
498 },
499
475 [piix_pata_33] = /* PIIX4 at 33MHz */ 500 [piix_pata_33] = /* PIIX4 at 33MHz */
476 { 501 {
477 .sht = &piix_sht, 502 .sht = &piix_sht,
@@ -565,13 +590,15 @@ static struct ata_port_info piix_port_info[] = {
565 .port_ops = &piix_sata_ops, 590 .port_ops = &piix_sata_ops,
566 }, 591 },
567 592
568 [piix_pata_mwdma] = /* PIIX3 MWDMA only */ 593 [ich8_2port_sata] =
569 { 594 {
570 .sht = &piix_sht, 595 .sht = &piix_sht,
571 .flags = PIIX_PATA_FLAGS, 596 .flags = PIIX_SATA_FLAGS | PIIX_FLAG_SCR |
597 PIIX_FLAG_AHCI,
572 .pio_mask = 0x1f, /* pio0-4 */ 598 .pio_mask = 0x1f, /* pio0-4 */
573 .mwdma_mask = 0x06, /* mwdma1-2 ?? CHECK 0 should be ok but slow */ 599 .mwdma_mask = 0x07, /* mwdma0-2 */
574 .port_ops = &piix_pata_ops, 600 .udma_mask = ATA_UDMA6,
601 .port_ops = &piix_sata_ops,
575 }, 602 },
576 603
577 [tolapai_sata_ahci] = 604 [tolapai_sata_ahci] =
@@ -585,7 +612,7 @@ static struct ata_port_info piix_port_info[] = {
585 .port_ops = &piix_sata_ops, 612 .port_ops = &piix_sata_ops,
586 }, 613 },
587 614
588 [ich9_2port_sata] = 615 [ich8m_apple_sata_ahci] =
589 { 616 {
590 .sht = &piix_sht, 617 .sht = &piix_sht,
591 .flags = PIIX_SATA_FLAGS | PIIX_FLAG_SCR | 618 .flags = PIIX_SATA_FLAGS | PIIX_FLAG_SCR |
@@ -595,6 +622,7 @@ static struct ata_port_info piix_port_info[] = {
595 .udma_mask = ATA_UDMA6, 622 .udma_mask = ATA_UDMA6,
596 .port_ops = &piix_sata_ops, 623 .port_ops = &piix_sata_ops,
597 }, 624 },
625
598}; 626};
599 627
600static struct pci_bits piix_enable_bits[] = { 628static struct pci_bits piix_enable_bits[] = {
@@ -939,6 +967,20 @@ static int piix_broken_suspend(void)
939 }, 967 },
940 }, 968 },
941 { 969 {
970 .ident = "TECRA M3",
971 .matches = {
972 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
973 DMI_MATCH(DMI_PRODUCT_NAME, "Tecra M3"),
974 },
975 },
976 {
977 .ident = "TECRA M4",
978 .matches = {
979 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
980 DMI_MATCH(DMI_PRODUCT_NAME, "Tecra M4"),
981 },
982 },
983 {
942 .ident = "TECRA M5", 984 .ident = "TECRA M5",
943 .matches = { 985 .matches = {
944 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"), 986 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
@@ -953,6 +995,20 @@ static int piix_broken_suspend(void)
953 }, 995 },
954 }, 996 },
955 { 997 {
998 .ident = "TECRA A8",
999 .matches = {
1000 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
1001 DMI_MATCH(DMI_PRODUCT_NAME, "TECRA A8"),
1002 },
1003 },
1004 {
1005 .ident = "Satellite R25",
1006 .matches = {
1007 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
1008 DMI_MATCH(DMI_PRODUCT_NAME, "Satellite R25"),
1009 },
1010 },
1011 {
956 .ident = "Satellite U200", 1012 .ident = "Satellite U200",
957 .matches = { 1013 .matches = {
958 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"), 1014 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
@@ -960,6 +1016,13 @@ static int piix_broken_suspend(void)
960 }, 1016 },
961 }, 1017 },
962 { 1018 {
1019 .ident = "Satellite U200",
1020 .matches = {
1021 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
1022 DMI_MATCH(DMI_PRODUCT_NAME, "SATELLITE U200"),
1023 },
1024 },
1025 {
963 .ident = "Satellite Pro U200", 1026 .ident = "Satellite Pro U200",
964 .matches = { 1027 .matches = {
965 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"), 1028 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
@@ -974,6 +1037,13 @@ static int piix_broken_suspend(void)
974 }, 1037 },
975 }, 1038 },
976 { 1039 {
1040 .ident = "SATELLITE U205",
1041 .matches = {
1042 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
1043 DMI_MATCH(DMI_PRODUCT_NAME, "SATELLITE U205"),
1044 },
1045 },
1046 {
977 .ident = "Portege M500", 1047 .ident = "Portege M500",
978 .matches = { 1048 .matches = {
979 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"), 1049 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
@@ -1086,12 +1156,12 @@ static int piix_disable_ahci(struct pci_dev *pdev)
1086 if (!mmio) 1156 if (!mmio)
1087 return -ENOMEM; 1157 return -ENOMEM;
1088 1158
1089 tmp = readl(mmio + AHCI_GLOBAL_CTL); 1159 tmp = ioread32(mmio + AHCI_GLOBAL_CTL);
1090 if (tmp & AHCI_ENABLE) { 1160 if (tmp & AHCI_ENABLE) {
1091 tmp &= ~AHCI_ENABLE; 1161 tmp &= ~AHCI_ENABLE;
1092 writel(tmp, mmio + AHCI_GLOBAL_CTL); 1162 iowrite32(tmp, mmio + AHCI_GLOBAL_CTL);
1093 1163
1094 tmp = readl(mmio + AHCI_GLOBAL_CTL); 1164 tmp = ioread32(mmio + AHCI_GLOBAL_CTL);
1095 if (tmp & AHCI_ENABLE) 1165 if (tmp & AHCI_ENABLE)
1096 rc = -EIO; 1166 rc = -EIO;
1097 } 1167 }
diff --git a/drivers/ata/libata-acpi.c b/drivers/ata/libata-acpi.c
index 545ea865ceb5..7bf4befd96bc 100644
--- a/drivers/ata/libata-acpi.c
+++ b/drivers/ata/libata-acpi.c
@@ -6,6 +6,7 @@
6 * Copyright (C) 2006 Randy Dunlap 6 * Copyright (C) 2006 Randy Dunlap
7 */ 7 */
8 8
9#include <linux/module.h>
9#include <linux/ata.h> 10#include <linux/ata.h>
10#include <linux/delay.h> 11#include <linux/delay.h>
11#include <linux/device.h> 12#include <linux/device.h>
@@ -25,6 +26,18 @@
25#include <acpi/acmacros.h> 26#include <acpi/acmacros.h>
26#include <acpi/actypes.h> 27#include <acpi/actypes.h>
27 28
29enum {
30 ATA_ACPI_FILTER_SETXFER = 1 << 0,
31 ATA_ACPI_FILTER_LOCK = 1 << 1,
32
33 ATA_ACPI_FILTER_DEFAULT = ATA_ACPI_FILTER_SETXFER |
34 ATA_ACPI_FILTER_LOCK,
35};
36
37static unsigned int ata_acpi_gtf_filter = ATA_ACPI_FILTER_DEFAULT;
38module_param_named(acpi_gtf_filter, ata_acpi_gtf_filter, int, 0644);
39MODULE_PARM_DESC(acpi_gtf_filter, "filter mask for ACPI _GTF commands, set to filter out (0x1=set xfermode, 0x2=lock/freeze lock)");
40
28#define NO_PORT_MULT 0xffff 41#define NO_PORT_MULT 0xffff
29#define SATA_ADR(root, pmp) (((root) << 16) | (pmp)) 42#define SATA_ADR(root, pmp) (((root) << 16) | (pmp))
30 43
@@ -41,6 +54,12 @@ static int is_pci_dev(struct device *dev)
41 return (dev->bus == &pci_bus_type); 54 return (dev->bus == &pci_bus_type);
42} 55}
43 56
57static void ata_acpi_clear_gtf(struct ata_device *dev)
58{
59 kfree(dev->gtf_cache);
60 dev->gtf_cache = NULL;
61}
62
44/** 63/**
45 * ata_acpi_associate_sata_port - associate SATA port with ACPI objects 64 * ata_acpi_associate_sata_port - associate SATA port with ACPI objects
46 * @ap: target SATA port 65 * @ap: target SATA port
@@ -94,6 +113,9 @@ static void ata_acpi_associate_ide_port(struct ata_port *ap)
94 113
95 dev->acpi_handle = acpi_get_child(ap->acpi_handle, i); 114 dev->acpi_handle = acpi_get_child(ap->acpi_handle, i);
96 } 115 }
116
117 if (ata_acpi_gtm(ap, &ap->__acpi_init_gtm) == 0)
118 ap->pflags |= ATA_PFLAG_INIT_GTM_VALID;
97} 119}
98 120
99static void ata_acpi_handle_hotplug(struct ata_port *ap, struct kobject *kobj, 121static void ata_acpi_handle_hotplug(struct ata_port *ap, struct kobject *kobj,
@@ -188,6 +210,32 @@ void ata_acpi_associate(struct ata_host *host)
188} 210}
189 211
190/** 212/**
213 * ata_acpi_dissociate - dissociate ATA host from ACPI objects
214 * @host: target ATA host
215 *
216 * This function is called during driver detach after the whole host
217 * is shut down.
218 *
219 * LOCKING:
220 * EH context.
221 */
222void ata_acpi_dissociate(struct ata_host *host)
223{
224 int i;
225
226 /* Restore initial _GTM values so that driver which attaches
227 * afterward can use them too.
228 */
229 for (i = 0; i < host->n_ports; i++) {
230 struct ata_port *ap = host->ports[i];
231 const struct ata_acpi_gtm *gtm = ata_acpi_init_gtm(ap);
232
233 if (ap->acpi_handle && gtm)
234 ata_acpi_stm(ap, gtm);
235 }
236}
237
238/**
191 * ata_acpi_gtm - execute _GTM 239 * ata_acpi_gtm - execute _GTM
192 * @ap: target ATA port 240 * @ap: target ATA port
193 * @gtm: out parameter for _GTM result 241 * @gtm: out parameter for _GTM result
@@ -200,7 +248,7 @@ void ata_acpi_associate(struct ata_host *host)
200 * RETURNS: 248 * RETURNS:
201 * 0 on success, -ENOENT if _GTM doesn't exist, -errno on failure. 249 * 0 on success, -ENOENT if _GTM doesn't exist, -errno on failure.
202 */ 250 */
203int ata_acpi_gtm(const struct ata_port *ap, struct ata_acpi_gtm *gtm) 251int ata_acpi_gtm(struct ata_port *ap, struct ata_acpi_gtm *gtm)
204{ 252{
205 struct acpi_buffer output = { .length = ACPI_ALLOCATE_BUFFER }; 253 struct acpi_buffer output = { .length = ACPI_ALLOCATE_BUFFER };
206 union acpi_object *out_obj; 254 union acpi_object *out_obj;
@@ -259,15 +307,16 @@ EXPORT_SYMBOL_GPL(ata_acpi_gtm);
259 * RETURNS: 307 * RETURNS:
260 * 0 on success, -ENOENT if _STM doesn't exist, -errno on failure. 308 * 0 on success, -ENOENT if _STM doesn't exist, -errno on failure.
261 */ 309 */
262int ata_acpi_stm(const struct ata_port *ap, struct ata_acpi_gtm *stm) 310int ata_acpi_stm(struct ata_port *ap, const struct ata_acpi_gtm *stm)
263{ 311{
264 acpi_status status; 312 acpi_status status;
313 struct ata_acpi_gtm stm_buf = *stm;
265 struct acpi_object_list input; 314 struct acpi_object_list input;
266 union acpi_object in_params[3]; 315 union acpi_object in_params[3];
267 316
268 in_params[0].type = ACPI_TYPE_BUFFER; 317 in_params[0].type = ACPI_TYPE_BUFFER;
269 in_params[0].buffer.length = sizeof(struct ata_acpi_gtm); 318 in_params[0].buffer.length = sizeof(struct ata_acpi_gtm);
270 in_params[0].buffer.pointer = (u8 *)stm; 319 in_params[0].buffer.pointer = (u8 *)&stm_buf;
271 /* Buffers for id may need byteswapping ? */ 320 /* Buffers for id may need byteswapping ? */
272 in_params[1].type = ACPI_TYPE_BUFFER; 321 in_params[1].type = ACPI_TYPE_BUFFER;
273 in_params[1].buffer.length = 512; 322 in_params[1].buffer.length = 512;
@@ -297,7 +346,6 @@ EXPORT_SYMBOL_GPL(ata_acpi_stm);
297 * ata_dev_get_GTF - get the drive bootup default taskfile settings 346 * ata_dev_get_GTF - get the drive bootup default taskfile settings
298 * @dev: target ATA device 347 * @dev: target ATA device
299 * @gtf: output parameter for buffer containing _GTF taskfile arrays 348 * @gtf: output parameter for buffer containing _GTF taskfile arrays
300 * @ptr_to_free: pointer which should be freed
301 * 349 *
302 * This applies to both PATA and SATA drives. 350 * This applies to both PATA and SATA drives.
303 * 351 *
@@ -311,11 +359,10 @@ EXPORT_SYMBOL_GPL(ata_acpi_stm);
311 * EH context. 359 * EH context.
312 * 360 *
313 * RETURNS: 361 * RETURNS:
314 * Number of taskfiles on success, 0 if _GTF doesn't exist or doesn't 362 * Number of taskfiles on success, 0 if _GTF doesn't exist. -EINVAL
315 * contain valid data. 363 * if _GTF is invalid.
316 */ 364 */
317static int ata_dev_get_GTF(struct ata_device *dev, struct ata_acpi_gtf **gtf, 365static int ata_dev_get_GTF(struct ata_device *dev, struct ata_acpi_gtf **gtf)
318 void **ptr_to_free)
319{ 366{
320 struct ata_port *ap = dev->link->ap; 367 struct ata_port *ap = dev->link->ap;
321 acpi_status status; 368 acpi_status status;
@@ -323,6 +370,12 @@ static int ata_dev_get_GTF(struct ata_device *dev, struct ata_acpi_gtf **gtf,
323 union acpi_object *out_obj; 370 union acpi_object *out_obj;
324 int rc = 0; 371 int rc = 0;
325 372
373 /* if _GTF is cached, use the cached value */
374 if (dev->gtf_cache) {
375 out_obj = dev->gtf_cache;
376 goto done;
377 }
378
326 /* set up output buffer */ 379 /* set up output buffer */
327 output.length = ACPI_ALLOCATE_BUFFER; 380 output.length = ACPI_ALLOCATE_BUFFER;
328 output.pointer = NULL; /* ACPI-CA sets this; save/free it later */ 381 output.pointer = NULL; /* ACPI-CA sets this; save/free it later */
@@ -333,12 +386,14 @@ static int ata_dev_get_GTF(struct ata_device *dev, struct ata_acpi_gtf **gtf,
333 386
334 /* _GTF has no input parameters */ 387 /* _GTF has no input parameters */
335 status = acpi_evaluate_object(dev->acpi_handle, "_GTF", NULL, &output); 388 status = acpi_evaluate_object(dev->acpi_handle, "_GTF", NULL, &output);
389 out_obj = dev->gtf_cache = output.pointer;
336 390
337 if (ACPI_FAILURE(status)) { 391 if (ACPI_FAILURE(status)) {
338 if (status != AE_NOT_FOUND) { 392 if (status != AE_NOT_FOUND) {
339 ata_dev_printk(dev, KERN_WARNING, 393 ata_dev_printk(dev, KERN_WARNING,
340 "_GTF evaluation failed (AE 0x%x)\n", 394 "_GTF evaluation failed (AE 0x%x)\n",
341 status); 395 status);
396 rc = -EINVAL;
342 } 397 }
343 goto out_free; 398 goto out_free;
344 } 399 }
@@ -350,14 +405,15 @@ static int ata_dev_get_GTF(struct ata_device *dev, struct ata_acpi_gtf **gtf,
350 __FUNCTION__, 405 __FUNCTION__,
351 (unsigned long long)output.length, 406 (unsigned long long)output.length,
352 output.pointer); 407 output.pointer);
408 rc = -EINVAL;
353 goto out_free; 409 goto out_free;
354 } 410 }
355 411
356 out_obj = output.pointer;
357 if (out_obj->type != ACPI_TYPE_BUFFER) { 412 if (out_obj->type != ACPI_TYPE_BUFFER) {
358 ata_dev_printk(dev, KERN_WARNING, 413 ata_dev_printk(dev, KERN_WARNING,
359 "_GTF unexpected object type 0x%x\n", 414 "_GTF unexpected object type 0x%x\n",
360 out_obj->type); 415 out_obj->type);
416 rc = -EINVAL;
361 goto out_free; 417 goto out_free;
362 } 418 }
363 419
@@ -365,21 +421,23 @@ static int ata_dev_get_GTF(struct ata_device *dev, struct ata_acpi_gtf **gtf,
365 ata_dev_printk(dev, KERN_WARNING, 421 ata_dev_printk(dev, KERN_WARNING,
366 "unexpected _GTF length (%d)\n", 422 "unexpected _GTF length (%d)\n",
367 out_obj->buffer.length); 423 out_obj->buffer.length);
424 rc = -EINVAL;
368 goto out_free; 425 goto out_free;
369 } 426 }
370 427
371 *ptr_to_free = out_obj; 428 done:
372 *gtf = (void *)out_obj->buffer.pointer;
373 rc = out_obj->buffer.length / REGS_PER_GTF; 429 rc = out_obj->buffer.length / REGS_PER_GTF;
374 430 if (gtf) {
375 if (ata_msg_probe(ap)) 431 *gtf = (void *)out_obj->buffer.pointer;
376 ata_dev_printk(dev, KERN_DEBUG, "%s: returning " 432 if (ata_msg_probe(ap))
377 "gtf=%p, gtf_count=%d, ptr_to_free=%p\n", 433 ata_dev_printk(dev, KERN_DEBUG,
378 __FUNCTION__, *gtf, rc, *ptr_to_free); 434 "%s: returning gtf=%p, gtf_count=%d\n",
435 __FUNCTION__, *gtf, rc);
436 }
379 return rc; 437 return rc;
380 438
381 out_free: 439 out_free:
382 kfree(output.pointer); 440 ata_acpi_clear_gtf(dev);
383 return rc; 441 return rc;
384} 442}
385 443
@@ -393,22 +451,21 @@ static int ata_dev_get_GTF(struct ata_device *dev, struct ata_acpi_gtf **gtf,
393 451
394int ata_acpi_cbl_80wire(struct ata_port *ap) 452int ata_acpi_cbl_80wire(struct ata_port *ap)
395{ 453{
396 struct ata_acpi_gtm gtm; 454 const struct ata_acpi_gtm *gtm = ata_acpi_init_gtm(ap);
397 int valid = 0; 455 int valid = 0;
398 456
399 /* No _GTM data, no information */ 457 if (!gtm)
400 if (ata_acpi_gtm(ap, &gtm) < 0)
401 return 0; 458 return 0;
402 459
403 /* Split timing, DMA enabled */ 460 /* Split timing, DMA enabled */
404 if ((gtm.flags & 0x11) == 0x11 && gtm.drive[0].dma < 55) 461 if ((gtm->flags & 0x11) == 0x11 && gtm->drive[0].dma < 55)
405 valid |= 1; 462 valid |= 1;
406 if ((gtm.flags & 0x14) == 0x14 && gtm.drive[1].dma < 55) 463 if ((gtm->flags & 0x14) == 0x14 && gtm->drive[1].dma < 55)
407 valid |= 2; 464 valid |= 2;
408 /* Shared timing, DMA enabled */ 465 /* Shared timing, DMA enabled */
409 if ((gtm.flags & 0x11) == 0x01 && gtm.drive[0].dma < 55) 466 if ((gtm->flags & 0x11) == 0x01 && gtm->drive[0].dma < 55)
410 valid |= 1; 467 valid |= 1;
411 if ((gtm.flags & 0x14) == 0x04 && gtm.drive[0].dma < 55) 468 if ((gtm->flags & 0x14) == 0x04 && gtm->drive[0].dma < 55)
412 valid |= 2; 469 valid |= 2;
413 470
414 /* Drive check */ 471 /* Drive check */
@@ -421,8 +478,62 @@ int ata_acpi_cbl_80wire(struct ata_port *ap)
421 478
422EXPORT_SYMBOL_GPL(ata_acpi_cbl_80wire); 479EXPORT_SYMBOL_GPL(ata_acpi_cbl_80wire);
423 480
481static void ata_acpi_gtf_to_tf(struct ata_device *dev,
482 const struct ata_acpi_gtf *gtf,
483 struct ata_taskfile *tf)
484{
485 ata_tf_init(dev, tf);
486
487 tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE;
488 tf->protocol = ATA_PROT_NODATA;
489 tf->feature = gtf->tf[0]; /* 0x1f1 */
490 tf->nsect = gtf->tf[1]; /* 0x1f2 */
491 tf->lbal = gtf->tf[2]; /* 0x1f3 */
492 tf->lbam = gtf->tf[3]; /* 0x1f4 */
493 tf->lbah = gtf->tf[4]; /* 0x1f5 */
494 tf->device = gtf->tf[5]; /* 0x1f6 */
495 tf->command = gtf->tf[6]; /* 0x1f7 */
496}
497
498static int ata_acpi_filter_tf(const struct ata_taskfile *tf,
499 const struct ata_taskfile *ptf)
500{
501 if (ata_acpi_gtf_filter & ATA_ACPI_FILTER_SETXFER) {
502 /* libata doesn't use ACPI to configure transfer mode.
503 * It will only confuse device configuration. Skip.
504 */
505 if (tf->command == ATA_CMD_SET_FEATURES &&
506 tf->feature == SETFEATURES_XFER)
507 return 1;
508 }
509
510 if (ata_acpi_gtf_filter & ATA_ACPI_FILTER_LOCK) {
511 /* BIOS writers, sorry but we don't wanna lock
512 * features unless the user explicitly said so.
513 */
514
515 /* DEVICE CONFIGURATION FREEZE LOCK */
516 if (tf->command == ATA_CMD_CONF_OVERLAY &&
517 tf->feature == ATA_DCO_FREEZE_LOCK)
518 return 1;
519
520 /* SECURITY FREEZE LOCK */
521 if (tf->command == ATA_CMD_SEC_FREEZE_LOCK)
522 return 1;
523
524 /* SET MAX LOCK and SET MAX FREEZE LOCK */
525 if ((!ptf || ptf->command != ATA_CMD_READ_NATIVE_MAX) &&
526 tf->command == ATA_CMD_SET_MAX &&
527 (tf->feature == ATA_SET_MAX_LOCK ||
528 tf->feature == ATA_SET_MAX_FREEZE_LOCK))
529 return 1;
530 }
531
532 return 0;
533}
534
424/** 535/**
425 * taskfile_load_raw - send taskfile registers to host controller 536 * ata_acpi_run_tf - send taskfile registers to host controller
426 * @dev: target ATA device 537 * @dev: target ATA device
427 * @gtf: raw ATA taskfile register set (0x1f1 - 0x1f7) 538 * @gtf: raw ATA taskfile register set (0x1f1 - 0x1f7)
428 * 539 *
@@ -441,56 +552,77 @@ EXPORT_SYMBOL_GPL(ata_acpi_cbl_80wire);
441 * EH context. 552 * EH context.
442 * 553 *
443 * RETURNS: 554 * RETURNS:
444 * 0 on success, -errno on failure. 555 * 1 if command is executed successfully. 0 if ignored, rejected or
556 * filtered out, -errno on other errors.
445 */ 557 */
446static int taskfile_load_raw(struct ata_device *dev, 558static int ata_acpi_run_tf(struct ata_device *dev,
447 const struct ata_acpi_gtf *gtf) 559 const struct ata_acpi_gtf *gtf,
560 const struct ata_acpi_gtf *prev_gtf)
448{ 561{
449 struct ata_port *ap = dev->link->ap; 562 struct ata_taskfile *pptf = NULL;
450 struct ata_taskfile tf, rtf; 563 struct ata_taskfile tf, ptf, rtf;
451 unsigned int err_mask; 564 unsigned int err_mask;
565 const char *level;
566 char msg[60];
567 int rc;
452 568
453 if ((gtf->tf[0] == 0) && (gtf->tf[1] == 0) && (gtf->tf[2] == 0) 569 if ((gtf->tf[0] == 0) && (gtf->tf[1] == 0) && (gtf->tf[2] == 0)
454 && (gtf->tf[3] == 0) && (gtf->tf[4] == 0) && (gtf->tf[5] == 0) 570 && (gtf->tf[3] == 0) && (gtf->tf[4] == 0) && (gtf->tf[5] == 0)
455 && (gtf->tf[6] == 0)) 571 && (gtf->tf[6] == 0))
456 return 0; 572 return 0;
457 573
458 ata_tf_init(dev, &tf); 574 ata_acpi_gtf_to_tf(dev, gtf, &tf);
575 if (prev_gtf) {
576 ata_acpi_gtf_to_tf(dev, prev_gtf, &ptf);
577 pptf = &ptf;
578 }
459 579
460 /* convert gtf to tf */ 580 if (!ata_acpi_filter_tf(&tf, pptf)) {
461 tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; /* TBD */ 581 rtf = tf;
462 tf.protocol = ATA_PROT_NODATA; 582 err_mask = ata_exec_internal(dev, &rtf, NULL,
463 tf.feature = gtf->tf[0]; /* 0x1f1 */ 583 DMA_NONE, NULL, 0, 0);
464 tf.nsect = gtf->tf[1]; /* 0x1f2 */
465 tf.lbal = gtf->tf[2]; /* 0x1f3 */
466 tf.lbam = gtf->tf[3]; /* 0x1f4 */
467 tf.lbah = gtf->tf[4]; /* 0x1f5 */
468 tf.device = gtf->tf[5]; /* 0x1f6 */
469 tf.command = gtf->tf[6]; /* 0x1f7 */
470 584
471 if (ata_msg_probe(ap)) 585 switch (err_mask) {
472 ata_dev_printk(dev, KERN_DEBUG, "executing ACPI cmd " 586 case 0:
473 "%02x/%02x:%02x:%02x:%02x:%02x:%02x\n", 587 level = KERN_DEBUG;
474 tf.command, tf.feature, tf.nsect, 588 snprintf(msg, sizeof(msg), "succeeded");
475 tf.lbal, tf.lbam, tf.lbah, tf.device); 589 rc = 1;
476 590 break;
477 rtf = tf; 591
478 err_mask = ata_exec_internal(dev, &rtf, NULL, DMA_NONE, NULL, 0, 0); 592 case AC_ERR_DEV:
479 if (err_mask) { 593 level = KERN_INFO;
480 ata_dev_printk(dev, KERN_ERR, 594 snprintf(msg, sizeof(msg),
481 "ACPI cmd %02x/%02x:%02x:%02x:%02x:%02x:%02x failed " 595 "rejected by device (Stat=0x%02x Err=0x%02x)",
482 "(Emask=0x%x Stat=0x%02x Err=0x%02x)\n", 596 rtf.command, rtf.feature);
483 tf.command, tf.feature, tf.nsect, tf.lbal, tf.lbam, 597 rc = 0;
484 tf.lbah, tf.device, err_mask, rtf.command, rtf.feature); 598 break;
485 return -EIO; 599
600 default:
601 level = KERN_ERR;
602 snprintf(msg, sizeof(msg),
603 "failed (Emask=0x%x Stat=0x%02x Err=0x%02x)",
604 err_mask, rtf.command, rtf.feature);
605 rc = -EIO;
606 break;
607 }
608 } else {
609 level = KERN_INFO;
610 snprintf(msg, sizeof(msg), "filtered out");
611 rc = 0;
486 } 612 }
487 613
488 return 0; 614 ata_dev_printk(dev, level,
615 "ACPI cmd %02x/%02x:%02x:%02x:%02x:%02x:%02x %s\n",
616 tf.command, tf.feature, tf.nsect, tf.lbal,
617 tf.lbam, tf.lbah, tf.device, msg);
618
619 return rc;
489} 620}
490 621
491/** 622/**
492 * ata_acpi_exec_tfs - get then write drive taskfile settings 623 * ata_acpi_exec_tfs - get then write drive taskfile settings
493 * @dev: target ATA device 624 * @dev: target ATA device
625 * @nr_executed: out paramter for the number of executed commands
494 * 626 *
495 * Evaluate _GTF and excute returned taskfiles. 627 * Evaluate _GTF and excute returned taskfiles.
496 * 628 *
@@ -498,35 +630,36 @@ static int taskfile_load_raw(struct ata_device *dev,
498 * EH context. 630 * EH context.
499 * 631 *
500 * RETURNS: 632 * RETURNS:
501 * Number of executed taskfiles on success, 0 if _GTF doesn't exist or 633 * Number of executed taskfiles on success, 0 if _GTF doesn't exist.
502 * doesn't contain valid data. -errno on other errors. 634 * -errno on other errors.
503 */ 635 */
504static int ata_acpi_exec_tfs(struct ata_device *dev) 636static int ata_acpi_exec_tfs(struct ata_device *dev, int *nr_executed)
505{ 637{
506 struct ata_acpi_gtf *gtf = NULL; 638 struct ata_acpi_gtf *gtf = NULL, *pgtf = NULL;
507 void *ptr_to_free = NULL;
508 int gtf_count, i, rc; 639 int gtf_count, i, rc;
509 640
510 /* get taskfiles */ 641 /* get taskfiles */
511 gtf_count = ata_dev_get_GTF(dev, &gtf, &ptr_to_free); 642 rc = ata_dev_get_GTF(dev, &gtf);
643 if (rc < 0)
644 return rc;
645 gtf_count = rc;
512 646
513 /* execute them */ 647 /* execute them */
514 for (i = 0, rc = 0; i < gtf_count; i++) { 648 for (i = 0; i < gtf_count; i++, gtf++) {
515 int tmp; 649 rc = ata_acpi_run_tf(dev, gtf, pgtf);
516 650 if (rc < 0)
517 /* ACPI errors are eventually ignored. Run till the 651 break;
518 * end even after errors. 652 if (rc) {
519 */ 653 (*nr_executed)++;
520 tmp = taskfile_load_raw(dev, gtf++); 654 pgtf = gtf;
521 if (!rc) 655 }
522 rc = tmp;
523 } 656 }
524 657
525 kfree(ptr_to_free); 658 ata_acpi_clear_gtf(dev);
526 659
527 if (rc == 0) 660 if (rc < 0)
528 return gtf_count; 661 return rc;
529 return rc; 662 return 0;
530} 663}
531 664
532/** 665/**
@@ -596,27 +729,8 @@ static int ata_acpi_push_id(struct ata_device *dev)
596 */ 729 */
597int ata_acpi_on_suspend(struct ata_port *ap) 730int ata_acpi_on_suspend(struct ata_port *ap)
598{ 731{
599 unsigned long flags; 732 /* nada */
600 int rc; 733 return 0;
601
602 /* proceed iff per-port acpi_handle is valid */
603 if (!ap->acpi_handle)
604 return 0;
605 BUG_ON(ap->flags & ATA_FLAG_ACPI_SATA);
606
607 /* store timing parameters */
608 rc = ata_acpi_gtm(ap, &ap->acpi_gtm);
609
610 spin_lock_irqsave(ap->lock, flags);
611 if (rc == 0)
612 ap->pflags |= ATA_PFLAG_GTM_VALID;
613 else
614 ap->pflags &= ~ATA_PFLAG_GTM_VALID;
615 spin_unlock_irqrestore(ap->lock, flags);
616
617 if (rc == -ENOENT)
618 rc = 0;
619 return rc;
620} 734}
621 735
622/** 736/**
@@ -631,18 +745,34 @@ int ata_acpi_on_suspend(struct ata_port *ap)
631 */ 745 */
632void ata_acpi_on_resume(struct ata_port *ap) 746void ata_acpi_on_resume(struct ata_port *ap)
633{ 747{
748 const struct ata_acpi_gtm *gtm = ata_acpi_init_gtm(ap);
634 struct ata_device *dev; 749 struct ata_device *dev;
635 750
636 if (ap->acpi_handle && (ap->pflags & ATA_PFLAG_GTM_VALID)) { 751 if (ap->acpi_handle && gtm) {
637 BUG_ON(ap->flags & ATA_FLAG_ACPI_SATA); 752 /* _GTM valid */
638 753
639 /* restore timing parameters */ 754 /* restore timing parameters */
640 ata_acpi_stm(ap, &ap->acpi_gtm); 755 ata_acpi_stm(ap, gtm);
641 }
642 756
643 /* schedule _GTF */ 757 /* _GTF should immediately follow _STM so that it can
644 ata_link_for_each_dev(dev, &ap->link) 758 * use values set by _STM. Cache _GTF result and
645 dev->flags |= ATA_DFLAG_ACPI_PENDING; 759 * schedule _GTF.
760 */
761 ata_link_for_each_dev(dev, &ap->link) {
762 ata_acpi_clear_gtf(dev);
763 if (ata_dev_get_GTF(dev, NULL) >= 0)
764 dev->flags |= ATA_DFLAG_ACPI_PENDING;
765 }
766 } else {
767 /* SATA _GTF needs to be evaulated after _SDD and
768 * there's no reason to evaluate IDE _GTF early
769 * without _STM. Clear cache and schedule _GTF.
770 */
771 ata_link_for_each_dev(dev, &ap->link) {
772 ata_acpi_clear_gtf(dev);
773 dev->flags |= ATA_DFLAG_ACPI_PENDING;
774 }
775 }
646} 776}
647 777
648/** 778/**
@@ -664,6 +794,7 @@ int ata_acpi_on_devcfg(struct ata_device *dev)
664 struct ata_port *ap = dev->link->ap; 794 struct ata_port *ap = dev->link->ap;
665 struct ata_eh_context *ehc = &ap->link.eh_context; 795 struct ata_eh_context *ehc = &ap->link.eh_context;
666 int acpi_sata = ap->flags & ATA_FLAG_ACPI_SATA; 796 int acpi_sata = ap->flags & ATA_FLAG_ACPI_SATA;
797 int nr_executed = 0;
667 int rc; 798 int rc;
668 799
669 if (!dev->acpi_handle) 800 if (!dev->acpi_handle)
@@ -682,14 +813,14 @@ int ata_acpi_on_devcfg(struct ata_device *dev)
682 } 813 }
683 814
684 /* do _GTF */ 815 /* do _GTF */
685 rc = ata_acpi_exec_tfs(dev); 816 rc = ata_acpi_exec_tfs(dev, &nr_executed);
686 if (rc < 0) 817 if (rc)
687 goto acpi_err; 818 goto acpi_err;
688 819
689 dev->flags &= ~ATA_DFLAG_ACPI_PENDING; 820 dev->flags &= ~ATA_DFLAG_ACPI_PENDING;
690 821
691 /* refresh IDENTIFY page if any _GTF command has been executed */ 822 /* refresh IDENTIFY page if any _GTF command has been executed */
692 if (rc > 0) { 823 if (nr_executed) {
693 rc = ata_dev_reread_id(dev, 0); 824 rc = ata_dev_reread_id(dev, 0);
694 if (rc < 0) { 825 if (rc < 0) {
695 ata_dev_printk(dev, KERN_ERR, "failed to IDENTIFY " 826 ata_dev_printk(dev, KERN_ERR, "failed to IDENTIFY "
@@ -701,17 +832,39 @@ int ata_acpi_on_devcfg(struct ata_device *dev)
701 return 0; 832 return 0;
702 833
703 acpi_err: 834 acpi_err:
704 /* let EH retry on the first failure, disable ACPI on the second */ 835 /* ignore evaluation failure if we can continue safely */
705 if (dev->flags & ATA_DFLAG_ACPI_FAILED) { 836 if (rc == -EINVAL && !nr_executed && !(ap->pflags & ATA_PFLAG_FROZEN))
706 ata_dev_printk(dev, KERN_WARNING, "ACPI on devcfg failed the " 837 return 0;
707 "second time, disabling (errno=%d)\n", rc);
708
709 dev->acpi_handle = NULL;
710 838
711 /* if port is working, request IDENTIFY reload and continue */ 839 /* fail and let EH retry once more for unknown IO errors */
712 if (!(ap->pflags & ATA_PFLAG_FROZEN)) 840 if (!(dev->flags & ATA_DFLAG_ACPI_FAILED)) {
713 rc = 1; 841 dev->flags |= ATA_DFLAG_ACPI_FAILED;
842 return rc;
714 } 843 }
715 dev->flags |= ATA_DFLAG_ACPI_FAILED; 844
845 ata_dev_printk(dev, KERN_WARNING,
846 "ACPI: failed the second time, disabled\n");
847 dev->acpi_handle = NULL;
848
849 /* We can safely continue if no _GTF command has been executed
850 * and port is not frozen.
851 */
852 if (!nr_executed && !(ap->pflags & ATA_PFLAG_FROZEN))
853 return 0;
854
716 return rc; 855 return rc;
717} 856}
857
858/**
859 * ata_acpi_on_disable - ATA ACPI hook called when a device is disabled
860 * @dev: target ATA device
861 *
862 * This function is called when @dev is about to be disabled.
863 *
864 * LOCKING:
865 * EH context.
866 */
867void ata_acpi_on_disable(struct ata_device *dev)
868{
869 ata_acpi_clear_gtf(dev);
870}
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index 81898036dbca..4753a1831dbc 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -30,6 +30,14 @@
30 * Hardware documentation available from http://www.t13.org/ and 30 * Hardware documentation available from http://www.t13.org/ and
31 * http://www.sata-io.org/ 31 * http://www.sata-io.org/
32 * 32 *
33 * Standards documents from:
34 * http://www.t13.org (ATA standards, PCI DMA IDE spec)
35 * http://www.t10.org (SCSI MMC - for ATAPI MMC)
36 * http://www.sata-io.org (SATA)
37 * http://www.compactflash.org (CF)
38 * http://www.qic.org (QIC157 - Tape and DSC)
39 * http://www.ce-ata.org (CE-ATA: not supported)
40 *
33 */ 41 */
34 42
35#include <linux/kernel.h> 43#include <linux/kernel.h>
@@ -56,6 +64,7 @@
56#include <linux/libata.h> 64#include <linux/libata.h>
57#include <asm/semaphore.h> 65#include <asm/semaphore.h>
58#include <asm/byteorder.h> 66#include <asm/byteorder.h>
67#include <linux/cdrom.h>
59 68
60#include "libata.h" 69#include "libata.h"
61 70
@@ -614,6 +623,7 @@ void ata_dev_disable(struct ata_device *dev)
614 if (ata_dev_enabled(dev)) { 623 if (ata_dev_enabled(dev)) {
615 if (ata_msg_drv(dev->link->ap)) 624 if (ata_msg_drv(dev->link->ap))
616 ata_dev_printk(dev, KERN_WARNING, "disabled\n"); 625 ata_dev_printk(dev, KERN_WARNING, "disabled\n");
626 ata_acpi_on_disable(dev);
617 ata_down_xfermask_limit(dev, ATA_DNXFER_FORCE_PIO0 | 627 ata_down_xfermask_limit(dev, ATA_DNXFER_FORCE_PIO0 |
618 ATA_DNXFER_QUIET); 628 ATA_DNXFER_QUIET);
619 dev->class++; 629 dev->class++;
@@ -2307,8 +2317,10 @@ int ata_dev_configure(struct ata_device *dev)
2307 } 2317 }
2308 2318
2309 if ((dev->class == ATA_DEV_ATAPI) && 2319 if ((dev->class == ATA_DEV_ATAPI) &&
2310 (atapi_command_packet_set(id) == TYPE_TAPE)) 2320 (atapi_command_packet_set(id) == TYPE_TAPE)) {
2311 dev->max_sectors = ATA_MAX_SECTORS_TAPE; 2321 dev->max_sectors = ATA_MAX_SECTORS_TAPE;
2322 dev->horkage |= ATA_HORKAGE_STUCK_ERR;
2323 }
2312 2324
2313 if (dev->horkage & ATA_HORKAGE_MAX_SEC_128) 2325 if (dev->horkage & ATA_HORKAGE_MAX_SEC_128)
2314 dev->max_sectors = min_t(unsigned int, ATA_MAX_SECTORS_128, 2326 dev->max_sectors = min_t(unsigned int, ATA_MAX_SECTORS_128,
@@ -2581,81 +2593,6 @@ void sata_print_link_status(struct ata_link *link)
2581} 2593}
2582 2594
2583/** 2595/**
2584 * __sata_phy_reset - Wake/reset a low-level SATA PHY
2585 * @ap: SATA port associated with target SATA PHY.
2586 *
2587 * This function issues commands to standard SATA Sxxx
2588 * PHY registers, to wake up the phy (and device), and
2589 * clear any reset condition.
2590 *
2591 * LOCKING:
2592 * PCI/etc. bus probe sem.
2593 *
2594 */
2595void __sata_phy_reset(struct ata_port *ap)
2596{
2597 struct ata_link *link = &ap->link;
2598 unsigned long timeout = jiffies + (HZ * 5);
2599 u32 sstatus;
2600
2601 if (ap->flags & ATA_FLAG_SATA_RESET) {
2602 /* issue phy wake/reset */
2603 sata_scr_write_flush(link, SCR_CONTROL, 0x301);
2604 /* Couldn't find anything in SATA I/II specs, but
2605 * AHCI-1.1 10.4.2 says at least 1 ms. */
2606 mdelay(1);
2607 }
2608 /* phy wake/clear reset */
2609 sata_scr_write_flush(link, SCR_CONTROL, 0x300);
2610
2611 /* wait for phy to become ready, if necessary */
2612 do {
2613 msleep(200);
2614 sata_scr_read(link, SCR_STATUS, &sstatus);
2615 if ((sstatus & 0xf) != 1)
2616 break;
2617 } while (time_before(jiffies, timeout));
2618
2619 /* print link status */
2620 sata_print_link_status(link);
2621
2622 /* TODO: phy layer with polling, timeouts, etc. */
2623 if (!ata_link_offline(link))
2624 ata_port_probe(ap);
2625 else
2626 ata_port_disable(ap);
2627
2628 if (ap->flags & ATA_FLAG_DISABLED)
2629 return;
2630
2631 if (ata_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT)) {
2632 ata_port_disable(ap);
2633 return;
2634 }
2635
2636 ap->cbl = ATA_CBL_SATA;
2637}
2638
2639/**
2640 * sata_phy_reset - Reset SATA bus.
2641 * @ap: SATA port associated with target SATA PHY.
2642 *
2643 * This function resets the SATA bus, and then probes
2644 * the bus for devices.
2645 *
2646 * LOCKING:
2647 * PCI/etc. bus probe sem.
2648 *
2649 */
2650void sata_phy_reset(struct ata_port *ap)
2651{
2652 __sata_phy_reset(ap);
2653 if (ap->flags & ATA_FLAG_DISABLED)
2654 return;
2655 ata_bus_reset(ap);
2656}
2657
2658/**
2659 * ata_dev_pair - return other device on cable 2596 * ata_dev_pair - return other device on cable
2660 * @adev: device 2597 * @adev: device
2661 * 2598 *
@@ -3988,6 +3925,7 @@ void ata_std_postreset(struct ata_link *link, unsigned int *classes)
3988 /* clear SError */ 3925 /* clear SError */
3989 if (sata_scr_read(link, SCR_ERROR, &serror) == 0) 3926 if (sata_scr_read(link, SCR_ERROR, &serror) == 0)
3990 sata_scr_write(link, SCR_ERROR, serror); 3927 sata_scr_write(link, SCR_ERROR, serror);
3928 link->eh_info.serror = 0;
3991 3929
3992 /* is double-select really necessary? */ 3930 /* is double-select really necessary? */
3993 if (classes[0] != ATA_DEV_NONE) 3931 if (classes[0] != ATA_DEV_NONE)
@@ -4205,6 +4143,7 @@ static const struct ata_blacklist_entry ata_device_blacklist [] = {
4205 /* Devices where NCQ should be avoided */ 4143 /* Devices where NCQ should be avoided */
4206 /* NCQ is slow */ 4144 /* NCQ is slow */
4207 { "WDC WD740ADFD-00", NULL, ATA_HORKAGE_NONCQ }, 4145 { "WDC WD740ADFD-00", NULL, ATA_HORKAGE_NONCQ },
4146 { "WDC WD740ADFD-00NLR1", NULL, ATA_HORKAGE_NONCQ, },
4208 /* http://thread.gmane.org/gmane.linux.ide/14907 */ 4147 /* http://thread.gmane.org/gmane.linux.ide/14907 */
4209 { "FUJITSU MHT2060BH", NULL, ATA_HORKAGE_NONCQ }, 4148 { "FUJITSU MHT2060BH", NULL, ATA_HORKAGE_NONCQ },
4210 /* NCQ is broken */ 4149 /* NCQ is broken */
@@ -4213,29 +4152,13 @@ static const struct ata_blacklist_entry ata_device_blacklist [] = {
4213 { "HITACHI HDS7250SASUN500G*", NULL, ATA_HORKAGE_NONCQ }, 4152 { "HITACHI HDS7250SASUN500G*", NULL, ATA_HORKAGE_NONCQ },
4214 { "HITACHI HDS7225SBSUN250G*", NULL, ATA_HORKAGE_NONCQ }, 4153 { "HITACHI HDS7225SBSUN250G*", NULL, ATA_HORKAGE_NONCQ },
4215 { "ST380817AS", "3.42", ATA_HORKAGE_NONCQ }, 4154 { "ST380817AS", "3.42", ATA_HORKAGE_NONCQ },
4155 { "ST3160023AS", "3.42", ATA_HORKAGE_NONCQ },
4216 4156
4217 /* Blacklist entries taken from Silicon Image 3124/3132 4157 /* Blacklist entries taken from Silicon Image 3124/3132
4218 Windows driver .inf file - also several Linux problem reports */ 4158 Windows driver .inf file - also several Linux problem reports */
4219 { "HTS541060G9SA00", "MB3OC60D", ATA_HORKAGE_NONCQ, }, 4159 { "HTS541060G9SA00", "MB3OC60D", ATA_HORKAGE_NONCQ, },
4220 { "HTS541080G9SA00", "MB4OC60D", ATA_HORKAGE_NONCQ, }, 4160 { "HTS541080G9SA00", "MB4OC60D", ATA_HORKAGE_NONCQ, },
4221 { "HTS541010G9SA00", "MBZOC60D", ATA_HORKAGE_NONCQ, }, 4161 { "HTS541010G9SA00", "MBZOC60D", ATA_HORKAGE_NONCQ, },
4222 /* Drives which do spurious command completion */
4223 { "HTS541680J9SA00", "SB2IC7EP", ATA_HORKAGE_NONCQ, },
4224 { "HTS541612J9SA00", "SBDIC7JP", ATA_HORKAGE_NONCQ, },
4225 { "HDT722516DLA380", "V43OA96A", ATA_HORKAGE_NONCQ, },
4226 { "Hitachi HTS541616J9SA00", "SB4OC70P", ATA_HORKAGE_NONCQ, },
4227 { "Hitachi HTS542525K9SA00", "BBFOC31P", ATA_HORKAGE_NONCQ, },
4228 { "WDC WD740ADFD-00NLR1", NULL, ATA_HORKAGE_NONCQ, },
4229 { "WDC WD3200AAJS-00RYA0", "12.01B01", ATA_HORKAGE_NONCQ, },
4230 { "FUJITSU MHV2080BH", "00840028", ATA_HORKAGE_NONCQ, },
4231 { "ST9120822AS", "3.CLF", ATA_HORKAGE_NONCQ, },
4232 { "ST9160821AS", "3.CLF", ATA_HORKAGE_NONCQ, },
4233 { "ST9160821AS", "3.ALD", ATA_HORKAGE_NONCQ, },
4234 { "ST9160821AS", "3.CCD", ATA_HORKAGE_NONCQ, },
4235 { "ST3160812AS", "3.ADJ", ATA_HORKAGE_NONCQ, },
4236 { "ST980813AS", "3.ADB", ATA_HORKAGE_NONCQ, },
4237 { "SAMSUNG HD401LJ", "ZZ100-15", ATA_HORKAGE_NONCQ, },
4238 { "Maxtor 7V300F0", "VA111900", ATA_HORKAGE_NONCQ, },
4239 4162
4240 /* devices which puke on READ_NATIVE_MAX */ 4163 /* devices which puke on READ_NATIVE_MAX */
4241 { "HDS724040KLSA80", "KFAOA20N", ATA_HORKAGE_BROKEN_HPA, }, 4164 { "HDS724040KLSA80", "KFAOA20N", ATA_HORKAGE_BROKEN_HPA, },
@@ -4250,6 +4173,9 @@ static const struct ata_blacklist_entry ata_device_blacklist [] = {
4250 /* Devices which get the IVB wrong */ 4173 /* Devices which get the IVB wrong */
4251 { "QUANTUM FIREBALLlct10 05", "A03.0900", ATA_HORKAGE_IVB, }, 4174 { "QUANTUM FIREBALLlct10 05", "A03.0900", ATA_HORKAGE_IVB, },
4252 { "TSSTcorp CDDVDW SH-S202J", "SB00", ATA_HORKAGE_IVB, }, 4175 { "TSSTcorp CDDVDW SH-S202J", "SB00", ATA_HORKAGE_IVB, },
4176 { "TSSTcorp CDDVDW SH-S202J", "SB01", ATA_HORKAGE_IVB, },
4177 { "TSSTcorp CDDVDW SH-S202N", "SB00", ATA_HORKAGE_IVB, },
4178 { "TSSTcorp CDDVDW SH-S202N", "SB01", ATA_HORKAGE_IVB, },
4253 4179
4254 /* End Marker */ 4180 /* End Marker */
4255 { } 4181 { }
@@ -4727,6 +4653,43 @@ int ata_check_atapi_dma(struct ata_queued_cmd *qc)
4727} 4653}
4728 4654
4729/** 4655/**
4656 * atapi_qc_may_overflow - Check whether data transfer may overflow
4657 * @qc: ATA command in question
4658 *
4659 * ATAPI commands which transfer variable length data to host
4660 * might overflow due to application error or hardare bug. This
4661 * function checks whether overflow should be drained and ignored
4662 * for @qc.
4663 *
4664 * LOCKING:
4665 * None.
4666 *
4667 * RETURNS:
4668 * 1 if @qc may overflow; otherwise, 0.
4669 */
4670static int atapi_qc_may_overflow(struct ata_queued_cmd *qc)
4671{
4672 if (qc->tf.protocol != ATA_PROT_ATAPI &&
4673 qc->tf.protocol != ATA_PROT_ATAPI_DMA)
4674 return 0;
4675
4676 if (qc->tf.flags & ATA_TFLAG_WRITE)
4677 return 0;
4678
4679 switch (qc->cdb[0]) {
4680 case READ_10:
4681 case READ_12:
4682 case WRITE_10:
4683 case WRITE_12:
4684 case GPCMD_READ_CD:
4685 case GPCMD_READ_CD_MSF:
4686 return 0;
4687 }
4688
4689 return 1;
4690}
4691
4692/**
4730 * ata_std_qc_defer - Check whether a qc needs to be deferred 4693 * ata_std_qc_defer - Check whether a qc needs to be deferred
4731 * @qc: ATA command in question 4694 * @qc: ATA command in question
4732 * 4695 *
@@ -5214,23 +5177,19 @@ static void atapi_send_cdb(struct ata_port *ap, struct ata_queued_cmd *qc)
5214 * Inherited from caller. 5177 * Inherited from caller.
5215 * 5178 *
5216 */ 5179 */
5217 5180static int __atapi_pio_bytes(struct ata_queued_cmd *qc, unsigned int bytes)
5218static void __atapi_pio_bytes(struct ata_queued_cmd *qc, unsigned int bytes)
5219{ 5181{
5220 int do_write = (qc->tf.flags & ATA_TFLAG_WRITE); 5182 int do_write = (qc->tf.flags & ATA_TFLAG_WRITE);
5221 struct scatterlist *sg = qc->__sg;
5222 struct scatterlist *lsg = sg_last(qc->__sg, qc->n_elem);
5223 struct ata_port *ap = qc->ap; 5183 struct ata_port *ap = qc->ap;
5184 struct ata_eh_info *ehi = &qc->dev->link->eh_info;
5185 struct scatterlist *sg;
5224 struct page *page; 5186 struct page *page;
5225 unsigned char *buf; 5187 unsigned char *buf;
5226 unsigned int offset, count; 5188 unsigned int offset, count;
5227 int no_more_sg = 0;
5228
5229 if (qc->curbytes + bytes >= qc->nbytes)
5230 ap->hsm_task_state = HSM_ST_LAST;
5231 5189
5232next_sg: 5190next_sg:
5233 if (unlikely(no_more_sg)) { 5191 sg = qc->cursg;
5192 if (unlikely(!sg)) {
5234 /* 5193 /*
5235 * The end of qc->sg is reached and the device expects 5194 * The end of qc->sg is reached and the device expects
5236 * more data to transfer. In order not to overrun qc->sg 5195 * more data to transfer. In order not to overrun qc->sg
@@ -5239,21 +5198,28 @@ next_sg:
5239 * - for write case, padding zero data to the device 5198 * - for write case, padding zero data to the device
5240 */ 5199 */
5241 u16 pad_buf[1] = { 0 }; 5200 u16 pad_buf[1] = { 0 };
5242 unsigned int words = bytes >> 1;
5243 unsigned int i; 5201 unsigned int i;
5244 5202
5245 if (words) /* warning if bytes > 1 */ 5203 if (bytes > qc->curbytes - qc->nbytes + ATAPI_MAX_DRAIN) {
5246 ata_dev_printk(qc->dev, KERN_WARNING, 5204 ata_ehi_push_desc(ehi, "too much trailing data "
5247 "%u bytes trailing data\n", bytes); 5205 "buf=%u cur=%u bytes=%u",
5206 qc->nbytes, qc->curbytes, bytes);
5207 return -1;
5208 }
5209
5210 /* overflow is exptected for misc ATAPI commands */
5211 if (bytes && !atapi_qc_may_overflow(qc))
5212 ata_dev_printk(qc->dev, KERN_WARNING, "ATAPI %u bytes "
5213 "trailing data (cdb=%02x nbytes=%u)\n",
5214 bytes, qc->cdb[0], qc->nbytes);
5248 5215
5249 for (i = 0; i < words; i++) 5216 for (i = 0; i < (bytes + 1) / 2; i++)
5250 ap->ops->data_xfer(qc->dev, (unsigned char *)pad_buf, 2, do_write); 5217 ap->ops->data_xfer(qc->dev, (unsigned char *)pad_buf, 2, do_write);
5251 5218
5252 ap->hsm_task_state = HSM_ST_LAST; 5219 qc->curbytes += bytes;
5253 return;
5254 }
5255 5220
5256 sg = qc->cursg; 5221 return 0;
5222 }
5257 5223
5258 page = sg_page(sg); 5224 page = sg_page(sg);
5259 offset = sg->offset + qc->cursg_ofs; 5225 offset = sg->offset + qc->cursg_ofs;
@@ -5288,19 +5254,20 @@ next_sg:
5288 } 5254 }
5289 5255
5290 bytes -= count; 5256 bytes -= count;
5257 if ((count & 1) && bytes)
5258 bytes--;
5291 qc->curbytes += count; 5259 qc->curbytes += count;
5292 qc->cursg_ofs += count; 5260 qc->cursg_ofs += count;
5293 5261
5294 if (qc->cursg_ofs == sg->length) { 5262 if (qc->cursg_ofs == sg->length) {
5295 if (qc->cursg == lsg)
5296 no_more_sg = 1;
5297
5298 qc->cursg = sg_next(qc->cursg); 5263 qc->cursg = sg_next(qc->cursg);
5299 qc->cursg_ofs = 0; 5264 qc->cursg_ofs = 0;
5300 } 5265 }
5301 5266
5302 if (bytes) 5267 if (bytes)
5303 goto next_sg; 5268 goto next_sg;
5269
5270 return 0;
5304} 5271}
5305 5272
5306/** 5273/**
@@ -5343,7 +5310,8 @@ static void atapi_pio_bytes(struct ata_queued_cmd *qc)
5343 5310
5344 VPRINTK("ata%u: xfering %d bytes\n", ap->print_id, bytes); 5311 VPRINTK("ata%u: xfering %d bytes\n", ap->print_id, bytes);
5345 5312
5346 __atapi_pio_bytes(qc, bytes); 5313 if (__atapi_pio_bytes(qc, bytes))
5314 goto err_out;
5347 ata_altstatus(ap); /* flush */ 5315 ata_altstatus(ap); /* flush */
5348 5316
5349 return; 5317 return;
@@ -5490,11 +5458,19 @@ fsm_start:
5490 * let the EH abort the command or reset the device. 5458 * let the EH abort the command or reset the device.
5491 */ 5459 */
5492 if (unlikely(status & (ATA_ERR | ATA_DF))) { 5460 if (unlikely(status & (ATA_ERR | ATA_DF))) {
5493 ata_port_printk(ap, KERN_WARNING, "DRQ=1 with device " 5461 /* Some ATAPI tape drives forget to clear the ERR bit
5494 "error, dev_stat 0x%X\n", status); 5462 * when doing the next command (mostly request sense).
5495 qc->err_mask |= AC_ERR_HSM; 5463 * We ignore ERR here to workaround and proceed sending
5496 ap->hsm_task_state = HSM_ST_ERR; 5464 * the CDB.
5497 goto fsm_start; 5465 */
5466 if (!(qc->dev->horkage & ATA_HORKAGE_STUCK_ERR)) {
5467 ata_port_printk(ap, KERN_WARNING,
5468 "DRQ=1 with device error, "
5469 "dev_stat 0x%X\n", status);
5470 qc->err_mask |= AC_ERR_HSM;
5471 ap->hsm_task_state = HSM_ST_ERR;
5472 goto fsm_start;
5473 }
5498 } 5474 }
5499 5475
5500 /* Send the CDB (atapi) or the first data block (ata pio out). 5476 /* Send the CDB (atapi) or the first data block (ata pio out).
@@ -7021,12 +6997,11 @@ int ata_host_start(struct ata_host *host)
7021 if (ap->ops->port_start) { 6997 if (ap->ops->port_start) {
7022 rc = ap->ops->port_start(ap); 6998 rc = ap->ops->port_start(ap);
7023 if (rc) { 6999 if (rc) {
7024 ata_port_printk(ap, KERN_ERR, "failed to " 7000 if (rc != -ENODEV)
7025 "start port (errno=%d)\n", rc); 7001 dev_printk(KERN_ERR, host->dev, "failed to start port %d (errno=%d)\n", i, rc);
7026 goto err_out; 7002 goto err_out;
7027 } 7003 }
7028 } 7004 }
7029
7030 ata_eh_freeze_port(ap); 7005 ata_eh_freeze_port(ap);
7031 } 7006 }
7032 7007
@@ -7279,18 +7254,14 @@ static void ata_port_detach(struct ata_port *ap)
7279 7254
7280 ata_port_wait_eh(ap); 7255 ata_port_wait_eh(ap);
7281 7256
7282 /* EH is now guaranteed to see UNLOADING, so no new device 7257 /* EH is now guaranteed to see UNLOADING - EH context belongs
7283 * will be attached. Disable all existing devices. 7258 * to us. Disable all existing devices.
7284 */ 7259 */
7285 spin_lock_irqsave(ap->lock, flags);
7286
7287 ata_port_for_each_link(link, ap) { 7260 ata_port_for_each_link(link, ap) {
7288 ata_link_for_each_dev(dev, link) 7261 ata_link_for_each_dev(dev, link)
7289 ata_dev_disable(dev); 7262 ata_dev_disable(dev);
7290 } 7263 }
7291 7264
7292 spin_unlock_irqrestore(ap->lock, flags);
7293
7294 /* Final freeze & EH. All in-flight commands are aborted. EH 7265 /* Final freeze & EH. All in-flight commands are aborted. EH
7295 * will be skipped and retrials will be terminated with bad 7266 * will be skipped and retrials will be terminated with bad
7296 * target. 7267 * target.
@@ -7322,6 +7293,9 @@ void ata_host_detach(struct ata_host *host)
7322 7293
7323 for (i = 0; i < host->n_ports; i++) 7294 for (i = 0; i < host->n_ports; i++)
7324 ata_port_detach(host->ports[i]); 7295 ata_port_detach(host->ports[i]);
7296
7297 /* the host is dead now, dissociate ACPI */
7298 ata_acpi_dissociate(host);
7325} 7299}
7326 7300
7327/** 7301/**
@@ -7653,8 +7627,6 @@ EXPORT_SYMBOL_GPL(ata_dev_disable);
7653EXPORT_SYMBOL_GPL(sata_set_spd); 7627EXPORT_SYMBOL_GPL(sata_set_spd);
7654EXPORT_SYMBOL_GPL(sata_link_debounce); 7628EXPORT_SYMBOL_GPL(sata_link_debounce);
7655EXPORT_SYMBOL_GPL(sata_link_resume); 7629EXPORT_SYMBOL_GPL(sata_link_resume);
7656EXPORT_SYMBOL_GPL(sata_phy_reset);
7657EXPORT_SYMBOL_GPL(__sata_phy_reset);
7658EXPORT_SYMBOL_GPL(ata_bus_reset); 7630EXPORT_SYMBOL_GPL(ata_bus_reset);
7659EXPORT_SYMBOL_GPL(ata_std_prereset); 7631EXPORT_SYMBOL_GPL(ata_std_prereset);
7660EXPORT_SYMBOL_GPL(ata_std_softreset); 7632EXPORT_SYMBOL_GPL(ata_std_softreset);
@@ -7725,7 +7697,6 @@ EXPORT_SYMBOL_GPL(ata_port_desc);
7725#ifdef CONFIG_PCI 7697#ifdef CONFIG_PCI
7726EXPORT_SYMBOL_GPL(ata_port_pbar_desc); 7698EXPORT_SYMBOL_GPL(ata_port_pbar_desc);
7727#endif /* CONFIG_PCI */ 7699#endif /* CONFIG_PCI */
7728EXPORT_SYMBOL_GPL(ata_eng_timeout);
7729EXPORT_SYMBOL_GPL(ata_port_schedule_eh); 7700EXPORT_SYMBOL_GPL(ata_port_schedule_eh);
7730EXPORT_SYMBOL_GPL(ata_link_abort); 7701EXPORT_SYMBOL_GPL(ata_link_abort);
7731EXPORT_SYMBOL_GPL(ata_port_abort); 7702EXPORT_SYMBOL_GPL(ata_port_abort);
diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c
index ed8813b222a0..f0124a8d3134 100644
--- a/drivers/ata/libata-eh.c
+++ b/drivers/ata/libata-eh.c
@@ -559,101 +559,6 @@ void ata_port_wait_eh(struct ata_port *ap)
559 } 559 }
560} 560}
561 561
562/**
563 * ata_qc_timeout - Handle timeout of queued command
564 * @qc: Command that timed out
565 *
566 * Some part of the kernel (currently, only the SCSI layer)
567 * has noticed that the active command on port @ap has not
568 * completed after a specified length of time. Handle this
569 * condition by disabling DMA (if necessary) and completing
570 * transactions, with error if necessary.
571 *
572 * This also handles the case of the "lost interrupt", where
573 * for some reason (possibly hardware bug, possibly driver bug)
574 * an interrupt was not delivered to the driver, even though the
575 * transaction completed successfully.
576 *
577 * TODO: kill this function once old EH is gone.
578 *
579 * LOCKING:
580 * Inherited from SCSI layer (none, can sleep)
581 */
582static void ata_qc_timeout(struct ata_queued_cmd *qc)
583{
584 struct ata_port *ap = qc->ap;
585 u8 host_stat = 0, drv_stat;
586 unsigned long flags;
587
588 DPRINTK("ENTER\n");
589
590 ap->hsm_task_state = HSM_ST_IDLE;
591
592 spin_lock_irqsave(ap->lock, flags);
593
594 switch (qc->tf.protocol) {
595
596 case ATA_PROT_DMA:
597 case ATA_PROT_ATAPI_DMA:
598 host_stat = ap->ops->bmdma_status(ap);
599
600 /* before we do anything else, clear DMA-Start bit */
601 ap->ops->bmdma_stop(qc);
602
603 /* fall through */
604
605 default:
606 ata_altstatus(ap);
607 drv_stat = ata_chk_status(ap);
608
609 /* ack bmdma irq events */
610 ap->ops->irq_clear(ap);
611
612 ata_dev_printk(qc->dev, KERN_ERR, "command 0x%x timeout, "
613 "stat 0x%x host_stat 0x%x\n",
614 qc->tf.command, drv_stat, host_stat);
615
616 /* complete taskfile transaction */
617 qc->err_mask |= AC_ERR_TIMEOUT;
618 break;
619 }
620
621 spin_unlock_irqrestore(ap->lock, flags);
622
623 ata_eh_qc_complete(qc);
624
625 DPRINTK("EXIT\n");
626}
627
628/**
629 * ata_eng_timeout - Handle timeout of queued command
630 * @ap: Port on which timed-out command is active
631 *
632 * Some part of the kernel (currently, only the SCSI layer)
633 * has noticed that the active command on port @ap has not
634 * completed after a specified length of time. Handle this
635 * condition by disabling DMA (if necessary) and completing
636 * transactions, with error if necessary.
637 *
638 * This also handles the case of the "lost interrupt", where
639 * for some reason (possibly hardware bug, possibly driver bug)
640 * an interrupt was not delivered to the driver, even though the
641 * transaction completed successfully.
642 *
643 * TODO: kill this function once old EH is gone.
644 *
645 * LOCKING:
646 * Inherited from SCSI layer (none, can sleep)
647 */
648void ata_eng_timeout(struct ata_port *ap)
649{
650 DPRINTK("ENTER\n");
651
652 ata_qc_timeout(ata_qc_from_tag(ap, ap->link.active_tag));
653
654 DPRINTK("EXIT\n");
655}
656
657static int ata_eh_nr_in_flight(struct ata_port *ap) 562static int ata_eh_nr_in_flight(struct ata_port *ap)
658{ 563{
659 unsigned int tag; 564 unsigned int tag;
@@ -1359,8 +1264,8 @@ static unsigned int atapi_eh_request_sense(struct ata_queued_cmd *qc)
1359 tf.feature |= ATAPI_PKT_DMA; 1264 tf.feature |= ATAPI_PKT_DMA;
1360 } else { 1265 } else {
1361 tf.protocol = ATA_PROT_ATAPI; 1266 tf.protocol = ATA_PROT_ATAPI;
1362 tf.lbam = (8 * 1024) & 0xff; 1267 tf.lbam = SCSI_SENSE_BUFFERSIZE;
1363 tf.lbah = (8 * 1024) >> 8; 1268 tf.lbah = 0;
1364 } 1269 }
1365 1270
1366 return ata_exec_internal(dev, &tf, cdb, DMA_FROM_DEVICE, 1271 return ata_exec_internal(dev, &tf, cdb, DMA_FROM_DEVICE,
@@ -1945,30 +1850,54 @@ static void ata_eh_link_report(struct ata_link *link)
1945 ehc->i.serror & SERR_DEV_XCHG ? "DevExch " : ""); 1850 ehc->i.serror & SERR_DEV_XCHG ? "DevExch " : "");
1946 1851
1947 for (tag = 0; tag < ATA_MAX_QUEUE; tag++) { 1852 for (tag = 0; tag < ATA_MAX_QUEUE; tag++) {
1948 static const char *dma_str[] = {
1949 [DMA_BIDIRECTIONAL] = "bidi",
1950 [DMA_TO_DEVICE] = "out",
1951 [DMA_FROM_DEVICE] = "in",
1952 [DMA_NONE] = "",
1953 };
1954 struct ata_queued_cmd *qc = __ata_qc_from_tag(ap, tag); 1853 struct ata_queued_cmd *qc = __ata_qc_from_tag(ap, tag);
1955 struct ata_taskfile *cmd = &qc->tf, *res = &qc->result_tf; 1854 struct ata_taskfile *cmd = &qc->tf, *res = &qc->result_tf;
1855 const u8 *cdb = qc->cdb;
1856 char data_buf[20] = "";
1857 char cdb_buf[70] = "";
1956 1858
1957 if (!(qc->flags & ATA_QCFLAG_FAILED) || 1859 if (!(qc->flags & ATA_QCFLAG_FAILED) ||
1958 qc->dev->link != link || !qc->err_mask) 1860 qc->dev->link != link || !qc->err_mask)
1959 continue; 1861 continue;
1960 1862
1863 if (qc->dma_dir != DMA_NONE) {
1864 static const char *dma_str[] = {
1865 [DMA_BIDIRECTIONAL] = "bidi",
1866 [DMA_TO_DEVICE] = "out",
1867 [DMA_FROM_DEVICE] = "in",
1868 };
1869 static const char *prot_str[] = {
1870 [ATA_PROT_PIO] = "pio",
1871 [ATA_PROT_DMA] = "dma",
1872 [ATA_PROT_NCQ] = "ncq",
1873 [ATA_PROT_ATAPI] = "pio",
1874 [ATA_PROT_ATAPI_DMA] = "dma",
1875 };
1876
1877 snprintf(data_buf, sizeof(data_buf), " %s %u %s",
1878 prot_str[qc->tf.protocol], qc->nbytes,
1879 dma_str[qc->dma_dir]);
1880 }
1881
1882 if (is_atapi_taskfile(&qc->tf))
1883 snprintf(cdb_buf, sizeof(cdb_buf),
1884 "cdb %02x %02x %02x %02x %02x %02x %02x %02x "
1885 "%02x %02x %02x %02x %02x %02x %02x %02x\n ",
1886 cdb[0], cdb[1], cdb[2], cdb[3],
1887 cdb[4], cdb[5], cdb[6], cdb[7],
1888 cdb[8], cdb[9], cdb[10], cdb[11],
1889 cdb[12], cdb[13], cdb[14], cdb[15]);
1890
1961 ata_dev_printk(qc->dev, KERN_ERR, 1891 ata_dev_printk(qc->dev, KERN_ERR,
1962 "cmd %02x/%02x:%02x:%02x:%02x:%02x/%02x:%02x:%02x:%02x:%02x/%02x " 1892 "cmd %02x/%02x:%02x:%02x:%02x:%02x/%02x:%02x:%02x:%02x:%02x/%02x "
1963 "tag %d cdb 0x%x data %u %s\n " 1893 "tag %d%s\n %s"
1964 "res %02x/%02x:%02x:%02x:%02x:%02x/%02x:%02x:%02x:%02x:%02x/%02x " 1894 "res %02x/%02x:%02x:%02x:%02x:%02x/%02x:%02x:%02x:%02x:%02x/%02x "
1965 "Emask 0x%x (%s)%s\n", 1895 "Emask 0x%x (%s)%s\n",
1966 cmd->command, cmd->feature, cmd->nsect, 1896 cmd->command, cmd->feature, cmd->nsect,
1967 cmd->lbal, cmd->lbam, cmd->lbah, 1897 cmd->lbal, cmd->lbam, cmd->lbah,
1968 cmd->hob_feature, cmd->hob_nsect, 1898 cmd->hob_feature, cmd->hob_nsect,
1969 cmd->hob_lbal, cmd->hob_lbam, cmd->hob_lbah, 1899 cmd->hob_lbal, cmd->hob_lbam, cmd->hob_lbah,
1970 cmd->device, qc->tag, qc->cdb[0], qc->nbytes, 1900 cmd->device, qc->tag, data_buf, cdb_buf,
1971 dma_str[qc->dma_dir],
1972 res->command, res->feature, res->nsect, 1901 res->command, res->feature, res->nsect,
1973 res->lbal, res->lbam, res->lbah, 1902 res->lbal, res->lbam, res->lbah,
1974 res->hob_feature, res->hob_nsect, 1903 res->hob_feature, res->hob_nsect,
diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index 94144ed50a6b..a883bb03d4c7 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -2485,11 +2485,40 @@ static unsigned int atapi_xlat(struct ata_queued_cmd *qc)
2485 if (!using_pio && ata_check_atapi_dma(qc)) 2485 if (!using_pio && ata_check_atapi_dma(qc))
2486 using_pio = 1; 2486 using_pio = 1;
2487 2487
2488 /* Some controller variants snoop this value for Packet transfers 2488 /* Some controller variants snoop this value for Packet
2489 to do state machine and FIFO management. Thus we want to set it 2489 * transfers to do state machine and FIFO management. Thus we
2490 properly, and for DMA where it is effectively meaningless */ 2490 * want to set it properly, and for DMA where it is
2491 * effectively meaningless.
2492 */
2491 nbytes = min(qc->nbytes, (unsigned int)63 * 1024); 2493 nbytes = min(qc->nbytes, (unsigned int)63 * 1024);
2492 2494
2495 /* Most ATAPI devices which honor transfer chunk size don't
2496 * behave according to the spec when odd chunk size which
2497 * matches the transfer length is specified. If the number of
2498 * bytes to transfer is 2n+1. According to the spec, what
2499 * should happen is to indicate that 2n+1 is going to be
2500 * transferred and transfer 2n+2 bytes where the last byte is
2501 * padding.
2502 *
2503 * In practice, this doesn't happen. ATAPI devices first
2504 * indicate and transfer 2n bytes and then indicate and
2505 * transfer 2 bytes where the last byte is padding.
2506 *
2507 * This inconsistency confuses several controllers which
2508 * perform PIO using DMA such as Intel AHCIs and sil3124/32.
2509 * These controllers use actual number of transferred bytes to
2510 * update DMA poitner and transfer of 4n+2 bytes make those
2511 * controller push DMA pointer by 4n+4 bytes because SATA data
2512 * FISes are aligned to 4 bytes. This causes data corruption
2513 * and buffer overrun.
2514 *
2515 * Always setting nbytes to even number solves this problem
2516 * because then ATAPI devices don't have to split data at 2n
2517 * boundaries.
2518 */
2519 if (nbytes & 0x1)
2520 nbytes++;
2521
2493 qc->tf.lbam = (nbytes & 0xFF); 2522 qc->tf.lbam = (nbytes & 0xFF);
2494 qc->tf.lbah = (nbytes >> 8); 2523 qc->tf.lbah = (nbytes >> 8);
2495 2524
@@ -2869,7 +2898,8 @@ static inline int __ata_scsi_queuecmd(struct scsi_cmnd *scmd,
2869 xlat_func = NULL; 2898 xlat_func = NULL;
2870 if (likely((scsi_op != ATA_16) || !atapi_passthru16)) { 2899 if (likely((scsi_op != ATA_16) || !atapi_passthru16)) {
2871 /* relay SCSI command to ATAPI device */ 2900 /* relay SCSI command to ATAPI device */
2872 if (unlikely(scmd->cmd_len > dev->cdb_len)) 2901 int len = COMMAND_SIZE(scsi_op);
2902 if (unlikely(len > scmd->cmd_len || len > dev->cdb_len))
2873 goto bad_cdb_len; 2903 goto bad_cdb_len;
2874 2904
2875 xlat_func = atapi_xlat; 2905 xlat_func = atapi_xlat;
diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
index 0e6cf3a484dc..bbe59c2fd1e2 100644
--- a/drivers/ata/libata.h
+++ b/drivers/ata/libata.h
@@ -108,15 +108,19 @@ extern void ata_lpm_schedule(struct ata_port *ap, enum link_pm);
108#ifdef CONFIG_ATA_ACPI 108#ifdef CONFIG_ATA_ACPI
109extern void ata_acpi_associate_sata_port(struct ata_port *ap); 109extern void ata_acpi_associate_sata_port(struct ata_port *ap);
110extern void ata_acpi_associate(struct ata_host *host); 110extern void ata_acpi_associate(struct ata_host *host);
111extern void ata_acpi_dissociate(struct ata_host *host);
111extern int ata_acpi_on_suspend(struct ata_port *ap); 112extern int ata_acpi_on_suspend(struct ata_port *ap);
112extern void ata_acpi_on_resume(struct ata_port *ap); 113extern void ata_acpi_on_resume(struct ata_port *ap);
113extern int ata_acpi_on_devcfg(struct ata_device *adev); 114extern int ata_acpi_on_devcfg(struct ata_device *dev);
115extern void ata_acpi_on_disable(struct ata_device *dev);
114#else 116#else
115static inline void ata_acpi_associate_sata_port(struct ata_port *ap) { } 117static inline void ata_acpi_associate_sata_port(struct ata_port *ap) { }
116static inline void ata_acpi_associate(struct ata_host *host) { } 118static inline void ata_acpi_associate(struct ata_host *host) { }
119static inline void ata_acpi_dissociate(struct ata_host *host) { }
117static inline int ata_acpi_on_suspend(struct ata_port *ap) { return 0; } 120static inline int ata_acpi_on_suspend(struct ata_port *ap) { return 0; }
118static inline void ata_acpi_on_resume(struct ata_port *ap) { } 121static inline void ata_acpi_on_resume(struct ata_port *ap) { }
119static inline int ata_acpi_on_devcfg(struct ata_device *adev) { return 0; } 122static inline int ata_acpi_on_devcfg(struct ata_device *dev) { return 0; }
123static inline void ata_acpi_on_disable(struct ata_device *dev) { }
120#endif 124#endif
121 125
122/* libata-scsi.c */ 126/* libata-scsi.c */
diff --git a/drivers/ata/pata_ali.c b/drivers/ata/pata_ali.c
index 364534e7aff4..8caf9afc8b90 100644
--- a/drivers/ata/pata_ali.c
+++ b/drivers/ata/pata_ali.c
@@ -63,6 +63,9 @@ static int ali_cable_override(struct pci_dev *pdev)
63 /* Fujitsu P2000 */ 63 /* Fujitsu P2000 */
64 if (pdev->subsystem_vendor == 0x10CF && pdev->subsystem_device == 0x10AF) 64 if (pdev->subsystem_vendor == 0x10CF && pdev->subsystem_device == 0x10AF)
65 return 1; 65 return 1;
66 /* Mitac 8317 (Winbook-A) and relatives */
67 if (pdev->subsystem_vendor == 0x1071 && pdev->subsystem_device == 0x8317)
68 return 1;
66 /* Systems by DMI */ 69 /* Systems by DMI */
67 if (dmi_check_system(cable_dmi_table)) 70 if (dmi_check_system(cable_dmi_table))
68 return 1; 71 return 1;
@@ -282,6 +285,21 @@ static void ali_lock_sectors(struct ata_device *adev)
282 adev->max_sectors = 255; 285 adev->max_sectors = 255;
283} 286}
284 287
288/**
289 * ali_check_atapi_dma - DMA check for most ALi controllers
290 * @adev: Device
291 *
292 * Called to decide whether commands should be sent by DMA or PIO
293 */
294
295static int ali_check_atapi_dma(struct ata_queued_cmd *qc)
296{
297 /* If its not a media command, its not worth it */
298 if (qc->nbytes < 2048)
299 return -EOPNOTSUPP;
300 return 0;
301}
302
285static struct scsi_host_template ali_sht = { 303static struct scsi_host_template ali_sht = {
286 .module = THIS_MODULE, 304 .module = THIS_MODULE,
287 .name = DRV_NAME, 305 .name = DRV_NAME,
@@ -378,6 +396,7 @@ static struct ata_port_operations ali_c2_port_ops = {
378 .mode_filter = ata_pci_default_filter, 396 .mode_filter = ata_pci_default_filter,
379 .tf_load = ata_tf_load, 397 .tf_load = ata_tf_load,
380 .tf_read = ata_tf_read, 398 .tf_read = ata_tf_read,
399 .check_atapi_dma = ali_check_atapi_dma,
381 .check_status = ata_check_status, 400 .check_status = ata_check_status,
382 .exec_command = ata_exec_command, 401 .exec_command = ata_exec_command,
383 .dev_select = ata_std_dev_select, 402 .dev_select = ata_std_dev_select,
@@ -415,6 +434,7 @@ static struct ata_port_operations ali_c5_port_ops = {
415 .mode_filter = ata_pci_default_filter, 434 .mode_filter = ata_pci_default_filter,
416 .tf_load = ata_tf_load, 435 .tf_load = ata_tf_load,
417 .tf_read = ata_tf_read, 436 .tf_read = ata_tf_read,
437 .check_atapi_dma = ali_check_atapi_dma,
418 .check_status = ata_check_status, 438 .check_status = ata_check_status,
419 .exec_command = ata_exec_command, 439 .exec_command = ata_exec_command,
420 .dev_select = ata_std_dev_select, 440 .dev_select = ata_std_dev_select,
diff --git a/drivers/ata/pata_amd.c b/drivers/ata/pata_amd.c
index c5779ad4abca..3cc27b514654 100644
--- a/drivers/ata/pata_amd.c
+++ b/drivers/ata/pata_amd.c
@@ -25,7 +25,7 @@
25#include <linux/libata.h> 25#include <linux/libata.h>
26 26
27#define DRV_NAME "pata_amd" 27#define DRV_NAME "pata_amd"
28#define DRV_VERSION "0.3.9" 28#define DRV_VERSION "0.3.10"
29 29
30/** 30/**
31 * timing_setup - shared timing computation and load 31 * timing_setup - shared timing computation and load
@@ -115,7 +115,8 @@ static void timing_setup(struct ata_port *ap, struct ata_device *adev, int offse
115 } 115 }
116 116
117 /* UDMA timing */ 117 /* UDMA timing */
118 pci_write_config_byte(pdev, offset + 0x10 + (3 - dn), t); 118 if (at.udma)
119 pci_write_config_byte(pdev, offset + 0x10 + (3 - dn), t);
119} 120}
120 121
121/** 122/**
diff --git a/drivers/ata/pata_at32.c b/drivers/ata/pata_at32.c
index bb250a48e27c..67e574de31e8 100644
--- a/drivers/ata/pata_at32.c
+++ b/drivers/ata/pata_at32.c
@@ -28,7 +28,7 @@
28#include <asm/arch/smc.h> 28#include <asm/arch/smc.h>
29 29
30#define DRV_NAME "pata_at32" 30#define DRV_NAME "pata_at32"
31#define DRV_VERSION "0.0.2" 31#define DRV_VERSION "0.0.3"
32 32
33/* 33/*
34 * CompactFlash controller memory layout relative to the base address: 34 * CompactFlash controller memory layout relative to the base address:
@@ -64,6 +64,8 @@
64 * Mode 2 | 8.3 | 240 ns | 0x07 64 * Mode 2 | 8.3 | 240 ns | 0x07
65 * Mode 3 | 11.1 | 180 ns | 0x0f 65 * Mode 3 | 11.1 | 180 ns | 0x0f
66 * Mode 4 | 16.7 | 120 ns | 0x1f 66 * Mode 4 | 16.7 | 120 ns | 0x1f
67 *
68 * Alter PIO_MASK below according to table to set maximal PIO mode.
67 */ 69 */
68#define PIO_MASK (0x1f) 70#define PIO_MASK (0x1f)
69 71
@@ -85,36 +87,40 @@ struct at32_ide_info {
85 */ 87 */
86static int pata_at32_setup_timing(struct device *dev, 88static int pata_at32_setup_timing(struct device *dev,
87 struct at32_ide_info *info, 89 struct at32_ide_info *info,
88 const struct ata_timing *timing) 90 const struct ata_timing *ata)
89{ 91{
90 /* These two values are found through testing */
91 const int min_recover = 25;
92 const int ncs_hold = 15;
93
94 struct smc_config *smc = &info->smc; 92 struct smc_config *smc = &info->smc;
93 struct smc_timing timing;
95 94
96 int active; 95 int active;
97 int recover; 96 int recover;
98 97
98 memset(&timing, 0, sizeof(struct smc_timing));
99
99 /* Total cycle time */ 100 /* Total cycle time */
100 smc->read_cycle = timing->cyc8b; 101 timing.read_cycle = ata->cyc8b;
101 102
102 /* DIOR <= CFIOR timings */ 103 /* DIOR <= CFIOR timings */
103 smc->nrd_setup = timing->setup; 104 timing.nrd_setup = ata->setup;
104 smc->nrd_pulse = timing->act8b; 105 timing.nrd_pulse = ata->act8b;
106 timing.nrd_recover = ata->rec8b;
107
108 /* Convert nanosecond timing to clock cycles */
109 smc_set_timing(smc, &timing);
105 110
106 /* Compute recover, extend total cycle if needed */ 111 /* Add one extra cycle setup due to signal ring */
107 active = smc->nrd_setup + smc->nrd_pulse; 112 smc->nrd_setup = smc->nrd_setup + 1;
113
114 active = smc->nrd_setup + smc->nrd_pulse;
108 recover = smc->read_cycle - active; 115 recover = smc->read_cycle - active;
109 116
110 if (recover < min_recover) { 117 /* Need at least two cycles recovery */
111 smc->read_cycle = active + min_recover; 118 if (recover < 2)
112 recover = min_recover; 119 smc->read_cycle = active + 2;
113 }
114 120
115 /* (CS0, CS1, DIR, OE) <= (CFCE1, CFCE2, CFRNW, NCSX) timings */ 121 /* (CS0, CS1, DIR, OE) <= (CFCE1, CFCE2, CFRNW, NCSX) timings */
116 smc->ncs_read_setup = 0; 122 smc->ncs_read_setup = 1;
117 smc->ncs_read_pulse = active + ncs_hold; 123 smc->ncs_read_pulse = smc->read_cycle - 2;
118 124
119 /* Write timings same as read timings */ 125 /* Write timings same as read timings */
120 smc->write_cycle = smc->read_cycle; 126 smc->write_cycle = smc->read_cycle;
@@ -123,11 +129,13 @@ static int pata_at32_setup_timing(struct device *dev,
123 smc->ncs_write_setup = smc->ncs_read_setup; 129 smc->ncs_write_setup = smc->ncs_read_setup;
124 smc->ncs_write_pulse = smc->ncs_read_pulse; 130 smc->ncs_write_pulse = smc->ncs_read_pulse;
125 131
126 /* Do some debugging output */ 132 /* Do some debugging output of ATA and SMC timings */
127 dev_dbg(dev, "SMC: C=%d S=%d P=%d R=%d NCSS=%d NCSP=%d NCSR=%d\n", 133 dev_dbg(dev, "ATA: C=%d S=%d P=%d R=%d\n",
134 ata->cyc8b, ata->setup, ata->act8b, ata->rec8b);
135
136 dev_dbg(dev, "SMC: C=%d S=%d P=%d NS=%d NP=%d\n",
128 smc->read_cycle, smc->nrd_setup, smc->nrd_pulse, 137 smc->read_cycle, smc->nrd_setup, smc->nrd_pulse,
129 recover, smc->ncs_read_setup, smc->ncs_read_pulse, 138 smc->ncs_read_setup, smc->ncs_read_pulse);
130 smc->read_cycle - smc->ncs_read_pulse);
131 139
132 /* Finally, configure the SMC */ 140 /* Finally, configure the SMC */
133 return smc_set_configuration(info->cs, smc); 141 return smc_set_configuration(info->cs, smc);
@@ -182,7 +190,6 @@ static struct scsi_host_template at32_sht = {
182}; 190};
183 191
184static struct ata_port_operations at32_port_ops = { 192static struct ata_port_operations at32_port_ops = {
185 .port_disable = ata_port_disable,
186 .set_piomode = pata_at32_set_piomode, 193 .set_piomode = pata_at32_set_piomode,
187 .tf_load = ata_tf_load, 194 .tf_load = ata_tf_load,
188 .tf_read = ata_tf_read, 195 .tf_read = ata_tf_read,
@@ -203,7 +210,6 @@ static struct ata_port_operations at32_port_ops = {
203 210
204 .irq_clear = pata_at32_irq_clear, 211 .irq_clear = pata_at32_irq_clear,
205 .irq_on = ata_irq_on, 212 .irq_on = ata_irq_on,
206 .irq_ack = ata_irq_ack,
207 213
208 .port_start = ata_sff_port_start, 214 .port_start = ata_sff_port_start,
209}; 215};
@@ -223,8 +229,7 @@ static int __init pata_at32_init_one(struct device *dev,
223 /* Setup ATA bindings */ 229 /* Setup ATA bindings */
224 ap->ops = &at32_port_ops; 230 ap->ops = &at32_port_ops;
225 ap->pio_mask = PIO_MASK; 231 ap->pio_mask = PIO_MASK;
226 ap->flags = ATA_FLAG_MMIO | ATA_FLAG_SLAVE_POSS 232 ap->flags |= ATA_FLAG_MMIO | ATA_FLAG_SLAVE_POSS;
227 | ATA_FLAG_PIO_POLLING;
228 233
229 /* 234 /*
230 * Since all 8-bit taskfile transfers has to go on the lower 235 * Since all 8-bit taskfile transfers has to go on the lower
@@ -357,12 +362,12 @@ static int __init pata_at32_probe(struct platform_device *pdev)
357 info->smc.tdf_mode = 0; /* TDF optimization disabled */ 362 info->smc.tdf_mode = 0; /* TDF optimization disabled */
358 info->smc.tdf_cycles = 0; /* No TDF wait cycles */ 363 info->smc.tdf_cycles = 0; /* No TDF wait cycles */
359 364
360 /* Setup ATA timing */ 365 /* Setup SMC to ATA timing */
361 ret = pata_at32_setup_timing(dev, info, &initial_timing); 366 ret = pata_at32_setup_timing(dev, info, &initial_timing);
362 if (ret) 367 if (ret)
363 goto err_setup_timing; 368 goto err_setup_timing;
364 369
365 /* Setup ATA addresses */ 370 /* Map ATA address space */
366 ret = -ENOMEM; 371 ret = -ENOMEM;
367 info->ide_addr = devm_ioremap(dev, info->res_ide.start, 16); 372 info->ide_addr = devm_ioremap(dev, info->res_ide.start, 16);
368 info->alt_addr = devm_ioremap(dev, info->res_alt.start, 16); 373 info->alt_addr = devm_ioremap(dev, info->res_alt.start, 16);
@@ -373,7 +378,7 @@ static int __init pata_at32_probe(struct platform_device *pdev)
373 pata_at32_debug_bus(dev, info); 378 pata_at32_debug_bus(dev, info);
374#endif 379#endif
375 380
376 /* Register ATA device */ 381 /* Setup and register ATA device */
377 ret = pata_at32_init_one(dev, info); 382 ret = pata_at32_init_one(dev, info);
378 if (ret) 383 if (ret)
379 goto err_ata_device; 384 goto err_ata_device;
diff --git a/drivers/ata/pata_bf54x.c b/drivers/ata/pata_bf54x.c
index b5e38426b815..088a41f4e656 100644
--- a/drivers/ata/pata_bf54x.c
+++ b/drivers/ata/pata_bf54x.c
@@ -1145,13 +1145,13 @@ static unsigned char bfin_bmdma_status(struct ata_port *ap)
1145 unsigned short int_status = ATAPI_GET_INT_STATUS(base); 1145 unsigned short int_status = ATAPI_GET_INT_STATUS(base);
1146 1146
1147 if (ATAPI_GET_STATUS(base) & (MULTI_XFER_ON|ULTRA_XFER_ON)) { 1147 if (ATAPI_GET_STATUS(base) & (MULTI_XFER_ON|ULTRA_XFER_ON)) {
1148 host_stat = ATA_DMA_ACTIVE; 1148 host_stat |= ATA_DMA_ACTIVE;
1149 } 1149 }
1150 if (int_status & (MULTI_DONE_INT|UDMAIN_DONE_INT|UDMAOUT_DONE_INT)) { 1150 if (int_status & (MULTI_DONE_INT|UDMAIN_DONE_INT|UDMAOUT_DONE_INT)) {
1151 host_stat = ATA_DMA_INTR; 1151 host_stat |= ATA_DMA_INTR;
1152 } 1152 }
1153 if (int_status & (MULTI_TERM_INT|UDMAIN_TERM_INT|UDMAOUT_TERM_INT)) { 1153 if (int_status & (MULTI_TERM_INT|UDMAIN_TERM_INT|UDMAOUT_TERM_INT)) {
1154 host_stat = ATA_DMA_ERR; 1154 host_stat |= ATA_DMA_ERR;
1155 } 1155 }
1156 1156
1157 return host_stat; 1157 return host_stat;
@@ -1489,6 +1489,8 @@ static int __devinit bfin_atapi_probe(struct platform_device *pdev)
1489 int board_idx = 0; 1489 int board_idx = 0;
1490 struct resource *res; 1490 struct resource *res;
1491 struct ata_host *host; 1491 struct ata_host *host;
1492 unsigned int fsclk = get_sclk();
1493 int udma_mode = 5;
1492 const struct ata_port_info *ppi[] = 1494 const struct ata_port_info *ppi[] =
1493 { &bfin_port_info[board_idx], NULL }; 1495 { &bfin_port_info[board_idx], NULL };
1494 1496
@@ -1507,6 +1509,11 @@ static int __devinit bfin_atapi_probe(struct platform_device *pdev)
1507 if (res == NULL) 1509 if (res == NULL)
1508 return -EINVAL; 1510 return -EINVAL;
1509 1511
1512 while (bfin_port_info[board_idx].udma_mask>0 && udma_fsclk[udma_mode] > fsclk) {
1513 udma_mode--;
1514 bfin_port_info[board_idx].udma_mask >>= 1;
1515 }
1516
1510 /* 1517 /*
1511 * Now that that's out of the way, wire up the port.. 1518 * Now that that's out of the way, wire up the port..
1512 */ 1519 */
diff --git a/drivers/ata/pata_hpt37x.c b/drivers/ata/pata_hpt37x.c
index 3816b8605e0d..c79f066c2bc9 100644
--- a/drivers/ata/pata_hpt37x.c
+++ b/drivers/ata/pata_hpt37x.c
@@ -329,7 +329,7 @@ static int hpt37x_pre_reset(struct ata_link *link, unsigned long deadline)
329 /* Restore state */ 329 /* Restore state */
330 pci_write_config_byte(pdev, 0x5B, scr2); 330 pci_write_config_byte(pdev, 0x5B, scr2);
331 331
332 if (ata66 & (1 << ap->port_no)) 332 if (ata66 & (2 >> ap->port_no))
333 ap->cbl = ATA_CBL_PATA40; 333 ap->cbl = ATA_CBL_PATA40;
334 else 334 else
335 ap->cbl = ATA_CBL_PATA80; 335 ap->cbl = ATA_CBL_PATA80;
@@ -375,7 +375,7 @@ static int hpt374_pre_reset(struct ata_link *link, unsigned long deadline)
375 pci_write_config_word(pdev, mcrbase + 2, mcr3 | 0x8000); 375 pci_write_config_word(pdev, mcrbase + 2, mcr3 | 0x8000);
376 pci_read_config_byte(pdev, 0x5A, &ata66); 376 pci_read_config_byte(pdev, 0x5A, &ata66);
377 /* Reset TCBLID/FCBLID to output */ 377 /* Reset TCBLID/FCBLID to output */
378 pci_write_config_word(pdev, 0x52, mcr3); 378 pci_write_config_word(pdev, mcrbase + 2, mcr3);
379 379
380 if (ata66 & (2 >> ap->port_no)) 380 if (ata66 & (2 >> ap->port_no))
381 ap->cbl = ATA_CBL_PATA40; 381 ap->cbl = ATA_CBL_PATA40;
diff --git a/drivers/ata/pata_isapnp.c b/drivers/ata/pata_isapnp.c
index 88ab0e1d353f..4320e7986321 100644
--- a/drivers/ata/pata_isapnp.c
+++ b/drivers/ata/pata_isapnp.c
@@ -75,13 +75,16 @@ static int isapnp_init_one(struct pnp_dev *idev, const struct pnp_device_id *dev
75 struct ata_host *host; 75 struct ata_host *host;
76 struct ata_port *ap; 76 struct ata_port *ap;
77 void __iomem *cmd_addr, *ctl_addr; 77 void __iomem *cmd_addr, *ctl_addr;
78 int irq = 0;
79 irq_handler_t handler = NULL;
78 80
79 if (pnp_port_valid(idev, 0) == 0) 81 if (pnp_port_valid(idev, 0) == 0)
80 return -ENODEV; 82 return -ENODEV;
81 83
82 /* FIXME: Should selected polled PIO here not fail */ 84 if (pnp_irq_valid(idev, 0)) {
83 if (pnp_irq_valid(idev, 0) == 0) 85 irq = pnp_irq(idev, 0);
84 return -ENODEV; 86 handler = ata_interrupt;
87 }
85 88
86 /* allocate host */ 89 /* allocate host */
87 host = ata_host_alloc(&idev->dev, 1); 90 host = ata_host_alloc(&idev->dev, 1);
@@ -115,7 +118,7 @@ static int isapnp_init_one(struct pnp_dev *idev, const struct pnp_device_id *dev
115 (unsigned long long)pnp_port_start(idev, 1)); 118 (unsigned long long)pnp_port_start(idev, 1));
116 119
117 /* activate */ 120 /* activate */
118 return ata_host_activate(host, pnp_irq(idev, 0), ata_interrupt, 0, 121 return ata_host_activate(host, irq, handler, 0,
119 &isapnp_sht); 122 &isapnp_sht);
120} 123}
121 124
diff --git a/drivers/ata/pata_jmicron.c b/drivers/ata/pata_jmicron.c
index 225a7223a726..5b8174d94067 100644
--- a/drivers/ata/pata_jmicron.c
+++ b/drivers/ata/pata_jmicron.c
@@ -80,11 +80,10 @@ static int jmicron_pre_reset(struct ata_link *link, unsigned long deadline)
80 * actually do our cable checking etc. Thankfully we don't need 80 * actually do our cable checking etc. Thankfully we don't need
81 * to do the plumbing for other cases. 81 * to do the plumbing for other cases.
82 */ 82 */
83 switch (port_map[port]) 83 switch (port_map[port]) {
84 {
85 case PORT_PATA0: 84 case PORT_PATA0:
86 if (control & (1 << 5)) 85 if ((control & (1 << 5)) == 0)
87 return 0; 86 return -ENOENT;
88 if (control & (1 << 3)) /* 40/80 pin primary */ 87 if (control & (1 << 3)) /* 40/80 pin primary */
89 ap->cbl = ATA_CBL_PATA40; 88 ap->cbl = ATA_CBL_PATA40;
90 else 89 else
@@ -93,7 +92,7 @@ static int jmicron_pre_reset(struct ata_link *link, unsigned long deadline)
93 case PORT_PATA1: 92 case PORT_PATA1:
94 /* Bit 21 is set if the port is enabled */ 93 /* Bit 21 is set if the port is enabled */
95 if ((control5 & (1 << 21)) == 0) 94 if ((control5 & (1 << 21)) == 0)
96 return 0; 95 return -ENOENT;
97 if (control5 & (1 << 19)) /* 40/80 pin secondary */ 96 if (control5 & (1 << 19)) /* 40/80 pin secondary */
98 ap->cbl = ATA_CBL_PATA40; 97 ap->cbl = ATA_CBL_PATA40;
99 else 98 else
diff --git a/drivers/ata/pata_sil680.c b/drivers/ata/pata_sil680.c
index 5c1e9cb59ecb..503245a1eafa 100644
--- a/drivers/ata/pata_sil680.c
+++ b/drivers/ata/pata_sil680.c
@@ -33,7 +33,7 @@
33#include <linux/libata.h> 33#include <linux/libata.h>
34 34
35#define DRV_NAME "pata_sil680" 35#define DRV_NAME "pata_sil680"
36#define DRV_VERSION "0.4.7" 36#define DRV_VERSION "0.4.8"
37 37
38#define SIL680_MMIO_BAR 5 38#define SIL680_MMIO_BAR 5
39 39
@@ -94,34 +94,6 @@ static int sil680_cable_detect(struct ata_port *ap) {
94} 94}
95 95
96/** 96/**
97 * sil680_bus_reset - reset the SIL680 bus
98 * @link: ATA link to reset
99 * @deadline: deadline jiffies for the operation
100 *
101 * Perform the SIL680 housekeeping when doing an ATA bus reset
102 */
103
104static int sil680_bus_reset(struct ata_link *link, unsigned int *classes,
105 unsigned long deadline)
106{
107 struct ata_port *ap = link->ap;
108 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
109 unsigned long addr = sil680_selreg(ap, 0);
110 u8 reset;
111
112 pci_read_config_byte(pdev, addr, &reset);
113 pci_write_config_byte(pdev, addr, reset | 0x03);
114 udelay(25);
115 pci_write_config_byte(pdev, addr, reset);
116 return ata_std_softreset(link, classes, deadline);
117}
118
119static void sil680_error_handler(struct ata_port *ap)
120{
121 ata_bmdma_drive_eh(ap, ata_std_prereset, sil680_bus_reset, NULL, ata_std_postreset);
122}
123
124/**
125 * sil680_set_piomode - set initial PIO mode data 97 * sil680_set_piomode - set initial PIO mode data
126 * @ap: ATA interface 98 * @ap: ATA interface
127 * @adev: ATA device 99 * @adev: ATA device
@@ -249,7 +221,7 @@ static struct ata_port_operations sil680_port_ops = {
249 221
250 .freeze = ata_bmdma_freeze, 222 .freeze = ata_bmdma_freeze,
251 .thaw = ata_bmdma_thaw, 223 .thaw = ata_bmdma_thaw,
252 .error_handler = sil680_error_handler, 224 .error_handler = ata_bmdma_error_handler,
253 .post_internal_cmd = ata_bmdma_post_internal_cmd, 225 .post_internal_cmd = ata_bmdma_post_internal_cmd,
254 .cable_detect = sil680_cable_detect, 226 .cable_detect = sil680_cable_detect,
255 227
diff --git a/drivers/ata/pata_sis.c b/drivers/ata/pata_sis.c
index 3b5be77e861c..87546d9f1ca0 100644
--- a/drivers/ata/pata_sis.c
+++ b/drivers/ata/pata_sis.c
@@ -55,6 +55,7 @@ static const struct sis_laptop sis_laptop[] = {
55 /* devid, subvendor, subdev */ 55 /* devid, subvendor, subdev */
56 { 0x5513, 0x1043, 0x1107 }, /* ASUS A6K */ 56 { 0x5513, 0x1043, 0x1107 }, /* ASUS A6K */
57 { 0x5513, 0x1734, 0x105F }, /* FSC Amilo A1630 */ 57 { 0x5513, 0x1734, 0x105F }, /* FSC Amilo A1630 */
58 { 0x5513, 0x1071, 0x8640 }, /* EasyNote K5305 */
58 /* end marker */ 59 /* end marker */
59 { 0, } 60 { 0, }
60}; 61};
diff --git a/drivers/ata/pata_via.c b/drivers/ata/pata_via.c
index a4175fbdd170..453d72bf2598 100644
--- a/drivers/ata/pata_via.c
+++ b/drivers/ata/pata_via.c
@@ -63,7 +63,7 @@
63#include <linux/dmi.h> 63#include <linux/dmi.h>
64 64
65#define DRV_NAME "pata_via" 65#define DRV_NAME "pata_via"
66#define DRV_VERSION "0.3.2" 66#define DRV_VERSION "0.3.3"
67 67
68/* 68/*
69 * The following comes directly from Vojtech Pavlik's ide/pci/via82cxxx 69 * The following comes directly from Vojtech Pavlik's ide/pci/via82cxxx
@@ -296,7 +296,7 @@ static void via_do_set_mode(struct ata_port *ap, struct ata_device *adev, int mo
296 } 296 }
297 297
298 /* Set UDMA unless device is not UDMA capable */ 298 /* Set UDMA unless device is not UDMA capable */
299 if (udma_type) { 299 if (udma_type && t.udma) {
300 u8 cable80_status; 300 u8 cable80_status;
301 301
302 /* Get 80-wire cable detection bit */ 302 /* Get 80-wire cable detection bit */
diff --git a/drivers/ata/sata_mv.c b/drivers/ata/sata_mv.c
index a43f64d2775b..37b850ae0845 100644
--- a/drivers/ata/sata_mv.c
+++ b/drivers/ata/sata_mv.c
@@ -164,10 +164,14 @@ enum {
164 MV_PCI_ERR_ATTRIBUTE = 0x1d48, 164 MV_PCI_ERR_ATTRIBUTE = 0x1d48,
165 MV_PCI_ERR_COMMAND = 0x1d50, 165 MV_PCI_ERR_COMMAND = 0x1d50,
166 166
167 PCI_IRQ_CAUSE_OFS = 0x1d58, 167 PCI_IRQ_CAUSE_OFS = 0x1d58,
168 PCI_IRQ_MASK_OFS = 0x1d5c, 168 PCI_IRQ_MASK_OFS = 0x1d5c,
169 PCI_UNMASK_ALL_IRQS = 0x7fffff, /* bits 22-0 */ 169 PCI_UNMASK_ALL_IRQS = 0x7fffff, /* bits 22-0 */
170 170
171 PCIE_IRQ_CAUSE_OFS = 0x1900,
172 PCIE_IRQ_MASK_OFS = 0x1910,
173 PCIE_UNMASK_ALL_IRQS = 0x70a, /* assorted bits */
174
171 HC_MAIN_IRQ_CAUSE_OFS = 0x1d60, 175 HC_MAIN_IRQ_CAUSE_OFS = 0x1d60,
172 HC_MAIN_IRQ_MASK_OFS = 0x1d64, 176 HC_MAIN_IRQ_MASK_OFS = 0x1d64,
173 PORT0_ERR = (1 << 0), /* shift by port # */ 177 PORT0_ERR = (1 << 0), /* shift by port # */
@@ -303,6 +307,7 @@ enum {
303 MV_HP_GEN_I = (1 << 6), /* Generation I: 50xx */ 307 MV_HP_GEN_I = (1 << 6), /* Generation I: 50xx */
304 MV_HP_GEN_II = (1 << 7), /* Generation II: 60xx */ 308 MV_HP_GEN_II = (1 << 7), /* Generation II: 60xx */
305 MV_HP_GEN_IIE = (1 << 8), /* Generation IIE: 6042/7042 */ 309 MV_HP_GEN_IIE = (1 << 8), /* Generation IIE: 6042/7042 */
310 MV_HP_PCIE = (1 << 9), /* PCIe bus/regs: 7042 */
306 311
307 /* Port private flags (pp_flags) */ 312 /* Port private flags (pp_flags) */
308 MV_PP_FLAG_EDMA_EN = (1 << 0), /* is EDMA engine enabled? */ 313 MV_PP_FLAG_EDMA_EN = (1 << 0), /* is EDMA engine enabled? */
@@ -388,7 +393,15 @@ struct mv_port_signal {
388 u32 pre; 393 u32 pre;
389}; 394};
390 395
391struct mv_host_priv; 396struct mv_host_priv {
397 u32 hp_flags;
398 struct mv_port_signal signal[8];
399 const struct mv_hw_ops *ops;
400 u32 irq_cause_ofs;
401 u32 irq_mask_ofs;
402 u32 unmask_all_irqs;
403};
404
392struct mv_hw_ops { 405struct mv_hw_ops {
393 void (*phy_errata)(struct mv_host_priv *hpriv, void __iomem *mmio, 406 void (*phy_errata)(struct mv_host_priv *hpriv, void __iomem *mmio,
394 unsigned int port); 407 unsigned int port);
@@ -401,12 +414,6 @@ struct mv_hw_ops {
401 void (*reset_bus)(struct pci_dev *pdev, void __iomem *mmio); 414 void (*reset_bus)(struct pci_dev *pdev, void __iomem *mmio);
402}; 415};
403 416
404struct mv_host_priv {
405 u32 hp_flags;
406 struct mv_port_signal signal[8];
407 const struct mv_hw_ops *ops;
408};
409
410static void mv_irq_clear(struct ata_port *ap); 417static void mv_irq_clear(struct ata_port *ap);
411static int mv_scr_read(struct ata_port *ap, unsigned int sc_reg_in, u32 *val); 418static int mv_scr_read(struct ata_port *ap, unsigned int sc_reg_in, u32 *val);
412static int mv_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val); 419static int mv_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val);
@@ -631,11 +638,13 @@ static const struct pci_device_id mv_pci_tbl[] = {
631 /* Adaptec 1430SA */ 638 /* Adaptec 1430SA */
632 { PCI_VDEVICE(ADAPTEC2, 0x0243), chip_7042 }, 639 { PCI_VDEVICE(ADAPTEC2, 0x0243), chip_7042 },
633 640
634 { PCI_VDEVICE(TTI, 0x2310), chip_7042 }, 641 /* Marvell 7042 support */
635
636 /* add Marvell 7042 support */
637 { PCI_VDEVICE(MARVELL, 0x7042), chip_7042 }, 642 { PCI_VDEVICE(MARVELL, 0x7042), chip_7042 },
638 643
644 /* Highpoint RocketRAID PCIe series */
645 { PCI_VDEVICE(TTI, 0x2300), chip_7042 },
646 { PCI_VDEVICE(TTI, 0x2310), chip_7042 },
647
639 { } /* terminate list */ 648 { } /* terminate list */
640}; 649};
641 650
@@ -1648,13 +1657,14 @@ static void mv_host_intr(struct ata_host *host, u32 relevant, unsigned int hc)
1648 1657
1649static void mv_pci_error(struct ata_host *host, void __iomem *mmio) 1658static void mv_pci_error(struct ata_host *host, void __iomem *mmio)
1650{ 1659{
1660 struct mv_host_priv *hpriv = host->private_data;
1651 struct ata_port *ap; 1661 struct ata_port *ap;
1652 struct ata_queued_cmd *qc; 1662 struct ata_queued_cmd *qc;
1653 struct ata_eh_info *ehi; 1663 struct ata_eh_info *ehi;
1654 unsigned int i, err_mask, printed = 0; 1664 unsigned int i, err_mask, printed = 0;
1655 u32 err_cause; 1665 u32 err_cause;
1656 1666
1657 err_cause = readl(mmio + PCI_IRQ_CAUSE_OFS); 1667 err_cause = readl(mmio + hpriv->irq_cause_ofs);
1658 1668
1659 dev_printk(KERN_ERR, host->dev, "PCI ERROR; PCI IRQ cause=0x%08x\n", 1669 dev_printk(KERN_ERR, host->dev, "PCI ERROR; PCI IRQ cause=0x%08x\n",
1660 err_cause); 1670 err_cause);
@@ -1662,7 +1672,7 @@ static void mv_pci_error(struct ata_host *host, void __iomem *mmio)
1662 DPRINTK("All regs @ PCI error\n"); 1672 DPRINTK("All regs @ PCI error\n");
1663 mv_dump_all_regs(mmio, -1, to_pci_dev(host->dev)); 1673 mv_dump_all_regs(mmio, -1, to_pci_dev(host->dev));
1664 1674
1665 writelfl(0, mmio + PCI_IRQ_CAUSE_OFS); 1675 writelfl(0, mmio + hpriv->irq_cause_ofs);
1666 1676
1667 for (i = 0; i < host->n_ports; i++) { 1677 for (i = 0; i < host->n_ports; i++) {
1668 ap = host->ports[i]; 1678 ap = host->ports[i];
@@ -1926,6 +1936,8 @@ static int mv5_reset_hc(struct mv_host_priv *hpriv, void __iomem *mmio,
1926#define ZERO(reg) writel(0, mmio + (reg)) 1936#define ZERO(reg) writel(0, mmio + (reg))
1927static void mv_reset_pci_bus(struct pci_dev *pdev, void __iomem *mmio) 1937static void mv_reset_pci_bus(struct pci_dev *pdev, void __iomem *mmio)
1928{ 1938{
1939 struct ata_host *host = dev_get_drvdata(&pdev->dev);
1940 struct mv_host_priv *hpriv = host->private_data;
1929 u32 tmp; 1941 u32 tmp;
1930 1942
1931 tmp = readl(mmio + MV_PCI_MODE); 1943 tmp = readl(mmio + MV_PCI_MODE);
@@ -1937,8 +1949,8 @@ static void mv_reset_pci_bus(struct pci_dev *pdev, void __iomem *mmio)
1937 writel(0x000100ff, mmio + MV_PCI_XBAR_TMOUT); 1949 writel(0x000100ff, mmio + MV_PCI_XBAR_TMOUT);
1938 ZERO(HC_MAIN_IRQ_MASK_OFS); 1950 ZERO(HC_MAIN_IRQ_MASK_OFS);
1939 ZERO(MV_PCI_SERR_MASK); 1951 ZERO(MV_PCI_SERR_MASK);
1940 ZERO(PCI_IRQ_CAUSE_OFS); 1952 ZERO(hpriv->irq_cause_ofs);
1941 ZERO(PCI_IRQ_MASK_OFS); 1953 ZERO(hpriv->irq_mask_ofs);
1942 ZERO(MV_PCI_ERR_LOW_ADDRESS); 1954 ZERO(MV_PCI_ERR_LOW_ADDRESS);
1943 ZERO(MV_PCI_ERR_HIGH_ADDRESS); 1955 ZERO(MV_PCI_ERR_HIGH_ADDRESS);
1944 ZERO(MV_PCI_ERR_ATTRIBUTE); 1956 ZERO(MV_PCI_ERR_ATTRIBUTE);
@@ -2170,7 +2182,7 @@ static void mv_phy_reset(struct ata_port *ap, unsigned int *class,
2170 mv_scr_read(ap, SCR_ERROR, &serror); 2182 mv_scr_read(ap, SCR_ERROR, &serror);
2171 mv_scr_read(ap, SCR_CONTROL, &scontrol); 2183 mv_scr_read(ap, SCR_CONTROL, &scontrol);
2172 DPRINTK("S-regs after ATA_RST: SStat 0x%08x SErr 0x%08x " 2184 DPRINTK("S-regs after ATA_RST: SStat 0x%08x SErr 0x%08x "
2173 "SCtrl 0x%08x\n", status, serror, scontrol); 2185 "SCtrl 0x%08x\n", sstatus, serror, scontrol);
2174 } 2186 }
2175#endif 2187#endif
2176 2188
@@ -2490,6 +2502,36 @@ static int mv_chip_id(struct ata_host *host, unsigned int board_idx)
2490 break; 2502 break;
2491 2503
2492 case chip_7042: 2504 case chip_7042:
2505 hp_flags |= MV_HP_PCIE;
2506 if (pdev->vendor == PCI_VENDOR_ID_TTI &&
2507 (pdev->device == 0x2300 || pdev->device == 0x2310))
2508 {
2509 /*
2510 * Highpoint RocketRAID PCIe 23xx series cards:
2511 *
2512 * Unconfigured drives are treated as "Legacy"
2513 * by the BIOS, and it overwrites sector 8 with
2514 * a "Lgcy" metadata block prior to Linux boot.
2515 *
2516 * Configured drives (RAID or JBOD) leave sector 8
2517 * alone, but instead overwrite a high numbered
2518 * sector for the RAID metadata. This sector can
2519 * be determined exactly, by truncating the physical
2520 * drive capacity to a nice even GB value.
2521 *
2522 * RAID metadata is at: (dev->n_sectors & ~0xfffff)
2523 *
2524 * Warn the user, lest they think we're just buggy.
2525 */
2526 printk(KERN_WARNING DRV_NAME ": Highpoint RocketRAID"
2527 " BIOS CORRUPTS DATA on all attached drives,"
2528 " regardless of if/how they are configured."
2529 " BEWARE!\n");
2530 printk(KERN_WARNING DRV_NAME ": For data safety, do not"
2531 " use sectors 8-9 on \"Legacy\" drives,"
2532 " and avoid the final two gigabytes on"
2533 " all RocketRAID BIOS initialized drives.\n");
2534 }
2493 case chip_6042: 2535 case chip_6042:
2494 hpriv->ops = &mv6xxx_ops; 2536 hpriv->ops = &mv6xxx_ops;
2495 hp_flags |= MV_HP_GEN_IIE; 2537 hp_flags |= MV_HP_GEN_IIE;
@@ -2516,6 +2558,15 @@ static int mv_chip_id(struct ata_host *host, unsigned int board_idx)
2516 } 2558 }
2517 2559
2518 hpriv->hp_flags = hp_flags; 2560 hpriv->hp_flags = hp_flags;
2561 if (hp_flags & MV_HP_PCIE) {
2562 hpriv->irq_cause_ofs = PCIE_IRQ_CAUSE_OFS;
2563 hpriv->irq_mask_ofs = PCIE_IRQ_MASK_OFS;
2564 hpriv->unmask_all_irqs = PCIE_UNMASK_ALL_IRQS;
2565 } else {
2566 hpriv->irq_cause_ofs = PCI_IRQ_CAUSE_OFS;
2567 hpriv->irq_mask_ofs = PCI_IRQ_MASK_OFS;
2568 hpriv->unmask_all_irqs = PCI_UNMASK_ALL_IRQS;
2569 }
2519 2570
2520 return 0; 2571 return 0;
2521} 2572}
@@ -2595,10 +2646,10 @@ static int mv_init_host(struct ata_host *host, unsigned int board_idx)
2595 } 2646 }
2596 2647
2597 /* Clear any currently outstanding host interrupt conditions */ 2648 /* Clear any currently outstanding host interrupt conditions */
2598 writelfl(0, mmio + PCI_IRQ_CAUSE_OFS); 2649 writelfl(0, mmio + hpriv->irq_cause_ofs);
2599 2650
2600 /* and unmask interrupt generation for host regs */ 2651 /* and unmask interrupt generation for host regs */
2601 writelfl(PCI_UNMASK_ALL_IRQS, mmio + PCI_IRQ_MASK_OFS); 2652 writelfl(hpriv->unmask_all_irqs, mmio + hpriv->irq_mask_ofs);
2602 2653
2603 if (IS_GEN_I(hpriv)) 2654 if (IS_GEN_I(hpriv))
2604 writelfl(~HC_MAIN_MASKED_IRQS_5, mmio + HC_MAIN_IRQ_MASK_OFS); 2655 writelfl(~HC_MAIN_MASKED_IRQS_5, mmio + HC_MAIN_IRQ_MASK_OFS);
@@ -2609,8 +2660,8 @@ static int mv_init_host(struct ata_host *host, unsigned int board_idx)
2609 "PCI int cause/mask=0x%08x/0x%08x\n", 2660 "PCI int cause/mask=0x%08x/0x%08x\n",
2610 readl(mmio + HC_MAIN_IRQ_CAUSE_OFS), 2661 readl(mmio + HC_MAIN_IRQ_CAUSE_OFS),
2611 readl(mmio + HC_MAIN_IRQ_MASK_OFS), 2662 readl(mmio + HC_MAIN_IRQ_MASK_OFS),
2612 readl(mmio + PCI_IRQ_CAUSE_OFS), 2663 readl(mmio + hpriv->irq_cause_ofs),
2613 readl(mmio + PCI_IRQ_MASK_OFS)); 2664 readl(mmio + hpriv->irq_mask_ofs));
2614 2665
2615done: 2666done:
2616 return rc; 2667 return rc;
diff --git a/drivers/ata/sata_nv.c b/drivers/ata/sata_nv.c
index 44f9e5d9e362..ed5dc7cb50cd 100644
--- a/drivers/ata/sata_nv.c
+++ b/drivers/ata/sata_nv.c
@@ -791,11 +791,13 @@ static int nv_adma_check_atapi_dma(struct ata_queued_cmd *qc)
791 791
792static void nv_adma_tf_read(struct ata_port *ap, struct ata_taskfile *tf) 792static void nv_adma_tf_read(struct ata_port *ap, struct ata_taskfile *tf)
793{ 793{
794 /* Since commands where a result TF is requested are not 794 /* Other than when internal or pass-through commands are executed,
795 executed in ADMA mode, the only time this function will be called 795 the only time this function will be called in ADMA mode will be
796 in ADMA mode will be if a command fails. In this case we 796 if a command fails. In the failure case we don't care about going
797 don't care about going into register mode with ADMA commands 797 into register mode with ADMA commands pending, as the commands will
798 pending, as the commands will all shortly be aborted anyway. */ 798 all shortly be aborted anyway. We assume that NCQ commands are not
799 issued via passthrough, which is the only way that switching into
800 ADMA mode could abort outstanding commands. */
799 nv_adma_register_mode(ap); 801 nv_adma_register_mode(ap);
800 802
801 ata_tf_read(ap, tf); 803 ata_tf_read(ap, tf);
@@ -1359,11 +1361,9 @@ static int nv_adma_use_reg_mode(struct ata_queued_cmd *qc)
1359 struct nv_adma_port_priv *pp = qc->ap->private_data; 1361 struct nv_adma_port_priv *pp = qc->ap->private_data;
1360 1362
1361 /* ADMA engine can only be used for non-ATAPI DMA commands, 1363 /* ADMA engine can only be used for non-ATAPI DMA commands,
1362 or interrupt-driven no-data commands, where a result taskfile 1364 or interrupt-driven no-data commands. */
1363 is not required. */
1364 if ((pp->flags & NV_ADMA_ATAPI_SETUP_COMPLETE) || 1365 if ((pp->flags & NV_ADMA_ATAPI_SETUP_COMPLETE) ||
1365 (qc->tf.flags & ATA_TFLAG_POLLING) || 1366 (qc->tf.flags & ATA_TFLAG_POLLING))
1366 (qc->flags & ATA_QCFLAG_RESULT_TF))
1367 return 1; 1367 return 1;
1368 1368
1369 if ((qc->flags & ATA_QCFLAG_DMAMAP) || 1369 if ((qc->flags & ATA_QCFLAG_DMAMAP) ||
@@ -1381,6 +1381,8 @@ static void nv_adma_qc_prep(struct ata_queued_cmd *qc)
1381 NV_CPB_CTL_IEN; 1381 NV_CPB_CTL_IEN;
1382 1382
1383 if (nv_adma_use_reg_mode(qc)) { 1383 if (nv_adma_use_reg_mode(qc)) {
1384 BUG_ON(!(pp->flags & NV_ADMA_ATAPI_SETUP_COMPLETE) &&
1385 (qc->flags & ATA_QCFLAG_DMAMAP));
1384 nv_adma_register_mode(qc->ap); 1386 nv_adma_register_mode(qc->ap);
1385 ata_qc_prep(qc); 1387 ata_qc_prep(qc);
1386 return; 1388 return;
@@ -1425,9 +1427,21 @@ static unsigned int nv_adma_qc_issue(struct ata_queued_cmd *qc)
1425 1427
1426 VPRINTK("ENTER\n"); 1428 VPRINTK("ENTER\n");
1427 1429
1430 /* We can't handle result taskfile with NCQ commands, since
1431 retrieving the taskfile switches us out of ADMA mode and would abort
1432 existing commands. */
1433 if (unlikely(qc->tf.protocol == ATA_PROT_NCQ &&
1434 (qc->flags & ATA_QCFLAG_RESULT_TF))) {
1435 ata_dev_printk(qc->dev, KERN_ERR,
1436 "NCQ w/ RESULT_TF not allowed\n");
1437 return AC_ERR_SYSTEM;
1438 }
1439
1428 if (nv_adma_use_reg_mode(qc)) { 1440 if (nv_adma_use_reg_mode(qc)) {
1429 /* use ATA register mode */ 1441 /* use ATA register mode */
1430 VPRINTK("using ATA register mode: 0x%lx\n", qc->flags); 1442 VPRINTK("using ATA register mode: 0x%lx\n", qc->flags);
1443 BUG_ON(!(pp->flags & NV_ADMA_ATAPI_SETUP_COMPLETE) &&
1444 (qc->flags & ATA_QCFLAG_DMAMAP));
1431 nv_adma_register_mode(qc->ap); 1445 nv_adma_register_mode(qc->ap);
1432 return ata_qc_issue_prot(qc); 1446 return ata_qc_issue_prot(qc);
1433 } else 1447 } else
diff --git a/drivers/ata/sata_sil.c b/drivers/ata/sata_sil.c
index 4e6e381279cc..f5119bf40c24 100644
--- a/drivers/ata/sata_sil.c
+++ b/drivers/ata/sata_sil.c
@@ -390,23 +390,19 @@ static void sil_host_intr(struct ata_port *ap, u32 bmdma2)
390 sil_scr_read(ap, SCR_ERROR, &serror); 390 sil_scr_read(ap, SCR_ERROR, &serror);
391 sil_scr_write(ap, SCR_ERROR, serror); 391 sil_scr_write(ap, SCR_ERROR, serror);
392 392
393 /* Trigger hotplug and accumulate SError only if the 393 /* Sometimes spurious interrupts occur, double check
394 * port isn't already frozen. Otherwise, PHY events 394 * it's PHYRDY CHG.
395 * during hardreset makes controllers with broken SIEN
396 * repeat probing needlessly.
397 */ 395 */
398 if (!(ap->pflags & ATA_PFLAG_FROZEN)) { 396 if (serror & SERR_PHYRDY_CHG) {
399 ata_ehi_hotplugged(&ap->link.eh_info);
400 ap->link.eh_info.serror |= serror; 397 ap->link.eh_info.serror |= serror;
398 goto freeze;
401 } 399 }
402 400
403 goto freeze; 401 if (!(bmdma2 & SIL_DMA_COMPLETE))
402 return;
404 } 403 }
405 404
406 if (unlikely(!qc)) 405 if (unlikely(!qc || (qc->tf.flags & ATA_TFLAG_POLLING))) {
407 goto freeze;
408
409 if (unlikely(qc->tf.flags & ATA_TFLAG_POLLING)) {
410 /* this sometimes happens, just clear IRQ */ 406 /* this sometimes happens, just clear IRQ */
411 ata_chk_status(ap); 407 ata_chk_status(ap);
412 return; 408 return;
diff --git a/drivers/ata/sata_sil24.c b/drivers/ata/sata_sil24.c
index 187dcb02c681..96fd5260446d 100644
--- a/drivers/ata/sata_sil24.c
+++ b/drivers/ata/sata_sil24.c
@@ -63,6 +63,21 @@ enum {
63 SIL24_HOST_BAR = 0, 63 SIL24_HOST_BAR = 0,
64 SIL24_PORT_BAR = 2, 64 SIL24_PORT_BAR = 2,
65 65
66 /* sil24 fetches in chunks of 64bytes. The first block
67 * contains the PRB and two SGEs. From the second block, it's
68 * consisted of four SGEs and called SGT. Calculate the
69 * number of SGTs that fit into one page.
70 */
71 SIL24_PRB_SZ = sizeof(struct sil24_prb)
72 + 2 * sizeof(struct sil24_sge),
73 SIL24_MAX_SGT = (PAGE_SIZE - SIL24_PRB_SZ)
74 / (4 * sizeof(struct sil24_sge)),
75
76 /* This will give us one unused SGEs for ATA. This extra SGE
77 * will be used to store CDB for ATAPI devices.
78 */
79 SIL24_MAX_SGE = 4 * SIL24_MAX_SGT + 1,
80
66 /* 81 /*
67 * Global controller registers (128 bytes @ BAR0) 82 * Global controller registers (128 bytes @ BAR0)
68 */ 83 */
@@ -247,13 +262,13 @@ enum {
247 262
248struct sil24_ata_block { 263struct sil24_ata_block {
249 struct sil24_prb prb; 264 struct sil24_prb prb;
250 struct sil24_sge sge[LIBATA_MAX_PRD]; 265 struct sil24_sge sge[SIL24_MAX_SGE];
251}; 266};
252 267
253struct sil24_atapi_block { 268struct sil24_atapi_block {
254 struct sil24_prb prb; 269 struct sil24_prb prb;
255 u8 cdb[16]; 270 u8 cdb[16];
256 struct sil24_sge sge[LIBATA_MAX_PRD - 1]; 271 struct sil24_sge sge[SIL24_MAX_SGE];
257}; 272};
258 273
259union sil24_cmd_block { 274union sil24_cmd_block {
@@ -378,7 +393,7 @@ static struct scsi_host_template sil24_sht = {
378 .change_queue_depth = ata_scsi_change_queue_depth, 393 .change_queue_depth = ata_scsi_change_queue_depth,
379 .can_queue = SIL24_MAX_CMDS, 394 .can_queue = SIL24_MAX_CMDS,
380 .this_id = ATA_SHT_THIS_ID, 395 .this_id = ATA_SHT_THIS_ID,
381 .sg_tablesize = LIBATA_MAX_PRD, 396 .sg_tablesize = SIL24_MAX_SGE,
382 .cmd_per_lun = ATA_SHT_CMD_PER_LUN, 397 .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
383 .emulated = ATA_SHT_EMULATED, 398 .emulated = ATA_SHT_EMULATED,
384 .use_clustering = ATA_SHT_USE_CLUSTERING, 399 .use_clustering = ATA_SHT_USE_CLUSTERING,
@@ -1284,6 +1299,7 @@ static void sil24_init_controller(struct ata_host *host)
1284 1299
1285static int sil24_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) 1300static int sil24_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
1286{ 1301{
1302 extern int __MARKER__sil24_cmd_block_is_sized_wrongly;
1287 static int printed_version; 1303 static int printed_version;
1288 struct ata_port_info pi = sil24_port_info[ent->driver_data]; 1304 struct ata_port_info pi = sil24_port_info[ent->driver_data];
1289 const struct ata_port_info *ppi[] = { &pi, NULL }; 1305 const struct ata_port_info *ppi[] = { &pi, NULL };
@@ -1292,6 +1308,10 @@ static int sil24_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
1292 int i, rc; 1308 int i, rc;
1293 u32 tmp; 1309 u32 tmp;
1294 1310
1311 /* cause link error if sil24_cmd_block is sized wrongly */
1312 if (sizeof(union sil24_cmd_block) != PAGE_SIZE)
1313 __MARKER__sil24_cmd_block_is_sized_wrongly = 1;
1314
1295 if (!printed_version++) 1315 if (!printed_version++)
1296 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n"); 1316 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
1297 1317
diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
index f8f7139c07c1..c662d686154a 100644
--- a/drivers/atm/firestream.c
+++ b/drivers/atm/firestream.c
@@ -171,8 +171,8 @@ static char *res_strings[] = {
171 "packet purged", 171 "packet purged",
172 "packet ageing timeout", 172 "packet ageing timeout",
173 "channel ageing timeout", 173 "channel ageing timeout",
174 "calculated lenght error", 174 "calculated length error",
175 "programmed lenght limit error", 175 "programmed length limit error",
176 "aal5 crc32 error", 176 "aal5 crc32 error",
177 "oam transp or transpc crc10 error", 177 "oam transp or transpc crc10 error",
178 "reserved 25", 178 "reserved 25",
diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
index 8b12925fe7a4..f97e050338f0 100644
--- a/drivers/atm/fore200e.c
+++ b/drivers/atm/fore200e.c
@@ -2689,7 +2689,7 @@ fore200e_init(struct fore200e* fore200e)
2689 return 0; 2689 return 0;
2690} 2690}
2691 2691
2692 2692#ifdef CONFIG_ATM_FORE200E_PCA
2693static int __devinit 2693static int __devinit
2694fore200e_pca_detect(struct pci_dev *pci_dev, const struct pci_device_id *pci_ent) 2694fore200e_pca_detect(struct pci_dev *pci_dev, const struct pci_device_id *pci_ent)
2695{ 2695{
@@ -2756,7 +2756,6 @@ static void __devexit fore200e_pca_remove_one(struct pci_dev *pci_dev)
2756} 2756}
2757 2757
2758 2758
2759#ifdef CONFIG_ATM_FORE200E_PCA
2760static struct pci_device_id fore200e_pca_tbl[] = { 2759static struct pci_device_id fore200e_pca_tbl[] = {
2761 { PCI_VENDOR_ID_FORE, PCI_DEVICE_ID_FORE_PCA200E, PCI_ANY_ID, PCI_ANY_ID, 2760 { PCI_VENDOR_ID_FORE, PCI_DEVICE_ID_FORE_PCA200E, PCI_ANY_ID, PCI_ANY_ID,
2762 0, 0, (unsigned long) &fore200e_bus[0] }, 2761 0, 0, (unsigned long) &fore200e_bus[0] },
diff --git a/drivers/atm/he.c b/drivers/atm/he.c
index d33aba6864c2..3b64a99772ea 100644
--- a/drivers/atm/he.c
+++ b/drivers/atm/he.c
@@ -394,6 +394,11 @@ he_init_one(struct pci_dev *pci_dev, const struct pci_device_id *pci_ent)
394 he_dev->atm_dev->dev_data = he_dev; 394 he_dev->atm_dev->dev_data = he_dev;
395 atm_dev->dev_data = he_dev; 395 atm_dev->dev_data = he_dev;
396 he_dev->number = atm_dev->number; 396 he_dev->number = atm_dev->number;
397#ifdef USE_TASKLET
398 tasklet_init(&he_dev->tasklet, he_tasklet, (unsigned long) he_dev);
399#endif
400 spin_lock_init(&he_dev->global_lock);
401
397 if (he_start(atm_dev)) { 402 if (he_start(atm_dev)) {
398 he_stop(he_dev); 403 he_stop(he_dev);
399 err = -ENODEV; 404 err = -ENODEV;
@@ -1173,11 +1178,6 @@ he_start(struct atm_dev *dev)
1173 if ((err = he_init_irq(he_dev)) != 0) 1178 if ((err = he_init_irq(he_dev)) != 0)
1174 return err; 1179 return err;
1175 1180
1176#ifdef USE_TASKLET
1177 tasklet_init(&he_dev->tasklet, he_tasklet, (unsigned long) he_dev);
1178#endif
1179 spin_lock_init(&he_dev->global_lock);
1180
1181 /* 4.11 enable pci bus controller state machines */ 1181 /* 4.11 enable pci bus controller state machines */
1182 host_cntl |= (OUTFF_ENB | CMDFF_ENB | 1182 host_cntl |= (OUTFF_ENB | CMDFF_ENB |
1183 QUICK_RD_RETRY | QUICK_WR_RETRY | PERR_INT_ENB); 1183 QUICK_RD_RETRY | QUICK_WR_RETRY | PERR_INT_ENB);
diff --git a/drivers/base/core.c b/drivers/base/core.c
index 3f4d6aa13990..2683eac30c68 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -770,9 +770,10 @@ int device_add(struct device *dev)
770 error = device_add_attrs(dev); 770 error = device_add_attrs(dev);
771 if (error) 771 if (error)
772 goto AttrsError; 772 goto AttrsError;
773 error = device_pm_add(dev); 773 error = dpm_sysfs_add(dev);
774 if (error) 774 if (error)
775 goto PMError; 775 goto PMError;
776 device_pm_add(dev);
776 error = bus_add_device(dev); 777 error = bus_add_device(dev);
777 if (error) 778 if (error)
778 goto BusError; 779 goto BusError;
@@ -797,6 +798,7 @@ int device_add(struct device *dev)
797 return error; 798 return error;
798 BusError: 799 BusError:
799 device_pm_remove(dev); 800 device_pm_remove(dev);
801 dpm_sysfs_remove(dev);
800 PMError: 802 PMError:
801 if (dev->bus) 803 if (dev->bus)
802 blocking_notifier_call_chain(&dev->bus->bus_notifier, 804 blocking_notifier_call_chain(&dev->bus->bus_notifier,
diff --git a/drivers/base/power/Makefile b/drivers/base/power/Makefile
index a803733c839e..44504e6618fb 100644
--- a/drivers/base/power/Makefile
+++ b/drivers/base/power/Makefile
@@ -1,5 +1,6 @@
1obj-y := shutdown.o 1obj-y := shutdown.o
2obj-$(CONFIG_PM_SLEEP) += main.o sysfs.o 2obj-$(CONFIG_PM) += sysfs.o
3obj-$(CONFIG_PM_SLEEP) += main.o
3obj-$(CONFIG_PM_TRACE) += trace.o 4obj-$(CONFIG_PM_TRACE) += trace.o
4 5
5ifeq ($(CONFIG_DEBUG_DRIVER),y) 6ifeq ($(CONFIG_DEBUG_DRIVER),y)
diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
index 0ab4ab21f564..691ffb64cc37 100644
--- a/drivers/base/power/main.c
+++ b/drivers/base/power/main.c
@@ -38,20 +38,14 @@ static DEFINE_MUTEX(dpm_list_mtx);
38int (*platform_enable_wakeup)(struct device *dev, int is_on); 38int (*platform_enable_wakeup)(struct device *dev, int is_on);
39 39
40 40
41int device_pm_add(struct device *dev) 41void device_pm_add(struct device *dev)
42{ 42{
43 int error;
44
45 pr_debug("PM: Adding info for %s:%s\n", 43 pr_debug("PM: Adding info for %s:%s\n",
46 dev->bus ? dev->bus->name : "No Bus", 44 dev->bus ? dev->bus->name : "No Bus",
47 kobject_name(&dev->kobj)); 45 kobject_name(&dev->kobj));
48 mutex_lock(&dpm_list_mtx); 46 mutex_lock(&dpm_list_mtx);
49 list_add_tail(&dev->power.entry, &dpm_active); 47 list_add_tail(&dev->power.entry, &dpm_active);
50 error = dpm_sysfs_add(dev);
51 if (error)
52 list_del(&dev->power.entry);
53 mutex_unlock(&dpm_list_mtx); 48 mutex_unlock(&dpm_list_mtx);
54 return error;
55} 49}
56 50
57void device_pm_remove(struct device *dev) 51void device_pm_remove(struct device *dev)
diff --git a/drivers/base/power/power.h b/drivers/base/power/power.h
index 5c4efd493fa5..379da4e958e0 100644
--- a/drivers/base/power/power.h
+++ b/drivers/base/power/power.h
@@ -13,14 +13,29 @@ extern void device_shutdown(void);
13 13
14extern struct list_head dpm_active; /* The active device list */ 14extern struct list_head dpm_active; /* The active device list */
15 15
16static inline struct device * to_device(struct list_head * entry) 16static inline struct device *to_device(struct list_head *entry)
17{ 17{
18 return container_of(entry, struct device, power.entry); 18 return container_of(entry, struct device, power.entry);
19} 19}
20 20
21extern int device_pm_add(struct device *); 21extern void device_pm_add(struct device *);
22extern void device_pm_remove(struct device *); 22extern void device_pm_remove(struct device *);
23 23
24#else /* CONFIG_PM_SLEEP */
25
26
27static inline void device_pm_add(struct device *dev)
28{
29}
30
31static inline void device_pm_remove(struct device *dev)
32{
33}
34
35#endif
36
37#ifdef CONFIG_PM
38
24/* 39/*
25 * sysfs.c 40 * sysfs.c
26 */ 41 */
@@ -28,16 +43,15 @@ extern void device_pm_remove(struct device *);
28extern int dpm_sysfs_add(struct device *); 43extern int dpm_sysfs_add(struct device *);
29extern void dpm_sysfs_remove(struct device *); 44extern void dpm_sysfs_remove(struct device *);
30 45
31#else /* CONFIG_PM_SLEEP */ 46#else /* CONFIG_PM */
32
33 47
34static inline int device_pm_add(struct device * dev) 48static inline int dpm_sysfs_add(struct device *dev)
35{ 49{
36 return 0; 50 return 0;
37} 51}
38static inline void device_pm_remove(struct device * dev)
39{
40 52
53static inline void dpm_sysfs_remove(struct device *dev)
54{
41} 55}
42 56
43#endif 57#endif
diff --git a/drivers/block/aoe/aoeblk.c b/drivers/block/aoe/aoeblk.c
index b1d00ef6659c..ad00b3d94711 100644
--- a/drivers/block/aoe/aoeblk.c
+++ b/drivers/block/aoe/aoeblk.c
@@ -6,6 +6,7 @@
6 6
7#include <linux/hdreg.h> 7#include <linux/hdreg.h>
8#include <linux/blkdev.h> 8#include <linux/blkdev.h>
9#include <linux/backing-dev.h>
9#include <linux/fs.h> 10#include <linux/fs.h>
10#include <linux/ioctl.h> 11#include <linux/ioctl.h>
11#include <linux/genhd.h> 12#include <linux/genhd.h>
@@ -210,25 +211,20 @@ aoeblk_gdalloc(void *vp)
210 if (gd == NULL) { 211 if (gd == NULL) {
211 printk(KERN_ERR "aoe: cannot allocate disk structure for %ld.%ld\n", 212 printk(KERN_ERR "aoe: cannot allocate disk structure for %ld.%ld\n",
212 d->aoemajor, d->aoeminor); 213 d->aoemajor, d->aoeminor);
213 spin_lock_irqsave(&d->lock, flags); 214 goto err;
214 d->flags &= ~DEVFL_GDALLOC;
215 spin_unlock_irqrestore(&d->lock, flags);
216 return;
217 } 215 }
218 216
219 d->bufpool = mempool_create_slab_pool(MIN_BUFS, buf_pool_cache); 217 d->bufpool = mempool_create_slab_pool(MIN_BUFS, buf_pool_cache);
220 if (d->bufpool == NULL) { 218 if (d->bufpool == NULL) {
221 printk(KERN_ERR "aoe: cannot allocate bufpool for %ld.%ld\n", 219 printk(KERN_ERR "aoe: cannot allocate bufpool for %ld.%ld\n",
222 d->aoemajor, d->aoeminor); 220 d->aoemajor, d->aoeminor);
223 put_disk(gd); 221 goto err_disk;
224 spin_lock_irqsave(&d->lock, flags);
225 d->flags &= ~DEVFL_GDALLOC;
226 spin_unlock_irqrestore(&d->lock, flags);
227 return;
228 } 222 }
229 223
230 spin_lock_irqsave(&d->lock, flags);
231 blk_queue_make_request(&d->blkq, aoeblk_make_request); 224 blk_queue_make_request(&d->blkq, aoeblk_make_request);
225 if (bdi_init(&d->blkq.backing_dev_info))
226 goto err_mempool;
227 spin_lock_irqsave(&d->lock, flags);
232 gd->major = AOE_MAJOR; 228 gd->major = AOE_MAJOR;
233 gd->first_minor = d->sysminor * AOE_PARTITIONS; 229 gd->first_minor = d->sysminor * AOE_PARTITIONS;
234 gd->fops = &aoe_bdops; 230 gd->fops = &aoe_bdops;
@@ -246,6 +242,16 @@ aoeblk_gdalloc(void *vp)
246 242
247 add_disk(gd); 243 add_disk(gd);
248 aoedisk_add_sysfs(d); 244 aoedisk_add_sysfs(d);
245 return;
246
247err_mempool:
248 mempool_destroy(d->bufpool);
249err_disk:
250 put_disk(gd);
251err:
252 spin_lock_irqsave(&d->lock, flags);
253 d->flags &= ~DEVFL_GDALLOC;
254 spin_unlock_irqrestore(&d->lock, flags);
249} 255}
250 256
251void 257void
diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
index a5ee21319d37..3535ef896677 100644
--- a/drivers/block/pktcdvd.c
+++ b/drivers/block/pktcdvd.c
@@ -117,8 +117,10 @@ static struct pktcdvd_kobj* pkt_kobj_create(struct pktcdvd_device *pd,
117 p->kobj.parent = parent; 117 p->kobj.parent = parent;
118 p->kobj.ktype = ktype; 118 p->kobj.ktype = ktype;
119 p->pd = pd; 119 p->pd = pd;
120 if (kobject_register(&p->kobj) != 0) 120 if (kobject_register(&p->kobj) != 0) {
121 kobject_put(&p->kobj);
121 return NULL; 122 return NULL;
123 }
122 return p; 124 return p;
123} 125}
124/* 126/*
diff --git a/drivers/block/umem.c b/drivers/block/umem.c
index 99806f9ee4ce..c24e1bdbad43 100644
--- a/drivers/block/umem.c
+++ b/drivers/block/umem.c
@@ -34,7 +34,7 @@
34 * - set initialised bit then. 34 * - set initialised bit then.
35 */ 35 */
36 36
37//#define DEBUG /* uncomment if you want debugging info (pr_debug) */ 37#undef DEBUG /* #define DEBUG if you want debugging info (pr_debug) */
38#include <linux/fs.h> 38#include <linux/fs.h>
39#include <linux/bio.h> 39#include <linux/bio.h>
40#include <linux/kernel.h> 40#include <linux/kernel.h>
@@ -143,17 +143,12 @@ static struct cardinfo cards[MM_MAXCARDS];
143static struct block_device_operations mm_fops; 143static struct block_device_operations mm_fops;
144static struct timer_list battery_timer; 144static struct timer_list battery_timer;
145 145
146static int num_cards = 0; 146static int num_cards;
147 147
148static struct gendisk *mm_gendisk[MM_MAXCARDS]; 148static struct gendisk *mm_gendisk[MM_MAXCARDS];
149 149
150static void check_batteries(struct cardinfo *card); 150static void check_batteries(struct cardinfo *card);
151 151
152/*
153-----------------------------------------------------------------------------------
154-- get_userbit
155-----------------------------------------------------------------------------------
156*/
157static int get_userbit(struct cardinfo *card, int bit) 152static int get_userbit(struct cardinfo *card, int bit)
158{ 153{
159 unsigned char led; 154 unsigned char led;
@@ -161,11 +156,7 @@ static int get_userbit(struct cardinfo *card, int bit)
161 led = readb(card->csr_remap + MEMCTRLCMD_LEDCTRL); 156 led = readb(card->csr_remap + MEMCTRLCMD_LEDCTRL);
162 return led & bit; 157 return led & bit;
163} 158}
164/* 159
165-----------------------------------------------------------------------------------
166-- set_userbit
167-----------------------------------------------------------------------------------
168*/
169static int set_userbit(struct cardinfo *card, int bit, unsigned char state) 160static int set_userbit(struct cardinfo *card, int bit, unsigned char state)
170{ 161{
171 unsigned char led; 162 unsigned char led;
@@ -179,11 +170,7 @@ static int set_userbit(struct cardinfo *card, int bit, unsigned char state)
179 170
180 return 0; 171 return 0;
181} 172}
182/* 173
183-----------------------------------------------------------------------------------
184-- set_led
185-----------------------------------------------------------------------------------
186*/
187/* 174/*
188 * NOTE: For the power LED, use the LED_POWER_* macros since they differ 175 * NOTE: For the power LED, use the LED_POWER_* macros since they differ
189 */ 176 */
@@ -203,11 +190,6 @@ static void set_led(struct cardinfo *card, int shift, unsigned char state)
203} 190}
204 191
205#ifdef MM_DIAG 192#ifdef MM_DIAG
206/*
207-----------------------------------------------------------------------------------
208-- dump_regs
209-----------------------------------------------------------------------------------
210*/
211static void dump_regs(struct cardinfo *card) 193static void dump_regs(struct cardinfo *card)
212{ 194{
213 unsigned char *p; 195 unsigned char *p;
@@ -224,32 +206,28 @@ static void dump_regs(struct cardinfo *card)
224 } 206 }
225} 207}
226#endif 208#endif
227/* 209
228-----------------------------------------------------------------------------------
229-- dump_dmastat
230-----------------------------------------------------------------------------------
231*/
232static void dump_dmastat(struct cardinfo *card, unsigned int dmastat) 210static void dump_dmastat(struct cardinfo *card, unsigned int dmastat)
233{ 211{
234 dev_printk(KERN_DEBUG, &card->dev->dev, "DMAstat - "); 212 dev_printk(KERN_DEBUG, &card->dev->dev, "DMAstat - ");
235 if (dmastat & DMASCR_ANY_ERR) 213 if (dmastat & DMASCR_ANY_ERR)
236 printk("ANY_ERR "); 214 printk(KERN_CONT "ANY_ERR ");
237 if (dmastat & DMASCR_MBE_ERR) 215 if (dmastat & DMASCR_MBE_ERR)
238 printk("MBE_ERR "); 216 printk(KERN_CONT "MBE_ERR ");
239 if (dmastat & DMASCR_PARITY_ERR_REP) 217 if (dmastat & DMASCR_PARITY_ERR_REP)
240 printk("PARITY_ERR_REP "); 218 printk(KERN_CONT "PARITY_ERR_REP ");
241 if (dmastat & DMASCR_PARITY_ERR_DET) 219 if (dmastat & DMASCR_PARITY_ERR_DET)
242 printk("PARITY_ERR_DET "); 220 printk(KERN_CONT "PARITY_ERR_DET ");
243 if (dmastat & DMASCR_SYSTEM_ERR_SIG) 221 if (dmastat & DMASCR_SYSTEM_ERR_SIG)
244 printk("SYSTEM_ERR_SIG "); 222 printk(KERN_CONT "SYSTEM_ERR_SIG ");
245 if (dmastat & DMASCR_TARGET_ABT) 223 if (dmastat & DMASCR_TARGET_ABT)
246 printk("TARGET_ABT "); 224 printk(KERN_CONT "TARGET_ABT ");
247 if (dmastat & DMASCR_MASTER_ABT) 225 if (dmastat & DMASCR_MASTER_ABT)
248 printk("MASTER_ABT "); 226 printk(KERN_CONT "MASTER_ABT ");
249 if (dmastat & DMASCR_CHAIN_COMPLETE) 227 if (dmastat & DMASCR_CHAIN_COMPLETE)
250 printk("CHAIN_COMPLETE "); 228 printk(KERN_CONT "CHAIN_COMPLETE ");
251 if (dmastat & DMASCR_DMA_COMPLETE) 229 if (dmastat & DMASCR_DMA_COMPLETE)
252 printk("DMA_COMPLETE "); 230 printk(KERN_CONT "DMA_COMPLETE ");
253 printk("\n"); 231 printk("\n");
254} 232}
255 233
@@ -286,7 +264,8 @@ static void mm_start_io(struct cardinfo *card)
286 264
287 /* make the last descriptor end the chain */ 265 /* make the last descriptor end the chain */
288 page = &card->mm_pages[card->Active]; 266 page = &card->mm_pages[card->Active];
289 pr_debug("start_io: %d %d->%d\n", card->Active, page->headcnt, page->cnt-1); 267 pr_debug("start_io: %d %d->%d\n",
268 card->Active, page->headcnt, page->cnt - 1);
290 desc = &page->desc[page->cnt-1]; 269 desc = &page->desc[page->cnt-1];
291 270
292 desc->control_bits |= cpu_to_le32(DMASCR_CHAIN_COMP_EN); 271 desc->control_bits |= cpu_to_le32(DMASCR_CHAIN_COMP_EN);
@@ -310,8 +289,8 @@ static void mm_start_io(struct cardinfo *card)
310 writel(0, card->csr_remap + DMA_SEMAPHORE_ADDR); 289 writel(0, card->csr_remap + DMA_SEMAPHORE_ADDR);
311 writel(0, card->csr_remap + DMA_SEMAPHORE_ADDR + 4); 290 writel(0, card->csr_remap + DMA_SEMAPHORE_ADDR + 4);
312 291
313 offset = ((char*)desc) - ((char*)page->desc); 292 offset = ((char *)desc) - ((char *)page->desc);
314 writel(cpu_to_le32((page->page_dma+offset)&0xffffffff), 293 writel(cpu_to_le32((page->page_dma+offset) & 0xffffffff),
315 card->csr_remap + DMA_DESCRIPTOR_ADDR); 294 card->csr_remap + DMA_DESCRIPTOR_ADDR);
316 /* Force the value to u64 before shifting otherwise >> 32 is undefined C 295 /* Force the value to u64 before shifting otherwise >> 32 is undefined C
317 * and on some ports will do nothing ! */ 296 * and on some ports will do nothing ! */
@@ -352,7 +331,7 @@ static inline void reset_page(struct mm_page *page)
352 page->cnt = 0; 331 page->cnt = 0;
353 page->headcnt = 0; 332 page->headcnt = 0;
354 page->bio = NULL; 333 page->bio = NULL;
355 page->biotail = & page->bio; 334 page->biotail = &page->bio;
356} 335}
357 336
358static void mm_unplug_device(struct request_queue *q) 337static void mm_unplug_device(struct request_queue *q)
@@ -408,7 +387,7 @@ static int add_bio(struct cardinfo *card)
408 vec->bv_page, 387 vec->bv_page,
409 vec->bv_offset, 388 vec->bv_offset,
410 len, 389 len,
411 (rw==READ) ? 390 (rw == READ) ?
412 PCI_DMA_FROMDEVICE : PCI_DMA_TODEVICE); 391 PCI_DMA_FROMDEVICE : PCI_DMA_TODEVICE);
413 392
414 p = &card->mm_pages[card->Ready]; 393 p = &card->mm_pages[card->Ready];
@@ -427,10 +406,10 @@ static int add_bio(struct cardinfo *card)
427 desc->pci_addr = cpu_to_le64((u64)desc->data_dma_handle); 406 desc->pci_addr = cpu_to_le64((u64)desc->data_dma_handle);
428 desc->local_addr = cpu_to_le64(card->current_sector << 9); 407 desc->local_addr = cpu_to_le64(card->current_sector << 9);
429 desc->transfer_size = cpu_to_le32(len); 408 desc->transfer_size = cpu_to_le32(len);
430 offset = ( ((char*)&desc->sem_control_bits) - ((char*)p->desc)); 409 offset = (((char *)&desc->sem_control_bits) - ((char *)p->desc));
431 desc->sem_addr = cpu_to_le64((u64)(p->page_dma+offset)); 410 desc->sem_addr = cpu_to_le64((u64)(p->page_dma+offset));
432 desc->zero1 = desc->zero2 = 0; 411 desc->zero1 = desc->zero2 = 0;
433 offset = ( ((char*)(desc+1)) - ((char*)p->desc)); 412 offset = (((char *)(desc+1)) - ((char *)p->desc));
434 desc->next_desc_addr = cpu_to_le64(p->page_dma+offset); 413 desc->next_desc_addr = cpu_to_le64(p->page_dma+offset);
435 desc->control_bits = cpu_to_le32(DMASCR_GO|DMASCR_ERR_INT_EN| 414 desc->control_bits = cpu_to_le32(DMASCR_GO|DMASCR_ERR_INT_EN|
436 DMASCR_PARITY_INT_EN| 415 DMASCR_PARITY_INT_EN|
@@ -455,11 +434,11 @@ static void process_page(unsigned long data)
455 /* check if any of the requests in the page are DMA_COMPLETE, 434 /* check if any of the requests in the page are DMA_COMPLETE,
456 * and deal with them appropriately. 435 * and deal with them appropriately.
457 * If we find a descriptor without DMA_COMPLETE in the semaphore, then 436 * If we find a descriptor without DMA_COMPLETE in the semaphore, then
458 * dma must have hit an error on that descriptor, so use dma_status instead 437 * dma must have hit an error on that descriptor, so use dma_status
459 * and assume that all following descriptors must be re-tried. 438 * instead and assume that all following descriptors must be re-tried.
460 */ 439 */
461 struct mm_page *page; 440 struct mm_page *page;
462 struct bio *return_bio=NULL; 441 struct bio *return_bio = NULL;
463 struct cardinfo *card = (struct cardinfo *)data; 442 struct cardinfo *card = (struct cardinfo *)data;
464 unsigned int dma_status = card->dma_status; 443 unsigned int dma_status = card->dma_status;
465 444
@@ -472,24 +451,25 @@ static void process_page(unsigned long data)
472 struct bio *bio = page->bio; 451 struct bio *bio = page->bio;
473 struct mm_dma_desc *desc = &page->desc[page->headcnt]; 452 struct mm_dma_desc *desc = &page->desc[page->headcnt];
474 int control = le32_to_cpu(desc->sem_control_bits); 453 int control = le32_to_cpu(desc->sem_control_bits);
475 int last=0; 454 int last = 0;
476 int idx; 455 int idx;
477 456
478 if (!(control & DMASCR_DMA_COMPLETE)) { 457 if (!(control & DMASCR_DMA_COMPLETE)) {
479 control = dma_status; 458 control = dma_status;
480 last=1; 459 last = 1;
481 } 460 }
482 page->headcnt++; 461 page->headcnt++;
483 idx = page->idx; 462 idx = page->idx;
484 page->idx++; 463 page->idx++;
485 if (page->idx >= bio->bi_vcnt) { 464 if (page->idx >= bio->bi_vcnt) {
486 page->bio = bio->bi_next; 465 page->bio = bio->bi_next;
487 page->idx = page->bio->bi_idx; 466 if (page->bio)
467 page->idx = page->bio->bi_idx;
488 } 468 }
489 469
490 pci_unmap_page(card->dev, desc->data_dma_handle, 470 pci_unmap_page(card->dev, desc->data_dma_handle,
491 bio_iovec_idx(bio,idx)->bv_len, 471 bio_iovec_idx(bio, idx)->bv_len,
492 (control& DMASCR_TRANSFER_READ) ? 472 (control & DMASCR_TRANSFER_READ) ?
493 PCI_DMA_TODEVICE : PCI_DMA_FROMDEVICE); 473 PCI_DMA_TODEVICE : PCI_DMA_FROMDEVICE);
494 if (control & DMASCR_HARD_ERROR) { 474 if (control & DMASCR_HARD_ERROR) {
495 /* error */ 475 /* error */
@@ -500,9 +480,10 @@ static void process_page(unsigned long data)
500 le32_to_cpu(desc->transfer_size)); 480 le32_to_cpu(desc->transfer_size));
501 dump_dmastat(card, control); 481 dump_dmastat(card, control);
502 } else if (test_bit(BIO_RW, &bio->bi_rw) && 482 } else if (test_bit(BIO_RW, &bio->bi_rw) &&
503 le32_to_cpu(desc->local_addr)>>9 == card->init_size) { 483 le32_to_cpu(desc->local_addr) >> 9 ==
504 card->init_size += le32_to_cpu(desc->transfer_size)>>9; 484 card->init_size) {
505 if (card->init_size>>1 >= card->mm_size) { 485 card->init_size += le32_to_cpu(desc->transfer_size) >> 9;
486 if (card->init_size >> 1 >= card->mm_size) {
506 dev_printk(KERN_INFO, &card->dev->dev, 487 dev_printk(KERN_INFO, &card->dev->dev,
507 "memory now initialised\n"); 488 "memory now initialised\n");
508 set_userbit(card, MEMORY_INITIALIZED, 1); 489 set_userbit(card, MEMORY_INITIALIZED, 1);
@@ -513,7 +494,8 @@ static void process_page(unsigned long data)
513 return_bio = bio; 494 return_bio = bio;
514 } 495 }
515 496
516 if (last) break; 497 if (last)
498 break;
517 } 499 }
518 500
519 if (debug & DEBUG_LED_ON_TRANSFER) 501 if (debug & DEBUG_LED_ON_TRANSFER)
@@ -535,7 +517,7 @@ static void process_page(unsigned long data)
535 out_unlock: 517 out_unlock:
536 spin_unlock_bh(&card->lock); 518 spin_unlock_bh(&card->lock);
537 519
538 while(return_bio) { 520 while (return_bio) {
539 struct bio *bio = return_bio; 521 struct bio *bio = return_bio;
540 522
541 return_bio = bio->bi_next; 523 return_bio = bio->bi_next;
@@ -544,11 +526,6 @@ static void process_page(unsigned long data)
544 } 526 }
545} 527}
546 528
547/*
548-----------------------------------------------------------------------------------
549-- mm_make_request
550-----------------------------------------------------------------------------------
551*/
552static int mm_make_request(struct request_queue *q, struct bio *bio) 529static int mm_make_request(struct request_queue *q, struct bio *bio)
553{ 530{
554 struct cardinfo *card = q->queuedata; 531 struct cardinfo *card = q->queuedata;
@@ -565,11 +542,6 @@ static int mm_make_request(struct request_queue *q, struct bio *bio)
565 return 0; 542 return 0;
566} 543}
567 544
568/*
569-----------------------------------------------------------------------------------
570-- mm_interrupt
571-----------------------------------------------------------------------------------
572*/
573static irqreturn_t mm_interrupt(int irq, void *__card) 545static irqreturn_t mm_interrupt(int irq, void *__card)
574{ 546{
575 struct cardinfo *card = (struct cardinfo *) __card; 547 struct cardinfo *card = (struct cardinfo *) __card;
@@ -583,15 +555,15 @@ HW_TRACE(0x30);
583 if (!(dma_status & (DMASCR_ERROR_MASK | DMASCR_CHAIN_COMPLETE))) { 555 if (!(dma_status & (DMASCR_ERROR_MASK | DMASCR_CHAIN_COMPLETE))) {
584 /* interrupt wasn't for me ... */ 556 /* interrupt wasn't for me ... */
585 return IRQ_NONE; 557 return IRQ_NONE;
586 } 558 }
587 559
588 /* clear COMPLETION interrupts */ 560 /* clear COMPLETION interrupts */
589 if (card->flags & UM_FLAG_NO_BYTE_STATUS) 561 if (card->flags & UM_FLAG_NO_BYTE_STATUS)
590 writel(cpu_to_le32(DMASCR_DMA_COMPLETE|DMASCR_CHAIN_COMPLETE), 562 writel(cpu_to_le32(DMASCR_DMA_COMPLETE|DMASCR_CHAIN_COMPLETE),
591 card->csr_remap+ DMA_STATUS_CTRL); 563 card->csr_remap + DMA_STATUS_CTRL);
592 else 564 else
593 writeb((DMASCR_DMA_COMPLETE|DMASCR_CHAIN_COMPLETE) >> 16, 565 writeb((DMASCR_DMA_COMPLETE|DMASCR_CHAIN_COMPLETE) >> 16,
594 card->csr_remap+ DMA_STATUS_CTRL + 2); 566 card->csr_remap + DMA_STATUS_CTRL + 2);
595 567
596 /* log errors and clear interrupt status */ 568 /* log errors and clear interrupt status */
597 if (dma_status & DMASCR_ANY_ERR) { 569 if (dma_status & DMASCR_ANY_ERR) {
@@ -601,9 +573,12 @@ HW_TRACE(0x30);
601 573
602 stat = readb(card->csr_remap + MEMCTRLCMD_ERRSTATUS); 574 stat = readb(card->csr_remap + MEMCTRLCMD_ERRSTATUS);
603 575
604 data_log1 = le32_to_cpu(readl(card->csr_remap + ERROR_DATA_LOG)); 576 data_log1 = le32_to_cpu(readl(card->csr_remap +
605 data_log2 = le32_to_cpu(readl(card->csr_remap + ERROR_DATA_LOG + 4)); 577 ERROR_DATA_LOG));
606 addr_log1 = le32_to_cpu(readl(card->csr_remap + ERROR_ADDR_LOG)); 578 data_log2 = le32_to_cpu(readl(card->csr_remap +
579 ERROR_DATA_LOG + 4));
580 addr_log1 = le32_to_cpu(readl(card->csr_remap +
581 ERROR_ADDR_LOG));
607 addr_log2 = readb(card->csr_remap + ERROR_ADDR_LOG + 4); 582 addr_log2 = readb(card->csr_remap + ERROR_ADDR_LOG + 4);
608 583
609 count = readb(card->csr_remap + ERROR_COUNT); 584 count = readb(card->csr_remap + ERROR_COUNT);
@@ -670,11 +645,7 @@ HW_TRACE(0x36);
670 645
671 return IRQ_HANDLED; 646 return IRQ_HANDLED;
672} 647}
673/* 648
674-----------------------------------------------------------------------------------
675-- set_fault_to_battery_status
676-----------------------------------------------------------------------------------
677*/
678/* 649/*
679 * If both batteries are good, no LED 650 * If both batteries are good, no LED
680 * If either battery has been warned, solid LED 651 * If either battery has been warned, solid LED
@@ -695,12 +666,6 @@ static void set_fault_to_battery_status(struct cardinfo *card)
695 666
696static void init_battery_timer(void); 667static void init_battery_timer(void);
697 668
698
699/*
700-----------------------------------------------------------------------------------
701-- check_battery
702-----------------------------------------------------------------------------------
703*/
704static int check_battery(struct cardinfo *card, int battery, int status) 669static int check_battery(struct cardinfo *card, int battery, int status)
705{ 670{
706 if (status != card->battery[battery].good) { 671 if (status != card->battery[battery].good) {
@@ -729,11 +694,7 @@ static int check_battery(struct cardinfo *card, int battery, int status)
729 694
730 return 0; 695 return 0;
731} 696}
732/* 697
733-----------------------------------------------------------------------------------
734-- check_batteries
735-----------------------------------------------------------------------------------
736*/
737static void check_batteries(struct cardinfo *card) 698static void check_batteries(struct cardinfo *card)
738{ 699{
739 /* NOTE: this must *never* be called while the card 700 /* NOTE: this must *never* be called while the card
@@ -774,11 +735,7 @@ static void check_all_batteries(unsigned long ptr)
774 735
775 init_battery_timer(); 736 init_battery_timer();
776} 737}
777/* 738
778-----------------------------------------------------------------------------------
779-- init_battery_timer
780-----------------------------------------------------------------------------------
781*/
782static void init_battery_timer(void) 739static void init_battery_timer(void)
783{ 740{
784 init_timer(&battery_timer); 741 init_timer(&battery_timer);
@@ -786,20 +743,12 @@ static void init_battery_timer(void)
786 battery_timer.expires = jiffies + (HZ * 60); 743 battery_timer.expires = jiffies + (HZ * 60);
787 add_timer(&battery_timer); 744 add_timer(&battery_timer);
788} 745}
789/* 746
790-----------------------------------------------------------------------------------
791-- del_battery_timer
792-----------------------------------------------------------------------------------
793*/
794static void del_battery_timer(void) 747static void del_battery_timer(void)
795{ 748{
796 del_timer(&battery_timer); 749 del_timer(&battery_timer);
797} 750}
798/* 751
799-----------------------------------------------------------------------------------
800-- mm_revalidate
801-----------------------------------------------------------------------------------
802*/
803/* 752/*
804 * Note no locks taken out here. In a worst case scenario, we could drop 753 * Note no locks taken out here. In a worst case scenario, we could drop
805 * a chunk of system memory. But that should never happen, since validation 754 * a chunk of system memory. But that should never happen, since validation
@@ -832,33 +781,23 @@ static int mm_getgeo(struct block_device *bdev, struct hd_geometry *geo)
832} 781}
833 782
834/* 783/*
835----------------------------------------------------------------------------------- 784 * Future support for removable devices
836-- mm_check_change 785 */
837-----------------------------------------------------------------------------------
838 Future support for removable devices
839*/
840static int mm_check_change(struct gendisk *disk) 786static int mm_check_change(struct gendisk *disk)
841{ 787{
842/* struct cardinfo *dev = disk->private_data; */ 788/* struct cardinfo *dev = disk->private_data; */
843 return 0; 789 return 0;
844} 790}
845/* 791
846-----------------------------------------------------------------------------------
847-- mm_fops
848-----------------------------------------------------------------------------------
849*/
850static struct block_device_operations mm_fops = { 792static struct block_device_operations mm_fops = {
851 .owner = THIS_MODULE, 793 .owner = THIS_MODULE,
852 .getgeo = mm_getgeo, 794 .getgeo = mm_getgeo,
853 .revalidate_disk= mm_revalidate, 795 .revalidate_disk = mm_revalidate,
854 .media_changed = mm_check_change, 796 .media_changed = mm_check_change,
855}; 797};
856/* 798
857----------------------------------------------------------------------------------- 799static int __devinit mm_pci_probe(struct pci_dev *dev,
858-- mm_pci_probe 800 const struct pci_device_id *id)
859-----------------------------------------------------------------------------------
860*/
861static int __devinit mm_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
862{ 801{
863 int ret = -ENODEV; 802 int ret = -ENODEV;
864 struct cardinfo *card = &cards[num_cards]; 803 struct cardinfo *card = &cards[num_cards];
@@ -888,7 +827,7 @@ static int __devinit mm_pci_probe(struct pci_dev *dev, const struct pci_device_i
888 return -ENODEV; 827 return -ENODEV;
889 828
890 dev_printk(KERN_INFO, &dev->dev, 829 dev_printk(KERN_INFO, &dev->dev,
891 "Micro Memory(tm) controller found (PCI Mem Module (Battery Backup))\n"); 830 "Micro Memory(tm) controller found (PCI Mem Module (Battery Backup))\n");
892 831
893 if (pci_set_dma_mask(dev, DMA_64BIT_MASK) && 832 if (pci_set_dma_mask(dev, DMA_64BIT_MASK) &&
894 pci_set_dma_mask(dev, DMA_32BIT_MASK)) { 833 pci_set_dma_mask(dev, DMA_32BIT_MASK)) {
@@ -916,7 +855,7 @@ static int __devinit mm_pci_probe(struct pci_dev *dev, const struct pci_device_i
916 "CSR 0x%08lx -> 0x%p (0x%lx)\n", 855 "CSR 0x%08lx -> 0x%p (0x%lx)\n",
917 csr_base, card->csr_remap, csr_len); 856 csr_base, card->csr_remap, csr_len);
918 857
919 switch(card->dev->device) { 858 switch (card->dev->device) {
920 case 0x5415: 859 case 0x5415:
921 card->flags |= UM_FLAG_NO_BYTE_STATUS | UM_FLAG_NO_BATTREG; 860 card->flags |= UM_FLAG_NO_BYTE_STATUS | UM_FLAG_NO_BATTREG;
922 magic_number = 0x59; 861 magic_number = 0x59;
@@ -928,7 +867,8 @@ static int __devinit mm_pci_probe(struct pci_dev *dev, const struct pci_device_i
928 break; 867 break;
929 868
930 case 0x6155: 869 case 0x6155:
931 card->flags |= UM_FLAG_NO_BYTE_STATUS | UM_FLAG_NO_BATTREG | UM_FLAG_NO_BATT; 870 card->flags |= UM_FLAG_NO_BYTE_STATUS |
871 UM_FLAG_NO_BATTREG | UM_FLAG_NO_BATT;
932 magic_number = 0x99; 872 magic_number = 0x99;
933 break; 873 break;
934 874
@@ -944,11 +884,11 @@ static int __devinit mm_pci_probe(struct pci_dev *dev, const struct pci_device_i
944 } 884 }
945 885
946 card->mm_pages[0].desc = pci_alloc_consistent(card->dev, 886 card->mm_pages[0].desc = pci_alloc_consistent(card->dev,
947 PAGE_SIZE*2, 887 PAGE_SIZE * 2,
948 &card->mm_pages[0].page_dma); 888 &card->mm_pages[0].page_dma);
949 card->mm_pages[1].desc = pci_alloc_consistent(card->dev, 889 card->mm_pages[1].desc = pci_alloc_consistent(card->dev,
950 PAGE_SIZE*2, 890 PAGE_SIZE * 2,
951 &card->mm_pages[1].page_dma); 891 &card->mm_pages[1].page_dma);
952 if (card->mm_pages[0].desc == NULL || 892 if (card->mm_pages[0].desc == NULL ||
953 card->mm_pages[1].desc == NULL) { 893 card->mm_pages[1].desc == NULL) {
954 dev_printk(KERN_ERR, &card->dev->dev, "alloc failed\n"); 894 dev_printk(KERN_ERR, &card->dev->dev, "alloc failed\n");
@@ -1012,9 +952,9 @@ static int __devinit mm_pci_probe(struct pci_dev *dev, const struct pci_device_i
1012 dev_printk(KERN_INFO, &card->dev->dev, 952 dev_printk(KERN_INFO, &card->dev->dev,
1013 "Size %d KB, Battery 1 %s (%s), Battery 2 %s (%s)\n", 953 "Size %d KB, Battery 1 %s (%s), Battery 2 %s (%s)\n",
1014 card->mm_size, 954 card->mm_size,
1015 (batt_status & BATTERY_1_DISABLED ? "Disabled" : "Enabled"), 955 batt_status & BATTERY_1_DISABLED ? "Disabled" : "Enabled",
1016 card->battery[0].good ? "OK" : "FAILURE", 956 card->battery[0].good ? "OK" : "FAILURE",
1017 (batt_status & BATTERY_2_DISABLED ? "Disabled" : "Enabled"), 957 batt_status & BATTERY_2_DISABLED ? "Disabled" : "Enabled",
1018 card->battery[1].good ? "OK" : "FAILURE"); 958 card->battery[1].good ? "OK" : "FAILURE");
1019 959
1020 set_fault_to_battery_status(card); 960 set_fault_to_battery_status(card);
@@ -1029,18 +969,18 @@ static int __devinit mm_pci_probe(struct pci_dev *dev, const struct pci_device_i
1029 data = ~data; 969 data = ~data;
1030 data += 1; 970 data += 1;
1031 971
1032 if (request_irq(dev->irq, mm_interrupt, IRQF_SHARED, DRIVER_NAME, card)) { 972 if (request_irq(dev->irq, mm_interrupt, IRQF_SHARED, DRIVER_NAME,
973 card)) {
1033 dev_printk(KERN_ERR, &card->dev->dev, 974 dev_printk(KERN_ERR, &card->dev->dev,
1034 "Unable to allocate IRQ\n"); 975 "Unable to allocate IRQ\n");
1035 ret = -ENODEV; 976 ret = -ENODEV;
1036
1037 goto failed_req_irq; 977 goto failed_req_irq;
1038 } 978 }
1039 979
1040 dev_printk(KERN_INFO, &card->dev->dev, 980 dev_printk(KERN_INFO, &card->dev->dev,
1041 "Window size %d bytes, IRQ %d\n", data, dev->irq); 981 "Window size %d bytes, IRQ %d\n", data, dev->irq);
1042 982
1043 spin_lock_init(&card->lock); 983 spin_lock_init(&card->lock);
1044 984
1045 pci_set_drvdata(dev, card); 985 pci_set_drvdata(dev, card);
1046 986
@@ -1059,7 +999,7 @@ static int __devinit mm_pci_probe(struct pci_dev *dev, const struct pci_device_i
1059 999
1060 if (!get_userbit(card, MEMORY_INITIALIZED)) { 1000 if (!get_userbit(card, MEMORY_INITIALIZED)) {
1061 dev_printk(KERN_INFO, &card->dev->dev, 1001 dev_printk(KERN_INFO, &card->dev->dev,
1062 "memory NOT initialized. Consider over-writing whole device.\n"); 1002 "memory NOT initialized. Consider over-writing whole device.\n");
1063 card->init_size = 0; 1003 card->init_size = 0;
1064 } else { 1004 } else {
1065 dev_printk(KERN_INFO, &card->dev->dev, 1005 dev_printk(KERN_INFO, &card->dev->dev,
@@ -1090,11 +1030,7 @@ static int __devinit mm_pci_probe(struct pci_dev *dev, const struct pci_device_i
1090 1030
1091 return ret; 1031 return ret;
1092} 1032}
1093/* 1033
1094-----------------------------------------------------------------------------------
1095-- mm_pci_remove
1096-----------------------------------------------------------------------------------
1097*/
1098static void mm_pci_remove(struct pci_dev *dev) 1034static void mm_pci_remove(struct pci_dev *dev)
1099{ 1035{
1100 struct cardinfo *card = pci_get_drvdata(dev); 1036 struct cardinfo *card = pci_get_drvdata(dev);
@@ -1118,16 +1054,16 @@ static void mm_pci_remove(struct pci_dev *dev)
1118} 1054}
1119 1055
1120static const struct pci_device_id mm_pci_ids[] = { 1056static const struct pci_device_id mm_pci_ids[] = {
1121 {PCI_DEVICE(PCI_VENDOR_ID_MICRO_MEMORY,PCI_DEVICE_ID_MICRO_MEMORY_5415CN)}, 1057 {PCI_DEVICE(PCI_VENDOR_ID_MICRO_MEMORY, PCI_DEVICE_ID_MICRO_MEMORY_5415CN)},
1122 {PCI_DEVICE(PCI_VENDOR_ID_MICRO_MEMORY,PCI_DEVICE_ID_MICRO_MEMORY_5425CN)}, 1058 {PCI_DEVICE(PCI_VENDOR_ID_MICRO_MEMORY, PCI_DEVICE_ID_MICRO_MEMORY_5425CN)},
1123 {PCI_DEVICE(PCI_VENDOR_ID_MICRO_MEMORY,PCI_DEVICE_ID_MICRO_MEMORY_6155)}, 1059 {PCI_DEVICE(PCI_VENDOR_ID_MICRO_MEMORY, PCI_DEVICE_ID_MICRO_MEMORY_6155)},
1124 { 1060 {
1125 .vendor = 0x8086, 1061 .vendor = 0x8086,
1126 .device = 0xB555, 1062 .device = 0xB555,
1127 .subvendor= 0x1332, 1063 .subvendor = 0x1332,
1128 .subdevice= 0x5460, 1064 .subdevice = 0x5460,
1129 .class = 0x050000, 1065 .class = 0x050000,
1130 .class_mask= 0, 1066 .class_mask = 0,
1131 }, { /* end: all zeroes */ } 1067 }, { /* end: all zeroes */ }
1132}; 1068};
1133 1069
@@ -1140,12 +1076,6 @@ static struct pci_driver mm_pci_driver = {
1140 .remove = mm_pci_remove, 1076 .remove = mm_pci_remove,
1141}; 1077};
1142 1078
1143/*
1144-----------------------------------------------------------------------------------
1145-- mm_init
1146-----------------------------------------------------------------------------------
1147*/
1148
1149static int __init mm_init(void) 1079static int __init mm_init(void)
1150{ 1080{
1151 int retval, i; 1081 int retval, i;
@@ -1192,18 +1122,14 @@ out:
1192 put_disk(mm_gendisk[i]); 1122 put_disk(mm_gendisk[i]);
1193 return -ENOMEM; 1123 return -ENOMEM;
1194} 1124}
1195/* 1125
1196-----------------------------------------------------------------------------------
1197-- mm_cleanup
1198-----------------------------------------------------------------------------------
1199*/
1200static void __exit mm_cleanup(void) 1126static void __exit mm_cleanup(void)
1201{ 1127{
1202 int i; 1128 int i;
1203 1129
1204 del_battery_timer(); 1130 del_battery_timer();
1205 1131
1206 for (i=0; i < num_cards ; i++) { 1132 for (i = 0; i < num_cards ; i++) {
1207 del_gendisk(mm_gendisk[i]); 1133 del_gendisk(mm_gendisk[i]);
1208 put_disk(mm_gendisk[i]); 1134 put_disk(mm_gendisk[i]);
1209 } 1135 }
diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index 3cf7129d83e6..924ddd8bccd2 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -223,7 +223,7 @@ static int virtblk_probe(struct virtio_device *vdev)
223 err = virtio_config_val(vdev, VIRTIO_CONFIG_BLK_F_CAPACITY, &cap); 223 err = virtio_config_val(vdev, VIRTIO_CONFIG_BLK_F_CAPACITY, &cap);
224 if (err) { 224 if (err) {
225 dev_err(&vdev->dev, "Bad/missing capacity in config\n"); 225 dev_err(&vdev->dev, "Bad/missing capacity in config\n");
226 goto out_put_disk; 226 goto out_cleanup_queue;
227 } 227 }
228 228
229 /* If capacity is too big, truncate with warning. */ 229 /* If capacity is too big, truncate with warning. */
@@ -239,7 +239,7 @@ static int virtblk_probe(struct virtio_device *vdev)
239 blk_queue_max_segment_size(vblk->disk->queue, v); 239 blk_queue_max_segment_size(vblk->disk->queue, v);
240 else if (err != -ENOENT) { 240 else if (err != -ENOENT) {
241 dev_err(&vdev->dev, "Bad SIZE_MAX in config\n"); 241 dev_err(&vdev->dev, "Bad SIZE_MAX in config\n");
242 goto out_put_disk; 242 goto out_cleanup_queue;
243 } 243 }
244 244
245 err = virtio_config_val(vdev, VIRTIO_CONFIG_BLK_F_SEG_MAX, &v); 245 err = virtio_config_val(vdev, VIRTIO_CONFIG_BLK_F_SEG_MAX, &v);
@@ -247,12 +247,14 @@ static int virtblk_probe(struct virtio_device *vdev)
247 blk_queue_max_hw_segments(vblk->disk->queue, v); 247 blk_queue_max_hw_segments(vblk->disk->queue, v);
248 else if (err != -ENOENT) { 248 else if (err != -ENOENT) {
249 dev_err(&vdev->dev, "Bad SEG_MAX in config\n"); 249 dev_err(&vdev->dev, "Bad SEG_MAX in config\n");
250 goto out_put_disk; 250 goto out_cleanup_queue;
251 } 251 }
252 252
253 add_disk(vblk->disk); 253 add_disk(vblk->disk);
254 return 0; 254 return 0;
255 255
256out_cleanup_queue:
257 blk_cleanup_queue(vblk->disk->queue);
256out_put_disk: 258out_put_disk:
257 put_disk(vblk->disk); 259 put_disk(vblk->disk);
258out_unregister_blkdev: 260out_unregister_blkdev:
@@ -277,6 +279,8 @@ static void virtblk_remove(struct virtio_device *vdev)
277 put_disk(vblk->disk); 279 put_disk(vblk->disk);
278 unregister_blkdev(major, "virtblk"); 280 unregister_blkdev(major, "virtblk");
279 mempool_destroy(vblk->pool); 281 mempool_destroy(vblk->pool);
282 /* There should be nothing in the queue now, so no need to shutdown */
283 vdev->config->del_vq(vblk->vq);
280 kfree(vblk); 284 kfree(vblk);
281} 285}
282 286
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
index bf18d757b876..ef1ed5d70125 100644
--- a/drivers/char/Kconfig
+++ b/drivers/char/Kconfig
@@ -457,7 +457,7 @@ config LEGACY_PTYS
457config LEGACY_PTY_COUNT 457config LEGACY_PTY_COUNT
458 int "Maximum number of legacy PTY in use" 458 int "Maximum number of legacy PTY in use"
459 depends on LEGACY_PTYS 459 depends on LEGACY_PTYS
460 range 1 256 460 range 0 256
461 default "256" 461 default "256"
462 ---help--- 462 ---help---
463 The maximum number of legacy PTYs that can be used at any one time. 463 The maximum number of legacy PTYs that can be used at any one time.
@@ -543,28 +543,6 @@ config PPDEV
543 543
544 If unsure, say N. 544 If unsure, say N.
545 545
546config TIPAR
547 tristate "Texas Instruments parallel link cable support"
548 depends on PARPORT
549 ---help---
550 If you own a Texas Instruments graphing calculator and use a
551 parallel link cable, then you might be interested in this driver.
552
553 If you enable this driver, you will be able to communicate with
554 your calculator through a set of device nodes under /dev. The
555 main advantage of this driver is that you don't have to be root
556 to use this precise link cable (depending on the permissions on
557 the device nodes, though).
558
559 To compile this driver as a module, choose M here: the
560 module will be called tipar.
561
562 If you don't know what a parallel link cable is or what a Texas
563 Instruments graphing calculator is, then you probably don't need this
564 driver.
565
566 If unsure, say N.
567
568config HVC_DRIVER 546config HVC_DRIVER
569 bool 547 bool
570 help 548 help
diff --git a/drivers/char/apm-emulation.c b/drivers/char/apm-emulation.c
index c99e43b837f5..17d54315e146 100644
--- a/drivers/char/apm-emulation.c
+++ b/drivers/char/apm-emulation.c
@@ -295,7 +295,6 @@ static int
295apm_ioctl(struct inode * inode, struct file *filp, u_int cmd, u_long arg) 295apm_ioctl(struct inode * inode, struct file *filp, u_int cmd, u_long arg)
296{ 296{
297 struct apm_user *as = filp->private_data; 297 struct apm_user *as = filp->private_data;
298 unsigned long flags;
299 int err = -EINVAL; 298 int err = -EINVAL;
300 299
301 if (!as->suser || !as->writer) 300 if (!as->suser || !as->writer)
@@ -331,10 +330,16 @@ apm_ioctl(struct inode * inode, struct file *filp, u_int cmd, u_long arg)
331 * Wait for the suspend/resume to complete. If there 330 * Wait for the suspend/resume to complete. If there
332 * are pending acknowledges, we wait here for them. 331 * are pending acknowledges, we wait here for them.
333 */ 332 */
334 flags = current->flags; 333 freezer_do_not_count();
335 334
336 wait_event(apm_suspend_waitqueue, 335 wait_event(apm_suspend_waitqueue,
337 as->suspend_state == SUSPEND_DONE); 336 as->suspend_state == SUSPEND_DONE);
337
338 /*
339 * Since we are waiting until the suspend is done, the
340 * try_to_freeze() in freezer_count() will not trigger
341 */
342 freezer_count();
338 } else { 343 } else {
339 as->suspend_state = SUSPEND_WAIT; 344 as->suspend_state = SUSPEND_WAIT;
340 mutex_unlock(&state_lock); 345 mutex_unlock(&state_lock);
@@ -362,14 +367,10 @@ apm_ioctl(struct inode * inode, struct file *filp, u_int cmd, u_long arg)
362 * Wait for the suspend/resume to complete. If there 367 * Wait for the suspend/resume to complete. If there
363 * are pending acknowledges, we wait here for them. 368 * are pending acknowledges, we wait here for them.
364 */ 369 */
365 flags = current->flags; 370 wait_event_freezable(apm_suspend_waitqueue,
366
367 wait_event_interruptible(apm_suspend_waitqueue,
368 as->suspend_state == SUSPEND_DONE); 371 as->suspend_state == SUSPEND_DONE);
369 } 372 }
370 373
371 current->flags = flags;
372
373 mutex_lock(&state_lock); 374 mutex_lock(&state_lock);
374 err = as->suspend_result; 375 err = as->suspend_result;
375 as->suspend_state = SUSPEND_NONE; 376 as->suspend_state = SUSPEND_NONE;
diff --git a/drivers/char/cs5535_gpio.c b/drivers/char/cs5535_gpio.c
index fe6d2407baed..c2d23cae9515 100644
--- a/drivers/char/cs5535_gpio.c
+++ b/drivers/char/cs5535_gpio.c
@@ -104,6 +104,11 @@ static ssize_t cs5535_gpio_write(struct file *file, const char __user *data,
104 for (j = 0; j < ARRAY_SIZE(rm); j++) { 104 for (j = 0; j < ARRAY_SIZE(rm); j++) {
105 if (c == rm[j].on) { 105 if (c == rm[j].on) {
106 outl(m1, base + rm[j].wr_offset); 106 outl(m1, base + rm[j].wr_offset);
107 /* If enabling output, turn off AUX 1 and AUX 2 */
108 if (c == 'O') {
109 outl(m0, base + 0x10);
110 outl(m0, base + 0x14);
111 }
107 break; 112 break;
108 } else if (c == rm[j].off) { 113 } else if (c == rm[j].off) {
109 outl(m0, base + rm[j].wr_offset); 114 outl(m0, base + rm[j].wr_offset);
diff --git a/drivers/char/ipmi/ipmi_watchdog.c b/drivers/char/ipmi/ipmi_watchdog.c
index e686fc925168..8f45ca9235ad 100644
--- a/drivers/char/ipmi/ipmi_watchdog.c
+++ b/drivers/char/ipmi/ipmi_watchdog.c
@@ -669,6 +669,7 @@ static int ipmi_ioctl(struct inode *inode, struct file *file,
669 return 0; 669 return 0;
670 670
671 case WDIOC_SET_PRETIMEOUT: 671 case WDIOC_SET_PRETIMEOUT:
672 case WDIOC_SETPRETIMEOUT:
672 i = copy_from_user(&val, argp, sizeof(int)); 673 i = copy_from_user(&val, argp, sizeof(int));
673 if (i) 674 if (i)
674 return -EFAULT; 675 return -EFAULT;
@@ -676,6 +677,7 @@ static int ipmi_ioctl(struct inode *inode, struct file *file,
676 return ipmi_set_timeout(IPMI_SET_TIMEOUT_HB_IF_NECESSARY); 677 return ipmi_set_timeout(IPMI_SET_TIMEOUT_HB_IF_NECESSARY);
677 678
678 case WDIOC_GET_PRETIMEOUT: 679 case WDIOC_GET_PRETIMEOUT:
680 case WDIOC_GETPRETIMEOUT:
679 i = copy_to_user(argp, &pretimeout, sizeof(pretimeout)); 681 i = copy_to_user(argp, &pretimeout, sizeof(pretimeout));
680 if (i) 682 if (i)
681 return -EFAULT; 683 return -EFAULT;
diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
index 877e53dcb996..921c6d2bc8fc 100644
--- a/drivers/char/sonypi.c
+++ b/drivers/char/sonypi.c
@@ -1163,7 +1163,7 @@ static struct acpi_driver sonypi_acpi_driver = {
1163}; 1163};
1164#endif 1164#endif
1165 1165
1166static int __devinit sonypi_create_input_devices(void) 1166static int __devinit sonypi_create_input_devices(struct platform_device *pdev)
1167{ 1167{
1168 struct input_dev *jog_dev; 1168 struct input_dev *jog_dev;
1169 struct input_dev *key_dev; 1169 struct input_dev *key_dev;
@@ -1177,6 +1177,7 @@ static int __devinit sonypi_create_input_devices(void)
1177 jog_dev->name = "Sony Vaio Jogdial"; 1177 jog_dev->name = "Sony Vaio Jogdial";
1178 jog_dev->id.bustype = BUS_ISA; 1178 jog_dev->id.bustype = BUS_ISA;
1179 jog_dev->id.vendor = PCI_VENDOR_ID_SONY; 1179 jog_dev->id.vendor = PCI_VENDOR_ID_SONY;
1180 jog_dev->dev.parent = &pdev->dev;
1180 1181
1181 jog_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL); 1182 jog_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL);
1182 jog_dev->keybit[BIT_WORD(BTN_MOUSE)] = BIT_MASK(BTN_MIDDLE); 1183 jog_dev->keybit[BIT_WORD(BTN_MOUSE)] = BIT_MASK(BTN_MIDDLE);
@@ -1191,6 +1192,7 @@ static int __devinit sonypi_create_input_devices(void)
1191 key_dev->name = "Sony Vaio Keys"; 1192 key_dev->name = "Sony Vaio Keys";
1192 key_dev->id.bustype = BUS_ISA; 1193 key_dev->id.bustype = BUS_ISA;
1193 key_dev->id.vendor = PCI_VENDOR_ID_SONY; 1194 key_dev->id.vendor = PCI_VENDOR_ID_SONY;
1195 key_dev->dev.parent = &pdev->dev;
1194 1196
1195 /* Initialize the Input Drivers: special keys */ 1197 /* Initialize the Input Drivers: special keys */
1196 key_dev->evbit[0] = BIT_MASK(EV_KEY); 1198 key_dev->evbit[0] = BIT_MASK(EV_KEY);
@@ -1385,7 +1387,7 @@ static int __devinit sonypi_probe(struct platform_device *dev)
1385 1387
1386 if (useinput) { 1388 if (useinput) {
1387 1389
1388 error = sonypi_create_input_devices(); 1390 error = sonypi_create_input_devices(dev);
1389 if (error) { 1391 if (error) {
1390 printk(KERN_ERR 1392 printk(KERN_ERR
1391 "sonypi: failed to create input devices\n"); 1393 "sonypi: failed to create input devices\n");
@@ -1432,7 +1434,7 @@ static int __devexit sonypi_remove(struct platform_device *dev)
1432{ 1434{
1433 sonypi_disable(); 1435 sonypi_disable();
1434 1436
1435 synchronize_sched(); /* Allow sonypi interrupt to complete. */ 1437 synchronize_irq(sonypi_device.irq);
1436 flush_scheduled_work(); 1438 flush_scheduled_work();
1437 1439
1438 if (useinput) { 1440 if (useinput) {
diff --git a/drivers/char/tipar.c b/drivers/char/tipar.c
deleted file mode 100644
index cef55c40654f..000000000000
--- a/drivers/char/tipar.c
+++ /dev/null
@@ -1,557 +0,0 @@
1/* Hey EMACS -*- linux-c -*-
2 *
3 * tipar - low level driver for handling a parallel link cable designed
4 * for Texas Instruments graphing calculators (http://lpg.ticalc.org).
5 * A part of the TiLP project.
6 *
7 * Copyright (C) 2000-2002, Romain Lievin <roms@lpg.ticalc.org>
8 * under the terms of the GNU General Public License.
9 *
10 * Various fixes & clean-up from the Linux Kernel Mailing List
11 * (Alan Cox, Richard B. Johnson, Christoph Hellwig).
12 */
13
14/* This driver should, in theory, work with any parallel port that has an
15 * appropriate low-level driver; all I/O is done through the parport
16 * abstraction layer.
17 *
18 * If this driver is built into the kernel, you can configure it using the
19 * kernel command-line. For example:
20 *
21 * tipar=timeout,delay (set timeout and delay)
22 *
23 * If the driver is loaded as a module, similar functionality is available
24 * using module parameters. The equivalent of the above commands would be:
25 *
26 * # insmod tipar timeout=15 delay=10
27 */
28
29/* COMPATIBILITY WITH OLD KERNELS
30 *
31 * Usually, parallel cables were bound to ports at
32 * particular I/O addresses, as follows:
33 *
34 * tipar0 0x378
35 * tipar1 0x278
36 * tipar2 0x3bc
37 *
38 *
39 * This driver, by default, binds tipar devices according to parport and
40 * the minor number.
41 *
42 */
43#undef DEBUG /* change to #define to get debugging
44 * output - for pr_debug() */
45#include <linux/module.h>
46#include <linux/types.h>
47#include <linux/errno.h>
48#include <linux/kernel.h>
49#include <linux/sched.h>
50#include <linux/delay.h>
51#include <linux/fcntl.h>
52#include <linux/fs.h>
53#include <linux/init.h>
54#include <asm/uaccess.h>
55#include <linux/ioport.h>
56#include <asm/io.h>
57#include <linux/bitops.h>
58#include <linux/parport.h> /* Our code depend on parport */
59#include <linux/device.h>
60
61/*
62 * TI definitions
63 */
64#include <linux/ticable.h>
65
66/*
67 * Version Information
68 */
69#define DRIVER_VERSION "1.19"
70#define DRIVER_AUTHOR "Romain Lievin <roms@lpg.ticalc.org>"
71#define DRIVER_DESC "Device driver for TI/PC parallel link cables"
72#define DRIVER_LICENSE "GPL"
73
74#define VERSION(ver,rel,seq) (((ver)<<16) | ((rel)<<8) | (seq))
75
76/* ----- global variables --------------------------------------------- */
77
78struct tipar_struct {
79 struct pardevice *dev; /* Parport device entry */
80};
81
82#define PP_NO 3
83static struct tipar_struct table[PP_NO];
84
85static int delay = IO_DELAY; /* inter-bit delay in microseconds */
86static int timeout = TIMAXTIME; /* timeout in tenth of seconds */
87
88static unsigned int tp_count; /* tipar count */
89static unsigned long opened; /* opened devices */
90
91static struct class *tipar_class;
92
93/* --- macros for parport access -------------------------------------- */
94
95#define r_dtr(x) (parport_read_data(table[(x)].dev->port))
96#define r_str(x) (parport_read_status(table[(x)].dev->port))
97#define w_ctr(x,y) (parport_write_control(table[(x)].dev->port, (y)))
98#define w_dtr(x,y) (parport_write_data(table[(x)].dev->port, (y)))
99
100/* --- setting states on the D-bus with the right timing: ------------- */
101
102static inline void
103outbyte(int value, int minor)
104{
105 w_dtr(minor, value);
106}
107
108static inline int
109inbyte(int minor)
110{
111 return (r_str(minor));
112}
113
114static inline void
115init_ti_parallel(int minor)
116{
117 outbyte(3, minor);
118}
119
120/* ----- global defines ----------------------------------------------- */
121
122#define START(x) { x = jiffies + (HZ * timeout) / 10; }
123#define WAIT(x) { \
124 if (time_before((x), jiffies)) return -1; \
125 if (need_resched()) schedule(); }
126
127/* ----- D-bus bit-banging functions ---------------------------------- */
128
129/* D-bus protocol (45kbit/s max):
130 1 0 0
131 _______ ______|______ __________|________ __________
132Red : ________ | ____ | ____
133 _ ____________|________ ______|__________ _____
134White: ________ | ______ | _______
135*/
136
137/* Try to transmit a byte on the specified port (-1 if error). */
138static int
139put_ti_parallel(int minor, unsigned char data)
140{
141 unsigned int bit;
142 unsigned long max;
143
144 for (bit = 0; bit < 8; bit++) {
145 if (data & 1) {
146 outbyte(2, minor);
147 START(max);
148 do {
149 WAIT(max);
150 } while (inbyte(minor) & 0x10);
151
152 outbyte(3, minor);
153 START(max);
154 do {
155 WAIT(max);
156 } while (!(inbyte(minor) & 0x10));
157 } else {
158 outbyte(1, minor);
159 START(max);
160 do {
161 WAIT(max);
162 } while (inbyte(minor) & 0x20);
163
164 outbyte(3, minor);
165 START(max);
166 do {
167 WAIT(max);
168 } while (!(inbyte(minor) & 0x20));
169 }
170
171 data >>= 1;
172 udelay(delay);
173
174 if (need_resched())
175 schedule();
176 }
177
178 return 0;
179}
180
181/* Receive a byte on the specified port or -1 if error. */
182static int
183get_ti_parallel(int minor)
184{
185 unsigned int bit;
186 unsigned char v, data = 0;
187 unsigned long max;
188
189 for (bit = 0; bit < 8; bit++) {
190 START(max);
191 do {
192 WAIT(max);
193 } while ((v = inbyte(minor) & 0x30) == 0x30);
194
195 if (v == 0x10) {
196 data = (data >> 1) | 0x80;
197 outbyte(1, minor);
198 START(max);
199 do {
200 WAIT(max);
201 } while (!(inbyte(minor) & 0x20));
202 outbyte(3, minor);
203 } else {
204 data = data >> 1;
205 outbyte(2, minor);
206 START(max);
207 do {
208 WAIT(max);
209 } while (!(inbyte(minor) & 0x10));
210 outbyte(3, minor);
211 }
212
213 udelay(delay);
214 if (need_resched())
215 schedule();
216 }
217
218 return (int) data;
219}
220
221/* Try to detect a parallel link cable on the specified port */
222static int
223probe_ti_parallel(int minor)
224{
225 int i;
226 int seq[] = { 0x00, 0x20, 0x10, 0x30 };
227 int data;
228
229 for (i = 3; i >= 0; i--) {
230 outbyte(3, minor);
231 outbyte(i, minor);
232 udelay(delay);
233 data = inbyte(minor) & 0x30;
234 pr_debug("tipar: Probing -> %i: 0x%02x 0x%02x\n", i,
235 data, seq[i]);
236 if (data != seq[i]) {
237 outbyte(3, minor);
238 return -1;
239 }
240 }
241
242 outbyte(3, minor);
243 return 0;
244}
245
246/* ----- kernel module functions--------------------------------------- */
247
248static int
249tipar_open(struct inode *inode, struct file *file)
250{
251 unsigned int minor = iminor(inode) - TIPAR_MINOR;
252
253 if (tp_count == 0 || minor > tp_count - 1)
254 return -ENXIO;
255
256 if (test_and_set_bit(minor, &opened))
257 return -EBUSY;
258
259 if (!table[minor].dev) {
260 printk(KERN_ERR "%s: NULL device for minor %u\n",
261 __FUNCTION__, minor);
262 return -ENXIO;
263 }
264 parport_claim_or_block(table[minor].dev);
265 init_ti_parallel(minor);
266 parport_release(table[minor].dev);
267
268 return nonseekable_open(inode, file);
269}
270
271static int
272tipar_close(struct inode *inode, struct file *file)
273{
274 unsigned int minor = iminor(inode) - TIPAR_MINOR;
275
276 if (minor > tp_count - 1)
277 return -ENXIO;
278
279 clear_bit(minor, &opened);
280
281 return 0;
282}
283
284static ssize_t
285tipar_write (struct file *file, const char __user *buf, size_t count,
286 loff_t * ppos)
287{
288 unsigned int minor = iminor(file->f_path.dentry->d_inode) - TIPAR_MINOR;
289 ssize_t n;
290
291 parport_claim_or_block(table[minor].dev);
292
293 for (n = 0; n < count; n++) {
294 unsigned char b;
295
296 if (get_user(b, buf + n)) {
297 n = -EFAULT;
298 goto out;
299 }
300
301 if (put_ti_parallel(minor, b) == -1) {
302 init_ti_parallel(minor);
303 n = -ETIMEDOUT;
304 goto out;
305 }
306 }
307 out:
308 parport_release(table[minor].dev);
309 return n;
310}
311
312static ssize_t
313tipar_read(struct file *file, char __user *buf, size_t count, loff_t * ppos)
314{
315 int b = 0;
316 unsigned int minor = iminor(file->f_path.dentry->d_inode) - TIPAR_MINOR;
317 ssize_t retval = 0;
318 ssize_t n = 0;
319
320 if (count == 0)
321 return 0;
322
323 parport_claim_or_block(table[minor].dev);
324
325 while (n < count) {
326 b = get_ti_parallel(minor);
327 if (b == -1) {
328 init_ti_parallel(minor);
329 retval = -ETIMEDOUT;
330 goto out;
331 } else {
332 if (put_user(b, buf + n)) {
333 retval = -EFAULT;
334 break;
335 } else
336 retval = ++n;
337 }
338
339 /* Non-blocking mode : try again ! */
340 if (file->f_flags & O_NONBLOCK) {
341 retval = -EAGAIN;
342 goto out;
343 }
344
345 /* Signal pending, try again ! */
346 if (signal_pending(current)) {
347 retval = -ERESTARTSYS;
348 goto out;
349 }
350
351 if (need_resched())
352 schedule();
353 }
354
355 out:
356 parport_release(table[minor].dev);
357 return retval;
358}
359
360static int
361tipar_ioctl(struct inode *inode, struct file *file,
362 unsigned int cmd, unsigned long arg)
363{
364 int retval = 0;
365
366 switch (cmd) {
367 case IOCTL_TIPAR_DELAY:
368 delay = (int)arg; //get_user(delay, &arg);
369 break;
370 case IOCTL_TIPAR_TIMEOUT:
371 if (arg != 0)
372 timeout = (int)arg;
373 else
374 retval = -EINVAL;
375 break;
376 default:
377 retval = -ENOTTY;
378 break;
379 }
380
381 return retval;
382}
383
384/* ----- kernel module registering ------------------------------------ */
385
386static const struct file_operations tipar_fops = {
387 .owner = THIS_MODULE,
388 .llseek = no_llseek,
389 .read = tipar_read,
390 .write = tipar_write,
391 .ioctl = tipar_ioctl,
392 .open = tipar_open,
393 .release = tipar_close,
394};
395
396/* --- initialisation code ------------------------------------- */
397
398#ifndef MODULE
399/* You must set these - there is no sane way to probe for this cable.
400 * You can use 'tipar=timeout,delay' to set these now. */
401static int __init
402tipar_setup(char *str)
403{
404 int ints[3];
405
406 str = get_options(str, ARRAY_SIZE(ints), ints);
407
408 if (ints[0] > 0) {
409 if (ints[1] != 0)
410 timeout = ints[1];
411 else
412 printk(KERN_WARNING "tipar: bad timeout value (0), "
413 "using default value instead");
414 if (ints[0] > 1) {
415 delay = ints[2];
416 }
417 }
418
419 return 1;
420}
421#endif
422
423/*
424 * Register our module into parport.
425 * Pass also 2 callbacks functions to parport: a pre-emptive function and an
426 * interrupt handler function (unused).
427 * Display a message such "tipar0: using parport0 (polling)".
428 */
429static int
430tipar_register(int nr, struct parport *port)
431{
432 int err = 0;
433
434 /* Register our module into parport */
435 table[nr].dev = parport_register_device(port, "tipar",
436 NULL, NULL, NULL, 0,
437 (void *) &table[nr]);
438
439 if (table[nr].dev == NULL) {
440 err = 1;
441 goto out;
442 }
443
444 device_create(tipar_class, port->dev, MKDEV(TIPAR_MAJOR,
445 TIPAR_MINOR + nr), "par%d", nr);
446
447 /* Display informations */
448 pr_info("tipar%d: using %s (%s)\n", nr, port->name, (port->irq ==
449 PARPORT_IRQ_NONE) ? "polling" : "interrupt-driven");
450
451 if (probe_ti_parallel(nr) != -1)
452 pr_info("tipar%d: link cable found\n", nr);
453 else
454 pr_info("tipar%d: link cable not found\n", nr);
455
456 err = 0;
457
458out:
459 return err;
460}
461
462static void
463tipar_attach(struct parport *port)
464{
465 if (tp_count == PP_NO) {
466 pr_info("tipar: ignoring parallel port (max. %d)\n", PP_NO);
467 return;
468 }
469
470 if (!tipar_register(tp_count, port))
471 tp_count++;
472}
473
474static void
475tipar_detach(struct parport *port)
476{
477 /* Nothing to do */
478}
479
480static struct parport_driver tipar_driver = {
481 .name = "tipar",
482 .attach = tipar_attach,
483 .detach = tipar_detach,
484};
485
486static int __init
487tipar_init_module(void)
488{
489 int err = 0;
490
491 pr_info("tipar: parallel link cable driver, version %s\n",
492 DRIVER_VERSION);
493
494 if (register_chrdev(TIPAR_MAJOR, "tipar", &tipar_fops)) {
495 printk(KERN_ERR "tipar: unable to get major %d\n", TIPAR_MAJOR);
496 err = -EIO;
497 goto out;
498 }
499
500 tipar_class = class_create(THIS_MODULE, "ticables");
501 if (IS_ERR(tipar_class)) {
502 err = PTR_ERR(tipar_class);
503 goto out_chrdev;
504 }
505 if (parport_register_driver(&tipar_driver)) {
506 printk(KERN_ERR "tipar: unable to register with parport\n");
507 err = -EIO;
508 goto out_class;
509 }
510
511 err = 0;
512 goto out;
513
514out_class:
515 class_destroy(tipar_class);
516
517out_chrdev:
518 unregister_chrdev(TIPAR_MAJOR, "tipar");
519out:
520 return err;
521}
522
523static void __exit
524tipar_cleanup_module(void)
525{
526 unsigned int i;
527
528 /* Unregistering module */
529 parport_unregister_driver(&tipar_driver);
530
531 unregister_chrdev(TIPAR_MAJOR, "tipar");
532
533 for (i = 0; i < PP_NO; i++) {
534 if (table[i].dev == NULL)
535 continue;
536 parport_unregister_device(table[i].dev);
537 device_destroy(tipar_class, MKDEV(TIPAR_MAJOR, i));
538 }
539 class_destroy(tipar_class);
540
541 pr_info("tipar: module unloaded\n");
542}
543
544/* --------------------------------------------------------------------- */
545
546__setup("tipar=", tipar_setup);
547module_init(tipar_init_module);
548module_exit(tipar_cleanup_module);
549
550MODULE_AUTHOR(DRIVER_AUTHOR);
551MODULE_DESCRIPTION(DRIVER_DESC);
552MODULE_LICENSE(DRIVER_LICENSE);
553
554module_param(timeout, int, 0);
555MODULE_PARM_DESC(timeout, "Timeout (default=1.5 seconds)");
556module_param(delay, int, 0);
557MODULE_PARM_DESC(delay, "Inter-bit delay (default=10 microseconds)");
diff --git a/drivers/char/tpm/tpm_tis.c b/drivers/char/tpm/tpm_tis.c
index fd771a4d6d18..81503d94fecc 100644
--- a/drivers/char/tpm/tpm_tis.c
+++ b/drivers/char/tpm/tpm_tis.c
@@ -450,6 +450,11 @@ static int tpm_tis_init(struct device *dev, resource_size_t start,
450 goto out_err; 450 goto out_err;
451 } 451 }
452 452
453 if (request_locality(chip, 0) != 0) {
454 rc = -ENODEV;
455 goto out_err;
456 }
457
453 vendor = ioread32(chip->vendor.iobase + TPM_DID_VID(0)); 458 vendor = ioread32(chip->vendor.iobase + TPM_DID_VID(0));
454 459
455 /* Default timeouts */ 460 /* Default timeouts */
@@ -487,11 +492,6 @@ static int tpm_tis_init(struct device *dev, resource_size_t start,
487 if (intfcaps & TPM_INTF_DATA_AVAIL_INT) 492 if (intfcaps & TPM_INTF_DATA_AVAIL_INT)
488 dev_dbg(dev, "\tData Avail Int Support\n"); 493 dev_dbg(dev, "\tData Avail Int Support\n");
489 494
490 if (request_locality(chip, 0) != 0) {
491 rc = -ENODEV;
492 goto out_err;
493 }
494
495 /* INTERRUPT Setup */ 495 /* INTERRUPT Setup */
496 init_waitqueue_head(&chip->vendor.read_queue); 496 init_waitqueue_head(&chip->vendor.read_queue);
497 init_waitqueue_head(&chip->vendor.int_queue); 497 init_waitqueue_head(&chip->vendor.int_queue);
diff --git a/drivers/char/tty_ioctl.c b/drivers/char/tty_ioctl.c
index 1bdd2bf4f37d..e02d59245a17 100644
--- a/drivers/char/tty_ioctl.c
+++ b/drivers/char/tty_ioctl.c
@@ -62,7 +62,7 @@ void tty_wait_until_sent(struct tty_struct * tty, long timeout)
62 if (!timeout) 62 if (!timeout)
63 timeout = MAX_SCHEDULE_TIMEOUT; 63 timeout = MAX_SCHEDULE_TIMEOUT;
64 if (wait_event_interruptible_timeout(tty->write_wait, 64 if (wait_event_interruptible_timeout(tty->write_wait,
65 !tty->driver->chars_in_buffer(tty), timeout)) 65 !tty->driver->chars_in_buffer(tty), timeout) < 0)
66 return; 66 return;
67 if (tty->driver->wait_until_sent) 67 if (tty->driver->wait_until_sent)
68 tty->driver->wait_until_sent(tty, timeout); 68 tty->driver->wait_until_sent(tty, timeout);
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 5e626b12b97e..79581fab82d6 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -841,19 +841,25 @@ static int cpufreq_add_dev (struct sys_device * sys_dev)
841 drv_attr = cpufreq_driver->attr; 841 drv_attr = cpufreq_driver->attr;
842 while ((drv_attr) && (*drv_attr)) { 842 while ((drv_attr) && (*drv_attr)) {
843 ret = sysfs_create_file(&policy->kobj, &((*drv_attr)->attr)); 843 ret = sysfs_create_file(&policy->kobj, &((*drv_attr)->attr));
844 if (ret) 844 if (ret) {
845 unlock_policy_rwsem_write(cpu);
845 goto err_out_driver_exit; 846 goto err_out_driver_exit;
847 }
846 drv_attr++; 848 drv_attr++;
847 } 849 }
848 if (cpufreq_driver->get){ 850 if (cpufreq_driver->get){
849 ret = sysfs_create_file(&policy->kobj, &cpuinfo_cur_freq.attr); 851 ret = sysfs_create_file(&policy->kobj, &cpuinfo_cur_freq.attr);
850 if (ret) 852 if (ret) {
853 unlock_policy_rwsem_write(cpu);
851 goto err_out_driver_exit; 854 goto err_out_driver_exit;
855 }
852 } 856 }
853 if (cpufreq_driver->target){ 857 if (cpufreq_driver->target){
854 ret = sysfs_create_file(&policy->kobj, &scaling_cur_freq.attr); 858 ret = sysfs_create_file(&policy->kobj, &scaling_cur_freq.attr);
855 if (ret) 859 if (ret) {
860 unlock_policy_rwsem_write(cpu);
856 goto err_out_driver_exit; 861 goto err_out_driver_exit;
862 }
857 } 863 }
858 864
859 spin_lock_irqsave(&cpufreq_driver_lock, flags); 865 spin_lock_irqsave(&cpufreq_driver_lock, flags);
diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
index 8a45d0f93e26..1b8312b02006 100644
--- a/drivers/cpufreq/cpufreq_stats.c
+++ b/drivers/cpufreq/cpufreq_stats.c
@@ -164,7 +164,7 @@ freq_table_get_index(struct cpufreq_stats *stat, unsigned int freq)
164 return -1; 164 return -1;
165} 165}
166 166
167static void __cpuexit cpufreq_stats_free_table(unsigned int cpu) 167static void cpufreq_stats_free_table(unsigned int cpu)
168{ 168{
169 struct cpufreq_stats *stat = cpufreq_stats_table[cpu]; 169 struct cpufreq_stats *stat = cpufreq_stats_table[cpu];
170 struct cpufreq_policy *policy = cpufreq_cpu_get(cpu); 170 struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
diff --git a/drivers/crypto/Kconfig b/drivers/crypto/Kconfig
index 5fd6688a444a..ddd3a259cea1 100644
--- a/drivers/crypto/Kconfig
+++ b/drivers/crypto/Kconfig
@@ -12,7 +12,7 @@ if CRYPTO_HW
12 12
13config CRYPTO_DEV_PADLOCK 13config CRYPTO_DEV_PADLOCK
14 tristate "Support for VIA PadLock ACE" 14 tristate "Support for VIA PadLock ACE"
15 depends on X86_32 15 depends on X86_32 && !UML
16 select CRYPTO_ALGAPI 16 select CRYPTO_ALGAPI
17 help 17 help
18 Some VIA processors come with an integrated crypto engine 18 Some VIA processors come with an integrated crypto engine
diff --git a/drivers/dma/Kconfig b/drivers/dma/Kconfig
index 6a7d25fc2470..c46b7c219ee9 100644
--- a/drivers/dma/Kconfig
+++ b/drivers/dma/Kconfig
@@ -3,11 +3,13 @@
3# 3#
4 4
5menuconfig DMADEVICES 5menuconfig DMADEVICES
6 bool "DMA Offload Engine support" 6 bool "DMA Engine support"
7 depends on (PCI && X86) || ARCH_IOP32X || ARCH_IOP33X || ARCH_IOP13XX 7 depends on (PCI && X86) || ARCH_IOP32X || ARCH_IOP33X || ARCH_IOP13XX
8 help 8 help
9 Intel(R) offload engines enable offloading memory copies in the 9 DMA engines can do asynchronous data transfers without
10 network stack and RAID operations in the MD driver. 10 involving the host CPU. Currently, this framework can be
11 used to offload memory copies in the network stack and
12 RAID operations in the MD driver.
11 13
12if DMADEVICES 14if DMADEVICES
13 15
diff --git a/drivers/dma/ioat_dma.c b/drivers/dma/ioat_dma.c
index c1c2dcc6fc2e..45e7b4666c7b 100644
--- a/drivers/dma/ioat_dma.c
+++ b/drivers/dma/ioat_dma.c
@@ -173,10 +173,47 @@ static void ioat_set_dest(dma_addr_t addr,
173 tx_to_ioat_desc(tx)->dst = addr; 173 tx_to_ioat_desc(tx)->dst = addr;
174} 174}
175 175
176/**
177 * ioat_dma_memcpy_issue_pending - push potentially unrecognized appended
178 * descriptors to hw
179 * @chan: DMA channel handle
180 */
176static inline void __ioat1_dma_memcpy_issue_pending( 181static inline void __ioat1_dma_memcpy_issue_pending(
177 struct ioat_dma_chan *ioat_chan); 182 struct ioat_dma_chan *ioat_chan)
183{
184 ioat_chan->pending = 0;
185 writeb(IOAT_CHANCMD_APPEND, ioat_chan->reg_base + IOAT1_CHANCMD_OFFSET);
186}
187
188static void ioat1_dma_memcpy_issue_pending(struct dma_chan *chan)
189{
190 struct ioat_dma_chan *ioat_chan = to_ioat_chan(chan);
191
192 if (ioat_chan->pending != 0) {
193 spin_lock_bh(&ioat_chan->desc_lock);
194 __ioat1_dma_memcpy_issue_pending(ioat_chan);
195 spin_unlock_bh(&ioat_chan->desc_lock);
196 }
197}
198
178static inline void __ioat2_dma_memcpy_issue_pending( 199static inline void __ioat2_dma_memcpy_issue_pending(
179 struct ioat_dma_chan *ioat_chan); 200 struct ioat_dma_chan *ioat_chan)
201{
202 ioat_chan->pending = 0;
203 writew(ioat_chan->dmacount,
204 ioat_chan->reg_base + IOAT_CHAN_DMACOUNT_OFFSET);
205}
206
207static void ioat2_dma_memcpy_issue_pending(struct dma_chan *chan)
208{
209 struct ioat_dma_chan *ioat_chan = to_ioat_chan(chan);
210
211 if (ioat_chan->pending != 0) {
212 spin_lock_bh(&ioat_chan->desc_lock);
213 __ioat2_dma_memcpy_issue_pending(ioat_chan);
214 spin_unlock_bh(&ioat_chan->desc_lock);
215 }
216}
180 217
181static dma_cookie_t ioat1_tx_submit(struct dma_async_tx_descriptor *tx) 218static dma_cookie_t ioat1_tx_submit(struct dma_async_tx_descriptor *tx)
182{ 219{
@@ -203,7 +240,7 @@ static dma_cookie_t ioat1_tx_submit(struct dma_async_tx_descriptor *tx)
203 prev = to_ioat_desc(ioat_chan->used_desc.prev); 240 prev = to_ioat_desc(ioat_chan->used_desc.prev);
204 prefetch(prev->hw); 241 prefetch(prev->hw);
205 do { 242 do {
206 copy = min((u32) len, ioat_chan->xfercap); 243 copy = min_t(size_t, len, ioat_chan->xfercap);
207 244
208 new->async_tx.ack = 1; 245 new->async_tx.ack = 1;
209 246
@@ -291,10 +328,12 @@ static dma_cookie_t ioat2_tx_submit(struct dma_async_tx_descriptor *tx)
291 orig_ack = first->async_tx.ack; 328 orig_ack = first->async_tx.ack;
292 new = first; 329 new = first;
293 330
294 /* ioat_chan->desc_lock is still in force in version 2 path */ 331 /*
295 332 * ioat_chan->desc_lock is still in force in version 2 path
333 * it gets unlocked at end of this function
334 */
296 do { 335 do {
297 copy = min((u32) len, ioat_chan->xfercap); 336 copy = min_t(size_t, len, ioat_chan->xfercap);
298 337
299 new->async_tx.ack = 1; 338 new->async_tx.ack = 1;
300 339
@@ -432,7 +471,7 @@ static void ioat2_dma_massage_chan_desc(struct ioat_dma_chan *ioat_chan)
432static int ioat_dma_alloc_chan_resources(struct dma_chan *chan) 471static int ioat_dma_alloc_chan_resources(struct dma_chan *chan)
433{ 472{
434 struct ioat_dma_chan *ioat_chan = to_ioat_chan(chan); 473 struct ioat_dma_chan *ioat_chan = to_ioat_chan(chan);
435 struct ioat_desc_sw *desc = NULL; 474 struct ioat_desc_sw *desc;
436 u16 chanctrl; 475 u16 chanctrl;
437 u32 chanerr; 476 u32 chanerr;
438 int i; 477 int i;
@@ -575,7 +614,7 @@ static void ioat_dma_free_chan_resources(struct dma_chan *chan)
575static struct ioat_desc_sw * 614static struct ioat_desc_sw *
576ioat1_dma_get_next_descriptor(struct ioat_dma_chan *ioat_chan) 615ioat1_dma_get_next_descriptor(struct ioat_dma_chan *ioat_chan)
577{ 616{
578 struct ioat_desc_sw *new = NULL; 617 struct ioat_desc_sw *new;
579 618
580 if (!list_empty(&ioat_chan->free_desc)) { 619 if (!list_empty(&ioat_chan->free_desc)) {
581 new = to_ioat_desc(ioat_chan->free_desc.next); 620 new = to_ioat_desc(ioat_chan->free_desc.next);
@@ -583,9 +622,11 @@ ioat1_dma_get_next_descriptor(struct ioat_dma_chan *ioat_chan)
583 } else { 622 } else {
584 /* try to get another desc */ 623 /* try to get another desc */
585 new = ioat_dma_alloc_descriptor(ioat_chan, GFP_ATOMIC); 624 new = ioat_dma_alloc_descriptor(ioat_chan, GFP_ATOMIC);
586 /* will this ever happen? */ 625 if (!new) {
587 /* TODO add upper limit on these */ 626 dev_err(&ioat_chan->device->pdev->dev,
588 BUG_ON(!new); 627 "alloc failed\n");
628 return NULL;
629 }
589 } 630 }
590 631
591 prefetch(new->hw); 632 prefetch(new->hw);
@@ -595,7 +636,7 @@ ioat1_dma_get_next_descriptor(struct ioat_dma_chan *ioat_chan)
595static struct ioat_desc_sw * 636static struct ioat_desc_sw *
596ioat2_dma_get_next_descriptor(struct ioat_dma_chan *ioat_chan) 637ioat2_dma_get_next_descriptor(struct ioat_dma_chan *ioat_chan)
597{ 638{
598 struct ioat_desc_sw *new = NULL; 639 struct ioat_desc_sw *new;
599 640
600 /* 641 /*
601 * used.prev points to where to start processing 642 * used.prev points to where to start processing
@@ -609,8 +650,8 @@ ioat2_dma_get_next_descriptor(struct ioat_dma_chan *ioat_chan)
609 if (ioat_chan->used_desc.prev && 650 if (ioat_chan->used_desc.prev &&
610 ioat_chan->used_desc.next == ioat_chan->used_desc.prev->prev) { 651 ioat_chan->used_desc.next == ioat_chan->used_desc.prev->prev) {
611 652
612 struct ioat_desc_sw *desc = NULL; 653 struct ioat_desc_sw *desc;
613 struct ioat_desc_sw *noop_desc = NULL; 654 struct ioat_desc_sw *noop_desc;
614 int i; 655 int i;
615 656
616 /* set up the noop descriptor */ 657 /* set up the noop descriptor */
@@ -624,10 +665,14 @@ ioat2_dma_get_next_descriptor(struct ioat_dma_chan *ioat_chan)
624 ioat_chan->pending++; 665 ioat_chan->pending++;
625 ioat_chan->dmacount++; 666 ioat_chan->dmacount++;
626 667
627 /* get a few more descriptors */ 668 /* try to get a few more descriptors */
628 for (i = 16; i; i--) { 669 for (i = 16; i; i--) {
629 desc = ioat_dma_alloc_descriptor(ioat_chan, GFP_ATOMIC); 670 desc = ioat_dma_alloc_descriptor(ioat_chan, GFP_ATOMIC);
630 BUG_ON(!desc); 671 if (!desc) {
672 dev_err(&ioat_chan->device->pdev->dev,
673 "alloc failed\n");
674 break;
675 }
631 list_add_tail(&desc->node, ioat_chan->used_desc.next); 676 list_add_tail(&desc->node, ioat_chan->used_desc.next);
632 677
633 desc->hw->next 678 desc->hw->next
@@ -677,10 +722,13 @@ static struct dma_async_tx_descriptor *ioat1_dma_prep_memcpy(
677 722
678 spin_lock_bh(&ioat_chan->desc_lock); 723 spin_lock_bh(&ioat_chan->desc_lock);
679 new = ioat_dma_get_next_descriptor(ioat_chan); 724 new = ioat_dma_get_next_descriptor(ioat_chan);
680 new->len = len;
681 spin_unlock_bh(&ioat_chan->desc_lock); 725 spin_unlock_bh(&ioat_chan->desc_lock);
682 726
683 return new ? &new->async_tx : NULL; 727 if (new) {
728 new->len = len;
729 return &new->async_tx;
730 } else
731 return NULL;
684} 732}
685 733
686static struct dma_async_tx_descriptor *ioat2_dma_prep_memcpy( 734static struct dma_async_tx_descriptor *ioat2_dma_prep_memcpy(
@@ -693,53 +741,17 @@ static struct dma_async_tx_descriptor *ioat2_dma_prep_memcpy(
693 741
694 spin_lock_bh(&ioat_chan->desc_lock); 742 spin_lock_bh(&ioat_chan->desc_lock);
695 new = ioat2_dma_get_next_descriptor(ioat_chan); 743 new = ioat2_dma_get_next_descriptor(ioat_chan);
696 new->len = len;
697
698 /* leave ioat_chan->desc_lock set in version 2 path */
699 return new ? &new->async_tx : NULL;
700}
701 744
745 /*
746 * leave ioat_chan->desc_lock set in ioat 2 path
747 * it will get unlocked at end of tx_submit
748 */
702 749
703/** 750 if (new) {
704 * ioat_dma_memcpy_issue_pending - push potentially unrecognized appended 751 new->len = len;
705 * descriptors to hw 752 return &new->async_tx;
706 * @chan: DMA channel handle 753 } else
707 */ 754 return NULL;
708static inline void __ioat1_dma_memcpy_issue_pending(
709 struct ioat_dma_chan *ioat_chan)
710{
711 ioat_chan->pending = 0;
712 writeb(IOAT_CHANCMD_APPEND, ioat_chan->reg_base + IOAT1_CHANCMD_OFFSET);
713}
714
715static void ioat1_dma_memcpy_issue_pending(struct dma_chan *chan)
716{
717 struct ioat_dma_chan *ioat_chan = to_ioat_chan(chan);
718
719 if (ioat_chan->pending != 0) {
720 spin_lock_bh(&ioat_chan->desc_lock);
721 __ioat1_dma_memcpy_issue_pending(ioat_chan);
722 spin_unlock_bh(&ioat_chan->desc_lock);
723 }
724}
725
726static inline void __ioat2_dma_memcpy_issue_pending(
727 struct ioat_dma_chan *ioat_chan)
728{
729 ioat_chan->pending = 0;
730 writew(ioat_chan->dmacount,
731 ioat_chan->reg_base + IOAT_CHAN_DMACOUNT_OFFSET);
732}
733
734static void ioat2_dma_memcpy_issue_pending(struct dma_chan *chan)
735{
736 struct ioat_dma_chan *ioat_chan = to_ioat_chan(chan);
737
738 if (ioat_chan->pending != 0) {
739 spin_lock_bh(&ioat_chan->desc_lock);
740 __ioat2_dma_memcpy_issue_pending(ioat_chan);
741 spin_unlock_bh(&ioat_chan->desc_lock);
742 }
743} 755}
744 756
745static void ioat_dma_cleanup_tasklet(unsigned long data) 757static void ioat_dma_cleanup_tasklet(unsigned long data)
@@ -1019,7 +1031,7 @@ static void ioat_dma_start_null_desc(struct ioat_dma_chan *ioat_chan)
1019static void ioat_dma_test_callback(void *dma_async_param) 1031static void ioat_dma_test_callback(void *dma_async_param)
1020{ 1032{
1021 printk(KERN_ERR "ioatdma: ioat_dma_test_callback(%p)\n", 1033 printk(KERN_ERR "ioatdma: ioat_dma_test_callback(%p)\n",
1022 dma_async_param); 1034 dma_async_param);
1023} 1035}
1024 1036
1025/** 1037/**
@@ -1032,7 +1044,7 @@ static int ioat_dma_self_test(struct ioatdma_device *device)
1032 u8 *src; 1044 u8 *src;
1033 u8 *dest; 1045 u8 *dest;
1034 struct dma_chan *dma_chan; 1046 struct dma_chan *dma_chan;
1035 struct dma_async_tx_descriptor *tx = NULL; 1047 struct dma_async_tx_descriptor *tx;
1036 dma_addr_t addr; 1048 dma_addr_t addr;
1037 dma_cookie_t cookie; 1049 dma_cookie_t cookie;
1038 int err = 0; 1050 int err = 0;
@@ -1351,7 +1363,7 @@ err_completion_pool:
1351err_dma_pool: 1363err_dma_pool:
1352 kfree(device); 1364 kfree(device);
1353err_kzalloc: 1365err_kzalloc:
1354 dev_err(&device->pdev->dev, 1366 dev_err(&pdev->dev,
1355 "Intel(R) I/OAT DMA Engine initialization failed\n"); 1367 "Intel(R) I/OAT DMA Engine initialization failed\n");
1356 return NULL; 1368 return NULL;
1357} 1369}
diff --git a/drivers/dma/ioatdma.h b/drivers/dma/ioatdma.h
index b668234ef654..f2c7fedbf009 100644
--- a/drivers/dma/ioatdma.h
+++ b/drivers/dma/ioatdma.h
@@ -76,7 +76,7 @@ struct ioat_dma_chan {
76 dma_cookie_t completed_cookie; 76 dma_cookie_t completed_cookie;
77 unsigned long last_completion; 77 unsigned long last_completion;
78 78
79 u32 xfercap; /* XFERCAP register value expanded out */ 79 size_t xfercap; /* XFERCAP register value expanded out */
80 80
81 spinlock_t cleanup_lock; 81 spinlock_t cleanup_lock;
82 spinlock_t desc_lock; 82 spinlock_t desc_lock;
diff --git a/drivers/firewire/fw-ohci.c b/drivers/firewire/fw-ohci.c
index c9b9081831da..436a855a4c60 100644
--- a/drivers/firewire/fw-ohci.c
+++ b/drivers/firewire/fw-ohci.c
@@ -437,6 +437,21 @@ static void ar_context_run(struct ar_context *ctx)
437 flush_writes(ctx->ohci); 437 flush_writes(ctx->ohci);
438} 438}
439 439
440static struct descriptor *
441find_branch_descriptor(struct descriptor *d, int z)
442{
443 int b, key;
444
445 b = (le16_to_cpu(d->control) & DESCRIPTOR_BRANCH_ALWAYS) >> 2;
446 key = (le16_to_cpu(d->control) & DESCRIPTOR_KEY_IMMEDIATE) >> 8;
447
448 /* figure out which descriptor the branch address goes in */
449 if (z == 2 && (b == 3 || key == 2))
450 return d;
451 else
452 return d + z - 1;
453}
454
440static void context_tasklet(unsigned long data) 455static void context_tasklet(unsigned long data)
441{ 456{
442 struct context *ctx = (struct context *) data; 457 struct context *ctx = (struct context *) data;
@@ -455,7 +470,7 @@ static void context_tasklet(unsigned long data)
455 address = le32_to_cpu(last->branch_address); 470 address = le32_to_cpu(last->branch_address);
456 z = address & 0xf; 471 z = address & 0xf;
457 d = ctx->buffer + (address - ctx->buffer_bus) / sizeof(*d); 472 d = ctx->buffer + (address - ctx->buffer_bus) / sizeof(*d);
458 last = (z == 2) ? d : d + z - 1; 473 last = find_branch_descriptor(d, z);
459 474
460 if (!ctx->callback(ctx, d, last)) 475 if (!ctx->callback(ctx, d, last))
461 break; 476 break;
@@ -566,7 +581,7 @@ static void context_append(struct context *ctx,
566 581
567 ctx->head_descriptor = d + z + extra; 582 ctx->head_descriptor = d + z + extra;
568 ctx->prev_descriptor->branch_address = cpu_to_le32(d_bus | z); 583 ctx->prev_descriptor->branch_address = cpu_to_le32(d_bus | z);
569 ctx->prev_descriptor = z == 2 ? d : d + z - 1; 584 ctx->prev_descriptor = find_branch_descriptor(d, z);
570 585
571 dma_sync_single_for_device(ctx->ohci->card.device, ctx->buffer_bus, 586 dma_sync_single_for_device(ctx->ohci->card.device, ctx->buffer_bus,
572 ctx->buffer_size, DMA_TO_DEVICE); 587 ctx->buffer_size, DMA_TO_DEVICE);
@@ -655,7 +670,7 @@ at_context_queue_packet(struct context *ctx, struct fw_packet *packet)
655 driver_data = (struct driver_data *) &d[3]; 670 driver_data = (struct driver_data *) &d[3];
656 driver_data->packet = packet; 671 driver_data->packet = packet;
657 packet->driver_data = driver_data; 672 packet->driver_data = driver_data;
658 673
659 if (packet->payload_length > 0) { 674 if (packet->payload_length > 0) {
660 payload_bus = 675 payload_bus =
661 dma_map_single(ohci->card.device, packet->payload, 676 dma_map_single(ohci->card.device, packet->payload,
@@ -903,7 +918,7 @@ at_context_transmit(struct context *ctx, struct fw_packet *packet)
903 918
904 if (retval < 0) 919 if (retval < 0)
905 packet->callback(packet, &ctx->ohci->card, packet->ack); 920 packet->callback(packet, &ctx->ohci->card, packet->ack);
906 921
907} 922}
908 923
909static void bus_reset_tasklet(unsigned long data) 924static void bus_reset_tasklet(unsigned long data)
@@ -1431,6 +1446,57 @@ static int handle_ir_dualbuffer_packet(struct context *context,
1431 return 1; 1446 return 1;
1432} 1447}
1433 1448
1449static int handle_ir_packet_per_buffer(struct context *context,
1450 struct descriptor *d,
1451 struct descriptor *last)
1452{
1453 struct iso_context *ctx =
1454 container_of(context, struct iso_context, context);
1455 struct descriptor *pd = d + 1;
1456 __le32 *ir_header;
1457 size_t header_length;
1458 void *p, *end;
1459 int i, z;
1460
1461 if (pd->res_count == pd->req_count)
1462 /* Descriptor(s) not done yet, stop iteration */
1463 return 0;
1464
1465 header_length = le16_to_cpu(d->req_count);
1466
1467 i = ctx->header_length;
1468 z = le32_to_cpu(pd->branch_address) & 0xf;
1469 p = d + z;
1470 end = p + header_length;
1471
1472 while (p < end && i + ctx->base.header_size <= PAGE_SIZE) {
1473 /*
1474 * The iso header is byteswapped to little endian by
1475 * the controller, but the remaining header quadlets
1476 * are big endian. We want to present all the headers
1477 * as big endian, so we have to swap the first quadlet.
1478 */
1479 *(u32 *) (ctx->header + i) = __swab32(*(u32 *) (p + 4));
1480 memcpy(ctx->header + i + 4, p + 8, ctx->base.header_size - 4);
1481 i += ctx->base.header_size;
1482 p += ctx->base.header_size + 4;
1483 }
1484
1485 ctx->header_length = i;
1486
1487 if (le16_to_cpu(pd->control) & DESCRIPTOR_IRQ_ALWAYS) {
1488 ir_header = (__le32 *) (d + z);
1489 ctx->base.callback(&ctx->base,
1490 le32_to_cpu(ir_header[0]) & 0xffff,
1491 ctx->header_length, ctx->header,
1492 ctx->base.callback_data);
1493 ctx->header_length = 0;
1494 }
1495
1496
1497 return 1;
1498}
1499
1434static int handle_it_packet(struct context *context, 1500static int handle_it_packet(struct context *context,
1435 struct descriptor *d, 1501 struct descriptor *d,
1436 struct descriptor *last) 1502 struct descriptor *last)
@@ -1466,14 +1532,12 @@ ohci_allocate_iso_context(struct fw_card *card, int type, size_t header_size)
1466 } else { 1532 } else {
1467 mask = &ohci->ir_context_mask; 1533 mask = &ohci->ir_context_mask;
1468 list = ohci->ir_context_list; 1534 list = ohci->ir_context_list;
1469 callback = handle_ir_dualbuffer_packet; 1535 if (ohci->version >= OHCI_VERSION_1_1)
1536 callback = handle_ir_dualbuffer_packet;
1537 else
1538 callback = handle_ir_packet_per_buffer;
1470 } 1539 }
1471 1540
1472 /* FIXME: We need a fallback for pre 1.1 OHCI. */
1473 if (callback == handle_ir_dualbuffer_packet &&
1474 ohci->version < OHCI_VERSION_1_1)
1475 return ERR_PTR(-ENOSYS);
1476
1477 spin_lock_irqsave(&ohci->lock, flags); 1541 spin_lock_irqsave(&ohci->lock, flags);
1478 index = ffs(*mask) - 1; 1542 index = ffs(*mask) - 1;
1479 if (index >= 0) 1543 if (index >= 0)
@@ -1532,7 +1596,9 @@ static int ohci_start_iso(struct fw_iso_context *base,
1532 context_run(&ctx->context, match); 1596 context_run(&ctx->context, match);
1533 } else { 1597 } else {
1534 index = ctx - ohci->ir_context_list; 1598 index = ctx - ohci->ir_context_list;
1535 control = IR_CONTEXT_DUAL_BUFFER_MODE | IR_CONTEXT_ISOCH_HEADER; 1599 control = IR_CONTEXT_ISOCH_HEADER;
1600 if (ohci->version >= OHCI_VERSION_1_1)
1601 control |= IR_CONTEXT_DUAL_BUFFER_MODE;
1536 match = (tags << 28) | (sync << 8) | ctx->base.channel; 1602 match = (tags << 28) | (sync << 8) | ctx->base.channel;
1537 if (cycle >= 0) { 1603 if (cycle >= 0) {
1538 match |= (cycle & 0x07fff) << 12; 1604 match |= (cycle & 0x07fff) << 12;
@@ -1738,7 +1804,6 @@ ohci_queue_iso_receive_dualbuffer(struct fw_iso_context *base,
1738 offset = payload & ~PAGE_MASK; 1804 offset = payload & ~PAGE_MASK;
1739 rest = p->payload_length; 1805 rest = p->payload_length;
1740 1806
1741 /* FIXME: OHCI 1.0 doesn't support dual buffer receive */
1742 /* FIXME: make packet-per-buffer/dual-buffer a context option */ 1807 /* FIXME: make packet-per-buffer/dual-buffer a context option */
1743 while (rest > 0) { 1808 while (rest > 0) {
1744 d = context_get_descriptors(&ctx->context, 1809 d = context_get_descriptors(&ctx->context,
@@ -1777,6 +1842,81 @@ ohci_queue_iso_receive_dualbuffer(struct fw_iso_context *base,
1777} 1842}
1778 1843
1779static int 1844static int
1845ohci_queue_iso_receive_packet_per_buffer(struct fw_iso_context *base,
1846 struct fw_iso_packet *packet,
1847 struct fw_iso_buffer *buffer,
1848 unsigned long payload)
1849{
1850 struct iso_context *ctx = container_of(base, struct iso_context, base);
1851 struct descriptor *d = NULL, *pd = NULL;
1852 struct fw_iso_packet *p;
1853 dma_addr_t d_bus, page_bus;
1854 u32 z, header_z, rest;
1855 int i, page, offset, packet_count, header_size;
1856
1857 if (packet->skip) {
1858 d = context_get_descriptors(&ctx->context, 1, &d_bus);
1859 if (d == NULL)
1860 return -ENOMEM;
1861
1862 d->control = cpu_to_le16(DESCRIPTOR_STATUS |
1863 DESCRIPTOR_INPUT_LAST |
1864 DESCRIPTOR_BRANCH_ALWAYS |
1865 DESCRIPTOR_WAIT);
1866 context_append(&ctx->context, d, 1, 0);
1867 }
1868
1869 /* one descriptor for header, one for payload */
1870 /* FIXME: handle cases where we need multiple desc. for payload */
1871 z = 2;
1872 p = packet;
1873
1874 /*
1875 * The OHCI controller puts the status word in the
1876 * buffer too, so we need 4 extra bytes per packet.
1877 */
1878 packet_count = p->header_length / ctx->base.header_size;
1879 header_size = packet_count * (ctx->base.header_size + 4);
1880
1881 /* Get header size in number of descriptors. */
1882 header_z = DIV_ROUND_UP(header_size, sizeof(*d));
1883 page = payload >> PAGE_SHIFT;
1884 offset = payload & ~PAGE_MASK;
1885 rest = p->payload_length;
1886
1887 for (i = 0; i < packet_count; i++) {
1888 /* d points to the header descriptor */
1889 d = context_get_descriptors(&ctx->context,
1890 z + header_z, &d_bus);
1891 if (d == NULL)
1892 return -ENOMEM;
1893
1894 d->control = cpu_to_le16(DESCRIPTOR_INPUT_MORE);
1895 d->req_count = cpu_to_le16(header_size);
1896 d->res_count = d->req_count;
1897 d->data_address = cpu_to_le32(d_bus + (z * sizeof(*d)));
1898
1899 /* pd points to the payload descriptor */
1900 pd = d + 1;
1901 pd->control = cpu_to_le16(DESCRIPTOR_STATUS |
1902 DESCRIPTOR_INPUT_LAST |
1903 DESCRIPTOR_BRANCH_ALWAYS);
1904 if (p->interrupt)
1905 pd->control |= cpu_to_le16(DESCRIPTOR_IRQ_ALWAYS);
1906
1907 pd->req_count = cpu_to_le16(rest);
1908 pd->res_count = pd->req_count;
1909
1910 page_bus = page_private(buffer->pages[page]);
1911 pd->data_address = cpu_to_le32(page_bus + offset);
1912
1913 context_append(&ctx->context, d, z, header_z);
1914 }
1915
1916 return 0;
1917}
1918
1919static int
1780ohci_queue_iso(struct fw_iso_context *base, 1920ohci_queue_iso(struct fw_iso_context *base,
1781 struct fw_iso_packet *packet, 1921 struct fw_iso_packet *packet,
1782 struct fw_iso_buffer *buffer, 1922 struct fw_iso_buffer *buffer,
@@ -1790,8 +1930,9 @@ ohci_queue_iso(struct fw_iso_context *base,
1790 return ohci_queue_iso_receive_dualbuffer(base, packet, 1930 return ohci_queue_iso_receive_dualbuffer(base, packet,
1791 buffer, payload); 1931 buffer, payload);
1792 else 1932 else
1793 /* FIXME: Implement fallback for OHCI 1.0 controllers. */ 1933 return ohci_queue_iso_receive_packet_per_buffer(base, packet,
1794 return -ENOSYS; 1934 buffer,
1935 payload);
1795} 1936}
1796 1937
1797static const struct fw_card_driver ohci_driver = { 1938static const struct fw_card_driver ohci_driver = {
@@ -1911,12 +2052,6 @@ pci_probe(struct pci_dev *dev, const struct pci_device_id *ent)
1911 ohci->version = reg_read(ohci, OHCI1394_Version) & 0x00ff00ff; 2052 ohci->version = reg_read(ohci, OHCI1394_Version) & 0x00ff00ff;
1912 fw_notify("Added fw-ohci device %s, OHCI version %x.%x\n", 2053 fw_notify("Added fw-ohci device %s, OHCI version %x.%x\n",
1913 dev->dev.bus_id, ohci->version >> 16, ohci->version & 0xff); 2054 dev->dev.bus_id, ohci->version >> 16, ohci->version & 0xff);
1914 if (ohci->version < OHCI_VERSION_1_1) {
1915 fw_notify(" Isochronous I/O is not yet implemented for "
1916 "OHCI 1.0 chips.\n");
1917 fw_notify(" Cameras, audio devices etc. won't work on "
1918 "this controller with this driver version.\n");
1919 }
1920 return 0; 2055 return 0;
1921 2056
1922 fail_self_id: 2057 fail_self_id:
diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
index 5c82ec7f8bbd..3ee60d26e3a2 100644
--- a/drivers/hwmon/coretemp.c
+++ b/drivers/hwmon/coretemp.c
@@ -337,11 +337,10 @@ static int coretemp_cpu_callback(struct notifier_block *nfb,
337 337
338 switch (action) { 338 switch (action) {
339 case CPU_ONLINE: 339 case CPU_ONLINE:
340 case CPU_ONLINE_FROZEN: 340 case CPU_DOWN_FAILED:
341 coretemp_device_add(cpu); 341 coretemp_device_add(cpu);
342 break; 342 break;
343 case CPU_DEAD: 343 case CPU_DOWN_PREPARE:
344 case CPU_DEAD_FROZEN:
345 coretemp_device_remove(cpu); 344 coretemp_device_remove(cpu);
346 break; 345 break;
347 } 346 }
diff --git a/drivers/i2c/busses/i2c-davinci.c b/drivers/i2c/busses/i2c-davinci.c
index bd7aaff35240..67679882ebef 100644
--- a/drivers/i2c/busses/i2c-davinci.c
+++ b/drivers/i2c/busses/i2c-davinci.c
@@ -404,7 +404,7 @@ static irqreturn_t i2c_davinci_isr(int this_irq, void *dev_id)
404 DAVINCI_I2C_STR_REG, 404 DAVINCI_I2C_STR_REG,
405 w); 405 w);
406 } else 406 } else
407 dev_err(dev->dev, "RDR IRQ while no" 407 dev_err(dev->dev, "RDR IRQ while no "
408 "data requested\n"); 408 "data requested\n");
409 break; 409 break;
410 410
@@ -423,7 +423,7 @@ static irqreturn_t i2c_davinci_isr(int this_irq, void *dev_id)
423 DAVINCI_I2C_IMR_REG, 423 DAVINCI_I2C_IMR_REG,
424 w); 424 w);
425 } else 425 } else
426 dev_err(dev->dev, "TDR IRQ while no data to" 426 dev_err(dev->dev, "TDR IRQ while no data to "
427 "send\n"); 427 "send\n");
428 break; 428 break;
429 429
diff --git a/drivers/i2c/busses/i2c-gpio.c b/drivers/i2c/busses/i2c-gpio.c
index 44e1cd21bb01..3ca19fc234fb 100644
--- a/drivers/i2c/busses/i2c-gpio.c
+++ b/drivers/i2c/busses/i2c-gpio.c
@@ -140,6 +140,7 @@ static int __init i2c_gpio_probe(struct platform_device *pdev)
140 adap->owner = THIS_MODULE; 140 adap->owner = THIS_MODULE;
141 snprintf(adap->name, sizeof(adap->name), "i2c-gpio%d", pdev->id); 141 snprintf(adap->name, sizeof(adap->name), "i2c-gpio%d", pdev->id);
142 adap->algo_data = bit_data; 142 adap->algo_data = bit_data;
143 adap->class = I2C_CLASS_HWMON;
143 adap->dev.parent = &pdev->dev; 144 adap->dev.parent = &pdev->dev;
144 145
145 /* 146 /*
diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c
index 89a30028ddb6..cb55cf2ba1e9 100644
--- a/drivers/i2c/busses/i2c-omap.c
+++ b/drivers/i2c/busses/i2c-omap.c
@@ -203,7 +203,7 @@ static int omap_i2c_init(struct omap_i2c_dev *dev)
203 while (!(omap_i2c_read_reg(dev, OMAP_I2C_SYSS_REG) & 203 while (!(omap_i2c_read_reg(dev, OMAP_I2C_SYSS_REG) &
204 OMAP_I2C_SYSS_RDONE)) { 204 OMAP_I2C_SYSS_RDONE)) {
205 if (time_after(jiffies, timeout)) { 205 if (time_after(jiffies, timeout)) {
206 dev_warn(dev->dev, "timeout waiting" 206 dev_warn(dev->dev, "timeout waiting "
207 "for controller reset\n"); 207 "for controller reset\n");
208 return -ETIMEDOUT; 208 return -ETIMEDOUT;
209 } 209 }
@@ -483,7 +483,7 @@ omap_i2c_isr(int this_irq, void *dev_id)
483 dev->buf_len--; 483 dev->buf_len--;
484 } 484 }
485 } else 485 } else
486 dev_err(dev->dev, "RRDY IRQ while no data" 486 dev_err(dev->dev, "RRDY IRQ while no data "
487 "requested\n"); 487 "requested\n");
488 omap_i2c_ack_stat(dev, OMAP_I2C_STAT_RRDY); 488 omap_i2c_ack_stat(dev, OMAP_I2C_STAT_RRDY);
489 continue; 489 continue;
@@ -498,7 +498,7 @@ omap_i2c_isr(int this_irq, void *dev_id)
498 dev->buf_len--; 498 dev->buf_len--;
499 } 499 }
500 } else 500 } else
501 dev_err(dev->dev, "XRDY IRQ while no" 501 dev_err(dev->dev, "XRDY IRQ while no "
502 "data to send\n"); 502 "data to send\n");
503 omap_i2c_write_reg(dev, OMAP_I2C_DATA_REG, w); 503 omap_i2c_write_reg(dev, OMAP_I2C_DATA_REG, w);
504 omap_i2c_ack_stat(dev, OMAP_I2C_STAT_XRDY); 504 omap_i2c_ack_stat(dev, OMAP_I2C_STAT_XRDY);
diff --git a/drivers/i2c/chips/isp1301_omap.c b/drivers/i2c/chips/isp1301_omap.c
index fe04e46991aa..b767603a07ba 100644
--- a/drivers/i2c/chips/isp1301_omap.c
+++ b/drivers/i2c/chips/isp1301_omap.c
@@ -26,7 +26,7 @@
26#include <linux/interrupt.h> 26#include <linux/interrupt.h>
27#include <linux/platform_device.h> 27#include <linux/platform_device.h>
28#include <linux/usb/ch9.h> 28#include <linux/usb/ch9.h>
29#include <linux/usb_gadget.h> 29#include <linux/usb/gadget.h>
30#include <linux/usb.h> 30#include <linux/usb.h>
31#include <linux/usb/otg.h> 31#include <linux/usb/otg.h>
32#include <linux/i2c.h> 32#include <linux/i2c.h>
diff --git a/drivers/ide/Kconfig b/drivers/ide/Kconfig
index e445fe6e4ba9..fb06555708a8 100644
--- a/drivers/ide/Kconfig
+++ b/drivers/ide/Kconfig
@@ -313,7 +313,6 @@ comment "IDE chipset support/bugfixes"
313 313
314config IDE_GENERIC 314config IDE_GENERIC
315 tristate "generic/default IDE chipset support" 315 tristate "generic/default IDE chipset support"
316 default H8300
317 help 316 help
318 If unsure, say N. 317 If unsure, say N.
319 318
@@ -391,7 +390,7 @@ config IDEPCI_PCIBUS_ORDER
391 390
392# TODO: split it on per host driver config options (or module parameters) 391# TODO: split it on per host driver config options (or module parameters)
393config BLK_DEV_OFFBOARD 392config BLK_DEV_OFFBOARD
394 bool "Boot off-board chipsets first support" 393 bool "Boot off-board chipsets first support (DEPRECATED)"
395 depends on BLK_DEV_IDEPCI && (BLK_DEV_AEC62XX || BLK_DEV_GENERIC || BLK_DEV_HPT34X || BLK_DEV_HPT366 || BLK_DEV_PDC202XX_NEW || BLK_DEV_PDC202XX_OLD || BLK_DEV_TC86C001) 394 depends on BLK_DEV_IDEPCI && (BLK_DEV_AEC62XX || BLK_DEV_GENERIC || BLK_DEV_HPT34X || BLK_DEV_HPT366 || BLK_DEV_PDC202XX_NEW || BLK_DEV_PDC202XX_OLD || BLK_DEV_TC86C001)
396 help 395 help
397 Normally, IDE controllers built into the motherboard (on-board 396 Normally, IDE controllers built into the motherboard (on-board
@@ -411,6 +410,10 @@ config BLK_DEV_OFFBOARD
411 Note that, if you do this, the order of the hd* devices will be 410 Note that, if you do this, the order of the hd* devices will be
412 rearranged which may require modification of fstab and other files. 411 rearranged which may require modification of fstab and other files.
413 412
413 Please also note that this method of assuring stable naming of
414 IDE devices is unreliable and use other means for achieving it
415 (i.e. udev).
416
414 If in doubt, say N. 417 If in doubt, say N.
415 418
416config BLK_DEV_GENERIC 419config BLK_DEV_GENERIC
@@ -484,6 +487,7 @@ config WDC_ALI15X3
484 487
485config BLK_DEV_AMD74XX 488config BLK_DEV_AMD74XX
486 tristate "AMD and nVidia IDE support" 489 tristate "AMD and nVidia IDE support"
490 depends on !ARM
487 select BLK_DEV_IDEDMA_PCI 491 select BLK_DEV_IDEDMA_PCI
488 help 492 help
489 This driver adds explicit support for AMD-7xx and AMD-8111 chips 493 This driver adds explicit support for AMD-7xx and AMD-8111 chips
@@ -883,6 +887,49 @@ config BLK_DEV_IDE_BAST
883 Say Y here if you want to support the onboard IDE channels on the 887 Say Y here if you want to support the onboard IDE channels on the
884 Simtec BAST or the Thorcom VR1000 888 Simtec BAST or the Thorcom VR1000
885 889
890config ETRAX_IDE
891 bool "ETRAX IDE support"
892 depends on CRIS && BROKEN
893 select BLK_DEV_IDEDMA
894 select IDE_GENERIC
895 help
896 Enables the ETRAX IDE driver.
897
898 You can't use parallel ports or SCSI ports at the same time.
899
900config ETRAX_IDE_DELAY
901 int "Delay for drives to regain consciousness"
902 depends on ETRAX_IDE && ETRAX_ARCH_V10
903 default 15
904 help
905 Number of seconds to wait for IDE drives to spin up after an IDE
906 reset.
907
908choice
909 prompt "IDE reset pin"
910 depends on ETRAX_IDE && ETRAX_ARCH_V10
911 default ETRAX_IDE_PB7_RESET
912
913config ETRAX_IDE_PB7_RESET
914 bool "Port_PB_Bit_7"
915 help
916 IDE reset on pin 7 on port B
917
918config ETRAX_IDE_G27_RESET
919 bool "Port_G_Bit_27"
920 help
921 IDE reset on pin 27 on port G
922
923endchoice
924
925config IDE_H8300
926 bool "H8300 IDE support"
927 depends on H8300
928 select IDE_GENERIC
929 default y
930 help
931 Enables the H8300 IDE driver.
932
886config BLK_DEV_GAYLE 933config BLK_DEV_GAYLE
887 bool "Amiga Gayle IDE interface support" 934 bool "Amiga Gayle IDE interface support"
888 depends on AMIGA 935 depends on AMIGA
@@ -963,7 +1010,7 @@ config BLK_DEV_Q40IDE
963 1010
964config BLK_DEV_MPC8xx_IDE 1011config BLK_DEV_MPC8xx_IDE
965 bool "MPC8xx IDE support" 1012 bool "MPC8xx IDE support"
966 depends on 8xx && IDE=y && BLK_DEV_IDE=y && !PPC_MERGE 1013 depends on 8xx && (LWMON || IVMS8 || IVML24 || TQM8xxL) && IDE=y && BLK_DEV_IDE=y && !PPC_MERGE
967 select IDE_GENERIC 1014 select IDE_GENERIC
968 help 1015 help
969 This option provides support for IDE on Motorola MPC8xx Systems. 1016 This option provides support for IDE on Motorola MPC8xx Systems.
diff --git a/drivers/ide/Makefile b/drivers/ide/Makefile
index 75dc6969e0a7..b181fc672057 100644
--- a/drivers/ide/Makefile
+++ b/drivers/ide/Makefile
@@ -39,7 +39,7 @@ ide-core-$(CONFIG_BLK_DEV_MPC8xx_IDE) += ppc/mpc8xx.o
39ide-core-$(CONFIG_BLK_DEV_IDE_PMAC) += ppc/pmac.o 39ide-core-$(CONFIG_BLK_DEV_IDE_PMAC) += ppc/pmac.o
40 40
41# built-in only drivers from h8300/ 41# built-in only drivers from h8300/
42ide-core-$(CONFIG_H8300) += h8300/ide-h8300.o 42ide-core-$(CONFIG_IDE_H8300) += h8300/ide-h8300.o
43 43
44obj-$(CONFIG_BLK_DEV_IDE) += ide-core.o 44obj-$(CONFIG_BLK_DEV_IDE) += ide-core.o
45obj-$(CONFIG_IDE_GENERIC) += ide-generic.o 45obj-$(CONFIG_IDE_GENERIC) += ide-generic.o
diff --git a/drivers/ide/cris/ide-cris.c b/drivers/ide/cris/ide-cris.c
index 7f5bc2ee6c7e..476e0d65ed43 100644
--- a/drivers/ide/cris/ide-cris.c
+++ b/drivers/ide/cris/ide-cris.c
@@ -773,15 +773,16 @@ init_e100_ide (void)
773 /* the IDE control register is at ATA address 6, with CS1 active instead of CS0 */ 773 /* the IDE control register is at ATA address 6, with CS1 active instead of CS0 */
774 ide_offsets[IDE_CONTROL_OFFSET] = cris_ide_reg_addr(6, 1, 0); 774 ide_offsets[IDE_CONTROL_OFFSET] = cris_ide_reg_addr(6, 1, 0);
775 775
776 /* first fill in some stuff in the ide_hwifs fields */ 776 for (h = 0; h < 4; h++) {
777 ide_hwif_t *hwif = NULL;
777 778
778 for(h = 0; h < MAX_HWIFS; h++) {
779 ide_hwif_t *hwif = &ide_hwifs[h];
780 ide_setup_ports(&hw, cris_ide_base_address(h), 779 ide_setup_ports(&hw, cris_ide_base_address(h),
781 ide_offsets, 780 ide_offsets,
782 0, 0, cris_ide_ack_intr, 781 0, 0, cris_ide_ack_intr,
783 ide_default_irq(0)); 782 ide_default_irq(0));
784 ide_register_hw(&hw, NULL, 1, &hwif); 783 ide_register_hw(&hw, NULL, 1, &hwif);
784 if (hwif == NULL)
785 continue;
785 hwif->mmio = 1; 786 hwif->mmio = 1;
786 hwif->chipset = ide_etrax100; 787 hwif->chipset = ide_etrax100;
787 hwif->set_pio_mode = &cris_set_pio_mode; 788 hwif->set_pio_mode = &cris_set_pio_mode;
diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
index 57a5f63d6ae3..c7d77f0ad892 100644
--- a/drivers/ide/ide-cd.c
+++ b/drivers/ide/ide-cd.c
@@ -1068,8 +1068,8 @@ int cdrom_read_check_ireason (ide_drive_t *drive, int len, int ireason)
1068 return 0; 1068 return 0;
1069 else if (ireason == 0) { 1069 else if (ireason == 0) {
1070 /* Whoops... The drive is expecting to receive data from us! */ 1070 /* Whoops... The drive is expecting to receive data from us! */
1071 printk(KERN_ERR "%s: read_intr: Drive wants to transfer data the " 1071 printk(KERN_ERR "%s: %s: wrong transfer direction!\n",
1072 "wrong way!\n", drive->name); 1072 drive->name, __FUNCTION__);
1073 1073
1074 /* Throw some data at the drive so it doesn't hang 1074 /* Throw some data at the drive so it doesn't hang
1075 and quit this request. */ 1075 and quit this request. */
@@ -1086,8 +1086,8 @@ int cdrom_read_check_ireason (ide_drive_t *drive, int len, int ireason)
1086 return 0; 1086 return 0;
1087 } else { 1087 } else {
1088 /* Drive wants a command packet, or invalid ireason... */ 1088 /* Drive wants a command packet, or invalid ireason... */
1089 printk(KERN_ERR "%s: read_intr: bad interrupt reason %x\n", drive->name, 1089 printk(KERN_ERR "%s: %s: bad interrupt reason 0x%02x\n",
1090 ireason); 1090 drive->name, __FUNCTION__, ireason);
1091 } 1091 }
1092 1092
1093 cdrom_end_request(drive, 0); 1093 cdrom_end_request(drive, 0);
@@ -1112,8 +1112,11 @@ static ide_startstop_t cdrom_read_intr (ide_drive_t *drive)
1112 */ 1112 */
1113 if (dma) { 1113 if (dma) {
1114 info->dma = 0; 1114 info->dma = 0;
1115 if ((dma_error = HWIF(drive)->ide_dma_end(drive))) 1115 dma_error = HWIF(drive)->ide_dma_end(drive);
1116 if (dma_error) {
1117 printk(KERN_ERR "%s: DMA read error\n", drive->name);
1116 ide_dma_off(drive); 1118 ide_dma_off(drive);
1119 }
1117 } 1120 }
1118 1121
1119 if (cdrom_decode_status(drive, 0, &stat)) 1122 if (cdrom_decode_status(drive, 0, &stat))
@@ -1443,7 +1446,7 @@ static ide_startstop_t cdrom_pc_intr (ide_drive_t *drive)
1443 return ide_stopped; 1446 return ide_stopped;
1444 1447
1445 /* Read the interrupt reason and the transfer length. */ 1448 /* Read the interrupt reason and the transfer length. */
1446 ireason = HWIF(drive)->INB(IDE_IREASON_REG); 1449 ireason = HWIF(drive)->INB(IDE_IREASON_REG) & 0x3;
1447 lowcyl = HWIF(drive)->INB(IDE_BCOUNTL_REG); 1450 lowcyl = HWIF(drive)->INB(IDE_BCOUNTL_REG);
1448 highcyl = HWIF(drive)->INB(IDE_BCOUNTH_REG); 1451 highcyl = HWIF(drive)->INB(IDE_BCOUNTH_REG);
1449 1452
@@ -1484,7 +1487,7 @@ static ide_startstop_t cdrom_pc_intr (ide_drive_t *drive)
1484 if (thislen > len) thislen = len; 1487 if (thislen > len) thislen = len;
1485 1488
1486 /* The drive wants to be written to. */ 1489 /* The drive wants to be written to. */
1487 if ((ireason & 3) == 0) { 1490 if (ireason == 0) {
1488 if (!rq->data) { 1491 if (!rq->data) {
1489 blk_dump_rq_flags(rq, "cdrom_pc_intr, write"); 1492 blk_dump_rq_flags(rq, "cdrom_pc_intr, write");
1490 goto confused; 1493 goto confused;
@@ -1506,9 +1509,9 @@ static ide_startstop_t cdrom_pc_intr (ide_drive_t *drive)
1506 } 1509 }
1507 1510
1508 /* Same drill for reading. */ 1511 /* Same drill for reading. */
1509 else if ((ireason & 3) == 2) { 1512 else if (ireason == 2) {
1510 if (!rq->data) { 1513 if (!rq->data) {
1511 blk_dump_rq_flags(rq, "cdrom_pc_intr, write"); 1514 blk_dump_rq_flags(rq, "cdrom_pc_intr, read");
1512 goto confused; 1515 goto confused;
1513 } 1516 }
1514 /* Transfer the data. */ 1517 /* Transfer the data. */
@@ -1632,8 +1635,8 @@ static int cdrom_write_check_ireason(ide_drive_t *drive, int len, int ireason)
1632 return 0; 1635 return 0;
1633 else if (ireason == 2) { 1636 else if (ireason == 2) {
1634 /* Whoops... The drive wants to send data. */ 1637 /* Whoops... The drive wants to send data. */
1635 printk(KERN_ERR "%s: write_intr: wrong transfer direction!\n", 1638 printk(KERN_ERR "%s: %s: wrong transfer direction!\n",
1636 drive->name); 1639 drive->name, __FUNCTION__);
1637 1640
1638 while (len > 0) { 1641 while (len > 0) {
1639 int dum = 0; 1642 int dum = 0;
@@ -1642,39 +1645,14 @@ static int cdrom_write_check_ireason(ide_drive_t *drive, int len, int ireason)
1642 } 1645 }
1643 } else { 1646 } else {
1644 /* Drive wants a command packet, or invalid ireason... */ 1647 /* Drive wants a command packet, or invalid ireason... */
1645 printk(KERN_ERR "%s: write_intr: bad interrupt reason %x\n", 1648 printk(KERN_ERR "%s: %s: bad interrupt reason 0x%02x\n",
1646 drive->name, ireason); 1649 drive->name, __FUNCTION__, ireason);
1647 } 1650 }
1648 1651
1649 cdrom_end_request(drive, 0); 1652 cdrom_end_request(drive, 0);
1650 return 1; 1653 return 1;
1651} 1654}
1652 1655
1653static void post_transform_command(struct request *req)
1654{
1655 u8 *c = req->cmd;
1656 char *ibuf;
1657
1658 if (!blk_pc_request(req))
1659 return;
1660
1661 if (req->bio)
1662 ibuf = bio_data(req->bio);
1663 else
1664 ibuf = req->data;
1665
1666 if (!ibuf)
1667 return;
1668
1669 /*
1670 * set ansi-revision and response data as atapi
1671 */
1672 if (c[0] == GPCMD_INQUIRY) {
1673 ibuf[2] |= 2;
1674 ibuf[3] = (ibuf[3] & 0xf0) | 2;
1675 }
1676}
1677
1678typedef void (xfer_func_t)(ide_drive_t *, void *, u32); 1656typedef void (xfer_func_t)(ide_drive_t *, void *, u32);
1679 1657
1680/* 1658/*
@@ -1810,9 +1788,6 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
1810 return ide_started; 1788 return ide_started;
1811 1789
1812end_request: 1790end_request:
1813 if (!rq->data_len)
1814 post_transform_command(rq);
1815
1816 spin_lock_irqsave(&ide_lock, flags); 1791 spin_lock_irqsave(&ide_lock, flags);
1817 blkdev_dequeue_request(rq); 1792 blkdev_dequeue_request(rq);
1818 end_that_request_last(rq, 1); 1793 end_that_request_last(rq, 1);
@@ -1833,8 +1808,9 @@ static ide_startstop_t cdrom_write_intr(ide_drive_t *drive)
1833 /* Check for errors. */ 1808 /* Check for errors. */
1834 if (dma) { 1809 if (dma) {
1835 info->dma = 0; 1810 info->dma = 0;
1836 if ((dma_error = HWIF(drive)->ide_dma_end(drive))) { 1811 dma_error = HWIF(drive)->ide_dma_end(drive);
1837 printk(KERN_ERR "ide-cd: write dma error\n"); 1812 if (dma_error) {
1813 printk(KERN_ERR "%s: DMA write error\n", drive->name);
1838 ide_dma_off(drive); 1814 ide_dma_off(drive);
1839 } 1815 }
1840 } 1816 }
@@ -1854,7 +1830,7 @@ static ide_startstop_t cdrom_write_intr(ide_drive_t *drive)
1854 } 1830 }
1855 1831
1856 /* Read the interrupt reason and the transfer length. */ 1832 /* Read the interrupt reason and the transfer length. */
1857 ireason = HWIF(drive)->INB(IDE_IREASON_REG); 1833 ireason = HWIF(drive)->INB(IDE_IREASON_REG) & 0x3;
1858 lowcyl = HWIF(drive)->INB(IDE_BCOUNTL_REG); 1834 lowcyl = HWIF(drive)->INB(IDE_BCOUNTL_REG);
1859 highcyl = HWIF(drive)->INB(IDE_BCOUNTH_REG); 1835 highcyl = HWIF(drive)->INB(IDE_BCOUNTH_REG);
1860 1836
@@ -1867,8 +1843,9 @@ static ide_startstop_t cdrom_write_intr(ide_drive_t *drive)
1867 */ 1843 */
1868 uptodate = 1; 1844 uptodate = 1;
1869 if (rq->current_nr_sectors > 0) { 1845 if (rq->current_nr_sectors > 0) {
1870 printk(KERN_ERR "%s: write_intr: data underrun (%d blocks)\n", 1846 printk(KERN_ERR "%s: %s: data underrun (%d blocks)\n",
1871 drive->name, rq->current_nr_sectors); 1847 drive->name, __FUNCTION__,
1848 rq->current_nr_sectors);
1872 uptodate = 0; 1849 uptodate = 0;
1873 } 1850 }
1874 cdrom_end_request(drive, uptodate); 1851 cdrom_end_request(drive, uptodate);
@@ -1888,7 +1865,8 @@ static ide_startstop_t cdrom_write_intr(ide_drive_t *drive)
1888 int this_transfer; 1865 int this_transfer;
1889 1866
1890 if (!rq->current_nr_sectors) { 1867 if (!rq->current_nr_sectors) {
1891 printk(KERN_ERR "ide-cd: write_intr: oops\n"); 1868 printk(KERN_ERR "%s: %s: confused, missing data\n",
1869 drive->name, __FUNCTION__);
1892 break; 1870 break;
1893 } 1871 }
1894 1872
@@ -2716,14 +2694,14 @@ void ide_cdrom_update_speed (ide_drive_t *drive, struct atapi_capabilities_page
2716 if (!drive->id->model[0] && 2694 if (!drive->id->model[0] &&
2717 !strncmp(drive->id->fw_rev, "241N", 4)) { 2695 !strncmp(drive->id->fw_rev, "241N", 4)) {
2718 CDROM_STATE_FLAGS(drive)->current_speed = 2696 CDROM_STATE_FLAGS(drive)->current_speed =
2719 (((unsigned int)cap->curspeed) + (176/2)) / 176; 2697 (le16_to_cpu(cap->curspeed) + (176/2)) / 176;
2720 CDROM_CONFIG_FLAGS(drive)->max_speed = 2698 CDROM_CONFIG_FLAGS(drive)->max_speed =
2721 (((unsigned int)cap->maxspeed) + (176/2)) / 176; 2699 (le16_to_cpu(cap->maxspeed) + (176/2)) / 176;
2722 } else { 2700 } else {
2723 CDROM_STATE_FLAGS(drive)->current_speed = 2701 CDROM_STATE_FLAGS(drive)->current_speed =
2724 (ntohs(cap->curspeed) + (176/2)) / 176; 2702 (be16_to_cpu(cap->curspeed) + (176/2)) / 176;
2725 CDROM_CONFIG_FLAGS(drive)->max_speed = 2703 CDROM_CONFIG_FLAGS(drive)->max_speed =
2726 (ntohs(cap->maxspeed) + (176/2)) / 176; 2704 (be16_to_cpu(cap->maxspeed) + (176/2)) / 176;
2727 } 2705 }
2728} 2706}
2729 2707
@@ -2937,6 +2915,9 @@ static int ide_cdrom_register (ide_drive_t *drive, int nslots)
2937 if (!CDROM_CONFIG_FLAGS(drive)->ram) 2915 if (!CDROM_CONFIG_FLAGS(drive)->ram)
2938 devinfo->mask |= CDC_RAM; 2916 devinfo->mask |= CDC_RAM;
2939 2917
2918 if (CDROM_CONFIG_FLAGS(drive)->no_speed_select)
2919 devinfo->mask |= CDC_SELECT_SPEED;
2920
2940 devinfo->disk = info->disk; 2921 devinfo->disk = info->disk;
2941 return register_cdrom(devinfo); 2922 return register_cdrom(devinfo);
2942} 2923}
@@ -3049,12 +3030,7 @@ int ide_cdrom_probe_capabilities (ide_drive_t *drive)
3049 else 3030 else
3050 printk(" drive"); 3031 printk(" drive");
3051 3032
3052 printk(", %dkB Cache", be16_to_cpu(cap.buffer_size)); 3033 printk(KERN_CONT ", %dkB Cache\n", be16_to_cpu(cap.buffer_size));
3053
3054 if (drive->using_dma)
3055 ide_dma_verbose(drive);
3056
3057 printk("\n");
3058 3034
3059 return nslots; 3035 return nslots;
3060} 3036}
@@ -3194,7 +3170,7 @@ int ide_cdrom_setup (ide_drive_t *drive)
3194 CDROM_CONFIG_FLAGS(drive)->limit_nframes = 1; 3170 CDROM_CONFIG_FLAGS(drive)->limit_nframes = 1;
3195 /* the 3231 model does not support the SET_CD_SPEED command */ 3171 /* the 3231 model does not support the SET_CD_SPEED command */
3196 else if (!strcmp(drive->id->model, "SAMSUNG CD-ROM SCR-3231")) 3172 else if (!strcmp(drive->id->model, "SAMSUNG CD-ROM SCR-3231"))
3197 cdi->mask |= CDC_SELECT_SPEED; 3173 CDROM_CONFIG_FLAGS(drive)->no_speed_select = 1;
3198 3174
3199#if ! STANDARD_ATAPI 3175#if ! STANDARD_ATAPI
3200 /* by default Sanyo 3 CD changer support is turned off and 3176 /* by default Sanyo 3 CD changer support is turned off and
@@ -3537,15 +3513,8 @@ static int ide_cd_probe(ide_drive_t *drive)
3537 g->driverfs_dev = &drive->gendev; 3513 g->driverfs_dev = &drive->gendev;
3538 g->flags = GENHD_FL_CD | GENHD_FL_REMOVABLE; 3514 g->flags = GENHD_FL_CD | GENHD_FL_REMOVABLE;
3539 if (ide_cdrom_setup(drive)) { 3515 if (ide_cdrom_setup(drive)) {
3540 struct cdrom_device_info *devinfo = &info->devinfo;
3541 ide_proc_unregister_driver(drive, &ide_cdrom_driver); 3516 ide_proc_unregister_driver(drive, &ide_cdrom_driver);
3542 kfree(info->buffer); 3517 ide_cd_release(&info->kref);
3543 kfree(info->toc);
3544 kfree(info->changer_info);
3545 if (devinfo->handle == drive && unregister_cdrom(devinfo))
3546 printk (KERN_ERR "%s: ide_cdrom_cleanup failed to unregister device from the cdrom driver.\n", drive->name);
3547 kfree(info);
3548 drive->driver_data = NULL;
3549 goto failed; 3518 goto failed;
3550 } 3519 }
3551 3520
diff --git a/drivers/ide/ide-cd.h b/drivers/ide/ide-cd.h
index 228b29c5d2e4..1b302fe2724d 100644
--- a/drivers/ide/ide-cd.h
+++ b/drivers/ide/ide-cd.h
@@ -91,7 +91,8 @@ struct ide_cd_config_flags {
91 __u8 close_tray : 1; /* can close the tray */ 91 __u8 close_tray : 1; /* can close the tray */
92 __u8 writing : 1; /* pseudo write in progress */ 92 __u8 writing : 1; /* pseudo write in progress */
93 __u8 mo_drive : 1; /* drive is an MO device */ 93 __u8 mo_drive : 1; /* drive is an MO device */
94 __u8 reserved : 2; 94 __u8 no_speed_select : 1; /* SET_CD_SPEED command is unsupported. */
95 __u8 reserved : 1;
95 byte max_speed; /* Max speed of the drive */ 96 byte max_speed; /* Max speed of the drive */
96}; 97};
97#define CDROM_CONFIG_FLAGS(drive) (&(((struct cdrom_info *)(drive->driver_data))->config_flags)) 98#define CDROM_CONFIG_FLAGS(drive) (&(((struct cdrom_info *)(drive->driver_data))->config_flags))
diff --git a/drivers/ide/ide-disk.c b/drivers/ide/ide-disk.c
index 00123d99527a..b1781908e1f2 100644
--- a/drivers/ide/ide-disk.c
+++ b/drivers/ide/ide-disk.c
@@ -13,32 +13,6 @@
13 * and Andre Hedrick <andre@linux-ide.org> 13 * and Andre Hedrick <andre@linux-ide.org>
14 * 14 *
15 * This is the IDE/ATA disk driver, as evolved from hd.c and ide.c. 15 * This is the IDE/ATA disk driver, as evolved from hd.c and ide.c.
16 *
17 * Version 1.00 move disk only code from ide.c to ide-disk.c
18 * support optional byte-swapping of all data
19 * Version 1.01 fix previous byte-swapping code
20 * Version 1.02 remove ", LBA" from drive identification msgs
21 * Version 1.03 fix display of id->buf_size for big-endian
22 * Version 1.04 add /proc configurable settings and S.M.A.R.T support
23 * Version 1.05 add capacity support for ATA3 >= 8GB
24 * Version 1.06 get boot-up messages to show full cyl count
25 * Version 1.07 disable door-locking if it fails
26 * Version 1.08 fixed CHS/LBA translations for ATA4 > 8GB,
27 * process of adding new ATA4 compliance.
28 * fixed problems in allowing fdisk to see
29 * the entire disk.
30 * Version 1.09 added increment of rq->sector in ide_multwrite
31 * added UDMA 3/4 reporting
32 * Version 1.10 request queue changes, Ultra DMA 100
33 * Version 1.11 added 48-bit lba
34 * Version 1.12 adding taskfile io access method
35 * Version 1.13 added standby and flush-cache for notifier
36 * Version 1.14 added acoustic-wcache
37 * Version 1.15 convert all calls to ide_raw_taskfile
38 * since args will return register content.
39 * Version 1.16 added suspend-resume-checkpower
40 * Version 1.17 do flush on standby, do flush on ATA < ATA6
41 * fix wcache setup.
42 */ 16 */
43 17
44#define IDEDISK_VERSION "1.18" 18#define IDEDISK_VERSION "1.18"
@@ -961,11 +935,8 @@ static void idedisk_setup (ide_drive_t *drive)
961 if (id->buf_size) 935 if (id->buf_size)
962 printk (" w/%dKiB Cache", id->buf_size/2); 936 printk (" w/%dKiB Cache", id->buf_size/2);
963 937
964 printk(", CHS=%d/%d/%d", 938 printk(KERN_CONT ", CHS=%d/%d/%d\n",
965 drive->bios_cyl, drive->bios_head, drive->bios_sect); 939 drive->bios_cyl, drive->bios_head, drive->bios_sect);
966 if (drive->using_dma)
967 ide_dma_verbose(drive);
968 printk("\n");
969 940
970 /* write cache enabled? */ 941 /* write cache enabled? */
971 if ((id->csfo & 1) || (id->cfs_enable_1 & (1 << 5))) 942 if ((id->csfo & 1) || (id->cfs_enable_1 & (1 << 5)))
diff --git a/drivers/ide/ide-dma.c b/drivers/ide/ide-dma.c
index e3add70b9cd8..4703837bf1fc 100644
--- a/drivers/ide/ide-dma.c
+++ b/drivers/ide/ide-dma.c
@@ -130,6 +130,7 @@ static const struct drive_list_entry drive_blacklist [] = {
130 { "_NEC DV5800A", NULL }, 130 { "_NEC DV5800A", NULL },
131 { "SAMSUNG CD-ROM SN-124", "N001" }, 131 { "SAMSUNG CD-ROM SN-124", "N001" },
132 { "Seagate STT20000A", NULL }, 132 { "Seagate STT20000A", NULL },
133 { "CD-ROM CDR_U200", "1.09" },
133 { NULL , NULL } 134 { NULL , NULL }
134 135
135}; 136};
@@ -610,12 +611,6 @@ static int __ide_dma_test_irq(ide_drive_t *drive)
610 ide_hwif_t *hwif = HWIF(drive); 611 ide_hwif_t *hwif = HWIF(drive);
611 u8 dma_stat = hwif->INB(hwif->dma_status); 612 u8 dma_stat = hwif->INB(hwif->dma_status);
612 613
613#if 0 /* do not set unless you know what you are doing */
614 if (dma_stat & 4) {
615 u8 stat = hwif->INB(IDE_STATUS_REG);
616 hwif->OUTB(hwif->dma_status, dma_stat & 0xE4);
617 }
618#endif
619 /* return 1 if INTR asserted */ 614 /* return 1 if INTR asserted */
620 if ((dma_stat & 4) == 4) 615 if ((dma_stat & 4) == 4)
621 return 1; 616 return 1;
@@ -752,10 +747,12 @@ u8 ide_find_dma_mode(ide_drive_t *drive, u8 req_mode)
752 mode = XFER_MW_DMA_1; 747 mode = XFER_MW_DMA_1;
753 } 748 }
754 749
755 printk(KERN_DEBUG "%s: %s mode selected\n", drive->name, 750 mode = min(mode, req_mode);
751
752 printk(KERN_INFO "%s: %s mode selected\n", drive->name,
756 mode ? ide_xfer_verbose(mode) : "no DMA"); 753 mode ? ide_xfer_verbose(mode) : "no DMA");
757 754
758 return min(mode, req_mode); 755 return mode;
759} 756}
760 757
761EXPORT_SYMBOL_GPL(ide_find_dma_mode); 758EXPORT_SYMBOL_GPL(ide_find_dma_mode);
@@ -771,6 +768,9 @@ static int ide_tune_dma(ide_drive_t *drive)
771 if (__ide_dma_bad_drive(drive)) 768 if (__ide_dma_bad_drive(drive))
772 return 0; 769 return 0;
773 770
771 if (ide_id_dma_bug(drive))
772 return 0;
773
774 if (drive->hwif->host_flags & IDE_HFLAG_TRUST_BIOS_FOR_DMA) 774 if (drive->hwif->host_flags & IDE_HFLAG_TRUST_BIOS_FOR_DMA)
775 return config_drive_for_dma(drive); 775 return config_drive_for_dma(drive);
776 776
@@ -805,58 +805,23 @@ static int ide_dma_check(ide_drive_t *drive)
805 return vdma ? 0 : -1; 805 return vdma ? 0 : -1;
806} 806}
807 807
808void ide_dma_verbose(ide_drive_t *drive) 808int ide_id_dma_bug(ide_drive_t *drive)
809{ 809{
810 struct hd_driveid *id = drive->id; 810 struct hd_driveid *id = drive->id;
811 ide_hwif_t *hwif = HWIF(drive);
812 811
813 if (id->field_valid & 4) { 812 if (id->field_valid & 4) {
814 if ((id->dma_ultra >> 8) && (id->dma_mword >> 8)) 813 if ((id->dma_ultra >> 8) && (id->dma_mword >> 8))
815 goto bug_dma_off; 814 goto err_out;
816 if (id->dma_ultra & ((id->dma_ultra >> 8) & hwif->ultra_mask)) {
817 if (((id->dma_ultra >> 11) & 0x1F) &&
818 eighty_ninty_three(drive)) {
819 if ((id->dma_ultra >> 15) & 1) {
820 printk(", UDMA(mode 7)");
821 } else if ((id->dma_ultra >> 14) & 1) {
822 printk(", UDMA(133)");
823 } else if ((id->dma_ultra >> 13) & 1) {
824 printk(", UDMA(100)");
825 } else if ((id->dma_ultra >> 12) & 1) {
826 printk(", UDMA(66)");
827 } else if ((id->dma_ultra >> 11) & 1) {
828 printk(", UDMA(44)");
829 } else
830 goto mode_two;
831 } else {
832 mode_two:
833 if ((id->dma_ultra >> 10) & 1) {
834 printk(", UDMA(33)");
835 } else if ((id->dma_ultra >> 9) & 1) {
836 printk(", UDMA(25)");
837 } else if ((id->dma_ultra >> 8) & 1) {
838 printk(", UDMA(16)");
839 }
840 }
841 } else {
842 printk(", (U)DMA"); /* Can be BIOS-enabled! */
843 }
844 } else if (id->field_valid & 2) { 815 } else if (id->field_valid & 2) {
845 if ((id->dma_mword >> 8) && (id->dma_1word >> 8)) 816 if ((id->dma_mword >> 8) && (id->dma_1word >> 8))
846 goto bug_dma_off; 817 goto err_out;
847 printk(", DMA");
848 } else if (id->field_valid & 1) {
849 goto bug_dma_off;
850 } 818 }
851 return; 819 return 0;
852bug_dma_off: 820err_out:
853 printk(", BUG DMA OFF"); 821 printk(KERN_ERR "%s: bad DMA info in identify block\n", drive->name);
854 hwif->dma_off_quietly(drive); 822 return 1;
855 return;
856} 823}
857 824
858EXPORT_SYMBOL(ide_dma_verbose);
859
860int ide_set_dma(ide_drive_t *drive) 825int ide_set_dma(ide_drive_t *drive)
861{ 826{
862 ide_hwif_t *hwif = drive->hwif; 827 ide_hwif_t *hwif = drive->hwif;
diff --git a/drivers/ide/ide-io.c b/drivers/ide/ide-io.c
index db22d1ff4e55..bef781fec500 100644
--- a/drivers/ide/ide-io.c
+++ b/drivers/ide/ide-io.c
@@ -970,7 +970,8 @@ static void ide_check_pm_state(ide_drive_t *drive, struct request *rq)
970 if (rc) 970 if (rc)
971 printk(KERN_WARNING "%s: bus not ready on wakeup\n", drive->name); 971 printk(KERN_WARNING "%s: bus not ready on wakeup\n", drive->name);
972 SELECT_DRIVE(drive); 972 SELECT_DRIVE(drive);
973 HWIF(drive)->OUTB(8, HWIF(drive)->io_ports[IDE_CONTROL_OFFSET]); 973 if (IDE_CONTROL_REG)
974 HWIF(drive)->OUTB(drive->ctl, IDE_CONTROL_REG);
974 rc = ide_wait_not_busy(HWIF(drive), 100000); 975 rc = ide_wait_not_busy(HWIF(drive), 100000);
975 if (rc) 976 if (rc)
976 printk(KERN_WARNING "%s: drive not ready on wakeup\n", drive->name); 977 printk(KERN_WARNING "%s: drive not ready on wakeup\n", drive->name);
diff --git a/drivers/ide/ide-iops.c b/drivers/ide/ide-iops.c
index e17a9ee120ea..cef405ddaf0e 100644
--- a/drivers/ide/ide-iops.c
+++ b/drivers/ide/ide-iops.c
@@ -303,9 +303,6 @@ void default_hwif_transport(ide_hwif_t *hwif)
303 hwif->atapi_output_bytes = atapi_output_bytes; 303 hwif->atapi_output_bytes = atapi_output_bytes;
304} 304}
305 305
306/*
307 * Beginning of Taskfile OPCODE Library and feature sets.
308 */
309void ide_fix_driveid (struct hd_driveid *id) 306void ide_fix_driveid (struct hd_driveid *id)
310{ 307{
311#ifndef __LITTLE_ENDIAN 308#ifndef __LITTLE_ENDIAN
@@ -592,6 +589,9 @@ EXPORT_SYMBOL_GPL(ide_in_drive_list);
592static const struct drive_list_entry ivb_list[] = { 589static const struct drive_list_entry ivb_list[] = {
593 { "QUANTUM FIREBALLlct10 05" , "A03.0900" }, 590 { "QUANTUM FIREBALLlct10 05" , "A03.0900" },
594 { "TSSTcorp CDDVDW SH-S202J" , "SB00" }, 591 { "TSSTcorp CDDVDW SH-S202J" , "SB00" },
592 { "TSSTcorp CDDVDW SH-S202J" , "SB01" },
593 { "TSSTcorp CDDVDW SH-S202N" , "SB00" },
594 { "TSSTcorp CDDVDW SH-S202N" , "SB01" },
595 { NULL , NULL } 595 { NULL , NULL }
596}; 596};
597 597
@@ -748,6 +748,9 @@ int ide_driveid_update(ide_drive_t *drive)
748 drive->id->dma_1word = id->dma_1word; 748 drive->id->dma_1word = id->dma_1word;
749 /* anything more ? */ 749 /* anything more ? */
750 kfree(id); 750 kfree(id);
751
752 if (drive->using_dma && ide_id_dma_bug(drive))
753 ide_dma_off(drive);
751 } 754 }
752 755
753 return 1; 756 return 1;
@@ -756,7 +759,7 @@ int ide_driveid_update(ide_drive_t *drive)
756int ide_config_drive_speed(ide_drive_t *drive, u8 speed) 759int ide_config_drive_speed(ide_drive_t *drive, u8 speed)
757{ 760{
758 ide_hwif_t *hwif = drive->hwif; 761 ide_hwif_t *hwif = drive->hwif;
759 int error; 762 int error = 0;
760 u8 stat; 763 u8 stat;
761 764
762// while (HWGROUP(drive)->busy) 765// while (HWGROUP(drive)->busy)
@@ -767,6 +770,10 @@ int ide_config_drive_speed(ide_drive_t *drive, u8 speed)
767 hwif->dma_host_off(drive); 770 hwif->dma_host_off(drive);
768#endif 771#endif
769 772
773 /* Skip setting PIO flow-control modes on pre-EIDE drives */
774 if ((speed & 0xf8) == XFER_PIO_0 && !(drive->id->capability & 0x08))
775 goto skip;
776
770 /* 777 /*
771 * Don't use ide_wait_cmd here - it will 778 * Don't use ide_wait_cmd here - it will
772 * attempt to set_geometry and recalibrate, 779 * attempt to set_geometry and recalibrate,
@@ -814,6 +821,7 @@ int ide_config_drive_speed(ide_drive_t *drive, u8 speed)
814 drive->id->dma_mword &= ~0x0F00; 821 drive->id->dma_mword &= ~0x0F00;
815 drive->id->dma_1word &= ~0x0F00; 822 drive->id->dma_1word &= ~0x0F00;
816 823
824 skip:
817#ifdef CONFIG_BLK_DEV_IDEDMA 825#ifdef CONFIG_BLK_DEV_IDEDMA
818 if (speed >= XFER_SW_DMA_0) 826 if (speed >= XFER_SW_DMA_0)
819 hwif->dma_host_on(drive); 827 hwif->dma_host_on(drive);
diff --git a/drivers/ide/ide-lib.c b/drivers/ide/ide-lib.c
index 1609b8604f56..062d3bcb2471 100644
--- a/drivers/ide/ide-lib.c
+++ b/drivers/ide/ide-lib.c
@@ -29,41 +29,44 @@
29 * Add common non I/O op stuff here. Make sure it has proper 29 * Add common non I/O op stuff here. Make sure it has proper
30 * kernel-doc function headers or your patch will be rejected 30 * kernel-doc function headers or your patch will be rejected
31 */ 31 */
32 32
33static const char *udma_str[] =
34 { "UDMA/16", "UDMA/25", "UDMA/33", "UDMA/44",
35 "UDMA/66", "UDMA/100", "UDMA/133", "UDMA7" };
36static const char *mwdma_str[] =
37 { "MWDMA0", "MWDMA1", "MWDMA2" };
38static const char *swdma_str[] =
39 { "SWDMA0", "SWDMA1", "SWDMA2" };
40static const char *pio_str[] =
41 { "PIO0", "PIO1", "PIO2", "PIO3", "PIO4", "PIO5" };
33 42
34/** 43/**
35 * ide_xfer_verbose - return IDE mode names 44 * ide_xfer_verbose - return IDE mode names
36 * @xfer_rate: rate to name 45 * @mode: transfer mode
37 * 46 *
38 * Returns a constant string giving the name of the mode 47 * Returns a constant string giving the name of the mode
39 * requested. 48 * requested.
40 */ 49 */
41 50
42char *ide_xfer_verbose (u8 xfer_rate) 51const char *ide_xfer_verbose(u8 mode)
43{ 52{
44 switch(xfer_rate) { 53 const char *s;
45 case XFER_UDMA_7: return("UDMA 7"); 54 u8 i = mode & 0xf;
46 case XFER_UDMA_6: return("UDMA 6"); 55
47 case XFER_UDMA_5: return("UDMA 5"); 56 if (mode >= XFER_UDMA_0 && mode <= XFER_UDMA_7)
48 case XFER_UDMA_4: return("UDMA 4"); 57 s = udma_str[i];
49 case XFER_UDMA_3: return("UDMA 3"); 58 else if (mode >= XFER_MW_DMA_0 && mode <= XFER_MW_DMA_2)
50 case XFER_UDMA_2: return("UDMA 2"); 59 s = mwdma_str[i];
51 case XFER_UDMA_1: return("UDMA 1"); 60 else if (mode >= XFER_SW_DMA_0 && mode <= XFER_SW_DMA_2)
52 case XFER_UDMA_0: return("UDMA 0"); 61 s = swdma_str[i];
53 case XFER_MW_DMA_2: return("MW DMA 2"); 62 else if (mode >= XFER_PIO_0 && mode <= XFER_PIO_5)
54 case XFER_MW_DMA_1: return("MW DMA 1"); 63 s = pio_str[i & 0x7];
55 case XFER_MW_DMA_0: return("MW DMA 0"); 64 else if (mode == XFER_PIO_SLOW)
56 case XFER_SW_DMA_2: return("SW DMA 2"); 65 s = "PIO SLOW";
57 case XFER_SW_DMA_1: return("SW DMA 1"); 66 else
58 case XFER_SW_DMA_0: return("SW DMA 0"); 67 s = "XFER ERROR";
59 case XFER_PIO_4: return("PIO 4"); 68
60 case XFER_PIO_3: return("PIO 3"); 69 return s;
61 case XFER_PIO_2: return("PIO 2");
62 case XFER_PIO_1: return("PIO 1");
63 case XFER_PIO_0: return("PIO 0");
64 case XFER_PIO_SLOW: return("PIO SLOW");
65 default: return("XFER ERROR");
66 }
67} 70}
68 71
69EXPORT_SYMBOL(ide_xfer_verbose); 72EXPORT_SYMBOL(ide_xfer_verbose);
diff --git a/drivers/ide/ide-probe.c b/drivers/ide/ide-probe.c
index 56fb0b843429..2994523be7bf 100644
--- a/drivers/ide/ide-probe.c
+++ b/drivers/ide/ide-probe.c
@@ -13,22 +13,8 @@
13 * 13 *
14 * This is the IDE probe module, as evolved from hd.c and ide.c. 14 * This is the IDE probe module, as evolved from hd.c and ide.c.
15 * 15 *
16 * Version 1.00 move drive probing code from ide.c to ide-probe.c 16 * -- increase WAIT_PIDENTIFY to avoid CD-ROM locking at boot
17 * Version 1.01 fix compilation problem for m68k 17 * by Andrea Arcangeli
18 * Version 1.02 increase WAIT_PIDENTIFY to avoid CD-ROM locking at boot
19 * by Andrea Arcangeli
20 * Version 1.03 fix for (hwif->chipset == ide_4drives)
21 * Version 1.04 fixed buggy treatments of known flash memory cards
22 *
23 * Version 1.05 fix for (hwif->chipset == ide_pdc4030)
24 * added ide6/7/8/9
25 * allowed for secondary flash card to be detectable
26 * with new flag : drive->ata_flash : 1;
27 * Version 1.06 stream line request queue and prep for cascade project.
28 * Version 1.07 max_sect <= 255; slower disks would get behind and
29 * then fall over when they get to 256. Paul G.
30 * Version 1.10 Update set for new IDE. drive->id is now always
31 * valid after probe time even with noprobe
32 */ 18 */
33 19
34#include <linux/module.h> 20#include <linux/module.h>
@@ -644,7 +630,7 @@ static void hwif_register (ide_hwif_t *hwif)
644 630
645static int wait_hwif_ready(ide_hwif_t *hwif) 631static int wait_hwif_ready(ide_hwif_t *hwif)
646{ 632{
647 int rc; 633 int unit, rc;
648 634
649 printk(KERN_DEBUG "Probing IDE interface %s...\n", hwif->name); 635 printk(KERN_DEBUG "Probing IDE interface %s...\n", hwif->name);
650 636
@@ -661,20 +647,27 @@ static int wait_hwif_ready(ide_hwif_t *hwif)
661 return rc; 647 return rc;
662 648
663 /* Now make sure both master & slave are ready */ 649 /* Now make sure both master & slave are ready */
664 SELECT_DRIVE(&hwif->drives[0]); 650 for (unit = 0; unit < MAX_DRIVES; unit++) {
665 hwif->OUTB(8, hwif->io_ports[IDE_CONTROL_OFFSET]); 651 ide_drive_t *drive = &hwif->drives[unit];
666 mdelay(2);
667 rc = ide_wait_not_busy(hwif, 35000);
668 if (rc)
669 return rc;
670 SELECT_DRIVE(&hwif->drives[1]);
671 hwif->OUTB(8, hwif->io_ports[IDE_CONTROL_OFFSET]);
672 mdelay(2);
673 rc = ide_wait_not_busy(hwif, 35000);
674 652
653 /* Ignore disks that we will not probe for later. */
654 if (!drive->noprobe || drive->present) {
655 SELECT_DRIVE(drive);
656 if (IDE_CONTROL_REG)
657 hwif->OUTB(drive->ctl, IDE_CONTROL_REG);
658 mdelay(2);
659 rc = ide_wait_not_busy(hwif, 35000);
660 if (rc)
661 goto out;
662 } else
663 printk(KERN_DEBUG "%s: ide_wait_not_busy() skipped\n",
664 drive->name);
665 }
666out:
675 /* Exit function with master reselected (let's be sane) */ 667 /* Exit function with master reselected (let's be sane) */
676 SELECT_DRIVE(&hwif->drives[0]); 668 if (unit)
677 669 SELECT_DRIVE(&hwif->drives[0]);
670
678 return rc; 671 return rc;
679} 672}
680 673
diff --git a/drivers/ide/ide.c b/drivers/ide/ide.c
index 674a65c1a130..54943da6e4e5 100644
--- a/drivers/ide/ide.c
+++ b/drivers/ide/ide.c
@@ -800,11 +800,17 @@ int set_io_32bit(ide_drive_t *drive, int arg)
800 if (arg < 0 || arg > 1 + (SUPPORT_VLB_SYNC << 1)) 800 if (arg < 0 || arg > 1 + (SUPPORT_VLB_SYNC << 1))
801 return -EINVAL; 801 return -EINVAL;
802 802
803 if (ide_spin_wait_hwgroup(drive))
804 return -EBUSY;
805
803 drive->io_32bit = arg; 806 drive->io_32bit = arg;
804#ifdef CONFIG_BLK_DEV_DTC2278 807#ifdef CONFIG_BLK_DEV_DTC2278
805 if (HWIF(drive)->chipset == ide_dtc2278) 808 if (HWIF(drive)->chipset == ide_dtc2278)
806 HWIF(drive)->drives[!drive->select.b.unit].io_32bit = arg; 809 HWIF(drive)->drives[!drive->select.b.unit].io_32bit = arg;
807#endif /* CONFIG_BLK_DEV_DTC2278 */ 810#endif /* CONFIG_BLK_DEV_DTC2278 */
811
812 spin_unlock_irq(&ide_lock);
813
808 return 0; 814 return 0;
809} 815}
810 816
@@ -1670,10 +1676,34 @@ static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
1670 return sprintf(buf, "ide:m-%s\n", media_string(drive)); 1676 return sprintf(buf, "ide:m-%s\n", media_string(drive));
1671} 1677}
1672 1678
1679static ssize_t model_show(struct device *dev, struct device_attribute *attr,
1680 char *buf)
1681{
1682 ide_drive_t *drive = to_ide_device(dev);
1683 return sprintf(buf, "%s\n", drive->id->model);
1684}
1685
1686static ssize_t firmware_show(struct device *dev, struct device_attribute *attr,
1687 char *buf)
1688{
1689 ide_drive_t *drive = to_ide_device(dev);
1690 return sprintf(buf, "%s\n", drive->id->fw_rev);
1691}
1692
1693static ssize_t serial_show(struct device *dev, struct device_attribute *attr,
1694 char *buf)
1695{
1696 ide_drive_t *drive = to_ide_device(dev);
1697 return sprintf(buf, "%s\n", drive->id->serial_no);
1698}
1699
1673static struct device_attribute ide_dev_attrs[] = { 1700static struct device_attribute ide_dev_attrs[] = {
1674 __ATTR_RO(media), 1701 __ATTR_RO(media),
1675 __ATTR_RO(drivename), 1702 __ATTR_RO(drivename),
1676 __ATTR_RO(modalias), 1703 __ATTR_RO(modalias),
1704 __ATTR_RO(model),
1705 __ATTR_RO(firmware),
1706 __ATTR(serial, 0400, serial_show, NULL),
1677 __ATTR_NULL 1707 __ATTR_NULL
1678}; 1708};
1679 1709
diff --git a/drivers/ide/legacy/ali14xx.c b/drivers/ide/legacy/ali14xx.c
index 10311ecc674a..38c3a6d63f30 100644
--- a/drivers/ide/legacy/ali14xx.c
+++ b/drivers/ide/legacy/ali14xx.c
@@ -53,12 +53,13 @@
53 53
54/* port addresses for auto-detection */ 54/* port addresses for auto-detection */
55#define ALI_NUM_PORTS 4 55#define ALI_NUM_PORTS 4
56static int ports[ALI_NUM_PORTS] __initdata = {0x074, 0x0f4, 0x034, 0x0e4}; 56static const int ports[ALI_NUM_PORTS] __initdata =
57 { 0x074, 0x0f4, 0x034, 0x0e4 };
57 58
58/* register initialization data */ 59/* register initialization data */
59typedef struct { u8 reg, data; } RegInitializer; 60typedef struct { u8 reg, data; } RegInitializer;
60 61
61static RegInitializer initData[] __initdata = { 62static const RegInitializer initData[] __initdata = {
62 {0x01, 0x0f}, {0x02, 0x00}, {0x03, 0x00}, {0x04, 0x00}, 63 {0x01, 0x0f}, {0x02, 0x00}, {0x03, 0x00}, {0x04, 0x00},
63 {0x05, 0x00}, {0x06, 0x00}, {0x07, 0x2b}, {0x0a, 0x0f}, 64 {0x05, 0x00}, {0x06, 0x00}, {0x07, 0x2b}, {0x0a, 0x0f},
64 {0x25, 0x00}, {0x26, 0x00}, {0x27, 0x00}, {0x28, 0x00}, 65 {0x25, 0x00}, {0x26, 0x00}, {0x27, 0x00}, {0x28, 0x00},
@@ -177,7 +178,7 @@ static int __init findPort (void)
177 * Initialize controller registers with default values. 178 * Initialize controller registers with default values.
178 */ 179 */
179static int __init initRegisters (void) { 180static int __init initRegisters (void) {
180 RegInitializer *p; 181 const RegInitializer *p;
181 u8 t; 182 u8 t;
182 unsigned long flags; 183 unsigned long flags;
183 184
diff --git a/drivers/ide/legacy/macide.c b/drivers/ide/legacy/macide.c
index e87cd2f16430..5c6aa77c2370 100644
--- a/drivers/ide/legacy/macide.c
+++ b/drivers/ide/legacy/macide.c
@@ -81,7 +81,7 @@ int macide_ack_intr(ide_hwif_t* hwif)
81 * Probe for a Macintosh IDE interface 81 * Probe for a Macintosh IDE interface
82 */ 82 */
83 83
84void macide_init(void) 84void __init macide_init(void)
85{ 85{
86 hw_regs_t hw; 86 hw_regs_t hw;
87 ide_hwif_t *hwif; 87 ide_hwif_t *hwif;
diff --git a/drivers/ide/legacy/q40ide.c b/drivers/ide/legacy/q40ide.c
index a73db1bd482d..6ea46a6723e2 100644
--- a/drivers/ide/legacy/q40ide.c
+++ b/drivers/ide/legacy/q40ide.c
@@ -111,7 +111,7 @@ static const char *q40_ide_names[Q40IDE_NUM_HWIFS]={
111 * Probe for Q40 IDE interfaces 111 * Probe for Q40 IDE interfaces
112 */ 112 */
113 113
114void q40ide_init(void) 114void __init q40ide_init(void)
115{ 115{
116 int i; 116 int i;
117 ide_hwif_t *hwif; 117 ide_hwif_t *hwif;
diff --git a/drivers/ide/pci/aec62xx.c b/drivers/ide/pci/aec62xx.c
index 19ec421f7b9f..44268504ae43 100644
--- a/drivers/ide/pci/aec62xx.c
+++ b/drivers/ide/pci/aec62xx.c
@@ -260,6 +260,11 @@ static int __devinit aec62xx_init_one(struct pci_dev *dev, const struct pci_devi
260{ 260{
261 struct ide_port_info d; 261 struct ide_port_info d;
262 u8 idx = id->driver_data; 262 u8 idx = id->driver_data;
263 int err;
264
265 err = pci_enable_device(dev);
266 if (err)
267 return err;
263 268
264 d = aec62xx_chipsets[idx]; 269 d = aec62xx_chipsets[idx];
265 270
@@ -272,7 +277,11 @@ static int __devinit aec62xx_init_one(struct pci_dev *dev, const struct pci_devi
272 } 277 }
273 } 278 }
274 279
275 return ide_setup_pci_device(dev, &d); 280 err = ide_setup_pci_device(dev, &d);
281 if (err)
282 pci_disable_device(dev);
283
284 return err;
276} 285}
277 286
278static const struct pci_device_id aec62xx_pci_tbl[] = { 287static const struct pci_device_id aec62xx_pci_tbl[] = {
diff --git a/drivers/ide/pci/alim15x3.c b/drivers/ide/pci/alim15x3.c
index a607dd31a64c..ce293936af4b 100644
--- a/drivers/ide/pci/alim15x3.c
+++ b/drivers/ide/pci/alim15x3.c
@@ -603,6 +603,11 @@ static int ali_cable_override(struct pci_dev *pdev)
603 pdev->subsystem_device == 0x10AF) 603 pdev->subsystem_device == 0x10AF)
604 return 1; 604 return 1;
605 605
606 /* Mitac 8317 (Winbook-A) and relatives */
607 if (pdev->subsystem_vendor == 0x1071 &&
608 pdev->subsystem_device == 0x8317)
609 return 1;
610
606 /* Systems by DMI */ 611 /* Systems by DMI */
607 if (dmi_check_system(cable_dmi_table)) 612 if (dmi_check_system(cable_dmi_table))
608 return 1; 613 return 1;
diff --git a/drivers/ide/pci/cmd64x.c b/drivers/ide/pci/cmd64x.c
index 51fca441c294..bc553337b1be 100644
--- a/drivers/ide/pci/cmd64x.c
+++ b/drivers/ide/pci/cmd64x.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * linux/drivers/ide/pci/cmd64x.c Version 1.51 Nov 8, 2007 2 * linux/drivers/ide/pci/cmd64x.c Version 1.52 Dec 24, 2007
3 * 3 *
4 * cmd64x.c: Enable interrupts at initialization time on Ultra/PCI machines. 4 * cmd64x.c: Enable interrupts at initialization time on Ultra/PCI machines.
5 * Due to massive hardware bugs, UltraDMA is only supported 5 * Due to massive hardware bugs, UltraDMA is only supported
@@ -564,6 +564,7 @@ static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
564 .init_chipset = init_chipset_cmd64x, 564 .init_chipset = init_chipset_cmd64x,
565 .init_hwif = init_hwif_cmd64x, 565 .init_hwif = init_hwif_cmd64x,
566 .enablebits = {{0x51,0x04,0x04}, {0x51,0x08,0x08}}, 566 .enablebits = {{0x51,0x04,0x04}, {0x51,0x08,0x08}},
567 .chipset = ide_cmd646,
567 .host_flags = IDE_HFLAG_ABUSE_PREFETCH | IDE_HFLAG_BOOTABLE, 568 .host_flags = IDE_HFLAG_ABUSE_PREFETCH | IDE_HFLAG_BOOTABLE,
568 .pio_mask = ATA_PIO5, 569 .pio_mask = ATA_PIO5,
569 .mwdma_mask = ATA_MWDMA2, 570 .mwdma_mask = ATA_MWDMA2,
@@ -573,7 +574,6 @@ static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
573 .init_chipset = init_chipset_cmd64x, 574 .init_chipset = init_chipset_cmd64x,
574 .init_hwif = init_hwif_cmd64x, 575 .init_hwif = init_hwif_cmd64x,
575 .enablebits = {{0x51,0x04,0x04}, {0x51,0x08,0x08}}, 576 .enablebits = {{0x51,0x04,0x04}, {0x51,0x08,0x08}},
576 .chipset = ide_cmd646,
577 .host_flags = IDE_HFLAG_ABUSE_PREFETCH | IDE_HFLAG_BOOTABLE, 577 .host_flags = IDE_HFLAG_ABUSE_PREFETCH | IDE_HFLAG_BOOTABLE,
578 .pio_mask = ATA_PIO5, 578 .pio_mask = ATA_PIO5,
579 .mwdma_mask = ATA_MWDMA2, 579 .mwdma_mask = ATA_MWDMA2,
diff --git a/drivers/ide/pci/cs5535.c b/drivers/ide/pci/cs5535.c
index 9094916e3780..ddcbeba671e1 100644
--- a/drivers/ide/pci/cs5535.c
+++ b/drivers/ide/pci/cs5535.c
@@ -49,7 +49,7 @@
49#define ATAC_BM0_PRD 0x04 49#define ATAC_BM0_PRD 0x04
50#define CS5535_CABLE_DETECT 0x48 50#define CS5535_CABLE_DETECT 0x48
51 51
52/* Format I PIO settings. We seperate out cmd and data for safer timings */ 52/* Format I PIO settings. We separate out cmd and data for safer timings */
53 53
54static unsigned int cs5535_pio_cmd_timings[5] = 54static unsigned int cs5535_pio_cmd_timings[5] =
55{ 0xF7F4, 0x53F3, 0x13F1, 0x5131, 0x1131 }; 55{ 0xF7F4, 0x53F3, 0x13F1, 0x5131, 0x1131 };
diff --git a/drivers/ide/pci/hpt366.c b/drivers/ide/pci/hpt366.c
index 5682895d36d9..9fce25bdec8a 100644
--- a/drivers/ide/pci/hpt366.c
+++ b/drivers/ide/pci/hpt366.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * linux/drivers/ide/pci/hpt366.c Version 1.21 Oct 23, 2007 2 * linux/drivers/ide/pci/hpt366.c Version 1.22 Dec 4, 2007
3 * 3 *
4 * Copyright (C) 1999-2003 Andre Hedrick <andre@linux-ide.org> 4 * Copyright (C) 1999-2003 Andre Hedrick <andre@linux-ide.org>
5 * Portions Copyright (C) 2001 Sun Microsystems, Inc. 5 * Portions Copyright (C) 2001 Sun Microsystems, Inc.
@@ -310,6 +310,8 @@ static u32 twenty_five_base_hpt36x[] = {
310 /* XFER_PIO_0 */ 0xc0d08585 310 /* XFER_PIO_0 */ 0xc0d08585
311}; 311};
312 312
313#if 0
314/* These are the timing tables from the HighPoint open source drivers... */
313static u32 thirty_three_base_hpt37x[] = { 315static u32 thirty_three_base_hpt37x[] = {
314 /* XFER_UDMA_6 */ 0x12446231, /* 0x12646231 ?? */ 316 /* XFER_UDMA_6 */ 0x12446231, /* 0x12646231 ?? */
315 /* XFER_UDMA_5 */ 0x12446231, 317 /* XFER_UDMA_5 */ 0x12446231,
@@ -369,6 +371,73 @@ static u32 sixty_six_base_hpt37x[] = {
369 /* XFER_PIO_1 */ 0x0d029d26, 371 /* XFER_PIO_1 */ 0x0d029d26,
370 /* XFER_PIO_0 */ 0x0d029d5e 372 /* XFER_PIO_0 */ 0x0d029d5e
371}; 373};
374#else
375/*
376 * The following are the new timing tables with PIO mode data/taskfile transfer
377 * overclocking fixed...
378 */
379
380/* This table is taken from the HPT370 data manual rev. 1.02 */
381static u32 thirty_three_base_hpt37x[] = {
382 /* XFER_UDMA_6 */ 0x16455031, /* 0x16655031 ?? */
383 /* XFER_UDMA_5 */ 0x16455031,
384 /* XFER_UDMA_4 */ 0x16455031,
385 /* XFER_UDMA_3 */ 0x166d5031,
386 /* XFER_UDMA_2 */ 0x16495031,
387 /* XFER_UDMA_1 */ 0x164d5033,
388 /* XFER_UDMA_0 */ 0x16515097,
389
390 /* XFER_MW_DMA_2 */ 0x26515031,
391 /* XFER_MW_DMA_1 */ 0x26515033,
392 /* XFER_MW_DMA_0 */ 0x26515097,
393
394 /* XFER_PIO_4 */ 0x06515021,
395 /* XFER_PIO_3 */ 0x06515022,
396 /* XFER_PIO_2 */ 0x06515033,
397 /* XFER_PIO_1 */ 0x06915065,
398 /* XFER_PIO_0 */ 0x06d1508a
399};
400
401static u32 fifty_base_hpt37x[] = {
402 /* XFER_UDMA_6 */ 0x1a861842,
403 /* XFER_UDMA_5 */ 0x1a861842,
404 /* XFER_UDMA_4 */ 0x1aae1842,
405 /* XFER_UDMA_3 */ 0x1a8e1842,
406 /* XFER_UDMA_2 */ 0x1a0e1842,
407 /* XFER_UDMA_1 */ 0x1a161854,
408 /* XFER_UDMA_0 */ 0x1a1a18ea,
409
410 /* XFER_MW_DMA_2 */ 0x2a821842,
411 /* XFER_MW_DMA_1 */ 0x2a821854,
412 /* XFER_MW_DMA_0 */ 0x2a8218ea,
413
414 /* XFER_PIO_4 */ 0x0a821842,
415 /* XFER_PIO_3 */ 0x0a821843,
416 /* XFER_PIO_2 */ 0x0a821855,
417 /* XFER_PIO_1 */ 0x0ac218a8,
418 /* XFER_PIO_0 */ 0x0b02190c
419};
420
421static u32 sixty_six_base_hpt37x[] = {
422 /* XFER_UDMA_6 */ 0x1c86fe62,
423 /* XFER_UDMA_5 */ 0x1caefe62, /* 0x1c8afe62 */
424 /* XFER_UDMA_4 */ 0x1c8afe62,
425 /* XFER_UDMA_3 */ 0x1c8efe62,
426 /* XFER_UDMA_2 */ 0x1c92fe62,
427 /* XFER_UDMA_1 */ 0x1c9afe62,
428 /* XFER_UDMA_0 */ 0x1c82fe62,
429
430 /* XFER_MW_DMA_2 */ 0x2c82fe62,
431 /* XFER_MW_DMA_1 */ 0x2c82fe66,
432 /* XFER_MW_DMA_0 */ 0x2c82ff2e,
433
434 /* XFER_PIO_4 */ 0x0c82fe62,
435 /* XFER_PIO_3 */ 0x0c82fe84,
436 /* XFER_PIO_2 */ 0x0c82fea6,
437 /* XFER_PIO_1 */ 0x0d02ff26,
438 /* XFER_PIO_0 */ 0x0d42ff7f
439};
440#endif
372 441
373#define HPT366_DEBUG_DRIVE_INFO 0 442#define HPT366_DEBUG_DRIVE_INFO 0
374#define HPT371_ALLOW_ATA133_6 1 443#define HPT371_ALLOW_ATA133_6 1
diff --git a/drivers/ide/pci/pdc202xx_new.c b/drivers/ide/pci/pdc202xx_new.c
index 4234efeba606..2b4f44e45a1a 100644
--- a/drivers/ide/pci/pdc202xx_new.c
+++ b/drivers/ide/pci/pdc202xx_new.c
@@ -482,8 +482,9 @@ static struct pci_dev * __devinit pdc20270_get_dev2(struct pci_dev *dev)
482{ 482{
483 struct pci_dev *dev2; 483 struct pci_dev *dev2;
484 484
485 dev2 = pci_get_slot(dev->bus, PCI_DEVFN(PCI_SLOT(dev->devfn) + 2, 485 dev2 = pci_get_slot(dev->bus, PCI_DEVFN(PCI_SLOT(dev->devfn) + 1,
486 PCI_FUNC(dev->devfn))); 486 PCI_FUNC(dev->devfn)));
487
487 if (dev2 && 488 if (dev2 &&
488 dev2->vendor == dev->vendor && 489 dev2->vendor == dev->vendor &&
489 dev2->device == dev->device) { 490 dev2->device == dev->device) {
diff --git a/drivers/ide/pci/piix.c b/drivers/ide/pci/piix.c
index 63625a0be712..27781d294cea 100644
--- a/drivers/ide/pci/piix.c
+++ b/drivers/ide/pci/piix.c
@@ -306,6 +306,7 @@ static const struct ich_laptop ich_laptop[] = {
306 { 0x27DF, 0x0005, 0x0280 }, /* ICH7 on Acer 5602WLMi */ 306 { 0x27DF, 0x0005, 0x0280 }, /* ICH7 on Acer 5602WLMi */
307 { 0x27DF, 0x1025, 0x0110 }, /* ICH7 on Acer 3682WLMi */ 307 { 0x27DF, 0x1025, 0x0110 }, /* ICH7 on Acer 3682WLMi */
308 { 0x27DF, 0x1043, 0x1267 }, /* ICH7 on Asus W5F */ 308 { 0x27DF, 0x1043, 0x1267 }, /* ICH7 on Asus W5F */
309 { 0x27DF, 0x103C, 0x30A1 }, /* ICH7 on HP Compaq nc2400 */
309 { 0x24CA, 0x1025, 0x0061 }, /* ICH4 on Acer Aspire 2023WLMi */ 310 { 0x24CA, 0x1025, 0x0061 }, /* ICH4 on Acer Aspire 2023WLMi */
310 /* end marker */ 311 /* end marker */
311 { 0, } 312 { 0, }
diff --git a/drivers/ide/pci/siimage.c b/drivers/ide/pci/siimage.c
index 6d99441c605b..5709c252543b 100644
--- a/drivers/ide/pci/siimage.c
+++ b/drivers/ide/pci/siimage.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * linux/drivers/ide/pci/siimage.c Version 1.18 Oct 18 2007 2 * linux/drivers/ide/pci/siimage.c Version 1.19 Nov 16 2007
3 * 3 *
4 * Copyright (C) 2001-2002 Andre Hedrick <andre@linux-ide.org> 4 * Copyright (C) 2001-2002 Andre Hedrick <andre@linux-ide.org>
5 * Copyright (C) 2003 Red Hat <alan@redhat.com> 5 * Copyright (C) 2003 Red Hat <alan@redhat.com>
@@ -460,48 +460,6 @@ static void sil_sata_pre_reset(ide_drive_t *drive)
460} 460}
461 461
462/** 462/**
463 * siimage_reset - reset a device on an siimage controller
464 * @drive: drive to reset
465 *
466 * Perform a controller level reset fo the device. For
467 * SATA we must also check the PHY.
468 */
469
470static void siimage_reset (ide_drive_t *drive)
471{
472 ide_hwif_t *hwif = HWIF(drive);
473 u8 reset = 0;
474 unsigned long addr = siimage_selreg(hwif, 0);
475
476 if (hwif->mmio) {
477 reset = hwif->INB(addr);
478 hwif->OUTB((reset|0x03), addr);
479 /* FIXME:posting */
480 udelay(25);
481 hwif->OUTB(reset, addr);
482 (void) hwif->INB(addr);
483 } else {
484 pci_read_config_byte(hwif->pci_dev, addr, &reset);
485 pci_write_config_byte(hwif->pci_dev, addr, reset|0x03);
486 udelay(25);
487 pci_write_config_byte(hwif->pci_dev, addr, reset);
488 pci_read_config_byte(hwif->pci_dev, addr, &reset);
489 }
490
491 if (SATA_STATUS_REG) {
492 /* SATA_STATUS_REG is valid only when in MMIO mode */
493 u32 sata_stat = readl((void __iomem *)SATA_STATUS_REG);
494 printk(KERN_WARNING "%s: reset phy, status=0x%08x, %s\n",
495 hwif->name, sata_stat, __FUNCTION__);
496 if (!(sata_stat)) {
497 printk(KERN_WARNING "%s: reset phy dead, status=0x%08x\n",
498 hwif->name, sata_stat);
499 drive->failures++;
500 }
501 }
502}
503
504/**
505 * proc_reports_siimage - add siimage controller to proc 463 * proc_reports_siimage - add siimage controller to proc
506 * @dev: PCI device 464 * @dev: PCI device
507 * @clocking: SCSC value 465 * @clocking: SCSC value
@@ -857,7 +815,6 @@ static void __devinit init_hwif_siimage(ide_hwif_t *hwif)
857{ 815{
858 u8 sata = is_sata(hwif); 816 u8 sata = is_sata(hwif);
859 817
860 hwif->resetproc = &siimage_reset;
861 hwif->set_pio_mode = &sil_set_pio_mode; 818 hwif->set_pio_mode = &sil_set_pio_mode;
862 hwif->set_dma_mode = &sil_set_dma_mode; 819 hwif->set_dma_mode = &sil_set_dma_mode;
863 820
diff --git a/drivers/ide/pci/sis5513.c b/drivers/ide/pci/sis5513.c
index f6e2ab3dd166..d90b42917775 100644
--- a/drivers/ide/pci/sis5513.c
+++ b/drivers/ide/pci/sis5513.c
@@ -526,6 +526,7 @@ static const struct sis_laptop sis_laptop[] = {
526 /* devid, subvendor, subdev */ 526 /* devid, subvendor, subdev */
527 { 0x5513, 0x1043, 0x1107 }, /* ASUS A6K */ 527 { 0x5513, 0x1043, 0x1107 }, /* ASUS A6K */
528 { 0x5513, 0x1734, 0x105f }, /* FSC Amilo A1630 */ 528 { 0x5513, 0x1734, 0x105f }, /* FSC Amilo A1630 */
529 { 0x5513, 0x1071, 0x8640 }, /* EasyNote K5305 */
529 /* end marker */ 530 /* end marker */
530 { 0, } 531 { 0, }
531}; 532};
diff --git a/drivers/ide/pci/trm290.c b/drivers/ide/pci/trm290.c
index 5011ba22e36c..0895e753a35d 100644
--- a/drivers/ide/pci/trm290.c
+++ b/drivers/ide/pci/trm290.c
@@ -240,9 +240,6 @@ static int trm290_ide_dma_test_irq (ide_drive_t *drive)
240 return (status == 0x00ff); 240 return (status == 0x00ff);
241} 241}
242 242
243/*
244 * Invoked from ide-dma.c at boot time.
245 */
246static void __devinit init_hwif_trm290(ide_hwif_t *hwif) 243static void __devinit init_hwif_trm290(ide_hwif_t *hwif)
247{ 244{
248 unsigned int cfgbase = 0; 245 unsigned int cfgbase = 0;
diff --git a/drivers/ide/ppc/pmac.c b/drivers/ide/ppc/pmac.c
index 5afdfef7264c..7f7a59885777 100644
--- a/drivers/ide/ppc/pmac.c
+++ b/drivers/ide/ppc/pmac.c
@@ -1513,7 +1513,7 @@ pmac_ide_build_dmatable(ide_drive_t *drive, struct request *rq)
1513 1513
1514 if (pmif->broken_dma && cur_addr & (L1_CACHE_BYTES - 1)) { 1514 if (pmif->broken_dma && cur_addr & (L1_CACHE_BYTES - 1)) {
1515 if (pmif->broken_dma_warn == 0) { 1515 if (pmif->broken_dma_warn == 0) {
1516 printk(KERN_WARNING "%s: DMA on non aligned address," 1516 printk(KERN_WARNING "%s: DMA on non aligned address, "
1517 "switching to PIO on Ohare chipset\n", drive->name); 1517 "switching to PIO on Ohare chipset\n", drive->name);
1518 pmif->broken_dma_warn = 1; 1518 pmif->broken_dma_warn = 1;
1519 } 1519 }
diff --git a/drivers/ide/setup-pci.c b/drivers/ide/setup-pci.c
index 25fd09053220..d2cd5a3d38f8 100644
--- a/drivers/ide/setup-pci.c
+++ b/drivers/ide/setup-pci.c
@@ -704,7 +704,7 @@ EXPORT_SYMBOL_GPL(ide_setup_pci_devices);
704/* 704/*
705 * Module interfaces 705 * Module interfaces
706 */ 706 */
707 707
708static int pre_init = 1; /* Before first ordered IDE scan */ 708static int pre_init = 1; /* Before first ordered IDE scan */
709static LIST_HEAD(ide_pci_drivers); 709static LIST_HEAD(ide_pci_drivers);
710 710
@@ -714,7 +714,7 @@ static LIST_HEAD(ide_pci_drivers);
714 * @module: owner module of the driver 714 * @module: owner module of the driver
715 * 715 *
716 * Registers a driver with the IDE layer. The IDE layer arranges that 716 * Registers a driver with the IDE layer. The IDE layer arranges that
717 * boot time setup is done in the expected device order and then 717 * boot time setup is done in the expected device order and then
718 * hands the controllers off to the core PCI code to do the rest of 718 * hands the controllers off to the core PCI code to do the rest of
719 * the work. 719 * the work.
720 * 720 *
@@ -724,13 +724,12 @@ static LIST_HEAD(ide_pci_drivers);
724int __ide_pci_register_driver(struct pci_driver *driver, struct module *module, 724int __ide_pci_register_driver(struct pci_driver *driver, struct module *module,
725 const char *mod_name) 725 const char *mod_name)
726{ 726{
727 if(!pre_init) 727 if (!pre_init)
728 return __pci_register_driver(driver, module, mod_name); 728 return __pci_register_driver(driver, module, mod_name);
729 driver->driver.owner = module; 729 driver->driver.owner = module;
730 list_add_tail(&driver->node, &ide_pci_drivers); 730 list_add_tail(&driver->node, &ide_pci_drivers);
731 return 0; 731 return 0;
732} 732}
733
734EXPORT_SYMBOL_GPL(__ide_pci_register_driver); 733EXPORT_SYMBOL_GPL(__ide_pci_register_driver);
735 734
736/** 735/**
@@ -741,17 +740,18 @@ EXPORT_SYMBOL_GPL(__ide_pci_register_driver);
741 * This is only used during boot up to get the ordering correct. After 740 * This is only used during boot up to get the ordering correct. After
742 * boot up the pci layer takes over the job. 741 * boot up the pci layer takes over the job.
743 */ 742 */
744 743
745static int __init ide_scan_pcidev(struct pci_dev *dev) 744static int __init ide_scan_pcidev(struct pci_dev *dev)
746{ 745{
747 struct list_head *l; 746 struct list_head *l;
748 struct pci_driver *d; 747 struct pci_driver *d;
749 748
750 list_for_each(l, &ide_pci_drivers) { 749 list_for_each(l, &ide_pci_drivers) {
751 d = list_entry(l, struct pci_driver, node); 750 d = list_entry(l, struct pci_driver, node);
752 if (d->id_table) { 751 if (d->id_table) {
753 const struct pci_device_id *id = pci_match_id(d->id_table, 752 const struct pci_device_id *id =
754 dev); 753 pci_match_id(d->id_table, dev);
754
755 if (id != NULL && d->probe(dev, id) >= 0) { 755 if (id != NULL && d->probe(dev, id) >= 0) {
756 dev->driver = d; 756 dev->driver = d;
757 pci_dev_get(dev); 757 pci_dev_get(dev);
@@ -779,13 +779,13 @@ void __init ide_scan_pcibus (int scan_direction)
779 779
780 pre_init = 0; 780 pre_init = 0;
781 if (!scan_direction) 781 if (!scan_direction)
782 while ((dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) 782 while ((dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev)))
783 ide_scan_pcidev(dev); 783 ide_scan_pcidev(dev);
784 else 784 else
785 while ((dev = pci_get_device_reverse(PCI_ANY_ID, PCI_ANY_ID, dev)) 785 while ((dev = pci_get_device_reverse(PCI_ANY_ID, PCI_ANY_ID,
786 != NULL) 786 dev)))
787 ide_scan_pcidev(dev); 787 ide_scan_pcidev(dev);
788 788
789 /* 789 /*
790 * Hand the drivers over to the PCI layer now we 790 * Hand the drivers over to the PCI layer now we
791 * are post init. 791 * are post init.
@@ -794,9 +794,10 @@ void __init ide_scan_pcibus (int scan_direction)
794 list_for_each_safe(l, n, &ide_pci_drivers) { 794 list_for_each_safe(l, n, &ide_pci_drivers) {
795 list_del(l); 795 list_del(l);
796 d = list_entry(l, struct pci_driver, node); 796 d = list_entry(l, struct pci_driver, node);
797 if (__pci_register_driver(d, d->driver.owner, d->driver.mod_name)) 797 if (__pci_register_driver(d, d->driver.owner,
798 printk(KERN_ERR "%s: failed to register driver for %s\n", 798 d->driver.mod_name))
799 __FUNCTION__, d->driver.mod_name); 799 printk(KERN_ERR "%s: failed to register %s driver\n",
800 __FUNCTION__, d->driver.mod_name);
800 } 801 }
801} 802}
802#endif 803#endif
diff --git a/drivers/infiniband/hw/ehca/ehca_av.c b/drivers/infiniband/hw/ehca/ehca_av.c
index 453eb995c1d4..f7782c882ab4 100644
--- a/drivers/infiniband/hw/ehca/ehca_av.c
+++ b/drivers/infiniband/hw/ehca/ehca_av.c
@@ -76,8 +76,12 @@ int ehca_calc_ipd(struct ehca_shca *shca, int port,
76 76
77 link = ib_width_enum_to_int(pa.active_width) * pa.active_speed; 77 link = ib_width_enum_to_int(pa.active_width) * pa.active_speed;
78 78
79 /* IPD = round((link / path) - 1) */ 79 if (path >= link)
80 *ipd = ((link + (path >> 1)) / path) - 1; 80 /* no need to throttle if path faster than link */
81 *ipd = 0;
82 else
83 /* IPD = round((link / path) - 1) */
84 *ipd = ((link + (path >> 1)) / path) - 1;
81 85
82 return 0; 86 return 0;
83} 87}
diff --git a/drivers/infiniband/hw/ehca/ehca_classes.h b/drivers/infiniband/hw/ehca/ehca_classes.h
index 87f12d4312a7..74d2b72a11d8 100644
--- a/drivers/infiniband/hw/ehca/ehca_classes.h
+++ b/drivers/infiniband/hw/ehca/ehca_classes.h
@@ -322,6 +322,7 @@ extern int ehca_static_rate;
322extern int ehca_port_act_time; 322extern int ehca_port_act_time;
323extern int ehca_use_hp_mr; 323extern int ehca_use_hp_mr;
324extern int ehca_scaling_code; 324extern int ehca_scaling_code;
325extern int ehca_lock_hcalls;
325 326
326struct ipzu_queue_resp { 327struct ipzu_queue_resp {
327 u32 qe_size; /* queue entry size */ 328 u32 qe_size; /* queue entry size */
diff --git a/drivers/infiniband/hw/ehca/ehca_main.c b/drivers/infiniband/hw/ehca/ehca_main.c
index 90d4334179bf..6a56d86a2951 100644
--- a/drivers/infiniband/hw/ehca/ehca_main.c
+++ b/drivers/infiniband/hw/ehca/ehca_main.c
@@ -43,13 +43,14 @@
43#ifdef CONFIG_PPC_64K_PAGES 43#ifdef CONFIG_PPC_64K_PAGES
44#include <linux/slab.h> 44#include <linux/slab.h>
45#endif 45#endif
46
46#include "ehca_classes.h" 47#include "ehca_classes.h"
47#include "ehca_iverbs.h" 48#include "ehca_iverbs.h"
48#include "ehca_mrmw.h" 49#include "ehca_mrmw.h"
49#include "ehca_tools.h" 50#include "ehca_tools.h"
50#include "hcp_if.h" 51#include "hcp_if.h"
51 52
52#define HCAD_VERSION "0024" 53#define HCAD_VERSION "0025"
53 54
54MODULE_LICENSE("Dual BSD/GPL"); 55MODULE_LICENSE("Dual BSD/GPL");
55MODULE_AUTHOR("Christoph Raisch <raisch@de.ibm.com>"); 56MODULE_AUTHOR("Christoph Raisch <raisch@de.ibm.com>");
@@ -66,6 +67,7 @@ int ehca_poll_all_eqs = 1;
66int ehca_static_rate = -1; 67int ehca_static_rate = -1;
67int ehca_scaling_code = 0; 68int ehca_scaling_code = 0;
68int ehca_mr_largepage = 1; 69int ehca_mr_largepage = 1;
70int ehca_lock_hcalls = -1;
69 71
70module_param_named(open_aqp1, ehca_open_aqp1, int, S_IRUGO); 72module_param_named(open_aqp1, ehca_open_aqp1, int, S_IRUGO);
71module_param_named(debug_level, ehca_debug_level, int, S_IRUGO); 73module_param_named(debug_level, ehca_debug_level, int, S_IRUGO);
@@ -77,6 +79,7 @@ module_param_named(poll_all_eqs, ehca_poll_all_eqs, int, S_IRUGO);
77module_param_named(static_rate, ehca_static_rate, int, S_IRUGO); 79module_param_named(static_rate, ehca_static_rate, int, S_IRUGO);
78module_param_named(scaling_code, ehca_scaling_code, int, S_IRUGO); 80module_param_named(scaling_code, ehca_scaling_code, int, S_IRUGO);
79module_param_named(mr_largepage, ehca_mr_largepage, int, S_IRUGO); 81module_param_named(mr_largepage, ehca_mr_largepage, int, S_IRUGO);
82module_param_named(lock_hcalls, ehca_lock_hcalls, bool, S_IRUGO);
80 83
81MODULE_PARM_DESC(open_aqp1, 84MODULE_PARM_DESC(open_aqp1,
82 "AQP1 on startup (0: no (default), 1: yes)"); 85 "AQP1 on startup (0: no (default), 1: yes)");
@@ -102,6 +105,9 @@ MODULE_PARM_DESC(scaling_code,
102MODULE_PARM_DESC(mr_largepage, 105MODULE_PARM_DESC(mr_largepage,
103 "use large page for MR (0: use PAGE_SIZE (default), " 106 "use large page for MR (0: use PAGE_SIZE (default), "
104 "1: use large page depending on MR size"); 107 "1: use large page depending on MR size");
108MODULE_PARM_DESC(lock_hcalls,
109 "serialize all hCalls made by the driver "
110 "(default: autodetect)");
105 111
106DEFINE_RWLOCK(ehca_qp_idr_lock); 112DEFINE_RWLOCK(ehca_qp_idr_lock);
107DEFINE_RWLOCK(ehca_cq_idr_lock); 113DEFINE_RWLOCK(ehca_cq_idr_lock);
@@ -258,6 +264,7 @@ static struct cap_descr {
258 { HCA_CAP_UD_LL_QP, "HCA_CAP_UD_LL_QP" }, 264 { HCA_CAP_UD_LL_QP, "HCA_CAP_UD_LL_QP" },
259 { HCA_CAP_RESIZE_MR, "HCA_CAP_RESIZE_MR" }, 265 { HCA_CAP_RESIZE_MR, "HCA_CAP_RESIZE_MR" },
260 { HCA_CAP_MINI_QP, "HCA_CAP_MINI_QP" }, 266 { HCA_CAP_MINI_QP, "HCA_CAP_MINI_QP" },
267 { HCA_CAP_H_ALLOC_RES_SYNC, "HCA_CAP_H_ALLOC_RES_SYNC" },
261}; 268};
262 269
263static int ehca_sense_attributes(struct ehca_shca *shca) 270static int ehca_sense_attributes(struct ehca_shca *shca)
@@ -333,6 +340,12 @@ static int ehca_sense_attributes(struct ehca_shca *shca)
333 if (EHCA_BMASK_GET(hca_cap_descr[i].mask, shca->hca_cap)) 340 if (EHCA_BMASK_GET(hca_cap_descr[i].mask, shca->hca_cap))
334 ehca_gen_dbg(" %s", hca_cap_descr[i].descr); 341 ehca_gen_dbg(" %s", hca_cap_descr[i].descr);
335 342
343 /* Autodetect hCall locking -- the "H_ALLOC_RESOURCE synced" flag is
344 * a firmware property, so it's valid across all adapters
345 */
346 if (ehca_lock_hcalls == -1)
347 ehca_lock_hcalls = !(shca->hca_cap & HCA_CAP_H_ALLOC_RES_SYNC);
348
336 /* translate supported MR page sizes; always support 4K */ 349 /* translate supported MR page sizes; always support 4K */
337 shca->hca_cap_mr_pgsize = EHCA_PAGESIZE; 350 shca->hca_cap_mr_pgsize = EHCA_PAGESIZE;
338 if (ehca_mr_largepage) { /* support extra sizes only if enabled */ 351 if (ehca_mr_largepage) { /* support extra sizes only if enabled */
diff --git a/drivers/infiniband/hw/ehca/ehca_qp.c b/drivers/infiniband/hw/ehca/ehca_qp.c
index 2e3e6547cb78..eff5fb55604b 100644
--- a/drivers/infiniband/hw/ehca/ehca_qp.c
+++ b/drivers/infiniband/hw/ehca/ehca_qp.c
@@ -838,7 +838,7 @@ struct ib_srq *ehca_create_srq(struct ib_pd *pd,
838 838
839 /* copy back return values */ 839 /* copy back return values */
840 srq_init_attr->attr.max_wr = qp_init_attr.cap.max_recv_wr; 840 srq_init_attr->attr.max_wr = qp_init_attr.cap.max_recv_wr;
841 srq_init_attr->attr.max_sge = qp_init_attr.cap.max_recv_sge; 841 srq_init_attr->attr.max_sge = 3;
842 842
843 /* drive SRQ into RTR state */ 843 /* drive SRQ into RTR state */
844 mqpcb = ehca_alloc_fw_ctrlblock(GFP_KERNEL); 844 mqpcb = ehca_alloc_fw_ctrlblock(GFP_KERNEL);
@@ -1203,7 +1203,7 @@ static int internal_modify_qp(struct ib_qp *ibqp,
1203 mqpcb->service_level = attr->ah_attr.sl; 1203 mqpcb->service_level = attr->ah_attr.sl;
1204 update_mask |= EHCA_BMASK_SET(MQPCB_MASK_SERVICE_LEVEL, 1); 1204 update_mask |= EHCA_BMASK_SET(MQPCB_MASK_SERVICE_LEVEL, 1);
1205 1205
1206 if (ehca_calc_ipd(shca, my_qp->init_attr.port_num, 1206 if (ehca_calc_ipd(shca, mqpcb->prim_phys_port,
1207 attr->ah_attr.static_rate, 1207 attr->ah_attr.static_rate,
1208 &mqpcb->max_static_rate)) { 1208 &mqpcb->max_static_rate)) {
1209 ret = -EINVAL; 1209 ret = -EINVAL;
@@ -1302,7 +1302,7 @@ static int internal_modify_qp(struct ib_qp *ibqp,
1302 mqpcb->source_path_bits_al = attr->alt_ah_attr.src_path_bits; 1302 mqpcb->source_path_bits_al = attr->alt_ah_attr.src_path_bits;
1303 mqpcb->service_level_al = attr->alt_ah_attr.sl; 1303 mqpcb->service_level_al = attr->alt_ah_attr.sl;
1304 1304
1305 if (ehca_calc_ipd(shca, my_qp->init_attr.port_num, 1305 if (ehca_calc_ipd(shca, mqpcb->alt_phys_port,
1306 attr->alt_ah_attr.static_rate, 1306 attr->alt_ah_attr.static_rate,
1307 &mqpcb->max_static_rate_al)) { 1307 &mqpcb->max_static_rate_al)) {
1308 ret = -EINVAL; 1308 ret = -EINVAL;
@@ -1750,7 +1750,7 @@ int ehca_query_srq(struct ib_srq *srq, struct ib_srq_attr *srq_attr)
1750 } 1750 }
1751 1751
1752 srq_attr->max_wr = qpcb->max_nr_outst_recv_wr - 1; 1752 srq_attr->max_wr = qpcb->max_nr_outst_recv_wr - 1;
1753 srq_attr->max_sge = qpcb->actual_nr_sges_in_rq_wqe; 1753 srq_attr->max_sge = 3;
1754 srq_attr->srq_limit = EHCA_BMASK_GET( 1754 srq_attr->srq_limit = EHCA_BMASK_GET(
1755 MQPCB_CURR_SRQ_LIMIT, qpcb->curr_srq_limit); 1755 MQPCB_CURR_SRQ_LIMIT, qpcb->curr_srq_limit);
1756 1756
diff --git a/drivers/infiniband/hw/ehca/hcp_if.c b/drivers/infiniband/hw/ehca/hcp_if.c
index c16a21374bb5..7029aa653751 100644
--- a/drivers/infiniband/hw/ehca/hcp_if.c
+++ b/drivers/infiniband/hw/ehca/hcp_if.c
@@ -120,26 +120,21 @@ static long ehca_plpar_hcall_norets(unsigned long opcode,
120 unsigned long arg7) 120 unsigned long arg7)
121{ 121{
122 long ret; 122 long ret;
123 int i, sleep_msecs, do_lock; 123 int i, sleep_msecs;
124 unsigned long flags; 124 unsigned long flags = 0;
125 125
126 ehca_gen_dbg("opcode=%lx " HCALL7_REGS_FORMAT, 126 ehca_gen_dbg("opcode=%lx " HCALL7_REGS_FORMAT,
127 opcode, arg1, arg2, arg3, arg4, arg5, arg6, arg7); 127 opcode, arg1, arg2, arg3, arg4, arg5, arg6, arg7);
128 128
129 /* lock H_FREE_RESOURCE(MR) against itself and H_ALLOC_RESOURCE(MR) */
130 if ((opcode == H_FREE_RESOURCE) && (arg7 == 5)) {
131 arg7 = 0; /* better not upset firmware */
132 do_lock = 1;
133 }
134
135 for (i = 0; i < 5; i++) { 129 for (i = 0; i < 5; i++) {
136 if (do_lock) 130 /* serialize hCalls to work around firmware issue */
131 if (ehca_lock_hcalls)
137 spin_lock_irqsave(&hcall_lock, flags); 132 spin_lock_irqsave(&hcall_lock, flags);
138 133
139 ret = plpar_hcall_norets(opcode, arg1, arg2, arg3, arg4, 134 ret = plpar_hcall_norets(opcode, arg1, arg2, arg3, arg4,
140 arg5, arg6, arg7); 135 arg5, arg6, arg7);
141 136
142 if (do_lock) 137 if (ehca_lock_hcalls)
143 spin_unlock_irqrestore(&hcall_lock, flags); 138 spin_unlock_irqrestore(&hcall_lock, flags);
144 139
145 if (H_IS_LONG_BUSY(ret)) { 140 if (H_IS_LONG_BUSY(ret)) {
@@ -174,24 +169,22 @@ static long ehca_plpar_hcall9(unsigned long opcode,
174 unsigned long arg9) 169 unsigned long arg9)
175{ 170{
176 long ret; 171 long ret;
177 int i, sleep_msecs, do_lock; 172 int i, sleep_msecs;
178 unsigned long flags = 0; 173 unsigned long flags = 0;
179 174
180 ehca_gen_dbg("INPUT -- opcode=%lx " HCALL9_REGS_FORMAT, opcode, 175 ehca_gen_dbg("INPUT -- opcode=%lx " HCALL9_REGS_FORMAT, opcode,
181 arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9); 176 arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9);
182 177
183 /* lock H_ALLOC_RESOURCE(MR) against itself and H_FREE_RESOURCE(MR) */
184 do_lock = ((opcode == H_ALLOC_RESOURCE) && (arg2 == 5));
185
186 for (i = 0; i < 5; i++) { 178 for (i = 0; i < 5; i++) {
187 if (do_lock) 179 /* serialize hCalls to work around firmware issue */
180 if (ehca_lock_hcalls)
188 spin_lock_irqsave(&hcall_lock, flags); 181 spin_lock_irqsave(&hcall_lock, flags);
189 182
190 ret = plpar_hcall9(opcode, outs, 183 ret = plpar_hcall9(opcode, outs,
191 arg1, arg2, arg3, arg4, arg5, 184 arg1, arg2, arg3, arg4, arg5,
192 arg6, arg7, arg8, arg9); 185 arg6, arg7, arg8, arg9);
193 186
194 if (do_lock) 187 if (ehca_lock_hcalls)
195 spin_unlock_irqrestore(&hcall_lock, flags); 188 spin_unlock_irqrestore(&hcall_lock, flags);
196 189
197 if (H_IS_LONG_BUSY(ret)) { 190 if (H_IS_LONG_BUSY(ret)) {
@@ -821,7 +814,7 @@ u64 hipz_h_free_resource_mr(const struct ipz_adapter_handle adapter_handle,
821 return ehca_plpar_hcall_norets(H_FREE_RESOURCE, 814 return ehca_plpar_hcall_norets(H_FREE_RESOURCE,
822 adapter_handle.handle, /* r4 */ 815 adapter_handle.handle, /* r4 */
823 mr->ipz_mr_handle.handle, /* r5 */ 816 mr->ipz_mr_handle.handle, /* r5 */
824 0, 0, 0, 0, 5); 817 0, 0, 0, 0, 0);
825} 818}
826 819
827u64 hipz_h_reregister_pmr(const struct ipz_adapter_handle adapter_handle, 820u64 hipz_h_reregister_pmr(const struct ipz_adapter_handle adapter_handle,
diff --git a/drivers/infiniband/hw/ehca/hipz_hw.h b/drivers/infiniband/hw/ehca/hipz_hw.h
index 485b8400359e..bf996c7acc42 100644
--- a/drivers/infiniband/hw/ehca/hipz_hw.h
+++ b/drivers/infiniband/hw/ehca/hipz_hw.h
@@ -378,6 +378,7 @@ struct hipz_query_hca {
378#define HCA_CAP_UD_LL_QP EHCA_BMASK_IBM(16, 16) 378#define HCA_CAP_UD_LL_QP EHCA_BMASK_IBM(16, 16)
379#define HCA_CAP_RESIZE_MR EHCA_BMASK_IBM(17, 17) 379#define HCA_CAP_RESIZE_MR EHCA_BMASK_IBM(17, 17)
380#define HCA_CAP_MINI_QP EHCA_BMASK_IBM(18, 18) 380#define HCA_CAP_MINI_QP EHCA_BMASK_IBM(18, 18)
381#define HCA_CAP_H_ALLOC_RES_SYNC EHCA_BMASK_IBM(19, 19)
381 382
382/* query port response block */ 383/* query port response block */
383struct hipz_query_port { 384struct hipz_query_port {
diff --git a/drivers/infiniband/hw/ipath/ipath_cq.c b/drivers/infiniband/hw/ipath/ipath_cq.c
index 08d8ae148cd0..d1380c7a1703 100644
--- a/drivers/infiniband/hw/ipath/ipath_cq.c
+++ b/drivers/infiniband/hw/ipath/ipath_cq.c
@@ -395,12 +395,9 @@ int ipath_resize_cq(struct ib_cq *ibcq, int cqe, struct ib_udata *udata)
395 goto bail; 395 goto bail;
396 } 396 }
397 397
398 /* 398 /* Check that we can write the offset to mmap. */
399 * Return the address of the WC as the offset to mmap.
400 * See ipath_mmap() for details.
401 */
402 if (udata && udata->outlen >= sizeof(__u64)) { 399 if (udata && udata->outlen >= sizeof(__u64)) {
403 __u64 offset = (__u64) wc; 400 __u64 offset = 0;
404 401
405 ret = ib_copy_to_udata(udata, &offset, sizeof(offset)); 402 ret = ib_copy_to_udata(udata, &offset, sizeof(offset));
406 if (ret) 403 if (ret)
@@ -450,6 +447,18 @@ int ipath_resize_cq(struct ib_cq *ibcq, int cqe, struct ib_udata *udata)
450 struct ipath_mmap_info *ip = cq->ip; 447 struct ipath_mmap_info *ip = cq->ip;
451 448
452 ipath_update_mmap_info(dev, ip, sz, wc); 449 ipath_update_mmap_info(dev, ip, sz, wc);
450
451 /*
452 * Return the offset to mmap.
453 * See ipath_mmap() for details.
454 */
455 if (udata && udata->outlen >= sizeof(__u64)) {
456 ret = ib_copy_to_udata(udata, &ip->offset,
457 sizeof(ip->offset));
458 if (ret)
459 goto bail;
460 }
461
453 spin_lock_irq(&dev->pending_lock); 462 spin_lock_irq(&dev->pending_lock);
454 if (list_empty(&ip->pending_mmaps)) 463 if (list_empty(&ip->pending_mmaps))
455 list_add(&ip->pending_mmaps, &dev->pending_mmaps); 464 list_add(&ip->pending_mmaps, &dev->pending_mmaps);
diff --git a/drivers/infiniband/hw/ipath/ipath_qp.c b/drivers/infiniband/hw/ipath/ipath_qp.c
index 6a41fdbc8e57..b997ff88401b 100644
--- a/drivers/infiniband/hw/ipath/ipath_qp.c
+++ b/drivers/infiniband/hw/ipath/ipath_qp.c
@@ -835,7 +835,8 @@ struct ib_qp *ipath_create_qp(struct ib_pd *ibpd,
835 init_attr->qp_type); 835 init_attr->qp_type);
836 if (err) { 836 if (err) {
837 ret = ERR_PTR(err); 837 ret = ERR_PTR(err);
838 goto bail_rwq; 838 vfree(qp->r_rq.wq);
839 goto bail_qp;
839 } 840 }
840 qp->ip = NULL; 841 qp->ip = NULL;
841 ipath_reset_qp(qp); 842 ipath_reset_qp(qp);
@@ -863,7 +864,7 @@ struct ib_qp *ipath_create_qp(struct ib_pd *ibpd,
863 sizeof(offset)); 864 sizeof(offset));
864 if (err) { 865 if (err) {
865 ret = ERR_PTR(err); 866 ret = ERR_PTR(err);
866 goto bail_rwq; 867 goto bail_ip;
867 } 868 }
868 } else { 869 } else {
869 u32 s = sizeof(struct ipath_rwq) + 870 u32 s = sizeof(struct ipath_rwq) +
@@ -875,7 +876,7 @@ struct ib_qp *ipath_create_qp(struct ib_pd *ibpd,
875 qp->r_rq.wq); 876 qp->r_rq.wq);
876 if (!qp->ip) { 877 if (!qp->ip) {
877 ret = ERR_PTR(-ENOMEM); 878 ret = ERR_PTR(-ENOMEM);
878 goto bail_rwq; 879 goto bail_ip;
879 } 880 }
880 881
881 err = ib_copy_to_udata(udata, &(qp->ip->offset), 882 err = ib_copy_to_udata(udata, &(qp->ip->offset),
@@ -907,9 +908,11 @@ struct ib_qp *ipath_create_qp(struct ib_pd *ibpd,
907 goto bail; 908 goto bail;
908 909
909bail_ip: 910bail_ip:
910 kfree(qp->ip); 911 if (qp->ip)
911bail_rwq: 912 kref_put(&qp->ip->ref, ipath_release_mmap_info);
912 vfree(qp->r_rq.wq); 913 else
914 vfree(qp->r_rq.wq);
915 ipath_free_qp(&dev->qp_table, qp);
913bail_qp: 916bail_qp:
914 kfree(qp); 917 kfree(qp);
915bail_swq: 918bail_swq:
diff --git a/drivers/infiniband/hw/ipath/ipath_srq.c b/drivers/infiniband/hw/ipath/ipath_srq.c
index 40c36ec19016..2fef36f4b675 100644
--- a/drivers/infiniband/hw/ipath/ipath_srq.c
+++ b/drivers/infiniband/hw/ipath/ipath_srq.c
@@ -59,7 +59,7 @@ int ipath_post_srq_receive(struct ib_srq *ibsrq, struct ib_recv_wr *wr,
59 59
60 if ((unsigned) wr->num_sge > srq->rq.max_sge) { 60 if ((unsigned) wr->num_sge > srq->rq.max_sge) {
61 *bad_wr = wr; 61 *bad_wr = wr;
62 ret = -ENOMEM; 62 ret = -EINVAL;
63 goto bail; 63 goto bail;
64 } 64 }
65 65
@@ -211,11 +211,11 @@ int ipath_modify_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr,
211 struct ib_udata *udata) 211 struct ib_udata *udata)
212{ 212{
213 struct ipath_srq *srq = to_isrq(ibsrq); 213 struct ipath_srq *srq = to_isrq(ibsrq);
214 struct ipath_rwq *wq;
214 int ret = 0; 215 int ret = 0;
215 216
216 if (attr_mask & IB_SRQ_MAX_WR) { 217 if (attr_mask & IB_SRQ_MAX_WR) {
217 struct ipath_rwq *owq; 218 struct ipath_rwq *owq;
218 struct ipath_rwq *wq;
219 struct ipath_rwqe *p; 219 struct ipath_rwqe *p;
220 u32 sz, size, n, head, tail; 220 u32 sz, size, n, head, tail;
221 221
@@ -236,27 +236,20 @@ int ipath_modify_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr,
236 goto bail; 236 goto bail;
237 } 237 }
238 238
239 /* 239 /* Check that we can write the offset to mmap. */
240 * Return the address of the RWQ as the offset to mmap.
241 * See ipath_mmap() for details.
242 */
243 if (udata && udata->inlen >= sizeof(__u64)) { 240 if (udata && udata->inlen >= sizeof(__u64)) {
244 __u64 offset_addr; 241 __u64 offset_addr;
245 __u64 offset = (__u64) wq; 242 __u64 offset = 0;
246 243
247 ret = ib_copy_from_udata(&offset_addr, udata, 244 ret = ib_copy_from_udata(&offset_addr, udata,
248 sizeof(offset_addr)); 245 sizeof(offset_addr));
249 if (ret) { 246 if (ret)
250 vfree(wq); 247 goto bail_free;
251 goto bail;
252 }
253 udata->outbuf = (void __user *) offset_addr; 248 udata->outbuf = (void __user *) offset_addr;
254 ret = ib_copy_to_udata(udata, &offset, 249 ret = ib_copy_to_udata(udata, &offset,
255 sizeof(offset)); 250 sizeof(offset));
256 if (ret) { 251 if (ret)
257 vfree(wq); 252 goto bail_free;
258 goto bail;
259 }
260 } 253 }
261 254
262 spin_lock_irq(&srq->rq.lock); 255 spin_lock_irq(&srq->rq.lock);
@@ -277,10 +270,8 @@ int ipath_modify_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr,
277 else 270 else
278 n -= tail; 271 n -= tail;
279 if (size <= n) { 272 if (size <= n) {
280 spin_unlock_irq(&srq->rq.lock);
281 vfree(wq);
282 ret = -EINVAL; 273 ret = -EINVAL;
283 goto bail; 274 goto bail_unlock;
284 } 275 }
285 n = 0; 276 n = 0;
286 p = wq->wq; 277 p = wq->wq;
@@ -314,6 +305,18 @@ int ipath_modify_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr,
314 u32 s = sizeof(struct ipath_rwq) + size * sz; 305 u32 s = sizeof(struct ipath_rwq) + size * sz;
315 306
316 ipath_update_mmap_info(dev, ip, s, wq); 307 ipath_update_mmap_info(dev, ip, s, wq);
308
309 /*
310 * Return the offset to mmap.
311 * See ipath_mmap() for details.
312 */
313 if (udata && udata->inlen >= sizeof(__u64)) {
314 ret = ib_copy_to_udata(udata, &ip->offset,
315 sizeof(ip->offset));
316 if (ret)
317 goto bail;
318 }
319
317 spin_lock_irq(&dev->pending_lock); 320 spin_lock_irq(&dev->pending_lock);
318 if (list_empty(&ip->pending_mmaps)) 321 if (list_empty(&ip->pending_mmaps))
319 list_add(&ip->pending_mmaps, 322 list_add(&ip->pending_mmaps,
@@ -328,7 +331,12 @@ int ipath_modify_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr,
328 srq->limit = attr->srq_limit; 331 srq->limit = attr->srq_limit;
329 spin_unlock_irq(&srq->rq.lock); 332 spin_unlock_irq(&srq->rq.lock);
330 } 333 }
334 goto bail;
331 335
336bail_unlock:
337 spin_unlock_irq(&srq->rq.lock);
338bail_free:
339 vfree(wq);
332bail: 340bail:
333 return ret; 341 return ret;
334} 342}
diff --git a/drivers/infiniband/hw/ipath/ipath_verbs.c b/drivers/infiniband/hw/ipath/ipath_verbs.c
index 74f77e7c2c1b..c4c998446c7b 100644
--- a/drivers/infiniband/hw/ipath/ipath_verbs.c
+++ b/drivers/infiniband/hw/ipath/ipath_verbs.c
@@ -302,8 +302,10 @@ static int ipath_post_one_send(struct ipath_qp *qp, struct ib_send_wr *wr)
302 next = qp->s_head + 1; 302 next = qp->s_head + 1;
303 if (next >= qp->s_size) 303 if (next >= qp->s_size)
304 next = 0; 304 next = 0;
305 if (next == qp->s_last) 305 if (next == qp->s_last) {
306 goto bail_inval; 306 ret = -ENOMEM;
307 goto bail;
308 }
307 309
308 wqe = get_swqe_ptr(qp, qp->s_head); 310 wqe = get_swqe_ptr(qp, qp->s_head);
309 wqe->wr = *wr; 311 wqe->wr = *wr;
@@ -404,7 +406,7 @@ static int ipath_post_receive(struct ib_qp *ibqp, struct ib_recv_wr *wr,
404 406
405 if ((unsigned) wr->num_sge > qp->r_rq.max_sge) { 407 if ((unsigned) wr->num_sge > qp->r_rq.max_sge) {
406 *bad_wr = wr; 408 *bad_wr = wr;
407 ret = -ENOMEM; 409 ret = -EINVAL;
408 goto bail; 410 goto bail;
409 } 411 }
410 412
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_main.c b/drivers/infiniband/ulp/ipoib/ipoib_main.c
index a03a65ebcf0c..c9f6077b615e 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_main.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_main.c
@@ -460,6 +460,9 @@ static struct ipoib_path *path_rec_create(struct net_device *dev, void *gid)
460 struct ipoib_dev_priv *priv = netdev_priv(dev); 460 struct ipoib_dev_priv *priv = netdev_priv(dev);
461 struct ipoib_path *path; 461 struct ipoib_path *path;
462 462
463 if (!priv->broadcast)
464 return NULL;
465
463 path = kzalloc(sizeof *path, GFP_ATOMIC); 466 path = kzalloc(sizeof *path, GFP_ATOMIC);
464 if (!path) 467 if (!path)
465 return NULL; 468 return NULL;
diff --git a/drivers/infiniband/ulp/iser/iser_memory.c b/drivers/infiniband/ulp/iser/iser_memory.c
index d68798061795..4a17743a639f 100644
--- a/drivers/infiniband/ulp/iser/iser_memory.c
+++ b/drivers/infiniband/ulp/iser/iser_memory.c
@@ -310,13 +310,15 @@ static unsigned int iser_data_buf_aligned_len(struct iser_data_buf *data,
310 if (i + 1 < data->dma_nents) { 310 if (i + 1 < data->dma_nents) {
311 next_addr = ib_sg_dma_address(ibdev, sg_next(sg)); 311 next_addr = ib_sg_dma_address(ibdev, sg_next(sg));
312 /* are i, i+1 fragments of the same page? */ 312 /* are i, i+1 fragments of the same page? */
313 if (end_addr == next_addr) 313 if (end_addr == next_addr) {
314 cnt++;
314 continue; 315 continue;
315 else if (!IS_4K_ALIGNED(end_addr)) { 316 } else if (!IS_4K_ALIGNED(end_addr)) {
316 ret_len = cnt + 1; 317 ret_len = cnt + 1;
317 break; 318 break;
318 } 319 }
319 } 320 }
321 cnt++;
320 } 322 }
321 if (i == data->dma_nents) 323 if (i == data->dma_nents)
322 ret_len = cnt; /* loop ended */ 324 ret_len = cnt; /* loop ended */
diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
index 2316a018fae6..dfa6592c10f6 100644
--- a/drivers/input/keyboard/Kconfig
+++ b/drivers/input/keyboard/Kconfig
@@ -286,7 +286,7 @@ config KEYBOARD_MAPLE
286 286
287config KEYBOARD_BFIN 287config KEYBOARD_BFIN
288 tristate "Blackfin BF54x keypad support" 288 tristate "Blackfin BF54x keypad support"
289 depends on BF54x 289 depends on (BF54x && !BF544)
290 help 290 help
291 Say Y here if you want to use the BF54x keypad. 291 Say Y here if you want to use the BF54x keypad.
292 292
diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c
index 3eddf52a0bba..6a9ca4bdcb74 100644
--- a/drivers/input/keyboard/gpio_keys.c
+++ b/drivers/input/keyboard/gpio_keys.c
@@ -75,16 +75,32 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
75 75
76 for (i = 0; i < pdata->nbuttons; i++) { 76 for (i = 0; i < pdata->nbuttons; i++) {
77 struct gpio_keys_button *button = &pdata->buttons[i]; 77 struct gpio_keys_button *button = &pdata->buttons[i];
78 int irq = gpio_to_irq(button->gpio); 78 int irq;
79 unsigned int type = button->type ?: EV_KEY; 79 unsigned int type = button->type ?: EV_KEY;
80 80
81 error = gpio_request(button->gpio, button->desc ?: "gpio_keys");
82 if (error < 0) {
83 pr_err("gpio-keys: failed to request GPIO %d,"
84 " error %d\n", button->gpio, error);
85 goto fail;
86 }
87
88 error = gpio_direction_input(button->gpio);
89 if (error < 0) {
90 pr_err("gpio-keys: failed to configure input"
91 " direction for GPIO %d, error %d\n",
92 button->gpio, error);
93 gpio_free(button->gpio);
94 goto fail;
95 }
96
97 irq = gpio_to_irq(button->gpio);
81 if (irq < 0) { 98 if (irq < 0) {
82 error = irq; 99 error = irq;
83 printk(KERN_ERR 100 pr_err("gpio-keys: Unable to get irq number"
84 "gpio-keys: " 101 " for GPIO %d, error %d\n",
85 "Unable to get irq number for GPIO %d,"
86 "error %d\n",
87 button->gpio, error); 102 button->gpio, error);
103 gpio_free(button->gpio);
88 goto fail; 104 goto fail;
89 } 105 }
90 106
@@ -94,9 +110,9 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
94 button->desc ? button->desc : "gpio_keys", 110 button->desc ? button->desc : "gpio_keys",
95 pdev); 111 pdev);
96 if (error) { 112 if (error) {
97 printk(KERN_ERR 113 pr_err("gpio-keys: Unable to claim irq %d; error %d\n",
98 "gpio-keys: Unable to claim irq %d; error %d\n",
99 irq, error); 114 irq, error);
115 gpio_free(button->gpio);
100 goto fail; 116 goto fail;
101 } 117 }
102 118
@@ -108,8 +124,7 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
108 124
109 error = input_register_device(input); 125 error = input_register_device(input);
110 if (error) { 126 if (error) {
111 printk(KERN_ERR 127 pr_err("gpio-keys: Unable to register input device, "
112 "gpio-keys: Unable to register input device, "
113 "error: %d\n", error); 128 "error: %d\n", error);
114 goto fail; 129 goto fail;
115 } 130 }
@@ -119,8 +134,10 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
119 return 0; 134 return 0;
120 135
121 fail: 136 fail:
122 while (--i >= 0) 137 while (--i >= 0) {
123 free_irq(gpio_to_irq(pdata->buttons[i].gpio), pdev); 138 free_irq(gpio_to_irq(pdata->buttons[i].gpio), pdev);
139 gpio_free(pdata->buttons[i].gpio);
140 }
124 141
125 platform_set_drvdata(pdev, NULL); 142 platform_set_drvdata(pdev, NULL);
126 input_free_device(input); 143 input_free_device(input);
@@ -139,6 +156,7 @@ static int __devexit gpio_keys_remove(struct platform_device *pdev)
139 for (i = 0; i < pdata->nbuttons; i++) { 156 for (i = 0; i < pdata->nbuttons; i++) {
140 int irq = gpio_to_irq(pdata->buttons[i].gpio); 157 int irq = gpio_to_irq(pdata->buttons[i].gpio);
141 free_irq(irq, pdev); 158 free_irq(irq, pdev);
159 gpio_free(pdata->buttons[i].gpio);
142 } 160 }
143 161
144 input_unregister_device(input); 162 input_unregister_device(input);
diff --git a/drivers/input/serio/Kconfig b/drivers/input/serio/Kconfig
index 5ce632ca6815..b88569e21d60 100644
--- a/drivers/input/serio/Kconfig
+++ b/drivers/input/serio/Kconfig
@@ -21,7 +21,7 @@ if SERIO
21config SERIO_I8042 21config SERIO_I8042
22 tristate "i8042 PC Keyboard controller" if EMBEDDED || !X86 22 tristate "i8042 PC Keyboard controller" if EMBEDDED || !X86
23 default y 23 default y
24 depends on !PARISC && (!ARM || ARCH_SHARK || FOOTBRIDGE_HOST) && !M68K && !BFIN 24 depends on !PARISC && (!ARM || ARCH_SHARK || FOOTBRIDGE_HOST) && !M68K && !BLACKFIN
25 ---help--- 25 ---help---
26 i8042 is the chip over which the standard AT keyboard and PS/2 26 i8042 is the chip over which the standard AT keyboard and PS/2
27 mouse are connected to the computer. If you use these devices, 27 mouse are connected to the computer. If you use these devices,
diff --git a/drivers/input/serio/i8042-x86ia64io.h b/drivers/input/serio/i8042-x86ia64io.h
index f8fe42148093..c5e68dcd88ac 100644
--- a/drivers/input/serio/i8042-x86ia64io.h
+++ b/drivers/input/serio/i8042-x86ia64io.h
@@ -110,6 +110,14 @@ static struct dmi_system_id __initdata i8042_dmi_noloop_table[] = {
110 DMI_MATCH(DMI_PRODUCT_VERSION, "5a"), 110 DMI_MATCH(DMI_PRODUCT_VERSION, "5a"),
111 }, 111 },
112 }, 112 },
113 {
114 .ident = "Microsoft Virtual Machine",
115 .matches = {
116 DMI_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"),
117 DMI_MATCH(DMI_PRODUCT_NAME, "Virtual Machine"),
118 DMI_MATCH(DMI_PRODUCT_VERSION, "VS2005R2"),
119 },
120 },
113 { } 121 { }
114}; 122};
115 123
diff --git a/drivers/input/touchscreen/ads7846.c b/drivers/input/touchscreen/ads7846.c
index f59aecf5ec15..fd9c5d51870a 100644
--- a/drivers/input/touchscreen/ads7846.c
+++ b/drivers/input/touchscreen/ads7846.c
@@ -267,13 +267,12 @@ static int ads7846_read12_ser(struct device *dev, unsigned command)
267 ts->irq_disabled = 0; 267 ts->irq_disabled = 0;
268 enable_irq(spi->irq); 268 enable_irq(spi->irq);
269 269
270 if (req->msg.status) 270 if (status == 0) {
271 status = req->msg.status; 271 /* on-wire is a must-ignore bit, a BE12 value, then padding */
272 272 sample = be16_to_cpu(req->sample);
273 /* on-wire is a must-ignore bit, a BE12 value, then padding */ 273 sample = sample >> 3;
274 sample = be16_to_cpu(req->sample); 274 sample &= 0x0fff;
275 sample = sample >> 3; 275 }
276 sample &= 0x0fff;
277 276
278 kfree(req); 277 kfree(req);
279 return status ? status : sample; 278 return status ? status : sample;
diff --git a/drivers/isdn/hisax/hfcscard.c b/drivers/isdn/hisax/hfcscard.c
index 57670dc5034d..909d6709ec16 100644
--- a/drivers/isdn/hisax/hfcscard.c
+++ b/drivers/isdn/hisax/hfcscard.c
@@ -118,8 +118,7 @@ hfcs_card_msg(struct IsdnCardState *cs, int mt, void *arg)
118 return(0); 118 return(0);
119 case CARD_INIT: 119 case CARD_INIT:
120 delay = (75*HZ)/100 +1; 120 delay = (75*HZ)/100 +1;
121 cs->hw.hfcD.timer.expires = jiffies + delay; 121 mod_timer(&cs->hw.hfcD.timer, jiffies + delay);
122 add_timer(&cs->hw.hfcD.timer);
123 spin_lock_irqsave(&cs->lock, flags); 122 spin_lock_irqsave(&cs->lock, flags);
124 reset_hfcs(cs); 123 reset_hfcs(cs);
125 init2bds0(cs); 124 init2bds0(cs);
diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
index c6df2925ebd0..d6952959d72a 100644
--- a/drivers/isdn/i4l/isdn_common.c
+++ b/drivers/isdn/i4l/isdn_common.c
@@ -1515,6 +1515,7 @@ isdn_ioctl(struct inode *inode, struct file *file, uint cmd, ulong arg)
1515 if (copy_from_user(&iocts, argp, 1515 if (copy_from_user(&iocts, argp,
1516 sizeof(isdn_ioctl_struct))) 1516 sizeof(isdn_ioctl_struct)))
1517 return -EFAULT; 1517 return -EFAULT;
1518 iocts.drvid[sizeof(iocts.drvid)-1] = 0;
1518 if (strlen(iocts.drvid)) { 1519 if (strlen(iocts.drvid)) {
1519 if ((p = strchr(iocts.drvid, ','))) 1520 if ((p = strchr(iocts.drvid, ',')))
1520 *p = 0; 1521 *p = 0;
@@ -1599,6 +1600,7 @@ isdn_ioctl(struct inode *inode, struct file *file, uint cmd, ulong arg)
1599 if (copy_from_user(&iocts, argp, 1600 if (copy_from_user(&iocts, argp,
1600 sizeof(isdn_ioctl_struct))) 1601 sizeof(isdn_ioctl_struct)))
1601 return -EFAULT; 1602 return -EFAULT;
1603 iocts.drvid[sizeof(iocts.drvid)-1] = 0;
1602 if (strlen(iocts.drvid)) { 1604 if (strlen(iocts.drvid)) {
1603 drvidx = -1; 1605 drvidx = -1;
1604 for (i = 0; i < ISDN_MAX_DRIVERS; i++) 1606 for (i = 0; i < ISDN_MAX_DRIVERS; i++)
@@ -1643,7 +1645,7 @@ isdn_ioctl(struct inode *inode, struct file *file, uint cmd, ulong arg)
1643 } else { 1645 } else {
1644 p = (char __user *) iocts.arg; 1646 p = (char __user *) iocts.arg;
1645 for (i = 0; i < 10; i++) { 1647 for (i = 0; i < 10; i++) {
1646 sprintf(bname, "%s%s", 1648 snprintf(bname, sizeof(bname), "%s%s",
1647 strlen(dev->drv[drvidx]->msn2eaz[i]) ? 1649 strlen(dev->drv[drvidx]->msn2eaz[i]) ?
1648 dev->drv[drvidx]->msn2eaz[i] : "_", 1650 dev->drv[drvidx]->msn2eaz[i] : "_",
1649 (i < 9) ? "," : "\0"); 1651 (i < 9) ? "," : "\0");
@@ -1673,6 +1675,7 @@ isdn_ioctl(struct inode *inode, struct file *file, uint cmd, ulong arg)
1673 char *p; 1675 char *p;
1674 if (copy_from_user(&iocts, argp, sizeof(isdn_ioctl_struct))) 1676 if (copy_from_user(&iocts, argp, sizeof(isdn_ioctl_struct)))
1675 return -EFAULT; 1677 return -EFAULT;
1678 iocts.drvid[sizeof(iocts.drvid)-1] = 0;
1676 if (strlen(iocts.drvid)) { 1679 if (strlen(iocts.drvid)) {
1677 if ((p = strchr(iocts.drvid, ','))) 1680 if ((p = strchr(iocts.drvid, ',')))
1678 *p = 0; 1681 *p = 0;
diff --git a/drivers/isdn/i4l/isdn_net.c b/drivers/isdn/i4l/isdn_net.c
index b39d1f5b378e..ced83c202cac 100644
--- a/drivers/isdn/i4l/isdn_net.c
+++ b/drivers/isdn/i4l/isdn_net.c
@@ -2104,7 +2104,7 @@ isdn_net_find_icall(int di, int ch, int idx, setup_parm *setup)
2104 u_long flags; 2104 u_long flags;
2105 isdn_net_dev *p; 2105 isdn_net_dev *p;
2106 isdn_net_phone *n; 2106 isdn_net_phone *n;
2107 char nr[32]; 2107 char nr[ISDN_MSNLEN];
2108 char *my_eaz; 2108 char *my_eaz;
2109 2109
2110 /* Search name in netdev-chain */ 2110 /* Search name in netdev-chain */
@@ -2113,7 +2113,7 @@ isdn_net_find_icall(int di, int ch, int idx, setup_parm *setup)
2113 nr[1] = '\0'; 2113 nr[1] = '\0';
2114 printk(KERN_INFO "isdn_net: Incoming call without OAD, assuming '0'\n"); 2114 printk(KERN_INFO "isdn_net: Incoming call without OAD, assuming '0'\n");
2115 } else 2115 } else
2116 strcpy(nr, setup->phone); 2116 strlcpy(nr, setup->phone, ISDN_MSNLEN);
2117 si1 = (int) setup->si1; 2117 si1 = (int) setup->si1;
2118 si2 = (int) setup->si2; 2118 si2 = (int) setup->si2;
2119 if (!setup->eazmsn[0]) { 2119 if (!setup->eazmsn[0]) {
@@ -2789,7 +2789,7 @@ isdn_net_setcfg(isdn_net_ioctl_cfg * cfg)
2789 chidx = -1; 2789 chidx = -1;
2790 } 2790 }
2791 } 2791 }
2792 strcpy(lp->msn, cfg->eaz); 2792 strlcpy(lp->msn, cfg->eaz, sizeof(lp->msn));
2793 lp->pre_device = drvidx; 2793 lp->pre_device = drvidx;
2794 lp->pre_channel = chidx; 2794 lp->pre_channel = chidx;
2795 lp->onhtime = cfg->onhtime; 2795 lp->onhtime = cfg->onhtime;
@@ -2936,7 +2936,7 @@ isdn_net_addphone(isdn_net_ioctl_phone * phone)
2936 if (p) { 2936 if (p) {
2937 if (!(n = kmalloc(sizeof(isdn_net_phone), GFP_KERNEL))) 2937 if (!(n = kmalloc(sizeof(isdn_net_phone), GFP_KERNEL)))
2938 return -ENOMEM; 2938 return -ENOMEM;
2939 strcpy(n->num, phone->phone); 2939 strlcpy(n->num, phone->phone, sizeof(n->num));
2940 n->next = p->local->phone[phone->outgoing & 1]; 2940 n->next = p->local->phone[phone->outgoing & 1];
2941 p->local->phone[phone->outgoing & 1] = n; 2941 p->local->phone[phone->outgoing & 1] = n;
2942 return 0; 2942 return 0;
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index 07ae280e8fe5..47c10b8f89b3 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -1188,8 +1188,7 @@ int emulate_invlpg(struct kvm_vcpu *vcpu, gva_t address)
1188 1188
1189int emulate_clts(struct kvm_vcpu *vcpu) 1189int emulate_clts(struct kvm_vcpu *vcpu)
1190{ 1190{
1191 vcpu->cr0 &= ~X86_CR0_TS; 1191 kvm_x86_ops->set_cr0(vcpu, vcpu->cr0 & ~X86_CR0_TS);
1192 kvm_x86_ops->set_cr0(vcpu, vcpu->cr0);
1193 return X86EMUL_CONTINUE; 1192 return X86EMUL_CONTINUE;
1194} 1193}
1195 1194
diff --git a/drivers/kvm/svm.c b/drivers/kvm/svm.c
index 7a6eead63a6b..4e04e49a2f1c 100644
--- a/drivers/kvm/svm.c
+++ b/drivers/kvm/svm.c
@@ -663,6 +663,7 @@ static void svm_vcpu_put(struct kvm_vcpu *vcpu)
663 wrmsrl(host_save_user_msrs[i], svm->host_user_msrs[i]); 663 wrmsrl(host_save_user_msrs[i], svm->host_user_msrs[i]);
664 664
665 rdtscll(vcpu->host_tsc); 665 rdtscll(vcpu->host_tsc);
666 kvm_put_guest_fpu(vcpu);
666} 667}
667 668
668static void svm_vcpu_decache(struct kvm_vcpu *vcpu) 669static void svm_vcpu_decache(struct kvm_vcpu *vcpu)
diff --git a/drivers/kvm/x86_emulate.c b/drivers/kvm/x86_emulate.c
index 33b181451557..bd46de6bf891 100644
--- a/drivers/kvm/x86_emulate.c
+++ b/drivers/kvm/x86_emulate.c
@@ -448,8 +448,7 @@ struct operand {
448 448
449#define JMP_REL(rel) \ 449#define JMP_REL(rel) \
450 do { \ 450 do { \
451 _eip += (int)(rel); \ 451 register_address_increment(_eip, rel); \
452 _eip = ((op_bytes == 2) ? (uint16_t)_eip : (uint32_t)_eip); \
453 } while (0) 452 } while (0)
454 453
455/* 454/*
@@ -1147,7 +1146,7 @@ done_prefixes:
1147 } 1146 }
1148 register_address_increment(_regs[VCPU_REGS_RSP], 1147 register_address_increment(_regs[VCPU_REGS_RSP],
1149 -dst.bytes); 1148 -dst.bytes);
1150 if ((rc = ops->write_std( 1149 if ((rc = ops->write_emulated(
1151 register_address(ctxt->ss_base, 1150 register_address(ctxt->ss_base,
1152 _regs[VCPU_REGS_RSP]), 1151 _regs[VCPU_REGS_RSP]),
1153 &dst.val, dst.bytes, ctxt->vcpu)) != 0) 1152 &dst.val, dst.bytes, ctxt->vcpu)) != 0)
@@ -1359,6 +1358,7 @@ special_insn:
1359 } 1358 }
1360 src.val = (unsigned long) _eip; 1359 src.val = (unsigned long) _eip;
1361 JMP_REL(rel); 1360 JMP_REL(rel);
1361 op_bytes = ad_bytes;
1362 goto push; 1362 goto push;
1363 } 1363 }
1364 case 0xe9: /* jmp rel */ 1364 case 0xe9: /* jmp rel */
diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c
index 4211293ce862..ba8b04b03b9f 100644
--- a/drivers/leds/led-class.c
+++ b/drivers/leds/led-class.c
@@ -111,7 +111,7 @@ int led_classdev_register(struct device *parent, struct led_classdev *led_cdev)
111 write_unlock(&leds_list_lock); 111 write_unlock(&leds_list_lock);
112 112
113#ifdef CONFIG_LEDS_TRIGGERS 113#ifdef CONFIG_LEDS_TRIGGERS
114 rwlock_init(&led_cdev->trigger_lock); 114 init_rwsem(&led_cdev->trigger_lock);
115 115
116 rc = device_create_file(led_cdev->dev, &dev_attr_trigger); 116 rc = device_create_file(led_cdev->dev, &dev_attr_trigger);
117 if (rc) 117 if (rc)
@@ -147,10 +147,10 @@ void led_classdev_unregister(struct led_classdev *led_cdev)
147 device_remove_file(led_cdev->dev, &dev_attr_brightness); 147 device_remove_file(led_cdev->dev, &dev_attr_brightness);
148#ifdef CONFIG_LEDS_TRIGGERS 148#ifdef CONFIG_LEDS_TRIGGERS
149 device_remove_file(led_cdev->dev, &dev_attr_trigger); 149 device_remove_file(led_cdev->dev, &dev_attr_trigger);
150 write_lock(&led_cdev->trigger_lock); 150 down_write(&led_cdev->trigger_lock);
151 if (led_cdev->trigger) 151 if (led_cdev->trigger)
152 led_trigger_set(led_cdev, NULL); 152 led_trigger_set(led_cdev, NULL);
153 write_unlock(&led_cdev->trigger_lock); 153 up_write(&led_cdev->trigger_lock);
154#endif 154#endif
155 155
156 device_unregister(led_cdev->dev); 156 device_unregister(led_cdev->dev);
diff --git a/drivers/leds/led-triggers.c b/drivers/leds/led-triggers.c
index 575368c2b100..0bdb786210b1 100644
--- a/drivers/leds/led-triggers.c
+++ b/drivers/leds/led-triggers.c
@@ -19,13 +19,14 @@
19#include <linux/device.h> 19#include <linux/device.h>
20#include <linux/sysdev.h> 20#include <linux/sysdev.h>
21#include <linux/timer.h> 21#include <linux/timer.h>
22#include <linux/rwsem.h>
22#include <linux/leds.h> 23#include <linux/leds.h>
23#include "leds.h" 24#include "leds.h"
24 25
25/* 26/*
26 * Nests outside led_cdev->trigger_lock 27 * Nests outside led_cdev->trigger_lock
27 */ 28 */
28static DEFINE_RWLOCK(triggers_list_lock); 29static DECLARE_RWSEM(triggers_list_lock);
29static LIST_HEAD(trigger_list); 30static LIST_HEAD(trigger_list);
30 31
31ssize_t led_trigger_store(struct device *dev, struct device_attribute *attr, 32ssize_t led_trigger_store(struct device *dev, struct device_attribute *attr,
@@ -44,24 +45,24 @@ ssize_t led_trigger_store(struct device *dev, struct device_attribute *attr,
44 trigger_name[len - 1] = '\0'; 45 trigger_name[len - 1] = '\0';
45 46
46 if (!strcmp(trigger_name, "none")) { 47 if (!strcmp(trigger_name, "none")) {
47 write_lock(&led_cdev->trigger_lock); 48 down_write(&led_cdev->trigger_lock);
48 led_trigger_set(led_cdev, NULL); 49 led_trigger_set(led_cdev, NULL);
49 write_unlock(&led_cdev->trigger_lock); 50 up_write(&led_cdev->trigger_lock);
50 return count; 51 return count;
51 } 52 }
52 53
53 read_lock(&triggers_list_lock); 54 down_read(&triggers_list_lock);
54 list_for_each_entry(trig, &trigger_list, next_trig) { 55 list_for_each_entry(trig, &trigger_list, next_trig) {
55 if (!strcmp(trigger_name, trig->name)) { 56 if (!strcmp(trigger_name, trig->name)) {
56 write_lock(&led_cdev->trigger_lock); 57 down_write(&led_cdev->trigger_lock);
57 led_trigger_set(led_cdev, trig); 58 led_trigger_set(led_cdev, trig);
58 write_unlock(&led_cdev->trigger_lock); 59 up_write(&led_cdev->trigger_lock);
59 60
60 read_unlock(&triggers_list_lock); 61 up_read(&triggers_list_lock);
61 return count; 62 return count;
62 } 63 }
63 } 64 }
64 read_unlock(&triggers_list_lock); 65 up_read(&triggers_list_lock);
65 66
66 return -EINVAL; 67 return -EINVAL;
67} 68}
@@ -74,8 +75,8 @@ ssize_t led_trigger_show(struct device *dev, struct device_attribute *attr,
74 struct led_trigger *trig; 75 struct led_trigger *trig;
75 int len = 0; 76 int len = 0;
76 77
77 read_lock(&triggers_list_lock); 78 down_read(&triggers_list_lock);
78 read_lock(&led_cdev->trigger_lock); 79 down_read(&led_cdev->trigger_lock);
79 80
80 if (!led_cdev->trigger) 81 if (!led_cdev->trigger)
81 len += sprintf(buf+len, "[none] "); 82 len += sprintf(buf+len, "[none] ");
@@ -89,8 +90,8 @@ ssize_t led_trigger_show(struct device *dev, struct device_attribute *attr,
89 else 90 else
90 len += sprintf(buf+len, "%s ", trig->name); 91 len += sprintf(buf+len, "%s ", trig->name);
91 } 92 }
92 read_unlock(&led_cdev->trigger_lock); 93 up_read(&led_cdev->trigger_lock);
93 read_unlock(&triggers_list_lock); 94 up_read(&triggers_list_lock);
94 95
95 len += sprintf(len+buf, "\n"); 96 len += sprintf(len+buf, "\n");
96 return len; 97 return len;
@@ -145,14 +146,14 @@ void led_trigger_set_default(struct led_classdev *led_cdev)
145 if (!led_cdev->default_trigger) 146 if (!led_cdev->default_trigger)
146 return; 147 return;
147 148
148 read_lock(&triggers_list_lock); 149 down_read(&triggers_list_lock);
149 write_lock(&led_cdev->trigger_lock); 150 down_write(&led_cdev->trigger_lock);
150 list_for_each_entry(trig, &trigger_list, next_trig) { 151 list_for_each_entry(trig, &trigger_list, next_trig) {
151 if (!strcmp(led_cdev->default_trigger, trig->name)) 152 if (!strcmp(led_cdev->default_trigger, trig->name))
152 led_trigger_set(led_cdev, trig); 153 led_trigger_set(led_cdev, trig);
153 } 154 }
154 write_unlock(&led_cdev->trigger_lock); 155 up_write(&led_cdev->trigger_lock);
155 read_unlock(&triggers_list_lock); 156 up_read(&triggers_list_lock);
156} 157}
157 158
158int led_trigger_register(struct led_trigger *trigger) 159int led_trigger_register(struct led_trigger *trigger)
@@ -163,18 +164,18 @@ int led_trigger_register(struct led_trigger *trigger)
163 INIT_LIST_HEAD(&trigger->led_cdevs); 164 INIT_LIST_HEAD(&trigger->led_cdevs);
164 165
165 /* Add to the list of led triggers */ 166 /* Add to the list of led triggers */
166 write_lock(&triggers_list_lock); 167 down_write(&triggers_list_lock);
167 list_add_tail(&trigger->next_trig, &trigger_list); 168 list_add_tail(&trigger->next_trig, &trigger_list);
168 write_unlock(&triggers_list_lock); 169 up_write(&triggers_list_lock);
169 170
170 /* Register with any LEDs that have this as a default trigger */ 171 /* Register with any LEDs that have this as a default trigger */
171 read_lock(&leds_list_lock); 172 read_lock(&leds_list_lock);
172 list_for_each_entry(led_cdev, &leds_list, node) { 173 list_for_each_entry(led_cdev, &leds_list, node) {
173 write_lock(&led_cdev->trigger_lock); 174 down_write(&led_cdev->trigger_lock);
174 if (!led_cdev->trigger && led_cdev->default_trigger && 175 if (!led_cdev->trigger && led_cdev->default_trigger &&
175 !strcmp(led_cdev->default_trigger, trigger->name)) 176 !strcmp(led_cdev->default_trigger, trigger->name))
176 led_trigger_set(led_cdev, trigger); 177 led_trigger_set(led_cdev, trigger);
177 write_unlock(&led_cdev->trigger_lock); 178 up_write(&led_cdev->trigger_lock);
178 } 179 }
179 read_unlock(&leds_list_lock); 180 read_unlock(&leds_list_lock);
180 181
@@ -206,17 +207,17 @@ void led_trigger_unregister(struct led_trigger *trigger)
206 struct led_classdev *led_cdev; 207 struct led_classdev *led_cdev;
207 208
208 /* Remove from the list of led triggers */ 209 /* Remove from the list of led triggers */
209 write_lock(&triggers_list_lock); 210 down_write(&triggers_list_lock);
210 list_del(&trigger->next_trig); 211 list_del(&trigger->next_trig);
211 write_unlock(&triggers_list_lock); 212 up_write(&triggers_list_lock);
212 213
213 /* Remove anyone actively using this trigger */ 214 /* Remove anyone actively using this trigger */
214 read_lock(&leds_list_lock); 215 read_lock(&leds_list_lock);
215 list_for_each_entry(led_cdev, &leds_list, node) { 216 list_for_each_entry(led_cdev, &leds_list, node) {
216 write_lock(&led_cdev->trigger_lock); 217 down_write(&led_cdev->trigger_lock);
217 if (led_cdev->trigger == trigger) 218 if (led_cdev->trigger == trigger)
218 led_trigger_set(led_cdev, NULL); 219 led_trigger_set(led_cdev, NULL);
219 write_unlock(&led_cdev->trigger_lock); 220 up_write(&led_cdev->trigger_lock);
220 } 221 }
221 read_unlock(&leds_list_lock); 222 read_unlock(&leds_list_lock);
222} 223}
diff --git a/drivers/lguest/lguest_device.c b/drivers/lguest/lguest_device.c
index 66f38722253a..e2eec38c83c2 100644
--- a/drivers/lguest/lguest_device.c
+++ b/drivers/lguest/lguest_device.c
@@ -247,6 +247,8 @@ static void lg_del_vq(struct virtqueue *vq)
247{ 247{
248 struct lguest_vq_info *lvq = vq->priv; 248 struct lguest_vq_info *lvq = vq->priv;
249 249
250 /* Release the interrupt */
251 free_irq(lvq->config.irq, vq);
250 /* Tell virtio_ring.c to free the virtqueue. */ 252 /* Tell virtio_ring.c to free the virtqueue. */
251 vring_del_virtqueue(vq); 253 vring_del_virtqueue(vq);
252 /* Unmap the pages containing the ring. */ 254 /* Unmap the pages containing the ring. */
diff --git a/drivers/macintosh/via-pmu.c b/drivers/macintosh/via-pmu.c
index dc741d3a4531..6123c70153d3 100644
--- a/drivers/macintosh/via-pmu.c
+++ b/drivers/macintosh/via-pmu.c
@@ -2336,6 +2336,7 @@ powerbook_sleep_3400(void)
2336 ret = pmac_suspend_devices(); 2336 ret = pmac_suspend_devices();
2337 if (ret) { 2337 if (ret) {
2338 pbook_free_pci_save(); 2338 pbook_free_pci_save();
2339 iounmap(mem_ctrl);
2339 printk(KERN_ERR "Sleep rejected by devices\n"); 2340 printk(KERN_ERR "Sleep rejected by devices\n");
2340 return ret; 2341 return ret;
2341 } 2342 }
diff --git a/drivers/md/Kconfig b/drivers/md/Kconfig
index 9b6fbf044fd8..3fa7c77d9bd9 100644
--- a/drivers/md/Kconfig
+++ b/drivers/md/Kconfig
@@ -269,7 +269,7 @@ config DM_MULTIPATH_RDAC
269 269
270config DM_MULTIPATH_HP 270config DM_MULTIPATH_HP
271 tristate "HP MSA multipath support (EXPERIMENTAL)" 271 tristate "HP MSA multipath support (EXPERIMENTAL)"
272 depends on DM_MULTIPATH && BLK_DEV_DM && EXPERIMENTAL 272 depends on DM_MULTIPATH && BLK_DEV_DM && SCSI && EXPERIMENTAL
273 ---help--- 273 ---help---
274 Multipath support for HP MSA (Active/Passive) series hardware. 274 Multipath support for HP MSA (Active/Passive) series hardware.
275 275
diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c
index 28c6ae095c56..6b66ee46b87d 100644
--- a/drivers/md/dm-crypt.c
+++ b/drivers/md/dm-crypt.c
@@ -398,7 +398,8 @@ static struct bio *crypt_alloc_buffer(struct dm_crypt_io *io, unsigned size)
398 struct bio *clone; 398 struct bio *clone;
399 unsigned int nr_iovecs = (size + PAGE_SIZE - 1) >> PAGE_SHIFT; 399 unsigned int nr_iovecs = (size + PAGE_SIZE - 1) >> PAGE_SHIFT;
400 gfp_t gfp_mask = GFP_NOIO | __GFP_HIGHMEM; 400 gfp_t gfp_mask = GFP_NOIO | __GFP_HIGHMEM;
401 unsigned int i; 401 unsigned i, len;
402 struct page *page;
402 403
403 clone = bio_alloc_bioset(GFP_NOIO, nr_iovecs, cc->bs); 404 clone = bio_alloc_bioset(GFP_NOIO, nr_iovecs, cc->bs);
404 if (!clone) 405 if (!clone)
@@ -407,10 +408,8 @@ static struct bio *crypt_alloc_buffer(struct dm_crypt_io *io, unsigned size)
407 clone_init(io, clone); 408 clone_init(io, clone);
408 409
409 for (i = 0; i < nr_iovecs; i++) { 410 for (i = 0; i < nr_iovecs; i++) {
410 struct bio_vec *bv = bio_iovec_idx(clone, i); 411 page = mempool_alloc(cc->page_pool, gfp_mask);
411 412 if (!page)
412 bv->bv_page = mempool_alloc(cc->page_pool, gfp_mask);
413 if (!bv->bv_page)
414 break; 413 break;
415 414
416 /* 415 /*
@@ -421,15 +420,14 @@ static struct bio *crypt_alloc_buffer(struct dm_crypt_io *io, unsigned size)
421 if (i == (MIN_BIO_PAGES - 1)) 420 if (i == (MIN_BIO_PAGES - 1))
422 gfp_mask = (gfp_mask | __GFP_NOWARN) & ~__GFP_WAIT; 421 gfp_mask = (gfp_mask | __GFP_NOWARN) & ~__GFP_WAIT;
423 422
424 bv->bv_offset = 0; 423 len = (size > PAGE_SIZE) ? PAGE_SIZE : size;
425 if (size > PAGE_SIZE) 424
426 bv->bv_len = PAGE_SIZE; 425 if (!bio_add_page(clone, page, len, 0)) {
427 else 426 mempool_free(page, cc->page_pool);
428 bv->bv_len = size; 427 break;
428 }
429 429
430 clone->bi_size += bv->bv_len; 430 size -= len;
431 clone->bi_vcnt++;
432 size -= bv->bv_len;
433 } 431 }
434 432
435 if (!clone->bi_size) { 433 if (!clone->bi_size) {
@@ -511,6 +509,9 @@ static void crypt_endio(struct bio *clone, int error)
511 struct crypt_config *cc = io->target->private; 509 struct crypt_config *cc = io->target->private;
512 unsigned read_io = bio_data_dir(clone) == READ; 510 unsigned read_io = bio_data_dir(clone) == READ;
513 511
512 if (unlikely(!bio_flagged(clone, BIO_UPTODATE) && !error))
513 error = -EIO;
514
514 /* 515 /*
515 * free the processed pages 516 * free the processed pages
516 */ 517 */
@@ -519,10 +520,8 @@ static void crypt_endio(struct bio *clone, int error)
519 goto out; 520 goto out;
520 } 521 }
521 522
522 if (unlikely(!bio_flagged(clone, BIO_UPTODATE))) { 523 if (unlikely(error))
523 error = -EIO;
524 goto out; 524 goto out;
525 }
526 525
527 bio_put(clone); 526 bio_put(clone);
528 kcryptd_queue_crypt(io); 527 kcryptd_queue_crypt(io);
diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
index 138200bf5e0b..9627fa0f9470 100644
--- a/drivers/md/dm-ioctl.c
+++ b/drivers/md/dm-ioctl.c
@@ -332,6 +332,8 @@ static int dm_hash_rename(const char *old, const char *new)
332 dm_table_put(table); 332 dm_table_put(table);
333 } 333 }
334 334
335 dm_kobject_uevent(hc->md);
336
335 dm_put(hc->md); 337 dm_put(hc->md);
336 up_write(&_hash_lock); 338 up_write(&_hash_lock);
337 kfree(old_name); 339 kfree(old_name);
@@ -1250,21 +1252,17 @@ static int target_message(struct dm_ioctl *param, size_t param_size)
1250 if (!table) 1252 if (!table)
1251 goto out_argv; 1253 goto out_argv;
1252 1254
1253 if (tmsg->sector >= dm_table_get_size(table)) { 1255 ti = dm_table_find_target(table, tmsg->sector);
1256 if (!dm_target_is_valid(ti)) {
1254 DMWARN("Target message sector outside device."); 1257 DMWARN("Target message sector outside device.");
1255 r = -EINVAL; 1258 r = -EINVAL;
1256 goto out_table; 1259 } else if (ti->type->message)
1257 }
1258
1259 ti = dm_table_find_target(table, tmsg->sector);
1260 if (ti->type->message)
1261 r = ti->type->message(ti, argc, argv); 1260 r = ti->type->message(ti, argc, argv);
1262 else { 1261 else {
1263 DMWARN("Target type does not support messages"); 1262 DMWARN("Target type does not support messages");
1264 r = -EINVAL; 1263 r = -EINVAL;
1265 } 1264 }
1266 1265
1267 out_table:
1268 dm_table_put(table); 1266 dm_table_put(table);
1269 out_argv: 1267 out_argv:
1270 kfree(argv); 1268 kfree(argv);
diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
index e298d8d11f24..47818d8249cb 100644
--- a/drivers/md/dm-table.c
+++ b/drivers/md/dm-table.c
@@ -99,6 +99,9 @@ static void combine_restrictions_low(struct io_restrictions *lhs,
99 lhs->max_segment_size = 99 lhs->max_segment_size =
100 min_not_zero(lhs->max_segment_size, rhs->max_segment_size); 100 min_not_zero(lhs->max_segment_size, rhs->max_segment_size);
101 101
102 lhs->max_hw_sectors =
103 min_not_zero(lhs->max_hw_sectors, rhs->max_hw_sectors);
104
102 lhs->seg_boundary_mask = 105 lhs->seg_boundary_mask =
103 min_not_zero(lhs->seg_boundary_mask, rhs->seg_boundary_mask); 106 min_not_zero(lhs->seg_boundary_mask, rhs->seg_boundary_mask);
104 107
@@ -189,8 +192,10 @@ static int alloc_targets(struct dm_table *t, unsigned int num)
189 192
190 /* 193 /*
191 * Allocate both the target array and offset array at once. 194 * Allocate both the target array and offset array at once.
195 * Append an empty entry to catch sectors beyond the end of
196 * the device.
192 */ 197 */
193 n_highs = (sector_t *) dm_vcalloc(num, sizeof(struct dm_target) + 198 n_highs = (sector_t *) dm_vcalloc(num + 1, sizeof(struct dm_target) +
194 sizeof(sector_t)); 199 sizeof(sector_t));
195 if (!n_highs) 200 if (!n_highs)
196 return -ENOMEM; 201 return -ENOMEM;
@@ -564,6 +569,9 @@ void dm_set_device_limits(struct dm_target *ti, struct block_device *bdev)
564 rs->max_segment_size = 569 rs->max_segment_size =
565 min_not_zero(rs->max_segment_size, q->max_segment_size); 570 min_not_zero(rs->max_segment_size, q->max_segment_size);
566 571
572 rs->max_hw_sectors =
573 min_not_zero(rs->max_hw_sectors, q->max_hw_sectors);
574
567 rs->seg_boundary_mask = 575 rs->seg_boundary_mask =
568 min_not_zero(rs->seg_boundary_mask, 576 min_not_zero(rs->seg_boundary_mask,
569 q->seg_boundary_mask); 577 q->seg_boundary_mask);
@@ -701,6 +709,8 @@ static void check_for_valid_limits(struct io_restrictions *rs)
701{ 709{
702 if (!rs->max_sectors) 710 if (!rs->max_sectors)
703 rs->max_sectors = SAFE_MAX_SECTORS; 711 rs->max_sectors = SAFE_MAX_SECTORS;
712 if (!rs->max_hw_sectors)
713 rs->max_hw_sectors = SAFE_MAX_SECTORS;
704 if (!rs->max_phys_segments) 714 if (!rs->max_phys_segments)
705 rs->max_phys_segments = MAX_PHYS_SEGMENTS; 715 rs->max_phys_segments = MAX_PHYS_SEGMENTS;
706 if (!rs->max_hw_segments) 716 if (!rs->max_hw_segments)
@@ -867,6 +877,9 @@ struct dm_target *dm_table_get_target(struct dm_table *t, unsigned int index)
867 877
868/* 878/*
869 * Search the btree for the correct target. 879 * Search the btree for the correct target.
880 *
881 * Caller should check returned pointer with dm_target_is_valid()
882 * to trap I/O beyond end of device.
870 */ 883 */
871struct dm_target *dm_table_find_target(struct dm_table *t, sector_t sector) 884struct dm_target *dm_table_find_target(struct dm_table *t, sector_t sector)
872{ 885{
@@ -896,6 +909,7 @@ void dm_table_set_restrictions(struct dm_table *t, struct request_queue *q)
896 q->max_hw_segments = t->limits.max_hw_segments; 909 q->max_hw_segments = t->limits.max_hw_segments;
897 q->hardsect_size = t->limits.hardsect_size; 910 q->hardsect_size = t->limits.hardsect_size;
898 q->max_segment_size = t->limits.max_segment_size; 911 q->max_segment_size = t->limits.max_segment_size;
912 q->max_hw_sectors = t->limits.max_hw_sectors;
899 q->seg_boundary_mask = t->limits.seg_boundary_mask; 913 q->seg_boundary_mask = t->limits.seg_boundary_mask;
900 q->bounce_pfn = t->limits.bounce_pfn; 914 q->bounce_pfn = t->limits.bounce_pfn;
901 if (t->limits.no_cluster) 915 if (t->limits.no_cluster)
diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index 07cbbb8eb3e0..88c0fd657825 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -672,13 +672,19 @@ static struct bio *clone_bio(struct bio *bio, sector_t sector,
672 return clone; 672 return clone;
673} 673}
674 674
675static void __clone_and_map(struct clone_info *ci) 675static int __clone_and_map(struct clone_info *ci)
676{ 676{
677 struct bio *clone, *bio = ci->bio; 677 struct bio *clone, *bio = ci->bio;
678 struct dm_target *ti = dm_table_find_target(ci->map, ci->sector); 678 struct dm_target *ti;
679 sector_t len = 0, max = max_io_len(ci->md, ci->sector, ti); 679 sector_t len = 0, max;
680 struct dm_target_io *tio; 680 struct dm_target_io *tio;
681 681
682 ti = dm_table_find_target(ci->map, ci->sector);
683 if (!dm_target_is_valid(ti))
684 return -EIO;
685
686 max = max_io_len(ci->md, ci->sector, ti);
687
682 /* 688 /*
683 * Allocate a target io object. 689 * Allocate a target io object.
684 */ 690 */
@@ -736,6 +742,9 @@ static void __clone_and_map(struct clone_info *ci)
736 do { 742 do {
737 if (offset) { 743 if (offset) {
738 ti = dm_table_find_target(ci->map, ci->sector); 744 ti = dm_table_find_target(ci->map, ci->sector);
745 if (!dm_target_is_valid(ti))
746 return -EIO;
747
739 max = max_io_len(ci->md, ci->sector, ti); 748 max = max_io_len(ci->md, ci->sector, ti);
740 749
741 tio = alloc_tio(ci->md); 750 tio = alloc_tio(ci->md);
@@ -759,6 +768,8 @@ static void __clone_and_map(struct clone_info *ci)
759 768
760 ci->idx++; 769 ci->idx++;
761 } 770 }
771
772 return 0;
762} 773}
763 774
764/* 775/*
@@ -767,6 +778,7 @@ static void __clone_and_map(struct clone_info *ci)
767static int __split_bio(struct mapped_device *md, struct bio *bio) 778static int __split_bio(struct mapped_device *md, struct bio *bio)
768{ 779{
769 struct clone_info ci; 780 struct clone_info ci;
781 int error = 0;
770 782
771 ci.map = dm_get_table(md); 783 ci.map = dm_get_table(md);
772 if (unlikely(!ci.map)) 784 if (unlikely(!ci.map))
@@ -784,11 +796,11 @@ static int __split_bio(struct mapped_device *md, struct bio *bio)
784 ci.idx = bio->bi_idx; 796 ci.idx = bio->bi_idx;
785 797
786 start_io_acct(ci.io); 798 start_io_acct(ci.io);
787 while (ci.sector_count) 799 while (ci.sector_count && !error)
788 __clone_and_map(&ci); 800 error = __clone_and_map(&ci);
789 801
790 /* drop the extra reference count */ 802 /* drop the extra reference count */
791 dec_pending(ci.io, 0); 803 dec_pending(ci.io, error);
792 dm_table_put(ci.map); 804 dm_table_put(ci.map);
793 805
794 return 0; 806 return 0;
@@ -1502,7 +1514,7 @@ int dm_resume(struct mapped_device *md)
1502 1514
1503 dm_table_unplug_all(map); 1515 dm_table_unplug_all(map);
1504 1516
1505 kobject_uevent(&md->disk->kobj, KOBJ_CHANGE); 1517 dm_kobject_uevent(md);
1506 1518
1507 r = 0; 1519 r = 0;
1508 1520
@@ -1516,6 +1528,11 @@ out:
1516/*----------------------------------------------------------------- 1528/*-----------------------------------------------------------------
1517 * Event notification. 1529 * Event notification.
1518 *---------------------------------------------------------------*/ 1530 *---------------------------------------------------------------*/
1531void dm_kobject_uevent(struct mapped_device *md)
1532{
1533 kobject_uevent(&md->disk->kobj, KOBJ_CHANGE);
1534}
1535
1519uint32_t dm_next_uevent_seq(struct mapped_device *md) 1536uint32_t dm_next_uevent_seq(struct mapped_device *md)
1520{ 1537{
1521 return atomic_add_return(1, &md->uevent_seq); 1538 return atomic_add_return(1, &md->uevent_seq);
diff --git a/drivers/md/dm.h b/drivers/md/dm.h
index 4b3faa45277e..b4584a39383b 100644
--- a/drivers/md/dm.h
+++ b/drivers/md/dm.h
@@ -112,6 +112,11 @@ int dm_table_resume_targets(struct dm_table *t);
112int dm_table_any_congested(struct dm_table *t, int bdi_bits); 112int dm_table_any_congested(struct dm_table *t, int bdi_bits);
113void dm_table_unplug_all(struct dm_table *t); 113void dm_table_unplug_all(struct dm_table *t);
114 114
115/*
116 * To check the return value from dm_table_find_target().
117 */
118#define dm_target_is_valid(t) ((t)->table)
119
115/*----------------------------------------------------------------- 120/*-----------------------------------------------------------------
116 * A registry of target types. 121 * A registry of target types.
117 *---------------------------------------------------------------*/ 122 *---------------------------------------------------------------*/
@@ -182,4 +187,6 @@ union map_info *dm_get_mapinfo(struct bio *bio);
182int dm_open_count(struct mapped_device *md); 187int dm_open_count(struct mapped_device *md);
183int dm_lock_for_deletion(struct mapped_device *md); 188int dm_lock_for_deletion(struct mapped_device *md);
184 189
190void dm_kobject_uevent(struct mapped_device *md);
191
185#endif 192#endif
diff --git a/drivers/media/Makefile b/drivers/media/Makefile
index 8fa19939c2b6..8cf91353b56a 100644
--- a/drivers/media/Makefile
+++ b/drivers/media/Makefile
@@ -3,6 +3,6 @@
3# 3#
4 4
5obj-y := common/ 5obj-y := common/
6obj-$(CONFIG_VIDEO_DEV) += video/ 6obj-y += video/
7obj-$(CONFIG_VIDEO_DEV) += radio/ 7obj-$(CONFIG_VIDEO_DEV) += radio/
8obj-$(CONFIG_DVB_CORE) += dvb/ 8obj-$(CONFIG_DVB_CORE) += dvb/
diff --git a/drivers/media/common/saa7146_video.c b/drivers/media/common/saa7146_video.c
index f245a3b2ef47..ae36d101006b 100644
--- a/drivers/media/common/saa7146_video.c
+++ b/drivers/media/common/saa7146_video.c
@@ -1205,13 +1205,10 @@ int saa7146_video_do_ioctl(struct inode *inode, struct file *file, unsigned int
1205 DEB_D(("VIDIOCGMBUF \n")); 1205 DEB_D(("VIDIOCGMBUF \n"));
1206 1206
1207 q = &fh->video_q; 1207 q = &fh->video_q;
1208 mutex_lock(&q->lock);
1209 err = videobuf_mmap_setup(q,gbuffers,gbufsize, 1208 err = videobuf_mmap_setup(q,gbuffers,gbufsize,
1210 V4L2_MEMORY_MMAP); 1209 V4L2_MEMORY_MMAP);
1211 if (err < 0) { 1210 if (err < 0)
1212 mutex_unlock(&q->lock);
1213 return err; 1211 return err;
1214 }
1215 1212
1216 gbuffers = err; 1213 gbuffers = err;
1217 memset(mbuf,0,sizeof(*mbuf)); 1214 memset(mbuf,0,sizeof(*mbuf));
@@ -1219,7 +1216,6 @@ int saa7146_video_do_ioctl(struct inode *inode, struct file *file, unsigned int
1219 mbuf->size = gbuffers * gbufsize; 1216 mbuf->size = gbuffers * gbufsize;
1220 for (i = 0; i < gbuffers; i++) 1217 for (i = 0; i < gbuffers; i++)
1221 mbuf->offsets[i] = i * gbufsize; 1218 mbuf->offsets[i] = i * gbufsize;
1222 mutex_unlock(&q->lock);
1223 return 0; 1219 return 0;
1224 } 1220 }
1225#endif 1221#endif
@@ -1440,10 +1436,7 @@ static void video_close(struct saa7146_dev *dev, struct file *file)
1440 err = saa7146_stop_preview(fh); 1436 err = saa7146_stop_preview(fh);
1441 } 1437 }
1442 1438
1443 // release all capture buffers 1439 videobuf_stop(q);
1444 mutex_lock(&q->lock);
1445 videobuf_read_stop(q);
1446 mutex_unlock(&q->lock);
1447 1440
1448 /* hmm, why is this function declared void? */ 1441 /* hmm, why is this function declared void? */
1449 /* return err */ 1442 /* return err */
diff --git a/drivers/media/dvb/dvb-usb/Makefile b/drivers/media/dvb/dvb-usb/Makefile
index 73ac0a93fdeb..60a910052c16 100644
--- a/drivers/media/dvb/dvb-usb/Makefile
+++ b/drivers/media/dvb/dvb-usb/Makefile
@@ -62,3 +62,6 @@ dvb-usb-af9005-remote-objs = af9005-remote.o
62obj-$(CONFIG_DVB_USB_AF9005_REMOTE) += dvb-usb-af9005-remote.o 62obj-$(CONFIG_DVB_USB_AF9005_REMOTE) += dvb-usb-af9005-remote.o
63 63
64EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core/ -Idrivers/media/dvb/frontends/ 64EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core/ -Idrivers/media/dvb/frontends/
65# due to tuner-xc3028
66EXTRA_CFLAGS += -Idrivers/media/video
67
diff --git a/drivers/media/dvb/dvb-usb/dibusb-common.c b/drivers/media/dvb/dvb-usb/dibusb-common.c
index 9a184da01c47..8ee6cd4da9e7 100644
--- a/drivers/media/dvb/dvb-usb/dibusb-common.c
+++ b/drivers/media/dvb/dvb-usb/dibusb-common.c
@@ -223,6 +223,9 @@ static struct dibx000_agc_config dib3000p_panasonic_agc_config = {
223 .agc2_slope2 = 0x1e, 223 .agc2_slope2 = 0x1e,
224}; 224};
225 225
226#if defined(CONFIG_DVB_DIB3000MC) || \
227 (defined(CONFIG_DVB_DIB3000MC_MODULE) && defined(MODULE))
228
226static struct dib3000mc_config mod3000p_dib3000p_config = { 229static struct dib3000mc_config mod3000p_dib3000p_config = {
227 &dib3000p_panasonic_agc_config, 230 &dib3000p_panasonic_agc_config,
228 231
@@ -305,6 +308,7 @@ int dibusb_dib3000mc_tuner_attach(struct dvb_usb_adapter *adap)
305 return 0; 308 return 0;
306} 309}
307EXPORT_SYMBOL(dibusb_dib3000mc_tuner_attach); 310EXPORT_SYMBOL(dibusb_dib3000mc_tuner_attach);
311#endif
308 312
309/* 313/*
310 * common remote control stuff 314 * common remote control stuff
diff --git a/drivers/media/dvb/frontends/s5h1409.c b/drivers/media/dvb/frontends/s5h1409.c
index 8dee7ec9456a..562d9208857a 100644
--- a/drivers/media/dvb/frontends/s5h1409.c
+++ b/drivers/media/dvb/frontends/s5h1409.c
@@ -107,7 +107,7 @@ static struct vsb_snr_tab {
107 u16 val; 107 u16 val;
108 u16 data; 108 u16 data;
109} vsb_snr_tab[] = { 109} vsb_snr_tab[] = {
110 { 1023, 770, }, 110 { 924, 300, },
111 { 923, 300, }, 111 { 923, 300, },
112 { 918, 295, }, 112 { 918, 295, },
113 { 915, 290, }, 113 { 915, 290, },
@@ -154,6 +154,7 @@ static struct qam64_snr_tab {
154 u16 val; 154 u16 val;
155 u16 data; 155 u16 data;
156} qam64_snr_tab[] = { 156} qam64_snr_tab[] = {
157 { 1, 0, },
157 { 12, 300, }, 158 { 12, 300, },
158 { 15, 290, }, 159 { 15, 290, },
159 { 18, 280, }, 160 { 18, 280, },
@@ -217,6 +218,7 @@ static struct qam64_snr_tab {
217 { 95, 202, }, 218 { 95, 202, },
218 { 96, 201, }, 219 { 96, 201, },
219 { 104, 200, }, 220 { 104, 200, },
221 { 255, 0, },
220}; 222};
221 223
222/* QAM256 SNR lookup table */ 224/* QAM256 SNR lookup table */
@@ -224,6 +226,7 @@ static struct qam256_snr_tab {
224 u16 val; 226 u16 val;
225 u16 data; 227 u16 data;
226} qam256_snr_tab[] = { 228} qam256_snr_tab[] = {
229 { 1, 0, },
227 { 12, 400, }, 230 { 12, 400, },
228 { 13, 390, }, 231 { 13, 390, },
229 { 15, 380, }, 232 { 15, 380, },
@@ -292,6 +295,7 @@ static struct qam256_snr_tab {
292 { 105, 262, }, 295 { 105, 262, },
293 { 106, 261, }, 296 { 106, 261, },
294 { 110, 260, }, 297 { 110, 260, },
298 { 255, 0, },
295}; 299};
296 300
297/* 8 bit registers, 16 bit values */ 301/* 8 bit registers, 16 bit values */
@@ -670,14 +674,15 @@ static int s5h1409_read_snr(struct dvb_frontend* fe, u16* snr)
670 u16 reg; 674 u16 reg;
671 dprintk("%s()\n", __FUNCTION__); 675 dprintk("%s()\n", __FUNCTION__);
672 676
673 reg = s5h1409_readreg(state, 0xf1) & 0x1ff;
674
675 switch(state->current_modulation) { 677 switch(state->current_modulation) {
676 case QAM_64: 678 case QAM_64:
679 reg = s5h1409_readreg(state, 0xf0) & 0xff;
677 return s5h1409_qam64_lookup_snr(fe, snr, reg); 680 return s5h1409_qam64_lookup_snr(fe, snr, reg);
678 case QAM_256: 681 case QAM_256:
682 reg = s5h1409_readreg(state, 0xf0) & 0xff;
679 return s5h1409_qam256_lookup_snr(fe, snr, reg); 683 return s5h1409_qam256_lookup_snr(fe, snr, reg);
680 case VSB_8: 684 case VSB_8:
685 reg = s5h1409_readreg(state, 0xf1) & 0x3ff;
681 return s5h1409_vsb_lookup_snr(fe, snr, reg); 686 return s5h1409_vsb_lookup_snr(fe, snr, reg);
682 default: 687 default:
683 break; 688 break;
diff --git a/drivers/media/dvb/frontends/tda10086.c b/drivers/media/dvb/frontends/tda10086.c
index 9a8ddc537f8f..9d26ace65151 100644
--- a/drivers/media/dvb/frontends/tda10086.c
+++ b/drivers/media/dvb/frontends/tda10086.c
@@ -158,7 +158,7 @@ static int tda10086_init(struct dvb_frontend* fe)
158 tda10086_write_byte(state, 0x3d, 0x80); 158 tda10086_write_byte(state, 0x3d, 0x80);
159 159
160 // setup SEC 160 // setup SEC
161 tda10086_write_byte(state, 0x36, 0x00); // all SEC off 161 tda10086_write_byte(state, 0x36, 0x80); // all SEC off, no 22k tone
162 tda10086_write_byte(state, 0x34, (((1<<19) * (22000/1000)) / (SACLK/1000))); // } tone frequency 162 tda10086_write_byte(state, 0x34, (((1<<19) * (22000/1000)) / (SACLK/1000))); // } tone frequency
163 tda10086_write_byte(state, 0x35, (((1<<19) * (22000/1000)) / (SACLK/1000)) >> 8); // } 163 tda10086_write_byte(state, 0x35, (((1<<19) * (22000/1000)) / (SACLK/1000)) >> 8); // }
164 164
@@ -183,13 +183,13 @@ static int tda10086_set_tone (struct dvb_frontend* fe, fe_sec_tone_mode_t tone)
183 183
184 dprintk ("%s\n", __FUNCTION__); 184 dprintk ("%s\n", __FUNCTION__);
185 185
186 switch(tone) { 186 switch (tone) {
187 case SEC_TONE_OFF: 187 case SEC_TONE_OFF:
188 tda10086_write_byte(state, 0x36, 0x00); 188 tda10086_write_byte(state, 0x36, 0x80);
189 break; 189 break;
190 190
191 case SEC_TONE_ON: 191 case SEC_TONE_ON:
192 tda10086_write_byte(state, 0x36, 0x01); 192 tda10086_write_byte(state, 0x36, 0x81);
193 break; 193 break;
194 } 194 }
195 195
@@ -212,7 +212,7 @@ static int tda10086_send_master_cmd (struct dvb_frontend* fe,
212 for(i=0; i< cmd->msg_len; i++) { 212 for(i=0; i< cmd->msg_len; i++) {
213 tda10086_write_byte(state, 0x48+i, cmd->msg[i]); 213 tda10086_write_byte(state, 0x48+i, cmd->msg[i]);
214 } 214 }
215 tda10086_write_byte(state, 0x36, 0x08 | ((cmd->msg_len - 1) << 4)); 215 tda10086_write_byte(state, 0x36, 0x88 | ((cmd->msg_len - 1) << 4));
216 216
217 tda10086_diseqc_wait(state); 217 tda10086_diseqc_wait(state);
218 218
@@ -230,11 +230,11 @@ static int tda10086_send_burst (struct dvb_frontend* fe, fe_sec_mini_cmd_t minic
230 230
231 switch(minicmd) { 231 switch(minicmd) {
232 case SEC_MINI_A: 232 case SEC_MINI_A:
233 tda10086_write_byte(state, 0x36, 0x04); 233 tda10086_write_byte(state, 0x36, 0x84);
234 break; 234 break;
235 235
236 case SEC_MINI_B: 236 case SEC_MINI_B:
237 tda10086_write_byte(state, 0x36, 0x06); 237 tda10086_write_byte(state, 0x36, 0x86);
238 break; 238 break;
239 } 239 }
240 240
diff --git a/drivers/media/dvb/frontends/zl10353.c b/drivers/media/dvb/frontends/zl10353.c
index a97a7fd2c891..0106df4c55e8 100644
--- a/drivers/media/dvb/frontends/zl10353.c
+++ b/drivers/media/dvb/frontends/zl10353.c
@@ -122,7 +122,7 @@ static void zl10353_calc_nominal_rate(struct dvb_frontend *fe,
122 enum fe_bandwidth bandwidth, 122 enum fe_bandwidth bandwidth,
123 u16 *nominal_rate) 123 u16 *nominal_rate)
124{ 124{
125 u32 adc_clock = 22528; /* 20.480 MHz on the board(!?) */ 125 u32 adc_clock = 45056; /* 45.056 MHz */
126 u8 bw; 126 u8 bw;
127 struct zl10353_state *state = fe->demodulator_priv; 127 struct zl10353_state *state = fe->demodulator_priv;
128 128
@@ -142,7 +142,7 @@ static void zl10353_calc_nominal_rate(struct dvb_frontend *fe,
142 break; 142 break;
143 } 143 }
144 144
145 *nominal_rate = (64 * bw * (1<<16) / (7 * 8) * 4000 / adc_clock + 2) / 4; 145 *nominal_rate = (bw * (1 << 23) / 7 * 125 + adc_clock / 2) / adc_clock;
146 146
147 dprintk("%s: bw %d, adc_clock %d => 0x%x\n", 147 dprintk("%s: bw %d, adc_clock %d => 0x%x\n",
148 __FUNCTION__, bw, adc_clock, *nominal_rate); 148 __FUNCTION__, bw, adc_clock, *nominal_rate);
diff --git a/drivers/media/dvb/frontends/zl10353.h b/drivers/media/dvb/frontends/zl10353.h
index cb274dc12b82..1c3d494a6da9 100644
--- a/drivers/media/dvb/frontends/zl10353.h
+++ b/drivers/media/dvb/frontends/zl10353.h
@@ -30,7 +30,7 @@ struct zl10353_config
30 u8 demod_address; 30 u8 demod_address;
31 31
32 /* frequencies in kHz */ 32 /* frequencies in kHz */
33 int adc_clock; // default: 22528 33 int adc_clock; /* default: 45056 */
34 34
35 /* set if no pll is connected to the secondary i2c bus */ 35 /* set if no pll is connected to the secondary i2c bus */
36 int no_tuner; 36 int no_tuner;
diff --git a/drivers/media/video/bt866.c b/drivers/media/video/bt866.c
index b767b098d14b..96b415576f0d 100644
--- a/drivers/media/video/bt866.c
+++ b/drivers/media/video/bt866.c
@@ -300,7 +300,6 @@ static struct i2c_client bt866_client_tmpl =
300 .addr = 0, 300 .addr = 0,
301 .adapter = NULL, 301 .adapter = NULL,
302 .driver = &i2c_driver_bt866, 302 .driver = &i2c_driver_bt866,
303 .usage_count = 0
304}; 303};
305 304
306static int bt866_found_proc(struct i2c_adapter *adapter, 305static int bt866_found_proc(struct i2c_adapter *adapter,
diff --git a/drivers/media/video/bt8xx/bttv-cards.c b/drivers/media/video/bt8xx/bttv-cards.c
index 3abd9fa54d2c..585d1ef95afd 100644
--- a/drivers/media/video/bt8xx/bttv-cards.c
+++ b/drivers/media/video/bt8xx/bttv-cards.c
@@ -5080,7 +5080,7 @@ static void PXC200_muxsel(struct bttv *btv, unsigned int input)
5080/* ----------------------------------------------------------------------- */ 5080/* ----------------------------------------------------------------------- */
5081/* motherboard chipset specific stuff */ 5081/* motherboard chipset specific stuff */
5082 5082
5083void __devinit bttv_check_chipset(void) 5083void __init bttv_check_chipset(void)
5084{ 5084{
5085 int pcipci_fail = 0; 5085 int pcipci_fail = 0;
5086 struct pci_dev *dev = NULL; 5086 struct pci_dev *dev = NULL;
diff --git a/drivers/media/video/bt8xx/bttv-driver.c b/drivers/media/video/bt8xx/bttv-driver.c
index a88b56e6ca05..c02d92deacd2 100644
--- a/drivers/media/video/bt8xx/bttv-driver.c
+++ b/drivers/media/video/bt8xx/bttv-driver.c
@@ -3827,10 +3827,7 @@ static int bttv_release(struct inode *inode, struct file *file)
3827 3827
3828 /* stop vbi capture */ 3828 /* stop vbi capture */
3829 if (check_btres(fh, RESOURCE_VBI)) { 3829 if (check_btres(fh, RESOURCE_VBI)) {
3830 if (fh->vbi.streaming) 3830 videobuf_stop(&fh->vbi);
3831 videobuf_streamoff(&fh->vbi);
3832 if (fh->vbi.reading)
3833 videobuf_read_stop(&fh->vbi);
3834 free_btres(btv,fh,RESOURCE_VBI); 3831 free_btres(btv,fh,RESOURCE_VBI);
3835 } 3832 }
3836 3833
@@ -4988,7 +4985,7 @@ static struct pci_driver bttv_pci_driver = {
4988#endif 4985#endif
4989}; 4986};
4990 4987
4991static int bttv_init_module(void) 4988static int __init bttv_init_module(void)
4992{ 4989{
4993 int ret; 4990 int ret;
4994 4991
@@ -5021,7 +5018,7 @@ static int bttv_init_module(void)
5021 return pci_register_driver(&bttv_pci_driver); 5018 return pci_register_driver(&bttv_pci_driver);
5022} 5019}
5023 5020
5024static void bttv_cleanup_module(void) 5021static void __exit bttv_cleanup_module(void)
5025{ 5022{
5026 pci_unregister_driver(&bttv_pci_driver); 5023 pci_unregister_driver(&bttv_pci_driver);
5027 bus_unregister(&bttv_sub_bus_type); 5024 bus_unregister(&bttv_sub_bus_type);
diff --git a/drivers/media/video/cx23885/Kconfig b/drivers/media/video/cx23885/Kconfig
index d8b1ccb44913..081ee6e1536f 100644
--- a/drivers/media/video/cx23885/Kconfig
+++ b/drivers/media/video/cx23885/Kconfig
@@ -10,6 +10,7 @@ config VIDEO_CX23885
10 select VIDEOBUF_DVB 10 select VIDEOBUF_DVB
11 select DVB_TUNER_MT2131 if !DVB_FE_CUSTOMISE 11 select DVB_TUNER_MT2131 if !DVB_FE_CUSTOMISE
12 select DVB_S5H1409 if !DVB_FE_CUSTOMISE 12 select DVB_S5H1409 if !DVB_FE_CUSTOMISE
13 select DVB_LGDT330X if !DVB_FE_CUSTOMISE
13 select DVB_PLL if !DVB_FE_CUSTOMISE 14 select DVB_PLL if !DVB_FE_CUSTOMISE
14 ---help--- 15 ---help---
15 This is a video4linux driver for Conexant 23885 based 16 This is a video4linux driver for Conexant 23885 based
diff --git a/drivers/media/video/cx88/cx88-blackbird.c b/drivers/media/video/cx88/cx88-blackbird.c
index f33f0b47142c..f802b5653569 100644
--- a/drivers/media/video/cx88/cx88-blackbird.c
+++ b/drivers/media/video/cx88/cx88-blackbird.c
@@ -1085,10 +1085,7 @@ static int mpeg_release(struct inode *inode, struct file *file)
1085 1085
1086 cx8802_cancel_buffers(fh->dev); 1086 cx8802_cancel_buffers(fh->dev);
1087 /* stop mpeg capture */ 1087 /* stop mpeg capture */
1088 if (fh->mpegq.streaming) 1088 videobuf_stop(&fh->mpegq);
1089 videobuf_streamoff(&fh->mpegq);
1090 if (fh->mpegq.reading)
1091 videobuf_read_stop(&fh->mpegq);
1092 1089
1093 videobuf_mmap_free(&fh->mpegq); 1090 videobuf_mmap_free(&fh->mpegq);
1094 file->private_data = NULL; 1091 file->private_data = NULL;
diff --git a/drivers/media/video/cx88/cx88-video.c b/drivers/media/video/cx88/cx88-video.c
index 5ee05f8f3fad..c84dafbdb991 100644
--- a/drivers/media/video/cx88/cx88-video.c
+++ b/drivers/media/video/cx88/cx88-video.c
@@ -851,10 +851,7 @@ static int video_release(struct inode *inode, struct file *file)
851 851
852 /* stop vbi capture */ 852 /* stop vbi capture */
853 if (res_check(fh, RESOURCE_VBI)) { 853 if (res_check(fh, RESOURCE_VBI)) {
854 if (fh->vbiq.streaming) 854 videobuf_stop(&fh->vbiq);
855 videobuf_streamoff(&fh->vbiq);
856 if (fh->vbiq.reading)
857 videobuf_read_stop(&fh->vbiq);
858 res_free(dev,fh,RESOURCE_VBI); 855 res_free(dev,fh,RESOURCE_VBI);
859 } 856 }
860 857
diff --git a/drivers/media/video/em28xx/em28xx-video.c b/drivers/media/video/em28xx/em28xx-video.c
index 2529c298b862..0906bc5766cc 100644
--- a/drivers/media/video/em28xx/em28xx-video.c
+++ b/drivers/media/video/em28xx/em28xx-video.c
@@ -144,7 +144,8 @@ static int em28xx_config(struct em28xx *dev)
144{ 144{
145 145
146 /* Sets I2C speed to 100 KHz */ 146 /* Sets I2C speed to 100 KHz */
147 em28xx_write_regs_req(dev, 0x00, 0x06, "\x40", 1); 147 if (!dev->is_em2800)
148 em28xx_write_regs_req(dev, 0x00, 0x06, "\x40", 1);
148 149
149 /* enable vbi capturing */ 150 /* enable vbi capturing */
150 151
@@ -570,7 +571,9 @@ static void em28xx_vm_close(struct vm_area_struct *vma)
570{ 571{
571 /* NOTE: buffers are not freed here */ 572 /* NOTE: buffers are not freed here */
572 struct em28xx_frame_t *f = vma->vm_private_data; 573 struct em28xx_frame_t *f = vma->vm_private_data;
573 f->vma_use_count--; 574
575 if (f->vma_use_count)
576 f->vma_use_count--;
574} 577}
575 578
576static struct vm_operations_struct em28xx_vm_ops = { 579static struct vm_operations_struct em28xx_vm_ops = {
diff --git a/drivers/media/video/ivtv/ivtv-i2c.c b/drivers/media/video/ivtv/ivtv-i2c.c
index 623eea2652ca..44678fe27a04 100644
--- a/drivers/media/video/ivtv/ivtv-i2c.c
+++ b/drivers/media/video/ivtv/ivtv-i2c.c
@@ -706,7 +706,7 @@ void ivtv_call_i2c_clients(struct ivtv *itv, unsigned int cmd, void *arg)
706} 706}
707 707
708/* init + register i2c algo-bit adapter */ 708/* init + register i2c algo-bit adapter */
709int __devinit init_ivtv_i2c(struct ivtv *itv) 709int init_ivtv_i2c(struct ivtv *itv)
710{ 710{
711 IVTV_DEBUG_I2C("i2c init\n"); 711 IVTV_DEBUG_I2C("i2c init\n");
712 712
@@ -718,6 +718,9 @@ int __devinit init_ivtv_i2c(struct ivtv *itv)
718 sizeof(struct i2c_adapter)); 718 sizeof(struct i2c_adapter));
719 memcpy(&itv->i2c_algo, &ivtv_i2c_algo_template, 719 memcpy(&itv->i2c_algo, &ivtv_i2c_algo_template,
720 sizeof(struct i2c_algo_bit_data)); 720 sizeof(struct i2c_algo_bit_data));
721 /* The mspx4xx chips need a longer delay for some reason */
722 if (itv->hw_flags & IVTV_HW_MSP34XX)
723 itv->i2c_algo.udelay = 10;
721 itv->i2c_algo.data = itv; 724 itv->i2c_algo.data = itv;
722 itv->i2c_adap.algo_data = &itv->i2c_algo; 725 itv->i2c_adap.algo_data = &itv->i2c_algo;
723 } 726 }
diff --git a/drivers/media/video/ivtv/ivtv-i2c.h b/drivers/media/video/ivtv/ivtv-i2c.h
index de6a07442298..987042c09b64 100644
--- a/drivers/media/video/ivtv/ivtv-i2c.h
+++ b/drivers/media/video/ivtv/ivtv-i2c.h
@@ -35,7 +35,7 @@ int ivtv_call_i2c_client(struct ivtv *itv, int addr, unsigned int cmd, void *arg
35void ivtv_call_i2c_clients(struct ivtv *itv, unsigned int cmd, void *arg); 35void ivtv_call_i2c_clients(struct ivtv *itv, unsigned int cmd, void *arg);
36 36
37/* init + register i2c algo-bit adapter */ 37/* init + register i2c algo-bit adapter */
38int __devinit init_ivtv_i2c(struct ivtv *itv); 38int init_ivtv_i2c(struct ivtv *itv);
39void exit_ivtv_i2c(struct ivtv *itv); 39void exit_ivtv_i2c(struct ivtv *itv);
40 40
41#endif 41#endif
diff --git a/drivers/media/video/ivtv/ivtv-streams.c b/drivers/media/video/ivtv/ivtv-streams.c
index aa03e61ef310..74fb0e021979 100644
--- a/drivers/media/video/ivtv/ivtv-streams.c
+++ b/drivers/media/video/ivtv/ivtv-streams.c
@@ -76,7 +76,7 @@ static struct {
76 int minor_offset; 76 int minor_offset;
77 int dma, pio; 77 int dma, pio;
78 enum v4l2_buf_type buf_type; 78 enum v4l2_buf_type buf_type;
79 struct file_operations *fops; 79 const struct file_operations *fops;
80} ivtv_stream_info[] = { 80} ivtv_stream_info[] = {
81 { /* IVTV_ENC_STREAM_TYPE_MPG */ 81 { /* IVTV_ENC_STREAM_TYPE_MPG */
82 "encoder MPG", 82 "encoder MPG",
diff --git a/drivers/media/video/saa5246a.c b/drivers/media/video/saa5246a.c
index ad0232935df6..996b49491f5a 100644
--- a/drivers/media/video/saa5246a.c
+++ b/drivers/media/video/saa5246a.c
@@ -187,12 +187,14 @@ static int i2c_senddata(struct saa5246a_device *t, ...)
187{ 187{
188 unsigned char buf[64]; 188 unsigned char buf[64];
189 int v; 189 int v;
190 int ct=0; 190 int ct = 0;
191 va_list argp; 191 va_list argp;
192 va_start(argp,t); 192 va_start(argp, t);
193 193
194 while((v=va_arg(argp,int))!=-1) 194 while ((v = va_arg(argp, int)) != -1)
195 buf[ct++]=v; 195 buf[ct++] = v;
196
197 va_end(argp);
196 return i2c_sendbuf(t, buf[0], ct-1, buf+1); 198 return i2c_sendbuf(t, buf[0], ct-1, buf+1);
197} 199}
198 200
diff --git a/drivers/media/video/saa5249.c b/drivers/media/video/saa5249.c
index 94bb59a32b17..f55d6e85f20f 100644
--- a/drivers/media/video/saa5249.c
+++ b/drivers/media/video/saa5249.c
@@ -282,12 +282,14 @@ static int i2c_senddata(struct saa5249_device *t, ...)
282{ 282{
283 unsigned char buf[64]; 283 unsigned char buf[64];
284 int v; 284 int v;
285 int ct=0; 285 int ct = 0;
286 va_list argp; 286 va_list argp;
287 va_start(argp,t); 287 va_start(argp,t);
288 288
289 while((v=va_arg(argp,int))!=-1) 289 while ((v = va_arg(argp, int)) != -1)
290 buf[ct++]=v; 290 buf[ct++] = v;
291
292 va_end(argp);
291 return i2c_sendbuf(t, buf[0], ct-1, buf+1); 293 return i2c_sendbuf(t, buf[0], ct-1, buf+1);
292} 294}
293 295
diff --git a/drivers/media/video/saa7134/saa7134-alsa.c b/drivers/media/video/saa7134/saa7134-alsa.c
index b9c5cf7dc849..4878f3067787 100644
--- a/drivers/media/video/saa7134/saa7134-alsa.c
+++ b/drivers/media/video/saa7134/saa7134-alsa.c
@@ -222,7 +222,8 @@ static irqreturn_t saa7134_alsa_irq(int irq, void *dev_id)
222 222
223 if (report & SAA7134_IRQ_REPORT_DONE_RA3) { 223 if (report & SAA7134_IRQ_REPORT_DONE_RA3) {
224 handled = 1; 224 handled = 1;
225 saa_writel(SAA7134_IRQ_REPORT,report); 225 saa_writel(SAA7134_IRQ_REPORT,
226 SAA7134_IRQ_REPORT_DONE_RA3);
226 saa7134_irq_alsa_done(dev, status); 227 saa7134_irq_alsa_done(dev, status);
227 } else { 228 } else {
228 goto out; 229 goto out;
@@ -457,7 +458,7 @@ static struct snd_pcm_hardware snd_card_saa7134_capture =
457 .buffer_bytes_max = (256*1024), 458 .buffer_bytes_max = (256*1024),
458 .period_bytes_min = 64, 459 .period_bytes_min = 64,
459 .period_bytes_max = (256*1024), 460 .period_bytes_max = (256*1024),
460 .periods_min = 2, 461 .periods_min = 4,
461 .periods_max = 1024, 462 .periods_max = 1024,
462}; 463};
463 464
@@ -491,7 +492,7 @@ static int snd_card_saa7134_hw_params(struct snd_pcm_substream * substream,
491 492
492 snd_assert(period_size >= 0x100 && period_size <= 0x10000, 493 snd_assert(period_size >= 0x100 && period_size <= 0x10000,
493 return -EINVAL); 494 return -EINVAL);
494 snd_assert(periods >= 2, return -EINVAL); 495 snd_assert(periods >= 4, return -EINVAL);
495 snd_assert(period_size * periods <= 1024 * 1024, return -EINVAL); 496 snd_assert(period_size * periods <= 1024 * 1024, return -EINVAL);
496 497
497 dev = saa7134->dev; 498 dev = saa7134->dev;
@@ -647,7 +648,14 @@ static int snd_card_saa7134_capture_open(struct snd_pcm_substream * substream)
647 saa7134_tvaudio_setmute(dev); 648 saa7134_tvaudio_setmute(dev);
648 } 649 }
649 650
650 if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0) 651 err = snd_pcm_hw_constraint_integer(runtime,
652 SNDRV_PCM_HW_PARAM_PERIODS);
653 if (err < 0)
654 return err;
655
656 err = snd_pcm_hw_constraint_step(runtime, 0,
657 SNDRV_PCM_HW_PARAM_PERIODS, 2);
658 if (err < 0)
651 return err; 659 return err;
652 660
653 return 0; 661 return 0;
diff --git a/drivers/media/video/saa7134/saa7134-cards.c b/drivers/media/video/saa7134/saa7134-cards.c
index 4f3dad9ae6d6..98c1b084a716 100644
--- a/drivers/media/video/saa7134/saa7134-cards.c
+++ b/drivers/media/video/saa7134/saa7134-cards.c
@@ -334,7 +334,7 @@ struct saa7134_board saa7134_boards[] = {
334 .tv = 1, 334 .tv = 1,
335 },{ 335 },{
336 .name = name_comp1, 336 .name = name_comp1,
337 .vmux = 2, 337 .vmux = 0,
338 .amux = LINE1, 338 .amux = LINE1,
339 },{ 339 },{
340 .name = name_comp2, 340 .name = name_comp2,
@@ -3221,6 +3221,7 @@ struct saa7134_board saa7134_boards[] = {
3221 .radio_type = UNSET, 3221 .radio_type = UNSET,
3222 .tuner_addr = ADDR_UNSET, 3222 .tuner_addr = ADDR_UNSET,
3223 .radio_addr = ADDR_UNSET, 3223 .radio_addr = ADDR_UNSET,
3224 .tuner_config = 1,
3224 .mpeg = SAA7134_MPEG_DVB, 3225 .mpeg = SAA7134_MPEG_DVB,
3225 .inputs = {{ 3226 .inputs = {{
3226 .name = name_tv, 3227 .name = name_tv,
diff --git a/drivers/media/video/saa7134/saa7134-core.c b/drivers/media/video/saa7134/saa7134-core.c
index a499eea379e6..4fd187ac9d70 100644
--- a/drivers/media/video/saa7134/saa7134-core.c
+++ b/drivers/media/video/saa7134/saa7134-core.c
@@ -569,21 +569,22 @@ static irqreturn_t saa7134_irq(int irq, void *dev_id)
569 for (loop = 0; loop < 10; loop++) { 569 for (loop = 0; loop < 10; loop++) {
570 report = saa_readl(SAA7134_IRQ_REPORT); 570 report = saa_readl(SAA7134_IRQ_REPORT);
571 status = saa_readl(SAA7134_IRQ_STATUS); 571 status = saa_readl(SAA7134_IRQ_STATUS);
572 if (0 == report) {
573 if (irq_debug > 1)
574 printk(KERN_DEBUG "%s/irq: no (more) work\n",
575 dev->name);
576 goto out;
577 }
578
579 /* If dmasound support is active and we get a sound report, exit
580 and let the saa7134-alsa/oss module deal with it */
581 572
573 /* If dmasound support is active and we get a sound report,
574 * mask out the report and let the saa7134-alsa module deal
575 * with it */
582 if ((report & SAA7134_IRQ_REPORT_DONE_RA3) && 576 if ((report & SAA7134_IRQ_REPORT_DONE_RA3) &&
583 (dev->dmasound.priv_data != NULL) ) 577 (dev->dmasound.priv_data != NULL) )
584 { 578 {
585 if (irq_debug > 1) 579 if (irq_debug > 1)
586 printk(KERN_DEBUG "%s/irq: ignoring interrupt for DMA sound\n", 580 printk(KERN_DEBUG "%s/irq: preserving DMA sound interrupt\n",
581 dev->name);
582 report &= ~SAA7134_IRQ_REPORT_DONE_RA3;
583 }
584
585 if (0 == report) {
586 if (irq_debug > 1)
587 printk(KERN_DEBUG "%s/irq: no (more) work\n",
587 dev->name); 588 dev->name);
588 goto out; 589 goto out;
589 } 590 }
diff --git a/drivers/media/video/saa7134/saa7134-dvb.c b/drivers/media/video/saa7134/saa7134-dvb.c
index 38d87332cc5d..e1ab099ec4c6 100644
--- a/drivers/media/video/saa7134/saa7134-dvb.c
+++ b/drivers/media/video/saa7134/saa7134-dvb.c
@@ -662,6 +662,7 @@ static struct tda1004x_config hauppauge_hvr_1110_config = {
662 .if_freq = TDA10046_FREQ_045, 662 .if_freq = TDA10046_FREQ_045,
663 .i2c_gate = 0x4b, 663 .i2c_gate = 0x4b,
664 .tuner_address = 0x61, 664 .tuner_address = 0x61,
665 .tuner_config = 1,
665 .request_firmware = philips_tda1004x_request_firmware 666 .request_firmware = philips_tda1004x_request_firmware
666}; 667};
667 668
diff --git a/drivers/media/video/saa7134/saa7134-empress.c b/drivers/media/video/saa7134/saa7134-empress.c
index 75d0c5bf46d2..9322f44865b8 100644
--- a/drivers/media/video/saa7134/saa7134-empress.c
+++ b/drivers/media/video/saa7134/saa7134-empress.c
@@ -110,11 +110,8 @@ static int ts_release(struct inode *inode, struct file *file)
110{ 110{
111 struct saa7134_dev *dev = file->private_data; 111 struct saa7134_dev *dev = file->private_data;
112 112
113 if (dev->empress_tsq.streaming)
114 videobuf_streamoff(&dev->empress_tsq);
115 mutex_lock(&dev->empress_tsq.lock); 113 mutex_lock(&dev->empress_tsq.lock);
116 if (dev->empress_tsq.reading) 114 videobuf_stop(&dev->empress_tsq);
117 videobuf_read_stop(&dev->empress_tsq);
118 videobuf_mmap_free(&dev->empress_tsq); 115 videobuf_mmap_free(&dev->empress_tsq);
119 dev->empress_users--; 116 dev->empress_users--;
120 117
diff --git a/drivers/media/video/saa7134/saa7134-video.c b/drivers/media/video/saa7134/saa7134-video.c
index 3b9ffb4b648a..6396d9b5c063 100644
--- a/drivers/media/video/saa7134/saa7134-video.c
+++ b/drivers/media/video/saa7134/saa7134-video.c
@@ -1445,10 +1445,7 @@ static int video_release(struct inode *inode, struct file *file)
1445 1445
1446 /* stop vbi capture */ 1446 /* stop vbi capture */
1447 if (res_check(fh, RESOURCE_VBI)) { 1447 if (res_check(fh, RESOURCE_VBI)) {
1448 if (fh->vbi.streaming) 1448 videobuf_stop(&fh->vbi);
1449 videobuf_streamoff(&fh->vbi);
1450 if (fh->vbi.reading)
1451 videobuf_read_stop(&fh->vbi);
1452 res_free(dev,fh,RESOURCE_VBI); 1449 res_free(dev,fh,RESOURCE_VBI);
1453 } 1450 }
1454 1451
diff --git a/drivers/media/video/tvp5150.c b/drivers/media/video/tvp5150.c
index 25d0aef88ef5..445eba4174d7 100644
--- a/drivers/media/video/tvp5150.c
+++ b/drivers/media/video/tvp5150.c
@@ -290,6 +290,7 @@ static inline void tvp5150_selmux(struct i2c_client *c)
290 int opmode=0; 290 int opmode=0;
291 struct tvp5150 *decoder = i2c_get_clientdata(c); 291 struct tvp5150 *decoder = i2c_get_clientdata(c);
292 int input = 0; 292 int input = 0;
293 unsigned char val;
293 294
294 if ((decoder->route.output & TVP5150_BLACK_SCREEN) || !decoder->enable) 295 if ((decoder->route.output & TVP5150_BLACK_SCREEN) || !decoder->enable)
295 input = 8; 296 input = 8;
@@ -315,6 +316,16 @@ static inline void tvp5150_selmux(struct i2c_client *c)
315 316
316 tvp5150_write(c, TVP5150_OP_MODE_CTL, opmode); 317 tvp5150_write(c, TVP5150_OP_MODE_CTL, opmode);
317 tvp5150_write(c, TVP5150_VD_IN_SRC_SEL_1, input); 318 tvp5150_write(c, TVP5150_VD_IN_SRC_SEL_1, input);
319
320 /* Svideo should enable YCrCb output and disable GPCL output
321 * For Composite and TV, it should be the reverse
322 */
323 val = tvp5150_read(c, TVP5150_MISC_CTL);
324 if (decoder->route.input == TVP5150_SVIDEO)
325 val = (val & ~0x40) | 0x10;
326 else
327 val = (val & ~0x10) | 0x40;
328 tvp5150_write(c, TVP5150_MISC_CTL, val);
318}; 329};
319 330
320struct i2c_reg_value { 331struct i2c_reg_value {
diff --git a/drivers/media/video/videobuf-core.c b/drivers/media/video/videobuf-core.c
index 89a44f16f0ba..c8a5cb57963b 100644
--- a/drivers/media/video/videobuf-core.c
+++ b/drivers/media/video/videobuf-core.c
@@ -141,6 +141,7 @@ void videobuf_queue_core_init(struct videobuf_queue* q,
141 INIT_LIST_HEAD(&q->stream); 141 INIT_LIST_HEAD(&q->stream);
142} 142}
143 143
144/* Locking: Only usage in bttv unsafe find way to remove */
144int videobuf_queue_is_busy(struct videobuf_queue *q) 145int videobuf_queue_is_busy(struct videobuf_queue *q)
145{ 146{
146 int i; 147 int i;
@@ -178,6 +179,7 @@ int videobuf_queue_is_busy(struct videobuf_queue *q)
178 return 0; 179 return 0;
179} 180}
180 181
182/* Locking: Caller holds q->lock */
181void videobuf_queue_cancel(struct videobuf_queue *q) 183void videobuf_queue_cancel(struct videobuf_queue *q)
182{ 184{
183 unsigned long flags=0; 185 unsigned long flags=0;
@@ -208,6 +210,7 @@ void videobuf_queue_cancel(struct videobuf_queue *q)
208 210
209/* --------------------------------------------------------------------- */ 211/* --------------------------------------------------------------------- */
210 212
213/* Locking: Caller holds q->lock */
211enum v4l2_field videobuf_next_field(struct videobuf_queue *q) 214enum v4l2_field videobuf_next_field(struct videobuf_queue *q)
212{ 215{
213 enum v4l2_field field = q->field; 216 enum v4l2_field field = q->field;
@@ -226,6 +229,7 @@ enum v4l2_field videobuf_next_field(struct videobuf_queue *q)
226 return field; 229 return field;
227} 230}
228 231
232/* Locking: Caller holds q->lock */
229static void videobuf_status(struct videobuf_queue *q, struct v4l2_buffer *b, 233static void videobuf_status(struct videobuf_queue *q, struct v4l2_buffer *b,
230 struct videobuf_buffer *vb, enum v4l2_buf_type type) 234 struct videobuf_buffer *vb, enum v4l2_buf_type type)
231{ 235{
@@ -281,20 +285,108 @@ static void videobuf_status(struct videobuf_queue *q, struct v4l2_buffer *b,
281 b->sequence = vb->field_count >> 1; 285 b->sequence = vb->field_count >> 1;
282} 286}
283 287
288/* Locking: Caller holds q->lock */
289static int __videobuf_mmap_free(struct videobuf_queue *q)
290{
291 int i;
292 int rc;
293
294 if (!q)
295 return 0;
296
297 MAGIC_CHECK(q->int_ops->magic,MAGIC_QTYPE_OPS);
298
299 rc = CALL(q,mmap_free,q);
300 if (rc<0)
301 return rc;
302
303 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
304 if (NULL == q->bufs[i])
305 continue;
306 q->ops->buf_release(q,q->bufs[i]);
307 kfree(q->bufs[i]);
308 q->bufs[i] = NULL;
309 }
310
311 return rc;
312}
313
314int videobuf_mmap_free(struct videobuf_queue *q)
315{
316 int ret;
317 mutex_lock(&q->lock);
318 ret = __videobuf_mmap_free(q);
319 mutex_unlock(&q->lock);
320 return ret;
321}
322
323/* Locking: Caller holds q->lock */
324static int __videobuf_mmap_setup(struct videobuf_queue *q,
325 unsigned int bcount, unsigned int bsize,
326 enum v4l2_memory memory)
327{
328 unsigned int i;
329 int err;
330
331 MAGIC_CHECK(q->int_ops->magic,MAGIC_QTYPE_OPS);
332
333 err = __videobuf_mmap_free(q);
334 if (0 != err)
335 return err;
336
337 /* Allocate and initialize buffers */
338 for (i = 0; i < bcount; i++) {
339 q->bufs[i] = videobuf_alloc(q);
340
341 if (q->bufs[i] == NULL)
342 break;
343
344 q->bufs[i]->i = i;
345 q->bufs[i]->input = UNSET;
346 q->bufs[i]->memory = memory;
347 q->bufs[i]->bsize = bsize;
348 switch (memory) {
349 case V4L2_MEMORY_MMAP:
350 q->bufs[i]->boff = bsize * i;
351 break;
352 case V4L2_MEMORY_USERPTR:
353 case V4L2_MEMORY_OVERLAY:
354 /* nothing */
355 break;
356 }
357 }
358
359 if (!i)
360 return -ENOMEM;
361
362 dprintk(1,"mmap setup: %d buffers, %d bytes each\n",
363 i, bsize);
364
365 return i;
366}
367
368int videobuf_mmap_setup(struct videobuf_queue *q,
369 unsigned int bcount, unsigned int bsize,
370 enum v4l2_memory memory)
371{
372 int ret;
373 mutex_lock(&q->lock);
374 ret = __videobuf_mmap_setup(q, bcount, bsize, memory);
375 mutex_unlock(&q->lock);
376 return ret;
377}
378
284int videobuf_reqbufs(struct videobuf_queue *q, 379int videobuf_reqbufs(struct videobuf_queue *q,
285 struct v4l2_requestbuffers *req) 380 struct v4l2_requestbuffers *req)
286{ 381{
287 unsigned int size,count; 382 unsigned int size,count;
288 int retval; 383 int retval;
289 384
290 if (req->type != q->type) {
291 dprintk(1,"reqbufs: queue type invalid\n");
292 return -EINVAL;
293 }
294 if (req->count < 1) { 385 if (req->count < 1) {
295 dprintk(1,"reqbufs: count invalid (%d)\n",req->count); 386 dprintk(1,"reqbufs: count invalid (%d)\n",req->count);
296 return -EINVAL; 387 return -EINVAL;
297 } 388 }
389
298 if (req->memory != V4L2_MEMORY_MMAP && 390 if (req->memory != V4L2_MEMORY_MMAP &&
299 req->memory != V4L2_MEMORY_USERPTR && 391 req->memory != V4L2_MEMORY_USERPTR &&
300 req->memory != V4L2_MEMORY_OVERLAY) { 392 req->memory != V4L2_MEMORY_OVERLAY) {
@@ -303,6 +395,12 @@ int videobuf_reqbufs(struct videobuf_queue *q,
303 } 395 }
304 396
305 mutex_lock(&q->lock); 397 mutex_lock(&q->lock);
398 if (req->type != q->type) {
399 dprintk(1,"reqbufs: queue type invalid\n");
400 retval = -EINVAL;
401 goto done;
402 }
403
306 if (q->streaming) { 404 if (q->streaming) {
307 dprintk(1,"reqbufs: streaming already exists\n"); 405 dprintk(1,"reqbufs: streaming already exists\n");
308 retval = -EBUSY; 406 retval = -EBUSY;
@@ -323,7 +421,7 @@ int videobuf_reqbufs(struct videobuf_queue *q,
323 dprintk(1,"reqbufs: bufs=%d, size=0x%x [%d pages total]\n", 421 dprintk(1,"reqbufs: bufs=%d, size=0x%x [%d pages total]\n",
324 count, size, (count*size)>>PAGE_SHIFT); 422 count, size, (count*size)>>PAGE_SHIFT);
325 423
326 retval = videobuf_mmap_setup(q,count,size,req->memory); 424 retval = __videobuf_mmap_setup(q,count,size,req->memory);
327 if (retval < 0) { 425 if (retval < 0) {
328 dprintk(1,"reqbufs: mmap setup returned %d\n",retval); 426 dprintk(1,"reqbufs: mmap setup returned %d\n",retval);
329 goto done; 427 goto done;
@@ -338,20 +436,28 @@ int videobuf_reqbufs(struct videobuf_queue *q,
338 436
339int videobuf_querybuf(struct videobuf_queue *q, struct v4l2_buffer *b) 437int videobuf_querybuf(struct videobuf_queue *q, struct v4l2_buffer *b)
340{ 438{
439 int ret = -EINVAL;
440
441 mutex_lock(&q->lock);
341 if (unlikely(b->type != q->type)) { 442 if (unlikely(b->type != q->type)) {
342 dprintk(1,"querybuf: Wrong type.\n"); 443 dprintk(1,"querybuf: Wrong type.\n");
343 return -EINVAL; 444 goto done;
344 } 445 }
345 if (unlikely(b->index < 0 || b->index >= VIDEO_MAX_FRAME)) { 446 if (unlikely(b->index < 0 || b->index >= VIDEO_MAX_FRAME)) {
346 dprintk(1,"querybuf: index out of range.\n"); 447 dprintk(1,"querybuf: index out of range.\n");
347 return -EINVAL; 448 goto done;
348 } 449 }
349 if (unlikely(NULL == q->bufs[b->index])) { 450 if (unlikely(NULL == q->bufs[b->index])) {
350 dprintk(1,"querybuf: buffer is null.\n"); 451 dprintk(1,"querybuf: buffer is null.\n");
351 return -EINVAL; 452 goto done;
352 } 453 }
454
353 videobuf_status(q,b,q->bufs[b->index],q->type); 455 videobuf_status(q,b,q->bufs[b->index],q->type);
354 return 0; 456
457 ret = 0;
458done:
459 mutex_unlock(&q->lock);
460 return ret;
355} 461}
356 462
357int videobuf_qbuf(struct videobuf_queue *q, 463int videobuf_qbuf(struct videobuf_queue *q,
@@ -541,22 +647,30 @@ int videobuf_streamon(struct videobuf_queue *q)
541 return retval; 647 return retval;
542} 648}
543 649
544int videobuf_streamoff(struct videobuf_queue *q) 650/* Locking: Caller holds q->lock */
651static int __videobuf_streamoff(struct videobuf_queue *q)
545{ 652{
546 int retval = -EINVAL;
547
548 mutex_lock(&q->lock);
549 if (!q->streaming) 653 if (!q->streaming)
550 goto done; 654 return -EINVAL;
655
551 videobuf_queue_cancel(q); 656 videobuf_queue_cancel(q);
552 q->streaming = 0; 657 q->streaming = 0;
553 retval = 0;
554 658
555 done: 659 return 0;
660}
661
662int videobuf_streamoff(struct videobuf_queue *q)
663{
664 int retval;
665
666 mutex_lock(&q->lock);
667 retval = __videobuf_streamoff(q);
556 mutex_unlock(&q->lock); 668 mutex_unlock(&q->lock);
669
557 return retval; 670 return retval;
558} 671}
559 672
673/* Locking: Caller holds q->lock */
560static ssize_t videobuf_read_zerocopy(struct videobuf_queue *q, 674static ssize_t videobuf_read_zerocopy(struct videobuf_queue *q,
561 char __user *data, 675 char __user *data,
562 size_t count, loff_t *ppos) 676 size_t count, loff_t *ppos)
@@ -691,7 +805,8 @@ ssize_t videobuf_read_one(struct videobuf_queue *q,
691 return retval; 805 return retval;
692} 806}
693 807
694int videobuf_read_start(struct videobuf_queue *q) 808/* Locking: Caller holds q->lock */
809int __videobuf_read_start(struct videobuf_queue *q)
695{ 810{
696 enum v4l2_field field; 811 enum v4l2_field field;
697 unsigned long flags=0; 812 unsigned long flags=0;
@@ -705,7 +820,7 @@ int videobuf_read_start(struct videobuf_queue *q)
705 count = VIDEO_MAX_FRAME; 820 count = VIDEO_MAX_FRAME;
706 size = PAGE_ALIGN(size); 821 size = PAGE_ALIGN(size);
707 822
708 err = videobuf_mmap_setup(q, count, size, V4L2_MEMORY_USERPTR); 823 err = __videobuf_mmap_setup(q, count, size, V4L2_MEMORY_USERPTR);
709 if (err < 0) 824 if (err < 0)
710 return err; 825 return err;
711 826
@@ -728,12 +843,13 @@ int videobuf_read_start(struct videobuf_queue *q)
728 return 0; 843 return 0;
729} 844}
730 845
731void videobuf_read_stop(struct videobuf_queue *q) 846static void __videobuf_read_stop(struct videobuf_queue *q)
732{ 847{
733 int i; 848 int i;
734 849
850
735 videobuf_queue_cancel(q); 851 videobuf_queue_cancel(q);
736 videobuf_mmap_free(q); 852 __videobuf_mmap_free(q);
737 INIT_LIST_HEAD(&q->stream); 853 INIT_LIST_HEAD(&q->stream);
738 for (i = 0; i < VIDEO_MAX_FRAME; i++) { 854 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
739 if (NULL == q->bufs[i]) 855 if (NULL == q->bufs[i])
@@ -743,8 +859,41 @@ void videobuf_read_stop(struct videobuf_queue *q)
743 } 859 }
744 q->read_buf = NULL; 860 q->read_buf = NULL;
745 q->reading = 0; 861 q->reading = 0;
862
746} 863}
747 864
865int videobuf_read_start(struct videobuf_queue *q)
866{
867 int rc;
868
869 mutex_lock(&q->lock);
870 rc = __videobuf_read_start(q);
871 mutex_unlock(&q->lock);
872
873 return rc;
874}
875
876void videobuf_read_stop(struct videobuf_queue *q)
877{
878 mutex_lock(&q->lock);
879 __videobuf_read_stop(q);
880 mutex_unlock(&q->lock);
881}
882
883void videobuf_stop(struct videobuf_queue *q)
884{
885 mutex_lock(&q->lock);
886
887 if (q->streaming)
888 __videobuf_streamoff(q);
889
890 if (q->reading)
891 __videobuf_read_stop(q);
892
893 mutex_unlock(&q->lock);
894}
895
896
748ssize_t videobuf_read_stream(struct videobuf_queue *q, 897ssize_t videobuf_read_stream(struct videobuf_queue *q,
749 char __user *data, size_t count, loff_t *ppos, 898 char __user *data, size_t count, loff_t *ppos,
750 int vbihack, int nonblocking) 899 int vbihack, int nonblocking)
@@ -760,7 +909,7 @@ ssize_t videobuf_read_stream(struct videobuf_queue *q,
760 if (q->streaming) 909 if (q->streaming)
761 goto done; 910 goto done;
762 if (!q->reading) { 911 if (!q->reading) {
763 retval = videobuf_read_start(q); 912 retval = __videobuf_read_start(q);
764 if (retval < 0) 913 if (retval < 0)
765 goto done; 914 goto done;
766 } 915 }
@@ -833,7 +982,7 @@ unsigned int videobuf_poll_stream(struct file *file,
833 struct videobuf_buffer, stream); 982 struct videobuf_buffer, stream);
834 } else { 983 } else {
835 if (!q->reading) 984 if (!q->reading)
836 videobuf_read_start(q); 985 __videobuf_read_start(q);
837 if (!q->reading) { 986 if (!q->reading) {
838 rc = POLLERR; 987 rc = POLLERR;
839 } else if (NULL == q->read_buf) { 988 } else if (NULL == q->read_buf) {
@@ -858,75 +1007,6 @@ unsigned int videobuf_poll_stream(struct file *file,
858 return rc; 1007 return rc;
859} 1008}
860 1009
861int videobuf_mmap_setup(struct videobuf_queue *q,
862 unsigned int bcount, unsigned int bsize,
863 enum v4l2_memory memory)
864{
865 unsigned int i;
866 int err;
867
868 MAGIC_CHECK(q->int_ops->magic,MAGIC_QTYPE_OPS);
869
870 err = videobuf_mmap_free(q);
871 if (0 != err)
872 return err;
873
874 /* Allocate and initialize buffers */
875 for (i = 0; i < bcount; i++) {
876 q->bufs[i] = videobuf_alloc(q);
877
878 if (q->bufs[i] == NULL)
879 break;
880
881 q->bufs[i]->i = i;
882 q->bufs[i]->input = UNSET;
883 q->bufs[i]->memory = memory;
884 q->bufs[i]->bsize = bsize;
885 switch (memory) {
886 case V4L2_MEMORY_MMAP:
887 q->bufs[i]->boff = bsize * i;
888 break;
889 case V4L2_MEMORY_USERPTR:
890 case V4L2_MEMORY_OVERLAY:
891 /* nothing */
892 break;
893 }
894 }
895
896 if (!i)
897 return -ENOMEM;
898
899 dprintk(1,"mmap setup: %d buffers, %d bytes each\n",
900 i, bsize);
901
902 return i;
903}
904
905int videobuf_mmap_free(struct videobuf_queue *q)
906{
907 int i;
908 int rc;
909
910 if (!q)
911 return 0;
912
913 MAGIC_CHECK(q->int_ops->magic,MAGIC_QTYPE_OPS);
914
915 rc = CALL(q,mmap_free,q);
916 if (rc<0)
917 return rc;
918
919 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
920 if (NULL == q->bufs[i])
921 continue;
922 q->ops->buf_release(q,q->bufs[i]);
923 kfree(q->bufs[i]);
924 q->bufs[i] = NULL;
925 }
926
927 return rc;
928}
929
930int videobuf_mmap_mapper(struct videobuf_queue *q, 1010int videobuf_mmap_mapper(struct videobuf_queue *q,
931 struct vm_area_struct *vma) 1011 struct vm_area_struct *vma)
932{ 1012{
@@ -991,6 +1071,7 @@ EXPORT_SYMBOL_GPL(videobuf_streamoff);
991 1071
992EXPORT_SYMBOL_GPL(videobuf_read_start); 1072EXPORT_SYMBOL_GPL(videobuf_read_start);
993EXPORT_SYMBOL_GPL(videobuf_read_stop); 1073EXPORT_SYMBOL_GPL(videobuf_read_stop);
1074EXPORT_SYMBOL_GPL(videobuf_stop);
994EXPORT_SYMBOL_GPL(videobuf_read_stream); 1075EXPORT_SYMBOL_GPL(videobuf_read_stream);
995EXPORT_SYMBOL_GPL(videobuf_read_one); 1076EXPORT_SYMBOL_GPL(videobuf_read_one);
996EXPORT_SYMBOL_GPL(videobuf_poll_stream); 1077EXPORT_SYMBOL_GPL(videobuf_poll_stream);
diff --git a/drivers/media/video/videobuf-vmalloc.c b/drivers/media/video/videobuf-vmalloc.c
index cd74341c984f..e01259438bb2 100644
--- a/drivers/media/video/videobuf-vmalloc.c
+++ b/drivers/media/video/videobuf-vmalloc.c
@@ -51,7 +51,7 @@ videobuf_vm_open(struct vm_area_struct *vma)
51{ 51{
52 struct videobuf_mapping *map = vma->vm_private_data; 52 struct videobuf_mapping *map = vma->vm_private_data;
53 53
54 dprintk(2,"vm_open %p [count=%d,vma=%08lx-%08lx]\n",map, 54 dprintk(2,"vm_open %p [count=%u,vma=%08lx-%08lx]\n",map,
55 map->count,vma->vm_start,vma->vm_end); 55 map->count,vma->vm_start,vma->vm_end);
56 56
57 map->count++; 57 map->count++;
@@ -64,7 +64,7 @@ videobuf_vm_close(struct vm_area_struct *vma)
64 struct videobuf_queue *q = map->q; 64 struct videobuf_queue *q = map->q;
65 int i; 65 int i;
66 66
67 dprintk(2,"vm_close %p [count=%d,vma=%08lx-%08lx]\n",map, 67 dprintk(2,"vm_close %p [count=%u,vma=%08lx-%08lx]\n",map,
68 map->count,vma->vm_start,vma->vm_end); 68 map->count,vma->vm_start,vma->vm_end);
69 69
70 map->count--; 70 map->count--;
@@ -221,7 +221,7 @@ static int __videobuf_mmap_mapper(struct videobuf_queue *q,
221 } 221 }
222 222
223 /* create mapping + update buffer list */ 223 /* create mapping + update buffer list */
224 map = q->bufs[first]->map = kmalloc(sizeof(struct videobuf_mapping),GFP_KERNEL); 224 map = q->bufs[first]->map = kzalloc(sizeof(struct videobuf_mapping),GFP_KERNEL);
225 if (NULL == map) 225 if (NULL == map)
226 return -ENOMEM; 226 return -ENOMEM;
227 227
diff --git a/drivers/media/video/vivi.c b/drivers/media/video/vivi.c
index ee73dc75131c..9b54ff9d2e36 100644
--- a/drivers/media/video/vivi.c
+++ b/drivers/media/video/vivi.c
@@ -1076,6 +1076,7 @@ static int vivi_release(struct inode *inode, struct file *file)
1076 int minor = iminor(inode); 1076 int minor = iminor(inode);
1077 1077
1078 vivi_stop_thread(vidq); 1078 vivi_stop_thread(vidq);
1079 videobuf_stop(&fh->vb_vidq);
1079 videobuf_mmap_free(&fh->vb_vidq); 1080 videobuf_mmap_free(&fh->vb_vidq);
1080 1081
1081 kfree (fh); 1082 kfree (fh);
diff --git a/drivers/mfd/sm501.c b/drivers/mfd/sm501.c
index 8135e4c3bf47..afd82966f9a0 100644
--- a/drivers/mfd/sm501.c
+++ b/drivers/mfd/sm501.c
@@ -156,7 +156,7 @@ static void sm501_dump_clk(struct sm501_devdata *sm)
156 156
157 dev_dbg(sm->dev, "PM0[%c]: " 157 dev_dbg(sm->dev, "PM0[%c]: "
158 "P2 %ld.%ld MHz (%ld), V2 %ld.%ld (%ld), " 158 "P2 %ld.%ld MHz (%ld), V2 %ld.%ld (%ld), "
159x "M %ld.%ld (%ld), MX1 %ld.%ld (%ld)\n", 159 "M %ld.%ld (%ld), MX1 %ld.%ld (%ld)\n",
160 (pmc & 3 ) == 0 ? '*' : '-', 160 (pmc & 3 ) == 0 ? '*' : '-',
161 fmt_freq(decode_div(pll2, pm0, 24, 1<<29, 31, px_div)), 161 fmt_freq(decode_div(pll2, pm0, 24, 1<<29, 31, px_div)),
162 fmt_freq(decode_div(pll2, pm0, 16, 1<<20, 15, misc_div)), 162 fmt_freq(decode_div(pll2, pm0, 16, 1<<20, 15, misc_div)),
diff --git a/drivers/misc/sony-laptop.c b/drivers/misc/sony-laptop.c
index bb13858f60a1..b0f68031b49d 100644
--- a/drivers/misc/sony-laptop.c
+++ b/drivers/misc/sony-laptop.c
@@ -338,7 +338,7 @@ static void sony_laptop_report_input_event(u8 event)
338 dprintk("unknown input event %.2x\n", event); 338 dprintk("unknown input event %.2x\n", event);
339} 339}
340 340
341static int sony_laptop_setup_input(void) 341static int sony_laptop_setup_input(struct acpi_device *acpi_device)
342{ 342{
343 struct input_dev *jog_dev; 343 struct input_dev *jog_dev;
344 struct input_dev *key_dev; 344 struct input_dev *key_dev;
@@ -379,6 +379,7 @@ static int sony_laptop_setup_input(void)
379 key_dev->name = "Sony Vaio Keys"; 379 key_dev->name = "Sony Vaio Keys";
380 key_dev->id.bustype = BUS_ISA; 380 key_dev->id.bustype = BUS_ISA;
381 key_dev->id.vendor = PCI_VENDOR_ID_SONY; 381 key_dev->id.vendor = PCI_VENDOR_ID_SONY;
382 key_dev->dev.parent = &acpi_device->dev;
382 383
383 /* Initialize the Input Drivers: special keys */ 384 /* Initialize the Input Drivers: special keys */
384 set_bit(EV_KEY, key_dev->evbit); 385 set_bit(EV_KEY, key_dev->evbit);
@@ -410,6 +411,7 @@ static int sony_laptop_setup_input(void)
410 jog_dev->name = "Sony Vaio Jogdial"; 411 jog_dev->name = "Sony Vaio Jogdial";
411 jog_dev->id.bustype = BUS_ISA; 412 jog_dev->id.bustype = BUS_ISA;
412 jog_dev->id.vendor = PCI_VENDOR_ID_SONY; 413 jog_dev->id.vendor = PCI_VENDOR_ID_SONY;
414 key_dev->dev.parent = &acpi_device->dev;
413 415
414 jog_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL); 416 jog_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL);
415 jog_dev->keybit[BIT_WORD(BTN_MOUSE)] = BIT_MASK(BTN_MIDDLE); 417 jog_dev->keybit[BIT_WORD(BTN_MOUSE)] = BIT_MASK(BTN_MIDDLE);
@@ -1006,7 +1008,7 @@ static int sony_nc_add(struct acpi_device *device)
1006 } 1008 }
1007 1009
1008 /* setup input devices and helper fifo */ 1010 /* setup input devices and helper fifo */
1009 result = sony_laptop_setup_input(); 1011 result = sony_laptop_setup_input(device);
1010 if (result) { 1012 if (result) {
1011 printk(KERN_ERR DRV_PFX 1013 printk(KERN_ERR DRV_PFX
1012 "Unabe to create input devices.\n"); 1014 "Unabe to create input devices.\n");
@@ -1034,7 +1036,7 @@ static int sony_nc_add(struct acpi_device *device)
1034 sony_backlight_device->props.brightness = 1036 sony_backlight_device->props.brightness =
1035 sony_backlight_get_brightness 1037 sony_backlight_get_brightness
1036 (sony_backlight_device); 1038 (sony_backlight_device);
1037 sony_backlight_device->props.max_brightness = 1039 sony_backlight_device->props.max_brightness =
1038 SONY_MAX_BRIGHTNESS - 1; 1040 SONY_MAX_BRIGHTNESS - 1;
1039 } 1041 }
1040 1042
@@ -2453,7 +2455,7 @@ static int sony_pic_add(struct acpi_device *device)
2453 } 2455 }
2454 2456
2455 /* setup input devices and helper fifo */ 2457 /* setup input devices and helper fifo */
2456 result = sony_laptop_setup_input(); 2458 result = sony_laptop_setup_input(device);
2457 if (result) { 2459 if (result) {
2458 printk(KERN_ERR DRV_PFX 2460 printk(KERN_ERR DRV_PFX
2459 "Unabe to create input devices.\n"); 2461 "Unabe to create input devices.\n");
diff --git a/drivers/misc/thinkpad_acpi.c b/drivers/misc/thinkpad_acpi.c
index e953276664a0..cf56647a6ca4 100644
--- a/drivers/misc/thinkpad_acpi.c
+++ b/drivers/misc/thinkpad_acpi.c
@@ -21,7 +21,7 @@
21 * 02110-1301, USA. 21 * 02110-1301, USA.
22 */ 22 */
23 23
24#define IBM_VERSION "0.16" 24#define IBM_VERSION "0.17"
25#define TPACPI_SYSFS_VERSION 0x020000 25#define TPACPI_SYSFS_VERSION 0x020000
26 26
27/* 27/*
@@ -964,15 +964,15 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
964 KEY_UNKNOWN, /* 0x0C: FN+BACKSPACE */ 964 KEY_UNKNOWN, /* 0x0C: FN+BACKSPACE */
965 KEY_UNKNOWN, /* 0x0D: FN+INSERT */ 965 KEY_UNKNOWN, /* 0x0D: FN+INSERT */
966 KEY_UNKNOWN, /* 0x0E: FN+DELETE */ 966 KEY_UNKNOWN, /* 0x0E: FN+DELETE */
967 KEY_BRIGHTNESSUP, /* 0x0F: FN+HOME (brightness up) */ 967 KEY_RESERVED, /* 0x0F: FN+HOME (brightness up) */
968 /* Scan codes 0x10 to 0x1F: Extended ACPI HKEY hot keys */ 968 /* Scan codes 0x10 to 0x1F: Extended ACPI HKEY hot keys */
969 KEY_BRIGHTNESSDOWN, /* 0x10: FN+END (brightness down) */ 969 KEY_RESERVED, /* 0x10: FN+END (brightness down) */
970 KEY_RESERVED, /* 0x11: FN+PGUP (thinklight toggle) */ 970 KEY_RESERVED, /* 0x11: FN+PGUP (thinklight toggle) */
971 KEY_UNKNOWN, /* 0x12: FN+PGDOWN */ 971 KEY_UNKNOWN, /* 0x12: FN+PGDOWN */
972 KEY_ZOOM, /* 0x13: FN+SPACE (zoom) */ 972 KEY_ZOOM, /* 0x13: FN+SPACE (zoom) */
973 KEY_VOLUMEUP, /* 0x14: VOLUME UP */ 973 KEY_RESERVED, /* 0x14: VOLUME UP */
974 KEY_VOLUMEDOWN, /* 0x15: VOLUME DOWN */ 974 KEY_RESERVED, /* 0x15: VOLUME DOWN */
975 KEY_MUTE, /* 0x16: MUTE */ 975 KEY_RESERVED, /* 0x16: MUTE */
976 KEY_VENDOR, /* 0x17: Thinkpad/AccessIBM/Lenovo */ 976 KEY_VENDOR, /* 0x17: Thinkpad/AccessIBM/Lenovo */
977 /* (assignments unknown, please report if found) */ 977 /* (assignments unknown, please report if found) */
978 KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, 978 KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
@@ -987,15 +987,15 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
987 KEY_UNKNOWN, /* 0x0C: FN+BACKSPACE */ 987 KEY_UNKNOWN, /* 0x0C: FN+BACKSPACE */
988 KEY_UNKNOWN, /* 0x0D: FN+INSERT */ 988 KEY_UNKNOWN, /* 0x0D: FN+INSERT */
989 KEY_UNKNOWN, /* 0x0E: FN+DELETE */ 989 KEY_UNKNOWN, /* 0x0E: FN+DELETE */
990 KEY_BRIGHTNESSUP, /* 0x0F: FN+HOME (brightness up) */ 990 KEY_RESERVED, /* 0x0F: FN+HOME (brightness up) */
991 /* Scan codes 0x10 to 0x1F: Extended ACPI HKEY hot keys */ 991 /* Scan codes 0x10 to 0x1F: Extended ACPI HKEY hot keys */
992 KEY_BRIGHTNESSDOWN, /* 0x10: FN+END (brightness down) */ 992 KEY_RESERVED, /* 0x10: FN+END (brightness down) */
993 KEY_RESERVED, /* 0x11: FN+PGUP (thinklight toggle) */ 993 KEY_RESERVED, /* 0x11: FN+PGUP (thinklight toggle) */
994 KEY_UNKNOWN, /* 0x12: FN+PGDOWN */ 994 KEY_UNKNOWN, /* 0x12: FN+PGDOWN */
995 KEY_ZOOM, /* 0x13: FN+SPACE (zoom) */ 995 KEY_ZOOM, /* 0x13: FN+SPACE (zoom) */
996 KEY_VOLUMEUP, /* 0x14: VOLUME UP */ 996 KEY_RESERVED, /* 0x14: VOLUME UP */
997 KEY_VOLUMEDOWN, /* 0x15: VOLUME DOWN */ 997 KEY_RESERVED, /* 0x15: VOLUME DOWN */
998 KEY_MUTE, /* 0x16: MUTE */ 998 KEY_RESERVED, /* 0x16: MUTE */
999 KEY_VENDOR, /* 0x17: Thinkpad/AccessIBM/Lenovo */ 999 KEY_VENDOR, /* 0x17: Thinkpad/AccessIBM/Lenovo */
1000 /* (assignments unknown, please report if found) */ 1000 /* (assignments unknown, please report if found) */
1001 KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, 1001 KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
@@ -1342,9 +1342,8 @@ static int hotkey_read(char *p)
1342 return len; 1342 return len;
1343 } 1343 }
1344 1344
1345 res = mutex_lock_interruptible(&hotkey_mutex); 1345 if (mutex_lock_interruptible(&hotkey_mutex))
1346 if (res < 0) 1346 return -ERESTARTSYS;
1347 return res;
1348 res = hotkey_get(&status, &mask); 1347 res = hotkey_get(&status, &mask);
1349 mutex_unlock(&hotkey_mutex); 1348 mutex_unlock(&hotkey_mutex);
1350 if (res) 1349 if (res)
@@ -1373,9 +1372,8 @@ static int hotkey_write(char *buf)
1373 if (!tp_features.hotkey) 1372 if (!tp_features.hotkey)
1374 return -ENODEV; 1373 return -ENODEV;
1375 1374
1376 res = mutex_lock_interruptible(&hotkey_mutex); 1375 if (mutex_lock_interruptible(&hotkey_mutex))
1377 if (res < 0) 1376 return -ERESTARTSYS;
1378 return res;
1379 1377
1380 res = hotkey_get(&status, &mask); 1378 res = hotkey_get(&status, &mask);
1381 if (res) 1379 if (res)
@@ -3114,6 +3112,99 @@ static struct backlight_ops ibm_backlight_data = {
3114 3112
3115static struct mutex brightness_mutex; 3113static struct mutex brightness_mutex;
3116 3114
3115static int __init tpacpi_query_bcll_levels(acpi_handle handle)
3116{
3117 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
3118 union acpi_object *obj;
3119 int rc;
3120
3121 if (ACPI_SUCCESS(acpi_evaluate_object(handle, NULL, NULL, &buffer))) {
3122 obj = (union acpi_object *)buffer.pointer;
3123 if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) {
3124 printk(IBM_ERR "Unknown BCLL data, "
3125 "please report this to %s\n", IBM_MAIL);
3126 rc = 0;
3127 } else {
3128 rc = obj->package.count;
3129 }
3130 } else {
3131 return 0;
3132 }
3133
3134 kfree(buffer.pointer);
3135 return rc;
3136}
3137
3138static acpi_status __init brightness_find_bcll(acpi_handle handle, u32 lvl,
3139 void *context, void **rv)
3140{
3141 char name[ACPI_PATH_SEGMENT_LENGTH];
3142 struct acpi_buffer buffer = { sizeof(name), &name };
3143
3144 if (ACPI_SUCCESS(acpi_get_name(handle, ACPI_SINGLE_NAME, &buffer)) &&
3145 !strncmp("BCLL", name, sizeof(name) - 1)) {
3146 if (tpacpi_query_bcll_levels(handle) == 16) {
3147 *rv = handle;
3148 return AE_CTRL_TERMINATE;
3149 } else {
3150 return AE_OK;
3151 }
3152 } else {
3153 return AE_OK;
3154 }
3155}
3156
3157static int __init brightness_check_levels(void)
3158{
3159 int status;
3160 void *found_node = NULL;
3161
3162 if (!vid_handle) {
3163 IBM_ACPIHANDLE_INIT(vid);
3164 }
3165 if (!vid_handle)
3166 return 0;
3167
3168 /* Search for a BCLL package with 16 levels */
3169 status = acpi_walk_namespace(ACPI_TYPE_PACKAGE, vid_handle, 3,
3170 brightness_find_bcll, NULL, &found_node);
3171
3172 return (ACPI_SUCCESS(status) && found_node != NULL);
3173}
3174
3175static acpi_status __init brightness_find_bcl(acpi_handle handle, u32 lvl,
3176 void *context, void **rv)
3177{
3178 char name[ACPI_PATH_SEGMENT_LENGTH];
3179 struct acpi_buffer buffer = { sizeof(name), &name };
3180
3181 if (ACPI_SUCCESS(acpi_get_name(handle, ACPI_SINGLE_NAME, &buffer)) &&
3182 !strncmp("_BCL", name, sizeof(name) - 1)) {
3183 *rv = handle;
3184 return AE_CTRL_TERMINATE;
3185 } else {
3186 return AE_OK;
3187 }
3188}
3189
3190static int __init brightness_check_std_acpi_support(void)
3191{
3192 int status;
3193 void *found_node = NULL;
3194
3195 if (!vid_handle) {
3196 IBM_ACPIHANDLE_INIT(vid);
3197 }
3198 if (!vid_handle)
3199 return 0;
3200
3201 /* Search for a _BCL method, but don't execute it */
3202 status = acpi_walk_namespace(ACPI_TYPE_METHOD, vid_handle, 3,
3203 brightness_find_bcl, NULL, &found_node);
3204
3205 return (ACPI_SUCCESS(status) && found_node != NULL);
3206}
3207
3117static int __init brightness_init(struct ibm_init_struct *iibm) 3208static int __init brightness_init(struct ibm_init_struct *iibm)
3118{ 3209{
3119 int b; 3210 int b;
@@ -3122,6 +3213,18 @@ static int __init brightness_init(struct ibm_init_struct *iibm)
3122 3213
3123 mutex_init(&brightness_mutex); 3214 mutex_init(&brightness_mutex);
3124 3215
3216 if (!brightness_enable) {
3217 dbg_printk(TPACPI_DBG_INIT,
3218 "brightness support disabled by module parameter\n");
3219 return 1;
3220 } else if (brightness_enable > 1) {
3221 if (brightness_check_std_acpi_support()) {
3222 printk(IBM_NOTICE
3223 "standard ACPI backlight interface available, not loading native one...\n");
3224 return 1;
3225 }
3226 }
3227
3125 if (!brightness_mode) { 3228 if (!brightness_mode) {
3126 if (thinkpad_id.vendor == PCI_VENDOR_ID_LENOVO) 3229 if (thinkpad_id.vendor == PCI_VENDOR_ID_LENOVO)
3127 brightness_mode = 2; 3230 brightness_mode = 2;
@@ -3135,10 +3238,17 @@ static int __init brightness_init(struct ibm_init_struct *iibm)
3135 if (brightness_mode > 3) 3238 if (brightness_mode > 3)
3136 return -EINVAL; 3239 return -EINVAL;
3137 3240
3241 tp_features.bright_16levels =
3242 thinkpad_id.vendor == PCI_VENDOR_ID_LENOVO &&
3243 brightness_check_levels();
3244
3138 b = brightness_get(NULL); 3245 b = brightness_get(NULL);
3139 if (b < 0) 3246 if (b < 0)
3140 return 1; 3247 return 1;
3141 3248
3249 if (tp_features.bright_16levels)
3250 printk(IBM_INFO "detected a 16-level brightness capable ThinkPad\n");
3251
3142 ibm_backlight_device = backlight_device_register( 3252 ibm_backlight_device = backlight_device_register(
3143 TPACPI_BACKLIGHT_DEV_NAME, NULL, NULL, 3253 TPACPI_BACKLIGHT_DEV_NAME, NULL, NULL,
3144 &ibm_backlight_data); 3254 &ibm_backlight_data);
@@ -3148,7 +3258,8 @@ static int __init brightness_init(struct ibm_init_struct *iibm)
3148 } 3258 }
3149 vdbg_printk(TPACPI_DBG_INIT, "brightness is supported\n"); 3259 vdbg_printk(TPACPI_DBG_INIT, "brightness is supported\n");
3150 3260
3151 ibm_backlight_device->props.max_brightness = 7; 3261 ibm_backlight_device->props.max_brightness =
3262 (tp_features.bright_16levels)? 15 : 7;
3152 ibm_backlight_device->props.brightness = b; 3263 ibm_backlight_device->props.brightness = b;
3153 backlight_update_status(ibm_backlight_device); 3264 backlight_update_status(ibm_backlight_device);
3154 3265
@@ -3167,6 +3278,8 @@ static void brightness_exit(void)
3167 3278
3168static int brightness_update_status(struct backlight_device *bd) 3279static int brightness_update_status(struct backlight_device *bd)
3169{ 3280{
3281 /* it is the backlight class's job (caller) to handle
3282 * EINTR and other errors properly */
3170 return brightness_set( 3283 return brightness_set(
3171 (bd->props.fb_blank == FB_BLANK_UNBLANK && 3284 (bd->props.fb_blank == FB_BLANK_UNBLANK &&
3172 bd->props.power == FB_BLANK_UNBLANK) ? 3285 bd->props.power == FB_BLANK_UNBLANK) ?
@@ -3184,13 +3297,14 @@ static int brightness_get(struct backlight_device *bd)
3184 if (brightness_mode & 1) { 3297 if (brightness_mode & 1) {
3185 if (!acpi_ec_read(brightness_offset, &lec)) 3298 if (!acpi_ec_read(brightness_offset, &lec))
3186 return -EIO; 3299 return -EIO;
3187 lec &= 7; 3300 lec &= (tp_features.bright_16levels)? 0x0f : 0x07;
3188 level = lec; 3301 level = lec;
3189 }; 3302 };
3190 if (brightness_mode & 2) { 3303 if (brightness_mode & 2) {
3191 lcmos = (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS) 3304 lcmos = (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS)
3192 & TP_NVRAM_MASK_LEVEL_BRIGHTNESS) 3305 & TP_NVRAM_MASK_LEVEL_BRIGHTNESS)
3193 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS; 3306 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS;
3307 lcmos &= (tp_features.bright_16levels)? 0x0f : 0x07;
3194 level = lcmos; 3308 level = lcmos;
3195 } 3309 }
3196 3310
@@ -3206,12 +3320,13 @@ static int brightness_get(struct backlight_device *bd)
3206 return level; 3320 return level;
3207} 3321}
3208 3322
3323/* May return EINTR which can always be mapped to ERESTARTSYS */
3209static int brightness_set(int value) 3324static int brightness_set(int value)
3210{ 3325{
3211 int cmos_cmd, inc, i, res; 3326 int cmos_cmd, inc, i, res;
3212 int current_value; 3327 int current_value;
3213 3328
3214 if (value > 7) 3329 if (value > ((tp_features.bright_16levels)? 15 : 7))
3215 return -EINVAL; 3330 return -EINVAL;
3216 3331
3217 res = mutex_lock_interruptible(&brightness_mutex); 3332 res = mutex_lock_interruptible(&brightness_mutex);
@@ -3227,7 +3342,7 @@ static int brightness_set(int value)
3227 cmos_cmd = value > current_value ? 3342 cmos_cmd = value > current_value ?
3228 TP_CMOS_BRIGHTNESS_UP : 3343 TP_CMOS_BRIGHTNESS_UP :
3229 TP_CMOS_BRIGHTNESS_DOWN; 3344 TP_CMOS_BRIGHTNESS_DOWN;
3230 inc = value > current_value ? 1 : -1; 3345 inc = (value > current_value)? 1 : -1;
3231 3346
3232 res = 0; 3347 res = 0;
3233 for (i = current_value; i != value; i += inc) { 3348 for (i = current_value; i != value; i += inc) {
@@ -3256,10 +3371,11 @@ static int brightness_read(char *p)
3256 if ((level = brightness_get(NULL)) < 0) { 3371 if ((level = brightness_get(NULL)) < 0) {
3257 len += sprintf(p + len, "level:\t\tunreadable\n"); 3372 len += sprintf(p + len, "level:\t\tunreadable\n");
3258 } else { 3373 } else {
3259 len += sprintf(p + len, "level:\t\t%d\n", level & 0x7); 3374 len += sprintf(p + len, "level:\t\t%d\n", level);
3260 len += sprintf(p + len, "commands:\tup, down\n"); 3375 len += sprintf(p + len, "commands:\tup, down\n");
3261 len += sprintf(p + len, "commands:\tlevel <level>" 3376 len += sprintf(p + len, "commands:\tlevel <level>"
3262 " (<level> is 0-7)\n"); 3377 " (<level> is 0-%d)\n",
3378 (tp_features.bright_16levels) ? 15 : 7);
3263 } 3379 }
3264 3380
3265 return len; 3381 return len;
@@ -3268,28 +3384,34 @@ static int brightness_read(char *p)
3268static int brightness_write(char *buf) 3384static int brightness_write(char *buf)
3269{ 3385{
3270 int level; 3386 int level;
3271 int new_level; 3387 int rc;
3272 char *cmd; 3388 char *cmd;
3389 int max_level = (tp_features.bright_16levels) ? 15 : 7;
3273 3390
3274 while ((cmd = next_cmd(&buf))) { 3391 level = brightness_get(NULL);
3275 if ((level = brightness_get(NULL)) < 0) 3392 if (level < 0)
3276 return level; 3393 return level;
3277 level &= 7;
3278 3394
3395 while ((cmd = next_cmd(&buf))) {
3279 if (strlencmp(cmd, "up") == 0) { 3396 if (strlencmp(cmd, "up") == 0) {
3280 new_level = level == 7 ? 7 : level + 1; 3397 if (level < max_level)
3398 level++;
3281 } else if (strlencmp(cmd, "down") == 0) { 3399 } else if (strlencmp(cmd, "down") == 0) {
3282 new_level = level == 0 ? 0 : level - 1; 3400 if (level > 0)
3283 } else if (sscanf(cmd, "level %d", &new_level) == 1 && 3401 level--;
3284 new_level >= 0 && new_level <= 7) { 3402 } else if (sscanf(cmd, "level %d", &level) == 1 &&
3285 /* new_level set */ 3403 level >= 0 && level <= max_level) {
3404 /* new level set */
3286 } else 3405 } else
3287 return -EINVAL; 3406 return -EINVAL;
3288
3289 brightness_set(new_level);
3290 } 3407 }
3291 3408
3292 return 0; 3409 /*
3410 * Now we know what the final level should be, so we try to set it.
3411 * Doing it this way makes the syscall restartable in case of EINTR
3412 */
3413 rc = brightness_set(level);
3414 return (rc == -EINTR)? ERESTARTSYS : rc;
3293} 3415}
3294 3416
3295static struct ibm_struct brightness_driver_data = { 3417static struct ibm_struct brightness_driver_data = {
@@ -3652,9 +3774,8 @@ static ssize_t fan_pwm1_store(struct device *dev,
3652 /* scale down from 0-255 to 0-7 */ 3774 /* scale down from 0-255 to 0-7 */
3653 newlevel = (s >> 5) & 0x07; 3775 newlevel = (s >> 5) & 0x07;
3654 3776
3655 rc = mutex_lock_interruptible(&fan_mutex); 3777 if (mutex_lock_interruptible(&fan_mutex))
3656 if (rc < 0) 3778 return -ERESTARTSYS;
3657 return rc;
3658 3779
3659 rc = fan_get_status(&status); 3780 rc = fan_get_status(&status);
3660 if (!rc && (status & 3781 if (!rc && (status &
@@ -3904,9 +4025,8 @@ static int fan_get_status_safe(u8 *status)
3904 int rc; 4025 int rc;
3905 u8 s; 4026 u8 s;
3906 4027
3907 rc = mutex_lock_interruptible(&fan_mutex); 4028 if (mutex_lock_interruptible(&fan_mutex))
3908 if (rc < 0) 4029 return -ERESTARTSYS;
3909 return rc;
3910 rc = fan_get_status(&s); 4030 rc = fan_get_status(&s);
3911 if (!rc) 4031 if (!rc)
3912 fan_update_desired_level(s); 4032 fan_update_desired_level(s);
@@ -4040,9 +4160,8 @@ static int fan_set_level_safe(int level)
4040 if (!fan_control_allowed) 4160 if (!fan_control_allowed)
4041 return -EPERM; 4161 return -EPERM;
4042 4162
4043 rc = mutex_lock_interruptible(&fan_mutex); 4163 if (mutex_lock_interruptible(&fan_mutex))
4044 if (rc < 0) 4164 return -ERESTARTSYS;
4045 return rc;
4046 4165
4047 if (level == TPACPI_FAN_LAST_LEVEL) 4166 if (level == TPACPI_FAN_LAST_LEVEL)
4048 level = fan_control_desired_level; 4167 level = fan_control_desired_level;
@@ -4063,9 +4182,8 @@ static int fan_set_enable(void)
4063 if (!fan_control_allowed) 4182 if (!fan_control_allowed)
4064 return -EPERM; 4183 return -EPERM;
4065 4184
4066 rc = mutex_lock_interruptible(&fan_mutex); 4185 if (mutex_lock_interruptible(&fan_mutex))
4067 if (rc < 0) 4186 return -ERESTARTSYS;
4068 return rc;
4069 4187
4070 switch (fan_control_access_mode) { 4188 switch (fan_control_access_mode) {
4071 case TPACPI_FAN_WR_ACPI_FANS: 4189 case TPACPI_FAN_WR_ACPI_FANS:
@@ -4119,9 +4237,8 @@ static int fan_set_disable(void)
4119 if (!fan_control_allowed) 4237 if (!fan_control_allowed)
4120 return -EPERM; 4238 return -EPERM;
4121 4239
4122 rc = mutex_lock_interruptible(&fan_mutex); 4240 if (mutex_lock_interruptible(&fan_mutex))
4123 if (rc < 0) 4241 return -ERESTARTSYS;
4124 return rc;
4125 4242
4126 rc = 0; 4243 rc = 0;
4127 switch (fan_control_access_mode) { 4244 switch (fan_control_access_mode) {
@@ -4158,9 +4275,8 @@ static int fan_set_speed(int speed)
4158 if (!fan_control_allowed) 4275 if (!fan_control_allowed)
4159 return -EPERM; 4276 return -EPERM;
4160 4277
4161 rc = mutex_lock_interruptible(&fan_mutex); 4278 if (mutex_lock_interruptible(&fan_mutex))
4162 if (rc < 0) 4279 return -ERESTARTSYS;
4163 return rc;
4164 4280
4165 rc = 0; 4281 rc = 0;
4166 switch (fan_control_access_mode) { 4282 switch (fan_control_access_mode) {
@@ -4701,9 +4817,15 @@ static int __init set_ibm_param(const char *val, struct kernel_param *kp)
4701 unsigned int i; 4817 unsigned int i;
4702 struct ibm_struct *ibm; 4818 struct ibm_struct *ibm;
4703 4819
4820 if (!kp || !kp->name || !val)
4821 return -EINVAL;
4822
4704 for (i = 0; i < ARRAY_SIZE(ibms_init); i++) { 4823 for (i = 0; i < ARRAY_SIZE(ibms_init); i++) {
4705 ibm = ibms_init[i].data; 4824 ibm = ibms_init[i].data;
4706 BUG_ON(ibm == NULL); 4825 WARN_ON(ibm == NULL);
4826
4827 if (!ibm || !ibm->name)
4828 continue;
4707 4829
4708 if (strcmp(ibm->name, kp->name) == 0 && ibm->write) { 4830 if (strcmp(ibm->name, kp->name) == 0 && ibm->write) {
4709 if (strlen(val) > sizeof(ibms_init[i].param) - 2) 4831 if (strlen(val) > sizeof(ibms_init[i].param) - 2)
@@ -4732,6 +4854,9 @@ module_param_named(fan_control, fan_control_allowed, bool, 0);
4732static int brightness_mode; 4854static int brightness_mode;
4733module_param_named(brightness_mode, brightness_mode, int, 0); 4855module_param_named(brightness_mode, brightness_mode, int, 0);
4734 4856
4857static unsigned int brightness_enable = 2; /* 2 = auto, 0 = no, 1 = yes */
4858module_param(brightness_enable, uint, 0);
4859
4735static unsigned int hotkey_report_mode; 4860static unsigned int hotkey_report_mode;
4736module_param(hotkey_report_mode, uint, 0); 4861module_param(hotkey_report_mode, uint, 0);
4737 4862
diff --git a/drivers/misc/thinkpad_acpi.h b/drivers/misc/thinkpad_acpi.h
index 3abcc8120634..8fba2bbe345e 100644
--- a/drivers/misc/thinkpad_acpi.h
+++ b/drivers/misc/thinkpad_acpi.h
@@ -84,7 +84,7 @@
84 84
85/* ThinkPad CMOS NVRAM constants */ 85/* ThinkPad CMOS NVRAM constants */
86#define TP_NVRAM_ADDR_BRIGHTNESS 0x5e 86#define TP_NVRAM_ADDR_BRIGHTNESS 0x5e
87#define TP_NVRAM_MASK_LEVEL_BRIGHTNESS 0x07 87#define TP_NVRAM_MASK_LEVEL_BRIGHTNESS 0x0f
88#define TP_NVRAM_POS_LEVEL_BRIGHTNESS 0 88#define TP_NVRAM_POS_LEVEL_BRIGHTNESS 0
89 89
90#define onoff(status,bit) ((status) & (1 << (bit)) ? "on" : "off") 90#define onoff(status,bit) ((status) & (1 << (bit)) ? "on" : "off")
@@ -246,6 +246,7 @@ static struct {
246 u32 hotkey_wlsw:1; 246 u32 hotkey_wlsw:1;
247 u32 light:1; 247 u32 light:1;
248 u32 light_status:1; 248 u32 light_status:1;
249 u32 bright_16levels:1;
249 u32 wan:1; 250 u32 wan:1;
250 u32 fan_ctrl_status_undef:1; 251 u32 fan_ctrl_status_undef:1;
251 u32 input_device_registered:1; 252 u32 input_device_registered:1;
@@ -338,6 +339,7 @@ static int bluetooth_write(char *buf);
338static struct backlight_device *ibm_backlight_device; 339static struct backlight_device *ibm_backlight_device;
339static int brightness_offset = 0x31; 340static int brightness_offset = 0x31;
340static int brightness_mode; 341static int brightness_mode;
342static unsigned int brightness_enable; /* 0 = no, 1 = yes, 2 = auto */
341 343
342static int brightness_init(struct ibm_init_struct *iibm); 344static int brightness_init(struct ibm_init_struct *iibm);
343static void brightness_exit(void); 345static void brightness_exit(void);
diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
index e38d5a3b2a89..aeb32a93f6a0 100644
--- a/drivers/mmc/card/block.c
+++ b/drivers/mmc/card/block.c
@@ -44,6 +44,9 @@
44 * max 8 partitions per card 44 * max 8 partitions per card
45 */ 45 */
46#define MMC_SHIFT 3 46#define MMC_SHIFT 3
47#define MMC_NUM_MINORS (256 >> MMC_SHIFT)
48
49static unsigned long dev_use[MMC_NUM_MINORS/(8*sizeof(unsigned long))];
47 50
48/* 51/*
49 * There is one mmc_blk_data per slot. 52 * There is one mmc_blk_data per slot.
@@ -80,6 +83,9 @@ static void mmc_blk_put(struct mmc_blk_data *md)
80 mutex_lock(&open_lock); 83 mutex_lock(&open_lock);
81 md->usage--; 84 md->usage--;
82 if (md->usage == 0) { 85 if (md->usage == 0) {
86 int devidx = md->disk->first_minor >> MMC_SHIFT;
87 __clear_bit(devidx, dev_use);
88
83 put_disk(md->disk); 89 put_disk(md->disk);
84 kfree(md); 90 kfree(md);
85 } 91 }
@@ -321,7 +327,13 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
321 req->rq_disk->disk_name, err); 327 req->rq_disk->disk_name, err);
322 goto cmd_err; 328 goto cmd_err;
323 } 329 }
324 } while (!(cmd.resp[0] & R1_READY_FOR_DATA)); 330 /*
331 * Some cards mishandle the status bits,
332 * so make sure to check both the busy
333 * indication and the card state.
334 */
335 } while (!(cmd.resp[0] & R1_READY_FOR_DATA) ||
336 (R1_CURRENT_STATE(cmd.resp[0]) == 7));
325 337
326#if 0 338#if 0
327 if (cmd.resp[0] & ~0x00000900) 339 if (cmd.resp[0] & ~0x00000900)
@@ -400,9 +412,6 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
400 return 0; 412 return 0;
401} 413}
402 414
403#define MMC_NUM_MINORS (256 >> MMC_SHIFT)
404
405static unsigned long dev_use[MMC_NUM_MINORS/(8*sizeof(unsigned long))];
406 415
407static inline int mmc_blk_readonly(struct mmc_card *card) 416static inline int mmc_blk_readonly(struct mmc_card *card)
408{ 417{
@@ -568,17 +577,12 @@ static void mmc_blk_remove(struct mmc_card *card)
568 struct mmc_blk_data *md = mmc_get_drvdata(card); 577 struct mmc_blk_data *md = mmc_get_drvdata(card);
569 578
570 if (md) { 579 if (md) {
571 int devidx;
572
573 /* Stop new requests from getting into the queue */ 580 /* Stop new requests from getting into the queue */
574 del_gendisk(md->disk); 581 del_gendisk(md->disk);
575 582
576 /* Then flush out any already in there */ 583 /* Then flush out any already in there */
577 mmc_cleanup_queue(&md->queue); 584 mmc_cleanup_queue(&md->queue);
578 585
579 devidx = md->disk->first_minor >> MMC_SHIFT;
580 __clear_bit(devidx, dev_use);
581
582 mmc_blk_put(md); 586 mmc_blk_put(md);
583 } 587 }
584 mmc_set_drvdata(card, NULL); 588 mmc_set_drvdata(card, NULL);
diff --git a/drivers/mmc/card/queue.c b/drivers/mmc/card/queue.c
index 1b9c9b6da5b7..30cd13b13ac3 100644
--- a/drivers/mmc/card/queue.c
+++ b/drivers/mmc/card/queue.c
@@ -180,12 +180,13 @@ int mmc_init_queue(struct mmc_queue *mq, struct mmc_card *card, spinlock_t *lock
180 blk_queue_max_hw_segments(mq->queue, host->max_hw_segs); 180 blk_queue_max_hw_segments(mq->queue, host->max_hw_segs);
181 blk_queue_max_segment_size(mq->queue, host->max_seg_size); 181 blk_queue_max_segment_size(mq->queue, host->max_seg_size);
182 182
183 mq->sg = kzalloc(sizeof(struct scatterlist) * 183 mq->sg = kmalloc(sizeof(struct scatterlist) *
184 host->max_phys_segs, GFP_KERNEL); 184 host->max_phys_segs, GFP_KERNEL);
185 if (!mq->sg) { 185 if (!mq->sg) {
186 ret = -ENOMEM; 186 ret = -ENOMEM;
187 goto cleanup_queue; 187 goto cleanup_queue;
188 } 188 }
189 sg_init_table(mq->sg, host->max_phys_segs);
189 } 190 }
190 191
191 init_MUTEX(&mq->thread_sem); 192 init_MUTEX(&mq->thread_sem);
diff --git a/drivers/mmc/card/sdio_uart.c b/drivers/mmc/card/sdio_uart.c
index d552de683110..eeea84c309e6 100644
--- a/drivers/mmc/card/sdio_uart.c
+++ b/drivers/mmc/card/sdio_uart.c
@@ -386,7 +386,7 @@ static void sdio_uart_stop_rx(struct sdio_uart_port *port)
386 sdio_out(port, UART_IER, port->ier); 386 sdio_out(port, UART_IER, port->ier);
387} 387}
388 388
389static void sdio_uart_receive_chars(struct sdio_uart_port *port, int *status) 389static void sdio_uart_receive_chars(struct sdio_uart_port *port, unsigned int *status)
390{ 390{
391 struct tty_struct *tty = port->tty; 391 struct tty_struct *tty = port->tty;
392 unsigned int ch, flag; 392 unsigned int ch, flag;
diff --git a/drivers/mmc/host/mmc_spi.c b/drivers/mmc/host/mmc_spi.c
index a6469218f194..365024b83d3d 100644
--- a/drivers/mmc/host/mmc_spi.c
+++ b/drivers/mmc/host/mmc_spi.c
@@ -176,8 +176,6 @@ mmc_spi_readbytes(struct mmc_spi_host *host, unsigned len)
176 DMA_FROM_DEVICE); 176 DMA_FROM_DEVICE);
177 177
178 status = spi_sync(host->spi, &host->readback); 178 status = spi_sync(host->spi, &host->readback);
179 if (status == 0)
180 status = host->readback.status;
181 179
182 if (host->dma_dev) 180 if (host->dma_dev)
183 dma_sync_single_for_cpu(host->dma_dev, 181 dma_sync_single_for_cpu(host->dma_dev,
@@ -480,8 +478,6 @@ mmc_spi_command_send(struct mmc_spi_host *host,
480 DMA_BIDIRECTIONAL); 478 DMA_BIDIRECTIONAL);
481 } 479 }
482 status = spi_sync(host->spi, &host->m); 480 status = spi_sync(host->spi, &host->m);
483 if (status == 0)
484 status = host->m.status;
485 481
486 if (host->dma_dev) 482 if (host->dma_dev)
487 dma_sync_single_for_cpu(host->dma_dev, 483 dma_sync_single_for_cpu(host->dma_dev,
@@ -624,8 +620,6 @@ mmc_spi_writeblock(struct mmc_spi_host *host, struct spi_transfer *t)
624 DMA_BIDIRECTIONAL); 620 DMA_BIDIRECTIONAL);
625 621
626 status = spi_sync(spi, &host->m); 622 status = spi_sync(spi, &host->m);
627 if (status == 0)
628 status = host->m.status;
629 623
630 if (status != 0) { 624 if (status != 0) {
631 dev_dbg(&spi->dev, "write error (%d)\n", status); 625 dev_dbg(&spi->dev, "write error (%d)\n", status);
@@ -726,8 +720,6 @@ mmc_spi_readblock(struct mmc_spi_host *host, struct spi_transfer *t)
726 } 720 }
727 721
728 status = spi_sync(spi, &host->m); 722 status = spi_sync(spi, &host->m);
729 if (status == 0)
730 status = host->m.status;
731 723
732 if (host->dma_dev) { 724 if (host->dma_dev) {
733 dma_sync_single_for_cpu(host->dma_dev, 725 dma_sync_single_for_cpu(host->dma_dev,
@@ -905,8 +897,6 @@ mmc_spi_data_do(struct mmc_spi_host *host, struct mmc_command *cmd,
905 DMA_BIDIRECTIONAL); 897 DMA_BIDIRECTIONAL);
906 898
907 tmp = spi_sync(spi, &host->m); 899 tmp = spi_sync(spi, &host->m);
908 if (tmp == 0)
909 tmp = host->m.status;
910 900
911 if (host->dma_dev) 901 if (host->dma_dev)
912 dma_sync_single_for_cpu(host->dma_dev, 902 dma_sync_single_for_cpu(host->dma_dev,
diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
index ff59d2e0475b..785bbdcf4a58 100644
--- a/drivers/mmc/host/sdhci.c
+++ b/drivers/mmc/host/sdhci.c
@@ -7,6 +7,10 @@
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or (at 8 * the Free Software Foundation; either version 2 of the License, or (at
9 * your option) any later version. 9 * your option) any later version.
10 *
11 * Thanks to the following companies for their support:
12 *
13 * - JMicron (hardware and technical support)
10 */ 14 */
11 15
12#include <linux/delay.h> 16#include <linux/delay.h>
@@ -26,13 +30,29 @@
26 30
27static unsigned int debug_quirks = 0; 31static unsigned int debug_quirks = 0;
28 32
33/*
34 * Different quirks to handle when the hardware deviates from a strict
35 * interpretation of the SDHCI specification.
36 */
37
38/* Controller doesn't honor resets unless we touch the clock register */
29#define SDHCI_QUIRK_CLOCK_BEFORE_RESET (1<<0) 39#define SDHCI_QUIRK_CLOCK_BEFORE_RESET (1<<0)
40/* Controller has bad caps bits, but really supports DMA */
30#define SDHCI_QUIRK_FORCE_DMA (1<<1) 41#define SDHCI_QUIRK_FORCE_DMA (1<<1)
31/* Controller doesn't like some resets when there is no card inserted. */ 42/* Controller doesn't like some resets when there is no card inserted. */
32#define SDHCI_QUIRK_NO_CARD_NO_RESET (1<<2) 43#define SDHCI_QUIRK_NO_CARD_NO_RESET (1<<2)
44/* Controller doesn't like clearing the power reg before a change */
33#define SDHCI_QUIRK_SINGLE_POWER_WRITE (1<<3) 45#define SDHCI_QUIRK_SINGLE_POWER_WRITE (1<<3)
46/* Controller has flaky internal state so reset it on each ios change */
34#define SDHCI_QUIRK_RESET_CMD_DATA_ON_IOS (1<<4) 47#define SDHCI_QUIRK_RESET_CMD_DATA_ON_IOS (1<<4)
48/* Controller has an unusable DMA engine */
35#define SDHCI_QUIRK_BROKEN_DMA (1<<5) 49#define SDHCI_QUIRK_BROKEN_DMA (1<<5)
50/* Controller can only DMA from 32-bit aligned addresses */
51#define SDHCI_QUIRK_32BIT_DMA_ADDR (1<<6)
52/* Controller can only DMA chunk sizes that are a multiple of 32 bits */
53#define SDHCI_QUIRK_32BIT_DMA_SIZE (1<<7)
54/* Controller needs to be reset after each request to stay stable */
55#define SDHCI_QUIRK_RESET_AFTER_REQUEST (1<<8)
36 56
37static const struct pci_device_id pci_ids[] __devinitdata = { 57static const struct pci_device_id pci_ids[] __devinitdata = {
38 { 58 {
@@ -97,6 +117,16 @@ static const struct pci_device_id pci_ids[] __devinitdata = {
97 SDHCI_QUIRK_RESET_CMD_DATA_ON_IOS, 117 SDHCI_QUIRK_RESET_CMD_DATA_ON_IOS,
98 }, 118 },
99 119
120 {
121 .vendor = PCI_VENDOR_ID_JMICRON,
122 .device = PCI_DEVICE_ID_JMICRON_JMB38X_SD,
123 .subvendor = PCI_ANY_ID,
124 .subdevice = PCI_ANY_ID,
125 .driver_data = SDHCI_QUIRK_32BIT_DMA_ADDR |
126 SDHCI_QUIRK_32BIT_DMA_SIZE |
127 SDHCI_QUIRK_RESET_AFTER_REQUEST,
128 },
129
100 { /* Generic SD host controller */ 130 { /* Generic SD host controller */
101 PCI_DEVICE_CLASS((PCI_CLASS_SYSTEM_SDHCI << 8), 0xFFFF00) 131 PCI_DEVICE_CLASS((PCI_CLASS_SYSTEM_SDHCI << 8), 0xFFFF00)
102 }, 132 },
@@ -419,7 +449,29 @@ static void sdhci_prepare_data(struct sdhci_host *host, struct mmc_data *data)
419 449
420 writeb(count, host->ioaddr + SDHCI_TIMEOUT_CONTROL); 450 writeb(count, host->ioaddr + SDHCI_TIMEOUT_CONTROL);
421 451
422 if (host->flags & SDHCI_USE_DMA) { 452 if (host->flags & SDHCI_USE_DMA)
453 host->flags |= SDHCI_REQ_USE_DMA;
454
455 if (unlikely((host->flags & SDHCI_REQ_USE_DMA) &&
456 (host->chip->quirks & SDHCI_QUIRK_32BIT_DMA_SIZE) &&
457 ((data->blksz * data->blocks) & 0x3))) {
458 DBG("Reverting to PIO because of transfer size (%d)\n",
459 data->blksz * data->blocks);
460 host->flags &= ~SDHCI_REQ_USE_DMA;
461 }
462
463 /*
464 * The assumption here being that alignment is the same after
465 * translation to device address space.
466 */
467 if (unlikely((host->flags & SDHCI_REQ_USE_DMA) &&
468 (host->chip->quirks & SDHCI_QUIRK_32BIT_DMA_ADDR) &&
469 (data->sg->offset & 0x3))) {
470 DBG("Reverting to PIO because of bad alignment\n");
471 host->flags &= ~SDHCI_REQ_USE_DMA;
472 }
473
474 if (host->flags & SDHCI_REQ_USE_DMA) {
423 int count; 475 int count;
424 476
425 count = pci_map_sg(host->chip->pdev, data->sg, data->sg_len, 477 count = pci_map_sg(host->chip->pdev, data->sg, data->sg_len,
@@ -456,7 +508,7 @@ static void sdhci_set_transfer_mode(struct sdhci_host *host,
456 mode |= SDHCI_TRNS_MULTI; 508 mode |= SDHCI_TRNS_MULTI;
457 if (data->flags & MMC_DATA_READ) 509 if (data->flags & MMC_DATA_READ)
458 mode |= SDHCI_TRNS_READ; 510 mode |= SDHCI_TRNS_READ;
459 if (host->flags & SDHCI_USE_DMA) 511 if (host->flags & SDHCI_REQ_USE_DMA)
460 mode |= SDHCI_TRNS_DMA; 512 mode |= SDHCI_TRNS_DMA;
461 513
462 writew(mode, host->ioaddr + SDHCI_TRANSFER_MODE); 514 writew(mode, host->ioaddr + SDHCI_TRANSFER_MODE);
@@ -472,7 +524,7 @@ static void sdhci_finish_data(struct sdhci_host *host)
472 data = host->data; 524 data = host->data;
473 host->data = NULL; 525 host->data = NULL;
474 526
475 if (host->flags & SDHCI_USE_DMA) { 527 if (host->flags & SDHCI_REQ_USE_DMA) {
476 pci_unmap_sg(host->chip->pdev, data->sg, data->sg_len, 528 pci_unmap_sg(host->chip->pdev, data->sg, data->sg_len,
477 (data->flags & MMC_DATA_READ)?PCI_DMA_FROMDEVICE:PCI_DMA_TODEVICE); 529 (data->flags & MMC_DATA_READ)?PCI_DMA_FROMDEVICE:PCI_DMA_TODEVICE);
478 } 530 }
@@ -886,7 +938,8 @@ static void sdhci_tasklet_finish(unsigned long param)
886 */ 938 */
887 if (mrq->cmd->error || 939 if (mrq->cmd->error ||
888 (mrq->data && (mrq->data->error || 940 (mrq->data && (mrq->data->error ||
889 (mrq->data->stop && mrq->data->stop->error)))) { 941 (mrq->data->stop && mrq->data->stop->error))) ||
942 (host->chip->quirks & SDHCI_QUIRK_RESET_AFTER_REQUEST)) {
890 943
891 /* Some controllers need this kick or reset won't work here */ 944 /* Some controllers need this kick or reset won't work here */
892 if (host->chip->quirks & SDHCI_QUIRK_CLOCK_BEFORE_RESET) { 945 if (host->chip->quirks & SDHCI_QUIRK_CLOCK_BEFORE_RESET) {
@@ -1284,7 +1337,7 @@ static int __devinit sdhci_probe_slot(struct pci_dev *pdev, int slot)
1284 1337
1285 version = readw(host->ioaddr + SDHCI_HOST_VERSION); 1338 version = readw(host->ioaddr + SDHCI_HOST_VERSION);
1286 version = (version & SDHCI_SPEC_VER_MASK) >> SDHCI_SPEC_VER_SHIFT; 1339 version = (version & SDHCI_SPEC_VER_MASK) >> SDHCI_SPEC_VER_SHIFT;
1287 if (version != 0) { 1340 if (version > 1) {
1288 printk(KERN_ERR "%s: Unknown controller version (%d). " 1341 printk(KERN_ERR "%s: Unknown controller version (%d). "
1289 "You may experience problems.\n", host->slot_descr, 1342 "You may experience problems.\n", host->slot_descr,
1290 version); 1343 version);
diff --git a/drivers/mmc/host/sdhci.h b/drivers/mmc/host/sdhci.h
index 05195ea900f4..e4d77b038bfa 100644
--- a/drivers/mmc/host/sdhci.h
+++ b/drivers/mmc/host/sdhci.h
@@ -171,7 +171,8 @@ struct sdhci_host {
171 spinlock_t lock; /* Mutex */ 171 spinlock_t lock; /* Mutex */
172 172
173 int flags; /* Host attributes */ 173 int flags; /* Host attributes */
174#define SDHCI_USE_DMA (1<<0) 174#define SDHCI_USE_DMA (1<<0) /* Host is DMA capable */
175#define SDHCI_REQ_USE_DMA (1<<1) /* Use DMA for this req. */
175 176
176 unsigned int max_clk; /* Max possible freq (MHz) */ 177 unsigned int max_clk; /* Max possible freq (MHz) */
177 unsigned int timeout_clk; /* Timeout freq (KHz) */ 178 unsigned int timeout_clk; /* Timeout freq (KHz) */
diff --git a/drivers/mmc/host/tifm_sd.c b/drivers/mmc/host/tifm_sd.c
index c11a3d256051..20d5c7bd940a 100644
--- a/drivers/mmc/host/tifm_sd.c
+++ b/drivers/mmc/host/tifm_sd.c
@@ -16,7 +16,6 @@
16#include <linux/mmc/host.h> 16#include <linux/mmc/host.h>
17#include <linux/highmem.h> 17#include <linux/highmem.h>
18#include <linux/scatterlist.h> 18#include <linux/scatterlist.h>
19#include <linux/log2.h>
20#include <asm/io.h> 19#include <asm/io.h>
21 20
22#define DRIVER_NAME "tifm_sd" 21#define DRIVER_NAME "tifm_sd"
@@ -638,17 +637,15 @@ static void tifm_sd_request(struct mmc_host *mmc, struct mmc_request *mrq)
638 goto err_out; 637 goto err_out;
639 } 638 }
640 639
641 if (mrq->data && !is_power_of_2(mrq->data->blksz)) {
642 printk(KERN_ERR "%s: Unsupported block size (%d bytes)\n",
643 sock->dev.bus_id, mrq->data->blksz);
644 mrq->cmd->error = -EINVAL;
645 goto err_out;
646 }
647
648 host->cmd_flags = 0; 640 host->cmd_flags = 0;
649 host->block_pos = 0; 641 host->block_pos = 0;
650 host->sg_pos = 0; 642 host->sg_pos = 0;
651 643
644 if (mrq->data && !is_power_of_2(mrq->data->blksz))
645 host->no_dma = 1;
646 else
647 host->no_dma = no_dma ? 1 : 0;
648
652 if (r_data) { 649 if (r_data) {
653 tifm_sd_set_data_timeout(host, r_data); 650 tifm_sd_set_data_timeout(host, r_data);
654 651
@@ -676,7 +673,7 @@ static void tifm_sd_request(struct mmc_host *mmc, struct mmc_request *mrq)
676 : PCI_DMA_FROMDEVICE)) { 673 : PCI_DMA_FROMDEVICE)) {
677 printk(KERN_ERR "%s : scatterlist map failed\n", 674 printk(KERN_ERR "%s : scatterlist map failed\n",
678 sock->dev.bus_id); 675 sock->dev.bus_id);
679 spin_unlock_irqrestore(&sock->lock, flags); 676 mrq->cmd->error = -ENOMEM;
680 goto err_out; 677 goto err_out;
681 } 678 }
682 host->sg_len = tifm_map_sg(sock, r_data->sg, 679 host->sg_len = tifm_map_sg(sock, r_data->sg,
@@ -692,7 +689,7 @@ static void tifm_sd_request(struct mmc_host *mmc, struct mmc_request *mrq)
692 r_data->flags & MMC_DATA_WRITE 689 r_data->flags & MMC_DATA_WRITE
693 ? PCI_DMA_TODEVICE 690 ? PCI_DMA_TODEVICE
694 : PCI_DMA_FROMDEVICE); 691 : PCI_DMA_FROMDEVICE);
695 spin_unlock_irqrestore(&sock->lock, flags); 692 mrq->cmd->error = -ENOMEM;
696 goto err_out; 693 goto err_out;
697 } 694 }
698 695
@@ -966,7 +963,6 @@ static int tifm_sd_probe(struct tifm_dev *sock)
966 return -ENOMEM; 963 return -ENOMEM;
967 964
968 host = mmc_priv(mmc); 965 host = mmc_priv(mmc);
969 host->no_dma = no_dma;
970 tifm_set_drvdata(sock, mmc); 966 tifm_set_drvdata(sock, mmc);
971 host->dev = sock; 967 host->dev = sock;
972 host->timeout_jiffies = msecs_to_jiffies(1000); 968 host->timeout_jiffies = msecs_to_jiffies(1000);
diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
index e8d69b0adf90..d9107e542dfa 100644
--- a/drivers/net/Kconfig
+++ b/drivers/net/Kconfig
@@ -888,7 +888,7 @@ config SMC91X
888 tristate "SMC 91C9x/91C1xxx support" 888 tristate "SMC 91C9x/91C1xxx support"
889 select CRC32 889 select CRC32
890 select MII 890 select MII
891 depends on ARM || REDWOOD_5 || REDWOOD_6 || M32R || SUPERH || SOC_AU1X00 || BFIN 891 depends on ARM || REDWOOD_5 || REDWOOD_6 || M32R || SUPERH || SOC_AU1X00 || BLACKFIN
892 help 892 help
893 This is a driver for SMC's 91x series of Ethernet chipsets, 893 This is a driver for SMC's 91x series of Ethernet chipsets,
894 including the SMC91C94 and the SMC91C111. Say Y if you want it 894 including the SMC91C94 and the SMC91C111. Say Y if you want it
@@ -926,7 +926,7 @@ config SMC911X
926 tristate "SMSC LAN911[5678] support" 926 tristate "SMSC LAN911[5678] support"
927 select CRC32 927 select CRC32
928 select MII 928 select MII
929 depends on ARCH_PXA || SUPERH 929 depends on ARCH_PXA || SH_MAGIC_PANEL_R2
930 help 930 help
931 This is a driver for SMSC's LAN911x series of Ethernet chipsets 931 This is a driver for SMSC's LAN911x series of Ethernet chipsets
932 including the new LAN9115, LAN9116, LAN9117, and LAN9118. 932 including the new LAN9115, LAN9116, LAN9117, and LAN9118.
diff --git a/drivers/net/amd8111e.c b/drivers/net/amd8111e.c
index eebf5bb2b03a..e7fdd81919bd 100644
--- a/drivers/net/amd8111e.c
+++ b/drivers/net/amd8111e.c
@@ -1340,7 +1340,9 @@ static int amd8111e_close(struct net_device * dev)
1340 struct amd8111e_priv *lp = netdev_priv(dev); 1340 struct amd8111e_priv *lp = netdev_priv(dev);
1341 netif_stop_queue(dev); 1341 netif_stop_queue(dev);
1342 1342
1343#ifdef CONFIG_AMD8111E_NAPI
1343 napi_disable(&lp->napi); 1344 napi_disable(&lp->napi);
1345#endif
1344 1346
1345 spin_lock_irq(&lp->lock); 1347 spin_lock_irq(&lp->lock);
1346 1348
@@ -1372,7 +1374,9 @@ static int amd8111e_open(struct net_device * dev )
1372 dev->name, dev)) 1374 dev->name, dev))
1373 return -EAGAIN; 1375 return -EAGAIN;
1374 1376
1377#ifdef CONFIG_AMD8111E_NAPI
1375 napi_enable(&lp->napi); 1378 napi_enable(&lp->napi);
1379#endif
1376 1380
1377 spin_lock_irq(&lp->lock); 1381 spin_lock_irq(&lp->lock);
1378 1382
@@ -1380,7 +1384,9 @@ static int amd8111e_open(struct net_device * dev )
1380 1384
1381 if(amd8111e_restart(dev)){ 1385 if(amd8111e_restart(dev)){
1382 spin_unlock_irq(&lp->lock); 1386 spin_unlock_irq(&lp->lock);
1387#ifdef CONFIG_AMD8111E_NAPI
1383 napi_disable(&lp->napi); 1388 napi_disable(&lp->napi);
1389#endif
1384 if (dev->irq) 1390 if (dev->irq)
1385 free_irq(dev->irq, dev); 1391 free_irq(dev->irq, dev);
1386 return -ENOMEM; 1392 return -ENOMEM;
diff --git a/drivers/net/bfin_mac.c b/drivers/net/bfin_mac.c
index 084acfd6fc5f..eb971755a3ff 100644
--- a/drivers/net/bfin_mac.c
+++ b/drivers/net/bfin_mac.c
@@ -676,7 +676,7 @@ static void bf537mac_rx(struct net_device *dev)
676 skb->protocol = eth_type_trans(skb, dev); 676 skb->protocol = eth_type_trans(skb, dev);
677#if defined(BFIN_MAC_CSUM_OFFLOAD) 677#if defined(BFIN_MAC_CSUM_OFFLOAD)
678 skb->csum = current_rx_ptr->status.ip_payload_csum; 678 skb->csum = current_rx_ptr->status.ip_payload_csum;
679 skb->ip_summed = CHECKSUM_PARTIAL; 679 skb->ip_summed = CHECKSUM_COMPLETE;
680#endif 680#endif
681 681
682 netif_rx(skb); 682 netif_rx(skb);
@@ -924,7 +924,7 @@ static int __init bf537mac_probe(struct net_device *dev)
924 if (!is_valid_ether_addr(dev->dev_addr)) { 924 if (!is_valid_ether_addr(dev->dev_addr)) {
925 /* Grab the MAC from the board somehow - this is done in the 925 /* Grab the MAC from the board somehow - this is done in the
926 arch/blackfin/mach-bf537/boards/eth_mac.c */ 926 arch/blackfin/mach-bf537/boards/eth_mac.c */
927 get_bf537_ether_addr(dev->dev_addr); 927 bfin_get_ether_addr(dev->dev_addr);
928 } 928 }
929 929
930 /* If still not valid, get a random one */ 930 /* If still not valid, get a random one */
diff --git a/drivers/net/bfin_mac.h b/drivers/net/bfin_mac.h
index 3a107ad75381..5970ea7142cd 100644
--- a/drivers/net/bfin_mac.h
+++ b/drivers/net/bfin_mac.h
@@ -92,4 +92,4 @@ struct bf537mac_local {
92 struct mii_bus mii_bus; 92 struct mii_bus mii_bus;
93}; 93};
94 94
95extern void get_bf537_ether_addr(char *addr); 95extern void bfin_get_ether_addr(char *addr);
diff --git a/drivers/net/bnx2.c b/drivers/net/bnx2.c
index da767d3d5af5..4e7b46e44874 100644
--- a/drivers/net/bnx2.c
+++ b/drivers/net/bnx2.c
@@ -56,8 +56,8 @@
56 56
57#define DRV_MODULE_NAME "bnx2" 57#define DRV_MODULE_NAME "bnx2"
58#define PFX DRV_MODULE_NAME ": " 58#define PFX DRV_MODULE_NAME ": "
59#define DRV_MODULE_VERSION "1.6.8" 59#define DRV_MODULE_VERSION "1.6.9"
60#define DRV_MODULE_RELDATE "October 17, 2007" 60#define DRV_MODULE_RELDATE "December 8, 2007"
61 61
62#define RUN_AT(x) (jiffies + (x)) 62#define RUN_AT(x) (jiffies + (x))
63 63
@@ -2387,18 +2387,24 @@ bnx2_reuse_rx_skb(struct bnx2 *bp, struct sk_buff *skb,
2387 prod_bd->rx_bd_haddr_lo = cons_bd->rx_bd_haddr_lo; 2387 prod_bd->rx_bd_haddr_lo = cons_bd->rx_bd_haddr_lo;
2388} 2388}
2389 2389
2390static inline u16
2391bnx2_get_hw_rx_cons(struct bnx2 *bp)
2392{
2393 u16 cons = bp->status_blk->status_rx_quick_consumer_index0;
2394
2395 if (unlikely((cons & MAX_RX_DESC_CNT) == MAX_RX_DESC_CNT))
2396 cons++;
2397 return cons;
2398}
2399
2390static int 2400static int
2391bnx2_rx_int(struct bnx2 *bp, int budget) 2401bnx2_rx_int(struct bnx2 *bp, int budget)
2392{ 2402{
2393 struct status_block *sblk = bp->status_blk;
2394 u16 hw_cons, sw_cons, sw_ring_cons, sw_prod, sw_ring_prod; 2403 u16 hw_cons, sw_cons, sw_ring_cons, sw_prod, sw_ring_prod;
2395 struct l2_fhdr *rx_hdr; 2404 struct l2_fhdr *rx_hdr;
2396 int rx_pkt = 0; 2405 int rx_pkt = 0;
2397 2406
2398 hw_cons = bp->hw_rx_cons = sblk->status_rx_quick_consumer_index0; 2407 hw_cons = bnx2_get_hw_rx_cons(bp);
2399 if ((hw_cons & MAX_RX_DESC_CNT) == MAX_RX_DESC_CNT) {
2400 hw_cons++;
2401 }
2402 sw_cons = bp->rx_cons; 2408 sw_cons = bp->rx_cons;
2403 sw_prod = bp->rx_prod; 2409 sw_prod = bp->rx_prod;
2404 2410
@@ -2515,10 +2521,7 @@ next_rx:
2515 2521
2516 /* Refresh hw_cons to see if there is new work */ 2522 /* Refresh hw_cons to see if there is new work */
2517 if (sw_cons == hw_cons) { 2523 if (sw_cons == hw_cons) {
2518 hw_cons = bp->hw_rx_cons = 2524 hw_cons = bnx2_get_hw_rx_cons(bp);
2519 sblk->status_rx_quick_consumer_index0;
2520 if ((hw_cons & MAX_RX_DESC_CNT) == MAX_RX_DESC_CNT)
2521 hw_cons++;
2522 rmb(); 2525 rmb();
2523 } 2526 }
2524 } 2527 }
@@ -2622,7 +2625,7 @@ bnx2_has_work(struct bnx2 *bp)
2622{ 2625{
2623 struct status_block *sblk = bp->status_blk; 2626 struct status_block *sblk = bp->status_blk;
2624 2627
2625 if ((sblk->status_rx_quick_consumer_index0 != bp->hw_rx_cons) || 2628 if ((bnx2_get_hw_rx_cons(bp) != bp->rx_cons) ||
2626 (sblk->status_tx_quick_consumer_index0 != bp->hw_tx_cons)) 2629 (sblk->status_tx_quick_consumer_index0 != bp->hw_tx_cons))
2627 return 1; 2630 return 1;
2628 2631
@@ -2655,7 +2658,7 @@ static int bnx2_poll_work(struct bnx2 *bp, int work_done, int budget)
2655 if (sblk->status_tx_quick_consumer_index0 != bp->hw_tx_cons) 2658 if (sblk->status_tx_quick_consumer_index0 != bp->hw_tx_cons)
2656 bnx2_tx_int(bp); 2659 bnx2_tx_int(bp);
2657 2660
2658 if (sblk->status_rx_quick_consumer_index0 != bp->hw_rx_cons) 2661 if (bnx2_get_hw_rx_cons(bp) != bp->rx_cons)
2659 work_done += bnx2_rx_int(bp, budget - work_done); 2662 work_done += bnx2_rx_int(bp, budget - work_done);
2660 2663
2661 return work_done; 2664 return work_done;
@@ -4177,7 +4180,6 @@ bnx2_init_rx_ring(struct bnx2 *bp)
4177 4180
4178 ring_prod = prod = bp->rx_prod = 0; 4181 ring_prod = prod = bp->rx_prod = 0;
4179 bp->rx_cons = 0; 4182 bp->rx_cons = 0;
4180 bp->hw_rx_cons = 0;
4181 bp->rx_prod_bseq = 0; 4183 bp->rx_prod_bseq = 0;
4182 4184
4183 for (i = 0; i < bp->rx_max_ring; i++) { 4185 for (i = 0; i < bp->rx_max_ring; i++) {
@@ -6685,8 +6687,9 @@ bnx2_init_board(struct pci_dev *pdev, struct net_device *dev)
6685 } else if (CHIP_NUM(bp) == CHIP_NUM_5706 || 6687 } else if (CHIP_NUM(bp) == CHIP_NUM_5706 ||
6686 CHIP_NUM(bp) == CHIP_NUM_5708) 6688 CHIP_NUM(bp) == CHIP_NUM_5708)
6687 bp->phy_flags |= PHY_CRC_FIX_FLAG; 6689 bp->phy_flags |= PHY_CRC_FIX_FLAG;
6688 else if (CHIP_ID(bp) == CHIP_ID_5709_A0 || 6690 else if (CHIP_NUM(bp) == CHIP_NUM_5709 &&
6689 CHIP_ID(bp) == CHIP_ID_5709_A1) 6691 (CHIP_REV(bp) == CHIP_REV_Ax ||
6692 CHIP_REV(bp) == CHIP_REV_Bx))
6690 bp->phy_flags |= PHY_DIS_EARLY_DAC_FLAG; 6693 bp->phy_flags |= PHY_DIS_EARLY_DAC_FLAG;
6691 6694
6692 if ((CHIP_ID(bp) == CHIP_ID_5708_A0) || 6695 if ((CHIP_ID(bp) == CHIP_ID_5708_A0) ||
diff --git a/drivers/net/bnx2.h b/drivers/net/bnx2.h
index 1dce0d1a2581..30ba366608b0 100644
--- a/drivers/net/bnx2.h
+++ b/drivers/net/bnx2.h
@@ -6513,7 +6513,6 @@ struct bnx2 {
6513 u32 rx_prod_bseq; 6513 u32 rx_prod_bseq;
6514 u16 rx_prod; 6514 u16 rx_prod;
6515 u16 rx_cons; 6515 u16 rx_cons;
6516 u16 hw_rx_cons;
6517 6516
6518 u32 rx_csum; 6517 u32 rx_csum;
6519 6518
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index 423298c84a1d..b0b26036266b 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -74,6 +74,7 @@
74#include <linux/ethtool.h> 74#include <linux/ethtool.h>
75#include <linux/if_vlan.h> 75#include <linux/if_vlan.h>
76#include <linux/if_bonding.h> 76#include <linux/if_bonding.h>
77#include <linux/jiffies.h>
77#include <net/route.h> 78#include <net/route.h>
78#include <net/net_namespace.h> 79#include <net/net_namespace.h>
79#include "bonding.h" 80#include "bonding.h"
@@ -174,6 +175,7 @@ struct bond_parm_tbl bond_mode_tbl[] = {
174struct bond_parm_tbl xmit_hashtype_tbl[] = { 175struct bond_parm_tbl xmit_hashtype_tbl[] = {
175{ "layer2", BOND_XMIT_POLICY_LAYER2}, 176{ "layer2", BOND_XMIT_POLICY_LAYER2},
176{ "layer3+4", BOND_XMIT_POLICY_LAYER34}, 177{ "layer3+4", BOND_XMIT_POLICY_LAYER34},
178{ "layer2+3", BOND_XMIT_POLICY_LAYER23},
177{ NULL, -1}, 179{ NULL, -1},
178}; 180};
179 181
@@ -2722,8 +2724,8 @@ void bond_loadbalance_arp_mon(struct work_struct *work)
2722 */ 2724 */
2723 bond_for_each_slave(bond, slave, i) { 2725 bond_for_each_slave(bond, slave, i) {
2724 if (slave->link != BOND_LINK_UP) { 2726 if (slave->link != BOND_LINK_UP) {
2725 if (((jiffies - slave->dev->trans_start) <= delta_in_ticks) && 2727 if (time_before_eq(jiffies, slave->dev->trans_start + delta_in_ticks) &&
2726 ((jiffies - slave->dev->last_rx) <= delta_in_ticks)) { 2728 time_before_eq(jiffies, slave->dev->last_rx + delta_in_ticks)) {
2727 2729
2728 slave->link = BOND_LINK_UP; 2730 slave->link = BOND_LINK_UP;
2729 slave->state = BOND_STATE_ACTIVE; 2731 slave->state = BOND_STATE_ACTIVE;
@@ -2754,8 +2756,8 @@ void bond_loadbalance_arp_mon(struct work_struct *work)
2754 * when the source ip is 0, so don't take the link down 2756 * when the source ip is 0, so don't take the link down
2755 * if we don't know our ip yet 2757 * if we don't know our ip yet
2756 */ 2758 */
2757 if (((jiffies - slave->dev->trans_start) >= (2*delta_in_ticks)) || 2759 if (time_after_eq(jiffies, slave->dev->trans_start + 2*delta_in_ticks) ||
2758 (((jiffies - slave->dev->last_rx) >= (2*delta_in_ticks)) && 2760 (time_after_eq(jiffies, slave->dev->last_rx + 2*delta_in_ticks) &&
2759 bond_has_ip(bond))) { 2761 bond_has_ip(bond))) {
2760 2762
2761 slave->link = BOND_LINK_DOWN; 2763 slave->link = BOND_LINK_DOWN;
@@ -2848,8 +2850,8 @@ void bond_activebackup_arp_mon(struct work_struct *work)
2848 */ 2850 */
2849 bond_for_each_slave(bond, slave, i) { 2851 bond_for_each_slave(bond, slave, i) {
2850 if (slave->link != BOND_LINK_UP) { 2852 if (slave->link != BOND_LINK_UP) {
2851 if ((jiffies - slave_last_rx(bond, slave)) <= 2853 if (time_before_eq(jiffies,
2852 delta_in_ticks) { 2854 slave_last_rx(bond, slave) + delta_in_ticks)) {
2853 2855
2854 slave->link = BOND_LINK_UP; 2856 slave->link = BOND_LINK_UP;
2855 2857
@@ -2858,7 +2860,7 @@ void bond_activebackup_arp_mon(struct work_struct *work)
2858 write_lock_bh(&bond->curr_slave_lock); 2860 write_lock_bh(&bond->curr_slave_lock);
2859 2861
2860 if ((!bond->curr_active_slave) && 2862 if ((!bond->curr_active_slave) &&
2861 ((jiffies - slave->dev->trans_start) <= delta_in_ticks)) { 2863 time_before_eq(jiffies, slave->dev->trans_start + delta_in_ticks)) {
2862 bond_change_active_slave(bond, slave); 2864 bond_change_active_slave(bond, slave);
2863 bond->current_arp_slave = NULL; 2865 bond->current_arp_slave = NULL;
2864 } else if (bond->curr_active_slave != slave) { 2866 } else if (bond->curr_active_slave != slave) {
@@ -2897,7 +2899,7 @@ void bond_activebackup_arp_mon(struct work_struct *work)
2897 2899
2898 if ((slave != bond->curr_active_slave) && 2900 if ((slave != bond->curr_active_slave) &&
2899 (!bond->current_arp_slave) && 2901 (!bond->current_arp_slave) &&
2900 (((jiffies - slave_last_rx(bond, slave)) >= 3*delta_in_ticks) && 2902 (time_after_eq(jiffies, slave_last_rx(bond, slave) + 3*delta_in_ticks) &&
2901 bond_has_ip(bond))) { 2903 bond_has_ip(bond))) {
2902 /* a backup slave has gone down; three times 2904 /* a backup slave has gone down; three times
2903 * the delta allows the current slave to be 2905 * the delta allows the current slave to be
@@ -2943,10 +2945,10 @@ void bond_activebackup_arp_mon(struct work_struct *work)
2943 * before being taken out. if a primary is being used, check 2945 * before being taken out. if a primary is being used, check
2944 * if it is up and needs to take over as the curr_active_slave 2946 * if it is up and needs to take over as the curr_active_slave
2945 */ 2947 */
2946 if ((((jiffies - slave->dev->trans_start) >= (2*delta_in_ticks)) || 2948 if ((time_after_eq(jiffies, slave->dev->trans_start + 2*delta_in_ticks) ||
2947 (((jiffies - slave_last_rx(bond, slave)) >= (2*delta_in_ticks)) && 2949 (time_after_eq(jiffies, slave_last_rx(bond, slave) + 2*delta_in_ticks) &&
2948 bond_has_ip(bond))) && 2950 bond_has_ip(bond))) &&
2949 ((jiffies - slave->jiffies) >= 2*delta_in_ticks)) { 2951 time_after_eq(jiffies, slave->jiffies + 2*delta_in_ticks)) {
2950 2952
2951 slave->link = BOND_LINK_DOWN; 2953 slave->link = BOND_LINK_DOWN;
2952 2954
@@ -3604,6 +3606,24 @@ void bond_unregister_arp(struct bonding *bond)
3604/*---------------------------- Hashing Policies -----------------------------*/ 3606/*---------------------------- Hashing Policies -----------------------------*/
3605 3607
3606/* 3608/*
3609 * Hash for the output device based upon layer 2 and layer 3 data. If
3610 * the packet is not IP mimic bond_xmit_hash_policy_l2()
3611 */
3612static int bond_xmit_hash_policy_l23(struct sk_buff *skb,
3613 struct net_device *bond_dev, int count)
3614{
3615 struct ethhdr *data = (struct ethhdr *)skb->data;
3616 struct iphdr *iph = ip_hdr(skb);
3617
3618 if (skb->protocol == __constant_htons(ETH_P_IP)) {
3619 return ((ntohl(iph->saddr ^ iph->daddr) & 0xffff) ^
3620 (data->h_dest[5] ^ bond_dev->dev_addr[5])) % count;
3621 }
3622
3623 return (data->h_dest[5] ^ bond_dev->dev_addr[5]) % count;
3624}
3625
3626/*
3607 * Hash for the output device based upon layer 3 and layer 4 data. If 3627 * Hash for the output device based upon layer 3 and layer 4 data. If
3608 * the packet is a frag or not TCP or UDP, just use layer 3 data. If it is 3628 * the packet is a frag or not TCP or UDP, just use layer 3 data. If it is
3609 * altogether not IP, mimic bond_xmit_hash_policy_l2() 3629 * altogether not IP, mimic bond_xmit_hash_policy_l2()
@@ -4305,6 +4325,22 @@ out:
4305 4325
4306/*------------------------- Device initialization ---------------------------*/ 4326/*------------------------- Device initialization ---------------------------*/
4307 4327
4328static void bond_set_xmit_hash_policy(struct bonding *bond)
4329{
4330 switch (bond->params.xmit_policy) {
4331 case BOND_XMIT_POLICY_LAYER23:
4332 bond->xmit_hash_policy = bond_xmit_hash_policy_l23;
4333 break;
4334 case BOND_XMIT_POLICY_LAYER34:
4335 bond->xmit_hash_policy = bond_xmit_hash_policy_l34;
4336 break;
4337 case BOND_XMIT_POLICY_LAYER2:
4338 default:
4339 bond->xmit_hash_policy = bond_xmit_hash_policy_l2;
4340 break;
4341 }
4342}
4343
4308/* 4344/*
4309 * set bond mode specific net device operations 4345 * set bond mode specific net device operations
4310 */ 4346 */
@@ -4321,10 +4357,7 @@ void bond_set_mode_ops(struct bonding *bond, int mode)
4321 break; 4357 break;
4322 case BOND_MODE_XOR: 4358 case BOND_MODE_XOR:
4323 bond_dev->hard_start_xmit = bond_xmit_xor; 4359 bond_dev->hard_start_xmit = bond_xmit_xor;
4324 if (bond->params.xmit_policy == BOND_XMIT_POLICY_LAYER34) 4360 bond_set_xmit_hash_policy(bond);
4325 bond->xmit_hash_policy = bond_xmit_hash_policy_l34;
4326 else
4327 bond->xmit_hash_policy = bond_xmit_hash_policy_l2;
4328 break; 4361 break;
4329 case BOND_MODE_BROADCAST: 4362 case BOND_MODE_BROADCAST:
4330 bond_dev->hard_start_xmit = bond_xmit_broadcast; 4363 bond_dev->hard_start_xmit = bond_xmit_broadcast;
@@ -4332,10 +4365,7 @@ void bond_set_mode_ops(struct bonding *bond, int mode)
4332 case BOND_MODE_8023AD: 4365 case BOND_MODE_8023AD:
4333 bond_set_master_3ad_flags(bond); 4366 bond_set_master_3ad_flags(bond);
4334 bond_dev->hard_start_xmit = bond_3ad_xmit_xor; 4367 bond_dev->hard_start_xmit = bond_3ad_xmit_xor;
4335 if (bond->params.xmit_policy == BOND_XMIT_POLICY_LAYER34) 4368 bond_set_xmit_hash_policy(bond);
4336 bond->xmit_hash_policy = bond_xmit_hash_policy_l34;
4337 else
4338 bond->xmit_hash_policy = bond_xmit_hash_policy_l2;
4339 break; 4369 break;
4340 case BOND_MODE_ALB: 4370 case BOND_MODE_ALB:
4341 bond_set_master_alb_flags(bond); 4371 bond_set_master_alb_flags(bond);
@@ -4462,6 +4492,27 @@ static void bond_deinit(struct net_device *bond_dev)
4462#endif 4492#endif
4463} 4493}
4464 4494
4495static void bond_work_cancel_all(struct bonding *bond)
4496{
4497 write_lock_bh(&bond->lock);
4498 bond->kill_timers = 1;
4499 write_unlock_bh(&bond->lock);
4500
4501 if (bond->params.miimon && delayed_work_pending(&bond->mii_work))
4502 cancel_delayed_work(&bond->mii_work);
4503
4504 if (bond->params.arp_interval && delayed_work_pending(&bond->arp_work))
4505 cancel_delayed_work(&bond->arp_work);
4506
4507 if (bond->params.mode == BOND_MODE_ALB &&
4508 delayed_work_pending(&bond->alb_work))
4509 cancel_delayed_work(&bond->alb_work);
4510
4511 if (bond->params.mode == BOND_MODE_8023AD &&
4512 delayed_work_pending(&bond->ad_work))
4513 cancel_delayed_work(&bond->ad_work);
4514}
4515
4465/* Unregister and free all bond devices. 4516/* Unregister and free all bond devices.
4466 * Caller must hold rtnl_lock. 4517 * Caller must hold rtnl_lock.
4467 */ 4518 */
@@ -4472,6 +4523,7 @@ static void bond_free_all(void)
4472 list_for_each_entry_safe(bond, nxt, &bond_dev_list, bond_list) { 4523 list_for_each_entry_safe(bond, nxt, &bond_dev_list, bond_list) {
4473 struct net_device *bond_dev = bond->dev; 4524 struct net_device *bond_dev = bond->dev;
4474 4525
4526 bond_work_cancel_all(bond);
4475 bond_mc_list_destroy(bond); 4527 bond_mc_list_destroy(bond);
4476 /* Release the bonded slaves */ 4528 /* Release the bonded slaves */
4477 bond_release_all(bond_dev); 4529 bond_release_all(bond_dev);
@@ -4497,8 +4549,7 @@ int bond_parse_parm(char *mode_arg, struct bond_parm_tbl *tbl)
4497 for (i = 0; tbl[i].modename; i++) { 4549 for (i = 0; tbl[i].modename; i++) {
4498 if ((isdigit(*mode_arg) && 4550 if ((isdigit(*mode_arg) &&
4499 tbl[i].mode == simple_strtol(mode_arg, NULL, 0)) || 4551 tbl[i].mode == simple_strtol(mode_arg, NULL, 0)) ||
4500 (strncmp(mode_arg, tbl[i].modename, 4552 (strcmp(mode_arg, tbl[i].modename) == 0)) {
4501 strlen(tbl[i].modename)) == 0)) {
4502 return tbl[i].mode; 4553 return tbl[i].mode;
4503 } 4554 }
4504 } 4555 }
@@ -4873,27 +4924,6 @@ out_rtnl:
4873 return res; 4924 return res;
4874} 4925}
4875 4926
4876static void bond_work_cancel_all(struct bonding *bond)
4877{
4878 write_lock_bh(&bond->lock);
4879 bond->kill_timers = 1;
4880 write_unlock_bh(&bond->lock);
4881
4882 if (bond->params.miimon && delayed_work_pending(&bond->mii_work))
4883 cancel_delayed_work(&bond->mii_work);
4884
4885 if (bond->params.arp_interval && delayed_work_pending(&bond->arp_work))
4886 cancel_delayed_work(&bond->arp_work);
4887
4888 if (bond->params.mode == BOND_MODE_ALB &&
4889 delayed_work_pending(&bond->alb_work))
4890 cancel_delayed_work(&bond->alb_work);
4891
4892 if (bond->params.mode == BOND_MODE_8023AD &&
4893 delayed_work_pending(&bond->ad_work))
4894 cancel_delayed_work(&bond->ad_work);
4895}
4896
4897static int __init bonding_init(void) 4927static int __init bonding_init(void)
4898{ 4928{
4899 int i; 4929 int i;
diff --git a/drivers/net/bonding/bond_sysfs.c b/drivers/net/bonding/bond_sysfs.c
index b29330d8e309..11b76b352415 100644
--- a/drivers/net/bonding/bond_sysfs.c
+++ b/drivers/net/bonding/bond_sysfs.c
@@ -74,7 +74,7 @@ struct rw_semaphore bonding_rwsem;
74 * "show" function for the bond_masters attribute. 74 * "show" function for the bond_masters attribute.
75 * The class parameter is ignored. 75 * The class parameter is ignored.
76 */ 76 */
77static ssize_t bonding_show_bonds(struct class *cls, char *buffer) 77static ssize_t bonding_show_bonds(struct class *cls, char *buf)
78{ 78{
79 int res = 0; 79 int res = 0;
80 struct bonding *bond; 80 struct bonding *bond;
@@ -86,14 +86,13 @@ static ssize_t bonding_show_bonds(struct class *cls, char *buffer)
86 /* not enough space for another interface name */ 86 /* not enough space for another interface name */
87 if ((PAGE_SIZE - res) > 10) 87 if ((PAGE_SIZE - res) > 10)
88 res = PAGE_SIZE - 10; 88 res = PAGE_SIZE - 10;
89 res += sprintf(buffer + res, "++more++"); 89 res += sprintf(buf + res, "++more++ ");
90 break; 90 break;
91 } 91 }
92 res += sprintf(buffer + res, "%s ", 92 res += sprintf(buf + res, "%s ", bond->dev->name);
93 bond->dev->name);
94 } 93 }
95 res += sprintf(buffer + res, "\n"); 94 if (res)
96 res++; 95 buf[res-1] = '\n'; /* eat the leftover space */
97 up_read(&(bonding_rwsem)); 96 up_read(&(bonding_rwsem));
98 return res; 97 return res;
99} 98}
@@ -235,14 +234,14 @@ static ssize_t bonding_show_slaves(struct device *d,
235 /* not enough space for another interface name */ 234 /* not enough space for another interface name */
236 if ((PAGE_SIZE - res) > 10) 235 if ((PAGE_SIZE - res) > 10)
237 res = PAGE_SIZE - 10; 236 res = PAGE_SIZE - 10;
238 res += sprintf(buf + res, "++more++"); 237 res += sprintf(buf + res, "++more++ ");
239 break; 238 break;
240 } 239 }
241 res += sprintf(buf + res, "%s ", slave->dev->name); 240 res += sprintf(buf + res, "%s ", slave->dev->name);
242 } 241 }
243 read_unlock(&bond->lock); 242 read_unlock(&bond->lock);
244 res += sprintf(buf + res, "\n"); 243 if (res)
245 res++; 244 buf[res-1] = '\n'; /* eat the leftover space */
246 return res; 245 return res;
247} 246}
248 247
@@ -406,7 +405,7 @@ static ssize_t bonding_show_mode(struct device *d,
406 405
407 return sprintf(buf, "%s %d\n", 406 return sprintf(buf, "%s %d\n",
408 bond_mode_tbl[bond->params.mode].modename, 407 bond_mode_tbl[bond->params.mode].modename,
409 bond->params.mode) + 1; 408 bond->params.mode);
410} 409}
411 410
412static ssize_t bonding_store_mode(struct device *d, 411static ssize_t bonding_store_mode(struct device *d,
@@ -457,20 +456,11 @@ static ssize_t bonding_show_xmit_hash(struct device *d,
457 struct device_attribute *attr, 456 struct device_attribute *attr,
458 char *buf) 457 char *buf)
459{ 458{
460 int count;
461 struct bonding *bond = to_bond(d); 459 struct bonding *bond = to_bond(d);
462 460
463 if ((bond->params.mode != BOND_MODE_XOR) && 461 return sprintf(buf, "%s %d\n",
464 (bond->params.mode != BOND_MODE_8023AD)) { 462 xmit_hashtype_tbl[bond->params.xmit_policy].modename,
465 // Not Applicable 463 bond->params.xmit_policy);
466 count = sprintf(buf, "NA\n") + 1;
467 } else {
468 count = sprintf(buf, "%s %d\n",
469 xmit_hashtype_tbl[bond->params.xmit_policy].modename,
470 bond->params.xmit_policy) + 1;
471 }
472
473 return count;
474} 464}
475 465
476static ssize_t bonding_store_xmit_hash(struct device *d, 466static ssize_t bonding_store_xmit_hash(struct device *d,
@@ -488,15 +478,6 @@ static ssize_t bonding_store_xmit_hash(struct device *d,
488 goto out; 478 goto out;
489 } 479 }
490 480
491 if ((bond->params.mode != BOND_MODE_XOR) &&
492 (bond->params.mode != BOND_MODE_8023AD)) {
493 printk(KERN_ERR DRV_NAME
494 "%s: Transmit hash policy is irrelevant in this mode.\n",
495 bond->dev->name);
496 ret = -EPERM;
497 goto out;
498 }
499
500 new_value = bond_parse_parm((char *)buf, xmit_hashtype_tbl); 481 new_value = bond_parse_parm((char *)buf, xmit_hashtype_tbl);
501 if (new_value < 0) { 482 if (new_value < 0) {
502 printk(KERN_ERR DRV_NAME 483 printk(KERN_ERR DRV_NAME
@@ -527,7 +508,7 @@ static ssize_t bonding_show_arp_validate(struct device *d,
527 508
528 return sprintf(buf, "%s %d\n", 509 return sprintf(buf, "%s %d\n",
529 arp_validate_tbl[bond->params.arp_validate].modename, 510 arp_validate_tbl[bond->params.arp_validate].modename,
530 bond->params.arp_validate) + 1; 511 bond->params.arp_validate);
531} 512}
532 513
533static ssize_t bonding_store_arp_validate(struct device *d, 514static ssize_t bonding_store_arp_validate(struct device *d,
@@ -627,7 +608,7 @@ static ssize_t bonding_show_arp_interval(struct device *d,
627{ 608{
628 struct bonding *bond = to_bond(d); 609 struct bonding *bond = to_bond(d);
629 610
630 return sprintf(buf, "%d\n", bond->params.arp_interval) + 1; 611 return sprintf(buf, "%d\n", bond->params.arp_interval);
631} 612}
632 613
633static ssize_t bonding_store_arp_interval(struct device *d, 614static ssize_t bonding_store_arp_interval(struct device *d,
@@ -712,9 +693,7 @@ static ssize_t bonding_show_arp_targets(struct device *d,
712 NIPQUAD(bond->params.arp_targets[i])); 693 NIPQUAD(bond->params.arp_targets[i]));
713 } 694 }
714 if (res) 695 if (res)
715 res--; /* eat the leftover space */ 696 buf[res-1] = '\n'; /* eat the leftover space */
716 res += sprintf(buf + res, "\n");
717 res++;
718 return res; 697 return res;
719} 698}
720 699
@@ -815,7 +794,7 @@ static ssize_t bonding_show_downdelay(struct device *d,
815{ 794{
816 struct bonding *bond = to_bond(d); 795 struct bonding *bond = to_bond(d);
817 796
818 return sprintf(buf, "%d\n", bond->params.downdelay * bond->params.miimon) + 1; 797 return sprintf(buf, "%d\n", bond->params.downdelay * bond->params.miimon);
819} 798}
820 799
821static ssize_t bonding_store_downdelay(struct device *d, 800static ssize_t bonding_store_downdelay(struct device *d,
@@ -872,7 +851,7 @@ static ssize_t bonding_show_updelay(struct device *d,
872{ 851{
873 struct bonding *bond = to_bond(d); 852 struct bonding *bond = to_bond(d);
874 853
875 return sprintf(buf, "%d\n", bond->params.updelay * bond->params.miimon) + 1; 854 return sprintf(buf, "%d\n", bond->params.updelay * bond->params.miimon);
876 855
877} 856}
878 857
@@ -936,7 +915,7 @@ static ssize_t bonding_show_lacp(struct device *d,
936 915
937 return sprintf(buf, "%s %d\n", 916 return sprintf(buf, "%s %d\n",
938 bond_lacp_tbl[bond->params.lacp_fast].modename, 917 bond_lacp_tbl[bond->params.lacp_fast].modename,
939 bond->params.lacp_fast) + 1; 918 bond->params.lacp_fast);
940} 919}
941 920
942static ssize_t bonding_store_lacp(struct device *d, 921static ssize_t bonding_store_lacp(struct device *d,
@@ -992,7 +971,7 @@ static ssize_t bonding_show_miimon(struct device *d,
992{ 971{
993 struct bonding *bond = to_bond(d); 972 struct bonding *bond = to_bond(d);
994 973
995 return sprintf(buf, "%d\n", bond->params.miimon) + 1; 974 return sprintf(buf, "%d\n", bond->params.miimon);
996} 975}
997 976
998static ssize_t bonding_store_miimon(struct device *d, 977static ssize_t bonding_store_miimon(struct device *d,
@@ -1083,9 +1062,7 @@ static ssize_t bonding_show_primary(struct device *d,
1083 struct bonding *bond = to_bond(d); 1062 struct bonding *bond = to_bond(d);
1084 1063
1085 if (bond->primary_slave) 1064 if (bond->primary_slave)
1086 count = sprintf(buf, "%s\n", bond->primary_slave->dev->name) + 1; 1065 count = sprintf(buf, "%s\n", bond->primary_slave->dev->name);
1087 else
1088 count = sprintf(buf, "\n") + 1;
1089 1066
1090 return count; 1067 return count;
1091} 1068}
@@ -1149,7 +1126,7 @@ static ssize_t bonding_show_carrier(struct device *d,
1149{ 1126{
1150 struct bonding *bond = to_bond(d); 1127 struct bonding *bond = to_bond(d);
1151 1128
1152 return sprintf(buf, "%d\n", bond->params.use_carrier) + 1; 1129 return sprintf(buf, "%d\n", bond->params.use_carrier);
1153} 1130}
1154 1131
1155static ssize_t bonding_store_carrier(struct device *d, 1132static ssize_t bonding_store_carrier(struct device *d,
@@ -1191,16 +1168,14 @@ static ssize_t bonding_show_active_slave(struct device *d,
1191{ 1168{
1192 struct slave *curr; 1169 struct slave *curr;
1193 struct bonding *bond = to_bond(d); 1170 struct bonding *bond = to_bond(d);
1194 int count; 1171 int count = 0;
1195 1172
1196 read_lock(&bond->curr_slave_lock); 1173 read_lock(&bond->curr_slave_lock);
1197 curr = bond->curr_active_slave; 1174 curr = bond->curr_active_slave;
1198 read_unlock(&bond->curr_slave_lock); 1175 read_unlock(&bond->curr_slave_lock);
1199 1176
1200 if (USES_PRIMARY(bond->params.mode) && curr) 1177 if (USES_PRIMARY(bond->params.mode) && curr)
1201 count = sprintf(buf, "%s\n", curr->dev->name) + 1; 1178 count = sprintf(buf, "%s\n", curr->dev->name);
1202 else
1203 count = sprintf(buf, "\n") + 1;
1204 return count; 1179 return count;
1205} 1180}
1206 1181
@@ -1295,7 +1270,7 @@ static ssize_t bonding_show_mii_status(struct device *d,
1295 curr = bond->curr_active_slave; 1270 curr = bond->curr_active_slave;
1296 read_unlock(&bond->curr_slave_lock); 1271 read_unlock(&bond->curr_slave_lock);
1297 1272
1298 return sprintf(buf, "%s\n", (curr) ? "up" : "down") + 1; 1273 return sprintf(buf, "%s\n", (curr) ? "up" : "down");
1299} 1274}
1300static DEVICE_ATTR(mii_status, S_IRUGO, bonding_show_mii_status, NULL); 1275static DEVICE_ATTR(mii_status, S_IRUGO, bonding_show_mii_status, NULL);
1301 1276
@@ -1312,10 +1287,8 @@ static ssize_t bonding_show_ad_aggregator(struct device *d,
1312 1287
1313 if (bond->params.mode == BOND_MODE_8023AD) { 1288 if (bond->params.mode == BOND_MODE_8023AD) {
1314 struct ad_info ad_info; 1289 struct ad_info ad_info;
1315 count = sprintf(buf, "%d\n", (bond_3ad_get_active_agg_info(bond, &ad_info)) ? 0 : ad_info.aggregator_id) + 1; 1290 count = sprintf(buf, "%d\n", (bond_3ad_get_active_agg_info(bond, &ad_info)) ? 0 : ad_info.aggregator_id);
1316 } 1291 }
1317 else
1318 count = sprintf(buf, "\n") + 1;
1319 1292
1320 return count; 1293 return count;
1321} 1294}
@@ -1334,10 +1307,8 @@ static ssize_t bonding_show_ad_num_ports(struct device *d,
1334 1307
1335 if (bond->params.mode == BOND_MODE_8023AD) { 1308 if (bond->params.mode == BOND_MODE_8023AD) {
1336 struct ad_info ad_info; 1309 struct ad_info ad_info;
1337 count = sprintf(buf, "%d\n", (bond_3ad_get_active_agg_info(bond, &ad_info)) ? 0: ad_info.ports) + 1; 1310 count = sprintf(buf, "%d\n", (bond_3ad_get_active_agg_info(bond, &ad_info)) ? 0: ad_info.ports);
1338 } 1311 }
1339 else
1340 count = sprintf(buf, "\n") + 1;
1341 1312
1342 return count; 1313 return count;
1343} 1314}
@@ -1356,10 +1327,8 @@ static ssize_t bonding_show_ad_actor_key(struct device *d,
1356 1327
1357 if (bond->params.mode == BOND_MODE_8023AD) { 1328 if (bond->params.mode == BOND_MODE_8023AD) {
1358 struct ad_info ad_info; 1329 struct ad_info ad_info;
1359 count = sprintf(buf, "%d\n", (bond_3ad_get_active_agg_info(bond, &ad_info)) ? 0 : ad_info.actor_key) + 1; 1330 count = sprintf(buf, "%d\n", (bond_3ad_get_active_agg_info(bond, &ad_info)) ? 0 : ad_info.actor_key);
1360 } 1331 }
1361 else
1362 count = sprintf(buf, "\n") + 1;
1363 1332
1364 return count; 1333 return count;
1365} 1334}
@@ -1378,10 +1347,8 @@ static ssize_t bonding_show_ad_partner_key(struct device *d,
1378 1347
1379 if (bond->params.mode == BOND_MODE_8023AD) { 1348 if (bond->params.mode == BOND_MODE_8023AD) {
1380 struct ad_info ad_info; 1349 struct ad_info ad_info;
1381 count = sprintf(buf, "%d\n", (bond_3ad_get_active_agg_info(bond, &ad_info)) ? 0 : ad_info.partner_key) + 1; 1350 count = sprintf(buf, "%d\n", (bond_3ad_get_active_agg_info(bond, &ad_info)) ? 0 : ad_info.partner_key);
1382 } 1351 }
1383 else
1384 count = sprintf(buf, "\n") + 1;
1385 1352
1386 return count; 1353 return count;
1387} 1354}
@@ -1403,12 +1370,9 @@ static ssize_t bonding_show_ad_partner_mac(struct device *d,
1403 struct ad_info ad_info; 1370 struct ad_info ad_info;
1404 if (!bond_3ad_get_active_agg_info(bond, &ad_info)) { 1371 if (!bond_3ad_get_active_agg_info(bond, &ad_info)) {
1405 count = sprintf(buf,"%s\n", 1372 count = sprintf(buf,"%s\n",
1406 print_mac(mac, ad_info.partner_system)) 1373 print_mac(mac, ad_info.partner_system));
1407 + 1;
1408 } 1374 }
1409 } 1375 }
1410 else
1411 count = sprintf(buf, "\n") + 1;
1412 1376
1413 return count; 1377 return count;
1414} 1378}
diff --git a/drivers/net/bonding/bonding.h b/drivers/net/bonding/bonding.h
index 61c1b4536d34..e1e4734e23ce 100644
--- a/drivers/net/bonding/bonding.h
+++ b/drivers/net/bonding/bonding.h
@@ -22,8 +22,8 @@
22#include "bond_3ad.h" 22#include "bond_3ad.h"
23#include "bond_alb.h" 23#include "bond_alb.h"
24 24
25#define DRV_VERSION "3.2.1" 25#define DRV_VERSION "3.2.3"
26#define DRV_RELDATE "October 15, 2007" 26#define DRV_RELDATE "December 6, 2007"
27#define DRV_NAME "bonding" 27#define DRV_NAME "bonding"
28#define DRV_DESCRIPTION "Ethernet Channel Bonding Driver" 28#define DRV_DESCRIPTION "Ethernet Channel Bonding Driver"
29 29
diff --git a/drivers/net/chelsio/cxgb2.c b/drivers/net/chelsio/cxgb2.c
index 2dbf8dc116c6..c5975047c89b 100644
--- a/drivers/net/chelsio/cxgb2.c
+++ b/drivers/net/chelsio/cxgb2.c
@@ -374,7 +374,9 @@ static char stats_strings[][ETH_GSTRING_LEN] = {
374 "TxInternalMACXmitError", 374 "TxInternalMACXmitError",
375 "TxFramesWithExcessiveDeferral", 375 "TxFramesWithExcessiveDeferral",
376 "TxFCSErrors", 376 "TxFCSErrors",
377 377 "TxJumboFramesOk",
378 "TxJumboOctetsOk",
379
378 "RxOctetsOK", 380 "RxOctetsOK",
379 "RxOctetsBad", 381 "RxOctetsBad",
380 "RxUnicastFramesOK", 382 "RxUnicastFramesOK",
@@ -392,16 +394,17 @@ static char stats_strings[][ETH_GSTRING_LEN] = {
392 "RxInRangeLengthErrors", 394 "RxInRangeLengthErrors",
393 "RxOutOfRangeLengthField", 395 "RxOutOfRangeLengthField",
394 "RxFrameTooLongErrors", 396 "RxFrameTooLongErrors",
397 "RxJumboFramesOk",
398 "RxJumboOctetsOk",
395 399
396 /* Port stats */ 400 /* Port stats */
397 "RxPackets",
398 "RxCsumGood", 401 "RxCsumGood",
399 "TxPackets",
400 "TxCsumOffload", 402 "TxCsumOffload",
401 "TxTso", 403 "TxTso",
402 "RxVlan", 404 "RxVlan",
403 "TxVlan", 405 "TxVlan",
404 406 "TxNeedHeadroom",
407
405 /* Interrupt stats */ 408 /* Interrupt stats */
406 "rx drops", 409 "rx drops",
407 "pure_rsps", 410 "pure_rsps",
@@ -463,23 +466,56 @@ static void get_stats(struct net_device *dev, struct ethtool_stats *stats,
463 const struct cmac_statistics *s; 466 const struct cmac_statistics *s;
464 const struct sge_intr_counts *t; 467 const struct sge_intr_counts *t;
465 struct sge_port_stats ss; 468 struct sge_port_stats ss;
466 unsigned int len;
467 469
468 s = mac->ops->statistics_update(mac, MAC_STATS_UPDATE_FULL); 470 s = mac->ops->statistics_update(mac, MAC_STATS_UPDATE_FULL);
469 471 t = t1_sge_get_intr_counts(adapter->sge);
470 len = sizeof(u64)*(&s->TxFCSErrors + 1 - &s->TxOctetsOK);
471 memcpy(data, &s->TxOctetsOK, len);
472 data += len;
473
474 len = sizeof(u64)*(&s->RxFrameTooLongErrors + 1 - &s->RxOctetsOK);
475 memcpy(data, &s->RxOctetsOK, len);
476 data += len;
477
478 t1_sge_get_port_stats(adapter->sge, dev->if_port, &ss); 472 t1_sge_get_port_stats(adapter->sge, dev->if_port, &ss);
479 memcpy(data, &ss, sizeof(ss));
480 data += sizeof(ss);
481 473
482 t = t1_sge_get_intr_counts(adapter->sge); 474 *data++ = s->TxOctetsOK;
475 *data++ = s->TxOctetsBad;
476 *data++ = s->TxUnicastFramesOK;
477 *data++ = s->TxMulticastFramesOK;
478 *data++ = s->TxBroadcastFramesOK;
479 *data++ = s->TxPauseFrames;
480 *data++ = s->TxFramesWithDeferredXmissions;
481 *data++ = s->TxLateCollisions;
482 *data++ = s->TxTotalCollisions;
483 *data++ = s->TxFramesAbortedDueToXSCollisions;
484 *data++ = s->TxUnderrun;
485 *data++ = s->TxLengthErrors;
486 *data++ = s->TxInternalMACXmitError;
487 *data++ = s->TxFramesWithExcessiveDeferral;
488 *data++ = s->TxFCSErrors;
489 *data++ = s->TxJumboFramesOK;
490 *data++ = s->TxJumboOctetsOK;
491
492 *data++ = s->RxOctetsOK;
493 *data++ = s->RxOctetsBad;
494 *data++ = s->RxUnicastFramesOK;
495 *data++ = s->RxMulticastFramesOK;
496 *data++ = s->RxBroadcastFramesOK;
497 *data++ = s->RxPauseFrames;
498 *data++ = s->RxFCSErrors;
499 *data++ = s->RxAlignErrors;
500 *data++ = s->RxSymbolErrors;
501 *data++ = s->RxDataErrors;
502 *data++ = s->RxSequenceErrors;
503 *data++ = s->RxRuntErrors;
504 *data++ = s->RxJabberErrors;
505 *data++ = s->RxInternalMACRcvError;
506 *data++ = s->RxInRangeLengthErrors;
507 *data++ = s->RxOutOfRangeLengthField;
508 *data++ = s->RxFrameTooLongErrors;
509 *data++ = s->RxJumboFramesOK;
510 *data++ = s->RxJumboOctetsOK;
511
512 *data++ = ss.rx_cso_good;
513 *data++ = ss.tx_cso;
514 *data++ = ss.tx_tso;
515 *data++ = ss.vlan_xtract;
516 *data++ = ss.vlan_insert;
517 *data++ = ss.tx_need_hdrroom;
518
483 *data++ = t->rx_drops; 519 *data++ = t->rx_drops;
484 *data++ = t->pure_rsps; 520 *data++ = t->pure_rsps;
485 *data++ = t->unhandled_irqs; 521 *data++ = t->unhandled_irqs;
diff --git a/drivers/net/chelsio/pm3393.c b/drivers/net/chelsio/pm3393.c
index 678778a8d133..2117c4fbb107 100644
--- a/drivers/net/chelsio/pm3393.c
+++ b/drivers/net/chelsio/pm3393.c
@@ -45,7 +45,7 @@
45 45
46#include <linux/crc32.h> 46#include <linux/crc32.h>
47 47
48#define OFFSET(REG_ADDR) (REG_ADDR << 2) 48#define OFFSET(REG_ADDR) ((REG_ADDR) << 2)
49 49
50/* Max frame size PM3393 can handle. Includes Ethernet header and CRC. */ 50/* Max frame size PM3393 can handle. Includes Ethernet header and CRC. */
51#define MAX_FRAME_SIZE 9600 51#define MAX_FRAME_SIZE 9600
@@ -428,69 +428,26 @@ static int pm3393_set_speed_duplex_fc(struct cmac *cmac, int speed, int duplex,
428 return 0; 428 return 0;
429} 429}
430 430
431static void pm3393_rmon_update(struct adapter *adapter, u32 offs, u64 *val, 431#define RMON_UPDATE(mac, name, stat_name) \
432 int over) 432{ \
433{ 433 t1_tpi_read((mac)->adapter, OFFSET(name), &val0); \
434 u32 val0, val1, val2; 434 t1_tpi_read((mac)->adapter, OFFSET((name)+1), &val1); \
435 435 t1_tpi_read((mac)->adapter, OFFSET((name)+2), &val2); \
436 t1_tpi_read(adapter, offs, &val0); 436 (mac)->stats.stat_name = (u64)(val0 & 0xffff) | \
437 t1_tpi_read(adapter, offs + 4, &val1); 437 ((u64)(val1 & 0xffff) << 16) | \
438 t1_tpi_read(adapter, offs + 8, &val2); 438 ((u64)(val2 & 0xff) << 32) | \
439 439 ((mac)->stats.stat_name & \
440 *val &= ~0ull << 40; 440 0xffffff0000000000ULL); \
441 *val |= val0 & 0xffff; 441 if (ro & \
442 *val |= (val1 & 0xffff) << 16; 442 (1ULL << ((name - SUNI1x10GEXP_REG_MSTAT_COUNTER_0_LOW) >> 2))) \
443 *val |= (u64)(val2 & 0xff) << 32; 443 (mac)->stats.stat_name += 1ULL << 40; \
444
445 if (over)
446 *val += 1ull << 40;
447} 444}
448 445
449static const struct cmac_statistics *pm3393_update_statistics(struct cmac *mac, 446static const struct cmac_statistics *pm3393_update_statistics(struct cmac *mac,
450 int flag) 447 int flag)
451{ 448{
452 static struct { 449 u64 ro;
453 unsigned int reg; 450 u32 val0, val1, val2, val3;
454 unsigned int offset;
455 } hw_stats [] = {
456
457#define HW_STAT(name, stat_name) \
458 { name, (&((struct cmac_statistics *)NULL)->stat_name) - (u64 *)NULL }
459
460 /* Rx stats */
461 HW_STAT(RxOctetsReceivedOK, RxOctetsOK),
462 HW_STAT(RxUnicastFramesReceivedOK, RxUnicastFramesOK),
463 HW_STAT(RxMulticastFramesReceivedOK, RxMulticastFramesOK),
464 HW_STAT(RxBroadcastFramesReceivedOK, RxBroadcastFramesOK),
465 HW_STAT(RxPAUSEMACCtrlFramesReceived, RxPauseFrames),
466 HW_STAT(RxFrameCheckSequenceErrors, RxFCSErrors),
467 HW_STAT(RxFramesLostDueToInternalMACErrors,
468 RxInternalMACRcvError),
469 HW_STAT(RxSymbolErrors, RxSymbolErrors),
470 HW_STAT(RxInRangeLengthErrors, RxInRangeLengthErrors),
471 HW_STAT(RxFramesTooLongErrors , RxFrameTooLongErrors),
472 HW_STAT(RxJabbers, RxJabberErrors),
473 HW_STAT(RxFragments, RxRuntErrors),
474 HW_STAT(RxUndersizedFrames, RxRuntErrors),
475 HW_STAT(RxJumboFramesReceivedOK, RxJumboFramesOK),
476 HW_STAT(RxJumboOctetsReceivedOK, RxJumboOctetsOK),
477
478 /* Tx stats */
479 HW_STAT(TxOctetsTransmittedOK, TxOctetsOK),
480 HW_STAT(TxFramesLostDueToInternalMACTransmissionError,
481 TxInternalMACXmitError),
482 HW_STAT(TxTransmitSystemError, TxFCSErrors),
483 HW_STAT(TxUnicastFramesTransmittedOK, TxUnicastFramesOK),
484 HW_STAT(TxMulticastFramesTransmittedOK, TxMulticastFramesOK),
485 HW_STAT(TxBroadcastFramesTransmittedOK, TxBroadcastFramesOK),
486 HW_STAT(TxPAUSEMACCtrlFramesTransmitted, TxPauseFrames),
487 HW_STAT(TxJumboFramesReceivedOK, TxJumboFramesOK),
488 HW_STAT(TxJumboOctetsReceivedOK, TxJumboOctetsOK)
489 }, *p = hw_stats;
490 u64 ro;
491 u32 val0, val1, val2, val3;
492 u64 *stats = (u64 *) &mac->stats;
493 unsigned int i;
494 451
495 /* Snap the counters */ 452 /* Snap the counters */
496 pmwrite(mac, SUNI1x10GEXP_REG_MSTAT_CONTROL, 453 pmwrite(mac, SUNI1x10GEXP_REG_MSTAT_CONTROL,
@@ -504,14 +461,35 @@ static const struct cmac_statistics *pm3393_update_statistics(struct cmac *mac,
504 ro = ((u64)val0 & 0xffff) | (((u64)val1 & 0xffff) << 16) | 461 ro = ((u64)val0 & 0xffff) | (((u64)val1 & 0xffff) << 16) |
505 (((u64)val2 & 0xffff) << 32) | (((u64)val3 & 0xffff) << 48); 462 (((u64)val2 & 0xffff) << 32) | (((u64)val3 & 0xffff) << 48);
506 463
507 for (i = 0; i < ARRAY_SIZE(hw_stats); i++) { 464 /* Rx stats */
508 unsigned reg = p->reg - SUNI1x10GEXP_REG_MSTAT_COUNTER_0_LOW; 465 RMON_UPDATE(mac, RxOctetsReceivedOK, RxOctetsOK);
509 466 RMON_UPDATE(mac, RxUnicastFramesReceivedOK, RxUnicastFramesOK);
510 pm3393_rmon_update((mac)->adapter, OFFSET(p->reg), 467 RMON_UPDATE(mac, RxMulticastFramesReceivedOK, RxMulticastFramesOK);
511 stats + p->offset, ro & (reg >> 2)); 468 RMON_UPDATE(mac, RxBroadcastFramesReceivedOK, RxBroadcastFramesOK);
512 } 469 RMON_UPDATE(mac, RxPAUSEMACCtrlFramesReceived, RxPauseFrames);
513 470 RMON_UPDATE(mac, RxFrameCheckSequenceErrors, RxFCSErrors);
514 471 RMON_UPDATE(mac, RxFramesLostDueToInternalMACErrors,
472 RxInternalMACRcvError);
473 RMON_UPDATE(mac, RxSymbolErrors, RxSymbolErrors);
474 RMON_UPDATE(mac, RxInRangeLengthErrors, RxInRangeLengthErrors);
475 RMON_UPDATE(mac, RxFramesTooLongErrors , RxFrameTooLongErrors);
476 RMON_UPDATE(mac, RxJabbers, RxJabberErrors);
477 RMON_UPDATE(mac, RxFragments, RxRuntErrors);
478 RMON_UPDATE(mac, RxUndersizedFrames, RxRuntErrors);
479 RMON_UPDATE(mac, RxJumboFramesReceivedOK, RxJumboFramesOK);
480 RMON_UPDATE(mac, RxJumboOctetsReceivedOK, RxJumboOctetsOK);
481
482 /* Tx stats */
483 RMON_UPDATE(mac, TxOctetsTransmittedOK, TxOctetsOK);
484 RMON_UPDATE(mac, TxFramesLostDueToInternalMACTransmissionError,
485 TxInternalMACXmitError);
486 RMON_UPDATE(mac, TxTransmitSystemError, TxFCSErrors);
487 RMON_UPDATE(mac, TxUnicastFramesTransmittedOK, TxUnicastFramesOK);
488 RMON_UPDATE(mac, TxMulticastFramesTransmittedOK, TxMulticastFramesOK);
489 RMON_UPDATE(mac, TxBroadcastFramesTransmittedOK, TxBroadcastFramesOK);
490 RMON_UPDATE(mac, TxPAUSEMACCtrlFramesTransmitted, TxPauseFrames);
491 RMON_UPDATE(mac, TxJumboFramesReceivedOK, TxJumboFramesOK);
492 RMON_UPDATE(mac, TxJumboOctetsReceivedOK, TxJumboOctetsOK);
515 493
516 return &mac->stats; 494 return &mac->stats;
517} 495}
diff --git a/drivers/net/chelsio/sge.c b/drivers/net/chelsio/sge.c
index 443666292a5c..b301c0428ae0 100644
--- a/drivers/net/chelsio/sge.c
+++ b/drivers/net/chelsio/sge.c
@@ -986,11 +986,10 @@ void t1_sge_get_port_stats(const struct sge *sge, int port,
986 for_each_possible_cpu(cpu) { 986 for_each_possible_cpu(cpu) {
987 struct sge_port_stats *st = per_cpu_ptr(sge->port_stats[port], cpu); 987 struct sge_port_stats *st = per_cpu_ptr(sge->port_stats[port], cpu);
988 988
989 ss->rx_packets += st->rx_packets;
990 ss->rx_cso_good += st->rx_cso_good; 989 ss->rx_cso_good += st->rx_cso_good;
991 ss->tx_packets += st->tx_packets;
992 ss->tx_cso += st->tx_cso; 990 ss->tx_cso += st->tx_cso;
993 ss->tx_tso += st->tx_tso; 991 ss->tx_tso += st->tx_tso;
992 ss->tx_need_hdrroom += st->tx_need_hdrroom;
994 ss->vlan_xtract += st->vlan_xtract; 993 ss->vlan_xtract += st->vlan_xtract;
995 ss->vlan_insert += st->vlan_insert; 994 ss->vlan_insert += st->vlan_insert;
996 } 995 }
@@ -1380,7 +1379,6 @@ static void sge_rx(struct sge *sge, struct freelQ *fl, unsigned int len)
1380 __skb_pull(skb, sizeof(*p)); 1379 __skb_pull(skb, sizeof(*p));
1381 1380
1382 st = per_cpu_ptr(sge->port_stats[p->iff], smp_processor_id()); 1381 st = per_cpu_ptr(sge->port_stats[p->iff], smp_processor_id());
1383 st->rx_packets++;
1384 1382
1385 skb->protocol = eth_type_trans(skb, adapter->port[p->iff].dev); 1383 skb->protocol = eth_type_trans(skb, adapter->port[p->iff].dev);
1386 skb->dev->last_rx = jiffies; 1384 skb->dev->last_rx = jiffies;
@@ -1624,11 +1622,9 @@ int t1_poll(struct napi_struct *napi, int budget)
1624{ 1622{
1625 struct adapter *adapter = container_of(napi, struct adapter, napi); 1623 struct adapter *adapter = container_of(napi, struct adapter, napi);
1626 struct net_device *dev = adapter->port[0].dev; 1624 struct net_device *dev = adapter->port[0].dev;
1627 int work_done; 1625 int work_done = process_responses(adapter, budget);
1628
1629 work_done = process_responses(adapter, budget);
1630 1626
1631 if (likely(!responses_pending(adapter))) { 1627 if (likely(work_done < budget)) {
1632 netif_rx_complete(dev, napi); 1628 netif_rx_complete(dev, napi);
1633 writel(adapter->sge->respQ.cidx, 1629 writel(adapter->sge->respQ.cidx,
1634 adapter->regs + A_SG_SLEEPING); 1630 adapter->regs + A_SG_SLEEPING);
@@ -1848,7 +1844,8 @@ int t1_start_xmit(struct sk_buff *skb, struct net_device *dev)
1848{ 1844{
1849 struct adapter *adapter = dev->priv; 1845 struct adapter *adapter = dev->priv;
1850 struct sge *sge = adapter->sge; 1846 struct sge *sge = adapter->sge;
1851 struct sge_port_stats *st = per_cpu_ptr(sge->port_stats[dev->if_port], smp_processor_id()); 1847 struct sge_port_stats *st = per_cpu_ptr(sge->port_stats[dev->if_port],
1848 smp_processor_id());
1852 struct cpl_tx_pkt *cpl; 1849 struct cpl_tx_pkt *cpl;
1853 struct sk_buff *orig_skb = skb; 1850 struct sk_buff *orig_skb = skb;
1854 int ret; 1851 int ret;
@@ -1856,6 +1853,18 @@ int t1_start_xmit(struct sk_buff *skb, struct net_device *dev)
1856 if (skb->protocol == htons(ETH_P_CPL5)) 1853 if (skb->protocol == htons(ETH_P_CPL5))
1857 goto send; 1854 goto send;
1858 1855
1856 /*
1857 * We are using a non-standard hard_header_len.
1858 * Allocate more header room in the rare cases it is not big enough.
1859 */
1860 if (unlikely(skb_headroom(skb) < dev->hard_header_len - ETH_HLEN)) {
1861 skb = skb_realloc_headroom(skb, sizeof(struct cpl_tx_pkt_lso));
1862 ++st->tx_need_hdrroom;
1863 dev_kfree_skb_any(orig_skb);
1864 if (!skb)
1865 return NETDEV_TX_OK;
1866 }
1867
1859 if (skb_shinfo(skb)->gso_size) { 1868 if (skb_shinfo(skb)->gso_size) {
1860 int eth_type; 1869 int eth_type;
1861 struct cpl_tx_pkt_lso *hdr; 1870 struct cpl_tx_pkt_lso *hdr;
@@ -1889,24 +1898,6 @@ int t1_start_xmit(struct sk_buff *skb, struct net_device *dev)
1889 return NETDEV_TX_OK; 1898 return NETDEV_TX_OK;
1890 } 1899 }
1891 1900
1892 /*
1893 * We are using a non-standard hard_header_len and some kernel
1894 * components, such as pktgen, do not handle it right.
1895 * Complain when this happens but try to fix things up.
1896 */
1897 if (unlikely(skb_headroom(skb) < dev->hard_header_len - ETH_HLEN)) {
1898 pr_debug("%s: headroom %d header_len %d\n", dev->name,
1899 skb_headroom(skb), dev->hard_header_len);
1900
1901 if (net_ratelimit())
1902 printk(KERN_ERR "%s: inadequate headroom in "
1903 "Tx packet\n", dev->name);
1904 skb = skb_realloc_headroom(skb, sizeof(*cpl));
1905 dev_kfree_skb_any(orig_skb);
1906 if (!skb)
1907 return NETDEV_TX_OK;
1908 }
1909
1910 if (!(adapter->flags & UDP_CSUM_CAPABLE) && 1901 if (!(adapter->flags & UDP_CSUM_CAPABLE) &&
1911 skb->ip_summed == CHECKSUM_PARTIAL && 1902 skb->ip_summed == CHECKSUM_PARTIAL &&
1912 ip_hdr(skb)->protocol == IPPROTO_UDP) { 1903 ip_hdr(skb)->protocol == IPPROTO_UDP) {
@@ -1952,7 +1943,6 @@ int t1_start_xmit(struct sk_buff *skb, struct net_device *dev)
1952 cpl->vlan_valid = 0; 1943 cpl->vlan_valid = 0;
1953 1944
1954send: 1945send:
1955 st->tx_packets++;
1956 dev->trans_start = jiffies; 1946 dev->trans_start = jiffies;
1957 ret = t1_sge_tx(skb, adapter, 0, dev); 1947 ret = t1_sge_tx(skb, adapter, 0, dev);
1958 1948
diff --git a/drivers/net/chelsio/sge.h b/drivers/net/chelsio/sge.h
index 713d9c55f24d..cced9dff91c5 100644
--- a/drivers/net/chelsio/sge.h
+++ b/drivers/net/chelsio/sge.h
@@ -57,13 +57,12 @@ struct sge_intr_counts {
57}; 57};
58 58
59struct sge_port_stats { 59struct sge_port_stats {
60 u64 rx_packets; /* # of Ethernet packets received */
61 u64 rx_cso_good; /* # of successful RX csum offloads */ 60 u64 rx_cso_good; /* # of successful RX csum offloads */
62 u64 tx_packets; /* # of TX packets */
63 u64 tx_cso; /* # of TX checksum offloads */ 61 u64 tx_cso; /* # of TX checksum offloads */
64 u64 tx_tso; /* # of TSO requests */ 62 u64 tx_tso; /* # of TSO requests */
65 u64 vlan_xtract; /* # of VLAN tag extractions */ 63 u64 vlan_xtract; /* # of VLAN tag extractions */
66 u64 vlan_insert; /* # of VLAN tag insertions */ 64 u64 vlan_insert; /* # of VLAN tag insertions */
65 u64 tx_need_hdrroom; /* # of TX skbs in need of more header room */
67}; 66};
68 67
69struct sk_buff; 68struct sk_buff;
diff --git a/drivers/net/cxgb3/regs.h b/drivers/net/cxgb3/regs.h
index 5e1bc0dec5f1..6e12bf4bc6cf 100644
--- a/drivers/net/cxgb3/regs.h
+++ b/drivers/net/cxgb3/regs.h
@@ -1937,6 +1937,10 @@
1937 1937
1938#define A_XGM_RXFIFO_CFG 0x884 1938#define A_XGM_RXFIFO_CFG 0x884
1939 1939
1940#define S_RXFIFO_EMPTY 31
1941#define V_RXFIFO_EMPTY(x) ((x) << S_RXFIFO_EMPTY)
1942#define F_RXFIFO_EMPTY V_RXFIFO_EMPTY(1U)
1943
1940#define S_RXFIFOPAUSEHWM 17 1944#define S_RXFIFOPAUSEHWM 17
1941#define M_RXFIFOPAUSEHWM 0xfff 1945#define M_RXFIFOPAUSEHWM 0xfff
1942 1946
@@ -1961,6 +1965,10 @@
1961 1965
1962#define A_XGM_TXFIFO_CFG 0x888 1966#define A_XGM_TXFIFO_CFG 0x888
1963 1967
1968#define S_UNDERUNFIX 22
1969#define V_UNDERUNFIX(x) ((x) << S_UNDERUNFIX)
1970#define F_UNDERUNFIX V_UNDERUNFIX(1U)
1971
1964#define S_TXIPG 13 1972#define S_TXIPG 13
1965#define M_TXIPG 0xff 1973#define M_TXIPG 0xff
1966#define V_TXIPG(x) ((x) << S_TXIPG) 1974#define V_TXIPG(x) ((x) << S_TXIPG)
@@ -2034,10 +2042,27 @@
2034#define V_XAUIIMP(x) ((x) << S_XAUIIMP) 2042#define V_XAUIIMP(x) ((x) << S_XAUIIMP)
2035 2043
2036#define A_XGM_RX_MAX_PKT_SIZE 0x8a8 2044#define A_XGM_RX_MAX_PKT_SIZE 0x8a8
2037#define A_XGM_RX_MAX_PKT_SIZE_ERR_CNT 0x9a4 2045
2046#define S_RXMAXFRAMERSIZE 17
2047#define M_RXMAXFRAMERSIZE 0x3fff
2048#define V_RXMAXFRAMERSIZE(x) ((x) << S_RXMAXFRAMERSIZE)
2049#define G_RXMAXFRAMERSIZE(x) (((x) >> S_RXMAXFRAMERSIZE) & M_RXMAXFRAMERSIZE)
2050
2051#define S_RXENFRAMER 14
2052#define V_RXENFRAMER(x) ((x) << S_RXENFRAMER)
2053#define F_RXENFRAMER V_RXENFRAMER(1U)
2054
2055#define S_RXMAXPKTSIZE 0
2056#define M_RXMAXPKTSIZE 0x3fff
2057#define V_RXMAXPKTSIZE(x) ((x) << S_RXMAXPKTSIZE)
2058#define G_RXMAXPKTSIZE(x) (((x) >> S_RXMAXPKTSIZE) & M_RXMAXPKTSIZE)
2038 2059
2039#define A_XGM_RESET_CTRL 0x8ac 2060#define A_XGM_RESET_CTRL 0x8ac
2040 2061
2062#define S_XGMAC_STOP_EN 4
2063#define V_XGMAC_STOP_EN(x) ((x) << S_XGMAC_STOP_EN)
2064#define F_XGMAC_STOP_EN V_XGMAC_STOP_EN(1U)
2065
2041#define S_XG2G_RESET_ 3 2066#define S_XG2G_RESET_ 3
2042#define V_XG2G_RESET_(x) ((x) << S_XG2G_RESET_) 2067#define V_XG2G_RESET_(x) ((x) << S_XG2G_RESET_)
2043#define F_XG2G_RESET_ V_XG2G_RESET_(1U) 2068#define F_XG2G_RESET_ V_XG2G_RESET_(1U)
diff --git a/drivers/net/cxgb3/t3_hw.c b/drivers/net/cxgb3/t3_hw.c
index d4ee00d32219..522834c42ae7 100644
--- a/drivers/net/cxgb3/t3_hw.c
+++ b/drivers/net/cxgb3/t3_hw.c
@@ -447,8 +447,8 @@ static const struct adapter_info t3_adap_info[] = {
447 &mi1_mdio_ops, "Chelsio T302"}, 447 &mi1_mdio_ops, "Chelsio T302"},
448 {1, 0, 0, 0, 448 {1, 0, 0, 0,
449 F_GPIO1_OEN | F_GPIO6_OEN | F_GPIO7_OEN | F_GPIO10_OEN | 449 F_GPIO1_OEN | F_GPIO6_OEN | F_GPIO7_OEN | F_GPIO10_OEN |
450 F_GPIO1_OUT_VAL | F_GPIO6_OUT_VAL | F_GPIO10_OUT_VAL, 0, 450 F_GPIO11_OEN | F_GPIO1_OUT_VAL | F_GPIO6_OUT_VAL | F_GPIO10_OUT_VAL,
451 SUPPORTED_10000baseT_Full | SUPPORTED_AUI, 451 0, SUPPORTED_10000baseT_Full | SUPPORTED_AUI,
452 &mi1_mdio_ext_ops, "Chelsio T310"}, 452 &mi1_mdio_ext_ops, "Chelsio T310"},
453 {2, 0, 0, 0, 453 {2, 0, 0, 0,
454 F_GPIO1_OEN | F_GPIO2_OEN | F_GPIO4_OEN | F_GPIO5_OEN | F_GPIO6_OEN | 454 F_GPIO1_OEN | F_GPIO2_OEN | F_GPIO4_OEN | F_GPIO5_OEN | F_GPIO6_OEN |
@@ -2613,7 +2613,7 @@ static void __devinit init_mtus(unsigned short mtus[])
2613 * it can accomodate max size TCP/IP headers when SACK and timestamps 2613 * it can accomodate max size TCP/IP headers when SACK and timestamps
2614 * are enabled and still have at least 8 bytes of payload. 2614 * are enabled and still have at least 8 bytes of payload.
2615 */ 2615 */
2616 mtus[1] = 88; 2616 mtus[0] = 88;
2617 mtus[1] = 88; 2617 mtus[1] = 88;
2618 mtus[2] = 256; 2618 mtus[2] = 256;
2619 mtus[3] = 512; 2619 mtus[3] = 512;
diff --git a/drivers/net/cxgb3/xgmac.c b/drivers/net/cxgb3/xgmac.c
index eeb766aeced9..efcf09a709cf 100644
--- a/drivers/net/cxgb3/xgmac.c
+++ b/drivers/net/cxgb3/xgmac.c
@@ -106,6 +106,7 @@ int t3_mac_reset(struct cmac *mac)
106 t3_set_reg_field(adap, A_XGM_RXFIFO_CFG + oft, 106 t3_set_reg_field(adap, A_XGM_RXFIFO_CFG + oft,
107 F_RXSTRFRWRD | F_DISERRFRAMES, 107 F_RXSTRFRWRD | F_DISERRFRAMES,
108 uses_xaui(adap) ? 0 : F_RXSTRFRWRD); 108 uses_xaui(adap) ? 0 : F_RXSTRFRWRD);
109 t3_set_reg_field(adap, A_XGM_TXFIFO_CFG + oft, 0, F_UNDERUNFIX);
109 110
110 if (uses_xaui(adap)) { 111 if (uses_xaui(adap)) {
111 if (adap->params.rev == 0) { 112 if (adap->params.rev == 0) {
@@ -124,7 +125,11 @@ int t3_mac_reset(struct cmac *mac)
124 xaui_serdes_reset(mac); 125 xaui_serdes_reset(mac);
125 } 126 }
126 127
127 val = F_MAC_RESET_; 128 t3_set_reg_field(adap, A_XGM_RX_MAX_PKT_SIZE + oft,
129 V_RXMAXFRAMERSIZE(M_RXMAXFRAMERSIZE),
130 V_RXMAXFRAMERSIZE(MAX_FRAME_SIZE) | F_RXENFRAMER);
131 val = F_MAC_RESET_ | F_XGMAC_STOP_EN;
132
128 if (is_10G(adap)) 133 if (is_10G(adap))
129 val |= F_PCS_RESET_; 134 val |= F_PCS_RESET_;
130 else if (uses_xaui(adap)) 135 else if (uses_xaui(adap))
@@ -313,8 +318,9 @@ static int rx_fifo_hwm(int mtu)
313 318
314int t3_mac_set_mtu(struct cmac *mac, unsigned int mtu) 319int t3_mac_set_mtu(struct cmac *mac, unsigned int mtu)
315{ 320{
316 int hwm, lwm; 321 int hwm, lwm, divisor;
317 unsigned int thres, v; 322 int ipg;
323 unsigned int thres, v, reg;
318 struct adapter *adap = mac->adapter; 324 struct adapter *adap = mac->adapter;
319 325
320 /* 326 /*
@@ -335,27 +341,32 @@ int t3_mac_set_mtu(struct cmac *mac, unsigned int mtu)
335 hwm = min(hwm, MAC_RXFIFO_SIZE - 8192); 341 hwm = min(hwm, MAC_RXFIFO_SIZE - 8192);
336 lwm = min(3 * (int)mtu, MAC_RXFIFO_SIZE / 4); 342 lwm = min(3 * (int)mtu, MAC_RXFIFO_SIZE / 4);
337 343
338 if (adap->params.rev == T3_REV_B2 && 344 if (adap->params.rev >= T3_REV_B2 &&
339 (t3_read_reg(adap, A_XGM_RX_CTRL + mac->offset) & F_RXEN)) { 345 (t3_read_reg(adap, A_XGM_RX_CTRL + mac->offset) & F_RXEN)) {
340 disable_exact_filters(mac); 346 disable_exact_filters(mac);
341 v = t3_read_reg(adap, A_XGM_RX_CFG + mac->offset); 347 v = t3_read_reg(adap, A_XGM_RX_CFG + mac->offset);
342 t3_set_reg_field(adap, A_XGM_RX_CFG + mac->offset, 348 t3_set_reg_field(adap, A_XGM_RX_CFG + mac->offset,
343 F_ENHASHMCAST | F_COPYALLFRAMES, F_DISBCAST); 349 F_ENHASHMCAST | F_COPYALLFRAMES, F_DISBCAST);
344 350
345 /* drain rx FIFO */ 351 reg = adap->params.rev == T3_REV_B2 ?
346 if (t3_wait_op_done(adap, 352 A_XGM_RX_MAX_PKT_SIZE_ERR_CNT : A_XGM_RXFIFO_CFG;
347 A_XGM_RX_MAX_PKT_SIZE_ERR_CNT + 353
348 mac->offset, 354 /* drain RX FIFO */
349 1 << 31, 1, 20, 5)) { 355 if (t3_wait_op_done(adap, reg + mac->offset,
356 F_RXFIFO_EMPTY, 1, 20, 5)) {
350 t3_write_reg(adap, A_XGM_RX_CFG + mac->offset, v); 357 t3_write_reg(adap, A_XGM_RX_CFG + mac->offset, v);
351 enable_exact_filters(mac); 358 enable_exact_filters(mac);
352 return -EIO; 359 return -EIO;
353 } 360 }
354 t3_write_reg(adap, A_XGM_RX_MAX_PKT_SIZE + mac->offset, mtu); 361 t3_set_reg_field(adap, A_XGM_RX_MAX_PKT_SIZE + mac->offset,
362 V_RXMAXPKTSIZE(M_RXMAXPKTSIZE),
363 V_RXMAXPKTSIZE(mtu));
355 t3_write_reg(adap, A_XGM_RX_CFG + mac->offset, v); 364 t3_write_reg(adap, A_XGM_RX_CFG + mac->offset, v);
356 enable_exact_filters(mac); 365 enable_exact_filters(mac);
357 } else 366 } else
358 t3_write_reg(adap, A_XGM_RX_MAX_PKT_SIZE + mac->offset, mtu); 367 t3_set_reg_field(adap, A_XGM_RX_MAX_PKT_SIZE + mac->offset,
368 V_RXMAXPKTSIZE(M_RXMAXPKTSIZE),
369 V_RXMAXPKTSIZE(mtu));
359 370
360 /* 371 /*
361 * Adjust the PAUSE frame watermarks. We always set the LWM, and the 372 * Adjust the PAUSE frame watermarks. We always set the LWM, and the
@@ -379,13 +390,16 @@ int t3_mac_set_mtu(struct cmac *mac, unsigned int mtu)
379 thres /= 10; 390 thres /= 10;
380 thres = mtu > thres ? (mtu - thres + 7) / 8 : 0; 391 thres = mtu > thres ? (mtu - thres + 7) / 8 : 0;
381 thres = max(thres, 8U); /* need at least 8 */ 392 thres = max(thres, 8U); /* need at least 8 */
393 ipg = (adap->params.rev == T3_REV_C) ? 0 : 1;
382 t3_set_reg_field(adap, A_XGM_TXFIFO_CFG + mac->offset, 394 t3_set_reg_field(adap, A_XGM_TXFIFO_CFG + mac->offset,
383 V_TXFIFOTHRESH(M_TXFIFOTHRESH) | V_TXIPG(M_TXIPG), 395 V_TXFIFOTHRESH(M_TXFIFOTHRESH) | V_TXIPG(M_TXIPG),
384 V_TXFIFOTHRESH(thres) | V_TXIPG(1)); 396 V_TXFIFOTHRESH(thres) | V_TXIPG(ipg));
385 397
386 if (adap->params.rev > 0) 398 if (adap->params.rev > 0) {
399 divisor = (adap->params.rev == T3_REV_C) ? 64 : 8;
387 t3_write_reg(adap, A_XGM_PAUSE_TIMER + mac->offset, 400 t3_write_reg(adap, A_XGM_PAUSE_TIMER + mac->offset,
388 (hwm - lwm) * 4 / 8); 401 (hwm - lwm) * 4 / divisor);
402 }
389 t3_write_reg(adap, A_XGM_TX_PAUSE_QUANTA + mac->offset, 403 t3_write_reg(adap, A_XGM_TX_PAUSE_QUANTA + mac->offset,
390 MAC_RXFIFO_SIZE * 4 * 8 / 512); 404 MAC_RXFIFO_SIZE * 4 * 8 / 512);
391 return 0; 405 return 0;
@@ -522,7 +536,7 @@ int t3b2_mac_watchdog_task(struct cmac *mac)
522 goto rxcheck; 536 goto rxcheck;
523 } 537 }
524 538
525 if ((tx_tcnt != mac->tx_tcnt) && (mac->tx_xcnt == 0)) { 539 if ((tx_tcnt != mac->tx_tcnt) && (mac->tx_xcnt == 0)) {
526 if (mac->toggle_cnt > 4) { 540 if (mac->toggle_cnt > 4) {
527 status = 2; 541 status = 2;
528 goto out; 542 goto out;
diff --git a/drivers/net/dl2k.c b/drivers/net/dl2k.c
index 5066beb2e7bc..47cce9cad30f 100644
--- a/drivers/net/dl2k.c
+++ b/drivers/net/dl2k.c
@@ -332,7 +332,7 @@ parse_eeprom (struct net_device *dev)
332#endif 332#endif
333 /* Read eeprom */ 333 /* Read eeprom */
334 for (i = 0; i < 128; i++) { 334 for (i = 0; i < 128; i++) {
335 ((u16 *) sromdata)[i] = le16_to_cpu (read_eeprom (ioaddr, i)); 335 ((__le16 *) sromdata)[i] = cpu_to_le16(read_eeprom (ioaddr, i));
336 } 336 }
337#ifdef MEM_MAPPING 337#ifdef MEM_MAPPING
338 ioaddr = dev->base_addr; 338 ioaddr = dev->base_addr;
@@ -516,7 +516,7 @@ rio_timer (unsigned long data)
516 PCI_DMA_FROMDEVICE)); 516 PCI_DMA_FROMDEVICE));
517 } 517 }
518 np->rx_ring[entry].fraginfo |= 518 np->rx_ring[entry].fraginfo |=
519 cpu_to_le64 (np->rx_buf_sz) << 48; 519 cpu_to_le64((u64)np->rx_buf_sz << 48);
520 np->rx_ring[entry].status = 0; 520 np->rx_ring[entry].status = 0;
521 } /* end for */ 521 } /* end for */
522 } /* end if */ 522 } /* end if */
@@ -584,11 +584,11 @@ alloc_list (struct net_device *dev)
584 cpu_to_le64 ( pci_map_single ( 584 cpu_to_le64 ( pci_map_single (
585 np->pdev, skb->data, np->rx_buf_sz, 585 np->pdev, skb->data, np->rx_buf_sz,
586 PCI_DMA_FROMDEVICE)); 586 PCI_DMA_FROMDEVICE));
587 np->rx_ring[i].fraginfo |= cpu_to_le64 (np->rx_buf_sz) << 48; 587 np->rx_ring[i].fraginfo |= cpu_to_le64((u64)np->rx_buf_sz << 48);
588 } 588 }
589 589
590 /* Set RFDListPtr */ 590 /* Set RFDListPtr */
591 writel (cpu_to_le32 (np->rx_ring_dma), dev->base_addr + RFDListPtr0); 591 writel (np->rx_ring_dma, dev->base_addr + RFDListPtr0);
592 writel (0, dev->base_addr + RFDListPtr1); 592 writel (0, dev->base_addr + RFDListPtr1);
593 593
594 return; 594 return;
@@ -620,15 +620,14 @@ start_xmit (struct sk_buff *skb, struct net_device *dev)
620 } 620 }
621#endif 621#endif
622 if (np->vlan) { 622 if (np->vlan) {
623 tfc_vlan_tag = 623 tfc_vlan_tag = VLANTagInsert |
624 cpu_to_le64 (VLANTagInsert) | 624 ((u64)np->vlan << 32) |
625 (cpu_to_le64 (np->vlan) << 32) | 625 ((u64)skb->priority << 45);
626 (cpu_to_le64 (skb->priority) << 45);
627 } 626 }
628 txdesc->fraginfo = cpu_to_le64 (pci_map_single (np->pdev, skb->data, 627 txdesc->fraginfo = cpu_to_le64 (pci_map_single (np->pdev, skb->data,
629 skb->len, 628 skb->len,
630 PCI_DMA_TODEVICE)); 629 PCI_DMA_TODEVICE));
631 txdesc->fraginfo |= cpu_to_le64 (skb->len) << 48; 630 txdesc->fraginfo |= cpu_to_le64((u64)skb->len << 48);
632 631
633 /* DL2K bug: DMA fails to get next descriptor ptr in 10Mbps mode 632 /* DL2K bug: DMA fails to get next descriptor ptr in 10Mbps mode
634 * Work around: Always use 1 descriptor in 10Mbps mode */ 633 * Work around: Always use 1 descriptor in 10Mbps mode */
@@ -708,6 +707,11 @@ rio_interrupt (int irq, void *dev_instance)
708 return IRQ_RETVAL(handled); 707 return IRQ_RETVAL(handled);
709} 708}
710 709
710static inline dma_addr_t desc_to_dma(struct netdev_desc *desc)
711{
712 return le64_to_cpu(desc->fraginfo) & DMA_48BIT_MASK;
713}
714
711static void 715static void
712rio_free_tx (struct net_device *dev, int irq) 716rio_free_tx (struct net_device *dev, int irq)
713{ 717{
@@ -725,11 +729,11 @@ rio_free_tx (struct net_device *dev, int irq)
725 while (entry != np->cur_tx) { 729 while (entry != np->cur_tx) {
726 struct sk_buff *skb; 730 struct sk_buff *skb;
727 731
728 if (!(np->tx_ring[entry].status & TFDDone)) 732 if (!(np->tx_ring[entry].status & cpu_to_le64(TFDDone)))
729 break; 733 break;
730 skb = np->tx_skbuff[entry]; 734 skb = np->tx_skbuff[entry];
731 pci_unmap_single (np->pdev, 735 pci_unmap_single (np->pdev,
732 np->tx_ring[entry].fraginfo & DMA_48BIT_MASK, 736 desc_to_dma(&np->tx_ring[entry]),
733 skb->len, PCI_DMA_TODEVICE); 737 skb->len, PCI_DMA_TODEVICE);
734 if (irq) 738 if (irq)
735 dev_kfree_skb_irq (skb); 739 dev_kfree_skb_irq (skb);
@@ -831,13 +835,14 @@ receive_packet (struct net_device *dev)
831 int pkt_len; 835 int pkt_len;
832 u64 frame_status; 836 u64 frame_status;
833 837
834 if (!(desc->status & RFDDone) || 838 if (!(desc->status & cpu_to_le64(RFDDone)) ||
835 !(desc->status & FrameStart) || !(desc->status & FrameEnd)) 839 !(desc->status & cpu_to_le64(FrameStart)) ||
840 !(desc->status & cpu_to_le64(FrameEnd)))
836 break; 841 break;
837 842
838 /* Chip omits the CRC. */ 843 /* Chip omits the CRC. */
839 pkt_len = le64_to_cpu (desc->status & 0xffff); 844 frame_status = le64_to_cpu(desc->status);
840 frame_status = le64_to_cpu (desc->status); 845 pkt_len = frame_status & 0xffff;
841 if (--cnt < 0) 846 if (--cnt < 0)
842 break; 847 break;
843 /* Update rx error statistics, drop packet. */ 848 /* Update rx error statistics, drop packet. */
@@ -857,15 +862,14 @@ receive_packet (struct net_device *dev)
857 /* Small skbuffs for short packets */ 862 /* Small skbuffs for short packets */
858 if (pkt_len > copy_thresh) { 863 if (pkt_len > copy_thresh) {
859 pci_unmap_single (np->pdev, 864 pci_unmap_single (np->pdev,
860 desc->fraginfo & DMA_48BIT_MASK, 865 desc_to_dma(desc),
861 np->rx_buf_sz, 866 np->rx_buf_sz,
862 PCI_DMA_FROMDEVICE); 867 PCI_DMA_FROMDEVICE);
863 skb_put (skb = np->rx_skbuff[entry], pkt_len); 868 skb_put (skb = np->rx_skbuff[entry], pkt_len);
864 np->rx_skbuff[entry] = NULL; 869 np->rx_skbuff[entry] = NULL;
865 } else if ((skb = dev_alloc_skb (pkt_len + 2)) != NULL) { 870 } else if ((skb = dev_alloc_skb (pkt_len + 2)) != NULL) {
866 pci_dma_sync_single_for_cpu(np->pdev, 871 pci_dma_sync_single_for_cpu(np->pdev,
867 desc->fraginfo & 872 desc_to_dma(desc),
868 DMA_48BIT_MASK,
869 np->rx_buf_sz, 873 np->rx_buf_sz,
870 PCI_DMA_FROMDEVICE); 874 PCI_DMA_FROMDEVICE);
871 /* 16 byte align the IP header */ 875 /* 16 byte align the IP header */
@@ -875,8 +879,7 @@ receive_packet (struct net_device *dev)
875 pkt_len); 879 pkt_len);
876 skb_put (skb, pkt_len); 880 skb_put (skb, pkt_len);
877 pci_dma_sync_single_for_device(np->pdev, 881 pci_dma_sync_single_for_device(np->pdev,
878 desc->fraginfo & 882 desc_to_dma(desc),
879 DMA_48BIT_MASK,
880 np->rx_buf_sz, 883 np->rx_buf_sz,
881 PCI_DMA_FROMDEVICE); 884 PCI_DMA_FROMDEVICE);
882 } 885 }
@@ -919,7 +922,7 @@ receive_packet (struct net_device *dev)
919 PCI_DMA_FROMDEVICE)); 922 PCI_DMA_FROMDEVICE));
920 } 923 }
921 np->rx_ring[entry].fraginfo |= 924 np->rx_ring[entry].fraginfo |=
922 cpu_to_le64 (np->rx_buf_sz) << 48; 925 cpu_to_le64((u64)np->rx_buf_sz << 48);
923 np->rx_ring[entry].status = 0; 926 np->rx_ring[entry].status = 0;
924 entry = (entry + 1) % RX_RING_SIZE; 927 entry = (entry + 1) % RX_RING_SIZE;
925 } 928 }
@@ -1121,7 +1124,7 @@ set_multicast (struct net_device *dev)
1121 1124
1122 hash_table[0] = hash_table[1] = 0; 1125 hash_table[0] = hash_table[1] = 0;
1123 /* RxFlowcontrol DA: 01-80-C2-00-00-01. Hash index=0x39 */ 1126 /* RxFlowcontrol DA: 01-80-C2-00-00-01. Hash index=0x39 */
1124 hash_table[1] |= cpu_to_le32(0x02000000); 1127 hash_table[1] |= 0x02000000;
1125 if (dev->flags & IFF_PROMISC) { 1128 if (dev->flags & IFF_PROMISC) {
1126 /* Receive all frames promiscuously. */ 1129 /* Receive all frames promiscuously. */
1127 rx_mode = ReceiveAllFrames; 1130 rx_mode = ReceiveAllFrames;
@@ -1762,7 +1765,7 @@ rio_close (struct net_device *dev)
1762 skb = np->rx_skbuff[i]; 1765 skb = np->rx_skbuff[i];
1763 if (skb) { 1766 if (skb) {
1764 pci_unmap_single(np->pdev, 1767 pci_unmap_single(np->pdev,
1765 np->rx_ring[i].fraginfo & DMA_48BIT_MASK, 1768 desc_to_dma(&np->rx_ring[i]),
1766 skb->len, PCI_DMA_FROMDEVICE); 1769 skb->len, PCI_DMA_FROMDEVICE);
1767 dev_kfree_skb (skb); 1770 dev_kfree_skb (skb);
1768 np->rx_skbuff[i] = NULL; 1771 np->rx_skbuff[i] = NULL;
@@ -1772,7 +1775,7 @@ rio_close (struct net_device *dev)
1772 skb = np->tx_skbuff[i]; 1775 skb = np->tx_skbuff[i];
1773 if (skb) { 1776 if (skb) {
1774 pci_unmap_single(np->pdev, 1777 pci_unmap_single(np->pdev,
1775 np->tx_ring[i].fraginfo & DMA_48BIT_MASK, 1778 desc_to_dma(&np->tx_ring[i]),
1776 skb->len, PCI_DMA_TODEVICE); 1779 skb->len, PCI_DMA_TODEVICE);
1777 dev_kfree_skb (skb); 1780 dev_kfree_skb (skb);
1778 np->tx_skbuff[i] = NULL; 1781 np->tx_skbuff[i] = NULL;
diff --git a/drivers/net/dl2k.h b/drivers/net/dl2k.h
index 5b801775f42d..014b77ce96df 100644
--- a/drivers/net/dl2k.h
+++ b/drivers/net/dl2k.h
@@ -633,9 +633,9 @@ struct mii_data {
633 633
634/* The Rx and Tx buffer descriptors. */ 634/* The Rx and Tx buffer descriptors. */
635struct netdev_desc { 635struct netdev_desc {
636 u64 next_desc; 636 __le64 next_desc;
637 u64 status; 637 __le64 status;
638 u64 fraginfo; 638 __le64 fraginfo;
639}; 639};
640 640
641#define PRIV_ALIGN 15 /* Required alignment mask */ 641#define PRIV_ALIGN 15 /* Required alignment mask */
diff --git a/drivers/net/e100.c b/drivers/net/e100.c
index 3dbaec680b46..2b06e4b4dabc 100644
--- a/drivers/net/e100.c
+++ b/drivers/net/e100.c
@@ -2214,13 +2214,11 @@ static void e100_get_drvinfo(struct net_device *netdev,
2214 strcpy(info->bus_info, pci_name(nic->pdev)); 2214 strcpy(info->bus_info, pci_name(nic->pdev));
2215} 2215}
2216 2216
2217#define E100_PHY_REGS 0x1C
2217static int e100_get_regs_len(struct net_device *netdev) 2218static int e100_get_regs_len(struct net_device *netdev)
2218{ 2219{
2219 struct nic *nic = netdev_priv(netdev); 2220 struct nic *nic = netdev_priv(netdev);
2220#define E100_PHY_REGS 0x1C 2221 return 1 + E100_PHY_REGS + sizeof(nic->mem->dump_buf);
2221#define E100_REGS_LEN 1 + E100_PHY_REGS + \
2222 sizeof(nic->mem->dump_buf) / sizeof(u32)
2223 return E100_REGS_LEN * sizeof(u32);
2224} 2222}
2225 2223
2226static void e100_get_regs(struct net_device *netdev, 2224static void e100_get_regs(struct net_device *netdev,
@@ -2739,8 +2737,9 @@ static int e100_suspend(struct pci_dev *pdev, pm_message_t state)
2739 pci_enable_wake(pdev, PCI_D3cold, 0); 2737 pci_enable_wake(pdev, PCI_D3cold, 0);
2740 } 2738 }
2741 2739
2742 pci_disable_device(pdev);
2743 free_irq(pdev->irq, netdev); 2740 free_irq(pdev->irq, netdev);
2741
2742 pci_disable_device(pdev);
2744 pci_set_power_state(pdev, PCI_D3hot); 2743 pci_set_power_state(pdev, PCI_D3hot);
2745 2744
2746 return 0; 2745 return 0;
@@ -2782,6 +2781,8 @@ static void e100_shutdown(struct pci_dev *pdev)
2782 pci_enable_wake(pdev, PCI_D3cold, 0); 2781 pci_enable_wake(pdev, PCI_D3cold, 0);
2783 } 2782 }
2784 2783
2784 free_irq(pdev->irq, netdev);
2785
2785 pci_disable_device(pdev); 2786 pci_disable_device(pdev);
2786 pci_set_power_state(pdev, PCI_D3hot); 2787 pci_set_power_state(pdev, PCI_D3hot);
2787} 2788}
diff --git a/drivers/net/e1000/e1000_ethtool.c b/drivers/net/e1000/e1000_ethtool.c
index 667f18bcc172..b83ccce8a9b7 100644
--- a/drivers/net/e1000/e1000_ethtool.c
+++ b/drivers/net/e1000/e1000_ethtool.c
@@ -1923,7 +1923,7 @@ e1000_get_strings(struct net_device *netdev, uint32_t stringset, uint8_t *data)
1923 switch (stringset) { 1923 switch (stringset) {
1924 case ETH_SS_TEST: 1924 case ETH_SS_TEST:
1925 memcpy(data, *e1000_gstrings_test, 1925 memcpy(data, *e1000_gstrings_test,
1926 E1000_TEST_LEN*ETH_GSTRING_LEN); 1926 sizeof(e1000_gstrings_test));
1927 break; 1927 break;
1928 case ETH_SS_STATS: 1928 case ETH_SS_STATS:
1929 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) { 1929 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
diff --git a/drivers/net/e1000/e1000_main.c b/drivers/net/e1000/e1000_main.c
index cf39473ef90a..4f37506ad374 100644
--- a/drivers/net/e1000/e1000_main.c
+++ b/drivers/net/e1000/e1000_main.c
@@ -3942,7 +3942,7 @@ e1000_clean(struct napi_struct *napi, int budget)
3942 &work_done, budget); 3942 &work_done, budget);
3943 3943
3944 /* If no Tx and not enough Rx work done, exit the polling mode */ 3944 /* If no Tx and not enough Rx work done, exit the polling mode */
3945 if ((!tx_cleaned && (work_done < budget)) || 3945 if ((!tx_cleaned && (work_done == 0)) ||
3946 !netif_running(poll_dev)) { 3946 !netif_running(poll_dev)) {
3947quit_polling: 3947quit_polling:
3948 if (likely(adapter->itr_setting & 3)) 3948 if (likely(adapter->itr_setting & 3))
diff --git a/drivers/net/e1000e/ethtool.c b/drivers/net/e1000e/ethtool.c
index 6a39784e7ee2..87f9da1b6b4e 100644
--- a/drivers/net/e1000e/ethtool.c
+++ b/drivers/net/e1000e/ethtool.c
@@ -1739,7 +1739,7 @@ static void e1000_get_strings(struct net_device *netdev, u32 stringset,
1739 switch (stringset) { 1739 switch (stringset) {
1740 case ETH_SS_TEST: 1740 case ETH_SS_TEST:
1741 memcpy(data, *e1000_gstrings_test, 1741 memcpy(data, *e1000_gstrings_test,
1742 E1000_TEST_LEN*ETH_GSTRING_LEN); 1742 sizeof(e1000_gstrings_test));
1743 break; 1743 break;
1744 case ETH_SS_STATS: 1744 case ETH_SS_STATS:
1745 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) { 1745 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
diff --git a/drivers/net/ehea/ehea.h b/drivers/net/ehea/ehea.h
index f78e5bf7cb33..5f82a4647eee 100644
--- a/drivers/net/ehea/ehea.h
+++ b/drivers/net/ehea/ehea.h
@@ -40,7 +40,7 @@
40#include <asm/io.h> 40#include <asm/io.h>
41 41
42#define DRV_NAME "ehea" 42#define DRV_NAME "ehea"
43#define DRV_VERSION "EHEA_0080" 43#define DRV_VERSION "EHEA_0083"
44 44
45/* eHEA capability flags */ 45/* eHEA capability flags */
46#define DLPAR_PORT_ADD_REM 1 46#define DLPAR_PORT_ADD_REM 1
diff --git a/drivers/net/ehea/ehea_main.c b/drivers/net/ehea/ehea_main.c
index f0319f1e8e05..869e1604b16e 100644
--- a/drivers/net/ehea/ehea_main.c
+++ b/drivers/net/ehea/ehea_main.c
@@ -136,7 +136,7 @@ static struct net_device_stats *ehea_get_stats(struct net_device *dev)
136 struct ehea_port *port = netdev_priv(dev); 136 struct ehea_port *port = netdev_priv(dev);
137 struct net_device_stats *stats = &port->stats; 137 struct net_device_stats *stats = &port->stats;
138 struct hcp_ehea_port_cb2 *cb2; 138 struct hcp_ehea_port_cb2 *cb2;
139 u64 hret, rx_packets; 139 u64 hret, rx_packets, tx_packets;
140 int i; 140 int i;
141 141
142 memset(stats, 0, sizeof(*stats)); 142 memset(stats, 0, sizeof(*stats));
@@ -162,7 +162,11 @@ static struct net_device_stats *ehea_get_stats(struct net_device *dev)
162 for (i = 0; i < port->num_def_qps; i++) 162 for (i = 0; i < port->num_def_qps; i++)
163 rx_packets += port->port_res[i].rx_packets; 163 rx_packets += port->port_res[i].rx_packets;
164 164
165 stats->tx_packets = cb2->txucp + cb2->txmcp + cb2->txbcp; 165 tx_packets = 0;
166 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
167 tx_packets += port->port_res[i].tx_packets;
168
169 stats->tx_packets = tx_packets;
166 stats->multicast = cb2->rxmcp; 170 stats->multicast = cb2->rxmcp;
167 stats->rx_errors = cb2->rxuerr; 171 stats->rx_errors = cb2->rxuerr;
168 stats->rx_bytes = cb2->rxo; 172 stats->rx_bytes = cb2->rxo;
@@ -406,11 +410,6 @@ static int ehea_treat_poll_error(struct ehea_port_res *pr, int rq,
406 if (cqe->status & EHEA_CQE_STAT_ERR_CRC) 410 if (cqe->status & EHEA_CQE_STAT_ERR_CRC)
407 pr->p_stats.err_frame_crc++; 411 pr->p_stats.err_frame_crc++;
408 412
409 if (netif_msg_rx_err(pr->port)) {
410 ehea_error("CQE Error for QP %d", pr->qp->init_attr.qp_nr);
411 ehea_dump(cqe, sizeof(*cqe), "CQE");
412 }
413
414 if (rq == 2) { 413 if (rq == 2) {
415 *processed_rq2 += 1; 414 *processed_rq2 += 1;
416 skb = get_skb_by_index(pr->rq2_skba.arr, pr->rq2_skba.len, cqe); 415 skb = get_skb_by_index(pr->rq2_skba.arr, pr->rq2_skba.len, cqe);
@@ -422,7 +421,11 @@ static int ehea_treat_poll_error(struct ehea_port_res *pr, int rq,
422 } 421 }
423 422
424 if (cqe->status & EHEA_CQE_STAT_FAT_ERR_MASK) { 423 if (cqe->status & EHEA_CQE_STAT_FAT_ERR_MASK) {
425 ehea_error("Critical receive error. Resetting port."); 424 if (netif_msg_rx_err(pr->port)) {
425 ehea_error("Critical receive error for QP %d. "
426 "Resetting port.", pr->qp->init_attr.qp_nr);
427 ehea_dump(cqe, sizeof(*cqe), "CQE");
428 }
426 schedule_work(&pr->port->reset_task); 429 schedule_work(&pr->port->reset_task);
427 return 1; 430 return 1;
428 } 431 }
@@ -2000,6 +2003,7 @@ static int ehea_start_xmit(struct sk_buff *skb, struct net_device *dev)
2000 } 2003 }
2001 2004
2002 ehea_post_swqe(pr->qp, swqe); 2005 ehea_post_swqe(pr->qp, swqe);
2006 pr->tx_packets++;
2003 2007
2004 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) { 2008 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) {
2005 spin_lock_irqsave(&pr->netif_queue, flags); 2009 spin_lock_irqsave(&pr->netif_queue, flags);
diff --git a/drivers/net/ehea/ehea_qmr.h b/drivers/net/ehea/ehea_qmr.h
index 562de0ebdd85..bc62d389c166 100644
--- a/drivers/net/ehea/ehea_qmr.h
+++ b/drivers/net/ehea/ehea_qmr.h
@@ -145,8 +145,8 @@ struct ehea_rwqe {
145#define EHEA_CQE_VLAN_TAG_XTRACT 0x0400 145#define EHEA_CQE_VLAN_TAG_XTRACT 0x0400
146 146
147#define EHEA_CQE_TYPE_RQ 0x60 147#define EHEA_CQE_TYPE_RQ 0x60
148#define EHEA_CQE_STAT_ERR_MASK 0x720F 148#define EHEA_CQE_STAT_ERR_MASK 0x700F
149#define EHEA_CQE_STAT_FAT_ERR_MASK 0x1F 149#define EHEA_CQE_STAT_FAT_ERR_MASK 0xF
150#define EHEA_CQE_STAT_ERR_TCP 0x4000 150#define EHEA_CQE_STAT_ERR_TCP 0x4000
151#define EHEA_CQE_STAT_ERR_IP 0x2000 151#define EHEA_CQE_STAT_ERR_IP 0x2000
152#define EHEA_CQE_STAT_ERR_CRC 0x1000 152#define EHEA_CQE_STAT_ERR_CRC 0x1000
diff --git a/drivers/net/fec_mpc52xx.c b/drivers/net/fec_mpc52xx.c
index a8a0ee220da6..f91ee700e605 100644
--- a/drivers/net/fec_mpc52xx.c
+++ b/drivers/net/fec_mpc52xx.c
@@ -422,7 +422,7 @@ static irqreturn_t mpc52xx_fec_rx_interrupt(int irq, void *dev_id)
422 422
423 rskb = bcom_retrieve_buffer(priv->rx_dmatsk, &status, 423 rskb = bcom_retrieve_buffer(priv->rx_dmatsk, &status,
424 (struct bcom_bd **)&bd); 424 (struct bcom_bd **)&bd);
425 dma_unmap_single(&dev->dev, bd->skb_pa, skb->len, DMA_FROM_DEVICE); 425 dma_unmap_single(&dev->dev, bd->skb_pa, rskb->len, DMA_FROM_DEVICE);
426 426
427 /* Test for errors in received frame */ 427 /* Test for errors in received frame */
428 if (status & BCOM_FEC_RX_BD_ERRORS) { 428 if (status & BCOM_FEC_RX_BD_ERRORS) {
@@ -467,7 +467,7 @@ static irqreturn_t mpc52xx_fec_rx_interrupt(int irq, void *dev_id)
467 bcom_prepare_next_buffer(priv->rx_dmatsk); 467 bcom_prepare_next_buffer(priv->rx_dmatsk);
468 468
469 bd->status = FEC_RX_BUFFER_SIZE; 469 bd->status = FEC_RX_BUFFER_SIZE;
470 bd->skb_pa = dma_map_single(&dev->dev, rskb->data, 470 bd->skb_pa = dma_map_single(&dev->dev, skb->data,
471 FEC_RX_BUFFER_SIZE, DMA_FROM_DEVICE); 471 FEC_RX_BUFFER_SIZE, DMA_FROM_DEVICE);
472 472
473 bcom_submit_next_buffer(priv->rx_dmatsk, skb); 473 bcom_submit_next_buffer(priv->rx_dmatsk, skb);
@@ -568,8 +568,9 @@ static void mpc52xx_fec_reset_stats(struct net_device *dev)
568 struct mpc52xx_fec __iomem *fec = priv->fec; 568 struct mpc52xx_fec __iomem *fec = priv->fec;
569 569
570 out_be32(&fec->mib_control, FEC_MIB_DISABLE); 570 out_be32(&fec->mib_control, FEC_MIB_DISABLE);
571 memset_io(&fec->rmon_t_drop, 0, (__force u32)&fec->reserved10 - 571 memset_io(&fec->rmon_t_drop, 0,
572 (__force u32)&fec->rmon_t_drop); 572 offsetof(struct mpc52xx_fec, reserved10) -
573 offsetof(struct mpc52xx_fec, rmon_t_drop));
573 out_be32(&fec->mib_control, 0); 574 out_be32(&fec->mib_control, 0);
574 575
575 memset(&dev->stats, 0, sizeof(dev->stats)); 576 memset(&dev->stats, 0, sizeof(dev->stats));
@@ -971,6 +972,8 @@ mpc52xx_fec_probe(struct of_device *op, const struct of_device_id *match)
971 972
972 mpc52xx_fec_reset_stats(ndev); 973 mpc52xx_fec_reset_stats(ndev);
973 974
975 SET_NETDEV_DEV(ndev, &op->dev);
976
974 /* Register the new network device */ 977 /* Register the new network device */
975 rv = register_netdev(ndev); 978 rv = register_netdev(ndev);
976 if (rv < 0) 979 if (rv < 0)
diff --git a/drivers/net/forcedeth.c b/drivers/net/forcedeth.c
index 92ce2e38f0d5..a96583cceb5e 100644
--- a/drivers/net/forcedeth.c
+++ b/drivers/net/forcedeth.c
@@ -5286,19 +5286,15 @@ static int __devinit nv_probe(struct pci_dev *pci_dev, const struct pci_device_i
5286 if (readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_SYNC_PHY_INIT) { 5286 if (readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_SYNC_PHY_INIT) {
5287 np->mac_in_use = readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_MGMT_ST; 5287 np->mac_in_use = readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_MGMT_ST;
5288 dprintk(KERN_INFO "%s: mgmt unit is running. mac in use %x.\n", pci_name(pci_dev), np->mac_in_use); 5288 dprintk(KERN_INFO "%s: mgmt unit is running. mac in use %x.\n", pci_name(pci_dev), np->mac_in_use);
5289 for (i = 0; i < 5000; i++) { 5289 if (nv_mgmt_acquire_sema(dev)) {
5290 msleep(1); 5290 /* management unit setup the phy already? */
5291 if (nv_mgmt_acquire_sema(dev)) { 5291 if ((readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_SYNC_MASK) ==
5292 /* management unit setup the phy already? */ 5292 NVREG_XMITCTL_SYNC_PHY_INIT) {
5293 if ((readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_SYNC_MASK) == 5293 /* phy is inited by mgmt unit */
5294 NVREG_XMITCTL_SYNC_PHY_INIT) { 5294 phyinitialized = 1;
5295 /* phy is inited by mgmt unit */ 5295 dprintk(KERN_INFO "%s: Phy already initialized by mgmt unit.\n", pci_name(pci_dev));
5296 phyinitialized = 1; 5296 } else {
5297 dprintk(KERN_INFO "%s: Phy already initialized by mgmt unit.\n", pci_name(pci_dev)); 5297 /* we need to init the phy */
5298 } else {
5299 /* we need to init the phy */
5300 }
5301 break;
5302 } 5298 }
5303 } 5299 }
5304 } 5300 }
@@ -5613,6 +5609,22 @@ static struct pci_device_id pci_tbl[] = {
5613 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_35), 5609 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_35),
5614 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT, 5610 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT,
5615 }, 5611 },
5612 { /* MCP79 Ethernet Controller */
5613 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_36),
5614 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT,
5615 },
5616 { /* MCP79 Ethernet Controller */
5617 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_37),
5618 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT,
5619 },
5620 { /* MCP79 Ethernet Controller */
5621 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_38),
5622 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT,
5623 },
5624 { /* MCP79 Ethernet Controller */
5625 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_39),
5626 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT,
5627 },
5616 {0,}, 5628 {0,},
5617}; 5629};
5618 5630
diff --git a/drivers/net/fs_enet/mac-scc.c b/drivers/net/fs_enet/mac-scc.c
index 03134f47a4eb..48f2f3005935 100644
--- a/drivers/net/fs_enet/mac-scc.c
+++ b/drivers/net/fs_enet/mac-scc.c
@@ -158,7 +158,7 @@ static int setup_data(struct net_device *dev)
158{ 158{
159 struct fs_enet_private *fep = netdev_priv(dev); 159 struct fs_enet_private *fep = netdev_priv(dev);
160 160
161#ifdef CONFIG_PPC_CPM_NEW_BINDING 161#ifndef CONFIG_PPC_CPM_NEW_BINDING
162 struct fs_platform_info *fpi = fep->fpi; 162 struct fs_platform_info *fpi = fep->fpi;
163 163
164 fep->scc.idx = fs_get_scc_index(fpi->fs_no); 164 fep->scc.idx = fs_get_scc_index(fpi->fs_no);
diff --git a/drivers/net/gianfar.c b/drivers/net/gianfar.c
index 38268d7335a8..0431e9ed0fac 100644
--- a/drivers/net/gianfar.c
+++ b/drivers/net/gianfar.c
@@ -696,7 +696,7 @@ int startup_gfar(struct net_device *dev)
696{ 696{
697 struct txbd8 *txbdp; 697 struct txbd8 *txbdp;
698 struct rxbd8 *rxbdp; 698 struct rxbd8 *rxbdp;
699 dma_addr_t addr; 699 dma_addr_t addr = 0;
700 unsigned long vaddr; 700 unsigned long vaddr;
701 int i; 701 int i;
702 struct gfar_private *priv = netdev_priv(dev); 702 struct gfar_private *priv = netdev_priv(dev);
diff --git a/drivers/net/hamachi.c b/drivers/net/hamachi.c
index ed407c85708f..b53f6b6491b3 100644
--- a/drivers/net/hamachi.c
+++ b/drivers/net/hamachi.c
@@ -204,8 +204,10 @@ KERN_INFO " Further modifications by Keith Underwood <keithu@parl.clemson.edu>
204/* Condensed bus+endian portability operations. */ 204/* Condensed bus+endian portability operations. */
205#if ADDRLEN == 64 205#if ADDRLEN == 64
206#define cpu_to_leXX(addr) cpu_to_le64(addr) 206#define cpu_to_leXX(addr) cpu_to_le64(addr)
207#define leXX_to_cpu(addr) le64_to_cpu(addr)
207#else 208#else
208#define cpu_to_leXX(addr) cpu_to_le32(addr) 209#define cpu_to_leXX(addr) cpu_to_le32(addr)
210#define leXX_to_cpu(addr) le32_to_cpu(addr)
209#endif 211#endif
210 212
211 213
@@ -465,12 +467,12 @@ enum intr_status_bits {
465 467
466/* The Hamachi Rx and Tx buffer descriptors. */ 468/* The Hamachi Rx and Tx buffer descriptors. */
467struct hamachi_desc { 469struct hamachi_desc {
468 u32 status_n_length; 470 __le32 status_n_length;
469#if ADDRLEN == 64 471#if ADDRLEN == 64
470 u32 pad; 472 u32 pad;
471 u64 addr; 473 __le64 addr;
472#else 474#else
473 u32 addr; 475 __le32 addr;
474#endif 476#endif
475}; 477};
476 478
@@ -874,13 +876,13 @@ static int hamachi_open(struct net_device *dev)
874 876
875#if ADDRLEN == 64 877#if ADDRLEN == 64
876 /* writellll anyone ? */ 878 /* writellll anyone ? */
877 writel(cpu_to_le64(hmp->rx_ring_dma), ioaddr + RxPtr); 879 writel(hmp->rx_ring_dma, ioaddr + RxPtr);
878 writel(cpu_to_le64(hmp->rx_ring_dma) >> 32, ioaddr + RxPtr + 4); 880 writel(hmp->rx_ring_dma >> 32, ioaddr + RxPtr + 4);
879 writel(cpu_to_le64(hmp->tx_ring_dma), ioaddr + TxPtr); 881 writel(hmp->tx_ring_dma, ioaddr + TxPtr);
880 writel(cpu_to_le64(hmp->tx_ring_dma) >> 32, ioaddr + TxPtr + 4); 882 writel(hmp->tx_ring_dma >> 32, ioaddr + TxPtr + 4);
881#else 883#else
882 writel(cpu_to_le32(hmp->rx_ring_dma), ioaddr + RxPtr); 884 writel(hmp->rx_ring_dma, ioaddr + RxPtr);
883 writel(cpu_to_le32(hmp->tx_ring_dma), ioaddr + TxPtr); 885 writel(hmp->tx_ring_dma, ioaddr + TxPtr);
884#endif 886#endif
885 887
886 /* TODO: It would make sense to organize this as words since the card 888 /* TODO: It would make sense to organize this as words since the card
@@ -1019,8 +1021,8 @@ static inline int hamachi_tx(struct net_device *dev)
1019 skb = hmp->tx_skbuff[entry]; 1021 skb = hmp->tx_skbuff[entry];
1020 if (skb) { 1022 if (skb) {
1021 pci_unmap_single(hmp->pci_dev, 1023 pci_unmap_single(hmp->pci_dev,
1022 hmp->tx_ring[entry].addr, skb->len, 1024 leXX_to_cpu(hmp->tx_ring[entry].addr),
1023 PCI_DMA_TODEVICE); 1025 skb->len, PCI_DMA_TODEVICE);
1024 dev_kfree_skb(skb); 1026 dev_kfree_skb(skb);
1025 hmp->tx_skbuff[entry] = NULL; 1027 hmp->tx_skbuff[entry] = NULL;
1026 } 1028 }
@@ -1071,10 +1073,10 @@ static void hamachi_tx_timeout(struct net_device *dev)
1071 { 1073 {
1072 printk(KERN_DEBUG " Rx ring %p: ", hmp->rx_ring); 1074 printk(KERN_DEBUG " Rx ring %p: ", hmp->rx_ring);
1073 for (i = 0; i < RX_RING_SIZE; i++) 1075 for (i = 0; i < RX_RING_SIZE; i++)
1074 printk(" %8.8x", (unsigned int)hmp->rx_ring[i].status_n_length); 1076 printk(" %8.8x", le32_to_cpu(hmp->rx_ring[i].status_n_length));
1075 printk("\n"KERN_DEBUG" Tx ring %p: ", hmp->tx_ring); 1077 printk("\n"KERN_DEBUG" Tx ring %p: ", hmp->tx_ring);
1076 for (i = 0; i < TX_RING_SIZE; i++) 1078 for (i = 0; i < TX_RING_SIZE; i++)
1077 printk(" %4.4x", hmp->tx_ring[i].status_n_length); 1079 printk(" %4.4x", le32_to_cpu(hmp->tx_ring[i].status_n_length));
1078 printk("\n"); 1080 printk("\n");
1079 } 1081 }
1080 1082
@@ -1099,14 +1101,15 @@ static void hamachi_tx_timeout(struct net_device *dev)
1099 struct sk_buff *skb; 1101 struct sk_buff *skb;
1100 1102
1101 if (i >= TX_RING_SIZE - 1) 1103 if (i >= TX_RING_SIZE - 1)
1102 hmp->tx_ring[i].status_n_length = cpu_to_le32( 1104 hmp->tx_ring[i].status_n_length =
1103 DescEndRing | 1105 cpu_to_le32(DescEndRing) |
1104 (hmp->tx_ring[i].status_n_length & 0x0000FFFF)); 1106 (hmp->tx_ring[i].status_n_length &
1107 cpu_to_le32(0x0000ffff));
1105 else 1108 else
1106 hmp->tx_ring[i].status_n_length &= 0x0000ffff; 1109 hmp->tx_ring[i].status_n_length &= cpu_to_le32(0x0000ffff);
1107 skb = hmp->tx_skbuff[i]; 1110 skb = hmp->tx_skbuff[i];
1108 if (skb){ 1111 if (skb){
1109 pci_unmap_single(hmp->pci_dev, hmp->tx_ring[i].addr, 1112 pci_unmap_single(hmp->pci_dev, leXX_to_cpu(hmp->tx_ring[i].addr),
1110 skb->len, PCI_DMA_TODEVICE); 1113 skb->len, PCI_DMA_TODEVICE);
1111 dev_kfree_skb(skb); 1114 dev_kfree_skb(skb);
1112 hmp->tx_skbuff[i] = NULL; 1115 hmp->tx_skbuff[i] = NULL;
@@ -1128,7 +1131,8 @@ static void hamachi_tx_timeout(struct net_device *dev)
1128 struct sk_buff *skb = hmp->rx_skbuff[i]; 1131 struct sk_buff *skb = hmp->rx_skbuff[i];
1129 1132
1130 if (skb){ 1133 if (skb){
1131 pci_unmap_single(hmp->pci_dev, hmp->rx_ring[i].addr, 1134 pci_unmap_single(hmp->pci_dev,
1135 leXX_to_cpu(hmp->rx_ring[i].addr),
1132 hmp->rx_buf_sz, PCI_DMA_FROMDEVICE); 1136 hmp->rx_buf_sz, PCI_DMA_FROMDEVICE);
1133 dev_kfree_skb(skb); 1137 dev_kfree_skb(skb);
1134 hmp->rx_skbuff[i] = NULL; 1138 hmp->rx_skbuff[i] = NULL;
@@ -1420,7 +1424,7 @@ static irqreturn_t hamachi_interrupt(int irq, void *dev_instance)
1420 /* Free the original skb. */ 1424 /* Free the original skb. */
1421 if (skb){ 1425 if (skb){
1422 pci_unmap_single(hmp->pci_dev, 1426 pci_unmap_single(hmp->pci_dev,
1423 hmp->tx_ring[entry].addr, 1427 leXX_to_cpu(hmp->tx_ring[entry].addr),
1424 skb->len, 1428 skb->len,
1425 PCI_DMA_TODEVICE); 1429 PCI_DMA_TODEVICE);
1426 dev_kfree_skb_irq(skb); 1430 dev_kfree_skb_irq(skb);
@@ -1500,11 +1504,11 @@ static int hamachi_rx(struct net_device *dev)
1500 if (desc_status & DescOwn) 1504 if (desc_status & DescOwn)
1501 break; 1505 break;
1502 pci_dma_sync_single_for_cpu(hmp->pci_dev, 1506 pci_dma_sync_single_for_cpu(hmp->pci_dev,
1503 desc->addr, 1507 leXX_to_cpu(desc->addr),
1504 hmp->rx_buf_sz, 1508 hmp->rx_buf_sz,
1505 PCI_DMA_FROMDEVICE); 1509 PCI_DMA_FROMDEVICE);
1506 buf_addr = (u8 *) hmp->rx_skbuff[entry]->data; 1510 buf_addr = (u8 *) hmp->rx_skbuff[entry]->data;
1507 frame_status = le32_to_cpu(get_unaligned((s32*)&(buf_addr[data_size - 12]))); 1511 frame_status = le32_to_cpu(get_unaligned((__le32*)&(buf_addr[data_size - 12])));
1508 if (hamachi_debug > 4) 1512 if (hamachi_debug > 4)
1509 printk(KERN_DEBUG " hamachi_rx() status was %8.8x.\n", 1513 printk(KERN_DEBUG " hamachi_rx() status was %8.8x.\n",
1510 frame_status); 1514 frame_status);
@@ -1518,9 +1522,9 @@ static int hamachi_rx(struct net_device *dev)
1518 dev->name, desc, &hmp->rx_ring[hmp->cur_rx % RX_RING_SIZE]); 1522 dev->name, desc, &hmp->rx_ring[hmp->cur_rx % RX_RING_SIZE]);
1519 printk(KERN_WARNING "%s: Oversized Ethernet frame -- next status %x/%x last status %x.\n", 1523 printk(KERN_WARNING "%s: Oversized Ethernet frame -- next status %x/%x last status %x.\n",
1520 dev->name, 1524 dev->name,
1521 hmp->rx_ring[(hmp->cur_rx+1) % RX_RING_SIZE].status_n_length & 0xffff0000, 1525 le32_to_cpu(hmp->rx_ring[(hmp->cur_rx+1) % RX_RING_SIZE].status_n_length) & 0xffff0000,
1522 hmp->rx_ring[(hmp->cur_rx+1) % RX_RING_SIZE].status_n_length & 0x0000ffff, 1526 le32_to_cpu(hmp->rx_ring[(hmp->cur_rx+1) % RX_RING_SIZE].status_n_length) & 0x0000ffff,
1523 hmp->rx_ring[(hmp->cur_rx-1) % RX_RING_SIZE].status_n_length); 1527 le32_to_cpu(hmp->rx_ring[(hmp->cur_rx-1) % RX_RING_SIZE].status_n_length));
1524 hmp->stats.rx_length_errors++; 1528 hmp->stats.rx_length_errors++;
1525 } /* else Omit for prototype errata??? */ 1529 } /* else Omit for prototype errata??? */
1526 if (frame_status & 0x00380000) { 1530 if (frame_status & 0x00380000) {
@@ -1566,7 +1570,7 @@ static int hamachi_rx(struct net_device *dev)
1566#endif 1570#endif
1567 skb_reserve(skb, 2); /* 16 byte align the IP header */ 1571 skb_reserve(skb, 2); /* 16 byte align the IP header */
1568 pci_dma_sync_single_for_cpu(hmp->pci_dev, 1572 pci_dma_sync_single_for_cpu(hmp->pci_dev,
1569 hmp->rx_ring[entry].addr, 1573 leXX_to_cpu(hmp->rx_ring[entry].addr),
1570 hmp->rx_buf_sz, 1574 hmp->rx_buf_sz,
1571 PCI_DMA_FROMDEVICE); 1575 PCI_DMA_FROMDEVICE);
1572 /* Call copy + cksum if available. */ 1576 /* Call copy + cksum if available. */
@@ -1579,12 +1583,12 @@ static int hamachi_rx(struct net_device *dev)
1579 + entry*sizeof(*desc), pkt_len); 1583 + entry*sizeof(*desc), pkt_len);
1580#endif 1584#endif
1581 pci_dma_sync_single_for_device(hmp->pci_dev, 1585 pci_dma_sync_single_for_device(hmp->pci_dev,
1582 hmp->rx_ring[entry].addr, 1586 leXX_to_cpu(hmp->rx_ring[entry].addr),
1583 hmp->rx_buf_sz, 1587 hmp->rx_buf_sz,
1584 PCI_DMA_FROMDEVICE); 1588 PCI_DMA_FROMDEVICE);
1585 } else { 1589 } else {
1586 pci_unmap_single(hmp->pci_dev, 1590 pci_unmap_single(hmp->pci_dev,
1587 hmp->rx_ring[entry].addr, 1591 leXX_to_cpu(hmp->rx_ring[entry].addr),
1588 hmp->rx_buf_sz, PCI_DMA_FROMDEVICE); 1592 hmp->rx_buf_sz, PCI_DMA_FROMDEVICE);
1589 skb_put(skb = hmp->rx_skbuff[entry], pkt_len); 1593 skb_put(skb = hmp->rx_skbuff[entry], pkt_len);
1590 hmp->rx_skbuff[entry] = NULL; 1594 hmp->rx_skbuff[entry] = NULL;
@@ -1787,21 +1791,21 @@ static int hamachi_close(struct net_device *dev)
1787 for (i = 0; i < RX_RING_SIZE; i++) { 1791 for (i = 0; i < RX_RING_SIZE; i++) {
1788 skb = hmp->rx_skbuff[i]; 1792 skb = hmp->rx_skbuff[i];
1789 hmp->rx_ring[i].status_n_length = 0; 1793 hmp->rx_ring[i].status_n_length = 0;
1790 hmp->rx_ring[i].addr = 0xBADF00D0; /* An invalid address. */
1791 if (skb) { 1794 if (skb) {
1792 pci_unmap_single(hmp->pci_dev, 1795 pci_unmap_single(hmp->pci_dev,
1793 hmp->rx_ring[i].addr, hmp->rx_buf_sz, 1796 leXX_to_cpu(hmp->rx_ring[i].addr),
1794 PCI_DMA_FROMDEVICE); 1797 hmp->rx_buf_sz, PCI_DMA_FROMDEVICE);
1795 dev_kfree_skb(skb); 1798 dev_kfree_skb(skb);
1796 hmp->rx_skbuff[i] = NULL; 1799 hmp->rx_skbuff[i] = NULL;
1797 } 1800 }
1801 hmp->rx_ring[i].addr = cpu_to_leXX(0xBADF00D0); /* An invalid address. */
1798 } 1802 }
1799 for (i = 0; i < TX_RING_SIZE; i++) { 1803 for (i = 0; i < TX_RING_SIZE; i++) {
1800 skb = hmp->tx_skbuff[i]; 1804 skb = hmp->tx_skbuff[i];
1801 if (skb) { 1805 if (skb) {
1802 pci_unmap_single(hmp->pci_dev, 1806 pci_unmap_single(hmp->pci_dev,
1803 hmp->tx_ring[i].addr, skb->len, 1807 leXX_to_cpu(hmp->tx_ring[i].addr),
1804 PCI_DMA_TODEVICE); 1808 skb->len, PCI_DMA_TODEVICE);
1805 dev_kfree_skb(skb); 1809 dev_kfree_skb(skb);
1806 hmp->tx_skbuff[i] = NULL; 1810 hmp->tx_skbuff[i] = NULL;
1807 } 1811 }
diff --git a/drivers/net/ibm_newemac/core.c b/drivers/net/ibm_newemac/core.c
index 0de3aa2a2e44..cb06280dced5 100644
--- a/drivers/net/ibm_newemac/core.c
+++ b/drivers/net/ibm_newemac/core.c
@@ -3,6 +3,11 @@
3 * 3 *
4 * Driver for PowerPC 4xx on-chip ethernet controller. 4 * Driver for PowerPC 4xx on-chip ethernet controller.
5 * 5 *
6 * Copyright 2007 Benjamin Herrenschmidt, IBM Corp.
7 * <benh@kernel.crashing.org>
8 *
9 * Based on the arch/ppc version of the driver:
10 *
6 * Copyright (c) 2004, 2005 Zultys Technologies. 11 * Copyright (c) 2004, 2005 Zultys Technologies.
7 * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net> 12 * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net>
8 * 13 *
@@ -402,7 +407,7 @@ static u32 __emac_calc_base_mr1(struct emac_instance *dev, int tx_size, int rx_s
402static u32 __emac4_calc_base_mr1(struct emac_instance *dev, int tx_size, int rx_size) 407static u32 __emac4_calc_base_mr1(struct emac_instance *dev, int tx_size, int rx_size)
403{ 408{
404 u32 ret = EMAC_MR1_VLE | EMAC_MR1_IST | EMAC4_MR1_TR | 409 u32 ret = EMAC_MR1_VLE | EMAC_MR1_IST | EMAC4_MR1_TR |
405 EMAC4_MR1_OBCI(dev->opb_bus_freq); 410 EMAC4_MR1_OBCI(dev->opb_bus_freq / 1000000);
406 411
407 DBG2(dev, "__emac4_calc_base_mr1" NL); 412 DBG2(dev, "__emac4_calc_base_mr1" NL);
408 413
@@ -464,26 +469,34 @@ static int emac_configure(struct emac_instance *dev)
464{ 469{
465 struct emac_regs __iomem *p = dev->emacp; 470 struct emac_regs __iomem *p = dev->emacp;
466 struct net_device *ndev = dev->ndev; 471 struct net_device *ndev = dev->ndev;
467 int tx_size, rx_size; 472 int tx_size, rx_size, link = netif_carrier_ok(dev->ndev);
468 u32 r, mr1 = 0; 473 u32 r, mr1 = 0;
469 474
470 DBG(dev, "configure" NL); 475 DBG(dev, "configure" NL);
471 476
472 if (emac_reset(dev) < 0) 477 if (!link) {
478 out_be32(&p->mr1, in_be32(&p->mr1)
479 | EMAC_MR1_FDE | EMAC_MR1_ILE);
480 udelay(100);
481 } else if (emac_reset(dev) < 0)
473 return -ETIMEDOUT; 482 return -ETIMEDOUT;
474 483
475 if (emac_has_feature(dev, EMAC_FTR_HAS_TAH)) 484 if (emac_has_feature(dev, EMAC_FTR_HAS_TAH))
476 tah_reset(dev->tah_dev); 485 tah_reset(dev->tah_dev);
477 486
478 DBG(dev, " duplex = %d, pause = %d, asym_pause = %d\n", 487 DBG(dev, " link = %d duplex = %d, pause = %d, asym_pause = %d\n",
479 dev->phy.duplex, dev->phy.pause, dev->phy.asym_pause); 488 link, dev->phy.duplex, dev->phy.pause, dev->phy.asym_pause);
480 489
481 /* Default fifo sizes */ 490 /* Default fifo sizes */
482 tx_size = dev->tx_fifo_size; 491 tx_size = dev->tx_fifo_size;
483 rx_size = dev->rx_fifo_size; 492 rx_size = dev->rx_fifo_size;
484 493
494 /* No link, force loopback */
495 if (!link)
496 mr1 = EMAC_MR1_FDE | EMAC_MR1_ILE;
497
485 /* Check for full duplex */ 498 /* Check for full duplex */
486 if (dev->phy.duplex == DUPLEX_FULL) 499 else if (dev->phy.duplex == DUPLEX_FULL)
487 mr1 |= EMAC_MR1_FDE | EMAC_MR1_MWSW_001; 500 mr1 |= EMAC_MR1_FDE | EMAC_MR1_MWSW_001;
488 501
489 /* Adjust fifo sizes, mr1 and timeouts based on link speed */ 502 /* Adjust fifo sizes, mr1 and timeouts based on link speed */
@@ -642,9 +655,11 @@ static void emac_reset_work(struct work_struct *work)
642 DBG(dev, "reset_work" NL); 655 DBG(dev, "reset_work" NL);
643 656
644 mutex_lock(&dev->link_lock); 657 mutex_lock(&dev->link_lock);
645 emac_netif_stop(dev); 658 if (dev->opened) {
646 emac_full_tx_reset(dev); 659 emac_netif_stop(dev);
647 emac_netif_start(dev); 660 emac_full_tx_reset(dev);
661 emac_netif_start(dev);
662 }
648 mutex_unlock(&dev->link_lock); 663 mutex_unlock(&dev->link_lock);
649} 664}
650 665
@@ -701,7 +716,7 @@ static int __emac_mdio_read(struct emac_instance *dev, u8 id, u8 reg)
701 r = EMAC_STACR_BASE(dev->opb_bus_freq); 716 r = EMAC_STACR_BASE(dev->opb_bus_freq);
702 if (emac_has_feature(dev, EMAC_FTR_STACR_OC_INVERT)) 717 if (emac_has_feature(dev, EMAC_FTR_STACR_OC_INVERT))
703 r |= EMAC_STACR_OC; 718 r |= EMAC_STACR_OC;
704 if (emac_has_feature(dev, EMAC_FTR_HAS_AXON_STACR)) 719 if (emac_has_feature(dev, EMAC_FTR_HAS_NEW_STACR))
705 r |= EMACX_STACR_STAC_READ; 720 r |= EMACX_STACR_STAC_READ;
706 else 721 else
707 r |= EMAC_STACR_STAC_READ; 722 r |= EMAC_STACR_STAC_READ;
@@ -773,7 +788,7 @@ static void __emac_mdio_write(struct emac_instance *dev, u8 id, u8 reg,
773 r = EMAC_STACR_BASE(dev->opb_bus_freq); 788 r = EMAC_STACR_BASE(dev->opb_bus_freq);
774 if (emac_has_feature(dev, EMAC_FTR_STACR_OC_INVERT)) 789 if (emac_has_feature(dev, EMAC_FTR_STACR_OC_INVERT))
775 r |= EMAC_STACR_OC; 790 r |= EMAC_STACR_OC;
776 if (emac_has_feature(dev, EMAC_FTR_HAS_AXON_STACR)) 791 if (emac_has_feature(dev, EMAC_FTR_HAS_NEW_STACR))
777 r |= EMACX_STACR_STAC_WRITE; 792 r |= EMACX_STACR_STAC_WRITE;
778 else 793 else
779 r |= EMAC_STACR_STAC_WRITE; 794 r |= EMAC_STACR_STAC_WRITE;
@@ -1063,10 +1078,9 @@ static int emac_open(struct net_device *ndev)
1063 dev->rx_sg_skb = NULL; 1078 dev->rx_sg_skb = NULL;
1064 1079
1065 mutex_lock(&dev->link_lock); 1080 mutex_lock(&dev->link_lock);
1081 dev->opened = 1;
1066 1082
1067 /* XXX Start PHY polling now. Shouldn't wr do like sungem instead and 1083 /* Start PHY polling now.
1068 * always poll the PHY even when the iface is down ? That would allow
1069 * things like laptop-net to work. --BenH
1070 */ 1084 */
1071 if (dev->phy.address >= 0) { 1085 if (dev->phy.address >= 0) {
1072 int link_poll_interval; 1086 int link_poll_interval;
@@ -1145,9 +1159,11 @@ static void emac_link_timer(struct work_struct *work)
1145 int link_poll_interval; 1159 int link_poll_interval;
1146 1160
1147 mutex_lock(&dev->link_lock); 1161 mutex_lock(&dev->link_lock);
1148
1149 DBG2(dev, "link timer" NL); 1162 DBG2(dev, "link timer" NL);
1150 1163
1164 if (!dev->opened)
1165 goto bail;
1166
1151 if (dev->phy.def->ops->poll_link(&dev->phy)) { 1167 if (dev->phy.def->ops->poll_link(&dev->phy)) {
1152 if (!netif_carrier_ok(dev->ndev)) { 1168 if (!netif_carrier_ok(dev->ndev)) {
1153 /* Get new link parameters */ 1169 /* Get new link parameters */
@@ -1162,21 +1178,22 @@ static void emac_link_timer(struct work_struct *work)
1162 link_poll_interval = PHY_POLL_LINK_ON; 1178 link_poll_interval = PHY_POLL_LINK_ON;
1163 } else { 1179 } else {
1164 if (netif_carrier_ok(dev->ndev)) { 1180 if (netif_carrier_ok(dev->ndev)) {
1165 emac_reinitialize(dev);
1166 netif_carrier_off(dev->ndev); 1181 netif_carrier_off(dev->ndev);
1167 netif_tx_disable(dev->ndev); 1182 netif_tx_disable(dev->ndev);
1183 emac_reinitialize(dev);
1168 emac_print_link_status(dev); 1184 emac_print_link_status(dev);
1169 } 1185 }
1170 link_poll_interval = PHY_POLL_LINK_OFF; 1186 link_poll_interval = PHY_POLL_LINK_OFF;
1171 } 1187 }
1172 schedule_delayed_work(&dev->link_work, link_poll_interval); 1188 schedule_delayed_work(&dev->link_work, link_poll_interval);
1173 1189 bail:
1174 mutex_unlock(&dev->link_lock); 1190 mutex_unlock(&dev->link_lock);
1175} 1191}
1176 1192
1177static void emac_force_link_update(struct emac_instance *dev) 1193static void emac_force_link_update(struct emac_instance *dev)
1178{ 1194{
1179 netif_carrier_off(dev->ndev); 1195 netif_carrier_off(dev->ndev);
1196 smp_rmb();
1180 if (dev->link_polling) { 1197 if (dev->link_polling) {
1181 cancel_rearming_delayed_work(&dev->link_work); 1198 cancel_rearming_delayed_work(&dev->link_work);
1182 if (dev->link_polling) 1199 if (dev->link_polling)
@@ -1191,11 +1208,14 @@ static int emac_close(struct net_device *ndev)
1191 1208
1192 DBG(dev, "close" NL); 1209 DBG(dev, "close" NL);
1193 1210
1194 if (dev->phy.address >= 0) 1211 if (dev->phy.address >= 0) {
1212 dev->link_polling = 0;
1195 cancel_rearming_delayed_work(&dev->link_work); 1213 cancel_rearming_delayed_work(&dev->link_work);
1196 1214 }
1215 mutex_lock(&dev->link_lock);
1197 emac_netif_stop(dev); 1216 emac_netif_stop(dev);
1198 flush_scheduled_work(); 1217 dev->opened = 0;
1218 mutex_unlock(&dev->link_lock);
1199 1219
1200 emac_rx_disable(dev); 1220 emac_rx_disable(dev);
1201 emac_tx_disable(dev); 1221 emac_tx_disable(dev);
@@ -2427,7 +2447,7 @@ static int __devinit emac_init_config(struct emac_instance *dev)
2427 if (emac_read_uint_prop(np, "tah-device", &dev->tah_ph, 0)) 2447 if (emac_read_uint_prop(np, "tah-device", &dev->tah_ph, 0))
2428 dev->tah_ph = 0; 2448 dev->tah_ph = 0;
2429 if (emac_read_uint_prop(np, "tah-channel", &dev->tah_port, 0)) 2449 if (emac_read_uint_prop(np, "tah-channel", &dev->tah_port, 0))
2430 dev->tah_ph = 0; 2450 dev->tah_port = 0;
2431 if (emac_read_uint_prop(np, "mdio-device", &dev->mdio_ph, 0)) 2451 if (emac_read_uint_prop(np, "mdio-device", &dev->mdio_ph, 0))
2432 dev->mdio_ph = 0; 2452 dev->mdio_ph = 0;
2433 if (emac_read_uint_prop(np, "zmii-device", &dev->zmii_ph, 0)) 2453 if (emac_read_uint_prop(np, "zmii-device", &dev->zmii_ph, 0))
@@ -2465,16 +2485,19 @@ static int __devinit emac_init_config(struct emac_instance *dev)
2465 /* Check EMAC version */ 2485 /* Check EMAC version */
2466 if (of_device_is_compatible(np, "ibm,emac4")) 2486 if (of_device_is_compatible(np, "ibm,emac4"))
2467 dev->features |= EMAC_FTR_EMAC4; 2487 dev->features |= EMAC_FTR_EMAC4;
2468 if (of_device_is_compatible(np, "ibm,emac-axon") 2488
2469 || of_device_is_compatible(np, "ibm,emac-440epx")) 2489 /* Fixup some feature bits based on the device tree */
2470 dev->features |= EMAC_FTR_HAS_AXON_STACR 2490 if (of_get_property(np, "has-inverted-stacr-oc", NULL))
2471 | EMAC_FTR_STACR_OC_INVERT;
2472 if (of_device_is_compatible(np, "ibm,emac-440spe"))
2473 dev->features |= EMAC_FTR_STACR_OC_INVERT; 2491 dev->features |= EMAC_FTR_STACR_OC_INVERT;
2492 if (of_get_property(np, "has-new-stacr-staopc", NULL))
2493 dev->features |= EMAC_FTR_HAS_NEW_STACR;
2474 2494
2475 /* Fixup some feature bits based on the device tree and verify 2495 /* CAB lacks the appropriate properties */
2476 * we have support for them compiled in 2496 if (of_device_is_compatible(np, "ibm,emac-axon"))
2477 */ 2497 dev->features |= EMAC_FTR_HAS_NEW_STACR |
2498 EMAC_FTR_STACR_OC_INVERT;
2499
2500 /* Enable TAH/ZMII/RGMII features as found */
2478 if (dev->tah_ph != 0) { 2501 if (dev->tah_ph != 0) {
2479#ifdef CONFIG_IBM_NEW_EMAC_TAH 2502#ifdef CONFIG_IBM_NEW_EMAC_TAH
2480 dev->features |= EMAC_FTR_HAS_TAH; 2503 dev->features |= EMAC_FTR_HAS_TAH;
@@ -2532,6 +2555,10 @@ static int __devinit emac_probe(struct of_device *ofdev,
2532 struct device_node **blist = NULL; 2555 struct device_node **blist = NULL;
2533 int err, i; 2556 int err, i;
2534 2557
2558 /* Skip unused/unwired EMACS */
2559 if (of_get_property(np, "unused", NULL))
2560 return -ENODEV;
2561
2535 /* Find ourselves in the bootlist if we are there */ 2562 /* Find ourselves in the bootlist if we are there */
2536 for (i = 0; i < EMAC_BOOT_LIST_SIZE; i++) 2563 for (i = 0; i < EMAC_BOOT_LIST_SIZE; i++)
2537 if (emac_boot_list[i] == np) 2564 if (emac_boot_list[i] == np)
@@ -2756,6 +2783,8 @@ static int __devexit emac_remove(struct of_device *ofdev)
2756 2783
2757 unregister_netdev(dev->ndev); 2784 unregister_netdev(dev->ndev);
2758 2785
2786 flush_scheduled_work();
2787
2759 if (emac_has_feature(dev, EMAC_FTR_HAS_TAH)) 2788 if (emac_has_feature(dev, EMAC_FTR_HAS_TAH))
2760 tah_detach(dev->tah_dev, dev->tah_port); 2789 tah_detach(dev->tah_dev, dev->tah_port);
2761 if (emac_has_feature(dev, EMAC_FTR_HAS_RGMII)) 2790 if (emac_has_feature(dev, EMAC_FTR_HAS_RGMII))
diff --git a/drivers/net/ibm_newemac/core.h b/drivers/net/ibm_newemac/core.h
index 4011803117ca..4e74d8287c65 100644
--- a/drivers/net/ibm_newemac/core.h
+++ b/drivers/net/ibm_newemac/core.h
@@ -3,6 +3,11 @@
3 * 3 *
4 * Driver for PowerPC 4xx on-chip ethernet controller. 4 * Driver for PowerPC 4xx on-chip ethernet controller.
5 * 5 *
6 * Copyright 2007 Benjamin Herrenschmidt, IBM Corp.
7 * <benh@kernel.crashing.org>
8 *
9 * Based on the arch/ppc version of the driver:
10 *
6 * Copyright (c) 2004, 2005 Zultys Technologies. 11 * Copyright (c) 2004, 2005 Zultys Technologies.
7 * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net> 12 * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net>
8 * 13 *
@@ -258,6 +263,7 @@ struct emac_instance {
258 int stop_timeout; /* in us */ 263 int stop_timeout; /* in us */
259 int no_mcast; 264 int no_mcast;
260 int mcast_pending; 265 int mcast_pending;
266 int opened;
261 struct work_struct reset_work; 267 struct work_struct reset_work;
262 spinlock_t lock; 268 spinlock_t lock;
263}; 269};
@@ -292,9 +298,9 @@ struct emac_instance {
292 */ 298 */
293#define EMAC_FTR_HAS_RGMII 0x00000020 299#define EMAC_FTR_HAS_RGMII 0x00000020
294/* 300/*
295 * Set if we have axon-type STACR 301 * Set if we have new type STACR with STAOPC
296 */ 302 */
297#define EMAC_FTR_HAS_AXON_STACR 0x00000040 303#define EMAC_FTR_HAS_NEW_STACR 0x00000040
298 304
299 305
300/* Right now, we don't quite handle the always/possible masks on the 306/* Right now, we don't quite handle the always/possible masks on the
@@ -306,7 +312,7 @@ enum {
306 312
307 EMAC_FTRS_POSSIBLE = 313 EMAC_FTRS_POSSIBLE =
308#ifdef CONFIG_IBM_NEW_EMAC_EMAC4 314#ifdef CONFIG_IBM_NEW_EMAC_EMAC4
309 EMAC_FTR_EMAC4 | EMAC_FTR_HAS_AXON_STACR | 315 EMAC_FTR_EMAC4 | EMAC_FTR_HAS_NEW_STACR |
310 EMAC_FTR_STACR_OC_INVERT | 316 EMAC_FTR_STACR_OC_INVERT |
311#endif 317#endif
312#ifdef CONFIG_IBM_NEW_EMAC_TAH 318#ifdef CONFIG_IBM_NEW_EMAC_TAH
diff --git a/drivers/net/ibm_newemac/debug.c b/drivers/net/ibm_newemac/debug.c
index 170524ee0f19..86b756a30784 100644
--- a/drivers/net/ibm_newemac/debug.c
+++ b/drivers/net/ibm_newemac/debug.c
@@ -3,6 +3,11 @@
3 * 3 *
4 * Driver for PowerPC 4xx on-chip ethernet controller, debug print routines. 4 * Driver for PowerPC 4xx on-chip ethernet controller, debug print routines.
5 * 5 *
6 * Copyright 2007 Benjamin Herrenschmidt, IBM Corp.
7 * <benh@kernel.crashing.org>
8 *
9 * Based on the arch/ppc version of the driver:
10 *
6 * Copyright (c) 2004, 2005 Zultys Technologies 11 * Copyright (c) 2004, 2005 Zultys Technologies
7 * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net> 12 * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net>
8 * 13 *
@@ -21,7 +26,7 @@
21 26
22#include "core.h" 27#include "core.h"
23 28
24static spinlock_t emac_dbg_lock = SPIN_LOCK_UNLOCKED; 29static DEFINE_SPINLOCK(emac_dbg_lock);
25 30
26static void emac_desc_dump(struct emac_instance *p) 31static void emac_desc_dump(struct emac_instance *p)
27{ 32{
diff --git a/drivers/net/ibm_newemac/debug.h b/drivers/net/ibm_newemac/debug.h
index 1dd2dcbc157f..b631842ec8d0 100644
--- a/drivers/net/ibm_newemac/debug.h
+++ b/drivers/net/ibm_newemac/debug.h
@@ -3,6 +3,11 @@
3 * 3 *
4 * Driver for PowerPC 4xx on-chip ethernet controller, debug print routines. 4 * Driver for PowerPC 4xx on-chip ethernet controller, debug print routines.
5 * 5 *
6 * Copyright 2007 Benjamin Herrenschmidt, IBM Corp.
7 * <benh@kernel.crashing.org>
8 *
9 * Based on the arch/ppc version of the driver:
10 *
6 * Copyright (c) 2004, 2005 Zultys Technologies 11 * Copyright (c) 2004, 2005 Zultys Technologies
7 * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net> 12 * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net>
8 * 13 *
diff --git a/drivers/net/ibm_newemac/emac.h b/drivers/net/ibm_newemac/emac.h
index bef92efeeadc..91cb096ab405 100644
--- a/drivers/net/ibm_newemac/emac.h
+++ b/drivers/net/ibm_newemac/emac.h
@@ -3,6 +3,11 @@
3 * 3 *
4 * Register definitions for PowerPC 4xx on-chip ethernet contoller 4 * Register definitions for PowerPC 4xx on-chip ethernet contoller
5 * 5 *
6 * Copyright 2007 Benjamin Herrenschmidt, IBM Corp.
7 * <benh@kernel.crashing.org>
8 *
9 * Based on the arch/ppc version of the driver:
10 *
6 * Copyright (c) 2004, 2005 Zultys Technologies. 11 * Copyright (c) 2004, 2005 Zultys Technologies.
7 * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net> 12 * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net>
8 * 13 *
diff --git a/drivers/net/ibm_newemac/mal.c b/drivers/net/ibm_newemac/mal.c
index 9a88f71db004..6869f08c9dcb 100644
--- a/drivers/net/ibm_newemac/mal.c
+++ b/drivers/net/ibm_newemac/mal.c
@@ -3,6 +3,11 @@
3 * 3 *
4 * Memory Access Layer (MAL) support 4 * Memory Access Layer (MAL) support
5 * 5 *
6 * Copyright 2007 Benjamin Herrenschmidt, IBM Corp.
7 * <benh@kernel.crashing.org>
8 *
9 * Based on the arch/ppc version of the driver:
10 *
6 * Copyright (c) 2004, 2005 Zultys Technologies. 11 * Copyright (c) 2004, 2005 Zultys Technologies.
7 * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net> 12 * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net>
8 * 13 *
diff --git a/drivers/net/ibm_newemac/mal.h b/drivers/net/ibm_newemac/mal.h
index 784edb8ea822..eaa7262dc079 100644
--- a/drivers/net/ibm_newemac/mal.h
+++ b/drivers/net/ibm_newemac/mal.h
@@ -3,6 +3,11 @@
3 * 3 *
4 * Memory Access Layer (MAL) support 4 * Memory Access Layer (MAL) support
5 * 5 *
6 * Copyright 2007 Benjamin Herrenschmidt, IBM Corp.
7 * <benh@kernel.crashing.org>
8 *
9 * Based on the arch/ppc version of the driver:
10 *
6 * Copyright (c) 2004, 2005 Zultys Technologies. 11 * Copyright (c) 2004, 2005 Zultys Technologies.
7 * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net> 12 * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net>
8 * 13 *
diff --git a/drivers/net/ibm_newemac/phy.c b/drivers/net/ibm_newemac/phy.c
index aa1f0ddf1e3e..37bfeea8788a 100644
--- a/drivers/net/ibm_newemac/phy.c
+++ b/drivers/net/ibm_newemac/phy.c
@@ -8,6 +8,11 @@
8 * This file should be shared with other drivers or eventually 8 * This file should be shared with other drivers or eventually
9 * merged as the "low level" part of miilib 9 * merged as the "low level" part of miilib
10 * 10 *
11 * Copyright 2007 Benjamin Herrenschmidt, IBM Corp.
12 * <benh@kernel.crashing.org>
13 *
14 * Based on the arch/ppc version of the driver:
15 *
11 * (c) 2003, Benjamin Herrenscmidt (benh@kernel.crashing.org) 16 * (c) 2003, Benjamin Herrenscmidt (benh@kernel.crashing.org)
12 * (c) 2004-2005, Eugene Surovegin <ebs@ebshome.net> 17 * (c) 2004-2005, Eugene Surovegin <ebs@ebshome.net>
13 * 18 *
@@ -306,8 +311,84 @@ static struct mii_phy_def cis8201_phy_def = {
306 .ops = &cis8201_phy_ops 311 .ops = &cis8201_phy_ops
307}; 312};
308 313
314static struct mii_phy_def bcm5248_phy_def = {
315
316 .phy_id = 0x0143bc00,
317 .phy_id_mask = 0x0ffffff0,
318 .name = "BCM5248 10/100 SMII Ethernet",
319 .ops = &generic_phy_ops
320};
321
322static int m88e1111_init(struct mii_phy *phy)
323{
324 pr_debug("%s: Marvell 88E1111 Ethernet\n", __FUNCTION__);
325 phy_write(phy, 0x14, 0x0ce3);
326 phy_write(phy, 0x18, 0x4101);
327 phy_write(phy, 0x09, 0x0e00);
328 phy_write(phy, 0x04, 0x01e1);
329 phy_write(phy, 0x00, 0x9140);
330 phy_write(phy, 0x00, 0x1140);
331
332 return 0;
333}
334
335static int et1011c_init(struct mii_phy *phy)
336{
337 u16 reg_short;
338
339 reg_short = (u16)(phy_read(phy, 0x16));
340 reg_short &= ~(0x7);
341 reg_short |= 0x6; /* RGMII Trace Delay*/
342 phy_write(phy, 0x16, reg_short);
343
344 reg_short = (u16)(phy_read(phy, 0x17));
345 reg_short &= ~(0x40);
346 phy_write(phy, 0x17, reg_short);
347
348 phy_write(phy, 0x1c, 0x74f0);
349 return 0;
350}
351
352static struct mii_phy_ops et1011c_phy_ops = {
353 .init = et1011c_init,
354 .setup_aneg = genmii_setup_aneg,
355 .setup_forced = genmii_setup_forced,
356 .poll_link = genmii_poll_link,
357 .read_link = genmii_read_link
358};
359
360static struct mii_phy_def et1011c_phy_def = {
361 .phy_id = 0x0282f000,
362 .phy_id_mask = 0x0fffff00,
363 .name = "ET1011C Gigabit Ethernet",
364 .ops = &et1011c_phy_ops
365};
366
367
368
369
370
371static struct mii_phy_ops m88e1111_phy_ops = {
372 .init = m88e1111_init,
373 .setup_aneg = genmii_setup_aneg,
374 .setup_forced = genmii_setup_forced,
375 .poll_link = genmii_poll_link,
376 .read_link = genmii_read_link
377};
378
379static struct mii_phy_def m88e1111_phy_def = {
380
381 .phy_id = 0x01410CC0,
382 .phy_id_mask = 0x0ffffff0,
383 .name = "Marvell 88E1111 Ethernet",
384 .ops = &m88e1111_phy_ops,
385};
386
309static struct mii_phy_def *mii_phy_table[] = { 387static struct mii_phy_def *mii_phy_table[] = {
388 &et1011c_phy_def,
310 &cis8201_phy_def, 389 &cis8201_phy_def,
390 &bcm5248_phy_def,
391 &m88e1111_phy_def,
311 &genmii_phy_def, 392 &genmii_phy_def,
312 NULL 393 NULL
313}; 394};
diff --git a/drivers/net/ibm_newemac/phy.h b/drivers/net/ibm_newemac/phy.h
index 6feca26afedb..1b65c81f6557 100644
--- a/drivers/net/ibm_newemac/phy.h
+++ b/drivers/net/ibm_newemac/phy.h
@@ -3,6 +3,11 @@
3 * 3 *
4 * Driver for PowerPC 4xx on-chip ethernet controller, PHY support 4 * Driver for PowerPC 4xx on-chip ethernet controller, PHY support
5 * 5 *
6 * Copyright 2007 Benjamin Herrenschmidt, IBM Corp.
7 * <benh@kernel.crashing.org>
8 *
9 * Based on the arch/ppc version of the driver:
10 *
6 * Benjamin Herrenschmidt <benh@kernel.crashing.org> 11 * Benjamin Herrenschmidt <benh@kernel.crashing.org>
7 * February 2003 12 * February 2003
8 * 13 *
diff --git a/drivers/net/ibm_newemac/rgmii.c b/drivers/net/ibm_newemac/rgmii.c
index de416951a435..9bc1132fa788 100644
--- a/drivers/net/ibm_newemac/rgmii.c
+++ b/drivers/net/ibm_newemac/rgmii.c
@@ -3,6 +3,11 @@
3 * 3 *
4 * Driver for PowerPC 4xx on-chip ethernet controller, RGMII bridge support. 4 * Driver for PowerPC 4xx on-chip ethernet controller, RGMII bridge support.
5 * 5 *
6 * Copyright 2007 Benjamin Herrenschmidt, IBM Corp.
7 * <benh@kernel.crashing.org>
8 *
9 * Based on the arch/ppc version of the driver:
10 *
6 * Copyright (c) 2004, 2005 Zultys Technologies. 11 * Copyright (c) 2004, 2005 Zultys Technologies.
7 * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net> 12 * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net>
8 * 13 *
@@ -140,7 +145,7 @@ void rgmii_get_mdio(struct of_device *ofdev, int input)
140 145
141 RGMII_DBG2(dev, "get_mdio(%d)" NL, input); 146 RGMII_DBG2(dev, "get_mdio(%d)" NL, input);
142 147
143 if (dev->type != RGMII_AXON) 148 if (!(dev->flags & EMAC_RGMII_FLAG_HAS_MDIO))
144 return; 149 return;
145 150
146 mutex_lock(&dev->lock); 151 mutex_lock(&dev->lock);
@@ -161,7 +166,7 @@ void rgmii_put_mdio(struct of_device *ofdev, int input)
161 166
162 RGMII_DBG2(dev, "put_mdio(%d)" NL, input); 167 RGMII_DBG2(dev, "put_mdio(%d)" NL, input);
163 168
164 if (dev->type != RGMII_AXON) 169 if (!(dev->flags & EMAC_RGMII_FLAG_HAS_MDIO))
165 return; 170 return;
166 171
167 fer = in_be32(&p->fer); 172 fer = in_be32(&p->fer);
@@ -250,11 +255,13 @@ static int __devinit rgmii_probe(struct of_device *ofdev,
250 goto err_free; 255 goto err_free;
251 } 256 }
252 257
253 /* Check for RGMII type */ 258 /* Check for RGMII flags */
259 if (of_get_property(ofdev->node, "has-mdio", NULL))
260 dev->flags |= EMAC_RGMII_FLAG_HAS_MDIO;
261
262 /* CAB lacks the right properties, fix this up */
254 if (of_device_is_compatible(ofdev->node, "ibm,rgmii-axon")) 263 if (of_device_is_compatible(ofdev->node, "ibm,rgmii-axon"))
255 dev->type = RGMII_AXON; 264 dev->flags |= EMAC_RGMII_FLAG_HAS_MDIO;
256 else
257 dev->type = RGMII_STANDARD;
258 265
259 DBG2(dev, " Boot FER = 0x%08x, SSR = 0x%08x\n", 266 DBG2(dev, " Boot FER = 0x%08x, SSR = 0x%08x\n",
260 in_be32(&dev->base->fer), in_be32(&dev->base->ssr)); 267 in_be32(&dev->base->fer), in_be32(&dev->base->ssr));
@@ -263,9 +270,9 @@ static int __devinit rgmii_probe(struct of_device *ofdev,
263 out_be32(&dev->base->fer, 0); 270 out_be32(&dev->base->fer, 0);
264 271
265 printk(KERN_INFO 272 printk(KERN_INFO
266 "RGMII %s %s initialized\n", 273 "RGMII %s initialized with%s MDIO support\n",
267 dev->type == RGMII_STANDARD ? "standard" : "axon", 274 ofdev->node->full_name,
268 ofdev->node->full_name); 275 (dev->flags & EMAC_RGMII_FLAG_HAS_MDIO) ? "" : "out");
269 276
270 wmb(); 277 wmb();
271 dev_set_drvdata(&ofdev->dev, dev); 278 dev_set_drvdata(&ofdev->dev, dev);
diff --git a/drivers/net/ibm_newemac/rgmii.h b/drivers/net/ibm_newemac/rgmii.h
index 57806833121e..c4a4b358a270 100644
--- a/drivers/net/ibm_newemac/rgmii.h
+++ b/drivers/net/ibm_newemac/rgmii.h
@@ -3,6 +3,11 @@
3 * 3 *
4 * Driver for PowerPC 4xx on-chip ethernet controller, RGMII bridge support. 4 * Driver for PowerPC 4xx on-chip ethernet controller, RGMII bridge support.
5 * 5 *
6 * Copyright 2007 Benjamin Herrenschmidt, IBM Corp.
7 * <benh@kernel.crashing.org>
8 *
9 * Based on the arch/ppc version of the driver:
10 *
6 * Based on ocp_zmii.h/ibm_emac_zmii.h 11 * Based on ocp_zmii.h/ibm_emac_zmii.h
7 * Armin Kuster akuster@mvista.com 12 * Armin Kuster akuster@mvista.com
8 * 13 *
@@ -35,8 +40,9 @@ struct rgmii_regs {
35struct rgmii_instance { 40struct rgmii_instance {
36 struct rgmii_regs __iomem *base; 41 struct rgmii_regs __iomem *base;
37 42
38 /* Type of RGMII bridge */ 43 /* RGMII bridge flags */
39 int type; 44 int flags;
45#define EMAC_RGMII_FLAG_HAS_MDIO 0x00000001
40 46
41 /* Only one EMAC whacks us at a time */ 47 /* Only one EMAC whacks us at a time */
42 struct mutex lock; 48 struct mutex lock;
diff --git a/drivers/net/ibm_newemac/tah.c b/drivers/net/ibm_newemac/tah.c
index f161fb100e8e..96417adec326 100644
--- a/drivers/net/ibm_newemac/tah.c
+++ b/drivers/net/ibm_newemac/tah.c
@@ -3,6 +3,11 @@
3 * 3 *
4 * Driver for PowerPC 4xx on-chip ethernet controller, TAH support. 4 * Driver for PowerPC 4xx on-chip ethernet controller, TAH support.
5 * 5 *
6 * Copyright 2007 Benjamin Herrenschmidt, IBM Corp.
7 * <benh@kernel.crashing.org>
8 *
9 * Based on the arch/ppc version of the driver:
10 *
6 * Copyright 2004 MontaVista Software, Inc. 11 * Copyright 2004 MontaVista Software, Inc.
7 * Matt Porter <mporter@kernel.crashing.org> 12 * Matt Porter <mporter@kernel.crashing.org>
8 * 13 *
@@ -116,13 +121,14 @@ static int __devinit tah_probe(struct of_device *ofdev,
116 goto err_free; 121 goto err_free;
117 } 122 }
118 123
124 dev_set_drvdata(&ofdev->dev, dev);
125
119 /* Initialize TAH and enable IPv4 checksum verification, no TSO yet */ 126 /* Initialize TAH and enable IPv4 checksum verification, no TSO yet */
120 tah_reset(ofdev); 127 tah_reset(ofdev);
121 128
122 printk(KERN_INFO 129 printk(KERN_INFO
123 "TAH %s initialized\n", ofdev->node->full_name); 130 "TAH %s initialized\n", ofdev->node->full_name);
124 wmb(); 131 wmb();
125 dev_set_drvdata(&ofdev->dev, dev);
126 132
127 return 0; 133 return 0;
128 134
diff --git a/drivers/net/ibm_newemac/tah.h b/drivers/net/ibm_newemac/tah.h
index bc41853b6e26..a068b5658dad 100644
--- a/drivers/net/ibm_newemac/tah.h
+++ b/drivers/net/ibm_newemac/tah.h
@@ -3,6 +3,11 @@
3 * 3 *
4 * Driver for PowerPC 4xx on-chip ethernet controller, TAH support. 4 * Driver for PowerPC 4xx on-chip ethernet controller, TAH support.
5 * 5 *
6 * Copyright 2007 Benjamin Herrenschmidt, IBM Corp.
7 * <benh@kernel.crashing.org>
8 *
9 * Based on the arch/ppc version of the driver:
10 *
6 * Copyright 2004 MontaVista Software, Inc. 11 * Copyright 2004 MontaVista Software, Inc.
7 * Matt Porter <mporter@kernel.crashing.org> 12 * Matt Porter <mporter@kernel.crashing.org>
8 * 13 *
diff --git a/drivers/net/ibm_newemac/zmii.c b/drivers/net/ibm_newemac/zmii.c
index 2219ec2740e0..2ea472aeab06 100644
--- a/drivers/net/ibm_newemac/zmii.c
+++ b/drivers/net/ibm_newemac/zmii.c
@@ -3,6 +3,11 @@
3 * 3 *
4 * Driver for PowerPC 4xx on-chip ethernet controller, ZMII bridge support. 4 * Driver for PowerPC 4xx on-chip ethernet controller, ZMII bridge support.
5 * 5 *
6 * Copyright 2007 Benjamin Herrenschmidt, IBM Corp.
7 * <benh@kernel.crashing.org>
8 *
9 * Based on the arch/ppc version of the driver:
10 *
6 * Copyright (c) 2004, 2005 Zultys Technologies. 11 * Copyright (c) 2004, 2005 Zultys Technologies.
7 * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net> 12 * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net>
8 * 13 *
@@ -83,12 +88,14 @@ int __devinit zmii_attach(struct of_device *ofdev, int input, int *mode)
83 88
84 ZMII_DBG(dev, "init(%d, %d)" NL, input, *mode); 89 ZMII_DBG(dev, "init(%d, %d)" NL, input, *mode);
85 90
86 if (!zmii_valid_mode(*mode)) 91 if (!zmii_valid_mode(*mode)) {
87 /* Probably an EMAC connected to RGMII, 92 /* Probably an EMAC connected to RGMII,
88 * but it still may need ZMII for MDIO so 93 * but it still may need ZMII for MDIO so
89 * we don't fail here. 94 * we don't fail here.
90 */ 95 */
96 dev->users++;
91 return 0; 97 return 0;
98 }
92 99
93 mutex_lock(&dev->lock); 100 mutex_lock(&dev->lock);
94 101
diff --git a/drivers/net/ibm_newemac/zmii.h b/drivers/net/ibm_newemac/zmii.h
index 82a9968b1f74..6c9beba0c4b6 100644
--- a/drivers/net/ibm_newemac/zmii.h
+++ b/drivers/net/ibm_newemac/zmii.h
@@ -3,6 +3,11 @@
3 * 3 *
4 * Driver for PowerPC 4xx on-chip ethernet controller, ZMII bridge support. 4 * Driver for PowerPC 4xx on-chip ethernet controller, ZMII bridge support.
5 * 5 *
6 * Copyright 2007 Benjamin Herrenschmidt, IBM Corp.
7 * <benh@kernel.crashing.org>
8 *
9 * Based on the arch/ppc version of the driver:
10 *
6 * Copyright (c) 2004, 2005 Zultys Technologies. 11 * Copyright (c) 2004, 2005 Zultys Technologies.
7 * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net> 12 * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net>
8 * 13 *
diff --git a/drivers/net/irda/irda-usb.c b/drivers/net/irda/irda-usb.c
index c6355c00fd7a..9081234ab458 100644
--- a/drivers/net/irda/irda-usb.c
+++ b/drivers/net/irda/irda-usb.c
@@ -1168,6 +1168,7 @@ static int stir421x_patch_device(struct irda_usb_cb *self)
1168static int irda_usb_net_open(struct net_device *netdev) 1168static int irda_usb_net_open(struct net_device *netdev)
1169{ 1169{
1170 struct irda_usb_cb *self; 1170 struct irda_usb_cb *self;
1171 unsigned long flags;
1171 char hwname[16]; 1172 char hwname[16];
1172 int i; 1173 int i;
1173 1174
@@ -1177,13 +1178,16 @@ static int irda_usb_net_open(struct net_device *netdev)
1177 self = (struct irda_usb_cb *) netdev->priv; 1178 self = (struct irda_usb_cb *) netdev->priv;
1178 IRDA_ASSERT(self != NULL, return -1;); 1179 IRDA_ASSERT(self != NULL, return -1;);
1179 1180
1181 spin_lock_irqsave(&self->lock, flags);
1180 /* Can only open the device if it's there */ 1182 /* Can only open the device if it's there */
1181 if(!self->present) { 1183 if(!self->present) {
1184 spin_unlock_irqrestore(&self->lock, flags);
1182 IRDA_WARNING("%s(), device not present!\n", __FUNCTION__); 1185 IRDA_WARNING("%s(), device not present!\n", __FUNCTION__);
1183 return -1; 1186 return -1;
1184 } 1187 }
1185 1188
1186 if(self->needspatch) { 1189 if(self->needspatch) {
1190 spin_unlock_irqrestore(&self->lock, flags);
1187 IRDA_WARNING("%s(), device needs patch\n", __FUNCTION__) ; 1191 IRDA_WARNING("%s(), device needs patch\n", __FUNCTION__) ;
1188 return -EIO ; 1192 return -EIO ;
1189 } 1193 }
@@ -1198,6 +1202,7 @@ static int irda_usb_net_open(struct net_device *netdev)
1198 /* To do *before* submitting Rx urbs and starting net Tx queue 1202 /* To do *before* submitting Rx urbs and starting net Tx queue
1199 * Jean II */ 1203 * Jean II */
1200 self->netopen = 1; 1204 self->netopen = 1;
1205 spin_unlock_irqrestore(&self->lock, flags);
1201 1206
1202 /* 1207 /*
1203 * Now that everything should be initialized properly, 1208 * Now that everything should be initialized properly,
diff --git a/drivers/net/irda/mcs7780.c b/drivers/net/irda/mcs7780.c
index 0b769192d4ce..93916cf33f29 100644
--- a/drivers/net/irda/mcs7780.c
+++ b/drivers/net/irda/mcs7780.c
@@ -677,6 +677,8 @@ static int mcs_net_close(struct net_device *netdev)
677 /* Stop transmit processing */ 677 /* Stop transmit processing */
678 netif_stop_queue(netdev); 678 netif_stop_queue(netdev);
679 679
680 kfree_skb(mcs->rx_buff.skb);
681
680 /* kill and free the receive and transmit URBs */ 682 /* kill and free the receive and transmit URBs */
681 usb_kill_urb(mcs->rx_urb); 683 usb_kill_urb(mcs->rx_urb);
682 usb_free_urb(mcs->rx_urb); 684 usb_free_urb(mcs->rx_urb);
diff --git a/drivers/net/irda/stir4200.c b/drivers/net/irda/stir4200.c
index 042bc2f0417d..e59c485bc497 100644
--- a/drivers/net/irda/stir4200.c
+++ b/drivers/net/irda/stir4200.c
@@ -142,9 +142,6 @@ enum StirCtrl2Mask {
142}; 142};
143 143
144enum StirFifoCtlMask { 144enum StirFifoCtlMask {
145 FIFOCTL_EOF = 0x80,
146 FIFOCTL_UNDER = 0x40,
147 FIFOCTL_OVER = 0x20,
148 FIFOCTL_DIR = 0x10, 145 FIFOCTL_DIR = 0x10,
149 FIFOCTL_CLR = 0x08, 146 FIFOCTL_CLR = 0x08,
150 FIFOCTL_EMPTY = 0x04, 147 FIFOCTL_EMPTY = 0x04,
@@ -594,9 +591,10 @@ static int fifo_txwait(struct stir_cb *stir, int space)
594{ 591{
595 int err; 592 int err;
596 unsigned long count, status; 593 unsigned long count, status;
594 unsigned long prev_count = 0x1fff;
597 595
598 /* Read FIFO status and count */ 596 /* Read FIFO status and count */
599 for(;;) { 597 for (;; prev_count = count) {
600 err = read_reg(stir, REG_FIFOCTL, stir->fifo_status, 598 err = read_reg(stir, REG_FIFOCTL, stir->fifo_status,
601 FIFO_REGS_SIZE); 599 FIFO_REGS_SIZE);
602 if (unlikely(err != FIFO_REGS_SIZE)) { 600 if (unlikely(err != FIFO_REGS_SIZE)) {
@@ -629,6 +627,10 @@ static int fifo_txwait(struct stir_cb *stir, int space)
629 if (space >= 0 && STIR_FIFO_SIZE - 4 > space + count) 627 if (space >= 0 && STIR_FIFO_SIZE - 4 > space + count)
630 return 0; 628 return 0;
631 629
630 /* queue confused */
631 if (prev_count < count)
632 break;
633
632 /* estimate transfer time for remaining chars */ 634 /* estimate transfer time for remaining chars */
633 msleep((count * 8000) / stir->speed); 635 msleep((count * 8000) / stir->speed);
634 } 636 }
diff --git a/drivers/net/ixgb/ixgb_main.c b/drivers/net/ixgb/ixgb_main.c
index 3021234b1e17..bf9085fe035a 100644
--- a/drivers/net/ixgb/ixgb_main.c
+++ b/drivers/net/ixgb/ixgb_main.c
@@ -320,10 +320,22 @@ ixgb_down(struct ixgb_adapter *adapter, boolean_t kill_watchdog)
320void 320void
321ixgb_reset(struct ixgb_adapter *adapter) 321ixgb_reset(struct ixgb_adapter *adapter)
322{ 322{
323 struct ixgb_hw *hw = &adapter->hw;
323 324
324 ixgb_adapter_stop(&adapter->hw); 325 ixgb_adapter_stop(hw);
325 if(!ixgb_init_hw(&adapter->hw)) 326 if (!ixgb_init_hw(hw))
326 DPRINTK(PROBE, ERR, "ixgb_init_hw failed.\n"); 327 DPRINTK(PROBE, ERR, "ixgb_init_hw failed.\n");
328
329 /* restore frame size information */
330 IXGB_WRITE_REG(hw, MFS, hw->max_frame_size << IXGB_MFS_SHIFT);
331 if (hw->max_frame_size >
332 IXGB_MAX_ENET_FRAME_SIZE_WITHOUT_FCS + ENET_FCS_LENGTH) {
333 u32 ctrl0 = IXGB_READ_REG(hw, CTRL0);
334 if (!(ctrl0 & IXGB_CTRL0_JFE)) {
335 ctrl0 |= IXGB_CTRL0_JFE;
336 IXGB_WRITE_REG(hw, CTRL0, ctrl0);
337 }
338 }
327} 339}
328 340
329/** 341/**
diff --git a/drivers/net/lib82596.c b/drivers/net/lib82596.c
index 9a855e512147..b59f442bbf36 100644
--- a/drivers/net/lib82596.c
+++ b/drivers/net/lib82596.c
@@ -176,8 +176,8 @@ struct i596_reg {
176struct i596_tbd { 176struct i596_tbd {
177 unsigned short size; 177 unsigned short size;
178 unsigned short pad; 178 unsigned short pad;
179 dma_addr_t next; 179 u32 next;
180 dma_addr_t data; 180 u32 data;
181 u32 cache_pad[5]; /* Total 32 bytes... */ 181 u32 cache_pad[5]; /* Total 32 bytes... */
182}; 182};
183 183
@@ -195,12 +195,12 @@ struct i596_cmd {
195 struct i596_cmd *v_next; /* Address from CPUs viewpoint */ 195 struct i596_cmd *v_next; /* Address from CPUs viewpoint */
196 unsigned short status; 196 unsigned short status;
197 unsigned short command; 197 unsigned short command;
198 dma_addr_t b_next; /* Address from i596 viewpoint */ 198 u32 b_next; /* Address from i596 viewpoint */
199}; 199};
200 200
201struct tx_cmd { 201struct tx_cmd {
202 struct i596_cmd cmd; 202 struct i596_cmd cmd;
203 dma_addr_t tbd; 203 u32 tbd;
204 unsigned short size; 204 unsigned short size;
205 unsigned short pad; 205 unsigned short pad;
206 struct sk_buff *skb; /* So we can free it after tx */ 206 struct sk_buff *skb; /* So we can free it after tx */
@@ -237,8 +237,8 @@ struct cf_cmd {
237struct i596_rfd { 237struct i596_rfd {
238 unsigned short stat; 238 unsigned short stat;
239 unsigned short cmd; 239 unsigned short cmd;
240 dma_addr_t b_next; /* Address from i596 viewpoint */ 240 u32 b_next; /* Address from i596 viewpoint */
241 dma_addr_t rbd; 241 u32 rbd;
242 unsigned short count; 242 unsigned short count;
243 unsigned short size; 243 unsigned short size;
244 struct i596_rfd *v_next; /* Address from CPUs viewpoint */ 244 struct i596_rfd *v_next; /* Address from CPUs viewpoint */
@@ -249,18 +249,18 @@ struct i596_rfd {
249}; 249};
250 250
251struct i596_rbd { 251struct i596_rbd {
252 /* hardware data */ 252 /* hardware data */
253 unsigned short count; 253 unsigned short count;
254 unsigned short zero1; 254 unsigned short zero1;
255 dma_addr_t b_next; 255 u32 b_next;
256 dma_addr_t b_data; /* Address from i596 viewpoint */ 256 u32 b_data; /* Address from i596 viewpoint */
257 unsigned short size; 257 unsigned short size;
258 unsigned short zero2; 258 unsigned short zero2;
259 /* driver data */ 259 /* driver data */
260 struct sk_buff *skb; 260 struct sk_buff *skb;
261 struct i596_rbd *v_next; 261 struct i596_rbd *v_next;
262 dma_addr_t b_addr; /* This rbd addr from i596 view */ 262 u32 b_addr; /* This rbd addr from i596 view */
263 unsigned char *v_data; /* Address from CPUs viewpoint */ 263 unsigned char *v_data; /* Address from CPUs viewpoint */
264 /* Total 32 bytes... */ 264 /* Total 32 bytes... */
265#ifdef __LP64__ 265#ifdef __LP64__
266 u32 cache_pad[4]; 266 u32 cache_pad[4];
@@ -275,8 +275,8 @@ struct i596_rbd {
275struct i596_scb { 275struct i596_scb {
276 unsigned short status; 276 unsigned short status;
277 unsigned short command; 277 unsigned short command;
278 dma_addr_t cmd; 278 u32 cmd;
279 dma_addr_t rfd; 279 u32 rfd;
280 u32 crc_err; 280 u32 crc_err;
281 u32 align_err; 281 u32 align_err;
282 u32 resource_err; 282 u32 resource_err;
@@ -288,14 +288,14 @@ struct i596_scb {
288}; 288};
289 289
290struct i596_iscp { 290struct i596_iscp {
291 u32 stat; 291 u32 stat;
292 dma_addr_t scb; 292 u32 scb;
293}; 293};
294 294
295struct i596_scp { 295struct i596_scp {
296 u32 sysbus; 296 u32 sysbus;
297 u32 pad; 297 u32 pad;
298 dma_addr_t iscp; 298 u32 iscp;
299}; 299};
300 300
301struct i596_dma { 301struct i596_dma {
diff --git a/drivers/net/macb.c b/drivers/net/macb.c
index 047ea7be4850..e10528ed9081 100644
--- a/drivers/net/macb.c
+++ b/drivers/net/macb.c
@@ -307,8 +307,31 @@ static void macb_tx(struct macb *bp)
307 (unsigned long)status); 307 (unsigned long)status);
308 308
309 if (status & MACB_BIT(UND)) { 309 if (status & MACB_BIT(UND)) {
310 int i;
310 printk(KERN_ERR "%s: TX underrun, resetting buffers\n", 311 printk(KERN_ERR "%s: TX underrun, resetting buffers\n",
311 bp->dev->name); 312 bp->dev->name);
313
314 head = bp->tx_head;
315
316 /*Mark all the buffer as used to avoid sending a lost buffer*/
317 for (i = 0; i < TX_RING_SIZE; i++)
318 bp->tx_ring[i].ctrl = MACB_BIT(TX_USED);
319
320 /* free transmit buffer in upper layer*/
321 for (tail = bp->tx_tail; tail != head; tail = NEXT_TX(tail)) {
322 struct ring_info *rp = &bp->tx_skb[tail];
323 struct sk_buff *skb = rp->skb;
324
325 BUG_ON(skb == NULL);
326
327 rmb();
328
329 dma_unmap_single(&bp->pdev->dev, rp->mapping, skb->len,
330 DMA_TO_DEVICE);
331 rp->skb = NULL;
332 dev_kfree_skb_irq(skb);
333 }
334
312 bp->tx_head = bp->tx_tail = 0; 335 bp->tx_head = bp->tx_tail = 0;
313 } 336 }
314 337
diff --git a/drivers/net/mlx4/qp.c b/drivers/net/mlx4/qp.c
index 42b47639c81c..fa24e6597591 100644
--- a/drivers/net/mlx4/qp.c
+++ b/drivers/net/mlx4/qp.c
@@ -113,7 +113,7 @@ int mlx4_qp_modify(struct mlx4_dev *dev, struct mlx4_mtt *mtt,
113 struct mlx4_cmd_mailbox *mailbox; 113 struct mlx4_cmd_mailbox *mailbox;
114 int ret = 0; 114 int ret = 0;
115 115
116 if (cur_state >= MLX4_QP_NUM_STATE || cur_state >= MLX4_QP_NUM_STATE || 116 if (cur_state >= MLX4_QP_NUM_STATE || new_state >= MLX4_QP_NUM_STATE ||
117 !op[cur_state][new_state]) 117 !op[cur_state][new_state])
118 return -EINVAL; 118 return -EINVAL;
119 119
diff --git a/drivers/net/myri10ge/myri10ge.c b/drivers/net/myri10ge/myri10ge.c
index 0f306ddb5630..8def8657251f 100644
--- a/drivers/net/myri10ge/myri10ge.c
+++ b/drivers/net/myri10ge/myri10ge.c
@@ -1979,6 +1979,7 @@ static int myri10ge_open(struct net_device *dev)
1979 lro_mgr->lro_arr = mgp->rx_done.lro_desc; 1979 lro_mgr->lro_arr = mgp->rx_done.lro_desc;
1980 lro_mgr->get_frag_header = myri10ge_get_frag_header; 1980 lro_mgr->get_frag_header = myri10ge_get_frag_header;
1981 lro_mgr->max_aggr = myri10ge_lro_max_pkts; 1981 lro_mgr->max_aggr = myri10ge_lro_max_pkts;
1982 lro_mgr->frag_align_pad = 2;
1982 if (lro_mgr->max_aggr > MAX_SKB_FRAGS) 1983 if (lro_mgr->max_aggr > MAX_SKB_FRAGS)
1983 lro_mgr->max_aggr = MAX_SKB_FRAGS; 1984 lro_mgr->max_aggr = MAX_SKB_FRAGS;
1984 1985
diff --git a/drivers/net/niu.c b/drivers/net/niu.c
index 112ab079ce7d..abfc61c3a38c 100644
--- a/drivers/net/niu.c
+++ b/drivers/net/niu.c
@@ -1045,6 +1045,7 @@ static int niu_serdes_init(struct niu *np)
1045} 1045}
1046 1046
1047static void niu_init_xif(struct niu *); 1047static void niu_init_xif(struct niu *);
1048static void niu_handle_led(struct niu *, int status);
1048 1049
1049static int niu_link_status_common(struct niu *np, int link_up) 1050static int niu_link_status_common(struct niu *np, int link_up)
1050{ 1051{
@@ -1066,11 +1067,15 @@ static int niu_link_status_common(struct niu *np, int link_up)
1066 1067
1067 spin_lock_irqsave(&np->lock, flags); 1068 spin_lock_irqsave(&np->lock, flags);
1068 niu_init_xif(np); 1069 niu_init_xif(np);
1070 niu_handle_led(np, 1);
1069 spin_unlock_irqrestore(&np->lock, flags); 1071 spin_unlock_irqrestore(&np->lock, flags);
1070 1072
1071 netif_carrier_on(dev); 1073 netif_carrier_on(dev);
1072 } else if (netif_carrier_ok(dev) && !link_up) { 1074 } else if (netif_carrier_ok(dev) && !link_up) {
1073 niuwarn(LINK, "%s: Link is down\n", dev->name); 1075 niuwarn(LINK, "%s: Link is down\n", dev->name);
1076 spin_lock_irqsave(&np->lock, flags);
1077 niu_handle_led(np, 0);
1078 spin_unlock_irqrestore(&np->lock, flags);
1074 netif_carrier_off(dev); 1079 netif_carrier_off(dev);
1075 } 1080 }
1076 1081
@@ -3915,16 +3920,14 @@ static int niu_init_ipp(struct niu *np)
3915 return 0; 3920 return 0;
3916} 3921}
3917 3922
3918static void niu_init_xif_xmac(struct niu *np) 3923static void niu_handle_led(struct niu *np, int status)
3919{ 3924{
3920 struct niu_link_config *lp = &np->link_config;
3921 u64 val; 3925 u64 val;
3922
3923 val = nr64_mac(XMAC_CONFIG); 3926 val = nr64_mac(XMAC_CONFIG);
3924 3927
3925 if ((np->flags & NIU_FLAGS_10G) != 0 && 3928 if ((np->flags & NIU_FLAGS_10G) != 0 &&
3926 (np->flags & NIU_FLAGS_FIBER) != 0) { 3929 (np->flags & NIU_FLAGS_FIBER) != 0) {
3927 if (netif_carrier_ok(np->dev)) { 3930 if (status) {
3928 val |= XMAC_CONFIG_LED_POLARITY; 3931 val |= XMAC_CONFIG_LED_POLARITY;
3929 val &= ~XMAC_CONFIG_FORCE_LED_ON; 3932 val &= ~XMAC_CONFIG_FORCE_LED_ON;
3930 } else { 3933 } else {
@@ -3933,6 +3936,15 @@ static void niu_init_xif_xmac(struct niu *np)
3933 } 3936 }
3934 } 3937 }
3935 3938
3939 nw64_mac(XMAC_CONFIG, val);
3940}
3941
3942static void niu_init_xif_xmac(struct niu *np)
3943{
3944 struct niu_link_config *lp = &np->link_config;
3945 u64 val;
3946
3947 val = nr64_mac(XMAC_CONFIG);
3936 val &= ~XMAC_CONFIG_SEL_POR_CLK_SRC; 3948 val &= ~XMAC_CONFIG_SEL_POR_CLK_SRC;
3937 3949
3938 val |= XMAC_CONFIG_TX_OUTPUT_EN; 3950 val |= XMAC_CONFIG_TX_OUTPUT_EN;
@@ -4776,6 +4788,8 @@ static int niu_close(struct net_device *dev)
4776 4788
4777 niu_free_channels(np); 4789 niu_free_channels(np);
4778 4790
4791 niu_handle_led(np, 0);
4792
4779 return 0; 4793 return 0;
4780} 4794}
4781 4795
diff --git a/drivers/net/pasemi_mac.c b/drivers/net/pasemi_mac.c
index 09b4fde8d924..816a59e801b2 100644
--- a/drivers/net/pasemi_mac.c
+++ b/drivers/net/pasemi_mac.c
@@ -586,7 +586,7 @@ static int pasemi_mac_clean_rx(struct pasemi_mac *mac, int limit)
586 /* CRC error flagged */ 586 /* CRC error flagged */
587 mac->netdev->stats.rx_errors++; 587 mac->netdev->stats.rx_errors++;
588 mac->netdev->stats.rx_crc_errors++; 588 mac->netdev->stats.rx_crc_errors++;
589 dev_kfree_skb_irq(skb); 589 /* No need to free skb, it'll be reused */
590 goto next; 590 goto next;
591 } 591 }
592 592
@@ -1362,7 +1362,7 @@ pasemi_mac_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1362 1362
1363 netif_napi_add(dev, &mac->napi, pasemi_mac_poll, 64); 1363 netif_napi_add(dev, &mac->napi, pasemi_mac_poll, 64);
1364 1364
1365 dev->features = NETIF_F_HW_CSUM | NETIF_F_LLTX | NETIF_F_SG; 1365 dev->features = NETIF_F_IP_CSUM | NETIF_F_LLTX | NETIF_F_SG;
1366 1366
1367 /* These should come out of the device tree eventually */ 1367 /* These should come out of the device tree eventually */
1368 mac->dma_txch = index; 1368 mac->dma_txch = index;
diff --git a/drivers/net/pcmcia/3c574_cs.c b/drivers/net/pcmcia/3c574_cs.c
index ad134a61302a..288177716a49 100644
--- a/drivers/net/pcmcia/3c574_cs.c
+++ b/drivers/net/pcmcia/3c574_cs.c
@@ -337,15 +337,15 @@ static int tc574_config(struct pcmcia_device *link)
337 struct net_device *dev = link->priv; 337 struct net_device *dev = link->priv;
338 struct el3_private *lp = netdev_priv(dev); 338 struct el3_private *lp = netdev_priv(dev);
339 tuple_t tuple; 339 tuple_t tuple;
340 unsigned short buf[32]; 340 __le16 buf[32];
341 int last_fn, last_ret, i, j; 341 int last_fn, last_ret, i, j;
342 kio_addr_t ioaddr; 342 kio_addr_t ioaddr;
343 u16 *phys_addr; 343 __be16 *phys_addr;
344 char *cardname; 344 char *cardname;
345 union wn3_config config; 345 union wn3_config config;
346 DECLARE_MAC_BUF(mac); 346 DECLARE_MAC_BUF(mac);
347 347
348 phys_addr = (u16 *)dev->dev_addr; 348 phys_addr = (__be16 *)dev->dev_addr;
349 349
350 DEBUG(0, "3c574_config(0x%p)\n", link); 350 DEBUG(0, "3c574_config(0x%p)\n", link);
351 351
@@ -378,12 +378,12 @@ static int tc574_config(struct pcmcia_device *link)
378 if (pcmcia_get_first_tuple(link, &tuple) == CS_SUCCESS) { 378 if (pcmcia_get_first_tuple(link, &tuple) == CS_SUCCESS) {
379 pcmcia_get_tuple_data(link, &tuple); 379 pcmcia_get_tuple_data(link, &tuple);
380 for (i = 0; i < 3; i++) 380 for (i = 0; i < 3; i++)
381 phys_addr[i] = htons(buf[i]); 381 phys_addr[i] = htons(le16_to_cpu(buf[i]));
382 } else { 382 } else {
383 EL3WINDOW(0); 383 EL3WINDOW(0);
384 for (i = 0; i < 3; i++) 384 for (i = 0; i < 3; i++)
385 phys_addr[i] = htons(read_eeprom(ioaddr, i + 10)); 385 phys_addr[i] = htons(read_eeprom(ioaddr, i + 10));
386 if (phys_addr[0] == 0x6060) { 386 if (phys_addr[0] == htons(0x6060)) {
387 printk(KERN_NOTICE "3c574_cs: IO port conflict at 0x%03lx" 387 printk(KERN_NOTICE "3c574_cs: IO port conflict at 0x%03lx"
388 "-0x%03lx\n", dev->base_addr, dev->base_addr+15); 388 "-0x%03lx\n", dev->base_addr, dev->base_addr+15);
389 goto failed; 389 goto failed;
diff --git a/drivers/net/pcmcia/3c589_cs.c b/drivers/net/pcmcia/3c589_cs.c
index a98fe07cce70..e862d14ece79 100644
--- a/drivers/net/pcmcia/3c589_cs.c
+++ b/drivers/net/pcmcia/3c589_cs.c
@@ -251,7 +251,8 @@ static int tc589_config(struct pcmcia_device *link)
251 struct net_device *dev = link->priv; 251 struct net_device *dev = link->priv;
252 struct el3_private *lp = netdev_priv(dev); 252 struct el3_private *lp = netdev_priv(dev);
253 tuple_t tuple; 253 tuple_t tuple;
254 u16 buf[32], *phys_addr; 254 __le16 buf[32];
255 __be16 *phys_addr;
255 int last_fn, last_ret, i, j, multi = 0, fifo; 256 int last_fn, last_ret, i, j, multi = 0, fifo;
256 kio_addr_t ioaddr; 257 kio_addr_t ioaddr;
257 char *ram_split[] = {"5:3", "3:1", "1:1", "3:5"}; 258 char *ram_split[] = {"5:3", "3:1", "1:1", "3:5"};
@@ -259,7 +260,7 @@ static int tc589_config(struct pcmcia_device *link)
259 260
260 DEBUG(0, "3c589_config(0x%p)\n", link); 261 DEBUG(0, "3c589_config(0x%p)\n", link);
261 262
262 phys_addr = (u16 *)dev->dev_addr; 263 phys_addr = (__be16 *)dev->dev_addr;
263 tuple.Attributes = 0; 264 tuple.Attributes = 0;
264 tuple.TupleData = (cisdata_t *)buf; 265 tuple.TupleData = (cisdata_t *)buf;
265 tuple.TupleDataMax = sizeof(buf); 266 tuple.TupleDataMax = sizeof(buf);
@@ -298,11 +299,11 @@ static int tc589_config(struct pcmcia_device *link)
298 if (pcmcia_get_first_tuple(link, &tuple) == CS_SUCCESS) { 299 if (pcmcia_get_first_tuple(link, &tuple) == CS_SUCCESS) {
299 pcmcia_get_tuple_data(link, &tuple); 300 pcmcia_get_tuple_data(link, &tuple);
300 for (i = 0; i < 3; i++) 301 for (i = 0; i < 3; i++)
301 phys_addr[i] = htons(buf[i]); 302 phys_addr[i] = htons(le16_to_cpu(buf[i]));
302 } else { 303 } else {
303 for (i = 0; i < 3; i++) 304 for (i = 0; i < 3; i++)
304 phys_addr[i] = htons(read_eeprom(ioaddr, i)); 305 phys_addr[i] = htons(read_eeprom(ioaddr, i));
305 if (phys_addr[0] == 0x6060) { 306 if (phys_addr[0] == htons(0x6060)) {
306 printk(KERN_ERR "3c589_cs: IO port conflict at 0x%03lx" 307 printk(KERN_ERR "3c589_cs: IO port conflict at 0x%03lx"
307 "-0x%03lx\n", dev->base_addr, dev->base_addr+15); 308 "-0x%03lx\n", dev->base_addr, dev->base_addr+15);
308 goto failed; 309 goto failed;
diff --git a/drivers/net/pcmcia/pcnet_cs.c b/drivers/net/pcmcia/pcnet_cs.c
index db6a97d1d7b1..51bbd582f16c 100644
--- a/drivers/net/pcmcia/pcnet_cs.c
+++ b/drivers/net/pcmcia/pcnet_cs.c
@@ -1746,6 +1746,7 @@ static struct pcmcia_device_id pcnet_ids[] = {
1746 PCMCIA_DEVICE_CIS_PROD_ID12("NDC", "Ethernet", 0x01c43ae1, 0x00b2e941, "NE2K.cis"), 1746 PCMCIA_DEVICE_CIS_PROD_ID12("NDC", "Ethernet", 0x01c43ae1, 0x00b2e941, "NE2K.cis"),
1747 PCMCIA_DEVICE_CIS_PROD_ID12("PMX ", "PE-200", 0x34f3f1c8, 0x10b59f8c, "PE-200.cis"), 1747 PCMCIA_DEVICE_CIS_PROD_ID12("PMX ", "PE-200", 0x34f3f1c8, 0x10b59f8c, "PE-200.cis"),
1748 PCMCIA_DEVICE_CIS_PROD_ID12("TAMARACK", "Ethernet", 0xcf434fba, 0x00b2e941, "tamarack.cis"), 1748 PCMCIA_DEVICE_CIS_PROD_ID12("TAMARACK", "Ethernet", 0xcf434fba, 0x00b2e941, "tamarack.cis"),
1749 PCMCIA_DEVICE_PROD_ID12("Ethernet", "CF Size PC Card", 0x00b2e941, 0x43ac239b),
1749 PCMCIA_DEVICE_PROD_ID123("Fast Ethernet", "CF Size PC Card", "1.0", 1750 PCMCIA_DEVICE_PROD_ID123("Fast Ethernet", "CF Size PC Card", "1.0",
1750 0xb4be14e3, 0x43ac239b, 0x0877b627), 1751 0xb4be14e3, 0x43ac239b, 0x0877b627),
1751 PCMCIA_DEVICE_NULL 1752 PCMCIA_DEVICE_NULL
diff --git a/drivers/net/phy/marvell.c b/drivers/net/phy/marvell.c
index 035fd41fb61f..f0574073a2a3 100644
--- a/drivers/net/phy/marvell.c
+++ b/drivers/net/phy/marvell.c
@@ -143,21 +143,29 @@ static int m88e1111_config_init(struct phy_device *phydev)
143 int err; 143 int err;
144 144
145 if ((phydev->interface == PHY_INTERFACE_MODE_RGMII) || 145 if ((phydev->interface == PHY_INTERFACE_MODE_RGMII) ||
146 (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID)) { 146 (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID) ||
147 (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID) ||
148 (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID)) {
147 int temp; 149 int temp;
148 150
149 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID) { 151 temp = phy_read(phydev, MII_M1111_PHY_EXT_CR);
150 temp = phy_read(phydev, MII_M1111_PHY_EXT_CR); 152 if (temp < 0)
151 if (temp < 0) 153 return temp;
152 return temp;
153 154
155 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID) {
154 temp |= (MII_M1111_RX_DELAY | MII_M1111_TX_DELAY); 156 temp |= (MII_M1111_RX_DELAY | MII_M1111_TX_DELAY);
155 157 } else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID) {
156 err = phy_write(phydev, MII_M1111_PHY_EXT_CR, temp); 158 temp &= ~MII_M1111_TX_DELAY;
157 if (err < 0) 159 temp |= MII_M1111_RX_DELAY;
158 return err; 160 } else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) {
161 temp &= ~MII_M1111_RX_DELAY;
162 temp |= MII_M1111_TX_DELAY;
159 } 163 }
160 164
165 err = phy_write(phydev, MII_M1111_PHY_EXT_CR, temp);
166 if (err < 0)
167 return err;
168
161 temp = phy_read(phydev, MII_M1111_PHY_EXT_SR); 169 temp = phy_read(phydev, MII_M1111_PHY_EXT_SR);
162 if (temp < 0) 170 if (temp < 0)
163 return temp; 171 return temp;
diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index fc2f0e695a13..c30196d0ad16 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -91,9 +91,12 @@ int mdiobus_register(struct mii_bus *bus)
91 91
92 err = device_register(&phydev->dev); 92 err = device_register(&phydev->dev);
93 93
94 if (err) 94 if (err) {
95 printk(KERN_ERR "phy %d failed to register\n", 95 printk(KERN_ERR "phy %d failed to register\n",
96 i); 96 i);
97 phy_device_free(phydev);
98 phydev = NULL;
99 }
97 } 100 }
98 101
99 bus->phy_map[i] = phydev; 102 bus->phy_map[i] = phydev;
@@ -110,10 +113,8 @@ void mdiobus_unregister(struct mii_bus *bus)
110 int i; 113 int i;
111 114
112 for (i = 0; i < PHY_MAX_ADDR; i++) { 115 for (i = 0; i < PHY_MAX_ADDR; i++) {
113 if (bus->phy_map[i]) { 116 if (bus->phy_map[i])
114 device_unregister(&bus->phy_map[i]->dev); 117 device_unregister(&bus->phy_map[i]->dev);
115 kfree(bus->phy_map[i]);
116 }
117 } 118 }
118} 119}
119EXPORT_SYMBOL(mdiobus_unregister); 120EXPORT_SYMBOL(mdiobus_unregister);
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index 9bc11773705b..7c9e6e349503 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -406,6 +406,9 @@ int phy_mii_ioctl(struct phy_device *phydev,
406 && phydev->drv->config_init) 406 && phydev->drv->config_init)
407 phydev->drv->config_init(phydev); 407 phydev->drv->config_init(phydev);
408 break; 408 break;
409
410 default:
411 return -ENOTTY;
409 } 412 }
410 413
411 return 0; 414 return 0;
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index f6e484812a98..5b9e1751e1b4 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -44,6 +44,16 @@ static struct phy_driver genphy_driver;
44extern int mdio_bus_init(void); 44extern int mdio_bus_init(void);
45extern void mdio_bus_exit(void); 45extern void mdio_bus_exit(void);
46 46
47void phy_device_free(struct phy_device *phydev)
48{
49 kfree(phydev);
50}
51
52static void phy_device_release(struct device *dev)
53{
54 phy_device_free(to_phy_device(dev));
55}
56
47struct phy_device* phy_device_create(struct mii_bus *bus, int addr, int phy_id) 57struct phy_device* phy_device_create(struct mii_bus *bus, int addr, int phy_id)
48{ 58{
49 struct phy_device *dev; 59 struct phy_device *dev;
@@ -54,6 +64,8 @@ struct phy_device* phy_device_create(struct mii_bus *bus, int addr, int phy_id)
54 if (NULL == dev) 64 if (NULL == dev)
55 return (struct phy_device*) PTR_ERR((void*)-ENOMEM); 65 return (struct phy_device*) PTR_ERR((void*)-ENOMEM);
56 66
67 dev->dev.release = phy_device_release;
68
57 dev->speed = 0; 69 dev->speed = 0;
58 dev->duplex = -1; 70 dev->duplex = -1;
59 dev->pause = dev->asym_pause = 0; 71 dev->pause = dev->asym_pause = 0;
diff --git a/drivers/net/plip.c b/drivers/net/plip.c
index 5071fcd8a0bd..57c98669984d 100644
--- a/drivers/net/plip.c
+++ b/drivers/net/plip.c
@@ -663,7 +663,7 @@ plip_receive_packet(struct net_device *dev, struct net_local *nl,
663 case PLIP_PK_DONE: 663 case PLIP_PK_DONE:
664 /* Inform the upper layer for the arrival of a packet. */ 664 /* Inform the upper layer for the arrival of a packet. */
665 rcv->skb->protocol=plip_type_trans(rcv->skb, dev); 665 rcv->skb->protocol=plip_type_trans(rcv->skb, dev);
666 netif_rx(rcv->skb); 666 netif_rx_ni(rcv->skb);
667 dev->last_rx = jiffies; 667 dev->last_rx = jiffies;
668 dev->stats.rx_bytes += rcv->length.h; 668 dev->stats.rx_bytes += rcv->length.h;
669 dev->stats.rx_packets++; 669 dev->stats.rx_packets++;
@@ -1269,7 +1269,7 @@ static void plip_attach (struct parport *port)
1269 1269
1270 nl = netdev_priv(dev); 1270 nl = netdev_priv(dev);
1271 nl->dev = dev; 1271 nl->dev = dev;
1272 nl->pardev = parport_register_device(port, name, plip_preempt, 1272 nl->pardev = parport_register_device(port, dev->name, plip_preempt,
1273 plip_wakeup, plip_interrupt, 1273 plip_wakeup, plip_interrupt,
1274 0, dev); 1274 0, dev);
1275 1275
diff --git a/drivers/net/r8169.c b/drivers/net/r8169.c
index 1f647b9ce352..5863190894cc 100644
--- a/drivers/net/r8169.c
+++ b/drivers/net/r8169.c
@@ -2211,7 +2211,7 @@ out:
2211 2211
2212static inline void rtl8169_make_unusable_by_asic(struct RxDesc *desc) 2212static inline void rtl8169_make_unusable_by_asic(struct RxDesc *desc)
2213{ 2213{
2214 desc->addr = 0x0badbadbadbadbadull; 2214 desc->addr = cpu_to_le64(0x0badbadbadbadbadull);
2215 desc->opts1 &= ~cpu_to_le32(DescOwn | RsvdMask); 2215 desc->opts1 &= ~cpu_to_le32(DescOwn | RsvdMask);
2216} 2216}
2217 2217
@@ -2835,7 +2835,7 @@ static int rtl8169_rx_interrupt(struct net_device *dev,
2835 } 2835 }
2836 2836
2837 /* Work around for AMD plateform. */ 2837 /* Work around for AMD plateform. */
2838 if ((desc->opts2 & 0xfffe000) && 2838 if ((desc->opts2 & cpu_to_le32(0xfffe000)) &&
2839 (tp->mac_version == RTL_GIGA_MAC_VER_05)) { 2839 (tp->mac_version == RTL_GIGA_MAC_VER_05)) {
2840 desc->opts2 = 0; 2840 desc->opts2 = 0;
2841 cur_rx++; 2841 cur_rx++;
diff --git a/drivers/net/rrunner.c b/drivers/net/rrunner.c
index 73a7e6529ee0..55a590ab1e17 100644
--- a/drivers/net/rrunner.c
+++ b/drivers/net/rrunner.c
@@ -294,7 +294,6 @@ static int rr_reset(struct net_device *dev)
294{ 294{
295 struct rr_private *rrpriv; 295 struct rr_private *rrpriv;
296 struct rr_regs __iomem *regs; 296 struct rr_regs __iomem *regs;
297 struct eeprom *hw = NULL;
298 u32 start_pc; 297 u32 start_pc;
299 int i; 298 int i;
300 299
@@ -381,7 +380,8 @@ static int rr_reset(struct net_device *dev)
381 writel(RBURST_64|WBURST_64, &regs->PciState); 380 writel(RBURST_64|WBURST_64, &regs->PciState);
382 wmb(); 381 wmb();
383 382
384 start_pc = rr_read_eeprom_word(rrpriv, &hw->rncd_info.FwStart); 383 start_pc = rr_read_eeprom_word(rrpriv,
384 offsetof(struct eeprom, rncd_info.FwStart));
385 385
386#if (DEBUG > 1) 386#if (DEBUG > 1)
387 printk("%s: Executing firmware at address 0x%06x\n", 387 printk("%s: Executing firmware at address 0x%06x\n",
@@ -438,12 +438,12 @@ static unsigned int rr_read_eeprom(struct rr_private *rrpriv,
438 * it to our CPU byte-order. 438 * it to our CPU byte-order.
439 */ 439 */
440static u32 rr_read_eeprom_word(struct rr_private *rrpriv, 440static u32 rr_read_eeprom_word(struct rr_private *rrpriv,
441 void * offset) 441 size_t offset)
442{ 442{
443 u32 word; 443 __be32 word;
444 444
445 if ((rr_read_eeprom(rrpriv, (unsigned long)offset, 445 if ((rr_read_eeprom(rrpriv, offset,
446 (char *)&word, 4) == 4)) 446 (unsigned char *)&word, 4) == 4))
447 return be32_to_cpu(word); 447 return be32_to_cpu(word);
448 return 0; 448 return 0;
449} 449}
@@ -510,7 +510,6 @@ static int __devinit rr_init(struct net_device *dev)
510{ 510{
511 struct rr_private *rrpriv; 511 struct rr_private *rrpriv;
512 struct rr_regs __iomem *regs; 512 struct rr_regs __iomem *regs;
513 struct eeprom *hw = NULL;
514 u32 sram_size, rev; 513 u32 sram_size, rev;
515 DECLARE_MAC_BUF(mac); 514 DECLARE_MAC_BUF(mac);
516 515
@@ -545,14 +544,14 @@ static int __devinit rr_init(struct net_device *dev)
545 * other method I've seen. -VAL 544 * other method I've seen. -VAL
546 */ 545 */
547 546
548 *(u16 *)(dev->dev_addr) = 547 *(__be16 *)(dev->dev_addr) =
549 htons(rr_read_eeprom_word(rrpriv, &hw->manf.BoardULA)); 548 htons(rr_read_eeprom_word(rrpriv, offsetof(struct eeprom, manf.BoardULA)));
550 *(u32 *)(dev->dev_addr+2) = 549 *(__be32 *)(dev->dev_addr+2) =
551 htonl(rr_read_eeprom_word(rrpriv, &hw->manf.BoardULA[4])); 550 htonl(rr_read_eeprom_word(rrpriv, offsetof(struct eeprom, manf.BoardULA[4])));
552 551
553 printk(" MAC: %s\n", print_mac(mac, dev->dev_addr)); 552 printk(" MAC: %s\n", print_mac(mac, dev->dev_addr));
554 553
555 sram_size = rr_read_eeprom_word(rrpriv, (void *)8); 554 sram_size = rr_read_eeprom_word(rrpriv, 8);
556 printk(" SRAM size 0x%06x\n", sram_size); 555 printk(" SRAM size 0x%06x\n", sram_size);
557 556
558 return 0; 557 return 0;
@@ -1477,11 +1476,10 @@ static int rr_load_firmware(struct net_device *dev)
1477{ 1476{
1478 struct rr_private *rrpriv; 1477 struct rr_private *rrpriv;
1479 struct rr_regs __iomem *regs; 1478 struct rr_regs __iomem *regs;
1480 unsigned long eptr, segptr; 1479 size_t eptr, segptr;
1481 int i, j; 1480 int i, j;
1482 u32 localctrl, sptr, len, tmp; 1481 u32 localctrl, sptr, len, tmp;
1483 u32 p2len, p2size, nr_seg, revision, io, sram_size; 1482 u32 p2len, p2size, nr_seg, revision, io, sram_size;
1484 struct eeprom *hw = NULL;
1485 1483
1486 rrpriv = netdev_priv(dev); 1484 rrpriv = netdev_priv(dev);
1487 regs = rrpriv->regs; 1485 regs = rrpriv->regs;
@@ -1509,7 +1507,7 @@ static int rr_load_firmware(struct net_device *dev)
1509 */ 1507 */
1510 io = readl(&regs->ExtIo); 1508 io = readl(&regs->ExtIo);
1511 writel(0, &regs->ExtIo); 1509 writel(0, &regs->ExtIo);
1512 sram_size = rr_read_eeprom_word(rrpriv, (void *)8); 1510 sram_size = rr_read_eeprom_word(rrpriv, 8);
1513 1511
1514 for (i = 200; i < sram_size / 4; i++){ 1512 for (i = 200; i < sram_size / 4; i++){
1515 writel(i * 4, &regs->WinBase); 1513 writel(i * 4, &regs->WinBase);
@@ -1520,13 +1518,13 @@ static int rr_load_firmware(struct net_device *dev)
1520 writel(io, &regs->ExtIo); 1518 writel(io, &regs->ExtIo);
1521 mb(); 1519 mb();
1522 1520
1523 eptr = (unsigned long)rr_read_eeprom_word(rrpriv, 1521 eptr = rr_read_eeprom_word(rrpriv,
1524 &hw->rncd_info.AddrRunCodeSegs); 1522 offsetof(struct eeprom, rncd_info.AddrRunCodeSegs));
1525 eptr = ((eptr & 0x1fffff) >> 3); 1523 eptr = ((eptr & 0x1fffff) >> 3);
1526 1524
1527 p2len = rr_read_eeprom_word(rrpriv, (void *)(0x83*4)); 1525 p2len = rr_read_eeprom_word(rrpriv, 0x83*4);
1528 p2len = (p2len << 2); 1526 p2len = (p2len << 2);
1529 p2size = rr_read_eeprom_word(rrpriv, (void *)(0x84*4)); 1527 p2size = rr_read_eeprom_word(rrpriv, 0x84*4);
1530 p2size = ((p2size & 0x1fffff) >> 3); 1528 p2size = ((p2size & 0x1fffff) >> 3);
1531 1529
1532 if ((eptr < p2size) || (eptr > (p2size + p2len))){ 1530 if ((eptr < p2size) || (eptr > (p2size + p2len))){
@@ -1534,7 +1532,8 @@ static int rr_load_firmware(struct net_device *dev)
1534 goto out; 1532 goto out;
1535 } 1533 }
1536 1534
1537 revision = rr_read_eeprom_word(rrpriv, &hw->manf.HeaderFmt); 1535 revision = rr_read_eeprom_word(rrpriv,
1536 offsetof(struct eeprom, manf.HeaderFmt));
1538 1537
1539 if (revision != 1){ 1538 if (revision != 1){
1540 printk("%s: invalid firmware format (%i)\n", 1539 printk("%s: invalid firmware format (%i)\n",
@@ -1542,18 +1541,18 @@ static int rr_load_firmware(struct net_device *dev)
1542 goto out; 1541 goto out;
1543 } 1542 }
1544 1543
1545 nr_seg = rr_read_eeprom_word(rrpriv, (void *)eptr); 1544 nr_seg = rr_read_eeprom_word(rrpriv, eptr);
1546 eptr +=4; 1545 eptr +=4;
1547#if (DEBUG > 1) 1546#if (DEBUG > 1)
1548 printk("%s: nr_seg %i\n", dev->name, nr_seg); 1547 printk("%s: nr_seg %i\n", dev->name, nr_seg);
1549#endif 1548#endif
1550 1549
1551 for (i = 0; i < nr_seg; i++){ 1550 for (i = 0; i < nr_seg; i++){
1552 sptr = rr_read_eeprom_word(rrpriv, (void *)eptr); 1551 sptr = rr_read_eeprom_word(rrpriv, eptr);
1553 eptr += 4; 1552 eptr += 4;
1554 len = rr_read_eeprom_word(rrpriv, (void *)eptr); 1553 len = rr_read_eeprom_word(rrpriv, eptr);
1555 eptr += 4; 1554 eptr += 4;
1556 segptr = (unsigned long)rr_read_eeprom_word(rrpriv, (void *)eptr); 1555 segptr = rr_read_eeprom_word(rrpriv, eptr);
1557 segptr = ((segptr & 0x1fffff) >> 3); 1556 segptr = ((segptr & 0x1fffff) >> 3);
1558 eptr += 4; 1557 eptr += 4;
1559#if (DEBUG > 1) 1558#if (DEBUG > 1)
@@ -1561,7 +1560,7 @@ static int rr_load_firmware(struct net_device *dev)
1561 dev->name, i, sptr, len, segptr); 1560 dev->name, i, sptr, len, segptr);
1562#endif 1561#endif
1563 for (j = 0; j < len; j++){ 1562 for (j = 0; j < len; j++){
1564 tmp = rr_read_eeprom_word(rrpriv, (void *)segptr); 1563 tmp = rr_read_eeprom_word(rrpriv, segptr);
1565 writel(sptr, &regs->WinBase); 1564 writel(sptr, &regs->WinBase);
1566 mb(); 1565 mb();
1567 writel(tmp, &regs->WinData); 1566 writel(tmp, &regs->WinData);
diff --git a/drivers/net/rrunner.h b/drivers/net/rrunner.h
index 6a79825bc8cf..6173f11218df 100644
--- a/drivers/net/rrunner.h
+++ b/drivers/net/rrunner.h
@@ -838,7 +838,7 @@ static unsigned int rr_read_eeprom(struct rr_private *rrpriv,
838 unsigned long offset, 838 unsigned long offset,
839 unsigned char *buf, 839 unsigned char *buf,
840 unsigned long length); 840 unsigned long length);
841static u32 rr_read_eeprom_word(struct rr_private *rrpriv, void * offset); 841static u32 rr_read_eeprom_word(struct rr_private *rrpriv, size_t offset);
842static int rr_load_firmware(struct net_device *dev); 842static int rr_load_firmware(struct net_device *dev);
843static inline void rr_raz_tx(struct rr_private *, struct net_device *); 843static inline void rr_raz_tx(struct rr_private *, struct net_device *);
844static inline void rr_raz_rx(struct rr_private *, struct net_device *); 844static inline void rr_raz_rx(struct rr_private *, struct net_device *);
diff --git a/drivers/net/s2io-regs.h b/drivers/net/s2io-regs.h
index 01f08d726ace..f25264f2638e 100644
--- a/drivers/net/s2io-regs.h
+++ b/drivers/net/s2io-regs.h
@@ -66,6 +66,7 @@ struct XENA_dev_config {
66#define ADAPTER_STATUS_RC_PRC_QUIESCENT vBIT(0xFF,16,8) 66#define ADAPTER_STATUS_RC_PRC_QUIESCENT vBIT(0xFF,16,8)
67#define ADAPTER_STATUS_MC_DRAM_READY s2BIT(24) 67#define ADAPTER_STATUS_MC_DRAM_READY s2BIT(24)
68#define ADAPTER_STATUS_MC_QUEUES_READY s2BIT(25) 68#define ADAPTER_STATUS_MC_QUEUES_READY s2BIT(25)
69#define ADAPTER_STATUS_RIC_RUNNING s2BIT(26)
69#define ADAPTER_STATUS_M_PLL_LOCK s2BIT(30) 70#define ADAPTER_STATUS_M_PLL_LOCK s2BIT(30)
70#define ADAPTER_STATUS_P_PLL_LOCK s2BIT(31) 71#define ADAPTER_STATUS_P_PLL_LOCK s2BIT(31)
71 72
diff --git a/drivers/net/s2io.c b/drivers/net/s2io.c
index 632666706247..9d80f1cf73ac 100644
--- a/drivers/net/s2io.c
+++ b/drivers/net/s2io.c
@@ -84,7 +84,7 @@
84#include "s2io.h" 84#include "s2io.h"
85#include "s2io-regs.h" 85#include "s2io-regs.h"
86 86
87#define DRV_VERSION "2.0.26.6" 87#define DRV_VERSION "2.0.26.10"
88 88
89/* S2io Driver name & version. */ 89/* S2io Driver name & version. */
90static char s2io_driver_name[] = "Neterion"; 90static char s2io_driver_name[] = "Neterion";
@@ -1081,7 +1081,7 @@ static int init_nic(struct s2io_nic *nic)
1081 /* to set the swapper controle on the card */ 1081 /* to set the swapper controle on the card */
1082 if(s2io_set_swapper(nic)) { 1082 if(s2io_set_swapper(nic)) {
1083 DBG_PRINT(ERR_DBG,"ERROR: Setting Swapper failed\n"); 1083 DBG_PRINT(ERR_DBG,"ERROR: Setting Swapper failed\n");
1084 return -1; 1084 return -EIO;
1085 } 1085 }
1086 1086
1087 /* 1087 /*
@@ -1100,6 +1100,20 @@ static int init_nic(struct s2io_nic *nic)
1100 msleep(500); 1100 msleep(500);
1101 val64 = readq(&bar0->sw_reset); 1101 val64 = readq(&bar0->sw_reset);
1102 1102
1103 /* Ensure that it's safe to access registers by checking
1104 * RIC_RUNNING bit is reset. Check is valid only for XframeII.
1105 */
1106 if (nic->device_type == XFRAME_II_DEVICE) {
1107 for (i = 0; i < 50; i++) {
1108 val64 = readq(&bar0->adapter_status);
1109 if (!(val64 & ADAPTER_STATUS_RIC_RUNNING))
1110 break;
1111 msleep(10);
1112 }
1113 if (i == 50)
1114 return -ENODEV;
1115 }
1116
1103 /* Enable Receiving broadcasts */ 1117 /* Enable Receiving broadcasts */
1104 add = &bar0->mac_cfg; 1118 add = &bar0->mac_cfg;
1105 val64 = readq(&bar0->mac_cfg); 1119 val64 = readq(&bar0->mac_cfg);
@@ -1503,7 +1517,7 @@ static int init_nic(struct s2io_nic *nic)
1503 DBG_PRINT(ERR_DBG, "%s: failed rts ds steering", 1517 DBG_PRINT(ERR_DBG, "%s: failed rts ds steering",
1504 dev->name); 1518 dev->name);
1505 DBG_PRINT(ERR_DBG, "set on codepoint %d\n", i); 1519 DBG_PRINT(ERR_DBG, "set on codepoint %d\n", i);
1506 return FAILURE; 1520 return -ENODEV;
1507 } 1521 }
1508 } 1522 }
1509 1523
@@ -1570,7 +1584,7 @@ static int init_nic(struct s2io_nic *nic)
1570 if (time > 10) { 1584 if (time > 10) {
1571 DBG_PRINT(ERR_DBG, "%s: TTI init Failed\n", 1585 DBG_PRINT(ERR_DBG, "%s: TTI init Failed\n",
1572 dev->name); 1586 dev->name);
1573 return -1; 1587 return -ENODEV;
1574 } 1588 }
1575 msleep(50); 1589 msleep(50);
1576 time++; 1590 time++;
@@ -1623,7 +1637,7 @@ static int init_nic(struct s2io_nic *nic)
1623 if (time > 10) { 1637 if (time > 10) {
1624 DBG_PRINT(ERR_DBG, "%s: RTI init Failed\n", 1638 DBG_PRINT(ERR_DBG, "%s: RTI init Failed\n",
1625 dev->name); 1639 dev->name);
1626 return -1; 1640 return -ENODEV;
1627 } 1641 }
1628 time++; 1642 time++;
1629 msleep(50); 1643 msleep(50);
@@ -3723,7 +3737,7 @@ static int s2io_enable_msi_x(struct s2io_nic *nic)
3723} 3737}
3724 3738
3725/* Handle software interrupt used during MSI(X) test */ 3739/* Handle software interrupt used during MSI(X) test */
3726static irqreturn_t __devinit s2io_test_intr(int irq, void *dev_id) 3740static irqreturn_t s2io_test_intr(int irq, void *dev_id)
3727{ 3741{
3728 struct s2io_nic *sp = dev_id; 3742 struct s2io_nic *sp = dev_id;
3729 3743
@@ -3734,7 +3748,7 @@ static irqreturn_t __devinit s2io_test_intr(int irq, void *dev_id)
3734} 3748}
3735 3749
3736/* Test interrupt path by forcing a a software IRQ */ 3750/* Test interrupt path by forcing a a software IRQ */
3737static int __devinit s2io_test_msi(struct s2io_nic *sp) 3751static int s2io_test_msi(struct s2io_nic *sp)
3738{ 3752{
3739 struct pci_dev *pdev = sp->pdev; 3753 struct pci_dev *pdev = sp->pdev;
3740 struct XENA_dev_config __iomem *bar0 = sp->bar0; 3754 struct XENA_dev_config __iomem *bar0 = sp->bar0;
@@ -3914,6 +3928,12 @@ static int s2io_close(struct net_device *dev)
3914{ 3928{
3915 struct s2io_nic *sp = dev->priv; 3929 struct s2io_nic *sp = dev->priv;
3916 3930
3931 /* Return if the device is already closed *
3932 * Can happen when s2io_card_up failed in change_mtu *
3933 */
3934 if (!is_s2io_card_up(sp))
3935 return 0;
3936
3917 netif_stop_queue(dev); 3937 netif_stop_queue(dev);
3918 napi_disable(&sp->napi); 3938 napi_disable(&sp->napi);
3919 /* Reset card, kill tasklet and free Tx and Rx buffers. */ 3939 /* Reset card, kill tasklet and free Tx and Rx buffers. */
@@ -6355,6 +6375,7 @@ static int s2io_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
6355static int s2io_change_mtu(struct net_device *dev, int new_mtu) 6375static int s2io_change_mtu(struct net_device *dev, int new_mtu)
6356{ 6376{
6357 struct s2io_nic *sp = dev->priv; 6377 struct s2io_nic *sp = dev->priv;
6378 int ret = 0;
6358 6379
6359 if ((new_mtu < MIN_MTU) || (new_mtu > S2IO_JUMBO_SIZE)) { 6380 if ((new_mtu < MIN_MTU) || (new_mtu > S2IO_JUMBO_SIZE)) {
6360 DBG_PRINT(ERR_DBG, "%s: MTU size is invalid.\n", 6381 DBG_PRINT(ERR_DBG, "%s: MTU size is invalid.\n",
@@ -6366,9 +6387,11 @@ static int s2io_change_mtu(struct net_device *dev, int new_mtu)
6366 if (netif_running(dev)) { 6387 if (netif_running(dev)) {
6367 s2io_card_down(sp); 6388 s2io_card_down(sp);
6368 netif_stop_queue(dev); 6389 netif_stop_queue(dev);
6369 if (s2io_card_up(sp)) { 6390 ret = s2io_card_up(sp);
6391 if (ret) {
6370 DBG_PRINT(ERR_DBG, "%s: Device bring up failed\n", 6392 DBG_PRINT(ERR_DBG, "%s: Device bring up failed\n",
6371 __FUNCTION__); 6393 __FUNCTION__);
6394 return ret;
6372 } 6395 }
6373 if (netif_queue_stopped(dev)) 6396 if (netif_queue_stopped(dev))
6374 netif_wake_queue(dev); 6397 netif_wake_queue(dev);
@@ -6379,7 +6402,7 @@ static int s2io_change_mtu(struct net_device *dev, int new_mtu)
6379 writeq(vBIT(val64, 2, 14), &bar0->rmac_max_pyld_len); 6402 writeq(vBIT(val64, 2, 14), &bar0->rmac_max_pyld_len);
6380 } 6403 }
6381 6404
6382 return 0; 6405 return ret;
6383} 6406}
6384 6407
6385/** 6408/**
@@ -6777,6 +6800,9 @@ static void do_s2io_card_down(struct s2io_nic * sp, int do_io)
6777 unsigned long flags; 6800 unsigned long flags;
6778 register u64 val64 = 0; 6801 register u64 val64 = 0;
6779 6802
6803 if (!is_s2io_card_up(sp))
6804 return;
6805
6780 del_timer_sync(&sp->alarm_timer); 6806 del_timer_sync(&sp->alarm_timer);
6781 /* If s2io_set_link task is executing, wait till it completes. */ 6807 /* If s2io_set_link task is executing, wait till it completes. */
6782 while (test_and_set_bit(__S2IO_STATE_LINK_TASK, &(sp->state))) { 6808 while (test_and_set_bit(__S2IO_STATE_LINK_TASK, &(sp->state))) {
@@ -6850,11 +6876,13 @@ static int s2io_card_up(struct s2io_nic * sp)
6850 u16 interruptible; 6876 u16 interruptible;
6851 6877
6852 /* Initialize the H/W I/O registers */ 6878 /* Initialize the H/W I/O registers */
6853 if (init_nic(sp) != 0) { 6879 ret = init_nic(sp);
6880 if (ret != 0) {
6854 DBG_PRINT(ERR_DBG, "%s: H/W initialization failed\n", 6881 DBG_PRINT(ERR_DBG, "%s: H/W initialization failed\n",
6855 dev->name); 6882 dev->name);
6856 s2io_reset(sp); 6883 if (ret != -EIO)
6857 return -ENODEV; 6884 s2io_reset(sp);
6885 return ret;
6858 } 6886 }
6859 6887
6860 /* 6888 /*
diff --git a/drivers/net/sis190.c b/drivers/net/sis190.c
index 720088396bb9..7eab072ae792 100644
--- a/drivers/net/sis190.c
+++ b/drivers/net/sis190.c
@@ -474,7 +474,7 @@ static inline void sis190_map_to_asic(struct RxDesc *desc, dma_addr_t mapping,
474static inline void sis190_make_unusable_by_asic(struct RxDesc *desc) 474static inline void sis190_make_unusable_by_asic(struct RxDesc *desc)
475{ 475{
476 desc->PSize = 0x0; 476 desc->PSize = 0x0;
477 desc->addr = 0xdeadbeef; 477 desc->addr = cpu_to_le32(0xdeadbeef);
478 desc->size &= cpu_to_le32(RingEnd); 478 desc->size &= cpu_to_le32(RingEnd);
479 wmb(); 479 wmb();
480 desc->status = 0x0; 480 desc->status = 0x0;
@@ -580,7 +580,7 @@ static int sis190_rx_interrupt(struct net_device *dev,
580 struct RxDesc *desc = tp->RxDescRing + entry; 580 struct RxDesc *desc = tp->RxDescRing + entry;
581 u32 status; 581 u32 status;
582 582
583 if (desc->status & OWNbit) 583 if (le32_to_cpu(desc->status) & OWNbit)
584 break; 584 break;
585 585
586 status = le32_to_cpu(desc->PSize); 586 status = le32_to_cpu(desc->PSize);
@@ -1381,7 +1381,7 @@ out:
1381 return rc; 1381 return rc;
1382} 1382}
1383 1383
1384static void __devexit sis190_mii_remove(struct net_device *dev) 1384static void sis190_mii_remove(struct net_device *dev)
1385{ 1385{
1386 struct sis190_private *tp = netdev_priv(dev); 1386 struct sis190_private *tp = netdev_priv(dev);
1387 1387
@@ -1538,9 +1538,9 @@ static int __devinit sis190_get_mac_addr_from_eeprom(struct pci_dev *pdev,
1538 1538
1539 /* Get MAC address from EEPROM */ 1539 /* Get MAC address from EEPROM */
1540 for (i = 0; i < MAC_ADDR_LEN / 2; i++) { 1540 for (i = 0; i < MAC_ADDR_LEN / 2; i++) {
1541 __le16 w = sis190_read_eeprom(ioaddr, EEPROMMACAddr + i); 1541 u16 w = sis190_read_eeprom(ioaddr, EEPROMMACAddr + i);
1542 1542
1543 ((u16 *)dev->dev_addr)[i] = le16_to_cpu(w); 1543 ((__le16 *)dev->dev_addr)[i] = cpu_to_le16(w);
1544 } 1544 }
1545 1545
1546 sis190_set_rgmii(tp, sis190_read_eeprom(ioaddr, EEPROMInfo)); 1546 sis190_set_rgmii(tp, sis190_read_eeprom(ioaddr, EEPROMInfo));
diff --git a/drivers/net/skge.c b/drivers/net/skge.c
index 6d62250fba07..186eb8ebfda6 100644
--- a/drivers/net/skge.c
+++ b/drivers/net/skge.c
@@ -44,7 +44,7 @@
44#include "skge.h" 44#include "skge.h"
45 45
46#define DRV_NAME "skge" 46#define DRV_NAME "skge"
47#define DRV_VERSION "1.12" 47#define DRV_VERSION "1.13"
48#define PFX DRV_NAME " " 48#define PFX DRV_NAME " "
49 49
50#define DEFAULT_TX_RING_SIZE 128 50#define DEFAULT_TX_RING_SIZE 128
@@ -1095,16 +1095,9 @@ static void xm_link_down(struct skge_hw *hw, int port)
1095{ 1095{
1096 struct net_device *dev = hw->dev[port]; 1096 struct net_device *dev = hw->dev[port];
1097 struct skge_port *skge = netdev_priv(dev); 1097 struct skge_port *skge = netdev_priv(dev);
1098 u16 cmd = xm_read16(hw, port, XM_MMU_CMD);
1099 1098
1100 xm_write16(hw, port, XM_IMSK, XM_IMSK_DISABLE); 1099 xm_write16(hw, port, XM_IMSK, XM_IMSK_DISABLE);
1101 1100
1102 cmd &= ~(XM_MMU_ENA_RX | XM_MMU_ENA_TX);
1103 xm_write16(hw, port, XM_MMU_CMD, cmd);
1104
1105 /* dummy read to ensure writing */
1106 xm_read16(hw, port, XM_MMU_CMD);
1107
1108 if (netif_carrier_ok(dev)) 1101 if (netif_carrier_ok(dev))
1109 skge_link_down(skge); 1102 skge_link_down(skge);
1110} 1103}
@@ -1194,6 +1187,7 @@ static void genesis_init(struct skge_hw *hw)
1194static void genesis_reset(struct skge_hw *hw, int port) 1187static void genesis_reset(struct skge_hw *hw, int port)
1195{ 1188{
1196 const u8 zero[8] = { 0 }; 1189 const u8 zero[8] = { 0 };
1190 u32 reg;
1197 1191
1198 skge_write8(hw, SK_REG(port, GMAC_IRQ_MSK), 0); 1192 skge_write8(hw, SK_REG(port, GMAC_IRQ_MSK), 0);
1199 1193
@@ -1209,6 +1203,11 @@ static void genesis_reset(struct skge_hw *hw, int port)
1209 xm_write16(hw, port, PHY_BCOM_INT_MASK, 0xffff); 1203 xm_write16(hw, port, PHY_BCOM_INT_MASK, 0xffff);
1210 1204
1211 xm_outhash(hw, port, XM_HSM, zero); 1205 xm_outhash(hw, port, XM_HSM, zero);
1206
1207 /* Flush TX and RX fifo */
1208 reg = xm_read32(hw, port, XM_MODE);
1209 xm_write32(hw, port, XM_MODE, reg | XM_MD_FTF);
1210 xm_write32(hw, port, XM_MODE, reg | XM_MD_FRF);
1212} 1211}
1213 1212
1214 1213
@@ -1634,15 +1633,14 @@ static void genesis_mac_init(struct skge_hw *hw, int port)
1634 } 1633 }
1635 xm_write16(hw, port, XM_RX_CMD, r); 1634 xm_write16(hw, port, XM_RX_CMD, r);
1636 1635
1637
1638 /* We want short frames padded to 60 bytes. */ 1636 /* We want short frames padded to 60 bytes. */
1639 xm_write16(hw, port, XM_TX_CMD, XM_TX_AUTO_PAD); 1637 xm_write16(hw, port, XM_TX_CMD, XM_TX_AUTO_PAD);
1640 1638
1641 /* 1639 /* Increase threshold for jumbo frames on dual port */
1642 * Bump up the transmit threshold. This helps hold off transmit 1640 if (hw->ports > 1 && jumbo)
1643 * underruns when we're blasting traffic from both ports at once. 1641 xm_write16(hw, port, XM_TX_THR, 1020);
1644 */ 1642 else
1645 xm_write16(hw, port, XM_TX_THR, 512); 1643 xm_write16(hw, port, XM_TX_THR, 512);
1646 1644
1647 /* 1645 /*
1648 * Enable the reception of all error frames. This is is 1646 * Enable the reception of all error frames. This is is
@@ -1713,7 +1711,13 @@ static void genesis_stop(struct skge_port *skge)
1713{ 1711{
1714 struct skge_hw *hw = skge->hw; 1712 struct skge_hw *hw = skge->hw;
1715 int port = skge->port; 1713 int port = skge->port;
1716 u32 reg; 1714 unsigned retries = 1000;
1715 u16 cmd;
1716
1717 /* Disable Tx and Rx */
1718 cmd = xm_read16(hw, port, XM_MMU_CMD);
1719 cmd &= ~(XM_MMU_ENA_RX | XM_MMU_ENA_TX);
1720 xm_write16(hw, port, XM_MMU_CMD, cmd);
1717 1721
1718 genesis_reset(hw, port); 1722 genesis_reset(hw, port);
1719 1723
@@ -1721,20 +1725,17 @@ static void genesis_stop(struct skge_port *skge)
1721 skge_write16(hw, B3_PA_CTRL, 1725 skge_write16(hw, B3_PA_CTRL,
1722 port == 0 ? PA_CLR_TO_TX1 : PA_CLR_TO_TX2); 1726 port == 0 ? PA_CLR_TO_TX1 : PA_CLR_TO_TX2);
1723 1727
1724 /*
1725 * If the transfer sticks at the MAC the STOP command will not
1726 * terminate if we don't flush the XMAC's transmit FIFO !
1727 */
1728 xm_write32(hw, port, XM_MODE,
1729 xm_read32(hw, port, XM_MODE)|XM_MD_FTF);
1730
1731
1732 /* Reset the MAC */ 1728 /* Reset the MAC */
1733 skge_write16(hw, SK_REG(port, TX_MFF_CTRL1), MFF_SET_MAC_RST); 1729 skge_write16(hw, SK_REG(port, TX_MFF_CTRL1), MFF_CLR_MAC_RST);
1730 do {
1731 skge_write16(hw, SK_REG(port, TX_MFF_CTRL1), MFF_SET_MAC_RST);
1732 if (!(skge_read16(hw, SK_REG(port, TX_MFF_CTRL1)) & MFF_SET_MAC_RST))
1733 break;
1734 } while (--retries > 0);
1734 1735
1735 /* For external PHYs there must be special handling */ 1736 /* For external PHYs there must be special handling */
1736 if (hw->phy_type != SK_PHY_XMAC) { 1737 if (hw->phy_type != SK_PHY_XMAC) {
1737 reg = skge_read32(hw, B2_GP_IO); 1738 u32 reg = skge_read32(hw, B2_GP_IO);
1738 if (port == 0) { 1739 if (port == 0) {
1739 reg |= GP_DIR_0; 1740 reg |= GP_DIR_0;
1740 reg &= ~GP_IO_0; 1741 reg &= ~GP_IO_0;
@@ -1801,11 +1802,6 @@ static void genesis_mac_intr(struct skge_hw *hw, int port)
1801 xm_write32(hw, port, XM_MODE, XM_MD_FTF); 1802 xm_write32(hw, port, XM_MODE, XM_MD_FTF);
1802 ++dev->stats.tx_fifo_errors; 1803 ++dev->stats.tx_fifo_errors;
1803 } 1804 }
1804
1805 if (status & XM_IS_RXF_OV) {
1806 xm_write32(hw, port, XM_MODE, XM_MD_FRF);
1807 ++dev->stats.rx_fifo_errors;
1808 }
1809} 1805}
1810 1806
1811static void genesis_link_up(struct skge_port *skge) 1807static void genesis_link_up(struct skge_port *skge)
@@ -1862,9 +1858,9 @@ static void genesis_link_up(struct skge_port *skge)
1862 1858
1863 xm_write32(hw, port, XM_MODE, mode); 1859 xm_write32(hw, port, XM_MODE, mode);
1864 1860
1865 /* Turn on detection of Tx underrun, Rx overrun */ 1861 /* Turn on detection of Tx underrun */
1866 msk = xm_read16(hw, port, XM_IMSK); 1862 msk = xm_read16(hw, port, XM_IMSK);
1867 msk &= ~(XM_IS_RXF_OV | XM_IS_TXF_UR); 1863 msk &= ~XM_IS_TXF_UR;
1868 xm_write16(hw, port, XM_IMSK, msk); 1864 xm_write16(hw, port, XM_IMSK, msk);
1869 1865
1870 xm_read16(hw, port, XM_ISRC); 1866 xm_read16(hw, port, XM_ISRC);
@@ -2194,9 +2190,12 @@ static void yukon_mac_init(struct skge_hw *hw, int port)
2194 TX_JAM_IPG_VAL(TX_JAM_IPG_DEF) | 2190 TX_JAM_IPG_VAL(TX_JAM_IPG_DEF) |
2195 TX_IPG_JAM_DATA(TX_IPG_JAM_DEF)); 2191 TX_IPG_JAM_DATA(TX_IPG_JAM_DEF));
2196 2192
2197 /* serial mode register */ 2193 /* configure the Serial Mode Register */
2198 reg = GM_SMOD_VLAN_ENA | IPG_DATA_VAL(IPG_DATA_DEF); 2194 reg = DATA_BLIND_VAL(DATA_BLIND_DEF)
2199 if (hw->dev[port]->mtu > 1500) 2195 | GM_SMOD_VLAN_ENA
2196 | IPG_DATA_VAL(IPG_DATA_DEF);
2197
2198 if (hw->dev[port]->mtu > ETH_DATA_LEN)
2200 reg |= GM_SMOD_JUMBO_ENA; 2199 reg |= GM_SMOD_JUMBO_ENA;
2201 2200
2202 gma_write16(hw, port, GM_SERIAL_MODE, reg); 2201 gma_write16(hw, port, GM_SERIAL_MODE, reg);
@@ -2619,8 +2618,8 @@ static int skge_up(struct net_device *dev)
2619 yukon_mac_init(hw, port); 2618 yukon_mac_init(hw, port);
2620 spin_unlock_bh(&hw->phy_lock); 2619 spin_unlock_bh(&hw->phy_lock);
2621 2620
2622 /* Configure RAMbuffers */ 2621 /* Configure RAMbuffers - equally between ports and tx/rx */
2623 chunk = hw->ram_size / ((hw->ports + 1)*2); 2622 chunk = (hw->ram_size - hw->ram_offset) / (hw->ports * 2);
2624 ram_addr = hw->ram_offset + 2 * chunk * port; 2623 ram_addr = hw->ram_offset + 2 * chunk * port;
2625 2624
2626 skge_ramset(hw, rxqaddr[port], ram_addr, chunk); 2625 skge_ramset(hw, rxqaddr[port], ram_addr, chunk);
@@ -2897,11 +2896,7 @@ static void skge_tx_timeout(struct net_device *dev)
2897 2896
2898static int skge_change_mtu(struct net_device *dev, int new_mtu) 2897static int skge_change_mtu(struct net_device *dev, int new_mtu)
2899{ 2898{
2900 struct skge_port *skge = netdev_priv(dev);
2901 struct skge_hw *hw = skge->hw;
2902 int port = skge->port;
2903 int err; 2899 int err;
2904 u16 ctl, reg;
2905 2900
2906 if (new_mtu < ETH_ZLEN || new_mtu > ETH_JUMBO_MTU) 2901 if (new_mtu < ETH_ZLEN || new_mtu > ETH_JUMBO_MTU)
2907 return -EINVAL; 2902 return -EINVAL;
@@ -2911,40 +2906,13 @@ static int skge_change_mtu(struct net_device *dev, int new_mtu)
2911 return 0; 2906 return 0;
2912 } 2907 }
2913 2908
2914 skge_write32(hw, B0_IMSK, 0); 2909 skge_down(dev);
2915 dev->trans_start = jiffies; /* prevent tx timeout */
2916 netif_stop_queue(dev);
2917 napi_disable(&skge->napi);
2918
2919 ctl = gma_read16(hw, port, GM_GP_CTRL);
2920 gma_write16(hw, port, GM_GP_CTRL, ctl & ~GM_GPCR_RX_ENA);
2921
2922 skge_rx_clean(skge);
2923 skge_rx_stop(hw, port);
2924 2910
2925 dev->mtu = new_mtu; 2911 dev->mtu = new_mtu;
2926 2912
2927 reg = GM_SMOD_VLAN_ENA | IPG_DATA_VAL(IPG_DATA_DEF); 2913 err = skge_up(dev);
2928 if (new_mtu > 1500)
2929 reg |= GM_SMOD_JUMBO_ENA;
2930 gma_write16(hw, port, GM_SERIAL_MODE, reg);
2931
2932 skge_write8(hw, RB_ADDR(rxqaddr[port], RB_CTRL), RB_ENA_OP_MD);
2933
2934 err = skge_rx_fill(dev);
2935 wmb();
2936 if (!err)
2937 skge_write8(hw, Q_ADDR(rxqaddr[port], Q_CSR), CSR_START | CSR_IRQ_CL_F);
2938 skge_write32(hw, B0_IMSK, hw->intr_mask);
2939
2940 if (err) 2914 if (err)
2941 dev_close(dev); 2915 dev_close(dev);
2942 else {
2943 gma_write16(hw, port, GM_GP_CTRL, ctl);
2944
2945 napi_enable(&skge->napi);
2946 netif_wake_queue(dev);
2947 }
2948 2916
2949 return err; 2917 return err;
2950} 2918}
diff --git a/drivers/net/sky2.c b/drivers/net/sky2.c
index a2070db725c9..a74fc11a6482 100644
--- a/drivers/net/sky2.c
+++ b/drivers/net/sky2.c
@@ -31,7 +31,6 @@
31#include <linux/etherdevice.h> 31#include <linux/etherdevice.h>
32#include <linux/ethtool.h> 32#include <linux/ethtool.h>
33#include <linux/pci.h> 33#include <linux/pci.h>
34#include <linux/aer.h>
35#include <linux/ip.h> 34#include <linux/ip.h>
36#include <net/ip.h> 35#include <net/ip.h>
37#include <linux/tcp.h> 36#include <linux/tcp.h>
@@ -240,22 +239,21 @@ static void sky2_power_on(struct sky2_hw *hw)
240 sky2_write8(hw, B2_Y2_CLK_GATE, 0); 239 sky2_write8(hw, B2_Y2_CLK_GATE, 0);
241 240
242 if (hw->flags & SKY2_HW_ADV_POWER_CTL) { 241 if (hw->flags & SKY2_HW_ADV_POWER_CTL) {
243 struct pci_dev *pdev = hw->pdev;
244 u32 reg; 242 u32 reg;
245 243
246 pci_write_config_dword(pdev, PCI_DEV_REG3, 0); 244 sky2_pci_write32(hw, PCI_DEV_REG3, 0);
247 245
248 pci_read_config_dword(pdev, PCI_DEV_REG4, &reg); 246 reg = sky2_pci_read32(hw, PCI_DEV_REG4);
249 /* set all bits to 0 except bits 15..12 and 8 */ 247 /* set all bits to 0 except bits 15..12 and 8 */
250 reg &= P_ASPM_CONTROL_MSK; 248 reg &= P_ASPM_CONTROL_MSK;
251 pci_write_config_dword(pdev, PCI_DEV_REG4, reg); 249 sky2_pci_write32(hw, PCI_DEV_REG4, reg);
252 250
253 pci_read_config_dword(pdev, PCI_DEV_REG5, &reg); 251 reg = sky2_pci_read32(hw, PCI_DEV_REG5);
254 /* set all bits to 0 except bits 28 & 27 */ 252 /* set all bits to 0 except bits 28 & 27 */
255 reg &= P_CTL_TIM_VMAIN_AV_MSK; 253 reg &= P_CTL_TIM_VMAIN_AV_MSK;
256 pci_write_config_dword(pdev, PCI_DEV_REG5, reg); 254 sky2_pci_write32(hw, PCI_DEV_REG5, reg);
257 255
258 pci_write_config_dword(pdev, PCI_CFG_REG_1, 0); 256 sky2_pci_write32(hw, PCI_CFG_REG_1, 0);
259 257
260 /* Enable workaround for dev 4.107 on Yukon-Ultra & Extreme */ 258 /* Enable workaround for dev 4.107 on Yukon-Ultra & Extreme */
261 reg = sky2_read32(hw, B2_GP_IO); 259 reg = sky2_read32(hw, B2_GP_IO);
@@ -619,12 +617,11 @@ static void sky2_phy_init(struct sky2_hw *hw, unsigned port)
619 617
620static void sky2_phy_power(struct sky2_hw *hw, unsigned port, int onoff) 618static void sky2_phy_power(struct sky2_hw *hw, unsigned port, int onoff)
621{ 619{
622 struct pci_dev *pdev = hw->pdev;
623 u32 reg1; 620 u32 reg1;
624 static const u32 phy_power[] = { PCI_Y2_PHY1_POWD, PCI_Y2_PHY2_POWD }; 621 static const u32 phy_power[] = { PCI_Y2_PHY1_POWD, PCI_Y2_PHY2_POWD };
625 static const u32 coma_mode[] = { PCI_Y2_PHY1_COMA, PCI_Y2_PHY2_COMA }; 622 static const u32 coma_mode[] = { PCI_Y2_PHY1_COMA, PCI_Y2_PHY2_COMA };
626 623
627 pci_read_config_dword(pdev, PCI_DEV_REG1, &reg1); 624 reg1 = sky2_pci_read32(hw, PCI_DEV_REG1);
628 /* Turn on/off phy power saving */ 625 /* Turn on/off phy power saving */
629 if (onoff) 626 if (onoff)
630 reg1 &= ~phy_power[port]; 627 reg1 &= ~phy_power[port];
@@ -634,8 +631,8 @@ static void sky2_phy_power(struct sky2_hw *hw, unsigned port, int onoff)
634 if (onoff && hw->chip_id == CHIP_ID_YUKON_XL && hw->chip_rev > 1) 631 if (onoff && hw->chip_id == CHIP_ID_YUKON_XL && hw->chip_rev > 1)
635 reg1 |= coma_mode[port]; 632 reg1 |= coma_mode[port];
636 633
637 pci_write_config_dword(pdev, PCI_DEV_REG1, reg1); 634 sky2_pci_write32(hw, PCI_DEV_REG1, reg1);
638 pci_read_config_dword(pdev, PCI_DEV_REG1, &reg1); 635 reg1 = sky2_pci_read32(hw, PCI_DEV_REG1);
639 636
640 udelay(100); 637 udelay(100);
641} 638}
@@ -704,9 +701,9 @@ static void sky2_wol_init(struct sky2_port *sky2)
704 sky2_write16(hw, WOL_REGS(port, WOL_CTRL_STAT), ctrl); 701 sky2_write16(hw, WOL_REGS(port, WOL_CTRL_STAT), ctrl);
705 702
706 /* Turn on legacy PCI-Express PME mode */ 703 /* Turn on legacy PCI-Express PME mode */
707 pci_read_config_dword(hw->pdev, PCI_DEV_REG1, &reg1); 704 reg1 = sky2_pci_read32(hw, PCI_DEV_REG1);
708 reg1 |= PCI_Y2_PME_LEGACY; 705 reg1 |= PCI_Y2_PME_LEGACY;
709 pci_write_config_dword(hw->pdev, PCI_DEV_REG1, reg1); 706 sky2_pci_write32(hw, PCI_DEV_REG1, reg1);
710 707
711 /* block receiver */ 708 /* block receiver */
712 sky2_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_RST_SET); 709 sky2_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_RST_SET);
@@ -825,8 +822,13 @@ static void sky2_mac_init(struct sky2_hw *hw, unsigned port)
825 822
826 sky2_write32(hw, SK_REG(port, RX_GMF_CTRL_T), rx_reg); 823 sky2_write32(hw, SK_REG(port, RX_GMF_CTRL_T), rx_reg);
827 824
828 /* Flush Rx MAC FIFO on any flow control or error */ 825 if (hw->chip_id == CHIP_ID_YUKON_XL) {
829 sky2_write16(hw, SK_REG(port, RX_GMF_FL_MSK), GMR_FS_ANY_ERR); 826 /* Hardware errata - clear flush mask */
827 sky2_write16(hw, SK_REG(port, RX_GMF_FL_MSK), 0);
828 } else {
829 /* Flush Rx MAC FIFO on any flow control or error */
830 sky2_write16(hw, SK_REG(port, RX_GMF_FL_MSK), GMR_FS_ANY_ERR);
831 }
830 832
831 /* Set threshold to 0xa (64 bytes) + 1 to workaround pause bug */ 833 /* Set threshold to 0xa (64 bytes) + 1 to workaround pause bug */
832 reg = RX_GMF_FL_THR_DEF + 1; 834 reg = RX_GMF_FL_THR_DEF + 1;
@@ -848,6 +850,13 @@ static void sky2_mac_init(struct sky2_hw *hw, unsigned port)
848 sky2_set_tx_stfwd(hw, port); 850 sky2_set_tx_stfwd(hw, port);
849 } 851 }
850 852
853 if (hw->chip_id == CHIP_ID_YUKON_FE_P &&
854 hw->chip_rev == CHIP_REV_YU_FE2_A0) {
855 /* disable dynamic watermark */
856 reg = sky2_read16(hw, SK_REG(port, TX_GMF_EA));
857 reg &= ~TX_DYN_WM_ENA;
858 sky2_write16(hw, SK_REG(port, TX_GMF_EA), reg);
859 }
851} 860}
852 861
853/* Assign Ram Buffer allocation to queue */ 862/* Assign Ram Buffer allocation to queue */
@@ -1320,15 +1329,12 @@ static int sky2_up(struct net_device *dev)
1320 */ 1329 */
1321 if (otherdev && netif_running(otherdev) && 1330 if (otherdev && netif_running(otherdev) &&
1322 (cap = pci_find_capability(hw->pdev, PCI_CAP_ID_PCIX))) { 1331 (cap = pci_find_capability(hw->pdev, PCI_CAP_ID_PCIX))) {
1323 struct sky2_port *osky2 = netdev_priv(otherdev);
1324 u16 cmd; 1332 u16 cmd;
1325 1333
1326 pci_read_config_word(hw->pdev, cap + PCI_X_CMD, &cmd); 1334 cmd = sky2_pci_read16(hw, cap + PCI_X_CMD);
1327 cmd &= ~PCI_X_CMD_MAX_SPLIT; 1335 cmd &= ~PCI_X_CMD_MAX_SPLIT;
1328 pci_write_config_word(hw->pdev, cap + PCI_X_CMD, cmd); 1336 sky2_pci_write16(hw, cap + PCI_X_CMD, cmd);
1329 1337
1330 sky2->rx_csum = 0;
1331 osky2->rx_csum = 0;
1332 } 1338 }
1333 1339
1334 if (netif_msg_ifup(sky2)) 1340 if (netif_msg_ifup(sky2))
@@ -2426,37 +2432,26 @@ static void sky2_hw_intr(struct sky2_hw *hw)
2426 if (status & (Y2_IS_MST_ERR | Y2_IS_IRQ_STAT)) { 2432 if (status & (Y2_IS_MST_ERR | Y2_IS_IRQ_STAT)) {
2427 u16 pci_err; 2433 u16 pci_err;
2428 2434
2429 pci_read_config_word(pdev, PCI_STATUS, &pci_err); 2435 pci_err = sky2_pci_read16(hw, PCI_STATUS);
2430 if (net_ratelimit()) 2436 if (net_ratelimit())
2431 dev_err(&pdev->dev, "PCI hardware error (0x%x)\n", 2437 dev_err(&pdev->dev, "PCI hardware error (0x%x)\n",
2432 pci_err); 2438 pci_err);
2433 2439
2434 pci_write_config_word(pdev, PCI_STATUS, 2440 sky2_pci_write16(hw, PCI_STATUS,
2435 pci_err | PCI_STATUS_ERROR_BITS); 2441 pci_err | PCI_STATUS_ERROR_BITS);
2436 } 2442 }
2437 2443
2438 if (status & Y2_IS_PCI_EXP) { 2444 if (status & Y2_IS_PCI_EXP) {
2439 /* PCI-Express uncorrectable Error occurred */ 2445 /* PCI-Express uncorrectable Error occurred */
2440 int aer = pci_find_aer_capability(hw->pdev);
2441 u32 err; 2446 u32 err;
2442 2447
2443 if (aer) { 2448 err = sky2_read32(hw, Y2_CFG_AER + PCI_ERR_UNCOR_STATUS);
2444 pci_read_config_dword(pdev, aer + PCI_ERR_UNCOR_STATUS, 2449 sky2_write32(hw, Y2_CFG_AER + PCI_ERR_UNCOR_STATUS,
2445 &err); 2450 0xfffffffful);
2446 pci_cleanup_aer_uncorrect_error_status(pdev);
2447 } else {
2448 /* Either AER not configured, or not working
2449 * because of bad MMCONFIG, so just do recover
2450 * manually.
2451 */
2452 err = sky2_read32(hw, Y2_CFG_AER + PCI_ERR_UNCOR_STATUS);
2453 sky2_write32(hw, Y2_CFG_AER + PCI_ERR_UNCOR_STATUS,
2454 0xfffffffful);
2455 }
2456
2457 if (net_ratelimit()) 2451 if (net_ratelimit())
2458 dev_err(&pdev->dev, "PCI Express error (0x%x)\n", err); 2452 dev_err(&pdev->dev, "PCI Express error (0x%x)\n", err);
2459 2453
2454 sky2_read32(hw, Y2_CFG_AER + PCI_ERR_UNCOR_STATUS);
2460 } 2455 }
2461 2456
2462 if (status & Y2_HWE_L1_MASK) 2457 if (status & Y2_HWE_L1_MASK)
@@ -2703,13 +2698,10 @@ static inline u32 sky2_clk2us(const struct sky2_hw *hw, u32 clk)
2703 2698
2704static int __devinit sky2_init(struct sky2_hw *hw) 2699static int __devinit sky2_init(struct sky2_hw *hw)
2705{ 2700{
2706 int rc;
2707 u8 t8; 2701 u8 t8;
2708 2702
2709 /* Enable all clocks and check for bad PCI access */ 2703 /* Enable all clocks and check for bad PCI access */
2710 rc = pci_write_config_dword(hw->pdev, PCI_DEV_REG3, 0); 2704 sky2_pci_write32(hw, PCI_DEV_REG3, 0);
2711 if (rc)
2712 return rc;
2713 2705
2714 sky2_write8(hw, B0_CTST, CS_RST_CLR); 2706 sky2_write8(hw, B0_CTST, CS_RST_CLR);
2715 2707
@@ -2806,32 +2798,21 @@ static void sky2_reset(struct sky2_hw *hw)
2806 sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON); 2798 sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON);
2807 2799
2808 /* clear PCI errors, if any */ 2800 /* clear PCI errors, if any */
2809 pci_read_config_word(pdev, PCI_STATUS, &status); 2801 status = sky2_pci_read16(hw, PCI_STATUS);
2810 status |= PCI_STATUS_ERROR_BITS; 2802 status |= PCI_STATUS_ERROR_BITS;
2811 pci_write_config_word(pdev, PCI_STATUS, status); 2803 sky2_pci_write16(hw, PCI_STATUS, status);
2812 2804
2813 sky2_write8(hw, B0_CTST, CS_MRST_CLR); 2805 sky2_write8(hw, B0_CTST, CS_MRST_CLR);
2814 2806
2815 cap = pci_find_capability(pdev, PCI_CAP_ID_EXP); 2807 cap = pci_find_capability(pdev, PCI_CAP_ID_EXP);
2816 if (cap) { 2808 if (cap) {
2817 if (pci_find_aer_capability(pdev)) { 2809 sky2_write32(hw, Y2_CFG_AER + PCI_ERR_UNCOR_STATUS,
2818 /* Check for advanced error reporting */ 2810 0xfffffffful);
2819 pci_cleanup_aer_uncorrect_error_status(pdev);
2820 pci_cleanup_aer_correct_error_status(pdev);
2821 } else {
2822 dev_warn(&pdev->dev,
2823 "PCI Express Advanced Error Reporting"
2824 " not configured or MMCONFIG problem?\n");
2825
2826 sky2_write32(hw, Y2_CFG_AER + PCI_ERR_UNCOR_STATUS,
2827 0xfffffffful);
2828 }
2829 2811
2830 /* If error bit is stuck on ignore it */ 2812 /* If error bit is stuck on ignore it */
2831 if (sky2_read32(hw, B0_HWE_ISRC) & Y2_IS_PCI_EXP) 2813 if (sky2_read32(hw, B0_HWE_ISRC) & Y2_IS_PCI_EXP)
2832 dev_info(&pdev->dev, "ignoring stuck error report bit\n"); 2814 dev_info(&pdev->dev, "ignoring stuck error report bit\n");
2833 2815 else
2834 else if (pci_enable_pcie_error_reporting(pdev))
2835 hwe_mask |= Y2_IS_PCI_EXP; 2816 hwe_mask |= Y2_IS_PCI_EXP;
2836 } 2817 }
2837 2818
@@ -2930,16 +2911,14 @@ static void sky2_restart(struct work_struct *work)
2930 int i, err; 2911 int i, err;
2931 2912
2932 rtnl_lock(); 2913 rtnl_lock();
2933 sky2_write32(hw, B0_IMSK, 0);
2934 sky2_read32(hw, B0_IMSK);
2935 napi_disable(&hw->napi);
2936
2937 for (i = 0; i < hw->ports; i++) { 2914 for (i = 0; i < hw->ports; i++) {
2938 dev = hw->dev[i]; 2915 dev = hw->dev[i];
2939 if (netif_running(dev)) 2916 if (netif_running(dev))
2940 sky2_down(dev); 2917 sky2_down(dev);
2941 } 2918 }
2942 2919
2920 napi_disable(&hw->napi);
2921 sky2_write32(hw, B0_IMSK, 0);
2943 sky2_reset(hw); 2922 sky2_reset(hw);
2944 sky2_write32(hw, B0_IMSK, Y2_IS_BASE); 2923 sky2_write32(hw, B0_IMSK, Y2_IS_BASE);
2945 napi_enable(&hw->napi); 2924 napi_enable(&hw->napi);
@@ -3672,32 +3651,33 @@ static int sky2_set_tso(struct net_device *dev, u32 data)
3672static int sky2_get_eeprom_len(struct net_device *dev) 3651static int sky2_get_eeprom_len(struct net_device *dev)
3673{ 3652{
3674 struct sky2_port *sky2 = netdev_priv(dev); 3653 struct sky2_port *sky2 = netdev_priv(dev);
3654 struct sky2_hw *hw = sky2->hw;
3675 u16 reg2; 3655 u16 reg2;
3676 3656
3677 pci_read_config_word(sky2->hw->pdev, PCI_DEV_REG2, &reg2); 3657 reg2 = sky2_pci_read16(hw, PCI_DEV_REG2);
3678 return 1 << ( ((reg2 & PCI_VPD_ROM_SZ) >> 14) + 8); 3658 return 1 << ( ((reg2 & PCI_VPD_ROM_SZ) >> 14) + 8);
3679} 3659}
3680 3660
3681static u32 sky2_vpd_read(struct pci_dev *pdev, int cap, u16 offset) 3661static u32 sky2_vpd_read(struct sky2_hw *hw, int cap, u16 offset)
3682{ 3662{
3683 u32 val; 3663 u32 val;
3684 3664
3685 pci_write_config_word(pdev, cap + PCI_VPD_ADDR, offset); 3665 sky2_pci_write16(hw, cap + PCI_VPD_ADDR, offset);
3686 3666
3687 do { 3667 do {
3688 pci_read_config_word(pdev, cap + PCI_VPD_ADDR, &offset); 3668 offset = sky2_pci_read16(hw, cap + PCI_VPD_ADDR);
3689 } while (!(offset & PCI_VPD_ADDR_F)); 3669 } while (!(offset & PCI_VPD_ADDR_F));
3690 3670
3691 pci_read_config_dword(pdev, cap + PCI_VPD_DATA, &val); 3671 val = sky2_pci_read32(hw, cap + PCI_VPD_DATA);
3692 return val; 3672 return val;
3693} 3673}
3694 3674
3695static void sky2_vpd_write(struct pci_dev *pdev, int cap, u16 offset, u32 val) 3675static void sky2_vpd_write(struct sky2_hw *hw, int cap, u16 offset, u32 val)
3696{ 3676{
3697 pci_write_config_word(pdev, cap + PCI_VPD_DATA, val); 3677 sky2_pci_write16(hw, cap + PCI_VPD_DATA, val);
3698 pci_write_config_dword(pdev, cap + PCI_VPD_ADDR, offset | PCI_VPD_ADDR_F); 3678 sky2_pci_write32(hw, cap + PCI_VPD_ADDR, offset | PCI_VPD_ADDR_F);
3699 do { 3679 do {
3700 pci_read_config_word(pdev, cap + PCI_VPD_ADDR, &offset); 3680 offset = sky2_pci_read16(hw, cap + PCI_VPD_ADDR);
3701 } while (offset & PCI_VPD_ADDR_F); 3681 } while (offset & PCI_VPD_ADDR_F);
3702} 3682}
3703 3683
@@ -3715,7 +3695,7 @@ static int sky2_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom
3715 eeprom->magic = SKY2_EEPROM_MAGIC; 3695 eeprom->magic = SKY2_EEPROM_MAGIC;
3716 3696
3717 while (length > 0) { 3697 while (length > 0) {
3718 u32 val = sky2_vpd_read(sky2->hw->pdev, cap, offset); 3698 u32 val = sky2_vpd_read(sky2->hw, cap, offset);
3719 int n = min_t(int, length, sizeof(val)); 3699 int n = min_t(int, length, sizeof(val));
3720 3700
3721 memcpy(data, &val, n); 3701 memcpy(data, &val, n);
@@ -3745,10 +3725,10 @@ static int sky2_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom
3745 int n = min_t(int, length, sizeof(val)); 3725 int n = min_t(int, length, sizeof(val));
3746 3726
3747 if (n < sizeof(val)) 3727 if (n < sizeof(val))
3748 val = sky2_vpd_read(sky2->hw->pdev, cap, offset); 3728 val = sky2_vpd_read(sky2->hw, cap, offset);
3749 memcpy(&val, data, n); 3729 memcpy(&val, data, n);
3750 3730
3751 sky2_vpd_write(sky2->hw->pdev, cap, offset, val); 3731 sky2_vpd_write(sky2->hw, cap, offset, val);
3752 3732
3753 length -= n; 3733 length -= n;
3754 data += n; 3734 data += n;
@@ -4013,7 +3993,7 @@ static __devinit struct net_device *sky2_init_netdev(struct sky2_hw *hw,
4013 sky2->duplex = -1; 3993 sky2->duplex = -1;
4014 sky2->speed = -1; 3994 sky2->speed = -1;
4015 sky2->advertising = sky2_supported_modes(hw); 3995 sky2->advertising = sky2_supported_modes(hw);
4016 sky2->rx_csum = 1; 3996 sky2->rx_csum = (hw->chip_id != CHIP_ID_YUKON_XL);
4017 sky2->wol = wol; 3997 sky2->wol = wol;
4018 3998
4019 spin_lock_init(&sky2->phy_lock); 3999 spin_lock_init(&sky2->phy_lock);
@@ -4184,9 +4164,9 @@ static int __devinit sky2_probe(struct pci_dev *pdev,
4184 */ 4164 */
4185 { 4165 {
4186 u32 reg; 4166 u32 reg;
4187 pci_read_config_dword(pdev,PCI_DEV_REG2, &reg); 4167 reg = sky2_pci_read32(hw, PCI_DEV_REG2);
4188 reg &= ~PCI_REV_DESC; 4168 reg &= ~PCI_REV_DESC;
4189 pci_write_config_dword(pdev, PCI_DEV_REG2, reg); 4169 sky2_pci_write32(hw, PCI_DEV_REG2, reg);
4190 } 4170 }
4191#endif 4171#endif
4192 4172
@@ -4377,7 +4357,7 @@ static int sky2_resume(struct pci_dev *pdev)
4377 if (hw->chip_id == CHIP_ID_YUKON_EX || 4357 if (hw->chip_id == CHIP_ID_YUKON_EX ||
4378 hw->chip_id == CHIP_ID_YUKON_EC_U || 4358 hw->chip_id == CHIP_ID_YUKON_EC_U ||
4379 hw->chip_id == CHIP_ID_YUKON_FE_P) 4359 hw->chip_id == CHIP_ID_YUKON_FE_P)
4380 pci_write_config_dword(pdev, PCI_DEV_REG3, 0); 4360 sky2_pci_write32(hw, PCI_DEV_REG3, 0);
4381 4361
4382 sky2_reset(hw); 4362 sky2_reset(hw);
4383 sky2_write32(hw, B0_IMSK, Y2_IS_BASE); 4363 sky2_write32(hw, B0_IMSK, Y2_IS_BASE);
diff --git a/drivers/net/sky2.h b/drivers/net/sky2.h
index 69525fd7908d..bc646a47edd2 100644
--- a/drivers/net/sky2.h
+++ b/drivers/net/sky2.h
@@ -2128,4 +2128,25 @@ static inline void gma_set_addr(struct sky2_hw *hw, unsigned port, unsigned reg,
2128 gma_write16(hw, port, reg+4,(u16) addr[2] | ((u16) addr[3] << 8)); 2128 gma_write16(hw, port, reg+4,(u16) addr[2] | ((u16) addr[3] << 8));
2129 gma_write16(hw, port, reg+8,(u16) addr[4] | ((u16) addr[5] << 8)); 2129 gma_write16(hw, port, reg+8,(u16) addr[4] | ((u16) addr[5] << 8));
2130} 2130}
2131
2132/* PCI config space access */
2133static inline u32 sky2_pci_read32(const struct sky2_hw *hw, unsigned reg)
2134{
2135 return sky2_read32(hw, Y2_CFG_SPC + reg);
2136}
2137
2138static inline u16 sky2_pci_read16(const struct sky2_hw *hw, unsigned reg)
2139{
2140 return sky2_read16(hw, Y2_CFG_SPC + reg);
2141}
2142
2143static inline void sky2_pci_write32(struct sky2_hw *hw, unsigned reg, u32 val)
2144{
2145 sky2_write32(hw, Y2_CFG_SPC + reg, val);
2146}
2147
2148static inline void sky2_pci_write16(struct sky2_hw *hw, unsigned reg, u16 val)
2149{
2150 sky2_write16(hw, Y2_CFG_SPC + reg, val);
2151}
2131#endif 2152#endif
diff --git a/drivers/net/smc911x.c b/drivers/net/smc911x.c
index dd18af0ce676..76cc1d3adf71 100644
--- a/drivers/net/smc911x.c
+++ b/drivers/net/smc911x.c
@@ -428,7 +428,6 @@ static inline void smc911x_drop_pkt(struct net_device *dev)
428 */ 428 */
429static inline void smc911x_rcv(struct net_device *dev) 429static inline void smc911x_rcv(struct net_device *dev)
430{ 430{
431 struct smc911x_local *lp = netdev_priv(dev);
432 unsigned long ioaddr = dev->base_addr; 431 unsigned long ioaddr = dev->base_addr;
433 unsigned int pkt_len, status; 432 unsigned int pkt_len, status;
434 struct sk_buff *skb; 433 struct sk_buff *skb;
@@ -473,6 +472,7 @@ static inline void smc911x_rcv(struct net_device *dev)
473 skb_put(skb,pkt_len-4); 472 skb_put(skb,pkt_len-4);
474#ifdef SMC_USE_DMA 473#ifdef SMC_USE_DMA
475 { 474 {
475 struct smc911x_local *lp = netdev_priv(dev);
476 unsigned int fifo; 476 unsigned int fifo;
477 /* Lower the FIFO threshold if possible */ 477 /* Lower the FIFO threshold if possible */
478 fifo = SMC_GET_FIFO_INT(); 478 fifo = SMC_GET_FIFO_INT();
@@ -1299,9 +1299,9 @@ smc911x_rx_dma_irq(int dma, void *data)
1299 PRINT_PKT(skb->data, skb->len); 1299 PRINT_PKT(skb->data, skb->len);
1300 dev->last_rx = jiffies; 1300 dev->last_rx = jiffies;
1301 skb->protocol = eth_type_trans(skb, dev); 1301 skb->protocol = eth_type_trans(skb, dev);
1302 netif_rx(skb);
1303 dev->stats.rx_packets++; 1302 dev->stats.rx_packets++;
1304 dev->stats.rx_bytes += skb->len; 1303 dev->stats.rx_bytes += skb->len;
1304 netif_rx(skb);
1305 1305
1306 spin_lock_irqsave(&lp->lock, flags); 1306 spin_lock_irqsave(&lp->lock, flags);
1307 pkts = (SMC_GET_RX_FIFO_INF() & RX_FIFO_INF_RXSUSED_) >> 16; 1307 pkts = (SMC_GET_RX_FIFO_INF() & RX_FIFO_INF_RXSUSED_) >> 16;
@@ -1379,13 +1379,6 @@ static void smc911x_set_multicast_list(struct net_device *dev)
1379 unsigned int multicast_table[2]; 1379 unsigned int multicast_table[2];
1380 unsigned int mcr, update_multicast = 0; 1380 unsigned int mcr, update_multicast = 0;
1381 unsigned long flags; 1381 unsigned long flags;
1382 /* table for flipping the order of 5 bits */
1383 static const unsigned char invert5[] =
1384 {0x00, 0x10, 0x08, 0x18, 0x04, 0x14, 0x0C, 0x1C,
1385 0x02, 0x12, 0x0A, 0x1A, 0x06, 0x16, 0x0E, 0x1E,
1386 0x01, 0x11, 0x09, 0x19, 0x05, 0x15, 0x0D, 0x1D,
1387 0x03, 0x13, 0x0B, 0x1B, 0x07, 0x17, 0x0F, 0x1F};
1388
1389 1382
1390 DBG(SMC_DEBUG_FUNC, "%s: --> %s\n", dev->name, __FUNCTION__); 1383 DBG(SMC_DEBUG_FUNC, "%s: --> %s\n", dev->name, __FUNCTION__);
1391 1384
@@ -1432,7 +1425,7 @@ static void smc911x_set_multicast_list(struct net_device *dev)
1432 1425
1433 cur_addr = dev->mc_list; 1426 cur_addr = dev->mc_list;
1434 for (i = 0; i < dev->mc_count; i++, cur_addr = cur_addr->next) { 1427 for (i = 0; i < dev->mc_count; i++, cur_addr = cur_addr->next) {
1435 int position; 1428 u32 position;
1436 1429
1437 /* do we have a pointer here? */ 1430 /* do we have a pointer here? */
1438 if (!cur_addr) 1431 if (!cur_addr)
@@ -1442,12 +1435,10 @@ static void smc911x_set_multicast_list(struct net_device *dev)
1442 if (!(*cur_addr->dmi_addr & 1)) 1435 if (!(*cur_addr->dmi_addr & 1))
1443 continue; 1436 continue;
1444 1437
1445 /* only use the low order bits */ 1438 /* upper 6 bits are used as hash index */
1446 position = crc32_le(~0, cur_addr->dmi_addr, 6) & 0x3f; 1439 position = ether_crc(ETH_ALEN, cur_addr->dmi_addr)>>26;
1447 1440
1448 /* do some messy swapping to put the bit in the right spot */ 1441 multicast_table[position>>5] |= 1 << (position&0x1f);
1449 multicast_table[invert5[position&0x1F]&0x1] |=
1450 (1<<invert5[(position>>1)&0x1F]);
1451 } 1442 }
1452 1443
1453 /* be sure I get rid of flags I might have set */ 1444 /* be sure I get rid of flags I might have set */
diff --git a/drivers/net/smc911x.h b/drivers/net/smc911x.h
index 16a0edc078fd..7defa63b9c74 100644
--- a/drivers/net/smc911x.h
+++ b/drivers/net/smc911x.h
@@ -37,7 +37,7 @@
37 #define SMC_USE_16BIT 0 37 #define SMC_USE_16BIT 0
38 #define SMC_USE_32BIT 1 38 #define SMC_USE_32BIT 1
39 #define SMC_IRQ_SENSE IRQF_TRIGGER_FALLING 39 #define SMC_IRQ_SENSE IRQF_TRIGGER_FALLING
40#elif CONFIG_SH_MAGIC_PANEL_R2 40#elif defined(CONFIG_SH_MAGIC_PANEL_R2)
41 #define SMC_USE_SH_DMA 0 41 #define SMC_USE_SH_DMA 0
42 #define SMC_USE_16BIT 0 42 #define SMC_USE_16BIT 0
43 #define SMC_USE_32BIT 1 43 #define SMC_USE_32BIT 1
@@ -76,7 +76,7 @@
76 76
77 77
78 78
79#if SMC_USE_PXA_DMA 79#ifdef SMC_USE_PXA_DMA
80#define SMC_USE_DMA 80#define SMC_USE_DMA
81 81
82/* 82/*
diff --git a/drivers/net/smc91x.h b/drivers/net/smc91x.h
index db34e1eb67e9..07b7f7120e37 100644
--- a/drivers/net/smc91x.h
+++ b/drivers/net/smc91x.h
@@ -55,7 +55,7 @@
55#define SMC_insw(a, r, p, l) readsw((a) + (r), p, l) 55#define SMC_insw(a, r, p, l) readsw((a) + (r), p, l)
56#define SMC_outsw(a, r, p, l) writesw((a) + (r), p, l) 56#define SMC_outsw(a, r, p, l) writesw((a) + (r), p, l)
57 57
58#elif defined(CONFIG_BFIN) 58#elif defined(CONFIG_BLACKFIN)
59 59
60#define SMC_IRQ_FLAGS IRQF_TRIGGER_HIGH 60#define SMC_IRQ_FLAGS IRQF_TRIGGER_HIGH
61#define RPC_LSA_DEFAULT RPC_LED_100_10 61#define RPC_LSA_DEFAULT RPC_LED_100_10
diff --git a/drivers/net/starfire.c b/drivers/net/starfire.c
index bcc430bd9e49..6e00dc857afa 100644
--- a/drivers/net/starfire.c
+++ b/drivers/net/starfire.c
@@ -1742,7 +1742,7 @@ static void set_rx_mode(struct net_device *dev)
1742 if (vlan_group_get_device(np->vlgrp, i)) { 1742 if (vlan_group_get_device(np->vlgrp, i)) {
1743 if (vlan_count >= 32) 1743 if (vlan_count >= 32)
1744 break; 1744 break;
1745 writew(cpu_to_be16(i), filter_addr); 1745 writew(i, filter_addr);
1746 filter_addr += 16; 1746 filter_addr += 16;
1747 vlan_count++; 1747 vlan_count++;
1748 } 1748 }
diff --git a/drivers/net/sundance.c b/drivers/net/sundance.c
index ff98f5d597f1..0a6186d4a48e 100644
--- a/drivers/net/sundance.c
+++ b/drivers/net/sundance.c
@@ -340,9 +340,9 @@ enum mac_ctrl1_bits {
340/* Note that using only 32 bit fields simplifies conversion to big-endian 340/* Note that using only 32 bit fields simplifies conversion to big-endian
341 architectures. */ 341 architectures. */
342struct netdev_desc { 342struct netdev_desc {
343 u32 next_desc; 343 __le32 next_desc;
344 u32 status; 344 __le32 status;
345 struct desc_frag { u32 addr, length; } frag[1]; 345 struct desc_frag { __le32 addr, length; } frag[1];
346}; 346};
347 347
348/* Bits in netdev_desc.status */ 348/* Bits in netdev_desc.status */
@@ -495,8 +495,8 @@ static int __devinit sundance_probe1 (struct pci_dev *pdev,
495 goto err_out_res; 495 goto err_out_res;
496 496
497 for (i = 0; i < 3; i++) 497 for (i = 0; i < 3; i++)
498 ((u16 *)dev->dev_addr)[i] = 498 ((__le16 *)dev->dev_addr)[i] =
499 le16_to_cpu(eeprom_read(ioaddr, i + EEPROM_SA_OFFSET)); 499 cpu_to_le16(eeprom_read(ioaddr, i + EEPROM_SA_OFFSET));
500 memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len); 500 memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
501 501
502 dev->base_addr = (unsigned long)ioaddr; 502 dev->base_addr = (unsigned long)ioaddr;
@@ -1090,8 +1090,8 @@ reset_tx (struct net_device *dev)
1090 skb = np->tx_skbuff[i]; 1090 skb = np->tx_skbuff[i];
1091 if (skb) { 1091 if (skb) {
1092 pci_unmap_single(np->pci_dev, 1092 pci_unmap_single(np->pci_dev,
1093 np->tx_ring[i].frag[0].addr, skb->len, 1093 le32_to_cpu(np->tx_ring[i].frag[0].addr),
1094 PCI_DMA_TODEVICE); 1094 skb->len, PCI_DMA_TODEVICE);
1095 if (irq) 1095 if (irq)
1096 dev_kfree_skb_irq (skb); 1096 dev_kfree_skb_irq (skb);
1097 else 1097 else
@@ -1214,7 +1214,7 @@ static irqreturn_t intr_handler(int irq, void *dev_instance)
1214 skb = np->tx_skbuff[entry]; 1214 skb = np->tx_skbuff[entry];
1215 /* Free the original skb. */ 1215 /* Free the original skb. */
1216 pci_unmap_single(np->pci_dev, 1216 pci_unmap_single(np->pci_dev,
1217 np->tx_ring[entry].frag[0].addr, 1217 le32_to_cpu(np->tx_ring[entry].frag[0].addr),
1218 skb->len, PCI_DMA_TODEVICE); 1218 skb->len, PCI_DMA_TODEVICE);
1219 dev_kfree_skb_irq (np->tx_skbuff[entry]); 1219 dev_kfree_skb_irq (np->tx_skbuff[entry]);
1220 np->tx_skbuff[entry] = NULL; 1220 np->tx_skbuff[entry] = NULL;
@@ -1233,7 +1233,7 @@ static irqreturn_t intr_handler(int irq, void *dev_instance)
1233 skb = np->tx_skbuff[entry]; 1233 skb = np->tx_skbuff[entry];
1234 /* Free the original skb. */ 1234 /* Free the original skb. */
1235 pci_unmap_single(np->pci_dev, 1235 pci_unmap_single(np->pci_dev,
1236 np->tx_ring[entry].frag[0].addr, 1236 le32_to_cpu(np->tx_ring[entry].frag[0].addr),
1237 skb->len, PCI_DMA_TODEVICE); 1237 skb->len, PCI_DMA_TODEVICE);
1238 dev_kfree_skb_irq (np->tx_skbuff[entry]); 1238 dev_kfree_skb_irq (np->tx_skbuff[entry]);
1239 np->tx_skbuff[entry] = NULL; 1239 np->tx_skbuff[entry] = NULL;
@@ -1311,19 +1311,19 @@ static void rx_poll(unsigned long data)
1311 && (skb = dev_alloc_skb(pkt_len + 2)) != NULL) { 1311 && (skb = dev_alloc_skb(pkt_len + 2)) != NULL) {
1312 skb_reserve(skb, 2); /* 16 byte align the IP header */ 1312 skb_reserve(skb, 2); /* 16 byte align the IP header */
1313 pci_dma_sync_single_for_cpu(np->pci_dev, 1313 pci_dma_sync_single_for_cpu(np->pci_dev,
1314 desc->frag[0].addr, 1314 le32_to_cpu(desc->frag[0].addr),
1315 np->rx_buf_sz, 1315 np->rx_buf_sz,
1316 PCI_DMA_FROMDEVICE); 1316 PCI_DMA_FROMDEVICE);
1317 1317
1318 skb_copy_to_linear_data(skb, np->rx_skbuff[entry]->data, pkt_len); 1318 skb_copy_to_linear_data(skb, np->rx_skbuff[entry]->data, pkt_len);
1319 pci_dma_sync_single_for_device(np->pci_dev, 1319 pci_dma_sync_single_for_device(np->pci_dev,
1320 desc->frag[0].addr, 1320 le32_to_cpu(desc->frag[0].addr),
1321 np->rx_buf_sz, 1321 np->rx_buf_sz,
1322 PCI_DMA_FROMDEVICE); 1322 PCI_DMA_FROMDEVICE);
1323 skb_put(skb, pkt_len); 1323 skb_put(skb, pkt_len);
1324 } else { 1324 } else {
1325 pci_unmap_single(np->pci_dev, 1325 pci_unmap_single(np->pci_dev,
1326 desc->frag[0].addr, 1326 le32_to_cpu(desc->frag[0].addr),
1327 np->rx_buf_sz, 1327 np->rx_buf_sz,
1328 PCI_DMA_FROMDEVICE); 1328 PCI_DMA_FROMDEVICE);
1329 skb_put(skb = np->rx_skbuff[entry], pkt_len); 1329 skb_put(skb = np->rx_skbuff[entry], pkt_len);
@@ -1709,23 +1709,23 @@ static int netdev_close(struct net_device *dev)
1709 /* Free all the skbuffs in the Rx queue. */ 1709 /* Free all the skbuffs in the Rx queue. */
1710 for (i = 0; i < RX_RING_SIZE; i++) { 1710 for (i = 0; i < RX_RING_SIZE; i++) {
1711 np->rx_ring[i].status = 0; 1711 np->rx_ring[i].status = 0;
1712 np->rx_ring[i].frag[0].addr = 0xBADF00D0; /* An invalid address. */
1713 skb = np->rx_skbuff[i]; 1712 skb = np->rx_skbuff[i];
1714 if (skb) { 1713 if (skb) {
1715 pci_unmap_single(np->pci_dev, 1714 pci_unmap_single(np->pci_dev,
1716 np->rx_ring[i].frag[0].addr, np->rx_buf_sz, 1715 le32_to_cpu(np->rx_ring[i].frag[0].addr),
1717 PCI_DMA_FROMDEVICE); 1716 np->rx_buf_sz, PCI_DMA_FROMDEVICE);
1718 dev_kfree_skb(skb); 1717 dev_kfree_skb(skb);
1719 np->rx_skbuff[i] = NULL; 1718 np->rx_skbuff[i] = NULL;
1720 } 1719 }
1720 np->rx_ring[i].frag[0].addr = cpu_to_le32(0xBADF00D0); /* poison */
1721 } 1721 }
1722 for (i = 0; i < TX_RING_SIZE; i++) { 1722 for (i = 0; i < TX_RING_SIZE; i++) {
1723 np->tx_ring[i].next_desc = 0; 1723 np->tx_ring[i].next_desc = 0;
1724 skb = np->tx_skbuff[i]; 1724 skb = np->tx_skbuff[i];
1725 if (skb) { 1725 if (skb) {
1726 pci_unmap_single(np->pci_dev, 1726 pci_unmap_single(np->pci_dev,
1727 np->tx_ring[i].frag[0].addr, skb->len, 1727 le32_to_cpu(np->tx_ring[i].frag[0].addr),
1728 PCI_DMA_TODEVICE); 1728 skb->len, PCI_DMA_TODEVICE);
1729 dev_kfree_skb(skb); 1729 dev_kfree_skb(skb);
1730 np->tx_skbuff[i] = NULL; 1730 np->tx_skbuff[i] = NULL;
1731 } 1731 }
diff --git a/drivers/net/sungem.c b/drivers/net/sungem.c
index f6fedcc32de1..68872142530b 100644
--- a/drivers/net/sungem.c
+++ b/drivers/net/sungem.c
@@ -2281,14 +2281,12 @@ static void gem_reset_task(struct work_struct *work)
2281 2281
2282 mutex_lock(&gp->pm_mutex); 2282 mutex_lock(&gp->pm_mutex);
2283 2283
2284 napi_disable(&gp->napi); 2284 if (gp->opened)
2285 napi_disable(&gp->napi);
2285 2286
2286 spin_lock_irq(&gp->lock); 2287 spin_lock_irq(&gp->lock);
2287 spin_lock(&gp->tx_lock); 2288 spin_lock(&gp->tx_lock);
2288 2289
2289 if (gp->running == 0)
2290 goto not_running;
2291
2292 if (gp->running) { 2290 if (gp->running) {
2293 netif_stop_queue(gp->dev); 2291 netif_stop_queue(gp->dev);
2294 2292
@@ -2298,13 +2296,14 @@ static void gem_reset_task(struct work_struct *work)
2298 gem_set_link_modes(gp); 2296 gem_set_link_modes(gp);
2299 netif_wake_queue(gp->dev); 2297 netif_wake_queue(gp->dev);
2300 } 2298 }
2301 not_running: 2299
2302 gp->reset_task_pending = 0; 2300 gp->reset_task_pending = 0;
2303 2301
2304 spin_unlock(&gp->tx_lock); 2302 spin_unlock(&gp->tx_lock);
2305 spin_unlock_irq(&gp->lock); 2303 spin_unlock_irq(&gp->lock);
2306 2304
2307 napi_enable(&gp->napi); 2305 if (gp->opened)
2306 napi_enable(&gp->napi);
2308 2307
2309 mutex_unlock(&gp->pm_mutex); 2308 mutex_unlock(&gp->pm_mutex);
2310} 2309}
diff --git a/drivers/net/tg3.c b/drivers/net/tg3.c
index 4942f7d18937..22eb7c8c1a25 100644
--- a/drivers/net/tg3.c
+++ b/drivers/net/tg3.c
@@ -8189,6 +8189,7 @@ static int tg3_get_eeprom_len(struct net_device *dev)
8189} 8189}
8190 8190
8191static int tg3_nvram_read(struct tg3 *tp, u32 offset, u32 *val); 8191static int tg3_nvram_read(struct tg3 *tp, u32 offset, u32 *val);
8192static int tg3_nvram_read_le(struct tg3 *tp, u32 offset, __le32 *val);
8192static int tg3_nvram_read_swab(struct tg3 *tp, u32 offset, u32 *val); 8193static int tg3_nvram_read_swab(struct tg3 *tp, u32 offset, u32 *val);
8193 8194
8194static int tg3_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, u8 *data) 8195static int tg3_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, u8 *data)
@@ -8196,7 +8197,8 @@ static int tg3_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
8196 struct tg3 *tp = netdev_priv(dev); 8197 struct tg3 *tp = netdev_priv(dev);
8197 int ret; 8198 int ret;
8198 u8 *pd; 8199 u8 *pd;
8199 u32 i, offset, len, val, b_offset, b_count; 8200 u32 i, offset, len, b_offset, b_count;
8201 __le32 val;
8200 8202
8201 if (tp->link_config.phy_is_low_power) 8203 if (tp->link_config.phy_is_low_power)
8202 return -EAGAIN; 8204 return -EAGAIN;
@@ -8215,10 +8217,9 @@ static int tg3_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
8215 /* i.e. offset=1 len=2 */ 8217 /* i.e. offset=1 len=2 */
8216 b_count = len; 8218 b_count = len;
8217 } 8219 }
8218 ret = tg3_nvram_read(tp, offset-b_offset, &val); 8220 ret = tg3_nvram_read_le(tp, offset-b_offset, &val);
8219 if (ret) 8221 if (ret)
8220 return ret; 8222 return ret;
8221 val = cpu_to_le32(val);
8222 memcpy(data, ((char*)&val) + b_offset, b_count); 8223 memcpy(data, ((char*)&val) + b_offset, b_count);
8223 len -= b_count; 8224 len -= b_count;
8224 offset += b_count; 8225 offset += b_count;
@@ -8228,12 +8229,11 @@ static int tg3_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
8228 /* read bytes upto the last 4 byte boundary */ 8229 /* read bytes upto the last 4 byte boundary */
8229 pd = &data[eeprom->len]; 8230 pd = &data[eeprom->len];
8230 for (i = 0; i < (len - (len & 3)); i += 4) { 8231 for (i = 0; i < (len - (len & 3)); i += 4) {
8231 ret = tg3_nvram_read(tp, offset + i, &val); 8232 ret = tg3_nvram_read_le(tp, offset + i, &val);
8232 if (ret) { 8233 if (ret) {
8233 eeprom->len += i; 8234 eeprom->len += i;
8234 return ret; 8235 return ret;
8235 } 8236 }
8236 val = cpu_to_le32(val);
8237 memcpy(pd + i, &val, 4); 8237 memcpy(pd + i, &val, 4);
8238 } 8238 }
8239 eeprom->len += i; 8239 eeprom->len += i;
@@ -8243,11 +8243,10 @@ static int tg3_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
8243 pd = &data[eeprom->len]; 8243 pd = &data[eeprom->len];
8244 b_count = len & 3; 8244 b_count = len & 3;
8245 b_offset = offset + len - b_count; 8245 b_offset = offset + len - b_count;
8246 ret = tg3_nvram_read(tp, b_offset, &val); 8246 ret = tg3_nvram_read_le(tp, b_offset, &val);
8247 if (ret) 8247 if (ret)
8248 return ret; 8248 return ret;
8249 val = cpu_to_le32(val); 8249 memcpy(pd, &val, b_count);
8250 memcpy(pd, ((char*)&val), b_count);
8251 eeprom->len += b_count; 8250 eeprom->len += b_count;
8252 } 8251 }
8253 return 0; 8252 return 0;
@@ -8259,8 +8258,9 @@ static int tg3_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
8259{ 8258{
8260 struct tg3 *tp = netdev_priv(dev); 8259 struct tg3 *tp = netdev_priv(dev);
8261 int ret; 8260 int ret;
8262 u32 offset, len, b_offset, odd_len, start, end; 8261 u32 offset, len, b_offset, odd_len;
8263 u8 *buf; 8262 u8 *buf;
8263 __le32 start, end;
8264 8264
8265 if (tp->link_config.phy_is_low_power) 8265 if (tp->link_config.phy_is_low_power)
8266 return -EAGAIN; 8266 return -EAGAIN;
@@ -8273,10 +8273,9 @@ static int tg3_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
8273 8273
8274 if ((b_offset = (offset & 3))) { 8274 if ((b_offset = (offset & 3))) {
8275 /* adjustments to start on required 4 byte boundary */ 8275 /* adjustments to start on required 4 byte boundary */
8276 ret = tg3_nvram_read(tp, offset-b_offset, &start); 8276 ret = tg3_nvram_read_le(tp, offset-b_offset, &start);
8277 if (ret) 8277 if (ret)
8278 return ret; 8278 return ret;
8279 start = cpu_to_le32(start);
8280 len += b_offset; 8279 len += b_offset;
8281 offset &= ~3; 8280 offset &= ~3;
8282 if (len < 4) 8281 if (len < 4)
@@ -8288,10 +8287,9 @@ static int tg3_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
8288 /* adjustments to end on required 4 byte boundary */ 8287 /* adjustments to end on required 4 byte boundary */
8289 odd_len = 1; 8288 odd_len = 1;
8290 len = (len + 3) & ~3; 8289 len = (len + 3) & ~3;
8291 ret = tg3_nvram_read(tp, offset+len-4, &end); 8290 ret = tg3_nvram_read_le(tp, offset+len-4, &end);
8292 if (ret) 8291 if (ret)
8293 return ret; 8292 return ret;
8294 end = cpu_to_le32(end);
8295 } 8293 }
8296 8294
8297 buf = data; 8295 buf = data;
@@ -8734,7 +8732,8 @@ static void tg3_get_ethtool_stats (struct net_device *dev,
8734 8732
8735static int tg3_test_nvram(struct tg3 *tp) 8733static int tg3_test_nvram(struct tg3 *tp)
8736{ 8734{
8737 u32 *buf, csum, magic; 8735 u32 csum, magic;
8736 __le32 *buf;
8738 int i, j, k, err = 0, size; 8737 int i, j, k, err = 0, size;
8739 8738
8740 if (tg3_nvram_read_swab(tp, 0, &magic) != 0) 8739 if (tg3_nvram_read_swab(tp, 0, &magic) != 0)
@@ -8771,21 +8770,19 @@ static int tg3_test_nvram(struct tg3 *tp)
8771 8770
8772 err = -EIO; 8771 err = -EIO;
8773 for (i = 0, j = 0; i < size; i += 4, j++) { 8772 for (i = 0, j = 0; i < size; i += 4, j++) {
8774 u32 val; 8773 if ((err = tg3_nvram_read_le(tp, i, &buf[j])) != 0)
8775
8776 if ((err = tg3_nvram_read(tp, i, &val)) != 0)
8777 break; 8774 break;
8778 buf[j] = cpu_to_le32(val);
8779 } 8775 }
8780 if (i < size) 8776 if (i < size)
8781 goto out; 8777 goto out;
8782 8778
8783 /* Selfboot format */ 8779 /* Selfboot format */
8784 if ((cpu_to_be32(buf[0]) & TG3_EEPROM_MAGIC_FW_MSK) == 8780 magic = swab32(le32_to_cpu(buf[0]));
8781 if ((magic & TG3_EEPROM_MAGIC_FW_MSK) ==
8785 TG3_EEPROM_MAGIC_FW) { 8782 TG3_EEPROM_MAGIC_FW) {
8786 u8 *buf8 = (u8 *) buf, csum8 = 0; 8783 u8 *buf8 = (u8 *) buf, csum8 = 0;
8787 8784
8788 if ((cpu_to_be32(buf[0]) & TG3_EEPROM_SB_REVISION_MASK) == 8785 if ((magic & TG3_EEPROM_SB_REVISION_MASK) ==
8789 TG3_EEPROM_SB_REVISION_2) { 8786 TG3_EEPROM_SB_REVISION_2) {
8790 /* For rev 2, the csum doesn't include the MBA. */ 8787 /* For rev 2, the csum doesn't include the MBA. */
8791 for (i = 0; i < TG3_EEPROM_SB_F1R2_MBA_OFF; i++) 8788 for (i = 0; i < TG3_EEPROM_SB_F1R2_MBA_OFF; i++)
@@ -8806,7 +8803,7 @@ static int tg3_test_nvram(struct tg3 *tp)
8806 goto out; 8803 goto out;
8807 } 8804 }
8808 8805
8809 if ((cpu_to_be32(buf[0]) & TG3_EEPROM_MAGIC_HW_MSK) == 8806 if ((magic & TG3_EEPROM_MAGIC_HW_MSK) ==
8810 TG3_EEPROM_MAGIC_HW) { 8807 TG3_EEPROM_MAGIC_HW) {
8811 u8 data[NVRAM_SELFBOOT_DATA_SIZE]; 8808 u8 data[NVRAM_SELFBOOT_DATA_SIZE];
8812 u8 parity[NVRAM_SELFBOOT_DATA_SIZE]; 8809 u8 parity[NVRAM_SELFBOOT_DATA_SIZE];
@@ -8852,12 +8849,12 @@ static int tg3_test_nvram(struct tg3 *tp)
8852 8849
8853 /* Bootstrap checksum at offset 0x10 */ 8850 /* Bootstrap checksum at offset 0x10 */
8854 csum = calc_crc((unsigned char *) buf, 0x10); 8851 csum = calc_crc((unsigned char *) buf, 0x10);
8855 if(csum != cpu_to_le32(buf[0x10/4])) 8852 if(csum != le32_to_cpu(buf[0x10/4]))
8856 goto out; 8853 goto out;
8857 8854
8858 /* Manufacturing block starts at offset 0x74, checksum at 0xfc */ 8855 /* Manufacturing block starts at offset 0x74, checksum at 0xfc */
8859 csum = calc_crc((unsigned char *) &buf[0x74/4], 0x88); 8856 csum = calc_crc((unsigned char *) &buf[0x74/4], 0x88);
8860 if (csum != cpu_to_le32(buf[0xfc/4])) 8857 if (csum != le32_to_cpu(buf[0xfc/4]))
8861 goto out; 8858 goto out;
8862 8859
8863 err = 0; 8860 err = 0;
@@ -10171,6 +10168,15 @@ static int tg3_nvram_read(struct tg3 *tp, u32 offset, u32 *val)
10171 return ret; 10168 return ret;
10172} 10169}
10173 10170
10171static int tg3_nvram_read_le(struct tg3 *tp, u32 offset, __le32 *val)
10172{
10173 u32 v;
10174 int res = tg3_nvram_read(tp, offset, &v);
10175 if (!res)
10176 *val = cpu_to_le32(v);
10177 return res;
10178}
10179
10174static int tg3_nvram_read_swab(struct tg3 *tp, u32 offset, u32 *val) 10180static int tg3_nvram_read_swab(struct tg3 *tp, u32 offset, u32 *val)
10175{ 10181{
10176 int err; 10182 int err;
@@ -10188,13 +10194,14 @@ static int tg3_nvram_write_block_using_eeprom(struct tg3 *tp,
10188 u32 val; 10194 u32 val;
10189 10195
10190 for (i = 0; i < len; i += 4) { 10196 for (i = 0; i < len; i += 4) {
10191 u32 addr, data; 10197 u32 addr;
10198 __le32 data;
10192 10199
10193 addr = offset + i; 10200 addr = offset + i;
10194 10201
10195 memcpy(&data, buf + i, 4); 10202 memcpy(&data, buf + i, 4);
10196 10203
10197 tw32(GRC_EEPROM_DATA, cpu_to_le32(data)); 10204 tw32(GRC_EEPROM_DATA, le32_to_cpu(data));
10198 10205
10199 val = tr32(GRC_EEPROM_ADDR); 10206 val = tr32(GRC_EEPROM_ADDR);
10200 tw32(GRC_EEPROM_ADDR, val | EEPROM_ADDR_COMPLETE); 10207 tw32(GRC_EEPROM_ADDR, val | EEPROM_ADDR_COMPLETE);
@@ -10244,8 +10251,8 @@ static int tg3_nvram_write_block_unbuffered(struct tg3 *tp, u32 offset, u32 len,
10244 phy_addr = offset & ~pagemask; 10251 phy_addr = offset & ~pagemask;
10245 10252
10246 for (j = 0; j < pagesize; j += 4) { 10253 for (j = 0; j < pagesize; j += 4) {
10247 if ((ret = tg3_nvram_read(tp, phy_addr + j, 10254 if ((ret = tg3_nvram_read_le(tp, phy_addr + j,
10248 (u32 *) (tmp + j)))) 10255 (__le32 *) (tmp + j))))
10249 break; 10256 break;
10250 } 10257 }
10251 if (ret) 10258 if (ret)
@@ -10289,10 +10296,11 @@ static int tg3_nvram_write_block_unbuffered(struct tg3 *tp, u32 offset, u32 len,
10289 break; 10296 break;
10290 10297
10291 for (j = 0; j < pagesize; j += 4) { 10298 for (j = 0; j < pagesize; j += 4) {
10292 u32 data; 10299 __be32 data;
10293 10300
10294 data = *((u32 *) (tmp + j)); 10301 data = *((__be32 *) (tmp + j));
10295 tw32(NVRAM_WRDATA, cpu_to_be32(data)); 10302 /* swab32(le32_to_cpu(data)), actually */
10303 tw32(NVRAM_WRDATA, be32_to_cpu(data));
10296 10304
10297 tw32(NVRAM_ADDR, phy_addr + j); 10305 tw32(NVRAM_ADDR, phy_addr + j);
10298 10306
@@ -10326,10 +10334,11 @@ static int tg3_nvram_write_block_buffered(struct tg3 *tp, u32 offset, u32 len,
10326 int i, ret = 0; 10334 int i, ret = 0;
10327 10335
10328 for (i = 0; i < len; i += 4, offset += 4) { 10336 for (i = 0; i < len; i += 4, offset += 4) {
10329 u32 data, page_off, phy_addr, nvram_cmd; 10337 u32 page_off, phy_addr, nvram_cmd;
10338 __be32 data;
10330 10339
10331 memcpy(&data, buf + i, 4); 10340 memcpy(&data, buf + i, 4);
10332 tw32(NVRAM_WRDATA, cpu_to_be32(data)); 10341 tw32(NVRAM_WRDATA, be32_to_cpu(data));
10333 10342
10334 page_off = offset % tp->nvram_pagesize; 10343 page_off = offset % tp->nvram_pagesize;
10335 10344
@@ -10831,6 +10840,7 @@ static void __devinit tg3_read_partno(struct tg3 *tp)
10831 vpd_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_VPD); 10840 vpd_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_VPD);
10832 for (i = 0; i < 256; i += 4) { 10841 for (i = 0; i < 256; i += 4) {
10833 u32 tmp, j = 0; 10842 u32 tmp, j = 0;
10843 __le32 v;
10834 u16 tmp16; 10844 u16 tmp16;
10835 10845
10836 pci_write_config_word(tp->pdev, vpd_cap + PCI_VPD_ADDR, 10846 pci_write_config_word(tp->pdev, vpd_cap + PCI_VPD_ADDR,
@@ -10847,8 +10857,8 @@ static void __devinit tg3_read_partno(struct tg3 *tp)
10847 10857
10848 pci_read_config_dword(tp->pdev, vpd_cap + PCI_VPD_DATA, 10858 pci_read_config_dword(tp->pdev, vpd_cap + PCI_VPD_DATA,
10849 &tmp); 10859 &tmp);
10850 tmp = cpu_to_le32(tmp); 10860 v = cpu_to_le32(tmp);
10851 memcpy(&vpd_data[i], &tmp, 4); 10861 memcpy(&vpd_data[i], &v, 4);
10852 } 10862 }
10853 } 10863 }
10854 10864
@@ -10941,11 +10951,11 @@ static void __devinit tg3_read_fw_ver(struct tg3 *tp)
10941 10951
10942 offset = offset + ver_offset - start; 10952 offset = offset + ver_offset - start;
10943 for (i = 0; i < 16; i += 4) { 10953 for (i = 0; i < 16; i += 4) {
10944 if (tg3_nvram_read(tp, offset + i, &val)) 10954 __le32 v;
10955 if (tg3_nvram_read_le(tp, offset + i, &v))
10945 return; 10956 return;
10946 10957
10947 val = le32_to_cpu(val); 10958 memcpy(tp->fw_ver + i, &v, 4);
10948 memcpy(tp->fw_ver + i, &val, 4);
10949 } 10959 }
10950 10960
10951 if (!(tp->tg3_flags & TG3_FLAG_ENABLE_ASF) || 10961 if (!(tp->tg3_flags & TG3_FLAG_ENABLE_ASF) ||
@@ -10983,19 +10993,19 @@ static void __devinit tg3_read_fw_ver(struct tg3 *tp)
10983 tp->fw_ver[bcnt++] = ' '; 10993 tp->fw_ver[bcnt++] = ' ';
10984 10994
10985 for (i = 0; i < 4; i++) { 10995 for (i = 0; i < 4; i++) {
10986 if (tg3_nvram_read(tp, offset, &val)) 10996 __le32 v;
10997 if (tg3_nvram_read_le(tp, offset, &v))
10987 return; 10998 return;
10988 10999
10989 val = le32_to_cpu(val); 11000 offset += sizeof(v);
10990 offset += sizeof(val);
10991 11001
10992 if (bcnt > TG3_VER_SIZE - sizeof(val)) { 11002 if (bcnt > TG3_VER_SIZE - sizeof(v)) {
10993 memcpy(&tp->fw_ver[bcnt], &val, TG3_VER_SIZE - bcnt); 11003 memcpy(&tp->fw_ver[bcnt], &v, TG3_VER_SIZE - bcnt);
10994 break; 11004 break;
10995 } 11005 }
10996 11006
10997 memcpy(&tp->fw_ver[bcnt], &val, sizeof(val)); 11007 memcpy(&tp->fw_ver[bcnt], &v, sizeof(v));
10998 bcnt += sizeof(val); 11008 bcnt += sizeof(v);
10999 } 11009 }
11000 11010
11001 tp->fw_ver[TG3_VER_SIZE - 1] = 0; 11011 tp->fw_ver[TG3_VER_SIZE - 1] = 0;
diff --git a/drivers/net/tokenring/3c359.c b/drivers/net/tokenring/3c359.c
index 5d31519a6c67..44a06f8b588f 100644
--- a/drivers/net/tokenring/3c359.c
+++ b/drivers/net/tokenring/3c359.c
@@ -570,7 +570,7 @@ static int xl_open(struct net_device *dev)
570 struct xl_private *xl_priv=netdev_priv(dev); 570 struct xl_private *xl_priv=netdev_priv(dev);
571 u8 __iomem *xl_mmio = xl_priv->xl_mmio ; 571 u8 __iomem *xl_mmio = xl_priv->xl_mmio ;
572 u8 i ; 572 u8 i ;
573 u16 hwaddr[3] ; /* Should be u8[6] but we get word return values */ 573 __le16 hwaddr[3] ; /* Should be u8[6] but we get word return values */
574 int open_err ; 574 int open_err ;
575 575
576 u16 switchsettings, switchsettings_eeprom ; 576 u16 switchsettings, switchsettings_eeprom ;
@@ -580,15 +580,12 @@ static int xl_open(struct net_device *dev)
580 } 580 }
581 581
582 /* 582 /*
583 * Read the information from the EEPROM that we need. I know we 583 * Read the information from the EEPROM that we need.
584 * should use ntohs, but the word gets stored reversed in the 16
585 * bit field anyway and it all works its self out when we memcpy
586 * it into dev->dev_addr.
587 */ 584 */
588 585
589 hwaddr[0] = xl_ee_read(dev,0x10) ; 586 hwaddr[0] = cpu_to_le16(xl_ee_read(dev,0x10));
590 hwaddr[1] = xl_ee_read(dev,0x11) ; 587 hwaddr[1] = cpu_to_le16(xl_ee_read(dev,0x11));
591 hwaddr[2] = xl_ee_read(dev,0x12) ; 588 hwaddr[2] = cpu_to_le16(xl_ee_read(dev,0x12));
592 589
593 /* Ring speed */ 590 /* Ring speed */
594 591
@@ -665,8 +662,8 @@ static int xl_open(struct net_device *dev)
665 break ; 662 break ;
666 663
667 skb->dev = dev ; 664 skb->dev = dev ;
668 xl_priv->xl_rx_ring[i].upfragaddr = pci_map_single(xl_priv->pdev, skb->data,xl_priv->pkt_buf_sz, PCI_DMA_FROMDEVICE) ; 665 xl_priv->xl_rx_ring[i].upfragaddr = cpu_to_le32(pci_map_single(xl_priv->pdev, skb->data,xl_priv->pkt_buf_sz, PCI_DMA_FROMDEVICE));
669 xl_priv->xl_rx_ring[i].upfraglen = xl_priv->pkt_buf_sz | RXUPLASTFRAG; 666 xl_priv->xl_rx_ring[i].upfraglen = cpu_to_le32(xl_priv->pkt_buf_sz) | RXUPLASTFRAG;
670 xl_priv->rx_ring_skb[i] = skb ; 667 xl_priv->rx_ring_skb[i] = skb ;
671 } 668 }
672 669
@@ -680,7 +677,7 @@ static int xl_open(struct net_device *dev)
680 xl_priv->rx_ring_tail = 0 ; 677 xl_priv->rx_ring_tail = 0 ;
681 xl_priv->rx_ring_dma_addr = pci_map_single(xl_priv->pdev,xl_priv->xl_rx_ring, sizeof(struct xl_rx_desc) * XL_RX_RING_SIZE, PCI_DMA_TODEVICE) ; 678 xl_priv->rx_ring_dma_addr = pci_map_single(xl_priv->pdev,xl_priv->xl_rx_ring, sizeof(struct xl_rx_desc) * XL_RX_RING_SIZE, PCI_DMA_TODEVICE) ;
682 for (i=0;i<(xl_priv->rx_ring_no-1);i++) { 679 for (i=0;i<(xl_priv->rx_ring_no-1);i++) {
683 xl_priv->xl_rx_ring[i].upnextptr = xl_priv->rx_ring_dma_addr + (sizeof (struct xl_rx_desc) * (i+1)) ; 680 xl_priv->xl_rx_ring[i].upnextptr = cpu_to_le32(xl_priv->rx_ring_dma_addr + (sizeof (struct xl_rx_desc) * (i+1)));
684 } 681 }
685 xl_priv->xl_rx_ring[i].upnextptr = 0 ; 682 xl_priv->xl_rx_ring[i].upnextptr = 0 ;
686 683
@@ -698,7 +695,7 @@ static int xl_open(struct net_device *dev)
698 * Setup the first dummy DPD entry for polling to start working. 695 * Setup the first dummy DPD entry for polling to start working.
699 */ 696 */
700 697
701 xl_priv->xl_tx_ring[0].framestartheader = TXDPDEMPTY ; 698 xl_priv->xl_tx_ring[0].framestartheader = TXDPDEMPTY;
702 xl_priv->xl_tx_ring[0].buffer = 0 ; 699 xl_priv->xl_tx_ring[0].buffer = 0 ;
703 xl_priv->xl_tx_ring[0].buffer_length = 0 ; 700 xl_priv->xl_tx_ring[0].buffer_length = 0 ;
704 xl_priv->xl_tx_ring[0].dnnextptr = 0 ; 701 xl_priv->xl_tx_ring[0].dnnextptr = 0 ;
@@ -811,17 +808,17 @@ static int xl_open_hw(struct net_device *dev)
811 return open_err ; 808 return open_err ;
812 } else { 809 } else {
813 writel( (MEM_WORD_READ | 0xD0000 | xl_priv->srb) + 8, xl_mmio + MMIO_MAC_ACCESS_CMD) ; 810 writel( (MEM_WORD_READ | 0xD0000 | xl_priv->srb) + 8, xl_mmio + MMIO_MAC_ACCESS_CMD) ;
814 xl_priv->asb = ntohs(readw(xl_mmio + MMIO_MACDATA)) ; 811 xl_priv->asb = swab16(readw(xl_mmio + MMIO_MACDATA)) ;
815 printk(KERN_INFO "%s: Adapter Opened Details: ",dev->name) ; 812 printk(KERN_INFO "%s: Adapter Opened Details: ",dev->name) ;
816 printk("ASB: %04x",xl_priv->asb ) ; 813 printk("ASB: %04x",xl_priv->asb ) ;
817 writel( (MEM_WORD_READ | 0xD0000 | xl_priv->srb) + 10, xl_mmio + MMIO_MAC_ACCESS_CMD) ; 814 writel( (MEM_WORD_READ | 0xD0000 | xl_priv->srb) + 10, xl_mmio + MMIO_MAC_ACCESS_CMD) ;
818 printk(", SRB: %04x",ntohs(readw(xl_mmio + MMIO_MACDATA)) ) ; 815 printk(", SRB: %04x",swab16(readw(xl_mmio + MMIO_MACDATA)) ) ;
819 816
820 writel( (MEM_WORD_READ | 0xD0000 | xl_priv->srb) + 12, xl_mmio + MMIO_MAC_ACCESS_CMD) ; 817 writel( (MEM_WORD_READ | 0xD0000 | xl_priv->srb) + 12, xl_mmio + MMIO_MAC_ACCESS_CMD) ;
821 xl_priv->arb = ntohs(readw(xl_mmio + MMIO_MACDATA)) ; 818 xl_priv->arb = swab16(readw(xl_mmio + MMIO_MACDATA)) ;
822 printk(", ARB: %04x \n",xl_priv->arb ) ; 819 printk(", ARB: %04x \n",xl_priv->arb ) ;
823 writel( (MEM_WORD_READ | 0xD0000 | xl_priv->srb) + 14, xl_mmio + MMIO_MAC_ACCESS_CMD) ; 820 writel( (MEM_WORD_READ | 0xD0000 | xl_priv->srb) + 14, xl_mmio + MMIO_MAC_ACCESS_CMD) ;
824 vsoff = ntohs(readw(xl_mmio + MMIO_MACDATA)) ; 821 vsoff = swab16(readw(xl_mmio + MMIO_MACDATA)) ;
825 822
826 /* 823 /*
827 * Interesting, sending the individual characters directly to printk was causing klogd to use 824 * Interesting, sending the individual characters directly to printk was causing klogd to use
@@ -873,16 +870,15 @@ static int xl_open_hw(struct net_device *dev)
873static void adv_rx_ring(struct net_device *dev) /* Advance rx_ring, cut down on bloat in xl_rx */ 870static void adv_rx_ring(struct net_device *dev) /* Advance rx_ring, cut down on bloat in xl_rx */
874{ 871{
875 struct xl_private *xl_priv=netdev_priv(dev); 872 struct xl_private *xl_priv=netdev_priv(dev);
876 int prev_ring_loc ; 873 int n = xl_priv->rx_ring_tail;
877 874 int prev_ring_loc;
878 prev_ring_loc = (xl_priv->rx_ring_tail + XL_RX_RING_SIZE - 1) & (XL_RX_RING_SIZE - 1); 875
879 xl_priv->xl_rx_ring[prev_ring_loc].upnextptr = xl_priv->rx_ring_dma_addr + (sizeof (struct xl_rx_desc) * xl_priv->rx_ring_tail) ; 876 prev_ring_loc = (n + XL_RX_RING_SIZE - 1) & (XL_RX_RING_SIZE - 1);
880 xl_priv->xl_rx_ring[xl_priv->rx_ring_tail].framestatus = 0 ; 877 xl_priv->xl_rx_ring[prev_ring_loc].upnextptr = cpu_to_le32(xl_priv->rx_ring_dma_addr + (sizeof (struct xl_rx_desc) * n));
881 xl_priv->xl_rx_ring[xl_priv->rx_ring_tail].upnextptr = 0 ; 878 xl_priv->xl_rx_ring[n].framestatus = 0;
882 xl_priv->rx_ring_tail++ ; 879 xl_priv->xl_rx_ring[n].upnextptr = 0;
883 xl_priv->rx_ring_tail &= (XL_RX_RING_SIZE-1) ; 880 xl_priv->rx_ring_tail++;
884 881 xl_priv->rx_ring_tail &= (XL_RX_RING_SIZE-1);
885 return ;
886} 882}
887 883
888static void xl_rx(struct net_device *dev) 884static void xl_rx(struct net_device *dev)
@@ -914,7 +910,7 @@ static void xl_rx(struct net_device *dev)
914 temp_ring_loc &= (XL_RX_RING_SIZE-1) ; 910 temp_ring_loc &= (XL_RX_RING_SIZE-1) ;
915 } 911 }
916 912
917 frame_length = xl_priv->xl_rx_ring[temp_ring_loc].framestatus & 0x7FFF ; 913 frame_length = le32_to_cpu(xl_priv->xl_rx_ring[temp_ring_loc].framestatus) & 0x7FFF;
918 914
919 skb = dev_alloc_skb(frame_length) ; 915 skb = dev_alloc_skb(frame_length) ;
920 916
@@ -931,29 +927,29 @@ static void xl_rx(struct net_device *dev)
931 } 927 }
932 928
933 while (xl_priv->rx_ring_tail != temp_ring_loc) { 929 while (xl_priv->rx_ring_tail != temp_ring_loc) {
934 copy_len = xl_priv->xl_rx_ring[xl_priv->rx_ring_tail].upfraglen & 0x7FFF ; 930 copy_len = le32_to_cpu(xl_priv->xl_rx_ring[xl_priv->rx_ring_tail].upfraglen) & 0x7FFF;
935 frame_length -= copy_len ; 931 frame_length -= copy_len ;
936 pci_dma_sync_single_for_cpu(xl_priv->pdev,xl_priv->xl_rx_ring[xl_priv->rx_ring_tail].upfragaddr,xl_priv->pkt_buf_sz,PCI_DMA_FROMDEVICE) ; 932 pci_dma_sync_single_for_cpu(xl_priv->pdev,le32_to_cpu(xl_priv->xl_rx_ring[xl_priv->rx_ring_tail].upfragaddr),xl_priv->pkt_buf_sz,PCI_DMA_FROMDEVICE);
937 skb_copy_from_linear_data(xl_priv->rx_ring_skb[xl_priv->rx_ring_tail], 933 skb_copy_from_linear_data(xl_priv->rx_ring_skb[xl_priv->rx_ring_tail],
938 skb_put(skb, copy_len), 934 skb_put(skb, copy_len),
939 copy_len); 935 copy_len);
940 pci_dma_sync_single_for_device(xl_priv->pdev,xl_priv->xl_rx_ring[xl_priv->rx_ring_tail].upfragaddr,xl_priv->pkt_buf_sz,PCI_DMA_FROMDEVICE) ; 936 pci_dma_sync_single_for_device(xl_priv->pdev,le32_to_cpu(xl_priv->xl_rx_ring[xl_priv->rx_ring_tail].upfragaddr),xl_priv->pkt_buf_sz,PCI_DMA_FROMDEVICE);
941 adv_rx_ring(dev) ; 937 adv_rx_ring(dev) ;
942 } 938 }
943 939
944 /* Now we have found the last fragment */ 940 /* Now we have found the last fragment */
945 pci_dma_sync_single_for_cpu(xl_priv->pdev,xl_priv->xl_rx_ring[xl_priv->rx_ring_tail].upfragaddr,xl_priv->pkt_buf_sz,PCI_DMA_FROMDEVICE) ; 941 pci_dma_sync_single_for_cpu(xl_priv->pdev,le32_to_cpu(xl_priv->xl_rx_ring[xl_priv->rx_ring_tail].upfragaddr),xl_priv->pkt_buf_sz,PCI_DMA_FROMDEVICE);
946 skb_copy_from_linear_data(xl_priv->rx_ring_skb[xl_priv->rx_ring_tail], 942 skb_copy_from_linear_data(xl_priv->rx_ring_skb[xl_priv->rx_ring_tail],
947 skb_put(skb,copy_len), frame_length); 943 skb_put(skb,copy_len), frame_length);
948/* memcpy(skb_put(skb,frame_length), bus_to_virt(xl_priv->xl_rx_ring[xl_priv->rx_ring_tail].upfragaddr), frame_length) ; */ 944/* memcpy(skb_put(skb,frame_length), bus_to_virt(xl_priv->xl_rx_ring[xl_priv->rx_ring_tail].upfragaddr), frame_length) ; */
949 pci_dma_sync_single_for_device(xl_priv->pdev,xl_priv->xl_rx_ring[xl_priv->rx_ring_tail].upfragaddr,xl_priv->pkt_buf_sz,PCI_DMA_FROMDEVICE) ; 945 pci_dma_sync_single_for_device(xl_priv->pdev,le32_to_cpu(xl_priv->xl_rx_ring[xl_priv->rx_ring_tail].upfragaddr),xl_priv->pkt_buf_sz,PCI_DMA_FROMDEVICE);
950 adv_rx_ring(dev) ; 946 adv_rx_ring(dev) ;
951 skb->protocol = tr_type_trans(skb,dev) ; 947 skb->protocol = tr_type_trans(skb,dev) ;
952 netif_rx(skb) ; 948 netif_rx(skb) ;
953 949
954 } else { /* Single Descriptor Used, simply swap buffers over, fast path */ 950 } else { /* Single Descriptor Used, simply swap buffers over, fast path */
955 951
956 frame_length = xl_priv->xl_rx_ring[xl_priv->rx_ring_tail].framestatus & 0x7FFF ; 952 frame_length = le32_to_cpu(xl_priv->xl_rx_ring[xl_priv->rx_ring_tail].framestatus) & 0x7FFF;
957 953
958 skb = dev_alloc_skb(xl_priv->pkt_buf_sz) ; 954 skb = dev_alloc_skb(xl_priv->pkt_buf_sz) ;
959 955
@@ -966,13 +962,13 @@ static void xl_rx(struct net_device *dev)
966 } 962 }
967 963
968 skb2 = xl_priv->rx_ring_skb[xl_priv->rx_ring_tail] ; 964 skb2 = xl_priv->rx_ring_skb[xl_priv->rx_ring_tail] ;
969 pci_unmap_single(xl_priv->pdev, xl_priv->xl_rx_ring[xl_priv->rx_ring_tail].upfragaddr, xl_priv->pkt_buf_sz,PCI_DMA_FROMDEVICE) ; 965 pci_unmap_single(xl_priv->pdev, le32_to_cpu(xl_priv->xl_rx_ring[xl_priv->rx_ring_tail].upfragaddr), xl_priv->pkt_buf_sz,PCI_DMA_FROMDEVICE) ;
970 skb_put(skb2, frame_length) ; 966 skb_put(skb2, frame_length) ;
971 skb2->protocol = tr_type_trans(skb2,dev) ; 967 skb2->protocol = tr_type_trans(skb2,dev) ;
972 968
973 xl_priv->rx_ring_skb[xl_priv->rx_ring_tail] = skb ; 969 xl_priv->rx_ring_skb[xl_priv->rx_ring_tail] = skb ;
974 xl_priv->xl_rx_ring[xl_priv->rx_ring_tail].upfragaddr = pci_map_single(xl_priv->pdev,skb->data,xl_priv->pkt_buf_sz, PCI_DMA_FROMDEVICE) ; 970 xl_priv->xl_rx_ring[xl_priv->rx_ring_tail].upfragaddr = cpu_to_le32(pci_map_single(xl_priv->pdev,skb->data,xl_priv->pkt_buf_sz, PCI_DMA_FROMDEVICE));
975 xl_priv->xl_rx_ring[xl_priv->rx_ring_tail].upfraglen = xl_priv->pkt_buf_sz | RXUPLASTFRAG ; 971 xl_priv->xl_rx_ring[xl_priv->rx_ring_tail].upfraglen = cpu_to_le32(xl_priv->pkt_buf_sz) | RXUPLASTFRAG;
976 adv_rx_ring(dev) ; 972 adv_rx_ring(dev) ;
977 xl_priv->xl_stats.rx_packets++ ; 973 xl_priv->xl_stats.rx_packets++ ;
978 xl_priv->xl_stats.rx_bytes += frame_length ; 974 xl_priv->xl_stats.rx_bytes += frame_length ;
@@ -1022,7 +1018,7 @@ static void xl_freemem(struct net_device *dev)
1022 1018
1023 for (i=0;i<XL_RX_RING_SIZE;i++) { 1019 for (i=0;i<XL_RX_RING_SIZE;i++) {
1024 dev_kfree_skb_irq(xl_priv->rx_ring_skb[xl_priv->rx_ring_tail]) ; 1020 dev_kfree_skb_irq(xl_priv->rx_ring_skb[xl_priv->rx_ring_tail]) ;
1025 pci_unmap_single(xl_priv->pdev,xl_priv->xl_rx_ring[xl_priv->rx_ring_tail].upfragaddr,xl_priv->pkt_buf_sz, PCI_DMA_FROMDEVICE) ; 1021 pci_unmap_single(xl_priv->pdev,le32_to_cpu(xl_priv->xl_rx_ring[xl_priv->rx_ring_tail].upfragaddr),xl_priv->pkt_buf_sz, PCI_DMA_FROMDEVICE);
1026 xl_priv->rx_ring_tail++ ; 1022 xl_priv->rx_ring_tail++ ;
1027 xl_priv->rx_ring_tail &= XL_RX_RING_SIZE-1; 1023 xl_priv->rx_ring_tail &= XL_RX_RING_SIZE-1;
1028 } 1024 }
@@ -1181,9 +1177,9 @@ static int xl_xmit(struct sk_buff *skb, struct net_device *dev)
1181 1177
1182 txd = &(xl_priv->xl_tx_ring[tx_head]) ; 1178 txd = &(xl_priv->xl_tx_ring[tx_head]) ;
1183 txd->dnnextptr = 0 ; 1179 txd->dnnextptr = 0 ;
1184 txd->framestartheader = skb->len | TXDNINDICATE ; 1180 txd->framestartheader = cpu_to_le32(skb->len) | TXDNINDICATE;
1185 txd->buffer = pci_map_single(xl_priv->pdev, skb->data, skb->len, PCI_DMA_TODEVICE) ; 1181 txd->buffer = cpu_to_le32(pci_map_single(xl_priv->pdev, skb->data, skb->len, PCI_DMA_TODEVICE));
1186 txd->buffer_length = skb->len | TXDNFRAGLAST ; 1182 txd->buffer_length = cpu_to_le32(skb->len) | TXDNFRAGLAST;
1187 xl_priv->tx_ring_skb[tx_head] = skb ; 1183 xl_priv->tx_ring_skb[tx_head] = skb ;
1188 xl_priv->xl_stats.tx_packets++ ; 1184 xl_priv->xl_stats.tx_packets++ ;
1189 xl_priv->xl_stats.tx_bytes += skb->len ; 1185 xl_priv->xl_stats.tx_bytes += skb->len ;
@@ -1199,7 +1195,7 @@ static int xl_xmit(struct sk_buff *skb, struct net_device *dev)
1199 xl_priv->tx_ring_head &= (XL_TX_RING_SIZE - 1) ; 1195 xl_priv->tx_ring_head &= (XL_TX_RING_SIZE - 1) ;
1200 xl_priv->free_ring_entries-- ; 1196 xl_priv->free_ring_entries-- ;
1201 1197
1202 xl_priv->xl_tx_ring[tx_prev].dnnextptr = xl_priv->tx_ring_dma_addr + (sizeof (struct xl_tx_desc) * tx_head) ; 1198 xl_priv->xl_tx_ring[tx_prev].dnnextptr = cpu_to_le32(xl_priv->tx_ring_dma_addr + (sizeof (struct xl_tx_desc) * tx_head));
1203 1199
1204 /* Sneaky, by doing a read on DnListPtr we can force the card to poll on the DnNextPtr */ 1200 /* Sneaky, by doing a read on DnListPtr we can force the card to poll on the DnNextPtr */
1205 /* readl(xl_mmio + MMIO_DNLISTPTR) ; */ 1201 /* readl(xl_mmio + MMIO_DNLISTPTR) ; */
@@ -1237,9 +1233,9 @@ static void xl_dn_comp(struct net_device *dev)
1237 1233
1238 while (xl_priv->xl_tx_ring[xl_priv->tx_ring_tail].framestartheader & TXDNCOMPLETE ) { 1234 while (xl_priv->xl_tx_ring[xl_priv->tx_ring_tail].framestartheader & TXDNCOMPLETE ) {
1239 txd = &(xl_priv->xl_tx_ring[xl_priv->tx_ring_tail]) ; 1235 txd = &(xl_priv->xl_tx_ring[xl_priv->tx_ring_tail]) ;
1240 pci_unmap_single(xl_priv->pdev,txd->buffer, xl_priv->tx_ring_skb[xl_priv->tx_ring_tail]->len, PCI_DMA_TODEVICE) ; 1236 pci_unmap_single(xl_priv->pdev, le32_to_cpu(txd->buffer), xl_priv->tx_ring_skb[xl_priv->tx_ring_tail]->len, PCI_DMA_TODEVICE);
1241 txd->framestartheader = 0 ; 1237 txd->framestartheader = 0 ;
1242 txd->buffer = 0xdeadbeef ; 1238 txd->buffer = cpu_to_le32(0xdeadbeef);
1243 txd->buffer_length = 0 ; 1239 txd->buffer_length = 0 ;
1244 dev_kfree_skb_irq(xl_priv->tx_ring_skb[xl_priv->tx_ring_tail]) ; 1240 dev_kfree_skb_irq(xl_priv->tx_ring_skb[xl_priv->tx_ring_tail]) ;
1245 xl_priv->tx_ring_tail++ ; 1241 xl_priv->tx_ring_tail++ ;
@@ -1507,9 +1503,9 @@ static void xl_arb_cmd(struct net_device *dev)
1507 if (arb_cmd == RING_STATUS_CHANGE) { /* Ring.Status.Change */ 1503 if (arb_cmd == RING_STATUS_CHANGE) { /* Ring.Status.Change */
1508 writel( ( (MEM_WORD_READ | 0xD0000 | xl_priv->arb) + 6), xl_mmio + MMIO_MAC_ACCESS_CMD) ; 1504 writel( ( (MEM_WORD_READ | 0xD0000 | xl_priv->arb) + 6), xl_mmio + MMIO_MAC_ACCESS_CMD) ;
1509 1505
1510 printk(KERN_INFO "%s: Ring Status Change: New Status = %04x\n", dev->name, ntohs(readw(xl_mmio + MMIO_MACDATA) )) ; 1506 printk(KERN_INFO "%s: Ring Status Change: New Status = %04x\n", dev->name, swab16(readw(xl_mmio + MMIO_MACDATA) )) ;
1511 1507
1512 lan_status = ntohs(readw(xl_mmio + MMIO_MACDATA)); 1508 lan_status = swab16(readw(xl_mmio + MMIO_MACDATA));
1513 1509
1514 /* Acknowledge interrupt, this tells nic we are done with the arb */ 1510 /* Acknowledge interrupt, this tells nic we are done with the arb */
1515 writel(ACK_INTERRUPT | ARBCACK | LATCH_ACK, xl_mmio + MMIO_COMMAND) ; 1511 writel(ACK_INTERRUPT | ARBCACK | LATCH_ACK, xl_mmio + MMIO_COMMAND) ;
@@ -1573,7 +1569,7 @@ static void xl_arb_cmd(struct net_device *dev)
1573 printk(KERN_INFO "Received.Data \n") ; 1569 printk(KERN_INFO "Received.Data \n") ;
1574#endif 1570#endif
1575 writel( ((MEM_WORD_READ | 0xD0000 | xl_priv->arb) + 6), xl_mmio + MMIO_MAC_ACCESS_CMD) ; 1571 writel( ((MEM_WORD_READ | 0xD0000 | xl_priv->arb) + 6), xl_mmio + MMIO_MAC_ACCESS_CMD) ;
1576 xl_priv->mac_buffer = ntohs(readw(xl_mmio + MMIO_MACDATA)) ; 1572 xl_priv->mac_buffer = swab16(readw(xl_mmio + MMIO_MACDATA)) ;
1577 1573
1578 /* Now we are going to be really basic here and not do anything 1574 /* Now we are going to be really basic here and not do anything
1579 * with the data at all. The tech docs do not give me enough 1575 * with the data at all. The tech docs do not give me enough
@@ -1634,7 +1630,7 @@ static void xl_asb_cmd(struct net_device *dev)
1634 writeb(0x81, xl_mmio + MMIO_MACDATA) ; 1630 writeb(0x81, xl_mmio + MMIO_MACDATA) ;
1635 1631
1636 writel(MEM_WORD_WRITE | 0xd0000 | xl_priv->asb | 6, xl_mmio + MMIO_MAC_ACCESS_CMD) ; 1632 writel(MEM_WORD_WRITE | 0xd0000 | xl_priv->asb | 6, xl_mmio + MMIO_MAC_ACCESS_CMD) ;
1637 writew(ntohs(xl_priv->mac_buffer), xl_mmio + MMIO_MACDATA) ; 1633 writew(swab16(xl_priv->mac_buffer), xl_mmio + MMIO_MACDATA) ;
1638 1634
1639 xl_wait_misr_flags(dev) ; 1635 xl_wait_misr_flags(dev) ;
1640 1636
diff --git a/drivers/net/tokenring/3c359.h b/drivers/net/tokenring/3c359.h
index 05c860368852..b880cba0f6fd 100644
--- a/drivers/net/tokenring/3c359.h
+++ b/drivers/net/tokenring/3c359.h
@@ -156,19 +156,19 @@
156#define HOSTERRINT (1<<1) 156#define HOSTERRINT (1<<1)
157 157
158/* Receive descriptor bits */ 158/* Receive descriptor bits */
159#define RXOVERRUN (1<<19) 159#define RXOVERRUN cpu_to_le32(1<<19)
160#define RXFC (1<<21) 160#define RXFC cpu_to_le32(1<<21)
161#define RXAR (1<<22) 161#define RXAR cpu_to_le32(1<<22)
162#define RXUPDCOMPLETE (1<<23) 162#define RXUPDCOMPLETE cpu_to_le32(1<<23)
163#define RXUPDFULL (1<<24) 163#define RXUPDFULL cpu_to_le32(1<<24)
164#define RXUPLASTFRAG (1<<31) 164#define RXUPLASTFRAG cpu_to_le32(1<<31)
165 165
166/* Transmit descriptor bits */ 166/* Transmit descriptor bits */
167#define TXDNCOMPLETE (1<<16) 167#define TXDNCOMPLETE cpu_to_le32(1<<16)
168#define TXTXINDICATE (1<<27) 168#define TXTXINDICATE cpu_to_le32(1<<27)
169#define TXDPDEMPTY (1<<29) 169#define TXDPDEMPTY cpu_to_le32(1<<29)
170#define TXDNINDICATE (1<<31) 170#define TXDNINDICATE cpu_to_le32(1<<31)
171#define TXDNFRAGLAST (1<<31) 171#define TXDNFRAGLAST cpu_to_le32(1<<31)
172 172
173/* Interrupts to Acknowledge */ 173/* Interrupts to Acknowledge */
174#define LATCH_ACK 1 174#define LATCH_ACK 1
@@ -232,17 +232,17 @@
232/* 3c359 data structures */ 232/* 3c359 data structures */
233 233
234struct xl_tx_desc { 234struct xl_tx_desc {
235 u32 dnnextptr ; 235 __le32 dnnextptr;
236 u32 framestartheader ; 236 __le32 framestartheader;
237 u32 buffer ; 237 __le32 buffer;
238 u32 buffer_length ; 238 __le32 buffer_length;
239}; 239};
240 240
241struct xl_rx_desc { 241struct xl_rx_desc {
242 u32 upnextptr ; 242 __le32 upnextptr;
243 u32 framestatus ; 243 __le32 framestatus;
244 u32 upfragaddr ; 244 __le32 upfragaddr;
245 u32 upfraglen ; 245 __le32 upfraglen;
246}; 246};
247 247
248struct xl_private { 248struct xl_private {
diff --git a/drivers/net/tulip/dmfe.c b/drivers/net/tulip/dmfe.c
index ca90566d5bcd..b4891caeae5a 100644
--- a/drivers/net/tulip/dmfe.c
+++ b/drivers/net/tulip/dmfe.c
@@ -2118,8 +2118,8 @@ static int dmfe_suspend(struct pci_dev *pci_dev, pm_message_t state)
2118 pci_enable_wake(pci_dev, PCI_D3cold, 1); 2118 pci_enable_wake(pci_dev, PCI_D3cold, 1);
2119 2119
2120 /* Power down device*/ 2120 /* Power down device*/
2121 pci_set_power_state(pci_dev, pci_choose_state (pci_dev,state));
2122 pci_save_state(pci_dev); 2121 pci_save_state(pci_dev);
2122 pci_set_power_state(pci_dev, pci_choose_state (pci_dev, state));
2123 2123
2124 return 0; 2124 return 0;
2125} 2125}
@@ -2129,8 +2129,8 @@ static int dmfe_resume(struct pci_dev *pci_dev)
2129 struct net_device *dev = pci_get_drvdata(pci_dev); 2129 struct net_device *dev = pci_get_drvdata(pci_dev);
2130 u32 tmp; 2130 u32 tmp;
2131 2131
2132 pci_restore_state(pci_dev);
2133 pci_set_power_state(pci_dev, PCI_D0); 2132 pci_set_power_state(pci_dev, PCI_D0);
2133 pci_restore_state(pci_dev);
2134 2134
2135 /* Re-initilize DM910X board */ 2135 /* Re-initilize DM910X board */
2136 dmfe_init_dm910x(dev); 2136 dmfe_init_dm910x(dev);
diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index 1f7644695976..f8b8c71187a0 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -610,7 +610,7 @@ static int tun_chr_ioctl(struct inode *inode, struct file *file,
610 tun->flags &= ~TUN_PERSIST; 610 tun->flags &= ~TUN_PERSIST;
611 611
612 DBG(KERN_INFO "%s: persist %s\n", 612 DBG(KERN_INFO "%s: persist %s\n",
613 tun->dev->name, arg ? "disabled" : "enabled"); 613 tun->dev->name, arg ? "enabled" : "disabled");
614 break; 614 break;
615 615
616 case TUNSETOWNER: 616 case TUNSETOWNER:
diff --git a/drivers/net/typhoon.c b/drivers/net/typhoon.c
index 94ac5869bb18..f50cb520dffb 100644
--- a/drivers/net/typhoon.c
+++ b/drivers/net/typhoon.c
@@ -813,8 +813,7 @@ typhoon_start_tx(struct sk_buff *skb, struct net_device *dev)
813 first_txd->flags = TYPHOON_TX_DESC | TYPHOON_DESC_VALID; 813 first_txd->flags = TYPHOON_TX_DESC | TYPHOON_DESC_VALID;
814 first_txd->numDesc = 0; 814 first_txd->numDesc = 0;
815 first_txd->len = 0; 815 first_txd->len = 0;
816 first_txd->addr = (u64)((unsigned long) skb) & 0xffffffff; 816 first_txd->tx_addr = (u64)((unsigned long) skb);
817 first_txd->addrHi = (u64)((unsigned long) skb) >> 32;
818 first_txd->processFlags = 0; 817 first_txd->processFlags = 0;
819 818
820 if(skb->ip_summed == CHECKSUM_PARTIAL) { 819 if(skb->ip_summed == CHECKSUM_PARTIAL) {
@@ -850,8 +849,8 @@ typhoon_start_tx(struct sk_buff *skb, struct net_device *dev)
850 PCI_DMA_TODEVICE); 849 PCI_DMA_TODEVICE);
851 txd->flags = TYPHOON_FRAG_DESC | TYPHOON_DESC_VALID; 850 txd->flags = TYPHOON_FRAG_DESC | TYPHOON_DESC_VALID;
852 txd->len = cpu_to_le16(skb->len); 851 txd->len = cpu_to_le16(skb->len);
853 txd->addr = cpu_to_le32(skb_dma); 852 txd->frag.addr = cpu_to_le32(skb_dma);
854 txd->addrHi = 0; 853 txd->frag.addrHi = 0;
855 first_txd->numDesc++; 854 first_txd->numDesc++;
856 } else { 855 } else {
857 int i, len; 856 int i, len;
@@ -861,8 +860,8 @@ typhoon_start_tx(struct sk_buff *skb, struct net_device *dev)
861 PCI_DMA_TODEVICE); 860 PCI_DMA_TODEVICE);
862 txd->flags = TYPHOON_FRAG_DESC | TYPHOON_DESC_VALID; 861 txd->flags = TYPHOON_FRAG_DESC | TYPHOON_DESC_VALID;
863 txd->len = cpu_to_le16(len); 862 txd->len = cpu_to_le16(len);
864 txd->addr = cpu_to_le32(skb_dma); 863 txd->frag.addr = cpu_to_le32(skb_dma);
865 txd->addrHi = 0; 864 txd->frag.addrHi = 0;
866 first_txd->numDesc++; 865 first_txd->numDesc++;
867 866
868 for(i = 0; i < skb_shinfo(skb)->nr_frags; i++) { 867 for(i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
@@ -880,8 +879,8 @@ typhoon_start_tx(struct sk_buff *skb, struct net_device *dev)
880 PCI_DMA_TODEVICE); 879 PCI_DMA_TODEVICE);
881 txd->flags = TYPHOON_FRAG_DESC | TYPHOON_DESC_VALID; 880 txd->flags = TYPHOON_FRAG_DESC | TYPHOON_DESC_VALID;
882 txd->len = cpu_to_le16(len); 881 txd->len = cpu_to_le16(len);
883 txd->addr = cpu_to_le32(skb_dma); 882 txd->frag.addr = cpu_to_le32(skb_dma);
884 txd->addrHi = 0; 883 txd->frag.addrHi = 0;
885 first_txd->numDesc++; 884 first_txd->numDesc++;
886 } 885 }
887 } 886 }
@@ -977,12 +976,12 @@ typhoon_do_get_stats(struct typhoon *tp)
977 * ethtool_ops->get_{strings,stats}() 976 * ethtool_ops->get_{strings,stats}()
978 */ 977 */
979 stats->tx_packets = le32_to_cpu(s->txPackets); 978 stats->tx_packets = le32_to_cpu(s->txPackets);
980 stats->tx_bytes = le32_to_cpu(s->txBytes); 979 stats->tx_bytes = le64_to_cpu(s->txBytes);
981 stats->tx_errors = le32_to_cpu(s->txCarrierLost); 980 stats->tx_errors = le32_to_cpu(s->txCarrierLost);
982 stats->tx_carrier_errors = le32_to_cpu(s->txCarrierLost); 981 stats->tx_carrier_errors = le32_to_cpu(s->txCarrierLost);
983 stats->collisions = le32_to_cpu(s->txMultipleCollisions); 982 stats->collisions = le32_to_cpu(s->txMultipleCollisions);
984 stats->rx_packets = le32_to_cpu(s->rxPacketsGood); 983 stats->rx_packets = le32_to_cpu(s->rxPacketsGood);
985 stats->rx_bytes = le32_to_cpu(s->rxBytesGood); 984 stats->rx_bytes = le64_to_cpu(s->rxBytesGood);
986 stats->rx_fifo_errors = le32_to_cpu(s->rxFifoOverruns); 985 stats->rx_fifo_errors = le32_to_cpu(s->rxFifoOverruns);
987 stats->rx_errors = le32_to_cpu(s->rxFifoOverruns) + 986 stats->rx_errors = le32_to_cpu(s->rxFifoOverruns) +
988 le32_to_cpu(s->BadSSD) + le32_to_cpu(s->rxCrcErrors); 987 le32_to_cpu(s->BadSSD) + le32_to_cpu(s->rxCrcErrors);
@@ -1056,7 +1055,7 @@ typhoon_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
1056 if(typhoon_issue_command(tp, 1, &xp_cmd, 3, xp_resp) < 0) { 1055 if(typhoon_issue_command(tp, 1, &xp_cmd, 3, xp_resp) < 0) {
1057 strcpy(info->fw_version, "Unknown runtime"); 1056 strcpy(info->fw_version, "Unknown runtime");
1058 } else { 1057 } else {
1059 u32 sleep_ver = xp_resp[0].parm2; 1058 u32 sleep_ver = le32_to_cpu(xp_resp[0].parm2);
1060 snprintf(info->fw_version, 32, "%02x.%03x.%03x", 1059 snprintf(info->fw_version, 32, "%02x.%03x.%03x",
1061 sleep_ver >> 24, (sleep_ver >> 12) & 0xfff, 1060 sleep_ver >> 24, (sleep_ver >> 12) & 0xfff,
1062 sleep_ver & 0xfff); 1061 sleep_ver & 0xfff);
@@ -1157,7 +1156,7 @@ typhoon_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
1157 } 1156 }
1158 1157
1159 INIT_COMMAND_NO_RESPONSE(&xp_cmd, TYPHOON_CMD_XCVR_SELECT); 1158 INIT_COMMAND_NO_RESPONSE(&xp_cmd, TYPHOON_CMD_XCVR_SELECT);
1160 xp_cmd.parm1 = cpu_to_le16(xcvr); 1159 xp_cmd.parm1 = xcvr;
1161 err = typhoon_issue_command(tp, 1, &xp_cmd, 0, NULL); 1160 err = typhoon_issue_command(tp, 1, &xp_cmd, 0, NULL);
1162 if(err < 0) 1161 if(err < 0)
1163 goto out; 1162 goto out;
@@ -1320,7 +1319,7 @@ typhoon_init_interface(struct typhoon *tp)
1320 tp->txLoRing.writeRegister = TYPHOON_REG_TX_LO_READY; 1319 tp->txLoRing.writeRegister = TYPHOON_REG_TX_LO_READY;
1321 tp->txHiRing.writeRegister = TYPHOON_REG_TX_HI_READY; 1320 tp->txHiRing.writeRegister = TYPHOON_REG_TX_HI_READY;
1322 1321
1323 tp->txlo_dma_addr = iface->txLoAddr; 1322 tp->txlo_dma_addr = le32_to_cpu(iface->txLoAddr);
1324 tp->card_state = Sleeping; 1323 tp->card_state = Sleeping;
1325 smp_wmb(); 1324 smp_wmb();
1326 1325
@@ -1358,7 +1357,7 @@ typhoon_download_firmware(struct typhoon *tp)
1358 u8 *image_data; 1357 u8 *image_data;
1359 void *dpage; 1358 void *dpage;
1360 dma_addr_t dpage_dma; 1359 dma_addr_t dpage_dma;
1361 unsigned int csum; 1360 __sum16 csum;
1362 u32 irqEnabled; 1361 u32 irqEnabled;
1363 u32 irqMasked; 1362 u32 irqMasked;
1364 u32 numSections; 1363 u32 numSections;
@@ -1450,13 +1449,13 @@ typhoon_download_firmware(struct typhoon *tp)
1450 * summing. Fortunately, due to the properties of 1449 * summing. Fortunately, due to the properties of
1451 * the checksum, we can do this once, at the end. 1450 * the checksum, we can do this once, at the end.
1452 */ 1451 */
1453 csum = csum_partial_copy_nocheck(image_data, dpage, 1452 csum = csum_fold(csum_partial_copy_nocheck(image_data,
1454 len, 0); 1453 dpage, len,
1455 csum = csum_fold(csum); 1454 0));
1456 csum = le16_to_cpu(csum);
1457 1455
1458 iowrite32(len, ioaddr + TYPHOON_REG_BOOT_LENGTH); 1456 iowrite32(len, ioaddr + TYPHOON_REG_BOOT_LENGTH);
1459 iowrite32(csum, ioaddr + TYPHOON_REG_BOOT_CHECKSUM); 1457 iowrite32(le16_to_cpu((__force __le16)csum),
1458 ioaddr + TYPHOON_REG_BOOT_CHECKSUM);
1460 iowrite32(load_addr, 1459 iowrite32(load_addr,
1461 ioaddr + TYPHOON_REG_BOOT_DEST_ADDR); 1460 ioaddr + TYPHOON_REG_BOOT_DEST_ADDR);
1462 iowrite32(0, ioaddr + TYPHOON_REG_BOOT_DATA_HI); 1461 iowrite32(0, ioaddr + TYPHOON_REG_BOOT_DATA_HI);
@@ -1551,13 +1550,13 @@ typhoon_clean_tx(struct typhoon *tp, struct transmit_ring *txRing,
1551 if(type == TYPHOON_TX_DESC) { 1550 if(type == TYPHOON_TX_DESC) {
1552 /* This tx_desc describes a packet. 1551 /* This tx_desc describes a packet.
1553 */ 1552 */
1554 unsigned long ptr = tx->addr | ((u64)tx->addrHi << 32); 1553 unsigned long ptr = tx->tx_addr;
1555 struct sk_buff *skb = (struct sk_buff *) ptr; 1554 struct sk_buff *skb = (struct sk_buff *) ptr;
1556 dev_kfree_skb_irq(skb); 1555 dev_kfree_skb_irq(skb);
1557 } else if(type == TYPHOON_FRAG_DESC) { 1556 } else if(type == TYPHOON_FRAG_DESC) {
1558 /* This tx_desc describes a memory mapping. Free it. 1557 /* This tx_desc describes a memory mapping. Free it.
1559 */ 1558 */
1560 skb_dma = (dma_addr_t) le32_to_cpu(tx->addr); 1559 skb_dma = (dma_addr_t) le32_to_cpu(tx->frag.addr);
1561 dma_len = le16_to_cpu(tx->len); 1560 dma_len = le16_to_cpu(tx->len);
1562 pci_unmap_single(tp->pdev, skb_dma, dma_len, 1561 pci_unmap_single(tp->pdev, skb_dma, dma_len,
1563 PCI_DMA_TODEVICE); 1562 PCI_DMA_TODEVICE);
@@ -1596,7 +1595,7 @@ typhoon_recycle_rx_skb(struct typhoon *tp, u32 idx)
1596 struct rx_free *r; 1595 struct rx_free *r;
1597 1596
1598 if((ring->lastWrite + sizeof(*r)) % (RXFREE_ENTRIES * sizeof(*r)) == 1597 if((ring->lastWrite + sizeof(*r)) % (RXFREE_ENTRIES * sizeof(*r)) ==
1599 indexes->rxBuffCleared) { 1598 le32_to_cpu(indexes->rxBuffCleared)) {
1600 /* no room in ring, just drop the skb 1599 /* no room in ring, just drop the skb
1601 */ 1600 */
1602 dev_kfree_skb_any(rxb->skb); 1601 dev_kfree_skb_any(rxb->skb);
@@ -1627,7 +1626,7 @@ typhoon_alloc_rx_skb(struct typhoon *tp, u32 idx)
1627 rxb->skb = NULL; 1626 rxb->skb = NULL;
1628 1627
1629 if((ring->lastWrite + sizeof(*r)) % (RXFREE_ENTRIES * sizeof(*r)) == 1628 if((ring->lastWrite + sizeof(*r)) % (RXFREE_ENTRIES * sizeof(*r)) ==
1630 indexes->rxBuffCleared) 1629 le32_to_cpu(indexes->rxBuffCleared))
1631 return -ENOMEM; 1630 return -ENOMEM;
1632 1631
1633 skb = dev_alloc_skb(PKT_BUF_SZ); 1632 skb = dev_alloc_skb(PKT_BUF_SZ);
diff --git a/drivers/net/typhoon.h b/drivers/net/typhoon.h
index 19df20889b82..dd7022ca7354 100644
--- a/drivers/net/typhoon.h
+++ b/drivers/net/typhoon.h
@@ -73,7 +73,7 @@ struct typhoon_indexes {
73 volatile __le32 txLoCleared; 73 volatile __le32 txLoCleared;
74 volatile __le32 txHiCleared; 74 volatile __le32 txHiCleared;
75 volatile __le32 rxLoReady; 75 volatile __le32 rxLoReady;
76 volatile __u32 rxBuffCleared; /* AV: really? */ 76 volatile __le32 rxBuffCleared;
77 volatile __le32 cmdCleared; 77 volatile __le32 cmdCleared;
78 volatile __le32 respReady; 78 volatile __le32 respReady;
79 volatile __le32 rxHiReady; 79 volatile __le32 rxHiReady;
@@ -166,8 +166,13 @@ struct tx_desc {
166#define TYPHOON_DESC_VALID 0x80 166#define TYPHOON_DESC_VALID 0x80
167 u8 numDesc; 167 u8 numDesc;
168 __le16 len; 168 __le16 len;
169 u32 addr; 169 union {
170 u32 addrHi; 170 struct {
171 __le32 addr;
172 __le32 addrHi;
173 } frag;
174 u64 tx_addr; /* opaque for hardware, for TX_DESC */
175 };
171 __le32 processFlags; 176 __le32 processFlags;
172#define TYPHOON_TX_PF_NO_CRC __constant_cpu_to_le32(0x00000001) 177#define TYPHOON_TX_PF_NO_CRC __constant_cpu_to_le32(0x00000001)
173#define TYPHOON_TX_PF_IP_CHKSUM __constant_cpu_to_le32(0x00000002) 178#define TYPHOON_TX_PF_IP_CHKSUM __constant_cpu_to_le32(0x00000002)
@@ -240,8 +245,8 @@ struct rx_desc {
240 u8 flags; 245 u8 flags;
241 u8 numDesc; 246 u8 numDesc;
242 __le16 frameLen; 247 __le16 frameLen;
243 u32 addr; 248 u32 addr; /* opaque, comes from virtAddr */
244 u32 addrHi; 249 u32 addrHi; /* opaque, comes from virtAddrHi */
245 __le32 rxStatus; 250 __le32 rxStatus;
246#define TYPHOON_RX_ERR_INTERNAL __constant_cpu_to_le32(0x00000000) 251#define TYPHOON_RX_ERR_INTERNAL __constant_cpu_to_le32(0x00000000)
247#define TYPHOON_RX_ERR_FIFO_UNDERRUN __constant_cpu_to_le32(0x00000001) 252#define TYPHOON_RX_ERR_FIFO_UNDERRUN __constant_cpu_to_le32(0x00000001)
diff --git a/drivers/net/ucc_geth.c b/drivers/net/ucc_geth.c
index a3ff270593f1..abac7db3819e 100644
--- a/drivers/net/ucc_geth.c
+++ b/drivers/net/ucc_geth.c
@@ -1460,6 +1460,8 @@ static int adjust_enet_interface(struct ucc_geth_private *ugeth)
1460 if ((ugeth->phy_interface == PHY_INTERFACE_MODE_RMII) || 1460 if ((ugeth->phy_interface == PHY_INTERFACE_MODE_RMII) ||
1461 (ugeth->phy_interface == PHY_INTERFACE_MODE_RGMII) || 1461 (ugeth->phy_interface == PHY_INTERFACE_MODE_RGMII) ||
1462 (ugeth->phy_interface == PHY_INTERFACE_MODE_RGMII_ID) || 1462 (ugeth->phy_interface == PHY_INTERFACE_MODE_RGMII_ID) ||
1463 (ugeth->phy_interface == PHY_INTERFACE_MODE_RGMII_RXID) ||
1464 (ugeth->phy_interface == PHY_INTERFACE_MODE_RGMII_TXID) ||
1463 (ugeth->phy_interface == PHY_INTERFACE_MODE_RTBI)) { 1465 (ugeth->phy_interface == PHY_INTERFACE_MODE_RTBI)) {
1464 upsmr |= UPSMR_RPM; 1466 upsmr |= UPSMR_RPM;
1465 switch (ugeth->max_speed) { 1467 switch (ugeth->max_speed) {
@@ -1557,6 +1559,8 @@ static void adjust_link(struct net_device *dev)
1557 if ((ugeth->phy_interface == PHY_INTERFACE_MODE_RMII) || 1559 if ((ugeth->phy_interface == PHY_INTERFACE_MODE_RMII) ||
1558 (ugeth->phy_interface == PHY_INTERFACE_MODE_RGMII) || 1560 (ugeth->phy_interface == PHY_INTERFACE_MODE_RGMII) ||
1559 (ugeth->phy_interface == PHY_INTERFACE_MODE_RGMII_ID) || 1561 (ugeth->phy_interface == PHY_INTERFACE_MODE_RGMII_ID) ||
1562 (ugeth->phy_interface == PHY_INTERFACE_MODE_RGMII_RXID) ||
1563 (ugeth->phy_interface == PHY_INTERFACE_MODE_RGMII_TXID) ||
1560 (ugeth->phy_interface == PHY_INTERFACE_MODE_RTBI)) { 1564 (ugeth->phy_interface == PHY_INTERFACE_MODE_RTBI)) {
1561 if (phydev->speed == SPEED_10) 1565 if (phydev->speed == SPEED_10)
1562 upsmr |= UPSMR_R10M; 1566 upsmr |= UPSMR_R10M;
@@ -3443,7 +3447,7 @@ static int ucc_geth_rx(struct ucc_geth_private *ugeth, u8 rxQ, int rx_work_limit
3443 u16 length, howmany = 0; 3447 u16 length, howmany = 0;
3444 u32 bd_status; 3448 u32 bd_status;
3445 u8 *bdBuffer; 3449 u8 *bdBuffer;
3446 struct net_device * dev; 3450 struct net_device *dev;
3447 3451
3448 ugeth_vdbg("%s: IN", __FUNCTION__); 3452 ugeth_vdbg("%s: IN", __FUNCTION__);
3449 3453
@@ -3795,6 +3799,10 @@ static phy_interface_t to_phy_interface(const char *phy_connection_type)
3795 return PHY_INTERFACE_MODE_RGMII; 3799 return PHY_INTERFACE_MODE_RGMII;
3796 if (strcasecmp(phy_connection_type, "rgmii-id") == 0) 3800 if (strcasecmp(phy_connection_type, "rgmii-id") == 0)
3797 return PHY_INTERFACE_MODE_RGMII_ID; 3801 return PHY_INTERFACE_MODE_RGMII_ID;
3802 if (strcasecmp(phy_connection_type, "rgmii-txid") == 0)
3803 return PHY_INTERFACE_MODE_RGMII_TXID;
3804 if (strcasecmp(phy_connection_type, "rgmii-rxid") == 0)
3805 return PHY_INTERFACE_MODE_RGMII_RXID;
3798 if (strcasecmp(phy_connection_type, "rtbi") == 0) 3806 if (strcasecmp(phy_connection_type, "rtbi") == 0)
3799 return PHY_INTERFACE_MODE_RTBI; 3807 return PHY_INTERFACE_MODE_RTBI;
3800 3808
@@ -3889,6 +3897,8 @@ static int ucc_geth_probe(struct of_device* ofdev, const struct of_device_id *ma
3889 case PHY_INTERFACE_MODE_GMII: 3897 case PHY_INTERFACE_MODE_GMII:
3890 case PHY_INTERFACE_MODE_RGMII: 3898 case PHY_INTERFACE_MODE_RGMII:
3891 case PHY_INTERFACE_MODE_RGMII_ID: 3899 case PHY_INTERFACE_MODE_RGMII_ID:
3900 case PHY_INTERFACE_MODE_RGMII_RXID:
3901 case PHY_INTERFACE_MODE_RGMII_TXID:
3892 case PHY_INTERFACE_MODE_TBI: 3902 case PHY_INTERFACE_MODE_TBI:
3893 case PHY_INTERFACE_MODE_RTBI: 3903 case PHY_INTERFACE_MODE_RTBI:
3894 max_speed = SPEED_1000; 3904 max_speed = SPEED_1000;
diff --git a/drivers/net/ucc_geth_mii.h b/drivers/net/ucc_geth_mii.h
index d83437039919..1e45b2028a50 100644
--- a/drivers/net/ucc_geth_mii.h
+++ b/drivers/net/ucc_geth_mii.h
@@ -96,5 +96,5 @@ enum enet_tbi_mii_reg {
96int uec_mdio_read(struct mii_bus *bus, int mii_id, int regnum); 96int uec_mdio_read(struct mii_bus *bus, int mii_id, int regnum);
97int uec_mdio_write(struct mii_bus *bus, int mii_id, int regnum, u16 value); 97int uec_mdio_write(struct mii_bus *bus, int mii_id, int regnum, u16 value);
98int __init uec_mdio_init(void); 98int __init uec_mdio_init(void);
99void __exit uec_mdio_exit(void); 99void uec_mdio_exit(void);
100#endif /* __UEC_MII_H */ 100#endif /* __UEC_MII_H */
diff --git a/drivers/net/usb/asix.c b/drivers/net/usb/asix.c
index 61daa096de66..1249f444039e 100644
--- a/drivers/net/usb/asix.c
+++ b/drivers/net/usb/asix.c
@@ -172,45 +172,76 @@ struct asix_data {
172}; 172};
173 173
174struct ax88172_int_data { 174struct ax88172_int_data {
175 u16 res1; 175 __le16 res1;
176 u8 link; 176 u8 link;
177 u16 res2; 177 __le16 res2;
178 u8 status; 178 u8 status;
179 u16 res3; 179 __le16 res3;
180} __attribute__ ((packed)); 180} __attribute__ ((packed));
181 181
182static int asix_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index, 182static int asix_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
183 u16 size, void *data) 183 u16 size, void *data)
184{ 184{
185 void *buf;
186 int err = -ENOMEM;
187
185 devdbg(dev,"asix_read_cmd() cmd=0x%02x value=0x%04x index=0x%04x size=%d", 188 devdbg(dev,"asix_read_cmd() cmd=0x%02x value=0x%04x index=0x%04x size=%d",
186 cmd, value, index, size); 189 cmd, value, index, size);
187 return usb_control_msg( 190
191 buf = kmalloc(size, GFP_KERNEL);
192 if (!buf)
193 goto out;
194
195 err = usb_control_msg(
188 dev->udev, 196 dev->udev,
189 usb_rcvctrlpipe(dev->udev, 0), 197 usb_rcvctrlpipe(dev->udev, 0),
190 cmd, 198 cmd,
191 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 199 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
192 value, 200 value,
193 index, 201 index,
194 data, 202 buf,
195 size, 203 size,
196 USB_CTRL_GET_TIMEOUT); 204 USB_CTRL_GET_TIMEOUT);
205 if (err >= 0 && err < size)
206 err = -EINVAL;
207 if (!err)
208 memcpy(data, buf, size);
209 kfree(buf);
210
211out:
212 return err;
197} 213}
198 214
199static int asix_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index, 215static int asix_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
200 u16 size, void *data) 216 u16 size, void *data)
201{ 217{
218 void *buf = NULL;
219 int err = -ENOMEM;
220
202 devdbg(dev,"asix_write_cmd() cmd=0x%02x value=0x%04x index=0x%04x size=%d", 221 devdbg(dev,"asix_write_cmd() cmd=0x%02x value=0x%04x index=0x%04x size=%d",
203 cmd, value, index, size); 222 cmd, value, index, size);
204 return usb_control_msg( 223
224 if (data) {
225 buf = kmalloc(size, GFP_KERNEL);
226 if (!buf)
227 goto out;
228 memcpy(buf, data, size);
229 }
230
231 err = usb_control_msg(
205 dev->udev, 232 dev->udev,
206 usb_sndctrlpipe(dev->udev, 0), 233 usb_sndctrlpipe(dev->udev, 0),
207 cmd, 234 cmd,
208 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 235 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
209 value, 236 value,
210 index, 237 index,
211 data, 238 buf,
212 size, 239 size,
213 USB_CTRL_SET_TIMEOUT); 240 USB_CTRL_SET_TIMEOUT);
241 kfree(buf);
242
243out:
244 return err;
214} 245}
215 246
216static void asix_async_cmd_callback(struct urb *urb) 247static void asix_async_cmd_callback(struct urb *urb)
@@ -402,25 +433,19 @@ static inline int asix_set_hw_mii(struct usbnet *dev)
402 433
403static inline int asix_get_phy_addr(struct usbnet *dev) 434static inline int asix_get_phy_addr(struct usbnet *dev)
404{ 435{
405 int ret = 0; 436 u8 buf[2];
406 void *buf; 437 int ret = asix_read_cmd(dev, AX_CMD_READ_PHY_ID, 0, 0, 2, buf);
407 438
408 devdbg(dev, "asix_get_phy_addr()"); 439 devdbg(dev, "asix_get_phy_addr()");
409 440
410 buf = kmalloc(2, GFP_KERNEL); 441 if (ret < 0) {
411 if (!buf)
412 goto out1;
413
414 if ((ret = asix_read_cmd(dev, AX_CMD_READ_PHY_ID,
415 0, 0, 2, buf)) < 2) {
416 deverr(dev, "Error reading PHYID register: %02x", ret); 442 deverr(dev, "Error reading PHYID register: %02x", ret);
417 goto out2; 443 goto out;
418 } 444 }
419 devdbg(dev, "asix_get_phy_addr() returning 0x%04x", *((u16 *)buf)); 445 devdbg(dev, "asix_get_phy_addr() returning 0x%04x", *((__le16 *)buf));
420 ret = *((u8 *)buf + 1); 446 ret = buf[1];
421out2: 447
422 kfree(buf); 448out:
423out1:
424 return ret; 449 return ret;
425} 450}
426 451
@@ -437,22 +462,15 @@ static int asix_sw_reset(struct usbnet *dev, u8 flags)
437 462
438static u16 asix_read_rx_ctl(struct usbnet *dev) 463static u16 asix_read_rx_ctl(struct usbnet *dev)
439{ 464{
440 u16 ret = 0; 465 __le16 v;
441 void *buf; 466 int ret = asix_read_cmd(dev, AX_CMD_READ_RX_CTL, 0, 0, 2, &v);
442
443 buf = kmalloc(2, GFP_KERNEL);
444 if (!buf)
445 goto out1;
446 467
447 if ((ret = asix_read_cmd(dev, AX_CMD_READ_RX_CTL, 468 if (ret < 0) {
448 0, 0, 2, buf)) < 2) {
449 deverr(dev, "Error reading RX_CTL register: %02x", ret); 469 deverr(dev, "Error reading RX_CTL register: %02x", ret);
450 goto out2; 470 goto out;
451 } 471 }
452 ret = le16_to_cpu(*((u16 *)buf)); 472 ret = le16_to_cpu(v);
453out2: 473out:
454 kfree(buf);
455out1:
456 return ret; 474 return ret;
457} 475}
458 476
@@ -471,22 +489,15 @@ static int asix_write_rx_ctl(struct usbnet *dev, u16 mode)
471 489
472static u16 asix_read_medium_status(struct usbnet *dev) 490static u16 asix_read_medium_status(struct usbnet *dev)
473{ 491{
474 u16 ret = 0; 492 __le16 v;
475 void *buf; 493 int ret = asix_read_cmd(dev, AX_CMD_READ_MEDIUM_STATUS, 0, 0, 2, &v);
476 494
477 buf = kmalloc(2, GFP_KERNEL); 495 if (ret < 0) {
478 if (!buf)
479 goto out1;
480
481 if ((ret = asix_read_cmd(dev, AX_CMD_READ_MEDIUM_STATUS,
482 0, 0, 2, buf)) < 2) {
483 deverr(dev, "Error reading Medium Status register: %02x", ret); 496 deverr(dev, "Error reading Medium Status register: %02x", ret);
484 goto out2; 497 goto out;
485 } 498 }
486 ret = le16_to_cpu(*((u16 *)buf)); 499 ret = le16_to_cpu(v);
487out2: 500out:
488 kfree(buf);
489out1:
490 return ret; 501 return ret;
491} 502}
492 503
@@ -568,31 +579,30 @@ static void asix_set_multicast(struct net_device *net)
568static int asix_mdio_read(struct net_device *netdev, int phy_id, int loc) 579static int asix_mdio_read(struct net_device *netdev, int phy_id, int loc)
569{ 580{
570 struct usbnet *dev = netdev_priv(netdev); 581 struct usbnet *dev = netdev_priv(netdev);
571 u16 res; 582 __le16 res;
572 583
573 mutex_lock(&dev->phy_mutex); 584 mutex_lock(&dev->phy_mutex);
574 asix_set_sw_mii(dev); 585 asix_set_sw_mii(dev);
575 asix_read_cmd(dev, AX_CMD_READ_MII_REG, phy_id, 586 asix_read_cmd(dev, AX_CMD_READ_MII_REG, phy_id,
576 (__u16)loc, 2, (u16 *)&res); 587 (__u16)loc, 2, &res);
577 asix_set_hw_mii(dev); 588 asix_set_hw_mii(dev);
578 mutex_unlock(&dev->phy_mutex); 589 mutex_unlock(&dev->phy_mutex);
579 590
580 devdbg(dev, "asix_mdio_read() phy_id=0x%02x, loc=0x%02x, returns=0x%04x", phy_id, loc, le16_to_cpu(res & 0xffff)); 591 devdbg(dev, "asix_mdio_read() phy_id=0x%02x, loc=0x%02x, returns=0x%04x", phy_id, loc, le16_to_cpu(res));
581 592
582 return le16_to_cpu(res & 0xffff); 593 return le16_to_cpu(res);
583} 594}
584 595
585static void 596static void
586asix_mdio_write(struct net_device *netdev, int phy_id, int loc, int val) 597asix_mdio_write(struct net_device *netdev, int phy_id, int loc, int val)
587{ 598{
588 struct usbnet *dev = netdev_priv(netdev); 599 struct usbnet *dev = netdev_priv(netdev);
589 u16 res = cpu_to_le16(val); 600 __le16 res = cpu_to_le16(val);
590 601
591 devdbg(dev, "asix_mdio_write() phy_id=0x%02x, loc=0x%02x, val=0x%04x", phy_id, loc, val); 602 devdbg(dev, "asix_mdio_write() phy_id=0x%02x, loc=0x%02x, val=0x%04x", phy_id, loc, val);
592 mutex_lock(&dev->phy_mutex); 603 mutex_lock(&dev->phy_mutex);
593 asix_set_sw_mii(dev); 604 asix_set_sw_mii(dev);
594 asix_write_cmd(dev, AX_CMD_WRITE_MII_REG, phy_id, 605 asix_write_cmd(dev, AX_CMD_WRITE_MII_REG, phy_id, (__u16)loc, 2, &res);
595 (__u16)loc, 2, (u16 *)&res);
596 asix_set_hw_mii(dev); 606 asix_set_hw_mii(dev);
597 mutex_unlock(&dev->phy_mutex); 607 mutex_unlock(&dev->phy_mutex);
598} 608}
@@ -644,7 +654,6 @@ asix_set_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo)
644{ 654{
645 struct usbnet *dev = netdev_priv(net); 655 struct usbnet *dev = netdev_priv(net);
646 u8 opt = 0; 656 u8 opt = 0;
647 u8 buf[1];
648 657
649 if (wolinfo->wolopts & WAKE_PHY) 658 if (wolinfo->wolopts & WAKE_PHY)
650 opt |= AX_MONITOR_LINK; 659 opt |= AX_MONITOR_LINK;
@@ -654,7 +663,7 @@ asix_set_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo)
654 opt |= AX_MONITOR_MODE; 663 opt |= AX_MONITOR_MODE;
655 664
656 if (asix_write_cmd(dev, AX_CMD_WRITE_MONITOR_MODE, 665 if (asix_write_cmd(dev, AX_CMD_WRITE_MONITOR_MODE,
657 opt, 0, 0, &buf) < 0) 666 opt, 0, 0, NULL) < 0)
658 return -EINVAL; 667 return -EINVAL;
659 668
660 return 0; 669 return 0;
@@ -672,7 +681,7 @@ static int asix_get_eeprom(struct net_device *net,
672 struct ethtool_eeprom *eeprom, u8 *data) 681 struct ethtool_eeprom *eeprom, u8 *data)
673{ 682{
674 struct usbnet *dev = netdev_priv(net); 683 struct usbnet *dev = netdev_priv(net);
675 u16 *ebuf = (u16 *)data; 684 __le16 *ebuf = (__le16 *)data;
676 int i; 685 int i;
677 686
678 /* Crude hack to ensure that we don't overwrite memory 687 /* Crude hack to ensure that we don't overwrite memory
@@ -801,7 +810,7 @@ static int ax88172_link_reset(struct usbnet *dev)
801static int ax88172_bind(struct usbnet *dev, struct usb_interface *intf) 810static int ax88172_bind(struct usbnet *dev, struct usb_interface *intf)
802{ 811{
803 int ret = 0; 812 int ret = 0;
804 void *buf; 813 u8 buf[ETH_ALEN];
805 int i; 814 int i;
806 unsigned long gpio_bits = dev->driver_info->data; 815 unsigned long gpio_bits = dev->driver_info->data;
807 struct asix_data *data = (struct asix_data *)&dev->data; 816 struct asix_data *data = (struct asix_data *)&dev->data;
@@ -810,30 +819,23 @@ static int ax88172_bind(struct usbnet *dev, struct usb_interface *intf)
810 819
811 usbnet_get_endpoints(dev,intf); 820 usbnet_get_endpoints(dev,intf);
812 821
813 buf = kmalloc(ETH_ALEN, GFP_KERNEL);
814 if(!buf) {
815 ret = -ENOMEM;
816 goto out1;
817 }
818
819 /* Toggle the GPIOs in a manufacturer/model specific way */ 822 /* Toggle the GPIOs in a manufacturer/model specific way */
820 for (i = 2; i >= 0; i--) { 823 for (i = 2; i >= 0; i--) {
821 if ((ret = asix_write_cmd(dev, AX_CMD_WRITE_GPIOS, 824 if ((ret = asix_write_cmd(dev, AX_CMD_WRITE_GPIOS,
822 (gpio_bits >> (i * 8)) & 0xff, 0, 0, 825 (gpio_bits >> (i * 8)) & 0xff, 0, 0,
823 buf)) < 0) 826 NULL)) < 0)
824 goto out2; 827 goto out;
825 msleep(5); 828 msleep(5);
826 } 829 }
827 830
828 if ((ret = asix_write_rx_ctl(dev, 0x80)) < 0) 831 if ((ret = asix_write_rx_ctl(dev, 0x80)) < 0)
829 goto out2; 832 goto out;
830 833
831 /* Get the MAC address */ 834 /* Get the MAC address */
832 memset(buf, 0, ETH_ALEN);
833 if ((ret = asix_read_cmd(dev, AX88172_CMD_READ_NODE_ID, 835 if ((ret = asix_read_cmd(dev, AX88172_CMD_READ_NODE_ID,
834 0, 0, 6, buf)) < 0) { 836 0, 0, ETH_ALEN, buf)) < 0) {
835 dbg("read AX_CMD_READ_NODE_ID failed: %d", ret); 837 dbg("read AX_CMD_READ_NODE_ID failed: %d", ret);
836 goto out2; 838 goto out;
837 } 839 }
838 memcpy(dev->net->dev_addr, buf, ETH_ALEN); 840 memcpy(dev->net->dev_addr, buf, ETH_ALEN);
839 841
@@ -855,9 +857,8 @@ static int ax88172_bind(struct usbnet *dev, struct usb_interface *intf)
855 mii_nway_restart(&dev->mii); 857 mii_nway_restart(&dev->mii);
856 858
857 return 0; 859 return 0;
858out2: 860
859 kfree(buf); 861out:
860out1:
861 return ret; 862 return ret;
862} 863}
863 864
@@ -900,66 +901,58 @@ static int ax88772_link_reset(struct usbnet *dev)
900static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf) 901static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf)
901{ 902{
902 int ret, embd_phy; 903 int ret, embd_phy;
903 void *buf;
904 u16 rx_ctl; 904 u16 rx_ctl;
905 struct asix_data *data = (struct asix_data *)&dev->data; 905 struct asix_data *data = (struct asix_data *)&dev->data;
906 u8 buf[ETH_ALEN];
906 u32 phyid; 907 u32 phyid;
907 908
908 data->eeprom_len = AX88772_EEPROM_LEN; 909 data->eeprom_len = AX88772_EEPROM_LEN;
909 910
910 usbnet_get_endpoints(dev,intf); 911 usbnet_get_endpoints(dev,intf);
911 912
912 buf = kmalloc(6, GFP_KERNEL);
913 if(!buf) {
914 dbg ("Cannot allocate memory for buffer");
915 ret = -ENOMEM;
916 goto out1;
917 }
918
919 if ((ret = asix_write_gpio(dev, 913 if ((ret = asix_write_gpio(dev,
920 AX_GPIO_RSE | AX_GPIO_GPO_2 | AX_GPIO_GPO2EN, 5)) < 0) 914 AX_GPIO_RSE | AX_GPIO_GPO_2 | AX_GPIO_GPO2EN, 5)) < 0)
921 goto out2; 915 goto out;
922 916
923 /* 0x10 is the phy id of the embedded 10/100 ethernet phy */ 917 /* 0x10 is the phy id of the embedded 10/100 ethernet phy */
924 embd_phy = ((asix_get_phy_addr(dev) & 0x1f) == 0x10 ? 1 : 0); 918 embd_phy = ((asix_get_phy_addr(dev) & 0x1f) == 0x10 ? 1 : 0);
925 if ((ret = asix_write_cmd(dev, AX_CMD_SW_PHY_SELECT, 919 if ((ret = asix_write_cmd(dev, AX_CMD_SW_PHY_SELECT,
926 embd_phy, 0, 0, buf)) < 0) { 920 embd_phy, 0, 0, NULL)) < 0) {
927 dbg("Select PHY #1 failed: %d", ret); 921 dbg("Select PHY #1 failed: %d", ret);
928 goto out2; 922 goto out;
929 } 923 }
930 924
931 if ((ret = asix_sw_reset(dev, AX_SWRESET_IPPD | AX_SWRESET_PRL)) < 0) 925 if ((ret = asix_sw_reset(dev, AX_SWRESET_IPPD | AX_SWRESET_PRL)) < 0)
932 goto out2; 926 goto out;
933 927
934 msleep(150); 928 msleep(150);
935 if ((ret = asix_sw_reset(dev, AX_SWRESET_CLEAR)) < 0) 929 if ((ret = asix_sw_reset(dev, AX_SWRESET_CLEAR)) < 0)
936 goto out2; 930 goto out;
937 931
938 msleep(150); 932 msleep(150);
939 if (embd_phy) { 933 if (embd_phy) {
940 if ((ret = asix_sw_reset(dev, AX_SWRESET_IPRL)) < 0) 934 if ((ret = asix_sw_reset(dev, AX_SWRESET_IPRL)) < 0)
941 goto out2; 935 goto out;
942 } 936 }
943 else { 937 else {
944 if ((ret = asix_sw_reset(dev, AX_SWRESET_PRTE)) < 0) 938 if ((ret = asix_sw_reset(dev, AX_SWRESET_PRTE)) < 0)
945 goto out2; 939 goto out;
946 } 940 }
947 941
948 msleep(150); 942 msleep(150);
949 rx_ctl = asix_read_rx_ctl(dev); 943 rx_ctl = asix_read_rx_ctl(dev);
950 dbg("RX_CTL is 0x%04x after software reset", rx_ctl); 944 dbg("RX_CTL is 0x%04x after software reset", rx_ctl);
951 if ((ret = asix_write_rx_ctl(dev, 0x0000)) < 0) 945 if ((ret = asix_write_rx_ctl(dev, 0x0000)) < 0)
952 goto out2; 946 goto out;
953 947
954 rx_ctl = asix_read_rx_ctl(dev); 948 rx_ctl = asix_read_rx_ctl(dev);
955 dbg("RX_CTL is 0x%04x setting to 0x0000", rx_ctl); 949 dbg("RX_CTL is 0x%04x setting to 0x0000", rx_ctl);
956 950
957 /* Get the MAC address */ 951 /* Get the MAC address */
958 memset(buf, 0, ETH_ALEN);
959 if ((ret = asix_read_cmd(dev, AX_CMD_READ_NODE_ID, 952 if ((ret = asix_read_cmd(dev, AX_CMD_READ_NODE_ID,
960 0, 0, ETH_ALEN, buf)) < 0) { 953 0, 0, ETH_ALEN, buf)) < 0) {
961 dbg("Failed to read MAC address: %d", ret); 954 dbg("Failed to read MAC address: %d", ret);
962 goto out2; 955 goto out;
963 } 956 }
964 memcpy(dev->net->dev_addr, buf, ETH_ALEN); 957 memcpy(dev->net->dev_addr, buf, ETH_ALEN);
965 958
@@ -976,12 +969,12 @@ static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf)
976 dbg("PHYID=0x%08x", phyid); 969 dbg("PHYID=0x%08x", phyid);
977 970
978 if ((ret = asix_sw_reset(dev, AX_SWRESET_PRL)) < 0) 971 if ((ret = asix_sw_reset(dev, AX_SWRESET_PRL)) < 0)
979 goto out2; 972 goto out;
980 973
981 msleep(150); 974 msleep(150);
982 975
983 if ((ret = asix_sw_reset(dev, AX_SWRESET_IPRL | AX_SWRESET_PRL)) < 0) 976 if ((ret = asix_sw_reset(dev, AX_SWRESET_IPRL | AX_SWRESET_PRL)) < 0)
984 goto out2; 977 goto out;
985 978
986 msleep(150); 979 msleep(150);
987 980
@@ -994,18 +987,18 @@ static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf)
994 mii_nway_restart(&dev->mii); 987 mii_nway_restart(&dev->mii);
995 988
996 if ((ret = asix_write_medium_mode(dev, AX88772_MEDIUM_DEFAULT)) < 0) 989 if ((ret = asix_write_medium_mode(dev, AX88772_MEDIUM_DEFAULT)) < 0)
997 goto out2; 990 goto out;
998 991
999 if ((ret = asix_write_cmd(dev, AX_CMD_WRITE_IPG0, 992 if ((ret = asix_write_cmd(dev, AX_CMD_WRITE_IPG0,
1000 AX88772_IPG0_DEFAULT | AX88772_IPG1_DEFAULT, 993 AX88772_IPG0_DEFAULT | AX88772_IPG1_DEFAULT,
1001 AX88772_IPG2_DEFAULT, 0, buf)) < 0) { 994 AX88772_IPG2_DEFAULT, 0, NULL)) < 0) {
1002 dbg("Write IPG,IPG1,IPG2 failed: %d", ret); 995 dbg("Write IPG,IPG1,IPG2 failed: %d", ret);
1003 goto out2; 996 goto out;
1004 } 997 }
1005 998
1006 /* Set RX_CTL to default values with 2k buffer, and enable cactus */ 999 /* Set RX_CTL to default values with 2k buffer, and enable cactus */
1007 if ((ret = asix_write_rx_ctl(dev, AX_DEFAULT_RX_CTL)) < 0) 1000 if ((ret = asix_write_rx_ctl(dev, AX_DEFAULT_RX_CTL)) < 0)
1008 goto out2; 1001 goto out;
1009 1002
1010 rx_ctl = asix_read_rx_ctl(dev); 1003 rx_ctl = asix_read_rx_ctl(dev);
1011 dbg("RX_CTL is 0x%04x after all initializations", rx_ctl); 1004 dbg("RX_CTL is 0x%04x after all initializations", rx_ctl);
@@ -1013,20 +1006,15 @@ static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf)
1013 rx_ctl = asix_read_medium_status(dev); 1006 rx_ctl = asix_read_medium_status(dev);
1014 dbg("Medium Status is 0x%04x after all initializations", rx_ctl); 1007 dbg("Medium Status is 0x%04x after all initializations", rx_ctl);
1015 1008
1016 kfree(buf);
1017
1018 /* Asix framing packs multiple eth frames into a 2K usb bulk transfer */ 1009 /* Asix framing packs multiple eth frames into a 2K usb bulk transfer */
1019 if (dev->driver_info->flags & FLAG_FRAMING_AX) { 1010 if (dev->driver_info->flags & FLAG_FRAMING_AX) {
1020 /* hard_mtu is still the default - the device does not support 1011 /* hard_mtu is still the default - the device does not support
1021 jumbo eth frames */ 1012 jumbo eth frames */
1022 dev->rx_urb_size = 2048; 1013 dev->rx_urb_size = 2048;
1023 } 1014 }
1024
1025 return 0; 1015 return 0;
1026 1016
1027out2: 1017out:
1028 kfree(buf);
1029out1:
1030 return ret; 1018 return ret;
1031} 1019}
1032 1020
@@ -1195,23 +1183,16 @@ static int ax88178_bind(struct usbnet *dev, struct usb_interface *intf)
1195{ 1183{
1196 struct asix_data *data = (struct asix_data *)&dev->data; 1184 struct asix_data *data = (struct asix_data *)&dev->data;
1197 int ret; 1185 int ret;
1198 void *buf; 1186 u8 buf[ETH_ALEN];
1199 u16 eeprom; 1187 __le16 eeprom;
1188 u8 status;
1200 int gpio0 = 0; 1189 int gpio0 = 0;
1201 u32 phyid; 1190 u32 phyid;
1202 1191
1203 usbnet_get_endpoints(dev,intf); 1192 usbnet_get_endpoints(dev,intf);
1204 1193
1205 buf = kmalloc(6, GFP_KERNEL); 1194 asix_read_cmd(dev, AX_CMD_READ_GPIOS, 0, 0, 1, &status);
1206 if(!buf) { 1195 dbg("GPIO Status: 0x%04x", status);
1207 dbg ("Cannot allocate memory for buffer");
1208 ret = -ENOMEM;
1209 goto out1;
1210 }
1211
1212 eeprom = 0;
1213 asix_read_cmd(dev, AX_CMD_READ_GPIOS, 0, 0, 1, &eeprom);
1214 dbg("GPIO Status: 0x%04x", eeprom);
1215 1196
1216 asix_write_cmd(dev, AX_CMD_WRITE_ENABLE, 0, 0, 0, NULL); 1197 asix_write_cmd(dev, AX_CMD_WRITE_ENABLE, 0, 0, 0, NULL);
1217 asix_read_cmd(dev, AX_CMD_READ_EEPROM, 0x0017, 0, 2, &eeprom); 1198 asix_read_cmd(dev, AX_CMD_READ_EEPROM, 0x0017, 0, 2, &eeprom);
@@ -1219,19 +1200,19 @@ static int ax88178_bind(struct usbnet *dev, struct usb_interface *intf)
1219 1200
1220 dbg("EEPROM index 0x17 is 0x%04x", eeprom); 1201 dbg("EEPROM index 0x17 is 0x%04x", eeprom);
1221 1202
1222 if (eeprom == 0xffff) { 1203 if (eeprom == cpu_to_le16(0xffff)) {
1223 data->phymode = PHY_MODE_MARVELL; 1204 data->phymode = PHY_MODE_MARVELL;
1224 data->ledmode = 0; 1205 data->ledmode = 0;
1225 gpio0 = 1; 1206 gpio0 = 1;
1226 } else { 1207 } else {
1227 data->phymode = eeprom & 7; 1208 data->phymode = le16_to_cpu(eeprom) & 7;
1228 data->ledmode = eeprom >> 8; 1209 data->ledmode = le16_to_cpu(eeprom) >> 8;
1229 gpio0 = (eeprom & 0x80) ? 0 : 1; 1210 gpio0 = (le16_to_cpu(eeprom) & 0x80) ? 0 : 1;
1230 } 1211 }
1231 dbg("GPIO0: %d, PhyMode: %d", gpio0, data->phymode); 1212 dbg("GPIO0: %d, PhyMode: %d", gpio0, data->phymode);
1232 1213
1233 asix_write_gpio(dev, AX_GPIO_RSE | AX_GPIO_GPO_1 | AX_GPIO_GPO1EN, 40); 1214 asix_write_gpio(dev, AX_GPIO_RSE | AX_GPIO_GPO_1 | AX_GPIO_GPO1EN, 40);
1234 if ((eeprom >> 8) != 1) { 1215 if ((le16_to_cpu(eeprom) >> 8) != 1) {
1235 asix_write_gpio(dev, 0x003c, 30); 1216 asix_write_gpio(dev, 0x003c, 30);
1236 asix_write_gpio(dev, 0x001c, 300); 1217 asix_write_gpio(dev, 0x001c, 300);
1237 asix_write_gpio(dev, 0x003c, 30); 1218 asix_write_gpio(dev, 0x003c, 30);
@@ -1250,11 +1231,10 @@ static int ax88178_bind(struct usbnet *dev, struct usb_interface *intf)
1250 asix_write_rx_ctl(dev, 0); 1231 asix_write_rx_ctl(dev, 0);
1251 1232
1252 /* Get the MAC address */ 1233 /* Get the MAC address */
1253 memset(buf, 0, ETH_ALEN);
1254 if ((ret = asix_read_cmd(dev, AX_CMD_READ_NODE_ID, 1234 if ((ret = asix_read_cmd(dev, AX_CMD_READ_NODE_ID,
1255 0, 0, ETH_ALEN, buf)) < 0) { 1235 0, 0, ETH_ALEN, buf)) < 0) {
1256 dbg("Failed to read MAC address: %d", ret); 1236 dbg("Failed to read MAC address: %d", ret);
1257 goto out2; 1237 goto out;
1258 } 1238 }
1259 memcpy(dev->net->dev_addr, buf, ETH_ALEN); 1239 memcpy(dev->net->dev_addr, buf, ETH_ALEN);
1260 1240
@@ -1289,12 +1269,10 @@ static int ax88178_bind(struct usbnet *dev, struct usb_interface *intf)
1289 mii_nway_restart(&dev->mii); 1269 mii_nway_restart(&dev->mii);
1290 1270
1291 if ((ret = asix_write_medium_mode(dev, AX88178_MEDIUM_DEFAULT)) < 0) 1271 if ((ret = asix_write_medium_mode(dev, AX88178_MEDIUM_DEFAULT)) < 0)
1292 goto out2; 1272 goto out;
1293 1273
1294 if ((ret = asix_write_rx_ctl(dev, AX_DEFAULT_RX_CTL)) < 0) 1274 if ((ret = asix_write_rx_ctl(dev, AX_DEFAULT_RX_CTL)) < 0)
1295 goto out2; 1275 goto out;
1296
1297 kfree(buf);
1298 1276
1299 /* Asix framing packs multiple eth frames into a 2K usb bulk transfer */ 1277 /* Asix framing packs multiple eth frames into a 2K usb bulk transfer */
1300 if (dev->driver_info->flags & FLAG_FRAMING_AX) { 1278 if (dev->driver_info->flags & FLAG_FRAMING_AX) {
@@ -1302,12 +1280,9 @@ static int ax88178_bind(struct usbnet *dev, struct usb_interface *intf)
1302 jumbo eth frames */ 1280 jumbo eth frames */
1303 dev->rx_urb_size = 2048; 1281 dev->rx_urb_size = 2048;
1304 } 1282 }
1305
1306 return 0; 1283 return 0;
1307 1284
1308out2: 1285out:
1309 kfree(buf);
1310out1:
1311 return ret; 1286 return ret;
1312} 1287}
1313 1288
diff --git a/drivers/net/usb/dm9601.c b/drivers/net/usb/dm9601.c
index 2c685734b7a4..1ffdd106f4c4 100644
--- a/drivers/net/usb/dm9601.c
+++ b/drivers/net/usb/dm9601.c
@@ -94,7 +94,7 @@ static void dm_write_async_callback(struct urb *urb)
94 struct usb_ctrlrequest *req = (struct usb_ctrlrequest *)urb->context; 94 struct usb_ctrlrequest *req = (struct usb_ctrlrequest *)urb->context;
95 95
96 if (urb->status < 0) 96 if (urb->status < 0)
97 printk(KERN_DEBUG "dm_write_async_callback() failed with %d", 97 printk(KERN_DEBUG "dm_write_async_callback() failed with %d\n",
98 urb->status); 98 urb->status);
99 99
100 kfree(req); 100 kfree(req);
diff --git a/drivers/net/veth.c b/drivers/net/veth.c
index fdd1e034569d..43af9e9b2652 100644
--- a/drivers/net/veth.c
+++ b/drivers/net/veth.c
@@ -15,7 +15,7 @@
15 15
16#include <net/dst.h> 16#include <net/dst.h>
17#include <net/xfrm.h> 17#include <net/xfrm.h>
18#include <net/veth.h> 18#include <linux/veth.h>
19 19
20#define DRV_NAME "veth" 20#define DRV_NAME "veth"
21#define DRV_VERSION "1.0" 21#define DRV_VERSION "1.0"
diff --git a/drivers/net/via-velocity.c b/drivers/net/via-velocity.c
index 450e29d7a9f3..35cd65d6b9ed 100644
--- a/drivers/net/via-velocity.c
+++ b/drivers/net/via-velocity.c
@@ -1242,6 +1242,9 @@ static int velocity_rx_refill(struct velocity_info *vptr)
1242static int velocity_init_rd_ring(struct velocity_info *vptr) 1242static int velocity_init_rd_ring(struct velocity_info *vptr)
1243{ 1243{
1244 int ret; 1244 int ret;
1245 int mtu = vptr->dev->mtu;
1246
1247 vptr->rx_buf_sz = (mtu <= ETH_DATA_LEN) ? PKT_BUF_SZ : mtu + 32;
1245 1248
1246 vptr->rd_info = kcalloc(vptr->options.numrx, 1249 vptr->rd_info = kcalloc(vptr->options.numrx,
1247 sizeof(struct velocity_rd_info), GFP_KERNEL); 1250 sizeof(struct velocity_rd_info), GFP_KERNEL);
@@ -1898,8 +1901,6 @@ static int velocity_open(struct net_device *dev)
1898 struct velocity_info *vptr = netdev_priv(dev); 1901 struct velocity_info *vptr = netdev_priv(dev);
1899 int ret; 1902 int ret;
1900 1903
1901 vptr->rx_buf_sz = (dev->mtu <= 1504 ? PKT_BUF_SZ : dev->mtu + 32);
1902
1903 ret = velocity_init_rings(vptr); 1904 ret = velocity_init_rings(vptr);
1904 if (ret < 0) 1905 if (ret < 0)
1905 goto out; 1906 goto out;
@@ -1978,12 +1979,6 @@ static int velocity_change_mtu(struct net_device *dev, int new_mtu)
1978 velocity_free_rd_ring(vptr); 1979 velocity_free_rd_ring(vptr);
1979 1980
1980 dev->mtu = new_mtu; 1981 dev->mtu = new_mtu;
1981 if (new_mtu > 8192)
1982 vptr->rx_buf_sz = 9 * 1024;
1983 else if (new_mtu > 4096)
1984 vptr->rx_buf_sz = 8192;
1985 else
1986 vptr->rx_buf_sz = 4 * 1024;
1987 1982
1988 ret = velocity_init_rd_ring(vptr); 1983 ret = velocity_init_rd_ring(vptr);
1989 if (ret < 0) 1984 if (ret < 0)
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index a75be57fb209..5413dbf3d4ac 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -198,8 +198,8 @@ again:
198 if (vi->num < vi->max / 2) 198 if (vi->num < vi->max / 2)
199 try_fill_recv(vi); 199 try_fill_recv(vi);
200 200
201 /* All done? */ 201 /* Out of packets? */
202 if (!skb) { 202 if (received < budget) {
203 netif_rx_complete(vi->dev, napi); 203 netif_rx_complete(vi->dev, napi);
204 if (unlikely(!vi->rvq->vq_ops->restart(vi->rvq)) 204 if (unlikely(!vi->rvq->vq_ops->restart(vi->rvq))
205 && netif_rx_reschedule(vi->dev, napi)) 205 && netif_rx_reschedule(vi->dev, napi))
@@ -404,8 +404,12 @@ free:
404 404
405static void virtnet_remove(struct virtio_device *vdev) 405static void virtnet_remove(struct virtio_device *vdev)
406{ 406{
407 unregister_netdev(vdev->priv); 407 struct virtnet_info *vi = vdev->priv;
408 free_netdev(vdev->priv); 408
409 vdev->config->del_vq(vi->svq);
410 vdev->config->del_vq(vi->rvq);
411 unregister_netdev(vi->dev);
412 free_netdev(vi->dev);
409} 413}
410 414
411static struct virtio_device_id id_table[] = { 415static struct virtio_device_id id_table[] = {
diff --git a/drivers/net/wan/cycx_x25.c b/drivers/net/wan/cycx_x25.c
index 8a1778cf98d1..d3b28b01b9f9 100644
--- a/drivers/net/wan/cycx_x25.c
+++ b/drivers/net/wan/cycx_x25.c
@@ -503,7 +503,7 @@ static int cycx_netdevice_init(struct net_device *dev)
503 dev->addr_len = 0; /* hardware address length */ 503 dev->addr_len = 0; /* hardware address length */
504 504
505 if (!chan->svc) 505 if (!chan->svc)
506 *(u16*)dev->dev_addr = htons(chan->lcn); 506 *(__be16*)dev->dev_addr = htons(chan->lcn);
507 507
508 /* Initialize hardware parameters (just for reference) */ 508 /* Initialize hardware parameters (just for reference) */
509 dev->irq = wandev->irq; 509 dev->irq = wandev->irq;
@@ -565,7 +565,7 @@ static int cycx_netdevice_hard_header(struct sk_buff *skb,
565 const void *daddr, const void *saddr, 565 const void *daddr, const void *saddr,
566 unsigned len) 566 unsigned len)
567{ 567{
568 skb->protocol = type; 568 skb->protocol = htons(type);
569 569
570 return dev->hard_header_len; 570 return dev->hard_header_len;
571} 571}
@@ -600,15 +600,15 @@ static int cycx_netdevice_hard_start_xmit(struct sk_buff *skb,
600 struct cycx_device *card = chan->card; 600 struct cycx_device *card = chan->card;
601 601
602 if (!chan->svc) 602 if (!chan->svc)
603 chan->protocol = skb->protocol; 603 chan->protocol = ntohs(skb->protocol);
604 604
605 if (card->wandev.state != WAN_CONNECTED) 605 if (card->wandev.state != WAN_CONNECTED)
606 ++chan->ifstats.tx_dropped; 606 ++chan->ifstats.tx_dropped;
607 else if (chan->svc && chan->protocol && 607 else if (chan->svc && chan->protocol &&
608 chan->protocol != skb->protocol) { 608 chan->protocol != ntohs(skb->protocol)) {
609 printk(KERN_INFO 609 printk(KERN_INFO
610 "%s: unsupported Ethertype 0x%04X on interface %s!\n", 610 "%s: unsupported Ethertype 0x%04X on interface %s!\n",
611 card->devname, skb->protocol, dev->name); 611 card->devname, ntohs(skb->protocol), dev->name);
612 ++chan->ifstats.tx_errors; 612 ++chan->ifstats.tx_errors;
613 } else if (chan->protocol == ETH_P_IP) { 613 } else if (chan->protocol == ETH_P_IP) {
614 switch (chan->state) { 614 switch (chan->state) {
@@ -1401,7 +1401,7 @@ static void cycx_x25_set_chan_state(struct net_device *dev, u8 state)
1401 switch (state) { 1401 switch (state) {
1402 case WAN_CONNECTED: 1402 case WAN_CONNECTED:
1403 string_state = "connected!"; 1403 string_state = "connected!";
1404 *(u16*)dev->dev_addr = htons(chan->lcn); 1404 *(__be16*)dev->dev_addr = htons(chan->lcn);
1405 netif_wake_queue(dev); 1405 netif_wake_queue(dev);
1406 reset_timer(dev); 1406 reset_timer(dev);
1407 1407
diff --git a/drivers/net/wan/syncppp.c b/drivers/net/wan/syncppp.c
index 232ecba5340f..61e24b7a45a3 100644
--- a/drivers/net/wan/syncppp.c
+++ b/drivers/net/wan/syncppp.c
@@ -107,24 +107,24 @@
107struct ppp_header { 107struct ppp_header {
108 u8 address; 108 u8 address;
109 u8 control; 109 u8 control;
110 u16 protocol; 110 __be16 protocol;
111}; 111};
112#define PPP_HEADER_LEN sizeof (struct ppp_header) 112#define PPP_HEADER_LEN sizeof (struct ppp_header)
113 113
114struct lcp_header { 114struct lcp_header {
115 u8 type; 115 u8 type;
116 u8 ident; 116 u8 ident;
117 u16 len; 117 __be16 len;
118}; 118};
119#define LCP_HEADER_LEN sizeof (struct lcp_header) 119#define LCP_HEADER_LEN sizeof (struct lcp_header)
120 120
121struct cisco_packet { 121struct cisco_packet {
122 u32 type; 122 __be32 type;
123 u32 par1; 123 __be32 par1;
124 u32 par2; 124 __be32 par2;
125 u16 rel; 125 __be16 rel;
126 u16 time0; 126 __be16 time0;
127 u16 time1; 127 __be16 time1;
128}; 128};
129#define CISCO_PACKET_LEN 18 129#define CISCO_PACKET_LEN 18
130#define CISCO_BIG_PACKET_LEN 20 130#define CISCO_BIG_PACKET_LEN 20
@@ -139,7 +139,7 @@ static struct sk_buff_head tx_queue;
139static void sppp_keepalive (unsigned long dummy); 139static void sppp_keepalive (unsigned long dummy);
140static void sppp_cp_send (struct sppp *sp, u16 proto, u8 type, 140static void sppp_cp_send (struct sppp *sp, u16 proto, u8 type,
141 u8 ident, u16 len, void *data); 141 u8 ident, u16 len, void *data);
142static void sppp_cisco_send (struct sppp *sp, int type, long par1, long par2); 142static void sppp_cisco_send (struct sppp *sp, int type, u32 par1, u32 par2);
143static void sppp_lcp_input (struct sppp *sp, struct sk_buff *m); 143static void sppp_lcp_input (struct sppp *sp, struct sk_buff *m);
144static void sppp_cisco_input (struct sppp *sp, struct sk_buff *m); 144static void sppp_cisco_input (struct sppp *sp, struct sk_buff *m);
145static void sppp_ipcp_input (struct sppp *sp, struct sk_buff *m); 145static void sppp_ipcp_input (struct sppp *sp, struct sk_buff *m);
@@ -447,7 +447,7 @@ static void sppp_keepalive (unsigned long dummy)
447 sppp_cisco_send (sp, CISCO_KEEPALIVE_REQ, ++sp->pp_seq, 447 sppp_cisco_send (sp, CISCO_KEEPALIVE_REQ, ++sp->pp_seq,
448 sp->pp_rseq); 448 sp->pp_rseq);
449 else if (sp->lcp.state == LCP_STATE_OPENED) { 449 else if (sp->lcp.state == LCP_STATE_OPENED) {
450 long nmagic = htonl (sp->lcp.magic); 450 __be32 nmagic = htonl (sp->lcp.magic);
451 sp->lcp.echoid = ++sp->pp_seq; 451 sp->lcp.echoid = ++sp->pp_seq;
452 sppp_cp_send (sp, PPP_LCP, LCP_ECHO_REQ, 452 sppp_cp_send (sp, PPP_LCP, LCP_ECHO_REQ,
453 sp->lcp.echoid, 4, &nmagic); 453 sp->lcp.echoid, 4, &nmagic);
@@ -667,7 +667,7 @@ badreq:
667 dev->name, len); 667 dev->name, len);
668 break; 668 break;
669 } 669 }
670 if (ntohl (*(long*)(h+1)) == sp->lcp.magic) { 670 if (ntohl (*(__be32*)(h+1)) == sp->lcp.magic) {
671 /* Line loopback mode detected. */ 671 /* Line loopback mode detected. */
672 printk (KERN_WARNING "%s: loopback\n", dev->name); 672 printk (KERN_WARNING "%s: loopback\n", dev->name);
673 if_down (dev); 673 if_down (dev);
@@ -680,7 +680,7 @@ badreq:
680 sppp_lcp_open (sp); 680 sppp_lcp_open (sp);
681 break; 681 break;
682 } 682 }
683 *(long*)(h+1) = htonl (sp->lcp.magic); 683 *(__be32 *)(h+1) = htonl (sp->lcp.magic);
684 sppp_cp_send (sp, PPP_LCP, LCP_ECHO_REPLY, h->ident, len-4, h+1); 684 sppp_cp_send (sp, PPP_LCP, LCP_ECHO_REPLY, h->ident, len-4, h+1);
685 break; 685 break;
686 case LCP_ECHO_REPLY: 686 case LCP_ECHO_REPLY:
@@ -692,7 +692,7 @@ badreq:
692 dev->name, len); 692 dev->name, len);
693 break; 693 break;
694 } 694 }
695 if (ntohl (*(long*)(h+1)) != sp->lcp.magic) 695 if (ntohl(*(__be32 *)(h+1)) != sp->lcp.magic)
696 sp->pp_alivecnt = 0; 696 sp->pp_alivecnt = 0;
697 break; 697 break;
698 } 698 }
@@ -765,7 +765,7 @@ static void sppp_cisco_input (struct sppp *sp, struct sk_buff *skb)
765 { 765 {
766 struct in_device *in_dev; 766 struct in_device *in_dev;
767 struct in_ifaddr *ifa; 767 struct in_ifaddr *ifa;
768 __be32 addr = 0, mask = ~0; /* FIXME: is the mask correct? */ 768 __be32 addr = 0, mask = htonl(~0U); /* FIXME: is the mask correct? */
769#ifdef CONFIG_INET 769#ifdef CONFIG_INET
770 rcu_read_lock(); 770 rcu_read_lock();
771 if ((in_dev = __in_dev_get_rcu(dev)) != NULL) 771 if ((in_dev = __in_dev_get_rcu(dev)) != NULL)
@@ -782,8 +782,7 @@ static void sppp_cisco_input (struct sppp *sp, struct sk_buff *skb)
782 } 782 }
783 rcu_read_unlock(); 783 rcu_read_unlock();
784#endif 784#endif
785 /* I hope both addr and mask are in the net order */ 785 sppp_cisco_send (sp, CISCO_ADDR_REPLY, ntohl(addr), ntohl(mask));
786 sppp_cisco_send (sp, CISCO_ADDR_REPLY, addr, mask);
787 break; 786 break;
788 } 787 }
789 } 788 }
@@ -844,7 +843,7 @@ static void sppp_cp_send (struct sppp *sp, u16 proto, u8 type,
844 * Send Cisco keepalive packet. 843 * Send Cisco keepalive packet.
845 */ 844 */
846 845
847static void sppp_cisco_send (struct sppp *sp, int type, long par1, long par2) 846static void sppp_cisco_send (struct sppp *sp, int type, u32 par1, u32 par2)
848{ 847{
849 struct ppp_header *h; 848 struct ppp_header *h;
850 struct cisco_packet *ch; 849 struct cisco_packet *ch;
@@ -868,7 +867,7 @@ static void sppp_cisco_send (struct sppp *sp, int type, long par1, long par2)
868 ch->type = htonl (type); 867 ch->type = htonl (type);
869 ch->par1 = htonl (par1); 868 ch->par1 = htonl (par1);
870 ch->par2 = htonl (par2); 869 ch->par2 = htonl (par2);
871 ch->rel = -1; 870 ch->rel = htons(0xffff);
872 ch->time0 = htons ((u16) (t >> 16)); 871 ch->time0 = htons ((u16) (t >> 16));
873 ch->time1 = htons ((u16) t); 872 ch->time1 = htons ((u16) t);
874 873
diff --git a/drivers/net/wireless/Kconfig b/drivers/net/wireless/Kconfig
index 2b733c582915..c98fc62a3e61 100644
--- a/drivers/net/wireless/Kconfig
+++ b/drivers/net/wireless/Kconfig
@@ -264,6 +264,7 @@ config IPW2200_DEBUG
264config LIBERTAS 264config LIBERTAS
265 tristate "Marvell 8xxx Libertas WLAN driver support" 265 tristate "Marvell 8xxx Libertas WLAN driver support"
266 depends on WLAN_80211 266 depends on WLAN_80211
267 select WIRELESS_EXT
267 select IEEE80211 268 select IEEE80211
268 select FW_LOADER 269 select FW_LOADER
269 ---help--- 270 ---help---
@@ -586,15 +587,66 @@ config ADM8211
586config P54_COMMON 587config P54_COMMON
587 tristate "Softmac Prism54 support" 588 tristate "Softmac Prism54 support"
588 depends on MAC80211 && WLAN_80211 && FW_LOADER && EXPERIMENTAL 589 depends on MAC80211 && WLAN_80211 && FW_LOADER && EXPERIMENTAL
590 ---help---
591 This is common code for isl38xx based cards.
592 This module does nothing by itself - the USB/PCI frontends
593 also need to be enabled in order to support any devices.
594
595 These devices require softmac firmware which can be found at
596 http://prism54.org/
597
598 If you choose to build a module, it'll be called p54common.
589 599
590config P54_USB 600config P54_USB
591 tristate "Prism54 USB support" 601 tristate "Prism54 USB support"
592 depends on P54_COMMON && USB 602 depends on P54_COMMON && USB
593 select CRC32 603 select CRC32
604 ---help---
605 This driver is for USB isl38xx based wireless cards.
606 These are USB based adapters found in devices such as:
607
608 3COM 3CRWE254G72
609 SMC 2862W-G
610 Accton 802.11g WN4501 USB
611 Siemens Gigaset USB
612 Netgear WG121
613 Netgear WG111
614 Medion 40900, Roper Europe
615 Shuttle PN15, Airvast WM168g, IOGear GWU513
616 Linksys WUSB54G
617 Linksys WUSB54G Portable
618 DLink DWL-G120 Spinnaker
619 DLink DWL-G122
620 Belkin F5D7050 ver 1000
621 Cohiba Proto board
622 SMC 2862W-G version 2
623 U.S. Robotics U5 802.11g Adapter
624 FUJITSU E-5400 USB D1700
625 Sagem XG703A
626 DLink DWL-G120 Cohiba
627 Spinnaker Proto board
628 Linksys WUSB54AG
629 Inventel UR054G
630 Spinnaker DUT
631
632 These devices require softmac firmware which can be found at
633 http://prism54.org/
634
635 If you choose to build a module, it'll be called p54usb.
594 636
595config P54_PCI 637config P54_PCI
596 tristate "Prism54 PCI support" 638 tristate "Prism54 PCI support"
597 depends on P54_COMMON && PCI 639 depends on P54_COMMON && PCI
640 ---help---
641 This driver is for PCI isl38xx based wireless cards.
642 This driver supports most devices that are supported by the
643 fullmac prism54 driver plus many devices which are not
644 supported by the fullmac driver/firmware.
645
646 This driver requires softmac firmware which can be found at
647 http://prism54.org/
648
649 If you choose to build a module, it'll be called p54pci.
598 650
599source "drivers/net/wireless/iwlwifi/Kconfig" 651source "drivers/net/wireless/iwlwifi/Kconfig"
600source "drivers/net/wireless/hostap/Kconfig" 652source "drivers/net/wireless/hostap/Kconfig"
diff --git a/drivers/net/wireless/b43/leds.c b/drivers/net/wireless/b43/leds.c
index 19e588582c7c..6c0e2b9f7760 100644
--- a/drivers/net/wireless/b43/leds.c
+++ b/drivers/net/wireless/b43/leds.c
@@ -163,6 +163,9 @@ static void b43_map_led(struct b43_wldev *dev,
163 b43_register_led(dev, &dev->led_radio, name, 163 b43_register_led(dev, &dev->led_radio, name,
164 b43_rfkill_led_name(dev), 164 b43_rfkill_led_name(dev),
165 led_index, activelow); 165 led_index, activelow);
166 /* Sync the RF-kill LED state with the switch state. */
167 if (dev->radio_hw_enable)
168 b43_led_turn_on(dev, led_index, activelow);
166 break; 169 break;
167 case B43_LED_WEIRD: 170 case B43_LED_WEIRD:
168 case B43_LED_ASSOC: 171 case B43_LED_ASSOC:
@@ -232,4 +235,5 @@ void b43_leds_exit(struct b43_wldev *dev)
232 b43_unregister_led(&dev->led_tx); 235 b43_unregister_led(&dev->led_tx);
233 b43_unregister_led(&dev->led_rx); 236 b43_unregister_led(&dev->led_rx);
234 b43_unregister_led(&dev->led_assoc); 237 b43_unregister_led(&dev->led_assoc);
238 b43_unregister_led(&dev->led_radio);
235} 239}
diff --git a/drivers/net/wireless/b43/main.c b/drivers/net/wireless/b43/main.c
index 2b17c1dc46f1..1c93b4f4bfe3 100644
--- a/drivers/net/wireless/b43/main.c
+++ b/drivers/net/wireless/b43/main.c
@@ -1566,7 +1566,7 @@ static void b43_release_firmware(struct b43_wldev *dev)
1566static void b43_print_fw_helptext(struct b43_wl *wl) 1566static void b43_print_fw_helptext(struct b43_wl *wl)
1567{ 1567{
1568 b43err(wl, "You must go to " 1568 b43err(wl, "You must go to "
1569 "http://linuxwireless.org/en/users/Drivers/bcm43xx#devicefirmware " 1569 "http://linuxwireless.org/en/users/Drivers/b43#devicefirmware "
1570 "and download the correct firmware (version 4).\n"); 1570 "and download the correct firmware (version 4).\n");
1571} 1571}
1572 1572
@@ -2163,7 +2163,6 @@ static void b43_mgmtframe_txantenna(struct b43_wldev *dev, int antenna)
2163static void b43_chip_exit(struct b43_wldev *dev) 2163static void b43_chip_exit(struct b43_wldev *dev)
2164{ 2164{
2165 b43_radio_turn_off(dev, 1); 2165 b43_radio_turn_off(dev, 1);
2166 b43_leds_exit(dev);
2167 b43_gpio_cleanup(dev); 2166 b43_gpio_cleanup(dev);
2168 /* firmware is released later */ 2167 /* firmware is released later */
2169} 2168}
@@ -2191,11 +2190,10 @@ static int b43_chip_init(struct b43_wldev *dev)
2191 err = b43_gpio_init(dev); 2190 err = b43_gpio_init(dev);
2192 if (err) 2191 if (err)
2193 goto out; /* firmware is released later */ 2192 goto out; /* firmware is released later */
2194 b43_leds_init(dev);
2195 2193
2196 err = b43_upload_initvals(dev); 2194 err = b43_upload_initvals(dev);
2197 if (err) 2195 if (err)
2198 goto err_leds_exit; 2196 goto err_gpio_clean;
2199 b43_radio_turn_on(dev); 2197 b43_radio_turn_on(dev);
2200 2198
2201 b43_write16(dev, 0x03E6, 0x0000); 2199 b43_write16(dev, 0x03E6, 0x0000);
@@ -2271,8 +2269,7 @@ out:
2271 2269
2272err_radio_off: 2270err_radio_off:
2273 b43_radio_turn_off(dev, 1); 2271 b43_radio_turn_off(dev, 1);
2274err_leds_exit: 2272err_gpio_clean:
2275 b43_leds_exit(dev);
2276 b43_gpio_cleanup(dev); 2273 b43_gpio_cleanup(dev);
2277 return err; 2274 return err;
2278} 2275}
@@ -3273,10 +3270,7 @@ static void b43_wireless_core_exit(struct b43_wldev *dev)
3273 return; 3270 return;
3274 b43_set_status(dev, B43_STAT_UNINIT); 3271 b43_set_status(dev, B43_STAT_UNINIT);
3275 3272
3276 mutex_unlock(&dev->wl->mutex); 3273 b43_leds_exit(dev);
3277 b43_rfkill_exit(dev);
3278 mutex_lock(&dev->wl->mutex);
3279
3280 b43_rng_exit(dev->wl); 3274 b43_rng_exit(dev->wl);
3281 b43_pio_free(dev); 3275 b43_pio_free(dev);
3282 b43_dma_free(dev); 3276 b43_dma_free(dev);
@@ -3405,12 +3399,12 @@ static int b43_wireless_core_init(struct b43_wldev *dev)
3405 memset(wl->mac_addr, 0, ETH_ALEN); 3399 memset(wl->mac_addr, 0, ETH_ALEN);
3406 b43_upload_card_macaddress(dev); 3400 b43_upload_card_macaddress(dev);
3407 b43_security_init(dev); 3401 b43_security_init(dev);
3408 b43_rfkill_init(dev);
3409 b43_rng_init(wl); 3402 b43_rng_init(wl);
3410 3403
3411 b43_set_status(dev, B43_STAT_INITIALIZED); 3404 b43_set_status(dev, B43_STAT_INITIALIZED);
3412 3405
3413 out: 3406 b43_leds_init(dev);
3407out:
3414 return err; 3408 return err;
3415 3409
3416 err_chip_exit: 3410 err_chip_exit:
@@ -3499,6 +3493,10 @@ static int b43_start(struct ieee80211_hw *hw)
3499 int did_init = 0; 3493 int did_init = 0;
3500 int err = 0; 3494 int err = 0;
3501 3495
3496 /* First register RFkill.
3497 * LEDs that are registered later depend on it. */
3498 b43_rfkill_init(dev);
3499
3502 mutex_lock(&wl->mutex); 3500 mutex_lock(&wl->mutex);
3503 3501
3504 if (b43_status(dev) < B43_STAT_INITIALIZED) { 3502 if (b43_status(dev) < B43_STAT_INITIALIZED) {
@@ -3528,6 +3526,8 @@ static void b43_stop(struct ieee80211_hw *hw)
3528 struct b43_wl *wl = hw_to_b43_wl(hw); 3526 struct b43_wl *wl = hw_to_b43_wl(hw);
3529 struct b43_wldev *dev = wl->current_dev; 3527 struct b43_wldev *dev = wl->current_dev;
3530 3528
3529 b43_rfkill_exit(dev);
3530
3531 mutex_lock(&wl->mutex); 3531 mutex_lock(&wl->mutex);
3532 if (b43_status(dev) >= B43_STAT_STARTED) 3532 if (b43_status(dev) >= B43_STAT_STARTED)
3533 b43_wireless_core_stop(dev); 3533 b43_wireless_core_stop(dev);
diff --git a/drivers/net/wireless/b43/phy.c b/drivers/net/wireless/b43/phy.c
index 3d4ed647c311..7ff091e69f05 100644
--- a/drivers/net/wireless/b43/phy.c
+++ b/drivers/net/wireless/b43/phy.c
@@ -2214,7 +2214,7 @@ int b43_phy_init_tssi2dbm_table(struct b43_wldev *dev)
2214 } 2214 }
2215 dyn_tssi2dbm = kmalloc(64, GFP_KERNEL); 2215 dyn_tssi2dbm = kmalloc(64, GFP_KERNEL);
2216 if (dyn_tssi2dbm == NULL) { 2216 if (dyn_tssi2dbm == NULL) {
2217 b43err(dev->wl, "Could not allocate memory" 2217 b43err(dev->wl, "Could not allocate memory "
2218 "for tssi2dbm table\n"); 2218 "for tssi2dbm table\n");
2219 return -ENOMEM; 2219 return -ENOMEM;
2220 } 2220 }
diff --git a/drivers/net/wireless/b43/rfkill.c b/drivers/net/wireless/b43/rfkill.c
index 9b1f905ffbf4..98cf70c5fd47 100644
--- a/drivers/net/wireless/b43/rfkill.c
+++ b/drivers/net/wireless/b43/rfkill.c
@@ -25,6 +25,8 @@
25#include "rfkill.h" 25#include "rfkill.h"
26#include "b43.h" 26#include "b43.h"
27 27
28#include <linux/kmod.h>
29
28 30
29/* Returns TRUE, if the radio is enabled in hardware. */ 31/* Returns TRUE, if the radio is enabled in hardware. */
30static bool b43_is_hw_radio_enabled(struct b43_wldev *dev) 32static bool b43_is_hw_radio_enabled(struct b43_wldev *dev)
@@ -50,7 +52,10 @@ static void b43_rfkill_poll(struct input_polled_dev *poll_dev)
50 bool report_change = 0; 52 bool report_change = 0;
51 53
52 mutex_lock(&wl->mutex); 54 mutex_lock(&wl->mutex);
53 B43_WARN_ON(b43_status(dev) < B43_STAT_INITIALIZED); 55 if (unlikely(b43_status(dev) < B43_STAT_INITIALIZED)) {
56 mutex_unlock(&wl->mutex);
57 return;
58 }
54 enabled = b43_is_hw_radio_enabled(dev); 59 enabled = b43_is_hw_radio_enabled(dev);
55 if (unlikely(enabled != dev->radio_hw_enable)) { 60 if (unlikely(enabled != dev->radio_hw_enable)) {
56 dev->radio_hw_enable = enabled; 61 dev->radio_hw_enable = enabled;
@@ -60,8 +65,12 @@ static void b43_rfkill_poll(struct input_polled_dev *poll_dev)
60 } 65 }
61 mutex_unlock(&wl->mutex); 66 mutex_unlock(&wl->mutex);
62 67
63 if (unlikely(report_change)) 68 /* send the radio switch event to the system - note both a key press
64 input_report_key(poll_dev->input, KEY_WLAN, enabled); 69 * and a release are required */
70 if (unlikely(report_change)) {
71 input_report_key(poll_dev->input, KEY_WLAN, 1);
72 input_report_key(poll_dev->input, KEY_WLAN, 0);
73 }
65} 74}
66 75
67/* Called when the RFKILL toggled in software. */ 76/* Called when the RFKILL toggled in software. */
@@ -69,13 +78,15 @@ static int b43_rfkill_soft_toggle(void *data, enum rfkill_state state)
69{ 78{
70 struct b43_wldev *dev = data; 79 struct b43_wldev *dev = data;
71 struct b43_wl *wl = dev->wl; 80 struct b43_wl *wl = dev->wl;
72 int err = 0; 81 int err = -EBUSY;
73 82
74 if (!wl->rfkill.registered) 83 if (!wl->rfkill.registered)
75 return 0; 84 return 0;
76 85
77 mutex_lock(&wl->mutex); 86 mutex_lock(&wl->mutex);
78 B43_WARN_ON(b43_status(dev) < B43_STAT_INITIALIZED); 87 if (b43_status(dev) < B43_STAT_INITIALIZED)
88 goto out_unlock;
89 err = 0;
79 switch (state) { 90 switch (state) {
80 case RFKILL_STATE_ON: 91 case RFKILL_STATE_ON:
81 if (!dev->radio_hw_enable) { 92 if (!dev->radio_hw_enable) {
@@ -133,9 +144,25 @@ void b43_rfkill_init(struct b43_wldev *dev)
133 rfk->poll_dev->poll = b43_rfkill_poll; 144 rfk->poll_dev->poll = b43_rfkill_poll;
134 rfk->poll_dev->poll_interval = 1000; /* msecs */ 145 rfk->poll_dev->poll_interval = 1000; /* msecs */
135 146
147 rfk->poll_dev->input->name = rfk->name;
148 rfk->poll_dev->input->id.bustype = BUS_HOST;
149 rfk->poll_dev->input->id.vendor = dev->dev->bus->boardinfo.vendor;
150 rfk->poll_dev->input->evbit[0] = BIT(EV_KEY);
151 set_bit(KEY_WLAN, rfk->poll_dev->input->keybit);
152
136 err = rfkill_register(rfk->rfkill); 153 err = rfkill_register(rfk->rfkill);
137 if (err) 154 if (err)
138 goto err_free_polldev; 155 goto err_free_polldev;
156
157#ifdef CONFIG_RFKILL_INPUT_MODULE
158 /* B43 RF-kill isn't useful without the rfkill-input subsystem.
159 * Try to load the module. */
160 err = request_module("rfkill-input");
161 if (err)
162 b43warn(wl, "Failed to load the rfkill-input module. "
163 "The built-in radio LED will not work.\n");
164#endif /* CONFIG_RFKILL_INPUT */
165
139 err = input_register_polled_device(rfk->poll_dev); 166 err = input_register_polled_device(rfk->poll_dev);
140 if (err) 167 if (err)
141 goto err_unreg_rfk; 168 goto err_unreg_rfk;
diff --git a/drivers/net/wireless/b43legacy/dma.c b/drivers/net/wireless/b43legacy/dma.c
index 8cb3dc4c4745..83161d9af813 100644
--- a/drivers/net/wireless/b43legacy/dma.c
+++ b/drivers/net/wireless/b43legacy/dma.c
@@ -996,7 +996,7 @@ int b43legacy_dma_init(struct b43legacy_wldev *dev)
996 996
997 err = ssb_dma_set_mask(dev->dev, dmamask); 997 err = ssb_dma_set_mask(dev->dev, dmamask);
998 if (err) { 998 if (err) {
999#ifdef BCM43XX_PIO 999#ifdef CONFIG_B43LEGACY_PIO
1000 b43legacywarn(dev->wl, "DMA for this device not supported. " 1000 b43legacywarn(dev->wl, "DMA for this device not supported. "
1001 "Falling back to PIO\n"); 1001 "Falling back to PIO\n");
1002 dev->__using_pio = 1; 1002 dev->__using_pio = 1;
diff --git a/drivers/net/wireless/b43legacy/main.c b/drivers/net/wireless/b43legacy/main.c
index 3bde1e9ab428..32d5e1785bda 100644
--- a/drivers/net/wireless/b43legacy/main.c
+++ b/drivers/net/wireless/b43legacy/main.c
@@ -1419,7 +1419,7 @@ static void b43legacy_release_firmware(struct b43legacy_wldev *dev)
1419static void b43legacy_print_fw_helptext(struct b43legacy_wl *wl) 1419static void b43legacy_print_fw_helptext(struct b43legacy_wl *wl)
1420{ 1420{
1421 b43legacyerr(wl, "You must go to http://linuxwireless.org/en/users/" 1421 b43legacyerr(wl, "You must go to http://linuxwireless.org/en/users/"
1422 "Drivers/bcm43xx#devicefirmware " 1422 "Drivers/b43#devicefirmware "
1423 "and download the correct firmware (version 3).\n"); 1423 "and download the correct firmware (version 3).\n");
1424} 1424}
1425 1425
diff --git a/drivers/net/wireless/b43legacy/phy.c b/drivers/net/wireless/b43legacy/phy.c
index 22a4b3d0186d..491e518e4aeb 100644
--- a/drivers/net/wireless/b43legacy/phy.c
+++ b/drivers/net/wireless/b43legacy/phy.c
@@ -2020,7 +2020,7 @@ int b43legacy_phy_init_tssi2dbm_table(struct b43legacy_wldev *dev)
2020 phy->idle_tssi = 62; 2020 phy->idle_tssi = 62;
2021 dyn_tssi2dbm = kmalloc(64, GFP_KERNEL); 2021 dyn_tssi2dbm = kmalloc(64, GFP_KERNEL);
2022 if (dyn_tssi2dbm == NULL) { 2022 if (dyn_tssi2dbm == NULL) {
2023 b43legacyerr(dev->wl, "Could not allocate memory" 2023 b43legacyerr(dev->wl, "Could not allocate memory "
2024 "for tssi2dbm table\n"); 2024 "for tssi2dbm table\n");
2025 return -ENOMEM; 2025 return -ENOMEM;
2026 } 2026 }
diff --git a/drivers/net/wireless/bcm43xx/bcm43xx_debugfs.c b/drivers/net/wireless/bcm43xx/bcm43xx_debugfs.c
index 35dbe4554513..76e9dd843faa 100644
--- a/drivers/net/wireless/bcm43xx/bcm43xx_debugfs.c
+++ b/drivers/net/wireless/bcm43xx/bcm43xx_debugfs.c
@@ -219,7 +219,7 @@ static ssize_t tsf_write_file(struct file *file, const char __user *user_buf,
219 ssize_t buf_size; 219 ssize_t buf_size;
220 ssize_t res; 220 ssize_t res;
221 unsigned long flags; 221 unsigned long flags;
222 u64 tsf; 222 unsigned long long tsf;
223 223
224 buf_size = min(count, sizeof (really_big_buffer) - 1); 224 buf_size = min(count, sizeof (really_big_buffer) - 1);
225 down(&big_buffer_sem); 225 down(&big_buffer_sem);
diff --git a/drivers/net/wireless/bcm43xx/bcm43xx_phy.c b/drivers/net/wireless/bcm43xx/bcm43xx_phy.c
index b37f1e348700..af3de3343650 100644
--- a/drivers/net/wireless/bcm43xx/bcm43xx_phy.c
+++ b/drivers/net/wireless/bcm43xx/bcm43xx_phy.c
@@ -2149,7 +2149,7 @@ int bcm43xx_phy_init_tssi2dbm_table(struct bcm43xx_private *bcm)
2149 } 2149 }
2150 dyn_tssi2dbm = kmalloc(64, GFP_KERNEL); 2150 dyn_tssi2dbm = kmalloc(64, GFP_KERNEL);
2151 if (dyn_tssi2dbm == NULL) { 2151 if (dyn_tssi2dbm == NULL) {
2152 printk(KERN_ERR PFX "Could not allocate memory" 2152 printk(KERN_ERR PFX "Could not allocate memory "
2153 "for tssi2dbm table\n"); 2153 "for tssi2dbm table\n");
2154 return -ENOMEM; 2154 return -ENOMEM;
2155 } 2155 }
diff --git a/drivers/net/wireless/ipw2200.c b/drivers/net/wireless/ipw2200.c
index 54f44e5473c0..88062c1318a8 100644
--- a/drivers/net/wireless/ipw2200.c
+++ b/drivers/net/wireless/ipw2200.c
@@ -1233,9 +1233,19 @@ static ssize_t show_event_log(struct device *d,
1233{ 1233{
1234 struct ipw_priv *priv = dev_get_drvdata(d); 1234 struct ipw_priv *priv = dev_get_drvdata(d);
1235 u32 log_len = ipw_get_event_log_len(priv); 1235 u32 log_len = ipw_get_event_log_len(priv);
1236 struct ipw_event log[log_len]; 1236 u32 log_size;
1237 struct ipw_event *log;
1237 u32 len = 0, i; 1238 u32 len = 0, i;
1238 1239
1240 /* not using min() because of its strict type checking */
1241 log_size = PAGE_SIZE / sizeof(*log) > log_len ?
1242 sizeof(*log) * log_len : PAGE_SIZE;
1243 log = kzalloc(log_size, GFP_KERNEL);
1244 if (!log) {
1245 IPW_ERROR("Unable to allocate memory for log\n");
1246 return 0;
1247 }
1248 log_len = log_size / sizeof(*log);
1239 ipw_capture_event_log(priv, log_len, log); 1249 ipw_capture_event_log(priv, log_len, log);
1240 1250
1241 len += snprintf(buf + len, PAGE_SIZE - len, "%08X", log_len); 1251 len += snprintf(buf + len, PAGE_SIZE - len, "%08X", log_len);
@@ -1244,6 +1254,7 @@ static ssize_t show_event_log(struct device *d,
1244 "\n%08X%08X%08X", 1254 "\n%08X%08X%08X",
1245 log[i].time, log[i].event, log[i].data); 1255 log[i].time, log[i].event, log[i].data);
1246 len += snprintf(buf + len, PAGE_SIZE - len, "\n"); 1256 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1257 kfree(log);
1247 return len; 1258 return len;
1248} 1259}
1249 1260
@@ -10751,7 +10762,7 @@ static void ipw_bg_link_down(struct work_struct *work)
10751 mutex_unlock(&priv->mutex); 10762 mutex_unlock(&priv->mutex);
10752} 10763}
10753 10764
10754static int ipw_setup_deferred_work(struct ipw_priv *priv) 10765static int __devinit ipw_setup_deferred_work(struct ipw_priv *priv)
10755{ 10766{
10756 int ret = 0; 10767 int ret = 0;
10757 10768
@@ -11600,7 +11611,8 @@ static void ipw_prom_free(struct ipw_priv *priv)
11600#endif 11611#endif
11601 11612
11602 11613
11603static int ipw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) 11614static int __devinit ipw_pci_probe(struct pci_dev *pdev,
11615 const struct pci_device_id *ent)
11604{ 11616{
11605 int err = 0; 11617 int err = 0;
11606 struct net_device *net_dev; 11618 struct net_device *net_dev;
@@ -11767,7 +11779,7 @@ static int ipw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
11767 return err; 11779 return err;
11768} 11780}
11769 11781
11770static void ipw_pci_remove(struct pci_dev *pdev) 11782static void __devexit ipw_pci_remove(struct pci_dev *pdev)
11771{ 11783{
11772 struct ipw_priv *priv = pci_get_drvdata(pdev); 11784 struct ipw_priv *priv = pci_get_drvdata(pdev);
11773 struct list_head *p, *q; 11785 struct list_head *p, *q;
diff --git a/drivers/net/wireless/iwlwifi/iwl3945-base.c b/drivers/net/wireless/iwlwifi/iwl3945-base.c
index 465da4f67ce7..1a6b0e0edf6f 100644
--- a/drivers/net/wireless/iwlwifi/iwl3945-base.c
+++ b/drivers/net/wireless/iwlwifi/iwl3945-base.c
@@ -2915,6 +2915,10 @@ static void iwl_set_rate(struct iwl_priv *priv)
2915 int i; 2915 int i;
2916 2916
2917 hw = iwl_get_hw_mode(priv, priv->phymode); 2917 hw = iwl_get_hw_mode(priv, priv->phymode);
2918 if (!hw) {
2919 IWL_ERROR("Failed to set rate: unable to get hw mode\n");
2920 return;
2921 }
2918 2922
2919 priv->active_rate = 0; 2923 priv->active_rate = 0;
2920 priv->active_rate_basic = 0; 2924 priv->active_rate_basic = 0;
@@ -4739,8 +4743,10 @@ static void iwl_irq_tasklet(struct iwl_priv *priv)
4739 * when we loaded driver, and is now set to "enable". 4743 * when we loaded driver, and is now set to "enable".
4740 * After we're Alive, RF_KILL gets handled by 4744 * After we're Alive, RF_KILL gets handled by
4741 * iwl_rx_card_state_notif() */ 4745 * iwl_rx_card_state_notif() */
4742 if (!hw_rf_kill && !test_bit(STATUS_ALIVE, &priv->status)) 4746 if (!hw_rf_kill && !test_bit(STATUS_ALIVE, &priv->status)) {
4747 clear_bit(STATUS_RF_KILL_HW, &priv->status);
4743 queue_work(priv->workqueue, &priv->restart); 4748 queue_work(priv->workqueue, &priv->restart);
4749 }
4744 4750
4745 handled |= CSR_INT_BIT_RF_KILL; 4751 handled |= CSR_INT_BIT_RF_KILL;
4746 } 4752 }
@@ -6167,6 +6173,7 @@ static void iwl_alive_start(struct iwl_priv *priv)
6167 mutex_lock(&priv->mutex); 6173 mutex_lock(&priv->mutex);
6168 6174
6169 if (rc) { 6175 if (rc) {
6176 iwl_rate_control_unregister(priv->hw);
6170 IWL_ERROR("Failed to register network " 6177 IWL_ERROR("Failed to register network "
6171 "device (error %d)\n", rc); 6178 "device (error %d)\n", rc);
6172 return; 6179 return;
@@ -6239,8 +6246,6 @@ static void __iwl_down(struct iwl_priv *priv)
6239 /* Unblock any waiting calls */ 6246 /* Unblock any waiting calls */
6240 wake_up_interruptible_all(&priv->wait_command_queue); 6247 wake_up_interruptible_all(&priv->wait_command_queue);
6241 6248
6242 iwl_cancel_deferred_work(priv);
6243
6244 /* Wipe out the EXIT_PENDING status bit if we are not actually 6249 /* Wipe out the EXIT_PENDING status bit if we are not actually
6245 * exiting the module */ 6250 * exiting the module */
6246 if (!exit_pending) 6251 if (!exit_pending)
@@ -6315,6 +6320,8 @@ static void iwl_down(struct iwl_priv *priv)
6315 mutex_lock(&priv->mutex); 6320 mutex_lock(&priv->mutex);
6316 __iwl_down(priv); 6321 __iwl_down(priv);
6317 mutex_unlock(&priv->mutex); 6322 mutex_unlock(&priv->mutex);
6323
6324 iwl_cancel_deferred_work(priv);
6318} 6325}
6319 6326
6320#define MAX_HW_RESTARTS 5 6327#define MAX_HW_RESTARTS 5
@@ -6936,13 +6943,10 @@ static int iwl_mac_add_interface(struct ieee80211_hw *hw,
6936 DECLARE_MAC_BUF(mac); 6943 DECLARE_MAC_BUF(mac);
6937 6944
6938 IWL_DEBUG_MAC80211("enter: id %d, type %d\n", conf->if_id, conf->type); 6945 IWL_DEBUG_MAC80211("enter: id %d, type %d\n", conf->if_id, conf->type);
6939 if (conf->mac_addr)
6940 IWL_DEBUG_MAC80211("enter: MAC %s\n",
6941 print_mac(mac, conf->mac_addr));
6942 6946
6943 if (priv->interface_id) { 6947 if (priv->interface_id) {
6944 IWL_DEBUG_MAC80211("leave - interface_id != 0\n"); 6948 IWL_DEBUG_MAC80211("leave - interface_id != 0\n");
6945 return 0; 6949 return -EOPNOTSUPP;
6946 } 6950 }
6947 6951
6948 spin_lock_irqsave(&priv->lock, flags); 6952 spin_lock_irqsave(&priv->lock, flags);
@@ -6951,6 +6955,12 @@ static int iwl_mac_add_interface(struct ieee80211_hw *hw,
6951 spin_unlock_irqrestore(&priv->lock, flags); 6955 spin_unlock_irqrestore(&priv->lock, flags);
6952 6956
6953 mutex_lock(&priv->mutex); 6957 mutex_lock(&priv->mutex);
6958
6959 if (conf->mac_addr) {
6960 IWL_DEBUG_MAC80211("Set: %s\n", print_mac(mac, conf->mac_addr));
6961 memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN);
6962 }
6963
6954 iwl_set_mode(priv, conf->type); 6964 iwl_set_mode(priv, conf->type);
6955 6965
6956 IWL_DEBUG_MAC80211("leave\n"); 6966 IWL_DEBUG_MAC80211("leave\n");
@@ -8270,6 +8280,7 @@ static void iwl_cancel_deferred_work(struct iwl_priv *priv)
8270{ 8280{
8271 iwl_hw_cancel_deferred_work(priv); 8281 iwl_hw_cancel_deferred_work(priv);
8272 8282
8283 cancel_delayed_work_sync(&priv->init_alive_start);
8273 cancel_delayed_work(&priv->scan_check); 8284 cancel_delayed_work(&priv->scan_check);
8274 cancel_delayed_work(&priv->alive_start); 8285 cancel_delayed_work(&priv->alive_start);
8275 cancel_delayed_work(&priv->post_associate); 8286 cancel_delayed_work(&priv->post_associate);
@@ -8569,10 +8580,9 @@ static void iwl_pci_remove(struct pci_dev *pdev)
8569 8580
8570 IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n"); 8581 IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n");
8571 8582
8572 mutex_lock(&priv->mutex);
8573 set_bit(STATUS_EXIT_PENDING, &priv->status); 8583 set_bit(STATUS_EXIT_PENDING, &priv->status);
8574 __iwl_down(priv); 8584
8575 mutex_unlock(&priv->mutex); 8585 iwl_down(priv);
8576 8586
8577 /* Free MAC hash list for ADHOC */ 8587 /* Free MAC hash list for ADHOC */
8578 for (i = 0; i < IWL_IBSS_MAC_HASH_SIZE; i++) { 8588 for (i = 0; i < IWL_IBSS_MAC_HASH_SIZE; i++) {
@@ -8631,12 +8641,10 @@ static int iwl_pci_suspend(struct pci_dev *pdev, pm_message_t state)
8631{ 8641{
8632 struct iwl_priv *priv = pci_get_drvdata(pdev); 8642 struct iwl_priv *priv = pci_get_drvdata(pdev);
8633 8643
8634 mutex_lock(&priv->mutex);
8635
8636 set_bit(STATUS_IN_SUSPEND, &priv->status); 8644 set_bit(STATUS_IN_SUSPEND, &priv->status);
8637 8645
8638 /* Take down the device; powers it off, etc. */ 8646 /* Take down the device; powers it off, etc. */
8639 __iwl_down(priv); 8647 iwl_down(priv);
8640 8648
8641 if (priv->mac80211_registered) 8649 if (priv->mac80211_registered)
8642 ieee80211_stop_queues(priv->hw); 8650 ieee80211_stop_queues(priv->hw);
@@ -8645,8 +8653,6 @@ static int iwl_pci_suspend(struct pci_dev *pdev, pm_message_t state)
8645 pci_disable_device(pdev); 8653 pci_disable_device(pdev);
8646 pci_set_power_state(pdev, PCI_D3hot); 8654 pci_set_power_state(pdev, PCI_D3hot);
8647 8655
8648 mutex_unlock(&priv->mutex);
8649
8650 return 0; 8656 return 0;
8651} 8657}
8652 8658
@@ -8704,8 +8710,6 @@ static int iwl_pci_resume(struct pci_dev *pdev)
8704 8710
8705 printk(KERN_INFO "Coming out of suspend...\n"); 8711 printk(KERN_INFO "Coming out of suspend...\n");
8706 8712
8707 mutex_lock(&priv->mutex);
8708
8709 pci_set_power_state(pdev, PCI_D0); 8713 pci_set_power_state(pdev, PCI_D0);
8710 err = pci_enable_device(pdev); 8714 err = pci_enable_device(pdev);
8711 pci_restore_state(pdev); 8715 pci_restore_state(pdev);
@@ -8719,7 +8723,6 @@ static int iwl_pci_resume(struct pci_dev *pdev)
8719 pci_write_config_byte(pdev, 0x41, 0x00); 8723 pci_write_config_byte(pdev, 0x41, 0x00);
8720 8724
8721 iwl_resume(priv); 8725 iwl_resume(priv);
8722 mutex_unlock(&priv->mutex);
8723 8726
8724 return 0; 8727 return 0;
8725} 8728}
diff --git a/drivers/net/wireless/iwlwifi/iwl4965-base.c b/drivers/net/wireless/iwlwifi/iwl4965-base.c
index 9918780f5e86..6cd57c220631 100644
--- a/drivers/net/wireless/iwlwifi/iwl4965-base.c
+++ b/drivers/net/wireless/iwlwifi/iwl4965-base.c
@@ -3003,6 +3003,10 @@ static void iwl_set_rate(struct iwl_priv *priv)
3003 int i; 3003 int i;
3004 3004
3005 hw = iwl_get_hw_mode(priv, priv->phymode); 3005 hw = iwl_get_hw_mode(priv, priv->phymode);
3006 if (!hw) {
3007 IWL_ERROR("Failed to set rate: unable to get hw mode\n");
3008 return;
3009 }
3006 3010
3007 priv->active_rate = 0; 3011 priv->active_rate = 0;
3008 priv->active_rate_basic = 0; 3012 priv->active_rate_basic = 0;
@@ -5055,8 +5059,10 @@ static void iwl_irq_tasklet(struct iwl_priv *priv)
5055 * when we loaded driver, and is now set to "enable". 5059 * when we loaded driver, and is now set to "enable".
5056 * After we're Alive, RF_KILL gets handled by 5060 * After we're Alive, RF_KILL gets handled by
5057 * iwl_rx_card_state_notif() */ 5061 * iwl_rx_card_state_notif() */
5058 if (!hw_rf_kill && !test_bit(STATUS_ALIVE, &priv->status)) 5062 if (!hw_rf_kill && !test_bit(STATUS_ALIVE, &priv->status)) {
5063 clear_bit(STATUS_RF_KILL_HW, &priv->status);
5059 queue_work(priv->workqueue, &priv->restart); 5064 queue_work(priv->workqueue, &priv->restart);
5065 }
5060 5066
5061 handled |= CSR_INT_BIT_RF_KILL; 5067 handled |= CSR_INT_BIT_RF_KILL;
5062 } 5068 }
@@ -6523,6 +6529,7 @@ static void iwl_alive_start(struct iwl_priv *priv)
6523 mutex_lock(&priv->mutex); 6529 mutex_lock(&priv->mutex);
6524 6530
6525 if (rc) { 6531 if (rc) {
6532 iwl_rate_control_unregister(priv->hw);
6526 IWL_ERROR("Failed to register network " 6533 IWL_ERROR("Failed to register network "
6527 "device (error %d)\n", rc); 6534 "device (error %d)\n", rc);
6528 return; 6535 return;
@@ -6594,8 +6601,6 @@ static void __iwl_down(struct iwl_priv *priv)
6594 /* Unblock any waiting calls */ 6601 /* Unblock any waiting calls */
6595 wake_up_interruptible_all(&priv->wait_command_queue); 6602 wake_up_interruptible_all(&priv->wait_command_queue);
6596 6603
6597 iwl_cancel_deferred_work(priv);
6598
6599 /* Wipe out the EXIT_PENDING status bit if we are not actually 6604 /* Wipe out the EXIT_PENDING status bit if we are not actually
6600 * exiting the module */ 6605 * exiting the module */
6601 if (!exit_pending) 6606 if (!exit_pending)
@@ -6670,6 +6675,8 @@ static void iwl_down(struct iwl_priv *priv)
6670 mutex_lock(&priv->mutex); 6675 mutex_lock(&priv->mutex);
6671 __iwl_down(priv); 6676 __iwl_down(priv);
6672 mutex_unlock(&priv->mutex); 6677 mutex_unlock(&priv->mutex);
6678
6679 iwl_cancel_deferred_work(priv);
6673} 6680}
6674 6681
6675#define MAX_HW_RESTARTS 5 6682#define MAX_HW_RESTARTS 5
@@ -7326,9 +7333,6 @@ static int iwl_mac_add_interface(struct ieee80211_hw *hw,
7326 DECLARE_MAC_BUF(mac); 7333 DECLARE_MAC_BUF(mac);
7327 7334
7328 IWL_DEBUG_MAC80211("enter: id %d, type %d\n", conf->if_id, conf->type); 7335 IWL_DEBUG_MAC80211("enter: id %d, type %d\n", conf->if_id, conf->type);
7329 if (conf->mac_addr)
7330 IWL_DEBUG_MAC80211("enter: MAC %s\n",
7331 print_mac(mac, conf->mac_addr));
7332 7336
7333 if (priv->interface_id) { 7337 if (priv->interface_id) {
7334 IWL_DEBUG_MAC80211("leave - interface_id != 0\n"); 7338 IWL_DEBUG_MAC80211("leave - interface_id != 0\n");
@@ -7341,6 +7345,11 @@ static int iwl_mac_add_interface(struct ieee80211_hw *hw,
7341 spin_unlock_irqrestore(&priv->lock, flags); 7345 spin_unlock_irqrestore(&priv->lock, flags);
7342 7346
7343 mutex_lock(&priv->mutex); 7347 mutex_lock(&priv->mutex);
7348
7349 if (conf->mac_addr) {
7350 IWL_DEBUG_MAC80211("Set %s\n", print_mac(mac, conf->mac_addr));
7351 memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN);
7352 }
7344 iwl_set_mode(priv, conf->type); 7353 iwl_set_mode(priv, conf->type);
7345 7354
7346 IWL_DEBUG_MAC80211("leave\n"); 7355 IWL_DEBUG_MAC80211("leave\n");
@@ -8864,6 +8873,7 @@ static void iwl_cancel_deferred_work(struct iwl_priv *priv)
8864{ 8873{
8865 iwl_hw_cancel_deferred_work(priv); 8874 iwl_hw_cancel_deferred_work(priv);
8866 8875
8876 cancel_delayed_work_sync(&priv->init_alive_start);
8867 cancel_delayed_work(&priv->scan_check); 8877 cancel_delayed_work(&priv->scan_check);
8868 cancel_delayed_work(&priv->alive_start); 8878 cancel_delayed_work(&priv->alive_start);
8869 cancel_delayed_work(&priv->post_associate); 8879 cancel_delayed_work(&priv->post_associate);
@@ -9164,10 +9174,9 @@ static void iwl_pci_remove(struct pci_dev *pdev)
9164 9174
9165 IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n"); 9175 IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n");
9166 9176
9167 mutex_lock(&priv->mutex);
9168 set_bit(STATUS_EXIT_PENDING, &priv->status); 9177 set_bit(STATUS_EXIT_PENDING, &priv->status);
9169 __iwl_down(priv); 9178
9170 mutex_unlock(&priv->mutex); 9179 iwl_down(priv);
9171 9180
9172 /* Free MAC hash list for ADHOC */ 9181 /* Free MAC hash list for ADHOC */
9173 for (i = 0; i < IWL_IBSS_MAC_HASH_SIZE; i++) { 9182 for (i = 0; i < IWL_IBSS_MAC_HASH_SIZE; i++) {
@@ -9226,12 +9235,10 @@ static int iwl_pci_suspend(struct pci_dev *pdev, pm_message_t state)
9226{ 9235{
9227 struct iwl_priv *priv = pci_get_drvdata(pdev); 9236 struct iwl_priv *priv = pci_get_drvdata(pdev);
9228 9237
9229 mutex_lock(&priv->mutex);
9230
9231 set_bit(STATUS_IN_SUSPEND, &priv->status); 9238 set_bit(STATUS_IN_SUSPEND, &priv->status);
9232 9239
9233 /* Take down the device; powers it off, etc. */ 9240 /* Take down the device; powers it off, etc. */
9234 __iwl_down(priv); 9241 iwl_down(priv);
9235 9242
9236 if (priv->mac80211_registered) 9243 if (priv->mac80211_registered)
9237 ieee80211_stop_queues(priv->hw); 9244 ieee80211_stop_queues(priv->hw);
@@ -9240,8 +9247,6 @@ static int iwl_pci_suspend(struct pci_dev *pdev, pm_message_t state)
9240 pci_disable_device(pdev); 9247 pci_disable_device(pdev);
9241 pci_set_power_state(pdev, PCI_D3hot); 9248 pci_set_power_state(pdev, PCI_D3hot);
9242 9249
9243 mutex_unlock(&priv->mutex);
9244
9245 return 0; 9250 return 0;
9246} 9251}
9247 9252
@@ -9299,8 +9304,6 @@ static int iwl_pci_resume(struct pci_dev *pdev)
9299 9304
9300 printk(KERN_INFO "Coming out of suspend...\n"); 9305 printk(KERN_INFO "Coming out of suspend...\n");
9301 9306
9302 mutex_lock(&priv->mutex);
9303
9304 pci_set_power_state(pdev, PCI_D0); 9307 pci_set_power_state(pdev, PCI_D0);
9305 err = pci_enable_device(pdev); 9308 err = pci_enable_device(pdev);
9306 pci_restore_state(pdev); 9309 pci_restore_state(pdev);
@@ -9314,7 +9317,6 @@ static int iwl_pci_resume(struct pci_dev *pdev)
9314 pci_write_config_byte(pdev, 0x41, 0x00); 9317 pci_write_config_byte(pdev, 0x41, 0x00);
9315 9318
9316 iwl_resume(priv); 9319 iwl_resume(priv);
9317 mutex_unlock(&priv->mutex);
9318 9320
9319 return 0; 9321 return 0;
9320} 9322}
diff --git a/drivers/net/wireless/libertas/if_cs.c b/drivers/net/wireless/libertas/if_cs.c
index ec89dabc412c..ba4fc2b3bf0a 100644
--- a/drivers/net/wireless/libertas/if_cs.c
+++ b/drivers/net/wireless/libertas/if_cs.c
@@ -170,7 +170,8 @@ static int if_cs_poll_while_fw_download(struct if_cs_card *card, uint addr, u8 r
170#define IF_CS_H_IC_TX_OVER 0x0001 170#define IF_CS_H_IC_TX_OVER 0x0001
171#define IF_CS_H_IC_RX_OVER 0x0002 171#define IF_CS_H_IC_RX_OVER 0x0002
172#define IF_CS_H_IC_DNLD_OVER 0x0004 172#define IF_CS_H_IC_DNLD_OVER 0x0004
173#define IF_CS_H_IC_HOST_EVENT 0x0008 173#define IF_CS_H_IC_POWER_DOWN 0x0008
174#define IF_CS_H_IC_HOST_EVENT 0x0010
174#define IF_CS_H_IC_MASK 0x001f 175#define IF_CS_H_IC_MASK 0x001f
175 176
176#define IF_CS_H_INT_MASK 0x00000004 177#define IF_CS_H_INT_MASK 0x00000004
diff --git a/drivers/net/wireless/libertas/main.c b/drivers/net/wireless/libertas/main.c
index 5ead08312e1e..1823b48a8ba7 100644
--- a/drivers/net/wireless/libertas/main.c
+++ b/drivers/net/wireless/libertas/main.c
@@ -1165,8 +1165,6 @@ wlan_private *libertas_add_card(void *card, struct device *dmdev)
1165#ifdef WIRELESS_EXT 1165#ifdef WIRELESS_EXT
1166 dev->wireless_handlers = (struct iw_handler_def *)&libertas_handler_def; 1166 dev->wireless_handlers = (struct iw_handler_def *)&libertas_handler_def;
1167#endif 1167#endif
1168#define NETIF_F_DYNALLOC 16
1169 dev->features |= NETIF_F_DYNALLOC;
1170 dev->flags |= IFF_BROADCAST | IFF_MULTICAST; 1168 dev->flags |= IFF_BROADCAST | IFF_MULTICAST;
1171 dev->set_multicast_list = libertas_set_multicast_list; 1169 dev->set_multicast_list = libertas_set_multicast_list;
1172 1170
@@ -1348,8 +1346,6 @@ int libertas_add_mesh(wlan_private *priv, struct device *dev)
1348#ifdef WIRELESS_EXT 1346#ifdef WIRELESS_EXT
1349 mesh_dev->wireless_handlers = (struct iw_handler_def *)&mesh_handler_def; 1347 mesh_dev->wireless_handlers = (struct iw_handler_def *)&mesh_handler_def;
1350#endif 1348#endif
1351#define NETIF_F_DYNALLOC 16
1352
1353 /* Register virtual mesh interface */ 1349 /* Register virtual mesh interface */
1354 ret = register_netdev(mesh_dev); 1350 ret = register_netdev(mesh_dev);
1355 if (ret) { 1351 if (ret) {
diff --git a/drivers/net/wireless/libertas/wext.c b/drivers/net/wireless/libertas/wext.c
index c6f5aa3cb465..395b7882d4d6 100644
--- a/drivers/net/wireless/libertas/wext.c
+++ b/drivers/net/wireless/libertas/wext.c
@@ -1528,7 +1528,7 @@ static int wlan_set_encodeext(struct net_device *dev,
1528 && (ext->key_len != KEY_LEN_WPA_TKIP)) 1528 && (ext->key_len != KEY_LEN_WPA_TKIP))
1529 || ((alg == IW_ENCODE_ALG_CCMP) 1529 || ((alg == IW_ENCODE_ALG_CCMP)
1530 && (ext->key_len != KEY_LEN_WPA_AES))) { 1530 && (ext->key_len != KEY_LEN_WPA_AES))) {
1531 lbs_deb_wext("invalid size %d for key of alg" 1531 lbs_deb_wext("invalid size %d for key of alg "
1532 "type %d\n", 1532 "type %d\n",
1533 ext->key_len, 1533 ext->key_len,
1534 alg); 1534 alg);
diff --git a/drivers/net/wireless/netwave_cs.c b/drivers/net/wireless/netwave_cs.c
index 2402cb8dd328..d2fa079fbc4c 100644
--- a/drivers/net/wireless/netwave_cs.c
+++ b/drivers/net/wireless/netwave_cs.c
@@ -806,7 +806,7 @@ static int netwave_pcmcia_config(struct pcmcia_device *link) {
806 for (i = 0; i < 6; i++) 806 for (i = 0; i < 6; i++)
807 dev->dev_addr[i] = readb(ramBase + NETWAVE_EREG_PA + i); 807 dev->dev_addr[i] = readb(ramBase + NETWAVE_EREG_PA + i);
808 808
809 printk(KERN_INFO "%s: Netwave: port %#3lx, irq %d, mem %lx" 809 printk(KERN_INFO "%s: Netwave: port %#3lx, irq %d, mem %lx, "
810 "id %c%c, hw_addr %s\n", 810 "id %c%c, hw_addr %s\n",
811 dev->name, dev->base_addr, dev->irq, 811 dev->name, dev->base_addr, dev->irq,
812 (u_long) ramBase, 812 (u_long) ramBase,
diff --git a/drivers/net/wireless/p54usb.c b/drivers/net/wireless/p54usb.c
index 755482a5a938..60d286eb0b8b 100644
--- a/drivers/net/wireless/p54usb.c
+++ b/drivers/net/wireless/p54usb.c
@@ -308,7 +308,7 @@ static int p54u_read_eeprom(struct ieee80211_hw *dev)
308 308
309 buf = kmalloc(0x2020, GFP_KERNEL); 309 buf = kmalloc(0x2020, GFP_KERNEL);
310 if (!buf) { 310 if (!buf) {
311 printk(KERN_ERR "prism54usb: cannot allocate memory for" 311 printk(KERN_ERR "prism54usb: cannot allocate memory for "
312 "eeprom readback!\n"); 312 "eeprom readback!\n");
313 return -ENOMEM; 313 return -ENOMEM;
314 } 314 }
diff --git a/drivers/net/wireless/rt2x00/rt2500usb.c b/drivers/net/wireless/rt2x00/rt2500usb.c
index 277a020b35e9..50775f9234cc 100644
--- a/drivers/net/wireless/rt2x00/rt2500usb.c
+++ b/drivers/net/wireless/rt2x00/rt2500usb.c
@@ -1032,7 +1032,7 @@ static void rt2500usb_write_tx_desc(struct rt2x00_dev *rt2x00dev,
1032} 1032}
1033 1033
1034static int rt2500usb_get_tx_data_len(struct rt2x00_dev *rt2x00dev, 1034static int rt2500usb_get_tx_data_len(struct rt2x00_dev *rt2x00dev,
1035 int maxpacket, struct sk_buff *skb) 1035 struct sk_buff *skb)
1036{ 1036{
1037 int length; 1037 int length;
1038 1038
@@ -1041,7 +1041,7 @@ static int rt2500usb_get_tx_data_len(struct rt2x00_dev *rt2x00dev,
1041 * but it must _not_ be a multiple of the USB packet size. 1041 * but it must _not_ be a multiple of the USB packet size.
1042 */ 1042 */
1043 length = roundup(skb->len, 2); 1043 length = roundup(skb->len, 2);
1044 length += (2 * !(length % maxpacket)); 1044 length += (2 * !(length % rt2x00dev->usb_maxpacket));
1045 1045
1046 return length; 1046 return length;
1047} 1047}
@@ -1643,7 +1643,6 @@ static int rt2500usb_beacon_update(struct ieee80211_hw *hw,
1643 struct data_entry *beacon; 1643 struct data_entry *beacon;
1644 struct data_entry *guardian; 1644 struct data_entry *guardian;
1645 int pipe = usb_sndbulkpipe(usb_dev, 1); 1645 int pipe = usb_sndbulkpipe(usb_dev, 1);
1646 int max_packet = usb_maxpacket(usb_dev, pipe, 1);
1647 int length; 1646 int length;
1648 1647
1649 /* 1648 /*
@@ -1672,7 +1671,7 @@ static int rt2500usb_beacon_update(struct ieee80211_hw *hw,
1672 ring->desc_size), 1671 ring->desc_size),
1673 skb->len - ring->desc_size, control); 1672 skb->len - ring->desc_size, control);
1674 1673
1675 length = rt2500usb_get_tx_data_len(rt2x00dev, max_packet, skb); 1674 length = rt2500usb_get_tx_data_len(rt2x00dev, skb);
1676 1675
1677 usb_fill_bulk_urb(beacon->priv, usb_dev, pipe, 1676 usb_fill_bulk_urb(beacon->priv, usb_dev, pipe,
1678 skb->data, length, rt2500usb_beacondone, beacon); 1677 skb->data, length, rt2500usb_beacondone, beacon);
diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
index d1ad5251a77a..c8f16f161c28 100644
--- a/drivers/net/wireless/rt2x00/rt2x00.h
+++ b/drivers/net/wireless/rt2x00/rt2x00.h
@@ -418,7 +418,7 @@ struct rt2x00lib_ops {
418 int (*write_tx_data) (struct rt2x00_dev *rt2x00dev, 418 int (*write_tx_data) (struct rt2x00_dev *rt2x00dev,
419 struct data_ring *ring, struct sk_buff *skb, 419 struct data_ring *ring, struct sk_buff *skb,
420 struct ieee80211_tx_control *control); 420 struct ieee80211_tx_control *control);
421 int (*get_tx_data_len) (struct rt2x00_dev *rt2x00dev, int maxpacket, 421 int (*get_tx_data_len) (struct rt2x00_dev *rt2x00dev,
422 struct sk_buff *skb); 422 struct sk_buff *skb);
423 void (*kick_tx_queue) (struct rt2x00_dev *rt2x00dev, 423 void (*kick_tx_queue) (struct rt2x00_dev *rt2x00dev,
424 unsigned int queue); 424 unsigned int queue);
@@ -599,6 +599,11 @@ struct rt2x00_dev {
599 u32 *rf; 599 u32 *rf;
600 600
601 /* 601 /*
602 * USB Max frame size (for rt2500usb & rt73usb).
603 */
604 u16 usb_maxpacket;
605
606 /*
602 * Current TX power value. 607 * Current TX power value.
603 */ 608 */
604 u16 tx_power; 609 u16 tx_power;
diff --git a/drivers/net/wireless/rt2x00/rt2x00usb.c b/drivers/net/wireless/rt2x00/rt2x00usb.c
index 73cc726c4046..1f5675dd329f 100644
--- a/drivers/net/wireless/rt2x00/rt2x00usb.c
+++ b/drivers/net/wireless/rt2x00/rt2x00usb.c
@@ -159,7 +159,6 @@ int rt2x00usb_write_tx_data(struct rt2x00_dev *rt2x00dev,
159 interface_to_usbdev(rt2x00dev_usb(rt2x00dev)); 159 interface_to_usbdev(rt2x00dev_usb(rt2x00dev));
160 struct data_entry *entry = rt2x00_get_data_entry(ring); 160 struct data_entry *entry = rt2x00_get_data_entry(ring);
161 int pipe = usb_sndbulkpipe(usb_dev, 1); 161 int pipe = usb_sndbulkpipe(usb_dev, 1);
162 int max_packet = usb_maxpacket(usb_dev, pipe, 1);
163 u32 length; 162 u32 length;
164 163
165 if (rt2x00_ring_full(ring)) { 164 if (rt2x00_ring_full(ring)) {
@@ -194,8 +193,7 @@ int rt2x00usb_write_tx_data(struct rt2x00_dev *rt2x00dev,
194 * length of the data to usb_fill_bulk_urb. Pass the skb 193 * length of the data to usb_fill_bulk_urb. Pass the skb
195 * to the driver to determine what the length should be. 194 * to the driver to determine what the length should be.
196 */ 195 */
197 length = rt2x00dev->ops->lib->get_tx_data_len(rt2x00dev, 196 length = rt2x00dev->ops->lib->get_tx_data_len(rt2x00dev, skb);
198 max_packet, skb);
199 197
200 /* 198 /*
201 * Initialize URB and send the frame to the device. 199 * Initialize URB and send the frame to the device.
@@ -490,6 +488,11 @@ int rt2x00usb_probe(struct usb_interface *usb_intf,
490 rt2x00dev->ops = ops; 488 rt2x00dev->ops = ops;
491 rt2x00dev->hw = hw; 489 rt2x00dev->hw = hw;
492 490
491 rt2x00dev->usb_maxpacket =
492 usb_maxpacket(usb_dev, usb_sndbulkpipe(usb_dev, 1), 1);
493 if (!rt2x00dev->usb_maxpacket)
494 rt2x00dev->usb_maxpacket = 1;
495
493 retval = rt2x00usb_alloc_reg(rt2x00dev); 496 retval = rt2x00usb_alloc_reg(rt2x00dev);
494 if (retval) 497 if (retval)
495 goto exit_free_device; 498 goto exit_free_device;
diff --git a/drivers/net/wireless/rt2x00/rt73usb.c b/drivers/net/wireless/rt2x00/rt73usb.c
index dc640bf6b5eb..c0671c2e6e73 100644
--- a/drivers/net/wireless/rt2x00/rt73usb.c
+++ b/drivers/net/wireless/rt2x00/rt73usb.c
@@ -1251,7 +1251,7 @@ static void rt73usb_write_tx_desc(struct rt2x00_dev *rt2x00dev,
1251} 1251}
1252 1252
1253static int rt73usb_get_tx_data_len(struct rt2x00_dev *rt2x00dev, 1253static int rt73usb_get_tx_data_len(struct rt2x00_dev *rt2x00dev,
1254 int maxpacket, struct sk_buff *skb) 1254 struct sk_buff *skb)
1255{ 1255{
1256 int length; 1256 int length;
1257 1257
@@ -1260,7 +1260,7 @@ static int rt73usb_get_tx_data_len(struct rt2x00_dev *rt2x00dev,
1260 * but it must _not_ be a multiple of the USB packet size. 1260 * but it must _not_ be a multiple of the USB packet size.
1261 */ 1261 */
1262 length = roundup(skb->len, 4); 1262 length = roundup(skb->len, 4);
1263 length += (4 * !(length % maxpacket)); 1263 length += (4 * !(length % rt2x00dev->usb_maxpacket));
1264 1264
1265 return length; 1265 return length;
1266} 1266}
diff --git a/drivers/net/wireless/rtl8187_dev.c b/drivers/net/wireless/rtl8187_dev.c
index e454ae83e97a..bd1ab3b3afc0 100644
--- a/drivers/net/wireless/rtl8187_dev.c
+++ b/drivers/net/wireless/rtl8187_dev.c
@@ -38,6 +38,8 @@ static struct usb_device_id rtl8187_table[] __devinitdata = {
38 {USB_DEVICE(0x0846, 0x6a00)}, 38 {USB_DEVICE(0x0846, 0x6a00)},
39 /* HP */ 39 /* HP */
40 {USB_DEVICE(0x03f0, 0xca02)}, 40 {USB_DEVICE(0x03f0, 0xca02)},
41 /* Sitecom */
42 {USB_DEVICE(0x0df6, 0x000d)},
41 {} 43 {}
42}; 44};
43 45
diff --git a/drivers/net/wireless/zd1211rw/zd_mac.c b/drivers/net/wireless/zd1211rw/zd_mac.c
index a903645e157a..5298a8bf1129 100644
--- a/drivers/net/wireless/zd1211rw/zd_mac.c
+++ b/drivers/net/wireless/zd1211rw/zd_mac.c
@@ -1130,6 +1130,8 @@ static void zd_mac_rx(struct zd_mac *mac, struct sk_buff *skb)
1130 __skb_trim(skb, skb->len - 1130 __skb_trim(skb, skb->len -
1131 (IEEE80211_FCS_LEN + sizeof(struct rx_status))); 1131 (IEEE80211_FCS_LEN + sizeof(struct rx_status)));
1132 1132
1133 ZD_ASSERT(IS_ALIGNED((unsigned long)skb->data, 4));
1134
1133 update_qual_rssi(mac, skb->data, skb->len, stats.signal, 1135 update_qual_rssi(mac, skb->data, skb->len, stats.signal,
1134 status->signal_strength); 1136 status->signal_strength);
1135 1137
@@ -1166,15 +1168,19 @@ static void do_rx(unsigned long mac_ptr)
1166int zd_mac_rx_irq(struct zd_mac *mac, const u8 *buffer, unsigned int length) 1168int zd_mac_rx_irq(struct zd_mac *mac, const u8 *buffer, unsigned int length)
1167{ 1169{
1168 struct sk_buff *skb; 1170 struct sk_buff *skb;
1171 unsigned int reserved =
1172 ALIGN(max_t(unsigned int,
1173 sizeof(struct zd_rt_hdr), ZD_PLCP_HEADER_SIZE), 4) -
1174 ZD_PLCP_HEADER_SIZE;
1169 1175
1170 skb = dev_alloc_skb(sizeof(struct zd_rt_hdr) + length); 1176 skb = dev_alloc_skb(reserved + length);
1171 if (!skb) { 1177 if (!skb) {
1172 struct ieee80211_device *ieee = zd_mac_to_ieee80211(mac); 1178 struct ieee80211_device *ieee = zd_mac_to_ieee80211(mac);
1173 dev_warn(zd_mac_dev(mac), "Could not allocate skb.\n"); 1179 dev_warn(zd_mac_dev(mac), "Could not allocate skb.\n");
1174 ieee->stats.rx_dropped++; 1180 ieee->stats.rx_dropped++;
1175 return -ENOMEM; 1181 return -ENOMEM;
1176 } 1182 }
1177 skb_reserve(skb, sizeof(struct zd_rt_hdr)); 1183 skb_reserve(skb, reserved);
1178 memcpy(__skb_put(skb, length), buffer, length); 1184 memcpy(__skb_put(skb, length), buffer, length);
1179 skb_queue_tail(&mac->rx_queue, skb); 1185 skb_queue_tail(&mac->rx_queue, skb);
1180 tasklet_schedule(&mac->rx_tasklet); 1186 tasklet_schedule(&mac->rx_tasklet);
diff --git a/drivers/net/yellowfin.c b/drivers/net/yellowfin.c
index 87f002ade531..fe6ff3e3d525 100644
--- a/drivers/net/yellowfin.c
+++ b/drivers/net/yellowfin.c
@@ -265,10 +265,10 @@ enum yellowfin_offsets {
265/* The Yellowfin Rx and Tx buffer descriptors. 265/* The Yellowfin Rx and Tx buffer descriptors.
266 Elements are written as 32 bit for endian portability. */ 266 Elements are written as 32 bit for endian portability. */
267struct yellowfin_desc { 267struct yellowfin_desc {
268 u32 dbdma_cmd; 268 __le32 dbdma_cmd;
269 u32 addr; 269 __le32 addr;
270 u32 branch_addr; 270 __le32 branch_addr;
271 u32 result_status; 271 __le32 result_status;
272}; 272};
273 273
274struct tx_status_words { 274struct tx_status_words {
@@ -922,7 +922,7 @@ static irqreturn_t yellowfin_interrupt(int irq, void *dev_instance)
922 dev->stats.tx_packets++; 922 dev->stats.tx_packets++;
923 dev->stats.tx_bytes += skb->len; 923 dev->stats.tx_bytes += skb->len;
924 /* Free the original skb. */ 924 /* Free the original skb. */
925 pci_unmap_single(yp->pci_dev, yp->tx_ring[entry].addr, 925 pci_unmap_single(yp->pci_dev, le32_to_cpu(yp->tx_ring[entry].addr),
926 skb->len, PCI_DMA_TODEVICE); 926 skb->len, PCI_DMA_TODEVICE);
927 dev_kfree_skb_irq(skb); 927 dev_kfree_skb_irq(skb);
928 yp->tx_skbuff[entry] = NULL; 928 yp->tx_skbuff[entry] = NULL;
@@ -1056,13 +1056,13 @@ static int yellowfin_rx(struct net_device *dev)
1056 1056
1057 if(!desc->result_status) 1057 if(!desc->result_status)
1058 break; 1058 break;
1059 pci_dma_sync_single_for_cpu(yp->pci_dev, desc->addr, 1059 pci_dma_sync_single_for_cpu(yp->pci_dev, le32_to_cpu(desc->addr),
1060 yp->rx_buf_sz, PCI_DMA_FROMDEVICE); 1060 yp->rx_buf_sz, PCI_DMA_FROMDEVICE);
1061 desc_status = le32_to_cpu(desc->result_status) >> 16; 1061 desc_status = le32_to_cpu(desc->result_status) >> 16;
1062 buf_addr = rx_skb->data; 1062 buf_addr = rx_skb->data;
1063 data_size = (le32_to_cpu(desc->dbdma_cmd) - 1063 data_size = (le32_to_cpu(desc->dbdma_cmd) -
1064 le32_to_cpu(desc->result_status)) & 0xffff; 1064 le32_to_cpu(desc->result_status)) & 0xffff;
1065 frame_status = le16_to_cpu(get_unaligned((s16*)&(buf_addr[data_size - 2]))); 1065 frame_status = le16_to_cpu(get_unaligned((__le16*)&(buf_addr[data_size - 2])));
1066 if (yellowfin_debug > 4) 1066 if (yellowfin_debug > 4)
1067 printk(KERN_DEBUG " yellowfin_rx() status was %4.4x.\n", 1067 printk(KERN_DEBUG " yellowfin_rx() status was %4.4x.\n",
1068 frame_status); 1068 frame_status);
@@ -1123,7 +1123,7 @@ static int yellowfin_rx(struct net_device *dev)
1123 if (pkt_len > rx_copybreak) { 1123 if (pkt_len > rx_copybreak) {
1124 skb_put(skb = rx_skb, pkt_len); 1124 skb_put(skb = rx_skb, pkt_len);
1125 pci_unmap_single(yp->pci_dev, 1125 pci_unmap_single(yp->pci_dev,
1126 yp->rx_ring[entry].addr, 1126 le32_to_cpu(yp->rx_ring[entry].addr),
1127 yp->rx_buf_sz, 1127 yp->rx_buf_sz,
1128 PCI_DMA_FROMDEVICE); 1128 PCI_DMA_FROMDEVICE);
1129 yp->rx_skbuff[entry] = NULL; 1129 yp->rx_skbuff[entry] = NULL;
@@ -1134,9 +1134,10 @@ static int yellowfin_rx(struct net_device *dev)
1134 skb_reserve(skb, 2); /* 16 byte align the IP header */ 1134 skb_reserve(skb, 2); /* 16 byte align the IP header */
1135 skb_copy_to_linear_data(skb, rx_skb->data, pkt_len); 1135 skb_copy_to_linear_data(skb, rx_skb->data, pkt_len);
1136 skb_put(skb, pkt_len); 1136 skb_put(skb, pkt_len);
1137 pci_dma_sync_single_for_device(yp->pci_dev, desc->addr, 1137 pci_dma_sync_single_for_device(yp->pci_dev,
1138 yp->rx_buf_sz, 1138 le32_to_cpu(desc->addr),
1139 PCI_DMA_FROMDEVICE); 1139 yp->rx_buf_sz,
1140 PCI_DMA_FROMDEVICE);
1140 } 1141 }
1141 skb->protocol = eth_type_trans(skb, dev); 1142 skb->protocol = eth_type_trans(skb, dev);
1142 netif_rx(skb); 1143 netif_rx(skb);
@@ -1252,7 +1253,7 @@ static int yellowfin_close(struct net_device *dev)
1252 /* Free all the skbuffs in the Rx queue. */ 1253 /* Free all the skbuffs in the Rx queue. */
1253 for (i = 0; i < RX_RING_SIZE; i++) { 1254 for (i = 0; i < RX_RING_SIZE; i++) {
1254 yp->rx_ring[i].dbdma_cmd = cpu_to_le32(CMD_STOP); 1255 yp->rx_ring[i].dbdma_cmd = cpu_to_le32(CMD_STOP);
1255 yp->rx_ring[i].addr = 0xBADF00D0; /* An invalid address. */ 1256 yp->rx_ring[i].addr = cpu_to_le32(0xBADF00D0); /* An invalid address. */
1256 if (yp->rx_skbuff[i]) { 1257 if (yp->rx_skbuff[i]) {
1257 dev_kfree_skb(yp->rx_skbuff[i]); 1258 dev_kfree_skb(yp->rx_skbuff[i]);
1258 } 1259 }
diff --git a/drivers/parisc/lba_pci.c b/drivers/parisc/lba_pci.c
index 5eace9e66e14..66ce61048361 100644
--- a/drivers/parisc/lba_pci.c
+++ b/drivers/parisc/lba_pci.c
@@ -768,9 +768,13 @@ lba_fixup_bus(struct pci_bus *bus)
768 DBG("lba_fixup_bus() WTF? 0x%lx [%lx/%lx] XXX", 768 DBG("lba_fixup_bus() WTF? 0x%lx [%lx/%lx] XXX",
769 res->flags, res->start, res->end); 769 res->flags, res->start, res->end);
770 } 770 }
771 if ((i != PCI_ROM_RESOURCE) || 771
772 (res->flags & IORESOURCE_ROM_ENABLE)) 772 /*
773 pci_claim_resource(dev, i); 773 ** FIXME: this will result in whinging for devices
774 ** that share expansion ROMs (think quad tulip), but
775 ** isn't harmful.
776 */
777 pci_claim_resource(dev, i);
774 } 778 }
775 779
776#ifdef FBB_SUPPORT 780#ifdef FBB_SUPPORT
diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
index ed82e41210d1..d950fc34320a 100644
--- a/drivers/parport/procfs.c
+++ b/drivers/parport/procfs.c
@@ -384,7 +384,7 @@ parport_device_sysctl_template = {
384 { 384 {
385 .procname = "timeslice", 385 .procname = "timeslice",
386 .data = NULL, 386 .data = NULL,
387 .maxlen = sizeof(int), 387 .maxlen = sizeof(unsigned long),
388 .mode = 0644, 388 .mode = 0644,
389 .proc_handler = &proc_doulongvec_ms_jiffies_minmax, 389 .proc_handler = &proc_doulongvec_ms_jiffies_minmax,
390 .extra1 = (void*) &parport_min_timeslice_value, 390 .extra1 = (void*) &parport_min_timeslice_value,
diff --git a/drivers/pci/hotplug/acpiphp.h b/drivers/pci/hotplug/acpiphp.h
index f6cc0c5b5657..1ef417cca2db 100644
--- a/drivers/pci/hotplug/acpiphp.h
+++ b/drivers/pci/hotplug/acpiphp.h
@@ -66,7 +66,7 @@ struct slot {
66 char name[SLOT_NAME_SIZE]; 66 char name[SLOT_NAME_SIZE];
67}; 67};
68 68
69/** 69/*
70 * struct acpiphp_bridge - PCI bridge information 70 * struct acpiphp_bridge - PCI bridge information
71 * 71 *
72 * for each bridge device in ACPI namespace 72 * for each bridge device in ACPI namespace
@@ -97,7 +97,7 @@ struct acpiphp_bridge {
97}; 97};
98 98
99 99
100/** 100/*
101 * struct acpiphp_slot - PCI slot information 101 * struct acpiphp_slot - PCI slot information
102 * 102 *
103 * PCI slot information for each *physical* PCI slot 103 * PCI slot information for each *physical* PCI slot
@@ -118,7 +118,7 @@ struct acpiphp_slot {
118}; 118};
119 119
120 120
121/** 121/*
122 * struct acpiphp_func - PCI function information 122 * struct acpiphp_func - PCI function information
123 * 123 *
124 * PCI function information for each object in ACPI namespace 124 * PCI function information for each object in ACPI namespace
@@ -137,7 +137,7 @@ struct acpiphp_func {
137 u32 flags; /* see below */ 137 u32 flags; /* see below */
138}; 138};
139 139
140/** 140/*
141 * struct acpiphp_attention_info - device specific attention registration 141 * struct acpiphp_attention_info - device specific attention registration
142 * 142 *
143 * ACPI has no generic method of setting/getting attention status 143 * ACPI has no generic method of setting/getting attention status
diff --git a/drivers/pci/hotplug/acpiphp_core.c b/drivers/pci/hotplug/acpiphp_core.c
index a0ca63adad5a..c8c263875c21 100644
--- a/drivers/pci/hotplug/acpiphp_core.c
+++ b/drivers/pci/hotplug/acpiphp_core.c
@@ -91,10 +91,10 @@ static struct hotplug_slot_ops acpi_hotplug_slot_ops = {
91 * acpiphp_register_attention - set attention LED callback 91 * acpiphp_register_attention - set attention LED callback
92 * @info: must be completely filled with LED callbacks 92 * @info: must be completely filled with LED callbacks
93 * 93 *
94 * Description: this is used to register a hardware specific ACPI 94 * Description: This is used to register a hardware specific ACPI
95 * driver that manipulates the attention LED. All the fields in 95 * driver that manipulates the attention LED. All the fields in
96 * info must be set. 96 * info must be set.
97 **/ 97 */
98int acpiphp_register_attention(struct acpiphp_attention_info *info) 98int acpiphp_register_attention(struct acpiphp_attention_info *info)
99{ 99{
100 int retval = -EINVAL; 100 int retval = -EINVAL;
@@ -112,10 +112,10 @@ int acpiphp_register_attention(struct acpiphp_attention_info *info)
112 * acpiphp_unregister_attention - unset attention LED callback 112 * acpiphp_unregister_attention - unset attention LED callback
113 * @info: must match the pointer used to register 113 * @info: must match the pointer used to register
114 * 114 *
115 * Description: this is used to un-register a hardware specific acpi 115 * Description: This is used to un-register a hardware specific acpi
116 * driver that manipulates the attention LED. The pointer to the 116 * driver that manipulates the attention LED. The pointer to the
117 * info struct must be the same as the one used to set it. 117 * info struct must be the same as the one used to set it.
118 **/ 118 */
119int acpiphp_unregister_attention(struct acpiphp_attention_info *info) 119int acpiphp_unregister_attention(struct acpiphp_attention_info *info)
120{ 120{
121 int retval = -EINVAL; 121 int retval = -EINVAL;
@@ -133,7 +133,6 @@ int acpiphp_unregister_attention(struct acpiphp_attention_info *info)
133 * @hotplug_slot: slot to enable 133 * @hotplug_slot: slot to enable
134 * 134 *
135 * Actual tasks are done in acpiphp_enable_slot() 135 * Actual tasks are done in acpiphp_enable_slot()
136 *
137 */ 136 */
138static int enable_slot(struct hotplug_slot *hotplug_slot) 137static int enable_slot(struct hotplug_slot *hotplug_slot)
139{ 138{
@@ -151,7 +150,6 @@ static int enable_slot(struct hotplug_slot *hotplug_slot)
151 * @hotplug_slot: slot to disable 150 * @hotplug_slot: slot to disable
152 * 151 *
153 * Actual tasks are done in acpiphp_disable_slot() 152 * Actual tasks are done in acpiphp_disable_slot()
154 *
155 */ 153 */
156static int disable_slot(struct hotplug_slot *hotplug_slot) 154static int disable_slot(struct hotplug_slot *hotplug_slot)
157{ 155{
@@ -168,15 +166,15 @@ static int disable_slot(struct hotplug_slot *hotplug_slot)
168} 166}
169 167
170 168
171 /** 169/**
172 * set_attention_status - set attention LED 170 * set_attention_status - set attention LED
173 * @hotplug_slot: slot to set attention LED on 171 * @hotplug_slot: slot to set attention LED on
174 * @status: value to set attention LED to (0 or 1) 172 * @status: value to set attention LED to (0 or 1)
175 * 173 *
176 * attention status LED, so we use a callback that 174 * attention status LED, so we use a callback that
177 * was registered with us. This allows hardware specific 175 * was registered with us. This allows hardware specific
178 * ACPI implementations to blink the light for us. 176 * ACPI implementations to blink the light for us.
179 **/ 177 */
180 static int set_attention_status(struct hotplug_slot *hotplug_slot, u8 status) 178 static int set_attention_status(struct hotplug_slot *hotplug_slot, u8 status)
181 { 179 {
182 int retval = -ENODEV; 180 int retval = -ENODEV;
@@ -199,7 +197,6 @@ static int disable_slot(struct hotplug_slot *hotplug_slot)
199 * 197 *
200 * Some platforms may not implement _STA method properly. 198 * Some platforms may not implement _STA method properly.
201 * In that case, the value returned may not be reliable. 199 * In that case, the value returned may not be reliable.
202 *
203 */ 200 */
204static int get_power_status(struct hotplug_slot *hotplug_slot, u8 *value) 201static int get_power_status(struct hotplug_slot *hotplug_slot, u8 *value)
205{ 202{
@@ -213,7 +210,7 @@ static int get_power_status(struct hotplug_slot *hotplug_slot, u8 *value)
213} 210}
214 211
215 212
216 /** 213/**
217 * get_attention_status - get attention LED status 214 * get_attention_status - get attention LED status
218 * @hotplug_slot: slot to get status from 215 * @hotplug_slot: slot to get status from
219 * @value: returns with value of attention LED 216 * @value: returns with value of attention LED
@@ -221,8 +218,8 @@ static int get_power_status(struct hotplug_slot *hotplug_slot, u8 *value)
221 * ACPI doesn't have known method to determine the state 218 * ACPI doesn't have known method to determine the state
222 * of the attention status LED, so we use a callback that 219 * of the attention status LED, so we use a callback that
223 * was registered with us. This allows hardware specific 220 * was registered with us. This allows hardware specific
224 * ACPI implementations to determine its state 221 * ACPI implementations to determine its state.
225 **/ 222 */
226static int get_attention_status(struct hotplug_slot *hotplug_slot, u8 *value) 223static int get_attention_status(struct hotplug_slot *hotplug_slot, u8 *value)
227{ 224{
228 int retval = -EINVAL; 225 int retval = -EINVAL;
@@ -244,8 +241,7 @@ static int get_attention_status(struct hotplug_slot *hotplug_slot, u8 *value)
244 * @value: pointer to store status 241 * @value: pointer to store status
245 * 242 *
246 * ACPI doesn't provide any formal means to access latch status. 243 * ACPI doesn't provide any formal means to access latch status.
247 * Instead, we fake latch status from _STA 244 * Instead, we fake latch status from _STA.
248 *
249 */ 245 */
250static int get_latch_status(struct hotplug_slot *hotplug_slot, u8 *value) 246static int get_latch_status(struct hotplug_slot *hotplug_slot, u8 *value)
251{ 247{
@@ -265,8 +261,7 @@ static int get_latch_status(struct hotplug_slot *hotplug_slot, u8 *value)
265 * @value: pointer to store status 261 * @value: pointer to store status
266 * 262 *
267 * ACPI doesn't provide any formal means to access adapter status. 263 * ACPI doesn't provide any formal means to access adapter status.
268 * Instead, we fake adapter status from _STA 264 * Instead, we fake adapter status from _STA.
269 *
270 */ 265 */
271static int get_adapter_status(struct hotplug_slot *hotplug_slot, u8 *value) 266static int get_adapter_status(struct hotplug_slot *hotplug_slot, u8 *value)
272{ 267{
diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c
index 1e125b56c9a9..ff1b1c71291a 100644
--- a/drivers/pci/hotplug/acpiphp_glue.c
+++ b/drivers/pci/hotplug/acpiphp_glue.c
@@ -82,7 +82,6 @@ static void handle_hotplug_event_func(acpi_handle handle, u32 type, void *contex
82 * 2. has _PS0 method 82 * 2. has _PS0 method
83 * 3. has _PS3 method 83 * 3. has _PS3 method
84 * 4. .. 84 * 4. ..
85 *
86 */ 85 */
87static int is_ejectable(acpi_handle handle) 86static int is_ejectable(acpi_handle handle)
88{ 87{
@@ -986,10 +985,8 @@ static int power_off_slot(struct acpiphp_slot *slot)
986 985
987 986
988/** 987/**
989 * acpiphp_max_busnr - return the highest reserved bus number under 988 * acpiphp_max_busnr - return the highest reserved bus number under the given bus.
990 * the given bus.
991 * @bus: bus to start search with 989 * @bus: bus to start search with
992 *
993 */ 990 */
994static unsigned char acpiphp_max_busnr(struct pci_bus *bus) 991static unsigned char acpiphp_max_busnr(struct pci_bus *bus)
995{ 992{
@@ -1018,7 +1015,6 @@ static unsigned char acpiphp_max_busnr(struct pci_bus *bus)
1018/** 1015/**
1019 * acpiphp_bus_add - add a new bus to acpi subsystem 1016 * acpiphp_bus_add - add a new bus to acpi subsystem
1020 * @func: acpiphp_func of the bridge 1017 * @func: acpiphp_func of the bridge
1021 *
1022 */ 1018 */
1023static int acpiphp_bus_add(struct acpiphp_func *func) 1019static int acpiphp_bus_add(struct acpiphp_func *func)
1024{ 1020{
@@ -1063,7 +1059,6 @@ acpiphp_bus_add_out:
1063/** 1059/**
1064 * acpiphp_bus_trim - trim a bus from acpi subsystem 1060 * acpiphp_bus_trim - trim a bus from acpi subsystem
1065 * @handle: handle to acpi namespace 1061 * @handle: handle to acpi namespace
1066 *
1067 */ 1062 */
1068static int acpiphp_bus_trim(acpi_handle handle) 1063static int acpiphp_bus_trim(acpi_handle handle)
1069{ 1064{
@@ -1089,7 +1084,6 @@ static int acpiphp_bus_trim(acpi_handle handle)
1089 * 1084 *
1090 * This function should be called per *physical slot*, 1085 * This function should be called per *physical slot*,
1091 * not per each slot object in ACPI namespace. 1086 * not per each slot object in ACPI namespace.
1092 *
1093 */ 1087 */
1094static int enable_device(struct acpiphp_slot *slot) 1088static int enable_device(struct acpiphp_slot *slot)
1095{ 1089{
@@ -1185,6 +1179,7 @@ static void disable_bridges(struct pci_bus *bus)
1185 1179
1186/** 1180/**
1187 * disable_device - disable a slot 1181 * disable_device - disable a slot
1182 * @slot: ACPI PHP slot
1188 */ 1183 */
1189static int disable_device(struct acpiphp_slot *slot) 1184static int disable_device(struct acpiphp_slot *slot)
1190{ 1185{
@@ -1240,14 +1235,15 @@ static int disable_device(struct acpiphp_slot *slot)
1240 1235
1241/** 1236/**
1242 * get_slot_status - get ACPI slot status 1237 * get_slot_status - get ACPI slot status
1238 * @slot: ACPI PHP slot
1243 * 1239 *
1244 * if a slot has _STA for each function and if any one of them 1240 * If a slot has _STA for each function and if any one of them
1245 * returned non-zero status, return it 1241 * returned non-zero status, return it.
1246 * 1242 *
1247 * if a slot doesn't have _STA and if any one of its functions' 1243 * If a slot doesn't have _STA and if any one of its functions'
1248 * configuration space is configured, return 0x0f as a _STA 1244 * configuration space is configured, return 0x0f as a _STA.
1249 * 1245 *
1250 * otherwise return 0 1246 * Otherwise return 0.
1251 */ 1247 */
1252static unsigned int get_slot_status(struct acpiphp_slot *slot) 1248static unsigned int get_slot_status(struct acpiphp_slot *slot)
1253{ 1249{
@@ -1281,6 +1277,7 @@ static unsigned int get_slot_status(struct acpiphp_slot *slot)
1281 1277
1282/** 1278/**
1283 * acpiphp_eject_slot - physically eject the slot 1279 * acpiphp_eject_slot - physically eject the slot
1280 * @slot: ACPI PHP slot
1284 */ 1281 */
1285int acpiphp_eject_slot(struct acpiphp_slot *slot) 1282int acpiphp_eject_slot(struct acpiphp_slot *slot)
1286{ 1283{
@@ -1314,6 +1311,7 @@ int acpiphp_eject_slot(struct acpiphp_slot *slot)
1314 1311
1315/** 1312/**
1316 * acpiphp_check_bridge - re-enumerate devices 1313 * acpiphp_check_bridge - re-enumerate devices
1314 * @bridge: where to begin re-enumeration
1317 * 1315 *
1318 * Iterate over all slots under this bridge and make sure that if a 1316 * Iterate over all slots under this bridge and make sure that if a
1319 * card is present they are enabled, and if not they are disabled. 1317 * card is present they are enabled, and if not they are disabled.
@@ -1538,13 +1536,11 @@ check_sub_bridges(acpi_handle handle, u32 lvl, void *context, void **rv)
1538 1536
1539/** 1537/**
1540 * handle_hotplug_event_bridge - handle ACPI event on bridges 1538 * handle_hotplug_event_bridge - handle ACPI event on bridges
1541 *
1542 * @handle: Notify()'ed acpi_handle 1539 * @handle: Notify()'ed acpi_handle
1543 * @type: Notify code 1540 * @type: Notify code
1544 * @context: pointer to acpiphp_bridge structure 1541 * @context: pointer to acpiphp_bridge structure
1545 * 1542 *
1546 * handles ACPI event notification on {host,p2p} bridges 1543 * Handles ACPI event notification on {host,p2p} bridges.
1547 *
1548 */ 1544 */
1549static void handle_hotplug_event_bridge(acpi_handle handle, u32 type, void *context) 1545static void handle_hotplug_event_bridge(acpi_handle handle, u32 type, void *context)
1550{ 1546{
@@ -1634,13 +1630,11 @@ static void handle_hotplug_event_bridge(acpi_handle handle, u32 type, void *cont
1634 1630
1635/** 1631/**
1636 * handle_hotplug_event_func - handle ACPI event on functions (i.e. slots) 1632 * handle_hotplug_event_func - handle ACPI event on functions (i.e. slots)
1637 *
1638 * @handle: Notify()'ed acpi_handle 1633 * @handle: Notify()'ed acpi_handle
1639 * @type: Notify code 1634 * @type: Notify code
1640 * @context: pointer to acpiphp_func structure 1635 * @context: pointer to acpiphp_func structure
1641 * 1636 *
1642 * handles ACPI event notification on slots 1637 * Handles ACPI event notification on slots.
1643 *
1644 */ 1638 */
1645static void handle_hotplug_event_func(acpi_handle handle, u32 type, void *context) 1639static void handle_hotplug_event_func(acpi_handle handle, u32 type, void *context)
1646{ 1640{
@@ -1705,7 +1699,6 @@ static struct acpi_pci_driver acpi_pci_hp_driver = {
1705 1699
1706/** 1700/**
1707 * acpiphp_glue_init - initializes all PCI hotplug - ACPI glue data structures 1701 * acpiphp_glue_init - initializes all PCI hotplug - ACPI glue data structures
1708 *
1709 */ 1702 */
1710int __init acpiphp_glue_init(void) 1703int __init acpiphp_glue_init(void)
1711{ 1704{
@@ -1726,7 +1719,7 @@ int __init acpiphp_glue_init(void)
1726/** 1719/**
1727 * acpiphp_glue_exit - terminates all PCI hotplug - ACPI glue data structures 1720 * acpiphp_glue_exit - terminates all PCI hotplug - ACPI glue data structures
1728 * 1721 *
1729 * This function frees all data allocated in acpiphp_glue_init() 1722 * This function frees all data allocated in acpiphp_glue_init().
1730 */ 1723 */
1731void acpiphp_glue_exit(void) 1724void acpiphp_glue_exit(void)
1732{ 1725{
@@ -1760,7 +1753,6 @@ int __init acpiphp_get_num_slots(void)
1760 * acpiphp_for_each_slot - call function for each slot 1753 * acpiphp_for_each_slot - call function for each slot
1761 * @fn: callback function 1754 * @fn: callback function
1762 * @data: context to be passed to callback function 1755 * @data: context to be passed to callback function
1763 *
1764 */ 1756 */
1765static int acpiphp_for_each_slot(acpiphp_callback fn, void *data) 1757static int acpiphp_for_each_slot(acpiphp_callback fn, void *data)
1766{ 1758{
@@ -1786,6 +1778,7 @@ static int acpiphp_for_each_slot(acpiphp_callback fn, void *data)
1786 1778
1787/** 1779/**
1788 * acpiphp_enable_slot - power on slot 1780 * acpiphp_enable_slot - power on slot
1781 * @slot: ACPI PHP slot
1789 */ 1782 */
1790int acpiphp_enable_slot(struct acpiphp_slot *slot) 1783int acpiphp_enable_slot(struct acpiphp_slot *slot)
1791{ 1784{
@@ -1815,6 +1808,7 @@ int acpiphp_enable_slot(struct acpiphp_slot *slot)
1815 1808
1816/** 1809/**
1817 * acpiphp_disable_slot - power off slot 1810 * acpiphp_disable_slot - power off slot
1811 * @slot: ACPI PHP slot
1818 */ 1812 */
1819int acpiphp_disable_slot(struct acpiphp_slot *slot) 1813int acpiphp_disable_slot(struct acpiphp_slot *slot)
1820{ 1814{
diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
index 56829f82be4a..47d26b65e99a 100644
--- a/drivers/pci/hotplug/acpiphp_ibm.c
+++ b/drivers/pci/hotplug/acpiphp_ibm.c
@@ -134,11 +134,11 @@ static struct acpiphp_attention_info ibm_attention_info =
134 * ibm_slot_from_id - workaround for bad ibm hardware 134 * ibm_slot_from_id - workaround for bad ibm hardware
135 * @id: the slot number that linux refers to the slot by 135 * @id: the slot number that linux refers to the slot by
136 * 136 *
137 * Description: this method returns the aCPI slot descriptor 137 * Description: This method returns the aCPI slot descriptor
138 * corresponding to the Linux slot number. This descriptor 138 * corresponding to the Linux slot number. This descriptor
139 * has info about the aPCI slot id and attention status. 139 * has info about the aPCI slot id and attention status.
140 * This descriptor must be freed using kfree when done. 140 * This descriptor must be freed using kfree when done.
141 **/ 141 */
142static union apci_descriptor *ibm_slot_from_id(int id) 142static union apci_descriptor *ibm_slot_from_id(int id)
143{ 143{
144 int ind = 0, size; 144 int ind = 0, size;
@@ -173,9 +173,9 @@ ibm_slot_done:
173 * @slot: the hotplug_slot to work with 173 * @slot: the hotplug_slot to work with
174 * @status: what to set the LED to (0 or 1) 174 * @status: what to set the LED to (0 or 1)
175 * 175 *
176 * Description: this method is registered with the acpiphp module as a 176 * Description: This method is registered with the acpiphp module as a
177 * callback to do the device specific task of setting the LED status 177 * callback to do the device specific task of setting the LED status.
178 **/ 178 */
179static int ibm_set_attention_status(struct hotplug_slot *slot, u8 status) 179static int ibm_set_attention_status(struct hotplug_slot *slot, u8 status)
180{ 180{
181 union acpi_object args[2]; 181 union acpi_object args[2];
@@ -213,13 +213,13 @@ static int ibm_set_attention_status(struct hotplug_slot *slot, u8 status)
213 * @slot: the hotplug_slot to work with 213 * @slot: the hotplug_slot to work with
214 * @status: returns what the LED is set to (0 or 1) 214 * @status: returns what the LED is set to (0 or 1)
215 * 215 *
216 * Description: this method is registered with the acpiphp module as a 216 * Description: This method is registered with the acpiphp module as a
217 * callback to do the device specific task of getting the LED status 217 * callback to do the device specific task of getting the LED status.
218 * 218 *
219 * Because there is no direct method of getting the LED status directly 219 * Because there is no direct method of getting the LED status directly
220 * from an ACPI call, we read the aPCI table and parse out our 220 * from an ACPI call, we read the aPCI table and parse out our
221 * slot descriptor to read the status from that. 221 * slot descriptor to read the status from that.
222 **/ 222 */
223static int ibm_get_attention_status(struct hotplug_slot *slot, u8 *status) 223static int ibm_get_attention_status(struct hotplug_slot *slot, u8 *status)
224{ 224{
225 union apci_descriptor *ibm_slot; 225 union apci_descriptor *ibm_slot;
@@ -245,8 +245,8 @@ static int ibm_get_attention_status(struct hotplug_slot *slot, u8 *status)
245 * @event: the event info (device specific) 245 * @event: the event info (device specific)
246 * @context: passed context (our notification struct) 246 * @context: passed context (our notification struct)
247 * 247 *
248 * Description: this method is registered as a callback with the ACPI 248 * Description: This method is registered as a callback with the ACPI
249 * subsystem it is called when this device has an event to notify the OS of 249 * subsystem it is called when this device has an event to notify the OS of.
250 * 250 *
251 * The events actually come from the device as two events that get 251 * The events actually come from the device as two events that get
252 * synthesized into one event with data by this function. The event 252 * synthesized into one event with data by this function. The event
@@ -256,7 +256,7 @@ static int ibm_get_attention_status(struct hotplug_slot *slot, u8 *status)
256 * From section 5.6.2.2 of the ACPI 2.0 spec, I understand that the OSPM will 256 * From section 5.6.2.2 of the ACPI 2.0 spec, I understand that the OSPM will
257 * only re-enable the interrupt that causes this event AFTER this method 257 * only re-enable the interrupt that causes this event AFTER this method
258 * has returned, thereby enforcing serial access for the notification struct. 258 * has returned, thereby enforcing serial access for the notification struct.
259 **/ 259 */
260static void ibm_handle_events(acpi_handle handle, u32 event, void *context) 260static void ibm_handle_events(acpi_handle handle, u32 event, void *context)
261{ 261{
262 u8 detail = event & 0x0f; 262 u8 detail = event & 0x0f;
@@ -279,16 +279,16 @@ static void ibm_handle_events(acpi_handle handle, u32 event, void *context)
279 * ibm_get_table_from_acpi - reads the APLS buffer from ACPI 279 * ibm_get_table_from_acpi - reads the APLS buffer from ACPI
280 * @bufp: address to pointer to allocate for the table 280 * @bufp: address to pointer to allocate for the table
281 * 281 *
282 * Description: this method reads the APLS buffer in from ACPI and 282 * Description: This method reads the APLS buffer in from ACPI and
283 * stores the "stripped" table into a single buffer 283 * stores the "stripped" table into a single buffer
284 * it allocates and passes the address back in bufp 284 * it allocates and passes the address back in bufp.
285 * 285 *
286 * If NULL is passed in as buffer, this method only calculates 286 * If NULL is passed in as buffer, this method only calculates
287 * the size of the table and returns that without filling 287 * the size of the table and returns that without filling
288 * in the buffer 288 * in the buffer.
289 * 289 *
290 * returns < 0 on error or the size of the table on success 290 * Returns < 0 on error or the size of the table on success.
291 **/ 291 */
292static int ibm_get_table_from_acpi(char **bufp) 292static int ibm_get_table_from_acpi(char **bufp)
293{ 293{
294 union acpi_object *package; 294 union acpi_object *package;
@@ -349,17 +349,18 @@ read_table_done:
349/** 349/**
350 * ibm_read_apci_table - callback for the sysfs apci_table file 350 * ibm_read_apci_table - callback for the sysfs apci_table file
351 * @kobj: the kobject this binary attribute is a part of 351 * @kobj: the kobject this binary attribute is a part of
352 * @bin_attr: struct bin_attribute for this file
352 * @buffer: the kernel space buffer to fill 353 * @buffer: the kernel space buffer to fill
353 * @pos: the offset into the file 354 * @pos: the offset into the file
354 * @size: the number of bytes requested 355 * @size: the number of bytes requested
355 * 356 *
356 * Description: gets registered with sysfs as the reader callback 357 * Description: Gets registered with sysfs as the reader callback
357 * to be executed when /sys/bus/pci/slots/apci_table gets read 358 * to be executed when /sys/bus/pci/slots/apci_table gets read.
358 * 359 *
359 * Since we don't get notified on open and close for this file, 360 * Since we don't get notified on open and close for this file,
360 * things get really tricky here... 361 * things get really tricky here...
361 * our solution is to only allow reading the table in all at once 362 * our solution is to only allow reading the table in all at once.
362 **/ 363 */
363static ssize_t ibm_read_apci_table(struct kobject *kobj, 364static ssize_t ibm_read_apci_table(struct kobject *kobj,
364 struct bin_attribute *bin_attr, 365 struct bin_attribute *bin_attr,
365 char *buffer, loff_t pos, size_t size) 366 char *buffer, loff_t pos, size_t size)
@@ -385,10 +386,10 @@ static ssize_t ibm_read_apci_table(struct kobject *kobj,
385 * @context: a pointer to our handle to fill when we find the device 386 * @context: a pointer to our handle to fill when we find the device
386 * @rv: a return value to fill if desired 387 * @rv: a return value to fill if desired
387 * 388 *
388 * Description: used as a callback when calling acpi_walk_namespace 389 * Description: Used as a callback when calling acpi_walk_namespace
389 * to find our device. When this method returns non-zero 390 * to find our device. When this method returns non-zero
390 * acpi_walk_namespace quits its search and returns our value 391 * acpi_walk_namespace quits its search and returns our value.
391 **/ 392 */
392static acpi_status __init ibm_find_acpi_device(acpi_handle handle, 393static acpi_status __init ibm_find_acpi_device(acpi_handle handle,
393 u32 lvl, void *context, void **rv) 394 u32 lvl, void *context, void **rv)
394{ 395{
diff --git a/drivers/pci/hotplug/cpqphp_core.c b/drivers/pci/hotplug/cpqphp_core.c
index a96b739b2d35..74178875b949 100644
--- a/drivers/pci/hotplug/cpqphp_core.c
+++ b/drivers/pci/hotplug/cpqphp_core.c
@@ -117,12 +117,10 @@ static inline int is_slot66mhz(struct slot *slot)
117 117
118/** 118/**
119 * detect_SMBIOS_pointer - find the System Management BIOS Table in mem region. 119 * detect_SMBIOS_pointer - find the System Management BIOS Table in mem region.
120 *
121 * @begin: begin pointer for region to be scanned. 120 * @begin: begin pointer for region to be scanned.
122 * @end: end pointer for region to be scanned. 121 * @end: end pointer for region to be scanned.
123 * 122 *
124 * Returns pointer to the head of the SMBIOS tables (or NULL) 123 * Returns pointer to the head of the SMBIOS tables (or %NULL).
125 *
126 */ 124 */
127static void __iomem * detect_SMBIOS_pointer(void __iomem *begin, void __iomem *end) 125static void __iomem * detect_SMBIOS_pointer(void __iomem *begin, void __iomem *end)
128{ 126{
@@ -157,9 +155,9 @@ static void __iomem * detect_SMBIOS_pointer(void __iomem *begin, void __iomem *e
157 155
158/** 156/**
159 * init_SERR - Initializes the per slot SERR generation. 157 * init_SERR - Initializes the per slot SERR generation.
158 * @ctrl: controller to use
160 * 159 *
161 * For unexpected switch opens 160 * For unexpected switch opens
162 *
163 */ 161 */
164static int init_SERR(struct controller * ctrl) 162static int init_SERR(struct controller * ctrl)
165{ 163{
@@ -224,14 +222,15 @@ static int pci_print_IRQ_route (void)
224 222
225/** 223/**
226 * get_subsequent_smbios_entry: get the next entry from bios table. 224 * get_subsequent_smbios_entry: get the next entry from bios table.
227 * 225 * @smbios_start: where to start in the SMBIOS table
228 * Gets the first entry if previous == NULL 226 * @smbios_table: location of the SMBIOS table
229 * Otherwise, returns the next entry
230 * Uses global SMBIOS Table pointer
231 *
232 * @curr: %NULL or pointer to previously returned structure 227 * @curr: %NULL or pointer to previously returned structure
233 * 228 *
234 * returns a pointer to an SMBIOS structure or NULL if none found 229 * Gets the first entry if previous == NULL;
230 * otherwise, returns the next entry.
231 * Uses global SMBIOS Table pointer.
232 *
233 * Returns a pointer to an SMBIOS structure or NULL if none found.
235 */ 234 */
236static void __iomem *get_subsequent_smbios_entry(void __iomem *smbios_start, 235static void __iomem *get_subsequent_smbios_entry(void __iomem *smbios_start,
237 void __iomem *smbios_table, 236 void __iomem *smbios_table,
@@ -272,17 +271,18 @@ static void __iomem *get_subsequent_smbios_entry(void __iomem *smbios_start,
272 271
273 272
274/** 273/**
275 * get_SMBIOS_entry 274 * get_SMBIOS_entry - return the requested SMBIOS entry or %NULL
276 * 275 * @smbios_start: where to start in the SMBIOS table
277 * @type:SMBIOS structure type to be returned 276 * @smbios_table: location of the SMBIOS table
277 * @type: SMBIOS structure type to be returned
278 * @previous: %NULL or pointer to previously returned structure 278 * @previous: %NULL or pointer to previously returned structure
279 * 279 *
280 * Gets the first entry of the specified type if previous == NULL 280 * Gets the first entry of the specified type if previous == %NULL;
281 * Otherwise, returns the next entry of the given type. 281 * Otherwise, returns the next entry of the given type.
282 * Uses global SMBIOS Table pointer 282 * Uses global SMBIOS Table pointer.
283 * Uses get_subsequent_smbios_entry 283 * Uses get_subsequent_smbios_entry.
284 * 284 *
285 * returns a pointer to an SMBIOS structure or %NULL if none found 285 * Returns a pointer to an SMBIOS structure or %NULL if none found.
286 */ 286 */
287static void __iomem *get_SMBIOS_entry(void __iomem *smbios_start, 287static void __iomem *get_SMBIOS_entry(void __iomem *smbios_start,
288 void __iomem *smbios_table, 288 void __iomem *smbios_table,
@@ -581,7 +581,9 @@ get_slot_mapping(struct pci_bus *bus, u8 bus_num, u8 dev_num, u8 *slot)
581 581
582/** 582/**
583 * cpqhp_set_attention_status - Turns the Amber LED for a slot on or off 583 * cpqhp_set_attention_status - Turns the Amber LED for a slot on or off
584 * 584 * @ctrl: struct controller to use
585 * @func: PCI device/function info
586 * @status: LED control flag: 1 = LED on, 0 = LED off
585 */ 587 */
586static int 588static int
587cpqhp_set_attention_status(struct controller *ctrl, struct pci_func *func, 589cpqhp_set_attention_status(struct controller *ctrl, struct pci_func *func,
@@ -621,7 +623,8 @@ cpqhp_set_attention_status(struct controller *ctrl, struct pci_func *func,
621 623
622/** 624/**
623 * set_attention_status - Turns the Amber LED for a slot on or off 625 * set_attention_status - Turns the Amber LED for a slot on or off
624 * 626 * @hotplug_slot: slot to change LED on
627 * @status: LED control flag
625 */ 628 */
626static int set_attention_status (struct hotplug_slot *hotplug_slot, u8 status) 629static int set_attention_status (struct hotplug_slot *hotplug_slot, u8 status)
627{ 630{
diff --git a/drivers/pci/hotplug/cpqphp_ctrl.c b/drivers/pci/hotplug/cpqphp_ctrl.c
index 856d57b4d604..4018420c6f95 100644
--- a/drivers/pci/hotplug/cpqphp_ctrl.c
+++ b/drivers/pci/hotplug/cpqphp_ctrl.c
@@ -123,7 +123,7 @@ static u8 handle_switch_change(u8 change, struct controller * ctrl)
123} 123}
124 124
125/** 125/**
126 * cpqhp_find_slot: find the struct slot of given device 126 * cpqhp_find_slot - find the struct slot of given device
127 * @ctrl: scan lots of this controller 127 * @ctrl: scan lots of this controller
128 * @device: the device id to find 128 * @device: the device id to find
129 */ 129 */
@@ -305,9 +305,8 @@ static u8 handle_power_fault(u8 change, struct controller * ctrl)
305 305
306 306
307/** 307/**
308 * sort_by_size: sort nodes on the list by their length, smallest first. 308 * sort_by_size - sort nodes on the list by their length, smallest first.
309 * @head: list to sort 309 * @head: list to sort
310 *
311 */ 310 */
312static int sort_by_size(struct pci_resource **head) 311static int sort_by_size(struct pci_resource **head)
313{ 312{
@@ -354,9 +353,8 @@ static int sort_by_size(struct pci_resource **head)
354 353
355 354
356/** 355/**
357 * sort_by_max_size: sort nodes on the list by their length, largest first. 356 * sort_by_max_size - sort nodes on the list by their length, largest first.
358 * @head: list to sort 357 * @head: list to sort
359 *
360 */ 358 */
361static int sort_by_max_size(struct pci_resource **head) 359static int sort_by_max_size(struct pci_resource **head)
362{ 360{
@@ -403,8 +401,10 @@ static int sort_by_max_size(struct pci_resource **head)
403 401
404 402
405/** 403/**
406 * do_pre_bridge_resource_split: find node of resources that are unused 404 * do_pre_bridge_resource_split - find node of resources that are unused
407 * 405 * @head: new list head
406 * @orig_head: original list head
407 * @alignment: max node size (?)
408 */ 408 */
409static struct pci_resource *do_pre_bridge_resource_split(struct pci_resource **head, 409static struct pci_resource *do_pre_bridge_resource_split(struct pci_resource **head,
410 struct pci_resource **orig_head, u32 alignment) 410 struct pci_resource **orig_head, u32 alignment)
@@ -477,8 +477,9 @@ static struct pci_resource *do_pre_bridge_resource_split(struct pci_resource **h
477 477
478 478
479/** 479/**
480 * do_bridge_resource_split: find one node of resources that aren't in use 480 * do_bridge_resource_split - find one node of resources that aren't in use
481 * 481 * @head: list head
482 * @alignment: max node size (?)
482 */ 483 */
483static struct pci_resource *do_bridge_resource_split(struct pci_resource **head, u32 alignment) 484static struct pci_resource *do_bridge_resource_split(struct pci_resource **head, u32 alignment)
484{ 485{
@@ -525,14 +526,13 @@ error:
525 526
526 527
527/** 528/**
528 * get_io_resource: find first node of given size not in ISA aliasing window. 529 * get_io_resource - find first node of given size not in ISA aliasing window.
529 * @head: list to search 530 * @head: list to search
530 * @size: size of node to find, must be a power of two. 531 * @size: size of node to find, must be a power of two.
531 * 532 *
532 * Description: this function sorts the resource list by size and then returns 533 * Description: This function sorts the resource list by size and then returns
533 * returns the first node of "size" length that is not in the ISA aliasing 534 * returns the first node of "size" length that is not in the ISA aliasing
534 * window. If it finds a node larger than "size" it will split it up. 535 * window. If it finds a node larger than "size" it will split it up.
535 *
536 */ 536 */
537static struct pci_resource *get_io_resource(struct pci_resource **head, u32 size) 537static struct pci_resource *get_io_resource(struct pci_resource **head, u32 size)
538{ 538{
@@ -620,7 +620,7 @@ static struct pci_resource *get_io_resource(struct pci_resource **head, u32 size
620 620
621 621
622/** 622/**
623 * get_max_resource: get largest node which has at least the given size. 623 * get_max_resource - get largest node which has at least the given size.
624 * @head: the list to search the node in 624 * @head: the list to search the node in
625 * @size: the minimum size of the node to find 625 * @size: the minimum size of the node to find
626 * 626 *
@@ -712,7 +712,7 @@ static struct pci_resource *get_max_resource(struct pci_resource **head, u32 siz
712 712
713 713
714/** 714/**
715 * get_resource: find resource of given size and split up larger ones. 715 * get_resource - find resource of given size and split up larger ones.
716 * @head: the list to search for resources 716 * @head: the list to search for resources
717 * @size: the size limit to use 717 * @size: the size limit to use
718 * 718 *
@@ -804,14 +804,14 @@ static struct pci_resource *get_resource(struct pci_resource **head, u32 size)
804 804
805 805
806/** 806/**
807 * cpqhp_resource_sort_and_combine: sort nodes by base addresses and clean up. 807 * cpqhp_resource_sort_and_combine - sort nodes by base addresses and clean up
808 * @head: the list to sort and clean up 808 * @head: the list to sort and clean up
809 * 809 *
810 * Description: Sorts all of the nodes in the list in ascending order by 810 * Description: Sorts all of the nodes in the list in ascending order by
811 * their base addresses. Also does garbage collection by 811 * their base addresses. Also does garbage collection by
812 * combining adjacent nodes. 812 * combining adjacent nodes.
813 * 813 *
814 * returns 0 if success 814 * Returns %0 if success.
815 */ 815 */
816int cpqhp_resource_sort_and_combine(struct pci_resource **head) 816int cpqhp_resource_sort_and_combine(struct pci_resource **head)
817{ 817{
@@ -951,9 +951,9 @@ irqreturn_t cpqhp_ctrl_intr(int IRQ, void *data)
951 951
952/** 952/**
953 * cpqhp_slot_create - Creates a node and adds it to the proper bus. 953 * cpqhp_slot_create - Creates a node and adds it to the proper bus.
954 * @busnumber - bus where new node is to be located 954 * @busnumber: bus where new node is to be located
955 * 955 *
956 * Returns pointer to the new node or NULL if unsuccessful 956 * Returns pointer to the new node or %NULL if unsuccessful.
957 */ 957 */
958struct pci_func *cpqhp_slot_create(u8 busnumber) 958struct pci_func *cpqhp_slot_create(u8 busnumber)
959{ 959{
@@ -986,7 +986,7 @@ struct pci_func *cpqhp_slot_create(u8 busnumber)
986 * slot_remove - Removes a node from the linked list of slots. 986 * slot_remove - Removes a node from the linked list of slots.
987 * @old_slot: slot to remove 987 * @old_slot: slot to remove
988 * 988 *
989 * Returns 0 if successful, !0 otherwise. 989 * Returns %0 if successful, !0 otherwise.
990 */ 990 */
991static int slot_remove(struct pci_func * old_slot) 991static int slot_remove(struct pci_func * old_slot)
992{ 992{
@@ -1026,7 +1026,7 @@ static int slot_remove(struct pci_func * old_slot)
1026 * bridge_slot_remove - Removes a node from the linked list of slots. 1026 * bridge_slot_remove - Removes a node from the linked list of slots.
1027 * @bridge: bridge to remove 1027 * @bridge: bridge to remove
1028 * 1028 *
1029 * Returns 0 if successful, !0 otherwise. 1029 * Returns %0 if successful, !0 otherwise.
1030 */ 1030 */
1031static int bridge_slot_remove(struct pci_func *bridge) 1031static int bridge_slot_remove(struct pci_func *bridge)
1032{ 1032{
@@ -1071,7 +1071,7 @@ out:
1071 * cpqhp_slot_find - Looks for a node by bus, and device, multiple functions accessed 1071 * cpqhp_slot_find - Looks for a node by bus, and device, multiple functions accessed
1072 * @bus: bus to find 1072 * @bus: bus to find
1073 * @device: device to find 1073 * @device: device to find
1074 * @index: is 0 for first function found, 1 for the second... 1074 * @index: is %0 for first function found, %1 for the second...
1075 * 1075 *
1076 * Returns pointer to the node if successful, %NULL otherwise. 1076 * Returns pointer to the node if successful, %NULL otherwise.
1077 */ 1077 */
@@ -1115,16 +1115,13 @@ static int is_bridge(struct pci_func * func)
1115 1115
1116 1116
1117/** 1117/**
1118 * set_controller_speed - set the frequency and/or mode of a specific 1118 * set_controller_speed - set the frequency and/or mode of a specific controller segment.
1119 * controller segment.
1120 *
1121 * @ctrl: controller to change frequency/mode for. 1119 * @ctrl: controller to change frequency/mode for.
1122 * @adapter_speed: the speed of the adapter we want to match. 1120 * @adapter_speed: the speed of the adapter we want to match.
1123 * @hp_slot: the slot number where the adapter is installed. 1121 * @hp_slot: the slot number where the adapter is installed.
1124 * 1122 *
1125 * Returns 0 if we successfully change frequency and/or mode to match the 1123 * Returns %0 if we successfully change frequency and/or mode to match the
1126 * adapter speed. 1124 * adapter speed.
1127 *
1128 */ 1125 */
1129static u8 set_controller_speed(struct controller *ctrl, u8 adapter_speed, u8 hp_slot) 1126static u8 set_controller_speed(struct controller *ctrl, u8 adapter_speed, u8 hp_slot)
1130{ 1127{
@@ -1253,13 +1250,14 @@ static u8 set_controller_speed(struct controller *ctrl, u8 adapter_speed, u8 hp_
1253 1250
1254/** 1251/**
1255 * board_replaced - Called after a board has been replaced in the system. 1252 * board_replaced - Called after a board has been replaced in the system.
1253 * @func: PCI device/function information
1254 * @ctrl: hotplug controller
1256 * 1255 *
1257 * This is only used if we don't have resources for hot add 1256 * This is only used if we don't have resources for hot add.
1258 * Turns power on for the board 1257 * Turns power on for the board.
1259 * Checks to see if board is the same 1258 * Checks to see if board is the same.
1260 * If board is same, reconfigures it 1259 * If board is same, reconfigures it.
1261 * If board isn't same, turns it back off. 1260 * If board isn't same, turns it back off.
1262 *
1263 */ 1261 */
1264static u32 board_replaced(struct pci_func *func, struct controller *ctrl) 1262static u32 board_replaced(struct pci_func *func, struct controller *ctrl)
1265{ 1263{
@@ -1403,10 +1401,11 @@ static u32 board_replaced(struct pci_func *func, struct controller *ctrl)
1403 1401
1404/** 1402/**
1405 * board_added - Called after a board has been added to the system. 1403 * board_added - Called after a board has been added to the system.
1404 * @func: PCI device/function info
1405 * @ctrl: hotplug controller
1406 * 1406 *
1407 * Turns power on for the board 1407 * Turns power on for the board.
1408 * Configures board 1408 * Configures board.
1409 *
1410 */ 1409 */
1411static u32 board_added(struct pci_func *func, struct controller *ctrl) 1410static u32 board_added(struct pci_func *func, struct controller *ctrl)
1412{ 1411{
@@ -1607,8 +1606,10 @@ static u32 board_added(struct pci_func *func, struct controller *ctrl)
1607 1606
1608 1607
1609/** 1608/**
1610 * remove_board - Turns off slot and LED's 1609 * remove_board - Turns off slot and LEDs
1611 * 1610 * @func: PCI device/function info
1611 * @replace_flag: whether replacing or adding a new device
1612 * @ctrl: target controller
1612 */ 1613 */
1613static u32 remove_board(struct pci_func * func, u32 replace_flag, struct controller * ctrl) 1614static u32 remove_board(struct pci_func * func, u32 replace_flag, struct controller * ctrl)
1614{ 1615{
@@ -1902,11 +1903,11 @@ static void interrupt_event_handler(struct controller *ctrl)
1902 1903
1903 1904
1904/** 1905/**
1905 * cpqhp_pushbutton_thread 1906 * cpqhp_pushbutton_thread - handle pushbutton events
1907 * @slot: target slot (struct)
1906 * 1908 *
1907 * Scheduled procedure to handle blocking stuff for the pushbuttons 1909 * Scheduled procedure to handle blocking stuff for the pushbuttons.
1908 * Handles all pending events and exits. 1910 * Handles all pending events and exits.
1909 *
1910 */ 1911 */
1911void cpqhp_pushbutton_thread(unsigned long slot) 1912void cpqhp_pushbutton_thread(unsigned long slot)
1912{ 1913{
@@ -2137,9 +2138,10 @@ int cpqhp_process_SS(struct controller *ctrl, struct pci_func *func)
2137} 2138}
2138 2139
2139/** 2140/**
2140 * switch_leds: switch the leds, go from one site to the other. 2141 * switch_leds - switch the leds, go from one site to the other.
2141 * @ctrl: controller to use 2142 * @ctrl: controller to use
2142 * @num_of_slots: number of slots to use 2143 * @num_of_slots: number of slots to use
2144 * @work_LED: LED control value
2143 * @direction: 1 to start from the left side, 0 to start right. 2145 * @direction: 1 to start from the left side, 0 to start right.
2144 */ 2146 */
2145static void switch_leds(struct controller *ctrl, const int num_of_slots, 2147static void switch_leds(struct controller *ctrl, const int num_of_slots,
@@ -2165,11 +2167,11 @@ static void switch_leds(struct controller *ctrl, const int num_of_slots,
2165} 2167}
2166 2168
2167/** 2169/**
2168 * hardware_test - runs hardware tests 2170 * cpqhp_hardware_test - runs hardware tests
2171 * @ctrl: target controller
2172 * @test_num: the number written to the "test" file in sysfs.
2169 * 2173 *
2170 * For hot plug ctrl folks to play with. 2174 * For hot plug ctrl folks to play with.
2171 * test_num is the number written to the "test" file in sysfs
2172 *
2173 */ 2175 */
2174int cpqhp_hardware_test(struct controller *ctrl, int test_num) 2176int cpqhp_hardware_test(struct controller *ctrl, int test_num)
2175{ 2177{
@@ -2249,14 +2251,12 @@ int cpqhp_hardware_test(struct controller *ctrl, int test_num)
2249 2251
2250/** 2252/**
2251 * configure_new_device - Configures the PCI header information of one board. 2253 * configure_new_device - Configures the PCI header information of one board.
2252 *
2253 * @ctrl: pointer to controller structure 2254 * @ctrl: pointer to controller structure
2254 * @func: pointer to function structure 2255 * @func: pointer to function structure
2255 * @behind_bridge: 1 if this is a recursive call, 0 if not 2256 * @behind_bridge: 1 if this is a recursive call, 0 if not
2256 * @resources: pointer to set of resource lists 2257 * @resources: pointer to set of resource lists
2257 * 2258 *
2258 * Returns 0 if success 2259 * Returns 0 if success.
2259 *
2260 */ 2260 */
2261static u32 configure_new_device(struct controller * ctrl, struct pci_func * func, 2261static u32 configure_new_device(struct controller * ctrl, struct pci_func * func,
2262 u8 behind_bridge, struct resource_lists * resources) 2262 u8 behind_bridge, struct resource_lists * resources)
@@ -2346,15 +2346,13 @@ static u32 configure_new_device(struct controller * ctrl, struct pci_func * func
2346 2346
2347/** 2347/**
2348 * configure_new_function - Configures the PCI header information of one device 2348 * configure_new_function - Configures the PCI header information of one device
2349 *
2350 * @ctrl: pointer to controller structure 2349 * @ctrl: pointer to controller structure
2351 * @func: pointer to function structure 2350 * @func: pointer to function structure
2352 * @behind_bridge: 1 if this is a recursive call, 0 if not 2351 * @behind_bridge: 1 if this is a recursive call, 0 if not
2353 * @resources: pointer to set of resource lists 2352 * @resources: pointer to set of resource lists
2354 * 2353 *
2355 * Calls itself recursively for bridged devices. 2354 * Calls itself recursively for bridged devices.
2356 * Returns 0 if success 2355 * Returns 0 if success.
2357 *
2358 */ 2356 */
2359static int configure_new_function(struct controller *ctrl, struct pci_func *func, 2357static int configure_new_function(struct controller *ctrl, struct pci_func *func,
2360 u8 behind_bridge, 2358 u8 behind_bridge,
diff --git a/drivers/pci/hotplug/fakephp.c b/drivers/pci/hotplug/fakephp.c
index 027f6865d7e3..d7a293e3faf5 100644
--- a/drivers/pci/hotplug/fakephp.c
+++ b/drivers/pci/hotplug/fakephp.c
@@ -165,11 +165,11 @@ static void remove_slot(struct dummy_slot *dslot)
165} 165}
166 166
167/** 167/**
168 * Rescan slot. 168 * pci_rescan_slot - Rescan slot
169 * Tries hard not to re-enable already existing devices 169 * @temp: Device template. Should be set: bus and devfn.
170 * also handles scanning of subfunctions
171 * 170 *
172 * @param temp Device template. Should be set: bus and devfn. 171 * Tries hard not to re-enable already existing devices;
172 * also handles scanning of subfunctions.
173 */ 173 */
174static void pci_rescan_slot(struct pci_dev *temp) 174static void pci_rescan_slot(struct pci_dev *temp)
175{ 175{
@@ -229,10 +229,10 @@ static void pci_rescan_slot(struct pci_dev *temp)
229 229
230 230
231/** 231/**
232 * Rescan PCI bus. 232 * pci_rescan_bus - Rescan PCI bus
233 * call pci_rescan_slot for each possible function of the bus 233 * @bus: the PCI bus to rescan
234 * 234 *
235 * @param bus 235 * Call pci_rescan_slot for each possible function of the bus.
236 */ 236 */
237static void pci_rescan_bus(const struct pci_bus *bus) 237static void pci_rescan_bus(const struct pci_bus *bus)
238{ 238{
diff --git a/drivers/pci/hotplug/pciehp_ctrl.c b/drivers/pci/hotplug/pciehp_ctrl.c
index c8cb49c5a752..f1e0966cee95 100644
--- a/drivers/pci/hotplug/pciehp_ctrl.c
+++ b/drivers/pci/hotplug/pciehp_ctrl.c
@@ -208,10 +208,10 @@ static void set_slot_off(struct controller *ctrl, struct slot * pslot)
208 208
209/** 209/**
210 * board_added - Called after a board has been added to the system. 210 * board_added - Called after a board has been added to the system.
211 * @p_slot: &slot where board is added
211 * 212 *
212 * Turns power on for the board 213 * Turns power on for the board.
213 * Configures board 214 * Configures board.
214 *
215 */ 215 */
216static int board_added(struct slot *p_slot) 216static int board_added(struct slot *p_slot)
217{ 217{
@@ -276,8 +276,8 @@ err_exit:
276} 276}
277 277
278/** 278/**
279 * remove_board - Turns off slot and LED's 279 * remove_board - Turns off slot and LEDs
280 * 280 * @p_slot: slot where board is being removed
281 */ 281 */
282static int remove_board(struct slot *p_slot) 282static int remove_board(struct slot *p_slot)
283{ 283{
@@ -319,11 +319,11 @@ struct power_work_info {
319}; 319};
320 320
321/** 321/**
322 * pciehp_pushbutton_thread 322 * pciehp_power_thread - handle pushbutton events
323 * @work: &struct work_struct describing work to be done
323 * 324 *
324 * Scheduled procedure to handle blocking stuff for the pushbuttons 325 * Scheduled procedure to handle blocking stuff for the pushbuttons.
325 * Handles all pending events and exits. 326 * Handles all pending events and exits.
326 *
327 */ 327 */
328static void pciehp_power_thread(struct work_struct *work) 328static void pciehp_power_thread(struct work_struct *work)
329{ 329{
diff --git a/drivers/pci/hotplug/rpadlpar_core.c b/drivers/pci/hotplug/rpadlpar_core.c
index deb6b5e35feb..b169b0e2647f 100644
--- a/drivers/pci/hotplug/rpadlpar_core.c
+++ b/drivers/pci/hotplug/rpadlpar_core.c
@@ -100,6 +100,7 @@ static struct device_node *find_dlpar_node(char *drc_name, int *node_type)
100 100
101/** 101/**
102 * find_php_slot - return hotplug slot structure for device node 102 * find_php_slot - return hotplug slot structure for device node
103 * @dn: target &device_node
103 * 104 *
104 * This routine will return the hotplug slot structure 105 * This routine will return the hotplug slot structure
105 * for a given device node. Note that built-in PCI slots 106 * for a given device node. Note that built-in PCI slots
@@ -293,9 +294,8 @@ static int dlpar_add_vio_slot(char *drc_name, struct device_node *dn)
293 * dlpar_add_slot - DLPAR add an I/O Slot 294 * dlpar_add_slot - DLPAR add an I/O Slot
294 * @drc_name: drc-name of newly added slot 295 * @drc_name: drc-name of newly added slot
295 * 296 *
296 * Make the hotplug module and the kernel aware 297 * Make the hotplug module and the kernel aware of a newly added I/O Slot.
297 * of a newly added I/O Slot. 298 * Return Codes:
298 * Return Codes -
299 * 0 Success 299 * 0 Success
300 * -ENODEV Not a valid drc_name 300 * -ENODEV Not a valid drc_name
301 * -EINVAL Slot already added 301 * -EINVAL Slot already added
@@ -339,9 +339,9 @@ exit:
339/** 339/**
340 * dlpar_remove_vio_slot - DLPAR remove a virtual I/O Slot 340 * dlpar_remove_vio_slot - DLPAR remove a virtual I/O Slot
341 * @drc_name: drc-name of newly added slot 341 * @drc_name: drc-name of newly added slot
342 * @dn: &device_node
342 * 343 *
343 * Remove the kernel and hotplug representations 344 * Remove the kernel and hotplug representations of an I/O Slot.
344 * of an I/O Slot.
345 * Return Codes: 345 * Return Codes:
346 * 0 Success 346 * 0 Success
347 * -EINVAL Vio dev doesn't exist 347 * -EINVAL Vio dev doesn't exist
@@ -359,11 +359,11 @@ static int dlpar_remove_vio_slot(char *drc_name, struct device_node *dn)
359} 359}
360 360
361/** 361/**
362 * dlpar_remove_slot - DLPAR remove a PCI I/O Slot 362 * dlpar_remove_pci_slot - DLPAR remove a PCI I/O Slot
363 * @drc_name: drc-name of newly added slot 363 * @drc_name: drc-name of newly added slot
364 * @dn: &device_node
364 * 365 *
365 * Remove the kernel and hotplug representations 366 * Remove the kernel and hotplug representations of a PCI I/O Slot.
366 * of a PCI I/O Slot.
367 * Return Codes: 367 * Return Codes:
368 * 0 Success 368 * 0 Success
369 * -ENODEV Not a valid drc_name 369 * -ENODEV Not a valid drc_name
@@ -405,8 +405,7 @@ int dlpar_remove_pci_slot(char *drc_name, struct device_node *dn)
405 * dlpar_remove_slot - DLPAR remove an I/O Slot 405 * dlpar_remove_slot - DLPAR remove an I/O Slot
406 * @drc_name: drc-name of newly added slot 406 * @drc_name: drc-name of newly added slot
407 * 407 *
408 * Remove the kernel and hotplug representations 408 * Remove the kernel and hotplug representations of an I/O Slot.
409 * of an I/O Slot.
410 * Return Codes: 409 * Return Codes:
411 * 0 Success 410 * 0 Success
412 * -ENODEV Not a valid drc_name 411 * -ENODEV Not a valid drc_name
diff --git a/drivers/pci/hotplug/rpaphp_core.c b/drivers/pci/hotplug/rpaphp_core.c
index 458c08ef2654..58f1a9927709 100644
--- a/drivers/pci/hotplug/rpaphp_core.c
+++ b/drivers/pci/hotplug/rpaphp_core.c
@@ -54,10 +54,12 @@ module_param(debug, bool, 0644);
54 54
55/** 55/**
56 * set_attention_status - set attention LED 56 * set_attention_status - set attention LED
57 * @hotplug_slot: target &hotplug_slot
58 * @value: LED control value
59 *
57 * echo 0 > attention -- set LED OFF 60 * echo 0 > attention -- set LED OFF
58 * echo 1 > attention -- set LED ON 61 * echo 1 > attention -- set LED ON
59 * echo 2 > attention -- set LED ID(identify, light is blinking) 62 * echo 2 > attention -- set LED ID(identify, light is blinking)
60 *
61 */ 63 */
62static int set_attention_status(struct hotplug_slot *hotplug_slot, u8 value) 64static int set_attention_status(struct hotplug_slot *hotplug_slot, u8 value)
63{ 65{
@@ -99,6 +101,8 @@ static int get_power_status(struct hotplug_slot *hotplug_slot, u8 * value)
99 101
100/** 102/**
101 * get_attention_status - get attention LED status 103 * get_attention_status - get attention LED status
104 * @hotplug_slot: slot to get status
105 * @value: pointer to store status
102 */ 106 */
103static int get_attention_status(struct hotplug_slot *hotplug_slot, u8 * value) 107static int get_attention_status(struct hotplug_slot *hotplug_slot, u8 * value)
104{ 108{
@@ -254,6 +258,11 @@ static int is_php_type(char *drc_type)
254 258
255/** 259/**
256 * is_php_dn() - return 1 if this is a hotpluggable pci slot, else 0 260 * is_php_dn() - return 1 if this is a hotpluggable pci slot, else 0
261 * @dn: target &device_node
262 * @indexes: passed to get_children_props()
263 * @names: passed to get_children_props()
264 * @types: returned from get_children_props()
265 * @power_domains:
257 * 266 *
258 * This routine will return true only if the device node is 267 * This routine will return true only if the device node is
259 * a hotpluggable slot. This routine will return false 268 * a hotpluggable slot. This routine will return false
@@ -279,7 +288,7 @@ static int is_php_dn(struct device_node *dn, const int **indexes,
279 288
280/** 289/**
281 * rpaphp_add_slot -- declare a hotplug slot to the hotplug subsystem. 290 * rpaphp_add_slot -- declare a hotplug slot to the hotplug subsystem.
282 * @dn device node of slot 291 * @dn: device node of slot
283 * 292 *
284 * This subroutine will register a hotplugable slot with the 293 * This subroutine will register a hotplugable slot with the
285 * PCI hotplug infrastructure. This routine is typicaly called 294 * PCI hotplug infrastructure. This routine is typicaly called
@@ -291,7 +300,7 @@ static int is_php_dn(struct device_node *dn, const int **indexes,
291 * routine will just return without doing anything, since embedded 300 * routine will just return without doing anything, since embedded
292 * slots cannot be hotplugged. 301 * slots cannot be hotplugged.
293 * 302 *
294 * To remove a slot, it suffices to call rpaphp_deregister_slot() 303 * To remove a slot, it suffices to call rpaphp_deregister_slot().
295 */ 304 */
296int rpaphp_add_slot(struct device_node *dn) 305int rpaphp_add_slot(struct device_node *dn)
297{ 306{
diff --git a/drivers/pci/hotplug/rpaphp_pci.c b/drivers/pci/hotplug/rpaphp_pci.c
index 54ca8650d511..0de84533cd80 100644
--- a/drivers/pci/hotplug/rpaphp_pci.c
+++ b/drivers/pci/hotplug/rpaphp_pci.c
@@ -79,6 +79,7 @@ static void set_slot_name(struct slot *slot)
79 79
80/** 80/**
81 * rpaphp_enable_slot - record slot state, config pci device 81 * rpaphp_enable_slot - record slot state, config pci device
82 * @slot: target &slot
82 * 83 *
83 * Initialize values in the slot, and the hotplug_slot info 84 * Initialize values in the slot, and the hotplug_slot info
84 * structures to indicate if there is a pci card plugged into 85 * structures to indicate if there is a pci card plugged into
diff --git a/drivers/pci/hotplug/shpchp_ctrl.c b/drivers/pci/hotplug/shpchp_ctrl.c
index d2fc35598cdd..eb5cac6f08ae 100644
--- a/drivers/pci/hotplug/shpchp_ctrl.c
+++ b/drivers/pci/hotplug/shpchp_ctrl.c
@@ -231,10 +231,10 @@ static int fix_bus_speed(struct controller *ctrl, struct slot *pslot,
231 231
232/** 232/**
233 * board_added - Called after a board has been added to the system. 233 * board_added - Called after a board has been added to the system.
234 * @p_slot: target &slot
234 * 235 *
235 * Turns power on for the board 236 * Turns power on for the board.
236 * Configures board 237 * Configures board.
237 *
238 */ 238 */
239static int board_added(struct slot *p_slot) 239static int board_added(struct slot *p_slot)
240{ 240{
@@ -350,8 +350,8 @@ err_exit:
350 350
351 351
352/** 352/**
353 * remove_board - Turns off slot and LED's 353 * remove_board - Turns off slot and LEDs
354 * 354 * @p_slot: target &slot
355 */ 355 */
356static int remove_board(struct slot *p_slot) 356static int remove_board(struct slot *p_slot)
357{ 357{
@@ -397,11 +397,11 @@ struct pushbutton_work_info {
397}; 397};
398 398
399/** 399/**
400 * shpchp_pushbutton_thread 400 * shpchp_pushbutton_thread - handle pushbutton events
401 * @work: &struct work_struct to be handled
401 * 402 *
402 * Scheduled procedure to handle blocking stuff for the pushbuttons 403 * Scheduled procedure to handle blocking stuff for the pushbuttons.
403 * Handles all pending events and exits. 404 * Handles all pending events and exits.
404 *
405 */ 405 */
406static void shpchp_pushbutton_thread(struct work_struct *work) 406static void shpchp_pushbutton_thread(struct work_struct *work)
407{ 407{
diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
index 1b7b2812bf2d..7d1877341aad 100644
--- a/drivers/pci/pci-sysfs.c
+++ b/drivers/pci/pci-sysfs.c
@@ -702,8 +702,10 @@ static int __init pci_sysfs_init(void)
702 sysfs_initialized = 1; 702 sysfs_initialized = 1;
703 for_each_pci_dev(pdev) { 703 for_each_pci_dev(pdev) {
704 retval = pci_create_sysfs_dev_files(pdev); 704 retval = pci_create_sysfs_dev_files(pdev);
705 if (retval) 705 if (retval) {
706 pci_dev_put(pdev);
706 return retval; 707 return retval;
708 }
707 } 709 }
708 710
709 return 0; 711 return 0;
diff --git a/drivers/pci/pcie/aer/aerdrv_core.c b/drivers/pci/pcie/aer/aerdrv_core.c
index 92a8469b21ba..3c0d8d138f5a 100644
--- a/drivers/pci/pcie/aer/aerdrv_core.c
+++ b/drivers/pci/pcie/aer/aerdrv_core.c
@@ -168,11 +168,11 @@ static int find_device_iter(struct device *device, void *data)
168 168
169/** 169/**
170 * find_source_device - search through device hierarchy for source device 170 * find_source_device - search through device hierarchy for source device
171 * @p_dev: pointer to Root Port pci_dev data structure 171 * @parent: pointer to Root Port pci_dev data structure
172 * @id: device ID of agent who sends an error message to this Root Port 172 * @id: device ID of agent who sends an error message to this Root Port
173 * 173 *
174 * Invoked when error is detected at the Root Port. 174 * Invoked when error is detected at the Root Port.
175 **/ 175 */
176static struct device* find_source_device(struct pci_dev *parent, u16 id) 176static struct device* find_source_device(struct pci_dev *parent, u16 id)
177{ 177{
178 struct pci_dev *dev = parent; 178 struct pci_dev *dev = parent;
@@ -286,14 +286,15 @@ static void report_resume(struct pci_dev *dev, void *data)
286 286
287/** 287/**
288 * broadcast_error_message - handle message broadcast to downstream drivers 288 * broadcast_error_message - handle message broadcast to downstream drivers
289 * @device: pointer to from where in a hierarchy message is broadcasted down 289 * @dev: pointer to from where in a hierarchy message is broadcasted down
290 * @api: callback to be broadcasted
291 * @state: error state 290 * @state: error state
291 * @error_mesg: message to print
292 * @cb: callback to be broadcasted
292 * 293 *
293 * Invoked during error recovery process. Once being invoked, the content 294 * Invoked during error recovery process. Once being invoked, the content
294 * of error severity will be broadcasted to all downstream drivers in a 295 * of error severity will be broadcasted to all downstream drivers in a
295 * hierarchy in question. 296 * hierarchy in question.
296 **/ 297 */
297static pci_ers_result_t broadcast_error_message(struct pci_dev *dev, 298static pci_ers_result_t broadcast_error_message(struct pci_dev *dev,
298 enum pci_channel_state state, 299 enum pci_channel_state state,
299 char *error_mesg, 300 char *error_mesg,
@@ -428,7 +429,7 @@ static pci_ers_result_t reset_link(struct pcie_device *aerdev,
428 * Invoked when an error is nonfatal/fatal. Once being invoked, broadcast 429 * Invoked when an error is nonfatal/fatal. Once being invoked, broadcast
429 * error detected message to all downstream drivers within a hierarchy in 430 * error detected message to all downstream drivers within a hierarchy in
430 * question and return the returned code. 431 * question and return the returned code.
431 **/ 432 */
432static pci_ers_result_t do_recovery(struct pcie_device *aerdev, 433static pci_ers_result_t do_recovery(struct pcie_device *aerdev,
433 struct pci_dev *dev, 434 struct pci_dev *dev,
434 int severity) 435 int severity)
@@ -488,7 +489,7 @@ static pci_ers_result_t do_recovery(struct pcie_device *aerdev,
488 * @info: comprehensive error information 489 * @info: comprehensive error information
489 * 490 *
490 * Invoked when an error being detected by Root Port. 491 * Invoked when an error being detected by Root Port.
491 **/ 492 */
492static void handle_error_source(struct pcie_device * aerdev, 493static void handle_error_source(struct pcie_device * aerdev,
493 struct pci_dev *dev, 494 struct pci_dev *dev,
494 struct aer_err_info info) 495 struct aer_err_info info)
@@ -521,7 +522,7 @@ static void handle_error_source(struct pcie_device * aerdev,
521 * @rpc: pointer to a Root Port data structure 522 * @rpc: pointer to a Root Port data structure
522 * 523 *
523 * Invoked when PCIE bus loads AER service driver. 524 * Invoked when PCIE bus loads AER service driver.
524 **/ 525 */
525void aer_enable_rootport(struct aer_rpc *rpc) 526void aer_enable_rootport(struct aer_rpc *rpc)
526{ 527{
527 struct pci_dev *pdev = rpc->rpd->port; 528 struct pci_dev *pdev = rpc->rpd->port;
@@ -569,7 +570,7 @@ void aer_enable_rootport(struct aer_rpc *rpc)
569 * @rpc: pointer to a Root Port data structure 570 * @rpc: pointer to a Root Port data structure
570 * 571 *
571 * Invoked when PCIE bus unloads AER service driver. 572 * Invoked when PCIE bus unloads AER service driver.
572 **/ 573 */
573static void disable_root_aer(struct aer_rpc *rpc) 574static void disable_root_aer(struct aer_rpc *rpc)
574{ 575{
575 struct pci_dev *pdev = rpc->rpd->port; 576 struct pci_dev *pdev = rpc->rpd->port;
@@ -590,7 +591,7 @@ static void disable_root_aer(struct aer_rpc *rpc)
590 * @rpc: pointer to the root port which holds an error 591 * @rpc: pointer to the root port which holds an error
591 * 592 *
592 * Invoked by DPC handler to consume an error. 593 * Invoked by DPC handler to consume an error.
593 **/ 594 */
594static struct aer_err_source* get_e_source(struct aer_rpc *rpc) 595static struct aer_err_source* get_e_source(struct aer_rpc *rpc)
595{ 596{
596 struct aer_err_source *e_source; 597 struct aer_err_source *e_source;
@@ -655,7 +656,7 @@ static int get_device_error_info(struct pci_dev *dev, struct aer_err_info *info)
655 * aer_isr_one_error - consume an error detected by root port 656 * aer_isr_one_error - consume an error detected by root port
656 * @p_device: pointer to error root port service device 657 * @p_device: pointer to error root port service device
657 * @e_src: pointer to an error source 658 * @e_src: pointer to an error source
658 **/ 659 */
659static void aer_isr_one_error(struct pcie_device *p_device, 660static void aer_isr_one_error(struct pcie_device *p_device,
660 struct aer_err_source *e_src) 661 struct aer_err_source *e_src)
661{ 662{
@@ -706,7 +707,7 @@ static void aer_isr_one_error(struct pcie_device *p_device,
706 * @work: definition of this work item 707 * @work: definition of this work item
707 * 708 *
708 * Invoked, as DPC, when root port records new detected error 709 * Invoked, as DPC, when root port records new detected error
709 **/ 710 */
710void aer_isr(struct work_struct *work) 711void aer_isr(struct work_struct *work)
711{ 712{
712 struct aer_rpc *rpc = container_of(work, struct aer_rpc, dpc_handler); 713 struct aer_rpc *rpc = container_of(work, struct aer_rpc, dpc_handler);
@@ -729,7 +730,7 @@ void aer_isr(struct work_struct *work)
729 * @rpc: pointer to a root port device being deleted 730 * @rpc: pointer to a root port device being deleted
730 * 731 *
731 * Invoked when AER service unloaded on a specific Root Port 732 * Invoked when AER service unloaded on a specific Root Port
732 **/ 733 */
733void aer_delete_rootport(struct aer_rpc *rpc) 734void aer_delete_rootport(struct aer_rpc *rpc)
734{ 735{
735 /* Disable root port AER itself */ 736 /* Disable root port AER itself */
@@ -743,7 +744,7 @@ void aer_delete_rootport(struct aer_rpc *rpc)
743 * @dev: pointer to AER pcie device 744 * @dev: pointer to AER pcie device
744 * 745 *
745 * Invoked when AER service driver is loaded. 746 * Invoked when AER service driver is loaded.
746 **/ 747 */
747int aer_init(struct pcie_device *dev) 748int aer_init(struct pcie_device *dev)
748{ 749{
749 if (aer_osc_setup(dev) && !forceload) 750 if (aer_osc_setup(dev) && !forceload)
diff --git a/drivers/pci/pcie/portdrv_pci.c b/drivers/pci/pcie/portdrv_pci.c
index df383645e366..26057f98f72e 100644
--- a/drivers/pci/pcie/portdrv_pci.c
+++ b/drivers/pci/pcie/portdrv_pci.c
@@ -217,7 +217,7 @@ static int slot_reset_iter(struct device *device, void *data)
217 217
218static pci_ers_result_t pcie_portdrv_slot_reset(struct pci_dev *dev) 218static pci_ers_result_t pcie_portdrv_slot_reset(struct pci_dev *dev)
219{ 219{
220 pci_ers_result_t status; 220 pci_ers_result_t status = PCI_ERS_RESULT_NONE;
221 int retval; 221 int retval;
222 222
223 /* If fatal, restore cfg space for possible link reset at upstream */ 223 /* If fatal, restore cfg space for possible link reset at upstream */
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 463a5a9d583d..c5ca3134513a 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -276,7 +276,8 @@ static void pci_read_bases(struct pci_dev *dev, unsigned int howmany, int rom)
276 sz = pci_size(l, sz, (u32)PCI_ROM_ADDRESS_MASK); 276 sz = pci_size(l, sz, (u32)PCI_ROM_ADDRESS_MASK);
277 if (sz) { 277 if (sz) {
278 res->flags = (l & IORESOURCE_ROM_ENABLE) | 278 res->flags = (l & IORESOURCE_ROM_ENABLE) |
279 IORESOURCE_MEM | IORESOURCE_READONLY; 279 IORESOURCE_MEM | IORESOURCE_PREFETCH |
280 IORESOURCE_READONLY | IORESOURCE_CACHEABLE;
280 res->start = l & PCI_ROM_ADDRESS_MASK; 281 res->start = l & PCI_ROM_ADDRESS_MASK;
281 res->end = res->start + (unsigned long) sz; 282 res->end = res->start + (unsigned long) sz;
282 } 283 }
@@ -454,22 +455,6 @@ struct pci_bus *pci_add_new_bus(struct pci_bus *parent, struct pci_dev *dev, int
454 return child; 455 return child;
455} 456}
456 457
457static void pci_enable_crs(struct pci_dev *dev)
458{
459 u16 cap, rpctl;
460 int rpcap = pci_find_capability(dev, PCI_CAP_ID_EXP);
461 if (!rpcap)
462 return;
463
464 pci_read_config_word(dev, rpcap + PCI_CAP_FLAGS, &cap);
465 if (((cap & PCI_EXP_FLAGS_TYPE) >> 4) != PCI_EXP_TYPE_ROOT_PORT)
466 return;
467
468 pci_read_config_word(dev, rpcap + PCI_EXP_RTCTL, &rpctl);
469 rpctl |= PCI_EXP_RTCTL_CRSSVE;
470 pci_write_config_word(dev, rpcap + PCI_EXP_RTCTL, rpctl);
471}
472
473static void pci_fixup_parent_subordinate_busnr(struct pci_bus *child, int max) 458static void pci_fixup_parent_subordinate_busnr(struct pci_bus *child, int max)
474{ 459{
475 struct pci_bus *parent = child->parent; 460 struct pci_bus *parent = child->parent;
@@ -516,8 +501,6 @@ int pci_scan_bridge(struct pci_bus *bus, struct pci_dev * dev, int max, int pass
516 pci_write_config_word(dev, PCI_BRIDGE_CONTROL, 501 pci_write_config_word(dev, PCI_BRIDGE_CONTROL,
517 bctl & ~PCI_BRIDGE_CTL_MASTER_ABORT); 502 bctl & ~PCI_BRIDGE_CTL_MASTER_ABORT);
518 503
519 pci_enable_crs(dev);
520
521 if ((buses & 0xffff00) && !pcibios_assign_all_busses() && !is_cardbus) { 504 if ((buses & 0xffff00) && !pcibios_assign_all_busses() && !is_cardbus) {
522 unsigned int cmax, busnr; 505 unsigned int cmax, busnr;
523 /* 506 /*
@@ -743,46 +726,22 @@ static int pci_setup_device(struct pci_dev * dev)
743 */ 726 */
744 if (class == PCI_CLASS_STORAGE_IDE) { 727 if (class == PCI_CLASS_STORAGE_IDE) {
745 u8 progif; 728 u8 progif;
746 struct pci_bus_region region;
747
748 pci_read_config_byte(dev, PCI_CLASS_PROG, &progif); 729 pci_read_config_byte(dev, PCI_CLASS_PROG, &progif);
749 if ((progif & 1) == 0) { 730 if ((progif & 1) == 0) {
750 struct resource resource = { 731 dev->resource[0].start = 0x1F0;
751 .start = 0x1F0, 732 dev->resource[0].end = 0x1F7;
752 .end = 0x1F7, 733 dev->resource[0].flags = LEGACY_IO_RESOURCE;
753 .flags = LEGACY_IO_RESOURCE, 734 dev->resource[1].start = 0x3F6;
754 }; 735 dev->resource[1].end = 0x3F6;
755 736 dev->resource[1].flags = LEGACY_IO_RESOURCE;
756 pcibios_resource_to_bus(dev, &region, &resource);
757 dev->resource[0].start = region.start;
758 dev->resource[0].end = region.end;
759 dev->resource[0].flags = resource.flags;
760 resource.start = 0x3F6;
761 resource.end = 0x3F6;
762 resource.flags = LEGACY_IO_RESOURCE;
763 pcibios_resource_to_bus(dev, &region, &resource);
764 dev->resource[1].start = region.start;
765 dev->resource[1].end = region.end;
766 dev->resource[1].flags = resource.flags;
767 } 737 }
768 if ((progif & 4) == 0) { 738 if ((progif & 4) == 0) {
769 struct resource resource = { 739 dev->resource[2].start = 0x170;
770 .start = 0x170, 740 dev->resource[2].end = 0x177;
771 .end = 0x177, 741 dev->resource[2].flags = LEGACY_IO_RESOURCE;
772 .flags = LEGACY_IO_RESOURCE, 742 dev->resource[3].start = 0x376;
773 }; 743 dev->resource[3].end = 0x376;
774 744 dev->resource[3].flags = LEGACY_IO_RESOURCE;
775 pcibios_resource_to_bus(dev, &region, &resource);
776 dev->resource[2].start = region.start;
777 dev->resource[2].end = region.end;
778 dev->resource[2].flags = resource.flags;
779 resource.start = 0x376;
780 resource.end = 0x376;
781 resource.flags = LEGACY_IO_RESOURCE;
782 pcibios_resource_to_bus(dev, &region, &resource);
783 dev->resource[3].start = region.start;
784 dev->resource[3].end = region.end;
785 dev->resource[3].flags = resource.flags;
786 } 745 }
787 } 746 }
788 break; 747 break;
diff --git a/drivers/pcmcia/cs.c b/drivers/pcmcia/cs.c
index a0aca46ce877..56230dbd347a 100644
--- a/drivers/pcmcia/cs.c
+++ b/drivers/pcmcia/cs.c
@@ -89,7 +89,7 @@ DECLARE_RWSEM(pcmcia_socket_list_rwsem);
89EXPORT_SYMBOL(pcmcia_socket_list_rwsem); 89EXPORT_SYMBOL(pcmcia_socket_list_rwsem);
90 90
91 91
92/** 92/*
93 * Low-level PCMCIA socket drivers need to register with the PCCard 93 * Low-level PCMCIA socket drivers need to register with the PCCard
94 * core using pcmcia_register_socket. 94 * core using pcmcia_register_socket.
95 * 95 *
@@ -174,6 +174,7 @@ static int pccardd(void *__skt);
174 174
175/** 175/**
176 * pcmcia_register_socket - add a new pcmcia socket device 176 * pcmcia_register_socket - add a new pcmcia socket device
177 * @socket: the &socket to register
177 */ 178 */
178int pcmcia_register_socket(struct pcmcia_socket *socket) 179int pcmcia_register_socket(struct pcmcia_socket *socket)
179{ 180{
@@ -268,6 +269,7 @@ EXPORT_SYMBOL(pcmcia_register_socket);
268 269
269/** 270/**
270 * pcmcia_unregister_socket - remove a pcmcia socket device 271 * pcmcia_unregister_socket - remove a pcmcia socket device
272 * @socket: the &socket to unregister
271 */ 273 */
272void pcmcia_unregister_socket(struct pcmcia_socket *socket) 274void pcmcia_unregister_socket(struct pcmcia_socket *socket)
273{ 275{
@@ -311,7 +313,7 @@ struct pcmcia_socket * pcmcia_get_socket_by_nr(unsigned int nr)
311} 313}
312EXPORT_SYMBOL(pcmcia_get_socket_by_nr); 314EXPORT_SYMBOL(pcmcia_get_socket_by_nr);
313 315
314/** 316/*
315 * The central event handler. Send_event() sends an event to the 317 * The central event handler. Send_event() sends an event to the
316 * 16-bit subsystem, which then calls the relevant device drivers. 318 * 16-bit subsystem, which then calls the relevant device drivers.
317 * Parse_events() interprets the event bits from 319 * Parse_events() interprets the event bits from
@@ -380,7 +382,7 @@ static int socket_reset(struct pcmcia_socket *skt)
380 return CS_GENERAL_FAILURE; 382 return CS_GENERAL_FAILURE;
381} 383}
382 384
383/** 385/*
384 * socket_setup() and socket_shutdown() are called by the main event handler 386 * socket_setup() and socket_shutdown() are called by the main event handler
385 * when card insertion and removal events are received. 387 * when card insertion and removal events are received.
386 * socket_setup() turns on socket power and resets the socket, in two stages. 388 * socket_setup() turns on socket power and resets the socket, in two stages.
diff --git a/drivers/pcmcia/ds.c b/drivers/pcmcia/ds.c
index 7bf78c127898..5cf89a91da1e 100644
--- a/drivers/pcmcia/ds.c
+++ b/drivers/pcmcia/ds.c
@@ -320,6 +320,7 @@ pcmcia_create_newid_file(struct pcmcia_driver *drv)
320 320
321/** 321/**
322 * pcmcia_register_driver - register a PCMCIA driver with the bus core 322 * pcmcia_register_driver - register a PCMCIA driver with the bus core
323 * @driver: the &driver being registered
323 * 324 *
324 * Registers a PCMCIA driver with the PCMCIA bus core. 325 * Registers a PCMCIA driver with the PCMCIA bus core.
325 */ 326 */
@@ -354,6 +355,7 @@ EXPORT_SYMBOL(pcmcia_register_driver);
354 355
355/** 356/**
356 * pcmcia_unregister_driver - unregister a PCMCIA driver with the bus core 357 * pcmcia_unregister_driver - unregister a PCMCIA driver with the bus core
358 * @driver: the &driver being unregistered
357 */ 359 */
358void pcmcia_unregister_driver(struct pcmcia_driver *driver) 360void pcmcia_unregister_driver(struct pcmcia_driver *driver)
359{ 361{
@@ -840,8 +842,8 @@ static void pcmcia_bus_rescan(struct pcmcia_socket *skt, int new_cis)
840 842
841/** 843/**
842 * pcmcia_load_firmware - load CIS from userspace if device-provided is broken 844 * pcmcia_load_firmware - load CIS from userspace if device-provided is broken
843 * @dev - the pcmcia device which needs a CIS override 845 * @dev: the pcmcia device which needs a CIS override
844 * @filename - requested filename in /lib/firmware/ 846 * @filename: requested filename in /lib/firmware/
845 * 847 *
846 * This uses the in-kernel firmware loading mechanism to use a "fake CIS" if 848 * This uses the in-kernel firmware loading mechanism to use a "fake CIS" if
847 * the one provided by the card is broken. The firmware files reside in 849 * the one provided by the card is broken. The firmware files reside in
diff --git a/drivers/pcmcia/pxa2xx_lubbock.c b/drivers/pcmcia/pxa2xx_lubbock.c
index 1510d6cde3e2..4a05802213c8 100644
--- a/drivers/pcmcia/pxa2xx_lubbock.c
+++ b/drivers/pcmcia/pxa2xx_lubbock.c
@@ -213,7 +213,7 @@ static struct pcmcia_low_level lubbock_pcmcia_ops = {
213 213
214#include "pxa2xx_base.h" 214#include "pxa2xx_base.h"
215 215
216int __init pcmcia_lubbock_init(struct sa1111_dev *sadev) 216int pcmcia_lubbock_init(struct sa1111_dev *sadev)
217{ 217{
218 int ret = -ENODEV; 218 int ret = -ENODEV;
219 219
diff --git a/drivers/pcmcia/ti113x.h b/drivers/pcmcia/ti113x.h
index 62e9ebf967f9..d29657bf1b40 100644
--- a/drivers/pcmcia/ti113x.h
+++ b/drivers/pcmcia/ti113x.h
@@ -874,7 +874,7 @@ static int ti1250_override(struct yenta_socket *socket)
874 */ 874 */
875 875
876#ifdef CONFIG_YENTA_ENE_TUNE 876#ifdef CONFIG_YENTA_ENE_TUNE
877/** 877/*
878 * set/clear various test bits: 878 * set/clear various test bits:
879 * Defaults to clear the bit. 879 * Defaults to clear the bit.
880 * - mask (u8) defines what bits to change 880 * - mask (u8) defines what bits to change
diff --git a/drivers/pcmcia/yenta_socket.c b/drivers/pcmcia/yenta_socket.c
index 20853a03202d..0ab1fb65cdc3 100644
--- a/drivers/pcmcia/yenta_socket.c
+++ b/drivers/pcmcia/yenta_socket.c
@@ -48,7 +48,7 @@ MODULE_PARM_DESC(pwr_irqs_off, "Force IRQs off during power-on of slot. Use only
48#define to_cycles(ns) ((ns)/120) 48#define to_cycles(ns) ((ns)/120)
49#define to_ns(cycles) ((cycles)*120) 49#define to_ns(cycles) ((cycles)*120)
50 50
51/** 51/*
52 * yenta PCI irq probing. 52 * yenta PCI irq probing.
53 * currently only used in the TI/EnE initialization code 53 * currently only used in the TI/EnE initialization code
54 */ 54 */
@@ -888,7 +888,7 @@ static unsigned int yenta_probe_irq(struct yenta_socket *socket, u32 isa_irq_mas
888} 888}
889 889
890 890
891/** 891/*
892 * yenta PCI irq probing. 892 * yenta PCI irq probing.
893 * currently only used in the TI/EnE initialization code 893 * currently only used in the TI/EnE initialization code
894 */ 894 */
@@ -1012,7 +1012,7 @@ static void yenta_config_init(struct yenta_socket *socket)
1012 * invisible during PCI scans because of a misconfigured subordinate number 1012 * invisible during PCI scans because of a misconfigured subordinate number
1013 * of the parent brige - some BIOSes seem to be too lazy to set it right. 1013 * of the parent brige - some BIOSes seem to be too lazy to set it right.
1014 * Does the fixup carefully by checking how far it can go without conflicts. 1014 * Does the fixup carefully by checking how far it can go without conflicts.
1015 * See http://bugzilla.kernel.org/show_bug.cgi?id=2944 for more information. 1015 * See http\://bugzilla.kernel.org/show_bug.cgi?id=2944 for more information.
1016 */ 1016 */
1017static void yenta_fixup_parent_bridge(struct pci_bus *cardbus_bridge) 1017static void yenta_fixup_parent_bridge(struct pci_bus *cardbus_bridge)
1018{ 1018{
diff --git a/drivers/pnp/pnpacpi/rsparser.c b/drivers/pnp/pnpacpi/rsparser.c
index cd0a204d96d1..3c5eb374adf8 100644
--- a/drivers/pnp/pnpacpi/rsparser.c
+++ b/drivers/pnp/pnpacpi/rsparser.c
@@ -75,6 +75,7 @@ static void pnpacpi_parse_allocated_irqresource(struct pnp_resource_table *res,
75{ 75{
76 int i = 0; 76 int i = 0;
77 int irq; 77 int irq;
78 int p, t;
78 79
79 if (!valid_IRQ(gsi)) 80 if (!valid_IRQ(gsi))
80 return; 81 return;
@@ -82,18 +83,27 @@ static void pnpacpi_parse_allocated_irqresource(struct pnp_resource_table *res,
82 while (!(res->irq_resource[i].flags & IORESOURCE_UNSET) && 83 while (!(res->irq_resource[i].flags & IORESOURCE_UNSET) &&
83 i < PNP_MAX_IRQ) 84 i < PNP_MAX_IRQ)
84 i++; 85 i++;
85 if (i >= PNP_MAX_IRQ) 86 if (i >= PNP_MAX_IRQ) {
87 printk(KERN_ERR "pnpacpi: exceeded the max number of IRQ "
88 "resources: %d \n", PNP_MAX_IRQ);
86 return; 89 return;
87
88#ifdef CONFIG_X86
89 if (gsi < 16 && (triggering != ACPI_EDGE_SENSITIVE ||
90 polarity != ACPI_ACTIVE_HIGH)) {
91 pnp_warn("BIOS BUG: legacy PNP IRQ %d should be edge trigger, "
92 "active high", gsi);
93 triggering = ACPI_EDGE_SENSITIVE;
94 polarity = ACPI_ACTIVE_HIGH;
95 } 90 }
96#endif 91 /*
92 * in IO-APIC mode, use overrided attribute. Two reasons:
93 * 1. BIOS bug in DSDT
94 * 2. BIOS uses IO-APIC mode Interrupt Source Override
95 */
96 if (!acpi_get_override_irq(gsi, &t, &p)) {
97 t = t ? ACPI_LEVEL_SENSITIVE : ACPI_EDGE_SENSITIVE;
98 p = p ? ACPI_ACTIVE_LOW : ACPI_ACTIVE_HIGH;
99
100 if (triggering != t || polarity != p) {
101 pnp_warn("IRQ %d override to %s, %s",
102 gsi, t ? "edge":"level", p ? "low":"high");
103 triggering = t;
104 polarity = p;
105 }
106 }
97 107
98 res->irq_resource[i].flags = IORESOURCE_IRQ; // Also clears _UNSET flag 108 res->irq_resource[i].flags = IORESOURCE_IRQ; // Also clears _UNSET flag
99 res->irq_resource[i].flags |= irq_flags(triggering, polarity); 109 res->irq_resource[i].flags |= irq_flags(triggering, polarity);
@@ -173,6 +183,9 @@ static void pnpacpi_parse_allocated_dmaresource(struct pnp_resource_table *res,
173 } 183 }
174 res->dma_resource[i].start = dma; 184 res->dma_resource[i].start = dma;
175 res->dma_resource[i].end = dma; 185 res->dma_resource[i].end = dma;
186 } else {
187 printk(KERN_ERR "pnpacpi: exceeded the max number of DMA "
188 "resources: %d \n", PNP_MAX_DMA);
176 } 189 }
177} 190}
178 191
@@ -194,6 +207,9 @@ static void pnpacpi_parse_allocated_ioresource(struct pnp_resource_table *res,
194 } 207 }
195 res->port_resource[i].start = io; 208 res->port_resource[i].start = io;
196 res->port_resource[i].end = io + len - 1; 209 res->port_resource[i].end = io + len - 1;
210 } else {
211 printk(KERN_ERR "pnpacpi: exceeded the max number of IO "
212 "resources: %d \n", PNP_MAX_PORT);
197 } 213 }
198} 214}
199 215
@@ -217,6 +233,9 @@ static void pnpacpi_parse_allocated_memresource(struct pnp_resource_table *res,
217 233
218 res->mem_resource[i].start = mem; 234 res->mem_resource[i].start = mem;
219 res->mem_resource[i].end = mem + len - 1; 235 res->mem_resource[i].end = mem + len - 1;
236 } else {
237 printk(KERN_ERR "pnpacpi: exceeded the max number of mem "
238 "resources: %d\n", PNP_MAX_MEM);
220 } 239 }
221} 240}
222 241
diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
index 41d73a5e9312..e50ebcffb962 100644
--- a/drivers/pnp/resource.c
+++ b/drivers/pnp/resource.c
@@ -367,8 +367,10 @@ int pnp_check_irq(struct pnp_dev *dev, int idx)
367 { 367 {
368 struct pci_dev *pci = NULL; 368 struct pci_dev *pci = NULL;
369 for_each_pci_dev(pci) { 369 for_each_pci_dev(pci) {
370 if (pci->irq == *irq) 370 if (pci->irq == *irq) {
371 pci_dev_put(pci);
371 return 0; 372 return 0;
373 }
372 } 374 }
373 } 375 }
374#endif 376#endif
diff --git a/drivers/ps3/Makefile b/drivers/ps3/Makefile
index 746031de2195..1f5a2d33bf5b 100644
--- a/drivers/ps3/Makefile
+++ b/drivers/ps3/Makefile
@@ -1,6 +1,6 @@
1obj-$(CONFIG_PS3_VUART) += vuart.o 1obj-$(CONFIG_PS3_VUART) += ps3-vuart.o
2obj-$(CONFIG_PS3_PS3AV) += ps3av_mod.o 2obj-$(CONFIG_PS3_PS3AV) += ps3av_mod.o
3ps3av_mod-objs += ps3av.o ps3av_cmd.o 3ps3av_mod-objs += ps3av.o ps3av_cmd.o
4obj-$(CONFIG_PPC_PS3) += sys-manager-core.o 4obj-$(CONFIG_PPC_PS3) += sys-manager-core.o
5obj-$(CONFIG_PS3_SYS_MANAGER) += sys-manager.o 5obj-$(CONFIG_PS3_SYS_MANAGER) += ps3-sys-manager.o
6obj-$(CONFIG_PS3_STORAGE) += ps3stor_lib.o 6obj-$(CONFIG_PS3_STORAGE) += ps3stor_lib.o
diff --git a/drivers/ps3/sys-manager.c b/drivers/ps3/ps3-sys-manager.c
index 8461b08ab9fb..8461b08ab9fb 100644
--- a/drivers/ps3/sys-manager.c
+++ b/drivers/ps3/ps3-sys-manager.c
diff --git a/drivers/ps3/vuart.c b/drivers/ps3/ps3-vuart.c
index 9dea585ef806..bb8d5b1eec90 100644
--- a/drivers/ps3/vuart.c
+++ b/drivers/ps3/ps3-vuart.c
@@ -1074,7 +1074,6 @@ static int ps3_vuart_probe(struct ps3_system_bus_device *dev)
1074 if (result) { 1074 if (result) {
1075 dev_dbg(&dev->core, "%s:%d: drv->probe failed\n", 1075 dev_dbg(&dev->core, "%s:%d: drv->probe failed\n",
1076 __func__, __LINE__); 1076 __func__, __LINE__);
1077 down(&vuart_bus_priv.probe_mutex);
1078 goto fail_probe; 1077 goto fail_probe;
1079 } 1078 }
1080 1079
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index e5cdc0294aaa..1e6715ec51ef 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -447,7 +447,7 @@ config RTC_DRV_AT91RM9200
447 447
448config RTC_DRV_BFIN 448config RTC_DRV_BFIN
449 tristate "Blackfin On-Chip RTC" 449 tristate "Blackfin On-Chip RTC"
450 depends on BFIN 450 depends on BLACKFIN
451 help 451 help
452 If you say yes here you will get support for the 452 If you say yes here you will get support for the
453 Blackfin On-Chip Real Time Clock. 453 Blackfin On-Chip Real Time Clock.
diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c
index de0da545c7a1..f1e00ff54ce8 100644
--- a/drivers/rtc/interface.c
+++ b/drivers/rtc/interface.c
@@ -293,7 +293,7 @@ int rtc_irq_register(struct rtc_device *rtc, struct rtc_task *task)
293 return -EINVAL; 293 return -EINVAL;
294 294
295 /* Cannot register while the char dev is in use */ 295 /* Cannot register while the char dev is in use */
296 if (!(mutex_trylock(&rtc->char_lock))) 296 if (test_and_set_bit_lock(RTC_DEV_BUSY, &rtc->flags))
297 return -EBUSY; 297 return -EBUSY;
298 298
299 spin_lock_irq(&rtc->irq_task_lock); 299 spin_lock_irq(&rtc->irq_task_lock);
@@ -303,7 +303,7 @@ int rtc_irq_register(struct rtc_device *rtc, struct rtc_task *task)
303 } 303 }
304 spin_unlock_irq(&rtc->irq_task_lock); 304 spin_unlock_irq(&rtc->irq_task_lock);
305 305
306 mutex_unlock(&rtc->char_lock); 306 clear_bit_unlock(RTC_DEV_BUSY, &rtc->flags);
307 307
308 return retval; 308 return retval;
309} 309}
diff --git a/drivers/rtc/rtc-at32ap700x.c b/drivers/rtc/rtc-at32ap700x.c
index 2999214ca534..d3b9b14267ab 100644
--- a/drivers/rtc/rtc-at32ap700x.c
+++ b/drivers/rtc/rtc-at32ap700x.c
@@ -225,18 +225,12 @@ static int __init at32_rtc_probe(struct platform_device *pdev)
225 goto out; 225 goto out;
226 } 226 }
227 227
228 ret = request_irq(irq, at32_rtc_interrupt, IRQF_SHARED, "rtc", rtc);
229 if (ret) {
230 dev_dbg(&pdev->dev, "could not request irq %d\n", irq);
231 goto out;
232 }
233
234 rtc->irq = irq; 228 rtc->irq = irq;
235 rtc->regs = ioremap(regs->start, regs->end - regs->start + 1); 229 rtc->regs = ioremap(regs->start, regs->end - regs->start + 1);
236 if (!rtc->regs) { 230 if (!rtc->regs) {
237 ret = -ENOMEM; 231 ret = -ENOMEM;
238 dev_dbg(&pdev->dev, "could not map I/O memory\n"); 232 dev_dbg(&pdev->dev, "could not map I/O memory\n");
239 goto out_free_irq; 233 goto out;
240 } 234 }
241 spin_lock_init(&rtc->lock); 235 spin_lock_init(&rtc->lock);
242 236
@@ -253,12 +247,18 @@ static int __init at32_rtc_probe(struct platform_device *pdev)
253 | RTC_BIT(CTRL_EN)); 247 | RTC_BIT(CTRL_EN));
254 } 248 }
255 249
250 ret = request_irq(irq, at32_rtc_interrupt, IRQF_SHARED, "rtc", rtc);
251 if (ret) {
252 dev_dbg(&pdev->dev, "could not request irq %d\n", irq);
253 goto out_iounmap;
254 }
255
256 rtc->rtc = rtc_device_register(pdev->name, &pdev->dev, 256 rtc->rtc = rtc_device_register(pdev->name, &pdev->dev,
257 &at32_rtc_ops, THIS_MODULE); 257 &at32_rtc_ops, THIS_MODULE);
258 if (IS_ERR(rtc->rtc)) { 258 if (IS_ERR(rtc->rtc)) {
259 dev_dbg(&pdev->dev, "could not register rtc device\n"); 259 dev_dbg(&pdev->dev, "could not register rtc device\n");
260 ret = PTR_ERR(rtc->rtc); 260 ret = PTR_ERR(rtc->rtc);
261 goto out_iounmap; 261 goto out_free_irq;
262 } 262 }
263 263
264 platform_set_drvdata(pdev, rtc); 264 platform_set_drvdata(pdev, rtc);
@@ -268,10 +268,10 @@ static int __init at32_rtc_probe(struct platform_device *pdev)
268 268
269 return 0; 269 return 0;
270 270
271out_iounmap:
272 iounmap(rtc->regs);
273out_free_irq: 271out_free_irq:
274 free_irq(irq, rtc); 272 free_irq(irq, rtc);
273out_iounmap:
274 iounmap(rtc->regs);
275out: 275out:
276 kfree(rtc); 276 kfree(rtc);
277 return ret; 277 return ret;
diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
index 814583bd2fe7..025c60a17a4a 100644
--- a/drivers/rtc/rtc-dev.c
+++ b/drivers/rtc/rtc-dev.c
@@ -26,10 +26,7 @@ static int rtc_dev_open(struct inode *inode, struct file *file)
26 struct rtc_device, char_dev); 26 struct rtc_device, char_dev);
27 const struct rtc_class_ops *ops = rtc->ops; 27 const struct rtc_class_ops *ops = rtc->ops;
28 28
29 /* We keep the lock as long as the device is in use 29 if (test_and_set_bit_lock(RTC_DEV_BUSY, &rtc->flags))
30 * and return immediately if busy
31 */
32 if (!(mutex_trylock(&rtc->char_lock)))
33 return -EBUSY; 30 return -EBUSY;
34 31
35 file->private_data = rtc; 32 file->private_data = rtc;
@@ -43,8 +40,8 @@ static int rtc_dev_open(struct inode *inode, struct file *file)
43 return 0; 40 return 0;
44 } 41 }
45 42
46 /* something has gone wrong, release the lock */ 43 /* something has gone wrong */
47 mutex_unlock(&rtc->char_lock); 44 clear_bit_unlock(RTC_DEV_BUSY, &rtc->flags);
48 return err; 45 return err;
49} 46}
50 47
@@ -405,7 +402,7 @@ static int rtc_dev_release(struct inode *inode, struct file *file)
405 if (rtc->ops->release) 402 if (rtc->ops->release)
406 rtc->ops->release(rtc->dev.parent); 403 rtc->ops->release(rtc->dev.parent);
407 404
408 mutex_unlock(&rtc->char_lock); 405 clear_bit_unlock(RTC_DEV_BUSY, &rtc->flags);
409 return 0; 406 return 0;
410} 407}
411 408
@@ -440,7 +437,6 @@ void rtc_dev_prepare(struct rtc_device *rtc)
440 437
441 rtc->dev.devt = MKDEV(MAJOR(rtc_devt), rtc->id); 438 rtc->dev.devt = MKDEV(MAJOR(rtc_devt), rtc->id);
442 439
443 mutex_init(&rtc->char_lock);
444#ifdef CONFIG_RTC_INTF_DEV_UIE_EMUL 440#ifdef CONFIG_RTC_INTF_DEV_UIE_EMUL
445 INIT_WORK(&rtc->uie_task, rtc_uie_task); 441 INIT_WORK(&rtc->uie_task, rtc_uie_task);
446 setup_timer(&rtc->uie_timer, rtc_uie_timer, (unsigned long)rtc); 442 setup_timer(&rtc->uie_timer, rtc_uie_timer, (unsigned long)rtc);
diff --git a/drivers/rtc/rtc-max6902.c b/drivers/rtc/rtc-max6902.c
index 3e183cfee10f..1f956dc5d56e 100644
--- a/drivers/rtc/rtc-max6902.c
+++ b/drivers/rtc/rtc-max6902.c
@@ -89,13 +89,9 @@ static int max6902_get_reg(struct device *dev, unsigned char address,
89 89
90 /* do the i/o */ 90 /* do the i/o */
91 status = spi_sync(spi, &message); 91 status = spi_sync(spi, &message);
92 if (status == 0)
93 status = message.status;
94 else
95 return status;
96
97 *data = chip->rx_buf[1];
98 92
93 if (status == 0)
94 *data = chip->rx_buf[1];
99 return status; 95 return status;
100} 96}
101 97
@@ -125,9 +121,7 @@ static int max6902_get_datetime(struct device *dev, struct rtc_time *dt)
125 121
126 /* do the i/o */ 122 /* do the i/o */
127 status = spi_sync(spi, &message); 123 status = spi_sync(spi, &message);
128 if (status == 0) 124 if (status)
129 status = message.status;
130 else
131 return status; 125 return status;
132 126
133 /* The chip sends data in this order: 127 /* The chip sends data in this order:
diff --git a/drivers/s390/block/dcssblk.c b/drivers/s390/block/dcssblk.c
index 5e083d1f57e7..15a5789b7734 100644
--- a/drivers/s390/block/dcssblk.c
+++ b/drivers/s390/block/dcssblk.c
@@ -472,11 +472,11 @@ dcssblk_add_store(struct device *dev, struct device_attribute *attr, const char
472 if (rc) 472 if (rc)
473 goto unregister_dev; 473 goto unregister_dev;
474 474
475 add_disk(dev_info->gd);
476
477 blk_queue_make_request(dev_info->dcssblk_queue, dcssblk_make_request); 475 blk_queue_make_request(dev_info->dcssblk_queue, dcssblk_make_request);
478 blk_queue_hardsect_size(dev_info->dcssblk_queue, 4096); 476 blk_queue_hardsect_size(dev_info->dcssblk_queue, 4096);
479 477
478 add_disk(dev_info->gd);
479
480 switch (dev_info->segment_type) { 480 switch (dev_info->segment_type) {
481 case SEG_TYPE_SR: 481 case SEG_TYPE_SR:
482 case SEG_TYPE_ER: 482 case SEG_TYPE_ER:
diff --git a/drivers/s390/cio/css.c b/drivers/s390/cio/css.c
index 838f7ac0dc32..c3df2cd009a4 100644
--- a/drivers/s390/cio/css.c
+++ b/drivers/s390/cio/css.c
@@ -451,6 +451,7 @@ static int reprobe_subchannel(struct subchannel_id schid, void *data)
451 break; 451 break;
452 case -ENXIO: 452 case -ENXIO:
453 case -ENOMEM: 453 case -ENOMEM:
454 case -EIO:
454 /* These should abort looping */ 455 /* These should abort looping */
455 break; 456 break;
456 default: 457 default:
@@ -483,7 +484,7 @@ static DECLARE_WORK(css_reprobe_work, reprobe_all);
483void css_schedule_reprobe(void) 484void css_schedule_reprobe(void)
484{ 485{
485 need_reprobe = 1; 486 need_reprobe = 1;
486 queue_work(ccw_device_work, &css_reprobe_work); 487 queue_work(slow_path_wq, &css_reprobe_work);
487} 488}
488 489
489EXPORT_SYMBOL_GPL(css_schedule_reprobe); 490EXPORT_SYMBOL_GPL(css_schedule_reprobe);
diff --git a/drivers/s390/cio/device_fsm.c b/drivers/s390/cio/device_fsm.c
index 8867443b8060..bfad421cda66 100644
--- a/drivers/s390/cio/device_fsm.c
+++ b/drivers/s390/cio/device_fsm.c
@@ -1034,7 +1034,7 @@ device_trigger_reprobe(struct subchannel *sch)
1034 if (sch->schib.pmcw.dev != cdev->private->dev_id.devno) { 1034 if (sch->schib.pmcw.dev != cdev->private->dev_id.devno) {
1035 PREPARE_WORK(&cdev->private->kick_work, 1035 PREPARE_WORK(&cdev->private->kick_work,
1036 ccw_device_move_to_orphanage); 1036 ccw_device_move_to_orphanage);
1037 queue_work(ccw_device_work, &cdev->private->kick_work); 1037 queue_work(slow_path_wq, &cdev->private->kick_work);
1038 } else 1038 } else
1039 ccw_device_start_id(cdev, 0); 1039 ccw_device_start_id(cdev, 0);
1040} 1040}
diff --git a/drivers/s390/cio/device_id.c b/drivers/s390/cio/device_id.c
index f232832f2b22..156f3f9786b5 100644
--- a/drivers/s390/cio/device_id.c
+++ b/drivers/s390/cio/device_id.c
@@ -118,14 +118,6 @@ __ccw_device_sense_id_start(struct ccw_device *cdev)
118 sch = to_subchannel(cdev->dev.parent); 118 sch = to_subchannel(cdev->dev.parent);
119 /* Setup sense channel program. */ 119 /* Setup sense channel program. */
120 ccw = cdev->private->iccws; 120 ccw = cdev->private->iccws;
121 if (sch->schib.pmcw.pim != 0x80) {
122 /* more than one path installed. */
123 ccw->cmd_code = CCW_CMD_SUSPEND_RECONN;
124 ccw->cda = 0;
125 ccw->count = 0;
126 ccw->flags = CCW_FLAG_SLI | CCW_FLAG_CC;
127 ccw++;
128 }
129 ccw->cmd_code = CCW_CMD_SENSE_ID; 121 ccw->cmd_code = CCW_CMD_SENSE_ID;
130 ccw->cda = (__u32) __pa (&cdev->private->senseid); 122 ccw->cda = (__u32) __pa (&cdev->private->senseid);
131 ccw->count = sizeof (struct senseid); 123 ccw->count = sizeof (struct senseid);
diff --git a/drivers/s390/net/ctcmain.c b/drivers/s390/net/ctcmain.c
index 6bf3ebbe985a..77a503139e32 100644
--- a/drivers/s390/net/ctcmain.c
+++ b/drivers/s390/net/ctcmain.c
@@ -478,14 +478,14 @@ ctc_unpack_skb(struct channel *ch, struct sk_buff *pskb)
478 skb->dev = pskb->dev; 478 skb->dev = pskb->dev;
479 skb->protocol = pskb->protocol; 479 skb->protocol = pskb->protocol;
480 pskb->ip_summed = CHECKSUM_UNNECESSARY; 480 pskb->ip_summed = CHECKSUM_UNNECESSARY;
481 netif_rx_ni(skb);
482 /** 481 /**
483 * Successful rx; reset logflags 482 * reset logflags
484 */ 483 */
485 ch->logflags = 0; 484 ch->logflags = 0;
486 dev->last_rx = jiffies;
487 privptr->stats.rx_packets++; 485 privptr->stats.rx_packets++;
488 privptr->stats.rx_bytes += skb->len; 486 privptr->stats.rx_bytes += skb->len;
487 netif_rx_ni(skb);
488 dev->last_rx = jiffies;
489 if (len > 0) { 489 if (len > 0) {
490 skb_pull(pskb, header->length); 490 skb_pull(pskb, header->length);
491 if (skb_tailroom(pskb) < LL_HEADER_LENGTH) { 491 if (skb_tailroom(pskb) < LL_HEADER_LENGTH) {
@@ -2782,35 +2782,14 @@ ctc_probe_device(struct ccwgroup_device *cgdev)
2782} 2782}
2783 2783
2784/** 2784/**
2785 * Initialize everything of the net device except the name and the 2785 * Device setup function called by alloc_netdev().
2786 * channel structs. 2786 *
2787 * @param dev Device to be setup.
2787 */ 2788 */
2788static struct net_device * 2789void ctc_init_netdevice(struct net_device * dev)
2789ctc_init_netdevice(struct net_device * dev, int alloc_device,
2790 struct ctc_priv *privptr)
2791{ 2790{
2792 if (!privptr)
2793 return NULL;
2794
2795 DBF_TEXT(setup, 3, __FUNCTION__); 2791 DBF_TEXT(setup, 3, __FUNCTION__);
2796 2792
2797 if (alloc_device) {
2798 dev = kzalloc(sizeof(struct net_device), GFP_KERNEL);
2799 if (!dev)
2800 return NULL;
2801 }
2802
2803 dev->priv = privptr;
2804 privptr->fsm = init_fsm("ctcdev", dev_state_names,
2805 dev_event_names, CTC_NR_DEV_STATES, CTC_NR_DEV_EVENTS,
2806 dev_fsm, DEV_FSM_LEN, GFP_KERNEL);
2807 if (privptr->fsm == NULL) {
2808 if (alloc_device)
2809 kfree(dev);
2810 return NULL;
2811 }
2812 fsm_newstate(privptr->fsm, DEV_STATE_STOPPED);
2813 fsm_settimer(privptr->fsm, &privptr->restart_timer);
2814 if (dev->mtu == 0) 2793 if (dev->mtu == 0)
2815 dev->mtu = CTC_BUFSIZE_DEFAULT - LL_HEADER_LENGTH - 2; 2794 dev->mtu = CTC_BUFSIZE_DEFAULT - LL_HEADER_LENGTH - 2;
2816 dev->hard_start_xmit = ctc_tx; 2795 dev->hard_start_xmit = ctc_tx;
@@ -2823,7 +2802,6 @@ ctc_init_netdevice(struct net_device * dev, int alloc_device,
2823 dev->type = ARPHRD_SLIP; 2802 dev->type = ARPHRD_SLIP;
2824 dev->tx_queue_len = 100; 2803 dev->tx_queue_len = 100;
2825 dev->flags = IFF_POINTOPOINT | IFF_NOARP; 2804 dev->flags = IFF_POINTOPOINT | IFF_NOARP;
2826 return dev;
2827} 2805}
2828 2806
2829 2807
@@ -2879,14 +2857,22 @@ ctc_new_device(struct ccwgroup_device *cgdev)
2879 "ccw_device_set_online (cdev[1]) failed with ret = %d\n", ret); 2857 "ccw_device_set_online (cdev[1]) failed with ret = %d\n", ret);
2880 } 2858 }
2881 2859
2882 dev = ctc_init_netdevice(NULL, 1, privptr); 2860 dev = alloc_netdev(0, "ctc%d", ctc_init_netdevice);
2883
2884 if (!dev) { 2861 if (!dev) {
2885 ctc_pr_warn("ctc_init_netdevice failed\n"); 2862 ctc_pr_warn("ctc_init_netdevice failed\n");
2886 goto out; 2863 goto out;
2887 } 2864 }
2865 dev->priv = privptr;
2888 2866
2889 strlcpy(dev->name, "ctc%d", IFNAMSIZ); 2867 privptr->fsm = init_fsm("ctcdev", dev_state_names,
2868 dev_event_names, CTC_NR_DEV_STATES, CTC_NR_DEV_EVENTS,
2869 dev_fsm, DEV_FSM_LEN, GFP_KERNEL);
2870 if (privptr->fsm == NULL) {
2871 free_netdev(dev);
2872 goto out;
2873 }
2874 fsm_newstate(privptr->fsm, DEV_STATE_STOPPED);
2875 fsm_settimer(privptr->fsm, &privptr->restart_timer);
2890 2876
2891 for (direction = READ; direction <= WRITE; direction++) { 2877 for (direction = READ; direction <= WRITE; direction++) {
2892 privptr->channel[direction] = 2878 privptr->channel[direction] =
diff --git a/drivers/s390/net/netiucv.c b/drivers/s390/net/netiucv.c
index 4d18d6419ddc..c7ea9381db9f 100644
--- a/drivers/s390/net/netiucv.c
+++ b/drivers/s390/net/netiucv.c
@@ -639,14 +639,14 @@ static void netiucv_unpack_skb(struct iucv_connection *conn,
639 skb->dev = pskb->dev; 639 skb->dev = pskb->dev;
640 skb->protocol = pskb->protocol; 640 skb->protocol = pskb->protocol;
641 pskb->ip_summed = CHECKSUM_UNNECESSARY; 641 pskb->ip_summed = CHECKSUM_UNNECESSARY;
642 privptr->stats.rx_packets++;
643 privptr->stats.rx_bytes += skb->len;
642 /* 644 /*
643 * Since receiving is always initiated from a tasklet (in iucv.c), 645 * Since receiving is always initiated from a tasklet (in iucv.c),
644 * we must use netif_rx_ni() instead of netif_rx() 646 * we must use netif_rx_ni() instead of netif_rx()
645 */ 647 */
646 netif_rx_ni(skb); 648 netif_rx_ni(skb);
647 dev->last_rx = jiffies; 649 dev->last_rx = jiffies;
648 privptr->stats.rx_packets++;
649 privptr->stats.rx_bytes += skb->len;
650 skb_pull(pskb, header->next); 650 skb_pull(pskb, header->next);
651 skb_put(pskb, NETIUCV_HDRLEN); 651 skb_put(pskb, NETIUCV_HDRLEN);
652 } 652 }
diff --git a/drivers/s390/scsi/zfcp_erp.c b/drivers/s390/scsi/zfcp_erp.c
index 5552b755c08a..07fa824d179f 100644
--- a/drivers/s390/scsi/zfcp_erp.c
+++ b/drivers/s390/scsi/zfcp_erp.c
@@ -977,7 +977,9 @@ static void zfcp_erp_action_dismiss(struct zfcp_erp_action *erp_action)
977 debug_text_event(adapter->erp_dbf, 2, "a_adis"); 977 debug_text_event(adapter->erp_dbf, 2, "a_adis");
978 debug_event(adapter->erp_dbf, 2, &erp_action->action, sizeof (int)); 978 debug_event(adapter->erp_dbf, 2, &erp_action->action, sizeof (int));
979 979
980 zfcp_erp_async_handler_nolock(erp_action, ZFCP_STATUS_ERP_DISMISSED); 980 erp_action->status |= ZFCP_STATUS_ERP_DISMISSED;
981 if (zfcp_erp_action_exists(erp_action) == ZFCP_ERP_ACTION_RUNNING)
982 zfcp_erp_action_ready(erp_action);
981} 983}
982 984
983int 985int
@@ -1063,7 +1065,7 @@ zfcp_erp_thread(void *data)
1063 &adapter->status)) { 1065 &adapter->status)) {
1064 1066
1065 write_lock_irqsave(&adapter->erp_lock, flags); 1067 write_lock_irqsave(&adapter->erp_lock, flags);
1066 next = adapter->erp_ready_head.prev; 1068 next = adapter->erp_ready_head.next;
1067 write_unlock_irqrestore(&adapter->erp_lock, flags); 1069 write_unlock_irqrestore(&adapter->erp_lock, flags);
1068 1070
1069 if (next != &adapter->erp_ready_head) { 1071 if (next != &adapter->erp_ready_head) {
@@ -1153,15 +1155,13 @@ zfcp_erp_strategy(struct zfcp_erp_action *erp_action)
1153 1155
1154 /* 1156 /*
1155 * check for dismissed status again to avoid follow-up actions, 1157 * check for dismissed status again to avoid follow-up actions,
1156 * failing of targets and so on for dismissed actions 1158 * failing of targets and so on for dismissed actions,
1159 * we go through down() here because there has been an up()
1157 */ 1160 */
1158 retval = zfcp_erp_strategy_check_action(erp_action, retval); 1161 if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED)
1162 retval = ZFCP_ERP_CONTINUES;
1159 1163
1160 switch (retval) { 1164 switch (retval) {
1161 case ZFCP_ERP_DISMISSED:
1162 /* leave since this action has ridden to its ancestors */
1163 debug_text_event(adapter->erp_dbf, 6, "a_st_dis2");
1164 goto unlock;
1165 case ZFCP_ERP_NOMEM: 1165 case ZFCP_ERP_NOMEM:
1166 /* no memory to continue immediately, let it sleep */ 1166 /* no memory to continue immediately, let it sleep */
1167 if (!(erp_action->status & ZFCP_STATUS_ERP_LOWMEM)) { 1167 if (!(erp_action->status & ZFCP_STATUS_ERP_LOWMEM)) {
@@ -3089,7 +3089,7 @@ zfcp_erp_action_enqueue(int action,
3089 ++adapter->erp_total_count; 3089 ++adapter->erp_total_count;
3090 3090
3091 /* finally put it into 'ready' queue and kick erp thread */ 3091 /* finally put it into 'ready' queue and kick erp thread */
3092 list_add(&erp_action->list, &adapter->erp_ready_head); 3092 list_add_tail(&erp_action->list, &adapter->erp_ready_head);
3093 up(&adapter->erp_ready_sem); 3093 up(&adapter->erp_ready_sem);
3094 retval = 0; 3094 retval = 0;
3095 out: 3095 out:
diff --git a/drivers/sbus/char/cpwatchdog.c b/drivers/sbus/char/cpwatchdog.c
index 7b5773d88212..a4e758143665 100644
--- a/drivers/sbus/char/cpwatchdog.c
+++ b/drivers/sbus/char/cpwatchdog.c
@@ -154,7 +154,7 @@ struct wd_device {
154}; 154};
155 155
156static struct wd_device wd_dev = { 156static struct wd_device wd_dev = {
157 0, SPIN_LOCK_UNLOCKED, 0, 0, 0, 0, 157 0, __SPIN_LOCK_UNLOCKED(wd_dev.lock), 0, 0, 0, 0,
158}; 158};
159 159
160static struct timer_list wd_timer; 160static struct timer_list wd_timer;
diff --git a/drivers/scsi/aacraid/commsup.c b/drivers/scsi/aacraid/commsup.c
index 240a0bb8986f..abce48ccc85b 100644
--- a/drivers/scsi/aacraid/commsup.c
+++ b/drivers/scsi/aacraid/commsup.c
@@ -1339,10 +1339,10 @@ int aac_check_health(struct aac_dev * aac)
1339 aif = (struct aac_aifcmd *)hw_fib->data; 1339 aif = (struct aac_aifcmd *)hw_fib->data;
1340 aif->command = cpu_to_le32(AifCmdEventNotify); 1340 aif->command = cpu_to_le32(AifCmdEventNotify);
1341 aif->seqnum = cpu_to_le32(0xFFFFFFFF); 1341 aif->seqnum = cpu_to_le32(0xFFFFFFFF);
1342 aif->data[0] = cpu_to_le32(AifEnExpEvent); 1342 aif->data[0] = AifEnExpEvent;
1343 aif->data[1] = cpu_to_le32(AifExeFirmwarePanic); 1343 aif->data[1] = AifExeFirmwarePanic;
1344 aif->data[2] = cpu_to_le32(AifHighPriority); 1344 aif->data[2] = AifHighPriority;
1345 aif->data[3] = cpu_to_le32(BlinkLED); 1345 aif->data[3] = BlinkLED;
1346 1346
1347 /* 1347 /*
1348 * Put the FIB onto the 1348 * Put the FIB onto the
diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
index 038980be763d..9dd331bc29b0 100644
--- a/drivers/scsi/aacraid/linit.c
+++ b/drivers/scsi/aacraid/linit.c
@@ -636,7 +636,7 @@ static int aac_cfg_open(struct inode *inode, struct file *file)
636static int aac_cfg_ioctl(struct inode *inode, struct file *file, 636static int aac_cfg_ioctl(struct inode *inode, struct file *file,
637 unsigned int cmd, unsigned long arg) 637 unsigned int cmd, unsigned long arg)
638{ 638{
639 if (!capable(CAP_SYS_ADMIN)) 639 if (!capable(CAP_SYS_RAWIO))
640 return -EPERM; 640 return -EPERM;
641 return aac_do_ioctl(file->private_data, cmd, (void __user *)arg); 641 return aac_do_ioctl(file->private_data, cmd, (void __user *)arg);
642} 642}
@@ -691,7 +691,7 @@ static int aac_compat_ioctl(struct scsi_device *sdev, int cmd, void __user *arg)
691 691
692static long aac_compat_cfg_ioctl(struct file *file, unsigned cmd, unsigned long arg) 692static long aac_compat_cfg_ioctl(struct file *file, unsigned cmd, unsigned long arg)
693{ 693{
694 if (!capable(CAP_SYS_ADMIN)) 694 if (!capable(CAP_SYS_RAWIO))
695 return -EPERM; 695 return -EPERM;
696 return aac_compat_do_ioctl((struct aac_dev *)file->private_data, cmd, arg); 696 return aac_compat_do_ioctl((struct aac_dev *)file->private_data, cmd, arg);
697} 697}
@@ -950,7 +950,8 @@ static struct scsi_host_template aac_driver_template = {
950 950
951static void __aac_shutdown(struct aac_dev * aac) 951static void __aac_shutdown(struct aac_dev * aac)
952{ 952{
953 kthread_stop(aac->thread); 953 if (aac->aif_thread)
954 kthread_stop(aac->thread);
954 aac_send_shutdown(aac); 955 aac_send_shutdown(aac);
955 aac_adapter_disable_int(aac); 956 aac_adapter_disable_int(aac);
956 free_irq(aac->pdev->irq, aac); 957 free_irq(aac->pdev->irq, aac);
diff --git a/drivers/scsi/atari_scsi.c b/drivers/scsi/atari_scsi.c
index 6f8403b82ba1..f5732d8f67fe 100644
--- a/drivers/scsi/atari_scsi.c
+++ b/drivers/scsi/atari_scsi.c
@@ -393,7 +393,7 @@ static irqreturn_t scsi_tt_intr(int irq, void *dummy)
393 393
394#endif /* REAL_DMA */ 394#endif /* REAL_DMA */
395 395
396 NCR5380_intr(0, 0); 396 NCR5380_intr(irq, dummy);
397 397
398#if 0 398#if 0
399 /* To be sure the int is not masked */ 399 /* To be sure the int is not masked */
@@ -458,7 +458,7 @@ static irqreturn_t scsi_falcon_intr(int irq, void *dummy)
458 458
459#endif /* REAL_DMA */ 459#endif /* REAL_DMA */
460 460
461 NCR5380_intr(0, 0); 461 NCR5380_intr(irq, dummy);
462 return IRQ_HANDLED; 462 return IRQ_HANDLED;
463} 463}
464 464
@@ -684,7 +684,7 @@ int atari_scsi_detect(struct scsi_host_template *host)
684 * interrupt after having cleared the pending flag for the DMA 684 * interrupt after having cleared the pending flag for the DMA
685 * interrupt. */ 685 * interrupt. */
686 if (request_irq(IRQ_TT_MFP_SCSI, scsi_tt_intr, IRQ_TYPE_SLOW, 686 if (request_irq(IRQ_TT_MFP_SCSI, scsi_tt_intr, IRQ_TYPE_SLOW,
687 "SCSI NCR5380", scsi_tt_intr)) { 687 "SCSI NCR5380", instance)) {
688 printk(KERN_ERR "atari_scsi_detect: cannot allocate irq %d, aborting",IRQ_TT_MFP_SCSI); 688 printk(KERN_ERR "atari_scsi_detect: cannot allocate irq %d, aborting",IRQ_TT_MFP_SCSI);
689 scsi_unregister(atari_scsi_host); 689 scsi_unregister(atari_scsi_host);
690 atari_stram_free(atari_dma_buffer); 690 atari_stram_free(atari_dma_buffer);
@@ -701,7 +701,7 @@ int atari_scsi_detect(struct scsi_host_template *host)
701 IRQ_TYPE_PRIO, "Hades DMA emulator", 701 IRQ_TYPE_PRIO, "Hades DMA emulator",
702 hades_dma_emulator)) { 702 hades_dma_emulator)) {
703 printk(KERN_ERR "atari_scsi_detect: cannot allocate irq %d, aborting (MACH_IS_HADES)",IRQ_AUTO_2); 703 printk(KERN_ERR "atari_scsi_detect: cannot allocate irq %d, aborting (MACH_IS_HADES)",IRQ_AUTO_2);
704 free_irq(IRQ_TT_MFP_SCSI, scsi_tt_intr); 704 free_irq(IRQ_TT_MFP_SCSI, instance);
705 scsi_unregister(atari_scsi_host); 705 scsi_unregister(atari_scsi_host);
706 atari_stram_free(atari_dma_buffer); 706 atari_stram_free(atari_dma_buffer);
707 atari_dma_buffer = 0; 707 atari_dma_buffer = 0;
@@ -761,7 +761,7 @@ int atari_scsi_detect(struct scsi_host_template *host)
761int atari_scsi_release(struct Scsi_Host *sh) 761int atari_scsi_release(struct Scsi_Host *sh)
762{ 762{
763 if (IS_A_TT()) 763 if (IS_A_TT())
764 free_irq(IRQ_TT_MFP_SCSI, scsi_tt_intr); 764 free_irq(IRQ_TT_MFP_SCSI, sh);
765 if (atari_dma_buffer) 765 if (atari_dma_buffer)
766 atari_stram_free(atari_dma_buffer); 766 atari_stram_free(atari_dma_buffer);
767 return 1; 767 return 1;
diff --git a/drivers/scsi/dpt_i2o.c b/drivers/scsi/dpt_i2o.c
index 8258506ba7d7..b31d1c95c9fb 100644
--- a/drivers/scsi/dpt_i2o.c
+++ b/drivers/scsi/dpt_i2o.c
@@ -173,20 +173,20 @@ static struct pci_device_id dptids[] = {
173}; 173};
174MODULE_DEVICE_TABLE(pci,dptids); 174MODULE_DEVICE_TABLE(pci,dptids);
175 175
176static void adpt_exit(void); 176static int adpt_detect(struct scsi_host_template* sht)
177
178static int adpt_detect(void)
179{ 177{
180 struct pci_dev *pDev = NULL; 178 struct pci_dev *pDev = NULL;
181 adpt_hba* pHba; 179 adpt_hba* pHba;
182 180
181 adpt_init();
182
183 PINFO("Detecting Adaptec I2O RAID controllers...\n"); 183 PINFO("Detecting Adaptec I2O RAID controllers...\n");
184 184
185 /* search for all Adatpec I2O RAID cards */ 185 /* search for all Adatpec I2O RAID cards */
186 while ((pDev = pci_get_device( PCI_DPT_VENDOR_ID, PCI_ANY_ID, pDev))) { 186 while ((pDev = pci_get_device( PCI_DPT_VENDOR_ID, PCI_ANY_ID, pDev))) {
187 if(pDev->device == PCI_DPT_DEVICE_ID || 187 if(pDev->device == PCI_DPT_DEVICE_ID ||
188 pDev->device == PCI_DPT_RAPTOR_DEVICE_ID){ 188 pDev->device == PCI_DPT_RAPTOR_DEVICE_ID){
189 if(adpt_install_hba(pDev) ){ 189 if(adpt_install_hba(sht, pDev) ){
190 PERROR("Could not Init an I2O RAID device\n"); 190 PERROR("Could not Init an I2O RAID device\n");
191 PERROR("Will not try to detect others.\n"); 191 PERROR("Will not try to detect others.\n");
192 return hba_count-1; 192 return hba_count-1;
@@ -248,33 +248,34 @@ rebuild_sys_tab:
248 } 248 }
249 249
250 for (pHba = hba_chain; pHba; pHba = pHba->next) { 250 for (pHba = hba_chain; pHba; pHba = pHba->next) {
251 if (adpt_scsi_register(pHba) < 0) { 251 if( adpt_scsi_register(pHba,sht) < 0){
252 adpt_i2o_delete_hba(pHba); 252 adpt_i2o_delete_hba(pHba);
253 continue; 253 continue;
254 } 254 }
255 pHba->initialized = TRUE; 255 pHba->initialized = TRUE;
256 pHba->state &= ~DPTI_STATE_RESET; 256 pHba->state &= ~DPTI_STATE_RESET;
257 scsi_scan_host(pHba->host);
258 } 257 }
259 258
260 // Register our control device node 259 // Register our control device node
261 // nodes will need to be created in /dev to access this 260 // nodes will need to be created in /dev to access this
262 // the nodes can not be created from within the driver 261 // the nodes can not be created from within the driver
263 if (hba_count && register_chrdev(DPTI_I2O_MAJOR, DPT_DRIVER, &adpt_fops)) { 262 if (hba_count && register_chrdev(DPTI_I2O_MAJOR, DPT_DRIVER, &adpt_fops)) {
264 adpt_exit(); 263 adpt_i2o_sys_shutdown();
265 return 0; 264 return 0;
266 } 265 }
267 return hba_count; 266 return hba_count;
268} 267}
269 268
270 269
271static int adpt_release(adpt_hba *pHba) 270/*
271 * scsi_unregister will be called AFTER we return.
272 */
273static int adpt_release(struct Scsi_Host *host)
272{ 274{
273 struct Scsi_Host *shost = pHba->host; 275 adpt_hba* pHba = (adpt_hba*) host->hostdata[0];
274 scsi_remove_host(shost);
275// adpt_i2o_quiesce_hba(pHba); 276// adpt_i2o_quiesce_hba(pHba);
276 adpt_i2o_delete_hba(pHba); 277 adpt_i2o_delete_hba(pHba);
277 scsi_host_put(shost); 278 scsi_unregister(host);
278 return 0; 279 return 0;
279} 280}
280 281
@@ -881,7 +882,7 @@ static int adpt_reboot_event(struct notifier_block *n, ulong code, void *p)
881#endif 882#endif
882 883
883 884
884static int adpt_install_hba(struct pci_dev* pDev) 885static int adpt_install_hba(struct scsi_host_template* sht, struct pci_dev* pDev)
885{ 886{
886 887
887 adpt_hba* pHba = NULL; 888 adpt_hba* pHba = NULL;
@@ -905,8 +906,7 @@ static int adpt_install_hba(struct pci_dev* pDev)
905 } 906 }
906 907
907 pci_set_master(pDev); 908 pci_set_master(pDev);
908 if (pci_set_dma_mask(pDev, DMA_64BIT_MASK) && 909 if (pci_set_dma_mask(pDev, DMA_32BIT_MASK))
909 pci_set_dma_mask(pDev, DMA_32BIT_MASK))
910 return -EINVAL; 910 return -EINVAL;
911 911
912 base_addr0_phys = pci_resource_start(pDev,0); 912 base_addr0_phys = pci_resource_start(pDev,0);
@@ -1028,6 +1028,8 @@ static void adpt_i2o_delete_hba(adpt_hba* pHba)
1028 1028
1029 1029
1030 mutex_lock(&adpt_configuration_lock); 1030 mutex_lock(&adpt_configuration_lock);
1031 // scsi_unregister calls our adpt_release which
1032 // does a quiese
1031 if(pHba->host){ 1033 if(pHba->host){
1032 free_irq(pHba->host->irq, pHba); 1034 free_irq(pHba->host->irq, pHba);
1033 } 1035 }
@@ -1079,6 +1081,17 @@ static void adpt_i2o_delete_hba(adpt_hba* pHba)
1079} 1081}
1080 1082
1081 1083
1084static int adpt_init(void)
1085{
1086 printk("Loading Adaptec I2O RAID: Version " DPT_I2O_VERSION "\n");
1087#ifdef REBOOT_NOTIFIER
1088 register_reboot_notifier(&adpt_reboot_notifier);
1089#endif
1090
1091 return 0;
1092}
1093
1094
1082static struct adpt_device* adpt_find_device(adpt_hba* pHba, u32 chan, u32 id, u32 lun) 1095static struct adpt_device* adpt_find_device(adpt_hba* pHba, u32 chan, u32 id, u32 lun)
1083{ 1096{
1084 struct adpt_device* d; 1097 struct adpt_device* d;
@@ -2164,6 +2177,37 @@ static s32 adpt_scsi_to_i2o(adpt_hba* pHba, struct scsi_cmnd* cmd, struct adpt_d
2164} 2177}
2165 2178
2166 2179
2180static s32 adpt_scsi_register(adpt_hba* pHba,struct scsi_host_template * sht)
2181{
2182 struct Scsi_Host *host = NULL;
2183
2184 host = scsi_register(sht, sizeof(adpt_hba*));
2185 if (host == NULL) {
2186 printk ("%s: scsi_register returned NULL\n",pHba->name);
2187 return -1;
2188 }
2189 host->hostdata[0] = (unsigned long)pHba;
2190 pHba->host = host;
2191
2192 host->irq = pHba->pDev->irq;
2193 /* no IO ports, so don't have to set host->io_port and
2194 * host->n_io_port
2195 */
2196 host->io_port = 0;
2197 host->n_io_port = 0;
2198 /* see comments in scsi_host.h */
2199 host->max_id = 16;
2200 host->max_lun = 256;
2201 host->max_channel = pHba->top_scsi_channel + 1;
2202 host->cmd_per_lun = 1;
2203 host->unique_id = (uint) pHba;
2204 host->sg_tablesize = pHba->sg_tablesize;
2205 host->can_queue = pHba->post_fifo_size;
2206
2207 return 0;
2208}
2209
2210
2167static s32 adpt_i2o_to_scsi(void __iomem *reply, struct scsi_cmnd* cmd) 2211static s32 adpt_i2o_to_scsi(void __iomem *reply, struct scsi_cmnd* cmd)
2168{ 2212{
2169 adpt_hba* pHba; 2213 adpt_hba* pHba;
@@ -3279,10 +3323,12 @@ static static void adpt_delay(int millisec)
3279 3323
3280#endif 3324#endif
3281 3325
3282static struct scsi_host_template adpt_template = { 3326static struct scsi_host_template driver_template = {
3283 .name = "dpt_i2o", 3327 .name = "dpt_i2o",
3284 .proc_name = "dpt_i2o", 3328 .proc_name = "dpt_i2o",
3285 .proc_info = adpt_proc_info, 3329 .proc_info = adpt_proc_info,
3330 .detect = adpt_detect,
3331 .release = adpt_release,
3286 .info = adpt_info, 3332 .info = adpt_info,
3287 .queuecommand = adpt_queue, 3333 .queuecommand = adpt_queue,
3288 .eh_abort_handler = adpt_abort, 3334 .eh_abort_handler = adpt_abort,
@@ -3297,62 +3343,5 @@ static struct scsi_host_template adpt_template = {
3297 .use_clustering = ENABLE_CLUSTERING, 3343 .use_clustering = ENABLE_CLUSTERING,
3298 .use_sg_chaining = ENABLE_SG_CHAINING, 3344 .use_sg_chaining = ENABLE_SG_CHAINING,
3299}; 3345};
3300 3346#include "scsi_module.c"
3301static s32 adpt_scsi_register(adpt_hba* pHba)
3302{
3303 struct Scsi_Host *host;
3304
3305 host = scsi_host_alloc(&adpt_template, sizeof(adpt_hba*));
3306 if (host == NULL) {
3307 printk ("%s: scsi_host_alloc returned NULL\n",pHba->name);
3308 return -1;
3309 }
3310 host->hostdata[0] = (unsigned long)pHba;
3311 pHba->host = host;
3312
3313 host->irq = pHba->pDev->irq;
3314 /* no IO ports, so don't have to set host->io_port and
3315 * host->n_io_port
3316 */
3317 host->io_port = 0;
3318 host->n_io_port = 0;
3319 /* see comments in scsi_host.h */
3320 host->max_id = 16;
3321 host->max_lun = 256;
3322 host->max_channel = pHba->top_scsi_channel + 1;
3323 host->cmd_per_lun = 1;
3324 host->unique_id = (uint) pHba;
3325 host->sg_tablesize = pHba->sg_tablesize;
3326 host->can_queue = pHba->post_fifo_size;
3327
3328 if (scsi_add_host(host, &pHba->pDev->dev)) {
3329 scsi_host_put(host);
3330 return -1;
3331 }
3332
3333 return 0;
3334}
3335
3336static int __init adpt_init(void)
3337{
3338 int count;
3339
3340 printk("Loading Adaptec I2O RAID: Version " DPT_I2O_VERSION "\n");
3341#ifdef REBOOT_NOTIFIER
3342 register_reboot_notifier(&adpt_reboot_notifier);
3343#endif
3344
3345 count = adpt_detect();
3346
3347 return count > 0 ? 0 : -ENODEV;
3348}
3349
3350static void adpt_exit(void)
3351{
3352 while (hba_chain)
3353 adpt_release(hba_chain);
3354}
3355
3356module_init(adpt_init);
3357module_exit(adpt_exit);
3358MODULE_LICENSE("GPL"); 3347MODULE_LICENSE("GPL");
diff --git a/drivers/scsi/dpti.h b/drivers/scsi/dpti.h
index 0892f6c70319..fd79068c5869 100644
--- a/drivers/scsi/dpti.h
+++ b/drivers/scsi/dpti.h
@@ -28,9 +28,11 @@
28 * SCSI interface function Prototypes 28 * SCSI interface function Prototypes
29 */ 29 */
30 30
31static int adpt_detect(struct scsi_host_template * sht);
31static int adpt_queue(struct scsi_cmnd * cmd, void (*cmdcomplete) (struct scsi_cmnd *)); 32static int adpt_queue(struct scsi_cmnd * cmd, void (*cmdcomplete) (struct scsi_cmnd *));
32static int adpt_abort(struct scsi_cmnd * cmd); 33static int adpt_abort(struct scsi_cmnd * cmd);
33static int adpt_reset(struct scsi_cmnd* cmd); 34static int adpt_reset(struct scsi_cmnd* cmd);
35static int adpt_release(struct Scsi_Host *host);
34static int adpt_slave_configure(struct scsi_device *); 36static int adpt_slave_configure(struct scsi_device *);
35 37
36static const char *adpt_info(struct Scsi_Host *pSHost); 38static const char *adpt_info(struct Scsi_Host *pSHost);
@@ -47,6 +49,8 @@ static int adpt_device_reset(struct scsi_cmnd* cmd);
47 49
48#define DPT_DRIVER_NAME "Adaptec I2O RAID" 50#define DPT_DRIVER_NAME "Adaptec I2O RAID"
49 51
52#ifndef HOSTS_C
53
50#include "dpt/sys_info.h" 54#include "dpt/sys_info.h"
51#include <linux/wait.h> 55#include <linux/wait.h>
52#include "dpt/dpti_i2o.h" 56#include "dpt/dpti_i2o.h"
@@ -285,7 +289,7 @@ static s32 adpt_i2o_init_outbound_q(adpt_hba* pHba);
285static s32 adpt_i2o_hrt_get(adpt_hba* pHba); 289static s32 adpt_i2o_hrt_get(adpt_hba* pHba);
286static s32 adpt_scsi_to_i2o(adpt_hba* pHba, struct scsi_cmnd* cmd, struct adpt_device* dptdevice); 290static s32 adpt_scsi_to_i2o(adpt_hba* pHba, struct scsi_cmnd* cmd, struct adpt_device* dptdevice);
287static s32 adpt_i2o_to_scsi(void __iomem *reply, struct scsi_cmnd* cmd); 291static s32 adpt_i2o_to_scsi(void __iomem *reply, struct scsi_cmnd* cmd);
288static s32 adpt_scsi_register(adpt_hba* pHba); 292static s32 adpt_scsi_register(adpt_hba* pHba,struct scsi_host_template * sht);
289static s32 adpt_hba_reset(adpt_hba* pHba); 293static s32 adpt_hba_reset(adpt_hba* pHba);
290static s32 adpt_i2o_reset_hba(adpt_hba* pHba); 294static s32 adpt_i2o_reset_hba(adpt_hba* pHba);
291static s32 adpt_rescan(adpt_hba* pHba); 295static s32 adpt_rescan(adpt_hba* pHba);
@@ -295,7 +299,7 @@ static void adpt_i2o_delete_hba(adpt_hba* pHba);
295static void adpt_inquiry(adpt_hba* pHba); 299static void adpt_inquiry(adpt_hba* pHba);
296static void adpt_fail_posted_scbs(adpt_hba* pHba); 300static void adpt_fail_posted_scbs(adpt_hba* pHba);
297static struct adpt_device* adpt_find_device(adpt_hba* pHba, u32 chan, u32 id, u32 lun); 301static struct adpt_device* adpt_find_device(adpt_hba* pHba, u32 chan, u32 id, u32 lun);
298static int adpt_install_hba(struct pci_dev* pDev) ; 302static int adpt_install_hba(struct scsi_host_template* sht, struct pci_dev* pDev) ;
299static int adpt_i2o_online_hba(adpt_hba* pHba); 303static int adpt_i2o_online_hba(adpt_hba* pHba);
300static void adpt_i2o_post_wait_complete(u32, int); 304static void adpt_i2o_post_wait_complete(u32, int);
301static int adpt_i2o_systab_send(adpt_hba* pHba); 305static int adpt_i2o_systab_send(adpt_hba* pHba);
@@ -339,4 +343,5 @@ static void adpt_i386_info(sysInfo_S* si);
339#define FW_DEBUG_BLED_OFFSET 8 343#define FW_DEBUG_BLED_OFFSET 8
340 344
341#define FW_DEBUG_FLAGS_NO_HEADERS_B 0x01 345#define FW_DEBUG_FLAGS_NO_HEADERS_B 0x01
346#endif /* !HOSTS_C */
342#endif /* _DPT_H */ 347#endif /* _DPT_H */
diff --git a/drivers/scsi/dtc.c b/drivers/scsi/dtc.c
index 2596165096d3..c2677ba29c74 100644
--- a/drivers/scsi/dtc.c
+++ b/drivers/scsi/dtc.c
@@ -277,7 +277,8 @@ found:
277 /* With interrupts enabled, it will sometimes hang when doing heavy 277 /* With interrupts enabled, it will sometimes hang when doing heavy
278 * reads. So better not enable them until I finger it out. */ 278 * reads. So better not enable them until I finger it out. */
279 if (instance->irq != SCSI_IRQ_NONE) 279 if (instance->irq != SCSI_IRQ_NONE)
280 if (request_irq(instance->irq, dtc_intr, IRQF_DISABLED, "dtc", instance)) { 280 if (request_irq(instance->irq, dtc_intr, IRQF_DISABLED,
281 "dtc", instance)) {
281 printk(KERN_ERR "scsi%d : IRQ%d not free, interrupts disabled\n", instance->host_no, instance->irq); 282 printk(KERN_ERR "scsi%d : IRQ%d not free, interrupts disabled\n", instance->host_no, instance->irq);
282 instance->irq = SCSI_IRQ_NONE; 283 instance->irq = SCSI_IRQ_NONE;
283 } 284 }
@@ -459,7 +460,7 @@ static int dtc_release(struct Scsi_Host *shost)
459 NCR5380_local_declare(); 460 NCR5380_local_declare();
460 NCR5380_setup(shost); 461 NCR5380_setup(shost);
461 if (shost->irq) 462 if (shost->irq)
462 free_irq(shost->irq, NULL); 463 free_irq(shost->irq, shost);
463 NCR5380_exit(shost); 464 NCR5380_exit(shost);
464 if (shost->io_port && shost->n_io_port) 465 if (shost->io_port && shost->n_io_port)
465 release_region(shost->io_port, shost->n_io_port); 466 release_region(shost->io_port, shost->n_io_port);
diff --git a/drivers/scsi/esp_scsi.c b/drivers/scsi/esp_scsi.c
index 4ed3a5297066..bfdee5968892 100644
--- a/drivers/scsi/esp_scsi.c
+++ b/drivers/scsi/esp_scsi.c
@@ -2026,8 +2026,8 @@ static void esp_reset_cleanup(struct esp *esp)
2026 tp->flags |= ESP_TGT_CHECK_NEGO; 2026 tp->flags |= ESP_TGT_CHECK_NEGO;
2027 2027
2028 if (tp->starget) 2028 if (tp->starget)
2029 starget_for_each_device(tp->starget, NULL, 2029 __starget_for_each_device(tp->starget, NULL,
2030 esp_clear_hold); 2030 esp_clear_hold);
2031 } 2031 }
2032 esp->flags &= ~ESP_FLAG_RESETTING; 2032 esp->flags &= ~ESP_FLAG_RESETTING;
2033} 2033}
diff --git a/drivers/scsi/g_NCR5380.c b/drivers/scsi/g_NCR5380.c
index 607336f56d55..75585a52c88b 100644
--- a/drivers/scsi/g_NCR5380.c
+++ b/drivers/scsi/g_NCR5380.c
@@ -460,7 +460,8 @@ int __init generic_NCR5380_detect(struct scsi_host_template * tpnt)
460 instance->irq = NCR5380_probe_irq(instance, 0xffff); 460 instance->irq = NCR5380_probe_irq(instance, 0xffff);
461 461
462 if (instance->irq != SCSI_IRQ_NONE) 462 if (instance->irq != SCSI_IRQ_NONE)
463 if (request_irq(instance->irq, generic_NCR5380_intr, IRQF_DISABLED, "NCR5380", instance)) { 463 if (request_irq(instance->irq, generic_NCR5380_intr,
464 IRQF_DISABLED, "NCR5380", instance)) {
464 printk(KERN_WARNING "scsi%d : IRQ%d not free, interrupts disabled\n", instance->host_no, instance->irq); 465 printk(KERN_WARNING "scsi%d : IRQ%d not free, interrupts disabled\n", instance->host_no, instance->irq);
465 instance->irq = SCSI_IRQ_NONE; 466 instance->irq = SCSI_IRQ_NONE;
466 } 467 }
@@ -513,7 +514,7 @@ int generic_NCR5380_release_resources(struct Scsi_Host *instance)
513 NCR5380_setup(instance); 514 NCR5380_setup(instance);
514 515
515 if (instance->irq != SCSI_IRQ_NONE) 516 if (instance->irq != SCSI_IRQ_NONE)
516 free_irq(instance->irq, NULL); 517 free_irq(instance->irq, instance);
517 NCR5380_exit(instance); 518 NCR5380_exit(instance);
518 519
519#ifndef CONFIG_SCSI_G_NCR5380_MEM 520#ifndef CONFIG_SCSI_G_NCR5380_MEM
diff --git a/drivers/scsi/ide-scsi.c b/drivers/scsi/ide-scsi.c
index 8d0244c2e7d4..9706de9d98d5 100644
--- a/drivers/scsi/ide-scsi.c
+++ b/drivers/scsi/ide-scsi.c
@@ -242,14 +242,9 @@ static void idescsi_output_buffers (ide_drive_t *drive, idescsi_pc_t *pc, unsign
242 } 242 }
243} 243}
244 244
245static void hexdump(u8 *x, int len) 245static void ide_scsi_hex_dump(u8 *data, int len)
246{ 246{
247 int i; 247 print_hex_dump(KERN_CONT, "", DUMP_PREFIX_NONE, 16, 1, data, len, 0);
248
249 printk("[ ");
250 for (i = 0; i < len; i++)
251 printk("%x ", x[i]);
252 printk("]\n");
253} 248}
254 249
255static int idescsi_check_condition(ide_drive_t *drive, struct request *failed_command) 250static int idescsi_check_condition(ide_drive_t *drive, struct request *failed_command)
@@ -282,7 +277,7 @@ static int idescsi_check_condition(ide_drive_t *drive, struct request *failed_co
282 pc->scsi_cmd = ((idescsi_pc_t *) failed_command->special)->scsi_cmd; 277 pc->scsi_cmd = ((idescsi_pc_t *) failed_command->special)->scsi_cmd;
283 if (test_bit(IDESCSI_LOG_CMD, &scsi->log)) { 278 if (test_bit(IDESCSI_LOG_CMD, &scsi->log)) {
284 printk ("ide-scsi: %s: queue cmd = ", drive->name); 279 printk ("ide-scsi: %s: queue cmd = ", drive->name);
285 hexdump(pc->c, 6); 280 ide_scsi_hex_dump(pc->c, 6);
286 } 281 }
287 rq->rq_disk = scsi->disk; 282 rq->rq_disk = scsi->disk;
288 return ide_do_drive_cmd(drive, rq, ide_preempt); 283 return ide_do_drive_cmd(drive, rq, ide_preempt);
@@ -337,7 +332,7 @@ static int idescsi_end_request (ide_drive_t *drive, int uptodate, int nrsecs)
337 idescsi_pc_t *opc = (idescsi_pc_t *) rq->buffer; 332 idescsi_pc_t *opc = (idescsi_pc_t *) rq->buffer;
338 if (log) { 333 if (log) {
339 printk ("ide-scsi: %s: wrap up check %lu, rst = ", drive->name, opc->scsi_cmd->serial_number); 334 printk ("ide-scsi: %s: wrap up check %lu, rst = ", drive->name, opc->scsi_cmd->serial_number);
340 hexdump(pc->buffer,16); 335 ide_scsi_hex_dump(pc->buffer, 16);
341 } 336 }
342 memcpy((void *) opc->scsi_cmd->sense_buffer, pc->buffer, SCSI_SENSE_BUFFERSIZE); 337 memcpy((void *) opc->scsi_cmd->sense_buffer, pc->buffer, SCSI_SENSE_BUFFERSIZE);
343 kfree(pc->buffer); 338 kfree(pc->buffer);
@@ -816,10 +811,10 @@ static int idescsi_queue (struct scsi_cmnd *cmd,
816 811
817 if (test_bit(IDESCSI_LOG_CMD, &scsi->log)) { 812 if (test_bit(IDESCSI_LOG_CMD, &scsi->log)) {
818 printk ("ide-scsi: %s: que %lu, cmd = ", drive->name, cmd->serial_number); 813 printk ("ide-scsi: %s: que %lu, cmd = ", drive->name, cmd->serial_number);
819 hexdump(cmd->cmnd, cmd->cmd_len); 814 ide_scsi_hex_dump(cmd->cmnd, cmd->cmd_len);
820 if (memcmp(pc->c, cmd->cmnd, cmd->cmd_len)) { 815 if (memcmp(pc->c, cmd->cmnd, cmd->cmd_len)) {
821 printk ("ide-scsi: %s: que %lu, tsl = ", drive->name, cmd->serial_number); 816 printk ("ide-scsi: %s: que %lu, tsl = ", drive->name, cmd->serial_number);
822 hexdump(pc->c, 12); 817 ide_scsi_hex_dump(pc->c, 12);
823 } 818 }
824 } 819 }
825 820
diff --git a/drivers/scsi/initio.c b/drivers/scsi/initio.c
index 4c4465d39a1d..01bf0189367d 100644
--- a/drivers/scsi/initio.c
+++ b/drivers/scsi/initio.c
@@ -2616,6 +2616,7 @@ static void initio_build_scb(struct initio_host * host, struct scsi_ctrl_blk * c
2616 scsi_for_each_sg(cmnd, sglist, cblk->sglen, i) { 2616 scsi_for_each_sg(cmnd, sglist, cblk->sglen, i) {
2617 sg->data = cpu_to_le32((u32)sg_dma_address(sglist)); 2617 sg->data = cpu_to_le32((u32)sg_dma_address(sglist));
2618 total_len += sg->len = cpu_to_le32((u32)sg_dma_len(sglist)); 2618 total_len += sg->len = cpu_to_le32((u32)sg_dma_len(sglist));
2619 ++sg;
2619 } 2620 }
2620 2621
2621 cblk->buflen = (scsi_bufflen(cmnd) > total_len) ? 2622 cblk->buflen = (scsi_bufflen(cmnd) > total_len) ?
@@ -2867,6 +2868,7 @@ static int initio_probe_one(struct pci_dev *pdev,
2867 } 2868 }
2868 host = (struct initio_host *)shost->hostdata; 2869 host = (struct initio_host *)shost->hostdata;
2869 memset(host, 0, sizeof(struct initio_host)); 2870 memset(host, 0, sizeof(struct initio_host));
2871 host->addr = pci_resource_start(pdev, 0);
2870 2872
2871 if (!request_region(host->addr, 256, "i91u")) { 2873 if (!request_region(host->addr, 256, "i91u")) {
2872 printk(KERN_WARNING "initio: I/O port range 0x%x is busy.\n", host->addr); 2874 printk(KERN_WARNING "initio: I/O port range 0x%x is busy.\n", host->addr);
diff --git a/drivers/scsi/iscsi_tcp.c b/drivers/scsi/iscsi_tcp.c
index 4bcf916c21a7..57ce2251abc8 100644
--- a/drivers/scsi/iscsi_tcp.c
+++ b/drivers/scsi/iscsi_tcp.c
@@ -197,7 +197,7 @@ iscsi_tcp_cleanup_ctask(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask)
197 if (unlikely(!sc)) 197 if (unlikely(!sc))
198 return; 198 return;
199 199
200 tcp_ctask->xmstate = XMSTATE_IDLE; 200 tcp_ctask->xmstate = XMSTATE_VALUE_IDLE;
201 tcp_ctask->r2t = NULL; 201 tcp_ctask->r2t = NULL;
202} 202}
203 203
@@ -409,7 +409,7 @@ iscsi_r2t_rsp(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask)
409 409
410 tcp_ctask->exp_datasn = r2tsn + 1; 410 tcp_ctask->exp_datasn = r2tsn + 1;
411 __kfifo_put(tcp_ctask->r2tqueue, (void*)&r2t, sizeof(void*)); 411 __kfifo_put(tcp_ctask->r2tqueue, (void*)&r2t, sizeof(void*));
412 tcp_ctask->xmstate |= XMSTATE_SOL_HDR_INIT; 412 set_bit(XMSTATE_BIT_SOL_HDR_INIT, &tcp_ctask->xmstate);
413 list_move_tail(&ctask->running, &conn->xmitqueue); 413 list_move_tail(&ctask->running, &conn->xmitqueue);
414 414
415 scsi_queue_work(session->host, &conn->xmitwork); 415 scsi_queue_work(session->host, &conn->xmitwork);
@@ -1254,7 +1254,7 @@ static void iscsi_set_padding(struct iscsi_tcp_cmd_task *tcp_ctask,
1254 1254
1255 tcp_ctask->pad_count = ISCSI_PAD_LEN - tcp_ctask->pad_count; 1255 tcp_ctask->pad_count = ISCSI_PAD_LEN - tcp_ctask->pad_count;
1256 debug_scsi("write padding %d bytes\n", tcp_ctask->pad_count); 1256 debug_scsi("write padding %d bytes\n", tcp_ctask->pad_count);
1257 tcp_ctask->xmstate |= XMSTATE_W_PAD; 1257 set_bit(XMSTATE_BIT_W_PAD, &tcp_ctask->xmstate);
1258} 1258}
1259 1259
1260/** 1260/**
@@ -1269,7 +1269,7 @@ iscsi_tcp_cmd_init(struct iscsi_cmd_task *ctask)
1269 struct iscsi_tcp_cmd_task *tcp_ctask = ctask->dd_data; 1269 struct iscsi_tcp_cmd_task *tcp_ctask = ctask->dd_data;
1270 1270
1271 BUG_ON(__kfifo_len(tcp_ctask->r2tqueue)); 1271 BUG_ON(__kfifo_len(tcp_ctask->r2tqueue));
1272 tcp_ctask->xmstate = XMSTATE_CMD_HDR_INIT; 1272 tcp_ctask->xmstate = 1 << XMSTATE_BIT_CMD_HDR_INIT;
1273} 1273}
1274 1274
1275/** 1275/**
@@ -1283,10 +1283,10 @@ iscsi_tcp_cmd_init(struct iscsi_cmd_task *ctask)
1283 * xmit. 1283 * xmit.
1284 * 1284 *
1285 * Management xmit state machine consists of these states: 1285 * Management xmit state machine consists of these states:
1286 * XMSTATE_IMM_HDR_INIT - calculate digest of PDU Header 1286 * XMSTATE_BIT_IMM_HDR_INIT - calculate digest of PDU Header
1287 * XMSTATE_IMM_HDR - PDU Header xmit in progress 1287 * XMSTATE_BIT_IMM_HDR - PDU Header xmit in progress
1288 * XMSTATE_IMM_DATA - PDU Data xmit in progress 1288 * XMSTATE_BIT_IMM_DATA - PDU Data xmit in progress
1289 * XMSTATE_IDLE - management PDU is done 1289 * XMSTATE_VALUE_IDLE - management PDU is done
1290 **/ 1290 **/
1291static int 1291static int
1292iscsi_tcp_mtask_xmit(struct iscsi_conn *conn, struct iscsi_mgmt_task *mtask) 1292iscsi_tcp_mtask_xmit(struct iscsi_conn *conn, struct iscsi_mgmt_task *mtask)
@@ -1297,12 +1297,12 @@ iscsi_tcp_mtask_xmit(struct iscsi_conn *conn, struct iscsi_mgmt_task *mtask)
1297 debug_scsi("mtask deq [cid %d state %x itt 0x%x]\n", 1297 debug_scsi("mtask deq [cid %d state %x itt 0x%x]\n",
1298 conn->id, tcp_mtask->xmstate, mtask->itt); 1298 conn->id, tcp_mtask->xmstate, mtask->itt);
1299 1299
1300 if (tcp_mtask->xmstate & XMSTATE_IMM_HDR_INIT) { 1300 if (test_bit(XMSTATE_BIT_IMM_HDR_INIT, &tcp_mtask->xmstate)) {
1301 iscsi_buf_init_iov(&tcp_mtask->headbuf, (char*)mtask->hdr, 1301 iscsi_buf_init_iov(&tcp_mtask->headbuf, (char*)mtask->hdr,
1302 sizeof(struct iscsi_hdr)); 1302 sizeof(struct iscsi_hdr));
1303 1303
1304 if (mtask->data_count) { 1304 if (mtask->data_count) {
1305 tcp_mtask->xmstate |= XMSTATE_IMM_DATA; 1305 set_bit(XMSTATE_BIT_IMM_DATA, &tcp_mtask->xmstate);
1306 iscsi_buf_init_iov(&tcp_mtask->sendbuf, 1306 iscsi_buf_init_iov(&tcp_mtask->sendbuf,
1307 (char*)mtask->data, 1307 (char*)mtask->data,
1308 mtask->data_count); 1308 mtask->data_count);
@@ -1315,21 +1315,20 @@ iscsi_tcp_mtask_xmit(struct iscsi_conn *conn, struct iscsi_mgmt_task *mtask)
1315 (u8*)tcp_mtask->hdrext); 1315 (u8*)tcp_mtask->hdrext);
1316 1316
1317 tcp_mtask->sent = 0; 1317 tcp_mtask->sent = 0;
1318 tcp_mtask->xmstate &= ~XMSTATE_IMM_HDR_INIT; 1318 clear_bit(XMSTATE_BIT_IMM_HDR_INIT, &tcp_mtask->xmstate);
1319 tcp_mtask->xmstate |= XMSTATE_IMM_HDR; 1319 set_bit(XMSTATE_BIT_IMM_HDR, &tcp_mtask->xmstate);
1320 } 1320 }
1321 1321
1322 if (tcp_mtask->xmstate & XMSTATE_IMM_HDR) { 1322 if (test_bit(XMSTATE_BIT_IMM_HDR, &tcp_mtask->xmstate)) {
1323 rc = iscsi_sendhdr(conn, &tcp_mtask->headbuf, 1323 rc = iscsi_sendhdr(conn, &tcp_mtask->headbuf,
1324 mtask->data_count); 1324 mtask->data_count);
1325 if (rc) 1325 if (rc)
1326 return rc; 1326 return rc;
1327 tcp_mtask->xmstate &= ~XMSTATE_IMM_HDR; 1327 clear_bit(XMSTATE_BIT_IMM_HDR, &tcp_mtask->xmstate);
1328 } 1328 }
1329 1329
1330 if (tcp_mtask->xmstate & XMSTATE_IMM_DATA) { 1330 if (test_and_clear_bit(XMSTATE_BIT_IMM_DATA, &tcp_mtask->xmstate)) {
1331 BUG_ON(!mtask->data_count); 1331 BUG_ON(!mtask->data_count);
1332 tcp_mtask->xmstate &= ~XMSTATE_IMM_DATA;
1333 /* FIXME: implement. 1332 /* FIXME: implement.
1334 * Virtual buffer could be spreaded across multiple pages... 1333 * Virtual buffer could be spreaded across multiple pages...
1335 */ 1334 */
@@ -1339,13 +1338,13 @@ iscsi_tcp_mtask_xmit(struct iscsi_conn *conn, struct iscsi_mgmt_task *mtask)
1339 rc = iscsi_sendpage(conn, &tcp_mtask->sendbuf, 1338 rc = iscsi_sendpage(conn, &tcp_mtask->sendbuf,
1340 &mtask->data_count, &tcp_mtask->sent); 1339 &mtask->data_count, &tcp_mtask->sent);
1341 if (rc) { 1340 if (rc) {
1342 tcp_mtask->xmstate |= XMSTATE_IMM_DATA; 1341 set_bit(XMSTATE_BIT_IMM_DATA, &tcp_mtask->xmstate);
1343 return rc; 1342 return rc;
1344 } 1343 }
1345 } while (mtask->data_count); 1344 } while (mtask->data_count);
1346 } 1345 }
1347 1346
1348 BUG_ON(tcp_mtask->xmstate != XMSTATE_IDLE); 1347 BUG_ON(tcp_mtask->xmstate != XMSTATE_VALUE_IDLE);
1349 if (mtask->hdr->itt == RESERVED_ITT) { 1348 if (mtask->hdr->itt == RESERVED_ITT) {
1350 struct iscsi_session *session = conn->session; 1349 struct iscsi_session *session = conn->session;
1351 1350
@@ -1365,7 +1364,7 @@ iscsi_send_cmd_hdr(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask)
1365 struct iscsi_tcp_cmd_task *tcp_ctask = ctask->dd_data; 1364 struct iscsi_tcp_cmd_task *tcp_ctask = ctask->dd_data;
1366 int rc = 0; 1365 int rc = 0;
1367 1366
1368 if (tcp_ctask->xmstate & XMSTATE_CMD_HDR_INIT) { 1367 if (test_bit(XMSTATE_BIT_CMD_HDR_INIT, &tcp_ctask->xmstate)) {
1369 tcp_ctask->sent = 0; 1368 tcp_ctask->sent = 0;
1370 tcp_ctask->sg_count = 0; 1369 tcp_ctask->sg_count = 0;
1371 tcp_ctask->exp_datasn = 0; 1370 tcp_ctask->exp_datasn = 0;
@@ -1390,21 +1389,21 @@ iscsi_send_cmd_hdr(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask)
1390 if (conn->hdrdgst_en) 1389 if (conn->hdrdgst_en)
1391 iscsi_hdr_digest(conn, &tcp_ctask->headbuf, 1390 iscsi_hdr_digest(conn, &tcp_ctask->headbuf,
1392 (u8*)tcp_ctask->hdrext); 1391 (u8*)tcp_ctask->hdrext);
1393 tcp_ctask->xmstate &= ~XMSTATE_CMD_HDR_INIT; 1392 clear_bit(XMSTATE_BIT_CMD_HDR_INIT, &tcp_ctask->xmstate);
1394 tcp_ctask->xmstate |= XMSTATE_CMD_HDR_XMIT; 1393 set_bit(XMSTATE_BIT_CMD_HDR_XMIT, &tcp_ctask->xmstate);
1395 } 1394 }
1396 1395
1397 if (tcp_ctask->xmstate & XMSTATE_CMD_HDR_XMIT) { 1396 if (test_bit(XMSTATE_BIT_CMD_HDR_XMIT, &tcp_ctask->xmstate)) {
1398 rc = iscsi_sendhdr(conn, &tcp_ctask->headbuf, ctask->imm_count); 1397 rc = iscsi_sendhdr(conn, &tcp_ctask->headbuf, ctask->imm_count);
1399 if (rc) 1398 if (rc)
1400 return rc; 1399 return rc;
1401 tcp_ctask->xmstate &= ~XMSTATE_CMD_HDR_XMIT; 1400 clear_bit(XMSTATE_BIT_CMD_HDR_XMIT, &tcp_ctask->xmstate);
1402 1401
1403 if (sc->sc_data_direction != DMA_TO_DEVICE) 1402 if (sc->sc_data_direction != DMA_TO_DEVICE)
1404 return 0; 1403 return 0;
1405 1404
1406 if (ctask->imm_count) { 1405 if (ctask->imm_count) {
1407 tcp_ctask->xmstate |= XMSTATE_IMM_DATA; 1406 set_bit(XMSTATE_BIT_IMM_DATA, &tcp_ctask->xmstate);
1408 iscsi_set_padding(tcp_ctask, ctask->imm_count); 1407 iscsi_set_padding(tcp_ctask, ctask->imm_count);
1409 1408
1410 if (ctask->conn->datadgst_en) { 1409 if (ctask->conn->datadgst_en) {
@@ -1414,9 +1413,10 @@ iscsi_send_cmd_hdr(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask)
1414 } 1413 }
1415 } 1414 }
1416 1415
1417 if (ctask->unsol_count) 1416 if (ctask->unsol_count) {
1418 tcp_ctask->xmstate |= 1417 set_bit(XMSTATE_BIT_UNS_HDR, &tcp_ctask->xmstate);
1419 XMSTATE_UNS_HDR | XMSTATE_UNS_INIT; 1418 set_bit(XMSTATE_BIT_UNS_INIT, &tcp_ctask->xmstate);
1419 }
1420 } 1420 }
1421 return rc; 1421 return rc;
1422} 1422}
@@ -1428,25 +1428,25 @@ iscsi_send_padding(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask)
1428 struct iscsi_tcp_conn *tcp_conn = conn->dd_data; 1428 struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
1429 int sent = 0, rc; 1429 int sent = 0, rc;
1430 1430
1431 if (tcp_ctask->xmstate & XMSTATE_W_PAD) { 1431 if (test_bit(XMSTATE_BIT_W_PAD, &tcp_ctask->xmstate)) {
1432 iscsi_buf_init_iov(&tcp_ctask->sendbuf, (char*)&tcp_ctask->pad, 1432 iscsi_buf_init_iov(&tcp_ctask->sendbuf, (char*)&tcp_ctask->pad,
1433 tcp_ctask->pad_count); 1433 tcp_ctask->pad_count);
1434 if (conn->datadgst_en) 1434 if (conn->datadgst_en)
1435 crypto_hash_update(&tcp_conn->tx_hash, 1435 crypto_hash_update(&tcp_conn->tx_hash,
1436 &tcp_ctask->sendbuf.sg, 1436 &tcp_ctask->sendbuf.sg,
1437 tcp_ctask->sendbuf.sg.length); 1437 tcp_ctask->sendbuf.sg.length);
1438 } else if (!(tcp_ctask->xmstate & XMSTATE_W_RESEND_PAD)) 1438 } else if (!test_bit(XMSTATE_BIT_W_RESEND_PAD, &tcp_ctask->xmstate))
1439 return 0; 1439 return 0;
1440 1440
1441 tcp_ctask->xmstate &= ~XMSTATE_W_PAD; 1441 clear_bit(XMSTATE_BIT_W_PAD, &tcp_ctask->xmstate);
1442 tcp_ctask->xmstate &= ~XMSTATE_W_RESEND_PAD; 1442 clear_bit(XMSTATE_BIT_W_RESEND_PAD, &tcp_ctask->xmstate);
1443 debug_scsi("sending %d pad bytes for itt 0x%x\n", 1443 debug_scsi("sending %d pad bytes for itt 0x%x\n",
1444 tcp_ctask->pad_count, ctask->itt); 1444 tcp_ctask->pad_count, ctask->itt);
1445 rc = iscsi_sendpage(conn, &tcp_ctask->sendbuf, &tcp_ctask->pad_count, 1445 rc = iscsi_sendpage(conn, &tcp_ctask->sendbuf, &tcp_ctask->pad_count,
1446 &sent); 1446 &sent);
1447 if (rc) { 1447 if (rc) {
1448 debug_scsi("padding send failed %d\n", rc); 1448 debug_scsi("padding send failed %d\n", rc);
1449 tcp_ctask->xmstate |= XMSTATE_W_RESEND_PAD; 1449 set_bit(XMSTATE_BIT_W_RESEND_PAD, &tcp_ctask->xmstate);
1450 } 1450 }
1451 return rc; 1451 return rc;
1452} 1452}
@@ -1465,11 +1465,11 @@ iscsi_send_digest(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask,
1465 tcp_ctask = ctask->dd_data; 1465 tcp_ctask = ctask->dd_data;
1466 tcp_conn = conn->dd_data; 1466 tcp_conn = conn->dd_data;
1467 1467
1468 if (!(tcp_ctask->xmstate & XMSTATE_W_RESEND_DATA_DIGEST)) { 1468 if (!test_bit(XMSTATE_BIT_W_RESEND_DATA_DIGEST, &tcp_ctask->xmstate)) {
1469 crypto_hash_final(&tcp_conn->tx_hash, (u8*)digest); 1469 crypto_hash_final(&tcp_conn->tx_hash, (u8*)digest);
1470 iscsi_buf_init_iov(buf, (char*)digest, 4); 1470 iscsi_buf_init_iov(buf, (char*)digest, 4);
1471 } 1471 }
1472 tcp_ctask->xmstate &= ~XMSTATE_W_RESEND_DATA_DIGEST; 1472 clear_bit(XMSTATE_BIT_W_RESEND_DATA_DIGEST, &tcp_ctask->xmstate);
1473 1473
1474 rc = iscsi_sendpage(conn, buf, &tcp_ctask->digest_count, &sent); 1474 rc = iscsi_sendpage(conn, buf, &tcp_ctask->digest_count, &sent);
1475 if (!rc) 1475 if (!rc)
@@ -1478,7 +1478,7 @@ iscsi_send_digest(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask,
1478 else { 1478 else {
1479 debug_scsi("sending digest 0x%x failed for itt 0x%x!\n", 1479 debug_scsi("sending digest 0x%x failed for itt 0x%x!\n",
1480 *digest, ctask->itt); 1480 *digest, ctask->itt);
1481 tcp_ctask->xmstate |= XMSTATE_W_RESEND_DATA_DIGEST; 1481 set_bit(XMSTATE_BIT_W_RESEND_DATA_DIGEST, &tcp_ctask->xmstate);
1482 } 1482 }
1483 return rc; 1483 return rc;
1484} 1484}
@@ -1526,8 +1526,8 @@ iscsi_send_unsol_hdr(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask)
1526 struct iscsi_data_task *dtask; 1526 struct iscsi_data_task *dtask;
1527 int rc; 1527 int rc;
1528 1528
1529 tcp_ctask->xmstate |= XMSTATE_UNS_DATA; 1529 set_bit(XMSTATE_BIT_UNS_DATA, &tcp_ctask->xmstate);
1530 if (tcp_ctask->xmstate & XMSTATE_UNS_INIT) { 1530 if (test_bit(XMSTATE_BIT_UNS_INIT, &tcp_ctask->xmstate)) {
1531 dtask = &tcp_ctask->unsol_dtask; 1531 dtask = &tcp_ctask->unsol_dtask;
1532 1532
1533 iscsi_prep_unsolicit_data_pdu(ctask, &dtask->hdr); 1533 iscsi_prep_unsolicit_data_pdu(ctask, &dtask->hdr);
@@ -1537,14 +1537,14 @@ iscsi_send_unsol_hdr(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask)
1537 iscsi_hdr_digest(conn, &tcp_ctask->headbuf, 1537 iscsi_hdr_digest(conn, &tcp_ctask->headbuf,
1538 (u8*)dtask->hdrext); 1538 (u8*)dtask->hdrext);
1539 1539
1540 tcp_ctask->xmstate &= ~XMSTATE_UNS_INIT; 1540 clear_bit(XMSTATE_BIT_UNS_INIT, &tcp_ctask->xmstate);
1541 iscsi_set_padding(tcp_ctask, ctask->data_count); 1541 iscsi_set_padding(tcp_ctask, ctask->data_count);
1542 } 1542 }
1543 1543
1544 rc = iscsi_sendhdr(conn, &tcp_ctask->headbuf, ctask->data_count); 1544 rc = iscsi_sendhdr(conn, &tcp_ctask->headbuf, ctask->data_count);
1545 if (rc) { 1545 if (rc) {
1546 tcp_ctask->xmstate &= ~XMSTATE_UNS_DATA; 1546 clear_bit(XMSTATE_BIT_UNS_DATA, &tcp_ctask->xmstate);
1547 tcp_ctask->xmstate |= XMSTATE_UNS_HDR; 1547 set_bit(XMSTATE_BIT_UNS_HDR, &tcp_ctask->xmstate);
1548 return rc; 1548 return rc;
1549 } 1549 }
1550 1550
@@ -1565,16 +1565,15 @@ iscsi_send_unsol_pdu(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask)
1565 struct iscsi_tcp_cmd_task *tcp_ctask = ctask->dd_data; 1565 struct iscsi_tcp_cmd_task *tcp_ctask = ctask->dd_data;
1566 int rc; 1566 int rc;
1567 1567
1568 if (tcp_ctask->xmstate & XMSTATE_UNS_HDR) { 1568 if (test_and_clear_bit(XMSTATE_BIT_UNS_HDR, &tcp_ctask->xmstate)) {
1569 BUG_ON(!ctask->unsol_count); 1569 BUG_ON(!ctask->unsol_count);
1570 tcp_ctask->xmstate &= ~XMSTATE_UNS_HDR;
1571send_hdr: 1570send_hdr:
1572 rc = iscsi_send_unsol_hdr(conn, ctask); 1571 rc = iscsi_send_unsol_hdr(conn, ctask);
1573 if (rc) 1572 if (rc)
1574 return rc; 1573 return rc;
1575 } 1574 }
1576 1575
1577 if (tcp_ctask->xmstate & XMSTATE_UNS_DATA) { 1576 if (test_bit(XMSTATE_BIT_UNS_DATA, &tcp_ctask->xmstate)) {
1578 struct iscsi_data_task *dtask = &tcp_ctask->unsol_dtask; 1577 struct iscsi_data_task *dtask = &tcp_ctask->unsol_dtask;
1579 int start = tcp_ctask->sent; 1578 int start = tcp_ctask->sent;
1580 1579
@@ -1584,14 +1583,14 @@ send_hdr:
1584 ctask->unsol_count -= tcp_ctask->sent - start; 1583 ctask->unsol_count -= tcp_ctask->sent - start;
1585 if (rc) 1584 if (rc)
1586 return rc; 1585 return rc;
1587 tcp_ctask->xmstate &= ~XMSTATE_UNS_DATA; 1586 clear_bit(XMSTATE_BIT_UNS_DATA, &tcp_ctask->xmstate);
1588 /* 1587 /*
1589 * Done with the Data-Out. Next, check if we need 1588 * Done with the Data-Out. Next, check if we need
1590 * to send another unsolicited Data-Out. 1589 * to send another unsolicited Data-Out.
1591 */ 1590 */
1592 if (ctask->unsol_count) { 1591 if (ctask->unsol_count) {
1593 debug_scsi("sending more uns\n"); 1592 debug_scsi("sending more uns\n");
1594 tcp_ctask->xmstate |= XMSTATE_UNS_INIT; 1593 set_bit(XMSTATE_BIT_UNS_INIT, &tcp_ctask->xmstate);
1595 goto send_hdr; 1594 goto send_hdr;
1596 } 1595 }
1597 } 1596 }
@@ -1607,7 +1606,7 @@ static int iscsi_send_sol_pdu(struct iscsi_conn *conn,
1607 struct iscsi_data_task *dtask; 1606 struct iscsi_data_task *dtask;
1608 int left, rc; 1607 int left, rc;
1609 1608
1610 if (tcp_ctask->xmstate & XMSTATE_SOL_HDR_INIT) { 1609 if (test_bit(XMSTATE_BIT_SOL_HDR_INIT, &tcp_ctask->xmstate)) {
1611 if (!tcp_ctask->r2t) { 1610 if (!tcp_ctask->r2t) {
1612 spin_lock_bh(&session->lock); 1611 spin_lock_bh(&session->lock);
1613 __kfifo_get(tcp_ctask->r2tqueue, (void*)&tcp_ctask->r2t, 1612 __kfifo_get(tcp_ctask->r2tqueue, (void*)&tcp_ctask->r2t,
@@ -1621,19 +1620,19 @@ send_hdr:
1621 if (conn->hdrdgst_en) 1620 if (conn->hdrdgst_en)
1622 iscsi_hdr_digest(conn, &r2t->headbuf, 1621 iscsi_hdr_digest(conn, &r2t->headbuf,
1623 (u8*)dtask->hdrext); 1622 (u8*)dtask->hdrext);
1624 tcp_ctask->xmstate &= ~XMSTATE_SOL_HDR_INIT; 1623 clear_bit(XMSTATE_BIT_SOL_HDR_INIT, &tcp_ctask->xmstate);
1625 tcp_ctask->xmstate |= XMSTATE_SOL_HDR; 1624 set_bit(XMSTATE_BIT_SOL_HDR, &tcp_ctask->xmstate);
1626 } 1625 }
1627 1626
1628 if (tcp_ctask->xmstate & XMSTATE_SOL_HDR) { 1627 if (test_bit(XMSTATE_BIT_SOL_HDR, &tcp_ctask->xmstate)) {
1629 r2t = tcp_ctask->r2t; 1628 r2t = tcp_ctask->r2t;
1630 dtask = &r2t->dtask; 1629 dtask = &r2t->dtask;
1631 1630
1632 rc = iscsi_sendhdr(conn, &r2t->headbuf, r2t->data_count); 1631 rc = iscsi_sendhdr(conn, &r2t->headbuf, r2t->data_count);
1633 if (rc) 1632 if (rc)
1634 return rc; 1633 return rc;
1635 tcp_ctask->xmstate &= ~XMSTATE_SOL_HDR; 1634 clear_bit(XMSTATE_BIT_SOL_HDR, &tcp_ctask->xmstate);
1636 tcp_ctask->xmstate |= XMSTATE_SOL_DATA; 1635 set_bit(XMSTATE_BIT_SOL_DATA, &tcp_ctask->xmstate);
1637 1636
1638 if (conn->datadgst_en) { 1637 if (conn->datadgst_en) {
1639 iscsi_data_digest_init(conn->dd_data, tcp_ctask); 1638 iscsi_data_digest_init(conn->dd_data, tcp_ctask);
@@ -1646,7 +1645,7 @@ send_hdr:
1646 r2t->sent); 1645 r2t->sent);
1647 } 1646 }
1648 1647
1649 if (tcp_ctask->xmstate & XMSTATE_SOL_DATA) { 1648 if (test_bit(XMSTATE_BIT_SOL_DATA, &tcp_ctask->xmstate)) {
1650 r2t = tcp_ctask->r2t; 1649 r2t = tcp_ctask->r2t;
1651 dtask = &r2t->dtask; 1650 dtask = &r2t->dtask;
1652 1651
@@ -1655,7 +1654,7 @@ send_hdr:
1655 &dtask->digestbuf, &dtask->digest); 1654 &dtask->digestbuf, &dtask->digest);
1656 if (rc) 1655 if (rc)
1657 return rc; 1656 return rc;
1658 tcp_ctask->xmstate &= ~XMSTATE_SOL_DATA; 1657 clear_bit(XMSTATE_BIT_SOL_DATA, &tcp_ctask->xmstate);
1659 1658
1660 /* 1659 /*
1661 * Done with this Data-Out. Next, check if we have 1660 * Done with this Data-Out. Next, check if we have
@@ -1700,32 +1699,32 @@ send_hdr:
1700 * xmit stages. 1699 * xmit stages.
1701 * 1700 *
1702 *iscsi_send_cmd_hdr() 1701 *iscsi_send_cmd_hdr()
1703 * XMSTATE_CMD_HDR_INIT - prepare Header and Data buffers Calculate 1702 * XMSTATE_BIT_CMD_HDR_INIT - prepare Header and Data buffers Calculate
1704 * Header Digest 1703 * Header Digest
1705 * XMSTATE_CMD_HDR_XMIT - Transmit header in progress 1704 * XMSTATE_BIT_CMD_HDR_XMIT - Transmit header in progress
1706 * 1705 *
1707 *iscsi_send_padding 1706 *iscsi_send_padding
1708 * XMSTATE_W_PAD - Prepare and send pading 1707 * XMSTATE_BIT_W_PAD - Prepare and send pading
1709 * XMSTATE_W_RESEND_PAD - retry send pading 1708 * XMSTATE_BIT_W_RESEND_PAD - retry send pading
1710 * 1709 *
1711 *iscsi_send_digest 1710 *iscsi_send_digest
1712 * XMSTATE_W_RESEND_DATA_DIGEST - Finalize and send Data Digest 1711 * XMSTATE_BIT_W_RESEND_DATA_DIGEST - Finalize and send Data Digest
1713 * XMSTATE_W_RESEND_DATA_DIGEST - retry sending digest 1712 * XMSTATE_BIT_W_RESEND_DATA_DIGEST - retry sending digest
1714 * 1713 *
1715 *iscsi_send_unsol_hdr 1714 *iscsi_send_unsol_hdr
1716 * XMSTATE_UNS_INIT - prepare un-solicit data header and digest 1715 * XMSTATE_BIT_UNS_INIT - prepare un-solicit data header and digest
1717 * XMSTATE_UNS_HDR - send un-solicit header 1716 * XMSTATE_BIT_UNS_HDR - send un-solicit header
1718 * 1717 *
1719 *iscsi_send_unsol_pdu 1718 *iscsi_send_unsol_pdu
1720 * XMSTATE_UNS_DATA - send un-solicit data in progress 1719 * XMSTATE_BIT_UNS_DATA - send un-solicit data in progress
1721 * 1720 *
1722 *iscsi_send_sol_pdu 1721 *iscsi_send_sol_pdu
1723 * XMSTATE_SOL_HDR_INIT - solicit data header and digest initialize 1722 * XMSTATE_BIT_SOL_HDR_INIT - solicit data header and digest initialize
1724 * XMSTATE_SOL_HDR - send solicit header 1723 * XMSTATE_BIT_SOL_HDR - send solicit header
1725 * XMSTATE_SOL_DATA - send solicit data 1724 * XMSTATE_BIT_SOL_DATA - send solicit data
1726 * 1725 *
1727 *iscsi_tcp_ctask_xmit 1726 *iscsi_tcp_ctask_xmit
1728 * XMSTATE_IMM_DATA - xmit managment data (??) 1727 * XMSTATE_BIT_IMM_DATA - xmit managment data (??)
1729 **/ 1728 **/
1730static int 1729static int
1731iscsi_tcp_ctask_xmit(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask) 1730iscsi_tcp_ctask_xmit(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask)
@@ -1742,13 +1741,13 @@ iscsi_tcp_ctask_xmit(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask)
1742 if (ctask->sc->sc_data_direction != DMA_TO_DEVICE) 1741 if (ctask->sc->sc_data_direction != DMA_TO_DEVICE)
1743 return 0; 1742 return 0;
1744 1743
1745 if (tcp_ctask->xmstate & XMSTATE_IMM_DATA) { 1744 if (test_bit(XMSTATE_BIT_IMM_DATA, &tcp_ctask->xmstate)) {
1746 rc = iscsi_send_data(ctask, &tcp_ctask->sendbuf, &tcp_ctask->sg, 1745 rc = iscsi_send_data(ctask, &tcp_ctask->sendbuf, &tcp_ctask->sg,
1747 &tcp_ctask->sent, &ctask->imm_count, 1746 &tcp_ctask->sent, &ctask->imm_count,
1748 &tcp_ctask->immbuf, &tcp_ctask->immdigest); 1747 &tcp_ctask->immbuf, &tcp_ctask->immdigest);
1749 if (rc) 1748 if (rc)
1750 return rc; 1749 return rc;
1751 tcp_ctask->xmstate &= ~XMSTATE_IMM_DATA; 1750 clear_bit(XMSTATE_BIT_IMM_DATA, &tcp_ctask->xmstate);
1752 } 1751 }
1753 1752
1754 rc = iscsi_send_unsol_pdu(conn, ctask); 1753 rc = iscsi_send_unsol_pdu(conn, ctask);
@@ -1981,7 +1980,7 @@ static void
1981iscsi_tcp_mgmt_init(struct iscsi_conn *conn, struct iscsi_mgmt_task *mtask) 1980iscsi_tcp_mgmt_init(struct iscsi_conn *conn, struct iscsi_mgmt_task *mtask)
1982{ 1981{
1983 struct iscsi_tcp_mgmt_task *tcp_mtask = mtask->dd_data; 1982 struct iscsi_tcp_mgmt_task *tcp_mtask = mtask->dd_data;
1984 tcp_mtask->xmstate = XMSTATE_IMM_HDR_INIT; 1983 tcp_mtask->xmstate = 1 << XMSTATE_BIT_IMM_HDR_INIT;
1985} 1984}
1986 1985
1987static int 1986static int
diff --git a/drivers/scsi/iscsi_tcp.h b/drivers/scsi/iscsi_tcp.h
index 7eba44df0a7f..68c36cc8997e 100644
--- a/drivers/scsi/iscsi_tcp.h
+++ b/drivers/scsi/iscsi_tcp.h
@@ -32,21 +32,21 @@
32#define IN_PROGRESS_PAD_RECV 0x4 32#define IN_PROGRESS_PAD_RECV 0x4
33 33
34/* xmit state machine */ 34/* xmit state machine */
35#define XMSTATE_IDLE 0x0 35#define XMSTATE_VALUE_IDLE 0
36#define XMSTATE_CMD_HDR_INIT 0x1 36#define XMSTATE_BIT_CMD_HDR_INIT 0
37#define XMSTATE_CMD_HDR_XMIT 0x2 37#define XMSTATE_BIT_CMD_HDR_XMIT 1
38#define XMSTATE_IMM_HDR 0x4 38#define XMSTATE_BIT_IMM_HDR 2
39#define XMSTATE_IMM_DATA 0x8 39#define XMSTATE_BIT_IMM_DATA 3
40#define XMSTATE_UNS_INIT 0x10 40#define XMSTATE_BIT_UNS_INIT 4
41#define XMSTATE_UNS_HDR 0x20 41#define XMSTATE_BIT_UNS_HDR 5
42#define XMSTATE_UNS_DATA 0x40 42#define XMSTATE_BIT_UNS_DATA 6
43#define XMSTATE_SOL_HDR 0x80 43#define XMSTATE_BIT_SOL_HDR 7
44#define XMSTATE_SOL_DATA 0x100 44#define XMSTATE_BIT_SOL_DATA 8
45#define XMSTATE_W_PAD 0x200 45#define XMSTATE_BIT_W_PAD 9
46#define XMSTATE_W_RESEND_PAD 0x400 46#define XMSTATE_BIT_W_RESEND_PAD 10
47#define XMSTATE_W_RESEND_DATA_DIGEST 0x800 47#define XMSTATE_BIT_W_RESEND_DATA_DIGEST 11
48#define XMSTATE_IMM_HDR_INIT 0x1000 48#define XMSTATE_BIT_IMM_HDR_INIT 12
49#define XMSTATE_SOL_HDR_INIT 0x2000 49#define XMSTATE_BIT_SOL_HDR_INIT 13
50 50
51#define ISCSI_PAD_LEN 4 51#define ISCSI_PAD_LEN 4
52#define ISCSI_SG_TABLESIZE SG_ALL 52#define ISCSI_SG_TABLESIZE SG_ALL
@@ -122,7 +122,7 @@ struct iscsi_data_task {
122struct iscsi_tcp_mgmt_task { 122struct iscsi_tcp_mgmt_task {
123 struct iscsi_hdr hdr; 123 struct iscsi_hdr hdr;
124 char hdrext[sizeof(__u32)]; /* Header-Digest */ 124 char hdrext[sizeof(__u32)]; /* Header-Digest */
125 int xmstate; /* mgmt xmit progress */ 125 unsigned long xmstate; /* mgmt xmit progress */
126 struct iscsi_buf headbuf; /* header buffer */ 126 struct iscsi_buf headbuf; /* header buffer */
127 struct iscsi_buf sendbuf; /* in progress buffer */ 127 struct iscsi_buf sendbuf; /* in progress buffer */
128 int sent; 128 int sent;
@@ -150,7 +150,7 @@ struct iscsi_tcp_cmd_task {
150 int pad_count; /* padded bytes */ 150 int pad_count; /* padded bytes */
151 struct iscsi_buf headbuf; /* header buf (xmit) */ 151 struct iscsi_buf headbuf; /* header buf (xmit) */
152 struct iscsi_buf sendbuf; /* in progress buffer*/ 152 struct iscsi_buf sendbuf; /* in progress buffer*/
153 int xmstate; /* xmit xtate machine */ 153 unsigned long xmstate; /* xmit xtate machine */
154 int sent; 154 int sent;
155 struct scatterlist *sg; /* per-cmd SG list */ 155 struct scatterlist *sg; /* per-cmd SG list */
156 struct scatterlist *bad_sg; /* assert statement */ 156 struct scatterlist *bad_sg; /* assert statement */
diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c
index efceed451b46..8b57af5baaec 100644
--- a/drivers/scsi/libiscsi.c
+++ b/drivers/scsi/libiscsi.c
@@ -291,9 +291,6 @@ invalid_datalen:
291 min_t(uint16_t, senselen, SCSI_SENSE_BUFFERSIZE)); 291 min_t(uint16_t, senselen, SCSI_SENSE_BUFFERSIZE));
292 } 292 }
293 293
294 if (sc->sc_data_direction == DMA_TO_DEVICE)
295 goto out;
296
297 if (rhdr->flags & ISCSI_FLAG_CMD_UNDERFLOW) { 294 if (rhdr->flags & ISCSI_FLAG_CMD_UNDERFLOW) {
298 int res_count = be32_to_cpu(rhdr->residual_count); 295 int res_count = be32_to_cpu(rhdr->residual_count);
299 296
diff --git a/drivers/scsi/mac_scsi.c b/drivers/scsi/mac_scsi.c
index abe2bda6ac37..3b09ab21d701 100644
--- a/drivers/scsi/mac_scsi.c
+++ b/drivers/scsi/mac_scsi.c
@@ -303,7 +303,7 @@ int macscsi_detect(struct scsi_host_template * tpnt)
303 303
304 if (instance->irq != SCSI_IRQ_NONE) 304 if (instance->irq != SCSI_IRQ_NONE)
305 if (request_irq(instance->irq, NCR5380_intr, IRQ_FLG_SLOW, 305 if (request_irq(instance->irq, NCR5380_intr, IRQ_FLG_SLOW,
306 "ncr5380", instance)) { 306 "ncr5380", instance)) {
307 printk(KERN_WARNING "scsi%d: IRQ%d not free, interrupts disabled\n", 307 printk(KERN_WARNING "scsi%d: IRQ%d not free, interrupts disabled\n",
308 instance->host_no, instance->irq); 308 instance->host_no, instance->irq);
309 instance->irq = SCSI_IRQ_NONE; 309 instance->irq = SCSI_IRQ_NONE;
@@ -326,7 +326,7 @@ int macscsi_detect(struct scsi_host_template * tpnt)
326int macscsi_release (struct Scsi_Host *shpnt) 326int macscsi_release (struct Scsi_Host *shpnt)
327{ 327{
328 if (shpnt->irq != SCSI_IRQ_NONE) 328 if (shpnt->irq != SCSI_IRQ_NONE)
329 free_irq (shpnt->irq, NCR5380_intr); 329 free_irq(shpnt->irq, shpnt);
330 NCR5380_exit(shpnt); 330 NCR5380_exit(shpnt);
331 331
332 return 0; 332 return 0;
diff --git a/drivers/scsi/pas16.c b/drivers/scsi/pas16.c
index ee5965659971..f2018b46f494 100644
--- a/drivers/scsi/pas16.c
+++ b/drivers/scsi/pas16.c
@@ -453,7 +453,8 @@ int __init pas16_detect(struct scsi_host_template * tpnt)
453 instance->irq = NCR5380_probe_irq(instance, PAS16_IRQS); 453 instance->irq = NCR5380_probe_irq(instance, PAS16_IRQS);
454 454
455 if (instance->irq != SCSI_IRQ_NONE) 455 if (instance->irq != SCSI_IRQ_NONE)
456 if (request_irq(instance->irq, pas16_intr, IRQF_DISABLED, "pas16", instance)) { 456 if (request_irq(instance->irq, pas16_intr, IRQF_DISABLED,
457 "pas16", instance)) {
457 printk("scsi%d : IRQ%d not free, interrupts disabled\n", 458 printk("scsi%d : IRQ%d not free, interrupts disabled\n",
458 instance->host_no, instance->irq); 459 instance->host_no, instance->irq);
459 instance->irq = SCSI_IRQ_NONE; 460 instance->irq = SCSI_IRQ_NONE;
@@ -604,7 +605,7 @@ static inline int NCR5380_pwrite (struct Scsi_Host *instance, unsigned char *src
604static int pas16_release(struct Scsi_Host *shost) 605static int pas16_release(struct Scsi_Host *shost)
605{ 606{
606 if (shost->irq) 607 if (shost->irq)
607 free_irq(shost->irq, NULL); 608 free_irq(shost->irq, shost);
608 NCR5380_exit(shost); 609 NCR5380_exit(shost);
609 if (shost->dma_channel != 0xff) 610 if (shost->dma_channel != 0xff)
610 free_dma(shost->dma_channel); 611 free_dma(shost->dma_channel);
diff --git a/drivers/scsi/qla1280.c b/drivers/scsi/qla1280.c
index 3aeb68bcb7ac..146d540f6281 100644
--- a/drivers/scsi/qla1280.c
+++ b/drivers/scsi/qla1280.c
@@ -1310,14 +1310,7 @@ qla1280_done(struct scsi_qla_host *ha)
1310 } 1310 }
1311 1311
1312 /* Release memory used for this I/O */ 1312 /* Release memory used for this I/O */
1313 if (cmd->use_sg) { 1313 scsi_dma_unmap(cmd);
1314 pci_unmap_sg(ha->pdev, cmd->request_buffer,
1315 cmd->use_sg, cmd->sc_data_direction);
1316 } else if (cmd->request_bufflen) {
1317 pci_unmap_single(ha->pdev, sp->saved_dma_handle,
1318 cmd->request_bufflen,
1319 cmd->sc_data_direction);
1320 }
1321 1314
1322 /* Call the mid-level driver interrupt handler */ 1315 /* Call the mid-level driver interrupt handler */
1323 CMD_HANDLE(sp->cmd) = (unsigned char *)INVALID_HANDLE; 1316 CMD_HANDLE(sp->cmd) = (unsigned char *)INVALID_HANDLE;
@@ -1406,14 +1399,14 @@ qla1280_return_status(struct response * sts, struct scsi_cmnd *cp)
1406 break; 1399 break;
1407 1400
1408 case CS_DATA_UNDERRUN: 1401 case CS_DATA_UNDERRUN:
1409 if ((cp->request_bufflen - residual_length) < 1402 if ((scsi_bufflen(cp) - residual_length) <
1410 cp->underflow) { 1403 cp->underflow) {
1411 printk(KERN_WARNING 1404 printk(KERN_WARNING
1412 "scsi: Underflow detected - retrying " 1405 "scsi: Underflow detected - retrying "
1413 "command.\n"); 1406 "command.\n");
1414 host_status = DID_ERROR; 1407 host_status = DID_ERROR;
1415 } else { 1408 } else {
1416 cp->resid = residual_length; 1409 scsi_set_resid(cp, residual_length);
1417 host_status = DID_OK; 1410 host_status = DID_OK;
1418 } 1411 }
1419 break; 1412 break;
@@ -2775,33 +2768,28 @@ qla1280_64bit_start_scsi(struct scsi_qla_host *ha, struct srb * sp)
2775 struct device_reg __iomem *reg = ha->iobase; 2768 struct device_reg __iomem *reg = ha->iobase;
2776 struct scsi_cmnd *cmd = sp->cmd; 2769 struct scsi_cmnd *cmd = sp->cmd;
2777 cmd_a64_entry_t *pkt; 2770 cmd_a64_entry_t *pkt;
2778 struct scatterlist *sg = NULL, *s;
2779 __le32 *dword_ptr; 2771 __le32 *dword_ptr;
2780 dma_addr_t dma_handle; 2772 dma_addr_t dma_handle;
2781 int status = 0; 2773 int status = 0;
2782 int cnt; 2774 int cnt;
2783 int req_cnt; 2775 int req_cnt;
2784 u16 seg_cnt; 2776 int seg_cnt;
2785 u8 dir; 2777 u8 dir;
2786 2778
2787 ENTER("qla1280_64bit_start_scsi:"); 2779 ENTER("qla1280_64bit_start_scsi:");
2788 2780
2789 /* Calculate number of entries and segments required. */ 2781 /* Calculate number of entries and segments required. */
2790 req_cnt = 1; 2782 req_cnt = 1;
2791 if (cmd->use_sg) { 2783 seg_cnt = scsi_dma_map(cmd);
2792 sg = (struct scatterlist *) cmd->request_buffer; 2784 if (seg_cnt > 0) {
2793 seg_cnt = pci_map_sg(ha->pdev, sg, cmd->use_sg,
2794 cmd->sc_data_direction);
2795
2796 if (seg_cnt > 2) { 2785 if (seg_cnt > 2) {
2797 req_cnt += (seg_cnt - 2) / 5; 2786 req_cnt += (seg_cnt - 2) / 5;
2798 if ((seg_cnt - 2) % 5) 2787 if ((seg_cnt - 2) % 5)
2799 req_cnt++; 2788 req_cnt++;
2800 } 2789 }
2801 } else if (cmd->request_bufflen) { /* If data transfer. */ 2790 } else if (seg_cnt < 0) {
2802 seg_cnt = 1; 2791 status = 1;
2803 } else { 2792 goto out;
2804 seg_cnt = 0;
2805 } 2793 }
2806 2794
2807 if ((req_cnt + 2) >= ha->req_q_cnt) { 2795 if ((req_cnt + 2) >= ha->req_q_cnt) {
@@ -2889,124 +2877,104 @@ qla1280_64bit_start_scsi(struct scsi_qla_host *ha, struct srb * sp)
2889 * Load data segments. 2877 * Load data segments.
2890 */ 2878 */
2891 if (seg_cnt) { /* If data transfer. */ 2879 if (seg_cnt) { /* If data transfer. */
2880 struct scatterlist *sg, *s;
2892 int remseg = seg_cnt; 2881 int remseg = seg_cnt;
2882
2883 sg = scsi_sglist(cmd);
2884
2893 /* Setup packet address segment pointer. */ 2885 /* Setup packet address segment pointer. */
2894 dword_ptr = (u32 *)&pkt->dseg_0_address; 2886 dword_ptr = (u32 *)&pkt->dseg_0_address;
2895 2887
2896 if (cmd->use_sg) { /* If scatter gather */ 2888 /* Load command entry data segments. */
2897 /* Load command entry data segments. */ 2889 for_each_sg(sg, s, seg_cnt, cnt) {
2898 for_each_sg(sg, s, seg_cnt, cnt) { 2890 if (cnt == 2)
2899 if (cnt == 2) 2891 break;
2892
2893 dma_handle = sg_dma_address(s);
2894#if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
2895 if (ha->flags.use_pci_vchannel)
2896 sn_pci_set_vchan(ha->pdev,
2897 (unsigned long *)&dma_handle,
2898 SCSI_BUS_32(cmd));
2899#endif
2900 *dword_ptr++ =
2901 cpu_to_le32(pci_dma_lo32(dma_handle));
2902 *dword_ptr++ =
2903 cpu_to_le32(pci_dma_hi32(dma_handle));
2904 *dword_ptr++ = cpu_to_le32(sg_dma_len(s));
2905 dprintk(3, "S/G Segment phys_addr=%x %x, len=0x%x\n",
2906 cpu_to_le32(pci_dma_hi32(dma_handle)),
2907 cpu_to_le32(pci_dma_lo32(dma_handle)),
2908 cpu_to_le32(sg_dma_len(sg_next(s))));
2909 remseg--;
2910 }
2911 dprintk(5, "qla1280_64bit_start_scsi: Scatter/gather "
2912 "command packet data - b %i, t %i, l %i \n",
2913 SCSI_BUS_32(cmd), SCSI_TCN_32(cmd),
2914 SCSI_LUN_32(cmd));
2915 qla1280_dump_buffer(5, (char *)pkt,
2916 REQUEST_ENTRY_SIZE);
2917
2918 /*
2919 * Build continuation packets.
2920 */
2921 dprintk(3, "S/G Building Continuation...seg_cnt=0x%x "
2922 "remains\n", seg_cnt);
2923
2924 while (remseg > 0) {
2925 /* Update sg start */
2926 sg = s;
2927 /* Adjust ring index. */
2928 ha->req_ring_index++;
2929 if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
2930 ha->req_ring_index = 0;
2931 ha->request_ring_ptr =
2932 ha->request_ring;
2933 } else
2934 ha->request_ring_ptr++;
2935
2936 pkt = (cmd_a64_entry_t *)ha->request_ring_ptr;
2937
2938 /* Zero out packet. */
2939 memset(pkt, 0, REQUEST_ENTRY_SIZE);
2940
2941 /* Load packet defaults. */
2942 ((struct cont_a64_entry *) pkt)->entry_type =
2943 CONTINUE_A64_TYPE;
2944 ((struct cont_a64_entry *) pkt)->entry_count = 1;
2945 ((struct cont_a64_entry *) pkt)->sys_define =
2946 (uint8_t)ha->req_ring_index;
2947 /* Setup packet address segment pointer. */
2948 dword_ptr =
2949 (u32 *)&((struct cont_a64_entry *) pkt)->dseg_0_address;
2950
2951 /* Load continuation entry data segments. */
2952 for_each_sg(sg, s, remseg, cnt) {
2953 if (cnt == 5)
2900 break; 2954 break;
2901 dma_handle = sg_dma_address(s); 2955 dma_handle = sg_dma_address(s);
2902#if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2) 2956#if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
2903 if (ha->flags.use_pci_vchannel) 2957 if (ha->flags.use_pci_vchannel)
2904 sn_pci_set_vchan(ha->pdev, 2958 sn_pci_set_vchan(ha->pdev,
2905 (unsigned long *)&dma_handle, 2959 (unsigned long *)&dma_handle,
2906 SCSI_BUS_32(cmd)); 2960 SCSI_BUS_32(cmd));
2907#endif 2961#endif
2908 *dword_ptr++ = 2962 *dword_ptr++ =
2909 cpu_to_le32(pci_dma_lo32(dma_handle)); 2963 cpu_to_le32(pci_dma_lo32(dma_handle));
2910 *dword_ptr++ = 2964 *dword_ptr++ =
2911 cpu_to_le32(pci_dma_hi32(dma_handle)); 2965 cpu_to_le32(pci_dma_hi32(dma_handle));
2912 *dword_ptr++ = cpu_to_le32(sg_dma_len(s)); 2966 *dword_ptr++ =
2913 dprintk(3, "S/G Segment phys_addr=%x %x, len=0x%x\n", 2967 cpu_to_le32(sg_dma_len(s));
2968 dprintk(3, "S/G Segment Cont. phys_addr=%x %x, len=0x%x\n",
2914 cpu_to_le32(pci_dma_hi32(dma_handle)), 2969 cpu_to_le32(pci_dma_hi32(dma_handle)),
2915 cpu_to_le32(pci_dma_lo32(dma_handle)), 2970 cpu_to_le32(pci_dma_lo32(dma_handle)),
2916 cpu_to_le32(sg_dma_len(sg_next(s)))); 2971 cpu_to_le32(sg_dma_len(s)));
2917 remseg--;
2918 } 2972 }
2919 dprintk(5, "qla1280_64bit_start_scsi: Scatter/gather " 2973 remseg -= cnt;
2920 "command packet data - b %i, t %i, l %i \n", 2974 dprintk(5, "qla1280_64bit_start_scsi: "
2921 SCSI_BUS_32(cmd), SCSI_TCN_32(cmd), 2975 "continuation packet data - b %i, t "
2922 SCSI_LUN_32(cmd)); 2976 "%i, l %i \n", SCSI_BUS_32(cmd),
2923 qla1280_dump_buffer(5, (char *)pkt, 2977 SCSI_TCN_32(cmd), SCSI_LUN_32(cmd));
2924 REQUEST_ENTRY_SIZE);
2925
2926 /*
2927 * Build continuation packets.
2928 */
2929 dprintk(3, "S/G Building Continuation...seg_cnt=0x%x "
2930 "remains\n", seg_cnt);
2931
2932 while (remseg > 0) {
2933 /* Update sg start */
2934 sg = s;
2935 /* Adjust ring index. */
2936 ha->req_ring_index++;
2937 if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
2938 ha->req_ring_index = 0;
2939 ha->request_ring_ptr =
2940 ha->request_ring;
2941 } else
2942 ha->request_ring_ptr++;
2943
2944 pkt = (cmd_a64_entry_t *)ha->request_ring_ptr;
2945
2946 /* Zero out packet. */
2947 memset(pkt, 0, REQUEST_ENTRY_SIZE);
2948
2949 /* Load packet defaults. */
2950 ((struct cont_a64_entry *) pkt)->entry_type =
2951 CONTINUE_A64_TYPE;
2952 ((struct cont_a64_entry *) pkt)->entry_count = 1;
2953 ((struct cont_a64_entry *) pkt)->sys_define =
2954 (uint8_t)ha->req_ring_index;
2955 /* Setup packet address segment pointer. */
2956 dword_ptr =
2957 (u32 *)&((struct cont_a64_entry *) pkt)->dseg_0_address;
2958
2959 /* Load continuation entry data segments. */
2960 for_each_sg(sg, s, remseg, cnt) {
2961 if (cnt == 5)
2962 break;
2963 dma_handle = sg_dma_address(s);
2964#if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
2965 if (ha->flags.use_pci_vchannel)
2966 sn_pci_set_vchan(ha->pdev,
2967 (unsigned long *)&dma_handle,
2968 SCSI_BUS_32(cmd));
2969#endif
2970 *dword_ptr++ =
2971 cpu_to_le32(pci_dma_lo32(dma_handle));
2972 *dword_ptr++ =
2973 cpu_to_le32(pci_dma_hi32(dma_handle));
2974 *dword_ptr++ =
2975 cpu_to_le32(sg_dma_len(s));
2976 dprintk(3, "S/G Segment Cont. phys_addr=%x %x, len=0x%x\n",
2977 cpu_to_le32(pci_dma_hi32(dma_handle)),
2978 cpu_to_le32(pci_dma_lo32(dma_handle)),
2979 cpu_to_le32(sg_dma_len(s)));
2980 }
2981 remseg -= cnt;
2982 dprintk(5, "qla1280_64bit_start_scsi: "
2983 "continuation packet data - b %i, t "
2984 "%i, l %i \n", SCSI_BUS_32(cmd),
2985 SCSI_TCN_32(cmd), SCSI_LUN_32(cmd));
2986 qla1280_dump_buffer(5, (char *)pkt,
2987 REQUEST_ENTRY_SIZE);
2988 }
2989 } else { /* No scatter gather data transfer */
2990 dma_handle = pci_map_single(ha->pdev,
2991 cmd->request_buffer,
2992 cmd->request_bufflen,
2993 cmd->sc_data_direction);
2994
2995 sp->saved_dma_handle = dma_handle;
2996#if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
2997 if (ha->flags.use_pci_vchannel)
2998 sn_pci_set_vchan(ha->pdev,
2999 (unsigned long *)&dma_handle,
3000 SCSI_BUS_32(cmd));
3001#endif
3002 *dword_ptr++ = cpu_to_le32(pci_dma_lo32(dma_handle));
3003 *dword_ptr++ = cpu_to_le32(pci_dma_hi32(dma_handle));
3004 *dword_ptr = cpu_to_le32(cmd->request_bufflen);
3005
3006 dprintk(5, "qla1280_64bit_start_scsi: No scatter/"
3007 "gather command packet data - b %i, t %i, "
3008 "l %i \n", SCSI_BUS_32(cmd), SCSI_TCN_32(cmd),
3009 SCSI_LUN_32(cmd));
3010 qla1280_dump_buffer(5, (char *)pkt, 2978 qla1280_dump_buffer(5, (char *)pkt,
3011 REQUEST_ENTRY_SIZE); 2979 REQUEST_ENTRY_SIZE);
3012 } 2980 }
@@ -3068,12 +3036,11 @@ qla1280_32bit_start_scsi(struct scsi_qla_host *ha, struct srb * sp)
3068 struct device_reg __iomem *reg = ha->iobase; 3036 struct device_reg __iomem *reg = ha->iobase;
3069 struct scsi_cmnd *cmd = sp->cmd; 3037 struct scsi_cmnd *cmd = sp->cmd;
3070 struct cmd_entry *pkt; 3038 struct cmd_entry *pkt;
3071 struct scatterlist *sg = NULL, *s;
3072 __le32 *dword_ptr; 3039 __le32 *dword_ptr;
3073 int status = 0; 3040 int status = 0;
3074 int cnt; 3041 int cnt;
3075 int req_cnt; 3042 int req_cnt;
3076 uint16_t seg_cnt; 3043 int seg_cnt;
3077 dma_addr_t dma_handle; 3044 dma_addr_t dma_handle;
3078 u8 dir; 3045 u8 dir;
3079 3046
@@ -3083,18 +3050,8 @@ qla1280_32bit_start_scsi(struct scsi_qla_host *ha, struct srb * sp)
3083 cmd->cmnd[0]); 3050 cmd->cmnd[0]);
3084 3051
3085 /* Calculate number of entries and segments required. */ 3052 /* Calculate number of entries and segments required. */
3086 req_cnt = 1; 3053 seg_cnt = scsi_dma_map(cmd);
3087 if (cmd->use_sg) { 3054 if (seg_cnt) {
3088 /*
3089 * We must build an SG list in adapter format, as the kernel's
3090 * SG list cannot be used directly because of data field size
3091 * (__alpha__) differences and the kernel SG list uses virtual
3092 * addresses where we need physical addresses.
3093 */
3094 sg = (struct scatterlist *) cmd->request_buffer;
3095 seg_cnt = pci_map_sg(ha->pdev, sg, cmd->use_sg,
3096 cmd->sc_data_direction);
3097
3098 /* 3055 /*
3099 * if greater than four sg entries then we need to allocate 3056 * if greater than four sg entries then we need to allocate
3100 * continuation entries 3057 * continuation entries
@@ -3106,14 +3063,9 @@ qla1280_32bit_start_scsi(struct scsi_qla_host *ha, struct srb * sp)
3106 } 3063 }
3107 dprintk(3, "S/G Transfer cmd=%p seg_cnt=0x%x, req_cnt=%x\n", 3064 dprintk(3, "S/G Transfer cmd=%p seg_cnt=0x%x, req_cnt=%x\n",
3108 cmd, seg_cnt, req_cnt); 3065 cmd, seg_cnt, req_cnt);
3109 } else if (cmd->request_bufflen) { /* If data transfer. */ 3066 } else if (seg_cnt < 0) {
3110 dprintk(3, "No S/G transfer t=%x cmd=%p len=%x CDB=%x\n", 3067 status = 1;
3111 SCSI_TCN_32(cmd), cmd, cmd->request_bufflen, 3068 goto out;
3112 cmd->cmnd[0]);
3113 seg_cnt = 1;
3114 } else {
3115 /* dprintk(1, "No data transfer \n"); */
3116 seg_cnt = 0;
3117 } 3069 }
3118 3070
3119 if ((req_cnt + 2) >= ha->req_q_cnt) { 3071 if ((req_cnt + 2) >= ha->req_q_cnt) {
@@ -3194,91 +3146,84 @@ qla1280_32bit_start_scsi(struct scsi_qla_host *ha, struct srb * sp)
3194 * Load data segments. 3146 * Load data segments.
3195 */ 3147 */
3196 if (seg_cnt) { 3148 if (seg_cnt) {
3149 struct scatterlist *sg, *s;
3197 int remseg = seg_cnt; 3150 int remseg = seg_cnt;
3151
3152 sg = scsi_sglist(cmd);
3153
3198 /* Setup packet address segment pointer. */ 3154 /* Setup packet address segment pointer. */
3199 dword_ptr = &pkt->dseg_0_address; 3155 dword_ptr = &pkt->dseg_0_address;
3200 3156
3201 if (cmd->use_sg) { /* If scatter gather */ 3157 dprintk(3, "Building S/G data segments..\n");
3202 dprintk(3, "Building S/G data segments..\n"); 3158 qla1280_dump_buffer(1, (char *)sg, 4 * 16);
3203 qla1280_dump_buffer(1, (char *)sg, 4 * 16); 3159
3160 /* Load command entry data segments. */
3161 for_each_sg(sg, s, seg_cnt, cnt) {
3162 if (cnt == 4)
3163 break;
3164 *dword_ptr++ =
3165 cpu_to_le32(pci_dma_lo32(sg_dma_address(s)));
3166 *dword_ptr++ = cpu_to_le32(sg_dma_len(s));
3167 dprintk(3, "S/G Segment phys_addr=0x%lx, len=0x%x\n",
3168 (pci_dma_lo32(sg_dma_address(s))),
3169 (sg_dma_len(s)));
3170 remseg--;
3171 }
3172 /*
3173 * Build continuation packets.
3174 */
3175 dprintk(3, "S/G Building Continuation"
3176 "...seg_cnt=0x%x remains\n", seg_cnt);
3177 while (remseg > 0) {
3178 /* Continue from end point */
3179 sg = s;
3180 /* Adjust ring index. */
3181 ha->req_ring_index++;
3182 if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
3183 ha->req_ring_index = 0;
3184 ha->request_ring_ptr =
3185 ha->request_ring;
3186 } else
3187 ha->request_ring_ptr++;
3188
3189 pkt = (struct cmd_entry *)ha->request_ring_ptr;
3190
3191 /* Zero out packet. */
3192 memset(pkt, 0, REQUEST_ENTRY_SIZE);
3193
3194 /* Load packet defaults. */
3195 ((struct cont_entry *) pkt)->
3196 entry_type = CONTINUE_TYPE;
3197 ((struct cont_entry *) pkt)->entry_count = 1;
3204 3198
3205 /* Load command entry data segments. */ 3199 ((struct cont_entry *) pkt)->sys_define =
3206 for_each_sg(sg, s, seg_cnt, cnt) { 3200 (uint8_t) ha->req_ring_index;
3207 if (cnt == 4) 3201
3202 /* Setup packet address segment pointer. */
3203 dword_ptr =
3204 &((struct cont_entry *) pkt)->dseg_0_address;
3205
3206 /* Load continuation entry data segments. */
3207 for_each_sg(sg, s, remseg, cnt) {
3208 if (cnt == 7)
3208 break; 3209 break;
3209 *dword_ptr++ = 3210 *dword_ptr++ =
3210 cpu_to_le32(pci_dma_lo32(sg_dma_address(s))); 3211 cpu_to_le32(pci_dma_lo32(sg_dma_address(s)));
3211 *dword_ptr++ = cpu_to_le32(sg_dma_len(s)); 3212 *dword_ptr++ =
3212 dprintk(3, "S/G Segment phys_addr=0x%lx, len=0x%x\n", 3213 cpu_to_le32(sg_dma_len(s));
3213 (pci_dma_lo32(sg_dma_address(s))), 3214 dprintk(1,
3214 (sg_dma_len(s))); 3215 "S/G Segment Cont. phys_addr=0x%x, "
3215 remseg--; 3216 "len=0x%x\n",
3216 } 3217 cpu_to_le32(pci_dma_lo32(sg_dma_address(s))),
3217 /* 3218 cpu_to_le32(sg_dma_len(s)));
3218 * Build continuation packets.
3219 */
3220 dprintk(3, "S/G Building Continuation"
3221 "...seg_cnt=0x%x remains\n", seg_cnt);
3222 while (remseg > 0) {
3223 /* Continue from end point */
3224 sg = s;
3225 /* Adjust ring index. */
3226 ha->req_ring_index++;
3227 if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
3228 ha->req_ring_index = 0;
3229 ha->request_ring_ptr =
3230 ha->request_ring;
3231 } else
3232 ha->request_ring_ptr++;
3233
3234 pkt = (struct cmd_entry *)ha->request_ring_ptr;
3235
3236 /* Zero out packet. */
3237 memset(pkt, 0, REQUEST_ENTRY_SIZE);
3238
3239 /* Load packet defaults. */
3240 ((struct cont_entry *) pkt)->
3241 entry_type = CONTINUE_TYPE;
3242 ((struct cont_entry *) pkt)->entry_count = 1;
3243
3244 ((struct cont_entry *) pkt)->sys_define =
3245 (uint8_t) ha->req_ring_index;
3246
3247 /* Setup packet address segment pointer. */
3248 dword_ptr =
3249 &((struct cont_entry *) pkt)->dseg_0_address;
3250
3251 /* Load continuation entry data segments. */
3252 for_each_sg(sg, s, remseg, cnt) {
3253 if (cnt == 7)
3254 break;
3255 *dword_ptr++ =
3256 cpu_to_le32(pci_dma_lo32(sg_dma_address(s)));
3257 *dword_ptr++ =
3258 cpu_to_le32(sg_dma_len(s));
3259 dprintk(1,
3260 "S/G Segment Cont. phys_addr=0x%x, "
3261 "len=0x%x\n",
3262 cpu_to_le32(pci_dma_lo32(sg_dma_address(s))),
3263 cpu_to_le32(sg_dma_len(s)));
3264 }
3265 remseg -= cnt;
3266 dprintk(5, "qla1280_32bit_start_scsi: "
3267 "continuation packet data - "
3268 "scsi(%i:%i:%i)\n", SCSI_BUS_32(cmd),
3269 SCSI_TCN_32(cmd), SCSI_LUN_32(cmd));
3270 qla1280_dump_buffer(5, (char *)pkt,
3271 REQUEST_ENTRY_SIZE);
3272 } 3219 }
3273 } else { /* No S/G data transfer */ 3220 remseg -= cnt;
3274 dma_handle = pci_map_single(ha->pdev, 3221 dprintk(5, "qla1280_32bit_start_scsi: "
3275 cmd->request_buffer, 3222 "continuation packet data - "
3276 cmd->request_bufflen, 3223 "scsi(%i:%i:%i)\n", SCSI_BUS_32(cmd),
3277 cmd->sc_data_direction); 3224 SCSI_TCN_32(cmd), SCSI_LUN_32(cmd));
3278 sp->saved_dma_handle = dma_handle; 3225 qla1280_dump_buffer(5, (char *)pkt,
3279 3226 REQUEST_ENTRY_SIZE);
3280 *dword_ptr++ = cpu_to_le32(pci_dma_lo32(dma_handle));
3281 *dword_ptr = cpu_to_le32(cmd->request_bufflen);
3282 } 3227 }
3283 } else { /* No data transfer at all */ 3228 } else { /* No data transfer at all */
3284 dprintk(5, "qla1280_32bit_start_scsi: No data, command " 3229 dprintk(5, "qla1280_32bit_start_scsi: No data, command "
@@ -4086,9 +4031,9 @@ __qla1280_print_scsi_cmd(struct scsi_cmnd *cmd)
4086 for (i = 0; i < cmd->cmd_len; i++) { 4031 for (i = 0; i < cmd->cmd_len; i++) {
4087 printk("0x%02x ", cmd->cmnd[i]); 4032 printk("0x%02x ", cmd->cmnd[i]);
4088 } 4033 }
4089 printk(" seg_cnt =%d\n", cmd->use_sg); 4034 printk(" seg_cnt =%d\n", scsi_sg_count(cmd));
4090 printk(" request buffer=0x%p, request buffer len=0x%x\n", 4035 printk(" request buffer=0x%p, request buffer len=0x%x\n",
4091 cmd->request_buffer, cmd->request_bufflen); 4036 scsi_sglist(cmd), scsi_bufflen(cmd));
4092 /* if (cmd->use_sg) 4037 /* if (cmd->use_sg)
4093 { 4038 {
4094 sg = (struct scatterlist *) cmd->request_buffer; 4039 sg = (struct scatterlist *) cmd->request_buffer;
diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
index 192948822455..0fb1709ce5e3 100644
--- a/drivers/scsi/scsi.c
+++ b/drivers/scsi/scsi.c
@@ -896,11 +896,11 @@ EXPORT_SYMBOL(__scsi_iterate_devices);
896 * starget_for_each_device - helper to walk all devices of a target 896 * starget_for_each_device - helper to walk all devices of a target
897 * @starget: target whose devices we want to iterate over. 897 * @starget: target whose devices we want to iterate over.
898 * 898 *
899 * This traverses over each devices of @shost. The devices have 899 * This traverses over each device of @starget. The devices have
900 * a reference that must be released by scsi_host_put when breaking 900 * a reference that must be released by scsi_host_put when breaking
901 * out of the loop. 901 * out of the loop.
902 */ 902 */
903void starget_for_each_device(struct scsi_target *starget, void * data, 903void starget_for_each_device(struct scsi_target *starget, void *data,
904 void (*fn)(struct scsi_device *, void *)) 904 void (*fn)(struct scsi_device *, void *))
905{ 905{
906 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); 906 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
@@ -915,6 +915,33 @@ void starget_for_each_device(struct scsi_target *starget, void * data,
915EXPORT_SYMBOL(starget_for_each_device); 915EXPORT_SYMBOL(starget_for_each_device);
916 916
917/** 917/**
918 * __starget_for_each_device - helper to walk all devices of a target
919 * (UNLOCKED)
920 * @starget: target whose devices we want to iterate over.
921 *
922 * This traverses over each device of @starget. It does _not_
923 * take a reference on the scsi_device, so the whole loop must be
924 * protected by shost->host_lock.
925 *
926 * Note: The only reason why drivers would want to use this is because
927 * they need to access the device list in irq context. Otherwise you
928 * really want to use starget_for_each_device instead.
929 **/
930void __starget_for_each_device(struct scsi_target *starget, void *data,
931 void (*fn)(struct scsi_device *, void *))
932{
933 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
934 struct scsi_device *sdev;
935
936 __shost_for_each_device(sdev, shost) {
937 if ((sdev->channel == starget->channel) &&
938 (sdev->id == starget->id))
939 fn(sdev, data);
940 }
941}
942EXPORT_SYMBOL(__starget_for_each_device);
943
944/**
918 * __scsi_device_lookup_by_target - find a device given the target (UNLOCKED) 945 * __scsi_device_lookup_by_target - find a device given the target (UNLOCKED)
919 * @starget: SCSI target pointer 946 * @starget: SCSI target pointer
920 * @lun: SCSI Logical Unit Number 947 * @lun: SCSI Logical Unit Number
diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c
index 98dfd6ea209c..328c47c6aeb1 100644
--- a/drivers/scsi/st.c
+++ b/drivers/scsi/st.c
@@ -3611,6 +3611,7 @@ static struct st_buffer *
3611 3611
3612 tb->dma = need_dma; 3612 tb->dma = need_dma;
3613 tb->buffer_size = got; 3613 tb->buffer_size = got;
3614 sg_init_table(tb->sg, max_sg);
3614 3615
3615 return tb; 3616 return tb;
3616} 3617}
diff --git a/drivers/scsi/sun3_scsi.c b/drivers/scsi/sun3_scsi.c
index 5e46d842c6f9..e606cf0a2eb7 100644
--- a/drivers/scsi/sun3_scsi.c
+++ b/drivers/scsi/sun3_scsi.c
@@ -268,7 +268,7 @@ int sun3scsi_detect(struct scsi_host_template * tpnt)
268 ((struct NCR5380_hostdata *)instance->hostdata)->ctrl = 0; 268 ((struct NCR5380_hostdata *)instance->hostdata)->ctrl = 0;
269 269
270 if (request_irq(instance->irq, scsi_sun3_intr, 270 if (request_irq(instance->irq, scsi_sun3_intr,
271 0, "Sun3SCSI-5380", NULL)) { 271 0, "Sun3SCSI-5380", instance)) {
272#ifndef REAL_DMA 272#ifndef REAL_DMA
273 printk("scsi%d: IRQ%d not free, interrupts disabled\n", 273 printk("scsi%d: IRQ%d not free, interrupts disabled\n",
274 instance->host_no, instance->irq); 274 instance->host_no, instance->irq);
@@ -310,7 +310,7 @@ int sun3scsi_detect(struct scsi_host_template * tpnt)
310int sun3scsi_release (struct Scsi_Host *shpnt) 310int sun3scsi_release (struct Scsi_Host *shpnt)
311{ 311{
312 if (shpnt->irq != SCSI_IRQ_NONE) 312 if (shpnt->irq != SCSI_IRQ_NONE)
313 free_irq (shpnt->irq, NULL); 313 free_irq(shpnt->irq, shpnt);
314 314
315 iounmap((void *)sun3_scsi_regp); 315 iounmap((void *)sun3_scsi_regp);
316 316
diff --git a/drivers/scsi/sun3_scsi_vme.c b/drivers/scsi/sun3_scsi_vme.c
index 7cb4a31453e6..02d9727f017a 100644
--- a/drivers/scsi/sun3_scsi_vme.c
+++ b/drivers/scsi/sun3_scsi_vme.c
@@ -230,7 +230,7 @@ static int sun3scsi_detect(struct scsi_host_template * tpnt)
230 ((struct NCR5380_hostdata *)instance->hostdata)->ctrl = 0; 230 ((struct NCR5380_hostdata *)instance->hostdata)->ctrl = 0;
231 231
232 if (request_irq(instance->irq, scsi_sun3_intr, 232 if (request_irq(instance->irq, scsi_sun3_intr,
233 0, "Sun3SCSI-5380VME", NULL)) { 233 0, "Sun3SCSI-5380VME", instance)) {
234#ifndef REAL_DMA 234#ifndef REAL_DMA
235 printk("scsi%d: IRQ%d not free, interrupts disabled\n", 235 printk("scsi%d: IRQ%d not free, interrupts disabled\n",
236 instance->host_no, instance->irq); 236 instance->host_no, instance->irq);
@@ -279,7 +279,7 @@ static int sun3scsi_detect(struct scsi_host_template * tpnt)
279int sun3scsi_release (struct Scsi_Host *shpnt) 279int sun3scsi_release (struct Scsi_Host *shpnt)
280{ 280{
281 if (shpnt->irq != SCSI_IRQ_NONE) 281 if (shpnt->irq != SCSI_IRQ_NONE)
282 free_irq (shpnt->irq, NULL); 282 free_irq(shpnt->irq, shpnt);
283 283
284 iounmap((void *)sun3_scsi_regp); 284 iounmap((void *)sun3_scsi_regp);
285 285
diff --git a/drivers/scsi/sym53c8xx_2/sym_glue.c b/drivers/scsi/sym53c8xx_2/sym_glue.c
index 0f74aba5b237..9e0908d1981a 100644
--- a/drivers/scsi/sym53c8xx_2/sym_glue.c
+++ b/drivers/scsi/sym53c8xx_2/sym_glue.c
@@ -1243,7 +1243,7 @@ static void sym_free_resources(struct sym_hcb *np, struct pci_dev *pdev)
1243 * Free O/S specific resources. 1243 * Free O/S specific resources.
1244 */ 1244 */
1245 if (pdev->irq) 1245 if (pdev->irq)
1246 free_irq(pdev->irq, np); 1246 free_irq(pdev->irq, np->s.host);
1247 if (np->s.ioaddr) 1247 if (np->s.ioaddr)
1248 pci_iounmap(pdev, np->s.ioaddr); 1248 pci_iounmap(pdev, np->s.ioaddr);
1249 if (np->s.ramaddr) 1249 if (np->s.ramaddr)
diff --git a/drivers/scsi/sym53c8xx_2/sym_hipd.c b/drivers/scsi/sym53c8xx_2/sym_hipd.c
index 463f119f20e9..254bdaeb35ff 100644
--- a/drivers/scsi/sym53c8xx_2/sym_hipd.c
+++ b/drivers/scsi/sym53c8xx_2/sym_hipd.c
@@ -2791,7 +2791,7 @@ irqreturn_t sym_interrupt(struct Scsi_Host *shost)
2791 istat = INB(np, nc_istat); 2791 istat = INB(np, nc_istat);
2792 if (istat & INTF) { 2792 if (istat & INTF) {
2793 OUTB(np, nc_istat, (istat & SIGP) | INTF | np->istat_sem); 2793 OUTB(np, nc_istat, (istat & SIGP) | INTF | np->istat_sem);
2794 istat = INB(np, nc_istat); /* DUMMY READ */ 2794 istat |= INB(np, nc_istat); /* DUMMY READ */
2795 if (DEBUG_FLAGS & DEBUG_TINY) printf ("F "); 2795 if (DEBUG_FLAGS & DEBUG_TINY) printf ("F ");
2796 sym_wakeup_done(np); 2796 sym_wakeup_done(np);
2797 } 2797 }
diff --git a/drivers/scsi/t128.c b/drivers/scsi/t128.c
index 248d60b8d899..041eaaace2c3 100644
--- a/drivers/scsi/t128.c
+++ b/drivers/scsi/t128.c
@@ -259,7 +259,8 @@ found:
259 instance->irq = NCR5380_probe_irq(instance, T128_IRQS); 259 instance->irq = NCR5380_probe_irq(instance, T128_IRQS);
260 260
261 if (instance->irq != SCSI_IRQ_NONE) 261 if (instance->irq != SCSI_IRQ_NONE)
262 if (request_irq(instance->irq, t128_intr, IRQF_DISABLED, "t128", instance)) { 262 if (request_irq(instance->irq, t128_intr, IRQF_DISABLED, "t128",
263 instance)) {
263 printk("scsi%d : IRQ%d not free, interrupts disabled\n", 264 printk("scsi%d : IRQ%d not free, interrupts disabled\n",
264 instance->host_no, instance->irq); 265 instance->host_no, instance->irq);
265 instance->irq = SCSI_IRQ_NONE; 266 instance->irq = SCSI_IRQ_NONE;
@@ -295,7 +296,7 @@ static int t128_release(struct Scsi_Host *shost)
295 NCR5380_local_declare(); 296 NCR5380_local_declare();
296 NCR5380_setup(shost); 297 NCR5380_setup(shost);
297 if (shost->irq) 298 if (shost->irq)
298 free_irq(shost->irq, NULL); 299 free_irq(shost->irq, shost);
299 NCR5380_exit(shost); 300 NCR5380_exit(shost);
300 if (shost->io_port && shost->n_io_port) 301 if (shost->io_port && shost->n_io_port)
301 release_region(shost->io_port, shost->n_io_port); 302 release_region(shost->io_port, shost->n_io_port);
diff --git a/drivers/scsi/zorro7xx.c b/drivers/scsi/zorro7xx.c
index ac67394c7373..64d40a2d4d4d 100644
--- a/drivers/scsi/zorro7xx.c
+++ b/drivers/scsi/zorro7xx.c
@@ -13,7 +13,10 @@
13#include <linux/init.h> 13#include <linux/init.h>
14#include <linux/interrupt.h> 14#include <linux/interrupt.h>
15#include <linux/zorro.h> 15#include <linux/zorro.h>
16
17#include <asm/amigahw.h>
16#include <asm/amigaints.h> 18#include <asm/amigaints.h>
19
17#include <scsi/scsi_host.h> 20#include <scsi/scsi_host.h>
18#include <scsi/scsi_transport_spi.h> 21#include <scsi/scsi_transport_spi.h>
19 22
diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig
index ed438bc7e98d..d7e1996e2fec 100644
--- a/drivers/serial/Kconfig
+++ b/drivers/serial/Kconfig
@@ -600,7 +600,7 @@ config SERIAL_SA1100_CONSOLE
600 600
601config SERIAL_BFIN 601config SERIAL_BFIN
602 tristate "Blackfin serial port support" 602 tristate "Blackfin serial port support"
603 depends on BFIN 603 depends on BLACKFIN
604 select SERIAL_CORE 604 select SERIAL_CORE
605 select SERIAL_BFIN_UART0 if (BF531 || BF532 || BF533 || BF561) 605 select SERIAL_BFIN_UART0 if (BF531 || BF532 || BF533 || BF561)
606 help 606 help
diff --git a/drivers/serial/ip22zilog.c b/drivers/serial/ip22zilog.c
index f3257f708ef9..9c95bc0398ad 100644
--- a/drivers/serial/ip22zilog.c
+++ b/drivers/serial/ip22zilog.c
@@ -45,8 +45,6 @@
45 45
46#include "ip22zilog.h" 46#include "ip22zilog.h"
47 47
48void ip22_do_break(void);
49
50/* 48/*
51 * On IP22 we need to delay after register accesses but we do not need to 49 * On IP22 we need to delay after register accesses but we do not need to
52 * flush writes. 50 * flush writes.
@@ -81,12 +79,9 @@ struct uart_ip22zilog_port {
81#define IP22ZILOG_FLAG_REGS_HELD 0x00000040 79#define IP22ZILOG_FLAG_REGS_HELD 0x00000040
82#define IP22ZILOG_FLAG_TX_STOPPED 0x00000080 80#define IP22ZILOG_FLAG_TX_STOPPED 0x00000080
83#define IP22ZILOG_FLAG_TX_ACTIVE 0x00000100 81#define IP22ZILOG_FLAG_TX_ACTIVE 0x00000100
82#define IP22ZILOG_FLAG_RESET_DONE 0x00000200
84 83
85 unsigned int cflag; 84 unsigned int tty_break;
86
87 /* L1-A keyboard break state. */
88 int kbd_id;
89 int l1_down;
90 85
91 unsigned char parity_mask; 86 unsigned char parity_mask;
92 unsigned char prev_status; 87 unsigned char prev_status;
@@ -250,13 +245,26 @@ static void ip22zilog_maybe_update_regs(struct uart_ip22zilog_port *up,
250 } 245 }
251} 246}
252 247
253static void ip22zilog_receive_chars(struct uart_ip22zilog_port *up, 248#define Rx_BRK 0x0100 /* BREAK event software flag. */
254 struct zilog_channel *channel) 249#define Rx_SYS 0x0200 /* SysRq event software flag. */
250
251static struct tty_struct *ip22zilog_receive_chars(struct uart_ip22zilog_port *up,
252 struct zilog_channel *channel)
255{ 253{
256 struct tty_struct *tty = up->port.info->tty; /* XXX info==NULL? */ 254 struct tty_struct *tty;
255 unsigned char ch, flag;
256 unsigned int r1;
257
258 tty = NULL;
259 if (up->port.info != NULL &&
260 up->port.info->tty != NULL)
261 tty = up->port.info->tty;
257 262
258 while (1) { 263 for (;;) {
259 unsigned char ch, r1, flag; 264 ch = readb(&channel->control);
265 ZSDELAY();
266 if (!(ch & Rx_CH_AV))
267 break;
260 268
261 r1 = read_zsreg(channel, R1); 269 r1 = read_zsreg(channel, R1);
262 if (r1 & (PAR_ERR | Rx_OVR | CRC_ERR)) { 270 if (r1 & (PAR_ERR | Rx_OVR | CRC_ERR)) {
@@ -265,43 +273,26 @@ static void ip22zilog_receive_chars(struct uart_ip22zilog_port *up,
265 ZS_WSYNC(channel); 273 ZS_WSYNC(channel);
266 } 274 }
267 275
268 ch = readb(&channel->control);
269 ZSDELAY();
270
271 /* This funny hack depends upon BRK_ABRT not interfering
272 * with the other bits we care about in R1.
273 */
274 if (ch & BRK_ABRT)
275 r1 |= BRK_ABRT;
276
277 ch = readb(&channel->data); 276 ch = readb(&channel->data);
278 ZSDELAY(); 277 ZSDELAY();
279 278
280 ch &= up->parity_mask; 279 ch &= up->parity_mask;
281 280
282 if (ZS_IS_CONS(up) && (r1 & BRK_ABRT)) { 281 /* Handle the null char got when BREAK is removed. */
283 /* Wait for BREAK to deassert to avoid potentially 282 if (!ch)
284 * confusing the PROM. 283 r1 |= up->tty_break;
285 */
286 while (1) {
287 ch = readb(&channel->control);
288 ZSDELAY();
289 if (!(ch & BRK_ABRT))
290 break;
291 }
292 ip22_do_break();
293 return;
294 }
295 284
296 /* A real serial line, record the character and status. */ 285 /* A real serial line, record the character and status. */
297 flag = TTY_NORMAL; 286 flag = TTY_NORMAL;
298 up->port.icount.rx++; 287 up->port.icount.rx++;
299 if (r1 & (BRK_ABRT | PAR_ERR | Rx_OVR | CRC_ERR)) { 288 if (r1 & (PAR_ERR | Rx_OVR | CRC_ERR | Rx_SYS | Rx_BRK)) {
300 if (r1 & BRK_ABRT) { 289 up->tty_break = 0;
301 r1 &= ~(PAR_ERR | CRC_ERR); 290
291 if (r1 & (Rx_SYS | Rx_BRK)) {
302 up->port.icount.brk++; 292 up->port.icount.brk++;
303 if (uart_handle_break(&up->port)) 293 if (r1 & Rx_SYS)
304 goto next_char; 294 continue;
295 r1 &= ~(PAR_ERR | CRC_ERR);
305 } 296 }
306 else if (r1 & PAR_ERR) 297 else if (r1 & PAR_ERR)
307 up->port.icount.parity++; 298 up->port.icount.parity++;
@@ -310,30 +301,21 @@ static void ip22zilog_receive_chars(struct uart_ip22zilog_port *up,
310 if (r1 & Rx_OVR) 301 if (r1 & Rx_OVR)
311 up->port.icount.overrun++; 302 up->port.icount.overrun++;
312 r1 &= up->port.read_status_mask; 303 r1 &= up->port.read_status_mask;
313 if (r1 & BRK_ABRT) 304 if (r1 & Rx_BRK)
314 flag = TTY_BREAK; 305 flag = TTY_BREAK;
315 else if (r1 & PAR_ERR) 306 else if (r1 & PAR_ERR)
316 flag = TTY_PARITY; 307 flag = TTY_PARITY;
317 else if (r1 & CRC_ERR) 308 else if (r1 & CRC_ERR)
318 flag = TTY_FRAME; 309 flag = TTY_FRAME;
319 } 310 }
320 if (uart_handle_sysrq_char(&up->port, ch))
321 goto next_char;
322 311
323 if (up->port.ignore_status_mask == 0xff || 312 if (uart_handle_sysrq_char(&up->port, ch))
324 (r1 & up->port.ignore_status_mask) == 0) 313 continue;
325 tty_insert_flip_char(tty, ch, flag);
326 314
327 if (r1 & Rx_OVR) 315 if (tty)
328 tty_insert_flip_char(tty, 0, TTY_OVERRUN); 316 uart_insert_char(&up->port, r1, Rx_OVR, ch, flag);
329 next_char:
330 ch = readb(&channel->control);
331 ZSDELAY();
332 if (!(ch & Rx_CH_AV))
333 break;
334 } 317 }
335 318 return tty;
336 tty_flip_buffer_push(tty);
337} 319}
338 320
339static void ip22zilog_status_handle(struct uart_ip22zilog_port *up, 321static void ip22zilog_status_handle(struct uart_ip22zilog_port *up,
@@ -348,6 +330,15 @@ static void ip22zilog_status_handle(struct uart_ip22zilog_port *up,
348 ZSDELAY(); 330 ZSDELAY();
349 ZS_WSYNC(channel); 331 ZS_WSYNC(channel);
350 332
333 if (up->curregs[R15] & BRKIE) {
334 if ((status & BRK_ABRT) && !(up->prev_status & BRK_ABRT)) {
335 if (uart_handle_break(&up->port))
336 up->tty_break = Rx_SYS;
337 else
338 up->tty_break = Rx_BRK;
339 }
340 }
341
351 if (ZS_WANTS_MODEM_STATUS(up)) { 342 if (ZS_WANTS_MODEM_STATUS(up)) {
352 if (status & SYNC) 343 if (status & SYNC)
353 up->port.icount.dsr++; 344 up->port.icount.dsr++;
@@ -356,10 +347,10 @@ static void ip22zilog_status_handle(struct uart_ip22zilog_port *up,
356 * But it does not tell us which bit has changed, we have to keep 347 * But it does not tell us which bit has changed, we have to keep
357 * track of this ourselves. 348 * track of this ourselves.
358 */ 349 */
359 if ((status & DCD) ^ up->prev_status) 350 if ((status ^ up->prev_status) ^ DCD)
360 uart_handle_dcd_change(&up->port, 351 uart_handle_dcd_change(&up->port,
361 (status & DCD)); 352 (status & DCD));
362 if ((status & CTS) ^ up->prev_status) 353 if ((status ^ up->prev_status) ^ CTS)
363 uart_handle_cts_change(&up->port, 354 uart_handle_cts_change(&up->port,
364 (status & CTS)); 355 (status & CTS));
365 356
@@ -447,19 +438,21 @@ static irqreturn_t ip22zilog_interrupt(int irq, void *dev_id)
447 while (up) { 438 while (up) {
448 struct zilog_channel *channel 439 struct zilog_channel *channel
449 = ZILOG_CHANNEL_FROM_PORT(&up->port); 440 = ZILOG_CHANNEL_FROM_PORT(&up->port);
441 struct tty_struct *tty;
450 unsigned char r3; 442 unsigned char r3;
451 443
452 spin_lock(&up->port.lock); 444 spin_lock(&up->port.lock);
453 r3 = read_zsreg(channel, R3); 445 r3 = read_zsreg(channel, R3);
454 446
455 /* Channel A */ 447 /* Channel A */
448 tty = NULL;
456 if (r3 & (CHAEXT | CHATxIP | CHARxIP)) { 449 if (r3 & (CHAEXT | CHATxIP | CHARxIP)) {
457 writeb(RES_H_IUS, &channel->control); 450 writeb(RES_H_IUS, &channel->control);
458 ZSDELAY(); 451 ZSDELAY();
459 ZS_WSYNC(channel); 452 ZS_WSYNC(channel);
460 453
461 if (r3 & CHARxIP) 454 if (r3 & CHARxIP)
462 ip22zilog_receive_chars(up, channel); 455 tty = ip22zilog_receive_chars(up, channel);
463 if (r3 & CHAEXT) 456 if (r3 & CHAEXT)
464 ip22zilog_status_handle(up, channel); 457 ip22zilog_status_handle(up, channel);
465 if (r3 & CHATxIP) 458 if (r3 & CHATxIP)
@@ -467,18 +460,22 @@ static irqreturn_t ip22zilog_interrupt(int irq, void *dev_id)
467 } 460 }
468 spin_unlock(&up->port.lock); 461 spin_unlock(&up->port.lock);
469 462
463 if (tty)
464 tty_flip_buffer_push(tty);
465
470 /* Channel B */ 466 /* Channel B */
471 up = up->next; 467 up = up->next;
472 channel = ZILOG_CHANNEL_FROM_PORT(&up->port); 468 channel = ZILOG_CHANNEL_FROM_PORT(&up->port);
473 469
474 spin_lock(&up->port.lock); 470 spin_lock(&up->port.lock);
471 tty = NULL;
475 if (r3 & (CHBEXT | CHBTxIP | CHBRxIP)) { 472 if (r3 & (CHBEXT | CHBTxIP | CHBRxIP)) {
476 writeb(RES_H_IUS, &channel->control); 473 writeb(RES_H_IUS, &channel->control);
477 ZSDELAY(); 474 ZSDELAY();
478 ZS_WSYNC(channel); 475 ZS_WSYNC(channel);
479 476
480 if (r3 & CHBRxIP) 477 if (r3 & CHBRxIP)
481 ip22zilog_receive_chars(up, channel); 478 tty = ip22zilog_receive_chars(up, channel);
482 if (r3 & CHBEXT) 479 if (r3 & CHBEXT)
483 ip22zilog_status_handle(up, channel); 480 ip22zilog_status_handle(up, channel);
484 if (r3 & CHBTxIP) 481 if (r3 & CHBTxIP)
@@ -486,6 +483,9 @@ static irqreturn_t ip22zilog_interrupt(int irq, void *dev_id)
486 } 483 }
487 spin_unlock(&up->port.lock); 484 spin_unlock(&up->port.lock);
488 485
486 if (tty)
487 tty_flip_buffer_push(tty);
488
489 up = up->next; 489 up = up->next;
490 } 490 }
491 491
@@ -681,11 +681,46 @@ static void ip22zilog_break_ctl(struct uart_port *port, int break_state)
681 spin_unlock_irqrestore(&port->lock, flags); 681 spin_unlock_irqrestore(&port->lock, flags);
682} 682}
683 683
684static void __ip22zilog_reset(struct uart_ip22zilog_port *up)
685{
686 struct zilog_channel *channel;
687 int i;
688
689 if (up->flags & IP22ZILOG_FLAG_RESET_DONE)
690 return;
691
692 /* Let pending transmits finish. */
693 channel = ZILOG_CHANNEL_FROM_PORT(&up->port);
694 for (i = 0; i < 1000; i++) {
695 unsigned char stat = read_zsreg(channel, R1);
696 if (stat & ALL_SNT)
697 break;
698 udelay(100);
699 }
700
701 if (!ZS_IS_CHANNEL_A(up)) {
702 up++;
703 channel = ZILOG_CHANNEL_FROM_PORT(&up->port);
704 }
705 write_zsreg(channel, R9, FHWRES);
706 ZSDELAY_LONG();
707 (void) read_zsreg(channel, R0);
708
709 up->flags |= IP22ZILOG_FLAG_RESET_DONE;
710 up->next->flags |= IP22ZILOG_FLAG_RESET_DONE;
711}
712
684static void __ip22zilog_startup(struct uart_ip22zilog_port *up) 713static void __ip22zilog_startup(struct uart_ip22zilog_port *up)
685{ 714{
686 struct zilog_channel *channel; 715 struct zilog_channel *channel;
687 716
688 channel = ZILOG_CHANNEL_FROM_PORT(&up->port); 717 channel = ZILOG_CHANNEL_FROM_PORT(&up->port);
718
719 __ip22zilog_reset(up);
720
721 __load_zsregs(channel, up->curregs);
722 /* set master interrupt enable */
723 write_zsreg(channel, R9, up->curregs[R9]);
689 up->prev_status = readb(&channel->control); 724 up->prev_status = readb(&channel->control);
690 725
691 /* Enable receiver and transmitter. */ 726 /* Enable receiver and transmitter. */
@@ -859,8 +894,6 @@ ip22zilog_set_termios(struct uart_port *port, struct ktermios *termios,
859 else 894 else
860 up->flags &= ~IP22ZILOG_FLAG_MODEM_STATUS; 895 up->flags &= ~IP22ZILOG_FLAG_MODEM_STATUS;
861 896
862 up->cflag = termios->c_cflag;
863
864 ip22zilog_maybe_update_regs(up, ZILOG_CHANNEL_FROM_PORT(port)); 897 ip22zilog_maybe_update_regs(up, ZILOG_CHANNEL_FROM_PORT(port));
865 uart_update_timeout(port, termios->c_cflag, baud); 898 uart_update_timeout(port, termios->c_cflag, baud);
866 899
@@ -992,74 +1025,29 @@ ip22zilog_console_write(struct console *con, const char *s, unsigned int count)
992 spin_unlock_irqrestore(&up->port.lock, flags); 1025 spin_unlock_irqrestore(&up->port.lock, flags);
993} 1026}
994 1027
995void
996ip22serial_console_termios(struct console *con, char *options)
997{
998 int baud = 9600, bits = 8, cflag;
999 int parity = 'n';
1000 int flow = 'n';
1001
1002 if (options)
1003 uart_parse_options(options, &baud, &parity, &bits, &flow);
1004
1005 cflag = CREAD | HUPCL | CLOCAL;
1006
1007 switch (baud) {
1008 case 150: cflag |= B150; break;
1009 case 300: cflag |= B300; break;
1010 case 600: cflag |= B600; break;
1011 case 1200: cflag |= B1200; break;
1012 case 2400: cflag |= B2400; break;
1013 case 4800: cflag |= B4800; break;
1014 case 9600: cflag |= B9600; break;
1015 case 19200: cflag |= B19200; break;
1016 case 38400: cflag |= B38400; break;
1017 default: baud = 9600; cflag |= B9600; break;
1018 }
1019
1020 con->cflag = cflag | CS8; /* 8N1 */
1021
1022 uart_update_timeout(&ip22zilog_port_table[con->index].port, cflag, baud);
1023}
1024
1025static int __init ip22zilog_console_setup(struct console *con, char *options) 1028static int __init ip22zilog_console_setup(struct console *con, char *options)
1026{ 1029{
1027 struct uart_ip22zilog_port *up = &ip22zilog_port_table[con->index]; 1030 struct uart_ip22zilog_port *up = &ip22zilog_port_table[con->index];
1028 unsigned long flags; 1031 unsigned long flags;
1029 int baud, brg; 1032 int baud = 9600, bits = 8;
1030 1033 int parity = 'n';
1031 printk("Console: ttyS%d (IP22-Zilog)\n", con->index); 1034 int flow = 'n';
1032 1035
1033 /* Get firmware console settings. */ 1036 up->flags |= IP22ZILOG_FLAG_IS_CONS;
1034 ip22serial_console_termios(con, options);
1035 1037
1036 /* Firmware console speed is limited to 150-->38400 baud so 1038 printk(KERN_INFO "Console: ttyS%d (IP22-Zilog)\n", con->index);
1037 * this hackish cflag thing is OK.
1038 */
1039 switch (con->cflag & CBAUD) {
1040 case B150: baud = 150; break;
1041 case B300: baud = 300; break;
1042 case B600: baud = 600; break;
1043 case B1200: baud = 1200; break;
1044 case B2400: baud = 2400; break;
1045 case B4800: baud = 4800; break;
1046 default: case B9600: baud = 9600; break;
1047 case B19200: baud = 19200; break;
1048 case B38400: baud = 38400; break;
1049 };
1050
1051 brg = BPS_TO_BRG(baud, ZS_CLOCK / ZS_CLOCK_DIVISOR);
1052 1039
1053 spin_lock_irqsave(&up->port.lock, flags); 1040 spin_lock_irqsave(&up->port.lock, flags);
1054 1041
1055 up->curregs[R15] = BRKIE; 1042 up->curregs[R15] |= BRKIE;
1056 ip22zilog_convert_to_zs(up, con->cflag, 0, brg);
1057 1043
1058 __ip22zilog_startup(up); 1044 __ip22zilog_startup(up);
1059 1045
1060 spin_unlock_irqrestore(&up->port.lock, flags); 1046 spin_unlock_irqrestore(&up->port.lock, flags);
1061 1047
1062 return 0; 1048 if (options)
1049 uart_parse_options(options, &baud, &parity, &bits, &flow);
1050 return uart_set_options(&up->port, con, baud, parity, bits, flow);
1063} 1051}
1064 1052
1065static struct uart_driver ip22zilog_reg; 1053static struct uart_driver ip22zilog_reg;
@@ -1140,25 +1128,10 @@ static void __init ip22zilog_prepare(void)
1140 up[(chip * 2) + 1].port.line = (chip * 2) + 1; 1128 up[(chip * 2) + 1].port.line = (chip * 2) + 1;
1141 up[(chip * 2) + 1].flags |= IP22ZILOG_FLAG_IS_CHANNEL_A; 1129 up[(chip * 2) + 1].flags |= IP22ZILOG_FLAG_IS_CHANNEL_A;
1142 } 1130 }
1143}
1144
1145static void __init ip22zilog_init_hw(void)
1146{
1147 int i;
1148
1149 for (i = 0; i < NUM_CHANNELS; i++) {
1150 struct uart_ip22zilog_port *up = &ip22zilog_port_table[i];
1151 struct zilog_channel *channel = ZILOG_CHANNEL_FROM_PORT(&up->port);
1152 unsigned long flags;
1153 int baud, brg;
1154 1131
1155 spin_lock_irqsave(&up->port.lock, flags); 1132 for (channel = 0; channel < NUM_CHANNELS; channel++) {
1156 1133 struct uart_ip22zilog_port *up = &ip22zilog_port_table[channel];
1157 if (ZS_IS_CHANNEL_A(up)) { 1134 int brg;
1158 write_zsreg(channel, R9, FHWRES);
1159 ZSDELAY_LONG();
1160 (void) read_zsreg(channel, R0);
1161 }
1162 1135
1163 /* Normal serial TTY. */ 1136 /* Normal serial TTY. */
1164 up->parity_mask = 0xff; 1137 up->parity_mask = 0xff;
@@ -1169,16 +1142,10 @@ static void __init ip22zilog_init_hw(void)
1169 up->curregs[R9] = NV | MIE; 1142 up->curregs[R9] = NV | MIE;
1170 up->curregs[R10] = NRZ; 1143 up->curregs[R10] = NRZ;
1171 up->curregs[R11] = TCBR | RCBR; 1144 up->curregs[R11] = TCBR | RCBR;
1172 baud = 9600; 1145 brg = BPS_TO_BRG(9600, ZS_CLOCK / ZS_CLOCK_DIVISOR);
1173 brg = BPS_TO_BRG(baud, ZS_CLOCK / ZS_CLOCK_DIVISOR);
1174 up->curregs[R12] = (brg & 0xff); 1146 up->curregs[R12] = (brg & 0xff);
1175 up->curregs[R13] = (brg >> 8) & 0xff; 1147 up->curregs[R13] = (brg >> 8) & 0xff;
1176 up->curregs[R14] = BRENAB; 1148 up->curregs[R14] = BRENAB;
1177 __load_zsregs(channel, up->curregs);
1178 /* set master interrupt enable */
1179 write_zsreg(channel, R9, up->curregs[R9]);
1180
1181 spin_unlock_irqrestore(&up->port.lock, flags);
1182 } 1149 }
1183} 1150}
1184 1151
@@ -1195,8 +1162,6 @@ static int __init ip22zilog_ports_init(void)
1195 panic("IP22-Zilog: Unable to register zs interrupt handler.\n"); 1162 panic("IP22-Zilog: Unable to register zs interrupt handler.\n");
1196 } 1163 }
1197 1164
1198 ip22zilog_init_hw();
1199
1200 ret = uart_register_driver(&ip22zilog_reg); 1165 ret = uart_register_driver(&ip22zilog_reg);
1201 if (ret == 0) { 1166 if (ret == 0) {
1202 int i; 1167 int i;
diff --git a/drivers/serial/pxa.c b/drivers/serial/pxa.c
index af3a011b2b24..352fcb8926a6 100644
--- a/drivers/serial/pxa.c
+++ b/drivers/serial/pxa.c
@@ -585,11 +585,11 @@ serial_pxa_type(struct uart_port *port)
585 return up->name; 585 return up->name;
586} 586}
587 587
588#ifdef CONFIG_SERIAL_PXA_CONSOLE
589
590static struct uart_pxa_port *serial_pxa_ports[4]; 588static struct uart_pxa_port *serial_pxa_ports[4];
591static struct uart_driver serial_pxa_reg; 589static struct uart_driver serial_pxa_reg;
592 590
591#ifdef CONFIG_SERIAL_PXA_CONSOLE
592
593#define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE) 593#define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE)
594 594
595/* 595/*
diff --git a/drivers/serial/suncore.c b/drivers/serial/suncore.c
index 70a09a3d5af0..707c5b03bce9 100644
--- a/drivers/serial/suncore.c
+++ b/drivers/serial/suncore.c
@@ -23,11 +23,36 @@
23 23
24#include "suncore.h" 24#include "suncore.h"
25 25
26int sunserial_current_minor = 64; 26static int sunserial_current_minor = 64;
27 27
28EXPORT_SYMBOL(sunserial_current_minor); 28int sunserial_register_minors(struct uart_driver *drv, int count)
29{
30 int err = 0;
31
32 drv->minor = sunserial_current_minor;
33 drv->nr += count;
34 /* Register the driver on the first call */
35 if (drv->nr == count)
36 err = uart_register_driver(drv);
37 if (err == 0) {
38 sunserial_current_minor += count;
39 drv->tty_driver->name_base = drv->minor - 64;
40 }
41 return err;
42}
43EXPORT_SYMBOL(sunserial_register_minors);
44
45void sunserial_unregister_minors(struct uart_driver *drv, int count)
46{
47 drv->nr -= count;
48 sunserial_current_minor -= count;
49
50 if (drv->nr == 0)
51 uart_unregister_driver(drv);
52}
53EXPORT_SYMBOL(sunserial_unregister_minors);
29 54
30int sunserial_console_match(struct console *con, struct device_node *dp, 55int __init sunserial_console_match(struct console *con, struct device_node *dp,
31 struct uart_driver *drv, int line) 56 struct uart_driver *drv, int line)
32{ 57{
33 int off; 58 int off;
@@ -133,8 +158,6 @@ sunserial_console_termios(struct console *con)
133 con->cflag = cflag; 158 con->cflag = cflag;
134} 159}
135 160
136EXPORT_SYMBOL(sunserial_console_termios);
137
138/* Sun serial MOUSE auto baud rate detection. */ 161/* Sun serial MOUSE auto baud rate detection. */
139static struct mouse_baud_cflag { 162static struct mouse_baud_cflag {
140 int baud; 163 int baud;
diff --git a/drivers/serial/suncore.h b/drivers/serial/suncore.h
index 829d7d65d6db..042668aa602e 100644
--- a/drivers/serial/suncore.h
+++ b/drivers/serial/suncore.h
@@ -22,7 +22,8 @@
22extern unsigned int suncore_mouse_baud_cflag_next(unsigned int, int *); 22extern unsigned int suncore_mouse_baud_cflag_next(unsigned int, int *);
23extern int suncore_mouse_baud_detection(unsigned char, int); 23extern int suncore_mouse_baud_detection(unsigned char, int);
24 24
25extern int sunserial_current_minor; 25extern int sunserial_register_minors(struct uart_driver *, int);
26extern void sunserial_unregister_minors(struct uart_driver *, int);
26 27
27extern int sunserial_console_match(struct console *, struct device_node *, 28extern int sunserial_console_match(struct console *, struct device_node *,
28 struct uart_driver *, int); 29 struct uart_driver *, int);
diff --git a/drivers/serial/sunhv.c b/drivers/serial/sunhv.c
index 8ff900b09811..be0fe152891b 100644
--- a/drivers/serial/sunhv.c
+++ b/drivers/serial/sunhv.c
@@ -562,16 +562,10 @@ static int __devinit hv_probe(struct of_device *op, const struct of_device_id *m
562 562
563 port->dev = &op->dev; 563 port->dev = &op->dev;
564 564
565 sunhv_reg.minor = sunserial_current_minor; 565 err = sunserial_register_minors(&sunhv_reg, 1);
566 sunhv_reg.nr = 1;
567
568 err = uart_register_driver(&sunhv_reg);
569 if (err) 566 if (err)
570 goto out_free_con_read_page; 567 goto out_free_con_read_page;
571 568
572 sunhv_reg.tty_driver->name_base = sunhv_reg.minor - 64;
573 sunserial_current_minor += 1;
574
575 sunserial_console_match(&sunhv_console, op->node, 569 sunserial_console_match(&sunhv_console, op->node,
576 &sunhv_reg, port->line); 570 &sunhv_reg, port->line);
577 571
@@ -591,8 +585,7 @@ out_remove_port:
591 uart_remove_one_port(&sunhv_reg, port); 585 uart_remove_one_port(&sunhv_reg, port);
592 586
593out_unregister_driver: 587out_unregister_driver:
594 sunserial_current_minor -= 1; 588 sunserial_unregister_minors(&sunhv_reg, 1);
595 uart_unregister_driver(&sunhv_reg);
596 589
597out_free_con_read_page: 590out_free_con_read_page:
598 kfree(con_read_page); 591 kfree(con_read_page);
@@ -614,8 +607,7 @@ static int __devexit hv_remove(struct of_device *dev)
614 607
615 uart_remove_one_port(&sunhv_reg, port); 608 uart_remove_one_port(&sunhv_reg, port);
616 609
617 sunserial_current_minor -= 1; 610 sunserial_unregister_minors(&sunhv_reg, 1);
618 uart_unregister_driver(&sunhv_reg);
619 611
620 kfree(port); 612 kfree(port);
621 sunhv_port = NULL; 613 sunhv_port = NULL;
diff --git a/drivers/serial/sunsab.c b/drivers/serial/sunsab.c
index ff610c23314b..543f93741e6f 100644
--- a/drivers/serial/sunsab.c
+++ b/drivers/serial/sunsab.c
@@ -832,7 +832,6 @@ static struct uart_driver sunsab_reg = {
832}; 832};
833 833
834static struct uart_sunsab_port *sunsab_ports; 834static struct uart_sunsab_port *sunsab_ports;
835static int num_channels;
836 835
837#ifdef CONFIG_SERIAL_SUNSAB_CONSOLE 836#ifdef CONFIG_SERIAL_SUNSAB_CONSOLE
838 837
@@ -1102,8 +1101,8 @@ static int __init sunsab_init(void)
1102{ 1101{
1103 struct device_node *dp; 1102 struct device_node *dp;
1104 int err; 1103 int err;
1104 int num_channels = 0;
1105 1105
1106 num_channels = 0;
1107 for_each_node_by_name(dp, "se") 1106 for_each_node_by_name(dp, "se")
1108 num_channels += 2; 1107 num_channels += 2;
1109 for_each_node_by_name(dp, "serial") { 1108 for_each_node_by_name(dp, "serial") {
@@ -1117,20 +1116,14 @@ static int __init sunsab_init(void)
1117 if (!sunsab_ports) 1116 if (!sunsab_ports)
1118 return -ENOMEM; 1117 return -ENOMEM;
1119 1118
1120 sunsab_reg.minor = sunserial_current_minor;
1121 sunsab_reg.nr = num_channels;
1122 sunsab_reg.cons = SUNSAB_CONSOLE(); 1119 sunsab_reg.cons = SUNSAB_CONSOLE();
1123 1120 err = sunserial_register_minors(&sunsab_reg, num_channels);
1124 err = uart_register_driver(&sunsab_reg);
1125 if (err) { 1121 if (err) {
1126 kfree(sunsab_ports); 1122 kfree(sunsab_ports);
1127 sunsab_ports = NULL; 1123 sunsab_ports = NULL;
1128 1124
1129 return err; 1125 return err;
1130 } 1126 }
1131
1132 sunsab_reg.tty_driver->name_base = sunsab_reg.minor - 64;
1133 sunserial_current_minor += num_channels;
1134 } 1127 }
1135 1128
1136 return of_register_driver(&sab_driver, &of_bus_type); 1129 return of_register_driver(&sab_driver, &of_bus_type);
@@ -1139,9 +1132,8 @@ static int __init sunsab_init(void)
1139static void __exit sunsab_exit(void) 1132static void __exit sunsab_exit(void)
1140{ 1133{
1141 of_unregister_driver(&sab_driver); 1134 of_unregister_driver(&sab_driver);
1142 if (num_channels) { 1135 if (sunsab_reg.nr) {
1143 sunserial_current_minor -= num_channels; 1136 sunserial_unregister_minors(&sunsab_reg, sunsab_reg.nr);
1144 uart_unregister_driver(&sunsab_reg);
1145 } 1137 }
1146 1138
1147 kfree(sunsab_ports); 1139 kfree(sunsab_ports);
diff --git a/drivers/serial/sunsu.c b/drivers/serial/sunsu.c
index e074943feff5..4e2302d43ab1 100644
--- a/drivers/serial/sunsu.c
+++ b/drivers/serial/sunsu.c
@@ -1528,14 +1528,12 @@ static struct of_platform_driver su_driver = {
1528 .remove = __devexit_p(su_remove), 1528 .remove = __devexit_p(su_remove),
1529}; 1529};
1530 1530
1531static int num_uart;
1532
1533static int __init sunsu_init(void) 1531static int __init sunsu_init(void)
1534{ 1532{
1535 struct device_node *dp; 1533 struct device_node *dp;
1536 int err; 1534 int err;
1535 int num_uart = 0;
1537 1536
1538 num_uart = 0;
1539 for_each_node_by_name(dp, "su") { 1537 for_each_node_by_name(dp, "su") {
1540 if (su_get_type(dp) == SU_PORT_PORT) 1538 if (su_get_type(dp) == SU_PORT_PORT)
1541 num_uart++; 1539 num_uart++;
@@ -1552,26 +1550,22 @@ static int __init sunsu_init(void)
1552 } 1550 }
1553 1551
1554 if (num_uart) { 1552 if (num_uart) {
1555 sunsu_reg.minor = sunserial_current_minor; 1553 err = sunserial_register_minors(&sunsu_reg, num_uart);
1556 sunsu_reg.nr = num_uart;
1557 err = uart_register_driver(&sunsu_reg);
1558 if (err) 1554 if (err)
1559 return err; 1555 return err;
1560 sunsu_reg.tty_driver->name_base = sunsu_reg.minor - 64;
1561 sunserial_current_minor += num_uart;
1562 } 1556 }
1563 1557
1564 err = of_register_driver(&su_driver, &of_bus_type); 1558 err = of_register_driver(&su_driver, &of_bus_type);
1565 if (err && num_uart) 1559 if (err && num_uart)
1566 uart_unregister_driver(&sunsu_reg); 1560 sunserial_unregister_minors(&sunsu_reg, num_uart);
1567 1561
1568 return err; 1562 return err;
1569} 1563}
1570 1564
1571static void __exit sunsu_exit(void) 1565static void __exit sunsu_exit(void)
1572{ 1566{
1573 if (num_uart) 1567 if (sunsu_reg.nr)
1574 uart_unregister_driver(&sunsu_reg); 1568 sunserial_unregister_minors(&sunsu_reg, sunsu_reg.nr);
1575} 1569}
1576 1570
1577module_init(sunsu_init); 1571module_init(sunsu_init);
diff --git a/drivers/serial/sunzilog.c b/drivers/serial/sunzilog.c
index 283bef0d24cb..cb2e40506379 100644
--- a/drivers/serial/sunzilog.c
+++ b/drivers/serial/sunzilog.c
@@ -63,10 +63,6 @@
63 readb(&((__channel)->control)) 63 readb(&((__channel)->control))
64#endif 64#endif
65 65
66static int num_sunzilog;
67#define NUM_SUNZILOG num_sunzilog
68#define NUM_CHANNELS (NUM_SUNZILOG * 2)
69
70#define ZS_CLOCK 4915200 /* Zilog input clock rate. */ 66#define ZS_CLOCK 4915200 /* Zilog input clock rate. */
71#define ZS_CLOCK_DIVISOR 16 /* Divisor this driver uses. */ 67#define ZS_CLOCK_DIVISOR 16 /* Divisor this driver uses. */
72 68
@@ -1031,18 +1027,19 @@ static struct uart_driver sunzilog_reg = {
1031 .major = TTY_MAJOR, 1027 .major = TTY_MAJOR,
1032}; 1028};
1033 1029
1034static int __init sunzilog_alloc_tables(void) 1030static int __init sunzilog_alloc_tables(int num_sunzilog)
1035{ 1031{
1036 struct uart_sunzilog_port *up; 1032 struct uart_sunzilog_port *up;
1037 unsigned long size; 1033 unsigned long size;
1034 int num_channels = num_sunzilog * 2;
1038 int i; 1035 int i;
1039 1036
1040 size = NUM_CHANNELS * sizeof(struct uart_sunzilog_port); 1037 size = num_channels * sizeof(struct uart_sunzilog_port);
1041 sunzilog_port_table = kzalloc(size, GFP_KERNEL); 1038 sunzilog_port_table = kzalloc(size, GFP_KERNEL);
1042 if (!sunzilog_port_table) 1039 if (!sunzilog_port_table)
1043 return -ENOMEM; 1040 return -ENOMEM;
1044 1041
1045 for (i = 0; i < NUM_CHANNELS; i++) { 1042 for (i = 0; i < num_channels; i++) {
1046 up = &sunzilog_port_table[i]; 1043 up = &sunzilog_port_table[i];
1047 1044
1048 spin_lock_init(&up->port.lock); 1045 spin_lock_init(&up->port.lock);
@@ -1050,13 +1047,13 @@ static int __init sunzilog_alloc_tables(void)
1050 if (i == 0) 1047 if (i == 0)
1051 sunzilog_irq_chain = up; 1048 sunzilog_irq_chain = up;
1052 1049
1053 if (i < NUM_CHANNELS - 1) 1050 if (i < num_channels - 1)
1054 up->next = up + 1; 1051 up->next = up + 1;
1055 else 1052 else
1056 up->next = NULL; 1053 up->next = NULL;
1057 } 1054 }
1058 1055
1059 size = NUM_SUNZILOG * sizeof(struct zilog_layout __iomem *); 1056 size = num_sunzilog * sizeof(struct zilog_layout __iomem *);
1060 sunzilog_chip_regs = kzalloc(size, GFP_KERNEL); 1057 sunzilog_chip_regs = kzalloc(size, GFP_KERNEL);
1061 if (!sunzilog_chip_regs) { 1058 if (!sunzilog_chip_regs) {
1062 kfree(sunzilog_port_table); 1059 kfree(sunzilog_port_table);
@@ -1496,34 +1493,28 @@ static int __init sunzilog_init(void)
1496 struct device_node *dp; 1493 struct device_node *dp;
1497 int err, uart_count; 1494 int err, uart_count;
1498 int num_keybms; 1495 int num_keybms;
1496 int num_sunzilog = 0;
1499 1497
1500 NUM_SUNZILOG = 0;
1501 num_keybms = 0; 1498 num_keybms = 0;
1502 for_each_node_by_name(dp, "zs") { 1499 for_each_node_by_name(dp, "zs") {
1503 NUM_SUNZILOG++; 1500 num_sunzilog++;
1504 if (of_find_property(dp, "keyboard", NULL)) 1501 if (of_find_property(dp, "keyboard", NULL))
1505 num_keybms++; 1502 num_keybms++;
1506 } 1503 }
1507 1504
1508 uart_count = 0; 1505 uart_count = 0;
1509 if (NUM_SUNZILOG) { 1506 if (num_sunzilog) {
1510 int uart_count; 1507 int uart_count;
1511 1508
1512 err = sunzilog_alloc_tables(); 1509 err = sunzilog_alloc_tables(num_sunzilog);
1513 if (err) 1510 if (err)
1514 goto out; 1511 goto out;
1515 1512
1516 uart_count = (NUM_SUNZILOG * 2) - (2 * num_keybms); 1513 uart_count = (num_sunzilog * 2) - (2 * num_keybms);
1517 1514
1518 sunzilog_reg.nr = uart_count; 1515 err = sunserial_register_minors(&sunzilog_reg, uart_count);
1519 sunzilog_reg.minor = sunserial_current_minor;
1520 err = uart_register_driver(&sunzilog_reg);
1521 if (err) 1516 if (err)
1522 goto out_free_tables; 1517 goto out_free_tables;
1523
1524 sunzilog_reg.tty_driver->name_base = sunzilog_reg.minor - 64;
1525
1526 sunserial_current_minor += uart_count;
1527 } 1518 }
1528 1519
1529 err = of_register_driver(&zs_driver, &of_bus_type); 1520 err = of_register_driver(&zs_driver, &of_bus_type);
@@ -1557,8 +1548,8 @@ out_unregister_driver:
1557 of_unregister_driver(&zs_driver); 1548 of_unregister_driver(&zs_driver);
1558 1549
1559out_unregister_uart: 1550out_unregister_uart:
1560 if (NUM_SUNZILOG) { 1551 if (num_sunzilog) {
1561 uart_unregister_driver(&sunzilog_reg); 1552 sunserial_unregister_minors(&sunzilog_reg, num_sunzilog);
1562 sunzilog_reg.cons = NULL; 1553 sunzilog_reg.cons = NULL;
1563 } 1554 }
1564 1555
@@ -1590,8 +1581,8 @@ static void __exit sunzilog_exit(void)
1590 zilog_irq = -1; 1581 zilog_irq = -1;
1591 } 1582 }
1592 1583
1593 if (NUM_SUNZILOG) { 1584 if (sunzilog_reg.nr) {
1594 uart_unregister_driver(&sunzilog_reg); 1585 sunserial_unregister_minors(&sunzilog_reg, sunzilog_reg.nr);
1595 sunzilog_free_tables(); 1586 sunzilog_free_tables();
1596 } 1587 }
1597} 1588}
diff --git a/drivers/serial/uartlite.c b/drivers/serial/uartlite.c
index a85f2d31a686..3f593247c41e 100644
--- a/drivers/serial/uartlite.c
+++ b/drivers/serial/uartlite.c
@@ -393,6 +393,7 @@ static inline void __init ulite_console_of_find_device(int id)
393 continue; 393 continue;
394 394
395 ulite_ports[id].mapbase = res.start; 395 ulite_ports[id].mapbase = res.start;
396 of_node_put(np);
396 return; 397 return;
397 } 398 }
398} 399}
diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig
index a77ede598d34..abf05048c638 100644
--- a/drivers/spi/Kconfig
+++ b/drivers/spi/Kconfig
@@ -61,7 +61,7 @@ config SPI_ATMEL
61 61
62config SPI_BFIN 62config SPI_BFIN
63 tristate "SPI controller driver for ADI Blackfin5xx" 63 tristate "SPI controller driver for ADI Blackfin5xx"
64 depends on SPI_MASTER && BFIN 64 depends on SPI_MASTER && BLACKFIN
65 help 65 help
66 This is the SPI controller master driver for Blackfin 5xx processor. 66 This is the SPI controller master driver for Blackfin 5xx processor.
67 67
diff --git a/drivers/spi/at25.c b/drivers/spi/at25.c
index e007833cca59..290dbe99647a 100644
--- a/drivers/spi/at25.c
+++ b/drivers/spi/at25.c
@@ -21,6 +21,13 @@
21#include <linux/spi/eeprom.h> 21#include <linux/spi/eeprom.h>
22 22
23 23
24/*
25 * NOTE: this is an *EEPROM* driver. The vagaries of product naming
26 * mean that some AT25 products are EEPROMs, and others are FLASH.
27 * Handle FLASH chips with the drivers/mtd/devices/m25p80.c driver,
28 * not this one!
29 */
30
24struct at25_data { 31struct at25_data {
25 struct spi_device *spi; 32 struct spi_device *spi;
26 struct mutex lock; 33 struct mutex lock;
diff --git a/drivers/spi/atmel_spi.c b/drivers/spi/atmel_spi.c
index 0d342dcdd302..ff10808183a3 100644
--- a/drivers/spi/atmel_spi.c
+++ b/drivers/spi/atmel_spi.c
@@ -195,8 +195,8 @@ static void atmel_spi_next_xfer(struct spi_master *master,
195 xfer, xfer->len, xfer->tx_buf, xfer->tx_dma, 195 xfer, xfer->len, xfer->tx_buf, xfer->tx_dma,
196 xfer->rx_buf, xfer->rx_dma, spi_readl(as, IMR)); 196 xfer->rx_buf, xfer->rx_dma, spi_readl(as, IMR));
197 197
198 spi_writel(as, TCR, len);
199 spi_writel(as, RCR, len); 198 spi_writel(as, RCR, len);
199 spi_writel(as, TCR, len);
200 spi_writel(as, PTCR, SPI_BIT(TXTEN) | SPI_BIT(RXTEN)); 200 spi_writel(as, PTCR, SPI_BIT(TXTEN) | SPI_BIT(RXTEN));
201} 201}
202 202
@@ -497,7 +497,7 @@ static int atmel_spi_setup(struct spi_device *spi)
497 /* chipselect must have been muxed as GPIO (e.g. in board setup) */ 497 /* chipselect must have been muxed as GPIO (e.g. in board setup) */
498 npcs_pin = (unsigned int)spi->controller_data; 498 npcs_pin = (unsigned int)spi->controller_data;
499 if (!spi->controller_state) { 499 if (!spi->controller_state) {
500 ret = gpio_request(npcs_pin, "spi_npcs"); 500 ret = gpio_request(npcs_pin, spi->dev.bus_id);
501 if (ret) 501 if (ret)
502 return ret; 502 return ret;
503 spi->controller_state = (void *)npcs_pin; 503 spi->controller_state = (void *)npcs_pin;
diff --git a/drivers/spi/pxa2xx_spi.c b/drivers/spi/pxa2xx_spi.c
index 5f3d808cbc29..1c2ab541d37d 100644
--- a/drivers/spi/pxa2xx_spi.c
+++ b/drivers/spi/pxa2xx_spi.c
@@ -39,7 +39,7 @@
39#include <asm/arch/pxa2xx_spi.h> 39#include <asm/arch/pxa2xx_spi.h>
40 40
41MODULE_AUTHOR("Stephen Street"); 41MODULE_AUTHOR("Stephen Street");
42MODULE_DESCRIPTION("PXA2xx SSP SPI Contoller"); 42MODULE_DESCRIPTION("PXA2xx SSP SPI Controller");
43MODULE_LICENSE("GPL"); 43MODULE_LICENSE("GPL");
44 44
45#define MAX_BUSES 3 45#define MAX_BUSES 3
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index b31f4431849b..93e9de46977a 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -541,10 +541,7 @@ static void spi_complete(void *arg)
541 * Also, the caller is guaranteeing that the memory associated with the 541 * Also, the caller is guaranteeing that the memory associated with the
542 * message will not be freed before this call returns. 542 * message will not be freed before this call returns.
543 * 543 *
544 * The return value is a negative error code if the message could not be 544 * It returns zero on success, else a negative error code.
545 * submitted, else zero. When the value is zero, then message->status is
546 * also defined; it's the completion code for the transfer, either zero
547 * or a negative error code from the controller driver.
548 */ 545 */
549int spi_sync(struct spi_device *spi, struct spi_message *message) 546int spi_sync(struct spi_device *spi, struct spi_message *message)
550{ 547{
@@ -554,8 +551,10 @@ int spi_sync(struct spi_device *spi, struct spi_message *message)
554 message->complete = spi_complete; 551 message->complete = spi_complete;
555 message->context = &done; 552 message->context = &done;
556 status = spi_async(spi, message); 553 status = spi_async(spi, message);
557 if (status == 0) 554 if (status == 0) {
558 wait_for_completion(&done); 555 wait_for_completion(&done);
556 status = message->status;
557 }
559 message->context = NULL; 558 message->context = NULL;
560 return status; 559 return status;
561} 560}
@@ -589,7 +588,7 @@ int spi_write_then_read(struct spi_device *spi,
589 const u8 *txbuf, unsigned n_tx, 588 const u8 *txbuf, unsigned n_tx,
590 u8 *rxbuf, unsigned n_rx) 589 u8 *rxbuf, unsigned n_rx)
591{ 590{
592 static DECLARE_MUTEX(lock); 591 static DEFINE_MUTEX(lock);
593 592
594 int status; 593 int status;
595 struct spi_message message; 594 struct spi_message message;
@@ -615,7 +614,7 @@ int spi_write_then_read(struct spi_device *spi,
615 } 614 }
616 615
617 /* ... unless someone else is using the pre-allocated buffer */ 616 /* ... unless someone else is using the pre-allocated buffer */
618 if (down_trylock(&lock)) { 617 if (!mutex_trylock(&lock)) {
619 local_buf = kmalloc(SPI_BUFSIZ, GFP_KERNEL); 618 local_buf = kmalloc(SPI_BUFSIZ, GFP_KERNEL);
620 if (!local_buf) 619 if (!local_buf)
621 return -ENOMEM; 620 return -ENOMEM;
@@ -628,13 +627,11 @@ int spi_write_then_read(struct spi_device *spi,
628 627
629 /* do the i/o */ 628 /* do the i/o */
630 status = spi_sync(spi, &message); 629 status = spi_sync(spi, &message);
631 if (status == 0) { 630 if (status == 0)
632 memcpy(rxbuf, x[1].rx_buf, n_rx); 631 memcpy(rxbuf, x[1].rx_buf, n_rx);
633 status = message.status;
634 }
635 632
636 if (x[0].tx_buf == buf) 633 if (x[0].tx_buf == buf)
637 up(&lock); 634 mutex_unlock(&lock);
638 else 635 else
639 kfree(local_buf); 636 kfree(local_buf);
640 637
diff --git a/drivers/spi/spi_bfin5xx.c b/drivers/spi/spi_bfin5xx.c
index 2ef11bb70b2e..7ef39a6e8c06 100644
--- a/drivers/spi/spi_bfin5xx.c
+++ b/drivers/spi/spi_bfin5xx.c
@@ -1,17 +1,22 @@
1/* 1/*
2 * File: drivers/spi/bfin5xx_spi.c 2 * File: drivers/spi/bfin5xx_spi.c
3 * Based on: N/A 3 * Maintainer:
4 * Author: Luke Yang (Analog Devices Inc.) 4 * Bryan Wu <bryan.wu@analog.com>
5 * Original Author:
6 * Luke Yang (Analog Devices Inc.)
5 * 7 *
6 * Created: March. 10th 2006 8 * Created: March. 10th 2006
7 * Description: SPI controller driver for Blackfin 5xx 9 * Description: SPI controller driver for Blackfin BF5xx
8 * Bugs: Enter bugs at http://blackfin.uclinux.org/ 10 * Bugs: Enter bugs at http://blackfin.uclinux.org/
9 * 11 *
10 * Modified: 12 * Modified:
11 * March 10, 2006 bfin5xx_spi.c Created. (Luke Yang) 13 * March 10, 2006 bfin5xx_spi.c Created. (Luke Yang)
12 * August 7, 2006 added full duplex mode (Axel Weiss & Luke Yang) 14 * August 7, 2006 added full duplex mode (Axel Weiss & Luke Yang)
15 * July 17, 2007 add support for BF54x SPI0 controller (Bryan Wu)
16 * July 30, 2007 add platfrom_resource interface to support multi-port
17 * SPI controller (Bryan Wu)
13 * 18 *
14 * Copyright 2004-2006 Analog Devices Inc. 19 * Copyright 2004-2007 Analog Devices Inc.
15 * 20 *
16 * This program is free software ; you can redistribute it and/or modify 21 * This program is free software ; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by 22 * it under the terms of the GNU General Public License as published by
@@ -31,50 +36,39 @@
31 36
32#include <linux/init.h> 37#include <linux/init.h>
33#include <linux/module.h> 38#include <linux/module.h>
39#include <linux/delay.h>
34#include <linux/device.h> 40#include <linux/device.h>
41#include <linux/io.h>
35#include <linux/ioport.h> 42#include <linux/ioport.h>
43#include <linux/irq.h>
36#include <linux/errno.h> 44#include <linux/errno.h>
37#include <linux/interrupt.h> 45#include <linux/interrupt.h>
38#include <linux/platform_device.h> 46#include <linux/platform_device.h>
39#include <linux/dma-mapping.h> 47#include <linux/dma-mapping.h>
40#include <linux/spi/spi.h> 48#include <linux/spi/spi.h>
41#include <linux/workqueue.h> 49#include <linux/workqueue.h>
42#include <linux/delay.h>
43 50
44#include <asm/io.h>
45#include <asm/irq.h>
46#include <asm/delay.h>
47#include <asm/dma.h> 51#include <asm/dma.h>
48 52#include <asm/portmux.h>
49#include <asm/bfin5xx_spi.h> 53#include <asm/bfin5xx_spi.h>
50 54
51MODULE_AUTHOR("Luke Yang"); 55#define DRV_NAME "bfin-spi"
52MODULE_DESCRIPTION("Blackfin 5xx SPI Contoller"); 56#define DRV_AUTHOR "Bryan Wu, Luke Yang"
53MODULE_LICENSE("GPL"); 57#define DRV_DESC "Blackfin BF5xx on-chip SPI Controller Driver"
58#define DRV_VERSION "1.0"
54 59
55#define IS_DMA_ALIGNED(x) (((u32)(x)&0x07)==0) 60MODULE_AUTHOR(DRV_AUTHOR);
61MODULE_DESCRIPTION(DRV_DESC);
62MODULE_LICENSE("GPL");
56 63
57#define DEFINE_SPI_REG(reg, off) \ 64#define IS_DMA_ALIGNED(x) (((u32)(x)&0x07) == 0)
58static inline u16 read_##reg(void) \
59 { return *(volatile unsigned short*)(SPI0_REGBASE + off); } \
60static inline void write_##reg(u16 v) \
61 {*(volatile unsigned short*)(SPI0_REGBASE + off) = v;\
62 SSYNC();}
63 65
64DEFINE_SPI_REG(CTRL, 0x00) 66#define START_STATE ((void *)0)
65DEFINE_SPI_REG(FLAG, 0x04) 67#define RUNNING_STATE ((void *)1)
66DEFINE_SPI_REG(STAT, 0x08) 68#define DONE_STATE ((void *)2)
67DEFINE_SPI_REG(TDBR, 0x0C) 69#define ERROR_STATE ((void *)-1)
68DEFINE_SPI_REG(RDBR, 0x10) 70#define QUEUE_RUNNING 0
69DEFINE_SPI_REG(BAUD, 0x14) 71#define QUEUE_STOPPED 1
70DEFINE_SPI_REG(SHAW, 0x18)
71#define START_STATE ((void*)0)
72#define RUNNING_STATE ((void*)1)
73#define DONE_STATE ((void*)2)
74#define ERROR_STATE ((void*)-1)
75#define QUEUE_RUNNING 0
76#define QUEUE_STOPPED 1
77int dma_requested;
78 72
79struct driver_data { 73struct driver_data {
80 /* Driver model hookup */ 74 /* Driver model hookup */
@@ -83,6 +77,12 @@ struct driver_data {
83 /* SPI framework hookup */ 77 /* SPI framework hookup */
84 struct spi_master *master; 78 struct spi_master *master;
85 79
80 /* Regs base of SPI controller */
81 void __iomem *regs_base;
82
83 /* Pin request list */
84 u16 *pin_req;
85
86 /* BFIN hookup */ 86 /* BFIN hookup */
87 struct bfin5xx_spi_master *master_info; 87 struct bfin5xx_spi_master *master_info;
88 88
@@ -107,12 +107,18 @@ struct driver_data {
107 void *tx_end; 107 void *tx_end;
108 void *rx; 108 void *rx;
109 void *rx_end; 109 void *rx_end;
110
111 /* DMA stuffs */
112 int dma_channel;
110 int dma_mapped; 113 int dma_mapped;
114 int dma_requested;
111 dma_addr_t rx_dma; 115 dma_addr_t rx_dma;
112 dma_addr_t tx_dma; 116 dma_addr_t tx_dma;
117
113 size_t rx_map_len; 118 size_t rx_map_len;
114 size_t tx_map_len; 119 size_t tx_map_len;
115 u8 n_bytes; 120 u8 n_bytes;
121 int cs_change;
116 void (*write) (struct driver_data *); 122 void (*write) (struct driver_data *);
117 void (*read) (struct driver_data *); 123 void (*read) (struct driver_data *);
118 void (*duplex) (struct driver_data *); 124 void (*duplex) (struct driver_data *);
@@ -129,28 +135,40 @@ struct chip_data {
129 u8 enable_dma; 135 u8 enable_dma;
130 u8 bits_per_word; /* 8 or 16 */ 136 u8 bits_per_word; /* 8 or 16 */
131 u8 cs_change_per_word; 137 u8 cs_change_per_word;
132 u8 cs_chg_udelay; 138 u16 cs_chg_udelay; /* Some devices require > 255usec delay */
133 void (*write) (struct driver_data *); 139 void (*write) (struct driver_data *);
134 void (*read) (struct driver_data *); 140 void (*read) (struct driver_data *);
135 void (*duplex) (struct driver_data *); 141 void (*duplex) (struct driver_data *);
136}; 142};
137 143
144#define DEFINE_SPI_REG(reg, off) \
145static inline u16 read_##reg(struct driver_data *drv_data) \
146 { return bfin_read16(drv_data->regs_base + off); } \
147static inline void write_##reg(struct driver_data *drv_data, u16 v) \
148 { bfin_write16(drv_data->regs_base + off, v); }
149
150DEFINE_SPI_REG(CTRL, 0x00)
151DEFINE_SPI_REG(FLAG, 0x04)
152DEFINE_SPI_REG(STAT, 0x08)
153DEFINE_SPI_REG(TDBR, 0x0C)
154DEFINE_SPI_REG(RDBR, 0x10)
155DEFINE_SPI_REG(BAUD, 0x14)
156DEFINE_SPI_REG(SHAW, 0x18)
157
138static void bfin_spi_enable(struct driver_data *drv_data) 158static void bfin_spi_enable(struct driver_data *drv_data)
139{ 159{
140 u16 cr; 160 u16 cr;
141 161
142 cr = read_CTRL(); 162 cr = read_CTRL(drv_data);
143 write_CTRL(cr | BIT_CTL_ENABLE); 163 write_CTRL(drv_data, (cr | BIT_CTL_ENABLE));
144 SSYNC();
145} 164}
146 165
147static void bfin_spi_disable(struct driver_data *drv_data) 166static void bfin_spi_disable(struct driver_data *drv_data)
148{ 167{
149 u16 cr; 168 u16 cr;
150 169
151 cr = read_CTRL(); 170 cr = read_CTRL(drv_data);
152 write_CTRL(cr & (~BIT_CTL_ENABLE)); 171 write_CTRL(drv_data, (cr & (~BIT_CTL_ENABLE)));
153 SSYNC();
154} 172}
155 173
156/* Caculate the SPI_BAUD register value based on input HZ */ 174/* Caculate the SPI_BAUD register value based on input HZ */
@@ -170,83 +188,71 @@ static int flush(struct driver_data *drv_data)
170 unsigned long limit = loops_per_jiffy << 1; 188 unsigned long limit = loops_per_jiffy << 1;
171 189
172 /* wait for stop and clear stat */ 190 /* wait for stop and clear stat */
173 while (!(read_STAT() & BIT_STAT_SPIF) && limit--) 191 while (!(read_STAT(drv_data) & BIT_STAT_SPIF) && limit--)
174 continue; 192 cpu_relax();
175 193
176 write_STAT(BIT_STAT_CLR); 194 write_STAT(drv_data, BIT_STAT_CLR);
177 195
178 return limit; 196 return limit;
179} 197}
180 198
199/* Chip select operation functions for cs_change flag */
200static void cs_active(struct driver_data *drv_data, struct chip_data *chip)
201{
202 u16 flag = read_FLAG(drv_data);
203
204 flag |= chip->flag;
205 flag &= ~(chip->flag << 8);
206
207 write_FLAG(drv_data, flag);
208}
209
210static void cs_deactive(struct driver_data *drv_data, struct chip_data *chip)
211{
212 u16 flag = read_FLAG(drv_data);
213
214 flag |= (chip->flag << 8);
215
216 write_FLAG(drv_data, flag);
217
218 /* Move delay here for consistency */
219 if (chip->cs_chg_udelay)
220 udelay(chip->cs_chg_udelay);
221}
222
223#define MAX_SPI_SSEL 7
224
181/* stop controller and re-config current chip*/ 225/* stop controller and re-config current chip*/
182static void restore_state(struct driver_data *drv_data) 226static int restore_state(struct driver_data *drv_data)
183{ 227{
184 struct chip_data *chip = drv_data->cur_chip; 228 struct chip_data *chip = drv_data->cur_chip;
229 int ret = 0;
185 230
186 /* Clear status and disable clock */ 231 /* Clear status and disable clock */
187 write_STAT(BIT_STAT_CLR); 232 write_STAT(drv_data, BIT_STAT_CLR);
188 bfin_spi_disable(drv_data); 233 bfin_spi_disable(drv_data);
189 dev_dbg(&drv_data->pdev->dev, "restoring spi ctl state\n"); 234 dev_dbg(&drv_data->pdev->dev, "restoring spi ctl state\n");
190 235
191#if defined(CONFIG_BF534) || defined(CONFIG_BF536) || defined(CONFIG_BF537) 236 /* Load the registers */
192 dev_dbg(&drv_data->pdev->dev, 237 write_CTRL(drv_data, chip->ctl_reg);
193 "chip select number is %d\n", chip->chip_select_num); 238 write_BAUD(drv_data, chip->baud);
194
195 switch (chip->chip_select_num) {
196 case 1:
197 bfin_write_PORTF_FER(bfin_read_PORTF_FER() | 0x3c00);
198 SSYNC();
199 break;
200
201 case 2:
202 case 3:
203 bfin_write_PORT_MUX(bfin_read_PORT_MUX() | PJSE_SPI);
204 SSYNC();
205 bfin_write_PORTF_FER(bfin_read_PORTF_FER() | 0x3800);
206 SSYNC();
207 break;
208
209 case 4:
210 bfin_write_PORT_MUX(bfin_read_PORT_MUX() | PFS4E_SPI);
211 SSYNC();
212 bfin_write_PORTF_FER(bfin_read_PORTF_FER() | 0x3840);
213 SSYNC();
214 break;
215 239
216 case 5: 240 bfin_spi_enable(drv_data);
217 bfin_write_PORT_MUX(bfin_read_PORT_MUX() | PFS5E_SPI); 241 cs_active(drv_data, chip);
218 SSYNC();
219 bfin_write_PORTF_FER(bfin_read_PORTF_FER() | 0x3820);
220 SSYNC();
221 break;
222 242
223 case 6: 243 if (ret)
224 bfin_write_PORT_MUX(bfin_read_PORT_MUX() | PFS6E_SPI); 244 dev_dbg(&drv_data->pdev->dev,
225 SSYNC(); 245 ": request chip select number %d failed\n",
226 bfin_write_PORTF_FER(bfin_read_PORTF_FER() | 0x3810); 246 chip->chip_select_num);
227 SSYNC();
228 break;
229 247
230 case 7: 248 return ret;
231 bfin_write_PORT_MUX(bfin_read_PORT_MUX() | PJCE_SPI);
232 SSYNC();
233 bfin_write_PORTF_FER(bfin_read_PORTF_FER() | 0x3800);
234 SSYNC();
235 break;
236 }
237#endif
238
239 /* Load the registers */
240 write_CTRL(chip->ctl_reg);
241 write_BAUD(chip->baud);
242 write_FLAG(chip->flag);
243} 249}
244 250
245/* used to kick off transfer in rx mode */ 251/* used to kick off transfer in rx mode */
246static unsigned short dummy_read(void) 252static unsigned short dummy_read(struct driver_data *drv_data)
247{ 253{
248 unsigned short tmp; 254 unsigned short tmp;
249 tmp = read_RDBR(); 255 tmp = read_RDBR(drv_data);
250 return tmp; 256 return tmp;
251} 257}
252 258
@@ -255,9 +261,9 @@ static void null_writer(struct driver_data *drv_data)
255 u8 n_bytes = drv_data->n_bytes; 261 u8 n_bytes = drv_data->n_bytes;
256 262
257 while (drv_data->tx < drv_data->tx_end) { 263 while (drv_data->tx < drv_data->tx_end) {
258 write_TDBR(0); 264 write_TDBR(drv_data, 0);
259 while ((read_STAT() & BIT_STAT_TXS)) 265 while ((read_STAT(drv_data) & BIT_STAT_TXS))
260 continue; 266 cpu_relax();
261 drv_data->tx += n_bytes; 267 drv_data->tx += n_bytes;
262 } 268 }
263} 269}
@@ -265,75 +271,78 @@ static void null_writer(struct driver_data *drv_data)
265static void null_reader(struct driver_data *drv_data) 271static void null_reader(struct driver_data *drv_data)
266{ 272{
267 u8 n_bytes = drv_data->n_bytes; 273 u8 n_bytes = drv_data->n_bytes;
268 dummy_read(); 274 dummy_read(drv_data);
269 275
270 while (drv_data->rx < drv_data->rx_end) { 276 while (drv_data->rx < drv_data->rx_end) {
271 while (!(read_STAT() & BIT_STAT_RXS)) 277 while (!(read_STAT(drv_data) & BIT_STAT_RXS))
272 continue; 278 cpu_relax();
273 dummy_read(); 279 dummy_read(drv_data);
274 drv_data->rx += n_bytes; 280 drv_data->rx += n_bytes;
275 } 281 }
276} 282}
277 283
278static void u8_writer(struct driver_data *drv_data) 284static void u8_writer(struct driver_data *drv_data)
279{ 285{
280 dev_dbg(&drv_data->pdev->dev, 286 dev_dbg(&drv_data->pdev->dev,
281 "cr8-s is 0x%x\n", read_STAT()); 287 "cr8-s is 0x%x\n", read_STAT(drv_data));
288
289 /* poll for SPI completion before start */
290 while (!(read_STAT(drv_data) & BIT_STAT_SPIF))
291 cpu_relax();
292
282 while (drv_data->tx < drv_data->tx_end) { 293 while (drv_data->tx < drv_data->tx_end) {
283 write_TDBR(*(u8 *) (drv_data->tx)); 294 write_TDBR(drv_data, (*(u8 *) (drv_data->tx)));
284 while (read_STAT() & BIT_STAT_TXS) 295 while (read_STAT(drv_data) & BIT_STAT_TXS)
285 continue; 296 cpu_relax();
286 ++drv_data->tx; 297 ++drv_data->tx;
287 } 298 }
288
289 /* poll for SPI completion before returning */
290 while (!(read_STAT() & BIT_STAT_SPIF))
291 continue;
292} 299}
293 300
294static void u8_cs_chg_writer(struct driver_data *drv_data) 301static void u8_cs_chg_writer(struct driver_data *drv_data)
295{ 302{
296 struct chip_data *chip = drv_data->cur_chip; 303 struct chip_data *chip = drv_data->cur_chip;
297 304
305 /* poll for SPI completion before start */
306 while (!(read_STAT(drv_data) & BIT_STAT_SPIF))
307 cpu_relax();
308
298 while (drv_data->tx < drv_data->tx_end) { 309 while (drv_data->tx < drv_data->tx_end) {
299 write_FLAG(chip->flag); 310 cs_active(drv_data, chip);
300 SSYNC(); 311
301 312 write_TDBR(drv_data, (*(u8 *) (drv_data->tx)));
302 write_TDBR(*(u8 *) (drv_data->tx)); 313 while (read_STAT(drv_data) & BIT_STAT_TXS)
303 while (read_STAT() & BIT_STAT_TXS) 314 cpu_relax();
304 continue; 315
305 while (!(read_STAT() & BIT_STAT_SPIF)) 316 cs_deactive(drv_data, chip);
306 continue; 317
307 write_FLAG(0xFF00 | chip->flag);
308 SSYNC();
309 if (chip->cs_chg_udelay)
310 udelay(chip->cs_chg_udelay);
311 ++drv_data->tx; 318 ++drv_data->tx;
312 } 319 }
313 write_FLAG(0xFF00);
314 SSYNC();
315} 320}
316 321
317static void u8_reader(struct driver_data *drv_data) 322static void u8_reader(struct driver_data *drv_data)
318{ 323{
319 dev_dbg(&drv_data->pdev->dev, 324 dev_dbg(&drv_data->pdev->dev,
320 "cr-8 is 0x%x\n", read_STAT()); 325 "cr-8 is 0x%x\n", read_STAT(drv_data));
326
327 /* poll for SPI completion before start */
328 while (!(read_STAT(drv_data) & BIT_STAT_SPIF))
329 cpu_relax();
321 330
322 /* clear TDBR buffer before read(else it will be shifted out) */ 331 /* clear TDBR buffer before read(else it will be shifted out) */
323 write_TDBR(0xFFFF); 332 write_TDBR(drv_data, 0xFFFF);
324 333
325 dummy_read(); 334 dummy_read(drv_data);
326 335
327 while (drv_data->rx < drv_data->rx_end - 1) { 336 while (drv_data->rx < drv_data->rx_end - 1) {
328 while (!(read_STAT() & BIT_STAT_RXS)) 337 while (!(read_STAT(drv_data) & BIT_STAT_RXS))
329 continue; 338 cpu_relax();
330 *(u8 *) (drv_data->rx) = read_RDBR(); 339 *(u8 *) (drv_data->rx) = read_RDBR(drv_data);
331 ++drv_data->rx; 340 ++drv_data->rx;
332 } 341 }
333 342
334 while (!(read_STAT() & BIT_STAT_RXS)) 343 while (!(read_STAT(drv_data) & BIT_STAT_RXS))
335 continue; 344 cpu_relax();
336 *(u8 *) (drv_data->rx) = read_SHAW(); 345 *(u8 *) (drv_data->rx) = read_SHAW(drv_data);
337 ++drv_data->rx; 346 ++drv_data->rx;
338} 347}
339 348
@@ -341,36 +350,47 @@ static void u8_cs_chg_reader(struct driver_data *drv_data)
341{ 350{
342 struct chip_data *chip = drv_data->cur_chip; 351 struct chip_data *chip = drv_data->cur_chip;
343 352
344 while (drv_data->rx < drv_data->rx_end) { 353 /* poll for SPI completion before start */
345 write_FLAG(chip->flag); 354 while (!(read_STAT(drv_data) & BIT_STAT_SPIF))
346 SSYNC(); 355 cpu_relax();
347 356
348 read_RDBR(); /* kick off */ 357 /* clear TDBR buffer before read(else it will be shifted out) */
349 while (!(read_STAT() & BIT_STAT_RXS)) 358 write_TDBR(drv_data, 0xFFFF);
350 continue; 359
351 while (!(read_STAT() & BIT_STAT_SPIF)) 360 cs_active(drv_data, chip);
352 continue; 361 dummy_read(drv_data);
353 *(u8 *) (drv_data->rx) = read_SHAW(); 362
354 write_FLAG(0xFF00 | chip->flag); 363 while (drv_data->rx < drv_data->rx_end - 1) {
355 SSYNC(); 364 cs_deactive(drv_data, chip);
356 if (chip->cs_chg_udelay) 365
357 udelay(chip->cs_chg_udelay); 366 while (!(read_STAT(drv_data) & BIT_STAT_RXS))
367 cpu_relax();
368 cs_active(drv_data, chip);
369 *(u8 *) (drv_data->rx) = read_RDBR(drv_data);
358 ++drv_data->rx; 370 ++drv_data->rx;
359 } 371 }
360 write_FLAG(0xFF00); 372 cs_deactive(drv_data, chip);
361 SSYNC(); 373
374 while (!(read_STAT(drv_data) & BIT_STAT_RXS))
375 cpu_relax();
376 *(u8 *) (drv_data->rx) = read_SHAW(drv_data);
377 ++drv_data->rx;
362} 378}
363 379
364static void u8_duplex(struct driver_data *drv_data) 380static void u8_duplex(struct driver_data *drv_data)
365{ 381{
382 /* poll for SPI completion before start */
383 while (!(read_STAT(drv_data) & BIT_STAT_SPIF))
384 cpu_relax();
385
366 /* in duplex mode, clk is triggered by writing of TDBR */ 386 /* in duplex mode, clk is triggered by writing of TDBR */
367 while (drv_data->rx < drv_data->rx_end) { 387 while (drv_data->rx < drv_data->rx_end) {
368 write_TDBR(*(u8 *) (drv_data->tx)); 388 write_TDBR(drv_data, (*(u8 *) (drv_data->tx)));
369 while (!(read_STAT() & BIT_STAT_SPIF)) 389 while (read_STAT(drv_data) & BIT_STAT_TXS)
370 continue; 390 cpu_relax();
371 while (!(read_STAT() & BIT_STAT_RXS)) 391 while (!(read_STAT(drv_data) & BIT_STAT_RXS))
372 continue; 392 cpu_relax();
373 *(u8 *) (drv_data->rx) = read_RDBR(); 393 *(u8 *) (drv_data->rx) = read_RDBR(drv_data);
374 ++drv_data->rx; 394 ++drv_data->rx;
375 ++drv_data->tx; 395 ++drv_data->tx;
376 } 396 }
@@ -380,83 +400,89 @@ static void u8_cs_chg_duplex(struct driver_data *drv_data)
380{ 400{
381 struct chip_data *chip = drv_data->cur_chip; 401 struct chip_data *chip = drv_data->cur_chip;
382 402
403 /* poll for SPI completion before start */
404 while (!(read_STAT(drv_data) & BIT_STAT_SPIF))
405 cpu_relax();
406
383 while (drv_data->rx < drv_data->rx_end) { 407 while (drv_data->rx < drv_data->rx_end) {
384 write_FLAG(chip->flag); 408 cs_active(drv_data, chip);
385 SSYNC(); 409
386 410 write_TDBR(drv_data, (*(u8 *) (drv_data->tx)));
387 write_TDBR(*(u8 *) (drv_data->tx)); 411 while (read_STAT(drv_data) & BIT_STAT_TXS)
388 while (!(read_STAT() & BIT_STAT_SPIF)) 412 cpu_relax();
389 continue; 413 while (!(read_STAT(drv_data) & BIT_STAT_RXS))
390 while (!(read_STAT() & BIT_STAT_RXS)) 414 cpu_relax();
391 continue; 415 *(u8 *) (drv_data->rx) = read_RDBR(drv_data);
392 *(u8 *) (drv_data->rx) = read_RDBR(); 416
393 write_FLAG(0xFF00 | chip->flag); 417 cs_deactive(drv_data, chip);
394 SSYNC(); 418
395 if (chip->cs_chg_udelay)
396 udelay(chip->cs_chg_udelay);
397 ++drv_data->rx; 419 ++drv_data->rx;
398 ++drv_data->tx; 420 ++drv_data->tx;
399 } 421 }
400 write_FLAG(0xFF00);
401 SSYNC();
402} 422}
403 423
404static void u16_writer(struct driver_data *drv_data) 424static void u16_writer(struct driver_data *drv_data)
405{ 425{
406 dev_dbg(&drv_data->pdev->dev, 426 dev_dbg(&drv_data->pdev->dev,
407 "cr16 is 0x%x\n", read_STAT()); 427 "cr16 is 0x%x\n", read_STAT(drv_data));
428
429 /* poll for SPI completion before start */
430 while (!(read_STAT(drv_data) & BIT_STAT_SPIF))
431 cpu_relax();
408 432
409 while (drv_data->tx < drv_data->tx_end) { 433 while (drv_data->tx < drv_data->tx_end) {
410 write_TDBR(*(u16 *) (drv_data->tx)); 434 write_TDBR(drv_data, (*(u16 *) (drv_data->tx)));
411 while ((read_STAT() & BIT_STAT_TXS)) 435 while ((read_STAT(drv_data) & BIT_STAT_TXS))
412 continue; 436 cpu_relax();
413 drv_data->tx += 2; 437 drv_data->tx += 2;
414 } 438 }
415
416 /* poll for SPI completion before returning */
417 while (!(read_STAT() & BIT_STAT_SPIF))
418 continue;
419} 439}
420 440
421static void u16_cs_chg_writer(struct driver_data *drv_data) 441static void u16_cs_chg_writer(struct driver_data *drv_data)
422{ 442{
423 struct chip_data *chip = drv_data->cur_chip; 443 struct chip_data *chip = drv_data->cur_chip;
424 444
445 /* poll for SPI completion before start */
446 while (!(read_STAT(drv_data) & BIT_STAT_SPIF))
447 cpu_relax();
448
425 while (drv_data->tx < drv_data->tx_end) { 449 while (drv_data->tx < drv_data->tx_end) {
426 write_FLAG(chip->flag); 450 cs_active(drv_data, chip);
427 SSYNC(); 451
428 452 write_TDBR(drv_data, (*(u16 *) (drv_data->tx)));
429 write_TDBR(*(u16 *) (drv_data->tx)); 453 while ((read_STAT(drv_data) & BIT_STAT_TXS))
430 while ((read_STAT() & BIT_STAT_TXS)) 454 cpu_relax();
431 continue; 455
432 while (!(read_STAT() & BIT_STAT_SPIF)) 456 cs_deactive(drv_data, chip);
433 continue; 457
434 write_FLAG(0xFF00 | chip->flag);
435 SSYNC();
436 if (chip->cs_chg_udelay)
437 udelay(chip->cs_chg_udelay);
438 drv_data->tx += 2; 458 drv_data->tx += 2;
439 } 459 }
440 write_FLAG(0xFF00);
441 SSYNC();
442} 460}
443 461
444static void u16_reader(struct driver_data *drv_data) 462static void u16_reader(struct driver_data *drv_data)
445{ 463{
446 dev_dbg(&drv_data->pdev->dev, 464 dev_dbg(&drv_data->pdev->dev,
447 "cr-16 is 0x%x\n", read_STAT()); 465 "cr-16 is 0x%x\n", read_STAT(drv_data));
448 dummy_read(); 466
467 /* poll for SPI completion before start */
468 while (!(read_STAT(drv_data) & BIT_STAT_SPIF))
469 cpu_relax();
470
471 /* clear TDBR buffer before read(else it will be shifted out) */
472 write_TDBR(drv_data, 0xFFFF);
473
474 dummy_read(drv_data);
449 475
450 while (drv_data->rx < (drv_data->rx_end - 2)) { 476 while (drv_data->rx < (drv_data->rx_end - 2)) {
451 while (!(read_STAT() & BIT_STAT_RXS)) 477 while (!(read_STAT(drv_data) & BIT_STAT_RXS))
452 continue; 478 cpu_relax();
453 *(u16 *) (drv_data->rx) = read_RDBR(); 479 *(u16 *) (drv_data->rx) = read_RDBR(drv_data);
454 drv_data->rx += 2; 480 drv_data->rx += 2;
455 } 481 }
456 482
457 while (!(read_STAT() & BIT_STAT_RXS)) 483 while (!(read_STAT(drv_data) & BIT_STAT_RXS))
458 continue; 484 cpu_relax();
459 *(u16 *) (drv_data->rx) = read_SHAW(); 485 *(u16 *) (drv_data->rx) = read_SHAW(drv_data);
460 drv_data->rx += 2; 486 drv_data->rx += 2;
461} 487}
462 488
@@ -464,36 +490,47 @@ static void u16_cs_chg_reader(struct driver_data *drv_data)
464{ 490{
465 struct chip_data *chip = drv_data->cur_chip; 491 struct chip_data *chip = drv_data->cur_chip;
466 492
467 while (drv_data->rx < drv_data->rx_end) { 493 /* poll for SPI completion before start */
468 write_FLAG(chip->flag); 494 while (!(read_STAT(drv_data) & BIT_STAT_SPIF))
469 SSYNC(); 495 cpu_relax();
470 496
471 read_RDBR(); /* kick off */ 497 /* clear TDBR buffer before read(else it will be shifted out) */
472 while (!(read_STAT() & BIT_STAT_RXS)) 498 write_TDBR(drv_data, 0xFFFF);
473 continue; 499
474 while (!(read_STAT() & BIT_STAT_SPIF)) 500 cs_active(drv_data, chip);
475 continue; 501 dummy_read(drv_data);
476 *(u16 *) (drv_data->rx) = read_SHAW(); 502
477 write_FLAG(0xFF00 | chip->flag); 503 while (drv_data->rx < drv_data->rx_end - 2) {
478 SSYNC(); 504 cs_deactive(drv_data, chip);
479 if (chip->cs_chg_udelay) 505
480 udelay(chip->cs_chg_udelay); 506 while (!(read_STAT(drv_data) & BIT_STAT_RXS))
507 cpu_relax();
508 cs_active(drv_data, chip);
509 *(u16 *) (drv_data->rx) = read_RDBR(drv_data);
481 drv_data->rx += 2; 510 drv_data->rx += 2;
482 } 511 }
483 write_FLAG(0xFF00); 512 cs_deactive(drv_data, chip);
484 SSYNC(); 513
514 while (!(read_STAT(drv_data) & BIT_STAT_RXS))
515 cpu_relax();
516 *(u16 *) (drv_data->rx) = read_SHAW(drv_data);
517 drv_data->rx += 2;
485} 518}
486 519
487static void u16_duplex(struct driver_data *drv_data) 520static void u16_duplex(struct driver_data *drv_data)
488{ 521{
522 /* poll for SPI completion before start */
523 while (!(read_STAT(drv_data) & BIT_STAT_SPIF))
524 cpu_relax();
525
489 /* in duplex mode, clk is triggered by writing of TDBR */ 526 /* in duplex mode, clk is triggered by writing of TDBR */
490 while (drv_data->tx < drv_data->tx_end) { 527 while (drv_data->tx < drv_data->tx_end) {
491 write_TDBR(*(u16 *) (drv_data->tx)); 528 write_TDBR(drv_data, (*(u16 *) (drv_data->tx)));
492 while (!(read_STAT() & BIT_STAT_SPIF)) 529 while (read_STAT(drv_data) & BIT_STAT_TXS)
493 continue; 530 cpu_relax();
494 while (!(read_STAT() & BIT_STAT_RXS)) 531 while (!(read_STAT(drv_data) & BIT_STAT_RXS))
495 continue; 532 cpu_relax();
496 *(u16 *) (drv_data->rx) = read_RDBR(); 533 *(u16 *) (drv_data->rx) = read_RDBR(drv_data);
497 drv_data->rx += 2; 534 drv_data->rx += 2;
498 drv_data->tx += 2; 535 drv_data->tx += 2;
499 } 536 }
@@ -503,25 +540,25 @@ static void u16_cs_chg_duplex(struct driver_data *drv_data)
503{ 540{
504 struct chip_data *chip = drv_data->cur_chip; 541 struct chip_data *chip = drv_data->cur_chip;
505 542
543 /* poll for SPI completion before start */
544 while (!(read_STAT(drv_data) & BIT_STAT_SPIF))
545 cpu_relax();
546
506 while (drv_data->tx < drv_data->tx_end) { 547 while (drv_data->tx < drv_data->tx_end) {
507 write_FLAG(chip->flag); 548 cs_active(drv_data, chip);
508 SSYNC(); 549
509 550 write_TDBR(drv_data, (*(u16 *) (drv_data->tx)));
510 write_TDBR(*(u16 *) (drv_data->tx)); 551 while (read_STAT(drv_data) & BIT_STAT_TXS)
511 while (!(read_STAT() & BIT_STAT_SPIF)) 552 cpu_relax();
512 continue; 553 while (!(read_STAT(drv_data) & BIT_STAT_RXS))
513 while (!(read_STAT() & BIT_STAT_RXS)) 554 cpu_relax();
514 continue; 555 *(u16 *) (drv_data->rx) = read_RDBR(drv_data);
515 *(u16 *) (drv_data->rx) = read_RDBR(); 556
516 write_FLAG(0xFF00 | chip->flag); 557 cs_deactive(drv_data, chip);
517 SSYNC(); 558
518 if (chip->cs_chg_udelay)
519 udelay(chip->cs_chg_udelay);
520 drv_data->rx += 2; 559 drv_data->rx += 2;
521 drv_data->tx += 2; 560 drv_data->tx += 2;
522 } 561 }
523 write_FLAG(0xFF00);
524 SSYNC();
525} 562}
526 563
527/* test if ther is more transfer to be done */ 564/* test if ther is more transfer to be done */
@@ -546,6 +583,7 @@ static void *next_transfer(struct driver_data *drv_data)
546 */ 583 */
547static void giveback(struct driver_data *drv_data) 584static void giveback(struct driver_data *drv_data)
548{ 585{
586 struct chip_data *chip = drv_data->cur_chip;
549 struct spi_transfer *last_transfer; 587 struct spi_transfer *last_transfer;
550 unsigned long flags; 588 unsigned long flags;
551 struct spi_message *msg; 589 struct spi_message *msg;
@@ -565,10 +603,13 @@ static void giveback(struct driver_data *drv_data)
565 603
566 /* disable chip select signal. And not stop spi in autobuffer mode */ 604 /* disable chip select signal. And not stop spi in autobuffer mode */
567 if (drv_data->tx_dma != 0xFFFF) { 605 if (drv_data->tx_dma != 0xFFFF) {
568 write_FLAG(0xFF00); 606 cs_deactive(drv_data, chip);
569 bfin_spi_disable(drv_data); 607 bfin_spi_disable(drv_data);
570 } 608 }
571 609
610 if (!drv_data->cs_change)
611 cs_deactive(drv_data, chip);
612
572 if (msg->complete) 613 if (msg->complete)
573 msg->complete(msg->context); 614 msg->complete(msg->context);
574} 615}
@@ -576,14 +617,15 @@ static void giveback(struct driver_data *drv_data)
576static irqreturn_t dma_irq_handler(int irq, void *dev_id) 617static irqreturn_t dma_irq_handler(int irq, void *dev_id)
577{ 618{
578 struct driver_data *drv_data = (struct driver_data *)dev_id; 619 struct driver_data *drv_data = (struct driver_data *)dev_id;
620 struct chip_data *chip = drv_data->cur_chip;
579 struct spi_message *msg = drv_data->cur_msg; 621 struct spi_message *msg = drv_data->cur_msg;
580 622
581 dev_dbg(&drv_data->pdev->dev, "in dma_irq_handler\n"); 623 dev_dbg(&drv_data->pdev->dev, "in dma_irq_handler\n");
582 clear_dma_irqstat(CH_SPI); 624 clear_dma_irqstat(drv_data->dma_channel);
583 625
584 /* Wait for DMA to complete */ 626 /* Wait for DMA to complete */
585 while (get_dma_curr_irqstat(CH_SPI) & DMA_RUN) 627 while (get_dma_curr_irqstat(drv_data->dma_channel) & DMA_RUN)
586 continue; 628 cpu_relax();
587 629
588 /* 630 /*
589 * wait for the last transaction shifted out. HRM states: 631 * wait for the last transaction shifted out. HRM states:
@@ -592,18 +634,19 @@ static irqreturn_t dma_irq_handler(int irq, void *dev_id)
592 * register until it goes low for 2 successive reads 634 * register until it goes low for 2 successive reads
593 */ 635 */
594 if (drv_data->tx != NULL) { 636 if (drv_data->tx != NULL) {
595 while ((bfin_read_SPI_STAT() & TXS) || 637 while ((read_STAT(drv_data) & TXS) ||
596 (bfin_read_SPI_STAT() & TXS)) 638 (read_STAT(drv_data) & TXS))
597 continue; 639 cpu_relax();
598 } 640 }
599 641
600 while (!(bfin_read_SPI_STAT() & SPIF)) 642 while (!(read_STAT(drv_data) & SPIF))
601 continue; 643 cpu_relax();
602
603 bfin_spi_disable(drv_data);
604 644
605 msg->actual_length += drv_data->len_in_bytes; 645 msg->actual_length += drv_data->len_in_bytes;
606 646
647 if (drv_data->cs_change)
648 cs_deactive(drv_data, chip);
649
607 /* Move to next transfer */ 650 /* Move to next transfer */
608 msg->state = next_transfer(drv_data); 651 msg->state = next_transfer(drv_data);
609 652
@@ -613,8 +656,8 @@ static irqreturn_t dma_irq_handler(int irq, void *dev_id)
613 /* free the irq handler before next transfer */ 656 /* free the irq handler before next transfer */
614 dev_dbg(&drv_data->pdev->dev, 657 dev_dbg(&drv_data->pdev->dev,
615 "disable dma channel irq%d\n", 658 "disable dma channel irq%d\n",
616 CH_SPI); 659 drv_data->dma_channel);
617 dma_disable_irq(CH_SPI); 660 dma_disable_irq(drv_data->dma_channel);
618 661
619 return IRQ_HANDLED; 662 return IRQ_HANDLED;
620} 663}
@@ -690,31 +733,67 @@ static void pump_transfers(unsigned long data)
690 drv_data->rx_dma = transfer->rx_dma; 733 drv_data->rx_dma = transfer->rx_dma;
691 drv_data->tx_dma = transfer->tx_dma; 734 drv_data->tx_dma = transfer->tx_dma;
692 drv_data->len_in_bytes = transfer->len; 735 drv_data->len_in_bytes = transfer->len;
736 drv_data->cs_change = transfer->cs_change;
737
738 /* Bits per word setup */
739 switch (transfer->bits_per_word) {
740 case 8:
741 drv_data->n_bytes = 1;
742 width = CFG_SPI_WORDSIZE8;
743 drv_data->read = chip->cs_change_per_word ?
744 u8_cs_chg_reader : u8_reader;
745 drv_data->write = chip->cs_change_per_word ?
746 u8_cs_chg_writer : u8_writer;
747 drv_data->duplex = chip->cs_change_per_word ?
748 u8_cs_chg_duplex : u8_duplex;
749 break;
750
751 case 16:
752 drv_data->n_bytes = 2;
753 width = CFG_SPI_WORDSIZE16;
754 drv_data->read = chip->cs_change_per_word ?
755 u16_cs_chg_reader : u16_reader;
756 drv_data->write = chip->cs_change_per_word ?
757 u16_cs_chg_writer : u16_writer;
758 drv_data->duplex = chip->cs_change_per_word ?
759 u16_cs_chg_duplex : u16_duplex;
760 break;
761
762 default:
763 /* No change, the same as default setting */
764 drv_data->n_bytes = chip->n_bytes;
765 width = chip->width;
766 drv_data->write = drv_data->tx ? chip->write : null_writer;
767 drv_data->read = drv_data->rx ? chip->read : null_reader;
768 drv_data->duplex = chip->duplex ? chip->duplex : null_writer;
769 break;
770 }
771 cr = (read_CTRL(drv_data) & (~BIT_CTL_TIMOD));
772 cr |= (width << 8);
773 write_CTRL(drv_data, cr);
693 774
694 width = chip->width;
695 if (width == CFG_SPI_WORDSIZE16) { 775 if (width == CFG_SPI_WORDSIZE16) {
696 drv_data->len = (transfer->len) >> 1; 776 drv_data->len = (transfer->len) >> 1;
697 } else { 777 } else {
698 drv_data->len = transfer->len; 778 drv_data->len = transfer->len;
699 } 779 }
700 drv_data->write = drv_data->tx ? chip->write : null_writer; 780 dev_dbg(&drv_data->pdev->dev, "transfer: ",
701 drv_data->read = drv_data->rx ? chip->read : null_reader; 781 "drv_data->write is %p, chip->write is %p, null_wr is %p\n",
702 drv_data->duplex = chip->duplex ? chip->duplex : null_writer; 782 drv_data->write, chip->write, null_writer);
703 dev_dbg(&drv_data->pdev->dev,
704 "transfer: drv_data->write is %p, chip->write is %p, null_wr is %p\n",
705 drv_data->write, chip->write, null_writer);
706 783
707 /* speed and width has been set on per message */ 784 /* speed and width has been set on per message */
708 message->state = RUNNING_STATE; 785 message->state = RUNNING_STATE;
709 dma_config = 0; 786 dma_config = 0;
710 787
711 /* restore spi status for each spi transfer */ 788 /* Speed setup (surely valid because already checked) */
712 if (transfer->speed_hz) { 789 if (transfer->speed_hz)
713 write_BAUD(hz_to_spi_baud(transfer->speed_hz)); 790 write_BAUD(drv_data, hz_to_spi_baud(transfer->speed_hz));
714 } else { 791 else
715 write_BAUD(chip->baud); 792 write_BAUD(drv_data, chip->baud);
716 } 793
717 write_FLAG(chip->flag); 794 write_STAT(drv_data, BIT_STAT_CLR);
795 cr = (read_CTRL(drv_data) & (~BIT_CTL_TIMOD));
796 cs_active(drv_data, chip);
718 797
719 dev_dbg(&drv_data->pdev->dev, 798 dev_dbg(&drv_data->pdev->dev,
720 "now pumping a transfer: width is %d, len is %d\n", 799 "now pumping a transfer: width is %d, len is %d\n",
@@ -727,25 +806,25 @@ static void pump_transfers(unsigned long data)
727 */ 806 */
728 if (drv_data->cur_chip->enable_dma && drv_data->len > 6) { 807 if (drv_data->cur_chip->enable_dma && drv_data->len > 6) {
729 808
730 write_STAT(BIT_STAT_CLR); 809 disable_dma(drv_data->dma_channel);
731 disable_dma(CH_SPI); 810 clear_dma_irqstat(drv_data->dma_channel);
732 clear_dma_irqstat(CH_SPI);
733 bfin_spi_disable(drv_data); 811 bfin_spi_disable(drv_data);
734 812
735 /* config dma channel */ 813 /* config dma channel */
736 dev_dbg(&drv_data->pdev->dev, "doing dma transfer\n"); 814 dev_dbg(&drv_data->pdev->dev, "doing dma transfer\n");
737 if (width == CFG_SPI_WORDSIZE16) { 815 if (width == CFG_SPI_WORDSIZE16) {
738 set_dma_x_count(CH_SPI, drv_data->len); 816 set_dma_x_count(drv_data->dma_channel, drv_data->len);
739 set_dma_x_modify(CH_SPI, 2); 817 set_dma_x_modify(drv_data->dma_channel, 2);
740 dma_width = WDSIZE_16; 818 dma_width = WDSIZE_16;
741 } else { 819 } else {
742 set_dma_x_count(CH_SPI, drv_data->len); 820 set_dma_x_count(drv_data->dma_channel, drv_data->len);
743 set_dma_x_modify(CH_SPI, 1); 821 set_dma_x_modify(drv_data->dma_channel, 1);
744 dma_width = WDSIZE_8; 822 dma_width = WDSIZE_8;
745 } 823 }
746 824
747 /* set transfer width,direction. And enable spi */ 825 /* poll for SPI completion before start */
748 cr = (read_CTRL() & (~BIT_CTL_TIMOD)); 826 while (!(read_STAT(drv_data) & BIT_STAT_SPIF))
827 cpu_relax();
749 828
750 /* dirty hack for autobuffer DMA mode */ 829 /* dirty hack for autobuffer DMA mode */
751 if (drv_data->tx_dma == 0xFFFF) { 830 if (drv_data->tx_dma == 0xFFFF) {
@@ -755,13 +834,18 @@ static void pump_transfers(unsigned long data)
755 /* no irq in autobuffer mode */ 834 /* no irq in autobuffer mode */
756 dma_config = 835 dma_config =
757 (DMAFLOW_AUTO | RESTART | dma_width | DI_EN); 836 (DMAFLOW_AUTO | RESTART | dma_width | DI_EN);
758 set_dma_config(CH_SPI, dma_config); 837 set_dma_config(drv_data->dma_channel, dma_config);
759 set_dma_start_addr(CH_SPI, (unsigned long)drv_data->tx); 838 set_dma_start_addr(drv_data->dma_channel,
760 enable_dma(CH_SPI); 839 (unsigned long)drv_data->tx);
761 write_CTRL(cr | CFG_SPI_DMAWRITE | (width << 8) | 840 enable_dma(drv_data->dma_channel);
762 (CFG_SPI_ENABLE << 14)); 841
763 842 /* start SPI transfer */
764 /* just return here, there can only be one transfer in this mode */ 843 write_CTRL(drv_data,
844 (cr | CFG_SPI_DMAWRITE | BIT_CTL_ENABLE));
845
846 /* just return here, there can only be one transfer
847 * in this mode
848 */
765 message->status = 0; 849 message->status = 0;
766 giveback(drv_data); 850 giveback(drv_data);
767 return; 851 return;
@@ -772,58 +856,51 @@ static void pump_transfers(unsigned long data)
772 /* set transfer mode, and enable SPI */ 856 /* set transfer mode, and enable SPI */
773 dev_dbg(&drv_data->pdev->dev, "doing DMA in.\n"); 857 dev_dbg(&drv_data->pdev->dev, "doing DMA in.\n");
774 858
775 /* disable SPI before write to TDBR */
776 write_CTRL(cr & ~BIT_CTL_ENABLE);
777
778 /* clear tx reg soformer data is not shifted out */ 859 /* clear tx reg soformer data is not shifted out */
779 write_TDBR(0xFF); 860 write_TDBR(drv_data, 0xFFFF);
780 861
781 set_dma_x_count(CH_SPI, drv_data->len); 862 set_dma_x_count(drv_data->dma_channel, drv_data->len);
782 863
783 /* start dma */ 864 /* start dma */
784 dma_enable_irq(CH_SPI); 865 dma_enable_irq(drv_data->dma_channel);
785 dma_config = (WNR | RESTART | dma_width | DI_EN); 866 dma_config = (WNR | RESTART | dma_width | DI_EN);
786 set_dma_config(CH_SPI, dma_config); 867 set_dma_config(drv_data->dma_channel, dma_config);
787 set_dma_start_addr(CH_SPI, (unsigned long)drv_data->rx); 868 set_dma_start_addr(drv_data->dma_channel,
788 enable_dma(CH_SPI); 869 (unsigned long)drv_data->rx);
870 enable_dma(drv_data->dma_channel);
871
872 /* start SPI transfer */
873 write_CTRL(drv_data,
874 (cr | CFG_SPI_DMAREAD | BIT_CTL_ENABLE));
789 875
790 cr |=
791 CFG_SPI_DMAREAD | (width << 8) | (CFG_SPI_ENABLE <<
792 14);
793 /* set transfer mode, and enable SPI */
794 write_CTRL(cr);
795 } else if (drv_data->tx != NULL) { 876 } else if (drv_data->tx != NULL) {
796 dev_dbg(&drv_data->pdev->dev, "doing DMA out.\n"); 877 dev_dbg(&drv_data->pdev->dev, "doing DMA out.\n");
797 878
798 /* start dma */ 879 /* start dma */
799 dma_enable_irq(CH_SPI); 880 dma_enable_irq(drv_data->dma_channel);
800 dma_config = (RESTART | dma_width | DI_EN); 881 dma_config = (RESTART | dma_width | DI_EN);
801 set_dma_config(CH_SPI, dma_config); 882 set_dma_config(drv_data->dma_channel, dma_config);
802 set_dma_start_addr(CH_SPI, (unsigned long)drv_data->tx); 883 set_dma_start_addr(drv_data->dma_channel,
803 enable_dma(CH_SPI); 884 (unsigned long)drv_data->tx);
804 885 enable_dma(drv_data->dma_channel);
805 write_CTRL(cr | CFG_SPI_DMAWRITE | (width << 8) | 886
806 (CFG_SPI_ENABLE << 14)); 887 /* start SPI transfer */
807 888 write_CTRL(drv_data,
889 (cr | CFG_SPI_DMAWRITE | BIT_CTL_ENABLE));
808 } 890 }
809 } else { 891 } else {
810 /* IO mode write then read */ 892 /* IO mode write then read */
811 dev_dbg(&drv_data->pdev->dev, "doing IO transfer\n"); 893 dev_dbg(&drv_data->pdev->dev, "doing IO transfer\n");
812 894
813 write_STAT(BIT_STAT_CLR);
814
815 if (drv_data->tx != NULL && drv_data->rx != NULL) { 895 if (drv_data->tx != NULL && drv_data->rx != NULL) {
816 /* full duplex mode */ 896 /* full duplex mode */
817 BUG_ON((drv_data->tx_end - drv_data->tx) != 897 BUG_ON((drv_data->tx_end - drv_data->tx) !=
818 (drv_data->rx_end - drv_data->rx)); 898 (drv_data->rx_end - drv_data->rx));
819 cr = (read_CTRL() & (~BIT_CTL_TIMOD));
820 cr |= CFG_SPI_WRITE | (width << 8) |
821 (CFG_SPI_ENABLE << 14);
822 dev_dbg(&drv_data->pdev->dev, 899 dev_dbg(&drv_data->pdev->dev,
823 "IO duplex: cr is 0x%x\n", cr); 900 "IO duplex: cr is 0x%x\n", cr);
824 901
825 write_CTRL(cr); 902 /* set SPI transfer mode */
826 SSYNC(); 903 write_CTRL(drv_data, (cr | CFG_SPI_WRITE));
827 904
828 drv_data->duplex(drv_data); 905 drv_data->duplex(drv_data);
829 906
@@ -831,14 +908,11 @@ static void pump_transfers(unsigned long data)
831 tranf_success = 0; 908 tranf_success = 0;
832 } else if (drv_data->tx != NULL) { 909 } else if (drv_data->tx != NULL) {
833 /* write only half duplex */ 910 /* write only half duplex */
834 cr = (read_CTRL() & (~BIT_CTL_TIMOD)); 911 dev_dbg(&drv_data->pdev->dev,
835 cr |= CFG_SPI_WRITE | (width << 8) |
836 (CFG_SPI_ENABLE << 14);
837 dev_dbg(&drv_data->pdev->dev,
838 "IO write: cr is 0x%x\n", cr); 912 "IO write: cr is 0x%x\n", cr);
839 913
840 write_CTRL(cr); 914 /* set SPI transfer mode */
841 SSYNC(); 915 write_CTRL(drv_data, (cr | CFG_SPI_WRITE));
842 916
843 drv_data->write(drv_data); 917 drv_data->write(drv_data);
844 918
@@ -846,14 +920,11 @@ static void pump_transfers(unsigned long data)
846 tranf_success = 0; 920 tranf_success = 0;
847 } else if (drv_data->rx != NULL) { 921 } else if (drv_data->rx != NULL) {
848 /* read only half duplex */ 922 /* read only half duplex */
849 cr = (read_CTRL() & (~BIT_CTL_TIMOD)); 923 dev_dbg(&drv_data->pdev->dev,
850 cr |= CFG_SPI_READ | (width << 8) |
851 (CFG_SPI_ENABLE << 14);
852 dev_dbg(&drv_data->pdev->dev,
853 "IO read: cr is 0x%x\n", cr); 924 "IO read: cr is 0x%x\n", cr);
854 925
855 write_CTRL(cr); 926 /* set SPI transfer mode */
856 SSYNC(); 927 write_CTRL(drv_data, (cr | CFG_SPI_READ));
857 928
858 drv_data->read(drv_data); 929 drv_data->read(drv_data);
859 if (drv_data->rx != drv_data->rx_end) 930 if (drv_data->rx != drv_data->rx_end)
@@ -861,7 +932,7 @@ static void pump_transfers(unsigned long data)
861 } 932 }
862 933
863 if (!tranf_success) { 934 if (!tranf_success) {
864 dev_dbg(&drv_data->pdev->dev, 935 dev_dbg(&drv_data->pdev->dev,
865 "IO write error!\n"); 936 "IO write error!\n");
866 message->state = ERROR_STATE; 937 message->state = ERROR_STATE;
867 } else { 938 } else {
@@ -881,9 +952,11 @@ static void pump_transfers(unsigned long data)
881/* pop a msg from queue and kick off real transfer */ 952/* pop a msg from queue and kick off real transfer */
882static void pump_messages(struct work_struct *work) 953static void pump_messages(struct work_struct *work)
883{ 954{
884 struct driver_data *drv_data = container_of(work, struct driver_data, pump_messages); 955 struct driver_data *drv_data;
885 unsigned long flags; 956 unsigned long flags;
886 957
958 drv_data = container_of(work, struct driver_data, pump_messages);
959
887 /* Lock queue and check for queue work */ 960 /* Lock queue and check for queue work */
888 spin_lock_irqsave(&drv_data->lock, flags); 961 spin_lock_irqsave(&drv_data->lock, flags);
889 if (list_empty(&drv_data->queue) || drv_data->run == QUEUE_STOPPED) { 962 if (list_empty(&drv_data->queue) || drv_data->run == QUEUE_STOPPED) {
@@ -902,6 +975,14 @@ static void pump_messages(struct work_struct *work)
902 /* Extract head of queue */ 975 /* Extract head of queue */
903 drv_data->cur_msg = list_entry(drv_data->queue.next, 976 drv_data->cur_msg = list_entry(drv_data->queue.next,
904 struct spi_message, queue); 977 struct spi_message, queue);
978
979 /* Setup the SSP using the per chip configuration */
980 drv_data->cur_chip = spi_get_ctldata(drv_data->cur_msg->spi);
981 if (restore_state(drv_data)) {
982 spin_unlock_irqrestore(&drv_data->lock, flags);
983 return;
984 };
985
905 list_del_init(&drv_data->cur_msg->queue); 986 list_del_init(&drv_data->cur_msg->queue);
906 987
907 /* Initial message state */ 988 /* Initial message state */
@@ -909,15 +990,12 @@ static void pump_messages(struct work_struct *work)
909 drv_data->cur_transfer = list_entry(drv_data->cur_msg->transfers.next, 990 drv_data->cur_transfer = list_entry(drv_data->cur_msg->transfers.next,
910 struct spi_transfer, transfer_list); 991 struct spi_transfer, transfer_list);
911 992
912 /* Setup the SSP using the per chip configuration */ 993 dev_dbg(&drv_data->pdev->dev, "got a message to pump, "
913 drv_data->cur_chip = spi_get_ctldata(drv_data->cur_msg->spi); 994 "state is set to: baud %d, flag 0x%x, ctl 0x%x\n",
914 restore_state(drv_data); 995 drv_data->cur_chip->baud, drv_data->cur_chip->flag,
996 drv_data->cur_chip->ctl_reg);
997
915 dev_dbg(&drv_data->pdev->dev, 998 dev_dbg(&drv_data->pdev->dev,
916 "got a message to pump, state is set to: baud %d, flag 0x%x, ctl 0x%x\n",
917 drv_data->cur_chip->baud, drv_data->cur_chip->flag,
918 drv_data->cur_chip->ctl_reg);
919
920 dev_dbg(&drv_data->pdev->dev,
921 "the first transfer len is %d\n", 999 "the first transfer len is %d\n",
922 drv_data->cur_transfer->len); 1000 drv_data->cur_transfer->len);
923 1001
@@ -959,6 +1037,22 @@ static int transfer(struct spi_device *spi, struct spi_message *msg)
959 return 0; 1037 return 0;
960} 1038}
961 1039
1040#define MAX_SPI_SSEL 7
1041
1042static u16 ssel[3][MAX_SPI_SSEL] = {
1043 {P_SPI0_SSEL1, P_SPI0_SSEL2, P_SPI0_SSEL3,
1044 P_SPI0_SSEL4, P_SPI0_SSEL5,
1045 P_SPI0_SSEL6, P_SPI0_SSEL7},
1046
1047 {P_SPI1_SSEL1, P_SPI1_SSEL2, P_SPI1_SSEL3,
1048 P_SPI1_SSEL4, P_SPI1_SSEL5,
1049 P_SPI1_SSEL6, P_SPI1_SSEL7},
1050
1051 {P_SPI2_SSEL1, P_SPI2_SSEL2, P_SPI2_SSEL3,
1052 P_SPI2_SSEL4, P_SPI2_SSEL5,
1053 P_SPI2_SSEL6, P_SPI2_SSEL7},
1054};
1055
962/* first setup for new devices */ 1056/* first setup for new devices */
963static int setup(struct spi_device *spi) 1057static int setup(struct spi_device *spi)
964{ 1058{
@@ -993,6 +1087,18 @@ static int setup(struct spi_device *spi)
993 1087
994 /* chip_info isn't always needed */ 1088 /* chip_info isn't always needed */
995 if (chip_info) { 1089 if (chip_info) {
1090 /* Make sure people stop trying to set fields via ctl_reg
1091 * when they should actually be using common SPI framework.
1092 * Currently we let through: WOM EMISO PSSE GM SZ TIMOD.
1093 * Not sure if a user actually needs/uses any of these,
1094 * but let's assume (for now) they do.
1095 */
1096 if (chip_info->ctl_reg & (SPE|MSTR|CPOL|CPHA|LSBF|SIZE)) {
1097 dev_err(&spi->dev, "do not set bits in ctl_reg "
1098 "that the SPI framework manages\n");
1099 return -EINVAL;
1100 }
1101
996 chip->enable_dma = chip_info->enable_dma != 0 1102 chip->enable_dma = chip_info->enable_dma != 0
997 && drv_data->master_info->enable_dma; 1103 && drv_data->master_info->enable_dma;
998 chip->ctl_reg = chip_info->ctl_reg; 1104 chip->ctl_reg = chip_info->ctl_reg;
@@ -1015,20 +1121,20 @@ static int setup(struct spi_device *spi)
1015 * if any one SPI chip is registered and wants DMA, request the 1121 * if any one SPI chip is registered and wants DMA, request the
1016 * DMA channel for it 1122 * DMA channel for it
1017 */ 1123 */
1018 if (chip->enable_dma && !dma_requested) { 1124 if (chip->enable_dma && !drv_data->dma_requested) {
1019 /* register dma irq handler */ 1125 /* register dma irq handler */
1020 if (request_dma(CH_SPI, "BF53x_SPI_DMA") < 0) { 1126 if (request_dma(drv_data->dma_channel, "BF53x_SPI_DMA") < 0) {
1021 dev_dbg(&spi->dev, 1127 dev_dbg(&spi->dev,
1022 "Unable to request BlackFin SPI DMA channel\n"); 1128 "Unable to request BlackFin SPI DMA channel\n");
1023 return -ENODEV; 1129 return -ENODEV;
1024 } 1130 }
1025 if (set_dma_callback(CH_SPI, (void *)dma_irq_handler, drv_data) 1131 if (set_dma_callback(drv_data->dma_channel,
1026 < 0) { 1132 (void *)dma_irq_handler, drv_data) < 0) {
1027 dev_dbg(&spi->dev, "Unable to set dma callback\n"); 1133 dev_dbg(&spi->dev, "Unable to set dma callback\n");
1028 return -EPERM; 1134 return -EPERM;
1029 } 1135 }
1030 dma_disable_irq(CH_SPI); 1136 dma_disable_irq(drv_data->dma_channel);
1031 dma_requested = 1; 1137 drv_data->dma_requested = 1;
1032 } 1138 }
1033 1139
1034 /* 1140 /*
@@ -1077,6 +1183,14 @@ static int setup(struct spi_device *spi)
1077 1183
1078 spi_set_ctldata(spi, chip); 1184 spi_set_ctldata(spi, chip);
1079 1185
1186 dev_dbg(&spi->dev, "chip select number is %d\n", chip->chip_select_num);
1187 if ((chip->chip_select_num > 0)
1188 && (chip->chip_select_num <= spi->master->num_chipselect))
1189 peripheral_request(ssel[spi->master->bus_num]
1190 [chip->chip_select_num-1], DRV_NAME);
1191
1192 cs_deactive(drv_data, chip);
1193
1080 return 0; 1194 return 0;
1081} 1195}
1082 1196
@@ -1088,6 +1202,11 @@ static void cleanup(struct spi_device *spi)
1088{ 1202{
1089 struct chip_data *chip = spi_get_ctldata(spi); 1203 struct chip_data *chip = spi_get_ctldata(spi);
1090 1204
1205 if ((chip->chip_select_num > 0)
1206 && (chip->chip_select_num <= spi->master->num_chipselect))
1207 peripheral_free(ssel[spi->master->bus_num]
1208 [chip->chip_select_num-1]);
1209
1091 kfree(chip); 1210 kfree(chip);
1092} 1211}
1093 1212
@@ -1183,6 +1302,7 @@ static int __init bfin5xx_spi_probe(struct platform_device *pdev)
1183 struct bfin5xx_spi_master *platform_info; 1302 struct bfin5xx_spi_master *platform_info;
1184 struct spi_master *master; 1303 struct spi_master *master;
1185 struct driver_data *drv_data = 0; 1304 struct driver_data *drv_data = 0;
1305 struct resource *res;
1186 int status = 0; 1306 int status = 0;
1187 1307
1188 platform_info = dev->platform_data; 1308 platform_info = dev->platform_data;
@@ -1193,10 +1313,12 @@ static int __init bfin5xx_spi_probe(struct platform_device *pdev)
1193 dev_err(&pdev->dev, "can not alloc spi_master\n"); 1313 dev_err(&pdev->dev, "can not alloc spi_master\n");
1194 return -ENOMEM; 1314 return -ENOMEM;
1195 } 1315 }
1316
1196 drv_data = spi_master_get_devdata(master); 1317 drv_data = spi_master_get_devdata(master);
1197 drv_data->master = master; 1318 drv_data->master = master;
1198 drv_data->master_info = platform_info; 1319 drv_data->master_info = platform_info;
1199 drv_data->pdev = pdev; 1320 drv_data->pdev = pdev;
1321 drv_data->pin_req = platform_info->pin_req;
1200 1322
1201 master->bus_num = pdev->id; 1323 master->bus_num = pdev->id;
1202 master->num_chipselect = platform_info->num_chipselect; 1324 master->num_chipselect = platform_info->num_chipselect;
@@ -1204,15 +1326,38 @@ static int __init bfin5xx_spi_probe(struct platform_device *pdev)
1204 master->setup = setup; 1326 master->setup = setup;
1205 master->transfer = transfer; 1327 master->transfer = transfer;
1206 1328
1329 /* Find and map our resources */
1330 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1331 if (res == NULL) {
1332 dev_err(dev, "Cannot get IORESOURCE_MEM\n");
1333 status = -ENOENT;
1334 goto out_error_get_res;
1335 }
1336
1337 drv_data->regs_base = ioremap(res->start, (res->end - res->start + 1));
1338 if (drv_data->regs_base == NULL) {
1339 dev_err(dev, "Cannot map IO\n");
1340 status = -ENXIO;
1341 goto out_error_ioremap;
1342 }
1343
1344 drv_data->dma_channel = platform_get_irq(pdev, 0);
1345 if (drv_data->dma_channel < 0) {
1346 dev_err(dev, "No DMA channel specified\n");
1347 status = -ENOENT;
1348 goto out_error_no_dma_ch;
1349 }
1350
1207 /* Initial and start queue */ 1351 /* Initial and start queue */
1208 status = init_queue(drv_data); 1352 status = init_queue(drv_data);
1209 if (status != 0) { 1353 if (status != 0) {
1210 dev_err(&pdev->dev, "problem initializing queue\n"); 1354 dev_err(dev, "problem initializing queue\n");
1211 goto out_error_queue_alloc; 1355 goto out_error_queue_alloc;
1212 } 1356 }
1357
1213 status = start_queue(drv_data); 1358 status = start_queue(drv_data);
1214 if (status != 0) { 1359 if (status != 0) {
1215 dev_err(&pdev->dev, "problem starting queue\n"); 1360 dev_err(dev, "problem starting queue\n");
1216 goto out_error_queue_alloc; 1361 goto out_error_queue_alloc;
1217 } 1362 }
1218 1363
@@ -1220,15 +1365,30 @@ static int __init bfin5xx_spi_probe(struct platform_device *pdev)
1220 platform_set_drvdata(pdev, drv_data); 1365 platform_set_drvdata(pdev, drv_data);
1221 status = spi_register_master(master); 1366 status = spi_register_master(master);
1222 if (status != 0) { 1367 if (status != 0) {
1223 dev_err(&pdev->dev, "problem registering spi master\n"); 1368 dev_err(dev, "problem registering spi master\n");
1224 goto out_error_queue_alloc; 1369 goto out_error_queue_alloc;
1225 } 1370 }
1226 dev_dbg(&pdev->dev, "controller probe successfully\n"); 1371
1372 status = peripheral_request_list(drv_data->pin_req, DRV_NAME);
1373 if (status != 0) {
1374 dev_err(&pdev->dev, ": Requesting Peripherals failed\n");
1375 goto out_error;
1376 }
1377
1378 dev_info(dev, "%s, Version %s, regs_base@%p, dma channel@%d\n",
1379 DRV_DESC, DRV_VERSION, drv_data->regs_base,
1380 drv_data->dma_channel);
1227 return status; 1381 return status;
1228 1382
1229 out_error_queue_alloc: 1383out_error_queue_alloc:
1230 destroy_queue(drv_data); 1384 destroy_queue(drv_data);
1385out_error_no_dma_ch:
1386 iounmap((void *) drv_data->regs_base);
1387out_error_ioremap:
1388out_error_get_res:
1389out_error:
1231 spi_master_put(master); 1390 spi_master_put(master);
1391
1232 return status; 1392 return status;
1233} 1393}
1234 1394
@@ -1251,13 +1411,15 @@ static int __devexit bfin5xx_spi_remove(struct platform_device *pdev)
1251 1411
1252 /* Release DMA */ 1412 /* Release DMA */
1253 if (drv_data->master_info->enable_dma) { 1413 if (drv_data->master_info->enable_dma) {
1254 if (dma_channel_active(CH_SPI)) 1414 if (dma_channel_active(drv_data->dma_channel))
1255 free_dma(CH_SPI); 1415 free_dma(drv_data->dma_channel);
1256 } 1416 }
1257 1417
1258 /* Disconnect from the SPI framework */ 1418 /* Disconnect from the SPI framework */
1259 spi_unregister_master(drv_data->master); 1419 spi_unregister_master(drv_data->master);
1260 1420
1421 peripheral_free_list(drv_data->pin_req);
1422
1261 /* Prevent double remove */ 1423 /* Prevent double remove */
1262 platform_set_drvdata(pdev, NULL); 1424 platform_set_drvdata(pdev, NULL);
1263 1425
@@ -1305,7 +1467,7 @@ static int bfin5xx_spi_resume(struct platform_device *pdev)
1305MODULE_ALIAS("bfin-spi-master"); /* for platform bus hotplug */ 1467MODULE_ALIAS("bfin-spi-master"); /* for platform bus hotplug */
1306static struct platform_driver bfin5xx_spi_driver = { 1468static struct platform_driver bfin5xx_spi_driver = {
1307 .driver = { 1469 .driver = {
1308 .name = "bfin-spi-master", 1470 .name = DRV_NAME,
1309 .owner = THIS_MODULE, 1471 .owner = THIS_MODULE,
1310 }, 1472 },
1311 .suspend = bfin5xx_spi_suspend, 1473 .suspend = bfin5xx_spi_suspend,
diff --git a/drivers/spi/spi_imx.c b/drivers/spi/spi_imx.c
index 7686ba34430f..2cd8573fb09c 100644
--- a/drivers/spi/spi_imx.c
+++ b/drivers/spi/spi_imx.c
@@ -1758,5 +1758,5 @@ static void __exit spi_imx_exit(void)
1758module_exit(spi_imx_exit); 1758module_exit(spi_imx_exit);
1759 1759
1760MODULE_AUTHOR("Andrea Paterniani, <a.paterniani@swapp-eng.it>"); 1760MODULE_AUTHOR("Andrea Paterniani, <a.paterniani@swapp-eng.it>");
1761MODULE_DESCRIPTION("iMX SPI Contoller Driver"); 1761MODULE_DESCRIPTION("iMX SPI Controller Driver");
1762MODULE_LICENSE("GPL"); 1762MODULE_LICENSE("GPL");
diff --git a/drivers/spi/spi_s3c24xx_gpio.c b/drivers/spi/spi_s3c24xx_gpio.c
index 0fa25e2e80fe..109d82c1abc0 100644
--- a/drivers/spi/spi_s3c24xx_gpio.c
+++ b/drivers/spi/spi_s3c24xx_gpio.c
@@ -96,6 +96,7 @@ static void s3c2410_spigpio_chipselect(struct spi_device *dev, int value)
96 96
97static int s3c2410_spigpio_probe(struct platform_device *dev) 97static int s3c2410_spigpio_probe(struct platform_device *dev)
98{ 98{
99 struct s3c2410_spigpio_info *info;
99 struct spi_master *master; 100 struct spi_master *master;
100 struct s3c2410_spigpio *sp; 101 struct s3c2410_spigpio *sp;
101 int ret; 102 int ret;
@@ -113,10 +114,11 @@ static int s3c2410_spigpio_probe(struct platform_device *dev)
113 platform_set_drvdata(dev, sp); 114 platform_set_drvdata(dev, sp);
114 115
115 /* copy in the plkatform data */ 116 /* copy in the plkatform data */
116 sp->info = dev->dev.platform_data; 117 info = sp->info = dev->dev.platform_data;
117 118
118 /* setup spi bitbang adaptor */ 119 /* setup spi bitbang adaptor */
119 sp->bitbang.master = spi_master_get(master); 120 sp->bitbang.master = spi_master_get(master);
121 sp->bitbang.master->bus_num = info->bus_num;
120 sp->bitbang.chipselect = s3c2410_spigpio_chipselect; 122 sp->bitbang.chipselect = s3c2410_spigpio_chipselect;
121 123
122 sp->bitbang.txrx_word[SPI_MODE_0] = s3c2410_spigpio_txrx_mode0; 124 sp->bitbang.txrx_word[SPI_MODE_0] = s3c2410_spigpio_txrx_mode0;
@@ -124,13 +126,18 @@ static int s3c2410_spigpio_probe(struct platform_device *dev)
124 sp->bitbang.txrx_word[SPI_MODE_2] = s3c2410_spigpio_txrx_mode2; 126 sp->bitbang.txrx_word[SPI_MODE_2] = s3c2410_spigpio_txrx_mode2;
125 sp->bitbang.txrx_word[SPI_MODE_3] = s3c2410_spigpio_txrx_mode3; 127 sp->bitbang.txrx_word[SPI_MODE_3] = s3c2410_spigpio_txrx_mode3;
126 128
127 /* set state of spi pins */ 129 /* set state of spi pins, always assume that the clock is
128 s3c2410_gpio_setpin(sp->info->pin_clk, 0); 130 * available, but do check the MOSI and MISO. */
129 s3c2410_gpio_setpin(sp->info->pin_mosi, 0); 131 s3c2410_gpio_setpin(info->pin_clk, 0);
132 s3c2410_gpio_cfgpin(info->pin_clk, S3C2410_GPIO_OUTPUT);
130 133
131 s3c2410_gpio_cfgpin(sp->info->pin_clk, S3C2410_GPIO_OUTPUT); 134 if (info->pin_mosi < S3C2410_GPH10) {
132 s3c2410_gpio_cfgpin(sp->info->pin_mosi, S3C2410_GPIO_OUTPUT); 135 s3c2410_gpio_setpin(info->pin_mosi, 0);
133 s3c2410_gpio_cfgpin(sp->info->pin_miso, S3C2410_GPIO_INPUT); 136 s3c2410_gpio_cfgpin(info->pin_mosi, S3C2410_GPIO_OUTPUT);
137 }
138
139 if (info->pin_miso != S3C2410_GPA0 && info->pin_miso < S3C2410_GPH10)
140 s3c2410_gpio_cfgpin(info->pin_miso, S3C2410_GPIO_INPUT);
134 141
135 ret = spi_bitbang_start(&sp->bitbang); 142 ret = spi_bitbang_start(&sp->bitbang);
136 if (ret) 143 if (ret)
diff --git a/drivers/usb/README b/drivers/usb/README
index 3c8434128554..284f46b3e1cc 100644
--- a/drivers/usb/README
+++ b/drivers/usb/README
@@ -39,12 +39,12 @@ first subdirectory in the list below that it fits into.
39 39
40image/ - This is for still image drivers, like scanners or 40image/ - This is for still image drivers, like scanners or
41 digital cameras. 41 digital cameras.
42input/ - This is for any driver that uses the input subsystem, 42../input/ - This is for any driver that uses the input subsystem,
43 like keyboard, mice, touchscreens, tablets, etc. 43 like keyboard, mice, touchscreens, tablets, etc.
44media/ - This is for multimedia drivers, like video cameras, 44../media/ - This is for multimedia drivers, like video cameras,
45 radios, and any other drivers that talk to the v4l 45 radios, and any other drivers that talk to the v4l
46 subsystem. 46 subsystem.
47net/ - This is for network drivers. 47../net/ - This is for network drivers.
48serial/ - This is for USB to serial drivers. 48serial/ - This is for USB to serial drivers.
49storage/ - This is for USB mass-storage drivers. 49storage/ - This is for USB mass-storage drivers.
50class/ - This is for all USB device drivers that do not fit 50class/ - This is for all USB device drivers that do not fit
diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c
index 8586817698ad..c51f8e9312e0 100644
--- a/drivers/usb/core/driver.c
+++ b/drivers/usb/core/driver.c
@@ -585,9 +585,6 @@ static int usb_uevent(struct device *dev, struct kobj_uevent_env *env)
585{ 585{
586 struct usb_device *usb_dev; 586 struct usb_device *usb_dev;
587 587
588 if (!dev)
589 return -ENODEV;
590
591 /* driver is often null here; dev_dbg() would oops */ 588 /* driver is often null here; dev_dbg() would oops */
592 pr_debug ("usb %s: uevent\n", dev->bus_id); 589 pr_debug ("usb %s: uevent\n", dev->bus_id);
593 590
@@ -631,14 +628,6 @@ static int usb_uevent(struct device *dev, struct kobj_uevent_env *env)
631 usb_dev->descriptor.bDeviceProtocol)) 628 usb_dev->descriptor.bDeviceProtocol))
632 return -ENOMEM; 629 return -ENOMEM;
633 630
634 if (add_uevent_var(env, "BUSNUM=%03d",
635 usb_dev->bus->busnum))
636 return -ENOMEM;
637
638 if (add_uevent_var(env, "DEVNUM=%03d",
639 usb_dev->devnum))
640 return -ENOMEM;
641
642 return 0; 631 return 0;
643} 632}
644 633
diff --git a/drivers/usb/core/hcd-pci.c b/drivers/usb/core/hcd-pci.c
index 5cf6d5f9acbd..3fb9af80cbf4 100644
--- a/drivers/usb/core/hcd-pci.c
+++ b/drivers/usb/core/hcd-pci.c
@@ -125,7 +125,7 @@ int usb_hcd_pci_probe (struct pci_dev *dev, const struct pci_device_id *id)
125 125
126 pci_set_master (dev); 126 pci_set_master (dev);
127 127
128 retval = usb_add_hcd (hcd, dev->irq, IRQF_SHARED); 128 retval = usb_add_hcd(hcd, dev->irq, IRQF_DISABLED | IRQF_SHARED);
129 if (retval != 0) 129 if (retval != 0)
130 goto err4; 130 goto err4;
131 return retval; 131 return retval;
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index fea8256a18d6..d5ed3fa9e304 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -1311,8 +1311,8 @@ void usb_hcd_flush_endpoint(struct usb_device *udev,
1311 hcd = bus_to_hcd(udev->bus); 1311 hcd = bus_to_hcd(udev->bus);
1312 1312
1313 /* No more submits can occur */ 1313 /* No more submits can occur */
1314rescan:
1315 spin_lock_irq(&hcd_urb_list_lock); 1314 spin_lock_irq(&hcd_urb_list_lock);
1315rescan:
1316 list_for_each_entry (urb, &ep->urb_list, urb_list) { 1316 list_for_each_entry (urb, &ep->urb_list, urb_list) {
1317 int is_in; 1317 int is_in;
1318 1318
@@ -1345,6 +1345,7 @@ rescan:
1345 usb_put_urb (urb); 1345 usb_put_urb (urb);
1346 1346
1347 /* list contents may have changed */ 1347 /* list contents may have changed */
1348 spin_lock(&hcd_urb_list_lock);
1348 goto rescan; 1349 goto rescan;
1349 } 1350 }
1350 spin_unlock_irq(&hcd_urb_list_lock); 1351 spin_unlock_irq(&hcd_urb_list_lock);
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 036c3dea855e..b04d232d4c65 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -335,7 +335,7 @@ static void kick_khubd(struct usb_hub *hub)
335 to_usb_interface(hub->intfdev)->pm_usage_cnt = 1; 335 to_usb_interface(hub->intfdev)->pm_usage_cnt = 1;
336 336
337 spin_lock_irqsave(&hub_event_lock, flags); 337 spin_lock_irqsave(&hub_event_lock, flags);
338 if (!hub->disconnected & list_empty(&hub->event_list)) { 338 if (!hub->disconnected && list_empty(&hub->event_list)) {
339 list_add_tail(&hub->event_list, &hub_event_list); 339 list_add_tail(&hub->event_list, &hub_event_list);
340 wake_up(&khubd_wait); 340 wake_up(&khubd_wait);
341 } 341 }
@@ -522,9 +522,9 @@ static void hub_quiesce(struct usb_hub *hub)
522 /* (blocking) stop khubd and related activity */ 522 /* (blocking) stop khubd and related activity */
523 usb_kill_urb(hub->urb); 523 usb_kill_urb(hub->urb);
524 if (hub->has_indicators) 524 if (hub->has_indicators)
525 cancel_delayed_work(&hub->leds); 525 cancel_delayed_work_sync(&hub->leds);
526 if (hub->has_indicators || hub->tt.hub) 526 if (hub->tt.hub)
527 flush_scheduled_work(); 527 cancel_work_sync(&hub->tt.kevent);
528} 528}
529 529
530static void hub_activate(struct usb_hub *hub) 530static void hub_activate(struct usb_hub *hub)
diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
index 316a746e0080..fcd40ecbeecc 100644
--- a/drivers/usb/core/message.c
+++ b/drivers/usb/core/message.c
@@ -1172,7 +1172,6 @@ int usb_set_interface(struct usb_device *dev, int interface, int alternate)
1172 struct usb_host_interface *alt; 1172 struct usb_host_interface *alt;
1173 int ret; 1173 int ret;
1174 int manual = 0; 1174 int manual = 0;
1175 int changed;
1176 1175
1177 if (dev->state == USB_STATE_SUSPENDED) 1176 if (dev->state == USB_STATE_SUSPENDED)
1178 return -EHOSTUNREACH; 1177 return -EHOSTUNREACH;
@@ -1212,8 +1211,7 @@ int usb_set_interface(struct usb_device *dev, int interface, int alternate)
1212 */ 1211 */
1213 1212
1214 /* prevent submissions using previous endpoint settings */ 1213 /* prevent submissions using previous endpoint settings */
1215 changed = (iface->cur_altsetting != alt); 1214 if (iface->cur_altsetting != alt && device_is_registered(&iface->dev))
1216 if (changed && device_is_registered(&iface->dev))
1217 usb_remove_sysfs_intf_files(iface); 1215 usb_remove_sysfs_intf_files(iface);
1218 usb_disable_interface(dev, iface); 1216 usb_disable_interface(dev, iface);
1219 1217
@@ -1250,7 +1248,7 @@ int usb_set_interface(struct usb_device *dev, int interface, int alternate)
1250 * (Likewise, EP0 never "halts" on well designed devices.) 1248 * (Likewise, EP0 never "halts" on well designed devices.)
1251 */ 1249 */
1252 usb_enable_interface(dev, iface); 1250 usb_enable_interface(dev, iface);
1253 if (changed && device_is_registered(&iface->dev)) 1251 if (device_is_registered(&iface->dev))
1254 usb_create_sysfs_intf_files(iface); 1252 usb_create_sysfs_intf_files(iface);
1255 1253
1256 return 0; 1254 return 0;
@@ -1348,34 +1346,10 @@ static int usb_if_uevent(struct device *dev, struct kobj_uevent_env *env)
1348 struct usb_interface *intf; 1346 struct usb_interface *intf;
1349 struct usb_host_interface *alt; 1347 struct usb_host_interface *alt;
1350 1348
1351 if (!dev)
1352 return -ENODEV;
1353
1354 /* driver is often null here; dev_dbg() would oops */
1355 pr_debug ("usb %s: uevent\n", dev->bus_id);
1356
1357 intf = to_usb_interface(dev); 1349 intf = to_usb_interface(dev);
1358 usb_dev = interface_to_usbdev(intf); 1350 usb_dev = interface_to_usbdev(intf);
1359 alt = intf->cur_altsetting; 1351 alt = intf->cur_altsetting;
1360 1352
1361#ifdef CONFIG_USB_DEVICEFS
1362 if (add_uevent_var(env, "DEVICE=/proc/bus/usb/%03d/%03d",
1363 usb_dev->bus->busnum, usb_dev->devnum))
1364 return -ENOMEM;
1365#endif
1366
1367 if (add_uevent_var(env, "PRODUCT=%x/%x/%x",
1368 le16_to_cpu(usb_dev->descriptor.idVendor),
1369 le16_to_cpu(usb_dev->descriptor.idProduct),
1370 le16_to_cpu(usb_dev->descriptor.bcdDevice)))
1371 return -ENOMEM;
1372
1373 if (add_uevent_var(env, "TYPE=%d/%d/%d",
1374 usb_dev->descriptor.bDeviceClass,
1375 usb_dev->descriptor.bDeviceSubClass,
1376 usb_dev->descriptor.bDeviceProtocol))
1377 return -ENOMEM;
1378
1379 if (add_uevent_var(env, "INTERFACE=%d/%d/%d", 1353 if (add_uevent_var(env, "INTERFACE=%d/%d/%d",
1380 alt->desc.bInterfaceClass, 1354 alt->desc.bInterfaceClass,
1381 alt->desc.bInterfaceSubClass, 1355 alt->desc.bInterfaceSubClass,
@@ -1641,12 +1615,6 @@ free_interfaces:
1641 intf->dev.bus_id, ret); 1615 intf->dev.bus_id, ret);
1642 continue; 1616 continue;
1643 } 1617 }
1644
1645 /* The driver's probe method can call usb_set_interface(),
1646 * which would mean the interface's sysfs files are already
1647 * created. Just in case, we'll remove them first.
1648 */
1649 usb_remove_sysfs_intf_files(intf);
1650 usb_create_sysfs_intf_files(intf); 1618 usb_create_sysfs_intf_files(intf);
1651 } 1619 }
1652 1620
diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
index b04afd06e502..32bd130b1eed 100644
--- a/drivers/usb/core/sysfs.c
+++ b/drivers/usb/core/sysfs.c
@@ -735,6 +735,8 @@ int usb_create_sysfs_intf_files(struct usb_interface *intf)
735 struct usb_host_interface *alt = intf->cur_altsetting; 735 struct usb_host_interface *alt = intf->cur_altsetting;
736 int retval; 736 int retval;
737 737
738 if (intf->sysfs_files_created)
739 return 0;
738 retval = sysfs_create_group(&dev->kobj, &intf_attr_grp); 740 retval = sysfs_create_group(&dev->kobj, &intf_attr_grp);
739 if (retval) 741 if (retval)
740 return retval; 742 return retval;
@@ -746,6 +748,7 @@ int usb_create_sysfs_intf_files(struct usb_interface *intf)
746 if (intf->intf_assoc) 748 if (intf->intf_assoc)
747 retval = sysfs_create_group(&dev->kobj, &intf_assoc_attr_grp); 749 retval = sysfs_create_group(&dev->kobj, &intf_assoc_attr_grp);
748 usb_create_intf_ep_files(intf, udev); 750 usb_create_intf_ep_files(intf, udev);
751 intf->sysfs_files_created = 1;
749 return 0; 752 return 0;
750} 753}
751 754
@@ -753,8 +756,11 @@ void usb_remove_sysfs_intf_files(struct usb_interface *intf)
753{ 756{
754 struct device *dev = &intf->dev; 757 struct device *dev = &intf->dev;
755 758
759 if (!intf->sysfs_files_created)
760 return;
756 usb_remove_intf_ep_files(intf); 761 usb_remove_intf_ep_files(intf);
757 device_remove_file(dev, &dev_attr_interface); 762 device_remove_file(dev, &dev_attr_interface);
758 sysfs_remove_group(&dev->kobj, &intf_attr_grp); 763 sysfs_remove_group(&dev->kobj, &intf_attr_grp);
759 sysfs_remove_group(&intf->dev.kobj, &intf_assoc_attr_grp); 764 sysfs_remove_group(&intf->dev.kobj, &intf_assoc_attr_grp);
765 intf->sysfs_files_created = 0;
760} 766}
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index c4a6f1095b8b..8f142370103d 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -192,9 +192,34 @@ static void usb_release_dev(struct device *dev)
192 kfree(udev); 192 kfree(udev);
193} 193}
194 194
195#ifdef CONFIG_HOTPLUG
196static int usb_dev_uevent(struct device *dev, struct kobj_uevent_env *env)
197{
198 struct usb_device *usb_dev;
199
200 usb_dev = to_usb_device(dev);
201
202 if (add_uevent_var(env, "BUSNUM=%03d", usb_dev->bus->busnum))
203 return -ENOMEM;
204
205 if (add_uevent_var(env, "DEVNUM=%03d", usb_dev->devnum))
206 return -ENOMEM;
207
208 return 0;
209}
210
211#else
212
213static int usb_dev_uevent(struct device *dev, struct kobj_uevent_env *env)
214{
215 return -ENODEV;
216}
217#endif /* CONFIG_HOTPLUG */
218
195struct device_type usb_device_type = { 219struct device_type usb_device_type = {
196 .name = "usb_device", 220 .name = "usb_device",
197 .release = usb_release_dev, 221 .release = usb_release_dev,
222 .uevent = usb_dev_uevent,
198}; 223};
199 224
200#ifdef CONFIG_PM 225#ifdef CONFIG_PM
diff --git a/drivers/usb/gadget/at91_udc.c b/drivers/usb/gadget/at91_udc.c
index a6adf7e0f6f8..cd62b029d176 100644
--- a/drivers/usb/gadget/at91_udc.c
+++ b/drivers/usb/gadget/at91_udc.c
@@ -887,6 +887,7 @@ static void pullup(struct at91_udc *udc, int is_on)
887 887
888 if (is_on) { 888 if (is_on) {
889 clk_on(udc); 889 clk_on(udc);
890 at91_udp_write(udc, AT91_UDP_ICR, AT91_UDP_RXRSM);
890 at91_udp_write(udc, AT91_UDP_TXVC, 0); 891 at91_udp_write(udc, AT91_UDP_TXVC, 0);
891 if (cpu_is_at91rm9200()) 892 if (cpu_is_at91rm9200())
892 at91_set_gpio_value(udc->board.pullup_pin, 1); 893 at91_set_gpio_value(udc->board.pullup_pin, 1);
@@ -904,6 +905,7 @@ static void pullup(struct at91_udc *udc, int is_on)
904 } 905 }
905 } else { 906 } else {
906 stop_activity(udc); 907 stop_activity(udc);
908 at91_udp_write(udc, AT91_UDP_IDR, AT91_UDP_RXRSM);
907 at91_udp_write(udc, AT91_UDP_TXVC, AT91_UDP_TXVC_TXVDIS); 909 at91_udp_write(udc, AT91_UDP_TXVC, AT91_UDP_TXVC_TXVDIS);
908 if (cpu_is_at91rm9200()) 910 if (cpu_is_at91rm9200())
909 at91_set_gpio_value(udc->board.pullup_pin, 0); 911 at91_set_gpio_value(udc->board.pullup_pin, 0);
diff --git a/drivers/usb/gadget/fsl_usb2_udc.c b/drivers/usb/gadget/fsl_usb2_udc.c
index 9bb7f64a85cd..038e7d7b4da1 100644
--- a/drivers/usb/gadget/fsl_usb2_udc.c
+++ b/drivers/usb/gadget/fsl_usb2_udc.c
@@ -1318,7 +1318,7 @@ static void setup_received_irq(struct fsl_udc *udc,
1318 | USB_TYPE_STANDARD)) { 1318 | USB_TYPE_STANDARD)) {
1319 /* Note: The driver has not include OTG support yet. 1319 /* Note: The driver has not include OTG support yet.
1320 * This will be set when OTG support is added */ 1320 * This will be set when OTG support is added */
1321 if (!gadget_is_otg(udc->gadget)) 1321 if (!gadget_is_otg(&udc->gadget))
1322 break; 1322 break;
1323 else if (setup->bRequest == USB_DEVICE_B_HNP_ENABLE) 1323 else if (setup->bRequest == USB_DEVICE_B_HNP_ENABLE)
1324 udc->gadget.b_hnp_enable = 1; 1324 udc->gadget.b_hnp_enable = 1;
diff --git a/drivers/usb/gadget/omap_udc.c b/drivers/usb/gadget/omap_udc.c
index 87c4f50dfb61..d377154658b5 100644
--- a/drivers/usb/gadget/omap_udc.c
+++ b/drivers/usb/gadget/omap_udc.c
@@ -1241,14 +1241,14 @@ static void pullup_enable(struct omap_udc *udc)
1241 udc->gadget.dev.parent->power.power_state = PMSG_ON; 1241 udc->gadget.dev.parent->power.power_state = PMSG_ON;
1242 udc->gadget.dev.power.power_state = PMSG_ON; 1242 udc->gadget.dev.power.power_state = PMSG_ON;
1243 UDC_SYSCON1_REG |= UDC_PULLUP_EN; 1243 UDC_SYSCON1_REG |= UDC_PULLUP_EN;
1244 if (!gadget_is_otg(udc->gadget) && !cpu_is_omap15xx()) 1244 if (!gadget_is_otg(&udc->gadget) && !cpu_is_omap15xx())
1245 OTG_CTRL_REG |= OTG_BSESSVLD; 1245 OTG_CTRL_REG |= OTG_BSESSVLD;
1246 UDC_IRQ_EN_REG = UDC_DS_CHG_IE; 1246 UDC_IRQ_EN_REG = UDC_DS_CHG_IE;
1247} 1247}
1248 1248
1249static void pullup_disable(struct omap_udc *udc) 1249static void pullup_disable(struct omap_udc *udc)
1250{ 1250{
1251 if (!gadget_is_otg(udc->gadget) && !cpu_is_omap15xx()) 1251 if (!gadget_is_otg(&udc->gadget) && !cpu_is_omap15xx())
1252 OTG_CTRL_REG &= ~OTG_BSESSVLD; 1252 OTG_CTRL_REG &= ~OTG_BSESSVLD;
1253 UDC_IRQ_EN_REG = UDC_DS_CHG_IE; 1253 UDC_IRQ_EN_REG = UDC_DS_CHG_IE;
1254 UDC_SYSCON1_REG &= ~UDC_PULLUP_EN; 1254 UDC_SYSCON1_REG &= ~UDC_PULLUP_EN;
@@ -1386,7 +1386,7 @@ static void update_otg(struct omap_udc *udc)
1386{ 1386{
1387 u16 devstat; 1387 u16 devstat;
1388 1388
1389 if (!gadget_is_otg(udc->gadget)) 1389 if (!gadget_is_otg(&udc->gadget))
1390 return; 1390 return;
1391 1391
1392 if (OTG_CTRL_REG & OTG_ID) 1392 if (OTG_CTRL_REG & OTG_ID)
diff --git a/drivers/usb/gadget/s3c2410_udc.c b/drivers/usb/gadget/s3c2410_udc.c
index e3e90f8a75e7..4ce050c3d13f 100644
--- a/drivers/usb/gadget/s3c2410_udc.c
+++ b/drivers/usb/gadget/s3c2410_udc.c
@@ -52,10 +52,10 @@
52#include <asm/arch/irqs.h> 52#include <asm/arch/irqs.h>
53 53
54#include <asm/arch/hardware.h> 54#include <asm/arch/hardware.h>
55#include <asm/arch/regs-clock.h>
56#include <asm/arch/regs-gpio.h> 55#include <asm/arch/regs-gpio.h>
57#include <asm/arch/regs-udc.h> 56
58#include <asm/arch/udc.h> 57#include <asm/plat-s3c24xx/regs-udc.h>
58#include <asm/plat-s3c24xx/udc.h>
59 59
60#include <asm/mach-types.h> 60#include <asm/mach-types.h>
61 61
@@ -1511,7 +1511,11 @@ static irqreturn_t s3c2410_udc_vbus_irq(int irq, void *_dev)
1511 unsigned int value; 1511 unsigned int value;
1512 1512
1513 dprintk(DEBUG_NORMAL, "%s()\n", __func__); 1513 dprintk(DEBUG_NORMAL, "%s()\n", __func__);
1514
1515 /* some cpus cannot read from an line configured to IRQ! */
1516 s3c2410_gpio_cfgpin(udc_info->vbus_pin, S3C2410_GPIO_INPUT);
1514 value = s3c2410_gpio_getpin(udc_info->vbus_pin); 1517 value = s3c2410_gpio_getpin(udc_info->vbus_pin);
1518 s3c2410_gpio_cfgpin(udc_info->vbus_pin, S3C2410_GPIO_SFN2);
1515 1519
1516 if (udc_info->vbus_pin_inverted) 1520 if (udc_info->vbus_pin_inverted)
1517 value = !value; 1521 value = !value;
@@ -1872,9 +1876,9 @@ static int s3c2410_udc_probe(struct platform_device *pdev)
1872 if (udc_info && udc_info->vbus_pin > 0) { 1876 if (udc_info && udc_info->vbus_pin > 0) {
1873 irq = s3c2410_gpio_getirq(udc_info->vbus_pin); 1877 irq = s3c2410_gpio_getirq(udc_info->vbus_pin);
1874 retval = request_irq(irq, s3c2410_udc_vbus_irq, 1878 retval = request_irq(irq, s3c2410_udc_vbus_irq,
1875 IRQF_DISABLED | IRQF_TRIGGER_RISING 1879 IRQF_DISABLED | IRQF_TRIGGER_RISING
1876 | IRQF_TRIGGER_FALLING, 1880 | IRQF_TRIGGER_FALLING | IRQF_SHARED,
1877 gadget_name, udc); 1881 gadget_name, udc);
1878 1882
1879 if (retval != 0) { 1883 if (retval != 0) {
1880 dev_err(dev, "can't get vbus irq %i, err %d\n", 1884 dev_err(dev, "can't get vbus irq %i, err %d\n",
diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
index 177e78ed241b..49a91c5ee51b 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -156,7 +156,7 @@ config USB_OHCI_HCD_PCI
156 156
157config USB_OHCI_HCD_SSB 157config USB_OHCI_HCD_SSB
158 bool "OHCI support for Broadcom SSB OHCI core" 158 bool "OHCI support for Broadcom SSB OHCI core"
159 depends on USB_OHCI_HCD && (SSB = y || SSB = CONFIG_USB_OHCI_HCD) && EXPERIMENTAL 159 depends on USB_OHCI_HCD && (SSB = y || SSB = USB_OHCI_HCD) && EXPERIMENTAL
160 default n 160 default n
161 ---help--- 161 ---help---
162 Support for the Sonics Silicon Backplane (SSB) attached 162 Support for the Sonics Silicon Backplane (SSB) attached
diff --git a/drivers/usb/host/ehci-fsl.c b/drivers/usb/host/ehci-fsl.c
index b7b7bfbce527..430821cb95c8 100644
--- a/drivers/usb/host/ehci-fsl.c
+++ b/drivers/usb/host/ehci-fsl.c
@@ -122,7 +122,7 @@ int usb_hcd_fsl_probe(const struct hc_driver *driver,
122 temp = in_le32(hcd->regs + 0x1a8); 122 temp = in_le32(hcd->regs + 0x1a8);
123 out_le32(hcd->regs + 0x1a8, temp | 0x3); 123 out_le32(hcd->regs + 0x1a8, temp | 0x3);
124 124
125 retval = usb_add_hcd(hcd, irq, IRQF_SHARED); 125 retval = usb_add_hcd(hcd, irq, IRQF_DISABLED | IRQF_SHARED);
126 if (retval != 0) 126 if (retval != 0)
127 goto err4; 127 goto err4;
128 return retval; 128 return retval;
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index c1514442883e..5f2d74ed5ad7 100644
--- a/drivers/usb/host/ehci-hcd.c
+++ b/drivers/usb/host/ehci-hcd.c
@@ -575,12 +575,15 @@ static int ehci_run (struct usb_hcd *hcd)
575 * from the companions to the EHCI controller. If any of the 575 * from the companions to the EHCI controller. If any of the
576 * companions are in the middle of a port reset at the time, it 576 * companions are in the middle of a port reset at the time, it
577 * could cause trouble. Write-locking ehci_cf_port_reset_rwsem 577 * could cause trouble. Write-locking ehci_cf_port_reset_rwsem
578 * guarantees that no resets are in progress. 578 * guarantees that no resets are in progress. After we set CF,
579 * a short delay lets the hardware catch up; new resets shouldn't
580 * be started before the port switching actions could complete.
579 */ 581 */
580 down_write(&ehci_cf_port_reset_rwsem); 582 down_write(&ehci_cf_port_reset_rwsem);
581 hcd->state = HC_STATE_RUNNING; 583 hcd->state = HC_STATE_RUNNING;
582 ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag); 584 ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag);
583 ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */ 585 ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */
586 msleep(5);
584 up_write(&ehci_cf_port_reset_rwsem); 587 up_write(&ehci_cf_port_reset_rwsem);
585 588
586 temp = HC_VERSION(ehci_readl(ehci, &ehci->caps->hc_capbase)); 589 temp = HC_VERSION(ehci_readl(ehci, &ehci->caps->hc_capbase));
diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c
index 704f33fdd2f1..ecfe800fd720 100644
--- a/drivers/usb/host/ohci-hcd.c
+++ b/drivers/usb/host/ohci-hcd.c
@@ -732,24 +732,27 @@ static irqreturn_t ohci_irq (struct usb_hcd *hcd)
732 struct ohci_regs __iomem *regs = ohci->regs; 732 struct ohci_regs __iomem *regs = ohci->regs;
733 int ints; 733 int ints;
734 734
735 /* we can eliminate a (slow) ohci_readl() 735 /* Read interrupt status (and flush pending writes). We ignore the
736 * if _only_ WDH caused this irq 736 * optimization of checking the LSB of hcca->done_head; it doesn't
737 * work on all systems (edge triggering for OHCI can be a factor).
737 */ 738 */
738 if ((ohci->hcca->done_head != 0) 739 ints = ohci_readl(ohci, &regs->intrstatus);
739 && ! (hc32_to_cpup (ohci, &ohci->hcca->done_head)
740 & 0x01)) {
741 ints = OHCI_INTR_WDH;
742 740
743 /* cardbus/... hardware gone before remove() */ 741 /* Check for an all 1's result which is a typical consequence
744 } else if ((ints = ohci_readl (ohci, &regs->intrstatus)) == ~(u32)0) { 742 * of dead, unclocked, or unplugged (CardBus...) devices
743 */
744 if (ints == ~(u32)0) {
745 disable (ohci); 745 disable (ohci);
746 ohci_dbg (ohci, "device removed!\n"); 746 ohci_dbg (ohci, "device removed!\n");
747 return IRQ_HANDLED; 747 return IRQ_HANDLED;
748 }
749
750 /* We only care about interrupts that are enabled */
751 ints &= ohci_readl(ohci, &regs->intrenable);
748 752
749 /* interrupt for some other device? */ 753 /* interrupt for some other device? */
750 } else if ((ints &= ohci_readl (ohci, &regs->intrenable)) == 0) { 754 if (ints == 0)
751 return IRQ_NOTMINE; 755 return IRQ_NOTMINE;
752 }
753 756
754 if (ints & OHCI_INTR_UE) { 757 if (ints & OHCI_INTR_UE) {
755 // e.g. due to PCI Master/Target Abort 758 // e.g. due to PCI Master/Target Abort
diff --git a/drivers/usb/host/ohci-ppc-of.c b/drivers/usb/host/ohci-ppc-of.c
index 0a7426920150..0c3e6b790b7b 100644
--- a/drivers/usb/host/ohci-ppc-of.c
+++ b/drivers/usb/host/ohci-ppc-of.c
@@ -142,7 +142,7 @@ ohci_hcd_ppc_of_probe(struct of_device *op, const struct of_device_id *match)
142 142
143 ohci_hcd_init(ohci); 143 ohci_hcd_init(ohci);
144 144
145 rv = usb_add_hcd(hcd, irq, 0); 145 rv = usb_add_hcd(hcd, irq, IRQF_DISABLED);
146 if (rv == 0) 146 if (rv == 0)
147 return 0; 147 return 0;
148 148
diff --git a/drivers/usb/host/ohci-ssb.c b/drivers/usb/host/ohci-ssb.c
index fe70e72340de..6e9c2d6db887 100644
--- a/drivers/usb/host/ohci-ssb.c
+++ b/drivers/usb/host/ohci-ssb.c
@@ -160,7 +160,7 @@ static int ssb_ohci_attach(struct ssb_device *dev)
160 hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len); 160 hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len);
161 if (!hcd->regs) 161 if (!hcd->regs)
162 goto err_put_hcd; 162 goto err_put_hcd;
163 err = usb_add_hcd(hcd, dev->irq, IRQF_SHARED); 163 err = usb_add_hcd(hcd, dev->irq, IRQF_DISABLED | IRQF_SHARED);
164 if (err) 164 if (err)
165 goto err_iounmap; 165 goto err_iounmap;
166 166
diff --git a/drivers/usb/host/r8a66597-hcd.c b/drivers/usb/host/r8a66597-hcd.c
index ae8ec4474eb8..0ce2fc5e396b 100644
--- a/drivers/usb/host/r8a66597-hcd.c
+++ b/drivers/usb/host/r8a66597-hcd.c
@@ -2197,7 +2197,7 @@ static int __init r8a66597_probe(struct platform_device *pdev)
2197 INIT_LIST_HEAD(&r8a66597->child_device); 2197 INIT_LIST_HEAD(&r8a66597->child_device);
2198 2198
2199 hcd->rsrc_start = res->start; 2199 hcd->rsrc_start = res->start;
2200 ret = usb_add_hcd(hcd, irq, 0); 2200 ret = usb_add_hcd(hcd, irq, IRQF_DISABLED);
2201 if (ret != 0) { 2201 if (ret != 0) {
2202 err("Failed to add hcd"); 2202 err("Failed to add hcd");
2203 goto clean_up; 2203 goto clean_up;
diff --git a/drivers/usb/host/uhci-hcd.c b/drivers/usb/host/uhci-hcd.c
index 4db17f75f4f1..ec987897b8ed 100644
--- a/drivers/usb/host/uhci-hcd.c
+++ b/drivers/usb/host/uhci-hcd.c
@@ -378,7 +378,6 @@ static irqreturn_t uhci_irq(struct usb_hcd *hcd)
378{ 378{
379 struct uhci_hcd *uhci = hcd_to_uhci(hcd); 379 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
380 unsigned short status; 380 unsigned short status;
381 unsigned long flags;
382 381
383 /* 382 /*
384 * Read the interrupt status, and write it back to clear the 383 * Read the interrupt status, and write it back to clear the
@@ -398,7 +397,7 @@ static irqreturn_t uhci_irq(struct usb_hcd *hcd)
398 dev_err(uhci_dev(uhci), "host controller process " 397 dev_err(uhci_dev(uhci), "host controller process "
399 "error, something bad happened!\n"); 398 "error, something bad happened!\n");
400 if (status & USBSTS_HCH) { 399 if (status & USBSTS_HCH) {
401 spin_lock_irqsave(&uhci->lock, flags); 400 spin_lock(&uhci->lock);
402 if (uhci->rh_state >= UHCI_RH_RUNNING) { 401 if (uhci->rh_state >= UHCI_RH_RUNNING) {
403 dev_err(uhci_dev(uhci), 402 dev_err(uhci_dev(uhci),
404 "host controller halted, " 403 "host controller halted, "
@@ -415,16 +414,16 @@ static irqreturn_t uhci_irq(struct usb_hcd *hcd)
415 * pending unlinks */ 414 * pending unlinks */
416 mod_timer(&hcd->rh_timer, jiffies); 415 mod_timer(&hcd->rh_timer, jiffies);
417 } 416 }
418 spin_unlock_irqrestore(&uhci->lock, flags); 417 spin_unlock(&uhci->lock);
419 } 418 }
420 } 419 }
421 420
422 if (status & USBSTS_RD) 421 if (status & USBSTS_RD)
423 usb_hcd_poll_rh_status(hcd); 422 usb_hcd_poll_rh_status(hcd);
424 else { 423 else {
425 spin_lock_irqsave(&uhci->lock, flags); 424 spin_lock(&uhci->lock);
426 uhci_scan_schedule(uhci); 425 uhci_scan_schedule(uhci);
427 spin_unlock_irqrestore(&uhci->lock, flags); 426 spin_unlock(&uhci->lock);
428 } 427 }
429 428
430 return IRQ_HANDLED; 429 return IRQ_HANDLED;
diff --git a/drivers/usb/image/microtek.c b/drivers/usb/image/microtek.c
index 91e999c9f680..bc207e3c21f5 100644
--- a/drivers/usb/image/microtek.c
+++ b/drivers/usb/image/microtek.c
@@ -819,7 +819,7 @@ static int mts_usb_probe(struct usb_interface *intf,
819 goto out_kfree2; 819 goto out_kfree2;
820 820
821 new_desc->host->hostdata[0] = (unsigned long)new_desc; 821 new_desc->host->hostdata[0] = (unsigned long)new_desc;
822 if (scsi_add_host(new_desc->host, NULL)) { 822 if (scsi_add_host(new_desc->host, &dev->dev)) {
823 err_retval = -EIO; 823 err_retval = -EIO;
824 goto out_host_put; 824 goto out_host_put;
825 } 825 }
diff --git a/drivers/usb/misc/adutux.c b/drivers/usb/misc/adutux.c
index c567aa7a41ea..5a2c44e4c1f7 100644
--- a/drivers/usb/misc/adutux.c
+++ b/drivers/usb/misc/adutux.c
@@ -79,12 +79,22 @@ MODULE_DEVICE_TABLE(usb, device_table);
79 79
80#define COMMAND_TIMEOUT (2*HZ) /* 60 second timeout for a command */ 80#define COMMAND_TIMEOUT (2*HZ) /* 60 second timeout for a command */
81 81
82/*
83 * The locking scheme is a vanilla 3-lock:
84 * adu_device.buflock: A spinlock, covers what IRQs touch.
85 * adutux_mutex: A Static lock to cover open_count. It would also cover
86 * any globals, but we don't have them in 2.6.
87 * adu_device.mtx: A mutex to hold across sleepers like copy_from_user.
88 * It covers all of adu_device, except the open_count
89 * and what .buflock covers.
90 */
91
82/* Structure to hold all of our device specific stuff */ 92/* Structure to hold all of our device specific stuff */
83struct adu_device { 93struct adu_device {
84 struct mutex mtx; /* locks this structure */ 94 struct mutex mtx;
85 struct usb_device* udev; /* save off the usb device pointer */ 95 struct usb_device* udev; /* save off the usb device pointer */
86 struct usb_interface* interface; 96 struct usb_interface* interface;
87 unsigned char minor; /* the starting minor number for this device */ 97 unsigned int minor; /* the starting minor number for this device */
88 char serial_number[8]; 98 char serial_number[8];
89 99
90 int open_count; /* number of times this port has been opened */ 100 int open_count; /* number of times this port has been opened */
@@ -107,8 +117,11 @@ struct adu_device {
107 char* interrupt_out_buffer; 117 char* interrupt_out_buffer;
108 struct usb_endpoint_descriptor* interrupt_out_endpoint; 118 struct usb_endpoint_descriptor* interrupt_out_endpoint;
109 struct urb* interrupt_out_urb; 119 struct urb* interrupt_out_urb;
120 int out_urb_finished;
110}; 121};
111 122
123static DEFINE_MUTEX(adutux_mutex);
124
112static struct usb_driver adu_driver; 125static struct usb_driver adu_driver;
113 126
114static void adu_debug_data(int level, const char *function, int size, 127static void adu_debug_data(int level, const char *function, int size,
@@ -132,27 +145,31 @@ static void adu_debug_data(int level, const char *function, int size,
132 */ 145 */
133static void adu_abort_transfers(struct adu_device *dev) 146static void adu_abort_transfers(struct adu_device *dev)
134{ 147{
135 dbg(2," %s : enter", __FUNCTION__); 148 unsigned long flags;
136 149
137 if (dev == NULL) { 150 dbg(2," %s : enter", __FUNCTION__);
138 dbg(1," %s : dev is null", __FUNCTION__);
139 goto exit;
140 }
141 151
142 if (dev->udev == NULL) { 152 if (dev->udev == NULL) {
143 dbg(1," %s : udev is null", __FUNCTION__); 153 dbg(1," %s : udev is null", __FUNCTION__);
144 goto exit; 154 goto exit;
145 } 155 }
146 156
147 dbg(2," %s : udev state %d", __FUNCTION__, dev->udev->state);
148 if (dev->udev->state == USB_STATE_NOTATTACHED) {
149 dbg(1," %s : udev is not attached", __FUNCTION__);
150 goto exit;
151 }
152
153 /* shutdown transfer */ 157 /* shutdown transfer */
154 usb_unlink_urb(dev->interrupt_in_urb); 158
155 usb_unlink_urb(dev->interrupt_out_urb); 159 /* XXX Anchor these instead */
160 spin_lock_irqsave(&dev->buflock, flags);
161 if (!dev->read_urb_finished) {
162 spin_unlock_irqrestore(&dev->buflock, flags);
163 usb_kill_urb(dev->interrupt_in_urb);
164 } else
165 spin_unlock_irqrestore(&dev->buflock, flags);
166
167 spin_lock_irqsave(&dev->buflock, flags);
168 if (!dev->out_urb_finished) {
169 spin_unlock_irqrestore(&dev->buflock, flags);
170 usb_kill_urb(dev->interrupt_out_urb);
171 } else
172 spin_unlock_irqrestore(&dev->buflock, flags);
156 173
157exit: 174exit:
158 dbg(2," %s : leave", __FUNCTION__); 175 dbg(2," %s : leave", __FUNCTION__);
@@ -162,8 +179,6 @@ static void adu_delete(struct adu_device *dev)
162{ 179{
163 dbg(2, "%s enter", __FUNCTION__); 180 dbg(2, "%s enter", __FUNCTION__);
164 181
165 adu_abort_transfers(dev);
166
167 /* free data structures */ 182 /* free data structures */
168 usb_free_urb(dev->interrupt_in_urb); 183 usb_free_urb(dev->interrupt_in_urb);
169 usb_free_urb(dev->interrupt_out_urb); 184 usb_free_urb(dev->interrupt_out_urb);
@@ -239,7 +254,10 @@ static void adu_interrupt_out_callback(struct urb *urb)
239 goto exit; 254 goto exit;
240 } 255 }
241 256
242 wake_up_interruptible(&dev->write_wait); 257 spin_lock(&dev->buflock);
258 dev->out_urb_finished = 1;
259 wake_up(&dev->write_wait);
260 spin_unlock(&dev->buflock);
243exit: 261exit:
244 262
245 adu_debug_data(5, __FUNCTION__, urb->actual_length, 263 adu_debug_data(5, __FUNCTION__, urb->actual_length,
@@ -252,12 +270,17 @@ static int adu_open(struct inode *inode, struct file *file)
252 struct adu_device *dev = NULL; 270 struct adu_device *dev = NULL;
253 struct usb_interface *interface; 271 struct usb_interface *interface;
254 int subminor; 272 int subminor;
255 int retval = 0; 273 int retval;
256 274
257 dbg(2,"%s : enter", __FUNCTION__); 275 dbg(2,"%s : enter", __FUNCTION__);
258 276
259 subminor = iminor(inode); 277 subminor = iminor(inode);
260 278
279 if ((retval = mutex_lock_interruptible(&adutux_mutex))) {
280 dbg(2, "%s : mutex lock failed", __FUNCTION__);
281 goto exit_no_lock;
282 }
283
261 interface = usb_find_interface(&adu_driver, subminor); 284 interface = usb_find_interface(&adu_driver, subminor);
262 if (!interface) { 285 if (!interface) {
263 err("%s - error, can't find device for minor %d", 286 err("%s - error, can't find device for minor %d",
@@ -267,54 +290,54 @@ static int adu_open(struct inode *inode, struct file *file)
267 } 290 }
268 291
269 dev = usb_get_intfdata(interface); 292 dev = usb_get_intfdata(interface);
270 if (!dev) { 293 if (!dev || !dev->udev) {
271 retval = -ENODEV; 294 retval = -ENODEV;
272 goto exit_no_device; 295 goto exit_no_device;
273 } 296 }
274 297
275 /* lock this device */ 298 /* check that nobody else is using the device */
276 if ((retval = mutex_lock_interruptible(&dev->mtx))) { 299 if (dev->open_count) {
277 dbg(2, "%s : mutex lock failed", __FUNCTION__); 300 retval = -EBUSY;
278 goto exit_no_device; 301 goto exit_no_device;
279 } 302 }
280 303
281 /* increment our usage count for the device */
282 ++dev->open_count; 304 ++dev->open_count;
283 dbg(2,"%s : open count %d", __FUNCTION__, dev->open_count); 305 dbg(2,"%s : open count %d", __FUNCTION__, dev->open_count);
284 306
285 /* save device in the file's private structure */ 307 /* save device in the file's private structure */
286 file->private_data = dev; 308 file->private_data = dev;
287 309
288 if (dev->open_count == 1) { 310 /* initialize in direction */
289 /* initialize in direction */ 311 dev->read_buffer_length = 0;
290 dev->read_buffer_length = 0;
291 312
292 /* fixup first read by having urb waiting for it */ 313 /* fixup first read by having urb waiting for it */
293 usb_fill_int_urb(dev->interrupt_in_urb,dev->udev, 314 usb_fill_int_urb(dev->interrupt_in_urb,dev->udev,
294 usb_rcvintpipe(dev->udev, 315 usb_rcvintpipe(dev->udev,
295 dev->interrupt_in_endpoint->bEndpointAddress), 316 dev->interrupt_in_endpoint->bEndpointAddress),
296 dev->interrupt_in_buffer, 317 dev->interrupt_in_buffer,
297 le16_to_cpu(dev->interrupt_in_endpoint->wMaxPacketSize), 318 le16_to_cpu(dev->interrupt_in_endpoint->wMaxPacketSize),
298 adu_interrupt_in_callback, dev, 319 adu_interrupt_in_callback, dev,
299 dev->interrupt_in_endpoint->bInterval); 320 dev->interrupt_in_endpoint->bInterval);
300 /* dev->interrupt_in_urb->transfer_flags |= URB_ASYNC_UNLINK; */ 321 dev->read_urb_finished = 0;
301 dev->read_urb_finished = 0; 322 if (usb_submit_urb(dev->interrupt_in_urb, GFP_KERNEL))
302 retval = usb_submit_urb(dev->interrupt_in_urb, GFP_KERNEL); 323 dev->read_urb_finished = 1;
303 if (retval) 324 /* we ignore failure */
304 --dev->open_count; 325 /* end of fixup for first read */
305 } 326
306 mutex_unlock(&dev->mtx); 327 /* initialize out direction */
328 dev->out_urb_finished = 1;
329
330 retval = 0;
307 331
308exit_no_device: 332exit_no_device:
333 mutex_unlock(&adutux_mutex);
334exit_no_lock:
309 dbg(2,"%s : leave, return value %d ", __FUNCTION__, retval); 335 dbg(2,"%s : leave, return value %d ", __FUNCTION__, retval);
310
311 return retval; 336 return retval;
312} 337}
313 338
314static int adu_release_internal(struct adu_device *dev) 339static void adu_release_internal(struct adu_device *dev)
315{ 340{
316 int retval = 0;
317
318 dbg(2," %s : enter", __FUNCTION__); 341 dbg(2," %s : enter", __FUNCTION__);
319 342
320 /* decrement our usage count for the device */ 343 /* decrement our usage count for the device */
@@ -326,12 +349,11 @@ static int adu_release_internal(struct adu_device *dev)
326 } 349 }
327 350
328 dbg(2," %s : leave", __FUNCTION__); 351 dbg(2," %s : leave", __FUNCTION__);
329 return retval;
330} 352}
331 353
332static int adu_release(struct inode *inode, struct file *file) 354static int adu_release(struct inode *inode, struct file *file)
333{ 355{
334 struct adu_device *dev = NULL; 356 struct adu_device *dev;
335 int retval = 0; 357 int retval = 0;
336 358
337 dbg(2," %s : enter", __FUNCTION__); 359 dbg(2," %s : enter", __FUNCTION__);
@@ -343,15 +365,13 @@ static int adu_release(struct inode *inode, struct file *file)
343 } 365 }
344 366
345 dev = file->private_data; 367 dev = file->private_data;
346
347 if (dev == NULL) { 368 if (dev == NULL) {
348 dbg(1," %s : object is NULL", __FUNCTION__); 369 dbg(1," %s : object is NULL", __FUNCTION__);
349 retval = -ENODEV; 370 retval = -ENODEV;
350 goto exit; 371 goto exit;
351 } 372 }
352 373
353 /* lock our device */ 374 mutex_lock(&adutux_mutex); /* not interruptible */
354 mutex_lock(&dev->mtx); /* not interruptible */
355 375
356 if (dev->open_count <= 0) { 376 if (dev->open_count <= 0) {
357 dbg(1," %s : device not opened", __FUNCTION__); 377 dbg(1," %s : device not opened", __FUNCTION__);
@@ -359,19 +379,15 @@ static int adu_release(struct inode *inode, struct file *file)
359 goto exit; 379 goto exit;
360 } 380 }
361 381
382 adu_release_internal(dev);
362 if (dev->udev == NULL) { 383 if (dev->udev == NULL) {
363 /* the device was unplugged before the file was released */ 384 /* the device was unplugged before the file was released */
364 mutex_unlock(&dev->mtx); 385 if (!dev->open_count) /* ... and we're the last user */
365 adu_delete(dev); 386 adu_delete(dev);
366 dev = NULL;
367 } else {
368 /* do the work */
369 retval = adu_release_internal(dev);
370 } 387 }
371 388
372exit: 389exit:
373 if (dev) 390 mutex_unlock(&adutux_mutex);
374 mutex_unlock(&dev->mtx);
375 dbg(2," %s : leave, return value %d", __FUNCTION__, retval); 391 dbg(2," %s : leave, return value %d", __FUNCTION__, retval);
376 return retval; 392 return retval;
377} 393}
@@ -393,12 +409,12 @@ static ssize_t adu_read(struct file *file, __user char *buffer, size_t count,
393 409
394 dev = file->private_data; 410 dev = file->private_data;
395 dbg(2," %s : dev=%p", __FUNCTION__, dev); 411 dbg(2," %s : dev=%p", __FUNCTION__, dev);
396 /* lock this object */ 412
397 if (mutex_lock_interruptible(&dev->mtx)) 413 if (mutex_lock_interruptible(&dev->mtx))
398 return -ERESTARTSYS; 414 return -ERESTARTSYS;
399 415
400 /* verify that the device wasn't unplugged */ 416 /* verify that the device wasn't unplugged */
401 if (dev->udev == NULL || dev->minor == 0) { 417 if (dev->udev == NULL) {
402 retval = -ENODEV; 418 retval = -ENODEV;
403 err("No device or device unplugged %d", retval); 419 err("No device or device unplugged %d", retval);
404 goto exit; 420 goto exit;
@@ -452,7 +468,7 @@ static ssize_t adu_read(struct file *file, __user char *buffer, size_t count,
452 should_submit = 1; 468 should_submit = 1;
453 } else { 469 } else {
454 /* even the primary was empty - we may need to do IO */ 470 /* even the primary was empty - we may need to do IO */
455 if (dev->interrupt_in_urb->status == -EINPROGRESS) { 471 if (!dev->read_urb_finished) {
456 /* somebody is doing IO */ 472 /* somebody is doing IO */
457 spin_unlock_irqrestore(&dev->buflock, flags); 473 spin_unlock_irqrestore(&dev->buflock, flags);
458 dbg(2," %s : submitted already", __FUNCTION__); 474 dbg(2," %s : submitted already", __FUNCTION__);
@@ -460,6 +476,7 @@ static ssize_t adu_read(struct file *file, __user char *buffer, size_t count,
460 /* we must initiate input */ 476 /* we must initiate input */
461 dbg(2," %s : initiate input", __FUNCTION__); 477 dbg(2," %s : initiate input", __FUNCTION__);
462 dev->read_urb_finished = 0; 478 dev->read_urb_finished = 0;
479 spin_unlock_irqrestore(&dev->buflock, flags);
463 480
464 usb_fill_int_urb(dev->interrupt_in_urb,dev->udev, 481 usb_fill_int_urb(dev->interrupt_in_urb,dev->udev,
465 usb_rcvintpipe(dev->udev, 482 usb_rcvintpipe(dev->udev,
@@ -469,15 +486,12 @@ static ssize_t adu_read(struct file *file, __user char *buffer, size_t count,
469 adu_interrupt_in_callback, 486 adu_interrupt_in_callback,
470 dev, 487 dev,
471 dev->interrupt_in_endpoint->bInterval); 488 dev->interrupt_in_endpoint->bInterval);
472 retval = usb_submit_urb(dev->interrupt_in_urb, GFP_ATOMIC); 489 retval = usb_submit_urb(dev->interrupt_in_urb, GFP_KERNEL);
473 if (!retval) { 490 if (retval) {
474 spin_unlock_irqrestore(&dev->buflock, flags); 491 dev->read_urb_finished = 1;
475 dbg(2," %s : submitted OK", __FUNCTION__);
476 } else {
477 if (retval == -ENOMEM) { 492 if (retval == -ENOMEM) {
478 retval = bytes_read ? bytes_read : -ENOMEM; 493 retval = bytes_read ? bytes_read : -ENOMEM;
479 } 494 }
480 spin_unlock_irqrestore(&dev->buflock, flags);
481 dbg(2," %s : submit failed", __FUNCTION__); 495 dbg(2," %s : submit failed", __FUNCTION__);
482 goto exit; 496 goto exit;
483 } 497 }
@@ -486,10 +500,14 @@ static ssize_t adu_read(struct file *file, __user char *buffer, size_t count,
486 /* we wait for I/O to complete */ 500 /* we wait for I/O to complete */
487 set_current_state(TASK_INTERRUPTIBLE); 501 set_current_state(TASK_INTERRUPTIBLE);
488 add_wait_queue(&dev->read_wait, &wait); 502 add_wait_queue(&dev->read_wait, &wait);
489 if (!dev->read_urb_finished) 503 spin_lock_irqsave(&dev->buflock, flags);
504 if (!dev->read_urb_finished) {
505 spin_unlock_irqrestore(&dev->buflock, flags);
490 timeout = schedule_timeout(COMMAND_TIMEOUT); 506 timeout = schedule_timeout(COMMAND_TIMEOUT);
491 else 507 } else {
508 spin_unlock_irqrestore(&dev->buflock, flags);
492 set_current_state(TASK_RUNNING); 509 set_current_state(TASK_RUNNING);
510 }
493 remove_wait_queue(&dev->read_wait, &wait); 511 remove_wait_queue(&dev->read_wait, &wait);
494 512
495 if (timeout <= 0) { 513 if (timeout <= 0) {
@@ -509,19 +527,23 @@ static ssize_t adu_read(struct file *file, __user char *buffer, size_t count,
509 527
510 retval = bytes_read; 528 retval = bytes_read;
511 /* if the primary buffer is empty then use it */ 529 /* if the primary buffer is empty then use it */
512 if (should_submit && !dev->interrupt_in_urb->status==-EINPROGRESS) { 530 spin_lock_irqsave(&dev->buflock, flags);
531 if (should_submit && dev->read_urb_finished) {
532 dev->read_urb_finished = 0;
533 spin_unlock_irqrestore(&dev->buflock, flags);
513 usb_fill_int_urb(dev->interrupt_in_urb,dev->udev, 534 usb_fill_int_urb(dev->interrupt_in_urb,dev->udev,
514 usb_rcvintpipe(dev->udev, 535 usb_rcvintpipe(dev->udev,
515 dev->interrupt_in_endpoint->bEndpointAddress), 536 dev->interrupt_in_endpoint->bEndpointAddress),
516 dev->interrupt_in_buffer, 537 dev->interrupt_in_buffer,
517 le16_to_cpu(dev->interrupt_in_endpoint->wMaxPacketSize), 538 le16_to_cpu(dev->interrupt_in_endpoint->wMaxPacketSize),
518 adu_interrupt_in_callback, 539 adu_interrupt_in_callback,
519 dev, 540 dev,
520 dev->interrupt_in_endpoint->bInterval); 541 dev->interrupt_in_endpoint->bInterval);
521 /* dev->interrupt_in_urb->transfer_flags |= URB_ASYNC_UNLINK; */ 542 if (usb_submit_urb(dev->interrupt_in_urb, GFP_KERNEL) != 0)
522 dev->read_urb_finished = 0; 543 dev->read_urb_finished = 1;
523 usb_submit_urb(dev->interrupt_in_urb, GFP_KERNEL);
524 /* we ignore failure */ 544 /* we ignore failure */
545 } else {
546 spin_unlock_irqrestore(&dev->buflock, flags);
525 } 547 }
526 548
527exit: 549exit:
@@ -535,24 +557,24 @@ exit:
535static ssize_t adu_write(struct file *file, const __user char *buffer, 557static ssize_t adu_write(struct file *file, const __user char *buffer,
536 size_t count, loff_t *ppos) 558 size_t count, loff_t *ppos)
537{ 559{
560 DECLARE_WAITQUEUE(waita, current);
538 struct adu_device *dev; 561 struct adu_device *dev;
539 size_t bytes_written = 0; 562 size_t bytes_written = 0;
540 size_t bytes_to_write; 563 size_t bytes_to_write;
541 size_t buffer_size; 564 size_t buffer_size;
565 unsigned long flags;
542 int retval; 566 int retval;
543 int timeout = 0;
544 567
545 dbg(2," %s : enter, count = %Zd", __FUNCTION__, count); 568 dbg(2," %s : enter, count = %Zd", __FUNCTION__, count);
546 569
547 dev = file->private_data; 570 dev = file->private_data;
548 571
549 /* lock this object */
550 retval = mutex_lock_interruptible(&dev->mtx); 572 retval = mutex_lock_interruptible(&dev->mtx);
551 if (retval) 573 if (retval)
552 goto exit_nolock; 574 goto exit_nolock;
553 575
554 /* verify that the device wasn't unplugged */ 576 /* verify that the device wasn't unplugged */
555 if (dev->udev == NULL || dev->minor == 0) { 577 if (dev->udev == NULL) {
556 retval = -ENODEV; 578 retval = -ENODEV;
557 err("No device or device unplugged %d", retval); 579 err("No device or device unplugged %d", retval);
558 goto exit; 580 goto exit;
@@ -564,42 +586,37 @@ static ssize_t adu_write(struct file *file, const __user char *buffer,
564 goto exit; 586 goto exit;
565 } 587 }
566 588
567
568 while (count > 0) { 589 while (count > 0) {
569 if (dev->interrupt_out_urb->status == -EINPROGRESS) { 590 add_wait_queue(&dev->write_wait, &waita);
570 timeout = COMMAND_TIMEOUT; 591 set_current_state(TASK_INTERRUPTIBLE);
592 spin_lock_irqsave(&dev->buflock, flags);
593 if (!dev->out_urb_finished) {
594 spin_unlock_irqrestore(&dev->buflock, flags);
571 595
572 while (timeout > 0) { 596 mutex_unlock(&dev->mtx);
573 if (signal_pending(current)) { 597 if (signal_pending(current)) {
574 dbg(1," %s : interrupted", __FUNCTION__); 598 dbg(1," %s : interrupted", __FUNCTION__);
599 set_current_state(TASK_RUNNING);
575 retval = -EINTR; 600 retval = -EINTR;
576 goto exit; 601 goto exit_onqueue;
577 } 602 }
578 mutex_unlock(&dev->mtx); 603 if (schedule_timeout(COMMAND_TIMEOUT) == 0) {
579 timeout = interruptible_sleep_on_timeout(&dev->write_wait, timeout); 604 dbg(1, "%s - command timed out.", __FUNCTION__);
605 retval = -ETIMEDOUT;
606 goto exit_onqueue;
607 }
608 remove_wait_queue(&dev->write_wait, &waita);
580 retval = mutex_lock_interruptible(&dev->mtx); 609 retval = mutex_lock_interruptible(&dev->mtx);
581 if (retval) { 610 if (retval) {
582 retval = bytes_written ? bytes_written : retval; 611 retval = bytes_written ? bytes_written : retval;
583 goto exit_nolock; 612 goto exit_nolock;
584 } 613 }
585 if (timeout > 0) {
586 break;
587 }
588 dbg(1," %s : interrupted timeout: %d", __FUNCTION__, timeout);
589 }
590
591
592 dbg(1," %s : final timeout: %d", __FUNCTION__, timeout);
593
594 if (timeout == 0) {
595 dbg(1, "%s - command timed out.", __FUNCTION__);
596 retval = -ETIMEDOUT;
597 goto exit;
598 }
599
600 dbg(4," %s : in progress, count = %Zd", __FUNCTION__, count);
601 614
615 dbg(4," %s : in progress, count = %Zd", __FUNCTION__, count);
602 } else { 616 } else {
617 spin_unlock_irqrestore(&dev->buflock, flags);
618 set_current_state(TASK_RUNNING);
619 remove_wait_queue(&dev->write_wait, &waita);
603 dbg(4," %s : sending, count = %Zd", __FUNCTION__, count); 620 dbg(4," %s : sending, count = %Zd", __FUNCTION__, count);
604 621
605 /* write the data into interrupt_out_buffer from userspace */ 622 /* write the data into interrupt_out_buffer from userspace */
@@ -622,11 +639,12 @@ static ssize_t adu_write(struct file *file, const __user char *buffer,
622 bytes_to_write, 639 bytes_to_write,
623 adu_interrupt_out_callback, 640 adu_interrupt_out_callback,
624 dev, 641 dev,
625 dev->interrupt_in_endpoint->bInterval); 642 dev->interrupt_out_endpoint->bInterval);
626 /* dev->interrupt_in_urb->transfer_flags |= URB_ASYNC_UNLINK; */
627 dev->interrupt_out_urb->actual_length = bytes_to_write; 643 dev->interrupt_out_urb->actual_length = bytes_to_write;
644 dev->out_urb_finished = 0;
628 retval = usb_submit_urb(dev->interrupt_out_urb, GFP_KERNEL); 645 retval = usb_submit_urb(dev->interrupt_out_urb, GFP_KERNEL);
629 if (retval < 0) { 646 if (retval < 0) {
647 dev->out_urb_finished = 1;
630 err("Couldn't submit interrupt_out_urb %d", retval); 648 err("Couldn't submit interrupt_out_urb %d", retval);
631 goto exit; 649 goto exit;
632 } 650 }
@@ -637,16 +655,17 @@ static ssize_t adu_write(struct file *file, const __user char *buffer,
637 bytes_written += bytes_to_write; 655 bytes_written += bytes_to_write;
638 } 656 }
639 } 657 }
640 658 mutex_unlock(&dev->mtx);
641 retval = bytes_written; 659 return bytes_written;
642 660
643exit: 661exit:
644 /* unlock the device */
645 mutex_unlock(&dev->mtx); 662 mutex_unlock(&dev->mtx);
646exit_nolock: 663exit_nolock:
647
648 dbg(2," %s : leave, return value %d", __FUNCTION__, retval); 664 dbg(2," %s : leave, return value %d", __FUNCTION__, retval);
665 return retval;
649 666
667exit_onqueue:
668 remove_wait_queue(&dev->write_wait, &waita);
650 return retval; 669 return retval;
651} 670}
652 671
@@ -831,25 +850,22 @@ static void adu_disconnect(struct usb_interface *interface)
831 dbg(2," %s : enter", __FUNCTION__); 850 dbg(2," %s : enter", __FUNCTION__);
832 851
833 dev = usb_get_intfdata(interface); 852 dev = usb_get_intfdata(interface);
834 usb_set_intfdata(interface, NULL);
835 853
854 mutex_lock(&dev->mtx); /* not interruptible */
855 dev->udev = NULL; /* poison */
836 minor = dev->minor; 856 minor = dev->minor;
837
838 /* give back our minor */
839 usb_deregister_dev(interface, &adu_class); 857 usb_deregister_dev(interface, &adu_class);
840 dev->minor = 0; 858 mutex_unlock(&dev->mtx);
841 859
842 mutex_lock(&dev->mtx); /* not interruptible */ 860 mutex_lock(&adutux_mutex);
861 usb_set_intfdata(interface, NULL);
843 862
844 /* if the device is not opened, then we clean up right now */ 863 /* if the device is not opened, then we clean up right now */
845 dbg(2," %s : open count %d", __FUNCTION__, dev->open_count); 864 dbg(2," %s : open count %d", __FUNCTION__, dev->open_count);
846 if (!dev->open_count) { 865 if (!dev->open_count)
847 mutex_unlock(&dev->mtx);
848 adu_delete(dev); 866 adu_delete(dev);
849 } else { 867
850 dev->udev = NULL; 868 mutex_unlock(&adutux_mutex);
851 mutex_unlock(&dev->mtx);
852 }
853 869
854 dev_info(&interface->dev, "ADU device adutux%d now disconnected\n", 870 dev_info(&interface->dev, "ADU device adutux%d now disconnected\n",
855 (minor - ADU_MINOR_BASE)); 871 (minor - ADU_MINOR_BASE));
diff --git a/drivers/usb/misc/usbled.c b/drivers/usb/misc/usbled.c
index 49c5c5c4c431..06cb71942dc7 100644
--- a/drivers/usb/misc/usbled.c
+++ b/drivers/usb/misc/usbled.c
@@ -144,12 +144,14 @@ static void led_disconnect(struct usb_interface *interface)
144 struct usb_led *dev; 144 struct usb_led *dev;
145 145
146 dev = usb_get_intfdata (interface); 146 dev = usb_get_intfdata (interface);
147 usb_set_intfdata (interface, NULL);
148 147
149 device_remove_file(&interface->dev, &dev_attr_blue); 148 device_remove_file(&interface->dev, &dev_attr_blue);
150 device_remove_file(&interface->dev, &dev_attr_red); 149 device_remove_file(&interface->dev, &dev_attr_red);
151 device_remove_file(&interface->dev, &dev_attr_green); 150 device_remove_file(&interface->dev, &dev_attr_green);
152 151
152 /* first remove the files, then set the pointer to NULL */
153 usb_set_intfdata (interface, NULL);
154
153 usb_put_dev(dev->udev); 155 usb_put_dev(dev->udev);
154 156
155 kfree(dev); 157 kfree(dev);
diff --git a/drivers/usb/serial/cp2101.c b/drivers/usb/serial/cp2101.c
index 3a83cb4c4bc2..22833589c4be 100644
--- a/drivers/usb/serial/cp2101.c
+++ b/drivers/usb/serial/cp2101.c
@@ -55,6 +55,7 @@ static int debug;
55static struct usb_device_id id_table [] = { 55static struct usb_device_id id_table [] = {
56 { USB_DEVICE(0x08e6, 0x5501) }, /* Gemalto Prox-PU/CU contactless smartcard reader */ 56 { USB_DEVICE(0x08e6, 0x5501) }, /* Gemalto Prox-PU/CU contactless smartcard reader */
57 { USB_DEVICE(0x0FCF, 0x1003) }, /* Dynastream ANT development board */ 57 { USB_DEVICE(0x0FCF, 0x1003) }, /* Dynastream ANT development board */
58 { USB_DEVICE(0x0FCF, 0x1004) }, /* Dynastream ANT2USB */
58 { USB_DEVICE(0x10A6, 0xAA26) }, /* Knock-off DCU-11 cable */ 59 { USB_DEVICE(0x10A6, 0xAA26) }, /* Knock-off DCU-11 cable */
59 { USB_DEVICE(0x10AB, 0x10C5) }, /* Siemens MC60 Cable */ 60 { USB_DEVICE(0x10AB, 0x10C5) }, /* Siemens MC60 Cable */
60 { USB_DEVICE(0x10B5, 0xAC70) }, /* Nokia CA-42 USB */ 61 { USB_DEVICE(0x10B5, 0xAC70) }, /* Nokia CA-42 USB */
@@ -71,6 +72,7 @@ static struct usb_device_id id_table [] = {
71 { USB_DEVICE(0x10C4, 0x815E) }, /* Helicomm IP-Link 1220-DVM */ 72 { USB_DEVICE(0x10C4, 0x815E) }, /* Helicomm IP-Link 1220-DVM */
72 { USB_DEVICE(0x10C4, 0x81C8) }, /* Lipowsky Industrie Elektronik GmbH, Baby-JTAG */ 73 { USB_DEVICE(0x10C4, 0x81C8) }, /* Lipowsky Industrie Elektronik GmbH, Baby-JTAG */
73 { USB_DEVICE(0x10C4, 0x81E2) }, /* Lipowsky Industrie Elektronik GmbH, Baby-LIN */ 74 { USB_DEVICE(0x10C4, 0x81E2) }, /* Lipowsky Industrie Elektronik GmbH, Baby-LIN */
75 { USB_DEVICE(0x10C4, 0x81E7) }, /* Aerocomm Radio */
74 { USB_DEVICE(0x10C4, 0x8218) }, /* Lipowsky Industrie Elektronik GmbH, HARP-1 */ 76 { USB_DEVICE(0x10C4, 0x8218) }, /* Lipowsky Industrie Elektronik GmbH, HARP-1 */
75 { USB_DEVICE(0x10C4, 0xEA60) }, /* Silicon Labs factory default */ 77 { USB_DEVICE(0x10C4, 0xEA60) }, /* Silicon Labs factory default */
76 { USB_DEVICE(0x10C4, 0xEA61) }, /* Silicon Labs factory default */ 78 { USB_DEVICE(0x10C4, 0xEA61) }, /* Silicon Labs factory default */
@@ -98,8 +100,8 @@ static struct usb_serial_driver cp2101_device = {
98 .usb_driver = &cp2101_driver, 100 .usb_driver = &cp2101_driver,
99 .id_table = id_table, 101 .id_table = id_table,
100 .num_interrupt_in = 0, 102 .num_interrupt_in = 0,
101 .num_bulk_in = 0, 103 .num_bulk_in = NUM_DONT_CARE,
102 .num_bulk_out = 0, 104 .num_bulk_out = NUM_DONT_CARE,
103 .num_ports = 1, 105 .num_ports = 1,
104 .open = cp2101_open, 106 .open = cp2101_open,
105 .close = cp2101_close, 107 .close = cp2101_close,
diff --git a/drivers/usb/serial/generic.c b/drivers/usb/serial/generic.c
index 9eb4a65ee4d9..d41531139c55 100644
--- a/drivers/usb/serial/generic.c
+++ b/drivers/usb/serial/generic.c
@@ -327,6 +327,7 @@ void usb_serial_generic_read_bulk_callback (struct urb *urb)
327 struct usb_serial_port *port = (struct usb_serial_port *)urb->context; 327 struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
328 unsigned char *data = urb->transfer_buffer; 328 unsigned char *data = urb->transfer_buffer;
329 int status = urb->status; 329 int status = urb->status;
330 unsigned long flags;
330 331
331 dbg("%s - port %d", __FUNCTION__, port->number); 332 dbg("%s - port %d", __FUNCTION__, port->number);
332 333
@@ -339,11 +340,11 @@ void usb_serial_generic_read_bulk_callback (struct urb *urb)
339 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, urb->actual_length, data); 340 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, urb->actual_length, data);
340 341
341 /* Throttle the device if requested by tty */ 342 /* Throttle the device if requested by tty */
342 spin_lock(&port->lock); 343 spin_lock_irqsave(&port->lock, flags);
343 if (!(port->throttled = port->throttle_req)) 344 if (!(port->throttled = port->throttle_req))
344 /* Handle data and continue reading from device */ 345 /* Handle data and continue reading from device */
345 flush_and_resubmit_read_urb(port); 346 flush_and_resubmit_read_urb(port);
346 spin_unlock(&port->lock); 347 spin_unlock_irqrestore(&port->lock, flags);
347} 348}
348EXPORT_SYMBOL_GPL(usb_serial_generic_read_bulk_callback); 349EXPORT_SYMBOL_GPL(usb_serial_generic_read_bulk_callback);
349 350
diff --git a/drivers/usb/serial/keyspan.c b/drivers/usb/serial/keyspan.c
index 1f7ab15df36d..feba9679ace8 100644
--- a/drivers/usb/serial/keyspan.c
+++ b/drivers/usb/serial/keyspan.c
@@ -1215,12 +1215,14 @@ static int keyspan_chars_in_buffer (struct usb_serial_port *port)
1215 1215
1216static int keyspan_open (struct usb_serial_port *port, struct file *filp) 1216static int keyspan_open (struct usb_serial_port *port, struct file *filp)
1217{ 1217{
1218 struct keyspan_port_private *p_priv; 1218 struct keyspan_port_private *p_priv;
1219 struct keyspan_serial_private *s_priv; 1219 struct keyspan_serial_private *s_priv;
1220 struct usb_serial *serial = port->serial; 1220 struct usb_serial *serial = port->serial;
1221 const struct keyspan_device_details *d_details; 1221 const struct keyspan_device_details *d_details;
1222 int i, err; 1222 int i, err;
1223 int baud_rate, device_port;
1223 struct urb *urb; 1224 struct urb *urb;
1225 unsigned int cflag;
1224 1226
1225 s_priv = usb_get_serial_data(serial); 1227 s_priv = usb_get_serial_data(serial);
1226 p_priv = usb_get_serial_port_data(port); 1228 p_priv = usb_get_serial_port_data(port);
@@ -1263,6 +1265,30 @@ static int keyspan_open (struct usb_serial_port *port, struct file *filp)
1263 /* usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe), usb_pipeout(urb->pipe), 0); */ 1265 /* usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe), usb_pipeout(urb->pipe), 0); */
1264 } 1266 }
1265 1267
1268 /* get the terminal config for the setup message now so we don't
1269 * need to send 2 of them */
1270
1271 cflag = port->tty->termios->c_cflag;
1272 device_port = port->number - port->serial->minor;
1273
1274 /* Baud rate calculation takes baud rate as an integer
1275 so other rates can be generated if desired. */
1276 baud_rate = tty_get_baud_rate(port->tty);
1277 /* If no match or invalid, leave as default */
1278 if (baud_rate >= 0
1279 && d_details->calculate_baud_rate(baud_rate, d_details->baudclk,
1280 NULL, NULL, NULL, device_port) == KEYSPAN_BAUD_RATE_OK) {
1281 p_priv->baud = baud_rate;
1282 }
1283
1284 /* set CTS/RTS handshake etc. */
1285 p_priv->cflag = cflag;
1286 p_priv->flow_control = (cflag & CRTSCTS)? flow_cts: flow_none;
1287
1288 keyspan_send_setup(port, 1);
1289 //mdelay(100);
1290 //keyspan_set_termios(port, NULL);
1291
1266 return (0); 1292 return (0);
1267} 1293}
1268 1294
diff --git a/drivers/usb/serial/mos7840.c b/drivers/usb/serial/mos7840.c
index a5ced7e08cbf..c29c91271133 100644
--- a/drivers/usb/serial/mos7840.c
+++ b/drivers/usb/serial/mos7840.c
@@ -2711,7 +2711,7 @@ static int mos7840_startup(struct usb_serial *serial)
2711 status = mos7840_set_reg_sync(serial->port[0], ZLP_REG5, Data); 2711 status = mos7840_set_reg_sync(serial->port[0], ZLP_REG5, Data);
2712 if (status < 0) { 2712 if (status < 0) {
2713 dbg("Writing ZLP_REG5 failed status-0x%x\n", status); 2713 dbg("Writing ZLP_REG5 failed status-0x%x\n", status);
2714 return -1; 2714 goto error;
2715 } else 2715 } else
2716 dbg("ZLP_REG5 Writing success status%d\n", status); 2716 dbg("ZLP_REG5 Writing success status%d\n", status);
2717 2717
diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c
index 4590124cf888..d1185f53447b 100644
--- a/drivers/usb/serial/option.c
+++ b/drivers/usb/serial/option.c
@@ -158,8 +158,8 @@ static struct usb_device_id option_ids[] = {
158 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_ETNA_KOI_MODEM) }, 158 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_ETNA_KOI_MODEM) },
159 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_ETNA_KOI_NETWORK) }, 159 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_ETNA_KOI_NETWORK) },
160 { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E600) }, 160 { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E600) },
161 { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E220) }, 161 { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E220, 0xff, 0xff, 0xff) },
162 { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E220BIS) }, 162 { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E220BIS, 0xff, 0xff, 0xff) },
163 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, 0x1100) }, /* Novatel Merlin XS620/S640 */ 163 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, 0x1100) }, /* Novatel Merlin XS620/S640 */
164 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, 0x1110) }, /* Novatel Merlin S620 */ 164 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, 0x1110) }, /* Novatel Merlin S620 */
165 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, 0x1120) }, /* Novatel Merlin EX720 */ 165 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, 0x1120) }, /* Novatel Merlin EX720 */
diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c
index 2cd3f1d4b687..cf8add91de05 100644
--- a/drivers/usb/serial/pl2303.c
+++ b/drivers/usb/serial/pl2303.c
@@ -86,6 +86,7 @@ static struct usb_device_id id_table [] = {
86 { USB_DEVICE(ALCOR_VENDOR_ID, ALCOR_PRODUCT_ID) }, 86 { USB_DEVICE(ALCOR_VENDOR_ID, ALCOR_PRODUCT_ID) },
87 { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_ID) }, 87 { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_ID) },
88 { USB_DEVICE(WS002IN_VENDOR_ID, WS002IN_PRODUCT_ID) }, 88 { USB_DEVICE(WS002IN_VENDOR_ID, WS002IN_PRODUCT_ID) },
89 { USB_DEVICE(COREGA_VENDOR_ID, COREGA_PRODUCT_ID) },
89 { } /* Terminating entry */ 90 { } /* Terminating entry */
90}; 91};
91 92
diff --git a/drivers/usb/serial/pl2303.h b/drivers/usb/serial/pl2303.h
index ed603e3decd6..d31f5d299989 100644
--- a/drivers/usb/serial/pl2303.h
+++ b/drivers/usb/serial/pl2303.h
@@ -104,3 +104,6 @@
104#define WS002IN_VENDOR_ID 0x11f6 104#define WS002IN_VENDOR_ID 0x11f6
105#define WS002IN_PRODUCT_ID 0x2001 105#define WS002IN_PRODUCT_ID 0x2001
106 106
107/* Corega CG-USBRS232R Serial Adapter */
108#define COREGA_VENDOR_ID 0x07aa
109#define COREGA_PRODUCT_ID 0x002a
diff --git a/drivers/usb/serial/sierra.c b/drivers/usb/serial/sierra.c
index 833f6e1e3721..c295d0495f96 100644
--- a/drivers/usb/serial/sierra.c
+++ b/drivers/usb/serial/sierra.c
@@ -100,6 +100,7 @@ static struct usb_device_id id_table [] = {
100 { USB_DEVICE(0x1199, 0x0218) }, /* Sierra Wireless MC5720 */ 100 { USB_DEVICE(0x1199, 0x0218) }, /* Sierra Wireless MC5720 */
101 { USB_DEVICE(0x0f30, 0x1b1d) }, /* Sierra Wireless MC5720 */ 101 { USB_DEVICE(0x0f30, 0x1b1d) }, /* Sierra Wireless MC5720 */
102 { USB_DEVICE(0x1199, 0x0020) }, /* Sierra Wireless MC5725 */ 102 { USB_DEVICE(0x1199, 0x0020) }, /* Sierra Wireless MC5725 */
103 { USB_DEVICE(0x1199, 0x0220) }, /* Sierra Wireless MC5725 */
103 { USB_DEVICE(0x1199, 0x0019) }, /* Sierra Wireless AirCard 595 */ 104 { USB_DEVICE(0x1199, 0x0019) }, /* Sierra Wireless AirCard 595 */
104 { USB_DEVICE(0x1199, 0x0021) }, /* Sierra Wireless AirCard 597E */ 105 { USB_DEVICE(0x1199, 0x0021) }, /* Sierra Wireless AirCard 597E */
105 { USB_DEVICE(0x1199, 0x0120) }, /* Sierra Wireless USB Dongle 595U */ 106 { USB_DEVICE(0x1199, 0x0120) }, /* Sierra Wireless USB Dongle 595U */
@@ -108,6 +109,7 @@ static struct usb_device_id id_table [] = {
108 { USB_DEVICE(0x1199, 0x6804) }, /* Sierra Wireless MC8755 */ 109 { USB_DEVICE(0x1199, 0x6804) }, /* Sierra Wireless MC8755 */
109 { USB_DEVICE(0x1199, 0x6803) }, /* Sierra Wireless MC8765 */ 110 { USB_DEVICE(0x1199, 0x6803) }, /* Sierra Wireless MC8765 */
110 { USB_DEVICE(0x1199, 0x6812) }, /* Sierra Wireless MC8775 & AC 875U */ 111 { USB_DEVICE(0x1199, 0x6812) }, /* Sierra Wireless MC8775 & AC 875U */
112 { USB_DEVICE(0x1199, 0x6813) }, /* Sierra Wireless MC8775 (Thinkpad internal) */
111 { USB_DEVICE(0x1199, 0x6820) }, /* Sierra Wireless AirCard 875 */ 113 { USB_DEVICE(0x1199, 0x6820) }, /* Sierra Wireless AirCard 875 */
112 { USB_DEVICE(0x1199, 0x6832) }, /* Sierra Wireless MC8780*/ 114 { USB_DEVICE(0x1199, 0x6832) }, /* Sierra Wireless MC8780*/
113 { USB_DEVICE(0x1199, 0x6833) }, /* Sierra Wireless MC8781*/ 115 { USB_DEVICE(0x1199, 0x6833) }, /* Sierra Wireless MC8781*/
@@ -136,6 +138,7 @@ static struct usb_device_id id_table_3port [] = {
136 { USB_DEVICE(0x0f30, 0x1b1d) }, /* Sierra Wireless MC5720 */ 138 { USB_DEVICE(0x0f30, 0x1b1d) }, /* Sierra Wireless MC5720 */
137 { USB_DEVICE(0x1199, 0x0218) }, /* Sierra Wireless MC5720 */ 139 { USB_DEVICE(0x1199, 0x0218) }, /* Sierra Wireless MC5720 */
138 { USB_DEVICE(0x1199, 0x0020) }, /* Sierra Wireless MC5725 */ 140 { USB_DEVICE(0x1199, 0x0020) }, /* Sierra Wireless MC5725 */
141 { USB_DEVICE(0x1199, 0x0220) }, /* Sierra Wireless MC5725 */
139 { USB_DEVICE(0x1199, 0x0019) }, /* Sierra Wireless AirCard 595 */ 142 { USB_DEVICE(0x1199, 0x0019) }, /* Sierra Wireless AirCard 595 */
140 { USB_DEVICE(0x1199, 0x0021) }, /* Sierra Wireless AirCard 597E */ 143 { USB_DEVICE(0x1199, 0x0021) }, /* Sierra Wireless AirCard 597E */
141 { USB_DEVICE(0x1199, 0x0120) }, /* Sierra Wireless USB Dongle 595U*/ 144 { USB_DEVICE(0x1199, 0x0120) }, /* Sierra Wireless USB Dongle 595U*/
@@ -144,6 +147,7 @@ static struct usb_device_id id_table_3port [] = {
144 { USB_DEVICE(0x1199, 0x6804) }, /* Sierra Wireless MC8755 */ 147 { USB_DEVICE(0x1199, 0x6804) }, /* Sierra Wireless MC8755 */
145 { USB_DEVICE(0x1199, 0x6803) }, /* Sierra Wireless MC8765 */ 148 { USB_DEVICE(0x1199, 0x6803) }, /* Sierra Wireless MC8765 */
146 { USB_DEVICE(0x1199, 0x6812) }, /* Sierra Wireless MC8775 & AC 875U */ 149 { USB_DEVICE(0x1199, 0x6812) }, /* Sierra Wireless MC8775 & AC 875U */
150 { USB_DEVICE(0x1199, 0x6813) }, /* Sierra Wireless MC8775 (Thinkpad internal) */
147 { USB_DEVICE(0x1199, 0x6820) }, /* Sierra Wireless AirCard 875 */ 151 { USB_DEVICE(0x1199, 0x6820) }, /* Sierra Wireless AirCard 875 */
148 { USB_DEVICE(0x1199, 0x6832) }, /* Sierra Wireless MC8780*/ 152 { USB_DEVICE(0x1199, 0x6832) }, /* Sierra Wireless MC8780*/
149 { USB_DEVICE(0x1199, 0x6833) }, /* Sierra Wireless MC8781*/ 153 { USB_DEVICE(0x1199, 0x6833) }, /* Sierra Wireless MC8781*/
diff --git a/drivers/usb/storage/scsiglue.c b/drivers/usb/storage/scsiglue.c
index 1ba19eaa1970..7c9593b7b04e 100644
--- a/drivers/usb/storage/scsiglue.c
+++ b/drivers/usb/storage/scsiglue.c
@@ -114,9 +114,15 @@ static int slave_configure(struct scsi_device *sdev)
114 * while others have trouble with more than 64K. At this time we 114 * while others have trouble with more than 64K. At this time we
115 * are limiting both to 32K (64 sectores). 115 * are limiting both to 32K (64 sectores).
116 */ 116 */
117 if ((us->flags & US_FL_MAX_SECTORS_64) && 117 if (us->flags & (US_FL_MAX_SECTORS_64 | US_FL_MAX_SECTORS_MIN)) {
118 sdev->request_queue->max_sectors > 64) 118 unsigned int max_sectors = 64;
119 blk_queue_max_sectors(sdev->request_queue, 64); 119
120 if (us->flags & US_FL_MAX_SECTORS_MIN)
121 max_sectors = PAGE_CACHE_SIZE >> 9;
122 if (sdev->request_queue->max_sectors > max_sectors)
123 blk_queue_max_sectors(sdev->request_queue,
124 max_sectors);
125 }
120 126
121 /* We can't put these settings in slave_alloc() because that gets 127 /* We can't put these settings in slave_alloc() because that gets
122 * called before the device type is known. Consequently these 128 * called before the device type is known. Consequently these
@@ -177,6 +183,10 @@ static int slave_configure(struct scsi_device *sdev)
177 * is an occasional series of retries that will all fail. */ 183 * is an occasional series of retries that will all fail. */
178 sdev->retry_hwerror = 1; 184 sdev->retry_hwerror = 1;
179 185
186 /* USB disks should allow restart. Some drives spin down
187 * automatically, requiring a START-STOP UNIT command. */
188 sdev->allow_restart = 1;
189
180 } else { 190 } else {
181 191
182 /* Non-disk-type devices don't need to blacklist any pages 192 /* Non-disk-type devices don't need to blacklist any pages
diff --git a/drivers/usb/storage/unusual_devs.h b/drivers/usb/storage/unusual_devs.h
index 22ab2380367d..6d6108b3993b 100644
--- a/drivers/usb/storage/unusual_devs.h
+++ b/drivers/usb/storage/unusual_devs.h
@@ -342,11 +342,11 @@ UNUSUAL_DEV( 0x04b0, 0x040d, 0x0100, 0x0100,
342 US_FL_FIX_CAPACITY), 342 US_FL_FIX_CAPACITY),
343 343
344/* Reported by Graber and Mike Pagano <mpagano-kernel@mpagano.com> */ 344/* Reported by Graber and Mike Pagano <mpagano-kernel@mpagano.com> */
345UNUSUAL_DEV( 0x04b0, 0x040f, 0x0200, 0x0200, 345UNUSUAL_DEV( 0x04b0, 0x040f, 0x0100, 0x0200,
346 "NIKON", 346 "NIKON",
347 "NIKON DSC D200", 347 "NIKON DSC D200",
348 US_SC_DEVICE, US_PR_DEVICE, NULL, 348 US_SC_DEVICE, US_PR_DEVICE, NULL,
349 US_FL_FIX_CAPACITY), 349 US_FL_FIX_CAPACITY),
350 350
351/* Reported by Emil Larsson <emil@swip.net> */ 351/* Reported by Emil Larsson <emil@swip.net> */
352UNUSUAL_DEV( 0x04b0, 0x0411, 0x0100, 0x0101, 352UNUSUAL_DEV( 0x04b0, 0x0411, 0x0100, 0x0101,
@@ -376,6 +376,13 @@ UNUSUAL_DEV( 0x04b0, 0x0417, 0x0100, 0x0100,
376 US_SC_DEVICE, US_PR_DEVICE, NULL, 376 US_SC_DEVICE, US_PR_DEVICE, NULL,
377 US_FL_FIX_CAPACITY), 377 US_FL_FIX_CAPACITY),
378 378
379/* Reported by Doug Maxey (dwm@austin.ibm.com) */
380UNUSUAL_DEV( 0x04b3, 0x4001, 0x0110, 0x0110,
381 "IBM",
382 "IBM RSA2",
383 US_SC_DEVICE, US_PR_CB, NULL,
384 US_FL_MAX_SECTORS_MIN),
385
379/* BENQ DC5330 386/* BENQ DC5330
380 * Reported by Manuel Fombuena <mfombuena@ya.com> and 387 * Reported by Manuel Fombuena <mfombuena@ya.com> and
381 * Frank Copeland <fjc@thingy.apana.org.au> */ 388 * Frank Copeland <fjc@thingy.apana.org.au> */
@@ -731,6 +738,13 @@ UNUSUAL_DEV( 0x0584, 0x0008, 0x0102, 0x0102,
731 US_SC_SCSI, US_PR_ALAUDA, init_alauda, 0 ), 738 US_SC_SCSI, US_PR_ALAUDA, init_alauda, 0 ),
732#endif 739#endif
733 740
741/* Reported by RTE <raszilki@yandex.ru> */
742UNUSUAL_DEV( 0x058f, 0x6387, 0x0141, 0x0141,
743 "JetFlash",
744 "TS1GJF2A/120",
745 US_SC_DEVICE, US_PR_DEVICE, NULL,
746 US_FL_MAX_SECTORS_64 ),
747
734/* Fabrizio Fellini <fello@libero.it> */ 748/* Fabrizio Fellini <fello@libero.it> */
735UNUSUAL_DEV( 0x0595, 0x4343, 0x0000, 0x2210, 749UNUSUAL_DEV( 0x0595, 0x4343, 0x0000, 0x2210,
736 "Fujifilm", 750 "Fujifilm",
@@ -1251,14 +1265,6 @@ UNUSUAL_DEV( 0x0ace, 0x20ff, 0x0101, 0x0101,
1251 US_SC_DEVICE, US_PR_DEVICE, NULL, 1265 US_SC_DEVICE, US_PR_DEVICE, NULL,
1252 US_FL_IGNORE_DEVICE ), 1266 US_FL_IGNORE_DEVICE ),
1253 1267
1254/* SanDisk that has a second LUN for a driver ISO, reported by
1255 * Ben Collins <bcollins@ubuntu.com> */
1256UNUSUAL_DEV( 0x0781, 0x5406, 0x0000, 0xffff,
1257 "SanDisk",
1258 "U3 Cruzer Micro driver ISO",
1259 US_SC_DEVICE, US_PR_DEVICE, NULL,
1260 US_FL_SINGLE_LUN ),
1261
1262#ifdef CONFIG_USB_STORAGE_ISD200 1268#ifdef CONFIG_USB_STORAGE_ISD200
1263UNUSUAL_DEV( 0x0bf6, 0xa001, 0x0100, 0x0110, 1269UNUSUAL_DEV( 0x0bf6, 0xa001, 0x0100, 0x0110,
1264 "ATI", 1270 "ATI",
diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index 7d86e9eae915..5b3dbcfcda48 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -641,6 +641,17 @@ config FB_VESA
641 You will get a boot time penguin logo at no additional cost. Please 641 You will get a boot time penguin logo at no additional cost. Please
642 read <file:Documentation/fb/vesafb.txt>. If unsure, say Y. 642 read <file:Documentation/fb/vesafb.txt>. If unsure, say Y.
643 643
644config FB_EFI
645 bool "EFI-based Framebuffer Support"
646 depends on (FB = y) && X86
647 select FB_CFB_FILLRECT
648 select FB_CFB_COPYAREA
649 select FB_CFB_IMAGEBLIT
650 help
651 This is the EFI frame buffer device driver. If the firmware on
652 your platform is UEFI2.0, select Y to add support for
653 Graphics Output Protocol for early console messages to appear.
654
644config FB_IMAC 655config FB_IMAC
645 bool "Intel-based Macintosh Framebuffer Support" 656 bool "Intel-based Macintosh Framebuffer Support"
646 depends on (FB = y) && X86 && EFI 657 depends on (FB = y) && X86 && EFI
diff --git a/drivers/video/Makefile b/drivers/video/Makefile
index 59d6c45a910d..83e02b3429b6 100644
--- a/drivers/video/Makefile
+++ b/drivers/video/Makefile
@@ -118,6 +118,7 @@ obj-$(CONFIG_FB_OMAP) += omap/
118obj-$(CONFIG_FB_UVESA) += uvesafb.o 118obj-$(CONFIG_FB_UVESA) += uvesafb.o
119obj-$(CONFIG_FB_VESA) += vesafb.o 119obj-$(CONFIG_FB_VESA) += vesafb.o
120obj-$(CONFIG_FB_IMAC) += imacfb.o 120obj-$(CONFIG_FB_IMAC) += imacfb.o
121obj-$(CONFIG_FB_EFI) += efifb.o
121obj-$(CONFIG_FB_VGA16) += vga16fb.o 122obj-$(CONFIG_FB_VGA16) += vga16fb.o
122obj-$(CONFIG_FB_OF) += offb.o 123obj-$(CONFIG_FB_OF) += offb.o
123obj-$(CONFIG_FB_BF54X_LQ043) += bf54x-lq043fb.o 124obj-$(CONFIG_FB_BF54X_LQ043) += bf54x-lq043fb.o
diff --git a/drivers/video/atmel_lcdfb.c b/drivers/video/atmel_lcdfb.c
index 235b618b4117..11a3a222dfc3 100644
--- a/drivers/video/atmel_lcdfb.c
+++ b/drivers/video/atmel_lcdfb.c
@@ -268,6 +268,10 @@ static int atmel_lcdfb_set_par(struct fb_info *info)
268 /* Turn off the LCD controller and the DMA controller */ 268 /* Turn off the LCD controller and the DMA controller */
269 lcdc_writel(sinfo, ATMEL_LCDC_PWRCON, sinfo->guard_time << ATMEL_LCDC_GUARDT_OFFSET); 269 lcdc_writel(sinfo, ATMEL_LCDC_PWRCON, sinfo->guard_time << ATMEL_LCDC_GUARDT_OFFSET);
270 270
271 /* Wait for the LCDC core to become idle */
272 while (lcdc_readl(sinfo, ATMEL_LCDC_PWRCON) & ATMEL_LCDC_BUSY)
273 msleep(10);
274
271 lcdc_writel(sinfo, ATMEL_LCDC_DMACON, 0); 275 lcdc_writel(sinfo, ATMEL_LCDC_DMACON, 0);
272 276
273 if (info->var.bits_per_pixel == 1) 277 if (info->var.bits_per_pixel == 1)
diff --git a/drivers/video/aty/radeon_base.c b/drivers/video/aty/radeon_base.c
index 1e32b3d13f2e..62867cb63fef 100644
--- a/drivers/video/aty/radeon_base.c
+++ b/drivers/video/aty/radeon_base.c
@@ -202,6 +202,7 @@ static struct pci_device_id radeonfb_pci_table[] = {
202 CHIP_DEF(PCI_CHIP_RV380_3154, RV380, CHIP_HAS_CRTC2 | CHIP_IS_MOBILITY), 202 CHIP_DEF(PCI_CHIP_RV380_3154, RV380, CHIP_HAS_CRTC2 | CHIP_IS_MOBILITY),
203 CHIP_DEF(PCI_CHIP_RV370_5B60, RV380, CHIP_HAS_CRTC2), 203 CHIP_DEF(PCI_CHIP_RV370_5B60, RV380, CHIP_HAS_CRTC2),
204 CHIP_DEF(PCI_CHIP_RV370_5B62, RV380, CHIP_HAS_CRTC2), 204 CHIP_DEF(PCI_CHIP_RV370_5B62, RV380, CHIP_HAS_CRTC2),
205 CHIP_DEF(PCI_CHIP_RV370_5B63, RV380, CHIP_HAS_CRTC2),
205 CHIP_DEF(PCI_CHIP_RV370_5B64, RV380, CHIP_HAS_CRTC2), 206 CHIP_DEF(PCI_CHIP_RV370_5B64, RV380, CHIP_HAS_CRTC2),
206 CHIP_DEF(PCI_CHIP_RV370_5B65, RV380, CHIP_HAS_CRTC2), 207 CHIP_DEF(PCI_CHIP_RV370_5B65, RV380, CHIP_HAS_CRTC2),
207 CHIP_DEF(PCI_CHIP_RV370_5460, RV380, CHIP_HAS_CRTC2 | CHIP_IS_MOBILITY), 208 CHIP_DEF(PCI_CHIP_RV370_5460, RV380, CHIP_HAS_CRTC2 | CHIP_IS_MOBILITY),
diff --git a/drivers/video/console/Kconfig b/drivers/video/console/Kconfig
index 267422f66255..b87ed37ac0c1 100644
--- a/drivers/video/console/Kconfig
+++ b/drivers/video/console/Kconfig
@@ -6,7 +6,7 @@ menu "Console display driver support"
6 6
7config VGA_CONSOLE 7config VGA_CONSOLE
8 bool "VGA text console" if EMBEDDED || !X86 8 bool "VGA text console" if EMBEDDED || !X86
9 depends on !ARCH_ACORN && !ARCH_EBSA110 && !4xx && !8xx && !SPARC && !M68K && !PARISC && !FRV && !ARCH_VERSATILE && !SUPERH && !BFIN 9 depends on !ARCH_ACORN && !ARCH_EBSA110 && !4xx && !8xx && !SPARC && !M68K && !PARISC && !FRV && !ARCH_VERSATILE && !SUPERH && !BLACKFIN
10 default y 10 default y
11 help 11 help
12 Saying Y here will allow you to use Linux in text mode through a 12 Saying Y here will allow you to use Linux in text mode through a
diff --git a/drivers/video/efifb.c b/drivers/video/efifb.c
new file mode 100644
index 000000000000..bd779ae44b1e
--- /dev/null
+++ b/drivers/video/efifb.c
@@ -0,0 +1,232 @@
1/*
2 * Framebuffer driver for EFI/UEFI based system
3 *
4 * (c) 2006 Edgar Hucek <gimli@dark-green.com>
5 * Original efi driver written by Gerd Knorr <kraxel@goldbach.in-berlin.de>
6 *
7 */
8
9#include <linux/module.h>
10#include <linux/kernel.h>
11#include <linux/errno.h>
12#include <linux/fb.h>
13#include <linux/platform_device.h>
14#include <linux/screen_info.h>
15
16#include <video/vga.h>
17
18static struct fb_var_screeninfo efifb_defined __initdata = {
19 .activate = FB_ACTIVATE_NOW,
20 .height = -1,
21 .width = -1,
22 .right_margin = 32,
23 .upper_margin = 16,
24 .lower_margin = 4,
25 .vsync_len = 4,
26 .vmode = FB_VMODE_NONINTERLACED,
27};
28
29static struct fb_fix_screeninfo efifb_fix __initdata = {
30 .id = "EFI VGA",
31 .type = FB_TYPE_PACKED_PIXELS,
32 .accel = FB_ACCEL_NONE,
33 .visual = FB_VISUAL_TRUECOLOR,
34};
35
36static int efifb_setcolreg(unsigned regno, unsigned red, unsigned green,
37 unsigned blue, unsigned transp,
38 struct fb_info *info)
39{
40 /*
41 * Set a single color register. The values supplied are
42 * already rounded down to the hardware's capabilities
43 * (according to the entries in the `var' structure). Return
44 * != 0 for invalid regno.
45 */
46
47 if (regno >= info->cmap.len)
48 return 1;
49
50 if (regno < 16) {
51 red >>= 8;
52 green >>= 8;
53 blue >>= 8;
54 ((u32 *)(info->pseudo_palette))[regno] =
55 (red << info->var.red.offset) |
56 (green << info->var.green.offset) |
57 (blue << info->var.blue.offset);
58 }
59 return 0;
60}
61
62static struct fb_ops efifb_ops = {
63 .owner = THIS_MODULE,
64 .fb_setcolreg = efifb_setcolreg,
65 .fb_fillrect = cfb_fillrect,
66 .fb_copyarea = cfb_copyarea,
67 .fb_imageblit = cfb_imageblit,
68};
69
70static int __init efifb_probe(struct platform_device *dev)
71{
72 struct fb_info *info;
73 int err;
74 unsigned int size_vmode;
75 unsigned int size_remap;
76 unsigned int size_total;
77
78 efifb_fix.smem_start = screen_info.lfb_base;
79 efifb_defined.bits_per_pixel = screen_info.lfb_depth;
80 efifb_defined.xres = screen_info.lfb_width;
81 efifb_defined.yres = screen_info.lfb_height;
82 efifb_fix.line_length = screen_info.lfb_linelength;
83
84 /* size_vmode -- that is the amount of memory needed for the
85 * used video mode, i.e. the minimum amount of
86 * memory we need. */
87 size_vmode = efifb_defined.yres * efifb_fix.line_length;
88
89 /* size_total -- all video memory we have. Used for
90 * entries, ressource allocation and bounds
91 * checking. */
92 size_total = screen_info.lfb_size;
93 if (size_total < size_vmode)
94 size_total = size_vmode;
95
96 /* size_remap -- the amount of video memory we are going to
97 * use for efifb. With modern cards it is no
98 * option to simply use size_total as that
99 * wastes plenty of kernel address space. */
100 size_remap = size_vmode * 2;
101 if (size_remap < size_vmode)
102 size_remap = size_vmode;
103 if (size_remap > size_total)
104 size_remap = size_total;
105 efifb_fix.smem_len = size_remap;
106
107 if (!request_mem_region(efifb_fix.smem_start, size_total, "efifb"))
108 /* We cannot make this fatal. Sometimes this comes from magic
109 spaces our resource handlers simply don't know about */
110 printk(KERN_WARNING
111 "efifb: cannot reserve video memory at 0x%lx\n",
112 efifb_fix.smem_start);
113
114 info = framebuffer_alloc(sizeof(u32) * 16, &dev->dev);
115 if (!info) {
116 err = -ENOMEM;
117 goto err_release_mem;
118 }
119 info->pseudo_palette = info->par;
120 info->par = NULL;
121
122 info->screen_base = ioremap(efifb_fix.smem_start, efifb_fix.smem_len);
123 if (!info->screen_base) {
124 printk(KERN_ERR "efifb: abort, cannot ioremap video memory "
125 "0x%x @ 0x%lx\n",
126 efifb_fix.smem_len, efifb_fix.smem_start);
127 err = -EIO;
128 goto err_unmap;
129 }
130
131 printk(KERN_INFO "efifb: framebuffer at 0x%lx, mapped to 0x%p, "
132 "using %dk, total %dk\n",
133 efifb_fix.smem_start, info->screen_base,
134 size_remap/1024, size_total/1024);
135 printk(KERN_INFO "efifb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
136 efifb_defined.xres, efifb_defined.yres,
137 efifb_defined.bits_per_pixel, efifb_fix.line_length,
138 screen_info.pages);
139
140 efifb_defined.xres_virtual = efifb_defined.xres;
141 efifb_defined.yres_virtual = efifb_fix.smem_len /
142 efifb_fix.line_length;
143 printk(KERN_INFO "efifb: scrolling: redraw\n");
144 efifb_defined.yres_virtual = efifb_defined.yres;
145
146 /* some dummy values for timing to make fbset happy */
147 efifb_defined.pixclock = 10000000 / efifb_defined.xres *
148 1000 / efifb_defined.yres;
149 efifb_defined.left_margin = (efifb_defined.xres / 8) & 0xf8;
150 efifb_defined.hsync_len = (efifb_defined.xres / 8) & 0xf8;
151
152 efifb_defined.red.offset = screen_info.red_pos;
153 efifb_defined.red.length = screen_info.red_size;
154 efifb_defined.green.offset = screen_info.green_pos;
155 efifb_defined.green.length = screen_info.green_size;
156 efifb_defined.blue.offset = screen_info.blue_pos;
157 efifb_defined.blue.length = screen_info.blue_size;
158 efifb_defined.transp.offset = screen_info.rsvd_pos;
159 efifb_defined.transp.length = screen_info.rsvd_size;
160
161 printk(KERN_INFO "efifb: %s: "
162 "size=%d:%d:%d:%d, shift=%d:%d:%d:%d\n",
163 "Truecolor",
164 screen_info.rsvd_size,
165 screen_info.red_size,
166 screen_info.green_size,
167 screen_info.blue_size,
168 screen_info.rsvd_pos,
169 screen_info.red_pos,
170 screen_info.green_pos,
171 screen_info.blue_pos);
172
173 efifb_fix.ypanstep = 0;
174 efifb_fix.ywrapstep = 0;
175
176 info->fbops = &efifb_ops;
177 info->var = efifb_defined;
178 info->fix = efifb_fix;
179 info->flags = FBINFO_FLAG_DEFAULT;
180
181 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
182 err = -ENOMEM;
183 goto err_unmap;
184 }
185 if (register_framebuffer(info) < 0) {
186 err = -EINVAL;
187 goto err_fb_dealoc;
188 }
189 printk(KERN_INFO "fb%d: %s frame buffer device\n",
190 info->node, info->fix.id);
191 return 0;
192
193err_fb_dealoc:
194 fb_dealloc_cmap(&info->cmap);
195err_unmap:
196 iounmap(info->screen_base);
197 framebuffer_release(info);
198err_release_mem:
199 release_mem_region(efifb_fix.smem_start, size_total);
200 return err;
201}
202
203static struct platform_driver efifb_driver = {
204 .probe = efifb_probe,
205 .driver = {
206 .name = "efifb",
207 },
208};
209
210static struct platform_device efifb_device = {
211 .name = "efifb",
212};
213
214static int __init efifb_init(void)
215{
216 int ret;
217
218 if (screen_info.orig_video_isVGA != VIDEO_TYPE_EFI)
219 return -ENODEV;
220
221 ret = platform_driver_register(&efifb_driver);
222
223 if (!ret) {
224 ret = platform_device_register(&efifb_device);
225 if (ret)
226 platform_driver_unregister(&efifb_driver);
227 }
228 return ret;
229}
230module_init(efifb_init);
231
232MODULE_LICENSE("GPL");
diff --git a/drivers/video/fb_ddc.c b/drivers/video/fb_ddc.c
index f836137a0eda..a0df63289b5f 100644
--- a/drivers/video/fb_ddc.c
+++ b/drivers/video/fb_ddc.c
@@ -56,13 +56,12 @@ unsigned char *fb_ddc_read(struct i2c_adapter *adapter)
56 int i, j; 56 int i, j;
57 57
58 algo_data->setscl(algo_data->data, 1); 58 algo_data->setscl(algo_data->data, 1);
59 algo_data->setscl(algo_data->data, 0);
60 59
61 for (i = 0; i < 3; i++) { 60 for (i = 0; i < 3; i++) {
62 /* For some old monitors we need the 61 /* For some old monitors we need the
63 * following process to initialize/stop DDC 62 * following process to initialize/stop DDC
64 */ 63 */
65 algo_data->setsda(algo_data->data, 0); 64 algo_data->setsda(algo_data->data, 1);
66 msleep(13); 65 msleep(13);
67 66
68 algo_data->setscl(algo_data->data, 1); 67 algo_data->setscl(algo_data->data, 1);
@@ -97,14 +96,15 @@ unsigned char *fb_ddc_read(struct i2c_adapter *adapter)
97 algo_data->setsda(algo_data->data, 1); 96 algo_data->setsda(algo_data->data, 1);
98 msleep(15); 97 msleep(15);
99 algo_data->setscl(algo_data->data, 0); 98 algo_data->setscl(algo_data->data, 0);
99 algo_data->setsda(algo_data->data, 0);
100 if (edid) 100 if (edid)
101 break; 101 break;
102 } 102 }
103 /* Release the DDC lines when done or the Apple Cinema HD display 103 /* Release the DDC lines when done or the Apple Cinema HD display
104 * will switch off 104 * will switch off
105 */ 105 */
106 algo_data->setsda(algo_data->data, 0); 106 algo_data->setsda(algo_data->data, 1);
107 algo_data->setscl(algo_data->data, 0); 107 algo_data->setscl(algo_data->data, 1);
108 108
109 return edid; 109 return edid;
110} 110}
diff --git a/drivers/video/imacfb.c b/drivers/video/imacfb.c
index 6455fd2a39f2..9366ef2bb5f7 100644
--- a/drivers/video/imacfb.c
+++ b/drivers/video/imacfb.c
@@ -234,10 +234,6 @@ static int __init imacfb_probe(struct platform_device *dev)
234 size_remap = size_total; 234 size_remap = size_total;
235 imacfb_fix.smem_len = size_remap; 235 imacfb_fix.smem_len = size_remap;
236 236
237#ifndef __i386__
238 screen_info.imacpm_seg = 0;
239#endif
240
241 if (!request_mem_region(imacfb_fix.smem_start, size_total, "imacfb")) { 237 if (!request_mem_region(imacfb_fix.smem_start, size_total, "imacfb")) {
242 printk(KERN_WARNING 238 printk(KERN_WARNING
243 "imacfb: cannot reserve video memory at 0x%lx\n", 239 "imacfb: cannot reserve video memory at 0x%lx\n",
diff --git a/drivers/video/ps3fb.c b/drivers/video/ps3fb.c
index 75836aa83191..b3128903d673 100644
--- a/drivers/video/ps3fb.c
+++ b/drivers/video/ps3fb.c
@@ -51,8 +51,8 @@
51#define L1GPU_DISPLAY_SYNC_HSYNC 1 51#define L1GPU_DISPLAY_SYNC_HSYNC 1
52#define L1GPU_DISPLAY_SYNC_VSYNC 2 52#define L1GPU_DISPLAY_SYNC_VSYNC 2
53 53
54#define DDR_SIZE (0) /* used no ddr */ 54#define GPU_CMD_BUF_SIZE (2 * 1024 * 1024)
55#define GPU_CMD_BUF_SIZE (64 * 1024) 55#define GPU_FB_START (64 * 1024)
56#define GPU_IOIF (0x0d000000UL) 56#define GPU_IOIF (0x0d000000UL)
57#define GPU_ALIGN_UP(x) _ALIGN_UP((x), 64) 57#define GPU_ALIGN_UP(x) _ALIGN_UP((x), 64)
58#define GPU_MAX_LINE_LENGTH (65536 - 64) 58#define GPU_MAX_LINE_LENGTH (65536 - 64)
@@ -407,6 +407,7 @@ static void ps3fb_sync_image(struct device *dev, u64 frame_offset,
407 if (src_line_length != dst_line_length) 407 if (src_line_length != dst_line_length)
408 line_length |= (u64)src_line_length << 32; 408 line_length |= (u64)src_line_length << 32;
409 409
410 src_offset += GPU_FB_START;
410 status = lv1_gpu_context_attribute(ps3fb.context_handle, 411 status = lv1_gpu_context_attribute(ps3fb.context_handle,
411 L1GPU_CONTEXT_ATTRIBUTE_FB_BLIT, 412 L1GPU_CONTEXT_ATTRIBUTE_FB_BLIT,
412 dst_offset, GPU_IOIF + src_offset, 413 dst_offset, GPU_IOIF + src_offset,
@@ -977,9 +978,8 @@ static int ps3fb_xdr_settings(u64 xdr_lpar, struct device *dev)
977 978
978 status = lv1_gpu_context_attribute(ps3fb.context_handle, 979 status = lv1_gpu_context_attribute(ps3fb.context_handle,
979 L1GPU_CONTEXT_ATTRIBUTE_FB_SETUP, 980 L1GPU_CONTEXT_ATTRIBUTE_FB_SETUP,
980 xdr_lpar + ps3fb.xdr_size, 981 xdr_lpar, GPU_CMD_BUF_SIZE,
981 GPU_CMD_BUF_SIZE, 982 GPU_IOIF, 0);
982 GPU_IOIF + ps3fb.xdr_size, 0);
983 if (status) { 983 if (status) {
984 dev_err(dev, 984 dev_err(dev,
985 "%s: lv1_gpu_context_attribute FB_SETUP failed: %d\n", 985 "%s: lv1_gpu_context_attribute FB_SETUP failed: %d\n",
@@ -1060,6 +1060,12 @@ static int __devinit ps3fb_probe(struct ps3_system_bus_device *dev)
1060 u64 xdr_lpar; 1060 u64 xdr_lpar;
1061 int status, res_index; 1061 int status, res_index;
1062 struct task_struct *task; 1062 struct task_struct *task;
1063 unsigned long max_ps3fb_size;
1064
1065 if (ps3fb_videomemory.size < GPU_CMD_BUF_SIZE) {
1066 dev_err(&dev->core, "%s: Not enough video memory\n", __func__);
1067 return -ENOMEM;
1068 }
1063 1069
1064 status = ps3_open_hv_device(dev); 1070 status = ps3_open_hv_device(dev);
1065 if (status) { 1071 if (status) {
@@ -1085,8 +1091,15 @@ static int __devinit ps3fb_probe(struct ps3_system_bus_device *dev)
1085 1091
1086 ps3fb_set_sync(&dev->core); 1092 ps3fb_set_sync(&dev->core);
1087 1093
1094 max_ps3fb_size = _ALIGN_UP(GPU_IOIF, 256*1024*1024) - GPU_IOIF;
1095 if (ps3fb_videomemory.size > max_ps3fb_size) {
1096 dev_info(&dev->core, "Limiting ps3fb mem size to %lu bytes\n",
1097 max_ps3fb_size);
1098 ps3fb_videomemory.size = max_ps3fb_size;
1099 }
1100
1088 /* get gpu context handle */ 1101 /* get gpu context handle */
1089 status = lv1_gpu_memory_allocate(DDR_SIZE, 0, 0, 0, 0, 1102 status = lv1_gpu_memory_allocate(ps3fb_videomemory.size, 0, 0, 0, 0,
1090 &ps3fb.memory_handle, &ddr_lpar); 1103 &ps3fb.memory_handle, &ddr_lpar);
1091 if (status) { 1104 if (status) {
1092 dev_err(&dev->core, "%s: lv1_gpu_memory_allocate failed: %d\n", 1105 dev_err(&dev->core, "%s: lv1_gpu_memory_allocate failed: %d\n",
@@ -1124,8 +1137,14 @@ static int __devinit ps3fb_probe(struct ps3_system_bus_device *dev)
1124 /* Clear memory to prevent kernel info leakage into userspace */ 1137 /* Clear memory to prevent kernel info leakage into userspace */
1125 memset(ps3fb.xdr_ea, 0, ps3fb_videomemory.size); 1138 memset(ps3fb.xdr_ea, 0, ps3fb_videomemory.size);
1126 1139
1127 /* The GPU command buffer is at the end of video memory */ 1140 /*
1128 ps3fb.xdr_size = ps3fb_videomemory.size - GPU_CMD_BUF_SIZE; 1141 * The GPU command buffer is at the start of video memory
1142 * As we don't use the full command buffer, we can put the actual
1143 * frame buffer at offset GPU_FB_START and save some precious XDR
1144 * memory
1145 */
1146 ps3fb.xdr_ea += GPU_FB_START;
1147 ps3fb.xdr_size = ps3fb_videomemory.size - GPU_FB_START;
1129 1148
1130 retval = ps3fb_xdr_settings(xdr_lpar, &dev->core); 1149 retval = ps3fb_xdr_settings(xdr_lpar, &dev->core);
1131 if (retval) 1150 if (retval)
@@ -1193,7 +1212,7 @@ err_fb_dealloc:
1193err_framebuffer_release: 1212err_framebuffer_release:
1194 framebuffer_release(info); 1213 framebuffer_release(info);
1195err_free_irq: 1214err_free_irq:
1196 free_irq(ps3fb.irq_no, dev); 1215 free_irq(ps3fb.irq_no, &dev->core);
1197 ps3_irq_plug_destroy(ps3fb.irq_no); 1216 ps3_irq_plug_destroy(ps3fb.irq_no);
1198err_iounmap_dinfo: 1217err_iounmap_dinfo:
1199 iounmap((u8 __iomem *)ps3fb.dinfo); 1218 iounmap((u8 __iomem *)ps3fb.dinfo);
@@ -1228,7 +1247,7 @@ static int ps3fb_shutdown(struct ps3_system_bus_device *dev)
1228 kthread_stop(task); 1247 kthread_stop(task);
1229 } 1248 }
1230 if (ps3fb.irq_no) { 1249 if (ps3fb.irq_no) {
1231 free_irq(ps3fb.irq_no, dev); 1250 free_irq(ps3fb.irq_no, &dev->core);
1232 ps3_irq_plug_destroy(ps3fb.irq_no); 1251 ps3_irq_plug_destroy(ps3fb.irq_no);
1233 } 1252 }
1234 iounmap((u8 __iomem *)ps3fb.dinfo); 1253 iounmap((u8 __iomem *)ps3fb.dinfo);
diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c
index 15d7787dea87..69d7ea02cd48 100644
--- a/drivers/virtio/virtio.c
+++ b/drivers/virtio/virtio.c
@@ -96,10 +96,23 @@ static int virtio_dev_probe(struct device *_d)
96 return err; 96 return err;
97} 97}
98 98
99static int virtio_dev_remove(struct device *_d)
100{
101 struct virtio_device *dev = container_of(_d,struct virtio_device,dev);
102 struct virtio_driver *drv = container_of(dev->dev.driver,
103 struct virtio_driver, driver);
104
105 dev->config->set_status(dev, dev->config->get_status(dev)
106 & ~VIRTIO_CONFIG_S_DRIVER);
107 drv->remove(dev);
108 return 0;
109}
110
99int register_virtio_driver(struct virtio_driver *driver) 111int register_virtio_driver(struct virtio_driver *driver)
100{ 112{
101 driver->driver.bus = &virtio_bus; 113 driver->driver.bus = &virtio_bus;
102 driver->driver.probe = virtio_dev_probe; 114 driver->driver.probe = virtio_dev_probe;
115 driver->driver.remove = virtio_dev_remove;
103 return driver_register(&driver->driver); 116 return driver_register(&driver->driver);
104} 117}
105EXPORT_SYMBOL_GPL(register_virtio_driver); 118EXPORT_SYMBOL_GPL(register_virtio_driver);
diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index 2792bc1a7269..52dff40ec192 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -392,6 +392,16 @@ config ITCO_VENDOR_SUPPORT
392 devices. At this moment we only have additional support for some 392 devices. At this moment we only have additional support for some
393 SuperMicro Inc. motherboards. 393 SuperMicro Inc. motherboards.
394 394
395config IT8712F_WDT
396 tristate "IT8712F (Smart Guardian) Watchdog Timer"
397 depends on X86
398 ---help---
399 This is the driver for the built-in watchdog timer on the IT8712F
400 Super I/0 chipset used on many motherboards.
401
402 To compile this driver as a module, choose M here: the
403 module will be called it8712f_wdt.
404
395config SC1200_WDT 405config SC1200_WDT
396 tristate "National Semiconductor PC87307/PC97307 (ala SC1200) Watchdog" 406 tristate "National Semiconductor PC87307/PC97307 (ala SC1200) Watchdog"
397 depends on X86 407 depends on X86
@@ -456,6 +466,19 @@ config SBC8360_WDT
456 466
457 Most people will say N. 467 Most people will say N.
458 468
469config SBC7240_WDT
470 tristate "SBC Nano 7240 Watchdog Timer"
471 depends on X86_32
472 ---help---
473 This is the driver for the hardware watchdog found on the IEI
474 single board computers EPIC Nano 7240 (and likely others). This
475 watchdog simply watches your kernel to make sure it doesn't freeze,
476 and if it does, it reboots your computer after a certain amount of
477 time.
478
479 To compile this driver as a module, choose M here: the
480 module will be called sbc7240_wdt.
481
459config CPU5_WDT 482config CPU5_WDT
460 tristate "SMA CPU5 Watchdog" 483 tristate "SMA CPU5 Watchdog"
461 depends on X86 484 depends on X86
diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile
index 7d9e5734f8bb..87483cc63252 100644
--- a/drivers/watchdog/Makefile
+++ b/drivers/watchdog/Makefile
@@ -66,11 +66,13 @@ obj-$(CONFIG_IBMASR) += ibmasr.o
66obj-$(CONFIG_WAFER_WDT) += wafer5823wdt.o 66obj-$(CONFIG_WAFER_WDT) += wafer5823wdt.o
67obj-$(CONFIG_I6300ESB_WDT) += i6300esb.o 67obj-$(CONFIG_I6300ESB_WDT) += i6300esb.o
68obj-$(CONFIG_ITCO_WDT) += iTCO_wdt.o iTCO_vendor_support.o 68obj-$(CONFIG_ITCO_WDT) += iTCO_wdt.o iTCO_vendor_support.o
69obj-$(CONFIG_IT8712F_WDT) += it8712f_wdt.o
69obj-$(CONFIG_SC1200_WDT) += sc1200wdt.o 70obj-$(CONFIG_SC1200_WDT) += sc1200wdt.o
70obj-$(CONFIG_SCx200_WDT) += scx200_wdt.o 71obj-$(CONFIG_SCx200_WDT) += scx200_wdt.o
71obj-$(CONFIG_PC87413_WDT) += pc87413_wdt.o 72obj-$(CONFIG_PC87413_WDT) += pc87413_wdt.o
72obj-$(CONFIG_60XX_WDT) += sbc60xxwdt.o 73obj-$(CONFIG_60XX_WDT) += sbc60xxwdt.o
73obj-$(CONFIG_SBC8360_WDT) += sbc8360.o 74obj-$(CONFIG_SBC8360_WDT) += sbc8360.o
75obj-$(CONFIG_SBC7240_WDT) += sbc7240_wdt.o
74obj-$(CONFIG_CPU5_WDT) += cpu5wdt.o 76obj-$(CONFIG_CPU5_WDT) += cpu5wdt.o
75obj-$(CONFIG_SMSC37B787_WDT) += smsc37b787_wdt.o 77obj-$(CONFIG_SMSC37B787_WDT) += smsc37b787_wdt.o
76obj-$(CONFIG_W83627HF_WDT) += w83627hf_wdt.o 78obj-$(CONFIG_W83627HF_WDT) += w83627hf_wdt.o
diff --git a/drivers/watchdog/at32ap700x_wdt.c b/drivers/watchdog/at32ap700x_wdt.c
index 54a516169d07..fb5ed6478f78 100644
--- a/drivers/watchdog/at32ap700x_wdt.c
+++ b/drivers/watchdog/at32ap700x_wdt.c
@@ -6,6 +6,19 @@
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as 7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation. 8 * published by the Free Software Foundation.
9 *
10 *
11 * Errata: WDT Clear is blocked after WDT Reset
12 *
13 * A watchdog timer event will, after reset, block writes to the WDT_CLEAR
14 * register, preventing the program to clear the next Watchdog Timer Reset.
15 *
16 * If you still want to use the WDT after a WDT reset a small code can be
17 * insterted at the startup checking the AVR32_PM.rcause register for WDT reset
18 * and use a GPIO pin to reset the system. This method requires that one of the
19 * GPIO pins are available and connected externally to the RESET_N pin. After
20 * the GPIO pin has pulled down the reset line the GPIO will be reset and leave
21 * the pin tristated with pullup.
9 */ 22 */
10 23
11#include <linux/init.h> 24#include <linux/init.h>
@@ -44,6 +57,13 @@ MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
44 57
45#define WDT_CLR 0x04 58#define WDT_CLR 0x04
46 59
60#define WDT_RCAUSE 0x10
61#define WDT_RCAUSE_POR 0
62#define WDT_RCAUSE_EXT 2
63#define WDT_RCAUSE_WDT 3
64#define WDT_RCAUSE_JTAG 4
65#define WDT_RCAUSE_SERP 5
66
47#define WDT_BIT(name) (1 << WDT_##name) 67#define WDT_BIT(name) (1 << WDT_##name)
48#define WDT_BF(name, value) ((value) << WDT_##name) 68#define WDT_BF(name, value) ((value) << WDT_##name)
49 69
@@ -56,6 +76,7 @@ struct wdt_at32ap700x {
56 void __iomem *regs; 76 void __iomem *regs;
57 spinlock_t io_lock; 77 spinlock_t io_lock;
58 int timeout; 78 int timeout;
79 int boot_status;
59 unsigned long users; 80 unsigned long users;
60 struct miscdevice miscdev; 81 struct miscdevice miscdev;
61}; 82};
@@ -126,7 +147,7 @@ static int at32_wdt_close(struct inode *inode, struct file *file)
126 at32_wdt_stop(); 147 at32_wdt_stop();
127 } else { 148 } else {
128 dev_dbg(wdt->miscdev.parent, 149 dev_dbg(wdt->miscdev.parent,
129 "Unexpected close, not stopping watchdog!\n"); 150 "unexpected close, not stopping watchdog!\n");
130 at32_wdt_pat(); 151 at32_wdt_pat();
131 } 152 }
132 clear_bit(1, &wdt->users); 153 clear_bit(1, &wdt->users);
@@ -154,6 +175,33 @@ static int at32_wdt_settimeout(int time)
154 return 0; 175 return 0;
155} 176}
156 177
178/*
179 * Get the watchdog status.
180 */
181static int at32_wdt_get_status(void)
182{
183 int rcause;
184 int status = 0;
185
186 rcause = wdt_readl(wdt, RCAUSE);
187
188 switch (rcause) {
189 case WDT_BIT(RCAUSE_EXT):
190 status = WDIOF_EXTERN1;
191 break;
192 case WDT_BIT(RCAUSE_WDT):
193 status = WDIOF_CARDRESET;
194 break;
195 case WDT_BIT(RCAUSE_POR): /* fall through */
196 case WDT_BIT(RCAUSE_JTAG): /* fall through */
197 case WDT_BIT(RCAUSE_SERP): /* fall through */
198 default:
199 break;
200 }
201
202 return status;
203}
204
157static struct watchdog_info at32_wdt_info = { 205static struct watchdog_info at32_wdt_info = {
158 .identity = "at32ap700x watchdog", 206 .identity = "at32ap700x watchdog",
159 .options = WDIOF_SETTIMEOUT | 207 .options = WDIOF_SETTIMEOUT |
@@ -194,10 +242,12 @@ static int at32_wdt_ioctl(struct inode *inode, struct file *file,
194 case WDIOC_GETTIMEOUT: 242 case WDIOC_GETTIMEOUT:
195 ret = put_user(wdt->timeout, p); 243 ret = put_user(wdt->timeout, p);
196 break; 244 break;
197 case WDIOC_GETSTATUS: /* fall through */ 245 case WDIOC_GETSTATUS:
198 case WDIOC_GETBOOTSTATUS:
199 ret = put_user(0, p); 246 ret = put_user(0, p);
200 break; 247 break;
248 case WDIOC_GETBOOTSTATUS:
249 ret = put_user(wdt->boot_status, p);
250 break;
201 case WDIOC_SETOPTIONS: 251 case WDIOC_SETOPTIONS:
202 ret = get_user(time, p); 252 ret = get_user(time, p);
203 if (ret) 253 if (ret)
@@ -282,8 +332,19 @@ static int __init at32_wdt_probe(struct platform_device *pdev)
282 dev_dbg(&pdev->dev, "could not map I/O memory\n"); 332 dev_dbg(&pdev->dev, "could not map I/O memory\n");
283 goto err_free; 333 goto err_free;
284 } 334 }
335
285 spin_lock_init(&wdt->io_lock); 336 spin_lock_init(&wdt->io_lock);
286 wdt->users = 0; 337 wdt->boot_status = at32_wdt_get_status();
338
339 /* Work-around for watchdog silicon errata. */
340 if (wdt->boot_status & WDIOF_CARDRESET) {
341 dev_info(&pdev->dev, "CPU must be reset with external "
342 "reset or POR due to silicon errata.\n");
343 ret = -EIO;
344 goto err_iounmap;
345 } else {
346 wdt->users = 0;
347 }
287 wdt->miscdev.minor = WATCHDOG_MINOR; 348 wdt->miscdev.minor = WATCHDOG_MINOR;
288 wdt->miscdev.name = "watchdog"; 349 wdt->miscdev.name = "watchdog";
289 wdt->miscdev.fops = &at32_wdt_fops; 350 wdt->miscdev.fops = &at32_wdt_fops;
diff --git a/drivers/watchdog/bfin_wdt.c b/drivers/watchdog/bfin_wdt.c
index 309d27913fc1..31dc7a69e90c 100644
--- a/drivers/watchdog/bfin_wdt.c
+++ b/drivers/watchdog/bfin_wdt.c
@@ -71,7 +71,7 @@ static int nowayout = WATCHDOG_NOWAYOUT;
71static struct watchdog_info bfin_wdt_info; 71static struct watchdog_info bfin_wdt_info;
72static unsigned long open_check; 72static unsigned long open_check;
73static char expect_close; 73static char expect_close;
74static spinlock_t bfin_wdt_spinlock = SPIN_LOCK_UNLOCKED; 74static DEFINE_SPINLOCK(bfin_wdt_spinlock);
75 75
76/** 76/**
77 * bfin_wdt_keepalive - Keep the Userspace Watchdog Alive 77 * bfin_wdt_keepalive - Keep the Userspace Watchdog Alive
diff --git a/drivers/watchdog/it8712f_wdt.c b/drivers/watchdog/it8712f_wdt.c
new file mode 100644
index 000000000000..6330fc02464e
--- /dev/null
+++ b/drivers/watchdog/it8712f_wdt.c
@@ -0,0 +1,400 @@
1/*
2 * IT8712F "Smart Guardian" Watchdog support
3 *
4 * Copyright (c) 2006-2007 Jorge Boncompte - DTI2 <jorge@dti2.net>
5 *
6 * Based on info and code taken from:
7 *
8 * drivers/char/watchdog/scx200_wdt.c
9 * drivers/hwmon/it87.c
10 * IT8712F EC-LPC I/O Preliminary Specification 0.9.2.pdf
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License as
14 * published by the Free Software Foundation; either version 2 of the
15 * License, or (at your option) any later version.
16 *
17 * The author(s) of this software shall not be held liable for damages
18 * of any nature resulting due to the use of this software. This
19 * software is provided AS-IS with no warranties.
20 */
21
22#include <linux/module.h>
23#include <linux/moduleparam.h>
24#include <linux/init.h>
25#include <linux/miscdevice.h>
26#include <linux/watchdog.h>
27#include <linux/notifier.h>
28#include <linux/reboot.h>
29#include <linux/fs.h>
30#include <linux/pci.h>
31#include <linux/spinlock.h>
32
33#include <asm/uaccess.h>
34#include <asm/io.h>
35
36#define NAME "it8712f_wdt"
37
38MODULE_AUTHOR("Jorge Boncompte - DTI2 <jorge@dti2.net>");
39MODULE_DESCRIPTION("IT8712F Watchdog Driver");
40MODULE_LICENSE("GPL");
41MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
42
43static int margin = 60; /* in seconds */
44module_param(margin, int, 0);
45MODULE_PARM_DESC(margin, "Watchdog margin in seconds");
46
47static int nowayout = WATCHDOG_NOWAYOUT;
48module_param(nowayout, int, 0);
49MODULE_PARM_DESC(nowayout, "Disable watchdog shutdown on close");
50
51static struct semaphore it8712f_wdt_sem;
52static unsigned expect_close;
53static spinlock_t io_lock;
54
55/* Dog Food address - We use the game port address */
56static unsigned short address;
57
58#define REG 0x2e /* The register to read/write */
59#define VAL 0x2f /* The value to read/write */
60
61#define LDN 0x07 /* Register: Logical device select */
62#define DEVID 0x20 /* Register: Device ID */
63#define DEVREV 0x22 /* Register: Device Revision */
64#define ACT_REG 0x30 /* LDN Register: Activation */
65#define BASE_REG 0x60 /* LDN Register: Base address */
66
67#define IT8712F_DEVID 0x8712
68
69#define LDN_GPIO 0x07 /* GPIO and Watch Dog Timer */
70#define LDN_GAME 0x09 /* Game Port */
71
72#define WDT_CONTROL 0x71 /* WDT Register: Control */
73#define WDT_CONFIG 0x72 /* WDT Register: Configuration */
74#define WDT_TIMEOUT 0x73 /* WDT Register: Timeout Value */
75
76#define WDT_RESET_GAME 0x10
77#define WDT_RESET_KBD 0x20
78#define WDT_RESET_MOUSE 0x40
79#define WDT_RESET_CIR 0x80
80
81#define WDT_UNIT_SEC 0x80 /* If 0 in MINUTES */
82
83#define WDT_OUT_PWROK 0x10
84#define WDT_OUT_KRST 0x40
85
86static int
87superio_inb(int reg)
88{
89 outb(reg, REG);
90 return inb(VAL);
91}
92
93static void
94superio_outb(int val, int reg)
95{
96 outb(reg, REG);
97 outb(val, VAL);
98}
99
100static int
101superio_inw(int reg)
102{
103 int val;
104 outb(reg++, REG);
105 val = inb(VAL) << 8;
106 outb(reg, REG);
107 val |= inb(VAL);
108 return val;
109}
110
111static inline void
112superio_select(int ldn)
113{
114 outb(LDN, REG);
115 outb(ldn, VAL);
116}
117
118static inline void
119superio_enter(void)
120{
121 spin_lock(&io_lock);
122 outb(0x87, REG);
123 outb(0x01, REG);
124 outb(0x55, REG);
125 outb(0x55, REG);
126}
127
128static inline void
129superio_exit(void)
130{
131 outb(0x02, REG);
132 outb(0x02, VAL);
133 spin_unlock(&io_lock);
134}
135
136static inline void
137it8712f_wdt_ping(void)
138{
139 inb(address);
140}
141
142static void
143it8712f_wdt_update_margin(void)
144{
145 int config = WDT_OUT_KRST | WDT_OUT_PWROK;
146
147 printk(KERN_INFO NAME ": timer margin %d seconds\n", margin);
148
149 /* The timeout register only has 8bits wide */
150 if (margin < 256)
151 config |= WDT_UNIT_SEC; /* else UNIT are MINUTES */
152 superio_outb(config, WDT_CONFIG);
153
154 superio_outb((margin > 255) ? (margin / 60) : margin, WDT_TIMEOUT);
155}
156
157static void
158it8712f_wdt_enable(void)
159{
160 printk(KERN_DEBUG NAME ": enabling watchdog timer\n");
161 superio_enter();
162 superio_select(LDN_GPIO);
163
164 superio_outb(WDT_RESET_GAME, WDT_CONTROL);
165
166 it8712f_wdt_update_margin();
167
168 superio_exit();
169
170 it8712f_wdt_ping();
171}
172
173static void
174it8712f_wdt_disable(void)
175{
176 printk(KERN_DEBUG NAME ": disabling watchdog timer\n");
177
178 superio_enter();
179 superio_select(LDN_GPIO);
180
181 superio_outb(0, WDT_CONFIG);
182 superio_outb(0, WDT_CONTROL);
183 superio_outb(0, WDT_TIMEOUT);
184
185 superio_exit();
186}
187
188static int
189it8712f_wdt_notify(struct notifier_block *this,
190 unsigned long code, void *unused)
191{
192 if (code == SYS_HALT || code == SYS_POWER_OFF)
193 if (!nowayout)
194 it8712f_wdt_disable();
195
196 return NOTIFY_DONE;
197}
198
199static struct notifier_block it8712f_wdt_notifier = {
200 .notifier_call = it8712f_wdt_notify,
201};
202
203static ssize_t
204it8712f_wdt_write(struct file *file, const char __user *data,
205 size_t len, loff_t *ppos)
206{
207 /* check for a magic close character */
208 if (len) {
209 size_t i;
210
211 it8712f_wdt_ping();
212
213 expect_close = 0;
214 for (i = 0; i < len; ++i) {
215 char c;
216 if (get_user(c, data+i))
217 return -EFAULT;
218 if (c == 'V')
219 expect_close = 42;
220 }
221 }
222
223 return len;
224}
225
226static int
227it8712f_wdt_ioctl(struct inode *inode, struct file *file,
228 unsigned int cmd, unsigned long arg)
229{
230 void __user *argp = (void __user *)arg;
231 int __user *p = argp;
232 static struct watchdog_info ident = {
233 .identity = "IT8712F Watchdog",
234 .firmware_version = 1,
235 .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING,
236 };
237 int new_margin;
238
239 switch (cmd) {
240 default:
241 return -ENOTTY;
242 case WDIOC_GETSUPPORT:
243 if (copy_to_user(argp, &ident, sizeof(ident)))
244 return -EFAULT;
245 return 0;
246 case WDIOC_GETSTATUS:
247 case WDIOC_GETBOOTSTATUS:
248 return put_user(0, p);
249 case WDIOC_KEEPALIVE:
250 it8712f_wdt_ping();
251 return 0;
252 case WDIOC_SETTIMEOUT:
253 if (get_user(new_margin, p))
254 return -EFAULT;
255 if (new_margin < 1)
256 return -EINVAL;
257 margin = new_margin;
258 superio_enter();
259 superio_select(LDN_GPIO);
260
261 it8712f_wdt_update_margin();
262
263 superio_exit();
264 it8712f_wdt_ping();
265 case WDIOC_GETTIMEOUT:
266 if (put_user(margin, p))
267 return -EFAULT;
268 return 0;
269 }
270}
271
272static int
273it8712f_wdt_open(struct inode *inode, struct file *file)
274{
275 /* only allow one at a time */
276 if (down_trylock(&it8712f_wdt_sem))
277 return -EBUSY;
278 it8712f_wdt_enable();
279
280 return nonseekable_open(inode, file);
281}
282
283static int
284it8712f_wdt_release(struct inode *inode, struct file *file)
285{
286 if (expect_close != 42) {
287 printk(KERN_WARNING NAME
288 ": watchdog device closed unexpectedly, will not"
289 " disable the watchdog timer\n");
290 } else if (!nowayout) {
291 it8712f_wdt_disable();
292 }
293 expect_close = 0;
294 up(&it8712f_wdt_sem);
295
296 return 0;
297}
298
299static struct file_operations it8712f_wdt_fops = {
300 .owner = THIS_MODULE,
301 .llseek = no_llseek,
302 .write = it8712f_wdt_write,
303 .ioctl = it8712f_wdt_ioctl,
304 .open = it8712f_wdt_open,
305 .release = it8712f_wdt_release,
306};
307
308static struct miscdevice it8712f_wdt_miscdev = {
309 .minor = WATCHDOG_MINOR,
310 .name = "watchdog",
311 .fops = &it8712f_wdt_fops,
312};
313
314static int __init
315it8712f_wdt_find(unsigned short *address)
316{
317 int err = -ENODEV;
318 int chip_type;
319
320 superio_enter();
321 chip_type = superio_inw(DEVID);
322 if (chip_type != IT8712F_DEVID)
323 goto exit;
324
325 superio_select(LDN_GAME);
326 superio_outb(1, ACT_REG);
327 if (!(superio_inb(ACT_REG) & 0x01)) {
328 printk(KERN_ERR NAME ": Device not activated, skipping\n");
329 goto exit;
330 }
331
332 *address = superio_inw(BASE_REG);
333 if (*address == 0) {
334 printk(KERN_ERR NAME ": Base address not set, skipping\n");
335 goto exit;
336 }
337
338 err = 0;
339 printk(KERN_DEBUG NAME ": Found IT%04xF chip revision %d - "
340 "using DogFood address 0x%x\n",
341 chip_type, superio_inb(DEVREV) & 0x0f, *address);
342
343exit:
344 superio_exit();
345 return err;
346}
347
348static int __init
349it8712f_wdt_init(void)
350{
351 int err = 0;
352
353 spin_lock_init(&io_lock);
354
355 if (it8712f_wdt_find(&address))
356 return -ENODEV;
357
358 if (!request_region(address, 1, "IT8712F Watchdog")) {
359 printk(KERN_WARNING NAME ": watchdog I/O region busy\n");
360 return -EBUSY;
361 }
362
363 it8712f_wdt_disable();
364
365 sema_init(&it8712f_wdt_sem, 1);
366
367 err = register_reboot_notifier(&it8712f_wdt_notifier);
368 if (err) {
369 printk(KERN_ERR NAME ": unable to register reboot notifier\n");
370 goto out;
371 }
372
373 err = misc_register(&it8712f_wdt_miscdev);
374 if (err) {
375 printk(KERN_ERR NAME
376 ": cannot register miscdev on minor=%d (err=%d)\n",
377 WATCHDOG_MINOR, err);
378 goto reboot_out;
379 }
380
381 return 0;
382
383
384reboot_out:
385 unregister_reboot_notifier(&it8712f_wdt_notifier);
386out:
387 release_region(address, 1);
388 return err;
389}
390
391static void __exit
392it8712f_wdt_exit(void)
393{
394 misc_deregister(&it8712f_wdt_miscdev);
395 unregister_reboot_notifier(&it8712f_wdt_notifier);
396 release_region(address, 1);
397}
398
399module_init(it8712f_wdt_init);
400module_exit(it8712f_wdt_exit);
diff --git a/drivers/watchdog/sbc7240_wdt.c b/drivers/watchdog/sbc7240_wdt.c
new file mode 100644
index 000000000000..4c8cefbd8627
--- /dev/null
+++ b/drivers/watchdog/sbc7240_wdt.c
@@ -0,0 +1,324 @@
1/*
2 * NANO7240 SBC Watchdog device driver
3 *
4 * Based on w83877f.c by Scott Jennings,
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation;
9 *
10 * Software distributed under the License is distributed on an "AS IS"
11 * basis, WITHOUT WARRANTY OF ANY KIND, either express or
12 * implied. See the License for the specific language governing
13 * rights and limitations under the License.
14 *
15 * (c) Copyright 2007 Gilles GIGAN <gilles.gigan@jcu.edu.au>
16 *
17 */
18
19#include <linux/fs.h>
20#include <linux/init.h>
21#include <linux/ioport.h>
22#include <linux/jiffies.h>
23#include <linux/module.h>
24#include <linux/moduleparam.h>
25#include <linux/miscdevice.h>
26#include <linux/notifier.h>
27#include <linux/reboot.h>
28#include <linux/types.h>
29#include <linux/watchdog.h>
30#include <asm/atomic.h>
31#include <asm/io.h>
32#include <asm/system.h>
33#include <asm/uaccess.h>
34
35#define SBC7240_PREFIX "sbc7240_wdt: "
36
37#define SBC7240_ENABLE_PORT 0x443
38#define SBC7240_DISABLE_PORT 0x043
39#define SBC7240_SET_TIMEOUT_PORT SBC7240_ENABLE_PORT
40#define SBC7240_MAGIC_CHAR 'V'
41
42#define SBC7240_TIMEOUT 30
43#define SBC7240_MAX_TIMEOUT 255
44static int timeout = SBC7240_TIMEOUT; /* in seconds */
45module_param(timeout, int, 0);
46MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds. (1<=timeout<="
47 __MODULE_STRING(SBC7240_MAX_TIMEOUT) ", default="
48 __MODULE_STRING(SBC7240_TIMEOUT) ")");
49
50static int nowayout = WATCHDOG_NOWAYOUT;
51module_param(nowayout, int, 0);
52MODULE_PARM_DESC(nowayout, "Disable watchdog when closing device file");
53
54#define SBC7240_OPEN_STATUS_BIT 0
55#define SBC7240_ENABLED_STATUS_BIT 1
56#define SBC7240_EXPECT_CLOSE_STATUS_BIT 2
57static unsigned long wdt_status;
58
59/*
60 * Utility routines
61 */
62
63static void wdt_disable(void)
64{
65 /* disable the watchdog */
66 if (test_and_clear_bit(SBC7240_ENABLED_STATUS_BIT, &wdt_status)) {
67 inb_p(SBC7240_DISABLE_PORT);
68 printk(KERN_INFO SBC7240_PREFIX
69 "Watchdog timer is now disabled.\n");
70 }
71}
72
73static void wdt_enable(void)
74{
75 /* enable the watchdog */
76 if (!test_and_set_bit(SBC7240_ENABLED_STATUS_BIT, &wdt_status)) {
77 inb_p(SBC7240_ENABLE_PORT);
78 printk(KERN_INFO SBC7240_PREFIX
79 "Watchdog timer is now enabled.\n");
80 }
81}
82
83static int wdt_set_timeout(int t)
84{
85 if (t < 1 || t > SBC7240_MAX_TIMEOUT) {
86 printk(KERN_ERR SBC7240_PREFIX
87 "timeout value must be 1<=x<=%d\n",
88 SBC7240_MAX_TIMEOUT);
89 return -1;
90 }
91 /* set the timeout */
92 outb_p((unsigned)t, SBC7240_SET_TIMEOUT_PORT);
93 timeout = t;
94 printk(KERN_INFO SBC7240_PREFIX "timeout set to %d seconds\n", t);
95 return 0;
96}
97
98/* Whack the dog */
99static inline void wdt_keepalive(void)
100{
101 if (test_bit(SBC7240_ENABLED_STATUS_BIT, &wdt_status))
102 inb_p(SBC7240_ENABLE_PORT);
103}
104
105/*
106 * /dev/watchdog handling
107 */
108static ssize_t fop_write(struct file *file, const char __user *buf,
109 size_t count, loff_t *ppos)
110{
111 size_t i;
112 char c;
113
114 if (count) {
115 if (!nowayout) {
116 clear_bit(SBC7240_EXPECT_CLOSE_STATUS_BIT,
117 &wdt_status);
118
119 /* is there a magic char ? */
120 for (i = 0; i != count; i++) {
121 if (get_user(c, buf + i))
122 return -EFAULT;
123 if (c == SBC7240_MAGIC_CHAR) {
124 set_bit(SBC7240_EXPECT_CLOSE_STATUS_BIT,
125 &wdt_status);
126 break;
127 }
128 }
129 }
130
131 wdt_keepalive();
132 }
133
134 return count;
135}
136
137static int fop_open(struct inode *inode, struct file *file)
138{
139 if (test_and_set_bit(SBC7240_OPEN_STATUS_BIT, &wdt_status))
140 return -EBUSY;
141
142 wdt_enable();
143
144 return nonseekable_open(inode, file);
145}
146
147static int fop_close(struct inode *inode, struct file *file)
148{
149 if (test_and_clear_bit(SBC7240_EXPECT_CLOSE_STATUS_BIT, &wdt_status)
150 || !nowayout) {
151 wdt_disable();
152 } else {
153 printk(KERN_CRIT SBC7240_PREFIX
154 "Unexpected close, not stopping watchdog!\n");
155 wdt_keepalive();
156 }
157
158 clear_bit(SBC7240_OPEN_STATUS_BIT, &wdt_status);
159 return 0;
160}
161
162static struct watchdog_info ident = {
163 .options = WDIOF_KEEPALIVEPING|
164 WDIOF_SETTIMEOUT|
165 WDIOF_MAGICCLOSE,
166 .firmware_version = 1,
167 .identity = "SBC7240",
168};
169
170
171static int fop_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
172 unsigned long arg)
173{
174 switch (cmd) {
175 case WDIOC_GETSUPPORT:
176 return copy_to_user
177 ((void __user *)arg, &ident, sizeof(ident))
178 ? -EFAULT : 0;
179 case WDIOC_GETSTATUS:
180 case WDIOC_GETBOOTSTATUS:
181 return put_user(0, (int __user *)arg);
182 case WDIOC_KEEPALIVE:
183 wdt_keepalive();
184 return 0;
185 case WDIOC_SETOPTIONS:{
186 int options;
187 int retval = -EINVAL;
188
189 if (get_user(options, (int __user *)arg))
190 return -EFAULT;
191
192 if (options & WDIOS_DISABLECARD) {
193 wdt_disable();
194 retval = 0;
195 }
196
197 if (options & WDIOS_ENABLECARD) {
198 wdt_enable();
199 retval = 0;
200 }
201
202 return retval;
203 }
204 case WDIOC_SETTIMEOUT:{
205 int new_timeout;
206
207 if (get_user(new_timeout, (int __user *)arg))
208 return -EFAULT;
209
210 if (wdt_set_timeout(new_timeout))
211 return -EINVAL;
212
213 /* Fall through */
214 }
215 case WDIOC_GETTIMEOUT:
216 return put_user(timeout, (int __user *)arg);
217 default:
218 return -ENOTTY;
219 }
220}
221
222static const struct file_operations wdt_fops = {
223 .owner = THIS_MODULE,
224 .llseek = no_llseek,
225 .write = fop_write,
226 .open = fop_open,
227 .release = fop_close,
228 .ioctl = fop_ioctl,
229};
230
231static struct miscdevice wdt_miscdev = {
232 .minor = WATCHDOG_MINOR,
233 .name = "watchdog",
234 .fops = &wdt_fops,
235};
236
237/*
238 * Notifier for system down
239 */
240
241static int wdt_notify_sys(struct notifier_block *this, unsigned long code,
242 void *unused)
243{
244 if (code == SYS_DOWN || code == SYS_HALT)
245 wdt_disable();
246 return NOTIFY_DONE;
247}
248
249static struct notifier_block wdt_notifier = {
250 .notifier_call = wdt_notify_sys,
251};
252
253static void __exit sbc7240_wdt_unload(void)
254{
255 printk(KERN_INFO SBC7240_PREFIX "Removing watchdog\n");
256 misc_deregister(&wdt_miscdev);
257
258 unregister_reboot_notifier(&wdt_notifier);
259 release_region(SBC7240_ENABLE_PORT, 1);
260}
261
262static int __init sbc7240_wdt_init(void)
263{
264 int rc = -EBUSY;
265
266 if (!request_region(SBC7240_ENABLE_PORT, 1, "SBC7240 WDT")) {
267 printk(KERN_ERR SBC7240_PREFIX
268 "I/O address 0x%04x already in use\n",
269 SBC7240_ENABLE_PORT);
270 rc = -EIO;
271 goto err_out;
272 }
273
274 /* The IO port 0x043 used to disable the watchdog
275 * is already claimed by the system timer, so we
276 * cant request_region() it ...*/
277
278 if (timeout < 1 || timeout > SBC7240_MAX_TIMEOUT) {
279 timeout = SBC7240_TIMEOUT;
280 printk(KERN_INFO SBC7240_PREFIX
281 "timeout value must be 1<=x<=%d, using %d\n",
282 SBC7240_MAX_TIMEOUT, timeout);
283 }
284 wdt_set_timeout(timeout);
285 wdt_disable();
286
287 rc = register_reboot_notifier(&wdt_notifier);
288 if (rc) {
289 printk(KERN_ERR SBC7240_PREFIX
290 "cannot register reboot notifier (err=%d)\n", rc);
291 goto err_out_region;
292 }
293
294 rc = misc_register(&wdt_miscdev);
295 if (rc) {
296 printk(KERN_ERR SBC7240_PREFIX
297 "cannot register miscdev on minor=%d (err=%d)\n",
298 wdt_miscdev.minor, rc);
299 goto err_out_reboot_notifier;
300 }
301
302 printk(KERN_INFO SBC7240_PREFIX
303 "Watchdog driver for SBC7240 initialised (nowayout=%d)\n",
304 nowayout);
305
306 return 0;
307
308err_out_reboot_notifier:
309 unregister_reboot_notifier(&wdt_notifier);
310err_out_region:
311 release_region(SBC7240_ENABLE_PORT, 1);
312err_out:
313 return rc;
314}
315
316module_init(sbc7240_wdt_init);
317module_exit(sbc7240_wdt_unload);
318
319MODULE_AUTHOR("Gilles Gigan");
320MODULE_DESCRIPTION("Watchdog device driver for single board"
321 " computers EPIC Nano 7240 from iEi");
322MODULE_LICENSE("GPL");
323MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
324
diff --git a/drivers/watchdog/w83697hf_wdt.c b/drivers/watchdog/w83697hf_wdt.c
index c622a0e6c9ae..6ea125eabeaa 100644
--- a/drivers/watchdog/w83697hf_wdt.c
+++ b/drivers/watchdog/w83697hf_wdt.c
@@ -382,8 +382,10 @@ wdt_init(void)
382 /* we will autodetect the W83697HF/HG watchdog */ 382 /* we will autodetect the W83697HF/HG watchdog */
383 for (i = 0; ((!found) && (w83697hf_ioports[i] != 0)); i++) { 383 for (i = 0; ((!found) && (w83697hf_ioports[i] != 0)); i++) {
384 wdt_io = w83697hf_ioports[i]; 384 wdt_io = w83697hf_ioports[i];
385 if (!w83697hf_check_wdt()) 385 if (!w83697hf_check_wdt()) {
386 found++; 386 found++;
387 break;
388 }
387 } 389 }
388 } else { 390 } else {
389 if (!w83697hf_check_wdt()) 391 if (!w83697hf_check_wdt())
diff --git a/drivers/zorro/zorro-driver.c b/drivers/zorro/zorro-driver.c
index 067c07be928c..e6c4390d8bd6 100644
--- a/drivers/zorro/zorro-driver.c
+++ b/drivers/zorro/zorro-driver.c
@@ -60,6 +60,20 @@ static int zorro_device_probe(struct device *dev)
60} 60}
61 61
62 62
63static int zorro_device_remove(struct device *dev)
64{
65 struct zorro_dev *z = to_zorro_dev(dev);
66 struct zorro_driver *drv = to_zorro_driver(dev->driver);
67
68 if (drv) {
69 if (drv->remove)
70 drv->remove(z);
71 z->driver = NULL;
72 }
73 return 0;
74}
75
76
63 /** 77 /**
64 * zorro_register_driver - register a new Zorro driver 78 * zorro_register_driver - register a new Zorro driver
65 * @drv: the driver structure to register 79 * @drv: the driver structure to register
@@ -128,6 +142,7 @@ struct bus_type zorro_bus_type = {
128 .name = "zorro", 142 .name = "zorro",
129 .match = zorro_bus_match, 143 .match = zorro_bus_match,
130 .probe = zorro_device_probe, 144 .probe = zorro_device_probe,
145 .remove = zorro_device_remove,
131}; 146};
132 147
133 148