aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/acpi/Kconfig10
-rw-r--r--drivers/acpi/Makefile1
-rw-r--r--drivers/acpi/ac.c9
-rw-r--r--drivers/acpi/acpi_memhotplug.c9
-rw-r--r--drivers/acpi/asus_acpi.c20
-rw-r--r--drivers/acpi/battery.c24
-rw-r--r--drivers/acpi/bay.c107
-rw-r--r--drivers/acpi/bus.c30
-rw-r--r--drivers/acpi/button.c7
-rw-r--r--drivers/acpi/cm_sbs.c2
-rw-r--r--drivers/acpi/container.c9
-rw-r--r--drivers/acpi/debug.c2
-rw-r--r--drivers/acpi/dispatcher/dsmethod.c12
-rw-r--r--drivers/acpi/dock.c8
-rw-r--r--drivers/acpi/ec.c9
-rw-r--r--drivers/acpi/event.c2
-rw-r--r--drivers/acpi/events/evgpe.c11
-rw-r--r--drivers/acpi/events/evmisc.c11
-rw-r--r--drivers/acpi/executer/exdump.c2
-rw-r--r--drivers/acpi/executer/exmutex.c36
-rw-r--r--drivers/acpi/fan.c9
-rw-r--r--drivers/acpi/glue.c62
-rw-r--r--drivers/acpi/hardware/hwsleep.c13
-rw-r--r--drivers/acpi/hotkey.c1042
-rw-r--r--drivers/acpi/i2c_ec.c5
-rw-r--r--drivers/acpi/ibm_acpi.c18
-rw-r--r--drivers/acpi/numa.c18
-rw-r--r--drivers/acpi/osl.c35
-rw-r--r--drivers/acpi/pci_bind.c2
-rw-r--r--drivers/acpi/pci_irq.c2
-rw-r--r--drivers/acpi/pci_link.c5
-rw-r--r--drivers/acpi/pci_root.c5
-rw-r--r--drivers/acpi/power.c156
-rw-r--r--drivers/acpi/processor_core.c13
-rw-r--r--drivers/acpi/processor_idle.c11
-rw-r--r--drivers/acpi/processor_perflib.c3
-rw-r--r--drivers/acpi/processor_thermal.c3
-rw-r--r--drivers/acpi/processor_throttling.c3
-rw-r--r--drivers/acpi/sbs.c25
-rw-r--r--drivers/acpi/scan.c3
-rw-r--r--drivers/acpi/sleep/main.c3
-rw-r--r--drivers/acpi/system.c3
-rw-r--r--drivers/acpi/tables.c41
-rw-r--r--drivers/acpi/tables/tbxface.c9
-rw-r--r--drivers/acpi/thermal.c37
-rw-r--r--drivers/acpi/toshiba_acpi.c6
-rw-r--r--drivers/acpi/utilities/utdelete.c1
-rw-r--r--drivers/acpi/utils.c2
-rw-r--r--drivers/acpi/video.c9
-rw-r--r--drivers/ata/Kconfig13
-rw-r--r--drivers/ata/Makefile2
-rw-r--r--drivers/ata/libata-acpi.c698
-rw-r--r--drivers/ata/libata-core.c14
-rw-r--r--drivers/ata/libata.h15
-rw-r--r--drivers/atm/he.c2
-rw-r--r--drivers/atm/idt77252.c8
-rw-r--r--drivers/atm/nicstarmac.c4
-rw-r--r--drivers/base/bus.c22
-rw-r--r--drivers/base/class.c3
-rw-r--r--drivers/base/cpu.c2
-rw-r--r--drivers/base/node.c2
-rw-r--r--drivers/char/rio/rio_linux.c2
-rw-r--r--drivers/hwmon/Kconfig11
-rw-r--r--drivers/hwmon/Makefile1
-rw-r--r--drivers/hwmon/abituguru.c30
-rw-r--r--drivers/hwmon/adm1026.c1
-rw-r--r--drivers/hwmon/adm1029.c508
-rw-r--r--drivers/hwmon/f71805f.c30
-rw-r--r--drivers/hwmon/hwmon.c2
-rw-r--r--drivers/hwmon/it87.c84
-rw-r--r--drivers/hwmon/lm70.c2
-rw-r--r--drivers/hwmon/lm78.c6
-rw-r--r--drivers/hwmon/lm85.c8
-rw-r--r--drivers/hwmon/sis5595.c6
-rw-r--r--drivers/hwmon/via686a.c5
-rw-r--r--drivers/hwmon/vt1211.c58
-rw-r--r--drivers/hwmon/w83627ehf.c54
-rw-r--r--drivers/hwmon/w83627hf.c5
-rw-r--r--drivers/hwmon/w83781d.c10
-rw-r--r--drivers/i2c/busses/i2c-ali1535.c2
-rw-r--r--drivers/i2c/busses/i2c-ali15x3.c2
-rw-r--r--drivers/i2c/busses/i2c-amd756.c2
-rw-r--r--drivers/i2c/busses/i2c-amd8111.c2
-rw-r--r--drivers/i2c/busses/i2c-i801.c2
-rw-r--r--drivers/i2c/busses/i2c-iop3xx.c2
-rw-r--r--drivers/i2c/busses/i2c-piix4.c2
-rw-r--r--drivers/i2c/busses/i2c-pxa.c241
-rw-r--r--drivers/i2c/busses/i2c-sis5595.c2
-rw-r--r--drivers/i2c/busses/i2c-sis630.c2
-rw-r--r--drivers/i2c/busses/i2c-sis96x.c2
-rw-r--r--drivers/i2c/busses/i2c-via.c2
-rw-r--r--drivers/ide/Kconfig11
-rw-r--r--drivers/ide/Makefile1
-rw-r--r--drivers/ide/arm/icside.c25
-rw-r--r--drivers/ide/arm/rapide.c2
-rw-r--r--drivers/ide/cris/ide-cris.c34
-rw-r--r--drivers/ide/h8300/ide-h8300.c4
-rw-r--r--drivers/ide/ide-cd.c44
-rw-r--r--drivers/ide/ide-disk.c14
-rw-r--r--drivers/ide/ide-dma.c105
-rw-r--r--drivers/ide/ide-floppy.c29
-rw-r--r--drivers/ide/ide-io.c15
-rw-r--r--drivers/ide/ide-iops.c34
-rw-r--r--drivers/ide/ide-lib.c20
-rw-r--r--drivers/ide/ide-probe.c4
-rw-r--r--drivers/ide/ide-tape.c12
-rw-r--r--drivers/ide/ide.c24
-rw-r--r--drivers/ide/legacy/buddha.c2
-rw-r--r--drivers/ide/legacy/gayle.c2
-rw-r--r--drivers/ide/legacy/ht6560b.c14
-rw-r--r--drivers/ide/legacy/macide.c2
-rw-r--r--drivers/ide/legacy/q40ide.c2
-rw-r--r--drivers/ide/mips/au1xxx-ide.c41
-rw-r--r--drivers/ide/mips/swarm.c2
-rw-r--r--drivers/ide/pci/aec62xx.c32
-rw-r--r--drivers/ide/pci/alim15x3.c15
-rw-r--r--drivers/ide/pci/amd74xx.c5
-rw-r--r--drivers/ide/pci/atiixp.c41
-rw-r--r--drivers/ide/pci/cmd64x.c47
-rw-r--r--drivers/ide/pci/cs5520.c5
-rw-r--r--drivers/ide/pci/cs5530.c41
-rw-r--r--drivers/ide/pci/cs5535.c19
-rw-r--r--drivers/ide/pci/cy82c693.c33
-rw-r--r--drivers/ide/pci/hpt34x.c42
-rw-r--r--drivers/ide/pci/hpt366.c24
-rw-r--r--drivers/ide/pci/it8213.c14
-rw-r--r--drivers/ide/pci/it821x.c14
-rw-r--r--drivers/ide/pci/jmicron.c14
-rw-r--r--drivers/ide/pci/ns87415.c13
-rw-r--r--drivers/ide/pci/opti621.c63
-rw-r--r--drivers/ide/pci/pdc202xx_new.c28
-rw-r--r--drivers/ide/pci/pdc202xx_old.c104
-rw-r--r--drivers/ide/pci/piix.c119
-rw-r--r--drivers/ide/pci/sc1200.c11
-rw-r--r--drivers/ide/pci/serverworks.c59
-rw-r--r--drivers/ide/pci/sgiioc4.c125
-rw-r--r--drivers/ide/pci/siimage.c113
-rw-r--r--drivers/ide/pci/sis5513.c59
-rw-r--r--drivers/ide/pci/sl82c105.c39
-rw-r--r--drivers/ide/pci/slc90e66.c22
-rw-r--r--drivers/ide/pci/tc86c001.c46
-rw-r--r--drivers/ide/pci/triflex.c24
-rw-r--r--drivers/ide/pci/trm290.c42
-rw-r--r--drivers/ide/pci/via82cxxx.c5
-rw-r--r--drivers/ide/ppc/pmac.c16
-rw-r--r--drivers/ide/ppc/scc_pata.c831
-rw-r--r--drivers/ieee1394/ieee1394-ioctl.h2
-rw-r--r--drivers/ieee1394/ieee1394_core.c43
-rw-r--r--drivers/ieee1394/ieee1394_core.h3
-rw-r--r--drivers/ieee1394/nodemgr.c3
-rw-r--r--drivers/ieee1394/ohci1394.c2
-rw-r--r--drivers/ieee1394/raw1394.c20
-rw-r--r--drivers/ieee1394/raw1394.h10
-rw-r--r--drivers/infiniband/core/Makefile2
-rw-r--r--drivers/infiniband/core/cma.c359
-rw-r--r--drivers/infiniband/core/fmr_pool.c4
-rw-r--r--drivers/infiniband/core/iwcm.c47
-rw-r--r--drivers/infiniband/core/multicast.c837
-rw-r--r--drivers/infiniband/core/sa.h66
-rw-r--r--drivers/infiniband/core/sa_query.c30
-rw-r--r--drivers/infiniband/core/sysfs.c2
-rw-r--r--drivers/infiniband/core/ucma.c204
-rw-r--r--drivers/infiniband/hw/cxgb3/cxio_dbg.c1
-rw-r--r--drivers/infiniband/hw/cxgb3/cxio_hal.c1
-rw-r--r--drivers/infiniband/hw/cxgb3/cxio_hal.h1
-rw-r--r--drivers/infiniband/hw/cxgb3/cxio_resource.c1
-rw-r--r--drivers/infiniband/hw/cxgb3/cxio_resource.h1
-rw-r--r--drivers/infiniband/hw/cxgb3/cxio_wr.h1
-rw-r--r--drivers/infiniband/hw/cxgb3/iwch.c1
-rw-r--r--drivers/infiniband/hw/cxgb3/iwch.h1
-rw-r--r--drivers/infiniband/hw/cxgb3/iwch_cm.c1
-rw-r--r--drivers/infiniband/hw/cxgb3/iwch_cm.h1
-rw-r--r--drivers/infiniband/hw/cxgb3/iwch_cq.c1
-rw-r--r--drivers/infiniband/hw/cxgb3/iwch_ev.c1
-rw-r--r--drivers/infiniband/hw/cxgb3/iwch_mem.c1
-rw-r--r--drivers/infiniband/hw/cxgb3/iwch_provider.c1
-rw-r--r--drivers/infiniband/hw/cxgb3/iwch_provider.h1
-rw-r--r--drivers/infiniband/hw/cxgb3/iwch_qp.c3
-rw-r--r--drivers/infiniband/hw/cxgb3/iwch_user.h1
-rw-r--r--drivers/infiniband/hw/ehca/Kconfig8
-rw-r--r--drivers/infiniband/hw/ehca/ehca_classes.h19
-rw-r--r--drivers/infiniband/hw/ehca/ehca_eq.c1
-rw-r--r--drivers/infiniband/hw/ehca/ehca_hca.c3
-rw-r--r--drivers/infiniband/hw/ehca/ehca_irq.c307
-rw-r--r--drivers/infiniband/hw/ehca/ehca_irq.h1
-rw-r--r--drivers/infiniband/hw/ehca/ehca_main.c32
-rw-r--r--drivers/infiniband/hw/ehca/ipz_pt_fn.h11
-rw-r--r--drivers/infiniband/hw/ipath/ipath_dma.c4
-rw-r--r--drivers/infiniband/hw/ipath/ipath_iba6110.c2
-rw-r--r--drivers/infiniband/hw/ipath/ipath_iba6120.c2
-rw-r--r--drivers/infiniband/hw/mthca/mthca_memfree.c4
-rw-r--r--drivers/infiniband/hw/mthca/mthca_qp.c5
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_cm.c4
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_multicast.c195
-rw-r--r--drivers/input/input.c17
-rw-r--r--drivers/input/joystick/amijoy.c2
-rw-r--r--drivers/input/joystick/analog.c2
-rw-r--r--drivers/input/joystick/db9.c4
-rw-r--r--drivers/input/joystick/gamecon.c6
-rw-r--r--drivers/input/joystick/turbografx.c4
-rw-r--r--drivers/input/keyboard/Kconfig6
-rw-r--r--drivers/input/keyboard/atkbd.c4
-rw-r--r--drivers/input/keyboard/gpio_keys.c15
-rw-r--r--drivers/input/keyboard/hilkbd.c2
-rw-r--r--drivers/input/mouse/inport.c2
-rw-r--r--drivers/input/mouse/logibm.c2
-rw-r--r--drivers/input/mouse/psmouse-base.c34
-rw-r--r--drivers/input/mouse/psmouse.h1
-rw-r--r--drivers/input/mouse/synaptics.c1
-rw-r--r--drivers/input/serio/i8042.c63
-rw-r--r--drivers/input/serio/libps2.c2
-rw-r--r--drivers/input/serio/serio.c36
-rw-r--r--drivers/isdn/i4l/isdn_ppp.c2
-rw-r--r--drivers/media/dvb/dvb-core/dvb_frontend.c2
-rw-r--r--drivers/media/dvb/frontends/dib3000mb.c2
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-audio.c2
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-cx2584x-v4l.c2
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-std.c4
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-tuner.c2
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-video-v4l.c2
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-wm8775.c2
-rw-r--r--drivers/misc/Kconfig15
-rw-r--r--drivers/misc/Makefile1
-rw-r--r--drivers/misc/asus-laptop.c5
-rw-r--r--drivers/misc/sony-laptop.c562
-rw-r--r--drivers/mmc/at91_mci.c46
-rw-r--r--drivers/mtd/chips/cfi_cmdset_0001.c26
-rw-r--r--drivers/mtd/chips/cfi_cmdset_0020.c2
-rw-r--r--drivers/mtd/devices/doc2000.c1
-rw-r--r--drivers/mtd/devices/doc2001.c1
-rw-r--r--drivers/mtd/devices/doc2001plus.c1
-rw-r--r--drivers/mtd/maps/Kconfig2
-rw-r--r--drivers/mtd/maps/amd76xrom.c4
-rw-r--r--drivers/mtd/maps/ck804xrom.c6
-rw-r--r--drivers/mtd/maps/esb2rom.c4
-rw-r--r--drivers/mtd/maps/ichxrom.c4
-rw-r--r--drivers/mtd/maps/netsc520.c4
-rw-r--r--drivers/mtd/maps/sc520cdp.c5
-rw-r--r--drivers/mtd/mtdchar.c5
-rw-r--r--drivers/mtd/mtdconcat.c4
-rw-r--r--drivers/mtd/mtdpart.c2
-rw-r--r--drivers/mtd/nand/Kconfig14
-rw-r--r--drivers/mtd/nand/Makefile1
-rw-r--r--drivers/mtd/nand/cafe.c89
-rw-r--r--drivers/mtd/nand/cafe_ecc.c2
-rw-r--r--drivers/mtd/nand/excite_nandflash.c248
-rw-r--r--drivers/mtd/nand/nand_base.c47
-rw-r--r--drivers/mtd/nand/s3c2410.c96
-rw-r--r--drivers/mtd/onenand/onenand_base.c596
-rw-r--r--drivers/mtd/onenand/onenand_bbt.c27
-rw-r--r--drivers/mtd/redboot.c19
-rw-r--r--drivers/net/Kconfig14
-rw-r--r--drivers/net/arcnet/arc-rawmode.c4
-rw-r--r--drivers/net/arcnet/arcnet.c2
-rw-r--r--drivers/net/arcnet/com20020-pci.c3
-rw-r--r--drivers/net/arcnet/com20020.c2
-rw-r--r--drivers/net/atl1/atl1_hw.c37
-rw-r--r--drivers/net/atl1/atl1_main.c5
-rw-r--r--drivers/net/b44.c19
-rw-r--r--drivers/net/cxgb3/cxgb3_defs.h1
-rw-r--r--drivers/net/cxgb3/cxgb3_offload.c1
-rw-r--r--drivers/net/cxgb3/cxgb3_offload.h1
-rw-r--r--drivers/net/cxgb3/l2t.c1
-rw-r--r--drivers/net/cxgb3/l2t.h1
-rw-r--r--drivers/net/cxgb3/t3cdev.h1
-rw-r--r--drivers/net/e1000/e1000.h1
-rw-r--r--drivers/net/e1000/e1000_ethtool.c2
-rw-r--r--drivers/net/e1000/e1000_hw.h2
-rw-r--r--drivers/net/e1000/e1000_main.c70
-rw-r--r--drivers/net/eexpress.c7
-rw-r--r--drivers/net/ehea/ehea.h2
-rw-r--r--drivers/net/ehea/ehea_main.c8
-rw-r--r--drivers/net/ehea/ehea_phyp.c10
-rw-r--r--drivers/net/ehea/ehea_phyp.h3
-rw-r--r--drivers/net/ehea/ehea_qmr.c42
-rw-r--r--drivers/net/ehea/ehea_qmr.h5
-rw-r--r--drivers/net/gianfar.c85
-rw-r--r--drivers/net/gianfar_sysfs.c108
-rw-r--r--drivers/net/hamradio/Kconfig3
-rw-r--r--drivers/net/ioc3-eth.c16
-rw-r--r--drivers/net/macb.c24
-rw-r--r--drivers/net/meth.c26
-rw-r--r--drivers/net/netxen/netxen_nic.h9
-rw-r--r--drivers/net/netxen/netxen_nic_ethtool.c9
-rw-r--r--drivers/net/netxen/netxen_nic_hw.c2
-rw-r--r--drivers/net/netxen/netxen_nic_init.c12
-rw-r--r--drivers/net/netxen/netxen_nic_main.c3
-rw-r--r--drivers/net/netxen/netxen_nic_niu.c2
-rw-r--r--drivers/net/pcmcia/3c574_cs.c2
-rw-r--r--drivers/net/pcmcia/smc91c92_cs.c2
-rw-r--r--drivers/net/phy/marvell.c156
-rw-r--r--drivers/net/phy/phy_device.c4
-rw-r--r--drivers/net/sk98lin/skge.c3
-rw-r--r--drivers/net/sky2.c125
-rw-r--r--drivers/net/sky2.h3
-rw-r--r--drivers/net/wan/Kconfig2
-rw-r--r--drivers/net/wan/pc300too.c2
-rw-r--r--drivers/net/wireless/bcm43xx/bcm43xx.h1
-rw-r--r--drivers/net/wireless/bcm43xx/bcm43xx_dma.c171
-rw-r--r--drivers/net/wireless/bcm43xx/bcm43xx_main.c25
-rw-r--r--drivers/net/wireless/bcm43xx/bcm43xx_wx.c28
-rw-r--r--drivers/net/wireless/ipw2100.c16
-rw-r--r--drivers/net/wireless/wavelan_cs.c8
-rw-r--r--drivers/net/wireless/zd1211rw/zd_mac.c44
-rw-r--r--drivers/net/wireless/zd1211rw/zd_usb.c12
-rw-r--r--drivers/pci/pci-driver.c1
-rw-r--r--drivers/pci/pci-sysfs.c11
-rw-r--r--drivers/pci/pci.c12
-rw-r--r--drivers/pci/pcie/aer/aerdrv.h2
-rw-r--r--drivers/pci/setup-bus.c27
-rw-r--r--drivers/pci/setup-irq.c18
-rw-r--r--drivers/pcmcia/at91_cf.c2
-rw-r--r--drivers/pcmcia/cardbus.c2
-rw-r--r--drivers/pcmcia/soc_common.c8
-rw-r--r--drivers/pnp/pnpacpi/Kconfig16
-rw-r--r--drivers/ps3/Makefile1
-rw-r--r--drivers/ps3/sys-manager.c604
-rw-r--r--drivers/ps3/vuart.c398
-rw-r--r--drivers/ps3/vuart.h59
-rw-r--r--drivers/sbus/char/vfc_i2c.c2
-rw-r--r--drivers/scsi/Kconfig5
-rw-r--r--drivers/scsi/a100u2w.c2
-rw-r--r--drivers/scsi/aic7xxx/aic79xx_osm.c1
-rw-r--r--drivers/scsi/aic94xx/aic94xx_seq.c13
-rw-r--r--drivers/scsi/aic94xx/aic94xx_seq.h1
-rw-r--r--drivers/scsi/arm/eesox.c2
-rw-r--r--drivers/scsi/ide-scsi.c8
-rw-r--r--drivers/scsi/lpfc/lpfc_init.c97
-rw-r--r--drivers/scsi/lpfc/lpfc_sli.c12
-rw-r--r--drivers/scsi/megaraid.c2
-rw-r--r--drivers/scsi/megaraid/megaraid_sas.c90
-rw-r--r--drivers/scsi/megaraid/megaraid_sas.h6
-rw-r--r--drivers/scsi/osst.c12
-rw-r--r--drivers/scsi/scsi_proc.c5
-rw-r--r--drivers/scsi/scsi_scan.c16
-rw-r--r--drivers/scsi/scsi_sysfs.c2
-rw-r--r--drivers/scsi/scsi_tgt_if.c8
-rw-r--r--drivers/scsi/scsi_transport_fc.c2
-rw-r--r--drivers/scsi/scsi_transport_sas.c4
-rw-r--r--drivers/scsi/sd.c11
-rw-r--r--drivers/scsi/sgiwd93.c5
-rw-r--r--drivers/scsi/st.c38
-rw-r--r--drivers/scsi/sym53c8xx_2/sym_fw1.h4
-rw-r--r--drivers/scsi/sym53c8xx_2/sym_fw2.h4
-rw-r--r--drivers/scsi/wd33c93.c321
-rw-r--r--drivers/scsi/wd33c93.h6
-rw-r--r--drivers/serial/Kconfig3
-rw-r--r--drivers/serial/atmel_serial.c3
-rw-r--r--drivers/serial/cpm_uart/cpm_uart_cpm2.c2
-rw-r--r--drivers/serial/imx.c14
-rw-r--r--drivers/serial/mpc52xx_uart.c4
-rw-r--r--drivers/serial/serial_cs.c5
-rw-r--r--drivers/usb/Makefile1
-rw-r--r--drivers/usb/atm/ueagle-atm.c1
-rw-r--r--drivers/usb/class/cdc-acm.c33
-rw-r--r--drivers/usb/core/devices.c9
-rw-r--r--drivers/usb/core/devio.c4
-rw-r--r--drivers/usb/core/driver.c1
-rw-r--r--drivers/usb/core/endpoint.c2
-rw-r--r--drivers/usb/core/generic.c2
-rw-r--r--drivers/usb/core/hub.c31
-rw-r--r--drivers/usb/core/message.c22
-rw-r--r--drivers/usb/core/otg_whitelist.h2
-rw-r--r--drivers/usb/core/sysfs.c2
-rw-r--r--drivers/usb/gadget/at91_udc.c19
-rw-r--r--drivers/usb/gadget/pxa2xx_udc.c16
-rw-r--r--drivers/usb/gadget/pxa2xx_udc.h15
-rw-r--r--drivers/usb/gadget/serial.c1
-rw-r--r--drivers/usb/host/ehci-dbg.c2
-rw-r--r--drivers/usb/host/ehci-hcd.c36
-rw-r--r--drivers/usb/host/ehci-hub.c2
-rw-r--r--drivers/usb/host/isp116x-hcd.c2
-rw-r--r--drivers/usb/host/ohci-at91.c50
-rw-r--r--drivers/usb/host/ohci-hcd.c18
-rw-r--r--drivers/usb/input/Kconfig6
-rw-r--r--drivers/usb/input/hid-core.c8
-rw-r--r--drivers/usb/input/hid-ff.c3
-rw-r--r--drivers/usb/input/hid-lgff.c12
-rw-r--r--drivers/usb/misc/Kconfig11
-rw-r--r--drivers/usb/misc/Makefile1
-rw-r--r--drivers/usb/misc/appledisplay.c4
-rw-r--r--drivers/usb/misc/berry_charge.c140
-rw-r--r--drivers/usb/net/Kconfig11
-rw-r--r--drivers/usb/net/asix.c2
-rw-r--r--drivers/usb/net/cdc_subset.c21
-rw-r--r--drivers/usb/net/usbnet.c29
-rw-r--r--drivers/usb/serial/airprime.c35
-rw-r--r--drivers/usb/serial/cp2101.c1
-rw-r--r--drivers/usb/serial/generic.c102
-rw-r--r--drivers/usb/serial/option.c4
-rw-r--r--drivers/usb/serial/pl2303.c1
-rw-r--r--drivers/usb/serial/pl2303.h5
-rw-r--r--drivers/usb/storage/scsiglue.c6
-rw-r--r--drivers/usb/storage/unusual_devs.h26
-rw-r--r--drivers/usb/usb-skeleton.c10
395 files changed, 9837 insertions, 4447 deletions
diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig
index 20eacc2c9e0e..e942ffe8b57e 100644
--- a/drivers/acpi/Kconfig
+++ b/drivers/acpi/Kconfig
@@ -13,6 +13,7 @@ config ACPI
13 depends on IA64 || X86 13 depends on IA64 || X86
14 depends on PCI 14 depends on PCI
15 depends on PM 15 depends on PM
16 select PNP
16 default y 17 default y
17 ---help--- 18 ---help---
18 Advanced Configuration and Power Interface (ACPI) support for 19 Advanced Configuration and Power Interface (ACPI) support for
@@ -132,15 +133,6 @@ config ACPI_VIDEO
132 Note that this is an ref. implementation only. It may or may not work 133 Note that this is an ref. implementation only. It may or may not work
133 for your integrated video device. 134 for your integrated video device.
134 135
135config ACPI_HOTKEY
136 tristate "Generic Hotkey (EXPERIMENTAL)"
137 depends on EXPERIMENTAL
138 depends on X86
139 default n
140 help
141 Experimental consolidated hotkey driver.
142 If you are unsure, say N.
143
144config ACPI_FAN 136config ACPI_FAN
145 tristate "Fan" 137 tristate "Fan"
146 default y 138 default y
diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
index 856c32bccacb..5956e9f64a8b 100644
--- a/drivers/acpi/Makefile
+++ b/drivers/acpi/Makefile
@@ -46,7 +46,6 @@ obj-$(CONFIG_ACPI_FAN) += fan.o
46obj-$(CONFIG_ACPI_DOCK) += dock.o 46obj-$(CONFIG_ACPI_DOCK) += dock.o
47obj-$(CONFIG_ACPI_BAY) += bay.o 47obj-$(CONFIG_ACPI_BAY) += bay.o
48obj-$(CONFIG_ACPI_VIDEO) += video.o 48obj-$(CONFIG_ACPI_VIDEO) += video.o
49obj-$(CONFIG_ACPI_HOTKEY) += hotkey.o
50obj-y += pci_root.o pci_link.o pci_irq.o pci_bind.o 49obj-y += pci_root.o pci_link.o pci_irq.o pci_bind.o
51obj-$(CONFIG_ACPI_POWER) += power.o 50obj-$(CONFIG_ACPI_POWER) += power.o
52obj-$(CONFIG_ACPI_PROCESSOR) += processor.o 51obj-$(CONFIG_ACPI_PROCESSOR) += processor.o
diff --git a/drivers/acpi/ac.c b/drivers/acpi/ac.c
index 6daeace796a8..37c7dc4f9fe5 100644
--- a/drivers/acpi/ac.c
+++ b/drivers/acpi/ac.c
@@ -35,7 +35,6 @@
35#define ACPI_AC_COMPONENT 0x00020000 35#define ACPI_AC_COMPONENT 0x00020000
36#define ACPI_AC_CLASS "ac_adapter" 36#define ACPI_AC_CLASS "ac_adapter"
37#define ACPI_AC_HID "ACPI0003" 37#define ACPI_AC_HID "ACPI0003"
38#define ACPI_AC_DRIVER_NAME "ACPI AC Adapter Driver"
39#define ACPI_AC_DEVICE_NAME "AC Adapter" 38#define ACPI_AC_DEVICE_NAME "AC Adapter"
40#define ACPI_AC_FILE_STATE "state" 39#define ACPI_AC_FILE_STATE "state"
41#define ACPI_AC_NOTIFY_STATUS 0x80 40#define ACPI_AC_NOTIFY_STATUS 0x80
@@ -44,10 +43,10 @@
44#define ACPI_AC_STATUS_UNKNOWN 0xFF 43#define ACPI_AC_STATUS_UNKNOWN 0xFF
45 44
46#define _COMPONENT ACPI_AC_COMPONENT 45#define _COMPONENT ACPI_AC_COMPONENT
47ACPI_MODULE_NAME("acpi_ac") 46ACPI_MODULE_NAME("ac");
48 47
49 MODULE_AUTHOR("Paul Diefenbaugh"); 48MODULE_AUTHOR("Paul Diefenbaugh");
50MODULE_DESCRIPTION(ACPI_AC_DRIVER_NAME); 49MODULE_DESCRIPTION("ACPI AC Adapter Driver");
51MODULE_LICENSE("GPL"); 50MODULE_LICENSE("GPL");
52 51
53extern struct proc_dir_entry *acpi_lock_ac_dir(void); 52extern struct proc_dir_entry *acpi_lock_ac_dir(void);
@@ -58,7 +57,7 @@ static int acpi_ac_remove(struct acpi_device *device, int type);
58static int acpi_ac_open_fs(struct inode *inode, struct file *file); 57static int acpi_ac_open_fs(struct inode *inode, struct file *file);
59 58
60static struct acpi_driver acpi_ac_driver = { 59static struct acpi_driver acpi_ac_driver = {
61 .name = ACPI_AC_DRIVER_NAME, 60 .name = "ac",
62 .class = ACPI_AC_CLASS, 61 .class = ACPI_AC_CLASS,
63 .ids = ACPI_AC_HID, 62 .ids = ACPI_AC_HID,
64 .ops = { 63 .ops = {
diff --git a/drivers/acpi/acpi_memhotplug.c b/drivers/acpi/acpi_memhotplug.c
index cd946ed192d3..c26172671fd8 100644
--- a/drivers/acpi/acpi_memhotplug.c
+++ b/drivers/acpi/acpi_memhotplug.c
@@ -35,14 +35,13 @@
35#define ACPI_MEMORY_DEVICE_COMPONENT 0x08000000UL 35#define ACPI_MEMORY_DEVICE_COMPONENT 0x08000000UL
36#define ACPI_MEMORY_DEVICE_CLASS "memory" 36#define ACPI_MEMORY_DEVICE_CLASS "memory"
37#define ACPI_MEMORY_DEVICE_HID "PNP0C80" 37#define ACPI_MEMORY_DEVICE_HID "PNP0C80"
38#define ACPI_MEMORY_DEVICE_DRIVER_NAME "Hotplug Mem Driver"
39#define ACPI_MEMORY_DEVICE_NAME "Hotplug Mem Device" 38#define ACPI_MEMORY_DEVICE_NAME "Hotplug Mem Device"
40 39
41#define _COMPONENT ACPI_MEMORY_DEVICE_COMPONENT 40#define _COMPONENT ACPI_MEMORY_DEVICE_COMPONENT
42 41
43ACPI_MODULE_NAME("acpi_memory") 42ACPI_MODULE_NAME("acpi_memhotplug");
44 MODULE_AUTHOR("Naveen B S <naveen.b.s@intel.com>"); 43MODULE_AUTHOR("Naveen B S <naveen.b.s@intel.com>");
45MODULE_DESCRIPTION(ACPI_MEMORY_DEVICE_DRIVER_NAME); 44MODULE_DESCRIPTION("Hotplug Mem Driver");
46MODULE_LICENSE("GPL"); 45MODULE_LICENSE("GPL");
47 46
48/* ACPI _STA method values */ 47/* ACPI _STA method values */
@@ -60,7 +59,7 @@ static int acpi_memory_device_remove(struct acpi_device *device, int type);
60static int acpi_memory_device_start(struct acpi_device *device); 59static int acpi_memory_device_start(struct acpi_device *device);
61 60
62static struct acpi_driver acpi_memory_device_driver = { 61static struct acpi_driver acpi_memory_device_driver = {
63 .name = ACPI_MEMORY_DEVICE_DRIVER_NAME, 62 .name = "acpi_memhotplug",
64 .class = ACPI_MEMORY_DEVICE_CLASS, 63 .class = ACPI_MEMORY_DEVICE_CLASS,
65 .ids = ACPI_MEMORY_DEVICE_HID, 64 .ids = ACPI_MEMORY_DEVICE_HID,
66 .ops = { 65 .ops = {
diff --git a/drivers/acpi/asus_acpi.c b/drivers/acpi/asus_acpi.c
index 31ad70a6e22e..772299fb5f9d 100644
--- a/drivers/acpi/asus_acpi.c
+++ b/drivers/acpi/asus_acpi.c
@@ -141,6 +141,7 @@ struct asus_hotk {
141 W5A, //W5A 141 W5A, //W5A
142 W3V, //W3030V 142 W3V, //W3030V
143 xxN, //M2400N, M3700N, M5200N, M6800N, S1300N, S5200N 143 xxN, //M2400N, M3700N, M5200N, M6800N, S1300N, S5200N
144 A4S, //Z81sp
144 //(Centrino) 145 //(Centrino)
145 END_MODEL 146 END_MODEL
146 } model; //Models currently supported 147 } model; //Models currently supported
@@ -397,7 +398,16 @@ static struct model_data model_conf[END_MODEL] = {
397 .brightness_set = "SPLV", 398 .brightness_set = "SPLV",
398 .brightness_get = "GPLV", 399 .brightness_get = "GPLV",
399 .display_set = "SDSP", 400 .display_set = "SDSP",
400 .display_get = "\\ADVG"} 401 .display_get = "\\ADVG"},
402
403 {
404 .name = "A4S",
405 .brightness_set = "SPLV",
406 .brightness_get = "GPLV",
407 .mt_bt_switch = "BLED",
408 .mt_wled = "WLED"
409 }
410
401}; 411};
402 412
403/* procdir we use */ 413/* procdir we use */
@@ -421,7 +431,7 @@ static struct asus_hotk *hotk;
421static int asus_hotk_add(struct acpi_device *device); 431static int asus_hotk_add(struct acpi_device *device);
422static int asus_hotk_remove(struct acpi_device *device, int type); 432static int asus_hotk_remove(struct acpi_device *device, int type);
423static struct acpi_driver asus_hotk_driver = { 433static struct acpi_driver asus_hotk_driver = {
424 .name = ACPI_HOTK_NAME, 434 .name = "asus_acpi",
425 .class = ACPI_HOTK_CLASS, 435 .class = ACPI_HOTK_CLASS,
426 .ids = ACPI_HOTK_HID, 436 .ids = ACPI_HOTK_HID,
427 .ops = { 437 .ops = {
@@ -1117,6 +1127,8 @@ static int asus_model_match(char *model)
1117 return W3V; 1127 return W3V;
1118 else if (strncmp(model, "W5A", 3) == 0) 1128 else if (strncmp(model, "W5A", 3) == 0)
1119 return W5A; 1129 return W5A;
1130 else if (strncmp(model, "A4S", 3) == 0)
1131 return A4S;
1120 else 1132 else
1121 return END_MODEL; 1133 return END_MODEL;
1122} 1134}
@@ -1365,10 +1377,6 @@ static int __init asus_acpi_init(void)
1365 if (acpi_disabled) 1377 if (acpi_disabled)
1366 return -ENODEV; 1378 return -ENODEV;
1367 1379
1368 if (!acpi_specific_hotkey_enabled) {
1369 printk(KERN_ERR "Using generic hotkey driver\n");
1370 return -ENODEV;
1371 }
1372 asus_proc_dir = proc_mkdir(PROC_ASUS, acpi_root_dir); 1380 asus_proc_dir = proc_mkdir(PROC_ASUS, acpi_root_dir);
1373 if (!asus_proc_dir) { 1381 if (!asus_proc_dir) {
1374 printk(KERN_ERR "Asus ACPI: Unable to create /proc entry\n"); 1382 printk(KERN_ERR "Asus ACPI: Unable to create /proc entry\n");
diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
index 2f4521a48fe7..e64c76c8b726 100644
--- a/drivers/acpi/battery.c
+++ b/drivers/acpi/battery.c
@@ -42,7 +42,6 @@
42#define ACPI_BATTERY_COMPONENT 0x00040000 42#define ACPI_BATTERY_COMPONENT 0x00040000
43#define ACPI_BATTERY_CLASS "battery" 43#define ACPI_BATTERY_CLASS "battery"
44#define ACPI_BATTERY_HID "PNP0C0A" 44#define ACPI_BATTERY_HID "PNP0C0A"
45#define ACPI_BATTERY_DRIVER_NAME "ACPI Battery Driver"
46#define ACPI_BATTERY_DEVICE_NAME "Battery" 45#define ACPI_BATTERY_DEVICE_NAME "Battery"
47#define ACPI_BATTERY_FILE_INFO "info" 46#define ACPI_BATTERY_FILE_INFO "info"
48#define ACPI_BATTERY_FILE_STATUS "state" 47#define ACPI_BATTERY_FILE_STATUS "state"
@@ -53,10 +52,10 @@
53#define ACPI_BATTERY_UNITS_AMPS "mA" 52#define ACPI_BATTERY_UNITS_AMPS "mA"
54 53
55#define _COMPONENT ACPI_BATTERY_COMPONENT 54#define _COMPONENT ACPI_BATTERY_COMPONENT
56ACPI_MODULE_NAME("acpi_battery") 55ACPI_MODULE_NAME("battery");
57 56
58 MODULE_AUTHOR("Paul Diefenbaugh"); 57MODULE_AUTHOR("Paul Diefenbaugh");
59MODULE_DESCRIPTION(ACPI_BATTERY_DRIVER_NAME); 58MODULE_DESCRIPTION("ACPI Battery Driver");
60MODULE_LICENSE("GPL"); 59MODULE_LICENSE("GPL");
61 60
62extern struct proc_dir_entry *acpi_lock_battery_dir(void); 61extern struct proc_dir_entry *acpi_lock_battery_dir(void);
@@ -67,7 +66,7 @@ static int acpi_battery_remove(struct acpi_device *device, int type);
67static int acpi_battery_resume(struct acpi_device *device); 66static int acpi_battery_resume(struct acpi_device *device);
68 67
69static struct acpi_driver acpi_battery_driver = { 68static struct acpi_driver acpi_battery_driver = {
70 .name = ACPI_BATTERY_DRIVER_NAME, 69 .name = "battery",
71 .class = ACPI_BATTERY_CLASS, 70 .class = ACPI_BATTERY_CLASS,
72 .ids = ACPI_BATTERY_HID, 71 .ids = ACPI_BATTERY_HID,
73 .ops = { 72 .ops = {
@@ -324,6 +323,13 @@ static int acpi_battery_check(struct acpi_battery *battery)
324 return result; 323 return result;
325} 324}
326 325
326static void acpi_battery_check_present(struct acpi_battery *battery)
327{
328 if (!battery->flags.present) {
329 acpi_battery_check(battery);
330 }
331}
332
327/* -------------------------------------------------------------------------- 333/* --------------------------------------------------------------------------
328 FS Interface (/proc) 334 FS Interface (/proc)
329 -------------------------------------------------------------------------- */ 335 -------------------------------------------------------------------------- */
@@ -340,6 +346,8 @@ static int acpi_battery_read_info(struct seq_file *seq, void *offset)
340 if (!battery) 346 if (!battery)
341 goto end; 347 goto end;
342 348
349 acpi_battery_check_present(battery);
350
343 if (battery->flags.present) 351 if (battery->flags.present)
344 seq_printf(seq, "present: yes\n"); 352 seq_printf(seq, "present: yes\n");
345 else { 353 else {
@@ -424,6 +432,8 @@ static int acpi_battery_read_state(struct seq_file *seq, void *offset)
424 if (!battery) 432 if (!battery)
425 goto end; 433 goto end;
426 434
435 acpi_battery_check_present(battery);
436
427 if (battery->flags.present) 437 if (battery->flags.present)
428 seq_printf(seq, "present: yes\n"); 438 seq_printf(seq, "present: yes\n");
429 else { 439 else {
@@ -499,6 +509,8 @@ static int acpi_battery_read_alarm(struct seq_file *seq, void *offset)
499 if (!battery) 509 if (!battery)
500 goto end; 510 goto end;
501 511
512 acpi_battery_check_present(battery);
513
502 if (!battery->flags.present) { 514 if (!battery->flags.present) {
503 seq_printf(seq, "present: no\n"); 515 seq_printf(seq, "present: no\n");
504 goto end; 516 goto end;
@@ -536,6 +548,8 @@ acpi_battery_write_alarm(struct file *file,
536 if (!battery || (count > sizeof(alarm_string) - 1)) 548 if (!battery || (count > sizeof(alarm_string) - 1))
537 return -EINVAL; 549 return -EINVAL;
538 550
551 acpi_battery_check_present(battery);
552
539 if (!battery->flags.present) 553 if (!battery->flags.present)
540 return -ENODEV; 554 return -ENODEV;
541 555
diff --git a/drivers/acpi/bay.c b/drivers/acpi/bay.c
index 91082ce6f5d1..fb3f31b5e69f 100644
--- a/drivers/acpi/bay.c
+++ b/drivers/acpi/bay.c
@@ -32,11 +32,9 @@
32#include <asm/uaccess.h> 32#include <asm/uaccess.h>
33#include <linux/platform_device.h> 33#include <linux/platform_device.h>
34 34
35#define ACPI_BAY_DRIVER_NAME "ACPI Removable Drive Bay Driver" 35ACPI_MODULE_NAME("bay");
36
37ACPI_MODULE_NAME("bay")
38MODULE_AUTHOR("Kristen Carlson Accardi"); 36MODULE_AUTHOR("Kristen Carlson Accardi");
39MODULE_DESCRIPTION(ACPI_BAY_DRIVER_NAME); 37MODULE_DESCRIPTION("ACPI Removable Drive Bay Driver");
40MODULE_LICENSE("GPL"); 38MODULE_LICENSE("GPL");
41#define ACPI_BAY_CLASS "bay" 39#define ACPI_BAY_CLASS "bay"
42#define ACPI_BAY_COMPONENT 0x10000000 40#define ACPI_BAY_COMPONENT 0x10000000
@@ -47,18 +45,6 @@ MODULE_LICENSE("GPL");
47 acpi_get_name(h, ACPI_FULL_PATHNAME, &buffer);\ 45 acpi_get_name(h, ACPI_FULL_PATHNAME, &buffer);\
48 printk(KERN_DEBUG PREFIX "%s: %s\n", prefix, s); } 46 printk(KERN_DEBUG PREFIX "%s: %s\n", prefix, s); }
49static void bay_notify(acpi_handle handle, u32 event, void *data); 47static void bay_notify(acpi_handle handle, u32 event, void *data);
50static int acpi_bay_add(struct acpi_device *device);
51static int acpi_bay_remove(struct acpi_device *device, int type);
52
53static struct acpi_driver acpi_bay_driver = {
54 .name = ACPI_BAY_DRIVER_NAME,
55 .class = ACPI_BAY_CLASS,
56 .ids = ACPI_BAY_HID,
57 .ops = {
58 .add = acpi_bay_add,
59 .remove = acpi_bay_remove,
60 },
61};
62 48
63struct bay { 49struct bay {
64 acpi_handle handle; 50 acpi_handle handle;
@@ -234,14 +220,6 @@ int eject_removable_drive(struct device *dev)
234} 220}
235EXPORT_SYMBOL_GPL(eject_removable_drive); 221EXPORT_SYMBOL_GPL(eject_removable_drive);
236 222
237static int acpi_bay_add(struct acpi_device *device)
238{
239 bay_dprintk(device->handle, "adding bay device");
240 strcpy(acpi_device_name(device), "Dockable Bay");
241 strcpy(acpi_device_class(device), "bay");
242 return 0;
243}
244
245static int acpi_bay_add_fs(struct bay *bay) 223static int acpi_bay_add_fs(struct bay *bay)
246{ 224{
247 int ret; 225 int ret;
@@ -303,7 +281,7 @@ static int bay_add(acpi_handle handle, int id)
303 281
304 /* initialize platform device stuff */ 282 /* initialize platform device stuff */
305 pdev = platform_device_register_simple(ACPI_BAY_CLASS, id, NULL, 0); 283 pdev = platform_device_register_simple(ACPI_BAY_CLASS, id, NULL, 0);
306 if (pdev == NULL) { 284 if (IS_ERR(pdev)) {
307 printk(KERN_ERR PREFIX "Error registering bay device\n"); 285 printk(KERN_ERR PREFIX "Error registering bay device\n");
308 goto bay_add_err; 286 goto bay_add_err;
309 } 287 }
@@ -339,52 +317,6 @@ bay_add_err:
339 return -ENODEV; 317 return -ENODEV;
340} 318}
341 319
342static int acpi_bay_remove(struct acpi_device *device, int type)
343{
344 /*** FIXME: do something here */
345 return 0;
346}
347
348/**
349 * bay_create_acpi_device - add new devices to acpi
350 * @handle - handle of the device to add
351 *
352 * This function will create a new acpi_device for the given
353 * handle if one does not exist already. This should cause
354 * acpi to scan for drivers for the given devices, and call
355 * matching driver's add routine.
356 *
357 * Returns a pointer to the acpi_device corresponding to the handle.
358 */
359static struct acpi_device * bay_create_acpi_device(acpi_handle handle)
360{
361 struct acpi_device *device = NULL;
362 struct acpi_device *parent_device;
363 acpi_handle parent;
364 int ret;
365
366 bay_dprintk(handle, "Trying to get device");
367 if (acpi_bus_get_device(handle, &device)) {
368 /*
369 * no device created for this object,
370 * so we should create one.
371 */
372 bay_dprintk(handle, "No device for handle");
373 acpi_get_parent(handle, &parent);
374 if (acpi_bus_get_device(parent, &parent_device))
375 parent_device = NULL;
376
377 ret = acpi_bus_add(&device, parent_device, handle,
378 ACPI_BUS_TYPE_DEVICE);
379 if (ret) {
380 pr_debug("error adding bus, %x\n",
381 -ret);
382 return NULL;
383 }
384 }
385 return device;
386}
387
388/** 320/**
389 * bay_notify - act upon an acpi bay notification 321 * bay_notify - act upon an acpi bay notification
390 * @handle: the bay handle 322 * @handle: the bay handle
@@ -394,38 +326,19 @@ static struct acpi_device * bay_create_acpi_device(acpi_handle handle)
394 */ 326 */
395static void bay_notify(acpi_handle handle, u32 event, void *data) 327static void bay_notify(acpi_handle handle, u32 event, void *data)
396{ 328{
397 struct acpi_device *dev; 329 struct bay *bay_dev = (struct bay *)data;
330 struct device *dev = &bay_dev->pdev->dev;
398 331
399 bay_dprintk(handle, "Bay event"); 332 bay_dprintk(handle, "Bay event");
400 333
401 switch(event) { 334 switch(event) {
402 case ACPI_NOTIFY_BUS_CHECK: 335 case ACPI_NOTIFY_BUS_CHECK:
403 printk("Bus Check\n");
404 case ACPI_NOTIFY_DEVICE_CHECK: 336 case ACPI_NOTIFY_DEVICE_CHECK:
405 printk("Device Check\n");
406 dev = bay_create_acpi_device(handle);
407 if (dev)
408 acpi_bus_generate_event(dev, event, 0);
409 else
410 printk("No device for generating event\n");
411 /* wouldn't it be a good idea to just rescan SATA
412 * right here?
413 */
414 break;
415 case ACPI_NOTIFY_EJECT_REQUEST: 337 case ACPI_NOTIFY_EJECT_REQUEST:
416 printk("Eject request\n"); 338 kobject_uevent(&dev->kobj, KOBJ_CHANGE);
417 dev = bay_create_acpi_device(handle);
418 if (dev)
419 acpi_bus_generate_event(dev, event, 0);
420 else
421 printk("No device for generating eventn");
422
423 /* wouldn't it be a good idea to just call the
424 * eject_device here if we were a SATA device?
425 */
426 break; 339 break;
427 default: 340 default:
428 printk("unknown event %d\n", event); 341 printk(KERN_ERR PREFIX "Bay: unknown event %d\n", event);
429 } 342 }
430} 343}
431 344
@@ -457,10 +370,6 @@ static int __init bay_init(void)
457 acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, 370 acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
458 ACPI_UINT32_MAX, find_bay, &bays, NULL); 371 ACPI_UINT32_MAX, find_bay, &bays, NULL);
459 372
460 if (bays)
461 if ((acpi_bus_register_driver(&acpi_bay_driver) < 0))
462 printk(KERN_ERR "Unable to register bay driver\n");
463
464 if (!bays) 373 if (!bays)
465 return -ENODEV; 374 return -ENODEV;
466 375
@@ -481,8 +390,6 @@ static void __exit bay_exit(void)
481 kfree(bay->name); 390 kfree(bay->name);
482 kfree(bay); 391 kfree(bay);
483 } 392 }
484
485 acpi_bus_unregister_driver(&acpi_bay_driver);
486} 393}
487 394
488postcore_initcall(bay_init); 395postcore_initcall(bay_init);
diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c
index c26468da4295..dd49ea0d0ed3 100644
--- a/drivers/acpi/bus.c
+++ b/drivers/acpi/bus.c
@@ -39,7 +39,7 @@
39#include <acpi/acpi_drivers.h> 39#include <acpi/acpi_drivers.h>
40 40
41#define _COMPONENT ACPI_BUS_COMPONENT 41#define _COMPONENT ACPI_BUS_COMPONENT
42ACPI_MODULE_NAME("acpi_bus") 42ACPI_MODULE_NAME("bus");
43#ifdef CONFIG_X86 43#ifdef CONFIG_X86
44extern void __init acpi_pic_sci_set_trigger(unsigned int irq, u16 trigger); 44extern void __init acpi_pic_sci_set_trigger(unsigned int irq, u16 trigger);
45#endif 45#endif
@@ -147,7 +147,7 @@ int acpi_bus_get_power(acpi_handle handle, int *state)
147 *state = ACPI_STATE_D0; 147 *state = ACPI_STATE_D0;
148 } else { 148 } else {
149 /* 149 /*
150 * Get the device's power state either directly (via _PSC) or 150 * Get the device's power state either directly (via _PSC) or
151 * indirectly (via power resources). 151 * indirectly (via power resources).
152 */ 152 */
153 if (device->power.flags.explicit_get) { 153 if (device->power.flags.explicit_get) {
@@ -199,15 +199,14 @@ int acpi_bus_set_power(acpi_handle handle, int state)
199 * Get device's current power state if it's unknown 199 * Get device's current power state if it's unknown
200 * This means device power state isn't initialized or previous setting failed 200 * This means device power state isn't initialized or previous setting failed
201 */ 201 */
202 if (!device->flags.force_power_state) { 202 if ((device->power.state == ACPI_STATE_UNKNOWN) || device->flags.force_power_state)
203 if (device->power.state == ACPI_STATE_UNKNOWN) 203 acpi_bus_get_power(device->handle, &device->power.state);
204 acpi_bus_get_power(device->handle, &device->power.state); 204 if ((state == device->power.state) && !device->flags.force_power_state) {
205 if (state == device->power.state) { 205 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device is already at D%d\n",
206 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device is already at D%d\n", 206 state));
207 state)); 207 return 0;
208 return 0;
209 }
210 } 208 }
209
211 if (!device->power.states[state].flags.valid) { 210 if (!device->power.states[state].flags.valid) {
212 printk(KERN_WARNING PREFIX "Device does not support D%d\n", state); 211 printk(KERN_WARNING PREFIX "Device does not support D%d\n", state);
213 return -ENODEV; 212 return -ENODEV;
@@ -462,7 +461,7 @@ static void acpi_bus_notify(acpi_handle handle, u32 type, void *data)
462 "Received BUS CHECK notification for device [%s]\n", 461 "Received BUS CHECK notification for device [%s]\n",
463 device->pnp.bus_id)); 462 device->pnp.bus_id));
464 result = acpi_bus_check_scope(device); 463 result = acpi_bus_check_scope(device);
465 /* 464 /*
466 * TBD: We'll need to outsource certain events to non-ACPI 465 * TBD: We'll need to outsource certain events to non-ACPI
467 * drivers via the device manager (device.c). 466 * drivers via the device manager (device.c).
468 */ 467 */
@@ -473,7 +472,7 @@ static void acpi_bus_notify(acpi_handle handle, u32 type, void *data)
473 "Received DEVICE CHECK notification for device [%s]\n", 472 "Received DEVICE CHECK notification for device [%s]\n",
474 device->pnp.bus_id)); 473 device->pnp.bus_id));
475 result = acpi_bus_check_device(device, NULL); 474 result = acpi_bus_check_device(device, NULL);
476 /* 475 /*
477 * TBD: We'll need to outsource certain events to non-ACPI 476 * TBD: We'll need to outsource certain events to non-ACPI
478 * drivers via the device manager (device.c). 477 * drivers via the device manager (device.c).
479 */ 478 */
@@ -543,7 +542,7 @@ static int __init acpi_bus_init_irq(void)
543 char *message = NULL; 542 char *message = NULL;
544 543
545 544
546 /* 545 /*
547 * Let the system know what interrupt model we are using by 546 * Let the system know what interrupt model we are using by
548 * evaluating the \_PIC object, if exists. 547 * evaluating the \_PIC object, if exists.
549 */ 548 */
@@ -684,7 +683,7 @@ static int __init acpi_bus_init(void)
684 * the EC device is found in the namespace (i.e. before acpi_initialize_objects() 683 * the EC device is found in the namespace (i.e. before acpi_initialize_objects()
685 * is called). 684 * is called).
686 * 685 *
687 * This is accomplished by looking for the ECDT table, and getting 686 * This is accomplished by looking for the ECDT table, and getting
688 * the EC parameters out of that. 687 * the EC parameters out of that.
689 */ 688 */
690 status = acpi_ec_ecdt_probe(); 689 status = acpi_ec_ecdt_probe();
@@ -699,6 +698,9 @@ static int __init acpi_bus_init(void)
699 698
700 printk(KERN_INFO PREFIX "Interpreter enabled\n"); 699 printk(KERN_INFO PREFIX "Interpreter enabled\n");
701 700
701 /* Initialize sleep structures */
702 acpi_sleep_init();
703
702 /* 704 /*
703 * Get the system interrupt model and evaluate \_PIC. 705 * Get the system interrupt model and evaluate \_PIC.
704 */ 706 */
diff --git a/drivers/acpi/button.c b/drivers/acpi/button.c
index c726612fafb6..cb4110b50cd0 100644
--- a/drivers/acpi/button.c
+++ b/drivers/acpi/button.c
@@ -34,7 +34,6 @@
34#include <acpi/acpi_drivers.h> 34#include <acpi/acpi_drivers.h>
35 35
36#define ACPI_BUTTON_COMPONENT 0x00080000 36#define ACPI_BUTTON_COMPONENT 0x00080000
37#define ACPI_BUTTON_DRIVER_NAME "ACPI Button Driver"
38#define ACPI_BUTTON_CLASS "button" 37#define ACPI_BUTTON_CLASS "button"
39#define ACPI_BUTTON_FILE_INFO "info" 38#define ACPI_BUTTON_FILE_INFO "info"
40#define ACPI_BUTTON_FILE_STATE "state" 39#define ACPI_BUTTON_FILE_STATE "state"
@@ -61,10 +60,10 @@
61#define ACPI_BUTTON_TYPE_LID 0x05 60#define ACPI_BUTTON_TYPE_LID 0x05
62 61
63#define _COMPONENT ACPI_BUTTON_COMPONENT 62#define _COMPONENT ACPI_BUTTON_COMPONENT
64ACPI_MODULE_NAME("acpi_button") 63ACPI_MODULE_NAME("button");
65 64
66MODULE_AUTHOR("Paul Diefenbaugh"); 65MODULE_AUTHOR("Paul Diefenbaugh");
67MODULE_DESCRIPTION(ACPI_BUTTON_DRIVER_NAME); 66MODULE_DESCRIPTION("ACPI Button Driver");
68MODULE_LICENSE("GPL"); 67MODULE_LICENSE("GPL");
69 68
70static int acpi_button_add(struct acpi_device *device); 69static int acpi_button_add(struct acpi_device *device);
@@ -73,7 +72,7 @@ static int acpi_button_info_open_fs(struct inode *inode, struct file *file);
73static int acpi_button_state_open_fs(struct inode *inode, struct file *file); 72static int acpi_button_state_open_fs(struct inode *inode, struct file *file);
74 73
75static struct acpi_driver acpi_button_driver = { 74static struct acpi_driver acpi_button_driver = {
76 .name = ACPI_BUTTON_DRIVER_NAME, 75 .name = "button",
77 .class = ACPI_BUTTON_CLASS, 76 .class = ACPI_BUTTON_CLASS,
78 .ids = "button_power,button_sleep,PNP0C0D,PNP0C0C,PNP0C0E", 77 .ids = "button_power,button_sleep,PNP0C0D,PNP0C0C,PNP0C0E",
79 .ops = { 78 .ops = {
diff --git a/drivers/acpi/cm_sbs.c b/drivers/acpi/cm_sbs.c
index 4a9b7bf6f44e..f9db4f444bd0 100644
--- a/drivers/acpi/cm_sbs.c
+++ b/drivers/acpi/cm_sbs.c
@@ -31,7 +31,7 @@
31#include <acpi/actypes.h> 31#include <acpi/actypes.h>
32#include <acpi/acutils.h> 32#include <acpi/acutils.h>
33 33
34ACPI_MODULE_NAME("cm_sbs") 34ACPI_MODULE_NAME("cm_sbs");
35#define ACPI_AC_CLASS "ac_adapter" 35#define ACPI_AC_CLASS "ac_adapter"
36#define ACPI_BATTERY_CLASS "battery" 36#define ACPI_BATTERY_CLASS "battery"
37#define ACPI_SBS_COMPONENT 0x00080000 37#define ACPI_SBS_COMPONENT 0x00080000
diff --git a/drivers/acpi/container.c b/drivers/acpi/container.c
index 69a68fd394cf..0930d9413dfa 100644
--- a/drivers/acpi/container.c
+++ b/drivers/acpi/container.c
@@ -35,7 +35,6 @@
35#include <acpi/acpi_drivers.h> 35#include <acpi/acpi_drivers.h>
36#include <acpi/container.h> 36#include <acpi/container.h>
37 37
38#define ACPI_CONTAINER_DRIVER_NAME "ACPI container driver"
39#define ACPI_CONTAINER_DEVICE_NAME "ACPI container device" 38#define ACPI_CONTAINER_DEVICE_NAME "ACPI container device"
40#define ACPI_CONTAINER_CLASS "container" 39#define ACPI_CONTAINER_CLASS "container"
41 40
@@ -44,10 +43,10 @@
44 43
45#define ACPI_CONTAINER_COMPONENT 0x01000000 44#define ACPI_CONTAINER_COMPONENT 0x01000000
46#define _COMPONENT ACPI_CONTAINER_COMPONENT 45#define _COMPONENT ACPI_CONTAINER_COMPONENT
47ACPI_MODULE_NAME("acpi_container") 46ACPI_MODULE_NAME("container");
48 47
49 MODULE_AUTHOR("Anil S Keshavamurthy"); 48MODULE_AUTHOR("Anil S Keshavamurthy");
50MODULE_DESCRIPTION(ACPI_CONTAINER_DRIVER_NAME); 49MODULE_DESCRIPTION("ACPI container driver");
51MODULE_LICENSE("GPL"); 50MODULE_LICENSE("GPL");
52 51
53#define ACPI_STA_PRESENT (0x00000001) 52#define ACPI_STA_PRESENT (0x00000001)
@@ -56,7 +55,7 @@ static int acpi_container_add(struct acpi_device *device);
56static int acpi_container_remove(struct acpi_device *device, int type); 55static int acpi_container_remove(struct acpi_device *device, int type);
57 56
58static struct acpi_driver acpi_container_driver = { 57static struct acpi_driver acpi_container_driver = {
59 .name = ACPI_CONTAINER_DRIVER_NAME, 58 .name = "container",
60 .class = ACPI_CONTAINER_CLASS, 59 .class = ACPI_CONTAINER_CLASS,
61 .ids = "ACPI0004,PNP0A05,PNP0A06", 60 .ids = "ACPI0004,PNP0A05,PNP0A06",
62 .ops = { 61 .ops = {
diff --git a/drivers/acpi/debug.c b/drivers/acpi/debug.c
index d48f65a8f658..bf513e07b773 100644
--- a/drivers/acpi/debug.c
+++ b/drivers/acpi/debug.c
@@ -12,7 +12,7 @@
12#include <acpi/acglobal.h> 12#include <acpi/acglobal.h>
13 13
14#define _COMPONENT ACPI_SYSTEM_COMPONENT 14#define _COMPONENT ACPI_SYSTEM_COMPONENT
15ACPI_MODULE_NAME("debug") 15ACPI_MODULE_NAME("debug");
16 16
17#ifdef MODULE_PARAM_PREFIX 17#ifdef MODULE_PARAM_PREFIX
18#undef MODULE_PARAM_PREFIX 18#undef MODULE_PARAM_PREFIX
diff --git a/drivers/acpi/dispatcher/dsmethod.c b/drivers/acpi/dispatcher/dsmethod.c
index 1cbe61905824..1683e5c5b94c 100644
--- a/drivers/acpi/dispatcher/dsmethod.c
+++ b/drivers/acpi/dispatcher/dsmethod.c
@@ -231,10 +231,8 @@ acpi_ds_begin_method_execution(struct acpi_namespace_node *method_node,
231 * Obtain the method mutex if necessary. Do not acquire mutex for a 231 * Obtain the method mutex if necessary. Do not acquire mutex for a
232 * recursive call. 232 * recursive call.
233 */ 233 */
234 if (!walk_state || 234 if (acpi_os_get_thread_id() !=
235 !obj_desc->method.mutex->mutex.owner_thread || 235 obj_desc->method.mutex->mutex.owner_thread_id) {
236 (walk_state->thread !=
237 obj_desc->method.mutex->mutex.owner_thread)) {
238 /* 236 /*
239 * Acquire the method mutex. This releases the interpreter if we 237 * Acquire the method mutex. This releases the interpreter if we
240 * block (and reacquires it before it returns) 238 * block (and reacquires it before it returns)
@@ -248,14 +246,14 @@ acpi_ds_begin_method_execution(struct acpi_namespace_node *method_node,
248 } 246 }
249 247
250 /* Update the mutex and walk info and save the original sync_level */ 248 /* Update the mutex and walk info and save the original sync_level */
249 obj_desc->method.mutex->mutex.owner_thread_id =
250 acpi_os_get_thread_id();
251 251
252 if (walk_state) { 252 if (walk_state) {
253 obj_desc->method.mutex->mutex. 253 obj_desc->method.mutex->mutex.
254 original_sync_level = 254 original_sync_level =
255 walk_state->thread->current_sync_level; 255 walk_state->thread->current_sync_level;
256 256
257 obj_desc->method.mutex->mutex.owner_thread =
258 walk_state->thread;
259 walk_state->thread->current_sync_level = 257 walk_state->thread->current_sync_level =
260 obj_desc->method.sync_level; 258 obj_desc->method.sync_level;
261 } else { 259 } else {
@@ -569,7 +567,7 @@ acpi_ds_terminate_control_method(union acpi_operand_object *method_desc,
569 567
570 acpi_os_release_mutex(method_desc->method.mutex->mutex. 568 acpi_os_release_mutex(method_desc->method.mutex->mutex.
571 os_mutex); 569 os_mutex);
572 method_desc->method.mutex->mutex.owner_thread = NULL; 570 method_desc->method.mutex->mutex.owner_thread_id = ACPI_MUTEX_NOT_ACQUIRED;
573 } 571 }
574 } 572 }
575 573
diff --git a/drivers/acpi/dock.c b/drivers/acpi/dock.c
index 688e83a16906..54a697f9aa18 100644
--- a/drivers/acpi/dock.c
+++ b/drivers/acpi/dock.c
@@ -32,11 +32,11 @@
32#include <acpi/acpi_bus.h> 32#include <acpi/acpi_bus.h>
33#include <acpi/acpi_drivers.h> 33#include <acpi/acpi_drivers.h>
34 34
35#define ACPI_DOCK_DRIVER_NAME "ACPI Dock Station Driver" 35#define ACPI_DOCK_DRIVER_DESCRIPTION "ACPI Dock Station Driver"
36 36
37ACPI_MODULE_NAME("dock") 37ACPI_MODULE_NAME("dock");
38MODULE_AUTHOR("Kristen Carlson Accardi"); 38MODULE_AUTHOR("Kristen Carlson Accardi");
39MODULE_DESCRIPTION(ACPI_DOCK_DRIVER_NAME); 39MODULE_DESCRIPTION(ACPI_DOCK_DRIVER_DESCRIPTION);
40MODULE_LICENSE("GPL"); 40MODULE_LICENSE("GPL");
41 41
42static struct atomic_notifier_head dock_notifier_list; 42static struct atomic_notifier_head dock_notifier_list;
@@ -741,7 +741,7 @@ static int dock_add(acpi_handle handle)
741 goto dock_add_err; 741 goto dock_add_err;
742 } 742 }
743 743
744 printk(KERN_INFO PREFIX "%s \n", ACPI_DOCK_DRIVER_NAME); 744 printk(KERN_INFO PREFIX "%s \n", ACPI_DOCK_DRIVER_DESCRIPTION);
745 745
746 return 0; 746 return 0;
747 747
diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c
index 743ce27fa0bb..ab6888373795 100644
--- a/drivers/acpi/ec.c
+++ b/drivers/acpi/ec.c
@@ -38,11 +38,10 @@
38#include <acpi/actypes.h> 38#include <acpi/actypes.h>
39 39
40#define _COMPONENT ACPI_EC_COMPONENT 40#define _COMPONENT ACPI_EC_COMPONENT
41ACPI_MODULE_NAME("acpi_ec") 41ACPI_MODULE_NAME("ec");
42#define ACPI_EC_COMPONENT 0x00100000 42#define ACPI_EC_COMPONENT 0x00100000
43#define ACPI_EC_CLASS "embedded_controller" 43#define ACPI_EC_CLASS "embedded_controller"
44#define ACPI_EC_HID "PNP0C09" 44#define ACPI_EC_HID "PNP0C09"
45#define ACPI_EC_DRIVER_NAME "ACPI Embedded Controller Driver"
46#define ACPI_EC_DEVICE_NAME "Embedded Controller" 45#define ACPI_EC_DEVICE_NAME "Embedded Controller"
47#define ACPI_EC_FILE_INFO "info" 46#define ACPI_EC_FILE_INFO "info"
48#undef PREFIX 47#undef PREFIX
@@ -80,7 +79,7 @@ static int acpi_ec_stop(struct acpi_device *device, int type);
80static int acpi_ec_add(struct acpi_device *device); 79static int acpi_ec_add(struct acpi_device *device);
81 80
82static struct acpi_driver acpi_ec_driver = { 81static struct acpi_driver acpi_ec_driver = {
83 .name = ACPI_EC_DRIVER_NAME, 82 .name = "ec",
84 .class = ACPI_EC_CLASS, 83 .class = ACPI_EC_CLASS,
85 .ids = ACPI_EC_HID, 84 .ids = ACPI_EC_HID,
86 .ops = { 85 .ops = {
@@ -280,8 +279,10 @@ static int acpi_ec_transaction(struct acpi_ec *ec, u8 command,
280 mutex_lock(&ec->lock); 279 mutex_lock(&ec->lock);
281 if (ec->global_lock) { 280 if (ec->global_lock) {
282 status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk); 281 status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk);
283 if (ACPI_FAILURE(status)) 282 if (ACPI_FAILURE(status)) {
283 mutex_unlock(&ec->lock);
284 return -ENODEV; 284 return -ENODEV;
285 }
285 } 286 }
286 287
287 /* Make sure GPE is enabled before doing transaction */ 288 /* Make sure GPE is enabled before doing transaction */
diff --git a/drivers/acpi/event.c b/drivers/acpi/event.c
index 959a893c8d1f..3b23562e6f92 100644
--- a/drivers/acpi/event.c
+++ b/drivers/acpi/event.c
@@ -13,7 +13,7 @@
13#include <acpi/acpi_drivers.h> 13#include <acpi/acpi_drivers.h>
14 14
15#define _COMPONENT ACPI_SYSTEM_COMPONENT 15#define _COMPONENT ACPI_SYSTEM_COMPONENT
16ACPI_MODULE_NAME("event") 16ACPI_MODULE_NAME("event");
17 17
18/* Global vars for handling event proc entry */ 18/* Global vars for handling event proc entry */
19static DEFINE_SPINLOCK(acpi_system_event_lock); 19static DEFINE_SPINLOCK(acpi_system_event_lock);
diff --git a/drivers/acpi/events/evgpe.c b/drivers/acpi/events/evgpe.c
index dfac3ecc596e..635ba449ebc2 100644
--- a/drivers/acpi/events/evgpe.c
+++ b/drivers/acpi/events/evgpe.c
@@ -636,17 +636,6 @@ acpi_ev_gpe_dispatch(struct acpi_gpe_event_info *gpe_event_info, u32 gpe_number)
636 } 636 }
637 } 637 }
638 638
639 if (!acpi_gbl_system_awake_and_running) {
640 /*
641 * We just woke up because of a wake GPE. Disable any further GPEs
642 * until we are fully up and running (Only wake GPEs should be enabled
643 * at this time, but we just brute-force disable them all.)
644 * 1) We must disable this particular wake GPE so it won't fire again
645 * 2) We want to disable all wake GPEs, since we are now awake
646 */
647 (void)acpi_hw_disable_all_gpes();
648 }
649
650 /* 639 /*
651 * Dispatch the GPE to either an installed handler, or the control method 640 * Dispatch the GPE to either an installed handler, or the control method
652 * associated with this GPE (_Lxx or _Exx). If a handler exists, we invoke 641 * associated with this GPE (_Lxx or _Exx). If a handler exists, we invoke
diff --git a/drivers/acpi/events/evmisc.c b/drivers/acpi/events/evmisc.c
index 1b784ffe54c3..d572700197f3 100644
--- a/drivers/acpi/events/evmisc.c
+++ b/drivers/acpi/events/evmisc.c
@@ -196,12 +196,11 @@ acpi_ev_queue_notify_request(struct acpi_namespace_node * node,
196 notify_info->notify.value = (u16) notify_value; 196 notify_info->notify.value = (u16) notify_value;
197 notify_info->notify.handler_obj = handler_obj; 197 notify_info->notify.handler_obj = handler_obj;
198 198
199 status = 199 acpi_ex_relinquish_interpreter();
200 acpi_os_execute(OSL_NOTIFY_HANDLER, acpi_ev_notify_dispatch, 200
201 notify_info); 201 acpi_ev_notify_dispatch(notify_info);
202 if (ACPI_FAILURE(status)) { 202
203 acpi_ut_delete_generic_state(notify_info); 203 acpi_ex_reacquire_interpreter();
204 }
205 } 204 }
206 205
207 if (!handler_obj) { 206 if (!handler_obj) {
diff --git a/drivers/acpi/executer/exdump.c b/drivers/acpi/executer/exdump.c
index 68d283fd60e7..1a73c14df2c5 100644
--- a/drivers/acpi/executer/exdump.c
+++ b/drivers/acpi/executer/exdump.c
@@ -134,7 +134,7 @@ static struct acpi_exdump_info acpi_ex_dump_method[8] = {
134static struct acpi_exdump_info acpi_ex_dump_mutex[5] = { 134static struct acpi_exdump_info acpi_ex_dump_mutex[5] = {
135 {ACPI_EXD_INIT, ACPI_EXD_TABLE_SIZE(acpi_ex_dump_mutex), NULL}, 135 {ACPI_EXD_INIT, ACPI_EXD_TABLE_SIZE(acpi_ex_dump_mutex), NULL},
136 {ACPI_EXD_UINT8, ACPI_EXD_OFFSET(mutex.sync_level), "Sync Level"}, 136 {ACPI_EXD_UINT8, ACPI_EXD_OFFSET(mutex.sync_level), "Sync Level"},
137 {ACPI_EXD_POINTER, ACPI_EXD_OFFSET(mutex.owner_thread), "Owner Thread"}, 137 {ACPI_EXD_POINTER, ACPI_EXD_OFFSET(mutex.owner_thread_id), "Owner Thread"},
138 {ACPI_EXD_UINT16, ACPI_EXD_OFFSET(mutex.acquisition_depth), 138 {ACPI_EXD_UINT16, ACPI_EXD_OFFSET(mutex.acquisition_depth),
139 "Acquire Depth"}, 139 "Acquire Depth"},
140 {ACPI_EXD_POINTER, ACPI_EXD_OFFSET(mutex.os_mutex), "OsMutex"} 140 {ACPI_EXD_POINTER, ACPI_EXD_OFFSET(mutex.os_mutex), "OsMutex"}
diff --git a/drivers/acpi/executer/exmutex.c b/drivers/acpi/executer/exmutex.c
index 5101bad5baf8..4eb883bda6ae 100644
--- a/drivers/acpi/executer/exmutex.c
+++ b/drivers/acpi/executer/exmutex.c
@@ -66,10 +66,9 @@ acpi_ex_link_mutex(union acpi_operand_object *obj_desc,
66 * 66 *
67 ******************************************************************************/ 67 ******************************************************************************/
68 68
69void acpi_ex_unlink_mutex(union acpi_operand_object *obj_desc) 69void acpi_ex_unlink_mutex(union acpi_operand_object *obj_desc,
70 struct acpi_thread_state *thread)
70{ 71{
71 struct acpi_thread_state *thread = obj_desc->mutex.owner_thread;
72
73 if (!thread) { 72 if (!thread) {
74 return; 73 return;
75 } 74 }
@@ -174,16 +173,13 @@ acpi_ex_acquire_mutex(union acpi_operand_object *time_desc,
174 173
175 /* Support for multiple acquires by the owning thread */ 174 /* Support for multiple acquires by the owning thread */
176 175
177 if (obj_desc->mutex.owner_thread) { 176 if (obj_desc->mutex.owner_thread_id == acpi_os_get_thread_id()) {
178 if (obj_desc->mutex.owner_thread->thread_id == 177 /*
179 walk_state->thread->thread_id) { 178 * The mutex is already owned by this thread, just increment the
180 /* 179 * acquisition depth
181 * The mutex is already owned by this thread, just increment the 180 */
182 * acquisition depth 181 obj_desc->mutex.acquisition_depth++;
183 */ 182 return_ACPI_STATUS(AE_OK);
184 obj_desc->mutex.acquisition_depth++;
185 return_ACPI_STATUS(AE_OK);
186 }
187 } 183 }
188 184
189 /* Acquire the mutex, wait if necessary. Special case for Global Lock */ 185 /* Acquire the mutex, wait if necessary. Special case for Global Lock */
@@ -206,7 +202,7 @@ acpi_ex_acquire_mutex(union acpi_operand_object *time_desc,
206 202
207 /* Have the mutex: update mutex and walk info and save the sync_level */ 203 /* Have the mutex: update mutex and walk info and save the sync_level */
208 204
209 obj_desc->mutex.owner_thread = walk_state->thread; 205 obj_desc->mutex.owner_thread_id = acpi_os_get_thread_id();
210 obj_desc->mutex.acquisition_depth = 1; 206 obj_desc->mutex.acquisition_depth = 1;
211 obj_desc->mutex.original_sync_level = 207 obj_desc->mutex.original_sync_level =
212 walk_state->thread->current_sync_level; 208 walk_state->thread->current_sync_level;
@@ -246,7 +242,7 @@ acpi_ex_release_mutex(union acpi_operand_object *obj_desc,
246 242
247 /* The mutex must have been previously acquired in order to release it */ 243 /* The mutex must have been previously acquired in order to release it */
248 244
249 if (!obj_desc->mutex.owner_thread) { 245 if (!obj_desc->mutex.owner_thread_id) {
250 ACPI_ERROR((AE_INFO, 246 ACPI_ERROR((AE_INFO,
251 "Cannot release Mutex [%4.4s], not acquired", 247 "Cannot release Mutex [%4.4s], not acquired",
252 acpi_ut_get_node_name(obj_desc->mutex.node))); 248 acpi_ut_get_node_name(obj_desc->mutex.node)));
@@ -266,14 +262,14 @@ acpi_ex_release_mutex(union acpi_operand_object *obj_desc,
266 * The Mutex is owned, but this thread must be the owner. 262 * The Mutex is owned, but this thread must be the owner.
267 * Special case for Global Lock, any thread can release 263 * Special case for Global Lock, any thread can release
268 */ 264 */
269 if ((obj_desc->mutex.owner_thread->thread_id != 265 if ((obj_desc->mutex.owner_thread_id !=
270 walk_state->thread->thread_id) 266 walk_state->thread->thread_id)
271 && (obj_desc->mutex.os_mutex != acpi_gbl_global_lock_mutex)) { 267 && (obj_desc->mutex.os_mutex != acpi_gbl_global_lock_mutex)) {
272 ACPI_ERROR((AE_INFO, 268 ACPI_ERROR((AE_INFO,
273 "Thread %lX cannot release Mutex [%4.4s] acquired by thread %lX", 269 "Thread %lX cannot release Mutex [%4.4s] acquired by thread %lX",
274 (unsigned long)walk_state->thread->thread_id, 270 (unsigned long)walk_state->thread->thread_id,
275 acpi_ut_get_node_name(obj_desc->mutex.node), 271 acpi_ut_get_node_name(obj_desc->mutex.node),
276 (unsigned long)obj_desc->mutex.owner_thread->thread_id)); 272 (unsigned long)obj_desc->mutex.owner_thread_id));
277 return_ACPI_STATUS(AE_AML_NOT_OWNER); 273 return_ACPI_STATUS(AE_AML_NOT_OWNER);
278 } 274 }
279 275
@@ -300,7 +296,7 @@ acpi_ex_release_mutex(union acpi_operand_object *obj_desc,
300 296
301 /* Unlink the mutex from the owner's list */ 297 /* Unlink the mutex from the owner's list */
302 298
303 acpi_ex_unlink_mutex(obj_desc); 299 acpi_ex_unlink_mutex(obj_desc, walk_state->thread);
304 300
305 /* Release the mutex, special case for Global Lock */ 301 /* Release the mutex, special case for Global Lock */
306 302
@@ -312,7 +308,7 @@ acpi_ex_release_mutex(union acpi_operand_object *obj_desc,
312 308
313 /* Update the mutex and restore sync_level */ 309 /* Update the mutex and restore sync_level */
314 310
315 obj_desc->mutex.owner_thread = NULL; 311 obj_desc->mutex.owner_thread_id = ACPI_MUTEX_NOT_ACQUIRED;
316 walk_state->thread->current_sync_level = 312 walk_state->thread->current_sync_level =
317 obj_desc->mutex.original_sync_level; 313 obj_desc->mutex.original_sync_level;
318 314
@@ -367,7 +363,7 @@ void acpi_ex_release_all_mutexes(struct acpi_thread_state *thread)
367 363
368 /* Mark mutex unowned */ 364 /* Mark mutex unowned */
369 365
370 obj_desc->mutex.owner_thread = NULL; 366 obj_desc->mutex.owner_thread_id = ACPI_MUTEX_NOT_ACQUIRED;
371 367
372 /* Update Thread sync_level (Last mutex is the important one) */ 368 /* Update Thread sync_level (Last mutex is the important one) */
373 369
diff --git a/drivers/acpi/fan.c b/drivers/acpi/fan.c
index af22fdf73413..ec655c539492 100644
--- a/drivers/acpi/fan.c
+++ b/drivers/acpi/fan.c
@@ -36,14 +36,13 @@
36 36
37#define ACPI_FAN_COMPONENT 0x00200000 37#define ACPI_FAN_COMPONENT 0x00200000
38#define ACPI_FAN_CLASS "fan" 38#define ACPI_FAN_CLASS "fan"
39#define ACPI_FAN_DRIVER_NAME "ACPI Fan Driver"
40#define ACPI_FAN_FILE_STATE "state" 39#define ACPI_FAN_FILE_STATE "state"
41 40
42#define _COMPONENT ACPI_FAN_COMPONENT 41#define _COMPONENT ACPI_FAN_COMPONENT
43ACPI_MODULE_NAME("acpi_fan") 42ACPI_MODULE_NAME("fan");
44 43
45 MODULE_AUTHOR("Paul Diefenbaugh"); 44MODULE_AUTHOR("Paul Diefenbaugh");
46MODULE_DESCRIPTION(ACPI_FAN_DRIVER_NAME); 45MODULE_DESCRIPTION("ACPI Fan Driver");
47MODULE_LICENSE("GPL"); 46MODULE_LICENSE("GPL");
48 47
49static int acpi_fan_add(struct acpi_device *device); 48static int acpi_fan_add(struct acpi_device *device);
@@ -52,7 +51,7 @@ static int acpi_fan_suspend(struct acpi_device *device, pm_message_t state);
52static int acpi_fan_resume(struct acpi_device *device); 51static int acpi_fan_resume(struct acpi_device *device);
53 52
54static struct acpi_driver acpi_fan_driver = { 53static struct acpi_driver acpi_fan_driver = {
55 .name = ACPI_FAN_DRIVER_NAME, 54 .name = "fan",
56 .class = ACPI_FAN_CLASS, 55 .class = ACPI_FAN_CLASS,
57 .ids = "PNP0C0B", 56 .ids = "PNP0C0B",
58 .ops = { 57 .ops = {
diff --git a/drivers/acpi/glue.c b/drivers/acpi/glue.c
index 7b6c9ff9bebe..4334c208841a 100644
--- a/drivers/acpi/glue.c
+++ b/drivers/acpi/glue.c
@@ -241,3 +241,65 @@ static int __init init_acpi_device_notify(void)
241} 241}
242 242
243arch_initcall(init_acpi_device_notify); 243arch_initcall(init_acpi_device_notify);
244
245
246#if defined(CONFIG_RTC_DRV_CMOS) || defined(CONFIG_RTC_DRV_CMOS_MODULE)
247
248/* Every ACPI platform has a mc146818 compatible "cmos rtc". Here we find
249 * its device node and pass extra config data. This helps its driver use
250 * capabilities that the now-obsolete mc146818 didn't have, and informs it
251 * that this board's RTC is wakeup-capable (per ACPI spec).
252 */
253#include <linux/mc146818rtc.h>
254
255static struct cmos_rtc_board_info rtc_info;
256
257
258/* PNP devices are registered in a subsys_initcall();
259 * ACPI specifies the PNP IDs to use.
260 */
261#include <linux/pnp.h>
262
263static int __init pnp_match(struct device *dev, void *data)
264{
265 static const char *ids[] = { "PNP0b00", "PNP0b01", "PNP0b02", };
266 struct pnp_dev *pnp = to_pnp_dev(dev);
267 int i;
268
269 for (i = 0; i < ARRAY_SIZE(ids); i++) {
270 if (compare_pnp_id(pnp->id, ids[i]) != 0)
271 return 1;
272 }
273 return 0;
274}
275
276static struct device *__init get_rtc_dev(void)
277{
278 return bus_find_device(&pnp_bus_type, NULL, NULL, pnp_match);
279}
280
281static int __init acpi_rtc_init(void)
282{
283 struct device *dev = get_rtc_dev();
284
285 if (dev) {
286 rtc_info.rtc_day_alarm = acpi_gbl_FADT.day_alarm;
287 rtc_info.rtc_mon_alarm = acpi_gbl_FADT.month_alarm;
288 rtc_info.rtc_century = acpi_gbl_FADT.century;
289
290 /* NOTE: acpi_gbl_FADT->rtcs4 is NOT currently useful */
291
292 dev->platform_data = &rtc_info;
293
294 /* RTC always wakes from S1/S2/S3, and often S4/STD */
295 device_init_wakeup(dev, 1);
296
297 put_device(dev);
298 } else
299 pr_debug("ACPI: RTC unavailable?\n");
300 return 0;
301}
302/* do this between RTC subsys_initcall() and rtc_cmos driver_initcall() */
303fs_initcall(acpi_rtc_init);
304
305#endif
diff --git a/drivers/acpi/hardware/hwsleep.c b/drivers/acpi/hardware/hwsleep.c
index 57901ca3ade9..8fa93125fd4c 100644
--- a/drivers/acpi/hardware/hwsleep.c
+++ b/drivers/acpi/hardware/hwsleep.c
@@ -235,6 +235,14 @@ acpi_status acpi_enter_sleep_state_prep(u8 sleep_state)
235 "While executing method _SST")); 235 "While executing method _SST"));
236 } 236 }
237 237
238 /*
239 * 1) Disable/Clear all GPEs
240 */
241 status = acpi_hw_disable_all_gpes();
242 if (ACPI_FAILURE(status)) {
243 return_ACPI_STATUS(status);
244 }
245
238 return_ACPI_STATUS(AE_OK); 246 return_ACPI_STATUS(AE_OK);
239} 247}
240 248
@@ -290,13 +298,8 @@ acpi_status asmlinkage acpi_enter_sleep_state(u8 sleep_state)
290 } 298 }
291 299
292 /* 300 /*
293 * 1) Disable/Clear all GPEs
294 * 2) Enable all wakeup GPEs 301 * 2) Enable all wakeup GPEs
295 */ 302 */
296 status = acpi_hw_disable_all_gpes();
297 if (ACPI_FAILURE(status)) {
298 return_ACPI_STATUS(status);
299 }
300 acpi_gbl_system_awake_and_running = FALSE; 303 acpi_gbl_system_awake_and_running = FALSE;
301 304
302 status = acpi_hw_enable_all_wakeup_gpes(); 305 status = acpi_hw_enable_all_wakeup_gpes();
diff --git a/drivers/acpi/hotkey.c b/drivers/acpi/hotkey.c
deleted file mode 100644
index 8edfb92f7ede..000000000000
--- a/drivers/acpi/hotkey.c
+++ /dev/null
@@ -1,1042 +0,0 @@
1/*
2 * hotkey.c - ACPI Hotkey Driver ($Revision: 0.2 $)
3 *
4 * Copyright (C) 2004 Luming Yu <luming.yu@intel.com>
5 *
6 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or (at
11 * your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
21 *
22 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
23 */
24#include <linux/kernel.h>
25#include <linux/module.h>
26#include <linux/init.h>
27#include <linux/types.h>
28#include <linux/proc_fs.h>
29#include <linux/sched.h>
30#include <linux/kmod.h>
31#include <linux/seq_file.h>
32#include <acpi/acpi_drivers.h>
33#include <acpi/acpi_bus.h>
34#include <asm/uaccess.h>
35
36#define HOTKEY_ACPI_VERSION "0.1"
37
38#define HOTKEY_PROC "hotkey"
39#define HOTKEY_EV_CONFIG "event_config"
40#define HOTKEY_PL_CONFIG "poll_config"
41#define HOTKEY_ACTION "action"
42#define HOTKEY_INFO "info"
43
44#define ACPI_HOTK_NAME "Generic Hotkey Driver"
45#define ACPI_HOTK_CLASS "Hotkey"
46#define ACPI_HOTK_DEVICE_NAME "Hotkey"
47#define ACPI_HOTK_HID "Unknown?"
48#define ACPI_HOTKEY_COMPONENT 0x20000000
49
50#define ACPI_HOTKEY_EVENT 0x1
51#define ACPI_HOTKEY_POLLING 0x2
52#define ACPI_UNDEFINED_EVENT 0xf
53
54#define RESULT_STR_LEN 80
55
56#define ACTION_METHOD 0
57#define POLL_METHOD 1
58
59#define IS_EVENT(e) ((e) <= 10000 && (e) >0)
60#define IS_POLL(e) ((e) > 10000)
61#define IS_OTHERS(e) ((e)<=0 || (e)>=20000)
62#define _COMPONENT ACPI_HOTKEY_COMPONENT
63ACPI_MODULE_NAME("acpi_hotkey")
64
65 MODULE_AUTHOR("luming.yu@intel.com");
66MODULE_DESCRIPTION(ACPI_HOTK_NAME);
67MODULE_LICENSE("GPL");
68
69/* standardized internal hotkey number/event */
70enum {
71 /* Video Extension event */
72 HK_EVENT_CYCLE_OUTPUT_DEVICE = 0x80,
73 HK_EVENT_OUTPUT_DEVICE_STATUS_CHANGE,
74 HK_EVENT_CYCLE_DISPLAY_OUTPUT,
75 HK_EVENT_NEXT_DISPLAY_OUTPUT,
76 HK_EVENT_PREVIOUS_DISPLAY_OUTPUT,
77 HK_EVENT_CYCLE_BRIGHTNESS,
78 HK_EVENT_INCREASE_BRIGHTNESS,
79 HK_EVENT_DECREASE_BRIGHTNESS,
80 HK_EVENT_ZERO_BRIGHTNESS,
81 HK_EVENT_DISPLAY_DEVICE_OFF,
82
83 /* Snd Card event */
84 HK_EVENT_VOLUME_MUTE,
85 HK_EVENT_VOLUME_INCLREASE,
86 HK_EVENT_VOLUME_DECREASE,
87
88 /* running state control */
89 HK_EVENT_ENTERRING_S3,
90 HK_EVENT_ENTERRING_S4,
91 HK_EVENT_ENTERRING_S5,
92};
93
94enum conf_entry_enum {
95 bus_handle = 0,
96 bus_method = 1,
97 action_handle = 2,
98 method = 3,
99 LAST_CONF_ENTRY
100};
101
102/* procdir we use */
103static struct proc_dir_entry *hotkey_proc_dir;
104static struct proc_dir_entry *hotkey_config;
105static struct proc_dir_entry *hotkey_poll_config;
106static struct proc_dir_entry *hotkey_action;
107static struct proc_dir_entry *hotkey_info;
108
109/* linkage for all type of hotkey */
110struct acpi_hotkey_link {
111 struct list_head entries;
112 int hotkey_type; /* event or polling based hotkey */
113 int hotkey_standard_num; /* standardized hotkey(event) number */
114};
115
116/* event based hotkey */
117struct acpi_event_hotkey {
118 struct acpi_hotkey_link hotkey_link;
119 int flag;
120 acpi_handle bus_handle; /* bus to install notify handler */
121 int external_hotkey_num; /* external hotkey/event number */
122 acpi_handle action_handle; /* acpi handle attached aml action method */
123 char *action_method; /* action method */
124};
125
126/*
127 * There are two ways to poll status
128 * 1. directy call read_xxx method, without any arguments passed in
129 * 2. call write_xxx method, with arguments passed in, you need
130 * the result is saved in acpi_polling_hotkey.poll_result.
131 * anthoer read command through polling interface.
132 *
133 */
134
135/* polling based hotkey */
136struct acpi_polling_hotkey {
137 struct acpi_hotkey_link hotkey_link;
138 int flag;
139 acpi_handle poll_handle; /* acpi handle attached polling method */
140 char *poll_method; /* poll method */
141 acpi_handle action_handle; /* acpi handle attached action method */
142 char *action_method; /* action method */
143 union acpi_object *poll_result; /* polling_result */
144 struct proc_dir_entry *proc;
145};
146
147/* hotkey object union */
148union acpi_hotkey {
149 struct list_head entries;
150 struct acpi_hotkey_link link;
151 struct acpi_event_hotkey event_hotkey;
152 struct acpi_polling_hotkey poll_hotkey;
153};
154
155/* hotkey object list */
156struct acpi_hotkey_list {
157 struct list_head *entries;
158 int count;
159};
160
161static int auto_hotkey_add(struct acpi_device *device);
162static int auto_hotkey_remove(struct acpi_device *device, int type);
163
164static struct acpi_driver hotkey_driver = {
165 .name = ACPI_HOTK_NAME,
166 .class = ACPI_HOTK_CLASS,
167 .ids = ACPI_HOTK_HID,
168 .ops = {
169 .add = auto_hotkey_add,
170 .remove = auto_hotkey_remove,
171 },
172};
173
174static void free_hotkey_device(union acpi_hotkey *key);
175static void free_hotkey_buffer(union acpi_hotkey *key);
176static void free_poll_hotkey_buffer(union acpi_hotkey *key);
177static int hotkey_open_config(struct inode *inode, struct file *file);
178static int hotkey_poll_open_config(struct inode *inode, struct file *file);
179static ssize_t hotkey_write_config(struct file *file,
180 const char __user * buffer,
181 size_t count, loff_t * data);
182static int hotkey_info_open_fs(struct inode *inode, struct file *file);
183static int hotkey_action_open_fs(struct inode *inode, struct file *file);
184static ssize_t hotkey_execute_aml_method(struct file *file,
185 const char __user * buffer,
186 size_t count, loff_t * data);
187static int hotkey_config_seq_show(struct seq_file *seq, void *offset);
188static int hotkey_poll_config_seq_show(struct seq_file *seq, void *offset);
189static int hotkey_polling_open_fs(struct inode *inode, struct file *file);
190static union acpi_hotkey *get_hotkey_by_event(struct
191 acpi_hotkey_list
192 *hotkey_list, int event);
193
194/* event based config */
195static const struct file_operations hotkey_config_fops = {
196 .open = hotkey_open_config,
197 .read = seq_read,
198 .write = hotkey_write_config,
199 .llseek = seq_lseek,
200 .release = single_release,
201};
202
203/* polling based config */
204static const struct file_operations hotkey_poll_config_fops = {
205 .open = hotkey_poll_open_config,
206 .read = seq_read,
207 .write = hotkey_write_config,
208 .llseek = seq_lseek,
209 .release = single_release,
210};
211
212/* hotkey driver info */
213static const struct file_operations hotkey_info_fops = {
214 .open = hotkey_info_open_fs,
215 .read = seq_read,
216 .llseek = seq_lseek,
217 .release = single_release,
218};
219
220/* action */
221static const struct file_operations hotkey_action_fops = {
222 .open = hotkey_action_open_fs,
223 .read = seq_read,
224 .write = hotkey_execute_aml_method,
225 .llseek = seq_lseek,
226 .release = single_release,
227};
228
229/* polling results */
230static const struct file_operations hotkey_polling_fops = {
231 .open = hotkey_polling_open_fs,
232 .read = seq_read,
233 .llseek = seq_lseek,
234 .release = single_release,
235};
236
237struct acpi_hotkey_list global_hotkey_list; /* link all ev or pl hotkey */
238struct list_head hotkey_entries; /* head of the list of hotkey_list */
239
240static int hotkey_info_seq_show(struct seq_file *seq, void *offset)
241{
242
243 seq_printf(seq, "Hotkey generic driver ver: %s\n", HOTKEY_ACPI_VERSION);
244
245 return 0;
246}
247
248static int hotkey_info_open_fs(struct inode *inode, struct file *file)
249{
250 return single_open(file, hotkey_info_seq_show, PDE(inode)->data);
251}
252
253static char *format_result(union acpi_object *object)
254{
255 char *buf;
256
257 buf = kzalloc(RESULT_STR_LEN, GFP_KERNEL);
258 if (!buf)
259 return NULL;
260 /* Now, just support integer type */
261 if (object->type == ACPI_TYPE_INTEGER)
262 sprintf(buf, "%d\n", (u32) object->integer.value);
263 return buf;
264}
265
266static int hotkey_polling_seq_show(struct seq_file *seq, void *offset)
267{
268 struct acpi_polling_hotkey *poll_hotkey = seq->private;
269 char *buf;
270
271
272 if (poll_hotkey->poll_result) {
273 buf = format_result(poll_hotkey->poll_result);
274 if (buf)
275 seq_printf(seq, "%s", buf);
276 kfree(buf);
277 }
278 return 0;
279}
280
281static int hotkey_polling_open_fs(struct inode *inode, struct file *file)
282{
283 return single_open(file, hotkey_polling_seq_show, PDE(inode)->data);
284}
285
286static int hotkey_action_open_fs(struct inode *inode, struct file *file)
287{
288 return single_open(file, hotkey_info_seq_show, PDE(inode)->data);
289}
290
291/* Mapping external hotkey number to standardized hotkey event num */
292static int hotkey_get_internal_event(int event, struct acpi_hotkey_list *list)
293{
294 struct list_head *entries;
295 int val = -1;
296
297
298 list_for_each(entries, list->entries) {
299 union acpi_hotkey *key =
300 container_of(entries, union acpi_hotkey, entries);
301 if (key->link.hotkey_type == ACPI_HOTKEY_EVENT
302 && key->event_hotkey.external_hotkey_num == event) {
303 val = key->link.hotkey_standard_num;
304 break;
305 }
306 }
307
308 return val;
309}
310
311static void
312acpi_hotkey_notify_handler(acpi_handle handle, u32 event, void *data)
313{
314 struct acpi_device *device = NULL;
315 u32 internal_event;
316
317
318 if (acpi_bus_get_device(handle, &device))
319 return;
320
321 internal_event = hotkey_get_internal_event(event, &global_hotkey_list);
322 acpi_bus_generate_event(device, internal_event, 0);
323
324 return;
325}
326
327/* Need to invent automatically hotkey add method */
328static int auto_hotkey_add(struct acpi_device *device)
329{
330 /* Implement me */
331 return 0;
332}
333
334/* Need to invent automatically hotkey remove method */
335static int auto_hotkey_remove(struct acpi_device *device, int type)
336{
337 /* Implement me */
338 return 0;
339}
340
341/* Create a proc file for each polling method */
342static int create_polling_proc(union acpi_hotkey *device)
343{
344 struct proc_dir_entry *proc;
345 char proc_name[80];
346 mode_t mode;
347
348 mode = S_IFREG | S_IRUGO | S_IWUGO;
349
350 sprintf(proc_name, "%d", device->link.hotkey_standard_num);
351 /*
352 strcat(proc_name, device->poll_hotkey.poll_method);
353 */
354 proc = create_proc_entry(proc_name, mode, hotkey_proc_dir);
355
356 if (!proc) {
357 return -ENODEV;
358 } else {
359 proc->proc_fops = &hotkey_polling_fops;
360 proc->owner = THIS_MODULE;
361 proc->data = device;
362 proc->uid = 0;
363 proc->gid = 0;
364 device->poll_hotkey.proc = proc;
365 }
366 return 0;
367}
368
369static int hotkey_add(union acpi_hotkey *device)
370{
371 int status = 0;
372 struct acpi_device *dev = NULL;
373
374
375 if (device->link.hotkey_type == ACPI_HOTKEY_EVENT) {
376 acpi_bus_get_device(device->event_hotkey.bus_handle, &dev);
377 status = acpi_install_notify_handler(dev->handle,
378 ACPI_DEVICE_NOTIFY,
379 acpi_hotkey_notify_handler,
380 dev);
381 } else /* Add polling hotkey */
382 create_polling_proc(device);
383
384 global_hotkey_list.count++;
385
386 list_add_tail(&device->link.entries, global_hotkey_list.entries);
387
388 return status;
389}
390
391static int hotkey_remove(union acpi_hotkey *device)
392{
393 struct list_head *entries, *next;
394
395
396 list_for_each_safe(entries, next, global_hotkey_list.entries) {
397 union acpi_hotkey *key =
398 container_of(entries, union acpi_hotkey, entries);
399 if (key->link.hotkey_standard_num ==
400 device->link.hotkey_standard_num) {
401 list_del(&key->link.entries);
402 free_hotkey_device(key);
403 global_hotkey_list.count--;
404 break;
405 }
406 }
407 kfree(device);
408 return 0;
409}
410
411static int hotkey_update(union acpi_hotkey *key)
412{
413 struct list_head *entries;
414
415
416 list_for_each(entries, global_hotkey_list.entries) {
417 union acpi_hotkey *tmp =
418 container_of(entries, union acpi_hotkey, entries);
419 if (tmp->link.hotkey_standard_num ==
420 key->link.hotkey_standard_num) {
421 if (key->link.hotkey_type == ACPI_HOTKEY_EVENT) {
422 free_hotkey_buffer(tmp);
423 tmp->event_hotkey.bus_handle =
424 key->event_hotkey.bus_handle;
425 tmp->event_hotkey.external_hotkey_num =
426 key->event_hotkey.external_hotkey_num;
427 tmp->event_hotkey.action_handle =
428 key->event_hotkey.action_handle;
429 tmp->event_hotkey.action_method =
430 key->event_hotkey.action_method;
431 kfree(key);
432 } else {
433 /*
434 char proc_name[80];
435
436 sprintf(proc_name, "%d", tmp->link.hotkey_standard_num);
437 strcat(proc_name, tmp->poll_hotkey.poll_method);
438 remove_proc_entry(proc_name,hotkey_proc_dir);
439 */
440 free_poll_hotkey_buffer(tmp);
441 tmp->poll_hotkey.poll_handle =
442 key->poll_hotkey.poll_handle;
443 tmp->poll_hotkey.poll_method =
444 key->poll_hotkey.poll_method;
445 tmp->poll_hotkey.action_handle =
446 key->poll_hotkey.action_handle;
447 tmp->poll_hotkey.action_method =
448 key->poll_hotkey.action_method;
449 tmp->poll_hotkey.poll_result =
450 key->poll_hotkey.poll_result;
451 /*
452 create_polling_proc(tmp);
453 */
454 kfree(key);
455 }
456 return 0;
457 break;
458 }
459 }
460
461 return -ENODEV;
462}
463
464static void free_hotkey_device(union acpi_hotkey *key)
465{
466 struct acpi_device *dev;
467
468
469 if (key->link.hotkey_type == ACPI_HOTKEY_EVENT) {
470 acpi_bus_get_device(key->event_hotkey.bus_handle, &dev);
471 if (dev->handle)
472 acpi_remove_notify_handler(dev->handle,
473 ACPI_DEVICE_NOTIFY,
474 acpi_hotkey_notify_handler);
475 free_hotkey_buffer(key);
476 } else {
477 char proc_name[80];
478
479 sprintf(proc_name, "%d", key->link.hotkey_standard_num);
480 /*
481 strcat(proc_name, key->poll_hotkey.poll_method);
482 */
483 remove_proc_entry(proc_name, hotkey_proc_dir);
484 free_poll_hotkey_buffer(key);
485 }
486 kfree(key);
487 return;
488}
489
490static void free_hotkey_buffer(union acpi_hotkey *key)
491{
492 /* key would never be null, action method could be */
493 kfree(key->event_hotkey.action_method);
494}
495
496static void free_poll_hotkey_buffer(union acpi_hotkey *key)
497{
498 /* key would never be null, others could be*/
499 kfree(key->poll_hotkey.action_method);
500 kfree(key->poll_hotkey.poll_method);
501 kfree(key->poll_hotkey.poll_result);
502}
503static int
504init_hotkey_device(union acpi_hotkey *key, char **config_entry,
505 int std_num, int external_num)
506{
507 acpi_handle tmp_handle;
508 acpi_status status = AE_OK;
509
510 if (std_num < 0 || IS_POLL(std_num) || !key)
511 goto do_fail;
512
513 if (!config_entry[bus_handle] || !config_entry[action_handle]
514 || !config_entry[method])
515 goto do_fail;
516
517 key->link.hotkey_type = ACPI_HOTKEY_EVENT;
518 key->link.hotkey_standard_num = std_num;
519 key->event_hotkey.flag = 0;
520 key->event_hotkey.action_method = config_entry[method];
521
522 status = acpi_get_handle(NULL, config_entry[bus_handle],
523 &(key->event_hotkey.bus_handle));
524 if (ACPI_FAILURE(status))
525 goto do_fail_zero;
526 key->event_hotkey.external_hotkey_num = external_num;
527 status = acpi_get_handle(NULL, config_entry[action_handle],
528 &(key->event_hotkey.action_handle));
529 if (ACPI_FAILURE(status))
530 goto do_fail_zero;
531 status = acpi_get_handle(key->event_hotkey.action_handle,
532 config_entry[method], &tmp_handle);
533 if (ACPI_FAILURE(status))
534 goto do_fail_zero;
535 return AE_OK;
536do_fail_zero:
537 key->event_hotkey.action_method = NULL;
538do_fail:
539 return -ENODEV;
540}
541
542static int
543init_poll_hotkey_device(union acpi_hotkey *key, char **config_entry,
544 int std_num)
545{
546 acpi_status status = AE_OK;
547 acpi_handle tmp_handle;
548
549 if (std_num < 0 || IS_EVENT(std_num) || !key)
550 goto do_fail;
551 if (!config_entry[bus_handle] ||!config_entry[bus_method] ||
552 !config_entry[action_handle] || !config_entry[method])
553 goto do_fail;
554
555 key->link.hotkey_type = ACPI_HOTKEY_POLLING;
556 key->link.hotkey_standard_num = std_num;
557 key->poll_hotkey.flag = 0;
558 key->poll_hotkey.poll_method = config_entry[bus_method];
559 key->poll_hotkey.action_method = config_entry[method];
560
561 status = acpi_get_handle(NULL, config_entry[bus_handle],
562 &(key->poll_hotkey.poll_handle));
563 if (ACPI_FAILURE(status))
564 goto do_fail_zero;
565 status = acpi_get_handle(key->poll_hotkey.poll_handle,
566 config_entry[bus_method], &tmp_handle);
567 if (ACPI_FAILURE(status))
568 goto do_fail_zero;
569 status =
570 acpi_get_handle(NULL, config_entry[action_handle],
571 &(key->poll_hotkey.action_handle));
572 if (ACPI_FAILURE(status))
573 goto do_fail_zero;
574 status = acpi_get_handle(key->poll_hotkey.action_handle,
575 config_entry[method], &tmp_handle);
576 if (ACPI_FAILURE(status))
577 goto do_fail_zero;
578 key->poll_hotkey.poll_result =
579 kmalloc(sizeof(union acpi_object), GFP_KERNEL);
580 if (!key->poll_hotkey.poll_result)
581 goto do_fail_zero;
582 return AE_OK;
583
584do_fail_zero:
585 key->poll_hotkey.poll_method = NULL;
586 key->poll_hotkey.action_method = NULL;
587do_fail:
588 return -ENODEV;
589}
590
591static int hotkey_open_config(struct inode *inode, struct file *file)
592{
593 return (single_open
594 (file, hotkey_config_seq_show, PDE(inode)->data));
595}
596
597static int hotkey_poll_open_config(struct inode *inode, struct file *file)
598{
599 return (single_open
600 (file, hotkey_poll_config_seq_show, PDE(inode)->data));
601}
602
603static int hotkey_config_seq_show(struct seq_file *seq, void *offset)
604{
605 struct acpi_hotkey_list *hotkey_list = &global_hotkey_list;
606 struct list_head *entries;
607 char bus_name[ACPI_PATHNAME_MAX] = { 0 };
608 char action_name[ACPI_PATHNAME_MAX] = { 0 };
609 struct acpi_buffer bus = { ACPI_PATHNAME_MAX, bus_name };
610 struct acpi_buffer act = { ACPI_PATHNAME_MAX, action_name };
611
612
613 list_for_each(entries, hotkey_list->entries) {
614 union acpi_hotkey *key =
615 container_of(entries, union acpi_hotkey, entries);
616 if (key->link.hotkey_type == ACPI_HOTKEY_EVENT) {
617 acpi_get_name(key->event_hotkey.bus_handle,
618 ACPI_NAME_TYPE_MAX, &bus);
619 acpi_get_name(key->event_hotkey.action_handle,
620 ACPI_NAME_TYPE_MAX, &act);
621 seq_printf(seq, "%s:%s:%s:%d:%d\n", bus_name,
622 action_name,
623 key->event_hotkey.action_method,
624 key->link.hotkey_standard_num,
625 key->event_hotkey.external_hotkey_num);
626 }
627 }
628 seq_puts(seq, "\n");
629 return 0;
630}
631
632static int hotkey_poll_config_seq_show(struct seq_file *seq, void *offset)
633{
634 struct acpi_hotkey_list *hotkey_list = &global_hotkey_list;
635 struct list_head *entries;
636 char bus_name[ACPI_PATHNAME_MAX] = { 0 };
637 char action_name[ACPI_PATHNAME_MAX] = { 0 };
638 struct acpi_buffer bus = { ACPI_PATHNAME_MAX, bus_name };
639 struct acpi_buffer act = { ACPI_PATHNAME_MAX, action_name };
640
641
642 list_for_each(entries, hotkey_list->entries) {
643 union acpi_hotkey *key =
644 container_of(entries, union acpi_hotkey, entries);
645 if (key->link.hotkey_type == ACPI_HOTKEY_POLLING) {
646 acpi_get_name(key->poll_hotkey.poll_handle,
647 ACPI_NAME_TYPE_MAX, &bus);
648 acpi_get_name(key->poll_hotkey.action_handle,
649 ACPI_NAME_TYPE_MAX, &act);
650 seq_printf(seq, "%s:%s:%s:%s:%d\n", bus_name,
651 key->poll_hotkey.poll_method,
652 action_name,
653 key->poll_hotkey.action_method,
654 key->link.hotkey_standard_num);
655 }
656 }
657 seq_puts(seq, "\n");
658 return 0;
659}
660
661static int
662get_parms(char *config_record, int *cmd, char **config_entry,
663 int *internal_event_num, int *external_event_num)
664{
665/* the format of *config_record =
666 * "1:\d+:*" : "cmd:internal_event_num"
667 * "\d+:\w+:\w+:\w+:\w+:\d+:\d+" :
668 * "cmd:bus_handle:bus_method:action_handle:method:internal_event_num:external_event_num"
669 */
670 char *tmp, *tmp1, count;
671 int i;
672
673 sscanf(config_record, "%d", cmd);
674 if (*cmd == 1) {
675 if (sscanf(config_record, "%d:%d", cmd, internal_event_num) !=
676 2)
677 goto do_fail;
678 else
679 return (6);
680 }
681 tmp = strchr(config_record, ':');
682 if (!tmp)
683 goto do_fail;
684 tmp++;
685 for (i = 0; i < LAST_CONF_ENTRY; i++) {
686 tmp1 = strchr(tmp, ':');
687 if (!tmp1) {
688 goto do_fail;
689 }
690 count = tmp1 - tmp;
691 config_entry[i] = kzalloc(count + 1, GFP_KERNEL);
692 if (!config_entry[i])
693 goto handle_failure;
694 strncpy(config_entry[i], tmp, count);
695 tmp = tmp1 + 1;
696 }
697 if (sscanf(tmp, "%d:%d", internal_event_num, external_event_num) <= 0)
698 goto handle_failure;
699 if (!IS_OTHERS(*internal_event_num)) {
700 return 6;
701 }
702handle_failure:
703 while (i-- > 0)
704 kfree(config_entry[i]);
705do_fail:
706 return -1;
707}
708
709/* count is length for one input record */
710static ssize_t hotkey_write_config(struct file *file,
711 const char __user * buffer,
712 size_t count, loff_t * data)
713{
714 char *config_record = NULL;
715 char *config_entry[LAST_CONF_ENTRY];
716 int cmd, internal_event_num, external_event_num;
717 int ret = 0;
718 union acpi_hotkey *key = kzalloc(sizeof(union acpi_hotkey), GFP_KERNEL);
719
720 if (!key)
721 return -ENOMEM;
722
723 config_record = kzalloc(count + 1, GFP_KERNEL);
724 if (!config_record) {
725 kfree(key);
726 return -ENOMEM;
727 }
728
729 if (copy_from_user(config_record, buffer, count)) {
730 kfree(config_record);
731 kfree(key);
732 printk(KERN_ERR PREFIX "Invalid data\n");
733 return -EINVAL;
734 }
735 ret = get_parms(config_record, &cmd, config_entry,
736 &internal_event_num, &external_event_num);
737 kfree(config_record);
738 if (ret != 6) {
739 printk(KERN_ERR PREFIX "Invalid data format ret=%d\n", ret);
740 return -EINVAL;
741 }
742
743 if (cmd == 1) {
744 union acpi_hotkey *tmp = NULL;
745 tmp = get_hotkey_by_event(&global_hotkey_list,
746 internal_event_num);
747 if (!tmp)
748 printk(KERN_ERR PREFIX "Invalid key\n");
749 else
750 memcpy(key, tmp, sizeof(union acpi_hotkey));
751 goto cont_cmd;
752 }
753 if (IS_EVENT(internal_event_num)) {
754 if (init_hotkey_device(key, config_entry,
755 internal_event_num, external_event_num))
756 goto init_hotkey_fail;
757 } else {
758 if (init_poll_hotkey_device(key, config_entry,
759 internal_event_num))
760 goto init_poll_hotkey_fail;
761 }
762cont_cmd:
763 switch (cmd) {
764 case 0:
765 if (get_hotkey_by_event(&global_hotkey_list,
766 key->link.hotkey_standard_num))
767 goto fail_out;
768 else
769 hotkey_add(key);
770 break;
771 case 1:
772 hotkey_remove(key);
773 break;
774 case 2:
775 /* key is kfree()ed if matched*/
776 if (hotkey_update(key))
777 goto fail_out;
778 break;
779 default:
780 goto fail_out;
781 break;
782 }
783 return count;
784
785init_poll_hotkey_fail: /* failed init_poll_hotkey_device */
786 kfree(config_entry[bus_method]);
787 config_entry[bus_method] = NULL;
788init_hotkey_fail: /* failed init_hotkey_device */
789 kfree(config_entry[method]);
790fail_out:
791 kfree(config_entry[bus_handle]);
792 kfree(config_entry[action_handle]);
793 /* No double free since elements =NULL for error cases */
794 if (IS_EVENT(internal_event_num)) {
795 if (config_entry[bus_method])
796 kfree(config_entry[bus_method]);
797 free_hotkey_buffer(key); /* frees [method] */
798 } else
799 free_poll_hotkey_buffer(key); /* frees [bus_method]+[method] */
800 kfree(key);
801 printk(KERN_ERR PREFIX "invalid key\n");
802 return -EINVAL;
803}
804
805/*
806 * This function evaluates an ACPI method, given an int as parameter, the
807 * method is searched within the scope of the handle, can be NULL. The output
808 * of the method is written is output, which can also be NULL
809 *
810 * returns 1 if write is successful, 0 else.
811 */
812static int write_acpi_int(acpi_handle handle, const char *method, int val,
813 struct acpi_buffer *output)
814{
815 struct acpi_object_list params; /* list of input parameters (an int here) */
816 union acpi_object in_obj; /* the only param we use */
817 acpi_status status;
818
819 params.count = 1;
820 params.pointer = &in_obj;
821 in_obj.type = ACPI_TYPE_INTEGER;
822 in_obj.integer.value = val;
823
824 status = acpi_evaluate_object(handle, (char *)method, &params, output);
825
826 return (status == AE_OK);
827}
828
829static int read_acpi_int(acpi_handle handle, const char *method,
830 union acpi_object *val)
831{
832 struct acpi_buffer output;
833 union acpi_object out_obj;
834 acpi_status status;
835
836 output.length = sizeof(out_obj);
837 output.pointer = &out_obj;
838
839 status = acpi_evaluate_object(handle, (char *)method, NULL, &output);
840 if (val) {
841 val->integer.value = out_obj.integer.value;
842 val->type = out_obj.type;
843 } else
844 printk(KERN_ERR PREFIX "null val pointer\n");
845 return ((status == AE_OK)
846 && (out_obj.type == ACPI_TYPE_INTEGER));
847}
848
849static union acpi_hotkey *get_hotkey_by_event(struct
850 acpi_hotkey_list
851 *hotkey_list, int event)
852{
853 struct list_head *entries;
854
855 list_for_each(entries, hotkey_list->entries) {
856 union acpi_hotkey *key =
857 container_of(entries, union acpi_hotkey, entries);
858 if (key->link.hotkey_standard_num == event) {
859 return (key);
860 }
861 }
862 return (NULL);
863}
864
865/*
866 * user call AML method interface:
867 * Call convention:
868 * echo "event_num: arg type : value"
869 * example: echo "1:1:30" > /proc/acpi/action
870 * Just support 1 integer arg passing to AML method
871 */
872
873static ssize_t hotkey_execute_aml_method(struct file *file,
874 const char __user * buffer,
875 size_t count, loff_t * data)
876{
877 struct acpi_hotkey_list *hotkey_list = &global_hotkey_list;
878 char *arg;
879 int event, method_type, type, value;
880 union acpi_hotkey *key;
881
882
883 arg = kzalloc(count + 1, GFP_KERNEL);
884 if (!arg)
885 return -ENOMEM;
886
887 if (copy_from_user(arg, buffer, count)) {
888 kfree(arg);
889 printk(KERN_ERR PREFIX "Invalid argument 2\n");
890 return -EINVAL;
891 }
892
893 if (sscanf(arg, "%d:%d:%d:%d", &event, &method_type, &type, &value) !=
894 4) {
895 kfree(arg);
896 printk(KERN_ERR PREFIX "Invalid argument 3\n");
897 return -EINVAL;
898 }
899 kfree(arg);
900 if (type == ACPI_TYPE_INTEGER) {
901 key = get_hotkey_by_event(hotkey_list, event);
902 if (!key)
903 goto do_fail;
904 if (IS_EVENT(event))
905 write_acpi_int(key->event_hotkey.action_handle,
906 key->event_hotkey.action_method, value,
907 NULL);
908 else if (IS_POLL(event)) {
909 if (method_type == POLL_METHOD)
910 read_acpi_int(key->poll_hotkey.poll_handle,
911 key->poll_hotkey.poll_method,
912 key->poll_hotkey.poll_result);
913 else if (method_type == ACTION_METHOD)
914 write_acpi_int(key->poll_hotkey.action_handle,
915 key->poll_hotkey.action_method,
916 value, NULL);
917 else
918 goto do_fail;
919
920 }
921 } else {
922 printk(KERN_WARNING "Not supported\n");
923 return -EINVAL;
924 }
925 return count;
926 do_fail:
927 return -EINVAL;
928
929}
930
931static int __init hotkey_init(void)
932{
933 int result;
934 mode_t mode = S_IFREG | S_IRUGO | S_IWUGO;
935
936
937 if (acpi_disabled)
938 return -ENODEV;
939
940 if (acpi_specific_hotkey_enabled) {
941 printk("Using specific hotkey driver\n");
942 return -ENODEV;
943 }
944
945 hotkey_proc_dir = proc_mkdir(HOTKEY_PROC, acpi_root_dir);
946 if (!hotkey_proc_dir) {
947 return (-ENODEV);
948 }
949 hotkey_proc_dir->owner = THIS_MODULE;
950
951 hotkey_config =
952 create_proc_entry(HOTKEY_EV_CONFIG, mode, hotkey_proc_dir);
953 if (!hotkey_config) {
954 goto do_fail1;
955 } else {
956 hotkey_config->proc_fops = &hotkey_config_fops;
957 hotkey_config->data = &global_hotkey_list;
958 hotkey_config->owner = THIS_MODULE;
959 hotkey_config->uid = 0;
960 hotkey_config->gid = 0;
961 }
962
963 hotkey_poll_config =
964 create_proc_entry(HOTKEY_PL_CONFIG, mode, hotkey_proc_dir);
965 if (!hotkey_poll_config) {
966 goto do_fail2;
967 } else {
968 hotkey_poll_config->proc_fops = &hotkey_poll_config_fops;
969 hotkey_poll_config->data = &global_hotkey_list;
970 hotkey_poll_config->owner = THIS_MODULE;
971 hotkey_poll_config->uid = 0;
972 hotkey_poll_config->gid = 0;
973 }
974
975 hotkey_action = create_proc_entry(HOTKEY_ACTION, mode, hotkey_proc_dir);
976 if (!hotkey_action) {
977 goto do_fail3;
978 } else {
979 hotkey_action->proc_fops = &hotkey_action_fops;
980 hotkey_action->owner = THIS_MODULE;
981 hotkey_action->uid = 0;
982 hotkey_action->gid = 0;
983 }
984
985 hotkey_info = create_proc_entry(HOTKEY_INFO, mode, hotkey_proc_dir);
986 if (!hotkey_info) {
987 goto do_fail4;
988 } else {
989 hotkey_info->proc_fops = &hotkey_info_fops;
990 hotkey_info->owner = THIS_MODULE;
991 hotkey_info->uid = 0;
992 hotkey_info->gid = 0;
993 }
994
995 result = acpi_bus_register_driver(&hotkey_driver);
996 if (result < 0)
997 goto do_fail5;
998 global_hotkey_list.count = 0;
999 global_hotkey_list.entries = &hotkey_entries;
1000
1001 INIT_LIST_HEAD(&hotkey_entries);
1002
1003 return (0);
1004
1005 do_fail5:
1006 remove_proc_entry(HOTKEY_INFO, hotkey_proc_dir);
1007 do_fail4:
1008 remove_proc_entry(HOTKEY_ACTION, hotkey_proc_dir);
1009 do_fail3:
1010 remove_proc_entry(HOTKEY_PL_CONFIG, hotkey_proc_dir);
1011 do_fail2:
1012 remove_proc_entry(HOTKEY_EV_CONFIG, hotkey_proc_dir);
1013 do_fail1:
1014 remove_proc_entry(HOTKEY_PROC, acpi_root_dir);
1015 return (-ENODEV);
1016}
1017
1018static void __exit hotkey_exit(void)
1019{
1020 struct list_head *entries, *next;
1021
1022
1023 list_for_each_safe(entries, next, global_hotkey_list.entries) {
1024 union acpi_hotkey *key =
1025 container_of(entries, union acpi_hotkey, entries);
1026
1027 acpi_os_wait_events_complete(NULL);
1028 list_del(&key->link.entries);
1029 global_hotkey_list.count--;
1030 free_hotkey_device(key);
1031 }
1032 acpi_bus_unregister_driver(&hotkey_driver);
1033 remove_proc_entry(HOTKEY_EV_CONFIG, hotkey_proc_dir);
1034 remove_proc_entry(HOTKEY_PL_CONFIG, hotkey_proc_dir);
1035 remove_proc_entry(HOTKEY_ACTION, hotkey_proc_dir);
1036 remove_proc_entry(HOTKEY_INFO, hotkey_proc_dir);
1037 remove_proc_entry(HOTKEY_PROC, acpi_root_dir);
1038 return;
1039}
1040
1041module_init(hotkey_init);
1042module_exit(hotkey_exit);
diff --git a/drivers/acpi/i2c_ec.c b/drivers/acpi/i2c_ec.c
index 76ec8b63e69f..acab4a481897 100644
--- a/drivers/acpi/i2c_ec.c
+++ b/drivers/acpi/i2c_ec.c
@@ -27,18 +27,17 @@
27#define ACPI_EC_HC_COMPONENT 0x00080000 27#define ACPI_EC_HC_COMPONENT 0x00080000
28#define ACPI_EC_HC_CLASS "ec_hc_smbus" 28#define ACPI_EC_HC_CLASS "ec_hc_smbus"
29#define ACPI_EC_HC_HID "ACPI0001" 29#define ACPI_EC_HC_HID "ACPI0001"
30#define ACPI_EC_HC_DRIVER_NAME "ACPI EC HC smbus driver"
31#define ACPI_EC_HC_DEVICE_NAME "EC HC smbus" 30#define ACPI_EC_HC_DEVICE_NAME "EC HC smbus"
32 31
33#define _COMPONENT ACPI_EC_HC_COMPONENT 32#define _COMPONENT ACPI_EC_HC_COMPONENT
34 33
35ACPI_MODULE_NAME("acpi_smbus") 34ACPI_MODULE_NAME("i2c_ec");
36 35
37static int acpi_ec_hc_add(struct acpi_device *device); 36static int acpi_ec_hc_add(struct acpi_device *device);
38static int acpi_ec_hc_remove(struct acpi_device *device, int type); 37static int acpi_ec_hc_remove(struct acpi_device *device, int type);
39 38
40static struct acpi_driver acpi_ec_hc_driver = { 39static struct acpi_driver acpi_ec_hc_driver = {
41 .name = ACPI_EC_HC_DRIVER_NAME, 40 .name = "i2c_ec",
42 .class = ACPI_EC_HC_CLASS, 41 .class = ACPI_EC_HC_CLASS,
43 .ids = ACPI_EC_HC_HID, 42 .ids = ACPI_EC_HC_HID,
44 .ops = { 43 .ops = {
diff --git a/drivers/acpi/ibm_acpi.c b/drivers/acpi/ibm_acpi.c
index c6144ca66638..1a0ed3dc409c 100644
--- a/drivers/acpi/ibm_acpi.c
+++ b/drivers/acpi/ibm_acpi.c
@@ -496,6 +496,10 @@ static int ibm_acpi_driver_init(void)
496 printk(IBM_INFO "%s v%s\n", IBM_DESC, IBM_VERSION); 496 printk(IBM_INFO "%s v%s\n", IBM_DESC, IBM_VERSION);
497 printk(IBM_INFO "%s\n", IBM_URL); 497 printk(IBM_INFO "%s\n", IBM_URL);
498 498
499 if (ibm_thinkpad_ec_found)
500 printk(IBM_INFO "ThinkPad EC firmware %s\n",
501 ibm_thinkpad_ec_found);
502
499 return 0; 503 return 0;
500} 504}
501 505
@@ -2617,7 +2621,7 @@ static void __init ibm_handle_init(char *name,
2617 ibm_handle_init(#object, &object##_handle, *object##_parent, \ 2621 ibm_handle_init(#object, &object##_handle, *object##_parent, \
2618 object##_paths, ARRAY_SIZE(object##_paths), &object##_path) 2622 object##_paths, ARRAY_SIZE(object##_paths), &object##_path)
2619 2623
2620static int set_ibm_param(const char *val, struct kernel_param *kp) 2624static int __init set_ibm_param(const char *val, struct kernel_param *kp)
2621{ 2625{
2622 unsigned int i; 2626 unsigned int i;
2623 2627
@@ -2659,7 +2663,8 @@ static void acpi_ibm_exit(void)
2659 for (i = ARRAY_SIZE(ibms) - 1; i >= 0; i--) 2663 for (i = ARRAY_SIZE(ibms) - 1; i >= 0; i--)
2660 ibm_exit(&ibms[i]); 2664 ibm_exit(&ibms[i]);
2661 2665
2662 remove_proc_entry(IBM_DIR, acpi_root_dir); 2666 if (proc_dir)
2667 remove_proc_entry(IBM_DIR, acpi_root_dir);
2663 2668
2664 if (ibm_thinkpad_ec_found) 2669 if (ibm_thinkpad_ec_found)
2665 kfree(ibm_thinkpad_ec_found); 2670 kfree(ibm_thinkpad_ec_found);
@@ -2696,11 +2701,6 @@ static int __init acpi_ibm_init(void)
2696 if (acpi_disabled) 2701 if (acpi_disabled)
2697 return -ENODEV; 2702 return -ENODEV;
2698 2703
2699 if (!acpi_specific_hotkey_enabled) {
2700 printk(IBM_ERR "using generic hotkey driver\n");
2701 return -ENODEV;
2702 }
2703
2704 /* ec is required because many other handles are relative to it */ 2704 /* ec is required because many other handles are relative to it */
2705 IBM_HANDLE_INIT(ec); 2705 IBM_HANDLE_INIT(ec);
2706 if (!ec_handle) { 2706 if (!ec_handle) {
@@ -2710,9 +2710,6 @@ static int __init acpi_ibm_init(void)
2710 2710
2711 /* Models with newer firmware report the EC in DMI */ 2711 /* Models with newer firmware report the EC in DMI */
2712 ibm_thinkpad_ec_found = check_dmi_for_ec(); 2712 ibm_thinkpad_ec_found = check_dmi_for_ec();
2713 if (ibm_thinkpad_ec_found)
2714 printk(IBM_INFO "ThinkPad EC firmware %s\n",
2715 ibm_thinkpad_ec_found);
2716 2713
2717 /* these handles are not required */ 2714 /* these handles are not required */
2718 IBM_HANDLE_INIT(vid); 2715 IBM_HANDLE_INIT(vid);
@@ -2742,6 +2739,7 @@ static int __init acpi_ibm_init(void)
2742 proc_dir = proc_mkdir(IBM_DIR, acpi_root_dir); 2739 proc_dir = proc_mkdir(IBM_DIR, acpi_root_dir);
2743 if (!proc_dir) { 2740 if (!proc_dir) {
2744 printk(IBM_ERR "unable to create proc dir %s", IBM_DIR); 2741 printk(IBM_ERR "unable to create proc dir %s", IBM_DIR);
2742 acpi_ibm_exit();
2745 return -ENODEV; 2743 return -ENODEV;
2746 } 2744 }
2747 proc_dir->owner = THIS_MODULE; 2745 proc_dir->owner = THIS_MODULE;
diff --git a/drivers/acpi/numa.c b/drivers/acpi/numa.c
index 4a9faff4c01d..8fcd6a15517f 100644
--- a/drivers/acpi/numa.c
+++ b/drivers/acpi/numa.c
@@ -33,7 +33,7 @@
33 33
34#define ACPI_NUMA 0x80000000 34#define ACPI_NUMA 0x80000000
35#define _COMPONENT ACPI_NUMA 35#define _COMPONENT ACPI_NUMA
36ACPI_MODULE_NAME("numa") 36ACPI_MODULE_NAME("numa");
37 37
38static nodemask_t nodes_found_map = NODE_MASK_NONE; 38static nodemask_t nodes_found_map = NODE_MASK_NONE;
39#define PXM_INVAL -1 39#define PXM_INVAL -1
@@ -45,12 +45,6 @@ int __cpuinitdata pxm_to_node_map[MAX_PXM_DOMAINS]
45int __cpuinitdata node_to_pxm_map[MAX_NUMNODES] 45int __cpuinitdata node_to_pxm_map[MAX_NUMNODES]
46 = { [0 ... MAX_NUMNODES - 1] = PXM_INVAL }; 46 = { [0 ... MAX_NUMNODES - 1] = PXM_INVAL };
47 47
48extern int __init acpi_table_parse_madt_family(char *id,
49 unsigned long madt_size,
50 int entry_id,
51 acpi_madt_entry_handler handler,
52 unsigned int max_entries);
53
54int __cpuinit pxm_to_node(int pxm) 48int __cpuinit pxm_to_node(int pxm)
55{ 49{
56 if (pxm < 0) 50 if (pxm < 0)
@@ -208,9 +202,9 @@ static int __init acpi_parse_srat(struct acpi_table_header *table)
208 202
209int __init 203int __init
210acpi_table_parse_srat(enum acpi_srat_type id, 204acpi_table_parse_srat(enum acpi_srat_type id,
211 acpi_madt_entry_handler handler, unsigned int max_entries) 205 acpi_table_entry_handler handler, unsigned int max_entries)
212{ 206{
213 return acpi_table_parse_madt_family(ACPI_SIG_SRAT, 207 return acpi_table_parse_entries(ACPI_SIG_SRAT,
214 sizeof(struct acpi_table_srat), id, 208 sizeof(struct acpi_table_srat), id,
215 handler, max_entries); 209 handler, max_entries);
216} 210}
@@ -220,9 +214,7 @@ int __init acpi_numa_init(void)
220 int result; 214 int result;
221 215
222 /* SRAT: Static Resource Affinity Table */ 216 /* SRAT: Static Resource Affinity Table */
223 result = acpi_table_parse(ACPI_SIG_SRAT, acpi_parse_srat); 217 if (!acpi_table_parse(ACPI_SIG_SRAT, acpi_parse_srat)) {
224
225 if (result > 0) {
226 result = acpi_table_parse_srat(ACPI_SRAT_TYPE_CPU_AFFINITY, 218 result = acpi_table_parse_srat(ACPI_SRAT_TYPE_CPU_AFFINITY,
227 acpi_parse_processor_affinity, 219 acpi_parse_processor_affinity,
228 NR_CPUS); 220 NR_CPUS);
@@ -230,7 +222,7 @@ int __init acpi_numa_init(void)
230 } 222 }
231 223
232 /* SLIT: System Locality Information Table */ 224 /* SLIT: System Locality Information Table */
233 result = acpi_table_parse(ACPI_SIG_SLIT, acpi_parse_slit); 225 acpi_table_parse(ACPI_SIG_SLIT, acpi_parse_slit);
234 226
235 acpi_numa_arch_fixup(); 227 acpi_numa_arch_fixup();
236 return 0; 228 return 0;
diff --git a/drivers/acpi/osl.c b/drivers/acpi/osl.c
index 0f6f3bcbc8eb..971eca4864fa 100644
--- a/drivers/acpi/osl.c
+++ b/drivers/acpi/osl.c
@@ -46,7 +46,7 @@
46#include <linux/efi.h> 46#include <linux/efi.h>
47 47
48#define _COMPONENT ACPI_OS_SERVICES 48#define _COMPONENT ACPI_OS_SERVICES
49ACPI_MODULE_NAME("osl") 49ACPI_MODULE_NAME("osl");
50#define PREFIX "ACPI: " 50#define PREFIX "ACPI: "
51struct acpi_os_dpc { 51struct acpi_os_dpc {
52 acpi_osd_exec_callback function; 52 acpi_osd_exec_callback function;
@@ -68,9 +68,6 @@ EXPORT_SYMBOL(acpi_in_debugger);
68extern char line_buf[80]; 68extern char line_buf[80];
69#endif /*ENABLE_DEBUGGER */ 69#endif /*ENABLE_DEBUGGER */
70 70
71int acpi_specific_hotkey_enabled = TRUE;
72EXPORT_SYMBOL(acpi_specific_hotkey_enabled);
73
74static unsigned int acpi_irq_irq; 71static unsigned int acpi_irq_irq;
75static acpi_osd_handler acpi_irq_handler; 72static acpi_osd_handler acpi_irq_handler;
76static void *acpi_irq_context; 73static void *acpi_irq_context;
@@ -205,7 +202,7 @@ void __iomem *acpi_os_map_memory(acpi_physical_address phys, acpi_size size)
205{ 202{
206 if (phys > ULONG_MAX) { 203 if (phys > ULONG_MAX) {
207 printk(KERN_ERR PREFIX "Cannot map memory that high\n"); 204 printk(KERN_ERR PREFIX "Cannot map memory that high\n");
208 return 0; 205 return NULL;
209 } 206 }
210 if (acpi_gbl_permanent_mmap) 207 if (acpi_gbl_permanent_mmap)
211 /* 208 /*
@@ -890,26 +887,6 @@ u32 acpi_os_get_line(char *buffer)
890} 887}
891#endif /* ACPI_FUTURE_USAGE */ 888#endif /* ACPI_FUTURE_USAGE */
892 889
893/* Assumes no unreadable holes inbetween */
894u8 acpi_os_readable(void *ptr, acpi_size len)
895{
896#if defined(__i386__) || defined(__x86_64__)
897 char tmp;
898 return !__get_user(tmp, (char __user *)ptr)
899 && !__get_user(tmp, (char __user *)ptr + len - 1);
900#endif
901 return 1;
902}
903
904#ifdef ACPI_FUTURE_USAGE
905u8 acpi_os_writable(void *ptr, acpi_size len)
906{
907 /* could do dummy write (racy) or a kernel page table lookup.
908 The later may be difficult at early boot when kmap doesn't work yet. */
909 return 1;
910}
911#endif
912
913acpi_status acpi_os_signal(u32 function, void *info) 890acpi_status acpi_os_signal(u32 function, void *info)
914{ 891{
915 switch (function) { 892 switch (function) {
@@ -1012,14 +989,6 @@ static int __init acpi_wake_gpes_always_on_setup(char *str)
1012 989
1013__setup("acpi_wake_gpes_always_on", acpi_wake_gpes_always_on_setup); 990__setup("acpi_wake_gpes_always_on", acpi_wake_gpes_always_on_setup);
1014 991
1015static int __init acpi_hotkey_setup(char *str)
1016{
1017 acpi_specific_hotkey_enabled = FALSE;
1018 return 1;
1019}
1020
1021__setup("acpi_generic_hotkey", acpi_hotkey_setup);
1022
1023/* 992/*
1024 * max_cstate is defined in the base kernel so modules can 993 * max_cstate is defined in the base kernel so modules can
1025 * change it w/o depending on the state of the processor module. 994 * change it w/o depending on the state of the processor module.
diff --git a/drivers/acpi/pci_bind.c b/drivers/acpi/pci_bind.c
index 55f57a61c55e..028969370bbf 100644
--- a/drivers/acpi/pci_bind.c
+++ b/drivers/acpi/pci_bind.c
@@ -36,7 +36,7 @@
36#include <acpi/acpi_drivers.h> 36#include <acpi/acpi_drivers.h>
37 37
38#define _COMPONENT ACPI_PCI_COMPONENT 38#define _COMPONENT ACPI_PCI_COMPONENT
39ACPI_MODULE_NAME("pci_bind") 39ACPI_MODULE_NAME("pci_bind");
40 40
41struct acpi_pci_data { 41struct acpi_pci_data {
42 struct acpi_pci_id id; 42 struct acpi_pci_id id;
diff --git a/drivers/acpi/pci_irq.c b/drivers/acpi/pci_irq.c
index fe7d007833ad..dd3186abe07a 100644
--- a/drivers/acpi/pci_irq.c
+++ b/drivers/acpi/pci_irq.c
@@ -38,7 +38,7 @@
38#include <acpi/acpi_drivers.h> 38#include <acpi/acpi_drivers.h>
39 39
40#define _COMPONENT ACPI_PCI_COMPONENT 40#define _COMPONENT ACPI_PCI_COMPONENT
41ACPI_MODULE_NAME("pci_irq") 41ACPI_MODULE_NAME("pci_irq");
42 42
43static struct acpi_prt_list acpi_prt; 43static struct acpi_prt_list acpi_prt;
44static DEFINE_SPINLOCK(acpi_prt_lock); 44static DEFINE_SPINLOCK(acpi_prt_lock);
diff --git a/drivers/acpi/pci_link.c b/drivers/acpi/pci_link.c
index 0f683c8c6fbc..acc594771379 100644
--- a/drivers/acpi/pci_link.c
+++ b/drivers/acpi/pci_link.c
@@ -44,10 +44,9 @@
44#include <acpi/acpi_drivers.h> 44#include <acpi/acpi_drivers.h>
45 45
46#define _COMPONENT ACPI_PCI_COMPONENT 46#define _COMPONENT ACPI_PCI_COMPONENT
47ACPI_MODULE_NAME("pci_link") 47ACPI_MODULE_NAME("pci_link");
48#define ACPI_PCI_LINK_CLASS "pci_irq_routing" 48#define ACPI_PCI_LINK_CLASS "pci_irq_routing"
49#define ACPI_PCI_LINK_HID "PNP0C0F" 49#define ACPI_PCI_LINK_HID "PNP0C0F"
50#define ACPI_PCI_LINK_DRIVER_NAME "ACPI PCI Interrupt Link Driver"
51#define ACPI_PCI_LINK_DEVICE_NAME "PCI Interrupt Link" 50#define ACPI_PCI_LINK_DEVICE_NAME "PCI Interrupt Link"
52#define ACPI_PCI_LINK_FILE_INFO "info" 51#define ACPI_PCI_LINK_FILE_INFO "info"
53#define ACPI_PCI_LINK_FILE_STATUS "state" 52#define ACPI_PCI_LINK_FILE_STATUS "state"
@@ -56,7 +55,7 @@ static int acpi_pci_link_add(struct acpi_device *device);
56static int acpi_pci_link_remove(struct acpi_device *device, int type); 55static int acpi_pci_link_remove(struct acpi_device *device, int type);
57 56
58static struct acpi_driver acpi_pci_link_driver = { 57static struct acpi_driver acpi_pci_link_driver = {
59 .name = ACPI_PCI_LINK_DRIVER_NAME, 58 .name = "pci_link",
60 .class = ACPI_PCI_LINK_CLASS, 59 .class = ACPI_PCI_LINK_CLASS,
61 .ids = ACPI_PCI_LINK_HID, 60 .ids = ACPI_PCI_LINK_HID,
62 .ops = { 61 .ops = {
diff --git a/drivers/acpi/pci_root.c b/drivers/acpi/pci_root.c
index 4ecf701687e8..ad4145a37786 100644
--- a/drivers/acpi/pci_root.c
+++ b/drivers/acpi/pci_root.c
@@ -36,17 +36,16 @@
36#include <acpi/acpi_drivers.h> 36#include <acpi/acpi_drivers.h>
37 37
38#define _COMPONENT ACPI_PCI_COMPONENT 38#define _COMPONENT ACPI_PCI_COMPONENT
39ACPI_MODULE_NAME("pci_root") 39ACPI_MODULE_NAME("pci_root");
40#define ACPI_PCI_ROOT_CLASS "pci_bridge" 40#define ACPI_PCI_ROOT_CLASS "pci_bridge"
41#define ACPI_PCI_ROOT_HID "PNP0A03" 41#define ACPI_PCI_ROOT_HID "PNP0A03"
42#define ACPI_PCI_ROOT_DRIVER_NAME "ACPI PCI Root Bridge Driver"
43#define ACPI_PCI_ROOT_DEVICE_NAME "PCI Root Bridge" 42#define ACPI_PCI_ROOT_DEVICE_NAME "PCI Root Bridge"
44static int acpi_pci_root_add(struct acpi_device *device); 43static int acpi_pci_root_add(struct acpi_device *device);
45static int acpi_pci_root_remove(struct acpi_device *device, int type); 44static int acpi_pci_root_remove(struct acpi_device *device, int type);
46static int acpi_pci_root_start(struct acpi_device *device); 45static int acpi_pci_root_start(struct acpi_device *device);
47 46
48static struct acpi_driver acpi_pci_root_driver = { 47static struct acpi_driver acpi_pci_root_driver = {
49 .name = ACPI_PCI_ROOT_DRIVER_NAME, 48 .name = "pci_root",
50 .class = ACPI_PCI_ROOT_CLASS, 49 .class = ACPI_PCI_ROOT_CLASS,
51 .ids = ACPI_PCI_ROOT_HID, 50 .ids = ACPI_PCI_ROOT_HID,
52 .ops = { 51 .ops = {
diff --git a/drivers/acpi/power.c b/drivers/acpi/power.c
index 0ba7dfbbb2ee..1ef338545dfe 100644
--- a/drivers/acpi/power.c
+++ b/drivers/acpi/power.c
@@ -45,10 +45,9 @@
45#include <acpi/acpi_drivers.h> 45#include <acpi/acpi_drivers.h>
46 46
47#define _COMPONENT ACPI_POWER_COMPONENT 47#define _COMPONENT ACPI_POWER_COMPONENT
48ACPI_MODULE_NAME("acpi_power") 48ACPI_MODULE_NAME("power");
49#define ACPI_POWER_COMPONENT 0x00800000 49#define ACPI_POWER_COMPONENT 0x00800000
50#define ACPI_POWER_CLASS "power_resource" 50#define ACPI_POWER_CLASS "power_resource"
51#define ACPI_POWER_DRIVER_NAME "ACPI Power Resource Driver"
52#define ACPI_POWER_DEVICE_NAME "Power Resource" 51#define ACPI_POWER_DEVICE_NAME "Power Resource"
53#define ACPI_POWER_FILE_INFO "info" 52#define ACPI_POWER_FILE_INFO "info"
54#define ACPI_POWER_FILE_STATUS "state" 53#define ACPI_POWER_FILE_STATUS "state"
@@ -57,25 +56,33 @@ ACPI_MODULE_NAME("acpi_power")
57#define ACPI_POWER_RESOURCE_STATE_UNKNOWN 0xFF 56#define ACPI_POWER_RESOURCE_STATE_UNKNOWN 0xFF
58static int acpi_power_add(struct acpi_device *device); 57static int acpi_power_add(struct acpi_device *device);
59static int acpi_power_remove(struct acpi_device *device, int type); 58static int acpi_power_remove(struct acpi_device *device, int type);
59static int acpi_power_resume(struct acpi_device *device);
60static int acpi_power_open_fs(struct inode *inode, struct file *file); 60static int acpi_power_open_fs(struct inode *inode, struct file *file);
61 61
62static struct acpi_driver acpi_power_driver = { 62static struct acpi_driver acpi_power_driver = {
63 .name = ACPI_POWER_DRIVER_NAME, 63 .name = "power",
64 .class = ACPI_POWER_CLASS, 64 .class = ACPI_POWER_CLASS,
65 .ids = ACPI_POWER_HID, 65 .ids = ACPI_POWER_HID,
66 .ops = { 66 .ops = {
67 .add = acpi_power_add, 67 .add = acpi_power_add,
68 .remove = acpi_power_remove, 68 .remove = acpi_power_remove,
69 .resume = acpi_power_resume,
69 }, 70 },
70}; 71};
71 72
73struct acpi_power_reference {
74 struct list_head node;
75 struct acpi_device *device;
76};
77
72struct acpi_power_resource { 78struct acpi_power_resource {
73 struct acpi_device * device; 79 struct acpi_device * device;
74 acpi_bus_id name; 80 acpi_bus_id name;
75 u32 system_level; 81 u32 system_level;
76 u32 order; 82 u32 order;
77 int state; 83 int state;
78 int references; 84 struct mutex resource_lock;
85 struct list_head reference;
79}; 86};
80 87
81static struct list_head acpi_power_resource_list; 88static struct list_head acpi_power_resource_list;
@@ -171,22 +178,47 @@ static int acpi_power_get_list_state(struct acpi_handle_list *list, int *state)
171 return result; 178 return result;
172} 179}
173 180
174static int acpi_power_on(acpi_handle handle) 181static int acpi_power_on(acpi_handle handle, struct acpi_device *dev)
175{ 182{
176 int result = 0; 183 int result = 0;
184 int found = 0;
177 acpi_status status = AE_OK; 185 acpi_status status = AE_OK;
178 struct acpi_device *device = NULL;
179 struct acpi_power_resource *resource = NULL; 186 struct acpi_power_resource *resource = NULL;
187 struct list_head *node, *next;
188 struct acpi_power_reference *ref;
180 189
181 190
182 result = acpi_power_get_context(handle, &resource); 191 result = acpi_power_get_context(handle, &resource);
183 if (result) 192 if (result)
184 return result; 193 return result;
185 194
186 resource->references++; 195 mutex_lock(&resource->resource_lock);
196 list_for_each_safe(node, next, &resource->reference) {
197 ref = container_of(node, struct acpi_power_reference, node);
198 if (dev->handle == ref->device->handle) {
199 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] already referenced by resource [%s]\n",
200 dev->pnp.bus_id, resource->name));
201 found = 1;
202 break;
203 }
204 }
205
206 if (!found) {
207 ref = kmalloc(sizeof (struct acpi_power_reference),
208 irqs_disabled() ? GFP_ATOMIC : GFP_KERNEL);
209 if (!ref) {
210 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "kmalloc() failed\n"));
211 mutex_unlock(&resource->resource_lock);
212 return -ENOMEM;
213 }
214 list_add_tail(&ref->node, &resource->reference);
215 ref->device = dev;
216 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] added to resource [%s] references\n",
217 dev->pnp.bus_id, resource->name));
218 }
219 mutex_unlock(&resource->resource_lock);
187 220
188 if ((resource->references > 1) 221 if (resource->state == ACPI_POWER_RESOURCE_STATE_ON) {
189 || (resource->state == ACPI_POWER_RESOURCE_STATE_ON)) {
190 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Resource [%s] already on\n", 222 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Resource [%s] already on\n",
191 resource->name)); 223 resource->name));
192 return 0; 224 return 0;
@@ -203,38 +235,49 @@ static int acpi_power_on(acpi_handle handle)
203 return -ENOEXEC; 235 return -ENOEXEC;
204 236
205 /* Update the power resource's _device_ power state */ 237 /* Update the power resource's _device_ power state */
206 device = resource->device;
207 resource->device->power.state = ACPI_STATE_D0; 238 resource->device->power.state = ACPI_STATE_D0;
208 239
209 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Resource [%s] turned on\n", 240 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Resource [%s] turned on\n",
210 resource->name)); 241 resource->name));
211
212 return 0; 242 return 0;
213} 243}
214 244
215static int acpi_power_off_device(acpi_handle handle) 245static int acpi_power_off_device(acpi_handle handle, struct acpi_device *dev)
216{ 246{
217 int result = 0; 247 int result = 0;
218 acpi_status status = AE_OK; 248 acpi_status status = AE_OK;
219 struct acpi_power_resource *resource = NULL; 249 struct acpi_power_resource *resource = NULL;
250 struct list_head *node, *next;
251 struct acpi_power_reference *ref;
252
220 253
221 result = acpi_power_get_context(handle, &resource); 254 result = acpi_power_get_context(handle, &resource);
222 if (result) 255 if (result)
223 return result; 256 return result;
224 257
225 if (resource->references) 258 mutex_lock(&resource->resource_lock);
226 resource->references--; 259 list_for_each_safe(node, next, &resource->reference) {
260 ref = container_of(node, struct acpi_power_reference, node);
261 if (dev->handle == ref->device->handle) {
262 list_del(&ref->node);
263 kfree(ref);
264 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] removed from resource [%s] references\n",
265 dev->pnp.bus_id, resource->name));
266 break;
267 }
268 }
227 269
228 if (resource->references) { 270 if (!list_empty(&resource->reference)) {
229 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 271 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Cannot turn resource [%s] off - resource is in use\n",
230 "Resource [%s] is still in use, dereferencing\n", 272 resource->name));
231 resource->device->pnp.bus_id)); 273 mutex_unlock(&resource->resource_lock);
232 return 0; 274 return 0;
233 } 275 }
276 mutex_unlock(&resource->resource_lock);
234 277
235 if (resource->state == ACPI_POWER_RESOURCE_STATE_OFF) { 278 if (resource->state == ACPI_POWER_RESOURCE_STATE_OFF) {
236 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Resource [%s] already off\n", 279 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Resource [%s] already off\n",
237 resource->device->pnp.bus_id)); 280 resource->name));
238 return 0; 281 return 0;
239 } 282 }
240 283
@@ -276,7 +319,7 @@ int acpi_enable_wakeup_device_power(struct acpi_device *dev)
276 arg.integer.value = 1; 319 arg.integer.value = 1;
277 /* Open power resource */ 320 /* Open power resource */
278 for (i = 0; i < dev->wakeup.resources.count; i++) { 321 for (i = 0; i < dev->wakeup.resources.count; i++) {
279 ret = acpi_power_on(dev->wakeup.resources.handles[i]); 322 ret = acpi_power_on(dev->wakeup.resources.handles[i], dev);
280 if (ret) { 323 if (ret) {
281 printk(KERN_ERR PREFIX "Transition power state\n"); 324 printk(KERN_ERR PREFIX "Transition power state\n");
282 dev->wakeup.flags.valid = 0; 325 dev->wakeup.flags.valid = 0;
@@ -323,7 +366,7 @@ int acpi_disable_wakeup_device_power(struct acpi_device *dev)
323 366
324 /* Close power resource */ 367 /* Close power resource */
325 for (i = 0; i < dev->wakeup.resources.count; i++) { 368 for (i = 0; i < dev->wakeup.resources.count; i++) {
326 ret = acpi_power_off_device(dev->wakeup.resources.handles[i]); 369 ret = acpi_power_off_device(dev->wakeup.resources.handles[i], dev);
327 if (ret) { 370 if (ret) {
328 printk(KERN_ERR PREFIX "Transition power state\n"); 371 printk(KERN_ERR PREFIX "Transition power state\n");
329 dev->wakeup.flags.valid = 0; 372 dev->wakeup.flags.valid = 0;
@@ -407,16 +450,20 @@ int acpi_power_transition(struct acpi_device *device, int state)
407 * (e.g. so the device doesn't lose power while transitioning). 450 * (e.g. so the device doesn't lose power while transitioning).
408 */ 451 */
409 for (i = 0; i < tl->count; i++) { 452 for (i = 0; i < tl->count; i++) {
410 result = acpi_power_on(tl->handles[i]); 453 result = acpi_power_on(tl->handles[i], device);
411 if (result) 454 if (result)
412 goto end; 455 goto end;
413 } 456 }
414 457
458 if (device->power.state == state) {
459 goto end;
460 }
461
415 /* 462 /*
416 * Then we dereference all power resources used in the current list. 463 * Then we dereference all power resources used in the current list.
417 */ 464 */
418 for (i = 0; i < cl->count; i++) { 465 for (i = 0; i < cl->count; i++) {
419 result = acpi_power_off_device(cl->handles[i]); 466 result = acpi_power_off_device(cl->handles[i], device);
420 if (result) 467 if (result)
421 goto end; 468 goto end;
422 } 469 }
@@ -439,7 +486,11 @@ static struct proc_dir_entry *acpi_power_dir;
439 486
440static int acpi_power_seq_show(struct seq_file *seq, void *offset) 487static int acpi_power_seq_show(struct seq_file *seq, void *offset)
441{ 488{
489 int count = 0;
490 int result = 0;
442 struct acpi_power_resource *resource = NULL; 491 struct acpi_power_resource *resource = NULL;
492 struct list_head *node, *next;
493 struct acpi_power_reference *ref;
443 494
444 495
445 resource = seq->private; 496 resource = seq->private;
@@ -447,6 +498,10 @@ static int acpi_power_seq_show(struct seq_file *seq, void *offset)
447 if (!resource) 498 if (!resource)
448 goto end; 499 goto end;
449 500
501 result = acpi_power_get_state(resource);
502 if (result)
503 goto end;
504
450 seq_puts(seq, "state: "); 505 seq_puts(seq, "state: ");
451 switch (resource->state) { 506 switch (resource->state) {
452 case ACPI_POWER_RESOURCE_STATE_ON: 507 case ACPI_POWER_RESOURCE_STATE_ON:
@@ -460,11 +515,18 @@ static int acpi_power_seq_show(struct seq_file *seq, void *offset)
460 break; 515 break;
461 } 516 }
462 517
518 mutex_lock(&resource->resource_lock);
519 list_for_each_safe(node, next, &resource->reference) {
520 ref = container_of(node, struct acpi_power_reference, node);
521 count++;
522 }
523 mutex_unlock(&resource->resource_lock);
524
463 seq_printf(seq, "system level: S%d\n" 525 seq_printf(seq, "system level: S%d\n"
464 "order: %d\n" 526 "order: %d\n"
465 "reference count: %d\n", 527 "reference count: %d\n",
466 resource->system_level, 528 resource->system_level,
467 resource->order, resource->references); 529 resource->order, count);
468 530
469 end: 531 end:
470 return 0; 532 return 0;
@@ -537,6 +599,8 @@ static int acpi_power_add(struct acpi_device *device)
537 return -ENOMEM; 599 return -ENOMEM;
538 600
539 resource->device = device; 601 resource->device = device;
602 mutex_init(&resource->resource_lock);
603 INIT_LIST_HEAD(&resource->reference);
540 strcpy(resource->name, device->pnp.bus_id); 604 strcpy(resource->name, device->pnp.bus_id);
541 strcpy(acpi_device_name(device), ACPI_POWER_DEVICE_NAME); 605 strcpy(acpi_device_name(device), ACPI_POWER_DEVICE_NAME);
542 strcpy(acpi_device_class(device), ACPI_POWER_CLASS); 606 strcpy(acpi_device_class(device), ACPI_POWER_CLASS);
@@ -584,6 +648,7 @@ static int acpi_power_add(struct acpi_device *device)
584static int acpi_power_remove(struct acpi_device *device, int type) 648static int acpi_power_remove(struct acpi_device *device, int type)
585{ 649{
586 struct acpi_power_resource *resource = NULL; 650 struct acpi_power_resource *resource = NULL;
651 struct list_head *node, *next;
587 652
588 653
589 if (!device || !acpi_driver_data(device)) 654 if (!device || !acpi_driver_data(device))
@@ -593,11 +658,54 @@ static int acpi_power_remove(struct acpi_device *device, int type)
593 658
594 acpi_power_remove_fs(device); 659 acpi_power_remove_fs(device);
595 660
661 mutex_lock(&resource->resource_lock);
662 list_for_each_safe(node, next, &resource->reference) {
663 struct acpi_power_reference *ref = container_of(node, struct acpi_power_reference, node);
664 list_del(&ref->node);
665 kfree(ref);
666 }
667 mutex_unlock(&resource->resource_lock);
668
596 kfree(resource); 669 kfree(resource);
597 670
598 return 0; 671 return 0;
599} 672}
600 673
674static int acpi_power_resume(struct acpi_device *device)
675{
676 int result = 0;
677 struct acpi_power_resource *resource = NULL;
678 struct acpi_power_reference *ref;
679
680 if (!device || !acpi_driver_data(device))
681 return -EINVAL;
682
683 resource = (struct acpi_power_resource *)acpi_driver_data(device);
684
685 result = acpi_power_get_state(resource);
686 if (result)
687 return result;
688
689 mutex_lock(&resource->resource_lock);
690 if ((resource->state == ACPI_POWER_RESOURCE_STATE_ON) &&
691 list_empty(&resource->reference)) {
692 mutex_unlock(&resource->resource_lock);
693 result = acpi_power_off_device(device->handle, NULL);
694 return result;
695 }
696
697 if ((resource->state == ACPI_POWER_RESOURCE_STATE_OFF) &&
698 !list_empty(&resource->reference)) {
699 ref = container_of(resource->reference.next, struct acpi_power_reference, node);
700 mutex_unlock(&resource->resource_lock);
701 result = acpi_power_on(device->handle, ref->device);
702 return result;
703 }
704
705 mutex_unlock(&resource->resource_lock);
706 return 0;
707}
708
601static int __init acpi_power_init(void) 709static int __init acpi_power_init(void)
602{ 710{
603 int result = 0; 711 int result = 0;
diff --git a/drivers/acpi/processor_core.c b/drivers/acpi/processor_core.c
index 0079bc51082c..99d1516d1e70 100644
--- a/drivers/acpi/processor_core.c
+++ b/drivers/acpi/processor_core.c
@@ -60,7 +60,6 @@
60 60
61#define ACPI_PROCESSOR_COMPONENT 0x01000000 61#define ACPI_PROCESSOR_COMPONENT 0x01000000
62#define ACPI_PROCESSOR_CLASS "processor" 62#define ACPI_PROCESSOR_CLASS "processor"
63#define ACPI_PROCESSOR_DRIVER_NAME "ACPI Processor Driver"
64#define ACPI_PROCESSOR_DEVICE_NAME "Processor" 63#define ACPI_PROCESSOR_DEVICE_NAME "Processor"
65#define ACPI_PROCESSOR_FILE_INFO "info" 64#define ACPI_PROCESSOR_FILE_INFO "info"
66#define ACPI_PROCESSOR_FILE_THROTTLING "throttling" 65#define ACPI_PROCESSOR_FILE_THROTTLING "throttling"
@@ -74,10 +73,10 @@
74#define ACPI_STA_PRESENT 0x00000001 73#define ACPI_STA_PRESENT 0x00000001
75 74
76#define _COMPONENT ACPI_PROCESSOR_COMPONENT 75#define _COMPONENT ACPI_PROCESSOR_COMPONENT
77ACPI_MODULE_NAME("acpi_processor") 76ACPI_MODULE_NAME("processor_core");
78 77
79 MODULE_AUTHOR("Paul Diefenbaugh"); 78MODULE_AUTHOR("Paul Diefenbaugh");
80MODULE_DESCRIPTION(ACPI_PROCESSOR_DRIVER_NAME); 79MODULE_DESCRIPTION("ACPI Processor Driver");
81MODULE_LICENSE("GPL"); 80MODULE_LICENSE("GPL");
82 81
83static int acpi_processor_add(struct acpi_device *device); 82static int acpi_processor_add(struct acpi_device *device);
@@ -89,7 +88,7 @@ static acpi_status acpi_processor_hotadd_init(acpi_handle handle, int *p_cpu);
89static int acpi_processor_handle_eject(struct acpi_processor *pr); 88static int acpi_processor_handle_eject(struct acpi_processor *pr);
90 89
91static struct acpi_driver acpi_processor_driver = { 90static struct acpi_driver acpi_processor_driver = {
92 .name = ACPI_PROCESSOR_DRIVER_NAME, 91 .name = "processor",
93 .class = ACPI_PROCESSOR_CLASS, 92 .class = ACPI_PROCESSOR_CLASS,
94 .ids = ACPI_PROCESSOR_HID, 93 .ids = ACPI_PROCESSOR_HID,
95 .ops = { 94 .ops = {
@@ -404,7 +403,7 @@ static int map_lsapic_id(struct acpi_subtable_header *entry,
404 if (lsapic->lapic_flags & ACPI_MADT_ENABLED) { 403 if (lsapic->lapic_flags & ACPI_MADT_ENABLED) {
405 /* First check against id */ 404 /* First check against id */
406 if (lsapic->processor_id == acpi_id) { 405 if (lsapic->processor_id == acpi_id) {
407 *apic_id = lsapic->id; 406 *apic_id = (lsapic->id << 8) | lsapic->eid;
408 return 1; 407 return 1;
409 /* Check against optional uid */ 408 /* Check against optional uid */
410 } else if (entry->length >= 16 && 409 } else if (entry->length >= 16 &&
@@ -1005,7 +1004,7 @@ static int __init acpi_processor_init(void)
1005#ifdef CONFIG_SMP 1004#ifdef CONFIG_SMP
1006 if (ACPI_FAILURE(acpi_get_table(ACPI_SIG_MADT, 0, 1005 if (ACPI_FAILURE(acpi_get_table(ACPI_SIG_MADT, 0,
1007 (struct acpi_table_header **)&madt))) 1006 (struct acpi_table_header **)&madt)))
1008 madt = 0; 1007 madt = NULL;
1009#endif 1008#endif
1010 1009
1011 acpi_processor_dir = proc_mkdir(ACPI_PROCESSOR_CLASS, acpi_root_dir); 1010 acpi_processor_dir = proc_mkdir(ACPI_PROCESSOR_CLASS, acpi_root_dir);
diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
index 8206fc1ecc58..60773005b8af 100644
--- a/drivers/acpi/processor_idle.c
+++ b/drivers/acpi/processor_idle.c
@@ -51,6 +51,14 @@
51#include <asm/apic.h> 51#include <asm/apic.h>
52#endif 52#endif
53 53
54/*
55 * Include the apic definitions for x86 to have the APIC timer related defines
56 * available also for UP (on SMP it gets magically included via linux/smp.h).
57 */
58#ifdef CONFIG_X86
59#include <asm/apic.h>
60#endif
61
54#include <asm/io.h> 62#include <asm/io.h>
55#include <asm/uaccess.h> 63#include <asm/uaccess.h>
56 64
@@ -59,9 +67,8 @@
59 67
60#define ACPI_PROCESSOR_COMPONENT 0x01000000 68#define ACPI_PROCESSOR_COMPONENT 0x01000000
61#define ACPI_PROCESSOR_CLASS "processor" 69#define ACPI_PROCESSOR_CLASS "processor"
62#define ACPI_PROCESSOR_DRIVER_NAME "ACPI Processor Driver"
63#define _COMPONENT ACPI_PROCESSOR_COMPONENT 70#define _COMPONENT ACPI_PROCESSOR_COMPONENT
64ACPI_MODULE_NAME("acpi_processor") 71ACPI_MODULE_NAME("processor_idle");
65#define ACPI_PROCESSOR_FILE_POWER "power" 72#define ACPI_PROCESSOR_FILE_POWER "power"
66#define US_TO_PM_TIMER_TICKS(t) ((t * (PM_TIMER_FREQUENCY/1000)) / 1000) 73#define US_TO_PM_TIMER_TICKS(t) ((t * (PM_TIMER_FREQUENCY/1000)) / 1000)
67#define C2_OVERHEAD 4 /* 1us (3.579 ticks per us) */ 74#define C2_OVERHEAD 4 /* 1us (3.579 ticks per us) */
diff --git a/drivers/acpi/processor_perflib.c b/drivers/acpi/processor_perflib.c
index 058f13cf3b79..2f2e7964226d 100644
--- a/drivers/acpi/processor_perflib.c
+++ b/drivers/acpi/processor_perflib.c
@@ -44,10 +44,9 @@
44 44
45#define ACPI_PROCESSOR_COMPONENT 0x01000000 45#define ACPI_PROCESSOR_COMPONENT 0x01000000
46#define ACPI_PROCESSOR_CLASS "processor" 46#define ACPI_PROCESSOR_CLASS "processor"
47#define ACPI_PROCESSOR_DRIVER_NAME "ACPI Processor Driver"
48#define ACPI_PROCESSOR_FILE_PERFORMANCE "performance" 47#define ACPI_PROCESSOR_FILE_PERFORMANCE "performance"
49#define _COMPONENT ACPI_PROCESSOR_COMPONENT 48#define _COMPONENT ACPI_PROCESSOR_COMPONENT
50ACPI_MODULE_NAME("acpi_processor") 49ACPI_MODULE_NAME("processor_perflib");
51 50
52static DEFINE_MUTEX(performance_mutex); 51static DEFINE_MUTEX(performance_mutex);
53 52
diff --git a/drivers/acpi/processor_thermal.c b/drivers/acpi/processor_thermal.c
index 40fecd67ad83..06e6f3fb8825 100644
--- a/drivers/acpi/processor_thermal.c
+++ b/drivers/acpi/processor_thermal.c
@@ -41,9 +41,8 @@
41 41
42#define ACPI_PROCESSOR_COMPONENT 0x01000000 42#define ACPI_PROCESSOR_COMPONENT 0x01000000
43#define ACPI_PROCESSOR_CLASS "processor" 43#define ACPI_PROCESSOR_CLASS "processor"
44#define ACPI_PROCESSOR_DRIVER_NAME "ACPI Processor Driver"
45#define _COMPONENT ACPI_PROCESSOR_COMPONENT 44#define _COMPONENT ACPI_PROCESSOR_COMPONENT
46ACPI_MODULE_NAME("acpi_processor") 45ACPI_MODULE_NAME("processor_thermal");
47 46
48/* -------------------------------------------------------------------------- 47/* --------------------------------------------------------------------------
49 Limit Interface 48 Limit Interface
diff --git a/drivers/acpi/processor_throttling.c b/drivers/acpi/processor_throttling.c
index 89dff3639abe..b33486009f41 100644
--- a/drivers/acpi/processor_throttling.c
+++ b/drivers/acpi/processor_throttling.c
@@ -41,9 +41,8 @@
41 41
42#define ACPI_PROCESSOR_COMPONENT 0x01000000 42#define ACPI_PROCESSOR_COMPONENT 0x01000000
43#define ACPI_PROCESSOR_CLASS "processor" 43#define ACPI_PROCESSOR_CLASS "processor"
44#define ACPI_PROCESSOR_DRIVER_NAME "ACPI Processor Driver"
45#define _COMPONENT ACPI_PROCESSOR_COMPONENT 44#define _COMPONENT ACPI_PROCESSOR_COMPONENT
46ACPI_MODULE_NAME("acpi_processor") 45ACPI_MODULE_NAME("processor_throttling");
47 46
48/* -------------------------------------------------------------------------- 47/* --------------------------------------------------------------------------
49 Throttling Control 48 Throttling Control
diff --git a/drivers/acpi/sbs.c b/drivers/acpi/sbs.c
index f58fc7447ab4..59640d9a0acc 100644
--- a/drivers/acpi/sbs.c
+++ b/drivers/acpi/sbs.c
@@ -59,7 +59,6 @@ extern void acpi_unlock_battery_dir(struct proc_dir_entry *acpi_battery_dir);
59#define ACPI_AC_CLASS "ac_adapter" 59#define ACPI_AC_CLASS "ac_adapter"
60#define ACPI_BATTERY_CLASS "battery" 60#define ACPI_BATTERY_CLASS "battery"
61#define ACPI_SBS_HID "ACPI0002" 61#define ACPI_SBS_HID "ACPI0002"
62#define ACPI_SBS_DRIVER_NAME "ACPI Smart Battery System Driver"
63#define ACPI_SBS_DEVICE_NAME "Smart Battery System" 62#define ACPI_SBS_DEVICE_NAME "Smart Battery System"
64#define ACPI_SBS_FILE_INFO "info" 63#define ACPI_SBS_FILE_INFO "info"
65#define ACPI_SBS_FILE_STATE "state" 64#define ACPI_SBS_FILE_STATE "state"
@@ -78,7 +77,7 @@ extern void acpi_unlock_battery_dir(struct proc_dir_entry *acpi_battery_dir);
78#define MAX_SBS_BAT 4 77#define MAX_SBS_BAT 4
79#define MAX_SMBUS_ERR 1 78#define MAX_SMBUS_ERR 1
80 79
81ACPI_MODULE_NAME("acpi_sbs"); 80ACPI_MODULE_NAME("sbs");
82 81
83MODULE_AUTHOR("Rich Townsend"); 82MODULE_AUTHOR("Rich Townsend");
84MODULE_DESCRIPTION("Smart Battery System ACPI interface driver"); 83MODULE_DESCRIPTION("Smart Battery System ACPI interface driver");
@@ -110,7 +109,7 @@ static void acpi_battery_smbus_err_handler(struct acpi_ec_smbus *smbus);
110static void acpi_sbs_update_queue(void *data); 109static void acpi_sbs_update_queue(void *data);
111 110
112static struct acpi_driver acpi_sbs_driver = { 111static struct acpi_driver acpi_sbs_driver = {
113 .name = ACPI_SBS_DRIVER_NAME, 112 .name = "sbs",
114 .class = ACPI_SBS_CLASS, 113 .class = ACPI_SBS_CLASS,
115 .ids = ACPI_SBS_HID, 114 .ids = ACPI_SBS_HID,
116 .ops = { 115 .ops = {
@@ -1034,21 +1033,19 @@ static int acpi_battery_read_state(struct seq_file *seq, void *offset)
1034 } else { 1033 } else {
1035 seq_printf(seq, "capacity state: ok\n"); 1034 seq_printf(seq, "capacity state: ok\n");
1036 } 1035 }
1036
1037 foo = (s16) battery->state.amperage * battery->info.ipscale;
1038 if (battery->info.capacity_mode) {
1039 foo = foo * battery->info.design_voltage / 1000;
1040 }
1037 if (battery->state.amperage < 0) { 1041 if (battery->state.amperage < 0) {
1038 seq_printf(seq, "charging state: discharging\n"); 1042 seq_printf(seq, "charging state: discharging\n");
1039 foo = battery->state.remaining_capacity * cscale * 60 / 1043 seq_printf(seq, "present rate: %d %s\n",
1040 (battery->state.average_time_to_empty == 0 ? 1 : 1044 -foo, battery->info.capacity_mode ? "mW" : "mA");
1041 battery->state.average_time_to_empty);
1042 seq_printf(seq, "present rate: %i%s\n",
1043 foo, battery->info.capacity_mode ? "0 mW" : " mA");
1044 } else if (battery->state.amperage > 0) { 1045 } else if (battery->state.amperage > 0) {
1045 seq_printf(seq, "charging state: charging\n"); 1046 seq_printf(seq, "charging state: charging\n");
1046 foo = (battery->info.full_charge_capacity - 1047 seq_printf(seq, "present rate: %d %s\n",
1047 battery->state.remaining_capacity) * cscale * 60 / 1048 foo, battery->info.capacity_mode ? "mW" : "mA");
1048 (battery->state.average_time_to_full == 0 ? 1 :
1049 battery->state.average_time_to_full);
1050 seq_printf(seq, "present rate: %i%s\n",
1051 foo, battery->info.capacity_mode ? "0 mW" : " mA");
1052 } else { 1049 } else {
1053 seq_printf(seq, "charging state: charged\n"); 1050 seq_printf(seq, "charging state: charged\n");
1054 seq_printf(seq, "present rate: 0 %s\n", 1051 seq_printf(seq, "present rate: 0 %s\n",
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index 64f26db10c8e..bb0e0da39fb1 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -11,13 +11,12 @@
11#include <acpi/acinterp.h> /* for acpi_ex_eisa_id_to_string() */ 11#include <acpi/acinterp.h> /* for acpi_ex_eisa_id_to_string() */
12 12
13#define _COMPONENT ACPI_BUS_COMPONENT 13#define _COMPONENT ACPI_BUS_COMPONENT
14ACPI_MODULE_NAME("scan") 14ACPI_MODULE_NAME("scan");
15#define STRUCT_TO_INT(s) (*((int*)&s)) 15#define STRUCT_TO_INT(s) (*((int*)&s))
16extern struct acpi_device *acpi_root; 16extern struct acpi_device *acpi_root;
17 17
18#define ACPI_BUS_CLASS "system_bus" 18#define ACPI_BUS_CLASS "system_bus"
19#define ACPI_BUS_HID "ACPI_BUS" 19#define ACPI_BUS_HID "ACPI_BUS"
20#define ACPI_BUS_DRIVER_NAME "ACPI Bus Driver"
21#define ACPI_BUS_DEVICE_NAME "System Bus" 20#define ACPI_BUS_DEVICE_NAME "System Bus"
22 21
23static LIST_HEAD(acpi_device_list); 22static LIST_HEAD(acpi_device_list);
diff --git a/drivers/acpi/sleep/main.c b/drivers/acpi/sleep/main.c
index 62ce87d71651..37a0930fc0a6 100644
--- a/drivers/acpi/sleep/main.c
+++ b/drivers/acpi/sleep/main.c
@@ -200,7 +200,7 @@ static struct dmi_system_id __initdata acpisleep_dmi_table[] = {
200 {}, 200 {},
201}; 201};
202 202
203static int __init acpi_sleep_init(void) 203int __init acpi_sleep_init(void)
204{ 204{
205 int i = 0; 205 int i = 0;
206 206
@@ -229,4 +229,3 @@ static int __init acpi_sleep_init(void)
229 return 0; 229 return 0;
230} 230}
231 231
232late_initcall(acpi_sleep_init);
diff --git a/drivers/acpi/system.c b/drivers/acpi/system.c
index 7147b0bdab0a..83a8d3097904 100644
--- a/drivers/acpi/system.c
+++ b/drivers/acpi/system.c
@@ -31,14 +31,13 @@
31#include <acpi/acpi_drivers.h> 31#include <acpi/acpi_drivers.h>
32 32
33#define _COMPONENT ACPI_SYSTEM_COMPONENT 33#define _COMPONENT ACPI_SYSTEM_COMPONENT
34ACPI_MODULE_NAME("acpi_system") 34ACPI_MODULE_NAME("system");
35#ifdef MODULE_PARAM_PREFIX 35#ifdef MODULE_PARAM_PREFIX
36#undef MODULE_PARAM_PREFIX 36#undef MODULE_PARAM_PREFIX
37#endif 37#endif
38#define MODULE_PARAM_PREFIX "acpi." 38#define MODULE_PARAM_PREFIX "acpi."
39 39
40#define ACPI_SYSTEM_CLASS "system" 40#define ACPI_SYSTEM_CLASS "system"
41#define ACPI_SYSTEM_DRIVER_NAME "ACPI System Driver"
42#define ACPI_SYSTEM_DEVICE_NAME "System" 41#define ACPI_SYSTEM_DEVICE_NAME "System"
43#define ACPI_SYSTEM_FILE_INFO "info" 42#define ACPI_SYSTEM_FILE_INFO "info"
44#define ACPI_SYSTEM_FILE_EVENT "event" 43#define ACPI_SYSTEM_FILE_EVENT "event"
diff --git a/drivers/acpi/tables.c b/drivers/acpi/tables.c
index 45bd17313c4a..849e2c361804 100644
--- a/drivers/acpi/tables.c
+++ b/drivers/acpi/tables.c
@@ -169,40 +169,40 @@ void acpi_table_print_madt_entry(struct acpi_subtable_header * header)
169 169
170 170
171int __init 171int __init
172acpi_table_parse_madt_family(char *id, 172acpi_table_parse_entries(char *id,
173 unsigned long madt_size, 173 unsigned long table_size,
174 int entry_id, 174 int entry_id,
175 acpi_madt_entry_handler handler, 175 acpi_table_entry_handler handler,
176 unsigned int max_entries) 176 unsigned int max_entries)
177{ 177{
178 struct acpi_table_header *madt = NULL; 178 struct acpi_table_header *table_header = NULL;
179 struct acpi_subtable_header *entry; 179 struct acpi_subtable_header *entry;
180 unsigned int count = 0; 180 unsigned int count = 0;
181 unsigned long madt_end; 181 unsigned long table_end;
182 182
183 if (!handler) 183 if (!handler)
184 return -EINVAL; 184 return -EINVAL;
185 185
186 /* Locate the MADT (if exists). There should only be one. */ 186 /* Locate the table (if exists). There should only be one. */
187 acpi_get_table(id, 0, &madt); 187 acpi_get_table(id, 0, &table_header);
188 188
189 if (!madt) { 189 if (!table_header) {
190 printk(KERN_WARNING PREFIX "%4.4s not present\n", id); 190 printk(KERN_WARNING PREFIX "%4.4s not present\n", id);
191 return -ENODEV; 191 return -ENODEV;
192 } 192 }
193 193
194 madt_end = (unsigned long)madt + madt->length; 194 table_end = (unsigned long)table_header + table_header->length;
195 195
196 /* Parse all entries looking for a match. */ 196 /* Parse all entries looking for a match. */
197 197
198 entry = (struct acpi_subtable_header *) 198 entry = (struct acpi_subtable_header *)
199 ((unsigned long)madt + madt_size); 199 ((unsigned long)table_header + table_size);
200 200
201 while (((unsigned long)entry) + sizeof(struct acpi_subtable_header) < 201 while (((unsigned long)entry) + sizeof(struct acpi_subtable_header) <
202 madt_end) { 202 table_end) {
203 if (entry->type == entry_id 203 if (entry->type == entry_id
204 && (!max_entries || count++ < max_entries)) 204 && (!max_entries || count++ < max_entries))
205 if (handler(entry, madt_end)) 205 if (handler(entry, table_end))
206 return -EINVAL; 206 return -EINVAL;
207 207
208 entry = (struct acpi_subtable_header *) 208 entry = (struct acpi_subtable_header *)
@@ -218,13 +218,22 @@ acpi_table_parse_madt_family(char *id,
218 218
219int __init 219int __init
220acpi_table_parse_madt(enum acpi_madt_type id, 220acpi_table_parse_madt(enum acpi_madt_type id,
221 acpi_madt_entry_handler handler, unsigned int max_entries) 221 acpi_table_entry_handler handler, unsigned int max_entries)
222{ 222{
223 return acpi_table_parse_madt_family(ACPI_SIG_MADT, 223 return acpi_table_parse_entries(ACPI_SIG_MADT,
224 sizeof(struct acpi_table_madt), id, 224 sizeof(struct acpi_table_madt), id,
225 handler, max_entries); 225 handler, max_entries);
226} 226}
227 227
228/**
229 * acpi_table_parse - find table with @id, run @handler on it
230 *
231 * @id: table id to find
232 * @handler: handler to run
233 *
234 * Scan the ACPI System Descriptor Table (STD) for a table matching @id,
235 * run @handler on it. Return 0 if table found, return on if not.
236 */
228int __init acpi_table_parse(char *id, acpi_table_handler handler) 237int __init acpi_table_parse(char *id, acpi_table_handler handler)
229{ 238{
230 struct acpi_table_header *table = NULL; 239 struct acpi_table_header *table = NULL;
@@ -234,9 +243,9 @@ int __init acpi_table_parse(char *id, acpi_table_handler handler)
234 acpi_get_table(id, 0, &table); 243 acpi_get_table(id, 0, &table);
235 if (table) { 244 if (table) {
236 handler(table); 245 handler(table);
237 return 1;
238 } else
239 return 0; 246 return 0;
247 } else
248 return 1;
240} 249}
241 250
242/* 251/*
diff --git a/drivers/acpi/tables/tbxface.c b/drivers/acpi/tables/tbxface.c
index 807978d5381a..417ef5fa7666 100644
--- a/drivers/acpi/tables/tbxface.c
+++ b/drivers/acpi/tables/tbxface.c
@@ -338,9 +338,9 @@ acpi_status acpi_unload_table_id(acpi_owner_id id)
338 int i; 338 int i;
339 acpi_status status = AE_NOT_EXIST; 339 acpi_status status = AE_NOT_EXIST;
340 340
341 ACPI_FUNCTION_TRACE(acpi_unload_table); 341 ACPI_FUNCTION_TRACE(acpi_unload_table_id);
342 342
343 /* Find table from the requested type list */ 343 /* Find table in the global table list */
344 for (i = 0; i < acpi_gbl_root_table_list.count; ++i) { 344 for (i = 0; i < acpi_gbl_root_table_list.count; ++i) {
345 if (id != acpi_gbl_root_table_list.tables[i].owner_id) { 345 if (id != acpi_gbl_root_table_list.tables[i].owner_id) {
346 continue; 346 continue;
@@ -352,8 +352,9 @@ acpi_status acpi_unload_table_id(acpi_owner_id id)
352 * simply a position within the hierarchy 352 * simply a position within the hierarchy
353 */ 353 */
354 acpi_tb_delete_namespace_by_owner(i); 354 acpi_tb_delete_namespace_by_owner(i);
355 acpi_tb_release_owner_id(i); 355 status = acpi_tb_release_owner_id(i);
356 acpi_tb_set_table_loaded_flag(i, FALSE); 356 acpi_tb_set_table_loaded_flag(i, FALSE);
357 break;
357 } 358 }
358 return_ACPI_STATUS(status); 359 return_ACPI_STATUS(status);
359} 360}
@@ -408,7 +409,7 @@ acpi_get_table(char *signature,
408 } 409 }
409 410
410 if (!acpi_gbl_permanent_mmap) { 411 if (!acpi_gbl_permanent_mmap) {
411 acpi_gbl_root_table_list.tables[i].pointer = 0; 412 acpi_gbl_root_table_list.tables[i].pointer = NULL;
412 } 413 }
413 414
414 return (status); 415 return (status);
diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c
index 986afd470a14..0ae8b9310cbf 100644
--- a/drivers/acpi/thermal.c
+++ b/drivers/acpi/thermal.c
@@ -47,7 +47,6 @@
47 47
48#define ACPI_THERMAL_COMPONENT 0x04000000 48#define ACPI_THERMAL_COMPONENT 0x04000000
49#define ACPI_THERMAL_CLASS "thermal_zone" 49#define ACPI_THERMAL_CLASS "thermal_zone"
50#define ACPI_THERMAL_DRIVER_NAME "ACPI Thermal Zone Driver"
51#define ACPI_THERMAL_DEVICE_NAME "Thermal Zone" 50#define ACPI_THERMAL_DEVICE_NAME "Thermal Zone"
52#define ACPI_THERMAL_FILE_STATE "state" 51#define ACPI_THERMAL_FILE_STATE "state"
53#define ACPI_THERMAL_FILE_TEMPERATURE "temperature" 52#define ACPI_THERMAL_FILE_TEMPERATURE "temperature"
@@ -71,10 +70,10 @@
71#define CELSIUS_TO_KELVIN(t) ((t+273)*10) 70#define CELSIUS_TO_KELVIN(t) ((t+273)*10)
72 71
73#define _COMPONENT ACPI_THERMAL_COMPONENT 72#define _COMPONENT ACPI_THERMAL_COMPONENT
74ACPI_MODULE_NAME("acpi_thermal") 73ACPI_MODULE_NAME("thermal");
75 74
76MODULE_AUTHOR("Paul Diefenbaugh"); 75MODULE_AUTHOR("Paul Diefenbaugh");
77MODULE_DESCRIPTION(ACPI_THERMAL_DRIVER_NAME); 76MODULE_DESCRIPTION("ACPI Thermal Zone Driver");
78MODULE_LICENSE("GPL"); 77MODULE_LICENSE("GPL");
79 78
80static int tzp; 79static int tzp;
@@ -99,7 +98,7 @@ static ssize_t acpi_thermal_write_polling(struct file *, const char __user *,
99 size_t, loff_t *); 98 size_t, loff_t *);
100 99
101static struct acpi_driver acpi_thermal_driver = { 100static struct acpi_driver acpi_thermal_driver = {
102 .name = ACPI_THERMAL_DRIVER_NAME, 101 .name = "thermal",
103 .class = ACPI_THERMAL_CLASS, 102 .class = ACPI_THERMAL_CLASS,
104 .ids = ACPI_THERMAL_HID, 103 .ids = ACPI_THERMAL_HID,
105 .ops = { 104 .ops = {
@@ -270,7 +269,7 @@ static int acpi_thermal_set_polling(struct acpi_thermal *tz, int seconds)
270 269
271 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 270 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
272 "Polling frequency set to %lu seconds\n", 271 "Polling frequency set to %lu seconds\n",
273 tz->polling_frequency)); 272 tz->polling_frequency/10));
274 273
275 return 0; 274 return 0;
276} 275}
@@ -1357,28 +1356,32 @@ static int acpi_thermal_remove(struct acpi_device *device, int type)
1357static int acpi_thermal_resume(struct acpi_device *device) 1356static int acpi_thermal_resume(struct acpi_device *device)
1358{ 1357{
1359 struct acpi_thermal *tz = NULL; 1358 struct acpi_thermal *tz = NULL;
1360 int i; 1359 int i, j, power_state, result;
1360
1361 1361
1362 if (!device || !acpi_driver_data(device)) 1362 if (!device || !acpi_driver_data(device))
1363 return -EINVAL; 1363 return -EINVAL;
1364 1364
1365 tz = acpi_driver_data(device); 1365 tz = acpi_driver_data(device);
1366 1366
1367 acpi_thermal_get_temperature(tz);
1368
1369 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { 1367 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
1370 if (tz->trips.active[i].flags.valid) { 1368 if (!(&tz->trips.active[i]))
1371 tz->temperature = tz->trips.active[i].temperature; 1369 break;
1372 tz->trips.active[i].flags.enabled = 0; 1370 if (!tz->trips.active[i].flags.valid)
1373 1371 break;
1374 acpi_thermal_active(tz); 1372 tz->trips.active[i].flags.enabled = 1;
1375 1373 for (j = 0; j < tz->trips.active[i].devices.count; j++) {
1376 tz->state.active |= tz->trips.active[i].flags.enabled; 1374 result = acpi_bus_get_power(tz->trips.active[i].devices.
1377 tz->state.active_index = i; 1375 handles[j], &power_state);
1376 if (result || (power_state != ACPI_STATE_D0)) {
1377 tz->trips.active[i].flags.enabled = 0;
1378 break;
1379 }
1378 } 1380 }
1381 tz->state.active |= tz->trips.active[i].flags.enabled;
1379 } 1382 }
1380 1383
1381 acpi_thermal_check(tz); 1384 acpi_thermal_check(tz);
1382 1385
1383 return AE_OK; 1386 return AE_OK;
1384} 1387}
diff --git a/drivers/acpi/toshiba_acpi.c b/drivers/acpi/toshiba_acpi.c
index d9b651ffcdc0..faf8a5232d8e 100644
--- a/drivers/acpi/toshiba_acpi.c
+++ b/drivers/acpi/toshiba_acpi.c
@@ -125,7 +125,7 @@ static int write_acpi_int(const char *methodName, int val)
125 union acpi_object in_objs[1]; 125 union acpi_object in_objs[1];
126 acpi_status status; 126 acpi_status status;
127 127
128 params.count = sizeof(in_objs) / sizeof(in_objs[0]); 128 params.count = ARRAY_SIZE(in_objs);
129 params.pointer = in_objs; 129 params.pointer = in_objs;
130 in_objs[0].type = ACPI_TYPE_INTEGER; 130 in_objs[0].type = ACPI_TYPE_INTEGER;
131 in_objs[0].integer.value = val; 131 in_objs[0].integer.value = val;
@@ -561,10 +561,6 @@ static int __init toshiba_acpi_init(void)
561 if (acpi_disabled) 561 if (acpi_disabled)
562 return -ENODEV; 562 return -ENODEV;
563 563
564 if (!acpi_specific_hotkey_enabled) {
565 printk(MY_INFO "Using generic hotkey driver\n");
566 return -ENODEV;
567 }
568 /* simple device detection: look for HCI method */ 564 /* simple device detection: look for HCI method */
569 if (is_valid_acpi_path(METHOD_HCI_1)) 565 if (is_valid_acpi_path(METHOD_HCI_1))
570 method_hci = METHOD_HCI_1; 566 method_hci = METHOD_HCI_1;
diff --git a/drivers/acpi/utilities/utdelete.c b/drivers/acpi/utilities/utdelete.c
index f777cebdc46d..673a0caa4073 100644
--- a/drivers/acpi/utilities/utdelete.c
+++ b/drivers/acpi/utilities/utdelete.c
@@ -170,7 +170,6 @@ static void acpi_ut_delete_internal_obj(union acpi_operand_object *object)
170 acpi_os_delete_mutex(object->mutex.os_mutex); 170 acpi_os_delete_mutex(object->mutex.os_mutex);
171 acpi_gbl_global_lock_mutex = NULL; 171 acpi_gbl_global_lock_mutex = NULL;
172 } else { 172 } else {
173 acpi_ex_unlink_mutex(object);
174 acpi_os_delete_mutex(object->mutex.os_mutex); 173 acpi_os_delete_mutex(object->mutex.os_mutex);
175 } 174 }
176 break; 175 break;
diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c
index 68a809fa7b19..34f157571080 100644
--- a/drivers/acpi/utils.c
+++ b/drivers/acpi/utils.c
@@ -31,7 +31,7 @@
31#include <acpi/acpi_drivers.h> 31#include <acpi/acpi_drivers.h>
32 32
33#define _COMPONENT ACPI_BUS_COMPONENT 33#define _COMPONENT ACPI_BUS_COMPONENT
34ACPI_MODULE_NAME("acpi_utils") 34ACPI_MODULE_NAME("utils");
35 35
36/* -------------------------------------------------------------------------- 36/* --------------------------------------------------------------------------
37 Object Evaluation Helpers 37 Object Evaluation Helpers
diff --git a/drivers/acpi/video.c b/drivers/acpi/video.c
index e0b97add8c63..bf525cca3b63 100644
--- a/drivers/acpi/video.c
+++ b/drivers/acpi/video.c
@@ -40,7 +40,6 @@
40 40
41#define ACPI_VIDEO_COMPONENT 0x08000000 41#define ACPI_VIDEO_COMPONENT 0x08000000
42#define ACPI_VIDEO_CLASS "video" 42#define ACPI_VIDEO_CLASS "video"
43#define ACPI_VIDEO_DRIVER_NAME "ACPI Video Driver"
44#define ACPI_VIDEO_BUS_NAME "Video Bus" 43#define ACPI_VIDEO_BUS_NAME "Video Bus"
45#define ACPI_VIDEO_DEVICE_NAME "Video Device" 44#define ACPI_VIDEO_DEVICE_NAME "Video Device"
46#define ACPI_VIDEO_NOTIFY_SWITCH 0x80 45#define ACPI_VIDEO_NOTIFY_SWITCH 0x80
@@ -65,17 +64,17 @@
65#define ACPI_VIDEO_DISPLAY_LCD 4 64#define ACPI_VIDEO_DISPLAY_LCD 4
66 65
67#define _COMPONENT ACPI_VIDEO_COMPONENT 66#define _COMPONENT ACPI_VIDEO_COMPONENT
68ACPI_MODULE_NAME("acpi_video") 67ACPI_MODULE_NAME("video");
69 68
70 MODULE_AUTHOR("Bruno Ducrot"); 69MODULE_AUTHOR("Bruno Ducrot");
71MODULE_DESCRIPTION(ACPI_VIDEO_DRIVER_NAME); 70MODULE_DESCRIPTION("ACPI Video Driver");
72MODULE_LICENSE("GPL"); 71MODULE_LICENSE("GPL");
73 72
74static int acpi_video_bus_add(struct acpi_device *device); 73static int acpi_video_bus_add(struct acpi_device *device);
75static int acpi_video_bus_remove(struct acpi_device *device, int type); 74static int acpi_video_bus_remove(struct acpi_device *device, int type);
76 75
77static struct acpi_driver acpi_video_bus = { 76static struct acpi_driver acpi_video_bus = {
78 .name = ACPI_VIDEO_DRIVER_NAME, 77 .name = "video",
79 .class = ACPI_VIDEO_CLASS, 78 .class = ACPI_VIDEO_CLASS,
80 .ids = ACPI_VIDEO_HID, 79 .ids = ACPI_VIDEO_HID,
81 .ops = { 80 .ops = {
diff --git a/drivers/ata/Kconfig b/drivers/ata/Kconfig
index 3747457fee7a..4af0a4bb5780 100644
--- a/drivers/ata/Kconfig
+++ b/drivers/ata/Kconfig
@@ -161,6 +161,19 @@ config SATA_INTEL_COMBINED
161 depends on IDE=y && !BLK_DEV_IDE_SATA && (SATA_AHCI || ATA_PIIX) 161 depends on IDE=y && !BLK_DEV_IDE_SATA && (SATA_AHCI || ATA_PIIX)
162 default y 162 default y
163 163
164config SATA_ACPI
165 bool
166 depends on ACPI && PCI
167 default y
168 help
169 This option adds support for SATA-related ACPI objects.
170 These ACPI objects add the ability to retrieve taskfiles
171 from the ACPI BIOS and write them to the disk controller.
172 These objects may be related to performance, security,
173 power management, or other areas.
174 You can disable this at kernel boot time by using the
175 option libata.noacpi=1
176
164config PATA_ALI 177config PATA_ALI
165 tristate "ALi PATA support (Experimental)" 178 tristate "ALi PATA support (Experimental)"
166 depends on PCI && EXPERIMENTAL 179 depends on PCI && EXPERIMENTAL
diff --git a/drivers/ata/Makefile b/drivers/ata/Makefile
index cd096f0c78a1..74298afbbaa7 100644
--- a/drivers/ata/Makefile
+++ b/drivers/ata/Makefile
@@ -66,4 +66,4 @@ obj-$(CONFIG_ATA_GENERIC) += ata_generic.o
66obj-$(CONFIG_PATA_LEGACY) += pata_legacy.o 66obj-$(CONFIG_PATA_LEGACY) += pata_legacy.o
67 67
68libata-objs := libata-core.o libata-scsi.o libata-sff.o libata-eh.o 68libata-objs := libata-core.o libata-scsi.o libata-sff.o libata-eh.o
69 69libata-$(CONFIG_SATA_ACPI) += libata-acpi.o
diff --git a/drivers/ata/libata-acpi.c b/drivers/ata/libata-acpi.c
new file mode 100644
index 000000000000..b4e8be5d292c
--- /dev/null
+++ b/drivers/ata/libata-acpi.c
@@ -0,0 +1,698 @@
1/*
2 * libata-acpi.c
3 * Provides ACPI support for PATA/SATA.
4 *
5 * Copyright (C) 2006 Intel Corp.
6 * Copyright (C) 2006 Randy Dunlap
7 */
8
9#include <linux/ata.h>
10#include <linux/delay.h>
11#include <linux/device.h>
12#include <linux/errno.h>
13#include <linux/kernel.h>
14#include <linux/acpi.h>
15#include <linux/libata.h>
16#include <linux/pci.h>
17#include "libata.h"
18
19#include <acpi/acpi_bus.h>
20#include <acpi/acnames.h>
21#include <acpi/acnamesp.h>
22#include <acpi/acparser.h>
23#include <acpi/acexcep.h>
24#include <acpi/acmacros.h>
25#include <acpi/actypes.h>
26
27#define SATA_ROOT_PORT(x) (((x) >> 16) & 0xffff)
28#define SATA_PORT_NUMBER(x) ((x) & 0xffff) /* or NO_PORT_MULT */
29#define NO_PORT_MULT 0xffff
30#define SATA_ADR_RSVD 0xffffffff
31
32#define REGS_PER_GTF 7
33struct taskfile_array {
34 u8 tfa[REGS_PER_GTF]; /* regs. 0x1f1 - 0x1f7 */
35};
36
37
38/**
39 * sata_get_dev_handle - finds acpi_handle and PCI device.function
40 * @dev: device to locate
41 * @handle: returned acpi_handle for @dev
42 * @pcidevfn: return PCI device.func for @dev
43 *
44 * This function is somewhat SATA-specific. Or at least the
45 * PATA & SATA versions of this function are different,
46 * so it's not entirely generic code.
47 *
48 * Returns 0 on success, <0 on error.
49 */
50static int sata_get_dev_handle(struct device *dev, acpi_handle *handle,
51 acpi_integer *pcidevfn)
52{
53 struct pci_dev *pci_dev;
54 acpi_integer addr;
55
56 pci_dev = to_pci_dev(dev); /* NOTE: PCI-specific */
57 /* Please refer to the ACPI spec for the syntax of _ADR. */
58 addr = (PCI_SLOT(pci_dev->devfn) << 16) | PCI_FUNC(pci_dev->devfn);
59 *pcidevfn = addr;
60 *handle = acpi_get_child(DEVICE_ACPI_HANDLE(dev->parent), addr);
61 if (!*handle)
62 return -ENODEV;
63 return 0;
64}
65
66/**
67 * pata_get_dev_handle - finds acpi_handle and PCI device.function
68 * @dev: device to locate
69 * @handle: returned acpi_handle for @dev
70 * @pcidevfn: return PCI device.func for @dev
71 *
72 * The PATA and SATA versions of this function are different.
73 *
74 * Returns 0 on success, <0 on error.
75 */
76static int pata_get_dev_handle(struct device *dev, acpi_handle *handle,
77 acpi_integer *pcidevfn)
78{
79 unsigned int bus, devnum, func;
80 acpi_integer addr;
81 acpi_handle dev_handle, parent_handle;
82 struct acpi_buffer buffer = {.length = ACPI_ALLOCATE_BUFFER,
83 .pointer = NULL};
84 acpi_status status;
85 struct acpi_device_info *dinfo = NULL;
86 int ret = -ENODEV;
87 struct pci_dev *pdev = to_pci_dev(dev);
88
89 bus = pdev->bus->number;
90 devnum = PCI_SLOT(pdev->devfn);
91 func = PCI_FUNC(pdev->devfn);
92
93 dev_handle = DEVICE_ACPI_HANDLE(dev);
94 parent_handle = DEVICE_ACPI_HANDLE(dev->parent);
95
96 status = acpi_get_object_info(parent_handle, &buffer);
97 if (ACPI_FAILURE(status))
98 goto err;
99
100 dinfo = buffer.pointer;
101 if (dinfo && (dinfo->valid & ACPI_VALID_ADR) &&
102 dinfo->address == bus) {
103 /* ACPI spec for _ADR for PCI bus: */
104 addr = (acpi_integer)(devnum << 16 | func);
105 *pcidevfn = addr;
106 *handle = dev_handle;
107 } else {
108 goto err;
109 }
110
111 if (!*handle)
112 goto err;
113 ret = 0;
114err:
115 kfree(dinfo);
116 return ret;
117}
118
119struct walk_info { /* can be trimmed some */
120 struct device *dev;
121 struct acpi_device *adev;
122 acpi_handle handle;
123 acpi_integer pcidevfn;
124 unsigned int drivenum;
125 acpi_handle obj_handle;
126 struct ata_port *ataport;
127 struct ata_device *atadev;
128 u32 sata_adr;
129 int status;
130 char basepath[ACPI_PATHNAME_MAX];
131 int basepath_len;
132};
133
134static acpi_status get_devices(acpi_handle handle,
135 u32 level, void *context, void **return_value)
136{
137 acpi_status status;
138 struct walk_info *winfo = context;
139 struct acpi_buffer namebuf = {ACPI_ALLOCATE_BUFFER, NULL};
140 char *pathname;
141 struct acpi_buffer buffer;
142 struct acpi_device_info *dinfo;
143
144 status = acpi_get_name(handle, ACPI_FULL_PATHNAME, &namebuf);
145 if (status)
146 goto ret;
147 pathname = namebuf.pointer;
148
149 buffer.length = ACPI_ALLOCATE_BUFFER;
150 buffer.pointer = NULL;
151 status = acpi_get_object_info(handle, &buffer);
152 if (ACPI_FAILURE(status))
153 goto out2;
154
155 dinfo = buffer.pointer;
156
157 /* find full device path name for pcidevfn */
158 if (dinfo && (dinfo->valid & ACPI_VALID_ADR) &&
159 dinfo->address == winfo->pcidevfn) {
160 if (ata_msg_probe(winfo->ataport))
161 ata_dev_printk(winfo->atadev, KERN_DEBUG,
162 ":%s: matches pcidevfn (0x%llx)\n",
163 pathname, winfo->pcidevfn);
164 strlcpy(winfo->basepath, pathname,
165 sizeof(winfo->basepath));
166 winfo->basepath_len = strlen(pathname);
167 goto out;
168 }
169
170 /* if basepath is not yet known, ignore this object */
171 if (!winfo->basepath_len)
172 goto out;
173
174 /* if this object is in scope of basepath, maybe use it */
175 if (strncmp(pathname, winfo->basepath,
176 winfo->basepath_len) == 0) {
177 if (!(dinfo->valid & ACPI_VALID_ADR))
178 goto out;
179 if (ata_msg_probe(winfo->ataport))
180 ata_dev_printk(winfo->atadev, KERN_DEBUG,
181 "GOT ONE: (%s) root_port = 0x%llx,"
182 " port_num = 0x%llx\n", pathname,
183 SATA_ROOT_PORT(dinfo->address),
184 SATA_PORT_NUMBER(dinfo->address));
185 /* heuristics: */
186 if (SATA_PORT_NUMBER(dinfo->address) != NO_PORT_MULT)
187 if (ata_msg_probe(winfo->ataport))
188 ata_dev_printk(winfo->atadev,
189 KERN_DEBUG, "warning: don't"
190 " know how to handle SATA port"
191 " multiplier\n");
192 if (SATA_ROOT_PORT(dinfo->address) ==
193 winfo->ataport->port_no &&
194 SATA_PORT_NUMBER(dinfo->address) == NO_PORT_MULT) {
195 if (ata_msg_probe(winfo->ataport))
196 ata_dev_printk(winfo->atadev,
197 KERN_DEBUG,
198 "THIS ^^^^^ is the requested"
199 " SATA drive (handle = 0x%p)\n",
200 handle);
201 winfo->sata_adr = dinfo->address;
202 winfo->obj_handle = handle;
203 }
204 }
205out:
206 kfree(dinfo);
207out2:
208 kfree(pathname);
209
210ret:
211 return status;
212}
213
214/* Get the SATA drive _ADR object. */
215static int get_sata_adr(struct device *dev, acpi_handle handle,
216 acpi_integer pcidevfn, unsigned int drive,
217 struct ata_port *ap,
218 struct ata_device *atadev, u32 *dev_adr)
219{
220 acpi_status status;
221 struct walk_info *winfo;
222 int err = -ENOMEM;
223
224 winfo = kzalloc(sizeof(struct walk_info), GFP_KERNEL);
225 if (!winfo)
226 goto out;
227
228 winfo->dev = dev;
229 winfo->atadev = atadev;
230 winfo->ataport = ap;
231 if (acpi_bus_get_device(handle, &winfo->adev) < 0)
232 if (ata_msg_probe(ap))
233 ata_dev_printk(winfo->atadev, KERN_DEBUG,
234 "acpi_bus_get_device failed\n");
235 winfo->handle = handle;
236 winfo->pcidevfn = pcidevfn;
237 winfo->drivenum = drive;
238
239 status = acpi_get_devices(NULL, get_devices, winfo, NULL);
240 if (ACPI_FAILURE(status)) {
241 if (ata_msg_probe(ap))
242 ata_dev_printk(winfo->atadev, KERN_DEBUG,
243 "%s: acpi_get_devices failed\n",
244 __FUNCTION__);
245 err = -ENODEV;
246 } else {
247 *dev_adr = winfo->sata_adr;
248 atadev->obj_handle = winfo->obj_handle;
249 err = 0;
250 }
251 kfree(winfo);
252out:
253 return err;
254}
255
256/**
257 * do_drive_get_GTF - get the drive bootup default taskfile settings
258 * @ap: the ata_port for the drive
259 * @ix: target ata_device (drive) index
260 * @gtf_length: number of bytes of _GTF data returned at @gtf_address
261 * @gtf_address: buffer containing _GTF taskfile arrays
262 *
263 * This applies to both PATA and SATA drives.
264 *
265 * The _GTF method has no input parameters.
266 * It returns a variable number of register set values (registers
267 * hex 1F1..1F7, taskfiles).
268 * The <variable number> is not known in advance, so have ACPI-CA
269 * allocate the buffer as needed and return it, then free it later.
270 *
271 * The returned @gtf_length and @gtf_address are only valid if the
272 * function return value is 0.
273 */
274static int do_drive_get_GTF(struct ata_port *ap, int ix,
275 unsigned int *gtf_length, unsigned long *gtf_address,
276 unsigned long *obj_loc)
277{
278 acpi_status status;
279 acpi_handle dev_handle = NULL;
280 acpi_handle chan_handle, drive_handle;
281 acpi_integer pcidevfn = 0;
282 u32 dev_adr;
283 struct acpi_buffer output;
284 union acpi_object *out_obj;
285 struct device *dev = ap->host->dev;
286 struct ata_device *atadev = &ap->device[ix];
287 int err = -ENODEV;
288
289 *gtf_length = 0;
290 *gtf_address = 0UL;
291 *obj_loc = 0UL;
292
293 if (noacpi)
294 return 0;
295
296 if (ata_msg_probe(ap))
297 ata_dev_printk(atadev, KERN_DEBUG,
298 "%s: ENTER: ap->id: %d, port#: %d\n",
299 __FUNCTION__, ap->id, ap->port_no);
300
301 if (!ata_dev_enabled(atadev) || (ap->flags & ATA_FLAG_DISABLED)) {
302 if (ata_msg_probe(ap))
303 ata_dev_printk(atadev, KERN_DEBUG, "%s: ERR: "
304 "ata_dev_present: %d, PORT_DISABLED: %lu\n",
305 __FUNCTION__, ata_dev_enabled(atadev),
306 ap->flags & ATA_FLAG_DISABLED);
307 goto out;
308 }
309
310 /* Don't continue if device has no _ADR method.
311 * _GTF is intended for known motherboard devices. */
312 if (!(ap->cbl == ATA_CBL_SATA)) {
313 err = pata_get_dev_handle(dev, &dev_handle, &pcidevfn);
314 if (err < 0) {
315 if (ata_msg_probe(ap))
316 ata_dev_printk(atadev, KERN_DEBUG,
317 "%s: pata_get_dev_handle failed (%d)\n",
318 __FUNCTION__, err);
319 goto out;
320 }
321 } else {
322 err = sata_get_dev_handle(dev, &dev_handle, &pcidevfn);
323 if (err < 0) {
324 if (ata_msg_probe(ap))
325 ata_dev_printk(atadev, KERN_DEBUG,
326 "%s: sata_get_dev_handle failed (%d\n",
327 __FUNCTION__, err);
328 goto out;
329 }
330 }
331
332 /* Get this drive's _ADR info. if not already known. */
333 if (!atadev->obj_handle) {
334 if (!(ap->cbl == ATA_CBL_SATA)) {
335 /* get child objects of dev_handle == channel objects,
336 * + _their_ children == drive objects */
337 /* channel is ap->port_no */
338 chan_handle = acpi_get_child(dev_handle,
339 ap->port_no);
340 if (ata_msg_probe(ap))
341 ata_dev_printk(atadev, KERN_DEBUG,
342 "%s: chan adr=%d: chan_handle=0x%p\n",
343 __FUNCTION__, ap->port_no,
344 chan_handle);
345 if (!chan_handle) {
346 err = -ENODEV;
347 goto out;
348 }
349 /* TBD: could also check ACPI object VALID bits */
350 drive_handle = acpi_get_child(chan_handle, ix);
351 if (!drive_handle) {
352 err = -ENODEV;
353 goto out;
354 }
355 dev_adr = ix;
356 atadev->obj_handle = drive_handle;
357 } else { /* for SATA mode */
358 dev_adr = SATA_ADR_RSVD;
359 err = get_sata_adr(dev, dev_handle, pcidevfn, 0,
360 ap, atadev, &dev_adr);
361 }
362 if (err < 0 || dev_adr == SATA_ADR_RSVD ||
363 !atadev->obj_handle) {
364 if (ata_msg_probe(ap))
365 ata_dev_printk(atadev, KERN_DEBUG,
366 "%s: get_sata/pata_adr failed: "
367 "err=%d, dev_adr=%u, obj_handle=0x%p\n",
368 __FUNCTION__, err, dev_adr,
369 atadev->obj_handle);
370 goto out;
371 }
372 }
373
374 /* Setting up output buffer */
375 output.length = ACPI_ALLOCATE_BUFFER;
376 output.pointer = NULL; /* ACPI-CA sets this; save/free it later */
377
378 /* _GTF has no input parameters */
379 err = -EIO;
380 status = acpi_evaluate_object(atadev->obj_handle, "_GTF",
381 NULL, &output);
382 if (ACPI_FAILURE(status)) {
383 if (ata_msg_probe(ap))
384 ata_dev_printk(atadev, KERN_DEBUG,
385 "%s: Run _GTF error: status = 0x%x\n",
386 __FUNCTION__, status);
387 goto out;
388 }
389
390 if (!output.length || !output.pointer) {
391 if (ata_msg_probe(ap))
392 ata_dev_printk(atadev, KERN_DEBUG, "%s: Run _GTF: "
393 "length or ptr is NULL (0x%llx, 0x%p)\n",
394 __FUNCTION__,
395 (unsigned long long)output.length,
396 output.pointer);
397 kfree(output.pointer);
398 goto out;
399 }
400
401 out_obj = output.pointer;
402 if (out_obj->type != ACPI_TYPE_BUFFER) {
403 kfree(output.pointer);
404 if (ata_msg_probe(ap))
405 ata_dev_printk(atadev, KERN_DEBUG, "%s: Run _GTF: "
406 "error: expected object type of "
407 " ACPI_TYPE_BUFFER, got 0x%x\n",
408 __FUNCTION__, out_obj->type);
409 err = -ENOENT;
410 goto out;
411 }
412
413 if (!out_obj->buffer.length || !out_obj->buffer.pointer ||
414 out_obj->buffer.length % REGS_PER_GTF) {
415 if (ata_msg_drv(ap))
416 ata_dev_printk(atadev, KERN_ERR,
417 "%s: unexpected GTF length (%d) or addr (0x%p)\n",
418 __FUNCTION__, out_obj->buffer.length,
419 out_obj->buffer.pointer);
420 err = -ENOENT;
421 goto out;
422 }
423
424 *gtf_length = out_obj->buffer.length;
425 *gtf_address = (unsigned long)out_obj->buffer.pointer;
426 *obj_loc = (unsigned long)out_obj;
427 if (ata_msg_probe(ap))
428 ata_dev_printk(atadev, KERN_DEBUG, "%s: returning "
429 "gtf_length=%d, gtf_address=0x%lx, obj_loc=0x%lx\n",
430 __FUNCTION__, *gtf_length, *gtf_address, *obj_loc);
431 err = 0;
432out:
433 return err;
434}
435
436/**
437 * taskfile_load_raw - send taskfile registers to host controller
438 * @ap: Port to which output is sent
439 * @gtf: raw ATA taskfile register set (0x1f1 - 0x1f7)
440 *
441 * Outputs ATA taskfile to standard ATA host controller using MMIO
442 * or PIO as indicated by the ATA_FLAG_MMIO flag.
443 * Writes the control, feature, nsect, lbal, lbam, and lbah registers.
444 * Optionally (ATA_TFLAG_LBA48) writes hob_feature, hob_nsect,
445 * hob_lbal, hob_lbam, and hob_lbah.
446 *
447 * This function waits for idle (!BUSY and !DRQ) after writing
448 * registers. If the control register has a new value, this
449 * function also waits for idle after writing control and before
450 * writing the remaining registers.
451 *
452 * LOCKING: TBD:
453 * Inherited from caller.
454 */
455static void taskfile_load_raw(struct ata_port *ap,
456 struct ata_device *atadev,
457 const struct taskfile_array *gtf)
458{
459 if (ata_msg_probe(ap))
460 ata_dev_printk(atadev, KERN_DEBUG, "%s: (0x1f1-1f7): hex: "
461 "%02x %02x %02x %02x %02x %02x %02x\n",
462 __FUNCTION__,
463 gtf->tfa[0], gtf->tfa[1], gtf->tfa[2],
464 gtf->tfa[3], gtf->tfa[4], gtf->tfa[5], gtf->tfa[6]);
465
466 if ((gtf->tfa[0] == 0) && (gtf->tfa[1] == 0) && (gtf->tfa[2] == 0)
467 && (gtf->tfa[3] == 0) && (gtf->tfa[4] == 0) && (gtf->tfa[5] == 0)
468 && (gtf->tfa[6] == 0))
469 return;
470
471 if (ap->ops->qc_issue) {
472 struct ata_taskfile tf;
473 unsigned int err;
474
475 ata_tf_init(atadev, &tf);
476
477 /* convert gtf to tf */
478 tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; /* TBD */
479 tf.protocol = atadev->class == ATA_DEV_ATAPI ?
480 ATA_PROT_ATAPI_NODATA : ATA_PROT_NODATA;
481 tf.feature = gtf->tfa[0]; /* 0x1f1 */
482 tf.nsect = gtf->tfa[1]; /* 0x1f2 */
483 tf.lbal = gtf->tfa[2]; /* 0x1f3 */
484 tf.lbam = gtf->tfa[3]; /* 0x1f4 */
485 tf.lbah = gtf->tfa[4]; /* 0x1f5 */
486 tf.device = gtf->tfa[5]; /* 0x1f6 */
487 tf.command = gtf->tfa[6]; /* 0x1f7 */
488
489 err = ata_exec_internal(atadev, &tf, NULL, DMA_NONE, NULL, 0);
490 if (err && ata_msg_probe(ap))
491 ata_dev_printk(atadev, KERN_ERR,
492 "%s: ata_exec_internal failed: %u\n",
493 __FUNCTION__, err);
494 } else
495 if (ata_msg_warn(ap))
496 ata_dev_printk(atadev, KERN_WARNING,
497 "%s: SATA driver is missing qc_issue function"
498 " entry points\n",
499 __FUNCTION__);
500}
501
502/**
503 * do_drive_set_taskfiles - write the drive taskfile settings from _GTF
504 * @ap: the ata_port for the drive
505 * @atadev: target ata_device
506 * @gtf_length: total number of bytes of _GTF taskfiles
507 * @gtf_address: location of _GTF taskfile arrays
508 *
509 * This applies to both PATA and SATA drives.
510 *
511 * Write {gtf_address, length gtf_length} in groups of
512 * REGS_PER_GTF bytes.
513 */
514static int do_drive_set_taskfiles(struct ata_port *ap,
515 struct ata_device *atadev, unsigned int gtf_length,
516 unsigned long gtf_address)
517{
518 int err = -ENODEV;
519 int gtf_count = gtf_length / REGS_PER_GTF;
520 int ix;
521 struct taskfile_array *gtf;
522
523 if (ata_msg_probe(ap))
524 ata_dev_printk(atadev, KERN_DEBUG,
525 "%s: ENTER: ap->id: %d, port#: %d\n",
526 __FUNCTION__, ap->id, ap->port_no);
527
528 if (noacpi || !(ap->cbl == ATA_CBL_SATA))
529 return 0;
530
531 if (!ata_dev_enabled(atadev) || (ap->flags & ATA_FLAG_DISABLED))
532 goto out;
533 if (!gtf_count) /* shouldn't be here */
534 goto out;
535
536 if (gtf_length % REGS_PER_GTF) {
537 if (ata_msg_drv(ap))
538 ata_dev_printk(atadev, KERN_ERR,
539 "%s: unexpected GTF length (%d)\n",
540 __FUNCTION__, gtf_length);
541 goto out;
542 }
543
544 for (ix = 0; ix < gtf_count; ix++) {
545 gtf = (struct taskfile_array *)
546 (gtf_address + ix * REGS_PER_GTF);
547
548 /* send all TaskFile registers (0x1f1-0x1f7) *in*that*order* */
549 taskfile_load_raw(ap, atadev, gtf);
550 }
551
552 err = 0;
553out:
554 return err;
555}
556
557/**
558 * ata_acpi_exec_tfs - get then write drive taskfile settings
559 * @ap: the ata_port for the drive
560 *
561 * This applies to both PATA and SATA drives.
562 */
563int ata_acpi_exec_tfs(struct ata_port *ap)
564{
565 int ix;
566 int ret =0;
567 unsigned int gtf_length;
568 unsigned long gtf_address;
569 unsigned long obj_loc;
570
571 if (noacpi)
572 return 0;
573
574 for (ix = 0; ix < ATA_MAX_DEVICES; ix++) {
575 if (!ata_dev_enabled(&ap->device[ix]))
576 continue;
577
578 ret = do_drive_get_GTF(ap, ix,
579 &gtf_length, &gtf_address, &obj_loc);
580 if (ret < 0) {
581 if (ata_msg_probe(ap))
582 ata_port_printk(ap, KERN_DEBUG,
583 "%s: get_GTF error (%d)\n",
584 __FUNCTION__, ret);
585 break;
586 }
587
588 ret = do_drive_set_taskfiles(ap, &ap->device[ix],
589 gtf_length, gtf_address);
590 kfree((void *)obj_loc);
591 if (ret < 0) {
592 if (ata_msg_probe(ap))
593 ata_port_printk(ap, KERN_DEBUG,
594 "%s: set_taskfiles error (%d)\n",
595 __FUNCTION__, ret);
596 break;
597 }
598 }
599
600 return ret;
601}
602
603/**
604 * ata_acpi_push_id - send Identify data to drive
605 * @ap: the ata_port for the drive
606 * @ix: drive index
607 *
608 * _SDD ACPI object: for SATA mode only
609 * Must be after Identify (Packet) Device -- uses its data
610 * ATM this function never returns a failure. It is an optional
611 * method and if it fails for whatever reason, we should still
612 * just keep going.
613 */
614int ata_acpi_push_id(struct ata_port *ap, unsigned int ix)
615{
616 acpi_handle handle;
617 acpi_integer pcidevfn;
618 int err;
619 struct device *dev = ap->host->dev;
620 struct ata_device *atadev = &ap->device[ix];
621 u32 dev_adr;
622 acpi_status status;
623 struct acpi_object_list input;
624 union acpi_object in_params[1];
625
626 if (noacpi)
627 return 0;
628
629 if (ata_msg_probe(ap))
630 ata_dev_printk(atadev, KERN_DEBUG,
631 "%s: ap->id: %d, ix = %d, port#: %d\n",
632 __FUNCTION__, ap->id, ix, ap->port_no);
633
634 /* Don't continue if not a SATA device. */
635 if (!(ap->cbl == ATA_CBL_SATA)) {
636 if (ata_msg_probe(ap))
637 ata_dev_printk(atadev, KERN_DEBUG,
638 "%s: Not a SATA device\n", __FUNCTION__);
639 goto out;
640 }
641
642 /* Don't continue if device has no _ADR method.
643 * _SDD is intended for known motherboard devices. */
644 err = sata_get_dev_handle(dev, &handle, &pcidevfn);
645 if (err < 0) {
646 if (ata_msg_probe(ap))
647 ata_dev_printk(atadev, KERN_DEBUG,
648 "%s: sata_get_dev_handle failed (%d\n",
649 __FUNCTION__, err);
650 goto out;
651 }
652
653 /* Get this drive's _ADR info, if not already known */
654 if (!atadev->obj_handle) {
655 dev_adr = SATA_ADR_RSVD;
656 err = get_sata_adr(dev, handle, pcidevfn, ix, ap, atadev,
657 &dev_adr);
658 if (err < 0 || dev_adr == SATA_ADR_RSVD ||
659 !atadev->obj_handle) {
660 if (ata_msg_probe(ap))
661 ata_dev_printk(atadev, KERN_DEBUG,
662 "%s: get_sata_adr failed: "
663 "err=%d, dev_adr=%u, obj_handle=0x%p\n",
664 __FUNCTION__, err, dev_adr,
665 atadev->obj_handle);
666 goto out;
667 }
668 }
669
670 /* Give the drive Identify data to the drive via the _SDD method */
671 /* _SDD: set up input parameters */
672 input.count = 1;
673 input.pointer = in_params;
674 in_params[0].type = ACPI_TYPE_BUFFER;
675 in_params[0].buffer.length = sizeof(atadev->id[0]) * ATA_ID_WORDS;
676 in_params[0].buffer.pointer = (u8 *)atadev->id;
677 /* Output buffer: _SDD has no output */
678
679 /* It's OK for _SDD to be missing too. */
680 swap_buf_le16(atadev->id, ATA_ID_WORDS);
681 status = acpi_evaluate_object(atadev->obj_handle, "_SDD", &input, NULL);
682 swap_buf_le16(atadev->id, ATA_ID_WORDS);
683
684 err = ACPI_FAILURE(status) ? -EIO : 0;
685 if (err < 0) {
686 if (ata_msg_probe(ap))
687 ata_dev_printk(atadev, KERN_DEBUG,
688 "ata%u(%u): %s _SDD error: status = 0x%x\n",
689 ap->id, ap->device->devno,
690 __FUNCTION__, status);
691 }
692
693 /* always return success */
694out:
695 return 0;
696}
697
698
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index 2cf8251728d2..e900c5edefc4 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -93,6 +93,10 @@ static int ata_probe_timeout = ATA_TMOUT_INTERNAL / HZ;
93module_param(ata_probe_timeout, int, 0444); 93module_param(ata_probe_timeout, int, 0444);
94MODULE_PARM_DESC(ata_probe_timeout, "Set ATA probing timeout (seconds)"); 94MODULE_PARM_DESC(ata_probe_timeout, "Set ATA probing timeout (seconds)");
95 95
96int noacpi;
97module_param(noacpi, int, 0444);
98MODULE_PARM_DESC(noacpi, "Disables the use of ACPI in suspend/resume when set");
99
96MODULE_AUTHOR("Jeff Garzik"); 100MODULE_AUTHOR("Jeff Garzik");
97MODULE_DESCRIPTION("Library module for ATA devices"); 101MODULE_DESCRIPTION("Library module for ATA devices");
98MODULE_LICENSE("GPL"); 102MODULE_LICENSE("GPL");
@@ -1564,6 +1568,16 @@ int ata_dev_configure(struct ata_device *dev)
1564 ata_dev_printk(dev, KERN_DEBUG, "%s: ENTER, host %u, dev %u\n", 1568 ata_dev_printk(dev, KERN_DEBUG, "%s: ENTER, host %u, dev %u\n",
1565 __FUNCTION__, ap->id, dev->devno); 1569 __FUNCTION__, ap->id, dev->devno);
1566 1570
1571 /* set _SDD */
1572 rc = ata_acpi_push_id(ap, dev->devno);
1573 if (rc) {
1574 ata_dev_printk(dev, KERN_WARNING, "failed to set _SDD(%d)\n",
1575 rc);
1576 }
1577
1578 /* retrieve and execute the ATA task file of _GTF */
1579 ata_acpi_exec_tfs(ap);
1580
1567 /* print device capabilities */ 1581 /* print device capabilities */
1568 if (ata_msg_probe(ap)) 1582 if (ata_msg_probe(ap))
1569 ata_dev_printk(dev, KERN_DEBUG, 1583 ata_dev_printk(dev, KERN_DEBUG,
diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
index 06ccf230e3c2..0ad7781d72a3 100644
--- a/drivers/ata/libata.h
+++ b/drivers/ata/libata.h
@@ -47,6 +47,7 @@ extern struct workqueue_struct *ata_aux_wq;
47extern int atapi_enabled; 47extern int atapi_enabled;
48extern int atapi_dmadir; 48extern int atapi_dmadir;
49extern int libata_fua; 49extern int libata_fua;
50extern int noacpi;
50extern struct ata_queued_cmd *ata_qc_new_init(struct ata_device *dev); 51extern struct ata_queued_cmd *ata_qc_new_init(struct ata_device *dev);
51extern int ata_build_rw_tf(struct ata_taskfile *tf, struct ata_device *dev, 52extern int ata_build_rw_tf(struct ata_taskfile *tf, struct ata_device *dev,
52 u64 block, u32 n_block, unsigned int tf_flags, 53 u64 block, u32 n_block, unsigned int tf_flags,
@@ -87,6 +88,20 @@ extern void ata_port_init(struct ata_port *ap, struct ata_host *host,
87extern struct ata_probe_ent *ata_probe_ent_alloc(struct device *dev, 88extern struct ata_probe_ent *ata_probe_ent_alloc(struct device *dev,
88 const struct ata_port_info *port); 89 const struct ata_port_info *port);
89 90
91/* libata-acpi.c */
92#ifdef CONFIG_SATA_ACPI
93extern int ata_acpi_exec_tfs(struct ata_port *ap);
94extern int ata_acpi_push_id(struct ata_port *ap, unsigned int ix);
95#else
96static inline int ata_acpi_exec_tfs(struct ata_port *ap)
97{
98 return 0;
99}
100static inline int ata_acpi_push_id(struct ata_port *ap, unsigned int ix)
101{
102 return 0;
103}
104#endif
90 105
91/* libata-scsi.c */ 106/* libata-scsi.c */
92extern struct scsi_transport_template ata_scsi_transport_template; 107extern struct scsi_transport_template ata_scsi_transport_template;
diff --git a/drivers/atm/he.c b/drivers/atm/he.c
index db33f6f4dd2a..8510026b690a 100644
--- a/drivers/atm/he.c
+++ b/drivers/atm/he.c
@@ -3017,7 +3017,7 @@ read_prom_byte(struct he_dev *he_dev, int addr)
3017 he_writel(he_dev, val, HOST_CNTL); 3017 he_writel(he_dev, val, HOST_CNTL);
3018 3018
3019 /* Send READ instruction */ 3019 /* Send READ instruction */
3020 for (i = 0; i < sizeof(readtab)/sizeof(readtab[0]); i++) { 3020 for (i = 0; i < ARRAY_SIZE(readtab); i++) {
3021 he_writel(he_dev, val | readtab[i], HOST_CNTL); 3021 he_writel(he_dev, val | readtab[i], HOST_CNTL);
3022 udelay(EEPROM_DELAY); 3022 udelay(EEPROM_DELAY);
3023 } 3023 }
diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
index f40786121948..b4b80140c398 100644
--- a/drivers/atm/idt77252.c
+++ b/drivers/atm/idt77252.c
@@ -388,7 +388,7 @@ idt77252_eeprom_read_status(struct idt77252_dev *card)
388 388
389 gp = idt77252_read_gp(card) & ~(SAR_GP_EESCLK|SAR_GP_EECS|SAR_GP_EEDO); 389 gp = idt77252_read_gp(card) & ~(SAR_GP_EESCLK|SAR_GP_EECS|SAR_GP_EEDO);
390 390
391 for (i = 0; i < sizeof(rdsrtab)/sizeof(rdsrtab[0]); i++) { 391 for (i = 0; i < ARRAY_SIZE(rdsrtab); i++) {
392 idt77252_write_gp(card, gp | rdsrtab[i]); 392 idt77252_write_gp(card, gp | rdsrtab[i]);
393 udelay(5); 393 udelay(5);
394 } 394 }
@@ -422,7 +422,7 @@ idt77252_eeprom_read_byte(struct idt77252_dev *card, u8 offset)
422 422
423 gp = idt77252_read_gp(card) & ~(SAR_GP_EESCLK|SAR_GP_EECS|SAR_GP_EEDO); 423 gp = idt77252_read_gp(card) & ~(SAR_GP_EESCLK|SAR_GP_EECS|SAR_GP_EEDO);
424 424
425 for (i = 0; i < sizeof(rdtab)/sizeof(rdtab[0]); i++) { 425 for (i = 0; i < ARRAY_SIZE(rdtab); i++) {
426 idt77252_write_gp(card, gp | rdtab[i]); 426 idt77252_write_gp(card, gp | rdtab[i]);
427 udelay(5); 427 udelay(5);
428 } 428 }
@@ -469,14 +469,14 @@ idt77252_eeprom_write_byte(struct idt77252_dev *card, u8 offset, u8 data)
469 469
470 gp = idt77252_read_gp(card) & ~(SAR_GP_EESCLK|SAR_GP_EECS|SAR_GP_EEDO); 470 gp = idt77252_read_gp(card) & ~(SAR_GP_EESCLK|SAR_GP_EECS|SAR_GP_EEDO);
471 471
472 for (i = 0; i < sizeof(wrentab)/sizeof(wrentab[0]); i++) { 472 for (i = 0; i < ARRAY_SIZE(wrentab); i++) {
473 idt77252_write_gp(card, gp | wrentab[i]); 473 idt77252_write_gp(card, gp | wrentab[i]);
474 udelay(5); 474 udelay(5);
475 } 475 }
476 idt77252_write_gp(card, gp | SAR_GP_EECS); 476 idt77252_write_gp(card, gp | SAR_GP_EECS);
477 udelay(5); 477 udelay(5);
478 478
479 for (i = 0; i < sizeof(wrtab)/sizeof(wrtab[0]); i++) { 479 for (i = 0; i < ARRAY_SIZE(wrtab); i++) {
480 idt77252_write_gp(card, gp | wrtab[i]); 480 idt77252_write_gp(card, gp | wrtab[i]);
481 udelay(5); 481 udelay(5);
482 } 482 }
diff --git a/drivers/atm/nicstarmac.c b/drivers/atm/nicstarmac.c
index 2c5e3ae77503..480947f4e01e 100644
--- a/drivers/atm/nicstarmac.c
+++ b/drivers/atm/nicstarmac.c
@@ -7,6 +7,8 @@
7 * Read this ForeRunner's MAC address from eprom/eeprom 7 * Read this ForeRunner's MAC address from eprom/eeprom
8 */ 8 */
9 9
10#include <linux/kernel.h>
11
10typedef void __iomem *virt_addr_t; 12typedef void __iomem *virt_addr_t;
11 13
12#define CYCLE_DELAY 5 14#define CYCLE_DELAY 5
@@ -176,7 +178,7 @@ read_eprom_byte(virt_addr_t base, u_int8_t offset)
176 val = NICSTAR_REG_READ( base, NICSTAR_REG_GENERAL_PURPOSE ) & 0xFFFFFFF0; 178 val = NICSTAR_REG_READ( base, NICSTAR_REG_GENERAL_PURPOSE ) & 0xFFFFFFF0;
177 179
178 /* Send READ instruction */ 180 /* Send READ instruction */
179 for (i=0; i<sizeof readtab/sizeof readtab[0]; i++) 181 for (i=0; i<ARRAY_SIZE(readtab); i++)
180 { 182 {
181 NICSTAR_REG_WRITE( base, NICSTAR_REG_GENERAL_PURPOSE, 183 NICSTAR_REG_WRITE( base, NICSTAR_REG_GENERAL_PURPOSE,
182 (val | readtab[i]) ); 184 (val | readtab[i]) );
diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index 472810f8e6e7..253868e03c70 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -324,27 +324,25 @@ int bus_for_each_drv(struct bus_type * bus, struct device_driver * start,
324 return error; 324 return error;
325} 325}
326 326
327static int device_add_attrs(struct bus_type * bus, struct device * dev) 327static int device_add_attrs(struct bus_type *bus, struct device *dev)
328{ 328{
329 int error = 0; 329 int error = 0;
330 int i; 330 int i;
331 331
332 if (bus->dev_attrs) { 332 if (!bus->dev_attrs)
333 for (i = 0; attr_name(bus->dev_attrs[i]); i++) { 333 return 0;
334 error = device_create_file(dev,&bus->dev_attrs[i]); 334
335 if (error) 335 for (i = 0; attr_name(bus->dev_attrs[i]); i++) {
336 goto Err; 336 error = device_create_file(dev,&bus->dev_attrs[i]);
337 if (error) {
338 while (--i >= 0)
339 device_remove_file(dev, &bus->dev_attrs[i]);
340 break;
337 } 341 }
338 } 342 }
339 Done:
340 return error; 343 return error;
341 Err:
342 while (--i >= 0)
343 device_remove_file(dev,&bus->dev_attrs[i]);
344 goto Done;
345} 344}
346 345
347
348static void device_remove_attrs(struct bus_type * bus, struct device * dev) 346static void device_remove_attrs(struct bus_type * bus, struct device * dev)
349{ 347{
350 int i; 348 int i;
diff --git a/drivers/base/class.c b/drivers/base/class.c
index 96def1ddba19..1417e5cd4c6f 100644
--- a/drivers/base/class.c
+++ b/drivers/base/class.c
@@ -163,8 +163,7 @@ int class_register(struct class * cls)
163void class_unregister(struct class * cls) 163void class_unregister(struct class * cls)
164{ 164{
165 pr_debug("device class '%s': unregistering\n", cls->name); 165 pr_debug("device class '%s': unregistering\n", cls->name);
166 if (cls->virtual_dir) 166 kobject_unregister(cls->virtual_dir);
167 kobject_unregister(cls->virtual_dir);
168 remove_class_attrs(cls); 167 remove_class_attrs(cls);
169 subsystem_unregister(&cls->subsys); 168 subsystem_unregister(&cls->subsys);
170} 169}
diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c
index 7fd095efaebd..fe7ef3394144 100644
--- a/drivers/base/cpu.c
+++ b/drivers/base/cpu.c
@@ -103,7 +103,7 @@ static SYSDEV_ATTR(crash_notes, 0400, show_crash_notes, NULL);
103#endif 103#endif
104 104
105/* 105/*
106 * register_cpu - Setup a driverfs device for a CPU. 106 * register_cpu - Setup a sysfs device for a CPU.
107 * @cpu - cpu->hotpluggable field set to 1 will generate a control file in 107 * @cpu - cpu->hotpluggable field set to 1 will generate a control file in
108 * sysfs for this CPU. 108 * sysfs for this CPU.
109 * @num - CPU number to use when creating the device. 109 * @num - CPU number to use when creating the device.
diff --git a/drivers/base/node.c b/drivers/base/node.c
index 475e33f76e0d..cae346ef1b20 100644
--- a/drivers/base/node.c
+++ b/drivers/base/node.c
@@ -133,7 +133,7 @@ static SYSDEV_ATTR(distance, S_IRUGO, node_read_distance, NULL);
133 133
134 134
135/* 135/*
136 * register_node - Setup a driverfs device for a node. 136 * register_node - Setup a sysfs device for a node.
137 * @num - Node number to use when creating the device. 137 * @num - Node number to use when creating the device.
138 * 138 *
139 * Initialize and register the node device. 139 * Initialize and register the node device.
diff --git a/drivers/char/rio/rio_linux.c b/drivers/char/rio/rio_linux.c
index 85c161845260..294e9cb0c449 100644
--- a/drivers/char/rio/rio_linux.c
+++ b/drivers/char/rio/rio_linux.c
@@ -1146,7 +1146,7 @@ static int __init rio_init(void)
1146 rio_dprintk(RIO_DEBUG_INIT, "Enabling interrupts on rio card.\n"); 1146 rio_dprintk(RIO_DEBUG_INIT, "Enabling interrupts on rio card.\n");
1147 hp->Mode |= RIO_PCI_INT_ENABLE; 1147 hp->Mode |= RIO_PCI_INT_ENABLE;
1148 } else 1148 } else
1149 hp->Mode &= !RIO_PCI_INT_ENABLE; 1149 hp->Mode &= ~RIO_PCI_INT_ENABLE;
1150 rio_dprintk(RIO_DEBUG_INIT, "New Mode: %x\n", hp->Mode); 1150 rio_dprintk(RIO_DEBUG_INIT, "New Mode: %x\n", hp->Mode);
1151 rio_start_card_running(hp); 1151 rio_start_card_running(hp);
1152 } 1152 }
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index 891ef6d0b1bf..c3d4856fb618 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -73,6 +73,17 @@ config SENSORS_ADM1026
73 This driver can also be built as a module. If so, the module 73 This driver can also be built as a module. If so, the module
74 will be called adm1026. 74 will be called adm1026.
75 75
76config SENSORS_ADM1029
77 tristate "Analog Devices ADM1029"
78 depends on HWMON && I2C && EXPERIMENTAL
79 help
80 If you say yes here you get support for Analog Devices ADM1029
81 sensor chip.
82 Very rare chip, please let us know you use it.
83
84 This driver can also be built as a module. If so, the module
85 will be called adm1029.
86
76config SENSORS_ADM1031 87config SENSORS_ADM1031
77 tristate "Analog Devices ADM1031 and compatibles" 88 tristate "Analog Devices ADM1031 and compatibles"
78 depends on HWMON && I2C && EXPERIMENTAL 89 depends on HWMON && I2C && EXPERIMENTAL
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index 31661124271e..4165c27a2f25 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -17,6 +17,7 @@ obj-$(CONFIG_SENSORS_ABITUGURU) += abituguru.o
17obj-$(CONFIG_SENSORS_ADM1021) += adm1021.o 17obj-$(CONFIG_SENSORS_ADM1021) += adm1021.o
18obj-$(CONFIG_SENSORS_ADM1025) += adm1025.o 18obj-$(CONFIG_SENSORS_ADM1025) += adm1025.o
19obj-$(CONFIG_SENSORS_ADM1026) += adm1026.o 19obj-$(CONFIG_SENSORS_ADM1026) += adm1026.o
20obj-$(CONFIG_SENSORS_ADM1029) += adm1029.o
20obj-$(CONFIG_SENSORS_ADM1031) += adm1031.o 21obj-$(CONFIG_SENSORS_ADM1031) += adm1031.o
21obj-$(CONFIG_SENSORS_ADM9240) += adm9240.o 22obj-$(CONFIG_SENSORS_ADM9240) += adm9240.o
22obj-$(CONFIG_SENSORS_AMS) += ams/ 23obj-$(CONFIG_SENSORS_AMS) += ams/
diff --git a/drivers/hwmon/abituguru.c b/drivers/hwmon/abituguru.c
index b1dc63e4ac7b..bede4d990ea6 100644
--- a/drivers/hwmon/abituguru.c
+++ b/drivers/hwmon/abituguru.c
@@ -1267,30 +1267,42 @@ static int __devinit abituguru_probe(struct platform_device *pdev)
1267 printk(KERN_INFO ABIT_UGURU_NAME ": found Abit uGuru\n"); 1267 printk(KERN_INFO ABIT_UGURU_NAME ": found Abit uGuru\n");
1268 1268
1269 /* Register sysfs hooks */ 1269 /* Register sysfs hooks */
1270 data->class_dev = hwmon_device_register(&pdev->dev);
1271 if (IS_ERR(data->class_dev)) {
1272 res = PTR_ERR(data->class_dev);
1273 goto abituguru_probe_error;
1274 }
1275 for (i = 0; i < sysfs_attr_i; i++) 1270 for (i = 0; i < sysfs_attr_i; i++)
1276 device_create_file(&pdev->dev, &data->sysfs_attr[i].dev_attr); 1271 if (device_create_file(&pdev->dev,
1272 &data->sysfs_attr[i].dev_attr))
1273 goto abituguru_probe_error;
1277 for (i = 0; i < ARRAY_SIZE(abituguru_sysfs_attr); i++) 1274 for (i = 0; i < ARRAY_SIZE(abituguru_sysfs_attr); i++)
1278 device_create_file(&pdev->dev, 1275 if (device_create_file(&pdev->dev,
1279 &abituguru_sysfs_attr[i].dev_attr); 1276 &abituguru_sysfs_attr[i].dev_attr))
1277 goto abituguru_probe_error;
1280 1278
1281 return 0; 1279 data->class_dev = hwmon_device_register(&pdev->dev);
1280 if (!IS_ERR(data->class_dev))
1281 return 0; /* success */
1282 1282
1283 res = PTR_ERR(data->class_dev);
1283abituguru_probe_error: 1284abituguru_probe_error:
1285 for (i = 0; data->sysfs_attr[i].dev_attr.attr.name; i++)
1286 device_remove_file(&pdev->dev, &data->sysfs_attr[i].dev_attr);
1287 for (i = 0; i < ARRAY_SIZE(abituguru_sysfs_attr); i++)
1288 device_remove_file(&pdev->dev,
1289 &abituguru_sysfs_attr[i].dev_attr);
1284 kfree(data); 1290 kfree(data);
1285 return res; 1291 return res;
1286} 1292}
1287 1293
1288static int __devexit abituguru_remove(struct platform_device *pdev) 1294static int __devexit abituguru_remove(struct platform_device *pdev)
1289{ 1295{
1296 int i;
1290 struct abituguru_data *data = platform_get_drvdata(pdev); 1297 struct abituguru_data *data = platform_get_drvdata(pdev);
1291 1298
1292 platform_set_drvdata(pdev, NULL); 1299 platform_set_drvdata(pdev, NULL);
1293 hwmon_device_unregister(data->class_dev); 1300 hwmon_device_unregister(data->class_dev);
1301 for (i = 0; data->sysfs_attr[i].dev_attr.attr.name; i++)
1302 device_remove_file(&pdev->dev, &data->sysfs_attr[i].dev_attr);
1303 for (i = 0; i < ARRAY_SIZE(abituguru_sysfs_attr); i++)
1304 device_remove_file(&pdev->dev,
1305 &abituguru_sysfs_attr[i].dev_attr);
1294 kfree(data); 1306 kfree(data);
1295 1307
1296 return 0; 1308 return 0;
diff --git a/drivers/hwmon/adm1026.c b/drivers/hwmon/adm1026.c
index b4618b2705f7..ba80cd3258c6 100644
--- a/drivers/hwmon/adm1026.c
+++ b/drivers/hwmon/adm1026.c
@@ -261,7 +261,6 @@ struct pwm_data {
261struct adm1026_data { 261struct adm1026_data {
262 struct i2c_client client; 262 struct i2c_client client;
263 struct class_device *class_dev; 263 struct class_device *class_dev;
264 struct mutex lock;
265 enum chips type; 264 enum chips type;
266 265
267 struct mutex update_lock; 266 struct mutex update_lock;
diff --git a/drivers/hwmon/adm1029.c b/drivers/hwmon/adm1029.c
new file mode 100644
index 000000000000..73ce31b31511
--- /dev/null
+++ b/drivers/hwmon/adm1029.c
@@ -0,0 +1,508 @@
1/*
2 * adm1029.c - Part of lm_sensors, Linux kernel modules for hardware monitoring
3 *
4 * Copyright (C) 2006 Corentin LABBE <corentin.labbe@geomatys.fr>
5 *
6 * Based on LM83 Driver by Jean Delvare <khali@linux-fr.org>
7 *
8 * Give only processor, motherboard temperatures and fan tachs
9 * Very rare chip please let me know if you use it
10 *
11 * http://www.analog.com/UploadedFiles/Data_Sheets/ADM1029.pdf
12 *
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation version 2 of the License
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 */
27
28#include <linux/module.h>
29#include <linux/init.h>
30#include <linux/slab.h>
31#include <linux/jiffies.h>
32#include <linux/i2c.h>
33#include <linux/hwmon-sysfs.h>
34#include <linux/hwmon.h>
35#include <linux/err.h>
36#include <linux/mutex.h>
37
38/*
39 * Addresses to scan
40 */
41
42static unsigned short normal_i2c[] = {
43 0x28, 0x29, 0x2a,
44 0x2b, 0x2c, 0x2d,
45 0x2e, 0x2f, I2C_CLIENT_END
46};
47
48/*
49 * Insmod parameters
50 */
51
52I2C_CLIENT_INSMOD_1(adm1029);
53
54/*
55 * The ADM1029 registers
56 * Manufacturer ID is 0x41 for Analog Devices
57 */
58
59#define ADM1029_REG_MAN_ID 0x0D
60#define ADM1029_REG_CHIP_ID 0x0E
61#define ADM1029_REG_CONFIG 0x01
62#define ADM1029_REG_NB_FAN_SUPPORT 0x02
63
64#define ADM1029_REG_TEMP_DEVICES_INSTALLED 0x06
65
66#define ADM1029_REG_LOCAL_TEMP 0xA0
67#define ADM1029_REG_REMOTE1_TEMP 0xA1
68#define ADM1029_REG_REMOTE2_TEMP 0xA2
69
70#define ADM1029_REG_LOCAL_TEMP_HIGH 0x90
71#define ADM1029_REG_REMOTE1_TEMP_HIGH 0x91
72#define ADM1029_REG_REMOTE2_TEMP_HIGH 0x92
73
74#define ADM1029_REG_LOCAL_TEMP_LOW 0x98
75#define ADM1029_REG_REMOTE1_TEMP_LOW 0x99
76#define ADM1029_REG_REMOTE2_TEMP_LOW 0x9A
77
78#define ADM1029_REG_FAN1 0x70
79#define ADM1029_REG_FAN2 0x71
80
81#define ADM1029_REG_FAN1_MIN 0x78
82#define ADM1029_REG_FAN2_MIN 0x79
83
84#define ADM1029_REG_FAN1_CONFIG 0x68
85#define ADM1029_REG_FAN2_CONFIG 0x69
86
87#define TEMP_FROM_REG(val) ((val) * 1000)
88
89#define DIV_FROM_REG(val) ( 1 << (((val) >> 6) - 1))
90
91/* Registers to be checked by adm1029_update_device() */
92static const u8 ADM1029_REG_TEMP[] = {
93 ADM1029_REG_LOCAL_TEMP,
94 ADM1029_REG_REMOTE1_TEMP,
95 ADM1029_REG_REMOTE2_TEMP,
96 ADM1029_REG_LOCAL_TEMP_HIGH,
97 ADM1029_REG_REMOTE1_TEMP_HIGH,
98 ADM1029_REG_REMOTE2_TEMP_HIGH,
99 ADM1029_REG_LOCAL_TEMP_LOW,
100 ADM1029_REG_REMOTE1_TEMP_LOW,
101 ADM1029_REG_REMOTE2_TEMP_LOW,
102};
103
104static const u8 ADM1029_REG_FAN[] = {
105 ADM1029_REG_FAN1,
106 ADM1029_REG_FAN2,
107 ADM1029_REG_FAN1_MIN,
108 ADM1029_REG_FAN2_MIN,
109};
110
111static const u8 ADM1029_REG_FAN_DIV[] = {
112 ADM1029_REG_FAN1_CONFIG,
113 ADM1029_REG_FAN2_CONFIG,
114};
115
116/*
117 * Functions declaration
118 */
119
120static int adm1029_attach_adapter(struct i2c_adapter *adapter);
121static int adm1029_detect(struct i2c_adapter *adapter, int address, int kind);
122static int adm1029_detach_client(struct i2c_client *client);
123static struct adm1029_data *adm1029_update_device(struct device *dev);
124static int adm1029_init_client(struct i2c_client *client);
125
126/*
127 * Driver data (common to all clients)
128 */
129
130static struct i2c_driver adm1029_driver = {
131 .driver = {
132 .name = "adm1029",
133 },
134 .attach_adapter = adm1029_attach_adapter,
135 .detach_client = adm1029_detach_client,
136};
137
138/*
139 * Client data (each client gets its own)
140 */
141
142struct adm1029_data {
143 struct i2c_client client;
144 struct class_device *class_dev;
145 struct mutex update_lock;
146 char valid; /* zero until following fields are valid */
147 unsigned long last_updated; /* in jiffies */
148
149 /* registers values, signed for temperature, unsigned for other stuff */
150 s8 temp[ARRAY_SIZE(ADM1029_REG_TEMP)];
151 u8 fan[ARRAY_SIZE(ADM1029_REG_FAN)];
152 u8 fan_div[ARRAY_SIZE(ADM1029_REG_FAN_DIV)];
153};
154
155/*
156 * Sysfs stuff
157 */
158
159static ssize_t
160show_temp(struct device *dev, struct device_attribute *devattr, char *buf)
161{
162 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
163 struct adm1029_data *data = adm1029_update_device(dev);
164 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[attr->index]));
165}
166
167static ssize_t
168show_fan(struct device *dev, struct device_attribute *devattr, char *buf)
169{
170 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
171 struct adm1029_data *data = adm1029_update_device(dev);
172 u16 val;
173 if (data->fan[attr->index] == 0 || data->fan_div[attr->index] == 0
174 || data->fan[attr->index] == 255) {
175 return sprintf(buf, "0\n");
176 }
177
178 val = 1880 * 120 / DIV_FROM_REG(data->fan_div[attr->index])
179 / data->fan[attr->index];
180 return sprintf(buf, "%d\n", val);
181}
182
183static ssize_t
184show_fan_div(struct device *dev, struct device_attribute *devattr, char *buf)
185{
186 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
187 struct adm1029_data *data = adm1029_update_device(dev);
188 if (data->fan_div[attr->index] == 0)
189 return sprintf(buf, "0\n");
190 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[attr->index]));
191}
192
193static ssize_t set_fan_div(struct device *dev,
194 struct device_attribute *devattr, const char *buf, size_t count)
195{
196 struct i2c_client *client = to_i2c_client(dev);
197 struct adm1029_data *data = i2c_get_clientdata(client);
198 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
199 long val = simple_strtol(buf, NULL, 10);
200 u8 reg;
201
202 mutex_lock(&data->update_lock);
203
204 /*Read actual config */
205 reg = i2c_smbus_read_byte_data(client,
206 ADM1029_REG_FAN_DIV[attr->index]);
207
208 switch (val) {
209 case 1:
210 val = 1;
211 break;
212 case 2:
213 val = 2;
214 break;
215 case 4:
216 val = 3;
217 break;
218 default:
219 mutex_unlock(&data->update_lock);
220 dev_err(&client->dev, "fan_div value %ld not "
221 "supported. Choose one of 1, 2 or 4!\n", val);
222 return -EINVAL;
223 }
224 /* Update the value */
225 reg = (reg & 0x3F) | (val << 6);
226
227 /* Write value */
228 i2c_smbus_write_byte_data(client,
229 ADM1029_REG_FAN_DIV[attr->index], reg);
230 mutex_unlock(&data->update_lock);
231
232 return count;
233}
234
235/*
236Access rights on sysfs, S_IRUGO stand for Is Readable by User, Group and Others
237 S_IWUSR stand for Is Writable by User
238*/
239static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0);
240static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp, NULL, 1);
241static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, show_temp, NULL, 2);
242
243static SENSOR_DEVICE_ATTR(temp1_max, S_IRUGO, show_temp, NULL, 3);
244static SENSOR_DEVICE_ATTR(temp2_max, S_IRUGO, show_temp, NULL, 4);
245static SENSOR_DEVICE_ATTR(temp3_max, S_IRUGO, show_temp, NULL, 5);
246
247static SENSOR_DEVICE_ATTR(temp1_min, S_IRUGO, show_temp, NULL, 6);
248static SENSOR_DEVICE_ATTR(temp2_min, S_IRUGO, show_temp, NULL, 7);
249static SENSOR_DEVICE_ATTR(temp3_min, S_IRUGO, show_temp, NULL, 8);
250
251static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_fan, NULL, 0);
252static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, show_fan, NULL, 1);
253
254static SENSOR_DEVICE_ATTR(fan1_min, S_IRUGO, show_fan, NULL, 2);
255static SENSOR_DEVICE_ATTR(fan2_min, S_IRUGO, show_fan, NULL, 3);
256
257static SENSOR_DEVICE_ATTR(fan1_div, S_IRUGO | S_IWUSR,
258 show_fan_div, set_fan_div, 0);
259static SENSOR_DEVICE_ATTR(fan2_div, S_IRUGO | S_IWUSR,
260 show_fan_div, set_fan_div, 1);
261
262static struct attribute *adm1029_attributes[] = {
263 &sensor_dev_attr_temp1_input.dev_attr.attr,
264 &sensor_dev_attr_temp1_min.dev_attr.attr,
265 &sensor_dev_attr_temp1_max.dev_attr.attr,
266 &sensor_dev_attr_temp2_input.dev_attr.attr,
267 &sensor_dev_attr_temp2_min.dev_attr.attr,
268 &sensor_dev_attr_temp2_max.dev_attr.attr,
269 &sensor_dev_attr_temp3_input.dev_attr.attr,
270 &sensor_dev_attr_temp3_min.dev_attr.attr,
271 &sensor_dev_attr_temp3_max.dev_attr.attr,
272 &sensor_dev_attr_fan1_input.dev_attr.attr,
273 &sensor_dev_attr_fan2_input.dev_attr.attr,
274 &sensor_dev_attr_fan1_min.dev_attr.attr,
275 &sensor_dev_attr_fan2_min.dev_attr.attr,
276 &sensor_dev_attr_fan1_div.dev_attr.attr,
277 &sensor_dev_attr_fan2_div.dev_attr.attr,
278 NULL
279};
280
281static const struct attribute_group adm1029_group = {
282 .attrs = adm1029_attributes,
283};
284
285/*
286 * Real code
287 */
288
289static int adm1029_attach_adapter(struct i2c_adapter *adapter)
290{
291 if (!(adapter->class & I2C_CLASS_HWMON))
292 return 0;
293 return i2c_probe(adapter, &addr_data, adm1029_detect);
294}
295
296/*
297 * The following function does more than just detection. If detection
298 * succeeds, it also registers the new chip.
299 */
300
301static int adm1029_detect(struct i2c_adapter *adapter, int address, int kind)
302{
303 struct i2c_client *client;
304 struct adm1029_data *data;
305 int err = 0;
306 const char *name = "";
307 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
308 goto exit;
309
310 if (!(data = kzalloc(sizeof(struct adm1029_data), GFP_KERNEL))) {
311 err = -ENOMEM;
312 goto exit;
313 }
314
315 client = &data->client;
316 i2c_set_clientdata(client, data);
317 client->addr = address;
318 client->adapter = adapter;
319 client->driver = &adm1029_driver;
320
321 /* Now we do the detection and identification. A negative kind
322 * means that the driver was loaded with no force parameter
323 * (default), so we must both detect and identify the chip
324 * (actually there is only one possible kind of chip for now, adm1029).
325 * A zero kind means that the driver was loaded with the force
326 * parameter, the detection step shall be skipped. A positive kind
327 * means that the driver was loaded with the force parameter and a
328 * given kind of chip is requested, so both the detection and the
329 * identification steps are skipped. */
330
331 /* Default to an adm1029 if forced */
332 if (kind == 0)
333 kind = adm1029;
334
335 /* ADM1029 doesn't have CHIP ID, check just MAN ID
336 * For better detection we check also ADM1029_TEMP_DEVICES_INSTALLED,
337 * ADM1029_REG_NB_FAN_SUPPORT and compare it with possible values
338 * documented
339 */
340
341 if (kind <= 0) { /* identification */
342 u8 man_id, chip_id, temp_devices_installed, nb_fan_support;
343
344 man_id = i2c_smbus_read_byte_data(client, ADM1029_REG_MAN_ID);
345 chip_id = i2c_smbus_read_byte_data(client, ADM1029_REG_CHIP_ID);
346 temp_devices_installed = i2c_smbus_read_byte_data(client,
347 ADM1029_REG_TEMP_DEVICES_INSTALLED);
348 nb_fan_support = i2c_smbus_read_byte_data(client,
349 ADM1029_REG_NB_FAN_SUPPORT);
350 /* 0x41 is Analog Devices */
351 if (man_id == 0x41 && (temp_devices_installed & 0xf9) == 0x01
352 && nb_fan_support == 0x03) {
353 if ((chip_id & 0xF0) == 0x00) {
354 kind = adm1029;
355 } else {
356 /* There are no "official" CHIP ID, so actually
357 * we use Major/Minor revision for that */
358 printk(KERN_INFO
359 "adm1029: Unknown major revision %x, "
360 "please let us know\n", chip_id);
361 }
362 }
363
364 if (kind <= 0) { /* identification failed */
365 pr_debug("adm1029: Unsupported chip (man_id=0x%02X, "
366 "chip_id=0x%02X)\n", man_id, chip_id);
367 goto exit_free;
368 }
369 }
370
371 if (kind == adm1029) {
372 name = "adm1029";
373 }
374
375 /* We can fill in the remaining client fields */
376 strlcpy(client->name, name, I2C_NAME_SIZE);
377 mutex_init(&data->update_lock);
378
379 /* Tell the I2C layer a new client has arrived */
380 if ((err = i2c_attach_client(client)))
381 goto exit_free;
382
383 /*
384 * Initialize the ADM1029 chip
385 * Check config register
386 */
387 if (adm1029_init_client(client) == 0)
388 goto exit_detach;
389
390 /* Register sysfs hooks */
391 if ((err = sysfs_create_group(&client->dev.kobj, &adm1029_group)))
392 goto exit_detach;
393
394 data->class_dev = hwmon_device_register(&client->dev);
395 if (IS_ERR(data->class_dev)) {
396 err = PTR_ERR(data->class_dev);
397 goto exit_remove_files;
398 }
399
400 return 0;
401
402 exit_remove_files:
403 sysfs_remove_group(&client->dev.kobj, &adm1029_group);
404 exit_detach:
405 i2c_detach_client(client);
406 exit_free:
407 kfree(data);
408 exit:
409 return err;
410}
411
412static int adm1029_init_client(struct i2c_client *client)
413{
414 u8 config;
415 config = i2c_smbus_read_byte_data(client, ADM1029_REG_CONFIG);
416 if ((config & 0x10) == 0) {
417 i2c_smbus_write_byte_data(client, ADM1029_REG_CONFIG,
418 config | 0x10);
419 }
420 /* recheck config */
421 config = i2c_smbus_read_byte_data(client, ADM1029_REG_CONFIG);
422 if ((config & 0x10) == 0) {
423 dev_err(&client->dev, "Initialization failed!\n");
424 return 0;
425 }
426 return 1;
427}
428
429static int adm1029_detach_client(struct i2c_client *client)
430{
431 struct adm1029_data *data = i2c_get_clientdata(client);
432 int err;
433
434 hwmon_device_unregister(data->class_dev);
435 sysfs_remove_group(&client->dev.kobj, &adm1029_group);
436
437 if ((err = i2c_detach_client(client)))
438 return err;
439
440 kfree(data);
441 return 0;
442}
443
444/*
445function that update the status of the chips (temperature for exemple)
446*/
447static struct adm1029_data *adm1029_update_device(struct device *dev)
448{
449 struct i2c_client *client = to_i2c_client(dev);
450 struct adm1029_data *data = i2c_get_clientdata(client);
451
452 mutex_lock(&data->update_lock);
453 /*
454 * Use the "cache" Luke, don't recheck values
455 * if there are already checked not a long time later
456 */
457 if (time_after(jiffies, data->last_updated + HZ * 2)
458 || !data->valid) {
459 int nr;
460
461 dev_dbg(&client->dev, "Updating adm1029 data\n");
462
463 for (nr = 0; nr < ARRAY_SIZE(ADM1029_REG_TEMP); nr++) {
464 data->temp[nr] =
465 i2c_smbus_read_byte_data(client,
466 ADM1029_REG_TEMP[nr]);
467 }
468 for (nr = 0; nr < ARRAY_SIZE(ADM1029_REG_FAN); nr++) {
469 data->fan[nr] =
470 i2c_smbus_read_byte_data(client,
471 ADM1029_REG_FAN[nr]);
472 }
473 for (nr = 0; nr < ARRAY_SIZE(ADM1029_REG_FAN_DIV); nr++) {
474 data->fan_div[nr] =
475 i2c_smbus_read_byte_data(client,
476 ADM1029_REG_FAN_DIV[nr]);
477 }
478
479 data->last_updated = jiffies;
480 data->valid = 1;
481 }
482
483 mutex_unlock(&data->update_lock);
484
485 return data;
486}
487
488/*
489 Common module stuff
490*/
491static int __init sensors_adm1029_init(void)
492{
493
494 return i2c_add_driver(&adm1029_driver);
495}
496
497static void __exit sensors_adm1029_exit(void)
498{
499
500 i2c_del_driver(&adm1029_driver);
501}
502
503MODULE_AUTHOR("Corentin LABBE <corentin.labbe@geomatys.fr>");
504MODULE_DESCRIPTION("adm1029 driver");
505MODULE_LICENSE("GPL v2");
506
507module_init(sensors_adm1029_init);
508module_exit(sensors_adm1029_exit);
diff --git a/drivers/hwmon/f71805f.c b/drivers/hwmon/f71805f.c
index a272cae8f60e..7c2973487122 100644
--- a/drivers/hwmon/f71805f.c
+++ b/drivers/hwmon/f71805f.c
@@ -146,7 +146,6 @@ superio_exit(int base)
146struct f71805f_data { 146struct f71805f_data {
147 unsigned short addr; 147 unsigned short addr;
148 const char *name; 148 const char *name;
149 struct mutex lock;
150 struct class_device *class_dev; 149 struct class_device *class_dev;
151 150
152 struct mutex update_lock; 151 struct mutex update_lock;
@@ -271,50 +270,42 @@ static inline u8 temp_to_reg(long val)
271 * Device I/O access 270 * Device I/O access
272 */ 271 */
273 272
273/* Must be called with data->update_lock held, except during initialization */
274static u8 f71805f_read8(struct f71805f_data *data, u8 reg) 274static u8 f71805f_read8(struct f71805f_data *data, u8 reg)
275{ 275{
276 u8 val;
277
278 mutex_lock(&data->lock);
279 outb(reg, data->addr + ADDR_REG_OFFSET); 276 outb(reg, data->addr + ADDR_REG_OFFSET);
280 val = inb(data->addr + DATA_REG_OFFSET); 277 return inb(data->addr + DATA_REG_OFFSET);
281 mutex_unlock(&data->lock);
282
283 return val;
284} 278}
285 279
280/* Must be called with data->update_lock held, except during initialization */
286static void f71805f_write8(struct f71805f_data *data, u8 reg, u8 val) 281static void f71805f_write8(struct f71805f_data *data, u8 reg, u8 val)
287{ 282{
288 mutex_lock(&data->lock);
289 outb(reg, data->addr + ADDR_REG_OFFSET); 283 outb(reg, data->addr + ADDR_REG_OFFSET);
290 outb(val, data->addr + DATA_REG_OFFSET); 284 outb(val, data->addr + DATA_REG_OFFSET);
291 mutex_unlock(&data->lock);
292} 285}
293 286
294/* It is important to read the MSB first, because doing so latches the 287/* It is important to read the MSB first, because doing so latches the
295 value of the LSB, so we are sure both bytes belong to the same value. */ 288 value of the LSB, so we are sure both bytes belong to the same value.
289 Must be called with data->update_lock held, except during initialization */
296static u16 f71805f_read16(struct f71805f_data *data, u8 reg) 290static u16 f71805f_read16(struct f71805f_data *data, u8 reg)
297{ 291{
298 u16 val; 292 u16 val;
299 293
300 mutex_lock(&data->lock);
301 outb(reg, data->addr + ADDR_REG_OFFSET); 294 outb(reg, data->addr + ADDR_REG_OFFSET);
302 val = inb(data->addr + DATA_REG_OFFSET) << 8; 295 val = inb(data->addr + DATA_REG_OFFSET) << 8;
303 outb(++reg, data->addr + ADDR_REG_OFFSET); 296 outb(++reg, data->addr + ADDR_REG_OFFSET);
304 val |= inb(data->addr + DATA_REG_OFFSET); 297 val |= inb(data->addr + DATA_REG_OFFSET);
305 mutex_unlock(&data->lock);
306 298
307 return val; 299 return val;
308} 300}
309 301
302/* Must be called with data->update_lock held, except during initialization */
310static void f71805f_write16(struct f71805f_data *data, u8 reg, u16 val) 303static void f71805f_write16(struct f71805f_data *data, u8 reg, u16 val)
311{ 304{
312 mutex_lock(&data->lock);
313 outb(reg, data->addr + ADDR_REG_OFFSET); 305 outb(reg, data->addr + ADDR_REG_OFFSET);
314 outb(val >> 8, data->addr + DATA_REG_OFFSET); 306 outb(val >> 8, data->addr + DATA_REG_OFFSET);
315 outb(++reg, data->addr + ADDR_REG_OFFSET); 307 outb(++reg, data->addr + ADDR_REG_OFFSET);
316 outb(val & 0xff, data->addr + DATA_REG_OFFSET); 308 outb(val & 0xff, data->addr + DATA_REG_OFFSET);
317 mutex_unlock(&data->lock);
318} 309}
319 310
320static struct f71805f_data *f71805f_update_device(struct device *dev) 311static struct f71805f_data *f71805f_update_device(struct device *dev)
@@ -1150,7 +1141,6 @@ static int __devinit f71805f_probe(struct platform_device *pdev)
1150 1141
1151 res = platform_get_resource(pdev, IORESOURCE_IO, 0); 1142 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
1152 data->addr = res->start; 1143 data->addr = res->start;
1153 mutex_init(&data->lock);
1154 data->name = names[sio_data->kind]; 1144 data->name = names[sio_data->kind];
1155 mutex_init(&data->update_lock); 1145 mutex_init(&data->update_lock);
1156 1146
@@ -1300,14 +1290,11 @@ static int __init f71805f_device_add(unsigned short address,
1300 if (err) { 1290 if (err) {
1301 printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n", 1291 printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n",
1302 err); 1292 err);
1303 goto exit_kfree_data; 1293 goto exit_device_put;
1304 } 1294 }
1305 1295
1306 return 0; 1296 return 0;
1307 1297
1308exit_kfree_data:
1309 kfree(pdev->dev.platform_data);
1310 pdev->dev.platform_data = NULL;
1311exit_device_put: 1298exit_device_put:
1312 platform_device_put(pdev); 1299 platform_device_put(pdev);
1313exit: 1300exit:
@@ -1400,10 +1387,7 @@ exit:
1400 1387
1401static void __exit f71805f_exit(void) 1388static void __exit f71805f_exit(void)
1402{ 1389{
1403 kfree(pdev->dev.platform_data);
1404 pdev->dev.platform_data = NULL;
1405 platform_device_unregister(pdev); 1390 platform_device_unregister(pdev);
1406
1407 platform_driver_unregister(&f71805f_driver); 1391 platform_driver_unregister(&f71805f_driver);
1408} 1392}
1409 1393
diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c
index 106fa01cdb60..affcc00764d3 100644
--- a/drivers/hwmon/hwmon.c
+++ b/drivers/hwmon/hwmon.c
@@ -101,7 +101,7 @@ static void __exit hwmon_exit(void)
101 class_destroy(hwmon_class); 101 class_destroy(hwmon_class);
102} 102}
103 103
104module_init(hwmon_init); 104subsys_initcall(hwmon_init);
105module_exit(hwmon_exit); 105module_exit(hwmon_exit);
106 106
107EXPORT_SYMBOL_GPL(hwmon_device_register); 107EXPORT_SYMBOL_GPL(hwmon_device_register);
diff --git a/drivers/hwmon/it87.c b/drivers/hwmon/it87.c
index 1ed8b7e2c35d..62afc63708a5 100644
--- a/drivers/hwmon/it87.c
+++ b/drivers/hwmon/it87.c
@@ -202,15 +202,23 @@ static int DIV_TO_REG(int val)
202} 202}
203#define DIV_FROM_REG(val) (1 << (val)) 203#define DIV_FROM_REG(val) (1 << (val))
204 204
205static const unsigned int pwm_freq[8] = {
206 48000000 / 128,
207 24000000 / 128,
208 12000000 / 128,
209 8000000 / 128,
210 6000000 / 128,
211 3000000 / 128,
212 1500000 / 128,
213 750000 / 128,
214};
215
205 216
206/* For each registered IT87, we need to keep some data in memory. That 217/* For each registered chip, we need to keep some data in memory.
207 data is pointed to by it87_list[NR]->data. The structure itself is 218 The structure is dynamically allocated. */
208 dynamically allocated, at the same time when a new it87 client is
209 allocated. */
210struct it87_data { 219struct it87_data {
211 struct i2c_client client; 220 struct i2c_client client;
212 struct class_device *class_dev; 221 struct class_device *class_dev;
213 struct mutex lock;
214 enum chips type; 222 enum chips type;
215 223
216 struct mutex update_lock; 224 struct mutex update_lock;
@@ -232,6 +240,7 @@ struct it87_data {
232 u8 vrm; 240 u8 vrm;
233 u32 alarms; /* Register encoding, combined */ 241 u32 alarms; /* Register encoding, combined */
234 u8 fan_main_ctrl; /* Register value */ 242 u8 fan_main_ctrl; /* Register value */
243 u8 fan_ctl; /* Register value */
235 u8 manual_pwm_ctl[3]; /* manual PWM value set by user */ 244 u8 manual_pwm_ctl[3]; /* manual PWM value set by user */
236}; 245};
237 246
@@ -519,6 +528,14 @@ static ssize_t show_pwm(struct device *dev, struct device_attribute *attr,
519 struct it87_data *data = it87_update_device(dev); 528 struct it87_data *data = it87_update_device(dev);
520 return sprintf(buf,"%d\n", data->manual_pwm_ctl[nr]); 529 return sprintf(buf,"%d\n", data->manual_pwm_ctl[nr]);
521} 530}
531static ssize_t show_pwm_freq(struct device *dev, struct device_attribute *attr,
532 char *buf)
533{
534 struct it87_data *data = it87_update_device(dev);
535 int index = (data->fan_ctl >> 4) & 0x07;
536
537 return sprintf(buf, "%u\n", pwm_freq[index]);
538}
522static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr, 539static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
523 const char *buf, size_t count) 540 const char *buf, size_t count)
524{ 541{
@@ -528,9 +545,10 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
528 struct i2c_client *client = to_i2c_client(dev); 545 struct i2c_client *client = to_i2c_client(dev);
529 struct it87_data *data = i2c_get_clientdata(client); 546 struct it87_data *data = i2c_get_clientdata(client);
530 int val = simple_strtol(buf, NULL, 10); 547 int val = simple_strtol(buf, NULL, 10);
531 u8 reg = it87_read_value(client, IT87_REG_FAN_DIV); 548 u8 reg;
532 549
533 mutex_lock(&data->update_lock); 550 mutex_lock(&data->update_lock);
551 reg = it87_read_value(client, IT87_REG_FAN_DIV);
534 switch (nr) { 552 switch (nr) {
535 case 0: data->fan_div[nr] = reg & 0x07; break; 553 case 0: data->fan_div[nr] = reg & 0x07; break;
536 case 1: data->fan_div[nr] = (reg >> 3) & 0x07; break; 554 case 1: data->fan_div[nr] = (reg >> 3) & 0x07; break;
@@ -639,6 +657,28 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
639 mutex_unlock(&data->update_lock); 657 mutex_unlock(&data->update_lock);
640 return count; 658 return count;
641} 659}
660static ssize_t set_pwm_freq(struct device *dev,
661 struct device_attribute *attr, const char *buf, size_t count)
662{
663 struct i2c_client *client = to_i2c_client(dev);
664 struct it87_data *data = i2c_get_clientdata(client);
665 unsigned long val = simple_strtoul(buf, NULL, 10);
666 int i;
667
668 /* Search for the nearest available frequency */
669 for (i = 0; i < 7; i++) {
670 if (val > (pwm_freq[i] + pwm_freq[i+1]) / 2)
671 break;
672 }
673
674 mutex_lock(&data->update_lock);
675 data->fan_ctl = it87_read_value(client, IT87_REG_FAN_CTL) & 0x8f;
676 data->fan_ctl |= i << 4;
677 it87_write_value(client, IT87_REG_FAN_CTL, data->fan_ctl);
678 mutex_unlock(&data->update_lock);
679
680 return count;
681}
642 682
643#define show_fan_offset(offset) \ 683#define show_fan_offset(offset) \
644static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \ 684static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \
@@ -656,7 +696,10 @@ show_fan_offset(3);
656static SENSOR_DEVICE_ATTR(pwm##offset##_enable, S_IRUGO | S_IWUSR, \ 696static SENSOR_DEVICE_ATTR(pwm##offset##_enable, S_IRUGO | S_IWUSR, \
657 show_pwm_enable, set_pwm_enable, offset - 1); \ 697 show_pwm_enable, set_pwm_enable, offset - 1); \
658static SENSOR_DEVICE_ATTR(pwm##offset, S_IRUGO | S_IWUSR, \ 698static SENSOR_DEVICE_ATTR(pwm##offset, S_IRUGO | S_IWUSR, \
659 show_pwm, set_pwm, offset - 1); 699 show_pwm, set_pwm, offset - 1); \
700static DEVICE_ATTR(pwm##offset##_freq, \
701 (offset == 1 ? S_IRUGO | S_IWUSR : S_IRUGO), \
702 show_pwm_freq, (offset == 1 ? set_pwm_freq : NULL));
660 703
661show_pwm_offset(1); 704show_pwm_offset(1);
662show_pwm_offset(2); 705show_pwm_offset(2);
@@ -904,7 +947,6 @@ static int it87_detect(struct i2c_adapter *adapter)
904 } 947 }
905 948
906 new_client = &data->client; 949 new_client = &data->client;
907 mutex_init(&data->lock);
908 i2c_set_clientdata(new_client, data); 950 i2c_set_clientdata(new_client, data);
909 new_client->addr = isa_address; 951 new_client->addr = isa_address;
910 new_client->adapter = adapter; 952 new_client->adapter = adapter;
@@ -1021,7 +1063,13 @@ static int it87_detect(struct i2c_adapter *adapter)
1021 || (err = device_create_file(&new_client->dev, 1063 || (err = device_create_file(&new_client->dev,
1022 &sensor_dev_attr_pwm2.dev_attr)) 1064 &sensor_dev_attr_pwm2.dev_attr))
1023 || (err = device_create_file(&new_client->dev, 1065 || (err = device_create_file(&new_client->dev,
1024 &sensor_dev_attr_pwm3.dev_attr))) 1066 &sensor_dev_attr_pwm3.dev_attr))
1067 || (err = device_create_file(&new_client->dev,
1068 &dev_attr_pwm1_freq))
1069 || (err = device_create_file(&new_client->dev,
1070 &dev_attr_pwm2_freq))
1071 || (err = device_create_file(&new_client->dev,
1072 &dev_attr_pwm3_freq)))
1025 goto ERROR4; 1073 goto ERROR4;
1026 } 1074 }
1027 1075
@@ -1076,33 +1124,22 @@ static int it87_detach_client(struct i2c_client *client)
1076 return 0; 1124 return 0;
1077} 1125}
1078 1126
1079/* ISA access must be locked explicitly! 1127/* Must be called with data->update_lock held, except during initialization.
1080 We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks, 1128 We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks,
1081 would slow down the IT87 access and should not be necessary. */ 1129 would slow down the IT87 access and should not be necessary. */
1082static int it87_read_value(struct i2c_client *client, u8 reg) 1130static int it87_read_value(struct i2c_client *client, u8 reg)
1083{ 1131{
1084 struct it87_data *data = i2c_get_clientdata(client);
1085 int res;
1086
1087 mutex_lock(&data->lock);
1088 outb_p(reg, client->addr + IT87_ADDR_REG_OFFSET); 1132 outb_p(reg, client->addr + IT87_ADDR_REG_OFFSET);
1089 res = inb_p(client->addr + IT87_DATA_REG_OFFSET); 1133 return inb_p(client->addr + IT87_DATA_REG_OFFSET);
1090 mutex_unlock(&data->lock);
1091
1092 return res;
1093} 1134}
1094 1135
1095/* ISA access must be locked explicitly! 1136/* Must be called with data->update_lock held, except during initialization.
1096 We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks, 1137 We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks,
1097 would slow down the IT87 access and should not be necessary. */ 1138 would slow down the IT87 access and should not be necessary. */
1098static void it87_write_value(struct i2c_client *client, u8 reg, u8 value) 1139static void it87_write_value(struct i2c_client *client, u8 reg, u8 value)
1099{ 1140{
1100 struct it87_data *data = i2c_get_clientdata(client);
1101
1102 mutex_lock(&data->lock);
1103 outb_p(reg, client->addr + IT87_ADDR_REG_OFFSET); 1141 outb_p(reg, client->addr + IT87_ADDR_REG_OFFSET);
1104 outb_p(value, client->addr + IT87_DATA_REG_OFFSET); 1142 outb_p(value, client->addr + IT87_DATA_REG_OFFSET);
1105 mutex_unlock(&data->lock);
1106} 1143}
1107 1144
1108/* Return 1 if and only if the PWM interface is safe to use */ 1145/* Return 1 if and only if the PWM interface is safe to use */
@@ -1316,6 +1353,7 @@ static struct it87_data *it87_update_device(struct device *dev)
1316 (it87_read_value(client, IT87_REG_ALARM2) << 8) | 1353 (it87_read_value(client, IT87_REG_ALARM2) << 8) |
1317 (it87_read_value(client, IT87_REG_ALARM3) << 16); 1354 (it87_read_value(client, IT87_REG_ALARM3) << 16);
1318 data->fan_main_ctrl = it87_read_value(client, IT87_REG_FAN_MAIN_CTRL); 1355 data->fan_main_ctrl = it87_read_value(client, IT87_REG_FAN_MAIN_CTRL);
1356 data->fan_ctl = it87_read_value(client, IT87_REG_FAN_CTL);
1319 1357
1320 data->sensor = it87_read_value(client, IT87_REG_TEMP_ENABLE); 1358 data->sensor = it87_read_value(client, IT87_REG_TEMP_ENABLE);
1321 /* The 8705 does not have VID capability */ 1359 /* The 8705 does not have VID capability */
diff --git a/drivers/hwmon/lm70.c b/drivers/hwmon/lm70.c
index 6ba84731b9cd..7eaae3834e15 100644
--- a/drivers/hwmon/lm70.c
+++ b/drivers/hwmon/lm70.c
@@ -126,7 +126,7 @@ out_dev_reg_failed:
126 return status; 126 return status;
127} 127}
128 128
129static int __exit lm70_remove(struct spi_device *spi) 129static int __devexit lm70_remove(struct spi_device *spi)
130{ 130{
131 struct lm70 *p_lm70 = dev_get_drvdata(&spi->dev); 131 struct lm70 *p_lm70 = dev_get_drvdata(&spi->dev);
132 132
diff --git a/drivers/hwmon/lm78.c b/drivers/hwmon/lm78.c
index 73bc2ffc598d..886786c33916 100644
--- a/drivers/hwmon/lm78.c
+++ b/drivers/hwmon/lm78.c
@@ -125,10 +125,8 @@ static inline int TEMP_FROM_REG(s8 val)
125 bad. Quite a lot of bookkeeping is done. A real driver can often cut 125 bad. Quite a lot of bookkeeping is done. A real driver can often cut
126 some corners. */ 126 some corners. */
127 127
128/* For each registered LM78, we need to keep some data in memory. That 128/* For each registered chip, we need to keep some data in memory.
129 data is pointed to by lm78_list[NR]->data. The structure itself is 129 The structure is dynamically allocated. */
130 dynamically allocated, at the same time when a new lm78 client is
131 allocated. */
132struct lm78_data { 130struct lm78_data {
133 struct i2c_client client; 131 struct i2c_client client;
134 struct class_device *class_dev; 132 struct class_device *class_dev;
diff --git a/drivers/hwmon/lm85.c b/drivers/hwmon/lm85.c
index 2c3293cf69d1..20a8c648280d 100644
--- a/drivers/hwmon/lm85.c
+++ b/drivers/hwmon/lm85.c
@@ -298,11 +298,6 @@ static int ZONE_TO_REG( int zone )
298#define LM85_DATA_INTERVAL (HZ + HZ / 2) 298#define LM85_DATA_INTERVAL (HZ + HZ / 2)
299#define LM85_CONFIG_INTERVAL (1 * 60 * HZ) 299#define LM85_CONFIG_INTERVAL (1 * 60 * HZ)
300 300
301/* For each registered LM85, we need to keep some data in memory. That
302 data is pointed to by lm85_list[NR]->data. The structure itself is
303 dynamically allocated, at the same time when a new lm85 client is
304 allocated. */
305
306/* LM85 can automatically adjust fan speeds based on temperature 301/* LM85 can automatically adjust fan speeds based on temperature
307 * This structure encapsulates an entire Zone config. There are 302 * This structure encapsulates an entire Zone config. There are
308 * three zones (one for each temperature input) on the lm85 303 * three zones (one for each temperature input) on the lm85
@@ -329,10 +324,11 @@ struct lm85_autofan {
329 u8 min_off; /* Min PWM or OFF below "limit", flag */ 324 u8 min_off; /* Min PWM or OFF below "limit", flag */
330}; 325};
331 326
327/* For each registered chip, we need to keep some data in memory.
328 The structure is dynamically allocated. */
332struct lm85_data { 329struct lm85_data {
333 struct i2c_client client; 330 struct i2c_client client;
334 struct class_device *class_dev; 331 struct class_device *class_dev;
335 struct mutex lock;
336 enum chips type; 332 enum chips type;
337 333
338 struct mutex update_lock; 334 struct mutex update_lock;
diff --git a/drivers/hwmon/sis5595.c b/drivers/hwmon/sis5595.c
index 95a4b5d9eaf2..3f400263fc0f 100644
--- a/drivers/hwmon/sis5595.c
+++ b/drivers/hwmon/sis5595.c
@@ -162,10 +162,8 @@ static inline u8 DIV_TO_REG(int val)
162} 162}
163#define DIV_FROM_REG(val) (1 << (val)) 163#define DIV_FROM_REG(val) (1 << (val))
164 164
165/* For the SIS5595, we need to keep some data in memory. That 165/* For each registered chip, we need to keep some data in memory.
166 data is pointed to by sis5595_list[NR]->data. The structure itself is 166 The structure is dynamically allocated. */
167 dynamically allocated, at the time when the new sis5595 client is
168 allocated. */
169struct sis5595_data { 167struct sis5595_data {
170 struct i2c_client client; 168 struct i2c_client client;
171 struct class_device *class_dev; 169 struct class_device *class_dev;
diff --git a/drivers/hwmon/via686a.c b/drivers/hwmon/via686a.c
index f8acada0537a..9a440c8cc520 100644
--- a/drivers/hwmon/via686a.c
+++ b/drivers/hwmon/via686a.c
@@ -292,9 +292,8 @@ static inline long TEMP_FROM_REG10(u16 val)
292#define DIV_FROM_REG(val) (1 << (val)) 292#define DIV_FROM_REG(val) (1 << (val))
293#define DIV_TO_REG(val) ((val)==8?3:(val)==4?2:(val)==1?0:1) 293#define DIV_TO_REG(val) ((val)==8?3:(val)==4?2:(val)==1?0:1)
294 294
295/* For the VIA686A, we need to keep some data in memory. 295/* For each registered chip, we need to keep some data in memory.
296 The structure is dynamically allocated, at the same time when a new 296 The structure is dynamically allocated. */
297 via686a client is allocated. */
298struct via686a_data { 297struct via686a_data {
299 struct i2c_client client; 298 struct i2c_client client;
300 struct class_device *class_dev; 299 struct class_device *class_dev;
diff --git a/drivers/hwmon/vt1211.c b/drivers/hwmon/vt1211.c
index 25cc56003d7a..89c23d6add7b 100644
--- a/drivers/hwmon/vt1211.c
+++ b/drivers/hwmon/vt1211.c
@@ -178,9 +178,10 @@ struct vt1211_data {
178 * Super-I/O constants and functions 178 * Super-I/O constants and functions
179 * --------------------------------------------------------------------- */ 179 * --------------------------------------------------------------------- */
180 180
181/* Configuration & data index port registers */ 181/* Configuration index port registers
182#define SIO_REG_CIP 0x2e 182 * The vt1211 can live at 2 different addresses so we need to probe both */
183#define SIO_REG_DIP 0x2f 183#define SIO_REG_CIP1 0x2e
184#define SIO_REG_CIP2 0x4e
184 185
185/* Configuration registers */ 186/* Configuration registers */
186#define SIO_VT1211_LDN 0x07 /* logical device number */ 187#define SIO_VT1211_LDN 0x07 /* logical device number */
@@ -193,33 +194,33 @@ struct vt1211_data {
193/* VT1211 logical device numbers */ 194/* VT1211 logical device numbers */
194#define SIO_VT1211_LDN_HWMON 0x0b /* HW monitor */ 195#define SIO_VT1211_LDN_HWMON 0x0b /* HW monitor */
195 196
196static inline void superio_outb(int reg, int val) 197static inline void superio_outb(int sio_cip, int reg, int val)
197{ 198{
198 outb(reg, SIO_REG_CIP); 199 outb(reg, sio_cip);
199 outb(val, SIO_REG_DIP); 200 outb(val, sio_cip + 1);
200} 201}
201 202
202static inline int superio_inb(int reg) 203static inline int superio_inb(int sio_cip, int reg)
203{ 204{
204 outb(reg, SIO_REG_CIP); 205 outb(reg, sio_cip);
205 return inb(SIO_REG_DIP); 206 return inb(sio_cip + 1);
206} 207}
207 208
208static inline void superio_select(int ldn) 209static inline void superio_select(int sio_cip, int ldn)
209{ 210{
210 outb(SIO_VT1211_LDN, SIO_REG_CIP); 211 outb(SIO_VT1211_LDN, sio_cip);
211 outb(ldn, SIO_REG_DIP); 212 outb(ldn, sio_cip + 1);
212} 213}
213 214
214static inline void superio_enter(void) 215static inline void superio_enter(int sio_cip)
215{ 216{
216 outb(0x87, SIO_REG_CIP); 217 outb(0x87, sio_cip);
217 outb(0x87, SIO_REG_CIP); 218 outb(0x87, sio_cip);
218} 219}
219 220
220static inline void superio_exit(void) 221static inline void superio_exit(int sio_cip)
221{ 222{
222 outb(0xaa, SIO_REG_CIP); 223 outb(0xaa, sio_cip);
223} 224}
224 225
225/* --------------------------------------------------------------------- 226/* ---------------------------------------------------------------------
@@ -1263,26 +1264,26 @@ EXIT:
1263 return err; 1264 return err;
1264} 1265}
1265 1266
1266static int __init vt1211_find(unsigned short *address) 1267static int __init vt1211_find(int sio_cip, unsigned short *address)
1267{ 1268{
1268 int err = -ENODEV; 1269 int err = -ENODEV;
1269 1270
1270 superio_enter(); 1271 superio_enter(sio_cip);
1271 1272
1272 if (superio_inb(SIO_VT1211_DEVID) != SIO_VT1211_ID) { 1273 if (superio_inb(sio_cip, SIO_VT1211_DEVID) != SIO_VT1211_ID) {
1273 goto EXIT; 1274 goto EXIT;
1274 } 1275 }
1275 1276
1276 superio_select(SIO_VT1211_LDN_HWMON); 1277 superio_select(sio_cip, SIO_VT1211_LDN_HWMON);
1277 1278
1278 if ((superio_inb(SIO_VT1211_ACTIVE) & 1) == 0) { 1279 if ((superio_inb(sio_cip, SIO_VT1211_ACTIVE) & 1) == 0) {
1279 printk(KERN_WARNING DRVNAME ": HW monitor is disabled, " 1280 printk(KERN_WARNING DRVNAME ": HW monitor is disabled, "
1280 "skipping\n"); 1281 "skipping\n");
1281 goto EXIT; 1282 goto EXIT;
1282 } 1283 }
1283 1284
1284 *address = ((superio_inb(SIO_VT1211_BADDR) << 8) | 1285 *address = ((superio_inb(sio_cip, SIO_VT1211_BADDR) << 8) |
1285 (superio_inb(SIO_VT1211_BADDR + 1))) & 0xff00; 1286 (superio_inb(sio_cip, SIO_VT1211_BADDR + 1))) & 0xff00;
1286 if (*address == 0) { 1287 if (*address == 0) {
1287 printk(KERN_WARNING DRVNAME ": Base address is not set, " 1288 printk(KERN_WARNING DRVNAME ": Base address is not set, "
1288 "skipping\n"); 1289 "skipping\n");
@@ -1291,10 +1292,11 @@ static int __init vt1211_find(unsigned short *address)
1291 1292
1292 err = 0; 1293 err = 0;
1293 printk(KERN_INFO DRVNAME ": Found VT1211 chip at 0x%04x, " 1294 printk(KERN_INFO DRVNAME ": Found VT1211 chip at 0x%04x, "
1294 "revision %u\n", *address, superio_inb(SIO_VT1211_DEVREV)); 1295 "revision %u\n", *address,
1296 superio_inb(sio_cip, SIO_VT1211_DEVREV));
1295 1297
1296EXIT: 1298EXIT:
1297 superio_exit(); 1299 superio_exit(sio_cip);
1298 return err; 1300 return err;
1299} 1301}
1300 1302
@@ -1303,8 +1305,8 @@ static int __init vt1211_init(void)
1303 int err; 1305 int err;
1304 unsigned short address = 0; 1306 unsigned short address = 0;
1305 1307
1306 err = vt1211_find(&address); 1308 if ((err = vt1211_find(SIO_REG_CIP1, &address)) &&
1307 if (err) { 1309 (err = vt1211_find(SIO_REG_CIP2, &address))) {
1308 goto EXIT; 1310 goto EXIT;
1309 } 1311 }
1310 1312
diff --git a/drivers/hwmon/w83627ehf.c b/drivers/hwmon/w83627ehf.c
index 212a1558c63b..da5828f2dfc2 100644
--- a/drivers/hwmon/w83627ehf.c
+++ b/drivers/hwmon/w83627ehf.c
@@ -32,8 +32,10 @@
32 32
33 Supports the following chips: 33 Supports the following chips:
34 34
35 Chip #vin #fan #pwm #temp chip_id man_id 35 Chip #vin #fan #pwm #temp chip IDs man ID
36 w83627ehf 10 5 4 3 0x88,0xa1 0x5ca3 36 w83627ehf 10 5 4 3 0x8850 0x88 0x5ca3
37 0x8860 0xa1
38 w83627dhg 9 5 4 3 0xa020 0xc1 0x5ca3
37*/ 39*/
38 40
39#include <linux/module.h> 41#include <linux/module.h>
@@ -55,8 +57,18 @@ static unsigned short address;
55 * Super-I/O constants and functions 57 * Super-I/O constants and functions
56 */ 58 */
57 59
60/*
61 * The three following globals are initialized in w83627ehf_find(), before
62 * the i2c-isa device is created. Otherwise, they could be stored in
63 * w83627ehf_data. This is ugly, but necessary, and when the driver is next
64 * updated to become a platform driver, the globals will disappear.
65 */
58static int REG; /* The register to read/write */ 66static int REG; /* The register to read/write */
59static int VAL; /* The value to read/write */ 67static int VAL; /* The value to read/write */
68/* The w83627ehf/ehg have 10 voltage inputs, but the w83627dhg has 9. This
69 * value is also used in w83627ehf_detect() to export a device name in sysfs
70 * (e.g. w83627ehf or w83627dhg) */
71static int w83627ehf_num_in;
60 72
61#define W83627EHF_LD_HWM 0x0b 73#define W83627EHF_LD_HWM 0x0b
62 74
@@ -65,8 +77,10 @@ static int VAL; /* The value to read/write */
65#define SIO_REG_ENABLE 0x30 /* Logical device enable */ 77#define SIO_REG_ENABLE 0x30 /* Logical device enable */
66#define SIO_REG_ADDR 0x60 /* Logical device address (2 bytes) */ 78#define SIO_REG_ADDR 0x60 /* Logical device address (2 bytes) */
67 79
68#define SIO_W83627EHF_ID 0x8840 80#define SIO_W83627EHF_ID 0x8850
69#define SIO_ID_MASK 0xFFC0 81#define SIO_W83627EHG_ID 0x8860
82#define SIO_W83627DHG_ID 0xa020
83#define SIO_ID_MASK 0xFFF0
70 84
71static inline void 85static inline void
72superio_outb(int reg, int val) 86superio_outb(int reg, int val)
@@ -115,8 +129,12 @@ superio_exit(void)
115 129
116#define W83627EHF_REG_BANK 0x4E 130#define W83627EHF_REG_BANK 0x4E
117#define W83627EHF_REG_CONFIG 0x40 131#define W83627EHF_REG_CONFIG 0x40
118#define W83627EHF_REG_CHIP_ID 0x49 132
119#define W83627EHF_REG_MAN_ID 0x4F 133/* Not currently used:
134 * REG_MAN_ID has the value 0x5ca3 for all supported chips.
135 * REG_CHIP_ID == 0x88/0xa1/0xc1 depending on chip model.
136 * REG_MAN_ID is at port 0x4f
137 * REG_CHIP_ID is at port 0x58 */
120 138
121static const u16 W83627EHF_REG_FAN[] = { 0x28, 0x29, 0x2a, 0x3f, 0x553 }; 139static const u16 W83627EHF_REG_FAN[] = { 0x28, 0x29, 0x2a, 0x3f, 0x553 };
122static const u16 W83627EHF_REG_FAN_MIN[] = { 0x3b, 0x3c, 0x3d, 0x3e, 0x55c }; 140static const u16 W83627EHF_REG_FAN_MIN[] = { 0x3b, 0x3c, 0x3d, 0x3e, 0x55c };
@@ -429,7 +447,7 @@ static struct w83627ehf_data *w83627ehf_update_device(struct device *dev)
429 } 447 }
430 448
431 /* Measured voltages and limits */ 449 /* Measured voltages and limits */
432 for (i = 0; i < 10; i++) { 450 for (i = 0; i < w83627ehf_num_in; i++) {
433 data->in[i] = w83627ehf_read_value(client, 451 data->in[i] = w83627ehf_read_value(client,
434 W83627EHF_REG_IN(i)); 452 W83627EHF_REG_IN(i));
435 data->in_min[i] = w83627ehf_read_value(client, 453 data->in_min[i] = w83627ehf_read_value(client,
@@ -1121,7 +1139,7 @@ static void w83627ehf_device_remove_files(struct device *dev)
1121 device_remove_file(dev, &sda_sf3_arrays[i].dev_attr); 1139 device_remove_file(dev, &sda_sf3_arrays[i].dev_attr);
1122 for (i = 0; i < ARRAY_SIZE(sda_sf3_arrays_fan4); i++) 1140 for (i = 0; i < ARRAY_SIZE(sda_sf3_arrays_fan4); i++)
1123 device_remove_file(dev, &sda_sf3_arrays_fan4[i].dev_attr); 1141 device_remove_file(dev, &sda_sf3_arrays_fan4[i].dev_attr);
1124 for (i = 0; i < 10; i++) { 1142 for (i = 0; i < w83627ehf_num_in; i++) {
1125 device_remove_file(dev, &sda_in_input[i].dev_attr); 1143 device_remove_file(dev, &sda_in_input[i].dev_attr);
1126 device_remove_file(dev, &sda_in_alarm[i].dev_attr); 1144 device_remove_file(dev, &sda_in_alarm[i].dev_attr);
1127 device_remove_file(dev, &sda_in_min[i].dev_attr); 1145 device_remove_file(dev, &sda_in_min[i].dev_attr);
@@ -1196,7 +1214,11 @@ static int w83627ehf_detect(struct i2c_adapter *adapter)
1196 client->flags = 0; 1214 client->flags = 0;
1197 dev = &client->dev; 1215 dev = &client->dev;
1198 1216
1199 strlcpy(client->name, "w83627ehf", I2C_NAME_SIZE); 1217 if (w83627ehf_num_in == 9)
1218 strlcpy(client->name, "w83627dhg", I2C_NAME_SIZE);
1219 else /* just say ehf. 627EHG is 627EHF in lead-free packaging. */
1220 strlcpy(client->name, "w83627ehf", I2C_NAME_SIZE);
1221
1200 data->valid = 0; 1222 data->valid = 0;
1201 mutex_init(&data->update_lock); 1223 mutex_init(&data->update_lock);
1202 1224
@@ -1246,7 +1268,7 @@ static int w83627ehf_detect(struct i2c_adapter *adapter)
1246 goto exit_remove; 1268 goto exit_remove;
1247 } 1269 }
1248 1270
1249 for (i = 0; i < 10; i++) 1271 for (i = 0; i < w83627ehf_num_in; i++)
1250 if ((err = device_create_file(dev, &sda_in_input[i].dev_attr)) 1272 if ((err = device_create_file(dev, &sda_in_input[i].dev_attr))
1251 || (err = device_create_file(dev, 1273 || (err = device_create_file(dev,
1252 &sda_in_alarm[i].dev_attr)) 1274 &sda_in_alarm[i].dev_attr))
@@ -1340,7 +1362,17 @@ static int __init w83627ehf_find(int sioaddr, unsigned short *addr)
1340 1362
1341 val = (superio_inb(SIO_REG_DEVID) << 8) 1363 val = (superio_inb(SIO_REG_DEVID) << 8)
1342 | superio_inb(SIO_REG_DEVID + 1); 1364 | superio_inb(SIO_REG_DEVID + 1);
1343 if ((val & SIO_ID_MASK) != SIO_W83627EHF_ID) { 1365 switch (val & SIO_ID_MASK) {
1366 case SIO_W83627DHG_ID:
1367 w83627ehf_num_in = 9;
1368 break;
1369 case SIO_W83627EHF_ID:
1370 case SIO_W83627EHG_ID:
1371 w83627ehf_num_in = 10;
1372 break;
1373 default:
1374 printk(KERN_WARNING "w83627ehf: unsupported chip ID: 0x%04x\n",
1375 val);
1344 superio_exit(); 1376 superio_exit();
1345 return -ENODEV; 1377 return -ENODEV;
1346 } 1378 }
diff --git a/drivers/hwmon/w83627hf.c b/drivers/hwmon/w83627hf.c
index dfdc29c77123..d7e240635b3b 100644
--- a/drivers/hwmon/w83627hf.c
+++ b/drivers/hwmon/w83627hf.c
@@ -286,9 +286,8 @@ static inline u8 DIV_TO_REG(long val)
286 return ((u8) i); 286 return ((u8) i);
287} 287}
288 288
289/* For each registered chip, we need to keep some data in memory. That 289/* For each registered chip, we need to keep some data in memory.
290 data is pointed to by w83627hf_list[NR]->data. The structure itself is 290 The structure is dynamically allocated. */
291 dynamically allocated, at the same time when a new client is allocated. */
292struct w83627hf_data { 291struct w83627hf_data {
293 struct i2c_client client; 292 struct i2c_client client;
294 struct class_device *class_dev; 293 struct class_device *class_dev;
diff --git a/drivers/hwmon/w83781d.c b/drivers/hwmon/w83781d.c
index 1232171c3aad..a47da3ec5472 100644
--- a/drivers/hwmon/w83781d.c
+++ b/drivers/hwmon/w83781d.c
@@ -221,14 +221,8 @@ DIV_TO_REG(long val, enum chips type)
221 a bit - except if there could be more than one SMBus. Groan. No solution 221 a bit - except if there could be more than one SMBus. Groan. No solution
222 for this yet. */ 222 for this yet. */
223 223
224/* This module may seem overly long and complicated. In fact, it is not so 224/* For each registered chip, we need to keep some data in memory.
225 bad. Quite a lot of bookkeeping is done. A real driver can often cut 225 The structure is dynamically allocated. */
226 some corners. */
227
228/* For each registered W83781D, we need to keep some data in memory. That
229 data is pointed to by w83781d_list[NR]->data. The structure itself is
230 dynamically allocated, at the same time when a new w83781d client is
231 allocated. */
232struct w83781d_data { 226struct w83781d_data {
233 struct i2c_client client; 227 struct i2c_client client;
234 struct class_device *class_dev; 228 struct class_device *class_dev;
diff --git a/drivers/i2c/busses/i2c-ali1535.c b/drivers/i2c/busses/i2c-ali1535.c
index 6fd8ad7faa06..1e277ba5a9f3 100644
--- a/drivers/i2c/busses/i2c-ali1535.c
+++ b/drivers/i2c/busses/i2c-ali1535.c
@@ -494,7 +494,7 @@ static int __devinit ali1535_probe(struct pci_dev *dev, const struct pci_device_
494 return -ENODEV; 494 return -ENODEV;
495 } 495 }
496 496
497 /* set up the driverfs linkage to our parent device */ 497 /* set up the sysfs linkage to our parent device */
498 ali1535_adapter.dev.parent = &dev->dev; 498 ali1535_adapter.dev.parent = &dev->dev;
499 499
500 snprintf(ali1535_adapter.name, I2C_NAME_SIZE, 500 snprintf(ali1535_adapter.name, I2C_NAME_SIZE,
diff --git a/drivers/i2c/busses/i2c-ali15x3.c b/drivers/i2c/busses/i2c-ali15x3.c
index e4e0df106812..e47fe01bf42a 100644
--- a/drivers/i2c/busses/i2c-ali15x3.c
+++ b/drivers/i2c/busses/i2c-ali15x3.c
@@ -489,7 +489,7 @@ static int __devinit ali15x3_probe(struct pci_dev *dev, const struct pci_device_
489 return -ENODEV; 489 return -ENODEV;
490 } 490 }
491 491
492 /* set up the driverfs linkage to our parent device */ 492 /* set up the sysfs linkage to our parent device */
493 ali15x3_adapter.dev.parent = &dev->dev; 493 ali15x3_adapter.dev.parent = &dev->dev;
494 494
495 snprintf(ali15x3_adapter.name, I2C_NAME_SIZE, 495 snprintf(ali15x3_adapter.name, I2C_NAME_SIZE,
diff --git a/drivers/i2c/busses/i2c-amd756.c b/drivers/i2c/busses/i2c-amd756.c
index fa6155a54cc3..7490dc1771ae 100644
--- a/drivers/i2c/busses/i2c-amd756.c
+++ b/drivers/i2c/busses/i2c-amd756.c
@@ -374,7 +374,7 @@ static int __devinit amd756_probe(struct pci_dev *pdev,
374 dev_dbg(&pdev->dev, "SMBREV = 0x%X\n", temp); 374 dev_dbg(&pdev->dev, "SMBREV = 0x%X\n", temp);
375 dev_dbg(&pdev->dev, "AMD756_smba = 0x%X\n", amd756_ioport); 375 dev_dbg(&pdev->dev, "AMD756_smba = 0x%X\n", amd756_ioport);
376 376
377 /* set up the driverfs linkage to our parent device */ 377 /* set up the sysfs linkage to our parent device */
378 amd756_smbus.dev.parent = &pdev->dev; 378 amd756_smbus.dev.parent = &pdev->dev;
379 379
380 sprintf(amd756_smbus.name, "SMBus %s adapter at %04x", 380 sprintf(amd756_smbus.name, "SMBus %s adapter at %04x",
diff --git a/drivers/i2c/busses/i2c-amd8111.c b/drivers/i2c/busses/i2c-amd8111.c
index 5bba3fb50d71..e15f9e37716a 100644
--- a/drivers/i2c/busses/i2c-amd8111.c
+++ b/drivers/i2c/busses/i2c-amd8111.c
@@ -371,7 +371,7 @@ static int __devinit amd8111_probe(struct pci_dev *dev,
371 smbus->adapter.algo = &smbus_algorithm; 371 smbus->adapter.algo = &smbus_algorithm;
372 smbus->adapter.algo_data = smbus; 372 smbus->adapter.algo_data = smbus;
373 373
374 /* set up the driverfs linkage to our parent device */ 374 /* set up the sysfs linkage to our parent device */
375 smbus->adapter.dev.parent = &dev->dev; 375 smbus->adapter.dev.parent = &dev->dev;
376 376
377 pci_write_config_dword(smbus->dev, AMD_PCI_MISC, 0); 377 pci_write_config_dword(smbus->dev, AMD_PCI_MISC, 0);
diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
index 21f2671f7220..6569a36985bd 100644
--- a/drivers/i2c/busses/i2c-i801.c
+++ b/drivers/i2c/busses/i2c-i801.c
@@ -522,7 +522,7 @@ static int __devinit i801_probe(struct pci_dev *dev, const struct pci_device_id
522 else 522 else
523 dev_dbg(&dev->dev, "SMBus using PCI Interrupt\n"); 523 dev_dbg(&dev->dev, "SMBus using PCI Interrupt\n");
524 524
525 /* set up the driverfs linkage to our parent device */ 525 /* set up the sysfs linkage to our parent device */
526 i801_adapter.dev.parent = &dev->dev; 526 i801_adapter.dev.parent = &dev->dev;
527 527
528 snprintf(i801_adapter.name, I2C_NAME_SIZE, 528 snprintf(i801_adapter.name, I2C_NAME_SIZE,
diff --git a/drivers/i2c/busses/i2c-iop3xx.c b/drivers/i2c/busses/i2c-iop3xx.c
index 20ee4f7c53a0..90e2d9350c1b 100644
--- a/drivers/i2c/busses/i2c-iop3xx.c
+++ b/drivers/i2c/busses/i2c-iop3xx.c
@@ -83,7 +83,7 @@ iop3xx_i2c_enable(struct i2c_algo_iop3xx_data *iop3xx_adap)
83 * Every time unit enable is asserted, GPOD needs to be cleared 83 * Every time unit enable is asserted, GPOD needs to be cleared
84 * on IOP3XX to avoid data corruption on the bus. 84 * on IOP3XX to avoid data corruption on the bus.
85 */ 85 */
86#ifdef CONFIG_PLAT_IOP 86#if defined(CONFIG_ARCH_IOP32X) || defined(CONFIG_ARCH_IOP33X)
87 if (iop3xx_adap->id == 0) { 87 if (iop3xx_adap->id == 0) {
88 gpio_line_set(IOP3XX_GPIO_LINE(7), GPIO_LOW); 88 gpio_line_set(IOP3XX_GPIO_LINE(7), GPIO_LOW);
89 gpio_line_set(IOP3XX_GPIO_LINE(6), GPIO_LOW); 89 gpio_line_set(IOP3XX_GPIO_LINE(6), GPIO_LOW);
diff --git a/drivers/i2c/busses/i2c-piix4.c b/drivers/i2c/busses/i2c-piix4.c
index d888293c1a9c..21b180904085 100644
--- a/drivers/i2c/busses/i2c-piix4.c
+++ b/drivers/i2c/busses/i2c-piix4.c
@@ -425,7 +425,7 @@ static int __devinit piix4_probe(struct pci_dev *dev,
425 if (retval) 425 if (retval)
426 return retval; 426 return retval;
427 427
428 /* set up the driverfs linkage to our parent device */ 428 /* set up the sysfs linkage to our parent device */
429 piix4_adapter.dev.parent = &dev->dev; 429 piix4_adapter.dev.parent = &dev->dev;
430 430
431 snprintf(piix4_adapter.name, I2C_NAME_SIZE, 431 snprintf(piix4_adapter.name, I2C_NAME_SIZE,
diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c
index c3b1567c852a..14e83d0aac8c 100644
--- a/drivers/i2c/busses/i2c-pxa.c
+++ b/drivers/i2c/busses/i2c-pxa.c
@@ -34,6 +34,7 @@
34 34
35#include <asm/hardware.h> 35#include <asm/hardware.h>
36#include <asm/irq.h> 36#include <asm/irq.h>
37#include <asm/io.h>
37#include <asm/arch/i2c.h> 38#include <asm/arch/i2c.h>
38#include <asm/arch/pxa-regs.h> 39#include <asm/arch/pxa-regs.h>
39 40
@@ -54,8 +55,21 @@ struct pxa_i2c {
54 unsigned int irqlogidx; 55 unsigned int irqlogidx;
55 u32 isrlog[32]; 56 u32 isrlog[32];
56 u32 icrlog[32]; 57 u32 icrlog[32];
58
59 void __iomem *reg_base;
60
61 unsigned long iobase;
62 unsigned long iosize;
63
64 int irq;
57}; 65};
58 66
67#define _IBMR(i2c) ((i2c)->reg_base + 0)
68#define _IDBR(i2c) ((i2c)->reg_base + 8)
69#define _ICR(i2c) ((i2c)->reg_base + 0x10)
70#define _ISR(i2c) ((i2c)->reg_base + 0x18)
71#define _ISAR(i2c) ((i2c)->reg_base + 0x20)
72
59/* 73/*
60 * I2C Slave mode address 74 * I2C Slave mode address
61 */ 75 */
@@ -130,7 +144,8 @@ static unsigned int i2c_debug = DEBUG;
130 144
131static void i2c_pxa_show_state(struct pxa_i2c *i2c, int lno, const char *fname) 145static void i2c_pxa_show_state(struct pxa_i2c *i2c, int lno, const char *fname)
132{ 146{
133 dev_dbg(&i2c->adap.dev, "state:%s:%d: ISR=%08x, ICR=%08x, IBMR=%02x\n", fname, lno, ISR, ICR, IBMR); 147 dev_dbg(&i2c->adap.dev, "state:%s:%d: ISR=%08x, ICR=%08x, IBMR=%02x\n", fname, lno,
148 readl(_ISR(i2c)), readl(_ICR(i2c)), readl(_IBMR(i2c)));
134} 149}
135 150
136#define show_state(i2c) i2c_pxa_show_state(i2c, __LINE__, __FUNCTION__) 151#define show_state(i2c) i2c_pxa_show_state(i2c, __LINE__, __FUNCTION__)
@@ -153,7 +168,7 @@ static void i2c_pxa_scream_blue_murder(struct pxa_i2c *i2c, const char *why)
153 printk("i2c: msg_num: %d msg_idx: %d msg_ptr: %d\n", 168 printk("i2c: msg_num: %d msg_idx: %d msg_ptr: %d\n",
154 i2c->msg_num, i2c->msg_idx, i2c->msg_ptr); 169 i2c->msg_num, i2c->msg_idx, i2c->msg_ptr);
155 printk("i2c: ICR: %08x ISR: %08x\n" 170 printk("i2c: ICR: %08x ISR: %08x\n"
156 "i2c: log: ", ICR, ISR); 171 "i2c: log: ", readl(_ICR(i2c)), readl(_ISR(i2c)));
157 for (i = 0; i < i2c->irqlogidx; i++) 172 for (i = 0; i < i2c->irqlogidx; i++)
158 printk("[%08x:%08x] ", i2c->isrlog[i], i2c->icrlog[i]); 173 printk("[%08x:%08x] ", i2c->isrlog[i], i2c->icrlog[i]);
159 printk("\n"); 174 printk("\n");
@@ -161,7 +176,7 @@ static void i2c_pxa_scream_blue_murder(struct pxa_i2c *i2c, const char *why)
161 176
162static inline int i2c_pxa_is_slavemode(struct pxa_i2c *i2c) 177static inline int i2c_pxa_is_slavemode(struct pxa_i2c *i2c)
163{ 178{
164 return !(ICR & ICR_SCLE); 179 return !(readl(_ICR(i2c)) & ICR_SCLE);
165} 180}
166 181
167static void i2c_pxa_abort(struct pxa_i2c *i2c) 182static void i2c_pxa_abort(struct pxa_i2c *i2c)
@@ -173,28 +188,29 @@ static void i2c_pxa_abort(struct pxa_i2c *i2c)
173 return; 188 return;
174 } 189 }
175 190
176 while (time_before(jiffies, timeout) && (IBMR & 0x1) == 0) { 191 while (time_before(jiffies, timeout) && (readl(_IBMR(i2c)) & 0x1) == 0) {
177 unsigned long icr = ICR; 192 unsigned long icr = readl(_ICR(i2c));
178 193
179 icr &= ~ICR_START; 194 icr &= ~ICR_START;
180 icr |= ICR_ACKNAK | ICR_STOP | ICR_TB; 195 icr |= ICR_ACKNAK | ICR_STOP | ICR_TB;
181 196
182 ICR = icr; 197 writel(icr, _ICR(i2c));
183 198
184 show_state(i2c); 199 show_state(i2c);
185 200
186 msleep(1); 201 msleep(1);
187 } 202 }
188 203
189 ICR &= ~(ICR_MA | ICR_START | ICR_STOP); 204 writel(readl(_ICR(i2c)) & ~(ICR_MA | ICR_START | ICR_STOP),
205 _ICR(i2c));
190} 206}
191 207
192static int i2c_pxa_wait_bus_not_busy(struct pxa_i2c *i2c) 208static int i2c_pxa_wait_bus_not_busy(struct pxa_i2c *i2c)
193{ 209{
194 int timeout = DEF_TIMEOUT; 210 int timeout = DEF_TIMEOUT;
195 211
196 while (timeout-- && ISR & (ISR_IBB | ISR_UB)) { 212 while (timeout-- && readl(_ISR(i2c)) & (ISR_IBB | ISR_UB)) {
197 if ((ISR & ISR_SAD) != 0) 213 if ((readl(_ISR(i2c)) & ISR_SAD) != 0)
198 timeout += 4; 214 timeout += 4;
199 215
200 msleep(2); 216 msleep(2);
@@ -214,9 +230,9 @@ static int i2c_pxa_wait_master(struct pxa_i2c *i2c)
214 while (time_before(jiffies, timeout)) { 230 while (time_before(jiffies, timeout)) {
215 if (i2c_debug > 1) 231 if (i2c_debug > 1)
216 dev_dbg(&i2c->adap.dev, "%s: %ld: ISR=%08x, ICR=%08x, IBMR=%02x\n", 232 dev_dbg(&i2c->adap.dev, "%s: %ld: ISR=%08x, ICR=%08x, IBMR=%02x\n",
217 __func__, (long)jiffies, ISR, ICR, IBMR); 233 __func__, (long)jiffies, readl(_ISR(i2c)), readl(_ICR(i2c)), readl(_IBMR(i2c)));
218 234
219 if (ISR & ISR_SAD) { 235 if (readl(_ISR(i2c)) & ISR_SAD) {
220 if (i2c_debug > 0) 236 if (i2c_debug > 0)
221 dev_dbg(&i2c->adap.dev, "%s: Slave detected\n", __func__); 237 dev_dbg(&i2c->adap.dev, "%s: Slave detected\n", __func__);
222 goto out; 238 goto out;
@@ -226,7 +242,7 @@ static int i2c_pxa_wait_master(struct pxa_i2c *i2c)
226 * quick check of the i2c lines themselves to ensure they've 242 * quick check of the i2c lines themselves to ensure they've
227 * gone high... 243 * gone high...
228 */ 244 */
229 if ((ISR & (ISR_UB | ISR_IBB)) == 0 && IBMR == 3) { 245 if ((readl(_ISR(i2c)) & (ISR_UB | ISR_IBB)) == 0 && readl(_IBMR(i2c)) == 3) {
230 if (i2c_debug > 0) 246 if (i2c_debug > 0)
231 dev_dbg(&i2c->adap.dev, "%s: done\n", __func__); 247 dev_dbg(&i2c->adap.dev, "%s: done\n", __func__);
232 return 1; 248 return 1;
@@ -246,7 +262,7 @@ static int i2c_pxa_set_master(struct pxa_i2c *i2c)
246 if (i2c_debug) 262 if (i2c_debug)
247 dev_dbg(&i2c->adap.dev, "setting to bus master\n"); 263 dev_dbg(&i2c->adap.dev, "setting to bus master\n");
248 264
249 if ((ISR & (ISR_UB | ISR_IBB)) != 0) { 265 if ((readl(_ISR(i2c)) & (ISR_UB | ISR_IBB)) != 0) {
250 dev_dbg(&i2c->adap.dev, "%s: unit is busy\n", __func__); 266 dev_dbg(&i2c->adap.dev, "%s: unit is busy\n", __func__);
251 if (!i2c_pxa_wait_master(i2c)) { 267 if (!i2c_pxa_wait_master(i2c)) {
252 dev_dbg(&i2c->adap.dev, "%s: error: unit busy\n", __func__); 268 dev_dbg(&i2c->adap.dev, "%s: error: unit busy\n", __func__);
@@ -254,7 +270,7 @@ static int i2c_pxa_set_master(struct pxa_i2c *i2c)
254 } 270 }
255 } 271 }
256 272
257 ICR |= ICR_SCLE; 273 writel(readl(_ICR(i2c)) | ICR_SCLE, _ICR(i2c));
258 return 0; 274 return 0;
259} 275}
260 276
@@ -270,11 +286,11 @@ static int i2c_pxa_wait_slave(struct pxa_i2c *i2c)
270 while (time_before(jiffies, timeout)) { 286 while (time_before(jiffies, timeout)) {
271 if (i2c_debug > 1) 287 if (i2c_debug > 1)
272 dev_dbg(&i2c->adap.dev, "%s: %ld: ISR=%08x, ICR=%08x, IBMR=%02x\n", 288 dev_dbg(&i2c->adap.dev, "%s: %ld: ISR=%08x, ICR=%08x, IBMR=%02x\n",
273 __func__, (long)jiffies, ISR, ICR, IBMR); 289 __func__, (long)jiffies, readl(_ISR(i2c)), readl(_ICR(i2c)), readl(_IBMR(i2c)));
274 290
275 if ((ISR & (ISR_UB|ISR_IBB)) == 0 || 291 if ((readl(_ISR(i2c)) & (ISR_UB|ISR_IBB)) == 0 ||
276 (ISR & ISR_SAD) != 0 || 292 (readl(_ISR(i2c)) & ISR_SAD) != 0 ||
277 (ICR & ICR_SCLE) == 0) { 293 (readl(_ICR(i2c)) & ICR_SCLE) == 0) {
278 if (i2c_debug > 1) 294 if (i2c_debug > 1)
279 dev_dbg(&i2c->adap.dev, "%s: done\n", __func__); 295 dev_dbg(&i2c->adap.dev, "%s: done\n", __func__);
280 return 1; 296 return 1;
@@ -302,9 +318,9 @@ static void i2c_pxa_set_slave(struct pxa_i2c *i2c, int errcode)
302 /* we need to wait for the stop condition to end */ 318 /* we need to wait for the stop condition to end */
303 319
304 /* if we where in stop, then clear... */ 320 /* if we where in stop, then clear... */
305 if (ICR & ICR_STOP) { 321 if (readl(_ICR(i2c)) & ICR_STOP) {
306 udelay(100); 322 udelay(100);
307 ICR &= ~ICR_STOP; 323 writel(readl(_ICR(i2c)) & ~ICR_STOP, _ICR(i2c));
308 } 324 }
309 325
310 if (!i2c_pxa_wait_slave(i2c)) { 326 if (!i2c_pxa_wait_slave(i2c)) {
@@ -314,12 +330,12 @@ static void i2c_pxa_set_slave(struct pxa_i2c *i2c, int errcode)
314 } 330 }
315 } 331 }
316 332
317 ICR &= ~(ICR_STOP|ICR_ACKNAK|ICR_MA); 333 writel(readl(_ICR(i2c)) & ~(ICR_STOP|ICR_ACKNAK|ICR_MA), _ICR(i2c));
318 ICR &= ~ICR_SCLE; 334 writel(readl(_ICR(i2c)) & ~ICR_SCLE, _ICR(i2c));
319 335
320 if (i2c_debug) { 336 if (i2c_debug) {
321 dev_dbg(&i2c->adap.dev, "ICR now %08x, ISR %08x\n", ICR, ISR); 337 dev_dbg(&i2c->adap.dev, "ICR now %08x, ISR %08x\n", readl(_ICR(i2c)), readl(_ISR(i2c)));
322 decode_ICR(ICR); 338 decode_ICR(readl(_ICR(i2c)));
323 } 339 }
324} 340}
325#else 341#else
@@ -334,24 +350,24 @@ static void i2c_pxa_reset(struct pxa_i2c *i2c)
334 i2c_pxa_abort(i2c); 350 i2c_pxa_abort(i2c);
335 351
336 /* reset according to 9.8 */ 352 /* reset according to 9.8 */
337 ICR = ICR_UR; 353 writel(ICR_UR, _ICR(i2c));
338 ISR = I2C_ISR_INIT; 354 writel(I2C_ISR_INIT, _ISR(i2c));
339 ICR &= ~ICR_UR; 355 writel(readl(_ICR(i2c)) & ~ICR_UR, _ICR(i2c));
340 356
341 ISAR = i2c->slave_addr; 357 writel(i2c->slave_addr, _ISAR(i2c));
342 358
343 /* set control register values */ 359 /* set control register values */
344 ICR = I2C_ICR_INIT; 360 writel(I2C_ICR_INIT, _ICR(i2c));
345 361
346#ifdef CONFIG_I2C_PXA_SLAVE 362#ifdef CONFIG_I2C_PXA_SLAVE
347 dev_info(&i2c->adap.dev, "Enabling slave mode\n"); 363 dev_info(&i2c->adap.dev, "Enabling slave mode\n");
348 ICR |= ICR_SADIE | ICR_ALDIE | ICR_SSDIE; 364 writel(readl(_ICR(i2c)) | ICR_SADIE | ICR_ALDIE | ICR_SSDIE, _ICR(i2c));
349#endif 365#endif
350 366
351 i2c_pxa_set_slave(i2c, 0); 367 i2c_pxa_set_slave(i2c, 0);
352 368
353 /* enable unit */ 369 /* enable unit */
354 ICR |= ICR_IUE; 370 writel(readl(_ICR(i2c)) | ICR_IUE, _ICR(i2c));
355 udelay(100); 371 udelay(100);
356} 372}
357 373
@@ -371,19 +387,19 @@ static void i2c_pxa_slave_txempty(struct pxa_i2c *i2c, u32 isr)
371 if (i2c->slave != NULL) 387 if (i2c->slave != NULL)
372 ret = i2c->slave->read(i2c->slave->data); 388 ret = i2c->slave->read(i2c->slave->data);
373 389
374 IDBR = ret; 390 writel(ret, _IDBR(i2c));
375 ICR |= ICR_TB; /* allow next byte */ 391 writel(readl(_ICR(i2c)) | ICR_TB, _ICR(i2c)); /* allow next byte */
376 } 392 }
377} 393}
378 394
379static void i2c_pxa_slave_rxfull(struct pxa_i2c *i2c, u32 isr) 395static void i2c_pxa_slave_rxfull(struct pxa_i2c *i2c, u32 isr)
380{ 396{
381 unsigned int byte = IDBR; 397 unsigned int byte = readl(_IDBR(i2c));
382 398
383 if (i2c->slave != NULL) 399 if (i2c->slave != NULL)
384 i2c->slave->write(i2c->slave->data, byte); 400 i2c->slave->write(i2c->slave->data, byte);
385 401
386 ICR |= ICR_TB; 402 writel(readl(_ICR(i2c)) | ICR_TB, _ICR(i2c));
387} 403}
388 404
389static void i2c_pxa_slave_start(struct pxa_i2c *i2c, u32 isr) 405static void i2c_pxa_slave_start(struct pxa_i2c *i2c, u32 isr)
@@ -403,13 +419,13 @@ static void i2c_pxa_slave_start(struct pxa_i2c *i2c, u32 isr)
403 * start condition... if this happens, we'd better back off 419 * start condition... if this happens, we'd better back off
404 * and stop holding the poor thing up 420 * and stop holding the poor thing up
405 */ 421 */
406 ICR &= ~(ICR_START|ICR_STOP); 422 writel(readl(_ICR(i2c)) & ~(ICR_START|ICR_STOP), _ICR(i2c));
407 ICR |= ICR_TB; 423 writel(readl(_ICR(i2c)) | ICR_TB, _ICR(i2c));
408 424
409 timeout = 0x10000; 425 timeout = 0x10000;
410 426
411 while (1) { 427 while (1) {
412 if ((IBMR & 2) == 2) 428 if ((readl(_IBMR(i2c)) & 2) == 2)
413 break; 429 break;
414 430
415 timeout--; 431 timeout--;
@@ -420,7 +436,7 @@ static void i2c_pxa_slave_start(struct pxa_i2c *i2c, u32 isr)
420 } 436 }
421 } 437 }
422 438
423 ICR &= ~ICR_SCLE; 439 writel(readl(_ICR(i2c)) & ~ICR_SCLE, _ICR(i2c));
424} 440}
425 441
426static void i2c_pxa_slave_stop(struct pxa_i2c *i2c) 442static void i2c_pxa_slave_stop(struct pxa_i2c *i2c)
@@ -447,14 +463,14 @@ static void i2c_pxa_slave_txempty(struct pxa_i2c *i2c, u32 isr)
447 if (isr & ISR_BED) { 463 if (isr & ISR_BED) {
448 /* what should we do here? */ 464 /* what should we do here? */
449 } else { 465 } else {
450 IDBR = 0; 466 writel(0, _IDBR(i2c));
451 ICR |= ICR_TB; 467 writel(readl(_ICR(i2c)) | ICR_TB, _ICR(i2c));
452 } 468 }
453} 469}
454 470
455static void i2c_pxa_slave_rxfull(struct pxa_i2c *i2c, u32 isr) 471static void i2c_pxa_slave_rxfull(struct pxa_i2c *i2c, u32 isr)
456{ 472{
457 ICR |= ICR_TB | ICR_ACKNAK; 473 writel(readl(_ICR(i2c)) | ICR_TB | ICR_ACKNAK, _ICR(i2c));
458} 474}
459 475
460static void i2c_pxa_slave_start(struct pxa_i2c *i2c, u32 isr) 476static void i2c_pxa_slave_start(struct pxa_i2c *i2c, u32 isr)
@@ -466,13 +482,13 @@ static void i2c_pxa_slave_start(struct pxa_i2c *i2c, u32 isr)
466 * start condition... if this happens, we'd better back off 482 * start condition... if this happens, we'd better back off
467 * and stop holding the poor thing up 483 * and stop holding the poor thing up
468 */ 484 */
469 ICR &= ~(ICR_START|ICR_STOP); 485 writel(readl(_ICR(i2c)) & ~(ICR_START|ICR_STOP), _ICR(i2c));
470 ICR |= ICR_TB | ICR_ACKNAK; 486 writel(readl(_ICR(i2c)) | ICR_TB | ICR_ACKNAK, _ICR(i2c));
471 487
472 timeout = 0x10000; 488 timeout = 0x10000;
473 489
474 while (1) { 490 while (1) {
475 if ((IBMR & 2) == 2) 491 if ((readl(_IBMR(i2c)) & 2) == 2)
476 break; 492 break;
477 493
478 timeout--; 494 timeout--;
@@ -483,7 +499,7 @@ static void i2c_pxa_slave_start(struct pxa_i2c *i2c, u32 isr)
483 } 499 }
484 } 500 }
485 501
486 ICR &= ~ICR_SCLE; 502 writel(readl(_ICR(i2c)) & ~ICR_SCLE, _ICR(i2c));
487} 503}
488 504
489static void i2c_pxa_slave_stop(struct pxa_i2c *i2c) 505static void i2c_pxa_slave_stop(struct pxa_i2c *i2c)
@@ -514,13 +530,13 @@ static inline void i2c_pxa_start_message(struct pxa_i2c *i2c)
514 /* 530 /*
515 * Step 1: target slave address into IDBR 531 * Step 1: target slave address into IDBR
516 */ 532 */
517 IDBR = i2c_pxa_addr_byte(i2c->msg); 533 writel(i2c_pxa_addr_byte(i2c->msg), _IDBR(i2c));
518 534
519 /* 535 /*
520 * Step 2: initiate the write. 536 * Step 2: initiate the write.
521 */ 537 */
522 icr = ICR & ~(ICR_STOP | ICR_ALDIE); 538 icr = readl(_ICR(i2c)) & ~(ICR_STOP | ICR_ALDIE);
523 ICR = icr | ICR_START | ICR_TB; 539 writel(icr | ICR_START | ICR_TB, _ICR(i2c));
524} 540}
525 541
526/* 542/*
@@ -594,7 +610,7 @@ static void i2c_pxa_master_complete(struct pxa_i2c *i2c, int ret)
594 610
595static void i2c_pxa_irq_txempty(struct pxa_i2c *i2c, u32 isr) 611static void i2c_pxa_irq_txempty(struct pxa_i2c *i2c, u32 isr)
596{ 612{
597 u32 icr = ICR & ~(ICR_START|ICR_STOP|ICR_ACKNAK|ICR_TB); 613 u32 icr = readl(_ICR(i2c)) & ~(ICR_START|ICR_STOP|ICR_ACKNAK|ICR_TB);
598 614
599 again: 615 again:
600 /* 616 /*
@@ -645,7 +661,7 @@ static void i2c_pxa_irq_txempty(struct pxa_i2c *i2c, u32 isr)
645 /* 661 /*
646 * Write mode. Write the next data byte. 662 * Write mode. Write the next data byte.
647 */ 663 */
648 IDBR = i2c->msg->buf[i2c->msg_ptr++]; 664 writel(i2c->msg->buf[i2c->msg_ptr++], _IDBR(i2c));
649 665
650 icr |= ICR_ALDIE | ICR_TB; 666 icr |= ICR_ALDIE | ICR_TB;
651 667
@@ -675,7 +691,7 @@ static void i2c_pxa_irq_txempty(struct pxa_i2c *i2c, u32 isr)
675 /* 691 /*
676 * Write the next address. 692 * Write the next address.
677 */ 693 */
678 IDBR = i2c_pxa_addr_byte(i2c->msg); 694 writel(i2c_pxa_addr_byte(i2c->msg), _IDBR(i2c));
679 695
680 /* 696 /*
681 * And trigger a repeated start, and send the byte. 697 * And trigger a repeated start, and send the byte.
@@ -696,18 +712,18 @@ static void i2c_pxa_irq_txempty(struct pxa_i2c *i2c, u32 isr)
696 712
697 i2c->icrlog[i2c->irqlogidx-1] = icr; 713 i2c->icrlog[i2c->irqlogidx-1] = icr;
698 714
699 ICR = icr; 715 writel(icr, _ICR(i2c));
700 show_state(i2c); 716 show_state(i2c);
701} 717}
702 718
703static void i2c_pxa_irq_rxfull(struct pxa_i2c *i2c, u32 isr) 719static void i2c_pxa_irq_rxfull(struct pxa_i2c *i2c, u32 isr)
704{ 720{
705 u32 icr = ICR & ~(ICR_START|ICR_STOP|ICR_ACKNAK|ICR_TB); 721 u32 icr = readl(_ICR(i2c)) & ~(ICR_START|ICR_STOP|ICR_ACKNAK|ICR_TB);
706 722
707 /* 723 /*
708 * Read the byte. 724 * Read the byte.
709 */ 725 */
710 i2c->msg->buf[i2c->msg_ptr++] = IDBR; 726 i2c->msg->buf[i2c->msg_ptr++] = readl(_IDBR(i2c));
711 727
712 if (i2c->msg_ptr < i2c->msg->len) { 728 if (i2c->msg_ptr < i2c->msg->len) {
713 /* 729 /*
@@ -724,17 +740,17 @@ static void i2c_pxa_irq_rxfull(struct pxa_i2c *i2c, u32 isr)
724 740
725 i2c->icrlog[i2c->irqlogidx-1] = icr; 741 i2c->icrlog[i2c->irqlogidx-1] = icr;
726 742
727 ICR = icr; 743 writel(icr, _ICR(i2c));
728} 744}
729 745
730static irqreturn_t i2c_pxa_handler(int this_irq, void *dev_id) 746static irqreturn_t i2c_pxa_handler(int this_irq, void *dev_id)
731{ 747{
732 struct pxa_i2c *i2c = dev_id; 748 struct pxa_i2c *i2c = dev_id;
733 u32 isr = ISR; 749 u32 isr = readl(_ISR(i2c));
734 750
735 if (i2c_debug > 2 && 0) { 751 if (i2c_debug > 2 && 0) {
736 dev_dbg(&i2c->adap.dev, "%s: ISR=%08x, ICR=%08x, IBMR=%02x\n", 752 dev_dbg(&i2c->adap.dev, "%s: ISR=%08x, ICR=%08x, IBMR=%02x\n",
737 __func__, isr, ICR, IBMR); 753 __func__, isr, readl(_ICR(i2c)), readl(_IBMR(i2c)));
738 decode_ISR(isr); 754 decode_ISR(isr);
739 } 755 }
740 756
@@ -746,7 +762,7 @@ static irqreturn_t i2c_pxa_handler(int this_irq, void *dev_id)
746 /* 762 /*
747 * Always clear all pending IRQs. 763 * Always clear all pending IRQs.
748 */ 764 */
749 ISR = isr & (ISR_SSD|ISR_ALD|ISR_ITE|ISR_IRF|ISR_SAD|ISR_BED); 765 writel(isr & (ISR_SSD|ISR_ALD|ISR_ITE|ISR_IRF|ISR_SAD|ISR_BED), _ISR(i2c));
750 766
751 if (isr & ISR_SAD) 767 if (isr & ISR_SAD)
752 i2c_pxa_slave_start(i2c, isr); 768 i2c_pxa_slave_start(i2c, isr);
@@ -779,7 +795,7 @@ static int i2c_pxa_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num
779 /* If the I2C controller is disabled we need to reset it (probably due 795 /* If the I2C controller is disabled we need to reset it (probably due
780 to a suspend/resume destroying state). We do this here as we can then 796 to a suspend/resume destroying state). We do this here as we can then
781 avoid worrying about resuming the controller before its users. */ 797 avoid worrying about resuming the controller before its users. */
782 if (!(ICR & ICR_IUE)) 798 if (!(readl(_ICR(i2c)) & ICR_IUE))
783 i2c_pxa_reset(i2c); 799 i2c_pxa_reset(i2c);
784 800
785 for (i = adap->retries; i >= 0; i--) { 801 for (i = adap->retries; i >= 0; i--) {
@@ -810,28 +826,53 @@ static const struct i2c_algorithm i2c_pxa_algorithm = {
810 826
811static struct pxa_i2c i2c_pxa = { 827static struct pxa_i2c i2c_pxa = {
812 .lock = SPIN_LOCK_UNLOCKED, 828 .lock = SPIN_LOCK_UNLOCKED,
813 .wait = __WAIT_QUEUE_HEAD_INITIALIZER(i2c_pxa.wait),
814 .adap = { 829 .adap = {
815 .owner = THIS_MODULE, 830 .owner = THIS_MODULE,
816 .algo = &i2c_pxa_algorithm, 831 .algo = &i2c_pxa_algorithm,
817 .name = "pxa2xx-i2c", 832 .name = "pxa2xx-i2c.0",
818 .retries = 5, 833 .retries = 5,
819 }, 834 },
820}; 835};
821 836
837#define res_len(r) ((r)->end - (r)->start + 1)
822static int i2c_pxa_probe(struct platform_device *dev) 838static int i2c_pxa_probe(struct platform_device *dev)
823{ 839{
824 struct pxa_i2c *i2c = &i2c_pxa; 840 struct pxa_i2c *i2c = &i2c_pxa;
841 struct resource *res;
825#ifdef CONFIG_I2C_PXA_SLAVE 842#ifdef CONFIG_I2C_PXA_SLAVE
826 struct i2c_pxa_platform_data *plat = dev->dev.platform_data; 843 struct i2c_pxa_platform_data *plat = dev->dev.platform_data;
827#endif 844#endif
828 int ret; 845 int ret;
846 int irq;
829 847
830#ifdef CONFIG_PXA27x 848 res = platform_get_resource(dev, IORESOURCE_MEM, 0);
831 pxa_gpio_mode(GPIO117_I2CSCL_MD); 849 irq = platform_get_irq(dev, 0);
832 pxa_gpio_mode(GPIO118_I2CSDA_MD); 850 if (res == NULL || irq < 0)
833 udelay(100); 851 return -ENODEV;
834#endif 852
853 if (!request_mem_region(res->start, res_len(res), res->name))
854 return -ENOMEM;
855
856 i2c = kmalloc(sizeof(struct pxa_i2c), GFP_KERNEL);
857 if (!i2c) {
858 ret = -ENOMEM;
859 goto emalloc;
860 }
861
862 memcpy(i2c, &i2c_pxa, sizeof(struct pxa_i2c));
863 init_waitqueue_head(&i2c->wait);
864 i2c->adap.name[strlen(i2c->adap.name) - 1] = '0' + dev->id % 10;
865
866 i2c->reg_base = ioremap(res->start, res_len(res));
867 if (!i2c->reg_base) {
868 ret = -EIO;
869 goto eremap;
870 }
871
872 i2c->iobase = res->start;
873 i2c->iosize = res_len(res);
874
875 i2c->irq = irq;
835 876
836 i2c->slave_addr = I2C_PXA_SLAVE_ADDR; 877 i2c->slave_addr = I2C_PXA_SLAVE_ADDR;
837 878
@@ -842,11 +883,28 @@ static int i2c_pxa_probe(struct platform_device *dev)
842 } 883 }
843#endif 884#endif
844 885
845 pxa_set_cken(CKEN14_I2C, 1); 886 switch (dev->id) {
846 ret = request_irq(IRQ_I2C, i2c_pxa_handler, IRQF_DISABLED, 887 case 0:
847 "pxa2xx-i2c", i2c); 888#ifdef CONFIG_PXA27x
889 pxa_gpio_mode(GPIO117_I2CSCL_MD);
890 pxa_gpio_mode(GPIO118_I2CSDA_MD);
891#endif
892 pxa_set_cken(CKEN14_I2C, 1);
893 break;
894#ifdef CONFIG_PXA27x
895 case 1:
896 local_irq_disable();
897 PCFR |= PCFR_PI2CEN;
898 local_irq_enable();
899 pxa_set_cken(CKEN15_PWRI2C, 1);
900#endif
901 }
902
903 ret = request_irq(irq, i2c_pxa_handler, IRQF_DISABLED,
904 i2c->adap.name, i2c);
848 if (ret) 905 if (ret)
849 goto out; 906 goto ereqirq;
907
850 908
851 i2c_pxa_reset(i2c); 909 i2c_pxa_reset(i2c);
852 910
@@ -856,7 +914,7 @@ static int i2c_pxa_probe(struct platform_device *dev)
856 ret = i2c_add_adapter(&i2c->adap); 914 ret = i2c_add_adapter(&i2c->adap);
857 if (ret < 0) { 915 if (ret < 0) {
858 printk(KERN_INFO "I2C: Failed to add bus\n"); 916 printk(KERN_INFO "I2C: Failed to add bus\n");
859 goto err_irq; 917 goto eadapt;
860 } 918 }
861 919
862 platform_set_drvdata(dev, i2c); 920 platform_set_drvdata(dev, i2c);
@@ -870,9 +928,25 @@ static int i2c_pxa_probe(struct platform_device *dev)
870#endif 928#endif
871 return 0; 929 return 0;
872 930
873 err_irq: 931eadapt:
874 free_irq(IRQ_I2C, i2c); 932 free_irq(irq, i2c);
875 out: 933ereqirq:
934 switch (dev->id) {
935 case 0:
936 pxa_set_cken(CKEN14_I2C, 0);
937 break;
938#ifdef CONFIG_PXA27x
939 case 1:
940 pxa_set_cken(CKEN15_PWRI2C, 0);
941 local_irq_disable();
942 PCFR &= ~PCFR_PI2CEN;
943 local_irq_enable();
944#endif
945 }
946eremap:
947 kfree(i2c);
948emalloc:
949 release_mem_region(res->start, res_len(res));
876 return ret; 950 return ret;
877} 951}
878 952
@@ -883,8 +957,21 @@ static int i2c_pxa_remove(struct platform_device *dev)
883 platform_set_drvdata(dev, NULL); 957 platform_set_drvdata(dev, NULL);
884 958
885 i2c_del_adapter(&i2c->adap); 959 i2c_del_adapter(&i2c->adap);
886 free_irq(IRQ_I2C, i2c); 960 free_irq(i2c->irq, i2c);
887 pxa_set_cken(CKEN14_I2C, 0); 961 switch (dev->id) {
962 case 0:
963 pxa_set_cken(CKEN14_I2C, 0);
964 break;
965#ifdef CONFIG_PXA27x
966 case 1:
967 pxa_set_cken(CKEN15_PWRI2C, 0);
968 local_irq_disable();
969 PCFR &= ~PCFR_PI2CEN;
970 local_irq_enable();
971#endif
972 }
973 release_mem_region(i2c->iobase, i2c->iosize);
974 kfree(i2c);
888 975
889 return 0; 976 return 0;
890} 977}
diff --git a/drivers/i2c/busses/i2c-sis5595.c b/drivers/i2c/busses/i2c-sis5595.c
index d333babe4ad3..a6feed449dbe 100644
--- a/drivers/i2c/busses/i2c-sis5595.c
+++ b/drivers/i2c/busses/i2c-sis5595.c
@@ -384,7 +384,7 @@ static int __devinit sis5595_probe(struct pci_dev *dev, const struct pci_device_
384 return -ENODEV; 384 return -ENODEV;
385 } 385 }
386 386
387 /* set up the driverfs linkage to our parent device */ 387 /* set up the sysfs linkage to our parent device */
388 sis5595_adapter.dev.parent = &dev->dev; 388 sis5595_adapter.dev.parent = &dev->dev;
389 389
390 sprintf(sis5595_adapter.name, "SMBus SIS5595 adapter at %04x", 390 sprintf(sis5595_adapter.name, "SMBus SIS5595 adapter at %04x",
diff --git a/drivers/i2c/busses/i2c-sis630.c b/drivers/i2c/busses/i2c-sis630.c
index 172bacf932a6..5fd734f99ee9 100644
--- a/drivers/i2c/busses/i2c-sis630.c
+++ b/drivers/i2c/busses/i2c-sis630.c
@@ -477,7 +477,7 @@ static int __devinit sis630_probe(struct pci_dev *dev, const struct pci_device_i
477 return -ENODEV; 477 return -ENODEV;
478 } 478 }
479 479
480 /* set up the driverfs linkage to our parent device */ 480 /* set up the sysfs linkage to our parent device */
481 sis630_adapter.dev.parent = &dev->dev; 481 sis630_adapter.dev.parent = &dev->dev;
482 482
483 sprintf(sis630_adapter.name, "SMBus SIS630 adapter at %04x", 483 sprintf(sis630_adapter.name, "SMBus SIS630 adapter at %04x",
diff --git a/drivers/i2c/busses/i2c-sis96x.c b/drivers/i2c/busses/i2c-sis96x.c
index 73dae449fb23..4157b0cd604c 100644
--- a/drivers/i2c/busses/i2c-sis96x.c
+++ b/drivers/i2c/busses/i2c-sis96x.c
@@ -297,7 +297,7 @@ static int __devinit sis96x_probe(struct pci_dev *dev,
297 return -EINVAL; 297 return -EINVAL;
298 } 298 }
299 299
300 /* set up the driverfs linkage to our parent device */ 300 /* set up the sysfs linkage to our parent device */
301 sis96x_adapter.dev.parent = &dev->dev; 301 sis96x_adapter.dev.parent = &dev->dev;
302 302
303 snprintf(sis96x_adapter.name, I2C_NAME_SIZE, 303 snprintf(sis96x_adapter.name, I2C_NAME_SIZE,
diff --git a/drivers/i2c/busses/i2c-via.c b/drivers/i2c/busses/i2c-via.c
index bbcc62151f7c..81520868797b 100644
--- a/drivers/i2c/busses/i2c-via.c
+++ b/drivers/i2c/busses/i2c-via.c
@@ -138,7 +138,7 @@ static int __devinit vt586b_probe(struct pci_dev *dev, const struct pci_device_i
138 outb(inb(I2C_DIR) & ~(I2C_SDA | I2C_SCL), I2C_DIR); 138 outb(inb(I2C_DIR) & ~(I2C_SDA | I2C_SCL), I2C_DIR);
139 outb(inb(I2C_OUT) & ~(I2C_SDA | I2C_SCL), I2C_OUT); 139 outb(inb(I2C_OUT) & ~(I2C_SDA | I2C_SCL), I2C_OUT);
140 140
141 /* set up the driverfs linkage to our parent device */ 141 /* set up the sysfs linkage to our parent device */
142 vt586b_adapter.dev.parent = &dev->dev; 142 vt586b_adapter.dev.parent = &dev->dev;
143 143
144 res = i2c_bit_add_bus(&vt586b_adapter); 144 res = i2c_bit_add_bus(&vt586b_adapter);
diff --git a/drivers/ide/Kconfig b/drivers/ide/Kconfig
index ec03341d2bd8..49234e32fd16 100644
--- a/drivers/ide/Kconfig
+++ b/drivers/ide/Kconfig
@@ -383,6 +383,9 @@ config BLK_DEV_OFFBOARD
383config BLK_DEV_GENERIC 383config BLK_DEV_GENERIC
384 tristate "Generic PCI IDE Chipset Support" 384 tristate "Generic PCI IDE Chipset Support"
385 depends on BLK_DEV_IDEPCI 385 depends on BLK_DEV_IDEPCI
386 help
387 This option provides generic support for various PCI IDE Chipsets
388 which otherwise might not be supported.
386 389
387config BLK_DEV_OPTI621 390config BLK_DEV_OPTI621
388 tristate "OPTi 82C621 chipset enhanced support (EXPERIMENTAL)" 391 tristate "OPTi 82C621 chipset enhanced support (EXPERIMENTAL)"
@@ -797,6 +800,14 @@ config BLK_DEV_IDEDMA_PMAC
797 to transfer data to and from memory. Saying Y is safe and improves 800 to transfer data to and from memory. Saying Y is safe and improves
798 performance. 801 performance.
799 802
803config BLK_DEV_IDE_CELLEB
804 bool "Toshiba's Cell Reference Set IDE support"
805 depends on PPC_CELLEB
806 help
807 This driver provides support for the built-in IDE controller on
808 Toshiba Cell Reference Board.
809 If unsure, say Y.
810
800config BLK_DEV_IDE_SWARM 811config BLK_DEV_IDE_SWARM
801 tristate "IDE for Sibyte evaluation boards" 812 tristate "IDE for Sibyte evaluation boards"
802 depends on SIBYTE_SB1xxx_SOC 813 depends on SIBYTE_SB1xxx_SOC
diff --git a/drivers/ide/Makefile b/drivers/ide/Makefile
index d9f029e8ff74..28feedfbd21d 100644
--- a/drivers/ide/Makefile
+++ b/drivers/ide/Makefile
@@ -37,6 +37,7 @@ ide-core-$(CONFIG_BLK_DEV_Q40IDE) += legacy/q40ide.o
37# built-in only drivers from ppc/ 37# built-in only drivers from ppc/
38ide-core-$(CONFIG_BLK_DEV_MPC8xx_IDE) += ppc/mpc8xx.o 38ide-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
40ide-core-$(CONFIG_BLK_DEV_IDE_CELLEB) += ppc/scc_pata.o
40 41
41# built-in only drivers from h8300/ 42# built-in only drivers from h8300/
42ide-core-$(CONFIG_H8300) += h8300/ide-h8300.o 43ide-core-$(CONFIG_H8300) += h8300/ide-h8300.o
diff --git a/drivers/ide/arm/icside.c b/drivers/ide/arm/icside.c
index 8a1c27f28692..40e5c66b81ce 100644
--- a/drivers/ide/arm/icside.c
+++ b/drivers/ide/arm/icside.c
@@ -307,26 +307,24 @@ static int icside_set_speed(ide_drive_t *drive, u8 xfer_mode)
307 return on; 307 return on;
308} 308}
309 309
310static int icside_dma_host_off(ide_drive_t *drive) 310static void icside_dma_host_off(ide_drive_t *drive)
311{ 311{
312 return 0;
313} 312}
314 313
315static int icside_dma_off_quietly(ide_drive_t *drive) 314static void icside_dma_off_quietly(ide_drive_t *drive)
316{ 315{
317 drive->using_dma = 0; 316 drive->using_dma = 0;
318 return icside_dma_host_off(drive);
319} 317}
320 318
321static int icside_dma_host_on(ide_drive_t *drive) 319static void icside_dma_host_on(ide_drive_t *drive)
322{ 320{
323 return 0;
324} 321}
325 322
326static int icside_dma_on(ide_drive_t *drive) 323static int icside_dma_on(ide_drive_t *drive)
327{ 324{
328 drive->using_dma = 1; 325 drive->using_dma = 1;
329 return icside_dma_host_on(drive); 326
327 return 0;
330} 328}
331 329
332static int icside_dma_check(ide_drive_t *drive) 330static int icside_dma_check(ide_drive_t *drive)
@@ -365,10 +363,7 @@ static int icside_dma_check(ide_drive_t *drive)
365out: 363out:
366 on = icside_set_speed(drive, xfer_mode); 364 on = icside_set_speed(drive, xfer_mode);
367 365
368 if (on) 366 return on ? 0 : -1;
369 return icside_dma_on(drive);
370 else
371 return icside_dma_off_quietly(drive);
372} 367}
373 368
374static int icside_dma_end(ide_drive_t *drive) 369static int icside_dma_end(ide_drive_t *drive)
@@ -497,9 +492,9 @@ static void icside_dma_init(ide_hwif_t *hwif)
497 hwif->autodma = autodma; 492 hwif->autodma = autodma;
498 493
499 hwif->ide_dma_check = icside_dma_check; 494 hwif->ide_dma_check = icside_dma_check;
500 hwif->ide_dma_host_off = icside_dma_host_off; 495 hwif->dma_host_off = icside_dma_host_off;
501 hwif->ide_dma_off_quietly = icside_dma_off_quietly; 496 hwif->dma_off_quietly = icside_dma_off_quietly;
502 hwif->ide_dma_host_on = icside_dma_host_on; 497 hwif->dma_host_on = icside_dma_host_on;
503 hwif->ide_dma_on = icside_dma_on; 498 hwif->ide_dma_on = icside_dma_on;
504 hwif->dma_setup = icside_dma_setup; 499 hwif->dma_setup = icside_dma_setup;
505 hwif->dma_exec_cmd = icside_dma_exec_cmd; 500 hwif->dma_exec_cmd = icside_dma_exec_cmd;
@@ -556,7 +551,7 @@ icside_setup(void __iomem *base, struct cardinfo *info, struct expansion_card *e
556 * Ensure we're using MMIO 551 * Ensure we're using MMIO
557 */ 552 */
558 default_hwif_mmiops(hwif); 553 default_hwif_mmiops(hwif);
559 hwif->mmio = 2; 554 hwif->mmio = 1;
560 555
561 for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++) { 556 for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++) {
562 hwif->hw.io_ports[i] = port; 557 hwif->hw.io_ports[i] = port;
diff --git a/drivers/ide/arm/rapide.c b/drivers/ide/arm/rapide.c
index 3058217767d6..9c6c49fdd2b1 100644
--- a/drivers/ide/arm/rapide.c
+++ b/drivers/ide/arm/rapide.c
@@ -46,7 +46,7 @@ rapide_locate_hwif(void __iomem *base, void __iomem *ctrl, unsigned int sz, int
46 hwif->hw.io_ports[IDE_CONTROL_OFFSET] = (unsigned long)ctrl; 46 hwif->hw.io_ports[IDE_CONTROL_OFFSET] = (unsigned long)ctrl;
47 hwif->io_ports[IDE_CONTROL_OFFSET] = (unsigned long)ctrl; 47 hwif->io_ports[IDE_CONTROL_OFFSET] = (unsigned long)ctrl;
48 hwif->hw.irq = hwif->irq = irq; 48 hwif->hw.irq = hwif->irq = irq;
49 hwif->mmio = 2; 49 hwif->mmio = 1;
50 default_hwif_mmiops(hwif); 50 default_hwif_mmiops(hwif);
51 51
52 return hwif; 52 return hwif;
diff --git a/drivers/ide/cris/ide-cris.c b/drivers/ide/cris/ide-cris.c
index 5797e0b5a132..6b2d152351b3 100644
--- a/drivers/ide/cris/ide-cris.c
+++ b/drivers/ide/cris/ide-cris.c
@@ -682,9 +682,12 @@ static void cris_ide_input_data (ide_drive_t *drive, void *, unsigned int);
682static void cris_ide_output_data (ide_drive_t *drive, void *, unsigned int); 682static void cris_ide_output_data (ide_drive_t *drive, void *, unsigned int);
683static void cris_atapi_input_bytes(ide_drive_t *drive, void *, unsigned int); 683static void cris_atapi_input_bytes(ide_drive_t *drive, void *, unsigned int);
684static void cris_atapi_output_bytes(ide_drive_t *drive, void *, unsigned int); 684static void cris_atapi_output_bytes(ide_drive_t *drive, void *, unsigned int);
685static int cris_dma_off (ide_drive_t *drive);
686static int cris_dma_on (ide_drive_t *drive); 685static int cris_dma_on (ide_drive_t *drive);
687 686
687static void cris_dma_off(ide_drive_t *drive)
688{
689}
690
688static void tune_cris_ide(ide_drive_t *drive, u8 pio) 691static void tune_cris_ide(ide_drive_t *drive, u8 pio)
689{ 692{
690 int setup, strobe, hold; 693 int setup, strobe, hold;
@@ -795,7 +798,7 @@ init_e100_ide (void)
795 0, 0, cris_ide_ack_intr, 798 0, 0, cris_ide_ack_intr,
796 ide_default_irq(0)); 799 ide_default_irq(0));
797 ide_register_hw(&hw, &hwif); 800 ide_register_hw(&hw, &hwif);
798 hwif->mmio = 2; 801 hwif->mmio = 1;
799 hwif->chipset = ide_etrax100; 802 hwif->chipset = ide_etrax100;
800 hwif->tuneproc = &tune_cris_ide; 803 hwif->tuneproc = &tune_cris_ide;
801 hwif->speedproc = &speed_cris_ide; 804 hwif->speedproc = &speed_cris_ide;
@@ -814,13 +817,16 @@ init_e100_ide (void)
814 hwif->OUTBSYNC = &cris_ide_outbsync; 817 hwif->OUTBSYNC = &cris_ide_outbsync;
815 hwif->INB = &cris_ide_inb; 818 hwif->INB = &cris_ide_inb;
816 hwif->INW = &cris_ide_inw; 819 hwif->INW = &cris_ide_inw;
817 hwif->ide_dma_host_off = &cris_dma_off; 820 hwif->dma_host_off = &cris_dma_off;
818 hwif->ide_dma_host_on = &cris_dma_on; 821 hwif->dma_host_on = &cris_dma_on;
819 hwif->ide_dma_off_quietly = &cris_dma_off; 822 hwif->dma_off_quietly = &cris_dma_off;
820 hwif->udma_four = 0; 823 hwif->udma_four = 0;
821 hwif->ultra_mask = cris_ultra_mask; 824 hwif->ultra_mask = cris_ultra_mask;
822 hwif->mwdma_mask = 0x07; /* Multiword DMA 0-2 */ 825 hwif->mwdma_mask = 0x07; /* Multiword DMA 0-2 */
823 hwif->swdma_mask = 0x07; /* Singleword DMA 0-2 */ 826 hwif->swdma_mask = 0x07; /* Singleword DMA 0-2 */
827 hwif->autodma = 1;
828 hwif->drives[0].autodma = 1;
829 hwif->drives[1].autodma = 1;
824 } 830 }
825 831
826 /* Reset pulse */ 832 /* Reset pulse */
@@ -835,11 +841,6 @@ init_e100_ide (void)
835 cris_ide_set_speed(TYPE_UDMA, ATA_UDMA2_CYC, ATA_UDMA2_DVS, 0); 841 cris_ide_set_speed(TYPE_UDMA, ATA_UDMA2_CYC, ATA_UDMA2_DVS, 0);
836} 842}
837 843
838static int cris_dma_off (ide_drive_t *drive)
839{
840 return 0;
841}
842
843static int cris_dma_on (ide_drive_t *drive) 844static int cris_dma_on (ide_drive_t *drive)
844{ 845{
845 return 0; 846 return 0;
@@ -1045,17 +1046,10 @@ static ide_startstop_t cris_dma_intr (ide_drive_t *drive)
1045 1046
1046static int cris_dma_check(ide_drive_t *drive) 1047static int cris_dma_check(ide_drive_t *drive)
1047{ 1048{
1048 ide_hwif_t *hwif = drive->hwif; 1049 if (ide_use_dma(drive) && cris_config_drive_for_dma(drive))
1049 struct hd_driveid* id = drive->id; 1050 return 0;
1050
1051 if (id && (id->capability & 1)) {
1052 if (ide_use_dma(drive)) {
1053 if (cris_config_drive_for_dma(drive))
1054 return hwif->ide_dma_on(drive);
1055 }
1056 }
1057 1051
1058 return hwif->ide_dma_off_quietly(drive); 1052 return -1;
1059} 1053}
1060 1054
1061static int cris_dma_end(ide_drive_t *drive) 1055static int cris_dma_end(ide_drive_t *drive)
diff --git a/drivers/ide/h8300/ide-h8300.c b/drivers/ide/h8300/ide-h8300.c
index 608ca871744b..88750a300337 100644
--- a/drivers/ide/h8300/ide-h8300.c
+++ b/drivers/ide/h8300/ide-h8300.c
@@ -76,13 +76,11 @@ static inline void hwif_setup(ide_hwif_t *hwif)
76{ 76{
77 default_hwif_iops(hwif); 77 default_hwif_iops(hwif);
78 78
79 hwif->mmio = 2; 79 hwif->mmio = 1;
80 hwif->OUTW = mm_outw; 80 hwif->OUTW = mm_outw;
81 hwif->OUTSW = mm_outsw; 81 hwif->OUTSW = mm_outsw;
82 hwif->INW = mm_inw; 82 hwif->INW = mm_inw;
83 hwif->INSW = mm_insw; 83 hwif->INSW = mm_insw;
84 hwif->OUTL = NULL;
85 hwif->INL = NULL;
86 hwif->OUTSL = NULL; 84 hwif->OUTSL = NULL;
87 hwif->INSL = NULL; 85 hwif->INSL = NULL;
88} 86}
diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
index 5969cec58dc1..45a928c058cf 100644
--- a/drivers/ide/ide-cd.c
+++ b/drivers/ide/ide-cd.c
@@ -687,15 +687,8 @@ static void ide_dump_status_no_sense(ide_drive_t *drive, const char *msg, u8 sta
687static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret) 687static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret)
688{ 688{
689 struct request *rq = HWGROUP(drive)->rq; 689 struct request *rq = HWGROUP(drive)->rq;
690 ide_hwif_t *hwif = HWIF(drive);
691 int stat, err, sense_key; 690 int stat, err, sense_key;
692 691
693 /* We may have bogus DMA interrupts in PIO state here */
694 if (HWIF(drive)->dma_status && hwif->atapi_irq_bogon) {
695 stat = hwif->INB(hwif->dma_status);
696 /* Should we force the bit as well ? */
697 hwif->OUTB(stat, hwif->dma_status);
698 }
699 /* Check for errors. */ 692 /* Check for errors. */
700 stat = HWIF(drive)->INB(IDE_STATUS_REG); 693 stat = HWIF(drive)->INB(IDE_STATUS_REG);
701 if (stat_ret) 694 if (stat_ret)
@@ -930,6 +923,10 @@ static ide_startstop_t cdrom_start_packet_command(ide_drive_t *drive,
930 HWIF(drive)->OUTB(drive->ctl, IDE_CONTROL_REG); 923 HWIF(drive)->OUTB(drive->ctl, IDE_CONTROL_REG);
931 924
932 if (CDROM_CONFIG_FLAGS (drive)->drq_interrupt) { 925 if (CDROM_CONFIG_FLAGS (drive)->drq_interrupt) {
926 /* waiting for CDB interrupt, not DMA yet. */
927 if (info->dma)
928 drive->waiting_for_dma = 0;
929
933 /* packet command */ 930 /* packet command */
934 ide_execute_command(drive, WIN_PACKETCMD, handler, ATAPI_WAIT_PC, cdrom_timer_expiry); 931 ide_execute_command(drive, WIN_PACKETCMD, handler, ATAPI_WAIT_PC, cdrom_timer_expiry);
935 return ide_started; 932 return ide_started;
@@ -972,6 +969,10 @@ static ide_startstop_t cdrom_transfer_packet_command (ide_drive_t *drive,
972 /* Check for errors. */ 969 /* Check for errors. */
973 if (cdrom_decode_status(drive, DRQ_STAT, NULL)) 970 if (cdrom_decode_status(drive, DRQ_STAT, NULL))
974 return ide_stopped; 971 return ide_stopped;
972
973 /* Ok, next interrupt will be DMA interrupt. */
974 if (info->dma)
975 drive->waiting_for_dma = 1;
975 } else { 976 } else {
976 /* Otherwise, we must wait for DRQ to get set. */ 977 /* Otherwise, we must wait for DRQ to get set. */
977 if (ide_wait_stat(&startstop, drive, DRQ_STAT, 978 if (ide_wait_stat(&startstop, drive, DRQ_STAT,
@@ -1103,7 +1104,7 @@ static ide_startstop_t cdrom_read_intr (ide_drive_t *drive)
1103 if (dma) { 1104 if (dma) {
1104 info->dma = 0; 1105 info->dma = 0;
1105 if ((dma_error = HWIF(drive)->ide_dma_end(drive))) 1106 if ((dma_error = HWIF(drive)->ide_dma_end(drive)))
1106 __ide_dma_off(drive); 1107 ide_dma_off(drive);
1107 } 1108 }
1108 1109
1109 if (cdrom_decode_status(drive, 0, &stat)) 1110 if (cdrom_decode_status(drive, 0, &stat))
@@ -1699,7 +1700,7 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
1699 if (dma) { 1700 if (dma) {
1700 if (dma_error) { 1701 if (dma_error) {
1701 printk(KERN_ERR "ide-cd: dma error\n"); 1702 printk(KERN_ERR "ide-cd: dma error\n");
1702 __ide_dma_off(drive); 1703 ide_dma_off(drive);
1703 return ide_error(drive, "dma error", stat); 1704 return ide_error(drive, "dma error", stat);
1704 } 1705 }
1705 1706
@@ -1825,7 +1826,7 @@ static ide_startstop_t cdrom_write_intr(ide_drive_t *drive)
1825 info->dma = 0; 1826 info->dma = 0;
1826 if ((dma_error = HWIF(drive)->ide_dma_end(drive))) { 1827 if ((dma_error = HWIF(drive)->ide_dma_end(drive))) {
1827 printk(KERN_ERR "ide-cd: write dma error\n"); 1828 printk(KERN_ERR "ide-cd: write dma error\n");
1828 __ide_dma_off(drive); 1829 ide_dma_off(drive);
1829 } 1830 }
1830 } 1831 }
1831 1832
@@ -3254,14 +3255,6 @@ int ide_cdrom_setup (ide_drive_t *drive)
3254 if (drive->autotune == IDE_TUNE_DEFAULT || 3255 if (drive->autotune == IDE_TUNE_DEFAULT ||
3255 drive->autotune == IDE_TUNE_AUTO) 3256 drive->autotune == IDE_TUNE_AUTO)
3256 drive->dsc_overlap = (drive->next != drive); 3257 drive->dsc_overlap = (drive->next != drive);
3257#if 0
3258 drive->dsc_overlap = (HWIF(drive)->no_dsc) ? 0 : 1;
3259 if (HWIF(drive)->no_dsc) {
3260 printk(KERN_INFO "ide-cd: %s: disabling DSC overlap\n",
3261 drive->name);
3262 drive->dsc_overlap = 0;
3263 }
3264#endif
3265 3258
3266 if (ide_cdrom_register(drive, nslots)) { 3259 if (ide_cdrom_register(drive, nslots)) {
3267 printk (KERN_ERR "%s: ide_cdrom_setup failed to register device with the cdrom driver.\n", drive->name); 3260 printk (KERN_ERR "%s: ide_cdrom_setup failed to register device with the cdrom driver.\n", drive->name);
@@ -3360,21 +3353,16 @@ static int idecd_open(struct inode * inode, struct file * file)
3360{ 3353{
3361 struct gendisk *disk = inode->i_bdev->bd_disk; 3354 struct gendisk *disk = inode->i_bdev->bd_disk;
3362 struct cdrom_info *info; 3355 struct cdrom_info *info;
3363 ide_drive_t *drive;
3364 int rc = -ENOMEM; 3356 int rc = -ENOMEM;
3365 3357
3366 if (!(info = ide_cd_get(disk))) 3358 if (!(info = ide_cd_get(disk)))
3367 return -ENXIO; 3359 return -ENXIO;
3368 3360
3369 drive = info->drive;
3370
3371 drive->usage++;
3372
3373 if (!info->buffer) 3361 if (!info->buffer)
3374 info->buffer = kmalloc(SECTOR_BUFFER_SIZE, 3362 info->buffer = kmalloc(SECTOR_BUFFER_SIZE, GFP_KERNEL|__GFP_REPEAT);
3375 GFP_KERNEL|__GFP_REPEAT); 3363
3376 if (!info->buffer || (rc = cdrom_open(&info->devinfo, inode, file))) 3364 if (info->buffer)
3377 drive->usage--; 3365 rc = cdrom_open(&info->devinfo, inode, file);
3378 3366
3379 if (rc < 0) 3367 if (rc < 0)
3380 ide_cd_put(info); 3368 ide_cd_put(info);
@@ -3386,10 +3374,8 @@ static int idecd_release(struct inode * inode, struct file * file)
3386{ 3374{
3387 struct gendisk *disk = inode->i_bdev->bd_disk; 3375 struct gendisk *disk = inode->i_bdev->bd_disk;
3388 struct cdrom_info *info = ide_cd_g(disk); 3376 struct cdrom_info *info = ide_cd_g(disk);
3389 ide_drive_t *drive = info->drive;
3390 3377
3391 cdrom_release (&info->devinfo, file); 3378 cdrom_release (&info->devinfo, file);
3392 drive->usage--;
3393 3379
3394 ide_cd_put(info); 3380 ide_cd_put(info);
3395 3381
diff --git a/drivers/ide/ide-disk.c b/drivers/ide/ide-disk.c
index 0a05a377d66a..e2cea1889c4d 100644
--- a/drivers/ide/ide-disk.c
+++ b/drivers/ide/ide-disk.c
@@ -77,6 +77,7 @@ struct ide_disk_obj {
77 ide_driver_t *driver; 77 ide_driver_t *driver;
78 struct gendisk *disk; 78 struct gendisk *disk;
79 struct kref kref; 79 struct kref kref;
80 unsigned int openers; /* protected by BKL for now */
80}; 81};
81 82
82static DEFINE_MUTEX(idedisk_ref_mutex); 83static DEFINE_MUTEX(idedisk_ref_mutex);
@@ -1081,8 +1082,9 @@ static int idedisk_open(struct inode *inode, struct file *filp)
1081 1082
1082 drive = idkp->drive; 1083 drive = idkp->drive;
1083 1084
1084 drive->usage++; 1085 idkp->openers++;
1085 if (drive->removable && drive->usage == 1) { 1086
1087 if (drive->removable && idkp->openers == 1) {
1086 ide_task_t args; 1088 ide_task_t args;
1087 memset(&args, 0, sizeof(ide_task_t)); 1089 memset(&args, 0, sizeof(ide_task_t));
1088 args.tfRegister[IDE_COMMAND_OFFSET] = WIN_DOORLOCK; 1090 args.tfRegister[IDE_COMMAND_OFFSET] = WIN_DOORLOCK;
@@ -1106,9 +1108,10 @@ static int idedisk_release(struct inode *inode, struct file *filp)
1106 struct ide_disk_obj *idkp = ide_disk_g(disk); 1108 struct ide_disk_obj *idkp = ide_disk_g(disk);
1107 ide_drive_t *drive = idkp->drive; 1109 ide_drive_t *drive = idkp->drive;
1108 1110
1109 if (drive->usage == 1) 1111 if (idkp->openers == 1)
1110 ide_cacheflush_p(drive); 1112 ide_cacheflush_p(drive);
1111 if (drive->removable && drive->usage == 1) { 1113
1114 if (drive->removable && idkp->openers == 1) {
1112 ide_task_t args; 1115 ide_task_t args;
1113 memset(&args, 0, sizeof(ide_task_t)); 1116 memset(&args, 0, sizeof(ide_task_t));
1114 args.tfRegister[IDE_COMMAND_OFFSET] = WIN_DOORUNLOCK; 1117 args.tfRegister[IDE_COMMAND_OFFSET] = WIN_DOORUNLOCK;
@@ -1117,7 +1120,8 @@ static int idedisk_release(struct inode *inode, struct file *filp)
1117 if (drive->doorlocking && ide_raw_taskfile(drive, &args, NULL)) 1120 if (drive->doorlocking && ide_raw_taskfile(drive, &args, NULL))
1118 drive->doorlocking = 0; 1121 drive->doorlocking = 0;
1119 } 1122 }
1120 drive->usage--; 1123
1124 idkp->openers--;
1121 1125
1122 ide_disk_put(idkp); 1126 ide_disk_put(idkp);
1123 1127
diff --git a/drivers/ide/ide-dma.c b/drivers/ide/ide-dma.c
index 56efed6742d4..08e7cd043bcc 100644
--- a/drivers/ide/ide-dma.c
+++ b/drivers/ide/ide-dma.c
@@ -348,15 +348,14 @@ EXPORT_SYMBOL_GPL(ide_destroy_dmatable);
348static int config_drive_for_dma (ide_drive_t *drive) 348static int config_drive_for_dma (ide_drive_t *drive)
349{ 349{
350 struct hd_driveid *id = drive->id; 350 struct hd_driveid *id = drive->id;
351 ide_hwif_t *hwif = HWIF(drive);
352 351
353 if ((id->capability & 1) && hwif->autodma) { 352 if ((id->capability & 1) && drive->hwif->autodma) {
354 /* 353 /*
355 * Enable DMA on any drive that has 354 * Enable DMA on any drive that has
356 * UltraDMA (mode 0/1/2/3/4/5/6) enabled 355 * UltraDMA (mode 0/1/2/3/4/5/6) enabled
357 */ 356 */
358 if ((id->field_valid & 4) && ((id->dma_ultra >> 8) & 0x7f)) 357 if ((id->field_valid & 4) && ((id->dma_ultra >> 8) & 0x7f))
359 return hwif->ide_dma_on(drive); 358 return 0;
360 /* 359 /*
361 * Enable DMA on any drive that has mode2 DMA 360 * Enable DMA on any drive that has mode2 DMA
362 * (multi or single) enabled 361 * (multi or single) enabled
@@ -364,14 +363,14 @@ static int config_drive_for_dma (ide_drive_t *drive)
364 if (id->field_valid & 2) /* regular DMA */ 363 if (id->field_valid & 2) /* regular DMA */
365 if ((id->dma_mword & 0x404) == 0x404 || 364 if ((id->dma_mword & 0x404) == 0x404 ||
366 (id->dma_1word & 0x404) == 0x404) 365 (id->dma_1word & 0x404) == 0x404)
367 return hwif->ide_dma_on(drive); 366 return 0;
368 367
369 /* Consult the list of known "good" drives */ 368 /* Consult the list of known "good" drives */
370 if (__ide_dma_good_drive(drive)) 369 if (__ide_dma_good_drive(drive))
371 return hwif->ide_dma_on(drive); 370 return 0;
372 } 371 }
373// if (hwif->tuneproc != NULL) hwif->tuneproc(drive, 255); 372
374 return hwif->ide_dma_off_quietly(drive); 373 return -1;
375} 374}
376 375
377/** 376/**
@@ -415,72 +414,68 @@ static int dma_timer_expiry (ide_drive_t *drive)
415} 414}
416 415
417/** 416/**
418 * __ide_dma_host_off - Generic DMA kill 417 * ide_dma_host_off - Generic DMA kill
419 * @drive: drive to control 418 * @drive: drive to control
420 * 419 *
421 * Perform the generic IDE controller DMA off operation. This 420 * Perform the generic IDE controller DMA off operation. This
422 * works for most IDE bus mastering controllers 421 * works for most IDE bus mastering controllers
423 */ 422 */
424 423
425int __ide_dma_host_off (ide_drive_t *drive) 424void ide_dma_host_off(ide_drive_t *drive)
426{ 425{
427 ide_hwif_t *hwif = HWIF(drive); 426 ide_hwif_t *hwif = HWIF(drive);
428 u8 unit = (drive->select.b.unit & 0x01); 427 u8 unit = (drive->select.b.unit & 0x01);
429 u8 dma_stat = hwif->INB(hwif->dma_status); 428 u8 dma_stat = hwif->INB(hwif->dma_status);
430 429
431 hwif->OUTB((dma_stat & ~(1<<(5+unit))), hwif->dma_status); 430 hwif->OUTB((dma_stat & ~(1<<(5+unit))), hwif->dma_status);
432 return 0;
433} 431}
434 432
435EXPORT_SYMBOL(__ide_dma_host_off); 433EXPORT_SYMBOL(ide_dma_host_off);
436 434
437/** 435/**
438 * __ide_dma_host_off_quietly - Generic DMA kill 436 * ide_dma_off_quietly - Generic DMA kill
439 * @drive: drive to control 437 * @drive: drive to control
440 * 438 *
441 * Turn off the current DMA on this IDE controller. 439 * Turn off the current DMA on this IDE controller.
442 */ 440 */
443 441
444int __ide_dma_off_quietly (ide_drive_t *drive) 442void ide_dma_off_quietly(ide_drive_t *drive)
445{ 443{
446 drive->using_dma = 0; 444 drive->using_dma = 0;
447 ide_toggle_bounce(drive, 0); 445 ide_toggle_bounce(drive, 0);
448 446
449 if (HWIF(drive)->ide_dma_host_off(drive)) 447 drive->hwif->dma_host_off(drive);
450 return 1;
451
452 return 0;
453} 448}
454 449
455EXPORT_SYMBOL(__ide_dma_off_quietly); 450EXPORT_SYMBOL(ide_dma_off_quietly);
456#endif /* CONFIG_BLK_DEV_IDEDMA_PCI */ 451#endif /* CONFIG_BLK_DEV_IDEDMA_PCI */
457 452
458/** 453/**
459 * __ide_dma_off - disable DMA on a device 454 * ide_dma_off - disable DMA on a device
460 * @drive: drive to disable DMA on 455 * @drive: drive to disable DMA on
461 * 456 *
462 * Disable IDE DMA for a device on this IDE controller. 457 * Disable IDE DMA for a device on this IDE controller.
463 * Inform the user that DMA has been disabled. 458 * Inform the user that DMA has been disabled.
464 */ 459 */
465 460
466int __ide_dma_off (ide_drive_t *drive) 461void ide_dma_off(ide_drive_t *drive)
467{ 462{
468 printk(KERN_INFO "%s: DMA disabled\n", drive->name); 463 printk(KERN_INFO "%s: DMA disabled\n", drive->name);
469 return HWIF(drive)->ide_dma_off_quietly(drive); 464 drive->hwif->dma_off_quietly(drive);
470} 465}
471 466
472EXPORT_SYMBOL(__ide_dma_off); 467EXPORT_SYMBOL(ide_dma_off);
473 468
474#ifdef CONFIG_BLK_DEV_IDEDMA_PCI 469#ifdef CONFIG_BLK_DEV_IDEDMA_PCI
475/** 470/**
476 * __ide_dma_host_on - Enable DMA on a host 471 * ide_dma_host_on - Enable DMA on a host
477 * @drive: drive to enable for DMA 472 * @drive: drive to enable for DMA
478 * 473 *
479 * Enable DMA on an IDE controller following generic bus mastering 474 * Enable DMA on an IDE controller following generic bus mastering
480 * IDE controller behaviour 475 * IDE controller behaviour
481 */ 476 */
482 477
483int __ide_dma_host_on (ide_drive_t *drive) 478void ide_dma_host_on(ide_drive_t *drive)
484{ 479{
485 if (drive->using_dma) { 480 if (drive->using_dma) {
486 ide_hwif_t *hwif = HWIF(drive); 481 ide_hwif_t *hwif = HWIF(drive);
@@ -488,12 +483,10 @@ int __ide_dma_host_on (ide_drive_t *drive)
488 u8 dma_stat = hwif->INB(hwif->dma_status); 483 u8 dma_stat = hwif->INB(hwif->dma_status);
489 484
490 hwif->OUTB((dma_stat|(1<<(5+unit))), hwif->dma_status); 485 hwif->OUTB((dma_stat|(1<<(5+unit))), hwif->dma_status);
491 return 0;
492 } 486 }
493 return 1;
494} 487}
495 488
496EXPORT_SYMBOL(__ide_dma_host_on); 489EXPORT_SYMBOL(ide_dma_host_on);
497 490
498/** 491/**
499 * __ide_dma_on - Enable DMA on a device 492 * __ide_dma_on - Enable DMA on a device
@@ -511,8 +504,7 @@ int __ide_dma_on (ide_drive_t *drive)
511 drive->using_dma = 1; 504 drive->using_dma = 1;
512 ide_toggle_bounce(drive, 1); 505 ide_toggle_bounce(drive, 1);
513 506
514 if (HWIF(drive)->ide_dma_host_on(drive)) 507 drive->hwif->dma_host_on(drive);
515 return 1;
516 508
517 return 0; 509 return 0;
518} 510}
@@ -565,7 +557,10 @@ int ide_dma_setup(ide_drive_t *drive)
565 } 557 }
566 558
567 /* PRD table */ 559 /* PRD table */
568 hwif->OUTL(hwif->dmatable_dma, hwif->dma_prdtable); 560 if (hwif->mmio)
561 writel(hwif->dmatable_dma, (void __iomem *)hwif->dma_prdtable);
562 else
563 outl(hwif->dmatable_dma, hwif->dma_prdtable);
569 564
570 /* specify r/w */ 565 /* specify r/w */
571 hwif->OUTB(reading, hwif->dma_command); 566 hwif->OUTB(reading, hwif->dma_command);
@@ -680,6 +675,9 @@ int ide_use_dma(ide_drive_t *drive)
680 struct hd_driveid *id = drive->id; 675 struct hd_driveid *id = drive->id;
681 ide_hwif_t *hwif = drive->hwif; 676 ide_hwif_t *hwif = drive->hwif;
682 677
678 if ((id->capability & 1) == 0 || drive->autodma == 0)
679 return 0;
680
683 /* consult the list of known "bad" drives */ 681 /* consult the list of known "bad" drives */
684 if (__ide_dma_bad_drive(drive)) 682 if (__ide_dma_bad_drive(drive))
685 return 0; 683 return 0;
@@ -753,12 +751,37 @@ void ide_dma_verbose(ide_drive_t *drive)
753 return; 751 return;
754bug_dma_off: 752bug_dma_off:
755 printk(", BUG DMA OFF"); 753 printk(", BUG DMA OFF");
756 hwif->ide_dma_off_quietly(drive); 754 hwif->dma_off_quietly(drive);
757 return; 755 return;
758} 756}
759 757
760EXPORT_SYMBOL(ide_dma_verbose); 758EXPORT_SYMBOL(ide_dma_verbose);
761 759
760int ide_set_dma(ide_drive_t *drive)
761{
762 ide_hwif_t *hwif = drive->hwif;
763 int rc;
764
765 rc = hwif->ide_dma_check(drive);
766
767 switch(rc) {
768 case -1: /* DMA needs to be disabled */
769 hwif->dma_off_quietly(drive);
770 return 0;
771 case 0: /* DMA needs to be enabled */
772 return hwif->ide_dma_on(drive);
773 case 1: /* DMA setting cannot be changed */
774 break;
775 default:
776 BUG();
777 break;
778 }
779
780 return rc;
781}
782
783EXPORT_SYMBOL_GPL(ide_set_dma);
784
762#ifdef CONFIG_BLK_DEV_IDEDMA_PCI 785#ifdef CONFIG_BLK_DEV_IDEDMA_PCI
763int __ide_dma_lostirq (ide_drive_t *drive) 786int __ide_dma_lostirq (ide_drive_t *drive)
764{ 787{
@@ -809,7 +832,7 @@ int ide_release_dma(ide_hwif_t *hwif)
809{ 832{
810 ide_release_dma_engine(hwif); 833 ide_release_dma_engine(hwif);
811 834
812 if (hwif->mmio == 2) 835 if (hwif->mmio)
813 return 1; 836 return 1;
814 else 837 else
815 return ide_release_iomio_dma(hwif); 838 return ide_release_iomio_dma(hwif);
@@ -878,9 +901,9 @@ static int ide_iomio_dma(ide_hwif_t *hwif, unsigned long base, unsigned int port
878 901
879static int ide_dma_iobase(ide_hwif_t *hwif, unsigned long base, unsigned int ports) 902static int ide_dma_iobase(ide_hwif_t *hwif, unsigned long base, unsigned int ports)
880{ 903{
881 if (hwif->mmio == 2) 904 if (hwif->mmio)
882 return ide_mapped_mmio_dma(hwif, base,ports); 905 return ide_mapped_mmio_dma(hwif, base,ports);
883 BUG_ON(hwif->mmio == 1); 906
884 return ide_iomio_dma(hwif, base, ports); 907 return ide_iomio_dma(hwif, base, ports);
885} 908}
886 909
@@ -908,14 +931,14 @@ void ide_setup_dma (ide_hwif_t *hwif, unsigned long dma_base, unsigned int num_p
908 if (!(hwif->dma_prdtable)) 931 if (!(hwif->dma_prdtable))
909 hwif->dma_prdtable = (hwif->dma_base + 4); 932 hwif->dma_prdtable = (hwif->dma_base + 4);
910 933
911 if (!hwif->ide_dma_off_quietly) 934 if (!hwif->dma_off_quietly)
912 hwif->ide_dma_off_quietly = &__ide_dma_off_quietly; 935 hwif->dma_off_quietly = &ide_dma_off_quietly;
913 if (!hwif->ide_dma_host_off) 936 if (!hwif->dma_host_off)
914 hwif->ide_dma_host_off = &__ide_dma_host_off; 937 hwif->dma_host_off = &ide_dma_host_off;
915 if (!hwif->ide_dma_on) 938 if (!hwif->ide_dma_on)
916 hwif->ide_dma_on = &__ide_dma_on; 939 hwif->ide_dma_on = &__ide_dma_on;
917 if (!hwif->ide_dma_host_on) 940 if (!hwif->dma_host_on)
918 hwif->ide_dma_host_on = &__ide_dma_host_on; 941 hwif->dma_host_on = &ide_dma_host_on;
919 if (!hwif->ide_dma_check) 942 if (!hwif->ide_dma_check)
920 hwif->ide_dma_check = &__ide_dma_check; 943 hwif->ide_dma_check = &__ide_dma_check;
921 if (!hwif->dma_setup) 944 if (!hwif->dma_setup)
diff --git a/drivers/ide/ide-floppy.c b/drivers/ide/ide-floppy.c
index d33717c8afd4..57cd21c5b2c1 100644
--- a/drivers/ide/ide-floppy.c
+++ b/drivers/ide/ide-floppy.c
@@ -279,6 +279,7 @@ typedef struct ide_floppy_obj {
279 ide_driver_t *driver; 279 ide_driver_t *driver;
280 struct gendisk *disk; 280 struct gendisk *disk;
281 struct kref kref; 281 struct kref kref;
282 unsigned int openers; /* protected by BKL for now */
282 283
283 /* Current packet command */ 284 /* Current packet command */
284 idefloppy_pc_t *pc; 285 idefloppy_pc_t *pc;
@@ -866,7 +867,7 @@ static ide_startstop_t idefloppy_pc_intr (ide_drive_t *drive)
866 if (test_and_clear_bit(PC_DMA_IN_PROGRESS, &pc->flags)) { 867 if (test_and_clear_bit(PC_DMA_IN_PROGRESS, &pc->flags)) {
867 printk(KERN_ERR "ide-floppy: The floppy wants to issue " 868 printk(KERN_ERR "ide-floppy: The floppy wants to issue "
868 "more interrupts in DMA mode\n"); 869 "more interrupts in DMA mode\n");
869 (void)__ide_dma_off(drive); 870 ide_dma_off(drive);
870 return ide_do_reset(drive); 871 return ide_do_reset(drive);
871 } 872 }
872 873
@@ -1096,9 +1097,9 @@ static ide_startstop_t idefloppy_issue_pc (ide_drive_t *drive, idefloppy_pc_t *p
1096 pc->current_position = pc->buffer; 1097 pc->current_position = pc->buffer;
1097 bcount.all = min(pc->request_transfer, 63 * 1024); 1098 bcount.all = min(pc->request_transfer, 63 * 1024);
1098 1099
1099 if (test_and_clear_bit(PC_DMA_ERROR, &pc->flags)) { 1100 if (test_and_clear_bit(PC_DMA_ERROR, &pc->flags))
1100 (void)__ide_dma_off(drive); 1101 ide_dma_off(drive);
1101 } 1102
1102 feature.all = 0; 1103 feature.all = 0;
1103 1104
1104 if (test_bit(PC_DMA_RECOMMENDED, &pc->flags) && drive->using_dma) 1105 if (test_bit(PC_DMA_RECOMMENDED, &pc->flags) && drive->using_dma)
@@ -1433,7 +1434,8 @@ static int idefloppy_get_capacity (ide_drive_t *drive)
1433 1434
1434 drive->bios_cyl = 0; 1435 drive->bios_cyl = 0;
1435 drive->bios_head = drive->bios_sect = 0; 1436 drive->bios_head = drive->bios_sect = 0;
1436 floppy->blocks = floppy->bs_factor = 0; 1437 floppy->blocks = 0;
1438 floppy->bs_factor = 1;
1437 set_capacity(floppy->disk, 0); 1439 set_capacity(floppy->disk, 0);
1438 1440
1439 idefloppy_create_read_capacity_cmd(&pc); 1441 idefloppy_create_read_capacity_cmd(&pc);
@@ -1949,9 +1951,9 @@ static int idefloppy_open(struct inode *inode, struct file *filp)
1949 1951
1950 drive = floppy->drive; 1952 drive = floppy->drive;
1951 1953
1952 drive->usage++; 1954 floppy->openers++;
1953 1955
1954 if (drive->usage == 1) { 1956 if (floppy->openers == 1) {
1955 clear_bit(IDEFLOPPY_FORMAT_IN_PROGRESS, &floppy->flags); 1957 clear_bit(IDEFLOPPY_FORMAT_IN_PROGRESS, &floppy->flags);
1956 /* Just in case */ 1958 /* Just in case */
1957 1959
@@ -1969,13 +1971,11 @@ static int idefloppy_open(struct inode *inode, struct file *filp)
1969 ** capacity of the drive or begin the format - Sam 1971 ** capacity of the drive or begin the format - Sam
1970 */ 1972 */
1971 ) { 1973 ) {
1972 drive->usage--;
1973 ret = -EIO; 1974 ret = -EIO;
1974 goto out_put_floppy; 1975 goto out_put_floppy;
1975 } 1976 }
1976 1977
1977 if (floppy->wp && (filp->f_mode & 2)) { 1978 if (floppy->wp && (filp->f_mode & 2)) {
1978 drive->usage--;
1979 ret = -EROFS; 1979 ret = -EROFS;
1980 goto out_put_floppy; 1980 goto out_put_floppy;
1981 } 1981 }
@@ -1987,13 +1987,13 @@ static int idefloppy_open(struct inode *inode, struct file *filp)
1987 } 1987 }
1988 check_disk_change(inode->i_bdev); 1988 check_disk_change(inode->i_bdev);
1989 } else if (test_bit(IDEFLOPPY_FORMAT_IN_PROGRESS, &floppy->flags)) { 1989 } else if (test_bit(IDEFLOPPY_FORMAT_IN_PROGRESS, &floppy->flags)) {
1990 drive->usage--;
1991 ret = -EBUSY; 1990 ret = -EBUSY;
1992 goto out_put_floppy; 1991 goto out_put_floppy;
1993 } 1992 }
1994 return 0; 1993 return 0;
1995 1994
1996out_put_floppy: 1995out_put_floppy:
1996 floppy->openers--;
1997 ide_floppy_put(floppy); 1997 ide_floppy_put(floppy);
1998 return ret; 1998 return ret;
1999} 1999}
@@ -2007,7 +2007,7 @@ static int idefloppy_release(struct inode *inode, struct file *filp)
2007 2007
2008 debug_log(KERN_INFO "Reached idefloppy_release\n"); 2008 debug_log(KERN_INFO "Reached idefloppy_release\n");
2009 2009
2010 if (drive->usage == 1) { 2010 if (floppy->openers == 1) {
2011 /* IOMEGA Clik! drives do not support lock/unlock commands */ 2011 /* IOMEGA Clik! drives do not support lock/unlock commands */
2012 if (!test_bit(IDEFLOPPY_CLIK_DRIVE, &floppy->flags)) { 2012 if (!test_bit(IDEFLOPPY_CLIK_DRIVE, &floppy->flags)) {
2013 idefloppy_create_prevent_cmd(&pc, 0); 2013 idefloppy_create_prevent_cmd(&pc, 0);
@@ -2016,7 +2016,8 @@ static int idefloppy_release(struct inode *inode, struct file *filp)
2016 2016
2017 clear_bit(IDEFLOPPY_FORMAT_IN_PROGRESS, &floppy->flags); 2017 clear_bit(IDEFLOPPY_FORMAT_IN_PROGRESS, &floppy->flags);
2018 } 2018 }
2019 drive->usage--; 2019
2020 floppy->openers--;
2020 2021
2021 ide_floppy_put(floppy); 2022 ide_floppy_put(floppy);
2022 2023
@@ -2050,7 +2051,7 @@ static int idefloppy_ioctl(struct inode *inode, struct file *file,
2050 prevent = 0; 2051 prevent = 0;
2051 /* fall through */ 2052 /* fall through */
2052 case CDROM_LOCKDOOR: 2053 case CDROM_LOCKDOOR:
2053 if (drive->usage > 1) 2054 if (floppy->openers > 1)
2054 return -EBUSY; 2055 return -EBUSY;
2055 2056
2056 /* The IOMEGA Clik! Drive doesn't support this command - no room for an eject mechanism */ 2057 /* The IOMEGA Clik! Drive doesn't support this command - no room for an eject mechanism */
@@ -2072,7 +2073,7 @@ static int idefloppy_ioctl(struct inode *inode, struct file *file,
2072 if (!(file->f_mode & 2)) 2073 if (!(file->f_mode & 2))
2073 return -EPERM; 2074 return -EPERM;
2074 2075
2075 if (drive->usage > 1) { 2076 if (floppy->openers > 1) {
2076 /* Don't format if someone is using the disk */ 2077 /* Don't format if someone is using the disk */
2077 2078
2078 clear_bit(IDEFLOPPY_FORMAT_IN_PROGRESS, 2079 clear_bit(IDEFLOPPY_FORMAT_IN_PROGRESS,
diff --git a/drivers/ide/ide-io.c b/drivers/ide/ide-io.c
index 2614f41b5074..c193553f6fe7 100644
--- a/drivers/ide/ide-io.c
+++ b/drivers/ide/ide-io.c
@@ -226,7 +226,7 @@ static ide_startstop_t ide_start_power_step(ide_drive_t *drive, struct request *
226 break; 226 break;
227 if (drive->hwif->ide_dma_check == NULL) 227 if (drive->hwif->ide_dma_check == NULL)
228 break; 228 break;
229 drive->hwif->ide_dma_check(drive); 229 ide_set_dma(drive);
230 break; 230 break;
231 } 231 }
232 pm->pm_step = ide_pm_state_completed; 232 pm->pm_step = ide_pm_state_completed;
@@ -1351,7 +1351,7 @@ static ide_startstop_t ide_dma_timeout_retry(ide_drive_t *drive, int error)
1351 */ 1351 */
1352 drive->retry_pio++; 1352 drive->retry_pio++;
1353 drive->state = DMA_PIO_RETRY; 1353 drive->state = DMA_PIO_RETRY;
1354 (void) hwif->ide_dma_off_quietly(drive); 1354 hwif->dma_off_quietly(drive);
1355 1355
1356 /* 1356 /*
1357 * un-busy drive etc (hwgroup->busy is cleared on return) and 1357 * un-busy drive etc (hwgroup->busy is cleared on return) and
@@ -1646,6 +1646,17 @@ irqreturn_t ide_intr (int irq, void *dev_id)
1646 del_timer(&hwgroup->timer); 1646 del_timer(&hwgroup->timer);
1647 spin_unlock(&ide_lock); 1647 spin_unlock(&ide_lock);
1648 1648
1649 /* Some controllers might set DMA INTR no matter DMA or PIO;
1650 * bmdma status might need to be cleared even for
1651 * PIO interrupts to prevent spurious/lost irq.
1652 */
1653 if (hwif->ide_dma_clear_irq && !(drive->waiting_for_dma))
1654 /* ide_dma_end() needs bmdma status for error checking.
1655 * So, skip clearing bmdma status here and leave it
1656 * to ide_dma_end() if this is dma interrupt.
1657 */
1658 hwif->ide_dma_clear_irq(drive);
1659
1649 if (drive->unmask) 1660 if (drive->unmask)
1650 local_irq_enable_in_hardirq(); 1661 local_irq_enable_in_hardirq();
1651 /* service this interrupt, may set handler for next interrupt */ 1662 /* service this interrupt, may set handler for next interrupt */
diff --git a/drivers/ide/ide-iops.c b/drivers/ide/ide-iops.c
index badde6331775..c67b3b1e6f4c 100644
--- a/drivers/ide/ide-iops.c
+++ b/drivers/ide/ide-iops.c
@@ -49,11 +49,6 @@ static void ide_insw (unsigned long port, void *addr, u32 count)
49 insw(port, addr, count); 49 insw(port, addr, count);
50} 50}
51 51
52static u32 ide_inl (unsigned long port)
53{
54 return (u32) inl(port);
55}
56
57static void ide_insl (unsigned long port, void *addr, u32 count) 52static void ide_insl (unsigned long port, void *addr, u32 count)
58{ 53{
59 insl(port, addr, count); 54 insl(port, addr, count);
@@ -79,11 +74,6 @@ static void ide_outsw (unsigned long port, void *addr, u32 count)
79 outsw(port, addr, count); 74 outsw(port, addr, count);
80} 75}
81 76
82static void ide_outl (u32 val, unsigned long port)
83{
84 outl(val, port);
85}
86
87static void ide_outsl (unsigned long port, void *addr, u32 count) 77static void ide_outsl (unsigned long port, void *addr, u32 count)
88{ 78{
89 outsl(port, addr, count); 79 outsl(port, addr, count);
@@ -94,12 +84,10 @@ void default_hwif_iops (ide_hwif_t *hwif)
94 hwif->OUTB = ide_outb; 84 hwif->OUTB = ide_outb;
95 hwif->OUTBSYNC = ide_outbsync; 85 hwif->OUTBSYNC = ide_outbsync;
96 hwif->OUTW = ide_outw; 86 hwif->OUTW = ide_outw;
97 hwif->OUTL = ide_outl;
98 hwif->OUTSW = ide_outsw; 87 hwif->OUTSW = ide_outsw;
99 hwif->OUTSL = ide_outsl; 88 hwif->OUTSL = ide_outsl;
100 hwif->INB = ide_inb; 89 hwif->INB = ide_inb;
101 hwif->INW = ide_inw; 90 hwif->INW = ide_inw;
102 hwif->INL = ide_inl;
103 hwif->INSW = ide_insw; 91 hwif->INSW = ide_insw;
104 hwif->INSL = ide_insl; 92 hwif->INSL = ide_insl;
105} 93}
@@ -123,11 +111,6 @@ static void ide_mm_insw (unsigned long port, void *addr, u32 count)
123 __ide_mm_insw((void __iomem *) port, addr, count); 111 __ide_mm_insw((void __iomem *) port, addr, count);
124} 112}
125 113
126static u32 ide_mm_inl (unsigned long port)
127{
128 return (u32) readl((void __iomem *) port);
129}
130
131static void ide_mm_insl (unsigned long port, void *addr, u32 count) 114static void ide_mm_insl (unsigned long port, void *addr, u32 count)
132{ 115{
133 __ide_mm_insl((void __iomem *) port, addr, count); 116 __ide_mm_insl((void __iomem *) port, addr, count);
@@ -153,11 +136,6 @@ static void ide_mm_outsw (unsigned long port, void *addr, u32 count)
153 __ide_mm_outsw((void __iomem *) port, addr, count); 136 __ide_mm_outsw((void __iomem *) port, addr, count);
154} 137}
155 138
156static void ide_mm_outl (u32 value, unsigned long port)
157{
158 writel(value, (void __iomem *) port);
159}
160
161static void ide_mm_outsl (unsigned long port, void *addr, u32 count) 139static void ide_mm_outsl (unsigned long port, void *addr, u32 count)
162{ 140{
163 __ide_mm_outsl((void __iomem *) port, addr, count); 141 __ide_mm_outsl((void __iomem *) port, addr, count);
@@ -170,12 +148,10 @@ void default_hwif_mmiops (ide_hwif_t *hwif)
170 this one is controller specific! */ 148 this one is controller specific! */
171 hwif->OUTBSYNC = ide_mm_outbsync; 149 hwif->OUTBSYNC = ide_mm_outbsync;
172 hwif->OUTW = ide_mm_outw; 150 hwif->OUTW = ide_mm_outw;
173 hwif->OUTL = ide_mm_outl;
174 hwif->OUTSW = ide_mm_outsw; 151 hwif->OUTSW = ide_mm_outsw;
175 hwif->OUTSL = ide_mm_outsl; 152 hwif->OUTSL = ide_mm_outsl;
176 hwif->INB = ide_mm_inb; 153 hwif->INB = ide_mm_inb;
177 hwif->INW = ide_mm_inw; 154 hwif->INW = ide_mm_inw;
178 hwif->INL = ide_mm_inl;
179 hwif->INSW = ide_mm_insw; 155 hwif->INSW = ide_mm_insw;
180 hwif->INSL = ide_mm_insl; 156 hwif->INSL = ide_mm_insl;
181} 157}
@@ -777,7 +753,7 @@ int ide_config_drive_speed (ide_drive_t *drive, u8 speed)
777 753
778#ifdef CONFIG_BLK_DEV_IDEDMA 754#ifdef CONFIG_BLK_DEV_IDEDMA
779 if (hwif->ide_dma_check) /* check if host supports DMA */ 755 if (hwif->ide_dma_check) /* check if host supports DMA */
780 hwif->ide_dma_host_off(drive); 756 hwif->dma_host_off(drive);
781#endif 757#endif
782 758
783 /* 759 /*
@@ -854,9 +830,9 @@ int ide_config_drive_speed (ide_drive_t *drive, u8 speed)
854 830
855#ifdef CONFIG_BLK_DEV_IDEDMA 831#ifdef CONFIG_BLK_DEV_IDEDMA
856 if (speed >= XFER_SW_DMA_0) 832 if (speed >= XFER_SW_DMA_0)
857 hwif->ide_dma_host_on(drive); 833 hwif->dma_host_on(drive);
858 else if (hwif->ide_dma_check) /* check if host supports DMA */ 834 else if (hwif->ide_dma_check) /* check if host supports DMA */
859 hwif->ide_dma_off_quietly(drive); 835 hwif->dma_off_quietly(drive);
860#endif 836#endif
861 837
862 switch(speed) { 838 switch(speed) {
@@ -1066,12 +1042,12 @@ static void check_dma_crc(ide_drive_t *drive)
1066{ 1042{
1067#ifdef CONFIG_BLK_DEV_IDEDMA 1043#ifdef CONFIG_BLK_DEV_IDEDMA
1068 if (drive->crc_count) { 1044 if (drive->crc_count) {
1069 (void) HWIF(drive)->ide_dma_off_quietly(drive); 1045 drive->hwif->dma_off_quietly(drive);
1070 ide_set_xfer_rate(drive, ide_auto_reduce_xfer(drive)); 1046 ide_set_xfer_rate(drive, ide_auto_reduce_xfer(drive));
1071 if (drive->current_speed >= XFER_SW_DMA_0) 1047 if (drive->current_speed >= XFER_SW_DMA_0)
1072 (void) HWIF(drive)->ide_dma_on(drive); 1048 (void) HWIF(drive)->ide_dma_on(drive);
1073 } else 1049 } else
1074 (void)__ide_dma_off(drive); 1050 ide_dma_off(drive);
1075#endif 1051#endif
1076} 1052}
1077 1053
diff --git a/drivers/ide/ide-lib.c b/drivers/ide/ide-lib.c
index 8237d89eec6e..8afce4ceea31 100644
--- a/drivers/ide/ide-lib.c
+++ b/drivers/ide/ide-lib.c
@@ -205,6 +205,21 @@ int ide_dma_enable (ide_drive_t *drive)
205 205
206EXPORT_SYMBOL(ide_dma_enable); 206EXPORT_SYMBOL(ide_dma_enable);
207 207
208int ide_use_fast_pio(ide_drive_t *drive)
209{
210 struct hd_driveid *id = drive->id;
211
212 if ((id->capability & 1) && drive->autodma)
213 return 1;
214
215 if ((id->capability & 8) || (id->field_valid & 2))
216 return 1;
217
218 return 0;
219}
220
221EXPORT_SYMBOL_GPL(ide_use_fast_pio);
222
208/* 223/*
209 * Standard (generic) timings for PIO modes, from ATA2 specification. 224 * Standard (generic) timings for PIO modes, from ATA2 specification.
210 * These timings are for access to the IDE data port register *only*. 225 * These timings are for access to the IDE data port register *only*.
@@ -349,7 +364,6 @@ u8 ide_get_best_pio_mode (ide_drive_t *drive, u8 mode_wanted, u8 max_mode, ide_p
349 int use_iordy = 0; 364 int use_iordy = 0;
350 struct hd_driveid* id = drive->id; 365 struct hd_driveid* id = drive->id;
351 int overridden = 0; 366 int overridden = 0;
352 int blacklisted = 0;
353 367
354 if (mode_wanted != 255) { 368 if (mode_wanted != 255) {
355 pio_mode = mode_wanted; 369 pio_mode = mode_wanted;
@@ -357,7 +371,6 @@ u8 ide_get_best_pio_mode (ide_drive_t *drive, u8 mode_wanted, u8 max_mode, ide_p
357 pio_mode = 0; 371 pio_mode = 0;
358 } else if ((pio_mode = ide_scan_pio_blacklist(id->model)) != -1) { 372 } else if ((pio_mode = ide_scan_pio_blacklist(id->model)) != -1) {
359 overridden = 1; 373 overridden = 1;
360 blacklisted = 1;
361 use_iordy = (pio_mode > 2); 374 use_iordy = (pio_mode > 2);
362 } else { 375 } else {
363 pio_mode = id->tPIO; 376 pio_mode = id->tPIO;
@@ -409,7 +422,6 @@ u8 ide_get_best_pio_mode (ide_drive_t *drive, u8 mode_wanted, u8 max_mode, ide_p
409 d->cycle_time = cycle_time ? cycle_time : ide_pio_timings[pio_mode].cycle_time; 422 d->cycle_time = cycle_time ? cycle_time : ide_pio_timings[pio_mode].cycle_time;
410 d->use_iordy = use_iordy; 423 d->use_iordy = use_iordy;
411 d->overridden = overridden; 424 d->overridden = overridden;
412 d->blacklisted = blacklisted;
413 } 425 }
414 return pio_mode; 426 return pio_mode;
415} 427}
@@ -462,8 +474,6 @@ int ide_set_xfer_rate(ide_drive_t *drive, u8 rate)
462 return -1; 474 return -1;
463} 475}
464 476
465EXPORT_SYMBOL_GPL(ide_set_xfer_rate);
466
467static void ide_dump_opcode(ide_drive_t *drive) 477static void ide_dump_opcode(ide_drive_t *drive)
468{ 478{
469 struct request *rq; 479 struct request *rq;
diff --git a/drivers/ide/ide-probe.c b/drivers/ide/ide-probe.c
index 176bbc850d6b..8afbd6cb94be 100644
--- a/drivers/ide/ide-probe.c
+++ b/drivers/ide/ide-probe.c
@@ -853,11 +853,11 @@ static void probe_hwif(ide_hwif_t *hwif)
853 * things, if not checked and cleared. 853 * things, if not checked and cleared.
854 * PARANOIA!!! 854 * PARANOIA!!!
855 */ 855 */
856 hwif->ide_dma_off_quietly(drive); 856 hwif->dma_off_quietly(drive);
857#ifdef CONFIG_IDEDMA_ONLYDISK 857#ifdef CONFIG_IDEDMA_ONLYDISK
858 if (drive->media == ide_disk) 858 if (drive->media == ide_disk)
859#endif 859#endif
860 hwif->ide_dma_check(drive); 860 ide_set_dma(drive);
861 } 861 }
862 } 862 }
863 } 863 }
diff --git a/drivers/ide/ide-tape.c b/drivers/ide/ide-tape.c
index c6eec0413a6c..4e59239fef75 100644
--- a/drivers/ide/ide-tape.c
+++ b/drivers/ide/ide-tape.c
@@ -1970,7 +1970,7 @@ static ide_startstop_t idetape_pc_intr (ide_drive_t *drive)
1970 printk(KERN_ERR "ide-tape: The tape wants to issue more " 1970 printk(KERN_ERR "ide-tape: The tape wants to issue more "
1971 "interrupts in DMA mode\n"); 1971 "interrupts in DMA mode\n");
1972 printk(KERN_ERR "ide-tape: DMA disabled, reverting to PIO\n"); 1972 printk(KERN_ERR "ide-tape: DMA disabled, reverting to PIO\n");
1973 (void)__ide_dma_off(drive); 1973 ide_dma_off(drive);
1974 return ide_do_reset(drive); 1974 return ide_do_reset(drive);
1975 } 1975 }
1976 /* Get the number of bytes to transfer on this interrupt. */ 1976 /* Get the number of bytes to transfer on this interrupt. */
@@ -2176,7 +2176,7 @@ static ide_startstop_t idetape_issue_packet_command (ide_drive_t *drive, idetape
2176 if (test_and_clear_bit(PC_DMA_ERROR, &pc->flags)) { 2176 if (test_and_clear_bit(PC_DMA_ERROR, &pc->flags)) {
2177 printk(KERN_WARNING "ide-tape: DMA disabled, " 2177 printk(KERN_WARNING "ide-tape: DMA disabled, "
2178 "reverting to PIO\n"); 2178 "reverting to PIO\n");
2179 (void)__ide_dma_off(drive); 2179 ide_dma_off(drive);
2180 } 2180 }
2181 if (test_bit(PC_DMA_RECOMMENDED, &pc->flags) && drive->using_dma) 2181 if (test_bit(PC_DMA_RECOMMENDED, &pc->flags) && drive->using_dma)
2182 dma_ok = !hwif->dma_setup(drive); 2182 dma_ok = !hwif->dma_setup(drive);
@@ -4792,15 +4792,10 @@ static int idetape_open(struct inode *inode, struct file *filp)
4792{ 4792{
4793 struct gendisk *disk = inode->i_bdev->bd_disk; 4793 struct gendisk *disk = inode->i_bdev->bd_disk;
4794 struct ide_tape_obj *tape; 4794 struct ide_tape_obj *tape;
4795 ide_drive_t *drive;
4796 4795
4797 if (!(tape = ide_tape_get(disk))) 4796 if (!(tape = ide_tape_get(disk)))
4798 return -ENXIO; 4797 return -ENXIO;
4799 4798
4800 drive = tape->drive;
4801
4802 drive->usage++;
4803
4804 return 0; 4799 return 0;
4805} 4800}
4806 4801
@@ -4808,9 +4803,6 @@ static int idetape_release(struct inode *inode, struct file *filp)
4808{ 4803{
4809 struct gendisk *disk = inode->i_bdev->bd_disk; 4804 struct gendisk *disk = inode->i_bdev->bd_disk;
4810 struct ide_tape_obj *tape = ide_tape_g(disk); 4805 struct ide_tape_obj *tape = ide_tape_g(disk);
4811 ide_drive_t *drive = tape->drive;
4812
4813 drive->usage--;
4814 4806
4815 ide_tape_put(tape); 4807 ide_tape_put(tape);
4816 4808
diff --git a/drivers/ide/ide.c b/drivers/ide/ide.c
index c750f6ce770a..b3c0818c5c6c 100644
--- a/drivers/ide/ide.c
+++ b/drivers/ide/ide.c
@@ -389,9 +389,8 @@ int ide_hwif_request_regions(ide_hwif_t *hwif)
389 unsigned long addr; 389 unsigned long addr;
390 unsigned int i; 390 unsigned int i;
391 391
392 if (hwif->mmio == 2) 392 if (hwif->mmio)
393 return 0; 393 return 0;
394 BUG_ON(hwif->mmio == 1);
395 addr = hwif->io_ports[IDE_CONTROL_OFFSET]; 394 addr = hwif->io_ports[IDE_CONTROL_OFFSET];
396 if (addr && !hwif_request_region(hwif, addr, 1)) 395 if (addr && !hwif_request_region(hwif, addr, 1))
397 goto control_region_busy; 396 goto control_region_busy;
@@ -438,7 +437,7 @@ void ide_hwif_release_regions(ide_hwif_t *hwif)
438{ 437{
439 u32 i = 0; 438 u32 i = 0;
440 439
441 if (hwif->mmio == 2) 440 if (hwif->mmio)
442 return; 441 return;
443 if (hwif->io_ports[IDE_CONTROL_OFFSET]) 442 if (hwif->io_ports[IDE_CONTROL_OFFSET])
444 release_region(hwif->io_ports[IDE_CONTROL_OFFSET], 1); 443 release_region(hwif->io_ports[IDE_CONTROL_OFFSET], 1);
@@ -507,23 +506,22 @@ static void ide_hwif_restore(ide_hwif_t *hwif, ide_hwif_t *tmp_hwif)
507 hwif->ide_dma_end = tmp_hwif->ide_dma_end; 506 hwif->ide_dma_end = tmp_hwif->ide_dma_end;
508 hwif->ide_dma_check = tmp_hwif->ide_dma_check; 507 hwif->ide_dma_check = tmp_hwif->ide_dma_check;
509 hwif->ide_dma_on = tmp_hwif->ide_dma_on; 508 hwif->ide_dma_on = tmp_hwif->ide_dma_on;
510 hwif->ide_dma_off_quietly = tmp_hwif->ide_dma_off_quietly; 509 hwif->dma_off_quietly = tmp_hwif->dma_off_quietly;
511 hwif->ide_dma_test_irq = tmp_hwif->ide_dma_test_irq; 510 hwif->ide_dma_test_irq = tmp_hwif->ide_dma_test_irq;
512 hwif->ide_dma_host_on = tmp_hwif->ide_dma_host_on; 511 hwif->ide_dma_clear_irq = tmp_hwif->ide_dma_clear_irq;
513 hwif->ide_dma_host_off = tmp_hwif->ide_dma_host_off; 512 hwif->dma_host_on = tmp_hwif->dma_host_on;
513 hwif->dma_host_off = tmp_hwif->dma_host_off;
514 hwif->ide_dma_lostirq = tmp_hwif->ide_dma_lostirq; 514 hwif->ide_dma_lostirq = tmp_hwif->ide_dma_lostirq;
515 hwif->ide_dma_timeout = tmp_hwif->ide_dma_timeout; 515 hwif->ide_dma_timeout = tmp_hwif->ide_dma_timeout;
516 516
517 hwif->OUTB = tmp_hwif->OUTB; 517 hwif->OUTB = tmp_hwif->OUTB;
518 hwif->OUTBSYNC = tmp_hwif->OUTBSYNC; 518 hwif->OUTBSYNC = tmp_hwif->OUTBSYNC;
519 hwif->OUTW = tmp_hwif->OUTW; 519 hwif->OUTW = tmp_hwif->OUTW;
520 hwif->OUTL = tmp_hwif->OUTL;
521 hwif->OUTSW = tmp_hwif->OUTSW; 520 hwif->OUTSW = tmp_hwif->OUTSW;
522 hwif->OUTSL = tmp_hwif->OUTSL; 521 hwif->OUTSL = tmp_hwif->OUTSL;
523 522
524 hwif->INB = tmp_hwif->INB; 523 hwif->INB = tmp_hwif->INB;
525 hwif->INW = tmp_hwif->INW; 524 hwif->INW = tmp_hwif->INW;
526 hwif->INL = tmp_hwif->INL;
527 hwif->INSW = tmp_hwif->INSW; 525 hwif->INSW = tmp_hwif->INSW;
528 hwif->INSL = tmp_hwif->INSL; 526 hwif->INSL = tmp_hwif->INSL;
529 527
@@ -551,7 +549,6 @@ static void ide_hwif_restore(ide_hwif_t *hwif, ide_hwif_t *tmp_hwif)
551 hwif->extra_ports = tmp_hwif->extra_ports; 549 hwif->extra_ports = tmp_hwif->extra_ports;
552 hwif->autodma = tmp_hwif->autodma; 550 hwif->autodma = tmp_hwif->autodma;
553 hwif->udma_four = tmp_hwif->udma_four; 551 hwif->udma_four = tmp_hwif->udma_four;
554 hwif->no_dsc = tmp_hwif->no_dsc;
555 552
556 hwif->hwif_data = tmp_hwif->hwif_data; 553 hwif->hwif_data = tmp_hwif->hwif_data;
557} 554}
@@ -1138,12 +1135,11 @@ static int set_using_dma (ide_drive_t *drive, int arg)
1138 if (HWIF(drive)->ide_dma_check == NULL) 1135 if (HWIF(drive)->ide_dma_check == NULL)
1139 return -EPERM; 1136 return -EPERM;
1140 if (arg) { 1137 if (arg) {
1141 if (HWIF(drive)->ide_dma_check(drive)) return -EIO; 1138 if (ide_set_dma(drive))
1142 if (HWIF(drive)->ide_dma_on(drive)) return -EIO;
1143 } else {
1144 if (__ide_dma_off(drive))
1145 return -EIO; 1139 return -EIO;
1146 } 1140 if (HWIF(drive)->ide_dma_on(drive)) return -EIO;
1141 } else
1142 ide_dma_off(drive);
1147 return 0; 1143 return 0;
1148#else 1144#else
1149 return -EPERM; 1145 return -EPERM;
diff --git a/drivers/ide/legacy/buddha.c b/drivers/ide/legacy/buddha.c
index 0391a3122878..1ed224a01f79 100644
--- a/drivers/ide/legacy/buddha.c
+++ b/drivers/ide/legacy/buddha.c
@@ -215,7 +215,7 @@ fail_base2:
215 215
216 index = ide_register_hw(&hw, &hwif); 216 index = ide_register_hw(&hw, &hwif);
217 if (index != -1) { 217 if (index != -1) {
218 hwif->mmio = 2; 218 hwif->mmio = 1;
219 printk("ide%d: ", index); 219 printk("ide%d: ", index);
220 switch(type) { 220 switch(type) {
221 case BOARD_BUDDHA: 221 case BOARD_BUDDHA:
diff --git a/drivers/ide/legacy/gayle.c b/drivers/ide/legacy/gayle.c
index 64d42619ab06..dcfadbbf55d8 100644
--- a/drivers/ide/legacy/gayle.c
+++ b/drivers/ide/legacy/gayle.c
@@ -167,7 +167,7 @@ found:
167 167
168 index = ide_register_hw(&hw, &hwif); 168 index = ide_register_hw(&hw, &hwif);
169 if (index != -1) { 169 if (index != -1) {
170 hwif->mmio = 2; 170 hwif->mmio = 1;
171 switch (i) { 171 switch (i) {
172 case 0: 172 case 0:
173 printk("ide%d: Gayle IDE interface (A%d style)\n", index, 173 printk("ide%d: Gayle IDE interface (A%d style)\n", index,
diff --git a/drivers/ide/legacy/ht6560b.c b/drivers/ide/legacy/ht6560b.c
index c48e87e512d3..19ccd006f205 100644
--- a/drivers/ide/legacy/ht6560b.c
+++ b/drivers/ide/legacy/ht6560b.c
@@ -143,16 +143,16 @@ static void ht6560b_selectproc (ide_drive_t *drive)
143 current_timing = timing; 143 current_timing = timing;
144 if (drive->media != ide_disk || !drive->present) 144 if (drive->media != ide_disk || !drive->present)
145 select |= HT_PREFETCH_MODE; 145 select |= HT_PREFETCH_MODE;
146 (void) HWIF(drive)->INB(HT_CONFIG_PORT); 146 (void)inb(HT_CONFIG_PORT);
147 (void) HWIF(drive)->INB(HT_CONFIG_PORT); 147 (void)inb(HT_CONFIG_PORT);
148 (void) HWIF(drive)->INB(HT_CONFIG_PORT); 148 (void)inb(HT_CONFIG_PORT);
149 (void) HWIF(drive)->INB(HT_CONFIG_PORT); 149 (void)inb(HT_CONFIG_PORT);
150 HWIF(drive)->OUTB(select, HT_CONFIG_PORT); 150 outb(select, HT_CONFIG_PORT);
151 /* 151 /*
152 * Set timing for this drive: 152 * Set timing for this drive:
153 */ 153 */
154 HWIF(drive)->OUTB(timing, IDE_SELECT_REG); 154 outb(timing, IDE_SELECT_REG);
155 (void) HWIF(drive)->INB(IDE_STATUS_REG); 155 (void)inb(IDE_STATUS_REG);
156#ifdef DEBUG 156#ifdef DEBUG
157 printk("ht6560b: %s: select=%#x timing=%#x\n", 157 printk("ht6560b: %s: select=%#x timing=%#x\n",
158 drive->name, select, timing); 158 drive->name, select, timing);
diff --git a/drivers/ide/legacy/macide.c b/drivers/ide/legacy/macide.c
index b1730d7e414c..4c0079ad52ac 100644
--- a/drivers/ide/legacy/macide.c
+++ b/drivers/ide/legacy/macide.c
@@ -141,7 +141,7 @@ void macide_init(void)
141 } 141 }
142 142
143 if (index != -1) { 143 if (index != -1) {
144 hwif->mmio = 2; 144 hwif->mmio = 1;
145 if (macintosh_config->ide_type == MAC_IDE_QUADRA) 145 if (macintosh_config->ide_type == MAC_IDE_QUADRA)
146 printk(KERN_INFO "ide%d: Macintosh Quadra IDE interface\n", index); 146 printk(KERN_INFO "ide%d: Macintosh Quadra IDE interface\n", index);
147 else if (macintosh_config->ide_type == MAC_IDE_PB) 147 else if (macintosh_config->ide_type == MAC_IDE_PB)
diff --git a/drivers/ide/legacy/q40ide.c b/drivers/ide/legacy/q40ide.c
index 434a94faa3b7..74f08124eabb 100644
--- a/drivers/ide/legacy/q40ide.c
+++ b/drivers/ide/legacy/q40ide.c
@@ -145,7 +145,7 @@ void q40ide_init(void)
145 index = ide_register_hw(&hw, &hwif); 145 index = ide_register_hw(&hw, &hwif);
146 // **FIXME** 146 // **FIXME**
147 if (index != -1) 147 if (index != -1)
148 hwif->mmio = 2; 148 hwif->mmio = 1;
149 } 149 }
150} 150}
151 151
diff --git a/drivers/ide/mips/au1xxx-ide.c b/drivers/ide/mips/au1xxx-ide.c
index c7854ea57b52..0a59d5ef1599 100644
--- a/drivers/ide/mips/au1xxx-ide.c
+++ b/drivers/ide/mips/au1xxx-ide.c
@@ -181,12 +181,6 @@ static int auide_tune_chipset (ide_drive_t *drive, u8 speed)
181{ 181{
182 int mem_sttime; 182 int mem_sttime;
183 int mem_stcfg; 183 int mem_stcfg;
184 unsigned long mode;
185
186#ifdef CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA
187 if (ide_use_dma(drive))
188 mode = ide_dma_speed(drive, 0);
189#endif
190 184
191 mem_sttime = 0; 185 mem_sttime = 0;
192 mem_stcfg = au_readl(MEM_STCFG2); 186 mem_stcfg = au_readl(MEM_STCFG2);
@@ -195,7 +189,7 @@ static int auide_tune_chipset (ide_drive_t *drive, u8 speed)
195 auide_tune_drive(drive, speed - XFER_PIO_0); 189 auide_tune_drive(drive, speed - XFER_PIO_0);
196 return 0; 190 return 0;
197 } 191 }
198 192
199 switch(speed) { 193 switch(speed) {
200#ifdef CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA 194#ifdef CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA
201 case XFER_MW_DMA_2: 195 case XFER_MW_DMA_2:
@@ -207,7 +201,6 @@ static int auide_tune_chipset (ide_drive_t *drive, u8 speed)
207 mem_stcfg &= ~TOECS_MASK; 201 mem_stcfg &= ~TOECS_MASK;
208 mem_stcfg |= SBC_IDE_MDMA2_TCSOE | SBC_IDE_MDMA2_TOECS; 202 mem_stcfg |= SBC_IDE_MDMA2_TCSOE | SBC_IDE_MDMA2_TOECS;
209 203
210 mode = XFER_MW_DMA_2;
211 break; 204 break;
212 case XFER_MW_DMA_1: 205 case XFER_MW_DMA_1:
213 mem_sttime = SBC_IDE_TIMING(MDMA1); 206 mem_sttime = SBC_IDE_TIMING(MDMA1);
@@ -218,7 +211,6 @@ static int auide_tune_chipset (ide_drive_t *drive, u8 speed)
218 mem_stcfg &= ~TOECS_MASK; 211 mem_stcfg &= ~TOECS_MASK;
219 mem_stcfg |= SBC_IDE_MDMA1_TCSOE | SBC_IDE_MDMA1_TOECS; 212 mem_stcfg |= SBC_IDE_MDMA1_TCSOE | SBC_IDE_MDMA1_TOECS;
220 213
221 mode = XFER_MW_DMA_1;
222 break; 214 break;
223 case XFER_MW_DMA_0: 215 case XFER_MW_DMA_0:
224 mem_sttime = SBC_IDE_TIMING(MDMA0); 216 mem_sttime = SBC_IDE_TIMING(MDMA0);
@@ -229,14 +221,13 @@ static int auide_tune_chipset (ide_drive_t *drive, u8 speed)
229 mem_stcfg &= ~TOECS_MASK; 221 mem_stcfg &= ~TOECS_MASK;
230 mem_stcfg |= SBC_IDE_MDMA0_TCSOE | SBC_IDE_MDMA0_TOECS; 222 mem_stcfg |= SBC_IDE_MDMA0_TCSOE | SBC_IDE_MDMA0_TOECS;
231 223
232 mode = XFER_MW_DMA_0;
233 break; 224 break;
234#endif 225#endif
235 default: 226 default:
236 return 1; 227 return 1;
237 } 228 }
238 229
239 if (ide_config_drive_speed(drive, mode)) 230 if (ide_config_drive_speed(drive, speed))
240 return 1; 231 return 1;
241 232
242 au_writel(mem_sttime,MEM_STTIME2); 233 au_writel(mem_sttime,MEM_STTIME2);
@@ -423,9 +414,9 @@ static int auide_dma_check(ide_drive_t *drive)
423 speed = ide_find_best_mode(drive, XFER_PIO | XFER_MWDMA); 414 speed = ide_find_best_mode(drive, XFER_PIO | XFER_MWDMA);
424 415
425 if (drive->autodma && (speed & XFER_MODE) != XFER_PIO) 416 if (drive->autodma && (speed & XFER_MODE) != XFER_PIO)
426 return HWIF(drive)->ide_dma_on(drive); 417 return 0;
427 418
428 return HWIF(drive)->ide_dma_off_quietly(drive); 419 return -1;
429} 420}
430 421
431static int auide_dma_test_irq(ide_drive_t *drive) 422static int auide_dma_test_irq(ide_drive_t *drive)
@@ -447,27 +438,24 @@ static int auide_dma_test_irq(ide_drive_t *drive)
447 return 0; 438 return 0;
448} 439}
449 440
450static int auide_dma_host_on(ide_drive_t *drive) 441static void auide_dma_host_on(ide_drive_t *drive)
451{ 442{
452 return 0;
453} 443}
454 444
455static int auide_dma_on(ide_drive_t *drive) 445static int auide_dma_on(ide_drive_t *drive)
456{ 446{
457 drive->using_dma = 1; 447 drive->using_dma = 1;
458 return auide_dma_host_on(drive);
459}
460 448
449 return 0;
450}
461 451
462static int auide_dma_host_off(ide_drive_t *drive) 452static void auide_dma_host_off(ide_drive_t *drive)
463{ 453{
464 return 0;
465} 454}
466 455
467static int auide_dma_off_quietly(ide_drive_t *drive) 456static void auide_dma_off_quietly(ide_drive_t *drive)
468{ 457{
469 drive->using_dma = 0; 458 drive->using_dma = 0;
470 return auide_dma_host_off(drive);
471} 459}
472 460
473static int auide_dma_lostirq(ide_drive_t *drive) 461static int auide_dma_lostirq(ide_drive_t *drive)
@@ -717,7 +705,8 @@ static int au_ide_probe(struct device *dev)
717 705
718 /* hold should be on in all cases */ 706 /* hold should be on in all cases */
719 hwif->hold = 1; 707 hwif->hold = 1;
720 hwif->mmio = 2; 708
709 hwif->mmio = 1;
721 710
722 /* If the user has selected DDMA assisted copies, 711 /* If the user has selected DDMA assisted copies,
723 then set up a few local I/O function entry points 712 then set up a few local I/O function entry points
@@ -732,7 +721,7 @@ static int au_ide_probe(struct device *dev)
732 hwif->speedproc = &auide_tune_chipset; 721 hwif->speedproc = &auide_tune_chipset;
733 722
734#ifdef CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA 723#ifdef CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA
735 hwif->ide_dma_off_quietly = &auide_dma_off_quietly; 724 hwif->dma_off_quietly = &auide_dma_off_quietly;
736 hwif->ide_dma_timeout = &auide_dma_timeout; 725 hwif->ide_dma_timeout = &auide_dma_timeout;
737 726
738 hwif->ide_dma_check = &auide_dma_check; 727 hwif->ide_dma_check = &auide_dma_check;
@@ -741,8 +730,8 @@ static int au_ide_probe(struct device *dev)
741 hwif->ide_dma_end = &auide_dma_end; 730 hwif->ide_dma_end = &auide_dma_end;
742 hwif->dma_setup = &auide_dma_setup; 731 hwif->dma_setup = &auide_dma_setup;
743 hwif->ide_dma_test_irq = &auide_dma_test_irq; 732 hwif->ide_dma_test_irq = &auide_dma_test_irq;
744 hwif->ide_dma_host_off = &auide_dma_host_off; 733 hwif->dma_host_off = &auide_dma_host_off;
745 hwif->ide_dma_host_on = &auide_dma_host_on; 734 hwif->dma_host_on = &auide_dma_host_on;
746 hwif->ide_dma_lostirq = &auide_dma_lostirq; 735 hwif->ide_dma_lostirq = &auide_dma_lostirq;
747 hwif->ide_dma_on = &auide_dma_on; 736 hwif->ide_dma_on = &auide_dma_on;
748 737
diff --git a/drivers/ide/mips/swarm.c b/drivers/ide/mips/swarm.c
index 09c9e7936b0d..81fa06851b27 100644
--- a/drivers/ide/mips/swarm.c
+++ b/drivers/ide/mips/swarm.c
@@ -115,7 +115,7 @@ static int __devinit swarm_ide_probe(struct device *dev)
115 /* Setup MMIO ops. */ 115 /* Setup MMIO ops. */
116 default_hwif_mmiops(hwif); 116 default_hwif_mmiops(hwif);
117 /* Prevent resource map manipulation. */ 117 /* Prevent resource map manipulation. */
118 hwif->mmio = 2; 118 hwif->mmio = 1;
119 hwif->noprobe = 0; 119 hwif->noprobe = 0;
120 120
121 for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++) 121 for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++)
diff --git a/drivers/ide/pci/aec62xx.c b/drivers/ide/pci/aec62xx.c
index d261bfbad222..990eafe5ea11 100644
--- a/drivers/ide/pci/aec62xx.c
+++ b/drivers/ide/pci/aec62xx.c
@@ -94,9 +94,9 @@ static u8 aec62xx_ratemask (ide_drive_t *drive)
94 switch(hwif->pci_dev->device) { 94 switch(hwif->pci_dev->device) {
95 case PCI_DEVICE_ID_ARTOP_ATP865: 95 case PCI_DEVICE_ID_ARTOP_ATP865:
96 case PCI_DEVICE_ID_ARTOP_ATP865R: 96 case PCI_DEVICE_ID_ARTOP_ATP865R:
97 mode = (hwif->INB(((hwif->channel) ? 97 mode = (inb(hwif->channel ?
98 hwif->mate->dma_status : 98 hwif->mate->dma_status :
99 hwif->dma_status)) & 0x10) ? 4 : 3; 99 hwif->dma_status) & 0x10) ? 4 : 3;
100 break; 100 break;
101 case PCI_DEVICE_ID_ARTOP_ATP860: 101 case PCI_DEVICE_ID_ARTOP_ATP860:
102 case PCI_DEVICE_ID_ARTOP_ATP860R: 102 case PCI_DEVICE_ID_ARTOP_ATP860R:
@@ -209,25 +209,13 @@ static void aec62xx_tune_drive (ide_drive_t *drive, u8 pio)
209 209
210static int aec62xx_config_drive_xfer_rate (ide_drive_t *drive) 210static int aec62xx_config_drive_xfer_rate (ide_drive_t *drive)
211{ 211{
212 ide_hwif_t *hwif = HWIF(drive); 212 if (ide_use_dma(drive) && config_chipset_for_dma(drive))
213 struct hd_driveid *id = drive->id; 213 return 0;
214
215 if ((id->capability & 1) && drive->autodma) {
216
217 if (ide_use_dma(drive)) {
218 if (config_chipset_for_dma(drive))
219 return hwif->ide_dma_on(drive);
220 }
221
222 goto fast_ata_pio;
223 214
224 } else if ((id->capability & 8) || (id->field_valid & 2)) { 215 if (ide_use_fast_pio(drive))
225fast_ata_pio:
226 aec62xx_tune_drive(drive, 5); 216 aec62xx_tune_drive(drive, 5);
227 return hwif->ide_dma_off_quietly(drive); 217
228 } 218 return -1;
229 /* IORDY not supported */
230 return 0;
231} 219}
232 220
233static int aec62xx_irq_timeout (ide_drive_t *drive) 221static int aec62xx_irq_timeout (ide_drive_t *drive)
@@ -286,10 +274,8 @@ static void __devinit init_hwif_aec62xx(ide_hwif_t *hwif)
286 hwif->tuneproc = &aec62xx_tune_drive; 274 hwif->tuneproc = &aec62xx_tune_drive;
287 hwif->speedproc = &aec62xx_tune_chipset; 275 hwif->speedproc = &aec62xx_tune_chipset;
288 276
289 if (hwif->pci_dev->device == PCI_DEVICE_ID_ARTOP_ATP850UF) { 277 if (hwif->pci_dev->device == PCI_DEVICE_ID_ARTOP_ATP850UF)
290 hwif->serialized = hwif->channel; 278 hwif->serialized = hwif->channel;
291 hwif->no_dsc = 1;
292 }
293 279
294 if (hwif->mate) 280 if (hwif->mate)
295 hwif->mate->serialized = hwif->serialized; 281 hwif->mate->serialized = hwif->serialized;
diff --git a/drivers/ide/pci/alim15x3.c b/drivers/ide/pci/alim15x3.c
index 68df77ec502b..4debd18d52f8 100644
--- a/drivers/ide/pci/alim15x3.c
+++ b/drivers/ide/pci/alim15x3.c
@@ -507,17 +507,15 @@ static int config_chipset_for_dma (ide_drive_t *drive)
507 * 507 *
508 * Configure a drive for DMA operation. If DMA is not possible we 508 * Configure a drive for DMA operation. If DMA is not possible we
509 * drop the drive into PIO mode instead. 509 * drop the drive into PIO mode instead.
510 *
511 * FIXME: exactly what are we trying to return here
512 */ 510 */
513 511
514static int ali15x3_config_drive_for_dma(ide_drive_t *drive) 512static int ali15x3_config_drive_for_dma(ide_drive_t *drive)
515{ 513{
516 ide_hwif_t *hwif = HWIF(drive); 514 ide_hwif_t *hwif = HWIF(drive);
517 struct hd_driveid *id = drive->id; 515 struct hd_driveid *id = drive->id;
518 516
519 if ((m5229_revision<=0x20) && (drive->media!=ide_disk)) 517 if ((m5229_revision<=0x20) && (drive->media!=ide_disk))
520 return hwif->ide_dma_off_quietly(drive); 518 goto no_dma_set;
521 519
522 drive->init_speed = 0; 520 drive->init_speed = 0;
523 521
@@ -552,9 +550,10 @@ try_dma_modes:
552ata_pio: 550ata_pio:
553 hwif->tuneproc(drive, 255); 551 hwif->tuneproc(drive, 255);
554no_dma_set: 552no_dma_set:
555 return hwif->ide_dma_off_quietly(drive); 553 return -1;
556 } 554 }
557 return hwif->ide_dma_on(drive); 555
556 return 0;
558} 557}
559 558
560/** 559/**
@@ -852,8 +851,8 @@ static void __devinit init_dma_ali15x3 (ide_hwif_t *hwif, unsigned long dmabase)
852{ 851{
853 if (m5229_revision < 0x20) 852 if (m5229_revision < 0x20)
854 return; 853 return;
855 if (!(hwif->channel)) 854 if (!hwif->channel)
856 hwif->OUTB(hwif->INB(dmabase+2) & 0x60, dmabase+2); 855 outb(inb(dmabase + 2) & 0x60, dmabase + 2);
857 ide_setup_dma(hwif, dmabase, 8); 856 ide_setup_dma(hwif, dmabase, 8);
858} 857}
859 858
diff --git a/drivers/ide/pci/amd74xx.c b/drivers/ide/pci/amd74xx.c
index a4336995a410..7989bdd842a2 100644
--- a/drivers/ide/pci/amd74xx.c
+++ b/drivers/ide/pci/amd74xx.c
@@ -304,8 +304,9 @@ static int amd74xx_ide_dma_check(ide_drive_t *drive)
304 amd_set_drive(drive, speed); 304 amd_set_drive(drive, speed);
305 305
306 if (drive->autodma && (speed & XFER_MODE) != XFER_PIO) 306 if (drive->autodma && (speed & XFER_MODE) != XFER_PIO)
307 return HWIF(drive)->ide_dma_on(drive); 307 return 0;
308 return HWIF(drive)->ide_dma_off_quietly(drive); 308
309 return -1;
309} 310}
310 311
311/* 312/*
diff --git a/drivers/ide/pci/atiixp.c b/drivers/ide/pci/atiixp.c
index 982ac31fa995..2d48af32e3f4 100644
--- a/drivers/ide/pci/atiixp.c
+++ b/drivers/ide/pci/atiixp.c
@@ -101,7 +101,7 @@ static u8 atiixp_dma_2_pio(u8 xfer_rate) {
101 } 101 }
102} 102}
103 103
104static int atiixp_ide_dma_host_on(ide_drive_t *drive) 104static void atiixp_dma_host_on(ide_drive_t *drive)
105{ 105{
106 struct pci_dev *dev = drive->hwif->pci_dev; 106 struct pci_dev *dev = drive->hwif->pci_dev;
107 unsigned long flags; 107 unsigned long flags;
@@ -118,10 +118,10 @@ static int atiixp_ide_dma_host_on(ide_drive_t *drive)
118 118
119 spin_unlock_irqrestore(&atiixp_lock, flags); 119 spin_unlock_irqrestore(&atiixp_lock, flags);
120 120
121 return __ide_dma_host_on(drive); 121 ide_dma_host_on(drive);
122} 122}
123 123
124static int atiixp_ide_dma_host_off(ide_drive_t *drive) 124static void atiixp_dma_host_off(ide_drive_t *drive)
125{ 125{
126 struct pci_dev *dev = drive->hwif->pci_dev; 126 struct pci_dev *dev = drive->hwif->pci_dev;
127 unsigned long flags; 127 unsigned long flags;
@@ -135,7 +135,7 @@ static int atiixp_ide_dma_host_off(ide_drive_t *drive)
135 135
136 spin_unlock_irqrestore(&atiixp_lock, flags); 136 spin_unlock_irqrestore(&atiixp_lock, flags);
137 137
138 return __ide_dma_host_off(drive); 138 ide_dma_host_off(drive);
139} 139}
140 140
141/** 141/**
@@ -235,11 +235,8 @@ static int atiixp_config_drive_for_dma(ide_drive_t *drive)
235{ 235{
236 u8 speed = ide_dma_speed(drive, atiixp_ratemask(drive)); 236 u8 speed = ide_dma_speed(drive, atiixp_ratemask(drive));
237 237
238 /* If no DMA speed was available then disable DMA and use PIO. */ 238 if (!speed)
239 if (!speed) { 239 return 0;
240 u8 tspeed = ide_get_best_pio_mode(drive, 255, 5, NULL);
241 speed = atiixp_dma_2_pio(XFER_PIO_0 + tspeed) + XFER_PIO_0;
242 }
243 240
244 (void) atiixp_speedproc(drive, speed); 241 (void) atiixp_speedproc(drive, speed);
245 return ide_dma_enable(drive); 242 return ide_dma_enable(drive);
@@ -255,30 +252,20 @@ static int atiixp_config_drive_for_dma(ide_drive_t *drive)
255 252
256static int atiixp_dma_check(ide_drive_t *drive) 253static int atiixp_dma_check(ide_drive_t *drive)
257{ 254{
258 ide_hwif_t *hwif = HWIF(drive);
259 struct hd_driveid *id = drive->id;
260 u8 tspeed, speed; 255 u8 tspeed, speed;
261 256
262 drive->init_speed = 0; 257 drive->init_speed = 0;
263 258
264 if ((id->capability & 1) && drive->autodma) { 259 if (ide_use_dma(drive) && atiixp_config_drive_for_dma(drive))
265 260 return 0;
266 if (ide_use_dma(drive)) {
267 if (atiixp_config_drive_for_dma(drive))
268 return hwif->ide_dma_on(drive);
269 }
270
271 goto fast_ata_pio;
272 261
273 } else if ((id->capability & 8) || (id->field_valid & 2)) { 262 if (ide_use_fast_pio(drive)) {
274fast_ata_pio:
275 tspeed = ide_get_best_pio_mode(drive, 255, 5, NULL); 263 tspeed = ide_get_best_pio_mode(drive, 255, 5, NULL);
276 speed = atiixp_dma_2_pio(XFER_PIO_0 + tspeed) + XFER_PIO_0; 264 speed = atiixp_dma_2_pio(XFER_PIO_0 + tspeed) + XFER_PIO_0;
277 hwif->speedproc(drive, speed); 265 atiixp_speedproc(drive, speed);
278 return hwif->ide_dma_off_quietly(drive);
279 } 266 }
280 /* IORDY not supported */ 267
281 return 0; 268 return -1;
282} 269}
283 270
284/** 271/**
@@ -318,8 +305,8 @@ static void __devinit init_hwif_atiixp(ide_hwif_t *hwif)
318 else 305 else
319 hwif->udma_four = 0; 306 hwif->udma_four = 0;
320 307
321 hwif->ide_dma_host_on = &atiixp_ide_dma_host_on; 308 hwif->dma_host_on = &atiixp_dma_host_on;
322 hwif->ide_dma_host_off = &atiixp_ide_dma_host_off; 309 hwif->dma_host_off = &atiixp_dma_host_off;
323 hwif->ide_dma_check = &atiixp_dma_check; 310 hwif->ide_dma_check = &atiixp_dma_check;
324 if (!noautodma) 311 if (!noautodma)
325 hwif->autodma = 1; 312 hwif->autodma = 1;
diff --git a/drivers/ide/pci/cmd64x.c b/drivers/ide/pci/cmd64x.c
index aee947e8fc38..49df27513da7 100644
--- a/drivers/ide/pci/cmd64x.c
+++ b/drivers/ide/pci/cmd64x.c
@@ -466,36 +466,21 @@ static int config_chipset_for_dma (ide_drive_t *drive)
466 if (!speed) 466 if (!speed)
467 return 0; 467 return 0;
468 468
469 if(ide_set_xfer_rate(drive, speed)) 469 if (cmd64x_tune_chipset(drive, speed))
470 return 0; 470 return 0;
471
472 if (!drive->init_speed)
473 drive->init_speed = speed;
474 471
475 return ide_dma_enable(drive); 472 return ide_dma_enable(drive);
476} 473}
477 474
478static int cmd64x_config_drive_for_dma (ide_drive_t *drive) 475static int cmd64x_config_drive_for_dma (ide_drive_t *drive)
479{ 476{
480 ide_hwif_t *hwif = HWIF(drive); 477 if (ide_use_dma(drive) && config_chipset_for_dma(drive))
481 struct hd_driveid *id = drive->id; 478 return 0;
482
483 if ((id != NULL) && ((id->capability & 1) != 0) && drive->autodma) {
484
485 if (ide_use_dma(drive)) {
486 if (config_chipset_for_dma(drive))
487 return hwif->ide_dma_on(drive);
488 }
489
490 goto fast_ata_pio;
491 479
492 } else if ((id->capability & 8) || (id->field_valid & 2)) { 480 if (ide_use_fast_pio(drive))
493fast_ata_pio:
494 config_chipset_for_pio(drive, 1); 481 config_chipset_for_pio(drive, 1);
495 return hwif->ide_dma_off_quietly(drive); 482
496 } 483 return -1;
497 /* IORDY not supported */
498 return 0;
499} 484}
500 485
501static int cmd64x_alt_dma_status (struct pci_dev *dev) 486static int cmd64x_alt_dma_status (struct pci_dev *dev)
@@ -518,13 +503,13 @@ static int cmd64x_ide_dma_end (ide_drive_t *drive)
518 503
519 drive->waiting_for_dma = 0; 504 drive->waiting_for_dma = 0;
520 /* read DMA command state */ 505 /* read DMA command state */
521 dma_cmd = hwif->INB(hwif->dma_command); 506 dma_cmd = inb(hwif->dma_command);
522 /* stop DMA */ 507 /* stop DMA */
523 hwif->OUTB((dma_cmd & ~1), hwif->dma_command); 508 outb(dma_cmd & ~1, hwif->dma_command);
524 /* get DMA status */ 509 /* get DMA status */
525 dma_stat = hwif->INB(hwif->dma_status); 510 dma_stat = inb(hwif->dma_status);
526 /* clear the INTR & ERROR bits */ 511 /* clear the INTR & ERROR bits */
527 hwif->OUTB(dma_stat|6, hwif->dma_status); 512 outb(dma_stat | 6, hwif->dma_status);
528 if (cmd64x_alt_dma_status(dev)) { 513 if (cmd64x_alt_dma_status(dev)) {
529 u8 dma_intr = 0; 514 u8 dma_intr = 0;
530 u8 dma_mask = (hwif->channel) ? ARTTIM23_INTR_CH1 : 515 u8 dma_mask = (hwif->channel) ? ARTTIM23_INTR_CH1 :
@@ -546,7 +531,7 @@ static int cmd64x_ide_dma_test_irq (ide_drive_t *drive)
546 struct pci_dev *dev = hwif->pci_dev; 531 struct pci_dev *dev = hwif->pci_dev;
547 u8 dma_alt_stat = 0, mask = (hwif->channel) ? MRDMODE_INTR_CH1 : 532 u8 dma_alt_stat = 0, mask = (hwif->channel) ? MRDMODE_INTR_CH1 :
548 MRDMODE_INTR_CH0; 533 MRDMODE_INTR_CH0;
549 u8 dma_stat = hwif->INB(hwif->dma_status); 534 u8 dma_stat = inb(hwif->dma_status);
550 535
551 (void) pci_read_config_byte(dev, MRDMODE, &dma_alt_stat); 536 (void) pci_read_config_byte(dev, MRDMODE, &dma_alt_stat);
552#ifdef DEBUG 537#ifdef DEBUG
@@ -576,13 +561,13 @@ static int cmd646_1_ide_dma_end (ide_drive_t *drive)
576 561
577 drive->waiting_for_dma = 0; 562 drive->waiting_for_dma = 0;
578 /* get DMA status */ 563 /* get DMA status */
579 dma_stat = hwif->INB(hwif->dma_status); 564 dma_stat = inb(hwif->dma_status);
580 /* read DMA command state */ 565 /* read DMA command state */
581 dma_cmd = hwif->INB(hwif->dma_command); 566 dma_cmd = inb(hwif->dma_command);
582 /* stop DMA */ 567 /* stop DMA */
583 hwif->OUTB((dma_cmd & ~1), hwif->dma_command); 568 outb(dma_cmd & ~1, hwif->dma_command);
584 /* clear the INTR & ERROR bits */ 569 /* clear the INTR & ERROR bits */
585 hwif->OUTB(dma_stat|6, hwif->dma_status); 570 outb(dma_stat | 6, hwif->dma_status);
586 /* and free any DMA resources */ 571 /* and free any DMA resources */
587 ide_destroy_dmatable(drive); 572 ide_destroy_dmatable(drive);
588 /* verify good DMA status */ 573 /* verify good DMA status */
diff --git a/drivers/ide/pci/cs5520.c b/drivers/ide/pci/cs5520.c
index ba6786aabf3b..400859a839f7 100644
--- a/drivers/ide/pci/cs5520.c
+++ b/drivers/ide/pci/cs5520.c
@@ -132,12 +132,11 @@ static void cs5520_tune_drive(ide_drive_t *drive, u8 pio)
132 132
133static int cs5520_config_drive_xfer_rate(ide_drive_t *drive) 133static int cs5520_config_drive_xfer_rate(ide_drive_t *drive)
134{ 134{
135 ide_hwif_t *hwif = HWIF(drive);
136
137 /* Tune the drive for PIO modes up to PIO 4 */ 135 /* Tune the drive for PIO modes up to PIO 4 */
138 cs5520_tune_drive(drive, 4); 136 cs5520_tune_drive(drive, 4);
137
139 /* Then tell the core to use DMA operations */ 138 /* Then tell the core to use DMA operations */
140 return hwif->ide_dma_on(drive); 139 return 0;
141} 140}
142 141
143/* 142/*
diff --git a/drivers/ide/pci/cs5530.c b/drivers/ide/pci/cs5530.c
index 9bf5fdfc5b1f..b2d7c132ef4b 100644
--- a/drivers/ide/pci/cs5530.c
+++ b/drivers/ide/pci/cs5530.c
@@ -81,8 +81,8 @@ static void cs5530_tuneproc (ide_drive_t *drive, u8 pio) /* pio=255 means "autot
81 81
82 pio = ide_get_best_pio_mode(drive, pio, 4, NULL); 82 pio = ide_get_best_pio_mode(drive, pio, 4, NULL);
83 if (!cs5530_set_xfer_mode(drive, modes[pio])) { 83 if (!cs5530_set_xfer_mode(drive, modes[pio])) {
84 format = (hwif->INL(basereg+4) >> 31) & 1; 84 format = (inl(basereg + 4) >> 31) & 1;
85 hwif->OUTL(cs5530_pio_timings[format][pio], 85 outl(cs5530_pio_timings[format][pio],
86 basereg+(drive->select.b.unit<<3)); 86 basereg+(drive->select.b.unit<<3));
87 } 87 }
88} 88}
@@ -103,16 +103,13 @@ static int cs5530_config_dma (ide_drive_t *drive)
103 int unit = drive->select.b.unit; 103 int unit = drive->select.b.unit;
104 ide_drive_t *mate = &hwif->drives[unit^1]; 104 ide_drive_t *mate = &hwif->drives[unit^1];
105 struct hd_driveid *id = drive->id; 105 struct hd_driveid *id = drive->id;
106 unsigned int reg, timings; 106 unsigned int reg, timings = 0;
107 unsigned long basereg; 107 unsigned long basereg;
108 108
109 /* 109 /*
110 * Default to DMA-off in case we run into trouble here. 110 * Default to DMA-off in case we run into trouble here.
111 */ 111 */
112 hwif->ide_dma_off_quietly(drive); 112 hwif->dma_off_quietly(drive);
113 /* turn off DMA while we fiddle */
114 hwif->ide_dma_host_off(drive);
115 /* clear DMA_capable bit */
116 113
117 /* 114 /*
118 * The CS5530 specifies that two drives sharing a cable cannot 115 * The CS5530 specifies that two drives sharing a cable cannot
@@ -182,30 +179,24 @@ static int cs5530_config_dma (ide_drive_t *drive)
182 case XFER_MW_DMA_1: timings = 0x00012121; break; 179 case XFER_MW_DMA_1: timings = 0x00012121; break;
183 case XFER_MW_DMA_2: timings = 0x00002020; break; 180 case XFER_MW_DMA_2: timings = 0x00002020; break;
184 default: 181 default:
185 printk(KERN_ERR "%s: cs5530_config_dma: huh? mode=%02x\n", 182 BUG();
186 drive->name, mode); 183 break;
187 return 1; /* failure */
188 } 184 }
189 basereg = CS5530_BASEREG(hwif); 185 basereg = CS5530_BASEREG(hwif);
190 reg = hwif->INL(basereg+4); /* get drive0 config register */ 186 reg = inl(basereg + 4); /* get drive0 config register */
191 timings |= reg & 0x80000000; /* preserve PIO format bit */ 187 timings |= reg & 0x80000000; /* preserve PIO format bit */
192 if (unit == 0) { /* are we configuring drive0? */ 188 if (unit == 0) { /* are we configuring drive0? */
193 hwif->OUTL(timings, basereg+4); /* write drive0 config register */ 189 outl(timings, basereg + 4); /* write drive0 config register */
194 } else { 190 } else {
195 if (timings & 0x00100000) 191 if (timings & 0x00100000)
196 reg |= 0x00100000; /* enable UDMA timings for both drives */ 192 reg |= 0x00100000; /* enable UDMA timings for both drives */
197 else 193 else
198 reg &= ~0x00100000; /* disable UDMA timings for both drives */ 194 reg &= ~0x00100000; /* disable UDMA timings for both drives */
199 hwif->OUTL(reg, basereg+4); /* write drive0 config register */ 195 outl(reg, basereg + 4); /* write drive0 config register */
200 hwif->OUTL(timings, basereg+12); /* write drive1 config register */ 196 outl(timings, basereg + 12); /* write drive1 config register */
201 } 197 }
202 (void) hwif->ide_dma_host_on(drive);
203 /* set DMA_capable bit */
204 198
205 /* 199 return 0; /* success */
206 * Finally, turn DMA on in software, and exit.
207 */
208 return hwif->ide_dma_on(drive); /* success */
209} 200}
210 201
211/** 202/**
@@ -321,17 +312,17 @@ static void __devinit init_hwif_cs5530 (ide_hwif_t *hwif)
321 312
322 hwif->tuneproc = &cs5530_tuneproc; 313 hwif->tuneproc = &cs5530_tuneproc;
323 basereg = CS5530_BASEREG(hwif); 314 basereg = CS5530_BASEREG(hwif);
324 d0_timings = hwif->INL(basereg+0); 315 d0_timings = inl(basereg + 0);
325 if (CS5530_BAD_PIO(d0_timings)) { 316 if (CS5530_BAD_PIO(d0_timings)) {
326 /* PIO timings not initialized? */ 317 /* PIO timings not initialized? */
327 hwif->OUTL(cs5530_pio_timings[(d0_timings>>31)&1][0], basereg+0); 318 outl(cs5530_pio_timings[(d0_timings >> 31) & 1][0], basereg + 0);
328 if (!hwif->drives[0].autotune) 319 if (!hwif->drives[0].autotune)
329 hwif->drives[0].autotune = 1; 320 hwif->drives[0].autotune = 1;
330 /* needs autotuning later */ 321 /* needs autotuning later */
331 } 322 }
332 if (CS5530_BAD_PIO(hwif->INL(basereg+8))) { 323 if (CS5530_BAD_PIO(inl(basereg + 8))) {
333 /* PIO timings not initialized? */ 324 /* PIO timings not initialized? */
334 hwif->OUTL(cs5530_pio_timings[(d0_timings>>31)&1][0], basereg+8); 325 outl(cs5530_pio_timings[(d0_timings >> 31) & 1][0], basereg + 8);
335 if (!hwif->drives[1].autotune) 326 if (!hwif->drives[1].autotune)
336 hwif->drives[1].autotune = 1; 327 hwif->drives[1].autotune = 1;
337 /* needs autotuning later */ 328 /* needs autotuning later */
diff --git a/drivers/ide/pci/cs5535.c b/drivers/ide/pci/cs5535.c
index 5c5aec28e671..45f43efbf92c 100644
--- a/drivers/ide/pci/cs5535.c
+++ b/drivers/ide/pci/cs5535.c
@@ -195,28 +195,19 @@ static int cs5535_config_drive_for_dma(ide_drive_t *drive)
195 195
196static int cs5535_dma_check(ide_drive_t *drive) 196static int cs5535_dma_check(ide_drive_t *drive)
197{ 197{
198 ide_hwif_t *hwif = drive->hwif;
199 struct hd_driveid *id = drive->id;
200 u8 speed; 198 u8 speed;
201 199
202 drive->init_speed = 0; 200 drive->init_speed = 0;
203 201
204 if ((id->capability & 1) && drive->autodma) { 202 if (ide_use_dma(drive) && cs5535_config_drive_for_dma(drive))
205 if (ide_use_dma(drive)) { 203 return 0;
206 if (cs5535_config_drive_for_dma(drive))
207 return hwif->ide_dma_on(drive);
208 }
209
210 goto fast_ata_pio;
211 204
212 } else if ((id->capability & 8) || (id->field_valid & 2)) { 205 if (ide_use_fast_pio(drive)) {
213fast_ata_pio:
214 speed = ide_get_best_pio_mode(drive, 255, 4, NULL); 206 speed = ide_get_best_pio_mode(drive, 255, 4, NULL);
215 cs5535_set_drive(drive, speed); 207 cs5535_set_drive(drive, speed);
216 return hwif->ide_dma_off_quietly(drive);
217 } 208 }
218 /* IORDY not supported */ 209
219 return 0; 210 return -1;
220} 211}
221 212
222static u8 __devinit cs5535_cable_detect(struct pci_dev *dev) 213static u8 __devinit cs5535_cable_detect(struct pci_dev *dev)
diff --git a/drivers/ide/pci/cy82c693.c b/drivers/ide/pci/cy82c693.c
index 9eafcbf444f4..103b9db97853 100644
--- a/drivers/ide/pci/cy82c693.c
+++ b/drivers/ide/pci/cy82c693.c
@@ -197,8 +197,8 @@ static void cy82c693_dma_enable (ide_drive_t *drive, int mode, int single)
197#if CY82C693_DEBUG_LOGS 197#if CY82C693_DEBUG_LOGS
198 /* for debug let's show the previous values */ 198 /* for debug let's show the previous values */
199 199
200 HWIF(drive)->OUTB(index, CY82_INDEX_PORT); 200 outb(index, CY82_INDEX_PORT);
201 data = HWIF(drive)->INB(CY82_DATA_PORT); 201 data = inb(CY82_DATA_PORT);
202 202
203 printk (KERN_INFO "%s (ch=%d, dev=%d): DMA mode is %d (single=%d)\n", 203 printk (KERN_INFO "%s (ch=%d, dev=%d): DMA mode is %d (single=%d)\n",
204 drive->name, HWIF(drive)->channel, drive->select.b.unit, 204 drive->name, HWIF(drive)->channel, drive->select.b.unit,
@@ -207,8 +207,8 @@ static void cy82c693_dma_enable (ide_drive_t *drive, int mode, int single)
207 207
208 data = (u8)mode|(u8)(single<<2); 208 data = (u8)mode|(u8)(single<<2);
209 209
210 HWIF(drive)->OUTB(index, CY82_INDEX_PORT); 210 outb(index, CY82_INDEX_PORT);
211 HWIF(drive)->OUTB(data, CY82_DATA_PORT); 211 outb(data, CY82_DATA_PORT);
212 212
213#if CY82C693_DEBUG_INFO 213#if CY82C693_DEBUG_INFO
214 printk(KERN_INFO "%s (ch=%d, dev=%d): set DMA mode to %d (single=%d)\n", 214 printk(KERN_INFO "%s (ch=%d, dev=%d): set DMA mode to %d (single=%d)\n",
@@ -227,8 +227,8 @@ static void cy82c693_dma_enable (ide_drive_t *drive, int mode, int single)
227 */ 227 */
228 228
229 data = BUSMASTER_TIMEOUT; 229 data = BUSMASTER_TIMEOUT;
230 HWIF(drive)->OUTB(CY82_INDEX_TIMEOUT, CY82_INDEX_PORT); 230 outb(CY82_INDEX_TIMEOUT, CY82_INDEX_PORT);
231 HWIF(drive)->OUTB(data, CY82_DATA_PORT); 231 outb(data, CY82_DATA_PORT);
232 232
233#if CY82C693_DEBUG_INFO 233#if CY82C693_DEBUG_INFO
234 printk (KERN_INFO "%s: Set IDE Bus Master TimeOut Register to 0x%X\n", 234 printk (KERN_INFO "%s: Set IDE Bus Master TimeOut Register to 0x%X\n",
@@ -478,21 +478,18 @@ static void __devinit init_iops_cy82c693(ide_hwif_t *hwif)
478 } 478 }
479} 479}
480 480
481static ide_pci_device_t cy82c693_chipsets[] __devinitdata = { 481static ide_pci_device_t cy82c693_chipset __devinitdata = {
482 { /* 0 */ 482 .name = "CY82C693",
483 .name = "CY82C693", 483 .init_chipset = init_chipset_cy82c693,
484 .init_chipset = init_chipset_cy82c693, 484 .init_iops = init_iops_cy82c693,
485 .init_iops = init_iops_cy82c693, 485 .init_hwif = init_hwif_cy82c693,
486 .init_hwif = init_hwif_cy82c693, 486 .channels = 1,
487 .channels = 1, 487 .autodma = AUTODMA,
488 .autodma = AUTODMA, 488 .bootable = ON_BOARD,
489 .bootable = ON_BOARD,
490 }
491}; 489};
492 490
493static int __devinit cy82c693_init_one(struct pci_dev *dev, const struct pci_device_id *id) 491static int __devinit cy82c693_init_one(struct pci_dev *dev, const struct pci_device_id *id)
494{ 492{
495 ide_pci_device_t *d = &cy82c693_chipsets[id->driver_data];
496 struct pci_dev *dev2; 493 struct pci_dev *dev2;
497 int ret = -ENODEV; 494 int ret = -ENODEV;
498 495
@@ -501,7 +498,7 @@ static int __devinit cy82c693_init_one(struct pci_dev *dev, const struct pci_dev
501 if ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE && 498 if ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE &&
502 PCI_FUNC(dev->devfn) == 1) { 499 PCI_FUNC(dev->devfn) == 1) {
503 dev2 = pci_get_slot(dev->bus, dev->devfn + 1); 500 dev2 = pci_get_slot(dev->bus, dev->devfn + 1);
504 ret = ide_setup_pci_devices(dev, dev2, d); 501 ret = ide_setup_pci_devices(dev, dev2, &cy82c693_chipset);
505 /* We leak pci refs here but thats ok - we can't be unloaded */ 502 /* We leak pci refs here but thats ok - we can't be unloaded */
506 } 503 }
507 return ret; 504 return ret;
diff --git a/drivers/ide/pci/hpt34x.c b/drivers/ide/pci/hpt34x.c
index ce7b08f08a09..924eaa3a5708 100644
--- a/drivers/ide/pci/hpt34x.c
+++ b/drivers/ide/pci/hpt34x.c
@@ -48,19 +48,6 @@ static u8 hpt34x_ratemask (ide_drive_t *drive)
48 return 1; 48 return 1;
49} 49}
50 50
51static void hpt34x_clear_chipset (ide_drive_t *drive)
52{
53 struct pci_dev *dev = HWIF(drive)->pci_dev;
54 u32 reg1 = 0, tmp1 = 0, reg2 = 0, tmp2 = 0;
55
56 pci_read_config_dword(dev, 0x44, &reg1);
57 pci_read_config_dword(dev, 0x48, &reg2);
58 tmp1 = ((0x00 << (3*drive->dn)) | (reg1 & ~(7 << (3*drive->dn))));
59 tmp2 = (reg2 & ~(0x11 << drive->dn));
60 pci_write_config_dword(dev, 0x44, tmp1);
61 pci_write_config_dword(dev, 0x48, tmp2);
62}
63
64static int hpt34x_tune_chipset (ide_drive_t *drive, u8 xferspeed) 51static int hpt34x_tune_chipset (ide_drive_t *drive, u8 xferspeed)
65{ 52{
66 struct pci_dev *dev = HWIF(drive)->pci_dev; 53 struct pci_dev *dev = HWIF(drive)->pci_dev;
@@ -81,7 +68,7 @@ static int hpt34x_tune_chipset (ide_drive_t *drive, u8 xferspeed)
81 pci_read_config_dword(dev, 0x44, &reg1); 68 pci_read_config_dword(dev, 0x44, &reg1);
82 pci_read_config_dword(dev, 0x48, &reg2); 69 pci_read_config_dword(dev, 0x48, &reg2);
83 tmp1 = ((lo_speed << (3*drive->dn)) | (reg1 & ~(7 << (3*drive->dn)))); 70 tmp1 = ((lo_speed << (3*drive->dn)) | (reg1 & ~(7 << (3*drive->dn))));
84 tmp2 = ((hi_speed << drive->dn) | reg2); 71 tmp2 = ((hi_speed << drive->dn) | (reg2 & ~(0x11 << drive->dn)));
85 pci_write_config_dword(dev, 0x44, tmp1); 72 pci_write_config_dword(dev, 0x44, tmp1);
86 pci_write_config_dword(dev, 0x48, tmp2); 73 pci_write_config_dword(dev, 0x48, tmp2);
87 74
@@ -99,7 +86,6 @@ static int hpt34x_tune_chipset (ide_drive_t *drive, u8 xferspeed)
99static void hpt34x_tune_drive (ide_drive_t *drive, u8 pio) 86static void hpt34x_tune_drive (ide_drive_t *drive, u8 pio)
100{ 87{
101 pio = ide_get_best_pio_mode(drive, pio, 5, NULL); 88 pio = ide_get_best_pio_mode(drive, pio, 5, NULL);
102 hpt34x_clear_chipset(drive);
103 (void) hpt34x_tune_chipset(drive, (XFER_PIO_0 + pio)); 89 (void) hpt34x_tune_chipset(drive, (XFER_PIO_0 + pio));
104} 90}
105 91
@@ -117,38 +103,25 @@ static int config_chipset_for_dma (ide_drive_t *drive)
117 if (!(speed)) 103 if (!(speed))
118 return 0; 104 return 0;
119 105
120 hpt34x_clear_chipset(drive);
121 (void) hpt34x_tune_chipset(drive, speed); 106 (void) hpt34x_tune_chipset(drive, speed);
122 return ide_dma_enable(drive); 107 return ide_dma_enable(drive);
123} 108}
124 109
125static int hpt34x_config_drive_xfer_rate (ide_drive_t *drive) 110static int hpt34x_config_drive_xfer_rate (ide_drive_t *drive)
126{ 111{
127 ide_hwif_t *hwif = HWIF(drive);
128 struct hd_driveid *id = drive->id;
129
130 drive->init_speed = 0; 112 drive->init_speed = 0;
131 113
132 if (id && (id->capability & 1) && drive->autodma) { 114 if (ide_use_dma(drive) && config_chipset_for_dma(drive))
133
134 if (ide_use_dma(drive)) {
135 if (config_chipset_for_dma(drive))
136#ifndef CONFIG_HPT34X_AUTODMA 115#ifndef CONFIG_HPT34X_AUTODMA
137 return hwif->ide_dma_off_quietly(drive); 116 return -1;
138#else 117#else
139 return hwif->ide_dma_on(drive); 118 return 0;
140#endif 119#endif
141 }
142
143 goto fast_ata_pio;
144 120
145 } else if ((id->capability & 8) || (id->field_valid & 2)) { 121 if (ide_use_fast_pio(drive))
146fast_ata_pio:
147 hpt34x_tune_drive(drive, 255); 122 hpt34x_tune_drive(drive, 255);
148 return hwif->ide_dma_off_quietly(drive); 123
149 } 124 return -1;
150 /* IORDY not supported */
151 return 0;
152} 125}
153 126
154/* 127/*
@@ -209,7 +182,6 @@ static void __devinit init_hwif_hpt34x(ide_hwif_t *hwif)
209 182
210 hwif->tuneproc = &hpt34x_tune_drive; 183 hwif->tuneproc = &hpt34x_tune_drive;
211 hwif->speedproc = &hpt34x_tune_chipset; 184 hwif->speedproc = &hpt34x_tune_chipset;
212 hwif->no_dsc = 1;
213 hwif->drives[0].autotune = 1; 185 hwif->drives[0].autotune = 1;
214 hwif->drives[1].autotune = 1; 186 hwif->drives[1].autotune = 1;
215 187
diff --git a/drivers/ide/pci/hpt366.c b/drivers/ide/pci/hpt366.c
index 05be8fadda7a..60ecdc258c7c 100644
--- a/drivers/ide/pci/hpt366.c
+++ b/drivers/ide/pci/hpt366.c
@@ -736,24 +736,15 @@ static void hpt3xx_maskproc(ide_drive_t *drive, int mask)
736 736
737static int hpt366_config_drive_xfer_rate(ide_drive_t *drive) 737static int hpt366_config_drive_xfer_rate(ide_drive_t *drive)
738{ 738{
739 ide_hwif_t *hwif = HWIF(drive);
740 struct hd_driveid *id = drive->id;
741
742 drive->init_speed = 0; 739 drive->init_speed = 0;
743 740
744 if ((id->capability & 1) && drive->autodma) { 741 if (ide_use_dma(drive) && config_chipset_for_dma(drive))
745 if (ide_use_dma(drive) && config_chipset_for_dma(drive)) 742 return 0;
746 return hwif->ide_dma_on(drive);
747
748 goto fast_ata_pio;
749 743
750 } else if ((id->capability & 8) || (id->field_valid & 2)) { 744 if (ide_use_fast_pio(drive))
751fast_ata_pio:
752 hpt3xx_tune_drive(drive, 255); 745 hpt3xx_tune_drive(drive, 255);
753 return hwif->ide_dma_off_quietly(drive); 746
754 } 747 return -1;
755 /* IORDY not supported */
756 return 0;
757} 748}
758 749
759/* 750/*
@@ -841,7 +832,7 @@ static int hpt374_ide_dma_test_irq(ide_drive_t *drive)
841 return 0; 832 return 0;
842 } 833 }
843 834
844 dma_stat = hwif->INB(hwif->dma_status); 835 dma_stat = inb(hwif->dma_status);
845 /* return 1 if INTR asserted */ 836 /* return 1 if INTR asserted */
846 if (dma_stat & 4) 837 if (dma_stat & 4)
847 return 1; 838 return 1;
@@ -1391,9 +1382,6 @@ static void __devinit init_dma_hpt366(ide_hwif_t *hwif, unsigned long dmabase)
1391 u8 dma_new = 0, dma_old = 0; 1382 u8 dma_new = 0, dma_old = 0;
1392 unsigned long flags; 1383 unsigned long flags;
1393 1384
1394 if (!dmabase)
1395 return;
1396
1397 dma_old = hwif->INB(dmabase + 2); 1385 dma_old = hwif->INB(dmabase + 2);
1398 1386
1399 local_irq_save(flags); 1387 local_irq_save(flags);
diff --git a/drivers/ide/pci/it8213.c b/drivers/ide/pci/it8213.c
index 63248b6909fa..424f00bb160d 100644
--- a/drivers/ide/pci/it8213.c
+++ b/drivers/ide/pci/it8213.c
@@ -244,17 +244,15 @@ static int config_chipset_for_dma (ide_drive_t *drive)
244 244
245static int it8213_config_drive_for_dma (ide_drive_t *drive) 245static int it8213_config_drive_for_dma (ide_drive_t *drive)
246{ 246{
247 ide_hwif_t *hwif = drive->hwif; 247 u8 pio;
248 248
249 if (ide_use_dma(drive)) { 249 if (ide_use_dma(drive) && config_chipset_for_dma(drive))
250 if (config_chipset_for_dma(drive)) 250 return 0;
251 return hwif->ide_dma_on(drive);
252 }
253 251
254 hwif->speedproc(drive, XFER_PIO_0 252 pio = ide_get_best_pio_mode(drive, 255, 4, NULL);
255 + ide_get_best_pio_mode(drive, 255, 4, NULL)); 253 it8213_tune_chipset(drive, XFER_PIO_0 + pio);
256 254
257 return hwif->ide_dma_off_quietly(drive); 255 return -1;
258} 256}
259 257
260/** 258/**
diff --git a/drivers/ide/pci/it821x.c b/drivers/ide/pci/it821x.c
index e9bad185968a..a132767f7d90 100644
--- a/drivers/ide/pci/it821x.c
+++ b/drivers/ide/pci/it821x.c
@@ -520,14 +520,12 @@ static int config_chipset_for_dma (ide_drive_t *drive)
520 520
521static int it821x_config_drive_for_dma (ide_drive_t *drive) 521static int it821x_config_drive_for_dma (ide_drive_t *drive)
522{ 522{
523 ide_hwif_t *hwif = drive->hwif; 523 if (ide_use_dma(drive) && config_chipset_for_dma(drive))
524 return 0;
524 525
525 if (ide_use_dma(drive)) {
526 if (config_chipset_for_dma(drive))
527 return hwif->ide_dma_on(drive);
528 }
529 config_it821x_chipset_for_pio(drive, 1); 526 config_it821x_chipset_for_pio(drive, 1);
530 return hwif->ide_dma_off_quietly(drive); 527
528 return -1;
531} 529}
532 530
533/** 531/**
@@ -608,11 +606,11 @@ static void __devinit it821x_fixups(ide_hwif_t *hwif)
608 printk(".\n"); 606 printk(".\n");
609 /* Now the core code will have wrongly decided no DMA 607 /* Now the core code will have wrongly decided no DMA
610 so we need to fix this */ 608 so we need to fix this */
611 hwif->ide_dma_off_quietly(drive); 609 hwif->dma_off_quietly(drive);
612#ifdef CONFIG_IDEDMA_ONLYDISK 610#ifdef CONFIG_IDEDMA_ONLYDISK
613 if (drive->media == ide_disk) 611 if (drive->media == ide_disk)
614#endif 612#endif
615 hwif->ide_dma_check(drive); 613 ide_set_dma(drive);
616 } else { 614 } else {
617 /* Non RAID volume. Fixups to stop the core code 615 /* Non RAID volume. Fixups to stop the core code
618 doing unsupported things */ 616 doing unsupported things */
diff --git a/drivers/ide/pci/jmicron.c b/drivers/ide/pci/jmicron.c
index f07bbbed1778..53f25500c22b 100644
--- a/drivers/ide/pci/jmicron.c
+++ b/drivers/ide/pci/jmicron.c
@@ -147,7 +147,9 @@ static int config_chipset_for_dma (ide_drive_t *drive)
147{ 147{
148 u8 speed = ide_dma_speed(drive, jmicron_ratemask(drive)); 148 u8 speed = ide_dma_speed(drive, jmicron_ratemask(drive));
149 149
150 config_jmicron_chipset_for_pio(drive, !speed); 150 if (!speed)
151 return 0;
152
151 jmicron_tune_chipset(drive, speed); 153 jmicron_tune_chipset(drive, speed);
152 return ide_dma_enable(drive); 154 return ide_dma_enable(drive);
153} 155}
@@ -162,14 +164,12 @@ static int config_chipset_for_dma (ide_drive_t *drive)
162 164
163static int jmicron_config_drive_for_dma (ide_drive_t *drive) 165static int jmicron_config_drive_for_dma (ide_drive_t *drive)
164{ 166{
165 ide_hwif_t *hwif = drive->hwif; 167 if (ide_use_dma(drive) && config_chipset_for_dma(drive))
168 return 0;
166 169
167 if (ide_use_dma(drive)) {
168 if (config_chipset_for_dma(drive))
169 return hwif->ide_dma_on(drive);
170 }
171 config_jmicron_chipset_for_pio(drive, 1); 170 config_jmicron_chipset_for_pio(drive, 1);
172 return hwif->ide_dma_off_quietly(drive); 171
172 return -1;
173} 173}
174 174
175/** 175/**
diff --git a/drivers/ide/pci/ns87415.c b/drivers/ide/pci/ns87415.c
index 8aaea4ea5549..b310c4f51077 100644
--- a/drivers/ide/pci/ns87415.c
+++ b/drivers/ide/pci/ns87415.c
@@ -166,10 +166,10 @@ static int ns87415_ide_dma_end (ide_drive_t *drive)
166 /* get dma command mode */ 166 /* get dma command mode */
167 dma_cmd = hwif->INB(hwif->dma_command); 167 dma_cmd = hwif->INB(hwif->dma_command);
168 /* stop DMA */ 168 /* stop DMA */
169 hwif->OUTB(dma_cmd & ~1, hwif->dma_command); 169 outb(dma_cmd & ~1, hwif->dma_command);
170 /* from ERRATA: clear the INTR & ERROR bits */ 170 /* from ERRATA: clear the INTR & ERROR bits */
171 dma_cmd = hwif->INB(hwif->dma_command); 171 dma_cmd = hwif->INB(hwif->dma_command);
172 hwif->OUTB(dma_cmd|6, hwif->dma_command); 172 outb(dma_cmd | 6, hwif->dma_command);
173 /* and free any DMA resources */ 173 /* and free any DMA resources */
174 ide_destroy_dmatable(drive); 174 ide_destroy_dmatable(drive);
175 /* verify good DMA status */ 175 /* verify good DMA status */
@@ -190,7 +190,8 @@ static int ns87415_ide_dma_setup(ide_drive_t *drive)
190static int ns87415_ide_dma_check (ide_drive_t *drive) 190static int ns87415_ide_dma_check (ide_drive_t *drive)
191{ 191{
192 if (drive->media != ide_disk) 192 if (drive->media != ide_disk)
193 return HWIF(drive)->ide_dma_off_quietly(drive); 193 return -1;
194
194 return __ide_dma_check(drive); 195 return __ide_dma_check(drive);
195} 196}
196 197
@@ -243,9 +244,9 @@ static void __devinit init_hwif_ns87415 (ide_hwif_t *hwif)
243 * to SELECT_DRIVE() properly during first probe_hwif(). 244 * to SELECT_DRIVE() properly during first probe_hwif().
244 */ 245 */
245 timeout = 10000; 246 timeout = 10000;
246 hwif->OUTB(12, hwif->io_ports[IDE_CONTROL_OFFSET]); 247 outb(12, hwif->io_ports[IDE_CONTROL_OFFSET]);
247 udelay(10); 248 udelay(10);
248 hwif->OUTB(8, hwif->io_ports[IDE_CONTROL_OFFSET]); 249 outb(8, hwif->io_ports[IDE_CONTROL_OFFSET]);
249 do { 250 do {
250 udelay(50); 251 udelay(50);
251 stat = hwif->INB(hwif->io_ports[IDE_STATUS_OFFSET]); 252 stat = hwif->INB(hwif->io_ports[IDE_STATUS_OFFSET]);
@@ -263,7 +264,7 @@ static void __devinit init_hwif_ns87415 (ide_hwif_t *hwif)
263 if (!hwif->dma_base) 264 if (!hwif->dma_base)
264 return; 265 return;
265 266
266 hwif->OUTB(0x60, hwif->dma_status); 267 outb(0x60, hwif->dma_status);
267 hwif->dma_setup = &ns87415_ide_dma_setup; 268 hwif->dma_setup = &ns87415_ide_dma_setup;
268 hwif->ide_dma_check = &ns87415_ide_dma_check; 269 hwif->ide_dma_check = &ns87415_ide_dma_check;
269 hwif->ide_dma_end = &ns87415_ide_dma_end; 270 hwif->ide_dma_end = &ns87415_ide_dma_end;
diff --git a/drivers/ide/pci/opti621.c b/drivers/ide/pci/opti621.c
index 22bbf613f948..9ca60dd2185e 100644
--- a/drivers/ide/pci/opti621.c
+++ b/drivers/ide/pci/opti621.c
@@ -176,34 +176,35 @@ static int cmpt_clk(int time, int bus_speed)
176 return ((time*bus_speed+999)/1000); 176 return ((time*bus_speed+999)/1000);
177} 177}
178 178
179static void write_reg(ide_hwif_t *hwif, u8 value, int reg)
180/* Write value to register reg, base of register 179/* Write value to register reg, base of register
181 * is at reg_base (0x1f0 primary, 0x170 secondary, 180 * is at reg_base (0x1f0 primary, 0x170 secondary,
182 * if not changed by PCI configuration). 181 * if not changed by PCI configuration).
183 * This is from setupvic.exe program. 182 * This is from setupvic.exe program.
184 */ 183 */
184static void write_reg(u8 value, int reg)
185{ 185{
186 hwif->INW(reg_base+1); 186 inw(reg_base + 1);
187 hwif->INW(reg_base+1); 187 inw(reg_base + 1);
188 hwif->OUTB(3, reg_base+2); 188 outb(3, reg_base + 2);
189 hwif->OUTB(value, reg_base+reg); 189 outb(value, reg_base + reg);
190 hwif->OUTB(0x83, reg_base+2); 190 outb(0x83, reg_base + 2);
191} 191}
192 192
193static u8 read_reg(ide_hwif_t *hwif, int reg)
194/* Read value from register reg, base of register 193/* Read value from register reg, base of register
195 * is at reg_base (0x1f0 primary, 0x170 secondary, 194 * is at reg_base (0x1f0 primary, 0x170 secondary,
196 * if not changed by PCI configuration). 195 * if not changed by PCI configuration).
197 * This is from setupvic.exe program. 196 * This is from setupvic.exe program.
198 */ 197 */
198static u8 read_reg(int reg)
199{ 199{
200 u8 ret = 0; 200 u8 ret = 0;
201 201
202 hwif->INW(reg_base+1); 202 inw(reg_base + 1);
203 hwif->INW(reg_base+1); 203 inw(reg_base + 1);
204 hwif->OUTB(3, reg_base+2); 204 outb(3, reg_base + 2);
205 ret = hwif->INB(reg_base+reg); 205 ret = inb(reg_base + reg);
206 hwif->OUTB(0x83, reg_base+2); 206 outb(0x83, reg_base + 2);
207
207 return ret; 208 return ret;
208} 209}
209 210
@@ -286,39 +287,39 @@ static void opti621_tune_drive (ide_drive_t *drive, u8 pio)
286 reg_base = hwif->io_ports[IDE_DATA_OFFSET]; 287 reg_base = hwif->io_ports[IDE_DATA_OFFSET];
287 288
288 /* allow Register-B */ 289 /* allow Register-B */
289 hwif->OUTB(0xc0, reg_base+CNTRL_REG); 290 outb(0xc0, reg_base + CNTRL_REG);
290 /* hmm, setupvic.exe does this ;-) */ 291 /* hmm, setupvic.exe does this ;-) */
291 hwif->OUTB(0xff, reg_base+5); 292 outb(0xff, reg_base + 5);
292 /* if reads 0xff, adapter not exist? */ 293 /* if reads 0xff, adapter not exist? */
293 (void) hwif->INB(reg_base+CNTRL_REG); 294 (void)inb(reg_base + CNTRL_REG);
294 /* if reads 0xc0, no interface exist? */ 295 /* if reads 0xc0, no interface exist? */
295 read_reg(hwif, CNTRL_REG); 296 read_reg(CNTRL_REG);
296 /* read version, probably 0 */ 297 /* read version, probably 0 */
297 read_reg(hwif, STRAP_REG); 298 read_reg(STRAP_REG);
298 299
299 /* program primary drive */ 300 /* program primary drive */
300 /* select Index-0 for Register-A */ 301 /* select Index-0 for Register-A */
301 write_reg(hwif, 0, MISC_REG); 302 write_reg(0, MISC_REG);
302 /* set read cycle timings */ 303 /* set read cycle timings */
303 write_reg(hwif, cycle1, READ_REG); 304 write_reg(cycle1, READ_REG);
304 /* set write cycle timings */ 305 /* set write cycle timings */
305 write_reg(hwif, cycle1, WRITE_REG); 306 write_reg(cycle1, WRITE_REG);
306 307
307 /* program secondary drive */ 308 /* program secondary drive */
308 /* select Index-1 for Register-B */ 309 /* select Index-1 for Register-B */
309 write_reg(hwif, 1, MISC_REG); 310 write_reg(1, MISC_REG);
310 /* set read cycle timings */ 311 /* set read cycle timings */
311 write_reg(hwif, cycle2, READ_REG); 312 write_reg(cycle2, READ_REG);
312 /* set write cycle timings */ 313 /* set write cycle timings */
313 write_reg(hwif, cycle2, WRITE_REG); 314 write_reg(cycle2, WRITE_REG);
314 315
315 /* use Register-A for drive 0 */ 316 /* use Register-A for drive 0 */
316 /* use Register-B for drive 1 */ 317 /* use Register-B for drive 1 */
317 write_reg(hwif, 0x85, CNTRL_REG); 318 write_reg(0x85, CNTRL_REG);
318 319
319 /* set address setup, DRDY timings, */ 320 /* set address setup, DRDY timings, */
320 /* and read prefetch for both drives */ 321 /* and read prefetch for both drives */
321 write_reg(hwif, misc, MISC_REG); 322 write_reg(misc, MISC_REG);
322 323
323 spin_unlock_irqrestore(&ide_lock, flags); 324 spin_unlock_irqrestore(&ide_lock, flags);
324} 325}
diff --git a/drivers/ide/pci/pdc202xx_new.c b/drivers/ide/pci/pdc202xx_new.c
index 236a03144a27..6ceb25bc5a7b 100644
--- a/drivers/ide/pci/pdc202xx_new.c
+++ b/drivers/ide/pci/pdc202xx_new.c
@@ -101,8 +101,8 @@ static u8 get_indexed_reg(ide_hwif_t *hwif, u8 index)
101{ 101{
102 u8 value; 102 u8 value;
103 103
104 hwif->OUTB(index, hwif->dma_vendor1); 104 outb(index, hwif->dma_vendor1);
105 value = hwif->INB(hwif->dma_vendor3); 105 value = inb(hwif->dma_vendor3);
106 106
107 DBG("index[%02X] value[%02X]\n", index, value); 107 DBG("index[%02X] value[%02X]\n", index, value);
108 return value; 108 return value;
@@ -115,8 +115,8 @@ static u8 get_indexed_reg(ide_hwif_t *hwif, u8 index)
115 */ 115 */
116static void set_indexed_reg(ide_hwif_t *hwif, u8 index, u8 value) 116static void set_indexed_reg(ide_hwif_t *hwif, u8 index, u8 value)
117{ 117{
118 hwif->OUTB(index, hwif->dma_vendor1); 118 outb(index, hwif->dma_vendor1);
119 hwif->OUTB(value, hwif->dma_vendor3); 119 outb(value, hwif->dma_vendor3);
120 DBG("index[%02X] value[%02X]\n", index, value); 120 DBG("index[%02X] value[%02X]\n", index, value);
121} 121}
122 122
@@ -281,25 +281,15 @@ static int config_chipset_for_dma(ide_drive_t *drive)
281 281
282static int pdcnew_config_drive_xfer_rate(ide_drive_t *drive) 282static int pdcnew_config_drive_xfer_rate(ide_drive_t *drive)
283{ 283{
284 ide_hwif_t *hwif = HWIF(drive);
285 struct hd_driveid *id = drive->id;
286
287 drive->init_speed = 0; 284 drive->init_speed = 0;
288 285
289 if ((id->capability & 1) && drive->autodma) { 286 if (ide_use_dma(drive) && config_chipset_for_dma(drive))
290 287 return 0;
291 if (ide_use_dma(drive) && config_chipset_for_dma(drive))
292 return hwif->ide_dma_on(drive);
293 288
294 goto fast_ata_pio; 289 if (ide_use_fast_pio(drive))
290 pdcnew_tune_drive(drive, 255);
295 291
296 } else if ((id->capability & 8) || (id->field_valid & 2)) { 292 return -1;
297fast_ata_pio:
298 hwif->tuneproc(drive, 255);
299 return hwif->ide_dma_off_quietly(drive);
300 }
301 /* IORDY not supported */
302 return 0;
303} 293}
304 294
305static int pdcnew_quirkproc(ide_drive_t *drive) 295static int pdcnew_quirkproc(ide_drive_t *drive)
diff --git a/drivers/ide/pci/pdc202xx_old.c b/drivers/ide/pci/pdc202xx_old.c
index 730e8d1ec2f5..a7a639fe1eaf 100644
--- a/drivers/ide/pci/pdc202xx_old.c
+++ b/drivers/ide/pci/pdc202xx_old.c
@@ -2,6 +2,7 @@
2 * linux/drivers/ide/pci/pdc202xx_old.c Version 0.36 Sept 11, 2002 2 * linux/drivers/ide/pci/pdc202xx_old.c Version 0.36 Sept 11, 2002
3 * 3 *
4 * Copyright (C) 1998-2002 Andre Hedrick <andre@linux-ide.org> 4 * Copyright (C) 1998-2002 Andre Hedrick <andre@linux-ide.org>
5 * Copyright (C) 2006-2007 MontaVista Software, Inc.
5 * 6 *
6 * Promise Ultra33 cards with BIOS v1.20 through 1.28 will need this 7 * Promise Ultra33 cards with BIOS v1.20 through 1.28 will need this
7 * compiled into the kernel if you have more than one card installed. 8 * compiled into the kernel if you have more than one card installed.
@@ -216,21 +217,10 @@ static int pdc202xx_tune_chipset (ide_drive_t *drive, u8 xferspeed)
216} 217}
217 218
218 219
219/* 0 1 2 3 4 5 6 7 8 220static void pdc202xx_tune_drive(ide_drive_t *drive, u8 pio)
220 * 960, 480, 390, 300, 240, 180, 120, 90, 60
221 * 180, 150, 120, 90, 60
222 * DMA_Speed
223 * 180, 120, 90, 90, 90, 60, 30
224 * 11, 5, 4, 3, 2, 1, 0
225 */
226static void config_chipset_for_pio (ide_drive_t *drive, u8 pio)
227{ 221{
228 u8 speed = 0; 222 pio = ide_get_best_pio_mode(drive, pio, 4, NULL);
229 223 pdc202xx_tune_chipset(drive, XFER_PIO_0 + pio);
230 if (pio == 5) pio = 4;
231 speed = XFER_PIO_0 + ide_get_best_pio_mode(drive, 255, pio, NULL);
232
233 pdc202xx_tune_chipset(drive, speed);
234} 224}
235 225
236static u8 pdc202xx_old_cable_detect (ide_hwif_t *hwif) 226static u8 pdc202xx_old_cable_detect (ide_hwif_t *hwif)
@@ -250,17 +240,17 @@ static u8 pdc202xx_old_cable_detect (ide_hwif_t *hwif)
250static void pdc_old_enable_66MHz_clock(ide_hwif_t *hwif) 240static void pdc_old_enable_66MHz_clock(ide_hwif_t *hwif)
251{ 241{
252 unsigned long clock_reg = hwif->dma_master + 0x11; 242 unsigned long clock_reg = hwif->dma_master + 0x11;
253 u8 clock = hwif->INB(clock_reg); 243 u8 clock = inb(clock_reg);
254 244
255 hwif->OUTB(clock | (hwif->channel ? 0x08 : 0x02), clock_reg); 245 outb(clock | (hwif->channel ? 0x08 : 0x02), clock_reg);
256} 246}
257 247
258static void pdc_old_disable_66MHz_clock(ide_hwif_t *hwif) 248static void pdc_old_disable_66MHz_clock(ide_hwif_t *hwif)
259{ 249{
260 unsigned long clock_reg = hwif->dma_master + 0x11; 250 unsigned long clock_reg = hwif->dma_master + 0x11;
261 u8 clock = hwif->INB(clock_reg); 251 u8 clock = inb(clock_reg);
262 252
263 hwif->OUTB(clock & ~(hwif->channel ? 0x08 : 0x02), clock_reg); 253 outb(clock & ~(hwif->channel ? 0x08 : 0x02), clock_reg);
264} 254}
265 255
266static int config_chipset_for_dma (ide_drive_t *drive) 256static int config_chipset_for_dma (ide_drive_t *drive)
@@ -332,27 +322,15 @@ chipset_is_set:
332 322
333static int pdc202xx_config_drive_xfer_rate (ide_drive_t *drive) 323static int pdc202xx_config_drive_xfer_rate (ide_drive_t *drive)
334{ 324{
335 ide_hwif_t *hwif = HWIF(drive);
336 struct hd_driveid *id = drive->id;
337
338 drive->init_speed = 0; 325 drive->init_speed = 0;
339 326
340 if (id && (id->capability & 1) && drive->autodma) { 327 if (ide_use_dma(drive) && config_chipset_for_dma(drive))
341 328 return 0;
342 if (ide_use_dma(drive)) {
343 if (config_chipset_for_dma(drive))
344 return hwif->ide_dma_on(drive);
345 }
346 329
347 goto fast_ata_pio; 330 if (ide_use_fast_pio(drive))
331 pdc202xx_tune_drive(drive, 255);
348 332
349 } else if ((id->capability & 8) || (id->field_valid & 2)) { 333 return -1;
350fast_ata_pio:
351 hwif->tuneproc(drive, 5);
352 return hwif->ide_dma_off_quietly(drive);
353 }
354 /* IORDY not supported */
355 return 0;
356} 334}
357 335
358static int pdc202xx_quirkproc (ide_drive_t *drive) 336static int pdc202xx_quirkproc (ide_drive_t *drive)
@@ -375,14 +353,14 @@ static void pdc202xx_old_ide_dma_start(ide_drive_t *drive)
375 unsigned long high_16 = hwif->dma_master; 353 unsigned long high_16 = hwif->dma_master;
376 unsigned long atapi_reg = high_16 + (hwif->channel ? 0x24 : 0x20); 354 unsigned long atapi_reg = high_16 + (hwif->channel ? 0x24 : 0x20);
377 u32 word_count = 0; 355 u32 word_count = 0;
378 u8 clock = hwif->INB(high_16 + 0x11); 356 u8 clock = inb(high_16 + 0x11);
379 357
380 hwif->OUTB(clock|(hwif->channel ? 0x08 : 0x02), high_16+0x11); 358 outb(clock | (hwif->channel ? 0x08 : 0x02), high_16 + 0x11);
381 word_count = (rq->nr_sectors << 8); 359 word_count = (rq->nr_sectors << 8);
382 word_count = (rq_data_dir(rq) == READ) ? 360 word_count = (rq_data_dir(rq) == READ) ?
383 word_count | 0x05000000 : 361 word_count | 0x05000000 :
384 word_count | 0x06000000; 362 word_count | 0x06000000;
385 hwif->OUTL(word_count, atapi_reg); 363 outl(word_count, atapi_reg);
386 } 364 }
387 ide_dma_start(drive); 365 ide_dma_start(drive);
388} 366}
@@ -395,9 +373,9 @@ static int pdc202xx_old_ide_dma_end(ide_drive_t *drive)
395 unsigned long atapi_reg = high_16 + (hwif->channel ? 0x24 : 0x20); 373 unsigned long atapi_reg = high_16 + (hwif->channel ? 0x24 : 0x20);
396 u8 clock = 0; 374 u8 clock = 0;
397 375
398 hwif->OUTL(0, atapi_reg); /* zero out extra */ 376 outl(0, atapi_reg); /* zero out extra */
399 clock = hwif->INB(high_16 + 0x11); 377 clock = inb(high_16 + 0x11);
400 hwif->OUTB(clock & ~(hwif->channel ? 0x08:0x02), high_16+0x11); 378 outb(clock & ~(hwif->channel ? 0x08:0x02), high_16 + 0x11);
401 } 379 }
402 if (drive->current_speed > XFER_UDMA_2) 380 if (drive->current_speed > XFER_UDMA_2)
403 pdc_old_disable_66MHz_clock(drive->hwif); 381 pdc_old_disable_66MHz_clock(drive->hwif);
@@ -408,8 +386,8 @@ static int pdc202xx_old_ide_dma_test_irq(ide_drive_t *drive)
408{ 386{
409 ide_hwif_t *hwif = HWIF(drive); 387 ide_hwif_t *hwif = HWIF(drive);
410 unsigned long high_16 = hwif->dma_master; 388 unsigned long high_16 = hwif->dma_master;
411 u8 dma_stat = hwif->INB(hwif->dma_status); 389 u8 dma_stat = inb(hwif->dma_status);
412 u8 sc1d = hwif->INB((high_16 + 0x001d)); 390 u8 sc1d = inb(high_16 + 0x001d);
413 391
414 if (hwif->channel) { 392 if (hwif->channel) {
415 /* bit7: Error, bit6: Interrupting, bit5: FIFO Full, bit4: FIFO Empty */ 393 /* bit7: Error, bit6: Interrupting, bit5: FIFO Full, bit4: FIFO Empty */
@@ -445,11 +423,11 @@ static int pdc202xx_ide_dma_timeout(ide_drive_t *drive)
445static void pdc202xx_reset_host (ide_hwif_t *hwif) 423static void pdc202xx_reset_host (ide_hwif_t *hwif)
446{ 424{
447 unsigned long high_16 = hwif->dma_master; 425 unsigned long high_16 = hwif->dma_master;
448 u8 udma_speed_flag = hwif->INB(high_16|0x001f); 426 u8 udma_speed_flag = inb(high_16 | 0x001f);
449 427
450 hwif->OUTB((udma_speed_flag | 0x10), (high_16|0x001f)); 428 outb(udma_speed_flag | 0x10, high_16 | 0x001f);
451 mdelay(100); 429 mdelay(100);
452 hwif->OUTB((udma_speed_flag & ~0x10), (high_16|0x001f)); 430 outb(udma_speed_flag & ~0x10, high_16 | 0x001f);
453 mdelay(2000); /* 2 seconds ?! */ 431 mdelay(2000); /* 2 seconds ?! */
454 432
455 printk(KERN_WARNING "PDC202XX: %s channel reset.\n", 433 printk(KERN_WARNING "PDC202XX: %s channel reset.\n",
@@ -463,7 +441,7 @@ static void pdc202xx_reset (ide_drive_t *drive)
463 441
464 pdc202xx_reset_host(hwif); 442 pdc202xx_reset_host(hwif);
465 pdc202xx_reset_host(mate); 443 pdc202xx_reset_host(mate);
466 hwif->tuneproc(drive, 5); 444 pdc202xx_tune_drive(drive, 255);
467} 445}
468 446
469static unsigned int __devinit init_chipset_pdc202xx(struct pci_dev *dev, 447static unsigned int __devinit init_chipset_pdc202xx(struct pci_dev *dev,
@@ -490,7 +468,7 @@ static void __devinit init_hwif_pdc202xx(ide_hwif_t *hwif)
490 hwif->rqsize = 256; 468 hwif->rqsize = 256;
491 469
492 hwif->autodma = 0; 470 hwif->autodma = 0;
493 hwif->tuneproc = &config_chipset_for_pio; 471 hwif->tuneproc = &pdc202xx_tune_drive;
494 hwif->quirkproc = &pdc202xx_quirkproc; 472 hwif->quirkproc = &pdc202xx_quirkproc;
495 473
496 if (hwif->pci_dev->device != PCI_DEVICE_ID_PROMISE_20246) 474 if (hwif->pci_dev->device != PCI_DEVICE_ID_PROMISE_20246)
@@ -537,9 +515,9 @@ static void __devinit init_dma_pdc202xx(ide_hwif_t *hwif, unsigned long dmabase)
537 return; 515 return;
538 } 516 }
539 517
540 udma_speed_flag = hwif->INB((dmabase|0x1f)); 518 udma_speed_flag = inb(dmabase | 0x1f);
541 primary_mode = hwif->INB((dmabase|0x1a)); 519 primary_mode = inb(dmabase | 0x1a);
542 secondary_mode = hwif->INB((dmabase|0x1b)); 520 secondary_mode = inb(dmabase | 0x1b);
543 printk(KERN_INFO "%s: (U)DMA Burst Bit %sABLED " \ 521 printk(KERN_INFO "%s: (U)DMA Burst Bit %sABLED " \
544 "Primary %s Mode " \ 522 "Primary %s Mode " \
545 "Secondary %s Mode.\n", hwif->cds->name, 523 "Secondary %s Mode.\n", hwif->cds->name,
@@ -552,30 +530,10 @@ static void __devinit init_dma_pdc202xx(ide_hwif_t *hwif, unsigned long dmabase)
552 printk(KERN_INFO "%s: FORCING BURST BIT 0x%02x->0x%02x ", 530 printk(KERN_INFO "%s: FORCING BURST BIT 0x%02x->0x%02x ",
553 hwif->cds->name, udma_speed_flag, 531 hwif->cds->name, udma_speed_flag,
554 (udma_speed_flag|1)); 532 (udma_speed_flag|1));
555 hwif->OUTB(udma_speed_flag|1,(dmabase|0x1f)); 533 outb(udma_speed_flag | 1, dmabase | 0x1f);
556 printk("%sACTIVE\n", 534 printk("%sACTIVE\n", (inb(dmabase | 0x1f) & 1) ? "" : "IN");
557 (hwif->INB(dmabase|0x1f)&1) ? "":"IN");
558 } 535 }
559#endif /* CONFIG_PDC202XX_BURST */ 536#endif /* CONFIG_PDC202XX_BURST */
560#ifdef CONFIG_PDC202XX_MASTER
561 if (!(primary_mode & 1)) {
562 printk(KERN_INFO "%s: FORCING PRIMARY MODE BIT "
563 "0x%02x -> 0x%02x ", hwif->cds->name,
564 primary_mode, (primary_mode|1));
565 hwif->OUTB(primary_mode|1, (dmabase|0x1a));
566 printk("%s\n",
567 (hwif->INB((dmabase|0x1a)) & 1) ? "MASTER" : "PCI");
568 }
569
570 if (!(secondary_mode & 1)) {
571 printk(KERN_INFO "%s: FORCING SECONDARY MODE BIT "
572 "0x%02x -> 0x%02x ", hwif->cds->name,
573 secondary_mode, (secondary_mode|1));
574 hwif->OUTB(secondary_mode|1, (dmabase|0x1b));
575 printk("%s\n",
576 (hwif->INB((dmabase|0x1b)) & 1) ? "MASTER" : "PCI");
577 }
578#endif /* CONFIG_PDC202XX_MASTER */
579 537
580 ide_setup_dma(hwif, dmabase, 8); 538 ide_setup_dma(hwif, dmabase, 8);
581} 539}
diff --git a/drivers/ide/pci/piix.c b/drivers/ide/pci/piix.c
index 52cfc2ac22c1..569822f4cf55 100644
--- a/drivers/ide/pci/piix.c
+++ b/drivers/ide/pci/piix.c
@@ -369,7 +369,7 @@ static int piix_config_drive_for_dma (ide_drive_t *drive)
369 * If no DMA speed was available or the chipset has DMA bugs 369 * If no DMA speed was available or the chipset has DMA bugs
370 * then disable DMA and use PIO 370 * then disable DMA and use PIO
371 */ 371 */
372 if (!speed || no_piix_dma) 372 if (!speed)
373 return 0; 373 return 0;
374 374
375 (void) piix_tune_chipset(drive, speed); 375 (void) piix_tune_chipset(drive, speed);
@@ -386,41 +386,28 @@ static int piix_config_drive_for_dma (ide_drive_t *drive)
386 386
387static int piix_config_drive_xfer_rate (ide_drive_t *drive) 387static int piix_config_drive_xfer_rate (ide_drive_t *drive)
388{ 388{
389 ide_hwif_t *hwif = HWIF(drive);
390 struct hd_driveid *id = drive->id;
391
392 drive->init_speed = 0; 389 drive->init_speed = 0;
393 390
394 if ((id->capability & 1) && drive->autodma) { 391 if (ide_use_dma(drive) && piix_config_drive_for_dma(drive))
395 392 return 0;
396 if (ide_use_dma(drive) && piix_config_drive_for_dma(drive))
397 return hwif->ide_dma_on(drive);
398
399 goto fast_ata_pio;
400 393
401 } else if ((id->capability & 8) || (id->field_valid & 2)) { 394 if (ide_use_fast_pio(drive))
402fast_ata_pio:
403 /* Find best PIO mode. */ 395 /* Find best PIO mode. */
404 (void) hwif->speedproc(drive, XFER_PIO_0 + 396 piix_tune_chipset(drive, XFER_PIO_0 +
405 ide_get_best_pio_mode(drive, 255, 4, NULL)); 397 ide_get_best_pio_mode(drive, 255, 4, NULL));
406 return hwif->ide_dma_off_quietly(drive); 398
407 } 399 return -1;
408 /* IORDY not supported */
409 return 0;
410} 400}
411 401
412/** 402/**
413 * init_chipset_piix - set up the PIIX chipset 403 * piix_is_ichx - check if ICHx
414 * @dev: PCI device to set up 404 * @dev: PCI device to check
415 * @name: Name of the device
416 * 405 *
417 * Initialize the PCI device as required. For the PIIX this turns 406 * returns 1 if ICHx, 0 otherwise.
418 * out to be nice and simple
419 */ 407 */
420 408static int piix_is_ichx(struct pci_dev *dev)
421static unsigned int __devinit init_chipset_piix (struct pci_dev *dev, const char *name)
422{ 409{
423 switch(dev->device) { 410 switch (dev->device) {
424 case PCI_DEVICE_ID_INTEL_82801EB_1: 411 case PCI_DEVICE_ID_INTEL_82801EB_1:
425 case PCI_DEVICE_ID_INTEL_82801AA_1: 412 case PCI_DEVICE_ID_INTEL_82801AA_1:
426 case PCI_DEVICE_ID_INTEL_82801AB_1: 413 case PCI_DEVICE_ID_INTEL_82801AB_1:
@@ -438,19 +425,61 @@ static unsigned int __devinit init_chipset_piix (struct pci_dev *dev, const char
438 case PCI_DEVICE_ID_INTEL_ICH7_21: 425 case PCI_DEVICE_ID_INTEL_ICH7_21:
439 case PCI_DEVICE_ID_INTEL_ESB2_18: 426 case PCI_DEVICE_ID_INTEL_ESB2_18:
440 case PCI_DEVICE_ID_INTEL_ICH8_6: 427 case PCI_DEVICE_ID_INTEL_ICH8_6:
441 { 428 return 1;
442 unsigned int extra = 0;
443 pci_read_config_dword(dev, 0x54, &extra);
444 pci_write_config_dword(dev, 0x54, extra|0x400);
445 }
446 default:
447 break;
448 } 429 }
449 430
450 return 0; 431 return 0;
451} 432}
452 433
453/** 434/**
435 * init_chipset_piix - set up the PIIX chipset
436 * @dev: PCI device to set up
437 * @name: Name of the device
438 *
439 * Initialize the PCI device as required. For the PIIX this turns
440 * out to be nice and simple
441 */
442
443static unsigned int __devinit init_chipset_piix (struct pci_dev *dev, const char *name)
444{
445 if (piix_is_ichx(dev)) {
446 unsigned int extra = 0;
447 pci_read_config_dword(dev, 0x54, &extra);
448 pci_write_config_dword(dev, 0x54, extra|0x400);
449 }
450
451 return 0;
452}
453
454/**
455 * piix_dma_clear_irq - clear BMDMA status
456 * @drive: IDE drive to clear
457 *
458 * Called from ide_intr() for PIO interrupts
459 * to clear BMDMA status as needed by ICHx
460 */
461static void piix_dma_clear_irq(ide_drive_t *drive)
462{
463 ide_hwif_t *hwif = HWIF(drive);
464 u8 dma_stat;
465
466 /* clear the INTR & ERROR bits */
467 dma_stat = hwif->INB(hwif->dma_status);
468 /* Should we force the bit as well ? */
469 hwif->OUTB(dma_stat, hwif->dma_status);
470}
471
472static int __devinit piix_cable_detect(ide_hwif_t *hwif)
473{
474 struct pci_dev *dev = hwif->pci_dev;
475 u8 reg54h = 0, mask = hwif->channel ? 0xc0 : 0x30;
476
477 pci_read_config_byte(dev, 0x54, &reg54h);
478
479 return (reg54h & mask) ? 1 : 0;
480}
481
482/**
454 * init_hwif_piix - fill in the hwif for the PIIX 483 * init_hwif_piix - fill in the hwif for the PIIX
455 * @hwif: IDE interface 484 * @hwif: IDE interface
456 * 485 *
@@ -460,9 +489,6 @@ static unsigned int __devinit init_chipset_piix (struct pci_dev *dev, const char
460 489
461static void __devinit init_hwif_piix(ide_hwif_t *hwif) 490static void __devinit init_hwif_piix(ide_hwif_t *hwif)
462{ 491{
463 u8 reg54h = 0, reg55h = 0, ata66 = 0;
464 u8 mask = hwif->channel ? 0xc0 : 0x30;
465
466#ifndef CONFIG_IA64 492#ifndef CONFIG_IA64
467 if (!hwif->irq) 493 if (!hwif->irq)
468 hwif->irq = hwif->channel ? 15 : 14; 494 hwif->irq = hwif->channel ? 15 : 14;
@@ -472,10 +498,6 @@ static void __devinit init_hwif_piix(ide_hwif_t *hwif)
472 /* This is a painful system best to let it self tune for now */ 498 /* This is a painful system best to let it self tune for now */
473 return; 499 return;
474 } 500 }
475 /* ESB2 appears to generate spurious DMA interrupts in PIO mode
476 when in native mode */
477 if (hwif->pci_dev->device == PCI_DEVICE_ID_INTEL_ESB2_18)
478 hwif->atapi_irq_bogon = 1;
479 501
480 hwif->autodma = 0; 502 hwif->autodma = 0;
481 hwif->tuneproc = &piix_tune_drive; 503 hwif->tuneproc = &piix_tune_drive;
@@ -486,15 +508,16 @@ static void __devinit init_hwif_piix(ide_hwif_t *hwif)
486 if (!hwif->dma_base) 508 if (!hwif->dma_base)
487 return; 509 return;
488 510
511 /* ICHx need to clear the bmdma status for all interrupts */
512 if (piix_is_ichx(hwif->pci_dev))
513 hwif->ide_dma_clear_irq = &piix_dma_clear_irq;
514
489 hwif->atapi_dma = 1; 515 hwif->atapi_dma = 1;
490 hwif->ultra_mask = 0x3f; 516 hwif->ultra_mask = 0x3f;
491 hwif->mwdma_mask = 0x06; 517 hwif->mwdma_mask = 0x06;
492 hwif->swdma_mask = 0x04; 518 hwif->swdma_mask = 0x04;
493 519
494 switch(hwif->pci_dev->device) { 520 switch(hwif->pci_dev->device) {
495 case PCI_DEVICE_ID_INTEL_82371MX:
496 hwif->mwdma_mask = 0x80;
497 hwif->swdma_mask = 0x80;
498 case PCI_DEVICE_ID_INTEL_82371FB_0: 521 case PCI_DEVICE_ID_INTEL_82371FB_0:
499 case PCI_DEVICE_ID_INTEL_82371FB_1: 522 case PCI_DEVICE_ID_INTEL_82371FB_1:
500 case PCI_DEVICE_ID_INTEL_82371SB_1: 523 case PCI_DEVICE_ID_INTEL_82371SB_1:
@@ -507,14 +530,14 @@ static void __devinit init_hwif_piix(ide_hwif_t *hwif)
507 hwif->ultra_mask = 0x07; 530 hwif->ultra_mask = 0x07;
508 break; 531 break;
509 default: 532 default:
510 pci_read_config_byte(hwif->pci_dev, 0x54, &reg54h); 533 if (!hwif->udma_four)
511 pci_read_config_byte(hwif->pci_dev, 0x55, &reg55h); 534 hwif->udma_four = piix_cable_detect(hwif);
512 ata66 = (reg54h & mask) ? 1 : 0;
513 break; 535 break;
514 } 536 }
515 537
516 if (!(hwif->udma_four)) 538 if (no_piix_dma)
517 hwif->udma_four = ata66; 539 hwif->ultra_mask = hwif->mwdma_mask = hwif->swdma_mask = 0;
540
518 hwif->ide_dma_check = &piix_config_drive_xfer_rate; 541 hwif->ide_dma_check = &piix_config_drive_xfer_rate;
519 if (!noautodma) 542 if (!noautodma)
520 hwif->autodma = 1; 543 hwif->autodma = 1;
diff --git a/drivers/ide/pci/sc1200.c b/drivers/ide/pci/sc1200.c
index 8d762d323f8b..b5ae0c50e216 100644
--- a/drivers/ide/pci/sc1200.c
+++ b/drivers/ide/pci/sc1200.c
@@ -161,7 +161,7 @@ static int sc1200_config_dma2 (ide_drive_t *drive, int mode)
161 /* 161 /*
162 * Default to DMA-off in case we run into trouble here. 162 * Default to DMA-off in case we run into trouble here.
163 */ 163 */
164 hwif->ide_dma_off_quietly(drive); /* turn off DMA while we fiddle */ 164 hwif->dma_off_quietly(drive); /* turn off DMA while we fiddle */
165 outb(inb(hwif->dma_base+2)&~(unit?0x40:0x20), hwif->dma_base+2); /* clear DMA_capable bit */ 165 outb(inb(hwif->dma_base+2)&~(unit?0x40:0x20), hwif->dma_base+2); /* clear DMA_capable bit */
166 166
167 /* 167 /*
@@ -241,10 +241,7 @@ static int sc1200_config_dma2 (ide_drive_t *drive, int mode)
241 241
242 outb(inb(hwif->dma_base+2)|(unit?0x40:0x20), hwif->dma_base+2); /* set DMA_capable bit */ 242 outb(inb(hwif->dma_base+2)|(unit?0x40:0x20), hwif->dma_base+2); /* set DMA_capable bit */
243 243
244 /* 244 return 0; /* success */
245 * Finally, turn DMA on in software, and exit.
246 */
247 return hwif->ide_dma_on(drive); /* success */
248} 245}
249 246
250/* 247/*
@@ -442,10 +439,10 @@ static int sc1200_resume (struct pci_dev *dev)
442 ide_drive_t *drive = &(hwif->drives[d]); 439 ide_drive_t *drive = &(hwif->drives[d]);
443 if (drive->present && !__ide_dma_bad_drive(drive)) { 440 if (drive->present && !__ide_dma_bad_drive(drive)) {
444 int was_using_dma = drive->using_dma; 441 int was_using_dma = drive->using_dma;
445 hwif->ide_dma_off_quietly(drive); 442 hwif->dma_off_quietly(drive);
446 sc1200_config_dma(drive); 443 sc1200_config_dma(drive);
447 if (!was_using_dma && drive->using_dma) { 444 if (!was_using_dma && drive->using_dma) {
448 hwif->ide_dma_off_quietly(drive); 445 hwif->dma_off_quietly(drive);
449 } 446 }
450 } 447 }
451 } 448 }
diff --git a/drivers/ide/pci/serverworks.c b/drivers/ide/pci/serverworks.c
index ea9a28a45853..dbcd37a0c652 100644
--- a/drivers/ide/pci/serverworks.c
+++ b/drivers/ide/pci/serverworks.c
@@ -160,7 +160,7 @@ static int svwks_tune_chipset (ide_drive_t *drive, u8 xferspeed)
160 if ((dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE) || 160 if ((dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE) ||
161 (dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2)) { 161 (dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2)) {
162 if (!drive->init_speed) { 162 if (!drive->init_speed) {
163 u8 dma_stat = hwif->INB(hwif->dma_status); 163 u8 dma_stat = inb(hwif->dma_status);
164 164
165dma_pio: 165dma_pio:
166 if (((ultra_enable << (7-drive->dn) & 0x80) == 0x80) && 166 if (((ultra_enable << (7-drive->dn) & 0x80) == 0x80) &&
@@ -315,35 +315,15 @@ static int config_chipset_for_dma (ide_drive_t *drive)
315 315
316static int svwks_config_drive_xfer_rate (ide_drive_t *drive) 316static int svwks_config_drive_xfer_rate (ide_drive_t *drive)
317{ 317{
318 ide_hwif_t *hwif = HWIF(drive);
319 struct hd_driveid *id = drive->id;
320
321 drive->init_speed = 0; 318 drive->init_speed = 0;
322 319
323 if ((id->capability & 1) && drive->autodma) { 320 if (ide_use_dma(drive) && config_chipset_for_dma(drive))
324 321 return 0;
325 if (ide_use_dma(drive)) {
326 if (config_chipset_for_dma(drive))
327 return hwif->ide_dma_on(drive);
328 }
329
330 goto fast_ata_pio;
331 322
332 } else if ((id->capability & 8) || (id->field_valid & 2)) { 323 if (ide_use_fast_pio(drive))
333fast_ata_pio:
334 config_chipset_for_pio(drive); 324 config_chipset_for_pio(drive);
335 // hwif->tuneproc(drive, 5);
336 return hwif->ide_dma_off_quietly(drive);
337 }
338 /* IORDY not supported */
339 return 0;
340}
341
342/* This can go soon */
343 325
344static int svwks_ide_dma_end (ide_drive_t *drive) 326 return -1;
345{
346 return __ide_dma_end(drive);
347} 327}
348 328
349static unsigned int __devinit init_chipset_svwks (struct pci_dev *dev, const char *name) 329static unsigned int __devinit init_chipset_svwks (struct pci_dev *dev, const char *name)
@@ -537,35 +517,20 @@ static void __devinit init_hwif_svwks (ide_hwif_t *hwif)
537 } 517 }
538 518
539 hwif->ide_dma_check = &svwks_config_drive_xfer_rate; 519 hwif->ide_dma_check = &svwks_config_drive_xfer_rate;
540 if (hwif->pci_dev->device == PCI_DEVICE_ID_SERVERWORKS_OSB4IDE) 520 if (hwif->pci_dev->device != PCI_DEVICE_ID_SERVERWORKS_OSB4IDE) {
541 hwif->ide_dma_end = &svwks_ide_dma_end; 521 if (!hwif->udma_four)
542 else if (!(hwif->udma_four)) 522 hwif->udma_four = ata66_svwks(hwif);
543 hwif->udma_four = ata66_svwks(hwif); 523 }
544 if (!noautodma) 524 if (!noautodma)
545 hwif->autodma = 1; 525 hwif->autodma = 1;
546 526
547 dma_stat = hwif->INB(hwif->dma_status); 527 dma_stat = inb(hwif->dma_status);
548 hwif->drives[0].autodma = (dma_stat & 0x20); 528 hwif->drives[0].autodma = (dma_stat & 0x20);
549 hwif->drives[1].autodma = (dma_stat & 0x40); 529 hwif->drives[1].autodma = (dma_stat & 0x40);
550 hwif->drives[0].autotune = (!(dma_stat & 0x20)); 530 hwif->drives[0].autotune = (!(dma_stat & 0x20));
551 hwif->drives[1].autotune = (!(dma_stat & 0x40)); 531 hwif->drives[1].autotune = (!(dma_stat & 0x40));
552} 532}
553 533
554/*
555 * We allow the BM-DMA driver to only work on enabled interfaces.
556 */
557static void __devinit init_dma_svwks (ide_hwif_t *hwif, unsigned long dmabase)
558{
559 struct pci_dev *dev = hwif->pci_dev;
560
561 if (((dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE) ||
562 (dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2)) &&
563 (!(PCI_FUNC(dev->devfn) & 1)) && (hwif->channel))
564 return;
565
566 ide_setup_dma(hwif, dmabase, 8);
567}
568
569static int __devinit init_setup_svwks (struct pci_dev *dev, ide_pci_device_t *d) 534static int __devinit init_setup_svwks (struct pci_dev *dev, ide_pci_device_t *d)
570{ 535{
571 return ide_setup_pci_device(dev, d); 536 return ide_setup_pci_device(dev, d);
@@ -600,7 +565,6 @@ static ide_pci_device_t serverworks_chipsets[] __devinitdata = {
600 .init_setup = init_setup_svwks, 565 .init_setup = init_setup_svwks,
601 .init_chipset = init_chipset_svwks, 566 .init_chipset = init_chipset_svwks,
602 .init_hwif = init_hwif_svwks, 567 .init_hwif = init_hwif_svwks,
603 .init_dma = init_dma_svwks,
604 .channels = 2, 568 .channels = 2,
605 .autodma = AUTODMA, 569 .autodma = AUTODMA,
606 .bootable = ON_BOARD, 570 .bootable = ON_BOARD,
@@ -609,7 +573,6 @@ static ide_pci_device_t serverworks_chipsets[] __devinitdata = {
609 .init_setup = init_setup_csb6, 573 .init_setup = init_setup_csb6,
610 .init_chipset = init_chipset_svwks, 574 .init_chipset = init_chipset_svwks,
611 .init_hwif = init_hwif_svwks, 575 .init_hwif = init_hwif_svwks,
612 .init_dma = init_dma_svwks,
613 .channels = 2, 576 .channels = 2,
614 .autodma = AUTODMA, 577 .autodma = AUTODMA,
615 .bootable = ON_BOARD, 578 .bootable = ON_BOARD,
@@ -618,7 +581,6 @@ static ide_pci_device_t serverworks_chipsets[] __devinitdata = {
618 .init_setup = init_setup_csb6, 581 .init_setup = init_setup_csb6,
619 .init_chipset = init_chipset_svwks, 582 .init_chipset = init_chipset_svwks,
620 .init_hwif = init_hwif_svwks, 583 .init_hwif = init_hwif_svwks,
621 .init_dma = init_dma_svwks,
622 .channels = 1, /* 2 */ 584 .channels = 1, /* 2 */
623 .autodma = AUTODMA, 585 .autodma = AUTODMA,
624 .bootable = ON_BOARD, 586 .bootable = ON_BOARD,
@@ -627,7 +589,6 @@ static ide_pci_device_t serverworks_chipsets[] __devinitdata = {
627 .init_setup = init_setup_svwks, 589 .init_setup = init_setup_svwks,
628 .init_chipset = init_chipset_svwks, 590 .init_chipset = init_chipset_svwks,
629 .init_hwif = init_hwif_svwks, 591 .init_hwif = init_hwif_svwks,
630 .init_dma = init_dma_svwks,
631 .channels = 1, /* 2 */ 592 .channels = 1, /* 2 */
632 .autodma = AUTODMA, 593 .autodma = AUTODMA,
633 .bootable = ON_BOARD, 594 .bootable = ON_BOARD,
diff --git a/drivers/ide/pci/sgiioc4.c b/drivers/ide/pci/sgiioc4.c
index b0bf01809279..fd09b295a69d 100644
--- a/drivers/ide/pci/sgiioc4.c
+++ b/drivers/ide/pci/sgiioc4.c
@@ -110,24 +110,24 @@ sgiioc4_init_hwif_ports(hw_regs_t * hw, unsigned long data_port,
110static void 110static void
111sgiioc4_maskproc(ide_drive_t * drive, int mask) 111sgiioc4_maskproc(ide_drive_t * drive, int mask)
112{ 112{
113 ide_hwif_t *hwif = HWIF(drive); 113 writeb(mask ? (drive->ctl | 2) : (drive->ctl & ~2),
114 hwif->OUTB(mask ? (drive->ctl | 2) : (drive->ctl & ~2), 114 (void __iomem *)IDE_CONTROL_REG);
115 IDE_CONTROL_REG);
116} 115}
117 116
118 117
119static int 118static int
120sgiioc4_checkirq(ide_hwif_t * hwif) 119sgiioc4_checkirq(ide_hwif_t * hwif)
121{ 120{
122 u8 intr_reg = 121 unsigned long intr_addr =
123 hwif->INL(hwif->io_ports[IDE_IRQ_OFFSET] + IOC4_INTR_REG * 4); 122 hwif->io_ports[IDE_IRQ_OFFSET] + IOC4_INTR_REG * 4;
124 123
125 if (intr_reg & 0x03) 124 if ((u8)readl((void __iomem *)intr_addr) & 0x03)
126 return 1; 125 return 1;
127 126
128 return 0; 127 return 0;
129} 128}
130 129
130static u8 sgiioc4_INB(unsigned long);
131 131
132static int 132static int
133sgiioc4_clearirq(ide_drive_t * drive) 133sgiioc4_clearirq(ide_drive_t * drive)
@@ -138,21 +138,21 @@ sgiioc4_clearirq(ide_drive_t * drive)
138 hwif->io_ports[IDE_IRQ_OFFSET] + (IOC4_INTR_REG << 2); 138 hwif->io_ports[IDE_IRQ_OFFSET] + (IOC4_INTR_REG << 2);
139 139
140 /* Code to check for PCI error conditions */ 140 /* Code to check for PCI error conditions */
141 intr_reg = hwif->INL(other_ir); 141 intr_reg = readl((void __iomem *)other_ir);
142 if (intr_reg & 0x03) { /* Valid IOC4-IDE interrupt */ 142 if (intr_reg & 0x03) { /* Valid IOC4-IDE interrupt */
143 /* 143 /*
144 * Using hwif->INB to read the IDE_STATUS_REG has a side effect 144 * Using sgiioc4_INB to read the IDE_STATUS_REG has a side effect
145 * of clearing the interrupt. The first read should clear it 145 * of clearing the interrupt. The first read should clear it
146 * if it is set. The second read should return a "clear" status 146 * if it is set. The second read should return a "clear" status
147 * if it got cleared. If not, then spin for a bit trying to 147 * if it got cleared. If not, then spin for a bit trying to
148 * clear it. 148 * clear it.
149 */ 149 */
150 u8 stat = hwif->INB(IDE_STATUS_REG); 150 u8 stat = sgiioc4_INB(IDE_STATUS_REG);
151 int count = 0; 151 int count = 0;
152 stat = hwif->INB(IDE_STATUS_REG); 152 stat = sgiioc4_INB(IDE_STATUS_REG);
153 while ((stat & 0x80) && (count++ < 100)) { 153 while ((stat & 0x80) && (count++ < 100)) {
154 udelay(1); 154 udelay(1);
155 stat = hwif->INB(IDE_STATUS_REG); 155 stat = sgiioc4_INB(IDE_STATUS_REG);
156 } 156 }
157 157
158 if (intr_reg & 0x02) { 158 if (intr_reg & 0x02) {
@@ -161,9 +161,9 @@ sgiioc4_clearirq(ide_drive_t * drive)
161 pci_stat_cmd_reg; 161 pci_stat_cmd_reg;
162 162
163 pci_err_addr_low = 163 pci_err_addr_low =
164 hwif->INL(hwif->io_ports[IDE_IRQ_OFFSET]); 164 readl((void __iomem *)hwif->io_ports[IDE_IRQ_OFFSET]);
165 pci_err_addr_high = 165 pci_err_addr_high =
166 hwif->INL(hwif->io_ports[IDE_IRQ_OFFSET] + 4); 166 readl((void __iomem *)(hwif->io_ports[IDE_IRQ_OFFSET] + 4));
167 pci_read_config_dword(hwif->pci_dev, PCI_COMMAND, 167 pci_read_config_dword(hwif->pci_dev, PCI_COMMAND,
168 &pci_stat_cmd_reg); 168 &pci_stat_cmd_reg);
169 printk(KERN_ERR 169 printk(KERN_ERR
@@ -180,9 +180,9 @@ sgiioc4_clearirq(ide_drive_t * drive)
180 } 180 }
181 181
182 /* Clear the Interrupt, Error bits on the IOC4 */ 182 /* Clear the Interrupt, Error bits on the IOC4 */
183 hwif->OUTL(0x03, other_ir); 183 writel(0x03, (void __iomem *)other_ir);
184 184
185 intr_reg = hwif->INL(other_ir); 185 intr_reg = readl((void __iomem *)other_ir);
186 } 186 }
187 187
188 return intr_reg & 3; 188 return intr_reg & 3;
@@ -191,23 +191,25 @@ sgiioc4_clearirq(ide_drive_t * drive)
191static void sgiioc4_ide_dma_start(ide_drive_t * drive) 191static void sgiioc4_ide_dma_start(ide_drive_t * drive)
192{ 192{
193 ide_hwif_t *hwif = HWIF(drive); 193 ide_hwif_t *hwif = HWIF(drive);
194 unsigned int reg = hwif->INL(hwif->dma_base + IOC4_DMA_CTRL * 4); 194 unsigned long ioc4_dma_addr = hwif->dma_base + IOC4_DMA_CTRL * 4;
195 unsigned int reg = readl((void __iomem *)ioc4_dma_addr);
195 unsigned int temp_reg = reg | IOC4_S_DMA_START; 196 unsigned int temp_reg = reg | IOC4_S_DMA_START;
196 197
197 hwif->OUTL(temp_reg, hwif->dma_base + IOC4_DMA_CTRL * 4); 198 writel(temp_reg, (void __iomem *)ioc4_dma_addr);
198} 199}
199 200
200static u32 201static u32
201sgiioc4_ide_dma_stop(ide_hwif_t *hwif, u64 dma_base) 202sgiioc4_ide_dma_stop(ide_hwif_t *hwif, u64 dma_base)
202{ 203{
204 unsigned long ioc4_dma_addr = dma_base + IOC4_DMA_CTRL * 4;
203 u32 ioc4_dma; 205 u32 ioc4_dma;
204 int count; 206 int count;
205 207
206 count = 0; 208 count = 0;
207 ioc4_dma = hwif->INL(dma_base + IOC4_DMA_CTRL * 4); 209 ioc4_dma = readl((void __iomem *)ioc4_dma_addr);
208 while ((ioc4_dma & IOC4_S_DMA_STOP) && (count++ < 200)) { 210 while ((ioc4_dma & IOC4_S_DMA_STOP) && (count++ < 200)) {
209 udelay(1); 211 udelay(1);
210 ioc4_dma = hwif->INL(dma_base + IOC4_DMA_CTRL * 4); 212 ioc4_dma = readl((void __iomem *)ioc4_dma_addr);
211 } 213 }
212 return ioc4_dma; 214 return ioc4_dma;
213} 215}
@@ -218,11 +220,11 @@ sgiioc4_ide_dma_end(ide_drive_t * drive)
218{ 220{
219 u32 ioc4_dma, bc_dev, bc_mem, num, valid = 0, cnt = 0; 221 u32 ioc4_dma, bc_dev, bc_mem, num, valid = 0, cnt = 0;
220 ide_hwif_t *hwif = HWIF(drive); 222 ide_hwif_t *hwif = HWIF(drive);
221 u64 dma_base = hwif->dma_base; 223 unsigned long dma_base = hwif->dma_base;
222 int dma_stat = 0; 224 int dma_stat = 0;
223 unsigned long *ending_dma = ide_get_hwifdata(hwif); 225 unsigned long *ending_dma = ide_get_hwifdata(hwif);
224 226
225 hwif->OUTL(IOC4_S_DMA_STOP, dma_base + IOC4_DMA_CTRL * 4); 227 writel(IOC4_S_DMA_STOP, (void __iomem *)(dma_base + IOC4_DMA_CTRL * 4));
226 228
227 ioc4_dma = sgiioc4_ide_dma_stop(hwif, dma_base); 229 ioc4_dma = sgiioc4_ide_dma_stop(hwif, dma_base);
228 230
@@ -254,8 +256,8 @@ sgiioc4_ide_dma_end(ide_drive_t * drive)
254 dma_stat = 1; 256 dma_stat = 1;
255 } 257 }
256 258
257 bc_dev = hwif->INL(dma_base + IOC4_BC_DEV * 4); 259 bc_dev = readl((void __iomem *)(dma_base + IOC4_BC_DEV * 4));
258 bc_mem = hwif->INL(dma_base + IOC4_BC_MEM * 4); 260 bc_mem = readl((void __iomem *)(dma_base + IOC4_BC_MEM * 4));
259 261
260 if ((bc_dev & 0x01FF) || (bc_mem & 0x1FF)) { 262 if ((bc_dev & 0x01FF) || (bc_mem & 0x1FF)) {
261 if (bc_dev > bc_mem + 8) { 263 if (bc_dev > bc_mem + 8) {
@@ -273,34 +275,29 @@ sgiioc4_ide_dma_end(ide_drive_t * drive)
273} 275}
274 276
275static int 277static int
276sgiioc4_ide_dma_check(ide_drive_t * drive) 278sgiioc4_ide_dma_on(ide_drive_t * drive)
277{ 279{
278 if (ide_config_drive_speed(drive, XFER_MW_DMA_2) != 0) { 280 drive->using_dma = 1;
279 printk(KERN_INFO
280 "Couldnot set %s in Multimode-2 DMA mode | "
281 "Drive %s using PIO instead\n",
282 drive->name, drive->name);
283 drive->using_dma = 0;
284 } else
285 drive->using_dma = 1;
286 281
287 return 0; 282 return 0;
288} 283}
289 284
290static int 285static void sgiioc4_dma_off_quietly(ide_drive_t *drive)
291sgiioc4_ide_dma_on(ide_drive_t * drive)
292{ 286{
293 drive->using_dma = 1; 287 drive->using_dma = 0;
294 288
295 return HWIF(drive)->ide_dma_host_on(drive); 289 drive->hwif->dma_host_off(drive);
296} 290}
297 291
298static int 292static int sgiioc4_ide_dma_check(ide_drive_t *drive)
299sgiioc4_ide_dma_off_quietly(ide_drive_t * drive)
300{ 293{
301 drive->using_dma = 0; 294 /* FIXME: check for available DMA modes */
302 295 if (ide_config_drive_speed(drive, XFER_MW_DMA_2) != 0) {
303 return HWIF(drive)->ide_dma_host_off(drive); 296 printk(KERN_WARNING "%s: couldn't set MWDMA2 mode, "
297 "using PIO instead\n", drive->name);
298 return -1;
299 } else
300 return 0;
304} 301}
305 302
306/* returns 1 if dma irq issued, 0 otherwise */ 303/* returns 1 if dma irq issued, 0 otherwise */
@@ -310,21 +307,13 @@ sgiioc4_ide_dma_test_irq(ide_drive_t * drive)
310 return sgiioc4_checkirq(HWIF(drive)); 307 return sgiioc4_checkirq(HWIF(drive));
311} 308}
312 309
313static int 310static void sgiioc4_dma_host_on(ide_drive_t * drive)
314sgiioc4_ide_dma_host_on(ide_drive_t * drive)
315{ 311{
316 if (drive->using_dma)
317 return 0;
318
319 return 1;
320} 312}
321 313
322static int 314static void sgiioc4_dma_host_off(ide_drive_t * drive)
323sgiioc4_ide_dma_host_off(ide_drive_t * drive)
324{ 315{
325 sgiioc4_clearirq(drive); 316 sgiioc4_clearirq(drive);
326
327 return 0;
328} 317}
329 318
330static int 319static int
@@ -436,16 +425,17 @@ sgiioc4_configure_for_dma(int dma_direction, ide_drive_t * drive)
436{ 425{
437 u32 ioc4_dma; 426 u32 ioc4_dma;
438 ide_hwif_t *hwif = HWIF(drive); 427 ide_hwif_t *hwif = HWIF(drive);
439 u64 dma_base = hwif->dma_base; 428 unsigned long dma_base = hwif->dma_base;
429 unsigned long ioc4_dma_addr = dma_base + IOC4_DMA_CTRL * 4;
440 u32 dma_addr, ending_dma_addr; 430 u32 dma_addr, ending_dma_addr;
441 431
442 ioc4_dma = hwif->INL(dma_base + IOC4_DMA_CTRL * 4); 432 ioc4_dma = readl((void __iomem *)ioc4_dma_addr);
443 433
444 if (ioc4_dma & IOC4_S_DMA_ACTIVE) { 434 if (ioc4_dma & IOC4_S_DMA_ACTIVE) {
445 printk(KERN_WARNING 435 printk(KERN_WARNING
446 "%s(%s):Warning!! DMA from previous transfer was still active\n", 436 "%s(%s):Warning!! DMA from previous transfer was still active\n",
447 __FUNCTION__, drive->name); 437 __FUNCTION__, drive->name);
448 hwif->OUTL(IOC4_S_DMA_STOP, dma_base + IOC4_DMA_CTRL * 4); 438 writel(IOC4_S_DMA_STOP, (void __iomem *)ioc4_dma_addr);
449 ioc4_dma = sgiioc4_ide_dma_stop(hwif, dma_base); 439 ioc4_dma = sgiioc4_ide_dma_stop(hwif, dma_base);
450 440
451 if (ioc4_dma & IOC4_S_DMA_STOP) 441 if (ioc4_dma & IOC4_S_DMA_STOP)
@@ -454,13 +444,13 @@ sgiioc4_configure_for_dma(int dma_direction, ide_drive_t * drive)
454 __FUNCTION__, drive->name); 444 __FUNCTION__, drive->name);
455 } 445 }
456 446
457 ioc4_dma = hwif->INL(dma_base + IOC4_DMA_CTRL * 4); 447 ioc4_dma = readl((void __iomem *)ioc4_dma_addr);
458 if (ioc4_dma & IOC4_S_DMA_ERROR) { 448 if (ioc4_dma & IOC4_S_DMA_ERROR) {
459 printk(KERN_WARNING 449 printk(KERN_WARNING
460 "%s(%s) : Warning!! - DMA Error during Previous" 450 "%s(%s) : Warning!! - DMA Error during Previous"
461 " transfer | status 0x%x\n", 451 " transfer | status 0x%x\n",
462 __FUNCTION__, drive->name, ioc4_dma); 452 __FUNCTION__, drive->name, ioc4_dma);
463 hwif->OUTL(IOC4_S_DMA_STOP, dma_base + IOC4_DMA_CTRL * 4); 453 writel(IOC4_S_DMA_STOP, (void __iomem *)ioc4_dma_addr);
464 ioc4_dma = sgiioc4_ide_dma_stop(hwif, dma_base); 454 ioc4_dma = sgiioc4_ide_dma_stop(hwif, dma_base);
465 455
466 if (ioc4_dma & IOC4_S_DMA_STOP) 456 if (ioc4_dma & IOC4_S_DMA_STOP)
@@ -471,14 +461,14 @@ sgiioc4_configure_for_dma(int dma_direction, ide_drive_t * drive)
471 461
472 /* Address of the Scatter Gather List */ 462 /* Address of the Scatter Gather List */
473 dma_addr = cpu_to_le32(hwif->dmatable_dma); 463 dma_addr = cpu_to_le32(hwif->dmatable_dma);
474 hwif->OUTL(dma_addr, dma_base + IOC4_DMA_PTR_L * 4); 464 writel(dma_addr, (void __iomem *)(dma_base + IOC4_DMA_PTR_L * 4));
475 465
476 /* Address of the Ending DMA */ 466 /* Address of the Ending DMA */
477 memset(ide_get_hwifdata(hwif), 0, IOC4_IDE_CACHELINE_SIZE); 467 memset(ide_get_hwifdata(hwif), 0, IOC4_IDE_CACHELINE_SIZE);
478 ending_dma_addr = cpu_to_le32(hwif->dma_status); 468 ending_dma_addr = cpu_to_le32(hwif->dma_status);
479 hwif->OUTL(ending_dma_addr, dma_base + IOC4_DMA_END_ADDR * 4); 469 writel(ending_dma_addr, (void __iomem *)(dma_base + IOC4_DMA_END_ADDR * 4));
480 470
481 hwif->OUTL(dma_direction, dma_base + IOC4_DMA_CTRL * 4); 471 writel(dma_direction, (void __iomem *)ioc4_dma_addr);
482 drive->waiting_for_dma = 1; 472 drive->waiting_for_dma = 1;
483} 473}
484 474
@@ -590,7 +580,7 @@ static int sgiioc4_ide_dma_setup(ide_drive_t *drive)
590static void __devinit 580static void __devinit
591ide_init_sgiioc4(ide_hwif_t * hwif) 581ide_init_sgiioc4(ide_hwif_t * hwif)
592{ 582{
593 hwif->mmio = 2; 583 hwif->mmio = 1;
594 hwif->autodma = 1; 584 hwif->autodma = 1;
595 hwif->atapi_dma = 1; 585 hwif->atapi_dma = 1;
596 hwif->ultra_mask = 0x0; /* Disable Ultra DMA */ 586 hwif->ultra_mask = 0x0; /* Disable Ultra DMA */
@@ -613,10 +603,10 @@ ide_init_sgiioc4(ide_hwif_t * hwif)
613 hwif->ide_dma_end = &sgiioc4_ide_dma_end; 603 hwif->ide_dma_end = &sgiioc4_ide_dma_end;
614 hwif->ide_dma_check = &sgiioc4_ide_dma_check; 604 hwif->ide_dma_check = &sgiioc4_ide_dma_check;
615 hwif->ide_dma_on = &sgiioc4_ide_dma_on; 605 hwif->ide_dma_on = &sgiioc4_ide_dma_on;
616 hwif->ide_dma_off_quietly = &sgiioc4_ide_dma_off_quietly; 606 hwif->dma_off_quietly = &sgiioc4_dma_off_quietly;
617 hwif->ide_dma_test_irq = &sgiioc4_ide_dma_test_irq; 607 hwif->ide_dma_test_irq = &sgiioc4_ide_dma_test_irq;
618 hwif->ide_dma_host_on = &sgiioc4_ide_dma_host_on; 608 hwif->dma_host_on = &sgiioc4_dma_host_on;
619 hwif->ide_dma_host_off = &sgiioc4_ide_dma_host_off; 609 hwif->dma_host_off = &sgiioc4_dma_host_off;
620 hwif->ide_dma_lostirq = &sgiioc4_ide_dma_lostirq; 610 hwif->ide_dma_lostirq = &sgiioc4_ide_dma_lostirq;
621 hwif->ide_dma_timeout = &__ide_dma_timeout; 611 hwif->ide_dma_timeout = &__ide_dma_timeout;
622 612
@@ -688,7 +678,7 @@ sgiioc4_ide_setup_pci_device(struct pci_dev *dev, ide_pci_device_t * d)
688 default_hwif_mmiops(hwif); 678 default_hwif_mmiops(hwif);
689 679
690 /* Initializing chipset IRQ Registers */ 680 /* Initializing chipset IRQ Registers */
691 hwif->OUTL(0x03, irqport + IOC4_INTR_SET * 4); 681 writel(0x03, (void __iomem *)(irqport + IOC4_INTR_SET * 4));
692 682
693 ide_init_sgiioc4(hwif); 683 ide_init_sgiioc4(hwif);
694 684
@@ -729,8 +719,7 @@ out:
729 return ret; 719 return ret;
730} 720}
731 721
732static ide_pci_device_t sgiioc4_chipsets[] __devinitdata = { 722static ide_pci_device_t sgiioc4_chipset __devinitdata = {
733 {
734 /* Channel 0 */ 723 /* Channel 0 */
735 .name = "SGIIOC4", 724 .name = "SGIIOC4",
736 .init_hwif = ide_init_sgiioc4, 725 .init_hwif = ide_init_sgiioc4,
@@ -739,7 +728,6 @@ static ide_pci_device_t sgiioc4_chipsets[] __devinitdata = {
739 .autodma = AUTODMA, 728 .autodma = AUTODMA,
740 /* SGI IOC4 doesn't have enablebits. */ 729 /* SGI IOC4 doesn't have enablebits. */
741 .bootable = ON_BOARD, 730 .bootable = ON_BOARD,
742 }
743}; 731};
744 732
745int 733int
@@ -751,8 +739,7 @@ ioc4_ide_attach_one(struct ioc4_driver_data *idd)
751 if (idd->idd_variant == IOC4_VARIANT_PCI_RT) 739 if (idd->idd_variant == IOC4_VARIANT_PCI_RT)
752 return 0; 740 return 0;
753 741
754 return pci_init_sgiioc4(idd->idd_pdev, 742 return pci_init_sgiioc4(idd->idd_pdev, &sgiioc4_chipset);
755 &sgiioc4_chipsets[idd->idd_pci_id->driver_data]);
756} 743}
757 744
758static struct ioc4_submodule ioc4_ide_submodule = { 745static struct ioc4_submodule ioc4_ide_submodule = {
diff --git a/drivers/ide/pci/siimage.c b/drivers/ide/pci/siimage.c
index 4ff89c7d990a..7b4c189a9d99 100644
--- a/drivers/ide/pci/siimage.c
+++ b/drivers/ide/pci/siimage.c
@@ -1,8 +1,9 @@
1/* 1/*
2 * linux/drivers/ide/pci/siimage.c Version 1.07 Nov 30, 2003 2 * linux/drivers/ide/pci/siimage.c Version 1.11 Jan 27, 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>
6 * Copyright (C) 2007 MontaVista Software, Inc.
6 * 7 *
7 * May be copied or modified under the terms of the GNU General Public License 8 * May be copied or modified under the terms of the GNU General Public License
8 * 9 *
@@ -205,41 +206,39 @@ static void siimage_tuneproc (ide_drive_t *drive, byte mode_wanted)
205 unsigned long tfaddr = siimage_selreg(hwif, 0x02); 206 unsigned long tfaddr = siimage_selreg(hwif, 0x02);
206 207
207 /* cheat for now and use the docs */ 208 /* cheat for now and use the docs */
208 switch(mode_wanted) { 209 switch (mode_wanted) {
209 case 4: 210 case 4:
210 speedp = 0x10c1; 211 speedp = 0x10c1;
211 speedt = 0x10c1; 212 speedt = 0x10c1;
212 break; 213 break;
213 case 3: 214 case 3:
214 speedp = 0x10C3; 215 speedp = 0x10c3;
215 speedt = 0x10C3; 216 speedt = 0x10c3;
216 break; 217 break;
217 case 2: 218 case 2:
218 speedp = 0x1104; 219 speedp = 0x1104;
219 speedt = 0x1281; 220 speedt = 0x1281;
220 break; 221 break;
221 case 1: 222 case 1:
222 speedp = 0x2283; 223 speedp = 0x2283;
223 speedt = 0x1281; 224 speedt = 0x2283;
224 break; 225 break;
225 case 0: 226 case 0:
226 default: 227 default:
227 speedp = 0x328A; 228 speedp = 0x328a;
228 speedt = 0x328A; 229 speedt = 0x328a;
229 break; 230 break;
230 } 231 }
231 if (hwif->mmio) 232
232 { 233 if (hwif->mmio) {
233 hwif->OUTW(speedt, addr); 234 hwif->OUTW(speedp, addr);
234 hwif->OUTW(speedp, tfaddr); 235 hwif->OUTW(speedt, tfaddr);
235 /* Now set up IORDY */ 236 /* Now set up IORDY */
236 if(mode_wanted == 3 || mode_wanted == 4) 237 if(mode_wanted == 3 || mode_wanted == 4)
237 hwif->OUTW(hwif->INW(tfaddr-2)|0x200, tfaddr-2); 238 hwif->OUTW(hwif->INW(tfaddr-2)|0x200, tfaddr-2);
238 else 239 else
239 hwif->OUTW(hwif->INW(tfaddr-2)&~0x200, tfaddr-2); 240 hwif->OUTW(hwif->INW(tfaddr-2)&~0x200, tfaddr-2);
240 } 241 } else {
241 else
242 {
243 pci_write_config_word(hwif->pci_dev, addr, speedp); 242 pci_write_config_word(hwif->pci_dev, addr, speedp);
244 pci_write_config_word(hwif->pci_dev, tfaddr, speedt); 243 pci_write_config_word(hwif->pci_dev, tfaddr, speedt);
245 pci_read_config_word(hwif->pci_dev, tfaddr-2, &speedp); 244 pci_read_config_word(hwif->pci_dev, tfaddr-2, &speedp);
@@ -397,12 +396,9 @@ static int config_chipset_for_dma (ide_drive_t *drive)
397 if (!speed) 396 if (!speed)
398 return 0; 397 return 0;
399 398
400 if (ide_set_xfer_rate(drive, speed)) 399 if (siimage_tune_chipset(drive, speed))
401 return 0; 400 return 0;
402 401
403 if (!drive->init_speed)
404 drive->init_speed = speed;
405
406 return ide_dma_enable(drive); 402 return ide_dma_enable(drive);
407} 403}
408 404
@@ -418,25 +414,13 @@ static int config_chipset_for_dma (ide_drive_t *drive)
418 414
419static int siimage_config_drive_for_dma (ide_drive_t *drive) 415static int siimage_config_drive_for_dma (ide_drive_t *drive)
420{ 416{
421 ide_hwif_t *hwif = HWIF(drive); 417 if (ide_use_dma(drive) && config_chipset_for_dma(drive))
422 struct hd_driveid *id = drive->id; 418 return 0;
423
424 if ((id->capability & 1) != 0 && drive->autodma) {
425
426 if (ide_use_dma(drive)) {
427 if (config_chipset_for_dma(drive))
428 return hwif->ide_dma_on(drive);
429 }
430
431 goto fast_ata_pio;
432 419
433 } else if ((id->capability & 8) || (id->field_valid & 2)) { 420 if (ide_use_fast_pio(drive))
434fast_ata_pio:
435 config_chipset_for_pio(drive, 1); 421 config_chipset_for_pio(drive, 1);
436 return hwif->ide_dma_off_quietly(drive); 422
437 } 423 return -1;
438 /* IORDY not supported */
439 return 0;
440} 424}
441 425
442/* returns 1 if dma irq issued, 0 otherwise */ 426/* returns 1 if dma irq issued, 0 otherwise */
@@ -472,11 +456,11 @@ static int siimage_mmio_ide_dma_test_irq (ide_drive_t *drive)
472 unsigned long addr = siimage_selreg(hwif, 0x1); 456 unsigned long addr = siimage_selreg(hwif, 0x1);
473 457
474 if (SATA_ERROR_REG) { 458 if (SATA_ERROR_REG) {
475 u32 ext_stat = hwif->INL(base + 0x10); 459 u32 ext_stat = readl((void __iomem *)(base + 0x10));
476 u8 watchdog = 0; 460 u8 watchdog = 0;
477 if (ext_stat & ((hwif->channel) ? 0x40 : 0x10)) { 461 if (ext_stat & ((hwif->channel) ? 0x40 : 0x10)) {
478 u32 sata_error = hwif->INL(SATA_ERROR_REG); 462 u32 sata_error = readl((void __iomem *)SATA_ERROR_REG);
479 hwif->OUTL(sata_error, SATA_ERROR_REG); 463 writel(sata_error, (void __iomem *)SATA_ERROR_REG);
480 watchdog = (sata_error & 0x00680000) ? 1 : 0; 464 watchdog = (sata_error & 0x00680000) ? 1 : 0;
481 printk(KERN_WARNING "%s: sata_error = 0x%08x, " 465 printk(KERN_WARNING "%s: sata_error = 0x%08x, "
482 "watchdog = %d, %s\n", 466 "watchdog = %d, %s\n",
@@ -493,11 +477,11 @@ static int siimage_mmio_ide_dma_test_irq (ide_drive_t *drive)
493 } 477 }
494 478
495 /* return 1 if INTR asserted */ 479 /* return 1 if INTR asserted */
496 if ((hwif->INB(hwif->dma_status) & 0x04) == 0x04) 480 if ((readb((void __iomem *)hwif->dma_status) & 0x04) == 0x04)
497 return 1; 481 return 1;
498 482
499 /* return 1 if Device INTR asserted */ 483 /* return 1 if Device INTR asserted */
500 if ((hwif->INB(addr) & 8) == 8) 484 if ((readb((void __iomem *)addr) & 8) == 8)
501 return 0; //return 1; 485 return 0; //return 1;
502 486
503 return 0; 487 return 0;
@@ -519,9 +503,9 @@ static int siimage_busproc (ide_drive_t * drive, int state)
519 u32 stat_config = 0; 503 u32 stat_config = 0;
520 unsigned long addr = siimage_selreg(hwif, 0); 504 unsigned long addr = siimage_selreg(hwif, 0);
521 505
522 if (hwif->mmio) { 506 if (hwif->mmio)
523 stat_config = hwif->INL(addr); 507 stat_config = readl((void __iomem *)addr);
524 } else 508 else
525 pci_read_config_dword(hwif->pci_dev, addr, &stat_config); 509 pci_read_config_dword(hwif->pci_dev, addr, &stat_config);
526 510
527 switch (state) { 511 switch (state) {
@@ -557,9 +541,10 @@ static int siimage_reset_poll (ide_drive_t *drive)
557 if (SATA_STATUS_REG) { 541 if (SATA_STATUS_REG) {
558 ide_hwif_t *hwif = HWIF(drive); 542 ide_hwif_t *hwif = HWIF(drive);
559 543
560 if ((hwif->INL(SATA_STATUS_REG) & 0x03) != 0x03) { 544 /* SATA_STATUS_REG is valid only when in MMIO mode */
545 if ((readl((void __iomem *)SATA_STATUS_REG) & 0x03) != 0x03) {
561 printk(KERN_WARNING "%s: reset phy dead, status=0x%08x\n", 546 printk(KERN_WARNING "%s: reset phy dead, status=0x%08x\n",
562 hwif->name, hwif->INL(SATA_STATUS_REG)); 547 hwif->name, readl((void __iomem *)SATA_STATUS_REG));
563 HWGROUP(drive)->polling = 0; 548 HWGROUP(drive)->polling = 0;
564 return ide_started; 549 return ide_started;
565 } 550 }
@@ -619,7 +604,8 @@ static void siimage_reset (ide_drive_t *drive)
619 } 604 }
620 605
621 if (SATA_STATUS_REG) { 606 if (SATA_STATUS_REG) {
622 u32 sata_stat = hwif->INL(SATA_STATUS_REG); 607 /* SATA_STATUS_REG is valid only when in MMIO mode */
608 u32 sata_stat = readl((void __iomem *)SATA_STATUS_REG);
623 printk(KERN_WARNING "%s: reset phy, status=0x%08x, %s\n", 609 printk(KERN_WARNING "%s: reset phy, status=0x%08x, %s\n",
624 hwif->name, sata_stat, __FUNCTION__); 610 hwif->name, sata_stat, __FUNCTION__);
625 if (!(sata_stat)) { 611 if (!(sata_stat)) {
@@ -898,7 +884,8 @@ static void __devinit init_mmio_iops_siimage(ide_hwif_t *hwif)
898 base = (unsigned long) addr; 884 base = (unsigned long) addr;
899 885
900 hwif->dma_base = base + (ch ? 0x08 : 0x00); 886 hwif->dma_base = base + (ch ? 0x08 : 0x00);
901 hwif->mmio = 2; 887
888 hwif->mmio = 1;
902} 889}
903 890
904static int is_dev_seagate_sata(ide_drive_t *drive) 891static int is_dev_seagate_sata(ide_drive_t *drive)
diff --git a/drivers/ide/pci/sis5513.c b/drivers/ide/pci/sis5513.c
index 1afff659ab55..2ba0669f36a1 100644
--- a/drivers/ide/pci/sis5513.c
+++ b/drivers/ide/pci/sis5513.c
@@ -667,67 +667,20 @@ static int config_chipset_for_dma (ide_drive_t *drive)
667 return ide_dma_enable(drive); 667 return ide_dma_enable(drive);
668} 668}
669 669
670static int sis5513_config_drive_xfer_rate (ide_drive_t *drive) 670static int sis5513_config_xfer_rate(ide_drive_t *drive)
671{ 671{
672 ide_hwif_t *hwif = HWIF(drive); 672 config_art_rwp_pio(drive, 5);
673 struct hd_driveid *id = drive->id;
674 673
675 drive->init_speed = 0; 674 drive->init_speed = 0;
676 675
677 if (id && (id->capability & 1) && drive->autodma) { 676 if (ide_use_dma(drive) && config_chipset_for_dma(drive))
678 677 return 0;
679 if (ide_use_dma(drive)) {
680 if (config_chipset_for_dma(drive))
681 return hwif->ide_dma_on(drive);
682 }
683
684 goto fast_ata_pio;
685 678
686 } else if ((id->capability & 8) || (id->field_valid & 2)) { 679 if (ide_use_fast_pio(drive))
687fast_ata_pio:
688 sis5513_tune_drive(drive, 5); 680 sis5513_tune_drive(drive, 5);
689 return hwif->ide_dma_off_quietly(drive);
690 }
691 /* IORDY not supported */
692 return 0;
693}
694
695/* initiates/aborts (U)DMA read/write operations on a drive. */
696static int sis5513_config_xfer_rate (ide_drive_t *drive)
697{
698 config_drive_art_rwp(drive);
699 config_art_rwp_pio(drive, 5);
700 return sis5513_config_drive_xfer_rate(drive);
701}
702
703/*
704 Future simpler config_xfer_rate :
705 When ide_find_best_mode is made bad-drive aware
706 - remove config_drive_xfer_rate and config_chipset_for_dma,
707 - replace config_xfer_rate with the following
708
709static int sis5513_config_xfer_rate (ide_drive_t *drive)
710{
711 u16 w80 = HWIF(drive)->udma_four;
712 u16 speed;
713
714 config_drive_art_rwp(drive);
715 config_art_rwp_pio(drive, 5);
716
717 speed = ide_find_best_mode(drive,
718 XFER_PIO | XFER_EPIO | XFER_SWDMA | XFER_MWDMA |
719 (chipset_family >= ATA_33 ? XFER_UDMA : 0) |
720 (w80 && chipset_family >= ATA_66 ? XFER_UDMA_66 : 0) |
721 (w80 && chipset_family >= ATA_100a ? XFER_UDMA_100 : 0) |
722 (w80 && chipset_family >= ATA_133a ? XFER_UDMA_133 : 0));
723
724 sis5513_tune_chipset(drive, speed);
725 681
726 if (drive->autodma && (speed & XFER_MODE) != XFER_PIO) 682 return -1;
727 return HWIF(drive)->ide_dma_on(drive);
728 return HWIF(drive)->ide_dma_off_quietly(drive);
729} 683}
730*/
731 684
732/* Chip detection and general config */ 685/* Chip detection and general config */
733static unsigned int __devinit init_chipset_sis5513 (struct pci_dev *dev, const char *name) 686static unsigned int __devinit init_chipset_sis5513 (struct pci_dev *dev, const char *name)
diff --git a/drivers/ide/pci/sl82c105.c b/drivers/ide/pci/sl82c105.c
index 170a26199050..3a8a76fc78c7 100644
--- a/drivers/ide/pci/sl82c105.c
+++ b/drivers/ide/pci/sl82c105.c
@@ -161,14 +161,14 @@ static int sl82c105_check_drive (ide_drive_t *drive)
161 if (id->field_valid & 2) { 161 if (id->field_valid & 2) {
162 if ((id->dma_mword & hwif->mwdma_mask) || 162 if ((id->dma_mword & hwif->mwdma_mask) ||
163 (id->dma_1word & hwif->swdma_mask)) 163 (id->dma_1word & hwif->swdma_mask))
164 return hwif->ide_dma_on(drive); 164 return 0;
165 } 165 }
166 166
167 if (__ide_dma_good_drive(drive)) 167 if (__ide_dma_good_drive(drive) && id->eide_dma_time < 150)
168 return hwif->ide_dma_on(drive); 168 return 0;
169 } while (0); 169 } while (0);
170 170
171 return hwif->ide_dma_off_quietly(drive); 171 return -1;
172} 172}
173 173
174/* 174/*
@@ -215,7 +215,7 @@ static int sl82c105_ide_dma_lost_irq(ide_drive_t *drive)
215 * Was DMA enabled? If so, disable it - we're resetting the 215 * Was DMA enabled? If so, disable it - we're resetting the
216 * host. The IDE layer will be handling the drive for us. 216 * host. The IDE layer will be handling the drive for us.
217 */ 217 */
218 val = hwif->INB(dma_base); 218 val = inb(dma_base);
219 if (val & 1) { 219 if (val & 1) {
220 outb(val & ~1, dma_base); 220 outb(val & ~1, dma_base);
221 printk("sl82c105: DMA was enabled\n"); 221 printk("sl82c105: DMA was enabled\n");
@@ -259,28 +259,22 @@ static int sl82c105_ide_dma_on (ide_drive_t *drive)
259{ 259{
260 DBG(("sl82c105_ide_dma_on(drive:%s)\n", drive->name)); 260 DBG(("sl82c105_ide_dma_on(drive:%s)\n", drive->name));
261 261
262 if (config_for_dma(drive)) { 262 if (config_for_dma(drive))
263 config_for_pio(drive, 4, 0, 0); 263 return 1;
264 return HWIF(drive)->ide_dma_off_quietly(drive);
265 }
266 printk(KERN_INFO "%s: DMA enabled\n", drive->name); 264 printk(KERN_INFO "%s: DMA enabled\n", drive->name);
267 return __ide_dma_on(drive); 265 return __ide_dma_on(drive);
268} 266}
269 267
270static int sl82c105_ide_dma_off_quietly (ide_drive_t *drive) 268static void sl82c105_dma_off_quietly(ide_drive_t *drive)
271{ 269{
272 u8 speed = XFER_PIO_0; 270 u8 speed = XFER_PIO_0;
273 int rc;
274
275 DBG(("sl82c105_ide_dma_off_quietly(drive:%s)\n", drive->name));
276 271
277 rc = __ide_dma_off_quietly(drive); 272 DBG(("sl82c105_dma_off_quietly(drive:%s)\n", drive->name));
273
274 ide_dma_off_quietly(drive);
278 if (drive->pio_speed) 275 if (drive->pio_speed)
279 speed = drive->pio_speed - XFER_PIO_0; 276 speed = drive->pio_speed - XFER_PIO_0;
280 config_for_pio(drive, speed, 0, 1); 277 config_for_pio(drive, speed, 0, 1);
281 drive->current_speed = drive->pio_speed;
282
283 return rc;
284} 278}
285 279
286/* 280/*
@@ -401,11 +395,9 @@ static unsigned int __devinit init_chipset_sl82c105(struct pci_dev *dev, const c
401/* 395/*
402 * Initialise the chip 396 * Initialise the chip
403 */ 397 */
404
405static void __devinit init_hwif_sl82c105(ide_hwif_t *hwif) 398static void __devinit init_hwif_sl82c105(ide_hwif_t *hwif)
406{ 399{
407 unsigned int rev; 400 unsigned int rev;
408 u8 dma_state;
409 401
410 DBG(("init_hwif_sl82c105(hwif: ide%d)\n", hwif->index)); 402 DBG(("init_hwif_sl82c105(hwif: ide%d)\n", hwif->index));
411 403
@@ -431,7 +423,6 @@ static void __devinit init_hwif_sl82c105(ide_hwif_t *hwif)
431 if (!hwif->dma_base) 423 if (!hwif->dma_base)
432 return; 424 return;
433 425
434 dma_state = hwif->INB(hwif->dma_base + 2) & ~0x60;
435 rev = sl82c105_bridge_revision(hwif->pci_dev); 426 rev = sl82c105_bridge_revision(hwif->pci_dev);
436 if (rev <= 5) { 427 if (rev <= 5) {
437 /* 428 /*
@@ -441,15 +432,12 @@ static void __devinit init_hwif_sl82c105(ide_hwif_t *hwif)
441 printk(" %s: Winbond 553 bridge revision %d, BM-DMA disabled\n", 432 printk(" %s: Winbond 553 bridge revision %d, BM-DMA disabled\n",
442 hwif->name, rev); 433 hwif->name, rev);
443 } else { 434 } else {
444 dma_state |= 0x60;
445
446 hwif->atapi_dma = 1; 435 hwif->atapi_dma = 1;
447 hwif->mwdma_mask = 0x07; 436 hwif->mwdma_mask = 0x04;
448 hwif->swdma_mask = 0x07;
449 437
450 hwif->ide_dma_check = &sl82c105_check_drive; 438 hwif->ide_dma_check = &sl82c105_check_drive;
451 hwif->ide_dma_on = &sl82c105_ide_dma_on; 439 hwif->ide_dma_on = &sl82c105_ide_dma_on;
452 hwif->ide_dma_off_quietly = &sl82c105_ide_dma_off_quietly; 440 hwif->dma_off_quietly = &sl82c105_dma_off_quietly;
453 hwif->ide_dma_lostirq = &sl82c105_ide_dma_lost_irq; 441 hwif->ide_dma_lostirq = &sl82c105_ide_dma_lost_irq;
454 hwif->dma_start = &sl82c105_ide_dma_start; 442 hwif->dma_start = &sl82c105_ide_dma_start;
455 hwif->ide_dma_timeout = &sl82c105_ide_dma_timeout; 443 hwif->ide_dma_timeout = &sl82c105_ide_dma_timeout;
@@ -462,7 +450,6 @@ static void __devinit init_hwif_sl82c105(ide_hwif_t *hwif)
462 if (hwif->mate) 450 if (hwif->mate)
463 hwif->serialized = hwif->mate->serialized = 1; 451 hwif->serialized = hwif->mate->serialized = 1;
464 } 452 }
465 hwif->OUTB(dma_state, hwif->dma_base + 2);
466} 453}
467 454
468static ide_pci_device_t sl82c105_chipset __devinitdata = { 455static ide_pci_device_t sl82c105_chipset __devinitdata = {
diff --git a/drivers/ide/pci/slc90e66.c b/drivers/ide/pci/slc90e66.c
index 2663ddbd9b67..ae7eb58d961c 100644
--- a/drivers/ide/pci/slc90e66.c
+++ b/drivers/ide/pci/slc90e66.c
@@ -179,26 +179,16 @@ static int slc90e66_config_drive_for_dma (ide_drive_t *drive)
179 179
180static int slc90e66_config_drive_xfer_rate (ide_drive_t *drive) 180static int slc90e66_config_drive_xfer_rate (ide_drive_t *drive)
181{ 181{
182 ide_hwif_t *hwif = HWIF(drive);
183 struct hd_driveid *id = drive->id;
184
185 drive->init_speed = 0; 182 drive->init_speed = 0;
186 183
187 if ((id->capability & 1) && drive->autodma) { 184 if (ide_use_dma(drive) && slc90e66_config_drive_for_dma(drive))
188 185 return 0;
189 if (ide_use_dma(drive) && slc90e66_config_drive_for_dma(drive))
190 return hwif->ide_dma_on(drive);
191 186
192 goto fast_ata_pio; 187 if (ide_use_fast_pio(drive))
188 (void)slc90e66_tune_chipset(drive, XFER_PIO_0 +
189 ide_get_best_pio_mode(drive, 255, 4, NULL));
193 190
194 } else if ((id->capability & 8) || (id->field_valid & 2)) { 191 return -1;
195fast_ata_pio:
196 (void) hwif->speedproc(drive, XFER_PIO_0 +
197 ide_get_best_pio_mode(drive, 255, 4, NULL));
198 return hwif->ide_dma_off_quietly(drive);
199 }
200 /* IORDY not supported */
201 return 0;
202} 192}
203 193
204static void __devinit init_hwif_slc90e66 (ide_hwif_t *hwif) 194static void __devinit init_hwif_slc90e66 (ide_hwif_t *hwif)
diff --git a/drivers/ide/pci/tc86c001.c b/drivers/ide/pci/tc86c001.c
index 2ad72bbda342..0b6d81d6ce48 100644
--- a/drivers/ide/pci/tc86c001.c
+++ b/drivers/ide/pci/tc86c001.c
@@ -45,7 +45,7 @@ static int tc86c001_tune_chipset(ide_drive_t *drive, u8 speed)
45 45
46 scr &= (speed < XFER_MW_DMA_0) ? 0xf8ff : 0xff0f; 46 scr &= (speed < XFER_MW_DMA_0) ? 0xf8ff : 0xff0f;
47 scr |= mode; 47 scr |= mode;
48 hwif->OUTW(scr, scr_port); 48 outw(scr, scr_port);
49 49
50 return ide_config_drive_speed(drive, speed); 50 return ide_config_drive_speed(drive, speed);
51} 51}
@@ -89,15 +89,15 @@ static int tc86c001_timer_expiry(ide_drive_t *drive)
89 "attempting recovery...\n", drive->name); 89 "attempting recovery...\n", drive->name);
90 90
91 /* Stop DMA */ 91 /* Stop DMA */
92 hwif->OUTB(dma_cmd & ~0x01, hwif->dma_command); 92 outb(dma_cmd & ~0x01, hwif->dma_command);
93 93
94 /* Setup the dummy DMA transfer */ 94 /* Setup the dummy DMA transfer */
95 hwif->OUTW(0, sc_base + 0x0a); /* Sector Count */ 95 outw(0, sc_base + 0x0a); /* Sector Count */
96 hwif->OUTW(0, twcr_port); /* Transfer Word Count 1 or 2 */ 96 outw(0, twcr_port); /* Transfer Word Count 1 or 2 */
97 97
98 /* Start the dummy DMA transfer */ 98 /* Start the dummy DMA transfer */
99 hwif->OUTB(0x00, hwif->dma_command); /* clear R_OR_WCTR for write */ 99 outb(0x00, hwif->dma_command); /* clear R_OR_WCTR for write */
100 hwif->OUTB(0x01, hwif->dma_command); /* set START_STOPBM */ 100 outb(0x01, hwif->dma_command); /* set START_STOPBM */
101 101
102 /* 102 /*
103 * If an interrupt was pending, it should come thru shortly. 103 * If an interrupt was pending, it should come thru shortly.
@@ -128,8 +128,8 @@ static void tc86c001_dma_start(ide_drive_t *drive)
128 * the appropriate system control registers for DMA to work 128 * the appropriate system control registers for DMA to work
129 * with LBA48 and ATAPI devices... 129 * with LBA48 and ATAPI devices...
130 */ 130 */
131 hwif->OUTW(nsectors, sc_base + 0x0a); /* Sector Count */ 131 outw(nsectors, sc_base + 0x0a); /* Sector Count */
132 hwif->OUTW(SECTOR_SIZE / 2, twcr_port); /* Transfer Word Count 1/2 */ 132 outw(SECTOR_SIZE / 2, twcr_port); /* Transfer Word Count 1/2 */
133 133
134 /* Install our timeout expiry hook, saving the current handler... */ 134 /* Install our timeout expiry hook, saving the current handler... */
135 ide_set_hwifdata(hwif, hwgroup->expiry); 135 ide_set_hwifdata(hwif, hwgroup->expiry);
@@ -168,7 +168,7 @@ static int tc86c001_busproc(ide_drive_t *drive, int state)
168 } 168 }
169 169
170 /* System Control 1 Register bit 11 (ATA Hard Reset) write */ 170 /* System Control 1 Register bit 11 (ATA Hard Reset) write */
171 hwif->OUTW(scr1, sc_base + 0x00); 171 outw(scr1, sc_base + 0x00);
172 return 0; 172 return 0;
173} 173}
174 174
@@ -185,23 +185,13 @@ static int config_chipset_for_dma(ide_drive_t *drive)
185 185
186static int tc86c001_config_drive_xfer_rate(ide_drive_t *drive) 186static int tc86c001_config_drive_xfer_rate(ide_drive_t *drive)
187{ 187{
188 ide_hwif_t *hwif = HWIF(drive); 188 if (ide_use_dma(drive) && config_chipset_for_dma(drive))
189 struct hd_driveid *id = drive->id; 189 return 0;
190
191 if ((id->capability & 1) && drive->autodma) {
192
193 if (ide_use_dma(drive) && config_chipset_for_dma(drive))
194 return hwif->ide_dma_on(drive);
195
196 goto fast_ata_pio;
197 190
198 } else if ((id->capability & 8) || (id->field_valid & 2)) { 191 if (ide_use_fast_pio(drive))
199fast_ata_pio:
200 tc86c001_tune_drive(drive, 255); 192 tc86c001_tune_drive(drive, 255);
201 return hwif->ide_dma_off_quietly(drive); 193
202 } 194 return -1;
203 /* IORDY not supported */
204 return 0;
205} 195}
206 196
207static void __devinit init_hwif_tc86c001(ide_hwif_t *hwif) 197static void __devinit init_hwif_tc86c001(ide_hwif_t *hwif)
@@ -210,13 +200,13 @@ static void __devinit init_hwif_tc86c001(ide_hwif_t *hwif)
210 u16 scr1 = hwif->INW(sc_base + 0x00);; 200 u16 scr1 = hwif->INW(sc_base + 0x00);;
211 201
212 /* System Control 1 Register bit 15 (Soft Reset) set */ 202 /* System Control 1 Register bit 15 (Soft Reset) set */
213 hwif->OUTW(scr1 | 0x8000, sc_base + 0x00); 203 outw(scr1 | 0x8000, sc_base + 0x00);
214 204
215 /* System Control 1 Register bit 14 (FIFO Reset) set */ 205 /* System Control 1 Register bit 14 (FIFO Reset) set */
216 hwif->OUTW(scr1 | 0x4000, sc_base + 0x00); 206 outw(scr1 | 0x4000, sc_base + 0x00);
217 207
218 /* System Control 1 Register: reset clear */ 208 /* System Control 1 Register: reset clear */
219 hwif->OUTW(scr1 & ~0xc000, sc_base + 0x00); 209 outw(scr1 & ~0xc000, sc_base + 0x00);
220 210
221 /* Store the system control register base for convenience... */ 211 /* Store the system control register base for convenience... */
222 hwif->config_data = sc_base; 212 hwif->config_data = sc_base;
@@ -234,7 +224,7 @@ static void __devinit init_hwif_tc86c001(ide_hwif_t *hwif)
234 * Sector Count Control Register bits 0 and 1 set: 224 * Sector Count Control Register bits 0 and 1 set:
235 * software sets Sector Count Register for master and slave device 225 * software sets Sector Count Register for master and slave device
236 */ 226 */
237 hwif->OUTW(0x0003, sc_base + 0x0c); 227 outw(0x0003, sc_base + 0x0c);
238 228
239 /* Sector Count Register limit */ 229 /* Sector Count Register limit */
240 hwif->rqsize = 0xffff; 230 hwif->rqsize = 0xffff;
diff --git a/drivers/ide/pci/triflex.c b/drivers/ide/pci/triflex.c
index b13cce1fd1a6..5e06179c3469 100644
--- a/drivers/ide/pci/triflex.c
+++ b/drivers/ide/pci/triflex.c
@@ -104,29 +104,21 @@ static int triflex_config_drive_for_dma(ide_drive_t *drive)
104{ 104{
105 int speed = ide_dma_speed(drive, 0); /* No ultra speeds */ 105 int speed = ide_dma_speed(drive, 0); /* No ultra speeds */
106 106
107 if (!speed) { 107 if (!speed)
108 u8 pspeed = ide_get_best_pio_mode(drive, 255, 4, NULL); 108 return 0;
109 speed = XFER_PIO_0 + pspeed; 109
110 }
111
112 (void) triflex_tune_chipset(drive, speed); 110 (void) triflex_tune_chipset(drive, speed);
113 return ide_dma_enable(drive); 111 return ide_dma_enable(drive);
114} 112}
115 113
116static int triflex_config_drive_xfer_rate(ide_drive_t *drive) 114static int triflex_config_drive_xfer_rate(ide_drive_t *drive)
117{ 115{
118 ide_hwif_t *hwif = HWIF(drive); 116 if (ide_use_dma(drive) && triflex_config_drive_for_dma(drive))
119 struct hd_driveid *id = drive->id; 117 return 0;
120 118
121 if ((id->capability & 1) && drive->autodma) { 119 triflex_tune_drive(drive, 255);
122 if (ide_use_dma(drive)) {
123 if (triflex_config_drive_for_dma(drive))
124 return hwif->ide_dma_on(drive);
125 }
126 }
127 120
128 hwif->tuneproc(drive, 255); 121 return -1;
129 return hwif->ide_dma_off_quietly(drive);
130} 122}
131 123
132static void __devinit init_hwif_triflex(ide_hwif_t *hwif) 124static void __devinit init_hwif_triflex(ide_hwif_t *hwif)
diff --git a/drivers/ide/pci/trm290.c b/drivers/ide/pci/trm290.c
index 174b88c4780e..cbb1b11119a5 100644
--- a/drivers/ide/pci/trm290.c
+++ b/drivers/ide/pci/trm290.c
@@ -157,16 +157,16 @@ static void trm290_prepare_drive (ide_drive_t *drive, unsigned int use_dma)
157 if (reg != hwif->select_data) { 157 if (reg != hwif->select_data) {
158 hwif->select_data = reg; 158 hwif->select_data = reg;
159 /* set PIO/DMA */ 159 /* set PIO/DMA */
160 hwif->OUTB(0x51|(hwif->channel<<3), hwif->config_data+1); 160 outb(0x51 | (hwif->channel << 3), hwif->config_data + 1);
161 hwif->OUTW(reg & 0xff, hwif->config_data); 161 outw(reg & 0xff, hwif->config_data);
162 } 162 }
163 163
164 /* enable IRQ if not probing */ 164 /* enable IRQ if not probing */
165 if (drive->present) { 165 if (drive->present) {
166 reg = hwif->INW(hwif->config_data + 3); 166 reg = inw(hwif->config_data + 3);
167 reg &= 0x13; 167 reg &= 0x13;
168 reg &= ~(1 << hwif->channel); 168 reg &= ~(1 << hwif->channel);
169 hwif->OUTW(reg, hwif->config_data+3); 169 outw(reg, hwif->config_data + 3);
170 } 170 }
171 171
172 local_irq_restore(flags); 172 local_irq_restore(flags);
@@ -177,15 +177,12 @@ static void trm290_selectproc (ide_drive_t *drive)
177 trm290_prepare_drive(drive, drive->using_dma); 177 trm290_prepare_drive(drive, drive->using_dma);
178} 178}
179 179
180#ifdef CONFIG_BLK_DEV_IDEDMA
181static void trm290_ide_dma_exec_cmd(ide_drive_t *drive, u8 command) 180static void trm290_ide_dma_exec_cmd(ide_drive_t *drive, u8 command)
182{ 181{
183 ide_hwif_t *hwif = HWIF(drive);
184
185 BUG_ON(HWGROUP(drive)->handler != NULL); /* paranoia check */ 182 BUG_ON(HWGROUP(drive)->handler != NULL); /* paranoia check */
186 ide_set_handler(drive, &ide_dma_intr, WAIT_CMD, NULL); 183 ide_set_handler(drive, &ide_dma_intr, WAIT_CMD, NULL);
187 /* issue cmd to drive */ 184 /* issue cmd to drive */
188 hwif->OUTB(command, IDE_COMMAND_REG); 185 outb(command, IDE_COMMAND_REG);
189} 186}
190 187
191static int trm290_ide_dma_setup(ide_drive_t *drive) 188static int trm290_ide_dma_setup(ide_drive_t *drive)
@@ -211,10 +208,10 @@ static int trm290_ide_dma_setup(ide_drive_t *drive)
211 } 208 }
212 /* select DMA xfer */ 209 /* select DMA xfer */
213 trm290_prepare_drive(drive, 1); 210 trm290_prepare_drive(drive, 1);
214 hwif->OUTL(hwif->dmatable_dma|rw, hwif->dma_command); 211 outl(hwif->dmatable_dma | rw, hwif->dma_command);
215 drive->waiting_for_dma = 1; 212 drive->waiting_for_dma = 1;
216 /* start DMA */ 213 /* start DMA */
217 hwif->OUTW((count * 2) - 1, hwif->dma_status); 214 outw((count * 2) - 1, hwif->dma_status);
218 return 0; 215 return 0;
219} 216}
220 217
@@ -230,7 +227,7 @@ static int trm290_ide_dma_end (ide_drive_t *drive)
230 drive->waiting_for_dma = 0; 227 drive->waiting_for_dma = 0;
231 /* purge DMA mappings */ 228 /* purge DMA mappings */
232 ide_destroy_dmatable(drive); 229 ide_destroy_dmatable(drive);
233 status = hwif->INW(hwif->dma_status); 230 status = inw(hwif->dma_status);
234 return (status != 0x00ff); 231 return (status != 0x00ff);
235} 232}
236 233
@@ -239,10 +236,9 @@ static int trm290_ide_dma_test_irq (ide_drive_t *drive)
239 ide_hwif_t *hwif = HWIF(drive); 236 ide_hwif_t *hwif = HWIF(drive);
240 u16 status = 0; 237 u16 status = 0;
241 238
242 status = hwif->INW(hwif->dma_status); 239 status = inw(hwif->dma_status);
243 return (status == 0x00ff); 240 return (status == 0x00ff);
244} 241}
245#endif /* CONFIG_BLK_DEV_IDEDMA */
246 242
247/* 243/*
248 * Invoked from ide-dma.c at boot time. 244 * Invoked from ide-dma.c at boot time.
@@ -269,15 +265,15 @@ static void __devinit init_hwif_trm290(ide_hwif_t *hwif)
269 265
270 local_irq_save(flags); 266 local_irq_save(flags);
271 /* put config reg into first byte of hwif->select_data */ 267 /* put config reg into first byte of hwif->select_data */
272 hwif->OUTB(0x51|(hwif->channel<<3), hwif->config_data+1); 268 outb(0x51 | (hwif->channel << 3), hwif->config_data + 1);
273 /* select PIO as default */ 269 /* select PIO as default */
274 hwif->select_data = 0x21; 270 hwif->select_data = 0x21;
275 hwif->OUTB(hwif->select_data, hwif->config_data); 271 outb(hwif->select_data, hwif->config_data);
276 /* get IRQ info */ 272 /* get IRQ info */
277 reg = hwif->INB(hwif->config_data+3); 273 reg = inb(hwif->config_data + 3);
278 /* mask IRQs for both ports */ 274 /* mask IRQs for both ports */
279 reg = (reg & 0x10) | 0x03; 275 reg = (reg & 0x10) | 0x03;
280 hwif->OUTB(reg, hwif->config_data+3); 276 outb(reg, hwif->config_data + 3);
281 local_irq_restore(flags); 277 local_irq_restore(flags);
282 278
283 if ((reg & 0x10)) 279 if ((reg & 0x10))
@@ -289,13 +285,11 @@ static void __devinit init_hwif_trm290(ide_hwif_t *hwif)
289 285
290 ide_setup_dma(hwif, (hwif->config_data + 4) ^ (hwif->channel ? 0x0080 : 0x0000), 3); 286 ide_setup_dma(hwif, (hwif->config_data + 4) ^ (hwif->channel ? 0x0080 : 0x0000), 3);
291 287
292#ifdef CONFIG_BLK_DEV_IDEDMA
293 hwif->dma_setup = &trm290_ide_dma_setup; 288 hwif->dma_setup = &trm290_ide_dma_setup;
294 hwif->dma_exec_cmd = &trm290_ide_dma_exec_cmd; 289 hwif->dma_exec_cmd = &trm290_ide_dma_exec_cmd;
295 hwif->dma_start = &trm290_ide_dma_start; 290 hwif->dma_start = &trm290_ide_dma_start;
296 hwif->ide_dma_end = &trm290_ide_dma_end; 291 hwif->ide_dma_end = &trm290_ide_dma_end;
297 hwif->ide_dma_test_irq = &trm290_ide_dma_test_irq; 292 hwif->ide_dma_test_irq = &trm290_ide_dma_test_irq;
298#endif /* CONFIG_BLK_DEV_IDEDMA */
299 293
300 hwif->selectproc = &trm290_selectproc; 294 hwif->selectproc = &trm290_selectproc;
301 hwif->autodma = 0; /* play it safe for now */ 295 hwif->autodma = 0; /* play it safe for now */
@@ -312,16 +306,16 @@ static void __devinit init_hwif_trm290(ide_hwif_t *hwif)
312 static u16 next_offset = 0; 306 static u16 next_offset = 0;
313 u8 old_mask; 307 u8 old_mask;
314 308
315 hwif->OUTB(0x54|(hwif->channel<<3), hwif->config_data+1); 309 outb(0x54 | (hwif->channel << 3), hwif->config_data + 1);
316 old = hwif->INW(hwif->config_data); 310 old = inw(hwif->config_data);
317 old &= ~1; 311 old &= ~1;
318 old_mask = hwif->INB(old+2); 312 old_mask = inb(old + 2);
319 if (old != compat && old_mask == 0xff) { 313 if (old != compat && old_mask == 0xff) {
320 /* leave lower 10 bits untouched */ 314 /* leave lower 10 bits untouched */
321 compat += (next_offset += 0x400); 315 compat += (next_offset += 0x400);
322 hwif->io_ports[IDE_CONTROL_OFFSET] = compat + 2; 316 hwif->io_ports[IDE_CONTROL_OFFSET] = compat + 2;
323 hwif->OUTW(compat|1, hwif->config_data); 317 outw(compat | 1, hwif->config_data);
324 new = hwif->INW(hwif->config_data); 318 new = inw(hwif->config_data);
325 printk(KERN_INFO "%s: control basereg workaround: " 319 printk(KERN_INFO "%s: control basereg workaround: "
326 "old=0x%04x, new=0x%04x\n", 320 "old=0x%04x, new=0x%04x\n",
327 hwif->name, old, new & ~1); 321 hwif->name, old, new & ~1);
diff --git a/drivers/ide/pci/via82cxxx.c b/drivers/ide/pci/via82cxxx.c
index 6fb6e50b8231..a508550c4095 100644
--- a/drivers/ide/pci/via82cxxx.c
+++ b/drivers/ide/pci/via82cxxx.c
@@ -240,8 +240,9 @@ static int via82cxxx_ide_dma_check (ide_drive_t *drive)
240 via_set_drive(drive, speed); 240 via_set_drive(drive, speed);
241 241
242 if (drive->autodma && (speed & XFER_MODE) != XFER_PIO) 242 if (drive->autodma && (speed & XFER_MODE) != XFER_PIO)
243 return hwif->ide_dma_on(drive); 243 return 0;
244 return hwif->ide_dma_off_quietly(drive); 244
245 return -1;
245} 246}
246 247
247static struct via_isa_bridge *via_config_find(struct pci_dev **isa) 248static struct via_isa_bridge *via_config_find(struct pci_dev **isa)
diff --git a/drivers/ide/ppc/pmac.c b/drivers/ide/ppc/pmac.c
index d8ea23710bf0..395d35253d5d 100644
--- a/drivers/ide/ppc/pmac.c
+++ b/drivers/ide/ppc/pmac.c
@@ -1237,7 +1237,7 @@ pmac_ide_setup_device(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif)
1237 hwif->OUTBSYNC = pmac_outbsync; 1237 hwif->OUTBSYNC = pmac_outbsync;
1238 1238
1239 /* Tell common code _not_ to mess with resources */ 1239 /* Tell common code _not_ to mess with resources */
1240 hwif->mmio = 2; 1240 hwif->mmio = 1;
1241 hwif->hwif_data = pmif; 1241 hwif->hwif_data = pmif;
1242 pmac_ide_init_hwif_ports(&hwif->hw, pmif->regbase, 0, &hwif->irq); 1242 pmac_ide_init_hwif_ports(&hwif->hw, pmif->regbase, 0, &hwif->irq);
1243 memcpy(hwif->io_ports, hwif->hw.io_ports, sizeof(hwif->io_ports)); 1243 memcpy(hwif->io_ports, hwif->hw.io_ports, sizeof(hwif->io_ports));
@@ -1979,16 +1979,12 @@ pmac_ide_dma_test_irq (ide_drive_t *drive)
1979 return 1; 1979 return 1;
1980} 1980}
1981 1981
1982static int 1982static void pmac_ide_dma_host_off(ide_drive_t *drive)
1983pmac_ide_dma_host_off (ide_drive_t *drive)
1984{ 1983{
1985 return 0;
1986} 1984}
1987 1985
1988static int 1986static int pmac_ide_dma_host_on(ide_drive_t *drive)
1989pmac_ide_dma_host_on (ide_drive_t *drive)
1990{ 1987{
1991 return 0;
1992} 1988}
1993 1989
1994static int 1990static int
@@ -2034,7 +2030,7 @@ pmac_ide_setup_dma(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif)
2034 return; 2030 return;
2035 } 2031 }
2036 2032
2037 hwif->ide_dma_off_quietly = &__ide_dma_off_quietly; 2033 hwif->dma_off_quietly = &ide_dma_off_quietly;
2038 hwif->ide_dma_on = &__ide_dma_on; 2034 hwif->ide_dma_on = &__ide_dma_on;
2039 hwif->ide_dma_check = &pmac_ide_dma_check; 2035 hwif->ide_dma_check = &pmac_ide_dma_check;
2040 hwif->dma_setup = &pmac_ide_dma_setup; 2036 hwif->dma_setup = &pmac_ide_dma_setup;
@@ -2042,8 +2038,8 @@ pmac_ide_setup_dma(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif)
2042 hwif->dma_start = &pmac_ide_dma_start; 2038 hwif->dma_start = &pmac_ide_dma_start;
2043 hwif->ide_dma_end = &pmac_ide_dma_end; 2039 hwif->ide_dma_end = &pmac_ide_dma_end;
2044 hwif->ide_dma_test_irq = &pmac_ide_dma_test_irq; 2040 hwif->ide_dma_test_irq = &pmac_ide_dma_test_irq;
2045 hwif->ide_dma_host_off = &pmac_ide_dma_host_off; 2041 hwif->dma_host_off = &pmac_ide_dma_host_off;
2046 hwif->ide_dma_host_on = &pmac_ide_dma_host_on; 2042 hwif->dma_host_on = &pmac_ide_dma_host_on;
2047 hwif->ide_dma_timeout = &__ide_dma_timeout; 2043 hwif->ide_dma_timeout = &__ide_dma_timeout;
2048 hwif->ide_dma_lostirq = &pmac_ide_dma_lostirq; 2044 hwif->ide_dma_lostirq = &pmac_ide_dma_lostirq;
2049 2045
diff --git a/drivers/ide/ppc/scc_pata.c b/drivers/ide/ppc/scc_pata.c
new file mode 100644
index 000000000000..de64b022478b
--- /dev/null
+++ b/drivers/ide/ppc/scc_pata.c
@@ -0,0 +1,831 @@
1/*
2 * Support for IDE interfaces on Celleb platform
3 *
4 * (C) Copyright 2006 TOSHIBA CORPORATION
5 *
6 * This code is based on drivers/ide/pci/siimage.c:
7 * Copyright (C) 2001-2002 Andre Hedrick <andre@linux-ide.org>
8 * Copyright (C) 2003 Red Hat <alan@redhat.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 */
24
25#include <linux/types.h>
26#include <linux/module.h>
27#include <linux/pci.h>
28#include <linux/delay.h>
29#include <linux/hdreg.h>
30#include <linux/ide.h>
31#include <linux/init.h>
32
33#define PCI_DEVICE_ID_TOSHIBA_SCC_ATA 0x01b4
34
35#define SCC_PATA_NAME "scc IDE"
36
37#define TDVHSEL_MASTER 0x00000001
38#define TDVHSEL_SLAVE 0x00000004
39
40#define MODE_JCUSFEN 0x00000080
41
42#define CCKCTRL_ATARESET 0x00040000
43#define CCKCTRL_BUFCNT 0x00020000
44#define CCKCTRL_CRST 0x00010000
45#define CCKCTRL_OCLKEN 0x00000100
46#define CCKCTRL_ATACLKOEN 0x00000002
47#define CCKCTRL_LCLKEN 0x00000001
48
49#define QCHCD_IOS_SS 0x00000001
50
51#define QCHSD_STPDIAG 0x00020000
52
53#define INTMASK_MSK 0xD1000012
54#define INTSTS_SERROR 0x80000000
55#define INTSTS_PRERR 0x40000000
56#define INTSTS_RERR 0x10000000
57#define INTSTS_ICERR 0x01000000
58#define INTSTS_BMSINT 0x00000010
59#define INTSTS_BMHE 0x00000008
60#define INTSTS_IOIRQS 0x00000004
61#define INTSTS_INTRQ 0x00000002
62#define INTSTS_ACTEINT 0x00000001
63
64#define ECMODE_VALUE 0x01
65
66static struct scc_ports {
67 unsigned long ctl, dma;
68 unsigned char hwif_id; /* for removing hwif from system */
69} scc_ports[MAX_HWIFS];
70
71/* PIO transfer mode table */
72/* JCHST */
73static unsigned long JCHSTtbl[2][7] = {
74 {0x0E, 0x05, 0x02, 0x03, 0x02, 0x00, 0x00}, /* 100MHz */
75 {0x13, 0x07, 0x04, 0x04, 0x03, 0x00, 0x00} /* 133MHz */
76};
77
78/* JCHHT */
79static unsigned long JCHHTtbl[2][7] = {
80 {0x0E, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00}, /* 100MHz */
81 {0x13, 0x03, 0x03, 0x03, 0x03, 0x00, 0x00} /* 133MHz */
82};
83
84/* JCHCT */
85static unsigned long JCHCTtbl[2][7] = {
86 {0x1D, 0x1D, 0x1C, 0x0B, 0x06, 0x00, 0x00}, /* 100MHz */
87 {0x27, 0x26, 0x26, 0x0E, 0x09, 0x00, 0x00} /* 133MHz */
88};
89
90
91/* DMA transfer mode table */
92/* JCHDCTM/JCHDCTS */
93static unsigned long JCHDCTxtbl[2][7] = {
94 {0x0A, 0x06, 0x04, 0x03, 0x01, 0x00, 0x00}, /* 100MHz */
95 {0x0E, 0x09, 0x06, 0x04, 0x02, 0x01, 0x00} /* 133MHz */
96};
97
98/* JCSTWTM/JCSTWTS */
99static unsigned long JCSTWTxtbl[2][7] = {
100 {0x06, 0x04, 0x03, 0x02, 0x02, 0x02, 0x00}, /* 100MHz */
101 {0x09, 0x06, 0x04, 0x02, 0x02, 0x02, 0x02} /* 133MHz */
102};
103
104/* JCTSS */
105static unsigned long JCTSStbl[2][7] = {
106 {0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x00}, /* 100MHz */
107 {0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05} /* 133MHz */
108};
109
110/* JCENVT */
111static unsigned long JCENVTtbl[2][7] = {
112 {0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00}, /* 100MHz */
113 {0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02} /* 133MHz */
114};
115
116/* JCACTSELS/JCACTSELM */
117static unsigned long JCACTSELtbl[2][7] = {
118 {0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00}, /* 100MHz */
119 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01} /* 133MHz */
120};
121
122
123static u8 scc_ide_inb(unsigned long port)
124{
125 u32 data = in_be32((void*)port);
126 return (u8)data;
127}
128
129static u16 scc_ide_inw(unsigned long port)
130{
131 u32 data = in_be32((void*)port);
132 return (u16)data;
133}
134
135static void scc_ide_insw(unsigned long port, void *addr, u32 count)
136{
137 u16 *ptr = (u16 *)addr;
138 while (count--) {
139 *ptr++ = le16_to_cpu(in_be32((void*)port));
140 }
141}
142
143static void scc_ide_insl(unsigned long port, void *addr, u32 count)
144{
145 u16 *ptr = (u16 *)addr;
146 while (count--) {
147 *ptr++ = le16_to_cpu(in_be32((void*)port));
148 *ptr++ = le16_to_cpu(in_be32((void*)port));
149 }
150}
151
152static void scc_ide_outb(u8 addr, unsigned long port)
153{
154 out_be32((void*)port, addr);
155}
156
157static void scc_ide_outw(u16 addr, unsigned long port)
158{
159 out_be32((void*)port, addr);
160}
161
162static void
163scc_ide_outbsync(ide_drive_t * drive, u8 addr, unsigned long port)
164{
165 ide_hwif_t *hwif = HWIF(drive);
166
167 out_be32((void*)port, addr);
168 __asm__ __volatile__("eieio":::"memory");
169 in_be32((void*)(hwif->dma_base + 0x01c));
170 __asm__ __volatile__("eieio":::"memory");
171}
172
173static void
174scc_ide_outsw(unsigned long port, void *addr, u32 count)
175{
176 u16 *ptr = (u16 *)addr;
177 while (count--) {
178 out_be32((void*)port, cpu_to_le16(*ptr++));
179 }
180}
181
182static void
183scc_ide_outsl(unsigned long port, void *addr, u32 count)
184{
185 u16 *ptr = (u16 *)addr;
186 while (count--) {
187 out_be32((void*)port, cpu_to_le16(*ptr++));
188 out_be32((void*)port, cpu_to_le16(*ptr++));
189 }
190}
191
192/**
193 * scc_ratemask - Compute available modes
194 * @drive: IDE drive
195 *
196 * Compute the available speeds for the devices on the interface.
197 * Enforce UDMA33 as a limit if there is no 80pin cable present.
198 */
199
200static u8 scc_ratemask(ide_drive_t *drive)
201{
202 u8 mode = 4;
203
204 if (!eighty_ninty_three(drive))
205 mode = min(mode, (u8)1);
206 return mode;
207}
208
209/**
210 * scc_tuneproc - tune a drive PIO mode
211 * @drive: drive to tune
212 * @mode_wanted: the target operating mode
213 *
214 * Load the timing settings for this device mode into the
215 * controller.
216 */
217
218static void scc_tuneproc(ide_drive_t *drive, byte mode_wanted)
219{
220 ide_hwif_t *hwif = HWIF(drive);
221 struct scc_ports *ports = ide_get_hwifdata(hwif);
222 unsigned long ctl_base = ports->ctl;
223 unsigned long cckctrl_port = ctl_base + 0xff0;
224 unsigned long piosht_port = ctl_base + 0x000;
225 unsigned long pioct_port = ctl_base + 0x004;
226 unsigned long reg;
227 unsigned char speed = XFER_PIO_0;
228 int offset;
229
230 mode_wanted = ide_get_best_pio_mode(drive, mode_wanted, 4, NULL);
231 switch (mode_wanted) {
232 case 4:
233 speed = XFER_PIO_4;
234 break;
235 case 3:
236 speed = XFER_PIO_3;
237 break;
238 case 2:
239 speed = XFER_PIO_2;
240 break;
241 case 1:
242 speed = XFER_PIO_1;
243 break;
244 case 0:
245 default:
246 speed = XFER_PIO_0;
247 break;
248 }
249
250 reg = in_be32((void __iomem *)cckctrl_port);
251 if (reg & CCKCTRL_ATACLKOEN) {
252 offset = 1; /* 133MHz */
253 } else {
254 offset = 0; /* 100MHz */
255 }
256 reg = JCHSTtbl[offset][mode_wanted] << 16 | JCHHTtbl[offset][mode_wanted];
257 out_be32((void __iomem *)piosht_port, reg);
258 reg = JCHCTtbl[offset][mode_wanted];
259 out_be32((void __iomem *)pioct_port, reg);
260
261 ide_config_drive_speed(drive, speed);
262}
263
264/**
265 * scc_tune_chipset - tune a drive DMA mode
266 * @drive: Drive to set up
267 * @xferspeed: speed we want to achieve
268 *
269 * Load the timing settings for this device mode into the
270 * controller.
271 */
272
273static int scc_tune_chipset(ide_drive_t *drive, byte xferspeed)
274{
275 ide_hwif_t *hwif = HWIF(drive);
276 u8 speed = ide_rate_filter(scc_ratemask(drive), xferspeed);
277 struct scc_ports *ports = ide_get_hwifdata(hwif);
278 unsigned long ctl_base = ports->ctl;
279 unsigned long cckctrl_port = ctl_base + 0xff0;
280 unsigned long mdmact_port = ctl_base + 0x008;
281 unsigned long mcrcst_port = ctl_base + 0x00c;
282 unsigned long sdmact_port = ctl_base + 0x010;
283 unsigned long scrcst_port = ctl_base + 0x014;
284 unsigned long udenvt_port = ctl_base + 0x018;
285 unsigned long tdvhsel_port = ctl_base + 0x020;
286 int is_slave = (&hwif->drives[1] == drive);
287 int offset, idx;
288 unsigned long reg;
289 unsigned long jcactsel;
290
291 reg = in_be32((void __iomem *)cckctrl_port);
292 if (reg & CCKCTRL_ATACLKOEN) {
293 offset = 1; /* 133MHz */
294 } else {
295 offset = 0; /* 100MHz */
296 }
297
298 switch (speed) {
299 case XFER_UDMA_6:
300 idx = 6;
301 break;
302 case XFER_UDMA_5:
303 idx = 5;
304 break;
305 case XFER_UDMA_4:
306 idx = 4;
307 break;
308 case XFER_UDMA_3:
309 idx = 3;
310 break;
311 case XFER_UDMA_2:
312 idx = 2;
313 break;
314 case XFER_UDMA_1:
315 idx = 1;
316 break;
317 case XFER_UDMA_0:
318 idx = 0;
319 break;
320 default:
321 return 1;
322 }
323
324 jcactsel = JCACTSELtbl[offset][idx];
325 if (is_slave) {
326 out_be32((void __iomem *)sdmact_port, JCHDCTxtbl[offset][idx]);
327 out_be32((void __iomem *)scrcst_port, JCSTWTxtbl[offset][idx]);
328 jcactsel = jcactsel << 2;
329 out_be32((void __iomem *)tdvhsel_port, (in_be32((void __iomem *)tdvhsel_port) & ~TDVHSEL_SLAVE) | jcactsel);
330 } else {
331 out_be32((void __iomem *)mdmact_port, JCHDCTxtbl[offset][idx]);
332 out_be32((void __iomem *)mcrcst_port, JCSTWTxtbl[offset][idx]);
333 out_be32((void __iomem *)tdvhsel_port, (in_be32((void __iomem *)tdvhsel_port) & ~TDVHSEL_MASTER) | jcactsel);
334 }
335 reg = JCTSStbl[offset][idx] << 16 | JCENVTtbl[offset][idx];
336 out_be32((void __iomem *)udenvt_port, reg);
337
338 return ide_config_drive_speed(drive, speed);
339}
340
341/**
342 * scc_config_chipset_for_dma - configure for DMA
343 * @drive: drive to configure
344 *
345 * Called by scc_config_drive_for_dma().
346 */
347
348static int scc_config_chipset_for_dma(ide_drive_t *drive)
349{
350 u8 speed = ide_dma_speed(drive, scc_ratemask(drive));
351
352 if (!speed)
353 return 0;
354
355 if (scc_tune_chipset(drive, speed))
356 return 0;
357
358 return ide_dma_enable(drive);
359}
360
361/**
362 * scc_configure_drive_for_dma - set up for DMA transfers
363 * @drive: drive we are going to set up
364 *
365 * Set up the drive for DMA, tune the controller and drive as
366 * required.
367 * If the drive isn't suitable for DMA or we hit other problems
368 * then we will drop down to PIO and set up PIO appropriately.
369 * (return 1)
370 */
371
372static int scc_config_drive_for_dma(ide_drive_t *drive)
373{
374 if (ide_use_dma(drive) && scc_config_chipset_for_dma(drive))
375 return 0;
376
377 if (ide_use_fast_pio(drive))
378 scc_tuneproc(drive, 4);
379
380 return -1;
381}
382
383/**
384 * scc_ide_dma_setup - begin a DMA phase
385 * @drive: target device
386 *
387 * Build an IDE DMA PRD (IDE speak for scatter gather table)
388 * and then set up the DMA transfer registers.
389 *
390 * Returns 0 on success. If a PIO fallback is required then 1
391 * is returned.
392 */
393
394static int scc_dma_setup(ide_drive_t *drive)
395{
396 ide_hwif_t *hwif = drive->hwif;
397 struct request *rq = HWGROUP(drive)->rq;
398 unsigned int reading;
399 u8 dma_stat;
400
401 if (rq_data_dir(rq))
402 reading = 0;
403 else
404 reading = 1 << 3;
405
406 /* fall back to pio! */
407 if (!ide_build_dmatable(drive, rq)) {
408 ide_map_sg(drive, rq);
409 return 1;
410 }
411
412 /* PRD table */
413 out_be32((void __iomem *)hwif->dma_prdtable, hwif->dmatable_dma);
414
415 /* specify r/w */
416 out_be32((void __iomem *)hwif->dma_command, reading);
417
418 /* read dma_status for INTR & ERROR flags */
419 dma_stat = in_be32((void __iomem *)hwif->dma_status);
420
421 /* clear INTR & ERROR flags */
422 out_be32((void __iomem *)hwif->dma_status, dma_stat|6);
423 drive->waiting_for_dma = 1;
424 return 0;
425}
426
427
428/**
429 * scc_ide_dma_end - Stop DMA
430 * @drive: IDE drive
431 *
432 * Check and clear INT Status register.
433 * Then call __ide_dma_end().
434 */
435
436static int scc_ide_dma_end(ide_drive_t * drive)
437{
438 ide_hwif_t *hwif = HWIF(drive);
439 unsigned long intsts_port = hwif->dma_base + 0x014;
440 u32 reg;
441
442 while (1) {
443 reg = in_be32((void __iomem *)intsts_port);
444
445 if (reg & INTSTS_SERROR) {
446 printk(KERN_WARNING "%s: SERROR\n", SCC_PATA_NAME);
447 out_be32((void __iomem *)intsts_port, INTSTS_SERROR|INTSTS_BMSINT);
448
449 out_be32((void __iomem *)hwif->dma_command, in_be32((void __iomem *)hwif->dma_command) & ~QCHCD_IOS_SS);
450 continue;
451 }
452
453 if (reg & INTSTS_PRERR) {
454 u32 maea0, maec0;
455 unsigned long ctl_base = hwif->config_data;
456
457 maea0 = in_be32((void __iomem *)(ctl_base + 0xF50));
458 maec0 = in_be32((void __iomem *)(ctl_base + 0xF54));
459
460 printk(KERN_WARNING "%s: PRERR [addr:%x cmd:%x]\n", SCC_PATA_NAME, maea0, maec0);
461
462 out_be32((void __iomem *)intsts_port, INTSTS_PRERR|INTSTS_BMSINT);
463
464 out_be32((void __iomem *)hwif->dma_command, in_be32((void __iomem *)hwif->dma_command) & ~QCHCD_IOS_SS);
465 continue;
466 }
467
468 if (reg & INTSTS_RERR) {
469 printk(KERN_WARNING "%s: Response Error\n", SCC_PATA_NAME);
470 out_be32((void __iomem *)intsts_port, INTSTS_RERR|INTSTS_BMSINT);
471
472 out_be32((void __iomem *)hwif->dma_command, in_be32((void __iomem *)hwif->dma_command) & ~QCHCD_IOS_SS);
473 continue;
474 }
475
476 if (reg & INTSTS_ICERR) {
477 out_be32((void __iomem *)hwif->dma_command, in_be32((void __iomem *)hwif->dma_command) & ~QCHCD_IOS_SS);
478
479 printk(KERN_WARNING "%s: Illegal Configuration\n", SCC_PATA_NAME);
480 out_be32((void __iomem *)intsts_port, INTSTS_ICERR|INTSTS_BMSINT);
481 continue;
482 }
483
484 if (reg & INTSTS_BMSINT) {
485 printk(KERN_WARNING "%s: Internal Bus Error\n", SCC_PATA_NAME);
486 out_be32((void __iomem *)intsts_port, INTSTS_BMSINT);
487
488 ide_do_reset(drive);
489 continue;
490 }
491
492 if (reg & INTSTS_BMHE) {
493 out_be32((void __iomem *)intsts_port, INTSTS_BMHE);
494 continue;
495 }
496
497 if (reg & INTSTS_ACTEINT) {
498 out_be32((void __iomem *)intsts_port, INTSTS_ACTEINT);
499 continue;
500 }
501
502 if (reg & INTSTS_IOIRQS) {
503 out_be32((void __iomem *)intsts_port, INTSTS_IOIRQS);
504 continue;
505 }
506 break;
507 }
508
509 return __ide_dma_end(drive);
510}
511
512/**
513 * setup_mmio_scc - map CTRL/BMID region
514 * @dev: PCI device we are configuring
515 * @name: device name
516 *
517 */
518
519static int setup_mmio_scc (struct pci_dev *dev, const char *name)
520{
521 unsigned long ctl_base = pci_resource_start(dev, 0);
522 unsigned long dma_base = pci_resource_start(dev, 1);
523 unsigned long ctl_size = pci_resource_len(dev, 0);
524 unsigned long dma_size = pci_resource_len(dev, 1);
525 void *ctl_addr;
526 void *dma_addr;
527 int i;
528
529 for (i = 0; i < MAX_HWIFS; i++) {
530 if (scc_ports[i].ctl == 0)
531 break;
532 }
533 if (i >= MAX_HWIFS)
534 return -ENOMEM;
535
536 if (!request_mem_region(ctl_base, ctl_size, name)) {
537 printk(KERN_WARNING "%s: IDE controller MMIO ports not available.\n", SCC_PATA_NAME);
538 goto fail_0;
539 }
540
541 if (!request_mem_region(dma_base, dma_size, name)) {
542 printk(KERN_WARNING "%s: IDE controller MMIO ports not available.\n", SCC_PATA_NAME);
543 goto fail_1;
544 }
545
546 if ((ctl_addr = ioremap(ctl_base, ctl_size)) == NULL)
547 goto fail_2;
548
549 if ((dma_addr = ioremap(dma_base, dma_size)) == NULL)
550 goto fail_3;
551
552 pci_set_master(dev);
553 scc_ports[i].ctl = (unsigned long)ctl_addr;
554 scc_ports[i].dma = (unsigned long)dma_addr;
555 pci_set_drvdata(dev, (void *) &scc_ports[i]);
556
557 return 1;
558
559 fail_3:
560 iounmap(ctl_addr);
561 fail_2:
562 release_mem_region(dma_base, dma_size);
563 fail_1:
564 release_mem_region(ctl_base, ctl_size);
565 fail_0:
566 return -ENOMEM;
567}
568
569/**
570 * init_setup_scc - set up an SCC PATA Controller
571 * @dev: PCI device
572 * @d: IDE PCI device
573 *
574 * Perform the initial set up for this device.
575 */
576
577static int __devinit init_setup_scc(struct pci_dev *dev, ide_pci_device_t *d)
578{
579 unsigned long ctl_base;
580 unsigned long dma_base;
581 unsigned long cckctrl_port;
582 unsigned long intmask_port;
583 unsigned long mode_port;
584 unsigned long ecmode_port;
585 unsigned long dma_status_port;
586 u32 reg = 0;
587 struct scc_ports *ports;
588 int rc;
589
590 rc = setup_mmio_scc(dev, d->name);
591 if (rc < 0) {
592 return rc;
593 }
594
595 ports = pci_get_drvdata(dev);
596 ctl_base = ports->ctl;
597 dma_base = ports->dma;
598 cckctrl_port = ctl_base + 0xff0;
599 intmask_port = dma_base + 0x010;
600 mode_port = ctl_base + 0x024;
601 ecmode_port = ctl_base + 0xf00;
602 dma_status_port = dma_base + 0x004;
603
604 /* controller initialization */
605 reg = 0;
606 out_be32((void*)cckctrl_port, reg);
607 reg |= CCKCTRL_ATACLKOEN;
608 out_be32((void*)cckctrl_port, reg);
609 reg |= CCKCTRL_LCLKEN | CCKCTRL_OCLKEN;
610 out_be32((void*)cckctrl_port, reg);
611 reg |= CCKCTRL_CRST;
612 out_be32((void*)cckctrl_port, reg);
613
614 for (;;) {
615 reg = in_be32((void*)cckctrl_port);
616 if (reg & CCKCTRL_CRST)
617 break;
618 udelay(5000);
619 }
620
621 reg |= CCKCTRL_ATARESET;
622 out_be32((void*)cckctrl_port, reg);
623
624 out_be32((void*)ecmode_port, ECMODE_VALUE);
625 out_be32((void*)mode_port, MODE_JCUSFEN);
626 out_be32((void*)intmask_port, INTMASK_MSK);
627
628 return ide_setup_pci_device(dev, d);
629}
630
631/**
632 * init_mmio_iops_scc - set up the iops for MMIO
633 * @hwif: interface to set up
634 *
635 */
636
637static void __devinit init_mmio_iops_scc(ide_hwif_t *hwif)
638{
639 struct pci_dev *dev = hwif->pci_dev;
640 struct scc_ports *ports = pci_get_drvdata(dev);
641 unsigned long dma_base = ports->dma;
642
643 ide_set_hwifdata(hwif, ports);
644
645 hwif->INB = scc_ide_inb;
646 hwif->INW = scc_ide_inw;
647 hwif->INSW = scc_ide_insw;
648 hwif->INSL = scc_ide_insl;
649 hwif->OUTB = scc_ide_outb;
650 hwif->OUTBSYNC = scc_ide_outbsync;
651 hwif->OUTW = scc_ide_outw;
652 hwif->OUTSW = scc_ide_outsw;
653 hwif->OUTSL = scc_ide_outsl;
654
655 hwif->io_ports[IDE_DATA_OFFSET] = dma_base + 0x20;
656 hwif->io_ports[IDE_ERROR_OFFSET] = dma_base + 0x24;
657 hwif->io_ports[IDE_NSECTOR_OFFSET] = dma_base + 0x28;
658 hwif->io_ports[IDE_SECTOR_OFFSET] = dma_base + 0x2c;
659 hwif->io_ports[IDE_LCYL_OFFSET] = dma_base + 0x30;
660 hwif->io_ports[IDE_HCYL_OFFSET] = dma_base + 0x34;
661 hwif->io_ports[IDE_SELECT_OFFSET] = dma_base + 0x38;
662 hwif->io_ports[IDE_STATUS_OFFSET] = dma_base + 0x3c;
663 hwif->io_ports[IDE_CONTROL_OFFSET] = dma_base + 0x40;
664
665 hwif->irq = hwif->pci_dev->irq;
666 hwif->dma_base = dma_base;
667 hwif->config_data = ports->ctl;
668 hwif->mmio = 1;
669}
670
671/**
672 * init_iops_scc - set up iops
673 * @hwif: interface to set up
674 *
675 * Do the basic setup for the SCC hardware interface
676 * and then do the MMIO setup.
677 */
678
679static void __devinit init_iops_scc(ide_hwif_t *hwif)
680{
681 struct pci_dev *dev = hwif->pci_dev;
682 hwif->hwif_data = NULL;
683 if (pci_get_drvdata(dev) == NULL)
684 return;
685 init_mmio_iops_scc(hwif);
686}
687
688/**
689 * init_hwif_scc - set up hwif
690 * @hwif: interface to set up
691 *
692 * We do the basic set up of the interface structure. The SCC
693 * requires several custom handlers so we override the default
694 * ide DMA handlers appropriately.
695 */
696
697static void __devinit init_hwif_scc(ide_hwif_t *hwif)
698{
699 struct scc_ports *ports = ide_get_hwifdata(hwif);
700
701 ports->hwif_id = hwif->index;
702
703 hwif->dma_command = hwif->dma_base;
704 hwif->dma_status = hwif->dma_base + 0x04;
705 hwif->dma_prdtable = hwif->dma_base + 0x08;
706
707 /* PTERADD */
708 out_be32((void __iomem *)(hwif->dma_base + 0x018), hwif->dmatable_dma);
709
710 hwif->dma_setup = scc_dma_setup;
711 hwif->ide_dma_end = scc_ide_dma_end;
712 hwif->speedproc = scc_tune_chipset;
713 hwif->tuneproc = scc_tuneproc;
714 hwif->ide_dma_check = scc_config_drive_for_dma;
715
716 hwif->drives[0].autotune = IDE_TUNE_AUTO;
717 hwif->drives[1].autotune = IDE_TUNE_AUTO;
718
719 if (in_be32((void __iomem *)(hwif->config_data + 0xff0)) & CCKCTRL_ATACLKOEN) {
720 hwif->ultra_mask = 0x7f; /* 133MHz */
721 } else {
722 hwif->ultra_mask = 0x3f; /* 100MHz */
723 }
724 hwif->mwdma_mask = 0x00;
725 hwif->swdma_mask = 0x00;
726 hwif->atapi_dma = 1;
727
728 /* we support 80c cable only. */
729 hwif->udma_four = 1;
730
731 hwif->autodma = 0;
732 if (!noautodma)
733 hwif->autodma = 1;
734 hwif->drives[0].autodma = hwif->autodma;
735 hwif->drives[1].autodma = hwif->autodma;
736}
737
738#define DECLARE_SCC_DEV(name_str) \
739 { \
740 .name = name_str, \
741 .init_setup = init_setup_scc, \
742 .init_iops = init_iops_scc, \
743 .init_hwif = init_hwif_scc, \
744 .channels = 1, \
745 .autodma = AUTODMA, \
746 .bootable = ON_BOARD, \
747 }
748
749static ide_pci_device_t scc_chipsets[] __devinitdata = {
750 /* 0 */ DECLARE_SCC_DEV("sccIDE"),
751};
752
753/**
754 * scc_init_one - pci layer discovery entry
755 * @dev: PCI device
756 * @id: ident table entry
757 *
758 * Called by the PCI code when it finds an SCC PATA controller.
759 * We then use the IDE PCI generic helper to do most of the work.
760 */
761
762static int __devinit scc_init_one(struct pci_dev *dev, const struct pci_device_id *id)
763{
764 ide_pci_device_t *d = &scc_chipsets[id->driver_data];
765 return d->init_setup(dev, d);
766}
767
768/**
769 * scc_remove - pci layer remove entry
770 * @dev: PCI device
771 *
772 * Called by the PCI code when it removes an SCC PATA controller.
773 */
774
775static void __devexit scc_remove(struct pci_dev *dev)
776{
777 struct scc_ports *ports = pci_get_drvdata(dev);
778 ide_hwif_t *hwif = &ide_hwifs[ports->hwif_id];
779 unsigned long ctl_base = pci_resource_start(dev, 0);
780 unsigned long dma_base = pci_resource_start(dev, 1);
781 unsigned long ctl_size = pci_resource_len(dev, 0);
782 unsigned long dma_size = pci_resource_len(dev, 1);
783
784 if (hwif->dmatable_cpu) {
785 pci_free_consistent(hwif->pci_dev,
786 PRD_ENTRIES * PRD_BYTES,
787 hwif->dmatable_cpu,
788 hwif->dmatable_dma);
789 hwif->dmatable_cpu = NULL;
790 }
791
792 ide_unregister(hwif->index);
793
794 hwif->chipset = ide_unknown;
795 iounmap((void*)ports->dma);
796 iounmap((void*)ports->ctl);
797 release_mem_region(dma_base, dma_size);
798 release_mem_region(ctl_base, ctl_size);
799 memset(ports, 0, sizeof(*ports));
800}
801
802static struct pci_device_id scc_pci_tbl[] = {
803 { PCI_VENDOR_ID_TOSHIBA_2, PCI_DEVICE_ID_TOSHIBA_SCC_ATA, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
804 { 0, },
805};
806MODULE_DEVICE_TABLE(pci, scc_pci_tbl);
807
808static struct pci_driver driver = {
809 .name = "SCC IDE",
810 .id_table = scc_pci_tbl,
811 .probe = scc_init_one,
812 .remove = scc_remove,
813};
814
815static int scc_ide_init(void)
816{
817 return ide_pci_register_driver(&driver);
818}
819
820module_init(scc_ide_init);
821/* -- No exit code?
822static void scc_ide_exit(void)
823{
824 ide_pci_unregister_driver(&driver);
825}
826module_exit(scc_ide_exit);
827 */
828
829
830MODULE_DESCRIPTION("PCI driver module for Toshiba SCC IDE");
831MODULE_LICENSE("GPL");
diff --git a/drivers/ieee1394/ieee1394-ioctl.h b/drivers/ieee1394/ieee1394-ioctl.h
index 8f207508ed1d..46878fef136c 100644
--- a/drivers/ieee1394/ieee1394-ioctl.h
+++ b/drivers/ieee1394/ieee1394-ioctl.h
@@ -100,5 +100,7 @@
100 _IO ('#', 0x28) 100 _IO ('#', 0x28)
101#define RAW1394_IOC_ISO_RECV_FLUSH \ 101#define RAW1394_IOC_ISO_RECV_FLUSH \
102 _IO ('#', 0x29) 102 _IO ('#', 0x29)
103#define RAW1394_IOC_GET_CYCLE_TIMER \
104 _IOR ('#', 0x30, struct raw1394_cycle_timer)
103 105
104#endif /* __IEEE1394_IOCTL_H */ 106#endif /* __IEEE1394_IOCTL_H */
diff --git a/drivers/ieee1394/ieee1394_core.c b/drivers/ieee1394/ieee1394_core.c
index 1521e57e124b..d791d08c743c 100644
--- a/drivers/ieee1394/ieee1394_core.c
+++ b/drivers/ieee1394/ieee1394_core.c
@@ -33,7 +33,10 @@
33#include <linux/skbuff.h> 33#include <linux/skbuff.h>
34#include <linux/suspend.h> 34#include <linux/suspend.h>
35#include <linux/kthread.h> 35#include <linux/kthread.h>
36#include <linux/preempt.h>
37#include <linux/time.h>
36 38
39#include <asm/system.h>
37#include <asm/byteorder.h> 40#include <asm/byteorder.h>
38 41
39#include "ieee1394_types.h" 42#include "ieee1394_types.h"
@@ -186,6 +189,45 @@ int hpsb_reset_bus(struct hpsb_host *host, int type)
186 } 189 }
187} 190}
188 191
192/**
193 * hpsb_read_cycle_timer - read cycle timer register and system time
194 * @host: host whose isochronous cycle timer register is read
195 * @cycle_timer: address of bitfield to return the register contents
196 * @local_time: address to return the system time
197 *
198 * The format of * @cycle_timer, is described in OHCI 1.1 clause 5.13. This
199 * format is also read from non-OHCI controllers. * @local_time contains the
200 * system time in microseconds since the Epoch, read at the moment when the
201 * cycle timer was read.
202 *
203 * Return value: 0 for success or error number otherwise.
204 */
205int hpsb_read_cycle_timer(struct hpsb_host *host, u32 *cycle_timer,
206 u64 *local_time)
207{
208 int ctr;
209 struct timeval tv;
210 unsigned long flags;
211
212 if (!host || !cycle_timer || !local_time)
213 return -EINVAL;
214
215 preempt_disable();
216 local_irq_save(flags);
217
218 ctr = host->driver->devctl(host, GET_CYCLE_COUNTER, 0);
219 if (ctr)
220 do_gettimeofday(&tv);
221
222 local_irq_restore(flags);
223 preempt_enable();
224
225 if (!ctr)
226 return -EIO;
227 *cycle_timer = ctr;
228 *local_time = tv.tv_sec * 1000000ULL + tv.tv_usec;
229 return 0;
230}
189 231
190int hpsb_bus_reset(struct hpsb_host *host) 232int hpsb_bus_reset(struct hpsb_host *host)
191{ 233{
@@ -1190,6 +1232,7 @@ EXPORT_SYMBOL(hpsb_alloc_packet);
1190EXPORT_SYMBOL(hpsb_free_packet); 1232EXPORT_SYMBOL(hpsb_free_packet);
1191EXPORT_SYMBOL(hpsb_send_packet); 1233EXPORT_SYMBOL(hpsb_send_packet);
1192EXPORT_SYMBOL(hpsb_reset_bus); 1234EXPORT_SYMBOL(hpsb_reset_bus);
1235EXPORT_SYMBOL(hpsb_read_cycle_timer);
1193EXPORT_SYMBOL(hpsb_bus_reset); 1236EXPORT_SYMBOL(hpsb_bus_reset);
1194EXPORT_SYMBOL(hpsb_selfid_received); 1237EXPORT_SYMBOL(hpsb_selfid_received);
1195EXPORT_SYMBOL(hpsb_selfid_complete); 1238EXPORT_SYMBOL(hpsb_selfid_complete);
diff --git a/drivers/ieee1394/ieee1394_core.h b/drivers/ieee1394/ieee1394_core.h
index 536ba3f580fd..bd29d8ef5bbd 100644
--- a/drivers/ieee1394/ieee1394_core.h
+++ b/drivers/ieee1394/ieee1394_core.h
@@ -127,6 +127,9 @@ int hpsb_send_packet_and_wait(struct hpsb_packet *packet);
127 * progress, 0 otherwise. */ 127 * progress, 0 otherwise. */
128int hpsb_reset_bus(struct hpsb_host *host, int type); 128int hpsb_reset_bus(struct hpsb_host *host, int type);
129 129
130int hpsb_read_cycle_timer(struct hpsb_host *host, u32 *cycle_timer,
131 u64 *local_time);
132
130/* 133/*
131 * The following functions are exported for host driver module usage. All of 134 * The following functions are exported for host driver module usage. All of
132 * them are safe to use in interrupt contexts, although some are quite 135 * them are safe to use in interrupt contexts, although some are quite
diff --git a/drivers/ieee1394/nodemgr.c b/drivers/ieee1394/nodemgr.c
index ba9faeff4793..c5ace190bfe6 100644
--- a/drivers/ieee1394/nodemgr.c
+++ b/drivers/ieee1394/nodemgr.c
@@ -1681,7 +1681,8 @@ static int nodemgr_host_thread(void *__hi)
1681 for (;;) { 1681 for (;;) {
1682 /* Sleep until next bus reset */ 1682 /* Sleep until next bus reset */
1683 set_current_state(TASK_INTERRUPTIBLE); 1683 set_current_state(TASK_INTERRUPTIBLE);
1684 if (get_hpsb_generation(host) == generation) 1684 if (get_hpsb_generation(host) == generation &&
1685 !kthread_should_stop())
1685 schedule(); 1686 schedule();
1686 __set_current_state(TASK_RUNNING); 1687 __set_current_state(TASK_RUNNING);
1687 1688
diff --git a/drivers/ieee1394/ohci1394.c b/drivers/ieee1394/ohci1394.c
index e982d60ac4b7..06fac0d21264 100644
--- a/drivers/ieee1394/ohci1394.c
+++ b/drivers/ieee1394/ohci1394.c
@@ -180,7 +180,7 @@ static int alloc_dma_trm_ctx(struct ti_ohci *ohci, struct dma_trm_ctx *d,
180static void ohci1394_pci_remove(struct pci_dev *pdev); 180static void ohci1394_pci_remove(struct pci_dev *pdev);
181 181
182#ifndef __LITTLE_ENDIAN 182#ifndef __LITTLE_ENDIAN
183const static size_t hdr_sizes[] = { 183static const size_t hdr_sizes[] = {
184 3, /* TCODE_WRITEQ */ 184 3, /* TCODE_WRITEQ */
185 4, /* TCODE_WRITEB */ 185 4, /* TCODE_WRITEB */
186 3, /* TCODE_WRITE_RESPONSE */ 186 3, /* TCODE_WRITE_RESPONSE */
diff --git a/drivers/ieee1394/raw1394.c b/drivers/ieee1394/raw1394.c
index aa9ca8385ec7..bb897a37d9f7 100644
--- a/drivers/ieee1394/raw1394.c
+++ b/drivers/ieee1394/raw1394.c
@@ -2669,6 +2669,18 @@ static void raw1394_iso_shutdown(struct file_info *fi)
2669 fi->iso_state = RAW1394_ISO_INACTIVE; 2669 fi->iso_state = RAW1394_ISO_INACTIVE;
2670} 2670}
2671 2671
2672static int raw1394_read_cycle_timer(struct file_info *fi, void __user * uaddr)
2673{
2674 struct raw1394_cycle_timer ct;
2675 int err;
2676
2677 err = hpsb_read_cycle_timer(fi->host, &ct.cycle_timer, &ct.local_time);
2678 if (!err)
2679 if (copy_to_user(uaddr, &ct, sizeof(ct)))
2680 err = -EFAULT;
2681 return err;
2682}
2683
2672/* mmap the rawiso xmit/recv buffer */ 2684/* mmap the rawiso xmit/recv buffer */
2673static int raw1394_mmap(struct file *file, struct vm_area_struct *vma) 2685static int raw1394_mmap(struct file *file, struct vm_area_struct *vma)
2674{ 2686{
@@ -2777,6 +2789,14 @@ static int raw1394_ioctl(struct inode *inode, struct file *file,
2777 break; 2789 break;
2778 } 2790 }
2779 2791
2792 /* state-independent commands */
2793 switch(cmd) {
2794 case RAW1394_IOC_GET_CYCLE_TIMER:
2795 return raw1394_read_cycle_timer(fi, argp);
2796 default:
2797 break;
2798 }
2799
2780 return -EINVAL; 2800 return -EINVAL;
2781} 2801}
2782 2802
diff --git a/drivers/ieee1394/raw1394.h b/drivers/ieee1394/raw1394.h
index 35bfc38f013c..7bd22ee1afbb 100644
--- a/drivers/ieee1394/raw1394.h
+++ b/drivers/ieee1394/raw1394.h
@@ -178,4 +178,14 @@ struct raw1394_iso_status {
178 __s16 xmit_cycle; 178 __s16 xmit_cycle;
179}; 179};
180 180
181/* argument to RAW1394_IOC_GET_CYCLE_TIMER ioctl */
182struct raw1394_cycle_timer {
183 /* contents of Isochronous Cycle Timer register,
184 as in OHCI 1.1 clause 5.13 (also with non-OHCI hosts) */
185 __u32 cycle_timer;
186
187 /* local time in microseconds since Epoch,
188 simultaneously read with cycle timer */
189 __u64 local_time;
190};
181#endif /* IEEE1394_RAW1394_H */ 191#endif /* IEEE1394_RAW1394_H */
diff --git a/drivers/infiniband/core/Makefile b/drivers/infiniband/core/Makefile
index 50fb1cd447b7..189e5d4b9b17 100644
--- a/drivers/infiniband/core/Makefile
+++ b/drivers/infiniband/core/Makefile
@@ -12,7 +12,7 @@ ib_core-y := packer.o ud_header.o verbs.o sysfs.o \
12 12
13ib_mad-y := mad.o smi.o agent.o mad_rmpp.o 13ib_mad-y := mad.o smi.o agent.o mad_rmpp.o
14 14
15ib_sa-y := sa_query.o 15ib_sa-y := sa_query.o multicast.o
16 16
17ib_cm-y := cm.o 17ib_cm-y := cm.o
18 18
diff --git a/drivers/infiniband/core/cma.c b/drivers/infiniband/core/cma.c
index db88e609bf42..f8d69b3fa307 100644
--- a/drivers/infiniband/core/cma.c
+++ b/drivers/infiniband/core/cma.c
@@ -71,6 +71,7 @@ static struct workqueue_struct *cma_wq;
71static DEFINE_IDR(sdp_ps); 71static DEFINE_IDR(sdp_ps);
72static DEFINE_IDR(tcp_ps); 72static DEFINE_IDR(tcp_ps);
73static DEFINE_IDR(udp_ps); 73static DEFINE_IDR(udp_ps);
74static DEFINE_IDR(ipoib_ps);
74static int next_port; 75static int next_port;
75 76
76struct cma_device { 77struct cma_device {
@@ -116,6 +117,7 @@ struct rdma_id_private {
116 struct list_head list; 117 struct list_head list;
117 struct list_head listen_list; 118 struct list_head listen_list;
118 struct cma_device *cma_dev; 119 struct cma_device *cma_dev;
120 struct list_head mc_list;
119 121
120 enum cma_state state; 122 enum cma_state state;
121 spinlock_t lock; 123 spinlock_t lock;
@@ -134,10 +136,23 @@ struct rdma_id_private {
134 } cm_id; 136 } cm_id;
135 137
136 u32 seq_num; 138 u32 seq_num;
139 u32 qkey;
137 u32 qp_num; 140 u32 qp_num;
138 u8 srq; 141 u8 srq;
139}; 142};
140 143
144struct cma_multicast {
145 struct rdma_id_private *id_priv;
146 union {
147 struct ib_sa_multicast *ib;
148 } multicast;
149 struct list_head list;
150 void *context;
151 struct sockaddr addr;
152 u8 pad[sizeof(struct sockaddr_in6) -
153 sizeof(struct sockaddr)];
154};
155
141struct cma_work { 156struct cma_work {
142 struct work_struct work; 157 struct work_struct work;
143 struct rdma_id_private *id; 158 struct rdma_id_private *id;
@@ -243,6 +258,11 @@ static inline void sdp_set_ip_ver(struct sdp_hh *hh, u8 ip_ver)
243 hh->ip_version = (ip_ver << 4) | (hh->ip_version & 0xF); 258 hh->ip_version = (ip_ver << 4) | (hh->ip_version & 0xF);
244} 259}
245 260
261static inline int cma_is_ud_ps(enum rdma_port_space ps)
262{
263 return (ps == RDMA_PS_UDP || ps == RDMA_PS_IPOIB);
264}
265
246static void cma_attach_to_dev(struct rdma_id_private *id_priv, 266static void cma_attach_to_dev(struct rdma_id_private *id_priv,
247 struct cma_device *cma_dev) 267 struct cma_device *cma_dev)
248{ 268{
@@ -265,19 +285,41 @@ static void cma_detach_from_dev(struct rdma_id_private *id_priv)
265 id_priv->cma_dev = NULL; 285 id_priv->cma_dev = NULL;
266} 286}
267 287
288static int cma_set_qkey(struct ib_device *device, u8 port_num,
289 enum rdma_port_space ps,
290 struct rdma_dev_addr *dev_addr, u32 *qkey)
291{
292 struct ib_sa_mcmember_rec rec;
293 int ret = 0;
294
295 switch (ps) {
296 case RDMA_PS_UDP:
297 *qkey = RDMA_UDP_QKEY;
298 break;
299 case RDMA_PS_IPOIB:
300 ib_addr_get_mgid(dev_addr, &rec.mgid);
301 ret = ib_sa_get_mcmember_rec(device, port_num, &rec.mgid, &rec);
302 *qkey = be32_to_cpu(rec.qkey);
303 break;
304 default:
305 break;
306 }
307 return ret;
308}
309
268static int cma_acquire_dev(struct rdma_id_private *id_priv) 310static int cma_acquire_dev(struct rdma_id_private *id_priv)
269{ 311{
270 enum rdma_node_type dev_type = id_priv->id.route.addr.dev_addr.dev_type; 312 struct rdma_dev_addr *dev_addr = &id_priv->id.route.addr.dev_addr;
271 struct cma_device *cma_dev; 313 struct cma_device *cma_dev;
272 union ib_gid gid; 314 union ib_gid gid;
273 int ret = -ENODEV; 315 int ret = -ENODEV;
274 316
275 switch (rdma_node_get_transport(dev_type)) { 317 switch (rdma_node_get_transport(dev_addr->dev_type)) {
276 case RDMA_TRANSPORT_IB: 318 case RDMA_TRANSPORT_IB:
277 ib_addr_get_sgid(&id_priv->id.route.addr.dev_addr, &gid); 319 ib_addr_get_sgid(dev_addr, &gid);
278 break; 320 break;
279 case RDMA_TRANSPORT_IWARP: 321 case RDMA_TRANSPORT_IWARP:
280 iw_addr_get_sgid(&id_priv->id.route.addr.dev_addr, &gid); 322 iw_addr_get_sgid(dev_addr, &gid);
281 break; 323 break;
282 default: 324 default:
283 return -ENODEV; 325 return -ENODEV;
@@ -287,7 +329,12 @@ static int cma_acquire_dev(struct rdma_id_private *id_priv)
287 ret = ib_find_cached_gid(cma_dev->device, &gid, 329 ret = ib_find_cached_gid(cma_dev->device, &gid,
288 &id_priv->id.port_num, NULL); 330 &id_priv->id.port_num, NULL);
289 if (!ret) { 331 if (!ret) {
290 cma_attach_to_dev(id_priv, cma_dev); 332 ret = cma_set_qkey(cma_dev->device,
333 id_priv->id.port_num,
334 id_priv->id.ps, dev_addr,
335 &id_priv->qkey);
336 if (!ret)
337 cma_attach_to_dev(id_priv, cma_dev);
291 break; 338 break;
292 } 339 }
293 } 340 }
@@ -325,40 +372,50 @@ struct rdma_cm_id *rdma_create_id(rdma_cm_event_handler event_handler,
325 init_waitqueue_head(&id_priv->wait_remove); 372 init_waitqueue_head(&id_priv->wait_remove);
326 atomic_set(&id_priv->dev_remove, 0); 373 atomic_set(&id_priv->dev_remove, 0);
327 INIT_LIST_HEAD(&id_priv->listen_list); 374 INIT_LIST_HEAD(&id_priv->listen_list);
375 INIT_LIST_HEAD(&id_priv->mc_list);
328 get_random_bytes(&id_priv->seq_num, sizeof id_priv->seq_num); 376 get_random_bytes(&id_priv->seq_num, sizeof id_priv->seq_num);
329 377
330 return &id_priv->id; 378 return &id_priv->id;
331} 379}
332EXPORT_SYMBOL(rdma_create_id); 380EXPORT_SYMBOL(rdma_create_id);
333 381
334static int cma_init_ib_qp(struct rdma_id_private *id_priv, struct ib_qp *qp) 382static int cma_init_ud_qp(struct rdma_id_private *id_priv, struct ib_qp *qp)
335{ 383{
336 struct ib_qp_attr qp_attr; 384 struct ib_qp_attr qp_attr;
337 struct rdma_dev_addr *dev_addr; 385 int qp_attr_mask, ret;
338 int ret;
339 386
340 dev_addr = &id_priv->id.route.addr.dev_addr; 387 qp_attr.qp_state = IB_QPS_INIT;
341 ret = ib_find_cached_pkey(id_priv->id.device, id_priv->id.port_num, 388 ret = rdma_init_qp_attr(&id_priv->id, &qp_attr, &qp_attr_mask);
342 ib_addr_get_pkey(dev_addr),
343 &qp_attr.pkey_index);
344 if (ret) 389 if (ret)
345 return ret; 390 return ret;
346 391
347 qp_attr.qp_state = IB_QPS_INIT; 392 ret = ib_modify_qp(qp, &qp_attr, qp_attr_mask);
348 qp_attr.qp_access_flags = 0; 393 if (ret)
349 qp_attr.port_num = id_priv->id.port_num; 394 return ret;
350 return ib_modify_qp(qp, &qp_attr, IB_QP_STATE | IB_QP_ACCESS_FLAGS | 395
351 IB_QP_PKEY_INDEX | IB_QP_PORT); 396 qp_attr.qp_state = IB_QPS_RTR;
397 ret = ib_modify_qp(qp, &qp_attr, IB_QP_STATE);
398 if (ret)
399 return ret;
400
401 qp_attr.qp_state = IB_QPS_RTS;
402 qp_attr.sq_psn = 0;
403 ret = ib_modify_qp(qp, &qp_attr, IB_QP_STATE | IB_QP_SQ_PSN);
404
405 return ret;
352} 406}
353 407
354static int cma_init_iw_qp(struct rdma_id_private *id_priv, struct ib_qp *qp) 408static int cma_init_conn_qp(struct rdma_id_private *id_priv, struct ib_qp *qp)
355{ 409{
356 struct ib_qp_attr qp_attr; 410 struct ib_qp_attr qp_attr;
411 int qp_attr_mask, ret;
357 412
358 qp_attr.qp_state = IB_QPS_INIT; 413 qp_attr.qp_state = IB_QPS_INIT;
359 qp_attr.qp_access_flags = IB_ACCESS_LOCAL_WRITE; 414 ret = rdma_init_qp_attr(&id_priv->id, &qp_attr, &qp_attr_mask);
415 if (ret)
416 return ret;
360 417
361 return ib_modify_qp(qp, &qp_attr, IB_QP_STATE | IB_QP_ACCESS_FLAGS); 418 return ib_modify_qp(qp, &qp_attr, qp_attr_mask);
362} 419}
363 420
364int rdma_create_qp(struct rdma_cm_id *id, struct ib_pd *pd, 421int rdma_create_qp(struct rdma_cm_id *id, struct ib_pd *pd,
@@ -376,18 +433,10 @@ int rdma_create_qp(struct rdma_cm_id *id, struct ib_pd *pd,
376 if (IS_ERR(qp)) 433 if (IS_ERR(qp))
377 return PTR_ERR(qp); 434 return PTR_ERR(qp);
378 435
379 switch (rdma_node_get_transport(id->device->node_type)) { 436 if (cma_is_ud_ps(id_priv->id.ps))
380 case RDMA_TRANSPORT_IB: 437 ret = cma_init_ud_qp(id_priv, qp);
381 ret = cma_init_ib_qp(id_priv, qp); 438 else
382 break; 439 ret = cma_init_conn_qp(id_priv, qp);
383 case RDMA_TRANSPORT_IWARP:
384 ret = cma_init_iw_qp(id_priv, qp);
385 break;
386 default:
387 ret = -ENOSYS;
388 break;
389 }
390
391 if (ret) 440 if (ret)
392 goto err; 441 goto err;
393 442
@@ -460,23 +509,55 @@ static int cma_modify_qp_err(struct rdma_cm_id *id)
460 return ib_modify_qp(id->qp, &qp_attr, IB_QP_STATE); 509 return ib_modify_qp(id->qp, &qp_attr, IB_QP_STATE);
461} 510}
462 511
512static int cma_ib_init_qp_attr(struct rdma_id_private *id_priv,
513 struct ib_qp_attr *qp_attr, int *qp_attr_mask)
514{
515 struct rdma_dev_addr *dev_addr = &id_priv->id.route.addr.dev_addr;
516 int ret;
517
518 ret = ib_find_cached_pkey(id_priv->id.device, id_priv->id.port_num,
519 ib_addr_get_pkey(dev_addr),
520 &qp_attr->pkey_index);
521 if (ret)
522 return ret;
523
524 qp_attr->port_num = id_priv->id.port_num;
525 *qp_attr_mask = IB_QP_STATE | IB_QP_PKEY_INDEX | IB_QP_PORT;
526
527 if (cma_is_ud_ps(id_priv->id.ps)) {
528 qp_attr->qkey = id_priv->qkey;
529 *qp_attr_mask |= IB_QP_QKEY;
530 } else {
531 qp_attr->qp_access_flags = 0;
532 *qp_attr_mask |= IB_QP_ACCESS_FLAGS;
533 }
534 return 0;
535}
536
463int rdma_init_qp_attr(struct rdma_cm_id *id, struct ib_qp_attr *qp_attr, 537int rdma_init_qp_attr(struct rdma_cm_id *id, struct ib_qp_attr *qp_attr,
464 int *qp_attr_mask) 538 int *qp_attr_mask)
465{ 539{
466 struct rdma_id_private *id_priv; 540 struct rdma_id_private *id_priv;
467 int ret; 541 int ret = 0;
468 542
469 id_priv = container_of(id, struct rdma_id_private, id); 543 id_priv = container_of(id, struct rdma_id_private, id);
470 switch (rdma_node_get_transport(id_priv->id.device->node_type)) { 544 switch (rdma_node_get_transport(id_priv->id.device->node_type)) {
471 case RDMA_TRANSPORT_IB: 545 case RDMA_TRANSPORT_IB:
472 ret = ib_cm_init_qp_attr(id_priv->cm_id.ib, qp_attr, 546 if (!id_priv->cm_id.ib || cma_is_ud_ps(id_priv->id.ps))
473 qp_attr_mask); 547 ret = cma_ib_init_qp_attr(id_priv, qp_attr, qp_attr_mask);
548 else
549 ret = ib_cm_init_qp_attr(id_priv->cm_id.ib, qp_attr,
550 qp_attr_mask);
474 if (qp_attr->qp_state == IB_QPS_RTR) 551 if (qp_attr->qp_state == IB_QPS_RTR)
475 qp_attr->rq_psn = id_priv->seq_num; 552 qp_attr->rq_psn = id_priv->seq_num;
476 break; 553 break;
477 case RDMA_TRANSPORT_IWARP: 554 case RDMA_TRANSPORT_IWARP:
478 ret = iw_cm_init_qp_attr(id_priv->cm_id.iw, qp_attr, 555 if (!id_priv->cm_id.iw) {
479 qp_attr_mask); 556 qp_attr->qp_access_flags = IB_ACCESS_LOCAL_WRITE;
557 *qp_attr_mask = IB_QP_STATE | IB_QP_ACCESS_FLAGS;
558 } else
559 ret = iw_cm_init_qp_attr(id_priv->cm_id.iw, qp_attr,
560 qp_attr_mask);
480 break; 561 break;
481 default: 562 default:
482 ret = -ENOSYS; 563 ret = -ENOSYS;
@@ -698,6 +779,19 @@ static void cma_release_port(struct rdma_id_private *id_priv)
698 mutex_unlock(&lock); 779 mutex_unlock(&lock);
699} 780}
700 781
782static void cma_leave_mc_groups(struct rdma_id_private *id_priv)
783{
784 struct cma_multicast *mc;
785
786 while (!list_empty(&id_priv->mc_list)) {
787 mc = container_of(id_priv->mc_list.next,
788 struct cma_multicast, list);
789 list_del(&mc->list);
790 ib_sa_free_multicast(mc->multicast.ib);
791 kfree(mc);
792 }
793}
794
701void rdma_destroy_id(struct rdma_cm_id *id) 795void rdma_destroy_id(struct rdma_cm_id *id)
702{ 796{
703 struct rdma_id_private *id_priv; 797 struct rdma_id_private *id_priv;
@@ -722,6 +816,7 @@ void rdma_destroy_id(struct rdma_cm_id *id)
722 default: 816 default:
723 break; 817 break;
724 } 818 }
819 cma_leave_mc_groups(id_priv);
725 mutex_lock(&lock); 820 mutex_lock(&lock);
726 cma_detach_from_dev(id_priv); 821 cma_detach_from_dev(id_priv);
727 } 822 }
@@ -972,7 +1067,7 @@ static int cma_req_handler(struct ib_cm_id *cm_id, struct ib_cm_event *ib_event)
972 memset(&event, 0, sizeof event); 1067 memset(&event, 0, sizeof event);
973 offset = cma_user_data_offset(listen_id->id.ps); 1068 offset = cma_user_data_offset(listen_id->id.ps);
974 event.event = RDMA_CM_EVENT_CONNECT_REQUEST; 1069 event.event = RDMA_CM_EVENT_CONNECT_REQUEST;
975 if (listen_id->id.ps == RDMA_PS_UDP) { 1070 if (cma_is_ud_ps(listen_id->id.ps)) {
976 conn_id = cma_new_udp_id(&listen_id->id, ib_event); 1071 conn_id = cma_new_udp_id(&listen_id->id, ib_event);
977 event.param.ud.private_data = ib_event->private_data + offset; 1072 event.param.ud.private_data = ib_event->private_data + offset;
978 event.param.ud.private_data_len = 1073 event.param.ud.private_data_len =
@@ -1725,7 +1820,7 @@ static int cma_alloc_port(struct idr *ps, struct rdma_id_private *id_priv,
1725 struct rdma_bind_list *bind_list; 1820 struct rdma_bind_list *bind_list;
1726 int port, ret; 1821 int port, ret;
1727 1822
1728 bind_list = kzalloc(sizeof *bind_list, GFP_KERNEL); 1823 bind_list = kmalloc(sizeof *bind_list, GFP_KERNEL);
1729 if (!bind_list) 1824 if (!bind_list)
1730 return -ENOMEM; 1825 return -ENOMEM;
1731 1826
@@ -1847,6 +1942,9 @@ static int cma_get_port(struct rdma_id_private *id_priv)
1847 case RDMA_PS_UDP: 1942 case RDMA_PS_UDP:
1848 ps = &udp_ps; 1943 ps = &udp_ps;
1849 break; 1944 break;
1945 case RDMA_PS_IPOIB:
1946 ps = &ipoib_ps;
1947 break;
1850 default: 1948 default:
1851 return -EPROTONOSUPPORT; 1949 return -EPROTONOSUPPORT;
1852 } 1950 }
@@ -1961,7 +2059,7 @@ static int cma_sidr_rep_handler(struct ib_cm_id *cm_id,
1961 event.status = ib_event->param.sidr_rep_rcvd.status; 2059 event.status = ib_event->param.sidr_rep_rcvd.status;
1962 break; 2060 break;
1963 } 2061 }
1964 if (rep->qkey != RDMA_UD_QKEY) { 2062 if (id_priv->qkey != rep->qkey) {
1965 event.event = RDMA_CM_EVENT_UNREACHABLE; 2063 event.event = RDMA_CM_EVENT_UNREACHABLE;
1966 event.status = -EINVAL; 2064 event.status = -EINVAL;
1967 break; 2065 break;
@@ -2160,7 +2258,7 @@ int rdma_connect(struct rdma_cm_id *id, struct rdma_conn_param *conn_param)
2160 2258
2161 switch (rdma_node_get_transport(id->device->node_type)) { 2259 switch (rdma_node_get_transport(id->device->node_type)) {
2162 case RDMA_TRANSPORT_IB: 2260 case RDMA_TRANSPORT_IB:
2163 if (id->ps == RDMA_PS_UDP) 2261 if (cma_is_ud_ps(id->ps))
2164 ret = cma_resolve_ib_udp(id_priv, conn_param); 2262 ret = cma_resolve_ib_udp(id_priv, conn_param);
2165 else 2263 else
2166 ret = cma_connect_ib(id_priv, conn_param); 2264 ret = cma_connect_ib(id_priv, conn_param);
@@ -2256,7 +2354,7 @@ static int cma_send_sidr_rep(struct rdma_id_private *id_priv,
2256 rep.status = status; 2354 rep.status = status;
2257 if (status == IB_SIDR_SUCCESS) { 2355 if (status == IB_SIDR_SUCCESS) {
2258 rep.qp_num = id_priv->qp_num; 2356 rep.qp_num = id_priv->qp_num;
2259 rep.qkey = RDMA_UD_QKEY; 2357 rep.qkey = id_priv->qkey;
2260 } 2358 }
2261 rep.private_data = private_data; 2359 rep.private_data = private_data;
2262 rep.private_data_len = private_data_len; 2360 rep.private_data_len = private_data_len;
@@ -2280,7 +2378,7 @@ int rdma_accept(struct rdma_cm_id *id, struct rdma_conn_param *conn_param)
2280 2378
2281 switch (rdma_node_get_transport(id->device->node_type)) { 2379 switch (rdma_node_get_transport(id->device->node_type)) {
2282 case RDMA_TRANSPORT_IB: 2380 case RDMA_TRANSPORT_IB:
2283 if (id->ps == RDMA_PS_UDP) 2381 if (cma_is_ud_ps(id->ps))
2284 ret = cma_send_sidr_rep(id_priv, IB_SIDR_SUCCESS, 2382 ret = cma_send_sidr_rep(id_priv, IB_SIDR_SUCCESS,
2285 conn_param->private_data, 2383 conn_param->private_data,
2286 conn_param->private_data_len); 2384 conn_param->private_data_len);
@@ -2341,7 +2439,7 @@ int rdma_reject(struct rdma_cm_id *id, const void *private_data,
2341 2439
2342 switch (rdma_node_get_transport(id->device->node_type)) { 2440 switch (rdma_node_get_transport(id->device->node_type)) {
2343 case RDMA_TRANSPORT_IB: 2441 case RDMA_TRANSPORT_IB:
2344 if (id->ps == RDMA_PS_UDP) 2442 if (cma_is_ud_ps(id->ps))
2345 ret = cma_send_sidr_rep(id_priv, IB_SIDR_REJECT, 2443 ret = cma_send_sidr_rep(id_priv, IB_SIDR_REJECT,
2346 private_data, private_data_len); 2444 private_data, private_data_len);
2347 else 2445 else
@@ -2392,6 +2490,178 @@ out:
2392} 2490}
2393EXPORT_SYMBOL(rdma_disconnect); 2491EXPORT_SYMBOL(rdma_disconnect);
2394 2492
2493static int cma_ib_mc_handler(int status, struct ib_sa_multicast *multicast)
2494{
2495 struct rdma_id_private *id_priv;
2496 struct cma_multicast *mc = multicast->context;
2497 struct rdma_cm_event event;
2498 int ret;
2499
2500 id_priv = mc->id_priv;
2501 atomic_inc(&id_priv->dev_remove);
2502 if (!cma_comp(id_priv, CMA_ADDR_BOUND) &&
2503 !cma_comp(id_priv, CMA_ADDR_RESOLVED))
2504 goto out;
2505
2506 if (!status && id_priv->id.qp)
2507 status = ib_attach_mcast(id_priv->id.qp, &multicast->rec.mgid,
2508 multicast->rec.mlid);
2509
2510 memset(&event, 0, sizeof event);
2511 event.status = status;
2512 event.param.ud.private_data = mc->context;
2513 if (!status) {
2514 event.event = RDMA_CM_EVENT_MULTICAST_JOIN;
2515 ib_init_ah_from_mcmember(id_priv->id.device,
2516 id_priv->id.port_num, &multicast->rec,
2517 &event.param.ud.ah_attr);
2518 event.param.ud.qp_num = 0xFFFFFF;
2519 event.param.ud.qkey = be32_to_cpu(multicast->rec.qkey);
2520 } else
2521 event.event = RDMA_CM_EVENT_MULTICAST_ERROR;
2522
2523 ret = id_priv->id.event_handler(&id_priv->id, &event);
2524 if (ret) {
2525 cma_exch(id_priv, CMA_DESTROYING);
2526 cma_release_remove(id_priv);
2527 rdma_destroy_id(&id_priv->id);
2528 return 0;
2529 }
2530out:
2531 cma_release_remove(id_priv);
2532 return 0;
2533}
2534
2535static void cma_set_mgid(struct rdma_id_private *id_priv,
2536 struct sockaddr *addr, union ib_gid *mgid)
2537{
2538 unsigned char mc_map[MAX_ADDR_LEN];
2539 struct rdma_dev_addr *dev_addr = &id_priv->id.route.addr.dev_addr;
2540 struct sockaddr_in *sin = (struct sockaddr_in *) addr;
2541 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *) addr;
2542
2543 if (cma_any_addr(addr)) {
2544 memset(mgid, 0, sizeof *mgid);
2545 } else if ((addr->sa_family == AF_INET6) &&
2546 ((be32_to_cpu(sin6->sin6_addr.s6_addr32[0]) & 0xFF10A01B) ==
2547 0xFF10A01B)) {
2548 /* IPv6 address is an SA assigned MGID. */
2549 memcpy(mgid, &sin6->sin6_addr, sizeof *mgid);
2550 } else {
2551 ip_ib_mc_map(sin->sin_addr.s_addr, mc_map);
2552 if (id_priv->id.ps == RDMA_PS_UDP)
2553 mc_map[7] = 0x01; /* Use RDMA CM signature */
2554 mc_map[8] = ib_addr_get_pkey(dev_addr) >> 8;
2555 mc_map[9] = (unsigned char) ib_addr_get_pkey(dev_addr);
2556 *mgid = *(union ib_gid *) (mc_map + 4);
2557 }
2558}
2559
2560static int cma_join_ib_multicast(struct rdma_id_private *id_priv,
2561 struct cma_multicast *mc)
2562{
2563 struct ib_sa_mcmember_rec rec;
2564 struct rdma_dev_addr *dev_addr = &id_priv->id.route.addr.dev_addr;
2565 ib_sa_comp_mask comp_mask;
2566 int ret;
2567
2568 ib_addr_get_mgid(dev_addr, &rec.mgid);
2569 ret = ib_sa_get_mcmember_rec(id_priv->id.device, id_priv->id.port_num,
2570 &rec.mgid, &rec);
2571 if (ret)
2572 return ret;
2573
2574 cma_set_mgid(id_priv, &mc->addr, &rec.mgid);
2575 if (id_priv->id.ps == RDMA_PS_UDP)
2576 rec.qkey = cpu_to_be32(RDMA_UDP_QKEY);
2577 ib_addr_get_sgid(dev_addr, &rec.port_gid);
2578 rec.pkey = cpu_to_be16(ib_addr_get_pkey(dev_addr));
2579 rec.join_state = 1;
2580
2581 comp_mask = IB_SA_MCMEMBER_REC_MGID | IB_SA_MCMEMBER_REC_PORT_GID |
2582 IB_SA_MCMEMBER_REC_PKEY | IB_SA_MCMEMBER_REC_JOIN_STATE |
2583 IB_SA_MCMEMBER_REC_QKEY | IB_SA_MCMEMBER_REC_SL |
2584 IB_SA_MCMEMBER_REC_FLOW_LABEL |
2585 IB_SA_MCMEMBER_REC_TRAFFIC_CLASS;
2586
2587 mc->multicast.ib = ib_sa_join_multicast(&sa_client, id_priv->id.device,
2588 id_priv->id.port_num, &rec,
2589 comp_mask, GFP_KERNEL,
2590 cma_ib_mc_handler, mc);
2591 if (IS_ERR(mc->multicast.ib))
2592 return PTR_ERR(mc->multicast.ib);
2593
2594 return 0;
2595}
2596
2597int rdma_join_multicast(struct rdma_cm_id *id, struct sockaddr *addr,
2598 void *context)
2599{
2600 struct rdma_id_private *id_priv;
2601 struct cma_multicast *mc;
2602 int ret;
2603
2604 id_priv = container_of(id, struct rdma_id_private, id);
2605 if (!cma_comp(id_priv, CMA_ADDR_BOUND) &&
2606 !cma_comp(id_priv, CMA_ADDR_RESOLVED))
2607 return -EINVAL;
2608
2609 mc = kmalloc(sizeof *mc, GFP_KERNEL);
2610 if (!mc)
2611 return -ENOMEM;
2612
2613 memcpy(&mc->addr, addr, ip_addr_size(addr));
2614 mc->context = context;
2615 mc->id_priv = id_priv;
2616
2617 spin_lock(&id_priv->lock);
2618 list_add(&mc->list, &id_priv->mc_list);
2619 spin_unlock(&id_priv->lock);
2620
2621 switch (rdma_node_get_transport(id->device->node_type)) {
2622 case RDMA_TRANSPORT_IB:
2623 ret = cma_join_ib_multicast(id_priv, mc);
2624 break;
2625 default:
2626 ret = -ENOSYS;
2627 break;
2628 }
2629
2630 if (ret) {
2631 spin_lock_irq(&id_priv->lock);
2632 list_del(&mc->list);
2633 spin_unlock_irq(&id_priv->lock);
2634 kfree(mc);
2635 }
2636 return ret;
2637}
2638EXPORT_SYMBOL(rdma_join_multicast);
2639
2640void rdma_leave_multicast(struct rdma_cm_id *id, struct sockaddr *addr)
2641{
2642 struct rdma_id_private *id_priv;
2643 struct cma_multicast *mc;
2644
2645 id_priv = container_of(id, struct rdma_id_private, id);
2646 spin_lock_irq(&id_priv->lock);
2647 list_for_each_entry(mc, &id_priv->mc_list, list) {
2648 if (!memcmp(&mc->addr, addr, ip_addr_size(addr))) {
2649 list_del(&mc->list);
2650 spin_unlock_irq(&id_priv->lock);
2651
2652 if (id->qp)
2653 ib_detach_mcast(id->qp,
2654 &mc->multicast.ib->rec.mgid,
2655 mc->multicast.ib->rec.mlid);
2656 ib_sa_free_multicast(mc->multicast.ib);
2657 kfree(mc);
2658 return;
2659 }
2660 }
2661 spin_unlock_irq(&id_priv->lock);
2662}
2663EXPORT_SYMBOL(rdma_leave_multicast);
2664
2395static void cma_add_one(struct ib_device *device) 2665static void cma_add_one(struct ib_device *device)
2396{ 2666{
2397 struct cma_device *cma_dev; 2667 struct cma_device *cma_dev;
@@ -2522,6 +2792,7 @@ static void cma_cleanup(void)
2522 idr_destroy(&sdp_ps); 2792 idr_destroy(&sdp_ps);
2523 idr_destroy(&tcp_ps); 2793 idr_destroy(&tcp_ps);
2524 idr_destroy(&udp_ps); 2794 idr_destroy(&udp_ps);
2795 idr_destroy(&ipoib_ps);
2525} 2796}
2526 2797
2527module_init(cma_init); 2798module_init(cma_init);
diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
index 8926a2bd4a87..1d796e7c8199 100644
--- a/drivers/infiniband/core/fmr_pool.c
+++ b/drivers/infiniband/core/fmr_pool.c
@@ -301,7 +301,7 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
301 301
302 { 302 {
303 struct ib_pool_fmr *fmr; 303 struct ib_pool_fmr *fmr;
304 struct ib_fmr_attr attr = { 304 struct ib_fmr_attr fmr_attr = {
305 .max_pages = params->max_pages_per_fmr, 305 .max_pages = params->max_pages_per_fmr,
306 .max_maps = pool->max_remaps, 306 .max_maps = pool->max_remaps,
307 .page_shift = params->page_shift 307 .page_shift = params->page_shift
@@ -321,7 +321,7 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
321 fmr->ref_count = 0; 321 fmr->ref_count = 0;
322 INIT_HLIST_NODE(&fmr->cache_node); 322 INIT_HLIST_NODE(&fmr->cache_node);
323 323
324 fmr->fmr = ib_alloc_fmr(pd, params->access, &attr); 324 fmr->fmr = ib_alloc_fmr(pd, params->access, &fmr_attr);
325 if (IS_ERR(fmr->fmr)) { 325 if (IS_ERR(fmr->fmr)) {
326 printk(KERN_WARNING "fmr_create failed for FMR %d", i); 326 printk(KERN_WARNING "fmr_create failed for FMR %d", i);
327 kfree(fmr); 327 kfree(fmr);
diff --git a/drivers/infiniband/core/iwcm.c b/drivers/infiniband/core/iwcm.c
index 1039ad57d53b..891d1fa7b2eb 100644
--- a/drivers/infiniband/core/iwcm.c
+++ b/drivers/infiniband/core/iwcm.c
@@ -146,6 +146,12 @@ static int copy_private_data(struct iw_cm_event *event)
146 return 0; 146 return 0;
147} 147}
148 148
149static void free_cm_id(struct iwcm_id_private *cm_id_priv)
150{
151 dealloc_work_entries(cm_id_priv);
152 kfree(cm_id_priv);
153}
154
149/* 155/*
150 * Release a reference on cm_id. If the last reference is being 156 * Release a reference on cm_id. If the last reference is being
151 * released, enable the waiting thread (in iw_destroy_cm_id) to 157 * released, enable the waiting thread (in iw_destroy_cm_id) to
@@ -153,21 +159,14 @@ static int copy_private_data(struct iw_cm_event *event)
153 */ 159 */
154static int iwcm_deref_id(struct iwcm_id_private *cm_id_priv) 160static int iwcm_deref_id(struct iwcm_id_private *cm_id_priv)
155{ 161{
156 int ret = 0;
157
158 BUG_ON(atomic_read(&cm_id_priv->refcount)==0); 162 BUG_ON(atomic_read(&cm_id_priv->refcount)==0);
159 if (atomic_dec_and_test(&cm_id_priv->refcount)) { 163 if (atomic_dec_and_test(&cm_id_priv->refcount)) {
160 BUG_ON(!list_empty(&cm_id_priv->work_list)); 164 BUG_ON(!list_empty(&cm_id_priv->work_list));
161 if (waitqueue_active(&cm_id_priv->destroy_comp.wait)) {
162 BUG_ON(cm_id_priv->state != IW_CM_STATE_DESTROYING);
163 BUG_ON(test_bit(IWCM_F_CALLBACK_DESTROY,
164 &cm_id_priv->flags));
165 ret = 1;
166 }
167 complete(&cm_id_priv->destroy_comp); 165 complete(&cm_id_priv->destroy_comp);
166 return 1;
168 } 167 }
169 168
170 return ret; 169 return 0;
171} 170}
172 171
173static void add_ref(struct iw_cm_id *cm_id) 172static void add_ref(struct iw_cm_id *cm_id)
@@ -181,7 +180,11 @@ static void rem_ref(struct iw_cm_id *cm_id)
181{ 180{
182 struct iwcm_id_private *cm_id_priv; 181 struct iwcm_id_private *cm_id_priv;
183 cm_id_priv = container_of(cm_id, struct iwcm_id_private, id); 182 cm_id_priv = container_of(cm_id, struct iwcm_id_private, id);
184 iwcm_deref_id(cm_id_priv); 183 if (iwcm_deref_id(cm_id_priv) &&
184 test_bit(IWCM_F_CALLBACK_DESTROY, &cm_id_priv->flags)) {
185 BUG_ON(!list_empty(&cm_id_priv->work_list));
186 free_cm_id(cm_id_priv);
187 }
185} 188}
186 189
187static int cm_event_handler(struct iw_cm_id *cm_id, struct iw_cm_event *event); 190static int cm_event_handler(struct iw_cm_id *cm_id, struct iw_cm_event *event);
@@ -355,7 +358,9 @@ static void destroy_cm_id(struct iw_cm_id *cm_id)
355 case IW_CM_STATE_CONN_RECV: 358 case IW_CM_STATE_CONN_RECV:
356 /* 359 /*
357 * App called destroy before/without calling accept after 360 * App called destroy before/without calling accept after
358 * receiving connection request event notification. 361 * receiving connection request event notification or
362 * returned non zero from the event callback function.
363 * In either case, must tell the provider to reject.
359 */ 364 */
360 cm_id_priv->state = IW_CM_STATE_DESTROYING; 365 cm_id_priv->state = IW_CM_STATE_DESTROYING;
361 break; 366 break;
@@ -391,9 +396,7 @@ void iw_destroy_cm_id(struct iw_cm_id *cm_id)
391 396
392 wait_for_completion(&cm_id_priv->destroy_comp); 397 wait_for_completion(&cm_id_priv->destroy_comp);
393 398
394 dealloc_work_entries(cm_id_priv); 399 free_cm_id(cm_id_priv);
395
396 kfree(cm_id_priv);
397} 400}
398EXPORT_SYMBOL(iw_destroy_cm_id); 401EXPORT_SYMBOL(iw_destroy_cm_id);
399 402
@@ -647,10 +650,11 @@ static void cm_conn_req_handler(struct iwcm_id_private *listen_id_priv,
647 /* Call the client CM handler */ 650 /* Call the client CM handler */
648 ret = cm_id->cm_handler(cm_id, iw_event); 651 ret = cm_id->cm_handler(cm_id, iw_event);
649 if (ret) { 652 if (ret) {
653 iw_cm_reject(cm_id, NULL, 0);
650 set_bit(IWCM_F_CALLBACK_DESTROY, &cm_id_priv->flags); 654 set_bit(IWCM_F_CALLBACK_DESTROY, &cm_id_priv->flags);
651 destroy_cm_id(cm_id); 655 destroy_cm_id(cm_id);
652 if (atomic_read(&cm_id_priv->refcount)==0) 656 if (atomic_read(&cm_id_priv->refcount)==0)
653 kfree(cm_id); 657 free_cm_id(cm_id_priv);
654 } 658 }
655 659
656out: 660out:
@@ -854,13 +858,12 @@ static void cm_work_handler(struct work_struct *_work)
854 destroy_cm_id(&cm_id_priv->id); 858 destroy_cm_id(&cm_id_priv->id);
855 } 859 }
856 BUG_ON(atomic_read(&cm_id_priv->refcount)==0); 860 BUG_ON(atomic_read(&cm_id_priv->refcount)==0);
857 if (iwcm_deref_id(cm_id_priv)) 861 if (iwcm_deref_id(cm_id_priv)) {
858 return; 862 if (test_bit(IWCM_F_CALLBACK_DESTROY,
859 863 &cm_id_priv->flags)) {
860 if (atomic_read(&cm_id_priv->refcount)==0 && 864 BUG_ON(!list_empty(&cm_id_priv->work_list));
861 test_bit(IWCM_F_CALLBACK_DESTROY, &cm_id_priv->flags)) { 865 free_cm_id(cm_id_priv);
862 dealloc_work_entries(cm_id_priv); 866 }
863 kfree(cm_id_priv);
864 return; 867 return;
865 } 868 }
866 spin_lock_irqsave(&cm_id_priv->lock, flags); 869 spin_lock_irqsave(&cm_id_priv->lock, flags);
diff --git a/drivers/infiniband/core/multicast.c b/drivers/infiniband/core/multicast.c
new file mode 100644
index 000000000000..4a579b3a1c90
--- /dev/null
+++ b/drivers/infiniband/core/multicast.c
@@ -0,0 +1,837 @@
1/*
2 * Copyright (c) 2006 Intel Corporation.  All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32
33#include <linux/completion.h>
34#include <linux/dma-mapping.h>
35#include <linux/err.h>
36#include <linux/interrupt.h>
37#include <linux/pci.h>
38#include <linux/bitops.h>
39#include <linux/random.h>
40
41#include <rdma/ib_cache.h>
42#include "sa.h"
43
44static void mcast_add_one(struct ib_device *device);
45static void mcast_remove_one(struct ib_device *device);
46
47static struct ib_client mcast_client = {
48 .name = "ib_multicast",
49 .add = mcast_add_one,
50 .remove = mcast_remove_one
51};
52
53static struct ib_sa_client sa_client;
54static struct workqueue_struct *mcast_wq;
55static union ib_gid mgid0;
56
57struct mcast_device;
58
59struct mcast_port {
60 struct mcast_device *dev;
61 spinlock_t lock;
62 struct rb_root table;
63 atomic_t refcount;
64 struct completion comp;
65 u8 port_num;
66};
67
68struct mcast_device {
69 struct ib_device *device;
70 struct ib_event_handler event_handler;
71 int start_port;
72 int end_port;
73 struct mcast_port port[0];
74};
75
76enum mcast_state {
77 MCAST_IDLE,
78 MCAST_JOINING,
79 MCAST_MEMBER,
80 MCAST_BUSY,
81 MCAST_ERROR
82};
83
84struct mcast_member;
85
86struct mcast_group {
87 struct ib_sa_mcmember_rec rec;
88 struct rb_node node;
89 struct mcast_port *port;
90 spinlock_t lock;
91 struct work_struct work;
92 struct list_head pending_list;
93 struct list_head active_list;
94 struct mcast_member *last_join;
95 int members[3];
96 atomic_t refcount;
97 enum mcast_state state;
98 struct ib_sa_query *query;
99 int query_id;
100};
101
102struct mcast_member {
103 struct ib_sa_multicast multicast;
104 struct ib_sa_client *client;
105 struct mcast_group *group;
106 struct list_head list;
107 enum mcast_state state;
108 atomic_t refcount;
109 struct completion comp;
110};
111
112static void join_handler(int status, struct ib_sa_mcmember_rec *rec,
113 void *context);
114static void leave_handler(int status, struct ib_sa_mcmember_rec *rec,
115 void *context);
116
117static struct mcast_group *mcast_find(struct mcast_port *port,
118 union ib_gid *mgid)
119{
120 struct rb_node *node = port->table.rb_node;
121 struct mcast_group *group;
122 int ret;
123
124 while (node) {
125 group = rb_entry(node, struct mcast_group, node);
126 ret = memcmp(mgid->raw, group->rec.mgid.raw, sizeof *mgid);
127 if (!ret)
128 return group;
129
130 if (ret < 0)
131 node = node->rb_left;
132 else
133 node = node->rb_right;
134 }
135 return NULL;
136}
137
138static struct mcast_group *mcast_insert(struct mcast_port *port,
139 struct mcast_group *group,
140 int allow_duplicates)
141{
142 struct rb_node **link = &port->table.rb_node;
143 struct rb_node *parent = NULL;
144 struct mcast_group *cur_group;
145 int ret;
146
147 while (*link) {
148 parent = *link;
149 cur_group = rb_entry(parent, struct mcast_group, node);
150
151 ret = memcmp(group->rec.mgid.raw, cur_group->rec.mgid.raw,
152 sizeof group->rec.mgid);
153 if (ret < 0)
154 link = &(*link)->rb_left;
155 else if (ret > 0)
156 link = &(*link)->rb_right;
157 else if (allow_duplicates)
158 link = &(*link)->rb_left;
159 else
160 return cur_group;
161 }
162 rb_link_node(&group->node, parent, link);
163 rb_insert_color(&group->node, &port->table);
164 return NULL;
165}
166
167static void deref_port(struct mcast_port *port)
168{
169 if (atomic_dec_and_test(&port->refcount))
170 complete(&port->comp);
171}
172
173static void release_group(struct mcast_group *group)
174{
175 struct mcast_port *port = group->port;
176 unsigned long flags;
177
178 spin_lock_irqsave(&port->lock, flags);
179 if (atomic_dec_and_test(&group->refcount)) {
180 rb_erase(&group->node, &port->table);
181 spin_unlock_irqrestore(&port->lock, flags);
182 kfree(group);
183 deref_port(port);
184 } else
185 spin_unlock_irqrestore(&port->lock, flags);
186}
187
188static void deref_member(struct mcast_member *member)
189{
190 if (atomic_dec_and_test(&member->refcount))
191 complete(&member->comp);
192}
193
194static void queue_join(struct mcast_member *member)
195{
196 struct mcast_group *group = member->group;
197 unsigned long flags;
198
199 spin_lock_irqsave(&group->lock, flags);
200 list_add(&member->list, &group->pending_list);
201 if (group->state == MCAST_IDLE) {
202 group->state = MCAST_BUSY;
203 atomic_inc(&group->refcount);
204 queue_work(mcast_wq, &group->work);
205 }
206 spin_unlock_irqrestore(&group->lock, flags);
207}
208
209/*
210 * A multicast group has three types of members: full member, non member, and
211 * send only member. We need to keep track of the number of members of each
212 * type based on their join state. Adjust the number of members the belong to
213 * the specified join states.
214 */
215static void adjust_membership(struct mcast_group *group, u8 join_state, int inc)
216{
217 int i;
218
219 for (i = 0; i < 3; i++, join_state >>= 1)
220 if (join_state & 0x1)
221 group->members[i] += inc;
222}
223
224/*
225 * If a multicast group has zero members left for a particular join state, but
226 * the group is still a member with the SA, we need to leave that join state.
227 * Determine which join states we still belong to, but that do not have any
228 * active members.
229 */
230static u8 get_leave_state(struct mcast_group *group)
231{
232 u8 leave_state = 0;
233 int i;
234
235 for (i = 0; i < 3; i++)
236 if (!group->members[i])
237 leave_state |= (0x1 << i);
238
239 return leave_state & group->rec.join_state;
240}
241
242static int check_selector(ib_sa_comp_mask comp_mask,
243 ib_sa_comp_mask selector_mask,
244 ib_sa_comp_mask value_mask,
245 u8 selector, u8 src_value, u8 dst_value)
246{
247 int err;
248
249 if (!(comp_mask & selector_mask) || !(comp_mask & value_mask))
250 return 0;
251
252 switch (selector) {
253 case IB_SA_GT:
254 err = (src_value <= dst_value);
255 break;
256 case IB_SA_LT:
257 err = (src_value >= dst_value);
258 break;
259 case IB_SA_EQ:
260 err = (src_value != dst_value);
261 break;
262 default:
263 err = 0;
264 break;
265 }
266
267 return err;
268}
269
270static int cmp_rec(struct ib_sa_mcmember_rec *src,
271 struct ib_sa_mcmember_rec *dst, ib_sa_comp_mask comp_mask)
272{
273 /* MGID must already match */
274
275 if (comp_mask & IB_SA_MCMEMBER_REC_PORT_GID &&
276 memcmp(&src->port_gid, &dst->port_gid, sizeof src->port_gid))
277 return -EINVAL;
278 if (comp_mask & IB_SA_MCMEMBER_REC_QKEY && src->qkey != dst->qkey)
279 return -EINVAL;
280 if (comp_mask & IB_SA_MCMEMBER_REC_MLID && src->mlid != dst->mlid)
281 return -EINVAL;
282 if (check_selector(comp_mask, IB_SA_MCMEMBER_REC_MTU_SELECTOR,
283 IB_SA_MCMEMBER_REC_MTU, dst->mtu_selector,
284 src->mtu, dst->mtu))
285 return -EINVAL;
286 if (comp_mask & IB_SA_MCMEMBER_REC_TRAFFIC_CLASS &&
287 src->traffic_class != dst->traffic_class)
288 return -EINVAL;
289 if (comp_mask & IB_SA_MCMEMBER_REC_PKEY && src->pkey != dst->pkey)
290 return -EINVAL;
291 if (check_selector(comp_mask, IB_SA_MCMEMBER_REC_RATE_SELECTOR,
292 IB_SA_MCMEMBER_REC_RATE, dst->rate_selector,
293 src->rate, dst->rate))
294 return -EINVAL;
295 if (check_selector(comp_mask,
296 IB_SA_MCMEMBER_REC_PACKET_LIFE_TIME_SELECTOR,
297 IB_SA_MCMEMBER_REC_PACKET_LIFE_TIME,
298 dst->packet_life_time_selector,
299 src->packet_life_time, dst->packet_life_time))
300 return -EINVAL;
301 if (comp_mask & IB_SA_MCMEMBER_REC_SL && src->sl != dst->sl)
302 return -EINVAL;
303 if (comp_mask & IB_SA_MCMEMBER_REC_FLOW_LABEL &&
304 src->flow_label != dst->flow_label)
305 return -EINVAL;
306 if (comp_mask & IB_SA_MCMEMBER_REC_HOP_LIMIT &&
307 src->hop_limit != dst->hop_limit)
308 return -EINVAL;
309 if (comp_mask & IB_SA_MCMEMBER_REC_SCOPE && src->scope != dst->scope)
310 return -EINVAL;
311
312 /* join_state checked separately, proxy_join ignored */
313
314 return 0;
315}
316
317static int send_join(struct mcast_group *group, struct mcast_member *member)
318{
319 struct mcast_port *port = group->port;
320 int ret;
321
322 group->last_join = member;
323 ret = ib_sa_mcmember_rec_query(&sa_client, port->dev->device,
324 port->port_num, IB_MGMT_METHOD_SET,
325 &member->multicast.rec,
326 member->multicast.comp_mask,
327 3000, GFP_KERNEL, join_handler, group,
328 &group->query);
329 if (ret >= 0) {
330 group->query_id = ret;
331 ret = 0;
332 }
333 return ret;
334}
335
336static int send_leave(struct mcast_group *group, u8 leave_state)
337{
338 struct mcast_port *port = group->port;
339 struct ib_sa_mcmember_rec rec;
340 int ret;
341
342 rec = group->rec;
343 rec.join_state = leave_state;
344
345 ret = ib_sa_mcmember_rec_query(&sa_client, port->dev->device,
346 port->port_num, IB_SA_METHOD_DELETE, &rec,
347 IB_SA_MCMEMBER_REC_MGID |
348 IB_SA_MCMEMBER_REC_PORT_GID |
349 IB_SA_MCMEMBER_REC_JOIN_STATE,
350 3000, GFP_KERNEL, leave_handler,
351 group, &group->query);
352 if (ret >= 0) {
353 group->query_id = ret;
354 ret = 0;
355 }
356 return ret;
357}
358
359static void join_group(struct mcast_group *group, struct mcast_member *member,
360 u8 join_state)
361{
362 member->state = MCAST_MEMBER;
363 adjust_membership(group, join_state, 1);
364 group->rec.join_state |= join_state;
365 member->multicast.rec = group->rec;
366 member->multicast.rec.join_state = join_state;
367 list_move(&member->list, &group->active_list);
368}
369
370static int fail_join(struct mcast_group *group, struct mcast_member *member,
371 int status)
372{
373 spin_lock_irq(&group->lock);
374 list_del_init(&member->list);
375 spin_unlock_irq(&group->lock);
376 return member->multicast.callback(status, &member->multicast);
377}
378
379static void process_group_error(struct mcast_group *group)
380{
381 struct mcast_member *member;
382 int ret;
383
384 spin_lock_irq(&group->lock);
385 while (!list_empty(&group->active_list)) {
386 member = list_entry(group->active_list.next,
387 struct mcast_member, list);
388 atomic_inc(&member->refcount);
389 list_del_init(&member->list);
390 adjust_membership(group, member->multicast.rec.join_state, -1);
391 member->state = MCAST_ERROR;
392 spin_unlock_irq(&group->lock);
393
394 ret = member->multicast.callback(-ENETRESET,
395 &member->multicast);
396 deref_member(member);
397 if (ret)
398 ib_sa_free_multicast(&member->multicast);
399 spin_lock_irq(&group->lock);
400 }
401
402 group->rec.join_state = 0;
403 group->state = MCAST_BUSY;
404 spin_unlock_irq(&group->lock);
405}
406
407static void mcast_work_handler(struct work_struct *work)
408{
409 struct mcast_group *group;
410 struct mcast_member *member;
411 struct ib_sa_multicast *multicast;
412 int status, ret;
413 u8 join_state;
414
415 group = container_of(work, typeof(*group), work);
416retest:
417 spin_lock_irq(&group->lock);
418 while (!list_empty(&group->pending_list) ||
419 (group->state == MCAST_ERROR)) {
420
421 if (group->state == MCAST_ERROR) {
422 spin_unlock_irq(&group->lock);
423 process_group_error(group);
424 goto retest;
425 }
426
427 member = list_entry(group->pending_list.next,
428 struct mcast_member, list);
429 multicast = &member->multicast;
430 join_state = multicast->rec.join_state;
431 atomic_inc(&member->refcount);
432
433 if (join_state == (group->rec.join_state & join_state)) {
434 status = cmp_rec(&group->rec, &multicast->rec,
435 multicast->comp_mask);
436 if (!status)
437 join_group(group, member, join_state);
438 else
439 list_del_init(&member->list);
440 spin_unlock_irq(&group->lock);
441 ret = multicast->callback(status, multicast);
442 } else {
443 spin_unlock_irq(&group->lock);
444 status = send_join(group, member);
445 if (!status) {
446 deref_member(member);
447 return;
448 }
449 ret = fail_join(group, member, status);
450 }
451
452 deref_member(member);
453 if (ret)
454 ib_sa_free_multicast(&member->multicast);
455 spin_lock_irq(&group->lock);
456 }
457
458 join_state = get_leave_state(group);
459 if (join_state) {
460 group->rec.join_state &= ~join_state;
461 spin_unlock_irq(&group->lock);
462 if (send_leave(group, join_state))
463 goto retest;
464 } else {
465 group->state = MCAST_IDLE;
466 spin_unlock_irq(&group->lock);
467 release_group(group);
468 }
469}
470
471/*
472 * Fail a join request if it is still active - at the head of the pending queue.
473 */
474static void process_join_error(struct mcast_group *group, int status)
475{
476 struct mcast_member *member;
477 int ret;
478
479 spin_lock_irq(&group->lock);
480 member = list_entry(group->pending_list.next,
481 struct mcast_member, list);
482 if (group->last_join == member) {
483 atomic_inc(&member->refcount);
484 list_del_init(&member->list);
485 spin_unlock_irq(&group->lock);
486 ret = member->multicast.callback(status, &member->multicast);
487 deref_member(member);
488 if (ret)
489 ib_sa_free_multicast(&member->multicast);
490 } else
491 spin_unlock_irq(&group->lock);
492}
493
494static void join_handler(int status, struct ib_sa_mcmember_rec *rec,
495 void *context)
496{
497 struct mcast_group *group = context;
498
499 if (status)
500 process_join_error(group, status);
501 else {
502 spin_lock_irq(&group->port->lock);
503 group->rec = *rec;
504 if (!memcmp(&mgid0, &group->rec.mgid, sizeof mgid0)) {
505 rb_erase(&group->node, &group->port->table);
506 mcast_insert(group->port, group, 1);
507 }
508 spin_unlock_irq(&group->port->lock);
509 }
510 mcast_work_handler(&group->work);
511}
512
513static void leave_handler(int status, struct ib_sa_mcmember_rec *rec,
514 void *context)
515{
516 struct mcast_group *group = context;
517
518 mcast_work_handler(&group->work);
519}
520
521static struct mcast_group *acquire_group(struct mcast_port *port,
522 union ib_gid *mgid, gfp_t gfp_mask)
523{
524 struct mcast_group *group, *cur_group;
525 unsigned long flags;
526 int is_mgid0;
527
528 is_mgid0 = !memcmp(&mgid0, mgid, sizeof mgid0);
529 if (!is_mgid0) {
530 spin_lock_irqsave(&port->lock, flags);
531 group = mcast_find(port, mgid);
532 if (group)
533 goto found;
534 spin_unlock_irqrestore(&port->lock, flags);
535 }
536
537 group = kzalloc(sizeof *group, gfp_mask);
538 if (!group)
539 return NULL;
540
541 group->port = port;
542 group->rec.mgid = *mgid;
543 INIT_LIST_HEAD(&group->pending_list);
544 INIT_LIST_HEAD(&group->active_list);
545 INIT_WORK(&group->work, mcast_work_handler);
546 spin_lock_init(&group->lock);
547
548 spin_lock_irqsave(&port->lock, flags);
549 cur_group = mcast_insert(port, group, is_mgid0);
550 if (cur_group) {
551 kfree(group);
552 group = cur_group;
553 } else
554 atomic_inc(&port->refcount);
555found:
556 atomic_inc(&group->refcount);
557 spin_unlock_irqrestore(&port->lock, flags);
558 return group;
559}
560
561/*
562 * We serialize all join requests to a single group to make our lives much
563 * easier. Otherwise, two users could try to join the same group
564 * simultaneously, with different configurations, one could leave while the
565 * join is in progress, etc., which makes locking around error recovery
566 * difficult.
567 */
568struct ib_sa_multicast *
569ib_sa_join_multicast(struct ib_sa_client *client,
570 struct ib_device *device, u8 port_num,
571 struct ib_sa_mcmember_rec *rec,
572 ib_sa_comp_mask comp_mask, gfp_t gfp_mask,
573 int (*callback)(int status,
574 struct ib_sa_multicast *multicast),
575 void *context)
576{
577 struct mcast_device *dev;
578 struct mcast_member *member;
579 struct ib_sa_multicast *multicast;
580 int ret;
581
582 dev = ib_get_client_data(device, &mcast_client);
583 if (!dev)
584 return ERR_PTR(-ENODEV);
585
586 member = kmalloc(sizeof *member, gfp_mask);
587 if (!member)
588 return ERR_PTR(-ENOMEM);
589
590 ib_sa_client_get(client);
591 member->client = client;
592 member->multicast.rec = *rec;
593 member->multicast.comp_mask = comp_mask;
594 member->multicast.callback = callback;
595 member->multicast.context = context;
596 init_completion(&member->comp);
597 atomic_set(&member->refcount, 1);
598 member->state = MCAST_JOINING;
599
600 member->group = acquire_group(&dev->port[port_num - dev->start_port],
601 &rec->mgid, gfp_mask);
602 if (!member->group) {
603 ret = -ENOMEM;
604 goto err;
605 }
606
607 /*
608 * The user will get the multicast structure in their callback. They
609 * could then free the multicast structure before we can return from
610 * this routine. So we save the pointer to return before queuing
611 * any callback.
612 */
613 multicast = &member->multicast;
614 queue_join(member);
615 return multicast;
616
617err:
618 ib_sa_client_put(client);
619 kfree(member);
620 return ERR_PTR(ret);
621}
622EXPORT_SYMBOL(ib_sa_join_multicast);
623
624void ib_sa_free_multicast(struct ib_sa_multicast *multicast)
625{
626 struct mcast_member *member;
627 struct mcast_group *group;
628
629 member = container_of(multicast, struct mcast_member, multicast);
630 group = member->group;
631
632 spin_lock_irq(&group->lock);
633 if (member->state == MCAST_MEMBER)
634 adjust_membership(group, multicast->rec.join_state, -1);
635
636 list_del_init(&member->list);
637
638 if (group->state == MCAST_IDLE) {
639 group->state = MCAST_BUSY;
640 spin_unlock_irq(&group->lock);
641 /* Continue to hold reference on group until callback */
642 queue_work(mcast_wq, &group->work);
643 } else {
644 spin_unlock_irq(&group->lock);
645 release_group(group);
646 }
647
648 deref_member(member);
649 wait_for_completion(&member->comp);
650 ib_sa_client_put(member->client);
651 kfree(member);
652}
653EXPORT_SYMBOL(ib_sa_free_multicast);
654
655int ib_sa_get_mcmember_rec(struct ib_device *device, u8 port_num,
656 union ib_gid *mgid, struct ib_sa_mcmember_rec *rec)
657{
658 struct mcast_device *dev;
659 struct mcast_port *port;
660 struct mcast_group *group;
661 unsigned long flags;
662 int ret = 0;
663
664 dev = ib_get_client_data(device, &mcast_client);
665 if (!dev)
666 return -ENODEV;
667
668 port = &dev->port[port_num - dev->start_port];
669 spin_lock_irqsave(&port->lock, flags);
670 group = mcast_find(port, mgid);
671 if (group)
672 *rec = group->rec;
673 else
674 ret = -EADDRNOTAVAIL;
675 spin_unlock_irqrestore(&port->lock, flags);
676
677 return ret;
678}
679EXPORT_SYMBOL(ib_sa_get_mcmember_rec);
680
681int ib_init_ah_from_mcmember(struct ib_device *device, u8 port_num,
682 struct ib_sa_mcmember_rec *rec,
683 struct ib_ah_attr *ah_attr)
684{
685 int ret;
686 u16 gid_index;
687 u8 p;
688
689 ret = ib_find_cached_gid(device, &rec->port_gid, &p, &gid_index);
690 if (ret)
691 return ret;
692
693 memset(ah_attr, 0, sizeof *ah_attr);
694 ah_attr->dlid = be16_to_cpu(rec->mlid);
695 ah_attr->sl = rec->sl;
696 ah_attr->port_num = port_num;
697 ah_attr->static_rate = rec->rate;
698
699 ah_attr->ah_flags = IB_AH_GRH;
700 ah_attr->grh.dgid = rec->mgid;
701
702 ah_attr->grh.sgid_index = (u8) gid_index;
703 ah_attr->grh.flow_label = be32_to_cpu(rec->flow_label);
704 ah_attr->grh.hop_limit = rec->hop_limit;
705 ah_attr->grh.traffic_class = rec->traffic_class;
706
707 return 0;
708}
709EXPORT_SYMBOL(ib_init_ah_from_mcmember);
710
711static void mcast_groups_lost(struct mcast_port *port)
712{
713 struct mcast_group *group;
714 struct rb_node *node;
715 unsigned long flags;
716
717 spin_lock_irqsave(&port->lock, flags);
718 for (node = rb_first(&port->table); node; node = rb_next(node)) {
719 group = rb_entry(node, struct mcast_group, node);
720 spin_lock(&group->lock);
721 if (group->state == MCAST_IDLE) {
722 atomic_inc(&group->refcount);
723 queue_work(mcast_wq, &group->work);
724 }
725 group->state = MCAST_ERROR;
726 spin_unlock(&group->lock);
727 }
728 spin_unlock_irqrestore(&port->lock, flags);
729}
730
731static void mcast_event_handler(struct ib_event_handler *handler,
732 struct ib_event *event)
733{
734 struct mcast_device *dev;
735
736 dev = container_of(handler, struct mcast_device, event_handler);
737
738 switch (event->event) {
739 case IB_EVENT_PORT_ERR:
740 case IB_EVENT_LID_CHANGE:
741 case IB_EVENT_SM_CHANGE:
742 case IB_EVENT_CLIENT_REREGISTER:
743 mcast_groups_lost(&dev->port[event->element.port_num -
744 dev->start_port]);
745 break;
746 default:
747 break;
748 }
749}
750
751static void mcast_add_one(struct ib_device *device)
752{
753 struct mcast_device *dev;
754 struct mcast_port *port;
755 int i;
756
757 if (rdma_node_get_transport(device->node_type) != RDMA_TRANSPORT_IB)
758 return;
759
760 dev = kmalloc(sizeof *dev + device->phys_port_cnt * sizeof *port,
761 GFP_KERNEL);
762 if (!dev)
763 return;
764
765 if (device->node_type == RDMA_NODE_IB_SWITCH)
766 dev->start_port = dev->end_port = 0;
767 else {
768 dev->start_port = 1;
769 dev->end_port = device->phys_port_cnt;
770 }
771
772 for (i = 0; i <= dev->end_port - dev->start_port; i++) {
773 port = &dev->port[i];
774 port->dev = dev;
775 port->port_num = dev->start_port + i;
776 spin_lock_init(&port->lock);
777 port->table = RB_ROOT;
778 init_completion(&port->comp);
779 atomic_set(&port->refcount, 1);
780 }
781
782 dev->device = device;
783 ib_set_client_data(device, &mcast_client, dev);
784
785 INIT_IB_EVENT_HANDLER(&dev->event_handler, device, mcast_event_handler);
786 ib_register_event_handler(&dev->event_handler);
787}
788
789static void mcast_remove_one(struct ib_device *device)
790{
791 struct mcast_device *dev;
792 struct mcast_port *port;
793 int i;
794
795 dev = ib_get_client_data(device, &mcast_client);
796 if (!dev)
797 return;
798
799 ib_unregister_event_handler(&dev->event_handler);
800 flush_workqueue(mcast_wq);
801
802 for (i = 0; i <= dev->end_port - dev->start_port; i++) {
803 port = &dev->port[i];
804 deref_port(port);
805 wait_for_completion(&port->comp);
806 }
807
808 kfree(dev);
809}
810
811int mcast_init(void)
812{
813 int ret;
814
815 mcast_wq = create_singlethread_workqueue("ib_mcast");
816 if (!mcast_wq)
817 return -ENOMEM;
818
819 ib_sa_register_client(&sa_client);
820
821 ret = ib_register_client(&mcast_client);
822 if (ret)
823 goto err;
824 return 0;
825
826err:
827 ib_sa_unregister_client(&sa_client);
828 destroy_workqueue(mcast_wq);
829 return ret;
830}
831
832void mcast_cleanup(void)
833{
834 ib_unregister_client(&mcast_client);
835 ib_sa_unregister_client(&sa_client);
836 destroy_workqueue(mcast_wq);
837}
diff --git a/drivers/infiniband/core/sa.h b/drivers/infiniband/core/sa.h
new file mode 100644
index 000000000000..24c93fd320fb
--- /dev/null
+++ b/drivers/infiniband/core/sa.h
@@ -0,0 +1,66 @@
1/*
2 * Copyright (c) 2004 Topspin Communications. All rights reserved.
3 * Copyright (c) 2005 Voltaire, Inc.  All rights reserved.
4 * Copyright (c) 2006 Intel Corporation. All rights reserved.
5 *
6 * This software is available to you under a choice of one of two
7 * licenses. You may choose to be licensed under the terms of the GNU
8 * General Public License (GPL) Version 2, available from the file
9 * COPYING in the main directory of this source tree, or the
10 * OpenIB.org BSD license below:
11 *
12 * Redistribution and use in source and binary forms, with or
13 * without modification, are permitted provided that the following
14 * conditions are met:
15 *
16 * - Redistributions of source code must retain the above
17 * copyright notice, this list of conditions and the following
18 * disclaimer.
19 *
20 * - Redistributions in binary form must reproduce the above
21 * copyright notice, this list of conditions and the following
22 * disclaimer in the documentation and/or other materials
23 * provided with the distribution.
24 *
25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32 * SOFTWARE.
33 */
34
35#ifndef SA_H
36#define SA_H
37
38#include <rdma/ib_sa.h>
39
40static inline void ib_sa_client_get(struct ib_sa_client *client)
41{
42 atomic_inc(&client->users);
43}
44
45static inline void ib_sa_client_put(struct ib_sa_client *client)
46{
47 if (atomic_dec_and_test(&client->users))
48 complete(&client->comp);
49}
50
51int ib_sa_mcmember_rec_query(struct ib_sa_client *client,
52 struct ib_device *device, u8 port_num,
53 u8 method,
54 struct ib_sa_mcmember_rec *rec,
55 ib_sa_comp_mask comp_mask,
56 int timeout_ms, gfp_t gfp_mask,
57 void (*callback)(int status,
58 struct ib_sa_mcmember_rec *resp,
59 void *context),
60 void *context,
61 struct ib_sa_query **sa_query);
62
63int mcast_init(void);
64void mcast_cleanup(void);
65
66#endif /* SA_H */
diff --git a/drivers/infiniband/core/sa_query.c b/drivers/infiniband/core/sa_query.c
index e45afba75341..68db633711c5 100644
--- a/drivers/infiniband/core/sa_query.c
+++ b/drivers/infiniband/core/sa_query.c
@@ -47,8 +47,8 @@
47#include <linux/workqueue.h> 47#include <linux/workqueue.h>
48 48
49#include <rdma/ib_pack.h> 49#include <rdma/ib_pack.h>
50#include <rdma/ib_sa.h>
51#include <rdma/ib_cache.h> 50#include <rdma/ib_cache.h>
51#include "sa.h"
52 52
53MODULE_AUTHOR("Roland Dreier"); 53MODULE_AUTHOR("Roland Dreier");
54MODULE_DESCRIPTION("InfiniBand subnet administration query support"); 54MODULE_DESCRIPTION("InfiniBand subnet administration query support");
@@ -425,17 +425,6 @@ void ib_sa_register_client(struct ib_sa_client *client)
425} 425}
426EXPORT_SYMBOL(ib_sa_register_client); 426EXPORT_SYMBOL(ib_sa_register_client);
427 427
428static inline void ib_sa_client_get(struct ib_sa_client *client)
429{
430 atomic_inc(&client->users);
431}
432
433static inline void ib_sa_client_put(struct ib_sa_client *client)
434{
435 if (atomic_dec_and_test(&client->users))
436 complete(&client->comp);
437}
438
439void ib_sa_unregister_client(struct ib_sa_client *client) 428void ib_sa_unregister_client(struct ib_sa_client *client)
440{ 429{
441 ib_sa_client_put(client); 430 ib_sa_client_put(client);
@@ -482,6 +471,7 @@ int ib_init_ah_from_path(struct ib_device *device, u8 port_num,
482 ah_attr->sl = rec->sl; 471 ah_attr->sl = rec->sl;
483 ah_attr->src_path_bits = be16_to_cpu(rec->slid) & 0x7f; 472 ah_attr->src_path_bits = be16_to_cpu(rec->slid) & 0x7f;
484 ah_attr->port_num = port_num; 473 ah_attr->port_num = port_num;
474 ah_attr->static_rate = rec->rate;
485 475
486 if (rec->hop_limit > 1) { 476 if (rec->hop_limit > 1) {
487 ah_attr->ah_flags = IB_AH_GRH; 477 ah_attr->ah_flags = IB_AH_GRH;
@@ -901,7 +891,6 @@ err1:
901 kfree(query); 891 kfree(query);
902 return ret; 892 return ret;
903} 893}
904EXPORT_SYMBOL(ib_sa_mcmember_rec_query);
905 894
906static void send_handler(struct ib_mad_agent *agent, 895static void send_handler(struct ib_mad_agent *agent,
907 struct ib_mad_send_wc *mad_send_wc) 896 struct ib_mad_send_wc *mad_send_wc)
@@ -1053,14 +1042,27 @@ static int __init ib_sa_init(void)
1053 get_random_bytes(&tid, sizeof tid); 1042 get_random_bytes(&tid, sizeof tid);
1054 1043
1055 ret = ib_register_client(&sa_client); 1044 ret = ib_register_client(&sa_client);
1056 if (ret) 1045 if (ret) {
1057 printk(KERN_ERR "Couldn't register ib_sa client\n"); 1046 printk(KERN_ERR "Couldn't register ib_sa client\n");
1047 goto err1;
1048 }
1049
1050 ret = mcast_init();
1051 if (ret) {
1052 printk(KERN_ERR "Couldn't initialize multicast handling\n");
1053 goto err2;
1054 }
1058 1055
1056 return 0;
1057err2:
1058 ib_unregister_client(&sa_client);
1059err1:
1059 return ret; 1060 return ret;
1060} 1061}
1061 1062
1062static void __exit ib_sa_cleanup(void) 1063static void __exit ib_sa_cleanup(void)
1063{ 1064{
1065 mcast_cleanup();
1064 ib_unregister_client(&sa_client); 1066 ib_unregister_client(&sa_client);
1065 idr_destroy(&query_idr); 1067 idr_destroy(&query_idr);
1066} 1068}
diff --git a/drivers/infiniband/core/sysfs.c b/drivers/infiniband/core/sysfs.c
index 709323c14c5d..000c086bf2e9 100644
--- a/drivers/infiniband/core/sysfs.c
+++ b/drivers/infiniband/core/sysfs.c
@@ -714,8 +714,6 @@ int ib_device_register_sysfs(struct ib_device *device)
714 if (ret) 714 if (ret)
715 goto err_put; 715 goto err_put;
716 } else { 716 } else {
717 int i;
718
719 for (i = 1; i <= device->phys_port_cnt; ++i) { 717 for (i = 1; i <= device->phys_port_cnt; ++i) {
720 ret = add_port(device, i); 718 ret = add_port(device, i);
721 if (ret) 719 if (ret)
diff --git a/drivers/infiniband/core/ucma.c b/drivers/infiniband/core/ucma.c
index 6b81b98961c7..b516b93b8550 100644
--- a/drivers/infiniband/core/ucma.c
+++ b/drivers/infiniband/core/ucma.c
@@ -70,10 +70,24 @@ struct ucma_context {
70 u64 uid; 70 u64 uid;
71 71
72 struct list_head list; 72 struct list_head list;
73 struct list_head mc_list;
74};
75
76struct ucma_multicast {
77 struct ucma_context *ctx;
78 int id;
79 int events_reported;
80
81 u64 uid;
82 struct list_head list;
83 struct sockaddr addr;
84 u8 pad[sizeof(struct sockaddr_in6) -
85 sizeof(struct sockaddr)];
73}; 86};
74 87
75struct ucma_event { 88struct ucma_event {
76 struct ucma_context *ctx; 89 struct ucma_context *ctx;
90 struct ucma_multicast *mc;
77 struct list_head list; 91 struct list_head list;
78 struct rdma_cm_id *cm_id; 92 struct rdma_cm_id *cm_id;
79 struct rdma_ucm_event_resp resp; 93 struct rdma_ucm_event_resp resp;
@@ -81,6 +95,7 @@ struct ucma_event {
81 95
82static DEFINE_MUTEX(mut); 96static DEFINE_MUTEX(mut);
83static DEFINE_IDR(ctx_idr); 97static DEFINE_IDR(ctx_idr);
98static DEFINE_IDR(multicast_idr);
84 99
85static inline struct ucma_context *_ucma_find_context(int id, 100static inline struct ucma_context *_ucma_find_context(int id,
86 struct ucma_file *file) 101 struct ucma_file *file)
@@ -124,6 +139,7 @@ static struct ucma_context *ucma_alloc_ctx(struct ucma_file *file)
124 139
125 atomic_set(&ctx->ref, 1); 140 atomic_set(&ctx->ref, 1);
126 init_completion(&ctx->comp); 141 init_completion(&ctx->comp);
142 INIT_LIST_HEAD(&ctx->mc_list);
127 ctx->file = file; 143 ctx->file = file;
128 144
129 do { 145 do {
@@ -147,6 +163,37 @@ error:
147 return NULL; 163 return NULL;
148} 164}
149 165
166static struct ucma_multicast* ucma_alloc_multicast(struct ucma_context *ctx)
167{
168 struct ucma_multicast *mc;
169 int ret;
170
171 mc = kzalloc(sizeof(*mc), GFP_KERNEL);
172 if (!mc)
173 return NULL;
174
175 do {
176 ret = idr_pre_get(&multicast_idr, GFP_KERNEL);
177 if (!ret)
178 goto error;
179
180 mutex_lock(&mut);
181 ret = idr_get_new(&multicast_idr, mc, &mc->id);
182 mutex_unlock(&mut);
183 } while (ret == -EAGAIN);
184
185 if (ret)
186 goto error;
187
188 mc->ctx = ctx;
189 list_add_tail(&mc->list, &ctx->mc_list);
190 return mc;
191
192error:
193 kfree(mc);
194 return NULL;
195}
196
150static void ucma_copy_conn_event(struct rdma_ucm_conn_param *dst, 197static void ucma_copy_conn_event(struct rdma_ucm_conn_param *dst,
151 struct rdma_conn_param *src) 198 struct rdma_conn_param *src)
152{ 199{
@@ -180,8 +227,19 @@ static void ucma_set_event_context(struct ucma_context *ctx,
180 struct ucma_event *uevent) 227 struct ucma_event *uevent)
181{ 228{
182 uevent->ctx = ctx; 229 uevent->ctx = ctx;
183 uevent->resp.uid = ctx->uid; 230 switch (event->event) {
184 uevent->resp.id = ctx->id; 231 case RDMA_CM_EVENT_MULTICAST_JOIN:
232 case RDMA_CM_EVENT_MULTICAST_ERROR:
233 uevent->mc = (struct ucma_multicast *)
234 event->param.ud.private_data;
235 uevent->resp.uid = uevent->mc->uid;
236 uevent->resp.id = uevent->mc->id;
237 break;
238 default:
239 uevent->resp.uid = ctx->uid;
240 uevent->resp.id = ctx->id;
241 break;
242 }
185} 243}
186 244
187static int ucma_event_handler(struct rdma_cm_id *cm_id, 245static int ucma_event_handler(struct rdma_cm_id *cm_id,
@@ -199,7 +257,7 @@ static int ucma_event_handler(struct rdma_cm_id *cm_id,
199 ucma_set_event_context(ctx, event, uevent); 257 ucma_set_event_context(ctx, event, uevent);
200 uevent->resp.event = event->event; 258 uevent->resp.event = event->event;
201 uevent->resp.status = event->status; 259 uevent->resp.status = event->status;
202 if (cm_id->ps == RDMA_PS_UDP) 260 if (cm_id->ps == RDMA_PS_UDP || cm_id->ps == RDMA_PS_IPOIB)
203 ucma_copy_ud_event(&uevent->resp.param.ud, &event->param.ud); 261 ucma_copy_ud_event(&uevent->resp.param.ud, &event->param.ud);
204 else 262 else
205 ucma_copy_conn_event(&uevent->resp.param.conn, 263 ucma_copy_conn_event(&uevent->resp.param.conn,
@@ -290,6 +348,8 @@ static ssize_t ucma_get_event(struct ucma_file *file, const char __user *inbuf,
290 348
291 list_del(&uevent->list); 349 list_del(&uevent->list);
292 uevent->ctx->events_reported++; 350 uevent->ctx->events_reported++;
351 if (uevent->mc)
352 uevent->mc->events_reported++;
293 kfree(uevent); 353 kfree(uevent);
294done: 354done:
295 mutex_unlock(&file->mut); 355 mutex_unlock(&file->mut);
@@ -342,6 +402,19 @@ err1:
342 return ret; 402 return ret;
343} 403}
344 404
405static void ucma_cleanup_multicast(struct ucma_context *ctx)
406{
407 struct ucma_multicast *mc, *tmp;
408
409 mutex_lock(&mut);
410 list_for_each_entry_safe(mc, tmp, &ctx->mc_list, list) {
411 list_del(&mc->list);
412 idr_remove(&multicast_idr, mc->id);
413 kfree(mc);
414 }
415 mutex_unlock(&mut);
416}
417
345static void ucma_cleanup_events(struct ucma_context *ctx) 418static void ucma_cleanup_events(struct ucma_context *ctx)
346{ 419{
347 struct ucma_event *uevent, *tmp; 420 struct ucma_event *uevent, *tmp;
@@ -360,6 +433,19 @@ static void ucma_cleanup_events(struct ucma_context *ctx)
360 } 433 }
361} 434}
362 435
436static void ucma_cleanup_mc_events(struct ucma_multicast *mc)
437{
438 struct ucma_event *uevent, *tmp;
439
440 list_for_each_entry_safe(uevent, tmp, &mc->ctx->file->event_list, list) {
441 if (uevent->mc != mc)
442 continue;
443
444 list_del(&uevent->list);
445 kfree(uevent);
446 }
447}
448
363static int ucma_free_ctx(struct ucma_context *ctx) 449static int ucma_free_ctx(struct ucma_context *ctx)
364{ 450{
365 int events_reported; 451 int events_reported;
@@ -367,6 +453,8 @@ static int ucma_free_ctx(struct ucma_context *ctx)
367 /* No new events will be generated after destroying the id. */ 453 /* No new events will be generated after destroying the id. */
368 rdma_destroy_id(ctx->cm_id); 454 rdma_destroy_id(ctx->cm_id);
369 455
456 ucma_cleanup_multicast(ctx);
457
370 /* Cleanup events not yet reported to the user. */ 458 /* Cleanup events not yet reported to the user. */
371 mutex_lock(&ctx->file->mut); 459 mutex_lock(&ctx->file->mut);
372 ucma_cleanup_events(ctx); 460 ucma_cleanup_events(ctx);
@@ -731,6 +819,114 @@ static ssize_t ucma_notify(struct ucma_file *file, const char __user *inbuf,
731 return ret; 819 return ret;
732} 820}
733 821
822static ssize_t ucma_join_multicast(struct ucma_file *file,
823 const char __user *inbuf,
824 int in_len, int out_len)
825{
826 struct rdma_ucm_join_mcast cmd;
827 struct rdma_ucm_create_id_resp resp;
828 struct ucma_context *ctx;
829 struct ucma_multicast *mc;
830 int ret;
831
832 if (out_len < sizeof(resp))
833 return -ENOSPC;
834
835 if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
836 return -EFAULT;
837
838 ctx = ucma_get_ctx(file, cmd.id);
839 if (IS_ERR(ctx))
840 return PTR_ERR(ctx);
841
842 mutex_lock(&file->mut);
843 mc = ucma_alloc_multicast(ctx);
844 if (IS_ERR(mc)) {
845 ret = PTR_ERR(mc);
846 goto err1;
847 }
848
849 mc->uid = cmd.uid;
850 memcpy(&mc->addr, &cmd.addr, sizeof cmd.addr);
851 ret = rdma_join_multicast(ctx->cm_id, &mc->addr, mc);
852 if (ret)
853 goto err2;
854
855 resp.id = mc->id;
856 if (copy_to_user((void __user *)(unsigned long)cmd.response,
857 &resp, sizeof(resp))) {
858 ret = -EFAULT;
859 goto err3;
860 }
861
862 mutex_unlock(&file->mut);
863 ucma_put_ctx(ctx);
864 return 0;
865
866err3:
867 rdma_leave_multicast(ctx->cm_id, &mc->addr);
868 ucma_cleanup_mc_events(mc);
869err2:
870 mutex_lock(&mut);
871 idr_remove(&multicast_idr, mc->id);
872 mutex_unlock(&mut);
873 list_del(&mc->list);
874 kfree(mc);
875err1:
876 mutex_unlock(&file->mut);
877 ucma_put_ctx(ctx);
878 return ret;
879}
880
881static ssize_t ucma_leave_multicast(struct ucma_file *file,
882 const char __user *inbuf,
883 int in_len, int out_len)
884{
885 struct rdma_ucm_destroy_id cmd;
886 struct rdma_ucm_destroy_id_resp resp;
887 struct ucma_multicast *mc;
888 int ret = 0;
889
890 if (out_len < sizeof(resp))
891 return -ENOSPC;
892
893 if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
894 return -EFAULT;
895
896 mutex_lock(&mut);
897 mc = idr_find(&multicast_idr, cmd.id);
898 if (!mc)
899 mc = ERR_PTR(-ENOENT);
900 else if (mc->ctx->file != file)
901 mc = ERR_PTR(-EINVAL);
902 else {
903 idr_remove(&multicast_idr, mc->id);
904 atomic_inc(&mc->ctx->ref);
905 }
906 mutex_unlock(&mut);
907
908 if (IS_ERR(mc)) {
909 ret = PTR_ERR(mc);
910 goto out;
911 }
912
913 rdma_leave_multicast(mc->ctx->cm_id, &mc->addr);
914 mutex_lock(&mc->ctx->file->mut);
915 ucma_cleanup_mc_events(mc);
916 list_del(&mc->list);
917 mutex_unlock(&mc->ctx->file->mut);
918
919 ucma_put_ctx(mc->ctx);
920 resp.events_reported = mc->events_reported;
921 kfree(mc);
922
923 if (copy_to_user((void __user *)(unsigned long)cmd.response,
924 &resp, sizeof(resp)))
925 ret = -EFAULT;
926out:
927 return ret;
928}
929
734static ssize_t (*ucma_cmd_table[])(struct ucma_file *file, 930static ssize_t (*ucma_cmd_table[])(struct ucma_file *file,
735 const char __user *inbuf, 931 const char __user *inbuf,
736 int in_len, int out_len) = { 932 int in_len, int out_len) = {
@@ -750,6 +946,8 @@ static ssize_t (*ucma_cmd_table[])(struct ucma_file *file,
750 [RDMA_USER_CM_CMD_GET_OPTION] = NULL, 946 [RDMA_USER_CM_CMD_GET_OPTION] = NULL,
751 [RDMA_USER_CM_CMD_SET_OPTION] = NULL, 947 [RDMA_USER_CM_CMD_SET_OPTION] = NULL,
752 [RDMA_USER_CM_CMD_NOTIFY] = ucma_notify, 948 [RDMA_USER_CM_CMD_NOTIFY] = ucma_notify,
949 [RDMA_USER_CM_CMD_JOIN_MCAST] = ucma_join_multicast,
950 [RDMA_USER_CM_CMD_LEAVE_MCAST] = ucma_leave_multicast,
753}; 951};
754 952
755static ssize_t ucma_write(struct file *filp, const char __user *buf, 953static ssize_t ucma_write(struct file *filp, const char __user *buf,
diff --git a/drivers/infiniband/hw/cxgb3/cxio_dbg.c b/drivers/infiniband/hw/cxgb3/cxio_dbg.c
index 5a7306f5efae..75f7b16a271d 100644
--- a/drivers/infiniband/hw/cxgb3/cxio_dbg.c
+++ b/drivers/infiniband/hw/cxgb3/cxio_dbg.c
@@ -1,6 +1,5 @@
1/* 1/*
2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved.
3 * Copyright (c) 2006 Open Grid Computing, Inc. All rights reserved.
4 * 3 *
5 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
diff --git a/drivers/infiniband/hw/cxgb3/cxio_hal.c b/drivers/infiniband/hw/cxgb3/cxio_hal.c
index 82fa72041989..114ac3b775dc 100644
--- a/drivers/infiniband/hw/cxgb3/cxio_hal.c
+++ b/drivers/infiniband/hw/cxgb3/cxio_hal.c
@@ -1,6 +1,5 @@
1/* 1/*
2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved.
3 * Copyright (c) 2006 Open Grid Computing, Inc. All rights reserved.
4 * 3 *
5 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
diff --git a/drivers/infiniband/hw/cxgb3/cxio_hal.h b/drivers/infiniband/hw/cxgb3/cxio_hal.h
index 1b97e80b8780..8ab04a7c6f6e 100644
--- a/drivers/infiniband/hw/cxgb3/cxio_hal.h
+++ b/drivers/infiniband/hw/cxgb3/cxio_hal.h
@@ -1,6 +1,5 @@
1/* 1/*
2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved.
3 * Copyright (c) 2006 Open Grid Computing, Inc. All rights reserved.
4 * 3 *
5 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
diff --git a/drivers/infiniband/hw/cxgb3/cxio_resource.c b/drivers/infiniband/hw/cxgb3/cxio_resource.c
index 997aa32cbf07..65bf577311aa 100644
--- a/drivers/infiniband/hw/cxgb3/cxio_resource.c
+++ b/drivers/infiniband/hw/cxgb3/cxio_resource.c
@@ -1,6 +1,5 @@
1/* 1/*
2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved.
3 * Copyright (c) 2006 Open Grid Computing, Inc. All rights reserved.
4 * 3 *
5 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
diff --git a/drivers/infiniband/hw/cxgb3/cxio_resource.h b/drivers/infiniband/hw/cxgb3/cxio_resource.h
index a6bbe8370d81..a2703a3d882d 100644
--- a/drivers/infiniband/hw/cxgb3/cxio_resource.h
+++ b/drivers/infiniband/hw/cxgb3/cxio_resource.h
@@ -1,6 +1,5 @@
1/* 1/*
2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved.
3 * Copyright (c) 2006 Open Grid Computing, Inc. All rights reserved.
4 * 3 *
5 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
diff --git a/drivers/infiniband/hw/cxgb3/cxio_wr.h b/drivers/infiniband/hw/cxgb3/cxio_wr.h
index 103fc42d6976..90d7b8972cb4 100644
--- a/drivers/infiniband/hw/cxgb3/cxio_wr.h
+++ b/drivers/infiniband/hw/cxgb3/cxio_wr.h
@@ -1,6 +1,5 @@
1/* 1/*
2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved.
3 * Copyright (c) 2006 Open Grid Computing, Inc. All rights reserved.
4 * 3 *
5 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
diff --git a/drivers/infiniband/hw/cxgb3/iwch.c b/drivers/infiniband/hw/cxgb3/iwch.c
index 4611afa52220..0315c9d9fce9 100644
--- a/drivers/infiniband/hw/cxgb3/iwch.c
+++ b/drivers/infiniband/hw/cxgb3/iwch.c
@@ -1,6 +1,5 @@
1/* 1/*
2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved.
3 * Copyright (c) 2006 Open Grid Computing, Inc. All rights reserved.
4 * 3 *
5 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
diff --git a/drivers/infiniband/hw/cxgb3/iwch.h b/drivers/infiniband/hw/cxgb3/iwch.h
index 6517ef85026f..caf4e6007a44 100644
--- a/drivers/infiniband/hw/cxgb3/iwch.h
+++ b/drivers/infiniband/hw/cxgb3/iwch.h
@@ -1,6 +1,5 @@
1/* 1/*
2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved.
3 * Copyright (c) 2006 Open Grid Computing, Inc. All rights reserved.
4 * 3 *
5 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
diff --git a/drivers/infiniband/hw/cxgb3/iwch_cm.c b/drivers/infiniband/hw/cxgb3/iwch_cm.c
index a522b1baa3b4..e5442e34b788 100644
--- a/drivers/infiniband/hw/cxgb3/iwch_cm.c
+++ b/drivers/infiniband/hw/cxgb3/iwch_cm.c
@@ -1,6 +1,5 @@
1/* 1/*
2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved.
3 * Copyright (c) 2006 Open Grid Computing, Inc. All rights reserved.
4 * 3 *
5 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
diff --git a/drivers/infiniband/hw/cxgb3/iwch_cm.h b/drivers/infiniband/hw/cxgb3/iwch_cm.h
index 7c810d904279..0c6f281bd4a0 100644
--- a/drivers/infiniband/hw/cxgb3/iwch_cm.h
+++ b/drivers/infiniband/hw/cxgb3/iwch_cm.h
@@ -1,6 +1,5 @@
1/* 1/*
2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved.
3 * Copyright (c) 2006 Open Grid Computing, Inc. All rights reserved.
4 * 3 *
5 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
diff --git a/drivers/infiniband/hw/cxgb3/iwch_cq.c b/drivers/infiniband/hw/cxgb3/iwch_cq.c
index 98b3bdb5de9e..d7624c170ee7 100644
--- a/drivers/infiniband/hw/cxgb3/iwch_cq.c
+++ b/drivers/infiniband/hw/cxgb3/iwch_cq.c
@@ -1,6 +1,5 @@
1/* 1/*
2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved.
3 * Copyright (c) 2006 Open Grid Computing, Inc. All rights reserved.
4 * 3 *
5 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
diff --git a/drivers/infiniband/hw/cxgb3/iwch_ev.c b/drivers/infiniband/hw/cxgb3/iwch_ev.c
index a6efa8fe15d8..54362afbf72f 100644
--- a/drivers/infiniband/hw/cxgb3/iwch_ev.c
+++ b/drivers/infiniband/hw/cxgb3/iwch_ev.c
@@ -1,6 +1,5 @@
1/* 1/*
2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved.
3 * Copyright (c) 2006 Open Grid Computing, Inc. All rights reserved.
4 * 3 *
5 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
diff --git a/drivers/infiniband/hw/cxgb3/iwch_mem.c b/drivers/infiniband/hw/cxgb3/iwch_mem.c
index 2b6cd53bb3fc..a6c2c4ba29e6 100644
--- a/drivers/infiniband/hw/cxgb3/iwch_mem.c
+++ b/drivers/infiniband/hw/cxgb3/iwch_mem.c
@@ -1,6 +1,5 @@
1/* 1/*
2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved.
3 * Copyright (c) 2006 Open Grid Computing, Inc. All rights reserved.
4 * 3 *
5 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
diff --git a/drivers/infiniband/hw/cxgb3/iwch_provider.c b/drivers/infiniband/hw/cxgb3/iwch_provider.c
index 6861087d776c..2aef122f9955 100644
--- a/drivers/infiniband/hw/cxgb3/iwch_provider.c
+++ b/drivers/infiniband/hw/cxgb3/iwch_provider.c
@@ -1,6 +1,5 @@
1/* 1/*
2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved.
3 * Copyright (c) 2006 Open Grid Computing, Inc. All rights reserved.
4 * 3 *
5 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
diff --git a/drivers/infiniband/hw/cxgb3/iwch_provider.h b/drivers/infiniband/hw/cxgb3/iwch_provider.h
index 61e3278fd7a8..2af3e93b607f 100644
--- a/drivers/infiniband/hw/cxgb3/iwch_provider.h
+++ b/drivers/infiniband/hw/cxgb3/iwch_provider.h
@@ -1,6 +1,5 @@
1/* 1/*
2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved.
3 * Copyright (c) 2006 Open Grid Computing, Inc. All rights reserved.
4 * 3 *
5 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
diff --git a/drivers/infiniband/hw/cxgb3/iwch_qp.c b/drivers/infiniband/hw/cxgb3/iwch_qp.c
index e066727504b6..4dda2f6da2de 100644
--- a/drivers/infiniband/hw/cxgb3/iwch_qp.c
+++ b/drivers/infiniband/hw/cxgb3/iwch_qp.c
@@ -1,6 +1,5 @@
1/* 1/*
2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved.
3 * Copyright (c) 2006 Open Grid Computing, Inc. All rights reserved.
4 * 3 *
5 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
@@ -846,6 +845,8 @@ int iwch_modify_qp(struct iwch_dev *rhp, struct iwch_qp *qhp,
846 break; 845 break;
847 case IWCH_QP_STATE_TERMINATE: 846 case IWCH_QP_STATE_TERMINATE:
848 qhp->attr.state = IWCH_QP_STATE_TERMINATE; 847 qhp->attr.state = IWCH_QP_STATE_TERMINATE;
848 if (t3b_device(qhp->rhp))
849 cxio_set_wq_in_error(&qhp->wq);
849 if (!internal) 850 if (!internal)
850 terminate = 1; 851 terminate = 1;
851 break; 852 break;
diff --git a/drivers/infiniband/hw/cxgb3/iwch_user.h b/drivers/infiniband/hw/cxgb3/iwch_user.h
index c4e7fbea8bbd..cb7086f558c1 100644
--- a/drivers/infiniband/hw/cxgb3/iwch_user.h
+++ b/drivers/infiniband/hw/cxgb3/iwch_user.h
@@ -1,6 +1,5 @@
1/* 1/*
2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved.
3 * Copyright (c) 2006 Open Grid Computing, Inc. All rights reserved.
4 * 3 *
5 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
diff --git a/drivers/infiniband/hw/ehca/Kconfig b/drivers/infiniband/hw/ehca/Kconfig
index 727b10d89686..1a854598e0e6 100644
--- a/drivers/infiniband/hw/ehca/Kconfig
+++ b/drivers/infiniband/hw/ehca/Kconfig
@@ -7,11 +7,3 @@ config INFINIBAND_EHCA
7 To compile the driver as a module, choose M here. The module 7 To compile the driver as a module, choose M here. The module
8 will be called ib_ehca. 8 will be called ib_ehca.
9 9
10config INFINIBAND_EHCA_SCALING
11 bool "Scaling support (EXPERIMENTAL)"
12 depends on IBMEBUS && INFINIBAND_EHCA && HOTPLUG_CPU && EXPERIMENTAL
13 default y
14 ---help---
15 eHCA scaling support schedules the CQ callbacks to different CPUs.
16
17 To enable this feature choose Y here.
diff --git a/drivers/infiniband/hw/ehca/ehca_classes.h b/drivers/infiniband/hw/ehca/ehca_classes.h
index cf95ee474b0f..40404c9e2817 100644
--- a/drivers/infiniband/hw/ehca/ehca_classes.h
+++ b/drivers/infiniband/hw/ehca/ehca_classes.h
@@ -42,8 +42,6 @@
42#ifndef __EHCA_CLASSES_H__ 42#ifndef __EHCA_CLASSES_H__
43#define __EHCA_CLASSES_H__ 43#define __EHCA_CLASSES_H__
44 44
45#include "ehca_classes.h"
46#include "ipz_pt_fn.h"
47 45
48struct ehca_module; 46struct ehca_module;
49struct ehca_qp; 47struct ehca_qp;
@@ -54,14 +52,22 @@ struct ehca_mw;
54struct ehca_pd; 52struct ehca_pd;
55struct ehca_av; 53struct ehca_av;
56 54
55#include <rdma/ib_verbs.h>
56#include <rdma/ib_user_verbs.h>
57
57#ifdef CONFIG_PPC64 58#ifdef CONFIG_PPC64
58#include "ehca_classes_pSeries.h" 59#include "ehca_classes_pSeries.h"
59#endif 60#endif
61#include "ipz_pt_fn.h"
62#include "ehca_qes.h"
63#include "ehca_irq.h"
60 64
61#include <rdma/ib_verbs.h> 65#define EHCA_EQE_CACHE_SIZE 20
62#include <rdma/ib_user_verbs.h>
63 66
64#include "ehca_irq.h" 67struct ehca_eqe_cache_entry {
68 struct ehca_eqe *eqe;
69 struct ehca_cq *cq;
70};
65 71
66struct ehca_eq { 72struct ehca_eq {
67 u32 length; 73 u32 length;
@@ -74,6 +80,8 @@ struct ehca_eq {
74 spinlock_t spinlock; 80 spinlock_t spinlock;
75 struct tasklet_struct interrupt_task; 81 struct tasklet_struct interrupt_task;
76 u32 ist; 82 u32 ist;
83 spinlock_t irq_spinlock;
84 struct ehca_eqe_cache_entry eqe_cache[EHCA_EQE_CACHE_SIZE];
77}; 85};
78 86
79struct ehca_sport { 87struct ehca_sport {
@@ -269,6 +277,7 @@ extern struct idr ehca_cq_idr;
269extern int ehca_static_rate; 277extern int ehca_static_rate;
270extern int ehca_port_act_time; 278extern int ehca_port_act_time;
271extern int ehca_use_hp_mr; 279extern int ehca_use_hp_mr;
280extern int ehca_scaling_code;
272 281
273struct ipzu_queue_resp { 282struct ipzu_queue_resp {
274 u32 qe_size; /* queue entry size */ 283 u32 qe_size; /* queue entry size */
diff --git a/drivers/infiniband/hw/ehca/ehca_eq.c b/drivers/infiniband/hw/ehca/ehca_eq.c
index 24ceab0bae4a..4961eb88827c 100644
--- a/drivers/infiniband/hw/ehca/ehca_eq.c
+++ b/drivers/infiniband/hw/ehca/ehca_eq.c
@@ -61,6 +61,7 @@ int ehca_create_eq(struct ehca_shca *shca,
61 struct ib_device *ib_dev = &shca->ib_device; 61 struct ib_device *ib_dev = &shca->ib_device;
62 62
63 spin_lock_init(&eq->spinlock); 63 spin_lock_init(&eq->spinlock);
64 spin_lock_init(&eq->irq_spinlock);
64 eq->is_initialized = 0; 65 eq->is_initialized = 0;
65 66
66 if (type != EHCA_EQ && type != EHCA_NEQ) { 67 if (type != EHCA_EQ && type != EHCA_NEQ) {
diff --git a/drivers/infiniband/hw/ehca/ehca_hca.c b/drivers/infiniband/hw/ehca/ehca_hca.c
index b7be950ab47c..30eb45df9f0b 100644
--- a/drivers/infiniband/hw/ehca/ehca_hca.c
+++ b/drivers/infiniband/hw/ehca/ehca_hca.c
@@ -162,6 +162,9 @@ int ehca_query_port(struct ib_device *ibdev,
162 props->active_width = IB_WIDTH_12X; 162 props->active_width = IB_WIDTH_12X;
163 props->active_speed = 0x1; 163 props->active_speed = 0x1;
164 164
165 /* at the moment (logical) link state is always LINK_UP */
166 props->phys_state = 0x5;
167
165query_port1: 168query_port1:
166 ehca_free_fw_ctrlblock(rblock); 169 ehca_free_fw_ctrlblock(rblock);
167 170
diff --git a/drivers/infiniband/hw/ehca/ehca_irq.c b/drivers/infiniband/hw/ehca/ehca_irq.c
index 6c4f9f91b15d..3ec53c687d08 100644
--- a/drivers/infiniband/hw/ehca/ehca_irq.c
+++ b/drivers/infiniband/hw/ehca/ehca_irq.c
@@ -63,15 +63,11 @@
63#define ERROR_DATA_LENGTH EHCA_BMASK_IBM(52,63) 63#define ERROR_DATA_LENGTH EHCA_BMASK_IBM(52,63)
64#define ERROR_DATA_TYPE EHCA_BMASK_IBM(0,7) 64#define ERROR_DATA_TYPE EHCA_BMASK_IBM(0,7)
65 65
66#ifdef CONFIG_INFINIBAND_EHCA_SCALING
67
68static void queue_comp_task(struct ehca_cq *__cq); 66static void queue_comp_task(struct ehca_cq *__cq);
69 67
70static struct ehca_comp_pool* pool; 68static struct ehca_comp_pool* pool;
71static struct notifier_block comp_pool_callback_nb; 69static struct notifier_block comp_pool_callback_nb;
72 70
73#endif
74
75static inline void comp_event_callback(struct ehca_cq *cq) 71static inline void comp_event_callback(struct ehca_cq *cq)
76{ 72{
77 if (!cq->ib_cq.comp_handler) 73 if (!cq->ib_cq.comp_handler)
@@ -206,7 +202,7 @@ static void qp_event_callback(struct ehca_shca *shca,
206} 202}
207 203
208static void cq_event_callback(struct ehca_shca *shca, 204static void cq_event_callback(struct ehca_shca *shca,
209 u64 eqe) 205 u64 eqe)
210{ 206{
211 struct ehca_cq *cq; 207 struct ehca_cq *cq;
212 unsigned long flags; 208 unsigned long flags;
@@ -318,7 +314,7 @@ static void parse_ec(struct ehca_shca *shca, u64 eqe)
318 "disruptive port %x configuration change", port); 314 "disruptive port %x configuration change", port);
319 315
320 ehca_info(&shca->ib_device, 316 ehca_info(&shca->ib_device,
321 "port %x is inactive.", port); 317 "port %x is inactive.", port);
322 event.device = &shca->ib_device; 318 event.device = &shca->ib_device;
323 event.event = IB_EVENT_PORT_ERR; 319 event.event = IB_EVENT_PORT_ERR;
324 event.element.port_num = port; 320 event.element.port_num = port;
@@ -326,7 +322,7 @@ static void parse_ec(struct ehca_shca *shca, u64 eqe)
326 ib_dispatch_event(&event); 322 ib_dispatch_event(&event);
327 323
328 ehca_info(&shca->ib_device, 324 ehca_info(&shca->ib_device,
329 "port %x is active.", port); 325 "port %x is active.", port);
330 event.device = &shca->ib_device; 326 event.device = &shca->ib_device;
331 event.event = IB_EVENT_PORT_ACTIVE; 327 event.event = IB_EVENT_PORT_ACTIVE;
332 event.element.port_num = port; 328 event.element.port_num = port;
@@ -401,115 +397,170 @@ irqreturn_t ehca_interrupt_eq(int irq, void *dev_id)
401 return IRQ_HANDLED; 397 return IRQ_HANDLED;
402} 398}
403 399
404void ehca_tasklet_eq(unsigned long data)
405{
406 struct ehca_shca *shca = (struct ehca_shca*)data;
407 struct ehca_eqe *eqe;
408 int int_state;
409 int query_cnt = 0;
410 400
411 do { 401static inline void process_eqe(struct ehca_shca *shca, struct ehca_eqe *eqe)
412 eqe = (struct ehca_eqe *)ehca_poll_eq(shca, &shca->eq); 402{
403 u64 eqe_value;
404 u32 token;
405 unsigned long flags;
406 struct ehca_cq *cq;
407 eqe_value = eqe->entry;
408 ehca_dbg(&shca->ib_device, "eqe_value=%lx", eqe_value);
409 if (EHCA_BMASK_GET(EQE_COMPLETION_EVENT, eqe_value)) {
410 ehca_dbg(&shca->ib_device, "... completion event");
411 token = EHCA_BMASK_GET(EQE_CQ_TOKEN, eqe_value);
412 spin_lock_irqsave(&ehca_cq_idr_lock, flags);
413 cq = idr_find(&ehca_cq_idr, token);
414 if (cq == NULL) {
415 spin_unlock_irqrestore(&ehca_cq_idr_lock, flags);
416 ehca_err(&shca->ib_device,
417 "Invalid eqe for non-existing cq token=%x",
418 token);
419 return;
420 }
421 reset_eq_pending(cq);
422 if (ehca_scaling_code) {
423 queue_comp_task(cq);
424 spin_unlock_irqrestore(&ehca_cq_idr_lock, flags);
425 } else {
426 spin_unlock_irqrestore(&ehca_cq_idr_lock, flags);
427 comp_event_callback(cq);
428 }
429 } else {
430 ehca_dbg(&shca->ib_device,
431 "Got non completion event");
432 parse_identifier(shca, eqe_value);
433 }
434}
413 435
414 if ((shca->hw_level >= 2) && eqe) 436void ehca_process_eq(struct ehca_shca *shca, int is_irq)
415 int_state = 1; 437{
416 else 438 struct ehca_eq *eq = &shca->eq;
417 int_state = 0; 439 struct ehca_eqe_cache_entry *eqe_cache = eq->eqe_cache;
418 440 u64 eqe_value;
419 while ((int_state == 1) || eqe) { 441 unsigned long flags;
420 while (eqe) { 442 int eqe_cnt, i;
421 u64 eqe_value = eqe->entry; 443 int eq_empty = 0;
422 444
423 ehca_dbg(&shca->ib_device, 445 spin_lock_irqsave(&eq->irq_spinlock, flags);
424 "eqe_value=%lx", eqe_value); 446 if (is_irq) {
425 447 const int max_query_cnt = 100;
426 /* TODO: better structure */ 448 int query_cnt = 0;
427 if (EHCA_BMASK_GET(EQE_COMPLETION_EVENT, 449 int int_state = 1;
428 eqe_value)) { 450 do {
429 unsigned long flags; 451 int_state = hipz_h_query_int_state(
430 u32 token; 452 shca->ipz_hca_handle, eq->ist);
431 struct ehca_cq *cq; 453 query_cnt++;
432 454 iosync();
433 ehca_dbg(&shca->ib_device, 455 } while (int_state && query_cnt < max_query_cnt);
434 "... completion event"); 456 if (unlikely((query_cnt == max_query_cnt)))
435 token = 457 ehca_dbg(&shca->ib_device, "int_state=%x query_cnt=%x",
436 EHCA_BMASK_GET(EQE_CQ_TOKEN, 458 int_state, query_cnt);
437 eqe_value); 459 }
438 spin_lock_irqsave(&ehca_cq_idr_lock,
439 flags);
440 cq = idr_find(&ehca_cq_idr, token);
441
442 if (cq == NULL) {
443 spin_unlock_irqrestore(&ehca_cq_idr_lock,
444 flags);
445 break;
446 }
447
448 reset_eq_pending(cq);
449#ifdef CONFIG_INFINIBAND_EHCA_SCALING
450 queue_comp_task(cq);
451 spin_unlock_irqrestore(&ehca_cq_idr_lock,
452 flags);
453#else
454 spin_unlock_irqrestore(&ehca_cq_idr_lock,
455 flags);
456 comp_event_callback(cq);
457#endif
458 } else {
459 ehca_dbg(&shca->ib_device,
460 "... non completion event");
461 parse_identifier(shca, eqe_value);
462 }
463 eqe =
464 (struct ehca_eqe *)ehca_poll_eq(shca,
465 &shca->eq);
466 }
467 460
468 if (shca->hw_level >= 2) { 461 /* read out all eqes */
469 int_state = 462 eqe_cnt = 0;
470 hipz_h_query_int_state(shca->ipz_hca_handle, 463 do {
471 shca->eq.ist); 464 u32 token;
472 query_cnt++; 465 eqe_cache[eqe_cnt].eqe =
473 iosync(); 466 (struct ehca_eqe *)ehca_poll_eq(shca, eq);
474 if (query_cnt >= 100) { 467 if (!eqe_cache[eqe_cnt].eqe)
475 query_cnt = 0; 468 break;
476 int_state = 0; 469 eqe_value = eqe_cache[eqe_cnt].eqe->entry;
477 } 470 if (EHCA_BMASK_GET(EQE_COMPLETION_EVENT, eqe_value)) {
471 token = EHCA_BMASK_GET(EQE_CQ_TOKEN, eqe_value);
472 spin_lock(&ehca_cq_idr_lock);
473 eqe_cache[eqe_cnt].cq = idr_find(&ehca_cq_idr, token);
474 if (!eqe_cache[eqe_cnt].cq) {
475 spin_unlock(&ehca_cq_idr_lock);
476 ehca_err(&shca->ib_device,
477 "Invalid eqe for non-existing cq "
478 "token=%x", token);
479 continue;
478 } 480 }
479 eqe = (struct ehca_eqe *)ehca_poll_eq(shca, &shca->eq); 481 spin_unlock(&ehca_cq_idr_lock);
480 482 } else
483 eqe_cache[eqe_cnt].cq = NULL;
484 eqe_cnt++;
485 } while (eqe_cnt < EHCA_EQE_CACHE_SIZE);
486 if (!eqe_cnt) {
487 if (is_irq)
488 ehca_dbg(&shca->ib_device,
489 "No eqe found for irq event");
490 goto unlock_irq_spinlock;
491 } else if (!is_irq)
492 ehca_dbg(&shca->ib_device, "deadman found %x eqe", eqe_cnt);
493 if (unlikely(eqe_cnt == EHCA_EQE_CACHE_SIZE))
494 ehca_dbg(&shca->ib_device, "too many eqes for one irq event");
495 /* enable irq for new packets */
496 for (i = 0; i < eqe_cnt; i++) {
497 if (eq->eqe_cache[i].cq)
498 reset_eq_pending(eq->eqe_cache[i].cq);
499 }
500 /* check eq */
501 spin_lock(&eq->spinlock);
502 eq_empty = (!ipz_eqit_eq_peek_valid(&shca->eq.ipz_queue));
503 spin_unlock(&eq->spinlock);
504 /* call completion handler for cached eqes */
505 for (i = 0; i < eqe_cnt; i++)
506 if (eq->eqe_cache[i].cq) {
507 if (ehca_scaling_code) {
508 spin_lock(&ehca_cq_idr_lock);
509 queue_comp_task(eq->eqe_cache[i].cq);
510 spin_unlock(&ehca_cq_idr_lock);
511 } else
512 comp_event_callback(eq->eqe_cache[i].cq);
513 } else {
514 ehca_dbg(&shca->ib_device, "Got non completion event");
515 parse_identifier(shca, eq->eqe_cache[i].eqe->entry);
481 } 516 }
482 } while (int_state != 0); 517 /* poll eq if not empty */
483 518 if (eq_empty)
484 return; 519 goto unlock_irq_spinlock;
520 do {
521 struct ehca_eqe *eqe;
522 eqe = (struct ehca_eqe *)ehca_poll_eq(shca, &shca->eq);
523 if (!eqe)
524 break;
525 process_eqe(shca, eqe);
526 eqe_cnt++;
527 } while (1);
528
529unlock_irq_spinlock:
530 spin_unlock_irqrestore(&eq->irq_spinlock, flags);
485} 531}
486 532
487#ifdef CONFIG_INFINIBAND_EHCA_SCALING 533void ehca_tasklet_eq(unsigned long data)
534{
535 ehca_process_eq((struct ehca_shca*)data, 1);
536}
488 537
489static inline int find_next_online_cpu(struct ehca_comp_pool* pool) 538static inline int find_next_online_cpu(struct ehca_comp_pool* pool)
490{ 539{
491 unsigned long flags_last_cpu; 540 int cpu;
541 unsigned long flags;
492 542
543 WARN_ON_ONCE(!in_interrupt());
493 if (ehca_debug_level) 544 if (ehca_debug_level)
494 ehca_dmp(&cpu_online_map, sizeof(cpumask_t), ""); 545 ehca_dmp(&cpu_online_map, sizeof(cpumask_t), "");
495 546
496 spin_lock_irqsave(&pool->last_cpu_lock, flags_last_cpu); 547 spin_lock_irqsave(&pool->last_cpu_lock, flags);
497 pool->last_cpu = next_cpu(pool->last_cpu, cpu_online_map); 548 cpu = next_cpu(pool->last_cpu, cpu_online_map);
498 if (pool->last_cpu == NR_CPUS) 549 if (cpu == NR_CPUS)
499 pool->last_cpu = first_cpu(cpu_online_map); 550 cpu = first_cpu(cpu_online_map);
500 spin_unlock_irqrestore(&pool->last_cpu_lock, flags_last_cpu); 551 pool->last_cpu = cpu;
552 spin_unlock_irqrestore(&pool->last_cpu_lock, flags);
501 553
502 return pool->last_cpu; 554 return cpu;
503} 555}
504 556
505static void __queue_comp_task(struct ehca_cq *__cq, 557static void __queue_comp_task(struct ehca_cq *__cq,
506 struct ehca_cpu_comp_task *cct) 558 struct ehca_cpu_comp_task *cct)
507{ 559{
508 unsigned long flags_cct; 560 unsigned long flags;
509 unsigned long flags_cq;
510 561
511 spin_lock_irqsave(&cct->task_lock, flags_cct); 562 spin_lock_irqsave(&cct->task_lock, flags);
512 spin_lock_irqsave(&__cq->task_lock, flags_cq); 563 spin_lock(&__cq->task_lock);
513 564
514 if (__cq->nr_callbacks == 0) { 565 if (__cq->nr_callbacks == 0) {
515 __cq->nr_callbacks++; 566 __cq->nr_callbacks++;
@@ -520,8 +571,8 @@ static void __queue_comp_task(struct ehca_cq *__cq,
520 else 571 else
521 __cq->nr_callbacks++; 572 __cq->nr_callbacks++;
522 573
523 spin_unlock_irqrestore(&__cq->task_lock, flags_cq); 574 spin_unlock(&__cq->task_lock);
524 spin_unlock_irqrestore(&cct->task_lock, flags_cct); 575 spin_unlock_irqrestore(&cct->task_lock, flags);
525} 576}
526 577
527static void queue_comp_task(struct ehca_cq *__cq) 578static void queue_comp_task(struct ehca_cq *__cq)
@@ -532,69 +583,69 @@ static void queue_comp_task(struct ehca_cq *__cq)
532 583
533 cpu = get_cpu(); 584 cpu = get_cpu();
534 cpu_id = find_next_online_cpu(pool); 585 cpu_id = find_next_online_cpu(pool);
535
536 BUG_ON(!cpu_online(cpu_id)); 586 BUG_ON(!cpu_online(cpu_id));
537 587
538 cct = per_cpu_ptr(pool->cpu_comp_tasks, cpu_id); 588 cct = per_cpu_ptr(pool->cpu_comp_tasks, cpu_id);
589 BUG_ON(!cct);
539 590
540 if (cct->cq_jobs > 0) { 591 if (cct->cq_jobs > 0) {
541 cpu_id = find_next_online_cpu(pool); 592 cpu_id = find_next_online_cpu(pool);
542 cct = per_cpu_ptr(pool->cpu_comp_tasks, cpu_id); 593 cct = per_cpu_ptr(pool->cpu_comp_tasks, cpu_id);
594 BUG_ON(!cct);
543 } 595 }
544 596
545 __queue_comp_task(__cq, cct); 597 __queue_comp_task(__cq, cct);
546
547 put_cpu();
548
549 return;
550} 598}
551 599
552static void run_comp_task(struct ehca_cpu_comp_task* cct) 600static void run_comp_task(struct ehca_cpu_comp_task* cct)
553{ 601{
554 struct ehca_cq *cq; 602 struct ehca_cq *cq;
555 unsigned long flags_cct; 603 unsigned long flags;
556 unsigned long flags_cq;
557 604
558 spin_lock_irqsave(&cct->task_lock, flags_cct); 605 spin_lock_irqsave(&cct->task_lock, flags);
559 606
560 while (!list_empty(&cct->cq_list)) { 607 while (!list_empty(&cct->cq_list)) {
561 cq = list_entry(cct->cq_list.next, struct ehca_cq, entry); 608 cq = list_entry(cct->cq_list.next, struct ehca_cq, entry);
562 spin_unlock_irqrestore(&cct->task_lock, flags_cct); 609 spin_unlock_irqrestore(&cct->task_lock, flags);
563 comp_event_callback(cq); 610 comp_event_callback(cq);
564 spin_lock_irqsave(&cct->task_lock, flags_cct); 611 spin_lock_irqsave(&cct->task_lock, flags);
565 612
566 spin_lock_irqsave(&cq->task_lock, flags_cq); 613 spin_lock(&cq->task_lock);
567 cq->nr_callbacks--; 614 cq->nr_callbacks--;
568 if (cq->nr_callbacks == 0) { 615 if (cq->nr_callbacks == 0) {
569 list_del_init(cct->cq_list.next); 616 list_del_init(cct->cq_list.next);
570 cct->cq_jobs--; 617 cct->cq_jobs--;
571 } 618 }
572 spin_unlock_irqrestore(&cq->task_lock, flags_cq); 619 spin_unlock(&cq->task_lock);
573
574 } 620 }
575 621
576 spin_unlock_irqrestore(&cct->task_lock, flags_cct); 622 spin_unlock_irqrestore(&cct->task_lock, flags);
577
578 return;
579} 623}
580 624
581static int comp_task(void *__cct) 625static int comp_task(void *__cct)
582{ 626{
583 struct ehca_cpu_comp_task* cct = __cct; 627 struct ehca_cpu_comp_task* cct = __cct;
628 int cql_empty;
584 DECLARE_WAITQUEUE(wait, current); 629 DECLARE_WAITQUEUE(wait, current);
585 630
586 set_current_state(TASK_INTERRUPTIBLE); 631 set_current_state(TASK_INTERRUPTIBLE);
587 while(!kthread_should_stop()) { 632 while(!kthread_should_stop()) {
588 add_wait_queue(&cct->wait_queue, &wait); 633 add_wait_queue(&cct->wait_queue, &wait);
589 634
590 if (list_empty(&cct->cq_list)) 635 spin_lock_irq(&cct->task_lock);
636 cql_empty = list_empty(&cct->cq_list);
637 spin_unlock_irq(&cct->task_lock);
638 if (cql_empty)
591 schedule(); 639 schedule();
592 else 640 else
593 __set_current_state(TASK_RUNNING); 641 __set_current_state(TASK_RUNNING);
594 642
595 remove_wait_queue(&cct->wait_queue, &wait); 643 remove_wait_queue(&cct->wait_queue, &wait);
596 644
597 if (!list_empty(&cct->cq_list)) 645 spin_lock_irq(&cct->task_lock);
646 cql_empty = list_empty(&cct->cq_list);
647 spin_unlock_irq(&cct->task_lock);
648 if (!cql_empty)
598 run_comp_task(__cct); 649 run_comp_task(__cct);
599 650
600 set_current_state(TASK_INTERRUPTIBLE); 651 set_current_state(TASK_INTERRUPTIBLE);
@@ -637,8 +688,6 @@ static void destroy_comp_task(struct ehca_comp_pool *pool,
637 688
638 if (task) 689 if (task)
639 kthread_stop(task); 690 kthread_stop(task);
640
641 return;
642} 691}
643 692
644static void take_over_work(struct ehca_comp_pool *pool, 693static void take_over_work(struct ehca_comp_pool *pool,
@@ -654,11 +703,11 @@ static void take_over_work(struct ehca_comp_pool *pool,
654 list_splice_init(&cct->cq_list, &list); 703 list_splice_init(&cct->cq_list, &list);
655 704
656 while(!list_empty(&list)) { 705 while(!list_empty(&list)) {
657 cq = list_entry(cct->cq_list.next, struct ehca_cq, entry); 706 cq = list_entry(cct->cq_list.next, struct ehca_cq, entry);
658 707
659 list_del(&cq->entry); 708 list_del(&cq->entry);
660 __queue_comp_task(cq, per_cpu_ptr(pool->cpu_comp_tasks, 709 __queue_comp_task(cq, per_cpu_ptr(pool->cpu_comp_tasks,
661 smp_processor_id())); 710 smp_processor_id()));
662 } 711 }
663 712
664 spin_unlock_irqrestore(&cct->task_lock, flags_cct); 713 spin_unlock_irqrestore(&cct->task_lock, flags_cct);
@@ -708,14 +757,14 @@ static int comp_pool_callback(struct notifier_block *nfb,
708 return NOTIFY_OK; 757 return NOTIFY_OK;
709} 758}
710 759
711#endif
712
713int ehca_create_comp_pool(void) 760int ehca_create_comp_pool(void)
714{ 761{
715#ifdef CONFIG_INFINIBAND_EHCA_SCALING
716 int cpu; 762 int cpu;
717 struct task_struct *task; 763 struct task_struct *task;
718 764
765 if (!ehca_scaling_code)
766 return 0;
767
719 pool = kzalloc(sizeof(struct ehca_comp_pool), GFP_KERNEL); 768 pool = kzalloc(sizeof(struct ehca_comp_pool), GFP_KERNEL);
720 if (pool == NULL) 769 if (pool == NULL)
721 return -ENOMEM; 770 return -ENOMEM;
@@ -740,16 +789,19 @@ int ehca_create_comp_pool(void)
740 comp_pool_callback_nb.notifier_call = comp_pool_callback; 789 comp_pool_callback_nb.notifier_call = comp_pool_callback;
741 comp_pool_callback_nb.priority =0; 790 comp_pool_callback_nb.priority =0;
742 register_cpu_notifier(&comp_pool_callback_nb); 791 register_cpu_notifier(&comp_pool_callback_nb);
743#endif 792
793 printk(KERN_INFO "eHCA scaling code enabled\n");
744 794
745 return 0; 795 return 0;
746} 796}
747 797
748void ehca_destroy_comp_pool(void) 798void ehca_destroy_comp_pool(void)
749{ 799{
750#ifdef CONFIG_INFINIBAND_EHCA_SCALING
751 int i; 800 int i;
752 801
802 if (!ehca_scaling_code)
803 return;
804
753 unregister_cpu_notifier(&comp_pool_callback_nb); 805 unregister_cpu_notifier(&comp_pool_callback_nb);
754 806
755 for (i = 0; i < NR_CPUS; i++) { 807 for (i = 0; i < NR_CPUS; i++) {
@@ -758,7 +810,4 @@ void ehca_destroy_comp_pool(void)
758 } 810 }
759 free_percpu(pool->cpu_comp_tasks); 811 free_percpu(pool->cpu_comp_tasks);
760 kfree(pool); 812 kfree(pool);
761#endif
762
763 return;
764} 813}
diff --git a/drivers/infiniband/hw/ehca/ehca_irq.h b/drivers/infiniband/hw/ehca/ehca_irq.h
index be579cc0adf6..6ed06ee033ed 100644
--- a/drivers/infiniband/hw/ehca/ehca_irq.h
+++ b/drivers/infiniband/hw/ehca/ehca_irq.h
@@ -56,6 +56,7 @@ void ehca_tasklet_neq(unsigned long data);
56 56
57irqreturn_t ehca_interrupt_eq(int irq, void *dev_id); 57irqreturn_t ehca_interrupt_eq(int irq, void *dev_id);
58void ehca_tasklet_eq(unsigned long data); 58void ehca_tasklet_eq(unsigned long data);
59void ehca_process_eq(struct ehca_shca *shca, int is_irq);
59 60
60struct ehca_cpu_comp_task { 61struct ehca_cpu_comp_task {
61 wait_queue_head_t wait_queue; 62 wait_queue_head_t wait_queue;
diff --git a/drivers/infiniband/hw/ehca/ehca_main.c b/drivers/infiniband/hw/ehca/ehca_main.c
index 1155bcf48212..c1835121a822 100644
--- a/drivers/infiniband/hw/ehca/ehca_main.c
+++ b/drivers/infiniband/hw/ehca/ehca_main.c
@@ -52,7 +52,7 @@
52MODULE_LICENSE("Dual BSD/GPL"); 52MODULE_LICENSE("Dual BSD/GPL");
53MODULE_AUTHOR("Christoph Raisch <raisch@de.ibm.com>"); 53MODULE_AUTHOR("Christoph Raisch <raisch@de.ibm.com>");
54MODULE_DESCRIPTION("IBM eServer HCA InfiniBand Device Driver"); 54MODULE_DESCRIPTION("IBM eServer HCA InfiniBand Device Driver");
55MODULE_VERSION("SVNEHCA_0020"); 55MODULE_VERSION("SVNEHCA_0021");
56 56
57int ehca_open_aqp1 = 0; 57int ehca_open_aqp1 = 0;
58int ehca_debug_level = 0; 58int ehca_debug_level = 0;
@@ -62,6 +62,7 @@ int ehca_use_hp_mr = 0;
62int ehca_port_act_time = 30; 62int ehca_port_act_time = 30;
63int ehca_poll_all_eqs = 1; 63int ehca_poll_all_eqs = 1;
64int ehca_static_rate = -1; 64int ehca_static_rate = -1;
65int ehca_scaling_code = 1;
65 66
66module_param_named(open_aqp1, ehca_open_aqp1, int, 0); 67module_param_named(open_aqp1, ehca_open_aqp1, int, 0);
67module_param_named(debug_level, ehca_debug_level, int, 0); 68module_param_named(debug_level, ehca_debug_level, int, 0);
@@ -71,6 +72,7 @@ module_param_named(use_hp_mr, ehca_use_hp_mr, int, 0);
71module_param_named(port_act_time, ehca_port_act_time, int, 0); 72module_param_named(port_act_time, ehca_port_act_time, int, 0);
72module_param_named(poll_all_eqs, ehca_poll_all_eqs, int, 0); 73module_param_named(poll_all_eqs, ehca_poll_all_eqs, int, 0);
73module_param_named(static_rate, ehca_static_rate, int, 0); 74module_param_named(static_rate, ehca_static_rate, int, 0);
75module_param_named(scaling_code, ehca_scaling_code, int, 0);
74 76
75MODULE_PARM_DESC(open_aqp1, 77MODULE_PARM_DESC(open_aqp1,
76 "AQP1 on startup (0: no (default), 1: yes)"); 78 "AQP1 on startup (0: no (default), 1: yes)");
@@ -91,6 +93,8 @@ MODULE_PARM_DESC(poll_all_eqs,
91 " (0: no, 1: yes (default))"); 93 " (0: no, 1: yes (default))");
92MODULE_PARM_DESC(static_rate, 94MODULE_PARM_DESC(static_rate,
93 "set permanent static rate (default: disabled)"); 95 "set permanent static rate (default: disabled)");
96MODULE_PARM_DESC(scaling_code,
97 "set scaling code (0: disabled, 1: enabled/default)");
94 98
95spinlock_t ehca_qp_idr_lock; 99spinlock_t ehca_qp_idr_lock;
96spinlock_t ehca_cq_idr_lock; 100spinlock_t ehca_cq_idr_lock;
@@ -432,8 +436,8 @@ static int ehca_destroy_aqp1(struct ehca_sport *sport)
432 436
433static ssize_t ehca_show_debug_level(struct device_driver *ddp, char *buf) 437static ssize_t ehca_show_debug_level(struct device_driver *ddp, char *buf)
434{ 438{
435 return snprintf(buf, PAGE_SIZE, "%d\n", 439 return snprintf(buf, PAGE_SIZE, "%d\n",
436 ehca_debug_level); 440 ehca_debug_level);
437} 441}
438 442
439static ssize_t ehca_store_debug_level(struct device_driver *ddp, 443static ssize_t ehca_store_debug_level(struct device_driver *ddp,
@@ -778,8 +782,24 @@ void ehca_poll_eqs(unsigned long data)
778 782
779 spin_lock(&shca_list_lock); 783 spin_lock(&shca_list_lock);
780 list_for_each_entry(shca, &shca_list, shca_list) { 784 list_for_each_entry(shca, &shca_list, shca_list) {
781 if (shca->eq.is_initialized) 785 if (shca->eq.is_initialized) {
782 ehca_tasklet_eq((unsigned long)(void*)shca); 786 /* call deadman proc only if eq ptr does not change */
787 struct ehca_eq *eq = &shca->eq;
788 int max = 3;
789 volatile u64 q_ofs, q_ofs2;
790 u64 flags;
791 spin_lock_irqsave(&eq->spinlock, flags);
792 q_ofs = eq->ipz_queue.current_q_offset;
793 spin_unlock_irqrestore(&eq->spinlock, flags);
794 do {
795 spin_lock_irqsave(&eq->spinlock, flags);
796 q_ofs2 = eq->ipz_queue.current_q_offset;
797 spin_unlock_irqrestore(&eq->spinlock, flags);
798 max--;
799 } while (q_ofs == q_ofs2 && max > 0);
800 if (q_ofs == q_ofs2)
801 ehca_process_eq(shca, 0);
802 }
783 } 803 }
784 mod_timer(&poll_eqs_timer, jiffies + HZ); 804 mod_timer(&poll_eqs_timer, jiffies + HZ);
785 spin_unlock(&shca_list_lock); 805 spin_unlock(&shca_list_lock);
@@ -790,7 +810,7 @@ int __init ehca_module_init(void)
790 int ret; 810 int ret;
791 811
792 printk(KERN_INFO "eHCA Infiniband Device Driver " 812 printk(KERN_INFO "eHCA Infiniband Device Driver "
793 "(Rel.: SVNEHCA_0020)\n"); 813 "(Rel.: SVNEHCA_0021)\n");
794 idr_init(&ehca_qp_idr); 814 idr_init(&ehca_qp_idr);
795 idr_init(&ehca_cq_idr); 815 idr_init(&ehca_cq_idr);
796 spin_lock_init(&ehca_qp_idr_lock); 816 spin_lock_init(&ehca_qp_idr_lock);
diff --git a/drivers/infiniband/hw/ehca/ipz_pt_fn.h b/drivers/infiniband/hw/ehca/ipz_pt_fn.h
index dc3bda2634b7..8199c45768a3 100644
--- a/drivers/infiniband/hw/ehca/ipz_pt_fn.h
+++ b/drivers/infiniband/hw/ehca/ipz_pt_fn.h
@@ -79,7 +79,7 @@ static inline void *ipz_qeit_calc(struct ipz_queue *queue, u64 q_offset)
79 if (q_offset >= queue->queue_length) 79 if (q_offset >= queue->queue_length)
80 return NULL; 80 return NULL;
81 current_page = (queue->queue_pages)[q_offset >> EHCA_PAGESHIFT]; 81 current_page = (queue->queue_pages)[q_offset >> EHCA_PAGESHIFT];
82 return &current_page->entries[q_offset & (EHCA_PAGESIZE - 1)]; 82 return &current_page->entries[q_offset & (EHCA_PAGESIZE - 1)];
83} 83}
84 84
85/* 85/*
@@ -247,6 +247,15 @@ static inline void *ipz_eqit_eq_get_inc_valid(struct ipz_queue *queue)
247 return ret; 247 return ret;
248} 248}
249 249
250static inline void *ipz_eqit_eq_peek_valid(struct ipz_queue *queue)
251{
252 void *ret = ipz_qeit_get(queue);
253 u32 qe = *(u8 *) ret;
254 if ((qe >> 7) != (queue->toggle_state & 1))
255 return NULL;
256 return ret;
257}
258
250/* returns address (GX) of first queue entry */ 259/* returns address (GX) of first queue entry */
251static inline u64 ipz_qpt_get_firstpage(struct ipz_qpt *qpt) 260static inline u64 ipz_qpt_get_firstpage(struct ipz_qpt *qpt)
252{ 261{
diff --git a/drivers/infiniband/hw/ipath/ipath_dma.c b/drivers/infiniband/hw/ipath/ipath_dma.c
index 6e0f2b8918ce..f6f949040825 100644
--- a/drivers/infiniband/hw/ipath/ipath_dma.c
+++ b/drivers/infiniband/hw/ipath/ipath_dma.c
@@ -96,8 +96,8 @@ static void ipath_dma_unmap_page(struct ib_device *dev,
96 BUG_ON(!valid_dma_direction(direction)); 96 BUG_ON(!valid_dma_direction(direction));
97} 97}
98 98
99int ipath_map_sg(struct ib_device *dev, struct scatterlist *sg, int nents, 99static int ipath_map_sg(struct ib_device *dev, struct scatterlist *sg, int nents,
100 enum dma_data_direction direction) 100 enum dma_data_direction direction)
101{ 101{
102 u64 addr; 102 u64 addr;
103 int i; 103 int i;
diff --git a/drivers/infiniband/hw/ipath/ipath_iba6110.c b/drivers/infiniband/hw/ipath/ipath_iba6110.c
index 7468477ba837..993482545021 100644
--- a/drivers/infiniband/hw/ipath/ipath_iba6110.c
+++ b/drivers/infiniband/hw/ipath/ipath_iba6110.c
@@ -1534,7 +1534,7 @@ static int ipath_ht_early_init(struct ipath_devdata *dd)
1534 * @kbase: ipath_base_info pointer 1534 * @kbase: ipath_base_info pointer
1535 * 1535 *
1536 * We set the PCIE flag because the lower bandwidth on PCIe vs 1536 * We set the PCIE flag because the lower bandwidth on PCIe vs
1537 * HyperTransport can affect some user packet algorithims. 1537 * HyperTransport can affect some user packet algorithms.
1538 */ 1538 */
1539static int ipath_ht_get_base_info(struct ipath_portdata *pd, void *kbase) 1539static int ipath_ht_get_base_info(struct ipath_portdata *pd, void *kbase)
1540{ 1540{
diff --git a/drivers/infiniband/hw/ipath/ipath_iba6120.c b/drivers/infiniband/hw/ipath/ipath_iba6120.c
index ae8bf9950c6d..05918e1e7c36 100644
--- a/drivers/infiniband/hw/ipath/ipath_iba6120.c
+++ b/drivers/infiniband/hw/ipath/ipath_iba6120.c
@@ -1293,7 +1293,7 @@ int __attribute__((weak)) ipath_unordered_wc(void)
1293 * @kbase: ipath_base_info pointer 1293 * @kbase: ipath_base_info pointer
1294 * 1294 *
1295 * We set the PCIE flag because the lower bandwidth on PCIe vs 1295 * We set the PCIE flag because the lower bandwidth on PCIe vs
1296 * HyperTransport can affect some user packet algorithims. 1296 * HyperTransport can affect some user packet algorithms.
1297 */ 1297 */
1298static int ipath_pe_get_base_info(struct ipath_portdata *pd, void *kbase) 1298static int ipath_pe_get_base_info(struct ipath_portdata *pd, void *kbase)
1299{ 1299{
diff --git a/drivers/infiniband/hw/mthca/mthca_memfree.c b/drivers/infiniband/hw/mthca/mthca_memfree.c
index 0b9d053a599d..48f7c65e9aed 100644
--- a/drivers/infiniband/hw/mthca/mthca_memfree.c
+++ b/drivers/infiniband/hw/mthca/mthca_memfree.c
@@ -175,7 +175,9 @@ struct mthca_icm *mthca_alloc_icm(struct mthca_dev *dev, int npages,
175 if (!ret) { 175 if (!ret) {
176 ++chunk->npages; 176 ++chunk->npages;
177 177
178 if (!coherent && chunk->npages == MTHCA_ICM_CHUNK_LEN) { 178 if (coherent)
179 ++chunk->nsg;
180 else if (chunk->npages == MTHCA_ICM_CHUNK_LEN) {
179 chunk->nsg = pci_map_sg(dev->pdev, chunk->mem, 181 chunk->nsg = pci_map_sg(dev->pdev, chunk->mem,
180 chunk->npages, 182 chunk->npages,
181 PCI_DMA_BIDIRECTIONAL); 183 PCI_DMA_BIDIRECTIONAL);
diff --git a/drivers/infiniband/hw/mthca/mthca_qp.c b/drivers/infiniband/hw/mthca/mthca_qp.c
index 224c93dd29eb..71dc84bd4254 100644
--- a/drivers/infiniband/hw/mthca/mthca_qp.c
+++ b/drivers/infiniband/hw/mthca/mthca_qp.c
@@ -573,6 +573,11 @@ int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask,
573 goto out; 573 goto out;
574 } 574 }
575 575
576 if (cur_state == new_state && cur_state == IB_QPS_RESET) {
577 err = 0;
578 goto out;
579 }
580
576 if ((attr_mask & IB_QP_PKEY_INDEX) && 581 if ((attr_mask & IB_QP_PKEY_INDEX) &&
577 attr->pkey_index >= dev->limits.pkey_table_len) { 582 attr->pkey_index >= dev->limits.pkey_table_len) {
578 mthca_dbg(dev, "P_Key index (%u) too large. max is %d\n", 583 mthca_dbg(dev, "P_Key index (%u) too large. max is %d\n",
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_cm.c b/drivers/infiniband/ulp/ipoib/ipoib_cm.c
index 2d483874a589..4d59682f7d4a 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_cm.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_cm.c
@@ -145,7 +145,7 @@ partial_error:
145 for (; i >= 0; --i) 145 for (; i >= 0; --i)
146 ib_dma_unmap_single(priv->ca, mapping[i + 1], PAGE_SIZE, DMA_FROM_DEVICE); 146 ib_dma_unmap_single(priv->ca, mapping[i + 1], PAGE_SIZE, DMA_FROM_DEVICE);
147 147
148 kfree_skb(skb); 148 dev_kfree_skb_any(skb);
149 return -ENOMEM; 149 return -ENOMEM;
150} 150}
151 151
@@ -1138,7 +1138,7 @@ static ssize_t set_mode(struct device *d, struct device_attribute *attr,
1138 return -EINVAL; 1138 return -EINVAL;
1139} 1139}
1140 1140
1141static DEVICE_ATTR(mode, S_IWUGO | S_IRUGO, show_mode, set_mode); 1141static DEVICE_ATTR(mode, S_IWUSR | S_IRUGO, show_mode, set_mode);
1142 1142
1143int ipoib_cm_add_mode_attr(struct net_device *dev) 1143int ipoib_cm_add_mode_attr(struct net_device *dev)
1144{ 1144{
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_multicast.c b/drivers/infiniband/ulp/ipoib/ipoib_multicast.c
index fea737f520fd..b303ce6bc21e 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_multicast.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_multicast.c
@@ -60,14 +60,11 @@ static DEFINE_MUTEX(mcast_mutex);
60/* Used for all multicast joins (broadcast, IPv4 mcast and IPv6 mcast) */ 60/* Used for all multicast joins (broadcast, IPv4 mcast and IPv6 mcast) */
61struct ipoib_mcast { 61struct ipoib_mcast {
62 struct ib_sa_mcmember_rec mcmember; 62 struct ib_sa_mcmember_rec mcmember;
63 struct ib_sa_multicast *mc;
63 struct ipoib_ah *ah; 64 struct ipoib_ah *ah;
64 65
65 struct rb_node rb_node; 66 struct rb_node rb_node;
66 struct list_head list; 67 struct list_head list;
67 struct completion done;
68
69 int query_id;
70 struct ib_sa_query *query;
71 68
72 unsigned long created; 69 unsigned long created;
73 unsigned long backoff; 70 unsigned long backoff;
@@ -299,18 +296,22 @@ static int ipoib_mcast_join_finish(struct ipoib_mcast *mcast,
299 return 0; 296 return 0;
300} 297}
301 298
302static void 299static int
303ipoib_mcast_sendonly_join_complete(int status, 300ipoib_mcast_sendonly_join_complete(int status,
304 struct ib_sa_mcmember_rec *mcmember, 301 struct ib_sa_multicast *multicast)
305 void *mcast_ptr)
306{ 302{
307 struct ipoib_mcast *mcast = mcast_ptr; 303 struct ipoib_mcast *mcast = multicast->context;
308 struct net_device *dev = mcast->dev; 304 struct net_device *dev = mcast->dev;
309 struct ipoib_dev_priv *priv = netdev_priv(dev); 305 struct ipoib_dev_priv *priv = netdev_priv(dev);
310 306
307 /* We trap for port events ourselves. */
308 if (status == -ENETRESET)
309 return 0;
310
311 if (!status) 311 if (!status)
312 ipoib_mcast_join_finish(mcast, mcmember); 312 status = ipoib_mcast_join_finish(mcast, &multicast->rec);
313 else { 313
314 if (status) {
314 if (mcast->logcount++ < 20) 315 if (mcast->logcount++ < 20)
315 ipoib_dbg_mcast(netdev_priv(dev), "multicast join failed for " 316 ipoib_dbg_mcast(netdev_priv(dev), "multicast join failed for "
316 IPOIB_GID_FMT ", status %d\n", 317 IPOIB_GID_FMT ", status %d\n",
@@ -325,11 +326,10 @@ ipoib_mcast_sendonly_join_complete(int status,
325 spin_unlock_irq(&priv->tx_lock); 326 spin_unlock_irq(&priv->tx_lock);
326 327
327 /* Clear the busy flag so we try again */ 328 /* Clear the busy flag so we try again */
328 clear_bit(IPOIB_MCAST_FLAG_BUSY, &mcast->flags); 329 status = test_and_clear_bit(IPOIB_MCAST_FLAG_BUSY,
329 mcast->query = NULL; 330 &mcast->flags);
330 } 331 }
331 332 return status;
332 complete(&mcast->done);
333} 333}
334 334
335static int ipoib_mcast_sendonly_join(struct ipoib_mcast *mcast) 335static int ipoib_mcast_sendonly_join(struct ipoib_mcast *mcast)
@@ -359,35 +359,33 @@ static int ipoib_mcast_sendonly_join(struct ipoib_mcast *mcast)
359 rec.port_gid = priv->local_gid; 359 rec.port_gid = priv->local_gid;
360 rec.pkey = cpu_to_be16(priv->pkey); 360 rec.pkey = cpu_to_be16(priv->pkey);
361 361
362 init_completion(&mcast->done); 362 mcast->mc = ib_sa_join_multicast(&ipoib_sa_client, priv->ca,
363 363 priv->port, &rec,
364 ret = ib_sa_mcmember_rec_set(&ipoib_sa_client, priv->ca, priv->port, &rec, 364 IB_SA_MCMEMBER_REC_MGID |
365 IB_SA_MCMEMBER_REC_MGID | 365 IB_SA_MCMEMBER_REC_PORT_GID |
366 IB_SA_MCMEMBER_REC_PORT_GID | 366 IB_SA_MCMEMBER_REC_PKEY |
367 IB_SA_MCMEMBER_REC_PKEY | 367 IB_SA_MCMEMBER_REC_JOIN_STATE,
368 IB_SA_MCMEMBER_REC_JOIN_STATE, 368 GFP_ATOMIC,
369 1000, GFP_ATOMIC, 369 ipoib_mcast_sendonly_join_complete,
370 ipoib_mcast_sendonly_join_complete, 370 mcast);
371 mcast, &mcast->query); 371 if (IS_ERR(mcast->mc)) {
372 if (ret < 0) { 372 ret = PTR_ERR(mcast->mc);
373 ipoib_warn(priv, "ib_sa_mcmember_rec_set failed (ret = %d)\n", 373 clear_bit(IPOIB_MCAST_FLAG_BUSY, &mcast->flags);
374 ipoib_warn(priv, "ib_sa_join_multicast failed (ret = %d)\n",
374 ret); 375 ret);
375 } else { 376 } else {
376 ipoib_dbg_mcast(priv, "no multicast record for " IPOIB_GID_FMT 377 ipoib_dbg_mcast(priv, "no multicast record for " IPOIB_GID_FMT
377 ", starting join\n", 378 ", starting join\n",
378 IPOIB_GID_ARG(mcast->mcmember.mgid)); 379 IPOIB_GID_ARG(mcast->mcmember.mgid));
379
380 mcast->query_id = ret;
381 } 380 }
382 381
383 return ret; 382 return ret;
384} 383}
385 384
386static void ipoib_mcast_join_complete(int status, 385static int ipoib_mcast_join_complete(int status,
387 struct ib_sa_mcmember_rec *mcmember, 386 struct ib_sa_multicast *multicast)
388 void *mcast_ptr)
389{ 387{
390 struct ipoib_mcast *mcast = mcast_ptr; 388 struct ipoib_mcast *mcast = multicast->context;
391 struct net_device *dev = mcast->dev; 389 struct net_device *dev = mcast->dev;
392 struct ipoib_dev_priv *priv = netdev_priv(dev); 390 struct ipoib_dev_priv *priv = netdev_priv(dev);
393 391
@@ -395,24 +393,25 @@ static void ipoib_mcast_join_complete(int status,
395 " (status %d)\n", 393 " (status %d)\n",
396 IPOIB_GID_ARG(mcast->mcmember.mgid), status); 394 IPOIB_GID_ARG(mcast->mcmember.mgid), status);
397 395
398 if (!status && !ipoib_mcast_join_finish(mcast, mcmember)) { 396 /* We trap for port events ourselves. */
397 if (status == -ENETRESET)
398 return 0;
399
400 if (!status)
401 status = ipoib_mcast_join_finish(mcast, &multicast->rec);
402
403 if (!status) {
399 mcast->backoff = 1; 404 mcast->backoff = 1;
400 mutex_lock(&mcast_mutex); 405 mutex_lock(&mcast_mutex);
401 if (test_bit(IPOIB_MCAST_RUN, &priv->flags)) 406 if (test_bit(IPOIB_MCAST_RUN, &priv->flags))
402 queue_delayed_work(ipoib_workqueue, 407 queue_delayed_work(ipoib_workqueue,
403 &priv->mcast_task, 0); 408 &priv->mcast_task, 0);
404 mutex_unlock(&mcast_mutex); 409 mutex_unlock(&mcast_mutex);
405 complete(&mcast->done); 410 return 0;
406 return;
407 }
408
409 if (status == -EINTR) {
410 complete(&mcast->done);
411 return;
412 } 411 }
413 412
414 if (status && mcast->logcount++ < 20) { 413 if (mcast->logcount++ < 20) {
415 if (status == -ETIMEDOUT || status == -EINTR) { 414 if (status == -ETIMEDOUT) {
416 ipoib_dbg_mcast(priv, "multicast join failed for " IPOIB_GID_FMT 415 ipoib_dbg_mcast(priv, "multicast join failed for " IPOIB_GID_FMT
417 ", status %d\n", 416 ", status %d\n",
418 IPOIB_GID_ARG(mcast->mcmember.mgid), 417 IPOIB_GID_ARG(mcast->mcmember.mgid),
@@ -429,24 +428,18 @@ static void ipoib_mcast_join_complete(int status,
429 if (mcast->backoff > IPOIB_MAX_BACKOFF_SECONDS) 428 if (mcast->backoff > IPOIB_MAX_BACKOFF_SECONDS)
430 mcast->backoff = IPOIB_MAX_BACKOFF_SECONDS; 429 mcast->backoff = IPOIB_MAX_BACKOFF_SECONDS;
431 430
432 mutex_lock(&mcast_mutex); 431 /* Clear the busy flag so we try again */
432 status = test_and_clear_bit(IPOIB_MCAST_FLAG_BUSY, &mcast->flags);
433 433
434 mutex_lock(&mcast_mutex);
434 spin_lock_irq(&priv->lock); 435 spin_lock_irq(&priv->lock);
435 mcast->query = NULL; 436 if (test_bit(IPOIB_MCAST_RUN, &priv->flags))
436 437 queue_delayed_work(ipoib_workqueue, &priv->mcast_task,
437 if (test_bit(IPOIB_MCAST_RUN, &priv->flags)) { 438 mcast->backoff * HZ);
438 if (status == -ETIMEDOUT)
439 queue_delayed_work(ipoib_workqueue, &priv->mcast_task,
440 0);
441 else
442 queue_delayed_work(ipoib_workqueue, &priv->mcast_task,
443 mcast->backoff * HZ);
444 } else
445 complete(&mcast->done);
446 spin_unlock_irq(&priv->lock); 439 spin_unlock_irq(&priv->lock);
447 mutex_unlock(&mcast_mutex); 440 mutex_unlock(&mcast_mutex);
448 441
449 return; 442 return status;
450} 443}
451 444
452static void ipoib_mcast_join(struct net_device *dev, struct ipoib_mcast *mcast, 445static void ipoib_mcast_join(struct net_device *dev, struct ipoib_mcast *mcast,
@@ -495,15 +488,14 @@ static void ipoib_mcast_join(struct net_device *dev, struct ipoib_mcast *mcast,
495 rec.hop_limit = priv->broadcast->mcmember.hop_limit; 488 rec.hop_limit = priv->broadcast->mcmember.hop_limit;
496 } 489 }
497 490
498 init_completion(&mcast->done); 491 set_bit(IPOIB_MCAST_FLAG_BUSY, &mcast->flags);
499 492 mcast->mc = ib_sa_join_multicast(&ipoib_sa_client, priv->ca, priv->port,
500 ret = ib_sa_mcmember_rec_set(&ipoib_sa_client, priv->ca, priv->port, 493 &rec, comp_mask, GFP_KERNEL,
501 &rec, comp_mask, mcast->backoff * 1000, 494 ipoib_mcast_join_complete, mcast);
502 GFP_ATOMIC, ipoib_mcast_join_complete, 495 if (IS_ERR(mcast->mc)) {
503 mcast, &mcast->query); 496 clear_bit(IPOIB_MCAST_FLAG_BUSY, &mcast->flags);
504 497 ret = PTR_ERR(mcast->mc);
505 if (ret < 0) { 498 ipoib_warn(priv, "ib_sa_join_multicast failed, status %d\n", ret);
506 ipoib_warn(priv, "ib_sa_mcmember_rec_set failed, status %d\n", ret);
507 499
508 mcast->backoff *= 2; 500 mcast->backoff *= 2;
509 if (mcast->backoff > IPOIB_MAX_BACKOFF_SECONDS) 501 if (mcast->backoff > IPOIB_MAX_BACKOFF_SECONDS)
@@ -515,8 +507,7 @@ static void ipoib_mcast_join(struct net_device *dev, struct ipoib_mcast *mcast,
515 &priv->mcast_task, 507 &priv->mcast_task,
516 mcast->backoff * HZ); 508 mcast->backoff * HZ);
517 mutex_unlock(&mcast_mutex); 509 mutex_unlock(&mcast_mutex);
518 } else 510 }
519 mcast->query_id = ret;
520} 511}
521 512
522void ipoib_mcast_join_task(struct work_struct *work) 513void ipoib_mcast_join_task(struct work_struct *work)
@@ -541,7 +532,7 @@ void ipoib_mcast_join_task(struct work_struct *work)
541 priv->local_rate = attr.active_speed * 532 priv->local_rate = attr.active_speed *
542 ib_width_enum_to_int(attr.active_width); 533 ib_width_enum_to_int(attr.active_width);
543 } else 534 } else
544 ipoib_warn(priv, "ib_query_port failed\n"); 535 ipoib_warn(priv, "ib_query_port failed\n");
545 } 536 }
546 537
547 if (!priv->broadcast) { 538 if (!priv->broadcast) {
@@ -568,7 +559,8 @@ void ipoib_mcast_join_task(struct work_struct *work)
568 } 559 }
569 560
570 if (!test_bit(IPOIB_MCAST_FLAG_ATTACHED, &priv->broadcast->flags)) { 561 if (!test_bit(IPOIB_MCAST_FLAG_ATTACHED, &priv->broadcast->flags)) {
571 ipoib_mcast_join(dev, priv->broadcast, 0); 562 if (!test_bit(IPOIB_MCAST_FLAG_BUSY, &priv->broadcast->flags))
563 ipoib_mcast_join(dev, priv->broadcast, 0);
572 return; 564 return;
573 } 565 }
574 566
@@ -625,26 +617,9 @@ int ipoib_mcast_start_thread(struct net_device *dev)
625 return 0; 617 return 0;
626} 618}
627 619
628static void wait_for_mcast_join(struct ipoib_dev_priv *priv,
629 struct ipoib_mcast *mcast)
630{
631 spin_lock_irq(&priv->lock);
632 if (mcast && mcast->query) {
633 ib_sa_cancel_query(mcast->query_id, mcast->query);
634 mcast->query = NULL;
635 spin_unlock_irq(&priv->lock);
636 ipoib_dbg_mcast(priv, "waiting for MGID " IPOIB_GID_FMT "\n",
637 IPOIB_GID_ARG(mcast->mcmember.mgid));
638 wait_for_completion(&mcast->done);
639 }
640 else
641 spin_unlock_irq(&priv->lock);
642}
643
644int ipoib_mcast_stop_thread(struct net_device *dev, int flush) 620int ipoib_mcast_stop_thread(struct net_device *dev, int flush)
645{ 621{
646 struct ipoib_dev_priv *priv = netdev_priv(dev); 622 struct ipoib_dev_priv *priv = netdev_priv(dev);
647 struct ipoib_mcast *mcast;
648 623
649 ipoib_dbg_mcast(priv, "stopping multicast thread\n"); 624 ipoib_dbg_mcast(priv, "stopping multicast thread\n");
650 625
@@ -660,52 +635,27 @@ int ipoib_mcast_stop_thread(struct net_device *dev, int flush)
660 if (flush) 635 if (flush)
661 flush_workqueue(ipoib_workqueue); 636 flush_workqueue(ipoib_workqueue);
662 637
663 wait_for_mcast_join(priv, priv->broadcast);
664
665 list_for_each_entry(mcast, &priv->multicast_list, list)
666 wait_for_mcast_join(priv, mcast);
667
668 return 0; 638 return 0;
669} 639}
670 640
671static int ipoib_mcast_leave(struct net_device *dev, struct ipoib_mcast *mcast) 641static int ipoib_mcast_leave(struct net_device *dev, struct ipoib_mcast *mcast)
672{ 642{
673 struct ipoib_dev_priv *priv = netdev_priv(dev); 643 struct ipoib_dev_priv *priv = netdev_priv(dev);
674 struct ib_sa_mcmember_rec rec = {
675 .join_state = 1
676 };
677 int ret = 0; 644 int ret = 0;
678 645
679 if (!test_and_clear_bit(IPOIB_MCAST_FLAG_ATTACHED, &mcast->flags)) 646 if (test_and_clear_bit(IPOIB_MCAST_FLAG_ATTACHED, &mcast->flags)) {
680 return 0; 647 ipoib_dbg_mcast(priv, "leaving MGID " IPOIB_GID_FMT "\n",
681 648 IPOIB_GID_ARG(mcast->mcmember.mgid));
682 ipoib_dbg_mcast(priv, "leaving MGID " IPOIB_GID_FMT "\n",
683 IPOIB_GID_ARG(mcast->mcmember.mgid));
684
685 rec.mgid = mcast->mcmember.mgid;
686 rec.port_gid = priv->local_gid;
687 rec.pkey = cpu_to_be16(priv->pkey);
688 649
689 /* Remove ourselves from the multicast group */ 650 /* Remove ourselves from the multicast group */
690 ret = ipoib_mcast_detach(dev, be16_to_cpu(mcast->mcmember.mlid), 651 ret = ipoib_mcast_detach(dev, be16_to_cpu(mcast->mcmember.mlid),
691 &mcast->mcmember.mgid); 652 &mcast->mcmember.mgid);
692 if (ret) 653 if (ret)
693 ipoib_warn(priv, "ipoib_mcast_detach failed (result = %d)\n", ret); 654 ipoib_warn(priv, "ipoib_mcast_detach failed (result = %d)\n", ret);
655 }
694 656
695 /* 657 if (test_and_clear_bit(IPOIB_MCAST_FLAG_BUSY, &mcast->flags))
696 * Just make one shot at leaving and don't wait for a reply; 658 ib_sa_free_multicast(mcast->mc);
697 * if we fail, too bad.
698 */
699 ret = ib_sa_mcmember_rec_delete(&ipoib_sa_client, priv->ca, priv->port, &rec,
700 IB_SA_MCMEMBER_REC_MGID |
701 IB_SA_MCMEMBER_REC_PORT_GID |
702 IB_SA_MCMEMBER_REC_PKEY |
703 IB_SA_MCMEMBER_REC_JOIN_STATE,
704 0, GFP_ATOMIC, NULL,
705 mcast, &mcast->query);
706 if (ret < 0)
707 ipoib_warn(priv, "ib_sa_mcmember_rec_delete failed "
708 "for leave (result = %d)\n", ret);
709 659
710 return 0; 660 return 0;
711} 661}
@@ -758,7 +708,7 @@ void ipoib_mcast_send(struct net_device *dev, void *mgid, struct sk_buff *skb)
758 dev_kfree_skb_any(skb); 708 dev_kfree_skb_any(skb);
759 } 709 }
760 710
761 if (mcast->query) 711 if (test_bit(IPOIB_MCAST_FLAG_BUSY, &mcast->flags))
762 ipoib_dbg_mcast(priv, "no address vector, " 712 ipoib_dbg_mcast(priv, "no address vector, "
763 "but multicast join already started\n"); 713 "but multicast join already started\n");
764 else if (test_bit(IPOIB_MCAST_FLAG_SENDONLY, &mcast->flags)) 714 else if (test_bit(IPOIB_MCAST_FLAG_SENDONLY, &mcast->flags))
@@ -916,7 +866,6 @@ void ipoib_mcast_restart_task(struct work_struct *work)
916 866
917 /* We have to cancel outside of the spinlock */ 867 /* We have to cancel outside of the spinlock */
918 list_for_each_entry_safe(mcast, tmcast, &remove_list, list) { 868 list_for_each_entry_safe(mcast, tmcast, &remove_list, list) {
919 wait_for_mcast_join(priv, mcast);
920 ipoib_mcast_leave(mcast->dev, mcast); 869 ipoib_mcast_leave(mcast->dev, mcast);
921 ipoib_mcast_free(mcast); 870 ipoib_mcast_free(mcast);
922 } 871 }
diff --git a/drivers/input/input.c b/drivers/input/input.c
index efa1b1f75393..a9a706f8fff9 100644
--- a/drivers/input/input.c
+++ b/drivers/input/input.c
@@ -588,18 +588,9 @@ static inline void input_proc_exit(void) { }
588static ssize_t input_dev_show_##name(struct class_device *dev, char *buf) \ 588static ssize_t input_dev_show_##name(struct class_device *dev, char *buf) \
589{ \ 589{ \
590 struct input_dev *input_dev = to_input_dev(dev); \ 590 struct input_dev *input_dev = to_input_dev(dev); \
591 int retval; \
592 \ 591 \
593 retval = mutex_lock_interruptible(&input_dev->mutex); \ 592 return scnprintf(buf, PAGE_SIZE, "%s\n", \
594 if (retval) \ 593 input_dev->name ? input_dev->name : ""); \
595 return retval; \
596 \
597 retval = scnprintf(buf, PAGE_SIZE, \
598 "%s\n", input_dev->name ? input_dev->name : ""); \
599 \
600 mutex_unlock(&input_dev->mutex); \
601 \
602 return retval; \
603} \ 594} \
604static CLASS_DEVICE_ATTR(name, S_IRUGO, input_dev_show_##name, NULL); 595static CLASS_DEVICE_ATTR(name, S_IRUGO, input_dev_show_##name, NULL);
605 596
@@ -1049,10 +1040,6 @@ void input_unregister_device(struct input_dev *dev)
1049 sysfs_remove_group(&dev->cdev.kobj, &input_dev_id_attr_group); 1040 sysfs_remove_group(&dev->cdev.kobj, &input_dev_id_attr_group);
1050 sysfs_remove_group(&dev->cdev.kobj, &input_dev_attr_group); 1041 sysfs_remove_group(&dev->cdev.kobj, &input_dev_attr_group);
1051 1042
1052 mutex_lock(&dev->mutex);
1053 dev->name = dev->phys = dev->uniq = NULL;
1054 mutex_unlock(&dev->mutex);
1055
1056 class_device_unregister(&dev->cdev); 1043 class_device_unregister(&dev->cdev);
1057 1044
1058 input_wakeup_procfs_readers(); 1045 input_wakeup_procfs_readers();
diff --git a/drivers/input/joystick/amijoy.c b/drivers/input/joystick/amijoy.c
index e608691b5a61..b0f5541ec3e6 100644
--- a/drivers/input/joystick/amijoy.c
+++ b/drivers/input/joystick/amijoy.c
@@ -50,8 +50,6 @@ static int amijoy[2] = { 0, 1 };
50module_param_array_named(map, amijoy, uint, NULL, 0); 50module_param_array_named(map, amijoy, uint, NULL, 0);
51MODULE_PARM_DESC(map, "Map of attached joysticks in form of <a>,<b> (default is 0,1)"); 51MODULE_PARM_DESC(map, "Map of attached joysticks in form of <a>,<b> (default is 0,1)");
52 52
53__obsolete_setup("amijoy=");
54
55static int amijoy_used; 53static int amijoy_used;
56static DEFINE_MUTEX(amijoy_mutex); 54static DEFINE_MUTEX(amijoy_mutex);
57static struct input_dev *amijoy_dev[2]; 55static struct input_dev *amijoy_dev[2];
diff --git a/drivers/input/joystick/analog.c b/drivers/input/joystick/analog.c
index 7ef68456d7d6..51f1e4bfff3e 100644
--- a/drivers/input/joystick/analog.c
+++ b/drivers/input/joystick/analog.c
@@ -58,8 +58,6 @@ static int analog_options[ANALOG_PORTS];
58module_param_array_named(map, js, charp, &js_nargs, 0); 58module_param_array_named(map, js, charp, &js_nargs, 0);
59MODULE_PARM_DESC(map, "Describes analog joysticks type/capabilities"); 59MODULE_PARM_DESC(map, "Describes analog joysticks type/capabilities");
60 60
61__obsolete_setup("js=");
62
63/* 61/*
64 * Times, feature definitions. 62 * Times, feature definitions.
65 */ 63 */
diff --git a/drivers/input/joystick/db9.c b/drivers/input/joystick/db9.c
index 5080e15c6d30..b41bd2eb37dd 100644
--- a/drivers/input/joystick/db9.c
+++ b/drivers/input/joystick/db9.c
@@ -59,10 +59,6 @@ MODULE_PARM_DESC(dev2, "Describes second attached device (<parport#>,<type>)");
59module_param_array_named(dev3, db9[2].args, int, &db9[2].nargs, 0); 59module_param_array_named(dev3, db9[2].args, int, &db9[2].nargs, 0);
60MODULE_PARM_DESC(dev3, "Describes third attached device (<parport#>,<type>)"); 60MODULE_PARM_DESC(dev3, "Describes third attached device (<parport#>,<type>)");
61 61
62__obsolete_setup("db9=");
63__obsolete_setup("db9_2=");
64__obsolete_setup("db9_3=");
65
66#define DB9_ARG_PARPORT 0 62#define DB9_ARG_PARPORT 0
67#define DB9_ARG_MODE 1 63#define DB9_ARG_MODE 1
68 64
diff --git a/drivers/input/joystick/gamecon.c b/drivers/input/joystick/gamecon.c
index fe12aa37393d..711e4b3e9e61 100644
--- a/drivers/input/joystick/gamecon.c
+++ b/drivers/input/joystick/gamecon.c
@@ -60,10 +60,6 @@ MODULE_PARM_DESC(map2, "Describes second set of devices");
60module_param_array_named(map3, gc[2].args, int, &gc[2].nargs, 0); 60module_param_array_named(map3, gc[2].args, int, &gc[2].nargs, 0);
61MODULE_PARM_DESC(map3, "Describes third set of devices"); 61MODULE_PARM_DESC(map3, "Describes third set of devices");
62 62
63__obsolete_setup("gc=");
64__obsolete_setup("gc_2=");
65__obsolete_setup("gc_3=");
66
67/* see also gs_psx_delay parameter in PSX support section */ 63/* see also gs_psx_delay parameter in PSX support section */
68 64
69#define GC_SNES 1 65#define GC_SNES 1
@@ -403,8 +399,6 @@ static int gc_psx_delay = GC_PSX_DELAY;
403module_param_named(psx_delay, gc_psx_delay, uint, 0); 399module_param_named(psx_delay, gc_psx_delay, uint, 0);
404MODULE_PARM_DESC(psx_delay, "Delay when accessing Sony PSX controller (usecs)"); 400MODULE_PARM_DESC(psx_delay, "Delay when accessing Sony PSX controller (usecs)");
405 401
406__obsolete_setup("gc_psx_delay=");
407
408static short gc_psx_abs[] = { ABS_X, ABS_Y, ABS_RX, ABS_RY, ABS_HAT0X, ABS_HAT0Y }; 402static short gc_psx_abs[] = { ABS_X, ABS_Y, ABS_RX, ABS_RY, ABS_HAT0X, ABS_HAT0Y };
409static short gc_psx_btn[] = { BTN_TL, BTN_TR, BTN_TL2, BTN_TR2, BTN_A, BTN_B, BTN_X, BTN_Y, 403static short gc_psx_btn[] = { BTN_TL, BTN_TR, BTN_TL2, BTN_TR2, BTN_A, BTN_B, BTN_X, BTN_Y,
410 BTN_START, BTN_SELECT, BTN_THUMBL, BTN_THUMBR }; 404 BTN_START, BTN_SELECT, BTN_THUMBL, BTN_THUMBR };
diff --git a/drivers/input/joystick/turbografx.c b/drivers/input/joystick/turbografx.c
index 5570fd5487c7..037d3487fcc7 100644
--- a/drivers/input/joystick/turbografx.c
+++ b/drivers/input/joystick/turbografx.c
@@ -60,10 +60,6 @@ MODULE_PARM_DESC(map2, "Describes second set of devices");
60module_param_array_named(map3, tgfx[2].args, int, &tgfx[2].nargs, 0); 60module_param_array_named(map3, tgfx[2].args, int, &tgfx[2].nargs, 0);
61MODULE_PARM_DESC(map3, "Describes third set of devices"); 61MODULE_PARM_DESC(map3, "Describes third set of devices");
62 62
63__obsolete_setup("tgfx=");
64__obsolete_setup("tgfx_2=");
65__obsolete_setup("tgfx_3=");
66
67#define TGFX_REFRESH_TIME HZ/100 /* 10 ms */ 63#define TGFX_REFRESH_TIME HZ/100 /* 10 ms */
68 64
69#define TGFX_TRIGGER 0x08 65#define TGFX_TRIGGER 0x08
diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
index 1b81a72e19d9..64509689fa65 100644
--- a/drivers/input/keyboard/Kconfig
+++ b/drivers/input/keyboard/Kconfig
@@ -215,11 +215,11 @@ config KEYBOARD_AAED2000
215 module will be called aaed2000_kbd. 215 module will be called aaed2000_kbd.
216 216
217config KEYBOARD_GPIO 217config KEYBOARD_GPIO
218 tristate "Buttons on CPU GPIOs (PXA)" 218 tristate "Buttons on CPU GPIOs (PXA)"
219 depends on ARCH_PXA 219 depends on (ARCH_SA1100 || ARCH_PXA || ARCH_S3C2410)
220 help 220 help
221 This driver implements support for buttons connected 221 This driver implements support for buttons connected
222 directly to GPIO pins of PXA CPUs. 222 directly to GPIO pins of SA1100, PXA or S3C24xx CPUs.
223 223
224 Say Y here if your device has buttons connected 224 Say Y here if your device has buttons connected
225 directly to GPIO pins of the CPU. 225 directly to GPIO pins of the CPU.
diff --git a/drivers/input/keyboard/atkbd.c b/drivers/input/keyboard/atkbd.c
index c621a9177a56..663877076bc7 100644
--- a/drivers/input/keyboard/atkbd.c
+++ b/drivers/input/keyboard/atkbd.c
@@ -63,10 +63,6 @@ static int atkbd_extra;
63module_param_named(extra, atkbd_extra, bool, 0); 63module_param_named(extra, atkbd_extra, bool, 0);
64MODULE_PARM_DESC(extra, "Enable extra LEDs and keys on IBM RapidAcces, EzKey and similar keyboards"); 64MODULE_PARM_DESC(extra, "Enable extra LEDs and keys on IBM RapidAcces, EzKey and similar keyboards");
65 65
66__obsolete_setup("atkbd_set=");
67__obsolete_setup("atkbd_reset");
68__obsolete_setup("atkbd_softrepeat=");
69
70/* 66/*
71 * Scancode to keycode tables. These are just the default setting, and 67 * Scancode to keycode tables. These are just the default setting, and
72 * are loadable via an userland utility. 68 * are loadable via an userland utility.
diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c
index 7ad479e4e3b3..fa03a00b4c6d 100644
--- a/drivers/input/keyboard/gpio_keys.c
+++ b/drivers/input/keyboard/gpio_keys.c
@@ -24,7 +24,7 @@
24#include <linux/input.h> 24#include <linux/input.h>
25#include <linux/irq.h> 25#include <linux/irq.h>
26 26
27#include <asm/arch/pxa-regs.h> 27#include <asm/gpio.h>
28#include <asm/arch/hardware.h> 28#include <asm/arch/hardware.h>
29 29
30#include <asm/hardware/gpio_keys.h> 30#include <asm/hardware/gpio_keys.h>
@@ -38,8 +38,8 @@ static irqreturn_t gpio_keys_isr(int irq, void *dev_id)
38 38
39 for (i = 0; i < pdata->nbuttons; i++) { 39 for (i = 0; i < pdata->nbuttons; i++) {
40 int gpio = pdata->buttons[i].gpio; 40 int gpio = pdata->buttons[i].gpio;
41 if (irq == IRQ_GPIO(gpio)) { 41 if (irq == gpio_to_irq(gpio)) {
42 int state = ((GPLR(gpio) & GPIO_bit(gpio)) ? 1 : 0) ^ (pdata->buttons[i].active_low); 42 int state = (gpio_get_value(gpio) ? 1 : 0) ^ (pdata->buttons[i].active_low);
43 43
44 input_report_key(input, pdata->buttons[i].keycode, state); 44 input_report_key(input, pdata->buttons[i].keycode, state);
45 input_sync(input); 45 input_sync(input);
@@ -75,14 +75,15 @@ 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 int code = pdata->buttons[i].keycode; 77 int code = pdata->buttons[i].keycode;
78 int irq = IRQ_GPIO(pdata->buttons[i].gpio); 78 int irq = gpio_to_irq(pdata->buttons[i].gpio);
79 79
80 set_irq_type(irq, IRQ_TYPE_EDGE_BOTH); 80 set_irq_type(irq, IRQ_TYPE_EDGE_BOTH);
81 error = request_irq(irq, gpio_keys_isr, IRQF_SAMPLE_RANDOM, 81 error = request_irq(irq, gpio_keys_isr, IRQF_SAMPLE_RANDOM,
82 pdata->buttons[i].desc ? pdata->buttons[i].desc : "gpio_keys", 82 pdata->buttons[i].desc ? pdata->buttons[i].desc : "gpio_keys",
83 pdev); 83 pdev);
84 if (error) { 84 if (error) {
85 printk(KERN_ERR "gpio-keys: unable to claim irq %d; error %d\n", irq, ret); 85 printk(KERN_ERR "gpio-keys: unable to claim irq %d; error %d\n",
86 irq, error);
86 goto fail; 87 goto fail;
87 } 88 }
88 set_bit(code, input->keybit); 89 set_bit(code, input->keybit);
@@ -98,7 +99,7 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
98 99
99 fail: 100 fail:
100 for (i = i - 1; i >= 0; i--) 101 for (i = i - 1; i >= 0; i--)
101 free_irq(IRQ_GPIO(pdata->buttons[i].gpio), pdev); 102 free_irq(gpio_to_irq(pdata->buttons[i].gpio), pdev);
102 103
103 input_free_device(input); 104 input_free_device(input);
104 105
@@ -112,7 +113,7 @@ static int __devexit gpio_keys_remove(struct platform_device *pdev)
112 int i; 113 int i;
113 114
114 for (i = 0; i < pdata->nbuttons; i++) { 115 for (i = 0; i < pdata->nbuttons; i++) {
115 int irq = IRQ_GPIO(pdata->buttons[i].gpio); 116 int irq = gpio_to_irq(pdata->buttons[i].gpio);
116 free_irq(irq, pdev); 117 free_irq(irq, pdev);
117 } 118 }
118 119
diff --git a/drivers/input/keyboard/hilkbd.c b/drivers/input/keyboard/hilkbd.c
index 255a6ec75a48..4de4dc297d50 100644
--- a/drivers/input/keyboard/hilkbd.c
+++ b/drivers/input/keyboard/hilkbd.c
@@ -294,8 +294,10 @@ err3:
294 disable_irq(HIL_IRQ); 294 disable_irq(HIL_IRQ);
295 free_irq(HIL_IRQ, hil_dev.dev_id); 295 free_irq(HIL_IRQ, hil_dev.dev_id);
296err2: 296err2:
297#if defined(CONFIG_HP300)
297 release_region(HILBASE + HIL_DATA, 2); 298 release_region(HILBASE + HIL_DATA, 2);
298err1: 299err1:
300#endif
299 input_free_device(hil_dev.dev); 301 input_free_device(hil_dev.dev);
300 hil_dev.dev = NULL; 302 hil_dev.dev = NULL;
301 return err; 303 return err;
diff --git a/drivers/input/mouse/inport.c b/drivers/input/mouse/inport.c
index 701ebd5473cf..79b624fe8994 100644
--- a/drivers/input/mouse/inport.c
+++ b/drivers/input/mouse/inport.c
@@ -84,8 +84,6 @@ static int inport_irq = INPORT_IRQ;
84module_param_named(irq, inport_irq, uint, 0); 84module_param_named(irq, inport_irq, uint, 0);
85MODULE_PARM_DESC(irq, "IRQ number (5=default)"); 85MODULE_PARM_DESC(irq, "IRQ number (5=default)");
86 86
87__obsolete_setup("inport_irq=");
88
89static struct input_dev *inport_dev; 87static struct input_dev *inport_dev;
90 88
91static irqreturn_t inport_interrupt(int irq, void *dev_id) 89static irqreturn_t inport_interrupt(int irq, void *dev_id)
diff --git a/drivers/input/mouse/logibm.c b/drivers/input/mouse/logibm.c
index db205995bffd..26c3b2e2ca94 100644
--- a/drivers/input/mouse/logibm.c
+++ b/drivers/input/mouse/logibm.c
@@ -75,8 +75,6 @@ static int logibm_irq = LOGIBM_IRQ;
75module_param_named(irq, logibm_irq, uint, 0); 75module_param_named(irq, logibm_irq, uint, 0);
76MODULE_PARM_DESC(irq, "IRQ number (5=default)"); 76MODULE_PARM_DESC(irq, "IRQ number (5=default)");
77 77
78__obsolete_setup("logibm_irq=");
79
80static struct input_dev *logibm_dev; 78static struct input_dev *logibm_dev;
81 79
82static irqreturn_t logibm_interrupt(int irq, void *dev_id) 80static irqreturn_t logibm_interrupt(int irq, void *dev_id)
diff --git a/drivers/input/mouse/psmouse-base.c b/drivers/input/mouse/psmouse-base.c
index a0e4a033e2db..0fe5869d7d4c 100644
--- a/drivers/input/mouse/psmouse-base.c
+++ b/drivers/input/mouse/psmouse-base.c
@@ -93,12 +93,6 @@ static struct attribute_group psmouse_attribute_group = {
93 .attrs = psmouse_attributes, 93 .attrs = psmouse_attributes,
94}; 94};
95 95
96__obsolete_setup("psmouse_noext");
97__obsolete_setup("psmouse_resolution=");
98__obsolete_setup("psmouse_smartscroll=");
99__obsolete_setup("psmouse_resetafter=");
100__obsolete_setup("psmouse_rate=");
101
102/* 96/*
103 * psmouse_mutex protects all operations changing state of mouse 97 * psmouse_mutex protects all operations changing state of mouse
104 * (connecting, disconnecting, changing rate or resolution via 98 * (connecting, disconnecting, changing rate or resolution via
@@ -987,8 +981,36 @@ static void psmouse_resync(struct work_struct *work)
987static void psmouse_cleanup(struct serio *serio) 981static void psmouse_cleanup(struct serio *serio)
988{ 982{
989 struct psmouse *psmouse = serio_get_drvdata(serio); 983 struct psmouse *psmouse = serio_get_drvdata(serio);
984 struct psmouse *parent = NULL;
985
986 mutex_lock(&psmouse_mutex);
987
988 if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) {
989 parent = serio_get_drvdata(serio->parent);
990 psmouse_deactivate(parent);
991 }
992
993 psmouse_deactivate(psmouse);
994
995 if (psmouse->cleanup)
996 psmouse->cleanup(psmouse);
990 997
991 psmouse_reset(psmouse); 998 psmouse_reset(psmouse);
999
1000/*
1001 * Some boxes, such as HP nx7400, get terribly confused if mouse
1002 * is not fully enabled before suspending/shutting down.
1003 */
1004 ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_ENABLE);
1005
1006 if (parent) {
1007 if (parent->pt_deactivate)
1008 parent->pt_deactivate(parent);
1009
1010 psmouse_activate(parent);
1011 }
1012
1013 mutex_unlock(&psmouse_mutex);
992} 1014}
993 1015
994/* 1016/*
diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
index 1b74cae8a556..cf1de95b6f27 100644
--- a/drivers/input/mouse/psmouse.h
+++ b/drivers/input/mouse/psmouse.h
@@ -68,6 +68,7 @@ struct psmouse {
68 68
69 int (*reconnect)(struct psmouse *psmouse); 69 int (*reconnect)(struct psmouse *psmouse);
70 void (*disconnect)(struct psmouse *psmouse); 70 void (*disconnect)(struct psmouse *psmouse);
71 void (*cleanup)(struct psmouse *psmouse);
71 int (*poll)(struct psmouse *psmouse); 72 int (*poll)(struct psmouse *psmouse);
72 73
73 void (*pt_activate)(struct psmouse *psmouse); 74 void (*pt_activate)(struct psmouse *psmouse);
diff --git a/drivers/input/mouse/synaptics.c b/drivers/input/mouse/synaptics.c
index 49ac696d6cff..f0f9413d762c 100644
--- a/drivers/input/mouse/synaptics.c
+++ b/drivers/input/mouse/synaptics.c
@@ -652,6 +652,7 @@ int synaptics_init(struct psmouse *psmouse)
652 psmouse->set_rate = synaptics_set_rate; 652 psmouse->set_rate = synaptics_set_rate;
653 psmouse->disconnect = synaptics_disconnect; 653 psmouse->disconnect = synaptics_disconnect;
654 psmouse->reconnect = synaptics_reconnect; 654 psmouse->reconnect = synaptics_reconnect;
655 psmouse->cleanup = synaptics_reset;
655 psmouse->pktsize = 6; 656 psmouse->pktsize = 6;
656 /* Synaptics can usually stay in sync without extra help */ 657 /* Synaptics can usually stay in sync without extra help */
657 psmouse->resync_time = 0; 658 psmouse->resync_time = 0;
diff --git a/drivers/input/serio/i8042.c b/drivers/input/serio/i8042.c
index c3fdfc1f342a..ec195a36e8f6 100644
--- a/drivers/input/serio/i8042.c
+++ b/drivers/input/serio/i8042.c
@@ -76,13 +76,6 @@ module_param_named(debug, i8042_debug, bool, 0600);
76MODULE_PARM_DESC(debug, "Turn i8042 debugging mode on and off"); 76MODULE_PARM_DESC(debug, "Turn i8042 debugging mode on and off");
77#endif 77#endif
78 78
79__obsolete_setup("i8042_noaux");
80__obsolete_setup("i8042_nomux");
81__obsolete_setup("i8042_unlock");
82__obsolete_setup("i8042_reset");
83__obsolete_setup("i8042_direct");
84__obsolete_setup("i8042_dumbkbd");
85
86#include "i8042.h" 79#include "i8042.h"
87 80
88static DEFINE_SPINLOCK(i8042_lock); 81static DEFINE_SPINLOCK(i8042_lock);
@@ -724,7 +717,7 @@ static int i8042_controller_init(void)
724 if (~i8042_read_status() & I8042_STR_KEYLOCK) { 717 if (~i8042_read_status() & I8042_STR_KEYLOCK) {
725 if (i8042_unlock) 718 if (i8042_unlock)
726 i8042_ctr |= I8042_CTR_IGNKEYLOCK; 719 i8042_ctr |= I8042_CTR_IGNKEYLOCK;
727 else 720 else
728 printk(KERN_WARNING "i8042.c: Warning: Keylock active.\n"); 721 printk(KERN_WARNING "i8042.c: Warning: Keylock active.\n");
729 } 722 }
730 spin_unlock_irqrestore(&i8042_lock, flags); 723 spin_unlock_irqrestore(&i8042_lock, flags);
@@ -791,27 +784,6 @@ static void i8042_controller_reset(void)
791 784
792 785
793/* 786/*
794 * Here we try to reset everything back to a state in which the BIOS will be
795 * able to talk to the hardware when rebooting.
796 */
797
798static void i8042_controller_cleanup(void)
799{
800 int i;
801
802/*
803 * Reset anything that is connected to the ports.
804 */
805
806 for (i = 0; i < I8042_NUM_PORTS; i++)
807 if (i8042_ports[i].serio)
808 serio_cleanup(i8042_ports[i].serio);
809
810 i8042_controller_reset();
811}
812
813
814/*
815 * i8042_panic_blink() will flash the keyboard LEDs and is called when 787 * i8042_panic_blink() will flash the keyboard LEDs and is called when
816 * kernel panics. Flashing LEDs is useful for users running X who may 788 * kernel panics. Flashing LEDs is useful for users running X who may
817 * not see the console and will help distingushing panics from "real" 789 * not see the console and will help distingushing panics from "real"
@@ -857,13 +829,22 @@ static long i8042_panic_blink(long count)
857 829
858#undef DELAY 830#undef DELAY
859 831
832#ifdef CONFIG_PM
860/* 833/*
861 * Here we try to restore the original BIOS settings 834 * Here we try to restore the original BIOS settings. We only want to
835 * do that once, when we really suspend, not when we taking memory
836 * snapshot for swsusp (in this case we'll perform required cleanup
837 * as part of shutdown process).
862 */ 838 */
863 839
864static int i8042_suspend(struct platform_device *dev, pm_message_t state) 840static int i8042_suspend(struct platform_device *dev, pm_message_t state)
865{ 841{
866 i8042_controller_cleanup(); 842 if (dev->dev.power.power_state.event != state.event) {
843 if (state.event == PM_EVENT_SUSPEND)
844 i8042_controller_reset();
845
846 dev->dev.power.power_state = state;
847 }
867 848
868 return 0; 849 return 0;
869} 850}
@@ -877,6 +858,12 @@ static int i8042_resume(struct platform_device *dev)
877{ 858{
878 int error; 859 int error;
879 860
861/*
862 * Do not bother with restoring state if we haven't suspened yet
863 */
864 if (dev->dev.power.power_state.event == PM_EVENT_ON)
865 return 0;
866
880 error = i8042_controller_check(); 867 error = i8042_controller_check();
881 if (error) 868 if (error)
882 return error; 869 return error;
@@ -886,9 +873,12 @@ static int i8042_resume(struct platform_device *dev)
886 return error; 873 return error;
887 874
888/* 875/*
889 * Restore pre-resume CTR value and disable all ports 876 * Restore original CTR value and disable all ports
890 */ 877 */
891 878
879 i8042_ctr = i8042_initial_ctr;
880 if (i8042_direct)
881 i8042_ctr &= ~I8042_CTR_XLATE;
892 i8042_ctr |= I8042_CTR_AUXDIS | I8042_CTR_KBDDIS; 882 i8042_ctr |= I8042_CTR_AUXDIS | I8042_CTR_KBDDIS;
893 i8042_ctr &= ~(I8042_CTR_AUXINT | I8042_CTR_KBDINT); 883 i8042_ctr &= ~(I8042_CTR_AUXINT | I8042_CTR_KBDINT);
894 if (i8042_command(&i8042_ctr, I8042_CMD_CTL_WCTR)) { 884 if (i8042_command(&i8042_ctr, I8042_CMD_CTL_WCTR)) {
@@ -909,8 +899,11 @@ static int i8042_resume(struct platform_device *dev)
909 899
910 i8042_interrupt(0, NULL); 900 i8042_interrupt(0, NULL);
911 901
902 dev->dev.power.power_state = PMSG_ON;
903
912 return 0; 904 return 0;
913} 905}
906#endif /* CONFIG_PM */
914 907
915/* 908/*
916 * We need to reset the 8042 back to original mode on system shutdown, 909 * We need to reset the 8042 back to original mode on system shutdown,
@@ -919,7 +912,7 @@ static int i8042_resume(struct platform_device *dev)
919 912
920static void i8042_shutdown(struct platform_device *dev) 913static void i8042_shutdown(struct platform_device *dev)
921{ 914{
922 i8042_controller_cleanup(); 915 i8042_controller_reset();
923} 916}
924 917
925static int __devinit i8042_create_kbd_port(void) 918static int __devinit i8042_create_kbd_port(void)
@@ -1154,9 +1147,11 @@ static struct platform_driver i8042_driver = {
1154 }, 1147 },
1155 .probe = i8042_probe, 1148 .probe = i8042_probe,
1156 .remove = __devexit_p(i8042_remove), 1149 .remove = __devexit_p(i8042_remove),
1150 .shutdown = i8042_shutdown,
1151#ifdef CONFIG_PM
1157 .suspend = i8042_suspend, 1152 .suspend = i8042_suspend,
1158 .resume = i8042_resume, 1153 .resume = i8042_resume,
1159 .shutdown = i8042_shutdown, 1154#endif
1160}; 1155};
1161 1156
1162static int __init i8042_init(void) 1157static int __init i8042_init(void)
diff --git a/drivers/input/serio/libps2.c b/drivers/input/serio/libps2.c
index b3e84d3bb7f7..10d9d74ae43a 100644
--- a/drivers/input/serio/libps2.c
+++ b/drivers/input/serio/libps2.c
@@ -97,7 +97,7 @@ EXPORT_SYMBOL(ps2_drain);
97 97
98int ps2_is_keyboard_id(char id_byte) 98int ps2_is_keyboard_id(char id_byte)
99{ 99{
100 const static char keyboard_ids[] = { 100 static const char keyboard_ids[] = {
101 0xab, /* Regular keyboards */ 101 0xab, /* Regular keyboards */
102 0xac, /* NCD Sun keyboard */ 102 0xac, /* NCD Sun keyboard */
103 0x2b, /* Trust keyboard, translated */ 103 0x2b, /* Trust keyboard, translated */
diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
index 17c8c63cbe1a..a15e531ec755 100644
--- a/drivers/input/serio/serio.c
+++ b/drivers/input/serio/serio.c
@@ -778,6 +778,19 @@ static int serio_driver_remove(struct device *dev)
778 return 0; 778 return 0;
779} 779}
780 780
781static void serio_cleanup(struct serio *serio)
782{
783 if (serio->drv && serio->drv->cleanup)
784 serio->drv->cleanup(serio);
785}
786
787static void serio_shutdown(struct device *dev)
788{
789 struct serio *serio = to_serio_port(dev);
790
791 serio_cleanup(serio);
792}
793
781static void serio_attach_driver(struct serio_driver *drv) 794static void serio_attach_driver(struct serio_driver *drv)
782{ 795{
783 int error; 796 int error;
@@ -910,11 +923,25 @@ static int serio_uevent(struct device *dev, char **envp, int num_envp, char *buf
910 923
911#endif /* CONFIG_HOTPLUG */ 924#endif /* CONFIG_HOTPLUG */
912 925
926#ifdef CONFIG_PM
927static int serio_suspend(struct device *dev, pm_message_t state)
928{
929 if (dev->power.power_state.event != state.event) {
930 if (state.event == PM_EVENT_SUSPEND)
931 serio_cleanup(to_serio_port(dev));
932
933 dev->power.power_state = state;
934 }
935
936 return 0;
937}
938
913static int serio_resume(struct device *dev) 939static int serio_resume(struct device *dev)
914{ 940{
915 struct serio *serio = to_serio_port(dev); 941 struct serio *serio = to_serio_port(dev);
916 942
917 if (serio_reconnect_driver(serio)) { 943 if (dev->power.power_state.event != PM_EVENT_ON &&
944 serio_reconnect_driver(serio)) {
918 /* 945 /*
919 * Driver re-probing can take a while, so better let kseriod 946 * Driver re-probing can take a while, so better let kseriod
920 * deal with it. 947 * deal with it.
@@ -922,8 +949,11 @@ static int serio_resume(struct device *dev)
922 serio_rescan(serio); 949 serio_rescan(serio);
923 } 950 }
924 951
952 dev->power.power_state = PMSG_ON;
953
925 return 0; 954 return 0;
926} 955}
956#endif /* CONFIG_PM */
927 957
928/* called from serio_driver->connect/disconnect methods under serio_mutex */ 958/* called from serio_driver->connect/disconnect methods under serio_mutex */
929int serio_open(struct serio *serio, struct serio_driver *drv) 959int serio_open(struct serio *serio, struct serio_driver *drv)
@@ -974,7 +1004,11 @@ static struct bus_type serio_bus = {
974 .uevent = serio_uevent, 1004 .uevent = serio_uevent,
975 .probe = serio_driver_probe, 1005 .probe = serio_driver_probe,
976 .remove = serio_driver_remove, 1006 .remove = serio_driver_remove,
1007 .shutdown = serio_shutdown,
1008#ifdef CONFIG_PM
1009 .suspend = serio_suspend,
977 .resume = serio_resume, 1010 .resume = serio_resume,
1011#endif
978}; 1012};
979 1013
980static int __init serio_init(void) 1014static int __init serio_init(void)
diff --git a/drivers/isdn/i4l/isdn_ppp.c b/drivers/isdn/i4l/isdn_ppp.c
index 4e3f127e4003..1b2df80c3bce 100644
--- a/drivers/isdn/i4l/isdn_ppp.c
+++ b/drivers/isdn/i4l/isdn_ppp.c
@@ -1680,7 +1680,7 @@ static void isdn_ppp_mp_receive(isdn_net_dev * net_dev, isdn_net_local * lp,
1680 * - we hit a gap in the sequence, so no reassembly/processing is 1680 * - we hit a gap in the sequence, so no reassembly/processing is
1681 * possible ('start' would be set to NULL) 1681 * possible ('start' would be set to NULL)
1682 * 1682 *
1683 * algorightm for this code is derived from code in the book 1683 * algorithm for this code is derived from code in the book
1684 * 'PPP Design And Debugging' by James Carlson (Addison-Wesley) 1684 * 'PPP Design And Debugging' by James Carlson (Addison-Wesley)
1685 */ 1685 */
1686 while (start != NULL || newfrag != NULL) { 1686 while (start != NULL || newfrag != NULL) {
diff --git a/drivers/media/dvb/dvb-core/dvb_frontend.c b/drivers/media/dvb/dvb-core/dvb_frontend.c
index e85972222ab4..7c42d53a1cc7 100644
--- a/drivers/media/dvb/dvb-core/dvb_frontend.c
+++ b/drivers/media/dvb/dvb-core/dvb_frontend.c
@@ -915,7 +915,7 @@ static int dvb_frontend_ioctl(struct inode *inode, struct file *file,
915 fetunesettings.parameters.inversion = INVERSION_AUTO; 915 fetunesettings.parameters.inversion = INVERSION_AUTO;
916 } 916 }
917 if (fe->ops.info.type == FE_OFDM) { 917 if (fe->ops.info.type == FE_OFDM) {
918 /* without hierachical coding code_rate_LP is irrelevant, 918 /* without hierarchical coding code_rate_LP is irrelevant,
919 * so we tolerate the otherwise invalid FEC_NONE setting */ 919 * so we tolerate the otherwise invalid FEC_NONE setting */
920 if (fepriv->parameters.u.ofdm.hierarchy_information == HIERARCHY_NONE && 920 if (fepriv->parameters.u.ofdm.hierarchy_information == HIERARCHY_NONE &&
921 fepriv->parameters.u.ofdm.code_rate_LP == FEC_NONE) 921 fepriv->parameters.u.ofdm.code_rate_LP == FEC_NONE)
diff --git a/drivers/media/dvb/frontends/dib3000mb.c b/drivers/media/dvb/frontends/dib3000mb.c
index adbabfdb04a9..b6adea5ffeb8 100644
--- a/drivers/media/dvb/frontends/dib3000mb.c
+++ b/drivers/media/dvb/frontends/dib3000mb.c
@@ -239,7 +239,7 @@ static int dib3000mb_set_frontend(struct dvb_frontend* fe,
239 default: 239 default:
240 return -EINVAL; 240 return -EINVAL;
241 } 241 }
242 deb_setf("hierachy: "); 242 deb_setf("hierarchy: ");
243 switch (ofdm->hierarchy_information) { 243 switch (ofdm->hierarchy_information) {
244 case HIERARCHY_NONE: 244 case HIERARCHY_NONE:
245 deb_setf("none "); 245 deb_setf("none ");
diff --git a/drivers/media/video/pvrusb2/pvrusb2-audio.c b/drivers/media/video/pvrusb2/pvrusb2-audio.c
index 9846c464ec80..122496f36845 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-audio.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-audio.c
@@ -158,7 +158,7 @@ static unsigned int pvr2_msp3400_describe(struct pvr2_msp3400_handler *ctxt,
158} 158}
159 159
160 160
161const static struct pvr2_i2c_handler_functions msp3400_funcs = { 161static const struct pvr2_i2c_handler_functions msp3400_funcs = {
162 .detach = (void (*)(void *))pvr2_msp3400_detach, 162 .detach = (void (*)(void *))pvr2_msp3400_detach,
163 .check = (int (*)(void *))msp3400_check, 163 .check = (int (*)(void *))msp3400_check,
164 .update = (void (*)(void *))msp3400_update, 164 .update = (void (*)(void *))msp3400_update,
diff --git a/drivers/media/video/pvrusb2/pvrusb2-cx2584x-v4l.c b/drivers/media/video/pvrusb2/pvrusb2-cx2584x-v4l.c
index 848fb233d808..8df969c4874c 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-cx2584x-v4l.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-cx2584x-v4l.c
@@ -226,7 +226,7 @@ static void decoder_reset(struct pvr2_v4l_cx2584x *ctxt)
226} 226}
227 227
228 228
229const static struct pvr2_i2c_handler_functions hfuncs = { 229static const struct pvr2_i2c_handler_functions hfuncs = {
230 .detach = (void (*)(void *))decoder_detach, 230 .detach = (void (*)(void *))decoder_detach,
231 .check = (int (*)(void *))decoder_check, 231 .check = (int (*)(void *))decoder_check,
232 .update = (void (*)(void *))decoder_update, 232 .update = (void (*)(void *))decoder_update,
diff --git a/drivers/media/video/pvrusb2/pvrusb2-std.c b/drivers/media/video/pvrusb2/pvrusb2-std.c
index f95c598ff627..c08925557ed4 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-std.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-std.c
@@ -78,14 +78,14 @@ struct std_name {
78#define CSTD_ALL (CSTD_PAL|CSTD_NTSC|CSTD_SECAM) 78#define CSTD_ALL (CSTD_PAL|CSTD_NTSC|CSTD_SECAM)
79 79
80/* Mapping of standard bits to color system */ 80/* Mapping of standard bits to color system */
81const static struct std_name std_groups[] = { 81static const struct std_name std_groups[] = {
82 {"PAL",CSTD_PAL}, 82 {"PAL",CSTD_PAL},
83 {"NTSC",CSTD_NTSC}, 83 {"NTSC",CSTD_NTSC},
84 {"SECAM",CSTD_SECAM}, 84 {"SECAM",CSTD_SECAM},
85}; 85};
86 86
87/* Mapping of standard bits to modulation system */ 87/* Mapping of standard bits to modulation system */
88const static struct std_name std_items[] = { 88static const struct std_name std_items[] = {
89 {"B",TSTD_B}, 89 {"B",TSTD_B},
90 {"B1",TSTD_B1}, 90 {"B1",TSTD_B1},
91 {"D",TSTD_D}, 91 {"D",TSTD_D},
diff --git a/drivers/media/video/pvrusb2/pvrusb2-tuner.c b/drivers/media/video/pvrusb2/pvrusb2-tuner.c
index af9f246f8d3f..bb17db3f6434 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-tuner.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-tuner.c
@@ -80,7 +80,7 @@ static unsigned int pvr2_tuner_describe(struct pvr2_tuner_handler *ctxt,char *bu
80} 80}
81 81
82 82
83const static struct pvr2_i2c_handler_functions tuner_funcs = { 83static const struct pvr2_i2c_handler_functions tuner_funcs = {
84 .detach = (void (*)(void *))pvr2_tuner_detach, 84 .detach = (void (*)(void *))pvr2_tuner_detach,
85 .check = (int (*)(void *))tuner_check, 85 .check = (int (*)(void *))tuner_check,
86 .update = (void (*)(void *))tuner_update, 86 .update = (void (*)(void *))tuner_update,
diff --git a/drivers/media/video/pvrusb2/pvrusb2-video-v4l.c b/drivers/media/video/pvrusb2/pvrusb2-video-v4l.c
index 05f2cddeb47b..2a826464911a 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-video-v4l.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-video-v4l.c
@@ -201,7 +201,7 @@ static unsigned int decoder_describe(struct pvr2_v4l_decoder *ctxt,char *buf,uns
201} 201}
202 202
203 203
204const static struct pvr2_i2c_handler_functions hfuncs = { 204static const struct pvr2_i2c_handler_functions hfuncs = {
205 .detach = (void (*)(void *))decoder_detach, 205 .detach = (void (*)(void *))decoder_detach,
206 .check = (int (*)(void *))decoder_check, 206 .check = (int (*)(void *))decoder_check,
207 .update = (void (*)(void *))decoder_update, 207 .update = (void (*)(void *))decoder_update,
diff --git a/drivers/media/video/pvrusb2/pvrusb2-wm8775.c b/drivers/media/video/pvrusb2/pvrusb2-wm8775.c
index 2413e5198e16..7794c34c355e 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-wm8775.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-wm8775.c
@@ -126,7 +126,7 @@ static void wm8775_update(struct pvr2_v4l_wm8775 *ctxt)
126} 126}
127 127
128 128
129const static struct pvr2_i2c_handler_functions hfuncs = { 129static const struct pvr2_i2c_handler_functions hfuncs = {
130 .detach = (void (*)(void *))wm8775_detach, 130 .detach = (void (*)(void *))wm8775_detach,
131 .check = (int (*)(void *))wm8775_check, 131 .check = (int (*)(void *))wm8775_check,
132 .update = (void (*)(void *))wm8775_update, 132 .update = (void (*)(void *))wm8775_update,
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index bedae4ad3f74..80b199fa0aa9 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -107,4 +107,19 @@ config MSI_LAPTOP
107 107
108 If you have an MSI S270 laptop, say Y or M here. 108 If you have an MSI S270 laptop, say Y or M here.
109 109
110config SONY_LAPTOP
111 tristate "Sony Laptop Extras"
112 depends on X86 && ACPI
113 select BACKLIGHT_CLASS_DEVICE
114 ---help---
115 This mini-driver drives the SNC device present in the ACPI BIOS of
116 the Sony Vaio laptops.
117
118 It gives access to some extra laptop functionalities. In its current
119 form, this driver let the user set or query the screen brightness
120 through the backlight subsystem and remove/apply power to some
121 devices.
122
123 Read <file:Documentation/sony-laptop.txt> for more information.
124
110endmenu 125endmenu
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index 35da53c409c0..7793ccd79049 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -11,3 +11,4 @@ obj-$(CONFIG_LKDTM) += lkdtm.o
11obj-$(CONFIG_TIFM_CORE) += tifm_core.o 11obj-$(CONFIG_TIFM_CORE) += tifm_core.o
12obj-$(CONFIG_TIFM_7XX1) += tifm_7xx1.o 12obj-$(CONFIG_TIFM_7XX1) += tifm_7xx1.o
13obj-$(CONFIG_SGI_IOC4) += ioc4.o 13obj-$(CONFIG_SGI_IOC4) += ioc4.o
14obj-$(CONFIG_SONY_LAPTOP) += sony-laptop.o
diff --git a/drivers/misc/asus-laptop.c b/drivers/misc/asus-laptop.c
index 861c39935f99..e4e2b707a353 100644
--- a/drivers/misc/asus-laptop.c
+++ b/drivers/misc/asus-laptop.c
@@ -1088,11 +1088,6 @@ static int __init asus_laptop_init(void)
1088 if (acpi_disabled) 1088 if (acpi_disabled)
1089 return -ENODEV; 1089 return -ENODEV;
1090 1090
1091 if (!acpi_specific_hotkey_enabled) {
1092 printk(ASUS_ERR "Using generic hotkey driver\n");
1093 return -ENODEV;
1094 }
1095
1096 result = acpi_bus_register_driver(&asus_hotk_driver); 1091 result = acpi_bus_register_driver(&asus_hotk_driver);
1097 if (result < 0) 1092 if (result < 0)
1098 return result; 1093 return result;
diff --git a/drivers/misc/sony-laptop.c b/drivers/misc/sony-laptop.c
new file mode 100644
index 000000000000..cabbed0015e4
--- /dev/null
+++ b/drivers/misc/sony-laptop.c
@@ -0,0 +1,562 @@
1/*
2 * ACPI Sony Notebook Control Driver (SNC)
3 *
4 * Copyright (C) 2004-2005 Stelian Pop <stelian@popies.net>
5 * Copyright (C) 2007 Mattia Dongili <malattia@linux.it>
6 *
7 * Parts of this driver inspired from asus_acpi.c and ibm_acpi.c
8 * which are copyrighted by their respective authors.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 *
24 */
25
26#include <linux/kernel.h>
27#include <linux/module.h>
28#include <linux/moduleparam.h>
29#include <linux/init.h>
30#include <linux/types.h>
31#include <linux/backlight.h>
32#include <linux/platform_device.h>
33#include <linux/err.h>
34#include <acpi/acpi_drivers.h>
35#include <acpi/acpi_bus.h>
36#include <asm/uaccess.h>
37
38#define ACPI_SNC_CLASS "sony"
39#define ACPI_SNC_HID "SNY5001"
40#define ACPI_SNC_DRIVER_NAME "ACPI Sony Notebook Control Driver v0.4"
41
42/* the device uses 1-based values, while the backlight subsystem uses
43 0-based values */
44#define SONY_MAX_BRIGHTNESS 8
45
46#define LOG_PFX KERN_WARNING "sony-laptop: "
47
48MODULE_AUTHOR("Stelian Pop, Mattia Dongili");
49MODULE_DESCRIPTION(ACPI_SNC_DRIVER_NAME);
50MODULE_LICENSE("GPL");
51
52static int debug;
53module_param(debug, int, 0);
54MODULE_PARM_DESC(debug, "set this to 1 (and RTFM) if you want to help "
55 "the development of this driver");
56
57static ssize_t sony_acpi_show(struct device *, struct device_attribute *,
58 char *);
59static ssize_t sony_acpi_store(struct device *, struct device_attribute *,
60 const char *, size_t);
61static int boolean_validate(const int, const int);
62static int brightness_default_validate(const int, const int);
63
64#define SNC_VALIDATE_IN 0
65#define SNC_VALIDATE_OUT 1
66
67struct sony_acpi_value {
68 char *name; /* name of the entry */
69 char **acpiget; /* names of the ACPI get function */
70 char **acpiset; /* names of the ACPI set function */
71 int (*validate)(const int, const int); /* input/output validation */
72 int value; /* current setting */
73 int valid; /* Has ever been set */
74 int debug; /* active only in debug mode ? */
75 struct device_attribute devattr; /* sysfs atribute */
76};
77
78#define HANDLE_NAMES(_name, _values...) \
79 static char *snc_##_name[] = { _values, NULL }
80
81#define SONY_ACPI_VALUE(_name, _getters, _setters, _validate, _debug) \
82 { \
83 .name = __stringify(_name), \
84 .acpiget = _getters, \
85 .acpiset = _setters, \
86 .validate = _validate, \
87 .debug = _debug, \
88 .devattr = __ATTR(_name, 0, sony_acpi_show, sony_acpi_store), \
89 }
90
91#define SONY_ACPI_VALUE_NULL { .name = NULL }
92
93HANDLE_NAMES(fnkey_get, "GHKE");
94
95HANDLE_NAMES(brightness_def_get, "GPBR");
96HANDLE_NAMES(brightness_def_set, "SPBR");
97
98HANDLE_NAMES(cdpower_get, "GCDP");
99HANDLE_NAMES(cdpower_set, "SCDP", "CDPW");
100
101HANDLE_NAMES(audiopower_get, "GAZP");
102HANDLE_NAMES(audiopower_set, "AZPW");
103
104HANDLE_NAMES(lanpower_get, "GLNP");
105HANDLE_NAMES(lanpower_set, "LNPW");
106
107HANDLE_NAMES(PID_get, "GPID");
108
109HANDLE_NAMES(CTR_get, "GCTR");
110HANDLE_NAMES(CTR_set, "SCTR");
111
112HANDLE_NAMES(PCR_get, "GPCR");
113HANDLE_NAMES(PCR_set, "SPCR");
114
115HANDLE_NAMES(CMI_get, "GCMI");
116HANDLE_NAMES(CMI_set, "SCMI");
117
118static struct sony_acpi_value sony_acpi_values[] = {
119 SONY_ACPI_VALUE(brightness_default, snc_brightness_def_get,
120 snc_brightness_def_set, brightness_default_validate, 0),
121 SONY_ACPI_VALUE(fnkey, snc_fnkey_get, NULL, NULL, 0),
122 SONY_ACPI_VALUE(cdpower, snc_cdpower_get, snc_cdpower_set, boolean_validate, 0),
123 SONY_ACPI_VALUE(audiopower, snc_audiopower_get, snc_audiopower_set,
124 boolean_validate, 0),
125 SONY_ACPI_VALUE(lanpower, snc_lanpower_get, snc_lanpower_set,
126 boolean_validate, 1),
127 /* unknown methods */
128 SONY_ACPI_VALUE(PID, snc_PID_get, NULL, NULL, 1),
129 SONY_ACPI_VALUE(CTR, snc_CTR_get, snc_CTR_set, NULL, 1),
130 SONY_ACPI_VALUE(PCR, snc_PCR_get, snc_PCR_set, NULL, 1),
131 SONY_ACPI_VALUE(CMI, snc_CMI_get, snc_CMI_set, NULL, 1),
132 SONY_ACPI_VALUE_NULL
133};
134
135static acpi_handle sony_acpi_handle;
136static struct acpi_device *sony_acpi_acpi_device = NULL;
137
138/*
139 * acpi_evaluate_object wrappers
140 */
141static int acpi_callgetfunc(acpi_handle handle, char *name, int *result)
142{
143 struct acpi_buffer output;
144 union acpi_object out_obj;
145 acpi_status status;
146
147 output.length = sizeof(out_obj);
148 output.pointer = &out_obj;
149
150 status = acpi_evaluate_object(handle, name, NULL, &output);
151 if ((status == AE_OK) && (out_obj.type == ACPI_TYPE_INTEGER)) {
152 *result = out_obj.integer.value;
153 return 0;
154 }
155
156 printk(LOG_PFX "acpi_callreadfunc failed\n");
157
158 return -1;
159}
160
161static int acpi_callsetfunc(acpi_handle handle, char *name, int value,
162 int *result)
163{
164 struct acpi_object_list params;
165 union acpi_object in_obj;
166 struct acpi_buffer output;
167 union acpi_object out_obj;
168 acpi_status status;
169
170 params.count = 1;
171 params.pointer = &in_obj;
172 in_obj.type = ACPI_TYPE_INTEGER;
173 in_obj.integer.value = value;
174
175 output.length = sizeof(out_obj);
176 output.pointer = &out_obj;
177
178 status = acpi_evaluate_object(handle, name, &params, &output);
179 if (status == AE_OK) {
180 if (result != NULL) {
181 if (out_obj.type != ACPI_TYPE_INTEGER) {
182 printk(LOG_PFX "acpi_evaluate_object bad "
183 "return type\n");
184 return -1;
185 }
186 *result = out_obj.integer.value;
187 }
188 return 0;
189 }
190
191 printk(LOG_PFX "acpi_evaluate_object failed\n");
192
193 return -1;
194}
195
196/*
197 * sony_acpi_values input/output validate functions
198 */
199
200/* brightness_default_validate:
201 *
202 * manipulate input output values to keep consistency with the
203 * backlight framework for which brightness values are 0-based.
204 */
205static int brightness_default_validate(const int direction, const int value)
206{
207 switch (direction) {
208 case SNC_VALIDATE_OUT:
209 return value - 1;
210 case SNC_VALIDATE_IN:
211 if (value >= 0 && value < SONY_MAX_BRIGHTNESS)
212 return value + 1;
213 }
214 return -EINVAL;
215}
216
217/* boolean_validate:
218 *
219 * on input validate boolean values 0/1, on output just pass the
220 * received value.
221 */
222static int boolean_validate(const int direction, const int value)
223{
224 if (direction == SNC_VALIDATE_IN) {
225 if (value != 0 && value != 1)
226 return -EINVAL;
227 }
228 return value;
229}
230
231/*
232 * Sysfs show/store common to all sony_acpi_values
233 */
234static ssize_t sony_acpi_show(struct device *dev, struct device_attribute *attr,
235 char *buffer)
236{
237 int value;
238 struct sony_acpi_value *item =
239 container_of(attr, struct sony_acpi_value, devattr);
240
241 if (!*item->acpiget)
242 return -EIO;
243
244 if (acpi_callgetfunc(sony_acpi_handle, *item->acpiget, &value) < 0)
245 return -EIO;
246
247 if (item->validate)
248 value = item->validate(SNC_VALIDATE_OUT, value);
249
250 return snprintf(buffer, PAGE_SIZE, "%d\n", value);
251}
252
253static ssize_t sony_acpi_store(struct device *dev,
254 struct device_attribute *attr,
255 const char *buffer, size_t count)
256{
257 int value;
258 struct sony_acpi_value *item =
259 container_of(attr, struct sony_acpi_value, devattr);
260
261 if (!item->acpiset)
262 return -EIO;
263
264 if (count > 31)
265 return -EINVAL;
266
267 value = simple_strtoul(buffer, NULL, 10);
268
269 if (item->validate)
270 value = item->validate(SNC_VALIDATE_IN, value);
271
272 if (value < 0)
273 return value;
274
275 if (acpi_callsetfunc(sony_acpi_handle, *item->acpiset, value, NULL) < 0)
276 return -EIO;
277 item->value = value;
278 item->valid = 1;
279 return count;
280}
281
282/*
283 * Platform device
284 */
285static struct platform_driver sncpf_driver = {
286 .driver = {
287 .name = "sony-laptop",
288 .owner = THIS_MODULE,
289 }
290};
291static struct platform_device *sncpf_device;
292
293static int sony_snc_pf_add(void)
294{
295 acpi_handle handle;
296 struct sony_acpi_value *item;
297 int ret = 0;
298
299 ret = platform_driver_register(&sncpf_driver);
300 if (ret)
301 goto out;
302
303 sncpf_device = platform_device_alloc("sony-laptop", -1);
304 if (!sncpf_device) {
305 ret = -ENOMEM;
306 goto out_platform_registered;
307 }
308
309 ret = platform_device_add(sncpf_device);
310 if (ret)
311 goto out_platform_alloced;
312
313 for (item = sony_acpi_values; item->name; ++item) {
314
315 if (!debug && item->debug)
316 continue;
317
318 /* find the available acpiget as described in the DSDT */
319 for (; item->acpiget && *item->acpiget; ++item->acpiget) {
320 if (ACPI_SUCCESS(acpi_get_handle(sony_acpi_handle,
321 *item->acpiget,
322 &handle))) {
323 if (debug)
324 printk(LOG_PFX "Found %s getter: %s\n",
325 item->name, *item->acpiget);
326 item->devattr.attr.mode |= S_IRUGO;
327 break;
328 }
329 }
330
331 /* find the available acpiset as described in the DSDT */
332 for (; item->acpiset && *item->acpiset; ++item->acpiset) {
333 if (ACPI_SUCCESS(acpi_get_handle(sony_acpi_handle,
334 *item->acpiset,
335 &handle))) {
336 if (debug)
337 printk(LOG_PFX "Found %s setter: %s\n",
338 item->name, *item->acpiset);
339 item->devattr.attr.mode |= S_IWUSR;
340 break;
341 }
342 }
343
344 if (item->devattr.attr.mode != 0) {
345 ret =
346 device_create_file(&sncpf_device->dev,
347 &item->devattr);
348 if (ret)
349 goto out_sysfs;
350 }
351 }
352
353 return 0;
354
355 out_sysfs:
356 for (item = sony_acpi_values; item->name; ++item) {
357 device_remove_file(&sncpf_device->dev, &item->devattr);
358 }
359 platform_device_del(sncpf_device);
360 out_platform_alloced:
361 platform_device_put(sncpf_device);
362 out_platform_registered:
363 platform_driver_unregister(&sncpf_driver);
364 out:
365 return ret;
366}
367
368static void sony_snc_pf_remove(void)
369{
370 struct sony_acpi_value *item;
371
372 for (item = sony_acpi_values; item->name; ++item) {
373 device_remove_file(&sncpf_device->dev, &item->devattr);
374 }
375
376 platform_device_del(sncpf_device);
377 platform_device_put(sncpf_device);
378 platform_driver_unregister(&sncpf_driver);
379}
380
381/*
382 * Backlight device
383 */
384static int sony_backlight_update_status(struct backlight_device *bd)
385{
386 return acpi_callsetfunc(sony_acpi_handle, "SBRT",
387 bd->props->brightness + 1, NULL);
388}
389
390static int sony_backlight_get_brightness(struct backlight_device *bd)
391{
392 int value;
393
394 if (acpi_callgetfunc(sony_acpi_handle, "GBRT", &value))
395 return 0;
396 /* brightness levels are 1-based, while backlight ones are 0-based */
397 return value - 1;
398}
399
400static struct backlight_device *sony_backlight_device;
401static struct backlight_properties sony_backlight_properties = {
402 .owner = THIS_MODULE,
403 .update_status = sony_backlight_update_status,
404 .get_brightness = sony_backlight_get_brightness,
405 .max_brightness = SONY_MAX_BRIGHTNESS - 1,
406};
407
408/*
409 * ACPI callbacks
410 */
411static void sony_acpi_notify(acpi_handle handle, u32 event, void *data)
412{
413 if (debug)
414 printk(LOG_PFX "sony_acpi_notify, event: %d\n", event);
415 acpi_bus_generate_event(sony_acpi_acpi_device, 1, event);
416}
417
418static acpi_status sony_walk_callback(acpi_handle handle, u32 level,
419 void *context, void **return_value)
420{
421 struct acpi_namespace_node *node;
422 union acpi_operand_object *operand;
423
424 node = (struct acpi_namespace_node *)handle;
425 operand = (union acpi_operand_object *)node->object;
426
427 printk(LOG_PFX "method: name: %4.4s, args %X\n", node->name.ascii,
428 (u32) operand->method.param_count);
429
430 return AE_OK;
431}
432
433/*
434 * ACPI device
435 */
436static int sony_acpi_resume(struct acpi_device *device)
437{
438 struct sony_acpi_value *item;
439
440 for (item = sony_acpi_values; item->name; item++) {
441 int ret;
442
443 if (!item->valid)
444 continue;
445 ret = acpi_callsetfunc(sony_acpi_handle, *item->acpiset,
446 item->value, NULL);
447 if (ret < 0) {
448 printk("%s: %d\n", __FUNCTION__, ret);
449 break;
450 }
451 }
452 return 0;
453}
454
455static int sony_acpi_add(struct acpi_device *device)
456{
457 acpi_status status;
458 int result;
459 acpi_handle handle;
460
461 sony_acpi_acpi_device = device;
462
463 sony_acpi_handle = device->handle;
464
465 if (debug) {
466 status = acpi_walk_namespace(ACPI_TYPE_METHOD, sony_acpi_handle,
467 1, sony_walk_callback, NULL, NULL);
468 if (ACPI_FAILURE(status)) {
469 printk(LOG_PFX "unable to walk acpi resources\n");
470 result = -ENODEV;
471 goto outwalk;
472 }
473 }
474
475 status = acpi_install_notify_handler(sony_acpi_handle,
476 ACPI_DEVICE_NOTIFY,
477 sony_acpi_notify, NULL);
478 if (ACPI_FAILURE(status)) {
479 printk(LOG_PFX "unable to install notify handler\n");
480 result = -ENODEV;
481 goto outwalk;
482 }
483
484 if (ACPI_SUCCESS(acpi_get_handle(sony_acpi_handle, "GBRT", &handle))) {
485 sony_backlight_device = backlight_device_register("sony", NULL,
486 NULL,
487 &sony_backlight_properties);
488
489 if (IS_ERR(sony_backlight_device)) {
490 printk(LOG_PFX "unable to register backlight device\n");
491 sony_backlight_device = NULL;
492 } else
493 sony_backlight_properties.brightness =
494 sony_backlight_get_brightness
495 (sony_backlight_device);
496 }
497
498 if (sony_snc_pf_add())
499 goto outbacklight;
500
501 printk(KERN_INFO ACPI_SNC_DRIVER_NAME " successfully installed\n");
502
503 return 0;
504
505 outbacklight:
506 if (sony_backlight_device)
507 backlight_device_unregister(sony_backlight_device);
508
509 status = acpi_remove_notify_handler(sony_acpi_handle,
510 ACPI_DEVICE_NOTIFY,
511 sony_acpi_notify);
512 if (ACPI_FAILURE(status))
513 printk(LOG_PFX "unable to remove notify handler\n");
514 outwalk:
515 return result;
516}
517
518static int sony_acpi_remove(struct acpi_device *device, int type)
519{
520 acpi_status status;
521
522 if (sony_backlight_device)
523 backlight_device_unregister(sony_backlight_device);
524
525 sony_acpi_acpi_device = NULL;
526
527 status = acpi_remove_notify_handler(sony_acpi_handle,
528 ACPI_DEVICE_NOTIFY,
529 sony_acpi_notify);
530 if (ACPI_FAILURE(status))
531 printk(LOG_PFX "unable to remove notify handler\n");
532
533 sony_snc_pf_remove();
534
535 printk(KERN_INFO ACPI_SNC_DRIVER_NAME " successfully removed\n");
536
537 return 0;
538}
539
540static struct acpi_driver sony_acpi_driver = {
541 .name = ACPI_SNC_DRIVER_NAME,
542 .class = ACPI_SNC_CLASS,
543 .ids = ACPI_SNC_HID,
544 .ops = {
545 .add = sony_acpi_add,
546 .remove = sony_acpi_remove,
547 .resume = sony_acpi_resume,
548 },
549};
550
551static int __init sony_acpi_init(void)
552{
553 return acpi_bus_register_driver(&sony_acpi_driver);
554}
555
556static void __exit sony_acpi_exit(void)
557{
558 acpi_bus_unregister_driver(&sony_acpi_driver);
559}
560
561module_init(sony_acpi_init);
562module_exit(sony_acpi_exit);
diff --git a/drivers/mmc/at91_mci.c b/drivers/mmc/at91_mci.c
index 2ce50f38e3c7..459f4b4feded 100644
--- a/drivers/mmc/at91_mci.c
+++ b/drivers/mmc/at91_mci.c
@@ -64,6 +64,7 @@
64#include <linux/err.h> 64#include <linux/err.h>
65#include <linux/dma-mapping.h> 65#include <linux/dma-mapping.h>
66#include <linux/clk.h> 66#include <linux/clk.h>
67#include <linux/atmel_pdc.h>
67 68
68#include <linux/mmc/host.h> 69#include <linux/mmc/host.h>
69#include <linux/mmc/protocol.h> 70#include <linux/mmc/protocol.h>
@@ -75,7 +76,6 @@
75#include <asm/arch/cpu.h> 76#include <asm/arch/cpu.h>
76#include <asm/arch/gpio.h> 77#include <asm/arch/gpio.h>
77#include <asm/arch/at91_mci.h> 78#include <asm/arch/at91_mci.h>
78#include <asm/arch/at91_pdc.h>
79 79
80#define DRIVER_NAME "at91_mci" 80#define DRIVER_NAME "at91_mci"
81 81
@@ -211,13 +211,13 @@ static void at91mci_pre_dma_read(struct at91mci_host *host)
211 211
212 /* Check to see if this needs filling */ 212 /* Check to see if this needs filling */
213 if (i == 0) { 213 if (i == 0) {
214 if (at91_mci_read(host, AT91_PDC_RCR) != 0) { 214 if (at91_mci_read(host, ATMEL_PDC_RCR) != 0) {
215 pr_debug("Transfer active in current\n"); 215 pr_debug("Transfer active in current\n");
216 continue; 216 continue;
217 } 217 }
218 } 218 }
219 else { 219 else {
220 if (at91_mci_read(host, AT91_PDC_RNCR) != 0) { 220 if (at91_mci_read(host, ATMEL_PDC_RNCR) != 0) {
221 pr_debug("Transfer active in next\n"); 221 pr_debug("Transfer active in next\n");
222 continue; 222 continue;
223 } 223 }
@@ -234,12 +234,12 @@ static void at91mci_pre_dma_read(struct at91mci_host *host)
234 pr_debug("dma address = %08X, length = %d\n", sg->dma_address, sg->length); 234 pr_debug("dma address = %08X, length = %d\n", sg->dma_address, sg->length);
235 235
236 if (i == 0) { 236 if (i == 0) {
237 at91_mci_write(host, AT91_PDC_RPR, sg->dma_address); 237 at91_mci_write(host, ATMEL_PDC_RPR, sg->dma_address);
238 at91_mci_write(host, AT91_PDC_RCR, sg->length / 4); 238 at91_mci_write(host, ATMEL_PDC_RCR, sg->length / 4);
239 } 239 }
240 else { 240 else {
241 at91_mci_write(host, AT91_PDC_RNPR, sg->dma_address); 241 at91_mci_write(host, ATMEL_PDC_RNPR, sg->dma_address);
242 at91_mci_write(host, AT91_PDC_RNCR, sg->length / 4); 242 at91_mci_write(host, ATMEL_PDC_RNCR, sg->length / 4);
243 } 243 }
244 } 244 }
245 245
@@ -303,7 +303,7 @@ static void at91mci_post_dma_read(struct at91mci_host *host)
303 at91mci_pre_dma_read(host); 303 at91mci_pre_dma_read(host);
304 else { 304 else {
305 at91_mci_write(host, AT91_MCI_IER, AT91_MCI_RXBUFF); 305 at91_mci_write(host, AT91_MCI_IER, AT91_MCI_RXBUFF);
306 at91_mci_write(host, AT91_PDC_PTCR, AT91_PDC_RXTDIS | AT91_PDC_TXTDIS); 306 at91_mci_write(host, ATMEL_PDC_PTCR, ATMEL_PDC_RXTDIS | ATMEL_PDC_TXTDIS);
307 } 307 }
308 308
309 pr_debug("post dma read done\n"); 309 pr_debug("post dma read done\n");
@@ -320,7 +320,7 @@ static void at91_mci_handle_transmitted(struct at91mci_host *host)
320 pr_debug("Handling the transmit\n"); 320 pr_debug("Handling the transmit\n");
321 321
322 /* Disable the transfer */ 322 /* Disable the transfer */
323 at91_mci_write(host, AT91_PDC_PTCR, AT91_PDC_RXTDIS | AT91_PDC_TXTDIS); 323 at91_mci_write(host, ATMEL_PDC_PTCR, ATMEL_PDC_RXTDIS | ATMEL_PDC_TXTDIS);
324 324
325 /* Now wait for cmd ready */ 325 /* Now wait for cmd ready */
326 at91_mci_write(host, AT91_MCI_IDR, AT91_MCI_TXBUFE); 326 at91_mci_write(host, AT91_MCI_IDR, AT91_MCI_TXBUFE);
@@ -431,15 +431,15 @@ static unsigned int at91_mci_send_command(struct at91mci_host *host, struct mmc_
431 cmd->opcode, cmdr, cmd->arg, blocks, block_length, at91_mci_read(host, AT91_MCI_MR)); 431 cmd->opcode, cmdr, cmd->arg, blocks, block_length, at91_mci_read(host, AT91_MCI_MR));
432 432
433 if (!data) { 433 if (!data) {
434 at91_mci_write(host, AT91_PDC_PTCR, AT91_PDC_TXTDIS | AT91_PDC_RXTDIS); 434 at91_mci_write(host, ATMEL_PDC_PTCR, ATMEL_PDC_TXTDIS | ATMEL_PDC_RXTDIS);
435 at91_mci_write(host, AT91_PDC_RPR, 0); 435 at91_mci_write(host, ATMEL_PDC_RPR, 0);
436 at91_mci_write(host, AT91_PDC_RCR, 0); 436 at91_mci_write(host, ATMEL_PDC_RCR, 0);
437 at91_mci_write(host, AT91_PDC_RNPR, 0); 437 at91_mci_write(host, ATMEL_PDC_RNPR, 0);
438 at91_mci_write(host, AT91_PDC_RNCR, 0); 438 at91_mci_write(host, ATMEL_PDC_RNCR, 0);
439 at91_mci_write(host, AT91_PDC_TPR, 0); 439 at91_mci_write(host, ATMEL_PDC_TPR, 0);
440 at91_mci_write(host, AT91_PDC_TCR, 0); 440 at91_mci_write(host, ATMEL_PDC_TCR, 0);
441 at91_mci_write(host, AT91_PDC_TNPR, 0); 441 at91_mci_write(host, ATMEL_PDC_TNPR, 0);
442 at91_mci_write(host, AT91_PDC_TNCR, 0); 442 at91_mci_write(host, ATMEL_PDC_TNCR, 0);
443 443
444 at91_mci_write(host, AT91_MCI_ARGR, cmd->arg); 444 at91_mci_write(host, AT91_MCI_ARGR, cmd->arg);
445 at91_mci_write(host, AT91_MCI_CMDR, cmdr); 445 at91_mci_write(host, AT91_MCI_CMDR, cmdr);
@@ -452,7 +452,7 @@ static unsigned int at91_mci_send_command(struct at91mci_host *host, struct mmc_
452 /* 452 /*
453 * Disable the PDC controller 453 * Disable the PDC controller
454 */ 454 */
455 at91_mci_write(host, AT91_PDC_PTCR, AT91_PDC_RXTDIS | AT91_PDC_TXTDIS); 455 at91_mci_write(host, ATMEL_PDC_PTCR, ATMEL_PDC_RXTDIS | ATMEL_PDC_TXTDIS);
456 456
457 if (cmdr & AT91_MCI_TRCMD_START) { 457 if (cmdr & AT91_MCI_TRCMD_START) {
458 data->bytes_xfered = 0; 458 data->bytes_xfered = 0;
@@ -481,8 +481,8 @@ static unsigned int at91_mci_send_command(struct at91mci_host *host, struct mmc_
481 481
482 pr_debug("Transmitting %d bytes\n", host->total_length); 482 pr_debug("Transmitting %d bytes\n", host->total_length);
483 483
484 at91_mci_write(host, AT91_PDC_TPR, host->physical_address); 484 at91_mci_write(host, ATMEL_PDC_TPR, host->physical_address);
485 at91_mci_write(host, AT91_PDC_TCR, host->total_length / 4); 485 at91_mci_write(host, ATMEL_PDC_TCR, host->total_length / 4);
486 ier = AT91_MCI_TXBUFE; 486 ier = AT91_MCI_TXBUFE;
487 } 487 }
488 } 488 }
@@ -497,9 +497,9 @@ static unsigned int at91_mci_send_command(struct at91mci_host *host, struct mmc_
497 497
498 if (cmdr & AT91_MCI_TRCMD_START) { 498 if (cmdr & AT91_MCI_TRCMD_START) {
499 if (cmdr & AT91_MCI_TRDIR) 499 if (cmdr & AT91_MCI_TRDIR)
500 at91_mci_write(host, AT91_PDC_PTCR, AT91_PDC_RXTEN); 500 at91_mci_write(host, ATMEL_PDC_PTCR, ATMEL_PDC_RXTEN);
501 else 501 else
502 at91_mci_write(host, AT91_PDC_PTCR, AT91_PDC_TXTEN); 502 at91_mci_write(host, ATMEL_PDC_PTCR, ATMEL_PDC_TXTEN);
503 } 503 }
504 return ier; 504 return ier;
505} 505}
diff --git a/drivers/mtd/chips/cfi_cmdset_0001.c b/drivers/mtd/chips/cfi_cmdset_0001.c
index f69184a92eb2..f334959a335b 100644
--- a/drivers/mtd/chips/cfi_cmdset_0001.c
+++ b/drivers/mtd/chips/cfi_cmdset_0001.c
@@ -397,9 +397,23 @@ struct mtd_info *cfi_cmdset_0001(struct map_info *map, int primary)
397 cfi_fixup(mtd, fixup_table); 397 cfi_fixup(mtd, fixup_table);
398 398
399 for (i=0; i< cfi->numchips; i++) { 399 for (i=0; i< cfi->numchips; i++) {
400 cfi->chips[i].word_write_time = 1<<cfi->cfiq->WordWriteTimeoutTyp; 400 if (cfi->cfiq->WordWriteTimeoutTyp)
401 cfi->chips[i].buffer_write_time = 1<<cfi->cfiq->BufWriteTimeoutTyp; 401 cfi->chips[i].word_write_time =
402 cfi->chips[i].erase_time = 1000<<cfi->cfiq->BlockEraseTimeoutTyp; 402 1<<cfi->cfiq->WordWriteTimeoutTyp;
403 else
404 cfi->chips[i].word_write_time = 50000;
405
406 if (cfi->cfiq->BufWriteTimeoutTyp)
407 cfi->chips[i].buffer_write_time =
408 1<<cfi->cfiq->BufWriteTimeoutTyp;
409 /* No default; if it isn't specified, we won't use it */
410
411 if (cfi->cfiq->BlockEraseTimeoutTyp)
412 cfi->chips[i].erase_time =
413 1000<<cfi->cfiq->BlockEraseTimeoutTyp;
414 else
415 cfi->chips[i].erase_time = 2000000;
416
403 cfi->chips[i].ref_point_counter = 0; 417 cfi->chips[i].ref_point_counter = 0;
404 init_waitqueue_head(&(cfi->chips[i].wq)); 418 init_waitqueue_head(&(cfi->chips[i].wq));
405 } 419 }
@@ -546,13 +560,11 @@ static int cfi_intelext_partition_fixup(struct mtd_info *mtd,
546 struct cfi_intelext_programming_regioninfo *prinfo; 560 struct cfi_intelext_programming_regioninfo *prinfo;
547 prinfo = (struct cfi_intelext_programming_regioninfo *)&extp->extra[offs]; 561 prinfo = (struct cfi_intelext_programming_regioninfo *)&extp->extra[offs];
548 mtd->writesize = cfi->interleave << prinfo->ProgRegShift; 562 mtd->writesize = cfi->interleave << prinfo->ProgRegShift;
549 MTD_PROGREGION_CTRLMODE_VALID(mtd) = cfi->interleave * prinfo->ControlValid;
550 MTD_PROGREGION_CTRLMODE_INVALID(mtd) = cfi->interleave * prinfo->ControlInvalid;
551 mtd->flags &= ~MTD_BIT_WRITEABLE; 563 mtd->flags &= ~MTD_BIT_WRITEABLE;
552 printk(KERN_DEBUG "%s: program region size/ctrl_valid/ctrl_inval = %d/%d/%d\n", 564 printk(KERN_DEBUG "%s: program region size/ctrl_valid/ctrl_inval = %d/%d/%d\n",
553 map->name, mtd->writesize, 565 map->name, mtd->writesize,
554 MTD_PROGREGION_CTRLMODE_VALID(mtd), 566 cfi->interleave * prinfo->ControlValid,
555 MTD_PROGREGION_CTRLMODE_INVALID(mtd)); 567 cfi->interleave * prinfo->ControlInvalid);
556 } 568 }
557 569
558 /* 570 /*
diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
index d56849f5f107..69d49e0250a9 100644
--- a/drivers/mtd/chips/cfi_cmdset_0020.c
+++ b/drivers/mtd/chips/cfi_cmdset_0020.c
@@ -662,7 +662,7 @@ static int cfi_staa_write_buffers (struct mtd_info *mtd, loff_t to,
662 * a small buffer for this. 662 * a small buffer for this.
663 * XXX: If the buffer size is not a multiple of 2, this will break 663 * XXX: If the buffer size is not a multiple of 2, this will break
664 */ 664 */
665#define ECCBUF_SIZE (mtd->eccsize) 665#define ECCBUF_SIZE (mtd->writesize)
666#define ECCBUF_DIV(x) ((x) & ~(ECCBUF_SIZE - 1)) 666#define ECCBUF_DIV(x) ((x) & ~(ECCBUF_SIZE - 1))
667#define ECCBUF_MOD(x) ((x) & (ECCBUF_SIZE - 1)) 667#define ECCBUF_MOD(x) ((x) & (ECCBUF_SIZE - 1))
668static int 668static int
diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
index 603a7951ac9b..8a0c4dec6351 100644
--- a/drivers/mtd/devices/doc2000.c
+++ b/drivers/mtd/devices/doc2000.c
@@ -569,7 +569,6 @@ void DoC2k_init(struct mtd_info *mtd)
569 569
570 mtd->type = MTD_NANDFLASH; 570 mtd->type = MTD_NANDFLASH;
571 mtd->flags = MTD_CAP_NANDFLASH; 571 mtd->flags = MTD_CAP_NANDFLASH;
572 mtd->ecctype = MTD_ECC_RS_DiskOnChip;
573 mtd->size = 0; 572 mtd->size = 0;
574 mtd->erasesize = 0; 573 mtd->erasesize = 0;
575 mtd->writesize = 512; 574 mtd->writesize = 512;
diff --git a/drivers/mtd/devices/doc2001.c b/drivers/mtd/devices/doc2001.c
index fe71a12c2627..6f368aec5d5d 100644
--- a/drivers/mtd/devices/doc2001.c
+++ b/drivers/mtd/devices/doc2001.c
@@ -348,7 +348,6 @@ void DoCMil_init(struct mtd_info *mtd)
348 348
349 mtd->type = MTD_NANDFLASH; 349 mtd->type = MTD_NANDFLASH;
350 mtd->flags = MTD_CAP_NANDFLASH; 350 mtd->flags = MTD_CAP_NANDFLASH;
351 mtd->ecctype = MTD_ECC_RS_DiskOnChip;
352 mtd->size = 0; 351 mtd->size = 0;
353 352
354 /* FIXME: erase size is not always 8KiB */ 353 /* FIXME: erase size is not always 8KiB */
diff --git a/drivers/mtd/devices/doc2001plus.c b/drivers/mtd/devices/doc2001plus.c
index ba4db686285a..88ba82df0fbb 100644
--- a/drivers/mtd/devices/doc2001plus.c
+++ b/drivers/mtd/devices/doc2001plus.c
@@ -472,7 +472,6 @@ void DoCMilPlus_init(struct mtd_info *mtd)
472 472
473 mtd->type = MTD_NANDFLASH; 473 mtd->type = MTD_NANDFLASH;
474 mtd->flags = MTD_CAP_NANDFLASH; 474 mtd->flags = MTD_CAP_NANDFLASH;
475 mtd->ecctype = MTD_ECC_RS_DiskOnChip;
476 mtd->size = 0; 475 mtd->size = 0;
477 476
478 mtd->erasesize = 0; 477 mtd->erasesize = 0;
diff --git a/drivers/mtd/maps/Kconfig b/drivers/mtd/maps/Kconfig
index f457315579db..bbf0553bdb2e 100644
--- a/drivers/mtd/maps/Kconfig
+++ b/drivers/mtd/maps/Kconfig
@@ -204,7 +204,7 @@ config MTD_ESB2ROM
204 204
205config MTD_CK804XROM 205config MTD_CK804XROM
206 tristate "BIOS flash chip on Nvidia CK804" 206 tristate "BIOS flash chip on Nvidia CK804"
207 depends on X86 && MTD_JEDECPROBE 207 depends on X86 && MTD_JEDECPROBE && PCI
208 help 208 help
209 Support for treating the BIOS flash chip on nvidia motherboards 209 Support for treating the BIOS flash chip on nvidia motherboards
210 as an MTD device - with this you can reprogram your BIOS. 210 as an MTD device - with this you can reprogram your BIOS.
diff --git a/drivers/mtd/maps/amd76xrom.c b/drivers/mtd/maps/amd76xrom.c
index 78b671172bb2..728aed6ad722 100644
--- a/drivers/mtd/maps/amd76xrom.c
+++ b/drivers/mtd/maps/amd76xrom.c
@@ -205,8 +205,8 @@ static int __devinit amd76xrom_init_one (struct pci_dev *pdev,
205 (((unsigned long)(window->virt)) + offset); 205 (((unsigned long)(window->virt)) + offset);
206 map->map.size = 0xffffffffUL - map_top + 1UL; 206 map->map.size = 0xffffffffUL - map_top + 1UL;
207 /* Set the name of the map to the address I am trying */ 207 /* Set the name of the map to the address I am trying */
208 sprintf(map->map_name, "%s @%08lx", 208 sprintf(map->map_name, "%s @%08Lx",
209 MOD_NAME, map->map.phys); 209 MOD_NAME, (unsigned long long)map->map.phys);
210 210
211 /* There is no generic VPP support */ 211 /* There is no generic VPP support */
212 for(map->map.bankwidth = 32; map->map.bankwidth; 212 for(map->map.bankwidth = 32; map->map.bankwidth;
diff --git a/drivers/mtd/maps/ck804xrom.c b/drivers/mtd/maps/ck804xrom.c
index 238d42e88ec5..3d4a4d8ac789 100644
--- a/drivers/mtd/maps/ck804xrom.c
+++ b/drivers/mtd/maps/ck804xrom.c
@@ -207,8 +207,8 @@ static int __devinit ck804xrom_init_one (struct pci_dev *pdev,
207 (((unsigned long)(window->virt)) + offset); 207 (((unsigned long)(window->virt)) + offset);
208 map->map.size = 0xffffffffUL - map_top + 1UL; 208 map->map.size = 0xffffffffUL - map_top + 1UL;
209 /* Set the name of the map to the address I am trying */ 209 /* Set the name of the map to the address I am trying */
210 sprintf(map->map_name, "%s @%08lx", 210 sprintf(map->map_name, "%s @%08Lx",
211 MOD_NAME, map->map.phys); 211 MOD_NAME, (unsigned long long)map->map.phys);
212 212
213 /* There is no generic VPP support */ 213 /* There is no generic VPP support */
214 for(map->map.bankwidth = 32; map->map.bankwidth; 214 for(map->map.bankwidth = 32; map->map.bankwidth;
@@ -327,7 +327,7 @@ static int __init init_ck804xrom(void)
327 pdev = NULL; 327 pdev = NULL;
328 328
329 for(id = ck804xrom_pci_tbl; id->vendor; id++) { 329 for(id = ck804xrom_pci_tbl; id->vendor; id++) {
330 pdev = pci_find_device(id->vendor, id->device, NULL); 330 pdev = pci_get_device(id->vendor, id->device, NULL);
331 if (pdev) 331 if (pdev)
332 break; 332 break;
333 } 333 }
diff --git a/drivers/mtd/maps/esb2rom.c b/drivers/mtd/maps/esb2rom.c
index a9d808a617c9..0bc013fd66a3 100644
--- a/drivers/mtd/maps/esb2rom.c
+++ b/drivers/mtd/maps/esb2rom.c
@@ -289,8 +289,8 @@ static int __devinit esb2rom_init_one(struct pci_dev *pdev,
289 (((unsigned long)(window->virt)) + offset); 289 (((unsigned long)(window->virt)) + offset);
290 map->map.size = 0xffffffffUL - map_top + 1UL; 290 map->map.size = 0xffffffffUL - map_top + 1UL;
291 /* Set the name of the map to the address I am trying */ 291 /* Set the name of the map to the address I am trying */
292 sprintf(map->map_name, "%s @%08lx", 292 sprintf(map->map_name, "%s @%08Lx",
293 MOD_NAME, map->map.phys); 293 MOD_NAME, (unsigned long long)map->map.phys);
294 294
295 /* Firmware hubs only use vpp when being programmed 295 /* Firmware hubs only use vpp when being programmed
296 * in a factory setting. So in-place programming 296 * in a factory setting. So in-place programming
diff --git a/drivers/mtd/maps/ichxrom.c b/drivers/mtd/maps/ichxrom.c
index 2bb3e63606e5..2c884c49e84a 100644
--- a/drivers/mtd/maps/ichxrom.c
+++ b/drivers/mtd/maps/ichxrom.c
@@ -227,8 +227,8 @@ static int __devinit ichxrom_init_one (struct pci_dev *pdev,
227 (((unsigned long)(window->virt)) + offset); 227 (((unsigned long)(window->virt)) + offset);
228 map->map.size = 0xffffffffUL - map_top + 1UL; 228 map->map.size = 0xffffffffUL - map_top + 1UL;
229 /* Set the name of the map to the address I am trying */ 229 /* Set the name of the map to the address I am trying */
230 sprintf(map->map_name, "%s @%08lx", 230 sprintf(map->map_name, "%s @%08Lx",
231 MOD_NAME, map->map.phys); 231 MOD_NAME, (unsigned long long)map->map.phys);
232 232
233 /* Firmware hubs only use vpp when being programmed 233 /* Firmware hubs only use vpp when being programmed
234 * in a factory setting. So in-place programming 234 * in a factory setting. So in-place programming
diff --git a/drivers/mtd/maps/netsc520.c b/drivers/mtd/maps/netsc520.c
index ed215470158b..95dcab2146ad 100644
--- a/drivers/mtd/maps/netsc520.c
+++ b/drivers/mtd/maps/netsc520.c
@@ -94,7 +94,9 @@ static struct mtd_info *mymtd;
94 94
95static int __init init_netsc520(void) 95static int __init init_netsc520(void)
96{ 96{
97 printk(KERN_NOTICE "NetSc520 flash device: 0x%lx at 0x%lx\n", netsc520_map.size, netsc520_map.phys); 97 printk(KERN_NOTICE "NetSc520 flash device: 0x%Lx at 0x%Lx\n",
98 (unsigned long long)netsc520_map.size,
99 (unsigned long long)netsc520_map.phys);
98 netsc520_map.virt = ioremap_nocache(netsc520_map.phys, netsc520_map.size); 100 netsc520_map.virt = ioremap_nocache(netsc520_map.phys, netsc520_map.size);
99 101
100 if (!netsc520_map.virt) { 102 if (!netsc520_map.virt) {
diff --git a/drivers/mtd/maps/sc520cdp.c b/drivers/mtd/maps/sc520cdp.c
index 9b50cfc355b1..4045e372b90d 100644
--- a/drivers/mtd/maps/sc520cdp.c
+++ b/drivers/mtd/maps/sc520cdp.c
@@ -237,8 +237,9 @@ static int __init init_sc520cdp(void)
237#endif 237#endif
238 238
239 for (i = 0; i < NUM_FLASH_BANKS; i++) { 239 for (i = 0; i < NUM_FLASH_BANKS; i++) {
240 printk(KERN_NOTICE "SC520 CDP flash device: 0x%lx at 0x%lx\n", 240 printk(KERN_NOTICE "SC520 CDP flash device: 0x%Lx at 0x%Lx\n",
241 sc520cdp_map[i].size, sc520cdp_map[i].phys); 241 (unsigned long long)sc520cdp_map[i].size,
242 (unsigned long long)sc520cdp_map[i].phys);
242 243
243 sc520cdp_map[i].virt = ioremap_nocache(sc520cdp_map[i].phys, sc520cdp_map[i].size); 244 sc520cdp_map[i].virt = ioremap_nocache(sc520cdp_map[i].phys, sc520cdp_map[i].size);
244 245
diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
index 61a994ea8af1..1592eac64e57 100644
--- a/drivers/mtd/mtdchar.c
+++ b/drivers/mtd/mtdchar.c
@@ -419,8 +419,9 @@ static int mtd_ioctl(struct inode *inode, struct file *file,
419 info.erasesize = mtd->erasesize; 419 info.erasesize = mtd->erasesize;
420 info.writesize = mtd->writesize; 420 info.writesize = mtd->writesize;
421 info.oobsize = mtd->oobsize; 421 info.oobsize = mtd->oobsize;
422 info.ecctype = mtd->ecctype; 422 /* The below fields are obsolete */
423 info.eccsize = mtd->eccsize; 423 info.ecctype = -1;
424 info.eccsize = 0;
424 if (copy_to_user(argp, &info, sizeof(struct mtd_info_user))) 425 if (copy_to_user(argp, &info, sizeof(struct mtd_info_user)))
425 return -EFAULT; 426 return -EFAULT;
426 break; 427 break;
diff --git a/drivers/mtd/mtdconcat.c b/drivers/mtd/mtdconcat.c
index 06902683bc2a..880580c44e01 100644
--- a/drivers/mtd/mtdconcat.c
+++ b/drivers/mtd/mtdconcat.c
@@ -727,8 +727,6 @@ struct mtd_info *mtd_concat_create(struct mtd_info *subdev[], /* subdevices to c
727 concat->mtd.erasesize = subdev[0]->erasesize; 727 concat->mtd.erasesize = subdev[0]->erasesize;
728 concat->mtd.writesize = subdev[0]->writesize; 728 concat->mtd.writesize = subdev[0]->writesize;
729 concat->mtd.oobsize = subdev[0]->oobsize; 729 concat->mtd.oobsize = subdev[0]->oobsize;
730 concat->mtd.ecctype = subdev[0]->ecctype;
731 concat->mtd.eccsize = subdev[0]->eccsize;
732 if (subdev[0]->writev) 730 if (subdev[0]->writev)
733 concat->mtd.writev = concat_writev; 731 concat->mtd.writev = concat_writev;
734 if (subdev[0]->read_oob) 732 if (subdev[0]->read_oob)
@@ -774,8 +772,6 @@ struct mtd_info *mtd_concat_create(struct mtd_info *subdev[], /* subdevices to c
774 if (concat->mtd.writesize != subdev[i]->writesize || 772 if (concat->mtd.writesize != subdev[i]->writesize ||
775 concat->mtd.subpage_sft != subdev[i]->subpage_sft || 773 concat->mtd.subpage_sft != subdev[i]->subpage_sft ||
776 concat->mtd.oobsize != subdev[i]->oobsize || 774 concat->mtd.oobsize != subdev[i]->oobsize ||
777 concat->mtd.ecctype != subdev[i]->ecctype ||
778 concat->mtd.eccsize != subdev[i]->eccsize ||
779 !concat->mtd.read_oob != !subdev[i]->read_oob || 775 !concat->mtd.read_oob != !subdev[i]->read_oob ||
780 !concat->mtd.write_oob != !subdev[i]->write_oob) { 776 !concat->mtd.write_oob != !subdev[i]->write_oob) {
781 kfree(concat); 777 kfree(concat);
diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c
index bafd2fba87bd..633def3fb087 100644
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
@@ -338,8 +338,6 @@ int add_mtd_partitions(struct mtd_info *master,
338 slave->mtd.size = parts[i].size; 338 slave->mtd.size = parts[i].size;
339 slave->mtd.writesize = master->writesize; 339 slave->mtd.writesize = master->writesize;
340 slave->mtd.oobsize = master->oobsize; 340 slave->mtd.oobsize = master->oobsize;
341 slave->mtd.ecctype = master->ecctype;
342 slave->mtd.eccsize = master->eccsize;
343 slave->mtd.subpage_sft = master->subpage_sft; 341 slave->mtd.subpage_sft = master->subpage_sft;
344 342
345 slave->mtd.name = parts[i].name; 343 slave->mtd.name = parts[i].name;
diff --git a/drivers/mtd/nand/Kconfig b/drivers/mtd/nand/Kconfig
index 358f55a82dbe..2d12dcdd740c 100644
--- a/drivers/mtd/nand/Kconfig
+++ b/drivers/mtd/nand/Kconfig
@@ -126,10 +126,6 @@ config MTD_NAND_S3C2410_HWECC
126 incorrect ECC generation, and if using these, the default of 126 incorrect ECC generation, and if using these, the default of
127 software ECC is preferable. 127 software ECC is preferable.
128 128
129 If you lay down a device with the hardware ECC, then you will
130 currently not be able to switch to software, as there is no
131 implementation for ECC method used by the S3C2410
132
133config MTD_NAND_NDFC 129config MTD_NAND_NDFC
134 tristate "NDFC NanD Flash Controller" 130 tristate "NDFC NanD Flash Controller"
135 depends on MTD_NAND && 44x 131 depends on MTD_NAND && 44x
@@ -221,9 +217,17 @@ config MTD_NAND_SHARPSL
221 tristate "Support for NAND Flash on Sharp SL Series (C7xx + others)" 217 tristate "Support for NAND Flash on Sharp SL Series (C7xx + others)"
222 depends on MTD_NAND && ARCH_PXA 218 depends on MTD_NAND && ARCH_PXA
223 219
220config MTD_NAND_BASLER_EXCITE
221 tristate "Support for NAND Flash on Basler eXcite"
222 depends on MTD_NAND && BASLER_EXCITE
223 help
224 This enables the driver for the NAND flash device found on the
225 Basler eXcite Smart Camera. If built as a module, the driver
226 will be named "excite_nandflash.ko".
227
224config MTD_NAND_CAFE 228config MTD_NAND_CAFE
225 tristate "NAND support for OLPC CAFÉ chip" 229 tristate "NAND support for OLPC CAFÉ chip"
226 depends on PCI 230 depends on MTD_NAND && PCI
227 help 231 help
228 Use NAND flash attached to the CAFÉ chip designed for the $100 232 Use NAND flash attached to the CAFÉ chip designed for the $100
229 laptop. 233 laptop.
diff --git a/drivers/mtd/nand/Makefile b/drivers/mtd/nand/Makefile
index f7a53f0b7017..80f1dfc77949 100644
--- a/drivers/mtd/nand/Makefile
+++ b/drivers/mtd/nand/Makefile
@@ -24,6 +24,7 @@ obj-$(CONFIG_MTD_NAND_NANDSIM) += nandsim.o
24obj-$(CONFIG_MTD_NAND_CS553X) += cs553x_nand.o 24obj-$(CONFIG_MTD_NAND_CS553X) += cs553x_nand.o
25obj-$(CONFIG_MTD_NAND_NDFC) += ndfc.o 25obj-$(CONFIG_MTD_NAND_NDFC) += ndfc.o
26obj-$(CONFIG_MTD_NAND_AT91) += at91_nand.o 26obj-$(CONFIG_MTD_NAND_AT91) += at91_nand.o
27obj-$(CONFIG_MTD_NAND_BASLER_EXCITE) += excite_nandflash.o
27 28
28nand-objs := nand_base.o nand_bbt.o 29nand-objs := nand_base.o nand_bbt.o
29cafe_nand-objs := cafe.o cafe_ecc.o 30cafe_nand-objs := cafe.o cafe_ecc.o
diff --git a/drivers/mtd/nand/cafe.c b/drivers/mtd/nand/cafe.c
index 08cb060dfa3d..fd6bb3ed40df 100644
--- a/drivers/mtd/nand/cafe.c
+++ b/drivers/mtd/nand/cafe.c
@@ -78,8 +78,9 @@ module_param(regdebug, int, 0644);
78static int checkecc = 1; 78static int checkecc = 1;
79module_param(checkecc, int, 0644); 79module_param(checkecc, int, 0644);
80 80
81static int slowtiming = 0; 81static int numtimings;
82module_param(slowtiming, int, 0644); 82static int timing[3];
83module_param_array(timing, int, &numtimings, 0644);
83 84
84/* Hrm. Why isn't this already conditional on something in the struct device? */ 85/* Hrm. Why isn't this already conditional on something in the struct device? */
85#define cafe_dev_dbg(dev, args...) do { if (debug) dev_dbg(dev, ##args); } while(0) 86#define cafe_dev_dbg(dev, args...) do { if (debug) dev_dbg(dev, ##args); } while(0)
@@ -264,10 +265,10 @@ static void cafe_nand_cmdfunc(struct mtd_info *mtd, unsigned command,
264 ndelay(100); 265 ndelay(100);
265 266
266 if (1) { 267 if (1) {
267 int c = 500000; 268 int c;
268 uint32_t irqs; 269 uint32_t irqs;
269 270
270 while (c--) { 271 for (c = 500000; c != 0; c--) {
271 irqs = cafe_readl(cafe, NAND_IRQ); 272 irqs = cafe_readl(cafe, NAND_IRQ);
272 if (irqs & doneint) 273 if (irqs & doneint)
273 break; 274 break;
@@ -529,6 +530,7 @@ static int __devinit cafe_nand_probe(struct pci_dev *pdev,
529{ 530{
530 struct mtd_info *mtd; 531 struct mtd_info *mtd;
531 struct cafe_priv *cafe; 532 struct cafe_priv *cafe;
533 uint32_t timing1, timing2, timing3;
532 uint32_t ctrl; 534 uint32_t ctrl;
533 int err = 0; 535 int err = 0;
534 536
@@ -580,31 +582,45 @@ static int __devinit cafe_nand_probe(struct pci_dev *pdev,
580 cafe->nand.block_bad = cafe_nand_block_bad; 582 cafe->nand.block_bad = cafe_nand_block_bad;
581 } 583 }
582 584
585 if (numtimings && numtimings != 3) {
586 dev_warn(&cafe->pdev->dev, "%d timing register values ignored; precisely three are required\n", numtimings);
587 }
588
589 if (numtimings == 3) {
590 timing1 = timing[0];
591 timing2 = timing[1];
592 timing3 = timing[2];
593 cafe_dev_dbg(&cafe->pdev->dev, "Using provided timings (%08x %08x %08x)\n",
594 timing1, timing2, timing3);
595 } else {
596 timing1 = cafe_readl(cafe, NAND_TIMING1);
597 timing2 = cafe_readl(cafe, NAND_TIMING2);
598 timing3 = cafe_readl(cafe, NAND_TIMING3);
599
600 if (timing1 | timing2 | timing3) {
601 cafe_dev_dbg(&cafe->pdev->dev, "Timing registers already set (%08x %08x %08x)\n", timing1, timing2, timing3);
602 } else {
603 dev_warn(&cafe->pdev->dev, "Timing registers unset; using most conservative defaults\n");
604 timing1 = timing2 = timing3 = 0xffffffff;
605 }
606 }
607
583 /* Start off by resetting the NAND controller completely */ 608 /* Start off by resetting the NAND controller completely */
584 cafe_writel(cafe, 1, NAND_RESET); 609 cafe_writel(cafe, 1, NAND_RESET);
585 cafe_writel(cafe, 0, NAND_RESET); 610 cafe_writel(cafe, 0, NAND_RESET);
586 611
587 cafe_writel(cafe, 0xffffffff, NAND_IRQ_MASK); 612 cafe_writel(cafe, timing1, NAND_TIMING1);
613 cafe_writel(cafe, timing2, NAND_TIMING2);
614 cafe_writel(cafe, timing3, NAND_TIMING3);
588 615
589 /* Timings from Marvell's test code (not verified or calculated by us) */
590 if (!slowtiming) {
591 cafe_writel(cafe, 0x01010a0a, NAND_TIMING1);
592 cafe_writel(cafe, 0x24121212, NAND_TIMING2);
593 cafe_writel(cafe, 0x11000000, NAND_TIMING3);
594 } else {
595 cafe_writel(cafe, 0xffffffff, NAND_TIMING1);
596 cafe_writel(cafe, 0xffffffff, NAND_TIMING2);
597 cafe_writel(cafe, 0xffffffff, NAND_TIMING3);
598 }
599 cafe_writel(cafe, 0xffffffff, NAND_IRQ_MASK); 616 cafe_writel(cafe, 0xffffffff, NAND_IRQ_MASK);
600 err = request_irq(pdev->irq, &cafe_nand_interrupt, IRQF_SHARED, 617 err = request_irq(pdev->irq, &cafe_nand_interrupt, IRQF_SHARED,
601 "CAFE NAND", mtd); 618 "CAFE NAND", mtd);
602 if (err) { 619 if (err) {
603 dev_warn(&pdev->dev, "Could not register IRQ %d\n", pdev->irq); 620 dev_warn(&pdev->dev, "Could not register IRQ %d\n", pdev->irq);
604
605 goto out_free_dma; 621 goto out_free_dma;
606 } 622 }
607#if 1 623
608 /* Disable master reset, enable NAND clock */ 624 /* Disable master reset, enable NAND clock */
609 ctrl = cafe_readl(cafe, GLOBAL_CTRL); 625 ctrl = cafe_readl(cafe, GLOBAL_CTRL);
610 ctrl &= 0xffffeff0; 626 ctrl &= 0xffffeff0;
@@ -631,32 +647,8 @@ static int __devinit cafe_nand_probe(struct pci_dev *pdev,
631 cafe_writel(cafe, 0x80000007, GLOBAL_IRQ_MASK); 647 cafe_writel(cafe, 0x80000007, GLOBAL_IRQ_MASK);
632 cafe_dev_dbg(&cafe->pdev->dev, "Control %x, IRQ mask %x\n", 648 cafe_dev_dbg(&cafe->pdev->dev, "Control %x, IRQ mask %x\n",
633 cafe_readl(cafe, GLOBAL_CTRL), cafe_readl(cafe, GLOBAL_IRQ_MASK)); 649 cafe_readl(cafe, GLOBAL_CTRL), cafe_readl(cafe, GLOBAL_IRQ_MASK));
634#endif 650
635#if 1 651 /* Scan to find existence of the device */
636 mtd->writesize=2048;
637 mtd->oobsize = 0x40;
638 memset(cafe->dmabuf, 0x5a, 2112);
639 cafe->nand.cmdfunc(mtd, NAND_CMD_READID, 0, -1);
640 cafe->nand.read_byte(mtd);
641 cafe->nand.read_byte(mtd);
642 cafe->nand.read_byte(mtd);
643 cafe->nand.read_byte(mtd);
644 cafe->nand.read_byte(mtd);
645#endif
646#if 0
647 cafe->nand.cmdfunc(mtd, NAND_CMD_READ0, 0, 0);
648 // nand_wait_ready(mtd);
649 cafe->nand.read_byte(mtd);
650 cafe->nand.read_byte(mtd);
651 cafe->nand.read_byte(mtd);
652 cafe->nand.read_byte(mtd);
653#endif
654#if 0
655 writel(0x84600070, cafe->mmio);
656 udelay(10);
657 cafe_dev_dbg(&cafe->pdev->dev, "Status %x\n", cafe_readl(cafe, NAND_NONMEM));
658#endif
659 /* Scan to find existance of the device */
660 if (nand_scan_ident(mtd, 1)) { 652 if (nand_scan_ident(mtd, 1)) {
661 err = -ENXIO; 653 err = -ENXIO;
662 goto out_irq; 654 goto out_irq;
@@ -760,13 +752,4 @@ module_exit(cafe_nand_exit);
760 752
761MODULE_LICENSE("GPL"); 753MODULE_LICENSE("GPL");
762MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>"); 754MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
763MODULE_DESCRIPTION("NAND flash driver for OLPC CAFE chip"); 755MODULE_DESCRIPTION("NAND flash driver for OLPC CAFÉ chip");
764
765/* Correct ECC for 2048 bytes of 0xff:
766 41 a0 71 65 54 27 f3 93 ec a9 be ed 0b a1 */
767
768/* dwmw2's B-test board, in case of completely screwing it:
769Bad eraseblock 2394 at 0x12b40000
770Bad eraseblock 2627 at 0x14860000
771Bad eraseblock 3349 at 0x1a2a0000
772*/
diff --git a/drivers/mtd/nand/cafe_ecc.c b/drivers/mtd/nand/cafe_ecc.c
index 1b9fa05a4474..ea5c8491d2c5 100644
--- a/drivers/mtd/nand/cafe_ecc.c
+++ b/drivers/mtd/nand/cafe_ecc.c
@@ -1045,7 +1045,7 @@ static unsigned short err_pos_lut[4096] = {
1045 1045
1046static unsigned short err_pos(unsigned short din) 1046static unsigned short err_pos(unsigned short din)
1047{ 1047{
1048 BUG_ON(din > 4096); 1048 BUG_ON(din >= ARRAY_SIZE(err_pos_lut));
1049 return err_pos_lut[din]; 1049 return err_pos_lut[din];
1050} 1050}
1051static int chk_no_err_only(unsigned short *chk_syndrome_list, unsigned short *err_info) 1051static int chk_no_err_only(unsigned short *chk_syndrome_list, unsigned short *err_info)
diff --git a/drivers/mtd/nand/excite_nandflash.c b/drivers/mtd/nand/excite_nandflash.c
new file mode 100644
index 000000000000..7e9afc4c7757
--- /dev/null
+++ b/drivers/mtd/nand/excite_nandflash.c
@@ -0,0 +1,248 @@
1/*
2* Copyright (C) 2005 - 2007 by Basler Vision Technologies AG
3* Author: Thomas Koeller <thomas.koeller.qbaslerweb.com>
4* Original code by Thies Moeller <thies.moeller@baslerweb.com>
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 as published by
8* the Free Software Foundation; either version 2 of the License, or
9* (at your option) any later version.
10*
11* This program is distributed in the hope that it will be useful,
12* but WITHOUT ANY WARRANTY; without even the implied warranty of
13* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14* GNU General Public License for more details.
15*
16* You should have received a copy of the GNU General Public License
17* along with this program; if not, write to the Free Software
18* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19*/
20
21#include <linux/module.h>
22#include <linux/types.h>
23#include <linux/init.h>
24#include <linux/kernel.h>
25#include <linux/string.h>
26#include <linux/ioport.h>
27#include <linux/platform_device.h>
28#include <linux/delay.h>
29#include <linux/err.h>
30#include <linux/kernel.h>
31
32#include <linux/mtd/mtd.h>
33#include <linux/mtd/nand.h>
34#include <linux/mtd/nand_ecc.h>
35#include <linux/mtd/partitions.h>
36
37#include <asm/io.h>
38#include <asm/rm9k-ocd.h>
39
40#include <excite_nandflash.h>
41
42#define EXCITE_NANDFLASH_VERSION "0.1"
43
44/* I/O register offsets */
45#define EXCITE_NANDFLASH_DATA_BYTE 0x00
46#define EXCITE_NANDFLASH_STATUS_BYTE 0x0c
47#define EXCITE_NANDFLASH_ADDR_BYTE 0x10
48#define EXCITE_NANDFLASH_CMD_BYTE 0x14
49
50/* prefix for debug output */
51static const char module_id[] = "excite_nandflash";
52
53/*
54 * partition definition
55 */
56static const struct mtd_partition partition_info[] = {
57 {
58 .name = "eXcite RootFS",
59 .offset = 0,
60 .size = MTDPART_SIZ_FULL
61 }
62};
63
64static inline const struct resource *
65excite_nand_get_resource(struct platform_device *d, unsigned long flags,
66 const char *basename)
67{
68 char buf[80];
69
70 if (snprintf(buf, sizeof buf, "%s_%u", basename, d->id) >= sizeof buf)
71 return NULL;
72 return platform_get_resource_byname(d, flags, buf);
73}
74
75static inline void __iomem *
76excite_nand_map_regs(struct platform_device *d, const char *basename)
77{
78 void *result = NULL;
79 const struct resource *const r =
80 excite_nand_get_resource(d, IORESOURCE_MEM, basename);
81
82 if (r)
83 result = ioremap_nocache(r->start, r->end + 1 - r->start);
84 return result;
85}
86
87/* controller and mtd information */
88struct excite_nand_drvdata {
89 struct mtd_info board_mtd;
90 struct nand_chip board_chip;
91 void __iomem *regs;
92 void __iomem *tgt;
93};
94
95/* Control function */
96static void excite_nand_control(struct mtd_info *mtd, int cmd,
97 unsigned int ctrl)
98{
99 struct excite_nand_drvdata * const d =
100 container_of(mtd, struct excite_nand_drvdata, board_mtd);
101
102 switch (ctrl) {
103 case NAND_CTRL_CHANGE | NAND_CTRL_CLE:
104 d->tgt = d->regs + EXCITE_NANDFLASH_CMD_BYTE;
105 break;
106 case NAND_CTRL_CHANGE | NAND_CTRL_ALE:
107 d->tgt = d->regs + EXCITE_NANDFLASH_ADDR_BYTE;
108 break;
109 case NAND_CTRL_CHANGE | NAND_NCE:
110 d->tgt = d->regs + EXCITE_NANDFLASH_DATA_BYTE;
111 break;
112 }
113
114 if (cmd != NAND_CMD_NONE)
115 __raw_writeb(cmd, d->tgt);
116}
117
118/* Return 0 if flash is busy, 1 if ready */
119static int excite_nand_devready(struct mtd_info *mtd)
120{
121 struct excite_nand_drvdata * const drvdata =
122 container_of(mtd, struct excite_nand_drvdata, board_mtd);
123
124 return __raw_readb(drvdata->regs + EXCITE_NANDFLASH_STATUS_BYTE);
125}
126
127/*
128 * Called by device layer to remove the driver.
129 * The binding to the mtd and all allocated
130 * resources are released.
131 */
132static int __exit excite_nand_remove(struct device *dev)
133{
134 struct excite_nand_drvdata * const this = dev_get_drvdata(dev);
135
136 dev_set_drvdata(dev, NULL);
137
138 if (unlikely(!this)) {
139 printk(KERN_ERR "%s: called %s without private data!!",
140 module_id, __func__);
141 return -EINVAL;
142 }
143
144 /* first thing we need to do is release our mtd
145 * then go through freeing the resource used
146 */
147 nand_release(&this->board_mtd);
148
149 /* free the common resources */
150 iounmap(this->regs);
151 kfree(this);
152
153 DEBUG(MTD_DEBUG_LEVEL1, "%s: removed\n", module_id);
154 return 0;
155}
156
157/*
158 * Called by device layer when it finds a device matching
159 * one our driver can handle. This code checks to see if
160 * it can allocate all necessary resources then calls the
161 * nand layer to look for devices.
162*/
163static int __init excite_nand_probe(struct device *dev)
164{
165 struct platform_device * const pdev = to_platform_device(dev);
166 struct excite_nand_drvdata *drvdata; /* private driver data */
167 struct nand_chip *board_chip; /* private flash chip data */
168 struct mtd_info *board_mtd; /* mtd info for this board */
169 int scan_res;
170
171 drvdata = kzalloc(sizeof(*drvdata), GFP_KERNEL);
172 if (unlikely(!drvdata)) {
173 printk(KERN_ERR "%s: no memory for drvdata\n",
174 module_id);
175 return -ENOMEM;
176 }
177
178 /* bind private data into driver */
179 dev_set_drvdata(dev, drvdata);
180
181 /* allocate and map the resource */
182 drvdata->regs =
183 excite_nand_map_regs(pdev, EXCITE_NANDFLASH_RESOURCE_REGS);
184
185 if (unlikely(!drvdata->regs)) {
186 printk(KERN_ERR "%s: cannot reserve register region\n",
187 module_id);
188 kfree(drvdata);
189 return -ENXIO;
190 }
191
192 drvdata->tgt = drvdata->regs + EXCITE_NANDFLASH_DATA_BYTE;
193
194 /* initialise our chip */
195 board_chip = &drvdata->board_chip;
196 board_chip->IO_ADDR_R = board_chip->IO_ADDR_W =
197 drvdata->regs + EXCITE_NANDFLASH_DATA_BYTE;
198 board_chip->cmd_ctrl = excite_nand_control;
199 board_chip->dev_ready = excite_nand_devready;
200 board_chip->chip_delay = 25;
201 board_chip->ecc.mode = NAND_ECC_SOFT;
202
203 /* link chip to mtd */
204 board_mtd = &drvdata->board_mtd;
205 board_mtd->priv = board_chip;
206
207 DEBUG(MTD_DEBUG_LEVEL2, "%s: device scan\n", module_id);
208 scan_res = nand_scan(&drvdata->board_mtd, 1);
209
210 if (likely(!scan_res)) {
211 DEBUG(MTD_DEBUG_LEVEL2, "%s: register partitions\n", module_id);
212 add_mtd_partitions(&drvdata->board_mtd, partition_info,
213 sizeof partition_info / sizeof partition_info[0]);
214 } else {
215 iounmap(drvdata->regs);
216 kfree(drvdata);
217 printk(KERN_ERR "%s: device scan failed\n", module_id);
218 return -EIO;
219 }
220 return 0;
221}
222
223static struct device_driver excite_nand_driver = {
224 .name = "excite_nand",
225 .bus = &platform_bus_type,
226 .probe = excite_nand_probe,
227 .remove = __exit_p(excite_nand_remove)
228};
229
230static int __init excite_nand_init(void)
231{
232 pr_info("Basler eXcite nand flash driver Version "
233 EXCITE_NANDFLASH_VERSION "\n");
234 return driver_register(&excite_nand_driver);
235}
236
237static void __exit excite_nand_exit(void)
238{
239 driver_unregister(&excite_nand_driver);
240}
241
242module_init(excite_nand_init);
243module_exit(excite_nand_exit);
244
245MODULE_AUTHOR("Thomas Koeller <thomas.koeller@baslerweb.com>");
246MODULE_DESCRIPTION("Basler eXcite NAND-Flash driver");
247MODULE_LICENSE("GPL");
248MODULE_VERSION(EXCITE_NANDFLASH_VERSION)
diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index dfe56e03e48b..acaf97bc80d1 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -1272,10 +1272,25 @@ static int nand_do_read_oob(struct mtd_info *mtd, loff_t from,
1272 DEBUG(MTD_DEBUG_LEVEL3, "nand_read_oob: from = 0x%08Lx, len = %i\n", 1272 DEBUG(MTD_DEBUG_LEVEL3, "nand_read_oob: from = 0x%08Lx, len = %i\n",
1273 (unsigned long long)from, readlen); 1273 (unsigned long long)from, readlen);
1274 1274
1275 if (ops->mode == MTD_OOB_RAW) 1275 if (ops->mode == MTD_OOB_AUTO)
1276 len = mtd->oobsize;
1277 else
1278 len = chip->ecc.layout->oobavail; 1276 len = chip->ecc.layout->oobavail;
1277 else
1278 len = mtd->oobsize;
1279
1280 if (unlikely(ops->ooboffs >= len)) {
1281 DEBUG(MTD_DEBUG_LEVEL0, "nand_read_oob: "
1282 "Attempt to start read outside oob\n");
1283 return -EINVAL;
1284 }
1285
1286 /* Do not allow reads past end of device */
1287 if (unlikely(from >= mtd->size ||
1288 ops->ooboffs + readlen > ((mtd->size >> chip->page_shift) -
1289 (from >> chip->page_shift)) * len)) {
1290 DEBUG(MTD_DEBUG_LEVEL0, "nand_read_oob: "
1291 "Attempt read beyond end of device\n");
1292 return -EINVAL;
1293 }
1279 1294
1280 chipnr = (int)(from >> chip->chip_shift); 1295 chipnr = (int)(from >> chip->chip_shift);
1281 chip->select_chip(mtd, chipnr); 1296 chip->select_chip(mtd, chipnr);
@@ -1742,19 +1757,40 @@ static int nand_write(struct mtd_info *mtd, loff_t to, size_t len,
1742static int nand_do_write_oob(struct mtd_info *mtd, loff_t to, 1757static int nand_do_write_oob(struct mtd_info *mtd, loff_t to,
1743 struct mtd_oob_ops *ops) 1758 struct mtd_oob_ops *ops)
1744{ 1759{
1745 int chipnr, page, status; 1760 int chipnr, page, status, len;
1746 struct nand_chip *chip = mtd->priv; 1761 struct nand_chip *chip = mtd->priv;
1747 1762
1748 DEBUG(MTD_DEBUG_LEVEL3, "nand_write_oob: to = 0x%08x, len = %i\n", 1763 DEBUG(MTD_DEBUG_LEVEL3, "nand_write_oob: to = 0x%08x, len = %i\n",
1749 (unsigned int)to, (int)ops->ooblen); 1764 (unsigned int)to, (int)ops->ooblen);
1750 1765
1766 if (ops->mode == MTD_OOB_AUTO)
1767 len = chip->ecc.layout->oobavail;
1768 else
1769 len = mtd->oobsize;
1770
1751 /* Do not allow write past end of page */ 1771 /* Do not allow write past end of page */
1752 if ((ops->ooboffs + ops->ooblen) > mtd->oobsize) { 1772 if ((ops->ooboffs + ops->ooblen) > len) {
1753 DEBUG(MTD_DEBUG_LEVEL0, "nand_write_oob: " 1773 DEBUG(MTD_DEBUG_LEVEL0, "nand_write_oob: "
1754 "Attempt to write past end of page\n"); 1774 "Attempt to write past end of page\n");
1755 return -EINVAL; 1775 return -EINVAL;
1756 } 1776 }
1757 1777
1778 if (unlikely(ops->ooboffs >= len)) {
1779 DEBUG(MTD_DEBUG_LEVEL0, "nand_read_oob: "
1780 "Attempt to start write outside oob\n");
1781 return -EINVAL;
1782 }
1783
1784 /* Do not allow reads past end of device */
1785 if (unlikely(to >= mtd->size ||
1786 ops->ooboffs + ops->ooblen >
1787 ((mtd->size >> chip->page_shift) -
1788 (to >> chip->page_shift)) * len)) {
1789 DEBUG(MTD_DEBUG_LEVEL0, "nand_read_oob: "
1790 "Attempt write beyond end of device\n");
1791 return -EINVAL;
1792 }
1793
1758 chipnr = (int)(to >> chip->chip_shift); 1794 chipnr = (int)(to >> chip->chip_shift);
1759 chip->select_chip(mtd, chipnr); 1795 chip->select_chip(mtd, chipnr);
1760 1796
@@ -2530,7 +2566,6 @@ int nand_scan_tail(struct mtd_info *mtd)
2530 /* Fill in remaining MTD driver data */ 2566 /* Fill in remaining MTD driver data */
2531 mtd->type = MTD_NANDFLASH; 2567 mtd->type = MTD_NANDFLASH;
2532 mtd->flags = MTD_CAP_NANDFLASH; 2568 mtd->flags = MTD_CAP_NANDFLASH;
2533 mtd->ecctype = MTD_ECC_SW;
2534 mtd->erase = nand_erase; 2569 mtd->erase = nand_erase;
2535 mtd->point = NULL; 2570 mtd->point = NULL;
2536 mtd->unpoint = NULL; 2571 mtd->unpoint = NULL;
diff --git a/drivers/mtd/nand/s3c2410.c b/drivers/mtd/nand/s3c2410.c
index 8b3203571eeb..0ddfd6de75c5 100644
--- a/drivers/mtd/nand/s3c2410.c
+++ b/drivers/mtd/nand/s3c2410.c
@@ -337,17 +337,69 @@ static int s3c2412_nand_devready(struct mtd_info *mtd)
337static int s3c2410_nand_correct_data(struct mtd_info *mtd, u_char *dat, 337static int s3c2410_nand_correct_data(struct mtd_info *mtd, u_char *dat,
338 u_char *read_ecc, u_char *calc_ecc) 338 u_char *read_ecc, u_char *calc_ecc)
339{ 339{
340 pr_debug("s3c2410_nand_correct_data(%p,%p,%p,%p)\n", mtd, dat, read_ecc, calc_ecc); 340 struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
341 unsigned int diff0, diff1, diff2;
342 unsigned int bit, byte;
341 343
342 pr_debug("eccs: read %02x,%02x,%02x vs calc %02x,%02x,%02x\n", 344 pr_debug("%s(%p,%p,%p,%p)\n", __func__, mtd, dat, read_ecc, calc_ecc);
343 read_ecc[0], read_ecc[1], read_ecc[2], calc_ecc[0], calc_ecc[1], calc_ecc[2]);
344 345
345 if (read_ecc[0] == calc_ecc[0] && read_ecc[1] == calc_ecc[1] && read_ecc[2] == calc_ecc[2]) 346 diff0 = read_ecc[0] ^ calc_ecc[0];
346 return 0; 347 diff1 = read_ecc[1] ^ calc_ecc[1];
348 diff2 = read_ecc[2] ^ calc_ecc[2];
349
350 pr_debug("%s: rd %02x%02x%02x calc %02x%02x%02x diff %02x%02x%02x\n",
351 __func__,
352 read_ecc[0], read_ecc[1], read_ecc[2],
353 calc_ecc[0], calc_ecc[1], calc_ecc[2],
354 diff0, diff1, diff2);
355
356 if (diff0 == 0 && diff1 == 0 && diff2 == 0)
357 return 0; /* ECC is ok */
358
359 /* Can we correct this ECC (ie, one row and column change).
360 * Note, this is similar to the 256 error code on smartmedia */
361
362 if (((diff0 ^ (diff0 >> 1)) & 0x55) == 0x55 &&
363 ((diff1 ^ (diff1 >> 1)) & 0x55) == 0x55 &&
364 ((diff2 ^ (diff2 >> 1)) & 0x55) == 0x55) {
365 /* calculate the bit position of the error */
366
367 bit = (diff2 >> 2) & 1;
368 bit |= (diff2 >> 3) & 2;
369 bit |= (diff2 >> 4) & 4;
370
371 /* calculate the byte position of the error */
372
373 byte = (diff1 << 1) & 0x80;
374 byte |= (diff1 << 2) & 0x40;
375 byte |= (diff1 << 3) & 0x20;
376 byte |= (diff1 << 4) & 0x10;
377
378 byte |= (diff0 >> 3) & 0x08;
379 byte |= (diff0 >> 2) & 0x04;
380 byte |= (diff0 >> 1) & 0x02;
381 byte |= (diff0 >> 0) & 0x01;
347 382
348 /* we curently have no method for correcting the error */ 383 byte |= (diff2 << 8) & 0x100;
349 384
350 return -1; 385 dev_dbg(info->device, "correcting error bit %d, byte %d\n",
386 bit, byte);
387
388 dat[byte] ^= (1 << bit);
389 return 1;
390 }
391
392 /* if there is only one bit difference in the ECC, then
393 * one of only a row or column parity has changed, which
394 * means the error is most probably in the ECC itself */
395
396 diff0 |= (diff1 << 8);
397 diff0 |= (diff2 << 16);
398
399 if ((diff0 & ~(1<<fls(diff0))) == 0)
400 return 1;
401
402 return 0;
351} 403}
352 404
353/* ECC functions 405/* ECC functions
@@ -366,6 +418,15 @@ static void s3c2410_nand_enable_hwecc(struct mtd_info *mtd, int mode)
366 writel(ctrl, info->regs + S3C2410_NFCONF); 418 writel(ctrl, info->regs + S3C2410_NFCONF);
367} 419}
368 420
421static void s3c2412_nand_enable_hwecc(struct mtd_info *mtd, int mode)
422{
423 struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
424 unsigned long ctrl;
425
426 ctrl = readl(info->regs + S3C2440_NFCONT);
427 writel(ctrl | S3C2412_NFCONT_INIT_MAIN_ECC, info->regs + S3C2440_NFCONT);
428}
429
369static void s3c2440_nand_enable_hwecc(struct mtd_info *mtd, int mode) 430static void s3c2440_nand_enable_hwecc(struct mtd_info *mtd, int mode)
370{ 431{
371 struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd); 432 struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
@@ -383,6 +444,21 @@ static int s3c2410_nand_calculate_ecc(struct mtd_info *mtd, const u_char *dat, u
383 ecc_code[1] = readb(info->regs + S3C2410_NFECC + 1); 444 ecc_code[1] = readb(info->regs + S3C2410_NFECC + 1);
384 ecc_code[2] = readb(info->regs + S3C2410_NFECC + 2); 445 ecc_code[2] = readb(info->regs + S3C2410_NFECC + 2);
385 446
447 pr_debug("%s: returning ecc %02x%02x%02x\n", __func__,
448 ecc_code[0], ecc_code[1], ecc_code[2]);
449
450 return 0;
451}
452
453static int s3c2412_nand_calculate_ecc(struct mtd_info *mtd, const u_char *dat, u_char *ecc_code)
454{
455 struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
456 unsigned long ecc = readl(info->regs + S3C2412_NFMECC0);
457
458 ecc_code[0] = ecc;
459 ecc_code[1] = ecc >> 8;
460 ecc_code[2] = ecc >> 16;
461
386 pr_debug("calculate_ecc: returning ecc %02x,%02x,%02x\n", ecc_code[0], ecc_code[1], ecc_code[2]); 462 pr_debug("calculate_ecc: returning ecc %02x,%02x,%02x\n", ecc_code[0], ecc_code[1], ecc_code[2]);
387 463
388 return 0; 464 return 0;
@@ -397,7 +473,7 @@ static int s3c2440_nand_calculate_ecc(struct mtd_info *mtd, const u_char *dat, u
397 ecc_code[1] = ecc >> 8; 473 ecc_code[1] = ecc >> 8;
398 ecc_code[2] = ecc >> 16; 474 ecc_code[2] = ecc >> 16;
399 475
400 pr_debug("calculate_ecc: returning ecc %02x,%02x,%02x\n", ecc_code[0], ecc_code[1], ecc_code[2]); 476 pr_debug("%s: returning ecc %06x\n", __func__, ecc);
401 477
402 return 0; 478 return 0;
403} 479}
@@ -565,6 +641,10 @@ static void s3c2410_nand_init_chip(struct s3c2410_nand_info *info,
565 break; 641 break;
566 642
567 case TYPE_S3C2412: 643 case TYPE_S3C2412:
644 chip->ecc.hwctl = s3c2412_nand_enable_hwecc;
645 chip->ecc.calculate = s3c2412_nand_calculate_ecc;
646 break;
647
568 case TYPE_S3C2440: 648 case TYPE_S3C2440:
569 chip->ecc.hwctl = s3c2440_nand_enable_hwecc; 649 chip->ecc.hwctl = s3c2440_nand_enable_hwecc;
570 chip->ecc.calculate = s3c2440_nand_calculate_ecc; 650 chip->ecc.calculate = s3c2440_nand_calculate_ecc;
diff --git a/drivers/mtd/onenand/onenand_base.c b/drivers/mtd/onenand/onenand_base.c
index 2da6bb26353e..7f1cb6e5dccb 100644
--- a/drivers/mtd/onenand/onenand_base.c
+++ b/drivers/mtd/onenand/onenand_base.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * linux/drivers/mtd/onenand/onenand_base.c 2 * linux/drivers/mtd/onenand/onenand_base.c
3 * 3 *
4 * Copyright (C) 2005-2006 Samsung Electronics 4 * Copyright (C) 2005-2007 Samsung Electronics
5 * Kyungmin Park <kyungmin.park@samsung.com> 5 * Kyungmin Park <kyungmin.park@samsung.com>
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify 7 * This program is free software; you can redistribute it and/or modify
@@ -94,16 +94,9 @@ static void onenand_writew(unsigned short value, void __iomem *addr)
94 */ 94 */
95static int onenand_block_address(struct onenand_chip *this, int block) 95static int onenand_block_address(struct onenand_chip *this, int block)
96{ 96{
97 if (this->device_id & ONENAND_DEVICE_IS_DDP) { 97 /* Device Flash Core select, NAND Flash Block Address */
98 /* Device Flash Core select, NAND Flash Block Address */ 98 if (block & this->density_mask)
99 int dfs = 0; 99 return ONENAND_DDP_CHIP1 | (block ^ this->density_mask);
100
101 if (block & this->density_mask)
102 dfs = 1;
103
104 return (dfs << ONENAND_DDP_SHIFT) |
105 (block & (this->density_mask - 1));
106 }
107 100
108 return block; 101 return block;
109} 102}
@@ -118,17 +111,11 @@ static int onenand_block_address(struct onenand_chip *this, int block)
118 */ 111 */
119static int onenand_bufferram_address(struct onenand_chip *this, int block) 112static int onenand_bufferram_address(struct onenand_chip *this, int block)
120{ 113{
121 if (this->device_id & ONENAND_DEVICE_IS_DDP) { 114 /* Device BufferRAM Select */
122 /* Device BufferRAM Select */ 115 if (block & this->density_mask)
123 int dbs = 0; 116 return ONENAND_DDP_CHIP1;
124
125 if (block & this->density_mask)
126 dbs = 1;
127 117
128 return (dbs << ONENAND_DDP_SHIFT); 118 return ONENAND_DDP_CHIP0;
129 }
130
131 return 0;
132} 119}
133 120
134/** 121/**
@@ -317,22 +304,25 @@ static int onenand_wait(struct mtd_info *mtd, int state)
317 ctrl = this->read_word(this->base + ONENAND_REG_CTRL_STATUS); 304 ctrl = this->read_word(this->base + ONENAND_REG_CTRL_STATUS);
318 305
319 if (ctrl & ONENAND_CTRL_ERROR) { 306 if (ctrl & ONENAND_CTRL_ERROR) {
320 DEBUG(MTD_DEBUG_LEVEL0, "onenand_wait: controller error = 0x%04x\n", ctrl); 307 printk(KERN_ERR "onenand_wait: controller error = 0x%04x\n", ctrl);
321 if (ctrl & ONENAND_CTRL_LOCK) 308 if (ctrl & ONENAND_CTRL_LOCK)
322 DEBUG(MTD_DEBUG_LEVEL0, "onenand_wait: it's locked error.\n"); 309 printk(KERN_ERR "onenand_wait: it's locked error.\n");
323 return ctrl; 310 return ctrl;
324 } 311 }
325 312
326 if (interrupt & ONENAND_INT_READ) { 313 if (interrupt & ONENAND_INT_READ) {
327 int ecc = this->read_word(this->base + ONENAND_REG_ECC_STATUS); 314 int ecc = this->read_word(this->base + ONENAND_REG_ECC_STATUS);
328 if (ecc) { 315 if (ecc) {
329 DEBUG(MTD_DEBUG_LEVEL0, "onenand_wait: ECC error = 0x%04x\n", ecc); 316 printk(KERN_ERR "onenand_wait: ECC error = 0x%04x\n", ecc);
330 if (ecc & ONENAND_ECC_2BIT_ALL) { 317 if (ecc & ONENAND_ECC_2BIT_ALL) {
331 mtd->ecc_stats.failed++; 318 mtd->ecc_stats.failed++;
332 return ecc; 319 return ecc;
333 } else if (ecc & ONENAND_ECC_1BIT_ALL) 320 } else if (ecc & ONENAND_ECC_1BIT_ALL)
334 mtd->ecc_stats.corrected++; 321 mtd->ecc_stats.corrected++;
335 } 322 }
323 } else if (state == FL_READING) {
324 printk(KERN_ERR "onenand_wait: read timeout! ctrl=0x%04x intr=0x%04x\n", ctrl, interrupt);
325 return -EIO;
336 } 326 }
337 327
338 return 0; 328 return 0;
@@ -587,22 +577,32 @@ static int onenand_write_bufferram(struct mtd_info *mtd, int area,
587static int onenand_check_bufferram(struct mtd_info *mtd, loff_t addr) 577static int onenand_check_bufferram(struct mtd_info *mtd, loff_t addr)
588{ 578{
589 struct onenand_chip *this = mtd->priv; 579 struct onenand_chip *this = mtd->priv;
590 int block, page; 580 int blockpage, found = 0;
591 int i; 581 unsigned int i;
592 582
593 block = (int) (addr >> this->erase_shift); 583 blockpage = (int) (addr >> this->page_shift);
594 page = (int) (addr >> this->page_shift);
595 page &= this->page_mask;
596 584
585 /* Is there valid data? */
597 i = ONENAND_CURRENT_BUFFERRAM(this); 586 i = ONENAND_CURRENT_BUFFERRAM(this);
587 if (this->bufferram[i].blockpage == blockpage)
588 found = 1;
589 else {
590 /* Check another BufferRAM */
591 i = ONENAND_NEXT_BUFFERRAM(this);
592 if (this->bufferram[i].blockpage == blockpage) {
593 ONENAND_SET_NEXT_BUFFERRAM(this);
594 found = 1;
595 }
596 }
598 597
599 /* Is there valid data? */ 598 if (found && ONENAND_IS_DDP(this)) {
600 if (this->bufferram[i].block == block && 599 /* Select DataRAM for DDP */
601 this->bufferram[i].page == page && 600 int block = (int) (addr >> this->erase_shift);
602 this->bufferram[i].valid) 601 int value = onenand_bufferram_address(this, block);
603 return 1; 602 this->write_word(value, this->base + ONENAND_REG_START_ADDRESS2);
603 }
604 604
605 return 0; 605 return found;
606} 606}
607 607
608/** 608/**
@@ -613,31 +613,49 @@ static int onenand_check_bufferram(struct mtd_info *mtd, loff_t addr)
613 * 613 *
614 * Update BufferRAM information 614 * Update BufferRAM information
615 */ 615 */
616static int onenand_update_bufferram(struct mtd_info *mtd, loff_t addr, 616static void onenand_update_bufferram(struct mtd_info *mtd, loff_t addr,
617 int valid) 617 int valid)
618{ 618{
619 struct onenand_chip *this = mtd->priv; 619 struct onenand_chip *this = mtd->priv;
620 int block, page; 620 int blockpage;
621 int i; 621 unsigned int i;
622 622
623 block = (int) (addr >> this->erase_shift); 623 blockpage = (int) (addr >> this->page_shift);
624 page = (int) (addr >> this->page_shift);
625 page &= this->page_mask;
626 624
627 /* Invalidate BufferRAM */ 625 /* Invalidate another BufferRAM */
628 for (i = 0; i < MAX_BUFFERRAM; i++) { 626 i = ONENAND_NEXT_BUFFERRAM(this);
629 if (this->bufferram[i].block == block && 627 if (this->bufferram[i].blockpage == blockpage)
630 this->bufferram[i].page == page) 628 this->bufferram[i].blockpage = -1;
631 this->bufferram[i].valid = 0;
632 }
633 629
634 /* Update BufferRAM */ 630 /* Update BufferRAM */
635 i = ONENAND_CURRENT_BUFFERRAM(this); 631 i = ONENAND_CURRENT_BUFFERRAM(this);
636 this->bufferram[i].block = block; 632 if (valid)
637 this->bufferram[i].page = page; 633 this->bufferram[i].blockpage = blockpage;
638 this->bufferram[i].valid = valid; 634 else
635 this->bufferram[i].blockpage = -1;
636}
639 637
640 return 0; 638/**
639 * onenand_invalidate_bufferram - [GENERIC] Invalidate BufferRAM information
640 * @param mtd MTD data structure
641 * @param addr start address to invalidate
642 * @param len length to invalidate
643 *
644 * Invalidate BufferRAM information
645 */
646static void onenand_invalidate_bufferram(struct mtd_info *mtd, loff_t addr,
647 unsigned int len)
648{
649 struct onenand_chip *this = mtd->priv;
650 int i;
651 loff_t end_addr = addr + len;
652
653 /* Invalidate BufferRAM */
654 for (i = 0; i < MAX_BUFFERRAM; i++) {
655 loff_t buf_addr = this->bufferram[i].blockpage << this->page_shift;
656 if (buf_addr >= addr && buf_addr < end_addr)
657 this->bufferram[i].blockpage = -1;
658 }
641} 659}
642 660
643/** 661/**
@@ -716,7 +734,7 @@ static int onenand_read(struct mtd_info *mtd, loff_t from, size_t len,
716 734
717 /* Do not allow reads past end of device */ 735 /* Do not allow reads past end of device */
718 if ((from + len) > mtd->size) { 736 if ((from + len) > mtd->size) {
719 DEBUG(MTD_DEBUG_LEVEL0, "onenand_read: Attempt read beyond end of device\n"); 737 printk(KERN_ERR "onenand_read: Attempt read beyond end of device\n");
720 *retlen = 0; 738 *retlen = 0;
721 return -EINVAL; 739 return -EINVAL;
722 } 740 }
@@ -724,8 +742,6 @@ static int onenand_read(struct mtd_info *mtd, loff_t from, size_t len,
724 /* Grab the lock and see if the device is available */ 742 /* Grab the lock and see if the device is available */
725 onenand_get_device(mtd, FL_READING); 743 onenand_get_device(mtd, FL_READING);
726 744
727 /* TODO handling oob */
728
729 stats = mtd->ecc_stats; 745 stats = mtd->ecc_stats;
730 746
731 /* Read-while-load method */ 747 /* Read-while-load method */
@@ -754,9 +770,9 @@ static int onenand_read(struct mtd_info *mtd, loff_t from, size_t len,
754 * Now we issued chip 1 read and pointed chip 1 770 * Now we issued chip 1 read and pointed chip 1
755 * bufferam so we have to point chip 0 bufferam. 771 * bufferam so we have to point chip 0 bufferam.
756 */ 772 */
757 if (this->device_id & ONENAND_DEVICE_IS_DDP && 773 if (ONENAND_IS_DDP(this) &&
758 unlikely(from == (this->chipsize >> 1))) { 774 unlikely(from == (this->chipsize >> 1))) {
759 this->write_word(0, this->base + ONENAND_REG_START_ADDRESS2); 775 this->write_word(ONENAND_DDP_CHIP0, this->base + ONENAND_REG_START_ADDRESS2);
760 boundary = 1; 776 boundary = 1;
761 } else 777 } else
762 boundary = 0; 778 boundary = 0;
@@ -770,7 +786,7 @@ static int onenand_read(struct mtd_info *mtd, loff_t from, size_t len,
770 break; 786 break;
771 /* Set up for next read from bufferRAM */ 787 /* Set up for next read from bufferRAM */
772 if (unlikely(boundary)) 788 if (unlikely(boundary))
773 this->write_word(0x8000, this->base + ONENAND_REG_START_ADDRESS2); 789 this->write_word(ONENAND_DDP_CHIP1, this->base + ONENAND_REG_START_ADDRESS2);
774 ONENAND_SET_NEXT_BUFFERRAM(this); 790 ONENAND_SET_NEXT_BUFFERRAM(this);
775 buf += thislen; 791 buf += thislen;
776 thislen = min_t(int, mtd->writesize, len - read); 792 thislen = min_t(int, mtd->writesize, len - read);
@@ -801,20 +817,59 @@ static int onenand_read(struct mtd_info *mtd, loff_t from, size_t len,
801} 817}
802 818
803/** 819/**
820 * onenand_transfer_auto_oob - [Internal] oob auto-placement transfer
821 * @param mtd MTD device structure
822 * @param buf destination address
823 * @param column oob offset to read from
824 * @param thislen oob length to read
825 */
826static int onenand_transfer_auto_oob(struct mtd_info *mtd, uint8_t *buf, int column,
827 int thislen)
828{
829 struct onenand_chip *this = mtd->priv;
830 struct nand_oobfree *free;
831 int readcol = column;
832 int readend = column + thislen;
833 int lastgap = 0;
834 uint8_t *oob_buf = this->page_buf + mtd->writesize;
835
836 for (free = this->ecclayout->oobfree; free->length; ++free) {
837 if (readcol >= lastgap)
838 readcol += free->offset - lastgap;
839 if (readend >= lastgap)
840 readend += free->offset - lastgap;
841 lastgap = free->offset + free->length;
842 }
843 this->read_bufferram(mtd, ONENAND_SPARERAM, oob_buf, 0, mtd->oobsize);
844 for (free = this->ecclayout->oobfree; free->length; ++free) {
845 int free_end = free->offset + free->length;
846 if (free->offset < readend && free_end > readcol) {
847 int st = max_t(int,free->offset,readcol);
848 int ed = min_t(int,free_end,readend);
849 int n = ed - st;
850 memcpy(buf, oob_buf + st, n);
851 buf += n;
852 }
853 }
854 return 0;
855}
856
857/**
804 * onenand_do_read_oob - [MTD Interface] OneNAND read out-of-band 858 * onenand_do_read_oob - [MTD Interface] OneNAND read out-of-band
805 * @param mtd MTD device structure 859 * @param mtd MTD device structure
806 * @param from offset to read from 860 * @param from offset to read from
807 * @param len number of bytes to read 861 * @param len number of bytes to read
808 * @param retlen pointer to variable to store the number of read bytes 862 * @param retlen pointer to variable to store the number of read bytes
809 * @param buf the databuffer to put data 863 * @param buf the databuffer to put data
864 * @param mode operation mode
810 * 865 *
811 * OneNAND read out-of-band data from the spare area 866 * OneNAND read out-of-band data from the spare area
812 */ 867 */
813int onenand_do_read_oob(struct mtd_info *mtd, loff_t from, size_t len, 868static int onenand_do_read_oob(struct mtd_info *mtd, loff_t from, size_t len,
814 size_t *retlen, u_char *buf) 869 size_t *retlen, u_char *buf, mtd_oob_mode_t mode)
815{ 870{
816 struct onenand_chip *this = mtd->priv; 871 struct onenand_chip *this = mtd->priv;
817 int read = 0, thislen, column; 872 int read = 0, thislen, column, oobsize;
818 int ret = 0; 873 int ret = 0;
819 874
820 DEBUG(MTD_DEBUG_LEVEL3, "onenand_read_oob: from = 0x%08x, len = %i\n", (unsigned int) from, (int) len); 875 DEBUG(MTD_DEBUG_LEVEL3, "onenand_read_oob: from = 0x%08x, len = %i\n", (unsigned int) from, (int) len);
@@ -822,21 +877,33 @@ int onenand_do_read_oob(struct mtd_info *mtd, loff_t from, size_t len,
822 /* Initialize return length value */ 877 /* Initialize return length value */
823 *retlen = 0; 878 *retlen = 0;
824 879
880 if (mode == MTD_OOB_AUTO)
881 oobsize = this->ecclayout->oobavail;
882 else
883 oobsize = mtd->oobsize;
884
885 column = from & (mtd->oobsize - 1);
886
887 if (unlikely(column >= oobsize)) {
888 printk(KERN_ERR "onenand_read_oob: Attempted to start read outside oob\n");
889 return -EINVAL;
890 }
891
825 /* Do not allow reads past end of device */ 892 /* Do not allow reads past end of device */
826 if (unlikely((from + len) > mtd->size)) { 893 if (unlikely(from >= mtd->size ||
827 DEBUG(MTD_DEBUG_LEVEL0, "onenand_read_oob: Attempt read beyond end of device\n"); 894 column + len > ((mtd->size >> this->page_shift) -
895 (from >> this->page_shift)) * oobsize)) {
896 printk(KERN_ERR "onenand_read_oob: Attempted to read beyond end of device\n");
828 return -EINVAL; 897 return -EINVAL;
829 } 898 }
830 899
831 /* Grab the lock and see if the device is available */ 900 /* Grab the lock and see if the device is available */
832 onenand_get_device(mtd, FL_READING); 901 onenand_get_device(mtd, FL_READING);
833 902
834 column = from & (mtd->oobsize - 1);
835
836 while (read < len) { 903 while (read < len) {
837 cond_resched(); 904 cond_resched();
838 905
839 thislen = mtd->oobsize - column; 906 thislen = oobsize - column;
840 thislen = min_t(int, thislen, len); 907 thislen = min_t(int, thislen, len);
841 908
842 this->command(mtd, ONENAND_CMD_READOOB, from, mtd->oobsize); 909 this->command(mtd, ONENAND_CMD_READOOB, from, mtd->oobsize);
@@ -846,11 +913,14 @@ int onenand_do_read_oob(struct mtd_info *mtd, loff_t from, size_t len,
846 ret = this->wait(mtd, FL_READING); 913 ret = this->wait(mtd, FL_READING);
847 /* First copy data and check return value for ECC handling */ 914 /* First copy data and check return value for ECC handling */
848 915
849 this->read_bufferram(mtd, ONENAND_SPARERAM, buf, column, thislen); 916 if (mode == MTD_OOB_AUTO)
917 onenand_transfer_auto_oob(mtd, buf, column, thislen);
918 else
919 this->read_bufferram(mtd, ONENAND_SPARERAM, buf, column, thislen);
850 920
851 if (ret) { 921 if (ret) {
852 DEBUG(MTD_DEBUG_LEVEL0, "onenand_read_oob: read failed = 0x%x\n", ret); 922 printk(KERN_ERR "onenand_read_oob: read failed = 0x%x\n", ret);
853 goto out; 923 break;
854 } 924 }
855 925
856 read += thislen; 926 read += thislen;
@@ -868,7 +938,6 @@ int onenand_do_read_oob(struct mtd_info *mtd, loff_t from, size_t len,
868 } 938 }
869 } 939 }
870 940
871out:
872 /* Deselect and wake up anyone waiting on the device */ 941 /* Deselect and wake up anyone waiting on the device */
873 onenand_release_device(mtd); 942 onenand_release_device(mtd);
874 943
@@ -885,10 +954,132 @@ out:
885static int onenand_read_oob(struct mtd_info *mtd, loff_t from, 954static int onenand_read_oob(struct mtd_info *mtd, loff_t from,
886 struct mtd_oob_ops *ops) 955 struct mtd_oob_ops *ops)
887{ 956{
888 BUG_ON(ops->mode != MTD_OOB_PLACE); 957 switch (ops->mode) {
889 958 case MTD_OOB_PLACE:
959 case MTD_OOB_AUTO:
960 break;
961 case MTD_OOB_RAW:
962 /* Not implemented yet */
963 default:
964 return -EINVAL;
965 }
890 return onenand_do_read_oob(mtd, from + ops->ooboffs, ops->ooblen, 966 return onenand_do_read_oob(mtd, from + ops->ooboffs, ops->ooblen,
891 &ops->oobretlen, ops->oobbuf); 967 &ops->oobretlen, ops->oobbuf, ops->mode);
968}
969
970/**
971 * onenand_bbt_wait - [DEFAULT] wait until the command is done
972 * @param mtd MTD device structure
973 * @param state state to select the max. timeout value
974 *
975 * Wait for command done.
976 */
977static int onenand_bbt_wait(struct mtd_info *mtd, int state)
978{
979 struct onenand_chip *this = mtd->priv;
980 unsigned long timeout;
981 unsigned int interrupt;
982 unsigned int ctrl;
983
984 /* The 20 msec is enough */
985 timeout = jiffies + msecs_to_jiffies(20);
986 while (time_before(jiffies, timeout)) {
987 interrupt = this->read_word(this->base + ONENAND_REG_INTERRUPT);
988 if (interrupt & ONENAND_INT_MASTER)
989 break;
990 }
991 /* To get correct interrupt status in timeout case */
992 interrupt = this->read_word(this->base + ONENAND_REG_INTERRUPT);
993 ctrl = this->read_word(this->base + ONENAND_REG_CTRL_STATUS);
994
995 if (ctrl & ONENAND_CTRL_ERROR) {
996 printk(KERN_DEBUG "onenand_bbt_wait: controller error = 0x%04x\n", ctrl);
997 /* Initial bad block case */
998 if (ctrl & ONENAND_CTRL_LOAD)
999 return ONENAND_BBT_READ_ERROR;
1000 return ONENAND_BBT_READ_FATAL_ERROR;
1001 }
1002
1003 if (interrupt & ONENAND_INT_READ) {
1004 int ecc = this->read_word(this->base + ONENAND_REG_ECC_STATUS);
1005 if (ecc & ONENAND_ECC_2BIT_ALL)
1006 return ONENAND_BBT_READ_ERROR;
1007 } else {
1008 printk(KERN_ERR "onenand_bbt_wait: read timeout!"
1009 "ctrl=0x%04x intr=0x%04x\n", ctrl, interrupt);
1010 return ONENAND_BBT_READ_FATAL_ERROR;
1011 }
1012
1013 return 0;
1014}
1015
1016/**
1017 * onenand_bbt_read_oob - [MTD Interface] OneNAND read out-of-band for bbt scan
1018 * @param mtd MTD device structure
1019 * @param from offset to read from
1020 * @param @ops oob operation description structure
1021 *
1022 * OneNAND read out-of-band data from the spare area for bbt scan
1023 */
1024int onenand_bbt_read_oob(struct mtd_info *mtd, loff_t from,
1025 struct mtd_oob_ops *ops)
1026{
1027 struct onenand_chip *this = mtd->priv;
1028 int read = 0, thislen, column;
1029 int ret = 0;
1030 size_t len = ops->ooblen;
1031 u_char *buf = ops->oobbuf;
1032
1033 DEBUG(MTD_DEBUG_LEVEL3, "onenand_bbt_read_oob: from = 0x%08x, len = %zi\n", (unsigned int) from, len);
1034
1035 /* Initialize return value */
1036 ops->oobretlen = 0;
1037
1038 /* Do not allow reads past end of device */
1039 if (unlikely((from + len) > mtd->size)) {
1040 printk(KERN_ERR "onenand_bbt_read_oob: Attempt read beyond end of device\n");
1041 return ONENAND_BBT_READ_FATAL_ERROR;
1042 }
1043
1044 /* Grab the lock and see if the device is available */
1045 onenand_get_device(mtd, FL_READING);
1046
1047 column = from & (mtd->oobsize - 1);
1048
1049 while (read < len) {
1050 cond_resched();
1051
1052 thislen = mtd->oobsize - column;
1053 thislen = min_t(int, thislen, len);
1054
1055 this->command(mtd, ONENAND_CMD_READOOB, from, mtd->oobsize);
1056
1057 onenand_update_bufferram(mtd, from, 0);
1058
1059 ret = onenand_bbt_wait(mtd, FL_READING);
1060 if (ret)
1061 break;
1062
1063 this->read_bufferram(mtd, ONENAND_SPARERAM, buf, column, thislen);
1064 read += thislen;
1065 if (read == len)
1066 break;
1067
1068 buf += thislen;
1069
1070 /* Read more? */
1071 if (read < len) {
1072 /* Update Page size */
1073 from += mtd->writesize;
1074 column = 0;
1075 }
1076 }
1077
1078 /* Deselect and wake up anyone waiting on the device */
1079 onenand_release_device(mtd);
1080
1081 ops->oobretlen = read;
1082 return ret;
892} 1083}
893 1084
894#ifdef CONFIG_MTD_ONENAND_VERIFY_WRITE 1085#ifdef CONFIG_MTD_ONENAND_VERIFY_WRITE
@@ -897,14 +1088,12 @@ static int onenand_read_oob(struct mtd_info *mtd, loff_t from,
897 * @param mtd MTD device structure 1088 * @param mtd MTD device structure
898 * @param buf the databuffer to verify 1089 * @param buf the databuffer to verify
899 * @param to offset to read from 1090 * @param to offset to read from
900 * @param len number of bytes to read and compare
901 * 1091 *
902 */ 1092 */
903static int onenand_verify_oob(struct mtd_info *mtd, const u_char *buf, loff_t to, int len) 1093static int onenand_verify_oob(struct mtd_info *mtd, const u_char *buf, loff_t to)
904{ 1094{
905 struct onenand_chip *this = mtd->priv; 1095 struct onenand_chip *this = mtd->priv;
906 char *readp = this->page_buf; 1096 char *readp = this->page_buf + mtd->writesize;
907 int column = to & (mtd->oobsize - 1);
908 int status, i; 1097 int status, i;
909 1098
910 this->command(mtd, ONENAND_CMD_READOOB, to, mtd->oobsize); 1099 this->command(mtd, ONENAND_CMD_READOOB, to, mtd->oobsize);
@@ -913,9 +1102,8 @@ static int onenand_verify_oob(struct mtd_info *mtd, const u_char *buf, loff_t to
913 if (status) 1102 if (status)
914 return status; 1103 return status;
915 1104
916 this->read_bufferram(mtd, ONENAND_SPARERAM, readp, column, len); 1105 this->read_bufferram(mtd, ONENAND_SPARERAM, readp, 0, mtd->oobsize);
917 1106 for(i = 0; i < mtd->oobsize; i++)
918 for(i = 0; i < len; i++)
919 if (buf[i] != 0xFF && buf[i] != readp[i]) 1107 if (buf[i] != 0xFF && buf[i] != readp[i])
920 return -EBADMSG; 1108 return -EBADMSG;
921 1109
@@ -923,41 +1111,51 @@ static int onenand_verify_oob(struct mtd_info *mtd, const u_char *buf, loff_t to
923} 1111}
924 1112
925/** 1113/**
926 * onenand_verify_page - [GENERIC] verify the chip contents after a write 1114 * onenand_verify - [GENERIC] verify the chip contents after a write
927 * @param mtd MTD device structure 1115 * @param mtd MTD device structure
928 * @param buf the databuffer to verify 1116 * @param buf the databuffer to verify
1117 * @param addr offset to read from
1118 * @param len number of bytes to read and compare
929 * 1119 *
930 * Check DataRAM area directly
931 */ 1120 */
932static int onenand_verify_page(struct mtd_info *mtd, u_char *buf, loff_t addr) 1121static int onenand_verify(struct mtd_info *mtd, const u_char *buf, loff_t addr, size_t len)
933{ 1122{
934 struct onenand_chip *this = mtd->priv; 1123 struct onenand_chip *this = mtd->priv;
935 void __iomem *dataram0, *dataram1; 1124 void __iomem *dataram;
936 int ret = 0; 1125 int ret = 0;
1126 int thislen, column;
937 1127
938 /* In partial page write, just skip it */ 1128 while (len != 0) {
939 if ((addr & (mtd->writesize - 1)) != 0) 1129 thislen = min_t(int, mtd->writesize, len);
940 return 0; 1130 column = addr & (mtd->writesize - 1);
1131 if (column + thislen > mtd->writesize)
1132 thislen = mtd->writesize - column;
941 1133
942 this->command(mtd, ONENAND_CMD_READ, addr, mtd->writesize); 1134 this->command(mtd, ONENAND_CMD_READ, addr, mtd->writesize);
943 1135
944 ret = this->wait(mtd, FL_READING); 1136 onenand_update_bufferram(mtd, addr, 0);
945 if (ret) 1137
946 return ret; 1138 ret = this->wait(mtd, FL_READING);
1139 if (ret)
1140 return ret;
947 1141
948 onenand_update_bufferram(mtd, addr, 1); 1142 onenand_update_bufferram(mtd, addr, 1);
949 1143
950 /* Check, if the two dataram areas are same */ 1144 dataram = this->base + ONENAND_DATARAM;
951 dataram0 = this->base + ONENAND_DATARAM; 1145 dataram += onenand_bufferram_offset(mtd, ONENAND_DATARAM);
952 dataram1 = dataram0 + mtd->writesize;
953 1146
954 if (memcmp(dataram0, dataram1, mtd->writesize)) 1147 if (memcmp(buf, dataram + column, thislen))
955 return -EBADMSG; 1148 return -EBADMSG;
1149
1150 len -= thislen;
1151 buf += thislen;
1152 addr += thislen;
1153 }
956 1154
957 return 0; 1155 return 0;
958} 1156}
959#else 1157#else
960#define onenand_verify_page(...) (0) 1158#define onenand_verify(...) (0)
961#define onenand_verify_oob(...) (0) 1159#define onenand_verify_oob(...) (0)
962#endif 1160#endif
963 1161
@@ -988,60 +1186,57 @@ static int onenand_write(struct mtd_info *mtd, loff_t to, size_t len,
988 1186
989 /* Do not allow writes past end of device */ 1187 /* Do not allow writes past end of device */
990 if (unlikely((to + len) > mtd->size)) { 1188 if (unlikely((to + len) > mtd->size)) {
991 DEBUG(MTD_DEBUG_LEVEL0, "onenand_write: Attempt write to past end of device\n"); 1189 printk(KERN_ERR "onenand_write: Attempt write to past end of device\n");
992 return -EINVAL; 1190 return -EINVAL;
993 } 1191 }
994 1192
995 /* Reject writes, which are not page aligned */ 1193 /* Reject writes, which are not page aligned */
996 if (unlikely(NOTALIGNED(to)) || unlikely(NOTALIGNED(len))) { 1194 if (unlikely(NOTALIGNED(to)) || unlikely(NOTALIGNED(len))) {
997 DEBUG(MTD_DEBUG_LEVEL0, "onenand_write: Attempt to write not page aligned data\n"); 1195 printk(KERN_ERR "onenand_write: Attempt to write not page aligned data\n");
998 return -EINVAL; 1196 return -EINVAL;
999 } 1197 }
1000 1198
1001 column = to & (mtd->writesize - 1); 1199 column = to & (mtd->writesize - 1);
1002 subpage = column || (len & (mtd->writesize - 1));
1003 1200
1004 /* Grab the lock and see if the device is available */ 1201 /* Grab the lock and see if the device is available */
1005 onenand_get_device(mtd, FL_WRITING); 1202 onenand_get_device(mtd, FL_WRITING);
1006 1203
1007 /* Loop until all data write */ 1204 /* Loop until all data write */
1008 while (written < len) { 1205 while (written < len) {
1009 int bytes = mtd->writesize; 1206 int thislen = min_t(int, mtd->writesize - column, len - written);
1010 int thislen = min_t(int, bytes, len - written);
1011 u_char *wbuf = (u_char *) buf; 1207 u_char *wbuf = (u_char *) buf;
1012 1208
1013 cond_resched(); 1209 cond_resched();
1014 1210
1015 this->command(mtd, ONENAND_CMD_BUFFERRAM, to, bytes); 1211 this->command(mtd, ONENAND_CMD_BUFFERRAM, to, thislen);
1016 1212
1017 /* Partial page write */ 1213 /* Partial page write */
1214 subpage = thislen < mtd->writesize;
1018 if (subpage) { 1215 if (subpage) {
1019 bytes = min_t(int, bytes - column, (int) len);
1020 memset(this->page_buf, 0xff, mtd->writesize); 1216 memset(this->page_buf, 0xff, mtd->writesize);
1021 memcpy(this->page_buf + column, buf, bytes); 1217 memcpy(this->page_buf + column, buf, thislen);
1022 wbuf = this->page_buf; 1218 wbuf = this->page_buf;
1023 /* Even though partial write, we need page size */
1024 thislen = mtd->writesize;
1025 } 1219 }
1026 1220
1027 this->write_bufferram(mtd, ONENAND_DATARAM, wbuf, 0, thislen); 1221 this->write_bufferram(mtd, ONENAND_DATARAM, wbuf, 0, mtd->writesize);
1028 this->write_bufferram(mtd, ONENAND_SPARERAM, ffchars, 0, mtd->oobsize); 1222 this->write_bufferram(mtd, ONENAND_SPARERAM, ffchars, 0, mtd->oobsize);
1029 1223
1030 this->command(mtd, ONENAND_CMD_PROG, to, mtd->writesize); 1224 this->command(mtd, ONENAND_CMD_PROG, to, mtd->writesize);
1031 1225
1226 ret = this->wait(mtd, FL_WRITING);
1227
1032 /* In partial page write we don't update bufferram */ 1228 /* In partial page write we don't update bufferram */
1033 onenand_update_bufferram(mtd, to, !subpage); 1229 onenand_update_bufferram(mtd, to, !ret && !subpage);
1034 1230
1035 ret = this->wait(mtd, FL_WRITING);
1036 if (ret) { 1231 if (ret) {
1037 DEBUG(MTD_DEBUG_LEVEL0, "onenand_write: write filaed %d\n", ret); 1232 printk(KERN_ERR "onenand_write: write filaed %d\n", ret);
1038 break; 1233 break;
1039 } 1234 }
1040 1235
1041 /* Only check verify write turn on */ 1236 /* Only check verify write turn on */
1042 ret = onenand_verify_page(mtd, (u_char *) wbuf, to); 1237 ret = onenand_verify(mtd, (u_char *) wbuf, to, thislen);
1043 if (ret) { 1238 if (ret) {
1044 DEBUG(MTD_DEBUG_LEVEL0, "onenand_write: verify failed %d\n", ret); 1239 printk(KERN_ERR "onenand_write: verify failed %d\n", ret);
1045 break; 1240 break;
1046 } 1241 }
1047 1242
@@ -1064,20 +1259,58 @@ static int onenand_write(struct mtd_info *mtd, loff_t to, size_t len,
1064} 1259}
1065 1260
1066/** 1261/**
1262 * onenand_fill_auto_oob - [Internal] oob auto-placement transfer
1263 * @param mtd MTD device structure
1264 * @param oob_buf oob buffer
1265 * @param buf source address
1266 * @param column oob offset to write to
1267 * @param thislen oob length to write
1268 */
1269static int onenand_fill_auto_oob(struct mtd_info *mtd, u_char *oob_buf,
1270 const u_char *buf, int column, int thislen)
1271{
1272 struct onenand_chip *this = mtd->priv;
1273 struct nand_oobfree *free;
1274 int writecol = column;
1275 int writeend = column + thislen;
1276 int lastgap = 0;
1277
1278 for (free = this->ecclayout->oobfree; free->length; ++free) {
1279 if (writecol >= lastgap)
1280 writecol += free->offset - lastgap;
1281 if (writeend >= lastgap)
1282 writeend += free->offset - lastgap;
1283 lastgap = free->offset + free->length;
1284 }
1285 for (free = this->ecclayout->oobfree; free->length; ++free) {
1286 int free_end = free->offset + free->length;
1287 if (free->offset < writeend && free_end > writecol) {
1288 int st = max_t(int,free->offset,writecol);
1289 int ed = min_t(int,free_end,writeend);
1290 int n = ed - st;
1291 memcpy(oob_buf + st, buf, n);
1292 buf += n;
1293 }
1294 }
1295 return 0;
1296}
1297
1298/**
1067 * onenand_do_write_oob - [Internal] OneNAND write out-of-band 1299 * onenand_do_write_oob - [Internal] OneNAND write out-of-band
1068 * @param mtd MTD device structure 1300 * @param mtd MTD device structure
1069 * @param to offset to write to 1301 * @param to offset to write to
1070 * @param len number of bytes to write 1302 * @param len number of bytes to write
1071 * @param retlen pointer to variable to store the number of written bytes 1303 * @param retlen pointer to variable to store the number of written bytes
1072 * @param buf the data to write 1304 * @param buf the data to write
1305 * @param mode operation mode
1073 * 1306 *
1074 * OneNAND write out-of-band 1307 * OneNAND write out-of-band
1075 */ 1308 */
1076static int onenand_do_write_oob(struct mtd_info *mtd, loff_t to, size_t len, 1309static int onenand_do_write_oob(struct mtd_info *mtd, loff_t to, size_t len,
1077 size_t *retlen, const u_char *buf) 1310 size_t *retlen, const u_char *buf, mtd_oob_mode_t mode)
1078{ 1311{
1079 struct onenand_chip *this = mtd->priv; 1312 struct onenand_chip *this = mtd->priv;
1080 int column, ret = 0; 1313 int column, ret = 0, oobsize;
1081 int written = 0; 1314 int written = 0;
1082 1315
1083 DEBUG(MTD_DEBUG_LEVEL3, "onenand_write_oob: to = 0x%08x, len = %i\n", (unsigned int) to, (int) len); 1316 DEBUG(MTD_DEBUG_LEVEL3, "onenand_write_oob: to = 0x%08x, len = %i\n", (unsigned int) to, (int) len);
@@ -1085,9 +1318,30 @@ static int onenand_do_write_oob(struct mtd_info *mtd, loff_t to, size_t len,
1085 /* Initialize retlen, in case of early exit */ 1318 /* Initialize retlen, in case of early exit */
1086 *retlen = 0; 1319 *retlen = 0;
1087 1320
1088 /* Do not allow writes past end of device */ 1321 if (mode == MTD_OOB_AUTO)
1089 if (unlikely((to + len) > mtd->size)) { 1322 oobsize = this->ecclayout->oobavail;
1090 DEBUG(MTD_DEBUG_LEVEL0, "onenand_write_oob: Attempt write to past end of device\n"); 1323 else
1324 oobsize = mtd->oobsize;
1325
1326 column = to & (mtd->oobsize - 1);
1327
1328 if (unlikely(column >= oobsize)) {
1329 printk(KERN_ERR "onenand_write_oob: Attempted to start write outside oob\n");
1330 return -EINVAL;
1331 }
1332
1333 /* For compatibility with NAND: Do not allow write past end of page */
1334 if (column + len > oobsize) {
1335 printk(KERN_ERR "onenand_write_oob: "
1336 "Attempt to write past end of page\n");
1337 return -EINVAL;
1338 }
1339
1340 /* Do not allow reads past end of device */
1341 if (unlikely(to >= mtd->size ||
1342 column + len > ((mtd->size >> this->page_shift) -
1343 (to >> this->page_shift)) * oobsize)) {
1344 printk(KERN_ERR "onenand_write_oob: Attempted to write past end of device\n");
1091 return -EINVAL; 1345 return -EINVAL;
1092 } 1346 }
1093 1347
@@ -1096,18 +1350,19 @@ static int onenand_do_write_oob(struct mtd_info *mtd, loff_t to, size_t len,
1096 1350
1097 /* Loop until all data write */ 1351 /* Loop until all data write */
1098 while (written < len) { 1352 while (written < len) {
1099 int thislen = min_t(int, mtd->oobsize, len - written); 1353 int thislen = min_t(int, oobsize, len - written);
1100 1354
1101 cond_resched(); 1355 cond_resched();
1102 1356
1103 column = to & (mtd->oobsize - 1);
1104
1105 this->command(mtd, ONENAND_CMD_BUFFERRAM, to, mtd->oobsize); 1357 this->command(mtd, ONENAND_CMD_BUFFERRAM, to, mtd->oobsize);
1106 1358
1107 /* We send data to spare ram with oobsize 1359 /* We send data to spare ram with oobsize
1108 * to prevent byte access */ 1360 * to prevent byte access */
1109 memset(this->page_buf, 0xff, mtd->oobsize); 1361 memset(this->page_buf, 0xff, mtd->oobsize);
1110 memcpy(this->page_buf + column, buf, thislen); 1362 if (mode == MTD_OOB_AUTO)
1363 onenand_fill_auto_oob(mtd, this->page_buf, buf, column, thislen);
1364 else
1365 memcpy(this->page_buf + column, buf, thislen);
1111 this->write_bufferram(mtd, ONENAND_SPARERAM, this->page_buf, 0, mtd->oobsize); 1366 this->write_bufferram(mtd, ONENAND_SPARERAM, this->page_buf, 0, mtd->oobsize);
1112 1367
1113 this->command(mtd, ONENAND_CMD_PROGOOB, to, mtd->oobsize); 1368 this->command(mtd, ONENAND_CMD_PROGOOB, to, mtd->oobsize);
@@ -1116,26 +1371,25 @@ static int onenand_do_write_oob(struct mtd_info *mtd, loff_t to, size_t len,
1116 1371
1117 ret = this->wait(mtd, FL_WRITING); 1372 ret = this->wait(mtd, FL_WRITING);
1118 if (ret) { 1373 if (ret) {
1119 DEBUG(MTD_DEBUG_LEVEL0, "onenand_write_oob: write filaed %d\n", ret); 1374 printk(KERN_ERR "onenand_write_oob: write failed %d\n", ret);
1120 goto out; 1375 break;
1121 } 1376 }
1122 1377
1123 ret = onenand_verify_oob(mtd, buf, to, thislen); 1378 ret = onenand_verify_oob(mtd, this->page_buf, to);
1124 if (ret) { 1379 if (ret) {
1125 DEBUG(MTD_DEBUG_LEVEL0, "onenand_write_oob: verify failed %d\n", ret); 1380 printk(KERN_ERR "onenand_write_oob: verify failed %d\n", ret);
1126 goto out; 1381 break;
1127 } 1382 }
1128 1383
1129 written += thislen; 1384 written += thislen;
1130
1131 if (written == len) 1385 if (written == len)
1132 break; 1386 break;
1133 1387
1134 to += thislen; 1388 to += mtd->writesize;
1135 buf += thislen; 1389 buf += thislen;
1390 column = 0;
1136 } 1391 }
1137 1392
1138out:
1139 /* Deselect and wake up anyone waiting on the device */ 1393 /* Deselect and wake up anyone waiting on the device */
1140 onenand_release_device(mtd); 1394 onenand_release_device(mtd);
1141 1395
@@ -1153,10 +1407,17 @@ out:
1153static int onenand_write_oob(struct mtd_info *mtd, loff_t to, 1407static int onenand_write_oob(struct mtd_info *mtd, loff_t to,
1154 struct mtd_oob_ops *ops) 1408 struct mtd_oob_ops *ops)
1155{ 1409{
1156 BUG_ON(ops->mode != MTD_OOB_PLACE); 1410 switch (ops->mode) {
1157 1411 case MTD_OOB_PLACE:
1412 case MTD_OOB_AUTO:
1413 break;
1414 case MTD_OOB_RAW:
1415 /* Not implemented yet */
1416 default:
1417 return -EINVAL;
1418 }
1158 return onenand_do_write_oob(mtd, to + ops->ooboffs, ops->ooblen, 1419 return onenand_do_write_oob(mtd, to + ops->ooboffs, ops->ooblen,
1159 &ops->oobretlen, ops->oobbuf); 1420 &ops->oobretlen, ops->oobbuf, ops->mode);
1160} 1421}
1161 1422
1162/** 1423/**
@@ -1199,19 +1460,19 @@ static int onenand_erase(struct mtd_info *mtd, struct erase_info *instr)
1199 1460
1200 /* Start address must align on block boundary */ 1461 /* Start address must align on block boundary */
1201 if (unlikely(instr->addr & (block_size - 1))) { 1462 if (unlikely(instr->addr & (block_size - 1))) {
1202 DEBUG(MTD_DEBUG_LEVEL0, "onenand_erase: Unaligned address\n"); 1463 printk(KERN_ERR "onenand_erase: Unaligned address\n");
1203 return -EINVAL; 1464 return -EINVAL;
1204 } 1465 }
1205 1466
1206 /* Length must align on block boundary */ 1467 /* Length must align on block boundary */
1207 if (unlikely(instr->len & (block_size - 1))) { 1468 if (unlikely(instr->len & (block_size - 1))) {
1208 DEBUG(MTD_DEBUG_LEVEL0, "onenand_erase: Length not block aligned\n"); 1469 printk(KERN_ERR "onenand_erase: Length not block aligned\n");
1209 return -EINVAL; 1470 return -EINVAL;
1210 } 1471 }
1211 1472
1212 /* Do not allow erase past end of device */ 1473 /* Do not allow erase past end of device */
1213 if (unlikely((instr->len + instr->addr) > mtd->size)) { 1474 if (unlikely((instr->len + instr->addr) > mtd->size)) {
1214 DEBUG(MTD_DEBUG_LEVEL0, "onenand_erase: Erase past end of device\n"); 1475 printk(KERN_ERR "onenand_erase: Erase past end of device\n");
1215 return -EINVAL; 1476 return -EINVAL;
1216 } 1477 }
1217 1478
@@ -1238,10 +1499,12 @@ static int onenand_erase(struct mtd_info *mtd, struct erase_info *instr)
1238 1499
1239 this->command(mtd, ONENAND_CMD_ERASE, addr, block_size); 1500 this->command(mtd, ONENAND_CMD_ERASE, addr, block_size);
1240 1501
1502 onenand_invalidate_bufferram(mtd, addr, block_size);
1503
1241 ret = this->wait(mtd, FL_ERASING); 1504 ret = this->wait(mtd, FL_ERASING);
1242 /* Check, if it is write protected */ 1505 /* Check, if it is write protected */
1243 if (ret) { 1506 if (ret) {
1244 DEBUG(MTD_DEBUG_LEVEL0, "onenand_erase: Failed erase, block %d\n", (unsigned) (addr >> this->erase_shift)); 1507 printk(KERN_ERR "onenand_erase: Failed erase, block %d\n", (unsigned) (addr >> this->erase_shift));
1245 instr->state = MTD_ERASE_FAILED; 1508 instr->state = MTD_ERASE_FAILED;
1246 instr->fail_addr = addr; 1509 instr->fail_addr = addr;
1247 goto erase_exit; 1510 goto erase_exit;
@@ -1322,7 +1585,7 @@ static int onenand_default_block_markbad(struct mtd_info *mtd, loff_t ofs)
1322 1585
1323 /* We write two bytes, so we dont have to mess with 16 bit access */ 1586 /* We write two bytes, so we dont have to mess with 16 bit access */
1324 ofs += mtd->oobsize + (bbm->badblockpos & ~0x01); 1587 ofs += mtd->oobsize + (bbm->badblockpos & ~0x01);
1325 return onenand_do_write_oob(mtd, ofs , 2, &retlen, buf); 1588 return onenand_do_write_oob(mtd, ofs , 2, &retlen, buf, MTD_OOB_PLACE);
1326} 1589}
1327 1590
1328/** 1591/**
@@ -1491,6 +1754,8 @@ static int onenand_unlock_all(struct mtd_info *mtd)
1491 struct onenand_chip *this = mtd->priv; 1754 struct onenand_chip *this = mtd->priv;
1492 1755
1493 if (this->options & ONENAND_HAS_UNLOCK_ALL) { 1756 if (this->options & ONENAND_HAS_UNLOCK_ALL) {
1757 /* Set start block address */
1758 this->write_word(0, this->base + ONENAND_REG_START_BLOCK_ADDRESS);
1494 /* Write unlock command */ 1759 /* Write unlock command */
1495 this->command(mtd, ONENAND_CMD_UNLOCK_ALL, 0, 0); 1760 this->command(mtd, ONENAND_CMD_UNLOCK_ALL, 0, 0);
1496 1761
@@ -1503,13 +1768,10 @@ static int onenand_unlock_all(struct mtd_info *mtd)
1503 continue; 1768 continue;
1504 1769
1505 /* Workaround for all block unlock in DDP */ 1770 /* Workaround for all block unlock in DDP */
1506 if (this->device_id & ONENAND_DEVICE_IS_DDP) { 1771 if (ONENAND_IS_DDP(this)) {
1507 loff_t ofs;
1508 size_t len;
1509
1510 /* 1st block on another chip */ 1772 /* 1st block on another chip */
1511 ofs = this->chipsize >> 1; 1773 loff_t ofs = this->chipsize >> 1;
1512 len = 1 << this->erase_shift; 1774 size_t len = mtd->erasesize;
1513 1775
1514 onenand_unlock(mtd, ofs, len); 1776 onenand_unlock(mtd, ofs, len);
1515 } 1777 }
@@ -1617,7 +1879,7 @@ static int do_otp_lock(struct mtd_info *mtd, loff_t from, size_t len,
1617 this->command(mtd, ONENAND_CMD_OTP_ACCESS, 0, 0); 1879 this->command(mtd, ONENAND_CMD_OTP_ACCESS, 0, 0);
1618 this->wait(mtd, FL_OTPING); 1880 this->wait(mtd, FL_OTPING);
1619 1881
1620 ret = onenand_do_write_oob(mtd, from, len, retlen, buf); 1882 ret = onenand_do_write_oob(mtd, from, len, retlen, buf, MTD_OOB_PLACE);
1621 1883
1622 /* Exit OTP access mode */ 1884 /* Exit OTP access mode */
1623 this->command(mtd, ONENAND_CMD_RESET, 0, 0); 1885 this->command(mtd, ONENAND_CMD_RESET, 0, 0);
@@ -1823,12 +2085,13 @@ static int onenand_lock_user_prot_reg(struct mtd_info *mtd, loff_t from,
1823#endif /* CONFIG_MTD_ONENAND_OTP */ 2085#endif /* CONFIG_MTD_ONENAND_OTP */
1824 2086
1825/** 2087/**
1826 * onenand_lock_scheme - Check and set OneNAND lock scheme 2088 * onenand_check_features - Check and set OneNAND features
1827 * @param mtd MTD data structure 2089 * @param mtd MTD data structure
1828 * 2090 *
1829 * Check and set OneNAND lock scheme 2091 * Check and set OneNAND features
2092 * - lock scheme
1830 */ 2093 */
1831static void onenand_lock_scheme(struct mtd_info *mtd) 2094static void onenand_check_features(struct mtd_info *mtd)
1832{ 2095{
1833 struct onenand_chip *this = mtd->priv; 2096 struct onenand_chip *this = mtd->priv;
1834 unsigned int density, process; 2097 unsigned int density, process;
@@ -1961,26 +2224,28 @@ static int onenand_probe(struct mtd_info *mtd)
1961 density = dev_id >> ONENAND_DEVICE_DENSITY_SHIFT; 2224 density = dev_id >> ONENAND_DEVICE_DENSITY_SHIFT;
1962 this->chipsize = (16 << density) << 20; 2225 this->chipsize = (16 << density) << 20;
1963 /* Set density mask. it is used for DDP */ 2226 /* Set density mask. it is used for DDP */
1964 this->density_mask = (1 << (density + 6)); 2227 if (ONENAND_IS_DDP(this))
2228 this->density_mask = (1 << (density + 6));
2229 else
2230 this->density_mask = 0;
1965 2231
1966 /* OneNAND page size & block size */ 2232 /* OneNAND page size & block size */
1967 /* The data buffer size is equal to page size */ 2233 /* The data buffer size is equal to page size */
1968 mtd->writesize = this->read_word(this->base + ONENAND_REG_DATA_BUFFER_SIZE); 2234 mtd->writesize = this->read_word(this->base + ONENAND_REG_DATA_BUFFER_SIZE);
1969 mtd->oobsize = mtd->writesize >> 5; 2235 mtd->oobsize = mtd->writesize >> 5;
1970 /* Pagers per block is always 64 in OneNAND */ 2236 /* Pages per a block are always 64 in OneNAND */
1971 mtd->erasesize = mtd->writesize << 6; 2237 mtd->erasesize = mtd->writesize << 6;
1972 2238
1973 this->erase_shift = ffs(mtd->erasesize) - 1; 2239 this->erase_shift = ffs(mtd->erasesize) - 1;
1974 this->page_shift = ffs(mtd->writesize) - 1; 2240 this->page_shift = ffs(mtd->writesize) - 1;
1975 this->ppb_shift = (this->erase_shift - this->page_shift); 2241 this->page_mask = (1 << (this->erase_shift - this->page_shift)) - 1;
1976 this->page_mask = (mtd->erasesize / mtd->writesize) - 1;
1977 2242
1978 /* REVIST: Multichip handling */ 2243 /* REVIST: Multichip handling */
1979 2244
1980 mtd->size = this->chipsize; 2245 mtd->size = this->chipsize;
1981 2246
1982 /* Check OneNAND lock scheme */ 2247 /* Check OneNAND features */
1983 onenand_lock_scheme(mtd); 2248 onenand_check_features(mtd);
1984 2249
1985 return 0; 2250 return 0;
1986} 2251}
@@ -2021,6 +2286,7 @@ static void onenand_resume(struct mtd_info *mtd)
2021 */ 2286 */
2022int onenand_scan(struct mtd_info *mtd, int maxchips) 2287int onenand_scan(struct mtd_info *mtd, int maxchips)
2023{ 2288{
2289 int i;
2024 struct onenand_chip *this = mtd->priv; 2290 struct onenand_chip *this = mtd->priv;
2025 2291
2026 if (!this->read_word) 2292 if (!this->read_word)
@@ -2092,12 +2358,21 @@ int onenand_scan(struct mtd_info *mtd, int maxchips)
2092 } 2358 }
2093 2359
2094 this->subpagesize = mtd->writesize >> mtd->subpage_sft; 2360 this->subpagesize = mtd->writesize >> mtd->subpage_sft;
2361
2362 /*
2363 * The number of bytes available for a client to place data into
2364 * the out of band area
2365 */
2366 this->ecclayout->oobavail = 0;
2367 for (i = 0; this->ecclayout->oobfree[i].length; i++)
2368 this->ecclayout->oobavail +=
2369 this->ecclayout->oobfree[i].length;
2370
2095 mtd->ecclayout = this->ecclayout; 2371 mtd->ecclayout = this->ecclayout;
2096 2372
2097 /* Fill in remaining MTD driver data */ 2373 /* Fill in remaining MTD driver data */
2098 mtd->type = MTD_NANDFLASH; 2374 mtd->type = MTD_NANDFLASH;
2099 mtd->flags = MTD_CAP_NANDFLASH; 2375 mtd->flags = MTD_CAP_NANDFLASH;
2100 mtd->ecctype = MTD_ECC_SW;
2101 mtd->erase = onenand_erase; 2376 mtd->erase = onenand_erase;
2102 mtd->point = NULL; 2377 mtd->point = NULL;
2103 mtd->unpoint = NULL; 2378 mtd->unpoint = NULL;
@@ -2144,8 +2419,11 @@ void onenand_release(struct mtd_info *mtd)
2144 del_mtd_device (mtd); 2419 del_mtd_device (mtd);
2145 2420
2146 /* Free bad block table memory, if allocated */ 2421 /* Free bad block table memory, if allocated */
2147 if (this->bbm) 2422 if (this->bbm) {
2423 struct bbm_info *bbm = this->bbm;
2424 kfree(bbm->bbt);
2148 kfree(this->bbm); 2425 kfree(this->bbm);
2426 }
2149 /* Buffer allocated by onenand_scan */ 2427 /* Buffer allocated by onenand_scan */
2150 if (this->options & ONENAND_PAGEBUF_ALLOC) 2428 if (this->options & ONENAND_PAGEBUF_ALLOC)
2151 kfree(this->page_buf); 2429 kfree(this->page_buf);
diff --git a/drivers/mtd/onenand/onenand_bbt.c b/drivers/mtd/onenand/onenand_bbt.c
index 98f8fd1c6375..aecdd50a1781 100644
--- a/drivers/mtd/onenand/onenand_bbt.c
+++ b/drivers/mtd/onenand/onenand_bbt.c
@@ -17,8 +17,8 @@
17#include <linux/mtd/onenand.h> 17#include <linux/mtd/onenand.h>
18#include <linux/mtd/compatmac.h> 18#include <linux/mtd/compatmac.h>
19 19
20extern int onenand_do_read_oob(struct mtd_info *mtd, loff_t from, size_t len, 20extern int onenand_bbt_read_oob(struct mtd_info *mtd, loff_t from,
21 size_t *retlen, u_char *buf); 21 struct mtd_oob_ops *ops);
22 22
23/** 23/**
24 * check_short_pattern - [GENERIC] check if a pattern is in the buffer 24 * check_short_pattern - [GENERIC] check if a pattern is in the buffer
@@ -65,10 +65,11 @@ static int create_bbt(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr
65 int startblock; 65 int startblock;
66 loff_t from; 66 loff_t from;
67 size_t readlen, ooblen; 67 size_t readlen, ooblen;
68 struct mtd_oob_ops ops;
68 69
69 printk(KERN_INFO "Scanning device for bad blocks\n"); 70 printk(KERN_INFO "Scanning device for bad blocks\n");
70 71
71 len = 1; 72 len = 2;
72 73
73 /* We need only read few bytes from the OOB area */ 74 /* We need only read few bytes from the OOB area */
74 scanlen = ooblen = 0; 75 scanlen = ooblen = 0;
@@ -82,22 +83,24 @@ static int create_bbt(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr
82 startblock = 0; 83 startblock = 0;
83 from = 0; 84 from = 0;
84 85
86 ops.mode = MTD_OOB_PLACE;
87 ops.ooblen = readlen;
88 ops.oobbuf = buf;
89 ops.len = ops.ooboffs = ops.retlen = ops.oobretlen = 0;
90
85 for (i = startblock; i < numblocks; ) { 91 for (i = startblock; i < numblocks; ) {
86 int ret; 92 int ret;
87 93
88 for (j = 0; j < len; j++) { 94 for (j = 0; j < len; j++) {
89 size_t retlen;
90
91 /* No need to read pages fully, 95 /* No need to read pages fully,
92 * just read required OOB bytes */ 96 * just read required OOB bytes */
93 ret = onenand_do_read_oob(mtd, from + j * mtd->writesize + bd->offs, 97 ret = onenand_bbt_read_oob(mtd, from + j * mtd->writesize + bd->offs, &ops);
94 readlen, &retlen, &buf[0]);
95 98
96 /* If it is a initial bad block, just ignore it */ 99 /* If it is a initial bad block, just ignore it */
97 if (ret && !(ret & ONENAND_CTRL_LOAD)) 100 if (ret == ONENAND_BBT_READ_FATAL_ERROR)
98 return ret; 101 return -EIO;
99 102
100 if (check_short_pattern(&buf[j * scanlen], scanlen, mtd->writesize, bd)) { 103 if (ret || check_short_pattern(&buf[j * scanlen], scanlen, mtd->writesize, bd)) {
101 bbm->bbt[i >> 3] |= 0x03 << (i & 0x6); 104 bbm->bbt[i >> 3] |= 0x03 << (i & 0x6);
102 printk(KERN_WARNING "Bad eraseblock %d at 0x%08x\n", 105 printk(KERN_WARNING "Bad eraseblock %d at 0x%08x\n",
103 i >> 1, (unsigned int) from); 106 i >> 1, (unsigned int) from);
@@ -168,8 +171,8 @@ static int onenand_isbad_bbt(struct mtd_info *mtd, loff_t offs, int allowbbt)
168 * marked good / bad blocks and writes the bad block table(s) to 171 * marked good / bad blocks and writes the bad block table(s) to
169 * the selected place. 172 * the selected place.
170 * 173 *
171 * The bad block table memory is allocated here. It must be freed 174 * The bad block table memory is allocated here. It is freed
172 * by calling the onenand_free_bbt function. 175 * by the onenand_release function.
173 * 176 *
174 */ 177 */
175int onenand_scan_bbt(struct mtd_info *mtd, struct nand_bbt_descr *bd) 178int onenand_scan_bbt(struct mtd_info *mtd, struct nand_bbt_descr *bd)
diff --git a/drivers/mtd/redboot.c b/drivers/mtd/redboot.c
index 035cd9b0cc08..a61351f88ec0 100644
--- a/drivers/mtd/redboot.c
+++ b/drivers/mtd/redboot.c
@@ -94,8 +94,19 @@ static int parse_redboot_partitions(struct mtd_info *master,
94 * (NOTE: this is 'size' not 'data_length'; size is 94 * (NOTE: this is 'size' not 'data_length'; size is
95 * the full size of the entry.) 95 * the full size of the entry.)
96 */ 96 */
97 if (swab32(buf[i].size) == master->erasesize) { 97
98 /* RedBoot can combine the FIS directory and
99 config partitions into a single eraseblock;
100 we assume wrong-endian if either the swapped
101 'size' matches the eraseblock size precisely,
102 or if the swapped size actually fits in an
103 eraseblock while the unswapped size doesn't. */
104 if (swab32(buf[i].size) == master->erasesize ||
105 (buf[i].size > master->erasesize
106 && swab32(buf[i].size) < master->erasesize)) {
98 int j; 107 int j;
108 /* Update numslots based on actual FIS directory size */
109 numslots = swab32(buf[i].size) / sizeof (struct fis_image_desc);
99 for (j = 0; j < numslots; ++j) { 110 for (j = 0; j < numslots; ++j) {
100 111
101 /* A single 0xff denotes a deleted entry. 112 /* A single 0xff denotes a deleted entry.
@@ -120,11 +131,11 @@ static int parse_redboot_partitions(struct mtd_info *master,
120 swab32s(&buf[j].desc_cksum); 131 swab32s(&buf[j].desc_cksum);
121 swab32s(&buf[j].file_cksum); 132 swab32s(&buf[j].file_cksum);
122 } 133 }
134 } else if (buf[i].size < master->erasesize) {
135 /* Update numslots based on actual FIS directory size */
136 numslots = buf[i].size / sizeof(struct fis_image_desc);
123 } 137 }
124 break; 138 break;
125 } else {
126 /* re-calculate of real numslots */
127 numslots = buf[i].size / sizeof(struct fis_image_desc);
128 } 139 }
129 } 140 }
130 if (i == numslots) { 141 if (i == numslots) {
diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
index 38f41a593b12..d9400ef87195 100644
--- a/drivers/net/Kconfig
+++ b/drivers/net/Kconfig
@@ -1284,8 +1284,8 @@ config PCNET32
1284 will be called pcnet32. 1284 will be called pcnet32.
1285 1285
1286config PCNET32_NAPI 1286config PCNET32_NAPI
1287 bool "Use RX polling (NAPI) (EXPERIMENTAL)" 1287 bool "Use RX polling (NAPI)"
1288 depends on PCNET32 && EXPERIMENTAL 1288 depends on PCNET32
1289 help 1289 help
1290 NAPI is a new driver API designed to reduce CPU and interrupt load 1290 NAPI is a new driver API designed to reduce CPU and interrupt load
1291 when the driver is receiving lots of packets from the card. It is 1291 when the driver is receiving lots of packets from the card. It is
@@ -2125,14 +2125,16 @@ config SKY2
2125 will be called sky2. This is recommended. 2125 will be called sky2. This is recommended.
2126 2126
2127config SK98LIN 2127config SK98LIN
2128 tristate "Marvell Yukon Chipset / SysKonnect SK-98xx Support" 2128 tristate "Marvell Yukon Chipset / SysKonnect SK-98xx Support (DEPRECATED)"
2129 depends on PCI 2129 depends on PCI
2130 ---help--- 2130 ---help---
2131 Say Y here if you have a Marvell Yukon or SysKonnect SK-98xx/SK-95xx 2131 Say Y here if you have a Marvell Yukon or SysKonnect SK-98xx/SK-95xx
2132 compliant Gigabit Ethernet Adapter. 2132 compliant Gigabit Ethernet Adapter.
2133 2133
2134 This driver supports the original Yukon chipset. A cleaner driver is 2134 This driver supports the original Yukon chipset. This driver is
2135 also available (skge) which seems to work better than this one. 2135 deprecated and will be removed from the kernel in the near future,
2136 it has been replaced by the skge driver. skge is cleaner and
2137 seems to work better.
2136 2138
2137 This driver does not support the newer Yukon2 chipset. A separate 2139 This driver does not support the newer Yukon2 chipset. A separate
2138 driver, sky2, is provided to support Yukon2-based adapters. 2140 driver, sky2, is provided to support Yukon2-based adapters.
@@ -2337,7 +2339,7 @@ config QLA3XXX
2337 2339
2338config ATL1 2340config ATL1
2339 tristate "Attansic L1 Gigabit Ethernet support (EXPERIMENTAL)" 2341 tristate "Attansic L1 Gigabit Ethernet support (EXPERIMENTAL)"
2340 depends on NET_PCI && PCI && EXPERIMENTAL 2342 depends on PCI && EXPERIMENTAL
2341 select CRC32 2343 select CRC32
2342 select MII 2344 select MII
2343 help 2345 help
diff --git a/drivers/net/arcnet/arc-rawmode.c b/drivers/net/arcnet/arc-rawmode.c
index e7555d4e6ff1..6318814a11a8 100644
--- a/drivers/net/arcnet/arc-rawmode.c
+++ b/drivers/net/arcnet/arc-rawmode.c
@@ -94,7 +94,7 @@ static void rx(struct net_device *dev, int bufnum,
94 94
95 BUGMSG(D_DURING, "it's a raw packet (length=%d)\n", length); 95 BUGMSG(D_DURING, "it's a raw packet (length=%d)\n", length);
96 96
97 if (length >= MinTU) 97 if (length > MTU)
98 ofs = 512 - length; 98 ofs = 512 - length;
99 else 99 else
100 ofs = 256 - length; 100 ofs = 256 - length;
@@ -183,7 +183,7 @@ static int prepare_tx(struct net_device *dev, struct archdr *pkt, int length,
183 length, XMTU); 183 length, XMTU);
184 length = XMTU; 184 length = XMTU;
185 } 185 }
186 if (length > MinTU) { 186 if (length >= MinTU) {
187 hard->offset[0] = 0; 187 hard->offset[0] = 0;
188 hard->offset[1] = ofs = 512 - length; 188 hard->offset[1] = ofs = 512 - length;
189 } else if (length > MTU) { 189 } else if (length > MTU) {
diff --git a/drivers/net/arcnet/arcnet.c b/drivers/net/arcnet/arcnet.c
index 4e91dab1f17f..83004fdab0a4 100644
--- a/drivers/net/arcnet/arcnet.c
+++ b/drivers/net/arcnet/arcnet.c
@@ -41,7 +41,7 @@
41 * <jojo@repas.de> 41 * <jojo@repas.de>
42 */ 42 */
43 43
44#define VERSION "arcnet: v3.93 BETA 2000/04/29 - by Avery Pennarun et al.\n" 44#define VERSION "arcnet: v3.94 BETA 2007/02/08 - by Avery Pennarun et al.\n"
45 45
46#include <linux/module.h> 46#include <linux/module.h>
47#include <linux/types.h> 47#include <linux/types.h>
diff --git a/drivers/net/arcnet/com20020-pci.c b/drivers/net/arcnet/com20020-pci.c
index 98d326b23c92..b8c0fa6d401d 100644
--- a/drivers/net/arcnet/com20020-pci.c
+++ b/drivers/net/arcnet/com20020-pci.c
@@ -155,6 +155,7 @@ static struct pci_device_id com20020pci_id_table[] = {
155 { 0x1571, 0xa00b, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ARC_IS_5MBIT }, 155 { 0x1571, 0xa00b, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ARC_IS_5MBIT },
156 { 0x1571, 0xa00c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ARC_IS_5MBIT }, 156 { 0x1571, 0xa00c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ARC_IS_5MBIT },
157 { 0x1571, 0xa00d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ARC_IS_5MBIT }, 157 { 0x1571, 0xa00d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ARC_IS_5MBIT },
158 { 0x1571, 0xa00e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ARC_IS_5MBIT },
158 { 0x1571, 0xa201, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ARC_CAN_10MBIT }, 159 { 0x1571, 0xa201, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ARC_CAN_10MBIT },
159 { 0x1571, 0xa202, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ARC_CAN_10MBIT }, 160 { 0x1571, 0xa202, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ARC_CAN_10MBIT },
160 { 0x1571, 0xa203, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ARC_CAN_10MBIT }, 161 { 0x1571, 0xa203, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ARC_CAN_10MBIT },
@@ -163,6 +164,8 @@ static struct pci_device_id com20020pci_id_table[] = {
163 { 0x1571, 0xa206, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ARC_CAN_10MBIT }, 164 { 0x1571, 0xa206, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ARC_CAN_10MBIT },
164 { 0x10B5, 0x9030, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ARC_CAN_10MBIT }, 165 { 0x10B5, 0x9030, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ARC_CAN_10MBIT },
165 { 0x10B5, 0x9050, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ARC_CAN_10MBIT }, 166 { 0x10B5, 0x9050, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ARC_CAN_10MBIT },
167 { 0x14BA, 0x6000, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ARC_CAN_10MBIT },
168 { 0x10B5, 0x2200, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ARC_CAN_10MBIT },
166 {0,} 169 {0,}
167}; 170};
168 171
diff --git a/drivers/net/arcnet/com20020.c b/drivers/net/arcnet/com20020.c
index 4218075c8aa3..7cf0a2511697 100644
--- a/drivers/net/arcnet/com20020.c
+++ b/drivers/net/arcnet/com20020.c
@@ -104,7 +104,7 @@ int com20020_check(struct net_device *dev)
104 SET_SUBADR(SUB_SETUP1); 104 SET_SUBADR(SUB_SETUP1);
105 outb(lp->setup, _XREG); 105 outb(lp->setup, _XREG);
106 106
107 if (lp->card_flags & ARC_CAN_10MBIT) 107 if (lp->clockm != 0)
108 { 108 {
109 SET_SUBADR(SUB_SETUP2); 109 SET_SUBADR(SUB_SETUP2);
110 outb(lp->setup2, _XREG); 110 outb(lp->setup2, _XREG);
diff --git a/drivers/net/atl1/atl1_hw.c b/drivers/net/atl1/atl1_hw.c
index 08b2d785469d..314dbaabb642 100644
--- a/drivers/net/atl1/atl1_hw.c
+++ b/drivers/net/atl1/atl1_hw.c
@@ -243,14 +243,8 @@ static int atl1_get_permanent_address(struct atl1_hw *hw)
243 i += 4; 243 i += 4;
244 } 244 }
245 245
246/* 246 *(u32 *) &eth_addr[2] = swab32(addr[0]);
247 * The following 2 lines are the Attansic originals. Saving for posterity. 247 *(u16 *) &eth_addr[0] = swab16(*(u16 *) &addr[1]);
248 * *(u32 *) & eth_addr[2] = LONGSWAP(addr[0]);
249 * *(u16 *) & eth_addr[0] = SHORTSWAP(*(u16 *) & addr[1]);
250 */
251 *(u32 *) & eth_addr[2] = swab32(addr[0]);
252 *(u16 *) & eth_addr[0] = swab16(*(u16 *) & addr[1]);
253
254 if (is_valid_ether_addr(eth_addr)) { 248 if (is_valid_ether_addr(eth_addr)) {
255 memcpy(hw->perm_mac_addr, eth_addr, ETH_ALEN); 249 memcpy(hw->perm_mac_addr, eth_addr, ETH_ALEN);
256 return 0; 250 return 0;
@@ -281,17 +275,28 @@ static int atl1_get_permanent_address(struct atl1_hw *hw)
281 i += 4; 275 i += 4;
282 } 276 }
283 277
284/* 278 *(u32 *) &eth_addr[2] = swab32(addr[0]);
285 * The following 2 lines are the Attansic originals. Saving for posterity. 279 *(u16 *) &eth_addr[0] = swab16(*(u16 *) &addr[1]);
286 * *(u32 *) & eth_addr[2] = LONGSWAP(addr[0]);
287 * *(u16 *) & eth_addr[0] = SHORTSWAP(*(u16 *) & addr[1]);
288 */
289 *(u32 *) & eth_addr[2] = swab32(addr[0]);
290 *(u16 *) & eth_addr[0] = swab16(*(u16 *) & addr[1]);
291 if (is_valid_ether_addr(eth_addr)) { 280 if (is_valid_ether_addr(eth_addr)) {
292 memcpy(hw->perm_mac_addr, eth_addr, ETH_ALEN); 281 memcpy(hw->perm_mac_addr, eth_addr, ETH_ALEN);
293 return 0; 282 return 0;
294 } 283 }
284
285 /*
286 * On some motherboards, the MAC address is written by the
287 * BIOS directly to the MAC register during POST, and is
288 * not stored in eeprom. If all else thus far has failed
289 * to fetch the permanent MAC address, try reading it directly.
290 */
291 addr[0] = ioread32(hw->hw_addr + REG_MAC_STA_ADDR);
292 addr[1] = ioread16(hw->hw_addr + (REG_MAC_STA_ADDR + 4));
293 *(u32 *) &eth_addr[2] = swab32(addr[0]);
294 *(u16 *) &eth_addr[0] = swab16(*(u16 *) &addr[1]);
295 if (is_valid_ether_addr(eth_addr)) {
296 memcpy(hw->perm_mac_addr, eth_addr, ETH_ALEN);
297 return 0;
298 }
299
295 return 1; 300 return 1;
296} 301}
297 302
@@ -357,7 +362,7 @@ void atl1_hash_set(struct atl1_hw *hw, u32 hash_value)
357 */ 362 */
358 hash_reg = (hash_value >> 31) & 0x1; 363 hash_reg = (hash_value >> 31) & 0x1;
359 hash_bit = (hash_value >> 26) & 0x1F; 364 hash_bit = (hash_value >> 26) & 0x1F;
360 mta = ioread32((hw + REG_RX_HASH_TABLE) + (hash_reg << 2)); 365 mta = ioread32((hw->hw_addr + REG_RX_HASH_TABLE) + (hash_reg << 2));
361 mta |= (1 << hash_bit); 366 mta |= (1 << hash_bit);
362 iowrite32(mta, (hw->hw_addr + REG_RX_HASH_TABLE) + (hash_reg << 2)); 367 iowrite32(mta, (hw->hw_addr + REG_RX_HASH_TABLE) + (hash_reg << 2));
363} 368}
diff --git a/drivers/net/atl1/atl1_main.c b/drivers/net/atl1/atl1_main.c
index 6655640eb4ca..65673485bb6b 100644
--- a/drivers/net/atl1/atl1_main.c
+++ b/drivers/net/atl1/atl1_main.c
@@ -82,8 +82,7 @@
82 82
83#include "atl1.h" 83#include "atl1.h"
84 84
85#define RUN_REALTIME 0 85#define DRIVER_VERSION "2.0.7"
86#define DRIVER_VERSION "2.0.6"
87 86
88char atl1_driver_name[] = "atl1"; 87char atl1_driver_name[] = "atl1";
89static const char atl1_driver_string[] = "Attansic L1 Ethernet Network Driver"; 88static const char atl1_driver_string[] = "Attansic L1 Ethernet Network Driver";
@@ -100,7 +99,7 @@ MODULE_VERSION(DRIVER_VERSION);
100 * atl1_pci_tbl - PCI Device ID Table 99 * atl1_pci_tbl - PCI Device ID Table
101 */ 100 */
102static const struct pci_device_id atl1_pci_tbl[] = { 101static const struct pci_device_id atl1_pci_tbl[] = {
103 {PCI_DEVICE(PCI_VENDOR_ID_ATTANSIC, 0x1048)}, 102 {PCI_DEVICE(PCI_VENDOR_ID_ATTANSIC, PCI_DEVICE_ID_ATTANSIC_L1)},
104 /* required last entry */ 103 /* required last entry */
105 {0,} 104 {0,}
106}; 105};
diff --git a/drivers/net/b44.c b/drivers/net/b44.c
index 5ff7882297d6..aaada572732a 100644
--- a/drivers/net/b44.c
+++ b/drivers/net/b44.c
@@ -59,7 +59,6 @@
59#define B44_DEF_TX_RING_PENDING (B44_TX_RING_SIZE - 1) 59#define B44_DEF_TX_RING_PENDING (B44_TX_RING_SIZE - 1)
60#define B44_TX_RING_BYTES (sizeof(struct dma_desc) * \ 60#define B44_TX_RING_BYTES (sizeof(struct dma_desc) * \
61 B44_TX_RING_SIZE) 61 B44_TX_RING_SIZE)
62#define B44_DMA_MASK 0x3fffffff
63 62
64#define TX_RING_GAP(BP) \ 63#define TX_RING_GAP(BP) \
65 (B44_TX_RING_SIZE - (BP)->tx_pending) 64 (B44_TX_RING_SIZE - (BP)->tx_pending)
@@ -665,7 +664,7 @@ static int b44_alloc_rx_skb(struct b44 *bp, int src_idx, u32 dest_idx_unmasked)
665 /* Hardware bug work-around, the chip is unable to do PCI DMA 664 /* Hardware bug work-around, the chip is unable to do PCI DMA
666 to/from anything above 1GB :-( */ 665 to/from anything above 1GB :-( */
667 if (dma_mapping_error(mapping) || 666 if (dma_mapping_error(mapping) ||
668 mapping + RX_PKT_BUF_SZ > B44_DMA_MASK) { 667 mapping + RX_PKT_BUF_SZ > DMA_30BIT_MASK) {
669 /* Sigh... */ 668 /* Sigh... */
670 if (!dma_mapping_error(mapping)) 669 if (!dma_mapping_error(mapping))
671 pci_unmap_single(bp->pdev, mapping, RX_PKT_BUF_SZ,PCI_DMA_FROMDEVICE); 670 pci_unmap_single(bp->pdev, mapping, RX_PKT_BUF_SZ,PCI_DMA_FROMDEVICE);
@@ -677,7 +676,7 @@ static int b44_alloc_rx_skb(struct b44 *bp, int src_idx, u32 dest_idx_unmasked)
677 RX_PKT_BUF_SZ, 676 RX_PKT_BUF_SZ,
678 PCI_DMA_FROMDEVICE); 677 PCI_DMA_FROMDEVICE);
679 if (dma_mapping_error(mapping) || 678 if (dma_mapping_error(mapping) ||
680 mapping + RX_PKT_BUF_SZ > B44_DMA_MASK) { 679 mapping + RX_PKT_BUF_SZ > DMA_30BIT_MASK) {
681 if (!dma_mapping_error(mapping)) 680 if (!dma_mapping_error(mapping))
682 pci_unmap_single(bp->pdev, mapping, RX_PKT_BUF_SZ,PCI_DMA_FROMDEVICE); 681 pci_unmap_single(bp->pdev, mapping, RX_PKT_BUF_SZ,PCI_DMA_FROMDEVICE);
683 dev_kfree_skb_any(skb); 682 dev_kfree_skb_any(skb);
@@ -988,7 +987,7 @@ static int b44_start_xmit(struct sk_buff *skb, struct net_device *dev)
988 } 987 }
989 988
990 mapping = pci_map_single(bp->pdev, skb->data, len, PCI_DMA_TODEVICE); 989 mapping = pci_map_single(bp->pdev, skb->data, len, PCI_DMA_TODEVICE);
991 if (dma_mapping_error(mapping) || mapping + len > B44_DMA_MASK) { 990 if (dma_mapping_error(mapping) || mapping + len > DMA_30BIT_MASK) {
992 /* Chip can't handle DMA to/from >1GB, use bounce buffer */ 991 /* Chip can't handle DMA to/from >1GB, use bounce buffer */
993 if (!dma_mapping_error(mapping)) 992 if (!dma_mapping_error(mapping))
994 pci_unmap_single(bp->pdev, mapping, len, PCI_DMA_TODEVICE); 993 pci_unmap_single(bp->pdev, mapping, len, PCI_DMA_TODEVICE);
@@ -1000,7 +999,7 @@ static int b44_start_xmit(struct sk_buff *skb, struct net_device *dev)
1000 999
1001 mapping = pci_map_single(bp->pdev, bounce_skb->data, 1000 mapping = pci_map_single(bp->pdev, bounce_skb->data,
1002 len, PCI_DMA_TODEVICE); 1001 len, PCI_DMA_TODEVICE);
1003 if (dma_mapping_error(mapping) || mapping + len > B44_DMA_MASK) { 1002 if (dma_mapping_error(mapping) || mapping + len > DMA_30BIT_MASK) {
1004 if (!dma_mapping_error(mapping)) 1003 if (!dma_mapping_error(mapping))
1005 pci_unmap_single(bp->pdev, mapping, 1004 pci_unmap_single(bp->pdev, mapping,
1006 len, PCI_DMA_TODEVICE); 1005 len, PCI_DMA_TODEVICE);
@@ -1227,7 +1226,7 @@ static int b44_alloc_consistent(struct b44 *bp)
1227 DMA_BIDIRECTIONAL); 1226 DMA_BIDIRECTIONAL);
1228 1227
1229 if (dma_mapping_error(rx_ring_dma) || 1228 if (dma_mapping_error(rx_ring_dma) ||
1230 rx_ring_dma + size > B44_DMA_MASK) { 1229 rx_ring_dma + size > DMA_30BIT_MASK) {
1231 kfree(rx_ring); 1230 kfree(rx_ring);
1232 goto out_err; 1231 goto out_err;
1233 } 1232 }
@@ -1254,7 +1253,7 @@ static int b44_alloc_consistent(struct b44 *bp)
1254 DMA_TO_DEVICE); 1253 DMA_TO_DEVICE);
1255 1254
1256 if (dma_mapping_error(tx_ring_dma) || 1255 if (dma_mapping_error(tx_ring_dma) ||
1257 tx_ring_dma + size > B44_DMA_MASK) { 1256 tx_ring_dma + size > DMA_30BIT_MASK) {
1258 kfree(tx_ring); 1257 kfree(tx_ring);
1259 goto out_err; 1258 goto out_err;
1260 } 1259 }
@@ -1289,7 +1288,7 @@ static void b44_chip_reset(struct b44 *bp)
1289 if (ssb_is_core_up(bp)) { 1288 if (ssb_is_core_up(bp)) {
1290 bw32(bp, B44_RCV_LAZY, 0); 1289 bw32(bp, B44_RCV_LAZY, 0);
1291 bw32(bp, B44_ENET_CTRL, ENET_CTRL_DISABLE); 1290 bw32(bp, B44_ENET_CTRL, ENET_CTRL_DISABLE);
1292 b44_wait_bit(bp, B44_ENET_CTRL, ENET_CTRL_DISABLE, 100, 1); 1291 b44_wait_bit(bp, B44_ENET_CTRL, ENET_CTRL_DISABLE, 200, 1);
1293 bw32(bp, B44_DMATX_CTRL, 0); 1292 bw32(bp, B44_DMATX_CTRL, 0);
1294 bp->tx_prod = bp->tx_cons = 0; 1293 bp->tx_prod = bp->tx_cons = 0;
1295 if (br32(bp, B44_DMARX_STAT) & DMARX_STAT_EMASK) { 1294 if (br32(bp, B44_DMARX_STAT) & DMARX_STAT_EMASK) {
@@ -2151,13 +2150,13 @@ static int __devinit b44_init_one(struct pci_dev *pdev,
2151 2150
2152 pci_set_master(pdev); 2151 pci_set_master(pdev);
2153 2152
2154 err = pci_set_dma_mask(pdev, (u64) B44_DMA_MASK); 2153 err = pci_set_dma_mask(pdev, (u64) DMA_30BIT_MASK);
2155 if (err) { 2154 if (err) {
2156 dev_err(&pdev->dev, "No usable DMA configuration, aborting.\n"); 2155 dev_err(&pdev->dev, "No usable DMA configuration, aborting.\n");
2157 goto err_out_free_res; 2156 goto err_out_free_res;
2158 } 2157 }
2159 2158
2160 err = pci_set_consistent_dma_mask(pdev, (u64) B44_DMA_MASK); 2159 err = pci_set_consistent_dma_mask(pdev, (u64) DMA_30BIT_MASK);
2161 if (err) { 2160 if (err) {
2162 dev_err(&pdev->dev, "No usable DMA configuration, aborting.\n"); 2161 dev_err(&pdev->dev, "No usable DMA configuration, aborting.\n");
2163 goto err_out_free_res; 2162 goto err_out_free_res;
diff --git a/drivers/net/cxgb3/cxgb3_defs.h b/drivers/net/cxgb3/cxgb3_defs.h
index 16e004990c59..e14862b43d17 100644
--- a/drivers/net/cxgb3/cxgb3_defs.h
+++ b/drivers/net/cxgb3/cxgb3_defs.h
@@ -1,6 +1,5 @@
1/* 1/*
2 * Copyright (c) 2006-2007 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2006-2007 Chelsio, Inc. All rights reserved.
3 * Copyright (c) 2006-2007 Open Grid Computing, Inc. All rights reserved.
4 * 3 *
5 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
diff --git a/drivers/net/cxgb3/cxgb3_offload.c b/drivers/net/cxgb3/cxgb3_offload.c
index c6b726643185..b2cf5f6feb4a 100644
--- a/drivers/net/cxgb3/cxgb3_offload.c
+++ b/drivers/net/cxgb3/cxgb3_offload.c
@@ -1,6 +1,5 @@
1/* 1/*
2 * Copyright (c) 2006-2007 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2006-2007 Chelsio, Inc. All rights reserved.
3 * Copyright (c) 2006-2007 Open Grid Computing, Inc. All rights reserved.
4 * 3 *
5 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
diff --git a/drivers/net/cxgb3/cxgb3_offload.h b/drivers/net/cxgb3/cxgb3_offload.h
index 0e6beb69ba17..f15446a32efc 100644
--- a/drivers/net/cxgb3/cxgb3_offload.h
+++ b/drivers/net/cxgb3/cxgb3_offload.h
@@ -1,6 +1,5 @@
1/* 1/*
2 * Copyright (c) 2006-2007 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2006-2007 Chelsio, Inc. All rights reserved.
3 * Copyright (c) 2006-2007 Open Grid Computing, Inc. All rights reserved.
4 * 3 *
5 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
diff --git a/drivers/net/cxgb3/l2t.c b/drivers/net/cxgb3/l2t.c
index 3c0cb8557058..d660af74606e 100644
--- a/drivers/net/cxgb3/l2t.c
+++ b/drivers/net/cxgb3/l2t.c
@@ -1,6 +1,5 @@
1/* 1/*
2 * Copyright (c) 2003-2007 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2003-2007 Chelsio, Inc. All rights reserved.
3 * Copyright (c) 2006-2007 Open Grid Computing, Inc. All rights reserved.
4 * 3 *
5 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
diff --git a/drivers/net/cxgb3/l2t.h b/drivers/net/cxgb3/l2t.h
index ba5d2cbd7241..d79001336cfd 100644
--- a/drivers/net/cxgb3/l2t.h
+++ b/drivers/net/cxgb3/l2t.h
@@ -1,6 +1,5 @@
1/* 1/*
2 * Copyright (c) 2003-2007 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2003-2007 Chelsio, Inc. All rights reserved.
3 * Copyright (c) 2006-2007 Open Grid Computing, Inc. All rights reserved.
4 * 3 *
5 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
diff --git a/drivers/net/cxgb3/t3cdev.h b/drivers/net/cxgb3/t3cdev.h
index 9af3bcd64b3b..fa4099bc0416 100644
--- a/drivers/net/cxgb3/t3cdev.h
+++ b/drivers/net/cxgb3/t3cdev.h
@@ -1,6 +1,5 @@
1/* 1/*
2 * Copyright (C) 2006-2007 Chelsio Communications. All rights reserved. 2 * Copyright (C) 2006-2007 Chelsio Communications. All rights reserved.
3 * Copyright (C) 2006-2007 Open Grid Computing, Inc. All rights reserved.
4 * 3 *
5 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
diff --git a/drivers/net/e1000/e1000.h b/drivers/net/e1000/e1000.h
index 689f158a469e..dd4b728ac4b5 100644
--- a/drivers/net/e1000/e1000.h
+++ b/drivers/net/e1000/e1000.h
@@ -337,7 +337,6 @@ struct e1000_adapter {
337 struct e1000_rx_ring test_rx_ring; 337 struct e1000_rx_ring test_rx_ring;
338 338
339 339
340 uint32_t *config_space;
341 int msg_enable; 340 int msg_enable;
342#ifdef CONFIG_PCI_MSI 341#ifdef CONFIG_PCI_MSI
343 boolean_t have_msi; 342 boolean_t have_msi;
diff --git a/drivers/net/e1000/e1000_ethtool.c b/drivers/net/e1000/e1000_ethtool.c
index 44ebc72962dc..6777887295f5 100644
--- a/drivers/net/e1000/e1000_ethtool.c
+++ b/drivers/net/e1000/e1000_ethtool.c
@@ -166,7 +166,7 @@ e1000_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
166 ecmd->transceiver = XCVR_EXTERNAL; 166 ecmd->transceiver = XCVR_EXTERNAL;
167 } 167 }
168 168
169 if (netif_carrier_ok(adapter->netdev)) { 169 if (E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_LU) {
170 170
171 e1000_get_speed_and_duplex(hw, &adapter->link_speed, 171 e1000_get_speed_and_duplex(hw, &adapter->link_speed,
172 &adapter->link_duplex); 172 &adapter->link_duplex);
diff --git a/drivers/net/e1000/e1000_hw.h b/drivers/net/e1000/e1000_hw.h
index d67105883341..bd000b802ee7 100644
--- a/drivers/net/e1000/e1000_hw.h
+++ b/drivers/net/e1000/e1000_hw.h
@@ -3253,7 +3253,7 @@ struct e1000_host_command_info {
3253#define IFE_PMC_AUTO_MDIX 0x0080 /* 1=enable MDI/MDI-X feature, default 0=disabled */ 3253#define IFE_PMC_AUTO_MDIX 0x0080 /* 1=enable MDI/MDI-X feature, default 0=disabled */
3254#define IFE_PMC_FORCE_MDIX 0x0040 /* 1=force MDIX-X, 0=force MDI */ 3254#define IFE_PMC_FORCE_MDIX 0x0040 /* 1=force MDIX-X, 0=force MDI */
3255#define IFE_PMC_MDIX_STATUS 0x0020 /* 1=MDI-X, 0=MDI */ 3255#define IFE_PMC_MDIX_STATUS 0x0020 /* 1=MDI-X, 0=MDI */
3256#define IFE_PMC_AUTO_MDIX_COMPLETE 0x0010 /* Resolution algorthm is completed */ 3256#define IFE_PMC_AUTO_MDIX_COMPLETE 0x0010 /* Resolution algorithm is completed */
3257#define IFE_PMC_MDIX_MODE_SHIFT 6 3257#define IFE_PMC_MDIX_MODE_SHIFT 6
3258#define IFE_PHC_MDIX_RESET_ALL_MASK 0x0000 /* Disable auto MDI-X */ 3258#define IFE_PHC_MDIX_RESET_ALL_MASK 0x0000 /* Disable auto MDI-X */
3259 3259
diff --git a/drivers/net/e1000/e1000_main.c b/drivers/net/e1000/e1000_main.c
index 619c89218b4b..a71023741c3a 100644
--- a/drivers/net/e1000/e1000_main.c
+++ b/drivers/net/e1000/e1000_main.c
@@ -1417,10 +1417,6 @@ e1000_open(struct net_device *netdev)
1417 if ((err = e1000_setup_all_rx_resources(adapter))) 1417 if ((err = e1000_setup_all_rx_resources(adapter)))
1418 goto err_setup_rx; 1418 goto err_setup_rx;
1419 1419
1420 err = e1000_request_irq(adapter);
1421 if (err)
1422 goto err_req_irq;
1423
1424 e1000_power_up_phy(adapter); 1420 e1000_power_up_phy(adapter);
1425 1421
1426 if ((err = e1000_up(adapter))) 1422 if ((err = e1000_up(adapter)))
@@ -1431,6 +1427,10 @@ e1000_open(struct net_device *netdev)
1431 e1000_update_mng_vlan(adapter); 1427 e1000_update_mng_vlan(adapter);
1432 } 1428 }
1433 1429
1430 err = e1000_request_irq(adapter);
1431 if (err)
1432 goto err_req_irq;
1433
1434 /* If AMT is enabled, let the firmware know that the network 1434 /* If AMT is enabled, let the firmware know that the network
1435 * interface is now open */ 1435 * interface is now open */
1436 if (adapter->hw.mac_type == e1000_82573 && 1436 if (adapter->hw.mac_type == e1000_82573 &&
@@ -1439,10 +1439,10 @@ e1000_open(struct net_device *netdev)
1439 1439
1440 return E1000_SUCCESS; 1440 return E1000_SUCCESS;
1441 1441
1442err_req_irq:
1443 e1000_down(adapter);
1442err_up: 1444err_up:
1443 e1000_power_down_phy(adapter); 1445 e1000_power_down_phy(adapter);
1444 e1000_free_irq(adapter);
1445err_req_irq:
1446 e1000_free_all_rx_resources(adapter); 1446 e1000_free_all_rx_resources(adapter);
1447err_setup_rx: 1447err_setup_rx:
1448 e1000_free_all_tx_resources(adapter); 1448 e1000_free_all_tx_resources(adapter);
@@ -5071,58 +5071,6 @@ e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx)
5071 return 0; 5071 return 0;
5072} 5072}
5073 5073
5074#ifdef CONFIG_PM
5075/* Save/restore 16 or 64 dwords of PCI config space depending on which
5076 * bus we're on (PCI(X) vs. PCI-E)
5077 */
5078#define PCIE_CONFIG_SPACE_LEN 256
5079#define PCI_CONFIG_SPACE_LEN 64
5080static int
5081e1000_pci_save_state(struct e1000_adapter *adapter)
5082{
5083 struct pci_dev *dev = adapter->pdev;
5084 int size;
5085 int i;
5086
5087 if (adapter->hw.mac_type >= e1000_82571)
5088 size = PCIE_CONFIG_SPACE_LEN;
5089 else
5090 size = PCI_CONFIG_SPACE_LEN;
5091
5092 WARN_ON(adapter->config_space != NULL);
5093
5094 adapter->config_space = kmalloc(size, GFP_KERNEL);
5095 if (!adapter->config_space) {
5096 DPRINTK(PROBE, ERR, "unable to allocate %d bytes\n", size);
5097 return -ENOMEM;
5098 }
5099 for (i = 0; i < (size / 4); i++)
5100 pci_read_config_dword(dev, i * 4, &adapter->config_space[i]);
5101 return 0;
5102}
5103
5104static void
5105e1000_pci_restore_state(struct e1000_adapter *adapter)
5106{
5107 struct pci_dev *dev = adapter->pdev;
5108 int size;
5109 int i;
5110
5111 if (adapter->config_space == NULL)
5112 return;
5113
5114 if (adapter->hw.mac_type >= e1000_82571)
5115 size = PCIE_CONFIG_SPACE_LEN;
5116 else
5117 size = PCI_CONFIG_SPACE_LEN;
5118 for (i = 0; i < (size / 4); i++)
5119 pci_write_config_dword(dev, i * 4, adapter->config_space[i]);
5120 kfree(adapter->config_space);
5121 adapter->config_space = NULL;
5122 return;
5123}
5124#endif /* CONFIG_PM */
5125
5126static int 5074static int
5127e1000_suspend(struct pci_dev *pdev, pm_message_t state) 5075e1000_suspend(struct pci_dev *pdev, pm_message_t state)
5128{ 5076{
@@ -5142,9 +5090,7 @@ e1000_suspend(struct pci_dev *pdev, pm_message_t state)
5142 } 5090 }
5143 5091
5144#ifdef CONFIG_PM 5092#ifdef CONFIG_PM
5145 /* Implement our own version of pci_save_state(pdev) because pci- 5093 retval = pci_save_state(pdev);
5146 * express adapters have 256-byte config spaces. */
5147 retval = e1000_pci_save_state(adapter);
5148 if (retval) 5094 if (retval)
5149 return retval; 5095 return retval;
5150#endif 5096#endif
@@ -5231,7 +5177,7 @@ e1000_resume(struct pci_dev *pdev)
5231 uint32_t err; 5177 uint32_t err;
5232 5178
5233 pci_set_power_state(pdev, PCI_D0); 5179 pci_set_power_state(pdev, PCI_D0);
5234 e1000_pci_restore_state(adapter); 5180 pci_restore_state(pdev);
5235 if ((err = pci_enable_device(pdev))) { 5181 if ((err = pci_enable_device(pdev))) {
5236 printk(KERN_ERR "e1000: Cannot enable PCI device from suspend\n"); 5182 printk(KERN_ERR "e1000: Cannot enable PCI device from suspend\n");
5237 return err; 5183 return err;
diff --git a/drivers/net/eexpress.c b/drivers/net/eexpress.c
index 4a50fcb5ad6b..3868b8031266 100644
--- a/drivers/net/eexpress.c
+++ b/drivers/net/eexpress.c
@@ -714,13 +714,6 @@ static int eexp_xmit(struct sk_buff *buf, struct net_device *dev)
714 * check to make sure we've not become wedged. 714 * check to make sure we've not become wedged.
715 */ 715 */
716 716
717/*
718 * Handle an EtherExpress interrupt
719 * If we've finished initializing, start the RU and CU up.
720 * If we've already started, reap tx buffers, handle any received packets,
721 * check to make sure we've not become wedged.
722 */
723
724static unsigned short eexp_start_irq(struct net_device *dev, 717static unsigned short eexp_start_irq(struct net_device *dev,
725 unsigned short status) 718 unsigned short status)
726{ 719{
diff --git a/drivers/net/ehea/ehea.h b/drivers/net/ehea/ehea.h
index 272e1ec51aa2..42295d61ecd8 100644
--- a/drivers/net/ehea/ehea.h
+++ b/drivers/net/ehea/ehea.h
@@ -39,7 +39,7 @@
39#include <asm/io.h> 39#include <asm/io.h>
40 40
41#define DRV_NAME "ehea" 41#define DRV_NAME "ehea"
42#define DRV_VERSION "EHEA_0045" 42#define DRV_VERSION "EHEA_0046"
43 43
44#define EHEA_MSG_DEFAULT (NETIF_MSG_LINK | NETIF_MSG_TIMER \ 44#define EHEA_MSG_DEFAULT (NETIF_MSG_LINK | NETIF_MSG_TIMER \
45 | NETIF_MSG_RX_ERR | NETIF_MSG_TX_ERR) 45 | NETIF_MSG_RX_ERR | NETIF_MSG_TX_ERR)
diff --git a/drivers/net/ehea/ehea_main.c b/drivers/net/ehea/ehea_main.c
index 38b2fa424b2d..88ad1c8bcee4 100644
--- a/drivers/net/ehea/ehea_main.c
+++ b/drivers/net/ehea/ehea_main.c
@@ -76,7 +76,7 @@ void ehea_dump(void *adr, int len, char *msg) {
76 int x; 76 int x;
77 unsigned char *deb = adr; 77 unsigned char *deb = adr;
78 for (x = 0; x < len; x += 16) { 78 for (x = 0; x < len; x += 16) {
79 printk(DRV_NAME "%s adr=%p ofs=%04x %016lx %016lx\n", msg, 79 printk(DRV_NAME " %s adr=%p ofs=%04x %016lx %016lx\n", msg,
80 deb, x, *((u64*)&deb[0]), *((u64*)&deb[8])); 80 deb, x, *((u64*)&deb[0]), *((u64*)&deb[8]));
81 deb += 16; 81 deb += 16;
82 } 82 }
@@ -555,6 +555,7 @@ static irqreturn_t ehea_qp_aff_irq_handler(int irq, void *param)
555{ 555{
556 struct ehea_port *port = param; 556 struct ehea_port *port = param;
557 struct ehea_eqe *eqe; 557 struct ehea_eqe *eqe;
558 struct ehea_qp *qp;
558 u32 qp_token; 559 u32 qp_token;
559 560
560 eqe = ehea_poll_eq(port->qp_eq); 561 eqe = ehea_poll_eq(port->qp_eq);
@@ -563,9 +564,14 @@ static irqreturn_t ehea_qp_aff_irq_handler(int irq, void *param)
563 qp_token = EHEA_BMASK_GET(EHEA_EQE_QP_TOKEN, eqe->entry); 564 qp_token = EHEA_BMASK_GET(EHEA_EQE_QP_TOKEN, eqe->entry);
564 ehea_error("QP aff_err: entry=0x%lx, token=0x%x", 565 ehea_error("QP aff_err: entry=0x%lx, token=0x%x",
565 eqe->entry, qp_token); 566 eqe->entry, qp_token);
567
568 qp = port->port_res[qp_token].qp;
569 ehea_error_data(port->adapter, qp->fw_handle);
566 eqe = ehea_poll_eq(port->qp_eq); 570 eqe = ehea_poll_eq(port->qp_eq);
567 } 571 }
568 572
573 queue_work(port->adapter->ehea_wq, &port->reset_task);
574
569 return IRQ_HANDLED; 575 return IRQ_HANDLED;
570} 576}
571 577
diff --git a/drivers/net/ehea/ehea_phyp.c b/drivers/net/ehea/ehea_phyp.c
index 37716e05e808..bc3c00547264 100644
--- a/drivers/net/ehea/ehea_phyp.c
+++ b/drivers/net/ehea/ehea_phyp.c
@@ -612,3 +612,13 @@ u64 ehea_h_reset_events(const u64 adapter_handle, const u64 neq_handle,
612 event_mask, /* R6 */ 612 event_mask, /* R6 */
613 0, 0, 0, 0); /* R7-R12 */ 613 0, 0, 0, 0); /* R7-R12 */
614} 614}
615
616u64 ehea_h_error_data(const u64 adapter_handle, const u64 ressource_handle,
617 void *rblock)
618{
619 return ehea_plpar_hcall_norets(H_ERROR_DATA,
620 adapter_handle, /* R4 */
621 ressource_handle, /* R5 */
622 virt_to_abs(rblock), /* R6 */
623 0, 0, 0, 0); /* R7-R12 */
624}
diff --git a/drivers/net/ehea/ehea_phyp.h b/drivers/net/ehea/ehea_phyp.h
index 919f94b75933..90acddb068a1 100644
--- a/drivers/net/ehea/ehea_phyp.h
+++ b/drivers/net/ehea/ehea_phyp.h
@@ -454,4 +454,7 @@ u64 ehea_h_reg_dereg_bcmc(const u64 adapter_handle, const u16 port_num,
454u64 ehea_h_reset_events(const u64 adapter_handle, const u64 neq_handle, 454u64 ehea_h_reset_events(const u64 adapter_handle, const u64 neq_handle,
455 const u64 event_mask); 455 const u64 event_mask);
456 456
457u64 ehea_h_error_data(const u64 adapter_handle, const u64 ressource_handle,
458 void *rblock);
459
457#endif /* __EHEA_PHYP_H__ */ 460#endif /* __EHEA_PHYP_H__ */
diff --git a/drivers/net/ehea/ehea_qmr.c b/drivers/net/ehea/ehea_qmr.c
index f143e13b229d..96ff3b679996 100644
--- a/drivers/net/ehea/ehea_qmr.c
+++ b/drivers/net/ehea/ehea_qmr.c
@@ -486,6 +486,7 @@ int ehea_destroy_qp(struct ehea_qp *qp)
486 if (!qp) 486 if (!qp)
487 return 0; 487 return 0;
488 488
489 ehea_h_disable_and_get_hea(qp->adapter->handle, qp->fw_handle);
489 hret = ehea_h_free_resource(qp->adapter->handle, qp->fw_handle); 490 hret = ehea_h_free_resource(qp->adapter->handle, qp->fw_handle);
490 if (hret != H_SUCCESS) { 491 if (hret != H_SUCCESS) {
491 ehea_error("destroy_qp failed"); 492 ehea_error("destroy_qp failed");
@@ -581,4 +582,45 @@ out:
581 return ret; 582 return ret;
582} 583}
583 584
585void print_error_data(u64 *data)
586{
587 int length;
588 u64 type = EHEA_BMASK_GET(ERROR_DATA_TYPE, data[2]);
589 u64 resource = data[1];
590
591 length = EHEA_BMASK_GET(ERROR_DATA_LENGTH, data[0]);
592
593 if (length > EHEA_PAGESIZE)
594 length = EHEA_PAGESIZE;
595
596 if (type == 0x8) /* Queue Pair */
597 ehea_error("QP (resource=%lX) state: AER=0x%lX, AERR=0x%lX, "
598 "port=%lX", resource, data[6], data[12], data[22]);
599
600 ehea_dump(data, length, "error data");
601}
602
603void ehea_error_data(struct ehea_adapter *adapter, u64 res_handle)
604{
605 unsigned long ret;
606 u64 *rblock;
607
608 rblock = kzalloc(PAGE_SIZE, GFP_KERNEL);
609 if (!rblock) {
610 ehea_error("Cannot allocate rblock memory.");
611 return;
612 }
584 613
614 ret = ehea_h_error_data(adapter->handle,
615 res_handle,
616 rblock);
617
618 if (ret == H_R_STATE)
619 ehea_error("No error data is available: %lX.", res_handle);
620 else if (ret == H_SUCCESS)
621 print_error_data(rblock);
622 else
623 ehea_error("Error data could not be fetched: %lX", res_handle);
624
625 kfree(rblock);
626}
diff --git a/drivers/net/ehea/ehea_qmr.h b/drivers/net/ehea/ehea_qmr.h
index 7efdc96919ca..1ff60983504d 100644
--- a/drivers/net/ehea/ehea_qmr.h
+++ b/drivers/net/ehea/ehea_qmr.h
@@ -180,6 +180,9 @@ struct ehea_eqe {
180 u64 entry; 180 u64 entry;
181}; 181};
182 182
183#define ERROR_DATA_LENGTH EHEA_BMASK_IBM(52,63)
184#define ERROR_DATA_TYPE EHEA_BMASK_IBM(0,7)
185
183static inline void *hw_qeit_calc(struct hw_queue *queue, u64 q_offset) 186static inline void *hw_qeit_calc(struct hw_queue *queue, u64 q_offset)
184{ 187{
185 struct ehea_page *current_page; 188 struct ehea_page *current_page;
@@ -355,4 +358,6 @@ int ehea_destroy_qp(struct ehea_qp *qp);
355 358
356int ehea_reg_mr_adapter(struct ehea_adapter *adapter); 359int ehea_reg_mr_adapter(struct ehea_adapter *adapter);
357 360
361void ehea_error_data(struct ehea_adapter *adapter, u64 res_handle);
362
358#endif /* __EHEA_QMR_H__ */ 363#endif /* __EHEA_QMR_H__ */
diff --git a/drivers/net/gianfar.c b/drivers/net/gianfar.c
index 1be4a84dce0e..1f83988a6a64 100644
--- a/drivers/net/gianfar.c
+++ b/drivers/net/gianfar.c
@@ -10,6 +10,7 @@
10 * Maintainer: Kumar Gala 10 * Maintainer: Kumar Gala
11 * 11 *
12 * Copyright (c) 2002-2006 Freescale Semiconductor, Inc. 12 * Copyright (c) 2002-2006 Freescale Semiconductor, Inc.
13 * Copyright (c) 2007 MontaVista Software, Inc.
13 * 14 *
14 * This program is free software; you can redistribute it and/or modify it 15 * This program is free software; you can redistribute it and/or modify it
15 * under the terms of the GNU General Public License as published by the 16 * under the terms of the GNU General Public License as published by the
@@ -1612,71 +1613,17 @@ static irqreturn_t gfar_interrupt(int irq, void *dev_id)
1612 /* Save ievent for future reference */ 1613 /* Save ievent for future reference */
1613 u32 events = gfar_read(&priv->regs->ievent); 1614 u32 events = gfar_read(&priv->regs->ievent);
1614 1615
1615 /* Clear IEVENT */
1616 gfar_write(&priv->regs->ievent, events);
1617
1618 /* Check for reception */ 1616 /* Check for reception */
1619 if ((events & IEVENT_RXF0) || (events & IEVENT_RXB0)) 1617 if (events & IEVENT_RX_MASK)
1620 gfar_receive(irq, dev_id); 1618 gfar_receive(irq, dev_id);
1621 1619
1622 /* Check for transmit completion */ 1620 /* Check for transmit completion */
1623 if ((events & IEVENT_TXF) || (events & IEVENT_TXB)) 1621 if (events & IEVENT_TX_MASK)
1624 gfar_transmit(irq, dev_id); 1622 gfar_transmit(irq, dev_id);
1625 1623
1626 /* Update error statistics */ 1624 /* Check for errors */
1627 if (events & IEVENT_TXE) { 1625 if (events & IEVENT_ERR_MASK)
1628 priv->stats.tx_errors++; 1626 gfar_error(irq, dev_id);
1629
1630 if (events & IEVENT_LC)
1631 priv->stats.tx_window_errors++;
1632 if (events & IEVENT_CRL)
1633 priv->stats.tx_aborted_errors++;
1634 if (events & IEVENT_XFUN) {
1635 if (netif_msg_tx_err(priv))
1636 printk(KERN_WARNING "%s: tx underrun. dropped packet\n", dev->name);
1637 priv->stats.tx_dropped++;
1638 priv->extra_stats.tx_underrun++;
1639
1640 /* Reactivate the Tx Queues */
1641 gfar_write(&priv->regs->tstat, TSTAT_CLEAR_THALT);
1642 }
1643 }
1644 if (events & IEVENT_BSY) {
1645 priv->stats.rx_errors++;
1646 priv->extra_stats.rx_bsy++;
1647
1648 gfar_receive(irq, dev_id);
1649
1650#ifndef CONFIG_GFAR_NAPI
1651 /* Clear the halt bit in RSTAT */
1652 gfar_write(&priv->regs->rstat, RSTAT_CLEAR_RHALT);
1653#endif
1654
1655 if (netif_msg_rx_err(priv))
1656 printk(KERN_DEBUG "%s: busy error (rhalt: %x)\n",
1657 dev->name,
1658 gfar_read(&priv->regs->rstat));
1659 }
1660 if (events & IEVENT_BABR) {
1661 priv->stats.rx_errors++;
1662 priv->extra_stats.rx_babr++;
1663
1664 if (netif_msg_rx_err(priv))
1665 printk(KERN_DEBUG "%s: babbling error\n", dev->name);
1666 }
1667 if (events & IEVENT_EBERR) {
1668 priv->extra_stats.eberr++;
1669 if (netif_msg_rx_err(priv))
1670 printk(KERN_DEBUG "%s: EBERR\n", dev->name);
1671 }
1672 if ((events & IEVENT_RXC) && (netif_msg_rx_err(priv)))
1673 printk(KERN_DEBUG "%s: control frame\n", dev->name);
1674
1675 if (events & IEVENT_BABT) {
1676 priv->extra_stats.tx_babt++;
1677 if (netif_msg_rx_err(priv))
1678 printk(KERN_DEBUG "%s: babt error\n", dev->name);
1679 }
1680 1627
1681 return IRQ_HANDLED; 1628 return IRQ_HANDLED;
1682} 1629}
@@ -1938,7 +1885,7 @@ static irqreturn_t gfar_error(int irq, void *dev_id)
1938 /* Hmm... */ 1885 /* Hmm... */
1939 if (netif_msg_rx_err(priv) || netif_msg_tx_err(priv)) 1886 if (netif_msg_rx_err(priv) || netif_msg_tx_err(priv))
1940 printk(KERN_DEBUG "%s: error interrupt (ievent=0x%08x imask=0x%08x)\n", 1887 printk(KERN_DEBUG "%s: error interrupt (ievent=0x%08x imask=0x%08x)\n",
1941 dev->name, events, gfar_read(&priv->regs->imask)); 1888 dev->name, events, gfar_read(&priv->regs->imask));
1942 1889
1943 /* Update the error counters */ 1890 /* Update the error counters */
1944 if (events & IEVENT_TXE) { 1891 if (events & IEVENT_TXE) {
@@ -1950,8 +1897,8 @@ static irqreturn_t gfar_error(int irq, void *dev_id)
1950 priv->stats.tx_aborted_errors++; 1897 priv->stats.tx_aborted_errors++;
1951 if (events & IEVENT_XFUN) { 1898 if (events & IEVENT_XFUN) {
1952 if (netif_msg_tx_err(priv)) 1899 if (netif_msg_tx_err(priv))
1953 printk(KERN_DEBUG "%s: underrun. packet dropped.\n", 1900 printk(KERN_DEBUG "%s: TX FIFO underrun, "
1954 dev->name); 1901 "packet dropped.\n", dev->name);
1955 priv->stats.tx_dropped++; 1902 priv->stats.tx_dropped++;
1956 priv->extra_stats.tx_underrun++; 1903 priv->extra_stats.tx_underrun++;
1957 1904
@@ -1973,30 +1920,28 @@ static irqreturn_t gfar_error(int irq, void *dev_id)
1973#endif 1920#endif
1974 1921
1975 if (netif_msg_rx_err(priv)) 1922 if (netif_msg_rx_err(priv))
1976 printk(KERN_DEBUG "%s: busy error (rhalt: %x)\n", 1923 printk(KERN_DEBUG "%s: busy error (rstat: %x)\n",
1977 dev->name, 1924 dev->name, gfar_read(&priv->regs->rstat));
1978 gfar_read(&priv->regs->rstat));
1979 } 1925 }
1980 if (events & IEVENT_BABR) { 1926 if (events & IEVENT_BABR) {
1981 priv->stats.rx_errors++; 1927 priv->stats.rx_errors++;
1982 priv->extra_stats.rx_babr++; 1928 priv->extra_stats.rx_babr++;
1983 1929
1984 if (netif_msg_rx_err(priv)) 1930 if (netif_msg_rx_err(priv))
1985 printk(KERN_DEBUG "%s: babbling error\n", dev->name); 1931 printk(KERN_DEBUG "%s: babbling RX error\n", dev->name);
1986 } 1932 }
1987 if (events & IEVENT_EBERR) { 1933 if (events & IEVENT_EBERR) {
1988 priv->extra_stats.eberr++; 1934 priv->extra_stats.eberr++;
1989 if (netif_msg_rx_err(priv)) 1935 if (netif_msg_rx_err(priv))
1990 printk(KERN_DEBUG "%s: EBERR\n", dev->name); 1936 printk(KERN_DEBUG "%s: bus error\n", dev->name);
1991 } 1937 }
1992 if ((events & IEVENT_RXC) && netif_msg_rx_status(priv)) 1938 if ((events & IEVENT_RXC) && netif_msg_rx_status(priv))
1993 if (netif_msg_rx_status(priv)) 1939 printk(KERN_DEBUG "%s: control frame\n", dev->name);
1994 printk(KERN_DEBUG "%s: control frame\n", dev->name);
1995 1940
1996 if (events & IEVENT_BABT) { 1941 if (events & IEVENT_BABT) {
1997 priv->extra_stats.tx_babt++; 1942 priv->extra_stats.tx_babt++;
1998 if (netif_msg_tx_err(priv)) 1943 if (netif_msg_tx_err(priv))
1999 printk(KERN_DEBUG "%s: babt error\n", dev->name); 1944 printk(KERN_DEBUG "%s: babbling TX error\n", dev->name);
2000 } 1945 }
2001 return IRQ_HANDLED; 1946 return IRQ_HANDLED;
2002} 1947}
diff --git a/drivers/net/gianfar_sysfs.c b/drivers/net/gianfar_sysfs.c
index 45ffb5d0ca33..aec9ab17a9a5 100644
--- a/drivers/net/gianfar_sysfs.c
+++ b/drivers/net/gianfar_sysfs.c
@@ -38,13 +38,15 @@
38#include "gianfar.h" 38#include "gianfar.h"
39 39
40#define GFAR_ATTR(_name) \ 40#define GFAR_ATTR(_name) \
41static ssize_t gfar_show_##_name(struct class_device *cdev, char *buf); \ 41static ssize_t gfar_show_##_name(struct device *dev, \
42static ssize_t gfar_set_##_name(struct class_device *cdev, \ 42 struct device_attribute *attr, char *buf); \
43static ssize_t gfar_set_##_name(struct device *dev, \
44 struct device_attribute *attr, \
43 const char *buf, size_t count); \ 45 const char *buf, size_t count); \
44static CLASS_DEVICE_ATTR(_name, 0644, gfar_show_##_name, gfar_set_##_name) 46static DEVICE_ATTR(_name, 0644, gfar_show_##_name, gfar_set_##_name)
45 47
46#define GFAR_CREATE_FILE(_dev, _name) \ 48#define GFAR_CREATE_FILE(_dev, _name) \
47 class_device_create_file(&_dev->class_dev, &class_device_attr_##_name) 49 device_create_file(&_dev->dev, &dev_attr_##_name)
48 50
49GFAR_ATTR(bd_stash); 51GFAR_ATTR(bd_stash);
50GFAR_ATTR(rx_stash_size); 52GFAR_ATTR(rx_stash_size);
@@ -53,29 +55,28 @@ GFAR_ATTR(fifo_threshold);
53GFAR_ATTR(fifo_starve); 55GFAR_ATTR(fifo_starve);
54GFAR_ATTR(fifo_starve_off); 56GFAR_ATTR(fifo_starve_off);
55 57
56#define to_net_dev(cd) container_of(cd, struct net_device, class_dev) 58static ssize_t gfar_show_bd_stash(struct device *dev,
57 59 struct device_attribute *attr, char *buf)
58static ssize_t gfar_show_bd_stash(struct class_device *cdev, char *buf)
59{ 60{
60 struct net_device *dev = to_net_dev(cdev); 61 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
61 struct gfar_private *priv = netdev_priv(dev);
62 62
63 return sprintf(buf, "%s\n", priv->bd_stash_en? "on" : "off"); 63 return sprintf(buf, "%s\n", priv->bd_stash_en ? "on" : "off");
64} 64}
65 65
66static ssize_t gfar_set_bd_stash(struct class_device *cdev, 66static ssize_t gfar_set_bd_stash(struct device *dev,
67 const char *buf, size_t count) 67 struct device_attribute *attr,
68 const char *buf, size_t count)
68{ 69{
69 struct net_device *dev = to_net_dev(cdev); 70 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
70 struct gfar_private *priv = netdev_priv(dev);
71 int new_setting = 0; 71 int new_setting = 0;
72 u32 temp; 72 u32 temp;
73 unsigned long flags; 73 unsigned long flags;
74 74
75 /* Find out the new setting */ 75 /* Find out the new setting */
76 if (!strncmp("on", buf, count-1) || !strncmp("1", buf, count-1)) 76 if (!strncmp("on", buf, count - 1) || !strncmp("1", buf, count - 1))
77 new_setting = 1; 77 new_setting = 1;
78 else if (!strncmp("off", buf, count-1) || !strncmp("0", buf, count-1)) 78 else if (!strncmp("off", buf, count - 1)
79 || !strncmp("0", buf, count - 1))
79 new_setting = 0; 80 new_setting = 0;
80 else 81 else
81 return count; 82 return count;
@@ -99,19 +100,19 @@ static ssize_t gfar_set_bd_stash(struct class_device *cdev,
99 return count; 100 return count;
100} 101}
101 102
102static ssize_t gfar_show_rx_stash_size(struct class_device *cdev, char *buf) 103static ssize_t gfar_show_rx_stash_size(struct device *dev,
104 struct device_attribute *attr, char *buf)
103{ 105{
104 struct net_device *dev = to_net_dev(cdev); 106 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
105 struct gfar_private *priv = netdev_priv(dev);
106 107
107 return sprintf(buf, "%d\n", priv->rx_stash_size); 108 return sprintf(buf, "%d\n", priv->rx_stash_size);
108} 109}
109 110
110static ssize_t gfar_set_rx_stash_size(struct class_device *cdev, 111static ssize_t gfar_set_rx_stash_size(struct device *dev,
111 const char *buf, size_t count) 112 struct device_attribute *attr,
113 const char *buf, size_t count)
112{ 114{
113 struct net_device *dev = to_net_dev(cdev); 115 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
114 struct gfar_private *priv = netdev_priv(dev);
115 unsigned int length = simple_strtoul(buf, NULL, 0); 116 unsigned int length = simple_strtoul(buf, NULL, 0);
116 u32 temp; 117 u32 temp;
117 unsigned long flags; 118 unsigned long flags;
@@ -145,21 +146,21 @@ static ssize_t gfar_set_rx_stash_size(struct class_device *cdev,
145 return count; 146 return count;
146} 147}
147 148
148
149/* Stashing will only be enabled when rx_stash_size != 0 */ 149/* Stashing will only be enabled when rx_stash_size != 0 */
150static ssize_t gfar_show_rx_stash_index(struct class_device *cdev, char *buf) 150static ssize_t gfar_show_rx_stash_index(struct device *dev,
151 struct device_attribute *attr,
152 char *buf)
151{ 153{
152 struct net_device *dev = to_net_dev(cdev); 154 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
153 struct gfar_private *priv = netdev_priv(dev);
154 155
155 return sprintf(buf, "%d\n", priv->rx_stash_index); 156 return sprintf(buf, "%d\n", priv->rx_stash_index);
156} 157}
157 158
158static ssize_t gfar_set_rx_stash_index(struct class_device *cdev, 159static ssize_t gfar_set_rx_stash_index(struct device *dev,
159 const char *buf, size_t count) 160 struct device_attribute *attr,
161 const char *buf, size_t count)
160{ 162{
161 struct net_device *dev = to_net_dev(cdev); 163 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
162 struct gfar_private *priv = netdev_priv(dev);
163 unsigned short index = simple_strtoul(buf, NULL, 0); 164 unsigned short index = simple_strtoul(buf, NULL, 0);
164 u32 temp; 165 u32 temp;
165 unsigned long flags; 166 unsigned long flags;
@@ -183,19 +184,20 @@ static ssize_t gfar_set_rx_stash_index(struct class_device *cdev,
183 return count; 184 return count;
184} 185}
185 186
186static ssize_t gfar_show_fifo_threshold(struct class_device *cdev, char *buf) 187static ssize_t gfar_show_fifo_threshold(struct device *dev,
188 struct device_attribute *attr,
189 char *buf)
187{ 190{
188 struct net_device *dev = to_net_dev(cdev); 191 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
189 struct gfar_private *priv = netdev_priv(dev);
190 192
191 return sprintf(buf, "%d\n", priv->fifo_threshold); 193 return sprintf(buf, "%d\n", priv->fifo_threshold);
192} 194}
193 195
194static ssize_t gfar_set_fifo_threshold(struct class_device *cdev, 196static ssize_t gfar_set_fifo_threshold(struct device *dev,
195 const char *buf, size_t count) 197 struct device_attribute *attr,
198 const char *buf, size_t count)
196{ 199{
197 struct net_device *dev = to_net_dev(cdev); 200 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
198 struct gfar_private *priv = netdev_priv(dev);
199 unsigned int length = simple_strtoul(buf, NULL, 0); 201 unsigned int length = simple_strtoul(buf, NULL, 0);
200 u32 temp; 202 u32 temp;
201 unsigned long flags; 203 unsigned long flags;
@@ -217,20 +219,19 @@ static ssize_t gfar_set_fifo_threshold(struct class_device *cdev,
217 return count; 219 return count;
218} 220}
219 221
220static ssize_t gfar_show_fifo_starve(struct class_device *cdev, char *buf) 222static ssize_t gfar_show_fifo_starve(struct device *dev,
223 struct device_attribute *attr, char *buf)
221{ 224{
222 struct net_device *dev = to_net_dev(cdev); 225 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
223 struct gfar_private *priv = netdev_priv(dev);
224 226
225 return sprintf(buf, "%d\n", priv->fifo_starve); 227 return sprintf(buf, "%d\n", priv->fifo_starve);
226} 228}
227 229
228 230static ssize_t gfar_set_fifo_starve(struct device *dev,
229static ssize_t gfar_set_fifo_starve(struct class_device *cdev, 231 struct device_attribute *attr,
230 const char *buf, size_t count) 232 const char *buf, size_t count)
231{ 233{
232 struct net_device *dev = to_net_dev(cdev); 234 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
233 struct gfar_private *priv = netdev_priv(dev);
234 unsigned int num = simple_strtoul(buf, NULL, 0); 235 unsigned int num = simple_strtoul(buf, NULL, 0);
235 u32 temp; 236 u32 temp;
236 unsigned long flags; 237 unsigned long flags;
@@ -252,19 +253,20 @@ static ssize_t gfar_set_fifo_starve(struct class_device *cdev,
252 return count; 253 return count;
253} 254}
254 255
255static ssize_t gfar_show_fifo_starve_off(struct class_device *cdev, char *buf) 256static ssize_t gfar_show_fifo_starve_off(struct device *dev,
257 struct device_attribute *attr,
258 char *buf)
256{ 259{
257 struct net_device *dev = to_net_dev(cdev); 260 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
258 struct gfar_private *priv = netdev_priv(dev);
259 261
260 return sprintf(buf, "%d\n", priv->fifo_starve_off); 262 return sprintf(buf, "%d\n", priv->fifo_starve_off);
261} 263}
262 264
263static ssize_t gfar_set_fifo_starve_off(struct class_device *cdev, 265static ssize_t gfar_set_fifo_starve_off(struct device *dev,
264 const char *buf, size_t count) 266 struct device_attribute *attr,
267 const char *buf, size_t count)
265{ 268{
266 struct net_device *dev = to_net_dev(cdev); 269 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
267 struct gfar_private *priv = netdev_priv(dev);
268 unsigned int num = simple_strtoul(buf, NULL, 0); 270 unsigned int num = simple_strtoul(buf, NULL, 0);
269 u32 temp; 271 u32 temp;
270 unsigned long flags; 272 unsigned long flags;
diff --git a/drivers/net/hamradio/Kconfig b/drivers/net/hamradio/Kconfig
index feb0ada7a025..6e90619b3b41 100644
--- a/drivers/net/hamradio/Kconfig
+++ b/drivers/net/hamradio/Kconfig
@@ -138,7 +138,7 @@ config BAYCOM_SER_HDX
138 ---help--- 138 ---help---
139 This is one of two drivers for Baycom style simple amateur radio 139 This is one of two drivers for Baycom style simple amateur radio
140 modems that connect to a serial interface. The driver supports the 140 modems that connect to a serial interface. The driver supports the
141 ser12 design in full-duplex mode. This is the old driver. It is 141 ser12 design in half-duplex mode. This is the old driver. It is
142 still provided in case your serial interface chip does not work with 142 still provided in case your serial interface chip does not work with
143 the full-duplex driver. This driver is depreciated. To configure 143 the full-duplex driver. This driver is depreciated. To configure
144 the driver, use the sethdlc utility available in the standard ax25 144 the driver, use the sethdlc utility available in the standard ax25
@@ -190,3 +190,4 @@ config YAM
190 To compile this driver as a module, choose M here: the module 190 To compile this driver as a module, choose M here: the module
191 will be called yam. 191 will be called yam.
192 192
193
diff --git a/drivers/net/ioc3-eth.c b/drivers/net/ioc3-eth.c
index f0d30cf67b5f..4ad780719a84 100644
--- a/drivers/net/ioc3-eth.c
+++ b/drivers/net/ioc3-eth.c
@@ -836,13 +836,17 @@ static int ioc3_mii_init(struct ioc3_private *ip)
836 } 836 }
837 837
838 ip->mii.phy_id = i; 838 ip->mii.phy_id = i;
839
840out:
841 return res;
842}
843
844static void ioc3_mii_start(struct ioc3_private *ip)
845{
839 ip->ioc3_timer.expires = jiffies + (12 * HZ)/10; /* 1.2 sec. */ 846 ip->ioc3_timer.expires = jiffies + (12 * HZ)/10; /* 1.2 sec. */
840 ip->ioc3_timer.data = (unsigned long) ip; 847 ip->ioc3_timer.data = (unsigned long) ip;
841 ip->ioc3_timer.function = &ioc3_timer; 848 ip->ioc3_timer.function = &ioc3_timer;
842 add_timer(&ip->ioc3_timer); 849 add_timer(&ip->ioc3_timer);
843
844out:
845 return res;
846} 850}
847 851
848static inline void ioc3_clean_rx_ring(struct ioc3_private *ip) 852static inline void ioc3_clean_rx_ring(struct ioc3_private *ip)
@@ -1071,6 +1075,7 @@ static int ioc3_open(struct net_device *dev)
1071 ip->ehar_h = 0; 1075 ip->ehar_h = 0;
1072 ip->ehar_l = 0; 1076 ip->ehar_l = 0;
1073 ioc3_init(dev); 1077 ioc3_init(dev);
1078 ioc3_mii_start(ip);
1074 1079
1075 netif_start_queue(dev); 1080 netif_start_queue(dev);
1076 return 0; 1081 return 0;
@@ -1274,6 +1279,7 @@ static int ioc3_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1274 goto out_stop; 1279 goto out_stop;
1275 } 1280 }
1276 1281
1282 ioc3_mii_start(ip);
1277 ioc3_ssram_disc(ip); 1283 ioc3_ssram_disc(ip);
1278 ioc3_get_eaddr(ip); 1284 ioc3_get_eaddr(ip);
1279 1285
@@ -1314,6 +1320,7 @@ static int ioc3_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1314 1320
1315out_stop: 1321out_stop:
1316 ioc3_stop(ip); 1322 ioc3_stop(ip);
1323 del_timer_sync(&ip->ioc3_timer);
1317 ioc3_free_rings(ip); 1324 ioc3_free_rings(ip);
1318out_res: 1325out_res:
1319 pci_release_regions(pdev); 1326 pci_release_regions(pdev);
@@ -1335,6 +1342,8 @@ static void __devexit ioc3_remove_one (struct pci_dev *pdev)
1335 struct ioc3 *ioc3 = ip->regs; 1342 struct ioc3 *ioc3 = ip->regs;
1336 1343
1337 unregister_netdev(dev); 1344 unregister_netdev(dev);
1345 del_timer_sync(&ip->ioc3_timer);
1346
1338 iounmap(ioc3); 1347 iounmap(ioc3);
1339 pci_release_regions(pdev); 1348 pci_release_regions(pdev);
1340 free_netdev(dev); 1349 free_netdev(dev);
@@ -1492,6 +1501,7 @@ static void ioc3_timeout(struct net_device *dev)
1492 ioc3_stop(ip); 1501 ioc3_stop(ip);
1493 ioc3_init(dev); 1502 ioc3_init(dev);
1494 ioc3_mii_init(ip); 1503 ioc3_mii_init(ip);
1504 ioc3_mii_start(ip);
1495 1505
1496 spin_unlock_irq(&ip->ioc3_lock); 1506 spin_unlock_irq(&ip->ioc3_lock);
1497 1507
diff --git a/drivers/net/macb.c b/drivers/net/macb.c
index a41418b3c518..2e9571bf0736 100644
--- a/drivers/net/macb.c
+++ b/drivers/net/macb.c
@@ -881,27 +881,15 @@ static struct net_device_stats *macb_get_stats(struct net_device *dev)
881static int macb_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) 881static int macb_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
882{ 882{
883 struct macb *bp = netdev_priv(dev); 883 struct macb *bp = netdev_priv(dev);
884 int ret;
885 unsigned long flags;
886
887 spin_lock_irqsave(&bp->lock, flags);
888 ret = mii_ethtool_gset(&bp->mii, cmd);
889 spin_unlock_irqrestore(&bp->lock, flags);
890 884
891 return ret; 885 return mii_ethtool_gset(&bp->mii, cmd);
892} 886}
893 887
894static int macb_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) 888static int macb_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
895{ 889{
896 struct macb *bp = netdev_priv(dev); 890 struct macb *bp = netdev_priv(dev);
897 int ret;
898 unsigned long flags;
899
900 spin_lock_irqsave(&bp->lock, flags);
901 ret = mii_ethtool_sset(&bp->mii, cmd);
902 spin_unlock_irqrestore(&bp->lock, flags);
903 891
904 return ret; 892 return mii_ethtool_sset(&bp->mii, cmd);
905} 893}
906 894
907static void macb_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info) 895static void macb_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
@@ -930,17 +918,11 @@ static struct ethtool_ops macb_ethtool_ops = {
930static int macb_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) 918static int macb_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
931{ 919{
932 struct macb *bp = netdev_priv(dev); 920 struct macb *bp = netdev_priv(dev);
933 int ret;
934 unsigned long flags;
935 921
936 if (!netif_running(dev)) 922 if (!netif_running(dev))
937 return -EINVAL; 923 return -EINVAL;
938 924
939 spin_lock_irqsave(&bp->lock, flags); 925 return generic_mii_ioctl(&bp->mii, if_mii(rq), cmd, NULL);
940 ret = generic_mii_ioctl(&bp->mii, if_mii(rq), cmd, NULL);
941 spin_unlock_irqrestore(&bp->lock, flags);
942
943 return ret;
944} 926}
945 927
946static ssize_t macb_mii_show(const struct device *_dev, char *buf, 928static ssize_t macb_mii_show(const struct device *_dev, char *buf,
diff --git a/drivers/net/meth.c b/drivers/net/meth.c
index d38b7c723620..7e69ca6edd91 100644
--- a/drivers/net/meth.c
+++ b/drivers/net/meth.c
@@ -170,7 +170,7 @@ static int mdio_probe(struct meth_private *priv)
170 170
171static void meth_check_link(struct net_device *dev) 171static void meth_check_link(struct net_device *dev)
172{ 172{
173 struct meth_private *priv = (struct meth_private *) dev->priv; 173 struct meth_private *priv = netdev_priv(dev);
174 unsigned long mii_advertising = mdio_read(priv, 4); 174 unsigned long mii_advertising = mdio_read(priv, 4);
175 unsigned long mii_partner = mdio_read(priv, 5); 175 unsigned long mii_partner = mdio_read(priv, 5);
176 unsigned long negotiated = mii_advertising & mii_partner; 176 unsigned long negotiated = mii_advertising & mii_partner;
@@ -268,7 +268,7 @@ static void meth_free_rx_ring(struct meth_private *priv)
268 268
269int meth_reset(struct net_device *dev) 269int meth_reset(struct net_device *dev)
270{ 270{
271 struct meth_private *priv = (struct meth_private *) dev->priv; 271 struct meth_private *priv = netdev_priv(dev);
272 272
273 /* Reset card */ 273 /* Reset card */
274 mace->eth.mac_ctrl = SGI_MAC_RESET; 274 mace->eth.mac_ctrl = SGI_MAC_RESET;
@@ -310,7 +310,7 @@ int meth_reset(struct net_device *dev)
310 */ 310 */
311static int meth_open(struct net_device *dev) 311static int meth_open(struct net_device *dev)
312{ 312{
313 struct meth_private *priv = dev->priv; 313 struct meth_private *priv = netdev_priv(dev);
314 int ret; 314 int ret;
315 315
316 priv->phy_addr = -1; /* No PHY is known yet... */ 316 priv->phy_addr = -1; /* No PHY is known yet... */
@@ -354,7 +354,7 @@ out_free_tx_ring:
354 354
355static int meth_release(struct net_device *dev) 355static int meth_release(struct net_device *dev)
356{ 356{
357 struct meth_private *priv = dev->priv; 357 struct meth_private *priv = netdev_priv(dev);
358 358
359 DPRINTK("Stopping queue\n"); 359 DPRINTK("Stopping queue\n");
360 netif_stop_queue(dev); /* can't transmit any more */ 360 netif_stop_queue(dev); /* can't transmit any more */
@@ -376,7 +376,7 @@ static void meth_rx(struct net_device* dev, unsigned long int_status)
376{ 376{
377 struct sk_buff *skb; 377 struct sk_buff *skb;
378 unsigned long status; 378 unsigned long status;
379 struct meth_private *priv = (struct meth_private *) dev->priv; 379 struct meth_private *priv = netdev_priv(dev);
380 unsigned long fifo_rptr = (int_status & METH_INT_RX_RPTR_MASK) >> 8; 380 unsigned long fifo_rptr = (int_status & METH_INT_RX_RPTR_MASK) >> 8;
381 381
382 spin_lock(&priv->meth_lock); 382 spin_lock(&priv->meth_lock);
@@ -466,14 +466,14 @@ static void meth_rx(struct net_device* dev, unsigned long int_status)
466 466
467static int meth_tx_full(struct net_device *dev) 467static int meth_tx_full(struct net_device *dev)
468{ 468{
469 struct meth_private *priv = (struct meth_private *) dev->priv; 469 struct meth_private *priv = netdev_priv(dev);
470 470
471 return (priv->tx_count >= TX_RING_ENTRIES - 1); 471 return (priv->tx_count >= TX_RING_ENTRIES - 1);
472} 472}
473 473
474static void meth_tx_cleanup(struct net_device* dev, unsigned long int_status) 474static void meth_tx_cleanup(struct net_device* dev, unsigned long int_status)
475{ 475{
476 struct meth_private *priv = dev->priv; 476 struct meth_private *priv = netdev_priv(dev);
477 unsigned long status; 477 unsigned long status;
478 struct sk_buff *skb; 478 struct sk_buff *skb;
479 unsigned long rptr = (int_status&TX_INFO_RPTR) >> 16; 479 unsigned long rptr = (int_status&TX_INFO_RPTR) >> 16;
@@ -536,7 +536,7 @@ static void meth_tx_cleanup(struct net_device* dev, unsigned long int_status)
536 536
537static void meth_error(struct net_device* dev, unsigned status) 537static void meth_error(struct net_device* dev, unsigned status)
538{ 538{
539 struct meth_private *priv = (struct meth_private *) dev->priv; 539 struct meth_private *priv = netdev_priv(dev);
540 540
541 printk(KERN_WARNING "meth: error status: 0x%08x\n",status); 541 printk(KERN_WARNING "meth: error status: 0x%08x\n",status);
542 /* check for errors too... */ 542 /* check for errors too... */
@@ -570,7 +570,7 @@ static void meth_error(struct net_device* dev, unsigned status)
570static irqreturn_t meth_interrupt(int irq, void *dev_id) 570static irqreturn_t meth_interrupt(int irq, void *dev_id)
571{ 571{
572 struct net_device *dev = (struct net_device *)dev_id; 572 struct net_device *dev = (struct net_device *)dev_id;
573 struct meth_private *priv = (struct meth_private *) dev->priv; 573 struct meth_private *priv = netdev_priv(dev);
574 unsigned long status; 574 unsigned long status;
575 575
576 status = mace->eth.int_stat; 576 status = mace->eth.int_stat;
@@ -695,7 +695,7 @@ static void meth_add_to_tx_ring(struct meth_private *priv, struct sk_buff *skb)
695 */ 695 */
696static int meth_tx(struct sk_buff *skb, struct net_device *dev) 696static int meth_tx(struct sk_buff *skb, struct net_device *dev)
697{ 697{
698 struct meth_private *priv = (struct meth_private *) dev->priv; 698 struct meth_private *priv = netdev_priv(dev);
699 unsigned long flags; 699 unsigned long flags;
700 700
701 spin_lock_irqsave(&priv->meth_lock, flags); 701 spin_lock_irqsave(&priv->meth_lock, flags);
@@ -726,7 +726,7 @@ static int meth_tx(struct sk_buff *skb, struct net_device *dev)
726 */ 726 */
727static void meth_tx_timeout(struct net_device *dev) 727static void meth_tx_timeout(struct net_device *dev)
728{ 728{
729 struct meth_private *priv = (struct meth_private *) dev->priv; 729 struct meth_private *priv = netdev_priv(dev);
730 unsigned long flags; 730 unsigned long flags;
731 731
732 printk(KERN_WARNING "%s: transmit timed out\n", dev->name); 732 printk(KERN_WARNING "%s: transmit timed out\n", dev->name);
@@ -778,7 +778,7 @@ static int meth_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
778 */ 778 */
779static struct net_device_stats *meth_stats(struct net_device *dev) 779static struct net_device_stats *meth_stats(struct net_device *dev)
780{ 780{
781 struct meth_private *priv = (struct meth_private *) dev->priv; 781 struct meth_private *priv = netdev_priv(dev);
782 return &priv->stats; 782 return &priv->stats;
783} 783}
784 784
@@ -807,7 +807,7 @@ static struct net_device *meth_init(void)
807 dev->irq = MACE_ETHERNET_IRQ; 807 dev->irq = MACE_ETHERNET_IRQ;
808 dev->base_addr = (unsigned long)&mace->eth; 808 dev->base_addr = (unsigned long)&mace->eth;
809 809
810 priv = (struct meth_private *) dev->priv; 810 priv = netdev_priv(dev);
811 spin_lock_init(&priv->meth_lock); 811 spin_lock_init(&priv->meth_lock);
812 812
813 ret = register_netdev(dev); 813 ret = register_netdev(dev);
diff --git a/drivers/net/netxen/netxen_nic.h b/drivers/net/netxen/netxen_nic.h
index 3f3896e98879..2807ef400fb5 100644
--- a/drivers/net/netxen/netxen_nic.h
+++ b/drivers/net/netxen/netxen_nic.h
@@ -252,7 +252,7 @@ typedef u32 netxen_ctx_msg;
252#define netxen_set_msg_ctxid(config_word, val) \ 252#define netxen_set_msg_ctxid(config_word, val) \
253 ((config_word) &= ~(0x3ff<<18), (config_word) |= (val & 0x3ff) << 18) 253 ((config_word) &= ~(0x3ff<<18), (config_word) |= (val & 0x3ff) << 18)
254#define netxen_set_msg_opcode(config_word, val) \ 254#define netxen_set_msg_opcode(config_word, val) \
255 ((config_word) &= ~(0xf<<24), (config_word) |= (val & 0xf) << 24) 255 ((config_word) &= ~(0xf<<28), (config_word) |= (val & 0xf) << 28)
256 256
257struct netxen_rcv_context { 257struct netxen_rcv_context {
258 __le64 rcv_ring_addr; 258 __le64 rcv_ring_addr;
@@ -303,14 +303,14 @@ struct netxen_ring_ctx {
303 (cmd_desc)->flags_opcode |= cpu_to_le16((val) & 0x7f)) 303 (cmd_desc)->flags_opcode |= cpu_to_le16((val) & 0x7f))
304#define netxen_set_cmd_desc_opcode(cmd_desc, val) \ 304#define netxen_set_cmd_desc_opcode(cmd_desc, val) \
305 ((cmd_desc)->flags_opcode &= ~cpu_to_le16(0x3f<<7), \ 305 ((cmd_desc)->flags_opcode &= ~cpu_to_le16(0x3f<<7), \
306 (cmd_desc)->flags_opcode |= cpu_to_le16((val) & (0x3f<<7))) 306 (cmd_desc)->flags_opcode |= cpu_to_le16(((val & 0x3f)<<7)))
307 307
308#define netxen_set_cmd_desc_num_of_buff(cmd_desc, val) \ 308#define netxen_set_cmd_desc_num_of_buff(cmd_desc, val) \
309 ((cmd_desc)->num_of_buffers_total_length &= ~cpu_to_le32(0xff), \ 309 ((cmd_desc)->num_of_buffers_total_length &= ~cpu_to_le32(0xff), \
310 (cmd_desc)->num_of_buffers_total_length |= cpu_to_le32((val) & 0xff)) 310 (cmd_desc)->num_of_buffers_total_length |= cpu_to_le32((val) & 0xff))
311#define netxen_set_cmd_desc_totallength(cmd_desc, val) \ 311#define netxen_set_cmd_desc_totallength(cmd_desc, val) \
312 ((cmd_desc)->num_of_buffers_total_length &= cpu_to_le32(0xff), \ 312 ((cmd_desc)->num_of_buffers_total_length &= ~cpu_to_le32(0xffffff00), \
313 (cmd_desc)->num_of_buffers_total_length |= cpu_to_le32(val << 24)) 313 (cmd_desc)->num_of_buffers_total_length |= cpu_to_le32(val << 8))
314 314
315#define netxen_get_cmd_desc_opcode(cmd_desc) \ 315#define netxen_get_cmd_desc_opcode(cmd_desc) \
316 ((le16_to_cpu((cmd_desc)->flags_opcode) >> 7) & 0x003F) 316 ((le16_to_cpu((cmd_desc)->flags_opcode) >> 7) & 0x003F)
@@ -1040,6 +1040,7 @@ int netxen_flash_unlock(struct netxen_adapter *adapter);
1040int netxen_backup_crbinit(struct netxen_adapter *adapter); 1040int netxen_backup_crbinit(struct netxen_adapter *adapter);
1041int netxen_flash_erase_secondary(struct netxen_adapter *adapter); 1041int netxen_flash_erase_secondary(struct netxen_adapter *adapter);
1042int netxen_flash_erase_primary(struct netxen_adapter *adapter); 1042int netxen_flash_erase_primary(struct netxen_adapter *adapter);
1043void netxen_halt_pegs(struct netxen_adapter *adapter);
1043 1044
1044int netxen_rom_fast_write(struct netxen_adapter *adapter, int addr, int data); 1045int netxen_rom_fast_write(struct netxen_adapter *adapter, int addr, int data);
1045int netxen_rom_se(struct netxen_adapter *adapter, int addr); 1046int netxen_rom_se(struct netxen_adapter *adapter, int addr);
diff --git a/drivers/net/netxen/netxen_nic_ethtool.c b/drivers/net/netxen/netxen_nic_ethtool.c
index cc0efe213e01..6252e9a87278 100644
--- a/drivers/net/netxen/netxen_nic_ethtool.c
+++ b/drivers/net/netxen/netxen_nic_ethtool.c
@@ -402,7 +402,7 @@ netxen_nic_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
402 wol->wolopts = 0; 402 wol->wolopts = 0;
403} 403}
404 404
405static u32 netxen_nic_get_link(struct net_device *dev) 405static u32 netxen_nic_test_link(struct net_device *dev)
406{ 406{
407 struct netxen_port *port = netdev_priv(dev); 407 struct netxen_port *port = netdev_priv(dev);
408 struct netxen_adapter *adapter = port->adapter; 408 struct netxen_adapter *adapter = port->adapter;
@@ -459,6 +459,7 @@ netxen_nic_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
459 int ret; 459 int ret;
460 460
461 if (flash_start == 0) { 461 if (flash_start == 0) {
462 netxen_halt_pegs(adapter);
462 ret = netxen_flash_unlock(adapter); 463 ret = netxen_flash_unlock(adapter);
463 if (ret < 0) { 464 if (ret < 0) {
464 printk(KERN_ERR "%s: Flash unlock failed.\n", 465 printk(KERN_ERR "%s: Flash unlock failed.\n",
@@ -712,7 +713,7 @@ netxen_nic_diag_test(struct net_device *dev, struct ethtool_test *eth_test,
712{ 713{
713 if (eth_test->flags == ETH_TEST_FL_OFFLINE) { /* offline tests */ 714 if (eth_test->flags == ETH_TEST_FL_OFFLINE) { /* offline tests */
714 /* link test */ 715 /* link test */
715 if (!(data[4] = (u64) netxen_nic_get_link(dev))) 716 if (!(data[4] = (u64) netxen_nic_test_link(dev)))
716 eth_test->flags |= ETH_TEST_FL_FAILED; 717 eth_test->flags |= ETH_TEST_FL_FAILED;
717 718
718 if (netif_running(dev)) 719 if (netif_running(dev))
@@ -727,7 +728,7 @@ netxen_nic_diag_test(struct net_device *dev, struct ethtool_test *eth_test,
727 dev->open(dev); 728 dev->open(dev);
728 } else { /* online tests */ 729 } else { /* online tests */
729 /* link test */ 730 /* link test */
730 if (!(data[4] = (u64) netxen_nic_get_link(dev))) 731 if (!(data[4] = (u64) netxen_nic_test_link(dev)))
731 eth_test->flags |= ETH_TEST_FL_FAILED; 732 eth_test->flags |= ETH_TEST_FL_FAILED;
732 733
733 /* other tests pass by default */ 734 /* other tests pass by default */
@@ -783,7 +784,7 @@ struct ethtool_ops netxen_nic_ethtool_ops = {
783 .get_regs_len = netxen_nic_get_regs_len, 784 .get_regs_len = netxen_nic_get_regs_len,
784 .get_regs = netxen_nic_get_regs, 785 .get_regs = netxen_nic_get_regs,
785 .get_wol = netxen_nic_get_wol, 786 .get_wol = netxen_nic_get_wol,
786 .get_link = netxen_nic_get_link, 787 .get_link = ethtool_op_get_link,
787 .get_eeprom_len = netxen_nic_get_eeprom_len, 788 .get_eeprom_len = netxen_nic_get_eeprom_len,
788 .get_eeprom = netxen_nic_get_eeprom, 789 .get_eeprom = netxen_nic_get_eeprom,
789 .set_eeprom = netxen_nic_set_eeprom, 790 .set_eeprom = netxen_nic_set_eeprom,
diff --git a/drivers/net/netxen/netxen_nic_hw.c b/drivers/net/netxen/netxen_nic_hw.c
index f263232f499f..7195af3e8f3d 100644
--- a/drivers/net/netxen/netxen_nic_hw.c
+++ b/drivers/net/netxen/netxen_nic_hw.c
@@ -420,6 +420,7 @@ static int netxen_get_flash_block(struct netxen_adapter *adapter, int base,
420 for (i = 0; i < size / sizeof(u32); i++) { 420 for (i = 0; i < size / sizeof(u32); i++) {
421 if (netxen_rom_fast_read(adapter, addr, ptr32) == -1) 421 if (netxen_rom_fast_read(adapter, addr, ptr32) == -1)
422 return -1; 422 return -1;
423 *ptr32 = cpu_to_le32(*ptr32);
423 ptr32++; 424 ptr32++;
424 addr += sizeof(u32); 425 addr += sizeof(u32);
425 } 426 }
@@ -428,6 +429,7 @@ static int netxen_get_flash_block(struct netxen_adapter *adapter, int base,
428 429
429 if (netxen_rom_fast_read(adapter, addr, &local) == -1) 430 if (netxen_rom_fast_read(adapter, addr, &local) == -1)
430 return -1; 431 return -1;
432 local = cpu_to_le32(local);
431 memcpy(ptr32, &local, (char *)buf + size - (char *)ptr32); 433 memcpy(ptr32, &local, (char *)buf + size - (char *)ptr32);
432 } 434 }
433 435
diff --git a/drivers/net/netxen/netxen_nic_init.c b/drivers/net/netxen/netxen_nic_init.c
index f7bb8c90537c..2f324366784d 100644
--- a/drivers/net/netxen/netxen_nic_init.c
+++ b/drivers/net/netxen/netxen_nic_init.c
@@ -717,6 +717,14 @@ netxen_flash_erase_primary(struct netxen_adapter *adapter)
717 return ret; 717 return ret;
718} 718}
719 719
720void netxen_halt_pegs(struct netxen_adapter *adapter)
721{
722 netxen_crb_writelit_adapter(adapter, NETXEN_CRB_PEG_NET_0 + 0x3c, 1);
723 netxen_crb_writelit_adapter(adapter, NETXEN_CRB_PEG_NET_1 + 0x3c, 1);
724 netxen_crb_writelit_adapter(adapter, NETXEN_CRB_PEG_NET_2 + 0x3c, 1);
725 netxen_crb_writelit_adapter(adapter, NETXEN_CRB_PEG_NET_3 + 0x3c, 1);
726}
727
720int netxen_flash_unlock(struct netxen_adapter *adapter) 728int netxen_flash_unlock(struct netxen_adapter *adapter)
721{ 729{
722 int ret = 0; 730 int ret = 0;
@@ -1246,7 +1254,7 @@ int netxen_process_cmd_ring(unsigned long data)
1246 * the netdev which is associated with that device. 1254 * the netdev which is associated with that device.
1247 */ 1255 */
1248 1256
1249 consumer = *(adapter->cmd_consumer); 1257 consumer = le32_to_cpu(*(adapter->cmd_consumer));
1250 if (last_consumer == consumer) { /* Ring is empty */ 1258 if (last_consumer == consumer) { /* Ring is empty */
1251 DPRINTK(INFO, "last_consumer %d == consumer %d\n", 1259 DPRINTK(INFO, "last_consumer %d == consumer %d\n",
1252 last_consumer, consumer); 1260 last_consumer, consumer);
@@ -1340,7 +1348,7 @@ int netxen_process_cmd_ring(unsigned long data)
1340 if (adapter->last_cmd_consumer == consumer && 1348 if (adapter->last_cmd_consumer == consumer &&
1341 (((adapter->cmd_producer + 1) % 1349 (((adapter->cmd_producer + 1) %
1342 adapter->max_tx_desc_count) == adapter->last_cmd_consumer)) { 1350 adapter->max_tx_desc_count) == adapter->last_cmd_consumer)) {
1343 consumer = *(adapter->cmd_consumer); 1351 consumer = le32_to_cpu(*(adapter->cmd_consumer));
1344 } 1352 }
1345 done = (adapter->last_cmd_consumer == consumer); 1353 done = (adapter->last_cmd_consumer == consumer);
1346 1354
diff --git a/drivers/net/netxen/netxen_nic_main.c b/drivers/net/netxen/netxen_nic_main.c
index 36ba6a1aa363..225ff55527c4 100644
--- a/drivers/net/netxen/netxen_nic_main.c
+++ b/drivers/net/netxen/netxen_nic_main.c
@@ -434,12 +434,13 @@ netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
434 adapter->port_count++; 434 adapter->port_count++;
435 adapter->port[i] = port; 435 adapter->port[i] = port;
436 } 436 }
437 437#ifndef CONFIG_PPC64
438 writel(0, NETXEN_CRB_NORMALIZE(adapter, CRB_CMDPEG_STATE)); 438 writel(0, NETXEN_CRB_NORMALIZE(adapter, CRB_CMDPEG_STATE));
439 netxen_pinit_from_rom(adapter, 0); 439 netxen_pinit_from_rom(adapter, 0);
440 udelay(500); 440 udelay(500);
441 netxen_load_firmware(adapter); 441 netxen_load_firmware(adapter);
442 netxen_phantom_init(adapter, NETXEN_NIC_PEG_TUNE); 442 netxen_phantom_init(adapter, NETXEN_NIC_PEG_TUNE);
443#endif
443 /* 444 /*
444 * delay a while to ensure that the Pegs are up & running. 445 * delay a while to ensure that the Pegs are up & running.
445 * Otherwise, we might see some flaky behaviour. 446 * Otherwise, we might see some flaky behaviour.
diff --git a/drivers/net/netxen/netxen_nic_niu.c b/drivers/net/netxen/netxen_nic_niu.c
index 40d7003a371c..d5d95074e569 100644
--- a/drivers/net/netxen/netxen_nic_niu.c
+++ b/drivers/net/netxen/netxen_nic_niu.c
@@ -458,7 +458,7 @@ int netxen_niu_gbe_init_port(struct netxen_adapter *adapter, int port)
458 458
459int netxen_niu_xg_init_port(struct netxen_adapter *adapter, int port) 459int netxen_niu_xg_init_port(struct netxen_adapter *adapter, int port)
460{ 460{
461 long reg = 0, ret = 0; 461 u32 reg = 0, ret = 0;
462 462
463 if (adapter->ahw.boardcfg.board_type == NETXEN_BRDTYPE_P2_SB31_10G_IMEZ) { 463 if (adapter->ahw.boardcfg.board_type == NETXEN_BRDTYPE_P2_SB31_10G_IMEZ) {
464 netxen_crb_writelit_adapter(adapter, 464 netxen_crb_writelit_adapter(adapter,
diff --git a/drivers/net/pcmcia/3c574_cs.c b/drivers/net/pcmcia/3c574_cs.c
index 448bf4a78016..c7bd9c1c7f31 100644
--- a/drivers/net/pcmcia/3c574_cs.c
+++ b/drivers/net/pcmcia/3c574_cs.c
@@ -915,7 +915,7 @@ static void media_check(unsigned long arg)
915 if ((inw(ioaddr + EL3_STATUS) & IntLatch) && (inb(ioaddr + Timer) == 0xff)) { 915 if ((inw(ioaddr + EL3_STATUS) & IntLatch) && (inb(ioaddr + Timer) == 0xff)) {
916 if (!lp->fast_poll) 916 if (!lp->fast_poll)
917 printk(KERN_INFO "%s: interrupt(s) dropped!\n", dev->name); 917 printk(KERN_INFO "%s: interrupt(s) dropped!\n", dev->name);
918 el3_interrupt(dev->irq, lp); 918 el3_interrupt(dev->irq, dev);
919 lp->fast_poll = HZ; 919 lp->fast_poll = HZ;
920 } 920 }
921 if (lp->fast_poll) { 921 if (lp->fast_poll) {
diff --git a/drivers/net/pcmcia/smc91c92_cs.c b/drivers/net/pcmcia/smc91c92_cs.c
index 530df8883fe5..2561f76033ea 100644
--- a/drivers/net/pcmcia/smc91c92_cs.c
+++ b/drivers/net/pcmcia/smc91c92_cs.c
@@ -1927,7 +1927,7 @@ static void media_check(u_long arg)
1927 if (smc->watchdog++ && ((i>>8) & i)) { 1927 if (smc->watchdog++ && ((i>>8) & i)) {
1928 if (!smc->fast_poll) 1928 if (!smc->fast_poll)
1929 printk(KERN_INFO "%s: interrupt(s) dropped!\n", dev->name); 1929 printk(KERN_INFO "%s: interrupt(s) dropped!\n", dev->name);
1930 smc_interrupt(dev->irq, smc); 1930 smc_interrupt(dev->irq, dev);
1931 smc->fast_poll = HZ; 1931 smc->fast_poll = HZ;
1932 } 1932 }
1933 if (smc->fast_poll) { 1933 if (smc->fast_poll) {
diff --git a/drivers/net/phy/marvell.c b/drivers/net/phy/marvell.c
index f4d4eb659cad..22aec5cce683 100644
--- a/drivers/net/phy/marvell.c
+++ b/drivers/net/phy/marvell.c
@@ -42,6 +42,19 @@
42#define MII_M1011_IMASK_INIT 0x6400 42#define MII_M1011_IMASK_INIT 0x6400
43#define MII_M1011_IMASK_CLEAR 0x0000 43#define MII_M1011_IMASK_CLEAR 0x0000
44 44
45#define MII_M1011_PHY_SCR 0x10
46#define MII_M1011_PHY_SCR_AUTO_CROSS 0x0060
47
48#define MII_M1145_PHY_EXT_CR 0x14
49#define MII_M1145_RGMII_RX_DELAY 0x0080
50#define MII_M1145_RGMII_TX_DELAY 0x0002
51
52#define M1145_DEV_FLAGS_RESISTANCE 0x00000001
53
54#define MII_M1111_PHY_LED_CONTROL 0x18
55#define MII_M1111_PHY_LED_DIRECT 0x4100
56#define MII_M1111_PHY_LED_COMBINE 0x411c
57
45MODULE_DESCRIPTION("Marvell PHY driver"); 58MODULE_DESCRIPTION("Marvell PHY driver");
46MODULE_AUTHOR("Andy Fleming"); 59MODULE_AUTHOR("Andy Fleming");
47MODULE_LICENSE("GPL"); 60MODULE_LICENSE("GPL");
@@ -63,7 +76,7 @@ static int marvell_config_intr(struct phy_device *phydev)
63{ 76{
64 int err; 77 int err;
65 78
66 if(phydev->interrupts == PHY_INTERRUPT_ENABLED) 79 if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
67 err = phy_write(phydev, MII_M1011_IMASK, MII_M1011_IMASK_INIT); 80 err = phy_write(phydev, MII_M1011_IMASK, MII_M1011_IMASK_INIT);
68 else 81 else
69 err = phy_write(phydev, MII_M1011_IMASK, MII_M1011_IMASK_CLEAR); 82 err = phy_write(phydev, MII_M1011_IMASK, MII_M1011_IMASK_CLEAR);
@@ -103,34 +116,153 @@ static int marvell_config_aneg(struct phy_device *phydev)
103 if (err < 0) 116 if (err < 0)
104 return err; 117 return err;
105 118
119 err = phy_write(phydev, MII_M1011_PHY_SCR,
120 MII_M1011_PHY_SCR_AUTO_CROSS);
121 if (err < 0)
122 return err;
123
124 err = phy_write(phydev, MII_M1111_PHY_LED_CONTROL,
125 MII_M1111_PHY_LED_DIRECT);
126 if (err < 0)
127 return err;
106 128
107 err = genphy_config_aneg(phydev); 129 err = genphy_config_aneg(phydev);
108 130
109 return err; 131 return err;
110} 132}
111 133
134static int m88e1145_config_init(struct phy_device *phydev)
135{
136 int err;
137
138 /* Take care of errata E0 & E1 */
139 err = phy_write(phydev, 0x1d, 0x001b);
140 if (err < 0)
141 return err;
142
143 err = phy_write(phydev, 0x1e, 0x418f);
144 if (err < 0)
145 return err;
146
147 err = phy_write(phydev, 0x1d, 0x0016);
148 if (err < 0)
149 return err;
150
151 err = phy_write(phydev, 0x1e, 0xa2da);
152 if (err < 0)
153 return err;
154
155 if (phydev->interface == PHY_INTERFACE_MODE_RGMII) {
156 int temp = phy_read(phydev, MII_M1145_PHY_EXT_CR);
157 if (temp < 0)
158 return temp;
159
160 temp |= (MII_M1145_RGMII_RX_DELAY | MII_M1145_RGMII_TX_DELAY);
161
162 err = phy_write(phydev, MII_M1145_PHY_EXT_CR, temp);
163 if (err < 0)
164 return err;
165
166 if (phydev->dev_flags & M1145_DEV_FLAGS_RESISTANCE) {
167 err = phy_write(phydev, 0x1d, 0x0012);
168 if (err < 0)
169 return err;
170
171 temp = phy_read(phydev, 0x1e);
172 if (temp < 0)
173 return temp;
174
175 temp &= 0xf03f;
176 temp |= 2 << 9; /* 36 ohm */
177 temp |= 2 << 6; /* 39 ohm */
178
179 err = phy_write(phydev, 0x1e, temp);
180 if (err < 0)
181 return err;
182
183 err = phy_write(phydev, 0x1d, 0x3);
184 if (err < 0)
185 return err;
186
187 err = phy_write(phydev, 0x1e, 0x8000);
188 if (err < 0)
189 return err;
190 }
191 }
192
193 return 0;
194}
112 195
113static struct phy_driver m88e1101_driver = { 196static struct phy_driver m88e1101_driver = {
114 .phy_id = 0x01410c00, 197 .phy_id = 0x01410c60,
115 .phy_id_mask = 0xffffff00, 198 .phy_id_mask = 0xfffffff0,
116 .name = "Marvell 88E1101", 199 .name = "Marvell 88E1101",
117 .features = PHY_GBIT_FEATURES, 200 .features = PHY_GBIT_FEATURES,
118 .flags = PHY_HAS_INTERRUPT, 201 .flags = PHY_HAS_INTERRUPT,
119 .config_aneg = &marvell_config_aneg, 202 .config_aneg = &marvell_config_aneg,
120 .read_status = &genphy_read_status, 203 .read_status = &genphy_read_status,
121 .ack_interrupt = &marvell_ack_interrupt, 204 .ack_interrupt = &marvell_ack_interrupt,
122 .config_intr = &marvell_config_intr, 205 .config_intr = &marvell_config_intr,
123 .driver = { .owner = THIS_MODULE,}, 206 .driver = {.owner = THIS_MODULE,},
207};
208
209static struct phy_driver m88e1111s_driver = {
210 .phy_id = 0x01410cc0,
211 .phy_id_mask = 0xfffffff0,
212 .name = "Marvell 88E1111",
213 .features = PHY_GBIT_FEATURES,
214 .flags = PHY_HAS_INTERRUPT,
215 .config_aneg = &marvell_config_aneg,
216 .read_status = &genphy_read_status,
217 .ack_interrupt = &marvell_ack_interrupt,
218 .config_intr = &marvell_config_intr,
219 .driver = {.owner = THIS_MODULE,},
220};
221
222static struct phy_driver m88e1145_driver = {
223 .phy_id = 0x01410cd0,
224 .phy_id_mask = 0xfffffff0,
225 .name = "Marvell 88E1145",
226 .features = PHY_GBIT_FEATURES,
227 .flags = PHY_HAS_INTERRUPT,
228 .config_init = &m88e1145_config_init,
229 .config_aneg = &marvell_config_aneg,
230 .read_status = &genphy_read_status,
231 .ack_interrupt = &marvell_ack_interrupt,
232 .config_intr = &marvell_config_intr,
233 .driver = {.owner = THIS_MODULE,},
124}; 234};
125 235
126static int __init marvell_init(void) 236static int __init marvell_init(void)
127{ 237{
128 return phy_driver_register(&m88e1101_driver); 238 int ret;
239
240 ret = phy_driver_register(&m88e1101_driver);
241 if (ret)
242 return ret;
243
244 ret = phy_driver_register(&m88e1111s_driver);
245 if (ret)
246 goto err1111s;
247
248 ret = phy_driver_register(&m88e1145_driver);
249 if (ret)
250 goto err1145;
251
252 return 0;
253
254 err1145:
255 phy_driver_unregister(&m88e1111s_driver);
256 err1111s:
257 phy_driver_unregister(&m88e1101_driver);
258 return ret;
129} 259}
130 260
131static void __exit marvell_exit(void) 261static void __exit marvell_exit(void)
132{ 262{
133 phy_driver_unregister(&m88e1101_driver); 263 phy_driver_unregister(&m88e1101_driver);
264 phy_driver_unregister(&m88e1111s_driver);
265 phy_driver_unregister(&m88e1145_driver);
134} 266}
135 267
136module_init(marvell_init); 268module_init(marvell_init);
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index fdf45fdb6731..7d5b6d1838c8 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -138,7 +138,7 @@ void phy_prepare_link(struct phy_device *phydev,
138 */ 138 */
139struct phy_device * phy_connect(struct net_device *dev, const char *phy_id, 139struct phy_device * phy_connect(struct net_device *dev, const char *phy_id,
140 void (*handler)(struct net_device *), u32 flags, 140 void (*handler)(struct net_device *), u32 flags,
141 u32 interface) 141 phy_interface_t interface)
142{ 142{
143 struct phy_device *phydev; 143 struct phy_device *phydev;
144 144
@@ -187,7 +187,7 @@ static int phy_compare_id(struct device *dev, void *data)
187} 187}
188 188
189struct phy_device *phy_attach(struct net_device *dev, 189struct phy_device *phy_attach(struct net_device *dev,
190 const char *phy_id, u32 flags, u32 interface) 190 const char *phy_id, u32 flags, phy_interface_t interface)
191{ 191{
192 struct bus_type *bus = &mdio_bus_type; 192 struct bus_type *bus = &mdio_bus_type;
193 struct phy_device *phydev; 193 struct phy_device *phydev;
diff --git a/drivers/net/sk98lin/skge.c b/drivers/net/sk98lin/skge.c
index 92d11b961db8..e94ab256b540 100644
--- a/drivers/net/sk98lin/skge.c
+++ b/drivers/net/sk98lin/skge.c
@@ -5188,6 +5188,9 @@ static struct pci_driver skge_driver = {
5188 5188
5189static int __init skge_init(void) 5189static int __init skge_init(void)
5190{ 5190{
5191 printk(KERN_NOTICE "sk98lin: driver has been replaced by the skge driver"
5192 " and is scheduled for removal\n");
5193
5191 return pci_register_driver(&skge_driver); 5194 return pci_register_driver(&skge_driver);
5192} 5195}
5193 5196
diff --git a/drivers/net/sky2.c b/drivers/net/sky2.c
index f2ab3d56e565..52edbd7ac17e 100644
--- a/drivers/net/sky2.c
+++ b/drivers/net/sky2.c
@@ -49,7 +49,7 @@
49#include "sky2.h" 49#include "sky2.h"
50 50
51#define DRV_NAME "sky2" 51#define DRV_NAME "sky2"
52#define DRV_VERSION "1.12" 52#define DRV_VERSION "1.13"
53#define PFX DRV_NAME " " 53#define PFX DRV_NAME " "
54 54
55/* 55/*
@@ -1742,13 +1742,6 @@ static void sky2_link_down(struct sky2_port *sky2)
1742 reg &= ~(GM_GPCR_RX_ENA | GM_GPCR_TX_ENA); 1742 reg &= ~(GM_GPCR_RX_ENA | GM_GPCR_TX_ENA);
1743 gma_write16(hw, port, GM_GP_CTRL, reg); 1743 gma_write16(hw, port, GM_GP_CTRL, reg);
1744 1744
1745 if (sky2->flow_status == FC_RX) {
1746 /* restore Asymmetric Pause bit */
1747 gm_phy_write(hw, port, PHY_MARV_AUNE_ADV,
1748 gm_phy_read(hw, port, PHY_MARV_AUNE_ADV)
1749 | PHY_M_AN_ASP);
1750 }
1751
1752 netif_carrier_off(sky2->netdev); 1745 netif_carrier_off(sky2->netdev);
1753 netif_stop_queue(sky2->netdev); 1746 netif_stop_queue(sky2->netdev);
1754 1747
@@ -1773,10 +1766,10 @@ static int sky2_autoneg_done(struct sky2_port *sky2, u16 aux)
1773{ 1766{
1774 struct sky2_hw *hw = sky2->hw; 1767 struct sky2_hw *hw = sky2->hw;
1775 unsigned port = sky2->port; 1768 unsigned port = sky2->port;
1776 u16 lpa; 1769 u16 advert, lpa;
1777 1770
1771 advert = gm_phy_read(hw, port, PHY_MARV_AUNE_ADV);
1778 lpa = gm_phy_read(hw, port, PHY_MARV_AUNE_LP); 1772 lpa = gm_phy_read(hw, port, PHY_MARV_AUNE_LP);
1779
1780 if (lpa & PHY_M_AN_RF) { 1773 if (lpa & PHY_M_AN_RF) {
1781 printk(KERN_ERR PFX "%s: remote fault", sky2->netdev->name); 1774 printk(KERN_ERR PFX "%s: remote fault", sky2->netdev->name);
1782 return -1; 1775 return -1;
@@ -1791,20 +1784,40 @@ static int sky2_autoneg_done(struct sky2_port *sky2, u16 aux)
1791 sky2->speed = sky2_phy_speed(hw, aux); 1784 sky2->speed = sky2_phy_speed(hw, aux);
1792 sky2->duplex = (aux & PHY_M_PS_FULL_DUP) ? DUPLEX_FULL : DUPLEX_HALF; 1785 sky2->duplex = (aux & PHY_M_PS_FULL_DUP) ? DUPLEX_FULL : DUPLEX_HALF;
1793 1786
1794 /* Pause bits are offset (9..8) */ 1787 /* Since the pause result bits seem to in different positions on
1795 if (hw->chip_id == CHIP_ID_YUKON_XL 1788 * different chips. look at registers.
1796 || hw->chip_id == CHIP_ID_YUKON_EC_U 1789 */
1797 || hw->chip_id == CHIP_ID_YUKON_EX) 1790 if (!sky2_is_copper(hw)) {
1798 aux >>= 6; 1791 /* Shift for bits in fiber PHY */
1799 1792 advert &= ~(ADVERTISE_PAUSE_CAP|ADVERTISE_PAUSE_ASYM);
1800 sky2->flow_status = sky2_flow(aux & PHY_M_PS_RX_P_EN, 1793 lpa &= ~(LPA_PAUSE_CAP|LPA_PAUSE_ASYM);
1801 aux & PHY_M_PS_TX_P_EN); 1794
1795 if (advert & ADVERTISE_1000XPAUSE)
1796 advert |= ADVERTISE_PAUSE_CAP;
1797 if (advert & ADVERTISE_1000XPSE_ASYM)
1798 advert |= ADVERTISE_PAUSE_ASYM;
1799 if (lpa & LPA_1000XPAUSE)
1800 lpa |= LPA_PAUSE_CAP;
1801 if (lpa & LPA_1000XPAUSE_ASYM)
1802 lpa |= LPA_PAUSE_ASYM;
1803 }
1804
1805 sky2->flow_status = FC_NONE;
1806 if (advert & ADVERTISE_PAUSE_CAP) {
1807 if (lpa & LPA_PAUSE_CAP)
1808 sky2->flow_status = FC_BOTH;
1809 else if (advert & ADVERTISE_PAUSE_ASYM)
1810 sky2->flow_status = FC_RX;
1811 } else if (advert & ADVERTISE_PAUSE_ASYM) {
1812 if ((lpa & LPA_PAUSE_CAP) && (lpa & LPA_PAUSE_ASYM))
1813 sky2->flow_status = FC_TX;
1814 }
1802 1815
1803 if (sky2->duplex == DUPLEX_HALF && sky2->speed < SPEED_1000 1816 if (sky2->duplex == DUPLEX_HALF && sky2->speed < SPEED_1000
1804 && !(hw->chip_id == CHIP_ID_YUKON_EC_U || hw->chip_id == CHIP_ID_YUKON_EX)) 1817 && !(hw->chip_id == CHIP_ID_YUKON_EC_U || hw->chip_id == CHIP_ID_YUKON_EX))
1805 sky2->flow_status = FC_NONE; 1818 sky2->flow_status = FC_NONE;
1806 1819
1807 if (aux & PHY_M_PS_RX_P_EN) 1820 if (sky2->flow_status & FC_TX)
1808 sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_ON); 1821 sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_ON);
1809 else 1822 else
1810 sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_OFF); 1823 sky2_write8(hw, SK_REG(port, GMAC_CTRL), GMC_PAUSE_OFF);
@@ -1853,16 +1866,13 @@ out:
1853 spin_unlock(&sky2->phy_lock); 1866 spin_unlock(&sky2->phy_lock);
1854} 1867}
1855 1868
1856
1857/* Transmit timeout is only called if we are running, carrier is up 1869/* Transmit timeout is only called if we are running, carrier is up
1858 * and tx queue is full (stopped). 1870 * and tx queue is full (stopped).
1859 * Called with netif_tx_lock held.
1860 */ 1871 */
1861static void sky2_tx_timeout(struct net_device *dev) 1872static void sky2_tx_timeout(struct net_device *dev)
1862{ 1873{
1863 struct sky2_port *sky2 = netdev_priv(dev); 1874 struct sky2_port *sky2 = netdev_priv(dev);
1864 struct sky2_hw *hw = sky2->hw; 1875 struct sky2_hw *hw = sky2->hw;
1865 u32 imask;
1866 1876
1867 if (netif_msg_timer(sky2)) 1877 if (netif_msg_timer(sky2))
1868 printk(KERN_ERR PFX "%s: tx timeout\n", dev->name); 1878 printk(KERN_ERR PFX "%s: tx timeout\n", dev->name);
@@ -1872,19 +1882,8 @@ static void sky2_tx_timeout(struct net_device *dev)
1872 sky2_read16(hw, sky2->port == 0 ? STAT_TXA1_RIDX : STAT_TXA2_RIDX), 1882 sky2_read16(hw, sky2->port == 0 ? STAT_TXA1_RIDX : STAT_TXA2_RIDX),
1873 sky2_read16(hw, Q_ADDR(txqaddr[sky2->port], Q_DONE))); 1883 sky2_read16(hw, Q_ADDR(txqaddr[sky2->port], Q_DONE)));
1874 1884
1875 imask = sky2_read32(hw, B0_IMSK); /* block IRQ in hw */ 1885 /* can't restart safely under softirq */
1876 sky2_write32(hw, B0_IMSK, 0); 1886 schedule_work(&hw->restart_work);
1877 sky2_read32(hw, B0_IMSK);
1878
1879 netif_poll_disable(hw->dev[0]); /* stop NAPI poll */
1880 synchronize_irq(hw->pdev->irq);
1881
1882 netif_start_queue(dev); /* don't wakeup during flush */
1883 sky2_tx_complete(sky2, sky2->tx_prod); /* Flush transmit queue */
1884
1885 sky2_write32(hw, B0_IMSK, imask);
1886
1887 sky2_phy_reinit(sky2); /* this clears flow control etc */
1888} 1887}
1889 1888
1890static int sky2_change_mtu(struct net_device *dev, int new_mtu) 1889static int sky2_change_mtu(struct net_device *dev, int new_mtu)
@@ -2057,9 +2056,6 @@ static struct sk_buff *sky2_receive(struct net_device *dev,
2057 if (!(status & GMR_FS_RX_OK)) 2056 if (!(status & GMR_FS_RX_OK))
2058 goto resubmit; 2057 goto resubmit;
2059 2058
2060 if (length > dev->mtu + ETH_HLEN)
2061 goto oversize;
2062
2063 if (length < copybreak) 2059 if (length < copybreak)
2064 skb = receive_copy(sky2, re, length); 2060 skb = receive_copy(sky2, re, length);
2065 else 2061 else
@@ -2069,14 +2065,10 @@ resubmit:
2069 2065
2070 return skb; 2066 return skb;
2071 2067
2072oversize:
2073 ++sky2->net_stats.rx_over_errors;
2074 goto resubmit;
2075
2076error: 2068error:
2077 ++sky2->net_stats.rx_errors; 2069 ++sky2->net_stats.rx_errors;
2078 if (status & GMR_FS_RX_FF_OV) { 2070 if (status & GMR_FS_RX_FF_OV) {
2079 sky2->net_stats.rx_fifo_errors++; 2071 sky2->net_stats.rx_over_errors++;
2080 goto resubmit; 2072 goto resubmit;
2081 } 2073 }
2082 2074
@@ -2638,6 +2630,49 @@ static void sky2_reset(struct sky2_hw *hw)
2638 sky2_write8(hw, STAT_ISR_TIMER_CTRL, TIM_START); 2630 sky2_write8(hw, STAT_ISR_TIMER_CTRL, TIM_START);
2639} 2631}
2640 2632
2633static void sky2_restart(struct work_struct *work)
2634{
2635 struct sky2_hw *hw = container_of(work, struct sky2_hw, restart_work);
2636 struct net_device *dev;
2637 int i, err;
2638
2639 dev_dbg(&hw->pdev->dev, "restarting\n");
2640
2641 del_timer_sync(&hw->idle_timer);
2642
2643 rtnl_lock();
2644 sky2_write32(hw, B0_IMSK, 0);
2645 sky2_read32(hw, B0_IMSK);
2646
2647 netif_poll_disable(hw->dev[0]);
2648
2649 for (i = 0; i < hw->ports; i++) {
2650 dev = hw->dev[i];
2651 if (netif_running(dev))
2652 sky2_down(dev);
2653 }
2654
2655 sky2_reset(hw);
2656 sky2_write32(hw, B0_IMSK, Y2_IS_BASE);
2657 netif_poll_enable(hw->dev[0]);
2658
2659 for (i = 0; i < hw->ports; i++) {
2660 dev = hw->dev[i];
2661 if (netif_running(dev)) {
2662 err = sky2_up(dev);
2663 if (err) {
2664 printk(KERN_INFO PFX "%s: could not restart %d\n",
2665 dev->name, err);
2666 dev_close(dev);
2667 }
2668 }
2669 }
2670
2671 sky2_idle_start(hw);
2672
2673 rtnl_unlock();
2674}
2675
2641static inline u8 sky2_wol_supported(const struct sky2_hw *hw) 2676static inline u8 sky2_wol_supported(const struct sky2_hw *hw)
2642{ 2677{
2643 return sky2_is_copper(hw) ? (WAKE_PHY | WAKE_MAGIC) : 0; 2678 return sky2_is_copper(hw) ? (WAKE_PHY | WAKE_MAGIC) : 0;
@@ -3600,6 +3635,8 @@ static int __devinit sky2_probe(struct pci_dev *pdev,
3600 } 3635 }
3601 3636
3602 setup_timer(&hw->idle_timer, sky2_idle, (unsigned long) hw); 3637 setup_timer(&hw->idle_timer, sky2_idle, (unsigned long) hw);
3638 INIT_WORK(&hw->restart_work, sky2_restart);
3639
3603 sky2_idle_start(hw); 3640 sky2_idle_start(hw);
3604 3641
3605 pci_set_drvdata(pdev, hw); 3642 pci_set_drvdata(pdev, hw);
@@ -3636,6 +3673,8 @@ static void __devexit sky2_remove(struct pci_dev *pdev)
3636 3673
3637 del_timer_sync(&hw->idle_timer); 3674 del_timer_sync(&hw->idle_timer);
3638 3675
3676 flush_scheduled_work();
3677
3639 sky2_write32(hw, B0_IMSK, 0); 3678 sky2_write32(hw, B0_IMSK, 0);
3640 synchronize_irq(hw->pdev->irq); 3679 synchronize_irq(hw->pdev->irq);
3641 3680
diff --git a/drivers/net/sky2.h b/drivers/net/sky2.h
index 3b0189569d52..ac24bdc42976 100644
--- a/drivers/net/sky2.h
+++ b/drivers/net/sky2.h
@@ -1589,7 +1589,7 @@ enum {
1589 1589
1590 GMR_FS_ANY_ERR = GMR_FS_RX_FF_OV | GMR_FS_CRC_ERR | 1590 GMR_FS_ANY_ERR = GMR_FS_RX_FF_OV | GMR_FS_CRC_ERR |
1591 GMR_FS_FRAGMENT | GMR_FS_LONG_ERR | 1591 GMR_FS_FRAGMENT | GMR_FS_LONG_ERR |
1592 GMR_FS_MII_ERR | GMR_FS_GOOD_FC | GMR_FS_BAD_FC | 1592 GMR_FS_MII_ERR | GMR_FS_BAD_FC |
1593 GMR_FS_UN_SIZE | GMR_FS_JABBER, 1593 GMR_FS_UN_SIZE | GMR_FS_JABBER,
1594}; 1594};
1595 1595
@@ -1933,6 +1933,7 @@ struct sky2_hw {
1933 dma_addr_t st_dma; 1933 dma_addr_t st_dma;
1934 1934
1935 struct timer_list idle_timer; 1935 struct timer_list idle_timer;
1936 struct work_struct restart_work;
1936 int msi; 1937 int msi;
1937 wait_queue_head_t msi_wait; 1938 wait_queue_head_t msi_wait;
1938}; 1939};
diff --git a/drivers/net/wan/Kconfig b/drivers/net/wan/Kconfig
index 61708cf4c85d..8897f538a7c7 100644
--- a/drivers/net/wan/Kconfig
+++ b/drivers/net/wan/Kconfig
@@ -26,7 +26,7 @@ config WAN
26# There is no way to detect a comtrol sv11 - force it modular for now. 26# There is no way to detect a comtrol sv11 - force it modular for now.
27config HOSTESS_SV11 27config HOSTESS_SV11
28 tristate "Comtrol Hostess SV-11 support" 28 tristate "Comtrol Hostess SV-11 support"
29 depends on WAN && ISA && m && ISA_DMA_API 29 depends on WAN && ISA && m && ISA_DMA_API && INET
30 help 30 help
31 Driver for Comtrol Hostess SV-11 network card which 31 Driver for Comtrol Hostess SV-11 network card which
32 operates on low speed synchronous serial links at up to 32 operates on low speed synchronous serial links at up to
diff --git a/drivers/net/wan/pc300too.c b/drivers/net/wan/pc300too.c
index bc156b51678a..aff05dba720a 100644
--- a/drivers/net/wan/pc300too.c
+++ b/drivers/net/wan/pc300too.c
@@ -542,7 +542,7 @@ static int __init pc300_init_module(void)
542 542
543 CLOCK_BASE = use_crystal_clock ? 24576000 : pci_clock_freq; 543 CLOCK_BASE = use_crystal_clock ? 24576000 : pci_clock_freq;
544 544
545 return pci_module_init(&pc300_pci_driver); 545 return pci_register_driver(&pc300_pci_driver);
546} 546}
547 547
548 548
diff --git a/drivers/net/wireless/bcm43xx/bcm43xx.h b/drivers/net/wireless/bcm43xx/bcm43xx.h
index 3a064def162e..0e790efae683 100644
--- a/drivers/net/wireless/bcm43xx/bcm43xx.h
+++ b/drivers/net/wireless/bcm43xx/bcm43xx.h
@@ -771,6 +771,7 @@ struct bcm43xx_private {
771 * This is currently always BCM43xx_BUSTYPE_PCI 771 * This is currently always BCM43xx_BUSTYPE_PCI
772 */ 772 */
773 u8 bustype; 773 u8 bustype;
774 u64 dma_mask;
774 775
775 u16 board_vendor; 776 u16 board_vendor;
776 u16 board_type; 777 u16 board_type;
diff --git a/drivers/net/wireless/bcm43xx/bcm43xx_dma.c b/drivers/net/wireless/bcm43xx/bcm43xx_dma.c
index 978ed099e285..6e0dc76400e5 100644
--- a/drivers/net/wireless/bcm43xx/bcm43xx_dma.c
+++ b/drivers/net/wireless/bcm43xx/bcm43xx_dma.c
@@ -145,16 +145,14 @@ dma_addr_t map_descbuffer(struct bcm43xx_dmaring *ring,
145 int tx) 145 int tx)
146{ 146{
147 dma_addr_t dmaaddr; 147 dma_addr_t dmaaddr;
148 int direction = PCI_DMA_FROMDEVICE;
148 149
149 if (tx) { 150 if (tx)
150 dmaaddr = dma_map_single(&ring->bcm->pci_dev->dev, 151 direction = PCI_DMA_TODEVICE;
151 buf, len, 152
152 DMA_TO_DEVICE); 153 dmaaddr = pci_map_single(ring->bcm->pci_dev,
153 } else {
154 dmaaddr = dma_map_single(&ring->bcm->pci_dev->dev,
155 buf, len, 154 buf, len,
156 DMA_FROM_DEVICE); 155 direction);
157 }
158 156
159 return dmaaddr; 157 return dmaaddr;
160} 158}
@@ -166,13 +164,13 @@ void unmap_descbuffer(struct bcm43xx_dmaring *ring,
166 int tx) 164 int tx)
167{ 165{
168 if (tx) { 166 if (tx) {
169 dma_unmap_single(&ring->bcm->pci_dev->dev, 167 pci_unmap_single(ring->bcm->pci_dev,
170 addr, len, 168 addr, len,
171 DMA_TO_DEVICE); 169 PCI_DMA_TODEVICE);
172 } else { 170 } else {
173 dma_unmap_single(&ring->bcm->pci_dev->dev, 171 pci_unmap_single(ring->bcm->pci_dev,
174 addr, len, 172 addr, len,
175 DMA_FROM_DEVICE); 173 PCI_DMA_FROMDEVICE);
176 } 174 }
177} 175}
178 176
@@ -183,8 +181,8 @@ void sync_descbuffer_for_cpu(struct bcm43xx_dmaring *ring,
183{ 181{
184 assert(!ring->tx); 182 assert(!ring->tx);
185 183
186 dma_sync_single_for_cpu(&ring->bcm->pci_dev->dev, 184 pci_dma_sync_single_for_cpu(ring->bcm->pci_dev,
187 addr, len, DMA_FROM_DEVICE); 185 addr, len, PCI_DMA_FROMDEVICE);
188} 186}
189 187
190static inline 188static inline
@@ -194,8 +192,8 @@ void sync_descbuffer_for_device(struct bcm43xx_dmaring *ring,
194{ 192{
195 assert(!ring->tx); 193 assert(!ring->tx);
196 194
197 dma_sync_single_for_device(&ring->bcm->pci_dev->dev, 195 pci_dma_sync_single_for_cpu(ring->bcm->pci_dev,
198 addr, len, DMA_FROM_DEVICE); 196 addr, len, PCI_DMA_TODEVICE);
199} 197}
200 198
201/* Unmap and free a descriptor buffer. */ 199/* Unmap and free a descriptor buffer. */
@@ -214,17 +212,53 @@ void free_descriptor_buffer(struct bcm43xx_dmaring *ring,
214 212
215static int alloc_ringmemory(struct bcm43xx_dmaring *ring) 213static int alloc_ringmemory(struct bcm43xx_dmaring *ring)
216{ 214{
217 struct device *dev = &(ring->bcm->pci_dev->dev); 215 ring->descbase = pci_alloc_consistent(ring->bcm->pci_dev, BCM43xx_DMA_RINGMEMSIZE,
218 216 &(ring->dmabase));
219 ring->descbase = dma_alloc_coherent(dev, BCM43xx_DMA_RINGMEMSIZE,
220 &(ring->dmabase), GFP_KERNEL);
221 if (!ring->descbase) { 217 if (!ring->descbase) {
222 printk(KERN_ERR PFX "DMA ringmemory allocation failed\n"); 218 /* Allocation may have failed due to pci_alloc_consistent
223 return -ENOMEM; 219 insisting on use of GFP_DMA, which is more restrictive
220 than necessary... */
221 struct dma_desc *rx_ring;
222 dma_addr_t rx_ring_dma;
223
224 rx_ring = kzalloc(BCM43xx_DMA_RINGMEMSIZE, GFP_KERNEL);
225 if (!rx_ring)
226 goto out_err;
227
228 rx_ring_dma = pci_map_single(ring->bcm->pci_dev, rx_ring,
229 BCM43xx_DMA_RINGMEMSIZE,
230 PCI_DMA_BIDIRECTIONAL);
231
232 if (pci_dma_mapping_error(rx_ring_dma) ||
233 rx_ring_dma + BCM43xx_DMA_RINGMEMSIZE > ring->bcm->dma_mask) {
234 /* Sigh... */
235 if (!pci_dma_mapping_error(rx_ring_dma))
236 pci_unmap_single(ring->bcm->pci_dev,
237 rx_ring_dma, BCM43xx_DMA_RINGMEMSIZE,
238 PCI_DMA_BIDIRECTIONAL);
239 rx_ring_dma = pci_map_single(ring->bcm->pci_dev,
240 rx_ring, BCM43xx_DMA_RINGMEMSIZE,
241 PCI_DMA_BIDIRECTIONAL);
242 if (pci_dma_mapping_error(rx_ring_dma) ||
243 rx_ring_dma + BCM43xx_DMA_RINGMEMSIZE > ring->bcm->dma_mask) {
244 assert(0);
245 if (!pci_dma_mapping_error(rx_ring_dma))
246 pci_unmap_single(ring->bcm->pci_dev,
247 rx_ring_dma, BCM43xx_DMA_RINGMEMSIZE,
248 PCI_DMA_BIDIRECTIONAL);
249 goto out_err;
250 }
251 }
252
253 ring->descbase = rx_ring;
254 ring->dmabase = rx_ring_dma;
224 } 255 }
225 memset(ring->descbase, 0, BCM43xx_DMA_RINGMEMSIZE); 256 memset(ring->descbase, 0, BCM43xx_DMA_RINGMEMSIZE);
226 257
227 return 0; 258 return 0;
259out_err:
260 printk(KERN_ERR PFX "DMA ringmemory allocation failed\n");
261 return -ENOMEM;
228} 262}
229 263
230static void free_ringmemory(struct bcm43xx_dmaring *ring) 264static void free_ringmemory(struct bcm43xx_dmaring *ring)
@@ -407,6 +441,29 @@ static int setup_rx_descbuffer(struct bcm43xx_dmaring *ring,
407 if (unlikely(!skb)) 441 if (unlikely(!skb))
408 return -ENOMEM; 442 return -ENOMEM;
409 dmaaddr = map_descbuffer(ring, skb->data, ring->rx_buffersize, 0); 443 dmaaddr = map_descbuffer(ring, skb->data, ring->rx_buffersize, 0);
444 /* This hardware bug work-around adapted from the b44 driver.
445 The chip may be unable to do PCI DMA to/from anything above 1GB */
446 if (pci_dma_mapping_error(dmaaddr) ||
447 dmaaddr + ring->rx_buffersize > ring->bcm->dma_mask) {
448 /* This one has 30-bit addressing... */
449 if (!pci_dma_mapping_error(dmaaddr))
450 pci_unmap_single(ring->bcm->pci_dev,
451 dmaaddr, ring->rx_buffersize,
452 PCI_DMA_FROMDEVICE);
453 dev_kfree_skb_any(skb);
454 skb = __dev_alloc_skb(ring->rx_buffersize,GFP_DMA);
455 if (skb == NULL)
456 return -ENOMEM;
457 dmaaddr = pci_map_single(ring->bcm->pci_dev,
458 skb->data, ring->rx_buffersize,
459 PCI_DMA_FROMDEVICE);
460 if (pci_dma_mapping_error(dmaaddr) ||
461 dmaaddr + ring->rx_buffersize > ring->bcm->dma_mask) {
462 assert(0);
463 dev_kfree_skb_any(skb);
464 return -ENOMEM;
465 }
466 }
410 meta->skb = skb; 467 meta->skb = skb;
411 meta->dmaaddr = dmaaddr; 468 meta->dmaaddr = dmaaddr;
412 skb->dev = ring->bcm->net_dev; 469 skb->dev = ring->bcm->net_dev;
@@ -636,8 +693,10 @@ struct bcm43xx_dmaring * bcm43xx_setup_dmaring(struct bcm43xx_private *bcm,
636 err = dmacontroller_setup(ring); 693 err = dmacontroller_setup(ring);
637 if (err) 694 if (err)
638 goto err_free_ringmemory; 695 goto err_free_ringmemory;
696 return ring;
639 697
640out: 698out:
699 printk(KERN_ERR PFX "Error in bcm43xx_setup_dmaring\n");
641 return ring; 700 return ring;
642 701
643err_free_ringmemory: 702err_free_ringmemory:
@@ -705,30 +764,16 @@ int bcm43xx_dma_init(struct bcm43xx_private *bcm)
705 struct bcm43xx_dmaring *ring; 764 struct bcm43xx_dmaring *ring;
706 int err = -ENOMEM; 765 int err = -ENOMEM;
707 int dma64 = 0; 766 int dma64 = 0;
708 u64 mask = bcm43xx_get_supported_dma_mask(bcm);
709 int nobits;
710 767
711 if (mask == DMA_64BIT_MASK) { 768 bcm->dma_mask = bcm43xx_get_supported_dma_mask(bcm);
769 if (bcm->dma_mask == DMA_64BIT_MASK)
712 dma64 = 1; 770 dma64 = 1;
713 nobits = 64; 771 err = pci_set_dma_mask(bcm->pci_dev, bcm->dma_mask);
714 } else if (mask == DMA_32BIT_MASK) 772 if (err)
715 nobits = 32; 773 goto no_dma;
716 else 774 err = pci_set_consistent_dma_mask(bcm->pci_dev, bcm->dma_mask);
717 nobits = 30; 775 if (err)
718 err = pci_set_dma_mask(bcm->pci_dev, mask); 776 goto no_dma;
719 err |= pci_set_consistent_dma_mask(bcm->pci_dev, mask);
720 if (err) {
721#ifdef CONFIG_BCM43XX_PIO
722 printk(KERN_WARNING PFX "DMA not supported on this device."
723 " Falling back to PIO.\n");
724 bcm->__using_pio = 1;
725 return -ENOSYS;
726#else
727 printk(KERN_ERR PFX "FATAL: DMA not supported and PIO not configured. "
728 "Please recompile the driver with PIO support.\n");
729 return -ENODEV;
730#endif /* CONFIG_BCM43XX_PIO */
731 }
732 777
733 /* setup TX DMA channels. */ 778 /* setup TX DMA channels. */
734 ring = bcm43xx_setup_dmaring(bcm, 0, 1, dma64); 779 ring = bcm43xx_setup_dmaring(bcm, 0, 1, dma64);
@@ -774,7 +819,9 @@ int bcm43xx_dma_init(struct bcm43xx_private *bcm)
774 dma->rx_ring3 = ring; 819 dma->rx_ring3 = ring;
775 } 820 }
776 821
777 dprintk(KERN_INFO PFX "%d-bit DMA initialized\n", nobits); 822 dprintk(KERN_INFO PFX "%d-bit DMA initialized\n",
823 (bcm->dma_mask == DMA_64BIT_MASK) ? 64 :
824 (bcm->dma_mask == DMA_32BIT_MASK) ? 32 : 30);
778 err = 0; 825 err = 0;
779out: 826out:
780 return err; 827 return err;
@@ -800,7 +847,17 @@ err_destroy_tx1:
800err_destroy_tx0: 847err_destroy_tx0:
801 bcm43xx_destroy_dmaring(dma->tx_ring0); 848 bcm43xx_destroy_dmaring(dma->tx_ring0);
802 dma->tx_ring0 = NULL; 849 dma->tx_ring0 = NULL;
803 goto out; 850no_dma:
851#ifdef CONFIG_BCM43XX_PIO
852 printk(KERN_WARNING PFX "DMA not supported on this device."
853 " Falling back to PIO.\n");
854 bcm->__using_pio = 1;
855 return -ENOSYS;
856#else
857 printk(KERN_ERR PFX "FATAL: DMA not supported and PIO not configured. "
858 "Please recompile the driver with PIO support.\n");
859 return -ENODEV;
860#endif /* CONFIG_BCM43XX_PIO */
804} 861}
805 862
806/* Generate a cookie for the TX header. */ 863/* Generate a cookie for the TX header. */
@@ -905,6 +962,7 @@ static void dma_tx_fragment(struct bcm43xx_dmaring *ring,
905 struct bcm43xx_dmadesc_generic *desc; 962 struct bcm43xx_dmadesc_generic *desc;
906 struct bcm43xx_dmadesc_meta *meta; 963 struct bcm43xx_dmadesc_meta *meta;
907 dma_addr_t dmaaddr; 964 dma_addr_t dmaaddr;
965 struct sk_buff *bounce_skb;
908 966
909 assert(skb_shinfo(skb)->nr_frags == 0); 967 assert(skb_shinfo(skb)->nr_frags == 0);
910 968
@@ -924,9 +982,28 @@ static void dma_tx_fragment(struct bcm43xx_dmaring *ring,
924 skb->len - sizeof(struct bcm43xx_txhdr), 982 skb->len - sizeof(struct bcm43xx_txhdr),
925 (cur_frag == 0), 983 (cur_frag == 0),
926 generate_cookie(ring, slot)); 984 generate_cookie(ring, slot));
985 dmaaddr = map_descbuffer(ring, skb->data, skb->len, 1);
986 if (dma_mapping_error(dmaaddr) || dmaaddr + skb->len > ring->bcm->dma_mask) {
987 /* chip cannot handle DMA to/from > 1GB, use bounce buffer (copied from b44 driver) */
988 if (!dma_mapping_error(dmaaddr))
989 unmap_descbuffer(ring, dmaaddr, skb->len, 1);
990 bounce_skb = __dev_alloc_skb(skb->len, GFP_ATOMIC|GFP_DMA);
991 if (!bounce_skb)
992 return;
993 dmaaddr = map_descbuffer(ring, bounce_skb->data, bounce_skb->len, 1);
994 if (dma_mapping_error(dmaaddr) || dmaaddr + skb->len > ring->bcm->dma_mask) {
995 if (!dma_mapping_error(dmaaddr))
996 unmap_descbuffer(ring, dmaaddr, skb->len, 1);
997 dev_kfree_skb_any(bounce_skb);
998 assert(0);
999 return;
1000 }
1001 memcpy(skb_put(bounce_skb, skb->len), skb->data, skb->len);
1002 dev_kfree_skb_any(skb);
1003 skb = bounce_skb;
1004 }
927 1005
928 meta->skb = skb; 1006 meta->skb = skb;
929 dmaaddr = map_descbuffer(ring, skb->data, skb->len, 1);
930 meta->dmaaddr = dmaaddr; 1007 meta->dmaaddr = dmaaddr;
931 1008
932 fill_descriptor(ring, desc, dmaaddr, 1009 fill_descriptor(ring, desc, dmaaddr,
diff --git a/drivers/net/wireless/bcm43xx/bcm43xx_main.c b/drivers/net/wireless/bcm43xx/bcm43xx_main.c
index 23aaf1ed8541..2e400aacc436 100644
--- a/drivers/net/wireless/bcm43xx/bcm43xx_main.c
+++ b/drivers/net/wireless/bcm43xx/bcm43xx_main.c
@@ -95,13 +95,9 @@ static int modparam_noleds;
95module_param_named(noleds, modparam_noleds, int, 0444); 95module_param_named(noleds, modparam_noleds, int, 0444);
96MODULE_PARM_DESC(noleds, "Turn off all LED activity"); 96MODULE_PARM_DESC(noleds, "Turn off all LED activity");
97 97
98#ifdef CONFIG_BCM43XX_DEBUG
99static char modparam_fwpostfix[64]; 98static char modparam_fwpostfix[64];
100module_param_string(fwpostfix, modparam_fwpostfix, 64, 0444); 99module_param_string(fwpostfix, modparam_fwpostfix, 64, 0444);
101MODULE_PARM_DESC(fwpostfix, "Postfix for .fw files. Useful for debugging."); 100MODULE_PARM_DESC(fwpostfix, "Postfix for .fw files. Useful for using multiple firmware image versions.");
102#else
103# define modparam_fwpostfix ""
104#endif /* CONFIG_BCM43XX_DEBUG*/
105 101
106 102
107/* If you want to debug with just a single device, enable this, 103/* If you want to debug with just a single device, enable this,
@@ -2983,8 +2979,10 @@ static int bcm43xx_chipset_attach(struct bcm43xx_private *bcm)
2983 err = bcm43xx_pctl_set_crystal(bcm, 1); 2979 err = bcm43xx_pctl_set_crystal(bcm, 1);
2984 if (err) 2980 if (err)
2985 goto out; 2981 goto out;
2986 bcm43xx_pci_read_config16(bcm, PCI_STATUS, &pci_status); 2982 err = bcm43xx_pci_read_config16(bcm, PCI_STATUS, &pci_status);
2987 bcm43xx_pci_write_config16(bcm, PCI_STATUS, pci_status & ~PCI_STATUS_SIG_TARGET_ABORT); 2983 if (err)
2984 goto out;
2985 err = bcm43xx_pci_write_config16(bcm, PCI_STATUS, pci_status & ~PCI_STATUS_SIG_TARGET_ABORT);
2988 2986
2989out: 2987out:
2990 return err; 2988 return err;
@@ -3796,12 +3794,18 @@ static int bcm43xx_attach_board(struct bcm43xx_private *bcm)
3796 } 3794 }
3797 net_dev->base_addr = (unsigned long)bcm->mmio_addr; 3795 net_dev->base_addr = (unsigned long)bcm->mmio_addr;
3798 3796
3799 bcm43xx_pci_read_config16(bcm, PCI_SUBSYSTEM_VENDOR_ID, 3797 err = bcm43xx_pci_read_config16(bcm, PCI_SUBSYSTEM_VENDOR_ID,
3800 &bcm->board_vendor); 3798 &bcm->board_vendor);
3801 bcm43xx_pci_read_config16(bcm, PCI_SUBSYSTEM_ID, 3799 if (err)
3800 goto err_iounmap;
3801 err = bcm43xx_pci_read_config16(bcm, PCI_SUBSYSTEM_ID,
3802 &bcm->board_type); 3802 &bcm->board_type);
3803 bcm43xx_pci_read_config16(bcm, PCI_REVISION_ID, 3803 if (err)
3804 goto err_iounmap;
3805 err = bcm43xx_pci_read_config16(bcm, PCI_REVISION_ID,
3804 &bcm->board_revision); 3806 &bcm->board_revision);
3807 if (err)
3808 goto err_iounmap;
3805 3809
3806 err = bcm43xx_chipset_attach(bcm); 3810 err = bcm43xx_chipset_attach(bcm);
3807 if (err) 3811 if (err)
@@ -3892,6 +3896,7 @@ err_pci_release:
3892 pci_release_regions(pci_dev); 3896 pci_release_regions(pci_dev);
3893err_pci_disable: 3897err_pci_disable:
3894 pci_disable_device(pci_dev); 3898 pci_disable_device(pci_dev);
3899 printk(KERN_ERR PFX "Unable to attach board\n");
3895 goto out; 3900 goto out;
3896} 3901}
3897 3902
diff --git a/drivers/net/wireless/bcm43xx/bcm43xx_wx.c b/drivers/net/wireless/bcm43xx/bcm43xx_wx.c
index d2ca949174fe..7b665e2386a8 100644
--- a/drivers/net/wireless/bcm43xx/bcm43xx_wx.c
+++ b/drivers/net/wireless/bcm43xx/bcm43xx_wx.c
@@ -260,22 +260,22 @@ static int bcm43xx_wx_get_rangeparams(struct net_device *net_dev,
260 if (phy->type == BCM43xx_PHYTYPE_A || 260 if (phy->type == BCM43xx_PHYTYPE_A ||
261 phy->type == BCM43xx_PHYTYPE_G) { 261 phy->type == BCM43xx_PHYTYPE_G) {
262 range->num_bitrates = 8; 262 range->num_bitrates = 8;
263 range->bitrate[i++] = IEEE80211_OFDM_RATE_6MB; 263 range->bitrate[i++] = IEEE80211_OFDM_RATE_6MB * 500000;
264 range->bitrate[i++] = IEEE80211_OFDM_RATE_9MB; 264 range->bitrate[i++] = IEEE80211_OFDM_RATE_9MB * 500000;
265 range->bitrate[i++] = IEEE80211_OFDM_RATE_12MB; 265 range->bitrate[i++] = IEEE80211_OFDM_RATE_12MB * 500000;
266 range->bitrate[i++] = IEEE80211_OFDM_RATE_18MB; 266 range->bitrate[i++] = IEEE80211_OFDM_RATE_18MB * 500000;
267 range->bitrate[i++] = IEEE80211_OFDM_RATE_24MB; 267 range->bitrate[i++] = IEEE80211_OFDM_RATE_24MB * 500000;
268 range->bitrate[i++] = IEEE80211_OFDM_RATE_36MB; 268 range->bitrate[i++] = IEEE80211_OFDM_RATE_36MB * 500000;
269 range->bitrate[i++] = IEEE80211_OFDM_RATE_48MB; 269 range->bitrate[i++] = IEEE80211_OFDM_RATE_48MB * 500000;
270 range->bitrate[i++] = IEEE80211_OFDM_RATE_54MB; 270 range->bitrate[i++] = IEEE80211_OFDM_RATE_54MB * 500000;
271 } 271 }
272 if (phy->type == BCM43xx_PHYTYPE_B || 272 if (phy->type == BCM43xx_PHYTYPE_B ||
273 phy->type == BCM43xx_PHYTYPE_G) { 273 phy->type == BCM43xx_PHYTYPE_G) {
274 range->num_bitrates += 4; 274 range->num_bitrates += 4;
275 range->bitrate[i++] = IEEE80211_CCK_RATE_1MB; 275 range->bitrate[i++] = IEEE80211_CCK_RATE_1MB * 500000;
276 range->bitrate[i++] = IEEE80211_CCK_RATE_2MB; 276 range->bitrate[i++] = IEEE80211_CCK_RATE_2MB * 500000;
277 range->bitrate[i++] = IEEE80211_CCK_RATE_5MB; 277 range->bitrate[i++] = IEEE80211_CCK_RATE_5MB * 500000;
278 range->bitrate[i++] = IEEE80211_CCK_RATE_11MB; 278 range->bitrate[i++] = IEEE80211_CCK_RATE_11MB * 500000;
279 } 279 }
280 280
281 geo = ieee80211_get_geo(bcm->ieee); 281 geo = ieee80211_get_geo(bcm->ieee);
@@ -285,7 +285,7 @@ static int bcm43xx_wx_get_rangeparams(struct net_device *net_dev,
285 if (j == IW_MAX_FREQUENCIES) 285 if (j == IW_MAX_FREQUENCIES)
286 break; 286 break;
287 range->freq[j].i = j + 1; 287 range->freq[j].i = j + 1;
288 range->freq[j].m = geo->a[i].freq;//FIXME? 288 range->freq[j].m = geo->a[i].freq * 100000;
289 range->freq[j].e = 1; 289 range->freq[j].e = 1;
290 j++; 290 j++;
291 } 291 }
@@ -293,7 +293,7 @@ static int bcm43xx_wx_get_rangeparams(struct net_device *net_dev,
293 if (j == IW_MAX_FREQUENCIES) 293 if (j == IW_MAX_FREQUENCIES)
294 break; 294 break;
295 range->freq[j].i = j + 1; 295 range->freq[j].i = j + 1;
296 range->freq[j].m = geo->bg[i].freq;//FIXME? 296 range->freq[j].m = geo->bg[i].freq * 100000;
297 range->freq[j].e = 1; 297 range->freq[j].e = 1;
298 j++; 298 j++;
299 } 299 }
diff --git a/drivers/net/wireless/ipw2100.c b/drivers/net/wireless/ipw2100.c
index b85857a84870..d0639a45cd2c 100644
--- a/drivers/net/wireless/ipw2100.c
+++ b/drivers/net/wireless/ipw2100.c
@@ -175,7 +175,7 @@ that only one external action is invoked at a time.
175 175
176/* Debugging stuff */ 176/* Debugging stuff */
177#ifdef CONFIG_IPW2100_DEBUG 177#ifdef CONFIG_IPW2100_DEBUG
178#define CONFIG_IPW2100_RX_DEBUG /* Reception debugging */ 178#define IPW2100_RX_DEBUG /* Reception debugging */
179#endif 179#endif
180 180
181MODULE_DESCRIPTION(DRV_DESCRIPTION); 181MODULE_DESCRIPTION(DRV_DESCRIPTION);
@@ -2239,7 +2239,7 @@ static void ipw2100_snapshot_free(struct ipw2100_priv *priv)
2239 priv->snapshot[0] = NULL; 2239 priv->snapshot[0] = NULL;
2240} 2240}
2241 2241
2242#ifdef CONFIG_IPW2100_DEBUG_C3 2242#ifdef IPW2100_DEBUG_C3
2243static int ipw2100_snapshot_alloc(struct ipw2100_priv *priv) 2243static int ipw2100_snapshot_alloc(struct ipw2100_priv *priv)
2244{ 2244{
2245 int i; 2245 int i;
@@ -2314,13 +2314,13 @@ static u32 ipw2100_match_buf(struct ipw2100_priv *priv, u8 * in_buf,
2314 * The size of the constructed ethernet 2314 * The size of the constructed ethernet
2315 * 2315 *
2316 */ 2316 */
2317#ifdef CONFIG_IPW2100_RX_DEBUG 2317#ifdef IPW2100_RX_DEBUG
2318static u8 packet_data[IPW_RX_NIC_BUFFER_LENGTH]; 2318static u8 packet_data[IPW_RX_NIC_BUFFER_LENGTH];
2319#endif 2319#endif
2320 2320
2321static void ipw2100_corruption_detected(struct ipw2100_priv *priv, int i) 2321static void ipw2100_corruption_detected(struct ipw2100_priv *priv, int i)
2322{ 2322{
2323#ifdef CONFIG_IPW2100_DEBUG_C3 2323#ifdef IPW2100_DEBUG_C3
2324 struct ipw2100_status *status = &priv->status_queue.drv[i]; 2324 struct ipw2100_status *status = &priv->status_queue.drv[i];
2325 u32 match, reg; 2325 u32 match, reg;
2326 int j; 2326 int j;
@@ -2342,7 +2342,7 @@ static void ipw2100_corruption_detected(struct ipw2100_priv *priv, int i)
2342 } 2342 }
2343#endif 2343#endif
2344 2344
2345#ifdef CONFIG_IPW2100_DEBUG_C3 2345#ifdef IPW2100_DEBUG_C3
2346 /* Halt the fimrware so we can get a good image */ 2346 /* Halt the fimrware so we can get a good image */
2347 write_register(priv->net_dev, IPW_REG_RESET_REG, 2347 write_register(priv->net_dev, IPW_REG_RESET_REG,
2348 IPW_AUX_HOST_RESET_REG_STOP_MASTER); 2348 IPW_AUX_HOST_RESET_REG_STOP_MASTER);
@@ -2413,7 +2413,7 @@ static void isr_rx(struct ipw2100_priv *priv, int i,
2413 2413
2414 skb_put(packet->skb, status->frame_size); 2414 skb_put(packet->skb, status->frame_size);
2415 2415
2416#ifdef CONFIG_IPW2100_RX_DEBUG 2416#ifdef IPW2100_RX_DEBUG
2417 /* Make a copy of the frame so we can dump it to the logs if 2417 /* Make a copy of the frame so we can dump it to the logs if
2418 * ieee80211_rx fails */ 2418 * ieee80211_rx fails */
2419 memcpy(packet_data, packet->skb->data, 2419 memcpy(packet_data, packet->skb->data,
@@ -2421,7 +2421,7 @@ static void isr_rx(struct ipw2100_priv *priv, int i,
2421#endif 2421#endif
2422 2422
2423 if (!ieee80211_rx(priv->ieee, packet->skb, stats)) { 2423 if (!ieee80211_rx(priv->ieee, packet->skb, stats)) {
2424#ifdef CONFIG_IPW2100_RX_DEBUG 2424#ifdef IPW2100_RX_DEBUG
2425 IPW_DEBUG_DROP("%s: Non consumed packet:\n", 2425 IPW_DEBUG_DROP("%s: Non consumed packet:\n",
2426 priv->net_dev->name); 2426 priv->net_dev->name);
2427 printk_buf(IPW_DL_DROP, packet_data, status->frame_size); 2427 printk_buf(IPW_DL_DROP, packet_data, status->frame_size);
@@ -4912,7 +4912,7 @@ static int ipw2100_set_power_mode(struct ipw2100_priv *priv, int power_level)
4912 else 4912 else
4913 priv->power_mode = IPW_POWER_ENABLED | power_level; 4913 priv->power_mode = IPW_POWER_ENABLED | power_level;
4914 4914
4915#ifdef CONFIG_IPW2100_TX_POWER 4915#ifdef IPW2100_TX_POWER
4916 if (priv->port_type == IBSS && priv->adhoc_power != DFTL_IBSS_TX_POWER) { 4916 if (priv->port_type == IBSS && priv->adhoc_power != DFTL_IBSS_TX_POWER) {
4917 /* Set beacon interval */ 4917 /* Set beacon interval */
4918 cmd.host_command = TX_POWER_INDEX; 4918 cmd.host_command = TX_POWER_INDEX;
diff --git a/drivers/net/wireless/wavelan_cs.c b/drivers/net/wireless/wavelan_cs.c
index 5eb81638e846..b04239792f63 100644
--- a/drivers/net/wireless/wavelan_cs.c
+++ b/drivers/net/wireless/wavelan_cs.c
@@ -1168,7 +1168,7 @@ wv_mmc_show(struct net_device * dev)
1168 m.mmr_unused0[6], 1168 m.mmr_unused0[6],
1169 m.mmr_unused0[7]); 1169 m.mmr_unused0[7]);
1170#endif /* DEBUG_SHOW_UNUSED */ 1170#endif /* DEBUG_SHOW_UNUSED */
1171 printk(KERN_DEBUG "Encryption algorythm: %02X - Status: %02X\n", 1171 printk(KERN_DEBUG "Encryption algorithm: %02X - Status: %02X\n",
1172 m.mmr_des_avail, m.mmr_des_status); 1172 m.mmr_des_avail, m.mmr_des_status);
1173#ifdef DEBUG_SHOW_UNUSED 1173#ifdef DEBUG_SHOW_UNUSED
1174 printk(KERN_DEBUG "mmc_unused1[]: %02X:%02X:%02X:%02X:%02X\n", 1174 printk(KERN_DEBUG "mmc_unused1[]: %02X:%02X:%02X:%02X:%02X\n",
@@ -3590,9 +3590,9 @@ wv_82593_config(struct net_device * dev)
3590 cfblk.acloc = TRUE; /* Disable source addr insertion by i82593 */ 3590 cfblk.acloc = TRUE; /* Disable source addr insertion by i82593 */
3591 cfblk.preamb_len = 0; /* 2 bytes preamble (SFD) */ 3591 cfblk.preamb_len = 0; /* 2 bytes preamble (SFD) */
3592 cfblk.loopback = FALSE; 3592 cfblk.loopback = FALSE;
3593 cfblk.lin_prio = 0; /* conform to 802.3 backoff algoritm */ 3593 cfblk.lin_prio = 0; /* conform to 802.3 backoff algorithm */
3594 cfblk.exp_prio = 5; /* conform to 802.3 backoff algoritm */ 3594 cfblk.exp_prio = 5; /* conform to 802.3 backoff algorithm */
3595 cfblk.bof_met = 1; /* conform to 802.3 backoff algoritm */ 3595 cfblk.bof_met = 1; /* conform to 802.3 backoff algorithm */
3596 cfblk.ifrm_spc = 0x20 >> 4; /* 32 bit times interframe spacing */ 3596 cfblk.ifrm_spc = 0x20 >> 4; /* 32 bit times interframe spacing */
3597 cfblk.slottim_low = 0x20 >> 5; /* 32 bit times slot time */ 3597 cfblk.slottim_low = 0x20 >> 5; /* 32 bit times slot time */
3598 cfblk.slottim_hi = 0x0; 3598 cfblk.slottim_hi = 0x0;
diff --git a/drivers/net/wireless/zd1211rw/zd_mac.c b/drivers/net/wireless/zd1211rw/zd_mac.c
index a08524191b5d..4c5f78eac349 100644
--- a/drivers/net/wireless/zd1211rw/zd_mac.c
+++ b/drivers/net/wireless/zd1211rw/zd_mac.c
@@ -156,7 +156,7 @@ void zd_mac_clear(struct zd_mac *mac)
156static int reset_mode(struct zd_mac *mac) 156static int reset_mode(struct zd_mac *mac)
157{ 157{
158 struct ieee80211_device *ieee = zd_mac_to_ieee80211(mac); 158 struct ieee80211_device *ieee = zd_mac_to_ieee80211(mac);
159 struct zd_ioreq32 ioreqs[3] = { 159 struct zd_ioreq32 ioreqs[] = {
160 { CR_RX_FILTER, STA_RX_FILTER }, 160 { CR_RX_FILTER, STA_RX_FILTER },
161 { CR_SNIFFER_ON, 0U }, 161 { CR_SNIFFER_ON, 0U },
162 }; 162 };
@@ -164,10 +164,9 @@ static int reset_mode(struct zd_mac *mac)
164 if (ieee->iw_mode == IW_MODE_MONITOR) { 164 if (ieee->iw_mode == IW_MODE_MONITOR) {
165 ioreqs[0].value = 0xffffffff; 165 ioreqs[0].value = 0xffffffff;
166 ioreqs[1].value = 0x1; 166 ioreqs[1].value = 0x1;
167 ioreqs[2].value = ENC_SNIFFER;
168 } 167 }
169 168
170 return zd_iowrite32a(&mac->chip, ioreqs, 3); 169 return zd_iowrite32a(&mac->chip, ioreqs, ARRAY_SIZE(ioreqs));
171} 170}
172 171
173int zd_mac_open(struct net_device *netdev) 172int zd_mac_open(struct net_device *netdev)
@@ -904,16 +903,21 @@ static int fill_ctrlset(struct zd_mac *mac,
904static int zd_mac_tx(struct zd_mac *mac, struct ieee80211_txb *txb, int pri) 903static int zd_mac_tx(struct zd_mac *mac, struct ieee80211_txb *txb, int pri)
905{ 904{
906 int i, r; 905 int i, r;
906 struct ieee80211_device *ieee = zd_mac_to_ieee80211(mac);
907 907
908 for (i = 0; i < txb->nr_frags; i++) { 908 for (i = 0; i < txb->nr_frags; i++) {
909 struct sk_buff *skb = txb->fragments[i]; 909 struct sk_buff *skb = txb->fragments[i];
910 910
911 r = fill_ctrlset(mac, txb, i); 911 r = fill_ctrlset(mac, txb, i);
912 if (r) 912 if (r) {
913 ieee->stats.tx_dropped++;
913 return r; 914 return r;
915 }
914 r = zd_usb_tx(&mac->chip.usb, skb->data, skb->len); 916 r = zd_usb_tx(&mac->chip.usb, skb->data, skb->len);
915 if (r) 917 if (r) {
918 ieee->stats.tx_dropped++;
916 return r; 919 return r;
920 }
917 } 921 }
918 922
919 /* FIXME: shouldn't this be handled by the upper layers? */ 923 /* FIXME: shouldn't this be handled by the upper layers? */
@@ -1063,9 +1067,23 @@ static int fill_rx_stats(struct ieee80211_rx_stats *stats,
1063 1067
1064 *pstatus = status = zd_tail(buffer, length, sizeof(struct rx_status)); 1068 *pstatus = status = zd_tail(buffer, length, sizeof(struct rx_status));
1065 if (status->frame_status & ZD_RX_ERROR) { 1069 if (status->frame_status & ZD_RX_ERROR) {
1066 /* FIXME: update? */ 1070 struct ieee80211_device *ieee = zd_mac_to_ieee80211(mac);
1071 ieee->stats.rx_errors++;
1072 if (status->frame_status & ZD_RX_TIMEOUT_ERROR)
1073 ieee->stats.rx_missed_errors++;
1074 else if (status->frame_status & ZD_RX_FIFO_OVERRUN_ERROR)
1075 ieee->stats.rx_fifo_errors++;
1076 else if (status->frame_status & ZD_RX_DECRYPTION_ERROR)
1077 ieee->ieee_stats.rx_discards_undecryptable++;
1078 else if (status->frame_status & ZD_RX_CRC32_ERROR) {
1079 ieee->stats.rx_crc_errors++;
1080 ieee->ieee_stats.rx_fcs_errors++;
1081 }
1082 else if (status->frame_status & ZD_RX_CRC16_ERROR)
1083 ieee->stats.rx_crc_errors++;
1067 return -EINVAL; 1084 return -EINVAL;
1068 } 1085 }
1086
1069 memset(stats, 0, sizeof(struct ieee80211_rx_stats)); 1087 memset(stats, 0, sizeof(struct ieee80211_rx_stats));
1070 stats->len = length - (ZD_PLCP_HEADER_SIZE + IEEE80211_FCS_LEN + 1088 stats->len = length - (ZD_PLCP_HEADER_SIZE + IEEE80211_FCS_LEN +
1071 + sizeof(struct rx_status)); 1089 + sizeof(struct rx_status));
@@ -1094,14 +1112,16 @@ static void zd_mac_rx(struct zd_mac *mac, struct sk_buff *skb)
1094 if (skb->len < ZD_PLCP_HEADER_SIZE + IEEE80211_1ADDR_LEN + 1112 if (skb->len < ZD_PLCP_HEADER_SIZE + IEEE80211_1ADDR_LEN +
1095 IEEE80211_FCS_LEN + sizeof(struct rx_status)) 1113 IEEE80211_FCS_LEN + sizeof(struct rx_status))
1096 { 1114 {
1097 dev_dbg_f(zd_mac_dev(mac), "Packet with length %u to small.\n", 1115 ieee->stats.rx_errors++;
1098 skb->len); 1116 ieee->stats.rx_length_errors++;
1099 goto free_skb; 1117 goto free_skb;
1100 } 1118 }
1101 1119
1102 r = fill_rx_stats(&stats, &status, mac, skb->data, skb->len); 1120 r = fill_rx_stats(&stats, &status, mac, skb->data, skb->len);
1103 if (r) { 1121 if (r) {
1104 /* Only packets with rx errors are included here. */ 1122 /* Only packets with rx errors are included here.
1123 * The error stats have already been set in fill_rx_stats.
1124 */
1105 goto free_skb; 1125 goto free_skb;
1106 } 1126 }
1107 1127
@@ -1114,8 +1134,10 @@ static void zd_mac_rx(struct zd_mac *mac, struct sk_buff *skb)
1114 1134
1115 r = filter_rx(ieee, skb->data, skb->len, &stats); 1135 r = filter_rx(ieee, skb->data, skb->len, &stats);
1116 if (r <= 0) { 1136 if (r <= 0) {
1117 if (r < 0) 1137 if (r < 0) {
1138 ieee->stats.rx_errors++;
1118 dev_dbg_f(zd_mac_dev(mac), "Error in packet.\n"); 1139 dev_dbg_f(zd_mac_dev(mac), "Error in packet.\n");
1140 }
1119 goto free_skb; 1141 goto free_skb;
1120 } 1142 }
1121 1143
@@ -1146,7 +1168,9 @@ int zd_mac_rx_irq(struct zd_mac *mac, const u8 *buffer, unsigned int length)
1146 1168
1147 skb = dev_alloc_skb(sizeof(struct zd_rt_hdr) + length); 1169 skb = dev_alloc_skb(sizeof(struct zd_rt_hdr) + length);
1148 if (!skb) { 1170 if (!skb) {
1171 struct ieee80211_device *ieee = zd_mac_to_ieee80211(mac);
1149 dev_warn(zd_mac_dev(mac), "Could not allocate skb.\n"); 1172 dev_warn(zd_mac_dev(mac), "Could not allocate skb.\n");
1173 ieee->stats.rx_dropped++;
1150 return -ENOMEM; 1174 return -ENOMEM;
1151 } 1175 }
1152 skb_reserve(skb, sizeof(struct zd_rt_hdr)); 1176 skb_reserve(skb, sizeof(struct zd_rt_hdr));
diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
index 75ef55624d7f..aac8a1c5ba08 100644
--- a/drivers/net/wireless/zd1211rw/zd_usb.c
+++ b/drivers/net/wireless/zd1211rw/zd_usb.c
@@ -313,6 +313,12 @@ out:
313 313
314static inline void handle_retry_failed_int(struct urb *urb) 314static inline void handle_retry_failed_int(struct urb *urb)
315{ 315{
316 struct zd_usb *usb = urb->context;
317 struct zd_mac *mac = zd_usb_to_mac(usb);
318 struct ieee80211_device *ieee = zd_mac_to_ieee80211(mac);
319
320 ieee->stats.tx_errors++;
321 ieee->ieee_stats.tx_retry_limit_exceeded++;
316 dev_dbg_f(urb_dev(urb), "retry failed interrupt\n"); 322 dev_dbg_f(urb_dev(urb), "retry failed interrupt\n");
317} 323}
318 324
@@ -487,6 +493,9 @@ static void handle_rx_packet(struct zd_usb *usb, const u8 *buffer,
487 493
488 if (length < sizeof(struct rx_length_info)) { 494 if (length < sizeof(struct rx_length_info)) {
489 /* It's not a complete packet anyhow. */ 495 /* It's not a complete packet anyhow. */
496 struct ieee80211_device *ieee = zd_mac_to_ieee80211(mac);
497 ieee->stats.rx_errors++;
498 ieee->stats.rx_length_errors++;
490 return; 499 return;
491 } 500 }
492 length_info = (struct rx_length_info *) 501 length_info = (struct rx_length_info *)
@@ -923,6 +932,8 @@ static int probe(struct usb_interface *intf, const struct usb_device_id *id)
923 goto error; 932 goto error;
924 } 933 }
925 934
935 usb_reset_device(interface_to_usbdev(intf));
936
926 netdev = zd_netdev_alloc(intf); 937 netdev = zd_netdev_alloc(intf);
927 if (netdev == NULL) { 938 if (netdev == NULL) {
928 r = -ENOMEM; 939 r = -ENOMEM;
@@ -1024,6 +1035,7 @@ static int __init usb_init(void)
1024 1035
1025 r = usb_register(&driver); 1036 r = usb_register(&driver);
1026 if (r) { 1037 if (r) {
1038 destroy_workqueue(zd_workqueue);
1027 printk(KERN_ERR "%s usb_register() failed. Error number %d\n", 1039 printk(KERN_ERR "%s usb_register() failed. Error number %d\n",
1028 driver.name, r); 1040 driver.name, r);
1029 return r; 1041 return r;
diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
index 4438ae1ede4f..a3c1755b2f28 100644
--- a/drivers/pci/pci-driver.c
+++ b/drivers/pci/pci-driver.c
@@ -415,6 +415,7 @@ static struct kobj_type pci_driver_kobj_type = {
415 * __pci_register_driver - register a new pci driver 415 * __pci_register_driver - register a new pci driver
416 * @drv: the driver structure to register 416 * @drv: the driver structure to register
417 * @owner: owner module of drv 417 * @owner: owner module of drv
418 * @mod_name: module name string
418 * 419 *
419 * Adds the driver structure to the list of registered drivers. 420 * Adds the driver structure to the list of registered drivers.
420 * Returns a negative value on error, otherwise 0. 421 * Returns a negative value on error, otherwise 0.
diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
index 7a94076752d0..cd913a2a416f 100644
--- a/drivers/pci/pci-sysfs.c
+++ b/drivers/pci/pci-sysfs.c
@@ -143,6 +143,14 @@ static ssize_t is_enabled_show(struct device *dev,
143 return sprintf (buf, "%u\n", atomic_read(&pdev->enable_cnt)); 143 return sprintf (buf, "%u\n", atomic_read(&pdev->enable_cnt));
144} 144}
145 145
146#ifdef CONFIG_NUMA
147static ssize_t
148numa_node_show(struct device *dev, struct device_attribute *attr, char *buf)
149{
150 return sprintf (buf, "%d\n", dev->numa_node);
151}
152#endif
153
146static ssize_t 154static ssize_t
147msi_bus_show(struct device *dev, struct device_attribute *attr, char *buf) 155msi_bus_show(struct device *dev, struct device_attribute *attr, char *buf)
148{ 156{
@@ -194,6 +202,9 @@ struct device_attribute pci_dev_attrs[] = {
194 __ATTR_RO(irq), 202 __ATTR_RO(irq),
195 __ATTR_RO(local_cpus), 203 __ATTR_RO(local_cpus),
196 __ATTR_RO(modalias), 204 __ATTR_RO(modalias),
205#ifdef CONFIG_NUMA
206 __ATTR_RO(numa_node),
207#endif
197 __ATTR(enable, 0600, is_enabled_show, is_enabled_store), 208 __ATTR(enable, 0600, is_enabled_show, is_enabled_store),
198 __ATTR(broken_parity_status,(S_IRUGO|S_IWUSR), 209 __ATTR(broken_parity_status,(S_IRUGO|S_IWUSR),
199 broken_parity_status_show,broken_parity_status_store), 210 broken_parity_status_show,broken_parity_status_store),
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 8b44cff2c176..1e74e1ee8bd8 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -21,6 +21,12 @@
21 21
22unsigned int pci_pm_d3_delay = 10; 22unsigned int pci_pm_d3_delay = 10;
23 23
24#define DEFAULT_CARDBUS_IO_SIZE (256)
25#define DEFAULT_CARDBUS_MEM_SIZE (64*1024*1024)
26/* pci=cbmemsize=nnM,cbiosize=nn can override this */
27unsigned long pci_cardbus_io_size = DEFAULT_CARDBUS_IO_SIZE;
28unsigned long pci_cardbus_mem_size = DEFAULT_CARDBUS_MEM_SIZE;
29
24/** 30/**
25 * pci_bus_max_busnr - returns maximum PCI bus number of given bus' children 31 * pci_bus_max_busnr - returns maximum PCI bus number of given bus' children
26 * @bus: pointer to PCI bus structure to search 32 * @bus: pointer to PCI bus structure to search
@@ -1300,7 +1306,7 @@ pci_set_consistent_dma_mask(struct pci_dev *dev, u64 mask)
1300 1306
1301/** 1307/**
1302 * pci_select_bars - Make BAR mask from the type of resource 1308 * pci_select_bars - Make BAR mask from the type of resource
1303 * @pdev: the PCI device for which BAR mask is made 1309 * @dev: the PCI device for which BAR mask is made
1304 * @flags: resource type mask to be selected 1310 * @flags: resource type mask to be selected
1305 * 1311 *
1306 * This helper routine makes bar mask from the type of resource. 1312 * This helper routine makes bar mask from the type of resource.
@@ -1333,6 +1339,10 @@ static int __devinit pci_setup(char *str)
1333 if (*str && (str = pcibios_setup(str)) && *str) { 1339 if (*str && (str = pcibios_setup(str)) && *str) {
1334 if (!strcmp(str, "nomsi")) { 1340 if (!strcmp(str, "nomsi")) {
1335 pci_no_msi(); 1341 pci_no_msi();
1342 } else if (!strncmp(str, "cbiosize=", 9)) {
1343 pci_cardbus_io_size = memparse(str + 9, &str);
1344 } else if (!strncmp(str, "cbmemsize=", 10)) {
1345 pci_cardbus_mem_size = memparse(str + 10, &str);
1336 } else { 1346 } else {
1337 printk(KERN_ERR "PCI: Unknown option `%s'\n", 1347 printk(KERN_ERR "PCI: Unknown option `%s'\n",
1338 str); 1348 str);
diff --git a/drivers/pci/pcie/aer/aerdrv.h b/drivers/pci/pcie/aer/aerdrv.h
index 3c0a58f64dd8..bf655dbaf8e2 100644
--- a/drivers/pci/pcie/aer/aerdrv.h
+++ b/drivers/pci/pcie/aer/aerdrv.h
@@ -85,7 +85,7 @@ struct aer_rpc {
85 struct mutex rpc_mutex; /* 85 struct mutex rpc_mutex; /*
86 * only one thread could do 86 * only one thread could do
87 * recovery on the same 87 * recovery on the same
88 * root port hierachy 88 * root port hierarchy
89 */ 89 */
90 wait_queue_head_t wait_release; 90 wait_queue_head_t wait_release;
91}; 91};
diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index 89f3036f0de8..3554f3948814 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -36,13 +36,6 @@
36 36
37#define ROUND_UP(x, a) (((x) + (a) - 1) & ~((a) - 1)) 37#define ROUND_UP(x, a) (((x) + (a) - 1) & ~((a) - 1))
38 38
39/*
40 * FIXME: IO should be max 256 bytes. However, since we may
41 * have a P2P bridge below a cardbus bridge, we need 4K.
42 */
43#define CARDBUS_IO_SIZE (256)
44#define CARDBUS_MEM_SIZE (64*1024*1024)
45
46static void __devinit 39static void __devinit
47pbus_assign_resources_sorted(struct pci_bus *bus) 40pbus_assign_resources_sorted(struct pci_bus *bus)
48{ 41{
@@ -415,12 +408,12 @@ pci_bus_size_cardbus(struct pci_bus *bus)
415 * Reserve some resources for CardBus. We reserve 408 * Reserve some resources for CardBus. We reserve
416 * a fixed amount of bus space for CardBus bridges. 409 * a fixed amount of bus space for CardBus bridges.
417 */ 410 */
418 b_res[0].start = CARDBUS_IO_SIZE; 411 b_res[0].start = pci_cardbus_io_size;
419 b_res[0].end = b_res[0].start + CARDBUS_IO_SIZE - 1; 412 b_res[0].end = b_res[0].start + pci_cardbus_io_size - 1;
420 b_res[0].flags |= IORESOURCE_IO; 413 b_res[0].flags |= IORESOURCE_IO;
421 414
422 b_res[1].start = CARDBUS_IO_SIZE; 415 b_res[1].start = pci_cardbus_io_size;
423 b_res[1].end = b_res[1].start + CARDBUS_IO_SIZE - 1; 416 b_res[1].end = b_res[1].start + pci_cardbus_io_size - 1;
424 b_res[1].flags |= IORESOURCE_IO; 417 b_res[1].flags |= IORESOURCE_IO;
425 418
426 /* 419 /*
@@ -440,16 +433,16 @@ pci_bus_size_cardbus(struct pci_bus *bus)
440 * twice the size. 433 * twice the size.
441 */ 434 */
442 if (ctrl & PCI_CB_BRIDGE_CTL_PREFETCH_MEM0) { 435 if (ctrl & PCI_CB_BRIDGE_CTL_PREFETCH_MEM0) {
443 b_res[2].start = CARDBUS_MEM_SIZE; 436 b_res[2].start = pci_cardbus_mem_size;
444 b_res[2].end = b_res[2].start + CARDBUS_MEM_SIZE - 1; 437 b_res[2].end = b_res[2].start + pci_cardbus_mem_size - 1;
445 b_res[2].flags |= IORESOURCE_MEM | IORESOURCE_PREFETCH; 438 b_res[2].flags |= IORESOURCE_MEM | IORESOURCE_PREFETCH;
446 439
447 b_res[3].start = CARDBUS_MEM_SIZE; 440 b_res[3].start = pci_cardbus_mem_size;
448 b_res[3].end = b_res[3].start + CARDBUS_MEM_SIZE - 1; 441 b_res[3].end = b_res[3].start + pci_cardbus_mem_size - 1;
449 b_res[3].flags |= IORESOURCE_MEM; 442 b_res[3].flags |= IORESOURCE_MEM;
450 } else { 443 } else {
451 b_res[3].start = CARDBUS_MEM_SIZE * 2; 444 b_res[3].start = pci_cardbus_mem_size * 2;
452 b_res[3].end = b_res[3].start + CARDBUS_MEM_SIZE * 2 - 1; 445 b_res[3].end = b_res[3].start + pci_cardbus_mem_size * 2 - 1;
453 b_res[3].flags |= IORESOURCE_MEM; 446 b_res[3].flags |= IORESOURCE_MEM;
454 } 447 }
455} 448}
diff --git a/drivers/pci/setup-irq.c b/drivers/pci/setup-irq.c
index a251289c9958..568f1877315c 100644
--- a/drivers/pci/setup-irq.c
+++ b/drivers/pci/setup-irq.c
@@ -24,7 +24,7 @@ pdev_fixup_irq(struct pci_dev *dev,
24 int (*map_irq)(struct pci_dev *, u8, u8)) 24 int (*map_irq)(struct pci_dev *, u8, u8))
25{ 25{
26 u8 pin, slot; 26 u8 pin, slot;
27 int irq; 27 int irq = 0;
28 28
29 /* If this device is not on the primary bus, we need to figure out 29 /* If this device is not on the primary bus, we need to figure out
30 which interrupt pin it will come in on. We know which slot it 30 which interrupt pin it will come in on. We know which slot it
@@ -33,16 +33,18 @@ pdev_fixup_irq(struct pci_dev *dev,
33 apply the swizzle function. */ 33 apply the swizzle function. */
34 34
35 pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin); 35 pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin);
36 /* Cope with 0 and illegal. */ 36 /* Cope with illegal. */
37 if (pin == 0 || pin > 4) 37 if (pin > 4)
38 pin = 1; 38 pin = 1;
39 39
40 /* Follow the chain of bridges, swizzling as we go. */ 40 if (pin != 0) {
41 slot = (*swizzle)(dev, &pin); 41 /* Follow the chain of bridges, swizzling as we go. */
42 slot = (*swizzle)(dev, &pin);
42 43
43 irq = (*map_irq)(dev, slot, pin); 44 irq = (*map_irq)(dev, slot, pin);
44 if (irq == -1) 45 if (irq == -1)
45 irq = 0; 46 irq = 0;
47 }
46 dev->irq = irq; 48 dev->irq = irq;
47 49
48 pr_debug("PCI: fixup irq: (%s) got %d\n", 50 pr_debug("PCI: fixup irq: (%s) got %d\n",
diff --git a/drivers/pcmcia/at91_cf.c b/drivers/pcmcia/at91_cf.c
index b31862837534..99baabc23599 100644
--- a/drivers/pcmcia/at91_cf.c
+++ b/drivers/pcmcia/at91_cf.c
@@ -277,7 +277,7 @@ static int __init at91_cf_probe(struct platform_device *pdev)
277 board->det_pin, board->irq_pin); 277 board->det_pin, board->irq_pin);
278 278
279 cf->socket.owner = THIS_MODULE; 279 cf->socket.owner = THIS_MODULE;
280 cf->socket.dev.dev = &pdev->dev; 280 cf->socket.dev.parent = &pdev->dev;
281 cf->socket.ops = &at91_cf_ops; 281 cf->socket.ops = &at91_cf_ops;
282 cf->socket.resource_ops = &pccard_static_ops; 282 cf->socket.resource_ops = &pccard_static_ops;
283 cf->socket.features = SS_CAP_PCCARD | SS_CAP_STATIC_MAP 283 cf->socket.features = SS_CAP_PCCARD | SS_CAP_STATIC_MAP
diff --git a/drivers/pcmcia/cardbus.c b/drivers/pcmcia/cardbus.c
index 2d7effe7990d..a1bd763b4e33 100644
--- a/drivers/pcmcia/cardbus.c
+++ b/drivers/pcmcia/cardbus.c
@@ -40,8 +40,6 @@
40 40
41/*====================================================================*/ 41/*====================================================================*/
42 42
43#define FIND_FIRST_BIT(n) ((n) - ((n) & ((n)-1)))
44
45/* Offsets in the Expansion ROM Image Header */ 43/* Offsets in the Expansion ROM Image Header */
46#define ROM_SIGNATURE 0x0000 /* 2 bytes */ 44#define ROM_SIGNATURE 0x0000 /* 2 bytes */
47#define ROM_DATA_PTR 0x0018 /* 2 bytes */ 45#define ROM_DATA_PTR 0x0018 /* 2 bytes */
diff --git a/drivers/pcmcia/soc_common.c b/drivers/pcmcia/soc_common.c
index d2a3bea55de2..aa7779d89752 100644
--- a/drivers/pcmcia/soc_common.c
+++ b/drivers/pcmcia/soc_common.c
@@ -478,7 +478,7 @@ dump_bits(char **p, const char *prefix, unsigned int val, struct bittbl *bits, i
478 * 478 *
479 * Returns: the number of characters added to the buffer 479 * Returns: the number of characters added to the buffer
480 */ 480 */
481static ssize_t show_status(struct device *dev, char *buf) 481static ssize_t show_status(struct device *dev, struct device_attribute *attr, char *buf)
482{ 482{
483 struct soc_pcmcia_socket *skt = 483 struct soc_pcmcia_socket *skt =
484 container_of(dev, struct soc_pcmcia_socket, socket.dev); 484 container_of(dev, struct soc_pcmcia_socket, socket.dev);
@@ -501,7 +501,7 @@ static ssize_t show_status(struct device *dev, char *buf)
501 501
502 return p-buf; 502 return p-buf;
503} 503}
504static CLASS_DEVICE_ATTR(status, S_IRUGO, show_status, NULL); 504static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
505 505
506 506
507static struct pccard_operations soc_common_pcmcia_operations = { 507static struct pccard_operations soc_common_pcmcia_operations = {
@@ -660,7 +660,7 @@ int soc_common_drv_pcmcia_probe(struct device *dev, struct pcmcia_low_level *ops
660 660
661 skt->socket.ops = &soc_common_pcmcia_operations; 661 skt->socket.ops = &soc_common_pcmcia_operations;
662 skt->socket.owner = ops->owner; 662 skt->socket.owner = ops->owner;
663 skt->socket.dev.dev = dev; 663 skt->socket.dev.parent = dev;
664 664
665 init_timer(&skt->poll_timer); 665 init_timer(&skt->poll_timer);
666 skt->poll_timer.function = soc_common_pcmcia_poll_event; 666 skt->poll_timer.function = soc_common_pcmcia_poll_event;
@@ -747,7 +747,7 @@ int soc_common_drv_pcmcia_probe(struct device *dev, struct pcmcia_low_level *ops
747 747
748 add_timer(&skt->poll_timer); 748 add_timer(&skt->poll_timer);
749 749
750 device_create_file(&skt->socket.dev, &device_attr_status); 750 device_create_file(&skt->socket.dev, &dev_attr_status);
751 } 751 }
752 752
753 dev_set_drvdata(dev, sinfo); 753 dev_set_drvdata(dev, sinfo);
diff --git a/drivers/pnp/pnpacpi/Kconfig b/drivers/pnp/pnpacpi/Kconfig
index ad27e5e0101f..b04767ce273e 100644
--- a/drivers/pnp/pnpacpi/Kconfig
+++ b/drivers/pnp/pnpacpi/Kconfig
@@ -2,17 +2,5 @@
2# Plug and Play ACPI configuration 2# Plug and Play ACPI configuration
3# 3#
4config PNPACPI 4config PNPACPI
5 bool "Plug and Play ACPI support" 5 bool
6 depends on PNP && ACPI 6 default (PNP && ACPI)
7 default y
8 ---help---
9 Linux uses the PNPACPI to autodetect built-in
10 mainboard resources (e.g. parallel port resources).
11
12 Some features (e.g. real hotplug) are not currently
13 implemented.
14
15 If you would like the kernel to detect and allocate resources to
16 your mainboard devices (on some systems they are disabled by the
17 BIOS) say Y here. Also the PNPACPI can help prevent resource
18 conflicts between mainboard devices and other bus devices.
diff --git a/drivers/ps3/Makefile b/drivers/ps3/Makefile
index 96958c03cf61..e251d1c1171c 100644
--- a/drivers/ps3/Makefile
+++ b/drivers/ps3/Makefile
@@ -1,2 +1,3 @@
1obj-$(CONFIG_PS3_VUART) += vuart.o 1obj-$(CONFIG_PS3_VUART) += vuart.o
2obj-$(CONFIG_PS3_PS3AV) += ps3av.o ps3av_cmd.o 2obj-$(CONFIG_PS3_PS3AV) += ps3av.o ps3av_cmd.o
3obj-$(CONFIG_PS3_SYS_MANAGER) += sys-manager.o
diff --git a/drivers/ps3/sys-manager.c b/drivers/ps3/sys-manager.c
new file mode 100644
index 000000000000..0fc30be8b81e
--- /dev/null
+++ b/drivers/ps3/sys-manager.c
@@ -0,0 +1,604 @@
1/*
2 * PS3 System Manager.
3 *
4 * Copyright (C) 2007 Sony Computer Entertainment Inc.
5 * Copyright 2007 Sony Corp.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#include <linux/kernel.h>
22#include <linux/module.h>
23#include <linux/workqueue.h>
24#include <linux/reboot.h>
25#include <asm/ps3.h>
26#include "vuart.h"
27
28MODULE_AUTHOR("Sony Corporation");
29MODULE_LICENSE("GPL v2");
30MODULE_DESCRIPTION("PS3 System Manager");
31
32/**
33 * ps3_sys_manager - PS3 system manager driver.
34 *
35 * The system manager provides an asyncronous system event notification
36 * mechanism for reporting events like thermal alert and button presses to
37 * guests. It also provides support to control system shutdown and startup.
38 *
39 * The actual system manager is implemented as an application running in the
40 * system policy module in lpar_1. Guests communicate with the system manager
41 * through port 2 of the vuart using a simple packet message protocol.
42 * Messages are comprised of a fixed field header followed by a message
43 * specific payload.
44 */
45
46/**
47 * struct ps3_sys_manager_header - System manager message header.
48 * @version: Header version, currently 1.
49 * @size: Header size in bytes, curently 16.
50 * @payload_size: Message payload size in bytes.
51 * @service_id: Message type, one of enum ps3_sys_manager_service_id.
52 */
53
54struct ps3_sys_manager_header {
55 /* version 1 */
56 u8 version;
57 u8 size;
58 u16 reserved_1;
59 u32 payload_size;
60 u16 service_id;
61 u16 reserved_2[3];
62};
63
64/**
65 * @PS3_SM_RX_MSG_LEN - System manager received message length.
66 *
67 * Currently all messages received from the system manager are the same length
68 * (16 bytes header + 16 bytes payload = 32 bytes). This knowlege is used to
69 * simplify the logic.
70 */
71
72enum {
73 PS3_SM_RX_MSG_LEN = 32,
74};
75
76/**
77 * enum ps3_sys_manager_service_id - Message header service_id.
78 * @PS3_SM_SERVICE_ID_REQUEST: guest --> sys_manager.
79 * @PS3_SM_SERVICE_ID_COMMAND: guest <-- sys_manager.
80 * @PS3_SM_SERVICE_ID_RESPONSE: guest --> sys_manager.
81 * @PS3_SM_SERVICE_ID_SET_ATTR: guest --> sys_manager.
82 * @PS3_SM_SERVICE_ID_EXTERN_EVENT: guest <-- sys_manager.
83 * @PS3_SM_SERVICE_ID_SET_NEXT_OP: guest --> sys_manager.
84 */
85
86enum ps3_sys_manager_service_id {
87 /* version 1 */
88 PS3_SM_SERVICE_ID_REQUEST = 1,
89 PS3_SM_SERVICE_ID_RESPONSE = 2,
90 PS3_SM_SERVICE_ID_COMMAND = 3,
91 PS3_SM_SERVICE_ID_EXTERN_EVENT = 4,
92 PS3_SM_SERVICE_ID_SET_NEXT_OP = 5,
93 PS3_SM_SERVICE_ID_SET_ATTR = 8,
94};
95
96/**
97 * enum ps3_sys_manager_attr - Notification attribute (bit position mask).
98 * @PS3_SM_ATTR_POWER: Power button.
99 * @PS3_SM_ATTR_RESET: Reset button, not available on retail console.
100 * @PS3_SM_ATTR_THERMAL: Sytem thermal alert.
101 * @PS3_SM_ATTR_CONTROLLER: Remote controller event.
102 * @PS3_SM_ATTR_ALL: Logical OR of all.
103 *
104 * The guest tells the system manager which events it is interested in receiving
105 * notice of by sending the system manager a logical OR of notification
106 * attributes via the ps3_sys_manager_send_attr() routine.
107 */
108
109enum ps3_sys_manager_attr {
110 /* version 1 */
111 PS3_SM_ATTR_POWER = 1,
112 PS3_SM_ATTR_RESET = 2,
113 PS3_SM_ATTR_THERMAL = 4,
114 PS3_SM_ATTR_CONTROLLER = 8, /* bogus? */
115 PS3_SM_ATTR_ALL = 0x0f,
116};
117
118/**
119 * enum ps3_sys_manager_event - External event type, reported by system manager.
120 * @PS3_SM_EVENT_POWER_PRESSED: payload.value not used.
121 * @PS3_SM_EVENT_POWER_RELEASED: payload.value = time pressed in millisec.
122 * @PS3_SM_EVENT_RESET_PRESSED: payload.value not used.
123 * @PS3_SM_EVENT_RESET_RELEASED: payload.value = time pressed in millisec.
124 * @PS3_SM_EVENT_THERMAL_ALERT: payload.value = thermal zone id.
125 * @PS3_SM_EVENT_THERMAL_CLEARED: payload.value = thermal zone id.
126 */
127
128enum ps3_sys_manager_event {
129 /* version 1 */
130 PS3_SM_EVENT_POWER_PRESSED = 3,
131 PS3_SM_EVENT_POWER_RELEASED = 4,
132 PS3_SM_EVENT_RESET_PRESSED = 5,
133 PS3_SM_EVENT_RESET_RELEASED = 6,
134 PS3_SM_EVENT_THERMAL_ALERT = 7,
135 PS3_SM_EVENT_THERMAL_CLEARED = 8,
136 /* no info on controller events */
137};
138
139/**
140 * enum ps3_sys_manager_next_op - Operation to perform after lpar is destroyed.
141 */
142
143enum ps3_sys_manager_next_op {
144 /* version 3 */
145 PS3_SM_NEXT_OP_SYS_SHUTDOWN = 1,
146 PS3_SM_NEXT_OP_SYS_REBOOT = 2,
147 PS3_SM_NEXT_OP_LPAR_REBOOT = 0x82,
148};
149
150/**
151 * enum ps3_sys_manager_wake_source - Next-op wakeup source (bit position mask).
152 * @PS3_SM_WAKE_DEFAULT: Disk insert, power button, eject button, IR
153 * controller, and bluetooth controller.
154 * @PS3_SM_WAKE_RTC:
155 * @PS3_SM_WAKE_RTC_ERROR:
156 * @PS3_SM_WAKE_P_O_R: Power on reset.
157 *
158 * Additional wakeup sources when specifying PS3_SM_NEXT_OP_SYS_SHUTDOWN.
159 * System will always wake from the PS3_SM_WAKE_DEFAULT sources.
160 */
161
162enum ps3_sys_manager_wake_source {
163 /* version 3 */
164 PS3_SM_WAKE_DEFAULT = 0,
165 PS3_SM_WAKE_RTC = 0x00000040,
166 PS3_SM_WAKE_RTC_ERROR = 0x00000080,
167 PS3_SM_WAKE_P_O_R = 0x10000000,
168};
169
170/**
171 * enum ps3_sys_manager_cmd - Command from system manager to guest.
172 *
173 * The guest completes the actions needed, then acks or naks the command via
174 * ps3_sys_manager_send_response(). In the case of @PS3_SM_CMD_SHUTDOWN,
175 * the guest must be fully prepared for a system poweroff prior to acking the
176 * command.
177 */
178
179enum ps3_sys_manager_cmd {
180 /* version 1 */
181 PS3_SM_CMD_SHUTDOWN = 1, /* shutdown guest OS */
182};
183
184/**
185 * ps3_sys_manager_write - Helper to write a two part message to the vuart.
186 *
187 */
188
189static int ps3_sys_manager_write(struct ps3_vuart_port_device *dev,
190 const struct ps3_sys_manager_header *header, const void *payload)
191{
192 int result;
193
194 BUG_ON(header->version != 1);
195 BUG_ON(header->size != 16);
196 BUG_ON(header->payload_size != 8 && header->payload_size != 16);
197 BUG_ON(header->service_id > 8);
198
199 result = ps3_vuart_write(dev, header,
200 sizeof(struct ps3_sys_manager_header));
201
202 if (!result)
203 result = ps3_vuart_write(dev, payload, header->payload_size);
204
205 return result;
206}
207
208/**
209 * ps3_sys_manager_send_attr - Send a 'set attribute' to the system manager.
210 *
211 */
212
213static int ps3_sys_manager_send_attr(struct ps3_vuart_port_device *dev,
214 enum ps3_sys_manager_attr attr)
215{
216 static const struct ps3_sys_manager_header header = {
217 .version = 1,
218 .size = 16,
219 .payload_size = 16,
220 .service_id = PS3_SM_SERVICE_ID_SET_ATTR,
221 };
222 struct {
223 u8 version;
224 u8 reserved_1[3];
225 u32 attribute;
226 } payload;
227
228 BUILD_BUG_ON(sizeof(payload) != 8);
229
230 dev_dbg(&dev->core, "%s:%d: %xh\n", __func__, __LINE__, attr);
231
232 memset(&payload, 0, sizeof(payload));
233 payload.version = 1;
234 payload.attribute = attr;
235
236 return ps3_sys_manager_write(dev, &header, &payload);
237}
238
239/**
240 * ps3_sys_manager_send_next_op - Send a 'set next op' to the system manager.
241 *
242 * Tell the system manager what to do after this lpar is destroyed.
243 */
244
245static int ps3_sys_manager_send_next_op(struct ps3_vuart_port_device *dev,
246 enum ps3_sys_manager_next_op op,
247 enum ps3_sys_manager_wake_source wake_source)
248{
249 static const struct ps3_sys_manager_header header = {
250 .version = 1,
251 .size = 16,
252 .payload_size = 16,
253 .service_id = PS3_SM_SERVICE_ID_SET_NEXT_OP,
254 };
255 struct {
256 u8 version;
257 u8 type;
258 u8 gos_id;
259 u8 reserved_1;
260 u32 wake_source;
261 u8 reserved_2[8];
262 } payload;
263
264 BUILD_BUG_ON(sizeof(payload) != 16);
265
266 dev_dbg(&dev->core, "%s:%d: (%xh)\n", __func__, __LINE__, op);
267
268 memset(&payload, 0, sizeof(payload));
269 payload.version = 3;
270 payload.type = op;
271 payload.gos_id = 3; /* other os */
272 payload.wake_source = wake_source;
273
274 return ps3_sys_manager_write(dev, &header, &payload);
275}
276
277/**
278 * ps3_sys_manager_send_request_shutdown - Send 'request' to the system manager.
279 *
280 * The guest sends this message to request an operation or action of the system
281 * manager. The reply is a command message from the system manager. In the
282 * command handler the guest performs the requested operation. The result of
283 * the command is then communicated back to the system manager with a response
284 * message.
285 *
286 * Currently, the only supported request it the 'shutdown self' request.
287 */
288
289static int ps3_sys_manager_send_request_shutdown(struct ps3_vuart_port_device *dev)
290{
291 static const struct ps3_sys_manager_header header = {
292 .version = 1,
293 .size = 16,
294 .payload_size = 16,
295 .service_id = PS3_SM_SERVICE_ID_REQUEST,
296 };
297 struct {
298 u8 version;
299 u8 type;
300 u8 gos_id;
301 u8 reserved_1[13];
302 } static const payload = {
303 .version = 1,
304 .type = 1, /* shutdown */
305 .gos_id = 0, /* self */
306 };
307
308 BUILD_BUG_ON(sizeof(payload) != 16);
309
310 dev_dbg(&dev->core, "%s:%d\n", __func__, __LINE__);
311
312 return ps3_sys_manager_write(dev, &header, &payload);
313}
314
315/**
316 * ps3_sys_manager_send_response - Send a 'response' to the system manager.
317 * @status: zero = success, others fail.
318 *
319 * The guest sends this message to the system manager to acnowledge success or
320 * failure of a command sent by the system manager.
321 */
322
323static int ps3_sys_manager_send_response(struct ps3_vuart_port_device *dev,
324 u64 status)
325{
326 static const struct ps3_sys_manager_header header = {
327 .version = 1,
328 .size = 16,
329 .payload_size = 16,
330 .service_id = PS3_SM_SERVICE_ID_RESPONSE,
331 };
332 struct {
333 u8 version;
334 u8 reserved_1[3];
335 u8 status;
336 u8 reserved_2[11];
337 } payload;
338
339 BUILD_BUG_ON(sizeof(payload) != 16);
340
341 dev_dbg(&dev->core, "%s:%d: (%s)\n", __func__, __LINE__,
342 (status ? "nak" : "ack"));
343
344 memset(&payload, 0, sizeof(payload));
345 payload.version = 1;
346 payload.status = status;
347
348 return ps3_sys_manager_write(dev, &header, &payload);
349}
350
351/**
352 * ps3_sys_manager_handle_event - Second stage event msg handler.
353 *
354 */
355
356static int ps3_sys_manager_handle_event(struct ps3_vuart_port_device *dev)
357{
358 int result;
359 struct {
360 u8 version;
361 u8 type;
362 u8 reserved_1[2];
363 u32 value;
364 u8 reserved_2[8];
365 } event;
366
367 BUILD_BUG_ON(sizeof(event) != 16);
368
369 result = ps3_vuart_read(dev, &event, sizeof(event));
370 BUG_ON(result);
371
372 if (event.version != 1) {
373 dev_dbg(&dev->core, "%s:%d: unsupported event version (%u)\n",
374 __func__, __LINE__, event.version);
375 return -EIO;
376 }
377
378 switch (event.type) {
379 case PS3_SM_EVENT_POWER_PRESSED:
380 dev_dbg(&dev->core, "%s:%d: POWER_PRESSED\n",
381 __func__, __LINE__);
382 break;
383 case PS3_SM_EVENT_POWER_RELEASED:
384 dev_dbg(&dev->core, "%s:%d: POWER_RELEASED (%u ms)\n",
385 __func__, __LINE__, event.value);
386 kill_cad_pid(SIGINT, 1);
387 break;
388 case PS3_SM_EVENT_THERMAL_ALERT:
389 dev_dbg(&dev->core, "%s:%d: THERMAL_ALERT (zone %u)\n",
390 __func__, __LINE__, event.value);
391 printk(KERN_INFO "PS3 Thermal Alert Zone %u\n", event.value);
392 break;
393 case PS3_SM_EVENT_THERMAL_CLEARED:
394 dev_dbg(&dev->core, "%s:%d: THERMAL_CLEARED (zone %u)\n",
395 __func__, __LINE__, event.value);
396 break;
397 default:
398 dev_dbg(&dev->core, "%s:%d: unknown event (%u)\n",
399 __func__, __LINE__, event.type);
400 return -EIO;
401 }
402
403 return 0;
404}
405/**
406 * ps3_sys_manager_handle_cmd - Second stage command msg handler.
407 *
408 * The system manager sends this in reply to a 'request' message from the guest.
409 */
410
411static int ps3_sys_manager_handle_cmd(struct ps3_vuart_port_device *dev)
412{
413 int result;
414 struct {
415 u8 version;
416 u8 type;
417 u8 reserved_1[14];
418 } cmd;
419
420 BUILD_BUG_ON(sizeof(cmd) != 16);
421
422 dev_dbg(&dev->core, "%s:%d\n", __func__, __LINE__);
423
424 result = ps3_vuart_read(dev, &cmd, sizeof(cmd));
425
426 if(result)
427 return result;
428
429 if (cmd.version != 1) {
430 dev_dbg(&dev->core, "%s:%d: unsupported cmd version (%u)\n",
431 __func__, __LINE__, cmd.version);
432 return -EIO;
433 }
434
435 if (cmd.type != PS3_SM_CMD_SHUTDOWN) {
436 dev_dbg(&dev->core, "%s:%d: unknown cmd (%u)\n",
437 __func__, __LINE__, cmd.type);
438 return -EIO;
439 }
440
441 ps3_sys_manager_send_response(dev, 0);
442 return 0;
443}
444
445/**
446 * ps3_sys_manager_handle_msg - First stage msg handler.
447 *
448 */
449
450static int ps3_sys_manager_handle_msg(struct ps3_vuart_port_device *dev)
451{
452 int result;
453 struct ps3_sys_manager_header header;
454
455 result = ps3_vuart_read(dev, &header,
456 sizeof(struct ps3_sys_manager_header));
457
458 if(result)
459 return result;
460
461 if (header.version != 1) {
462 dev_dbg(&dev->core, "%s:%d: unsupported header version (%u)\n",
463 __func__, __LINE__, header.version);
464 goto fail_header;
465 }
466
467 BUILD_BUG_ON(sizeof(header) != 16);
468 BUG_ON(header.size != 16);
469 BUG_ON(header.payload_size != 16);
470
471 switch (header.service_id) {
472 case PS3_SM_SERVICE_ID_EXTERN_EVENT:
473 dev_dbg(&dev->core, "%s:%d: EVENT\n", __func__, __LINE__);
474 return ps3_sys_manager_handle_event(dev);
475 case PS3_SM_SERVICE_ID_COMMAND:
476 dev_dbg(&dev->core, "%s:%d: COMMAND\n", __func__, __LINE__);
477 return ps3_sys_manager_handle_cmd(dev);
478 default:
479 dev_dbg(&dev->core, "%s:%d: unknown service_id (%u)\n",
480 __func__, __LINE__, header.service_id);
481 break;
482 }
483 goto fail_id;
484
485fail_header:
486 ps3_vuart_clear_rx_bytes(dev, 0);
487 return -EIO;
488fail_id:
489 ps3_vuart_clear_rx_bytes(dev, header.payload_size);
490 return -EIO;
491}
492
493/**
494 * ps3_sys_manager_work - Asyncronous read handler.
495 *
496 * Signaled when a complete message arrives at the vuart port.
497 */
498
499static void ps3_sys_manager_work(struct work_struct *work)
500{
501 struct ps3_vuart_port_device *dev = ps3_vuart_work_to_port_device(work);
502
503 ps3_sys_manager_handle_msg(dev);
504 ps3_vuart_read_async(dev, ps3_sys_manager_work, PS3_SM_RX_MSG_LEN);
505}
506
507struct {
508 struct ps3_vuart_port_device *dev;
509} static drv_priv;
510
511/**
512 * ps3_sys_manager_restart - The final platform machine_restart routine.
513 *
514 * This routine never returns. The routine disables asyncronous vuart reads
515 * then spins calling ps3_sys_manager_handle_msg() to receive and acknowledge
516 * the shutdown command sent from the system manager. Soon after the
517 * acknowledgement is sent the lpar is destroyed by the HV. This routine
518 * should only be called from ps3_restart().
519 */
520
521void ps3_sys_manager_restart(void)
522{
523 struct ps3_vuart_port_device *dev = drv_priv.dev;
524
525 BUG_ON(!drv_priv.dev);
526
527 dev_dbg(&dev->core, "%s:%d\n", __func__, __LINE__);
528
529 ps3_vuart_cancel_async(dev);
530
531 ps3_sys_manager_send_attr(dev, 0);
532 ps3_sys_manager_send_next_op(dev, PS3_SM_NEXT_OP_LPAR_REBOOT,
533 PS3_SM_WAKE_DEFAULT);
534 ps3_sys_manager_send_request_shutdown(dev);
535
536 printk(KERN_EMERG "System Halted, OK to turn off power\n");
537
538 while(1)
539 ps3_sys_manager_handle_msg(dev);
540}
541
542/**
543 * ps3_sys_manager_power_off - The final platform machine_power_off routine.
544 *
545 * This routine never returns. The routine disables asyncronous vuart reads
546 * then spins calling ps3_sys_manager_handle_msg() to receive and acknowledge
547 * the shutdown command sent from the system manager. Soon after the
548 * acknowledgement is sent the lpar is destroyed by the HV. This routine
549 * should only be called from ps3_power_off().
550 */
551
552void ps3_sys_manager_power_off(void)
553{
554 struct ps3_vuart_port_device *dev = drv_priv.dev;
555
556 BUG_ON(!drv_priv.dev);
557
558 dev_dbg(&dev->core, "%s:%d\n", __func__, __LINE__);
559
560 ps3_vuart_cancel_async(dev);
561
562 ps3_sys_manager_send_next_op(dev, PS3_SM_NEXT_OP_SYS_SHUTDOWN,
563 PS3_SM_WAKE_DEFAULT);
564 ps3_sys_manager_send_request_shutdown(dev);
565
566 printk(KERN_EMERG "System Halted, OK to turn off power\n");
567
568 while(1)
569 ps3_sys_manager_handle_msg(dev);
570}
571
572static int ps3_sys_manager_probe(struct ps3_vuart_port_device *dev)
573{
574 int result;
575
576 dev_dbg(&dev->core, "%s:%d\n", __func__, __LINE__);
577
578 BUG_ON(drv_priv.dev);
579 drv_priv.dev = dev;
580
581 result = ps3_sys_manager_send_attr(dev, PS3_SM_ATTR_ALL);
582 BUG_ON(result);
583
584 result = ps3_vuart_read_async(dev, ps3_sys_manager_work,
585 PS3_SM_RX_MSG_LEN);
586 BUG_ON(result);
587
588 return result;
589}
590
591static struct ps3_vuart_port_driver ps3_sys_manager = {
592 .match_id = PS3_MATCH_ID_SYSTEM_MANAGER,
593 .core = {
594 .name = "ps3_sys_manager",
595 },
596 .probe = ps3_sys_manager_probe,
597};
598
599static int __init ps3_sys_manager_init(void)
600{
601 return ps3_vuart_port_driver_register(&ps3_sys_manager);
602}
603
604module_init(ps3_sys_manager_init);
diff --git a/drivers/ps3/vuart.c b/drivers/ps3/vuart.c
index ef8fd4c30875..746298107d6f 100644
--- a/drivers/ps3/vuart.c
+++ b/drivers/ps3/vuart.c
@@ -21,8 +21,10 @@
21#include <linux/kernel.h> 21#include <linux/kernel.h>
22#include <linux/module.h> 22#include <linux/module.h>
23#include <linux/interrupt.h> 23#include <linux/interrupt.h>
24#include <linux/workqueue.h>
24#include <asm/ps3.h> 25#include <asm/ps3.h>
25 26
27#include <asm/firmware.h>
26#include <asm/lv1call.h> 28#include <asm/lv1call.h>
27#include <asm/bitops.h> 29#include <asm/bitops.h>
28 30
@@ -30,7 +32,7 @@
30 32
31MODULE_AUTHOR("Sony Corporation"); 33MODULE_AUTHOR("Sony Corporation");
32MODULE_LICENSE("GPL v2"); 34MODULE_LICENSE("GPL v2");
33MODULE_DESCRIPTION("ps3 vuart"); 35MODULE_DESCRIPTION("PS3 vuart");
34 36
35/** 37/**
36 * vuart - An inter-partition data link service. 38 * vuart - An inter-partition data link service.
@@ -157,7 +159,7 @@ int ps3_vuart_get_triggers(struct ps3_vuart_port_device *dev,
157 unsigned long size; 159 unsigned long size;
158 unsigned long val; 160 unsigned long val;
159 161
160 result = lv1_get_virtual_uart_param(dev->port_number, 162 result = lv1_get_virtual_uart_param(dev->priv->port_number,
161 PARAM_TX_TRIGGER, &trig->tx); 163 PARAM_TX_TRIGGER, &trig->tx);
162 164
163 if (result) { 165 if (result) {
@@ -166,7 +168,7 @@ int ps3_vuart_get_triggers(struct ps3_vuart_port_device *dev,
166 return result; 168 return result;
167 } 169 }
168 170
169 result = lv1_get_virtual_uart_param(dev->port_number, 171 result = lv1_get_virtual_uart_param(dev->priv->port_number,
170 PARAM_RX_BUF_SIZE, &size); 172 PARAM_RX_BUF_SIZE, &size);
171 173
172 if (result) { 174 if (result) {
@@ -175,7 +177,7 @@ int ps3_vuart_get_triggers(struct ps3_vuart_port_device *dev,
175 return result; 177 return result;
176 } 178 }
177 179
178 result = lv1_get_virtual_uart_param(dev->port_number, 180 result = lv1_get_virtual_uart_param(dev->priv->port_number,
179 PARAM_RX_TRIGGER, &val); 181 PARAM_RX_TRIGGER, &val);
180 182
181 if (result) { 183 if (result) {
@@ -198,7 +200,7 @@ int ps3_vuart_set_triggers(struct ps3_vuart_port_device *dev, unsigned int tx,
198 int result; 200 int result;
199 unsigned long size; 201 unsigned long size;
200 202
201 result = lv1_set_virtual_uart_param(dev->port_number, 203 result = lv1_set_virtual_uart_param(dev->priv->port_number,
202 PARAM_TX_TRIGGER, tx); 204 PARAM_TX_TRIGGER, tx);
203 205
204 if (result) { 206 if (result) {
@@ -207,7 +209,7 @@ int ps3_vuart_set_triggers(struct ps3_vuart_port_device *dev, unsigned int tx,
207 return result; 209 return result;
208 } 210 }
209 211
210 result = lv1_get_virtual_uart_param(dev->port_number, 212 result = lv1_get_virtual_uart_param(dev->priv->port_number,
211 PARAM_RX_BUF_SIZE, &size); 213 PARAM_RX_BUF_SIZE, &size);
212 214
213 if (result) { 215 if (result) {
@@ -216,7 +218,7 @@ int ps3_vuart_set_triggers(struct ps3_vuart_port_device *dev, unsigned int tx,
216 return result; 218 return result;
217 } 219 }
218 220
219 result = lv1_set_virtual_uart_param(dev->port_number, 221 result = lv1_set_virtual_uart_param(dev->priv->port_number,
220 PARAM_RX_TRIGGER, size - rx); 222 PARAM_RX_TRIGGER, size - rx);
221 223
222 if (result) { 224 if (result) {
@@ -232,9 +234,9 @@ int ps3_vuart_set_triggers(struct ps3_vuart_port_device *dev, unsigned int tx,
232} 234}
233 235
234static int ps3_vuart_get_rx_bytes_waiting(struct ps3_vuart_port_device *dev, 236static int ps3_vuart_get_rx_bytes_waiting(struct ps3_vuart_port_device *dev,
235 unsigned long *bytes_waiting) 237 u64 *bytes_waiting)
236{ 238{
237 int result = lv1_get_virtual_uart_param(dev->port_number, 239 int result = lv1_get_virtual_uart_param(dev->priv->port_number,
238 PARAM_RX_BYTES, bytes_waiting); 240 PARAM_RX_BYTES, bytes_waiting);
239 241
240 if (result) 242 if (result)
@@ -253,10 +255,10 @@ static int ps3_vuart_set_interrupt_mask(struct ps3_vuart_port_device *dev,
253 255
254 dev_dbg(&dev->core, "%s:%d: %lxh\n", __func__, __LINE__, mask); 256 dev_dbg(&dev->core, "%s:%d: %lxh\n", __func__, __LINE__, mask);
255 257
256 dev->interrupt_mask = mask; 258 dev->priv->interrupt_mask = mask;
257 259
258 result = lv1_set_virtual_uart_param(dev->port_number, 260 result = lv1_set_virtual_uart_param(dev->priv->port_number,
259 PARAM_INTERRUPT_MASK, dev->interrupt_mask); 261 PARAM_INTERRUPT_MASK, dev->priv->interrupt_mask);
260 262
261 if (result) 263 if (result)
262 dev_dbg(&dev->core, "%s:%d: interrupt_mask failed: %s\n", 264 dev_dbg(&dev->core, "%s:%d: interrupt_mask failed: %s\n",
@@ -265,62 +267,64 @@ static int ps3_vuart_set_interrupt_mask(struct ps3_vuart_port_device *dev,
265 return result; 267 return result;
266} 268}
267 269
268static int ps3_vuart_get_interrupt_mask(struct ps3_vuart_port_device *dev, 270static int ps3_vuart_get_interrupt_status(struct ps3_vuart_port_device *dev,
269 unsigned long *status) 271 unsigned long *status)
270{ 272{
271 int result = lv1_get_virtual_uart_param(dev->port_number, 273 u64 tmp;
272 PARAM_INTERRUPT_STATUS, status); 274 int result = lv1_get_virtual_uart_param(dev->priv->port_number,
275 PARAM_INTERRUPT_STATUS, &tmp);
273 276
274 if (result) 277 if (result)
275 dev_dbg(&dev->core, "%s:%d: interrupt_status failed: %s\n", 278 dev_dbg(&dev->core, "%s:%d: interrupt_status failed: %s\n",
276 __func__, __LINE__, ps3_result(result)); 279 __func__, __LINE__, ps3_result(result));
277 280
281 *status = tmp & dev->priv->interrupt_mask;
282
278 dev_dbg(&dev->core, "%s:%d: m %lxh, s %lxh, m&s %lxh\n", 283 dev_dbg(&dev->core, "%s:%d: m %lxh, s %lxh, m&s %lxh\n",
279 __func__, __LINE__, dev->interrupt_mask, *status, 284 __func__, __LINE__, dev->priv->interrupt_mask, tmp, *status);
280 dev->interrupt_mask & *status);
281 285
282 return result; 286 return result;
283} 287}
284 288
285int ps3_vuart_enable_interrupt_tx(struct ps3_vuart_port_device *dev) 289int ps3_vuart_enable_interrupt_tx(struct ps3_vuart_port_device *dev)
286{ 290{
287 return (dev->interrupt_mask & INTERRUPT_MASK_TX) ? 0 291 return (dev->priv->interrupt_mask & INTERRUPT_MASK_TX) ? 0
288 : ps3_vuart_set_interrupt_mask(dev, dev->interrupt_mask 292 : ps3_vuart_set_interrupt_mask(dev, dev->priv->interrupt_mask
289 | INTERRUPT_MASK_TX); 293 | INTERRUPT_MASK_TX);
290} 294}
291 295
292int ps3_vuart_enable_interrupt_rx(struct ps3_vuart_port_device *dev) 296int ps3_vuart_enable_interrupt_rx(struct ps3_vuart_port_device *dev)
293{ 297{
294 return (dev->interrupt_mask & INTERRUPT_MASK_RX) ? 0 298 return (dev->priv->interrupt_mask & INTERRUPT_MASK_RX) ? 0
295 : ps3_vuart_set_interrupt_mask(dev, dev->interrupt_mask 299 : ps3_vuart_set_interrupt_mask(dev, dev->priv->interrupt_mask
296 | INTERRUPT_MASK_RX); 300 | INTERRUPT_MASK_RX);
297} 301}
298 302
299int ps3_vuart_enable_interrupt_disconnect(struct ps3_vuart_port_device *dev) 303int ps3_vuart_enable_interrupt_disconnect(struct ps3_vuart_port_device *dev)
300{ 304{
301 return (dev->interrupt_mask & INTERRUPT_MASK_DISCONNECT) ? 0 305 return (dev->priv->interrupt_mask & INTERRUPT_MASK_DISCONNECT) ? 0
302 : ps3_vuart_set_interrupt_mask(dev, dev->interrupt_mask 306 : ps3_vuart_set_interrupt_mask(dev, dev->priv->interrupt_mask
303 | INTERRUPT_MASK_DISCONNECT); 307 | INTERRUPT_MASK_DISCONNECT);
304} 308}
305 309
306int ps3_vuart_disable_interrupt_tx(struct ps3_vuart_port_device *dev) 310int ps3_vuart_disable_interrupt_tx(struct ps3_vuart_port_device *dev)
307{ 311{
308 return (dev->interrupt_mask & INTERRUPT_MASK_TX) 312 return (dev->priv->interrupt_mask & INTERRUPT_MASK_TX)
309 ? ps3_vuart_set_interrupt_mask(dev, dev->interrupt_mask 313 ? ps3_vuart_set_interrupt_mask(dev, dev->priv->interrupt_mask
310 & ~INTERRUPT_MASK_TX) : 0; 314 & ~INTERRUPT_MASK_TX) : 0;
311} 315}
312 316
313int ps3_vuart_disable_interrupt_rx(struct ps3_vuart_port_device *dev) 317int ps3_vuart_disable_interrupt_rx(struct ps3_vuart_port_device *dev)
314{ 318{
315 return (dev->interrupt_mask & INTERRUPT_MASK_RX) 319 return (dev->priv->interrupt_mask & INTERRUPT_MASK_RX)
316 ? ps3_vuart_set_interrupt_mask(dev, dev->interrupt_mask 320 ? ps3_vuart_set_interrupt_mask(dev, dev->priv->interrupt_mask
317 & ~INTERRUPT_MASK_RX) : 0; 321 & ~INTERRUPT_MASK_RX) : 0;
318} 322}
319 323
320int ps3_vuart_disable_interrupt_disconnect(struct ps3_vuart_port_device *dev) 324int ps3_vuart_disable_interrupt_disconnect(struct ps3_vuart_port_device *dev)
321{ 325{
322 return (dev->interrupt_mask & INTERRUPT_MASK_DISCONNECT) 326 return (dev->priv->interrupt_mask & INTERRUPT_MASK_DISCONNECT)
323 ? ps3_vuart_set_interrupt_mask(dev, dev->interrupt_mask 327 ? ps3_vuart_set_interrupt_mask(dev, dev->priv->interrupt_mask
324 & ~INTERRUPT_MASK_DISCONNECT) : 0; 328 & ~INTERRUPT_MASK_DISCONNECT) : 0;
325} 329}
326 330
@@ -335,9 +339,7 @@ static int ps3_vuart_raw_write(struct ps3_vuart_port_device *dev,
335{ 339{
336 int result; 340 int result;
337 341
338 dev_dbg(&dev->core, "%s:%d: %xh\n", __func__, __LINE__, bytes); 342 result = lv1_write_virtual_uart(dev->priv->port_number,
339
340 result = lv1_write_virtual_uart(dev->port_number,
341 ps3_mm_phys_to_lpar(__pa(buf)), bytes, bytes_written); 343 ps3_mm_phys_to_lpar(__pa(buf)), bytes, bytes_written);
342 344
343 if (result) { 345 if (result) {
@@ -346,10 +348,10 @@ static int ps3_vuart_raw_write(struct ps3_vuart_port_device *dev,
346 return result; 348 return result;
347 } 349 }
348 350
349 dev->stats.bytes_written += *bytes_written; 351 dev->priv->stats.bytes_written += *bytes_written;
350 352
351 dev_dbg(&dev->core, "%s:%d: wrote %lxh/%xh=>%lxh\n", __func__, 353 dev_dbg(&dev->core, "%s:%d: wrote %lxh/%xh=>%lxh\n", __func__, __LINE__,
352 __LINE__, *bytes_written, bytes, dev->stats.bytes_written); 354 *bytes_written, bytes, dev->priv->stats.bytes_written);
353 355
354 return result; 356 return result;
355} 357}
@@ -367,7 +369,7 @@ static int ps3_vuart_raw_read(struct ps3_vuart_port_device *dev, void* buf,
367 369
368 dev_dbg(&dev->core, "%s:%d: %xh\n", __func__, __LINE__, bytes); 370 dev_dbg(&dev->core, "%s:%d: %xh\n", __func__, __LINE__, bytes);
369 371
370 result = lv1_read_virtual_uart(dev->port_number, 372 result = lv1_read_virtual_uart(dev->priv->port_number,
371 ps3_mm_phys_to_lpar(__pa(buf)), bytes, bytes_read); 373 ps3_mm_phys_to_lpar(__pa(buf)), bytes, bytes_read);
372 374
373 if (result) { 375 if (result) {
@@ -376,15 +378,58 @@ static int ps3_vuart_raw_read(struct ps3_vuart_port_device *dev, void* buf,
376 return result; 378 return result;
377 } 379 }
378 380
379 dev->stats.bytes_read += *bytes_read; 381 dev->priv->stats.bytes_read += *bytes_read;
380 382
381 dev_dbg(&dev->core, "%s:%d: read %lxh/%xh=>%lxh\n", __func__, __LINE__, 383 dev_dbg(&dev->core, "%s:%d: read %lxh/%xh=>%lxh\n", __func__, __LINE__,
382 *bytes_read, bytes, dev->stats.bytes_read); 384 *bytes_read, bytes, dev->priv->stats.bytes_read);
383 385
384 return result; 386 return result;
385} 387}
386 388
387/** 389/**
390 * ps3_vuart_clear_rx_bytes - Discard bytes received.
391 * @bytes: Max byte count to discard, zero = all pending.
392 *
393 * Used to clear pending rx interrupt source. Will not block.
394 */
395
396void ps3_vuart_clear_rx_bytes(struct ps3_vuart_port_device *dev,
397 unsigned int bytes)
398{
399 int result;
400 u64 bytes_waiting;
401 void* tmp;
402
403 result = ps3_vuart_get_rx_bytes_waiting(dev, &bytes_waiting);
404
405 BUG_ON(result);
406
407 bytes = bytes ? min(bytes, (unsigned int)bytes_waiting) : bytes_waiting;
408
409 dev_dbg(&dev->core, "%s:%d: %u\n", __func__, __LINE__, bytes);
410
411 if (!bytes)
412 return;
413
414 /* Add some extra space for recently arrived data. */
415
416 bytes += 128;
417
418 tmp = kmalloc(bytes, GFP_KERNEL);
419
420 if (!tmp)
421 return;
422
423 ps3_vuart_raw_read(dev, tmp, bytes, &bytes_waiting);
424
425 kfree(tmp);
426
427 /* Don't include these bytes in the stats. */
428
429 dev->priv->stats.bytes_read -= bytes_waiting;
430}
431
432/**
388 * struct list_buffer - An element for a port device fifo buffer list. 433 * struct list_buffer - An element for a port device fifo buffer list.
389 */ 434 */
390 435
@@ -416,14 +461,14 @@ int ps3_vuart_write(struct ps3_vuart_port_device *dev, const void* buf,
416 dev_dbg(&dev->core, "%s:%d: %u(%xh) bytes\n", __func__, __LINE__, 461 dev_dbg(&dev->core, "%s:%d: %u(%xh) bytes\n", __func__, __LINE__,
417 bytes, bytes); 462 bytes, bytes);
418 463
419 spin_lock_irqsave(&dev->tx_list.lock, flags); 464 spin_lock_irqsave(&dev->priv->tx_list.lock, flags);
420 465
421 if (list_empty(&dev->tx_list.head)) { 466 if (list_empty(&dev->priv->tx_list.head)) {
422 unsigned long bytes_written; 467 unsigned long bytes_written;
423 468
424 result = ps3_vuart_raw_write(dev, buf, bytes, &bytes_written); 469 result = ps3_vuart_raw_write(dev, buf, bytes, &bytes_written);
425 470
426 spin_unlock_irqrestore(&dev->tx_list.lock, flags); 471 spin_unlock_irqrestore(&dev->priv->tx_list.lock, flags);
427 472
428 if (result) { 473 if (result) {
429 dev_dbg(&dev->core, 474 dev_dbg(&dev->core,
@@ -441,7 +486,7 @@ int ps3_vuart_write(struct ps3_vuart_port_device *dev, const void* buf,
441 bytes -= bytes_written; 486 bytes -= bytes_written;
442 buf += bytes_written; 487 buf += bytes_written;
443 } else 488 } else
444 spin_unlock_irqrestore(&dev->tx_list.lock, flags); 489 spin_unlock_irqrestore(&dev->priv->tx_list.lock, flags);
445 490
446 lb = kmalloc(sizeof(struct list_buffer) + bytes, GFP_KERNEL); 491 lb = kmalloc(sizeof(struct list_buffer) + bytes, GFP_KERNEL);
447 492
@@ -454,10 +499,10 @@ int ps3_vuart_write(struct ps3_vuart_port_device *dev, const void* buf,
454 lb->tail = lb->data + bytes; 499 lb->tail = lb->data + bytes;
455 lb->dbg_number = ++dbg_number; 500 lb->dbg_number = ++dbg_number;
456 501
457 spin_lock_irqsave(&dev->tx_list.lock, flags); 502 spin_lock_irqsave(&dev->priv->tx_list.lock, flags);
458 list_add_tail(&lb->link, &dev->tx_list.head); 503 list_add_tail(&lb->link, &dev->priv->tx_list.head);
459 ps3_vuart_enable_interrupt_tx(dev); 504 ps3_vuart_enable_interrupt_tx(dev);
460 spin_unlock_irqrestore(&dev->tx_list.lock, flags); 505 spin_unlock_irqrestore(&dev->priv->tx_list.lock, flags);
461 506
462 dev_dbg(&dev->core, "%s:%d: queued buf_%lu, %xh bytes\n", 507 dev_dbg(&dev->core, "%s:%d: queued buf_%lu, %xh bytes\n",
463 __func__, __LINE__, lb->dbg_number, bytes); 508 __func__, __LINE__, lb->dbg_number, bytes);
@@ -484,47 +529,83 @@ int ps3_vuart_read(struct ps3_vuart_port_device *dev, void* buf,
484 dev_dbg(&dev->core, "%s:%d: %u(%xh) bytes\n", __func__, __LINE__, 529 dev_dbg(&dev->core, "%s:%d: %u(%xh) bytes\n", __func__, __LINE__,
485 bytes, bytes); 530 bytes, bytes);
486 531
487 spin_lock_irqsave(&dev->rx_list.lock, flags); 532 spin_lock_irqsave(&dev->priv->rx_list.lock, flags);
488 533
489 if (dev->rx_list.bytes_held < bytes) { 534 if (dev->priv->rx_list.bytes_held < bytes) {
490 spin_unlock_irqrestore(&dev->rx_list.lock, flags); 535 spin_unlock_irqrestore(&dev->priv->rx_list.lock, flags);
491 dev_dbg(&dev->core, "%s:%d: starved for %lxh bytes\n", 536 dev_dbg(&dev->core, "%s:%d: starved for %lxh bytes\n",
492 __func__, __LINE__, bytes - dev->rx_list.bytes_held); 537 __func__, __LINE__,
538 bytes - dev->priv->rx_list.bytes_held);
493 return -EAGAIN; 539 return -EAGAIN;
494 } 540 }
495 541
496 list_for_each_entry_safe(lb, n, &dev->rx_list.head, link) { 542 list_for_each_entry_safe(lb, n, &dev->priv->rx_list.head, link) {
497 bytes_read = min((unsigned int)(lb->tail - lb->head), bytes); 543 bytes_read = min((unsigned int)(lb->tail - lb->head), bytes);
498 544
499 memcpy(buf, lb->head, bytes_read); 545 memcpy(buf, lb->head, bytes_read);
500 buf += bytes_read; 546 buf += bytes_read;
501 bytes -= bytes_read; 547 bytes -= bytes_read;
502 dev->rx_list.bytes_held -= bytes_read; 548 dev->priv->rx_list.bytes_held -= bytes_read;
503 549
504 if (bytes_read < lb->tail - lb->head) { 550 if (bytes_read < lb->tail - lb->head) {
505 lb->head += bytes_read; 551 lb->head += bytes_read;
506 spin_unlock_irqrestore(&dev->rx_list.lock, flags); 552 dev_dbg(&dev->core, "%s:%d: buf_%lu: dequeued %lxh "
507 553 "bytes\n", __func__, __LINE__, lb->dbg_number,
508 dev_dbg(&dev->core, 554 bytes_read);
509 "%s:%d: dequeued buf_%lu, %lxh bytes\n", 555 spin_unlock_irqrestore(&dev->priv->rx_list.lock, flags);
510 __func__, __LINE__, lb->dbg_number, bytes_read);
511 return 0; 556 return 0;
512 } 557 }
513 558
514 dev_dbg(&dev->core, "%s:%d free buf_%lu\n", __func__, __LINE__, 559 dev_dbg(&dev->core, "%s:%d: buf_%lu: free, dequeued %lxh "
515 lb->dbg_number); 560 "bytes\n", __func__, __LINE__, lb->dbg_number,
561 bytes_read);
516 562
517 list_del(&lb->link); 563 list_del(&lb->link);
518 kfree(lb); 564 kfree(lb);
519 } 565 }
520 spin_unlock_irqrestore(&dev->rx_list.lock, flags);
521 566
522 dev_dbg(&dev->core, "%s:%d: dequeued buf_%lu, %xh bytes\n", 567 spin_unlock_irqrestore(&dev->priv->rx_list.lock, flags);
523 __func__, __LINE__, lb->dbg_number, bytes); 568 return 0;
569}
570
571int ps3_vuart_read_async(struct ps3_vuart_port_device *dev, work_func_t func,
572 unsigned int bytes)
573{
574 unsigned long flags;
575
576 if(dev->priv->work.trigger) {
577 dev_dbg(&dev->core, "%s:%d: warning, multiple calls\n",
578 __func__, __LINE__);
579 return -EAGAIN;
580 }
581
582 BUG_ON(!bytes);
583
584 PREPARE_WORK(&dev->priv->work.work, func);
585
586 spin_lock_irqsave(&dev->priv->work.lock, flags);
587 if(dev->priv->rx_list.bytes_held >= bytes) {
588 dev_dbg(&dev->core, "%s:%d: schedule_work %xh bytes\n",
589 __func__, __LINE__, bytes);
590 schedule_work(&dev->priv->work.work);
591 spin_unlock_irqrestore(&dev->priv->work.lock, flags);
592 return 0;
593 }
594
595 dev->priv->work.trigger = bytes;
596 spin_unlock_irqrestore(&dev->priv->work.lock, flags);
597
598 dev_dbg(&dev->core, "%s:%d: waiting for %u(%xh) bytes\n", __func__,
599 __LINE__, bytes, bytes);
524 600
525 return 0; 601 return 0;
526} 602}
527 603
604void ps3_vuart_cancel_async(struct ps3_vuart_port_device *dev)
605{
606 dev->priv->work.trigger = 0;
607}
608
528/** 609/**
529 * ps3_vuart_handle_interrupt_tx - third stage transmit interrupt handler 610 * ps3_vuart_handle_interrupt_tx - third stage transmit interrupt handler
530 * 611 *
@@ -542,9 +623,9 @@ static int ps3_vuart_handle_interrupt_tx(struct ps3_vuart_port_device *dev)
542 623
543 dev_dbg(&dev->core, "%s:%d\n", __func__, __LINE__); 624 dev_dbg(&dev->core, "%s:%d\n", __func__, __LINE__);
544 625
545 spin_lock_irqsave(&dev->tx_list.lock, flags); 626 spin_lock_irqsave(&dev->priv->tx_list.lock, flags);
546 627
547 list_for_each_entry_safe(lb, n, &dev->tx_list.head, link) { 628 list_for_each_entry_safe(lb, n, &dev->priv->tx_list.head, link) {
548 629
549 unsigned long bytes_written; 630 unsigned long bytes_written;
550 631
@@ -578,7 +659,7 @@ static int ps3_vuart_handle_interrupt_tx(struct ps3_vuart_port_device *dev)
578 659
579 ps3_vuart_disable_interrupt_tx(dev); 660 ps3_vuart_disable_interrupt_tx(dev);
580port_full: 661port_full:
581 spin_unlock_irqrestore(&dev->tx_list.lock, flags); 662 spin_unlock_irqrestore(&dev->priv->tx_list.lock, flags);
582 dev_dbg(&dev->core, "%s:%d wrote %lxh bytes total\n", 663 dev_dbg(&dev->core, "%s:%d wrote %lxh bytes total\n",
583 __func__, __LINE__, bytes_total); 664 __func__, __LINE__, bytes_total);
584 return result; 665 return result;
@@ -609,7 +690,7 @@ static int ps3_vuart_handle_interrupt_rx(struct ps3_vuart_port_device *dev)
609 690
610 BUG_ON(!bytes); 691 BUG_ON(!bytes);
611 692
612 /* add some extra space for recently arrived data */ 693 /* Add some extra space for recently arrived data. */
613 694
614 bytes += 128; 695 bytes += 128;
615 696
@@ -624,14 +705,23 @@ static int ps3_vuart_handle_interrupt_rx(struct ps3_vuart_port_device *dev)
624 lb->tail = lb->data + bytes; 705 lb->tail = lb->data + bytes;
625 lb->dbg_number = ++dbg_number; 706 lb->dbg_number = ++dbg_number;
626 707
627 spin_lock_irqsave(&dev->rx_list.lock, flags); 708 spin_lock_irqsave(&dev->priv->rx_list.lock, flags);
628 list_add_tail(&lb->link, &dev->rx_list.head); 709 list_add_tail(&lb->link, &dev->priv->rx_list.head);
629 dev->rx_list.bytes_held += bytes; 710 dev->priv->rx_list.bytes_held += bytes;
630 spin_unlock_irqrestore(&dev->rx_list.lock, flags); 711 spin_unlock_irqrestore(&dev->priv->rx_list.lock, flags);
631 712
632 dev_dbg(&dev->core, "%s:%d: queued buf_%lu, %lxh bytes\n", 713 dev_dbg(&dev->core, "%s:%d: buf_%lu: queued %lxh bytes\n",
633 __func__, __LINE__, lb->dbg_number, bytes); 714 __func__, __LINE__, lb->dbg_number, bytes);
634 715
716 spin_lock_irqsave(&dev->priv->work.lock, flags);
717 if(dev->priv->work.trigger
718 && dev->priv->rx_list.bytes_held >= dev->priv->work.trigger) {
719 dev_dbg(&dev->core, "%s:%d: schedule_work %lxh bytes\n",
720 __func__, __LINE__, dev->priv->work.trigger);
721 dev->priv->work.trigger = 0;
722 schedule_work(&dev->priv->work.work);
723 }
724 spin_unlock_irqrestore(&dev->priv->work.lock, flags);
635 return 0; 725 return 0;
636} 726}
637 727
@@ -656,7 +746,7 @@ static int ps3_vuart_handle_port_interrupt(struct ps3_vuart_port_device *dev)
656 int result; 746 int result;
657 unsigned long status; 747 unsigned long status;
658 748
659 result = ps3_vuart_get_interrupt_mask(dev, &status); 749 result = ps3_vuart_get_interrupt_status(dev, &status);
660 750
661 if (result) 751 if (result)
662 return result; 752 return result;
@@ -665,21 +755,21 @@ static int ps3_vuart_handle_port_interrupt(struct ps3_vuart_port_device *dev)
665 status); 755 status);
666 756
667 if (status & INTERRUPT_MASK_DISCONNECT) { 757 if (status & INTERRUPT_MASK_DISCONNECT) {
668 dev->stats.disconnect_interrupts++; 758 dev->priv->stats.disconnect_interrupts++;
669 result = ps3_vuart_handle_interrupt_disconnect(dev); 759 result = ps3_vuart_handle_interrupt_disconnect(dev);
670 if (result) 760 if (result)
671 ps3_vuart_disable_interrupt_disconnect(dev); 761 ps3_vuart_disable_interrupt_disconnect(dev);
672 } 762 }
673 763
674 if (status & INTERRUPT_MASK_TX) { 764 if (status & INTERRUPT_MASK_TX) {
675 dev->stats.tx_interrupts++; 765 dev->priv->stats.tx_interrupts++;
676 result = ps3_vuart_handle_interrupt_tx(dev); 766 result = ps3_vuart_handle_interrupt_tx(dev);
677 if (result) 767 if (result)
678 ps3_vuart_disable_interrupt_tx(dev); 768 ps3_vuart_disable_interrupt_tx(dev);
679 } 769 }
680 770
681 if (status & INTERRUPT_MASK_RX) { 771 if (status & INTERRUPT_MASK_RX) {
682 dev->stats.rx_interrupts++; 772 dev->priv->stats.rx_interrupts++;
683 result = ps3_vuart_handle_interrupt_rx(dev); 773 result = ps3_vuart_handle_interrupt_rx(dev);
684 if (result) 774 if (result)
685 ps3_vuart_disable_interrupt_rx(dev); 775 ps3_vuart_disable_interrupt_rx(dev);
@@ -688,12 +778,13 @@ static int ps3_vuart_handle_port_interrupt(struct ps3_vuart_port_device *dev)
688 return 0; 778 return 0;
689} 779}
690 780
691struct vuart_private { 781struct vuart_bus_priv {
692 unsigned int in_use; 782 const struct ports_bmp bmp;
693 unsigned int virq; 783 unsigned int virq;
784 struct semaphore probe_mutex;
785 int use_count;
694 struct ps3_vuart_port_device *devices[PORT_COUNT]; 786 struct ps3_vuart_port_device *devices[PORT_COUNT];
695 const struct ports_bmp bmp; 787} static vuart_bus_priv;
696};
697 788
698/** 789/**
699 * ps3_vuart_irq_handler - first stage interrupt handler 790 * ps3_vuart_irq_handler - first stage interrupt handler
@@ -705,25 +796,25 @@ struct vuart_private {
705 796
706static irqreturn_t ps3_vuart_irq_handler(int irq, void *_private) 797static irqreturn_t ps3_vuart_irq_handler(int irq, void *_private)
707{ 798{
708 struct vuart_private *private; 799 struct vuart_bus_priv *bus_priv;
709 800
710 BUG_ON(!_private); 801 BUG_ON(!_private);
711 private = (struct vuart_private *)_private; 802 bus_priv = (struct vuart_bus_priv *)_private;
712 803
713 while (1) { 804 while (1) {
714 unsigned int port; 805 unsigned int port;
715 806
716 dump_ports_bmp(&private->bmp); 807 dump_ports_bmp(&bus_priv->bmp);
717 808
718 port = (BITS_PER_LONG - 1) - __ilog2(private->bmp.status); 809 port = (BITS_PER_LONG - 1) - __ilog2(bus_priv->bmp.status);
719 810
720 if (port == BITS_PER_LONG) 811 if (port == BITS_PER_LONG)
721 break; 812 break;
722 813
723 BUG_ON(port >= PORT_COUNT); 814 BUG_ON(port >= PORT_COUNT);
724 BUG_ON(!private->devices[port]); 815 BUG_ON(!bus_priv->devices[port]);
725 816
726 ps3_vuart_handle_port_interrupt(private->devices[port]); 817 ps3_vuart_handle_port_interrupt(bus_priv->devices[port]);
727 } 818 }
728 819
729 return IRQ_HANDLED; 820 return IRQ_HANDLED;
@@ -744,12 +835,10 @@ static int ps3_vuart_match(struct device *_dev, struct device_driver *_drv)
744 return result; 835 return result;
745} 836}
746 837
747static struct vuart_private vuart_private;
748
749static int ps3_vuart_probe(struct device *_dev) 838static int ps3_vuart_probe(struct device *_dev)
750{ 839{
751 int result; 840 int result;
752 unsigned long tmp; 841 unsigned int port_number;
753 struct ps3_vuart_port_device *dev = to_ps3_vuart_port_device(_dev); 842 struct ps3_vuart_port_device *dev = to_ps3_vuart_port_device(_dev);
754 struct ps3_vuart_port_driver *drv = 843 struct ps3_vuart_port_driver *drv =
755 to_ps3_vuart_port_driver(_dev->driver); 844 to_ps3_vuart_port_driver(_dev->driver);
@@ -758,7 +847,12 @@ static int ps3_vuart_probe(struct device *_dev)
758 847
759 BUG_ON(!drv); 848 BUG_ON(!drv);
760 849
761 result = ps3_vuart_match_id_to_port(dev->match_id, &dev->port_number); 850 down(&vuart_bus_priv.probe_mutex);
851
852 /* Setup vuart_bus_priv.devices[]. */
853
854 result = ps3_vuart_match_id_to_port(dev->match_id,
855 &port_number);
762 856
763 if (result) { 857 if (result) {
764 dev_dbg(&dev->core, "%s:%d: unknown match_id (%d)\n", 858 dev_dbg(&dev->core, "%s:%d: unknown match_id (%d)\n",
@@ -767,24 +861,41 @@ static int ps3_vuart_probe(struct device *_dev)
767 goto fail_match; 861 goto fail_match;
768 } 862 }
769 863
770 if (vuart_private.devices[dev->port_number]) { 864 if (vuart_bus_priv.devices[port_number]) {
771 dev_dbg(&dev->core, "%s:%d: port busy (%d)\n", __func__, 865 dev_dbg(&dev->core, "%s:%d: port busy (%d)\n", __func__,
772 __LINE__, dev->port_number); 866 __LINE__, port_number);
773 result = -EBUSY; 867 result = -EBUSY;
774 goto fail_match; 868 goto fail_match;
775 } 869 }
776 870
777 vuart_private.devices[dev->port_number] = dev; 871 vuart_bus_priv.devices[port_number] = dev;
872
873 /* Setup dev->priv. */
874
875 dev->priv = kzalloc(sizeof(struct ps3_vuart_port_priv), GFP_KERNEL);
876
877 if (!dev->priv) {
878 result = -ENOMEM;
879 goto fail_alloc;
880 }
778 881
779 INIT_LIST_HEAD(&dev->tx_list.head); 882 dev->priv->port_number = port_number;
780 spin_lock_init(&dev->tx_list.lock); 883
781 INIT_LIST_HEAD(&dev->rx_list.head); 884 INIT_LIST_HEAD(&dev->priv->tx_list.head);
782 spin_lock_init(&dev->rx_list.lock); 885 spin_lock_init(&dev->priv->tx_list.lock);
886
887 INIT_LIST_HEAD(&dev->priv->rx_list.head);
888 spin_lock_init(&dev->priv->rx_list.lock);
889
890 INIT_WORK(&dev->priv->work.work, NULL);
891 spin_lock_init(&dev->priv->work.lock);
892 dev->priv->work.trigger = 0;
893 dev->priv->work.dev = dev;
894
895 if (++vuart_bus_priv.use_count == 1) {
783 896
784 vuart_private.in_use++;
785 if (vuart_private.in_use == 1) {
786 result = ps3_alloc_vuart_irq(PS3_BINDING_CPU_ANY, 897 result = ps3_alloc_vuart_irq(PS3_BINDING_CPU_ANY,
787 (void*)&vuart_private.bmp.status, &vuart_private.virq); 898 (void*)&vuart_bus_priv.bmp.status, &vuart_bus_priv.virq);
788 899
789 if (result) { 900 if (result) {
790 dev_dbg(&dev->core, 901 dev_dbg(&dev->core,
@@ -794,8 +905,8 @@ static int ps3_vuart_probe(struct device *_dev)
794 goto fail_alloc_irq; 905 goto fail_alloc_irq;
795 } 906 }
796 907
797 result = request_irq(vuart_private.virq, ps3_vuart_irq_handler, 908 result = request_irq(vuart_bus_priv.virq, ps3_vuart_irq_handler,
798 IRQF_DISABLED, "vuart", &vuart_private); 909 IRQF_DISABLED, "vuart", &vuart_bus_priv);
799 910
800 if (result) { 911 if (result) {
801 dev_info(&dev->core, "%s:%d: request_irq failed (%d)\n", 912 dev_info(&dev->core, "%s:%d: request_irq failed (%d)\n",
@@ -804,10 +915,11 @@ static int ps3_vuart_probe(struct device *_dev)
804 } 915 }
805 } 916 }
806 917
807 ps3_vuart_set_interrupt_mask(dev, INTERRUPT_MASK_RX);
808
809 /* clear stale pending interrupts */ 918 /* clear stale pending interrupts */
810 ps3_vuart_get_interrupt_mask(dev, &tmp); 919
920 ps3_vuart_clear_rx_bytes(dev, 0);
921
922 ps3_vuart_set_interrupt_mask(dev, INTERRUPT_MASK_RX);
811 923
812 ps3_vuart_set_triggers(dev, 1, 1); 924 ps3_vuart_set_triggers(dev, 1, 1);
813 925
@@ -822,20 +934,27 @@ static int ps3_vuart_probe(struct device *_dev)
822 if (result) { 934 if (result) {
823 dev_dbg(&dev->core, "%s:%d: drv->probe failed\n", 935 dev_dbg(&dev->core, "%s:%d: drv->probe failed\n",
824 __func__, __LINE__); 936 __func__, __LINE__);
937 down(&vuart_bus_priv.probe_mutex);
825 goto fail_probe; 938 goto fail_probe;
826 } 939 }
827 940
941 up(&vuart_bus_priv.probe_mutex);
942
828 return result; 943 return result;
829 944
830fail_probe: 945fail_probe:
946 ps3_vuart_set_interrupt_mask(dev, 0);
831fail_request_irq: 947fail_request_irq:
832 vuart_private.in_use--; 948 ps3_free_vuart_irq(vuart_bus_priv.virq);
833 if (!vuart_private.in_use) { 949 vuart_bus_priv.virq = NO_IRQ;
834 ps3_free_vuart_irq(vuart_private.virq);
835 vuart_private.virq = NO_IRQ;
836 }
837fail_alloc_irq: 950fail_alloc_irq:
951 --vuart_bus_priv.use_count;
952 kfree(dev->priv);
953 dev->priv = NULL;
954fail_alloc:
955 vuart_bus_priv.devices[port_number] = 0;
838fail_match: 956fail_match:
957 up(&vuart_bus_priv.probe_mutex);
839 dev_dbg(&dev->core, "%s:%d failed\n", __func__, __LINE__); 958 dev_dbg(&dev->core, "%s:%d failed\n", __func__, __LINE__);
840 return result; 959 return result;
841} 960}
@@ -846,10 +965,12 @@ static int ps3_vuart_remove(struct device *_dev)
846 struct ps3_vuart_port_driver *drv = 965 struct ps3_vuart_port_driver *drv =
847 to_ps3_vuart_port_driver(_dev->driver); 966 to_ps3_vuart_port_driver(_dev->driver);
848 967
968 down(&vuart_bus_priv.probe_mutex);
969
849 dev_dbg(&dev->core, "%s:%d: %s\n", __func__, __LINE__, 970 dev_dbg(&dev->core, "%s:%d: %s\n", __func__, __LINE__,
850 dev->core.bus_id); 971 dev->core.bus_id);
851 972
852 BUG_ON(vuart_private.in_use < 1); 973 BUG_ON(vuart_bus_priv.use_count < 1);
853 974
854 if (drv->remove) 975 if (drv->remove)
855 drv->remove(dev); 976 drv->remove(dev);
@@ -857,13 +978,19 @@ static int ps3_vuart_remove(struct device *_dev)
857 dev_dbg(&dev->core, "%s:%d: %s no remove method\n", __func__, 978 dev_dbg(&dev->core, "%s:%d: %s no remove method\n", __func__,
858 __LINE__, dev->core.bus_id); 979 __LINE__, dev->core.bus_id);
859 980
860 vuart_private.in_use--; 981 vuart_bus_priv.devices[dev->priv->port_number] = 0;
861 982
862 if (!vuart_private.in_use) { 983 if (--vuart_bus_priv.use_count == 0) {
863 free_irq(vuart_private.virq, &vuart_private); 984 BUG();
864 ps3_free_vuart_irq(vuart_private.virq); 985 free_irq(vuart_bus_priv.virq, &vuart_bus_priv);
865 vuart_private.virq = NO_IRQ; 986 ps3_free_vuart_irq(vuart_bus_priv.virq);
987 vuart_bus_priv.virq = NO_IRQ;
866 } 988 }
989
990 kfree(dev->priv);
991 dev->priv = NULL;
992
993 up(&vuart_bus_priv.probe_mutex);
867 return 0; 994 return 0;
868} 995}
869 996
@@ -884,12 +1011,12 @@ static void ps3_vuart_shutdown(struct device *_dev)
884} 1011}
885 1012
886/** 1013/**
887 * ps3_vuart - The vuart instance. 1014 * ps3_vuart_bus - The vuart bus instance.
888 * 1015 *
889 * The vuart is managed as a bus that port devices connect to. 1016 * The vuart is managed as a bus that port devices connect to.
890 */ 1017 */
891 1018
892struct bus_type ps3_vuart = { 1019struct bus_type ps3_vuart_bus = {
893 .name = "ps3_vuart", 1020 .name = "ps3_vuart",
894 .match = ps3_vuart_match, 1021 .match = ps3_vuart_match,
895 .probe = ps3_vuart_probe, 1022 .probe = ps3_vuart_probe,
@@ -897,24 +1024,30 @@ struct bus_type ps3_vuart = {
897 .shutdown = ps3_vuart_shutdown, 1024 .shutdown = ps3_vuart_shutdown,
898}; 1025};
899 1026
900int __init ps3_vuart_init(void) 1027int __init ps3_vuart_bus_init(void)
901{ 1028{
902 int result; 1029 int result;
903 1030
904 pr_debug("%s:%d:\n", __func__, __LINE__); 1031 pr_debug("%s:%d:\n", __func__, __LINE__);
905 result = bus_register(&ps3_vuart); 1032
1033 if (!firmware_has_feature(FW_FEATURE_PS3_LV1))
1034 return 0;
1035
1036 init_MUTEX(&vuart_bus_priv.probe_mutex);
1037 result = bus_register(&ps3_vuart_bus);
906 BUG_ON(result); 1038 BUG_ON(result);
1039
907 return result; 1040 return result;
908} 1041}
909 1042
910void __exit ps3_vuart_exit(void) 1043void __exit ps3_vuart_bus_exit(void)
911{ 1044{
912 pr_debug("%s:%d:\n", __func__, __LINE__); 1045 pr_debug("%s:%d:\n", __func__, __LINE__);
913 bus_unregister(&ps3_vuart); 1046 bus_unregister(&ps3_vuart_bus);
914} 1047}
915 1048
916core_initcall(ps3_vuart_init); 1049core_initcall(ps3_vuart_bus_init);
917module_exit(ps3_vuart_exit); 1050module_exit(ps3_vuart_bus_exit);
918 1051
919/** 1052/**
920 * ps3_vuart_port_release_device - Remove a vuart port device. 1053 * ps3_vuart_port_release_device - Remove a vuart port device.
@@ -922,11 +1055,14 @@ module_exit(ps3_vuart_exit);
922 1055
923static void ps3_vuart_port_release_device(struct device *_dev) 1056static void ps3_vuart_port_release_device(struct device *_dev)
924{ 1057{
925 struct ps3_vuart_port_device *dev = to_ps3_vuart_port_device(_dev);
926#if defined(DEBUG) 1058#if defined(DEBUG)
927 memset(dev, 0xad, sizeof(struct ps3_vuart_port_device)); 1059 struct ps3_vuart_port_device *dev = to_ps3_vuart_port_device(_dev);
1060
1061 dev_dbg(&dev->core, "%s:%d\n", __func__, __LINE__);
1062
1063 BUG_ON(dev->priv && "forgot to free");
1064 memset(&dev->core, 0, sizeof(dev->core));
928#endif 1065#endif
929 kfree(dev);
930} 1066}
931 1067
932/** 1068/**
@@ -935,11 +1071,12 @@ static void ps3_vuart_port_release_device(struct device *_dev)
935 1071
936int ps3_vuart_port_device_register(struct ps3_vuart_port_device *dev) 1072int ps3_vuart_port_device_register(struct ps3_vuart_port_device *dev)
937{ 1073{
938 int result;
939 static unsigned int dev_count = 1; 1074 static unsigned int dev_count = 1;
940 1075
1076 BUG_ON(dev->priv && "forgot to free");
1077
941 dev->core.parent = NULL; 1078 dev->core.parent = NULL;
942 dev->core.bus = &ps3_vuart; 1079 dev->core.bus = &ps3_vuart_bus;
943 dev->core.release = ps3_vuart_port_release_device; 1080 dev->core.release = ps3_vuart_port_release_device;
944 1081
945 snprintf(dev->core.bus_id, sizeof(dev->core.bus_id), "vuart_%02x", 1082 snprintf(dev->core.bus_id, sizeof(dev->core.bus_id), "vuart_%02x",
@@ -947,9 +1084,7 @@ int ps3_vuart_port_device_register(struct ps3_vuart_port_device *dev)
947 1084
948 dev_dbg(&dev->core, "%s:%d register\n", __func__, __LINE__); 1085 dev_dbg(&dev->core, "%s:%d register\n", __func__, __LINE__);
949 1086
950 result = device_register(&dev->core); 1087 return device_register(&dev->core);
951
952 return result;
953} 1088}
954 1089
955EXPORT_SYMBOL_GPL(ps3_vuart_port_device_register); 1090EXPORT_SYMBOL_GPL(ps3_vuart_port_device_register);
@@ -963,7 +1098,7 @@ int ps3_vuart_port_driver_register(struct ps3_vuart_port_driver *drv)
963 int result; 1098 int result;
964 1099
965 pr_debug("%s:%d: (%s)\n", __func__, __LINE__, drv->core.name); 1100 pr_debug("%s:%d: (%s)\n", __func__, __LINE__, drv->core.name);
966 drv->core.bus = &ps3_vuart; 1101 drv->core.bus = &ps3_vuart_bus;
967 result = driver_register(&drv->core); 1102 result = driver_register(&drv->core);
968 return result; 1103 return result;
969} 1104}
@@ -976,6 +1111,7 @@ EXPORT_SYMBOL_GPL(ps3_vuart_port_driver_register);
976 1111
977void ps3_vuart_port_driver_unregister(struct ps3_vuart_port_driver *drv) 1112void ps3_vuart_port_driver_unregister(struct ps3_vuart_port_driver *drv)
978{ 1113{
1114 pr_debug("%s:%d: (%s)\n", __func__, __LINE__, drv->core.name);
979 driver_unregister(&drv->core); 1115 driver_unregister(&drv->core);
980} 1116}
981 1117
diff --git a/drivers/ps3/vuart.h b/drivers/ps3/vuart.h
index 2cbf728a3a0b..1be992d568c8 100644
--- a/drivers/ps3/vuart.h
+++ b/drivers/ps3/vuart.h
@@ -21,6 +21,44 @@
21#if !defined(_PS3_VUART_H) 21#if !defined(_PS3_VUART_H)
22#define _PS3_VUART_H 22#define _PS3_VUART_H
23 23
24#include <asm/ps3.h>
25
26struct ps3_vuart_stats {
27 unsigned long bytes_written;
28 unsigned long bytes_read;
29 unsigned long tx_interrupts;
30 unsigned long rx_interrupts;
31 unsigned long disconnect_interrupts;
32};
33
34struct ps3_vuart_work {
35 struct work_struct work;
36 unsigned long trigger;
37 spinlock_t lock;
38 struct ps3_vuart_port_device* dev; /* to convert work to device */
39};
40
41/**
42 * struct ps3_vuart_port_priv - private vuart device data.
43 */
44
45struct ps3_vuart_port_priv {
46 unsigned int port_number;
47 u64 interrupt_mask;
48
49 struct {
50 spinlock_t lock;
51 struct list_head head;
52 } tx_list;
53 struct {
54 unsigned long bytes_held;
55 spinlock_t lock;
56 struct list_head head;
57 } rx_list;
58 struct ps3_vuart_stats stats;
59 struct ps3_vuart_work work;
60};
61
24/** 62/**
25 * struct ps3_vuart_port_driver - a driver for a device on a vuart port 63 * struct ps3_vuart_port_driver - a driver for a device on a vuart port
26 */ 64 */
@@ -41,10 +79,6 @@ struct ps3_vuart_port_driver {
41int ps3_vuart_port_driver_register(struct ps3_vuart_port_driver *drv); 79int ps3_vuart_port_driver_register(struct ps3_vuart_port_driver *drv);
42void ps3_vuart_port_driver_unregister(struct ps3_vuart_port_driver *drv); 80void ps3_vuart_port_driver_unregister(struct ps3_vuart_port_driver *drv);
43 81
44int ps3_vuart_write(struct ps3_vuart_port_device *dev,
45 const void* buf, unsigned int bytes);
46int ps3_vuart_read(struct ps3_vuart_port_device *dev, void* buf,
47 unsigned int bytes);
48static inline struct ps3_vuart_port_driver *to_ps3_vuart_port_driver( 82static inline struct ps3_vuart_port_driver *to_ps3_vuart_port_driver(
49 struct device_driver *_drv) 83 struct device_driver *_drv)
50{ 84{
@@ -55,5 +89,22 @@ static inline struct ps3_vuart_port_device *to_ps3_vuart_port_device(
55{ 89{
56 return container_of(_dev, struct ps3_vuart_port_device, core); 90 return container_of(_dev, struct ps3_vuart_port_device, core);
57} 91}
92static inline struct ps3_vuart_port_device *ps3_vuart_work_to_port_device(
93 struct work_struct *_work)
94{
95 struct ps3_vuart_work *vw = container_of(_work, struct ps3_vuart_work,
96 work);
97 return vw->dev;
98}
99
100int ps3_vuart_write(struct ps3_vuart_port_device *dev, const void* buf,
101 unsigned int bytes);
102int ps3_vuart_read(struct ps3_vuart_port_device *dev, void* buf,
103 unsigned int bytes);
104int ps3_vuart_read_async(struct ps3_vuart_port_device *dev, work_func_t func,
105 unsigned int bytes);
106void ps3_vuart_cancel_async(struct ps3_vuart_port_device *dev);
107void ps3_vuart_clear_rx_bytes(struct ps3_vuart_port_device *dev,
108 unsigned int bytes);
58 109
59#endif 110#endif
diff --git a/drivers/sbus/char/vfc_i2c.c b/drivers/sbus/char/vfc_i2c.c
index ceec30648f4f..9efed771f6c0 100644
--- a/drivers/sbus/char/vfc_i2c.c
+++ b/drivers/sbus/char/vfc_i2c.c
@@ -14,7 +14,7 @@
14/* NOTE: It seems to me that the documentation regarding the 14/* NOTE: It seems to me that the documentation regarding the
15pcd8584t/pcf8584 does not show the correct way to address the i2c bus. 15pcd8584t/pcf8584 does not show the correct way to address the i2c bus.
16Based on the information on the I2C bus itself and the remainder of 16Based on the information on the I2C bus itself and the remainder of
17the Phillips docs the following algorithims apper to be correct. I am 17the Phillips docs the following algorithms appear to be correct. I am
18fairly certain that the flowcharts in the phillips docs are wrong. */ 18fairly certain that the flowcharts in the phillips docs are wrong. */
19 19
20 20
diff --git a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig
index 5bf3f07870ba..4cd280e86966 100644
--- a/drivers/scsi/Kconfig
+++ b/drivers/scsi/Kconfig
@@ -230,6 +230,7 @@ config SCSI_SCAN_ASYNC
230 The SCSI subsystem can probe for devices while the rest of the 230 The SCSI subsystem can probe for devices while the rest of the
231 system continues booting, and even probe devices on different 231 system continues booting, and even probe devices on different
232 busses in parallel, leading to a significant speed-up. 232 busses in parallel, leading to a significant speed-up.
233
233 If you have built SCSI as modules, enabling this option can 234 If you have built SCSI as modules, enabling this option can
234 be a problem as the devices may not have been found by the 235 be a problem as the devices may not have been found by the
235 time your system expects them to have been. You can load the 236 time your system expects them to have been. You can load the
@@ -237,8 +238,8 @@ config SCSI_SCAN_ASYNC
237 If you build your SCSI drivers into the kernel, then everything 238 If you build your SCSI drivers into the kernel, then everything
238 will work fine if you say Y here. 239 will work fine if you say Y here.
239 240
240 You can override this choice by specifying scsi_mod.scan="sync" 241 You can override this choice by specifying "scsi_mod.scan=sync"
241 or "async" on the kernel's command line. 242 or async on the kernel's command line.
242 243
243menu "SCSI Transports" 244menu "SCSI Transports"
244 depends on SCSI 245 depends on SCSI
diff --git a/drivers/scsi/a100u2w.c b/drivers/scsi/a100u2w.c
index 2650a5d0a161..7f4241bfb9c4 100644
--- a/drivers/scsi/a100u2w.c
+++ b/drivers/scsi/a100u2w.c
@@ -1067,7 +1067,7 @@ static int __devinit inia100_probe_one(struct pci_dev *pdev,
1067 goto out_disable_device; 1067 goto out_disable_device;
1068 } 1068 }
1069 1069
1070 /* <02> read from base address + 0x50 offset to get the bios balue. */ 1070 /* <02> read from base address + 0x50 offset to get the bios value. */
1071 bios = ORC_RDWORD(port, 0x50); 1071 bios = ORC_RDWORD(port, 0x50);
1072 1072
1073 1073
diff --git a/drivers/scsi/aic7xxx/aic79xx_osm.c b/drivers/scsi/aic7xxx/aic79xx_osm.c
index c7fe478f4813..2be03e975d97 100644
--- a/drivers/scsi/aic7xxx/aic79xx_osm.c
+++ b/drivers/scsi/aic7xxx/aic79xx_osm.c
@@ -418,7 +418,6 @@ ahd_linux_info(struct Scsi_Host *host)
418 strcat(bp, " "); 418 strcat(bp, " ");
419 ahd_controller_info(ahd, ahd_info); 419 ahd_controller_info(ahd, ahd_info);
420 strcat(bp, ahd_info); 420 strcat(bp, ahd_info);
421 strcat(bp, "\n");
422 421
423 return (bp); 422 return (bp);
424} 423}
diff --git a/drivers/scsi/aic94xx/aic94xx_seq.c b/drivers/scsi/aic94xx/aic94xx_seq.c
index eae7a247bece..c750fbf7013b 100644
--- a/drivers/scsi/aic94xx/aic94xx_seq.c
+++ b/drivers/scsi/aic94xx/aic94xx_seq.c
@@ -44,7 +44,6 @@
44#define PAUSE_TRIES 1000 44#define PAUSE_TRIES 1000
45 45
46static const struct firmware *sequencer_fw; 46static const struct firmware *sequencer_fw;
47static const char *sequencer_version;
48static u16 cseq_vecs[CSEQ_NUM_VECS], lseq_vecs[LSEQ_NUM_VECS], mode2_task, 47static u16 cseq_vecs[CSEQ_NUM_VECS], lseq_vecs[LSEQ_NUM_VECS], mode2_task,
49 cseq_idle_loop, lseq_idle_loop; 48 cseq_idle_loop, lseq_idle_loop;
50static u8 *cseq_code, *lseq_code; 49static u8 *cseq_code, *lseq_code;
@@ -1276,7 +1275,6 @@ static int asd_request_firmware(struct asd_ha_struct *asd_ha)
1276 header.csum = le32_to_cpu(hdr_ptr->csum); 1275 header.csum = le32_to_cpu(hdr_ptr->csum);
1277 header.major = le32_to_cpu(hdr_ptr->major); 1276 header.major = le32_to_cpu(hdr_ptr->major);
1278 header.minor = le32_to_cpu(hdr_ptr->minor); 1277 header.minor = le32_to_cpu(hdr_ptr->minor);
1279 sequencer_version = hdr_ptr->version;
1280 header.cseq_table_offset = le32_to_cpu(hdr_ptr->cseq_table_offset); 1278 header.cseq_table_offset = le32_to_cpu(hdr_ptr->cseq_table_offset);
1281 header.cseq_table_size = le32_to_cpu(hdr_ptr->cseq_table_size); 1279 header.cseq_table_size = le32_to_cpu(hdr_ptr->cseq_table_size);
1282 header.lseq_table_offset = le32_to_cpu(hdr_ptr->lseq_table_offset); 1280 header.lseq_table_offset = le32_to_cpu(hdr_ptr->lseq_table_offset);
@@ -1303,6 +1301,16 @@ static int asd_request_firmware(struct asd_ha_struct *asd_ha)
1303 return -EINVAL; 1301 return -EINVAL;
1304 } 1302 }
1305 1303
1304 asd_printk("Found sequencer Firmware version %d.%d (%s)\n",
1305 header.major, header.minor, hdr_ptr->version);
1306
1307 if (header.major != SAS_RAZOR_SEQUENCER_FW_MAJOR) {
1308 asd_printk("Firmware Major Version Mismatch;"
1309 "driver requires version %d.X",
1310 SAS_RAZOR_SEQUENCER_FW_MAJOR);
1311 return -EINVAL;
1312 }
1313
1306 ptr_cseq_vecs = (u16 *)&sequencer_fw->data[header.cseq_table_offset]; 1314 ptr_cseq_vecs = (u16 *)&sequencer_fw->data[header.cseq_table_offset];
1307 ptr_lseq_vecs = (u16 *)&sequencer_fw->data[header.lseq_table_offset]; 1315 ptr_lseq_vecs = (u16 *)&sequencer_fw->data[header.lseq_table_offset];
1308 mode2_task = header.mode2_task; 1316 mode2_task = header.mode2_task;
@@ -1335,7 +1343,6 @@ int asd_init_seqs(struct asd_ha_struct *asd_ha)
1335 return err; 1343 return err;
1336 } 1344 }
1337 1345
1338 asd_printk("using sequencer %s\n", sequencer_version);
1339 err = asd_seq_download_seqs(asd_ha); 1346 err = asd_seq_download_seqs(asd_ha);
1340 if (err) { 1347 if (err) {
1341 asd_printk("couldn't download sequencers for %s\n", 1348 asd_printk("couldn't download sequencers for %s\n",
diff --git a/drivers/scsi/aic94xx/aic94xx_seq.h b/drivers/scsi/aic94xx/aic94xx_seq.h
index 9437ff0ae3a4..2ea6a0d52208 100644
--- a/drivers/scsi/aic94xx/aic94xx_seq.h
+++ b/drivers/scsi/aic94xx/aic94xx_seq.h
@@ -31,6 +31,7 @@
31#define LSEQ_NUM_VECS 11 31#define LSEQ_NUM_VECS 11
32 32
33#define SAS_RAZOR_SEQUENCER_FW_FILE "aic94xx-seq.fw" 33#define SAS_RAZOR_SEQUENCER_FW_FILE "aic94xx-seq.fw"
34#define SAS_RAZOR_SEQUENCER_FW_MAJOR 1
34 35
35/* Note: All quantites in the sequencer file are little endian */ 36/* Note: All quantites in the sequencer file are little endian */
36struct sequencer_file_header { 37struct sequencer_file_header {
diff --git a/drivers/scsi/arm/eesox.c b/drivers/scsi/arm/eesox.c
index 4677152142d9..d4136524fc46 100644
--- a/drivers/scsi/arm/eesox.c
+++ b/drivers/scsi/arm/eesox.c
@@ -196,7 +196,7 @@ static void eesoxscsi_buffer_in(void *buf, int length, void __iomem *base)
196 const void __iomem *reg_fas = base + EESOX_FAS216_OFFSET; 196 const void __iomem *reg_fas = base + EESOX_FAS216_OFFSET;
197 const void __iomem *reg_dmastat = base + EESOX_DMASTAT; 197 const void __iomem *reg_dmastat = base + EESOX_DMASTAT;
198 const void __iomem *reg_dmadata = base + EESOX_DMADATA; 198 const void __iomem *reg_dmadata = base + EESOX_DMADATA;
199 const register unsigned long mask = 0xffff; 199 register const unsigned long mask = 0xffff;
200 200
201 do { 201 do {
202 unsigned int status; 202 unsigned int status;
diff --git a/drivers/scsi/ide-scsi.c b/drivers/scsi/ide-scsi.c
index 8f6b5bf580f6..2b5b8a93bc10 100644
--- a/drivers/scsi/ide-scsi.c
+++ b/drivers/scsi/ide-scsi.c
@@ -801,15 +801,10 @@ static int idescsi_ide_open(struct inode *inode, struct file *filp)
801{ 801{
802 struct gendisk *disk = inode->i_bdev->bd_disk; 802 struct gendisk *disk = inode->i_bdev->bd_disk;
803 struct ide_scsi_obj *scsi; 803 struct ide_scsi_obj *scsi;
804 ide_drive_t *drive;
805 804
806 if (!(scsi = ide_scsi_get(disk))) 805 if (!(scsi = ide_scsi_get(disk)))
807 return -ENXIO; 806 return -ENXIO;
808 807
809 drive = scsi->drive;
810
811 drive->usage++;
812
813 return 0; 808 return 0;
814} 809}
815 810
@@ -817,9 +812,6 @@ static int idescsi_ide_release(struct inode *inode, struct file *filp)
817{ 812{
818 struct gendisk *disk = inode->i_bdev->bd_disk; 813 struct gendisk *disk = inode->i_bdev->bd_disk;
819 struct ide_scsi_obj *scsi = ide_scsi_g(disk); 814 struct ide_scsi_obj *scsi = ide_scsi_g(disk);
820 ide_drive_t *drive = scsi->drive;
821
822 drive->usage--;
823 815
824 ide_scsi_put(scsi); 816 ide_scsi_put(scsi);
825 817
diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
index afca45cdbcef..9d014e5a81c4 100644
--- a/drivers/scsi/lpfc/lpfc_init.c
+++ b/drivers/scsi/lpfc/lpfc_init.c
@@ -518,6 +518,10 @@ lpfc_handle_eratt(struct lpfc_hba * phba)
518 struct lpfc_sli *psli = &phba->sli; 518 struct lpfc_sli *psli = &phba->sli;
519 struct lpfc_sli_ring *pring; 519 struct lpfc_sli_ring *pring;
520 uint32_t event_data; 520 uint32_t event_data;
521 /* If the pci channel is offline, ignore possible errors,
522 * since we cannot communicate with the pci card anyway. */
523 if (pci_channel_offline(phba->pcidev))
524 return;
521 525
522 if (phba->work_hs & HS_FFER6 || 526 if (phba->work_hs & HS_FFER6 ||
523 phba->work_hs & HS_FFER5) { 527 phba->work_hs & HS_FFER5) {
@@ -1797,6 +1801,92 @@ lpfc_pci_remove_one(struct pci_dev *pdev)
1797 pci_set_drvdata(pdev, NULL); 1801 pci_set_drvdata(pdev, NULL);
1798} 1802}
1799 1803
1804/**
1805 * lpfc_io_error_detected - called when PCI error is detected
1806 * @pdev: Pointer to PCI device
1807 * @state: The current pci conneection state
1808 *
1809 * This function is called after a PCI bus error affecting
1810 * this device has been detected.
1811 */
1812static pci_ers_result_t lpfc_io_error_detected(struct pci_dev *pdev,
1813 pci_channel_state_t state)
1814{
1815 struct Scsi_Host *host = pci_get_drvdata(pdev);
1816 struct lpfc_hba *phba = (struct lpfc_hba *)host->hostdata;
1817 struct lpfc_sli *psli = &phba->sli;
1818 struct lpfc_sli_ring *pring;
1819
1820 if (state == pci_channel_io_perm_failure) {
1821 lpfc_pci_remove_one(pdev);
1822 return PCI_ERS_RESULT_DISCONNECT;
1823 }
1824 pci_disable_device(pdev);
1825 /*
1826 * There may be I/Os dropped by the firmware.
1827 * Error iocb (I/O) on txcmplq and let the SCSI layer
1828 * retry it after re-establishing link.
1829 */
1830 pring = &psli->ring[psli->fcp_ring];
1831 lpfc_sli_abort_iocb_ring(phba, pring);
1832
1833 /* Request a slot reset. */
1834 return PCI_ERS_RESULT_NEED_RESET;
1835}
1836
1837/**
1838 * lpfc_io_slot_reset - called after the pci bus has been reset.
1839 * @pdev: Pointer to PCI device
1840 *
1841 * Restart the card from scratch, as if from a cold-boot.
1842 */
1843static pci_ers_result_t lpfc_io_slot_reset(struct pci_dev *pdev)
1844{
1845 struct Scsi_Host *host = pci_get_drvdata(pdev);
1846 struct lpfc_hba *phba = (struct lpfc_hba *)host->hostdata;
1847 struct lpfc_sli *psli = &phba->sli;
1848 int bars = pci_select_bars(pdev, IORESOURCE_MEM);
1849
1850 dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
1851 if (pci_enable_device_bars(pdev, bars)) {
1852 printk(KERN_ERR "lpfc: Cannot re-enable "
1853 "PCI device after reset.\n");
1854 return PCI_ERS_RESULT_DISCONNECT;
1855 }
1856
1857 pci_set_master(pdev);
1858
1859 /* Re-establishing Link */
1860 spin_lock_irq(phba->host->host_lock);
1861 phba->fc_flag |= FC_ESTABLISH_LINK;
1862 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
1863 spin_unlock_irq(phba->host->host_lock);
1864
1865
1866 /* Take device offline; this will perform cleanup */
1867 lpfc_offline(phba);
1868 lpfc_sli_brdrestart(phba);
1869
1870 return PCI_ERS_RESULT_RECOVERED;
1871}
1872
1873/**
1874 * lpfc_io_resume - called when traffic can start flowing again.
1875 * @pdev: Pointer to PCI device
1876 *
1877 * This callback is called when the error recovery driver tells us that
1878 * its OK to resume normal operation.
1879 */
1880static void lpfc_io_resume(struct pci_dev *pdev)
1881{
1882 struct Scsi_Host *host = pci_get_drvdata(pdev);
1883 struct lpfc_hba *phba = (struct lpfc_hba *)host->hostdata;
1884
1885 if (lpfc_online(phba) == 0) {
1886 mod_timer(&phba->fc_estabtmo, jiffies + HZ * 60);
1887 }
1888}
1889
1800static struct pci_device_id lpfc_id_table[] = { 1890static struct pci_device_id lpfc_id_table[] = {
1801 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER, 1891 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER,
1802 PCI_ANY_ID, PCI_ANY_ID, }, 1892 PCI_ANY_ID, PCI_ANY_ID, },
@@ -1857,11 +1947,18 @@ static struct pci_device_id lpfc_id_table[] = {
1857 1947
1858MODULE_DEVICE_TABLE(pci, lpfc_id_table); 1948MODULE_DEVICE_TABLE(pci, lpfc_id_table);
1859 1949
1950static struct pci_error_handlers lpfc_err_handler = {
1951 .error_detected = lpfc_io_error_detected,
1952 .slot_reset = lpfc_io_slot_reset,
1953 .resume = lpfc_io_resume,
1954};
1955
1860static struct pci_driver lpfc_driver = { 1956static struct pci_driver lpfc_driver = {
1861 .name = LPFC_DRIVER_NAME, 1957 .name = LPFC_DRIVER_NAME,
1862 .id_table = lpfc_id_table, 1958 .id_table = lpfc_id_table,
1863 .probe = lpfc_pci_probe_one, 1959 .probe = lpfc_pci_probe_one,
1864 .remove = __devexit_p(lpfc_pci_remove_one), 1960 .remove = __devexit_p(lpfc_pci_remove_one),
1961 .err_handler = &lpfc_err_handler,
1865}; 1962};
1866 1963
1867static int __init 1964static int __init
diff --git a/drivers/scsi/lpfc/lpfc_sli.c b/drivers/scsi/lpfc/lpfc_sli.c
index a4128e19338a..9fb6960a8ada 100644
--- a/drivers/scsi/lpfc/lpfc_sli.c
+++ b/drivers/scsi/lpfc/lpfc_sli.c
@@ -2104,6 +2104,10 @@ lpfc_sli_issue_mbox(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmbox, uint32_t flag)
2104 volatile uint32_t word0, ldata; 2104 volatile uint32_t word0, ldata;
2105 void __iomem *to_slim; 2105 void __iomem *to_slim;
2106 2106
2107 /* If the PCI channel is in offline state, do not post mbox. */
2108 if (unlikely(pci_channel_offline(phba->pcidev)))
2109 return MBX_NOT_FINISHED;
2110
2107 psli = &phba->sli; 2111 psli = &phba->sli;
2108 2112
2109 spin_lock_irqsave(phba->host->host_lock, drvr_flag); 2113 spin_lock_irqsave(phba->host->host_lock, drvr_flag);
@@ -2407,6 +2411,10 @@ lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2407 struct lpfc_iocbq *nextiocb; 2411 struct lpfc_iocbq *nextiocb;
2408 IOCB_t *iocb; 2412 IOCB_t *iocb;
2409 2413
2414 /* If the PCI channel is in offline state, do not post iocbs. */
2415 if (unlikely(pci_channel_offline(phba->pcidev)))
2416 return IOCB_ERROR;
2417
2410 /* 2418 /*
2411 * We should never get an IOCB if we are in a < LINK_DOWN state 2419 * We should never get an IOCB if we are in a < LINK_DOWN state
2412 */ 2420 */
@@ -3154,6 +3162,10 @@ lpfc_intr_handler(int irq, void *dev_id)
3154 if (unlikely(!phba)) 3162 if (unlikely(!phba))
3155 return IRQ_NONE; 3163 return IRQ_NONE;
3156 3164
3165 /* If the pci channel is offline, ignore all the interrupts. */
3166 if (unlikely(pci_channel_offline(phba->pcidev)))
3167 return IRQ_NONE;
3168
3157 phba->sli.slistat.sli_intr++; 3169 phba->sli.slistat.sli_intr++;
3158 3170
3159 /* 3171 /*
diff --git a/drivers/scsi/megaraid.c b/drivers/scsi/megaraid.c
index 808a1b8c4043..0aa3304f6b9b 100644
--- a/drivers/scsi/megaraid.c
+++ b/drivers/scsi/megaraid.c
@@ -5072,7 +5072,7 @@ static int __init megaraid_init(void)
5072 "megaraid: failed to create megaraid root\n"); 5072 "megaraid: failed to create megaraid root\n");
5073 } 5073 }
5074#endif 5074#endif
5075 error = pci_module_init(&megaraid_pci_driver); 5075 error = pci_register_driver(&megaraid_pci_driver);
5076 if (error) { 5076 if (error) {
5077#ifdef CONFIG_PROC_FS 5077#ifdef CONFIG_PROC_FS
5078 remove_proc_entry("megaraid", &proc_root); 5078 remove_proc_entry("megaraid", &proc_root);
diff --git a/drivers/scsi/megaraid/megaraid_sas.c b/drivers/scsi/megaraid/megaraid_sas.c
index 15e24fcc84f3..7a812677ff8a 100644
--- a/drivers/scsi/megaraid/megaraid_sas.c
+++ b/drivers/scsi/megaraid/megaraid_sas.c
@@ -10,11 +10,13 @@
10 * 2 of the License, or (at your option) any later version. 10 * 2 of the License, or (at your option) any later version.
11 * 11 *
12 * FILE : megaraid_sas.c 12 * FILE : megaraid_sas.c
13 * Version : v00.00.03.05 13 * Version : v00.00.03.10-rc1
14 * 14 *
15 * Authors: 15 * Authors:
16 * Sreenivas Bagalkote <Sreenivas.Bagalkote@lsi.com> 16 * (email-id : megaraidlinux@lsi.com)
17 * Sumant Patro <Sumant.Patro@lsi.com> 17 * Sreenivas Bagalkote
18 * Sumant Patro
19 * Bo Yang
18 * 20 *
19 * List of supported controllers 21 * List of supported controllers
20 * 22 *
@@ -35,6 +37,7 @@
35#include <asm/uaccess.h> 37#include <asm/uaccess.h>
36#include <linux/fs.h> 38#include <linux/fs.h>
37#include <linux/compat.h> 39#include <linux/compat.h>
40#include <linux/blkdev.h>
38#include <linux/mutex.h> 41#include <linux/mutex.h>
39 42
40#include <scsi/scsi.h> 43#include <scsi/scsi.h>
@@ -841,6 +844,11 @@ megasas_queue_command(struct scsi_cmnd *scmd, void (*done) (struct scsi_cmnd *))
841 844
842 instance = (struct megasas_instance *) 845 instance = (struct megasas_instance *)
843 scmd->device->host->hostdata; 846 scmd->device->host->hostdata;
847
848 /* Don't process if we have already declared adapter dead */
849 if (instance->hw_crit_error)
850 return SCSI_MLQUEUE_HOST_BUSY;
851
844 scmd->scsi_done = done; 852 scmd->scsi_done = done;
845 scmd->result = 0; 853 scmd->result = 0;
846 854
@@ -850,6 +858,18 @@ megasas_queue_command(struct scsi_cmnd *scmd, void (*done) (struct scsi_cmnd *))
850 goto out_done; 858 goto out_done;
851 } 859 }
852 860
861 switch (scmd->cmnd[0]) {
862 case SYNCHRONIZE_CACHE:
863 /*
864 * FW takes care of flush cache on its own
865 * No need to send it down
866 */
867 scmd->result = DID_OK << 16;
868 goto out_done;
869 default:
870 break;
871 }
872
853 cmd = megasas_get_cmd(instance); 873 cmd = megasas_get_cmd(instance);
854 if (!cmd) 874 if (!cmd)
855 return SCSI_MLQUEUE_HOST_BUSY; 875 return SCSI_MLQUEUE_HOST_BUSY;
@@ -1010,6 +1030,49 @@ static int megasas_reset_bus_host(struct scsi_cmnd *scmd)
1010} 1030}
1011 1031
1012/** 1032/**
1033 * megasas_bios_param - Returns disk geometry for a disk
1034 * @sdev: device handle
1035 * @bdev: block device
1036 * @capacity: drive capacity
1037 * @geom: geometry parameters
1038 */
1039static int
1040megasas_bios_param(struct scsi_device *sdev, struct block_device *bdev,
1041 sector_t capacity, int geom[])
1042{
1043 int heads;
1044 int sectors;
1045 sector_t cylinders;
1046 unsigned long tmp;
1047 /* Default heads (64) & sectors (32) */
1048 heads = 64;
1049 sectors = 32;
1050
1051 tmp = heads * sectors;
1052 cylinders = capacity;
1053
1054 sector_div(cylinders, tmp);
1055
1056 /*
1057 * Handle extended translation size for logical drives > 1Gb
1058 */
1059
1060 if (capacity >= 0x200000) {
1061 heads = 255;
1062 sectors = 63;
1063 tmp = heads*sectors;
1064 cylinders = capacity;
1065 sector_div(cylinders, tmp);
1066 }
1067
1068 geom[0] = heads;
1069 geom[1] = sectors;
1070 geom[2] = cylinders;
1071
1072 return 0;
1073}
1074
1075/**
1013 * megasas_service_aen - Processes an event notification 1076 * megasas_service_aen - Processes an event notification
1014 * @instance: Adapter soft state 1077 * @instance: Adapter soft state
1015 * @cmd: AEN command completed by the ISR 1078 * @cmd: AEN command completed by the ISR
@@ -1049,6 +1112,7 @@ static struct scsi_host_template megasas_template = {
1049 .eh_device_reset_handler = megasas_reset_device, 1112 .eh_device_reset_handler = megasas_reset_device,
1050 .eh_bus_reset_handler = megasas_reset_bus_host, 1113 .eh_bus_reset_handler = megasas_reset_bus_host,
1051 .eh_host_reset_handler = megasas_reset_bus_host, 1114 .eh_host_reset_handler = megasas_reset_bus_host,
1115 .bios_param = megasas_bios_param,
1052 .use_clustering = ENABLE_CLUSTERING, 1116 .use_clustering = ENABLE_CLUSTERING,
1053}; 1117};
1054 1118
@@ -1282,11 +1346,13 @@ megasas_deplete_reply_queue(struct megasas_instance *instance, u8 alt_status)
1282 if(instance->instancet->clear_intr(instance->reg_set)) 1346 if(instance->instancet->clear_intr(instance->reg_set))
1283 return IRQ_NONE; 1347 return IRQ_NONE;
1284 1348
1349 if (instance->hw_crit_error)
1350 goto out_done;
1285 /* 1351 /*
1286 * Schedule the tasklet for cmd completion 1352 * Schedule the tasklet for cmd completion
1287 */ 1353 */
1288 tasklet_schedule(&instance->isr_tasklet); 1354 tasklet_schedule(&instance->isr_tasklet);
1289 1355out_done:
1290 return IRQ_HANDLED; 1356 return IRQ_HANDLED;
1291} 1357}
1292 1358
@@ -1741,6 +1807,10 @@ static void megasas_complete_cmd_dpc(unsigned long instance_addr)
1741 struct megasas_cmd *cmd; 1807 struct megasas_cmd *cmd;
1742 struct megasas_instance *instance = (struct megasas_instance *)instance_addr; 1808 struct megasas_instance *instance = (struct megasas_instance *)instance_addr;
1743 1809
1810 /* If we have already declared adapter dead, donot complete cmds */
1811 if (instance->hw_crit_error)
1812 return;
1813
1744 producer = *instance->producer; 1814 producer = *instance->producer;
1745 consumer = *instance->consumer; 1815 consumer = *instance->consumer;
1746 1816
@@ -2655,9 +2725,9 @@ megasas_mgmt_fw_ioctl(struct megasas_instance *instance,
2655 * For each user buffer, create a mirror buffer and copy in 2725 * For each user buffer, create a mirror buffer and copy in
2656 */ 2726 */
2657 for (i = 0; i < ioc->sge_count; i++) { 2727 for (i = 0; i < ioc->sge_count; i++) {
2658 kbuff_arr[i] = pci_alloc_consistent(instance->pdev, 2728 kbuff_arr[i] = dma_alloc_coherent(&instance->pdev->dev,
2659 ioc->sgl[i].iov_len, 2729 ioc->sgl[i].iov_len,
2660 &buf_handle); 2730 &buf_handle, GFP_KERNEL);
2661 if (!kbuff_arr[i]) { 2731 if (!kbuff_arr[i]) {
2662 printk(KERN_DEBUG "megasas: Failed to alloc " 2732 printk(KERN_DEBUG "megasas: Failed to alloc "
2663 "kernel SGL buffer for IOCTL \n"); 2733 "kernel SGL buffer for IOCTL \n");
@@ -2684,8 +2754,8 @@ megasas_mgmt_fw_ioctl(struct megasas_instance *instance,
2684 } 2754 }
2685 2755
2686 if (ioc->sense_len) { 2756 if (ioc->sense_len) {
2687 sense = pci_alloc_consistent(instance->pdev, ioc->sense_len, 2757 sense = dma_alloc_coherent(&instance->pdev->dev, ioc->sense_len,
2688 &sense_handle); 2758 &sense_handle, GFP_KERNEL);
2689 if (!sense) { 2759 if (!sense) {
2690 error = -ENOMEM; 2760 error = -ENOMEM;
2691 goto out; 2761 goto out;
@@ -2744,12 +2814,12 @@ megasas_mgmt_fw_ioctl(struct megasas_instance *instance,
2744 2814
2745 out: 2815 out:
2746 if (sense) { 2816 if (sense) {
2747 pci_free_consistent(instance->pdev, ioc->sense_len, 2817 dma_free_coherent(&instance->pdev->dev, ioc->sense_len,
2748 sense, sense_handle); 2818 sense, sense_handle);
2749 } 2819 }
2750 2820
2751 for (i = 0; i < ioc->sge_count && kbuff_arr[i]; i++) { 2821 for (i = 0; i < ioc->sge_count && kbuff_arr[i]; i++) {
2752 pci_free_consistent(instance->pdev, 2822 dma_free_coherent(&instance->pdev->dev,
2753 kern_sge32[i].length, 2823 kern_sge32[i].length,
2754 kbuff_arr[i], kern_sge32[i].phys_addr); 2824 kbuff_arr[i], kern_sge32[i].phys_addr);
2755 } 2825 }
diff --git a/drivers/scsi/megaraid/megaraid_sas.h b/drivers/scsi/megaraid/megaraid_sas.h
index cacb3ad92527..e862992ee377 100644
--- a/drivers/scsi/megaraid/megaraid_sas.h
+++ b/drivers/scsi/megaraid/megaraid_sas.h
@@ -18,9 +18,9 @@
18/* 18/*
19 * MegaRAID SAS Driver meta data 19 * MegaRAID SAS Driver meta data
20 */ 20 */
21#define MEGASAS_VERSION "00.00.03.05" 21#define MEGASAS_VERSION "00.00.03.10-rc1"
22#define MEGASAS_RELDATE "Oct 02, 2006" 22#define MEGASAS_RELDATE "Feb 14, 2007"
23#define MEGASAS_EXT_VERSION "Mon Oct 02 11:21:32 PDT 2006" 23#define MEGASAS_EXT_VERSION "Wed Feb 14 10:14:25 PST 2007"
24 24
25/* 25/*
26 * Device IDs 26 * Device IDs
diff --git a/drivers/scsi/osst.c b/drivers/scsi/osst.c
index 9668b73872c7..a967fadb7439 100644
--- a/drivers/scsi/osst.c
+++ b/drivers/scsi/osst.c
@@ -5574,14 +5574,14 @@ static ssize_t osst_version_show(struct device_driver *ddd, char *buf)
5574 5574
5575static DRIVER_ATTR(version, S_IRUGO, osst_version_show, NULL); 5575static DRIVER_ATTR(version, S_IRUGO, osst_version_show, NULL);
5576 5576
5577static int osst_create_driverfs_files(struct device_driver *driverfs) 5577static int osst_create_sysfs_files(struct device_driver *sysfs)
5578{ 5578{
5579 return driver_create_file(driverfs, &driver_attr_version); 5579 return driver_create_file(sysfs, &driver_attr_version);
5580} 5580}
5581 5581
5582static void osst_remove_driverfs_files(struct device_driver *driverfs) 5582static void osst_remove_sysfs_files(struct device_driver *sysfs)
5583{ 5583{
5584 driver_remove_file(driverfs, &driver_attr_version); 5584 driver_remove_file(sysfs, &driver_attr_version);
5585} 5585}
5586 5586
5587/* 5587/*
@@ -5953,7 +5953,7 @@ static int __init init_osst(void)
5953 if (err) 5953 if (err)
5954 goto err_out_chrdev; 5954 goto err_out_chrdev;
5955 5955
5956 err = osst_create_driverfs_files(&osst_template.gendrv); 5956 err = osst_create_sysfs_files(&osst_template.gendrv);
5957 if (err) 5957 if (err)
5958 goto err_out_scsidrv; 5958 goto err_out_scsidrv;
5959 5959
@@ -5973,7 +5973,7 @@ static void __exit exit_osst (void)
5973 int i; 5973 int i;
5974 struct osst_tape * STp; 5974 struct osst_tape * STp;
5975 5975
5976 osst_remove_driverfs_files(&osst_template.gendrv); 5976 osst_remove_sysfs_files(&osst_template.gendrv);
5977 scsi_unregister_driver(&osst_template.gendrv); 5977 scsi_unregister_driver(&osst_template.gendrv);
5978 unregister_chrdev(OSST_MAJOR, "osst"); 5978 unregister_chrdev(OSST_MAJOR, "osst");
5979 osst_sysfs_cleanup(); 5979 osst_sysfs_cleanup();
diff --git a/drivers/scsi/scsi_proc.c b/drivers/scsi/scsi_proc.c
index 69d6e9b198c4..bb6f051beda8 100644
--- a/drivers/scsi/scsi_proc.c
+++ b/drivers/scsi/scsi_proc.c
@@ -179,9 +179,8 @@ static int proc_print_scsidevice(struct device *dev, void *data)
179 seq_printf(s, "\n"); 179 seq_printf(s, "\n");
180 180
181 seq_printf(s, " Type: %s ", scsi_device_type(sdev->type)); 181 seq_printf(s, " Type: %s ", scsi_device_type(sdev->type));
182 seq_printf(s, " ANSI" 182 seq_printf(s, " ANSI SCSI revision: %02x",
183 " SCSI revision: %02x", (sdev->scsi_level - 1) ? 183 sdev->scsi_level - (sdev->scsi_level > 1));
184 sdev->scsi_level - 1 : 1);
185 if (sdev->scsi_level == 2) 184 if (sdev->scsi_level == 2)
186 seq_printf(s, " CCS\n"); 185 seq_printf(s, " CCS\n");
187 else 186 else
diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c
index a43b9ec3aefd..0949145304ea 100644
--- a/drivers/scsi/scsi_scan.c
+++ b/drivers/scsi/scsi_scan.c
@@ -54,7 +54,7 @@
54#define SCSI_TIMEOUT (2*HZ) 54#define SCSI_TIMEOUT (2*HZ)
55 55
56/* 56/*
57 * Prefix values for the SCSI id's (stored in driverfs name field) 57 * Prefix values for the SCSI id's (stored in sysfs name field)
58 */ 58 */
59#define SCSI_UID_SER_NUM 'S' 59#define SCSI_UID_SER_NUM 'S'
60#define SCSI_UID_UNKNOWN 'Z' 60#define SCSI_UID_UNKNOWN 'Z'
@@ -385,6 +385,7 @@ static struct scsi_target *scsi_alloc_target(struct device *parent,
385 INIT_LIST_HEAD(&starget->siblings); 385 INIT_LIST_HEAD(&starget->siblings);
386 INIT_LIST_HEAD(&starget->devices); 386 INIT_LIST_HEAD(&starget->devices);
387 starget->state = STARGET_RUNNING; 387 starget->state = STARGET_RUNNING;
388 starget->scsi_level = SCSI_2;
388 retry: 389 retry:
389 spin_lock_irqsave(shost->host_lock, flags); 390 spin_lock_irqsave(shost->host_lock, flags);
390 391
@@ -654,6 +655,19 @@ static int scsi_probe_lun(struct scsi_device *sdev, unsigned char *inq_result,
654 * short INQUIRY), an abort here prevents any further use of the 655 * short INQUIRY), an abort here prevents any further use of the
655 * device, including spin up. 656 * device, including spin up.
656 * 657 *
658 * On the whole, the best approach seems to be to assume the first
659 * 36 bytes are valid no matter what the device says. That's
660 * better than copying < 36 bytes to the inquiry-result buffer
661 * and displaying garbage for the Vendor, Product, or Revision
662 * strings.
663 */
664 if (sdev->inquiry_len < 36) {
665 printk(KERN_INFO "scsi scan: INQUIRY result too short (%d),"
666 " using 36\n", sdev->inquiry_len);
667 sdev->inquiry_len = 36;
668 }
669
670 /*
657 * Related to the above issue: 671 * Related to the above issue:
658 * 672 *
659 * XXX Devices (disk or all?) should be sent a TEST UNIT READY, 673 * XXX Devices (disk or all?) should be sent a TEST UNIT READY,
diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
index 259c90cfa367..c275dcac3f18 100644
--- a/drivers/scsi/scsi_sysfs.c
+++ b/drivers/scsi/scsi_sysfs.c
@@ -922,7 +922,7 @@ void scsi_sysfs_device_initialize(struct scsi_device *sdev)
922 snprintf(sdev->sdev_classdev.class_id, BUS_ID_SIZE, 922 snprintf(sdev->sdev_classdev.class_id, BUS_ID_SIZE,
923 "%d:%d:%d:%d", sdev->host->host_no, 923 "%d:%d:%d:%d", sdev->host->host_no,
924 sdev->channel, sdev->id, sdev->lun); 924 sdev->channel, sdev->id, sdev->lun);
925 sdev->scsi_level = SCSI_2; 925 sdev->scsi_level = starget->scsi_level;
926 transport_setup_device(&sdev->sdev_gendev); 926 transport_setup_device(&sdev->sdev_gendev);
927 spin_lock_irqsave(shost->host_lock, flags); 927 spin_lock_irqsave(shost->host_lock, flags);
928 list_add_tail(&sdev->same_target_siblings, &starget->devices); 928 list_add_tail(&sdev->same_target_siblings, &starget->devices);
diff --git a/drivers/scsi/scsi_tgt_if.c b/drivers/scsi/scsi_tgt_if.c
index f2344ab8deff..0e08817fdecf 100644
--- a/drivers/scsi/scsi_tgt_if.c
+++ b/drivers/scsi/scsi_tgt_if.c
@@ -33,6 +33,14 @@
33 33
34#include "scsi_tgt_priv.h" 34#include "scsi_tgt_priv.h"
35 35
36#if TGT_RING_SIZE < PAGE_SIZE
37# define TGT_RING_SIZE PAGE_SIZE
38#endif
39
40#define TGT_RING_PAGES (TGT_RING_SIZE >> PAGE_SHIFT)
41#define TGT_EVENT_PER_PAGE (PAGE_SIZE / sizeof(struct tgt_event))
42#define TGT_MAX_EVENTS (TGT_EVENT_PER_PAGE * TGT_RING_PAGES)
43
36struct tgt_ring { 44struct tgt_ring {
37 u32 tr_idx; 45 u32 tr_idx;
38 unsigned long tr_pages[TGT_RING_PAGES]; 46 unsigned long tr_pages[TGT_RING_PAGES];
diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
index 0d3c10f2134c..58afdb401703 100644
--- a/drivers/scsi/scsi_transport_fc.c
+++ b/drivers/scsi/scsi_transport_fc.c
@@ -855,7 +855,7 @@ static FC_CLASS_DEVICE_ATTR(rport, fast_io_fail_tmo, S_IRUGO | S_IWUSR,
855 855
856/* 856/*
857 * Note: in the target show function we recognize when the remote 857 * Note: in the target show function we recognize when the remote
858 * port is in the heirarchy and do not allow the driver to get 858 * port is in the hierarchy and do not allow the driver to get
859 * involved in sysfs functions. The driver only gets involved if 859 * involved in sysfs functions. The driver only gets involved if
860 * it's the "old" style that doesn't use rports. 860 * it's the "old" style that doesn't use rports.
861 */ 861 */
diff --git a/drivers/scsi/scsi_transport_sas.c b/drivers/scsi/scsi_transport_sas.c
index 6d39150e205b..b2ef71a86292 100644
--- a/drivers/scsi/scsi_transport_sas.c
+++ b/drivers/scsi/scsi_transport_sas.c
@@ -500,7 +500,7 @@ struct sas_phy *sas_phy_alloc(struct device *parent, int number)
500EXPORT_SYMBOL(sas_phy_alloc); 500EXPORT_SYMBOL(sas_phy_alloc);
501 501
502/** 502/**
503 * sas_phy_add -- add a SAS PHY to the device hierachy 503 * sas_phy_add -- add a SAS PHY to the device hierarchy
504 * @phy: The PHY to be added 504 * @phy: The PHY to be added
505 * 505 *
506 * Publishes a SAS PHY to the rest of the system. 506 * Publishes a SAS PHY to the rest of the system.
@@ -1265,7 +1265,7 @@ struct sas_rphy *sas_expander_alloc(struct sas_port *parent,
1265EXPORT_SYMBOL(sas_expander_alloc); 1265EXPORT_SYMBOL(sas_expander_alloc);
1266 1266
1267/** 1267/**
1268 * sas_rphy_add -- add a SAS remote PHY to the device hierachy 1268 * sas_rphy_add -- add a SAS remote PHY to the device hierarchy
1269 * @rphy: The remote PHY to be added 1269 * @rphy: The remote PHY to be added
1270 * 1270 *
1271 * Publishes a SAS remote PHY to the rest of the system. 1271 * Publishes a SAS remote PHY to the rest of the system.
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 3f048bd6326d..5a8f55fea5ff 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -1269,9 +1269,18 @@ repeat:
1269 1269
1270 /* Some devices return the total number of sectors, not the 1270 /* Some devices return the total number of sectors, not the
1271 * highest sector number. Make the necessary adjustment. */ 1271 * highest sector number. Make the necessary adjustment. */
1272 if (sdp->fix_capacity) 1272 if (sdp->fix_capacity) {
1273 --sdkp->capacity; 1273 --sdkp->capacity;
1274 1274
1275 /* Some devices have version which report the correct sizes
1276 * and others which do not. We guess size according to a heuristic
1277 * and err on the side of lowering the capacity. */
1278 } else {
1279 if (sdp->guess_capacity)
1280 if (sdkp->capacity & 0x01) /* odd sizes are odd */
1281 --sdkp->capacity;
1282 }
1283
1275got_data: 1284got_data:
1276 if (sector_size == 0) { 1285 if (sector_size == 0) {
1277 sector_size = 512; 1286 sector_size = 512;
diff --git a/drivers/scsi/sgiwd93.c b/drivers/scsi/sgiwd93.c
index e81f97a35bc8..a15752b37990 100644
--- a/drivers/scsi/sgiwd93.c
+++ b/drivers/scsi/sgiwd93.c
@@ -244,9 +244,10 @@ static struct Scsi_Host * __init sgiwd93_setup_scsi(
244 regs.SASR = wdregs + 3; 244 regs.SASR = wdregs + 3;
245 regs.SCMD = wdregs + 7; 245 regs.SCMD = wdregs + 7;
246 246
247 wd33c93_init(host, regs, dma_setup, dma_stop, WD33C93_FS_16_20); 247 wd33c93_init(host, regs, dma_setup, dma_stop, WD33C93_FS_MHZ(20));
248 248
249 hdata->wh.no_sync = 0; 249 if (hdata->wh.no_sync == 0xff)
250 hdata->wh.no_sync = 0;
250 251
251 if (request_irq(irq, sgiwd93_intr, 0, "SGI WD93", (void *) host)) { 252 if (request_irq(irq, sgiwd93_intr, 0, "SGI WD93", (void *) host)) {
252 printk(KERN_WARNING "sgiwd93: Could not register irq %d " 253 printk(KERN_WARNING "sgiwd93: Could not register irq %d "
diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c
index 3d2e02381e92..98d8411bbccc 100644
--- a/drivers/scsi/st.c
+++ b/drivers/scsi/st.c
@@ -195,8 +195,8 @@ static int sgl_unmap_user_pages(struct scatterlist *, const unsigned int, int);
195static int st_probe(struct device *); 195static int st_probe(struct device *);
196static int st_remove(struct device *); 196static int st_remove(struct device *);
197 197
198static int do_create_driverfs_files(void); 198static int do_create_sysfs_files(void);
199static void do_remove_driverfs_files(void); 199static void do_remove_sysfs_files(void);
200static int do_create_class_files(struct scsi_tape *, int, int); 200static int do_create_class_files(struct scsi_tape *, int, int);
201 201
202static struct scsi_driver st_template = { 202static struct scsi_driver st_template = {
@@ -4193,7 +4193,7 @@ static int __init init_st(void)
4193 if (err) 4193 if (err)
4194 goto err_chrdev; 4194 goto err_chrdev;
4195 4195
4196 err = do_create_driverfs_files(); 4196 err = do_create_sysfs_files();
4197 if (err) 4197 if (err)
4198 goto err_scsidrv; 4198 goto err_scsidrv;
4199 4199
@@ -4211,7 +4211,7 @@ err_class:
4211 4211
4212static void __exit exit_st(void) 4212static void __exit exit_st(void)
4213{ 4213{
4214 do_remove_driverfs_files(); 4214 do_remove_sysfs_files();
4215 scsi_unregister_driver(&st_template.gendrv); 4215 scsi_unregister_driver(&st_template.gendrv);
4216 unregister_chrdev_region(MKDEV(SCSI_TAPE_MAJOR, 0), 4216 unregister_chrdev_region(MKDEV(SCSI_TAPE_MAJOR, 0),
4217 ST_MAX_TAPE_ENTRIES); 4217 ST_MAX_TAPE_ENTRIES);
@@ -4249,43 +4249,43 @@ static ssize_t st_version_show(struct device_driver *ddd, char *buf)
4249} 4249}
4250static DRIVER_ATTR(version, S_IRUGO, st_version_show, NULL); 4250static DRIVER_ATTR(version, S_IRUGO, st_version_show, NULL);
4251 4251
4252static int do_create_driverfs_files(void) 4252static int do_create_sysfs_files(void)
4253{ 4253{
4254 struct device_driver *driverfs = &st_template.gendrv; 4254 struct device_driver *sysfs = &st_template.gendrv;
4255 int err; 4255 int err;
4256 4256
4257 err = driver_create_file(driverfs, &driver_attr_try_direct_io); 4257 err = driver_create_file(sysfs, &driver_attr_try_direct_io);
4258 if (err) 4258 if (err)
4259 return err; 4259 return err;
4260 err = driver_create_file(driverfs, &driver_attr_fixed_buffer_size); 4260 err = driver_create_file(sysfs, &driver_attr_fixed_buffer_size);
4261 if (err) 4261 if (err)
4262 goto err_try_direct_io; 4262 goto err_try_direct_io;
4263 err = driver_create_file(driverfs, &driver_attr_max_sg_segs); 4263 err = driver_create_file(sysfs, &driver_attr_max_sg_segs);
4264 if (err) 4264 if (err)
4265 goto err_attr_fixed_buf; 4265 goto err_attr_fixed_buf;
4266 err = driver_create_file(driverfs, &driver_attr_version); 4266 err = driver_create_file(sysfs, &driver_attr_version);
4267 if (err) 4267 if (err)
4268 goto err_attr_max_sg; 4268 goto err_attr_max_sg;
4269 4269
4270 return 0; 4270 return 0;
4271 4271
4272err_attr_max_sg: 4272err_attr_max_sg:
4273 driver_remove_file(driverfs, &driver_attr_max_sg_segs); 4273 driver_remove_file(sysfs, &driver_attr_max_sg_segs);
4274err_attr_fixed_buf: 4274err_attr_fixed_buf:
4275 driver_remove_file(driverfs, &driver_attr_fixed_buffer_size); 4275 driver_remove_file(sysfs, &driver_attr_fixed_buffer_size);
4276err_try_direct_io: 4276err_try_direct_io:
4277 driver_remove_file(driverfs, &driver_attr_try_direct_io); 4277 driver_remove_file(sysfs, &driver_attr_try_direct_io);
4278 return err; 4278 return err;
4279} 4279}
4280 4280
4281static void do_remove_driverfs_files(void) 4281static void do_remove_sysfs_files(void)
4282{ 4282{
4283 struct device_driver *driverfs = &st_template.gendrv; 4283 struct device_driver *sysfs = &st_template.gendrv;
4284 4284
4285 driver_remove_file(driverfs, &driver_attr_version); 4285 driver_remove_file(sysfs, &driver_attr_version);
4286 driver_remove_file(driverfs, &driver_attr_max_sg_segs); 4286 driver_remove_file(sysfs, &driver_attr_max_sg_segs);
4287 driver_remove_file(driverfs, &driver_attr_fixed_buffer_size); 4287 driver_remove_file(sysfs, &driver_attr_fixed_buffer_size);
4288 driver_remove_file(driverfs, &driver_attr_try_direct_io); 4288 driver_remove_file(sysfs, &driver_attr_try_direct_io);
4289} 4289}
4290 4290
4291 4291
diff --git a/drivers/scsi/sym53c8xx_2/sym_fw1.h b/drivers/scsi/sym53c8xx_2/sym_fw1.h
index 7b39f4a35e98..7b08d6caaa99 100644
--- a/drivers/scsi/sym53c8xx_2/sym_fw1.h
+++ b/drivers/scsi/sym53c8xx_2/sym_fw1.h
@@ -1020,7 +1020,7 @@ static struct SYM_FWA_SCR SYM_FWA_SCR = {
1020 * It shall be a tagged command. 1020 * It shall be a tagged command.
1021 * Read SIMPLE+TAG. 1021 * Read SIMPLE+TAG.
1022 * The C code will deal with errors. 1022 * The C code will deal with errors.
1023 * Agressive optimization, is'nt it? :) 1023 * Aggressive optimization, isn't it? :)
1024 */ 1024 */
1025 SCR_MOVE_ABS (2) ^ SCR_MSG_IN, 1025 SCR_MOVE_ABS (2) ^ SCR_MSG_IN,
1026 HADDR_1 (msgin), 1026 HADDR_1 (msgin),
@@ -1044,7 +1044,7 @@ static struct SYM_FWA_SCR SYM_FWA_SCR = {
1044 RADDR_1 (dsa), 1044 RADDR_1 (dsa),
1045 /* 1045 /*
1046 * The SIDL still contains the TAG value. 1046 * The SIDL still contains the TAG value.
1047 * Agressive optimization, isn't it? :):) 1047 * Aggressive optimization, isn't it? :):)
1048 */ 1048 */
1049 SCR_REG_SFBR (sidl, SCR_SHL, 0), 1049 SCR_REG_SFBR (sidl, SCR_SHL, 0),
1050 0, 1050 0,
diff --git a/drivers/scsi/sym53c8xx_2/sym_fw2.h b/drivers/scsi/sym53c8xx_2/sym_fw2.h
index 851f2706f220..6e5b952312e3 100644
--- a/drivers/scsi/sym53c8xx_2/sym_fw2.h
+++ b/drivers/scsi/sym53c8xx_2/sym_fw2.h
@@ -956,7 +956,7 @@ static struct SYM_FWA_SCR SYM_FWA_SCR = {
956 * It shall be a tagged command. 956 * It shall be a tagged command.
957 * Read SIMPLE+TAG. 957 * Read SIMPLE+TAG.
958 * The C code will deal with errors. 958 * The C code will deal with errors.
959 * Agressive optimization, is'nt it? :) 959 * Aggressive optimization, isn't it? :)
960 */ 960 */
961 SCR_MOVE_ABS (2) ^ SCR_MSG_IN, 961 SCR_MOVE_ABS (2) ^ SCR_MSG_IN,
962 HADDR_1 (msgin), 962 HADDR_1 (msgin),
@@ -968,7 +968,7 @@ static struct SYM_FWA_SCR SYM_FWA_SCR = {
968 offsetof(struct sym_lcb, head.itlq_tbl_sa), 968 offsetof(struct sym_lcb, head.itlq_tbl_sa),
969 /* 969 /*
970 * The SIDL still contains the TAG value. 970 * The SIDL still contains the TAG value.
971 * Agressive optimization, isn't it? :):) 971 * Aggressive optimization, isn't it? :):)
972 */ 972 */
973 SCR_REG_SFBR (sidl, SCR_SHL, 0), 973 SCR_REG_SFBR (sidl, SCR_SHL, 0),
974 0, 974 0,
diff --git a/drivers/scsi/wd33c93.c b/drivers/scsi/wd33c93.c
index 835751600e93..fa4e08e508ad 100644
--- a/drivers/scsi/wd33c93.c
+++ b/drivers/scsi/wd33c93.c
@@ -69,6 +69,11 @@
69 * Added support for pre -A chips, which don't have advanced features 69 * Added support for pre -A chips, which don't have advanced features
70 * and will generate CSR_RESEL rather than CSR_RESEL_AM. 70 * and will generate CSR_RESEL rather than CSR_RESEL_AM.
71 * Richard Hirst <richard@sleepie.demon.co.uk> August 2000 71 * Richard Hirst <richard@sleepie.demon.co.uk> August 2000
72 *
73 * Added support for Burst Mode DMA and Fast SCSI. Enabled the use of
74 * default_sx_per for asynchronous data transfers. Added adjustment
75 * of transfer periods in sx_table to the actual input-clock.
76 * peter fuerst <post@pfrst.de> February 2007
72 */ 77 */
73 78
74#include <linux/module.h> 79#include <linux/module.h>
@@ -86,9 +91,11 @@
86 91
87#include "wd33c93.h" 92#include "wd33c93.h"
88 93
94#define optimum_sx_per(hostdata) (hostdata)->sx_table[1].period_ns
95
89 96
90#define WD33C93_VERSION "1.26" 97#define WD33C93_VERSION "1.26++"
91#define WD33C93_DATE "22/Feb/2003" 98#define WD33C93_DATE "10/Feb/2007"
92 99
93MODULE_AUTHOR("John Shifflett"); 100MODULE_AUTHOR("John Shifflett");
94MODULE_DESCRIPTION("Generic WD33C93 SCSI driver"); 101MODULE_DESCRIPTION("Generic WD33C93 SCSI driver");
@@ -122,6 +129,13 @@ MODULE_LICENSE("GPL");
122 * defines in wd33c93.h 129 * defines in wd33c93.h
123 * - clock:x -x = clock input in MHz for WD33c93 chip. Normal values 130 * - clock:x -x = clock input in MHz for WD33c93 chip. Normal values
124 * would be from 8 through 20. Default is 8. 131 * would be from 8 through 20. Default is 8.
132 * - burst:x -x = 1 to use Burst Mode (or Demand-Mode) DMA, x = 0 to use
133 * Single Byte DMA, which is the default. Argument is
134 * optional - if not present, same as "burst:1".
135 * - fast:x -x = 1 to enable Fast SCSI, which is only effective with
136 * input-clock divisor 4 (WD33C93_FS_16_20), x = 0 to disable
137 * it, which is the default. Argument is optional - if not
138 * present, same as "fast:1".
125 * - next -No argument. Used to separate blocks of keywords when 139 * - next -No argument. Used to separate blocks of keywords when
126 * there's more than one host adapter in the system. 140 * there's more than one host adapter in the system.
127 * 141 *
@@ -148,7 +162,7 @@ MODULE_LICENSE("GPL");
148 */ 162 */
149 163
150/* Normally, no defaults are specified */ 164/* Normally, no defaults are specified */
151static char *setup_args[] = { "", "", "", "", "", "", "", "", "" }; 165static char *setup_args[] = { "", "", "", "", "", "", "", "", "", "" };
152 166
153static char *setup_strings; 167static char *setup_strings;
154module_param(setup_strings, charp, 0); 168module_param(setup_strings, charp, 0);
@@ -298,20 +312,8 @@ read_1_byte(const wd33c93_regs regs)
298 return x; 312 return x;
299} 313}
300 314
301static struct sx_period sx_table[] = {
302 {1, 0x20},
303 {252, 0x20},
304 {376, 0x30},
305 {500, 0x40},
306 {624, 0x50},
307 {752, 0x60},
308 {876, 0x70},
309 {1000, 0x00},
310 {0, 0}
311};
312
313static int 315static int
314round_period(unsigned int period) 316round_period(unsigned int period, const struct sx_period *sx_table)
315{ 317{
316 int x; 318 int x;
317 319
@@ -324,17 +326,49 @@ round_period(unsigned int period)
324 return 7; 326 return 7;
325} 327}
326 328
329/*
330 * Calculate Synchronous Transfer Register value from SDTR code.
331 */
327static uchar 332static uchar
328calc_sync_xfer(unsigned int period, unsigned int offset) 333calc_sync_xfer(unsigned int period, unsigned int offset, unsigned int fast,
334 const struct sx_period *sx_table)
329{ 335{
336 /* When doing Fast SCSI synchronous data transfers, the corresponding
337 * value in 'sx_table' is two times the actually used transfer period.
338 */
330 uchar result; 339 uchar result;
331 340
341 if (offset && fast) {
342 fast = STR_FSS;
343 period *= 2;
344 } else {
345 fast = 0;
346 }
332 period *= 4; /* convert SDTR code to ns */ 347 period *= 4; /* convert SDTR code to ns */
333 result = sx_table[round_period(period)].reg_value; 348 result = sx_table[round_period(period,sx_table)].reg_value;
334 result |= (offset < OPTIMUM_SX_OFF) ? offset : OPTIMUM_SX_OFF; 349 result |= (offset < OPTIMUM_SX_OFF) ? offset : OPTIMUM_SX_OFF;
350 result |= fast;
335 return result; 351 return result;
336} 352}
337 353
354/*
355 * Calculate SDTR code bytes [3],[4] from period and offset.
356 */
357static inline void
358calc_sync_msg(unsigned int period, unsigned int offset, unsigned int fast,
359 uchar msg[2])
360{
361 /* 'period' is a "normal"-mode value, like the ones in 'sx_table'. The
362 * actually used transfer period for Fast SCSI synchronous data
363 * transfers is half that value.
364 */
365 period /= 4;
366 if (offset && fast)
367 period /= 2;
368 msg[0] = period;
369 msg[1] = offset;
370}
371
338int 372int
339wd33c93_queuecommand(struct scsi_cmnd *cmd, 373wd33c93_queuecommand(struct scsi_cmnd *cmd,
340 void (*done)(struct scsi_cmnd *)) 374 void (*done)(struct scsi_cmnd *))
@@ -632,7 +666,7 @@ wd33c93_execute(struct Scsi_Host *instance)
632 write_wd33c93_count(regs, 666 write_wd33c93_count(regs,
633 cmd->SCp.this_residual); 667 cmd->SCp.this_residual);
634 write_wd33c93(regs, WD_CONTROL, 668 write_wd33c93(regs, WD_CONTROL,
635 CTRL_IDI | CTRL_EDI | CTRL_DMA); 669 CTRL_IDI | CTRL_EDI | hostdata->dma_mode);
636 hostdata->dma = D_DMA_RUNNING; 670 hostdata->dma = D_DMA_RUNNING;
637 } 671 }
638 } else 672 } else
@@ -712,6 +746,8 @@ transfer_bytes(const wd33c93_regs regs, struct scsi_cmnd *cmd,
712 cmd->SCp.ptr = page_address(cmd->SCp.buffer->page) + 746 cmd->SCp.ptr = page_address(cmd->SCp.buffer->page) +
713 cmd->SCp.buffer->offset; 747 cmd->SCp.buffer->offset;
714 } 748 }
749 if (!cmd->SCp.this_residual) /* avoid bogus setups */
750 return;
715 751
716 write_wd33c93(regs, WD_SYNCHRONOUS_TRANSFER, 752 write_wd33c93(regs, WD_SYNCHRONOUS_TRANSFER,
717 hostdata->sync_xfer[cmd->device->id]); 753 hostdata->sync_xfer[cmd->device->id]);
@@ -744,7 +780,7 @@ transfer_bytes(const wd33c93_regs regs, struct scsi_cmnd *cmd,
744#ifdef PROC_STATISTICS 780#ifdef PROC_STATISTICS
745 hostdata->dma_cnt++; 781 hostdata->dma_cnt++;
746#endif 782#endif
747 write_wd33c93(regs, WD_CONTROL, CTRL_IDI | CTRL_EDI | CTRL_DMA); 783 write_wd33c93(regs, WD_CONTROL, CTRL_IDI | CTRL_EDI | hostdata->dma_mode);
748 write_wd33c93_count(regs, cmd->SCp.this_residual); 784 write_wd33c93_count(regs, cmd->SCp.this_residual);
749 785
750 if ((hostdata->level2 >= L2_DATA) || 786 if ((hostdata->level2 >= L2_DATA) ||
@@ -862,9 +898,6 @@ wd33c93_intr(struct Scsi_Host *instance)
862 hostdata->outgoing_msg[0] |= 0x40; 898 hostdata->outgoing_msg[0] |= 0x40;
863 899
864 if (hostdata->sync_stat[cmd->device->id] == SS_FIRST) { 900 if (hostdata->sync_stat[cmd->device->id] == SS_FIRST) {
865#ifdef SYNC_DEBUG
866 printk(" sending SDTR ");
867#endif
868 901
869 hostdata->sync_stat[cmd->device->id] = SS_WAITING; 902 hostdata->sync_stat[cmd->device->id] = SS_WAITING;
870 903
@@ -878,14 +911,20 @@ wd33c93_intr(struct Scsi_Host *instance)
878 hostdata->outgoing_msg[2] = 3; 911 hostdata->outgoing_msg[2] = 3;
879 hostdata->outgoing_msg[3] = EXTENDED_SDTR; 912 hostdata->outgoing_msg[3] = EXTENDED_SDTR;
880 if (hostdata->no_sync & (1 << cmd->device->id)) { 913 if (hostdata->no_sync & (1 << cmd->device->id)) {
881 hostdata->outgoing_msg[4] = 914 calc_sync_msg(hostdata->default_sx_per, 0,
882 hostdata->default_sx_per / 4; 915 0, hostdata->outgoing_msg + 4);
883 hostdata->outgoing_msg[5] = 0;
884 } else { 916 } else {
885 hostdata->outgoing_msg[4] = OPTIMUM_SX_PER / 4; 917 calc_sync_msg(optimum_sx_per(hostdata),
886 hostdata->outgoing_msg[5] = OPTIMUM_SX_OFF; 918 OPTIMUM_SX_OFF,
919 hostdata->fast,
920 hostdata->outgoing_msg + 4);
887 } 921 }
888 hostdata->outgoing_len = 6; 922 hostdata->outgoing_len = 6;
923#ifdef SYNC_DEBUG
924 ucp = hostdata->outgoing_msg + 1;
925 printk(" sending SDTR %02x03%02x%02x%02x ",
926 ucp[0], ucp[2], ucp[3], ucp[4]);
927#endif
889 } else 928 } else
890 hostdata->outgoing_len = 1; 929 hostdata->outgoing_len = 1;
891 930
@@ -1001,8 +1040,13 @@ wd33c93_intr(struct Scsi_Host *instance)
1001#ifdef SYNC_DEBUG 1040#ifdef SYNC_DEBUG
1002 printk("-REJ-"); 1041 printk("-REJ-");
1003#endif 1042#endif
1004 if (hostdata->sync_stat[cmd->device->id] == SS_WAITING) 1043 if (hostdata->sync_stat[cmd->device->id] == SS_WAITING) {
1005 hostdata->sync_stat[cmd->device->id] = SS_SET; 1044 hostdata->sync_stat[cmd->device->id] = SS_SET;
1045 /* we want default_sx_per, not DEFAULT_SX_PER */
1046 hostdata->sync_xfer[cmd->device->id] =
1047 calc_sync_xfer(hostdata->default_sx_per
1048 / 4, 0, 0, hostdata->sx_table);
1049 }
1006 write_wd33c93_cmd(regs, WD_CMD_NEGATE_ACK); 1050 write_wd33c93_cmd(regs, WD_CMD_NEGATE_ACK);
1007 hostdata->state = S_CONNECTED; 1051 hostdata->state = S_CONNECTED;
1008 break; 1052 break;
@@ -1022,7 +1066,10 @@ wd33c93_intr(struct Scsi_Host *instance)
1022 1066
1023 switch (ucp[2]) { /* what's the EXTENDED code? */ 1067 switch (ucp[2]) { /* what's the EXTENDED code? */
1024 case EXTENDED_SDTR: 1068 case EXTENDED_SDTR:
1025 id = calc_sync_xfer(ucp[3], ucp[4]); 1069 /* default to default async period */
1070 id = calc_sync_xfer(hostdata->
1071 default_sx_per / 4, 0,
1072 0, hostdata->sx_table);
1026 if (hostdata->sync_stat[cmd->device->id] != 1073 if (hostdata->sync_stat[cmd->device->id] !=
1027 SS_WAITING) { 1074 SS_WAITING) {
1028 1075
@@ -1041,20 +1088,22 @@ wd33c93_intr(struct Scsi_Host *instance)
1041 hostdata->outgoing_msg[1] = 3; 1088 hostdata->outgoing_msg[1] = 3;
1042 hostdata->outgoing_msg[2] = 1089 hostdata->outgoing_msg[2] =
1043 EXTENDED_SDTR; 1090 EXTENDED_SDTR;
1044 hostdata->outgoing_msg[3] = 1091 calc_sync_msg(hostdata->
1045 hostdata->default_sx_per / 1092 default_sx_per, 0,
1046 4; 1093 0, hostdata->outgoing_msg + 3);
1047 hostdata->outgoing_msg[4] = 0;
1048 hostdata->outgoing_len = 5; 1094 hostdata->outgoing_len = 5;
1049 hostdata->sync_xfer[cmd->device->id] =
1050 calc_sync_xfer(hostdata->
1051 default_sx_per
1052 / 4, 0);
1053 } else { 1095 } else {
1054 hostdata->sync_xfer[cmd->device->id] = id; 1096 if (ucp[4]) /* well, sync transfer */
1097 id = calc_sync_xfer(ucp[3], ucp[4],
1098 hostdata->fast,
1099 hostdata->sx_table);
1100 else if (ucp[3]) /* very unlikely... */
1101 id = calc_sync_xfer(ucp[3], ucp[4],
1102 0, hostdata->sx_table);
1055 } 1103 }
1104 hostdata->sync_xfer[cmd->device->id] = id;
1056#ifdef SYNC_DEBUG 1105#ifdef SYNC_DEBUG
1057 printk("sync_xfer=%02x", 1106 printk(" sync_xfer=%02x\n",
1058 hostdata->sync_xfer[cmd->device->id]); 1107 hostdata->sync_xfer[cmd->device->id]);
1059#endif 1108#endif
1060 hostdata->sync_stat[cmd->device->id] = 1109 hostdata->sync_stat[cmd->device->id] =
@@ -1486,7 +1535,7 @@ reset_wd33c93(struct Scsi_Host *instance)
1486 write_wd33c93(regs, WD_CONTROL, CTRL_IDI | CTRL_EDI | CTRL_POLLED); 1535 write_wd33c93(regs, WD_CONTROL, CTRL_IDI | CTRL_EDI | CTRL_POLLED);
1487 write_wd33c93(regs, WD_SYNCHRONOUS_TRANSFER, 1536 write_wd33c93(regs, WD_SYNCHRONOUS_TRANSFER,
1488 calc_sync_xfer(hostdata->default_sx_per / 4, 1537 calc_sync_xfer(hostdata->default_sx_per / 4,
1489 DEFAULT_SX_OFF)); 1538 DEFAULT_SX_OFF, 0, hostdata->sx_table));
1490 write_wd33c93(regs, WD_COMMAND, WD_CMD_RESET); 1539 write_wd33c93(regs, WD_COMMAND, WD_CMD_RESET);
1491 1540
1492 1541
@@ -1512,6 +1561,9 @@ reset_wd33c93(struct Scsi_Host *instance)
1512 } else 1561 } else
1513 hostdata->chip = C_UNKNOWN_CHIP; 1562 hostdata->chip = C_UNKNOWN_CHIP;
1514 1563
1564 if (hostdata->chip != C_WD33C93B) /* Fast SCSI unavailable */
1565 hostdata->fast = 0;
1566
1515 write_wd33c93(regs, WD_TIMEOUT_PERIOD, TIMEOUT_PERIOD_VALUE); 1567 write_wd33c93(regs, WD_TIMEOUT_PERIOD, TIMEOUT_PERIOD_VALUE);
1516 write_wd33c93(regs, WD_CONTROL, CTRL_IDI | CTRL_EDI | CTRL_POLLED); 1568 write_wd33c93(regs, WD_CONTROL, CTRL_IDI | CTRL_EDI | CTRL_POLLED);
1517} 1569}
@@ -1533,7 +1585,8 @@ wd33c93_host_reset(struct scsi_cmnd * SCpnt)
1533 for (i = 0; i < 8; i++) { 1585 for (i = 0; i < 8; i++) {
1534 hostdata->busy[i] = 0; 1586 hostdata->busy[i] = 0;
1535 hostdata->sync_xfer[i] = 1587 hostdata->sync_xfer[i] =
1536 calc_sync_xfer(DEFAULT_SX_PER / 4, DEFAULT_SX_OFF); 1588 calc_sync_xfer(DEFAULT_SX_PER / 4, DEFAULT_SX_OFF,
1589 0, hostdata->sx_table);
1537 hostdata->sync_stat[i] = SS_UNSET; /* using default sync values */ 1590 hostdata->sync_stat[i] = SS_UNSET; /* using default sync values */
1538 } 1591 }
1539 hostdata->input_Q = NULL; 1592 hostdata->input_Q = NULL;
@@ -1782,6 +1835,98 @@ check_setup_args(char *key, int *flags, int *val, char *buf)
1782 return ++x; 1835 return ++x;
1783} 1836}
1784 1837
1838/*
1839 * Calculate internal data-transfer-clock cycle from input-clock
1840 * frequency (/MHz) and fill 'sx_table'.
1841 *
1842 * The original driver used to rely on a fixed sx_table, containing periods
1843 * for (only) the lower limits of the respective input-clock-frequency ranges
1844 * (8-10/12-15/16-20 MHz). Although it seems, that no problems ocurred with
1845 * this setting so far, it might be desirable to adjust the transfer periods
1846 * closer to the really attached, possibly 25% higher, input-clock, since
1847 * - the wd33c93 may really use a significant shorter period, than it has
1848 * negotiated (eg. thrashing the target, which expects 4/8MHz, with 5/10MHz
1849 * instead).
1850 * - the wd33c93 may ask the target for a lower transfer rate, than the target
1851 * is capable of (eg. negotiating for an assumed minimum of 252ns instead of
1852 * possible 200ns, which indeed shows up in tests as an approx. 10% lower
1853 * transfer rate).
1854 */
1855static inline unsigned int
1856round_4(unsigned int x)
1857{
1858 switch (x & 3) {
1859 case 1: --x;
1860 break;
1861 case 2: ++x;
1862 case 3: ++x;
1863 }
1864 return x;
1865}
1866
1867static void
1868calc_sx_table(unsigned int mhz, struct sx_period sx_table[9])
1869{
1870 unsigned int d, i;
1871 if (mhz < 11)
1872 d = 2; /* divisor for 8-10 MHz input-clock */
1873 else if (mhz < 16)
1874 d = 3; /* divisor for 12-15 MHz input-clock */
1875 else
1876 d = 4; /* divisor for 16-20 MHz input-clock */
1877
1878 d = (100000 * d) / 2 / mhz; /* 100 x DTCC / nanosec */
1879
1880 sx_table[0].period_ns = 1;
1881 sx_table[0].reg_value = 0x20;
1882 for (i = 1; i < 8; i++) {
1883 sx_table[i].period_ns = round_4((i+1)*d / 100);
1884 sx_table[i].reg_value = (i+1)*0x10;
1885 }
1886 sx_table[7].reg_value = 0;
1887 sx_table[8].period_ns = 0;
1888 sx_table[8].reg_value = 0;
1889}
1890
1891/*
1892 * check and, maybe, map an init- or "clock:"- argument.
1893 */
1894static uchar
1895set_clk_freq(int freq, int *mhz)
1896{
1897 int x = freq;
1898 if (WD33C93_FS_8_10 == freq)
1899 freq = 8;
1900 else if (WD33C93_FS_12_15 == freq)
1901 freq = 12;
1902 else if (WD33C93_FS_16_20 == freq)
1903 freq = 16;
1904 else if (freq > 7 && freq < 11)
1905 x = WD33C93_FS_8_10;
1906 else if (freq > 11 && freq < 16)
1907 x = WD33C93_FS_12_15;
1908 else if (freq > 15 && freq < 21)
1909 x = WD33C93_FS_16_20;
1910 else {
1911 /* Hmm, wouldn't it be safer to assume highest freq here? */
1912 x = WD33C93_FS_8_10;
1913 freq = 8;
1914 }
1915 *mhz = freq;
1916 return x;
1917}
1918
1919/*
1920 * to be used with the resync: fast: ... options
1921 */
1922static inline void set_resync ( struct WD33C93_hostdata *hd, int mask )
1923{
1924 int i;
1925 for (i = 0; i < 8; i++)
1926 if (mask & (1 << i))
1927 hd->sync_stat[i] = SS_UNSET;
1928}
1929
1785void 1930void
1786wd33c93_init(struct Scsi_Host *instance, const wd33c93_regs regs, 1931wd33c93_init(struct Scsi_Host *instance, const wd33c93_regs regs,
1787 dma_setup_t setup, dma_stop_t stop, int clock_freq) 1932 dma_setup_t setup, dma_stop_t stop, int clock_freq)
@@ -1798,7 +1943,8 @@ wd33c93_init(struct Scsi_Host *instance, const wd33c93_regs regs,
1798 hostdata = (struct WD33C93_hostdata *) instance->hostdata; 1943 hostdata = (struct WD33C93_hostdata *) instance->hostdata;
1799 1944
1800 hostdata->regs = regs; 1945 hostdata->regs = regs;
1801 hostdata->clock_freq = clock_freq; 1946 hostdata->clock_freq = set_clk_freq(clock_freq, &i);
1947 calc_sx_table(i, hostdata->sx_table);
1802 hostdata->dma_setup = setup; 1948 hostdata->dma_setup = setup;
1803 hostdata->dma_stop = stop; 1949 hostdata->dma_stop = stop;
1804 hostdata->dma_bounce_buffer = NULL; 1950 hostdata->dma_bounce_buffer = NULL;
@@ -1806,7 +1952,8 @@ wd33c93_init(struct Scsi_Host *instance, const wd33c93_regs regs,
1806 for (i = 0; i < 8; i++) { 1952 for (i = 0; i < 8; i++) {
1807 hostdata->busy[i] = 0; 1953 hostdata->busy[i] = 0;
1808 hostdata->sync_xfer[i] = 1954 hostdata->sync_xfer[i] =
1809 calc_sync_xfer(DEFAULT_SX_PER / 4, DEFAULT_SX_OFF); 1955 calc_sync_xfer(DEFAULT_SX_PER / 4, DEFAULT_SX_OFF,
1956 0, hostdata->sx_table);
1810 hostdata->sync_stat[i] = SS_UNSET; /* using default sync values */ 1957 hostdata->sync_stat[i] = SS_UNSET; /* using default sync values */
1811#ifdef PROC_STATISTICS 1958#ifdef PROC_STATISTICS
1812 hostdata->cmd_cnt[i] = 0; 1959 hostdata->cmd_cnt[i] = 0;
@@ -1828,6 +1975,8 @@ wd33c93_init(struct Scsi_Host *instance, const wd33c93_regs regs,
1828 hostdata->default_sx_per = DEFAULT_SX_PER; 1975 hostdata->default_sx_per = DEFAULT_SX_PER;
1829 hostdata->no_sync = 0xff; /* sync defaults to off */ 1976 hostdata->no_sync = 0xff; /* sync defaults to off */
1830 hostdata->no_dma = 0; /* default is DMA enabled */ 1977 hostdata->no_dma = 0; /* default is DMA enabled */
1978 hostdata->fast = 0; /* default is Fast SCSI transfers disabled */
1979 hostdata->dma_mode = CTRL_DMA; /* default is Single Byte DMA */
1831 1980
1832#ifdef PROC_INTERFACE 1981#ifdef PROC_INTERFACE
1833 hostdata->proc = PR_VERSION | PR_INFO | PR_STATISTICS | 1982 hostdata->proc = PR_VERSION | PR_INFO | PR_STATISTICS |
@@ -1839,6 +1988,11 @@ wd33c93_init(struct Scsi_Host *instance, const wd33c93_regs regs,
1839#endif 1988#endif
1840#endif 1989#endif
1841 1990
1991 if (check_setup_args("clock", &flags, &val, buf)) {
1992 hostdata->clock_freq = set_clk_freq(val, &val);
1993 calc_sx_table(val, hostdata->sx_table);
1994 }
1995
1842 if (check_setup_args("nosync", &flags, &val, buf)) 1996 if (check_setup_args("nosync", &flags, &val, buf))
1843 hostdata->no_sync = val; 1997 hostdata->no_sync = val;
1844 1998
@@ -1847,7 +2001,8 @@ wd33c93_init(struct Scsi_Host *instance, const wd33c93_regs regs,
1847 2001
1848 if (check_setup_args("period", &flags, &val, buf)) 2002 if (check_setup_args("period", &flags, &val, buf))
1849 hostdata->default_sx_per = 2003 hostdata->default_sx_per =
1850 sx_table[round_period((unsigned int) val)].period_ns; 2004 hostdata->sx_table[round_period((unsigned int) val,
2005 hostdata->sx_table)].period_ns;
1851 2006
1852 if (check_setup_args("disconnect", &flags, &val, buf)) { 2007 if (check_setup_args("disconnect", &flags, &val, buf)) {
1853 if ((val >= DIS_NEVER) && (val <= DIS_ALWAYS)) 2008 if ((val >= DIS_NEVER) && (val <= DIS_ALWAYS))
@@ -1862,17 +2017,12 @@ wd33c93_init(struct Scsi_Host *instance, const wd33c93_regs regs,
1862 if (check_setup_args("debug", &flags, &val, buf)) 2017 if (check_setup_args("debug", &flags, &val, buf))
1863 hostdata->args = val & DB_MASK; 2018 hostdata->args = val & DB_MASK;
1864 2019
1865 if (check_setup_args("clock", &flags, &val, buf)) { 2020 if (check_setup_args("burst", &flags, &val, buf))
1866 if (val > 7 && val < 11) 2021 hostdata->dma_mode = val ? CTRL_BURST:CTRL_DMA;
1867 val = WD33C93_FS_8_10; 2022
1868 else if (val > 11 && val < 16) 2023 if (WD33C93_FS_16_20 == hostdata->clock_freq /* divisor 4 */
1869 val = WD33C93_FS_12_15; 2024 && check_setup_args("fast", &flags, &val, buf))
1870 else if (val > 15 && val < 21) 2025 hostdata->fast = !!val;
1871 val = WD33C93_FS_16_20;
1872 else
1873 val = WD33C93_FS_8_10;
1874 hostdata->clock_freq = val;
1875 }
1876 2026
1877 if ((i = check_setup_args("next", &flags, &val, buf))) { 2027 if ((i = check_setup_args("next", &flags, &val, buf))) {
1878 while (i) 2028 while (i)
@@ -1917,53 +2067,65 @@ wd33c93_proc_info(struct Scsi_Host *instance, char *buf, char **start, off_t off
1917 char tbuf[128]; 2067 char tbuf[128];
1918 struct WD33C93_hostdata *hd; 2068 struct WD33C93_hostdata *hd;
1919 struct scsi_cmnd *cmd; 2069 struct scsi_cmnd *cmd;
1920 int x, i; 2070 int x;
1921 static int stop = 0; 2071 static int stop = 0;
1922 2072
1923 hd = (struct WD33C93_hostdata *) instance->hostdata; 2073 hd = (struct WD33C93_hostdata *) instance->hostdata;
1924 2074
1925/* If 'in' is TRUE we need to _read_ the proc file. We accept the following 2075/* If 'in' is TRUE we need to _read_ the proc file. We accept the following
1926 * keywords (same format as command-line, but only ONE per read): 2076 * keywords (same format as command-line, but arguments are not optional):
1927 * debug 2077 * debug
1928 * disconnect 2078 * disconnect
1929 * period 2079 * period
1930 * resync 2080 * resync
1931 * proc 2081 * proc
1932 * nodma 2082 * nodma
2083 * level2
2084 * burst
2085 * fast
2086 * nosync
1933 */ 2087 */
1934 2088
1935 if (in) { 2089 if (in) {
1936 buf[len] = '\0'; 2090 buf[len] = '\0';
1937 bp = buf; 2091 for (bp = buf; *bp; ) {
2092 while (',' == *bp || ' ' == *bp)
2093 ++bp;
1938 if (!strncmp(bp, "debug:", 6)) { 2094 if (!strncmp(bp, "debug:", 6)) {
1939 bp += 6; 2095 hd->args = simple_strtoul(bp+6, &bp, 0) & DB_MASK;
1940 hd->args = simple_strtoul(bp, NULL, 0) & DB_MASK;
1941 } else if (!strncmp(bp, "disconnect:", 11)) { 2096 } else if (!strncmp(bp, "disconnect:", 11)) {
1942 bp += 11; 2097 x = simple_strtoul(bp+11, &bp, 0);
1943 x = simple_strtoul(bp, NULL, 0);
1944 if (x < DIS_NEVER || x > DIS_ALWAYS) 2098 if (x < DIS_NEVER || x > DIS_ALWAYS)
1945 x = DIS_ADAPTIVE; 2099 x = DIS_ADAPTIVE;
1946 hd->disconnect = x; 2100 hd->disconnect = x;
1947 } else if (!strncmp(bp, "period:", 7)) { 2101 } else if (!strncmp(bp, "period:", 7)) {
1948 bp += 7; 2102 x = simple_strtoul(bp+7, &bp, 0);
1949 x = simple_strtoul(bp, NULL, 0);
1950 hd->default_sx_per = 2103 hd->default_sx_per =
1951 sx_table[round_period((unsigned int) x)].period_ns; 2104 hd->sx_table[round_period((unsigned int) x,
2105 hd->sx_table)].period_ns;
1952 } else if (!strncmp(bp, "resync:", 7)) { 2106 } else if (!strncmp(bp, "resync:", 7)) {
1953 bp += 7; 2107 set_resync(hd, (int)simple_strtoul(bp+7, &bp, 0));
1954 x = simple_strtoul(bp, NULL, 0);
1955 for (i = 0; i < 7; i++)
1956 if (x & (1 << i))
1957 hd->sync_stat[i] = SS_UNSET;
1958 } else if (!strncmp(bp, "proc:", 5)) { 2108 } else if (!strncmp(bp, "proc:", 5)) {
1959 bp += 5; 2109 hd->proc = simple_strtoul(bp+5, &bp, 0);
1960 hd->proc = simple_strtoul(bp, NULL, 0);
1961 } else if (!strncmp(bp, "nodma:", 6)) { 2110 } else if (!strncmp(bp, "nodma:", 6)) {
1962 bp += 6; 2111 hd->no_dma = simple_strtoul(bp+6, &bp, 0);
1963 hd->no_dma = simple_strtoul(bp, NULL, 0);
1964 } else if (!strncmp(bp, "level2:", 7)) { 2112 } else if (!strncmp(bp, "level2:", 7)) {
1965 bp += 7; 2113 hd->level2 = simple_strtoul(bp+7, &bp, 0);
1966 hd->level2 = simple_strtoul(bp, NULL, 0); 2114 } else if (!strncmp(bp, "burst:", 6)) {
2115 hd->dma_mode =
2116 simple_strtol(bp+6, &bp, 0) ? CTRL_BURST:CTRL_DMA;
2117 } else if (!strncmp(bp, "fast:", 5)) {
2118 x = !!simple_strtol(bp+5, &bp, 0);
2119 if (x != hd->fast)
2120 set_resync(hd, 0xff);
2121 hd->fast = x;
2122 } else if (!strncmp(bp, "nosync:", 7)) {
2123 x = simple_strtoul(bp+7, &bp, 0);
2124 set_resync(hd, x ^ hd->no_sync);
2125 hd->no_sync = x;
2126 } else {
2127 break; /* unknown keyword,syntax-error,... */
2128 }
1967 } 2129 }
1968 return len; 2130 return len;
1969 } 2131 }
@@ -1977,8 +2139,9 @@ wd33c93_proc_info(struct Scsi_Host *instance, char *buf, char **start, off_t off
1977 strcat(bp, tbuf); 2139 strcat(bp, tbuf);
1978 } 2140 }
1979 if (hd->proc & PR_INFO) { 2141 if (hd->proc & PR_INFO) {
1980 sprintf(tbuf, "\nclock_freq=%02x no_sync=%02x no_dma=%d", 2142 sprintf(tbuf, "\nclock_freq=%02x no_sync=%02x no_dma=%d"
1981 hd->clock_freq, hd->no_sync, hd->no_dma); 2143 " dma_mode=%02x fast=%d",
2144 hd->clock_freq, hd->no_sync, hd->no_dma, hd->dma_mode, hd->fast);
1982 strcat(bp, tbuf); 2145 strcat(bp, tbuf);
1983 strcat(bp, "\nsync_xfer[] = "); 2146 strcat(bp, "\nsync_xfer[] = ");
1984 for (x = 0; x < 7; x++) { 2147 for (x = 0; x < 7; x++) {
diff --git a/drivers/scsi/wd33c93.h b/drivers/scsi/wd33c93.h
index edcb0365cf0c..61ffb860dacc 100644
--- a/drivers/scsi/wd33c93.h
+++ b/drivers/scsi/wd33c93.h
@@ -155,6 +155,9 @@
155#define WD33C93_FS_12_15 OWNID_FS_12 155#define WD33C93_FS_12_15 OWNID_FS_12
156#define WD33C93_FS_16_20 OWNID_FS_16 156#define WD33C93_FS_16_20 OWNID_FS_16
157 157
158 /* pass input-clock explicitely. accepted mhz values are 8-10,12-20 */
159#define WD33C93_FS_MHZ(mhz) (mhz)
160
158 /* Control register */ 161 /* Control register */
159#define CTRL_HSP 0x01 162#define CTRL_HSP 0x01
160#define CTRL_HA 0x02 163#define CTRL_HA 0x02
@@ -253,6 +256,9 @@ struct WD33C93_hostdata {
253 uchar sync_stat[8]; /* status of sync negotiation per target */ 256 uchar sync_stat[8]; /* status of sync negotiation per target */
254 uchar no_sync; /* bitmask: don't do sync on these targets */ 257 uchar no_sync; /* bitmask: don't do sync on these targets */
255 uchar no_dma; /* set this flag to disable DMA */ 258 uchar no_dma; /* set this flag to disable DMA */
259 uchar dma_mode; /* DMA Burst Mode or Single Byte DMA */
260 uchar fast; /* set this flag to enable Fast SCSI */
261 struct sx_period sx_table[9]; /* transfer periods for actual DTC-setting */
256#ifdef PROC_INTERFACE 262#ifdef PROC_INTERFACE
257 uchar proc; /* bitmask: what's in proc output */ 263 uchar proc; /* bitmask: what's in proc output */
258#ifdef PROC_STATISTICS 264#ifdef PROC_STATISTICS
diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig
index e8dd71df9165..ad9f321968e1 100644
--- a/drivers/serial/Kconfig
+++ b/drivers/serial/Kconfig
@@ -262,7 +262,8 @@ config SERIAL_AMBA_PL010
262 select SERIAL_CORE 262 select SERIAL_CORE
263 help 263 help
264 This selects the ARM(R) AMBA(R) PrimeCell PL010 UART. If you have 264 This selects the ARM(R) AMBA(R) PrimeCell PL010 UART. If you have
265 an Integrator/AP or Integrator/PP2 platform, say Y or M here. 265 an Integrator/AP or Integrator/PP2 platform, or if you have a
266 Cirrus Logic EP93xx CPU, say Y or M here.
266 267
267 If unsure, say N. 268 If unsure, say N.
268 269
diff --git a/drivers/serial/atmel_serial.c b/drivers/serial/atmel_serial.c
index df45a7ac773f..935f48fa501d 100644
--- a/drivers/serial/atmel_serial.c
+++ b/drivers/serial/atmel_serial.c
@@ -33,12 +33,13 @@
33#include <linux/sysrq.h> 33#include <linux/sysrq.h>
34#include <linux/tty_flip.h> 34#include <linux/tty_flip.h>
35#include <linux/platform_device.h> 35#include <linux/platform_device.h>
36#include <linux/atmel_pdc.h>
36 37
37#include <asm/io.h> 38#include <asm/io.h>
38 39
39#include <asm/mach/serial_at91.h> 40#include <asm/mach/serial_at91.h>
40#include <asm/arch/board.h> 41#include <asm/arch/board.h>
41#include <asm/arch/at91_pdc.h> 42
42#ifdef CONFIG_ARM 43#ifdef CONFIG_ARM
43#include <asm/arch/cpu.h> 44#include <asm/arch/cpu.h>
44#include <asm/arch/gpio.h> 45#include <asm/arch/gpio.h>
diff --git a/drivers/serial/cpm_uart/cpm_uart_cpm2.c b/drivers/serial/cpm_uart/cpm_uart_cpm2.c
index 787a8f134677..fa455996ad8f 100644
--- a/drivers/serial/cpm_uart/cpm_uart_cpm2.c
+++ b/drivers/serial/cpm_uart/cpm_uart_cpm2.c
@@ -285,7 +285,7 @@ void cpm_uart_freebuf(struct uart_cpm_port *pinfo)
285int __init cpm_uart_init_portdesc(void) 285int __init cpm_uart_init_portdesc(void)
286{ 286{
287#if defined(CONFIG_SERIAL_CPM_SMC1) || defined(CONFIG_SERIAL_CPM_SMC2) 287#if defined(CONFIG_SERIAL_CPM_SMC1) || defined(CONFIG_SERIAL_CPM_SMC2)
288 u32 addr; 288 u16 *addr;
289#endif 289#endif
290 pr_debug("CPM uart[-]:init portdesc\n"); 290 pr_debug("CPM uart[-]:init portdesc\n");
291 291
diff --git a/drivers/serial/imx.c b/drivers/serial/imx.c
index e216dcf29376..04cc88cc528c 100644
--- a/drivers/serial/imx.c
+++ b/drivers/serial/imx.c
@@ -154,7 +154,7 @@ static inline void imx_transmit_buffer(struct imx_port *sport)
154{ 154{
155 struct circ_buf *xmit = &sport->port.info->xmit; 155 struct circ_buf *xmit = &sport->port.info->xmit;
156 156
157 do { 157 while (!(UTS((u32)sport->port.membase) & UTS_TXFULL)) {
158 /* send xmit->buf[xmit->tail] 158 /* send xmit->buf[xmit->tail]
159 * out the port here */ 159 * out the port here */
160 URTX0((u32)sport->port.membase) = xmit->buf[xmit->tail]; 160 URTX0((u32)sport->port.membase) = xmit->buf[xmit->tail];
@@ -163,7 +163,7 @@ static inline void imx_transmit_buffer(struct imx_port *sport)
163 sport->port.icount.tx++; 163 sport->port.icount.tx++;
164 if (uart_circ_empty(xmit)) 164 if (uart_circ_empty(xmit))
165 break; 165 break;
166 } while (!(UTS((u32)sport->port.membase) & UTS_TXFULL)); 166 }
167 167
168 if (uart_circ_empty(xmit)) 168 if (uart_circ_empty(xmit))
169 imx_stop_tx(&sport->port); 169 imx_stop_tx(&sport->port);
@@ -178,8 +178,7 @@ static void imx_start_tx(struct uart_port *port)
178 178
179 UCR1((u32)sport->port.membase) |= UCR1_TXMPTYEN; 179 UCR1((u32)sport->port.membase) |= UCR1_TXMPTYEN;
180 180
181 if(UTS((u32)sport->port.membase) & UTS_TXEMPTY) 181 imx_transmit_buffer(sport);
182 imx_transmit_buffer(sport);
183} 182}
184 183
185static irqreturn_t imx_rtsint(int irq, void *dev_id) 184static irqreturn_t imx_rtsint(int irq, void *dev_id)
@@ -404,7 +403,8 @@ static int imx_startup(struct uart_port *port)
404 if (retval) goto error_out2; 403 if (retval) goto error_out2;
405 404
406 retval = request_irq(sport->rtsirq, imx_rtsint, 405 retval = request_irq(sport->rtsirq, imx_rtsint,
407 IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING, 406 (sport->rtsirq < IMX_IRQS) ? 0 :
407 IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
408 DRIVER_NAME, sport); 408 DRIVER_NAME, sport);
409 if (retval) goto error_out3; 409 if (retval) goto error_out3;
410 410
@@ -678,7 +678,7 @@ static struct imx_port imx_ports[] = {
678 .mapbase = IMX_UART1_BASE, /* FIXME */ 678 .mapbase = IMX_UART1_BASE, /* FIXME */
679 .irq = UART1_MINT_RX, 679 .irq = UART1_MINT_RX,
680 .uartclk = 16000000, 680 .uartclk = 16000000,
681 .fifosize = 8, 681 .fifosize = 32,
682 .flags = UPF_BOOT_AUTOCONF, 682 .flags = UPF_BOOT_AUTOCONF,
683 .ops = &imx_pops, 683 .ops = &imx_pops,
684 .line = 0, 684 .line = 0,
@@ -694,7 +694,7 @@ static struct imx_port imx_ports[] = {
694 .mapbase = IMX_UART2_BASE, /* FIXME */ 694 .mapbase = IMX_UART2_BASE, /* FIXME */
695 .irq = UART2_MINT_RX, 695 .irq = UART2_MINT_RX,
696 .uartclk = 16000000, 696 .uartclk = 16000000,
697 .fifosize = 8, 697 .fifosize = 32,
698 .flags = UPF_BOOT_AUTOCONF, 698 .flags = UPF_BOOT_AUTOCONF,
699 .ops = &imx_pops, 699 .ops = &imx_pops,
700 .line = 1, 700 .line = 1,
diff --git a/drivers/serial/mpc52xx_uart.c b/drivers/serial/mpc52xx_uart.c
index 955bbd653e22..8d24cd521056 100644
--- a/drivers/serial/mpc52xx_uart.c
+++ b/drivers/serial/mpc52xx_uart.c
@@ -995,8 +995,10 @@ mpc52xx_uart_of_remove(struct of_device *op)
995 struct uart_port *port = dev_get_drvdata(&op->dev); 995 struct uart_port *port = dev_get_drvdata(&op->dev);
996 dev_set_drvdata(&op->dev, NULL); 996 dev_set_drvdata(&op->dev, NULL);
997 997
998 if (port) 998 if (port) {
999 uart_remove_one_port(&mpc52xx_uart_driver, port); 999 uart_remove_one_port(&mpc52xx_uart_driver, port);
1000 irq_dispose_mapping(port->irq);
1001 }
1000 1002
1001 return 0; 1003 return 0;
1002} 1004}
diff --git a/drivers/serial/serial_cs.c b/drivers/serial/serial_cs.c
index c2f1012449da..6b76babc7fbf 100644
--- a/drivers/serial/serial_cs.c
+++ b/drivers/serial/serial_cs.c
@@ -248,6 +248,10 @@ static const struct serial_quirk quirks[] = {
248 .multi = 2, 248 .multi = 2,
249 }, { 249 }, {
250 .manfid = MANFID_QUATECH, 250 .manfid = MANFID_QUATECH,
251 .prodid = PRODID_QUATECH_DUAL_RS232_G,
252 .multi = 2,
253 }, {
254 .manfid = MANFID_QUATECH,
251 .prodid = PRODID_QUATECH_QUAD_RS232, 255 .prodid = PRODID_QUATECH_QUAD_RS232,
252 .multi = 4, 256 .multi = 4,
253 }, { 257 }, {
@@ -891,6 +895,7 @@ static struct pcmcia_device_id serial_ids[] = {
891 PCMCIA_DEVICE_PROD_ID12("OEM ", "C288MX ", 0xb572d360, 0xd2385b7a), 895 PCMCIA_DEVICE_PROD_ID12("OEM ", "C288MX ", 0xb572d360, 0xd2385b7a),
892 PCMCIA_DEVICE_PROD_ID12("PCMCIA ", "C336MX ", 0x99bcafe9, 0xaa25bcab), 896 PCMCIA_DEVICE_PROD_ID12("PCMCIA ", "C336MX ", 0x99bcafe9, 0xaa25bcab),
893 PCMCIA_DEVICE_PROD_ID12("Quatech Inc", "PCMCIA Dual RS-232 Serial Port Card", 0xc4420b35, 0x92abc92f), 897 PCMCIA_DEVICE_PROD_ID12("Quatech Inc", "PCMCIA Dual RS-232 Serial Port Card", 0xc4420b35, 0x92abc92f),
898 PCMCIA_DEVICE_PROD_ID12("Quatech Inc", "Dual RS-232 Serial Port PC Card", 0xc4420b35, 0x031a380d),
894 PCMCIA_PFC_DEVICE_CIS_PROD_ID12(1, "PCMCIA", "EN2218-LAN/MODEM", 0x281f1c5d, 0x570f348e, "PCMLM28.cis"), 899 PCMCIA_PFC_DEVICE_CIS_PROD_ID12(1, "PCMCIA", "EN2218-LAN/MODEM", 0x281f1c5d, 0x570f348e, "PCMLM28.cis"),
895 PCMCIA_PFC_DEVICE_CIS_PROD_ID12(1, "PCMCIA", "UE2218-LAN/MODEM", 0x281f1c5d, 0x6fdcacee, "PCMLM28.cis"), 900 PCMCIA_PFC_DEVICE_CIS_PROD_ID12(1, "PCMCIA", "UE2218-LAN/MODEM", 0x281f1c5d, 0x6fdcacee, "PCMLM28.cis"),
896 PCMCIA_PFC_DEVICE_CIS_PROD_ID12(1, "Psion Dacom", "Gold Card V34 Ethernet", 0xf5f025c2, 0x338e8155, "PCMLM28.cis"), 901 PCMCIA_PFC_DEVICE_CIS_PROD_ID12(1, "Psion Dacom", "Gold Card V34 Ethernet", 0xf5f025c2, 0x338e8155, "PCMLM28.cis"),
diff --git a/drivers/usb/Makefile b/drivers/usb/Makefile
index 825bf884537a..8b7ff467d262 100644
--- a/drivers/usb/Makefile
+++ b/drivers/usb/Makefile
@@ -51,6 +51,7 @@ obj-$(CONFIG_USB_SERIAL) += serial/
51obj-$(CONFIG_USB_ADUTUX) += misc/ 51obj-$(CONFIG_USB_ADUTUX) += misc/
52obj-$(CONFIG_USB_APPLEDISPLAY) += misc/ 52obj-$(CONFIG_USB_APPLEDISPLAY) += misc/
53obj-$(CONFIG_USB_AUERSWALD) += misc/ 53obj-$(CONFIG_USB_AUERSWALD) += misc/
54obj-$(CONFIG_USB_BERRY_CHARGE) += misc/
54obj-$(CONFIG_USB_CYPRESS_CY7C63)+= misc/ 55obj-$(CONFIG_USB_CYPRESS_CY7C63)+= misc/
55obj-$(CONFIG_USB_CYTHERM) += misc/ 56obj-$(CONFIG_USB_CYTHERM) += misc/
56obj-$(CONFIG_USB_EMI26) += misc/ 57obj-$(CONFIG_USB_EMI26) += misc/
diff --git a/drivers/usb/atm/ueagle-atm.c b/drivers/usb/atm/ueagle-atm.c
index dae4ef1e8fe5..4973e147bc79 100644
--- a/drivers/usb/atm/ueagle-atm.c
+++ b/drivers/usb/atm/ueagle-atm.c
@@ -61,6 +61,7 @@
61#include <linux/usb.h> 61#include <linux/usb.h>
62#include <linux/firmware.h> 62#include <linux/firmware.h>
63#include <linux/ctype.h> 63#include <linux/ctype.h>
64#include <linux/sched.h>
64#include <linux/kthread.h> 65#include <linux/kthread.h>
65#include <linux/version.h> 66#include <linux/version.h>
66#include <linux/mutex.h> 67#include <linux/mutex.h>
diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
index 98199628e394..d38a25f36ea5 100644
--- a/drivers/usb/class/cdc-acm.c
+++ b/drivers/usb/class/cdc-acm.c
@@ -326,10 +326,16 @@ static void acm_rx_tasklet(unsigned long _acm)
326 struct tty_struct *tty = acm->tty; 326 struct tty_struct *tty = acm->tty;
327 struct acm_ru *rcv; 327 struct acm_ru *rcv;
328 unsigned long flags; 328 unsigned long flags;
329 int i = 0; 329 unsigned char throttled;
330 dbg("Entering acm_rx_tasklet"); 330 dbg("Entering acm_rx_tasklet");
331 331
332 if (!ACM_READY(acm) || acm->throttle) 332 if (!ACM_READY(acm))
333 return;
334
335 spin_lock(&acm->throttle_lock);
336 throttled = acm->throttle;
337 spin_unlock(&acm->throttle_lock);
338 if (throttled)
333 return; 339 return;
334 340
335next_buffer: 341next_buffer:
@@ -346,22 +352,20 @@ next_buffer:
346 dbg("acm_rx_tasklet: procesing buf 0x%p, size = %d", buf, buf->size); 352 dbg("acm_rx_tasklet: procesing buf 0x%p, size = %d", buf, buf->size);
347 353
348 tty_buffer_request_room(tty, buf->size); 354 tty_buffer_request_room(tty, buf->size);
349 if (!acm->throttle) 355 spin_lock(&acm->throttle_lock);
356 throttled = acm->throttle;
357 spin_unlock(&acm->throttle_lock);
358 if (!throttled)
350 tty_insert_flip_string(tty, buf->base, buf->size); 359 tty_insert_flip_string(tty, buf->base, buf->size);
351 tty_flip_buffer_push(tty); 360 tty_flip_buffer_push(tty);
352 361
353 spin_lock(&acm->throttle_lock); 362 if (throttled) {
354 if (acm->throttle) { 363 dbg("Throttling noticed");
355 dbg("Throtteling noticed");
356 memmove(buf->base, buf->base + i, buf->size - i);
357 buf->size -= i;
358 spin_unlock(&acm->throttle_lock);
359 spin_lock_irqsave(&acm->read_lock, flags); 364 spin_lock_irqsave(&acm->read_lock, flags);
360 list_add(&buf->list, &acm->filled_read_bufs); 365 list_add(&buf->list, &acm->filled_read_bufs);
361 spin_unlock_irqrestore(&acm->read_lock, flags); 366 spin_unlock_irqrestore(&acm->read_lock, flags);
362 return; 367 return;
363 } 368 }
364 spin_unlock(&acm->throttle_lock);
365 369
366 spin_lock_irqsave(&acm->read_lock, flags); 370 spin_lock_irqsave(&acm->read_lock, flags);
367 list_add(&buf->list, &acm->spare_read_bufs); 371 list_add(&buf->list, &acm->spare_read_bufs);
@@ -467,7 +471,8 @@ static int acm_tty_open(struct tty_struct *tty, struct file *filp)
467 goto bail_out; 471 goto bail_out;
468 } 472 }
469 473
470 if (0 > acm_set_control(acm, acm->ctrlout = ACM_CTRL_DTR | ACM_CTRL_RTS)) 474 if (0 > acm_set_control(acm, acm->ctrlout = ACM_CTRL_DTR | ACM_CTRL_RTS) &&
475 (acm->ctrl_caps & USB_CDC_CAP_LINE))
471 goto full_bailout; 476 goto full_bailout;
472 477
473 INIT_LIST_HEAD(&acm->spare_read_urbs); 478 INIT_LIST_HEAD(&acm->spare_read_urbs);
@@ -480,6 +485,8 @@ static int acm_tty_open(struct tty_struct *tty, struct file *filp)
480 list_add(&(acm->rb[i].list), &acm->spare_read_bufs); 485 list_add(&(acm->rb[i].list), &acm->spare_read_bufs);
481 } 486 }
482 487
488 acm->throttle = 0;
489
483 tasklet_schedule(&acm->urb_task); 490 tasklet_schedule(&acm->urb_task);
484 491
485done: 492done:
@@ -1092,6 +1099,10 @@ static struct usb_device_id acm_ids[] = {
1092 { USB_DEVICE(0x0ace, 0x1611), /* ZyDAS 56K USB MODEM - new version */ 1099 { USB_DEVICE(0x0ace, 0x1611), /* ZyDAS 56K USB MODEM - new version */
1093 .driver_info = SINGLE_RX_URB, /* firmware bug */ 1100 .driver_info = SINGLE_RX_URB, /* firmware bug */
1094 }, 1101 },
1102 { USB_DEVICE(0x22b8, 0x7000), /* Motorola Q Phone */
1103 .driver_info = NO_UNION_NORMAL, /* has no union descriptor */
1104 },
1105
1095 /* control interfaces with various AT-command sets */ 1106 /* control interfaces with various AT-command sets */
1096 { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, 1107 { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM,
1097 USB_CDC_ACM_PROTO_AT_V25TER) }, 1108 USB_CDC_ACM_PROTO_AT_V25TER) },
diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
index a47c30b2d764..aefc7987120d 100644
--- a/drivers/usb/core/devices.c
+++ b/drivers/usb/core/devices.c
@@ -604,10 +604,6 @@ static unsigned int usb_device_poll(struct file *file, struct poll_table_struct
604 lock_kernel(); 604 lock_kernel();
605 if (!st) { 605 if (!st) {
606 st = kmalloc(sizeof(struct usb_device_status), GFP_KERNEL); 606 st = kmalloc(sizeof(struct usb_device_status), GFP_KERNEL);
607 if (!st) {
608 unlock_kernel();
609 return POLLIN;
610 }
611 607
612 /* we may have dropped BKL - need to check for having lost the race */ 608 /* we may have dropped BKL - need to check for having lost the race */
613 if (file->private_data) { 609 if (file->private_data) {
@@ -615,6 +611,11 @@ static unsigned int usb_device_poll(struct file *file, struct poll_table_struct
615 st = file->private_data; 611 st = file->private_data;
616 goto lost_race; 612 goto lost_race;
617 } 613 }
614 /* we haven't lost - check for allocation failure now */
615 if (!st) {
616 unlock_kernel();
617 return POLLIN;
618 }
618 619
619 /* 620 /*
620 * need to prevent the module from being unloaded, since 621 * need to prevent the module from being unloaded, since
diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index 2087766f9e88..274f14f1633e 100644
--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -857,11 +857,11 @@ static int proc_setintf(struct dev_state *ps, void __user *arg)
857 857
858static int proc_setconfig(struct dev_state *ps, void __user *arg) 858static int proc_setconfig(struct dev_state *ps, void __user *arg)
859{ 859{
860 unsigned int u; 860 int u;
861 int status = 0; 861 int status = 0;
862 struct usb_host_config *actconfig; 862 struct usb_host_config *actconfig;
863 863
864 if (get_user(u, (unsigned int __user *)arg)) 864 if (get_user(u, (int __user *)arg))
865 return -EFAULT; 865 return -EFAULT;
866 866
867 actconfig = ps->dev->actconfig; 867 actconfig = ps->dev->actconfig;
diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c
index 600d1bc8272a..2aded261f42c 100644
--- a/drivers/usb/core/driver.c
+++ b/drivers/usb/core/driver.c
@@ -743,6 +743,7 @@ EXPORT_SYMBOL_GPL(usb_deregister_device_driver);
743 * usb_register_driver - register a USB interface driver 743 * usb_register_driver - register a USB interface driver
744 * @new_driver: USB operations for the interface driver 744 * @new_driver: USB operations for the interface driver
745 * @owner: module owner of this driver. 745 * @owner: module owner of this driver.
746 * @mod_name: module name string
746 * 747 *
747 * Registers a USB interface driver with the USB core. The list of 748 * Registers a USB interface driver with the USB core. The list of
748 * unattached interfaces will be rescanned whenever a new driver is 749 * unattached interfaces will be rescanned whenever a new driver is
diff --git a/drivers/usb/core/endpoint.c b/drivers/usb/core/endpoint.c
index 5e628ae3aec7..e0ec7045e865 100644
--- a/drivers/usb/core/endpoint.c
+++ b/drivers/usb/core/endpoint.c
@@ -229,7 +229,7 @@ static int init_endpoint_class(void)
229 kref_init(&ep_class->kref); 229 kref_init(&ep_class->kref);
230 ep_class->class = class_create(THIS_MODULE, "usb_endpoint"); 230 ep_class->class = class_create(THIS_MODULE, "usb_endpoint");
231 if (IS_ERR(ep_class->class)) { 231 if (IS_ERR(ep_class->class)) {
232 result = IS_ERR(ep_class->class); 232 result = PTR_ERR(ep_class->class);
233 goto class_create_error; 233 goto class_create_error;
234 } 234 }
235 235
diff --git a/drivers/usb/core/generic.c b/drivers/usb/core/generic.c
index b531a4fd30c2..9bbcb20e2d94 100644
--- a/drivers/usb/core/generic.c
+++ b/drivers/usb/core/generic.c
@@ -184,7 +184,7 @@ static void generic_disconnect(struct usb_device *udev)
184 /* if this is only an unbind, not a physical disconnect, then 184 /* if this is only an unbind, not a physical disconnect, then
185 * unconfigure the device */ 185 * unconfigure the device */
186 if (udev->actconfig) 186 if (udev->actconfig)
187 usb_set_configuration(udev, 0); 187 usb_set_configuration(udev, -1);
188 188
189 usb_remove_sysfs_dev_files(udev); 189 usb_remove_sysfs_dev_files(udev);
190} 190}
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 590ec82d0515..50c0db15304a 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -44,6 +44,7 @@ struct usb_hub {
44 struct usb_hub_status hub; 44 struct usb_hub_status hub;
45 struct usb_port_status port; 45 struct usb_port_status port;
46 } *status; /* buffer for status reports */ 46 } *status; /* buffer for status reports */
47 struct mutex status_mutex; /* for the status buffer */
47 48
48 int error; /* last reported error */ 49 int error; /* last reported error */
49 int nerrors; /* track consecutive errors */ 50 int nerrors; /* track consecutive errors */
@@ -535,6 +536,7 @@ static int hub_hub_status(struct usb_hub *hub,
535{ 536{
536 int ret; 537 int ret;
537 538
539 mutex_lock(&hub->status_mutex);
538 ret = get_hub_status(hub->hdev, &hub->status->hub); 540 ret = get_hub_status(hub->hdev, &hub->status->hub);
539 if (ret < 0) 541 if (ret < 0)
540 dev_err (hub->intfdev, 542 dev_err (hub->intfdev,
@@ -544,6 +546,7 @@ static int hub_hub_status(struct usb_hub *hub,
544 *change = le16_to_cpu(hub->status->hub.wHubChange); 546 *change = le16_to_cpu(hub->status->hub.wHubChange);
545 ret = 0; 547 ret = 0;
546 } 548 }
549 mutex_unlock(&hub->status_mutex);
547 return ret; 550 return ret;
548} 551}
549 552
@@ -617,6 +620,7 @@ static int hub_configure(struct usb_hub *hub,
617 ret = -ENOMEM; 620 ret = -ENOMEM;
618 goto fail; 621 goto fail;
619 } 622 }
623 mutex_init(&hub->status_mutex);
620 624
621 hub->descriptor = kmalloc(sizeof(*hub->descriptor), GFP_KERNEL); 625 hub->descriptor = kmalloc(sizeof(*hub->descriptor), GFP_KERNEL);
622 if (!hub->descriptor) { 626 if (!hub->descriptor) {
@@ -1396,6 +1400,7 @@ static int hub_port_status(struct usb_hub *hub, int port1,
1396{ 1400{
1397 int ret; 1401 int ret;
1398 1402
1403 mutex_lock(&hub->status_mutex);
1399 ret = get_port_status(hub->hdev, port1, &hub->status->port); 1404 ret = get_port_status(hub->hdev, port1, &hub->status->port);
1400 if (ret < 4) { 1405 if (ret < 4) {
1401 dev_err (hub->intfdev, 1406 dev_err (hub->intfdev,
@@ -1407,6 +1412,7 @@ static int hub_port_status(struct usb_hub *hub, int port1,
1407 *change = le16_to_cpu(hub->status->port.wPortChange); 1412 *change = le16_to_cpu(hub->status->port.wPortChange);
1408 ret = 0; 1413 ret = 0;
1409 } 1414 }
1415 mutex_unlock(&hub->status_mutex);
1410 return ret; 1416 return ret;
1411} 1417}
1412 1418
@@ -1904,6 +1910,7 @@ static int hub_suspend(struct usb_interface *intf, pm_message_t msg)
1904 struct usb_hub *hub = usb_get_intfdata (intf); 1910 struct usb_hub *hub = usb_get_intfdata (intf);
1905 struct usb_device *hdev = hub->hdev; 1911 struct usb_device *hdev = hub->hdev;
1906 unsigned port1; 1912 unsigned port1;
1913 int status = 0;
1907 1914
1908 /* fail if children aren't already suspended */ 1915 /* fail if children aren't already suspended */
1909 for (port1 = 1; port1 <= hdev->maxchild; port1++) { 1916 for (port1 = 1; port1 <= hdev->maxchild; port1++) {
@@ -1927,24 +1934,18 @@ static int hub_suspend(struct usb_interface *intf, pm_message_t msg)
1927 1934
1928 dev_dbg(&intf->dev, "%s\n", __FUNCTION__); 1935 dev_dbg(&intf->dev, "%s\n", __FUNCTION__);
1929 1936
1937 /* stop khubd and related activity */
1938 hub_quiesce(hub);
1939
1930 /* "global suspend" of the downstream HC-to-USB interface */ 1940 /* "global suspend" of the downstream HC-to-USB interface */
1931 if (!hdev->parent) { 1941 if (!hdev->parent) {
1932 struct usb_bus *bus = hdev->bus; 1942 status = hcd_bus_suspend(hdev->bus);
1933 if (bus) { 1943 if (status != 0) {
1934 int status = hcd_bus_suspend (bus); 1944 dev_dbg(&hdev->dev, "'global' suspend %d\n", status);
1935 1945 hub_activate(hub);
1936 if (status != 0) { 1946 }
1937 dev_dbg(&hdev->dev, "'global' suspend %d\n",
1938 status);
1939 return status;
1940 }
1941 } else
1942 return -EOPNOTSUPP;
1943 } 1947 }
1944 1948 return status;
1945 /* stop khubd and related activity */
1946 hub_quiesce(hub);
1947 return 0;
1948} 1949}
1949 1950
1950static int hub_resume(struct usb_interface *intf) 1951static int hub_resume(struct usb_interface *intf)
diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
index 8aca3574c2b5..74edaea5665d 100644
--- a/drivers/usb/core/message.c
+++ b/drivers/usb/core/message.c
@@ -1316,6 +1316,14 @@ static void release_interface(struct device *dev)
1316 * use this kind of configurability; many devices only have one 1316 * use this kind of configurability; many devices only have one
1317 * configuration. 1317 * configuration.
1318 * 1318 *
1319 * @configuration is the value of the configuration to be installed.
1320 * According to the USB spec (e.g. section 9.1.1.5), configuration values
1321 * must be non-zero; a value of zero indicates that the device in
1322 * unconfigured. However some devices erroneously use 0 as one of their
1323 * configuration values. To help manage such devices, this routine will
1324 * accept @configuration = -1 as indicating the device should be put in
1325 * an unconfigured state.
1326 *
1319 * USB device configurations may affect Linux interoperability, 1327 * USB device configurations may affect Linux interoperability,
1320 * power consumption and the functionality available. For example, 1328 * power consumption and the functionality available. For example,
1321 * the default configuration is limited to using 100mA of bus power, 1329 * the default configuration is limited to using 100mA of bus power,
@@ -1347,10 +1355,15 @@ int usb_set_configuration(struct usb_device *dev, int configuration)
1347 struct usb_interface **new_interfaces = NULL; 1355 struct usb_interface **new_interfaces = NULL;
1348 int n, nintf; 1356 int n, nintf;
1349 1357
1350 for (i = 0; i < dev->descriptor.bNumConfigurations; i++) { 1358 if (configuration == -1)
1351 if (dev->config[i].desc.bConfigurationValue == configuration) { 1359 configuration = 0;
1352 cp = &dev->config[i]; 1360 else {
1353 break; 1361 for (i = 0; i < dev->descriptor.bNumConfigurations; i++) {
1362 if (dev->config[i].desc.bConfigurationValue ==
1363 configuration) {
1364 cp = &dev->config[i];
1365 break;
1366 }
1354 } 1367 }
1355 } 1368 }
1356 if ((!cp && configuration != 0)) 1369 if ((!cp && configuration != 0))
@@ -1359,6 +1372,7 @@ int usb_set_configuration(struct usb_device *dev, int configuration)
1359 /* The USB spec says configuration 0 means unconfigured. 1372 /* The USB spec says configuration 0 means unconfigured.
1360 * But if a device includes a configuration numbered 0, 1373 * But if a device includes a configuration numbered 0,
1361 * we will accept it as a correctly configured state. 1374 * we will accept it as a correctly configured state.
1375 * Use -1 if you really want to unconfigure the device.
1362 */ 1376 */
1363 if (cp && configuration == 0) 1377 if (cp && configuration == 0)
1364 dev_warn(&dev->dev, "config 0 descriptor??\n"); 1378 dev_warn(&dev->dev, "config 0 descriptor??\n");
diff --git a/drivers/usb/core/otg_whitelist.h b/drivers/usb/core/otg_whitelist.h
index 627a5a2fc9cf..7f31a495a25d 100644
--- a/drivers/usb/core/otg_whitelist.h
+++ b/drivers/usb/core/otg_whitelist.h
@@ -31,7 +31,7 @@ static struct usb_device_id whitelist_table [] = {
31{ USB_DEVICE_INFO(7, 1, 3) }, 31{ USB_DEVICE_INFO(7, 1, 3) },
32#endif 32#endif
33 33
34#ifdef CONFIG_USB_CDCETHER 34#ifdef CONFIG_USB_NET_CDCETHER
35/* Linux-USB CDC Ethernet gadget */ 35/* Linux-USB CDC Ethernet gadget */
36{ USB_DEVICE(0x0525, 0xa4a1), }, 36{ USB_DEVICE(0x0525, 0xa4a1), },
37/* Linux-USB CDC Ethernet + RNDIS gadget */ 37/* Linux-USB CDC Ethernet + RNDIS gadget */
diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
index 4eaa0ee8e72f..0edfbafd702c 100644
--- a/drivers/usb/core/sysfs.c
+++ b/drivers/usb/core/sysfs.c
@@ -63,7 +63,7 @@ set_bConfigurationValue(struct device *dev, struct device_attribute *attr,
63 struct usb_device *udev = to_usb_device(dev); 63 struct usb_device *udev = to_usb_device(dev);
64 int config, value; 64 int config, value;
65 65
66 if (sscanf(buf, "%u", &config) != 1 || config > 255) 66 if (sscanf(buf, "%d", &config) != 1 || config < -1 || config > 255)
67 return -EINVAL; 67 return -EINVAL;
68 usb_lock_device(udev); 68 usb_lock_device(udev);
69 value = usb_set_configuration(udev, config); 69 value = usb_set_configuration(udev, config);
diff --git a/drivers/usb/gadget/at91_udc.c b/drivers/usb/gadget/at91_udc.c
index 36b36e0175fc..a4677802fb20 100644
--- a/drivers/usb/gadget/at91_udc.c
+++ b/drivers/usb/gadget/at91_udc.c
@@ -784,7 +784,7 @@ static int at91_ep_set_halt(struct usb_ep *_ep, int value)
784 return status; 784 return status;
785} 785}
786 786
787static struct usb_ep_ops at91_ep_ops = { 787static const struct usb_ep_ops at91_ep_ops = {
788 .enable = at91_ep_enable, 788 .enable = at91_ep_enable,
789 .disable = at91_ep_disable, 789 .disable = at91_ep_disable,
790 .alloc_request = at91_ep_alloc_request, 790 .alloc_request = at91_ep_alloc_request,
@@ -912,7 +912,7 @@ static void pullup(struct at91_udc *udc, int is_on)
912 at91_udp_write(udc, AT91_UDP_TXVC, 0); 912 at91_udp_write(udc, AT91_UDP_TXVC, 0);
913 if (cpu_is_at91rm9200()) 913 if (cpu_is_at91rm9200())
914 at91_set_gpio_value(udc->board.pullup_pin, 1); 914 at91_set_gpio_value(udc->board.pullup_pin, 1);
915 else if (cpu_is_at91sam9260()) { 915 else if (cpu_is_at91sam9260() || cpu_is_at91sam9263()) {
916 u32 txvc = at91_udp_read(udc, AT91_UDP_TXVC); 916 u32 txvc = at91_udp_read(udc, AT91_UDP_TXVC);
917 917
918 txvc |= AT91_UDP_TXVC_PUON; 918 txvc |= AT91_UDP_TXVC_PUON;
@@ -929,7 +929,7 @@ static void pullup(struct at91_udc *udc, int is_on)
929 at91_udp_write(udc, AT91_UDP_TXVC, AT91_UDP_TXVC_TXVDIS); 929 at91_udp_write(udc, AT91_UDP_TXVC, AT91_UDP_TXVC_TXVDIS);
930 if (cpu_is_at91rm9200()) 930 if (cpu_is_at91rm9200())
931 at91_set_gpio_value(udc->board.pullup_pin, 0); 931 at91_set_gpio_value(udc->board.pullup_pin, 0);
932 else if (cpu_is_at91sam9260()) { 932 else if (cpu_is_at91sam9260() || cpu_is_at91sam9263()) {
933 u32 txvc = at91_udp_read(udc, AT91_UDP_TXVC); 933 u32 txvc = at91_udp_read(udc, AT91_UDP_TXVC);
934 934
935 txvc &= ~AT91_UDP_TXVC_PUON; 935 txvc &= ~AT91_UDP_TXVC_PUON;
@@ -1651,7 +1651,7 @@ static void at91udc_shutdown(struct platform_device *dev)
1651 pullup(platform_get_drvdata(dev), 0); 1651 pullup(platform_get_drvdata(dev), 0);
1652} 1652}
1653 1653
1654static int __devinit at91udc_probe(struct platform_device *pdev) 1654static int __init at91udc_probe(struct platform_device *pdev)
1655{ 1655{
1656 struct device *dev = &pdev->dev; 1656 struct device *dev = &pdev->dev;
1657 struct at91_udc *udc; 1657 struct at91_udc *udc;
@@ -1762,7 +1762,7 @@ fail0:
1762 return retval; 1762 return retval;
1763} 1763}
1764 1764
1765static int __devexit at91udc_remove(struct platform_device *pdev) 1765static int __exit at91udc_remove(struct platform_device *pdev)
1766{ 1766{
1767 struct at91_udc *udc = platform_get_drvdata(pdev); 1767 struct at91_udc *udc = platform_get_drvdata(pdev);
1768 struct resource *res; 1768 struct resource *res;
@@ -1836,8 +1836,7 @@ static int at91udc_resume(struct platform_device *pdev)
1836#endif 1836#endif
1837 1837
1838static struct platform_driver at91_udc = { 1838static struct platform_driver at91_udc = {
1839 .probe = at91udc_probe, 1839 .remove = __exit_p(at91udc_remove),
1840 .remove = __devexit_p(at91udc_remove),
1841 .shutdown = at91udc_shutdown, 1840 .shutdown = at91udc_shutdown,
1842 .suspend = at91udc_suspend, 1841 .suspend = at91udc_suspend,
1843 .resume = at91udc_resume, 1842 .resume = at91udc_resume,
@@ -1847,13 +1846,13 @@ static struct platform_driver at91_udc = {
1847 }, 1846 },
1848}; 1847};
1849 1848
1850static int __devinit udc_init_module(void) 1849static int __init udc_init_module(void)
1851{ 1850{
1852 return platform_driver_register(&at91_udc); 1851 return platform_driver_probe(&at91_udc, at91udc_probe);
1853} 1852}
1854module_init(udc_init_module); 1853module_init(udc_init_module);
1855 1854
1856static void __devexit udc_exit_module(void) 1855static void __exit udc_exit_module(void)
1857{ 1856{
1858 platform_driver_unregister(&at91_udc); 1857 platform_driver_unregister(&at91_udc);
1859} 1858}
diff --git a/drivers/usb/gadget/pxa2xx_udc.c b/drivers/usb/gadget/pxa2xx_udc.c
index 27904a56494b..f01890dc8751 100644
--- a/drivers/usb/gadget/pxa2xx_udc.c
+++ b/drivers/usb/gadget/pxa2xx_udc.c
@@ -155,7 +155,7 @@ static int is_vbus_present(void)
155 struct pxa2xx_udc_mach_info *mach = the_controller->mach; 155 struct pxa2xx_udc_mach_info *mach = the_controller->mach;
156 156
157 if (mach->gpio_vbus) 157 if (mach->gpio_vbus)
158 return pxa_gpio_get(mach->gpio_vbus); 158 return udc_gpio_get(mach->gpio_vbus);
159 if (mach->udc_is_connected) 159 if (mach->udc_is_connected)
160 return mach->udc_is_connected(); 160 return mach->udc_is_connected();
161 return 1; 161 return 1;
@@ -167,7 +167,7 @@ static void pullup_off(void)
167 struct pxa2xx_udc_mach_info *mach = the_controller->mach; 167 struct pxa2xx_udc_mach_info *mach = the_controller->mach;
168 168
169 if (mach->gpio_pullup) 169 if (mach->gpio_pullup)
170 pxa_gpio_set(mach->gpio_pullup, 0); 170 udc_gpio_set(mach->gpio_pullup, 0);
171 else if (mach->udc_command) 171 else if (mach->udc_command)
172 mach->udc_command(PXA2XX_UDC_CMD_DISCONNECT); 172 mach->udc_command(PXA2XX_UDC_CMD_DISCONNECT);
173} 173}
@@ -177,7 +177,7 @@ static void pullup_on(void)
177 struct pxa2xx_udc_mach_info *mach = the_controller->mach; 177 struct pxa2xx_udc_mach_info *mach = the_controller->mach;
178 178
179 if (mach->gpio_pullup) 179 if (mach->gpio_pullup)
180 pxa_gpio_set(mach->gpio_pullup, 1); 180 udc_gpio_set(mach->gpio_pullup, 1);
181 else if (mach->udc_command) 181 else if (mach->udc_command)
182 mach->udc_command(PXA2XX_UDC_CMD_CONNECT); 182 mach->udc_command(PXA2XX_UDC_CMD_CONNECT);
183} 183}
@@ -1755,7 +1755,7 @@ lubbock_vbus_irq(int irq, void *_dev)
1755static irqreturn_t udc_vbus_irq(int irq, void *_dev) 1755static irqreturn_t udc_vbus_irq(int irq, void *_dev)
1756{ 1756{
1757 struct pxa2xx_udc *dev = _dev; 1757 struct pxa2xx_udc *dev = _dev;
1758 int vbus = pxa_gpio_get(dev->mach->gpio_vbus); 1758 int vbus = udc_gpio_get(dev->mach->gpio_vbus);
1759 1759
1760 pxa2xx_udc_vbus_session(&dev->gadget, vbus); 1760 pxa2xx_udc_vbus_session(&dev->gadget, vbus);
1761 return IRQ_HANDLED; 1761 return IRQ_HANDLED;
@@ -2545,15 +2545,13 @@ static int __init pxa2xx_udc_probe(struct platform_device *pdev)
2545 dev->dev = &pdev->dev; 2545 dev->dev = &pdev->dev;
2546 dev->mach = pdev->dev.platform_data; 2546 dev->mach = pdev->dev.platform_data;
2547 if (dev->mach->gpio_vbus) { 2547 if (dev->mach->gpio_vbus) {
2548 vbus_irq = IRQ_GPIO(dev->mach->gpio_vbus & GPIO_MD_MASK_NR); 2548 udc_gpio_init_vbus(dev->mach->gpio_vbus);
2549 pxa_gpio_mode((dev->mach->gpio_vbus & GPIO_MD_MASK_NR) 2549 vbus_irq = udc_gpio_to_irq(dev->mach->gpio_vbus);
2550 | GPIO_IN);
2551 set_irq_type(vbus_irq, IRQT_BOTHEDGE); 2550 set_irq_type(vbus_irq, IRQT_BOTHEDGE);
2552 } else 2551 } else
2553 vbus_irq = 0; 2552 vbus_irq = 0;
2554 if (dev->mach->gpio_pullup) 2553 if (dev->mach->gpio_pullup)
2555 pxa_gpio_mode((dev->mach->gpio_pullup & GPIO_MD_MASK_NR) 2554 udc_gpio_init_pullup(dev->mach->gpio_pullup);
2556 | GPIO_OUT | GPIO_DFLT_LOW);
2557 2555
2558 init_timer(&dev->timer); 2556 init_timer(&dev->timer);
2559 dev->timer.function = udc_watchdog; 2557 dev->timer.function = udc_watchdog;
diff --git a/drivers/usb/gadget/pxa2xx_udc.h b/drivers/usb/gadget/pxa2xx_udc.h
index 8e598c8bf4e3..773e549aff3f 100644
--- a/drivers/usb/gadget/pxa2xx_udc.h
+++ b/drivers/usb/gadget/pxa2xx_udc.h
@@ -177,21 +177,6 @@ struct pxa2xx_udc {
177 177
178static struct pxa2xx_udc *the_controller; 178static struct pxa2xx_udc *the_controller;
179 179
180static inline int pxa_gpio_get(unsigned gpio)
181{
182 return (GPLR(gpio) & GPIO_bit(gpio)) != 0;
183}
184
185static inline void pxa_gpio_set(unsigned gpio, int is_on)
186{
187 int mask = GPIO_bit(gpio);
188
189 if (is_on)
190 GPSR(gpio) = mask;
191 else
192 GPCR(gpio) = mask;
193}
194
195/*-------------------------------------------------------------------------*/ 180/*-------------------------------------------------------------------------*/
196 181
197/* 182/*
diff --git a/drivers/usb/gadget/serial.c b/drivers/usb/gadget/serial.c
index e6c19aa4bef3..e552668d36b3 100644
--- a/drivers/usb/gadget/serial.c
+++ b/drivers/usb/gadget/serial.c
@@ -1699,6 +1699,7 @@ static int gs_setup_class(struct usb_gadget *gadget,
1699 memcpy(&port->port_line_coding, req->buf, ret); 1699 memcpy(&port->port_line_coding, req->buf, ret);
1700 spin_unlock(&port->port_lock); 1700 spin_unlock(&port->port_lock);
1701 } 1701 }
1702 ret = 0;
1702 break; 1703 break;
1703 1704
1704 case USB_CDC_REQ_GET_LINE_CODING: 1705 case USB_CDC_REQ_GET_LINE_CODING:
diff --git a/drivers/usb/host/ehci-dbg.c b/drivers/usb/host/ehci-dbg.c
index 246afea9e83b..43eddaecc3dd 100644
--- a/drivers/usb/host/ehci-dbg.c
+++ b/drivers/usb/host/ehci-dbg.c
@@ -322,7 +322,7 @@ static inline void remove_debug_files (struct ehci_hcd *bus) { }
322 322
323#else 323#else
324 324
325/* troubleshooting help: expose state in driverfs */ 325/* troubleshooting help: expose state in sysfs */
326 326
327#define speed_char(info1) ({ char tmp; \ 327#define speed_char(info1) ({ char tmp; \
328 switch (info1 & (3 << 12)) { \ 328 switch (info1 & (3 << 12)) { \
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index 185721dba42b..a74056488234 100644
--- a/drivers/usb/host/ehci-hcd.c
+++ b/drivers/usb/host/ehci-hcd.c
@@ -42,6 +42,9 @@
42#include <asm/irq.h> 42#include <asm/irq.h>
43#include <asm/system.h> 43#include <asm/system.h>
44#include <asm/unaligned.h> 44#include <asm/unaligned.h>
45#ifdef CONFIG_PPC_PS3
46#include <asm/firmware.h>
47#endif
45 48
46 49
47/*-------------------------------------------------------------------------*/ 50/*-------------------------------------------------------------------------*/
@@ -299,6 +302,19 @@ static void ehci_watchdog (unsigned long param)
299 spin_unlock_irqrestore (&ehci->lock, flags); 302 spin_unlock_irqrestore (&ehci->lock, flags);
300} 303}
301 304
305/* On some systems, leaving remote wakeup enabled prevents system shutdown.
306 * The firmware seems to think that powering off is a wakeup event!
307 * This routine turns off remote wakeup and everything else, on all ports.
308 */
309static void ehci_turn_off_all_ports(struct ehci_hcd *ehci)
310{
311 int port = HCS_N_PORTS(ehci->hcs_params);
312
313 while (port--)
314 ehci_writel(ehci, PORT_RWC_BITS,
315 &ehci->regs->port_status[port]);
316}
317
302/* ehci_shutdown kick in for silicon on any bus (not just pci, etc). 318/* ehci_shutdown kick in for silicon on any bus (not just pci, etc).
303 * This forcibly disables dma and IRQs, helping kexec and other cases 319 * This forcibly disables dma and IRQs, helping kexec and other cases
304 * where the next system software may expect clean state. 320 * where the next system software may expect clean state.
@@ -310,9 +326,13 @@ ehci_shutdown (struct usb_hcd *hcd)
310 326
311 ehci = hcd_to_ehci (hcd); 327 ehci = hcd_to_ehci (hcd);
312 (void) ehci_halt (ehci); 328 (void) ehci_halt (ehci);
329 ehci_turn_off_all_ports(ehci);
313 330
314 /* make BIOS/etc use companion controller during reboot */ 331 /* make BIOS/etc use companion controller during reboot */
315 ehci_writel(ehci, 0, &ehci->regs->configured_flag); 332 ehci_writel(ehci, 0, &ehci->regs->configured_flag);
333
334 /* unblock posted writes */
335 ehci_readl(ehci, &ehci->regs->configured_flag);
316} 336}
317 337
318static void ehci_port_power (struct ehci_hcd *ehci, int is_on) 338static void ehci_port_power (struct ehci_hcd *ehci, int is_on)
@@ -951,15 +971,18 @@ static int __init ehci_hcd_init(void)
951#endif 971#endif
952 972
953#ifdef PS3_SYSTEM_BUS_DRIVER 973#ifdef PS3_SYSTEM_BUS_DRIVER
954 retval = ps3_system_bus_driver_register(&PS3_SYSTEM_BUS_DRIVER); 974 if (firmware_has_feature(FW_FEATURE_PS3_LV1)) {
955 if (retval < 0) { 975 retval = ps3_system_bus_driver_register(
976 &PS3_SYSTEM_BUS_DRIVER);
977 if (retval < 0) {
956#ifdef PLATFORM_DRIVER 978#ifdef PLATFORM_DRIVER
957 platform_driver_unregister(&PLATFORM_DRIVER); 979 platform_driver_unregister(&PLATFORM_DRIVER);
958#endif 980#endif
959#ifdef PCI_DRIVER 981#ifdef PCI_DRIVER
960 pci_unregister_driver(&PCI_DRIVER); 982 pci_unregister_driver(&PCI_DRIVER);
961#endif 983#endif
962 return retval; 984 return retval;
985 }
963 } 986 }
964#endif 987#endif
965 988
@@ -976,7 +999,8 @@ static void __exit ehci_hcd_cleanup(void)
976 pci_unregister_driver(&PCI_DRIVER); 999 pci_unregister_driver(&PCI_DRIVER);
977#endif 1000#endif
978#ifdef PS3_SYSTEM_BUS_DRIVER 1001#ifdef PS3_SYSTEM_BUS_DRIVER
979 ps3_system_bus_driver_unregister(&PS3_SYSTEM_BUS_DRIVER); 1002 if (firmware_has_feature(FW_FEATURE_PS3_LV1))
1003 ps3_system_bus_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
980#endif 1004#endif
981} 1005}
982module_exit(ehci_hcd_cleanup); 1006module_exit(ehci_hcd_cleanup);
diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
index 0d83c6df1a3b..9af529d22b3e 100644
--- a/drivers/usb/host/ehci-hub.c
+++ b/drivers/usb/host/ehci-hub.c
@@ -36,6 +36,8 @@ static int ehci_bus_suspend (struct usb_hcd *hcd)
36 int port; 36 int port;
37 int mask; 37 int mask;
38 38
39 ehci_dbg(ehci, "suspend root hub\n");
40
39 if (time_before (jiffies, ehci->next_statechange)) 41 if (time_before (jiffies, ehci->next_statechange))
40 msleep(5); 42 msleep(5);
41 43
diff --git a/drivers/usb/host/isp116x-hcd.c b/drivers/usb/host/isp116x-hcd.c
index 2718b5dc4ec1..46873f2534b5 100644
--- a/drivers/usb/host/isp116x-hcd.c
+++ b/drivers/usb/host/isp116x-hcd.c
@@ -1577,7 +1577,7 @@ static int isp116x_remove(struct platform_device *pdev)
1577 1577
1578#define resource_len(r) (((r)->end - (r)->start) + 1) 1578#define resource_len(r) (((r)->end - (r)->start) + 1)
1579 1579
1580static int __init isp116x_probe(struct platform_device *pdev) 1580static int __devinit isp116x_probe(struct platform_device *pdev)
1581{ 1581{
1582 struct usb_hcd *hcd; 1582 struct usb_hcd *hcd;
1583 struct isp116x *isp116x; 1583 struct isp116x *isp116x;
diff --git a/drivers/usb/host/ohci-at91.c b/drivers/usb/host/ohci-at91.c
index 930346487278..d849c809acbd 100644
--- a/drivers/usb/host/ohci-at91.c
+++ b/drivers/usb/host/ohci-at91.c
@@ -18,19 +18,38 @@
18#include <asm/mach-types.h> 18#include <asm/mach-types.h>
19#include <asm/hardware.h> 19#include <asm/hardware.h>
20#include <asm/arch/board.h> 20#include <asm/arch/board.h>
21#include <asm/arch/cpu.h>
21 22
22#ifndef CONFIG_ARCH_AT91 23#ifndef CONFIG_ARCH_AT91
23#error "CONFIG_ARCH_AT91 must be defined." 24#error "CONFIG_ARCH_AT91 must be defined."
24#endif 25#endif
25 26
26/* interface and function clocks */ 27/* interface and function clocks; sometimes also an AHB clock */
27static struct clk *iclk, *fclk; 28static struct clk *iclk, *fclk, *hclk;
28static int clocked; 29static int clocked;
29 30
30extern int usb_disabled(void); 31extern int usb_disabled(void);
31 32
32/*-------------------------------------------------------------------------*/ 33/*-------------------------------------------------------------------------*/
33 34
35static void at91_start_clock(void)
36{
37 if (cpu_is_at91sam9261())
38 clk_enable(hclk);
39 clk_enable(iclk);
40 clk_enable(fclk);
41 clocked = 1;
42}
43
44static void at91_stop_clock(void)
45{
46 clk_disable(fclk);
47 clk_disable(iclk);
48 if (cpu_is_at91sam9261())
49 clk_disable(hclk);
50 clocked = 0;
51}
52
34static void at91_start_hc(struct platform_device *pdev) 53static void at91_start_hc(struct platform_device *pdev)
35{ 54{
36 struct usb_hcd *hcd = platform_get_drvdata(pdev); 55 struct usb_hcd *hcd = platform_get_drvdata(pdev);
@@ -41,9 +60,7 @@ static void at91_start_hc(struct platform_device *pdev)
41 /* 60 /*
42 * Start the USB clocks. 61 * Start the USB clocks.
43 */ 62 */
44 clk_enable(iclk); 63 at91_start_clock();
45 clk_enable(fclk);
46 clocked = 1;
47 64
48 /* 65 /*
49 * The USB host controller must remain in reset. 66 * The USB host controller must remain in reset.
@@ -66,9 +83,7 @@ static void at91_stop_hc(struct platform_device *pdev)
66 /* 83 /*
67 * Stop the USB clocks. 84 * Stop the USB clocks.
68 */ 85 */
69 clk_disable(fclk); 86 at91_stop_clock();
70 clk_disable(iclk);
71 clocked = 0;
72} 87}
73 88
74 89
@@ -126,6 +141,8 @@ static int usb_hcd_at91_probe(const struct hc_driver *driver,
126 141
127 iclk = clk_get(&pdev->dev, "ohci_clk"); 142 iclk = clk_get(&pdev->dev, "ohci_clk");
128 fclk = clk_get(&pdev->dev, "uhpck"); 143 fclk = clk_get(&pdev->dev, "uhpck");
144 if (cpu_is_at91sam9261())
145 hclk = clk_get(&pdev->dev, "hck0");
129 146
130 at91_start_hc(pdev); 147 at91_start_hc(pdev);
131 ohci_hcd_init(hcd_to_ohci(hcd)); 148 ohci_hcd_init(hcd_to_ohci(hcd));
@@ -137,6 +154,8 @@ static int usb_hcd_at91_probe(const struct hc_driver *driver,
137 /* Error handling */ 154 /* Error handling */
138 at91_stop_hc(pdev); 155 at91_stop_hc(pdev);
139 156
157 if (cpu_is_at91sam9261())
158 clk_put(hclk);
140 clk_put(fclk); 159 clk_put(fclk);
141 clk_put(iclk); 160 clk_put(iclk);
142 161
@@ -171,9 +190,11 @@ static int usb_hcd_at91_remove(struct usb_hcd *hcd,
171 iounmap(hcd->regs); 190 iounmap(hcd->regs);
172 release_mem_region(hcd->rsrc_start, hcd->rsrc_len); 191 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
173 192
193 if (cpu_is_at91sam9261())
194 clk_put(hclk);
174 clk_put(fclk); 195 clk_put(fclk);
175 clk_put(iclk); 196 clk_put(iclk);
176 fclk = iclk = NULL; 197 fclk = iclk = hclk = NULL;
177 198
178 dev_set_drvdata(&pdev->dev, NULL); 199 dev_set_drvdata(&pdev->dev, NULL);
179 return 0; 200 return 0;
@@ -280,9 +301,7 @@ ohci_hcd_at91_drv_suspend(struct platform_device *pdev, pm_message_t mesg)
280 */ 301 */
281 if (at91_suspend_entering_slow_clock()) { 302 if (at91_suspend_entering_slow_clock()) {
282 ohci_usb_reset (ohci); 303 ohci_usb_reset (ohci);
283 clk_disable(fclk); 304 at91_stop_clock();
284 clk_disable(iclk);
285 clocked = 0;
286 } 305 }
287 306
288 return 0; 307 return 0;
@@ -295,11 +314,8 @@ static int ohci_hcd_at91_drv_resume(struct platform_device *pdev)
295 if (device_may_wakeup(&pdev->dev)) 314 if (device_may_wakeup(&pdev->dev))
296 disable_irq_wake(hcd->irq); 315 disable_irq_wake(hcd->irq);
297 316
298 if (!clocked) { 317 if (!clocked)
299 clk_enable(iclk); 318 at91_start_clock();
300 clk_enable(fclk);
301 clocked = 1;
302 }
303 319
304 return 0; 320 return 0;
305} 321}
diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c
index fa6a7ceaa0db..f0d29eda3c6d 100644
--- a/drivers/usb/host/ohci-hcd.c
+++ b/drivers/usb/host/ohci-hcd.c
@@ -42,6 +42,9 @@
42#include <asm/system.h> 42#include <asm/system.h>
43#include <asm/unaligned.h> 43#include <asm/unaligned.h>
44#include <asm/byteorder.h> 44#include <asm/byteorder.h>
45#ifdef CONFIG_PPC_PS3
46#include <asm/firmware.h>
47#endif
45 48
46#include "../core/hcd.h" 49#include "../core/hcd.h"
47 50
@@ -944,9 +947,12 @@ static int __init ohci_hcd_mod_init(void)
944 sizeof (struct ed), sizeof (struct td)); 947 sizeof (struct ed), sizeof (struct td));
945 948
946#ifdef PS3_SYSTEM_BUS_DRIVER 949#ifdef PS3_SYSTEM_BUS_DRIVER
947 retval = ps3_system_bus_driver_register(&PS3_SYSTEM_BUS_DRIVER); 950 if (firmware_has_feature(FW_FEATURE_PS3_LV1)) {
948 if (retval < 0) 951 retval = ps3_system_bus_driver_register(
949 goto error_ps3; 952 &PS3_SYSTEM_BUS_DRIVER);
953 if (retval < 0)
954 goto error_ps3;
955 }
950#endif 956#endif
951 957
952#ifdef PLATFORM_DRIVER 958#ifdef PLATFORM_DRIVER
@@ -992,7 +998,8 @@ static int __init ohci_hcd_mod_init(void)
992 error_platform: 998 error_platform:
993#endif 999#endif
994#ifdef PS3_SYSTEM_BUS_DRIVER 1000#ifdef PS3_SYSTEM_BUS_DRIVER
995 ps3_system_bus_driver_unregister(&PS3_SYSTEM_BUS_DRIVER); 1001 if (firmware_has_feature(FW_FEATURE_PS3_LV1))
1002 ps3_system_bus_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
996 error_ps3: 1003 error_ps3:
997#endif 1004#endif
998 return retval; 1005 return retval;
@@ -1014,7 +1021,8 @@ static void __exit ohci_hcd_mod_exit(void)
1014 platform_driver_unregister(&PLATFORM_DRIVER); 1021 platform_driver_unregister(&PLATFORM_DRIVER);
1015#endif 1022#endif
1016#ifdef PS3_SYSTEM_BUS_DRIVER 1023#ifdef PS3_SYSTEM_BUS_DRIVER
1017 ps3_system_bus_driver_unregister(&PS3_SYSTEM_BUS_DRIVER); 1024 if (firmware_has_feature(FW_FEATURE_PS3_LV1))
1025 ps3_system_bus_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
1018#endif 1026#endif
1019} 1027}
1020module_exit(ohci_hcd_mod_exit); 1028module_exit(ohci_hcd_mod_exit);
diff --git a/drivers/usb/input/Kconfig b/drivers/usb/input/Kconfig
index 2e71d3cca198..69a9f3b6d0a9 100644
--- a/drivers/usb/input/Kconfig
+++ b/drivers/usb/input/Kconfig
@@ -58,13 +58,17 @@ config HID_PID
58 devices. 58 devices.
59 59
60config LOGITECH_FF 60config LOGITECH_FF
61 bool "Logitech WingMan *3D support" 61 bool "Logitech devices support"
62 depends on HID_FF 62 depends on HID_FF
63 select INPUT_FF_MEMLESS if USB_HID 63 select INPUT_FF_MEMLESS if USB_HID
64 help 64 help
65 Say Y here if you have one of these devices: 65 Say Y here if you have one of these devices:
66 - Logitech WingMan Cordless RumblePad 66 - Logitech WingMan Cordless RumblePad
67 - Logitech WingMan Cordless RumblePad 2
67 - Logitech WingMan Force 3D 68 - Logitech WingMan Force 3D
69 - Logitech Formula Force EX
70 - Logitech MOMO Force wheel
71
68 and if you want to enable force feedback for them. 72 and if you want to enable force feedback for them.
69 Note: if you say N here, this device will still be supported, but without 73 Note: if you say N here, this device will still be supported, but without
70 force feedback. 74 force feedback.
diff --git a/drivers/usb/input/hid-core.c b/drivers/usb/input/hid-core.c
index 4d8ed3d71a15..ef09952f2039 100644
--- a/drivers/usb/input/hid-core.c
+++ b/drivers/usb/input/hid-core.c
@@ -515,6 +515,7 @@ void usbhid_close(struct hid_device *hid)
515 515
516#define USB_VENDOR_ID_TURBOX 0x062a 516#define USB_VENDOR_ID_TURBOX 0x062a
517#define USB_DEVICE_ID_TURBOX_KEYBOARD 0x0201 517#define USB_DEVICE_ID_TURBOX_KEYBOARD 0x0201
518#define USB_VENDOR_ID_CIDC 0x1677
518 519
519/* 520/*
520 * Initialize all reports 521 * Initialize all reports
@@ -548,7 +549,6 @@ void usbhid_init_reports(struct hid_device *hid)
548} 549}
549 550
550#define USB_VENDOR_ID_GTCO 0x078c 551#define USB_VENDOR_ID_GTCO 0x078c
551#define USB_VENDOR_ID_GTCO_IPANEL_2 0x5543
552#define USB_DEVICE_ID_GTCO_90 0x0090 552#define USB_DEVICE_ID_GTCO_90 0x0090
553#define USB_DEVICE_ID_GTCO_100 0x0100 553#define USB_DEVICE_ID_GTCO_100 0x0100
554#define USB_DEVICE_ID_GTCO_101 0x0101 554#define USB_DEVICE_ID_GTCO_101 0x0101
@@ -594,8 +594,6 @@ void usbhid_init_reports(struct hid_device *hid)
594#define USB_DEVICE_ID_GTCO_1004 0x1004 594#define USB_DEVICE_ID_GTCO_1004 0x1004
595#define USB_DEVICE_ID_GTCO_1005 0x1005 595#define USB_DEVICE_ID_GTCO_1005 0x1005
596#define USB_DEVICE_ID_GTCO_1006 0x1006 596#define USB_DEVICE_ID_GTCO_1006 0x1006
597#define USB_DEVICE_ID_GTCO_8 0x0008
598#define USB_DEVICE_ID_GTCO_d 0x000d
599 597
600#define USB_VENDOR_ID_WACOM 0x056a 598#define USB_VENDOR_ID_WACOM 0x056a
601 599
@@ -854,8 +852,6 @@ static const struct hid_blacklist {
854 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1004, HID_QUIRK_IGNORE }, 852 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1004, HID_QUIRK_IGNORE },
855 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1005, HID_QUIRK_IGNORE }, 853 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1005, HID_QUIRK_IGNORE },
856 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1006, HID_QUIRK_IGNORE }, 854 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1006, HID_QUIRK_IGNORE },
857 { USB_VENDOR_ID_GTCO_IPANEL_2, USB_DEVICE_ID_GTCO_8, HID_QUIRK_IGNORE },
858 { USB_VENDOR_ID_GTCO_IPANEL_2, USB_DEVICE_ID_GTCO_d, HID_QUIRK_IGNORE },
859 { USB_VENDOR_ID_IMATION, USB_DEVICE_ID_DISC_STAKKA, HID_QUIRK_IGNORE }, 855 { USB_VENDOR_ID_IMATION, USB_DEVICE_ID_DISC_STAKKA, HID_QUIRK_IGNORE },
860 { USB_VENDOR_ID_KBGEAR, USB_DEVICE_ID_KBGEAR_JAMSTUDIO, HID_QUIRK_IGNORE }, 856 { USB_VENDOR_ID_KBGEAR, USB_DEVICE_ID_KBGEAR_JAMSTUDIO, HID_QUIRK_IGNORE },
861 { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_CASSY, HID_QUIRK_IGNORE }, 857 { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_CASSY, HID_QUIRK_IGNORE },
@@ -953,6 +949,8 @@ static const struct hid_blacklist {
953 949
954 { USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER, HID_QUIRK_SONY_PS3_CONTROLLER }, 950 { USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER, HID_QUIRK_SONY_PS3_CONTROLLER },
955 951
952 { USB_VENDOR_ID_CIDC, 0x0103, HID_QUIRK_IGNORE },
953
956 { 0, 0 } 954 { 0, 0 }
957}; 955};
958 956
diff --git a/drivers/usb/input/hid-ff.c b/drivers/usb/input/hid-ff.c
index bc7f8e6f8c97..e431faaa6abc 100644
--- a/drivers/usb/input/hid-ff.c
+++ b/drivers/usb/input/hid-ff.c
@@ -54,9 +54,10 @@ struct hid_ff_initializer {
54static struct hid_ff_initializer inits[] = { 54static struct hid_ff_initializer inits[] = {
55#ifdef CONFIG_LOGITECH_FF 55#ifdef CONFIG_LOGITECH_FF
56 { 0x46d, 0xc211, hid_lgff_init }, /* Logitech Cordless rumble pad */ 56 { 0x46d, 0xc211, hid_lgff_init }, /* Logitech Cordless rumble pad */
57 { 0x46d, 0xc219, hid_lgff_init }, /* Logitech Cordless rumble pad 2 */
57 { 0x46d, 0xc283, hid_lgff_init }, /* Logitech Wingman Force 3d */ 58 { 0x46d, 0xc283, hid_lgff_init }, /* Logitech Wingman Force 3d */
59 { 0x46d, 0xc294, hid_lgff_init }, /* Logitech Formula Force EX */
58 { 0x46d, 0xc295, hid_lgff_init }, /* Logitech MOMO force wheel */ 60 { 0x46d, 0xc295, hid_lgff_init }, /* Logitech MOMO force wheel */
59 { 0x46d, 0xc219, hid_lgff_init }, /* Logitech Cordless rumble pad 2 */
60 { 0x46d, 0xca03, hid_lgff_init }, /* Logitech MOMO force wheel */ 61 { 0x46d, 0xca03, hid_lgff_init }, /* Logitech MOMO force wheel */
61#endif 62#endif
62#ifdef CONFIG_PANTHERLORD_FF 63#ifdef CONFIG_PANTHERLORD_FF
diff --git a/drivers/usb/input/hid-lgff.c b/drivers/usb/input/hid-lgff.c
index 4df0968f852e..e6f3af3e66d1 100644
--- a/drivers/usb/input/hid-lgff.c
+++ b/drivers/usb/input/hid-lgff.c
@@ -52,8 +52,9 @@ static const struct dev_type devices[] = {
52 { 0x046d, 0xc211, ff_rumble }, 52 { 0x046d, 0xc211, ff_rumble },
53 { 0x046d, 0xc219, ff_rumble }, 53 { 0x046d, 0xc219, ff_rumble },
54 { 0x046d, 0xc283, ff_joystick }, 54 { 0x046d, 0xc283, ff_joystick },
55 { 0x046d, 0xc294, ff_joystick },
56 { 0x046d, 0xc295, ff_joystick },
55 { 0x046d, 0xca03, ff_joystick }, 57 { 0x046d, 0xca03, ff_joystick },
56 { 0x0000, 0x0000, ff_joystick }
57}; 58};
58 59
59static int hid_lgff_play(struct input_dev *dev, void *data, struct ff_effect *effect) 60static int hid_lgff_play(struct input_dev *dev, void *data, struct ff_effect *effect)
@@ -105,8 +106,9 @@ int hid_lgff_init(struct hid_device* hid)
105 struct input_dev *dev = hidinput->input; 106 struct input_dev *dev = hidinput->input;
106 struct hid_report *report; 107 struct hid_report *report;
107 struct hid_field *field; 108 struct hid_field *field;
109 const signed short *ff_bits = ff_joystick;
108 int error; 110 int error;
109 int i, j; 111 int i;
110 112
111 /* Find the report to use */ 113 /* Find the report to use */
112 if (list_empty(report_list)) { 114 if (list_empty(report_list)) {
@@ -130,12 +132,14 @@ int hid_lgff_init(struct hid_device* hid)
130 for (i = 0; i < ARRAY_SIZE(devices); i++) { 132 for (i = 0; i < ARRAY_SIZE(devices); i++) {
131 if (dev->id.vendor == devices[i].idVendor && 133 if (dev->id.vendor == devices[i].idVendor &&
132 dev->id.product == devices[i].idProduct) { 134 dev->id.product == devices[i].idProduct) {
133 for (j = 0; devices[i].ff[j] >= 0; j++) 135 ff_bits = devices[i].ff;
134 set_bit(devices[i].ff[j], dev->ffbit);
135 break; 136 break;
136 } 137 }
137 } 138 }
138 139
140 for (i = 0; ff_bits[i] >= 0; i++)
141 set_bit(ff_bits[i], dev->ffbit);
142
139 error = input_ff_create_memless(dev, NULL, hid_lgff_play); 143 error = input_ff_create_memless(dev, NULL, hid_lgff_play);
140 if (error) 144 if (error)
141 return error; 145 return error;
diff --git a/drivers/usb/misc/Kconfig b/drivers/usb/misc/Kconfig
index a74bf8617e7f..4907e8b80070 100644
--- a/drivers/usb/misc/Kconfig
+++ b/drivers/usb/misc/Kconfig
@@ -88,6 +88,17 @@ config USB_LCD
88 To compile this driver as a module, choose M here: the 88 To compile this driver as a module, choose M here: the
89 module will be called usblcd. 89 module will be called usblcd.
90 90
91config USB_BERRY_CHARGE
92 tristate "USB BlackBerry recharge support"
93 depends on USB
94 help
95 Say Y here if you want to connect a BlackBerry device to your
96 computer's USB port and have it automatically switch to "recharge"
97 mode.
98
99 To compile this driver as a module, choose M here: the
100 module will be called berry_charge.
101
91config USB_LED 102config USB_LED
92 tristate "USB LED driver support" 103 tristate "USB LED driver support"
93 depends on USB 104 depends on USB
diff --git a/drivers/usb/misc/Makefile b/drivers/usb/misc/Makefile
index 2cba07d31971..dac2d5b71566 100644
--- a/drivers/usb/misc/Makefile
+++ b/drivers/usb/misc/Makefile
@@ -6,6 +6,7 @@
6obj-$(CONFIG_USB_ADUTUX) += adutux.o 6obj-$(CONFIG_USB_ADUTUX) += adutux.o
7obj-$(CONFIG_USB_APPLEDISPLAY) += appledisplay.o 7obj-$(CONFIG_USB_APPLEDISPLAY) += appledisplay.o
8obj-$(CONFIG_USB_AUERSWALD) += auerswald.o 8obj-$(CONFIG_USB_AUERSWALD) += auerswald.o
9obj-$(CONFIG_USB_BERRY_CHARGE) += berry_charge.o
9obj-$(CONFIG_USB_CYPRESS_CY7C63)+= cypress_cy7c63.o 10obj-$(CONFIG_USB_CYPRESS_CY7C63)+= cypress_cy7c63.o
10obj-$(CONFIG_USB_CYTHERM) += cytherm.o 11obj-$(CONFIG_USB_CYTHERM) += cytherm.o
11obj-$(CONFIG_USB_EMI26) += emi26.o 12obj-$(CONFIG_USB_EMI26) += emi26.o
diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
index 32f0e3a5b022..e573c8ba9785 100644
--- a/drivers/usb/misc/appledisplay.c
+++ b/drivers/usb/misc/appledisplay.c
@@ -281,8 +281,8 @@ static int appledisplay_probe(struct usb_interface *iface,
281 /* Register backlight device */ 281 /* Register backlight device */
282 snprintf(bl_name, sizeof(bl_name), "appledisplay%d", 282 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
283 atomic_inc_return(&count_displays) - 1); 283 atomic_inc_return(&count_displays) - 1);
284 pdata->bd = backlight_device_register(bl_name, NULL, 284 pdata->bd = backlight_device_register(bl_name, NULL, pdata,
285 pdata, &appledisplay_bl_data); 285 &appledisplay_bl_data);
286 if (IS_ERR(pdata->bd)) { 286 if (IS_ERR(pdata->bd)) {
287 err("appledisplay: Backlight registration failed"); 287 err("appledisplay: Backlight registration failed");
288 goto error; 288 goto error;
diff --git a/drivers/usb/misc/berry_charge.c b/drivers/usb/misc/berry_charge.c
new file mode 100644
index 000000000000..60893c6c8221
--- /dev/null
+++ b/drivers/usb/misc/berry_charge.c
@@ -0,0 +1,140 @@
1/*
2 * USB BlackBerry charging module
3 *
4 * Copyright (C) 2007 Greg Kroah-Hartman <gregkh@suse.de>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation, version 2.
9 *
10 * Information on how to switch configs was taken by the bcharge.cc file
11 * created by the barry.sf.net project.
12 *
13 * bcharge.cc has the following copyright:
14 * Copyright (C) 2006, Net Direct Inc. (http://www.netdirect.ca/)
15 * and is released under the GPLv2.
16 *
17 *
18 */
19
20#include <linux/kernel.h>
21#include <linux/errno.h>
22#include <linux/init.h>
23#include <linux/slab.h>
24#include <linux/module.h>
25#include <linux/usb.h>
26
27#define RIM_VENDOR 0x0fca
28#define BLACKBERRY 0x0001
29
30static int debug;
31
32#ifdef dbg
33#undef dbg
34#endif
35#define dbg(dev, format, arg...) \
36 if (debug) \
37 dev_printk(KERN_DEBUG , dev , format , ## arg)
38
39static struct usb_device_id id_table [] = {
40 { USB_DEVICE(RIM_VENDOR, BLACKBERRY) },
41 { }, /* Terminating entry */
42};
43MODULE_DEVICE_TABLE(usb, id_table);
44
45static int magic_charge(struct usb_device *udev)
46{
47 char *dummy_buffer = kzalloc(2, GFP_KERNEL);
48 int retval;
49
50 if (!dummy_buffer)
51 return -ENOMEM;
52
53 /* send two magic commands and then set the configuration. The device
54 * will then reset itself with the new power usage and should start
55 * charging. */
56
57 /* Note, with testing, it only seems that the first message is really
58 * needed (at least for the 8700c), but to be safe, we emulate what
59 * other operating systems seem to be sending to their device. We
60 * really need to get some specs for this device to be sure about what
61 * is going on here.
62 */
63 dbg(&udev->dev, "Sending first magic command\n");
64 retval = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
65 0xa5, 0xc0, 0, 1, dummy_buffer, 2, 100);
66 if (retval != 2) {
67 dev_err(&udev->dev, "First magic command failed: %d.\n",
68 retval);
69 return retval;
70 }
71
72 dbg(&udev->dev, "Sending first magic command\n");
73 retval = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
74 0xa2, 0x40, 0, 1, dummy_buffer, 0, 100);
75 if (retval != 0) {
76 dev_err(&udev->dev, "Second magic command failed: %d.\n",
77 retval);
78 return retval;
79 }
80
81 dbg(&udev->dev, "Calling set_configuration\n");
82 retval = usb_driver_set_configuration(udev, 1);
83 if (retval)
84 dev_err(&udev->dev, "Set Configuration failed :%d.\n", retval);
85
86 return retval;
87}
88
89static int berry_probe(struct usb_interface *intf,
90 const struct usb_device_id *id)
91{
92 struct usb_device *udev = interface_to_usbdev(intf);
93
94 dbg(&udev->dev, "Power is set to %dmA\n",
95 udev->actconfig->desc.bMaxPower * 2);
96
97 /* check the power usage so we don't try to enable something that is
98 * already enabled */
99 if ((udev->actconfig->desc.bMaxPower * 2) == 500) {
100 dbg(&udev->dev, "device is already charging, power is "
101 "set to %dmA\n", udev->actconfig->desc.bMaxPower * 2);
102 return -ENODEV;
103 }
104
105 /* turn the power on */
106 magic_charge(udev);
107
108 /* we don't really want to bind to the device, userspace programs can
109 * handle the syncing just fine, so get outta here. */
110 return -ENODEV;
111}
112
113static void berry_disconnect(struct usb_interface *intf)
114{
115}
116
117static struct usb_driver berry_driver = {
118 .name = "berry_charge",
119 .probe = berry_probe,
120 .disconnect = berry_disconnect,
121 .id_table = id_table,
122};
123
124static int __init berry_init(void)
125{
126 return usb_register(&berry_driver);
127}
128
129static void __exit berry_exit(void)
130{
131 usb_deregister(&berry_driver);
132}
133
134module_init(berry_init);
135module_exit(berry_exit);
136
137MODULE_LICENSE("GPL");
138MODULE_AUTHOR("Greg Kroah-Hartman <gregkh@suse.de>");
139module_param(debug, bool, S_IRUGO | S_IWUSR);
140MODULE_PARM_DESC(debug, "Debug enabled or not");
diff --git a/drivers/usb/net/Kconfig b/drivers/usb/net/Kconfig
index a2b94ef512bc..0f3d7dbb537f 100644
--- a/drivers/usb/net/Kconfig
+++ b/drivers/usb/net/Kconfig
@@ -84,6 +84,7 @@ config USB_PEGASUS
84config USB_RTL8150 84config USB_RTL8150
85 tristate "USB RTL8150 based ethernet device support (EXPERIMENTAL)" 85 tristate "USB RTL8150 based ethernet device support (EXPERIMENTAL)"
86 depends on EXPERIMENTAL 86 depends on EXPERIMENTAL
87 select MII
87 help 88 help
88 Say Y here if you have RTL8150 based usb-ethernet adapter. 89 Say Y here if you have RTL8150 based usb-ethernet adapter.
89 Send me <petkan@users.sourceforge.net> any comments you may have. 90 Send me <petkan@users.sourceforge.net> any comments you may have.
@@ -98,7 +99,7 @@ config USB_USBNET_MII
98 99
99config USB_USBNET 100config USB_USBNET
100 tristate "Multi-purpose USB Networking Framework" 101 tristate "Multi-purpose USB Networking Framework"
101 select MII if USBNET_MII != n 102 select MII if USB_USBNET_MII != n
102 ---help--- 103 ---help---
103 This driver supports several kinds of network links over USB, 104 This driver supports several kinds of network links over USB,
104 with "minidrivers" built around a common network driver core 105 with "minidrivers" built around a common network driver core
@@ -239,6 +240,7 @@ config USB_NET_RNDIS_HOST
239config USB_NET_CDC_SUBSET 240config USB_NET_CDC_SUBSET
240 tristate "Simple USB Network Links (CDC Ethernet subset)" 241 tristate "Simple USB Network Links (CDC Ethernet subset)"
241 depends on USB_USBNET 242 depends on USB_USBNET
243 default y
242 help 244 help
243 This driver module supports USB network devices that can work 245 This driver module supports USB network devices that can work
244 without any device-specific information. Select it if you have 246 without any device-specific information. Select it if you have
@@ -298,6 +300,13 @@ config USB_EPSON2888
298 Choose this option to support the usb networking links used 300 Choose this option to support the usb networking links used
299 by some sample firmware from Epson. 301 by some sample firmware from Epson.
300 302
303config USB_KC2190
304 boolean "KT Technology KC2190 based cables (InstaNet)"
305 depends on USB_NET_CDC_SUBSET && EXPERIMENTAL
306 help
307  Choose this option if you're using a host-to-host cable
308  with one of these chips.
309
301config USB_NET_ZAURUS 310config USB_NET_ZAURUS
302 tristate "Sharp Zaurus (stock ROMs) and compatible" 311 tristate "Sharp Zaurus (stock ROMs) and compatible"
303 depends on USB_USBNET 312 depends on USB_USBNET
diff --git a/drivers/usb/net/asix.c b/drivers/usb/net/asix.c
index bd357e178e55..7ef2e4b5e39b 100644
--- a/drivers/usb/net/asix.c
+++ b/drivers/usb/net/asix.c
@@ -351,9 +351,11 @@ static struct sk_buff *asix_tx_fixup(struct usbnet *dev, struct sk_buff *skb,
351 351
352 skb_push(skb, 4); 352 skb_push(skb, 4);
353 packet_len = (((skb->len - 4) ^ 0x0000ffff) << 16) + (skb->len - 4); 353 packet_len = (((skb->len - 4) ^ 0x0000ffff) << 16) + (skb->len - 4);
354 cpu_to_le32s(&packet_len);
354 memcpy(skb->data, &packet_len, sizeof(packet_len)); 355 memcpy(skb->data, &packet_len, sizeof(packet_len));
355 356
356 if ((skb->len % 512) == 0) { 357 if ((skb->len % 512) == 0) {
358 cpu_to_le32s(&padbytes);
357 memcpy( skb->tail, &padbytes, sizeof(padbytes)); 359 memcpy( skb->tail, &padbytes, sizeof(padbytes));
358 skb_put(skb, sizeof(padbytes)); 360 skb_put(skb, sizeof(padbytes));
359 } 361 }
diff --git a/drivers/usb/net/cdc_subset.c b/drivers/usb/net/cdc_subset.c
index ae8fb06cf38e..bc62b012602b 100644
--- a/drivers/usb/net/cdc_subset.c
+++ b/drivers/usb/net/cdc_subset.c
@@ -79,13 +79,19 @@ static int always_connected (struct usbnet *dev)
79 * 79 *
80 * ALi M5632 driver ... does high speed 80 * ALi M5632 driver ... does high speed
81 * 81 *
82 * NOTE that the MS-Windows drivers for this chip use some funky and
83 * (naturally) undocumented 7-byte prefix to each packet, so this is a
84 * case where we don't currently interoperate. Also, once you unplug
85 * one end of the cable, you need to replug the other end too ... since
86 * chip docs are unavailable, there's no way to reset the relevant state
87 * short of a power cycle.
88 *
82 *-------------------------------------------------------------------------*/ 89 *-------------------------------------------------------------------------*/
83 90
84static const struct driver_info ali_m5632_info = { 91static const struct driver_info ali_m5632_info = {
85 .description = "ALi M5632", 92 .description = "ALi M5632",
86}; 93};
87 94
88
89#endif 95#endif
90 96
91 97
@@ -159,6 +165,11 @@ static const struct driver_info epson2888_info = {
159#endif /* CONFIG_USB_EPSON2888 */ 165#endif /* CONFIG_USB_EPSON2888 */
160 166
161 167
168/*-------------------------------------------------------------------------
169 *
170 * info from Jonathan McDowell <noodles@earth.li>
171 *
172 *-------------------------------------------------------------------------*/
162#ifdef CONFIG_USB_KC2190 173#ifdef CONFIG_USB_KC2190
163#define HAVE_HARDWARE 174#define HAVE_HARDWARE
164static const struct driver_info kc2190_info = { 175static const struct driver_info kc2190_info = {
@@ -223,6 +234,10 @@ static const struct usb_device_id products [] = {
223 USB_DEVICE (0x0402, 0x5632), // ALi defaults 234 USB_DEVICE (0x0402, 0x5632), // ALi defaults
224 .driver_info = (unsigned long) &ali_m5632_info, 235 .driver_info = (unsigned long) &ali_m5632_info,
225}, 236},
237{
238 USB_DEVICE (0x182d,0x207c), // SiteCom CN-124
239 .driver_info = (unsigned long) &ali_m5632_info,
240},
226#endif 241#endif
227 242
228#ifdef CONFIG_USB_AN2720 243#ifdef CONFIG_USB_AN2720
@@ -314,13 +329,13 @@ static struct usb_driver cdc_subset_driver = {
314 329
315static int __init cdc_subset_init(void) 330static int __init cdc_subset_init(void)
316{ 331{
317 return usb_register(&cdc_subset_driver); 332 return usb_register(&cdc_subset_driver);
318} 333}
319module_init(cdc_subset_init); 334module_init(cdc_subset_init);
320 335
321static void __exit cdc_subset_exit(void) 336static void __exit cdc_subset_exit(void)
322{ 337{
323 usb_deregister(&cdc_subset_driver); 338 usb_deregister(&cdc_subset_driver);
324} 339}
325module_exit(cdc_subset_exit); 340module_exit(cdc_subset_exit);
326 341
diff --git a/drivers/usb/net/usbnet.c b/drivers/usb/net/usbnet.c
index 43ba61abfcc5..de69b183bd2f 100644
--- a/drivers/usb/net/usbnet.c
+++ b/drivers/usb/net/usbnet.c
@@ -147,7 +147,7 @@ int usbnet_get_endpoints(struct usbnet *dev, struct usb_interface *intf)
147 if (tmp < 0) 147 if (tmp < 0)
148 return tmp; 148 return tmp;
149 } 149 }
150 150
151 dev->in = usb_rcvbulkpipe (dev->udev, 151 dev->in = usb_rcvbulkpipe (dev->udev,
152 in->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK); 152 in->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
153 dev->out = usb_sndbulkpipe (dev->udev, 153 dev->out = usb_sndbulkpipe (dev->udev,
@@ -327,7 +327,7 @@ static void rx_submit (struct usbnet *dev, struct urb *urb, gfp_t flags)
327 if (netif_running (dev->net) 327 if (netif_running (dev->net)
328 && netif_device_present (dev->net) 328 && netif_device_present (dev->net)
329 && !test_bit (EVENT_RX_HALT, &dev->flags)) { 329 && !test_bit (EVENT_RX_HALT, &dev->flags)) {
330 switch (retval = usb_submit_urb (urb, GFP_ATOMIC)){ 330 switch (retval = usb_submit_urb (urb, GFP_ATOMIC)){
331 case -EPIPE: 331 case -EPIPE:
332 usbnet_defer_kevent (dev, EVENT_RX_HALT); 332 usbnet_defer_kevent (dev, EVENT_RX_HALT);
333 break; 333 break;
@@ -443,7 +443,7 @@ block:
443 case -EOVERFLOW: 443 case -EOVERFLOW:
444 dev->stats.rx_over_errors++; 444 dev->stats.rx_over_errors++;
445 // FALLTHROUGH 445 // FALLTHROUGH
446 446
447 default: 447 default:
448 entry->state = rx_cleanup; 448 entry->state = rx_cleanup;
449 dev->stats.rx_errors++; 449 dev->stats.rx_errors++;
@@ -560,7 +560,7 @@ static int usbnet_stop (struct net_device *net)
560 560
561 if (netif_msg_ifdown (dev)) 561 if (netif_msg_ifdown (dev))
562 devinfo (dev, "stop stats: rx/tx %ld/%ld, errs %ld/%ld", 562 devinfo (dev, "stop stats: rx/tx %ld/%ld, errs %ld/%ld",
563 dev->stats.rx_packets, dev->stats.tx_packets, 563 dev->stats.rx_packets, dev->stats.tx_packets,
564 dev->stats.rx_errors, dev->stats.tx_errors 564 dev->stats.rx_errors, dev->stats.tx_errors
565 ); 565 );
566 566
@@ -578,7 +578,7 @@ static int usbnet_stop (struct net_device *net)
578 devdbg (dev, "waited for %d urb completions", temp); 578 devdbg (dev, "waited for %d urb completions", temp);
579 } 579 }
580 dev->wait = NULL; 580 dev->wait = NULL;
581 remove_wait_queue (&unlink_wakeup, &wait); 581 remove_wait_queue (&unlink_wakeup, &wait);
582 582
583 usb_kill_urb(dev->interrupt); 583 usb_kill_urb(dev->interrupt);
584 584
@@ -834,7 +834,7 @@ kevent (struct work_struct *work)
834 } 834 }
835 835
836 if (test_bit (EVENT_LINK_RESET, &dev->flags)) { 836 if (test_bit (EVENT_LINK_RESET, &dev->flags)) {
837 struct driver_info *info = dev->driver_info; 837 struct driver_info *info = dev->driver_info;
838 int retval = 0; 838 int retval = 0;
839 839
840 clear_bit (EVENT_LINK_RESET, &dev->flags); 840 clear_bit (EVENT_LINK_RESET, &dev->flags);
@@ -1066,7 +1066,7 @@ static void usbnet_bh (unsigned long param)
1066 * USB Device Driver support 1066 * USB Device Driver support
1067 * 1067 *
1068 *-------------------------------------------------------------------------*/ 1068 *-------------------------------------------------------------------------*/
1069 1069
1070// precondition: never called in_interrupt 1070// precondition: never called in_interrupt
1071 1071
1072void usbnet_disconnect (struct usb_interface *intf) 1072void usbnet_disconnect (struct usb_interface *intf)
@@ -1087,7 +1087,7 @@ void usbnet_disconnect (struct usb_interface *intf)
1087 intf->dev.driver->name, 1087 intf->dev.driver->name,
1088 xdev->bus->bus_name, xdev->devpath, 1088 xdev->bus->bus_name, xdev->devpath,
1089 dev->driver_info->description); 1089 dev->driver_info->description);
1090 1090
1091 net = dev->net; 1091 net = dev->net;
1092 unregister_netdev (net); 1092 unregister_netdev (net);
1093 1093
@@ -1111,7 +1111,7 @@ int
1111usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod) 1111usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod)
1112{ 1112{
1113 struct usbnet *dev; 1113 struct usbnet *dev;
1114 struct net_device *net; 1114 struct net_device *net;
1115 struct usb_host_interface *interface; 1115 struct usb_host_interface *interface;
1116 struct driver_info *info; 1116 struct driver_info *info;
1117 struct usb_device *xdev; 1117 struct usb_device *xdev;
@@ -1181,6 +1181,9 @@ usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod)
1181 // NOTE net->name still not usable ... 1181 // NOTE net->name still not usable ...
1182 if (info->bind) { 1182 if (info->bind) {
1183 status = info->bind (dev, udev); 1183 status = info->bind (dev, udev);
1184 if (status < 0)
1185 goto out1;
1186
1184 // heuristic: "usb%d" for links we know are two-host, 1187 // heuristic: "usb%d" for links we know are two-host,
1185 // else "eth%d" when there's reasonable doubt. userspace 1188 // else "eth%d" when there's reasonable doubt. userspace
1186 // can rename the link if it knows better. 1189 // can rename the link if it knows better.
@@ -1207,12 +1210,12 @@ usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod)
1207 if (status == 0 && dev->status) 1210 if (status == 0 && dev->status)
1208 status = init_status (dev, udev); 1211 status = init_status (dev, udev);
1209 if (status < 0) 1212 if (status < 0)
1210 goto out1; 1213 goto out3;
1211 1214
1212 if (!dev->rx_urb_size) 1215 if (!dev->rx_urb_size)
1213 dev->rx_urb_size = dev->hard_mtu; 1216 dev->rx_urb_size = dev->hard_mtu;
1214 dev->maxpacket = usb_maxpacket (dev->udev, dev->out, 1); 1217 dev->maxpacket = usb_maxpacket (dev->udev, dev->out, 1);
1215 1218
1216 SET_NETDEV_DEV(net, &udev->dev); 1219 SET_NETDEV_DEV(net, &udev->dev);
1217 status = register_netdev (net); 1220 status = register_netdev (net);
1218 if (status) 1221 if (status)
@@ -1255,7 +1258,7 @@ EXPORT_SYMBOL_GPL(usbnet_probe);
1255int usbnet_suspend (struct usb_interface *intf, pm_message_t message) 1258int usbnet_suspend (struct usb_interface *intf, pm_message_t message)
1256{ 1259{
1257 struct usbnet *dev = usb_get_intfdata(intf); 1260 struct usbnet *dev = usb_get_intfdata(intf);
1258 1261
1259 /* accelerate emptying of the rx and queues, to avoid 1262 /* accelerate emptying of the rx and queues, to avoid
1260 * having everything error out. 1263 * having everything error out.
1261 */ 1264 */
@@ -1286,7 +1289,7 @@ static int __init usbnet_init(void)
1286 < sizeof (struct skb_data)); 1289 < sizeof (struct skb_data));
1287 1290
1288 random_ether_addr(node_id); 1291 random_ether_addr(node_id);
1289 return 0; 1292 return 0;
1290} 1293}
1291module_init(usbnet_init); 1294module_init(usbnet_init);
1292 1295
diff --git a/drivers/usb/serial/airprime.c b/drivers/usb/serial/airprime.c
index 0af42e32fa0a..18816bf96a4d 100644
--- a/drivers/usb/serial/airprime.c
+++ b/drivers/usb/serial/airprime.c
@@ -58,11 +58,6 @@ static void airprime_read_bulk_callback(struct urb *urb)
58 if (urb->status) { 58 if (urb->status) {
59 dbg("%s - nonzero read bulk status received: %d", 59 dbg("%s - nonzero read bulk status received: %d",
60 __FUNCTION__, urb->status); 60 __FUNCTION__, urb->status);
61 /* something happened, so free up the memory for this urb */
62 if (urb->transfer_buffer) {
63 kfree (urb->transfer_buffer);
64 urb->transfer_buffer = NULL;
65 }
66 return; 61 return;
67 } 62 }
68 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, urb->actual_length, data); 63 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, urb->actual_length, data);
@@ -146,6 +141,8 @@ static int airprime_open(struct usb_serial_port *port, struct file *filp)
146 airprime_read_bulk_callback, port); 141 airprime_read_bulk_callback, port);
147 result = usb_submit_urb(urb, GFP_KERNEL); 142 result = usb_submit_urb(urb, GFP_KERNEL);
148 if (result) { 143 if (result) {
144 usb_free_urb(urb);
145 kfree(buffer);
149 dev_err(&port->dev, 146 dev_err(&port->dev,
150 "%s - failed submitting read urb %d for port %d, error %d\n", 147 "%s - failed submitting read urb %d for port %d, error %d\n",
151 __FUNCTION__, i, port->number, result); 148 __FUNCTION__, i, port->number, result);
@@ -160,27 +157,12 @@ static int airprime_open(struct usb_serial_port *port, struct file *filp)
160 /* some error happened, cancel any submitted urbs and clean up anything that 157 /* some error happened, cancel any submitted urbs and clean up anything that
161 got allocated successfully */ 158 got allocated successfully */
162 159
163 for ( ; i >= 0; --i) { 160 while (i-- != 0) {
164 urb = priv->read_urbp[i]; 161 urb = priv->read_urbp[i];
165 if (urb) { 162 buffer = urb->transfer_buffer;
166 /* This urb was submitted successfully. So we have to 163 usb_kill_urb (urb);
167 cancel it. 164 usb_free_urb (urb);
168 Unlinking the urb will invoke read_bulk_callback() 165 kfree (buffer);
169 with an error status, so its transfer buffer will
170 be freed there */
171 if (usb_unlink_urb (urb) != -EINPROGRESS) {
172 /* comments in drivers/usb/core/urb.c say this
173 can only happen if the urb was never submitted,
174 or has completed already.
175 Either way we may have to free the transfer
176 buffer here. */
177 if (urb->transfer_buffer) {
178 kfree (urb->transfer_buffer);
179 urb->transfer_buffer = NULL;
180 }
181 }
182 usb_free_urb (urb);
183 }
184 } 166 }
185 167
186 out: 168 out:
@@ -194,10 +176,9 @@ static void airprime_close(struct usb_serial_port *port, struct file * filp)
194 176
195 dbg("%s - port %d", __FUNCTION__, port->number); 177 dbg("%s - port %d", __FUNCTION__, port->number);
196 178
197 /* killing the urb will invoke read_bulk_callback() with an error status,
198 so the transfer buffer will be freed there */
199 for (i = 0; i < NUM_READ_URBS; ++i) { 179 for (i = 0; i < NUM_READ_URBS; ++i) {
200 usb_kill_urb (priv->read_urbp[i]); 180 usb_kill_urb (priv->read_urbp[i]);
181 kfree (priv->read_urbp[i]->transfer_buffer);
201 usb_free_urb (priv->read_urbp[i]); 182 usb_free_urb (priv->read_urbp[i]);
202 } 183 }
203 184
diff --git a/drivers/usb/serial/cp2101.c b/drivers/usb/serial/cp2101.c
index 3ec24870bca9..db623e754899 100644
--- a/drivers/usb/serial/cp2101.c
+++ b/drivers/usb/serial/cp2101.c
@@ -69,6 +69,7 @@ static struct usb_device_id id_table [] = {
69 { USB_DEVICE(0x10C4, 0x8218) }, /* Lipowsky Industrie Elektronik GmbH, HARP-1 */ 69 { USB_DEVICE(0x10C4, 0x8218) }, /* Lipowsky Industrie Elektronik GmbH, HARP-1 */
70 { USB_DEVICE(0x10C4, 0xEA60) }, /* Silicon Labs factory default */ 70 { USB_DEVICE(0x10C4, 0xEA60) }, /* Silicon Labs factory default */
71 { USB_DEVICE(0x10C4, 0xEA61) }, /* Silicon Labs factory default */ 71 { USB_DEVICE(0x10C4, 0xEA61) }, /* Silicon Labs factory default */
72 { USB_DEVICE(0x10C5, 0xEA61) }, /* Silicon Labs MobiData GPRS USB Modem */
72 { USB_DEVICE(0x13AD, 0x9999) }, /* Baltech card reader */ 73 { USB_DEVICE(0x13AD, 0x9999) }, /* Baltech card reader */
73 { USB_DEVICE(0x16D6, 0x0001) }, /* Jablotron serial interface */ 74 { USB_DEVICE(0x16D6, 0x0001) }, /* Jablotron serial interface */
74 { } /* Terminating Entry */ 75 { } /* Terminating Entry */
diff --git a/drivers/usb/serial/generic.c b/drivers/usb/serial/generic.c
index 601e0648dec6..53baeec8f265 100644
--- a/drivers/usb/serial/generic.c
+++ b/drivers/usb/serial/generic.c
@@ -66,6 +66,8 @@ struct usb_serial_driver usb_serial_generic_device = {
66 .num_bulk_out = NUM_DONT_CARE, 66 .num_bulk_out = NUM_DONT_CARE,
67 .num_ports = 1, 67 .num_ports = 1,
68 .shutdown = usb_serial_generic_shutdown, 68 .shutdown = usb_serial_generic_shutdown,
69 .throttle = usb_serial_generic_throttle,
70 .unthrottle = usb_serial_generic_unthrottle,
69}; 71};
70 72
71static int generic_probe(struct usb_interface *interface, 73static int generic_probe(struct usb_interface *interface,
@@ -115,6 +117,7 @@ int usb_serial_generic_open (struct usb_serial_port *port, struct file *filp)
115{ 117{
116 struct usb_serial *serial = port->serial; 118 struct usb_serial *serial = port->serial;
117 int result = 0; 119 int result = 0;
120 unsigned long flags;
118 121
119 dbg("%s - port %d", __FUNCTION__, port->number); 122 dbg("%s - port %d", __FUNCTION__, port->number);
120 123
@@ -124,7 +127,13 @@ int usb_serial_generic_open (struct usb_serial_port *port, struct file *filp)
124 if (port->tty) 127 if (port->tty)
125 port->tty->low_latency = 1; 128 port->tty->low_latency = 1;
126 129
127 /* if we have a bulk interrupt, start reading from it */ 130 /* clear the throttle flags */
131 spin_lock_irqsave(&port->lock, flags);
132 port->throttled = 0;
133 port->throttle_req = 0;
134 spin_unlock_irqrestore(&port->lock, flags);
135
136 /* if we have a bulk endpoint, start reading from it */
128 if (serial->num_bulk_in) { 137 if (serial->num_bulk_in) {
129 /* Start reading from the device */ 138 /* Start reading from the device */
130 usb_fill_bulk_urb (port->read_urb, serial->dev, 139 usb_fill_bulk_urb (port->read_urb, serial->dev,
@@ -253,31 +262,22 @@ int usb_serial_generic_chars_in_buffer (struct usb_serial_port *port)
253 return (chars); 262 return (chars);
254} 263}
255 264
256void usb_serial_generic_read_bulk_callback (struct urb *urb) 265/* Push data to tty layer and resubmit the bulk read URB */
266static void flush_and_resubmit_read_urb (struct usb_serial_port *port)
257{ 267{
258 struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
259 struct usb_serial *serial = port->serial; 268 struct usb_serial *serial = port->serial;
260 struct tty_struct *tty; 269 struct urb *urb = port->read_urb;
261 unsigned char *data = urb->transfer_buffer; 270 struct tty_struct *tty = port->tty;
262 int result; 271 int result;
263 272
264 dbg("%s - port %d", __FUNCTION__, port->number); 273 /* Push data to tty */
265
266 if (urb->status) {
267 dbg("%s - nonzero read bulk status received: %d", __FUNCTION__, urb->status);
268 return;
269 }
270
271 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, urb->actual_length, data);
272
273 tty = port->tty;
274 if (tty && urb->actual_length) { 274 if (tty && urb->actual_length) {
275 tty_buffer_request_room(tty, urb->actual_length); 275 tty_buffer_request_room(tty, urb->actual_length);
276 tty_insert_flip_string(tty, data, urb->actual_length); 276 tty_insert_flip_string(tty, urb->transfer_buffer, urb->actual_length);
277 tty_flip_buffer_push(tty); 277 tty_flip_buffer_push(tty); /* is this allowed from an URB callback ? */
278 } 278 }
279 279
280 /* Continue trying to always read */ 280 /* Continue reading from device */
281 usb_fill_bulk_urb (port->read_urb, serial->dev, 281 usb_fill_bulk_urb (port->read_urb, serial->dev,
282 usb_rcvbulkpipe (serial->dev, 282 usb_rcvbulkpipe (serial->dev,
283 port->bulk_in_endpointAddress), 283 port->bulk_in_endpointAddress),
@@ -290,6 +290,40 @@ void usb_serial_generic_read_bulk_callback (struct urb *urb)
290 if (result) 290 if (result)
291 dev_err(&port->dev, "%s - failed resubmitting read urb, error %d\n", __FUNCTION__, result); 291 dev_err(&port->dev, "%s - failed resubmitting read urb, error %d\n", __FUNCTION__, result);
292} 292}
293
294void usb_serial_generic_read_bulk_callback (struct urb *urb)
295{
296 struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
297 unsigned char *data = urb->transfer_buffer;
298 int is_throttled;
299 unsigned long flags;
300
301 dbg("%s - port %d", __FUNCTION__, port->number);
302
303 if (urb->status) {
304 dbg("%s - nonzero read bulk status received: %d", __FUNCTION__, urb->status);
305 return;
306 }
307
308 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, urb->actual_length, data);
309
310 /* Throttle the device if requested by tty */
311 if (urb->actual_length) {
312 spin_lock_irqsave(&port->lock, flags);
313 is_throttled = port->throttled = port->throttle_req;
314 spin_unlock_irqrestore(&port->lock, flags);
315 if (is_throttled) {
316 /* Let the received data linger in the read URB;
317 * usb_serial_generic_unthrottle() will pick it
318 * up later. */
319 dbg("%s - throttling device", __FUNCTION__);
320 return;
321 }
322 }
323
324 /* Handle data and continue reading from device */
325 flush_and_resubmit_read_urb(port);
326}
293EXPORT_SYMBOL_GPL(usb_serial_generic_read_bulk_callback); 327EXPORT_SYMBOL_GPL(usb_serial_generic_read_bulk_callback);
294 328
295void usb_serial_generic_write_bulk_callback (struct urb *urb) 329void usb_serial_generic_write_bulk_callback (struct urb *urb)
@@ -308,6 +342,38 @@ void usb_serial_generic_write_bulk_callback (struct urb *urb)
308} 342}
309EXPORT_SYMBOL_GPL(usb_serial_generic_write_bulk_callback); 343EXPORT_SYMBOL_GPL(usb_serial_generic_write_bulk_callback);
310 344
345void usb_serial_generic_throttle (struct usb_serial_port *port)
346{
347 unsigned long flags;
348
349 dbg("%s - port %d", __FUNCTION__, port->number);
350
351 /* Set the throttle request flag. It will be picked up
352 * by usb_serial_generic_read_bulk_callback(). */
353 spin_lock_irqsave(&port->lock, flags);
354 port->throttle_req = 1;
355 spin_unlock_irqrestore(&port->lock, flags);
356}
357
358void usb_serial_generic_unthrottle (struct usb_serial_port *port)
359{
360 int was_throttled;
361 unsigned long flags;
362
363 dbg("%s - port %d", __FUNCTION__, port->number);
364
365 /* Clear the throttle flags */
366 spin_lock_irqsave(&port->lock, flags);
367 was_throttled = port->throttled;
368 port->throttled = port->throttle_req = 0;
369 spin_unlock_irqrestore(&port->lock, flags);
370
371 if (was_throttled) {
372 /* Handle pending data and resume reading from device */
373 flush_and_resubmit_read_urb(port);
374 }
375}
376
311void usb_serial_generic_shutdown (struct usb_serial *serial) 377void usb_serial_generic_shutdown (struct usb_serial *serial)
312{ 378{
313 int i; 379 int i;
diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c
index ced9f32b29d9..9963a8b75840 100644
--- a/drivers/usb/serial/option.c
+++ b/drivers/usb/serial/option.c
@@ -69,7 +69,6 @@ static int option_send_setup(struct usb_serial_port *port);
69/* Vendor and product IDs */ 69/* Vendor and product IDs */
70#define OPTION_VENDOR_ID 0x0AF0 70#define OPTION_VENDOR_ID 0x0AF0
71#define HUAWEI_VENDOR_ID 0x12D1 71#define HUAWEI_VENDOR_ID 0x12D1
72#define AUDIOVOX_VENDOR_ID 0x0F3D
73#define NOVATELWIRELESS_VENDOR_ID 0x1410 72#define NOVATELWIRELESS_VENDOR_ID 0x1410
74#define ANYDATA_VENDOR_ID 0x16d5 73#define ANYDATA_VENDOR_ID 0x16d5
75 74
@@ -81,7 +80,6 @@ static int option_send_setup(struct usb_serial_port *port);
81#define OPTION_PRODUCT_GTMAX36 0x6701 80#define OPTION_PRODUCT_GTMAX36 0x6701
82#define HUAWEI_PRODUCT_E600 0x1001 81#define HUAWEI_PRODUCT_E600 0x1001
83#define HUAWEI_PRODUCT_E220 0x1003 82#define HUAWEI_PRODUCT_E220 0x1003
84#define AUDIOVOX_PRODUCT_AIRCARD 0x0112
85#define NOVATELWIRELESS_PRODUCT_U740 0x1400 83#define NOVATELWIRELESS_PRODUCT_U740 0x1400
86#define ANYDATA_PRODUCT_ID 0x6501 84#define ANYDATA_PRODUCT_ID 0x6501
87 85
@@ -94,7 +92,6 @@ static struct usb_device_id option_ids[] = {
94 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_GTMAX36) }, 92 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_GTMAX36) },
95 { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E600) }, 93 { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E600) },
96 { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E220) }, 94 { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E220) },
97 { USB_DEVICE(AUDIOVOX_VENDOR_ID, AUDIOVOX_PRODUCT_AIRCARD) },
98 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID,NOVATELWIRELESS_PRODUCT_U740) }, 95 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID,NOVATELWIRELESS_PRODUCT_U740) },
99 { USB_DEVICE(ANYDATA_VENDOR_ID, ANYDATA_PRODUCT_ID) }, 96 { USB_DEVICE(ANYDATA_VENDOR_ID, ANYDATA_PRODUCT_ID) },
100 { } /* Terminating entry */ 97 { } /* Terminating entry */
@@ -109,7 +106,6 @@ static struct usb_device_id option_ids1[] = {
109 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_GTMAX36) }, 106 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_GTMAX36) },
110 { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E600) }, 107 { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E600) },
111 { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E220) }, 108 { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E220) },
112 { USB_DEVICE(AUDIOVOX_VENDOR_ID, AUDIOVOX_PRODUCT_AIRCARD) },
113 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID,NOVATELWIRELESS_PRODUCT_U740) }, 109 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID,NOVATELWIRELESS_PRODUCT_U740) },
114 { USB_DEVICE(ANYDATA_VENDOR_ID, ANYDATA_PRODUCT_ID) }, 110 { USB_DEVICE(ANYDATA_VENDOR_ID, ANYDATA_PRODUCT_ID) },
115 { } /* Terminating entry */ 111 { } /* Terminating entry */
diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c
index 6c083d4e2c9b..83dfae93a45d 100644
--- a/drivers/usb/serial/pl2303.c
+++ b/drivers/usb/serial/pl2303.c
@@ -83,6 +83,7 @@ static struct usb_device_id id_table [] = {
83 { USB_DEVICE(BELKIN_VENDOR_ID, BELKIN_PRODUCT_ID) }, 83 { USB_DEVICE(BELKIN_VENDOR_ID, BELKIN_PRODUCT_ID) },
84 { USB_DEVICE(ALCOR_VENDOR_ID, ALCOR_PRODUCT_ID) }, 84 { USB_DEVICE(ALCOR_VENDOR_ID, ALCOR_PRODUCT_ID) },
85 { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_ID) }, 85 { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_ID) },
86 { USB_DEVICE(WS002IN_VENDOR_ID, WS002IN_PRODUCT_ID) },
86 { } /* Terminating entry */ 87 { } /* Terminating entry */
87}; 88};
88 89
diff --git a/drivers/usb/serial/pl2303.h b/drivers/usb/serial/pl2303.h
index 65a5039665e7..f9a71d0c102e 100644
--- a/drivers/usb/serial/pl2303.h
+++ b/drivers/usb/serial/pl2303.h
@@ -97,3 +97,8 @@
97/* Huawei E620 UMTS/HSDPA card (ID: 12d1:1001) */ 97/* Huawei E620 UMTS/HSDPA card (ID: 12d1:1001) */
98#define HUAWEI_VENDOR_ID 0x12d1 98#define HUAWEI_VENDOR_ID 0x12d1
99#define HUAWEI_PRODUCT_ID 0x1001 99#define HUAWEI_PRODUCT_ID 0x1001
100
101/* Willcom WS002IN Data Driver (by NetIndex Inc.) */
102#define WS002IN_VENDOR_ID 0x11f6
103#define WS002IN_PRODUCT_ID 0x2001
104
diff --git a/drivers/usb/storage/scsiglue.c b/drivers/usb/storage/scsiglue.c
index 70234f5dbeeb..e227f64d5641 100644
--- a/drivers/usb/storage/scsiglue.c
+++ b/drivers/usb/storage/scsiglue.c
@@ -153,6 +153,12 @@ static int slave_configure(struct scsi_device *sdev)
153 if (us->flags & US_FL_FIX_CAPACITY) 153 if (us->flags & US_FL_FIX_CAPACITY)
154 sdev->fix_capacity = 1; 154 sdev->fix_capacity = 1;
155 155
156 /* A few disks have two indistinguishable version, one of
157 * which reports the correct capacity and the other does not.
158 * The sd driver has to guess which is the case. */
159 if (us->flags & US_FL_CAPACITY_HEURISTICS)
160 sdev->guess_capacity = 1;
161
156 /* Some devices report a SCSI revision level above 2 but are 162 /* Some devices report a SCSI revision level above 2 but are
157 * unable to handle the REPORT LUNS command (for which 163 * unable to handle the REPORT LUNS command (for which
158 * support is mandatory at level 3). Since we already have 164 * support is mandatory at level 3). Since we already have
diff --git a/drivers/usb/storage/unusual_devs.h b/drivers/usb/storage/unusual_devs.h
index f49a62fc32d2..9644a8ea4aa7 100644
--- a/drivers/usb/storage/unusual_devs.h
+++ b/drivers/usb/storage/unusual_devs.h
@@ -1101,6 +1101,15 @@ UNUSUAL_DEV( 0x08bd, 0x1100, 0x0000, 0x0000,
1101 US_SC_DEVICE, US_PR_DEVICE, NULL, 1101 US_SC_DEVICE, US_PR_DEVICE, NULL,
1102 US_FL_SINGLE_LUN), 1102 US_FL_SINGLE_LUN),
1103 1103
1104/* Submitted by Dylan Taft <d13f00l@gmail.com>
1105 * US_FL_IGNORE_RESIDUE Needed
1106 */
1107UNUSUAL_DEV( 0x08ca, 0x3103, 0x0100, 0x0100,
1108 "AIPTEK",
1109 "Aiptek USB Keychain MP3 Player",
1110 US_SC_DEVICE, US_PR_DEVICE, NULL,
1111 US_FL_IGNORE_RESIDUE),
1112
1104/* Entry needed for flags. Moreover, all devices with this ID use 1113/* Entry needed for flags. Moreover, all devices with this ID use
1105 * bulk-only transport, but _some_ falsely report Control/Bulk instead. 1114 * bulk-only transport, but _some_ falsely report Control/Bulk instead.
1106 * One example is "Trumpion Digital Research MYMP3". 1115 * One example is "Trumpion Digital Research MYMP3".
@@ -1311,12 +1320,13 @@ UNUSUAL_DEV( 0x0fce, 0xd008, 0x0000, 0x0000,
1311 US_SC_DEVICE, US_PR_DEVICE, NULL, 1320 US_SC_DEVICE, US_PR_DEVICE, NULL,
1312 US_FL_NO_WP_DETECT ), 1321 US_FL_NO_WP_DETECT ),
1313 1322
1314/* Reported by Jan Mate <mate@fiit.stuba.sk> */ 1323/* Reported by Jan Mate <mate@fiit.stuba.sk>
1324 * and by Soeren Sonnenburg <kernel@nn7.de> */
1315UNUSUAL_DEV( 0x0fce, 0xe030, 0x0000, 0x0000, 1325UNUSUAL_DEV( 0x0fce, 0xe030, 0x0000, 0x0000,
1316 "Sony Ericsson", 1326 "Sony Ericsson",
1317 "P990i", 1327 "P990i",
1318 US_SC_DEVICE, US_PR_DEVICE, NULL, 1328 US_SC_DEVICE, US_PR_DEVICE, NULL,
1319 US_FL_FIX_CAPACITY ), 1329 US_FL_FIX_CAPACITY | US_FL_IGNORE_RESIDUE ),
1320 1330
1321/* Reported by Emmanuel Vasilakis <evas@forthnet.gr> */ 1331/* Reported by Emmanuel Vasilakis <evas@forthnet.gr> */
1322UNUSUAL_DEV( 0x0fce, 0xe031, 0x0000, 0x0000, 1332UNUSUAL_DEV( 0x0fce, 0xe031, 0x0000, 0x0000,
@@ -1385,6 +1395,16 @@ UNUSUAL_DEV( 0x1652, 0x6600, 0x0201, 0x0201,
1385 US_SC_DEVICE, US_PR_DEVICE, NULL, 1395 US_SC_DEVICE, US_PR_DEVICE, NULL,
1386 US_FL_IGNORE_RESIDUE ), 1396 US_FL_IGNORE_RESIDUE ),
1387 1397
1398/* Reported by Thomas Baechler <thomas@archlinux.org>
1399 * Fixes I/O errors with Teac HD-35PU devices
1400 */
1401
1402UNUSUAL_DEV( 0x1652, 0x6600, 0x0201, 0x0201,
1403 "Super Top",
1404 "USB 2.0 IDE DEVICE",
1405 US_SC_DEVICE, US_PR_DEVICE, NULL,
1406 US_FL_IGNORE_RESIDUE),
1407
1388/* patch submitted by Davide Perini <perini.davide@dpsoftware.org> 1408/* patch submitted by Davide Perini <perini.davide@dpsoftware.org>
1389 * and Renato Perini <rperini@email.it> 1409 * and Renato Perini <rperini@email.it>
1390 */ 1410 */
@@ -1423,7 +1443,7 @@ UNUSUAL_DEV( 0xed06, 0x4500, 0x0001, 0x0001,
1423 "DataStor", 1443 "DataStor",
1424 "USB4500 FW1.04", 1444 "USB4500 FW1.04",
1425 US_SC_DEVICE, US_PR_DEVICE, NULL, 1445 US_SC_DEVICE, US_PR_DEVICE, NULL,
1426 US_FL_FIX_CAPACITY), 1446 US_FL_CAPACITY_HEURISTICS),
1427 1447
1428/* Control/Bulk transport for all SubClass values */ 1448/* Control/Bulk transport for all SubClass values */
1429USUAL_DEV(US_SC_RBC, US_PR_CB, USB_US_TYPE_STOR), 1449USUAL_DEV(US_SC_RBC, US_PR_CB, USB_US_TYPE_STOR),
diff --git a/drivers/usb/usb-skeleton.c b/drivers/usb/usb-skeleton.c
index 296b091cf168..46929a1b6f24 100644
--- a/drivers/usb/usb-skeleton.c
+++ b/drivers/usb/usb-skeleton.c
@@ -90,13 +90,15 @@ static int skel_open(struct inode *inode, struct file *file)
90 goto exit; 90 goto exit;
91 } 91 }
92 92
93 /* increment our usage count for the device */
94 kref_get(&dev->kref);
95
93 /* prevent the device from being autosuspended */ 96 /* prevent the device from being autosuspended */
94 retval = usb_autopm_get_interface(interface); 97 retval = usb_autopm_get_interface(interface);
95 if (retval) 98 if (retval) {
99 kref_put(&dev->kref, skel_delete);
96 goto exit; 100 goto exit;
97 101 }
98 /* increment our usage count for the device */
99 kref_get(&dev->kref);
100 102
101 /* save our object in the file's private structure */ 103 /* save our object in the file's private structure */
102 file->private_data = dev; 104 file->private_data = dev;