aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorJeff Garzik <jeff@garzik.org>2006-03-24 12:29:39 -0500
committerJeff Garzik <jeff@garzik.org>2006-03-24 12:29:39 -0500
commit4bbf7bc4c7bf1c80ec3c942fa5f1b6e6fa67dd99 (patch)
treec4ff89dc09abe69d58db1e14da22ecda9fdd3ce8 /drivers
parent84ac69e8bf9f36eb0166817373336d14fa58f5cc (diff)
parentaec5c3c1a929d7d79a420e943285cf3ba26a7c0d (diff)
Merge branch 'upstream'
Conflicts: drivers/scsi/libata-core.c
Diffstat (limited to 'drivers')
-rw-r--r--drivers/acpi/Kconfig12
-rw-r--r--drivers/acpi/ibm_acpi.c13
-rw-r--r--drivers/acpi/scan.c5
-rw-r--r--drivers/base/power/suspend.c5
-rw-r--r--drivers/block/Makefile1
-rw-r--r--drivers/block/cciss.c4
-rw-r--r--drivers/block/floppy.c17
-rw-r--r--drivers/block/loop.c18
-rw-r--r--drivers/block/nbd.c16
-rw-r--r--drivers/block/paride/comm.c16
-rw-r--r--drivers/block/paride/on26.c2
-rw-r--r--drivers/block/pktcdvd.c27
-rw-r--r--drivers/block/rd.c7
-rw-r--r--drivers/cdrom/cdrom.c874
-rw-r--r--drivers/cdrom/cdu31a.c8
-rw-r--r--drivers/cdrom/cm206.c44
-rw-r--r--drivers/cdrom/sbpcd.c710
-rw-r--r--drivers/cdrom/viocd.c2
-rw-r--r--drivers/char/Kconfig4
-rw-r--r--drivers/char/amiserial.c18
-rw-r--r--drivers/char/generic_serial.c14
-rw-r--r--drivers/char/hvcs.c9
-rw-r--r--drivers/char/ipmi/ipmi_poweroff.c4
-rw-r--r--drivers/char/istallion.c1
-rw-r--r--drivers/char/n_tty.c10
-rw-r--r--drivers/char/nwflash.c11
-rw-r--r--drivers/char/pcmcia/synclink_cs.c2
-rw-r--r--drivers/char/raw.c23
-rw-r--r--drivers/char/rio/Makefile2
-rw-r--r--drivers/char/rio/board.h58
-rw-r--r--drivers/char/rio/bootpkt.h61
-rw-r--r--drivers/char/rio/cirrus.h110
-rw-r--r--drivers/char/rio/cmdblk.h4
-rw-r--r--drivers/char/rio/cmdpkt.h94
-rw-r--r--drivers/char/rio/control.h61
-rw-r--r--drivers/char/rio/daemon.h67
-rw-r--r--drivers/char/rio/defaults.h51
-rw-r--r--drivers/char/rio/error.h82
-rw-r--r--drivers/char/rio/func.h52
-rw-r--r--drivers/char/rio/host.h56
-rw-r--r--drivers/char/rio/link.h124
-rw-r--r--drivers/char/rio/linux_compat.h45
-rw-r--r--drivers/char/rio/list.h56
-rw-r--r--drivers/char/rio/map.h12
-rw-r--r--drivers/char/rio/param.h24
-rw-r--r--drivers/char/rio/parmmap.h68
-rw-r--r--drivers/char/rio/phb.h39
-rw-r--r--drivers/char/rio/pkt.h24
-rw-r--r--drivers/char/rio/port.h250
-rw-r--r--drivers/char/rio/qbuf.h62
-rw-r--r--drivers/char/rio/rio.h173
-rw-r--r--drivers/char/rio/rio_linux.c139
-rw-r--r--drivers/char/rio/rioboot.c1688
-rw-r--r--drivers/char/rio/riocmd.c176
-rw-r--r--drivers/char/rio/rioctrl.c401
-rw-r--r--drivers/char/rio/riodrvr.h48
-rw-r--r--drivers/char/rio/rioinit.c199
-rw-r--r--drivers/char/rio/riointr.c320
-rw-r--r--drivers/char/rio/rioparam.c129
-rw-r--r--drivers/char/rio/riopcicopy.c8
-rw-r--r--drivers/char/rio/rioroute.c166
-rw-r--r--drivers/char/rio/riotable.c123
-rw-r--r--drivers/char/rio/riotty.c198
-rw-r--r--drivers/char/rio/riotypes.h68
-rw-r--r--drivers/char/rio/rom.h62
-rw-r--r--drivers/char/rio/rup.h25
-rw-r--r--drivers/char/rio/sam.h67
-rw-r--r--drivers/char/rio/space.h45
-rw-r--r--drivers/char/rio/top.h48
-rw-r--r--drivers/char/rio/typdef.h82
-rw-r--r--drivers/char/rio/unixrup.h6
-rw-r--r--drivers/char/ser_a2232.c4
-rw-r--r--drivers/char/snsc.c8
-rw-r--r--drivers/char/snsc_event.c5
-rw-r--r--drivers/char/stallion.c1
-rw-r--r--drivers/char/sx.c2
-rw-r--r--drivers/char/synclink.c2
-rw-r--r--drivers/char/synclink_gt.c2
-rw-r--r--drivers/char/synclinkmp.c2
-rw-r--r--drivers/char/toshiba.c38
-rw-r--r--drivers/char/tty_io.c50
-rw-r--r--drivers/char/vme_scc.c2
-rw-r--r--drivers/char/vt.c22
-rw-r--r--drivers/char/watchdog/pcwd_usb.c7
-rw-r--r--drivers/connector/connector.c15
-rw-r--r--drivers/firmware/dcdbas.c23
-rw-r--r--drivers/hwmon/Kconfig7
-rw-r--r--drivers/hwmon/adm1021.c13
-rw-r--r--drivers/hwmon/adm1025.c25
-rw-r--r--drivers/hwmon/adm1026.c92
-rw-r--r--drivers/hwmon/adm1031.c49
-rw-r--r--drivers/hwmon/adm9240.c29
-rw-r--r--drivers/hwmon/asb100.c45
-rw-r--r--drivers/hwmon/atxp1.c9
-rw-r--r--drivers/hwmon/ds1621.c13
-rw-r--r--drivers/hwmon/f71805f.c275
-rw-r--r--drivers/hwmon/fscher.c41
-rw-r--r--drivers/hwmon/fscpos.c33
-rw-r--r--drivers/hwmon/gl518sm.c25
-rw-r--r--drivers/hwmon/gl520sm.c47
-rw-r--r--drivers/hwmon/hdaps.c37
-rw-r--r--drivers/hwmon/hwmon-vid.c9
-rw-r--r--drivers/hwmon/hwmon.c26
-rw-r--r--drivers/hwmon/it87.c66
-rw-r--r--drivers/hwmon/lm63.c29
-rw-r--r--drivers/hwmon/lm75.c13
-rw-r--r--drivers/hwmon/lm77.c21
-rw-r--r--drivers/hwmon/lm78.c51
-rw-r--r--drivers/hwmon/lm80.c27
-rw-r--r--drivers/hwmon/lm83.c13
-rw-r--r--drivers/hwmon/lm85.c71
-rw-r--r--drivers/hwmon/lm87.c39
-rw-r--r--drivers/hwmon/lm90.c21
-rw-r--r--drivers/hwmon/lm92.c17
-rw-r--r--drivers/hwmon/max1619.c13
-rw-r--r--drivers/hwmon/pc87360.c469
-rw-r--r--drivers/hwmon/sis5595.c51
-rw-r--r--drivers/hwmon/smsc47b397.c17
-rw-r--r--drivers/hwmon/smsc47m1.c41
-rw-r--r--drivers/hwmon/via686a.c33
-rw-r--r--drivers/hwmon/vt8231.c51
-rw-r--r--drivers/hwmon/w83627ehf.c239
-rw-r--r--drivers/hwmon/w83627hf.c134
-rw-r--r--drivers/hwmon/w83781d.c82
-rw-r--r--drivers/hwmon/w83792d.c538
-rw-r--r--drivers/hwmon/w83l785ts.c9
-rw-r--r--drivers/i2c/busses/Kconfig11
-rw-r--r--drivers/i2c/busses/i2c-ali1535.c4
-rw-r--r--drivers/i2c/busses/i2c-amd756-s4882.c13
-rw-r--r--drivers/i2c/busses/i2c-frodo.c85
-rw-r--r--drivers/i2c/busses/i2c-isa.c2
-rw-r--r--drivers/i2c/busses/i2c-ite.c4
-rw-r--r--drivers/i2c/busses/i2c-ixp4xx.c1
-rw-r--r--drivers/i2c/busses/i2c-piix4.c4
-rw-r--r--drivers/i2c/busses/i2c-pxa.c2
-rw-r--r--drivers/i2c/busses/scx200_acb.c283
-rw-r--r--drivers/i2c/chips/ds1374.c11
-rw-r--r--drivers/i2c/chips/eeprom.c9
-rw-r--r--drivers/i2c/chips/isp1301_omap.c2
-rw-r--r--drivers/i2c/chips/m41t00.c11
-rw-r--r--drivers/i2c/chips/max6875.c10
-rw-r--r--drivers/i2c/chips/pcf8591.c13
-rw-r--r--drivers/i2c/chips/rtc8564.c2
-rw-r--r--drivers/i2c/chips/tps65010.c45
-rw-r--r--drivers/i2c/i2c-core.c81
-rw-r--r--drivers/ide/ide-cd.c110
-rw-r--r--drivers/ide/ide-disk.c13
-rw-r--r--drivers/ide/ide-dma.c2
-rw-r--r--drivers/ide/ide-floppy.c11
-rw-r--r--drivers/ide/ide-probe.c9
-rw-r--r--drivers/ide/ide-tape.c19
-rw-r--r--drivers/isdn/capi/kcapi.c17
-rw-r--r--drivers/isdn/hisax/config.c1
-rw-r--r--drivers/isdn/hisax/elsa.c1
-rw-r--r--drivers/macintosh/macio_asic.c5
-rw-r--r--drivers/macintosh/smu.c4
-rw-r--r--drivers/macintosh/therm_pm72.c2
-rw-r--r--drivers/macintosh/via-pmu.c5
-rw-r--r--drivers/macintosh/windfarm_lm75_sensor.c1
-rw-r--r--drivers/macintosh/windfarm_max6690_sensor.c1
-rw-r--r--drivers/macintosh/windfarm_smu_sat.c1
-rw-r--r--drivers/md/dm.c13
-rw-r--r--drivers/media/video/adv7170.c18
-rw-r--r--drivers/media/video/adv7175.c52
-rw-r--r--drivers/media/video/bt819.c18
-rw-r--r--drivers/media/video/bt856.c14
-rw-r--r--drivers/media/video/cpia.c2
-rw-r--r--drivers/media/video/saa7110.c20
-rw-r--r--drivers/media/video/saa7111.c27
-rw-r--r--drivers/media/video/saa7114.c24
-rw-r--r--drivers/media/video/saa711x.c1
-rw-r--r--drivers/media/video/saa7185.c18
-rw-r--r--drivers/media/video/vpx3220.c1
-rw-r--r--drivers/media/video/zoran.h2
-rw-r--r--drivers/media/video/zoran_card.c49
-rw-r--r--drivers/media/video/zoran_driver.c227
-rw-r--r--drivers/mfd/Kconfig1
-rw-r--r--drivers/mmc/Kconfig11
-rw-r--r--drivers/mmc/Makefile1
-rw-r--r--drivers/mmc/sdhci.c1265
-rw-r--r--drivers/mmc/sdhci.h185
-rw-r--r--drivers/net/8139too.c2
-rw-r--r--drivers/net/Kconfig1
-rw-r--r--drivers/net/bnx2.c108
-rw-r--r--drivers/net/bnx2.h62
-rw-r--r--drivers/net/hp-plus.c17
-rw-r--r--drivers/net/lance.c9
-rw-r--r--drivers/net/loopback.c4
-rw-r--r--drivers/net/ppp_generic.c25
-rw-r--r--drivers/net/sk98lin/skge.c2
-rw-r--r--drivers/net/skge.c105
-rw-r--r--drivers/net/skge.h1
-rw-r--r--drivers/net/sky2.c8
-rw-r--r--drivers/net/sky2.h2
-rw-r--r--drivers/net/tg3.c84
-rw-r--r--drivers/net/tg3.h9
-rw-r--r--drivers/net/wireless/Kconfig9
-rw-r--r--drivers/net/wireless/airo.c455
-rw-r--r--drivers/net/wireless/hostap/hostap_ap.c2
-rw-r--r--drivers/net/wireless/hostap/hostap_cs.c2
-rw-r--r--drivers/net/wireless/hostap/hostap_hw.c8
-rw-r--r--drivers/net/wireless/hostap/hostap_ioctl.c4
-rw-r--r--drivers/net/wireless/hostap/hostap_pci.c4
-rw-r--r--drivers/net/wireless/hostap/hostap_plx.c13
-rw-r--r--drivers/net/wireless/prism54/oid_mgt.c4
-rw-r--r--drivers/net/wireless/spectrum_cs.c2
-rw-r--r--drivers/oprofile/cpu_buffer.c3
-rw-r--r--drivers/pci/Kconfig21
-rw-r--r--drivers/pci/hotplug/Makefile20
-rw-r--r--drivers/pci/hotplug/acpi_pcihp.c (renamed from drivers/pci/hotplug/shpchprm_acpi.c)145
-rw-r--r--drivers/pci/hotplug/acpiphp.h62
-rw-r--r--drivers/pci/hotplug/acpiphp_core.c134
-rw-r--r--drivers/pci/hotplug/acpiphp_dock.c438
-rw-r--r--drivers/pci/hotplug/acpiphp_glue.c356
-rw-r--r--drivers/pci/hotplug/cpci_hotplug_core.c9
-rw-r--r--drivers/pci/hotplug/cpqphp.h3
-rw-r--r--drivers/pci/hotplug/cpqphp_core.c27
-rw-r--r--drivers/pci/hotplug/cpqphp_ctrl.c124
-rw-r--r--drivers/pci/hotplug/fakephp.c9
-rw-r--r--drivers/pci/hotplug/ibmphp.h2
-rw-r--r--drivers/pci/hotplug/ibmphp_core.c10
-rw-r--r--drivers/pci/hotplug/ibmphp_ebda.c59
-rw-r--r--drivers/pci/hotplug/ibmphp_hpc.c64
-rw-r--r--drivers/pci/hotplug/ibmphp_pci.c121
-rw-r--r--drivers/pci/hotplug/ibmphp_res.c81
-rw-r--r--drivers/pci/hotplug/pci_hotplug.h16
-rw-r--r--drivers/pci/hotplug/pciehp.h27
-rw-r--r--drivers/pci/hotplug/pciehp_core.c19
-rw-r--r--drivers/pci/hotplug/pciehp_ctrl.c68
-rw-r--r--drivers/pci/hotplug/pciehp_hpc.c77
-rw-r--r--drivers/pci/hotplug/pciehprm_acpi.c257
-rw-r--r--drivers/pci/hotplug/pciehprm_nonacpi.c47
-rw-r--r--drivers/pci/hotplug/pcihp_skeleton.c33
-rw-r--r--drivers/pci/hotplug/rpaphp_slot.c9
-rw-r--r--drivers/pci/hotplug/sgi_hotplug.c16
-rw-r--r--drivers/pci/hotplug/shpchp.h108
-rw-r--r--drivers/pci/hotplug/shpchp_core.c331
-rw-r--r--drivers/pci/hotplug/shpchp_ctrl.c808
-rw-r--r--drivers/pci/hotplug/shpchp_hpc.c518
-rw-r--r--drivers/pci/hotplug/shpchp_pci.c10
-rw-r--r--drivers/pci/hotplug/shpchprm_legacy.c54
-rw-r--r--drivers/pci/hotplug/shpchprm_nonacpi.c57
-rw-r--r--drivers/pci/msi.c105
-rw-r--r--drivers/pci/pci-driver.c12
-rw-r--r--drivers/pci/pci-sysfs.c3
-rw-r--r--drivers/pci/pci.c22
-rw-r--r--drivers/pci/pci.h2
-rw-r--r--drivers/pci/pcie/portdrv.h1
-rw-r--r--drivers/pci/pcie/portdrv_core.c3
-rw-r--r--drivers/pci/pcie/portdrv_pci.c66
-rw-r--r--drivers/pci/probe.c34
-rw-r--r--drivers/pci/proc.c126
-rw-r--r--drivers/pci/quirks.c71
-rw-r--r--drivers/pci/search.c4
-rw-r--r--drivers/pnp/pnpbios/rsparser.c6
-rw-r--r--drivers/s390/Kconfig8
-rw-r--r--drivers/s390/block/Kconfig14
-rw-r--r--drivers/s390/block/Makefile4
-rw-r--r--drivers/s390/block/dasd.c41
-rw-r--r--drivers/s390/block/dasd_3990_erp.c3
-rw-r--r--drivers/s390/block/dasd_cmb.c128
-rw-r--r--drivers/s390/block/dasd_devmap.c41
-rw-r--r--drivers/s390/block/dasd_eckd.c142
-rw-r--r--drivers/s390/block/dasd_eckd.h1
-rw-r--r--drivers/s390/block/dasd_eer.c682
-rw-r--r--drivers/s390/block/dasd_int.h60
-rw-r--r--drivers/s390/block/dasd_ioctl.c322
-rw-r--r--drivers/s390/block/dcssblk.c3
-rw-r--r--drivers/s390/char/Makefile1
-rw-r--r--drivers/s390/char/fs3270.c3
-rw-r--r--drivers/s390/char/keyboard.c12
-rw-r--r--drivers/s390/char/monreader.c6
-rw-r--r--drivers/s390/char/raw3270.c3
-rw-r--r--drivers/s390/char/tape.h1
-rw-r--r--drivers/s390/char/tape_34xx.c8
-rw-r--r--drivers/s390/char/tape_3590.c1301
-rw-r--r--drivers/s390/char/tape_3590.h124
-rw-r--r--drivers/s390/char/tape_class.c3
-rw-r--r--drivers/s390/char/tape_core.c57
-rw-r--r--drivers/s390/char/tape_std.c15
-rw-r--r--drivers/s390/char/tape_std.h12
-rw-r--r--drivers/s390/char/tty3270.c9
-rw-r--r--drivers/s390/char/vmlogrdr.c3
-rw-r--r--drivers/s390/cio/ccwgroup.c3
-rw-r--r--drivers/s390/cio/chsc.c457
-rw-r--r--drivers/s390/cio/chsc.h22
-rw-r--r--drivers/s390/cio/css.c44
-rw-r--r--drivers/s390/cio/css.h6
-rw-r--r--drivers/s390/cio/device.c6
-rw-r--r--drivers/s390/cio/device_fsm.c12
-rw-r--r--drivers/s390/cio/device_ops.c9
-rw-r--r--drivers/s390/cio/qdio.c20
-rw-r--r--drivers/s390/crypto/z90hardware.c10
-rw-r--r--drivers/s390/crypto/z90main.c15
-rw-r--r--drivers/s390/net/claw.c3
-rw-r--r--drivers/s390/net/fsm.c10
-rw-r--r--drivers/s390/net/iucv.c11
-rw-r--r--drivers/s390/net/lcs.c11
-rw-r--r--drivers/s390/net/netiucv.c7
-rw-r--r--drivers/s390/net/qeth_eddp.c13
-rw-r--r--drivers/s390/net/qeth_main.c20
-rw-r--r--drivers/s390/net/qeth_sys.c3
-rw-r--r--drivers/s390/s390_rdev.c3
-rw-r--r--drivers/scsi/ata_piix.c6
-rw-r--r--drivers/scsi/g_NCR5380.c28
-rw-r--r--drivers/scsi/g_NCR5380.h23
-rw-r--r--drivers/scsi/ide-scsi.c11
-rw-r--r--drivers/scsi/in2000.c24
-rw-r--r--drivers/scsi/libata-bmdma.c4
-rw-r--r--drivers/scsi/libata-core.c333
-rw-r--r--drivers/scsi/libata-scsi.c79
-rw-r--r--drivers/scsi/megaraid/megaraid_mbox.c2
-rw-r--r--drivers/scsi/sata_sil.c2
-rw-r--r--drivers/scsi/sata_sil24.c2
-rw-r--r--drivers/scsi/sata_vsc.c4
-rw-r--r--drivers/scsi/scsi_sysfs.c2
-rw-r--r--drivers/scsi/sr.c37
-rw-r--r--drivers/scsi/sr.h1
-rw-r--r--drivers/scsi/sr_ioctl.c19
-rw-r--r--drivers/serial/68328serial.c9
-rw-r--r--drivers/serial/au1x00_uart.c11
-rw-r--r--drivers/serial/crisv10.c68
-rw-r--r--drivers/serial/m32r_sio.c15
-rw-r--r--drivers/serial/sunsu.c13
-rw-r--r--drivers/tc/zs.c9
-rw-r--r--drivers/usb/image/microtek.c2
-rw-r--r--drivers/usb/input/hid-core.c2
-rw-r--r--drivers/video/aty/radeon_pm.c2
-rw-r--r--drivers/w1/Kconfig60
-rw-r--r--drivers/w1/Makefile10
-rw-r--r--drivers/w1/masters/Kconfig48
-rw-r--r--drivers/w1/masters/Makefile13
-rw-r--r--drivers/w1/masters/ds2482.c564
-rw-r--r--drivers/w1/masters/ds_w1_bridge.c (renamed from drivers/w1/ds_w1_bridge.c)38
-rw-r--r--drivers/w1/masters/dscore.c (renamed from drivers/w1/dscore.c)4
-rw-r--r--drivers/w1/masters/dscore.h (renamed from drivers/w1/dscore.h)0
-rw-r--r--drivers/w1/masters/matrox_w1.c (renamed from drivers/w1/matrox_w1.c)22
-rw-r--r--drivers/w1/slaves/Kconfig38
-rw-r--r--drivers/w1/slaves/Makefile12
-rw-r--r--drivers/w1/slaves/w1_ds2433.c (renamed from drivers/w1/w1_ds2433.c)8
-rw-r--r--drivers/w1/slaves/w1_smem.c (renamed from drivers/w1/w1_smem.c)10
-rw-r--r--drivers/w1/slaves/w1_therm.c (renamed from drivers/w1/w1_therm.c)14
-rw-r--r--drivers/w1/w1.c77
-rw-r--r--drivers/w1/w1.h37
-rw-r--r--drivers/w1/w1_family.c2
-rw-r--r--drivers/w1/w1_int.c49
-rw-r--r--drivers/w1/w1_io.c2
347 files changed, 13188 insertions, 10957 deletions
diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig
index 33e2ca847a..82710ae392 100644
--- a/drivers/acpi/Kconfig
+++ b/drivers/acpi/Kconfig
@@ -205,6 +205,18 @@ config ACPI_IBM
205 205
206 If you have an IBM ThinkPad laptop, say Y or M here. 206 If you have an IBM ThinkPad laptop, say Y or M here.
207 207
208config ACPI_IBM_DOCK
209 bool "Legacy Docking Station Support"
210 depends on ACPI_IBM
211 default n
212 ---help---
213 Allows the ibm_acpi driver to handle docking station events.
214 This support is obsoleted by CONFIG_HOTPLUG_PCI_ACPI. It will
215 allow locking and removing the laptop from the docking station,
216 but will not properly connect PCI devices.
217
218 If you are not sure, say N here.
219
208config ACPI_TOSHIBA 220config ACPI_TOSHIBA
209 tristate "Toshiba Laptop Extras" 221 tristate "Toshiba Laptop Extras"
210 depends on X86 222 depends on X86
diff --git a/drivers/acpi/ibm_acpi.c b/drivers/acpi/ibm_acpi.c
index 5cc090326d..262b1f4133 100644
--- a/drivers/acpi/ibm_acpi.c
+++ b/drivers/acpi/ibm_acpi.c
@@ -160,13 +160,13 @@ IBM_HANDLE(cmos, root, "\\UCMS", /* R50, R50e, R50p, R51, T4x, X31, X40 */
160 "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */ 160 "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */
161 "\\CMS", /* R40, R40e */ 161 "\\CMS", /* R40, R40e */
162 ); /* all others */ 162 ); /* all others */
163 163#ifdef CONFIG_ACPI_IBM_DOCK
164IBM_HANDLE(dock, root, "\\_SB.GDCK", /* X30, X31, X40 */ 164IBM_HANDLE(dock, root, "\\_SB.GDCK", /* X30, X31, X40 */
165 "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */ 165 "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */
166 "\\_SB.PCI0.PCI1.DOCK", /* all others */ 166 "\\_SB.PCI0.PCI1.DOCK", /* all others */
167 "\\_SB.PCI.ISA.SLCE", /* 570 */ 167 "\\_SB.PCI.ISA.SLCE", /* 570 */
168 ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */ 168 ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */
169 169#endif
170IBM_HANDLE(bay, root, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */ 170IBM_HANDLE(bay, root, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */
171 "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */ 171 "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */
172 "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */ 172 "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */
@@ -844,7 +844,7 @@ static int _sta(acpi_handle handle)
844 844
845 return status; 845 return status;
846} 846}
847 847#ifdef CONFIG_ACPI_IBM_DOCK
848#define dock_docked() (_sta(dock_handle) & 1) 848#define dock_docked() (_sta(dock_handle) & 1)
849 849
850static int dock_read(char *p) 850static int dock_read(char *p)
@@ -907,6 +907,7 @@ static void dock_notify(struct ibm_struct *ibm, u32 event)
907 acpi_bus_generate_event(ibm->device, event, 0); /* unknown */ 907 acpi_bus_generate_event(ibm->device, event, 0); /* unknown */
908 } 908 }
909} 909}
910#endif
910 911
911static int bay_status_supported; 912static int bay_status_supported;
912static int bay_status2_supported; 913static int bay_status2_supported;
@@ -1574,6 +1575,7 @@ static struct ibm_struct ibms[] = {
1574 .read = light_read, 1575 .read = light_read,
1575 .write = light_write, 1576 .write = light_write,
1576 }, 1577 },
1578#ifdef CONFIG_ACPI_IBM_DOCK
1577 { 1579 {
1578 .name = "dock", 1580 .name = "dock",
1579 .read = dock_read, 1581 .read = dock_read,
@@ -1589,6 +1591,7 @@ static struct ibm_struct ibms[] = {
1589 .handle = &pci_handle, 1591 .handle = &pci_handle,
1590 .type = ACPI_SYSTEM_NOTIFY, 1592 .type = ACPI_SYSTEM_NOTIFY,
1591 }, 1593 },
1594#endif
1592 { 1595 {
1593 .name = "bay", 1596 .name = "bay",
1594 .init = bay_init, 1597 .init = bay_init,
@@ -1880,7 +1883,9 @@ IBM_PARAM(hotkey);
1880IBM_PARAM(bluetooth); 1883IBM_PARAM(bluetooth);
1881IBM_PARAM(video); 1884IBM_PARAM(video);
1882IBM_PARAM(light); 1885IBM_PARAM(light);
1886#ifdef CONFIG_ACPI_IBM_DOCK
1883IBM_PARAM(dock); 1887IBM_PARAM(dock);
1888#endif
1884IBM_PARAM(bay); 1889IBM_PARAM(bay);
1885IBM_PARAM(cmos); 1890IBM_PARAM(cmos);
1886IBM_PARAM(led); 1891IBM_PARAM(led);
@@ -1927,7 +1932,9 @@ static int __init acpi_ibm_init(void)
1927 IBM_HANDLE_INIT(hkey); 1932 IBM_HANDLE_INIT(hkey);
1928 IBM_HANDLE_INIT(lght); 1933 IBM_HANDLE_INIT(lght);
1929 IBM_HANDLE_INIT(cmos); 1934 IBM_HANDLE_INIT(cmos);
1935#ifdef CONFIG_ACPI_IBM_DOCK
1930 IBM_HANDLE_INIT(dock); 1936 IBM_HANDLE_INIT(dock);
1937#endif
1931 IBM_HANDLE_INIT(pci); 1938 IBM_HANDLE_INIT(pci);
1932 IBM_HANDLE_INIT(bay); 1939 IBM_HANDLE_INIT(bay);
1933 if (bay_handle) 1940 if (bay_handle)
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index 9271e5209a..a0ab828b2c 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -23,7 +23,6 @@ static LIST_HEAD(acpi_device_list);
23DEFINE_SPINLOCK(acpi_device_lock); 23DEFINE_SPINLOCK(acpi_device_lock);
24LIST_HEAD(acpi_wakeup_device_list); 24LIST_HEAD(acpi_wakeup_device_list);
25 25
26static int acpi_bus_trim(struct acpi_device *start, int rmdevice);
27 26
28static void acpi_device_release(struct kobject *kobj) 27static void acpi_device_release(struct kobject *kobj)
29{ 28{
@@ -1284,7 +1283,7 @@ int acpi_bus_start(struct acpi_device *device)
1284 1283
1285EXPORT_SYMBOL(acpi_bus_start); 1284EXPORT_SYMBOL(acpi_bus_start);
1286 1285
1287static int acpi_bus_trim(struct acpi_device *start, int rmdevice) 1286int acpi_bus_trim(struct acpi_device *start, int rmdevice)
1288{ 1287{
1289 acpi_status status; 1288 acpi_status status;
1290 struct acpi_device *parent, *child; 1289 struct acpi_device *parent, *child;
@@ -1337,6 +1336,8 @@ static int acpi_bus_trim(struct acpi_device *start, int rmdevice)
1337 } 1336 }
1338 return err; 1337 return err;
1339} 1338}
1339EXPORT_SYMBOL_GPL(acpi_bus_trim);
1340
1340 1341
1341static int acpi_bus_scan_fixed(struct acpi_device *root) 1342static int acpi_bus_scan_fixed(struct acpi_device *root)
1342{ 1343{
diff --git a/drivers/base/power/suspend.c b/drivers/base/power/suspend.c
index 8660779fb2..bdb60663f2 100644
--- a/drivers/base/power/suspend.c
+++ b/drivers/base/power/suspend.c
@@ -8,6 +8,7 @@
8 * 8 *
9 */ 9 */
10 10
11#include <linux/vt_kern.h>
11#include <linux/device.h> 12#include <linux/device.h>
12#include "../base.h" 13#include "../base.h"
13#include "power.h" 14#include "power.h"
@@ -62,7 +63,6 @@ int suspend_device(struct device * dev, pm_message_t state)
62 return error; 63 return error;
63} 64}
64 65
65
66/** 66/**
67 * device_suspend - Save state and stop all devices in system. 67 * device_suspend - Save state and stop all devices in system.
68 * @state: Power state to put each device in. 68 * @state: Power state to put each device in.
@@ -82,6 +82,9 @@ int device_suspend(pm_message_t state)
82{ 82{
83 int error = 0; 83 int error = 0;
84 84
85 if (!is_console_suspend_safe())
86 return -EINVAL;
87
85 down(&dpm_sem); 88 down(&dpm_sem);
86 down(&dpm_list_sem); 89 down(&dpm_list_sem);
87 while (!list_empty(&dpm_active) && error == 0) { 90 while (!list_empty(&dpm_active) && error == 0) {
diff --git a/drivers/block/Makefile b/drivers/block/Makefile
index 3ec1f8df87..410f259a80 100644
--- a/drivers/block/Makefile
+++ b/drivers/block/Makefile
@@ -7,7 +7,6 @@
7 7
8obj-$(CONFIG_MAC_FLOPPY) += swim3.o 8obj-$(CONFIG_MAC_FLOPPY) += swim3.o
9obj-$(CONFIG_BLK_DEV_FD) += floppy.o 9obj-$(CONFIG_BLK_DEV_FD) += floppy.o
10obj-$(CONFIG_BLK_DEV_FD98) += floppy98.o
11obj-$(CONFIG_AMIGA_FLOPPY) += amiflop.o 10obj-$(CONFIG_AMIGA_FLOPPY) += amiflop.o
12obj-$(CONFIG_ATARI_FLOPPY) += ataflop.o 11obj-$(CONFIG_ATARI_FLOPPY) += ataflop.o
13obj-$(CONFIG_BLK_DEV_SWIM_IOP) += swim_iop.o 12obj-$(CONFIG_BLK_DEV_SWIM_IOP) += swim_iop.o
diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
index cf39cf9aac..1f2890989b 100644
--- a/drivers/block/cciss.c
+++ b/drivers/block/cciss.c
@@ -38,6 +38,7 @@
38#include <linux/hdreg.h> 38#include <linux/hdreg.h>
39#include <linux/spinlock.h> 39#include <linux/spinlock.h>
40#include <linux/compat.h> 40#include <linux/compat.h>
41#include <linux/blktrace_api.h>
41#include <asm/uaccess.h> 42#include <asm/uaccess.h>
42#include <asm/io.h> 43#include <asm/io.h>
43 44
@@ -2331,6 +2332,7 @@ static inline void complete_command( ctlr_info_t *h, CommandList_struct *cmd,
2331 2332
2332 cmd->rq->completion_data = cmd; 2333 cmd->rq->completion_data = cmd;
2333 cmd->rq->errors = status; 2334 cmd->rq->errors = status;
2335 blk_add_trace_rq(cmd->rq->q, cmd->rq, BLK_TA_COMPLETE);
2334 blk_complete_request(cmd->rq); 2336 blk_complete_request(cmd->rq);
2335} 2337}
2336 2338
@@ -3268,8 +3270,8 @@ clean2:
3268 unregister_blkdev(hba[i]->major, hba[i]->devname); 3270 unregister_blkdev(hba[i]->major, hba[i]->devname);
3269clean1: 3271clean1:
3270 release_io_mem(hba[i]); 3272 release_io_mem(hba[i]);
3271 free_hba(i);
3272 hba[i]->busy_initializing = 0; 3273 hba[i]->busy_initializing = 0;
3274 free_hba(i);
3273 return(-1); 3275 return(-1);
3274} 3276}
3275 3277
diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index d23b54332d..fb2d0be7cd 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -179,6 +179,7 @@ static int print_unex = 1;
179#include <linux/devfs_fs_kernel.h> 179#include <linux/devfs_fs_kernel.h>
180#include <linux/platform_device.h> 180#include <linux/platform_device.h>
181#include <linux/buffer_head.h> /* for invalidate_buffers() */ 181#include <linux/buffer_head.h> /* for invalidate_buffers() */
182#include <linux/mutex.h>
182 183
183/* 184/*
184 * PS/2 floppies have much slower step rates than regular floppies. 185 * PS/2 floppies have much slower step rates than regular floppies.
@@ -413,7 +414,7 @@ static struct floppy_write_errors write_errors[N_DRIVE];
413static struct timer_list motor_off_timer[N_DRIVE]; 414static struct timer_list motor_off_timer[N_DRIVE];
414static struct gendisk *disks[N_DRIVE]; 415static struct gendisk *disks[N_DRIVE];
415static struct block_device *opened_bdev[N_DRIVE]; 416static struct block_device *opened_bdev[N_DRIVE];
416static DECLARE_MUTEX(open_lock); 417static DEFINE_MUTEX(open_lock);
417static struct floppy_raw_cmd *raw_cmd, default_raw_cmd; 418static struct floppy_raw_cmd *raw_cmd, default_raw_cmd;
418 419
419/* 420/*
@@ -3333,7 +3334,7 @@ static inline int set_geometry(unsigned int cmd, struct floppy_struct *g,
3333 if (type) { 3334 if (type) {
3334 if (!capable(CAP_SYS_ADMIN)) 3335 if (!capable(CAP_SYS_ADMIN))
3335 return -EPERM; 3336 return -EPERM;
3336 down(&open_lock); 3337 mutex_lock(&open_lock);
3337 LOCK_FDC(drive, 1); 3338 LOCK_FDC(drive, 1);
3338 floppy_type[type] = *g; 3339 floppy_type[type] = *g;
3339 floppy_type[type].name = "user format"; 3340 floppy_type[type].name = "user format";
@@ -3347,7 +3348,7 @@ static inline int set_geometry(unsigned int cmd, struct floppy_struct *g,
3347 continue; 3348 continue;
3348 __invalidate_device(bdev); 3349 __invalidate_device(bdev);
3349 } 3350 }
3350 up(&open_lock); 3351 mutex_unlock(&open_lock);
3351 } else { 3352 } else {
3352 int oldStretch; 3353 int oldStretch;
3353 LOCK_FDC(drive, 1); 3354 LOCK_FDC(drive, 1);
@@ -3674,7 +3675,7 @@ static int floppy_release(struct inode *inode, struct file *filp)
3674{ 3675{
3675 int drive = (long)inode->i_bdev->bd_disk->private_data; 3676 int drive = (long)inode->i_bdev->bd_disk->private_data;
3676 3677
3677 down(&open_lock); 3678 mutex_lock(&open_lock);
3678 if (UDRS->fd_ref < 0) 3679 if (UDRS->fd_ref < 0)
3679 UDRS->fd_ref = 0; 3680 UDRS->fd_ref = 0;
3680 else if (!UDRS->fd_ref--) { 3681 else if (!UDRS->fd_ref--) {
@@ -3684,7 +3685,7 @@ static int floppy_release(struct inode *inode, struct file *filp)
3684 if (!UDRS->fd_ref) 3685 if (!UDRS->fd_ref)
3685 opened_bdev[drive] = NULL; 3686 opened_bdev[drive] = NULL;
3686 floppy_release_irq_and_dma(); 3687 floppy_release_irq_and_dma();
3687 up(&open_lock); 3688 mutex_unlock(&open_lock);
3688 return 0; 3689 return 0;
3689} 3690}
3690 3691
@@ -3702,7 +3703,7 @@ static int floppy_open(struct inode *inode, struct file *filp)
3702 char *tmp; 3703 char *tmp;
3703 3704
3704 filp->private_data = (void *)0; 3705 filp->private_data = (void *)0;
3705 down(&open_lock); 3706 mutex_lock(&open_lock);
3706 old_dev = UDRS->fd_device; 3707 old_dev = UDRS->fd_device;
3707 if (opened_bdev[drive] && opened_bdev[drive] != inode->i_bdev) 3708 if (opened_bdev[drive] && opened_bdev[drive] != inode->i_bdev)
3708 goto out2; 3709 goto out2;
@@ -3785,7 +3786,7 @@ static int floppy_open(struct inode *inode, struct file *filp)
3785 if ((filp->f_mode & 2) && !(UTESTF(FD_DISK_WRITABLE))) 3786 if ((filp->f_mode & 2) && !(UTESTF(FD_DISK_WRITABLE)))
3786 goto out; 3787 goto out;
3787 } 3788 }
3788 up(&open_lock); 3789 mutex_unlock(&open_lock);
3789 return 0; 3790 return 0;
3790out: 3791out:
3791 if (UDRS->fd_ref < 0) 3792 if (UDRS->fd_ref < 0)
@@ -3796,7 +3797,7 @@ out:
3796 opened_bdev[drive] = NULL; 3797 opened_bdev[drive] = NULL;
3797 floppy_release_irq_and_dma(); 3798 floppy_release_irq_and_dma();
3798out2: 3799out2:
3799 up(&open_lock); 3800 mutex_unlock(&open_lock);
3800 return res; 3801 return res;
3801} 3802}
3802 3803
diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index 0010704739..74bf0255e9 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -1144,7 +1144,7 @@ static int lo_ioctl(struct inode * inode, struct file * file,
1144 struct loop_device *lo = inode->i_bdev->bd_disk->private_data; 1144 struct loop_device *lo = inode->i_bdev->bd_disk->private_data;
1145 int err; 1145 int err;
1146 1146
1147 down(&lo->lo_ctl_mutex); 1147 mutex_lock(&lo->lo_ctl_mutex);
1148 switch (cmd) { 1148 switch (cmd) {
1149 case LOOP_SET_FD: 1149 case LOOP_SET_FD:
1150 err = loop_set_fd(lo, file, inode->i_bdev, arg); 1150 err = loop_set_fd(lo, file, inode->i_bdev, arg);
@@ -1170,7 +1170,7 @@ static int lo_ioctl(struct inode * inode, struct file * file,
1170 default: 1170 default:
1171 err = lo->ioctl ? lo->ioctl(lo, cmd, arg) : -EINVAL; 1171 err = lo->ioctl ? lo->ioctl(lo, cmd, arg) : -EINVAL;
1172 } 1172 }
1173 up(&lo->lo_ctl_mutex); 1173 mutex_unlock(&lo->lo_ctl_mutex);
1174 return err; 1174 return err;
1175} 1175}
1176 1176
@@ -1178,9 +1178,9 @@ static int lo_open(struct inode *inode, struct file *file)
1178{ 1178{
1179 struct loop_device *lo = inode->i_bdev->bd_disk->private_data; 1179 struct loop_device *lo = inode->i_bdev->bd_disk->private_data;
1180 1180
1181 down(&lo->lo_ctl_mutex); 1181 mutex_lock(&lo->lo_ctl_mutex);
1182 lo->lo_refcnt++; 1182 lo->lo_refcnt++;
1183 up(&lo->lo_ctl_mutex); 1183 mutex_unlock(&lo->lo_ctl_mutex);
1184 1184
1185 return 0; 1185 return 0;
1186} 1186}
@@ -1189,9 +1189,9 @@ static int lo_release(struct inode *inode, struct file *file)
1189{ 1189{
1190 struct loop_device *lo = inode->i_bdev->bd_disk->private_data; 1190 struct loop_device *lo = inode->i_bdev->bd_disk->private_data;
1191 1191
1192 down(&lo->lo_ctl_mutex); 1192 mutex_lock(&lo->lo_ctl_mutex);
1193 --lo->lo_refcnt; 1193 --lo->lo_refcnt;
1194 up(&lo->lo_ctl_mutex); 1194 mutex_unlock(&lo->lo_ctl_mutex);
1195 1195
1196 return 0; 1196 return 0;
1197} 1197}
@@ -1233,12 +1233,12 @@ int loop_unregister_transfer(int number)
1233 xfer_funcs[n] = NULL; 1233 xfer_funcs[n] = NULL;
1234 1234
1235 for (lo = &loop_dev[0]; lo < &loop_dev[max_loop]; lo++) { 1235 for (lo = &loop_dev[0]; lo < &loop_dev[max_loop]; lo++) {
1236 down(&lo->lo_ctl_mutex); 1236 mutex_lock(&lo->lo_ctl_mutex);
1237 1237
1238 if (lo->lo_encryption == xfer) 1238 if (lo->lo_encryption == xfer)
1239 loop_release_xfer(lo); 1239 loop_release_xfer(lo);
1240 1240
1241 up(&lo->lo_ctl_mutex); 1241 mutex_unlock(&lo->lo_ctl_mutex);
1242 } 1242 }
1243 1243
1244 return 0; 1244 return 0;
@@ -1285,7 +1285,7 @@ static int __init loop_init(void)
1285 lo->lo_queue = blk_alloc_queue(GFP_KERNEL); 1285 lo->lo_queue = blk_alloc_queue(GFP_KERNEL);
1286 if (!lo->lo_queue) 1286 if (!lo->lo_queue)
1287 goto out_mem4; 1287 goto out_mem4;
1288 init_MUTEX(&lo->lo_ctl_mutex); 1288 mutex_init(&lo->lo_ctl_mutex);
1289 init_completion(&lo->lo_done); 1289 init_completion(&lo->lo_done);
1290 init_completion(&lo->lo_bh_done); 1290 init_completion(&lo->lo_bh_done);
1291 lo->lo_number = i; 1291 lo->lo_number = i;
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index 6997d8e6bf..a9bde30dad 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -459,9 +459,9 @@ static void do_nbd_request(request_queue_t * q)
459 req->errors = 0; 459 req->errors = 0;
460 spin_unlock_irq(q->queue_lock); 460 spin_unlock_irq(q->queue_lock);
461 461
462 down(&lo->tx_lock); 462 mutex_lock(&lo->tx_lock);
463 if (unlikely(!lo->sock)) { 463 if (unlikely(!lo->sock)) {
464 up(&lo->tx_lock); 464 mutex_unlock(&lo->tx_lock);
465 printk(KERN_ERR "%s: Attempted send on closed socket\n", 465 printk(KERN_ERR "%s: Attempted send on closed socket\n",
466 lo->disk->disk_name); 466 lo->disk->disk_name);
467 req->errors++; 467 req->errors++;
@@ -484,7 +484,7 @@ static void do_nbd_request(request_queue_t * q)
484 } 484 }
485 485
486 lo->active_req = NULL; 486 lo->active_req = NULL;
487 up(&lo->tx_lock); 487 mutex_unlock(&lo->tx_lock);
488 wake_up_all(&lo->active_wq); 488 wake_up_all(&lo->active_wq);
489 489
490 spin_lock_irq(q->queue_lock); 490 spin_lock_irq(q->queue_lock);
@@ -534,9 +534,9 @@ static int nbd_ioctl(struct inode *inode, struct file *file,
534 534
535 case NBD_CLEAR_SOCK: 535 case NBD_CLEAR_SOCK:
536 error = 0; 536 error = 0;
537 down(&lo->tx_lock); 537 mutex_lock(&lo->tx_lock);
538 lo->sock = NULL; 538 lo->sock = NULL;
539 up(&lo->tx_lock); 539 mutex_unlock(&lo->tx_lock);
540 file = lo->file; 540 file = lo->file;
541 lo->file = NULL; 541 lo->file = NULL;
542 nbd_clear_que(lo); 542 nbd_clear_que(lo);
@@ -590,7 +590,7 @@ static int nbd_ioctl(struct inode *inode, struct file *file,
590 * FIXME: This code is duplicated from sys_shutdown, but 590 * FIXME: This code is duplicated from sys_shutdown, but
591 * there should be a more generic interface rather than 591 * there should be a more generic interface rather than
592 * calling socket ops directly here */ 592 * calling socket ops directly here */
593 down(&lo->tx_lock); 593 mutex_lock(&lo->tx_lock);
594 if (lo->sock) { 594 if (lo->sock) {
595 printk(KERN_WARNING "%s: shutting down socket\n", 595 printk(KERN_WARNING "%s: shutting down socket\n",
596 lo->disk->disk_name); 596 lo->disk->disk_name);
@@ -598,7 +598,7 @@ static int nbd_ioctl(struct inode *inode, struct file *file,
598 SEND_SHUTDOWN|RCV_SHUTDOWN); 598 SEND_SHUTDOWN|RCV_SHUTDOWN);
599 lo->sock = NULL; 599 lo->sock = NULL;
600 } 600 }
601 up(&lo->tx_lock); 601 mutex_unlock(&lo->tx_lock);
602 file = lo->file; 602 file = lo->file;
603 lo->file = NULL; 603 lo->file = NULL;
604 nbd_clear_que(lo); 604 nbd_clear_que(lo);
@@ -683,7 +683,7 @@ static int __init nbd_init(void)
683 nbd_dev[i].flags = 0; 683 nbd_dev[i].flags = 0;
684 spin_lock_init(&nbd_dev[i].queue_lock); 684 spin_lock_init(&nbd_dev[i].queue_lock);
685 INIT_LIST_HEAD(&nbd_dev[i].queue_head); 685 INIT_LIST_HEAD(&nbd_dev[i].queue_head);
686 init_MUTEX(&nbd_dev[i].tx_lock); 686 mutex_init(&nbd_dev[i].tx_lock);
687 init_waitqueue_head(&nbd_dev[i].active_wq); 687 init_waitqueue_head(&nbd_dev[i].active_wq);
688 nbd_dev[i].blksize = 1024; 688 nbd_dev[i].blksize = 1024;
689 nbd_dev[i].bytesize = 0x7ffffc00ULL << 10; /* 2TB */ 689 nbd_dev[i].bytesize = 0x7ffffc00ULL << 10; /* 2TB */
diff --git a/drivers/block/paride/comm.c b/drivers/block/paride/comm.c
index d842956edf..43d61359d8 100644
--- a/drivers/block/paride/comm.c
+++ b/drivers/block/paride/comm.c
@@ -60,7 +60,7 @@ static int comm_read_regr( PIA *pi, int cont, int regr )
60 60
61 case 2: 61 case 2:
62 case 3: 62 case 3:
63 case 4: w3(r+0x20); r1(); 63 case 4: w3(r+0x20); (void)r1();
64 w2(0x24); h = r4(); w2(4); 64 w2(0x24); h = r4(); w2(4);
65 return h; 65 return h;
66 66
@@ -82,7 +82,7 @@ static void comm_write_regr( PIA *pi, int cont, int regr, int val )
82 82
83 case 2: 83 case 2:
84 case 3: 84 case 3:
85 case 4: w3(r); r1(); w4(val); 85 case 4: w3(r); (void)r1(); w4(val);
86 break; 86 break;
87 } 87 }
88} 88}
@@ -126,17 +126,17 @@ static void comm_read_block( PIA *pi, char * buf, int count )
126 w2(4); 126 w2(4);
127 break; 127 break;
128 128
129 case 2: w3(0x68); r1(); w2(0x24); 129 case 2: w3(0x68); (void)r1(); w2(0x24);
130 for (i=0;i<count;i++) buf[i] = r4(); 130 for (i=0;i<count;i++) buf[i] = r4();
131 w2(4); 131 w2(4);
132 break; 132 break;
133 133
134 case 3: w3(0x68); r1(); w2(0x24); 134 case 3: w3(0x68); (void)r1(); w2(0x24);
135 for (i=0;i<count/2;i++) ((u16 *)buf)[i] = r4w(); 135 for (i=0;i<count/2;i++) ((u16 *)buf)[i] = r4w();
136 w2(4); 136 w2(4);
137 break; 137 break;
138 138
139 case 4: w3(0x68); r1(); w2(0x24); 139 case 4: w3(0x68); (void)r1(); w2(0x24);
140 for (i=0;i<count/4;i++) ((u32 *)buf)[i] = r4l(); 140 for (i=0;i<count/4;i++) ((u32 *)buf)[i] = r4l();
141 w2(4); 141 w2(4);
142 break; 142 break;
@@ -160,15 +160,15 @@ static void comm_write_block( PIA *pi, char * buf, int count )
160 w2(5); w2(4); 160 w2(5); w2(4);
161 break; 161 break;
162 162
163 case 2: w3(0x48); r1(); 163 case 2: w3(0x48); (void)r1();
164 for (k=0;k<count;k++) w4(buf[k^1]); 164 for (k=0;k<count;k++) w4(buf[k^1]);
165 break; 165 break;
166 166
167 case 3: w3(0x48); r1(); 167 case 3: w3(0x48); (void)r1();
168 for (k=0;k<count/2;k++) w4w(pi_swab16(buf,k)); 168 for (k=0;k<count/2;k++) w4w(pi_swab16(buf,k));
169 break; 169 break;
170 170
171 case 4: w3(0x48); r1(); 171 case 4: w3(0x48); (void)r1();
172 for (k=0;k<count/4;k++) w4l(pi_swab32(buf,k)); 172 for (k=0;k<count/4;k++) w4l(pi_swab32(buf,k));
173 break; 173 break;
174 174
diff --git a/drivers/block/paride/on26.c b/drivers/block/paride/on26.c
index 9f837d9a36..0f833caa21 100644
--- a/drivers/block/paride/on26.c
+++ b/drivers/block/paride/on26.c
@@ -66,7 +66,7 @@ static int on26_read_regr( PIA *pi, int cont, int regr )
66 case 3: 66 case 3:
67 case 4: w3(1); w3(1); w2(5); w4(r); w2(4); 67 case 4: w3(1); w3(1); w2(5); w4(r); w2(4);
68 w3(0); w3(0); w2(0x24); a = r4(); w2(4); 68 w3(0); w3(0); w2(0x24); a = r4(); w2(4);
69 w2(0x24); r4(); w2(4); 69 w2(0x24); (void)r4(); w2(4);
70 return a; 70 return a;
71 71
72 } 72 }
diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
index 476a5b553f..1d261f985f 100644
--- a/drivers/block/pktcdvd.c
+++ b/drivers/block/pktcdvd.c
@@ -56,6 +56,7 @@
56#include <linux/seq_file.h> 56#include <linux/seq_file.h>
57#include <linux/miscdevice.h> 57#include <linux/miscdevice.h>
58#include <linux/suspend.h> 58#include <linux/suspend.h>
59#include <linux/mutex.h>
59#include <scsi/scsi_cmnd.h> 60#include <scsi/scsi_cmnd.h>
60#include <scsi/scsi_ioctl.h> 61#include <scsi/scsi_ioctl.h>
61#include <scsi/scsi.h> 62#include <scsi/scsi.h>
@@ -81,7 +82,7 @@
81static struct pktcdvd_device *pkt_devs[MAX_WRITERS]; 82static struct pktcdvd_device *pkt_devs[MAX_WRITERS];
82static struct proc_dir_entry *pkt_proc; 83static struct proc_dir_entry *pkt_proc;
83static int pkt_major; 84static int pkt_major;
84static struct semaphore ctl_mutex; /* Serialize open/close/setup/teardown */ 85static struct mutex ctl_mutex; /* Serialize open/close/setup/teardown */
85static mempool_t *psd_pool; 86static mempool_t *psd_pool;
86 87
87 88
@@ -2018,7 +2019,7 @@ static int pkt_open(struct inode *inode, struct file *file)
2018 2019
2019 VPRINTK("pktcdvd: entering open\n"); 2020 VPRINTK("pktcdvd: entering open\n");
2020 2021
2021 down(&ctl_mutex); 2022 mutex_lock(&ctl_mutex);
2022 pd = pkt_find_dev_from_minor(iminor(inode)); 2023 pd = pkt_find_dev_from_minor(iminor(inode));
2023 if (!pd) { 2024 if (!pd) {
2024 ret = -ENODEV; 2025 ret = -ENODEV;
@@ -2044,14 +2045,14 @@ static int pkt_open(struct inode *inode, struct file *file)
2044 set_blocksize(inode->i_bdev, CD_FRAMESIZE); 2045 set_blocksize(inode->i_bdev, CD_FRAMESIZE);
2045 } 2046 }
2046 2047
2047 up(&ctl_mutex); 2048 mutex_unlock(&ctl_mutex);
2048 return 0; 2049 return 0;
2049 2050
2050out_dec: 2051out_dec:
2051 pd->refcnt--; 2052 pd->refcnt--;
2052out: 2053out:
2053 VPRINTK("pktcdvd: failed open (%d)\n", ret); 2054 VPRINTK("pktcdvd: failed open (%d)\n", ret);
2054 up(&ctl_mutex); 2055 mutex_unlock(&ctl_mutex);
2055 return ret; 2056 return ret;
2056} 2057}
2057 2058
@@ -2060,14 +2061,14 @@ static int pkt_close(struct inode *inode, struct file *file)
2060 struct pktcdvd_device *pd = inode->i_bdev->bd_disk->private_data; 2061 struct pktcdvd_device *pd = inode->i_bdev->bd_disk->private_data;
2061 int ret = 0; 2062 int ret = 0;
2062 2063
2063 down(&ctl_mutex); 2064 mutex_lock(&ctl_mutex);
2064 pd->refcnt--; 2065 pd->refcnt--;
2065 BUG_ON(pd->refcnt < 0); 2066 BUG_ON(pd->refcnt < 0);
2066 if (pd->refcnt == 0) { 2067 if (pd->refcnt == 0) {
2067 int flush = test_bit(PACKET_WRITABLE, &pd->flags); 2068 int flush = test_bit(PACKET_WRITABLE, &pd->flags);
2068 pkt_release_dev(pd, flush); 2069 pkt_release_dev(pd, flush);
2069 } 2070 }
2070 up(&ctl_mutex); 2071 mutex_unlock(&ctl_mutex);
2071 return ret; 2072 return ret;
2072} 2073}
2073 2074
@@ -2596,21 +2597,21 @@ static int pkt_ctl_ioctl(struct inode *inode, struct file *file, unsigned int cm
2596 case PKT_CTRL_CMD_SETUP: 2597 case PKT_CTRL_CMD_SETUP:
2597 if (!capable(CAP_SYS_ADMIN)) 2598 if (!capable(CAP_SYS_ADMIN))
2598 return -EPERM; 2599 return -EPERM;
2599 down(&ctl_mutex); 2600 mutex_lock(&ctl_mutex);
2600 ret = pkt_setup_dev(&ctrl_cmd); 2601 ret = pkt_setup_dev(&ctrl_cmd);
2601 up(&ctl_mutex); 2602 mutex_unlock(&ctl_mutex);
2602 break; 2603 break;
2603 case PKT_CTRL_CMD_TEARDOWN: 2604 case PKT_CTRL_CMD_TEARDOWN:
2604 if (!capable(CAP_SYS_ADMIN)) 2605 if (!capable(CAP_SYS_ADMIN))
2605 return -EPERM; 2606 return -EPERM;
2606 down(&ctl_mutex); 2607 mutex_lock(&ctl_mutex);
2607 ret = pkt_remove_dev(&ctrl_cmd); 2608 ret = pkt_remove_dev(&ctrl_cmd);
2608 up(&ctl_mutex); 2609 mutex_unlock(&ctl_mutex);
2609 break; 2610 break;
2610 case PKT_CTRL_CMD_STATUS: 2611 case PKT_CTRL_CMD_STATUS:
2611 down(&ctl_mutex); 2612 mutex_lock(&ctl_mutex);
2612 pkt_get_status(&ctrl_cmd); 2613 pkt_get_status(&ctrl_cmd);
2613 up(&ctl_mutex); 2614 mutex_unlock(&ctl_mutex);
2614 break; 2615 break;
2615 default: 2616 default:
2616 return -ENOTTY; 2617 return -ENOTTY;
@@ -2656,7 +2657,7 @@ static int __init pkt_init(void)
2656 goto out; 2657 goto out;
2657 } 2658 }
2658 2659
2659 init_MUTEX(&ctl_mutex); 2660 mutex_init(&ctl_mutex);
2660 2661
2661 pkt_proc = proc_mkdir("pktcdvd", proc_root_driver); 2662 pkt_proc = proc_mkdir("pktcdvd", proc_root_driver);
2662 2663
diff --git a/drivers/block/rd.c b/drivers/block/rd.c
index ffd6abd6d5..940bfd7951 100644
--- a/drivers/block/rd.c
+++ b/drivers/block/rd.c
@@ -186,7 +186,8 @@ static int ramdisk_writepages(struct address_space *mapping,
186 */ 186 */
187static int ramdisk_set_page_dirty(struct page *page) 187static int ramdisk_set_page_dirty(struct page *page)
188{ 188{
189 SetPageDirty(page); 189 if (!TestSetPageDirty(page))
190 return 1;
190 return 0; 191 return 0;
191} 192}
192 193
@@ -310,12 +311,12 @@ static int rd_ioctl(struct inode *inode, struct file *file,
310 * cache 311 * cache
311 */ 312 */
312 error = -EBUSY; 313 error = -EBUSY;
313 down(&bdev->bd_sem); 314 mutex_lock(&bdev->bd_mutex);
314 if (bdev->bd_openers <= 2) { 315 if (bdev->bd_openers <= 2) {
315 truncate_inode_pages(bdev->bd_inode->i_mapping, 0); 316 truncate_inode_pages(bdev->bd_inode->i_mapping, 0);
316 error = 0; 317 error = 0;
317 } 318 }
318 up(&bdev->bd_sem); 319 mutex_unlock(&bdev->bd_mutex);
319 return error; 320 return error;
320} 321}
321 322
diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
index 879bbc26ce..a59876a0bf 100644
--- a/drivers/cdrom/cdrom.c
+++ b/drivers/cdrom/cdrom.c
@@ -407,7 +407,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
407 ENSURE(get_mcn, CDC_MCN); 407 ENSURE(get_mcn, CDC_MCN);
408 ENSURE(reset, CDC_RESET); 408 ENSURE(reset, CDC_RESET);
409 ENSURE(audio_ioctl, CDC_PLAY_AUDIO); 409 ENSURE(audio_ioctl, CDC_PLAY_AUDIO);
410 ENSURE(dev_ioctl, CDC_IOCTLS);
411 ENSURE(generic_packet, CDC_GENERIC_PACKET); 410 ENSURE(generic_packet, CDC_GENERIC_PACKET);
412 cdi->mc_flags = 0; 411 cdi->mc_flags = 0;
413 cdo->n_minors = 0; 412 cdo->n_minors = 0;
@@ -2196,395 +2195,586 @@ retry:
2196 return cdrom_read_cdda_old(cdi, ubuf, lba, nframes); 2195 return cdrom_read_cdda_old(cdi, ubuf, lba, nframes);
2197} 2196}
2198 2197
2199/* Just about every imaginable ioctl is supported in the Uniform layer 2198static int cdrom_ioctl_multisession(struct cdrom_device_info *cdi,
2200 * these days. ATAPI / SCSI specific code now mainly resides in 2199 void __user *argp)
2201 * mmc_ioct().
2202 */
2203int cdrom_ioctl(struct file * file, struct cdrom_device_info *cdi,
2204 struct inode *ip, unsigned int cmd, unsigned long arg)
2205{ 2200{
2206 struct cdrom_device_ops *cdo = cdi->ops; 2201 struct cdrom_multisession ms_info;
2202 u8 requested_format;
2207 int ret; 2203 int ret;
2208 2204
2209 /* Try the generic SCSI command ioctl's first.. */ 2205 cdinfo(CD_DO_IOCTL, "entering CDROMMULTISESSION\n");
2210 ret = scsi_cmd_ioctl(file, ip->i_bdev->bd_disk, cmd, (void __user *)arg); 2206
2211 if (ret != -ENOTTY) 2207 if (!(cdi->ops->capability & CDC_MULTI_SESSION))
2208 return -ENOSYS;
2209
2210 if (copy_from_user(&ms_info, argp, sizeof(ms_info)))
2211 return -EFAULT;
2212
2213 requested_format = ms_info.addr_format;
2214 if (requested_format != CDROM_MSF && requested_format != CDROM_LBA)
2215 return -EINVAL;
2216 ms_info.addr_format = CDROM_LBA;
2217
2218 ret = cdi->ops->get_last_session(cdi, &ms_info);
2219 if (ret)
2212 return ret; 2220 return ret;
2213 2221
2214 /* the first few commands do not deal with audio drive_info, but 2222 sanitize_format(&ms_info.addr, &ms_info.addr_format, requested_format);
2215 only with routines in cdrom device operations. */ 2223
2216 switch (cmd) { 2224 if (copy_to_user(argp, &ms_info, sizeof(ms_info)))
2217 case CDROMMULTISESSION: { 2225 return -EFAULT;
2218 struct cdrom_multisession ms_info; 2226
2219 u_char requested_format; 2227 cdinfo(CD_DO_IOCTL, "CDROMMULTISESSION successful\n");
2220 cdinfo(CD_DO_IOCTL, "entering CDROMMULTISESSION\n"); 2228 return 0;
2221 if (!(cdo->capability & CDC_MULTI_SESSION)) 2229}
2222 return -ENOSYS; 2230
2223 IOCTL_IN(arg, struct cdrom_multisession, ms_info); 2231static int cdrom_ioctl_eject(struct cdrom_device_info *cdi)
2224 requested_format = ms_info.addr_format; 2232{
2225 if (!((requested_format == CDROM_MSF) || 2233 cdinfo(CD_DO_IOCTL, "entering CDROMEJECT\n");
2226 (requested_format == CDROM_LBA))) 2234
2227 return -EINVAL; 2235 if (!CDROM_CAN(CDC_OPEN_TRAY))
2228 ms_info.addr_format = CDROM_LBA; 2236 return -ENOSYS;
2229 if ((ret=cdo->get_last_session(cdi, &ms_info))) 2237 if (cdi->use_count != 1 || keeplocked)
2238 return -EBUSY;
2239 if (CDROM_CAN(CDC_LOCK)) {
2240 int ret = cdi->ops->lock_door(cdi, 0);
2241 if (ret)
2230 return ret; 2242 return ret;
2231 sanitize_format(&ms_info.addr, &ms_info.addr_format, 2243 }
2232 requested_format);
2233 IOCTL_OUT(arg, struct cdrom_multisession, ms_info);
2234 cdinfo(CD_DO_IOCTL, "CDROMMULTISESSION successful\n");
2235 return 0;
2236 }
2237 2244
2238 case CDROMEJECT: { 2245 return cdi->ops->tray_move(cdi, 1);
2239 cdinfo(CD_DO_IOCTL, "entering CDROMEJECT\n"); 2246}
2240 if (!CDROM_CAN(CDC_OPEN_TRAY))
2241 return -ENOSYS;
2242 if (cdi->use_count != 1 || keeplocked)
2243 return -EBUSY;
2244 if (CDROM_CAN(CDC_LOCK))
2245 if ((ret=cdo->lock_door(cdi, 0)))
2246 return ret;
2247 2247
2248 return cdo->tray_move(cdi, 1); 2248static int cdrom_ioctl_closetray(struct cdrom_device_info *cdi)
2249 } 2249{
2250 cdinfo(CD_DO_IOCTL, "entering CDROMCLOSETRAY\n");
2250 2251
2251 case CDROMCLOSETRAY: { 2252 if (!CDROM_CAN(CDC_CLOSE_TRAY))
2252 cdinfo(CD_DO_IOCTL, "entering CDROMCLOSETRAY\n"); 2253 return -ENOSYS;
2253 if (!CDROM_CAN(CDC_CLOSE_TRAY)) 2254 return cdi->ops->tray_move(cdi, 0);
2254 return -ENOSYS; 2255}
2255 return cdo->tray_move(cdi, 0);
2256 }
2257 2256
2258 case CDROMEJECT_SW: { 2257static int cdrom_ioctl_eject_sw(struct cdrom_device_info *cdi,
2259 cdinfo(CD_DO_IOCTL, "entering CDROMEJECT_SW\n"); 2258 unsigned long arg)
2260 if (!CDROM_CAN(CDC_OPEN_TRAY)) 2259{
2261 return -ENOSYS; 2260 cdinfo(CD_DO_IOCTL, "entering CDROMEJECT_SW\n");
2262 if (keeplocked)
2263 return -EBUSY;
2264 cdi->options &= ~(CDO_AUTO_CLOSE | CDO_AUTO_EJECT);
2265 if (arg)
2266 cdi->options |= CDO_AUTO_CLOSE | CDO_AUTO_EJECT;
2267 return 0;
2268 }
2269 2261
2270 case CDROM_MEDIA_CHANGED: { 2262 if (!CDROM_CAN(CDC_OPEN_TRAY))
2271 struct cdrom_changer_info *info; 2263 return -ENOSYS;
2272 int changed; 2264 if (keeplocked)
2265 return -EBUSY;
2273 2266
2274 cdinfo(CD_DO_IOCTL, "entering CDROM_MEDIA_CHANGED\n"); 2267 cdi->options &= ~(CDO_AUTO_CLOSE | CDO_AUTO_EJECT);
2275 if (!CDROM_CAN(CDC_MEDIA_CHANGED)) 2268 if (arg)
2276 return -ENOSYS; 2269 cdi->options |= CDO_AUTO_CLOSE | CDO_AUTO_EJECT;
2270 return 0;
2271}
2277 2272
2278 /* cannot select disc or select current disc */ 2273static int cdrom_ioctl_media_changed(struct cdrom_device_info *cdi,
2279 if (!CDROM_CAN(CDC_SELECT_DISC) || arg == CDSL_CURRENT) 2274 unsigned long arg)
2280 return media_changed(cdi, 1); 2275{
2276 struct cdrom_changer_info *info;
2277 int ret;
2281 2278
2282 if ((unsigned int)arg >= cdi->capacity) 2279 cdinfo(CD_DO_IOCTL, "entering CDROM_MEDIA_CHANGED\n");
2283 return -EINVAL;
2284 2280
2285 info = kmalloc(sizeof(*info), GFP_KERNEL); 2281 if (!CDROM_CAN(CDC_MEDIA_CHANGED))
2286 if (!info) 2282 return -ENOSYS;
2287 return -ENOMEM;
2288 2283
2289 if ((ret = cdrom_read_mech_status(cdi, info))) { 2284 /* cannot select disc or select current disc */
2290 kfree(info); 2285 if (!CDROM_CAN(CDC_SELECT_DISC) || arg == CDSL_CURRENT)
2291 return ret; 2286 return media_changed(cdi, 1);
2292 }
2293 2287
2294 changed = info->slots[arg].change; 2288 if ((unsigned int)arg >= cdi->capacity)
2295 kfree(info); 2289 return -EINVAL;
2296 return changed;
2297 }
2298 2290
2299 case CDROM_SET_OPTIONS: { 2291 info = kmalloc(sizeof(*info), GFP_KERNEL);
2300 cdinfo(CD_DO_IOCTL, "entering CDROM_SET_OPTIONS\n"); 2292 if (!info)
2301 /* options need to be in sync with capability. too late for 2293 return -ENOMEM;
2302 that, so we have to check each one separately... */
2303 switch (arg) {
2304 case CDO_USE_FFLAGS:
2305 case CDO_CHECK_TYPE:
2306 break;
2307 case CDO_LOCK:
2308 if (!CDROM_CAN(CDC_LOCK))
2309 return -ENOSYS;
2310 break;
2311 case 0:
2312 return cdi->options;
2313 /* default is basically CDO_[AUTO_CLOSE|AUTO_EJECT] */
2314 default:
2315 if (!CDROM_CAN(arg))
2316 return -ENOSYS;
2317 }
2318 cdi->options |= (int) arg;
2319 return cdi->options;
2320 }
2321 2294
2322 case CDROM_CLEAR_OPTIONS: { 2295 ret = cdrom_read_mech_status(cdi, info);
2323 cdinfo(CD_DO_IOCTL, "entering CDROM_CLEAR_OPTIONS\n"); 2296 if (!ret)
2324 cdi->options &= ~(int) arg; 2297 ret = info->slots[arg].change;
2325 return cdi->options; 2298 kfree(info);
2326 } 2299 return ret;
2300}
2327 2301
2328 case CDROM_SELECT_SPEED: { 2302static int cdrom_ioctl_set_options(struct cdrom_device_info *cdi,
2329 cdinfo(CD_DO_IOCTL, "entering CDROM_SELECT_SPEED\n"); 2303 unsigned long arg)
2330 if (!CDROM_CAN(CDC_SELECT_SPEED)) 2304{
2331 return -ENOSYS; 2305 cdinfo(CD_DO_IOCTL, "entering CDROM_SET_OPTIONS\n");
2332 return cdo->select_speed(cdi, arg);
2333 }
2334 2306
2335 case CDROM_SELECT_DISC: { 2307 /*
2336 cdinfo(CD_DO_IOCTL, "entering CDROM_SELECT_DISC\n"); 2308 * Options need to be in sync with capability.
2337 if (!CDROM_CAN(CDC_SELECT_DISC)) 2309 * Too late for that, so we have to check each one separately.
2310 */
2311 switch (arg) {
2312 case CDO_USE_FFLAGS:
2313 case CDO_CHECK_TYPE:
2314 break;
2315 case CDO_LOCK:
2316 if (!CDROM_CAN(CDC_LOCK))
2317 return -ENOSYS;
2318 break;
2319 case 0:
2320 return cdi->options;
2321 /* default is basically CDO_[AUTO_CLOSE|AUTO_EJECT] */
2322 default:
2323 if (!CDROM_CAN(arg))
2338 return -ENOSYS; 2324 return -ENOSYS;
2325 }
2326 cdi->options |= (int) arg;
2327 return cdi->options;
2328}
2339 2329
2340 if ((arg != CDSL_CURRENT) && (arg != CDSL_NONE)) 2330static int cdrom_ioctl_clear_options(struct cdrom_device_info *cdi,
2341 if ((int)arg >= cdi->capacity) 2331 unsigned long arg)
2342 return -EINVAL; 2332{
2343 2333 cdinfo(CD_DO_IOCTL, "entering CDROM_CLEAR_OPTIONS\n");
2344 /* cdo->select_disc is a hook to allow a driver-specific
2345 * way of seleting disc. However, since there is no
2346 * equiv hook for cdrom_slot_status this may not
2347 * actually be useful...
2348 */
2349 if (cdo->select_disc != NULL)
2350 return cdo->select_disc(cdi, arg);
2351
2352 /* no driver specific select_disc(), call our own */
2353 cdinfo(CD_CHANGER, "Using generic cdrom_select_disc()\n");
2354 return cdrom_select_disc(cdi, arg);
2355 }
2356 2334
2357 case CDROMRESET: { 2335 cdi->options &= ~(int) arg;
2358 if (!capable(CAP_SYS_ADMIN)) 2336 return cdi->options;
2359 return -EACCES; 2337}
2360 cdinfo(CD_DO_IOCTL, "entering CDROM_RESET\n");
2361 if (!CDROM_CAN(CDC_RESET))
2362 return -ENOSYS;
2363 invalidate_bdev(ip->i_bdev, 0);
2364 return cdo->reset(cdi);
2365 }
2366 2338
2367 case CDROM_LOCKDOOR: { 2339static int cdrom_ioctl_select_speed(struct cdrom_device_info *cdi,
2368 cdinfo(CD_DO_IOCTL, "%socking door.\n", arg ? "L" : "Unl"); 2340 unsigned long arg)
2369 if (!CDROM_CAN(CDC_LOCK)) 2341{
2370 return -EDRIVE_CANT_DO_THIS; 2342 cdinfo(CD_DO_IOCTL, "entering CDROM_SELECT_SPEED\n");
2371 keeplocked = arg ? 1 : 0;
2372 /* don't unlock the door on multiple opens,but allow root
2373 * to do so */
2374 if ((cdi->use_count != 1) && !arg && !capable(CAP_SYS_ADMIN))
2375 return -EBUSY;
2376 return cdo->lock_door(cdi, arg);
2377 }
2378 2343
2379 case CDROM_DEBUG: { 2344 if (!CDROM_CAN(CDC_SELECT_SPEED))
2380 if (!capable(CAP_SYS_ADMIN)) 2345 return -ENOSYS;
2381 return -EACCES; 2346 return cdi->ops->select_speed(cdi, arg);
2382 cdinfo(CD_DO_IOCTL, "%sabling debug.\n", arg ? "En" : "Dis"); 2347}
2383 debug = arg ? 1 : 0;
2384 return debug;
2385 }
2386 2348
2387 case CDROM_GET_CAPABILITY: { 2349static int cdrom_ioctl_select_disc(struct cdrom_device_info *cdi,
2388 cdinfo(CD_DO_IOCTL, "entering CDROM_GET_CAPABILITY\n"); 2350 unsigned long arg)
2389 return (cdo->capability & ~cdi->mask); 2351{
2390 } 2352 cdinfo(CD_DO_IOCTL, "entering CDROM_SELECT_DISC\n");
2353
2354 if (!CDROM_CAN(CDC_SELECT_DISC))
2355 return -ENOSYS;
2356
2357 if (arg != CDSL_CURRENT && arg != CDSL_NONE) {
2358 if ((int)arg >= cdi->capacity)
2359 return -EINVAL;
2360 }
2361
2362 /*
2363 * ->select_disc is a hook to allow a driver-specific way of
2364 * seleting disc. However, since there is no equivalent hook for
2365 * cdrom_slot_status this may not actually be useful...
2366 */
2367 if (cdi->ops->select_disc)
2368 return cdi->ops->select_disc(cdi, arg);
2369
2370 cdinfo(CD_CHANGER, "Using generic cdrom_select_disc()\n");
2371 return cdrom_select_disc(cdi, arg);
2372}
2373
2374static int cdrom_ioctl_reset(struct cdrom_device_info *cdi,
2375 struct block_device *bdev)
2376{
2377 cdinfo(CD_DO_IOCTL, "entering CDROM_RESET\n");
2378
2379 if (!capable(CAP_SYS_ADMIN))
2380 return -EACCES;
2381 if (!CDROM_CAN(CDC_RESET))
2382 return -ENOSYS;
2383 invalidate_bdev(bdev, 0);
2384 return cdi->ops->reset(cdi);
2385}
2386
2387static int cdrom_ioctl_lock_door(struct cdrom_device_info *cdi,
2388 unsigned long arg)
2389{
2390 cdinfo(CD_DO_IOCTL, "%socking door.\n", arg ? "L" : "Unl");
2391
2392 if (!CDROM_CAN(CDC_LOCK))
2393 return -EDRIVE_CANT_DO_THIS;
2394
2395 keeplocked = arg ? 1 : 0;
2396
2397 /*
2398 * Don't unlock the door on multiple opens by default, but allow
2399 * root to do so.
2400 */
2401 if (cdi->use_count != 1 && !arg && !capable(CAP_SYS_ADMIN))
2402 return -EBUSY;
2403 return cdi->ops->lock_door(cdi, arg);
2404}
2405
2406static int cdrom_ioctl_debug(struct cdrom_device_info *cdi,
2407 unsigned long arg)
2408{
2409 cdinfo(CD_DO_IOCTL, "%sabling debug.\n", arg ? "En" : "Dis");
2410
2411 if (!capable(CAP_SYS_ADMIN))
2412 return -EACCES;
2413 debug = arg ? 1 : 0;
2414 return debug;
2415}
2391 2416
2392/* The following function is implemented, although very few audio 2417static int cdrom_ioctl_get_capability(struct cdrom_device_info *cdi)
2418{
2419 cdinfo(CD_DO_IOCTL, "entering CDROM_GET_CAPABILITY\n");
2420 return (cdi->ops->capability & ~cdi->mask);
2421}
2422
2423/*
2424 * The following function is implemented, although very few audio
2393 * discs give Universal Product Code information, which should just be 2425 * discs give Universal Product Code information, which should just be
2394 * the Medium Catalog Number on the box. Note, that the way the code 2426 * the Medium Catalog Number on the box. Note, that the way the code
2395 * is written on the CD is /not/ uniform across all discs! 2427 * is written on the CD is /not/ uniform across all discs!
2396 */ 2428 */
2397 case CDROM_GET_MCN: { 2429static int cdrom_ioctl_get_mcn(struct cdrom_device_info *cdi,
2398 struct cdrom_mcn mcn; 2430 void __user *argp)
2399 cdinfo(CD_DO_IOCTL, "entering CDROM_GET_MCN\n"); 2431{
2400 if (!(cdo->capability & CDC_MCN)) 2432 struct cdrom_mcn mcn;
2401 return -ENOSYS; 2433 int ret;
2402 if ((ret=cdo->get_mcn(cdi, &mcn)))
2403 return ret;
2404 IOCTL_OUT(arg, struct cdrom_mcn, mcn);
2405 cdinfo(CD_DO_IOCTL, "CDROM_GET_MCN successful\n");
2406 return 0;
2407 }
2408 2434
2409 case CDROM_DRIVE_STATUS: { 2435 cdinfo(CD_DO_IOCTL, "entering CDROM_GET_MCN\n");
2410 cdinfo(CD_DO_IOCTL, "entering CDROM_DRIVE_STATUS\n");
2411 if (!(cdo->capability & CDC_DRIVE_STATUS))
2412 return -ENOSYS;
2413 if (!CDROM_CAN(CDC_SELECT_DISC))
2414 return cdo->drive_status(cdi, CDSL_CURRENT);
2415 if ((arg == CDSL_CURRENT) || (arg == CDSL_NONE))
2416 return cdo->drive_status(cdi, CDSL_CURRENT);
2417 if (((int)arg >= cdi->capacity))
2418 return -EINVAL;
2419 return cdrom_slot_status(cdi, arg);
2420 }
2421 2436
2422 /* Ok, this is where problems start. The current interface for the 2437 if (!(cdi->ops->capability & CDC_MCN))
2423 CDROM_DISC_STATUS ioctl is flawed. It makes the false assumption 2438 return -ENOSYS;
2424 that CDs are all CDS_DATA_1 or all CDS_AUDIO, etc. Unfortunatly, 2439 ret = cdi->ops->get_mcn(cdi, &mcn);
2425 while this is often the case, it is also very common for CDs to 2440 if (ret)
2426 have some tracks with data, and some tracks with audio. Just 2441 return ret;
2427 because I feel like it, I declare the following to be the best
2428 way to cope. If the CD has ANY data tracks on it, it will be
2429 returned as a data CD. If it has any XA tracks, I will return
2430 it as that. Now I could simplify this interface by combining these
2431 returns with the above, but this more clearly demonstrates
2432 the problem with the current interface. Too bad this wasn't
2433 designed to use bitmasks... -Erik
2434
2435 Well, now we have the option CDS_MIXED: a mixed-type CD.
2436 User level programmers might feel the ioctl is not very useful.
2437 ---david
2438 */
2439 case CDROM_DISC_STATUS: {
2440 tracktype tracks;
2441 cdinfo(CD_DO_IOCTL, "entering CDROM_DISC_STATUS\n");
2442 cdrom_count_tracks(cdi, &tracks);
2443 if (tracks.error)
2444 return(tracks.error);
2445
2446 /* Policy mode on */
2447 if (tracks.audio > 0) {
2448 if (tracks.data==0 && tracks.cdi==0 && tracks.xa==0)
2449 return CDS_AUDIO;
2450 else
2451 return CDS_MIXED;
2452 }
2453 if (tracks.cdi > 0) return CDS_XA_2_2;
2454 if (tracks.xa > 0) return CDS_XA_2_1;
2455 if (tracks.data > 0) return CDS_DATA_1;
2456 /* Policy mode off */
2457 2442
2458 cdinfo(CD_WARNING,"This disc doesn't have any tracks I recognize!\n"); 2443 if (copy_to_user(argp, &mcn, sizeof(mcn)))
2459 return CDS_NO_INFO; 2444 return -EFAULT;
2460 } 2445 cdinfo(CD_DO_IOCTL, "CDROM_GET_MCN successful\n");
2446 return 0;
2447}
2461 2448
2462 case CDROM_CHANGER_NSLOTS: { 2449static int cdrom_ioctl_drive_status(struct cdrom_device_info *cdi,
2463 cdinfo(CD_DO_IOCTL, "entering CDROM_CHANGER_NSLOTS\n"); 2450 unsigned long arg)
2464 return cdi->capacity; 2451{
2465 } 2452 cdinfo(CD_DO_IOCTL, "entering CDROM_DRIVE_STATUS\n");
2453
2454 if (!(cdi->ops->capability & CDC_DRIVE_STATUS))
2455 return -ENOSYS;
2456 if (!CDROM_CAN(CDC_SELECT_DISC) ||
2457 (arg == CDSL_CURRENT || arg == CDSL_NONE))
2458 return cdi->ops->drive_status(cdi, CDSL_CURRENT);
2459 if (((int)arg >= cdi->capacity))
2460 return -EINVAL;
2461 return cdrom_slot_status(cdi, arg);
2462}
2463
2464/*
2465 * Ok, this is where problems start. The current interface for the
2466 * CDROM_DISC_STATUS ioctl is flawed. It makes the false assumption that
2467 * CDs are all CDS_DATA_1 or all CDS_AUDIO, etc. Unfortunatly, while this
2468 * is often the case, it is also very common for CDs to have some tracks
2469 * with data, and some tracks with audio. Just because I feel like it,
2470 * I declare the following to be the best way to cope. If the CD has ANY
2471 * data tracks on it, it will be returned as a data CD. If it has any XA
2472 * tracks, I will return it as that. Now I could simplify this interface
2473 * by combining these returns with the above, but this more clearly
2474 * demonstrates the problem with the current interface. Too bad this
2475 * wasn't designed to use bitmasks... -Erik
2476 *
2477 * Well, now we have the option CDS_MIXED: a mixed-type CD.
2478 * User level programmers might feel the ioctl is not very useful.
2479 * ---david
2480 */
2481static int cdrom_ioctl_disc_status(struct cdrom_device_info *cdi)
2482{
2483 tracktype tracks;
2484
2485 cdinfo(CD_DO_IOCTL, "entering CDROM_DISC_STATUS\n");
2486
2487 cdrom_count_tracks(cdi, &tracks);
2488 if (tracks.error)
2489 return tracks.error;
2490
2491 /* Policy mode on */
2492 if (tracks.audio > 0) {
2493 if (!tracks.data && !tracks.cdi && !tracks.xa)
2494 return CDS_AUDIO;
2495 else
2496 return CDS_MIXED;
2466 } 2497 }
2467 2498
2468 /* use the ioctls that are implemented through the generic_packet() 2499 if (tracks.cdi > 0)
2469 interface. this may look at bit funny, but if -ENOTTY is 2500 return CDS_XA_2_2;
2470 returned that particular ioctl is not implemented and we 2501 if (tracks.xa > 0)
2471 let it go through the device specific ones. */ 2502 return CDS_XA_2_1;
2503 if (tracks.data > 0)
2504 return CDS_DATA_1;
2505 /* Policy mode off */
2506
2507 cdinfo(CD_WARNING,"This disc doesn't have any tracks I recognize!\n");
2508 return CDS_NO_INFO;
2509}
2510
2511static int cdrom_ioctl_changer_nslots(struct cdrom_device_info *cdi)
2512{
2513 cdinfo(CD_DO_IOCTL, "entering CDROM_CHANGER_NSLOTS\n");
2514 return cdi->capacity;
2515}
2516
2517static int cdrom_ioctl_get_subchnl(struct cdrom_device_info *cdi,
2518 void __user *argp)
2519{
2520 struct cdrom_subchnl q;
2521 u8 requested, back;
2522 int ret;
2523
2524 /* cdinfo(CD_DO_IOCTL,"entering CDROMSUBCHNL\n");*/
2525
2526 if (!CDROM_CAN(CDC_PLAY_AUDIO))
2527 return -ENOSYS;
2528 if (copy_from_user(&q, argp, sizeof(q)))
2529 return -EFAULT;
2530
2531 requested = q.cdsc_format;
2532 if (requested != CDROM_MSF && requested != CDROM_LBA)
2533 return -EINVAL;
2534 q.cdsc_format = CDROM_MSF;
2535
2536 ret = cdi->ops->audio_ioctl(cdi, CDROMSUBCHNL, &q);
2537 if (ret)
2538 return ret;
2539
2540 back = q.cdsc_format; /* local copy */
2541 sanitize_format(&q.cdsc_absaddr, &back, requested);
2542 sanitize_format(&q.cdsc_reladdr, &q.cdsc_format, requested);
2543
2544 if (copy_to_user(argp, &q, sizeof(q)))
2545 return -EFAULT;
2546 /* cdinfo(CD_DO_IOCTL, "CDROMSUBCHNL successful\n"); */
2547 return 0;
2548}
2549
2550static int cdrom_ioctl_read_tochdr(struct cdrom_device_info *cdi,
2551 void __user *argp)
2552{
2553 struct cdrom_tochdr header;
2554 int ret;
2555
2556 /* cdinfo(CD_DO_IOCTL, "entering CDROMREADTOCHDR\n"); */
2557
2558 if (!CDROM_CAN(CDC_PLAY_AUDIO))
2559 return -ENOSYS;
2560 if (copy_from_user(&header, argp, sizeof(header)))
2561 return -EFAULT;
2562
2563 ret = cdi->ops->audio_ioctl(cdi, CDROMREADTOCHDR, &header);
2564 if (ret)
2565 return ret;
2566
2567 if (copy_to_user(argp, &header, sizeof(header)))
2568 return -EFAULT;
2569 /* cdinfo(CD_DO_IOCTL, "CDROMREADTOCHDR successful\n"); */
2570 return 0;
2571}
2572
2573static int cdrom_ioctl_read_tocentry(struct cdrom_device_info *cdi,
2574 void __user *argp)
2575{
2576 struct cdrom_tocentry entry;
2577 u8 requested_format;
2578 int ret;
2579
2580 /* cdinfo(CD_DO_IOCTL, "entering CDROMREADTOCENTRY\n"); */
2581
2582 if (!CDROM_CAN(CDC_PLAY_AUDIO))
2583 return -ENOSYS;
2584 if (copy_from_user(&entry, argp, sizeof(entry)))
2585 return -EFAULT;
2586
2587 requested_format = entry.cdte_format;
2588 if (requested_format != CDROM_MSF && requested_format != CDROM_LBA)
2589 return -EINVAL;
2590 /* make interface to low-level uniform */
2591 entry.cdte_format = CDROM_MSF;
2592 ret = cdi->ops->audio_ioctl(cdi, CDROMREADTOCENTRY, &entry);
2593 if (ret)
2594 return ret;
2595 sanitize_format(&entry.cdte_addr, &entry.cdte_format, requested_format);
2596
2597 if (copy_to_user(argp, &entry, sizeof(entry)))
2598 return -EFAULT;
2599 /* cdinfo(CD_DO_IOCTL, "CDROMREADTOCENTRY successful\n"); */
2600 return 0;
2601}
2602
2603static int cdrom_ioctl_play_msf(struct cdrom_device_info *cdi,
2604 void __user *argp)
2605{
2606 struct cdrom_msf msf;
2607
2608 cdinfo(CD_DO_IOCTL, "entering CDROMPLAYMSF\n");
2609
2610 if (!CDROM_CAN(CDC_PLAY_AUDIO))
2611 return -ENOSYS;
2612 if (copy_from_user(&msf, argp, sizeof(msf)))
2613 return -EFAULT;
2614 return cdi->ops->audio_ioctl(cdi, CDROMPLAYMSF, &msf);
2615}
2616
2617static int cdrom_ioctl_play_trkind(struct cdrom_device_info *cdi,
2618 void __user *argp)
2619{
2620 struct cdrom_ti ti;
2621 int ret;
2622
2623 cdinfo(CD_DO_IOCTL, "entering CDROMPLAYTRKIND\n");
2624
2625 if (!CDROM_CAN(CDC_PLAY_AUDIO))
2626 return -ENOSYS;
2627 if (copy_from_user(&ti, argp, sizeof(ti)))
2628 return -EFAULT;
2629
2630 ret = check_for_audio_disc(cdi, cdi->ops);
2631 if (ret)
2632 return ret;
2633 return cdi->ops->audio_ioctl(cdi, CDROMPLAYTRKIND, &ti);
2634}
2635static int cdrom_ioctl_volctrl(struct cdrom_device_info *cdi,
2636 void __user *argp)
2637{
2638 struct cdrom_volctrl volume;
2639
2640 cdinfo(CD_DO_IOCTL, "entering CDROMVOLCTRL\n");
2641
2642 if (!CDROM_CAN(CDC_PLAY_AUDIO))
2643 return -ENOSYS;
2644 if (copy_from_user(&volume, argp, sizeof(volume)))
2645 return -EFAULT;
2646 return cdi->ops->audio_ioctl(cdi, CDROMVOLCTRL, &volume);
2647}
2648
2649static int cdrom_ioctl_volread(struct cdrom_device_info *cdi,
2650 void __user *argp)
2651{
2652 struct cdrom_volctrl volume;
2653 int ret;
2654
2655 cdinfo(CD_DO_IOCTL, "entering CDROMVOLREAD\n");
2656
2657 if (!CDROM_CAN(CDC_PLAY_AUDIO))
2658 return -ENOSYS;
2659
2660 ret = cdi->ops->audio_ioctl(cdi, CDROMVOLREAD, &volume);
2661 if (ret)
2662 return ret;
2663
2664 if (copy_to_user(argp, &volume, sizeof(volume)))
2665 return -EFAULT;
2666 return 0;
2667}
2668
2669static int cdrom_ioctl_audioctl(struct cdrom_device_info *cdi,
2670 unsigned int cmd)
2671{
2672 int ret;
2673
2674 cdinfo(CD_DO_IOCTL, "doing audio ioctl (start/stop/pause/resume)\n");
2675
2676 if (!CDROM_CAN(CDC_PLAY_AUDIO))
2677 return -ENOSYS;
2678 ret = check_for_audio_disc(cdi, cdi->ops);
2679 if (ret)
2680 return ret;
2681 return cdi->ops->audio_ioctl(cdi, cmd, NULL);
2682}
2683
2684/*
2685 * Just about every imaginable ioctl is supported in the Uniform layer
2686 * these days.
2687 * ATAPI / SCSI specific code now mainly resides in mmc_ioctl().
2688 */
2689int cdrom_ioctl(struct file * file, struct cdrom_device_info *cdi,
2690 struct inode *ip, unsigned int cmd, unsigned long arg)
2691{
2692 void __user *argp = (void __user *)arg;
2693 int ret;
2694
2695 /*
2696 * Try the generic SCSI command ioctl's first.
2697 */
2698 ret = scsi_cmd_ioctl(file, ip->i_bdev->bd_disk, cmd, argp);
2699 if (ret != -ENOTTY)
2700 return ret;
2701
2702 switch (cmd) {
2703 case CDROMMULTISESSION:
2704 return cdrom_ioctl_multisession(cdi, argp);
2705 case CDROMEJECT:
2706 return cdrom_ioctl_eject(cdi);
2707 case CDROMCLOSETRAY:
2708 return cdrom_ioctl_closetray(cdi);
2709 case CDROMEJECT_SW:
2710 return cdrom_ioctl_eject_sw(cdi, arg);
2711 case CDROM_MEDIA_CHANGED:
2712 return cdrom_ioctl_media_changed(cdi, arg);
2713 case CDROM_SET_OPTIONS:
2714 return cdrom_ioctl_set_options(cdi, arg);
2715 case CDROM_CLEAR_OPTIONS:
2716 return cdrom_ioctl_clear_options(cdi, arg);
2717 case CDROM_SELECT_SPEED:
2718 return cdrom_ioctl_select_speed(cdi, arg);
2719 case CDROM_SELECT_DISC:
2720 return cdrom_ioctl_select_disc(cdi, arg);
2721 case CDROMRESET:
2722 return cdrom_ioctl_reset(cdi, ip->i_bdev);
2723 case CDROM_LOCKDOOR:
2724 return cdrom_ioctl_lock_door(cdi, arg);
2725 case CDROM_DEBUG:
2726 return cdrom_ioctl_debug(cdi, arg);
2727 case CDROM_GET_CAPABILITY:
2728 return cdrom_ioctl_get_capability(cdi);
2729 case CDROM_GET_MCN:
2730 return cdrom_ioctl_get_mcn(cdi, argp);
2731 case CDROM_DRIVE_STATUS:
2732 return cdrom_ioctl_drive_status(cdi, arg);
2733 case CDROM_DISC_STATUS:
2734 return cdrom_ioctl_disc_status(cdi);
2735 case CDROM_CHANGER_NSLOTS:
2736 return cdrom_ioctl_changer_nslots(cdi);
2737 }
2738
2739 /*
2740 * Use the ioctls that are implemented through the generic_packet()
2741 * interface. this may look at bit funny, but if -ENOTTY is
2742 * returned that particular ioctl is not implemented and we
2743 * let it go through the device specific ones.
2744 */
2472 if (CDROM_CAN(CDC_GENERIC_PACKET)) { 2745 if (CDROM_CAN(CDC_GENERIC_PACKET)) {
2473 ret = mmc_ioctl(cdi, cmd, arg); 2746 ret = mmc_ioctl(cdi, cmd, arg);
2474 if (ret != -ENOTTY) { 2747 if (ret != -ENOTTY)
2475 return ret; 2748 return ret;
2476 }
2477 } 2749 }
2478 2750
2479 /* note: most of the cdinfo() calls are commented out here, 2751 /*
2480 because they fill up the sys log when CD players poll 2752 * Note: most of the cdinfo() calls are commented out here,
2481 the drive. */ 2753 * because they fill up the sys log when CD players poll
2754 * the drive.
2755 */
2482 switch (cmd) { 2756 switch (cmd) {
2483 case CDROMSUBCHNL: { 2757 case CDROMSUBCHNL:
2484 struct cdrom_subchnl q; 2758 return cdrom_ioctl_get_subchnl(cdi, argp);
2485 u_char requested, back; 2759 case CDROMREADTOCHDR:
2486 if (!CDROM_CAN(CDC_PLAY_AUDIO)) 2760 return cdrom_ioctl_read_tochdr(cdi, argp);
2487 return -ENOSYS; 2761 case CDROMREADTOCENTRY:
2488 /* cdinfo(CD_DO_IOCTL,"entering CDROMSUBCHNL\n");*/ 2762 return cdrom_ioctl_read_tocentry(cdi, argp);
2489 IOCTL_IN(arg, struct cdrom_subchnl, q); 2763 case CDROMPLAYMSF:
2490 requested = q.cdsc_format; 2764 return cdrom_ioctl_play_msf(cdi, argp);
2491 if (!((requested == CDROM_MSF) || 2765 case CDROMPLAYTRKIND:
2492 (requested == CDROM_LBA))) 2766 return cdrom_ioctl_play_trkind(cdi, argp);
2493 return -EINVAL; 2767 case CDROMVOLCTRL:
2494 q.cdsc_format = CDROM_MSF; 2768 return cdrom_ioctl_volctrl(cdi, argp);
2495 if ((ret=cdo->audio_ioctl(cdi, cmd, &q))) 2769 case CDROMVOLREAD:
2496 return ret; 2770 return cdrom_ioctl_volread(cdi, argp);
2497 back = q.cdsc_format; /* local copy */
2498 sanitize_format(&q.cdsc_absaddr, &back, requested);
2499 sanitize_format(&q.cdsc_reladdr, &q.cdsc_format, requested);
2500 IOCTL_OUT(arg, struct cdrom_subchnl, q);
2501 /* cdinfo(CD_DO_IOCTL, "CDROMSUBCHNL successful\n"); */
2502 return 0;
2503 }
2504 case CDROMREADTOCHDR: {
2505 struct cdrom_tochdr header;
2506 if (!CDROM_CAN(CDC_PLAY_AUDIO))
2507 return -ENOSYS;
2508 /* cdinfo(CD_DO_IOCTL, "entering CDROMREADTOCHDR\n"); */
2509 IOCTL_IN(arg, struct cdrom_tochdr, header);
2510 if ((ret=cdo->audio_ioctl(cdi, cmd, &header)))
2511 return ret;
2512 IOCTL_OUT(arg, struct cdrom_tochdr, header);
2513 /* cdinfo(CD_DO_IOCTL, "CDROMREADTOCHDR successful\n"); */
2514 return 0;
2515 }
2516 case CDROMREADTOCENTRY: {
2517 struct cdrom_tocentry entry;
2518 u_char requested_format;
2519 if (!CDROM_CAN(CDC_PLAY_AUDIO))
2520 return -ENOSYS;
2521 /* cdinfo(CD_DO_IOCTL, "entering CDROMREADTOCENTRY\n"); */
2522 IOCTL_IN(arg, struct cdrom_tocentry, entry);
2523 requested_format = entry.cdte_format;
2524 if (!((requested_format == CDROM_MSF) ||
2525 (requested_format == CDROM_LBA)))
2526 return -EINVAL;
2527 /* make interface to low-level uniform */
2528 entry.cdte_format = CDROM_MSF;
2529 if ((ret=cdo->audio_ioctl(cdi, cmd, &entry)))
2530 return ret;
2531 sanitize_format(&entry.cdte_addr,
2532 &entry.cdte_format, requested_format);
2533 IOCTL_OUT(arg, struct cdrom_tocentry, entry);
2534 /* cdinfo(CD_DO_IOCTL, "CDROMREADTOCENTRY successful\n"); */
2535 return 0;
2536 }
2537 case CDROMPLAYMSF: {
2538 struct cdrom_msf msf;
2539 if (!CDROM_CAN(CDC_PLAY_AUDIO))
2540 return -ENOSYS;
2541 cdinfo(CD_DO_IOCTL, "entering CDROMPLAYMSF\n");
2542 IOCTL_IN(arg, struct cdrom_msf, msf);
2543 return cdo->audio_ioctl(cdi, cmd, &msf);
2544 }
2545 case CDROMPLAYTRKIND: {
2546 struct cdrom_ti ti;
2547 if (!CDROM_CAN(CDC_PLAY_AUDIO))
2548 return -ENOSYS;
2549 cdinfo(CD_DO_IOCTL, "entering CDROMPLAYTRKIND\n");
2550 IOCTL_IN(arg, struct cdrom_ti, ti);
2551 CHECKAUDIO;
2552 return cdo->audio_ioctl(cdi, cmd, &ti);
2553 }
2554 case CDROMVOLCTRL: {
2555 struct cdrom_volctrl volume;
2556 if (!CDROM_CAN(CDC_PLAY_AUDIO))
2557 return -ENOSYS;
2558 cdinfo(CD_DO_IOCTL, "entering CDROMVOLCTRL\n");
2559 IOCTL_IN(arg, struct cdrom_volctrl, volume);
2560 return cdo->audio_ioctl(cdi, cmd, &volume);
2561 }
2562 case CDROMVOLREAD: {
2563 struct cdrom_volctrl volume;
2564 if (!CDROM_CAN(CDC_PLAY_AUDIO))
2565 return -ENOSYS;
2566 cdinfo(CD_DO_IOCTL, "entering CDROMVOLREAD\n");
2567 if ((ret=cdo->audio_ioctl(cdi, cmd, &volume)))
2568 return ret;
2569 IOCTL_OUT(arg, struct cdrom_volctrl, volume);
2570 return 0;
2571 }
2572 case CDROMSTART: 2771 case CDROMSTART:
2573 case CDROMSTOP: 2772 case CDROMSTOP:
2574 case CDROMPAUSE: 2773 case CDROMPAUSE:
2575 case CDROMRESUME: { 2774 case CDROMRESUME:
2576 if (!CDROM_CAN(CDC_PLAY_AUDIO)) 2775 return cdrom_ioctl_audioctl(cdi, cmd);
2577 return -ENOSYS; 2776 }
2578 cdinfo(CD_DO_IOCTL, "doing audio ioctl (start/stop/pause/resume)\n");
2579 CHECKAUDIO;
2580 return cdo->audio_ioctl(cdi, cmd, NULL);
2581 }
2582 } /* switch */
2583 2777
2584 /* do the device specific ioctls */
2585 if (CDROM_CAN(CDC_IOCTLS))
2586 return cdo->dev_ioctl(cdi, cmd, arg);
2587
2588 return -ENOSYS; 2778 return -ENOSYS;
2589} 2779}
2590 2780
diff --git a/drivers/cdrom/cdu31a.c b/drivers/cdrom/cdu31a.c
index 378e88d207..72ffd64e8b 100644
--- a/drivers/cdrom/cdu31a.c
+++ b/drivers/cdrom/cdu31a.c
@@ -2668,7 +2668,7 @@ static int scd_audio_ioctl(struct cdrom_device_info *cdi,
2668 return retval; 2668 return retval;
2669} 2669}
2670 2670
2671static int scd_dev_ioctl(struct cdrom_device_info *cdi, 2671static int scd_read_audio(struct cdrom_device_info *cdi,
2672 unsigned int cmd, unsigned long arg) 2672 unsigned int cmd, unsigned long arg)
2673{ 2673{
2674 void __user *argp = (void __user *)arg; 2674 void __user *argp = (void __user *)arg;
@@ -2894,11 +2894,10 @@ static struct cdrom_device_ops scd_dops = {
2894 .get_mcn = scd_get_mcn, 2894 .get_mcn = scd_get_mcn,
2895 .reset = scd_reset, 2895 .reset = scd_reset,
2896 .audio_ioctl = scd_audio_ioctl, 2896 .audio_ioctl = scd_audio_ioctl,
2897 .dev_ioctl = scd_dev_ioctl,
2898 .capability = CDC_OPEN_TRAY | CDC_CLOSE_TRAY | CDC_LOCK | 2897 .capability = CDC_OPEN_TRAY | CDC_CLOSE_TRAY | CDC_LOCK |
2899 CDC_SELECT_SPEED | CDC_MULTI_SESSION | 2898 CDC_SELECT_SPEED | CDC_MULTI_SESSION |
2900 CDC_MCN | CDC_MEDIA_CHANGED | CDC_PLAY_AUDIO | 2899 CDC_MCN | CDC_MEDIA_CHANGED | CDC_PLAY_AUDIO |
2901 CDC_RESET | CDC_IOCTLS | CDC_DRIVE_STATUS, 2900 CDC_RESET | CDC_DRIVE_STATUS,
2902 .n_minors = 1, 2901 .n_minors = 1,
2903}; 2902};
2904 2903
@@ -2936,6 +2935,9 @@ static int scd_block_ioctl(struct inode *inode, struct file *file,
2936 case CDROMCLOSETRAY: 2935 case CDROMCLOSETRAY:
2937 retval = scd_tray_move(&scd_info, 0); 2936 retval = scd_tray_move(&scd_info, 0);
2938 break; 2937 break;
2938 case CDROMREADAUDIO:
2939 retval = scd_read_audio(&scd_info, CDROMREADAUDIO, arg);
2940 break;
2939 default: 2941 default:
2940 retval = cdrom_ioctl(file, &scd_info, inode, cmd, arg); 2942 retval = cdrom_ioctl(file, &scd_info, inode, cmd, arg);
2941 } 2943 }
diff --git a/drivers/cdrom/cm206.c b/drivers/cdrom/cm206.c
index ce127f7ec0..fad27a87ce 100644
--- a/drivers/cdrom/cm206.c
+++ b/drivers/cdrom/cm206.c
@@ -1157,32 +1157,6 @@ static int cm206_audio_ioctl(struct cdrom_device_info *cdi, unsigned int cmd,
1157 } 1157 }
1158} 1158}
1159 1159
1160/* Ioctl. These ioctls are specific to the cm206 driver. I have made
1161 some driver statistics accessible through ioctl calls.
1162 */
1163
1164static int cm206_ioctl(struct cdrom_device_info *cdi, unsigned int cmd,
1165 unsigned long arg)
1166{
1167 switch (cmd) {
1168#ifdef STATISTICS
1169 case CM206CTL_GET_STAT:
1170 if (arg >= NR_STATS)
1171 return -EINVAL;
1172 else
1173 return cd->stats[arg];
1174 case CM206CTL_GET_LAST_STAT:
1175 if (arg >= NR_STATS)
1176 return -EINVAL;
1177 else
1178 return cd->last_stat[arg];
1179#endif
1180 default:
1181 debug(("Unknown ioctl call 0x%x\n", cmd));
1182 return -EINVAL;
1183 }
1184}
1185
1186static int cm206_media_changed(struct cdrom_device_info *cdi, int disc_nr) 1160static int cm206_media_changed(struct cdrom_device_info *cdi, int disc_nr)
1187{ 1161{
1188 if (cd != NULL) { 1162 if (cd != NULL) {
@@ -1321,11 +1295,10 @@ static struct cdrom_device_ops cm206_dops = {
1321 .get_mcn = cm206_get_upc, 1295 .get_mcn = cm206_get_upc,
1322 .reset = cm206_reset, 1296 .reset = cm206_reset,
1323 .audio_ioctl = cm206_audio_ioctl, 1297 .audio_ioctl = cm206_audio_ioctl,
1324 .dev_ioctl = cm206_ioctl,
1325 .capability = CDC_CLOSE_TRAY | CDC_OPEN_TRAY | CDC_LOCK | 1298 .capability = CDC_CLOSE_TRAY | CDC_OPEN_TRAY | CDC_LOCK |
1326 CDC_MULTI_SESSION | CDC_MEDIA_CHANGED | 1299 CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
1327 CDC_MCN | CDC_PLAY_AUDIO | CDC_SELECT_SPEED | 1300 CDC_MCN | CDC_PLAY_AUDIO | CDC_SELECT_SPEED |
1328 CDC_IOCTLS | CDC_DRIVE_STATUS, 1301 CDC_DRIVE_STATUS,
1329 .n_minors = 1, 1302 .n_minors = 1,
1330}; 1303};
1331 1304
@@ -1350,6 +1323,21 @@ static int cm206_block_release(struct inode *inode, struct file *file)
1350static int cm206_block_ioctl(struct inode *inode, struct file *file, 1323static int cm206_block_ioctl(struct inode *inode, struct file *file,
1351 unsigned cmd, unsigned long arg) 1324 unsigned cmd, unsigned long arg)
1352{ 1325{
1326 switch (cmd) {
1327#ifdef STATISTICS
1328 case CM206CTL_GET_STAT:
1329 if (arg >= NR_STATS)
1330 return -EINVAL;
1331 return cd->stats[arg];
1332 case CM206CTL_GET_LAST_STAT:
1333 if (arg >= NR_STATS)
1334 return -EINVAL;
1335 return cd->last_stat[arg];
1336#endif
1337 default:
1338 break;
1339 }
1340
1353 return cdrom_ioctl(file, &cm206_info, inode, cmd, arg); 1341 return cdrom_ioctl(file, &cm206_info, inode, cmd, arg);
1354} 1342}
1355 1343
diff --git a/drivers/cdrom/sbpcd.c b/drivers/cdrom/sbpcd.c
index 466e9c2974..4760f515f5 100644
--- a/drivers/cdrom/sbpcd.c
+++ b/drivers/cdrom/sbpcd.c
@@ -4160,332 +4160,6 @@ static int sbpcd_get_last_session(struct cdrom_device_info *cdi, struct cdrom_mu
4160 return 0; 4160 return 0;
4161} 4161}
4162 4162
4163/*==========================================================================*/
4164/*==========================================================================*/
4165/*
4166 * ioctl support
4167 */
4168static int sbpcd_dev_ioctl(struct cdrom_device_info *cdi, u_int cmd,
4169 u_long arg)
4170{
4171 struct sbpcd_drive *p = cdi->handle;
4172 int i;
4173
4174 msg(DBG_IO2,"ioctl(%s, 0x%08lX, 0x%08lX)\n", cdi->name, cmd, arg);
4175 if (p->drv_id==-1) {
4176 msg(DBG_INF, "ioctl: bad device: %s\n", cdi->name);
4177 return (-ENXIO); /* no such drive */
4178 }
4179 down(&ioctl_read_sem);
4180 if (p != current_drive)
4181 switch_drive(p);
4182
4183 msg(DBG_IO2,"ioctl: device %s, request %04X\n",cdi->name,cmd);
4184 switch (cmd) /* Sun-compatible */
4185 {
4186 case DDIOCSDBG: /* DDI Debug */
4187 if (!capable(CAP_SYS_ADMIN)) RETURN_UP(-EPERM);
4188 i=sbpcd_dbg_ioctl(arg,1);
4189 RETURN_UP(i);
4190 case CDROMRESET: /* hard reset the drive */
4191 msg(DBG_IOC,"ioctl: CDROMRESET entered.\n");
4192 i=DriveReset();
4193 current_drive->audio_state=0;
4194 RETURN_UP(i);
4195
4196 case CDROMREADMODE1:
4197 msg(DBG_IOC,"ioctl: CDROMREADMODE1 requested.\n");
4198#ifdef SAFE_MIXED
4199 if (current_drive->has_data>1) RETURN_UP(-EBUSY);
4200#endif /* SAFE_MIXED */
4201 cc_ModeSelect(CD_FRAMESIZE);
4202 cc_ModeSense();
4203 current_drive->mode=READ_M1;
4204 RETURN_UP(0);
4205
4206 case CDROMREADMODE2: /* not usable at the moment */
4207 msg(DBG_IOC,"ioctl: CDROMREADMODE2 requested.\n");
4208#ifdef SAFE_MIXED
4209 if (current_drive->has_data>1) RETURN_UP(-EBUSY);
4210#endif /* SAFE_MIXED */
4211 cc_ModeSelect(CD_FRAMESIZE_RAW1);
4212 cc_ModeSense();
4213 current_drive->mode=READ_M2;
4214 RETURN_UP(0);
4215
4216 case CDROMAUDIOBUFSIZ: /* configure the audio buffer size */
4217 msg(DBG_IOC,"ioctl: CDROMAUDIOBUFSIZ entered.\n");
4218 if (current_drive->sbp_audsiz>0)
4219 vfree(current_drive->aud_buf);
4220 current_drive->aud_buf=NULL;
4221 current_drive->sbp_audsiz=arg;
4222
4223 if (current_drive->sbp_audsiz>16)
4224 {
4225 current_drive->sbp_audsiz = 0;
4226 RETURN_UP(current_drive->sbp_audsiz);
4227 }
4228
4229 if (current_drive->sbp_audsiz>0)
4230 {
4231 current_drive->aud_buf=(u_char *) vmalloc(current_drive->sbp_audsiz*CD_FRAMESIZE_RAW);
4232 if (current_drive->aud_buf==NULL)
4233 {
4234 msg(DBG_INF,"audio buffer (%d frames) not available.\n",current_drive->sbp_audsiz);
4235 current_drive->sbp_audsiz=0;
4236 }
4237 else msg(DBG_INF,"audio buffer size: %d frames.\n",current_drive->sbp_audsiz);
4238 }
4239 RETURN_UP(current_drive->sbp_audsiz);
4240
4241 case CDROMREADAUDIO:
4242 { /* start of CDROMREADAUDIO */
4243 int i=0, j=0, frame, block=0;
4244 u_int try=0;
4245 u_long timeout;
4246 u_char *p;
4247 u_int data_tries = 0;
4248 u_int data_waits = 0;
4249 u_int data_retrying = 0;
4250 int status_tries;
4251 int error_flag;
4252
4253 msg(DBG_IOC,"ioctl: CDROMREADAUDIO entered.\n");
4254 if (fam0_drive) RETURN_UP(-EINVAL);
4255 if (famL_drive) RETURN_UP(-EINVAL);
4256 if (famV_drive) RETURN_UP(-EINVAL);
4257 if (famT_drive) RETURN_UP(-EINVAL);
4258#ifdef SAFE_MIXED
4259 if (current_drive->has_data>1) RETURN_UP(-EBUSY);
4260#endif /* SAFE_MIXED */
4261 if (current_drive->aud_buf==NULL) RETURN_UP(-EINVAL);
4262 if (copy_from_user(&read_audio, (void __user *)arg,
4263 sizeof(struct cdrom_read_audio)))
4264 RETURN_UP(-EFAULT);
4265 if (read_audio.nframes < 0 || read_audio.nframes>current_drive->sbp_audsiz) RETURN_UP(-EINVAL);
4266 if (!access_ok(VERIFY_WRITE, read_audio.buf,
4267 read_audio.nframes*CD_FRAMESIZE_RAW))
4268 RETURN_UP(-EFAULT);
4269
4270 if (read_audio.addr_format==CDROM_MSF) /* MSF-bin specification of where to start */
4271 block=msf2lba(&read_audio.addr.msf.minute);
4272 else if (read_audio.addr_format==CDROM_LBA) /* lba specification of where to start */
4273 block=read_audio.addr.lba;
4274 else RETURN_UP(-EINVAL);
4275#if 000
4276 i=cc_SetSpeed(speed_150,0,0);
4277 if (i) msg(DBG_AUD,"read_audio: SetSpeed error %d\n", i);
4278#endif
4279 msg(DBG_AUD,"read_audio: lba: %d, msf: %06X\n",
4280 block, blk2msf(block));
4281 msg(DBG_AUD,"read_audio: before cc_ReadStatus.\n");
4282#if OLD_BUSY
4283 while (busy_data) sbp_sleep(HZ/10); /* wait a bit */
4284 busy_audio=1;
4285#endif /* OLD_BUSY */
4286 error_flag=0;
4287 for (data_tries=5; data_tries>0; data_tries--)
4288 {
4289 msg(DBG_AUD,"data_tries=%d ...\n", data_tries);
4290 current_drive->mode=READ_AU;
4291 cc_ModeSelect(CD_FRAMESIZE_RAW);
4292 cc_ModeSense();
4293 for (status_tries=3; status_tries > 0; status_tries--)
4294 {
4295 flags_cmd_out |= f_respo3;
4296 cc_ReadStatus();
4297 if (sbp_status() != 0) break;
4298 if (st_check) cc_ReadError();
4299 sbp_sleep(1); /* wait a bit, try again */
4300 }
4301 if (status_tries == 0)
4302 {
4303 msg(DBG_AUD,"read_audio: sbp_status: failed after 3 tries in line %d.\n", __LINE__);
4304 continue;
4305 }
4306 msg(DBG_AUD,"read_audio: sbp_status: ok.\n");
4307
4308 flags_cmd_out = f_putcmd | f_respo2 | f_ResponseStatus | f_obey_p_check;
4309 if (fam0L_drive)
4310 {
4311 flags_cmd_out |= f_lopsta | f_getsta | f_bit1;
4312 cmd_type=READ_M2;
4313 drvcmd[0]=CMD0_READ_XA; /* "read XA frames", old drives */
4314 drvcmd[1]=(block>>16)&0x000000ff;
4315 drvcmd[2]=(block>>8)&0x000000ff;
4316 drvcmd[3]=block&0x000000ff;
4317 drvcmd[4]=0;
4318 drvcmd[5]=read_audio.nframes; /* # of frames */
4319 drvcmd[6]=0;
4320 }
4321 else if (fam1_drive)
4322 {
4323 drvcmd[0]=CMD1_READ; /* "read frames", new drives */
4324 lba2msf(block,&drvcmd[1]); /* msf-bin format required */
4325 drvcmd[4]=0;
4326 drvcmd[5]=0;
4327 drvcmd[6]=read_audio.nframes; /* # of frames */
4328 }
4329 else if (fam2_drive)
4330 {
4331 drvcmd[0]=CMD2_READ_XA2;
4332 lba2msf(block,&drvcmd[1]); /* msf-bin format required */
4333 drvcmd[4]=0;
4334 drvcmd[5]=read_audio.nframes; /* # of frames */
4335 drvcmd[6]=0x11; /* raw mode */
4336 }
4337 else if (famT_drive) /* CD-55A: not tested yet */
4338 {
4339 }
4340 msg(DBG_AUD,"read_audio: before giving \"read\" command.\n");
4341 flags_cmd_out=f_putcmd;
4342 response_count=0;
4343 i=cmd_out();
4344 if (i<0) msg(DBG_INF,"error giving READ AUDIO command: %0d\n", i);
4345 sbp_sleep(0);
4346 msg(DBG_AUD,"read_audio: after giving \"read\" command.\n");
4347 for (frame=1;frame<2 && !error_flag; frame++)
4348 {
4349 try=maxtim_data;
4350 for (timeout=jiffies+9*HZ; ; )
4351 {
4352 for ( ; try!=0;try--)
4353 {
4354 j=inb(CDi_status);
4355 if (!(j&s_not_data_ready)) break;
4356 if (!(j&s_not_result_ready)) break;
4357 if (fam0L_drive) if (j&s_attention) break;
4358 }
4359 if (try != 0 || time_after_eq(jiffies, timeout)) break;
4360 if (data_retrying == 0) data_waits++;
4361 data_retrying = 1;
4362 sbp_sleep(1);
4363 try = 1;
4364 }
4365 if (try==0)
4366 {
4367 msg(DBG_INF,"read_audio: sbp_data: CDi_status timeout.\n");
4368 error_flag++;
4369 break;
4370 }
4371 msg(DBG_AUD,"read_audio: sbp_data: CDi_status ok.\n");
4372 if (j&s_not_data_ready)
4373 {
4374 msg(DBG_INF, "read_audio: sbp_data: DATA_READY timeout.\n");
4375 error_flag++;
4376 break;
4377 }
4378 msg(DBG_AUD,"read_audio: before reading data.\n");
4379 error_flag=0;
4380 p = current_drive->aud_buf;
4381 if (sbpro_type==1) OUT(CDo_sel_i_d,1);
4382 if (do_16bit)
4383 {
4384 u_short *p2 = (u_short *) p;
4385
4386 for (; (u_char *) p2 < current_drive->aud_buf + read_audio.nframes*CD_FRAMESIZE_RAW;)
4387 {
4388 if ((inb_p(CDi_status)&s_not_data_ready)) continue;
4389
4390 /* get one sample */
4391 *p2++ = inw_p(CDi_data);
4392 *p2++ = inw_p(CDi_data);
4393 }
4394 } else {
4395 for (; p < current_drive->aud_buf + read_audio.nframes*CD_FRAMESIZE_RAW;)
4396 {
4397 if ((inb_p(CDi_status)&s_not_data_ready)) continue;
4398
4399 /* get one sample */
4400 *p++ = inb_p(CDi_data);
4401 *p++ = inb_p(CDi_data);
4402 *p++ = inb_p(CDi_data);
4403 *p++ = inb_p(CDi_data);
4404 }
4405 }
4406 if (sbpro_type==1) OUT(CDo_sel_i_d,0);
4407 data_retrying = 0;
4408 }
4409 msg(DBG_AUD,"read_audio: after reading data.\n");
4410 if (error_flag) /* must have been spurious D_RDY or (ATTN&&!D_RDY) */
4411 {
4412 msg(DBG_AUD,"read_audio: read aborted by drive\n");
4413#if 0000
4414 i=cc_DriveReset(); /* ugly fix to prevent a hang */
4415#else
4416 i=cc_ReadError();
4417#endif
4418 continue;
4419 }
4420 if (fam0L_drive)
4421 {
4422 i=maxtim_data;
4423 for (timeout=jiffies+9*HZ; time_before(jiffies, timeout); timeout--)
4424 {
4425 for ( ;i!=0;i--)
4426 {
4427 j=inb(CDi_status);
4428 if (!(j&s_not_data_ready)) break;
4429 if (!(j&s_not_result_ready)) break;
4430 if (j&s_attention) break;
4431 }
4432 if (i != 0 || time_after_eq(jiffies, timeout)) break;
4433 sbp_sleep(0);
4434 i = 1;
4435 }
4436 if (i==0) msg(DBG_AUD,"read_audio: STATUS TIMEOUT AFTER READ");
4437 if (!(j&s_attention))
4438 {
4439 msg(DBG_AUD,"read_audio: sbp_data: timeout waiting DRV_ATTN - retrying\n");
4440 i=cc_DriveReset(); /* ugly fix to prevent a hang */
4441 continue;
4442 }
4443 }
4444 do
4445 {
4446 if (fam0L_drive) cc_ReadStatus();
4447 i=ResponseStatus(); /* builds status_bits, returns orig. status (old) or faked p_success (new) */
4448 if (i<0) { msg(DBG_AUD,
4449 "read_audio: cc_ReadStatus error after read: %02X\n",
4450 current_drive->status_bits);
4451 continue; /* FIXME */
4452 }
4453 }
4454 while ((fam0L_drive)&&(!st_check)&&(!(i&p_success)));
4455 if (st_check)
4456 {
4457 i=cc_ReadError();
4458 msg(DBG_AUD,"read_audio: cc_ReadError was necessary after read: %02X\n",i);
4459 continue;
4460 }
4461 if (copy_to_user(read_audio.buf,
4462 current_drive->aud_buf,
4463 read_audio.nframes * CD_FRAMESIZE_RAW))
4464 RETURN_UP(-EFAULT);
4465 msg(DBG_AUD,"read_audio: copy_to_user done.\n");
4466 break;
4467 }
4468 cc_ModeSelect(CD_FRAMESIZE);
4469 cc_ModeSense();
4470 current_drive->mode=READ_M1;
4471#if OLD_BUSY
4472 busy_audio=0;
4473#endif /* OLD_BUSY */
4474 if (data_tries == 0)
4475 {
4476 msg(DBG_AUD,"read_audio: failed after 5 tries in line %d.\n", __LINE__);
4477 RETURN_UP(-EIO);
4478 }
4479 msg(DBG_AUD,"read_audio: successful return.\n");
4480 RETURN_UP(0);
4481 } /* end of CDROMREADAUDIO */
4482
4483 default:
4484 msg(DBG_IOC,"ioctl: unknown function request %04X\n", cmd);
4485 RETURN_UP(-EINVAL);
4486 } /* end switch(cmd) */
4487}
4488
4489static int sbpcd_audio_ioctl(struct cdrom_device_info *cdi, u_int cmd, 4163static int sbpcd_audio_ioctl(struct cdrom_device_info *cdi, u_int cmd,
4490 void * arg) 4164 void * arg)
4491{ 4165{
@@ -4530,7 +4204,7 @@ static int sbpcd_audio_ioctl(struct cdrom_device_info *cdi, u_int cmd,
4530 default: 4204 default:
4531 RETURN_UP(-EINVAL); 4205 RETURN_UP(-EINVAL);
4532 } 4206 }
4533 4207
4534 case CDROMRESUME: /* resume paused audio play */ 4208 case CDROMRESUME: /* resume paused audio play */
4535 msg(DBG_IOC,"ioctl: CDROMRESUME entered.\n"); 4209 msg(DBG_IOC,"ioctl: CDROMRESUME entered.\n");
4536 /* resume playing audio tracks when a previous PLAY AUDIO call has */ 4210 /* resume playing audio tracks when a previous PLAY AUDIO call has */
@@ -4544,12 +4218,12 @@ static int sbpcd_audio_ioctl(struct cdrom_device_info *cdi, u_int cmd,
4544 if (i<0) RETURN_UP(-EIO); 4218 if (i<0) RETURN_UP(-EIO);
4545 current_drive->audio_state=audio_playing; 4219 current_drive->audio_state=audio_playing;
4546 RETURN_UP(0); 4220 RETURN_UP(0);
4547 4221
4548 case CDROMPLAYMSF: 4222 case CDROMPLAYMSF:
4549 msg(DBG_IOC,"ioctl: CDROMPLAYMSF entered.\n"); 4223 msg(DBG_IOC,"ioctl: CDROMPLAYMSF entered.\n");
4550#ifdef SAFE_MIXED 4224#ifdef SAFE_MIXED
4551 if (current_drive->has_data>1) RETURN_UP(-EBUSY); 4225 if (current_drive->has_data>1) RETURN_UP(-EBUSY);
4552#endif /* SAFE_MIXED */ 4226#endif /* SAFE_MIXED */
4553 if (current_drive->audio_state==audio_playing) 4227 if (current_drive->audio_state==audio_playing)
4554 { 4228 {
4555 i=cc_Pause_Resume(1); 4229 i=cc_Pause_Resume(1);
@@ -4584,7 +4258,7 @@ static int sbpcd_audio_ioctl(struct cdrom_device_info *cdi, u_int cmd,
4584 msg(DBG_IOC,"ioctl: CDROMPLAYTRKIND entered.\n"); 4258 msg(DBG_IOC,"ioctl: CDROMPLAYTRKIND entered.\n");
4585#ifdef SAFE_MIXED 4259#ifdef SAFE_MIXED
4586 if (current_drive->has_data>1) RETURN_UP(-EBUSY); 4260 if (current_drive->has_data>1) RETURN_UP(-EBUSY);
4587#endif /* SAFE_MIXED */ 4261#endif /* SAFE_MIXED */
4588 if (current_drive->audio_state==audio_playing) 4262 if (current_drive->audio_state==audio_playing)
4589 { 4263 {
4590 msg(DBG_IOX,"CDROMPLAYTRKIND: already audio_playing.\n"); 4264 msg(DBG_IOX,"CDROMPLAYTRKIND: already audio_playing.\n");
@@ -4654,13 +4328,13 @@ static int sbpcd_audio_ioctl(struct cdrom_device_info *cdi, u_int cmd,
4654 cc_DriveReset(); 4328 cc_DriveReset();
4655#endif 4329#endif
4656 RETURN_UP(i); 4330 RETURN_UP(i);
4657 4331
4658 case CDROMSTART: /* Spin up the drive */ 4332 case CDROMSTART: /* Spin up the drive */
4659 msg(DBG_IOC,"ioctl: CDROMSTART entered.\n"); 4333 msg(DBG_IOC,"ioctl: CDROMSTART entered.\n");
4660 cc_SpinUp(); 4334 cc_SpinUp();
4661 current_drive->audio_state=0; 4335 current_drive->audio_state=0;
4662 RETURN_UP(0); 4336 RETURN_UP(0);
4663 4337
4664 case CDROMVOLCTRL: /* Volume control */ 4338 case CDROMVOLCTRL: /* Volume control */
4665 msg(DBG_IOC,"ioctl: CDROMVOLCTRL entered.\n"); 4339 msg(DBG_IOC,"ioctl: CDROMVOLCTRL entered.\n");
4666 memcpy(&volctrl,(char *) arg,sizeof(volctrl)); 4340 memcpy(&volctrl,(char *) arg,sizeof(volctrl));
@@ -4670,7 +4344,7 @@ static int sbpcd_audio_ioctl(struct cdrom_device_info *cdi, u_int cmd,
4670 current_drive->vol_ctrl1=volctrl.channel1; 4344 current_drive->vol_ctrl1=volctrl.channel1;
4671 i=cc_SetVolume(); 4345 i=cc_SetVolume();
4672 RETURN_UP(0); 4346 RETURN_UP(0);
4673 4347
4674 case CDROMVOLREAD: /* read Volume settings from drive */ 4348 case CDROMVOLREAD: /* read Volume settings from drive */
4675 msg(DBG_IOC,"ioctl: CDROMVOLREAD entered.\n"); 4349 msg(DBG_IOC,"ioctl: CDROMVOLREAD entered.\n");
4676 st=cc_GetVolume(); 4350 st=cc_GetVolume();
@@ -4694,7 +4368,7 @@ static int sbpcd_audio_ioctl(struct cdrom_device_info *cdi, u_int cmd,
4694 if (i<0) { 4368 if (i<0) {
4695 j=cc_ReadError(); /* clear out error status from drive */ 4369 j=cc_ReadError(); /* clear out error status from drive */
4696 current_drive->audio_state=CDROM_AUDIO_NO_STATUS; 4370 current_drive->audio_state=CDROM_AUDIO_NO_STATUS;
4697 /* get and set the disk state here, 4371 /* get and set the disk state here,
4698 probably not the right place, but who cares! 4372 probably not the right place, but who cares!
4699 It makes it work properly! --AJK */ 4373 It makes it work properly! --AJK */
4700 if (current_drive->CD_changed==0xFF) { 4374 if (current_drive->CD_changed==0xFF) {
@@ -4715,8 +4389,8 @@ static int sbpcd_audio_ioctl(struct cdrom_device_info *cdi, u_int cmd,
4715 } 4389 }
4716 } 4390 }
4717 memcpy(&SC, (void *) arg, sizeof(struct cdrom_subchnl)); 4391 memcpy(&SC, (void *) arg, sizeof(struct cdrom_subchnl));
4718 /* 4392 /*
4719 This virtual crap is very bogus! 4393 This virtual crap is very bogus!
4720 It doesn't detect when the cd is done playing audio! 4394 It doesn't detect when the cd is done playing audio!
4721 Lets do this right with proper hardware register reading! 4395 Lets do this right with proper hardware register reading!
4722 */ 4396 */
@@ -4775,7 +4449,7 @@ static int sbpcd_audio_ioctl(struct cdrom_device_info *cdi, u_int cmd,
4775 SC.cdsc_trk,SC.cdsc_ind, 4449 SC.cdsc_trk,SC.cdsc_ind,
4776 SC.cdsc_absaddr,SC.cdsc_reladdr); 4450 SC.cdsc_absaddr,SC.cdsc_reladdr);
4777 RETURN_UP(0); 4451 RETURN_UP(0);
4778 4452
4779 default: 4453 default:
4780 msg(DBG_IOC,"ioctl: unknown function request %04X\n", cmd); 4454 msg(DBG_IOC,"ioctl: unknown function request %04X\n", cmd);
4781 RETURN_UP(-EINVAL); 4455 RETURN_UP(-EINVAL);
@@ -4788,7 +4462,7 @@ static int sbpcd_audio_ioctl(struct cdrom_device_info *cdi, u_int cmd,
4788static void sbp_transfer(struct request *req) 4462static void sbp_transfer(struct request *req)
4789{ 4463{
4790 long offs; 4464 long offs;
4791 4465
4792 while ( (req->nr_sectors > 0) && 4466 while ( (req->nr_sectors > 0) &&
4793 (req->sector/4 >= current_drive->sbp_first_frame) && 4467 (req->sector/4 >= current_drive->sbp_first_frame) &&
4794 (req->sector/4 <= current_drive->sbp_last_frame) ) 4468 (req->sector/4 <= current_drive->sbp_last_frame) )
@@ -4807,11 +4481,11 @@ static void sbp_transfer(struct request *req)
4807 * 4481 *
4808 * This is a kludge so we don't need to modify end_request. 4482 * This is a kludge so we don't need to modify end_request.
4809 * We put the req we take out after INIT_REQUEST in the requests list, 4483 * We put the req we take out after INIT_REQUEST in the requests list,
4810 * so that end_request will discard it. 4484 * so that end_request will discard it.
4811 * 4485 *
4812 * The bug could be present in other block devices, perhaps we 4486 * The bug could be present in other block devices, perhaps we
4813 * should modify INIT_REQUEST and end_request instead, and 4487 * should modify INIT_REQUEST and end_request instead, and
4814 * change every block device.. 4488 * change every block device..
4815 * 4489 *
4816 * Could be a race here?? Could e.g. a timer interrupt schedule() us? 4490 * Could be a race here?? Could e.g. a timer interrupt schedule() us?
4817 * If so, we should copy end_request here, and do it right.. (or 4491 * If so, we should copy end_request here, and do it right.. (or
@@ -4883,19 +4557,19 @@ static void do_sbpcd_request(request_queue_t * q)
4883 while (busy_audio) sbp_sleep(HZ); /* wait a bit */ 4557 while (busy_audio) sbp_sleep(HZ); /* wait a bit */
4884 busy_data=1; 4558 busy_data=1;
4885#endif /* OLD_BUSY */ 4559#endif /* OLD_BUSY */
4886 4560
4887 if (p->audio_state==audio_playing) goto err_done; 4561 if (p->audio_state==audio_playing) goto err_done;
4888 if (p != current_drive) 4562 if (p != current_drive)
4889 switch_drive(p); 4563 switch_drive(p);
4890 4564
4891 block = req->sector; /* always numbered as 512-byte-pieces */ 4565 block = req->sector; /* always numbered as 512-byte-pieces */
4892 nsect = req->nr_sectors; /* always counted as 512-byte-pieces */ 4566 nsect = req->nr_sectors; /* always counted as 512-byte-pieces */
4893 4567
4894 msg(DBG_BSZ,"read sector %d (%d sectors)\n", block, nsect); 4568 msg(DBG_BSZ,"read sector %d (%d sectors)\n", block, nsect);
4895#if 0 4569#if 0
4896 msg(DBG_MUL,"read LBA %d\n", block/4); 4570 msg(DBG_MUL,"read LBA %d\n", block/4);
4897#endif 4571#endif
4898 4572
4899 sbp_transfer(req); 4573 sbp_transfer(req);
4900 /* if we satisfied the request from the buffer, we're done. */ 4574 /* if we satisfied the request from the buffer, we're done. */
4901 if (req->nr_sectors == 0) 4575 if (req->nr_sectors == 0)
@@ -4914,10 +4588,10 @@ static void do_sbpcd_request(request_queue_t * q)
4914 i=prepare(0,0); /* at moment not really a hassle check, but ... */ 4588 i=prepare(0,0); /* at moment not really a hassle check, but ... */
4915 if (i!=0) 4589 if (i!=0)
4916 msg(DBG_INF,"\"prepare\" tells error %d -- ignored\n", i); 4590 msg(DBG_INF,"\"prepare\" tells error %d -- ignored\n", i);
4917#endif /* FUTURE */ 4591#endif /* FUTURE */
4918 4592
4919 if (!st_spinning) cc_SpinUp(); 4593 if (!st_spinning) cc_SpinUp();
4920 4594
4921 for (data_tries=n_retries; data_tries > 0; data_tries--) 4595 for (data_tries=n_retries; data_tries > 0; data_tries--)
4922 { 4596 {
4923 for (status_tries=3; status_tries > 0; status_tries--) 4597 for (status_tries=3; status_tries > 0; status_tries--)
@@ -4940,7 +4614,7 @@ static void do_sbpcd_request(request_queue_t * q)
4940 { 4614 {
4941#ifdef SAFE_MIXED 4615#ifdef SAFE_MIXED
4942 current_drive->has_data=2; /* is really a data disk */ 4616 current_drive->has_data=2; /* is really a data disk */
4943#endif /* SAFE_MIXED */ 4617#endif /* SAFE_MIXED */
4944#ifdef DEBUG_GTL 4618#ifdef DEBUG_GTL
4945 printk(" do_sbpcd_request[%do](%p:%ld+%ld) end 3, Time:%li\n", 4619 printk(" do_sbpcd_request[%do](%p:%ld+%ld) end 3, Time:%li\n",
4946 xnr, req, req->sector, req->nr_sectors, jiffies); 4620 xnr, req, req->sector, req->nr_sectors, jiffies);
@@ -4951,7 +4625,7 @@ static void do_sbpcd_request(request_queue_t * q)
4951 goto request_loop; 4625 goto request_loop;
4952 } 4626 }
4953 } 4627 }
4954 4628
4955 err_done: 4629 err_done:
4956#if OLD_BUSY 4630#if OLD_BUSY
4957 busy_data=0; 4631 busy_data=0;
@@ -4976,7 +4650,7 @@ static void sbp_read_cmd(struct request *req)
4976 4650
4977 int i; 4651 int i;
4978 int block; 4652 int block;
4979 4653
4980 current_drive->sbp_first_frame=current_drive->sbp_last_frame=-1; /* purge buffer */ 4654 current_drive->sbp_first_frame=current_drive->sbp_last_frame=-1; /* purge buffer */
4981 current_drive->sbp_current = 0; 4655 current_drive->sbp_current = 0;
4982 block=req->sector/4; 4656 block=req->sector/4;
@@ -4993,7 +4667,7 @@ static void sbp_read_cmd(struct request *req)
4993 current_drive->sbp_read_frames=1; 4667 current_drive->sbp_read_frames=1;
4994 } 4668 }
4995 } 4669 }
4996 4670
4997 flags_cmd_out = f_putcmd | f_respo2 | f_ResponseStatus | f_obey_p_check; 4671 flags_cmd_out = f_putcmd | f_respo2 | f_ResponseStatus | f_obey_p_check;
4998 clr_cmdbuf(); 4672 clr_cmdbuf();
4999 if (famV_drive) 4673 if (famV_drive)
@@ -5092,7 +4766,7 @@ static int sbp_data(struct request *req)
5092 int success; 4766 int success;
5093 int wait; 4767 int wait;
5094 int duration; 4768 int duration;
5095 4769
5096 error_flag=0; 4770 error_flag=0;
5097 success=0; 4771 success=0;
5098#if LONG_TIMING 4772#if LONG_TIMING
@@ -5105,12 +4779,12 @@ static int sbp_data(struct request *req)
5105 for (frame=0;frame<current_drive->sbp_read_frames&&!error_flag; frame++) 4779 for (frame=0;frame<current_drive->sbp_read_frames&&!error_flag; frame++)
5106 { 4780 {
5107 SBPCD_CLI; 4781 SBPCD_CLI;
5108 4782
5109 del_timer(&data_timer); 4783 del_timer(&data_timer);
5110 data_timer.expires=jiffies+max_latency; 4784 data_timer.expires=jiffies+max_latency;
5111 timed_out_data=0; 4785 timed_out_data=0;
5112 add_timer(&data_timer); 4786 add_timer(&data_timer);
5113 while (!timed_out_data) 4787 while (!timed_out_data)
5114 { 4788 {
5115 if (current_drive->f_multisession) try=maxtim_data*4; 4789 if (current_drive->f_multisession) try=maxtim_data*4;
5116 else try=maxtim_data; 4790 else try=maxtim_data;
@@ -5207,9 +4881,9 @@ static int sbp_data(struct request *req)
5207 else 4881 else
5208 { 4882 {
5209 sbp_sleep(1); 4883 sbp_sleep(1);
5210 OUT(CDo_sel_i_d,0); 4884 OUT(CDo_sel_i_d,0);
5211 i=inb(CDi_status); 4885 i=inb(CDi_status);
5212 } 4886 }
5213 if (!(i&s_not_data_ready)) 4887 if (!(i&s_not_data_ready))
5214 { 4888 {
5215 OUT(CDo_sel_i_d,1); 4889 OUT(CDo_sel_i_d,1);
@@ -5311,7 +4985,7 @@ static int sbp_data(struct request *req)
5311 } 4985 }
5312 SBPCD_STI; 4986 SBPCD_STI;
5313 } 4987 }
5314 4988
5315#if 0 4989#if 0
5316 if (!success) 4990 if (!success)
5317#endif 4991#endif
@@ -5370,7 +5044,326 @@ static int sbpcd_block_ioctl(struct inode *inode, struct file *file,
5370 unsigned cmd, unsigned long arg) 5044 unsigned cmd, unsigned long arg)
5371{ 5045{
5372 struct sbpcd_drive *p = inode->i_bdev->bd_disk->private_data; 5046 struct sbpcd_drive *p = inode->i_bdev->bd_disk->private_data;
5373 return cdrom_ioctl(file, p->sbpcd_infop, inode, cmd, arg); 5047 struct cdrom_device_info *cdi = p->sbpcd_infop;
5048 int ret, i;
5049
5050 ret = cdrom_ioctl(file, p->sbpcd_infop, inode, cmd, arg);
5051 if (ret != -ENOSYS)
5052 return ret;
5053
5054 msg(DBG_IO2,"ioctl(%s, 0x%08lX, 0x%08lX)\n", cdi->name, cmd, arg);
5055 if (p->drv_id==-1) {
5056 msg(DBG_INF, "ioctl: bad device: %s\n", cdi->name);
5057 return (-ENXIO); /* no such drive */
5058 }
5059 down(&ioctl_read_sem);
5060 if (p != current_drive)
5061 switch_drive(p);
5062
5063 msg(DBG_IO2,"ioctl: device %s, request %04X\n",cdi->name,cmd);
5064 switch (cmd) /* Sun-compatible */
5065 {
5066 case DDIOCSDBG: /* DDI Debug */
5067 if (!capable(CAP_SYS_ADMIN)) RETURN_UP(-EPERM);
5068 i=sbpcd_dbg_ioctl(arg,1);
5069 RETURN_UP(i);
5070 case CDROMRESET: /* hard reset the drive */
5071 msg(DBG_IOC,"ioctl: CDROMRESET entered.\n");
5072 i=DriveReset();
5073 current_drive->audio_state=0;
5074 RETURN_UP(i);
5075
5076 case CDROMREADMODE1:
5077 msg(DBG_IOC,"ioctl: CDROMREADMODE1 requested.\n");
5078#ifdef SAFE_MIXED
5079 if (current_drive->has_data>1) RETURN_UP(-EBUSY);
5080#endif /* SAFE_MIXED */
5081 cc_ModeSelect(CD_FRAMESIZE);
5082 cc_ModeSense();
5083 current_drive->mode=READ_M1;
5084 RETURN_UP(0);
5085
5086 case CDROMREADMODE2: /* not usable at the moment */
5087 msg(DBG_IOC,"ioctl: CDROMREADMODE2 requested.\n");
5088#ifdef SAFE_MIXED
5089 if (current_drive->has_data>1) RETURN_UP(-EBUSY);
5090#endif /* SAFE_MIXED */
5091 cc_ModeSelect(CD_FRAMESIZE_RAW1);
5092 cc_ModeSense();
5093 current_drive->mode=READ_M2;
5094 RETURN_UP(0);
5095
5096 case CDROMAUDIOBUFSIZ: /* configure the audio buffer size */
5097 msg(DBG_IOC,"ioctl: CDROMAUDIOBUFSIZ entered.\n");
5098 if (current_drive->sbp_audsiz>0)
5099 vfree(current_drive->aud_buf);
5100 current_drive->aud_buf=NULL;
5101 current_drive->sbp_audsiz=arg;
5102
5103 if (current_drive->sbp_audsiz>16)
5104 {
5105 current_drive->sbp_audsiz = 0;
5106 RETURN_UP(current_drive->sbp_audsiz);
5107 }
5108
5109 if (current_drive->sbp_audsiz>0)
5110 {
5111 current_drive->aud_buf=(u_char *) vmalloc(current_drive->sbp_audsiz*CD_FRAMESIZE_RAW);
5112 if (current_drive->aud_buf==NULL)
5113 {
5114 msg(DBG_INF,"audio buffer (%d frames) not available.\n",current_drive->sbp_audsiz);
5115 current_drive->sbp_audsiz=0;
5116 }
5117 else msg(DBG_INF,"audio buffer size: %d frames.\n",current_drive->sbp_audsiz);
5118 }
5119 RETURN_UP(current_drive->sbp_audsiz);
5120
5121 case CDROMREADAUDIO:
5122 { /* start of CDROMREADAUDIO */
5123 int i=0, j=0, frame, block=0;
5124 u_int try=0;
5125 u_long timeout;
5126 u_char *p;
5127 u_int data_tries = 0;
5128 u_int data_waits = 0;
5129 u_int data_retrying = 0;
5130 int status_tries;
5131 int error_flag;
5132
5133 msg(DBG_IOC,"ioctl: CDROMREADAUDIO entered.\n");
5134 if (fam0_drive) RETURN_UP(-EINVAL);
5135 if (famL_drive) RETURN_UP(-EINVAL);
5136 if (famV_drive) RETURN_UP(-EINVAL);
5137 if (famT_drive) RETURN_UP(-EINVAL);
5138#ifdef SAFE_MIXED
5139 if (current_drive->has_data>1) RETURN_UP(-EBUSY);
5140#endif /* SAFE_MIXED */
5141 if (current_drive->aud_buf==NULL) RETURN_UP(-EINVAL);
5142 if (copy_from_user(&read_audio, (void __user *)arg,
5143 sizeof(struct cdrom_read_audio)))
5144 RETURN_UP(-EFAULT);
5145 if (read_audio.nframes < 0 || read_audio.nframes>current_drive->sbp_audsiz) RETURN_UP(-EINVAL);
5146 if (!access_ok(VERIFY_WRITE, read_audio.buf,
5147 read_audio.nframes*CD_FRAMESIZE_RAW))
5148 RETURN_UP(-EFAULT);
5149
5150 if (read_audio.addr_format==CDROM_MSF) /* MSF-bin specification of where to start */
5151 block=msf2lba(&read_audio.addr.msf.minute);
5152 else if (read_audio.addr_format==CDROM_LBA) /* lba specification of where to start */
5153 block=read_audio.addr.lba;
5154 else RETURN_UP(-EINVAL);
5155#if 000
5156 i=cc_SetSpeed(speed_150,0,0);
5157 if (i) msg(DBG_AUD,"read_audio: SetSpeed error %d\n", i);
5158#endif
5159 msg(DBG_AUD,"read_audio: lba: %d, msf: %06X\n",
5160 block, blk2msf(block));
5161 msg(DBG_AUD,"read_audio: before cc_ReadStatus.\n");
5162#if OLD_BUSY
5163 while (busy_data) sbp_sleep(HZ/10); /* wait a bit */
5164 busy_audio=1;
5165#endif /* OLD_BUSY */
5166 error_flag=0;
5167 for (data_tries=5; data_tries>0; data_tries--)
5168 {
5169 msg(DBG_AUD,"data_tries=%d ...\n", data_tries);
5170 current_drive->mode=READ_AU;
5171 cc_ModeSelect(CD_FRAMESIZE_RAW);
5172 cc_ModeSense();
5173 for (status_tries=3; status_tries > 0; status_tries--)
5174 {
5175 flags_cmd_out |= f_respo3;
5176 cc_ReadStatus();
5177 if (sbp_status() != 0) break;
5178 if (st_check) cc_ReadError();
5179 sbp_sleep(1); /* wait a bit, try again */
5180 }
5181 if (status_tries == 0)
5182 {
5183 msg(DBG_AUD,"read_audio: sbp_status: failed after 3 tries in line %d.\n", __LINE__);
5184 continue;
5185 }
5186 msg(DBG_AUD,"read_audio: sbp_status: ok.\n");
5187
5188 flags_cmd_out = f_putcmd | f_respo2 | f_ResponseStatus | f_obey_p_check;
5189 if (fam0L_drive)
5190 {
5191 flags_cmd_out |= f_lopsta | f_getsta | f_bit1;
5192 cmd_type=READ_M2;
5193 drvcmd[0]=CMD0_READ_XA; /* "read XA frames", old drives */
5194 drvcmd[1]=(block>>16)&0x000000ff;
5195 drvcmd[2]=(block>>8)&0x000000ff;
5196 drvcmd[3]=block&0x000000ff;
5197 drvcmd[4]=0;
5198 drvcmd[5]=read_audio.nframes; /* # of frames */
5199 drvcmd[6]=0;
5200 }
5201 else if (fam1_drive)
5202 {
5203 drvcmd[0]=CMD1_READ; /* "read frames", new drives */
5204 lba2msf(block,&drvcmd[1]); /* msf-bin format required */
5205 drvcmd[4]=0;
5206 drvcmd[5]=0;
5207 drvcmd[6]=read_audio.nframes; /* # of frames */
5208 }
5209 else if (fam2_drive)
5210 {
5211 drvcmd[0]=CMD2_READ_XA2;
5212 lba2msf(block,&drvcmd[1]); /* msf-bin format required */
5213 drvcmd[4]=0;
5214 drvcmd[5]=read_audio.nframes; /* # of frames */
5215 drvcmd[6]=0x11; /* raw mode */
5216 }
5217 else if (famT_drive) /* CD-55A: not tested yet */
5218 {
5219 }
5220 msg(DBG_AUD,"read_audio: before giving \"read\" command.\n");
5221 flags_cmd_out=f_putcmd;
5222 response_count=0;
5223 i=cmd_out();
5224 if (i<0) msg(DBG_INF,"error giving READ AUDIO command: %0d\n", i);
5225 sbp_sleep(0);
5226 msg(DBG_AUD,"read_audio: after giving \"read\" command.\n");
5227 for (frame=1;frame<2 && !error_flag; frame++)
5228 {
5229 try=maxtim_data;
5230 for (timeout=jiffies+9*HZ; ; )
5231 {
5232 for ( ; try!=0;try--)
5233 {
5234 j=inb(CDi_status);
5235 if (!(j&s_not_data_ready)) break;
5236 if (!(j&s_not_result_ready)) break;
5237 if (fam0L_drive) if (j&s_attention) break;
5238 }
5239 if (try != 0 || time_after_eq(jiffies, timeout)) break;
5240 if (data_retrying == 0) data_waits++;
5241 data_retrying = 1;
5242 sbp_sleep(1);
5243 try = 1;
5244 }
5245 if (try==0)
5246 {
5247 msg(DBG_INF,"read_audio: sbp_data: CDi_status timeout.\n");
5248 error_flag++;
5249 break;
5250 }
5251 msg(DBG_AUD,"read_audio: sbp_data: CDi_status ok.\n");
5252 if (j&s_not_data_ready)
5253 {
5254 msg(DBG_INF, "read_audio: sbp_data: DATA_READY timeout.\n");
5255 error_flag++;
5256 break;
5257 }
5258 msg(DBG_AUD,"read_audio: before reading data.\n");
5259 error_flag=0;
5260 p = current_drive->aud_buf;
5261 if (sbpro_type==1) OUT(CDo_sel_i_d,1);
5262 if (do_16bit)
5263 {
5264 u_short *p2 = (u_short *) p;
5265
5266 for (; (u_char *) p2 < current_drive->aud_buf + read_audio.nframes*CD_FRAMESIZE_RAW;)
5267 {
5268 if ((inb_p(CDi_status)&s_not_data_ready)) continue;
5269
5270 /* get one sample */
5271 *p2++ = inw_p(CDi_data);
5272 *p2++ = inw_p(CDi_data);
5273 }
5274 } else {
5275 for (; p < current_drive->aud_buf + read_audio.nframes*CD_FRAMESIZE_RAW;)
5276 {
5277 if ((inb_p(CDi_status)&s_not_data_ready)) continue;
5278
5279 /* get one sample */
5280 *p++ = inb_p(CDi_data);
5281 *p++ = inb_p(CDi_data);
5282 *p++ = inb_p(CDi_data);
5283 *p++ = inb_p(CDi_data);
5284 }
5285 }
5286 if (sbpro_type==1) OUT(CDo_sel_i_d,0);
5287 data_retrying = 0;
5288 }
5289 msg(DBG_AUD,"read_audio: after reading data.\n");
5290 if (error_flag) /* must have been spurious D_RDY or (ATTN&&!D_RDY) */
5291 {
5292 msg(DBG_AUD,"read_audio: read aborted by drive\n");
5293#if 0000
5294 i=cc_DriveReset(); /* ugly fix to prevent a hang */
5295#else
5296 i=cc_ReadError();
5297#endif
5298 continue;
5299 }
5300 if (fam0L_drive)
5301 {
5302 i=maxtim_data;
5303 for (timeout=jiffies+9*HZ; time_before(jiffies, timeout); timeout--)
5304 {
5305 for ( ;i!=0;i--)
5306 {
5307 j=inb(CDi_status);
5308 if (!(j&s_not_data_ready)) break;
5309 if (!(j&s_not_result_ready)) break;
5310 if (j&s_attention) break;
5311 }
5312 if (i != 0 || time_after_eq(jiffies, timeout)) break;
5313 sbp_sleep(0);
5314 i = 1;
5315 }
5316 if (i==0) msg(DBG_AUD,"read_audio: STATUS TIMEOUT AFTER READ");
5317 if (!(j&s_attention))
5318 {
5319 msg(DBG_AUD,"read_audio: sbp_data: timeout waiting DRV_ATTN - retrying\n");
5320 i=cc_DriveReset(); /* ugly fix to prevent a hang */
5321 continue;
5322 }
5323 }
5324 do
5325 {
5326 if (fam0L_drive) cc_ReadStatus();
5327 i=ResponseStatus(); /* builds status_bits, returns orig. status (old) or faked p_success (new) */
5328 if (i<0) { msg(DBG_AUD,
5329 "read_audio: cc_ReadStatus error after read: %02X\n",
5330 current_drive->status_bits);
5331 continue; /* FIXME */
5332 }
5333 }
5334 while ((fam0L_drive)&&(!st_check)&&(!(i&p_success)));
5335 if (st_check)
5336 {
5337 i=cc_ReadError();
5338 msg(DBG_AUD,"read_audio: cc_ReadError was necessary after read: %02X\n",i);
5339 continue;
5340 }
5341 if (copy_to_user(read_audio.buf,
5342 current_drive->aud_buf,
5343 read_audio.nframes * CD_FRAMESIZE_RAW))
5344 RETURN_UP(-EFAULT);
5345 msg(DBG_AUD,"read_audio: copy_to_user done.\n");
5346 break;
5347 }
5348 cc_ModeSelect(CD_FRAMESIZE);
5349 cc_ModeSense();
5350 current_drive->mode=READ_M1;
5351#if OLD_BUSY
5352 busy_audio=0;
5353#endif /* OLD_BUSY */
5354 if (data_tries == 0)
5355 {
5356 msg(DBG_AUD,"read_audio: failed after 5 tries in line %d.\n", __LINE__);
5357 RETURN_UP(-EIO);
5358 }
5359 msg(DBG_AUD,"read_audio: successful return.\n");
5360 RETURN_UP(0);
5361 } /* end of CDROMREADAUDIO */
5362
5363 default:
5364 msg(DBG_IOC,"ioctl: unknown function request %04X\n", cmd);
5365 RETURN_UP(-EINVAL);
5366 } /* end switch(cmd) */
5374} 5367}
5375 5368
5376static int sbpcd_block_media_changed(struct gendisk *disk) 5369static int sbpcd_block_media_changed(struct gendisk *disk)
@@ -5478,10 +5471,9 @@ static struct cdrom_device_ops sbpcd_dops = {
5478 .get_mcn = sbpcd_get_mcn, 5471 .get_mcn = sbpcd_get_mcn,
5479 .reset = sbpcd_reset, 5472 .reset = sbpcd_reset,
5480 .audio_ioctl = sbpcd_audio_ioctl, 5473 .audio_ioctl = sbpcd_audio_ioctl,
5481 .dev_ioctl = sbpcd_dev_ioctl,
5482 .capability = CDC_CLOSE_TRAY | CDC_OPEN_TRAY | CDC_LOCK | 5474 .capability = CDC_CLOSE_TRAY | CDC_OPEN_TRAY | CDC_LOCK |
5483 CDC_MULTI_SESSION | CDC_MEDIA_CHANGED | 5475 CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
5484 CDC_MCN | CDC_PLAY_AUDIO | CDC_IOCTLS, 5476 CDC_MCN | CDC_PLAY_AUDIO,
5485 .n_minors = 1, 5477 .n_minors = 1,
5486}; 5478};
5487 5479
diff --git a/drivers/cdrom/viocd.c b/drivers/cdrom/viocd.c
index e276172595..c0f817ba7a 100644
--- a/drivers/cdrom/viocd.c
+++ b/drivers/cdrom/viocd.c
@@ -627,7 +627,7 @@ static struct cdrom_device_ops viocd_dops = {
627 .media_changed = viocd_media_changed, 627 .media_changed = viocd_media_changed,
628 .lock_door = viocd_lock_door, 628 .lock_door = viocd_lock_door,
629 .generic_packet = viocd_packet, 629 .generic_packet = viocd_packet,
630 .capability = CDC_CLOSE_TRAY | CDC_OPEN_TRAY | CDC_LOCK | CDC_SELECT_SPEED | CDC_SELECT_DISC | CDC_MULTI_SESSION | CDC_MCN | CDC_MEDIA_CHANGED | CDC_PLAY_AUDIO | CDC_RESET | CDC_IOCTLS | CDC_DRIVE_STATUS | CDC_GENERIC_PACKET | CDC_CD_R | CDC_CD_RW | CDC_DVD | CDC_DVD_R | CDC_DVD_RAM | CDC_RAM 630 .capability = CDC_CLOSE_TRAY | CDC_OPEN_TRAY | CDC_LOCK | CDC_SELECT_SPEED | CDC_SELECT_DISC | CDC_MULTI_SESSION | CDC_MCN | CDC_MEDIA_CHANGED | CDC_PLAY_AUDIO | CDC_RESET | CDC_DRIVE_STATUS | CDC_GENERIC_PACKET | CDC_CD_R | CDC_CD_RW | CDC_DVD | CDC_DVD_R | CDC_DVD_RAM | CDC_RAM
631}; 631};
632 632
633static int __init find_capability(const char *type) 633static int __init find_capability(const char *type)
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
index 05ba410682..5980f3e886 100644
--- a/drivers/char/Kconfig
+++ b/drivers/char/Kconfig
@@ -290,7 +290,7 @@ config SX
290 290
291config RIO 291config RIO
292 tristate "Specialix RIO system support" 292 tristate "Specialix RIO system support"
293 depends on SERIAL_NONSTANDARD && BROKEN_ON_SMP && !64BIT 293 depends on SERIAL_NONSTANDARD && !64BIT
294 help 294 help
295 This is a driver for the Specialix RIO, a smart serial card which 295 This is a driver for the Specialix RIO, a smart serial card which
296 drives an outboard box that can support up to 128 ports. Product 296 drives an outboard box that can support up to 128 ports. Product
@@ -695,7 +695,7 @@ config NVRAM
695 695
696config RTC 696config RTC
697 tristate "Enhanced Real Time Clock Support" 697 tristate "Enhanced Real Time Clock Support"
698 depends on !PPC32 && !PARISC && !IA64 && !M68K && (!SPARC || PCI) && !FRV 698 depends on !PPC && !PARISC && !IA64 && !M68K && (!SPARC || PCI) && !FRV
699 ---help--- 699 ---help---
700 If you say Y here and create a character special file /dev/rtc with 700 If you say Y here and create a character special file /dev/rtc with
701 major number 10 and minor number 135 using mknod ("man mknod"), you 701 major number 10 and minor number 135 using mknod ("man mknod"), you
diff --git a/drivers/char/amiserial.c b/drivers/char/amiserial.c
index 7ac365b5d9..6602b3156d 100644
--- a/drivers/char/amiserial.c
+++ b/drivers/char/amiserial.c
@@ -46,8 +46,6 @@
46 46
47/* Sanity checks */ 47/* Sanity checks */
48 48
49#define SERIAL_INLINE
50
51#if defined(MODULE) && defined(SERIAL_DEBUG_MCOUNT) 49#if defined(MODULE) && defined(SERIAL_DEBUG_MCOUNT)
52#define DBG_CNT(s) printk("(%s): [%x] refc=%d, serc=%d, ttyc=%d -> %s\n", \ 50#define DBG_CNT(s) printk("(%s): [%x] refc=%d, serc=%d, ttyc=%d -> %s\n", \
53 tty->name, (info->flags), serial_driver->refcount,info->count,tty->count,s) 51 tty->name, (info->flags), serial_driver->refcount,info->count,tty->count,s)
@@ -95,10 +93,6 @@ static char *serial_version = "4.30";
95#include <asm/amigahw.h> 93#include <asm/amigahw.h>
96#include <asm/amigaints.h> 94#include <asm/amigaints.h>
97 95
98#ifdef SERIAL_INLINE
99#define _INLINE_ inline
100#endif
101
102#define custom amiga_custom 96#define custom amiga_custom
103static char *serial_name = "Amiga-builtin serial driver"; 97static char *serial_name = "Amiga-builtin serial driver";
104 98
@@ -253,14 +247,14 @@ static void rs_start(struct tty_struct *tty)
253 * This routine is used by the interrupt handler to schedule 247 * This routine is used by the interrupt handler to schedule
254 * processing in the software interrupt portion of the driver. 248 * processing in the software interrupt portion of the driver.
255 */ 249 */
256static _INLINE_ void rs_sched_event(struct async_struct *info, 250static void rs_sched_event(struct async_struct *info,
257 int event) 251 int event)
258{ 252{
259 info->event |= 1 << event; 253 info->event |= 1 << event;
260 tasklet_schedule(&info->tlet); 254 tasklet_schedule(&info->tlet);
261} 255}
262 256
263static _INLINE_ void receive_chars(struct async_struct *info) 257static void receive_chars(struct async_struct *info)
264{ 258{
265 int status; 259 int status;
266 int serdatr; 260 int serdatr;
@@ -349,7 +343,7 @@ out:
349 return; 343 return;
350} 344}
351 345
352static _INLINE_ void transmit_chars(struct async_struct *info) 346static void transmit_chars(struct async_struct *info)
353{ 347{
354 custom.intreq = IF_TBE; 348 custom.intreq = IF_TBE;
355 mb(); 349 mb();
@@ -389,7 +383,7 @@ static _INLINE_ void transmit_chars(struct async_struct *info)
389 } 383 }
390} 384}
391 385
392static _INLINE_ void check_modem_status(struct async_struct *info) 386static void check_modem_status(struct async_struct *info)
393{ 387{
394 unsigned char status = ciab.pra & (SER_DCD | SER_CTS | SER_DSR); 388 unsigned char status = ciab.pra & (SER_DCD | SER_CTS | SER_DSR);
395 unsigned char dstatus; 389 unsigned char dstatus;
@@ -1959,7 +1953,7 @@ done:
1959 * number, and identifies which options were configured into this 1953 * number, and identifies which options were configured into this
1960 * driver. 1954 * driver.
1961 */ 1955 */
1962static _INLINE_ void show_serial_version(void) 1956static void show_serial_version(void)
1963{ 1957{
1964 printk(KERN_INFO "%s version %s\n", serial_name, serial_version); 1958 printk(KERN_INFO "%s version %s\n", serial_name, serial_version);
1965} 1959}
diff --git a/drivers/char/generic_serial.c b/drivers/char/generic_serial.c
index e38a5f0e07..5e59c0b427 100644
--- a/drivers/char/generic_serial.c
+++ b/drivers/char/generic_serial.c
@@ -48,8 +48,8 @@ static int gs_debug;
48#define NEW_WRITE_LOCKING 1 48#define NEW_WRITE_LOCKING 1
49#if NEW_WRITE_LOCKING 49#if NEW_WRITE_LOCKING
50#define DECL /* Nothing */ 50#define DECL /* Nothing */
51#define LOCKIT down (& port->port_write_sem); 51#define LOCKIT mutex_lock(& port->port_write_mutex);
52#define RELEASEIT up (&port->port_write_sem); 52#define RELEASEIT mutex_unlock(&port->port_write_mutex);
53#else 53#else
54#define DECL unsigned long flags; 54#define DECL unsigned long flags;
55#define LOCKIT save_flags (flags);cli () 55#define LOCKIT save_flags (flags);cli ()
@@ -124,14 +124,14 @@ int gs_write(struct tty_struct * tty,
124 /* get exclusive "write" access to this port (problem 3) */ 124 /* get exclusive "write" access to this port (problem 3) */
125 /* This is not a spinlock because we can have a disk access (page 125 /* This is not a spinlock because we can have a disk access (page
126 fault) in copy_from_user */ 126 fault) in copy_from_user */
127 down (& port->port_write_sem); 127 mutex_lock(& port->port_write_mutex);
128 128
129 while (1) { 129 while (1) {
130 130
131 c = count; 131 c = count;
132 132
133 /* This is safe because we "OWN" the "head". Noone else can 133 /* This is safe because we "OWN" the "head". Noone else can
134 change the "head": we own the port_write_sem. */ 134 change the "head": we own the port_write_mutex. */
135 /* Don't overrun the end of the buffer */ 135 /* Don't overrun the end of the buffer */
136 t = SERIAL_XMIT_SIZE - port->xmit_head; 136 t = SERIAL_XMIT_SIZE - port->xmit_head;
137 if (t < c) c = t; 137 if (t < c) c = t;
@@ -153,7 +153,7 @@ int gs_write(struct tty_struct * tty,
153 count -= c; 153 count -= c;
154 total += c; 154 total += c;
155 } 155 }
156 up (& port->port_write_sem); 156 mutex_unlock(& port->port_write_mutex);
157 157
158 gs_dprintk (GS_DEBUG_WRITE, "write: interrupts are %s\n", 158 gs_dprintk (GS_DEBUG_WRITE, "write: interrupts are %s\n",
159 (port->flags & GS_TX_INTEN)?"enabled": "disabled"); 159 (port->flags & GS_TX_INTEN)?"enabled": "disabled");
@@ -214,7 +214,7 @@ int gs_write(struct tty_struct * tty,
214 c = count; 214 c = count;
215 215
216 /* This is safe because we "OWN" the "head". Noone else can 216 /* This is safe because we "OWN" the "head". Noone else can
217 change the "head": we own the port_write_sem. */ 217 change the "head": we own the port_write_mutex. */
218 /* Don't overrun the end of the buffer */ 218 /* Don't overrun the end of the buffer */
219 t = SERIAL_XMIT_SIZE - port->xmit_head; 219 t = SERIAL_XMIT_SIZE - port->xmit_head;
220 if (t < c) c = t; 220 if (t < c) c = t;
@@ -888,7 +888,7 @@ int gs_init_port(struct gs_port *port)
888 spin_lock_irqsave (&port->driver_lock, flags); 888 spin_lock_irqsave (&port->driver_lock, flags);
889 if (port->tty) 889 if (port->tty)
890 clear_bit(TTY_IO_ERROR, &port->tty->flags); 890 clear_bit(TTY_IO_ERROR, &port->tty->flags);
891 init_MUTEX(&port->port_write_sem); 891 mutex_init(&port->port_write_mutex);
892 port->xmit_cnt = port->xmit_head = port->xmit_tail = 0; 892 port->xmit_cnt = port->xmit_head = port->xmit_tail = 0;
893 spin_unlock_irqrestore(&port->driver_lock, flags); 893 spin_unlock_irqrestore(&port->driver_lock, flags);
894 gs_set_termios(port->tty, NULL); 894 gs_set_termios(port->tty, NULL);
diff --git a/drivers/char/hvcs.c b/drivers/char/hvcs.c
index 831eb4e8d9..f7ac318565 100644
--- a/drivers/char/hvcs.c
+++ b/drivers/char/hvcs.c
@@ -118,7 +118,7 @@
118 * the hvcs_final_close() function in order to get it out of the spinlock. 118 * the hvcs_final_close() function in order to get it out of the spinlock.
119 * Rearranged hvcs_close(). Cleaned up some printks and did some housekeeping 119 * Rearranged hvcs_close(). Cleaned up some printks and did some housekeeping
120 * on the changelog. Removed local CLC_LENGTH and used HVCS_CLC_LENGTH from 120 * on the changelog. Removed local CLC_LENGTH and used HVCS_CLC_LENGTH from
121 * arch/ppc64/hvcserver.h. 121 * include/asm-powerpc/hvcserver.h
122 * 122 *
123 * 1.3.2 -> 1.3.3 Replaced yield() in hvcs_close() with tty_wait_until_sent() to 123 * 1.3.2 -> 1.3.3 Replaced yield() in hvcs_close() with tty_wait_until_sent() to
124 * prevent possible lockup with realtime scheduling as similarily pointed out by 124 * prevent possible lockup with realtime scheduling as similarily pointed out by
@@ -168,9 +168,10 @@ MODULE_VERSION(HVCS_DRIVER_VERSION);
168 168
169/* 169/*
170 * The hcall interface involves putting 8 chars into each of two registers. 170 * The hcall interface involves putting 8 chars into each of two registers.
171 * We load up those 2 registers (in arch/ppc64/hvconsole.c) by casting char[16] 171 * We load up those 2 registers (in arch/powerpc/platforms/pseries/hvconsole.c)
172 * to long[2]. It would work without __ALIGNED__, but a little (tiny) bit 172 * by casting char[16] to long[2]. It would work without __ALIGNED__, but a
173 * slower because an unaligned load is slower than aligned load. 173 * little (tiny) bit slower because an unaligned load is slower than aligned
174 * load.
174 */ 175 */
175#define __ALIGNED__ __attribute__((__aligned__(8))) 176#define __ALIGNED__ __attribute__((__aligned__(8)))
176 177
diff --git a/drivers/char/ipmi/ipmi_poweroff.c b/drivers/char/ipmi/ipmi_poweroff.c
index 49c09ae004..e8ed26b77d 100644
--- a/drivers/char/ipmi/ipmi_poweroff.c
+++ b/drivers/char/ipmi/ipmi_poweroff.c
@@ -37,15 +37,13 @@
37#include <linux/proc_fs.h> 37#include <linux/proc_fs.h>
38#include <linux/string.h> 38#include <linux/string.h>
39#include <linux/completion.h> 39#include <linux/completion.h>
40#include <linux/pm.h>
40#include <linux/kdev_t.h> 41#include <linux/kdev_t.h>
41#include <linux/ipmi.h> 42#include <linux/ipmi.h>
42#include <linux/ipmi_smi.h> 43#include <linux/ipmi_smi.h>
43 44
44#define PFX "IPMI poweroff: " 45#define PFX "IPMI poweroff: "
45 46
46/* Where to we insert our poweroff function? */
47extern void (*pm_power_off)(void);
48
49/* Definitions for controlling power off (if the system supports it). It 47/* Definitions for controlling power off (if the system supports it). It
50 * conveniently matches the IPMI chassis control values. */ 48 * conveniently matches the IPMI chassis control values. */
51#define IPMI_CHASSIS_POWER_DOWN 0 /* power down, the default. */ 49#define IPMI_CHASSIS_POWER_DOWN 0 /* power down, the default. */
diff --git a/drivers/char/istallion.c b/drivers/char/istallion.c
index 28c5a3193b..ede128356a 100644
--- a/drivers/char/istallion.c
+++ b/drivers/char/istallion.c
@@ -181,7 +181,6 @@ static struct tty_driver *stli_serial;
181 * is already swapping a shared buffer won't make things any worse. 181 * is already swapping a shared buffer won't make things any worse.
182 */ 182 */
183static char *stli_tmpwritebuf; 183static char *stli_tmpwritebuf;
184static DECLARE_MUTEX(stli_tmpwritesem);
185 184
186#define STLI_TXBUFSIZE 4096 185#define STLI_TXBUFSIZE 4096
187 186
diff --git a/drivers/char/n_tty.c b/drivers/char/n_tty.c
index ccad7ae945..ede365d053 100644
--- a/drivers/char/n_tty.c
+++ b/drivers/char/n_tty.c
@@ -132,7 +132,7 @@ static void put_tty_queue(unsigned char c, struct tty_struct *tty)
132 * We test the TTY_THROTTLED bit first so that it always 132 * We test the TTY_THROTTLED bit first so that it always
133 * indicates the current state. The decision about whether 133 * indicates the current state. The decision about whether
134 * it is worth allowing more input has been taken by the caller. 134 * it is worth allowing more input has been taken by the caller.
135 * Can sleep, may be called under the atomic_read semaphore but 135 * Can sleep, may be called under the atomic_read_lock mutex but
136 * this is not guaranteed. 136 * this is not guaranteed.
137 */ 137 */
138 138
@@ -1132,7 +1132,7 @@ static inline int input_available_p(struct tty_struct *tty, int amt)
1132 * buffer, and once to drain the space from the (physical) beginning of 1132 * buffer, and once to drain the space from the (physical) beginning of
1133 * the buffer to head pointer. 1133 * the buffer to head pointer.
1134 * 1134 *
1135 * Called under the tty->atomic_read sem and with TTY_DONT_FLIP set 1135 * Called under the tty->atomic_read_lock sem and with TTY_DONT_FLIP set
1136 * 1136 *
1137 */ 1137 */
1138 1138
@@ -1262,11 +1262,11 @@ do_it_again:
1262 * Internal serialization of reads. 1262 * Internal serialization of reads.
1263 */ 1263 */
1264 if (file->f_flags & O_NONBLOCK) { 1264 if (file->f_flags & O_NONBLOCK) {
1265 if (down_trylock(&tty->atomic_read)) 1265 if (!mutex_trylock(&tty->atomic_read_lock))
1266 return -EAGAIN; 1266 return -EAGAIN;
1267 } 1267 }
1268 else { 1268 else {
1269 if (down_interruptible(&tty->atomic_read)) 1269 if (mutex_lock_interruptible(&tty->atomic_read_lock))
1270 return -ERESTARTSYS; 1270 return -ERESTARTSYS;
1271 } 1271 }
1272 1272
@@ -1393,7 +1393,7 @@ do_it_again:
1393 timeout = time; 1393 timeout = time;
1394 } 1394 }
1395 clear_bit(TTY_DONT_FLIP, &tty->flags); 1395 clear_bit(TTY_DONT_FLIP, &tty->flags);
1396 up(&tty->atomic_read); 1396 mutex_unlock(&tty->atomic_read_lock);
1397 remove_wait_queue(&tty->read_wait, &wait); 1397 remove_wait_queue(&tty->read_wait, &wait);
1398 1398
1399 if (!waitqueue_active(&tty->read_wait)) 1399 if (!waitqueue_active(&tty->read_wait))
diff --git a/drivers/char/nwflash.c b/drivers/char/nwflash.c
index ca41d62b1d..8865387d34 100644
--- a/drivers/char/nwflash.c
+++ b/drivers/char/nwflash.c
@@ -27,6 +27,7 @@
27#include <linux/rwsem.h> 27#include <linux/rwsem.h>
28#include <linux/init.h> 28#include <linux/init.h>
29#include <linux/smp_lock.h> 29#include <linux/smp_lock.h>
30#include <linux/mutex.h>
30 31
31#include <asm/hardware/dec21285.h> 32#include <asm/hardware/dec21285.h>
32#include <asm/io.h> 33#include <asm/io.h>
@@ -56,7 +57,7 @@ static int gbWriteEnable;
56static int gbWriteBase64Enable; 57static int gbWriteBase64Enable;
57static volatile unsigned char *FLASH_BASE; 58static volatile unsigned char *FLASH_BASE;
58static int gbFlashSize = KFLASH_SIZE; 59static int gbFlashSize = KFLASH_SIZE;
59static DECLARE_MUTEX(nwflash_sem); 60static DEFINE_MUTEX(nwflash_mutex);
60 61
61extern spinlock_t gpio_lock; 62extern spinlock_t gpio_lock;
62 63
@@ -140,7 +141,7 @@ static ssize_t flash_read(struct file *file, char __user *buf, size_t size,
140 /* 141 /*
141 * We now lock against reads and writes. --rmk 142 * We now lock against reads and writes. --rmk
142 */ 143 */
143 if (down_interruptible(&nwflash_sem)) 144 if (mutex_lock_interruptible(&nwflash_mutex))
144 return -ERESTARTSYS; 145 return -ERESTARTSYS;
145 146
146 ret = copy_to_user(buf, (void *)(FLASH_BASE + p), count); 147 ret = copy_to_user(buf, (void *)(FLASH_BASE + p), count);
@@ -149,7 +150,7 @@ static ssize_t flash_read(struct file *file, char __user *buf, size_t size,
149 *ppos += count; 150 *ppos += count;
150 } else 151 } else
151 ret = -EFAULT; 152 ret = -EFAULT;
152 up(&nwflash_sem); 153 mutex_unlock(&nwflash_mutex);
153 } 154 }
154 return ret; 155 return ret;
155} 156}
@@ -188,7 +189,7 @@ static ssize_t flash_write(struct file *file, const char __user *buf,
188 /* 189 /*
189 * We now lock against reads and writes. --rmk 190 * We now lock against reads and writes. --rmk
190 */ 191 */
191 if (down_interruptible(&nwflash_sem)) 192 if (mutex_lock_interruptible(&nwflash_mutex))
192 return -ERESTARTSYS; 193 return -ERESTARTSYS;
193 194
194 written = 0; 195 written = 0;
@@ -277,7 +278,7 @@ static ssize_t flash_write(struct file *file, const char __user *buf,
277 */ 278 */
278 leds_event(led_release); 279 leds_event(led_release);
279 280
280 up(&nwflash_sem); 281 mutex_unlock(&nwflash_mutex);
281 282
282 return written; 283 return written;
283} 284}
diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
index 8a8ca32822..e6b714b639 100644
--- a/drivers/char/pcmcia/synclink_cs.c
+++ b/drivers/char/pcmcia/synclink_cs.c
@@ -4181,7 +4181,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
4181 } 4181 }
4182 4182
4183 info->params.encoding = new_encoding; 4183 info->params.encoding = new_encoding;
4184 info->params.crc_type = new_crctype;; 4184 info->params.crc_type = new_crctype;
4185 4185
4186 /* if network interface up, reprogram hardware */ 4186 /* if network interface up, reprogram hardware */
4187 if (info->netcount) 4187 if (info->netcount)
diff --git a/drivers/char/raw.c b/drivers/char/raw.c
index 30e4cbe16b..15a7b40865 100644
--- a/drivers/char/raw.c
+++ b/drivers/char/raw.c
@@ -19,6 +19,7 @@
19#include <linux/uio.h> 19#include <linux/uio.h>
20#include <linux/cdev.h> 20#include <linux/cdev.h>
21#include <linux/device.h> 21#include <linux/device.h>
22#include <linux/mutex.h>
22 23
23#include <asm/uaccess.h> 24#include <asm/uaccess.h>
24 25
@@ -29,7 +30,7 @@ struct raw_device_data {
29 30
30static struct class *raw_class; 31static struct class *raw_class;
31static struct raw_device_data raw_devices[MAX_RAW_MINORS]; 32static struct raw_device_data raw_devices[MAX_RAW_MINORS];
32static DECLARE_MUTEX(raw_mutex); 33static DEFINE_MUTEX(raw_mutex);
33static struct file_operations raw_ctl_fops; /* forward declaration */ 34static struct file_operations raw_ctl_fops; /* forward declaration */
34 35
35/* 36/*
@@ -53,7 +54,7 @@ static int raw_open(struct inode *inode, struct file *filp)
53 return 0; 54 return 0;
54 } 55 }
55 56
56 down(&raw_mutex); 57 mutex_lock(&raw_mutex);
57 58
58 /* 59 /*
59 * All we need to do on open is check that the device is bound. 60 * All we need to do on open is check that the device is bound.
@@ -78,7 +79,7 @@ static int raw_open(struct inode *inode, struct file *filp)
78 filp->f_dentry->d_inode->i_mapping = 79 filp->f_dentry->d_inode->i_mapping =
79 bdev->bd_inode->i_mapping; 80 bdev->bd_inode->i_mapping;
80 filp->private_data = bdev; 81 filp->private_data = bdev;
81 up(&raw_mutex); 82 mutex_unlock(&raw_mutex);
82 return 0; 83 return 0;
83 84
84out2: 85out2:
@@ -86,7 +87,7 @@ out2:
86out1: 87out1:
87 blkdev_put(bdev); 88 blkdev_put(bdev);
88out: 89out:
89 up(&raw_mutex); 90 mutex_unlock(&raw_mutex);
90 return err; 91 return err;
91} 92}
92 93
@@ -99,14 +100,14 @@ static int raw_release(struct inode *inode, struct file *filp)
99 const int minor= iminor(inode); 100 const int minor= iminor(inode);
100 struct block_device *bdev; 101 struct block_device *bdev;
101 102
102 down(&raw_mutex); 103 mutex_lock(&raw_mutex);
103 bdev = raw_devices[minor].binding; 104 bdev = raw_devices[minor].binding;
104 if (--raw_devices[minor].inuse == 0) { 105 if (--raw_devices[minor].inuse == 0) {
105 /* Here inode->i_mapping == bdev->bd_inode->i_mapping */ 106 /* Here inode->i_mapping == bdev->bd_inode->i_mapping */
106 inode->i_mapping = &inode->i_data; 107 inode->i_mapping = &inode->i_data;
107 inode->i_mapping->backing_dev_info = &default_backing_dev_info; 108 inode->i_mapping->backing_dev_info = &default_backing_dev_info;
108 } 109 }
109 up(&raw_mutex); 110 mutex_unlock(&raw_mutex);
110 111
111 bd_release(bdev); 112 bd_release(bdev);
112 blkdev_put(bdev); 113 blkdev_put(bdev);
@@ -187,9 +188,9 @@ static int raw_ctl_ioctl(struct inode *inode, struct file *filp,
187 goto out; 188 goto out;
188 } 189 }
189 190
190 down(&raw_mutex); 191 mutex_lock(&raw_mutex);
191 if (rawdev->inuse) { 192 if (rawdev->inuse) {
192 up(&raw_mutex); 193 mutex_unlock(&raw_mutex);
193 err = -EBUSY; 194 err = -EBUSY;
194 goto out; 195 goto out;
195 } 196 }
@@ -211,11 +212,11 @@ static int raw_ctl_ioctl(struct inode *inode, struct file *filp,
211 bind_device(&rq); 212 bind_device(&rq);
212 } 213 }
213 } 214 }
214 up(&raw_mutex); 215 mutex_unlock(&raw_mutex);
215 } else { 216 } else {
216 struct block_device *bdev; 217 struct block_device *bdev;
217 218
218 down(&raw_mutex); 219 mutex_lock(&raw_mutex);
219 bdev = rawdev->binding; 220 bdev = rawdev->binding;
220 if (bdev) { 221 if (bdev) {
221 rq.block_major = MAJOR(bdev->bd_dev); 222 rq.block_major = MAJOR(bdev->bd_dev);
@@ -223,7 +224,7 @@ static int raw_ctl_ioctl(struct inode *inode, struct file *filp,
223 } else { 224 } else {
224 rq.block_major = rq.block_minor = 0; 225 rq.block_major = rq.block_minor = 0;
225 } 226 }
226 up(&raw_mutex); 227 mutex_unlock(&raw_mutex);
227 if (copy_to_user((void __user *)arg, &rq, sizeof(rq))) { 228 if (copy_to_user((void __user *)arg, &rq, sizeof(rq))) {
228 err = -EFAULT; 229 err = -EFAULT;
229 goto out; 230 goto out;
diff --git a/drivers/char/rio/Makefile b/drivers/char/rio/Makefile
index bce2bd1204..2d1c5a7cba 100644
--- a/drivers/char/rio/Makefile
+++ b/drivers/char/rio/Makefile
@@ -9,4 +9,4 @@
9obj-$(CONFIG_RIO) += rio.o 9obj-$(CONFIG_RIO) += rio.o
10 10
11rio-objs := rio_linux.o rioinit.o rioboot.o riocmd.o rioctrl.o riointr.o \ 11rio-objs := rio_linux.o rioinit.o rioboot.o riocmd.o rioctrl.o riointr.o \
12 rioparam.o riopcicopy.o rioroute.o riotable.o riotty.o 12 rioparam.o rioroute.o riotable.o riotty.o
diff --git a/drivers/char/rio/board.h b/drivers/char/rio/board.h
index 29c9802040..bdea633a90 100644
--- a/drivers/char/rio/board.h
+++ b/drivers/char/rio/board.h
@@ -33,10 +33,6 @@
33#ifndef __rio_board_h__ 33#ifndef __rio_board_h__
34#define __rio_board_h__ 34#define __rio_board_h__
35 35
36#ifdef SCCS_LABELS
37static char *_board_h_sccs_ = "@(#)board.h 1.2";
38#endif
39
40/* 36/*
41** board.h contains the definitions for the *hardware* of the host cards. 37** board.h contains the definitions for the *hardware* of the host cards.
42** It describes the memory overlay for the dual port RAM area. 38** It describes the memory overlay for the dual port RAM area.
@@ -53,29 +49,29 @@ static char *_board_h_sccs_ = "@(#)board.h 1.2";
53** The shape of the Host Control area, at offset 0x7C00, Write Only 49** The shape of the Host Control area, at offset 0x7C00, Write Only
54*/ 50*/
55struct s_Ctrl { 51struct s_Ctrl {
56 BYTE DpCtl; /* 7C00 */ 52 u8 DpCtl; /* 7C00 */
57 BYTE Dp_Unused2_[127]; 53 u8 Dp_Unused2_[127];
58 BYTE DpIntSet; /* 7C80 */ 54 u8 DpIntSet; /* 7C80 */
59 BYTE Dp_Unused3_[127]; 55 u8 Dp_Unused3_[127];
60 BYTE DpTpuReset; /* 7D00 */ 56 u8 DpTpuReset; /* 7D00 */
61 BYTE Dp_Unused4_[127]; 57 u8 Dp_Unused4_[127];
62 BYTE DpIntReset; /* 7D80 */ 58 u8 DpIntReset; /* 7D80 */
63 BYTE Dp_Unused5_[127]; 59 u8 Dp_Unused5_[127];
64}; 60};
65 61
66/* 62/*
67** The PROM data area on the host (0x7C00), Read Only 63** The PROM data area on the host (0x7C00), Read Only
68*/ 64*/
69struct s_Prom { 65struct s_Prom {
70 WORD DpSlxCode[2]; 66 u16 DpSlxCode[2];
71 WORD DpRev; 67 u16 DpRev;
72 WORD Dp_Unused6_; 68 u16 Dp_Unused6_;
73 WORD DpUniq[4]; 69 u16 DpUniq[4];
74 WORD DpJahre; 70 u16 DpJahre;
75 WORD DpWoche; 71 u16 DpWoche;
76 WORD DpHwFeature[5]; 72 u16 DpHwFeature[5];
77 WORD DpOemId; 73 u16 DpOemId;
78 WORD DpSiggy[16]; 74 u16 DpSiggy[16];
79}; 75};
80 76
81/* 77/*
@@ -90,19 +86,19 @@ union u_CtrlProm { /* This is the control/PROM area (0x7C00) */
90** The top end of memory! 86** The top end of memory!
91*/ 87*/
92struct s_ParmMapS { /* Area containing Parm Map Pointer */ 88struct s_ParmMapS { /* Area containing Parm Map Pointer */
93 BYTE Dp_Unused8_[DP_PARMMAP_ADDR]; 89 u8 Dp_Unused8_[DP_PARMMAP_ADDR];
94 WORD DpParmMapAd; 90 u16 DpParmMapAd;
95}; 91};
96 92
97struct s_StartUpS { 93struct s_StartUpS {
98 BYTE Dp_Unused9_[DP_STARTUP_ADDR]; 94 u8 Dp_Unused9_[DP_STARTUP_ADDR];
99 BYTE Dp_LongJump[0x4]; 95 u8 Dp_LongJump[0x4];
100 BYTE Dp_Unused10_[2]; 96 u8 Dp_Unused10_[2];
101 BYTE Dp_ShortJump[0x2]; 97 u8 Dp_ShortJump[0x2];
102}; 98};
103 99
104union u_Sram2ParmMap { /* This is the top of memory (0x7E00-0x7FFF) */ 100union u_Sram2ParmMap { /* This is the top of memory (0x7E00-0x7FFF) */
105 BYTE DpSramMem[DP_SRAM2_SIZE]; 101 u8 DpSramMem[DP_SRAM2_SIZE];
106 struct s_ParmMapS DpParmMapS; 102 struct s_ParmMapS DpParmMapS;
107 struct s_StartUpS DpStartUpS; 103 struct s_StartUpS DpStartUpS;
108}; 104};
@@ -111,11 +107,11 @@ union u_Sram2ParmMap { /* This is the top of memory (0x7E00-0x7FFF) */
111** This is the DP RAM overlay. 107** This is the DP RAM overlay.
112*/ 108*/
113struct DpRam { 109struct DpRam {
114 BYTE DpSram1[DP_SRAM1_SIZE]; /* 0000 - 7BFF */ 110 u8 DpSram1[DP_SRAM1_SIZE]; /* 0000 - 7BFF */
115 union u_CtrlProm DpCtrlProm; /* 7C00 - 7DFF */ 111 union u_CtrlProm DpCtrlProm; /* 7C00 - 7DFF */
116 union u_Sram2ParmMap DpSram2ParmMap; /* 7E00 - 7FFF */ 112 union u_Sram2ParmMap DpSram2ParmMap; /* 7E00 - 7FFF */
117 BYTE DpScratch[DP_SCRATCH_SIZE]; /* 8000 - 8FFF */ 113 u8 DpScratch[DP_SCRATCH_SIZE]; /* 8000 - 8FFF */
118 BYTE DpSram3[DP_SRAM3_SIZE]; /* 9000 - FFFF */ 114 u8 DpSram3[DP_SRAM3_SIZE]; /* 9000 - FFFF */
119}; 115};
120 116
121#define DpControl DpCtrlProm.DpCtrl.DpCtl 117#define DpControl DpCtrlProm.DpCtrl.DpCtl
diff --git a/drivers/char/rio/bootpkt.h b/drivers/char/rio/bootpkt.h
deleted file mode 100644
index 602266e0c0..0000000000
--- a/drivers/char/rio/bootpkt.h
+++ /dev/null
@@ -1,61 +0,0 @@
1
2
3/****************************************************************************
4 ******* *******
5 ******* B O O T P A C K E T H E A D E R F I L E
6 ******* *******
7 ****************************************************************************
8
9 Author : Ian Nandhra
10 Date :
11
12 *
13 * (C) 1990 - 2000 Specialix International Ltd., Byfleet, Surrey, UK.
14 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28
29 Version : 0.01
30
31
32 Mods
33 ----------------------------------------------------------------------------
34 Date By Description
35 ----------------------------------------------------------------------------
36
37 ***************************************************************************/
38
39#ifndef _pkt_h
40#define _pkt_h 1
41
42#ifndef lint
43#ifdef SCCS
44static char *_rio_bootpkt_h_sccs = "@(#)bootpkt.h 1.1";
45#endif
46#endif
47
48 /*************************************************
49 * Overlayed onto the Data fields of a regular
50 * Packet
51 ************************************************/
52typedef struct BOOT_PKT BOOT_PKT;
53struct BOOT_PKT {
54 short seq_num;
55 char data[10];
56};
57
58
59#endif
60
61/*********** end of file ***********/
diff --git a/drivers/char/rio/cirrus.h b/drivers/char/rio/cirrus.h
index 89bd94eb45..f4f837f868 100644
--- a/drivers/char/rio/cirrus.h
+++ b/drivers/char/rio/cirrus.h
@@ -40,73 +40,7 @@
40#endif 40#endif
41#define _cirrus_h 1 41#define _cirrus_h 1
42 42
43 43/* Bit fields for particular registers shared with driver */
44
45/* Bit fields for particular registers */
46
47/* GCR */
48#define GCR_SERIAL 0x00 /* Configure as serial channel */
49#define GCR_PARALLEL 0x80 /* Configure as parallel channel */
50
51/* RDSR - when status read from FIFO */
52#define RDSR_BREAK 0x08 /* Break received */
53#define RDSR_TIMEOUT 0x80 /* No new data timeout */
54#define RDSR_SC1 0x10 /* Special char 1 (tx XON) matched */
55#define RDSR_SC2 0x20 /* Special char 2 (tx XOFF) matched */
56#define RDSR_SC12_MASK 0x30 /* Mask for special chars 1 and 2 */
57
58/* PPR */
59#define PPR_DEFAULT 0x31 /* Default value - for a 25Mhz clock gives
60 a timeout period of 1ms */
61
62/* LIVR */
63#define LIVR_EXCEPTION 0x07 /* Receive exception interrupt */
64
65/* CCR */
66#define CCR_RESET 0x80 /* Reset channel */
67#define CCR_CHANGE 0x4e /* COR's have changed - NB always change all
68 COR's */
69#define CCR_WFLUSH 0x82 /* Flush transmit FIFO and TSR / THR */
70
71#define CCR_SENDSC1 0x21 /* Send special character one */
72#define CCR_SENDSC2 0x22 /* Send special character two */
73#define CCR_SENDSC3 0x23 /* Send special character three */
74#define CCR_SENDSC4 0x24 /* Send special character four */
75
76#define CCR_TENABLE 0x18 /* Enable transmitter */
77#define CCR_TDISABLE 0x14 /* Disable transmitter */
78#define CCR_RENABLE 0x12 /* Enable receiver */
79#define CCR_RDISABLE 0x11 /* Disable receiver */
80
81#define CCR_READY 0x00 /* CCR is ready for another command */
82
83/* CCSR */
84#define CCSR_TXENABLE 0x08 /* Transmitter enable */
85#define CCSR_RXENABLE 0x80 /* Receiver enable */
86#define CCSR_TXFLOWOFF 0x04 /* Transmit flow off */
87#define CCSR_TXFLOWON 0x02 /* Transmit flow on */
88
89/* SVRR */
90#define SVRR_RECEIVE 0x01 /* Receive interrupt pending */
91#define SVRR_TRANSMIT 0x02 /* Transmit interrupt pending */
92#define SVRR_MODEM 0x04 /* Modem interrupt pending */
93
94/* CAR */
95#define CAR_PORTS 0x03 /* Bit fields for ports */
96
97/* IER */
98#define IER_MODEM 0x80 /* Change in modem status */
99#define IER_RECEIVE 0x10 /* Good data / data exception */
100#define IER_TRANSMITR 0x04 /* Transmit ready (FIFO empty) */
101#define IER_TRANSMITE 0x02 /* Transmit empty */
102#define IER_TIMEOUT 0x01 /* Timeout on no data */
103
104#define IER_DEFAULT 0x94 /* Default values */
105#define IER_PARALLEL 0x84 /* Default for Parallel */
106#define IER_EMPTY 0x92 /* Transmitter empty rather than ready */
107
108/* COR1 - Driver only */
109#define COR1_INPCK 0x10 /* Check parity of received characters */
110 44
111/* COR1 - driver and RTA */ 45/* COR1 - driver and RTA */
112#define COR1_ODD 0x80 /* Odd parity */ 46#define COR1_ODD 0x80 /* Odd parity */
@@ -222,35 +156,6 @@
222 156
223#define MSVR1_HOST 0xf3 /* The bits the host wants */ 157#define MSVR1_HOST 0xf3 /* The bits the host wants */
224 158
225/* MSVR2 */
226#define MSVR2_DSR 0x02 /* DSR output pin (DTR on Cirrus) */
227
228/* MCOR */
229#define MCOR_CD 0x80 /* CD (DSR on Cirrus) */
230#define MCOR_RTS 0x40 /* RTS (CTS on Cirrus) */
231#define MCOR_RI 0x20 /* RI */
232#define MCOR_DTR 0x10 /* DTR (CD on Cirrus) */
233
234#define MCOR_DEFAULT (MCOR_CD | MCOR_RTS | MCOR_RI | MCOR_DTR)
235#define MCOR_FULLMODEM MCOR_DEFAULT
236#define MCOR_RJ45 (MCOR_CD | MCOR_RTS | MCOR_DTR)
237#define MCOR_RESTRICTED (MCOR_CD | MCOR_RTS)
238
239/* More MCOR - H/W Handshake (flowcontrol) stuff */
240#define MCOR_THRESH8 0x08 /* eight characters then we stop */
241#define MCOR_THRESH9 0x09 /* nine characters then we stop */
242#define MCOR_THRESH10 0x0A /* ten characters then we stop */
243#define MCOR_THRESH11 0x0B /* eleven characters then we stop */
244
245#define MCOR_THRESHBITS 0x0F /* mask for ANDing out the above */
246
247#define MCOR_THRESHOLD MCOR_THRESH9 /* MUST BE GREATER THAN COR3_THRESHOLD */
248
249
250/* RTPR */
251#define RTPR_DEFAULT 0x02 /* Default */
252
253
254/* Defines for the subscripts of a CONFIG packet */ 159/* Defines for the subscripts of a CONFIG packet */
255#define CONFIG_COR1 1 /* Option register 1 */ 160#define CONFIG_COR1 1 /* Option register 1 */
256#define CONFIG_COR2 2 /* Option register 2 */ 161#define CONFIG_COR2 2 /* Option register 2 */
@@ -264,19 +169,6 @@
264#define CONFIG_TXBAUD 10 /* Tx baud rate */ 169#define CONFIG_TXBAUD 10 /* Tx baud rate */
265#define CONFIG_RXBAUD 11 /* Rx baud rate */ 170#define CONFIG_RXBAUD 11 /* Rx baud rate */
266 171
267/* Port status stuff */
268#define IDLE_CLOSED 0 /* Closed */
269#define IDLE_OPEN 1 /* Idle open */
270#define IDLE_BREAK 2 /* Idle on break */
271
272/* Subscript of MODEM STATUS packet */
273#define MODEM_VALUE 3 /* Current values of handshake pins */
274/* Subscript of SBREAK packet */
275#define BREAK_LENGTH 1 /* Length of a break in slices of 0.01 seconds
276 0 = stay on break until an EBREAK command
277 is sent */
278
279
280#define PRE_EMPTIVE 0x80 /* Pre-emptive bit in command field */ 172#define PRE_EMPTIVE 0x80 /* Pre-emptive bit in command field */
281 173
282/* Packet types going from Host to remote - with the exception of OPEN, MOPEN, 174/* Packet types going from Host to remote - with the exception of OPEN, MOPEN,
diff --git a/drivers/char/rio/cmdblk.h b/drivers/char/rio/cmdblk.h
index a9a8c45631..c46b2fdb66 100644
--- a/drivers/char/rio/cmdblk.h
+++ b/drivers/char/rio/cmdblk.h
@@ -48,10 +48,10 @@ struct CmdBlk {
48 struct CmdBlk *NextP; /* Pointer to next command block */ 48 struct CmdBlk *NextP; /* Pointer to next command block */
49 struct PKT Packet; /* A packet, to copy to the rup */ 49 struct PKT Packet; /* A packet, to copy to the rup */
50 /* The func to call to check if OK */ 50 /* The func to call to check if OK */
51 int (*PreFuncP) (int, struct CmdBlk *); 51 int (*PreFuncP) (unsigned long, struct CmdBlk *);
52 int PreArg; /* The arg for the func */ 52 int PreArg; /* The arg for the func */
53 /* The func to call when completed */ 53 /* The func to call when completed */
54 int (*PostFuncP) (int, struct CmdBlk *); 54 int (*PostFuncP) (unsigned long, struct CmdBlk *);
55 int PostArg; /* The arg for the func */ 55 int PostArg; /* The arg for the func */
56}; 56};
57 57
diff --git a/drivers/char/rio/cmdpkt.h b/drivers/char/rio/cmdpkt.h
index 77cee8df68..357ae57224 100644
--- a/drivers/char/rio/cmdpkt.h
+++ b/drivers/char/rio/cmdpkt.h
@@ -55,24 +55,24 @@ static char *_cmdpkt_h_sccs_ = "@(#)cmdpkt.h 1.2";
55** at Data[2] in the actual pkt! 55** at Data[2] in the actual pkt!
56*/ 56*/
57struct BootSequence { 57struct BootSequence {
58 WORD NumPackets; 58 u16 NumPackets;
59 WORD LoadBase; 59 u16 LoadBase;
60 WORD CodeSize; 60 u16 CodeSize;
61}; 61};
62 62
63#define BOOT_SEQUENCE_LEN 8 63#define BOOT_SEQUENCE_LEN 8
64 64
65struct SamTop { 65struct SamTop {
66 BYTE Unit; 66 u8 Unit;
67 BYTE Link; 67 u8 Link;
68}; 68};
69 69
70struct CmdHdr { 70struct CmdHdr {
71 BYTE PcCommand; 71 u8 PcCommand;
72 union { 72 union {
73 BYTE PcPhbNum; 73 u8 PcPhbNum;
74 BYTE PcLinkNum; 74 u8 PcLinkNum;
75 BYTE PcIDNum; 75 u8 PcIDNum;
76 } U0; 76 } U0;
77}; 77};
78 78
@@ -84,28 +84,28 @@ struct PktCmd {
84 struct BootSequence PcBootSequence; 84 struct BootSequence PcBootSequence;
85 } S1; 85 } S1;
86 struct { 86 struct {
87 WORD PcSequence; 87 u16 PcSequence;
88 BYTE PcBootData[RTA_BOOT_DATA_SIZE]; 88 u8 PcBootData[RTA_BOOT_DATA_SIZE];
89 } S2; 89 } S2;
90 struct { 90 struct {
91 WORD __crud__; 91 u16 __crud__;
92 BYTE PcUniqNum[4]; /* this is really a uint. */ 92 u8 PcUniqNum[4]; /* this is really a uint. */
93 BYTE PcModuleTypes; /* what modules are fitted */ 93 u8 PcModuleTypes; /* what modules are fitted */
94 } S3; 94 } S3;
95 struct { 95 struct {
96 struct CmdHdr CmdHdr; 96 struct CmdHdr CmdHdr;
97 BYTE __undefined__; 97 u8 __undefined__;
98 BYTE PcModemStatus; 98 u8 PcModemStatus;
99 BYTE PcPortStatus; 99 u8 PcPortStatus;
100 BYTE PcSubCommand; /* commands like mem or register dump */ 100 u8 PcSubCommand; /* commands like mem or register dump */
101 WORD PcSubAddr; /* Address for command */ 101 u16 PcSubAddr; /* Address for command */
102 BYTE PcSubData[64]; /* Date area for command */ 102 u8 PcSubData[64]; /* Date area for command */
103 } S4; 103 } S4;
104 struct { 104 struct {
105 struct CmdHdr CmdHdr; 105 struct CmdHdr CmdHdr;
106 BYTE PcCommandText[1]; 106 u8 PcCommandText[1];
107 BYTE __crud__[20]; 107 u8 __crud__[20];
108 BYTE PcIDNum2; /* It had to go somewhere! */ 108 u8 PcIDNum2; /* It had to go somewhere! */
109 } S5; 109 } S5;
110 struct { 110 struct {
111 struct CmdHdr CmdHdr; 111 struct CmdHdr CmdHdr;
@@ -118,45 +118,45 @@ struct PktCmd_M {
118 union { 118 union {
119 struct { 119 struct {
120 struct { 120 struct {
121 uchar PcCommand; 121 u8 PcCommand;
122 union { 122 union {
123 uchar PcPhbNum; 123 u8 PcPhbNum;
124 uchar PcLinkNum; 124 u8 PcLinkNum;
125 uchar PcIDNum; 125 u8 PcIDNum;
126 } U0; 126 } U0;
127 } CmdHdr; 127 } CmdHdr;
128 struct { 128 struct {
129 ushort NumPackets; 129 u16 NumPackets;
130 ushort LoadBase; 130 u16 LoadBase;
131 ushort CodeSize; 131 u16 CodeSize;
132 } PcBootSequence; 132 } PcBootSequence;
133 } S1; 133 } S1;
134 struct { 134 struct {
135 ushort PcSequence; 135 u16 PcSequence;
136 uchar PcBootData[RTA_BOOT_DATA_SIZE]; 136 u8 PcBootData[RTA_BOOT_DATA_SIZE];
137 } S2; 137 } S2;
138 struct { 138 struct {
139 ushort __crud__; 139 u16 __crud__;
140 uchar PcUniqNum[4]; /* this is really a uint. */ 140 u8 PcUniqNum[4]; /* this is really a uint. */
141 uchar PcModuleTypes; /* what modules are fitted */ 141 u8 PcModuleTypes; /* what modules are fitted */
142 } S3; 142 } S3;
143 struct { 143 struct {
144 ushort __cmd_hdr__; 144 u16 __cmd_hdr__;
145 uchar __undefined__; 145 u8 __undefined__;
146 uchar PcModemStatus; 146 u8 PcModemStatus;
147 uchar PcPortStatus; 147 u8 PcPortStatus;
148 uchar PcSubCommand; 148 u8 PcSubCommand;
149 ushort PcSubAddr; 149 u16 PcSubAddr;
150 uchar PcSubData[64]; 150 u8 PcSubData[64];
151 } S4; 151 } S4;
152 struct { 152 struct {
153 ushort __cmd_hdr__; 153 u16 __cmd_hdr__;
154 uchar PcCommandText[1]; 154 u8 PcCommandText[1];
155 uchar __crud__[20]; 155 u8 __crud__[20];
156 uchar PcIDNum2; /* Tacked on end */ 156 u8 PcIDNum2; /* Tacked on end */
157 } S5; 157 } S5;
158 struct { 158 struct {
159 ushort __cmd_hdr__; 159 u16 __cmd_hdr__;
160 struct Top Topology[LINKS_PER_UNIT]; 160 struct Top Topology[LINKS_PER_UNIT];
161 } S6; 161 } S6;
162 } U1; 162 } U1;
diff --git a/drivers/char/rio/control.h b/drivers/char/rio/control.h
deleted file mode 100644
index 6853d03304..0000000000
--- a/drivers/char/rio/control.h
+++ /dev/null
@@ -1,61 +0,0 @@
1
2
3/****************************************************************************
4 ******* *******
5 ******* C O N T R O L P A C K E T H E A D E R S
6 ******* *******
7 ****************************************************************************
8
9 Author : Jon Brawn
10 Date :
11
12 *
13 * (C) 1990 - 2000 Specialix International Ltd., Byfleet, Surrey, UK.
14 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28
29 Version : 0.01
30
31
32 Mods
33 ----------------------------------------------------------------------------
34 Date By Description
35 ----------------------------------------------------------------------------
36
37 ***************************************************************************/
38
39
40#ifndef _control_h
41#define _control_h
42
43#ifndef lint
44/* static char *_rio_control_h_sccs = "@(#)control.h 1.4"; */
45#endif
46
47#define CONTROL '^'
48#define IFOAD ( CONTROL + 1 )
49#define IDENTIFY ( CONTROL + 2 )
50#define ZOMBIE ( CONTROL + 3 )
51#define UFOAD ( CONTROL + 4 )
52#define IWAIT ( CONTROL + 5 )
53
54#define IFOAD_MAGIC 0xF0AD /* of course */
55#define ZOMBIE_MAGIC (~0xDEAD) /* not dead -> zombie */
56#define UFOAD_MAGIC 0xD1E /* kill-your-neighbour */
57#define IWAIT_MAGIC 0xB1DE /* Bide your time */
58
59#endif
60
61/*********** end of file ***********/
diff --git a/drivers/char/rio/daemon.h b/drivers/char/rio/daemon.h
index 28a991bd4f..5818a8aa46 100644
--- a/drivers/char/rio/daemon.h
+++ b/drivers/char/rio/daemon.h
@@ -45,15 +45,15 @@ static char *_daemon_h_sccs_ = "@(#)daemon.h 1.3";
45*/ 45*/
46 46
47struct Error { 47struct Error {
48 uint Error; 48 unsigned int Error;
49 uint Entry; 49 unsigned int Entry;
50 uint Other; 50 unsigned int Other;
51}; 51};
52 52
53struct DownLoad { 53struct DownLoad {
54 char *DataP; 54 char *DataP;
55 uint Count; 55 unsigned int Count;
56 uint ProductCode; 56 unsigned int ProductCode;
57}; 57};
58 58
59/* 59/*
@@ -68,69 +68,64 @@ struct DownLoad {
68#endif 68#endif
69 69
70struct PortSetup { 70struct PortSetup {
71 uint From; /* Set/Clear XP & IXANY Control from this port.... */ 71 unsigned int From; /* Set/Clear XP & IXANY Control from this port.... */
72 uint To; /* .... to this port */ 72 unsigned int To; /* .... to this port */
73 uint XpCps; /* at this speed */ 73 unsigned int XpCps; /* at this speed */
74 char XpOn[MAX_XP_CTRL_LEN]; /* this is the start string */ 74 char XpOn[MAX_XP_CTRL_LEN]; /* this is the start string */
75 char XpOff[MAX_XP_CTRL_LEN]; /* this is the stop string */ 75 char XpOff[MAX_XP_CTRL_LEN]; /* this is the stop string */
76 uchar IxAny; /* enable/disable IXANY */ 76 u8 IxAny; /* enable/disable IXANY */
77 uchar IxOn; /* enable/disable IXON */ 77 u8 IxOn; /* enable/disable IXON */
78 uchar Lock; /* lock port params */ 78 u8 Lock; /* lock port params */
79 uchar Store; /* store params across closes */ 79 u8 Store; /* store params across closes */
80 uchar Drain; /* close only when drained */ 80 u8 Drain; /* close only when drained */
81}; 81};
82 82
83struct LpbReq { 83struct LpbReq {
84 uint Host; 84 unsigned int Host;
85 uint Link; 85 unsigned int Link;
86 struct LPB *LpbP; 86 struct LPB *LpbP;
87}; 87};
88 88
89struct RupReq { 89struct RupReq {
90 uint HostNum; 90 unsigned int HostNum;
91 uint RupNum; 91 unsigned int RupNum;
92 struct RUP *RupP; 92 struct RUP *RupP;
93}; 93};
94 94
95struct PortReq { 95struct PortReq {
96 uint SysPort; 96 unsigned int SysPort;
97 struct Port *PortP; 97 struct Port *PortP;
98}; 98};
99 99
100struct StreamInfo { 100struct StreamInfo {
101 uint SysPort; 101 unsigned int SysPort;
102#if 0
103 queue_t RQueue;
104 queue_t WQueue;
105#else
106 int RQueue; 102 int RQueue;
107 int WQueue; 103 int WQueue;
108#endif
109}; 104};
110 105
111struct HostReq { 106struct HostReq {
112 uint HostNum; 107 unsigned int HostNum;
113 struct Host *HostP; 108 struct Host *HostP;
114}; 109};
115 110
116struct HostDpRam { 111struct HostDpRam {
117 uint HostNum; 112 unsigned int HostNum;
118 struct DpRam *DpRamP; 113 struct DpRam *DpRamP;
119}; 114};
120 115
121struct DebugCtrl { 116struct DebugCtrl {
122 uint SysPort; 117 unsigned int SysPort;
123 uint Debug; 118 unsigned int Debug;
124 uint Wait; 119 unsigned int Wait;
125}; 120};
126 121
127struct MapInfo { 122struct MapInfo {
128 uint FirstPort; /* 8 ports, starting from this (tty) number */ 123 unsigned int FirstPort; /* 8 ports, starting from this (tty) number */
129 uint RtaUnique; /* reside on this RTA (unique number) */ 124 unsigned int RtaUnique; /* reside on this RTA (unique number) */
130}; 125};
131 126
132struct MapIn { 127struct MapIn {
133 uint NumEntries; /* How many port sets are we mapping? */ 128 unsigned int NumEntries; /* How many port sets are we mapping? */
134 struct MapInfo *MapInfoP; /* Pointer to (user space) info */ 129 struct MapInfo *MapInfoP; /* Pointer to (user space) info */
135}; 130};
136 131
@@ -147,13 +142,13 @@ struct SpecialRupCmd {
147}; 142};
148 143
149struct IdentifyRta { 144struct IdentifyRta {
150 ulong RtaUnique; 145 unsigned long RtaUnique;
151 uchar ID; 146 u8 ID;
152}; 147};
153 148
154struct KillNeighbour { 149struct KillNeighbour {
155 ulong UniqueNum; 150 unsigned long UniqueNum;
156 uchar Link; 151 u8 Link;
157}; 152};
158 153
159struct rioVersion { 154struct rioVersion {
diff --git a/drivers/char/rio/defaults.h b/drivers/char/rio/defaults.h
deleted file mode 100644
index d55c2f6a98..0000000000
--- a/drivers/char/rio/defaults.h
+++ /dev/null
@@ -1,51 +0,0 @@
1
2/****************************************************************************
3 ******* *******
4 ******* D E F A U L T S
5 ******* *******
6 ****************************************************************************
7
8 Author : Ian Nandhra
9 Date :
10
11 *
12 * (C) 1990 - 2000 Specialix International Ltd., Byfleet, Surrey, UK.
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; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27
28 Version : 0.01
29
30
31 Mods
32 ----------------------------------------------------------------------------
33 Date By Description
34 ----------------------------------------------------------------------------
35
36 ***************************************************************************/
37
38#ifndef lint
39#ifdef SCCS
40static char *_rio_defaults_h_sccs = "@(#)defaults.h 1.1";
41#endif
42#endif
43
44
45#define MILLISECOND (int) (1000/64) /* 15.625 low ticks */
46#define SECOND (int) 15625 /* Low priority ticks */
47
48#define LINK_TIMEOUT (int) (POLL_PERIOD / 2)
49
50
51/*********** end of file ***********/
diff --git a/drivers/char/rio/error.h b/drivers/char/rio/error.h
deleted file mode 100644
index f20f0789db..0000000000
--- a/drivers/char/rio/error.h
+++ /dev/null
@@ -1,82 +0,0 @@
1
2/****************************************************************************
3 ******* *******
4 ******* E R R O R H E A D E R F I L E
5 ******* *******
6 ****************************************************************************
7
8 Author : Ian Nandhra
9 Date :
10
11 *
12 * (C) 1990 - 2000 Specialix International Ltd., Byfleet, Surrey, UK.
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; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27
28 Version : 0.01
29
30
31 Mods
32 ----------------------------------------------------------------------------
33 Date By Description
34 ----------------------------------------------------------------------------
35
36 ***************************************************************************/
37
38#ifndef lint
39/* static char *_rio_error_h_sccs = "@(#)error.h 1.3"; */
40#endif
41
42#define E_NO_ERROR ((ushort) 0)
43#define E_PROCESS_NOT_INIT ((ushort) 1)
44#define E_LINK_TIMEOUT ((ushort) 2)
45#define E_NO_ROUTE ((ushort) 3)
46#define E_CONFUSED ((ushort) 4)
47#define E_HOME ((ushort) 5)
48#define E_CSUM_FAIL ((ushort) 6)
49#define E_DISCONNECTED ((ushort) 7)
50#define E_BAD_RUP ((ushort) 8)
51#define E_NO_VIRGIN ((ushort) 9)
52#define E_BOOT_RUP_BUSY ((ushort) 10)
53
54
55
56 /*************************************************
57 * Parsed to mem_halt()
58 ************************************************/
59#define E_CHANALLOC ((ushort) 0x80)
60#define E_POLL_ALLOC ((ushort) 0x81)
61#define E_LTTWAKE ((ushort) 0x82)
62#define E_LTT_ALLOC ((ushort) 0x83)
63#define E_LRT_ALLOC ((ushort) 0x84)
64#define E_CIRRUS ((ushort) 0x85)
65#define E_MONITOR ((ushort) 0x86)
66#define E_PHB_ALLOC ((ushort) 0x87)
67#define E_ARRAY_ALLOC ((ushort) 0x88)
68#define E_QBUF_ALLOC ((ushort) 0x89)
69#define E_PKT_ALLOC ((ushort) 0x8a)
70#define E_GET_TX_Q_BUF ((ushort) 0x8b)
71#define E_GET_RX_Q_BUF ((ushort) 0x8c)
72#define E_MEM_OUT ((ushort) 0x8d)
73#define E_MMU_INIT ((ushort) 0x8e)
74#define E_LTT_INIT ((ushort) 0x8f)
75#define E_LRT_INIT ((ushort) 0x90)
76#define E_LINK_RUN ((ushort) 0x91)
77#define E_MONITOR_ALLOC ((ushort) 0x92)
78#define E_MONITOR_INIT ((ushort) 0x93)
79#define E_POLL_INIT ((ushort) 0x94)
80
81
82/*********** end of file ***********/
diff --git a/drivers/char/rio/func.h b/drivers/char/rio/func.h
index b4778410ec..e64fe99123 100644
--- a/drivers/char/rio/func.h
+++ b/drivers/char/rio/func.h
@@ -43,35 +43,33 @@ static char *_func_h_sccs_ = "@(#)func.h 1.3";
43 43
44/* rioboot.c */ 44/* rioboot.c */
45int RIOBootCodeRTA(struct rio_info *, struct DownLoad *); 45int RIOBootCodeRTA(struct rio_info *, struct DownLoad *);
46int RIOBootCodeHOST(struct rio_info *, register struct DownLoad *); 46int RIOBootCodeHOST(struct rio_info *, struct DownLoad *);
47int RIOBootCodeUNKNOWN(struct rio_info *, struct DownLoad *); 47int RIOBootCodeUNKNOWN(struct rio_info *, struct DownLoad *);
48void msec_timeout(struct Host *); 48void msec_timeout(struct Host *);
49int RIOBootRup(struct rio_info *, uint, struct Host *, struct PKT *); 49int RIOBootRup(struct rio_info *, unsigned int, struct Host *, struct PKT *);
50int RIOBootOk(struct rio_info *, struct Host *, ulong); 50int RIOBootOk(struct rio_info *, struct Host *, unsigned long);
51int RIORtaBound(struct rio_info *, uint); 51int RIORtaBound(struct rio_info *, unsigned int);
52void FillSlot(int, int, uint, struct Host *); 52void rio_fill_host_slot(int, int, unsigned int, struct Host *);
53 53
54/* riocmd.c */ 54/* riocmd.c */
55int RIOFoadRta(struct Host *, struct Map *); 55int RIOFoadRta(struct Host *, struct Map *);
56int RIOZombieRta(struct Host *, struct Map *); 56int RIOZombieRta(struct Host *, struct Map *);
57int RIOCommandRta(struct rio_info *, uint, int (*func) (struct Host *, struct Map *)); 57int RIOCommandRta(struct rio_info *, unsigned long, int (*func) (struct Host *, struct Map *));
58int RIOIdentifyRta(struct rio_info *, caddr_t); 58int RIOIdentifyRta(struct rio_info *, void *);
59int RIOKillNeighbour(struct rio_info *, caddr_t); 59int RIOKillNeighbour(struct rio_info *, void *);
60int RIOSuspendBootRta(struct Host *, int, int); 60int RIOSuspendBootRta(struct Host *, int, int);
61int RIOFoadWakeup(struct rio_info *); 61int RIOFoadWakeup(struct rio_info *);
62struct CmdBlk *RIOGetCmdBlk(void); 62struct CmdBlk *RIOGetCmdBlk(void);
63void RIOFreeCmdBlk(struct CmdBlk *); 63void RIOFreeCmdBlk(struct CmdBlk *);
64int RIOQueueCmdBlk(struct Host *, uint, struct CmdBlk *); 64int RIOQueueCmdBlk(struct Host *, unsigned int, struct CmdBlk *);
65void RIOPollHostCommands(struct rio_info *, struct Host *); 65void RIOPollHostCommands(struct rio_info *, struct Host *);
66int RIOWFlushMark(int, struct CmdBlk *); 66int RIOWFlushMark(unsigned long, struct CmdBlk *);
67int RIORFlushEnable(int, struct CmdBlk *); 67int RIORFlushEnable(unsigned long, struct CmdBlk *);
68int RIOUnUse(int, struct CmdBlk *); 68int RIOUnUse(unsigned long, struct CmdBlk *);
69void ShowPacket(uint, struct PKT *);
70 69
71/* rioctrl.c */ 70/* rioctrl.c */
72int copyin(int, caddr_t, int);
73int riocontrol(struct rio_info *, dev_t, int, caddr_t, int); 71int riocontrol(struct rio_info *, dev_t, int, caddr_t, int);
74int RIOPreemptiveCmd(struct rio_info *, struct Port *, uchar); 72int RIOPreemptiveCmd(struct rio_info *, struct Port *, unsigned char);
75 73
76/* rioinit.c */ 74/* rioinit.c */
77void rioinit(struct rio_info *, struct RioHostInfo *); 75void rioinit(struct rio_info *, struct RioHostInfo *);
@@ -80,19 +78,17 @@ void RIOISAinit(struct rio_info *, int);
80int RIODoAT(struct rio_info *, int, int); 78int RIODoAT(struct rio_info *, int, int);
81caddr_t RIOCheckForATCard(int); 79caddr_t RIOCheckForATCard(int);
82int RIOAssignAT(struct rio_info *, int, caddr_t, int); 80int RIOAssignAT(struct rio_info *, int, caddr_t, int);
83int RIOBoardTest(paddr_t, caddr_t, uchar, int); 81int RIOBoardTest(unsigned long, caddr_t, unsigned char, int);
84void RIOAllocDataStructs(struct rio_info *); 82void RIOAllocDataStructs(struct rio_info *);
85void RIOSetupDataStructs(struct rio_info *); 83void RIOSetupDataStructs(struct rio_info *);
86int RIODefaultName(struct rio_info *, struct Host *, uint); 84int RIODefaultName(struct rio_info *, struct Host *, unsigned int);
87struct rioVersion *RIOVersid(void); 85struct rioVersion *RIOVersid(void);
88int RIOMapin(paddr_t, int, caddr_t *); 86void RIOHostReset(unsigned int, struct DpRam *, unsigned int);
89void RIOMapout(paddr_t, long, caddr_t);
90void RIOHostReset(uint, volatile struct DpRam *, uint);
91 87
92/* riointr.c */ 88/* riointr.c */
93void RIOTxEnable(char *); 89void RIOTxEnable(char *);
94void RIOServiceHost(struct rio_info *, struct Host *, int); 90void RIOServiceHost(struct rio_info *, struct Host *, int);
95int riotproc(struct rio_info *, register struct ttystatics *, int, int); 91int riotproc(struct rio_info *, struct ttystatics *, int, int);
96 92
97/* rioparam.c */ 93/* rioparam.c */
98int RIOParam(struct Port *, int, int, int); 94int RIOParam(struct Port *, int, int, int);
@@ -106,18 +102,18 @@ int can_remove_receive(struct PKT **, struct Port *);
106void remove_receive(struct Port *); 102void remove_receive(struct Port *);
107 103
108/* rioroute.c */ 104/* rioroute.c */
109int RIORouteRup(struct rio_info *, uint, struct Host *, struct PKT *); 105int RIORouteRup(struct rio_info *, unsigned int, struct Host *, struct PKT *);
110void RIOFixPhbs(struct rio_info *, struct Host *, uint); 106void RIOFixPhbs(struct rio_info *, struct Host *, unsigned int);
111uint GetUnitType(uint); 107unsigned int GetUnitType(unsigned int);
112int RIOSetChange(struct rio_info *); 108int RIOSetChange(struct rio_info *);
113int RIOFindFreeID(struct rio_info *, struct Host *, uint *, uint *); 109int RIOFindFreeID(struct rio_info *, struct Host *, unsigned int *, unsigned int *);
114 110
115 111
116/* riotty.c */ 112/* riotty.c */
117 113
118int riotopen(struct tty_struct *tty, struct file *filp); 114int riotopen(struct tty_struct *tty, struct file *filp);
119int riotclose(void *ptr); 115int riotclose(void *ptr);
120int riotioctl(struct rio_info *, struct tty_struct *, register int, register caddr_t); 116int riotioctl(struct rio_info *, struct tty_struct *, int, caddr_t);
121void ttyseth(struct Port *, struct ttystatics *, struct old_sgttyb *sg); 117void ttyseth(struct Port *, struct ttystatics *, struct old_sgttyb *sg);
122 118
123/* riotable.c */ 119/* riotable.c */
@@ -131,7 +127,7 @@ int RIOChangeName(struct rio_info *, struct Map *);
131#if 0 127#if 0
132/* riodrvr.c */ 128/* riodrvr.c */
133struct rio_info *rio_install(struct RioHostInfo *); 129struct rio_info *rio_install(struct RioHostInfo *);
134int rio_uninstall(register struct rio_info *); 130int rio_uninstall(struct rio_info *);
135int rio_open(struct rio_info *, int, struct file *); 131int rio_open(struct rio_info *, int, struct file *);
136int rio_close(struct rio_info *, struct file *); 132int rio_close(struct rio_info *, struct file *);
137int rio_read(struct rio_info *, struct file *, char *, int); 133int rio_read(struct rio_info *, struct file *, char *, int);
@@ -143,7 +139,7 @@ int rio_isr_thread(char *);
143struct rio_info *rio_info_store(int cmd, struct rio_info *p); 139struct rio_info *rio_info_store(int cmd, struct rio_info *p);
144#endif 140#endif
145 141
146extern int rio_pcicopy(char *src, char *dst, int n); 142extern void rio_copy_to_card(void *to, void *from, int len);
147extern int rio_minor(struct tty_struct *tty); 143extern int rio_minor(struct tty_struct *tty);
148extern int rio_ismodem(struct tty_struct *tty); 144extern int rio_ismodem(struct tty_struct *tty);
149 145
diff --git a/drivers/char/rio/host.h b/drivers/char/rio/host.h
index f7dfcedf7d..3ec73d1a27 100644
--- a/drivers/char/rio/host.h
+++ b/drivers/char/rio/host.h
@@ -50,22 +50,20 @@ static char *_host_h_sccs_ = "@(#)host.h 1.2";
50** the host. 50** the host.
51*/ 51*/
52struct Host { 52struct Host {
53 uchar Type; /* RIO_EISA, RIO_MCA, ... */ 53 unsigned char Type; /* RIO_EISA, RIO_MCA, ... */
54 uchar Ivec; /* POLLED or ivec number */ 54 unsigned char Ivec; /* POLLED or ivec number */
55 uchar Mode; /* Control stuff */ 55 unsigned char Mode; /* Control stuff */
56 uchar Slot; /* Slot */ 56 unsigned char Slot; /* Slot */
57 volatile caddr_t Caddr; /* KV address of DPRAM */ 57 caddr_t Caddr; /* KV address of DPRAM */
58 volatile struct DpRam *CardP; /* KV address of DPRAM, with overlay */ 58 struct DpRam *CardP; /* KV address of DPRAM, with overlay */
59 paddr_t PaddrP; /* Phys. address of DPRAM */ 59 unsigned long PaddrP; /* Phys. address of DPRAM */
60 char Name[MAX_NAME_LEN]; /* The name of the host */ 60 char Name[MAX_NAME_LEN]; /* The name of the host */
61 uint UniqueNum; /* host unique number */ 61 unsigned int UniqueNum; /* host unique number */
62 spinlock_t HostLock; /* Lock structure for MPX */ 62 spinlock_t HostLock; /* Lock structure for MPX */
63 /*struct pci_devinfo PciDevInfo; *//* PCI Bus/Device/Function stuff */ 63 unsigned int WorkToBeDone; /* set to true each interrupt */
64 /*struct lockb HostLock; *//* Lock structure for MPX */ 64 unsigned int InIntr; /* Being serviced? */
65 uint WorkToBeDone; /* set to true each interrupt */ 65 unsigned int IntSrvDone; /* host's interrupt has been serviced */
66 uint InIntr; /* Being serviced? */ 66 void (*Copy) (void *, void *, int); /* copy func */
67 uint IntSrvDone; /* host's interrupt has been serviced */
68 int (*Copy) (caddr_t, caddr_t, int); /* copy func */
69 struct timer_list timer; 67 struct timer_list timer;
70 /* 68 /*
71 ** I M P O R T A N T ! 69 ** I M P O R T A N T !
@@ -74,7 +72,7 @@ struct Host {
74 ** a RIO_HOST_FOAD command. 72 ** a RIO_HOST_FOAD command.
75 */ 73 */
76 74
77 ulong Flags; /* Whats going down */ 75 unsigned long Flags; /* Whats going down */
78#define RC_WAITING 0 76#define RC_WAITING 0
79#define RC_STARTUP 1 77#define RC_STARTUP 1
80#define RC_RUNNING 2 78#define RC_RUNNING 2
@@ -88,28 +86,28 @@ struct Host {
88** Boot mode applies to the way in which hosts in this system will 86** Boot mode applies to the way in which hosts in this system will
89** boot RTAs 87** boot RTAs
90*/ 88*/
91#define RC_BOOT_ALL 0x8 /* Boot all RTAs attached */ 89#define RC_BOOT_ALL 0x8 /* Boot all RTAs attached */
92#define RC_BOOT_OWN 0x10 /* Only boot RTAs bound to this system */ 90#define RC_BOOT_OWN 0x10 /* Only boot RTAs bound to this system */
93#define RC_BOOT_NONE 0x20 /* Don't boot any RTAs (slave mode) */ 91#define RC_BOOT_NONE 0x20 /* Don't boot any RTAs (slave mode) */
94 92
95 struct Top Topology[LINKS_PER_UNIT]; /* one per link */ 93 struct Top Topology[LINKS_PER_UNIT]; /* one per link */
96 struct Map Mapping[MAX_RUP]; /* Mappings for host */ 94 struct Map Mapping[MAX_RUP]; /* Mappings for host */
97 struct PHB *PhbP; /* Pointer to the PHB array */ 95 struct PHB *PhbP; /* Pointer to the PHB array */
98 ushort *PhbNumP; /* Ptr to Number of PHB's */ 96 unsigned short *PhbNumP; /* Ptr to Number of PHB's */
99 struct LPB *LinkStrP; /* Link Structure Array */ 97 struct LPB *LinkStrP; /* Link Structure Array */
100 struct RUP *RupP; /* Sixteen real rups here */ 98 struct RUP *RupP; /* Sixteen real rups here */
101 struct PARM_MAP *ParmMapP; /* points to the parmmap */ 99 struct PARM_MAP *ParmMapP; /* points to the parmmap */
102 uint ExtraUnits[MAX_EXTRA_UNITS]; /* unknown things */ 100 unsigned int ExtraUnits[MAX_EXTRA_UNITS]; /* unknown things */
103 uint NumExtraBooted; /* how many of the above */ 101 unsigned int NumExtraBooted; /* how many of the above */
104 /* 102 /*
105 ** Twenty logical rups. 103 ** Twenty logical rups.
106 ** The first sixteen are the real Rup entries (above), the last four 104 ** The first sixteen are the real Rup entries (above), the last four
107 ** are the link RUPs. 105 ** are the link RUPs.
108 */ 106 */
109 struct UnixRup UnixRups[MAX_RUP + LINKS_PER_UNIT]; 107 struct UnixRup UnixRups[MAX_RUP + LINKS_PER_UNIT];
110 int timeout_id; /* For calling 100 ms delays */ 108 int timeout_id; /* For calling 100 ms delays */
111 int timeout_sem; /* For calling 100 ms delays */ 109 int timeout_sem; /* For calling 100 ms delays */
112 long locks; /* long req'd for set_bit --RR */ 110 long locks; /* long req'd for set_bit --RR */
113 char ____end_marker____; 111 char ____end_marker____;
114}; 112};
115#define Control CardP->DpControl 113#define Control CardP->DpControl
diff --git a/drivers/char/rio/link.h b/drivers/char/rio/link.h
index 48d68ca7f8..f3bf11a04d 100644
--- a/drivers/char/rio/link.h
+++ b/drivers/char/rio/link.h
@@ -37,38 +37,9 @@
37#ifndef _link_h 37#ifndef _link_h
38#define _link_h 1 38#define _link_h 1
39 39
40#ifndef lint
41#ifdef SCCS_LABELS
42/* static char *_rio_link_h_sccs = "@(#)link.h 1.15"; */
43#endif
44#endif
45
46
47
48/************************************************* 40/*************************************************
49 * Define the Link Status stuff 41 * Define the Link Status stuff
50 ************************************************/ 42 ************************************************/
51#define LRT_ACTIVE ((ushort) 0x01)
52#define LRT_SPARE1 ((ushort) 0x02)
53#define INTRO_RCVD ((ushort) 0x04)
54#define FORCED_DISCONNECT ((ushort) 0x08)
55#define LRT_SPARE2 ((ushort) 0x80)
56
57#define TOP_OF_RTA_RAM ((ushort) 0x7000)
58#define HOST_SERIAL_POINTER (unsigned char **) (TOP_OF_RTA_RAM - 2 * sizeof (ushort))
59
60/* Flags for ltt_status */
61#define WAITING_ACK (ushort) 0x0001
62#define DATA_SENT (ushort) 0x0002
63#define WAITING_RUP (ushort) 0x0004
64#define WAITING_RETRY (ushort) 0x0008
65#define WAITING_TOPOLOGY (ushort) 0x0010
66#define SEND_SYNC (ushort) 0x0020
67#define FOAD_THIS_LINK (ushort) 0x0040
68#define REQUEST_SYNC (ushort) 0x0080
69#define REMOTE_DYING (ushort) 0x0100
70#define DIE_NOW (ushort) 0x0200
71
72/* Boot request stuff */ 43/* Boot request stuff */
73#define BOOT_REQUEST ((ushort) 0) /* Request for a boot */ 44#define BOOT_REQUEST ((ushort) 0) /* Request for a boot */
74#define BOOT_ABORT ((ushort) 1) /* Abort a boot */ 45#define BOOT_ABORT ((ushort) 1) /* Abort a boot */
@@ -76,77 +47,48 @@
76 and load address */ 47 and load address */
77#define BOOT_COMPLETED ((ushort) 3) /* Boot completed */ 48#define BOOT_COMPLETED ((ushort) 3) /* Boot completed */
78 49
79/* States that a link can be in */
80#define LINK_DISCONNECTED ((ushort) 0) /* Disconnected */
81#define LINK_BOOT1 ((ushort) 1) /* Trying to send 1st stage boot */
82#define LINK_BOOT2 ((ushort) 2) /* Trying to send 2nd stage boot */
83#define LINK_BOOT2WAIT ((ushort) 3) /* Waiting for selftest results */
84#define LINK_BOOT3 ((ushort) 4) /* Trying to send 3rd stage boots */
85#define LINK_SYNC ((ushort) 5) /* Syncing */
86
87#define LINK_INTRO ((ushort) 10) /* Introductory packet */
88#define LINK_SUPPLYID ((ushort) 11) /* Trying to supply an ID */
89#define LINK_TOPOLOGY ((ushort) 12) /* Send a topology update */
90#define LINK_REQUESTID ((ushort) 13) /* Waiting for an ID */
91#define LINK_CONNECTED ((ushort) 14) /* Connected */
92
93#define LINK_INTERCONNECT ((ushort) 20) /* Subnets interconnected */
94
95#define LINK_SPARE ((ushort) 40)
96
97/*
98** Set the default timeout for link communications.
99*/
100#define LINKTIMEOUT (400 * MILLISECOND)
101
102/*
103** LED stuff
104*/
105#define LED_SET_COLOUR(colour)
106#define LED_OR_COLOUR(colour)
107#define LED_TIMEOUT(time)
108 50
109struct LPB { 51struct LPB {
110 WORD link_number; /* Link Number */ 52 u16 link_number; /* Link Number */
111 Channel_ptr in_ch; /* Link In Channel */ 53 u16 in_ch; /* Link In Channel */
112 Channel_ptr out_ch; /* Link Out Channel */ 54 u16 out_ch; /* Link Out Channel */
113 BYTE attached_serial[4]; /* Attached serial number */ 55 u8 attached_serial[4]; /* Attached serial number */
114 BYTE attached_host_serial[4]; 56 u8 attached_host_serial[4];
115 /* Serial number of Host who 57 /* Serial number of Host who
116 booted the other end */ 58 booted the other end */
117 WORD descheduled; /* Currently Descheduled */ 59 u16 descheduled; /* Currently Descheduled */
118 WORD state; /* Current state */ 60 u16 state; /* Current state */
119 WORD send_poll; /* Send a Poll Packet */ 61 u16 send_poll; /* Send a Poll Packet */
120 Process_ptr ltt_p; /* Process Descriptor */ 62 u16 ltt_p; /* Process Descriptor */
121 Process_ptr lrt_p; /* Process Descriptor */ 63 u16 lrt_p; /* Process Descriptor */
122 WORD lrt_status; /* Current lrt status */ 64 u16 lrt_status; /* Current lrt status */
123 WORD ltt_status; /* Current ltt status */ 65 u16 ltt_status; /* Current ltt status */
124 WORD timeout; /* Timeout value */ 66 u16 timeout; /* Timeout value */
125 WORD topology; /* Topology bits */ 67 u16 topology; /* Topology bits */
126 WORD mon_ltt; 68 u16 mon_ltt;
127 WORD mon_lrt; 69 u16 mon_lrt;
128 WORD WaitNoBoot; /* Secs to hold off booting */ 70 u16 WaitNoBoot; /* Secs to hold off booting */
129 PKT_ptr add_packet_list; /* Add packets to here */ 71 u16 add_packet_list; /* Add packets to here */
130 PKT_ptr remove_packet_list; /* Send packets from here */ 72 u16 remove_packet_list; /* Send packets from here */
131 73
132 Channel_ptr lrt_fail_chan; /* Lrt's failure channel */ 74 u16 lrt_fail_chan; /* Lrt's failure channel */
133 Channel_ptr ltt_fail_chan; /* Ltt's failure channel */ 75 u16 ltt_fail_chan; /* Ltt's failure channel */
134 76
135 /* RUP structure for HOST to driver communications */ 77 /* RUP structure for HOST to driver communications */
136 struct RUP rup; 78 struct RUP rup;
137 struct RUP link_rup; /* RUP for the link (POLL, 79 struct RUP link_rup; /* RUP for the link (POLL,
138 topology etc.) */ 80 topology etc.) */
139 WORD attached_link; /* Number of attached link */ 81 u16 attached_link; /* Number of attached link */
140 WORD csum_errors; /* csum errors */ 82 u16 csum_errors; /* csum errors */
141 WORD num_disconnects; /* number of disconnects */ 83 u16 num_disconnects; /* number of disconnects */
142 WORD num_sync_rcvd; /* # sync's received */ 84 u16 num_sync_rcvd; /* # sync's received */
143 WORD num_sync_rqst; /* # sync requests */ 85 u16 num_sync_rqst; /* # sync requests */
144 WORD num_tx; /* Num pkts sent */ 86 u16 num_tx; /* Num pkts sent */
145 WORD num_rx; /* Num pkts received */ 87 u16 num_rx; /* Num pkts received */
146 WORD module_attached; /* Module tpyes of attached */ 88 u16 module_attached; /* Module tpyes of attached */
147 WORD led_timeout; /* LED timeout */ 89 u16 led_timeout; /* LED timeout */
148 WORD first_port; /* First port to service */ 90 u16 first_port; /* First port to service */
149 WORD last_port; /* Last port to service */ 91 u16 last_port; /* Last port to service */
150}; 92};
151 93
152#endif 94#endif
diff --git a/drivers/char/rio/linux_compat.h b/drivers/char/rio/linux_compat.h
index 17a14c4a34..34c0d2899e 100644
--- a/drivers/char/rio/linux_compat.h
+++ b/drivers/char/rio/linux_compat.h
@@ -19,56 +19,12 @@
19#include <linux/interrupt.h> 19#include <linux/interrupt.h>
20 20
21 21
22#define disable(oldspl) save_flags (oldspl)
23#define restore(oldspl) restore_flags (oldspl)
24
25#define sysbrk(x) kmalloc ((x),in_interrupt()? GFP_ATOMIC : GFP_KERNEL)
26#define sysfree(p,size) kfree ((p))
27
28#define WBYTE(p,v) writeb(v, &p)
29#define RBYTE(p) readb (&p)
30#define WWORD(p,v) writew(v, &p)
31#define RWORD(p) readw(&p)
32#define WINDW(p,v) writew(v, p)
33#define RINDW(p) readw(p)
34
35#define DEBUG_ALL 22#define DEBUG_ALL
36 23
37#define cprintf printk
38
39#ifdef __KERNEL__
40#define INKERNEL
41#endif
42
43struct ttystatics { 24struct ttystatics {
44 struct termios tm; 25 struct termios tm;
45}; 26};
46 27
47#define bzero(d, n) memset((d), 0, (n))
48#define bcopy(src, dest, n) memcpy ((dest), (src), (n))
49
50#define SEM_SIGIGNORE 0x1234
51
52#ifdef DEBUG_SEM
53#define swait(a,b) printk ("waiting: " __FILE__ " line %d\n", __LINE__)
54#define ssignal(sem) printk ("signalling: " __FILE__ " line %d\n", __LINE__)
55
56#define sreset(sem) printk ("sreset: " __FILE__ "\n")
57#define sem_init(sem,v) printk ("sreset: " __FILE__ "\n")
58#endif
59
60
61#define getpid() (current->pid)
62
63#define QSIZE SERIAL_XMIT_SIZE
64
65#define pseterr(errno) return (- errno)
66
67#define V_CBAUD CBAUD
68
69/* For one reason or another rioboot.c uses delay instead of RIODelay. */
70#define delay(x,y) RIODelay(NULL, y)
71
72extern int rio_debug; 28extern int rio_debug;
73 29
74#define RIO_DEBUG_INIT 0x000001 30#define RIO_DEBUG_INIT 0x000001
@@ -91,6 +47,7 @@ extern int rio_debug;
91#define RIO_DEBUG_DELAY 0x020000 47#define RIO_DEBUG_DELAY 0x020000
92#define RIO_DEBUG_MOD_COUNT 0x040000 48#define RIO_DEBUG_MOD_COUNT 0x040000
93 49
50
94/* Copied over from riowinif.h . This is ugly. The winif file declares 51/* Copied over from riowinif.h . This is ugly. The winif file declares
95also much other stuff which is incompatible with the headers from 52also much other stuff which is incompatible with the headers from
96the older driver. The older driver includes "brates.h" which shadows 53the older driver. The older driver includes "brates.h" which shadows
diff --git a/drivers/char/rio/list.h b/drivers/char/rio/list.h
deleted file mode 100644
index 79b853140a..0000000000
--- a/drivers/char/rio/list.h
+++ /dev/null
@@ -1,56 +0,0 @@
1/****************************************************************************
2 ******* *******
3 ******* L I S T *******
4 ******* *******
5 ****************************************************************************
6
7 Author : Jeremy Rolls.
8 Date : 04-Nov-1990
9
10 *
11 * (C) 1990 - 2000 Specialix International Ltd., Byfleet, Surrey, UK.
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
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 Version : 0.01
28
29
30 Mods
31 ----------------------------------------------------------------------------
32 Date By Description
33 ----------------------------------------------------------------------------
34 ***************************************************************************/
35
36#ifndef _list_h
37#define _list_h 1
38
39#ifdef SCCS_LABELS
40#ifndef lint
41static char *_rio_list_h_sccs = "@(#)list.h 1.9";
42#endif
43#endif
44
45#define PKT_IN_USE 0x1
46
47#define ZERO_PTR (ushort) 0x8000
48#define CaD PortP->Caddr
49
50/*
51** We can add another packet to a transmit queue if the packet pointer pointed
52** to by the TxAdd pointer has PKT_IN_USE clear in its address.
53*/
54
55#endif /* ifndef _list.h */
56/*********** end of file ***********/
diff --git a/drivers/char/rio/map.h b/drivers/char/rio/map.h
index 97fe287aab..bdbcd09c8b 100644
--- a/drivers/char/rio/map.h
+++ b/drivers/char/rio/map.h
@@ -47,17 +47,17 @@ static char *_map_h_sccs_ = "@(#)map.h 1.2";
47#define MAX_NAME_LEN 32 47#define MAX_NAME_LEN 32
48 48
49struct Map { 49struct Map {
50 uint HostUniqueNum; /* Supporting hosts unique number */ 50 unsigned int HostUniqueNum; /* Supporting hosts unique number */
51 uint RtaUniqueNum; /* Unique number */ 51 unsigned int RtaUniqueNum; /* Unique number */
52 /* 52 /*
53 ** The next two IDs must be swapped on big-endian architectures 53 ** The next two IDs must be swapped on big-endian architectures
54 ** when using a v2.04 /etc/rio/config with a v3.00 driver (when 54 ** when using a v2.04 /etc/rio/config with a v3.00 driver (when
55 ** upgrading for example). 55 ** upgrading for example).
56 */ 56 */
57 ushort ID; /* ID used in the subnet */ 57 unsigned short ID; /* ID used in the subnet */
58 ushort ID2; /* ID of 2nd block of 8 for 16 port */ 58 unsigned short ID2; /* ID of 2nd block of 8 for 16 port */
59 ulong Flags; /* Booted, ID Given, Disconnected */ 59 unsigned long Flags; /* Booted, ID Given, Disconnected */
60 ulong SysPort; /* First tty mapped to this port */ 60 unsigned long SysPort; /* First tty mapped to this port */
61 struct Top Topology[LINKS_PER_UNIT]; /* ID connected to each link */ 61 struct Top Topology[LINKS_PER_UNIT]; /* ID connected to each link */
62 char Name[MAX_NAME_LEN]; /* Cute name by which RTA is known */ 62 char Name[MAX_NAME_LEN]; /* Cute name by which RTA is known */
63}; 63};
diff --git a/drivers/char/rio/param.h b/drivers/char/rio/param.h
index de7e57180c..675c200b24 100644
--- a/drivers/char/rio/param.h
+++ b/drivers/char/rio/param.h
@@ -43,18 +43,18 @@ static char *_param_h_sccs_ = "@(#)param.h 1.2";
43*/ 43*/
44 44
45struct phb_param { 45struct phb_param {
46 BYTE Cmd; /* It is very important that these line up */ 46 u8 Cmd; /* It is very important that these line up */
47 BYTE Cor1; /* with what is expected at the other end. */ 47 u8 Cor1; /* with what is expected at the other end. */
48 BYTE Cor2; /* to confirm that you've got it right, */ 48 u8 Cor2; /* to confirm that you've got it right, */
49 BYTE Cor4; /* check with cirrus/cirrus.h */ 49 u8 Cor4; /* check with cirrus/cirrus.h */
50 BYTE Cor5; 50 u8 Cor5;
51 BYTE TxXon; /* Transmit X-On character */ 51 u8 TxXon; /* Transmit X-On character */
52 BYTE TxXoff; /* Transmit X-Off character */ 52 u8 TxXoff; /* Transmit X-Off character */
53 BYTE RxXon; /* Receive X-On character */ 53 u8 RxXon; /* Receive X-On character */
54 BYTE RxXoff; /* Receive X-Off character */ 54 u8 RxXoff; /* Receive X-Off character */
55 BYTE LNext; /* Literal-next character */ 55 u8 LNext; /* Literal-next character */
56 BYTE TxBaud; /* Transmit baudrate */ 56 u8 TxBaud; /* Transmit baudrate */
57 BYTE RxBaud; /* Receive baudrate */ 57 u8 RxBaud; /* Receive baudrate */
58}; 58};
59 59
60#endif 60#endif
diff --git a/drivers/char/rio/parmmap.h b/drivers/char/rio/parmmap.h
index e24acc1d18..9764ef85c5 100644
--- a/drivers/char/rio/parmmap.h
+++ b/drivers/char/rio/parmmap.h
@@ -47,40 +47,40 @@
47typedef struct PARM_MAP PARM_MAP; 47typedef struct PARM_MAP PARM_MAP;
48 48
49struct PARM_MAP { 49struct PARM_MAP {
50 PHB_ptr phb_ptr; /* Pointer to the PHB array */ 50 u16 phb_ptr; /* Pointer to the PHB array */
51 WORD_ptr phb_num_ptr; /* Ptr to Number of PHB's */ 51 u16 phb_num_ptr; /* Ptr to Number of PHB's */
52 FREE_LIST_ptr free_list; /* Free List pointer */ 52 u16 free_list; /* Free List pointer */
53 FREE_LIST_ptr free_list_end; /* Free List End pointer */ 53 u16 free_list_end; /* Free List End pointer */
54 Q_BUF_ptr_ptr q_free_list_ptr; /* Ptr to Q_BUF variable */ 54 u16 q_free_list_ptr; /* Ptr to Q_BUF variable */
55 BYTE_ptr unit_id_ptr; /* Unit Id */ 55 u16 unit_id_ptr; /* Unit Id */
56 LPB_ptr link_str_ptr; /* Link Structure Array */ 56 u16 link_str_ptr; /* Link Structure Array */
57 BYTE_ptr bootloader_1; /* 1st Stage Boot Loader */ 57 u16 bootloader_1; /* 1st Stage Boot Loader */
58 BYTE_ptr bootloader_2; /* 2nd Stage Boot Loader */ 58 u16 bootloader_2; /* 2nd Stage Boot Loader */
59 WORD_ptr port_route_map_ptr; /* Port Route Map */ 59 u16 port_route_map_ptr; /* Port Route Map */
60 ROUTE_STR_ptr route_ptr; /* Unit Route Map */ 60 u16 route_ptr; /* Unit Route Map */
61 NUMBER_ptr map_present; /* Route Map present */ 61 u16 map_present; /* Route Map present */
62 NUMBER pkt_num; /* Total number of packets */ 62 s16 pkt_num; /* Total number of packets */
63 NUMBER q_num; /* Total number of Q packets */ 63 s16 q_num; /* Total number of Q packets */
64 WORD buffers_per_port; /* Number of buffers per port */ 64 u16 buffers_per_port; /* Number of buffers per port */
65 WORD heap_size; /* Initial size of heap */ 65 u16 heap_size; /* Initial size of heap */
66 WORD heap_left; /* Current Heap left */ 66 u16 heap_left; /* Current Heap left */
67 WORD error; /* Error code */ 67 u16 error; /* Error code */
68 WORD tx_max; /* Max number of tx pkts per phb */ 68 u16 tx_max; /* Max number of tx pkts per phb */
69 WORD rx_max; /* Max number of rx pkts per phb */ 69 u16 rx_max; /* Max number of rx pkts per phb */
70 WORD rx_limit; /* For high / low watermarks */ 70 u16 rx_limit; /* For high / low watermarks */
71 NUMBER links; /* Links to use */ 71 s16 links; /* Links to use */
72 NUMBER timer; /* Interrupts per second */ 72 s16 timer; /* Interrupts per second */
73 RUP_ptr rups; /* Pointer to the RUPs */ 73 u16 rups; /* Pointer to the RUPs */
74 WORD max_phb; /* Mostly for debugging */ 74 u16 max_phb; /* Mostly for debugging */
75 WORD living; /* Just increments!! */ 75 u16 living; /* Just increments!! */
76 WORD init_done; /* Initialisation over */ 76 u16 init_done; /* Initialisation over */
77 WORD booting_link; 77 u16 booting_link;
78 WORD idle_count; /* Idle time counter */ 78 u16 idle_count; /* Idle time counter */
79 WORD busy_count; /* Busy counter */ 79 u16 busy_count; /* Busy counter */
80 WORD idle_control; /* Control Idle Process */ 80 u16 idle_control; /* Control Idle Process */
81 WORD tx_intr; /* TX interrupt pending */ 81 u16 tx_intr; /* TX interrupt pending */
82 WORD rx_intr; /* RX interrupt pending */ 82 u16 rx_intr; /* RX interrupt pending */
83 WORD rup_intr; /* RUP interrupt pending */ 83 u16 rup_intr; /* RUP interrupt pending */
84}; 84};
85 85
86#endif 86#endif
diff --git a/drivers/char/rio/phb.h b/drivers/char/rio/phb.h
index 2663ca0306..a4c48ae4e3 100644
--- a/drivers/char/rio/phb.h
+++ b/drivers/char/rio/phb.h
@@ -37,13 +37,6 @@
37#ifndef _phb_h 37#ifndef _phb_h
38#define _phb_h 1 38#define _phb_h 1
39 39
40#ifdef SCCS_LABELS
41#ifndef lint
42/* static char *_rio_phb_h_sccs = "@(#)phb.h 1.12"; */
43#endif
44#endif
45
46
47/************************************************* 40/*************************************************
48 * Handshake asserted. Deasserted by the LTT(s) 41 * Handshake asserted. Deasserted by the LTT(s)
49 ************************************************/ 42 ************************************************/
@@ -124,23 +117,23 @@
124 * the start. The pointer tx_add points to a SPACE to put a Packet. 117 * the start. The pointer tx_add points to a SPACE to put a Packet.
125 * The pointer tx_remove points to the next Packet to remove 118 * The pointer tx_remove points to the next Packet to remove
126 *************************************************************************/ 119 *************************************************************************/
127typedef struct PHB PHB; 120
128struct PHB { 121struct PHB {
129 WORD source; 122 u8 source;
130 WORD handshake; 123 u8 handshake;
131 WORD status; 124 u8 status;
132 NUMBER timeout; /* Maximum of 1.9 seconds */ 125 u16 timeout; /* Maximum of 1.9 seconds */
133 WORD link; /* Send down this link */ 126 u8 link; /* Send down this link */
134 WORD destination; 127 u8 destination;
135 PKT_ptr_ptr tx_start; 128 u16 tx_start;
136 PKT_ptr_ptr tx_end; 129 u16 tx_end;
137 PKT_ptr_ptr tx_add; 130 u16 tx_add;
138 PKT_ptr_ptr tx_remove; 131 u16 tx_remove;
139 132
140 PKT_ptr_ptr rx_start; 133 u16 rx_start;
141 PKT_ptr_ptr rx_end; 134 u16 rx_end;
142 PKT_ptr_ptr rx_add; 135 u16 rx_add;
143 PKT_ptr_ptr rx_remove; 136 u16 rx_remove;
144 137
145}; 138};
146 139
diff --git a/drivers/char/rio/pkt.h b/drivers/char/rio/pkt.h
index 7011e52e82..a9458164f0 100644
--- a/drivers/char/rio/pkt.h
+++ b/drivers/char/rio/pkt.h
@@ -37,14 +37,6 @@
37#ifndef _pkt_h 37#ifndef _pkt_h
38#define _pkt_h 1 38#define _pkt_h 1
39 39
40
41#ifdef SCCS_LABELS
42#ifndef lint
43/* static char *_rio_pkt_h_sccs = "@(#)pkt.h 1.8"; */
44#endif
45#endif
46
47#define MAX_TTL 0xf
48#define PKT_CMD_BIT ((ushort) 0x080) 40#define PKT_CMD_BIT ((ushort) 0x080)
49#define PKT_CMD_DATA ((ushort) 0x080) 41#define PKT_CMD_DATA ((ushort) 0x080)
50 42
@@ -70,15 +62,15 @@
70#define CONTROL_DATA_WNDW (DATA_WNDW << 8) 62#define CONTROL_DATA_WNDW (DATA_WNDW << 8)
71 63
72struct PKT { 64struct PKT {
73 BYTE dest_unit; /* Destination Unit Id */ 65 u8 dest_unit; /* Destination Unit Id */
74 BYTE dest_port; /* Destination POrt */ 66 u8 dest_port; /* Destination POrt */
75 BYTE src_unit; /* Source Unit Id */ 67 u8 src_unit; /* Source Unit Id */
76 BYTE src_port; /* Source POrt */ 68 u8 src_port; /* Source POrt */
77 BYTE len; 69 u8 len;
78 BYTE control; 70 u8 control;
79 BYTE data[PKT_MAX_DATA_LEN]; 71 u8 data[PKT_MAX_DATA_LEN];
80 /* Actual data :-) */ 72 /* Actual data :-) */
81 WORD csum; /* C-SUM */ 73 u16 csum; /* C-SUM */
82}; 74};
83#endif 75#endif
84 76
diff --git a/drivers/char/rio/port.h b/drivers/char/rio/port.h
index c99b1e70fd..9b5fa3eb04 100644
--- a/drivers/char/rio/port.h
+++ b/drivers/char/rio/port.h
@@ -33,91 +33,37 @@
33#ifndef __rio_port_h__ 33#ifndef __rio_port_h__
34#define __rio_port_h__ 34#define __rio_port_h__
35 35
36#ifdef SCCS_LABELS
37static char *_port_h_sccs_ = "@(#)port.h 1.3";
38#endif
39
40
41#undef VPIX
42
43
44/*
45** the port data structure - one per port in the system
46*/
47
48#ifdef STATS
49struct RIOStats {
50 /*
51 ** interrupt statistics
52 */
53 uint BreakIntCnt;
54 uint ModemOffCnt;
55 uint ModemOnCnt;
56 uint RxIntCnt;
57 uint TxIntCnt;
58 /*
59 ** throughput statistics
60 */
61 uint RxCharCnt;
62 uint RxPktCnt;
63 uint RxSaveCnt;
64 uint TxCharCnt;
65 uint TxPktCnt;
66 /*
67 ** driver entry statistics
68 */
69 uint CloseCnt;
70 uint IoctlCnt;
71 uint OpenCnt;
72 uint ReadCnt;
73 uint WriteCnt;
74 /*
75 ** proc statistics
76 */
77 uint BlockCnt;
78 uint OutputCnt;
79 uint ResumeCnt;
80 uint RflushCnt;
81 uint SuspendCnt;
82 uint TbreakCnt;
83 uint TimeoutCnt;
84 uint UnblockCnt;
85 uint WflushCnt;
86 uint WFBodgeCnt;
87};
88#endif
89
90/* 36/*
91** Port data structure 37** Port data structure
92*/ 38*/
93struct Port { 39struct Port {
94 struct gs_port gs; 40 struct gs_port gs;
95 int PortNum; /* RIO port no., 0-511 */ 41 int PortNum; /* RIO port no., 0-511 */
96 struct Host *HostP; 42 struct Host *HostP;
97 volatile caddr_t Caddr; 43 caddr_t Caddr;
98 ushort HostPort; /* Port number on host card */ 44 unsigned short HostPort; /* Port number on host card */
99 uchar RupNum; /* Number of RUP for port */ 45 unsigned char RupNum; /* Number of RUP for port */
100 uchar ID2; /* Second ID of RTA for port */ 46 unsigned char ID2; /* Second ID of RTA for port */
101 ulong State; /* FLAGS for open & xopen */ 47 unsigned long State; /* FLAGS for open & xopen */
102#define RIO_LOPEN 0x00001 /* Local open */ 48#define RIO_LOPEN 0x00001 /* Local open */
103#define RIO_MOPEN 0x00002 /* Modem open */ 49#define RIO_MOPEN 0x00002 /* Modem open */
104#define RIO_WOPEN 0x00004 /* Waiting for open */ 50#define RIO_WOPEN 0x00004 /* Waiting for open */
105#define RIO_CLOSING 0x00008 /* The port is being close */ 51#define RIO_CLOSING 0x00008 /* The port is being close */
106#define RIO_XPBUSY 0x00010 /* Transparent printer busy */ 52#define RIO_XPBUSY 0x00010 /* Transparent printer busy */
107#define RIO_BREAKING 0x00020 /* Break in progress */ 53#define RIO_BREAKING 0x00020 /* Break in progress */
108#define RIO_DIRECT 0x00040 /* Doing Direct output */ 54#define RIO_DIRECT 0x00040 /* Doing Direct output */
109#define RIO_EXCLUSIVE 0x00080 /* Stream open for exclusive use */ 55#define RIO_EXCLUSIVE 0x00080 /* Stream open for exclusive use */
110#define RIO_NDELAY 0x00100 /* Stream is open FNDELAY */ 56#define RIO_NDELAY 0x00100 /* Stream is open FNDELAY */
111#define RIO_CARR_ON 0x00200 /* Stream has carrier present */ 57#define RIO_CARR_ON 0x00200 /* Stream has carrier present */
112#define RIO_XPWANTR 0x00400 /* Stream wanted by Xprint */ 58#define RIO_XPWANTR 0x00400 /* Stream wanted by Xprint */
113#define RIO_RBLK 0x00800 /* Stream is read-blocked */ 59#define RIO_RBLK 0x00800 /* Stream is read-blocked */
114#define RIO_BUSY 0x01000 /* Stream is BUSY for write */ 60#define RIO_BUSY 0x01000 /* Stream is BUSY for write */
115#define RIO_TIMEOUT 0x02000 /* Stream timeout in progress */ 61#define RIO_TIMEOUT 0x02000 /* Stream timeout in progress */
116#define RIO_TXSTOP 0x04000 /* Stream output is stopped */ 62#define RIO_TXSTOP 0x04000 /* Stream output is stopped */
117#define RIO_WAITFLUSH 0x08000 /* Stream waiting for flush */ 63#define RIO_WAITFLUSH 0x08000 /* Stream waiting for flush */
118#define RIO_DYNOROD 0x10000 /* Drain failed */ 64#define RIO_DYNOROD 0x10000 /* Drain failed */
119#define RIO_DELETED 0x20000 /* RTA has been deleted */ 65#define RIO_DELETED 0x20000 /* RTA has been deleted */
120#define RIO_ISSCANCODE 0x40000 /* This line is in scancode mode */ 66#define RIO_ISSCANCODE 0x40000 /* This line is in scancode mode */
121#define RIO_USING_EUC 0x100000 /* Using extended Unix chars */ 67#define RIO_USING_EUC 0x100000 /* Using extended Unix chars */
122#define RIO_CAN_COOK 0x200000 /* This line can do cooking */ 68#define RIO_CAN_COOK 0x200000 /* This line can do cooking */
123#define RIO_TRIAD_MODE 0x400000 /* Enable TRIAD special ops. */ 69#define RIO_TRIAD_MODE 0x400000 /* Enable TRIAD special ops. */
@@ -125,15 +71,15 @@ struct Port {
125#define RIO_TRIAD_FUNC 0x1000000 /* Seen a function key coming in */ 71#define RIO_TRIAD_FUNC 0x1000000 /* Seen a function key coming in */
126#define RIO_THROTTLE_RX 0x2000000 /* RX needs to be throttled. */ 72#define RIO_THROTTLE_RX 0x2000000 /* RX needs to be throttled. */
127 73
128 ulong Config; /* FLAGS for NOREAD.... */ 74 unsigned long Config; /* FLAGS for NOREAD.... */
129#define RIO_NOREAD 0x0001 /* Are not allowed to read port */ 75#define RIO_NOREAD 0x0001 /* Are not allowed to read port */
130#define RIO_NOWRITE 0x0002 /* Are not allowed to write port */ 76#define RIO_NOWRITE 0x0002 /* Are not allowed to write port */
131#define RIO_NOXPRINT 0x0004 /* Are not allowed to xprint port */ 77#define RIO_NOXPRINT 0x0004 /* Are not allowed to xprint port */
132#define RIO_NOMASK 0x0007 /* All not allowed things */ 78#define RIO_NOMASK 0x0007 /* All not allowed things */
133#define RIO_IXANY 0x0008 /* Port is allowed ixany */ 79#define RIO_IXANY 0x0008 /* Port is allowed ixany */
134#define RIO_MODEM 0x0010 /* Stream is a modem device */ 80#define RIO_MODEM 0x0010 /* Stream is a modem device */
135#define RIO_IXON 0x0020 /* Port is allowed ixon */ 81#define RIO_IXON 0x0020 /* Port is allowed ixon */
136#define RIO_WAITDRAIN 0x0040 /* Wait for port to completely drain */ 82#define RIO_WAITDRAIN 0x0040 /* Wait for port to completely drain */
137#define RIO_MAP_50_TO_50 0x0080 /* Map 50 baud to 50 baud */ 83#define RIO_MAP_50_TO_50 0x0080 /* Map 50 baud to 50 baud */
138#define RIO_MAP_110_TO_110 0x0100 /* Map 110 baud to 110 baud */ 84#define RIO_MAP_110_TO_110 0x0100 /* Map 110 baud to 110 baud */
139 85
@@ -142,36 +88,36 @@ struct Port {
142** As LynxOS does not appear to support Hardware Flow Control ..... 88** As LynxOS does not appear to support Hardware Flow Control .....
143** Define our own flow control flags in 'Config'. 89** Define our own flow control flags in 'Config'.
144*/ 90*/
145#define RIO_CTSFLOW 0x0200 /* RIO's own CTSFLOW flag */ 91#define RIO_CTSFLOW 0x0200 /* RIO's own CTSFLOW flag */
146#define RIO_RTSFLOW 0x0400 /* RIO's own RTSFLOW flag */ 92#define RIO_RTSFLOW 0x0400 /* RIO's own RTSFLOW flag */
147 93
148 94
149 struct PHB *PhbP; /* pointer to PHB for port */ 95 struct PHB *PhbP; /* pointer to PHB for port */
150 WORD *TxAdd; /* Add packets here */ 96 u16 *TxAdd; /* Add packets here */
151 WORD *TxStart; /* Start of add array */ 97 u16 *TxStart; /* Start of add array */
152 WORD *TxEnd; /* End of add array */ 98 u16 *TxEnd; /* End of add array */
153 WORD *RxRemove; /* Remove packets here */ 99 u16 *RxRemove; /* Remove packets here */
154 WORD *RxStart; /* Start of remove array */ 100 u16 *RxStart; /* Start of remove array */
155 WORD *RxEnd; /* End of remove array */ 101 u16 *RxEnd; /* End of remove array */
156 uint RtaUniqueNum; /* Unique number of RTA */ 102 unsigned int RtaUniqueNum; /* Unique number of RTA */
157 ushort PortState; /* status of port */ 103 unsigned short PortState; /* status of port */
158 ushort ModemState; /* status of modem lines */ 104 unsigned short ModemState; /* status of modem lines */
159 ulong ModemLines; /* Modem bits sent to RTA */ 105 unsigned long ModemLines; /* Modem bits sent to RTA */
160 uchar CookMode; /* who expands CR/LF? */ 106 unsigned char CookMode; /* who expands CR/LF? */
161 uchar ParamSem; /* Prevent write during param */ 107 unsigned char ParamSem; /* Prevent write during param */
162 uchar Mapped; /* if port mapped onto host */ 108 unsigned char Mapped; /* if port mapped onto host */
163 uchar SecondBlock; /* if port belongs to 2nd block 109 unsigned char SecondBlock; /* if port belongs to 2nd block
164 of 16 port RTA */ 110 of 16 port RTA */
165 uchar InUse; /* how many pre-emptive cmds */ 111 unsigned char InUse; /* how many pre-emptive cmds */
166 uchar Lock; /* if params locked */ 112 unsigned char Lock; /* if params locked */
167 uchar Store; /* if params stored across closes */ 113 unsigned char Store; /* if params stored across closes */
168 uchar FirstOpen; /* TRUE if first time port opened */ 114 unsigned char FirstOpen; /* TRUE if first time port opened */
169 uchar FlushCmdBodge; /* if doing a (non)flush */ 115 unsigned char FlushCmdBodge; /* if doing a (non)flush */
170 uchar MagicFlags; /* require intr processing */ 116 unsigned char MagicFlags; /* require intr processing */
171#define MAGIC_FLUSH 0x01 /* mirror of WflushFlag */ 117#define MAGIC_FLUSH 0x01 /* mirror of WflushFlag */
172#define MAGIC_REBOOT 0x02 /* RTA re-booted, re-open ports */ 118#define MAGIC_REBOOT 0x02 /* RTA re-booted, re-open ports */
173#define MORE_OUTPUT_EYGOR 0x04 /* riotproc failed to empty clists */ 119#define MORE_OUTPUT_EYGOR 0x04 /* riotproc failed to empty clists */
174 uchar WflushFlag; /* 1 How many WFLUSHs active */ 120 unsigned char WflushFlag; /* 1 How many WFLUSHs active */
175/* 121/*
176** Transparent print stuff 122** Transparent print stuff
177*/ 123*/
@@ -179,63 +125,55 @@ struct Port {
179#ifndef MAX_XP_CTRL_LEN 125#ifndef MAX_XP_CTRL_LEN
180#define MAX_XP_CTRL_LEN 16 /* ALSO IN DAEMON.H */ 126#define MAX_XP_CTRL_LEN 16 /* ALSO IN DAEMON.H */
181#endif 127#endif
182 uint XpCps; 128 unsigned int XpCps;
183 char XpOn[MAX_XP_CTRL_LEN]; 129 char XpOn[MAX_XP_CTRL_LEN];
184 char XpOff[MAX_XP_CTRL_LEN]; 130 char XpOff[MAX_XP_CTRL_LEN];
185 ushort XpLen; /* strlen(XpOn)+strlen(XpOff) */ 131 unsigned short XpLen; /* strlen(XpOn)+strlen(XpOff) */
186 uchar XpActive; 132 unsigned char XpActive;
187 uchar XpLastTickOk; /* TRUE if we can process */ 133 unsigned char XpLastTickOk; /* TRUE if we can process */
188#define XP_OPEN 00001 134#define XP_OPEN 00001
189#define XP_RUNABLE 00002 135#define XP_RUNABLE 00002
190 struct ttystatics *XttyP; 136 struct ttystatics *XttyP;
191 } Xprint; 137 } Xprint;
192#ifdef VPIX 138 unsigned char RxDataStart;
193 v86_t *StashP; 139 unsigned char Cor2Copy; /* copy of COR2 */
194 uint IntMask; 140 char *Name; /* points to the Rta's name */
195 struct termss VpixSs;
196 uchar ModemStatusReg; /* Modem status register */
197#endif
198 uchar RxDataStart;
199 uchar Cor2Copy; /* copy of COR2 */
200 char *Name; /* points to the Rta's name */
201#ifdef STATS
202 struct RIOStats Stat; /* ports statistics */
203#endif
204 char *TxRingBuffer; 141 char *TxRingBuffer;
205 ushort TxBufferIn; /* New data arrives here */ 142 unsigned short TxBufferIn; /* New data arrives here */
206 ushort TxBufferOut; /* Intr removes data here */ 143 unsigned short TxBufferOut; /* Intr removes data here */
207 ushort OldTxBufferOut; /* Indicates if draining */ 144 unsigned short OldTxBufferOut; /* Indicates if draining */
208 int TimeoutId; /* Timeout ID */ 145 int TimeoutId; /* Timeout ID */
209 uint Debug; 146 unsigned int Debug;
210 uchar WaitUntilBooted; /* True if open should block */ 147 unsigned char WaitUntilBooted; /* True if open should block */
211 uint statsGather; /* True if gathering stats */ 148 unsigned int statsGather; /* True if gathering stats */
212 ulong txchars; /* Chars transmitted */ 149 unsigned long txchars; /* Chars transmitted */
213 ulong rxchars; /* Chars received */ 150 unsigned long rxchars; /* Chars received */
214 ulong opens; /* port open count */ 151 unsigned long opens; /* port open count */
215 ulong closes; /* port close count */ 152 unsigned long closes; /* port close count */
216 ulong ioctls; /* ioctl count */ 153 unsigned long ioctls; /* ioctl count */
217 uchar LastRxTgl; /* Last state of rx toggle bit */ 154 unsigned char LastRxTgl; /* Last state of rx toggle bit */
218 spinlock_t portSem; /* Lock using this sem */ 155 spinlock_t portSem; /* Lock using this sem */
219 int MonitorTstate; /* Monitoring ? */ 156 int MonitorTstate; /* Monitoring ? */
220 int timeout_id; /* For calling 100 ms delays */ 157 int timeout_id; /* For calling 100 ms delays */
221 int timeout_sem; /* For calling 100 ms delays */ 158 int timeout_sem; /* For calling 100 ms delays */
222 int firstOpen; /* First time open ? */ 159 int firstOpen; /* First time open ? */
223 char *p; /* save the global struc here .. */ 160 char *p; /* save the global struc here .. */
224}; 161};
225 162
226struct ModuleInfo { 163struct ModuleInfo {
227 char *Name; 164 char *Name;
228 uint Flags[4]; /* one per port on a module */ 165 unsigned int Flags[4]; /* one per port on a module */
229}; 166};
230#endif
231 167
232/* 168/*
233** This struct is required because trying to grab an entire Port structure 169** This struct is required because trying to grab an entire Port structure
234** runs into problems with differing struct sizes between driver and config. 170** runs into problems with differing struct sizes between driver and config.
235*/ 171*/
236struct PortParams { 172struct PortParams {
237 uint Port; 173 unsigned int Port;
238 ulong Config; 174 unsigned long Config;
239 ulong State; 175 unsigned long State;
240 struct ttystatics *TtyP; 176 struct ttystatics *TtyP;
241}; 177};
178
179#endif
diff --git a/drivers/char/rio/qbuf.h b/drivers/char/rio/qbuf.h
deleted file mode 100644
index 391ffc3355..0000000000
--- a/drivers/char/rio/qbuf.h
+++ /dev/null
@@ -1,62 +0,0 @@
1
2/****************************************************************************
3 ******* *******
4 ******* Q U E U E B U F F E R S T R U C T U R E S
5 ******* *******
6 ****************************************************************************
7
8 Author : Ian Nandhra / Jeremy Rolls
9 Date :
10
11 *
12 * (C) 1990 - 2000 Specialix International Ltd., Byfleet, Surrey, UK.
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; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27
28 Version : 0.01
29
30
31 Mods
32 ----------------------------------------------------------------------------
33 Date By Description
34 ----------------------------------------------------------------------------
35
36 ***************************************************************************/
37
38#ifndef _qbuf_h
39#define _qbuf_h 1
40
41#ifndef lint
42#ifdef SCCS_LABELS
43static char *_rio_qbuf_h_sccs = "@(#)qbuf.h 1.1";
44#endif
45#endif
46
47
48
49#define PKTS_PER_BUFFER (220 / PKT_LENGTH)
50
51typedef struct Q_BUF Q_BUF;
52struct Q_BUF {
53 Q_BUF_ptr next;
54 Q_BUF_ptr prev;
55 PKT_ptr buf[PKTS_PER_BUFFER];
56};
57
58
59#endif
60
61
62/*********** end of file ***********/
diff --git a/drivers/char/rio/rio.h b/drivers/char/rio/rio.h
index 7f45e1ab53..b4c91871ba 100644
--- a/drivers/char/rio/rio.h
+++ b/drivers/char/rio/rio.h
@@ -33,38 +33,6 @@
33#ifndef __rio_rio_h__ 33#ifndef __rio_rio_h__
34#define __rio_rio_h__ 34#define __rio_rio_h__
35 35
36#ifdef SCCS_LABELS
37static char *_rio_h_sccs_ = "@(#)rio.h 1.3";
38#endif
39
40/*
41** 30.09.1998 ARG -
42** Introduced driver version and host card type strings
43*/
44#define RIO_DRV_STR "Specialix RIO Driver"
45#define RIO_AT_HOST_STR "ISA"
46#define RIO_PCI_HOST_STR "PCI"
47
48
49/*
50** rio_info_store() commands (arbitary values) :
51*/
52#define RIO_INFO_PUT 0xA4B3C2D1
53#define RIO_INFO_GET 0xF1E2D3C4
54
55
56/*
57** anything that I couldn't cram in somewhere else
58*/
59/*
60#ifndef RIODEBUG
61#define debug
62#else
63#define debug rioprint
64#endif
65*/
66
67
68/* 36/*
69** Maximum numbers of things 37** Maximum numbers of things
70*/ 38*/
@@ -101,9 +69,8 @@ static char *_rio_h_sccs_ = "@(#)rio.h 1.3";
101/* 69/*
102** Flag values returned by functions 70** Flag values returned by functions
103*/ 71*/
72
104#define RIO_FAIL -1 73#define RIO_FAIL -1
105#define RIO_SUCCESS 0
106#define COPYFAIL -1 /* copy[in|out] failed */
107 74
108/* 75/*
109** SysPort value for something that hasn't any ports 76** SysPort value for something that hasn't any ports
@@ -142,30 +109,8 @@ static char *_rio_h_sccs_ = "@(#)rio.h 1.3";
142/* 109/*
143** Generally useful constants 110** Generally useful constants
144*/ 111*/
145#define HALF_A_SECOND ((HZ)>>1) 112
146#define A_SECOND (HZ) 113#define HUNDRED_MS ((HZ/10)?(HZ/10):1)
147#define HUNDRED_HZ ((HZ/100)?(HZ/100):1)
148#define FIFTY_HZ ((HZ/50)?(HZ/50):1)
149#define TWENTY_HZ ((HZ/20)?(HZ/20):1)
150#define TEN_HZ ((HZ/10)?(HZ/10):1)
151#define FIVE_HZ ((HZ/5)?(HZ/5):1)
152#define HUNDRED_MS TEN_HZ
153#define FIFTY_MS TWENTY_HZ
154#define TWENTY_MS FIFTY_HZ
155#define TEN_MS HUNDRED_HZ
156#define TWO_SECONDS ((A_SECOND)*2)
157#define FIVE_SECONDS ((A_SECOND)*5)
158#define TEN_SECONDS ((A_SECOND)*10)
159#define FIFTEEN_SECONDS ((A_SECOND)*15)
160#define TWENTY_SECONDS ((A_SECOND)*20)
161#define HALF_A_MINUTE (A_MINUTE>>1)
162#define A_MINUTE (A_SECOND*60)
163#define FIVE_MINUTES (A_MINUTE*5)
164#define QUARTER_HOUR (A_MINUTE*15)
165#define HALF_HOUR (A_MINUTE*30)
166#define HOUR (A_MINUTE*60)
167
168#define SIXTEEN_MEG 0x1000000
169#define ONE_MEG 0x100000 114#define ONE_MEG 0x100000
170#define SIXTY_FOUR_K 0x10000 115#define SIXTY_FOUR_K 0x10000
171 116
@@ -173,8 +118,6 @@ static char *_rio_h_sccs_ = "@(#)rio.h 1.3";
173#define RIO_EISA_MEM_SIZE SIXTY_FOUR_K 118#define RIO_EISA_MEM_SIZE SIXTY_FOUR_K
174#define RIO_MCA_MEM_SIZE SIXTY_FOUR_K 119#define RIO_MCA_MEM_SIZE SIXTY_FOUR_K
175 120
176#define POLL_VECTOR 0x100
177
178#define COOK_WELL 0 121#define COOK_WELL 0
179#define COOK_MEDIUM 1 122#define COOK_MEDIUM 1
180#define COOK_RAW 2 123#define COOK_RAW 2
@@ -186,69 +129,26 @@ static char *_rio_h_sccs_ = "@(#)rio.h 1.3";
186** RIO_OBJ takes hostp->Caddr and a UNIX pointer to an object and 129** RIO_OBJ takes hostp->Caddr and a UNIX pointer to an object and
187** returns the offset into the DP RAM area. 130** returns the offset into the DP RAM area.
188*/ 131*/
189#define RIO_PTR(C,O) (((caddr_t)(C))+(0xFFFF&(O))) 132#define RIO_PTR(C,O) (((unsigned char *)(C))+(0xFFFF&(O)))
190#define RIO_OFF(C,O) ((int)(O)-(int)(C)) 133#define RIO_OFF(C,O) ((long)(O)-(long)(C))
191 134
192/* 135/*
193** How to convert from various different device number formats: 136** How to convert from various different device number formats:
194** DEV is a dev number, as passed to open, close etc - NOT a minor 137** DEV is a dev number, as passed to open, close etc - NOT a minor
195** number! 138** number!
196** 139**/
197** Note: LynxOS only gives us 8 bits for the device minor number, 140
198** so all this crap here to deal with 'modem' bits etc. is
199** just a load of irrelevant old bunkum!
200** This however does not stop us needing to define a value
201** for RIO_MODEMOFFSET which is required by the 'riomkdev'
202** utility in the New Config Utilities suite.
203*/
204/* 0-511: direct 512-1023: modem */
205#define RIO_MODEMOFFSET 0x200 /* doesn't mean anything */
206#define RIO_MODEM_MASK 0x1FF 141#define RIO_MODEM_MASK 0x1FF
207#define RIO_MODEM_BIT 0x200 142#define RIO_MODEM_BIT 0x200
208#define RIO_UNMODEM(DEV) (MINOR(DEV) & RIO_MODEM_MASK) 143#define RIO_UNMODEM(DEV) (MINOR(DEV) & RIO_MODEM_MASK)
209#define RIO_ISMODEM(DEV) (MINOR(DEV) & RIO_MODEM_BIT) 144#define RIO_ISMODEM(DEV) (MINOR(DEV) & RIO_MODEM_BIT)
210#define RIO_PORT(DEV,FIRST_MAJ) ( (MAJOR(DEV) - FIRST_MAJ) * PORTS_PER_HOST) \ 145#define RIO_PORT(DEV,FIRST_MAJ) ( (MAJOR(DEV) - FIRST_MAJ) * PORTS_PER_HOST) \
211 + MINOR(DEV) 146 + MINOR(DEV)
212 147#define CSUM(pkt_ptr) (((u16 *)(pkt_ptr))[0] + ((u16 *)(pkt_ptr))[1] + \
213#define splrio spltty 148 ((u16 *)(pkt_ptr))[2] + ((u16 *)(pkt_ptr))[3] + \
214 149 ((u16 *)(pkt_ptr))[4] + ((u16 *)(pkt_ptr))[5] + \
215#define RIO_IPL 5 150 ((u16 *)(pkt_ptr))[6] + ((u16 *)(pkt_ptr))[7] + \
216#define RIO_PRI (PZERO+10) 151 ((u16 *)(pkt_ptr))[8] + ((u16 *)(pkt_ptr))[9] )
217#define RIO_CLOSE_PRI PZERO-1 /* uninterruptible sleeps for close */
218
219typedef struct DbInf {
220 uint Flag;
221 char Name[8];
222} DbInf;
223
224#ifndef TRUE
225#define TRUE (1==1)
226#endif
227#ifndef FALSE
228#define FALSE (!TRUE)
229#endif
230
231#define CSUM(pkt_ptr) (((ushort *)(pkt_ptr))[0] + ((ushort *)(pkt_ptr))[1] + \
232 ((ushort *)(pkt_ptr))[2] + ((ushort *)(pkt_ptr))[3] + \
233 ((ushort *)(pkt_ptr))[4] + ((ushort *)(pkt_ptr))[5] + \
234 ((ushort *)(pkt_ptr))[6] + ((ushort *)(pkt_ptr))[7] + \
235 ((ushort *)(pkt_ptr))[8] + ((ushort *)(pkt_ptr))[9] )
236
237/*
238** This happy little macro copies SIZE bytes of data from FROM to TO
239** quite well. SIZE must be a constant.
240*/
241#define CCOPY( FROM, TO, SIZE ) { *(struct s { char data[SIZE]; } *)(TO) = *(struct s *)(FROM); }
242
243/*
244** increment a buffer pointer modulo the size of the buffer...
245*/
246#define BUMP( P, I ) ((P) = (((P)+(I)) & RIOBufferMask))
247
248#define INIT_PACKET( PK, PP ) \
249{ \
250 *((uint *)PK) = PP->PacketInfo; \
251}
252 152
253#define RIO_LINK_ENABLE 0x80FF /* FF is a hack, mainly for Mips, to */ 153#define RIO_LINK_ENABLE 0x80FF /* FF is a hack, mainly for Mips, to */
254 /* prevent a really stupid race condition. */ 154 /* prevent a really stupid race condition. */
@@ -267,27 +167,42 @@ typedef struct DbInf {
267#define DISCONNECT 0 167#define DISCONNECT 0
268#define CONNECT 1 168#define CONNECT 1
269 169
170/* ------ Control Codes ------ */
270 171
271/* 172#define CONTROL '^'
272** Machine types - these must NOT overlap with product codes 0-15 173#define IFOAD ( CONTROL + 1 )
273*/ 174#define IDENTIFY ( CONTROL + 2 )
274#define RIO_MIPS_R3230 31 175#define ZOMBIE ( CONTROL + 3 )
275#define RIO_MIPS_R4030 32 176#define UFOAD ( CONTROL + 4 )
177#define IWAIT ( CONTROL + 5 )
178
179#define IFOAD_MAGIC 0xF0AD /* of course */
180#define ZOMBIE_MAGIC (~0xDEAD) /* not dead -> zombie */
181#define UFOAD_MAGIC 0xD1E /* kill-your-neighbour */
182#define IWAIT_MAGIC 0xB1DE /* Bide your time */
183
184/* ------ Error Codes ------ */
185
186#define E_NO_ERROR ((ushort) 0)
187
188/* ------ Free Lists ------ */
276 189
277#define RIO_IO_UNKNOWN -2 190struct rio_free_list {
191 u16 next;
192 u16 prev;
193};
278 194
279#undef MODERN 195/* NULL for card side linked lists */
280#define ERROR( E ) do { u.u_error = E; return OPENFAIL } while ( 0 ) 196#define TPNULL ((ushort)(0x8000))
197/* We can add another packet to a transmit queue if the packet pointer pointed
198 * to by the TxAdd pointer has PKT_IN_USE clear in its address. */
199#define PKT_IN_USE 0x1
281 200
282/* Defines for MPX line discipline routines */ 201/* ------ Topology ------ */
283 202
284#define DIST_LINESW_OPEN 0x01 203struct Top {
285#define DIST_LINESW_CLOSE 0x02 204 u8 Unit;
286#define DIST_LINESW_READ 0x04 205 u8 Link;
287#define DIST_LINESW_WRITE 0x08 206};
288#define DIST_LINESW_IOCTL 0x10
289#define DIST_LINESW_INPUT 0x20
290#define DIST_LINESW_OUTPUT 0x40
291#define DIST_LINESW_MDMINT 0x80
292 207
293#endif /* __rio_h__ */ 208#endif /* __rio_h__ */
diff --git a/drivers/char/rio/rio_linux.c b/drivers/char/rio/rio_linux.c
index c9af283a81..78dd856534 100644
--- a/drivers/char/rio/rio_linux.c
+++ b/drivers/char/rio/rio_linux.c
@@ -57,15 +57,12 @@
57#include <asm/uaccess.h> 57#include <asm/uaccess.h>
58 58
59#include "linux_compat.h" 59#include "linux_compat.h"
60#include "typdef.h"
61#include "pkt.h" 60#include "pkt.h"
62#include "daemon.h" 61#include "daemon.h"
63#include "rio.h" 62#include "rio.h"
64#include "riospace.h" 63#include "riospace.h"
65#include "top.h"
66#include "cmdpkt.h" 64#include "cmdpkt.h"
67#include "map.h" 65#include "map.h"
68#include "riotypes.h"
69#include "rup.h" 66#include "rup.h"
70#include "port.h" 67#include "port.h"
71#include "riodrvr.h" 68#include "riodrvr.h"
@@ -78,17 +75,13 @@
78#include "unixrup.h" 75#include "unixrup.h"
79#include "board.h" 76#include "board.h"
80#include "host.h" 77#include "host.h"
81#include "error.h"
82#include "phb.h" 78#include "phb.h"
83#include "link.h" 79#include "link.h"
84#include "cmdblk.h" 80#include "cmdblk.h"
85#include "route.h" 81#include "route.h"
86#include "control.h"
87#include "cirrus.h" 82#include "cirrus.h"
88#include "rioioctl.h" 83#include "rioioctl.h"
89#include "param.h" 84#include "param.h"
90#include "list.h"
91#include "sam.h"
92#include "protsts.h" 85#include "protsts.h"
93#include "rioboard.h" 86#include "rioboard.h"
94 87
@@ -297,7 +290,7 @@ static void my_hd(void *ad, int len)
297 unsigned char *addr = ad; 290 unsigned char *addr = ad;
298 291
299 for (i = 0; i < len; i += 16) { 292 for (i = 0; i < len; i += 16) {
300 rio_dprintk(RIO_DEBUG_PARAM, "%08x ", (int) addr + i); 293 rio_dprintk(RIO_DEBUG_PARAM, "%08lx ", (unsigned long) addr + i);
301 for (j = 0; j < 16; j++) { 294 for (j = 0; j < 16; j++) {
302 rio_dprintk(RIO_DEBUG_PARAM, "%02x %s", addr[j + i], (j == 7) ? " " : ""); 295 rio_dprintk(RIO_DEBUG_PARAM, "%02x %s", addr[j + i], (j == 7) ? " " : "");
303 } 296 }
@@ -340,34 +333,19 @@ int RIODelay_ni(struct Port *PortP, int njiffies)
340 return !RIO_FAIL; 333 return !RIO_FAIL;
341} 334}
342 335
343 336void rio_copy_to_card(void *to, void *from, int len)
344int rio_minor(struct tty_struct *tty)
345{ 337{
346 return tty->index + (tty->driver == rio_driver) ? 0 : 256; 338 rio_memcpy_toio(NULL, to, from, len);
347} 339}
348 340
349 341int rio_minor(struct tty_struct *tty)
350int rio_ismodem(struct tty_struct *tty)
351{ 342{
352 return 1; 343 return tty->index + (tty->driver == rio_driver) ? 0 : 256;
353} 344}
354 345
355
356static int rio_set_real_termios(void *ptr) 346static int rio_set_real_termios(void *ptr)
357{ 347{
358 int rv, modem; 348 return RIOParam((struct Port *) ptr, CONFIG, 1, 1);
359 struct tty_struct *tty;
360 func_enter();
361
362 tty = ((struct Port *) ptr)->gs.tty;
363
364 modem = rio_ismodem(tty);
365
366 rv = RIOParam((struct Port *) ptr, CONFIG, modem, 1);
367
368 func_exit();
369
370 return rv;
371} 349}
372 350
373 351
@@ -379,7 +357,7 @@ static void rio_reset_interrupt(struct Host *HostP)
379 case RIO_AT: 357 case RIO_AT:
380 case RIO_MCA: 358 case RIO_MCA:
381 case RIO_PCI: 359 case RIO_PCI:
382 WBYTE(HostP->ResetInt, 0xff); 360 writeb(0xFF, &HostP->ResetInt);
383 } 361 }
384 362
385 func_exit(); 363 func_exit();
@@ -397,9 +375,6 @@ static irqreturn_t rio_interrupt(int irq, void *ptr, struct pt_regs *regs)
397 /* AAargh! The order in which to do these things is essential and 375 /* AAargh! The order in which to do these things is essential and
398 not trivial. 376 not trivial.
399 377
400 - Rate limit goes before "recursive". Otherwise a series of
401 recursive calls will hang the machine in the interrupt routine.
402
403 - hardware twiddling goes before "recursive". Otherwise when we 378 - hardware twiddling goes before "recursive". Otherwise when we
404 poll the card, and a recursive interrupt happens, we won't 379 poll the card, and a recursive interrupt happens, we won't
405 ack the card, so it might keep on interrupting us. (especially 380 ack the card, so it might keep on interrupting us. (especially
@@ -414,26 +389,6 @@ static irqreturn_t rio_interrupt(int irq, void *ptr, struct pt_regs *regs)
414 - The initialized test goes before recursive. 389 - The initialized test goes before recursive.
415 */ 390 */
416 391
417
418
419#ifdef IRQ_RATE_LIMIT
420 /* Aaargh! I'm ashamed. This costs more lines-of-code than the
421 actual interrupt routine!. (Well, used to when I wrote that comment) */
422 {
423 static int lastjif;
424 static int nintr = 0;
425
426 if (lastjif == jiffies) {
427 if (++nintr > IRQ_RATE_LIMIT) {
428 free_irq(HostP->Ivec, ptr);
429 printk(KERN_ERR "rio: Too many interrupts. Turning off interrupt %d.\n", HostP->Ivec);
430 }
431 } else {
432 lastjif = jiffies;
433 nintr = 0;
434 }
435 }
436#endif
437 rio_dprintk(RIO_DEBUG_IFLOW, "rio: We've have noticed the interrupt\n"); 392 rio_dprintk(RIO_DEBUG_IFLOW, "rio: We've have noticed the interrupt\n");
438 if (HostP->Ivec == irq) { 393 if (HostP->Ivec == irq) {
439 /* Tell the card we've noticed the interrupt. */ 394 /* Tell the card we've noticed the interrupt. */
@@ -444,13 +399,13 @@ static irqreturn_t rio_interrupt(int irq, void *ptr, struct pt_regs *regs)
444 return IRQ_HANDLED; 399 return IRQ_HANDLED;
445 400
446 if (test_and_set_bit(RIO_BOARD_INTR_LOCK, &HostP->locks)) { 401 if (test_and_set_bit(RIO_BOARD_INTR_LOCK, &HostP->locks)) {
447 printk(KERN_ERR "Recursive interrupt! (host %d/irq%d)\n", (int) ptr, HostP->Ivec); 402 printk(KERN_ERR "Recursive interrupt! (host %p/irq%d)\n", ptr, HostP->Ivec);
448 return IRQ_HANDLED; 403 return IRQ_HANDLED;
449 } 404 }
450 405
451 RIOServiceHost(p, HostP, irq); 406 RIOServiceHost(p, HostP, irq);
452 407
453 rio_dprintk(RIO_DEBUG_IFLOW, "riointr() doing host %d type %d\n", (int) ptr, HostP->Type); 408 rio_dprintk(RIO_DEBUG_IFLOW, "riointr() doing host %p type %d\n", ptr, HostP->Type);
454 409
455 clear_bit(RIO_BOARD_INTR_LOCK, &HostP->locks); 410 clear_bit(RIO_BOARD_INTR_LOCK, &HostP->locks);
456 rio_dprintk(RIO_DEBUG_IFLOW, "rio: exit rio_interrupt (%d/%d)\n", irq, HostP->Ivec); 411 rio_dprintk(RIO_DEBUG_IFLOW, "rio: exit rio_interrupt (%d/%d)\n", irq, HostP->Ivec);
@@ -873,7 +828,7 @@ static int rio_init_datastructures(void)
873#define HOST_SZ sizeof(struct Host) 828#define HOST_SZ sizeof(struct Host)
874#define PORT_SZ sizeof(struct Port *) 829#define PORT_SZ sizeof(struct Port *)
875#define TMIO_SZ sizeof(struct termios *) 830#define TMIO_SZ sizeof(struct termios *)
876 rio_dprintk(RIO_DEBUG_INIT, "getting : %d %d %d %d %d bytes\n", RI_SZ, RIO_HOSTS * HOST_SZ, RIO_PORTS * PORT_SZ, RIO_PORTS * TMIO_SZ, RIO_PORTS * TMIO_SZ); 831 rio_dprintk(RIO_DEBUG_INIT, "getting : %Zd %Zd %Zd %Zd %Zd bytes\n", RI_SZ, RIO_HOSTS * HOST_SZ, RIO_PORTS * PORT_SZ, RIO_PORTS * TMIO_SZ, RIO_PORTS * TMIO_SZ);
877 832
878 if (!(p = ckmalloc(RI_SZ))) 833 if (!(p = ckmalloc(RI_SZ)))
879 goto free0; 834 goto free0;
@@ -963,22 +918,21 @@ static void __exit rio_release_drivers(void)
963 918
964static void fix_rio_pci(struct pci_dev *pdev) 919static void fix_rio_pci(struct pci_dev *pdev)
965{ 920{
966 unsigned int hwbase; 921 unsigned long hwbase;
967 unsigned long rebase; 922 unsigned char *rebase;
968 unsigned int t; 923 unsigned int t;
969 924
970#define CNTRL_REG_OFFSET 0x50 925#define CNTRL_REG_OFFSET 0x50
971#define CNTRL_REG_GOODVALUE 0x18260000 926#define CNTRL_REG_GOODVALUE 0x18260000
972 927
973 pci_read_config_dword(pdev, PCI_BASE_ADDRESS_0, &hwbase); 928 hwbase = pci_resource_start(pdev, 0);
974 hwbase &= PCI_BASE_ADDRESS_MEM_MASK; 929 rebase = ioremap(hwbase, 0x80);
975 rebase = (ulong) ioremap(hwbase, 0x80);
976 t = readl(rebase + CNTRL_REG_OFFSET); 930 t = readl(rebase + CNTRL_REG_OFFSET);
977 if (t != CNTRL_REG_GOODVALUE) { 931 if (t != CNTRL_REG_GOODVALUE) {
978 printk(KERN_DEBUG "rio: performing cntrl reg fix: %08x -> %08x\n", t, CNTRL_REG_GOODVALUE); 932 printk(KERN_DEBUG "rio: performing cntrl reg fix: %08x -> %08x\n", t, CNTRL_REG_GOODVALUE);
979 writel(CNTRL_REG_GOODVALUE, rebase + CNTRL_REG_OFFSET); 933 writel(CNTRL_REG_GOODVALUE, rebase + CNTRL_REG_OFFSET);
980 } 934 }
981 iounmap((char *) rebase); 935 iounmap(rebase);
982} 936}
983#endif 937#endif
984 938
@@ -994,7 +948,6 @@ static int __init rio_init(void)
994 948
995#ifdef CONFIG_PCI 949#ifdef CONFIG_PCI
996 struct pci_dev *pdev = NULL; 950 struct pci_dev *pdev = NULL;
997 unsigned int tint;
998 unsigned short tshort; 951 unsigned short tshort;
999#endif 952#endif
1000 953
@@ -1019,6 +972,8 @@ static int __init rio_init(void)
1019#ifdef CONFIG_PCI 972#ifdef CONFIG_PCI
1020 /* First look for the JET devices: */ 973 /* First look for the JET devices: */
1021 while ((pdev = pci_get_device(PCI_VENDOR_ID_SPECIALIX, PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8, pdev))) { 974 while ((pdev = pci_get_device(PCI_VENDOR_ID_SPECIALIX, PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8, pdev))) {
975 u32 tint;
976
1022 if (pci_enable_device(pdev)) 977 if (pci_enable_device(pdev))
1023 continue; 978 continue;
1024 979
@@ -1029,7 +984,6 @@ static int __init rio_init(void)
1029 Also, reading a non-aligned dword doesn't work. So we read the 984 Also, reading a non-aligned dword doesn't work. So we read the
1030 whole dword at 0x2c and extract the word at 0x2e (SUBSYSTEM_ID) 985 whole dword at 0x2c and extract the word at 0x2e (SUBSYSTEM_ID)
1031 ourselves */ 986 ourselves */
1032 /* I don't know why the define doesn't work, constant 0x2c does --REW */
1033 pci_read_config_dword(pdev, 0x2c, &tint); 987 pci_read_config_dword(pdev, 0x2c, &tint);
1034 tshort = (tint >> 16) & 0xffff; 988 tshort = (tint >> 16) & 0xffff;
1035 rio_dprintk(RIO_DEBUG_PROBE, "Got a specialix card: %x.\n", tint); 989 rio_dprintk(RIO_DEBUG_PROBE, "Got a specialix card: %x.\n", tint);
@@ -1039,33 +993,31 @@ static int __init rio_init(void)
1039 } 993 }
1040 rio_dprintk(RIO_DEBUG_PROBE, "cp1\n"); 994 rio_dprintk(RIO_DEBUG_PROBE, "cp1\n");
1041 995
1042 pci_read_config_dword(pdev, PCI_BASE_ADDRESS_2, &tint);
1043
1044 hp = &p->RIOHosts[p->RIONumHosts]; 996 hp = &p->RIOHosts[p->RIONumHosts];
1045 hp->PaddrP = tint & PCI_BASE_ADDRESS_MEM_MASK; 997 hp->PaddrP = pci_resource_start(pdev, 2);
1046 hp->Ivec = pdev->irq; 998 hp->Ivec = pdev->irq;
1047 if (((1 << hp->Ivec) & rio_irqmask) == 0) 999 if (((1 << hp->Ivec) & rio_irqmask) == 0)
1048 hp->Ivec = 0; 1000 hp->Ivec = 0;
1049 hp->Caddr = ioremap(p->RIOHosts[p->RIONumHosts].PaddrP, RIO_WINDOW_LEN); 1001 hp->Caddr = ioremap(p->RIOHosts[p->RIONumHosts].PaddrP, RIO_WINDOW_LEN);
1050 hp->CardP = (struct DpRam *) hp->Caddr; 1002 hp->CardP = (struct DpRam *) hp->Caddr;
1051 hp->Type = RIO_PCI; 1003 hp->Type = RIO_PCI;
1052 hp->Copy = rio_pcicopy; 1004 hp->Copy = rio_copy_to_card;
1053 hp->Mode = RIO_PCI_BOOT_FROM_RAM; 1005 hp->Mode = RIO_PCI_BOOT_FROM_RAM;
1054 spin_lock_init(&hp->HostLock); 1006 spin_lock_init(&hp->HostLock);
1055 rio_reset_interrupt(hp); 1007 rio_reset_interrupt(hp);
1056 rio_start_card_running(hp); 1008 rio_start_card_running(hp);
1057 1009
1058 rio_dprintk(RIO_DEBUG_PROBE, "Going to test it (%p/%p).\n", (void *) p->RIOHosts[p->RIONumHosts].PaddrP, p->RIOHosts[p->RIONumHosts].Caddr); 1010 rio_dprintk(RIO_DEBUG_PROBE, "Going to test it (%p/%p).\n", (void *) p->RIOHosts[p->RIONumHosts].PaddrP, p->RIOHosts[p->RIONumHosts].Caddr);
1059 if (RIOBoardTest(p->RIOHosts[p->RIONumHosts].PaddrP, p->RIOHosts[p->RIONumHosts].Caddr, RIO_PCI, 0) == RIO_SUCCESS) { 1011 if (RIOBoardTest(p->RIOHosts[p->RIONumHosts].PaddrP, p->RIOHosts[p->RIONumHosts].Caddr, RIO_PCI, 0) == 0) {
1060 rio_dprintk(RIO_DEBUG_INIT, "Done RIOBoardTest\n"); 1012 rio_dprintk(RIO_DEBUG_INIT, "Done RIOBoardTest\n");
1061 WBYTE(p->RIOHosts[p->RIONumHosts].ResetInt, 0xff); 1013 writeb(0xFF, &p->RIOHosts[p->RIONumHosts].ResetInt);
1062 p->RIOHosts[p->RIONumHosts].UniqueNum = 1014 p->RIOHosts[p->RIONumHosts].UniqueNum =
1063 ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[0]) & 0xFF) << 0) | 1015 ((readb(&p->RIOHosts[p->RIONumHosts].Unique[0]) & 0xFF) << 0) |
1064 ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[1]) & 0xFF) << 8) | ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[2]) & 0xFF) << 16) | ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[3]) & 0xFF) << 24); 1016 ((readb(&p->RIOHosts[p->RIONumHosts].Unique[1]) & 0xFF) << 8) | ((readb(&p->RIOHosts[p->RIONumHosts].Unique[2]) & 0xFF) << 16) | ((readb(&p->RIOHosts[p->RIONumHosts].Unique[3]) & 0xFF) << 24);
1065 rio_dprintk(RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n", p->RIOHosts[p->RIONumHosts].UniqueNum); 1017 rio_dprintk(RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n", p->RIOHosts[p->RIONumHosts].UniqueNum);
1066 1018
1067 fix_rio_pci(pdev); 1019 fix_rio_pci(pdev);
1068 p->RIOLastPCISearch = RIO_SUCCESS; 1020 p->RIOLastPCISearch = 0;
1069 p->RIONumHosts++; 1021 p->RIONumHosts++;
1070 found++; 1022 found++;
1071 } else { 1023 } else {
@@ -1088,10 +1040,8 @@ static int __init rio_init(void)
1088 continue; 1040 continue;
1089 1041
1090#ifdef CONFIG_RIO_OLDPCI 1042#ifdef CONFIG_RIO_OLDPCI
1091 pci_read_config_dword(pdev, PCI_BASE_ADDRESS_0, &tint);
1092
1093 hp = &p->RIOHosts[p->RIONumHosts]; 1043 hp = &p->RIOHosts[p->RIONumHosts];
1094 hp->PaddrP = tint & PCI_BASE_ADDRESS_MEM_MASK; 1044 hp->PaddrP = pci_resource_start(pdev, 0);
1095 hp->Ivec = pdev->irq; 1045 hp->Ivec = pdev->irq;
1096 if (((1 << hp->Ivec) & rio_irqmask) == 0) 1046 if (((1 << hp->Ivec) & rio_irqmask) == 0)
1097 hp->Ivec = 0; 1047 hp->Ivec = 0;
@@ -1099,7 +1049,7 @@ static int __init rio_init(void)
1099 hp->Caddr = ioremap(p->RIOHosts[p->RIONumHosts].PaddrP, RIO_WINDOW_LEN); 1049 hp->Caddr = ioremap(p->RIOHosts[p->RIONumHosts].PaddrP, RIO_WINDOW_LEN);
1100 hp->CardP = (struct DpRam *) hp->Caddr; 1050 hp->CardP = (struct DpRam *) hp->Caddr;
1101 hp->Type = RIO_PCI; 1051 hp->Type = RIO_PCI;
1102 hp->Copy = rio_pcicopy; 1052 hp->Copy = rio_copy_to_card;
1103 hp->Mode = RIO_PCI_BOOT_FROM_RAM; 1053 hp->Mode = RIO_PCI_BOOT_FROM_RAM;
1104 spin_lock_init(&hp->HostLock); 1054 spin_lock_init(&hp->HostLock);
1105 1055
@@ -1109,14 +1059,14 @@ static int __init rio_init(void)
1109 rio_reset_interrupt(hp); 1059 rio_reset_interrupt(hp);
1110 rio_start_card_running(hp); 1060 rio_start_card_running(hp);
1111 rio_dprintk(RIO_DEBUG_PROBE, "Going to test it (%p/%p).\n", (void *) p->RIOHosts[p->RIONumHosts].PaddrP, p->RIOHosts[p->RIONumHosts].Caddr); 1061 rio_dprintk(RIO_DEBUG_PROBE, "Going to test it (%p/%p).\n", (void *) p->RIOHosts[p->RIONumHosts].PaddrP, p->RIOHosts[p->RIONumHosts].Caddr);
1112 if (RIOBoardTest(p->RIOHosts[p->RIONumHosts].PaddrP, p->RIOHosts[p->RIONumHosts].Caddr, RIO_PCI, 0) == RIO_SUCCESS) { 1062 if (RIOBoardTest(p->RIOHosts[p->RIONumHosts].PaddrP, p->RIOHosts[p->RIONumHosts].Caddr, RIO_PCI, 0) == 0) {
1113 WBYTE(p->RIOHosts[p->RIONumHosts].ResetInt, 0xff); 1063 writeb(0xFF, &p->RIOHosts[p->RIONumHosts].ResetInt);
1114 p->RIOHosts[p->RIONumHosts].UniqueNum = 1064 p->RIOHosts[p->RIONumHosts].UniqueNum =
1115 ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[0]) & 0xFF) << 0) | 1065 ((readb(&p->RIOHosts[p->RIONumHosts].Unique[0]) & 0xFF) << 0) |
1116 ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[1]) & 0xFF) << 8) | ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[2]) & 0xFF) << 16) | ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[3]) & 0xFF) << 24); 1066 ((readb(&p->RIOHosts[p->RIONumHosts].Unique[1]) & 0xFF) << 8) | ((readb(&p->RIOHosts[p->RIONumHosts].Unique[2]) & 0xFF) << 16) | ((readb(&p->RIOHosts[p->RIONumHosts].Unique[3]) & 0xFF) << 24);
1117 rio_dprintk(RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n", p->RIOHosts[p->RIONumHosts].UniqueNum); 1067 rio_dprintk(RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n", p->RIOHosts[p->RIONumHosts].UniqueNum);
1118 1068
1119 p->RIOLastPCISearch = RIO_SUCCESS; 1069 p->RIOLastPCISearch = 0;
1120 p->RIONumHosts++; 1070 p->RIONumHosts++;
1121 found++; 1071 found++;
1122 } else { 1072 } else {
@@ -1137,8 +1087,8 @@ static int __init rio_init(void)
1137 hp->Caddr = ioremap(p->RIOHosts[p->RIONumHosts].PaddrP, RIO_WINDOW_LEN); 1087 hp->Caddr = ioremap(p->RIOHosts[p->RIONumHosts].PaddrP, RIO_WINDOW_LEN);
1138 hp->CardP = (struct DpRam *) hp->Caddr; 1088 hp->CardP = (struct DpRam *) hp->Caddr;
1139 hp->Type = RIO_AT; 1089 hp->Type = RIO_AT;
1140 hp->Copy = rio_pcicopy; /* AT card PCI???? - PVDL 1090 hp->Copy = rio_copy_to_card; /* AT card PCI???? - PVDL
1141 * -- YES! this is now a normal copy. Only the 1091 * -- YES! this is now a normal copy. Only the
1142 * old PCI card uses the special PCI copy. 1092 * old PCI card uses the special PCI copy.
1143 * Moreover, the ISA card will work with the 1093 * Moreover, the ISA card will work with the
1144 * special PCI copy anyway. -- REW */ 1094 * special PCI copy anyway. -- REW */
@@ -1150,7 +1100,7 @@ static int __init rio_init(void)
1150 okboard = 0; 1100 okboard = 0;
1151 if ((strncmp(vpdp->identifier, RIO_ISA_IDENT, 16) == 0) || (strncmp(vpdp->identifier, RIO_ISA2_IDENT, 16) == 0) || (strncmp(vpdp->identifier, RIO_ISA3_IDENT, 16) == 0)) { 1101 if ((strncmp(vpdp->identifier, RIO_ISA_IDENT, 16) == 0) || (strncmp(vpdp->identifier, RIO_ISA2_IDENT, 16) == 0) || (strncmp(vpdp->identifier, RIO_ISA3_IDENT, 16) == 0)) {
1152 /* Board is present... */ 1102 /* Board is present... */
1153 if (RIOBoardTest(hp->PaddrP, hp->Caddr, RIO_AT, 0) == RIO_SUCCESS) { 1103 if (RIOBoardTest(hp->PaddrP, hp->Caddr, RIO_AT, 0) == 0) {
1154 /* ... and feeling fine!!!! */ 1104 /* ... and feeling fine!!!! */
1155 rio_dprintk(RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n", p->RIOHosts[p->RIONumHosts].UniqueNum); 1105 rio_dprintk(RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n", p->RIOHosts[p->RIONumHosts].UniqueNum);
1156 if (RIOAssignAT(p, hp->PaddrP, hp->Caddr, 0)) { 1106 if (RIOAssignAT(p, hp->PaddrP, hp->Caddr, 0)) {
@@ -1252,24 +1202,3 @@ static void __exit rio_exit(void)
1252 1202
1253module_init(rio_init); 1203module_init(rio_init);
1254module_exit(rio_exit); 1204module_exit(rio_exit);
1255
1256/*
1257 * Anybody who knows why this doesn't work for me, please tell me -- REW.
1258 * Snatched from scsi.c (fixed one spelling error):
1259 * Overrides for Emacs so that we follow Linus' tabbing style.
1260 * Emacs will notice this stuff at the end of the file and automatically
1261 * adjust the settings for this buffer only. This must remain at the end
1262 * of the file.
1263 * ---------------------------------------------------------------------------
1264 * Local Variables:
1265 * c-indent-level: 4
1266 * c-brace-imaginary-offset: 0
1267 * c-brace-offset: -4
1268 * c-argdecl-indent: 4
1269 * c-label-offset: -4
1270 * c-continued-statement-offset: 4
1271 * c-continued-brace-offset: 0
1272 * indent-tabs-mode: nil
1273 * tab-width: 8
1274 * End:
1275 */
diff --git a/drivers/char/rio/rioboot.c b/drivers/char/rio/rioboot.c
index 92df43552f..acda9326c2 100644
--- a/drivers/char/rio/rioboot.c
+++ b/drivers/char/rio/rioboot.c
@@ -30,38 +30,29 @@
30** ----------------------------------------------------------------------------- 30** -----------------------------------------------------------------------------
31*/ 31*/
32 32
33#ifdef SCCS_LABELS
34static char *_rioboot_c_sccs_ = "@(#)rioboot.c 1.3";
35#endif
36
37#include <linux/module.h> 33#include <linux/module.h>
38#include <linux/slab.h> 34#include <linux/slab.h>
35#include <linux/termios.h>
36#include <linux/serial.h>
37#include <asm/semaphore.h>
38#include <linux/generic_serial.h>
39#include <linux/errno.h> 39#include <linux/errno.h>
40#include <linux/interrupt.h> 40#include <linux/interrupt.h>
41#include <linux/delay.h>
41#include <asm/io.h> 42#include <asm/io.h>
42#include <asm/system.h> 43#include <asm/system.h>
43#include <asm/string.h> 44#include <asm/string.h>
44#include <asm/semaphore.h> 45#include <asm/uaccess.h>
45
46
47#include <linux/termios.h>
48#include <linux/serial.h>
49
50#include <linux/generic_serial.h>
51
52 46
53 47
54#include "linux_compat.h" 48#include "linux_compat.h"
55#include "rio_linux.h" 49#include "rio_linux.h"
56#include "typdef.h"
57#include "pkt.h" 50#include "pkt.h"
58#include "daemon.h" 51#include "daemon.h"
59#include "rio.h" 52#include "rio.h"
60#include "riospace.h" 53#include "riospace.h"
61#include "top.h"
62#include "cmdpkt.h" 54#include "cmdpkt.h"
63#include "map.h" 55#include "map.h"
64#include "riotypes.h"
65#include "rup.h" 56#include "rup.h"
66#include "port.h" 57#include "port.h"
67#include "riodrvr.h" 58#include "riodrvr.h"
@@ -74,161 +65,130 @@ static char *_rioboot_c_sccs_ = "@(#)rioboot.c 1.3";
74#include "unixrup.h" 65#include "unixrup.h"
75#include "board.h" 66#include "board.h"
76#include "host.h" 67#include "host.h"
77#include "error.h"
78#include "phb.h" 68#include "phb.h"
79#include "link.h" 69#include "link.h"
80#include "cmdblk.h" 70#include "cmdblk.h"
81#include "route.h" 71#include "route.h"
82 72
83static int RIOBootComplete( struct rio_info *p, struct Host *HostP, uint Rup, struct PktCmd *PktCmdP ); 73static int RIOBootComplete(struct rio_info *p, struct Host *HostP, unsigned int Rup, struct PktCmd *PktCmdP);
84 74
85static uchar 75static const unsigned char RIOAtVec2Ctrl[] = {
86RIOAtVec2Ctrl[] = 76 /* 0 */ INTERRUPT_DISABLE,
87{ 77 /* 1 */ INTERRUPT_DISABLE,
88 /* 0 */ INTERRUPT_DISABLE, 78 /* 2 */ INTERRUPT_DISABLE,
89 /* 1 */ INTERRUPT_DISABLE, 79 /* 3 */ INTERRUPT_DISABLE,
90 /* 2 */ INTERRUPT_DISABLE, 80 /* 4 */ INTERRUPT_DISABLE,
91 /* 3 */ INTERRUPT_DISABLE, 81 /* 5 */ INTERRUPT_DISABLE,
92 /* 4 */ INTERRUPT_DISABLE, 82 /* 6 */ INTERRUPT_DISABLE,
93 /* 5 */ INTERRUPT_DISABLE, 83 /* 7 */ INTERRUPT_DISABLE,
94 /* 6 */ INTERRUPT_DISABLE, 84 /* 8 */ INTERRUPT_DISABLE,
95 /* 7 */ INTERRUPT_DISABLE, 85 /* 9 */ IRQ_9 | INTERRUPT_ENABLE,
96 /* 8 */ INTERRUPT_DISABLE,
97 /* 9 */ IRQ_9|INTERRUPT_ENABLE,
98 /* 10 */ INTERRUPT_DISABLE, 86 /* 10 */ INTERRUPT_DISABLE,
99 /* 11 */ IRQ_11|INTERRUPT_ENABLE, 87 /* 11 */ IRQ_11 | INTERRUPT_ENABLE,
100 /* 12 */ IRQ_12|INTERRUPT_ENABLE, 88 /* 12 */ IRQ_12 | INTERRUPT_ENABLE,
101 /* 13 */ INTERRUPT_DISABLE, 89 /* 13 */ INTERRUPT_DISABLE,
102 /* 14 */ INTERRUPT_DISABLE, 90 /* 14 */ INTERRUPT_DISABLE,
103 /* 15 */ IRQ_15|INTERRUPT_ENABLE 91 /* 15 */ IRQ_15 | INTERRUPT_ENABLE
104}; 92};
105 93
106/* 94/**
107** Load in the RTA boot code. 95 * RIOBootCodeRTA - Load RTA boot code
108*/ 96 * @p: RIO to load
109int 97 * @rbp: Download descriptor
110RIOBootCodeRTA(p, rbp) 98 *
111struct rio_info * p; 99 * Called when the user process initiates booting of the card firmware.
112struct DownLoad * rbp; 100 * Lads the firmware
101 */
102
103int RIOBootCodeRTA(struct rio_info *p, struct DownLoad * rbp)
113{ 104{
114 int offset; 105 int offset;
115 106
116 func_enter (); 107 func_enter();
117 108
118 /* Linux doesn't allow you to disable interrupts during a 109 rio_dprintk(RIO_DEBUG_BOOT, "Data at user address %p\n", rbp->DataP);
119 "copyin". (Crash when a pagefault occurs). */
120 /* disable(oldspl); */
121
122 rio_dprintk (RIO_DEBUG_BOOT, "Data at user address 0x%x\n",(int)rbp->DataP);
123 110
124 /* 111 /*
125 ** Check that we have set asside enough memory for this 112 ** Check that we have set asside enough memory for this
126 */ 113 */
127 if ( rbp->Count > SIXTY_FOUR_K ) { 114 if (rbp->Count > SIXTY_FOUR_K) {
128 rio_dprintk (RIO_DEBUG_BOOT, "RTA Boot Code Too Large!\n"); 115 rio_dprintk(RIO_DEBUG_BOOT, "RTA Boot Code Too Large!\n");
129 p->RIOError.Error = HOST_FILE_TOO_LARGE; 116 p->RIOError.Error = HOST_FILE_TOO_LARGE;
130 /* restore(oldspl); */ 117 func_exit();
131 func_exit ();
132 return -ENOMEM; 118 return -ENOMEM;
133 } 119 }
134 120
135 if ( p->RIOBooting ) { 121 if (p->RIOBooting) {
136 rio_dprintk (RIO_DEBUG_BOOT, "RTA Boot Code : BUSY BUSY BUSY!\n"); 122 rio_dprintk(RIO_DEBUG_BOOT, "RTA Boot Code : BUSY BUSY BUSY!\n");
137 p->RIOError.Error = BOOT_IN_PROGRESS; 123 p->RIOError.Error = BOOT_IN_PROGRESS;
138 /* restore(oldspl); */ 124 func_exit();
139 func_exit ();
140 return -EBUSY; 125 return -EBUSY;
141 } 126 }
142 127
143 /* 128 /*
144 ** The data we load in must end on a (RTA_BOOT_DATA_SIZE) byte boundary, 129 ** The data we load in must end on a (RTA_BOOT_DATA_SIZE) byte boundary,
145 ** so calculate how far we have to move the data up the buffer 130 ** so calculate how far we have to move the data up the buffer
146 ** to achieve this. 131 ** to achieve this.
147 */ 132 */
148 offset = (RTA_BOOT_DATA_SIZE - (rbp->Count % RTA_BOOT_DATA_SIZE)) % 133 offset = (RTA_BOOT_DATA_SIZE - (rbp->Count % RTA_BOOT_DATA_SIZE)) % RTA_BOOT_DATA_SIZE;
149 RTA_BOOT_DATA_SIZE;
150 134
151 /* 135 /*
152 ** Be clean, and clear the 'unused' portion of the boot buffer, 136 ** Be clean, and clear the 'unused' portion of the boot buffer,
153 ** because it will (eventually) be part of the Rta run time environment 137 ** because it will (eventually) be part of the Rta run time environment
154 ** and so should be zeroed. 138 ** and so should be zeroed.
155 */ 139 */
156 bzero( (caddr_t)p->RIOBootPackets, offset ); 140 memset(p->RIOBootPackets, 0, offset);
157 141
158 /* 142 /*
159 ** Copy the data from user space. 143 ** Copy the data from user space into the array
160 */ 144 */
161 145
162 if ( copyin((int)rbp->DataP,((caddr_t)(p->RIOBootPackets))+offset, 146 if (copy_from_user(((u8 *)p->RIOBootPackets) + offset, rbp->DataP, rbp->Count)) {
163 rbp->Count) ==COPYFAIL ) { 147 rio_dprintk(RIO_DEBUG_BOOT, "Bad data copy from user space\n");
164 rio_dprintk (RIO_DEBUG_BOOT, "Bad data copy from user space\n");
165 p->RIOError.Error = COPYIN_FAILED; 148 p->RIOError.Error = COPYIN_FAILED;
166 /* restore(oldspl); */ 149 func_exit();
167 func_exit ();
168 return -EFAULT; 150 return -EFAULT;
169 } 151 }
170 152
171 /* 153 /*
172 ** Make sure that our copy of the size includes that offset we discussed 154 ** Make sure that our copy of the size includes that offset we discussed
173 ** earlier. 155 ** earlier.
174 */ 156 */
175 p->RIONumBootPkts = (rbp->Count+offset)/RTA_BOOT_DATA_SIZE; 157 p->RIONumBootPkts = (rbp->Count + offset) / RTA_BOOT_DATA_SIZE;
176 p->RIOBootCount = rbp->Count; 158 p->RIOBootCount = rbp->Count;
177 159
178 /* restore(oldspl); */
179 func_exit(); 160 func_exit();
180 return 0; 161 return 0;
181} 162}
182 163
183void rio_start_card_running (struct Host * HostP) 164/**
184{ 165 * rio_start_card_running - host card start
185 func_enter (); 166 * @HostP: The RIO to kick off
167 *
168 * Start a RIO processor unit running. Encapsulates the knowledge
169 * of the card type.
170 */
186 171
187 switch ( HostP->Type ) { 172void rio_start_card_running(struct Host *HostP)
173{
174 switch (HostP->Type) {
188 case RIO_AT: 175 case RIO_AT:
189 rio_dprintk (RIO_DEBUG_BOOT, "Start ISA card running\n"); 176 rio_dprintk(RIO_DEBUG_BOOT, "Start ISA card running\n");
190 WBYTE(HostP->Control, 177 writeb(BOOT_FROM_RAM | EXTERNAL_BUS_ON | HostP->Mode | RIOAtVec2Ctrl[HostP->Ivec & 0xF], &HostP->Control);
191 BOOT_FROM_RAM | EXTERNAL_BUS_ON
192 | HostP->Mode
193 | RIOAtVec2Ctrl[HostP->Ivec & 0xF] );
194 break;
195
196#ifdef FUTURE_RELEASE
197 case RIO_MCA:
198 /*
199 ** MCA handles IRQ vectors differently, so we don't write
200 ** them to this register.
201 */
202 rio_dprintk (RIO_DEBUG_BOOT, "Start MCA card running\n");
203 WBYTE(HostP->Control, McaTpBootFromRam | McaTpBusEnable | HostP->Mode);
204 break; 178 break;
205
206 case RIO_EISA:
207 /*
208 ** EISA is totally different and expects OUTBZs to turn it on.
209 */
210 rio_dprintk (RIO_DEBUG_BOOT, "Start EISA card running\n");
211 OUTBZ( HostP->Slot, EISA_CONTROL_PORT, HostP->Mode | RIOEisaVec2Ctrl[HostP->Ivec] | EISA_TP_RUN | EISA_TP_BUS_ENABLE | EISA_TP_BOOT_FROM_RAM );
212 break;
213#endif
214
215 case RIO_PCI: 179 case RIO_PCI:
216 /* 180 /*
217 ** PCI is much the same as MCA. Everything is once again memory 181 ** PCI is much the same as MCA. Everything is once again memory
218 ** mapped, so we are writing to memory registers instead of io 182 ** mapped, so we are writing to memory registers instead of io
219 ** ports. 183 ** ports.
220 */ 184 */
221 rio_dprintk (RIO_DEBUG_BOOT, "Start PCI card running\n"); 185 rio_dprintk(RIO_DEBUG_BOOT, "Start PCI card running\n");
222 WBYTE(HostP->Control, PCITpBootFromRam | PCITpBusEnable | HostP->Mode); 186 writeb(PCITpBootFromRam | PCITpBusEnable | HostP->Mode, &HostP->Control);
223 break; 187 break;
224 default: 188 default:
225 rio_dprintk (RIO_DEBUG_BOOT, "Unknown host type %d\n", HostP->Type); 189 rio_dprintk(RIO_DEBUG_BOOT, "Unknown host type %d\n", HostP->Type);
226 break; 190 break;
227 } 191 }
228/*
229 printk (KERN_INFO "Done with starting the card\n");
230 func_exit ();
231*/
232 return; 192 return;
233} 193}
234 194
@@ -239,370 +199,350 @@ void rio_start_card_running (struct Host * HostP)
239** Put your rubber pants on before messing with this code - even the magic 199** Put your rubber pants on before messing with this code - even the magic
240** numbers have trouble understanding what they are doing here. 200** numbers have trouble understanding what they are doing here.
241*/ 201*/
242int 202
243RIOBootCodeHOST(p, rbp) 203int RIOBootCodeHOST(struct rio_info *p, struct DownLoad *rbp)
244struct rio_info * p;
245register struct DownLoad *rbp;
246{ 204{
247 register struct Host *HostP; 205 struct Host *HostP;
248 register caddr_t Cad; 206 u8 *Cad;
249 register PARM_MAP *ParmMapP; 207 PARM_MAP *ParmMapP;
250 register int RupN; 208 int RupN;
251 int PortN; 209 int PortN;
252 uint host; 210 unsigned int host;
253 caddr_t StartP; 211 u8 *StartP;
254 BYTE *DestP; 212 u8 *DestP;
255 int wait_count; 213 int wait_count;
256 ushort OldParmMap; 214 u16 OldParmMap;
257 ushort offset; /* It is very important that this is a ushort */ 215 u16 offset; /* It is very important that this is a u16 */
258 /* uint byte; */ 216 u8 *DownCode = NULL;
259 caddr_t DownCode = NULL;
260 unsigned long flags; 217 unsigned long flags;
261 218
262 HostP = NULL; /* Assure the compiler we've initialized it */ 219 HostP = NULL; /* Assure the compiler we've initialized it */
263 for ( host=0; host<p->RIONumHosts; host++ ) { 220
264 rio_dprintk (RIO_DEBUG_BOOT, "Attempt to boot host %d\n",host); 221
222 /* Walk the hosts */
223 for (host = 0; host < p->RIONumHosts; host++) {
224 rio_dprintk(RIO_DEBUG_BOOT, "Attempt to boot host %d\n", host);
265 HostP = &p->RIOHosts[host]; 225 HostP = &p->RIOHosts[host];
266
267 rio_dprintk (RIO_DEBUG_BOOT, "Host Type = 0x%x, Mode = 0x%x, IVec = 0x%x\n",
268 HostP->Type, HostP->Mode, HostP->Ivec);
269 226
227 rio_dprintk(RIO_DEBUG_BOOT, "Host Type = 0x%x, Mode = 0x%x, IVec = 0x%x\n", HostP->Type, HostP->Mode, HostP->Ivec);
270 228
271 if ( (HostP->Flags & RUN_STATE) != RC_WAITING ) { 229 /* Don't boot hosts already running */
272 rio_dprintk (RIO_DEBUG_BOOT, "%s %d already running\n","Host",host); 230 if ((HostP->Flags & RUN_STATE) != RC_WAITING) {
231 rio_dprintk(RIO_DEBUG_BOOT, "%s %d already running\n", "Host", host);
273 continue; 232 continue;
274 } 233 }
275 234
276 /* 235 /*
277 ** Grab a 32 bit pointer to the card. 236 ** Grab a pointer to the card (ioremapped)
278 */ 237 */
279 Cad = HostP->Caddr; 238 Cad = HostP->Caddr;
280 239
281 /* 240 /*
282 ** We are going to (try) and load in rbp->Count bytes. 241 ** We are going to (try) and load in rbp->Count bytes.
283 ** The last byte will reside at p->RIOConf.HostLoadBase-1; 242 ** The last byte will reside at p->RIOConf.HostLoadBase-1;
284 ** Therefore, we need to start copying at address 243 ** Therefore, we need to start copying at address
285 ** (caddr+p->RIOConf.HostLoadBase-rbp->Count) 244 ** (caddr+p->RIOConf.HostLoadBase-rbp->Count)
286 */ 245 */
287 StartP = (caddr_t)&Cad[p->RIOConf.HostLoadBase-rbp->Count]; 246 StartP = &Cad[p->RIOConf.HostLoadBase - rbp->Count];
288 247
289 rio_dprintk (RIO_DEBUG_BOOT, "kernel virtual address for host is 0x%x\n", (int)Cad ); 248 rio_dprintk(RIO_DEBUG_BOOT, "kernel virtual address for host is %p\n", Cad);
290 rio_dprintk (RIO_DEBUG_BOOT, "kernel virtual address for download is 0x%x\n", (int)StartP); 249 rio_dprintk(RIO_DEBUG_BOOT, "kernel virtual address for download is %p\n", StartP);
291 rio_dprintk (RIO_DEBUG_BOOT, "host loadbase is 0x%x\n",p->RIOConf.HostLoadBase); 250 rio_dprintk(RIO_DEBUG_BOOT, "host loadbase is 0x%x\n", p->RIOConf.HostLoadBase);
292 rio_dprintk (RIO_DEBUG_BOOT, "size of download is 0x%x\n", rbp->Count); 251 rio_dprintk(RIO_DEBUG_BOOT, "size of download is 0x%x\n", rbp->Count);
293 252
294 if ( p->RIOConf.HostLoadBase < rbp->Count ) { 253 /* Make sure it fits */
295 rio_dprintk (RIO_DEBUG_BOOT, "Bin too large\n"); 254 if (p->RIOConf.HostLoadBase < rbp->Count) {
255 rio_dprintk(RIO_DEBUG_BOOT, "Bin too large\n");
296 p->RIOError.Error = HOST_FILE_TOO_LARGE; 256 p->RIOError.Error = HOST_FILE_TOO_LARGE;
297 func_exit (); 257 func_exit();
298 return -EFBIG; 258 return -EFBIG;
299 } 259 }
300 /* 260 /*
301 ** Ensure that the host really is stopped. 261 ** Ensure that the host really is stopped.
302 ** Disable it's external bus & twang its reset line. 262 ** Disable it's external bus & twang its reset line.
303 */ 263 */
304 RIOHostReset( HostP->Type, (struct DpRam *)HostP->CardP, HostP->Slot ); 264 RIOHostReset(HostP->Type, (struct DpRam *) HostP->CardP, HostP->Slot);
305
306 /*
307 ** Copy the data directly from user space to the SRAM.
308 ** This ain't going to be none too clever if the download
309 ** code is bigger than this segment.
310 */
311 rio_dprintk (RIO_DEBUG_BOOT, "Copy in code\n");
312 265
313 /* 266 /*
314 ** PCI hostcard can't cope with 32 bit accesses and so need to copy 267 ** Copy the data directly from user space to the SRAM.
315 ** data to a local buffer, and then dripfeed the card. 268 ** This ain't going to be none too clever if the download
316 */ 269 ** code is bigger than this segment.
317 if ( HostP->Type == RIO_PCI ) { 270 */
318 /* int offset; */ 271 rio_dprintk(RIO_DEBUG_BOOT, "Copy in code\n");
319 272
320 DownCode = sysbrk(rbp->Count); 273 /* Buffer to local memory as we want to use I/O space and
321 if ( !DownCode ) { 274 some cards only do 8 or 16 bit I/O */
322 rio_dprintk (RIO_DEBUG_BOOT, "No system memory available\n"); 275
323 p->RIOError.Error = NOT_ENOUGH_CORE_FOR_PCI_COPY; 276 DownCode = vmalloc(rbp->Count);
324 func_exit (); 277 if (!DownCode) {
325 return -ENOMEM; 278 p->RIOError.Error = NOT_ENOUGH_CORE_FOR_PCI_COPY;
326 } 279 func_exit();
327 bzero(DownCode, rbp->Count); 280 return -ENOMEM;
328
329 if ( copyin((int)rbp->DataP,DownCode,rbp->Count)==COPYFAIL ) {
330 rio_dprintk (RIO_DEBUG_BOOT, "Bad copyin of host data\n");
331 sysfree( DownCode, rbp->Count );
332 p->RIOError.Error = COPYIN_FAILED;
333 func_exit ();
334 return -EFAULT;
335 }
336
337 HostP->Copy( DownCode, StartP, rbp->Count );
338
339 sysfree( DownCode, rbp->Count );
340 } 281 }
341 else if ( copyin((int)rbp->DataP,StartP,rbp->Count)==COPYFAIL ) { 282 if (copy_from_user(rbp->DataP, DownCode, rbp->Count)) {
342 rio_dprintk (RIO_DEBUG_BOOT, "Bad copyin of host data\n"); 283 kfree(DownCode);
343 p->RIOError.Error = COPYIN_FAILED; 284 p->RIOError.Error = COPYIN_FAILED;
344 func_exit (); 285 func_exit();
345 return -EFAULT; 286 return -EFAULT;
346 } 287 }
288 HostP->Copy(DownCode, StartP, rbp->Count);
289 vfree(DownCode);
347 290
348 rio_dprintk (RIO_DEBUG_BOOT, "Copy completed\n"); 291 rio_dprintk(RIO_DEBUG_BOOT, "Copy completed\n");
349 292
350 /* 293 /*
351 ** S T O P ! 294 ** S T O P !
352 ** 295 **
353 ** Upto this point the code has been fairly rational, and possibly 296 ** Upto this point the code has been fairly rational, and possibly
354 ** even straight forward. What follows is a pile of crud that will 297 ** even straight forward. What follows is a pile of crud that will
355 ** magically turn into six bytes of transputer assembler. Normally 298 ** magically turn into six bytes of transputer assembler. Normally
356 ** you would expect an array or something, but, being me, I have 299 ** you would expect an array or something, but, being me, I have
357 ** chosen [been told] to use a technique whereby the startup code 300 ** chosen [been told] to use a technique whereby the startup code
358 ** will be correct if we change the loadbase for the code. Which 301 ** will be correct if we change the loadbase for the code. Which
359 ** brings us onto another issue - the loadbase is the *end* of the 302 ** brings us onto another issue - the loadbase is the *end* of the
360 ** code, not the start. 303 ** code, not the start.
361 ** 304 **
362 ** If I were you I wouldn't start from here. 305 ** If I were you I wouldn't start from here.
363 */ 306 */
364 307
365 /* 308 /*
366 ** We now need to insert a short boot section into 309 ** We now need to insert a short boot section into
367 ** the memory at the end of Sram2. This is normally (de)composed 310 ** the memory at the end of Sram2. This is normally (de)composed
368 ** of the last eight bytes of the download code. The 311 ** of the last eight bytes of the download code. The
369 ** download has been assembled/compiled to expect to be 312 ** download has been assembled/compiled to expect to be
370 ** loaded from 0x7FFF downwards. We have loaded it 313 ** loaded from 0x7FFF downwards. We have loaded it
371 ** at some other address. The startup code goes into the small 314 ** at some other address. The startup code goes into the small
372 ** ram window at Sram2, in the last 8 bytes, which are really 315 ** ram window at Sram2, in the last 8 bytes, which are really
373 ** at addresses 0x7FF8-0x7FFF. 316 ** at addresses 0x7FF8-0x7FFF.
374 ** 317 **
375 ** If the loadbase is, say, 0x7C00, then we need to branch to 318 ** If the loadbase is, say, 0x7C00, then we need to branch to
376 ** address 0x7BFE to run the host.bin startup code. We assemble 319 ** address 0x7BFE to run the host.bin startup code. We assemble
377 ** this jump manually. 320 ** this jump manually.
378 ** 321 **
379 ** The two byte sequence 60 08 is loaded into memory at address 322 ** The two byte sequence 60 08 is loaded into memory at address
380 ** 0x7FFE,F. This is a local branch to location 0x7FF8 (60 is nfix 0, 323 ** 0x7FFE,F. This is a local branch to location 0x7FF8 (60 is nfix 0,
381 ** which adds '0' to the .O register, complements .O, and then shifts 324 ** which adds '0' to the .O register, complements .O, and then shifts
382 ** it left by 4 bit positions, 08 is a jump .O+8 instruction. This will 325 ** it left by 4 bit positions, 08 is a jump .O+8 instruction. This will
383 ** add 8 to .O (which was 0xFFF0), and will branch RELATIVE to the new 326 ** add 8 to .O (which was 0xFFF0), and will branch RELATIVE to the new
384 ** location. Now, the branch starts from the value of .PC (or .IP or 327 ** location. Now, the branch starts from the value of .PC (or .IP or
385 ** whatever the bloody register is called on this chip), and the .PC 328 ** whatever the bloody register is called on this chip), and the .PC
386 ** will be pointing to the location AFTER the branch, in this case 329 ** will be pointing to the location AFTER the branch, in this case
387 ** .PC == 0x8000, so the branch will be to 0x8000+0xFFF8 = 0x7FF8. 330 ** .PC == 0x8000, so the branch will be to 0x8000+0xFFF8 = 0x7FF8.
388 ** 331 **
389 ** A long branch is coded at 0x7FF8. This consists of loading a four 332 ** A long branch is coded at 0x7FF8. This consists of loading a four
390 ** byte offset into .O using nfix (as above) and pfix operators. The 333 ** byte offset into .O using nfix (as above) and pfix operators. The
391 ** pfix operates in exactly the same way as the nfix operator, but 334 ** pfix operates in exactly the same way as the nfix operator, but
392 ** without the complement operation. The offset, of course, must be 335 ** without the complement operation. The offset, of course, must be
393 ** relative to the address of the byte AFTER the branch instruction, 336 ** relative to the address of the byte AFTER the branch instruction,
394 ** which will be (urm) 0x7FFC, so, our final destination of the branch 337 ** which will be (urm) 0x7FFC, so, our final destination of the branch
395 ** (loadbase-2), has to be reached from here. Imagine that the loadbase 338 ** (loadbase-2), has to be reached from here. Imagine that the loadbase
396 ** is 0x7C00 (which it is), then we will need to branch to 0x7BFE (which 339 ** is 0x7C00 (which it is), then we will need to branch to 0x7BFE (which
397 ** is the first byte of the initial two byte short local branch of the 340 ** is the first byte of the initial two byte short local branch of the
398 ** download code). 341 ** download code).
399 ** 342 **
400 ** To code a jump from 0x7FFC (which is where the branch will start 343 ** To code a jump from 0x7FFC (which is where the branch will start
401 ** from) to 0x7BFE, we will need to branch 0xFC02 bytes (0x7FFC+0xFC02)= 344 ** from) to 0x7BFE, we will need to branch 0xFC02 bytes (0x7FFC+0xFC02)=
402 ** 0x7BFE. 345 ** 0x7BFE.
403 ** This will be coded as four bytes: 346 ** This will be coded as four bytes:
404 ** 60 2C 20 02 347 ** 60 2C 20 02
405 ** being nfix .O+0 348 ** being nfix .O+0
406 ** pfix .O+C 349 ** pfix .O+C
407 ** pfix .O+0 350 ** pfix .O+0
408 ** jump .O+2 351 ** jump .O+2
409 ** 352 **
410 ** The nfix operator is used, so that the startup code will be 353 ** The nfix operator is used, so that the startup code will be
411 ** compatible with the whole Tp family. (lies, damn lies, it'll never 354 ** compatible with the whole Tp family. (lies, damn lies, it'll never
412 ** work in a month of Sundays). 355 ** work in a month of Sundays).
413 ** 356 **
414 ** The nfix nyble is the 1s complement of the nyble value you 357 ** The nfix nyble is the 1s complement of the nyble value you
415 ** want to load - in this case we wanted 'F' so we nfix loaded '0'. 358 ** want to load - in this case we wanted 'F' so we nfix loaded '0'.
416 */ 359 */
417 360
418 361
419 /* 362 /*
420 ** Dest points to the top 8 bytes of Sram2. The Tp jumps 363 ** Dest points to the top 8 bytes of Sram2. The Tp jumps
421 ** to 0x7FFE at reset time, and starts executing. This is 364 ** to 0x7FFE at reset time, and starts executing. This is
422 ** a short branch to 0x7FF8, where a long branch is coded. 365 ** a short branch to 0x7FF8, where a long branch is coded.
423 */ 366 */
424 367
425 DestP = (BYTE *)&Cad[0x7FF8]; /* <<<---- READ THE ABOVE COMMENTS */ 368 DestP = (u8 *) &Cad[0x7FF8]; /* <<<---- READ THE ABOVE COMMENTS */
426 369
427#define NFIX(N) (0x60 | (N)) /* .O = (~(.O + N))<<4 */ 370#define NFIX(N) (0x60 | (N)) /* .O = (~(.O + N))<<4 */
428#define PFIX(N) (0x20 | (N)) /* .O = (.O + N)<<4 */ 371#define PFIX(N) (0x20 | (N)) /* .O = (.O + N)<<4 */
429#define JUMP(N) (0x00 | (N)) /* .PC = .PC + .O */ 372#define JUMP(N) (0x00 | (N)) /* .PC = .PC + .O */
430 373
431 /* 374 /*
432 ** 0x7FFC is the address of the location following the last byte of 375 ** 0x7FFC is the address of the location following the last byte of
433 ** the four byte jump instruction. 376 ** the four byte jump instruction.
434 ** READ THE ABOVE COMMENTS 377 ** READ THE ABOVE COMMENTS
435 ** 378 **
436 ** offset is (TO-FROM) % MEMSIZE, but with compound buggering about. 379 ** offset is (TO-FROM) % MEMSIZE, but with compound buggering about.
437 ** Memsize is 64K for this range of Tp, so offset is a short (unsigned, 380 ** Memsize is 64K for this range of Tp, so offset is a short (unsigned,
438 ** cos I don't understand 2's complement). 381 ** cos I don't understand 2's complement).
439 */ 382 */
440 offset = (p->RIOConf.HostLoadBase-2)-0x7FFC; 383 offset = (p->RIOConf.HostLoadBase - 2) - 0x7FFC;
441 WBYTE( DestP[0] , NFIX(((ushort)(~offset) >> (ushort)12) & 0xF) ); 384
442 WBYTE( DestP[1] , PFIX(( offset >> 8) & 0xF) ); 385 writeb(NFIX(((unsigned short) (~offset) >> (unsigned short) 12) & 0xF), DestP);
443 WBYTE( DestP[2] , PFIX(( offset >> 4) & 0xF) ); 386 writeb(PFIX((offset >> 8) & 0xF), DestP + 1);
444 WBYTE( DestP[3] , JUMP( offset & 0xF) ); 387 writeb(PFIX((offset >> 4) & 0xF), DestP + 2);
445 388 writeb(JUMP(offset & 0xF), DestP + 3);
446 WBYTE( DestP[6] , NFIX(0) ); 389
447 WBYTE( DestP[7] , JUMP(8) ); 390 writeb(NFIX(0), DestP + 6);
448 391 writeb(JUMP(8), DestP + 7);
449 rio_dprintk (RIO_DEBUG_BOOT, "host loadbase is 0x%x\n",p->RIOConf.HostLoadBase); 392
450 rio_dprintk (RIO_DEBUG_BOOT, "startup offset is 0x%x\n",offset); 393 rio_dprintk(RIO_DEBUG_BOOT, "host loadbase is 0x%x\n", p->RIOConf.HostLoadBase);
394 rio_dprintk(RIO_DEBUG_BOOT, "startup offset is 0x%x\n", offset);
451 395
452 /* 396 /*
453 ** Flag what is going on 397 ** Flag what is going on
454 */ 398 */
455 HostP->Flags &= ~RUN_STATE; 399 HostP->Flags &= ~RUN_STATE;
456 HostP->Flags |= RC_STARTUP; 400 HostP->Flags |= RC_STARTUP;
457 401
458 /* 402 /*
459 ** Grab a copy of the current ParmMap pointer, so we 403 ** Grab a copy of the current ParmMap pointer, so we
460 ** can tell when it has changed. 404 ** can tell when it has changed.
461 */ 405 */
462 OldParmMap = RWORD(HostP->__ParmMapR); 406 OldParmMap = readw(&HostP->__ParmMapR);
463 407
464 rio_dprintk (RIO_DEBUG_BOOT, "Original parmmap is 0x%x\n",OldParmMap); 408 rio_dprintk(RIO_DEBUG_BOOT, "Original parmmap is 0x%x\n", OldParmMap);
465 409
466 /* 410 /*
467 ** And start it running (I hope). 411 ** And start it running (I hope).
468 ** As there is nothing dodgy or obscure about the 412 ** As there is nothing dodgy or obscure about the
469 ** above code, this is guaranteed to work every time. 413 ** above code, this is guaranteed to work every time.
470 */ 414 */
471 rio_dprintk (RIO_DEBUG_BOOT, "Host Type = 0x%x, Mode = 0x%x, IVec = 0x%x\n", 415 rio_dprintk(RIO_DEBUG_BOOT, "Host Type = 0x%x, Mode = 0x%x, IVec = 0x%x\n", HostP->Type, HostP->Mode, HostP->Ivec);
472 HostP->Type, HostP->Mode, HostP->Ivec);
473 416
474 rio_start_card_running(HostP); 417 rio_start_card_running(HostP);
475 418
476 rio_dprintk (RIO_DEBUG_BOOT, "Set control port\n"); 419 rio_dprintk(RIO_DEBUG_BOOT, "Set control port\n");
477 420
478 /* 421 /*
479 ** Now, wait for upto five seconds for the Tp to setup the parmmap 422 ** Now, wait for upto five seconds for the Tp to setup the parmmap
480 ** pointer: 423 ** pointer:
481 */ 424 */
482 for ( wait_count=0; (wait_count<p->RIOConf.StartupTime)&& 425 for (wait_count = 0; (wait_count < p->RIOConf.StartupTime) && (readw(&HostP->__ParmMapR) == OldParmMap); wait_count++) {
483 (RWORD(HostP->__ParmMapR)==OldParmMap); wait_count++ ) { 426 rio_dprintk(RIO_DEBUG_BOOT, "Checkout %d, 0x%x\n", wait_count, readw(&HostP->__ParmMapR));
484 rio_dprintk (RIO_DEBUG_BOOT, "Checkout %d, 0x%x\n",wait_count,RWORD(HostP->__ParmMapR)); 427 mdelay(100);
485 delay(HostP, HUNDRED_MS);
486 428
487 } 429 }
488 430
489 /* 431 /*
490 ** If the parmmap pointer is unchanged, then the host code 432 ** If the parmmap pointer is unchanged, then the host code
491 ** has crashed & burned in a really spectacular way 433 ** has crashed & burned in a really spectacular way
492 */ 434 */
493 if ( RWORD(HostP->__ParmMapR) == OldParmMap ) { 435 if (readw(&HostP->__ParmMapR) == OldParmMap) {
494 rio_dprintk (RIO_DEBUG_BOOT, "parmmap 0x%x\n", RWORD(HostP->__ParmMapR)); 436 rio_dprintk(RIO_DEBUG_BOOT, "parmmap 0x%x\n", readw(&HostP->__ParmMapR));
495 rio_dprintk (RIO_DEBUG_BOOT, "RIO Mesg Run Fail\n"); 437 rio_dprintk(RIO_DEBUG_BOOT, "RIO Mesg Run Fail\n");
496 438 HostP->Flags &= ~RUN_STATE;
497#define HOST_DISABLE \ 439 HostP->Flags |= RC_STUFFED;
498 HostP->Flags &= ~RUN_STATE; \ 440 RIOHostReset( HostP->Type, (struct DpRam *)HostP->CardP, HostP->Slot );
499 HostP->Flags |= RC_STUFFED; \ 441 continue;
500 RIOHostReset( HostP->Type, (struct DpRam *)HostP->CardP, HostP->Slot );\
501 continue
502
503 HOST_DISABLE;
504 } 442 }
505 443
506 rio_dprintk (RIO_DEBUG_BOOT, "Running 0x%x\n", RWORD(HostP->__ParmMapR)); 444 rio_dprintk(RIO_DEBUG_BOOT, "Running 0x%x\n", readw(&HostP->__ParmMapR));
507 445
508 /* 446 /*
509 ** Well, the board thought it was OK, and setup its parmmap 447 ** Well, the board thought it was OK, and setup its parmmap
510 ** pointer. For the time being, we will pretend that this 448 ** pointer. For the time being, we will pretend that this
511 ** board is running, and check out what the error flag says. 449 ** board is running, and check out what the error flag says.
512 */ 450 */
513 451
514 /* 452 /*
515 ** Grab a 32 bit pointer to the parmmap structure 453 ** Grab a 32 bit pointer to the parmmap structure
516 */ 454 */
517 ParmMapP = (PARM_MAP *)RIO_PTR(Cad,RWORD(HostP->__ParmMapR)); 455 ParmMapP = (PARM_MAP *) RIO_PTR(Cad, readw(&HostP->__ParmMapR));
518 rio_dprintk (RIO_DEBUG_BOOT, "ParmMapP : %x\n", (int)ParmMapP); 456 rio_dprintk(RIO_DEBUG_BOOT, "ParmMapP : %p\n", ParmMapP);
519 ParmMapP = (PARM_MAP *)((unsigned long)Cad + 457 ParmMapP = (PARM_MAP *) ((unsigned long) Cad + readw(&HostP->__ParmMapR));
520 (unsigned long)((RWORD((HostP->__ParmMapR))) & 0xFFFF)); 458 rio_dprintk(RIO_DEBUG_BOOT, "ParmMapP : %p\n", ParmMapP);
521 rio_dprintk (RIO_DEBUG_BOOT, "ParmMapP : %x\n", (int)ParmMapP);
522 459
523 /* 460 /*
524 ** The links entry should be 0xFFFF; we set it up 461 ** The links entry should be 0xFFFF; we set it up
525 ** with a mask to say how many PHBs to use, and 462 ** with a mask to say how many PHBs to use, and
526 ** which links to use. 463 ** which links to use.
527 */ 464 */
528 if ( (RWORD(ParmMapP->links) & 0xFFFF) != 0xFFFF ) { 465 if (readw(&ParmMapP->links) != 0xFFFF) {
529 rio_dprintk (RIO_DEBUG_BOOT, "RIO Mesg Run Fail %s\n", HostP->Name); 466 rio_dprintk(RIO_DEBUG_BOOT, "RIO Mesg Run Fail %s\n", HostP->Name);
530 rio_dprintk (RIO_DEBUG_BOOT, "Links = 0x%x\n",RWORD(ParmMapP->links)); 467 rio_dprintk(RIO_DEBUG_BOOT, "Links = 0x%x\n", readw(&ParmMapP->links));
531 HOST_DISABLE; 468 HostP->Flags &= ~RUN_STATE;
469 HostP->Flags |= RC_STUFFED;
470 RIOHostReset( HostP->Type, (struct DpRam *)HostP->CardP, HostP->Slot );
471 continue;
532 } 472 }
533 473
534 WWORD(ParmMapP->links , RIO_LINK_ENABLE); 474 writew(RIO_LINK_ENABLE, &ParmMapP->links);
535 475
536 /* 476 /*
537 ** now wait for the card to set all the parmmap->XXX stuff 477 ** now wait for the card to set all the parmmap->XXX stuff
538 ** this is a wait of upto two seconds.... 478 ** this is a wait of upto two seconds....
539 */ 479 */
540 rio_dprintk (RIO_DEBUG_BOOT, "Looking for init_done - %d ticks\n",p->RIOConf.StartupTime); 480 rio_dprintk(RIO_DEBUG_BOOT, "Looking for init_done - %d ticks\n", p->RIOConf.StartupTime);
541 HostP->timeout_id = 0; 481 HostP->timeout_id = 0;
542 for ( wait_count=0; (wait_count<p->RIOConf.StartupTime) && 482 for (wait_count = 0; (wait_count < p->RIOConf.StartupTime) && !readw(&ParmMapP->init_done); wait_count++) {
543 !RWORD(ParmMapP->init_done); wait_count++ ) { 483 rio_dprintk(RIO_DEBUG_BOOT, "Waiting for init_done\n");
544 rio_dprintk (RIO_DEBUG_BOOT, "Waiting for init_done\n"); 484 mdelay(100);
545 delay(HostP, HUNDRED_MS);
546 } 485 }
547 rio_dprintk (RIO_DEBUG_BOOT, "OK! init_done!\n"); 486 rio_dprintk(RIO_DEBUG_BOOT, "OK! init_done!\n");
548 487
549 if (RWORD(ParmMapP->error) != E_NO_ERROR || 488 if (readw(&ParmMapP->error) != E_NO_ERROR || !readw(&ParmMapP->init_done)) {
550 !RWORD(ParmMapP->init_done) ) { 489 rio_dprintk(RIO_DEBUG_BOOT, "RIO Mesg Run Fail %s\n", HostP->Name);
551 rio_dprintk (RIO_DEBUG_BOOT, "RIO Mesg Run Fail %s\n", HostP->Name); 490 rio_dprintk(RIO_DEBUG_BOOT, "Timedout waiting for init_done\n");
552 rio_dprintk (RIO_DEBUG_BOOT, "Timedout waiting for init_done\n"); 491 HostP->Flags &= ~RUN_STATE;
553 HOST_DISABLE; 492 HostP->Flags |= RC_STUFFED;
493 RIOHostReset( HostP->Type, (struct DpRam *)HostP->CardP, HostP->Slot );
494 continue;
554 } 495 }
555 496
556 rio_dprintk (RIO_DEBUG_BOOT, "Got init_done\n"); 497 rio_dprintk(RIO_DEBUG_BOOT, "Got init_done\n");
557 498
558 /* 499 /*
559 ** It runs! It runs! 500 ** It runs! It runs!
560 */ 501 */
561 rio_dprintk (RIO_DEBUG_BOOT, "Host ID %x Running\n",HostP->UniqueNum); 502 rio_dprintk(RIO_DEBUG_BOOT, "Host ID %x Running\n", HostP->UniqueNum);
562 503
563 /* 504 /*
564 ** set the time period between interrupts. 505 ** set the time period between interrupts.
565 */ 506 */
566 WWORD(ParmMapP->timer, (short)p->RIOConf.Timer ); 507 writew(p->RIOConf.Timer, &ParmMapP->timer);
567 508
568 /* 509 /*
569 ** Translate all the 16 bit pointers in the __ParmMapR into 510 ** Translate all the 16 bit pointers in the __ParmMapR into
570 ** 32 bit pointers for the driver. 511 ** 32 bit pointers for the driver in ioremap space.
571 */ 512 */
572 HostP->ParmMapP = ParmMapP; 513 HostP->ParmMapP = ParmMapP;
573 HostP->PhbP = (PHB*)RIO_PTR(Cad,RWORD(ParmMapP->phb_ptr)); 514 HostP->PhbP = (struct PHB *) RIO_PTR(Cad, readw(&ParmMapP->phb_ptr));
574 HostP->RupP = (RUP*)RIO_PTR(Cad,RWORD(ParmMapP->rups)); 515 HostP->RupP = (struct RUP *) RIO_PTR(Cad, readw(&ParmMapP->rups));
575 HostP->PhbNumP = (ushort*)RIO_PTR(Cad,RWORD(ParmMapP->phb_num_ptr)); 516 HostP->PhbNumP = (unsigned short *) RIO_PTR(Cad, readw(&ParmMapP->phb_num_ptr));
576 HostP->LinkStrP = (LPB*)RIO_PTR(Cad,RWORD(ParmMapP->link_str_ptr)); 517 HostP->LinkStrP = (struct LPB *) RIO_PTR(Cad, readw(&ParmMapP->link_str_ptr));
577 518
578 /* 519 /*
579 ** point the UnixRups at the real Rups 520 ** point the UnixRups at the real Rups
580 */ 521 */
581 for ( RupN = 0; RupN<MAX_RUP; RupN++ ) { 522 for (RupN = 0; RupN < MAX_RUP; RupN++) {
582 HostP->UnixRups[RupN].RupP = &HostP->RupP[RupN]; 523 HostP->UnixRups[RupN].RupP = &HostP->RupP[RupN];
583 HostP->UnixRups[RupN].Id = RupN+1; 524 HostP->UnixRups[RupN].Id = RupN + 1;
584 HostP->UnixRups[RupN].BaseSysPort = NO_PORT; 525 HostP->UnixRups[RupN].BaseSysPort = NO_PORT;
585 spin_lock_init(&HostP->UnixRups[RupN].RupLock); 526 spin_lock_init(&HostP->UnixRups[RupN].RupLock);
586 } 527 }
587 528
588 for ( RupN = 0; RupN<LINKS_PER_UNIT; RupN++ ) { 529 for (RupN = 0; RupN < LINKS_PER_UNIT; RupN++) {
589 HostP->UnixRups[RupN+MAX_RUP].RupP = &HostP->LinkStrP[RupN].rup; 530 HostP->UnixRups[RupN + MAX_RUP].RupP = &HostP->LinkStrP[RupN].rup;
590 HostP->UnixRups[RupN+MAX_RUP].Id = 0; 531 HostP->UnixRups[RupN + MAX_RUP].Id = 0;
591 HostP->UnixRups[RupN+MAX_RUP].BaseSysPort = NO_PORT; 532 HostP->UnixRups[RupN + MAX_RUP].BaseSysPort = NO_PORT;
592 spin_lock_init(&HostP->UnixRups[RupN+MAX_RUP].RupLock); 533 spin_lock_init(&HostP->UnixRups[RupN + MAX_RUP].RupLock);
593 } 534 }
594 535
595 /* 536 /*
596 ** point the PortP->Phbs at the real Phbs 537 ** point the PortP->Phbs at the real Phbs
597 */ 538 */
598 for ( PortN=p->RIOFirstPortsMapped; 539 for (PortN = p->RIOFirstPortsMapped; PortN < p->RIOLastPortsMapped + PORTS_PER_RTA; PortN++) {
599 PortN<p->RIOLastPortsMapped+PORTS_PER_RTA; PortN++ ) { 540 if (p->RIOPortp[PortN]->HostP == HostP) {
600 if ( p->RIOPortp[PortN]->HostP == HostP ) {
601 struct Port *PortP = p->RIOPortp[PortN]; 541 struct Port *PortP = p->RIOPortp[PortN];
602 struct PHB *PhbP; 542 struct PHB *PhbP;
603 /* int oldspl; */ 543 /* int oldspl; */
604 544
605 if ( !PortP->Mapped ) 545 if (!PortP->Mapped)
606 continue; 546 continue;
607 547
608 PhbP = &HostP->PhbP[PortP->HostPort]; 548 PhbP = &HostP->PhbP[PortP->HostPort];
@@ -610,641 +550,522 @@ register struct DownLoad *rbp;
610 550
611 PortP->PhbP = PhbP; 551 PortP->PhbP = PhbP;
612 552
613 PortP->TxAdd = (WORD *)RIO_PTR(Cad,RWORD(PhbP->tx_add)); 553 PortP->TxAdd = (u16 *) RIO_PTR(Cad, readw(&PhbP->tx_add));
614 PortP->TxStart = (WORD *)RIO_PTR(Cad,RWORD(PhbP->tx_start)); 554 PortP->TxStart = (u16 *) RIO_PTR(Cad, readw(&PhbP->tx_start));
615 PortP->TxEnd = (WORD *)RIO_PTR(Cad,RWORD(PhbP->tx_end)); 555 PortP->TxEnd = (u16 *) RIO_PTR(Cad, readw(&PhbP->tx_end));
616 PortP->RxRemove = (WORD *)RIO_PTR(Cad,RWORD(PhbP->rx_remove)); 556 PortP->RxRemove = (u16 *) RIO_PTR(Cad, readw(&PhbP->rx_remove));
617 PortP->RxStart = (WORD *)RIO_PTR(Cad,RWORD(PhbP->rx_start)); 557 PortP->RxStart = (u16 *) RIO_PTR(Cad, readw(&PhbP->rx_start));
618 PortP->RxEnd = (WORD *)RIO_PTR(Cad,RWORD(PhbP->rx_end)); 558 PortP->RxEnd = (u16 *) RIO_PTR(Cad, readw(&PhbP->rx_end));
619 559
620 rio_spin_unlock_irqrestore(&PortP->portSem, flags); 560 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
621 /* 561 /*
622 ** point the UnixRup at the base SysPort 562 ** point the UnixRup at the base SysPort
623 */ 563 */
624 if ( !(PortN % PORTS_PER_RTA) ) 564 if (!(PortN % PORTS_PER_RTA))
625 HostP->UnixRups[PortP->RupNum].BaseSysPort = PortN; 565 HostP->UnixRups[PortP->RupNum].BaseSysPort = PortN;
626 } 566 }
627 } 567 }
628 568
629 rio_dprintk (RIO_DEBUG_BOOT, "Set the card running... \n"); 569 rio_dprintk(RIO_DEBUG_BOOT, "Set the card running... \n");
630 /* 570 /*
631 ** last thing - show the world that everything is in place 571 ** last thing - show the world that everything is in place
632 */ 572 */
633 HostP->Flags &= ~RUN_STATE; 573 HostP->Flags &= ~RUN_STATE;
634 HostP->Flags |= RC_RUNNING; 574 HostP->Flags |= RC_RUNNING;
635 } 575 }
636 /* 576 /*
637 ** MPX always uses a poller. This is actually patched into the system 577 ** MPX always uses a poller. This is actually patched into the system
638 ** configuration and called directly from each clock tick. 578 ** configuration and called directly from each clock tick.
639 ** 579 **
640 */ 580 */
641 p->RIOPolling = 1; 581 p->RIOPolling = 1;
642 582
643 p->RIOSystemUp++; 583 p->RIOSystemUp++;
644 584
645 rio_dprintk (RIO_DEBUG_BOOT, "Done everything %x\n", HostP->Ivec); 585 rio_dprintk(RIO_DEBUG_BOOT, "Done everything %x\n", HostP->Ivec);
646 func_exit (); 586 func_exit();
647 return 0; 587 return 0;
648} 588}
649 589
650 590
651 591
652/* 592/**
653** Boot an RTA. If we have successfully processed this boot, then 593 * RIOBootRup - Boot an RTA
654** return 1. If we havent, then return 0. 594 * @p: rio we are working with
655*/ 595 * @Rup: Rup number
656int 596 * @HostP: host object
657RIOBootRup( p, Rup, HostP, PacketP) 597 * @PacketP: packet to use
658struct rio_info * p; 598 *
659uint Rup; 599 * If we have successfully processed this boot, then
660struct Host *HostP; 600 * return 1. If we havent, then return 0.
661struct PKT *PacketP; 601 */
602
603int RIOBootRup(struct rio_info *p, unsigned int Rup, struct Host *HostP, struct PKT *PacketP)
662{ 604{
663 struct PktCmd *PktCmdP = (struct PktCmd *)PacketP->data; 605 struct PktCmd *PktCmdP = (struct PktCmd *) PacketP->data;
664 struct PktCmd_M *PktReplyP; 606 struct PktCmd_M *PktReplyP;
665 struct CmdBlk *CmdBlkP; 607 struct CmdBlk *CmdBlkP;
666 uint sequence; 608 unsigned int sequence;
667 609
668 /* 610 /*
669 ** If we haven't been told what to boot, we can't boot it. 611 ** If we haven't been told what to boot, we can't boot it.
670 */ 612 */
671 if ( p->RIONumBootPkts == 0 ) { 613 if (p->RIONumBootPkts == 0) {
672 rio_dprintk (RIO_DEBUG_BOOT, "No RTA code to download yet\n"); 614 rio_dprintk(RIO_DEBUG_BOOT, "No RTA code to download yet\n");
673 return 0; 615 return 0;
674 } 616 }
675 617
676 /* rio_dprint(RIO_DEBUG_BOOT, NULL,DBG_BOOT,"Incoming command packet\n"); */
677 /* ShowPacket( DBG_BOOT, PacketP ); */
678
679 /* 618 /*
680 ** Special case of boot completed - if we get one of these then we 619 ** Special case of boot completed - if we get one of these then we
681 ** don't need a command block. For all other cases we do, so handle 620 ** don't need a command block. For all other cases we do, so handle
682 ** this first and then get a command block, then handle every other 621 ** this first and then get a command block, then handle every other
683 ** case, relinquishing the command block if disaster strikes! 622 ** case, relinquishing the command block if disaster strikes!
684 */ 623 */
685 if ( (RBYTE(PacketP->len) & PKT_CMD_BIT) && 624 if ((readb(&PacketP->len) & PKT_CMD_BIT) && (readb(&PktCmdP->Command) == BOOT_COMPLETED))
686 (RBYTE(PktCmdP->Command)==BOOT_COMPLETED) ) 625 return RIOBootComplete(p, HostP, Rup, PktCmdP);
687 return RIOBootComplete(p, HostP, Rup, PktCmdP );
688 626
689 /* 627 /*
690 ** try to unhook a command block from the command free list. 628 ** Try to allocate a command block. This is in kernel space
691 */ 629 */
692 if ( !(CmdBlkP = RIOGetCmdBlk()) ) { 630 if (!(CmdBlkP = RIOGetCmdBlk())) {
693 rio_dprintk (RIO_DEBUG_BOOT, "No command blocks to boot RTA! come back later.\n"); 631 rio_dprintk(RIO_DEBUG_BOOT, "No command blocks to boot RTA! come back later.\n");
694 return 0; 632 return 0;
695 } 633 }
696 634
697 /* 635 /*
698 ** Fill in the default info on the command block 636 ** Fill in the default info on the command block
699 */ 637 */
700 CmdBlkP->Packet.dest_unit = Rup < (ushort)MAX_RUP ? Rup : 0; 638 CmdBlkP->Packet.dest_unit = Rup < (unsigned short) MAX_RUP ? Rup : 0;
701 CmdBlkP->Packet.dest_port = BOOT_RUP; 639 CmdBlkP->Packet.dest_port = BOOT_RUP;
702 CmdBlkP->Packet.src_unit = 0; 640 CmdBlkP->Packet.src_unit = 0;
703 CmdBlkP->Packet.src_port = BOOT_RUP; 641 CmdBlkP->Packet.src_port = BOOT_RUP;
704 642
705 CmdBlkP->PreFuncP = CmdBlkP->PostFuncP = NULL; 643 CmdBlkP->PreFuncP = CmdBlkP->PostFuncP = NULL;
706 PktReplyP = (struct PktCmd_M *)CmdBlkP->Packet.data; 644 PktReplyP = (struct PktCmd_M *) CmdBlkP->Packet.data;
707 645
708 /* 646 /*
709 ** process COMMANDS on the boot rup! 647 ** process COMMANDS on the boot rup!
710 */ 648 */
711 if ( RBYTE(PacketP->len) & PKT_CMD_BIT ) { 649 if (readb(&PacketP->len) & PKT_CMD_BIT) {
712 /* 650 /*
713 ** We only expect one type of command - a BOOT_REQUEST! 651 ** We only expect one type of command - a BOOT_REQUEST!
714 */ 652 */
715 if ( RBYTE(PktCmdP->Command) != BOOT_REQUEST ) { 653 if (readb(&PktCmdP->Command) != BOOT_REQUEST) {
716 rio_dprintk (RIO_DEBUG_BOOT, "Unexpected command %d on BOOT RUP %d of host %d\n", 654 rio_dprintk(RIO_DEBUG_BOOT, "Unexpected command %d on BOOT RUP %d of host %Zd\n", readb(&PktCmdP->Command), Rup, HostP - p->RIOHosts);
717 PktCmdP->Command,Rup,HostP-p->RIOHosts); 655 RIOFreeCmdBlk(CmdBlkP);
718 ShowPacket( DBG_BOOT, PacketP );
719 RIOFreeCmdBlk( CmdBlkP );
720 return 1; 656 return 1;
721 } 657 }
722 658
723 /* 659 /*
724 ** Build a Boot Sequence command block 660 ** Build a Boot Sequence command block
725 ** 661 **
726 ** 02.03.1999 ARG - ESIL 0820 fix 662 ** We no longer need to use "Boot Mode", we'll always allow
727 ** We no longer need to use "Boot Mode", we'll always allow 663 ** boot requests - the boot will not complete if the device
728 ** boot requests - the boot will not complete if the device 664 ** appears in the bindings table.
729 ** appears in the bindings table. 665 **
730 ** So, this conditional is not required ... 666 ** We'll just (always) set the command field in packet reply
731 ** 667 ** to allow an attempted boot sequence :
732 if (p->RIOBootMode == RC_BOOT_NONE) 668 */
733 **
734 ** If the system is in slave mode, and a boot request is
735 ** received, set command to BOOT_ABORT so that the boot
736 ** will not complete.
737 **
738 PktReplyP->Command = BOOT_ABORT;
739 else
740 **
741 ** We'll just (always) set the command field in packet reply
742 ** to allow an attempted boot sequence :
743 */
744 PktReplyP->Command = BOOT_SEQUENCE; 669 PktReplyP->Command = BOOT_SEQUENCE;
745 670
746 PktReplyP->BootSequence.NumPackets = p->RIONumBootPkts; 671 PktReplyP->BootSequence.NumPackets = p->RIONumBootPkts;
747 PktReplyP->BootSequence.LoadBase = p->RIOConf.RtaLoadBase; 672 PktReplyP->BootSequence.LoadBase = p->RIOConf.RtaLoadBase;
748 PktReplyP->BootSequence.CodeSize = p->RIOBootCount; 673 PktReplyP->BootSequence.CodeSize = p->RIOBootCount;
749 674
750 CmdBlkP->Packet.len = BOOT_SEQUENCE_LEN | PKT_CMD_BIT; 675 CmdBlkP->Packet.len = BOOT_SEQUENCE_LEN | PKT_CMD_BIT;
751 676
752 bcopy("BOOT",(void *)&CmdBlkP->Packet.data[BOOT_SEQUENCE_LEN],4); 677 memcpy((void *) &CmdBlkP->Packet.data[BOOT_SEQUENCE_LEN], "BOOT", 4);
753 678
754 rio_dprintk (RIO_DEBUG_BOOT, "Boot RTA on Host %d Rup %d - %d (0x%x) packets to 0x%x\n", 679 rio_dprintk(RIO_DEBUG_BOOT, "Boot RTA on Host %Zd Rup %d - %d (0x%x) packets to 0x%x\n", HostP - p->RIOHosts, Rup, p->RIONumBootPkts, p->RIONumBootPkts, p->RIOConf.RtaLoadBase);
755 HostP-p->RIOHosts, Rup, p->RIONumBootPkts, p->RIONumBootPkts,
756 p->RIOConf.RtaLoadBase);
757 680
758 /* 681 /*
759 ** If this host is in slave mode, send the RTA an invalid boot 682 ** If this host is in slave mode, send the RTA an invalid boot
760 ** sequence command block to force it to kill the boot. We wait 683 ** sequence command block to force it to kill the boot. We wait
761 ** for half a second before sending this packet to prevent the RTA 684 ** for half a second before sending this packet to prevent the RTA
762 ** attempting to boot too often. The master host should then grab 685 ** attempting to boot too often. The master host should then grab
763 ** the RTA and make it its own. 686 ** the RTA and make it its own.
764 */ 687 */
765 p->RIOBooting++; 688 p->RIOBooting++;
766 RIOQueueCmdBlk( HostP, Rup, CmdBlkP ); 689 RIOQueueCmdBlk(HostP, Rup, CmdBlkP);
767 return 1; 690 return 1;
768 } 691 }
769 692
770 /* 693 /*
771 ** It is a request for boot data. 694 ** It is a request for boot data.
772 */ 695 */
773 sequence = RWORD(PktCmdP->Sequence); 696 sequence = readw(&PktCmdP->Sequence);
774 697
775 rio_dprintk (RIO_DEBUG_BOOT, "Boot block %d on Host %d Rup%d\n",sequence,HostP-p->RIOHosts,Rup); 698 rio_dprintk(RIO_DEBUG_BOOT, "Boot block %d on Host %Zd Rup%d\n", sequence, HostP - p->RIOHosts, Rup);
776 699
777 if ( sequence >= p->RIONumBootPkts ) { 700 if (sequence >= p->RIONumBootPkts) {
778 rio_dprintk (RIO_DEBUG_BOOT, "Got a request for packet %d, max is %d\n", sequence, 701 rio_dprintk(RIO_DEBUG_BOOT, "Got a request for packet %d, max is %d\n", sequence, p->RIONumBootPkts);
779 p->RIONumBootPkts);
780 ShowPacket( DBG_BOOT, PacketP );
781 } 702 }
782 703
783 PktReplyP->Sequence = sequence; 704 PktReplyP->Sequence = sequence;
784 705 memcpy(PktReplyP->BootData, p->RIOBootPackets[p->RIONumBootPkts - sequence - 1], RTA_BOOT_DATA_SIZE);
785 bcopy( p->RIOBootPackets[ p->RIONumBootPkts - sequence - 1 ],
786 PktReplyP->BootData, RTA_BOOT_DATA_SIZE );
787
788 CmdBlkP->Packet.len = PKT_MAX_DATA_LEN; 706 CmdBlkP->Packet.len = PKT_MAX_DATA_LEN;
789 ShowPacket( DBG_BOOT, &CmdBlkP->Packet ); 707 RIOQueueCmdBlk(HostP, Rup, CmdBlkP);
790 RIOQueueCmdBlk( HostP, Rup, CmdBlkP );
791 return 1; 708 return 1;
792} 709}
793 710
794/* 711/**
795** This function is called when an RTA been booted. 712 * RIOBootComplete - RTA boot is done
796** If booted by a host, HostP->HostUniqueNum is the booting host. 713 * @p: RIO we are working with
797** If booted by an RTA, HostP->Mapping[Rup].RtaUniqueNum is the booting RTA. 714 * @HostP: Host structure
798** RtaUniq is the booted RTA. 715 * @Rup: RUP being used
799*/ 716 * @PktCmdP: Packet command that was used
800static int RIOBootComplete( struct rio_info *p, struct Host *HostP, uint Rup, struct PktCmd *PktCmdP ) 717 *
718 * This function is called when an RTA been booted.
719 * If booted by a host, HostP->HostUniqueNum is the booting host.
720 * If booted by an RTA, HostP->Mapping[Rup].RtaUniqueNum is the booting RTA.
721 * RtaUniq is the booted RTA.
722 */
723
724static int RIOBootComplete(struct rio_info *p, struct Host *HostP, unsigned int Rup, struct PktCmd *PktCmdP)
801{ 725{
802 struct Map *MapP = NULL; 726 struct Map *MapP = NULL;
803 struct Map *MapP2 = NULL; 727 struct Map *MapP2 = NULL;
804 int Flag; 728 int Flag;
805 int found; 729 int found;
806 int host, rta; 730 int host, rta;
807 int EmptySlot = -1; 731 int EmptySlot = -1;
808 int entry, entry2; 732 int entry, entry2;
809 char *MyType, *MyName; 733 char *MyType, *MyName;
810 uint MyLink; 734 unsigned int MyLink;
811 ushort RtaType; 735 unsigned short RtaType;
812 uint RtaUniq = (RBYTE(PktCmdP->UniqNum[0])) + 736 u32 RtaUniq = (readb(&PktCmdP->UniqNum[0])) + (readb(&PktCmdP->UniqNum[1]) << 8) + (readb(&PktCmdP->UniqNum[2]) << 16) + (readb(&PktCmdP->UniqNum[3]) << 24);
813 (RBYTE(PktCmdP->UniqNum[1]) << 8) + 737
814 (RBYTE(PktCmdP->UniqNum[2]) << 16) +
815 (RBYTE(PktCmdP->UniqNum[3]) << 24);
816
817 /* Was RIOBooting-- . That's bad. If an RTA sends two of them, the
818 driver will never think that the RTA has booted... -- REW */
819 p->RIOBooting = 0; 738 p->RIOBooting = 0;
820 739
821 rio_dprintk (RIO_DEBUG_BOOT, "RTA Boot completed - BootInProgress now %d\n", p->RIOBooting); 740 rio_dprintk(RIO_DEBUG_BOOT, "RTA Boot completed - BootInProgress now %d\n", p->RIOBooting);
822 741
823 /* 742 /*
824 ** Determine type of unit (16/8 port RTA). 743 ** Determine type of unit (16/8 port RTA).
825 */ 744 */
745
826 RtaType = GetUnitType(RtaUniq); 746 RtaType = GetUnitType(RtaUniq);
827 if ( Rup >= (ushort)MAX_RUP ) { 747 if (Rup >= (unsigned short) MAX_RUP)
828 rio_dprintk (RIO_DEBUG_BOOT, "RIO: Host %s has booted an RTA(%d) on link %c\n", 748 rio_dprintk(RIO_DEBUG_BOOT, "RIO: Host %s has booted an RTA(%d) on link %c\n", HostP->Name, 8 * RtaType, readb(&PktCmdP->LinkNum) + 'A');
829 HostP->Name, 8 * RtaType, RBYTE(PktCmdP->LinkNum)+'A'); 749 else
830 } else { 750 rio_dprintk(RIO_DEBUG_BOOT, "RIO: RTA %s has booted an RTA(%d) on link %c\n", HostP->Mapping[Rup].Name, 8 * RtaType, readb(&PktCmdP->LinkNum) + 'A');
831 rio_dprintk (RIO_DEBUG_BOOT, "RIO: RTA %s has booted an RTA(%d) on link %c\n",
832 HostP->Mapping[Rup].Name, 8 * RtaType,
833 RBYTE(PktCmdP->LinkNum)+'A');
834 }
835 751
836 rio_dprintk (RIO_DEBUG_BOOT, "UniqNum is 0x%x\n",RtaUniq); 752 rio_dprintk(RIO_DEBUG_BOOT, "UniqNum is 0x%x\n", RtaUniq);
837 753
838 if ( ( RtaUniq == 0x00000000 ) || ( RtaUniq == 0xffffffff ) ) 754 if (RtaUniq == 0x00000000 || RtaUniq == 0xffffffff) {
839 { 755 rio_dprintk(RIO_DEBUG_BOOT, "Illegal RTA Uniq Number\n");
840 rio_dprintk (RIO_DEBUG_BOOT, "Illegal RTA Uniq Number\n"); 756 return 1;
841 return TRUE;
842 } 757 }
843 758
844 /* 759 /*
845 ** If this RTA has just booted an RTA which doesn't belong to this 760 ** If this RTA has just booted an RTA which doesn't belong to this
846 ** system, or the system is in slave mode, do not attempt to create 761 ** system, or the system is in slave mode, do not attempt to create
847 ** a new table entry for it. 762 ** a new table entry for it.
848 */ 763 */
849 if (!RIOBootOk(p, HostP, RtaUniq)) 764
850 { 765 if (!RIOBootOk(p, HostP, RtaUniq)) {
851 MyLink = RBYTE(PktCmdP->LinkNum); 766 MyLink = readb(&PktCmdP->LinkNum);
852 if (Rup < (ushort) MAX_RUP) 767 if (Rup < (unsigned short) MAX_RUP) {
853 { 768 /*
854 /* 769 ** RtaUniq was clone booted (by this RTA). Instruct this RTA
855 ** RtaUniq was clone booted (by this RTA). Instruct this RTA 770 ** to hold off further attempts to boot on this link for 30
856 ** to hold off further attempts to boot on this link for 30 771 ** seconds.
857 ** seconds. 772 */
858 */ 773 if (RIOSuspendBootRta(HostP, HostP->Mapping[Rup].ID, MyLink)) {
859 if (RIOSuspendBootRta(HostP, HostP->Mapping[Rup].ID, MyLink)) 774 rio_dprintk(RIO_DEBUG_BOOT, "RTA failed to suspend booting on link %c\n", 'A' + MyLink);
860 { 775 }
861 rio_dprintk (RIO_DEBUG_BOOT, "RTA failed to suspend booting on link %c\n", 776 } else
862 'A' + MyLink); 777 /*
863 } 778 ** RtaUniq was booted by this host. Set the booting link
864 } 779 ** to hold off for 30 seconds to give another unit a
865 else 780 ** chance to boot it.
866 { 781 */
867 /* 782 writew(30, &HostP->LinkStrP[MyLink].WaitNoBoot);
868 ** RtaUniq was booted by this host. Set the booting link 783 rio_dprintk(RIO_DEBUG_BOOT, "RTA %x not owned - suspend booting down link %c on unit %x\n", RtaUniq, 'A' + MyLink, HostP->Mapping[Rup].RtaUniqueNum);
869 ** to hold off for 30 seconds to give another unit a 784 return 1;
870 ** chance to boot it.
871 */
872 WWORD(HostP->LinkStrP[MyLink].WaitNoBoot, 30);
873 }
874 rio_dprintk (RIO_DEBUG_BOOT, "RTA %x not owned - suspend booting down link %c on unit %x\n",
875 RtaUniq, 'A' + MyLink, HostP->Mapping[Rup].RtaUniqueNum);
876 return TRUE;
877 } 785 }
878 786
879 /* 787 /*
880 ** Check for a SLOT_IN_USE entry for this RTA attached to the 788 ** Check for a SLOT_IN_USE entry for this RTA attached to the
881 ** current host card in the driver table. 789 ** current host card in the driver table.
882 ** 790 **
883 ** If it exists, make a note that we have booted it. Other parts of 791 ** If it exists, make a note that we have booted it. Other parts of
884 ** the driver are interested in this information at a later date, 792 ** the driver are interested in this information at a later date,
885 ** in particular when the booting RTA asks for an ID for this unit, 793 ** in particular when the booting RTA asks for an ID for this unit,
886 ** we must have set the BOOTED flag, and the NEWBOOT flag is used 794 ** we must have set the BOOTED flag, and the NEWBOOT flag is used
887 ** to force an open on any ports that where previously open on this 795 ** to force an open on any ports that where previously open on this
888 ** unit. 796 ** unit.
889 */ 797 */
890 for ( entry=0; entry<MAX_RUP; entry++ ) 798 for (entry = 0; entry < MAX_RUP; entry++) {
891 { 799 unsigned int sysport;
892 uint sysport; 800
893 801 if ((HostP->Mapping[entry].Flags & SLOT_IN_USE) && (HostP->Mapping[entry].RtaUniqueNum == RtaUniq)) {
894 if ((HostP->Mapping[entry].Flags & SLOT_IN_USE) && 802 HostP->Mapping[entry].Flags |= RTA_BOOTED | RTA_NEWBOOT;
895 (HostP->Mapping[entry].RtaUniqueNum==RtaUniq)) 803 if ((sysport = HostP->Mapping[entry].SysPort) != NO_PORT) {
896 { 804 if (sysport < p->RIOFirstPortsBooted)
897 HostP->Mapping[entry].Flags |= RTA_BOOTED|RTA_NEWBOOT; 805 p->RIOFirstPortsBooted = sysport;
898#ifdef NEED_TO_FIX 806 if (sysport > p->RIOLastPortsBooted)
899 RIO_SV_BROADCAST(HostP->svFlags[entry]); 807 p->RIOLastPortsBooted = sysport;
900#endif 808 /*
901 if ( (sysport=HostP->Mapping[entry].SysPort) != NO_PORT ) 809 ** For a 16 port RTA, check the second bank of 8 ports
902 { 810 */
903 if ( sysport < p->RIOFirstPortsBooted ) 811 if (RtaType == TYPE_RTA16) {
904 p->RIOFirstPortsBooted = sysport; 812 entry2 = HostP->Mapping[entry].ID2 - 1;
905 if ( sysport > p->RIOLastPortsBooted ) 813 HostP->Mapping[entry2].Flags |= RTA_BOOTED | RTA_NEWBOOT;
906 p->RIOLastPortsBooted = sysport; 814 sysport = HostP->Mapping[entry2].SysPort;
907 /* 815 if (sysport < p->RIOFirstPortsBooted)
908 ** For a 16 port RTA, check the second bank of 8 ports 816 p->RIOFirstPortsBooted = sysport;
909 */ 817 if (sysport > p->RIOLastPortsBooted)
910 if (RtaType == TYPE_RTA16) 818 p->RIOLastPortsBooted = sysport;
911 { 819 }
912 entry2 = HostP->Mapping[entry].ID2 - 1; 820 }
913 HostP->Mapping[entry2].Flags |= RTA_BOOTED|RTA_NEWBOOT; 821 if (RtaType == TYPE_RTA16)
914#ifdef NEED_TO_FIX 822 rio_dprintk(RIO_DEBUG_BOOT, "RTA will be given IDs %d+%d\n", entry + 1, entry2 + 1);
915 RIO_SV_BROADCAST(HostP->svFlags[entry2]); 823 else
916#endif 824 rio_dprintk(RIO_DEBUG_BOOT, "RTA will be given ID %d\n", entry + 1);
917 sysport = HostP->Mapping[entry2].SysPort; 825 return 1;
918 if ( sysport < p->RIOFirstPortsBooted )
919 p->RIOFirstPortsBooted = sysport;
920 if ( sysport > p->RIOLastPortsBooted )
921 p->RIOLastPortsBooted = sysport;
922 }
923 }
924 if (RtaType == TYPE_RTA16) {
925 rio_dprintk (RIO_DEBUG_BOOT, "RTA will be given IDs %d+%d\n",
926 entry+1, entry2+1);
927 } else {
928 rio_dprintk (RIO_DEBUG_BOOT, "RTA will be given ID %d\n",entry+1);
929 } 826 }
930 return TRUE;
931 }
932 } 827 }
933 828
934 rio_dprintk (RIO_DEBUG_BOOT, "RTA not configured for this host\n"); 829 rio_dprintk(RIO_DEBUG_BOOT, "RTA not configured for this host\n");
935 830
936 if ( Rup >= (ushort)MAX_RUP ) 831 if (Rup >= (unsigned short) MAX_RUP) {
937 { 832 /*
938 /* 833 ** It was a host that did the booting
939 ** It was a host that did the booting 834 */
940 */ 835 MyType = "Host";
941 MyType = "Host"; 836 MyName = HostP->Name;
942 MyName = HostP->Name; 837 } else {
943 } 838 /*
944 else 839 ** It was an RTA that did the booting
945 { 840 */
946 /* 841 MyType = "RTA";
947 ** It was an RTA that did the booting 842 MyName = HostP->Mapping[Rup].Name;
948 */
949 MyType = "RTA";
950 MyName = HostP->Mapping[Rup].Name;
951 } 843 }
952 MyLink = RBYTE(PktCmdP->LinkNum); 844 MyLink = readb(&PktCmdP->LinkNum);
953 845
954 /* 846 /*
955 ** There is no SLOT_IN_USE entry for this RTA attached to the current 847 ** There is no SLOT_IN_USE entry for this RTA attached to the current
956 ** host card in the driver table. 848 ** host card in the driver table.
957 ** 849 **
958 ** Check for a SLOT_TENTATIVE entry for this RTA attached to the 850 ** Check for a SLOT_TENTATIVE entry for this RTA attached to the
959 ** current host card in the driver table. 851 ** current host card in the driver table.
960 ** 852 **
961 ** If we find one, then we re-use that slot. 853 ** If we find one, then we re-use that slot.
962 */ 854 */
963 for ( entry=0; entry<MAX_RUP; entry++ ) 855 for (entry = 0; entry < MAX_RUP; entry++) {
964 { 856 if ((HostP->Mapping[entry].Flags & SLOT_TENTATIVE) && (HostP->Mapping[entry].RtaUniqueNum == RtaUniq)) {
965 if ( (HostP->Mapping[entry].Flags & SLOT_TENTATIVE) && 857 if (RtaType == TYPE_RTA16) {
966 (HostP->Mapping[entry].RtaUniqueNum == RtaUniq) ) 858 entry2 = HostP->Mapping[entry].ID2 - 1;
967 { 859 if ((HostP->Mapping[entry2].Flags & SLOT_TENTATIVE) && (HostP->Mapping[entry2].RtaUniqueNum == RtaUniq))
968 if (RtaType == TYPE_RTA16) 860 rio_dprintk(RIO_DEBUG_BOOT, "Found previous tentative slots (%d+%d)\n", entry, entry2);
969 { 861 else
970 entry2 = HostP->Mapping[entry].ID2 - 1; 862 continue;
971 if ( (HostP->Mapping[entry2].Flags & SLOT_TENTATIVE) && 863 } else
972 (HostP->Mapping[entry2].RtaUniqueNum == RtaUniq) ) 864 rio_dprintk(RIO_DEBUG_BOOT, "Found previous tentative slot (%d)\n", entry);
973 rio_dprintk (RIO_DEBUG_BOOT, "Found previous tentative slots (%d+%d)\n", 865 if (!p->RIONoMessage)
974 entry, entry2); 866 printk("RTA connected to %s '%s' (%c) not configured.\n", MyType, MyName, MyLink + 'A');
975 else 867 return 1;
976 continue;
977 } 868 }
978 else
979 rio_dprintk (RIO_DEBUG_BOOT, "Found previous tentative slot (%d)\n",entry);
980 if (! p->RIONoMessage)
981 cprintf("RTA connected to %s '%s' (%c) not configured.\n",MyType,MyName,MyLink+'A');
982 return TRUE;
983 }
984 } 869 }
985 870
986 /* 871 /*
987 ** There is no SLOT_IN_USE or SLOT_TENTATIVE entry for this RTA 872 ** There is no SLOT_IN_USE or SLOT_TENTATIVE entry for this RTA
988 ** attached to the current host card in the driver table. 873 ** attached to the current host card in the driver table.
989 ** 874 **
990 ** Check if there is a SLOT_IN_USE or SLOT_TENTATIVE entry on another 875 ** Check if there is a SLOT_IN_USE or SLOT_TENTATIVE entry on another
991 ** host for this RTA in the driver table. 876 ** host for this RTA in the driver table.
992 ** 877 **
993 ** For a SLOT_IN_USE entry on another host, we need to delete the RTA 878 ** For a SLOT_IN_USE entry on another host, we need to delete the RTA
994 ** entry from the other host and add it to this host (using some of 879 ** entry from the other host and add it to this host (using some of
995 ** the functions from table.c which do this). 880 ** the functions from table.c which do this).
996 ** For a SLOT_TENTATIVE entry on another host, we must cope with the 881 ** For a SLOT_TENTATIVE entry on another host, we must cope with the
997 ** following scenario: 882 ** following scenario:
998 ** 883 **
999 ** + Plug 8 port RTA into host A. (This creates SLOT_TENTATIVE entry 884 ** + Plug 8 port RTA into host A. (This creates SLOT_TENTATIVE entry
1000 ** in table) 885 ** in table)
1001 ** + Unplug RTA and plug into host B. (We now have 2 SLOT_TENTATIVE 886 ** + Unplug RTA and plug into host B. (We now have 2 SLOT_TENTATIVE
1002 ** entries) 887 ** entries)
1003 ** + Configure RTA on host B. (This slot now becomes SLOT_IN_USE) 888 ** + Configure RTA on host B. (This slot now becomes SLOT_IN_USE)
1004 ** + Unplug RTA and plug back into host A. 889 ** + Unplug RTA and plug back into host A.
1005 ** + Configure RTA on host A. We now have the same RTA configured 890 ** + Configure RTA on host A. We now have the same RTA configured
1006 ** with different ports on two different hosts. 891 ** with different ports on two different hosts.
1007 */ 892 */
1008 rio_dprintk (RIO_DEBUG_BOOT, "Have we seen RTA %x before?\n", RtaUniq ); 893 rio_dprintk(RIO_DEBUG_BOOT, "Have we seen RTA %x before?\n", RtaUniq);
1009 found = 0; 894 found = 0;
1010 Flag = 0; /* Convince the compiler this variable is initialized */ 895 Flag = 0; /* Convince the compiler this variable is initialized */
1011 for ( host = 0; !found && (host < p->RIONumHosts); host++ ) 896 for (host = 0; !found && (host < p->RIONumHosts); host++) {
1012 { 897 for (rta = 0; rta < MAX_RUP; rta++) {
1013 for ( rta=0; rta<MAX_RUP; rta++ ) 898 if ((p->RIOHosts[host].Mapping[rta].Flags & (SLOT_IN_USE | SLOT_TENTATIVE)) && (p->RIOHosts[host].Mapping[rta].RtaUniqueNum == RtaUniq)) {
1014 { 899 Flag = p->RIOHosts[host].Mapping[rta].Flags;
1015 if ((p->RIOHosts[host].Mapping[rta].Flags & 900 MapP = &p->RIOHosts[host].Mapping[rta];
1016 (SLOT_IN_USE | SLOT_TENTATIVE)) && 901 if (RtaType == TYPE_RTA16) {
1017 (p->RIOHosts[host].Mapping[rta].RtaUniqueNum==RtaUniq)) 902 MapP2 = &p->RIOHosts[host].Mapping[MapP->ID2 - 1];
1018 { 903 rio_dprintk(RIO_DEBUG_BOOT, "This RTA is units %d+%d from host %s\n", rta + 1, MapP->ID2, p->RIOHosts[host].Name);
1019 Flag = p->RIOHosts[host].Mapping[rta].Flags; 904 } else
1020 MapP = &p->RIOHosts[host].Mapping[rta]; 905 rio_dprintk(RIO_DEBUG_BOOT, "This RTA is unit %d from host %s\n", rta + 1, p->RIOHosts[host].Name);
1021 if (RtaType == TYPE_RTA16) 906 found = 1;
1022 { 907 break;
1023 MapP2 = &p->RIOHosts[host].Mapping[MapP->ID2 - 1]; 908 }
1024 rio_dprintk (RIO_DEBUG_BOOT, "This RTA is units %d+%d from host %s\n",
1025 rta+1, MapP->ID2, p->RIOHosts[host].Name);
1026 }
1027 else
1028 rio_dprintk (RIO_DEBUG_BOOT, "This RTA is unit %d from host %s\n",
1029 rta+1, p->RIOHosts[host].Name);
1030 found = 1;
1031 break;
1032 } 909 }
1033 }
1034 } 910 }
1035 911
1036 /* 912 /*
1037 ** There is no SLOT_IN_USE or SLOT_TENTATIVE entry for this RTA 913 ** There is no SLOT_IN_USE or SLOT_TENTATIVE entry for this RTA
1038 ** attached to the current host card in the driver table. 914 ** attached to the current host card in the driver table.
1039 ** 915 **
1040 ** If we have not found a SLOT_IN_USE or SLOT_TENTATIVE entry on 916 ** If we have not found a SLOT_IN_USE or SLOT_TENTATIVE entry on
1041 ** another host for this RTA in the driver table... 917 ** another host for this RTA in the driver table...
1042 ** 918 **
1043 ** Check for a SLOT_IN_USE entry for this RTA in the config table. 919 ** Check for a SLOT_IN_USE entry for this RTA in the config table.
1044 */ 920 */
1045 if ( !MapP ) 921 if (!MapP) {
1046 { 922 rio_dprintk(RIO_DEBUG_BOOT, "Look for RTA %x in RIOSavedTable\n", RtaUniq);
1047 rio_dprintk (RIO_DEBUG_BOOT, "Look for RTA %x in RIOSavedTable\n",RtaUniq); 923 for (rta = 0; rta < TOTAL_MAP_ENTRIES; rta++) {
1048 for ( rta=0; rta < TOTAL_MAP_ENTRIES; rta++ ) 924 rio_dprintk(RIO_DEBUG_BOOT, "Check table entry %d (%x)", rta, p->RIOSavedTable[rta].RtaUniqueNum);
1049 { 925
1050 rio_dprintk (RIO_DEBUG_BOOT, "Check table entry %d (%x)", 926 if ((p->RIOSavedTable[rta].Flags & SLOT_IN_USE) && (p->RIOSavedTable[rta].RtaUniqueNum == RtaUniq)) {
1051 rta, 927 MapP = &p->RIOSavedTable[rta];
1052 p->RIOSavedTable[rta].RtaUniqueNum); 928 Flag = p->RIOSavedTable[rta].Flags;
1053 929 if (RtaType == TYPE_RTA16) {
1054 if ( (p->RIOSavedTable[rta].Flags & SLOT_IN_USE) && 930 for (entry2 = rta + 1; entry2 < TOTAL_MAP_ENTRIES; entry2++) {
1055 (p->RIOSavedTable[rta].RtaUniqueNum == RtaUniq) ) 931 if (p->RIOSavedTable[entry2].RtaUniqueNum == RtaUniq)
1056 { 932 break;
1057 MapP = &p->RIOSavedTable[rta]; 933 }
1058 Flag = p->RIOSavedTable[rta].Flags; 934 MapP2 = &p->RIOSavedTable[entry2];
1059 if (RtaType == TYPE_RTA16) 935 rio_dprintk(RIO_DEBUG_BOOT, "This RTA is from table entries %d+%d\n", rta, entry2);
1060 { 936 } else
1061 for (entry2 = rta + 1; entry2 < TOTAL_MAP_ENTRIES; 937 rio_dprintk(RIO_DEBUG_BOOT, "This RTA is from table entry %d\n", rta);
1062 entry2++) 938 break;
1063 { 939 }
1064 if (p->RIOSavedTable[entry2].RtaUniqueNum == RtaUniq)
1065 break;
1066 }
1067 MapP2 = &p->RIOSavedTable[entry2];
1068 rio_dprintk (RIO_DEBUG_BOOT, "This RTA is from table entries %d+%d\n",
1069 rta, entry2);
1070 }
1071 else
1072 rio_dprintk (RIO_DEBUG_BOOT, "This RTA is from table entry %d\n", rta);
1073 break;
1074 } 940 }
1075 }
1076 } 941 }
1077 942
1078 /* 943 /*
1079 ** There is no SLOT_IN_USE or SLOT_TENTATIVE entry for this RTA 944 ** There is no SLOT_IN_USE or SLOT_TENTATIVE entry for this RTA
1080 ** attached to the current host card in the driver table. 945 ** attached to the current host card in the driver table.
1081 ** 946 **
1082 ** We may have found a SLOT_IN_USE entry on another host for this 947 ** We may have found a SLOT_IN_USE entry on another host for this
1083 ** RTA in the config table, or a SLOT_IN_USE or SLOT_TENTATIVE entry 948 ** RTA in the config table, or a SLOT_IN_USE or SLOT_TENTATIVE entry
1084 ** on another host for this RTA in the driver table. 949 ** on another host for this RTA in the driver table.
1085 ** 950 **
1086 ** Check the driver table for room to fit this newly discovered RTA. 951 ** Check the driver table for room to fit this newly discovered RTA.
1087 ** RIOFindFreeID() first looks for free slots and if it does not 952 ** RIOFindFreeID() first looks for free slots and if it does not
1088 ** find any free slots it will then attempt to oust any 953 ** find any free slots it will then attempt to oust any
1089 ** tentative entry in the table. 954 ** tentative entry in the table.
1090 */ 955 */
1091 EmptySlot = 1; 956 EmptySlot = 1;
1092 if (RtaType == TYPE_RTA16) 957 if (RtaType == TYPE_RTA16) {
1093 { 958 if (RIOFindFreeID(p, HostP, &entry, &entry2) == 0) {
1094 if (RIOFindFreeID(p, HostP, &entry, &entry2) == 0) 959 RIODefaultName(p, HostP, entry);
1095 { 960 rio_fill_host_slot(entry, entry2, RtaUniq, HostP);
1096 RIODefaultName(p, HostP, entry); 961 EmptySlot = 0;
1097 FillSlot(entry, entry2, RtaUniq, HostP); 962 }
1098 EmptySlot = 0; 963 } else {
1099 } 964 if (RIOFindFreeID(p, HostP, &entry, NULL) == 0) {
1100 } 965 RIODefaultName(p, HostP, entry);
1101 else 966 rio_fill_host_slot(entry, 0, RtaUniq, HostP);
1102 { 967 EmptySlot = 0;
1103 if (RIOFindFreeID(p, HostP, &entry, NULL) == 0) 968 }
1104 {
1105 RIODefaultName(p, HostP, entry);
1106 FillSlot(entry, 0, RtaUniq, HostP);
1107 EmptySlot = 0;
1108 }
1109 } 969 }
1110 970
1111 /* 971 /*
1112 ** There is no SLOT_IN_USE or SLOT_TENTATIVE entry for this RTA 972 ** There is no SLOT_IN_USE or SLOT_TENTATIVE entry for this RTA
1113 ** attached to the current host card in the driver table. 973 ** attached to the current host card in the driver table.
1114 ** 974 **
1115 ** If we found a SLOT_IN_USE entry on another host for this 975 ** If we found a SLOT_IN_USE entry on another host for this
1116 ** RTA in the config or driver table, and there are enough free 976 ** RTA in the config or driver table, and there are enough free
1117 ** slots in the driver table, then we need to move it over and 977 ** slots in the driver table, then we need to move it over and
1118 ** delete it from the other host. 978 ** delete it from the other host.
1119 ** If we found a SLOT_TENTATIVE entry on another host for this 979 ** If we found a SLOT_TENTATIVE entry on another host for this
1120 ** RTA in the driver table, just delete the other host entry. 980 ** RTA in the driver table, just delete the other host entry.
1121 */ 981 */
1122 if (EmptySlot == 0) 982 if (EmptySlot == 0) {
1123 { 983 if (MapP) {
1124 if ( MapP ) 984 if (Flag & SLOT_IN_USE) {
1125 { 985 rio_dprintk(RIO_DEBUG_BOOT, "This RTA configured on another host - move entry to current host (1)\n");
1126 if (Flag & SLOT_IN_USE) 986 HostP->Mapping[entry].SysPort = MapP->SysPort;
1127 { 987 memcpy(HostP->Mapping[entry].Name, MapP->Name, MAX_NAME_LEN);
1128 rio_dprintk (RIO_DEBUG_BOOT, 988 HostP->Mapping[entry].Flags = SLOT_IN_USE | RTA_BOOTED | RTA_NEWBOOT;
1129 "This RTA configured on another host - move entry to current host (1)\n"); 989 RIOReMapPorts(p, HostP, &HostP->Mapping[entry]);
1130 HostP->Mapping[entry].SysPort = MapP->SysPort; 990 if (HostP->Mapping[entry].SysPort < p->RIOFirstPortsBooted)
1131 CCOPY( MapP->Name, HostP->Mapping[entry].Name, MAX_NAME_LEN ); 991 p->RIOFirstPortsBooted = HostP->Mapping[entry].SysPort;
1132 HostP->Mapping[entry].Flags = 992 if (HostP->Mapping[entry].SysPort > p->RIOLastPortsBooted)
1133 SLOT_IN_USE | RTA_BOOTED | RTA_NEWBOOT; 993 p->RIOLastPortsBooted = HostP->Mapping[entry].SysPort;
1134#ifdef NEED_TO_FIX 994 rio_dprintk(RIO_DEBUG_BOOT, "SysPort %d, Name %s\n", (int) MapP->SysPort, MapP->Name);
1135 RIO_SV_BROADCAST(HostP->svFlags[entry]); 995 } else {
1136#endif 996 rio_dprintk(RIO_DEBUG_BOOT, "This RTA has a tentative entry on another host - delete that entry (1)\n");
1137 RIOReMapPorts( p, HostP, &HostP->Mapping[entry] ); 997 HostP->Mapping[entry].Flags = SLOT_TENTATIVE | RTA_BOOTED | RTA_NEWBOOT;
1138 if ( HostP->Mapping[entry].SysPort < p->RIOFirstPortsBooted ) 998 }
1139 p->RIOFirstPortsBooted = HostP->Mapping[entry].SysPort; 999 if (RtaType == TYPE_RTA16) {
1140 if ( HostP->Mapping[entry].SysPort > p->RIOLastPortsBooted ) 1000 if (Flag & SLOT_IN_USE) {
1141 p->RIOLastPortsBooted = HostP->Mapping[entry].SysPort; 1001 HostP->Mapping[entry2].Flags = SLOT_IN_USE | RTA_BOOTED | RTA_NEWBOOT | RTA16_SECOND_SLOT;
1142 rio_dprintk (RIO_DEBUG_BOOT, "SysPort %d, Name %s\n",(int)MapP->SysPort,MapP->Name); 1002 HostP->Mapping[entry2].SysPort = MapP2->SysPort;
1143 } 1003 /*
1144 else 1004 ** Map second block of ttys for 16 port RTA
1145 { 1005 */
1146 rio_dprintk (RIO_DEBUG_BOOT, 1006 RIOReMapPorts(p, HostP, &HostP->Mapping[entry2]);
1147 "This RTA has a tentative entry on another host - delete that entry (1)\n"); 1007 if (HostP->Mapping[entry2].SysPort < p->RIOFirstPortsBooted)
1148 HostP->Mapping[entry].Flags = 1008 p->RIOFirstPortsBooted = HostP->Mapping[entry2].SysPort;
1149 SLOT_TENTATIVE | RTA_BOOTED | RTA_NEWBOOT; 1009 if (HostP->Mapping[entry2].SysPort > p->RIOLastPortsBooted)
1150#ifdef NEED_TO_FIX 1010 p->RIOLastPortsBooted = HostP->Mapping[entry2].SysPort;
1151 RIO_SV_BROADCAST(HostP->svFlags[entry]); 1011 rio_dprintk(RIO_DEBUG_BOOT, "SysPort %d, Name %s\n", (int) HostP->Mapping[entry2].SysPort, HostP->Mapping[entry].Name);
1152#endif 1012 } else
1153 } 1013 HostP->Mapping[entry2].Flags = SLOT_TENTATIVE | RTA_BOOTED | RTA_NEWBOOT | RTA16_SECOND_SLOT;
1154 if (RtaType == TYPE_RTA16) 1014 memset(MapP2, 0, sizeof(struct Map));
1155 { 1015 }
1156 if (Flag & SLOT_IN_USE) 1016 memset(MapP, 0, sizeof(struct Map));
1157 { 1017 if (!p->RIONoMessage)
1158 HostP->Mapping[entry2].Flags = SLOT_IN_USE | 1018 printk("An orphaned RTA has been adopted by %s '%s' (%c).\n", MyType, MyName, MyLink + 'A');
1159 RTA_BOOTED | RTA_NEWBOOT | RTA16_SECOND_SLOT; 1019 } else if (!p->RIONoMessage)
1160#ifdef NEED_TO_FIX 1020 printk("RTA connected to %s '%s' (%c) not configured.\n", MyType, MyName, MyLink + 'A');
1161 RIO_SV_BROADCAST(HostP->svFlags[entry2]); 1021 RIOSetChange(p);
1162#endif 1022 return 1;
1163 HostP->Mapping[entry2].SysPort = MapP2->SysPort;
1164 /*
1165 ** Map second block of ttys for 16 port RTA
1166 */
1167 RIOReMapPorts( p, HostP, &HostP->Mapping[entry2] );
1168 if (HostP->Mapping[entry2].SysPort < p->RIOFirstPortsBooted)
1169 p->RIOFirstPortsBooted = HostP->Mapping[entry2].SysPort;
1170 if (HostP->Mapping[entry2].SysPort > p->RIOLastPortsBooted)
1171 p->RIOLastPortsBooted = HostP->Mapping[entry2].SysPort;
1172 rio_dprintk (RIO_DEBUG_BOOT, "SysPort %d, Name %s\n",
1173 (int)HostP->Mapping[entry2].SysPort,
1174 HostP->Mapping[entry].Name);
1175 }
1176 else
1177 HostP->Mapping[entry2].Flags = SLOT_TENTATIVE |
1178 RTA_BOOTED | RTA_NEWBOOT | RTA16_SECOND_SLOT;
1179#ifdef NEED_TO_FIX
1180 RIO_SV_BROADCAST(HostP->svFlags[entry2]);
1181#endif
1182 bzero( (caddr_t)MapP2, sizeof(struct Map) );
1183 }
1184 bzero( (caddr_t)MapP, sizeof(struct Map) );
1185 if (! p->RIONoMessage)
1186 cprintf("An orphaned RTA has been adopted by %s '%s' (%c).\n",MyType,MyName,MyLink+'A');
1187 }
1188 else if (! p->RIONoMessage)
1189 cprintf("RTA connected to %s '%s' (%c) not configured.\n",MyType,MyName,MyLink+'A');
1190 RIOSetChange(p);
1191 return TRUE;
1192 } 1023 }
1193 1024
1194 /* 1025 /*
1195 ** There is no room in the driver table to make an entry for the 1026 ** There is no room in the driver table to make an entry for the
1196 ** booted RTA. Keep a note of its Uniq Num in the overflow table, 1027 ** booted RTA. Keep a note of its Uniq Num in the overflow table,
1197 ** so we can ignore it's ID requests. 1028 ** so we can ignore it's ID requests.
1198 */ 1029 */
1199 if (! p->RIONoMessage) 1030 if (!p->RIONoMessage)
1200 cprintf("The RTA connected to %s '%s' (%c) cannot be configured. You cannot configure more than 128 ports to one host card.\n",MyType,MyName,MyLink+'A'); 1031 printk("The RTA connected to %s '%s' (%c) cannot be configured. You cannot configure more than 128 ports to one host card.\n", MyType, MyName, MyLink + 'A');
1201 for ( entry=0; entry<HostP->NumExtraBooted; entry++ ) 1032 for (entry = 0; entry < HostP->NumExtraBooted; entry++) {
1202 { 1033 if (HostP->ExtraUnits[entry] == RtaUniq) {
1203 if ( HostP->ExtraUnits[entry] == RtaUniq ) 1034 /*
1204 { 1035 ** already got it!
1205 /* 1036 */
1206 ** already got it! 1037 return 1;
1207 */ 1038 }
1208 return TRUE;
1209 }
1210 } 1039 }
1211 /* 1040 /*
1212 ** If there is room, add the unit to the list of extras 1041 ** If there is room, add the unit to the list of extras
1213 */ 1042 */
1214 if ( HostP->NumExtraBooted < MAX_EXTRA_UNITS ) 1043 if (HostP->NumExtraBooted < MAX_EXTRA_UNITS)
1215 HostP->ExtraUnits[HostP->NumExtraBooted++] = RtaUniq; 1044 HostP->ExtraUnits[HostP->NumExtraBooted++] = RtaUniq;
1216 return TRUE; 1045 return 1;
1217} 1046}
1218 1047
1219 1048
1220/* 1049/*
1221** If the RTA or its host appears in the RIOBindTab[] structure then 1050** If the RTA or its host appears in the RIOBindTab[] structure then
1222** we mustn't boot the RTA and should return FALSE. 1051** we mustn't boot the RTA and should return 0.
1223** This operation is slightly different from the other drivers for RIO 1052** This operation is slightly different from the other drivers for RIO
1224** in that this is designed to work with the new utilities 1053** in that this is designed to work with the new utilities
1225** not config.rio and is FAR SIMPLER. 1054** not config.rio and is FAR SIMPLER.
1226** We no longer support the RIOBootMode variable. It is all done from the 1055** We no longer support the RIOBootMode variable. It is all done from the
1227** "boot/noboot" field in the rio.cf file. 1056** "boot/noboot" field in the rio.cf file.
1228*/ 1057*/
1229int 1058int RIOBootOk(struct rio_info *p, struct Host *HostP, unsigned long RtaUniq)
1230RIOBootOk(p, HostP, RtaUniq)
1231struct rio_info * p;
1232struct Host * HostP;
1233ulong RtaUniq;
1234{ 1059{
1235 int Entry; 1060 int Entry;
1236 uint HostUniq = HostP->UniqueNum; 1061 unsigned int HostUniq = HostP->UniqueNum;
1237 1062
1238 /* 1063 /*
1239 ** Search bindings table for RTA or its parent. 1064 ** Search bindings table for RTA or its parent.
1240 ** If it exists, return 0, else 1. 1065 ** If it exists, return 0, else 1.
1241 */ 1066 */
1242 for (Entry = 0; 1067 for (Entry = 0; (Entry < MAX_RTA_BINDINGS) && (p->RIOBindTab[Entry] != 0); Entry++) {
1243 ( Entry < MAX_RTA_BINDINGS ) && ( p->RIOBindTab[Entry] != 0 ); 1068 if ((p->RIOBindTab[Entry] == HostUniq) || (p->RIOBindTab[Entry] == RtaUniq))
1244 Entry++)
1245 {
1246 if ( (p->RIOBindTab[Entry] == HostUniq) ||
1247 (p->RIOBindTab[Entry] == RtaUniq) )
1248 return 0; 1069 return 0;
1249 } 1070 }
1250 return 1; 1071 return 1;
@@ -1255,45 +1076,38 @@ ulong RtaUniq;
1255** slots tentative, and the second one RTA_SECOND_SLOT as well. 1076** slots tentative, and the second one RTA_SECOND_SLOT as well.
1256*/ 1077*/
1257 1078
1258void 1079void rio_fill_host_slot(int entry, int entry2, unsigned int rta_uniq, struct Host *host)
1259FillSlot(entry, entry2, RtaUniq, HostP)
1260int entry;
1261int entry2;
1262uint RtaUniq;
1263struct Host *HostP;
1264{ 1080{
1265 int link; 1081 int link;
1266 1082
1267 rio_dprintk (RIO_DEBUG_BOOT, "FillSlot(%d, %d, 0x%x...)\n", entry, entry2, RtaUniq); 1083 rio_dprintk(RIO_DEBUG_BOOT, "rio_fill_host_slot(%d, %d, 0x%x...)\n", entry, entry2, rta_uniq);
1268 1084
1269 HostP->Mapping[entry].Flags = (RTA_BOOTED | RTA_NEWBOOT | SLOT_TENTATIVE); 1085 host->Mapping[entry].Flags = (RTA_BOOTED | RTA_NEWBOOT | SLOT_TENTATIVE);
1270 HostP->Mapping[entry].SysPort = NO_PORT; 1086 host->Mapping[entry].SysPort = NO_PORT;
1271 HostP->Mapping[entry].RtaUniqueNum = RtaUniq; 1087 host->Mapping[entry].RtaUniqueNum = rta_uniq;
1272 HostP->Mapping[entry].HostUniqueNum = HostP->UniqueNum; 1088 host->Mapping[entry].HostUniqueNum = host->UniqueNum;
1273 HostP->Mapping[entry].ID = entry + 1; 1089 host->Mapping[entry].ID = entry + 1;
1274 HostP->Mapping[entry].ID2 = 0; 1090 host->Mapping[entry].ID2 = 0;
1275 if (entry2) { 1091 if (entry2) {
1276 HostP->Mapping[entry2].Flags = (RTA_BOOTED | RTA_NEWBOOT | 1092 host->Mapping[entry2].Flags = (RTA_BOOTED | RTA_NEWBOOT | SLOT_TENTATIVE | RTA16_SECOND_SLOT);
1277 SLOT_TENTATIVE | RTA16_SECOND_SLOT); 1093 host->Mapping[entry2].SysPort = NO_PORT;
1278 HostP->Mapping[entry2].SysPort = NO_PORT; 1094 host->Mapping[entry2].RtaUniqueNum = rta_uniq;
1279 HostP->Mapping[entry2].RtaUniqueNum = RtaUniq; 1095 host->Mapping[entry2].HostUniqueNum = host->UniqueNum;
1280 HostP->Mapping[entry2].HostUniqueNum = HostP->UniqueNum; 1096 host->Mapping[entry2].Name[0] = '\0';
1281 HostP->Mapping[entry2].Name[0] = '\0'; 1097 host->Mapping[entry2].ID = entry2 + 1;
1282 HostP->Mapping[entry2].ID = entry2 + 1; 1098 host->Mapping[entry2].ID2 = entry + 1;
1283 HostP->Mapping[entry2].ID2 = entry + 1; 1099 host->Mapping[entry].ID2 = entry2 + 1;
1284 HostP->Mapping[entry].ID2 = entry2 + 1;
1285 } 1100 }
1286 /* 1101 /*
1287 ** Must set these up, so that utilities show 1102 ** Must set these up, so that utilities show
1288 ** topology of 16 port RTAs correctly 1103 ** topology of 16 port RTAs correctly
1289 */ 1104 */
1290 for ( link=0; link<LINKS_PER_UNIT; link++ ) { 1105 for (link = 0; link < LINKS_PER_UNIT; link++) {
1291 HostP->Mapping[entry].Topology[link].Unit = ROUTE_DISCONNECT; 1106 host->Mapping[entry].Topology[link].Unit = ROUTE_DISCONNECT;
1292 HostP->Mapping[entry].Topology[link].Link = NO_LINK; 1107 host->Mapping[entry].Topology[link].Link = NO_LINK;
1293 if (entry2) { 1108 if (entry2) {
1294 HostP->Mapping[entry2].Topology[link].Unit = ROUTE_DISCONNECT; 1109 host->Mapping[entry2].Topology[link].Unit = ROUTE_DISCONNECT;
1295 HostP->Mapping[entry2].Topology[link].Link = NO_LINK; 1110 host->Mapping[entry2].Topology[link].Link = NO_LINK;
1296 } 1111 }
1297 } 1112 }
1298} 1113}
1299
diff --git a/drivers/char/rio/riocmd.c b/drivers/char/rio/riocmd.c
index 694bfb9d93..e6d2b14b5e 100644
--- a/drivers/char/rio/riocmd.c
+++ b/drivers/char/rio/riocmd.c
@@ -42,6 +42,7 @@ static char *_riocmd_c_sccs_ = "@(#)riocmd.c 1.2";
42#include <asm/system.h> 42#include <asm/system.h>
43#include <asm/string.h> 43#include <asm/string.h>
44#include <asm/semaphore.h> 44#include <asm/semaphore.h>
45#include <asm/uaccess.h>
45 46
46#include <linux/termios.h> 47#include <linux/termios.h>
47#include <linux/serial.h> 48#include <linux/serial.h>
@@ -50,15 +51,12 @@ static char *_riocmd_c_sccs_ = "@(#)riocmd.c 1.2";
50 51
51#include "linux_compat.h" 52#include "linux_compat.h"
52#include "rio_linux.h" 53#include "rio_linux.h"
53#include "typdef.h"
54#include "pkt.h" 54#include "pkt.h"
55#include "daemon.h" 55#include "daemon.h"
56#include "rio.h" 56#include "rio.h"
57#include "riospace.h" 57#include "riospace.h"
58#include "top.h"
59#include "cmdpkt.h" 58#include "cmdpkt.h"
60#include "map.h" 59#include "map.h"
61#include "riotypes.h"
62#include "rup.h" 60#include "rup.h"
63#include "port.h" 61#include "port.h"
64#include "riodrvr.h" 62#include "riodrvr.h"
@@ -71,12 +69,10 @@ static char *_riocmd_c_sccs_ = "@(#)riocmd.c 1.2";
71#include "unixrup.h" 69#include "unixrup.h"
72#include "board.h" 70#include "board.h"
73#include "host.h" 71#include "host.h"
74#include "error.h"
75#include "phb.h" 72#include "phb.h"
76#include "link.h" 73#include "link.h"
77#include "cmdblk.h" 74#include "cmdblk.h"
78#include "route.h" 75#include "route.h"
79#include "control.h"
80#include "cirrus.h" 76#include "cirrus.h"
81 77
82 78
@@ -143,17 +139,17 @@ int RIOZombieRta(struct Host *HostP, struct Map *MapP)
143 return 0; 139 return 0;
144} 140}
145 141
146int RIOCommandRta(struct rio_info *p, uint RtaUnique, int (*func) (struct Host * HostP, struct Map * MapP)) 142int RIOCommandRta(struct rio_info *p, unsigned long RtaUnique, int (*func) (struct Host * HostP, struct Map * MapP))
147{ 143{
148 uint Host; 144 unsigned int Host;
149 145
150 rio_dprintk(RIO_DEBUG_CMD, "Command RTA 0x%x func 0x%x\n", RtaUnique, (int) func); 146 rio_dprintk(RIO_DEBUG_CMD, "Command RTA 0x%lx func %p\n", RtaUnique, func);
151 147
152 if (!RtaUnique) 148 if (!RtaUnique)
153 return (0); 149 return (0);
154 150
155 for (Host = 0; Host < p->RIONumHosts; Host++) { 151 for (Host = 0; Host < p->RIONumHosts; Host++) {
156 uint Rta; 152 unsigned int Rta;
157 struct Host *HostP = &p->RIOHosts[Host]; 153 struct Host *HostP = &p->RIOHosts[Host];
158 154
159 for (Rta = 0; Rta < RTAS_PER_HOST; Rta++) { 155 for (Rta = 0; Rta < RTAS_PER_HOST; Rta++) {
@@ -170,7 +166,7 @@ int RIOCommandRta(struct rio_info *p, uint RtaUnique, int (*func) (struct Host *
170 ** any connections, we can get to it. 166 ** any connections, we can get to it.
171 */ 167 */
172 for (Link = 0; Link < LINKS_PER_UNIT; Link++) { 168 for (Link = 0; Link < LINKS_PER_UNIT; Link++) {
173 if (MapP->Topology[Link].Unit <= (uchar) MAX_RUP) { 169 if (MapP->Topology[Link].Unit <= (u8) MAX_RUP) {
174 /* 170 /*
175 ** Its worth trying the operation... 171 ** Its worth trying the operation...
176 */ 172 */
@@ -184,18 +180,18 @@ int RIOCommandRta(struct rio_info *p, uint RtaUnique, int (*func) (struct Host *
184} 180}
185 181
186 182
187int RIOIdentifyRta(struct rio_info *p, caddr_t arg) 183int RIOIdentifyRta(struct rio_info *p, void * arg)
188{ 184{
189 uint Host; 185 unsigned int Host;
190 186
191 if (copyin((int) arg, (caddr_t) & IdRta, sizeof(IdRta)) == COPYFAIL) { 187 if (copy_from_user(&IdRta, arg, sizeof(IdRta))) {
192 rio_dprintk(RIO_DEBUG_CMD, "RIO_IDENTIFY_RTA copy failed\n"); 188 rio_dprintk(RIO_DEBUG_CMD, "RIO_IDENTIFY_RTA copy failed\n");
193 p->RIOError.Error = COPYIN_FAILED; 189 p->RIOError.Error = COPYIN_FAILED;
194 return -EFAULT; 190 return -EFAULT;
195 } 191 }
196 192
197 for (Host = 0; Host < p->RIONumHosts; Host++) { 193 for (Host = 0; Host < p->RIONumHosts; Host++) {
198 uint Rta; 194 unsigned int Rta;
199 struct Host *HostP = &p->RIOHosts[Host]; 195 struct Host *HostP = &p->RIOHosts[Host];
200 196
201 for (Rta = 0; Rta < RTAS_PER_HOST; Rta++) { 197 for (Rta = 0; Rta < RTAS_PER_HOST; Rta++) {
@@ -211,7 +207,7 @@ int RIOIdentifyRta(struct rio_info *p, caddr_t arg)
211 ** any connections, we can get to it. 207 ** any connections, we can get to it.
212 */ 208 */
213 for (Link = 0; Link < LINKS_PER_UNIT; Link++) { 209 for (Link = 0; Link < LINKS_PER_UNIT; Link++) {
214 if (MapP->Topology[Link].Unit <= (uchar) MAX_RUP) { 210 if (MapP->Topology[Link].Unit <= (u8) MAX_RUP) {
215 /* 211 /*
216 ** Its worth trying the operation... 212 ** Its worth trying the operation...
217 */ 213 */
@@ -249,7 +245,7 @@ int RIOIdentifyRta(struct rio_info *p, caddr_t arg)
249} 245}
250 246
251 247
252int RIOKillNeighbour(struct rio_info *p, caddr_t arg) 248int RIOKillNeighbour(struct rio_info *p, void * arg)
253{ 249{
254 uint Host; 250 uint Host;
255 uint ID; 251 uint ID;
@@ -258,7 +254,7 @@ int RIOKillNeighbour(struct rio_info *p, caddr_t arg)
258 254
259 rio_dprintk(RIO_DEBUG_CMD, "KILL HOST NEIGHBOUR\n"); 255 rio_dprintk(RIO_DEBUG_CMD, "KILL HOST NEIGHBOUR\n");
260 256
261 if (copyin((int) arg, (caddr_t) & KillUnit, sizeof(KillUnit)) == COPYFAIL) { 257 if (copy_from_user(&KillUnit, arg, sizeof(KillUnit))) {
262 rio_dprintk(RIO_DEBUG_CMD, "RIO_KILL_NEIGHBOUR copy failed\n"); 258 rio_dprintk(RIO_DEBUG_CMD, "RIO_KILL_NEIGHBOUR copy failed\n");
263 p->RIOError.Error = COPYIN_FAILED; 259 p->RIOError.Error = COPYIN_FAILED;
264 return -EFAULT; 260 return -EFAULT;
@@ -344,7 +340,7 @@ int RIOSuspendBootRta(struct Host *HostP, int ID, int Link)
344int RIOFoadWakeup(struct rio_info *p) 340int RIOFoadWakeup(struct rio_info *p)
345{ 341{
346 int port; 342 int port;
347 register struct Port *PortP; 343 struct Port *PortP;
348 unsigned long flags; 344 unsigned long flags;
349 345
350 for (port = 0; port < RIO_PORTS; port++) { 346 for (port = 0; port < RIO_PORTS; port++) {
@@ -374,15 +370,15 @@ int RIOFoadWakeup(struct rio_info *p)
374/* 370/*
375** Incoming command on the COMMAND_RUP to be processed. 371** Incoming command on the COMMAND_RUP to be processed.
376*/ 372*/
377static int RIOCommandRup(struct rio_info *p, uint Rup, struct Host *HostP, PKT * PacketP) 373static int RIOCommandRup(struct rio_info *p, uint Rup, struct Host *HostP, struct PKT * PacketP)
378{ 374{
379 struct PktCmd *PktCmdP = (struct PktCmd *) PacketP->data; 375 struct PktCmd *PktCmdP = (struct PktCmd *) PacketP->data;
380 struct Port *PortP; 376 struct Port *PortP;
381 struct UnixRup *UnixRupP; 377 struct UnixRup *UnixRupP;
382 ushort SysPort; 378 unsigned short SysPort;
383 ushort ReportedModemStatus; 379 unsigned short ReportedModemStatus;
384 ushort rup; 380 unsigned short rup;
385 ushort subCommand; 381 unsigned short subCommand;
386 unsigned long flags; 382 unsigned long flags;
387 383
388 func_enter(); 384 func_enter();
@@ -395,18 +391,18 @@ static int RIOCommandRup(struct rio_info *p, uint Rup, struct Host *HostP, PKT *
395 ** we can use PhbNum to get the rup number for the appropriate 8 port 391 ** we can use PhbNum to get the rup number for the appropriate 8 port
396 ** block (for the first block, this should be equal to 'Rup'). 392 ** block (for the first block, this should be equal to 'Rup').
397 */ 393 */
398 rup = RBYTE(PktCmdP->PhbNum) / (ushort) PORTS_PER_RTA; 394 rup = readb(&PktCmdP->PhbNum) / (unsigned short) PORTS_PER_RTA;
399 UnixRupP = &HostP->UnixRups[rup]; 395 UnixRupP = &HostP->UnixRups[rup];
400 SysPort = UnixRupP->BaseSysPort + (RBYTE(PktCmdP->PhbNum) % (ushort) PORTS_PER_RTA); 396 SysPort = UnixRupP->BaseSysPort + (readb(&PktCmdP->PhbNum) % (unsigned short) PORTS_PER_RTA);
401 rio_dprintk(RIO_DEBUG_CMD, "Command on rup %d, port %d\n", rup, SysPort); 397 rio_dprintk(RIO_DEBUG_CMD, "Command on rup %d, port %d\n", rup, SysPort);
402 398
403 if (UnixRupP->BaseSysPort == NO_PORT) { 399 if (UnixRupP->BaseSysPort == NO_PORT) {
404 rio_dprintk(RIO_DEBUG_CMD, "OBSCURE ERROR!\n"); 400 rio_dprintk(RIO_DEBUG_CMD, "OBSCURE ERROR!\n");
405 rio_dprintk(RIO_DEBUG_CMD, "Diagnostics follow. Please WRITE THESE DOWN and report them to Specialix Technical Support\n"); 401 rio_dprintk(RIO_DEBUG_CMD, "Diagnostics follow. Please WRITE THESE DOWN and report them to Specialix Technical Support\n");
406 rio_dprintk(RIO_DEBUG_CMD, "CONTROL information: Host number %d, name ``%s''\n", HostP - p->RIOHosts, HostP->Name); 402 rio_dprintk(RIO_DEBUG_CMD, "CONTROL information: Host number %Zd, name ``%s''\n", HostP - p->RIOHosts, HostP->Name);
407 rio_dprintk(RIO_DEBUG_CMD, "CONTROL information: Rup number 0x%x\n", rup); 403 rio_dprintk(RIO_DEBUG_CMD, "CONTROL information: Rup number 0x%x\n", rup);
408 404
409 if (Rup >= (ushort) MAX_RUP) { 405 if (Rup >= (unsigned short) MAX_RUP) {
410 rio_dprintk(RIO_DEBUG_CMD, "CONTROL information: This is the RUP for RTA ``%s''\n", HostP->Mapping[Rup].Name); 406 rio_dprintk(RIO_DEBUG_CMD, "CONTROL information: This is the RUP for RTA ``%s''\n", HostP->Mapping[Rup].Name);
411 } else 407 } else
412 rio_dprintk(RIO_DEBUG_CMD, "CONTROL information: This is the RUP for link ``%c'' of host ``%s''\n", ('A' + Rup - MAX_RUP), HostP->Name); 408 rio_dprintk(RIO_DEBUG_CMD, "CONTROL information: This is the RUP for link ``%c'' of host ``%s''\n", ('A' + Rup - MAX_RUP), HostP->Name);
@@ -417,16 +413,16 @@ static int RIOCommandRup(struct rio_info *p, uint Rup, struct Host *HostP, PKT *
417 rio_dprintk(RIO_DEBUG_CMD, "PACKET information: Control 0x%x (%d)\n", PacketP->control, PacketP->control); 413 rio_dprintk(RIO_DEBUG_CMD, "PACKET information: Control 0x%x (%d)\n", PacketP->control, PacketP->control);
418 rio_dprintk(RIO_DEBUG_CMD, "PACKET information: Check 0x%x (%d)\n", PacketP->csum, PacketP->csum); 414 rio_dprintk(RIO_DEBUG_CMD, "PACKET information: Check 0x%x (%d)\n", PacketP->csum, PacketP->csum);
419 rio_dprintk(RIO_DEBUG_CMD, "COMMAND information: Host Port Number 0x%x, " "Command Code 0x%x\n", PktCmdP->PhbNum, PktCmdP->Command); 415 rio_dprintk(RIO_DEBUG_CMD, "COMMAND information: Host Port Number 0x%x, " "Command Code 0x%x\n", PktCmdP->PhbNum, PktCmdP->Command);
420 return TRUE; 416 return 1;
421 } 417 }
422 PortP = p->RIOPortp[SysPort]; 418 PortP = p->RIOPortp[SysPort];
423 rio_spin_lock_irqsave(&PortP->portSem, flags); 419 rio_spin_lock_irqsave(&PortP->portSem, flags);
424 switch (RBYTE(PktCmdP->Command)) { 420 switch (readb(&PktCmdP->Command)) {
425 case BREAK_RECEIVED: 421 case BREAK_RECEIVED:
426 rio_dprintk(RIO_DEBUG_CMD, "Received a break!\n"); 422 rio_dprintk(RIO_DEBUG_CMD, "Received a break!\n");
427 /* If the current line disc. is not multi-threading and 423 /* If the current line disc. is not multi-threading and
428 the current processor is not the default, reset rup_intr 424 the current processor is not the default, reset rup_intr
429 and return FALSE to ensure that the command packet is 425 and return 0 to ensure that the command packet is
430 not freed. */ 426 not freed. */
431 /* Call tmgr HANGUP HERE */ 427 /* Call tmgr HANGUP HERE */
432 /* Fix this later when every thing works !!!! RAMRAJ */ 428 /* Fix this later when every thing works !!!! RAMRAJ */
@@ -434,15 +430,15 @@ static int RIOCommandRup(struct rio_info *p, uint Rup, struct Host *HostP, PKT *
434 break; 430 break;
435 431
436 case COMPLETE: 432 case COMPLETE:
437 rio_dprintk(RIO_DEBUG_CMD, "Command complete on phb %d host %d\n", RBYTE(PktCmdP->PhbNum), HostP - p->RIOHosts); 433 rio_dprintk(RIO_DEBUG_CMD, "Command complete on phb %d host %Zd\n", readb(&PktCmdP->PhbNum), HostP - p->RIOHosts);
438 subCommand = 1; 434 subCommand = 1;
439 switch (RBYTE(PktCmdP->SubCommand)) { 435 switch (readb(&PktCmdP->SubCommand)) {
440 case MEMDUMP: 436 case MEMDUMP:
441 rio_dprintk(RIO_DEBUG_CMD, "Memory dump cmd (0x%x) from addr 0x%x\n", RBYTE(PktCmdP->SubCommand), RWORD(PktCmdP->SubAddr)); 437 rio_dprintk(RIO_DEBUG_CMD, "Memory dump cmd (0x%x) from addr 0x%x\n", readb(&PktCmdP->SubCommand), readw(&PktCmdP->SubAddr));
442 break; 438 break;
443 case READ_REGISTER: 439 case READ_REGISTER:
444 rio_dprintk(RIO_DEBUG_CMD, "Read register (0x%x)\n", RWORD(PktCmdP->SubAddr)); 440 rio_dprintk(RIO_DEBUG_CMD, "Read register (0x%x)\n", readw(&PktCmdP->SubAddr));
445 p->CdRegister = (RBYTE(PktCmdP->ModemStatus) & MSVR1_HOST); 441 p->CdRegister = (readb(&PktCmdP->ModemStatus) & MSVR1_HOST);
446 break; 442 break;
447 default: 443 default:
448 subCommand = 0; 444 subCommand = 0;
@@ -450,10 +446,10 @@ static int RIOCommandRup(struct rio_info *p, uint Rup, struct Host *HostP, PKT *
450 } 446 }
451 if (subCommand) 447 if (subCommand)
452 break; 448 break;
453 rio_dprintk(RIO_DEBUG_CMD, "New status is 0x%x was 0x%x\n", RBYTE(PktCmdP->PortStatus), PortP->PortState); 449 rio_dprintk(RIO_DEBUG_CMD, "New status is 0x%x was 0x%x\n", readb(&PktCmdP->PortStatus), PortP->PortState);
454 if (PortP->PortState != RBYTE(PktCmdP->PortStatus)) { 450 if (PortP->PortState != readb(&PktCmdP->PortStatus)) {
455 rio_dprintk(RIO_DEBUG_CMD, "Mark status & wakeup\n"); 451 rio_dprintk(RIO_DEBUG_CMD, "Mark status & wakeup\n");
456 PortP->PortState = RBYTE(PktCmdP->PortStatus); 452 PortP->PortState = readb(&PktCmdP->PortStatus);
457 /* What should we do here ... 453 /* What should we do here ...
458 wakeup( &PortP->PortState ); 454 wakeup( &PortP->PortState );
459 */ 455 */
@@ -467,7 +463,7 @@ static int RIOCommandRup(struct rio_info *p, uint Rup, struct Host *HostP, PKT *
467 ** to the check for modem status change (they're just there because 463 ** to the check for modem status change (they're just there because
468 ** it's a convenient place to put them!). 464 ** it's a convenient place to put them!).
469 */ 465 */
470 ReportedModemStatus = RBYTE(PktCmdP->ModemStatus); 466 ReportedModemStatus = readb(&PktCmdP->ModemStatus);
471 if ((PortP->ModemState & MSVR1_HOST) == (ReportedModemStatus & MSVR1_HOST)) { 467 if ((PortP->ModemState & MSVR1_HOST) == (ReportedModemStatus & MSVR1_HOST)) {
472 rio_dprintk(RIO_DEBUG_CMD, "Modem status unchanged 0x%x\n", PortP->ModemState); 468 rio_dprintk(RIO_DEBUG_CMD, "Modem status unchanged 0x%x\n", PortP->ModemState);
473 /* 469 /*
@@ -514,9 +510,6 @@ static int RIOCommandRup(struct rio_info *p, uint Rup, struct Host *HostP, PKT *
514 */ 510 */
515 if (PortP->State & (PORT_ISOPEN | RIO_WOPEN)) 511 if (PortP->State & (PORT_ISOPEN | RIO_WOPEN))
516 wake_up_interruptible(&PortP->gs.open_wait); 512 wake_up_interruptible(&PortP->gs.open_wait);
517#ifdef STATS
518 PortP->Stat.ModemOnCnt++;
519#endif
520 } 513 }
521 } else { 514 } else {
522 /* 515 /*
@@ -527,9 +520,6 @@ static int RIOCommandRup(struct rio_info *p, uint Rup, struct Host *HostP, PKT *
527 tty_hangup(PortP->gs.tty); 520 tty_hangup(PortP->gs.tty);
528 PortP->State &= ~RIO_CARR_ON; 521 PortP->State &= ~RIO_CARR_ON;
529 rio_dprintk(RIO_DEBUG_CMD, "Carrirer just went down\n"); 522 rio_dprintk(RIO_DEBUG_CMD, "Carrirer just went down\n");
530#ifdef STATS
531 PortP->Stat.ModemOffCnt++;
532#endif
533 } 523 }
534 } 524 }
535 } 525 }
@@ -539,14 +529,14 @@ static int RIOCommandRup(struct rio_info *p, uint Rup, struct Host *HostP, PKT *
539 break; 529 break;
540 530
541 default: 531 default:
542 rio_dprintk(RIO_DEBUG_CMD, "Unknown command %d on CMD_RUP of host %d\n", RBYTE(PktCmdP->Command), HostP - p->RIOHosts); 532 rio_dprintk(RIO_DEBUG_CMD, "Unknown command %d on CMD_RUP of host %Zd\n", readb(&PktCmdP->Command), HostP - p->RIOHosts);
543 break; 533 break;
544 } 534 }
545 rio_spin_unlock_irqrestore(&PortP->portSem, flags); 535 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
546 536
547 func_exit(); 537 func_exit();
548 538
549 return TRUE; 539 return 1;
550} 540}
551 541
552/* 542/*
@@ -566,10 +556,9 @@ struct CmdBlk *RIOGetCmdBlk(void)
566{ 556{
567 struct CmdBlk *CmdBlkP; 557 struct CmdBlk *CmdBlkP;
568 558
569 CmdBlkP = (struct CmdBlk *) sysbrk(sizeof(struct CmdBlk)); 559 CmdBlkP = (struct CmdBlk *)kmalloc(sizeof(struct CmdBlk), GFP_ATOMIC);
570 if (CmdBlkP) 560 if (CmdBlkP)
571 bzero(CmdBlkP, sizeof(struct CmdBlk)); 561 memset(CmdBlkP, 0, sizeof(struct CmdBlk));
572
573 return CmdBlkP; 562 return CmdBlkP;
574} 563}
575 564
@@ -578,7 +567,7 @@ struct CmdBlk *RIOGetCmdBlk(void)
578*/ 567*/
579void RIOFreeCmdBlk(struct CmdBlk *CmdBlkP) 568void RIOFreeCmdBlk(struct CmdBlk *CmdBlkP)
580{ 569{
581 sysfree((void *) CmdBlkP, sizeof(struct CmdBlk)); 570 kfree(CmdBlkP);
582} 571}
583 572
584/* 573/*
@@ -591,7 +580,7 @@ int RIOQueueCmdBlk(struct Host *HostP, uint Rup, struct CmdBlk *CmdBlkP)
591 struct UnixRup *UnixRupP; 580 struct UnixRup *UnixRupP;
592 unsigned long flags; 581 unsigned long flags;
593 582
594 if (Rup >= (ushort) (MAX_RUP + LINKS_PER_UNIT)) { 583 if (Rup >= (unsigned short) (MAX_RUP + LINKS_PER_UNIT)) {
595 rio_dprintk(RIO_DEBUG_CMD, "Illegal rup number %d in RIOQueueCmdBlk\n", Rup); 584 rio_dprintk(RIO_DEBUG_CMD, "Illegal rup number %d in RIOQueueCmdBlk\n", Rup);
596 RIOFreeCmdBlk(CmdBlkP); 585 RIOFreeCmdBlk(CmdBlkP);
597 return RIO_FAIL; 586 return RIO_FAIL;
@@ -605,14 +594,14 @@ int RIOQueueCmdBlk(struct Host *HostP, uint Rup, struct CmdBlk *CmdBlkP)
605 ** If the RUP is currently inactive, then put the request 594 ** If the RUP is currently inactive, then put the request
606 ** straight on the RUP.... 595 ** straight on the RUP....
607 */ 596 */
608 if ((UnixRupP->CmdsWaitingP == NULL) && (UnixRupP->CmdPendingP == NULL) && (RWORD(UnixRupP->RupP->txcontrol) == TX_RUP_INACTIVE) && (CmdBlkP->PreFuncP ? (*CmdBlkP->PreFuncP) (CmdBlkP->PreArg, CmdBlkP) 597 if ((UnixRupP->CmdsWaitingP == NULL) && (UnixRupP->CmdPendingP == NULL) && (readw(&UnixRupP->RupP->txcontrol) == TX_RUP_INACTIVE) && (CmdBlkP->PreFuncP ? (*CmdBlkP->PreFuncP) (CmdBlkP->PreArg, CmdBlkP)
609 : TRUE)) { 598 : 1)) {
610 rio_dprintk(RIO_DEBUG_CMD, "RUP inactive-placing command straight on. Cmd byte is 0x%x\n", CmdBlkP->Packet.data[0]); 599 rio_dprintk(RIO_DEBUG_CMD, "RUP inactive-placing command straight on. Cmd byte is 0x%x\n", CmdBlkP->Packet.data[0]);
611 600
612 /* 601 /*
613 ** Whammy! blat that pack! 602 ** Whammy! blat that pack!
614 */ 603 */
615 HostP->Copy((caddr_t) & CmdBlkP->Packet, RIO_PTR(HostP->Caddr, UnixRupP->RupP->txpkt), sizeof(PKT)); 604 HostP->Copy((caddr_t) & CmdBlkP->Packet, RIO_PTR(HostP->Caddr, UnixRupP->RupP->txpkt), sizeof(struct PKT));
616 605
617 /* 606 /*
618 ** place command packet on the pending position. 607 ** place command packet on the pending position.
@@ -622,11 +611,11 @@ int RIOQueueCmdBlk(struct Host *HostP, uint Rup, struct CmdBlk *CmdBlkP)
622 /* 611 /*
623 ** set the command register 612 ** set the command register
624 */ 613 */
625 WWORD(UnixRupP->RupP->txcontrol, TX_PACKET_READY); 614 writew(TX_PACKET_READY, &UnixRupP->RupP->txcontrol);
626 615
627 rio_spin_unlock_irqrestore(&UnixRupP->RupLock, flags); 616 rio_spin_unlock_irqrestore(&UnixRupP->RupLock, flags);
628 617
629 return RIO_SUCCESS; 618 return 0;
630 } 619 }
631 rio_dprintk(RIO_DEBUG_CMD, "RUP active - en-queing\n"); 620 rio_dprintk(RIO_DEBUG_CMD, "RUP active - en-queing\n");
632 621
@@ -634,20 +623,20 @@ int RIOQueueCmdBlk(struct Host *HostP, uint Rup, struct CmdBlk *CmdBlkP)
634 rio_dprintk(RIO_DEBUG_CMD, "Rup active - command waiting\n"); 623 rio_dprintk(RIO_DEBUG_CMD, "Rup active - command waiting\n");
635 if (UnixRupP->CmdPendingP != NULL) 624 if (UnixRupP->CmdPendingP != NULL)
636 rio_dprintk(RIO_DEBUG_CMD, "Rup active - command pending\n"); 625 rio_dprintk(RIO_DEBUG_CMD, "Rup active - command pending\n");
637 if (RWORD(UnixRupP->RupP->txcontrol) != TX_RUP_INACTIVE) 626 if (readw(&UnixRupP->RupP->txcontrol) != TX_RUP_INACTIVE)
638 rio_dprintk(RIO_DEBUG_CMD, "Rup active - command rup not ready\n"); 627 rio_dprintk(RIO_DEBUG_CMD, "Rup active - command rup not ready\n");
639 628
640 Base = &UnixRupP->CmdsWaitingP; 629 Base = &UnixRupP->CmdsWaitingP;
641 630
642 rio_dprintk(RIO_DEBUG_CMD, "First try to queue cmdblk 0x%x at 0x%x\n", (int) CmdBlkP, (int) Base); 631 rio_dprintk(RIO_DEBUG_CMD, "First try to queue cmdblk %p at %p\n", CmdBlkP, Base);
643 632
644 while (*Base) { 633 while (*Base) {
645 rio_dprintk(RIO_DEBUG_CMD, "Command cmdblk 0x%x here\n", (int) (*Base)); 634 rio_dprintk(RIO_DEBUG_CMD, "Command cmdblk %p here\n", *Base);
646 Base = &((*Base)->NextP); 635 Base = &((*Base)->NextP);
647 rio_dprintk(RIO_DEBUG_CMD, "Now try to queue cmd cmdblk 0x%x at 0x%x\n", (int) CmdBlkP, (int) Base); 636 rio_dprintk(RIO_DEBUG_CMD, "Now try to queue cmd cmdblk %p at %p\n", CmdBlkP, Base);
648 } 637 }
649 638
650 rio_dprintk(RIO_DEBUG_CMD, "Will queue cmdblk 0x%x at 0x%x\n", (int) CmdBlkP, (int) Base); 639 rio_dprintk(RIO_DEBUG_CMD, "Will queue cmdblk %p at %p\n", CmdBlkP, Base);
651 640
652 *Base = CmdBlkP; 641 *Base = CmdBlkP;
653 642
@@ -655,7 +644,7 @@ int RIOQueueCmdBlk(struct Host *HostP, uint Rup, struct CmdBlk *CmdBlkP)
655 644
656 rio_spin_unlock_irqrestore(&UnixRupP->RupLock, flags); 645 rio_spin_unlock_irqrestore(&UnixRupP->RupLock, flags);
657 646
658 return RIO_SUCCESS; 647 return 0;
659} 648}
660 649
661/* 650/*
@@ -664,10 +653,10 @@ int RIOQueueCmdBlk(struct Host *HostP, uint Rup, struct CmdBlk *CmdBlkP)
664*/ 653*/
665void RIOPollHostCommands(struct rio_info *p, struct Host *HostP) 654void RIOPollHostCommands(struct rio_info *p, struct Host *HostP)
666{ 655{
667 register struct CmdBlk *CmdBlkP; 656 struct CmdBlk *CmdBlkP;
668 register struct UnixRup *UnixRupP; 657 struct UnixRup *UnixRupP;
669 struct PKT *PacketP; 658 struct PKT *PacketP;
670 ushort Rup; 659 unsigned short Rup;
671 unsigned long flags; 660 unsigned long flags;
672 661
673 662
@@ -684,16 +673,14 @@ void RIOPollHostCommands(struct rio_info *p, struct Host *HostP)
684 /* 673 /*
685 ** First check for incoming commands: 674 ** First check for incoming commands:
686 */ 675 */
687 if (RWORD(UnixRupP->RupP->rxcontrol) != RX_RUP_INACTIVE) { 676 if (readw(&UnixRupP->RupP->rxcontrol) != RX_RUP_INACTIVE) {
688 int FreeMe; 677 int FreeMe;
689 678
690 PacketP = (PKT *) RIO_PTR(HostP->Caddr, RWORD(UnixRupP->RupP->rxpkt)); 679 PacketP = (struct PKT *) RIO_PTR(HostP->Caddr, readw(&UnixRupP->RupP->rxpkt));
691 680
692 ShowPacket(DBG_CMD, PacketP); 681 switch (readb(&PacketP->dest_port)) {
693
694 switch (RBYTE(PacketP->dest_port)) {
695 case BOOT_RUP: 682 case BOOT_RUP:
696 rio_dprintk(RIO_DEBUG_CMD, "Incoming Boot %s packet '%x'\n", RBYTE(PacketP->len) & 0x80 ? "Command" : "Data", RBYTE(PacketP->data[0])); 683 rio_dprintk(RIO_DEBUG_CMD, "Incoming Boot %s packet '%x'\n", readb(&PacketP->len) & 0x80 ? "Command" : "Data", readb(&PacketP->data[0]));
697 rio_spin_unlock_irqrestore(&UnixRupP->RupLock, flags); 684 rio_spin_unlock_irqrestore(&UnixRupP->RupLock, flags);
698 FreeMe = RIOBootRup(p, Rup, HostP, PacketP); 685 FreeMe = RIOBootRup(p, Rup, HostP, PacketP);
699 rio_spin_lock_irqsave(&UnixRupP->RupLock, flags); 686 rio_spin_lock_irqsave(&UnixRupP->RupLock, flags);
@@ -708,7 +695,7 @@ void RIOPollHostCommands(struct rio_info *p, struct Host *HostP)
708 rio_spin_unlock_irqrestore(&UnixRupP->RupLock, flags); 695 rio_spin_unlock_irqrestore(&UnixRupP->RupLock, flags);
709 FreeMe = RIOCommandRup(p, Rup, HostP, PacketP); 696 FreeMe = RIOCommandRup(p, Rup, HostP, PacketP);
710 if (PacketP->data[5] == MEMDUMP) { 697 if (PacketP->data[5] == MEMDUMP) {
711 rio_dprintk(RIO_DEBUG_CMD, "Memdump from 0x%x complete\n", *(ushort *) & (PacketP->data[6])); 698 rio_dprintk(RIO_DEBUG_CMD, "Memdump from 0x%x complete\n", *(unsigned short *) & (PacketP->data[6]));
712 HostP->Copy((caddr_t) & (PacketP->data[8]), (caddr_t) p->RIOMemDump, 32); 699 HostP->Copy((caddr_t) & (PacketP->data[8]), (caddr_t) p->RIOMemDump, 32);
713 } 700 }
714 rio_spin_lock_irqsave(&UnixRupP->RupLock, flags); 701 rio_spin_lock_irqsave(&UnixRupP->RupLock, flags);
@@ -721,7 +708,7 @@ void RIOPollHostCommands(struct rio_info *p, struct Host *HostP)
721 break; 708 break;
722 709
723 default: 710 default:
724 rio_dprintk(RIO_DEBUG_CMD, "Unknown RUP %d\n", RBYTE(PacketP->dest_port)); 711 rio_dprintk(RIO_DEBUG_CMD, "Unknown RUP %d\n", readb(&PacketP->dest_port));
725 FreeMe = 1; 712 FreeMe = 1;
726 break; 713 break;
727 } 714 }
@@ -730,11 +717,11 @@ void RIOPollHostCommands(struct rio_info *p, struct Host *HostP)
730 rio_dprintk(RIO_DEBUG_CMD, "Free processed incoming command packet\n"); 717 rio_dprintk(RIO_DEBUG_CMD, "Free processed incoming command packet\n");
731 put_free_end(HostP, PacketP); 718 put_free_end(HostP, PacketP);
732 719
733 WWORD(UnixRupP->RupP->rxcontrol, RX_RUP_INACTIVE); 720 writew(RX_RUP_INACTIVE, &UnixRupP->RupP->rxcontrol);
734 721
735 if (RWORD(UnixRupP->RupP->handshake) == PHB_HANDSHAKE_SET) { 722 if (readw(&UnixRupP->RupP->handshake) == PHB_HANDSHAKE_SET) {
736 rio_dprintk(RIO_DEBUG_CMD, "Handshake rup %d\n", Rup); 723 rio_dprintk(RIO_DEBUG_CMD, "Handshake rup %d\n", Rup);
737 WWORD(UnixRupP->RupP->handshake, PHB_HANDSHAKE_SET | PHB_HANDSHAKE_RESET); 724 writew(PHB_HANDSHAKE_SET | PHB_HANDSHAKE_RESET, &UnixRupP->RupP->handshake);
738 } 725 }
739 } 726 }
740 } 727 }
@@ -744,7 +731,7 @@ void RIOPollHostCommands(struct rio_info *p, struct Host *HostP)
744 ** and it has completed, then tidy it up. 731 ** and it has completed, then tidy it up.
745 */ 732 */
746 if ((CmdBlkP = UnixRupP->CmdPendingP) && /* ASSIGN! */ 733 if ((CmdBlkP = UnixRupP->CmdPendingP) && /* ASSIGN! */
747 (RWORD(UnixRupP->RupP->txcontrol) == TX_RUP_INACTIVE)) { 734 (readw(&UnixRupP->RupP->txcontrol) == TX_RUP_INACTIVE)) {
748 /* 735 /*
749 ** we are idle. 736 ** we are idle.
750 ** there is a command in pending. 737 ** there is a command in pending.
@@ -755,7 +742,7 @@ void RIOPollHostCommands(struct rio_info *p, struct Host *HostP)
755 if (CmdBlkP->Packet.dest_port == BOOT_RUP) 742 if (CmdBlkP->Packet.dest_port == BOOT_RUP)
756 rio_dprintk(RIO_DEBUG_CMD, "Free Boot %s Command Block '%x'\n", CmdBlkP->Packet.len & 0x80 ? "Command" : "Data", CmdBlkP->Packet.data[0]); 743 rio_dprintk(RIO_DEBUG_CMD, "Free Boot %s Command Block '%x'\n", CmdBlkP->Packet.len & 0x80 ? "Command" : "Data", CmdBlkP->Packet.data[0]);
757 744
758 rio_dprintk(RIO_DEBUG_CMD, "Command 0x%x completed\n", (int) CmdBlkP); 745 rio_dprintk(RIO_DEBUG_CMD, "Command %p completed\n", CmdBlkP);
759 746
760 /* 747 /*
761 ** Clear the Rup lock to prevent mutual exclusion. 748 ** Clear the Rup lock to prevent mutual exclusion.
@@ -782,20 +769,20 @@ void RIOPollHostCommands(struct rio_info *p, struct Host *HostP)
782 ** is idle, then process the command 769 ** is idle, then process the command
783 */ 770 */
784 if ((CmdBlkP = UnixRupP->CmdsWaitingP) && /* ASSIGN! */ 771 if ((CmdBlkP = UnixRupP->CmdsWaitingP) && /* ASSIGN! */
785 (UnixRupP->CmdPendingP == NULL) && (RWORD(UnixRupP->RupP->txcontrol) == TX_RUP_INACTIVE)) { 772 (UnixRupP->CmdPendingP == NULL) && (readw(&UnixRupP->RupP->txcontrol) == TX_RUP_INACTIVE)) {
786 /* 773 /*
787 ** if the pre-function is non-zero, call it. 774 ** if the pre-function is non-zero, call it.
788 ** If it returns RIO_FAIL then don't 775 ** If it returns RIO_FAIL then don't
789 ** send this command yet! 776 ** send this command yet!
790 */ 777 */
791 if (!(CmdBlkP->PreFuncP ? (*CmdBlkP->PreFuncP) (CmdBlkP->PreArg, CmdBlkP) : TRUE)) { 778 if (!(CmdBlkP->PreFuncP ? (*CmdBlkP->PreFuncP) (CmdBlkP->PreArg, CmdBlkP) : 1)) {
792 rio_dprintk(RIO_DEBUG_CMD, "Not ready to start command 0x%x\n", (int) CmdBlkP); 779 rio_dprintk(RIO_DEBUG_CMD, "Not ready to start command %p\n", CmdBlkP);
793 } else { 780 } else {
794 rio_dprintk(RIO_DEBUG_CMD, "Start new command 0x%x Cmd byte is 0x%x\n", (int) CmdBlkP, CmdBlkP->Packet.data[0]); 781 rio_dprintk(RIO_DEBUG_CMD, "Start new command %p Cmd byte is 0x%x\n", CmdBlkP, CmdBlkP->Packet.data[0]);
795 /* 782 /*
796 ** Whammy! blat that pack! 783 ** Whammy! blat that pack!
797 */ 784 */
798 HostP->Copy((caddr_t) & CmdBlkP->Packet, RIO_PTR(HostP->Caddr, UnixRupP->RupP->txpkt), sizeof(PKT)); 785 HostP->Copy((caddr_t) & CmdBlkP->Packet, RIO_PTR(HostP->Caddr, UnixRupP->RupP->txpkt), sizeof(struct PKT));
799 786
800 /* 787 /*
801 ** remove the command from the rup command queue... 788 ** remove the command from the rup command queue...
@@ -810,7 +797,7 @@ void RIOPollHostCommands(struct rio_info *p, struct Host *HostP)
810 /* 797 /*
811 ** set the command register 798 ** set the command register
812 */ 799 */
813 WWORD(UnixRupP->RupP->txcontrol, TX_PACKET_READY); 800 writew(TX_PACKET_READY, &UnixRupP->RupP->txcontrol);
814 801
815 /* 802 /*
816 ** the command block will be freed 803 ** the command block will be freed
@@ -822,7 +809,7 @@ void RIOPollHostCommands(struct rio_info *p, struct Host *HostP)
822 } while (Rup); 809 } while (Rup);
823} 810}
824 811
825int RIOWFlushMark(int iPortP, struct CmdBlk *CmdBlkP) 812int RIOWFlushMark(unsigned long iPortP, struct CmdBlk *CmdBlkP)
826{ 813{
827 struct Port *PortP = (struct Port *) iPortP; 814 struct Port *PortP = (struct Port *) iPortP;
828 unsigned long flags; 815 unsigned long flags;
@@ -834,33 +821,32 @@ int RIOWFlushMark(int iPortP, struct CmdBlk *CmdBlkP)
834 return RIOUnUse(iPortP, CmdBlkP); 821 return RIOUnUse(iPortP, CmdBlkP);
835} 822}
836 823
837int RIORFlushEnable(int iPortP, struct CmdBlk *CmdBlkP) 824int RIORFlushEnable(unsigned long iPortP, struct CmdBlk *CmdBlkP)
838{ 825{
839 struct Port *PortP = (struct Port *) iPortP; 826 struct Port *PortP = (struct Port *) iPortP;
840 PKT *PacketP; 827 struct PKT *PacketP;
841 unsigned long flags; 828 unsigned long flags;
842 829
843 rio_spin_lock_irqsave(&PortP->portSem, flags); 830 rio_spin_lock_irqsave(&PortP->portSem, flags);
844 831
845 while (can_remove_receive(&PacketP, PortP)) { 832 while (can_remove_receive(&PacketP, PortP)) {
846 remove_receive(PortP); 833 remove_receive(PortP);
847 ShowPacket(DBG_PROC, PacketP);
848 put_free_end(PortP->HostP, PacketP); 834 put_free_end(PortP->HostP, PacketP);
849 } 835 }
850 836
851 if (RWORD(PortP->PhbP->handshake) == PHB_HANDSHAKE_SET) { 837 if (readw(&PortP->PhbP->handshake) == PHB_HANDSHAKE_SET) {
852 /* 838 /*
853 ** MAGIC! (Basically, handshake the RX buffer, so that 839 ** MAGIC! (Basically, handshake the RX buffer, so that
854 ** the RTAs upstream can be re-enabled.) 840 ** the RTAs upstream can be re-enabled.)
855 */ 841 */
856 rio_dprintk(RIO_DEBUG_CMD, "Util: Set RX handshake bit\n"); 842 rio_dprintk(RIO_DEBUG_CMD, "Util: Set RX handshake bit\n");
857 WWORD(PortP->PhbP->handshake, PHB_HANDSHAKE_SET | PHB_HANDSHAKE_RESET); 843 writew(PHB_HANDSHAKE_SET | PHB_HANDSHAKE_RESET, &PortP->PhbP->handshake);
858 } 844 }
859 rio_spin_unlock_irqrestore(&PortP->portSem, flags); 845 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
860 return RIOUnUse(iPortP, CmdBlkP); 846 return RIOUnUse(iPortP, CmdBlkP);
861} 847}
862 848
863int RIOUnUse(int iPortP, struct CmdBlk *CmdBlkP) 849int RIOUnUse(unsigned long iPortP, struct CmdBlk *CmdBlkP)
864{ 850{
865 struct Port *PortP = (struct Port *) iPortP; 851 struct Port *PortP = (struct Port *) iPortP;
866 unsigned long flags; 852 unsigned long flags;
@@ -890,7 +876,7 @@ int RIOUnUse(int iPortP, struct CmdBlk *CmdBlkP)
890 ** When PortP->InUse becomes NOT_INUSE, we must ensure that any data 876 ** When PortP->InUse becomes NOT_INUSE, we must ensure that any data
891 ** hanging around in the transmit buffer is sent immediately. 877 ** hanging around in the transmit buffer is sent immediately.
892 */ 878 */
893 WWORD(PortP->HostP->ParmMapP->tx_intr, 1); 879 writew(1, &PortP->HostP->ParmMapP->tx_intr);
894 /* What to do here .. 880 /* What to do here ..
895 wakeup( (caddr_t)&(PortP->InUse) ); 881 wakeup( (caddr_t)&(PortP->InUse) );
896 */ 882 */
@@ -898,10 +884,6 @@ int RIOUnUse(int iPortP, struct CmdBlk *CmdBlkP)
898 return 0; 884 return 0;
899} 885}
900 886
901void ShowPacket(uint Flags, struct PKT *PacketP)
902{
903}
904
905/* 887/*
906** 888**
907** How to use this file: 889** How to use this file:
diff --git a/drivers/char/rio/rioctrl.c b/drivers/char/rio/rioctrl.c
index fcf18a0612..d31aba62bb 100644
--- a/drivers/char/rio/rioctrl.c
+++ b/drivers/char/rio/rioctrl.c
@@ -51,15 +51,12 @@ static char *_rioctrl_c_sccs_ = "@(#)rioctrl.c 1.3";
51 51
52#include "linux_compat.h" 52#include "linux_compat.h"
53#include "rio_linux.h" 53#include "rio_linux.h"
54#include "typdef.h"
55#include "pkt.h" 54#include "pkt.h"
56#include "daemon.h" 55#include "daemon.h"
57#include "rio.h" 56#include "rio.h"
58#include "riospace.h" 57#include "riospace.h"
59#include "top.h"
60#include "cmdpkt.h" 58#include "cmdpkt.h"
61#include "map.h" 59#include "map.h"
62#include "riotypes.h"
63#include "rup.h" 60#include "rup.h"
64#include "port.h" 61#include "port.h"
65#include "riodrvr.h" 62#include "riodrvr.h"
@@ -72,12 +69,10 @@ static char *_rioctrl_c_sccs_ = "@(#)rioctrl.c 1.3";
72#include "unixrup.h" 69#include "unixrup.h"
73#include "board.h" 70#include "board.h"
74#include "host.h" 71#include "host.h"
75#include "error.h"
76#include "phb.h" 72#include "phb.h"
77#include "link.h" 73#include "link.h"
78#include "cmdblk.h" 74#include "cmdblk.h"
79#include "route.h" 75#include "route.h"
80#include "control.h"
81#include "cirrus.h" 76#include "cirrus.h"
82#include "rioioctl.h" 77#include "rioioctl.h"
83 78
@@ -131,30 +126,6 @@ static int
131 126
132#define drv_makedev(maj, min) ((((uint) maj & 0xff) << 8) | ((uint) min & 0xff)) 127#define drv_makedev(maj, min) ((((uint) maj & 0xff) << 8) | ((uint) min & 0xff))
133 128
134int copyin(int arg, caddr_t dp, int siz)
135{
136 int rv;
137
138 rio_dprintk(RIO_DEBUG_CTRL, "Copying %d bytes from user %p to %p.\n", siz, (void *) arg, dp);
139 rv = copy_from_user(dp, (void *) arg, siz);
140 if (rv)
141 return COPYFAIL;
142 else
143 return rv;
144}
145
146static int copyout(caddr_t dp, int arg, int siz)
147{
148 int rv;
149
150 rio_dprintk(RIO_DEBUG_CTRL, "Copying %d bytes to user %p from %p.\n", siz, (void *) arg, dp);
151 rv = copy_to_user((void *) arg, dp, siz);
152 if (rv)
153 return COPYFAIL;
154 else
155 return rv;
156}
157
158int riocontrol(p, dev, cmd, arg, su) 129int riocontrol(p, dev, cmd, arg, su)
159struct rio_info *p; 130struct rio_info *p;
160dev_t dev; 131dev_t dev;
@@ -168,7 +139,7 @@ int su;
168 ushort loop; 139 ushort loop;
169 int Entry; 140 int Entry;
170 struct Port *PortP; 141 struct Port *PortP;
171 PKT *PacketP; 142 struct PKT *PacketP;
172 int retval = 0; 143 int retval = 0;
173 unsigned long flags; 144 unsigned long flags;
174 145
@@ -178,7 +149,7 @@ int su;
178 Host = 0; 149 Host = 0;
179 PortP = NULL; 150 PortP = NULL;
180 151
181 rio_dprintk(RIO_DEBUG_CTRL, "control ioctl cmd: 0x%x arg: 0x%x\n", cmd, (int) arg); 152 rio_dprintk(RIO_DEBUG_CTRL, "control ioctl cmd: 0x%x arg: %p\n", cmd, arg);
182 153
183 switch (cmd) { 154 switch (cmd) {
184 /* 155 /*
@@ -189,90 +160,34 @@ int su;
189 ** otherwise just the specified host card will be changed. 160 ** otherwise just the specified host card will be changed.
190 */ 161 */
191 case RIO_SET_TIMER: 162 case RIO_SET_TIMER:
192 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET_TIMER to %dms\n", (uint) arg); 163 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET_TIMER to %ldms\n", (unsigned long)arg);
193 { 164 {
194 int host, value; 165 int host, value;
195 host = (uint) arg >> 16; 166 host = ((unsigned long) arg >> 16) & 0x0000FFFF;
196 value = (uint) arg & 0x0000ffff; 167 value = (unsigned long) arg & 0x0000ffff;
197 if (host == -1) { 168 if (host == -1) {
198 for (host = 0; host < p->RIONumHosts; host++) { 169 for (host = 0; host < p->RIONumHosts; host++) {
199 if (p->RIOHosts[host].Flags == RC_RUNNING) { 170 if (p->RIOHosts[host].Flags == RC_RUNNING) {
200 WWORD(p->RIOHosts[host].ParmMapP->timer, value); 171 writew(value, &p->RIOHosts[host].ParmMapP->timer);
201 } 172 }
202 } 173 }
203 } else if (host >= p->RIONumHosts) { 174 } else if (host >= p->RIONumHosts) {
204 return -EINVAL; 175 return -EINVAL;
205 } else { 176 } else {
206 if (p->RIOHosts[host].Flags == RC_RUNNING) { 177 if (p->RIOHosts[host].Flags == RC_RUNNING) {
207 WWORD(p->RIOHosts[host].ParmMapP->timer, value); 178 writew(value, &p->RIOHosts[host].ParmMapP->timer);
208 } 179 }
209 } 180 }
210 } 181 }
211 return 0; 182 return 0;
212 183
213 case RIO_IDENTIFY_DRIVER:
214 /*
215 ** 15.10.1998 ARG - ESIL 0760 part fix
216 ** Added driver ident string output.
217 **
218 #ifndef __THIS_RELEASE__
219 #warning Driver Version string not defined !
220 #endif
221 cprintf("%s %s %s %s\n",
222 RIO_DRV_STR,
223 __THIS_RELEASE__,
224 __DATE__, __TIME__ );
225
226 return 0;
227
228 case RIO_DISPLAY_HOST_CFG:
229 **
230 ** 15.10.1998 ARG - ESIL 0760 part fix
231 ** Added driver host card ident string output.
232 **
233 ** Note that the only types currently supported
234 ** are ISA and PCI. Also this driver does not
235 ** (yet) distinguish between the Old PCI card
236 ** and the Jet PCI card. In fact I think this
237 ** driver only supports JET PCI !
238 **
239
240 for (Host = 0; Host < p->RIONumHosts; Host++)
241 {
242 HostP = &(p->RIOHosts[Host]);
243
244 switch ( HostP->Type )
245 {
246 case RIO_AT :
247 strcpy( host_type, RIO_AT_HOST_STR );
248 break;
249
250 case RIO_PCI :
251 strcpy( host_type, RIO_PCI_HOST_STR );
252 break;
253
254 default :
255 strcpy( host_type, "Unknown" );
256 break;
257 }
258
259 cprintf(
260 "RIO Host %d - Type:%s Addr:%X IRQ:%d\n",
261 Host, host_type,
262 (uint)HostP->PaddrP,
263 (int)HostP->Ivec - 32 );
264 }
265 return 0;
266 **
267 */
268
269 case RIO_FOAD_RTA: 184 case RIO_FOAD_RTA:
270 rio_dprintk(RIO_DEBUG_CTRL, "RIO_FOAD_RTA\n"); 185 rio_dprintk(RIO_DEBUG_CTRL, "RIO_FOAD_RTA\n");
271 return RIOCommandRta(p, (uint) arg, RIOFoadRta); 186 return RIOCommandRta(p, (unsigned long)arg, RIOFoadRta);
272 187
273 case RIO_ZOMBIE_RTA: 188 case RIO_ZOMBIE_RTA:
274 rio_dprintk(RIO_DEBUG_CTRL, "RIO_ZOMBIE_RTA\n"); 189 rio_dprintk(RIO_DEBUG_CTRL, "RIO_ZOMBIE_RTA\n");
275 return RIOCommandRta(p, (uint) arg, RIOZombieRta); 190 return RIOCommandRta(p, (unsigned long)arg, RIOZombieRta);
276 191
277 case RIO_IDENTIFY_RTA: 192 case RIO_IDENTIFY_RTA:
278 rio_dprintk(RIO_DEBUG_CTRL, "RIO_IDENTIFY_RTA\n"); 193 rio_dprintk(RIO_DEBUG_CTRL, "RIO_IDENTIFY_RTA\n");
@@ -287,7 +202,7 @@ int su;
287 struct CmdBlk *CmdBlkP; 202 struct CmdBlk *CmdBlkP;
288 203
289 rio_dprintk(RIO_DEBUG_CTRL, "SPECIAL_RUP_CMD\n"); 204 rio_dprintk(RIO_DEBUG_CTRL, "SPECIAL_RUP_CMD\n");
290 if (copyin((int) arg, (caddr_t) & SpecialRupCmd, sizeof(SpecialRupCmd)) == COPYFAIL) { 205 if (copy_from_user(&SpecialRupCmd, arg, sizeof(SpecialRupCmd))) {
291 rio_dprintk(RIO_DEBUG_CTRL, "SPECIAL_RUP_CMD copy failed\n"); 206 rio_dprintk(RIO_DEBUG_CTRL, "SPECIAL_RUP_CMD copy failed\n");
292 p->RIOError.Error = COPYIN_FAILED; 207 p->RIOError.Error = COPYIN_FAILED;
293 return -EFAULT; 208 return -EFAULT;
@@ -302,7 +217,7 @@ int su;
302 SpecialRupCmd.Host = 0; 217 SpecialRupCmd.Host = 0;
303 rio_dprintk(RIO_DEBUG_CTRL, "Queue special rup command for host %d rup %d\n", SpecialRupCmd.Host, SpecialRupCmd.RupNum); 218 rio_dprintk(RIO_DEBUG_CTRL, "Queue special rup command for host %d rup %d\n", SpecialRupCmd.Host, SpecialRupCmd.RupNum);
304 if (RIOQueueCmdBlk(&p->RIOHosts[SpecialRupCmd.Host], SpecialRupCmd.RupNum, CmdBlkP) == RIO_FAIL) { 219 if (RIOQueueCmdBlk(&p->RIOHosts[SpecialRupCmd.Host], SpecialRupCmd.RupNum, CmdBlkP) == RIO_FAIL) {
305 cprintf("FAILED TO QUEUE SPECIAL RUP COMMAND\n"); 220 printk(KERN_WARNING "rio: FAILED TO QUEUE SPECIAL RUP COMMAND\n");
306 } 221 }
307 return 0; 222 return 0;
308 } 223 }
@@ -324,7 +239,7 @@ int su;
324 if ((retval = RIOApel(p)) != 0) 239 if ((retval = RIOApel(p)) != 0)
325 return retval; 240 return retval;
326 241
327 if (copyout((caddr_t) p->RIOConnectTable, (int) arg, TOTAL_MAP_ENTRIES * sizeof(struct Map)) == COPYFAIL) { 242 if (copy_to_user(arg, p->RIOConnectTable, TOTAL_MAP_ENTRIES * sizeof(struct Map))) {
328 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_TABLE copy failed\n"); 243 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_TABLE copy failed\n");
329 p->RIOError.Error = COPYOUT_FAILED; 244 p->RIOError.Error = COPYOUT_FAILED;
330 return -EFAULT; 245 return -EFAULT;
@@ -369,7 +284,7 @@ int su;
369 p->RIOError.Error = NOT_SUPER_USER; 284 p->RIOError.Error = NOT_SUPER_USER;
370 return -EPERM; 285 return -EPERM;
371 } 286 }
372 if (copyin((int) arg, (caddr_t) & p->RIOConnectTable[0], TOTAL_MAP_ENTRIES * sizeof(struct Map)) == COPYFAIL) { 287 if (copy_from_user(&p->RIOConnectTable[0], arg, TOTAL_MAP_ENTRIES * sizeof(struct Map))) {
373 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_TABLE copy failed\n"); 288 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_TABLE copy failed\n");
374 p->RIOError.Error = COPYIN_FAILED; 289 p->RIOError.Error = COPYIN_FAILED;
375 return -EFAULT; 290 return -EFAULT;
@@ -415,7 +330,7 @@ int su;
415 p->RIOError.Error = NOT_SUPER_USER; 330 p->RIOError.Error = NOT_SUPER_USER;
416 return -EPERM; 331 return -EPERM;
417 } 332 }
418 if (copyout((caddr_t) p->RIOBindTab, (int) arg, (sizeof(ulong) * MAX_RTA_BINDINGS)) == COPYFAIL) { 333 if (copy_to_user(arg, p->RIOBindTab, (sizeof(ulong) * MAX_RTA_BINDINGS))) {
419 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_BINDINGS copy failed\n"); 334 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_BINDINGS copy failed\n");
420 p->RIOError.Error = COPYOUT_FAILED; 335 p->RIOError.Error = COPYOUT_FAILED;
421 return -EFAULT; 336 return -EFAULT;
@@ -434,7 +349,7 @@ int su;
434 p->RIOError.Error = NOT_SUPER_USER; 349 p->RIOError.Error = NOT_SUPER_USER;
435 return -EPERM; 350 return -EPERM;
436 } 351 }
437 if (copyin((int) arg, (caddr_t) & p->RIOBindTab[0], (sizeof(ulong) * MAX_RTA_BINDINGS)) == COPYFAIL) { 352 if (copy_from_user(&p->RIOBindTab[0], arg, (sizeof(ulong) * MAX_RTA_BINDINGS))) {
438 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_BINDINGS copy failed\n"); 353 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_BINDINGS copy failed\n");
439 p->RIOError.Error = COPYIN_FAILED; 354 p->RIOError.Error = COPYIN_FAILED;
440 return -EFAULT; 355 return -EFAULT;
@@ -458,12 +373,12 @@ int su;
458 for (Entry = 0; Entry < MAX_RTA_BINDINGS; Entry++) { 373 for (Entry = 0; Entry < MAX_RTA_BINDINGS; Entry++) {
459 if ((EmptySlot == -1) && (p->RIOBindTab[Entry] == 0L)) 374 if ((EmptySlot == -1) && (p->RIOBindTab[Entry] == 0L))
460 EmptySlot = Entry; 375 EmptySlot = Entry;
461 else if (p->RIOBindTab[Entry] == (int) arg) { 376 else if (p->RIOBindTab[Entry] == (long)arg) {
462 /* 377 /*
463 ** Already exists - delete 378 ** Already exists - delete
464 */ 379 */
465 p->RIOBindTab[Entry] = 0L; 380 p->RIOBindTab[Entry] = 0L;
466 rio_dprintk(RIO_DEBUG_CTRL, "Removing Rta %x from p->RIOBindTab\n", (int) arg); 381 rio_dprintk(RIO_DEBUG_CTRL, "Removing Rta %ld from p->RIOBindTab\n", (unsigned long)arg);
467 return 0; 382 return 0;
468 } 383 }
469 } 384 }
@@ -471,10 +386,10 @@ int su;
471 ** Dosen't exist - add 386 ** Dosen't exist - add
472 */ 387 */
473 if (EmptySlot != -1) { 388 if (EmptySlot != -1) {
474 p->RIOBindTab[EmptySlot] = (int) arg; 389 p->RIOBindTab[EmptySlot] = (unsigned long)arg;
475 rio_dprintk(RIO_DEBUG_CTRL, "Adding Rta %x to p->RIOBindTab\n", (int) arg); 390 rio_dprintk(RIO_DEBUG_CTRL, "Adding Rta %lx to p->RIOBindTab\n", (unsigned long) arg);
476 } else { 391 } else {
477 rio_dprintk(RIO_DEBUG_CTRL, "p->RIOBindTab full! - Rta %x not added\n", (int) arg); 392 rio_dprintk(RIO_DEBUG_CTRL, "p->RIOBindTab full! - Rta %lx not added\n", (unsigned long) arg);
478 return -ENOMEM; 393 return -ENOMEM;
479 } 394 }
480 return 0; 395 return 0;
@@ -482,7 +397,7 @@ int su;
482 397
483 case RIO_RESUME: 398 case RIO_RESUME:
484 rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME\n"); 399 rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME\n");
485 port = (uint) arg; 400 port = (unsigned long) arg;
486 if ((port < 0) || (port > 511)) { 401 if ((port < 0) || (port > 511)) {
487 rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME: Bad port number %d\n", port); 402 rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME: Bad port number %d\n", port);
488 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE; 403 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
@@ -518,8 +433,7 @@ int su;
518 p->RIOError.Error = NOT_SUPER_USER; 433 p->RIOError.Error = NOT_SUPER_USER;
519 return -EPERM; 434 return -EPERM;
520 } 435 }
521 if (copyin((int) arg, (caddr_t) & MapEnt, sizeof(MapEnt)) 436 if (copy_from_user(&MapEnt, arg, sizeof(MapEnt))) {
522 == COPYFAIL) {
523 rio_dprintk(RIO_DEBUG_CTRL, "Copy from user space failed\n"); 437 rio_dprintk(RIO_DEBUG_CTRL, "Copy from user space failed\n");
524 p->RIOError.Error = COPYIN_FAILED; 438 p->RIOError.Error = COPYIN_FAILED;
525 return -EFAULT; 439 return -EFAULT;
@@ -533,8 +447,7 @@ int su;
533 p->RIOError.Error = NOT_SUPER_USER; 447 p->RIOError.Error = NOT_SUPER_USER;
534 return -EPERM; 448 return -EPERM;
535 } 449 }
536 if (copyin((int) arg, (caddr_t) & MapEnt, sizeof(MapEnt)) 450 if (copy_from_user(&MapEnt, arg, sizeof(MapEnt))) {
537 == COPYFAIL) {
538 rio_dprintk(RIO_DEBUG_CTRL, "Copy from user space failed\n"); 451 rio_dprintk(RIO_DEBUG_CTRL, "Copy from user space failed\n");
539 p->RIOError.Error = COPYIN_FAILED; 452 p->RIOError.Error = COPYIN_FAILED;
540 return -EFAULT; 453 return -EFAULT;
@@ -548,8 +461,7 @@ int su;
548 p->RIOError.Error = NOT_SUPER_USER; 461 p->RIOError.Error = NOT_SUPER_USER;
549 return -EPERM; 462 return -EPERM;
550 } 463 }
551 if (copyin((int) arg, (caddr_t) & MapEnt, sizeof(MapEnt)) 464 if (copy_from_user(&MapEnt, arg, sizeof(MapEnt))) {
552 == COPYFAIL) {
553 rio_dprintk(RIO_DEBUG_CTRL, "Copy from data space failed\n"); 465 rio_dprintk(RIO_DEBUG_CTRL, "Copy from data space failed\n");
554 p->RIOError.Error = COPYIN_FAILED; 466 p->RIOError.Error = COPYIN_FAILED;
555 return -EFAULT; 467 return -EFAULT;
@@ -557,30 +469,14 @@ int su;
557 return RIODeleteRta(p, &MapEnt); 469 return RIODeleteRta(p, &MapEnt);
558 470
559 case RIO_QUICK_CHECK: 471 case RIO_QUICK_CHECK:
560 /* 472 if (copy_to_user(arg, &p->RIORtaDisCons, sizeof(unsigned int))) {
561 ** 09.12.1998 ARG - ESIL 0776 part fix
562 ** A customer was using this to get the RTAs
563 ** connect/disconnect status.
564 ** RIOConCon() had been botched use RIOHalted
565 ** to keep track of RTA connections and
566 ** disconnections. That has been changed and
567 ** RIORtaDisCons in the rio_info struct now
568 ** does the job. So we need to return the value
569 ** of RIORtaCons instead of RIOHalted.
570 **
571 if (copyout((caddr_t)&p->RIOHalted,(int)arg,
572 sizeof(uint))==COPYFAIL) {
573 **
574 */
575
576 if (copyout((caddr_t) & p->RIORtaDisCons, (int) arg, sizeof(uint)) == COPYFAIL) {
577 p->RIOError.Error = COPYOUT_FAILED; 473 p->RIOError.Error = COPYOUT_FAILED;
578 return -EFAULT; 474 return -EFAULT;
579 } 475 }
580 return 0; 476 return 0;
581 477
582 case RIO_LAST_ERROR: 478 case RIO_LAST_ERROR:
583 if (copyout((caddr_t) & p->RIOError, (int) arg, sizeof(struct Error)) == COPYFAIL) 479 if (copy_to_user(arg, &p->RIOError, sizeof(struct Error)))
584 return -EFAULT; 480 return -EFAULT;
585 return 0; 481 return 0;
586 482
@@ -589,7 +485,7 @@ int su;
589 return -EINVAL; 485 return -EINVAL;
590 486
591 case RIO_GET_MODTYPE: 487 case RIO_GET_MODTYPE:
592 if (copyin((int) arg, (caddr_t) & port, sizeof(uint)) == COPYFAIL) { 488 if (copy_from_user(&port, arg, sizeof(unsigned int))) {
593 p->RIOError.Error = COPYIN_FAILED; 489 p->RIOError.Error = COPYIN_FAILED;
594 return -EFAULT; 490 return -EFAULT;
595 } 491 }
@@ -609,36 +505,11 @@ int su;
609 ** Return module type of port 505 ** Return module type of port
610 */ 506 */
611 port = PortP->HostP->UnixRups[PortP->RupNum].ModTypes; 507 port = PortP->HostP->UnixRups[PortP->RupNum].ModTypes;
612 if (copyout((caddr_t) & port, (int) arg, sizeof(uint)) == COPYFAIL) { 508 if (copy_to_user(arg, &port, sizeof(unsigned int))) {
613 p->RIOError.Error = COPYOUT_FAILED; 509 p->RIOError.Error = COPYOUT_FAILED;
614 return -EFAULT; 510 return -EFAULT;
615 } 511 }
616 return (0); 512 return (0);
617 /*
618 ** 02.03.1999 ARG - ESIL 0820 fix
619 ** We are no longer using "Boot Mode", so these ioctls
620 ** are not required :
621 **
622 case RIO_GET_BOOT_MODE :
623 rio_dprint(RIO_DEBUG_CTRL, ("Get boot mode - %x\n", p->RIOBootMode));
624 **
625 ** Return boot state of system - BOOT_ALL, BOOT_OWN or BOOT_NONE
626 **
627 if (copyout((caddr_t)&p->RIOBootMode, (int)arg,
628 sizeof(p->RIOBootMode)) == COPYFAIL) {
629 p->RIOError.Error = COPYOUT_FAILED;
630 return -EFAULT;
631 }
632 return(0);
633
634 case RIO_SET_BOOT_MODE :
635 p->RIOBootMode = (uint) arg;
636 rio_dprint(RIO_DEBUG_CTRL, ("Set boot mode to 0x%x\n", p->RIOBootMode));
637 return(0);
638 **
639 ** End ESIL 0820 fix
640 */
641
642 case RIO_BLOCK_OPENS: 513 case RIO_BLOCK_OPENS:
643 rio_dprintk(RIO_DEBUG_CTRL, "Opens block until booted\n"); 514 rio_dprintk(RIO_DEBUG_CTRL, "Opens block until booted\n");
644 for (Entry = 0; Entry < RIO_PORTS; Entry++) { 515 for (Entry = 0; Entry < RIO_PORTS; Entry++) {
@@ -650,8 +521,7 @@ int su;
650 521
651 case RIO_SETUP_PORTS: 522 case RIO_SETUP_PORTS:
652 rio_dprintk(RIO_DEBUG_CTRL, "Setup ports\n"); 523 rio_dprintk(RIO_DEBUG_CTRL, "Setup ports\n");
653 if (copyin((int) arg, (caddr_t) & PortSetup, sizeof(PortSetup)) 524 if (copy_from_user(&PortSetup, arg, sizeof(PortSetup))) {
654 == COPYFAIL) {
655 p->RIOError.Error = COPYIN_FAILED; 525 p->RIOError.Error = COPYIN_FAILED;
656 rio_dprintk(RIO_DEBUG_CTRL, "EFAULT"); 526 rio_dprintk(RIO_DEBUG_CTRL, "EFAULT");
657 return -EFAULT; 527 return -EFAULT;
@@ -667,7 +537,7 @@ int su;
667 return -EINVAL; 537 return -EINVAL;
668 } 538 }
669 if (!p->RIOPortp) { 539 if (!p->RIOPortp) {
670 cprintf("No p->RIOPortp array!\n"); 540 printk(KERN_ERR "rio: No p->RIOPortp array!\n");
671 rio_dprintk(RIO_DEBUG_CTRL, "No p->RIOPortp array!\n"); 541 rio_dprintk(RIO_DEBUG_CTRL, "No p->RIOPortp array!\n");
672 return -EIO; 542 return -EIO;
673 } 543 }
@@ -681,8 +551,7 @@ int su;
681 551
682 case RIO_GET_PORT_SETUP: 552 case RIO_GET_PORT_SETUP:
683 rio_dprintk(RIO_DEBUG_CTRL, "Get port setup\n"); 553 rio_dprintk(RIO_DEBUG_CTRL, "Get port setup\n");
684 if (copyin((int) arg, (caddr_t) & PortSetup, sizeof(PortSetup)) 554 if (copy_from_user(&PortSetup, arg, sizeof(PortSetup))) {
685 == COPYFAIL) {
686 p->RIOError.Error = COPYIN_FAILED; 555 p->RIOError.Error = COPYIN_FAILED;
687 return -EFAULT; 556 return -EFAULT;
688 } 557 }
@@ -698,13 +567,12 @@ int su;
698 PortSetup.Store = p->RIOPortp[port]->Store; 567 PortSetup.Store = p->RIOPortp[port]->Store;
699 PortSetup.Lock = p->RIOPortp[port]->Lock; 568 PortSetup.Lock = p->RIOPortp[port]->Lock;
700 PortSetup.XpCps = p->RIOPortp[port]->Xprint.XpCps; 569 PortSetup.XpCps = p->RIOPortp[port]->Xprint.XpCps;
701 bcopy(p->RIOPortp[port]->Xprint.XpOn, PortSetup.XpOn, MAX_XP_CTRL_LEN); 570 memcpy(PortSetup.XpOn, p->RIOPortp[port]->Xprint.XpOn, MAX_XP_CTRL_LEN);
702 bcopy(p->RIOPortp[port]->Xprint.XpOff, PortSetup.XpOff, MAX_XP_CTRL_LEN); 571 memcpy(PortSetup.XpOff, p->RIOPortp[port]->Xprint.XpOff, MAX_XP_CTRL_LEN);
703 PortSetup.XpOn[MAX_XP_CTRL_LEN - 1] = '\0'; 572 PortSetup.XpOn[MAX_XP_CTRL_LEN - 1] = '\0';
704 PortSetup.XpOff[MAX_XP_CTRL_LEN - 1] = '\0'; 573 PortSetup.XpOff[MAX_XP_CTRL_LEN - 1] = '\0';
705 574
706 if (copyout((caddr_t) & PortSetup, (int) arg, sizeof(PortSetup)) 575 if (copy_to_user(arg, &PortSetup, sizeof(PortSetup))) {
707 == COPYFAIL) {
708 p->RIOError.Error = COPYOUT_FAILED; 576 p->RIOError.Error = COPYOUT_FAILED;
709 return -EFAULT; 577 return -EFAULT;
710 } 578 }
@@ -712,7 +580,7 @@ int su;
712 580
713 case RIO_GET_PORT_PARAMS: 581 case RIO_GET_PORT_PARAMS:
714 rio_dprintk(RIO_DEBUG_CTRL, "Get port params\n"); 582 rio_dprintk(RIO_DEBUG_CTRL, "Get port params\n");
715 if (copyin((int) arg, (caddr_t) & PortParams, sizeof(struct PortParams)) == COPYFAIL) { 583 if (copy_from_user(&PortParams, arg, sizeof(struct PortParams))) {
716 p->RIOError.Error = COPYIN_FAILED; 584 p->RIOError.Error = COPYIN_FAILED;
717 return -EFAULT; 585 return -EFAULT;
718 } 586 }
@@ -725,7 +593,7 @@ int su;
725 PortParams.State = PortP->State; 593 PortParams.State = PortP->State;
726 rio_dprintk(RIO_DEBUG_CTRL, "Port %d\n", PortParams.Port); 594 rio_dprintk(RIO_DEBUG_CTRL, "Port %d\n", PortParams.Port);
727 595
728 if (copyout((caddr_t) & PortParams, (int) arg, sizeof(struct PortParams)) == COPYFAIL) { 596 if (copy_to_user(arg, &PortParams, sizeof(struct PortParams))) {
729 p->RIOError.Error = COPYOUT_FAILED; 597 p->RIOError.Error = COPYOUT_FAILED;
730 return -EFAULT; 598 return -EFAULT;
731 } 599 }
@@ -733,8 +601,7 @@ int su;
733 601
734 case RIO_GET_PORT_TTY: 602 case RIO_GET_PORT_TTY:
735 rio_dprintk(RIO_DEBUG_CTRL, "Get port tty\n"); 603 rio_dprintk(RIO_DEBUG_CTRL, "Get port tty\n");
736 if (copyin((int) arg, (caddr_t) & PortTty, sizeof(struct PortTty)) 604 if (copy_from_user(&PortTty, arg, sizeof(struct PortTty))) {
737 == COPYFAIL) {
738 p->RIOError.Error = COPYIN_FAILED; 605 p->RIOError.Error = COPYIN_FAILED;
739 return -EFAULT; 606 return -EFAULT;
740 } 607 }
@@ -745,14 +612,14 @@ int su;
745 612
746 rio_dprintk(RIO_DEBUG_CTRL, "Port %d\n", PortTty.port); 613 rio_dprintk(RIO_DEBUG_CTRL, "Port %d\n", PortTty.port);
747 PortP = (p->RIOPortp[PortTty.port]); 614 PortP = (p->RIOPortp[PortTty.port]);
748 if (copyout((caddr_t) & PortTty, (int) arg, sizeof(struct PortTty)) == COPYFAIL) { 615 if (copy_to_user(arg, &PortTty, sizeof(struct PortTty))) {
749 p->RIOError.Error = COPYOUT_FAILED; 616 p->RIOError.Error = COPYOUT_FAILED;
750 return -EFAULT; 617 return -EFAULT;
751 } 618 }
752 return retval; 619 return retval;
753 620
754 case RIO_SET_PORT_TTY: 621 case RIO_SET_PORT_TTY:
755 if (copyin((int) arg, (caddr_t) & PortTty, sizeof(struct PortTty)) == COPYFAIL) { 622 if (copy_from_user(&PortTty, arg, sizeof(struct PortTty))) {
756 p->RIOError.Error = COPYIN_FAILED; 623 p->RIOError.Error = COPYIN_FAILED;
757 return -EFAULT; 624 return -EFAULT;
758 } 625 }
@@ -767,8 +634,7 @@ int su;
767 634
768 case RIO_SET_PORT_PARAMS: 635 case RIO_SET_PORT_PARAMS:
769 rio_dprintk(RIO_DEBUG_CTRL, "Set port params\n"); 636 rio_dprintk(RIO_DEBUG_CTRL, "Set port params\n");
770 if (copyin((int) arg, (caddr_t) & PortParams, sizeof(PortParams)) 637 if (copy_from_user(&PortParams, arg, sizeof(PortParams))) {
771 == COPYFAIL) {
772 p->RIOError.Error = COPYIN_FAILED; 638 p->RIOError.Error = COPYIN_FAILED;
773 return -EFAULT; 639 return -EFAULT;
774 } 640 }
@@ -784,7 +650,7 @@ int su;
784 650
785 case RIO_GET_PORT_STATS: 651 case RIO_GET_PORT_STATS:
786 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_PORT_STATS\n"); 652 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_PORT_STATS\n");
787 if (copyin((int) arg, (caddr_t) & portStats, sizeof(struct portStats)) == COPYFAIL) { 653 if (copy_from_user(&portStats, arg, sizeof(struct portStats))) {
788 p->RIOError.Error = COPYIN_FAILED; 654 p->RIOError.Error = COPYIN_FAILED;
789 return -EFAULT; 655 return -EFAULT;
790 } 656 }
@@ -799,14 +665,14 @@ int su;
799 portStats.opens = PortP->opens; 665 portStats.opens = PortP->opens;
800 portStats.closes = PortP->closes; 666 portStats.closes = PortP->closes;
801 portStats.ioctls = PortP->ioctls; 667 portStats.ioctls = PortP->ioctls;
802 if (copyout((caddr_t) & portStats, (int) arg, sizeof(struct portStats)) == COPYFAIL) { 668 if (copy_to_user(arg, &portStats, sizeof(struct portStats))) {
803 p->RIOError.Error = COPYOUT_FAILED; 669 p->RIOError.Error = COPYOUT_FAILED;
804 return -EFAULT; 670 return -EFAULT;
805 } 671 }
806 return retval; 672 return retval;
807 673
808 case RIO_RESET_PORT_STATS: 674 case RIO_RESET_PORT_STATS:
809 port = (uint) arg; 675 port = (unsigned long) arg;
810 rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESET_PORT_STATS\n"); 676 rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESET_PORT_STATS\n");
811 if (port >= RIO_PORTS) { 677 if (port >= RIO_PORTS) {
812 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE; 678 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
@@ -824,7 +690,7 @@ int su;
824 690
825 case RIO_GATHER_PORT_STATS: 691 case RIO_GATHER_PORT_STATS:
826 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GATHER_PORT_STATS\n"); 692 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GATHER_PORT_STATS\n");
827 if (copyin((int) arg, (caddr_t) & portStats, sizeof(struct portStats)) == COPYFAIL) { 693 if (copy_from_user(&portStats, arg, sizeof(struct portStats))) {
828 p->RIOError.Error = COPYIN_FAILED; 694 p->RIOError.Error = COPYIN_FAILED;
829 return -EFAULT; 695 return -EFAULT;
830 } 696 }
@@ -840,7 +706,7 @@ int su;
840 706
841 case RIO_READ_CONFIG: 707 case RIO_READ_CONFIG:
842 rio_dprintk(RIO_DEBUG_CTRL, "RIO_READ_CONFIG\n"); 708 rio_dprintk(RIO_DEBUG_CTRL, "RIO_READ_CONFIG\n");
843 if (copyout((caddr_t) & p->RIOConf, (int) arg, sizeof(struct Conf)) == COPYFAIL) { 709 if (copy_to_user(arg, &p->RIOConf, sizeof(struct Conf))) {
844 p->RIOError.Error = COPYOUT_FAILED; 710 p->RIOError.Error = COPYOUT_FAILED;
845 return -EFAULT; 711 return -EFAULT;
846 } 712 }
@@ -852,8 +718,7 @@ int su;
852 p->RIOError.Error = NOT_SUPER_USER; 718 p->RIOError.Error = NOT_SUPER_USER;
853 return -EPERM; 719 return -EPERM;
854 } 720 }
855 if (copyin((int) arg, (caddr_t) & p->RIOConf, sizeof(struct Conf)) 721 if (copy_from_user(&p->RIOConf, arg, sizeof(struct Conf))) {
856 == COPYFAIL) {
857 p->RIOError.Error = COPYIN_FAILED; 722 p->RIOError.Error = COPYIN_FAILED;
858 return -EFAULT; 723 return -EFAULT;
859 } 724 }
@@ -862,7 +727,7 @@ int su;
862 */ 727 */
863 for (Host = 0; Host < p->RIONumHosts; Host++) 728 for (Host = 0; Host < p->RIONumHosts; Host++)
864 if ((p->RIOHosts[Host].Flags & RUN_STATE) == RC_RUNNING) 729 if ((p->RIOHosts[Host].Flags & RUN_STATE) == RC_RUNNING)
865 WWORD(p->RIOHosts[Host].ParmMapP->timer, p->RIOConf.Timer); 730 writew(p->RIOConf.Timer, &p->RIOHosts[Host].ParmMapP->timer);
866 return retval; 731 return retval;
867 732
868 case RIO_START_POLLER: 733 case RIO_START_POLLER:
@@ -881,8 +746,7 @@ int su;
881 case RIO_SETDEBUG: 746 case RIO_SETDEBUG:
882 case RIO_GETDEBUG: 747 case RIO_GETDEBUG:
883 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SETDEBUG/RIO_GETDEBUG\n"); 748 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SETDEBUG/RIO_GETDEBUG\n");
884 if (copyin((int) arg, (caddr_t) & DebugCtrl, sizeof(DebugCtrl)) 749 if (copy_from_user(&DebugCtrl, arg, sizeof(DebugCtrl))) {
885 == COPYFAIL) {
886 p->RIOError.Error = COPYIN_FAILED; 750 p->RIOError.Error = COPYIN_FAILED;
887 return -EFAULT; 751 return -EFAULT;
888 } 752 }
@@ -899,7 +763,7 @@ int su;
899 rio_dprintk(RIO_DEBUG_CTRL, "Get global debug 0x%x wait 0x%x\n", p->rio_debug, p->RIODebugWait); 763 rio_dprintk(RIO_DEBUG_CTRL, "Get global debug 0x%x wait 0x%x\n", p->rio_debug, p->RIODebugWait);
900 DebugCtrl.Debug = p->rio_debug; 764 DebugCtrl.Debug = p->rio_debug;
901 DebugCtrl.Wait = p->RIODebugWait; 765 DebugCtrl.Wait = p->RIODebugWait;
902 if (copyout((caddr_t) & DebugCtrl, (int) arg, sizeof(DebugCtrl)) == COPYFAIL) { 766 if (copy_to_user(arg, &DebugCtrl, sizeof(DebugCtrl))) {
903 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET/GET DEBUG: bad port number %d\n", DebugCtrl.SysPort); 767 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET/GET DEBUG: bad port number %d\n", DebugCtrl.SysPort);
904 p->RIOError.Error = COPYOUT_FAILED; 768 p->RIOError.Error = COPYOUT_FAILED;
905 return -EFAULT; 769 return -EFAULT;
@@ -921,7 +785,7 @@ int su;
921 } else { 785 } else {
922 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GETDEBUG 0x%x\n", p->RIOPortp[DebugCtrl.SysPort]->Debug); 786 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GETDEBUG 0x%x\n", p->RIOPortp[DebugCtrl.SysPort]->Debug);
923 DebugCtrl.Debug = p->RIOPortp[DebugCtrl.SysPort]->Debug; 787 DebugCtrl.Debug = p->RIOPortp[DebugCtrl.SysPort]->Debug;
924 if (copyout((caddr_t) & DebugCtrl, (int) arg, sizeof(DebugCtrl)) == COPYFAIL) { 788 if (copy_to_user(arg, &DebugCtrl, sizeof(DebugCtrl))) {
925 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GETDEBUG: Bad copy to user space\n"); 789 rio_dprintk(RIO_DEBUG_CTRL, "RIO_GETDEBUG: Bad copy to user space\n");
926 p->RIOError.Error = COPYOUT_FAILED; 790 p->RIOError.Error = COPYOUT_FAILED;
927 return -EFAULT; 791 return -EFAULT;
@@ -936,43 +800,20 @@ int su;
936 ** textual null terminated string. 800 ** textual null terminated string.
937 */ 801 */
938 rio_dprintk(RIO_DEBUG_CTRL, "RIO_VERSID\n"); 802 rio_dprintk(RIO_DEBUG_CTRL, "RIO_VERSID\n");
939 if (copyout((caddr_t) RIOVersid(), (int) arg, sizeof(struct rioVersion)) == COPYFAIL) { 803 if (copy_to_user(arg, RIOVersid(), sizeof(struct rioVersion))) {
940 rio_dprintk(RIO_DEBUG_CTRL, "RIO_VERSID: Bad copy to user space (host=%d)\n", Host); 804 rio_dprintk(RIO_DEBUG_CTRL, "RIO_VERSID: Bad copy to user space (host=%d)\n", Host);
941 p->RIOError.Error = COPYOUT_FAILED; 805 p->RIOError.Error = COPYOUT_FAILED;
942 return -EFAULT; 806 return -EFAULT;
943 } 807 }
944 return retval; 808 return retval;
945 809
946 /*
947 ** !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
948 ** !! commented out previous 'RIO_VERSID' functionality !!
949 ** !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
950 **
951 case RIO_VERSID:
952 **
953 ** Enquire about the release and version.
954 ** We return MAX_VERSION_LEN bytes, being a textual null
955 ** terminated string.
956 **
957 rio_dprint(RIO_DEBUG_CTRL, ("RIO_VERSID\n"));
958 if (copyout((caddr_t)RIOVersid(),
959 (int)arg, MAX_VERSION_LEN ) == COPYFAIL ) {
960 rio_dprint(RIO_DEBUG_CTRL, ("RIO_VERSID: Bad copy to user space\n",Host));
961 p->RIOError.Error = COPYOUT_FAILED;
962 return -EFAULT;
963 }
964 return retval;
965 **
966 ** !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
967 */
968
969 case RIO_NUM_HOSTS: 810 case RIO_NUM_HOSTS:
970 /* 811 /*
971 ** Enquire as to the number of hosts located 812 ** Enquire as to the number of hosts located
972 ** at init time. 813 ** at init time.
973 */ 814 */
974 rio_dprintk(RIO_DEBUG_CTRL, "RIO_NUM_HOSTS\n"); 815 rio_dprintk(RIO_DEBUG_CTRL, "RIO_NUM_HOSTS\n");
975 if (copyout((caddr_t) & p->RIONumHosts, (int) arg, sizeof(p->RIONumHosts)) == COPYFAIL) { 816 if (copy_to_user(arg, &p->RIONumHosts, sizeof(p->RIONumHosts))) {
976 rio_dprintk(RIO_DEBUG_CTRL, "RIO_NUM_HOSTS: Bad copy to user space\n"); 817 rio_dprintk(RIO_DEBUG_CTRL, "RIO_NUM_HOSTS: Bad copy to user space\n");
977 p->RIOError.Error = COPYOUT_FAILED; 818 p->RIOError.Error = COPYOUT_FAILED;
978 return -EFAULT; 819 return -EFAULT;
@@ -983,7 +824,7 @@ int su;
983 /* 824 /*
984 ** Kill host. This may not be in the final version... 825 ** Kill host. This may not be in the final version...
985 */ 826 */
986 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_FOAD %d\n", (int) arg); 827 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_FOAD %ld\n", (unsigned long) arg);
987 if (!su) { 828 if (!su) {
988 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_FOAD: Not super user\n"); 829 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_FOAD: Not super user\n");
989 p->RIOError.Error = NOT_SUPER_USER; 830 p->RIOError.Error = NOT_SUPER_USER;
@@ -994,7 +835,7 @@ int su;
994 835
995 for (Host = 0; Host < p->RIONumHosts; Host++) { 836 for (Host = 0; Host < p->RIONumHosts; Host++) {
996 (void) RIOBoardTest(p->RIOHosts[Host].PaddrP, p->RIOHosts[Host].Caddr, p->RIOHosts[Host].Type, p->RIOHosts[Host].Slot); 837 (void) RIOBoardTest(p->RIOHosts[Host].PaddrP, p->RIOHosts[Host].Caddr, p->RIOHosts[Host].Type, p->RIOHosts[Host].Slot);
997 bzero((caddr_t) & p->RIOHosts[Host].Flags, ((int) &p->RIOHosts[Host].____end_marker____) - ((int) &p->RIOHosts[Host].Flags)); 838 memset(&p->RIOHosts[Host].Flags, 0, ((char *) &p->RIOHosts[Host].____end_marker____) - ((char *) &p->RIOHosts[Host].Flags));
998 p->RIOHosts[Host].Flags = RC_WAITING; 839 p->RIOHosts[Host].Flags = RC_WAITING;
999 } 840 }
1000 RIOFoadWakeup(p); 841 RIOFoadWakeup(p);
@@ -1017,7 +858,7 @@ int su;
1017 p->RIOError.Error = NOT_SUPER_USER; 858 p->RIOError.Error = NOT_SUPER_USER;
1018 return -EPERM; 859 return -EPERM;
1019 } 860 }
1020 if (copyin((int) arg, (caddr_t) & DownLoad, sizeof(DownLoad)) == COPYFAIL) { 861 if (copy_from_user(&DownLoad, arg, sizeof(DownLoad))) {
1021 rio_dprintk(RIO_DEBUG_CTRL, "RIO_DOWNLOAD: Copy in from user space failed\n"); 862 rio_dprintk(RIO_DEBUG_CTRL, "RIO_DOWNLOAD: Copy in from user space failed\n");
1022 p->RIOError.Error = COPYIN_FAILED; 863 p->RIOError.Error = COPYIN_FAILED;
1023 return -EFAULT; 864 return -EFAULT;
@@ -1045,9 +886,9 @@ int su;
1045 886
1046 case RIO_PARMS: 887 case RIO_PARMS:
1047 { 888 {
1048 uint host; 889 unsigned int host;
1049 890
1050 if (copyin((int) arg, (caddr_t) & host, sizeof(host)) == COPYFAIL) { 891 if (copy_from_user(&host, arg, sizeof(host))) {
1051 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ: Copy in from user space failed\n"); 892 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ: Copy in from user space failed\n");
1052 p->RIOError.Error = COPYIN_FAILED; 893 p->RIOError.Error = COPYIN_FAILED;
1053 return -EFAULT; 894 return -EFAULT;
@@ -1056,7 +897,7 @@ int su;
1056 ** Fetch the parmmap 897 ** Fetch the parmmap
1057 */ 898 */
1058 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PARMS\n"); 899 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PARMS\n");
1059 if (copyout((caddr_t) p->RIOHosts[host].ParmMapP, (int) arg, sizeof(PARM_MAP)) == COPYFAIL) { 900 if (copy_to_user(arg, p->RIOHosts[host].ParmMapP, sizeof(PARM_MAP))) {
1060 p->RIOError.Error = COPYOUT_FAILED; 901 p->RIOError.Error = COPYOUT_FAILED;
1061 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PARMS: Copy out to user space failed\n"); 902 rio_dprintk(RIO_DEBUG_CTRL, "RIO_PARMS: Copy out to user space failed\n");
1062 return -EFAULT; 903 return -EFAULT;
@@ -1066,7 +907,7 @@ int su;
1066 907
1067 case RIO_HOST_REQ: 908 case RIO_HOST_REQ:
1068 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ\n"); 909 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ\n");
1069 if (copyin((int) arg, (caddr_t) & HostReq, sizeof(HostReq)) == COPYFAIL) { 910 if (copy_from_user(&HostReq, arg, sizeof(HostReq))) {
1070 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ: Copy in from user space failed\n"); 911 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ: Copy in from user space failed\n");
1071 p->RIOError.Error = COPYIN_FAILED; 912 p->RIOError.Error = COPYIN_FAILED;
1072 return -EFAULT; 913 return -EFAULT;
@@ -1078,7 +919,7 @@ int su;
1078 } 919 }
1079 rio_dprintk(RIO_DEBUG_CTRL, "Request for host %d\n", HostReq.HostNum); 920 rio_dprintk(RIO_DEBUG_CTRL, "Request for host %d\n", HostReq.HostNum);
1080 921
1081 if (copyout((caddr_t) & p->RIOHosts[HostReq.HostNum], (int) HostReq.HostP, sizeof(struct Host)) == COPYFAIL) { 922 if (copy_to_user(HostReq.HostP, &p->RIOHosts[HostReq.HostNum], sizeof(struct Host))) {
1082 p->RIOError.Error = COPYOUT_FAILED; 923 p->RIOError.Error = COPYOUT_FAILED;
1083 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ: Bad copy to user space\n"); 924 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ: Bad copy to user space\n");
1084 return -EFAULT; 925 return -EFAULT;
@@ -1087,7 +928,7 @@ int su;
1087 928
1088 case RIO_HOST_DPRAM: 929 case RIO_HOST_DPRAM:
1089 rio_dprintk(RIO_DEBUG_CTRL, "Request for DPRAM\n"); 930 rio_dprintk(RIO_DEBUG_CTRL, "Request for DPRAM\n");
1090 if (copyin((int) arg, (caddr_t) & HostDpRam, sizeof(HostDpRam)) == COPYFAIL) { 931 if (copy_from_user(&HostDpRam, arg, sizeof(HostDpRam))) {
1091 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_DPRAM: Copy in from user space failed\n"); 932 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_DPRAM: Copy in from user space failed\n");
1092 p->RIOError.Error = COPYIN_FAILED; 933 p->RIOError.Error = COPYIN_FAILED;
1093 return -EFAULT; 934 return -EFAULT;
@@ -1104,13 +945,13 @@ int su;
1104 /* It's hardware like this that really gets on my tits. */ 945 /* It's hardware like this that really gets on my tits. */
1105 static unsigned char copy[sizeof(struct DpRam)]; 946 static unsigned char copy[sizeof(struct DpRam)];
1106 for (off = 0; off < sizeof(struct DpRam); off++) 947 for (off = 0; off < sizeof(struct DpRam); off++)
1107 copy[off] = p->RIOHosts[HostDpRam.HostNum].Caddr[off]; 948 copy[off] = readb(&p->RIOHosts[HostDpRam.HostNum].Caddr[off]);
1108 if (copyout((caddr_t) copy, (int) HostDpRam.DpRamP, sizeof(struct DpRam)) == COPYFAIL) { 949 if (copy_to_user(HostDpRam.DpRamP, copy, sizeof(struct DpRam))) {
1109 p->RIOError.Error = COPYOUT_FAILED; 950 p->RIOError.Error = COPYOUT_FAILED;
1110 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_DPRAM: Bad copy to user space\n"); 951 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_DPRAM: Bad copy to user space\n");
1111 return -EFAULT; 952 return -EFAULT;
1112 } 953 }
1113 } else if (copyout((caddr_t) p->RIOHosts[HostDpRam.HostNum].Caddr, (int) HostDpRam.DpRamP, sizeof(struct DpRam)) == COPYFAIL) { 954 } else if (copy_to_user(HostDpRam.DpRamP, p->RIOHosts[HostDpRam.HostNum].Caddr, sizeof(struct DpRam))) {
1114 p->RIOError.Error = COPYOUT_FAILED; 955 p->RIOError.Error = COPYOUT_FAILED;
1115 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_DPRAM: Bad copy to user space\n"); 956 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_DPRAM: Bad copy to user space\n");
1116 return -EFAULT; 957 return -EFAULT;
@@ -1119,13 +960,13 @@ int su;
1119 960
1120 case RIO_SET_BUSY: 961 case RIO_SET_BUSY:
1121 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET_BUSY\n"); 962 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET_BUSY\n");
1122 if ((int) arg < 0 || (int) arg > 511) { 963 if ((unsigned long) arg > 511) {
1123 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET_BUSY: Bad port number %d\n", (int) arg); 964 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET_BUSY: Bad port number %ld\n", (unsigned long) arg);
1124 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE; 965 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
1125 return -EINVAL; 966 return -EINVAL;
1126 } 967 }
1127 rio_spin_lock_irqsave(&PortP->portSem, flags); 968 rio_spin_lock_irqsave(&PortP->portSem, flags);
1128 p->RIOPortp[(int) arg]->State |= RIO_BUSY; 969 p->RIOPortp[(unsigned long) arg]->State |= RIO_BUSY;
1129 rio_spin_unlock_irqrestore(&PortP->portSem, flags); 970 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1130 return retval; 971 return retval;
1131 972
@@ -1135,7 +976,7 @@ int su;
1135 ** (probably for debug reasons) 976 ** (probably for debug reasons)
1136 */ 977 */
1137 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_PORT\n"); 978 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_PORT\n");
1138 if (copyin((int) arg, (caddr_t) & PortReq, sizeof(PortReq)) == COPYFAIL) { 979 if (copy_from_user(&PortReq, arg, sizeof(PortReq))) {
1139 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_PORT: Copy in from user space failed\n"); 980 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_PORT: Copy in from user space failed\n");
1140 p->RIOError.Error = COPYIN_FAILED; 981 p->RIOError.Error = COPYIN_FAILED;
1141 return -EFAULT; 982 return -EFAULT;
@@ -1147,7 +988,7 @@ int su;
1147 return -ENXIO; 988 return -ENXIO;
1148 } 989 }
1149 rio_dprintk(RIO_DEBUG_CTRL, "Request for port %d\n", PortReq.SysPort); 990 rio_dprintk(RIO_DEBUG_CTRL, "Request for port %d\n", PortReq.SysPort);
1150 if (copyout((caddr_t) p->RIOPortp[PortReq.SysPort], (int) PortReq.PortP, sizeof(struct Port)) == COPYFAIL) { 991 if (copy_to_user(PortReq.PortP, p->RIOPortp[PortReq.SysPort], sizeof(struct Port))) {
1151 p->RIOError.Error = COPYOUT_FAILED; 992 p->RIOError.Error = COPYOUT_FAILED;
1152 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_PORT: Bad copy to user space\n"); 993 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_PORT: Bad copy to user space\n");
1153 return -EFAULT; 994 return -EFAULT;
@@ -1160,7 +1001,7 @@ int su;
1160 ** (probably for debug reasons) 1001 ** (probably for debug reasons)
1161 */ 1002 */
1162 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP\n"); 1003 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP\n");
1163 if (copyin((int) arg, (caddr_t) & RupReq, sizeof(RupReq)) == COPYFAIL) { 1004 if (copy_from_user(&RupReq, arg, sizeof(RupReq))) {
1164 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP: Copy in from user space failed\n"); 1005 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP: Copy in from user space failed\n");
1165 p->RIOError.Error = COPYIN_FAILED; 1006 p->RIOError.Error = COPYIN_FAILED;
1166 return -EFAULT; 1007 return -EFAULT;
@@ -1184,7 +1025,7 @@ int su;
1184 } 1025 }
1185 rio_dprintk(RIO_DEBUG_CTRL, "Request for rup %d from host %d\n", RupReq.RupNum, RupReq.HostNum); 1026 rio_dprintk(RIO_DEBUG_CTRL, "Request for rup %d from host %d\n", RupReq.RupNum, RupReq.HostNum);
1186 1027
1187 if (copyout((caddr_t) HostP->UnixRups[RupReq.RupNum].RupP, (int) RupReq.RupP, sizeof(struct RUP)) == COPYFAIL) { 1028 if (copy_to_user(HostP->UnixRups[RupReq.RupNum].RupP, RupReq.RupP, sizeof(struct RUP))) {
1188 p->RIOError.Error = COPYOUT_FAILED; 1029 p->RIOError.Error = COPYOUT_FAILED;
1189 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP: Bad copy to user space\n"); 1030 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP: Bad copy to user space\n");
1190 return -EFAULT; 1031 return -EFAULT;
@@ -1197,7 +1038,7 @@ int su;
1197 ** (probably for debug reasons) 1038 ** (probably for debug reasons)
1198 */ 1039 */
1199 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB\n"); 1040 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB\n");
1200 if (copyin((int) arg, (caddr_t) & LpbReq, sizeof(LpbReq)) == COPYFAIL) { 1041 if (copy_from_user(&LpbReq, arg, sizeof(LpbReq))) {
1201 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB: Bad copy from user space\n"); 1042 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB: Bad copy from user space\n");
1202 p->RIOError.Error = COPYIN_FAILED; 1043 p->RIOError.Error = COPYIN_FAILED;
1203 return -EFAULT; 1044 return -EFAULT;
@@ -1221,7 +1062,7 @@ int su;
1221 } 1062 }
1222 rio_dprintk(RIO_DEBUG_CTRL, "Request for lpb %d from host %d\n", LpbReq.Link, LpbReq.Host); 1063 rio_dprintk(RIO_DEBUG_CTRL, "Request for lpb %d from host %d\n", LpbReq.Link, LpbReq.Host);
1223 1064
1224 if (copyout((caddr_t) & HostP->LinkStrP[LpbReq.Link], (int) LpbReq.LpbP, sizeof(struct LPB)) == COPYFAIL) { 1065 if (copy_to_user(LpbReq.LpbP, &HostP->LinkStrP[LpbReq.Link], sizeof(struct LPB))) {
1225 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB: Bad copy to user space\n"); 1066 rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB: Bad copy to user space\n");
1226 p->RIOError.Error = COPYOUT_FAILED; 1067 p->RIOError.Error = COPYOUT_FAILED;
1227 return -EFAULT; 1068 return -EFAULT;
@@ -1252,12 +1093,13 @@ int su;
1252 p->RIOError.Error = SIGNALS_ALREADY_SET; 1093 p->RIOError.Error = SIGNALS_ALREADY_SET;
1253 return -EBUSY; 1094 return -EBUSY;
1254 } 1095 }
1255 p->RIOSignalProcess = getpid(); 1096 /* FIXME: PID tracking */
1097 p->RIOSignalProcess = current->pid;
1256 p->RIOPrintDisabled = DONT_PRINT; 1098 p->RIOPrintDisabled = DONT_PRINT;
1257 return retval; 1099 return retval;
1258 1100
1259 case RIO_SIGNALS_OFF: 1101 case RIO_SIGNALS_OFF:
1260 if (p->RIOSignalProcess != getpid()) { 1102 if (p->RIOSignalProcess != current->pid) {
1261 p->RIOError.Error = NOT_RECEIVING_PROCESS; 1103 p->RIOError.Error = NOT_RECEIVING_PROCESS;
1262 return -EPERM; 1104 return -EPERM;
1263 } 1105 }
@@ -1294,7 +1136,7 @@ int su;
1294 case RIO_MAP_B110_TO_110: 1136 case RIO_MAP_B110_TO_110:
1295 case RIO_MAP_B110_TO_115200: 1137 case RIO_MAP_B110_TO_115200:
1296 rio_dprintk(RIO_DEBUG_CTRL, "Baud rate mapping\n"); 1138 rio_dprintk(RIO_DEBUG_CTRL, "Baud rate mapping\n");
1297 port = (uint) arg; 1139 port = (unsigned long) arg;
1298 if (port < 0 || port > 511) { 1140 if (port < 0 || port > 511) {
1299 rio_dprintk(RIO_DEBUG_CTRL, "Baud rate mapping: Bad port number %d\n", port); 1141 rio_dprintk(RIO_DEBUG_CTRL, "Baud rate mapping: Bad port number %d\n", port);
1300 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE; 1142 p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
@@ -1324,7 +1166,7 @@ int su;
1324 1166
1325 case RIO_SEND_PACKET: 1167 case RIO_SEND_PACKET:
1326 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SEND_PACKET\n"); 1168 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SEND_PACKET\n");
1327 if (copyin((int) arg, (caddr_t) & SendPack, sizeof(SendPack)) == COPYFAIL) { 1169 if (copy_from_user(&SendPack, arg, sizeof(SendPack))) {
1328 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SEND_PACKET: Bad copy from user space\n"); 1170 rio_dprintk(RIO_DEBUG_CTRL, "RIO_SEND_PACKET: Bad copy from user space\n");
1329 p->RIOError.Error = COPYIN_FAILED; 1171 p->RIOError.Error = COPYIN_FAILED;
1330 return -EFAULT; 1172 return -EFAULT;
@@ -1344,9 +1186,9 @@ int su;
1344 } 1186 }
1345 1187
1346 for (loop = 0; loop < (ushort) (SendPack.Len & 127); loop++) 1188 for (loop = 0; loop < (ushort) (SendPack.Len & 127); loop++)
1347 WBYTE(PacketP->data[loop], SendPack.Data[loop]); 1189 writeb(SendPack.Data[loop], &PacketP->data[loop]);
1348 1190
1349 WBYTE(PacketP->len, SendPack.Len); 1191 writeb(SendPack.Len, &PacketP->len);
1350 1192
1351 add_transmit(PortP); 1193 add_transmit(PortP);
1352 /* 1194 /*
@@ -1368,7 +1210,7 @@ int su;
1368 return su ? 0 : -EPERM; 1210 return su ? 0 : -EPERM;
1369 1211
1370 case RIO_WHAT_MESG: 1212 case RIO_WHAT_MESG:
1371 if (copyout((caddr_t) & p->RIONoMessage, (int) arg, sizeof(p->RIONoMessage)) == COPYFAIL) { 1213 if (copy_to_user(arg, &p->RIONoMessage, sizeof(p->RIONoMessage))) {
1372 rio_dprintk(RIO_DEBUG_CTRL, "RIO_WHAT_MESG: Bad copy to user space\n"); 1214 rio_dprintk(RIO_DEBUG_CTRL, "RIO_WHAT_MESG: Bad copy to user space\n");
1373 p->RIOError.Error = COPYOUT_FAILED; 1215 p->RIOError.Error = COPYOUT_FAILED;
1374 return -EFAULT; 1216 return -EFAULT;
@@ -1376,7 +1218,7 @@ int su;
1376 return 0; 1218 return 0;
1377 1219
1378 case RIO_MEM_DUMP: 1220 case RIO_MEM_DUMP:
1379 if (copyin((int) arg, (caddr_t) & SubCmd, sizeof(struct SubCmdStruct)) == COPYFAIL) { 1221 if (copy_from_user(&SubCmd, arg, sizeof(struct SubCmdStruct))) {
1380 p->RIOError.Error = COPYIN_FAILED; 1222 p->RIOError.Error = COPYIN_FAILED;
1381 return -EFAULT; 1223 return -EFAULT;
1382 } 1224 }
@@ -1406,7 +1248,7 @@ int su;
1406 PortP->State |= RIO_BUSY; 1248 PortP->State |= RIO_BUSY;
1407 1249
1408 rio_spin_unlock_irqrestore(&PortP->portSem, flags); 1250 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1409 if (copyout((caddr_t) p->RIOMemDump, (int) arg, MEMDUMP_SIZE) == COPYFAIL) { 1251 if (copy_to_user(arg, p->RIOMemDump, MEMDUMP_SIZE)) {
1410 rio_dprintk(RIO_DEBUG_CTRL, "RIO_MEM_DUMP copy failed\n"); 1252 rio_dprintk(RIO_DEBUG_CTRL, "RIO_MEM_DUMP copy failed\n");
1411 p->RIOError.Error = COPYOUT_FAILED; 1253 p->RIOError.Error = COPYOUT_FAILED;
1412 return -EFAULT; 1254 return -EFAULT;
@@ -1414,30 +1256,30 @@ int su;
1414 return 0; 1256 return 0;
1415 1257
1416 case RIO_TICK: 1258 case RIO_TICK:
1417 if ((int) arg < 0 || (int) arg >= p->RIONumHosts) 1259 if ((unsigned long) arg >= p->RIONumHosts)
1418 return -EINVAL; 1260 return -EINVAL;
1419 rio_dprintk(RIO_DEBUG_CTRL, "Set interrupt for host %d\n", (int) arg); 1261 rio_dprintk(RIO_DEBUG_CTRL, "Set interrupt for host %ld\n", (unsigned long) arg);
1420 WBYTE(p->RIOHosts[(int) arg].SetInt, 0xff); 1262 writeb(0xFF, &p->RIOHosts[(unsigned long) arg].SetInt);
1421 return 0; 1263 return 0;
1422 1264
1423 case RIO_TOCK: 1265 case RIO_TOCK:
1424 if ((int) arg < 0 || (int) arg >= p->RIONumHosts) 1266 if ((unsigned long) arg >= p->RIONumHosts)
1425 return -EINVAL; 1267 return -EINVAL;
1426 rio_dprintk(RIO_DEBUG_CTRL, "Clear interrupt for host %d\n", (int) arg); 1268 rio_dprintk(RIO_DEBUG_CTRL, "Clear interrupt for host %ld\n", (unsigned long) arg);
1427 WBYTE((p->RIOHosts[(int) arg].ResetInt), 0xff); 1269 writeb(0xFF, &p->RIOHosts[(unsigned long) arg].ResetInt);
1428 return 0; 1270 return 0;
1429 1271
1430 case RIO_READ_CHECK: 1272 case RIO_READ_CHECK:
1431 /* Check reads for pkts with data[0] the same */ 1273 /* Check reads for pkts with data[0] the same */
1432 p->RIOReadCheck = !p->RIOReadCheck; 1274 p->RIOReadCheck = !p->RIOReadCheck;
1433 if (copyout((caddr_t) & p->RIOReadCheck, (int) arg, sizeof(uint)) == COPYFAIL) { 1275 if (copy_to_user(arg, &p->RIOReadCheck, sizeof(unsigned int))) {
1434 p->RIOError.Error = COPYOUT_FAILED; 1276 p->RIOError.Error = COPYOUT_FAILED;
1435 return -EFAULT; 1277 return -EFAULT;
1436 } 1278 }
1437 return 0; 1279 return 0;
1438 1280
1439 case RIO_READ_REGISTER: 1281 case RIO_READ_REGISTER:
1440 if (copyin((int) arg, (caddr_t) & SubCmd, sizeof(struct SubCmdStruct)) == COPYFAIL) { 1282 if (copy_from_user(&SubCmd, arg, sizeof(struct SubCmdStruct))) {
1441 p->RIOError.Error = COPYIN_FAILED; 1283 p->RIOError.Error = COPYIN_FAILED;
1442 return -EFAULT; 1284 return -EFAULT;
1443 } 1285 }
@@ -1472,7 +1314,7 @@ int su;
1472 PortP->State |= RIO_BUSY; 1314 PortP->State |= RIO_BUSY;
1473 1315
1474 rio_spin_unlock_irqrestore(&PortP->portSem, flags); 1316 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1475 if (copyout((caddr_t) & p->CdRegister, (int) arg, sizeof(uint)) == COPYFAIL) { 1317 if (copy_to_user(arg, &p->CdRegister, sizeof(unsigned int))) {
1476 rio_dprintk(RIO_DEBUG_CTRL, "RIO_READ_REGISTER copy failed\n"); 1318 rio_dprintk(RIO_DEBUG_CTRL, "RIO_READ_REGISTER copy failed\n");
1477 p->RIOError.Error = COPYOUT_FAILED; 1319 p->RIOError.Error = COPYOUT_FAILED;
1478 return -EFAULT; 1320 return -EFAULT;
@@ -1485,21 +1327,22 @@ int su;
1485 */ 1327 */
1486 case RIO_MAKE_DEV: 1328 case RIO_MAKE_DEV:
1487 { 1329 {
1488 uint port = (uint) arg & RIO_MODEM_MASK; 1330 unsigned int port = (unsigned long) arg & RIO_MODEM_MASK;
1331 unsigned int ret;
1489 1332
1490 switch ((uint) arg & RIO_DEV_MASK) { 1333 switch ((unsigned long) arg & RIO_DEV_MASK) {
1491 case RIO_DEV_DIRECT: 1334 case RIO_DEV_DIRECT:
1492 arg = (caddr_t) drv_makedev(MAJOR(dev), port); 1335 ret = drv_makedev(MAJOR(dev), port);
1493 rio_dprintk(RIO_DEBUG_CTRL, "Makedev direct 0x%x is 0x%x\n", port, (int) arg); 1336 rio_dprintk(RIO_DEBUG_CTRL, "Makedev direct 0x%x is 0x%x\n", port, ret);
1494 return (int) arg; 1337 return ret;
1495 case RIO_DEV_MODEM: 1338 case RIO_DEV_MODEM:
1496 arg = (caddr_t) drv_makedev(MAJOR(dev), (port | RIO_MODEM_BIT)); 1339 ret = drv_makedev(MAJOR(dev), (port | RIO_MODEM_BIT));
1497 rio_dprintk(RIO_DEBUG_CTRL, "Makedev modem 0x%x is 0x%x\n", port, (int) arg); 1340 rio_dprintk(RIO_DEBUG_CTRL, "Makedev modem 0x%x is 0x%x\n", port, ret);
1498 return (int) arg; 1341 return ret;
1499 case RIO_DEV_XPRINT: 1342 case RIO_DEV_XPRINT:
1500 arg = (caddr_t) drv_makedev(MAJOR(dev), port); 1343 ret = drv_makedev(MAJOR(dev), port);
1501 rio_dprintk(RIO_DEBUG_CTRL, "Makedev printer 0x%x is 0x%x\n", port, (int) arg); 1344 rio_dprintk(RIO_DEBUG_CTRL, "Makedev printer 0x%x is 0x%x\n", port, ret);
1502 return (int) arg; 1345 return ret;
1503 } 1346 }
1504 rio_dprintk(RIO_DEBUG_CTRL, "MAKE Device is called\n"); 1347 rio_dprintk(RIO_DEBUG_CTRL, "MAKE Device is called\n");
1505 return -EINVAL; 1348 return -EINVAL;
@@ -1513,18 +1356,19 @@ int su;
1513 { 1356 {
1514 dev_t dv; 1357 dev_t dv;
1515 int mino; 1358 int mino;
1359 unsigned long ret;
1516 1360
1517 dv = (dev_t) ((int) arg); 1361 dv = (dev_t) ((unsigned long) arg);
1518 mino = RIO_UNMODEM(dv); 1362 mino = RIO_UNMODEM(dv);
1519 1363
1520 if (RIO_ISMODEM(dv)) { 1364 if (RIO_ISMODEM(dv)) {
1521 rio_dprintk(RIO_DEBUG_CTRL, "Minor for device 0x%x: modem %d\n", dv, mino); 1365 rio_dprintk(RIO_DEBUG_CTRL, "Minor for device 0x%x: modem %d\n", dv, mino);
1522 arg = (caddr_t) (mino | RIO_DEV_MODEM); 1366 ret = mino | RIO_DEV_MODEM;
1523 } else { 1367 } else {
1524 rio_dprintk(RIO_DEBUG_CTRL, "Minor for device 0x%x: direct %d\n", dv, mino); 1368 rio_dprintk(RIO_DEBUG_CTRL, "Minor for device 0x%x: direct %d\n", dv, mino);
1525 arg = (caddr_t) (mino | RIO_DEV_DIRECT); 1369 ret = mino | RIO_DEV_DIRECT;
1526 } 1370 }
1527 return (int) arg; 1371 return ret;
1528 } 1372 }
1529 } 1373 }
1530 rio_dprintk(RIO_DEBUG_CTRL, "INVALID DAEMON IOCTL 0x%x\n", cmd); 1374 rio_dprintk(RIO_DEBUG_CTRL, "INVALID DAEMON IOCTL 0x%x\n", cmd);
@@ -1537,10 +1381,7 @@ int su;
1537/* 1381/*
1538** Pre-emptive commands go on RUPs and are only one byte long. 1382** Pre-emptive commands go on RUPs and are only one byte long.
1539*/ 1383*/
1540int RIOPreemptiveCmd(p, PortP, Cmd) 1384int RIOPreemptiveCmd(struct rio_info *p, struct Port *PortP, u8 Cmd)
1541struct rio_info *p;
1542struct Port *PortP;
1543uchar Cmd;
1544{ 1385{
1545 struct CmdBlk *CmdBlkP; 1386 struct CmdBlk *CmdBlkP;
1546 struct PktCmd_M *PktCmdP; 1387 struct PktCmd_M *PktCmdP;
@@ -1558,7 +1399,7 @@ uchar Cmd;
1558 return RIO_FAIL; 1399 return RIO_FAIL;
1559 } 1400 }
1560 1401
1561 rio_dprintk(RIO_DEBUG_CTRL, "Command blk 0x%x - InUse now %d\n", (int) CmdBlkP, PortP->InUse); 1402 rio_dprintk(RIO_DEBUG_CTRL, "Command blk %p - InUse now %d\n", CmdBlkP, PortP->InUse);
1562 1403
1563 PktCmdP = (struct PktCmd_M *) &CmdBlkP->Packet.data[0]; 1404 PktCmdP = (struct PktCmd_M *) &CmdBlkP->Packet.data[0];
1564 1405
@@ -1572,7 +1413,7 @@ uchar Cmd;
1572 CmdBlkP->Packet.dest_port = COMMAND_RUP; 1413 CmdBlkP->Packet.dest_port = COMMAND_RUP;
1573 CmdBlkP->Packet.len = PKT_CMD_BIT | 2; 1414 CmdBlkP->Packet.len = PKT_CMD_BIT | 2;
1574 CmdBlkP->PostFuncP = RIOUnUse; 1415 CmdBlkP->PostFuncP = RIOUnUse;
1575 CmdBlkP->PostArg = (int) PortP; 1416 CmdBlkP->PostArg = (unsigned long) PortP;
1576 PktCmdP->Command = Cmd; 1417 PktCmdP->Command = Cmd;
1577 port = PortP->HostPort % (ushort) PORTS_PER_RTA; 1418 port = PortP->HostPort % (ushort) PORTS_PER_RTA;
1578 /* 1419 /*
@@ -1584,38 +1425,38 @@ uchar Cmd;
1584 1425
1585 switch (Cmd) { 1426 switch (Cmd) {
1586 case MEMDUMP: 1427 case MEMDUMP:
1587 rio_dprintk(RIO_DEBUG_CTRL, "Queue MEMDUMP command blk 0x%x (addr 0x%x)\n", (int) CmdBlkP, (int) SubCmd.Addr); 1428 rio_dprintk(RIO_DEBUG_CTRL, "Queue MEMDUMP command blk %p (addr 0x%x)\n", CmdBlkP, (int) SubCmd.Addr);
1588 PktCmdP->SubCommand = MEMDUMP; 1429 PktCmdP->SubCommand = MEMDUMP;
1589 PktCmdP->SubAddr = SubCmd.Addr; 1430 PktCmdP->SubAddr = SubCmd.Addr;
1590 break; 1431 break;
1591 case FCLOSE: 1432 case FCLOSE:
1592 rio_dprintk(RIO_DEBUG_CTRL, "Queue FCLOSE command blk 0x%x\n", (int) CmdBlkP); 1433 rio_dprintk(RIO_DEBUG_CTRL, "Queue FCLOSE command blk %p\n", CmdBlkP);
1593 break; 1434 break;
1594 case READ_REGISTER: 1435 case READ_REGISTER:
1595 rio_dprintk(RIO_DEBUG_CTRL, "Queue READ_REGISTER (0x%x) command blk 0x%x\n", (int) SubCmd.Addr, (int) CmdBlkP); 1436 rio_dprintk(RIO_DEBUG_CTRL, "Queue READ_REGISTER (0x%x) command blk %p\n", (int) SubCmd.Addr, CmdBlkP);
1596 PktCmdP->SubCommand = READ_REGISTER; 1437 PktCmdP->SubCommand = READ_REGISTER;
1597 PktCmdP->SubAddr = SubCmd.Addr; 1438 PktCmdP->SubAddr = SubCmd.Addr;
1598 break; 1439 break;
1599 case RESUME: 1440 case RESUME:
1600 rio_dprintk(RIO_DEBUG_CTRL, "Queue RESUME command blk 0x%x\n", (int) CmdBlkP); 1441 rio_dprintk(RIO_DEBUG_CTRL, "Queue RESUME command blk %p\n", CmdBlkP);
1601 break; 1442 break;
1602 case RFLUSH: 1443 case RFLUSH:
1603 rio_dprintk(RIO_DEBUG_CTRL, "Queue RFLUSH command blk 0x%x\n", (int) CmdBlkP); 1444 rio_dprintk(RIO_DEBUG_CTRL, "Queue RFLUSH command blk %p\n", CmdBlkP);
1604 CmdBlkP->PostFuncP = RIORFlushEnable; 1445 CmdBlkP->PostFuncP = RIORFlushEnable;
1605 break; 1446 break;
1606 case SUSPEND: 1447 case SUSPEND:
1607 rio_dprintk(RIO_DEBUG_CTRL, "Queue SUSPEND command blk 0x%x\n", (int) CmdBlkP); 1448 rio_dprintk(RIO_DEBUG_CTRL, "Queue SUSPEND command blk %p\n", CmdBlkP);
1608 break; 1449 break;
1609 1450
1610 case MGET: 1451 case MGET:
1611 rio_dprintk(RIO_DEBUG_CTRL, "Queue MGET command blk 0x%x\n", (int) CmdBlkP); 1452 rio_dprintk(RIO_DEBUG_CTRL, "Queue MGET command blk %p\n", CmdBlkP);
1612 break; 1453 break;
1613 1454
1614 case MSET: 1455 case MSET:
1615 case MBIC: 1456 case MBIC:
1616 case MBIS: 1457 case MBIS:
1617 CmdBlkP->Packet.data[4] = (char) PortP->ModemLines; 1458 CmdBlkP->Packet.data[4] = (char) PortP->ModemLines;
1618 rio_dprintk(RIO_DEBUG_CTRL, "Queue MSET/MBIC/MBIS command blk 0x%x\n", (int) CmdBlkP); 1459 rio_dprintk(RIO_DEBUG_CTRL, "Queue MSET/MBIC/MBIS command blk %p\n", CmdBlkP);
1619 break; 1460 break;
1620 1461
1621 case WFLUSH: 1462 case WFLUSH:
@@ -1629,7 +1470,7 @@ uchar Cmd;
1629 RIOFreeCmdBlk(CmdBlkP); 1470 RIOFreeCmdBlk(CmdBlkP);
1630 return (RIO_FAIL); 1471 return (RIO_FAIL);
1631 } else { 1472 } else {
1632 rio_dprintk(RIO_DEBUG_CTRL, "Queue WFLUSH command blk 0x%x\n", (int) CmdBlkP); 1473 rio_dprintk(RIO_DEBUG_CTRL, "Queue WFLUSH command blk %p\n", CmdBlkP);
1633 CmdBlkP->PostFuncP = RIOWFlushMark; 1474 CmdBlkP->PostFuncP = RIOWFlushMark;
1634 } 1475 }
1635 break; 1476 break;
diff --git a/drivers/char/rio/riodrvr.h b/drivers/char/rio/riodrvr.h
index 663ee0914e..3cffe275f2 100644
--- a/drivers/char/rio/riodrvr.h
+++ b/drivers/char/rio/riodrvr.h
@@ -72,42 +72,42 @@ struct rio_info {
72*/ 72*/
73 int RIOHalted; /* halted ? */ 73 int RIOHalted; /* halted ? */
74 int RIORtaDisCons; /* RTA connections/disconnections */ 74 int RIORtaDisCons; /* RTA connections/disconnections */
75 uint RIOReadCheck; /* Rio read check */ 75 unsigned int RIOReadCheck; /* Rio read check */
76 uint RIONoMessage; /* To display message or not */ 76 unsigned int RIONoMessage; /* To display message or not */
77 uint RIONumBootPkts; /* how many packets for an RTA */ 77 unsigned int RIONumBootPkts; /* how many packets for an RTA */
78 uint RIOBootCount; /* size of RTA code */ 78 unsigned int RIOBootCount; /* size of RTA code */
79 uint RIOBooting; /* count of outstanding boots */ 79 unsigned int RIOBooting; /* count of outstanding boots */
80 uint RIOSystemUp; /* Booted ?? */ 80 unsigned int RIOSystemUp; /* Booted ?? */
81 uint RIOCounting; /* for counting interrupts */ 81 unsigned int RIOCounting; /* for counting interrupts */
82 uint RIOIntCount; /* # of intr since last check */ 82 unsigned int RIOIntCount; /* # of intr since last check */
83 uint RIOTxCount; /* number of xmit intrs */ 83 unsigned int RIOTxCount; /* number of xmit intrs */
84 uint RIORxCount; /* number of rx intrs */ 84 unsigned int RIORxCount; /* number of rx intrs */
85 uint RIORupCount; /* number of rup intrs */ 85 unsigned int RIORupCount; /* number of rup intrs */
86 int RIXTimer; 86 int RIXTimer;
87 int RIOBufferSize; /* Buffersize */ 87 int RIOBufferSize; /* Buffersize */
88 int RIOBufferMask; /* Buffersize */ 88 int RIOBufferMask; /* Buffersize */
89 89
90 int RIOFirstMajor; /* First host card's major no */ 90 int RIOFirstMajor; /* First host card's major no */
91 91
92 uint RIOLastPortsMapped; /* highest port number known */ 92 unsigned int RIOLastPortsMapped; /* highest port number known */
93 uint RIOFirstPortsMapped; /* lowest port number known */ 93 unsigned int RIOFirstPortsMapped; /* lowest port number known */
94 94
95 uint RIOLastPortsBooted; /* highest port number running */ 95 unsigned int RIOLastPortsBooted; /* highest port number running */
96 uint RIOFirstPortsBooted; /* lowest port number running */ 96 unsigned int RIOFirstPortsBooted; /* lowest port number running */
97 97
98 uint RIOLastPortsOpened; /* highest port number running */ 98 unsigned int RIOLastPortsOpened; /* highest port number running */
99 uint RIOFirstPortsOpened; /* lowest port number running */ 99 unsigned int RIOFirstPortsOpened; /* lowest port number running */
100 100
101 /* Flag to say that the topology information has been changed. */ 101 /* Flag to say that the topology information has been changed. */
102 uint RIOQuickCheck; 102 unsigned int RIOQuickCheck;
103 uint CdRegister; /* ??? */ 103 unsigned int CdRegister; /* ??? */
104 int RIOSignalProcess; /* Signalling process */ 104 int RIOSignalProcess; /* Signalling process */
105 int rio_debug; /* To debug ... */ 105 int rio_debug; /* To debug ... */
106 int RIODebugWait; /* For what ??? */ 106 int RIODebugWait; /* For what ??? */
107 int tpri; /* Thread prio */ 107 int tpri; /* Thread prio */
108 int tid; /* Thread id */ 108 int tid; /* Thread id */
109 uint _RIO_Polled; /* Counter for polling */ 109 unsigned int _RIO_Polled; /* Counter for polling */
110 uint _RIO_Interrupted; /* Counter for interrupt */ 110 unsigned int _RIO_Interrupted; /* Counter for interrupt */
111 int intr_tid; /* iointset return value */ 111 int intr_tid; /* iointset return value */
112 int TxEnSem; /* TxEnable Semaphore */ 112 int TxEnSem; /* TxEnable Semaphore */
113 113
@@ -121,9 +121,9 @@ struct rio_info {
121 struct Map RIOSavedTable[TOTAL_MAP_ENTRIES]; 121 struct Map RIOSavedTable[TOTAL_MAP_ENTRIES];
122 122
123 /* RTA to host binding table for master/slave operation */ 123 /* RTA to host binding table for master/slave operation */
124 ulong RIOBindTab[MAX_RTA_BINDINGS]; 124 unsigned long RIOBindTab[MAX_RTA_BINDINGS];
125 /* RTA memory dump variable */ 125 /* RTA memory dump variable */
126 uchar RIOMemDump[MEMDUMP_SIZE]; 126 unsigned char RIOMemDump[MEMDUMP_SIZE];
127 struct ModuleInfo RIOModuleTypes[MAX_MODULE_TYPES]; 127 struct ModuleInfo RIOModuleTypes[MAX_MODULE_TYPES];
128 128
129}; 129};
@@ -138,7 +138,5 @@ struct rio_info {
138 138
139 139
140#define RIO_RESET_INT 0x7d80 140#define RIO_RESET_INT 0x7d80
141#define WRBYTE(x,y) *(volatile unsigned char *)((x)) = \
142 (unsigned char)(y)
143 141
144#endif /* __riodrvr.h */ 142#endif /* __riodrvr.h */
diff --git a/drivers/char/rio/rioinit.c b/drivers/char/rio/rioinit.c
index 0d44ef464e..24d2992154 100644
--- a/drivers/char/rio/rioinit.c
+++ b/drivers/char/rio/rioinit.c
@@ -51,15 +51,12 @@ static char *_rioinit_c_sccs_ = "@(#)rioinit.c 1.3";
51 51
52 52
53#include "linux_compat.h" 53#include "linux_compat.h"
54#include "typdef.h"
55#include "pkt.h" 54#include "pkt.h"
56#include "daemon.h" 55#include "daemon.h"
57#include "rio.h" 56#include "rio.h"
58#include "riospace.h" 57#include "riospace.h"
59#include "top.h"
60#include "cmdpkt.h" 58#include "cmdpkt.h"
61#include "map.h" 59#include "map.h"
62#include "riotypes.h"
63#include "rup.h" 60#include "rup.h"
64#include "port.h" 61#include "port.h"
65#include "riodrvr.h" 62#include "riodrvr.h"
@@ -72,22 +69,17 @@ static char *_rioinit_c_sccs_ = "@(#)rioinit.c 1.3";
72#include "unixrup.h" 69#include "unixrup.h"
73#include "board.h" 70#include "board.h"
74#include "host.h" 71#include "host.h"
75#include "error.h"
76#include "phb.h" 72#include "phb.h"
77#include "link.h" 73#include "link.h"
78#include "cmdblk.h" 74#include "cmdblk.h"
79#include "route.h" 75#include "route.h"
80#include "control.h"
81#include "cirrus.h" 76#include "cirrus.h"
82#include "rioioctl.h" 77#include "rioioctl.h"
83#include "rio_linux.h" 78#include "rio_linux.h"
84 79
85#undef bcopy
86#define bcopy rio_pcicopy
87
88int RIOPCIinit(struct rio_info *p, int Mode); 80int RIOPCIinit(struct rio_info *p, int Mode);
89 81
90static int RIOScrub(int, BYTE *, int); 82static int RIOScrub(int, u8 *, int);
91 83
92 84
93/** 85/**
@@ -99,12 +91,8 @@ static int RIOScrub(int, BYTE *, int);
99** bits < 0 indicates 8 bit operation requested, 91** bits < 0 indicates 8 bit operation requested,
100** bits > 0 indicates 16 bit operation. 92** bits > 0 indicates 16 bit operation.
101*/ 93*/
102int 94
103RIOAssignAT(p, Base, virtAddr, mode) 95int RIOAssignAT(struct rio_info *p, int Base, caddr_t virtAddr, int mode)
104struct rio_info * p;
105int Base;
106caddr_t virtAddr;
107int mode;
108{ 96{
109 int bits; 97 int bits;
110 struct DpRam *cardp = (struct DpRam *)virtAddr; 98 struct DpRam *cardp = (struct DpRam *)virtAddr;
@@ -124,29 +112,25 @@ int mode;
124 /* 112 /*
125 ** Revision 01 AT host cards don't support WORD operations, 113 ** Revision 01 AT host cards don't support WORD operations,
126 */ 114 */
127 if ( RBYTE(cardp->DpRevision) == 01 ) 115 if (readb(&cardp->DpRevision) == 01)
128 bits = BYTE_OPERATION; 116 bits = BYTE_OPERATION;
129 117
130 p->RIOHosts[p->RIONumHosts].Type = RIO_AT; 118 p->RIOHosts[p->RIONumHosts].Type = RIO_AT;
131 p->RIOHosts[p->RIONumHosts].Copy = bcopy; 119 p->RIOHosts[p->RIONumHosts].Copy = rio_copy_to_card;
132 /* set this later */ 120 /* set this later */
133 p->RIOHosts[p->RIONumHosts].Slot = -1; 121 p->RIOHosts[p->RIONumHosts].Slot = -1;
134 p->RIOHosts[p->RIONumHosts].Mode = SLOW_LINKS | SLOW_AT_BUS | bits; 122 p->RIOHosts[p->RIONumHosts].Mode = SLOW_LINKS | SLOW_AT_BUS | bits;
135 WBYTE(p->RIOHosts[p->RIONumHosts].Control, 123 writeb(BOOT_FROM_RAM | EXTERNAL_BUS_OFF | p->RIOHosts[p->RIONumHosts].Mode | INTERRUPT_DISABLE ,
136 BOOT_FROM_RAM | EXTERNAL_BUS_OFF | 124 &p->RIOHosts[p->RIONumHosts].Control);
137 p->RIOHosts[p->RIONumHosts].Mode | 125 writeb(0xFF, &p->RIOHosts[p->RIONumHosts].ResetInt);
138 INTERRUPT_DISABLE ); 126 writeb(BOOT_FROM_RAM | EXTERNAL_BUS_OFF | p->RIOHosts[p->RIONumHosts].Mode | INTERRUPT_DISABLE,
139 WBYTE(p->RIOHosts[p->RIONumHosts].ResetInt,0xff); 127 &p->RIOHosts[p->RIONumHosts].Control);
140 WBYTE(p->RIOHosts[p->RIONumHosts].Control, 128 writeb(0xFF, &p->RIOHosts[p->RIONumHosts].ResetInt);
141 BOOT_FROM_RAM | EXTERNAL_BUS_OFF |
142 p->RIOHosts[p->RIONumHosts].Mode |
143 INTERRUPT_DISABLE );
144 WBYTE(p->RIOHosts[p->RIONumHosts].ResetInt,0xff);
145 p->RIOHosts[p->RIONumHosts].UniqueNum = 129 p->RIOHosts[p->RIONumHosts].UniqueNum =
146 ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[0])&0xFF)<<0)| 130 ((readb(&p->RIOHosts[p->RIONumHosts].Unique[0])&0xFF)<<0)|
147 ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[1])&0xFF)<<8)| 131 ((readb(&p->RIOHosts[p->RIONumHosts].Unique[1])&0xFF)<<8)|
148 ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[2])&0xFF)<<16)| 132 ((readb(&p->RIOHosts[p->RIONumHosts].Unique[2])&0xFF)<<16)|
149 ((RBYTE(p->RIOHosts[p->RIONumHosts].Unique[3])&0xFF)<<24); 133 ((readb(&p->RIOHosts[p->RIONumHosts].Unique[3])&0xFF)<<24);
150 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Uniquenum 0x%x\n",p->RIOHosts[p->RIONumHosts].UniqueNum); 134 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Uniquenum 0x%x\n",p->RIOHosts[p->RIONumHosts].UniqueNum);
151 135
152 p->RIONumHosts++; 136 p->RIONumHosts++;
@@ -154,7 +138,7 @@ int mode;
154 return(1); 138 return(1);
155} 139}
156 140
157static uchar val[] = { 141static u8 val[] = {
158#ifdef VERY_LONG_TEST 142#ifdef VERY_LONG_TEST
159 0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 143 0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
160 0xa5, 0xff, 0x5a, 0x00, 0xff, 0xc9, 0x36, 144 0xa5, 0xff, 0x5a, 0x00, 0xff, 0xc9, 0x36,
@@ -167,12 +151,7 @@ static uchar val[] = {
167** RAM test a board. 151** RAM test a board.
168** Nothing too complicated, just enough to check it out. 152** Nothing too complicated, just enough to check it out.
169*/ 153*/
170int 154int RIOBoardTest(unsigned long paddr, caddr_t caddr, unsigned char type, int slot)
171RIOBoardTest(paddr, caddr, type, slot)
172paddr_t paddr;
173caddr_t caddr;
174uchar type;
175int slot;
176{ 155{
177 struct DpRam *DpRam = (struct DpRam *)caddr; 156 struct DpRam *DpRam = (struct DpRam *)caddr;
178 char *ram[4]; 157 char *ram[4];
@@ -180,8 +159,8 @@ int slot;
180 int op, bank; 159 int op, bank;
181 int nbanks; 160 int nbanks;
182 161
183 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Reset host type=%d, DpRam=0x%x, slot=%d\n", 162 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Reset host type=%d, DpRam=%p, slot=%d\n",
184 type,(int)DpRam, slot); 163 type, DpRam, slot);
185 164
186 RIOHostReset(type, DpRam, slot); 165 RIOHostReset(type, DpRam, slot);
187 166
@@ -209,12 +188,11 @@ int slot;
209 188
210 189
211 if (nbanks == 3) { 190 if (nbanks == 3) {
212 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Memory: 0x%x(0x%x), 0x%x(0x%x), 0x%x(0x%x)\n", 191 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Memory: %p(0x%x), %p(0x%x), %p(0x%x)\n",
213 (int)ram[0], size[0], (int)ram[1], size[1], (int)ram[2], size[2]); 192 ram[0], size[0], ram[1], size[1], ram[2], size[2]);
214 } else { 193 } else {
215 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: 0x%x(0x%x), 0x%x(0x%x), 0x%x(0x%x), 0x%x(0x%x)\n", 194 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: %p(0x%x), %p(0x%x), %p(0x%x), %p(0x%x)\n",
216 (int)ram[0], size[0], (int)ram[1], size[1], (int)ram[2], size[2], (int)ram[3], 195 ram[0], size[0], ram[1], size[1], ram[2], size[2], ram[3], size[3]);
217 size[3]);
218 } 196 }
219 197
220 /* 198 /*
@@ -224,7 +202,7 @@ int slot;
224 */ 202 */
225 for (op=0; op<TEST_END; op++) { 203 for (op=0; op<TEST_END; op++) {
226 for (bank=0; bank<nbanks; bank++) { 204 for (bank=0; bank<nbanks; bank++) {
227 if (RIOScrub(op, (BYTE *)ram[bank], size[bank]) == RIO_FAIL) { 205 if (RIOScrub(op, (u8 *)ram[bank], size[bank]) == RIO_FAIL) {
228 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: RIOScrub band %d, op %d failed\n", 206 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: RIOScrub band %d, op %d failed\n",
229 bank, op); 207 bank, op);
230 return RIO_FAIL; 208 return RIO_FAIL;
@@ -233,7 +211,7 @@ int slot;
233 } 211 }
234 212
235 rio_dprintk (RIO_DEBUG_INIT, "Test completed\n"); 213 rio_dprintk (RIO_DEBUG_INIT, "Test completed\n");
236 return RIO_SUCCESS; 214 return 0;
237} 215}
238 216
239 217
@@ -248,13 +226,10 @@ int slot;
248** Call with op not zero, and the RAM will be read and compated with val[op-1] 226** Call with op not zero, and the RAM will be read and compated with val[op-1]
249** to check that the data from the previous phase was retained. 227** to check that the data from the previous phase was retained.
250*/ 228*/
251static int 229
252RIOScrub(op, ram, size) 230static int RIOScrub(int op, u8 *ram, int size)
253int op;
254BYTE * ram;
255int size;
256{ 231{
257 int off; 232 int off;
258 unsigned char oldbyte; 233 unsigned char oldbyte;
259 unsigned char newbyte; 234 unsigned char newbyte;
260 unsigned char invbyte; 235 unsigned char invbyte;
@@ -279,15 +254,15 @@ int size;
279 */ 254 */
280 if (op) { 255 if (op) {
281 for (off=0; off<size; off++) { 256 for (off=0; off<size; off++) {
282 if (RBYTE(ram[off]) != oldbyte) { 257 if (readb(ram + off) != oldbyte) {
283 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Byte Pre Check 1: BYTE at offset 0x%x should have been=%x, was=%x\n", off, oldbyte, RBYTE(ram[off])); 258 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Byte Pre Check 1: BYTE at offset 0x%x should have been=%x, was=%x\n", off, oldbyte, readb(ram + off));
284 return RIO_FAIL; 259 return RIO_FAIL;
285 } 260 }
286 } 261 }
287 for (off=0; off<size; off+=2) { 262 for (off=0; off<size; off+=2) {
288 if (*(ushort *)&ram[off] != oldword) { 263 if (readw(ram + off) != oldword) {
289 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Word Pre Check: WORD at offset 0x%x should have been=%x, was=%x\n",off,oldword,*(ushort *)&ram[off]); 264 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Word Pre Check: WORD at offset 0x%x should have been=%x, was=%x\n",off,oldword, readw(ram + off));
290 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Word Pre Check: BYTE at offset 0x%x is %x BYTE at offset 0x%x is %x\n", off, RBYTE(ram[off]), off+1, RBYTE(ram[off+1])); 265 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Word Pre Check: BYTE at offset 0x%x is %x BYTE at offset 0x%x is %x\n", off, readb(ram + off), off+1, readb(ram+off+1));
291 return RIO_FAIL; 266 return RIO_FAIL;
292 } 267 }
293 } 268 }
@@ -301,13 +276,13 @@ int size;
301 ** the BYTE read/write test. 276 ** the BYTE read/write test.
302 */ 277 */
303 for (off=0; off<size; off++) { 278 for (off=0; off<size; off++) {
304 if (op && (RBYTE(ram[off]) != oldbyte)) { 279 if (op && (readb(ram + off) != oldbyte)) {
305 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Byte Pre Check 2: BYTE at offset 0x%x should have been=%x, was=%x\n", off, oldbyte, RBYTE(ram[off])); 280 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Byte Pre Check 2: BYTE at offset 0x%x should have been=%x, was=%x\n", off, oldbyte, readb(ram + off));
306 return RIO_FAIL; 281 return RIO_FAIL;
307 } 282 }
308 WBYTE(ram[off],invbyte); 283 writeb(invbyte, ram + off);
309 if (RBYTE(ram[off]) != invbyte) { 284 if (readb(ram + off) != invbyte) {
310 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Byte Inv Check: BYTE at offset 0x%x should have been=%x, was=%x\n", off, invbyte, RBYTE(ram[off])); 285 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Byte Inv Check: BYTE at offset 0x%x should have been=%x, was=%x\n", off, invbyte, readb(ram + off));
311 return RIO_FAIL; 286 return RIO_FAIL;
312 } 287 }
313 } 288 }
@@ -320,16 +295,16 @@ int size;
320 ** This is the WORD operation test. 295 ** This is the WORD operation test.
321 */ 296 */
322 for (off=0; off<size; off+=2) { 297 for (off=0; off<size; off+=2) {
323 if (*(ushort *)&ram[off] != invword) { 298 if (readw(ram + off) != invword) {
324 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Word Inv Check: WORD at offset 0x%x should have been=%x, was=%x\n", off, invword, *(ushort *)&ram[off]); 299 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Word Inv Check: WORD at offset 0x%x should have been=%x, was=%x\n", off, invword, readw(ram + off));
325 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Word Inv Check: BYTE at offset 0x%x is %x BYTE at offset 0x%x is %x\n", off, RBYTE(ram[off]), off+1, RBYTE(ram[off+1])); 300 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Word Inv Check: BYTE at offset 0x%x is %x BYTE at offset 0x%x is %x\n", off, readb(ram + off), off+1, readb(ram+off+1));
326 return RIO_FAIL; 301 return RIO_FAIL;
327 } 302 }
328 303
329 *(ushort *)&ram[off] = newword; 304 writew(newword, ram + off);
330 if ( *(ushort *)&ram[off] != newword ) { 305 if ( readw(ram + off) != newword ) {
331 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Post Word Check 1: WORD at offset 0x%x should have been=%x, was=%x\n", off, newword, *(ushort *)&ram[off]); 306 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Post Word Check 1: WORD at offset 0x%x should have been=%x, was=%x\n", off, newword, readw(ram + off));
332 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Post Word Check 1: BYTE at offset 0x%x is %x BYTE at offset 0x%x is %x\n", off, RBYTE(ram[off]), off+1, RBYTE(ram[off+1])); 307 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Post Word Check 1: BYTE at offset 0x%x is %x BYTE at offset 0x%x is %x\n", off, readb(ram + off), off+1, readb(ram + off + 1));
333 return RIO_FAIL; 308 return RIO_FAIL;
334 } 309 }
335 } 310 }
@@ -340,16 +315,16 @@ int size;
340 ** required test data. 315 ** required test data.
341 */ 316 */
342 for (off=0; off<size; off++) { 317 for (off=0; off<size; off++) {
343 if (RBYTE(ram[off]) != newbyte) { 318 if (readb(ram + off) != newbyte) {
344 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Post Byte Check: BYTE at offset 0x%x should have been=%x, was=%x\n", off, newbyte, RBYTE(ram[off])); 319 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Post Byte Check: BYTE at offset 0x%x should have been=%x, was=%x\n", off, newbyte, readb(ram + off));
345 return RIO_FAIL; 320 return RIO_FAIL;
346 } 321 }
347 } 322 }
348 323
349 for (off=0; off<size; off+=2) { 324 for (off=0; off<size; off+=2) {
350 if ( *(ushort *)&ram[off] != newword ) { 325 if (readw(ram + off) != newword ) {
351 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Post Word Check 2: WORD at offset 0x%x should have been=%x, was=%x\n", off, newword, *(ushort *)&ram[off]); 326 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Post Word Check 2: WORD at offset 0x%x should have been=%x, was=%x\n", off, newword, readw(ram + off));
352 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Post Word Check 2: BYTE at offset 0x%x is %x BYTE at offset 0x%x is %x\n", off, RBYTE(ram[off]), off+1, RBYTE(ram[off+1])); 327 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: Post Word Check 2: BYTE at offset 0x%x is %x BYTE at offset 0x%x is %x\n", off, readb(ram + off), off+1, readb(ram + off + 1));
353 return RIO_FAIL; 328 return RIO_FAIL;
354 } 329 }
355 } 330 }
@@ -360,41 +335,37 @@ int size;
360 swapword = invbyte | (newbyte << 8); 335 swapword = invbyte | (newbyte << 8);
361 336
362 for (off=0; off<size; off+=2) { 337 for (off=0; off<size; off+=2) {
363 WBYTE(ram[off],invbyte); 338 writeb(invbyte, &ram[off]);
364 WBYTE(ram[off+1],newbyte); 339 writeb(newbyte, &ram[off+1]);
365 } 340 }
366 341
367 for ( off=0; off<size; off+=2 ) { 342 for ( off=0; off<size; off+=2 ) {
368 if (*(ushort *)&ram[off] != swapword) { 343 if (readw(ram + off) != swapword) {
369 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: SwapWord Check 1: WORD at offset 0x%x should have been=%x, was=%x\n", off, swapword, *((ushort *)&ram[off])); 344 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: SwapWord Check 1: WORD at offset 0x%x should have been=%x, was=%x\n", off, swapword, readw(ram + off));
370 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: SwapWord Check 1: BYTE at offset 0x%x is %x BYTE at offset 0x%x is %x\n", off, RBYTE(ram[off]), off+1, RBYTE(ram[off+1])); 345 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: SwapWord Check 1: BYTE at offset 0x%x is %x BYTE at offset 0x%x is %x\n", off, readb(ram + off), off+1, readb(ram + off + 1));
371 return RIO_FAIL; 346 return RIO_FAIL;
372 } 347 }
373 *((ushort *)&ram[off]) = ~swapword; 348 writew(~swapword, ram + off);
374 } 349 }
375 350
376 for (off=0; off<size; off+=2) { 351 for (off=0; off<size; off+=2) {
377 if (RBYTE(ram[off]) != newbyte) { 352 if (readb(ram + off) != newbyte) {
378 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: SwapWord Check 2: BYTE at offset 0x%x should have been=%x, was=%x\n", off, newbyte, RBYTE(ram[off])); 353 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: SwapWord Check 2: BYTE at offset 0x%x should have been=%x, was=%x\n", off, newbyte, readb(ram + off));
379 return RIO_FAIL; 354 return RIO_FAIL;
380 } 355 }
381 if (RBYTE(ram[off+1]) != invbyte) { 356 if (readb(ram + off + 1) != invbyte) {
382 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: SwapWord Check 2: BYTE at offset 0x%x should have been=%x, was=%x\n", off+1, invbyte, RBYTE(ram[off+1])); 357 rio_dprintk (RIO_DEBUG_INIT, "RIO-init: SwapWord Check 2: BYTE at offset 0x%x should have been=%x, was=%x\n", off+1, invbyte, readb(ram + off + 1));
383 return RIO_FAIL; 358 return RIO_FAIL;
384 } 359 }
385 *((ushort *)&ram[off]) = newword; 360 writew(newword, ram + off);
386 } 361 }
387 return RIO_SUCCESS; 362 return 0;
388} 363}
389 364
390 365
391int 366int RIODefaultName(struct rio_info *p, struct Host *HostP, unsigned int UnitId)
392RIODefaultName(p, HostP, UnitId)
393struct rio_info * p;
394struct Host * HostP;
395uint UnitId;
396{ 367{
397 bcopy("UNKNOWN RTA X-XX",HostP->Mapping[UnitId].Name,17); 368 memcpy(HostP->Mapping[UnitId].Name, "UNKNOWN RTA X-XX", 17);
398 HostP->Mapping[UnitId].Name[12]='1'+(HostP-p->RIOHosts); 369 HostP->Mapping[UnitId].Name[12]='1'+(HostP-p->RIOHosts);
399 if ((UnitId+1) > 9) { 370 if ((UnitId+1) > 9) {
400 HostP->Mapping[UnitId].Name[14]='0'+((UnitId+1)/10); 371 HostP->Mapping[UnitId].Name[14]='0'+((UnitId+1)/10);
@@ -412,8 +383,7 @@ uint UnitId;
412 383
413static struct rioVersion stVersion; 384static struct rioVersion stVersion;
414 385
415struct rioVersion * 386struct rioVersion *RIOVersid(void)
416RIOVersid(void)
417{ 387{
418 strlcpy(stVersion.version, "RIO driver for linux V1.0", 388 strlcpy(stVersion.version, "RIO driver for linux V1.0",
419 sizeof(stVersion.version)); 389 sizeof(stVersion.version));
@@ -423,40 +393,31 @@ RIOVersid(void)
423 return &stVersion; 393 return &stVersion;
424} 394}
425 395
426void 396void RIOHostReset(unsigned int Type, struct DpRam *DpRamP, unsigned int Slot)
427RIOHostReset(Type, DpRamP, Slot)
428uint Type;
429volatile struct DpRam *DpRamP;
430uint Slot;
431{ 397{
432 /* 398 /*
433 ** Reset the Tpu 399 ** Reset the Tpu
434 */ 400 */
435 rio_dprintk (RIO_DEBUG_INIT, "RIOHostReset: type 0x%x", Type); 401 rio_dprintk (RIO_DEBUG_INIT, "RIOHostReset: type 0x%x", Type);
436 switch ( Type ) { 402 switch ( Type ) {
437 case RIO_AT: 403 case RIO_AT:
438 rio_dprintk (RIO_DEBUG_INIT, " (RIO_AT)\n"); 404 rio_dprintk (RIO_DEBUG_INIT, " (RIO_AT)\n");
439 WBYTE(DpRamP->DpControl, BOOT_FROM_RAM | EXTERNAL_BUS_OFF | 405 writeb(BOOT_FROM_RAM | EXTERNAL_BUS_OFF | INTERRUPT_DISABLE | BYTE_OPERATION |
440 INTERRUPT_DISABLE | BYTE_OPERATION | 406 SLOW_LINKS | SLOW_AT_BUS, &DpRamP->DpControl);
441 SLOW_LINKS | SLOW_AT_BUS); 407 writeb(0xFF, &DpRamP->DpResetTpu);
442 WBYTE(DpRamP->DpResetTpu, 0xFF); 408 udelay(3);
443 udelay(3);
444
445 rio_dprintk (RIO_DEBUG_INIT, "RIOHostReset: Don't know if it worked. Try reset again\n"); 409 rio_dprintk (RIO_DEBUG_INIT, "RIOHostReset: Don't know if it worked. Try reset again\n");
446 WBYTE(DpRamP->DpControl, BOOT_FROM_RAM | EXTERNAL_BUS_OFF | 410 writeb(BOOT_FROM_RAM | EXTERNAL_BUS_OFF | INTERRUPT_DISABLE |
447 INTERRUPT_DISABLE | BYTE_OPERATION | 411 BYTE_OPERATION | SLOW_LINKS | SLOW_AT_BUS, &DpRamP->DpControl);
448 SLOW_LINKS | SLOW_AT_BUS); 412 writeb(0xFF, &DpRamP->DpResetTpu);
449 WBYTE(DpRamP->DpResetTpu, 0xFF); 413 udelay(3);
450 udelay(3); 414 break;
451 break;
452 case RIO_PCI: 415 case RIO_PCI:
453 rio_dprintk (RIO_DEBUG_INIT, " (RIO_PCI)\n"); 416 rio_dprintk (RIO_DEBUG_INIT, " (RIO_PCI)\n");
454 DpRamP->DpControl = RIO_PCI_BOOT_FROM_RAM; 417 writeb(RIO_PCI_BOOT_FROM_RAM, &DpRamP->DpControl);
455 DpRamP->DpResetInt = 0xFF; 418 writeb(0xFF, &DpRamP->DpResetInt);
456 DpRamP->DpResetTpu = 0xFF; 419 writeb(0xFF, &DpRamP->DpResetTpu);
457 udelay(100); 420 udelay(100);
458 /* for (i=0; i<6000; i++); */
459 /* suspend( 3 ); */
460 break; 421 break;
461 default: 422 default:
462 rio_dprintk (RIO_DEBUG_INIT, " (UNKNOWN)\n"); 423 rio_dprintk (RIO_DEBUG_INIT, " (UNKNOWN)\n");
diff --git a/drivers/char/rio/riointr.c b/drivers/char/rio/riointr.c
index 34d8787557..97f0fa5506 100644
--- a/drivers/char/rio/riointr.c
+++ b/drivers/char/rio/riointr.c
@@ -54,15 +54,12 @@ static char *_riointr_c_sccs_ = "@(#)riointr.c 1.2";
54 54
55#include "linux_compat.h" 55#include "linux_compat.h"
56#include "rio_linux.h" 56#include "rio_linux.h"
57#include "typdef.h"
58#include "pkt.h" 57#include "pkt.h"
59#include "daemon.h" 58#include "daemon.h"
60#include "rio.h" 59#include "rio.h"
61#include "riospace.h" 60#include "riospace.h"
62#include "top.h"
63#include "cmdpkt.h" 61#include "cmdpkt.h"
64#include "map.h" 62#include "map.h"
65#include "riotypes.h"
66#include "rup.h" 63#include "rup.h"
67#include "port.h" 64#include "port.h"
68#include "riodrvr.h" 65#include "riodrvr.h"
@@ -75,12 +72,10 @@ static char *_riointr_c_sccs_ = "@(#)riointr.c 1.2";
75#include "unixrup.h" 72#include "unixrup.h"
76#include "board.h" 73#include "board.h"
77#include "host.h" 74#include "host.h"
78#include "error.h"
79#include "phb.h" 75#include "phb.h"
80#include "link.h" 76#include "link.h"
81#include "cmdblk.h" 77#include "cmdblk.h"
82#include "route.h" 78#include "route.h"
83#include "control.h"
84#include "cirrus.h" 79#include "cirrus.h"
85#include "rioioctl.h" 80#include "rioioctl.h"
86 81
@@ -101,8 +96,7 @@ static char *firstchars(char *p, int nch)
101 96
102#define INCR( P, I ) ((P) = (((P)+(I)) & p->RIOBufferMask)) 97#define INCR( P, I ) ((P) = (((P)+(I)) & p->RIOBufferMask))
103/* Enable and start the transmission of packets */ 98/* Enable and start the transmission of packets */
104void RIOTxEnable(en) 99void RIOTxEnable(char *en)
105char *en;
106{ 100{
107 struct Port *PortP; 101 struct Port *PortP;
108 struct rio_info *p; 102 struct rio_info *p;
@@ -186,10 +180,8 @@ char *en;
186static int RupIntr; 180static int RupIntr;
187static int RxIntr; 181static int RxIntr;
188static int TxIntr; 182static int TxIntr;
189void RIOServiceHost(p, HostP, From) 183
190struct rio_info *p; 184void RIOServiceHost(struct rio_info *p, struct Host *HostP, int From)
191struct Host *HostP;
192int From;
193{ 185{
194 rio_spin_lock(&HostP->HostLock); 186 rio_spin_lock(&HostP->HostLock);
195 if ((HostP->Flags & RUN_STATE) != RC_RUNNING) { 187 if ((HostP->Flags & RUN_STATE) != RC_RUNNING) {
@@ -201,22 +193,22 @@ int From;
201 } 193 }
202 rio_spin_unlock(&HostP->HostLock); 194 rio_spin_unlock(&HostP->HostLock);
203 195
204 if (RWORD(HostP->ParmMapP->rup_intr)) { 196 if (readw(&HostP->ParmMapP->rup_intr)) {
205 WWORD(HostP->ParmMapP->rup_intr, 0); 197 writew(0, &HostP->ParmMapP->rup_intr);
206 p->RIORupCount++; 198 p->RIORupCount++;
207 RupIntr++; 199 RupIntr++;
208 rio_dprintk(RIO_DEBUG_INTR, "rio: RUP interrupt on host %d\n", HostP - p->RIOHosts); 200 rio_dprintk(RIO_DEBUG_INTR, "rio: RUP interrupt on host %Zd\n", HostP - p->RIOHosts);
209 RIOPollHostCommands(p, HostP); 201 RIOPollHostCommands(p, HostP);
210 } 202 }
211 203
212 if (RWORD(HostP->ParmMapP->rx_intr)) { 204 if (readw(&HostP->ParmMapP->rx_intr)) {
213 int port; 205 int port;
214 206
215 WWORD(HostP->ParmMapP->rx_intr, 0); 207 writew(0, &HostP->ParmMapP->rx_intr);
216 p->RIORxCount++; 208 p->RIORxCount++;
217 RxIntr++; 209 RxIntr++;
218 210
219 rio_dprintk(RIO_DEBUG_INTR, "rio: RX interrupt on host %d\n", HostP - p->RIOHosts); 211 rio_dprintk(RIO_DEBUG_INTR, "rio: RX interrupt on host %Zd\n", HostP - p->RIOHosts);
220 /* 212 /*
221 ** Loop through every port. If the port is mapped into 213 ** Loop through every port. If the port is mapped into
222 ** the system ( i.e. has /dev/ttyXXXX associated ) then it is 214 ** the system ( i.e. has /dev/ttyXXXX associated ) then it is
@@ -277,26 +269,26 @@ int From;
277 ** it's handshake bit is set, then we must clear the handshake, 269 ** it's handshake bit is set, then we must clear the handshake,
278 ** so that that downstream RTA is re-enabled. 270 ** so that that downstream RTA is re-enabled.
279 */ 271 */
280 if (!can_remove_receive(&PacketP, PortP) && (RWORD(PortP->PhbP->handshake) == PHB_HANDSHAKE_SET)) { 272 if (!can_remove_receive(&PacketP, PortP) && (readw(&PortP->PhbP->handshake) == PHB_HANDSHAKE_SET)) {
281 /* 273 /*
282 ** MAGIC! ( Basically, handshake the RX buffer, so that 274 ** MAGIC! ( Basically, handshake the RX buffer, so that
283 ** the RTAs upstream can be re-enabled. ) 275 ** the RTAs upstream can be re-enabled. )
284 */ 276 */
285 rio_dprintk(RIO_DEBUG_INTR, "Set RX handshake bit\n"); 277 rio_dprintk(RIO_DEBUG_INTR, "Set RX handshake bit\n");
286 WWORD(PortP->PhbP->handshake, PHB_HANDSHAKE_SET | PHB_HANDSHAKE_RESET); 278 writew(PHB_HANDSHAKE_SET | PHB_HANDSHAKE_RESET, &PortP->PhbP->handshake);
287 } 279 }
288 rio_spin_unlock(&PortP->portSem); 280 rio_spin_unlock(&PortP->portSem);
289 } 281 }
290 } 282 }
291 283
292 if (RWORD(HostP->ParmMapP->tx_intr)) { 284 if (readw(&HostP->ParmMapP->tx_intr)) {
293 int port; 285 int port;
294 286
295 WWORD(HostP->ParmMapP->tx_intr, 0); 287 writew(0, &HostP->ParmMapP->tx_intr);
296 288
297 p->RIOTxCount++; 289 p->RIOTxCount++;
298 TxIntr++; 290 TxIntr++;
299 rio_dprintk(RIO_DEBUG_INTR, "rio: TX interrupt on host %d\n", HostP - p->RIOHosts); 291 rio_dprintk(RIO_DEBUG_INTR, "rio: TX interrupt on host %Zd\n", HostP - p->RIOHosts);
300 292
301 /* 293 /*
302 ** Loop through every port. 294 ** Loop through every port.
@@ -399,7 +391,6 @@ int From;
399 /* For now don't handle RTA reboots. -- REW. 391 /* For now don't handle RTA reboots. -- REW.
400 Reenabled. Otherwise RTA reboots didn't work. Duh. -- REW */ 392 Reenabled. Otherwise RTA reboots didn't work. Duh. -- REW */
401 if (PortP->MagicFlags) { 393 if (PortP->MagicFlags) {
402#if 1
403 if (PortP->MagicFlags & MAGIC_REBOOT) { 394 if (PortP->MagicFlags & MAGIC_REBOOT) {
404 /* 395 /*
405 ** well, the RTA has been rebooted, and there is room 396 ** well, the RTA has been rebooted, and there is room
@@ -416,13 +407,12 @@ int From;
416 PortP->InUse = NOT_INUSE; 407 PortP->InUse = NOT_INUSE;
417 408
418 rio_spin_unlock(&PortP->portSem); 409 rio_spin_unlock(&PortP->portSem);
419 if (RIOParam(PortP, OPEN, ((PortP->Cor2Copy & (COR2_RTSFLOW | COR2_CTSFLOW)) == (COR2_RTSFLOW | COR2_CTSFLOW)) ? TRUE : FALSE, DONT_SLEEP) == RIO_FAIL) { 410 if (RIOParam(PortP, OPEN, ((PortP->Cor2Copy & (COR2_RTSFLOW | COR2_CTSFLOW)) == (COR2_RTSFLOW | COR2_CTSFLOW)) ? 1 : 0, DONT_SLEEP) == RIO_FAIL) {
420 continue; /* with next port */ 411 continue; /* with next port */
421 } 412 }
422 rio_spin_lock(&PortP->portSem); 413 rio_spin_lock(&PortP->portSem);
423 PortP->MagicFlags &= ~MAGIC_REBOOT; 414 PortP->MagicFlags &= ~MAGIC_REBOOT;
424 } 415 }
425#endif
426 416
427 /* 417 /*
428 ** As mentioned above, this is a tacky hack to cope 418 ** As mentioned above, this is a tacky hack to cope
@@ -445,9 +435,9 @@ int From;
445 */ 435 */
446 PktCmdP = (struct PktCmd *) &PacketP->data[0]; 436 PktCmdP = (struct PktCmd *) &PacketP->data[0];
447 437
448 WBYTE(PktCmdP->Command, WFLUSH); 438 writeb(WFLUSH, &PktCmdP->Command);
449 439
450 p = PortP->HostPort % (ushort) PORTS_PER_RTA; 440 p = PortP->HostPort % (u16) PORTS_PER_RTA;
451 441
452 /* 442 /*
453 ** If second block of ports for 16 port RTA, add 8 443 ** If second block of ports for 16 port RTA, add 8
@@ -456,27 +446,27 @@ int From;
456 if (PortP->SecondBlock) 446 if (PortP->SecondBlock)
457 p += PORTS_PER_RTA; 447 p += PORTS_PER_RTA;
458 448
459 WBYTE(PktCmdP->PhbNum, p); 449 writeb(p, &PktCmdP->PhbNum);
460 450
461 /* 451 /*
462 ** to make debuggery easier 452 ** to make debuggery easier
463 */ 453 */
464 WBYTE(PacketP->data[2], 'W'); 454 writeb('W', &PacketP->data[2]);
465 WBYTE(PacketP->data[3], 'F'); 455 writeb('F', &PacketP->data[3]);
466 WBYTE(PacketP->data[4], 'L'); 456 writeb('L', &PacketP->data[4]);
467 WBYTE(PacketP->data[5], 'U'); 457 writeb('U', &PacketP->data[5]);
468 WBYTE(PacketP->data[6], 'S'); 458 writeb('S', &PacketP->data[6]);
469 WBYTE(PacketP->data[7], 'H'); 459 writeb('H', &PacketP->data[7]);
470 WBYTE(PacketP->data[8], ' '); 460 writeb(' ', &PacketP->data[8]);
471 WBYTE(PacketP->data[9], '0' + PortP->WflushFlag); 461 writeb('0' + PortP->WflushFlag, &PacketP->data[9]);
472 WBYTE(PacketP->data[10], ' '); 462 writeb(' ', &PacketP->data[10]);
473 WBYTE(PacketP->data[11], ' '); 463 writeb(' ', &PacketP->data[11]);
474 WBYTE(PacketP->data[12], '\0'); 464 writeb('\0', &PacketP->data[12]);
475 465
476 /* 466 /*
477 ** its two bytes long! 467 ** its two bytes long!
478 */ 468 */
479 WBYTE(PacketP->len, PKT_CMD_BIT | 2); 469 writeb(PKT_CMD_BIT | 2, &PacketP->len);
480 470
481 /* 471 /*
482 ** queue it! 472 ** queue it!
@@ -529,19 +519,15 @@ int From;
529} 519}
530 520
531/* 521/*
532** Routine for handling received data for clist drivers. 522** Routine for handling received data for tty drivers
533** NB: Called with the tty locked. The spl from the lockb( ) is passed.
534** we return the ttySpl level that we re-locked at.
535*/ 523*/
536static void RIOReceive(p, PortP) 524static void RIOReceive(struct rio_info *p, struct Port *PortP)
537struct rio_info *p;
538struct Port *PortP;
539{ 525{
540 struct tty_struct *TtyP; 526 struct tty_struct *TtyP;
541 register ushort transCount; 527 unsigned short transCount;
542 struct PKT *PacketP; 528 struct PKT *PacketP;
543 register uint DataCnt; 529 register unsigned int DataCnt;
544 uchar *ptr; 530 unsigned char *ptr;
545 unsigned char *buf; 531 unsigned char *buf;
546 int copied = 0; 532 int copied = 0;
547 533
@@ -594,9 +580,6 @@ struct Port *PortP;
594 transCount = 1; 580 transCount = 1;
595 while (can_remove_receive(&PacketP, PortP) 581 while (can_remove_receive(&PacketP, PortP)
596 && transCount) { 582 && transCount) {
597#ifdef STATS
598 PortP->Stat.RxIntCnt++;
599#endif /* STATS */
600 RxIntCnt++; 583 RxIntCnt++;
601 584
602 /* 585 /*
@@ -642,28 +625,15 @@ struct Port *PortP;
642 ** to '#define', (this is the only place ___DEBUG_IT___ occurs in the 625 ** to '#define', (this is the only place ___DEBUG_IT___ occurs in the
643 ** driver). 626 ** driver).
644 */ 627 */
645#undef ___DEBUG_IT___ 628 ptr = (unsigned char *) PacketP->data + PortP->RxDataStart;
646#ifdef ___DEBUG_IT___
647 kkprintf("I:%d R:%d P:%d Q:%d C:%d F:%x ", intCount, RxIntCnt, PortP->PortNum, TtyP->rxqueue.count, transCount, TtyP->flags);
648#endif
649 ptr = (uchar *) PacketP->data + PortP->RxDataStart;
650 629
651 tty_prepare_flip_string(TtyP, &buf, transCount); 630 tty_prepare_flip_string(TtyP, &buf, transCount);
652 rio_memcpy_fromio(buf, ptr, transCount); 631 rio_memcpy_fromio(buf, ptr, transCount);
653#ifdef STATS
654 /*
655 ** keep a count for statistical purposes
656 */
657 PortP->Stat.RxCharCnt += transCount;
658#endif
659 PortP->RxDataStart += transCount; 632 PortP->RxDataStart += transCount;
660 PacketP->len -= transCount; 633 PacketP->len -= transCount;
661 copied += transCount; 634 copied += transCount;
662 635
663 636
664#ifdef ___DEBUG_IT___
665 kkprintf("T:%d L:%d\n", DataCnt, PacketP->len);
666#endif
667 637
668 if (PacketP->len == 0) { 638 if (PacketP->len == 0) {
669 /* 639 /*
@@ -674,12 +644,6 @@ struct Port *PortP;
674 remove_receive(PortP); 644 remove_receive(PortP);
675 put_free_end(PortP->HostP, PacketP); 645 put_free_end(PortP->HostP, PacketP);
676 PortP->RxDataStart = 0; 646 PortP->RxDataStart = 0;
677#ifdef STATS
678 /*
679 ** more lies ( oops, I mean statistics )
680 */
681 PortP->Stat.RxPktCnt++;
682#endif /* STATS */
683 } 647 }
684 } 648 }
685 } 649 }
@@ -691,215 +655,3 @@ struct Port *PortP;
691 return; 655 return;
692} 656}
693 657
694#ifdef FUTURE_RELEASE
695/*
696** The proc routine called by the line discipline to do the work for it.
697** The proc routine works hand in hand with the interrupt routine.
698*/
699int riotproc(p, tp, cmd, port)
700struct rio_info *p;
701register struct ttystatics *tp;
702int cmd;
703int port;
704{
705 register struct Port *PortP;
706 int SysPort;
707 struct PKT *PacketP;
708
709 SysPort = port; /* Believe me, it works. */
710
711 if (SysPort < 0 || SysPort >= RIO_PORTS) {
712 rio_dprintk(RIO_DEBUG_INTR, "Illegal port %d derived from TTY in riotproc()\n", SysPort);
713 return 0;
714 }
715 PortP = p->RIOPortp[SysPort];
716
717 if ((uint) PortP->PhbP < (uint) PortP->Caddr || (uint) PortP->PhbP >= (uint) PortP->Caddr + SIXTY_FOUR_K) {
718 rio_dprintk(RIO_DEBUG_INTR, "RIO: NULL or BAD PhbP on sys port %d in proc routine\n", SysPort);
719 rio_dprintk(RIO_DEBUG_INTR, " PortP = 0x%x\n", PortP);
720 rio_dprintk(RIO_DEBUG_INTR, " PortP->PhbP = 0x%x\n", PortP->PhbP);
721 rio_dprintk(RIO_DEBUG_INTR, " PortP->Caddr = 0x%x\n", PortP->PhbP);
722 rio_dprintk(RIO_DEBUG_INTR, " PortP->HostPort = 0x%x\n", PortP->HostPort);
723 return 0;
724 }
725
726 switch (cmd) {
727 case T_WFLUSH:
728 rio_dprintk(RIO_DEBUG_INTR, "T_WFLUSH\n");
729 /*
730 ** Because of the spooky way the RIO works, we don't need
731 ** to issue a flush command on any of the SET*F commands,
732 ** as that causes trouble with getty and login, which issue
733 ** these commands to incur a READ flush, and rely on the fact
734 ** that the line discipline does a wait for drain for them.
735 ** As the rio doesn't wait for drain, the write flush would
736 ** destroy the Password: prompt. This isn't very friendly, so
737 ** here we only issue a WFLUSH command if we are in the interrupt
738 ** routine, or we aren't executing a SET*F command.
739 */
740 if (PortP->HostP->InIntr || !PortP->FlushCmdBodge) {
741 /*
742 ** form a wflush packet - 1 byte long, no data
743 */
744 if (PortP->State & RIO_DELETED) {
745 rio_dprintk(RIO_DEBUG_INTR, "WFLUSH on deleted RTA\n");
746 } else {
747 if (RIOPreemptiveCmd(p, PortP, WFLUSH) == RIO_FAIL) {
748 rio_dprintk(RIO_DEBUG_INTR, "T_WFLUSH Command failed\n");
749 } else
750 rio_dprintk(RIO_DEBUG_INTR, "T_WFLUSH Command\n");
751 }
752 /*
753 ** WFLUSH operation - flush the data!
754 */
755 PortP->TxBufferIn = PortP->TxBufferOut = 0;
756 } else {
757 rio_dprintk(RIO_DEBUG_INTR, "T_WFLUSH Command ignored\n");
758 }
759 /*
760 ** sort out the line discipline
761 */
762 if (PortP->CookMode == COOK_WELL)
763 goto start;
764 break;
765
766 case T_RESUME:
767 rio_dprintk(RIO_DEBUG_INTR, "T_RESUME\n");
768 /*
769 ** send pre-emptive resume packet
770 */
771 if (PortP->State & RIO_DELETED) {
772 rio_dprintk(RIO_DEBUG_INTR, "RESUME on deleted RTA\n");
773 } else {
774 if (RIOPreemptiveCmd(p, PortP, RESUME) == RIO_FAIL) {
775 rio_dprintk(RIO_DEBUG_INTR, "T_RESUME Command failed\n");
776 }
777 }
778 /*
779 ** and re-start the sender software!
780 */
781 if (PortP->CookMode == COOK_WELL)
782 goto start;
783 break;
784
785 case T_TIME:
786 rio_dprintk(RIO_DEBUG_INTR, "T_TIME\n");
787 /*
788 ** T_TIME is called when xDLY is set in oflags and
789 ** the line discipline timeout has expired. It's
790 ** function in life is to clear the TIMEOUT flag
791 ** and to re-start output to the port.
792 */
793 /*
794 ** Fall through and re-start output
795 */
796 case T_OUTPUT:
797 start:
798 if (PortP->MagicFlags & MAGIC_FLUSH) {
799 PortP->MagicFlags |= MORE_OUTPUT_EYGOR;
800 return 0;
801 }
802 RIOTxEnable((char *) PortP);
803 PortP->MagicFlags &= ~MORE_OUTPUT_EYGOR;
804 /*rio_dprint(RIO_DEBUG_INTR, PortP,DBG_PROC,"T_OUTPUT finished\n"); */
805 break;
806
807 case T_SUSPEND:
808 rio_dprintk(RIO_DEBUG_INTR, "T_SUSPEND\n");
809 /*
810 ** send a suspend pre-emptive packet.
811 */
812 if (PortP->State & RIO_DELETED) {
813 rio_dprintk(RIO_DEBUG_INTR, "SUSPEND deleted RTA\n");
814 } else {
815 if (RIOPreemptiveCmd(p, PortP, SUSPEND) == RIO_FAIL) {
816 rio_dprintk(RIO_DEBUG_INTR, "T_SUSPEND Command failed\n");
817 }
818 }
819 /*
820 ** done!
821 */
822 break;
823
824 case T_BLOCK:
825 rio_dprintk(RIO_DEBUG_INTR, "T_BLOCK\n");
826 break;
827
828 case T_RFLUSH:
829 rio_dprintk(RIO_DEBUG_INTR, "T_RFLUSH\n");
830 if (PortP->State & RIO_DELETED) {
831 rio_dprintk(RIO_DEBUG_INTR, "RFLUSH on deleted RTA\n");
832 PortP->RxDataStart = 0;
833 } else {
834 if (RIOPreemptiveCmd(p, PortP, RFLUSH) == RIO_FAIL) {
835 rio_dprintk(RIO_DEBUG_INTR, "T_RFLUSH Command failed\n");
836 return 0;
837 }
838 PortP->RxDataStart = 0;
839 while (can_remove_receive(&PacketP, PortP)) {
840 remove_receive(PortP);
841 ShowPacket(DBG_PROC, PacketP);
842 put_free_end(PortP->HostP, PacketP);
843 }
844 if (PortP->PhbP->handshake == PHB_HANDSHAKE_SET) {
845 /*
846 ** MAGIC!
847 */
848 rio_dprintk(RIO_DEBUG_INTR, "Set receive handshake bit\n");
849 PortP->PhbP->handshake |= PHB_HANDSHAKE_RESET;
850 }
851 }
852 break;
853 /* FALLTHROUGH */
854 case T_UNBLOCK:
855 rio_dprintk(RIO_DEBUG_INTR, "T_UNBLOCK\n");
856 /*
857 ** If there is any data to receive set a timeout to service it.
858 */
859 RIOReceive(p, PortP);
860 break;
861
862 case T_BREAK:
863 rio_dprintk(RIO_DEBUG_INTR, "T_BREAK\n");
864 /*
865 ** Send a break command. For Sys V
866 ** this is a timed break, so we
867 ** send a SBREAK[time] packet
868 */
869 /*
870 ** Build a BREAK command
871 */
872 if (PortP->State & RIO_DELETED) {
873 rio_dprintk(RIO_DEBUG_INTR, "BREAK on deleted RTA\n");
874 } else {
875 if (RIOShortCommand(PortP, SBREAK, 2, p->RIOConf.BreakInterval) == RIO_FAIL) {
876 rio_dprintk(RIO_DEBUG_INTR, "SBREAK RIOShortCommand failed\n");
877 }
878 }
879
880 /*
881 ** done!
882 */
883 break;
884
885 case T_INPUT:
886 rio_dprintk(RIO_DEBUG_INTR, "Proc T_INPUT called - I don't know what to do!\n");
887 break;
888 case T_PARM:
889 rio_dprintk(RIO_DEBUG_INTR, "Proc T_PARM called - I don't know what to do!\n");
890 break;
891
892 case T_SWTCH:
893 rio_dprintk(RIO_DEBUG_INTR, "Proc T_SWTCH called - I don't know what to do!\n");
894 break;
895
896 default:
897 rio_dprintk(RIO_DEBUG_INTR, "Proc UNKNOWN command %d\n", cmd);
898 }
899 /*
900 ** T_OUTPUT returns without passing through this point!
901 */
902 /*rio_dprint(RIO_DEBUG_INTR, PortP,DBG_PROC,"riotproc done\n"); */
903 return (0);
904}
905#endif
diff --git a/drivers/char/rio/rioparam.c b/drivers/char/rio/rioparam.c
index c622f46d6d..d2e8092cdb 100644
--- a/drivers/char/rio/rioparam.c
+++ b/drivers/char/rio/rioparam.c
@@ -52,15 +52,12 @@ static char *_rioparam_c_sccs_ = "@(#)rioparam.c 1.3";
52 52
53#include "linux_compat.h" 53#include "linux_compat.h"
54#include "rio_linux.h" 54#include "rio_linux.h"
55#include "typdef.h"
56#include "pkt.h" 55#include "pkt.h"
57#include "daemon.h" 56#include "daemon.h"
58#include "rio.h" 57#include "rio.h"
59#include "riospace.h" 58#include "riospace.h"
60#include "top.h"
61#include "cmdpkt.h" 59#include "cmdpkt.h"
62#include "map.h" 60#include "map.h"
63#include "riotypes.h"
64#include "rup.h" 61#include "rup.h"
65#include "port.h" 62#include "port.h"
66#include "riodrvr.h" 63#include "riodrvr.h"
@@ -73,17 +70,13 @@ static char *_rioparam_c_sccs_ = "@(#)rioparam.c 1.3";
73#include "unixrup.h" 70#include "unixrup.h"
74#include "board.h" 71#include "board.h"
75#include "host.h" 72#include "host.h"
76#include "error.h"
77#include "phb.h" 73#include "phb.h"
78#include "link.h" 74#include "link.h"
79#include "cmdblk.h" 75#include "cmdblk.h"
80#include "route.h" 76#include "route.h"
81#include "control.h"
82#include "cirrus.h" 77#include "cirrus.h"
83#include "rioioctl.h" 78#include "rioioctl.h"
84#include "param.h" 79#include "param.h"
85#include "list.h"
86#include "sam.h"
87 80
88 81
89 82
@@ -157,20 +150,16 @@ static char *_rioparam_c_sccs_ = "@(#)rioparam.c 1.3";
157** NB. for MPX 150** NB. for MPX
158** tty lock must NOT have been previously acquired. 151** tty lock must NOT have been previously acquired.
159*/ 152*/
160int RIOParam(PortP, cmd, Modem, SleepFlag) 153int RIOParam(struct Port *PortP, int cmd, int Modem, int SleepFlag)
161struct Port *PortP;
162int cmd;
163int Modem;
164int SleepFlag;
165{ 154{
166 register struct tty_struct *TtyP; 155 struct tty_struct *TtyP;
167 int retval; 156 int retval;
168 register struct phb_param *phb_param_ptr; 157 struct phb_param *phb_param_ptr;
169 PKT *PacketP; 158 struct PKT *PacketP;
170 int res; 159 int res;
171 uchar Cor1 = 0, Cor2 = 0, Cor4 = 0, Cor5 = 0; 160 u8 Cor1 = 0, Cor2 = 0, Cor4 = 0, Cor5 = 0;
172 uchar TxXon = 0, TxXoff = 0, RxXon = 0, RxXoff = 0; 161 u8 TxXon = 0, TxXoff = 0, RxXon = 0, RxXoff = 0;
173 uchar LNext = 0, TxBaud = 0, RxBaud = 0; 162 u8 LNext = 0, TxBaud = 0, RxBaud = 0;
174 int retries = 0xff; 163 int retries = 0xff;
175 unsigned long flags; 164 unsigned long flags;
176 165
@@ -226,16 +215,13 @@ int SleepFlag;
226 if (retval == RIO_FAIL) { 215 if (retval == RIO_FAIL) {
227 rio_dprintk(RIO_DEBUG_PARAM, "wait for can_add_transmit broken by signal\n"); 216 rio_dprintk(RIO_DEBUG_PARAM, "wait for can_add_transmit broken by signal\n");
228 rio_spin_unlock_irqrestore(&PortP->portSem, flags); 217 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
229 pseterr(EINTR);
230 func_exit(); 218 func_exit();
231 219 return -EINTR;
232 return RIO_FAIL;
233 } 220 }
234 if (PortP->State & RIO_DELETED) { 221 if (PortP->State & RIO_DELETED) {
235 rio_spin_unlock_irqrestore(&PortP->portSem, flags); 222 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
236 func_exit(); 223 func_exit();
237 224 return 0;
238 return RIO_SUCCESS;
239 } 225 }
240 } 226 }
241 227
@@ -247,7 +233,7 @@ int SleepFlag;
247 } 233 }
248 234
249 rio_dprintk(RIO_DEBUG_PARAM, "can_add_transmit() returns %x\n", res); 235 rio_dprintk(RIO_DEBUG_PARAM, "can_add_transmit() returns %x\n", res);
250 rio_dprintk(RIO_DEBUG_PARAM, "Packet is 0x%x\n", (int) PacketP); 236 rio_dprintk(RIO_DEBUG_PARAM, "Packet is %p\n", PacketP);
251 237
252 phb_param_ptr = (struct phb_param *) PacketP->data; 238 phb_param_ptr = (struct phb_param *) PacketP->data;
253 239
@@ -474,9 +460,6 @@ int SleepFlag;
474 e(115200); /* e(230400);e(460800); e(921600); */ 460 e(115200); /* e(230400);e(460800); e(921600); */
475 } 461 }
476 462
477 /* XXX MIssing conversion table. XXX */
478 /* (TtyP->termios->c_cflag & V_CBAUD); */
479
480 rio_dprintk(RIO_DEBUG_PARAM, "tx baud 0x%x, rx baud 0x%x\n", TxBaud, RxBaud); 463 rio_dprintk(RIO_DEBUG_PARAM, "tx baud 0x%x, rx baud 0x%x\n", TxBaud, RxBaud);
481 464
482 465
@@ -552,23 +535,23 @@ int SleepFlag;
552 /* 535 /*
553 ** Actually write the info into the packet to be sent 536 ** Actually write the info into the packet to be sent
554 */ 537 */
555 WBYTE(phb_param_ptr->Cmd, cmd); 538 writeb(cmd, &phb_param_ptr->Cmd);
556 WBYTE(phb_param_ptr->Cor1, Cor1); 539 writeb(Cor1, &phb_param_ptr->Cor1);
557 WBYTE(phb_param_ptr->Cor2, Cor2); 540 writeb(Cor2, &phb_param_ptr->Cor2);
558 WBYTE(phb_param_ptr->Cor4, Cor4); 541 writeb(Cor4, &phb_param_ptr->Cor4);
559 WBYTE(phb_param_ptr->Cor5, Cor5); 542 writeb(Cor5, &phb_param_ptr->Cor5);
560 WBYTE(phb_param_ptr->TxXon, TxXon); 543 writeb(TxXon, &phb_param_ptr->TxXon);
561 WBYTE(phb_param_ptr->RxXon, RxXon); 544 writeb(RxXon, &phb_param_ptr->RxXon);
562 WBYTE(phb_param_ptr->TxXoff, TxXoff); 545 writeb(TxXoff, &phb_param_ptr->TxXoff);
563 WBYTE(phb_param_ptr->RxXoff, RxXoff); 546 writeb(RxXoff, &phb_param_ptr->RxXoff);
564 WBYTE(phb_param_ptr->LNext, LNext); 547 writeb(LNext, &phb_param_ptr->LNext);
565 WBYTE(phb_param_ptr->TxBaud, TxBaud); 548 writeb(TxBaud, &phb_param_ptr->TxBaud);
566 WBYTE(phb_param_ptr->RxBaud, RxBaud); 549 writeb(RxBaud, &phb_param_ptr->RxBaud);
567 550
568 /* 551 /*
569 ** Set the length/command field 552 ** Set the length/command field
570 */ 553 */
571 WBYTE(PacketP->len, 12 | PKT_CMD_BIT); 554 writeb(12 | PKT_CMD_BIT, &PacketP->len);
572 555
573 /* 556 /*
574 ** The packet is formed - now, whack it off 557 ** The packet is formed - now, whack it off
@@ -589,7 +572,7 @@ int SleepFlag;
589 */ 572 */
590 func_exit(); 573 func_exit();
591 574
592 return RIO_SUCCESS; 575 return 0;
593} 576}
594 577
595 578
@@ -597,15 +580,13 @@ int SleepFlag;
597** We can add another packet to a transmit queue if the packet pointer pointed 580** We can add another packet to a transmit queue if the packet pointer pointed
598** to by the TxAdd pointer has PKT_IN_USE clear in its address. 581** to by the TxAdd pointer has PKT_IN_USE clear in its address.
599*/ 582*/
600int can_add_transmit(PktP, PortP) 583int can_add_transmit(struct PKT **PktP, struct Port *PortP)
601PKT **PktP;
602struct Port *PortP;
603{ 584{
604 register PKT *tp; 585 struct PKT *tp;
605 586
606 *PktP = tp = (PKT *) RIO_PTR(PortP->Caddr, RWORD(*PortP->TxAdd)); 587 *PktP = tp = (struct PKT *) RIO_PTR(PortP->Caddr, readw(PortP->TxAdd));
607 588
608 return !((uint) tp & PKT_IN_USE); 589 return !((unsigned long) tp & PKT_IN_USE);
609} 590}
610 591
611/* 592/*
@@ -613,27 +594,24 @@ struct Port *PortP;
613** and then move the TxAdd pointer along one position to point to the next 594** and then move the TxAdd pointer along one position to point to the next
614** packet pointer. You must wrap the pointer from the end back to the start. 595** packet pointer. You must wrap the pointer from the end back to the start.
615*/ 596*/
616void add_transmit(PortP) 597void add_transmit(struct Port *PortP)
617struct Port *PortP;
618{ 598{
619 if (RWORD(*PortP->TxAdd) & PKT_IN_USE) { 599 if (readw(PortP->TxAdd) & PKT_IN_USE) {
620 rio_dprintk(RIO_DEBUG_PARAM, "add_transmit: Packet has been stolen!"); 600 rio_dprintk(RIO_DEBUG_PARAM, "add_transmit: Packet has been stolen!");
621 } 601 }
622 WWORD(*(ushort *) PortP->TxAdd, RWORD(*PortP->TxAdd) | PKT_IN_USE); 602 writew(readw(PortP->TxAdd) | PKT_IN_USE, PortP->TxAdd);
623 PortP->TxAdd = (PortP->TxAdd == PortP->TxEnd) ? PortP->TxStart : PortP->TxAdd + 1; 603 PortP->TxAdd = (PortP->TxAdd == PortP->TxEnd) ? PortP->TxStart : PortP->TxAdd + 1;
624 WWORD(PortP->PhbP->tx_add, RIO_OFF(PortP->Caddr, PortP->TxAdd)); 604 writew(RIO_OFF(PortP->Caddr, PortP->TxAdd), &PortP->PhbP->tx_add);
625} 605}
626 606
627/**************************************** 607/****************************************
628 * Put a packet onto the end of the 608 * Put a packet onto the end of the
629 * free list 609 * free list
630 ****************************************/ 610 ****************************************/
631void put_free_end(HostP, PktP) 611void put_free_end(struct Host *HostP, struct PKT *PktP)
632struct Host *HostP;
633PKT *PktP;
634{ 612{
635 FREE_LIST *tmp_pointer; 613 struct rio_free_list *tmp_pointer;
636 ushort old_end, new_end; 614 unsigned short old_end, new_end;
637 unsigned long flags; 615 unsigned long flags;
638 616
639 rio_spin_lock_irqsave(&HostP->HostLock, flags); 617 rio_spin_lock_irqsave(&HostP->HostLock, flags);
@@ -643,21 +621,21 @@ PKT *PktP;
643 * 621 *
644 ************************************************/ 622 ************************************************/
645 623
646 rio_dprintk(RIO_DEBUG_PFE, "put_free_end(PktP=%x)\n", (int) PktP); 624 rio_dprintk(RIO_DEBUG_PFE, "put_free_end(PktP=%p)\n", PktP);
647 625
648 if ((old_end = RWORD(HostP->ParmMapP->free_list_end)) != TPNULL) { 626 if ((old_end = readw(&HostP->ParmMapP->free_list_end)) != TPNULL) {
649 new_end = RIO_OFF(HostP->Caddr, PktP); 627 new_end = RIO_OFF(HostP->Caddr, PktP);
650 tmp_pointer = (FREE_LIST *) RIO_PTR(HostP->Caddr, old_end); 628 tmp_pointer = (struct rio_free_list *) RIO_PTR(HostP->Caddr, old_end);
651 WWORD(tmp_pointer->next, new_end); 629 writew(new_end, &tmp_pointer->next);
652 WWORD(((FREE_LIST *) PktP)->prev, old_end); 630 writew(old_end, &((struct rio_free_list *) PktP)->prev);
653 WWORD(((FREE_LIST *) PktP)->next, TPNULL); 631 writew(TPNULL, &((struct rio_free_list *) PktP)->next);
654 WWORD(HostP->ParmMapP->free_list_end, new_end); 632 writew(new_end, &HostP->ParmMapP->free_list_end);
655 } else { /* First packet on the free list this should never happen! */ 633 } else { /* First packet on the free list this should never happen! */
656 rio_dprintk(RIO_DEBUG_PFE, "put_free_end(): This should never happen\n"); 634 rio_dprintk(RIO_DEBUG_PFE, "put_free_end(): This should never happen\n");
657 WWORD(HostP->ParmMapP->free_list_end, RIO_OFF(HostP->Caddr, PktP)); 635 writew(RIO_OFF(HostP->Caddr, PktP), &HostP->ParmMapP->free_list_end);
658 tmp_pointer = (FREE_LIST *) PktP; 636 tmp_pointer = (struct rio_free_list *) PktP;
659 WWORD(tmp_pointer->prev, TPNULL); 637 writew(TPNULL, &tmp_pointer->prev);
660 WWORD(tmp_pointer->next, TPNULL); 638 writew(TPNULL, &tmp_pointer->next);
661 } 639 }
662 rio_dprintk(RIO_DEBUG_CMD, "Before unlock: %p\n", &HostP->HostLock); 640 rio_dprintk(RIO_DEBUG_CMD, "Before unlock: %p\n", &HostP->HostLock);
663 rio_spin_unlock_irqrestore(&HostP->HostLock, flags); 641 rio_spin_unlock_irqrestore(&HostP->HostLock, flags);
@@ -669,12 +647,10 @@ PKT *PktP;
669** relevant packet, [having cleared the PKT_IN_USE bit]. If PKT_IN_USE is clear, 647** relevant packet, [having cleared the PKT_IN_USE bit]. If PKT_IN_USE is clear,
670** then can_remove_receive() returns 0. 648** then can_remove_receive() returns 0.
671*/ 649*/
672int can_remove_receive(PktP, PortP) 650int can_remove_receive(struct PKT **PktP, struct Port *PortP)
673PKT **PktP;
674struct Port *PortP;
675{ 651{
676 if (RWORD(*PortP->RxRemove) & PKT_IN_USE) { 652 if (readw(PortP->RxRemove) & PKT_IN_USE) {
677 *PktP = (PKT *) RIO_PTR(PortP->Caddr, RWORD(*PortP->RxRemove) & ~PKT_IN_USE); 653 *PktP = (struct PKT *) RIO_PTR(PortP->Caddr, readw(PortP->RxRemove) & ~PKT_IN_USE);
678 return 1; 654 return 1;
679 } 655 }
680 return 0; 656 return 0;
@@ -685,10 +661,9 @@ struct Port *PortP;
685** and then bump the pointers. Once the pointers get to the end, they must 661** and then bump the pointers. Once the pointers get to the end, they must
686** be wrapped back to the start. 662** be wrapped back to the start.
687*/ 663*/
688void remove_receive(PortP) 664void remove_receive(struct Port *PortP)
689struct Port *PortP;
690{ 665{
691 WWORD(*PortP->RxRemove, RWORD(*PortP->RxRemove) & ~PKT_IN_USE); 666 writew(readw(PortP->RxRemove) & ~PKT_IN_USE, PortP->RxRemove);
692 PortP->RxRemove = (PortP->RxRemove == PortP->RxEnd) ? PortP->RxStart : PortP->RxRemove + 1; 667 PortP->RxRemove = (PortP->RxRemove == PortP->RxEnd) ? PortP->RxStart : PortP->RxRemove + 1;
693 WWORD(PortP->PhbP->rx_remove, RIO_OFF(PortP->Caddr, PortP->RxRemove)); 668 writew(RIO_OFF(PortP->Caddr, PortP->RxRemove), &PortP->PhbP->rx_remove);
694} 669}
diff --git a/drivers/char/rio/riopcicopy.c b/drivers/char/rio/riopcicopy.c
deleted file mode 100644
index 535afaa51c..0000000000
--- a/drivers/char/rio/riopcicopy.c
+++ /dev/null
@@ -1,8 +0,0 @@
1
2/* Yeah. We have copyright on this one. Sure. */
3
4void rio_pcicopy(char *from, char *to, int amount)
5{
6 while (amount--)
7 *to++ = *from++;
8}
diff --git a/drivers/char/rio/rioroute.c b/drivers/char/rio/rioroute.c
index f98888f526..3570853379 100644
--- a/drivers/char/rio/rioroute.c
+++ b/drivers/char/rio/rioroute.c
@@ -50,15 +50,12 @@ static char *_rioroute_c_sccs_ = "@(#)rioroute.c 1.3";
50 50
51#include "linux_compat.h" 51#include "linux_compat.h"
52#include "rio_linux.h" 52#include "rio_linux.h"
53#include "typdef.h"
54#include "pkt.h" 53#include "pkt.h"
55#include "daemon.h" 54#include "daemon.h"
56#include "rio.h" 55#include "rio.h"
57#include "riospace.h" 56#include "riospace.h"
58#include "top.h"
59#include "cmdpkt.h" 57#include "cmdpkt.h"
60#include "map.h" 58#include "map.h"
61#include "riotypes.h"
62#include "rup.h" 59#include "rup.h"
63#include "port.h" 60#include "port.h"
64#include "riodrvr.h" 61#include "riodrvr.h"
@@ -71,29 +68,25 @@ static char *_rioroute_c_sccs_ = "@(#)rioroute.c 1.3";
71#include "unixrup.h" 68#include "unixrup.h"
72#include "board.h" 69#include "board.h"
73#include "host.h" 70#include "host.h"
74#include "error.h"
75#include "phb.h" 71#include "phb.h"
76#include "link.h" 72#include "link.h"
77#include "cmdblk.h" 73#include "cmdblk.h"
78#include "route.h" 74#include "route.h"
79#include "control.h"
80#include "cirrus.h" 75#include "cirrus.h"
81#include "rioioctl.h" 76#include "rioioctl.h"
82#include "param.h" 77#include "param.h"
83#include "list.h"
84#include "sam.h"
85 78
86static int RIOCheckIsolated(struct rio_info *, struct Host *, uint); 79static int RIOCheckIsolated(struct rio_info *, struct Host *, unsigned int);
87static int RIOIsolate(struct rio_info *, struct Host *, uint); 80static int RIOIsolate(struct rio_info *, struct Host *, unsigned int);
88static int RIOCheck(struct Host *, uint); 81static int RIOCheck(struct Host *, unsigned int);
89static void RIOConCon(struct rio_info *, struct Host *, uint, uint, uint, uint, int); 82static void RIOConCon(struct rio_info *, struct Host *, unsigned int, unsigned int, unsigned int, unsigned int, int);
90 83
91 84
92/* 85/*
93** Incoming on the ROUTE_RUP 86** Incoming on the ROUTE_RUP
94** I wrote this while I was tired. Forgive me. 87** I wrote this while I was tired. Forgive me.
95*/ 88*/
96int RIORouteRup(struct rio_info *p, uint Rup, struct Host *HostP, PKT * PacketP) 89int RIORouteRup(struct rio_info *p, unsigned int Rup, struct Host *HostP, struct PKT * PacketP)
97{ 90{
98 struct PktCmd *PktCmdP = (struct PktCmd *) PacketP->data; 91 struct PktCmd *PktCmdP = (struct PktCmd *) PacketP->data;
99 struct PktCmd_M *PktReplyP; 92 struct PktCmd_M *PktReplyP;
@@ -104,10 +97,10 @@ int RIORouteRup(struct rio_info *p, uint Rup, struct Host *HostP, PKT * PacketP)
104 int ThisLink, ThisLinkMin, ThisLinkMax; 97 int ThisLink, ThisLinkMin, ThisLinkMax;
105 int port; 98 int port;
106 int Mod, Mod1, Mod2; 99 int Mod, Mod1, Mod2;
107 ushort RtaType; 100 unsigned short RtaType;
108 uint RtaUniq; 101 unsigned int RtaUniq;
109 uint ThisUnit, ThisUnit2; /* 2 ids to accommodate 16 port RTA */ 102 unsigned int ThisUnit, ThisUnit2; /* 2 ids to accommodate 16 port RTA */
110 uint OldUnit, NewUnit, OldLink, NewLink; 103 unsigned int OldUnit, NewUnit, OldLink, NewLink;
111 char *MyType, *MyName; 104 char *MyType, *MyName;
112 int Lies; 105 int Lies;
113 unsigned long flags; 106 unsigned long flags;
@@ -115,7 +108,7 @@ int RIORouteRup(struct rio_info *p, uint Rup, struct Host *HostP, PKT * PacketP)
115 /* 108 /*
116 ** Is this unit telling us it's current link topology? 109 ** Is this unit telling us it's current link topology?
117 */ 110 */
118 if (RBYTE(PktCmdP->Command) == ROUTE_TOPOLOGY) { 111 if (readb(&PktCmdP->Command) == ROUTE_TOPOLOGY) {
119 MapP = HostP->Mapping; 112 MapP = HostP->Mapping;
120 113
121 /* 114 /*
@@ -125,7 +118,7 @@ int RIORouteRup(struct rio_info *p, uint Rup, struct Host *HostP, PKT * PacketP)
125 ** from an RTA then we need to fill in the Mapping structure's 118 ** from an RTA then we need to fill in the Mapping structure's
126 ** Topology array for the unit. 119 ** Topology array for the unit.
127 */ 120 */
128 if (Rup >= (ushort) MAX_RUP) { 121 if (Rup >= (unsigned short) MAX_RUP) {
129 ThisUnit = HOST_ID; 122 ThisUnit = HOST_ID;
130 TopP = HostP->Topology; 123 TopP = HostP->Topology;
131 MyType = "Host"; 124 MyType = "Host";
@@ -151,11 +144,11 @@ int RIORouteRup(struct rio_info *p, uint Rup, struct Host *HostP, PKT * PacketP)
151 ** it won't lie about network interconnect, total disconnects 144 ** it won't lie about network interconnect, total disconnects
152 ** and no-IDs. (or at least, it doesn't *matter* if it does) 145 ** and no-IDs. (or at least, it doesn't *matter* if it does)
153 */ 146 */
154 if (RBYTE(PktCmdP->RouteTopology[ThisLink].Unit) > (ushort) MAX_RUP) 147 if (readb(&PktCmdP->RouteTopology[ThisLink].Unit) > (unsigned short) MAX_RUP)
155 continue; 148 continue;
156 149
157 for (NewLink = ThisLinkMin; NewLink < ThisLink; NewLink++) { 150 for (NewLink = ThisLinkMin; NewLink < ThisLink; NewLink++) {
158 if ((RBYTE(PktCmdP->RouteTopology[ThisLink].Unit) == RBYTE(PktCmdP->RouteTopology[NewLink].Unit)) && (RBYTE(PktCmdP->RouteTopology[ThisLink].Link) == RBYTE(PktCmdP->RouteTopology[NewLink].Link))) { 151 if ((readb(&PktCmdP->RouteTopology[ThisLink].Unit) == readb(&PktCmdP->RouteTopology[NewLink].Unit)) && (readb(&PktCmdP->RouteTopology[ThisLink].Link) == readb(&PktCmdP->RouteTopology[NewLink].Link))) {
159 Lies++; 152 Lies++;
160 } 153 }
161 } 154 }
@@ -164,11 +157,11 @@ int RIORouteRup(struct rio_info *p, uint Rup, struct Host *HostP, PKT * PacketP)
164 if (Lies) { 157 if (Lies) {
165 rio_dprintk(RIO_DEBUG_ROUTE, "LIES! DAMN LIES! %d LIES!\n", Lies); 158 rio_dprintk(RIO_DEBUG_ROUTE, "LIES! DAMN LIES! %d LIES!\n", Lies);
166 rio_dprintk(RIO_DEBUG_ROUTE, "%d:%c %d:%c %d:%c %d:%c\n", 159 rio_dprintk(RIO_DEBUG_ROUTE, "%d:%c %d:%c %d:%c %d:%c\n",
167 RBYTE(PktCmdP->RouteTopology[0].Unit), 160 readb(&PktCmdP->RouteTopology[0].Unit),
168 'A' + RBYTE(PktCmdP->RouteTopology[0].Link), 161 'A' + readb(&PktCmdP->RouteTopology[0].Link),
169 RBYTE(PktCmdP->RouteTopology[1].Unit), 162 readb(&PktCmdP->RouteTopology[1].Unit),
170 'A' + RBYTE(PktCmdP->RouteTopology[1].Link), RBYTE(PktCmdP->RouteTopology[2].Unit), 'A' + RBYTE(PktCmdP->RouteTopology[2].Link), RBYTE(PktCmdP->RouteTopology[3].Unit), 'A' + RBYTE(PktCmdP->RouteTopology[3].Link)); 163 'A' + readb(&PktCmdP->RouteTopology[1].Link), readb(&PktCmdP->RouteTopology[2].Unit), 'A' + readb(&PktCmdP->RouteTopology[2].Link), readb(&PktCmdP->RouteTopology[3].Unit), 'A' + readb(&PktCmdP->RouteTopology[3].Link));
171 return TRUE; 164 return 1;
172 } 165 }
173 166
174 /* 167 /*
@@ -184,8 +177,8 @@ int RIORouteRup(struct rio_info *p, uint Rup, struct Host *HostP, PKT * PacketP)
184 /* 177 /*
185 ** this is what it is now connected to 178 ** this is what it is now connected to
186 */ 179 */
187 NewUnit = RBYTE(PktCmdP->RouteTopology[ThisLink].Unit); 180 NewUnit = readb(&PktCmdP->RouteTopology[ThisLink].Unit);
188 NewLink = RBYTE(PktCmdP->RouteTopology[ThisLink].Link); 181 NewLink = readb(&PktCmdP->RouteTopology[ThisLink].Link);
189 182
190 if (OldUnit != NewUnit || OldLink != NewLink) { 183 if (OldUnit != NewUnit || OldLink != NewLink) {
191 /* 184 /*
@@ -219,7 +212,7 @@ int RIORouteRup(struct rio_info *p, uint Rup, struct Host *HostP, PKT * PacketP)
219 212
220 if (NewUnit == ROUTE_INTERCONNECT) { 213 if (NewUnit == ROUTE_INTERCONNECT) {
221 if (!p->RIONoMessage) 214 if (!p->RIONoMessage)
222 cprintf("%s '%s' (%c) is connected to another network.\n", MyType, MyName, 'A' + ThisLink); 215 printk(KERN_DEBUG "rio: %s '%s' (%c) is connected to another network.\n", MyType, MyName, 'A' + ThisLink);
223 } 216 }
224 217
225 /* 218 /*
@@ -258,18 +251,18 @@ int RIORouteRup(struct rio_info *p, uint Rup, struct Host *HostP, PKT * PacketP)
258 RIOCheckIsolated(p, HostP, OldUnit); 251 RIOCheckIsolated(p, HostP, OldUnit);
259 } 252 }
260 } 253 }
261 return TRUE; 254 return 1;
262 } 255 }
263 256
264 /* 257 /*
265 ** The only other command we recognise is a route_request command 258 ** The only other command we recognise is a route_request command
266 */ 259 */
267 if (RBYTE(PktCmdP->Command) != ROUTE_REQUEST) { 260 if (readb(&PktCmdP->Command) != ROUTE_REQUEST) {
268 rio_dprintk(RIO_DEBUG_ROUTE, "Unknown command %d received on rup %d host %d ROUTE_RUP\n", RBYTE(PktCmdP->Command), Rup, (int) HostP); 261 rio_dprintk(RIO_DEBUG_ROUTE, "Unknown command %d received on rup %d host %p ROUTE_RUP\n", readb(&PktCmdP->Command), Rup, HostP);
269 return TRUE; 262 return 1;
270 } 263 }
271 264
272 RtaUniq = (RBYTE(PktCmdP->UniqNum[0])) + (RBYTE(PktCmdP->UniqNum[1]) << 8) + (RBYTE(PktCmdP->UniqNum[2]) << 16) + (RBYTE(PktCmdP->UniqNum[3]) << 24); 265 RtaUniq = (readb(&PktCmdP->UniqNum[0])) + (readb(&PktCmdP->UniqNum[1]) << 8) + (readb(&PktCmdP->UniqNum[2]) << 16) + (readb(&PktCmdP->UniqNum[3]) << 24);
273 266
274 /* 267 /*
275 ** Determine if 8 or 16 port RTA 268 ** Determine if 8 or 16 port RTA
@@ -278,7 +271,7 @@ int RIORouteRup(struct rio_info *p, uint Rup, struct Host *HostP, PKT * PacketP)
278 271
279 rio_dprintk(RIO_DEBUG_ROUTE, "Received a request for an ID for serial number %x\n", RtaUniq); 272 rio_dprintk(RIO_DEBUG_ROUTE, "Received a request for an ID for serial number %x\n", RtaUniq);
280 273
281 Mod = RBYTE(PktCmdP->ModuleTypes); 274 Mod = readb(&PktCmdP->ModuleTypes);
282 Mod1 = LONYBLE(Mod); 275 Mod1 = LONYBLE(Mod);
283 if (RtaType == TYPE_RTA16) { 276 if (RtaType == TYPE_RTA16) {
284 /* 277 /*
@@ -292,10 +285,6 @@ int RIORouteRup(struct rio_info *p, uint Rup, struct Host *HostP, PKT * PacketP)
292 rio_dprintk(RIO_DEBUG_ROUTE, "Module types are %s (ports 0-3) and %s (ports 4-7)\n", p->RIOModuleTypes[Mod1].Name, p->RIOModuleTypes[Mod2].Name); 285 rio_dprintk(RIO_DEBUG_ROUTE, "Module types are %s (ports 0-3) and %s (ports 4-7)\n", p->RIOModuleTypes[Mod1].Name, p->RIOModuleTypes[Mod2].Name);
293 } 286 }
294 287
295 if (RtaUniq == 0xffffffff) {
296 ShowPacket(DBG_SPECIAL, PacketP);
297 }
298
299 /* 288 /*
300 ** try to unhook a command block from the command free list. 289 ** try to unhook a command block from the command free list.
301 */ 290 */
@@ -320,7 +309,7 @@ int RIORouteRup(struct rio_info *p, uint Rup, struct Host *HostP, PKT * PacketP)
320 PktReplyP->Command = ROUTE_FOAD; 309 PktReplyP->Command = ROUTE_FOAD;
321 HostP->Copy("RT_FOAD", PktReplyP->CommandText, 7); 310 HostP->Copy("RT_FOAD", PktReplyP->CommandText, 7);
322 RIOQueueCmdBlk(HostP, Rup, CmdBlkP); 311 RIOQueueCmdBlk(HostP, Rup, CmdBlkP);
323 return TRUE; 312 return 1;
324 } 313 }
325 314
326 /* 315 /*
@@ -348,13 +337,13 @@ int RIORouteRup(struct rio_info *p, uint Rup, struct Host *HostP, PKT * PacketP)
348 if ((HostP->Mapping[ThisUnit].Flags & SLOT_IN_USE) && !(HostP->Mapping[ThisUnit].Flags & RTA_BOOTED)) { 337 if ((HostP->Mapping[ThisUnit].Flags & SLOT_IN_USE) && !(HostP->Mapping[ThisUnit].Flags & RTA_BOOTED)) {
349 if (!(HostP->Mapping[ThisUnit].Flags & MSG_DONE)) { 338 if (!(HostP->Mapping[ThisUnit].Flags & MSG_DONE)) {
350 if (!p->RIONoMessage) 339 if (!p->RIONoMessage)
351 cprintf("RTA '%s' is being updated.\n", HostP->Mapping[ThisUnit].Name); 340 printk(KERN_DEBUG "rio: RTA '%s' is being updated.\n", HostP->Mapping[ThisUnit].Name);
352 HostP->Mapping[ThisUnit].Flags |= MSG_DONE; 341 HostP->Mapping[ThisUnit].Flags |= MSG_DONE;
353 } 342 }
354 PktReplyP->Command = ROUTE_FOAD; 343 PktReplyP->Command = ROUTE_FOAD;
355 HostP->Copy("RT_FOAD", PktReplyP->CommandText, 7); 344 HostP->Copy("RT_FOAD", PktReplyP->CommandText, 7);
356 RIOQueueCmdBlk(HostP, Rup, CmdBlkP); 345 RIOQueueCmdBlk(HostP, Rup, CmdBlkP);
357 return TRUE; 346 return 1;
358 } 347 }
359 348
360 /* 349 /*
@@ -447,7 +436,7 @@ int RIORouteRup(struct rio_info *p, uint Rup, struct Host *HostP, PKT * PacketP)
447 /* 436 /*
448 ** Job done, get on with the interrupts! 437 ** Job done, get on with the interrupts!
449 */ 438 */
450 return TRUE; 439 return 1;
451 } 440 }
452 } 441 }
453 /* 442 /*
@@ -475,7 +464,7 @@ int RIORouteRup(struct rio_info *p, uint Rup, struct Host *HostP, PKT * PacketP)
475 464
476 if (!UnknownMesgDone) { 465 if (!UnknownMesgDone) {
477 if (!p->RIONoMessage) 466 if (!p->RIONoMessage)
478 cprintf("One or more unknown RTAs are being updated.\n"); 467 printk(KERN_DEBUG "rio: One or more unknown RTAs are being updated.\n");
479 UnknownMesgDone = 1; 468 UnknownMesgDone = 1;
480 } 469 }
481 470
@@ -491,28 +480,25 @@ int RIORouteRup(struct rio_info *p, uint Rup, struct Host *HostP, PKT * PacketP)
491 if (RtaType == TYPE_RTA16) { 480 if (RtaType == TYPE_RTA16) {
492 if (RIOFindFreeID(p, HostP, &ThisUnit, &ThisUnit2) == 0) { 481 if (RIOFindFreeID(p, HostP, &ThisUnit, &ThisUnit2) == 0) {
493 RIODefaultName(p, HostP, ThisUnit); 482 RIODefaultName(p, HostP, ThisUnit);
494 FillSlot(ThisUnit, ThisUnit2, RtaUniq, HostP); 483 rio_fill_host_slot(ThisUnit, ThisUnit2, RtaUniq, HostP);
495 } 484 }
496 } else { 485 } else {
497 if (RIOFindFreeID(p, HostP, &ThisUnit, NULL) == 0) { 486 if (RIOFindFreeID(p, HostP, &ThisUnit, NULL) == 0) {
498 RIODefaultName(p, HostP, ThisUnit); 487 RIODefaultName(p, HostP, ThisUnit);
499 FillSlot(ThisUnit, 0, RtaUniq, HostP); 488 rio_fill_host_slot(ThisUnit, 0, RtaUniq, HostP);
500 } 489 }
501 } 490 }
502 PktReplyP->Command = ROUTE_USED; 491 PktReplyP->Command = ROUTE_USED;
503 HostP->Copy("RT_USED", PktReplyP->CommandText, 7); 492 HostP->Copy("RT_USED", PktReplyP->CommandText, 7);
504 } 493 }
505 RIOQueueCmdBlk(HostP, Rup, CmdBlkP); 494 RIOQueueCmdBlk(HostP, Rup, CmdBlkP);
506 return TRUE; 495 return 1;
507} 496}
508 497
509 498
510void RIOFixPhbs(p, HostP, unit) 499void RIOFixPhbs(struct rio_info *p, struct Host *HostP, unsigned int unit)
511struct rio_info *p;
512struct Host *HostP;
513uint unit;
514{ 500{
515 ushort link, port; 501 unsigned short link, port;
516 struct Port *PortP; 502 struct Port *PortP;
517 unsigned long flags; 503 unsigned long flags;
518 int PortN = HostP->Mapping[unit].SysPort; 504 int PortN = HostP->Mapping[unit].SysPort;
@@ -520,19 +506,19 @@ uint unit;
520 rio_dprintk(RIO_DEBUG_ROUTE, "RIOFixPhbs unit %d sysport %d\n", unit, PortN); 506 rio_dprintk(RIO_DEBUG_ROUTE, "RIOFixPhbs unit %d sysport %d\n", unit, PortN);
521 507
522 if (PortN != -1) { 508 if (PortN != -1) {
523 ushort dest_unit = HostP->Mapping[unit].ID2; 509 unsigned short dest_unit = HostP->Mapping[unit].ID2;
524 510
525 /* 511 /*
526 ** Get the link number used for the 1st 8 phbs on this unit. 512 ** Get the link number used for the 1st 8 phbs on this unit.
527 */ 513 */
528 PortP = p->RIOPortp[HostP->Mapping[dest_unit - 1].SysPort]; 514 PortP = p->RIOPortp[HostP->Mapping[dest_unit - 1].SysPort];
529 515
530 link = RWORD(PortP->PhbP->link); 516 link = readw(&PortP->PhbP->link);
531 517
532 for (port = 0; port < PORTS_PER_RTA; port++, PortN++) { 518 for (port = 0; port < PORTS_PER_RTA; port++, PortN++) {
533 ushort dest_port = port + 8; 519 unsigned short dest_port = port + 8;
534 WORD *TxPktP; 520 u16 *TxPktP;
535 PKT *Pkt; 521 struct PKT *Pkt;
536 522
537 PortP = p->RIOPortp[PortN]; 523 PortP = p->RIOPortp[PortN];
538 524
@@ -569,18 +555,18 @@ uint unit;
569 ** card. This needs to be translated into a 32 bit pointer 555 ** card. This needs to be translated into a 32 bit pointer
570 ** so it can be accessed from the driver. 556 ** so it can be accessed from the driver.
571 */ 557 */
572 Pkt = (PKT *) RIO_PTR(HostP->Caddr, RINDW(TxPktP)); 558 Pkt = (struct PKT *) RIO_PTR(HostP->Caddr, readw(TxPktP));
573 559
574 /* 560 /*
575 ** If the packet is used, reset it. 561 ** If the packet is used, reset it.
576 */ 562 */
577 Pkt = (PKT *) ((uint) Pkt & ~PKT_IN_USE); 563 Pkt = (struct PKT *) ((unsigned long) Pkt & ~PKT_IN_USE);
578 WBYTE(Pkt->dest_unit, dest_unit); 564 writeb(dest_unit, &Pkt->dest_unit);
579 WBYTE(Pkt->dest_port, dest_port); 565 writeb(dest_port, &Pkt->dest_port);
580 } 566 }
581 rio_dprintk(RIO_DEBUG_ROUTE, "phb dest: Old %x:%x New %x:%x\n", RWORD(PortP->PhbP->destination) & 0xff, (RWORD(PortP->PhbP->destination) >> 8) & 0xff, dest_unit, dest_port); 567 rio_dprintk(RIO_DEBUG_ROUTE, "phb dest: Old %x:%x New %x:%x\n", readw(&PortP->PhbP->destination) & 0xff, (readw(&PortP->PhbP->destination) >> 8) & 0xff, dest_unit, dest_port);
582 WWORD(PortP->PhbP->destination, dest_unit + (dest_port << 8)); 568 writew(dest_unit + (dest_port << 8), &PortP->PhbP->destination);
583 WWORD(PortP->PhbP->link, link); 569 writew(link, &PortP->PhbP->link);
584 570
585 rio_spin_unlock_irqrestore(&PortP->portSem, flags); 571 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
586 } 572 }
@@ -590,9 +576,9 @@ uint unit;
590 */ 576 */
591 if (link > 3) 577 if (link > 3)
592 return; 578 return;
593 if (((unit * 8) + 7) > RWORD(HostP->LinkStrP[link].last_port)) { 579 if (((unit * 8) + 7) > readw(&HostP->LinkStrP[link].last_port)) {
594 rio_dprintk(RIO_DEBUG_ROUTE, "last port on host link %d: %d\n", link, (unit * 8) + 7); 580 rio_dprintk(RIO_DEBUG_ROUTE, "last port on host link %d: %d\n", link, (unit * 8) + 7);
595 WWORD(HostP->LinkStrP[link].last_port, (unit * 8) + 7); 581 writew((unit * 8) + 7, &HostP->LinkStrP[link].last_port);
596 } 582 }
597 } 583 }
598} 584}
@@ -603,10 +589,7 @@ uint unit;
603** the world about it. This is done to ensure that the configurator 589** the world about it. This is done to ensure that the configurator
604** only gets up-to-date information about what is going on. 590** only gets up-to-date information about what is going on.
605*/ 591*/
606static int RIOCheckIsolated(p, HostP, UnitId) 592static int RIOCheckIsolated(struct rio_info *p, struct Host *HostP, unsigned int UnitId)
607struct rio_info *p;
608struct Host *HostP;
609uint UnitId;
610{ 593{
611 unsigned long flags; 594 unsigned long flags;
612 rio_spin_lock_irqsave(&HostP->HostLock, flags); 595 rio_spin_lock_irqsave(&HostP->HostLock, flags);
@@ -628,12 +611,9 @@ uint UnitId;
628** all the units attached to it. This will mean that the entire 611** all the units attached to it. This will mean that the entire
629** subnet will re-introduce itself. 612** subnet will re-introduce itself.
630*/ 613*/
631static int RIOIsolate(p, HostP, UnitId) 614static int RIOIsolate(struct rio_info *p, struct Host *HostP, unsigned int UnitId)
632struct rio_info *p;
633struct Host *HostP;
634uint UnitId;
635{ 615{
636 uint link, unit; 616 unsigned int link, unit;
637 617
638 UnitId--; /* this trick relies on the Unit Id being UNSIGNED! */ 618 UnitId--; /* this trick relies on the Unit Id being UNSIGNED! */
639 619
@@ -658,9 +638,7 @@ uint UnitId;
658 return 1; 638 return 1;
659} 639}
660 640
661static int RIOCheck(HostP, UnitId) 641static int RIOCheck(struct Host *HostP, unsigned int UnitId)
662struct Host *HostP;
663uint UnitId;
664{ 642{
665 unsigned char link; 643 unsigned char link;
666 644
@@ -714,8 +692,7 @@ uint UnitId;
714** Returns the type of unit (host, 16/8 port RTA) 692** Returns the type of unit (host, 16/8 port RTA)
715*/ 693*/
716 694
717uint GetUnitType(Uniq) 695unsigned int GetUnitType(unsigned int Uniq)
718uint Uniq;
719{ 696{
720 switch ((Uniq >> 28) & 0xf) { 697 switch ((Uniq >> 28) & 0xf) {
721 case RIO_AT: 698 case RIO_AT:
@@ -736,8 +713,7 @@ uint Uniq;
736 } 713 }
737} 714}
738 715
739int RIOSetChange(p) 716int RIOSetChange(struct rio_info *p)
740struct rio_info *p;
741{ 717{
742 if (p->RIOQuickCheck != NOT_CHANGED) 718 if (p->RIOQuickCheck != NOT_CHANGED)
743 return (0); 719 return (0);
@@ -751,14 +727,13 @@ struct rio_info *p;
751 return (0); 727 return (0);
752} 728}
753 729
754static void RIOConCon(p, HostP, FromId, FromLink, ToId, ToLink, Change) 730static void RIOConCon(struct rio_info *p,
755struct rio_info *p; 731 struct Host *HostP,
756struct Host *HostP; 732 unsigned int FromId,
757uint FromId; 733 unsigned int FromLink,
758uint FromLink; 734 unsigned int ToId,
759uint ToId; 735 unsigned int ToLink,
760uint ToLink; 736 int Change)
761int Change;
762{ 737{
763 char *FromName; 738 char *FromName;
764 char *FromType; 739 char *FromType;
@@ -818,7 +793,7 @@ int Change;
818 ToType = ToId ? "RTA" : "HOST"; 793 ToType = ToId ? "RTA" : "HOST";
819 794
820 rio_dprintk(RIO_DEBUG_ROUTE, "Link between %s '%s' (%c) and %s '%s' (%c) %s.\n", FromType, FromName, 'A' + FromLink, ToType, ToName, 'A' + ToLink, (Change == CONNECT) ? "established" : "disconnected"); 795 rio_dprintk(RIO_DEBUG_ROUTE, "Link between %s '%s' (%c) and %s '%s' (%c) %s.\n", FromType, FromName, 'A' + FromLink, ToType, ToName, 'A' + ToLink, (Change == CONNECT) ? "established" : "disconnected");
821 cprintf("Link between %s '%s' (%c) and %s '%s' (%c) %s.\n", FromType, FromName, 'A' + FromLink, ToType, ToName, 'A' + ToLink, (Change == CONNECT) ? "established" : "disconnected"); 796 printk(KERN_DEBUG "rio: Link between %s '%s' (%c) and %s '%s' (%c) %s.\n", FromType, FromName, 'A' + FromLink, ToType, ToName, 'A' + ToLink, (Change == CONNECT) ? "established" : "disconnected");
822} 797}
823 798
824/* 799/*
@@ -838,7 +813,7 @@ static int RIORemoveFromSavedTable(struct rio_info *p, struct Map *pMap)
838 */ 813 */
839 for (entry = 0; entry < TOTAL_MAP_ENTRIES; entry++) { 814 for (entry = 0; entry < TOTAL_MAP_ENTRIES; entry++) {
840 if (p->RIOSavedTable[entry].RtaUniqueNum == pMap->RtaUniqueNum) { 815 if (p->RIOSavedTable[entry].RtaUniqueNum == pMap->RtaUniqueNum) {
841 bzero((caddr_t) & p->RIOSavedTable[entry], sizeof(struct Map)); 816 memset(&p->RIOSavedTable[entry], 0, sizeof(struct Map));
842 } 817 }
843 } 818 }
844 return 0; 819 return 0;
@@ -898,7 +873,7 @@ static int RIOFreeDisconnected(struct rio_info *p, struct Host *HostP, int unit)
898 int nOther = (HostP->Mapping[unit].ID2) - 1; 873 int nOther = (HostP->Mapping[unit].ID2) - 1;
899 874
900 rio_dprintk(RIO_DEBUG_ROUTE, "RioFreedis second slot %d.\n", nOther); 875 rio_dprintk(RIO_DEBUG_ROUTE, "RioFreedis second slot %d.\n", nOther);
901 bzero((caddr_t) & HostP->Mapping[nOther], sizeof(struct Map)); 876 memset(&HostP->Mapping[nOther], 0, sizeof(struct Map));
902 } 877 }
903 RIORemoveFromSavedTable(p, &HostP->Mapping[unit]); 878 RIORemoveFromSavedTable(p, &HostP->Mapping[unit]);
904 879
@@ -912,7 +887,8 @@ static int RIOFreeDisconnected(struct rio_info *p, struct Host *HostP, int unit)
912** This function scans the given host table for either one 887** This function scans the given host table for either one
913** or two free unit ID's. 888** or two free unit ID's.
914*/ 889*/
915int RIOFindFreeID(struct rio_info *p, struct Host *HostP, uint * pID1, uint * pID2) 890
891int RIOFindFreeID(struct rio_info *p, struct Host *HostP, unsigned int * pID1, unsigned int * pID2)
916{ 892{
917 int unit, tempID; 893 int unit, tempID;
918 894
@@ -997,7 +973,7 @@ int RIOFindFreeID(struct rio_info *p, struct Host *HostP, uint * pID1, uint * pI
997 /* 973 /*
998 ** Clear out this slot now that we intend to use it. 974 ** Clear out this slot now that we intend to use it.
999 */ 975 */
1000 bzero(&HostP->Mapping[unit], sizeof(struct Map)); 976 memset(&HostP->Mapping[unit], 0, sizeof(struct Map));
1001 977
1002 /* 978 /*
1003 ** If the second ID is not needed then we can return 979 ** If the second ID is not needed then we can return
@@ -1015,7 +991,7 @@ int RIOFindFreeID(struct rio_info *p, struct Host *HostP, uint * pID1, uint * pI
1015 /* 991 /*
1016 ** Clear out this slot now that we intend to use it. 992 ** Clear out this slot now that we intend to use it.
1017 */ 993 */
1018 bzero(&HostP->Mapping[unit], sizeof(struct Map)); 994 memset(&HostP->Mapping[unit], 0, sizeof(struct Map));
1019 995
1020 /* At this point under the right(wrong?) conditions 996 /* At this point under the right(wrong?) conditions
1021 ** we may have a first unit ID being higher than the 997 ** we may have a first unit ID being higher than the
diff --git a/drivers/char/rio/riotable.c b/drivers/char/rio/riotable.c
index a86b216ab6..d3abe0d37d 100644
--- a/drivers/char/rio/riotable.c
+++ b/drivers/char/rio/riotable.c
@@ -53,15 +53,12 @@ static char *_riotable_c_sccs_ = "@(#)riotable.c 1.2";
53 53
54#include "linux_compat.h" 54#include "linux_compat.h"
55#include "rio_linux.h" 55#include "rio_linux.h"
56#include "typdef.h"
57#include "pkt.h" 56#include "pkt.h"
58#include "daemon.h" 57#include "daemon.h"
59#include "rio.h" 58#include "rio.h"
60#include "riospace.h" 59#include "riospace.h"
61#include "top.h"
62#include "cmdpkt.h" 60#include "cmdpkt.h"
63#include "map.h" 61#include "map.h"
64#include "riotypes.h"
65#include "rup.h" 62#include "rup.h"
66#include "port.h" 63#include "port.h"
67#include "riodrvr.h" 64#include "riodrvr.h"
@@ -74,25 +71,20 @@ static char *_riotable_c_sccs_ = "@(#)riotable.c 1.2";
74#include "unixrup.h" 71#include "unixrup.h"
75#include "board.h" 72#include "board.h"
76#include "host.h" 73#include "host.h"
77#include "error.h"
78#include "phb.h" 74#include "phb.h"
79#include "link.h" 75#include "link.h"
80#include "cmdblk.h" 76#include "cmdblk.h"
81#include "route.h" 77#include "route.h"
82#include "control.h"
83#include "cirrus.h" 78#include "cirrus.h"
84#include "rioioctl.h" 79#include "rioioctl.h"
85#include "param.h" 80#include "param.h"
86#include "list.h"
87#include "sam.h"
88#include "protsts.h" 81#include "protsts.h"
89 82
90/* 83/*
91** A configuration table has been loaded. It is now up to us 84** A configuration table has been loaded. It is now up to us
92** to sort it out and use the information contained therein. 85** to sort it out and use the information contained therein.
93*/ 86*/
94int RIONewTable(p) 87int RIONewTable(struct rio_info *p)
95struct rio_info *p;
96{ 88{
97 int Host, Host1, Host2, NameIsUnique, Entry, SubEnt; 89 int Host, Host1, Host2, NameIsUnique, Entry, SubEnt;
98 struct Map *MapP; 90 struct Map *MapP;
@@ -137,7 +129,7 @@ struct rio_info *p;
137 cptr = MapP->Name; /* (2) */ 129 cptr = MapP->Name; /* (2) */
138 cptr[MAX_NAME_LEN - 1] = '\0'; 130 cptr[MAX_NAME_LEN - 1] = '\0';
139 if (cptr[0] == '\0') { 131 if (cptr[0] == '\0') {
140 bcopy(MapP->RtaUniqueNum ? "RTA NN" : "HOST NN", MapP->Name, 8); 132 memcpy(MapP->Name, MapP->RtaUniqueNum ? "RTA NN" : "HOST NN", 8);
141 MapP->Name[5] = '0' + Entry / 10; 133 MapP->Name[5] = '0' + Entry / 10;
142 MapP->Name[6] = '0' + Entry % 10; 134 MapP->Name[6] = '0' + Entry % 10;
143 } 135 }
@@ -298,9 +290,9 @@ struct rio_info *p;
298 */ 290 */
299 for (Host = 0; Host < RIO_HOSTS; Host++) { 291 for (Host = 0; Host < RIO_HOSTS; Host++) {
300 for (Entry = 0; Entry < MAX_RUP; Entry++) { 292 for (Entry = 0; Entry < MAX_RUP; Entry++) {
301 bzero((caddr_t) & p->RIOHosts[Host].Mapping[Entry], sizeof(struct Map)); 293 memset(&p->RIOHosts[Host].Mapping[Entry], 0, sizeof(struct Map));
302 } 294 }
303 bzero((caddr_t) & p->RIOHosts[Host].Name[0], sizeof(p->RIOHosts[Host].Name)); 295 memset(&p->RIOHosts[Host].Name[0], 0, sizeof(p->RIOHosts[Host].Name));
304 } 296 }
305 297
306 /* 298 /*
@@ -326,7 +318,7 @@ struct rio_info *p;
326 */ 318 */
327 if (MapP->ID == 0) { 319 if (MapP->ID == 0) {
328 rio_dprintk(RIO_DEBUG_TABLE, "Host entry found. Name %s\n", MapP->Name); 320 rio_dprintk(RIO_DEBUG_TABLE, "Host entry found. Name %s\n", MapP->Name);
329 bcopy(MapP->Name, HostP->Name, MAX_NAME_LEN); 321 memcpy(HostP->Name, MapP->Name, MAX_NAME_LEN);
330 continue; 322 continue;
331 } 323 }
332 324
@@ -370,7 +362,7 @@ struct rio_info *p;
370 } 362 }
371 } 363 }
372 if (!p->RIOHosts[Host].Name[0]) { 364 if (!p->RIOHosts[Host].Name[0]) {
373 bcopy("HOST 1", p->RIOHosts[Host].Name, 7); 365 memcpy(p->RIOHosts[Host].Name, "HOST 1", 7);
374 p->RIOHosts[Host].Name[5] += Host; 366 p->RIOHosts[Host].Name[5] += Host;
375 } 367 }
376 /* 368 /*
@@ -398,7 +390,7 @@ struct rio_info *p;
398 */ 390 */
399 if (Host1 != Host) { 391 if (Host1 != Host) {
400 rio_dprintk(RIO_DEBUG_TABLE, "Default name %s already used\n", p->RIOHosts[Host].Name); 392 rio_dprintk(RIO_DEBUG_TABLE, "Default name %s already used\n", p->RIOHosts[Host].Name);
401 bcopy("HOST 1", p->RIOHosts[Host].Name, 7); 393 memcpy(p->RIOHosts[Host].Name, "HOST 1", 7);
402 p->RIOHosts[Host].Name[5] += Host1; 394 p->RIOHosts[Host].Name[5] += Host1;
403 } 395 }
404 rio_dprintk(RIO_DEBUG_TABLE, "Assigning default name %s\n", p->RIOHosts[Host].Name); 396 rio_dprintk(RIO_DEBUG_TABLE, "Assigning default name %s\n", p->RIOHosts[Host].Name);
@@ -409,9 +401,10 @@ struct rio_info *p;
409/* 401/*
410** User process needs the config table - build it from first 402** User process needs the config table - build it from first
411** principles. 403** principles.
404**
405* FIXME: SMP locking
412*/ 406*/
413int RIOApel(p) 407int RIOApel(struct rio_info *p)
414struct rio_info *p;
415{ 408{
416 int Host; 409 int Host;
417 int link; 410 int link;
@@ -419,17 +412,17 @@ struct rio_info *p;
419 int Next = 0; 412 int Next = 0;
420 struct Map *MapP; 413 struct Map *MapP;
421 struct Host *HostP; 414 struct Host *HostP;
422 long oldspl; 415 unsigned long flags;
423
424 disable(oldspl); /* strange but true! */
425 416
426 rio_dprintk(RIO_DEBUG_TABLE, "Generating a table to return to config.rio\n"); 417 rio_dprintk(RIO_DEBUG_TABLE, "Generating a table to return to config.rio\n");
427 418
428 bzero((caddr_t) & p->RIOConnectTable[0], sizeof(struct Map) * TOTAL_MAP_ENTRIES); 419 memset(&p->RIOConnectTable[0], 0, sizeof(struct Map) * TOTAL_MAP_ENTRIES);
429 420
430 for (Host = 0; Host < RIO_HOSTS; Host++) { 421 for (Host = 0; Host < RIO_HOSTS; Host++) {
431 rio_dprintk(RIO_DEBUG_TABLE, "Processing host %d\n", Host); 422 rio_dprintk(RIO_DEBUG_TABLE, "Processing host %d\n", Host);
432 HostP = &p->RIOHosts[Host]; 423 HostP = &p->RIOHosts[Host];
424 rio_spin_lock_irqsave(&HostP->HostLock, flags);
425
433 MapP = &p->RIOConnectTable[Next++]; 426 MapP = &p->RIOConnectTable[Next++];
434 MapP->HostUniqueNum = HostP->UniqueNum; 427 MapP->HostUniqueNum = HostP->UniqueNum;
435 if ((HostP->Flags & RUN_STATE) != RC_RUNNING) 428 if ((HostP->Flags & RUN_STATE) != RC_RUNNING)
@@ -440,7 +433,7 @@ struct rio_info *p;
440 MapP->SysPort = NO_PORT; 433 MapP->SysPort = NO_PORT;
441 for (link = 0; link < LINKS_PER_UNIT; link++) 434 for (link = 0; link < LINKS_PER_UNIT; link++)
442 MapP->Topology[link] = HostP->Topology[link]; 435 MapP->Topology[link] = HostP->Topology[link];
443 bcopy(HostP->Name, MapP->Name, MAX_NAME_LEN); 436 memcpy(MapP->Name, HostP->Name, MAX_NAME_LEN);
444 for (Rup = 0; Rup < MAX_RUP; Rup++) { 437 for (Rup = 0; Rup < MAX_RUP; Rup++) {
445 if (HostP->Mapping[Rup].Flags & (SLOT_IN_USE | SLOT_TENTATIVE)) { 438 if (HostP->Mapping[Rup].Flags & (SLOT_IN_USE | SLOT_TENTATIVE)) {
446 p->RIOConnectTable[Next] = HostP->Mapping[Rup]; 439 p->RIOConnectTable[Next] = HostP->Mapping[Rup];
@@ -453,8 +446,8 @@ struct rio_info *p;
453 Next++; 446 Next++;
454 } 447 }
455 } 448 }
449 rio_spin_unlock_irqrestore(&HostP->HostLock, flags);
456 } 450 }
457 restore(oldspl);
458 return 0; 451 return 0;
459} 452}
460 453
@@ -463,9 +456,7 @@ struct rio_info *p;
463** if the entry is suitably inactive, then we can gob on it and remove 456** if the entry is suitably inactive, then we can gob on it and remove
464** it from the table. 457** it from the table.
465*/ 458*/
466int RIODeleteRta(p, MapP) 459int RIODeleteRta(struct rio_info *p, struct Map *MapP)
467struct rio_info *p;
468struct Map *MapP;
469{ 460{
470 int host, entry, port, link; 461 int host, entry, port, link;
471 int SysPort; 462 int SysPort;
@@ -541,10 +532,10 @@ struct Map *MapP;
541 ** the phb to port mappings in RIORouteRup. 532 ** the phb to port mappings in RIORouteRup.
542 */ 533 */
543 if (PortP->SecondBlock) { 534 if (PortP->SecondBlock) {
544 ushort dest_unit = HostMapP->ID; 535 u16 dest_unit = HostMapP->ID;
545 ushort dest_port = port - SysPort; 536 u16 dest_port = port - SysPort;
546 WORD *TxPktP; 537 u16 *TxPktP;
547 PKT *Pkt; 538 struct PKT *Pkt;
548 539
549 for (TxPktP = PortP->TxStart; TxPktP <= PortP->TxEnd; TxPktP++) { 540 for (TxPktP = PortP->TxStart; TxPktP <= PortP->TxEnd; TxPktP++) {
550 /* 541 /*
@@ -554,19 +545,19 @@ struct Map *MapP;
554 ** a 32 bit pointer so it can be 545 ** a 32 bit pointer so it can be
555 ** accessed from the driver. 546 ** accessed from the driver.
556 */ 547 */
557 Pkt = (PKT *) RIO_PTR(HostP->Caddr, RWORD(*TxPktP)); 548 Pkt = (struct PKT *) RIO_PTR(HostP->Caddr, readw(&*TxPktP));
558 rio_dprintk(RIO_DEBUG_TABLE, "Tx packet (%x) destination: Old %x:%x New %x:%x\n", *TxPktP, Pkt->dest_unit, Pkt->dest_port, dest_unit, dest_port); 549 rio_dprintk(RIO_DEBUG_TABLE, "Tx packet (%x) destination: Old %x:%x New %x:%x\n", *TxPktP, Pkt->dest_unit, Pkt->dest_port, dest_unit, dest_port);
559 WWORD(Pkt->dest_unit, dest_unit); 550 writew(dest_unit, &Pkt->dest_unit);
560 WWORD(Pkt->dest_port, dest_port); 551 writew(dest_port, &Pkt->dest_port);
561 } 552 }
562 rio_dprintk(RIO_DEBUG_TABLE, "Port %d phb destination: Old %x:%x New %x:%x\n", port, PortP->PhbP->destination & 0xff, (PortP->PhbP->destination >> 8) & 0xff, dest_unit, dest_port); 553 rio_dprintk(RIO_DEBUG_TABLE, "Port %d phb destination: Old %x:%x New %x:%x\n", port, PortP->PhbP->destination & 0xff, (PortP->PhbP->destination >> 8) & 0xff, dest_unit, dest_port);
563 WWORD(PortP->PhbP->destination, dest_unit + (dest_port << 8)); 554 writew(dest_unit + (dest_port << 8), &PortP->PhbP->destination);
564 } 555 }
565 rio_spin_unlock_irqrestore(&PortP->portSem, sem_flags); 556 rio_spin_unlock_irqrestore(&PortP->portSem, sem_flags);
566 } 557 }
567 } 558 }
568 rio_dprintk(RIO_DEBUG_TABLE, "Entry nulled.\n"); 559 rio_dprintk(RIO_DEBUG_TABLE, "Entry nulled.\n");
569 bzero((char *) HostMapP, sizeof(struct Map)); 560 memset(HostMapP, 0, sizeof(struct Map));
570 work_done++; 561 work_done++;
571 } 562 }
572 } 563 }
@@ -576,11 +567,11 @@ struct Map *MapP;
576 /* XXXXX lock me up */ 567 /* XXXXX lock me up */
577 for (entry = 0; entry < TOTAL_MAP_ENTRIES; entry++) { 568 for (entry = 0; entry < TOTAL_MAP_ENTRIES; entry++) {
578 if (p->RIOSavedTable[entry].RtaUniqueNum == MapP->RtaUniqueNum) { 569 if (p->RIOSavedTable[entry].RtaUniqueNum == MapP->RtaUniqueNum) {
579 bzero((char *) &p->RIOSavedTable[entry], sizeof(struct Map)); 570 memset(&p->RIOSavedTable[entry], 0, sizeof(struct Map));
580 work_done++; 571 work_done++;
581 } 572 }
582 if (p->RIOConnectTable[entry].RtaUniqueNum == MapP->RtaUniqueNum) { 573 if (p->RIOConnectTable[entry].RtaUniqueNum == MapP->RtaUniqueNum) {
583 bzero((char *) &p->RIOConnectTable[entry], sizeof(struct Map)); 574 memset(&p->RIOConnectTable[entry], 0, sizeof(struct Map));
584 work_done++; 575 work_done++;
585 } 576 }
586 } 577 }
@@ -602,7 +593,7 @@ int RIOAssignRta(struct rio_info *p, struct Map *MapP)
602 593
603 rio_dprintk(RIO_DEBUG_TABLE, "Assign entry on host %x, rta %x, ID %d, Sysport %d\n", MapP->HostUniqueNum, MapP->RtaUniqueNum, MapP->ID, (int) MapP->SysPort); 594 rio_dprintk(RIO_DEBUG_TABLE, "Assign entry on host %x, rta %x, ID %d, Sysport %d\n", MapP->HostUniqueNum, MapP->RtaUniqueNum, MapP->ID, (int) MapP->SysPort);
604 595
605 if ((MapP->ID != (ushort) - 1) && ((int) MapP->ID < (int) 1 || (int) MapP->ID > MAX_RUP)) { 596 if ((MapP->ID != (u16) - 1) && ((int) MapP->ID < (int) 1 || (int) MapP->ID > MAX_RUP)) {
606 rio_dprintk(RIO_DEBUG_TABLE, "Bad ID in map entry!\n"); 597 rio_dprintk(RIO_DEBUG_TABLE, "Bad ID in map entry!\n");
607 p->RIOError.Error = ID_NUMBER_OUT_OF_RANGE; 598 p->RIOError.Error = ID_NUMBER_OUT_OF_RANGE;
608 return -EINVAL; 599 return -EINVAL;
@@ -648,7 +639,7 @@ int RIOAssignRta(struct rio_info *p, struct Map *MapP)
648 ** Now we have a host we need to allocate an ID 639 ** Now we have a host we need to allocate an ID
649 ** if the entry does not already have one. 640 ** if the entry does not already have one.
650 */ 641 */
651 if (MapP->ID == (ushort) - 1) { 642 if (MapP->ID == (u16) - 1) {
652 int nNewID; 643 int nNewID;
653 644
654 rio_dprintk(RIO_DEBUG_TABLE, "Attempting to get a new ID for rta \"%s\"\n", MapP->Name); 645 rio_dprintk(RIO_DEBUG_TABLE, "Attempting to get a new ID for rta \"%s\"\n", MapP->Name);
@@ -667,7 +658,7 @@ int RIOAssignRta(struct rio_info *p, struct Map *MapP)
667 p->RIOError.Error = COULDNT_FIND_ENTRY; 658 p->RIOError.Error = COULDNT_FIND_ENTRY;
668 return -EBUSY; 659 return -EBUSY;
669 } 660 }
670 MapP->ID = (ushort) nNewID + 1; 661 MapP->ID = (u16) nNewID + 1;
671 rio_dprintk(RIO_DEBUG_TABLE, "Allocated ID %d for this new RTA.\n", MapP->ID); 662 rio_dprintk(RIO_DEBUG_TABLE, "Allocated ID %d for this new RTA.\n", MapP->ID);
672 HostMapP = &p->RIOHosts[host].Mapping[nNewID]; 663 HostMapP = &p->RIOHosts[host].Mapping[nNewID];
673 HostMapP->RtaUniqueNum = MapP->RtaUniqueNum; 664 HostMapP->RtaUniqueNum = MapP->RtaUniqueNum;
@@ -708,7 +699,7 @@ int RIOAssignRta(struct rio_info *p, struct Map *MapP)
708 */ 699 */
709 HostMapP->SysPort = MapP->SysPort; 700 HostMapP->SysPort = MapP->SysPort;
710 if ((MapP->Flags & RTA16_SECOND_SLOT) == 0) 701 if ((MapP->Flags & RTA16_SECOND_SLOT) == 0)
711 CCOPY(MapP->Name, HostMapP->Name, MAX_NAME_LEN); 702 memcpy(HostMapP->Name, MapP->Name, MAX_NAME_LEN);
712 HostMapP->Flags = SLOT_IN_USE | RTA_BOOTED; 703 HostMapP->Flags = SLOT_IN_USE | RTA_BOOTED;
713#ifdef NEED_TO_FIX 704#ifdef NEED_TO_FIX
714 RIO_SV_BROADCAST(p->RIOHosts[host].svFlags[MapP->ID - 1]); 705 RIO_SV_BROADCAST(p->RIOHosts[host].svFlags[MapP->ID - 1]);
@@ -742,16 +733,13 @@ int RIOAssignRta(struct rio_info *p, struct Map *MapP)
742} 733}
743 734
744 735
745int RIOReMapPorts(p, HostP, HostMapP) 736int RIOReMapPorts(struct rio_info *p, struct Host *HostP, struct Map *HostMapP)
746struct rio_info *p;
747struct Host *HostP;
748struct Map *HostMapP;
749{ 737{
750 register struct Port *PortP; 738 struct Port *PortP;
751 uint SubEnt; 739 unsigned int SubEnt;
752 uint HostPort; 740 unsigned int HostPort;
753 uint SysPort; 741 unsigned int SysPort;
754 ushort RtaType; 742 u16 RtaType;
755 unsigned long flags; 743 unsigned long flags;
756 744
757 rio_dprintk(RIO_DEBUG_TABLE, "Mapping sysport %d to id %d\n", (int) HostMapP->SysPort, HostMapP->ID); 745 rio_dprintk(RIO_DEBUG_TABLE, "Mapping sysport %d to id %d\n", (int) HostMapP->SysPort, HostMapP->ID);
@@ -794,12 +782,12 @@ struct Map *HostMapP;
794 */ 782 */
795 if ((HostP->Flags & RUN_STATE) == RC_RUNNING) { 783 if ((HostP->Flags & RUN_STATE) == RC_RUNNING) {
796 struct PHB *PhbP = PortP->PhbP = &HostP->PhbP[HostPort]; 784 struct PHB *PhbP = PortP->PhbP = &HostP->PhbP[HostPort];
797 PortP->TxAdd = (WORD *) RIO_PTR(HostP->Caddr, RWORD(PhbP->tx_add)); 785 PortP->TxAdd = (u16 *) RIO_PTR(HostP->Caddr, readw(&PhbP->tx_add));
798 PortP->TxStart = (WORD *) RIO_PTR(HostP->Caddr, RWORD(PhbP->tx_start)); 786 PortP->TxStart = (u16 *) RIO_PTR(HostP->Caddr, readw(&PhbP->tx_start));
799 PortP->TxEnd = (WORD *) RIO_PTR(HostP->Caddr, RWORD(PhbP->tx_end)); 787 PortP->TxEnd = (u16 *) RIO_PTR(HostP->Caddr, readw(&PhbP->tx_end));
800 PortP->RxRemove = (WORD *) RIO_PTR(HostP->Caddr, RWORD(PhbP->rx_remove)); 788 PortP->RxRemove = (u16 *) RIO_PTR(HostP->Caddr, readw(&PhbP->rx_remove));
801 PortP->RxStart = (WORD *) RIO_PTR(HostP->Caddr, RWORD(PhbP->rx_start)); 789 PortP->RxStart = (u16 *) RIO_PTR(HostP->Caddr, readw(&PhbP->rx_start));
802 PortP->RxEnd = (WORD *) RIO_PTR(HostP->Caddr, RWORD(PhbP->rx_end)); 790 PortP->RxEnd = (u16 *) RIO_PTR(HostP->Caddr, readw(&PhbP->rx_end));
803 } else 791 } else
804 PortP->PhbP = NULL; 792 PortP->PhbP = NULL;
805 793
@@ -813,10 +801,10 @@ struct Map *HostMapP;
813 PortP->RupNum = HostMapP->ID - 1; 801 PortP->RupNum = HostMapP->ID - 1;
814 if (HostMapP->Flags & RTA16_SECOND_SLOT) { 802 if (HostMapP->Flags & RTA16_SECOND_SLOT) {
815 PortP->ID2 = HostMapP->ID2 - 1; 803 PortP->ID2 = HostMapP->ID2 - 1;
816 PortP->SecondBlock = TRUE; 804 PortP->SecondBlock = 1;
817 } else { 805 } else {
818 PortP->ID2 = 0; 806 PortP->ID2 = 0;
819 PortP->SecondBlock = FALSE; 807 PortP->SecondBlock = 0;
820 } 808 }
821 PortP->RtaUniqueNum = HostMapP->RtaUniqueNum; 809 PortP->RtaUniqueNum = HostMapP->RtaUniqueNum;
822 810
@@ -866,9 +854,6 @@ struct Map *HostMapP;
866 PortP->RxDataStart = 0; 854 PortP->RxDataStart = 0;
867 PortP->Cor2Copy = 0; 855 PortP->Cor2Copy = 0;
868 PortP->Name = &HostMapP->Name[0]; 856 PortP->Name = &HostMapP->Name[0];
869#ifdef STATS
870 bzero((caddr_t) & PortP->Stat, sizeof(struct RIOStats));
871#endif
872 PortP->statsGather = 0; 857 PortP->statsGather = 0;
873 PortP->txchars = 0; 858 PortP->txchars = 0;
874 PortP->rxchars = 0; 859 PortP->rxchars = 0;
@@ -876,10 +861,10 @@ struct Map *HostMapP;
876 PortP->closes = 0; 861 PortP->closes = 0;
877 PortP->ioctls = 0; 862 PortP->ioctls = 0;
878 if (PortP->TxRingBuffer) 863 if (PortP->TxRingBuffer)
879 bzero(PortP->TxRingBuffer, p->RIOBufferSize); 864 memset(PortP->TxRingBuffer, 0, p->RIOBufferSize);
880 else if (p->RIOBufferSize) { 865 else if (p->RIOBufferSize) {
881 PortP->TxRingBuffer = sysbrk(p->RIOBufferSize); 866 PortP->TxRingBuffer = kmalloc(p->RIOBufferSize, GFP_KERNEL);
882 bzero(PortP->TxRingBuffer, p->RIOBufferSize); 867 memset(PortP->TxRingBuffer, 0, p->RIOBufferSize);
883 } 868 }
884 PortP->TxBufferOut = 0; 869 PortP->TxBufferOut = 0;
885 PortP->TxBufferIn = 0; 870 PortP->TxBufferIn = 0;
@@ -890,7 +875,7 @@ struct Map *HostMapP;
890 ** If the same, we have received the same rx pkt from the RTA 875 ** If the same, we have received the same rx pkt from the RTA
891 ** twice. Initialise to a value not equal to PHB_RX_TGL or 0. 876 ** twice. Initialise to a value not equal to PHB_RX_TGL or 0.
892 */ 877 */
893 PortP->LastRxTgl = ~(uchar) PHB_RX_TGL; 878 PortP->LastRxTgl = ~(u8) PHB_RX_TGL;
894 879
895 /* 880 /*
896 ** and mark the port as usable 881 ** and mark the port as usable
@@ -906,9 +891,7 @@ struct Map *HostMapP;
906 return 0; 891 return 0;
907} 892}
908 893
909int RIOChangeName(p, MapP) 894int RIOChangeName(struct rio_info *p, struct Map *MapP)
910struct rio_info *p;
911struct Map *MapP;
912{ 895{
913 int host; 896 int host;
914 struct Map *HostMapP; 897 struct Map *HostMapP;
@@ -941,7 +924,7 @@ struct Map *MapP;
941 return -ENXIO; 924 return -ENXIO;
942 } 925 }
943 if (MapP->ID == 0) { 926 if (MapP->ID == 0) {
944 CCOPY(MapP->Name, p->RIOHosts[host].Name, MAX_NAME_LEN); 927 memcpy(p->RIOHosts[host].Name, MapP->Name, MAX_NAME_LEN);
945 return 0; 928 return 0;
946 } 929 }
947 930
@@ -951,7 +934,7 @@ struct Map *MapP;
951 p->RIOError.Error = RTA_NUMBER_WRONG; 934 p->RIOError.Error = RTA_NUMBER_WRONG;
952 return -ENXIO; 935 return -ENXIO;
953 } 936 }
954 CCOPY(MapP->Name, HostMapP->Name, MAX_NAME_LEN); 937 memcpy(HostMapP->Name, MapP->Name, MAX_NAME_LEN);
955 return 0; 938 return 0;
956 } 939 }
957 } 940 }
diff --git a/drivers/char/rio/riotty.c b/drivers/char/rio/riotty.c
index 6379816ed1..204267613c 100644
--- a/drivers/char/rio/riotty.c
+++ b/drivers/char/rio/riotty.c
@@ -56,15 +56,12 @@ static char *_riotty_c_sccs_ = "@(#)riotty.c 1.3";
56 56
57#include "linux_compat.h" 57#include "linux_compat.h"
58#include "rio_linux.h" 58#include "rio_linux.h"
59#include "typdef.h"
60#include "pkt.h" 59#include "pkt.h"
61#include "daemon.h" 60#include "daemon.h"
62#include "rio.h" 61#include "rio.h"
63#include "riospace.h" 62#include "riospace.h"
64#include "top.h"
65#include "cmdpkt.h" 63#include "cmdpkt.h"
66#include "map.h" 64#include "map.h"
67#include "riotypes.h"
68#include "rup.h" 65#include "rup.h"
69#include "port.h" 66#include "port.h"
70#include "riodrvr.h" 67#include "riodrvr.h"
@@ -77,58 +74,18 @@ static char *_riotty_c_sccs_ = "@(#)riotty.c 1.3";
77#include "unixrup.h" 74#include "unixrup.h"
78#include "board.h" 75#include "board.h"
79#include "host.h" 76#include "host.h"
80#include "error.h"
81#include "phb.h" 77#include "phb.h"
82#include "link.h" 78#include "link.h"
83#include "cmdblk.h" 79#include "cmdblk.h"
84#include "route.h" 80#include "route.h"
85#include "control.h"
86#include "cirrus.h" 81#include "cirrus.h"
87#include "rioioctl.h" 82#include "rioioctl.h"
88#include "param.h" 83#include "param.h"
89#include "list.h"
90#include "sam.h"
91 84
92static void RIOClearUp(struct Port *PortP); 85static void RIOClearUp(struct Port *PortP);
93int RIOShortCommand(struct rio_info *p, struct Port *PortP, int command, int len, int arg);
94
95
96extern int conv_vb[]; /* now defined in ttymgr.c */
97extern int conv_bv[]; /* now defined in ttymgr.c */
98 86
99/* 87/* Below belongs in func.h */
100** 16.09.1998 ARG - Fix to build riotty.k.o for Modular Kernel Support 88int RIOShortCommand(struct rio_info *p, struct Port *PortP, int command, int len, int arg);
101**
102** ep.def.h is necessary for Modular Kernel Support
103** DO NOT place any kernel 'extern's after this line
104** or this source file will not build riotty.k.o
105*/
106#ifdef uLYNX
107#include <ep.def.h>
108#endif
109
110#ifdef NEED_THIS2
111static struct old_sgttyb default_sg = {
112 B19200, B19200, /* input and output speed */
113 'H' - '@', /* erase char */
114 -1, /* 2nd erase char */
115 'U' - '@', /* kill char */
116 ECHO | CRMOD, /* mode */
117 'C' - '@', /* interrupt character */
118 '\\' - '@', /* quit char */
119 'Q' - '@', /* start char */
120 'S' - '@', /* stop char */
121 'D' - '@', /* EOF */
122 -1, /* brk */
123 (LCRTBS | LCRTERA | LCRTKIL | LCTLECH), /* local mode word */
124 'Z' - '@', /* process stop */
125 'Y' - '@', /* delayed stop */
126 'R' - '@', /* reprint line */
127 'O' - '@', /* flush output */
128 'W' - '@', /* word erase */
129 'V' - '@' /* literal next char */
130};
131#endif
132 89
133 90
134extern struct rio_info *p; 91extern struct rio_info *p;
@@ -136,8 +93,7 @@ extern struct rio_info *p;
136 93
137int riotopen(struct tty_struct *tty, struct file *filp) 94int riotopen(struct tty_struct *tty, struct file *filp)
138{ 95{
139 register uint SysPort; 96 unsigned int SysPort;
140 int Modem;
141 int repeat_this = 250; 97 int repeat_this = 250;
142 struct Port *PortP; /* pointer to the port structure */ 98 struct Port *PortP; /* pointer to the port structure */
143 unsigned long flags; 99 unsigned long flags;
@@ -151,16 +107,14 @@ int riotopen(struct tty_struct *tty, struct file *filp)
151 tty->driver_data = NULL; 107 tty->driver_data = NULL;
152 108
153 SysPort = rio_minor(tty); 109 SysPort = rio_minor(tty);
154 Modem = rio_ismodem(tty);
155 110
156 if (p->RIOFailed) { 111 if (p->RIOFailed) {
157 rio_dprintk(RIO_DEBUG_TTY, "System initialisation failed\n"); 112 rio_dprintk(RIO_DEBUG_TTY, "System initialisation failed\n");
158 pseterr(ENXIO);
159 func_exit(); 113 func_exit();
160 return -ENXIO; 114 return -ENXIO;
161 } 115 }
162 116
163 rio_dprintk(RIO_DEBUG_TTY, "port open SysPort %d (%s) (mapped:%d)\n", SysPort, Modem ? "Modem" : "tty", p->RIOPortp[SysPort]->Mapped); 117 rio_dprintk(RIO_DEBUG_TTY, "port open SysPort %d (mapped:%d)\n", SysPort, p->RIOPortp[SysPort]->Mapped);
164 118
165 /* 119 /*
166 ** Validate that we have received a legitimate request. 120 ** Validate that we have received a legitimate request.
@@ -170,7 +124,6 @@ int riotopen(struct tty_struct *tty, struct file *filp)
170 */ 124 */
171 if (SysPort >= RIO_PORTS) { /* out of range ? */ 125 if (SysPort >= RIO_PORTS) { /* out of range ? */
172 rio_dprintk(RIO_DEBUG_TTY, "Illegal port number %d\n", SysPort); 126 rio_dprintk(RIO_DEBUG_TTY, "Illegal port number %d\n", SysPort);
173 pseterr(ENXIO);
174 func_exit(); 127 func_exit();
175 return -ENXIO; 128 return -ENXIO;
176 } 129 }
@@ -187,7 +140,6 @@ int riotopen(struct tty_struct *tty, struct file *filp)
187 */ 140 */
188 rio_dprintk(RIO_DEBUG_TTY, "port not mapped into system\n"); 141 rio_dprintk(RIO_DEBUG_TTY, "port not mapped into system\n");
189 func_exit(); 142 func_exit();
190 pseterr(ENXIO);
191 return -ENXIO; 143 return -ENXIO;
192 } 144 }
193 145
@@ -209,7 +161,6 @@ int riotopen(struct tty_struct *tty, struct file *filp)
209 */ 161 */
210 if ((PortP->HostP->Flags & RUN_STATE) != RC_RUNNING) { 162 if ((PortP->HostP->Flags & RUN_STATE) != RC_RUNNING) {
211 rio_dprintk(RIO_DEBUG_TTY, "Host not running\n"); 163 rio_dprintk(RIO_DEBUG_TTY, "Host not running\n");
212 pseterr(ENXIO);
213 func_exit(); 164 func_exit();
214 return -ENXIO; 165 return -ENXIO;
215 } 166 }
@@ -309,15 +260,12 @@ int riotopen(struct tty_struct *tty, struct file *filp)
309 /* PortP->gs.xmit_cnt = 0; */ 260 /* PortP->gs.xmit_cnt = 0; */
310 261
311 rio_spin_unlock_irqrestore(&PortP->portSem, flags); 262 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
312#ifdef NEED_THIS
313 ttyseth(PortP, tp, (struct old_sgttyb *) &default_sg);
314#endif
315 263
316 /* Someone explain to me why this delay/config is 264 /* Someone explain to me why this delay/config is
317 here. If I read the docs correctly the "open" 265 here. If I read the docs correctly the "open"
318 command piggybacks the parameters immediately. 266 command piggybacks the parameters immediately.
319 -- REW */ 267 -- REW */
320 RIOParam(PortP, OPEN, Modem, OK_TO_SLEEP); /* Open the port */ 268 RIOParam(PortP, OPEN, 1, OK_TO_SLEEP); /* Open the port */
321 rio_spin_lock_irqsave(&PortP->portSem, flags); 269 rio_spin_lock_irqsave(&PortP->portSem, flags);
322 270
323 /* 271 /*
@@ -325,20 +273,6 @@ int riotopen(struct tty_struct *tty, struct file *filp)
325 */ 273 */
326 while (!(PortP->PortState & PORT_ISOPEN) && !p->RIOHalted) { 274 while (!(PortP->PortState & PORT_ISOPEN) && !p->RIOHalted) {
327 rio_dprintk(RIO_DEBUG_TTY, "Waiting for PORT_ISOPEN-currently %x\n", PortP->PortState); 275 rio_dprintk(RIO_DEBUG_TTY, "Waiting for PORT_ISOPEN-currently %x\n", PortP->PortState);
328/*
329** 15.10.1998 ARG - ESIL 0759
330** (Part) fix for port being trashed when opened whilst RTA "disconnected"
331** Take out the limited wait - now wait for ever or until user
332** bangs us out.
333**
334 if (repeat_this -- <= 0) {
335 rio_dprint(RIO_DEBUG_TTY, ("Waiting for open to finish timed out.\n"));
336 RIOPreemptiveCmd(p, PortP, FCLOSE );
337 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
338 return -EINTR;
339 }
340**
341*/
342 rio_spin_unlock_irqrestore(&PortP->portSem, flags); 276 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
343 if (RIODelay(PortP, HUNDRED_MS) == RIO_FAIL) { 277 if (RIODelay(PortP, HUNDRED_MS) == RIO_FAIL) {
344 rio_dprintk(RIO_DEBUG_TTY, "Waiting for open to finish broken by signal\n"); 278 rio_dprintk(RIO_DEBUG_TTY, "Waiting for open to finish broken by signal\n");
@@ -358,80 +292,61 @@ int riotopen(struct tty_struct *tty, struct file *filp)
358 } 292 }
359 rio_dprintk(RIO_DEBUG_TTY, "PORT_ISOPEN found\n"); 293 rio_dprintk(RIO_DEBUG_TTY, "PORT_ISOPEN found\n");
360 } 294 }
361#ifdef MODEM_SUPPORT 295 rio_dprintk(RIO_DEBUG_TTY, "Modem - test for carrier\n");
362 if (Modem) { 296 /*
363 rio_dprintk(RIO_DEBUG_TTY, "Modem - test for carrier\n"); 297 ** ACTION
298 ** insert test for carrier here. -- ???
299 ** I already see that test here. What's the deal? -- REW
300 */
301 if ((PortP->gs.tty->termios->c_cflag & CLOCAL) || (PortP->ModemState & MSVR1_CD)) {
302 rio_dprintk(RIO_DEBUG_TTY, "open(%d) Modem carr on\n", SysPort);
364 /* 303 /*
365 ** ACTION 304 tp->tm.c_state |= CARR_ON;
366 ** insert test for carrier here. -- ??? 305 wakeup((caddr_t) &tp->tm.c_canq);
367 ** I already see that test here. What's the deal? -- REW
368 */ 306 */
369 if ((PortP->gs.tty->termios->c_cflag & CLOCAL) || (PortP->ModemState & MSVR1_CD)) { 307 PortP->State |= RIO_CARR_ON;
370 rio_dprintk(RIO_DEBUG_TTY, "open(%d) Modem carr on\n", SysPort); 308 wake_up_interruptible(&PortP->gs.open_wait);
309 } else { /* no carrier - wait for DCD */
371 /* 310 /*
372 tp->tm.c_state |= CARR_ON; 311 while (!(PortP->gs.tty->termios->c_state & CARR_ON) &&
373 wakeup((caddr_t) &tp->tm.c_canq); 312 !(filp->f_flags & O_NONBLOCK) && !p->RIOHalted )
374 */ 313 */
375 PortP->State |= RIO_CARR_ON; 314 while (!(PortP->State & RIO_CARR_ON) && !(filp->f_flags & O_NONBLOCK) && !p->RIOHalted) {
376 wake_up_interruptible(&PortP->gs.open_wait); 315 rio_dprintk(RIO_DEBUG_TTY, "open(%d) sleeping for carr on\n", SysPort);
377 } else { /* no carrier - wait for DCD */
378
379 /* 316 /*
380 while (!(PortP->gs.tty->termios->c_state & CARR_ON) && 317 PortP->gs.tty->termios->c_state |= WOPEN;
381 !(filp->f_flags & O_NONBLOCK) && !p->RIOHalted )
382 */ 318 */
383 while (!(PortP->State & RIO_CARR_ON) && !(filp->f_flags & O_NONBLOCK) && !p->RIOHalted) { 319 PortP->State |= RIO_WOPEN;
384 320 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
385 rio_dprintk(RIO_DEBUG_TTY, "open(%d) sleeping for carr on\n", SysPort); 321 if (RIODelay(PortP, HUNDRED_MS) == RIO_FAIL) {
386 /* 322 /*
387 PortP->gs.tty->termios->c_state |= WOPEN; 323 ** ACTION: verify that this is a good thing
324 ** to do here. -- ???
325 ** I think it's OK. -- REW
388 */ 326 */
389 PortP->State |= RIO_WOPEN; 327 rio_dprintk(RIO_DEBUG_TTY, "open(%d) sleeping for carr broken by signal\n", SysPort);
328 RIOPreemptiveCmd(p, PortP, FCLOSE);
329 /*
330 tp->tm.c_state &= ~WOPEN;
331 */
332 PortP->State &= ~RIO_WOPEN;
390 rio_spin_unlock_irqrestore(&PortP->portSem, flags); 333 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
391 if (RIODelay(PortP, HUNDRED_MS) == RIO_FAIL) 334 func_exit();
392 { 335 return -EINTR;
393 /*
394 ** ACTION: verify that this is a good thing
395 ** to do here. -- ???
396 ** I think it's OK. -- REW
397 */
398 rio_dprintk(RIO_DEBUG_TTY, "open(%d) sleeping for carr broken by signal\n", SysPort);
399 RIOPreemptiveCmd(p, PortP, FCLOSE);
400 /*
401 tp->tm.c_state &= ~WOPEN;
402 */
403 PortP->State &= ~RIO_WOPEN;
404 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
405 func_exit();
406 return -EINTR;
407 }
408 } 336 }
409 PortP->State &= ~RIO_WOPEN;
410 } 337 }
411 if (p->RIOHalted) 338 PortP->State &= ~RIO_WOPEN;
412 goto bombout;
413 rio_dprintk(RIO_DEBUG_TTY, "Setting RIO_MOPEN\n");
414 PortP->State |= RIO_MOPEN;
415 } else
416#endif
417 {
418 /*
419 ** ACTION
420 ** Direct line open - force carrier (will probably mean
421 ** that sleeping Modem line fubar)
422 */
423 PortP->State |= RIO_LOPEN;
424 } 339 }
340 if (p->RIOHalted)
341 goto bombout;
342 rio_dprintk(RIO_DEBUG_TTY, "Setting RIO_MOPEN\n");
343 PortP->State |= RIO_MOPEN;
425 344
426 if (p->RIOHalted) { 345 if (p->RIOHalted)
427 goto bombout; 346 goto bombout;
428 }
429 347
430 rio_dprintk(RIO_DEBUG_TTY, "high level open done\n"); 348 rio_dprintk(RIO_DEBUG_TTY, "high level open done\n");
431 349
432#ifdef STATS
433 PortP->Stat.OpenCnt++;
434#endif
435 /* 350 /*
436 ** Count opens for port statistics reporting 351 ** Count opens for port statistics reporting
437 */ 352 */
@@ -460,23 +375,21 @@ int riotclose(void *ptr)
460 unsigned long end_time; 375 unsigned long end_time;
461 struct tty_struct *tty; 376 struct tty_struct *tty;
462 unsigned long flags; 377 unsigned long flags;
463 int Modem;
464 int rv = 0; 378 int rv = 0;
465 379
466 rio_dprintk(RIO_DEBUG_TTY, "port close SysPort %d\n", PortP->PortNum); 380 rio_dprintk(RIO_DEBUG_TTY, "port close SysPort %d\n", PortP->PortNum);
467 381
468 /* PortP = p->RIOPortp[SysPort]; */ 382 /* PortP = p->RIOPortp[SysPort]; */
469 rio_dprintk(RIO_DEBUG_TTY, "Port is at address 0x%x\n", (int) PortP); 383 rio_dprintk(RIO_DEBUG_TTY, "Port is at address %p\n", PortP);
470 /* tp = PortP->TtyP; *//* Get tty */ 384 /* tp = PortP->TtyP; *//* Get tty */
471 tty = PortP->gs.tty; 385 tty = PortP->gs.tty;
472 rio_dprintk(RIO_DEBUG_TTY, "TTY is at address 0x%x\n", (int) tty); 386 rio_dprintk(RIO_DEBUG_TTY, "TTY is at address %p\n", tty);
473 387
474 if (PortP->gs.closing_wait) 388 if (PortP->gs.closing_wait)
475 end_time = jiffies + PortP->gs.closing_wait; 389 end_time = jiffies + PortP->gs.closing_wait;
476 else 390 else
477 end_time = jiffies + MAX_SCHEDULE_TIMEOUT; 391 end_time = jiffies + MAX_SCHEDULE_TIMEOUT;
478 392
479 Modem = rio_ismodem(tty);
480 rio_spin_lock_irqsave(&PortP->portSem, flags); 393 rio_spin_lock_irqsave(&PortP->portSem, flags);
481 394
482 /* 395 /*
@@ -500,7 +413,7 @@ int riotclose(void *ptr)
500 /* 413 /*
501 ** clear the open bits for this device 414 ** clear the open bits for this device
502 */ 415 */
503 PortP->State &= (Modem ? ~RIO_MOPEN : ~RIO_LOPEN); 416 PortP->State &= ~RIO_MOPEN;
504 PortP->State &= ~RIO_CARR_ON; 417 PortP->State &= ~RIO_CARR_ON;
505 PortP->ModemState &= ~MSVR1_CD; 418 PortP->ModemState &= ~MSVR1_CD;
506 /* 419 /*
@@ -536,7 +449,6 @@ int riotclose(void *ptr)
536 449
537 if (!deleted) 450 if (!deleted)
538 while ((PortP->InUse != NOT_INUSE) && !p->RIOHalted && (PortP->TxBufferIn != PortP->TxBufferOut)) { 451 while ((PortP->InUse != NOT_INUSE) && !p->RIOHalted && (PortP->TxBufferIn != PortP->TxBufferOut)) {
539 cprintf("Need to flush the ttyport\n");
540 if (repeat_this-- <= 0) { 452 if (repeat_this-- <= 0) {
541 rv = -EINTR; 453 rv = -EINTR;
542 rio_dprintk(RIO_DEBUG_TTY, "Waiting for not idle closed broken by signal\n"); 454 rio_dprintk(RIO_DEBUG_TTY, "Waiting for not idle closed broken by signal\n");
@@ -615,16 +527,13 @@ int riotclose(void *ptr)
615*/ 527*/
616 PortP->Config &= ~(RIO_CTSFLOW | RIO_RTSFLOW); 528 PortP->Config &= ~(RIO_CTSFLOW | RIO_RTSFLOW);
617 529
618#ifdef STATS
619 PortP->Stat.CloseCnt++;
620#endif
621 /* 530 /*
622 ** Count opens for port statistics reporting 531 ** Count opens for port statistics reporting
623 */ 532 */
624 if (PortP->statsGather) 533 if (PortP->statsGather)
625 PortP->closes++; 534 PortP->closes++;
626 535
627 close_end: 536close_end:
628 /* XXX: Why would a "DELETED" flag be reset here? I'd have 537 /* XXX: Why would a "DELETED" flag be reset here? I'd have
629 thought that a "deleted" flag means that the port was 538 thought that a "deleted" flag means that the port was
630 permanently gone, but here we can make it reappear by it 539 permanently gone, but here we can make it reappear by it
@@ -640,8 +549,7 @@ int riotclose(void *ptr)
640 549
641 550
642 551
643static void RIOClearUp(PortP) 552static void RIOClearUp(struct Port *PortP)
644struct Port *PortP;
645{ 553{
646 rio_dprintk(RIO_DEBUG_TTY, "RIOHalted set\n"); 554 rio_dprintk(RIO_DEBUG_TTY, "RIOHalted set\n");
647 PortP->Config = 0; /* Direct semaphore */ 555 PortP->Config = 0; /* Direct semaphore */
@@ -668,7 +576,7 @@ struct Port *PortP;
668*/ 576*/
669int RIOShortCommand(struct rio_info *p, struct Port *PortP, int command, int len, int arg) 577int RIOShortCommand(struct rio_info *p, struct Port *PortP, int command, int len, int arg)
670{ 578{
671 PKT *PacketP; 579 struct PKT *PacketP;
672 int retries = 20; /* at 10 per second -> 2 seconds */ 580 int retries = 20; /* at 10 per second -> 2 seconds */
673 unsigned long flags; 581 unsigned long flags;
674 582
@@ -722,15 +630,15 @@ int RIOShortCommand(struct rio_info *p, struct Port *PortP, int command, int len
722 /* 630 /*
723 ** set the command byte and the argument byte 631 ** set the command byte and the argument byte
724 */ 632 */
725 WBYTE(PacketP->data[0], command); 633 writeb(command, &PacketP->data[0]);
726 634
727 if (len == 2) 635 if (len == 2)
728 WBYTE(PacketP->data[1], arg); 636 writeb(arg, &PacketP->data[1]);
729 637
730 /* 638 /*
731 ** set the length of the packet and set the command bit. 639 ** set the length of the packet and set the command bit.
732 */ 640 */
733 WBYTE(PacketP->len, PKT_CMD_BIT | len); 641 writeb(PKT_CMD_BIT | len, &PacketP->len);
734 642
735 add_transmit(PortP); 643 add_transmit(PortP);
736 /* 644 /*
diff --git a/drivers/char/rio/riotypes.h b/drivers/char/rio/riotypes.h
deleted file mode 100644
index 46084d5c7e..0000000000
--- a/drivers/char/rio/riotypes.h
+++ /dev/null
@@ -1,68 +0,0 @@
1/****************************************************************************
2 ******* *******
3 ******* R I O T Y P E S
4 ******* *******
5 ****************************************************************************
6
7 Author : Jon Brawn
8 Date :
9
10 *
11 * (C) 1990 - 2000 Specialix International Ltd., Byfleet, Surrey, UK.
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
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 Version : 0.01
28
29
30 Mods
31 ----------------------------------------------------------------------------
32 Date By Description
33 ----------------------------------------------------------------------------
34
35 ***************************************************************************/
36
37#ifndef _riotypes_h
38#define _riotypes_h 1
39
40#ifdef SCCS_LABELS
41#ifndef lint
42/* static char *_rio_riotypes_h_sccs = "@(#)riotypes.h 1.10"; */
43#endif
44#endif
45
46typedef unsigned short NUMBER_ptr;
47typedef unsigned short WORD_ptr;
48typedef unsigned short BYTE_ptr;
49typedef unsigned short char_ptr;
50typedef unsigned short Channel_ptr;
51typedef unsigned short FREE_LIST_ptr_ptr;
52typedef unsigned short FREE_LIST_ptr;
53typedef unsigned short LPB_ptr;
54typedef unsigned short Process_ptr;
55typedef unsigned short PHB_ptr;
56typedef unsigned short PKT_ptr;
57typedef unsigned short PKT_ptr_ptr;
58typedef unsigned short Q_BUF_ptr;
59typedef unsigned short Q_BUF_ptr_ptr;
60typedef unsigned short ROUTE_STR_ptr;
61typedef unsigned short RUP_ptr;
62typedef unsigned short short_ptr;
63typedef unsigned short u_short_ptr;
64typedef unsigned short ushort_ptr;
65
66#endif /* __riotypes__ */
67
68/*********** end of file ***********/
diff --git a/drivers/char/rio/rom.h b/drivers/char/rio/rom.h
deleted file mode 100644
index 58a7843625..0000000000
--- a/drivers/char/rio/rom.h
+++ /dev/null
@@ -1,62 +0,0 @@
1/****************************************************************************
2 ******* *******
3 ******* R O M
4 ******* *******
5 ****************************************************************************
6
7 Author : Ian Nandhra
8 Date :
9
10 *
11 * (C) 1990 - 2000 Specialix International Ltd., Byfleet, Surrey, UK.
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
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 Version : 0.01
28
29
30 Mods
31 ----------------------------------------------------------------------------
32 Date By Description
33 ----------------------------------------------------------------------------
34
35 ***************************************************************************/
36
37#ifndef _rom_h
38#define _rom_h 1
39
40#ifndef lint
41#ifdef SCCS
42static char *_rio_rom_h_sccs = "@(#)rom.h 1.1";
43#endif
44#endif
45
46typedef struct ROM ROM;
47struct ROM {
48 u_short slx;
49 char pcb_letter_rev;
50 char pcb_number_rev;
51 char serial[4];
52 char year;
53 char week;
54};
55
56#endif
57
58#define HOST_ROM (ROM *) 0x7c00
59#define RTA_ROM (ROM *) 0x7801
60#define ROM_LENGTH 0x20
61
62/*********** end of file ***********/
diff --git a/drivers/char/rio/rup.h b/drivers/char/rio/rup.h
index f74f67c6f7..4ae90cb207 100644
--- a/drivers/char/rio/rup.h
+++ b/drivers/char/rio/rup.h
@@ -37,14 +37,7 @@
37#ifndef _rup_h 37#ifndef _rup_h
38#define _rup_h 1 38#define _rup_h 1
39 39
40#ifdef SCCS_LABELS
41#ifndef lint
42/* static char *_rio_rup_h_sccs = "@(#)rup.h 1.5"; */
43#endif
44#endif
45
46#define MAX_RUP ((short) 16) 40#define MAX_RUP ((short) 16)
47
48#define PKTS_PER_RUP ((short) 2) /* They are always used in pairs */ 41#define PKTS_PER_RUP ((short) 2) /* They are always used in pairs */
49 42
50/************************************************* 43/*************************************************
@@ -60,15 +53,15 @@
60#define RUP_NO_OWNER 0xff /* RUP not owned by any process */ 53#define RUP_NO_OWNER 0xff /* RUP not owned by any process */
61 54
62struct RUP { 55struct RUP {
63 PKT_ptr txpkt; /* Outgoing packet */ 56 u16 txpkt; /* Outgoing packet */
64 PKT_ptr rxpkt; /* Incoming packet */ 57 u16 rxpkt; /* Incoming packet */
65 WORD link; /* Which link to send down? */ 58 u16 link; /* Which link to send down? */
66 BYTE rup_dest_unit[2]; /* Destination unit */ 59 u8 rup_dest_unit[2]; /* Destination unit */
67 WORD handshake; /* For handshaking */ 60 u16 handshake; /* For handshaking */
68 WORD timeout; /* Timeout */ 61 u16 timeout; /* Timeout */
69 WORD status; /* Status */ 62 u16 status; /* Status */
70 WORD txcontrol; /* Transmit control */ 63 u16 txcontrol; /* Transmit control */
71 WORD rxcontrol; /* Receive control */ 64 u16 rxcontrol; /* Receive control */
72}; 65};
73 66
74#endif 67#endif
diff --git a/drivers/char/rio/sam.h b/drivers/char/rio/sam.h
deleted file mode 100644
index 6f754e1901..0000000000
--- a/drivers/char/rio/sam.h
+++ /dev/null
@@ -1,67 +0,0 @@
1/****************************************************************************
2 ******* *******
3 ******* S A M . H
4 ******* *******
5 ****************************************************************************
6
7 Author : Ian Nandhra
8 Date :
9
10 *
11 * (C) 1990 - 2000 Specialix International Ltd., Byfleet, Surrey, UK.
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
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 Version : 0.01
28
29
30 Mods
31 ----------------------------------------------------------------------------
32 Date By Description
33 ----------------------------------------------------------------------------
34
35 ***************************************************************************/
36#ifndef _sam_h
37#define _sam_h 1
38
39#ifdef SCCS_LABELS
40#ifndef lint
41/* static char *_rio_sam_h_sccs = "@(#)sam.h 1.3"; */
42#endif
43#endif
44
45
46#define NUM_FREE_LIST_UNITS 500
47
48#ifndef FALSE
49#define FALSE (short) 0x00
50#endif
51#ifndef TRUE
52#define TRUE (short) !FALSE
53#endif
54
55#define TX TRUE
56#define RX FALSE
57
58
59typedef struct FREE_LIST FREE_LIST;
60struct FREE_LIST {
61 FREE_LIST_ptr next;
62 FREE_LIST_ptr prev;
63};
64
65
66#endif
67/*********** end of file ***********/
diff --git a/drivers/char/rio/space.h b/drivers/char/rio/space.h
deleted file mode 100644
index 1f12690f9d..0000000000
--- a/drivers/char/rio/space.h
+++ /dev/null
@@ -1,45 +0,0 @@
1/*
2** -----------------------------------------------------------------------------
3**
4** Perle Specialix driver for Linux
5** Ported from existing RIO Driver for SCO sources.
6 *
7 * (C) 1990 - 2000 Specialix International Ltd., Byfleet, Surrey, UK.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22**
23** Module : space.h
24** SID : 1.2
25** Last Modified : 11/6/98 11:34:19
26** Retrieved : 11/6/98 11:34:22
27**
28** ident @(#)space.h 1.2
29**
30** -----------------------------------------------------------------------------
31*/
32
33#ifndef __rio_space_h__
34#define __rio_space_h__
35
36#ifdef SCCS_LABELS
37static char *_space_h_sccs_ = "@(#)space.h 1.2";
38#endif
39
40extern int rio_cntls;
41extern int rio_bases[];
42extern int rio_limits[];
43extern int rio_vects[];
44
45#endif /* __rio_space_h__ */
diff --git a/drivers/char/rio/top.h b/drivers/char/rio/top.h
deleted file mode 100644
index d15a11dc4f..0000000000
--- a/drivers/char/rio/top.h
+++ /dev/null
@@ -1,48 +0,0 @@
1/*
2** -----------------------------------------------------------------------------
3**
4** Perle Specialix driver for Linux
5** Ported from existing RIO Driver for SCO sources.
6 *
7 * (C) 1990 - 2000 Specialix International Ltd., Byfleet, Surrey, UK.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22**
23** Module : top.h
24** SID : 1.2
25** Last Modified : 11/6/98 11:34:19
26** Retrieved : 11/6/98 11:34:22
27**
28** ident @(#)top.h 1.2
29**
30** -----------------------------------------------------------------------------
31*/
32
33#ifndef __rio_top_h__
34#define __rio_top_h__
35
36#ifdef SCCS_LABELS
37static char *_top_h_sccs_ = "@(#)top.h 1.2";
38#endif
39
40/*
41** Topology information
42*/
43struct Top {
44 uchar Unit;
45 uchar Link;
46};
47
48#endif /* __rio_top_h__ */
diff --git a/drivers/char/rio/typdef.h b/drivers/char/rio/typdef.h
deleted file mode 100644
index 185b889e15..0000000000
--- a/drivers/char/rio/typdef.h
+++ /dev/null
@@ -1,82 +0,0 @@
1/*
2** -----------------------------------------------------------------------------
3**
4** Perle Specialix driver for Linux
5** Ported from existing RIO Driver for SCO sources.
6 *
7 * (C) 1990 - 2000 Specialix International Ltd., Byfleet, Surrey, UK.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22**
23** Module : typdef.h
24** SID : 1.2
25** Last Modified : 11/6/98 11:34:20
26** Retrieved : 11/6/98 11:34:22
27**
28** ident @(#)typdef.h 1.2
29**
30** -----------------------------------------------------------------------------
31*/
32
33#ifndef __rio_typdef_h__
34#define __rio_typdef_h__
35
36#ifdef SCCS_LABELS
37static char *_typdef_h_sccs_ = "@(#)typdef.h 1.2";
38#endif
39
40#undef VPIX
41
42/*
43** IT IS REALLY, REALLY, IMPORTANT THAT BYTES ARE UNSIGNED!
44**
45** These types are ONLY to be used for refering to data structures
46** on the RIO Host card!
47*/
48typedef volatile unsigned char BYTE;
49typedef volatile unsigned short WORD;
50typedef volatile unsigned int DWORD;
51typedef volatile unsigned short RIOP;
52typedef volatile short NUMBER;
53
54
55/*
56** 27.01.199 ARG - mods to compile 'newutils' on LyxnOS -
57** These #defines are for the benefit of the 'libfuncs' library
58** only. They are not necessarily correct type mappings and
59** are here only to make the source compile.
60*/
61/* typedef unsigned int uint; */
62typedef unsigned long ulong_t;
63typedef unsigned short ushort_t;
64typedef unsigned char uchar_t;
65typedef unsigned char queue_t;
66typedef unsigned char mblk_t;
67typedef unsigned int paddr_t;
68typedef unsigned char uchar;
69
70#define TPNULL ((ushort)(0x8000))
71
72
73/*
74** RIO structures defined in other include files.
75*/
76typedef struct PKT PKT;
77typedef struct LPB LPB;
78typedef struct RUP RUP;
79typedef struct Port Port;
80typedef struct DpRam DpRam;
81
82#endif /* __rio_typdef_h__ */
diff --git a/drivers/char/rio/unixrup.h b/drivers/char/rio/unixrup.h
index a126c7caba..4306e01dbf 100644
--- a/drivers/char/rio/unixrup.h
+++ b/drivers/char/rio/unixrup.h
@@ -45,9 +45,9 @@ struct UnixRup {
45 struct CmdBlk *CmdsWaitingP; /* Commands waiting to be done */ 45 struct CmdBlk *CmdsWaitingP; /* Commands waiting to be done */
46 struct CmdBlk *CmdPendingP; /* The command currently being sent */ 46 struct CmdBlk *CmdPendingP; /* The command currently being sent */
47 struct RUP *RupP; /* the Rup to send it to */ 47 struct RUP *RupP; /* the Rup to send it to */
48 uint Id; /* Id number */ 48 unsigned int Id; /* Id number */
49 uint BaseSysPort; /* SysPort of first tty on this RTA */ 49 unsigned int BaseSysPort; /* SysPort of first tty on this RTA */
50 uint ModTypes; /* Modules on this RTA */ 50 unsigned int ModTypes; /* Modules on this RTA */
51 spinlock_t RupLock; /* Lock structure for MPX */ 51 spinlock_t RupLock; /* Lock structure for MPX */
52 /* struct lockb RupLock; *//* Lock structure for MPX */ 52 /* struct lockb RupLock; *//* Lock structure for MPX */
53}; 53};
diff --git a/drivers/char/ser_a2232.c b/drivers/char/ser_a2232.c
index fee68cc895..510bd3e0e8 100644
--- a/drivers/char/ser_a2232.c
+++ b/drivers/char/ser_a2232.c
@@ -97,7 +97,7 @@
97#include <asm/amigahw.h> 97#include <asm/amigahw.h>
98#include <linux/zorro.h> 98#include <linux/zorro.h>
99#include <asm/irq.h> 99#include <asm/irq.h>
100#include <asm/semaphore.h> 100#include <linux/mutex.h>
101 101
102#include <linux/delay.h> 102#include <linux/delay.h>
103 103
@@ -654,7 +654,7 @@ static void a2232_init_portstructs(void)
654 port->gs.closing_wait = 30 * HZ; 654 port->gs.closing_wait = 30 * HZ;
655 port->gs.rd = &a2232_real_driver; 655 port->gs.rd = &a2232_real_driver;
656#ifdef NEW_WRITE_LOCKING 656#ifdef NEW_WRITE_LOCKING
657 init_MUTEX(&(port->gs.port_write_sem)); 657 init_MUTEX(&(port->gs.port_write_mutex));
658#endif 658#endif
659 init_waitqueue_head(&port->gs.open_wait); 659 init_waitqueue_head(&port->gs.open_wait);
660 init_waitqueue_head(&port->gs.close_wait); 660 init_waitqueue_head(&port->gs.close_wait);
diff --git a/drivers/char/snsc.c b/drivers/char/snsc.c
index 0e7d216e7e..b543821d8c 100644
--- a/drivers/char/snsc.c
+++ b/drivers/char/snsc.c
@@ -5,7 +5,7 @@
5 * License. See the file "COPYING" in the main directory of this archive 5 * License. See the file "COPYING" in the main directory of this archive
6 * for more details. 6 * for more details.
7 * 7 *
8 * Copyright (C) 2004 Silicon Graphics, Inc. All rights reserved. 8 * Copyright (C) 2004, 2006 Silicon Graphics, Inc. All rights reserved.
9 */ 9 */
10 10
11/* 11/*
@@ -77,7 +77,7 @@ scdrv_open(struct inode *inode, struct file *file)
77 scd = container_of(inode->i_cdev, struct sysctl_data_s, scd_cdev); 77 scd = container_of(inode->i_cdev, struct sysctl_data_s, scd_cdev);
78 78
79 /* allocate memory for subchannel data */ 79 /* allocate memory for subchannel data */
80 sd = kmalloc(sizeof (struct subch_data_s), GFP_KERNEL); 80 sd = kzalloc(sizeof (struct subch_data_s), GFP_KERNEL);
81 if (sd == NULL) { 81 if (sd == NULL) {
82 printk("%s: couldn't allocate subchannel data\n", 82 printk("%s: couldn't allocate subchannel data\n",
83 __FUNCTION__); 83 __FUNCTION__);
@@ -85,7 +85,6 @@ scdrv_open(struct inode *inode, struct file *file)
85 } 85 }
86 86
87 /* initialize subch_data_s fields */ 87 /* initialize subch_data_s fields */
88 memset(sd, 0, sizeof (struct subch_data_s));
89 sd->sd_nasid = scd->scd_nasid; 88 sd->sd_nasid = scd->scd_nasid;
90 sd->sd_subch = ia64_sn_irtr_open(scd->scd_nasid); 89 sd->sd_subch = ia64_sn_irtr_open(scd->scd_nasid);
91 90
@@ -394,7 +393,7 @@ scdrv_init(void)
394 sprintf(devnamep, "#%d", geo_slab(geoid)); 393 sprintf(devnamep, "#%d", geo_slab(geoid));
395 394
396 /* allocate sysctl device data */ 395 /* allocate sysctl device data */
397 scd = kmalloc(sizeof (struct sysctl_data_s), 396 scd = kzalloc(sizeof (struct sysctl_data_s),
398 GFP_KERNEL); 397 GFP_KERNEL);
399 if (!scd) { 398 if (!scd) {
400 printk("%s: failed to allocate device info" 399 printk("%s: failed to allocate device info"
@@ -402,7 +401,6 @@ scdrv_init(void)
402 SYSCTL_BASENAME, devname); 401 SYSCTL_BASENAME, devname);
403 continue; 402 continue;
404 } 403 }
405 memset(scd, 0, sizeof (struct sysctl_data_s));
406 404
407 /* initialize sysctl device data fields */ 405 /* initialize sysctl device data fields */
408 scd->scd_nasid = cnodeid_to_nasid(cnode); 406 scd->scd_nasid = cnodeid_to_nasid(cnode);
diff --git a/drivers/char/snsc_event.c b/drivers/char/snsc_event.c
index a4fa507eed..e234d50e14 100644
--- a/drivers/char/snsc_event.c
+++ b/drivers/char/snsc_event.c
@@ -287,7 +287,7 @@ scdrv_event_init(struct sysctl_data_s *scd)
287{ 287{
288 int rv; 288 int rv;
289 289
290 event_sd = kmalloc(sizeof (struct subch_data_s), GFP_KERNEL); 290 event_sd = kzalloc(sizeof (struct subch_data_s), GFP_KERNEL);
291 if (event_sd == NULL) { 291 if (event_sd == NULL) {
292 printk(KERN_WARNING "%s: couldn't allocate subchannel info" 292 printk(KERN_WARNING "%s: couldn't allocate subchannel info"
293 " for event monitoring\n", __FUNCTION__); 293 " for event monitoring\n", __FUNCTION__);
@@ -295,7 +295,6 @@ scdrv_event_init(struct sysctl_data_s *scd)
295 } 295 }
296 296
297 /* initialize subch_data_s fields */ 297 /* initialize subch_data_s fields */
298 memset(event_sd, 0, sizeof (struct subch_data_s));
299 event_sd->sd_nasid = scd->scd_nasid; 298 event_sd->sd_nasid = scd->scd_nasid;
300 spin_lock_init(&event_sd->sd_rlock); 299 spin_lock_init(&event_sd->sd_rlock);
301 300
@@ -321,5 +320,3 @@ scdrv_event_init(struct sysctl_data_s *scd)
321 return; 320 return;
322 } 321 }
323} 322}
324
325
diff --git a/drivers/char/stallion.c b/drivers/char/stallion.c
index bdaab69921..3f5d6077f3 100644
--- a/drivers/char/stallion.c
+++ b/drivers/char/stallion.c
@@ -148,7 +148,6 @@ static struct tty_driver *stl_serial;
148 * is already swapping a shared buffer won't make things any worse. 148 * is already swapping a shared buffer won't make things any worse.
149 */ 149 */
150static char *stl_tmpwritebuf; 150static char *stl_tmpwritebuf;
151static DECLARE_MUTEX(stl_tmpwritesem);
152 151
153/* 152/*
154 * Define a local default termios struct. All ports will be created 153 * Define a local default termios struct. All ports will be created
diff --git a/drivers/char/sx.c b/drivers/char/sx.c
index a6b4f02bdc..3b47472302 100644
--- a/drivers/char/sx.c
+++ b/drivers/char/sx.c
@@ -2318,7 +2318,7 @@ static int sx_init_portstructs (int nboards, int nports)
2318 port->board = board; 2318 port->board = board;
2319 port->gs.rd = &sx_real_driver; 2319 port->gs.rd = &sx_real_driver;
2320#ifdef NEW_WRITE_LOCKING 2320#ifdef NEW_WRITE_LOCKING
2321 port->gs.port_write_sem = MUTEX; 2321 port->gs.port_write_mutex = MUTEX;
2322#endif 2322#endif
2323 port->gs.driver_lock = SPIN_LOCK_UNLOCKED; 2323 port->gs.driver_lock = SPIN_LOCK_UNLOCKED;
2324 /* 2324 /*
diff --git a/drivers/char/synclink.c b/drivers/char/synclink.c
index ede688a4e1..d68be61f0a 100644
--- a/drivers/char/synclink.c
+++ b/drivers/char/synclink.c
@@ -7770,7 +7770,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
7770 } 7770 }
7771 7771
7772 info->params.encoding = new_encoding; 7772 info->params.encoding = new_encoding;
7773 info->params.crc_type = new_crctype;; 7773 info->params.crc_type = new_crctype;
7774 7774
7775 /* if network interface up, reprogram hardware */ 7775 /* if network interface up, reprogram hardware */
7776 if (info->netcount) 7776 if (info->netcount)
diff --git a/drivers/char/synclink_gt.c b/drivers/char/synclink_gt.c
index b046390cd2..738ec2f4e5 100644
--- a/drivers/char/synclink_gt.c
+++ b/drivers/char/synclink_gt.c
@@ -1365,7 +1365,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
1365 } 1365 }
1366 1366
1367 info->params.encoding = new_encoding; 1367 info->params.encoding = new_encoding;
1368 info->params.crc_type = new_crctype;; 1368 info->params.crc_type = new_crctype;
1369 1369
1370 /* if network interface up, reprogram hardware */ 1370 /* if network interface up, reprogram hardware */
1371 if (info->netcount) 1371 if (info->netcount)
diff --git a/drivers/char/synclinkmp.c b/drivers/char/synclinkmp.c
index 960adb256f..8587401311 100644
--- a/drivers/char/synclinkmp.c
+++ b/drivers/char/synclinkmp.c
@@ -1650,7 +1650,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
1650 } 1650 }
1651 1651
1652 info->params.encoding = new_encoding; 1652 info->params.encoding = new_encoding;
1653 info->params.crc_type = new_crctype;; 1653 info->params.crc_type = new_crctype;
1654 1654
1655 /* if network interface up, reprogram hardware */ 1655 /* if network interface up, reprogram hardware */
1656 if (info->netcount) 1656 if (info->netcount)
diff --git a/drivers/char/toshiba.c b/drivers/char/toshiba.c
index 0c6f521abd..e2fb234dee 100644
--- a/drivers/char/toshiba.c
+++ b/drivers/char/toshiba.c
@@ -355,14 +355,14 @@ static void tosh_set_fn_port(void)
355/* 355/*
356 * Get the machine identification number of the current model 356 * Get the machine identification number of the current model
357 */ 357 */
358static int tosh_get_machine_id(void) 358static int tosh_get_machine_id(void __iomem *bios)
359{ 359{
360 int id; 360 int id;
361 SMMRegisters regs; 361 SMMRegisters regs;
362 unsigned short bx,cx; 362 unsigned short bx,cx;
363 unsigned long address; 363 unsigned long address;
364 364
365 id = (0x100*(int) isa_readb(0xffffe))+((int) isa_readb(0xffffa)); 365 id = (0x100*(int) readb(bios+0xfffe))+((int) readb(bios+0xfffa));
366 366
367 /* do we have a SCTTable machine identication number on our hands */ 367 /* do we have a SCTTable machine identication number on our hands */
368 368
@@ -388,12 +388,12 @@ static int tosh_get_machine_id(void)
388 388
389 /* now twiddle with our pointer a bit */ 389 /* now twiddle with our pointer a bit */
390 390
391 address = 0x000f0000+bx; 391 address = bx;
392 cx = isa_readw(address); 392 cx = readw(bios + address);
393 address = 0x000f0009+bx+cx; 393 address = 9+bx+cx;
394 cx = isa_readw(address); 394 cx = readw(bios + address);
395 address = 0x000f000a+cx; 395 address = 0xa+cx;
396 cx = isa_readw(address); 396 cx = readw(bios + address);
397 397
398 /* now construct our machine identification number */ 398 /* now construct our machine identification number */
399 399
@@ -416,13 +416,18 @@ static int tosh_probe(void)
416 int i,major,minor,day,year,month,flag; 416 int i,major,minor,day,year,month,flag;
417 unsigned char signature[7] = { 0x54,0x4f,0x53,0x48,0x49,0x42,0x41 }; 417 unsigned char signature[7] = { 0x54,0x4f,0x53,0x48,0x49,0x42,0x41 };
418 SMMRegisters regs; 418 SMMRegisters regs;
419 void __iomem *bios = ioremap(0xf0000, 0x10000);
420
421 if (!bios)
422 return -ENOMEM;
419 423
420 /* extra sanity check for the string "TOSHIBA" in the BIOS because 424 /* extra sanity check for the string "TOSHIBA" in the BIOS because
421 some machines that are not Toshiba's pass the next test */ 425 some machines that are not Toshiba's pass the next test */
422 426
423 for (i=0;i<7;i++) { 427 for (i=0;i<7;i++) {
424 if (isa_readb(0xfe010+i)!=signature[i]) { 428 if (readb(bios+0xe010+i)!=signature[i]) {
425 printk("toshiba: not a supported Toshiba laptop\n"); 429 printk("toshiba: not a supported Toshiba laptop\n");
430 iounmap(bios);
426 return -ENODEV; 431 return -ENODEV;
427 } 432 }
428 } 433 }
@@ -438,6 +443,7 @@ static int tosh_probe(void)
438 443
439 if ((flag==1) || ((regs.eax & 0xff00)==0x8600)) { 444 if ((flag==1) || ((regs.eax & 0xff00)==0x8600)) {
440 printk("toshiba: not a supported Toshiba laptop\n"); 445 printk("toshiba: not a supported Toshiba laptop\n");
446 iounmap(bios);
441 return -ENODEV; 447 return -ENODEV;
442 } 448 }
443 449
@@ -447,19 +453,19 @@ static int tosh_probe(void)
447 453
448 /* next get the machine ID of the current laptop */ 454 /* next get the machine ID of the current laptop */
449 455
450 tosh_id = tosh_get_machine_id(); 456 tosh_id = tosh_get_machine_id(bios);
451 457
452 /* get the BIOS version */ 458 /* get the BIOS version */
453 459
454 major = isa_readb(0xfe009)-'0'; 460 major = readb(bios+0xe009)-'0';
455 minor = ((isa_readb(0xfe00b)-'0')*10)+(isa_readb(0xfe00c)-'0'); 461 minor = ((readb(bios+0xe00b)-'0')*10)+(readb(bios+0xe00c)-'0');
456 tosh_bios = (major*0x100)+minor; 462 tosh_bios = (major*0x100)+minor;
457 463
458 /* get the BIOS date */ 464 /* get the BIOS date */
459 465
460 day = ((isa_readb(0xffff5)-'0')*10)+(isa_readb(0xffff6)-'0'); 466 day = ((readb(bios+0xfff5)-'0')*10)+(readb(bios+0xfff6)-'0');
461 month = ((isa_readb(0xffff8)-'0')*10)+(isa_readb(0xffff9)-'0'); 467 month = ((readb(bios+0xfff8)-'0')*10)+(readb(bios+0xfff9)-'0');
462 year = ((isa_readb(0xffffb)-'0')*10)+(isa_readb(0xffffc)-'0'); 468 year = ((readb(bios+0xfffb)-'0')*10)+(readb(bios+0xfffc)-'0');
463 tosh_date = (((year-90) & 0x1f)<<10) | ((month & 0xf)<<6) 469 tosh_date = (((year-90) & 0x1f)<<10) | ((month & 0xf)<<6)
464 | ((day & 0x1f)<<1); 470 | ((day & 0x1f)<<1);
465 471
@@ -476,6 +482,8 @@ static int tosh_probe(void)
476 if ((tosh_id==0xfccb) || (tosh_id==0xfccc)) 482 if ((tosh_id==0xfccb) || (tosh_id==0xfccc))
477 tosh_fan = 1; 483 tosh_fan = 1;
478 484
485 iounmap(bios);
486
479 return 0; 487 return 0;
480} 488}
481 489
diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c
index 53d3d06655..76592ee1fb 100644
--- a/drivers/char/tty_io.c
+++ b/drivers/char/tty_io.c
@@ -130,7 +130,7 @@ LIST_HEAD(tty_drivers); /* linked list of tty drivers */
130 130
131/* Semaphore to protect creating and releasing a tty. This is shared with 131/* Semaphore to protect creating and releasing a tty. This is shared with
132 vt.c for deeply disgusting hack reasons */ 132 vt.c for deeply disgusting hack reasons */
133DECLARE_MUTEX(tty_sem); 133DEFINE_MUTEX(tty_mutex);
134 134
135#ifdef CONFIG_UNIX98_PTYS 135#ifdef CONFIG_UNIX98_PTYS
136extern struct tty_driver *ptm_driver; /* Unix98 pty masters; for /dev/ptmx */ 136extern struct tty_driver *ptm_driver; /* Unix98 pty masters; for /dev/ptmx */
@@ -1188,11 +1188,11 @@ void disassociate_ctty(int on_exit)
1188 1188
1189 lock_kernel(); 1189 lock_kernel();
1190 1190
1191 down(&tty_sem); 1191 mutex_lock(&tty_mutex);
1192 tty = current->signal->tty; 1192 tty = current->signal->tty;
1193 if (tty) { 1193 if (tty) {
1194 tty_pgrp = tty->pgrp; 1194 tty_pgrp = tty->pgrp;
1195 up(&tty_sem); 1195 mutex_unlock(&tty_mutex);
1196 if (on_exit && tty->driver->type != TTY_DRIVER_TYPE_PTY) 1196 if (on_exit && tty->driver->type != TTY_DRIVER_TYPE_PTY)
1197 tty_vhangup(tty); 1197 tty_vhangup(tty);
1198 } else { 1198 } else {
@@ -1200,7 +1200,7 @@ void disassociate_ctty(int on_exit)
1200 kill_pg(current->signal->tty_old_pgrp, SIGHUP, on_exit); 1200 kill_pg(current->signal->tty_old_pgrp, SIGHUP, on_exit);
1201 kill_pg(current->signal->tty_old_pgrp, SIGCONT, on_exit); 1201 kill_pg(current->signal->tty_old_pgrp, SIGCONT, on_exit);
1202 } 1202 }
1203 up(&tty_sem); 1203 mutex_unlock(&tty_mutex);
1204 unlock_kernel(); 1204 unlock_kernel();
1205 return; 1205 return;
1206 } 1206 }
@@ -1211,7 +1211,7 @@ void disassociate_ctty(int on_exit)
1211 } 1211 }
1212 1212
1213 /* Must lock changes to tty_old_pgrp */ 1213 /* Must lock changes to tty_old_pgrp */
1214 down(&tty_sem); 1214 mutex_lock(&tty_mutex);
1215 current->signal->tty_old_pgrp = 0; 1215 current->signal->tty_old_pgrp = 0;
1216 tty->session = 0; 1216 tty->session = 0;
1217 tty->pgrp = -1; 1217 tty->pgrp = -1;
@@ -1222,7 +1222,7 @@ void disassociate_ctty(int on_exit)
1222 p->signal->tty = NULL; 1222 p->signal->tty = NULL;
1223 } while_each_task_pid(current->signal->session, PIDTYPE_SID, p); 1223 } while_each_task_pid(current->signal->session, PIDTYPE_SID, p);
1224 read_unlock(&tasklist_lock); 1224 read_unlock(&tasklist_lock);
1225 up(&tty_sem); 1225 mutex_unlock(&tty_mutex);
1226 unlock_kernel(); 1226 unlock_kernel();
1227} 1227}
1228 1228
@@ -1306,7 +1306,7 @@ static inline ssize_t do_tty_write(
1306 ssize_t ret = 0, written = 0; 1306 ssize_t ret = 0, written = 0;
1307 unsigned int chunk; 1307 unsigned int chunk;
1308 1308
1309 if (down_interruptible(&tty->atomic_write)) { 1309 if (mutex_lock_interruptible(&tty->atomic_write_lock)) {
1310 return -ERESTARTSYS; 1310 return -ERESTARTSYS;
1311 } 1311 }
1312 1312
@@ -1329,7 +1329,7 @@ static inline ssize_t do_tty_write(
1329 if (count < chunk) 1329 if (count < chunk)
1330 chunk = count; 1330 chunk = count;
1331 1331
1332 /* write_buf/write_cnt is protected by the atomic_write semaphore */ 1332 /* write_buf/write_cnt is protected by the atomic_write_lock mutex */
1333 if (tty->write_cnt < chunk) { 1333 if (tty->write_cnt < chunk) {
1334 unsigned char *buf; 1334 unsigned char *buf;
1335 1335
@@ -1338,7 +1338,7 @@ static inline ssize_t do_tty_write(
1338 1338
1339 buf = kmalloc(chunk, GFP_KERNEL); 1339 buf = kmalloc(chunk, GFP_KERNEL);
1340 if (!buf) { 1340 if (!buf) {
1341 up(&tty->atomic_write); 1341 mutex_unlock(&tty->atomic_write_lock);
1342 return -ENOMEM; 1342 return -ENOMEM;
1343 } 1343 }
1344 kfree(tty->write_buf); 1344 kfree(tty->write_buf);
@@ -1374,7 +1374,7 @@ static inline ssize_t do_tty_write(
1374 inode->i_mtime = current_fs_time(inode->i_sb); 1374 inode->i_mtime = current_fs_time(inode->i_sb);
1375 ret = written; 1375 ret = written;
1376 } 1376 }
1377 up(&tty->atomic_write); 1377 mutex_unlock(&tty->atomic_write_lock);
1378 return ret; 1378 return ret;
1379} 1379}
1380 1380
@@ -1442,8 +1442,8 @@ static inline void tty_line_name(struct tty_driver *driver, int index, char *p)
1442 1442
1443/* 1443/*
1444 * WSH 06/09/97: Rewritten to remove races and properly clean up after a 1444 * WSH 06/09/97: Rewritten to remove races and properly clean up after a
1445 * failed open. The new code protects the open with a semaphore, so it's 1445 * failed open. The new code protects the open with a mutex, so it's
1446 * really quite straightforward. The semaphore locking can probably be 1446 * really quite straightforward. The mutex locking can probably be
1447 * relaxed for the (most common) case of reopening a tty. 1447 * relaxed for the (most common) case of reopening a tty.
1448 */ 1448 */
1449static int init_dev(struct tty_driver *driver, int idx, 1449static int init_dev(struct tty_driver *driver, int idx,
@@ -1640,7 +1640,7 @@ fast_track:
1640success: 1640success:
1641 *ret_tty = tty; 1641 *ret_tty = tty;
1642 1642
1643 /* All paths come through here to release the semaphore */ 1643 /* All paths come through here to release the mutex */
1644end_init: 1644end_init:
1645 return retval; 1645 return retval;
1646 1646
@@ -1837,7 +1837,7 @@ static void release_dev(struct file * filp)
1837 /* Guard against races with tty->count changes elsewhere and 1837 /* Guard against races with tty->count changes elsewhere and
1838 opens on /dev/tty */ 1838 opens on /dev/tty */
1839 1839
1840 down(&tty_sem); 1840 mutex_lock(&tty_mutex);
1841 tty_closing = tty->count <= 1; 1841 tty_closing = tty->count <= 1;
1842 o_tty_closing = o_tty && 1842 o_tty_closing = o_tty &&
1843 (o_tty->count <= (pty_master ? 1 : 0)); 1843 (o_tty->count <= (pty_master ? 1 : 0));
@@ -1868,7 +1868,7 @@ static void release_dev(struct file * filp)
1868 1868
1869 printk(KERN_WARNING "release_dev: %s: read/write wait queue " 1869 printk(KERN_WARNING "release_dev: %s: read/write wait queue "
1870 "active!\n", tty_name(tty, buf)); 1870 "active!\n", tty_name(tty, buf));
1871 up(&tty_sem); 1871 mutex_unlock(&tty_mutex);
1872 schedule(); 1872 schedule();
1873 } 1873 }
1874 1874
@@ -1934,7 +1934,7 @@ static void release_dev(struct file * filp)
1934 read_unlock(&tasklist_lock); 1934 read_unlock(&tasklist_lock);
1935 } 1935 }
1936 1936
1937 up(&tty_sem); 1937 mutex_unlock(&tty_mutex);
1938 1938
1939 /* check whether both sides are closing ... */ 1939 /* check whether both sides are closing ... */
1940 if (!tty_closing || (o_tty && !o_tty_closing)) 1940 if (!tty_closing || (o_tty && !o_tty_closing))
@@ -2040,11 +2040,11 @@ retry_open:
2040 index = -1; 2040 index = -1;
2041 retval = 0; 2041 retval = 0;
2042 2042
2043 down(&tty_sem); 2043 mutex_lock(&tty_mutex);
2044 2044
2045 if (device == MKDEV(TTYAUX_MAJOR,0)) { 2045 if (device == MKDEV(TTYAUX_MAJOR,0)) {
2046 if (!current->signal->tty) { 2046 if (!current->signal->tty) {
2047 up(&tty_sem); 2047 mutex_unlock(&tty_mutex);
2048 return -ENXIO; 2048 return -ENXIO;
2049 } 2049 }
2050 driver = current->signal->tty->driver; 2050 driver = current->signal->tty->driver;
@@ -2070,18 +2070,18 @@ retry_open:
2070 noctty = 1; 2070 noctty = 1;
2071 goto got_driver; 2071 goto got_driver;
2072 } 2072 }
2073 up(&tty_sem); 2073 mutex_unlock(&tty_mutex);
2074 return -ENODEV; 2074 return -ENODEV;
2075 } 2075 }
2076 2076
2077 driver = get_tty_driver(device, &index); 2077 driver = get_tty_driver(device, &index);
2078 if (!driver) { 2078 if (!driver) {
2079 up(&tty_sem); 2079 mutex_unlock(&tty_mutex);
2080 return -ENODEV; 2080 return -ENODEV;
2081 } 2081 }
2082got_driver: 2082got_driver:
2083 retval = init_dev(driver, index, &tty); 2083 retval = init_dev(driver, index, &tty);
2084 up(&tty_sem); 2084 mutex_unlock(&tty_mutex);
2085 if (retval) 2085 if (retval)
2086 return retval; 2086 return retval;
2087 2087
@@ -2167,9 +2167,9 @@ static int ptmx_open(struct inode * inode, struct file * filp)
2167 } 2167 }
2168 up(&allocated_ptys_lock); 2168 up(&allocated_ptys_lock);
2169 2169
2170 down(&tty_sem); 2170 mutex_lock(&tty_mutex);
2171 retval = init_dev(ptm_driver, index, &tty); 2171 retval = init_dev(ptm_driver, index, &tty);
2172 up(&tty_sem); 2172 mutex_unlock(&tty_mutex);
2173 2173
2174 if (retval) 2174 if (retval)
2175 goto out; 2175 goto out;
@@ -2915,8 +2915,8 @@ static void initialize_tty_struct(struct tty_struct *tty)
2915 init_waitqueue_head(&tty->write_wait); 2915 init_waitqueue_head(&tty->write_wait);
2916 init_waitqueue_head(&tty->read_wait); 2916 init_waitqueue_head(&tty->read_wait);
2917 INIT_WORK(&tty->hangup_work, do_tty_hangup, tty); 2917 INIT_WORK(&tty->hangup_work, do_tty_hangup, tty);
2918 sema_init(&tty->atomic_read, 1); 2918 mutex_init(&tty->atomic_read_lock);
2919 sema_init(&tty->atomic_write, 1); 2919 mutex_init(&tty->atomic_write_lock);
2920 spin_lock_init(&tty->read_lock); 2920 spin_lock_init(&tty->read_lock);
2921 INIT_LIST_HEAD(&tty->tty_files); 2921 INIT_LIST_HEAD(&tty->tty_files);
2922 INIT_WORK(&tty->SAK_work, NULL, NULL); 2922 INIT_WORK(&tty->SAK_work, NULL, NULL);
diff --git a/drivers/char/vme_scc.c b/drivers/char/vme_scc.c
index d9325281e4..fd00822ac1 100644
--- a/drivers/char/vme_scc.c
+++ b/drivers/char/vme_scc.c
@@ -184,7 +184,7 @@ static void scc_init_portstructs(void)
184 port->gs.closing_wait = 30 * HZ; 184 port->gs.closing_wait = 30 * HZ;
185 port->gs.rd = &scc_real_driver; 185 port->gs.rd = &scc_real_driver;
186#ifdef NEW_WRITE_LOCKING 186#ifdef NEW_WRITE_LOCKING
187 port->gs.port_write_sem = MUTEX; 187 port->gs.port_write_mutex = MUTEX;
188#endif 188#endif
189 init_waitqueue_head(&port->gs.open_wait); 189 init_waitqueue_head(&port->gs.open_wait);
190 init_waitqueue_head(&port->gs.close_wait); 190 init_waitqueue_head(&port->gs.close_wait);
diff --git a/drivers/char/vt.c b/drivers/char/vt.c
index 0900d1dbee..ca4844c527 100644
--- a/drivers/char/vt.c
+++ b/drivers/char/vt.c
@@ -2489,7 +2489,7 @@ static int con_open(struct tty_struct *tty, struct file *filp)
2489} 2489}
2490 2490
2491/* 2491/*
2492 * We take tty_sem in here to prevent another thread from coming in via init_dev 2492 * We take tty_mutex in here to prevent another thread from coming in via init_dev
2493 * and taking a ref against the tty while we're in the process of forgetting 2493 * and taking a ref against the tty while we're in the process of forgetting
2494 * about it and cleaning things up. 2494 * about it and cleaning things up.
2495 * 2495 *
@@ -2497,7 +2497,7 @@ static int con_open(struct tty_struct *tty, struct file *filp)
2497 */ 2497 */
2498static void con_close(struct tty_struct *tty, struct file *filp) 2498static void con_close(struct tty_struct *tty, struct file *filp)
2499{ 2499{
2500 down(&tty_sem); 2500 mutex_lock(&tty_mutex);
2501 acquire_console_sem(); 2501 acquire_console_sem();
2502 if (tty && tty->count == 1) { 2502 if (tty && tty->count == 1) {
2503 struct vc_data *vc = tty->driver_data; 2503 struct vc_data *vc = tty->driver_data;
@@ -2507,15 +2507,15 @@ static void con_close(struct tty_struct *tty, struct file *filp)
2507 tty->driver_data = NULL; 2507 tty->driver_data = NULL;
2508 release_console_sem(); 2508 release_console_sem();
2509 vcs_remove_devfs(tty); 2509 vcs_remove_devfs(tty);
2510 up(&tty_sem); 2510 mutex_unlock(&tty_mutex);
2511 /* 2511 /*
2512 * tty_sem is released, but we still hold BKL, so there is 2512 * tty_mutex is released, but we still hold BKL, so there is
2513 * still exclusion against init_dev() 2513 * still exclusion against init_dev()
2514 */ 2514 */
2515 return; 2515 return;
2516 } 2516 }
2517 release_console_sem(); 2517 release_console_sem();
2518 up(&tty_sem); 2518 mutex_unlock(&tty_mutex);
2519} 2519}
2520 2520
2521static void vc_init(struct vc_data *vc, unsigned int rows, 2521static void vc_init(struct vc_data *vc, unsigned int rows,
@@ -2869,9 +2869,9 @@ void unblank_screen(void)
2869} 2869}
2870 2870
2871/* 2871/*
2872 * We defer the timer blanking to work queue so it can take the console semaphore 2872 * We defer the timer blanking to work queue so it can take the console mutex
2873 * (console operations can still happen at irq time, but only from printk which 2873 * (console operations can still happen at irq time, but only from printk which
2874 * has the console semaphore. Not perfect yet, but better than no locking 2874 * has the console mutex. Not perfect yet, but better than no locking
2875 */ 2875 */
2876static void blank_screen_t(unsigned long dummy) 2876static void blank_screen_t(unsigned long dummy)
2877{ 2877{
@@ -3234,6 +3234,14 @@ void vcs_scr_writew(struct vc_data *vc, u16 val, u16 *org)
3234 } 3234 }
3235} 3235}
3236 3236
3237int is_console_suspend_safe(void)
3238{
3239 /* It is unsafe to suspend devices while X has control of the
3240 * hardware. Make sure we are running on a kernel-controlled console.
3241 */
3242 return vc_cons[fg_console].d->vc_mode == KD_TEXT;
3243}
3244
3237/* 3245/*
3238 * Visible symbols for modules 3246 * Visible symbols for modules
3239 */ 3247 */
diff --git a/drivers/char/watchdog/pcwd_usb.c b/drivers/char/watchdog/pcwd_usb.c
index 1533f56baa..2700c5c45b 100644
--- a/drivers/char/watchdog/pcwd_usb.c
+++ b/drivers/char/watchdog/pcwd_usb.c
@@ -42,6 +42,7 @@
42#include <linux/completion.h> 42#include <linux/completion.h>
43#include <asm/uaccess.h> 43#include <asm/uaccess.h>
44#include <linux/usb.h> 44#include <linux/usb.h>
45#include <linux/mutex.h>
45 46
46 47
47#ifdef CONFIG_USB_DEBUG 48#ifdef CONFIG_USB_DEBUG
@@ -143,7 +144,7 @@ struct usb_pcwd_private {
143static struct usb_pcwd_private *usb_pcwd_device; 144static struct usb_pcwd_private *usb_pcwd_device;
144 145
145/* prevent races between open() and disconnect() */ 146/* prevent races between open() and disconnect() */
146static DECLARE_MUTEX (disconnect_sem); 147static DEFINE_MUTEX(disconnect_mutex);
147 148
148/* local function prototypes */ 149/* local function prototypes */
149static int usb_pcwd_probe (struct usb_interface *interface, const struct usb_device_id *id); 150static int usb_pcwd_probe (struct usb_interface *interface, const struct usb_device_id *id);
@@ -723,7 +724,7 @@ static void usb_pcwd_disconnect(struct usb_interface *interface)
723 struct usb_pcwd_private *usb_pcwd; 724 struct usb_pcwd_private *usb_pcwd;
724 725
725 /* prevent races with open() */ 726 /* prevent races with open() */
726 down (&disconnect_sem); 727 mutex_lock(&disconnect_mutex);
727 728
728 usb_pcwd = usb_get_intfdata (interface); 729 usb_pcwd = usb_get_intfdata (interface);
729 usb_set_intfdata (interface, NULL); 730 usb_set_intfdata (interface, NULL);
@@ -749,7 +750,7 @@ static void usb_pcwd_disconnect(struct usb_interface *interface)
749 750
750 cards_found--; 751 cards_found--;
751 752
752 up (&disconnect_sem); 753 mutex_unlock(&disconnect_mutex);
753 754
754 printk(KERN_INFO PFX "USB PC Watchdog disconnected\n"); 755 printk(KERN_INFO PFX "USB PC Watchdog disconnected\n");
755} 756}
diff --git a/drivers/connector/connector.c b/drivers/connector/connector.c
index d7125f4d91..35897079a7 100644
--- a/drivers/connector/connector.c
+++ b/drivers/connector/connector.c
@@ -26,6 +26,7 @@
26#include <linux/netlink.h> 26#include <linux/netlink.h>
27#include <linux/moduleparam.h> 27#include <linux/moduleparam.h>
28#include <linux/connector.h> 28#include <linux/connector.h>
29#include <linux/mutex.h>
29 30
30#include <net/sock.h> 31#include <net/sock.h>
31 32
@@ -41,7 +42,7 @@ module_param(cn_val, uint, 0);
41MODULE_PARM_DESC(cn_idx, "Connector's main device idx."); 42MODULE_PARM_DESC(cn_idx, "Connector's main device idx.");
42MODULE_PARM_DESC(cn_val, "Connector's main device val."); 43MODULE_PARM_DESC(cn_val, "Connector's main device val.");
43 44
44static DECLARE_MUTEX(notify_lock); 45static DEFINE_MUTEX(notify_lock);
45static LIST_HEAD(notify_list); 46static LIST_HEAD(notify_list);
46 47
47static struct cn_dev cdev; 48static struct cn_dev cdev;
@@ -260,7 +261,7 @@ static void cn_notify(struct cb_id *id, u32 notify_event)
260{ 261{
261 struct cn_ctl_entry *ent; 262 struct cn_ctl_entry *ent;
262 263
263 down(&notify_lock); 264 mutex_lock(&notify_lock);
264 list_for_each_entry(ent, &notify_list, notify_entry) { 265 list_for_each_entry(ent, &notify_list, notify_entry) {
265 int i; 266 int i;
266 struct cn_notify_req *req; 267 struct cn_notify_req *req;
@@ -293,7 +294,7 @@ static void cn_notify(struct cb_id *id, u32 notify_event)
293 cn_netlink_send(&m, ctl->group, GFP_KERNEL); 294 cn_netlink_send(&m, ctl->group, GFP_KERNEL);
294 } 295 }
295 } 296 }
296 up(&notify_lock); 297 mutex_unlock(&notify_lock);
297} 298}
298 299
299/* 300/*
@@ -407,14 +408,14 @@ static void cn_callback(void *data)
407 if (ctl->group == 0) { 408 if (ctl->group == 0) {
408 struct cn_ctl_entry *n; 409 struct cn_ctl_entry *n;
409 410
410 down(&notify_lock); 411 mutex_lock(&notify_lock);
411 list_for_each_entry_safe(ent, n, &notify_list, notify_entry) { 412 list_for_each_entry_safe(ent, n, &notify_list, notify_entry) {
412 if (cn_ctl_msg_equals(ent->msg, ctl)) { 413 if (cn_ctl_msg_equals(ent->msg, ctl)) {
413 list_del(&ent->notify_entry); 414 list_del(&ent->notify_entry);
414 kfree(ent); 415 kfree(ent);
415 } 416 }
416 } 417 }
417 up(&notify_lock); 418 mutex_unlock(&notify_lock);
418 419
419 return; 420 return;
420 } 421 }
@@ -429,9 +430,9 @@ static void cn_callback(void *data)
429 430
430 memcpy(ent->msg, ctl, size - sizeof(*ent)); 431 memcpy(ent->msg, ctl, size - sizeof(*ent));
431 432
432 down(&notify_lock); 433 mutex_lock(&notify_lock);
433 list_add(&ent->notify_entry, &notify_list); 434 list_add(&ent->notify_entry, &notify_list);
434 up(&notify_lock); 435 mutex_unlock(&notify_lock);
435} 436}
436 437
437static int __init cn_init(void) 438static int __init cn_init(void)
diff --git a/drivers/firmware/dcdbas.c b/drivers/firmware/dcdbas.c
index 3a4e5c5b4e..d6543fc4a9 100644
--- a/drivers/firmware/dcdbas.c
+++ b/drivers/firmware/dcdbas.c
@@ -33,6 +33,7 @@
33#include <linux/spinlock.h> 33#include <linux/spinlock.h>
34#include <linux/string.h> 34#include <linux/string.h>
35#include <linux/types.h> 35#include <linux/types.h>
36#include <linux/mutex.h>
36#include <asm/io.h> 37#include <asm/io.h>
37#include <asm/semaphore.h> 38#include <asm/semaphore.h>
38 39
@@ -48,7 +49,7 @@ static u8 *smi_data_buf;
48static dma_addr_t smi_data_buf_handle; 49static dma_addr_t smi_data_buf_handle;
49static unsigned long smi_data_buf_size; 50static unsigned long smi_data_buf_size;
50static u32 smi_data_buf_phys_addr; 51static u32 smi_data_buf_phys_addr;
51static DECLARE_MUTEX(smi_data_lock); 52static DEFINE_MUTEX(smi_data_lock);
52 53
53static unsigned int host_control_action; 54static unsigned int host_control_action;
54static unsigned int host_control_smi_type; 55static unsigned int host_control_smi_type;
@@ -139,9 +140,9 @@ static ssize_t smi_data_buf_size_store(struct device *dev,
139 buf_size = simple_strtoul(buf, NULL, 10); 140 buf_size = simple_strtoul(buf, NULL, 10);
140 141
141 /* make sure SMI data buffer is at least buf_size */ 142 /* make sure SMI data buffer is at least buf_size */
142 down(&smi_data_lock); 143 mutex_lock(&smi_data_lock);
143 ret = smi_data_buf_realloc(buf_size); 144 ret = smi_data_buf_realloc(buf_size);
144 up(&smi_data_lock); 145 mutex_unlock(&smi_data_lock);
145 if (ret) 146 if (ret)
146 return ret; 147 return ret;
147 148
@@ -154,7 +155,7 @@ static ssize_t smi_data_read(struct kobject *kobj, char *buf, loff_t pos,
154 size_t max_read; 155 size_t max_read;
155 ssize_t ret; 156 ssize_t ret;
156 157
157 down(&smi_data_lock); 158 mutex_lock(&smi_data_lock);
158 159
159 if (pos >= smi_data_buf_size) { 160 if (pos >= smi_data_buf_size) {
160 ret = 0; 161 ret = 0;
@@ -165,7 +166,7 @@ static ssize_t smi_data_read(struct kobject *kobj, char *buf, loff_t pos,
165 ret = min(max_read, count); 166 ret = min(max_read, count);
166 memcpy(buf, smi_data_buf + pos, ret); 167 memcpy(buf, smi_data_buf + pos, ret);
167out: 168out:
168 up(&smi_data_lock); 169 mutex_unlock(&smi_data_lock);
169 return ret; 170 return ret;
170} 171}
171 172
@@ -174,7 +175,7 @@ static ssize_t smi_data_write(struct kobject *kobj, char *buf, loff_t pos,
174{ 175{
175 ssize_t ret; 176 ssize_t ret;
176 177
177 down(&smi_data_lock); 178 mutex_lock(&smi_data_lock);
178 179
179 ret = smi_data_buf_realloc(pos + count); 180 ret = smi_data_buf_realloc(pos + count);
180 if (ret) 181 if (ret)
@@ -183,7 +184,7 @@ static ssize_t smi_data_write(struct kobject *kobj, char *buf, loff_t pos,
183 memcpy(smi_data_buf + pos, buf, count); 184 memcpy(smi_data_buf + pos, buf, count);
184 ret = count; 185 ret = count;
185out: 186out:
186 up(&smi_data_lock); 187 mutex_unlock(&smi_data_lock);
187 return ret; 188 return ret;
188} 189}
189 190
@@ -201,9 +202,9 @@ static ssize_t host_control_action_store(struct device *dev,
201 ssize_t ret; 202 ssize_t ret;
202 203
203 /* make sure buffer is available for host control command */ 204 /* make sure buffer is available for host control command */
204 down(&smi_data_lock); 205 mutex_lock(&smi_data_lock);
205 ret = smi_data_buf_realloc(sizeof(struct apm_cmd)); 206 ret = smi_data_buf_realloc(sizeof(struct apm_cmd));
206 up(&smi_data_lock); 207 mutex_unlock(&smi_data_lock);
207 if (ret) 208 if (ret)
208 return ret; 209 return ret;
209 210
@@ -302,7 +303,7 @@ static ssize_t smi_request_store(struct device *dev,
302 unsigned long val = simple_strtoul(buf, NULL, 10); 303 unsigned long val = simple_strtoul(buf, NULL, 10);
303 ssize_t ret; 304 ssize_t ret;
304 305
305 down(&smi_data_lock); 306 mutex_lock(&smi_data_lock);
306 307
307 if (smi_data_buf_size < sizeof(struct smi_cmd)) { 308 if (smi_data_buf_size < sizeof(struct smi_cmd)) {
308 ret = -ENODEV; 309 ret = -ENODEV;
@@ -334,7 +335,7 @@ static ssize_t smi_request_store(struct device *dev,
334 } 335 }
335 336
336out: 337out:
337 up(&smi_data_lock); 338 mutex_unlock(&smi_data_lock);
338 return ret; 339 return ret;
339} 340}
340 341
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index 7230d4e081..99cdc612d2 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -406,13 +406,14 @@ config SENSORS_W83L785TS
406 will be called w83l785ts. 406 will be called w83l785ts.
407 407
408config SENSORS_W83627HF 408config SENSORS_W83627HF
409 tristate "Winbond W83627HF, W83627THF, W83637HF, W83697HF" 409 tristate "Winbond W83627HF, W83627THF, W83637HF, W83687THF, W83697HF"
410 depends on HWMON && I2C && EXPERIMENTAL 410 depends on HWMON && I2C
411 select I2C_ISA 411 select I2C_ISA
412 select HWMON_VID 412 select HWMON_VID
413 help 413 help
414 If you say yes here you get support for the Winbond W836X7 series 414 If you say yes here you get support for the Winbond W836X7 series
415 of sensor chips: the W83627HF, W83627THF, W83637HF, and the W83697HF 415 of sensor chips: the W83627HF, W83627THF, W83637HF, W83687THF and
416 W83697HF.
416 417
417 This driver can also be built as a module. If so, the module 418 This driver can also be built as a module. If so, the module
418 will be called w83627hf. 419 will be called w83627hf.
diff --git a/drivers/hwmon/adm1021.c b/drivers/hwmon/adm1021.c
index 665612729c..2b6e74dd4a 100644
--- a/drivers/hwmon/adm1021.c
+++ b/drivers/hwmon/adm1021.c
@@ -26,6 +26,7 @@
26#include <linux/i2c.h> 26#include <linux/i2c.h>
27#include <linux/hwmon.h> 27#include <linux/hwmon.h>
28#include <linux/err.h> 28#include <linux/err.h>
29#include <linux/mutex.h>
29 30
30 31
31/* Addresses to scan */ 32/* Addresses to scan */
@@ -92,7 +93,7 @@ struct adm1021_data {
92 struct class_device *class_dev; 93 struct class_device *class_dev;
93 enum chips type; 94 enum chips type;
94 95
95 struct semaphore update_lock; 96 struct mutex update_lock;
96 char valid; /* !=0 if following fields are valid */ 97 char valid; /* !=0 if following fields are valid */
97 unsigned long last_updated; /* In jiffies */ 98 unsigned long last_updated; /* In jiffies */
98 99
@@ -162,10 +163,10 @@ static ssize_t set_##value(struct device *dev, struct device_attribute *attr, co
162 struct adm1021_data *data = i2c_get_clientdata(client); \ 163 struct adm1021_data *data = i2c_get_clientdata(client); \
163 int temp = simple_strtoul(buf, NULL, 10); \ 164 int temp = simple_strtoul(buf, NULL, 10); \
164 \ 165 \
165 down(&data->update_lock); \ 166 mutex_lock(&data->update_lock); \
166 data->value = TEMP_TO_REG(temp); \ 167 data->value = TEMP_TO_REG(temp); \
167 adm1021_write_value(client, reg, data->value); \ 168 adm1021_write_value(client, reg, data->value); \
168 up(&data->update_lock); \ 169 mutex_unlock(&data->update_lock); \
169 return count; \ 170 return count; \
170} 171}
171set(temp_max, ADM1021_REG_TOS_W); 172set(temp_max, ADM1021_REG_TOS_W);
@@ -275,7 +276,7 @@ static int adm1021_detect(struct i2c_adapter *adapter, int address, int kind)
275 strlcpy(new_client->name, type_name, I2C_NAME_SIZE); 276 strlcpy(new_client->name, type_name, I2C_NAME_SIZE);
276 data->type = kind; 277 data->type = kind;
277 data->valid = 0; 278 data->valid = 0;
278 init_MUTEX(&data->update_lock); 279 mutex_init(&data->update_lock);
279 280
280 /* Tell the I2C layer a new client has arrived */ 281 /* Tell the I2C layer a new client has arrived */
281 if ((err = i2c_attach_client(new_client))) 282 if ((err = i2c_attach_client(new_client)))
@@ -351,7 +352,7 @@ static struct adm1021_data *adm1021_update_device(struct device *dev)
351 struct i2c_client *client = to_i2c_client(dev); 352 struct i2c_client *client = to_i2c_client(dev);
352 struct adm1021_data *data = i2c_get_clientdata(client); 353 struct adm1021_data *data = i2c_get_clientdata(client);
353 354
354 down(&data->update_lock); 355 mutex_lock(&data->update_lock);
355 356
356 if (time_after(jiffies, data->last_updated + HZ + HZ / 2) 357 if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
357 || !data->valid) { 358 || !data->valid) {
@@ -375,7 +376,7 @@ static struct adm1021_data *adm1021_update_device(struct device *dev)
375 data->valid = 1; 376 data->valid = 1;
376 } 377 }
377 378
378 up(&data->update_lock); 379 mutex_unlock(&data->update_lock);
379 380
380 return data; 381 return data;
381} 382}
diff --git a/drivers/hwmon/adm1025.c b/drivers/hwmon/adm1025.c
index 9331c56d2b..a4c859c9fb 100644
--- a/drivers/hwmon/adm1025.c
+++ b/drivers/hwmon/adm1025.c
@@ -53,6 +53,7 @@
53#include <linux/hwmon.h> 53#include <linux/hwmon.h>
54#include <linux/hwmon-vid.h> 54#include <linux/hwmon-vid.h>
55#include <linux/err.h> 55#include <linux/err.h>
56#include <linux/mutex.h>
56 57
57/* 58/*
58 * Addresses to scan 59 * Addresses to scan
@@ -133,7 +134,7 @@ static struct i2c_driver adm1025_driver = {
133struct adm1025_data { 134struct adm1025_data {
134 struct i2c_client client; 135 struct i2c_client client;
135 struct class_device *class_dev; 136 struct class_device *class_dev;
136 struct semaphore update_lock; 137 struct mutex update_lock;
137 char valid; /* zero until following fields are valid */ 138 char valid; /* zero until following fields are valid */
138 unsigned long last_updated; /* in jiffies */ 139 unsigned long last_updated; /* in jiffies */
139 140
@@ -207,11 +208,11 @@ static ssize_t set_in##offset##_min(struct device *dev, struct device_attribute
207 struct adm1025_data *data = i2c_get_clientdata(client); \ 208 struct adm1025_data *data = i2c_get_clientdata(client); \
208 long val = simple_strtol(buf, NULL, 10); \ 209 long val = simple_strtol(buf, NULL, 10); \
209 \ 210 \
210 down(&data->update_lock); \ 211 mutex_lock(&data->update_lock); \
211 data->in_min[offset] = IN_TO_REG(val, in_scale[offset]); \ 212 data->in_min[offset] = IN_TO_REG(val, in_scale[offset]); \
212 i2c_smbus_write_byte_data(client, ADM1025_REG_IN_MIN(offset), \ 213 i2c_smbus_write_byte_data(client, ADM1025_REG_IN_MIN(offset), \
213 data->in_min[offset]); \ 214 data->in_min[offset]); \
214 up(&data->update_lock); \ 215 mutex_unlock(&data->update_lock); \
215 return count; \ 216 return count; \
216} \ 217} \
217static ssize_t set_in##offset##_max(struct device *dev, struct device_attribute *attr, const char *buf, \ 218static ssize_t set_in##offset##_max(struct device *dev, struct device_attribute *attr, const char *buf, \
@@ -221,11 +222,11 @@ static ssize_t set_in##offset##_max(struct device *dev, struct device_attribute
221 struct adm1025_data *data = i2c_get_clientdata(client); \ 222 struct adm1025_data *data = i2c_get_clientdata(client); \
222 long val = simple_strtol(buf, NULL, 10); \ 223 long val = simple_strtol(buf, NULL, 10); \
223 \ 224 \
224 down(&data->update_lock); \ 225 mutex_lock(&data->update_lock); \
225 data->in_max[offset] = IN_TO_REG(val, in_scale[offset]); \ 226 data->in_max[offset] = IN_TO_REG(val, in_scale[offset]); \
226 i2c_smbus_write_byte_data(client, ADM1025_REG_IN_MAX(offset), \ 227 i2c_smbus_write_byte_data(client, ADM1025_REG_IN_MAX(offset), \
227 data->in_max[offset]); \ 228 data->in_max[offset]); \
228 up(&data->update_lock); \ 229 mutex_unlock(&data->update_lock); \
229 return count; \ 230 return count; \
230} \ 231} \
231static DEVICE_ATTR(in##offset##_min, S_IWUSR | S_IRUGO, \ 232static DEVICE_ATTR(in##offset##_min, S_IWUSR | S_IRUGO, \
@@ -247,11 +248,11 @@ static ssize_t set_temp##offset##_min(struct device *dev, struct device_attribut
247 struct adm1025_data *data = i2c_get_clientdata(client); \ 248 struct adm1025_data *data = i2c_get_clientdata(client); \
248 long val = simple_strtol(buf, NULL, 10); \ 249 long val = simple_strtol(buf, NULL, 10); \
249 \ 250 \
250 down(&data->update_lock); \ 251 mutex_lock(&data->update_lock); \
251 data->temp_min[offset-1] = TEMP_TO_REG(val); \ 252 data->temp_min[offset-1] = TEMP_TO_REG(val); \
252 i2c_smbus_write_byte_data(client, ADM1025_REG_TEMP_LOW(offset-1), \ 253 i2c_smbus_write_byte_data(client, ADM1025_REG_TEMP_LOW(offset-1), \
253 data->temp_min[offset-1]); \ 254 data->temp_min[offset-1]); \
254 up(&data->update_lock); \ 255 mutex_unlock(&data->update_lock); \
255 return count; \ 256 return count; \
256} \ 257} \
257static ssize_t set_temp##offset##_max(struct device *dev, struct device_attribute *attr, const char *buf, \ 258static ssize_t set_temp##offset##_max(struct device *dev, struct device_attribute *attr, const char *buf, \
@@ -261,11 +262,11 @@ static ssize_t set_temp##offset##_max(struct device *dev, struct device_attribut
261 struct adm1025_data *data = i2c_get_clientdata(client); \ 262 struct adm1025_data *data = i2c_get_clientdata(client); \
262 long val = simple_strtol(buf, NULL, 10); \ 263 long val = simple_strtol(buf, NULL, 10); \
263 \ 264 \
264 down(&data->update_lock); \ 265 mutex_lock(&data->update_lock); \
265 data->temp_max[offset-1] = TEMP_TO_REG(val); \ 266 data->temp_max[offset-1] = TEMP_TO_REG(val); \
266 i2c_smbus_write_byte_data(client, ADM1025_REG_TEMP_HIGH(offset-1), \ 267 i2c_smbus_write_byte_data(client, ADM1025_REG_TEMP_HIGH(offset-1), \
267 data->temp_max[offset-1]); \ 268 data->temp_max[offset-1]); \
268 up(&data->update_lock); \ 269 mutex_unlock(&data->update_lock); \
269 return count; \ 270 return count; \
270} \ 271} \
271static DEVICE_ATTR(temp##offset##_min, S_IWUSR | S_IRUGO, \ 272static DEVICE_ATTR(temp##offset##_min, S_IWUSR | S_IRUGO, \
@@ -404,7 +405,7 @@ static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind)
404 /* We can fill in the remaining client fields */ 405 /* We can fill in the remaining client fields */
405 strlcpy(new_client->name, name, I2C_NAME_SIZE); 406 strlcpy(new_client->name, name, I2C_NAME_SIZE);
406 data->valid = 0; 407 data->valid = 0;
407 init_MUTEX(&data->update_lock); 408 mutex_init(&data->update_lock);
408 409
409 /* Tell the I2C layer a new client has arrived */ 410 /* Tell the I2C layer a new client has arrived */
410 if ((err = i2c_attach_client(new_client))) 411 if ((err = i2c_attach_client(new_client)))
@@ -523,7 +524,7 @@ static struct adm1025_data *adm1025_update_device(struct device *dev)
523 struct i2c_client *client = to_i2c_client(dev); 524 struct i2c_client *client = to_i2c_client(dev);
524 struct adm1025_data *data = i2c_get_clientdata(client); 525 struct adm1025_data *data = i2c_get_clientdata(client);
525 526
526 down(&data->update_lock); 527 mutex_lock(&data->update_lock);
527 528
528 if (time_after(jiffies, data->last_updated + HZ * 2) || !data->valid) { 529 if (time_after(jiffies, data->last_updated + HZ * 2) || !data->valid) {
529 int i; 530 int i;
@@ -558,7 +559,7 @@ static struct adm1025_data *adm1025_update_device(struct device *dev)
558 data->valid = 1; 559 data->valid = 1;
559 } 560 }
560 561
561 up(&data->update_lock); 562 mutex_unlock(&data->update_lock);
562 563
563 return data; 564 return data;
564} 565}
diff --git a/drivers/hwmon/adm1026.c b/drivers/hwmon/adm1026.c
index fefe6e74fd..6d4f8b8d35 100644
--- a/drivers/hwmon/adm1026.c
+++ b/drivers/hwmon/adm1026.c
@@ -32,6 +32,7 @@
32#include <linux/hwmon-sysfs.h> 32#include <linux/hwmon-sysfs.h>
33#include <linux/hwmon-vid.h> 33#include <linux/hwmon-vid.h>
34#include <linux/err.h> 34#include <linux/err.h>
35#include <linux/mutex.h>
35 36
36/* Addresses to scan */ 37/* Addresses to scan */
37static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END }; 38static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END };
@@ -260,10 +261,10 @@ struct pwm_data {
260struct adm1026_data { 261struct adm1026_data {
261 struct i2c_client client; 262 struct i2c_client client;
262 struct class_device *class_dev; 263 struct class_device *class_dev;
263 struct semaphore lock; 264 struct mutex lock;
264 enum chips type; 265 enum chips type;
265 266
266 struct semaphore update_lock; 267 struct mutex update_lock;
267 int valid; /* !=0 if following fields are valid */ 268 int valid; /* !=0 if following fields are valid */
268 unsigned long last_reading; /* In jiffies */ 269 unsigned long last_reading; /* In jiffies */
269 unsigned long last_config; /* In jiffies */ 270 unsigned long last_config; /* In jiffies */
@@ -298,9 +299,8 @@ static int adm1026_attach_adapter(struct i2c_adapter *adapter);
298static int adm1026_detect(struct i2c_adapter *adapter, int address, 299static int adm1026_detect(struct i2c_adapter *adapter, int address,
299 int kind); 300 int kind);
300static int adm1026_detach_client(struct i2c_client *client); 301static int adm1026_detach_client(struct i2c_client *client);
301static int adm1026_read_value(struct i2c_client *client, u8 register); 302static int adm1026_read_value(struct i2c_client *client, u8 reg);
302static int adm1026_write_value(struct i2c_client *client, u8 register, 303static int adm1026_write_value(struct i2c_client *client, u8 reg, int value);
303 int value);
304static void adm1026_print_gpio(struct i2c_client *client); 304static void adm1026_print_gpio(struct i2c_client *client);
305static void adm1026_fixup_gpio(struct i2c_client *client); 305static void adm1026_fixup_gpio(struct i2c_client *client);
306static struct adm1026_data *adm1026_update_device(struct device *dev); 306static struct adm1026_data *adm1026_update_device(struct device *dev);
@@ -575,7 +575,7 @@ static struct adm1026_data *adm1026_update_device(struct device *dev)
575 int i; 575 int i;
576 long value, alarms, gpio; 576 long value, alarms, gpio;
577 577
578 down(&data->update_lock); 578 mutex_lock(&data->update_lock);
579 if (!data->valid 579 if (!data->valid
580 || time_after(jiffies, data->last_reading + ADM1026_DATA_INTERVAL)) { 580 || time_after(jiffies, data->last_reading + ADM1026_DATA_INTERVAL)) {
581 /* Things that change quickly */ 581 /* Things that change quickly */
@@ -710,7 +710,7 @@ static struct adm1026_data *adm1026_update_device(struct device *dev)
710 dev_dbg(&client->dev, "Setting VID from GPIO11-15.\n"); 710 dev_dbg(&client->dev, "Setting VID from GPIO11-15.\n");
711 data->vid = (data->gpio >> 11) & 0x1f; 711 data->vid = (data->gpio >> 11) & 0x1f;
712 data->valid = 1; 712 data->valid = 1;
713 up(&data->update_lock); 713 mutex_unlock(&data->update_lock);
714 return data; 714 return data;
715} 715}
716 716
@@ -739,10 +739,10 @@ static ssize_t set_in_min(struct device *dev, struct device_attribute *attr,
739 struct adm1026_data *data = i2c_get_clientdata(client); 739 struct adm1026_data *data = i2c_get_clientdata(client);
740 int val = simple_strtol(buf, NULL, 10); 740 int val = simple_strtol(buf, NULL, 10);
741 741
742 down(&data->update_lock); 742 mutex_lock(&data->update_lock);
743 data->in_min[nr] = INS_TO_REG(nr, val); 743 data->in_min[nr] = INS_TO_REG(nr, val);
744 adm1026_write_value(client, ADM1026_REG_IN_MIN[nr], data->in_min[nr]); 744 adm1026_write_value(client, ADM1026_REG_IN_MIN[nr], data->in_min[nr]);
745 up(&data->update_lock); 745 mutex_unlock(&data->update_lock);
746 return count; 746 return count;
747} 747}
748static ssize_t show_in_max(struct device *dev, struct device_attribute *attr, 748static ssize_t show_in_max(struct device *dev, struct device_attribute *attr,
@@ -762,10 +762,10 @@ static ssize_t set_in_max(struct device *dev, struct device_attribute *attr,
762 struct adm1026_data *data = i2c_get_clientdata(client); 762 struct adm1026_data *data = i2c_get_clientdata(client);
763 int val = simple_strtol(buf, NULL, 10); 763 int val = simple_strtol(buf, NULL, 10);
764 764
765 down(&data->update_lock); 765 mutex_lock(&data->update_lock);
766 data->in_max[nr] = INS_TO_REG(nr, val); 766 data->in_max[nr] = INS_TO_REG(nr, val);
767 adm1026_write_value(client, ADM1026_REG_IN_MAX[nr], data->in_max[nr]); 767 adm1026_write_value(client, ADM1026_REG_IN_MAX[nr], data->in_max[nr]);
768 up(&data->update_lock); 768 mutex_unlock(&data->update_lock);
769 return count; 769 return count;
770} 770}
771 771
@@ -813,10 +813,10 @@ static ssize_t set_in16_min(struct device *dev, struct device_attribute *attr, c
813 struct adm1026_data *data = i2c_get_clientdata(client); 813 struct adm1026_data *data = i2c_get_clientdata(client);
814 int val = simple_strtol(buf, NULL, 10); 814 int val = simple_strtol(buf, NULL, 10);
815 815
816 down(&data->update_lock); 816 mutex_lock(&data->update_lock);
817 data->in_min[16] = INS_TO_REG(16, val + NEG12_OFFSET); 817 data->in_min[16] = INS_TO_REG(16, val + NEG12_OFFSET);
818 adm1026_write_value(client, ADM1026_REG_IN_MIN[16], data->in_min[16]); 818 adm1026_write_value(client, ADM1026_REG_IN_MIN[16], data->in_min[16]);
819 up(&data->update_lock); 819 mutex_unlock(&data->update_lock);
820 return count; 820 return count;
821} 821}
822static ssize_t show_in16_max(struct device *dev, struct device_attribute *attr, char *buf) 822static ssize_t show_in16_max(struct device *dev, struct device_attribute *attr, char *buf)
@@ -831,10 +831,10 @@ static ssize_t set_in16_max(struct device *dev, struct device_attribute *attr, c
831 struct adm1026_data *data = i2c_get_clientdata(client); 831 struct adm1026_data *data = i2c_get_clientdata(client);
832 int val = simple_strtol(buf, NULL, 10); 832 int val = simple_strtol(buf, NULL, 10);
833 833
834 down(&data->update_lock); 834 mutex_lock(&data->update_lock);
835 data->in_max[16] = INS_TO_REG(16, val+NEG12_OFFSET); 835 data->in_max[16] = INS_TO_REG(16, val+NEG12_OFFSET);
836 adm1026_write_value(client, ADM1026_REG_IN_MAX[16], data->in_max[16]); 836 adm1026_write_value(client, ADM1026_REG_IN_MAX[16], data->in_max[16]);
837 up(&data->update_lock); 837 mutex_unlock(&data->update_lock);
838 return count; 838 return count;
839} 839}
840 840
@@ -874,11 +874,11 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
874 struct adm1026_data *data = i2c_get_clientdata(client); 874 struct adm1026_data *data = i2c_get_clientdata(client);
875 int val = simple_strtol(buf, NULL, 10); 875 int val = simple_strtol(buf, NULL, 10);
876 876
877 down(&data->update_lock); 877 mutex_lock(&data->update_lock);
878 data->fan_min[nr] = FAN_TO_REG(val, data->fan_div[nr]); 878 data->fan_min[nr] = FAN_TO_REG(val, data->fan_div[nr]);
879 adm1026_write_value(client, ADM1026_REG_FAN_MIN(nr), 879 adm1026_write_value(client, ADM1026_REG_FAN_MIN(nr),
880 data->fan_min[nr]); 880 data->fan_min[nr]);
881 up(&data->update_lock); 881 mutex_unlock(&data->update_lock);
882 return count; 882 return count;
883} 883}
884 884
@@ -939,7 +939,7 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
939 if (new_div == 0) { 939 if (new_div == 0) {
940 return -EINVAL; 940 return -EINVAL;
941 } 941 }
942 down(&data->update_lock); 942 mutex_lock(&data->update_lock);
943 orig_div = data->fan_div[nr]; 943 orig_div = data->fan_div[nr];
944 data->fan_div[nr] = DIV_FROM_REG(new_div); 944 data->fan_div[nr] = DIV_FROM_REG(new_div);
945 945
@@ -958,7 +958,7 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
958 if (data->fan_div[nr] != orig_div) { 958 if (data->fan_div[nr] != orig_div) {
959 fixup_fan_min(dev,nr,orig_div); 959 fixup_fan_min(dev,nr,orig_div);
960 } 960 }
961 up(&data->update_lock); 961 mutex_unlock(&data->update_lock);
962 return count; 962 return count;
963} 963}
964 964
@@ -1001,11 +1001,11 @@ static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,
1001 struct adm1026_data *data = i2c_get_clientdata(client); 1001 struct adm1026_data *data = i2c_get_clientdata(client);
1002 int val = simple_strtol(buf, NULL, 10); 1002 int val = simple_strtol(buf, NULL, 10);
1003 1003
1004 down(&data->update_lock); 1004 mutex_lock(&data->update_lock);
1005 data->temp_min[nr] = TEMP_TO_REG(val); 1005 data->temp_min[nr] = TEMP_TO_REG(val);
1006 adm1026_write_value(client, ADM1026_REG_TEMP_MIN[nr], 1006 adm1026_write_value(client, ADM1026_REG_TEMP_MIN[nr],
1007 data->temp_min[nr]); 1007 data->temp_min[nr]);
1008 up(&data->update_lock); 1008 mutex_unlock(&data->update_lock);
1009 return count; 1009 return count;
1010} 1010}
1011static ssize_t show_temp_max(struct device *dev, struct device_attribute *attr, 1011static ssize_t show_temp_max(struct device *dev, struct device_attribute *attr,
@@ -1025,11 +1025,11 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
1025 struct adm1026_data *data = i2c_get_clientdata(client); 1025 struct adm1026_data *data = i2c_get_clientdata(client);
1026 int val = simple_strtol(buf, NULL, 10); 1026 int val = simple_strtol(buf, NULL, 10);
1027 1027
1028 down(&data->update_lock); 1028 mutex_lock(&data->update_lock);
1029 data->temp_max[nr] = TEMP_TO_REG(val); 1029 data->temp_max[nr] = TEMP_TO_REG(val);
1030 adm1026_write_value(client, ADM1026_REG_TEMP_MAX[nr], 1030 adm1026_write_value(client, ADM1026_REG_TEMP_MAX[nr],
1031 data->temp_max[nr]); 1031 data->temp_max[nr]);
1032 up(&data->update_lock); 1032 mutex_unlock(&data->update_lock);
1033 return count; 1033 return count;
1034} 1034}
1035 1035
@@ -1064,11 +1064,11 @@ static ssize_t set_temp_offset(struct device *dev,
1064 struct adm1026_data *data = i2c_get_clientdata(client); 1064 struct adm1026_data *data = i2c_get_clientdata(client);
1065 int val = simple_strtol(buf, NULL, 10); 1065 int val = simple_strtol(buf, NULL, 10);
1066 1066
1067 down(&data->update_lock); 1067 mutex_lock(&data->update_lock);
1068 data->temp_offset[nr] = TEMP_TO_REG(val); 1068 data->temp_offset[nr] = TEMP_TO_REG(val);
1069 adm1026_write_value(client, ADM1026_REG_TEMP_OFFSET[nr], 1069 adm1026_write_value(client, ADM1026_REG_TEMP_OFFSET[nr],
1070 data->temp_offset[nr]); 1070 data->temp_offset[nr]);
1071 up(&data->update_lock); 1071 mutex_unlock(&data->update_lock);
1072 return count; 1072 return count;
1073} 1073}
1074 1074
@@ -1115,11 +1115,11 @@ static ssize_t set_temp_auto_point1_temp(struct device *dev,
1115 struct adm1026_data *data = i2c_get_clientdata(client); 1115 struct adm1026_data *data = i2c_get_clientdata(client);
1116 int val = simple_strtol(buf, NULL, 10); 1116 int val = simple_strtol(buf, NULL, 10);
1117 1117
1118 down(&data->update_lock); 1118 mutex_lock(&data->update_lock);
1119 data->temp_tmin[nr] = TEMP_TO_REG(val); 1119 data->temp_tmin[nr] = TEMP_TO_REG(val);
1120 adm1026_write_value(client, ADM1026_REG_TEMP_TMIN[nr], 1120 adm1026_write_value(client, ADM1026_REG_TEMP_TMIN[nr],
1121 data->temp_tmin[nr]); 1121 data->temp_tmin[nr]);
1122 up(&data->update_lock); 1122 mutex_unlock(&data->update_lock);
1123 return count; 1123 return count;
1124} 1124}
1125 1125
@@ -1150,11 +1150,11 @@ static ssize_t set_temp_crit_enable(struct device *dev,
1150 int val = simple_strtol(buf, NULL, 10); 1150 int val = simple_strtol(buf, NULL, 10);
1151 1151
1152 if ((val == 1) || (val==0)) { 1152 if ((val == 1) || (val==0)) {
1153 down(&data->update_lock); 1153 mutex_lock(&data->update_lock);
1154 data->config1 = (data->config1 & ~CFG1_THERM_HOT) | (val << 4); 1154 data->config1 = (data->config1 & ~CFG1_THERM_HOT) | (val << 4);
1155 adm1026_write_value(client, ADM1026_REG_CONFIG1, 1155 adm1026_write_value(client, ADM1026_REG_CONFIG1,
1156 data->config1); 1156 data->config1);
1157 up(&data->update_lock); 1157 mutex_unlock(&data->update_lock);
1158 } 1158 }
1159 return count; 1159 return count;
1160} 1160}
@@ -1184,11 +1184,11 @@ static ssize_t set_temp_crit(struct device *dev, struct device_attribute *attr,
1184 struct adm1026_data *data = i2c_get_clientdata(client); 1184 struct adm1026_data *data = i2c_get_clientdata(client);
1185 int val = simple_strtol(buf, NULL, 10); 1185 int val = simple_strtol(buf, NULL, 10);
1186 1186
1187 down(&data->update_lock); 1187 mutex_lock(&data->update_lock);
1188 data->temp_crit[nr] = TEMP_TO_REG(val); 1188 data->temp_crit[nr] = TEMP_TO_REG(val);
1189 adm1026_write_value(client, ADM1026_REG_TEMP_THERM[nr], 1189 adm1026_write_value(client, ADM1026_REG_TEMP_THERM[nr],
1190 data->temp_crit[nr]); 1190 data->temp_crit[nr]);
1191 up(&data->update_lock); 1191 mutex_unlock(&data->update_lock);
1192 return count; 1192 return count;
1193} 1193}
1194 1194
@@ -1212,10 +1212,10 @@ static ssize_t set_analog_out_reg(struct device *dev, struct device_attribute *a
1212 struct adm1026_data *data = i2c_get_clientdata(client); 1212 struct adm1026_data *data = i2c_get_clientdata(client);
1213 int val = simple_strtol(buf, NULL, 10); 1213 int val = simple_strtol(buf, NULL, 10);
1214 1214
1215 down(&data->update_lock); 1215 mutex_lock(&data->update_lock);
1216 data->analog_out = DAC_TO_REG(val); 1216 data->analog_out = DAC_TO_REG(val);
1217 adm1026_write_value(client, ADM1026_REG_DAC, data->analog_out); 1217 adm1026_write_value(client, ADM1026_REG_DAC, data->analog_out);
1218 up(&data->update_lock); 1218 mutex_unlock(&data->update_lock);
1219 return count; 1219 return count;
1220} 1220}
1221 1221
@@ -1267,7 +1267,7 @@ static ssize_t set_alarm_mask(struct device *dev, struct device_attribute *attr,
1267 int val = simple_strtol(buf, NULL, 10); 1267 int val = simple_strtol(buf, NULL, 10);
1268 unsigned long mask; 1268 unsigned long mask;
1269 1269
1270 down(&data->update_lock); 1270 mutex_lock(&data->update_lock);
1271 data->alarm_mask = val & 0x7fffffff; 1271 data->alarm_mask = val & 0x7fffffff;
1272 mask = data->alarm_mask 1272 mask = data->alarm_mask
1273 | (data->gpio_mask & 0x10000 ? 0x80000000 : 0); 1273 | (data->gpio_mask & 0x10000 ? 0x80000000 : 0);
@@ -1282,7 +1282,7 @@ static ssize_t set_alarm_mask(struct device *dev, struct device_attribute *attr,
1282 mask >>= 8; 1282 mask >>= 8;
1283 adm1026_write_value(client, ADM1026_REG_MASK4, 1283 adm1026_write_value(client, ADM1026_REG_MASK4,
1284 mask & 0xff); 1284 mask & 0xff);
1285 up(&data->update_lock); 1285 mutex_unlock(&data->update_lock);
1286 return count; 1286 return count;
1287} 1287}
1288 1288
@@ -1303,7 +1303,7 @@ static ssize_t set_gpio(struct device *dev, struct device_attribute *attr, const
1303 int val = simple_strtol(buf, NULL, 10); 1303 int val = simple_strtol(buf, NULL, 10);
1304 long gpio; 1304 long gpio;
1305 1305
1306 down(&data->update_lock); 1306 mutex_lock(&data->update_lock);
1307 data->gpio = val & 0x1ffff; 1307 data->gpio = val & 0x1ffff;
1308 gpio = data->gpio; 1308 gpio = data->gpio;
1309 adm1026_write_value(client, ADM1026_REG_GPIO_STATUS_0_7,gpio & 0xff); 1309 adm1026_write_value(client, ADM1026_REG_GPIO_STATUS_0_7,gpio & 0xff);
@@ -1311,7 +1311,7 @@ static ssize_t set_gpio(struct device *dev, struct device_attribute *attr, const
1311 adm1026_write_value(client, ADM1026_REG_GPIO_STATUS_8_15,gpio & 0xff); 1311 adm1026_write_value(client, ADM1026_REG_GPIO_STATUS_8_15,gpio & 0xff);
1312 gpio = ((gpio >> 1) & 0x80) | (data->alarms >> 24 & 0x7f); 1312 gpio = ((gpio >> 1) & 0x80) | (data->alarms >> 24 & 0x7f);
1313 adm1026_write_value(client, ADM1026_REG_STATUS4,gpio & 0xff); 1313 adm1026_write_value(client, ADM1026_REG_STATUS4,gpio & 0xff);
1314 up(&data->update_lock); 1314 mutex_unlock(&data->update_lock);
1315 return count; 1315 return count;
1316} 1316}
1317 1317
@@ -1331,7 +1331,7 @@ static ssize_t set_gpio_mask(struct device *dev, struct device_attribute *attr,
1331 int val = simple_strtol(buf, NULL, 10); 1331 int val = simple_strtol(buf, NULL, 10);
1332 long mask; 1332 long mask;
1333 1333
1334 down(&data->update_lock); 1334 mutex_lock(&data->update_lock);
1335 data->gpio_mask = val & 0x1ffff; 1335 data->gpio_mask = val & 0x1ffff;
1336 mask = data->gpio_mask; 1336 mask = data->gpio_mask;
1337 adm1026_write_value(client, ADM1026_REG_GPIO_MASK_0_7,mask & 0xff); 1337 adm1026_write_value(client, ADM1026_REG_GPIO_MASK_0_7,mask & 0xff);
@@ -1339,7 +1339,7 @@ static ssize_t set_gpio_mask(struct device *dev, struct device_attribute *attr,
1339 adm1026_write_value(client, ADM1026_REG_GPIO_MASK_8_15,mask & 0xff); 1339 adm1026_write_value(client, ADM1026_REG_GPIO_MASK_8_15,mask & 0xff);
1340 mask = ((mask >> 1) & 0x80) | (data->alarm_mask >> 24 & 0x7f); 1340 mask = ((mask >> 1) & 0x80) | (data->alarm_mask >> 24 & 0x7f);
1341 adm1026_write_value(client, ADM1026_REG_MASK1,mask & 0xff); 1341 adm1026_write_value(client, ADM1026_REG_MASK1,mask & 0xff);
1342 up(&data->update_lock); 1342 mutex_unlock(&data->update_lock);
1343 return count; 1343 return count;
1344} 1344}
1345 1345
@@ -1359,10 +1359,10 @@ static ssize_t set_pwm_reg(struct device *dev, struct device_attribute *attr, co
1359 if (data->pwm1.enable == 1) { 1359 if (data->pwm1.enable == 1) {
1360 int val = simple_strtol(buf, NULL, 10); 1360 int val = simple_strtol(buf, NULL, 10);
1361 1361
1362 down(&data->update_lock); 1362 mutex_lock(&data->update_lock);
1363 data->pwm1.pwm = PWM_TO_REG(val); 1363 data->pwm1.pwm = PWM_TO_REG(val);
1364 adm1026_write_value(client, ADM1026_REG_PWM, data->pwm1.pwm); 1364 adm1026_write_value(client, ADM1026_REG_PWM, data->pwm1.pwm);
1365 up(&data->update_lock); 1365 mutex_unlock(&data->update_lock);
1366 } 1366 }
1367 return count; 1367 return count;
1368} 1368}
@@ -1378,14 +1378,14 @@ static ssize_t set_auto_pwm_min(struct device *dev, struct device_attribute *att
1378 struct adm1026_data *data = i2c_get_clientdata(client); 1378 struct adm1026_data *data = i2c_get_clientdata(client);
1379 int val = simple_strtol(buf, NULL, 10); 1379 int val = simple_strtol(buf, NULL, 10);
1380 1380
1381 down(&data->update_lock); 1381 mutex_lock(&data->update_lock);
1382 data->pwm1.auto_pwm_min = SENSORS_LIMIT(val,0,255); 1382 data->pwm1.auto_pwm_min = SENSORS_LIMIT(val,0,255);
1383 if (data->pwm1.enable == 2) { /* apply immediately */ 1383 if (data->pwm1.enable == 2) { /* apply immediately */
1384 data->pwm1.pwm = PWM_TO_REG((data->pwm1.pwm & 0x0f) | 1384 data->pwm1.pwm = PWM_TO_REG((data->pwm1.pwm & 0x0f) |
1385 PWM_MIN_TO_REG(data->pwm1.auto_pwm_min)); 1385 PWM_MIN_TO_REG(data->pwm1.auto_pwm_min));
1386 adm1026_write_value(client, ADM1026_REG_PWM, data->pwm1.pwm); 1386 adm1026_write_value(client, ADM1026_REG_PWM, data->pwm1.pwm);
1387 } 1387 }
1388 up(&data->update_lock); 1388 mutex_unlock(&data->update_lock);
1389 return count; 1389 return count;
1390} 1390}
1391static ssize_t show_auto_pwm_max(struct device *dev, struct device_attribute *attr, char *buf) 1391static ssize_t show_auto_pwm_max(struct device *dev, struct device_attribute *attr, char *buf)
@@ -1406,7 +1406,7 @@ static ssize_t set_pwm_enable(struct device *dev, struct device_attribute *attr,
1406 int old_enable; 1406 int old_enable;
1407 1407
1408 if ((val >= 0) && (val < 3)) { 1408 if ((val >= 0) && (val < 3)) {
1409 down(&data->update_lock); 1409 mutex_lock(&data->update_lock);
1410 old_enable = data->pwm1.enable; 1410 old_enable = data->pwm1.enable;
1411 data->pwm1.enable = val; 1411 data->pwm1.enable = val;
1412 data->config1 = (data->config1 & ~CFG1_PWM_AFC) 1412 data->config1 = (data->config1 & ~CFG1_PWM_AFC)
@@ -1424,7 +1424,7 @@ static ssize_t set_pwm_enable(struct device *dev, struct device_attribute *attr,
1424 adm1026_write_value(client, ADM1026_REG_PWM, 1424 adm1026_write_value(client, ADM1026_REG_PWM,
1425 data->pwm1.pwm); 1425 data->pwm1.pwm);
1426 } 1426 }
1427 up(&data->update_lock); 1427 mutex_unlock(&data->update_lock);
1428 } 1428 }
1429 return count; 1429 return count;
1430} 1430}
@@ -1541,7 +1541,7 @@ static int adm1026_detect(struct i2c_adapter *adapter, int address,
1541 /* Fill in the remaining client fields */ 1541 /* Fill in the remaining client fields */
1542 data->type = kind; 1542 data->type = kind;
1543 data->valid = 0; 1543 data->valid = 0;
1544 init_MUTEX(&data->update_lock); 1544 mutex_init(&data->update_lock);
1545 1545
1546 /* Tell the I2C layer a new client has arrived */ 1546 /* Tell the I2C layer a new client has arrived */
1547 if ((err = i2c_attach_client(new_client))) 1547 if ((err = i2c_attach_client(new_client)))
diff --git a/drivers/hwmon/adm1031.c b/drivers/hwmon/adm1031.c
index d063979660..3bf2da621a 100644
--- a/drivers/hwmon/adm1031.c
+++ b/drivers/hwmon/adm1031.c
@@ -28,6 +28,7 @@
28#include <linux/i2c.h> 28#include <linux/i2c.h>
29#include <linux/hwmon.h> 29#include <linux/hwmon.h>
30#include <linux/err.h> 30#include <linux/err.h>
31#include <linux/mutex.h>
31 32
32/* Following macros takes channel parameter starting from 0 to 2 */ 33/* Following macros takes channel parameter starting from 0 to 2 */
33#define ADM1031_REG_FAN_SPEED(nr) (0x08 + (nr)) 34#define ADM1031_REG_FAN_SPEED(nr) (0x08 + (nr))
@@ -70,7 +71,7 @@ typedef u8 auto_chan_table_t[8][2];
70struct adm1031_data { 71struct adm1031_data {
71 struct i2c_client client; 72 struct i2c_client client;
72 struct class_device *class_dev; 73 struct class_device *class_dev;
73 struct semaphore update_lock; 74 struct mutex update_lock;
74 int chip_type; 75 int chip_type;
75 char valid; /* !=0 if following fields are valid */ 76 char valid; /* !=0 if following fields are valid */
76 unsigned long last_updated; /* In jiffies */ 77 unsigned long last_updated; /* In jiffies */
@@ -262,10 +263,10 @@ set_fan_auto_channel(struct device *dev, const char *buf, size_t count, int nr)
262 263
263 old_fan_mode = data->conf1; 264 old_fan_mode = data->conf1;
264 265
265 down(&data->update_lock); 266 mutex_lock(&data->update_lock);
266 267
267 if ((ret = get_fan_auto_nearest(data, nr, val, data->conf1, &reg))) { 268 if ((ret = get_fan_auto_nearest(data, nr, val, data->conf1, &reg))) {
268 up(&data->update_lock); 269 mutex_unlock(&data->update_lock);
269 return ret; 270 return ret;
270 } 271 }
271 if (((data->conf1 = FAN_CHAN_TO_REG(reg, data->conf1)) & ADM1031_CONF1_AUTO_MODE) ^ 272 if (((data->conf1 = FAN_CHAN_TO_REG(reg, data->conf1)) & ADM1031_CONF1_AUTO_MODE) ^
@@ -288,7 +289,7 @@ set_fan_auto_channel(struct device *dev, const char *buf, size_t count, int nr)
288 } 289 }
289 data->conf1 = FAN_CHAN_TO_REG(reg, data->conf1); 290 data->conf1 = FAN_CHAN_TO_REG(reg, data->conf1);
290 adm1031_write_value(client, ADM1031_REG_CONF1, data->conf1); 291 adm1031_write_value(client, ADM1031_REG_CONF1, data->conf1);
291 up(&data->update_lock); 292 mutex_unlock(&data->update_lock);
292 return count; 293 return count;
293} 294}
294 295
@@ -329,11 +330,11 @@ set_auto_temp_min(struct device *dev, const char *buf, size_t count, int nr)
329 struct adm1031_data *data = i2c_get_clientdata(client); 330 struct adm1031_data *data = i2c_get_clientdata(client);
330 int val = simple_strtol(buf, NULL, 10); 331 int val = simple_strtol(buf, NULL, 10);
331 332
332 down(&data->update_lock); 333 mutex_lock(&data->update_lock);
333 data->auto_temp[nr] = AUTO_TEMP_MIN_TO_REG(val, data->auto_temp[nr]); 334 data->auto_temp[nr] = AUTO_TEMP_MIN_TO_REG(val, data->auto_temp[nr]);
334 adm1031_write_value(client, ADM1031_REG_AUTO_TEMP(nr), 335 adm1031_write_value(client, ADM1031_REG_AUTO_TEMP(nr),
335 data->auto_temp[nr]); 336 data->auto_temp[nr]);
336 up(&data->update_lock); 337 mutex_unlock(&data->update_lock);
337 return count; 338 return count;
338} 339}
339static ssize_t show_auto_temp_max(struct device *dev, char *buf, int nr) 340static ssize_t show_auto_temp_max(struct device *dev, char *buf, int nr)
@@ -349,11 +350,11 @@ set_auto_temp_max(struct device *dev, const char *buf, size_t count, int nr)
349 struct adm1031_data *data = i2c_get_clientdata(client); 350 struct adm1031_data *data = i2c_get_clientdata(client);
350 int val = simple_strtol(buf, NULL, 10); 351 int val = simple_strtol(buf, NULL, 10);
351 352
352 down(&data->update_lock); 353 mutex_lock(&data->update_lock);
353 data->temp_max[nr] = AUTO_TEMP_MAX_TO_REG(val, data->auto_temp[nr], data->pwm[nr]); 354 data->temp_max[nr] = AUTO_TEMP_MAX_TO_REG(val, data->auto_temp[nr], data->pwm[nr]);
354 adm1031_write_value(client, ADM1031_REG_AUTO_TEMP(nr), 355 adm1031_write_value(client, ADM1031_REG_AUTO_TEMP(nr),
355 data->temp_max[nr]); 356 data->temp_max[nr]);
356 up(&data->update_lock); 357 mutex_unlock(&data->update_lock);
357 return count; 358 return count;
358} 359}
359 360
@@ -405,11 +406,11 @@ set_pwm(struct device *dev, const char *buf, size_t count, int nr)
405 int val = simple_strtol(buf, NULL, 10); 406 int val = simple_strtol(buf, NULL, 10);
406 int reg; 407 int reg;
407 408
408 down(&data->update_lock); 409 mutex_lock(&data->update_lock);
409 if ((data->conf1 & ADM1031_CONF1_AUTO_MODE) && 410 if ((data->conf1 & ADM1031_CONF1_AUTO_MODE) &&
410 (((val>>4) & 0xf) != 5)) { 411 (((val>>4) & 0xf) != 5)) {
411 /* In automatic mode, the only PWM accepted is 33% */ 412 /* In automatic mode, the only PWM accepted is 33% */
412 up(&data->update_lock); 413 mutex_unlock(&data->update_lock);
413 return -EINVAL; 414 return -EINVAL;
414 } 415 }
415 data->pwm[nr] = PWM_TO_REG(val); 416 data->pwm[nr] = PWM_TO_REG(val);
@@ -417,7 +418,7 @@ set_pwm(struct device *dev, const char *buf, size_t count, int nr)
417 adm1031_write_value(client, ADM1031_REG_PWM, 418 adm1031_write_value(client, ADM1031_REG_PWM,
418 nr ? ((data->pwm[nr] << 4) & 0xf0) | (reg & 0xf) 419 nr ? ((data->pwm[nr] << 4) & 0xf0) | (reg & 0xf)
419 : (data->pwm[nr] & 0xf) | (reg & 0xf0)); 420 : (data->pwm[nr] & 0xf) | (reg & 0xf0));
420 up(&data->update_lock); 421 mutex_unlock(&data->update_lock);
421 return count; 422 return count;
422} 423}
423 424
@@ -511,7 +512,7 @@ set_fan_min(struct device *dev, const char *buf, size_t count, int nr)
511 struct adm1031_data *data = i2c_get_clientdata(client); 512 struct adm1031_data *data = i2c_get_clientdata(client);
512 int val = simple_strtol(buf, NULL, 10); 513 int val = simple_strtol(buf, NULL, 10);
513 514
514 down(&data->update_lock); 515 mutex_lock(&data->update_lock);
515 if (val) { 516 if (val) {
516 data->fan_min[nr] = 517 data->fan_min[nr] =
517 FAN_TO_REG(val, FAN_DIV_FROM_REG(data->fan_div[nr])); 518 FAN_TO_REG(val, FAN_DIV_FROM_REG(data->fan_div[nr]));
@@ -519,7 +520,7 @@ set_fan_min(struct device *dev, const char *buf, size_t count, int nr)
519 data->fan_min[nr] = 0xff; 520 data->fan_min[nr] = 0xff;
520 } 521 }
521 adm1031_write_value(client, ADM1031_REG_FAN_MIN(nr), data->fan_min[nr]); 522 adm1031_write_value(client, ADM1031_REG_FAN_MIN(nr), data->fan_min[nr]);
522 up(&data->update_lock); 523 mutex_unlock(&data->update_lock);
523 return count; 524 return count;
524} 525}
525static ssize_t 526static ssize_t
@@ -540,7 +541,7 @@ set_fan_div(struct device *dev, const char *buf, size_t count, int nr)
540 if (tmp == 0xff) 541 if (tmp == 0xff)
541 return -EINVAL; 542 return -EINVAL;
542 543
543 down(&data->update_lock); 544 mutex_lock(&data->update_lock);
544 old_div = FAN_DIV_FROM_REG(data->fan_div[nr]); 545 old_div = FAN_DIV_FROM_REG(data->fan_div[nr]);
545 data->fan_div[nr] = (tmp & 0xC0) | (0x3f & data->fan_div[nr]); 546 data->fan_div[nr] = (tmp & 0xC0) | (0x3f & data->fan_div[nr]);
546 new_min = data->fan_min[nr] * old_div / 547 new_min = data->fan_min[nr] * old_div /
@@ -553,7 +554,7 @@ set_fan_div(struct device *dev, const char *buf, size_t count, int nr)
553 data->fan_div[nr]); 554 data->fan_div[nr]);
554 adm1031_write_value(client, ADM1031_REG_FAN_MIN(nr), 555 adm1031_write_value(client, ADM1031_REG_FAN_MIN(nr),
555 data->fan_min[nr]); 556 data->fan_min[nr]);
556 up(&data->update_lock); 557 mutex_unlock(&data->update_lock);
557 return count; 558 return count;
558} 559}
559 560
@@ -627,11 +628,11 @@ set_temp_min(struct device *dev, const char *buf, size_t count, int nr)
627 628
628 val = simple_strtol(buf, NULL, 10); 629 val = simple_strtol(buf, NULL, 10);
629 val = SENSORS_LIMIT(val, -55000, nr == 0 ? 127750 : 127875); 630 val = SENSORS_LIMIT(val, -55000, nr == 0 ? 127750 : 127875);
630 down(&data->update_lock); 631 mutex_lock(&data->update_lock);
631 data->temp_min[nr] = TEMP_TO_REG(val); 632 data->temp_min[nr] = TEMP_TO_REG(val);
632 adm1031_write_value(client, ADM1031_REG_TEMP_MIN(nr), 633 adm1031_write_value(client, ADM1031_REG_TEMP_MIN(nr),
633 data->temp_min[nr]); 634 data->temp_min[nr]);
634 up(&data->update_lock); 635 mutex_unlock(&data->update_lock);
635 return count; 636 return count;
636} 637}
637static ssize_t 638static ssize_t
@@ -643,11 +644,11 @@ set_temp_max(struct device *dev, const char *buf, size_t count, int nr)
643 644
644 val = simple_strtol(buf, NULL, 10); 645 val = simple_strtol(buf, NULL, 10);
645 val = SENSORS_LIMIT(val, -55000, nr == 0 ? 127750 : 127875); 646 val = SENSORS_LIMIT(val, -55000, nr == 0 ? 127750 : 127875);
646 down(&data->update_lock); 647 mutex_lock(&data->update_lock);
647 data->temp_max[nr] = TEMP_TO_REG(val); 648 data->temp_max[nr] = TEMP_TO_REG(val);
648 adm1031_write_value(client, ADM1031_REG_TEMP_MAX(nr), 649 adm1031_write_value(client, ADM1031_REG_TEMP_MAX(nr),
649 data->temp_max[nr]); 650 data->temp_max[nr]);
650 up(&data->update_lock); 651 mutex_unlock(&data->update_lock);
651 return count; 652 return count;
652} 653}
653static ssize_t 654static ssize_t
@@ -659,11 +660,11 @@ set_temp_crit(struct device *dev, const char *buf, size_t count, int nr)
659 660
660 val = simple_strtol(buf, NULL, 10); 661 val = simple_strtol(buf, NULL, 10);
661 val = SENSORS_LIMIT(val, -55000, nr == 0 ? 127750 : 127875); 662 val = SENSORS_LIMIT(val, -55000, nr == 0 ? 127750 : 127875);
662 down(&data->update_lock); 663 mutex_lock(&data->update_lock);
663 data->temp_crit[nr] = TEMP_TO_REG(val); 664 data->temp_crit[nr] = TEMP_TO_REG(val);
664 adm1031_write_value(client, ADM1031_REG_TEMP_CRIT(nr), 665 adm1031_write_value(client, ADM1031_REG_TEMP_CRIT(nr),
665 data->temp_crit[nr]); 666 data->temp_crit[nr]);
666 up(&data->update_lock); 667 mutex_unlock(&data->update_lock);
667 return count; 668 return count;
668} 669}
669 670
@@ -778,7 +779,7 @@ static int adm1031_detect(struct i2c_adapter *adapter, int address, int kind)
778 779
779 strlcpy(new_client->name, name, I2C_NAME_SIZE); 780 strlcpy(new_client->name, name, I2C_NAME_SIZE);
780 data->valid = 0; 781 data->valid = 0;
781 init_MUTEX(&data->update_lock); 782 mutex_init(&data->update_lock);
782 783
783 /* Tell the I2C layer a new client has arrived */ 784 /* Tell the I2C layer a new client has arrived */
784 if ((err = i2c_attach_client(new_client))) 785 if ((err = i2c_attach_client(new_client)))
@@ -891,7 +892,7 @@ static struct adm1031_data *adm1031_update_device(struct device *dev)
891 struct adm1031_data *data = i2c_get_clientdata(client); 892 struct adm1031_data *data = i2c_get_clientdata(client);
892 int chan; 893 int chan;
893 894
894 down(&data->update_lock); 895 mutex_lock(&data->update_lock);
895 896
896 if (time_after(jiffies, data->last_updated + HZ + HZ / 2) 897 if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
897 || !data->valid) { 898 || !data->valid) {
@@ -965,7 +966,7 @@ static struct adm1031_data *adm1031_update_device(struct device *dev)
965 data->valid = 1; 966 data->valid = 1;
966 } 967 }
967 968
968 up(&data->update_lock); 969 mutex_unlock(&data->update_lock);
969 970
970 return data; 971 return data;
971} 972}
diff --git a/drivers/hwmon/adm9240.c b/drivers/hwmon/adm9240.c
index 5ddc22fea4..43f6991b58 100644
--- a/drivers/hwmon/adm9240.c
+++ b/drivers/hwmon/adm9240.c
@@ -49,6 +49,7 @@
49#include <linux/hwmon.h> 49#include <linux/hwmon.h>
50#include <linux/hwmon-vid.h> 50#include <linux/hwmon-vid.h>
51#include <linux/err.h> 51#include <linux/err.h>
52#include <linux/mutex.h>
52 53
53/* Addresses to scan */ 54/* Addresses to scan */
54static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, 0x2f, 55static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, 0x2f,
@@ -150,7 +151,7 @@ struct adm9240_data {
150 enum chips type; 151 enum chips type;
151 struct i2c_client client; 152 struct i2c_client client;
152 struct class_device *class_dev; 153 struct class_device *class_dev;
153 struct semaphore update_lock; 154 struct mutex update_lock;
154 char valid; 155 char valid;
155 unsigned long last_updated_measure; 156 unsigned long last_updated_measure;
156 unsigned long last_updated_config; 157 unsigned long last_updated_config;
@@ -195,11 +196,11 @@ static ssize_t set_max(struct device *dev, struct device_attribute *devattr,
195 struct adm9240_data *data = i2c_get_clientdata(client); 196 struct adm9240_data *data = i2c_get_clientdata(client);
196 long val = simple_strtol(buf, NULL, 10); 197 long val = simple_strtol(buf, NULL, 10);
197 198
198 down(&data->update_lock); 199 mutex_lock(&data->update_lock);
199 data->temp_max[attr->index] = TEMP_TO_REG(val); 200 data->temp_max[attr->index] = TEMP_TO_REG(val);
200 i2c_smbus_write_byte_data(client, ADM9240_REG_TEMP_MAX(attr->index), 201 i2c_smbus_write_byte_data(client, ADM9240_REG_TEMP_MAX(attr->index),
201 data->temp_max[attr->index]); 202 data->temp_max[attr->index]);
202 up(&data->update_lock); 203 mutex_unlock(&data->update_lock);
203 return count; 204 return count;
204} 205}
205 206
@@ -246,11 +247,11 @@ static ssize_t set_in_min(struct device *dev,
246 struct adm9240_data *data = i2c_get_clientdata(client); 247 struct adm9240_data *data = i2c_get_clientdata(client);
247 unsigned long val = simple_strtoul(buf, NULL, 10); 248 unsigned long val = simple_strtoul(buf, NULL, 10);
248 249
249 down(&data->update_lock); 250 mutex_lock(&data->update_lock);
250 data->in_min[attr->index] = IN_TO_REG(val, attr->index); 251 data->in_min[attr->index] = IN_TO_REG(val, attr->index);
251 i2c_smbus_write_byte_data(client, ADM9240_REG_IN_MIN(attr->index), 252 i2c_smbus_write_byte_data(client, ADM9240_REG_IN_MIN(attr->index),
252 data->in_min[attr->index]); 253 data->in_min[attr->index]);
253 up(&data->update_lock); 254 mutex_unlock(&data->update_lock);
254 return count; 255 return count;
255} 256}
256 257
@@ -263,11 +264,11 @@ static ssize_t set_in_max(struct device *dev,
263 struct adm9240_data *data = i2c_get_clientdata(client); 264 struct adm9240_data *data = i2c_get_clientdata(client);
264 unsigned long val = simple_strtoul(buf, NULL, 10); 265 unsigned long val = simple_strtoul(buf, NULL, 10);
265 266
266 down(&data->update_lock); 267 mutex_lock(&data->update_lock);
267 data->in_max[attr->index] = IN_TO_REG(val, attr->index); 268 data->in_max[attr->index] = IN_TO_REG(val, attr->index);
268 i2c_smbus_write_byte_data(client, ADM9240_REG_IN_MAX(attr->index), 269 i2c_smbus_write_byte_data(client, ADM9240_REG_IN_MAX(attr->index),
269 data->in_max[attr->index]); 270 data->in_max[attr->index]);
270 up(&data->update_lock); 271 mutex_unlock(&data->update_lock);
271 return count; 272 return count;
272} 273}
273 274
@@ -350,7 +351,7 @@ static ssize_t set_fan_min(struct device *dev,
350 int nr = attr->index; 351 int nr = attr->index;
351 u8 new_div; 352 u8 new_div;
352 353
353 down(&data->update_lock); 354 mutex_lock(&data->update_lock);
354 355
355 if (!val) { 356 if (!val) {
356 data->fan_min[nr] = 255; 357 data->fan_min[nr] = 255;
@@ -390,7 +391,7 @@ static ssize_t set_fan_min(struct device *dev,
390 i2c_smbus_write_byte_data(client, ADM9240_REG_FAN_MIN(nr), 391 i2c_smbus_write_byte_data(client, ADM9240_REG_FAN_MIN(nr),
391 data->fan_min[nr]); 392 data->fan_min[nr]);
392 393
393 up(&data->update_lock); 394 mutex_unlock(&data->update_lock);
394 return count; 395 return count;
395} 396}
396 397
@@ -439,10 +440,10 @@ static ssize_t set_aout(struct device *dev,
439 struct adm9240_data *data = i2c_get_clientdata(client); 440 struct adm9240_data *data = i2c_get_clientdata(client);
440 unsigned long val = simple_strtol(buf, NULL, 10); 441 unsigned long val = simple_strtol(buf, NULL, 10);
441 442
442 down(&data->update_lock); 443 mutex_lock(&data->update_lock);
443 data->aout = AOUT_TO_REG(val); 444 data->aout = AOUT_TO_REG(val);
444 i2c_smbus_write_byte_data(client, ADM9240_REG_ANALOG_OUT, data->aout); 445 i2c_smbus_write_byte_data(client, ADM9240_REG_ANALOG_OUT, data->aout);
445 up(&data->update_lock); 446 mutex_unlock(&data->update_lock);
446 return count; 447 return count;
447} 448}
448static DEVICE_ATTR(aout_output, S_IRUGO | S_IWUSR, show_aout, set_aout); 449static DEVICE_ATTR(aout_output, S_IRUGO | S_IWUSR, show_aout, set_aout);
@@ -539,7 +540,7 @@ static int adm9240_detect(struct i2c_adapter *adapter, int address, int kind)
539 /* fill in the remaining client fields and attach */ 540 /* fill in the remaining client fields and attach */
540 strlcpy(new_client->name, name, I2C_NAME_SIZE); 541 strlcpy(new_client->name, name, I2C_NAME_SIZE);
541 data->type = kind; 542 data->type = kind;
542 init_MUTEX(&data->update_lock); 543 mutex_init(&data->update_lock);
543 544
544 if ((err = i2c_attach_client(new_client))) 545 if ((err = i2c_attach_client(new_client)))
545 goto exit_free; 546 goto exit_free;
@@ -691,7 +692,7 @@ static struct adm9240_data *adm9240_update_device(struct device *dev)
691 struct adm9240_data *data = i2c_get_clientdata(client); 692 struct adm9240_data *data = i2c_get_clientdata(client);
692 int i; 693 int i;
693 694
694 down(&data->update_lock); 695 mutex_lock(&data->update_lock);
695 696
696 /* minimum measurement cycle: 1.75 seconds */ 697 /* minimum measurement cycle: 1.75 seconds */
697 if (time_after(jiffies, data->last_updated_measure + (HZ * 7 / 4)) 698 if (time_after(jiffies, data->last_updated_measure + (HZ * 7 / 4))
@@ -771,7 +772,7 @@ static struct adm9240_data *adm9240_update_device(struct device *dev)
771 data->last_updated_config = jiffies; 772 data->last_updated_config = jiffies;
772 data->valid = 1; 773 data->valid = 1;
773 } 774 }
774 up(&data->update_lock); 775 mutex_unlock(&data->update_lock);
775 return data; 776 return data;
776} 777}
777 778
diff --git a/drivers/hwmon/asb100.c b/drivers/hwmon/asb100.c
index ae9de63cf2..65b2709f75 100644
--- a/drivers/hwmon/asb100.c
+++ b/drivers/hwmon/asb100.c
@@ -44,6 +44,7 @@
44#include <linux/err.h> 44#include <linux/err.h>
45#include <linux/init.h> 45#include <linux/init.h>
46#include <linux/jiffies.h> 46#include <linux/jiffies.h>
47#include <linux/mutex.h>
47#include "lm75.h" 48#include "lm75.h"
48 49
49/* 50/*
@@ -182,10 +183,10 @@ static u8 DIV_TO_REG(long val)
182struct asb100_data { 183struct asb100_data {
183 struct i2c_client client; 184 struct i2c_client client;
184 struct class_device *class_dev; 185 struct class_device *class_dev;
185 struct semaphore lock; 186 struct mutex lock;
186 enum chips type; 187 enum chips type;
187 188
188 struct semaphore update_lock; 189 struct mutex update_lock;
189 unsigned long last_updated; /* In jiffies */ 190 unsigned long last_updated; /* In jiffies */
190 191
191 /* array of 2 pointers to subclients */ 192 /* array of 2 pointers to subclients */
@@ -245,11 +246,11 @@ static ssize_t set_in_##reg(struct device *dev, const char *buf, \
245 struct asb100_data *data = i2c_get_clientdata(client); \ 246 struct asb100_data *data = i2c_get_clientdata(client); \
246 unsigned long val = simple_strtoul(buf, NULL, 10); \ 247 unsigned long val = simple_strtoul(buf, NULL, 10); \
247 \ 248 \
248 down(&data->update_lock); \ 249 mutex_lock(&data->update_lock); \
249 data->in_##reg[nr] = IN_TO_REG(val); \ 250 data->in_##reg[nr] = IN_TO_REG(val); \
250 asb100_write_value(client, ASB100_REG_IN_##REG(nr), \ 251 asb100_write_value(client, ASB100_REG_IN_##REG(nr), \
251 data->in_##reg[nr]); \ 252 data->in_##reg[nr]); \
252 up(&data->update_lock); \ 253 mutex_unlock(&data->update_lock); \
253 return count; \ 254 return count; \
254} 255}
255 256
@@ -331,10 +332,10 @@ static ssize_t set_fan_min(struct device *dev, const char *buf,
331 struct asb100_data *data = i2c_get_clientdata(client); 332 struct asb100_data *data = i2c_get_clientdata(client);
332 u32 val = simple_strtoul(buf, NULL, 10); 333 u32 val = simple_strtoul(buf, NULL, 10);
333 334
334 down(&data->update_lock); 335 mutex_lock(&data->update_lock);
335 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); 336 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
336 asb100_write_value(client, ASB100_REG_FAN_MIN(nr), data->fan_min[nr]); 337 asb100_write_value(client, ASB100_REG_FAN_MIN(nr), data->fan_min[nr]);
337 up(&data->update_lock); 338 mutex_unlock(&data->update_lock);
338 return count; 339 return count;
339} 340}
340 341
@@ -351,7 +352,7 @@ static ssize_t set_fan_div(struct device *dev, const char *buf,
351 unsigned long val = simple_strtoul(buf, NULL, 10); 352 unsigned long val = simple_strtoul(buf, NULL, 10);
352 int reg; 353 int reg;
353 354
354 down(&data->update_lock); 355 mutex_lock(&data->update_lock);
355 356
356 min = FAN_FROM_REG(data->fan_min[nr], 357 min = FAN_FROM_REG(data->fan_min[nr],
357 DIV_FROM_REG(data->fan_div[nr])); 358 DIV_FROM_REG(data->fan_div[nr]));
@@ -381,7 +382,7 @@ static ssize_t set_fan_div(struct device *dev, const char *buf,
381 FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr])); 382 FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr]));
382 asb100_write_value(client, ASB100_REG_FAN_MIN(nr), data->fan_min[nr]); 383 asb100_write_value(client, ASB100_REG_FAN_MIN(nr), data->fan_min[nr]);
383 384
384 up(&data->update_lock); 385 mutex_unlock(&data->update_lock);
385 386
386 return count; 387 return count;
387} 388}
@@ -461,7 +462,7 @@ static ssize_t set_##reg(struct device *dev, const char *buf, \
461 struct asb100_data *data = i2c_get_clientdata(client); \ 462 struct asb100_data *data = i2c_get_clientdata(client); \
462 unsigned long val = simple_strtoul(buf, NULL, 10); \ 463 unsigned long val = simple_strtoul(buf, NULL, 10); \
463 \ 464 \
464 down(&data->update_lock); \ 465 mutex_lock(&data->update_lock); \
465 switch (nr) { \ 466 switch (nr) { \
466 case 1: case 2: \ 467 case 1: case 2: \
467 data->reg[nr] = LM75_TEMP_TO_REG(val); \ 468 data->reg[nr] = LM75_TEMP_TO_REG(val); \
@@ -472,7 +473,7 @@ static ssize_t set_##reg(struct device *dev, const char *buf, \
472 } \ 473 } \
473 asb100_write_value(client, ASB100_REG_TEMP_##REG(nr+1), \ 474 asb100_write_value(client, ASB100_REG_TEMP_##REG(nr+1), \
474 data->reg[nr]); \ 475 data->reg[nr]); \
475 up(&data->update_lock); \ 476 mutex_unlock(&data->update_lock); \
476 return count; \ 477 return count; \
477} 478}
478 479
@@ -574,11 +575,11 @@ static ssize_t set_pwm1(struct device *dev, struct device_attribute *attr, const
574 struct asb100_data *data = i2c_get_clientdata(client); 575 struct asb100_data *data = i2c_get_clientdata(client);
575 unsigned long val = simple_strtoul(buf, NULL, 10); 576 unsigned long val = simple_strtoul(buf, NULL, 10);
576 577
577 down(&data->update_lock); 578 mutex_lock(&data->update_lock);
578 data->pwm &= 0x80; /* keep the enable bit */ 579 data->pwm &= 0x80; /* keep the enable bit */
579 data->pwm |= (0x0f & ASB100_PWM_TO_REG(val)); 580 data->pwm |= (0x0f & ASB100_PWM_TO_REG(val));
580 asb100_write_value(client, ASB100_REG_PWM1, data->pwm); 581 asb100_write_value(client, ASB100_REG_PWM1, data->pwm);
581 up(&data->update_lock); 582 mutex_unlock(&data->update_lock);
582 return count; 583 return count;
583} 584}
584 585
@@ -595,11 +596,11 @@ static ssize_t set_pwm_enable1(struct device *dev, struct device_attribute *attr
595 struct asb100_data *data = i2c_get_clientdata(client); 596 struct asb100_data *data = i2c_get_clientdata(client);
596 unsigned long val = simple_strtoul(buf, NULL, 10); 597 unsigned long val = simple_strtoul(buf, NULL, 10);
597 598
598 down(&data->update_lock); 599 mutex_lock(&data->update_lock);
599 data->pwm &= 0x0f; /* keep the duty cycle bits */ 600 data->pwm &= 0x0f; /* keep the duty cycle bits */
600 data->pwm |= (val ? 0x80 : 0x00); 601 data->pwm |= (val ? 0x80 : 0x00);
601 asb100_write_value(client, ASB100_REG_PWM1, data->pwm); 602 asb100_write_value(client, ASB100_REG_PWM1, data->pwm);
602 up(&data->update_lock); 603 mutex_unlock(&data->update_lock);
603 return count; 604 return count;
604} 605}
605 606
@@ -729,7 +730,7 @@ static int asb100_detect(struct i2c_adapter *adapter, int address, int kind)
729 } 730 }
730 731
731 new_client = &data->client; 732 new_client = &data->client;
732 init_MUTEX(&data->lock); 733 mutex_init(&data->lock);
733 i2c_set_clientdata(new_client, data); 734 i2c_set_clientdata(new_client, data);
734 new_client->addr = address; 735 new_client->addr = address;
735 new_client->adapter = adapter; 736 new_client->adapter = adapter;
@@ -789,7 +790,7 @@ static int asb100_detect(struct i2c_adapter *adapter, int address, int kind)
789 data->type = kind; 790 data->type = kind;
790 791
791 data->valid = 0; 792 data->valid = 0;
792 init_MUTEX(&data->update_lock); 793 mutex_init(&data->update_lock);
793 794
794 /* Tell the I2C layer a new client has arrived */ 795 /* Tell the I2C layer a new client has arrived */
795 if ((err = i2c_attach_client(new_client))) 796 if ((err = i2c_attach_client(new_client)))
@@ -885,7 +886,7 @@ static int asb100_read_value(struct i2c_client *client, u16 reg)
885 struct i2c_client *cl; 886 struct i2c_client *cl;
886 int res, bank; 887 int res, bank;
887 888
888 down(&data->lock); 889 mutex_lock(&data->lock);
889 890
890 bank = (reg >> 8) & 0x0f; 891 bank = (reg >> 8) & 0x0f;
891 if (bank > 2) 892 if (bank > 2)
@@ -919,7 +920,7 @@ static int asb100_read_value(struct i2c_client *client, u16 reg)
919 if (bank > 2) 920 if (bank > 2)
920 i2c_smbus_write_byte_data(client, ASB100_REG_BANK, 0); 921 i2c_smbus_write_byte_data(client, ASB100_REG_BANK, 0);
921 922
922 up(&data->lock); 923 mutex_unlock(&data->lock);
923 924
924 return res; 925 return res;
925} 926}
@@ -930,7 +931,7 @@ static void asb100_write_value(struct i2c_client *client, u16 reg, u16 value)
930 struct i2c_client *cl; 931 struct i2c_client *cl;
931 int bank; 932 int bank;
932 933
933 down(&data->lock); 934 mutex_lock(&data->lock);
934 935
935 bank = (reg >> 8) & 0x0f; 936 bank = (reg >> 8) & 0x0f;
936 if (bank > 2) 937 if (bank > 2)
@@ -960,7 +961,7 @@ static void asb100_write_value(struct i2c_client *client, u16 reg, u16 value)
960 if (bank > 2) 961 if (bank > 2)
961 i2c_smbus_write_byte_data(client, ASB100_REG_BANK, 0); 962 i2c_smbus_write_byte_data(client, ASB100_REG_BANK, 0);
962 963
963 up(&data->lock); 964 mutex_unlock(&data->lock);
964} 965}
965 966
966static void asb100_init_client(struct i2c_client *client) 967static void asb100_init_client(struct i2c_client *client)
@@ -984,7 +985,7 @@ static struct asb100_data *asb100_update_device(struct device *dev)
984 struct asb100_data *data = i2c_get_clientdata(client); 985 struct asb100_data *data = i2c_get_clientdata(client);
985 int i; 986 int i;
986 987
987 down(&data->update_lock); 988 mutex_lock(&data->update_lock);
988 989
989 if (time_after(jiffies, data->last_updated + HZ + HZ / 2) 990 if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
990 || !data->valid) { 991 || !data->valid) {
@@ -1042,7 +1043,7 @@ static struct asb100_data *asb100_update_device(struct device *dev)
1042 dev_dbg(&client->dev, "... device update complete\n"); 1043 dev_dbg(&client->dev, "... device update complete\n");
1043 } 1044 }
1044 1045
1045 up(&data->update_lock); 1046 mutex_unlock(&data->update_lock);
1046 1047
1047 return data; 1048 return data;
1048} 1049}
diff --git a/drivers/hwmon/atxp1.c b/drivers/hwmon/atxp1.c
index b0c490073c..728a1e8b91 100644
--- a/drivers/hwmon/atxp1.c
+++ b/drivers/hwmon/atxp1.c
@@ -26,6 +26,7 @@
26#include <linux/hwmon.h> 26#include <linux/hwmon.h>
27#include <linux/hwmon-vid.h> 27#include <linux/hwmon-vid.h>
28#include <linux/err.h> 28#include <linux/err.h>
29#include <linux/mutex.h>
29 30
30MODULE_LICENSE("GPL"); 31MODULE_LICENSE("GPL");
31MODULE_DESCRIPTION("System voltages control via Attansic ATXP1"); 32MODULE_DESCRIPTION("System voltages control via Attansic ATXP1");
@@ -60,7 +61,7 @@ static struct i2c_driver atxp1_driver = {
60struct atxp1_data { 61struct atxp1_data {
61 struct i2c_client client; 62 struct i2c_client client;
62 struct class_device *class_dev; 63 struct class_device *class_dev;
63 struct semaphore update_lock; 64 struct mutex update_lock;
64 unsigned long last_updated; 65 unsigned long last_updated;
65 u8 valid; 66 u8 valid;
66 struct { 67 struct {
@@ -80,7 +81,7 @@ static struct atxp1_data * atxp1_update_device(struct device *dev)
80 client = to_i2c_client(dev); 81 client = to_i2c_client(dev);
81 data = i2c_get_clientdata(client); 82 data = i2c_get_clientdata(client);
82 83
83 down(&data->update_lock); 84 mutex_lock(&data->update_lock);
84 85
85 if (time_after(jiffies, data->last_updated + HZ) || !data->valid) { 86 if (time_after(jiffies, data->last_updated + HZ) || !data->valid) {
86 87
@@ -93,7 +94,7 @@ static struct atxp1_data * atxp1_update_device(struct device *dev)
93 data->valid = 1; 94 data->valid = 1;
94 } 95 }
95 96
96 up(&data->update_lock); 97 mutex_unlock(&data->update_lock);
97 98
98 return(data); 99 return(data);
99} 100}
@@ -309,7 +310,7 @@ static int atxp1_detect(struct i2c_adapter *adapter, int address, int kind)
309 310
310 data->valid = 0; 311 data->valid = 0;
311 312
312 init_MUTEX(&data->update_lock); 313 mutex_init(&data->update_lock);
313 314
314 err = i2c_attach_client(new_client); 315 err = i2c_attach_client(new_client);
315 316
diff --git a/drivers/hwmon/ds1621.c b/drivers/hwmon/ds1621.c
index 203f9c7abb..478eb4bb85 100644
--- a/drivers/hwmon/ds1621.c
+++ b/drivers/hwmon/ds1621.c
@@ -28,6 +28,7 @@
28#include <linux/i2c.h> 28#include <linux/i2c.h>
29#include <linux/hwmon.h> 29#include <linux/hwmon.h>
30#include <linux/err.h> 30#include <linux/err.h>
31#include <linux/mutex.h>
31#include "lm75.h" 32#include "lm75.h"
32 33
33/* Addresses to scan */ 34/* Addresses to scan */
@@ -72,7 +73,7 @@ MODULE_PARM_DESC(polarity, "Output's polarity: 0 = active high, 1 = active low")
72struct ds1621_data { 73struct ds1621_data {
73 struct i2c_client client; 74 struct i2c_client client;
74 struct class_device *class_dev; 75 struct class_device *class_dev;
75 struct semaphore update_lock; 76 struct mutex update_lock;
76 char valid; /* !=0 if following fields are valid */ 77 char valid; /* !=0 if following fields are valid */
77 unsigned long last_updated; /* In jiffies */ 78 unsigned long last_updated; /* In jiffies */
78 79
@@ -156,10 +157,10 @@ static ssize_t set_temp_##suffix(struct device *dev, struct device_attribute *at
156 struct ds1621_data *data = ds1621_update_client(dev); \ 157 struct ds1621_data *data = ds1621_update_client(dev); \
157 u16 val = LM75_TEMP_TO_REG(simple_strtoul(buf, NULL, 10)); \ 158 u16 val = LM75_TEMP_TO_REG(simple_strtoul(buf, NULL, 10)); \
158 \ 159 \
159 down(&data->update_lock); \ 160 mutex_lock(&data->update_lock); \
160 data->value = val; \ 161 data->value = val; \
161 ds1621_write_value(client, reg, data->value); \ 162 ds1621_write_value(client, reg, data->value); \
162 up(&data->update_lock); \ 163 mutex_unlock(&data->update_lock); \
163 return count; \ 164 return count; \
164} 165}
165 166
@@ -242,7 +243,7 @@ static int ds1621_detect(struct i2c_adapter *adapter, int address,
242 /* Fill in remaining client fields and put it into the global list */ 243 /* Fill in remaining client fields and put it into the global list */
243 strlcpy(new_client->name, "ds1621", I2C_NAME_SIZE); 244 strlcpy(new_client->name, "ds1621", I2C_NAME_SIZE);
244 data->valid = 0; 245 data->valid = 0;
245 init_MUTEX(&data->update_lock); 246 mutex_init(&data->update_lock);
246 247
247 /* Tell the I2C layer a new client has arrived */ 248 /* Tell the I2C layer a new client has arrived */
248 if ((err = i2c_attach_client(new_client))) 249 if ((err = i2c_attach_client(new_client)))
@@ -297,7 +298,7 @@ static struct ds1621_data *ds1621_update_client(struct device *dev)
297 struct ds1621_data *data = i2c_get_clientdata(client); 298 struct ds1621_data *data = i2c_get_clientdata(client);
298 u8 new_conf; 299 u8 new_conf;
299 300
300 down(&data->update_lock); 301 mutex_lock(&data->update_lock);
301 302
302 if (time_after(jiffies, data->last_updated + HZ + HZ / 2) 303 if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
303 || !data->valid) { 304 || !data->valid) {
@@ -327,7 +328,7 @@ static struct ds1621_data *ds1621_update_client(struct device *dev)
327 data->valid = 1; 328 data->valid = 1;
328 } 329 }
329 330
330 up(&data->update_lock); 331 mutex_unlock(&data->update_lock);
331 332
332 return data; 333 return data;
333} 334}
diff --git a/drivers/hwmon/f71805f.c b/drivers/hwmon/f71805f.c
index e029e0a94e..885465df6e 100644
--- a/drivers/hwmon/f71805f.c
+++ b/drivers/hwmon/f71805f.c
@@ -30,6 +30,7 @@
30#include <linux/hwmon.h> 30#include <linux/hwmon.h>
31#include <linux/hwmon-sysfs.h> 31#include <linux/hwmon-sysfs.h>
32#include <linux/err.h> 32#include <linux/err.h>
33#include <linux/mutex.h>
33#include <asm/io.h> 34#include <asm/io.h>
34 35
35static struct platform_device *pdev; 36static struct platform_device *pdev;
@@ -131,10 +132,10 @@ static struct resource f71805f_resource __initdata = {
131struct f71805f_data { 132struct f71805f_data {
132 unsigned short addr; 133 unsigned short addr;
133 const char *name; 134 const char *name;
134 struct semaphore lock; 135 struct mutex lock;
135 struct class_device *class_dev; 136 struct class_device *class_dev;
136 137
137 struct semaphore update_lock; 138 struct mutex update_lock;
138 char valid; /* !=0 if following fields are valid */ 139 char valid; /* !=0 if following fields are valid */
139 unsigned long last_updated; /* In jiffies */ 140 unsigned long last_updated; /* In jiffies */
140 unsigned long last_limits; /* In jiffies */ 141 unsigned long last_limits; /* In jiffies */
@@ -224,20 +225,20 @@ static u8 f71805f_read8(struct f71805f_data *data, u8 reg)
224{ 225{
225 u8 val; 226 u8 val;
226 227
227 down(&data->lock); 228 mutex_lock(&data->lock);
228 outb(reg, data->addr + ADDR_REG_OFFSET); 229 outb(reg, data->addr + ADDR_REG_OFFSET);
229 val = inb(data->addr + DATA_REG_OFFSET); 230 val = inb(data->addr + DATA_REG_OFFSET);
230 up(&data->lock); 231 mutex_unlock(&data->lock);
231 232
232 return val; 233 return val;
233} 234}
234 235
235static void f71805f_write8(struct f71805f_data *data, u8 reg, u8 val) 236static void f71805f_write8(struct f71805f_data *data, u8 reg, u8 val)
236{ 237{
237 down(&data->lock); 238 mutex_lock(&data->lock);
238 outb(reg, data->addr + ADDR_REG_OFFSET); 239 outb(reg, data->addr + ADDR_REG_OFFSET);
239 outb(val, data->addr + DATA_REG_OFFSET); 240 outb(val, data->addr + DATA_REG_OFFSET);
240 up(&data->lock); 241 mutex_unlock(&data->lock);
241} 242}
242 243
243/* It is important to read the MSB first, because doing so latches the 244/* It is important to read the MSB first, because doing so latches the
@@ -246,24 +247,24 @@ static u16 f71805f_read16(struct f71805f_data *data, u8 reg)
246{ 247{
247 u16 val; 248 u16 val;
248 249
249 down(&data->lock); 250 mutex_lock(&data->lock);
250 outb(reg, data->addr + ADDR_REG_OFFSET); 251 outb(reg, data->addr + ADDR_REG_OFFSET);
251 val = inb(data->addr + DATA_REG_OFFSET) << 8; 252 val = inb(data->addr + DATA_REG_OFFSET) << 8;
252 outb(++reg, data->addr + ADDR_REG_OFFSET); 253 outb(++reg, data->addr + ADDR_REG_OFFSET);
253 val |= inb(data->addr + DATA_REG_OFFSET); 254 val |= inb(data->addr + DATA_REG_OFFSET);
254 up(&data->lock); 255 mutex_unlock(&data->lock);
255 256
256 return val; 257 return val;
257} 258}
258 259
259static void f71805f_write16(struct f71805f_data *data, u8 reg, u16 val) 260static void f71805f_write16(struct f71805f_data *data, u8 reg, u16 val)
260{ 261{
261 down(&data->lock); 262 mutex_lock(&data->lock);
262 outb(reg, data->addr + ADDR_REG_OFFSET); 263 outb(reg, data->addr + ADDR_REG_OFFSET);
263 outb(val >> 8, data->addr + DATA_REG_OFFSET); 264 outb(val >> 8, data->addr + DATA_REG_OFFSET);
264 outb(++reg, data->addr + ADDR_REG_OFFSET); 265 outb(++reg, data->addr + ADDR_REG_OFFSET);
265 outb(val & 0xff, data->addr + DATA_REG_OFFSET); 266 outb(val & 0xff, data->addr + DATA_REG_OFFSET);
266 up(&data->lock); 267 mutex_unlock(&data->lock);
267} 268}
268 269
269static struct f71805f_data *f71805f_update_device(struct device *dev) 270static struct f71805f_data *f71805f_update_device(struct device *dev)
@@ -271,7 +272,7 @@ static struct f71805f_data *f71805f_update_device(struct device *dev)
271 struct f71805f_data *data = dev_get_drvdata(dev); 272 struct f71805f_data *data = dev_get_drvdata(dev);
272 int nr; 273 int nr;
273 274
274 down(&data->update_lock); 275 mutex_lock(&data->update_lock);
275 276
276 /* Limit registers cache is refreshed after 60 seconds */ 277 /* Limit registers cache is refreshed after 60 seconds */
277 if (time_after(jiffies, data->last_updated + 60 * HZ) 278 if (time_after(jiffies, data->last_updated + 60 * HZ)
@@ -323,7 +324,7 @@ static struct f71805f_data *f71805f_update_device(struct device *dev)
323 data->valid = 1; 324 data->valid = 1;
324 } 325 }
325 326
326 up(&data->update_lock); 327 mutex_unlock(&data->update_lock);
327 328
328 return data; 329 return data;
329} 330}
@@ -362,10 +363,10 @@ static ssize_t set_in0_max(struct device *dev, struct device_attribute
362 struct f71805f_data *data = dev_get_drvdata(dev); 363 struct f71805f_data *data = dev_get_drvdata(dev);
363 long val = simple_strtol(buf, NULL, 10); 364 long val = simple_strtol(buf, NULL, 10);
364 365
365 down(&data->update_lock); 366 mutex_lock(&data->update_lock);
366 data->in_high[0] = in0_to_reg(val); 367 data->in_high[0] = in0_to_reg(val);
367 f71805f_write8(data, F71805F_REG_IN_HIGH(0), data->in_high[0]); 368 f71805f_write8(data, F71805F_REG_IN_HIGH(0), data->in_high[0]);
368 up(&data->update_lock); 369 mutex_unlock(&data->update_lock);
369 370
370 return count; 371 return count;
371} 372}
@@ -376,18 +377,14 @@ static ssize_t set_in0_min(struct device *dev, struct device_attribute
376 struct f71805f_data *data = dev_get_drvdata(dev); 377 struct f71805f_data *data = dev_get_drvdata(dev);
377 long val = simple_strtol(buf, NULL, 10); 378 long val = simple_strtol(buf, NULL, 10);
378 379
379 down(&data->update_lock); 380 mutex_lock(&data->update_lock);
380 data->in_low[0] = in0_to_reg(val); 381 data->in_low[0] = in0_to_reg(val);
381 f71805f_write8(data, F71805F_REG_IN_LOW(0), data->in_low[0]); 382 f71805f_write8(data, F71805F_REG_IN_LOW(0), data->in_low[0]);
382 up(&data->update_lock); 383 mutex_unlock(&data->update_lock);
383 384
384 return count; 385 return count;
385} 386}
386 387
387static DEVICE_ATTR(in0_input, S_IRUGO, show_in0, NULL);
388static DEVICE_ATTR(in0_max, S_IRUGO| S_IWUSR, show_in0_max, set_in0_max);
389static DEVICE_ATTR(in0_min, S_IRUGO| S_IWUSR, show_in0_min, set_in0_min);
390
391static ssize_t show_in(struct device *dev, struct device_attribute *devattr, 388static ssize_t show_in(struct device *dev, struct device_attribute *devattr,
392 char *buf) 389 char *buf)
393{ 390{
@@ -426,10 +423,10 @@ static ssize_t set_in_max(struct device *dev, struct device_attribute
426 int nr = attr->index; 423 int nr = attr->index;
427 long val = simple_strtol(buf, NULL, 10); 424 long val = simple_strtol(buf, NULL, 10);
428 425
429 down(&data->update_lock); 426 mutex_lock(&data->update_lock);
430 data->in_high[nr] = in_to_reg(val); 427 data->in_high[nr] = in_to_reg(val);
431 f71805f_write8(data, F71805F_REG_IN_HIGH(nr), data->in_high[nr]); 428 f71805f_write8(data, F71805F_REG_IN_HIGH(nr), data->in_high[nr]);
432 up(&data->update_lock); 429 mutex_unlock(&data->update_lock);
433 430
434 return count; 431 return count;
435} 432}
@@ -442,31 +439,14 @@ static ssize_t set_in_min(struct device *dev, struct device_attribute
442 int nr = attr->index; 439 int nr = attr->index;
443 long val = simple_strtol(buf, NULL, 10); 440 long val = simple_strtol(buf, NULL, 10);
444 441
445 down(&data->update_lock); 442 mutex_lock(&data->update_lock);
446 data->in_low[nr] = in_to_reg(val); 443 data->in_low[nr] = in_to_reg(val);
447 f71805f_write8(data, F71805F_REG_IN_LOW(nr), data->in_low[nr]); 444 f71805f_write8(data, F71805F_REG_IN_LOW(nr), data->in_low[nr]);
448 up(&data->update_lock); 445 mutex_unlock(&data->update_lock);
449 446
450 return count; 447 return count;
451} 448}
452 449
453#define sysfs_in(offset) \
454static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \
455 show_in, NULL, offset); \
456static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
457 show_in_max, set_in_max, offset); \
458static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
459 show_in_min, set_in_min, offset)
460
461sysfs_in(1);
462sysfs_in(2);
463sysfs_in(3);
464sysfs_in(4);
465sysfs_in(5);
466sysfs_in(6);
467sysfs_in(7);
468sysfs_in(8);
469
470static ssize_t show_fan(struct device *dev, struct device_attribute *devattr, 450static ssize_t show_fan(struct device *dev, struct device_attribute *devattr,
471 char *buf) 451 char *buf)
472{ 452{
@@ -495,24 +475,14 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute
495 int nr = attr->index; 475 int nr = attr->index;
496 long val = simple_strtol(buf, NULL, 10); 476 long val = simple_strtol(buf, NULL, 10);
497 477
498 down(&data->update_lock); 478 mutex_lock(&data->update_lock);
499 data->fan_low[nr] = fan_to_reg(val); 479 data->fan_low[nr] = fan_to_reg(val);
500 f71805f_write16(data, F71805F_REG_FAN_LOW(nr), data->fan_low[nr]); 480 f71805f_write16(data, F71805F_REG_FAN_LOW(nr), data->fan_low[nr]);
501 up(&data->update_lock); 481 mutex_unlock(&data->update_lock);
502 482
503 return count; 483 return count;
504} 484}
505 485
506#define sysfs_fan(offset) \
507static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \
508 show_fan, NULL, offset - 1); \
509static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
510 show_fan_min, set_fan_min, offset - 1)
511
512sysfs_fan(1);
513sysfs_fan(2);
514sysfs_fan(3);
515
516static ssize_t show_temp(struct device *dev, struct device_attribute *devattr, 486static ssize_t show_temp(struct device *dev, struct device_attribute *devattr,
517 char *buf) 487 char *buf)
518{ 488{
@@ -562,10 +532,10 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute
562 int nr = attr->index; 532 int nr = attr->index;
563 long val = simple_strtol(buf, NULL, 10); 533 long val = simple_strtol(buf, NULL, 10);
564 534
565 down(&data->update_lock); 535 mutex_lock(&data->update_lock);
566 data->temp_high[nr] = temp_to_reg(val); 536 data->temp_high[nr] = temp_to_reg(val);
567 f71805f_write8(data, F71805F_REG_TEMP_HIGH(nr), data->temp_high[nr]); 537 f71805f_write8(data, F71805F_REG_TEMP_HIGH(nr), data->temp_high[nr]);
568 up(&data->update_lock); 538 mutex_unlock(&data->update_lock);
569 539
570 return count; 540 return count;
571} 541}
@@ -578,28 +548,14 @@ static ssize_t set_temp_hyst(struct device *dev, struct device_attribute
578 int nr = attr->index; 548 int nr = attr->index;
579 long val = simple_strtol(buf, NULL, 10); 549 long val = simple_strtol(buf, NULL, 10);
580 550
581 down(&data->update_lock); 551 mutex_lock(&data->update_lock);
582 data->temp_hyst[nr] = temp_to_reg(val); 552 data->temp_hyst[nr] = temp_to_reg(val);
583 f71805f_write8(data, F71805F_REG_TEMP_HYST(nr), data->temp_hyst[nr]); 553 f71805f_write8(data, F71805F_REG_TEMP_HYST(nr), data->temp_hyst[nr]);
584 up(&data->update_lock); 554 mutex_unlock(&data->update_lock);
585 555
586 return count; 556 return count;
587} 557}
588 558
589#define sysfs_temp(offset) \
590static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \
591 show_temp, NULL, offset - 1); \
592static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \
593 show_temp_max, set_temp_max, offset - 1); \
594static SENSOR_DEVICE_ATTR(temp##offset##_max_hyst, S_IRUGO | S_IWUSR, \
595 show_temp_hyst, set_temp_hyst, offset - 1); \
596static SENSOR_DEVICE_ATTR(temp##offset##_type, S_IRUGO, \
597 show_temp_type, NULL, offset - 1)
598
599sysfs_temp(1);
600sysfs_temp(2);
601sysfs_temp(3);
602
603static ssize_t show_alarms_in(struct device *dev, struct device_attribute 559static ssize_t show_alarms_in(struct device *dev, struct device_attribute
604 *devattr, char *buf) 560 *devattr, char *buf)
605{ 561{
@@ -625,10 +581,6 @@ static ssize_t show_alarms_temp(struct device *dev, struct device_attribute
625 return sprintf(buf, "%d\n", (data->alarms[1] >> 3) & 0x07); 581 return sprintf(buf, "%d\n", (data->alarms[1] >> 3) & 0x07);
626} 582}
627 583
628static DEVICE_ATTR(alarms_in, S_IRUGO, show_alarms_in, NULL);
629static DEVICE_ATTR(alarms_fan, S_IRUGO, show_alarms_fan, NULL);
630static DEVICE_ATTR(alarms_temp, S_IRUGO, show_alarms_temp, NULL);
631
632static ssize_t show_name(struct device *dev, struct device_attribute 584static ssize_t show_name(struct device *dev, struct device_attribute
633 *devattr, char *buf) 585 *devattr, char *buf)
634{ 586{
@@ -637,7 +589,89 @@ static ssize_t show_name(struct device *dev, struct device_attribute
637 return sprintf(buf, "%s\n", data->name); 589 return sprintf(buf, "%s\n", data->name);
638} 590}
639 591
640static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); 592static struct device_attribute f71805f_dev_attr[] = {
593 __ATTR(in0_input, S_IRUGO, show_in0, NULL),
594 __ATTR(in0_max, S_IRUGO| S_IWUSR, show_in0_max, set_in0_max),
595 __ATTR(in0_min, S_IRUGO| S_IWUSR, show_in0_min, set_in0_min),
596 __ATTR(alarms_in, S_IRUGO, show_alarms_in, NULL),
597 __ATTR(alarms_fan, S_IRUGO, show_alarms_fan, NULL),
598 __ATTR(alarms_temp, S_IRUGO, show_alarms_temp, NULL),
599 __ATTR(name, S_IRUGO, show_name, NULL),
600};
601
602static struct sensor_device_attribute f71805f_sensor_attr[] = {
603 SENSOR_ATTR(in1_input, S_IRUGO, show_in, NULL, 1),
604 SENSOR_ATTR(in1_max, S_IRUGO | S_IWUSR,
605 show_in_max, set_in_max, 1),
606 SENSOR_ATTR(in1_min, S_IRUGO | S_IWUSR,
607 show_in_min, set_in_min, 1),
608 SENSOR_ATTR(in2_input, S_IRUGO, show_in, NULL, 2),
609 SENSOR_ATTR(in2_max, S_IRUGO | S_IWUSR,
610 show_in_max, set_in_max, 2),
611 SENSOR_ATTR(in2_min, S_IRUGO | S_IWUSR,
612 show_in_min, set_in_min, 2),
613 SENSOR_ATTR(in3_input, S_IRUGO, show_in, NULL, 3),
614 SENSOR_ATTR(in3_max, S_IRUGO | S_IWUSR,
615 show_in_max, set_in_max, 3),
616 SENSOR_ATTR(in3_min, S_IRUGO | S_IWUSR,
617 show_in_min, set_in_min, 3),
618 SENSOR_ATTR(in4_input, S_IRUGO, show_in, NULL, 4),
619 SENSOR_ATTR(in4_max, S_IRUGO | S_IWUSR,
620 show_in_max, set_in_max, 4),
621 SENSOR_ATTR(in4_min, S_IRUGO | S_IWUSR,
622 show_in_min, set_in_min, 4),
623 SENSOR_ATTR(in5_input, S_IRUGO, show_in, NULL, 5),
624 SENSOR_ATTR(in5_max, S_IRUGO | S_IWUSR,
625 show_in_max, set_in_max, 5),
626 SENSOR_ATTR(in5_min, S_IRUGO | S_IWUSR,
627 show_in_min, set_in_min, 5),
628 SENSOR_ATTR(in6_input, S_IRUGO, show_in, NULL, 6),
629 SENSOR_ATTR(in6_max, S_IRUGO | S_IWUSR,
630 show_in_max, set_in_max, 6),
631 SENSOR_ATTR(in6_min, S_IRUGO | S_IWUSR,
632 show_in_min, set_in_min, 6),
633 SENSOR_ATTR(in7_input, S_IRUGO, show_in, NULL, 7),
634 SENSOR_ATTR(in7_max, S_IRUGO | S_IWUSR,
635 show_in_max, set_in_max, 7),
636 SENSOR_ATTR(in7_min, S_IRUGO | S_IWUSR,
637 show_in_min, set_in_min, 7),
638 SENSOR_ATTR(in8_input, S_IRUGO, show_in, NULL, 8),
639 SENSOR_ATTR(in8_max, S_IRUGO | S_IWUSR,
640 show_in_max, set_in_max, 8),
641 SENSOR_ATTR(in8_min, S_IRUGO | S_IWUSR,
642 show_in_min, set_in_min, 8),
643
644 SENSOR_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0),
645 SENSOR_ATTR(temp1_max, S_IRUGO | S_IWUSR,
646 show_temp_max, set_temp_max, 0),
647 SENSOR_ATTR(temp1_max_hyst, S_IRUGO | S_IWUSR,
648 show_temp_hyst, set_temp_hyst, 0),
649 SENSOR_ATTR(temp1_type, S_IRUGO, show_temp_type, NULL, 0),
650 SENSOR_ATTR(temp2_input, S_IRUGO, show_temp, NULL, 1),
651 SENSOR_ATTR(temp2_max, S_IRUGO | S_IWUSR,
652 show_temp_max, set_temp_max, 1),
653 SENSOR_ATTR(temp2_max_hyst, S_IRUGO | S_IWUSR,
654 show_temp_hyst, set_temp_hyst, 1),
655 SENSOR_ATTR(temp2_type, S_IRUGO, show_temp_type, NULL, 1),
656 SENSOR_ATTR(temp3_input, S_IRUGO, show_temp, NULL, 2),
657 SENSOR_ATTR(temp3_max, S_IRUGO | S_IWUSR,
658 show_temp_max, set_temp_max, 2),
659 SENSOR_ATTR(temp3_max_hyst, S_IRUGO | S_IWUSR,
660 show_temp_hyst, set_temp_hyst, 2),
661 SENSOR_ATTR(temp3_type, S_IRUGO, show_temp_type, NULL, 2),
662};
663
664static struct sensor_device_attribute f71805f_fan_attr[] = {
665 SENSOR_ATTR(fan1_input, S_IRUGO, show_fan, NULL, 0),
666 SENSOR_ATTR(fan1_min, S_IRUGO | S_IWUSR,
667 show_fan_min, set_fan_min, 0),
668 SENSOR_ATTR(fan2_input, S_IRUGO, show_fan, NULL, 1),
669 SENSOR_ATTR(fan2_min, S_IRUGO | S_IWUSR,
670 show_fan_min, set_fan_min, 1),
671 SENSOR_ATTR(fan3_input, S_IRUGO, show_fan, NULL, 2),
672 SENSOR_ATTR(fan3_min, S_IRUGO | S_IWUSR,
673 show_fan_min, set_fan_min, 2),
674};
641 675
642/* 676/*
643 * Device registration and initialization 677 * Device registration and initialization
@@ -668,7 +702,7 @@ static int __devinit f71805f_probe(struct platform_device *pdev)
668{ 702{
669 struct f71805f_data *data; 703 struct f71805f_data *data;
670 struct resource *res; 704 struct resource *res;
671 int err; 705 int i, err;
672 706
673 if (!(data = kzalloc(sizeof(struct f71805f_data), GFP_KERNEL))) { 707 if (!(data = kzalloc(sizeof(struct f71805f_data), GFP_KERNEL))) {
674 err = -ENOMEM; 708 err = -ENOMEM;
@@ -678,9 +712,9 @@ static int __devinit f71805f_probe(struct platform_device *pdev)
678 712
679 res = platform_get_resource(pdev, IORESOURCE_IO, 0); 713 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
680 data->addr = res->start; 714 data->addr = res->start;
681 init_MUTEX(&data->lock); 715 mutex_init(&data->lock);
682 data->name = "f71805f"; 716 data->name = "f71805f";
683 init_MUTEX(&data->update_lock); 717 mutex_init(&data->update_lock);
684 718
685 platform_set_drvdata(pdev, data); 719 platform_set_drvdata(pdev, data);
686 720
@@ -695,76 +729,31 @@ static int __devinit f71805f_probe(struct platform_device *pdev)
695 f71805f_init_device(data); 729 f71805f_init_device(data);
696 730
697 /* Register sysfs interface files */ 731 /* Register sysfs interface files */
698 device_create_file(&pdev->dev, &dev_attr_in0_input); 732 for (i = 0; i < ARRAY_SIZE(f71805f_dev_attr); i++) {
699 device_create_file(&pdev->dev, &dev_attr_in0_max); 733 err = device_create_file(&pdev->dev, &f71805f_dev_attr[i]);
700 device_create_file(&pdev->dev, &dev_attr_in0_min); 734 if (err)
701 device_create_file(&pdev->dev, &sensor_dev_attr_in1_input.dev_attr); 735 goto exit_class;
702 device_create_file(&pdev->dev, &sensor_dev_attr_in2_input.dev_attr);
703 device_create_file(&pdev->dev, &sensor_dev_attr_in3_input.dev_attr);
704 device_create_file(&pdev->dev, &sensor_dev_attr_in4_input.dev_attr);
705 device_create_file(&pdev->dev, &sensor_dev_attr_in5_input.dev_attr);
706 device_create_file(&pdev->dev, &sensor_dev_attr_in6_input.dev_attr);
707 device_create_file(&pdev->dev, &sensor_dev_attr_in7_input.dev_attr);
708 device_create_file(&pdev->dev, &sensor_dev_attr_in8_input.dev_attr);
709 device_create_file(&pdev->dev, &sensor_dev_attr_in1_max.dev_attr);
710 device_create_file(&pdev->dev, &sensor_dev_attr_in2_max.dev_attr);
711 device_create_file(&pdev->dev, &sensor_dev_attr_in3_max.dev_attr);
712 device_create_file(&pdev->dev, &sensor_dev_attr_in4_max.dev_attr);
713 device_create_file(&pdev->dev, &sensor_dev_attr_in5_max.dev_attr);
714 device_create_file(&pdev->dev, &sensor_dev_attr_in6_max.dev_attr);
715 device_create_file(&pdev->dev, &sensor_dev_attr_in7_max.dev_attr);
716 device_create_file(&pdev->dev, &sensor_dev_attr_in8_max.dev_attr);
717 device_create_file(&pdev->dev, &sensor_dev_attr_in1_min.dev_attr);
718 device_create_file(&pdev->dev, &sensor_dev_attr_in2_min.dev_attr);
719 device_create_file(&pdev->dev, &sensor_dev_attr_in3_min.dev_attr);
720 device_create_file(&pdev->dev, &sensor_dev_attr_in4_min.dev_attr);
721 device_create_file(&pdev->dev, &sensor_dev_attr_in5_min.dev_attr);
722 device_create_file(&pdev->dev, &sensor_dev_attr_in6_min.dev_attr);
723 device_create_file(&pdev->dev, &sensor_dev_attr_in7_min.dev_attr);
724 device_create_file(&pdev->dev, &sensor_dev_attr_in8_min.dev_attr);
725 if (data->fan_enabled & (1 << 0)) {
726 device_create_file(&pdev->dev,
727 &sensor_dev_attr_fan1_input.dev_attr);
728 device_create_file(&pdev->dev,
729 &sensor_dev_attr_fan1_min.dev_attr);
730 } 736 }
731 if (data->fan_enabled & (1 << 1)) { 737 for (i = 0; i < ARRAY_SIZE(f71805f_sensor_attr); i++) {
732 device_create_file(&pdev->dev, 738 err = device_create_file(&pdev->dev,
733 &sensor_dev_attr_fan2_input.dev_attr); 739 &f71805f_sensor_attr[i].dev_attr);
734 device_create_file(&pdev->dev, 740 if (err)
735 &sensor_dev_attr_fan2_min.dev_attr); 741 goto exit_class;
736 } 742 }
737 if (data->fan_enabled & (1 << 2)) { 743 for (i = 0; i < ARRAY_SIZE(f71805f_fan_attr); i++) {
738 device_create_file(&pdev->dev, 744 if (!(data->fan_enabled & (1 << (i / 2))))
739 &sensor_dev_attr_fan3_input.dev_attr); 745 continue;
740 device_create_file(&pdev->dev, 746 err = device_create_file(&pdev->dev,
741 &sensor_dev_attr_fan3_min.dev_attr); 747 &f71805f_fan_attr[i].dev_attr);
748 if (err)
749 goto exit_class;
742 } 750 }
743 device_create_file(&pdev->dev,
744 &sensor_dev_attr_temp1_input.dev_attr);
745 device_create_file(&pdev->dev,
746 &sensor_dev_attr_temp2_input.dev_attr);
747 device_create_file(&pdev->dev,
748 &sensor_dev_attr_temp3_input.dev_attr);
749 device_create_file(&pdev->dev, &sensor_dev_attr_temp1_max.dev_attr);
750 device_create_file(&pdev->dev, &sensor_dev_attr_temp2_max.dev_attr);
751 device_create_file(&pdev->dev, &sensor_dev_attr_temp3_max.dev_attr);
752 device_create_file(&pdev->dev,
753 &sensor_dev_attr_temp1_max_hyst.dev_attr);
754 device_create_file(&pdev->dev,
755 &sensor_dev_attr_temp2_max_hyst.dev_attr);
756 device_create_file(&pdev->dev,
757 &sensor_dev_attr_temp3_max_hyst.dev_attr);
758 device_create_file(&pdev->dev, &sensor_dev_attr_temp1_type.dev_attr);
759 device_create_file(&pdev->dev, &sensor_dev_attr_temp2_type.dev_attr);
760 device_create_file(&pdev->dev, &sensor_dev_attr_temp3_type.dev_attr);
761 device_create_file(&pdev->dev, &dev_attr_alarms_in);
762 device_create_file(&pdev->dev, &dev_attr_alarms_fan);
763 device_create_file(&pdev->dev, &dev_attr_alarms_temp);
764 device_create_file(&pdev->dev, &dev_attr_name);
765 751
766 return 0; 752 return 0;
767 753
754exit_class:
755 dev_err(&pdev->dev, "Sysfs interface creation failed\n");
756 hwmon_device_unregister(data->class_dev);
768exit_free: 757exit_free:
769 kfree(data); 758 kfree(data);
770exit: 759exit:
diff --git a/drivers/hwmon/fscher.c b/drivers/hwmon/fscher.c
index 25409181d1..6bc76b4076 100644
--- a/drivers/hwmon/fscher.c
+++ b/drivers/hwmon/fscher.c
@@ -33,6 +33,7 @@
33#include <linux/i2c.h> 33#include <linux/i2c.h>
34#include <linux/hwmon.h> 34#include <linux/hwmon.h>
35#include <linux/err.h> 35#include <linux/err.h>
36#include <linux/mutex.h>
36 37
37/* 38/*
38 * Addresses to scan 39 * Addresses to scan
@@ -133,7 +134,7 @@ static struct i2c_driver fscher_driver = {
133struct fscher_data { 134struct fscher_data {
134 struct i2c_client client; 135 struct i2c_client client;
135 struct class_device *class_dev; 136 struct class_device *class_dev;
136 struct semaphore update_lock; 137 struct mutex update_lock;
137 char valid; /* zero until following fields are valid */ 138 char valid; /* zero until following fields are valid */
138 unsigned long last_updated; /* in jiffies */ 139 unsigned long last_updated; /* in jiffies */
139 140
@@ -332,7 +333,7 @@ static int fscher_detect(struct i2c_adapter *adapter, int address, int kind)
332 * global list */ 333 * global list */
333 strlcpy(new_client->name, "fscher", I2C_NAME_SIZE); 334 strlcpy(new_client->name, "fscher", I2C_NAME_SIZE);
334 data->valid = 0; 335 data->valid = 0;
335 init_MUTEX(&data->update_lock); 336 mutex_init(&data->update_lock);
336 337
337 /* Tell the I2C layer a new client has arrived */ 338 /* Tell the I2C layer a new client has arrived */
338 if ((err = i2c_attach_client(new_client))) 339 if ((err = i2c_attach_client(new_client)))
@@ -417,7 +418,7 @@ static struct fscher_data *fscher_update_device(struct device *dev)
417 struct i2c_client *client = to_i2c_client(dev); 418 struct i2c_client *client = to_i2c_client(dev);
418 struct fscher_data *data = i2c_get_clientdata(client); 419 struct fscher_data *data = i2c_get_clientdata(client);
419 420
420 down(&data->update_lock); 421 mutex_lock(&data->update_lock);
421 422
422 if (time_after(jiffies, data->last_updated + 2 * HZ) || !data->valid) { 423 if (time_after(jiffies, data->last_updated + 2 * HZ) || !data->valid) {
423 424
@@ -457,7 +458,7 @@ static struct fscher_data *fscher_update_device(struct device *dev)
457 data->valid = 1; 458 data->valid = 1;
458 } 459 }
459 460
460 up(&data->update_lock); 461 mutex_unlock(&data->update_lock);
461 462
462 return data; 463 return data;
463} 464}
@@ -472,10 +473,10 @@ static ssize_t set_fan_status(struct i2c_client *client, struct fscher_data *dat
472 /* bits 0..1, 3..7 reserved => mask with 0x04 */ 473 /* bits 0..1, 3..7 reserved => mask with 0x04 */
473 unsigned long v = simple_strtoul(buf, NULL, 10) & 0x04; 474 unsigned long v = simple_strtoul(buf, NULL, 10) & 0x04;
474 475
475 down(&data->update_lock); 476 mutex_lock(&data->update_lock);
476 data->fan_status[FAN_INDEX_FROM_NUM(nr)] &= ~v; 477 data->fan_status[FAN_INDEX_FROM_NUM(nr)] &= ~v;
477 fscher_write_value(client, reg, v); 478 fscher_write_value(client, reg, v);
478 up(&data->update_lock); 479 mutex_unlock(&data->update_lock);
479 return count; 480 return count;
480} 481}
481 482
@@ -490,10 +491,10 @@ static ssize_t set_pwm(struct i2c_client *client, struct fscher_data *data,
490{ 491{
491 unsigned long v = simple_strtoul(buf, NULL, 10); 492 unsigned long v = simple_strtoul(buf, NULL, 10);
492 493
493 down(&data->update_lock); 494 mutex_lock(&data->update_lock);
494 data->fan_min[FAN_INDEX_FROM_NUM(nr)] = v > 0xff ? 0xff : v; 495 data->fan_min[FAN_INDEX_FROM_NUM(nr)] = v > 0xff ? 0xff : v;
495 fscher_write_value(client, reg, data->fan_min[FAN_INDEX_FROM_NUM(nr)]); 496 fscher_write_value(client, reg, data->fan_min[FAN_INDEX_FROM_NUM(nr)]);
496 up(&data->update_lock); 497 mutex_unlock(&data->update_lock);
497 return count; 498 return count;
498} 499}
499 500
@@ -518,14 +519,14 @@ static ssize_t set_fan_div(struct i2c_client *client, struct fscher_data *data,
518 return -EINVAL; 519 return -EINVAL;
519 } 520 }
520 521
521 down(&data->update_lock); 522 mutex_lock(&data->update_lock);
522 523
523 /* bits 2..7 reserved => mask with 0x03 */ 524 /* bits 2..7 reserved => mask with 0x03 */
524 data->fan_ripple[FAN_INDEX_FROM_NUM(nr)] &= ~0x03; 525 data->fan_ripple[FAN_INDEX_FROM_NUM(nr)] &= ~0x03;
525 data->fan_ripple[FAN_INDEX_FROM_NUM(nr)] |= v; 526 data->fan_ripple[FAN_INDEX_FROM_NUM(nr)] |= v;
526 527
527 fscher_write_value(client, reg, data->fan_ripple[FAN_INDEX_FROM_NUM(nr)]); 528 fscher_write_value(client, reg, data->fan_ripple[FAN_INDEX_FROM_NUM(nr)]);
528 up(&data->update_lock); 529 mutex_unlock(&data->update_lock);
529 return count; 530 return count;
530} 531}
531 532
@@ -552,10 +553,10 @@ static ssize_t set_temp_status(struct i2c_client *client, struct fscher_data *da
552 /* bits 2..7 reserved, 0 read only => mask with 0x02 */ 553 /* bits 2..7 reserved, 0 read only => mask with 0x02 */
553 unsigned long v = simple_strtoul(buf, NULL, 10) & 0x02; 554 unsigned long v = simple_strtoul(buf, NULL, 10) & 0x02;
554 555
555 down(&data->update_lock); 556 mutex_lock(&data->update_lock);
556 data->temp_status[TEMP_INDEX_FROM_NUM(nr)] &= ~v; 557 data->temp_status[TEMP_INDEX_FROM_NUM(nr)] &= ~v;
557 fscher_write_value(client, reg, v); 558 fscher_write_value(client, reg, v);
558 up(&data->update_lock); 559 mutex_unlock(&data->update_lock);
559 return count; 560 return count;
560} 561}
561 562
@@ -609,10 +610,10 @@ static ssize_t set_control(struct i2c_client *client, struct fscher_data *data,
609 /* bits 1..7 reserved => mask with 0x01 */ 610 /* bits 1..7 reserved => mask with 0x01 */
610 unsigned long v = simple_strtoul(buf, NULL, 10) & 0x01; 611 unsigned long v = simple_strtoul(buf, NULL, 10) & 0x01;
611 612
612 down(&data->update_lock); 613 mutex_lock(&data->update_lock);
613 data->global_control &= ~v; 614 data->global_control &= ~v;
614 fscher_write_value(client, reg, v); 615 fscher_write_value(client, reg, v);
615 up(&data->update_lock); 616 mutex_unlock(&data->update_lock);
616 return count; 617 return count;
617} 618}
618 619
@@ -631,11 +632,11 @@ static ssize_t set_watchdog_control(struct i2c_client *client, struct
631 /* bits 0..3 reserved => mask with 0xf0 */ 632 /* bits 0..3 reserved => mask with 0xf0 */
632 unsigned long v = simple_strtoul(buf, NULL, 10) & 0xf0; 633 unsigned long v = simple_strtoul(buf, NULL, 10) & 0xf0;
633 634
634 down(&data->update_lock); 635 mutex_lock(&data->update_lock);
635 data->watchdog[2] &= ~0xf0; 636 data->watchdog[2] &= ~0xf0;
636 data->watchdog[2] |= v; 637 data->watchdog[2] |= v;
637 fscher_write_value(client, reg, data->watchdog[2]); 638 fscher_write_value(client, reg, data->watchdog[2]);
638 up(&data->update_lock); 639 mutex_unlock(&data->update_lock);
639 return count; 640 return count;
640} 641}
641 642
@@ -651,10 +652,10 @@ static ssize_t set_watchdog_status(struct i2c_client *client, struct fscher_data
651 /* bits 0, 2..7 reserved => mask with 0x02 */ 652 /* bits 0, 2..7 reserved => mask with 0x02 */
652 unsigned long v = simple_strtoul(buf, NULL, 10) & 0x02; 653 unsigned long v = simple_strtoul(buf, NULL, 10) & 0x02;
653 654
654 down(&data->update_lock); 655 mutex_lock(&data->update_lock);
655 data->watchdog[1] &= ~v; 656 data->watchdog[1] &= ~v;
656 fscher_write_value(client, reg, v); 657 fscher_write_value(client, reg, v);
657 up(&data->update_lock); 658 mutex_unlock(&data->update_lock);
658 return count; 659 return count;
659} 660}
660 661
@@ -669,10 +670,10 @@ static ssize_t set_watchdog_preset(struct i2c_client *client, struct fscher_data
669{ 670{
670 unsigned long v = simple_strtoul(buf, NULL, 10) & 0xff; 671 unsigned long v = simple_strtoul(buf, NULL, 10) & 0xff;
671 672
672 down(&data->update_lock); 673 mutex_lock(&data->update_lock);
673 data->watchdog[0] = v; 674 data->watchdog[0] = v;
674 fscher_write_value(client, reg, data->watchdog[0]); 675 fscher_write_value(client, reg, data->watchdog[0]);
675 up(&data->update_lock); 676 mutex_unlock(&data->update_lock);
676 return count; 677 return count;
677} 678}
678 679
diff --git a/drivers/hwmon/fscpos.c b/drivers/hwmon/fscpos.c
index 6d0146b570..6dc4846b9e 100644
--- a/drivers/hwmon/fscpos.c
+++ b/drivers/hwmon/fscpos.c
@@ -37,6 +37,7 @@
37#include <linux/init.h> 37#include <linux/init.h>
38#include <linux/hwmon.h> 38#include <linux/hwmon.h>
39#include <linux/err.h> 39#include <linux/err.h>
40#include <linux/mutex.h>
40 41
41/* 42/*
42 * Addresses to scan 43 * Addresses to scan
@@ -89,8 +90,8 @@ static int fscpos_attach_adapter(struct i2c_adapter *adapter);
89static int fscpos_detect(struct i2c_adapter *adapter, int address, int kind); 90static int fscpos_detect(struct i2c_adapter *adapter, int address, int kind);
90static int fscpos_detach_client(struct i2c_client *client); 91static int fscpos_detach_client(struct i2c_client *client);
91 92
92static int fscpos_read_value(struct i2c_client *client, u8 register); 93static int fscpos_read_value(struct i2c_client *client, u8 reg);
93static int fscpos_write_value(struct i2c_client *client, u8 register, u8 value); 94static int fscpos_write_value(struct i2c_client *client, u8 reg, u8 value);
94static struct fscpos_data *fscpos_update_device(struct device *dev); 95static struct fscpos_data *fscpos_update_device(struct device *dev);
95static void fscpos_init_client(struct i2c_client *client); 96static void fscpos_init_client(struct i2c_client *client);
96 97
@@ -114,7 +115,7 @@ static struct i2c_driver fscpos_driver = {
114struct fscpos_data { 115struct fscpos_data {
115 struct i2c_client client; 116 struct i2c_client client;
116 struct class_device *class_dev; 117 struct class_device *class_dev;
117 struct semaphore update_lock; 118 struct mutex update_lock;
118 char valid; /* 0 until following fields are valid */ 119 char valid; /* 0 until following fields are valid */
119 unsigned long last_updated; /* In jiffies */ 120 unsigned long last_updated; /* In jiffies */
120 121
@@ -208,13 +209,13 @@ static ssize_t set_fan_ripple(struct i2c_client *client, struct fscpos_data
208 return -EINVAL; 209 return -EINVAL;
209 } 210 }
210 211
211 down(&data->update_lock); 212 mutex_lock(&data->update_lock);
212 /* bits 2..7 reserved => mask with 0x03 */ 213 /* bits 2..7 reserved => mask with 0x03 */
213 data->fan_ripple[nr - 1] &= ~0x03; 214 data->fan_ripple[nr - 1] &= ~0x03;
214 data->fan_ripple[nr - 1] |= v; 215 data->fan_ripple[nr - 1] |= v;
215 216
216 fscpos_write_value(client, reg, data->fan_ripple[nr - 1]); 217 fscpos_write_value(client, reg, data->fan_ripple[nr - 1]);
217 up(&data->update_lock); 218 mutex_unlock(&data->update_lock);
218 return count; 219 return count;
219} 220}
220 221
@@ -232,10 +233,10 @@ static ssize_t set_pwm(struct i2c_client *client, struct fscpos_data *data,
232 if (v < 0) v = 0; 233 if (v < 0) v = 0;
233 if (v > 255) v = 255; 234 if (v > 255) v = 255;
234 235
235 down(&data->update_lock); 236 mutex_lock(&data->update_lock);
236 data->pwm[nr - 1] = v; 237 data->pwm[nr - 1] = v;
237 fscpos_write_value(client, reg, data->pwm[nr - 1]); 238 fscpos_write_value(client, reg, data->pwm[nr - 1]);
238 up(&data->update_lock); 239 mutex_unlock(&data->update_lock);
239 return count; 240 return count;
240} 241}
241 242
@@ -278,11 +279,11 @@ static ssize_t set_wdog_control(struct i2c_client *client, struct fscpos_data
278 /* bits 0..3 reserved => mask with 0xf0 */ 279 /* bits 0..3 reserved => mask with 0xf0 */
279 unsigned long v = simple_strtoul(buf, NULL, 10) & 0xf0; 280 unsigned long v = simple_strtoul(buf, NULL, 10) & 0xf0;
280 281
281 down(&data->update_lock); 282 mutex_lock(&data->update_lock);
282 data->wdog_control &= ~0xf0; 283 data->wdog_control &= ~0xf0;
283 data->wdog_control |= v; 284 data->wdog_control |= v;
284 fscpos_write_value(client, reg, data->wdog_control); 285 fscpos_write_value(client, reg, data->wdog_control);
285 up(&data->update_lock); 286 mutex_unlock(&data->update_lock);
286 return count; 287 return count;
287} 288}
288 289
@@ -304,10 +305,10 @@ static ssize_t set_wdog_state(struct i2c_client *client, struct fscpos_data
304 return -EINVAL; 305 return -EINVAL;
305 } 306 }
306 307
307 down(&data->update_lock); 308 mutex_lock(&data->update_lock);
308 data->wdog_state &= ~v; 309 data->wdog_state &= ~v;
309 fscpos_write_value(client, reg, v); 310 fscpos_write_value(client, reg, v);
310 up(&data->update_lock); 311 mutex_unlock(&data->update_lock);
311 return count; 312 return count;
312} 313}
313 314
@@ -321,10 +322,10 @@ static ssize_t set_wdog_preset(struct i2c_client *client, struct fscpos_data
321{ 322{
322 unsigned long v = simple_strtoul(buf, NULL, 10) & 0xff; 323 unsigned long v = simple_strtoul(buf, NULL, 10) & 0xff;
323 324
324 down(&data->update_lock); 325 mutex_lock(&data->update_lock);
325 data->wdog_preset = v; 326 data->wdog_preset = v;
326 fscpos_write_value(client, reg, data->wdog_preset); 327 fscpos_write_value(client, reg, data->wdog_preset);
327 up(&data->update_lock); 328 mutex_unlock(&data->update_lock);
328 return count; 329 return count;
329} 330}
330 331
@@ -483,7 +484,7 @@ static int fscpos_detect(struct i2c_adapter *adapter, int address, int kind)
483 strlcpy(new_client->name, "fscpos", I2C_NAME_SIZE); 484 strlcpy(new_client->name, "fscpos", I2C_NAME_SIZE);
484 485
485 data->valid = 0; 486 data->valid = 0;
486 init_MUTEX(&data->update_lock); 487 mutex_init(&data->update_lock);
487 488
488 /* Tell the I2C layer a new client has arrived */ 489 /* Tell the I2C layer a new client has arrived */
489 if ((err = i2c_attach_client(new_client))) 490 if ((err = i2c_attach_client(new_client)))
@@ -579,7 +580,7 @@ static struct fscpos_data *fscpos_update_device(struct device *dev)
579 struct i2c_client *client = to_i2c_client(dev); 580 struct i2c_client *client = to_i2c_client(dev);
580 struct fscpos_data *data = i2c_get_clientdata(client); 581 struct fscpos_data *data = i2c_get_clientdata(client);
581 582
582 down(&data->update_lock); 583 mutex_lock(&data->update_lock);
583 584
584 if (time_after(jiffies, data->last_updated + 2 * HZ) || !data->valid) { 585 if (time_after(jiffies, data->last_updated + 2 * HZ) || !data->valid) {
585 int i; 586 int i;
@@ -625,7 +626,7 @@ static struct fscpos_data *fscpos_update_device(struct device *dev)
625 data->last_updated = jiffies; 626 data->last_updated = jiffies;
626 data->valid = 1; 627 data->valid = 1;
627 } 628 }
628 up(&data->update_lock); 629 mutex_unlock(&data->update_lock);
629 return data; 630 return data;
630} 631}
631 632
diff --git a/drivers/hwmon/gl518sm.c b/drivers/hwmon/gl518sm.c
index 9e685e3a3b..6606aabdb4 100644
--- a/drivers/hwmon/gl518sm.c
+++ b/drivers/hwmon/gl518sm.c
@@ -43,6 +43,7 @@
43#include <linux/i2c.h> 43#include <linux/i2c.h>
44#include <linux/hwmon.h> 44#include <linux/hwmon.h>
45#include <linux/err.h> 45#include <linux/err.h>
46#include <linux/mutex.h>
46 47
47/* Addresses to scan */ 48/* Addresses to scan */
48static unsigned short normal_i2c[] = { 0x2c, 0x2d, I2C_CLIENT_END }; 49static unsigned short normal_i2c[] = { 0x2c, 0x2d, I2C_CLIENT_END };
@@ -120,7 +121,7 @@ struct gl518_data {
120 struct class_device *class_dev; 121 struct class_device *class_dev;
121 enum chips type; 122 enum chips type;
122 123
123 struct semaphore update_lock; 124 struct mutex update_lock;
124 char valid; /* !=0 if following fields are valid */ 125 char valid; /* !=0 if following fields are valid */
125 unsigned long last_updated; /* In jiffies */ 126 unsigned long last_updated; /* In jiffies */
126 127
@@ -212,10 +213,10 @@ static ssize_t set_##suffix(struct device *dev, struct device_attribute *attr, c
212 struct gl518_data *data = i2c_get_clientdata(client); \ 213 struct gl518_data *data = i2c_get_clientdata(client); \
213 long val = simple_strtol(buf, NULL, 10); \ 214 long val = simple_strtol(buf, NULL, 10); \
214 \ 215 \
215 down(&data->update_lock); \ 216 mutex_lock(&data->update_lock); \
216 data->value = type##_TO_REG(val); \ 217 data->value = type##_TO_REG(val); \
217 gl518_write_value(client, reg, data->value); \ 218 gl518_write_value(client, reg, data->value); \
218 up(&data->update_lock); \ 219 mutex_unlock(&data->update_lock); \
219 return count; \ 220 return count; \
220} 221}
221 222
@@ -228,12 +229,12 @@ static ssize_t set_##suffix(struct device *dev, struct device_attribute *attr, c
228 int regvalue; \ 229 int regvalue; \
229 unsigned long val = simple_strtoul(buf, NULL, 10); \ 230 unsigned long val = simple_strtoul(buf, NULL, 10); \
230 \ 231 \
231 down(&data->update_lock); \ 232 mutex_lock(&data->update_lock); \
232 regvalue = gl518_read_value(client, reg); \ 233 regvalue = gl518_read_value(client, reg); \
233 data->value = type##_TO_REG(val); \ 234 data->value = type##_TO_REG(val); \
234 regvalue = (regvalue & ~mask) | (data->value << shift); \ 235 regvalue = (regvalue & ~mask) | (data->value << shift); \
235 gl518_write_value(client, reg, regvalue); \ 236 gl518_write_value(client, reg, regvalue); \
236 up(&data->update_lock); \ 237 mutex_unlock(&data->update_lock); \
237 return count; \ 238 return count; \
238} 239}
239 240
@@ -265,7 +266,7 @@ static ssize_t set_fan_min1(struct device *dev, struct device_attribute *attr, c
265 int regvalue; 266 int regvalue;
266 unsigned long val = simple_strtoul(buf, NULL, 10); 267 unsigned long val = simple_strtoul(buf, NULL, 10);
267 268
268 down(&data->update_lock); 269 mutex_lock(&data->update_lock);
269 regvalue = gl518_read_value(client, GL518_REG_FAN_LIMIT); 270 regvalue = gl518_read_value(client, GL518_REG_FAN_LIMIT);
270 data->fan_min[0] = FAN_TO_REG(val, 271 data->fan_min[0] = FAN_TO_REG(val,
271 DIV_FROM_REG(data->fan_div[0])); 272 DIV_FROM_REG(data->fan_div[0]));
@@ -280,7 +281,7 @@ static ssize_t set_fan_min1(struct device *dev, struct device_attribute *attr, c
280 data->beep_mask &= data->alarm_mask; 281 data->beep_mask &= data->alarm_mask;
281 gl518_write_value(client, GL518_REG_ALARM, data->beep_mask); 282 gl518_write_value(client, GL518_REG_ALARM, data->beep_mask);
282 283
283 up(&data->update_lock); 284 mutex_unlock(&data->update_lock);
284 return count; 285 return count;
285} 286}
286 287
@@ -291,7 +292,7 @@ static ssize_t set_fan_min2(struct device *dev, struct device_attribute *attr, c
291 int regvalue; 292 int regvalue;
292 unsigned long val = simple_strtoul(buf, NULL, 10); 293 unsigned long val = simple_strtoul(buf, NULL, 10);
293 294
294 down(&data->update_lock); 295 mutex_lock(&data->update_lock);
295 regvalue = gl518_read_value(client, GL518_REG_FAN_LIMIT); 296 regvalue = gl518_read_value(client, GL518_REG_FAN_LIMIT);
296 data->fan_min[1] = FAN_TO_REG(val, 297 data->fan_min[1] = FAN_TO_REG(val,
297 DIV_FROM_REG(data->fan_div[1])); 298 DIV_FROM_REG(data->fan_div[1]));
@@ -306,7 +307,7 @@ static ssize_t set_fan_min2(struct device *dev, struct device_attribute *attr, c
306 data->beep_mask &= data->alarm_mask; 307 data->beep_mask &= data->alarm_mask;
307 gl518_write_value(client, GL518_REG_ALARM, data->beep_mask); 308 gl518_write_value(client, GL518_REG_ALARM, data->beep_mask);
308 309
309 up(&data->update_lock); 310 mutex_unlock(&data->update_lock);
310 return count; 311 return count;
311} 312}
312 313
@@ -407,7 +408,7 @@ static int gl518_detect(struct i2c_adapter *adapter, int address, int kind)
407 strlcpy(new_client->name, "gl518sm", I2C_NAME_SIZE); 408 strlcpy(new_client->name, "gl518sm", I2C_NAME_SIZE);
408 data->type = kind; 409 data->type = kind;
409 data->valid = 0; 410 data->valid = 0;
410 init_MUTEX(&data->update_lock); 411 mutex_init(&data->update_lock);
411 412
412 /* Tell the I2C layer a new client has arrived */ 413 /* Tell the I2C layer a new client has arrived */
413 if ((err = i2c_attach_client(new_client))) 414 if ((err = i2c_attach_client(new_client)))
@@ -525,7 +526,7 @@ static struct gl518_data *gl518_update_device(struct device *dev)
525 struct gl518_data *data = i2c_get_clientdata(client); 526 struct gl518_data *data = i2c_get_clientdata(client);
526 int val; 527 int val;
527 528
528 down(&data->update_lock); 529 mutex_lock(&data->update_lock);
529 530
530 if (time_after(jiffies, data->last_updated + HZ + HZ / 2) 531 if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
531 || !data->valid) { 532 || !data->valid) {
@@ -586,7 +587,7 @@ static struct gl518_data *gl518_update_device(struct device *dev)
586 data->valid = 1; 587 data->valid = 1;
587 } 588 }
588 589
589 up(&data->update_lock); 590 mutex_unlock(&data->update_lock);
590 591
591 return data; 592 return data;
592} 593}
diff --git a/drivers/hwmon/gl520sm.c b/drivers/hwmon/gl520sm.c
index baee60e44b..14e810f3c2 100644
--- a/drivers/hwmon/gl520sm.c
+++ b/drivers/hwmon/gl520sm.c
@@ -29,6 +29,7 @@
29#include <linux/hwmon.h> 29#include <linux/hwmon.h>
30#include <linux/hwmon-vid.h> 30#include <linux/hwmon-vid.h>
31#include <linux/err.h> 31#include <linux/err.h>
32#include <linux/mutex.h>
32 33
33/* Type of the extra sensor */ 34/* Type of the extra sensor */
34static unsigned short extra_sensor_type; 35static unsigned short extra_sensor_type;
@@ -121,7 +122,7 @@ static struct i2c_driver gl520_driver = {
121struct gl520_data { 122struct gl520_data {
122 struct i2c_client client; 123 struct i2c_client client;
123 struct class_device *class_dev; 124 struct class_device *class_dev;
124 struct semaphore update_lock; 125 struct mutex update_lock;
125 char valid; /* zero until the following fields are valid */ 126 char valid; /* zero until the following fields are valid */
126 unsigned long last_updated; /* in jiffies */ 127 unsigned long last_updated; /* in jiffies */
127 128
@@ -303,7 +304,7 @@ static ssize_t set_in_min(struct i2c_client *client, struct gl520_data *data, co
303 long v = simple_strtol(buf, NULL, 10); 304 long v = simple_strtol(buf, NULL, 10);
304 u8 r; 305 u8 r;
305 306
306 down(&data->update_lock); 307 mutex_lock(&data->update_lock);
307 308
308 if (n == 0) 309 if (n == 0)
309 r = VDD_TO_REG(v); 310 r = VDD_TO_REG(v);
@@ -317,7 +318,7 @@ static ssize_t set_in_min(struct i2c_client *client, struct gl520_data *data, co
317 else 318 else
318 gl520_write_value(client, reg, r); 319 gl520_write_value(client, reg, r);
319 320
320 up(&data->update_lock); 321 mutex_unlock(&data->update_lock);
321 return count; 322 return count;
322} 323}
323 324
@@ -331,7 +332,7 @@ static ssize_t set_in_max(struct i2c_client *client, struct gl520_data *data, co
331 else 332 else
332 r = IN_TO_REG(v); 333 r = IN_TO_REG(v);
333 334
334 down(&data->update_lock); 335 mutex_lock(&data->update_lock);
335 336
336 data->in_max[n] = r; 337 data->in_max[n] = r;
337 338
@@ -340,7 +341,7 @@ static ssize_t set_in_max(struct i2c_client *client, struct gl520_data *data, co
340 else 341 else
341 gl520_write_value(client, reg, r); 342 gl520_write_value(client, reg, r);
342 343
343 up(&data->update_lock); 344 mutex_unlock(&data->update_lock);
344 return count; 345 return count;
345} 346}
346 347
@@ -373,7 +374,7 @@ static ssize_t set_fan_min(struct i2c_client *client, struct gl520_data *data, c
373 unsigned long v = simple_strtoul(buf, NULL, 10); 374 unsigned long v = simple_strtoul(buf, NULL, 10);
374 u8 r; 375 u8 r;
375 376
376 down(&data->update_lock); 377 mutex_lock(&data->update_lock);
377 r = FAN_TO_REG(v, data->fan_div[n - 1]); 378 r = FAN_TO_REG(v, data->fan_div[n - 1]);
378 data->fan_min[n - 1] = r; 379 data->fan_min[n - 1] = r;
379 380
@@ -390,7 +391,7 @@ static ssize_t set_fan_min(struct i2c_client *client, struct gl520_data *data, c
390 data->beep_mask &= data->alarm_mask; 391 data->beep_mask &= data->alarm_mask;
391 gl520_write_value(client, GL520_REG_BEEP_MASK, data->beep_mask); 392 gl520_write_value(client, GL520_REG_BEEP_MASK, data->beep_mask);
392 393
393 up(&data->update_lock); 394 mutex_unlock(&data->update_lock);
394 return count; 395 return count;
395} 396}
396 397
@@ -409,7 +410,7 @@ static ssize_t set_fan_div(struct i2c_client *client, struct gl520_data *data, c
409 return -EINVAL; 410 return -EINVAL;
410 } 411 }
411 412
412 down(&data->update_lock); 413 mutex_lock(&data->update_lock);
413 data->fan_div[n - 1] = r; 414 data->fan_div[n - 1] = r;
414 415
415 if (n == 1) 416 if (n == 1)
@@ -417,7 +418,7 @@ static ssize_t set_fan_div(struct i2c_client *client, struct gl520_data *data, c
417 else 418 else
418 gl520_write_value(client, reg, (gl520_read_value(client, reg) & ~0x30) | (r << 4)); 419 gl520_write_value(client, reg, (gl520_read_value(client, reg) & ~0x30) | (r << 4));
419 420
420 up(&data->update_lock); 421 mutex_unlock(&data->update_lock);
421 return count; 422 return count;
422} 423}
423 424
@@ -425,10 +426,10 @@ static ssize_t set_fan_off(struct i2c_client *client, struct gl520_data *data, c
425{ 426{
426 u8 r = simple_strtoul(buf, NULL, 10)?1:0; 427 u8 r = simple_strtoul(buf, NULL, 10)?1:0;
427 428
428 down(&data->update_lock); 429 mutex_lock(&data->update_lock);
429 data->fan_off = r; 430 data->fan_off = r;
430 gl520_write_value(client, reg, (gl520_read_value(client, reg) & ~0x0c) | (r << 2)); 431 gl520_write_value(client, reg, (gl520_read_value(client, reg) & ~0x0c) | (r << 2));
431 up(&data->update_lock); 432 mutex_unlock(&data->update_lock);
432 return count; 433 return count;
433} 434}
434 435
@@ -454,10 +455,10 @@ static ssize_t set_temp_max(struct i2c_client *client, struct gl520_data *data,
454{ 455{
455 long v = simple_strtol(buf, NULL, 10); 456 long v = simple_strtol(buf, NULL, 10);
456 457
457 down(&data->update_lock); 458 mutex_lock(&data->update_lock);
458 data->temp_max[n - 1] = TEMP_TO_REG(v);; 459 data->temp_max[n - 1] = TEMP_TO_REG(v);
459 gl520_write_value(client, reg, data->temp_max[n - 1]); 460 gl520_write_value(client, reg, data->temp_max[n - 1]);
460 up(&data->update_lock); 461 mutex_unlock(&data->update_lock);
461 return count; 462 return count;
462} 463}
463 464
@@ -465,10 +466,10 @@ static ssize_t set_temp_max_hyst(struct i2c_client *client, struct gl520_data *d
465{ 466{
466 long v = simple_strtol(buf, NULL, 10); 467 long v = simple_strtol(buf, NULL, 10);
467 468
468 down(&data->update_lock); 469 mutex_lock(&data->update_lock);
469 data->temp_max_hyst[n - 1] = TEMP_TO_REG(v); 470 data->temp_max_hyst[n - 1] = TEMP_TO_REG(v);
470 gl520_write_value(client, reg, data->temp_max_hyst[n - 1]); 471 gl520_write_value(client, reg, data->temp_max_hyst[n - 1]);
471 up(&data->update_lock); 472 mutex_unlock(&data->update_lock);
472 return count; 473 return count;
473} 474}
474 475
@@ -491,10 +492,10 @@ static ssize_t set_beep_enable(struct i2c_client *client, struct gl520_data *dat
491{ 492{
492 u8 r = simple_strtoul(buf, NULL, 10)?0:1; 493 u8 r = simple_strtoul(buf, NULL, 10)?0:1;
493 494
494 down(&data->update_lock); 495 mutex_lock(&data->update_lock);
495 data->beep_enable = !r; 496 data->beep_enable = !r;
496 gl520_write_value(client, reg, (gl520_read_value(client, reg) & ~0x04) | (r << 2)); 497 gl520_write_value(client, reg, (gl520_read_value(client, reg) & ~0x04) | (r << 2));
497 up(&data->update_lock); 498 mutex_unlock(&data->update_lock);
498 return count; 499 return count;
499} 500}
500 501
@@ -502,11 +503,11 @@ static ssize_t set_beep_mask(struct i2c_client *client, struct gl520_data *data,
502{ 503{
503 u8 r = simple_strtoul(buf, NULL, 10); 504 u8 r = simple_strtoul(buf, NULL, 10);
504 505
505 down(&data->update_lock); 506 mutex_lock(&data->update_lock);
506 r &= data->alarm_mask; 507 r &= data->alarm_mask;
507 data->beep_mask = r; 508 data->beep_mask = r;
508 gl520_write_value(client, reg, r); 509 gl520_write_value(client, reg, r);
509 up(&data->update_lock); 510 mutex_unlock(&data->update_lock);
510 return count; 511 return count;
511} 512}
512 513
@@ -561,7 +562,7 @@ static int gl520_detect(struct i2c_adapter *adapter, int address, int kind)
561 /* Fill in the remaining client fields */ 562 /* Fill in the remaining client fields */
562 strlcpy(new_client->name, "gl520sm", I2C_NAME_SIZE); 563 strlcpy(new_client->name, "gl520sm", I2C_NAME_SIZE);
563 data->valid = 0; 564 data->valid = 0;
564 init_MUTEX(&data->update_lock); 565 mutex_init(&data->update_lock);
565 566
566 /* Tell the I2C layer a new client has arrived */ 567 /* Tell the I2C layer a new client has arrived */
567 if ((err = i2c_attach_client(new_client))) 568 if ((err = i2c_attach_client(new_client)))
@@ -685,7 +686,7 @@ static struct gl520_data *gl520_update_device(struct device *dev)
685 struct gl520_data *data = i2c_get_clientdata(client); 686 struct gl520_data *data = i2c_get_clientdata(client);
686 int val; 687 int val;
687 688
688 down(&data->update_lock); 689 mutex_lock(&data->update_lock);
689 690
690 if (time_after(jiffies, data->last_updated + 2 * HZ) || !data->valid) { 691 if (time_after(jiffies, data->last_updated + 2 * HZ) || !data->valid) {
691 692
@@ -750,7 +751,7 @@ static struct gl520_data *gl520_update_device(struct device *dev)
750 data->valid = 1; 751 data->valid = 1;
751 } 752 }
752 753
753 up(&data->update_lock); 754 mutex_unlock(&data->update_lock);
754 755
755 return data; 756 return data;
756} 757}
diff --git a/drivers/hwmon/hdaps.c b/drivers/hwmon/hdaps.c
index 23a9e1ea8e..7636c1a58f 100644
--- a/drivers/hwmon/hdaps.c
+++ b/drivers/hwmon/hdaps.c
@@ -33,6 +33,7 @@
33#include <linux/module.h> 33#include <linux/module.h>
34#include <linux/timer.h> 34#include <linux/timer.h>
35#include <linux/dmi.h> 35#include <linux/dmi.h>
36#include <linux/mutex.h>
36#include <asm/io.h> 37#include <asm/io.h>
37 38
38#define HDAPS_LOW_PORT 0x1600 /* first port used by hdaps */ 39#define HDAPS_LOW_PORT 0x1600 /* first port used by hdaps */
@@ -70,10 +71,10 @@ static u8 km_activity;
70static int rest_x; 71static int rest_x;
71static int rest_y; 72static int rest_y;
72 73
73static DECLARE_MUTEX(hdaps_sem); 74static DEFINE_MUTEX(hdaps_mutex);
74 75
75/* 76/*
76 * __get_latch - Get the value from a given port. Callers must hold hdaps_sem. 77 * __get_latch - Get the value from a given port. Callers must hold hdaps_mutex.
77 */ 78 */
78static inline u8 __get_latch(u16 port) 79static inline u8 __get_latch(u16 port)
79{ 80{
@@ -82,7 +83,7 @@ static inline u8 __get_latch(u16 port)
82 83
83/* 84/*
84 * __check_latch - Check a port latch for a given value. Returns zero if the 85 * __check_latch - Check a port latch for a given value. Returns zero if the
85 * port contains the given value. Callers must hold hdaps_sem. 86 * port contains the given value. Callers must hold hdaps_mutex.
86 */ 87 */
87static inline int __check_latch(u16 port, u8 val) 88static inline int __check_latch(u16 port, u8 val)
88{ 89{
@@ -93,7 +94,7 @@ static inline int __check_latch(u16 port, u8 val)
93 94
94/* 95/*
95 * __wait_latch - Wait up to 100us for a port latch to get a certain value, 96 * __wait_latch - Wait up to 100us for a port latch to get a certain value,
96 * returning zero if the value is obtained. Callers must hold hdaps_sem. 97 * returning zero if the value is obtained. Callers must hold hdaps_mutex.
97 */ 98 */
98static int __wait_latch(u16 port, u8 val) 99static int __wait_latch(u16 port, u8 val)
99{ 100{
@@ -110,7 +111,7 @@ static int __wait_latch(u16 port, u8 val)
110 111
111/* 112/*
112 * __device_refresh - request a refresh from the accelerometer. Does not wait 113 * __device_refresh - request a refresh from the accelerometer. Does not wait
113 * for refresh to complete. Callers must hold hdaps_sem. 114 * for refresh to complete. Callers must hold hdaps_mutex.
114 */ 115 */
115static void __device_refresh(void) 116static void __device_refresh(void)
116{ 117{
@@ -124,7 +125,7 @@ static void __device_refresh(void)
124/* 125/*
125 * __device_refresh_sync - request a synchronous refresh from the 126 * __device_refresh_sync - request a synchronous refresh from the
126 * accelerometer. We wait for the refresh to complete. Returns zero if 127 * accelerometer. We wait for the refresh to complete. Returns zero if
127 * successful and nonzero on error. Callers must hold hdaps_sem. 128 * successful and nonzero on error. Callers must hold hdaps_mutex.
128 */ 129 */
129static int __device_refresh_sync(void) 130static int __device_refresh_sync(void)
130{ 131{
@@ -134,7 +135,7 @@ static int __device_refresh_sync(void)
134 135
135/* 136/*
136 * __device_complete - indicate to the accelerometer that we are done reading 137 * __device_complete - indicate to the accelerometer that we are done reading
137 * data, and then initiate an async refresh. Callers must hold hdaps_sem. 138 * data, and then initiate an async refresh. Callers must hold hdaps_mutex.
138 */ 139 */
139static inline void __device_complete(void) 140static inline void __device_complete(void)
140{ 141{
@@ -152,7 +153,7 @@ static int hdaps_readb_one(unsigned int port, u8 *val)
152{ 153{
153 int ret; 154 int ret;
154 155
155 down(&hdaps_sem); 156 mutex_lock(&hdaps_mutex);
156 157
157 /* do a sync refresh -- we need to be sure that we read fresh data */ 158 /* do a sync refresh -- we need to be sure that we read fresh data */
158 ret = __device_refresh_sync(); 159 ret = __device_refresh_sync();
@@ -163,7 +164,7 @@ static int hdaps_readb_one(unsigned int port, u8 *val)
163 __device_complete(); 164 __device_complete();
164 165
165out: 166out:
166 up(&hdaps_sem); 167 mutex_unlock(&hdaps_mutex);
167 return ret; 168 return ret;
168} 169}
169 170
@@ -198,9 +199,9 @@ static int hdaps_read_pair(unsigned int port1, unsigned int port2,
198{ 199{
199 int ret; 200 int ret;
200 201
201 down(&hdaps_sem); 202 mutex_lock(&hdaps_mutex);
202 ret = __hdaps_read_pair(port1, port2, val1, val2); 203 ret = __hdaps_read_pair(port1, port2, val1, val2);
203 up(&hdaps_sem); 204 mutex_unlock(&hdaps_mutex);
204 205
205 return ret; 206 return ret;
206} 207}
@@ -213,7 +214,7 @@ static int hdaps_device_init(void)
213{ 214{
214 int total, ret = -ENXIO; 215 int total, ret = -ENXIO;
215 216
216 down(&hdaps_sem); 217 mutex_lock(&hdaps_mutex);
217 218
218 outb(0x13, 0x1610); 219 outb(0x13, 0x1610);
219 outb(0x01, 0x161f); 220 outb(0x01, 0x161f);
@@ -279,7 +280,7 @@ static int hdaps_device_init(void)
279 } 280 }
280 281
281out: 282out:
282 up(&hdaps_sem); 283 mutex_unlock(&hdaps_mutex);
283 return ret; 284 return ret;
284} 285}
285 286
@@ -313,7 +314,7 @@ static struct platform_driver hdaps_driver = {
313}; 314};
314 315
315/* 316/*
316 * hdaps_calibrate - Set our "resting" values. Callers must hold hdaps_sem. 317 * hdaps_calibrate - Set our "resting" values. Callers must hold hdaps_mutex.
317 */ 318 */
318static void hdaps_calibrate(void) 319static void hdaps_calibrate(void)
319{ 320{
@@ -325,7 +326,7 @@ static void hdaps_mousedev_poll(unsigned long unused)
325 int x, y; 326 int x, y;
326 327
327 /* Cannot sleep. Try nonblockingly. If we fail, try again later. */ 328 /* Cannot sleep. Try nonblockingly. If we fail, try again later. */
328 if (down_trylock(&hdaps_sem)) { 329 if (!mutex_trylock(&hdaps_mutex)) {
329 mod_timer(&hdaps_timer,jiffies + HDAPS_POLL_PERIOD); 330 mod_timer(&hdaps_timer,jiffies + HDAPS_POLL_PERIOD);
330 return; 331 return;
331 } 332 }
@@ -340,7 +341,7 @@ static void hdaps_mousedev_poll(unsigned long unused)
340 mod_timer(&hdaps_timer, jiffies + HDAPS_POLL_PERIOD); 341 mod_timer(&hdaps_timer, jiffies + HDAPS_POLL_PERIOD);
341 342
342out: 343out:
343 up(&hdaps_sem); 344 mutex_unlock(&hdaps_mutex);
344} 345}
345 346
346 347
@@ -420,9 +421,9 @@ static ssize_t hdaps_calibrate_store(struct device *dev,
420 struct device_attribute *attr, 421 struct device_attribute *attr,
421 const char *buf, size_t count) 422 const char *buf, size_t count)
422{ 423{
423 down(&hdaps_sem); 424 mutex_lock(&hdaps_mutex);
424 hdaps_calibrate(); 425 hdaps_calibrate();
425 up(&hdaps_sem); 426 mutex_unlock(&hdaps_mutex);
426 427
427 return count; 428 return count;
428} 429}
diff --git a/drivers/hwmon/hwmon-vid.c b/drivers/hwmon/hwmon-vid.c
index e497274916..a74a44f16f 100644
--- a/drivers/hwmon/hwmon-vid.c
+++ b/drivers/hwmon/hwmon-vid.c
@@ -54,6 +54,10 @@
54 (IMVP-II). You can find more information in the datasheet of Max1718 54 (IMVP-II). You can find more information in the datasheet of Max1718
55 http://www.maxim-ic.com/quick_view2.cfm/qv_pk/2452 55 http://www.maxim-ic.com/quick_view2.cfm/qv_pk/2452
56 56
57 The 13 specification corresponds to the Intel Pentium M series. There
58 doesn't seem to be any named specification for these. The conversion
59 tables are detailed directly in the various Pentium M datasheets:
60 http://www.intel.com/design/intarch/pentiumm/docs_pentiumm.htm
57*/ 61*/
58 62
59/* vrm is the VRM/VRD document version multiplied by 10. 63/* vrm is the VRM/VRD document version multiplied by 10.
@@ -100,6 +104,8 @@ int vid_from_reg(int val, u8 vrm)
100 case 17: /* Intel IMVP-II */ 104 case 17: /* Intel IMVP-II */
101 return(val & 0x10 ? 975 - (val & 0xF) * 25 : 105 return(val & 0x10 ? 975 - (val & 0xF) * 25 :
102 1750 - val * 50); 106 1750 - val * 50);
107 case 13:
108 return(1708 - (val & 0x3f) * 16);
103 default: /* report 0 for unknown */ 109 default: /* report 0 for unknown */
104 printk(KERN_INFO "hwmon-vid: requested unknown VRM version\n"); 110 printk(KERN_INFO "hwmon-vid: requested unknown VRM version\n");
105 return 0; 111 return 0;
@@ -129,8 +135,9 @@ struct vrm_model {
129static struct vrm_model vrm_models[] = { 135static struct vrm_model vrm_models[] = {
130 {X86_VENDOR_AMD, 0x6, ANY, ANY, 90}, /* Athlon Duron etc */ 136 {X86_VENDOR_AMD, 0x6, ANY, ANY, 90}, /* Athlon Duron etc */
131 {X86_VENDOR_AMD, 0xF, ANY, ANY, 24}, /* Athlon 64, Opteron and above VRM 24 */ 137 {X86_VENDOR_AMD, 0xF, ANY, ANY, 24}, /* Athlon 64, Opteron and above VRM 24 */
132 {X86_VENDOR_INTEL, 0x6, 0x9, ANY, 85}, /* 0.13um too */ 138 {X86_VENDOR_INTEL, 0x6, 0x9, ANY, 13}, /* Pentium M (130 nm) */
133 {X86_VENDOR_INTEL, 0x6, 0xB, ANY, 85}, /* Tualatin */ 139 {X86_VENDOR_INTEL, 0x6, 0xB, ANY, 85}, /* Tualatin */
140 {X86_VENDOR_INTEL, 0x6, 0xD, ANY, 13}, /* Pentium M (90 nm) */
134 {X86_VENDOR_INTEL, 0x6, ANY, ANY, 82}, /* any P6 */ 141 {X86_VENDOR_INTEL, 0x6, ANY, ANY, 82}, /* any P6 */
135 {X86_VENDOR_INTEL, 0x7, ANY, ANY, 0}, /* Itanium */ 142 {X86_VENDOR_INTEL, 0x7, ANY, ANY, 0}, /* Itanium */
136 {X86_VENDOR_INTEL, 0xF, 0x0, ANY, 90}, /* P4 */ 143 {X86_VENDOR_INTEL, 0xF, 0x0, ANY, 90}, /* P4 */
diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c
index dddd3eb9b3..106fa01cdb 100644
--- a/drivers/hwmon/hwmon.c
+++ b/drivers/hwmon/hwmon.c
@@ -17,6 +17,7 @@
17#include <linux/idr.h> 17#include <linux/idr.h>
18#include <linux/hwmon.h> 18#include <linux/hwmon.h>
19#include <linux/gfp.h> 19#include <linux/gfp.h>
20#include <linux/spinlock.h>
20 21
21#define HWMON_ID_PREFIX "hwmon" 22#define HWMON_ID_PREFIX "hwmon"
22#define HWMON_ID_FORMAT HWMON_ID_PREFIX "%d" 23#define HWMON_ID_FORMAT HWMON_ID_PREFIX "%d"
@@ -24,6 +25,7 @@
24static struct class *hwmon_class; 25static struct class *hwmon_class;
25 26
26static DEFINE_IDR(hwmon_idr); 27static DEFINE_IDR(hwmon_idr);
28static DEFINE_SPINLOCK(idr_lock);
27 29
28/** 30/**
29 * hwmon_device_register - register w/ hwmon sysfs class 31 * hwmon_device_register - register w/ hwmon sysfs class
@@ -37,20 +39,30 @@ static DEFINE_IDR(hwmon_idr);
37struct class_device *hwmon_device_register(struct device *dev) 39struct class_device *hwmon_device_register(struct device *dev)
38{ 40{
39 struct class_device *cdev; 41 struct class_device *cdev;
40 int id; 42 int id, err;
41 43
42 if (idr_pre_get(&hwmon_idr, GFP_KERNEL) == 0) 44again:
45 if (unlikely(idr_pre_get(&hwmon_idr, GFP_KERNEL) == 0))
43 return ERR_PTR(-ENOMEM); 46 return ERR_PTR(-ENOMEM);
44 47
45 if (idr_get_new(&hwmon_idr, NULL, &id) < 0) 48 spin_lock(&idr_lock);
46 return ERR_PTR(-ENOMEM); 49 err = idr_get_new(&hwmon_idr, NULL, &id);
50 spin_unlock(&idr_lock);
51
52 if (unlikely(err == -EAGAIN))
53 goto again;
54 else if (unlikely(err))
55 return ERR_PTR(err);
47 56
48 id = id & MAX_ID_MASK; 57 id = id & MAX_ID_MASK;
49 cdev = class_device_create(hwmon_class, NULL, MKDEV(0,0), dev, 58 cdev = class_device_create(hwmon_class, NULL, MKDEV(0,0), dev,
50 HWMON_ID_FORMAT, id); 59 HWMON_ID_FORMAT, id);
51 60
52 if (IS_ERR(cdev)) 61 if (IS_ERR(cdev)) {
62 spin_lock(&idr_lock);
53 idr_remove(&hwmon_idr, id); 63 idr_remove(&hwmon_idr, id);
64 spin_unlock(&idr_lock);
65 }
54 66
55 return cdev; 67 return cdev;
56} 68}
@@ -64,9 +76,11 @@ void hwmon_device_unregister(struct class_device *cdev)
64{ 76{
65 int id; 77 int id;
66 78
67 if (sscanf(cdev->class_id, HWMON_ID_FORMAT, &id) == 1) { 79 if (likely(sscanf(cdev->class_id, HWMON_ID_FORMAT, &id) == 1)) {
68 class_device_unregister(cdev); 80 class_device_unregister(cdev);
81 spin_lock(&idr_lock);
69 idr_remove(&hwmon_idr, id); 82 idr_remove(&hwmon_idr, id);
83 spin_unlock(&idr_lock);
70 } else 84 } else
71 dev_dbg(cdev->dev, 85 dev_dbg(cdev->dev,
72 "hwmon_device_unregister() failed: bad class ID!\n"); 86 "hwmon_device_unregister() failed: bad class ID!\n");
diff --git a/drivers/hwmon/it87.c b/drivers/hwmon/it87.c
index d7a9401600..06df92b3ee 100644
--- a/drivers/hwmon/it87.c
+++ b/drivers/hwmon/it87.c
@@ -41,6 +41,7 @@
41#include <linux/hwmon-sysfs.h> 41#include <linux/hwmon-sysfs.h>
42#include <linux/hwmon-vid.h> 42#include <linux/hwmon-vid.h>
43#include <linux/err.h> 43#include <linux/err.h>
44#include <linux/mutex.h>
44#include <asm/io.h> 45#include <asm/io.h>
45 46
46 47
@@ -194,10 +195,10 @@ static int DIV_TO_REG(int val)
194struct it87_data { 195struct it87_data {
195 struct i2c_client client; 196 struct i2c_client client;
196 struct class_device *class_dev; 197 struct class_device *class_dev;
197 struct semaphore lock; 198 struct mutex lock;
198 enum chips type; 199 enum chips type;
199 200
200 struct semaphore update_lock; 201 struct mutex update_lock;
201 char valid; /* !=0 if following fields are valid */ 202 char valid; /* !=0 if following fields are valid */
202 unsigned long last_updated; /* In jiffies */ 203 unsigned long last_updated; /* In jiffies */
203 204
@@ -224,9 +225,8 @@ static int it87_isa_attach_adapter(struct i2c_adapter *adapter);
224static int it87_detect(struct i2c_adapter *adapter, int address, int kind); 225static int it87_detect(struct i2c_adapter *adapter, int address, int kind);
225static int it87_detach_client(struct i2c_client *client); 226static int it87_detach_client(struct i2c_client *client);
226 227
227static int it87_read_value(struct i2c_client *client, u8 register); 228static int it87_read_value(struct i2c_client *client, u8 reg);
228static int it87_write_value(struct i2c_client *client, u8 register, 229static int it87_write_value(struct i2c_client *client, u8 reg, u8 value);
229 u8 value);
230static struct it87_data *it87_update_device(struct device *dev); 230static struct it87_data *it87_update_device(struct device *dev);
231static int it87_check_pwm(struct i2c_client *client); 231static int it87_check_pwm(struct i2c_client *client);
232static void it87_init_client(struct i2c_client *client, struct it87_data *data); 232static void it87_init_client(struct i2c_client *client, struct it87_data *data);
@@ -290,11 +290,11 @@ static ssize_t set_in_min(struct device *dev, struct device_attribute *attr,
290 struct it87_data *data = i2c_get_clientdata(client); 290 struct it87_data *data = i2c_get_clientdata(client);
291 unsigned long val = simple_strtoul(buf, NULL, 10); 291 unsigned long val = simple_strtoul(buf, NULL, 10);
292 292
293 down(&data->update_lock); 293 mutex_lock(&data->update_lock);
294 data->in_min[nr] = IN_TO_REG(val); 294 data->in_min[nr] = IN_TO_REG(val);
295 it87_write_value(client, IT87_REG_VIN_MIN(nr), 295 it87_write_value(client, IT87_REG_VIN_MIN(nr),
296 data->in_min[nr]); 296 data->in_min[nr]);
297 up(&data->update_lock); 297 mutex_unlock(&data->update_lock);
298 return count; 298 return count;
299} 299}
300static ssize_t set_in_max(struct device *dev, struct device_attribute *attr, 300static ssize_t set_in_max(struct device *dev, struct device_attribute *attr,
@@ -307,11 +307,11 @@ static ssize_t set_in_max(struct device *dev, struct device_attribute *attr,
307 struct it87_data *data = i2c_get_clientdata(client); 307 struct it87_data *data = i2c_get_clientdata(client);
308 unsigned long val = simple_strtoul(buf, NULL, 10); 308 unsigned long val = simple_strtoul(buf, NULL, 10);
309 309
310 down(&data->update_lock); 310 mutex_lock(&data->update_lock);
311 data->in_max[nr] = IN_TO_REG(val); 311 data->in_max[nr] = IN_TO_REG(val);
312 it87_write_value(client, IT87_REG_VIN_MAX(nr), 312 it87_write_value(client, IT87_REG_VIN_MAX(nr),
313 data->in_max[nr]); 313 data->in_max[nr]);
314 up(&data->update_lock); 314 mutex_unlock(&data->update_lock);
315 return count; 315 return count;
316} 316}
317 317
@@ -381,10 +381,10 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
381 struct it87_data *data = i2c_get_clientdata(client); 381 struct it87_data *data = i2c_get_clientdata(client);
382 int val = simple_strtol(buf, NULL, 10); 382 int val = simple_strtol(buf, NULL, 10);
383 383
384 down(&data->update_lock); 384 mutex_lock(&data->update_lock);
385 data->temp_high[nr] = TEMP_TO_REG(val); 385 data->temp_high[nr] = TEMP_TO_REG(val);
386 it87_write_value(client, IT87_REG_TEMP_HIGH(nr), data->temp_high[nr]); 386 it87_write_value(client, IT87_REG_TEMP_HIGH(nr), data->temp_high[nr]);
387 up(&data->update_lock); 387 mutex_unlock(&data->update_lock);
388 return count; 388 return count;
389} 389}
390static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr, 390static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,
@@ -397,10 +397,10 @@ static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,
397 struct it87_data *data = i2c_get_clientdata(client); 397 struct it87_data *data = i2c_get_clientdata(client);
398 int val = simple_strtol(buf, NULL, 10); 398 int val = simple_strtol(buf, NULL, 10);
399 399
400 down(&data->update_lock); 400 mutex_lock(&data->update_lock);
401 data->temp_low[nr] = TEMP_TO_REG(val); 401 data->temp_low[nr] = TEMP_TO_REG(val);
402 it87_write_value(client, IT87_REG_TEMP_LOW(nr), data->temp_low[nr]); 402 it87_write_value(client, IT87_REG_TEMP_LOW(nr), data->temp_low[nr]);
403 up(&data->update_lock); 403 mutex_unlock(&data->update_lock);
404 return count; 404 return count;
405} 405}
406#define show_temp_offset(offset) \ 406#define show_temp_offset(offset) \
@@ -440,7 +440,7 @@ static ssize_t set_sensor(struct device *dev, struct device_attribute *attr,
440 struct it87_data *data = i2c_get_clientdata(client); 440 struct it87_data *data = i2c_get_clientdata(client);
441 int val = simple_strtol(buf, NULL, 10); 441 int val = simple_strtol(buf, NULL, 10);
442 442
443 down(&data->update_lock); 443 mutex_lock(&data->update_lock);
444 444
445 data->sensor &= ~(1 << nr); 445 data->sensor &= ~(1 << nr);
446 data->sensor &= ~(8 << nr); 446 data->sensor &= ~(8 << nr);
@@ -450,11 +450,11 @@ static ssize_t set_sensor(struct device *dev, struct device_attribute *attr,
450 else if (val == 2) 450 else if (val == 2)
451 data->sensor |= 8 << nr; 451 data->sensor |= 8 << nr;
452 else if (val != 0) { 452 else if (val != 0) {
453 up(&data->update_lock); 453 mutex_unlock(&data->update_lock);
454 return -EINVAL; 454 return -EINVAL;
455 } 455 }
456 it87_write_value(client, IT87_REG_TEMP_ENABLE, data->sensor); 456 it87_write_value(client, IT87_REG_TEMP_ENABLE, data->sensor);
457 up(&data->update_lock); 457 mutex_unlock(&data->update_lock);
458 return count; 458 return count;
459} 459}
460#define show_sensor_offset(offset) \ 460#define show_sensor_offset(offset) \
@@ -524,7 +524,7 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
524 int val = simple_strtol(buf, NULL, 10); 524 int val = simple_strtol(buf, NULL, 10);
525 u8 reg = it87_read_value(client, IT87_REG_FAN_DIV); 525 u8 reg = it87_read_value(client, IT87_REG_FAN_DIV);
526 526
527 down(&data->update_lock); 527 mutex_lock(&data->update_lock);
528 switch (nr) { 528 switch (nr) {
529 case 0: data->fan_div[nr] = reg & 0x07; break; 529 case 0: data->fan_div[nr] = reg & 0x07; break;
530 case 1: data->fan_div[nr] = (reg >> 3) & 0x07; break; 530 case 1: data->fan_div[nr] = (reg >> 3) & 0x07; break;
@@ -533,7 +533,7 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
533 533
534 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); 534 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
535 it87_write_value(client, IT87_REG_FAN_MIN(nr), data->fan_min[nr]); 535 it87_write_value(client, IT87_REG_FAN_MIN(nr), data->fan_min[nr]);
536 up(&data->update_lock); 536 mutex_unlock(&data->update_lock);
537 return count; 537 return count;
538} 538}
539static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, 539static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
@@ -548,7 +548,7 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
548 int i, min[3]; 548 int i, min[3];
549 u8 old; 549 u8 old;
550 550
551 down(&data->update_lock); 551 mutex_lock(&data->update_lock);
552 old = it87_read_value(client, IT87_REG_FAN_DIV); 552 old = it87_read_value(client, IT87_REG_FAN_DIV);
553 553
554 for (i = 0; i < 3; i++) 554 for (i = 0; i < 3; i++)
@@ -576,7 +576,7 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
576 data->fan_min[i]=FAN_TO_REG(min[i], DIV_FROM_REG(data->fan_div[i])); 576 data->fan_min[i]=FAN_TO_REG(min[i], DIV_FROM_REG(data->fan_div[i]));
577 it87_write_value(client, IT87_REG_FAN_MIN(i), data->fan_min[i]); 577 it87_write_value(client, IT87_REG_FAN_MIN(i), data->fan_min[i]);
578 } 578 }
579 up(&data->update_lock); 579 mutex_unlock(&data->update_lock);
580 return count; 580 return count;
581} 581}
582static ssize_t set_pwm_enable(struct device *dev, 582static ssize_t set_pwm_enable(struct device *dev,
@@ -589,7 +589,7 @@ static ssize_t set_pwm_enable(struct device *dev,
589 struct it87_data *data = i2c_get_clientdata(client); 589 struct it87_data *data = i2c_get_clientdata(client);
590 int val = simple_strtol(buf, NULL, 10); 590 int val = simple_strtol(buf, NULL, 10);
591 591
592 down(&data->update_lock); 592 mutex_lock(&data->update_lock);
593 593
594 if (val == 0) { 594 if (val == 0) {
595 int tmp; 595 int tmp;
@@ -606,11 +606,11 @@ static ssize_t set_pwm_enable(struct device *dev,
606 /* set saved pwm value, clear FAN_CTLX PWM mode bit */ 606 /* set saved pwm value, clear FAN_CTLX PWM mode bit */
607 it87_write_value(client, IT87_REG_PWM(nr), PWM_TO_REG(data->manual_pwm_ctl[nr])); 607 it87_write_value(client, IT87_REG_PWM(nr), PWM_TO_REG(data->manual_pwm_ctl[nr]));
608 } else { 608 } else {
609 up(&data->update_lock); 609 mutex_unlock(&data->update_lock);
610 return -EINVAL; 610 return -EINVAL;
611 } 611 }
612 612
613 up(&data->update_lock); 613 mutex_unlock(&data->update_lock);
614 return count; 614 return count;
615} 615}
616static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, 616static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
@@ -626,11 +626,11 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
626 if (val < 0 || val > 255) 626 if (val < 0 || val > 255)
627 return -EINVAL; 627 return -EINVAL;
628 628
629 down(&data->update_lock); 629 mutex_lock(&data->update_lock);
630 data->manual_pwm_ctl[nr] = val; 630 data->manual_pwm_ctl[nr] = val;
631 if (data->fan_main_ctrl & (1 << nr)) 631 if (data->fan_main_ctrl & (1 << nr))
632 it87_write_value(client, IT87_REG_PWM(nr), PWM_TO_REG(data->manual_pwm_ctl[nr])); 632 it87_write_value(client, IT87_REG_PWM(nr), PWM_TO_REG(data->manual_pwm_ctl[nr]));
633 up(&data->update_lock); 633 mutex_unlock(&data->update_lock);
634 return count; 634 return count;
635} 635}
636 636
@@ -776,7 +776,7 @@ static int it87_detect(struct i2c_adapter *adapter, int address, int kind)
776 776
777 new_client = &data->client; 777 new_client = &data->client;
778 if (is_isa) 778 if (is_isa)
779 init_MUTEX(&data->lock); 779 mutex_init(&data->lock);
780 i2c_set_clientdata(new_client, data); 780 i2c_set_clientdata(new_client, data);
781 new_client->addr = address; 781 new_client->addr = address;
782 new_client->adapter = adapter; 782 new_client->adapter = adapter;
@@ -823,7 +823,7 @@ static int it87_detect(struct i2c_adapter *adapter, int address, int kind)
823 strlcpy(new_client->name, name, I2C_NAME_SIZE); 823 strlcpy(new_client->name, name, I2C_NAME_SIZE);
824 data->type = kind; 824 data->type = kind;
825 data->valid = 0; 825 data->valid = 0;
826 init_MUTEX(&data->update_lock); 826 mutex_init(&data->update_lock);
827 827
828 /* Tell the I2C layer a new client has arrived */ 828 /* Tell the I2C layer a new client has arrived */
829 if ((err = i2c_attach_client(new_client))) 829 if ((err = i2c_attach_client(new_client)))
@@ -950,10 +950,10 @@ static int it87_read_value(struct i2c_client *client, u8 reg)
950 950
951 int res; 951 int res;
952 if (i2c_is_isa_client(client)) { 952 if (i2c_is_isa_client(client)) {
953 down(&data->lock); 953 mutex_lock(&data->lock);
954 outb_p(reg, client->addr + IT87_ADDR_REG_OFFSET); 954 outb_p(reg, client->addr + IT87_ADDR_REG_OFFSET);
955 res = inb_p(client->addr + IT87_DATA_REG_OFFSET); 955 res = inb_p(client->addr + IT87_DATA_REG_OFFSET);
956 up(&data->lock); 956 mutex_unlock(&data->lock);
957 return res; 957 return res;
958 } else 958 } else
959 return i2c_smbus_read_byte_data(client, reg); 959 return i2c_smbus_read_byte_data(client, reg);
@@ -969,10 +969,10 @@ static int it87_write_value(struct i2c_client *client, u8 reg, u8 value)
969 struct it87_data *data = i2c_get_clientdata(client); 969 struct it87_data *data = i2c_get_clientdata(client);
970 970
971 if (i2c_is_isa_client(client)) { 971 if (i2c_is_isa_client(client)) {
972 down(&data->lock); 972 mutex_lock(&data->lock);
973 outb_p(reg, client->addr + IT87_ADDR_REG_OFFSET); 973 outb_p(reg, client->addr + IT87_ADDR_REG_OFFSET);
974 outb_p(value, client->addr + IT87_DATA_REG_OFFSET); 974 outb_p(value, client->addr + IT87_DATA_REG_OFFSET);
975 up(&data->lock); 975 mutex_unlock(&data->lock);
976 return 0; 976 return 0;
977 } else 977 } else
978 return i2c_smbus_write_byte_data(client, reg, value); 978 return i2c_smbus_write_byte_data(client, reg, value);
@@ -1098,7 +1098,7 @@ static struct it87_data *it87_update_device(struct device *dev)
1098 struct it87_data *data = i2c_get_clientdata(client); 1098 struct it87_data *data = i2c_get_clientdata(client);
1099 int i; 1099 int i;
1100 1100
1101 down(&data->update_lock); 1101 mutex_lock(&data->update_lock);
1102 1102
1103 if (time_after(jiffies, data->last_updated + HZ + HZ / 2) 1103 if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
1104 || !data->valid) { 1104 || !data->valid) {
@@ -1160,7 +1160,7 @@ static struct it87_data *it87_update_device(struct device *dev)
1160 data->valid = 1; 1160 data->valid = 1;
1161 } 1161 }
1162 1162
1163 up(&data->update_lock); 1163 mutex_unlock(&data->update_lock);
1164 1164
1165 return data; 1165 return data;
1166} 1166}
diff --git a/drivers/hwmon/lm63.c b/drivers/hwmon/lm63.c
index 6b1aa7ef55..071f0fc6ad 100644
--- a/drivers/hwmon/lm63.c
+++ b/drivers/hwmon/lm63.c
@@ -45,6 +45,7 @@
45#include <linux/hwmon-sysfs.h> 45#include <linux/hwmon-sysfs.h>
46#include <linux/hwmon.h> 46#include <linux/hwmon.h>
47#include <linux/err.h> 47#include <linux/err.h>
48#include <linux/mutex.h>
48 49
49/* 50/*
50 * Addresses to scan 51 * Addresses to scan
@@ -153,7 +154,7 @@ static struct i2c_driver lm63_driver = {
153struct lm63_data { 154struct lm63_data {
154 struct i2c_client client; 155 struct i2c_client client;
155 struct class_device *class_dev; 156 struct class_device *class_dev;
156 struct semaphore update_lock; 157 struct mutex update_lock;
157 char valid; /* zero until following fields are valid */ 158 char valid; /* zero until following fields are valid */
158 unsigned long last_updated; /* in jiffies */ 159 unsigned long last_updated; /* in jiffies */
159 160
@@ -192,13 +193,13 @@ static ssize_t set_fan(struct device *dev, struct device_attribute *dummy,
192 struct lm63_data *data = i2c_get_clientdata(client); 193 struct lm63_data *data = i2c_get_clientdata(client);
193 unsigned long val = simple_strtoul(buf, NULL, 10); 194 unsigned long val = simple_strtoul(buf, NULL, 10);
194 195
195 down(&data->update_lock); 196 mutex_lock(&data->update_lock);
196 data->fan[1] = FAN_TO_REG(val); 197 data->fan[1] = FAN_TO_REG(val);
197 i2c_smbus_write_byte_data(client, LM63_REG_TACH_LIMIT_LSB, 198 i2c_smbus_write_byte_data(client, LM63_REG_TACH_LIMIT_LSB,
198 data->fan[1] & 0xFF); 199 data->fan[1] & 0xFF);
199 i2c_smbus_write_byte_data(client, LM63_REG_TACH_LIMIT_MSB, 200 i2c_smbus_write_byte_data(client, LM63_REG_TACH_LIMIT_MSB,
200 data->fan[1] >> 8); 201 data->fan[1] >> 8);
201 up(&data->update_lock); 202 mutex_unlock(&data->update_lock);
202 return count; 203 return count;
203} 204}
204 205
@@ -222,12 +223,12 @@ static ssize_t set_pwm1(struct device *dev, struct device_attribute *dummy,
222 return -EPERM; 223 return -EPERM;
223 224
224 val = simple_strtoul(buf, NULL, 10); 225 val = simple_strtoul(buf, NULL, 10);
225 down(&data->update_lock); 226 mutex_lock(&data->update_lock);
226 data->pwm1_value = val <= 0 ? 0 : 227 data->pwm1_value = val <= 0 ? 0 :
227 val >= 255 ? 2 * data->pwm1_freq : 228 val >= 255 ? 2 * data->pwm1_freq :
228 (val * data->pwm1_freq * 2 + 127) / 255; 229 (val * data->pwm1_freq * 2 + 127) / 255;
229 i2c_smbus_write_byte_data(client, LM63_REG_PWM_VALUE, data->pwm1_value); 230 i2c_smbus_write_byte_data(client, LM63_REG_PWM_VALUE, data->pwm1_value);
230 up(&data->update_lock); 231 mutex_unlock(&data->update_lock);
231 return count; 232 return count;
232} 233}
233 234
@@ -253,10 +254,10 @@ static ssize_t set_temp8(struct device *dev, struct device_attribute *dummy,
253 struct lm63_data *data = i2c_get_clientdata(client); 254 struct lm63_data *data = i2c_get_clientdata(client);
254 long val = simple_strtol(buf, NULL, 10); 255 long val = simple_strtol(buf, NULL, 10);
255 256
256 down(&data->update_lock); 257 mutex_lock(&data->update_lock);
257 data->temp8[1] = TEMP8_TO_REG(val); 258 data->temp8[1] = TEMP8_TO_REG(val);
258 i2c_smbus_write_byte_data(client, LM63_REG_LOCAL_HIGH, data->temp8[1]); 259 i2c_smbus_write_byte_data(client, LM63_REG_LOCAL_HIGH, data->temp8[1]);
259 up(&data->update_lock); 260 mutex_unlock(&data->update_lock);
260 return count; 261 return count;
261} 262}
262 263
@@ -284,13 +285,13 @@ static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr,
284 long val = simple_strtol(buf, NULL, 10); 285 long val = simple_strtol(buf, NULL, 10);
285 int nr = attr->index; 286 int nr = attr->index;
286 287
287 down(&data->update_lock); 288 mutex_lock(&data->update_lock);
288 data->temp11[nr] = TEMP11_TO_REG(val); 289 data->temp11[nr] = TEMP11_TO_REG(val);
289 i2c_smbus_write_byte_data(client, reg[(nr - 1) * 2], 290 i2c_smbus_write_byte_data(client, reg[(nr - 1) * 2],
290 data->temp11[nr] >> 8); 291 data->temp11[nr] >> 8);
291 i2c_smbus_write_byte_data(client, reg[(nr - 1) * 2 + 1], 292 i2c_smbus_write_byte_data(client, reg[(nr - 1) * 2 + 1],
292 data->temp11[nr] & 0xff); 293 data->temp11[nr] & 0xff);
293 up(&data->update_lock); 294 mutex_unlock(&data->update_lock);
294 return count; 295 return count;
295} 296}
296 297
@@ -314,11 +315,11 @@ static ssize_t set_temp2_crit_hyst(struct device *dev, struct device_attribute *
314 long val = simple_strtol(buf, NULL, 10); 315 long val = simple_strtol(buf, NULL, 10);
315 long hyst; 316 long hyst;
316 317
317 down(&data->update_lock); 318 mutex_lock(&data->update_lock);
318 hyst = TEMP8_FROM_REG(data->temp8[2]) - val; 319 hyst = TEMP8_FROM_REG(data->temp8[2]) - val;
319 i2c_smbus_write_byte_data(client, LM63_REG_REMOTE_TCRIT_HYST, 320 i2c_smbus_write_byte_data(client, LM63_REG_REMOTE_TCRIT_HYST,
320 HYST_TO_REG(hyst)); 321 HYST_TO_REG(hyst));
321 up(&data->update_lock); 322 mutex_unlock(&data->update_lock);
322 return count; 323 return count;
323} 324}
324 325
@@ -427,7 +428,7 @@ static int lm63_detect(struct i2c_adapter *adapter, int address, int kind)
427 428
428 strlcpy(new_client->name, "lm63", I2C_NAME_SIZE); 429 strlcpy(new_client->name, "lm63", I2C_NAME_SIZE);
429 data->valid = 0; 430 data->valid = 0;
430 init_MUTEX(&data->update_lock); 431 mutex_init(&data->update_lock);
431 432
432 /* Tell the I2C layer a new client has arrived */ 433 /* Tell the I2C layer a new client has arrived */
433 if ((err = i2c_attach_client(new_client))) 434 if ((err = i2c_attach_client(new_client)))
@@ -530,7 +531,7 @@ static struct lm63_data *lm63_update_device(struct device *dev)
530 struct i2c_client *client = to_i2c_client(dev); 531 struct i2c_client *client = to_i2c_client(dev);
531 struct lm63_data *data = i2c_get_clientdata(client); 532 struct lm63_data *data = i2c_get_clientdata(client);
532 533
533 down(&data->update_lock); 534 mutex_lock(&data->update_lock);
534 535
535 if (time_after(jiffies, data->last_updated + HZ) || !data->valid) { 536 if (time_after(jiffies, data->last_updated + HZ) || !data->valid) {
536 if (data->config & 0x04) { /* tachometer enabled */ 537 if (data->config & 0x04) { /* tachometer enabled */
@@ -582,7 +583,7 @@ static struct lm63_data *lm63_update_device(struct device *dev)
582 data->valid = 1; 583 data->valid = 1;
583 } 584 }
584 585
585 up(&data->update_lock); 586 mutex_unlock(&data->update_lock);
586 587
587 return data; 588 return data;
588} 589}
diff --git a/drivers/hwmon/lm75.c b/drivers/hwmon/lm75.c
index 74ca2c8c61..fc25b90ec2 100644
--- a/drivers/hwmon/lm75.c
+++ b/drivers/hwmon/lm75.c
@@ -25,6 +25,7 @@
25#include <linux/i2c.h> 25#include <linux/i2c.h>
26#include <linux/hwmon.h> 26#include <linux/hwmon.h>
27#include <linux/err.h> 27#include <linux/err.h>
28#include <linux/mutex.h>
28#include "lm75.h" 29#include "lm75.h"
29 30
30 31
@@ -47,7 +48,7 @@ I2C_CLIENT_INSMOD_1(lm75);
47struct lm75_data { 48struct lm75_data {
48 struct i2c_client client; 49 struct i2c_client client;
49 struct class_device *class_dev; 50 struct class_device *class_dev;
50 struct semaphore update_lock; 51 struct mutex update_lock;
51 char valid; /* !=0 if following fields are valid */ 52 char valid; /* !=0 if following fields are valid */
52 unsigned long last_updated; /* In jiffies */ 53 unsigned long last_updated; /* In jiffies */
53 u16 temp_input; /* Register values */ 54 u16 temp_input; /* Register values */
@@ -91,10 +92,10 @@ static ssize_t set_##value(struct device *dev, struct device_attribute *attr, co
91 struct lm75_data *data = i2c_get_clientdata(client); \ 92 struct lm75_data *data = i2c_get_clientdata(client); \
92 int temp = simple_strtoul(buf, NULL, 10); \ 93 int temp = simple_strtoul(buf, NULL, 10); \
93 \ 94 \
94 down(&data->update_lock); \ 95 mutex_lock(&data->update_lock); \
95 data->value = LM75_TEMP_TO_REG(temp); \ 96 data->value = LM75_TEMP_TO_REG(temp); \
96 lm75_write_value(client, reg, data->value); \ 97 lm75_write_value(client, reg, data->value); \
97 up(&data->update_lock); \ 98 mutex_unlock(&data->update_lock); \
98 return count; \ 99 return count; \
99} 100}
100set(temp_max, LM75_REG_TEMP_OS); 101set(temp_max, LM75_REG_TEMP_OS);
@@ -188,7 +189,7 @@ static int lm75_detect(struct i2c_adapter *adapter, int address, int kind)
188 /* Fill in the remaining client fields and put it into the global list */ 189 /* Fill in the remaining client fields and put it into the global list */
189 strlcpy(new_client->name, name, I2C_NAME_SIZE); 190 strlcpy(new_client->name, name, I2C_NAME_SIZE);
190 data->valid = 0; 191 data->valid = 0;
191 init_MUTEX(&data->update_lock); 192 mutex_init(&data->update_lock);
192 193
193 /* Tell the I2C layer a new client has arrived */ 194 /* Tell the I2C layer a new client has arrived */
194 if ((err = i2c_attach_client(new_client))) 195 if ((err = i2c_attach_client(new_client)))
@@ -264,7 +265,7 @@ static struct lm75_data *lm75_update_device(struct device *dev)
264 struct i2c_client *client = to_i2c_client(dev); 265 struct i2c_client *client = to_i2c_client(dev);
265 struct lm75_data *data = i2c_get_clientdata(client); 266 struct lm75_data *data = i2c_get_clientdata(client);
266 267
267 down(&data->update_lock); 268 mutex_lock(&data->update_lock);
268 269
269 if (time_after(jiffies, data->last_updated + HZ + HZ / 2) 270 if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
270 || !data->valid) { 271 || !data->valid) {
@@ -277,7 +278,7 @@ static struct lm75_data *lm75_update_device(struct device *dev)
277 data->valid = 1; 278 data->valid = 1;
278 } 279 }
279 280
280 up(&data->update_lock); 281 mutex_unlock(&data->update_lock);
281 282
282 return data; 283 return data;
283} 284}
diff --git a/drivers/hwmon/lm77.c b/drivers/hwmon/lm77.c
index df9e02aaa7..459cc97738 100644
--- a/drivers/hwmon/lm77.c
+++ b/drivers/hwmon/lm77.c
@@ -32,6 +32,7 @@
32#include <linux/i2c.h> 32#include <linux/i2c.h>
33#include <linux/hwmon.h> 33#include <linux/hwmon.h>
34#include <linux/err.h> 34#include <linux/err.h>
35#include <linux/mutex.h>
35 36
36/* Addresses to scan */ 37/* Addresses to scan */
37static unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, I2C_CLIENT_END }; 38static unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, I2C_CLIENT_END };
@@ -51,7 +52,7 @@ I2C_CLIENT_INSMOD_1(lm77);
51struct lm77_data { 52struct lm77_data {
52 struct i2c_client client; 53 struct i2c_client client;
53 struct class_device *class_dev; 54 struct class_device *class_dev;
54 struct semaphore update_lock; 55 struct mutex update_lock;
55 char valid; 56 char valid;
56 unsigned long last_updated; /* In jiffies */ 57 unsigned long last_updated; /* In jiffies */
57 int temp_input; /* Temperatures */ 58 int temp_input; /* Temperatures */
@@ -139,10 +140,10 @@ static ssize_t set_##value(struct device *dev, struct device_attribute *attr, co
139 struct lm77_data *data = i2c_get_clientdata(client); \ 140 struct lm77_data *data = i2c_get_clientdata(client); \
140 long val = simple_strtoul(buf, NULL, 10); \ 141 long val = simple_strtoul(buf, NULL, 10); \
141 \ 142 \
142 down(&data->update_lock); \ 143 mutex_lock(&data->update_lock); \
143 data->value = val; \ 144 data->value = val; \
144 lm77_write_value(client, reg, LM77_TEMP_TO_REG(data->value)); \ 145 lm77_write_value(client, reg, LM77_TEMP_TO_REG(data->value)); \
145 up(&data->update_lock); \ 146 mutex_unlock(&data->update_lock); \
146 return count; \ 147 return count; \
147} 148}
148 149
@@ -157,11 +158,11 @@ static ssize_t set_temp_crit_hyst(struct device *dev, struct device_attribute *a
157 struct lm77_data *data = i2c_get_clientdata(client); 158 struct lm77_data *data = i2c_get_clientdata(client);
158 unsigned long val = simple_strtoul(buf, NULL, 10); 159 unsigned long val = simple_strtoul(buf, NULL, 10);
159 160
160 down(&data->update_lock); 161 mutex_lock(&data->update_lock);
161 data->temp_hyst = data->temp_crit - val; 162 data->temp_hyst = data->temp_crit - val;
162 lm77_write_value(client, LM77_REG_TEMP_HYST, 163 lm77_write_value(client, LM77_REG_TEMP_HYST,
163 LM77_TEMP_TO_REG(data->temp_hyst)); 164 LM77_TEMP_TO_REG(data->temp_hyst));
164 up(&data->update_lock); 165 mutex_unlock(&data->update_lock);
165 return count; 166 return count;
166} 167}
167 168
@@ -173,7 +174,7 @@ static ssize_t set_temp_crit(struct device *dev, struct device_attribute *attr,
173 long val = simple_strtoul(buf, NULL, 10); 174 long val = simple_strtoul(buf, NULL, 10);
174 int oldcrithyst; 175 int oldcrithyst;
175 176
176 down(&data->update_lock); 177 mutex_lock(&data->update_lock);
177 oldcrithyst = data->temp_crit - data->temp_hyst; 178 oldcrithyst = data->temp_crit - data->temp_hyst;
178 data->temp_crit = val; 179 data->temp_crit = val;
179 data->temp_hyst = data->temp_crit - oldcrithyst; 180 data->temp_hyst = data->temp_crit - oldcrithyst;
@@ -181,7 +182,7 @@ static ssize_t set_temp_crit(struct device *dev, struct device_attribute *attr,
181 LM77_TEMP_TO_REG(data->temp_crit)); 182 LM77_TEMP_TO_REG(data->temp_crit));
182 lm77_write_value(client, LM77_REG_TEMP_HYST, 183 lm77_write_value(client, LM77_REG_TEMP_HYST,
183 LM77_TEMP_TO_REG(data->temp_hyst)); 184 LM77_TEMP_TO_REG(data->temp_hyst));
184 up(&data->update_lock); 185 mutex_unlock(&data->update_lock);
185 return count; 186 return count;
186} 187}
187 188
@@ -306,7 +307,7 @@ static int lm77_detect(struct i2c_adapter *adapter, int address, int kind)
306 /* Fill in the remaining client fields and put it into the global list */ 307 /* Fill in the remaining client fields and put it into the global list */
307 strlcpy(new_client->name, name, I2C_NAME_SIZE); 308 strlcpy(new_client->name, name, I2C_NAME_SIZE);
308 data->valid = 0; 309 data->valid = 0;
309 init_MUTEX(&data->update_lock); 310 mutex_init(&data->update_lock);
310 311
311 /* Tell the I2C layer a new client has arrived */ 312 /* Tell the I2C layer a new client has arrived */
312 if ((err = i2c_attach_client(new_client))) 313 if ((err = i2c_attach_client(new_client)))
@@ -380,7 +381,7 @@ static struct lm77_data *lm77_update_device(struct device *dev)
380 struct i2c_client *client = to_i2c_client(dev); 381 struct i2c_client *client = to_i2c_client(dev);
381 struct lm77_data *data = i2c_get_clientdata(client); 382 struct lm77_data *data = i2c_get_clientdata(client);
382 383
383 down(&data->update_lock); 384 mutex_lock(&data->update_lock);
384 385
385 if (time_after(jiffies, data->last_updated + HZ + HZ / 2) 386 if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
386 || !data->valid) { 387 || !data->valid) {
@@ -406,7 +407,7 @@ static struct lm77_data *lm77_update_device(struct device *dev)
406 data->valid = 1; 407 data->valid = 1;
407 } 408 }
408 409
409 up(&data->update_lock); 410 mutex_unlock(&data->update_lock);
410 411
411 return data; 412 return data;
412} 413}
diff --git a/drivers/hwmon/lm78.c b/drivers/hwmon/lm78.c
index e404001e20..94be3d797e 100644
--- a/drivers/hwmon/lm78.c
+++ b/drivers/hwmon/lm78.c
@@ -27,6 +27,7 @@
27#include <linux/hwmon.h> 27#include <linux/hwmon.h>
28#include <linux/hwmon-vid.h> 28#include <linux/hwmon-vid.h>
29#include <linux/err.h> 29#include <linux/err.h>
30#include <linux/mutex.h>
30#include <asm/io.h> 31#include <asm/io.h>
31 32
32/* Addresses to scan */ 33/* Addresses to scan */
@@ -131,10 +132,10 @@ static inline int TEMP_FROM_REG(s8 val)
131struct lm78_data { 132struct lm78_data {
132 struct i2c_client client; 133 struct i2c_client client;
133 struct class_device *class_dev; 134 struct class_device *class_dev;
134 struct semaphore lock; 135 struct mutex lock;
135 enum chips type; 136 enum chips type;
136 137
137 struct semaphore update_lock; 138 struct mutex update_lock;
138 char valid; /* !=0 if following fields are valid */ 139 char valid; /* !=0 if following fields are valid */
139 unsigned long last_updated; /* In jiffies */ 140 unsigned long last_updated; /* In jiffies */
140 141
@@ -157,8 +158,8 @@ static int lm78_isa_attach_adapter(struct i2c_adapter *adapter);
157static int lm78_detect(struct i2c_adapter *adapter, int address, int kind); 158static int lm78_detect(struct i2c_adapter *adapter, int address, int kind);
158static int lm78_detach_client(struct i2c_client *client); 159static int lm78_detach_client(struct i2c_client *client);
159 160
160static int lm78_read_value(struct i2c_client *client, u8 register); 161static int lm78_read_value(struct i2c_client *client, u8 reg);
161static int lm78_write_value(struct i2c_client *client, u8 register, u8 value); 162static int lm78_write_value(struct i2c_client *client, u8 reg, u8 value);
162static struct lm78_data *lm78_update_device(struct device *dev); 163static struct lm78_data *lm78_update_device(struct device *dev);
163static void lm78_init_client(struct i2c_client *client); 164static void lm78_init_client(struct i2c_client *client);
164 165
@@ -207,10 +208,10 @@ static ssize_t set_in_min(struct device *dev, const char *buf,
207 struct lm78_data *data = i2c_get_clientdata(client); 208 struct lm78_data *data = i2c_get_clientdata(client);
208 unsigned long val = simple_strtoul(buf, NULL, 10); 209 unsigned long val = simple_strtoul(buf, NULL, 10);
209 210
210 down(&data->update_lock); 211 mutex_lock(&data->update_lock);
211 data->in_min[nr] = IN_TO_REG(val); 212 data->in_min[nr] = IN_TO_REG(val);
212 lm78_write_value(client, LM78_REG_IN_MIN(nr), data->in_min[nr]); 213 lm78_write_value(client, LM78_REG_IN_MIN(nr), data->in_min[nr]);
213 up(&data->update_lock); 214 mutex_unlock(&data->update_lock);
214 return count; 215 return count;
215} 216}
216 217
@@ -221,10 +222,10 @@ static ssize_t set_in_max(struct device *dev, const char *buf,
221 struct lm78_data *data = i2c_get_clientdata(client); 222 struct lm78_data *data = i2c_get_clientdata(client);
222 unsigned long val = simple_strtoul(buf, NULL, 10); 223 unsigned long val = simple_strtoul(buf, NULL, 10);
223 224
224 down(&data->update_lock); 225 mutex_lock(&data->update_lock);
225 data->in_max[nr] = IN_TO_REG(val); 226 data->in_max[nr] = IN_TO_REG(val);
226 lm78_write_value(client, LM78_REG_IN_MAX(nr), data->in_max[nr]); 227 lm78_write_value(client, LM78_REG_IN_MAX(nr), data->in_max[nr]);
227 up(&data->update_lock); 228 mutex_unlock(&data->update_lock);
228 return count; 229 return count;
229} 230}
230 231
@@ -288,10 +289,10 @@ static ssize_t set_temp_over(struct device *dev, struct device_attribute *attr,
288 struct lm78_data *data = i2c_get_clientdata(client); 289 struct lm78_data *data = i2c_get_clientdata(client);
289 long val = simple_strtol(buf, NULL, 10); 290 long val = simple_strtol(buf, NULL, 10);
290 291
291 down(&data->update_lock); 292 mutex_lock(&data->update_lock);
292 data->temp_over = TEMP_TO_REG(val); 293 data->temp_over = TEMP_TO_REG(val);
293 lm78_write_value(client, LM78_REG_TEMP_OVER, data->temp_over); 294 lm78_write_value(client, LM78_REG_TEMP_OVER, data->temp_over);
294 up(&data->update_lock); 295 mutex_unlock(&data->update_lock);
295 return count; 296 return count;
296} 297}
297 298
@@ -307,10 +308,10 @@ static ssize_t set_temp_hyst(struct device *dev, struct device_attribute *attr,
307 struct lm78_data *data = i2c_get_clientdata(client); 308 struct lm78_data *data = i2c_get_clientdata(client);
308 long val = simple_strtol(buf, NULL, 10); 309 long val = simple_strtol(buf, NULL, 10);
309 310
310 down(&data->update_lock); 311 mutex_lock(&data->update_lock);
311 data->temp_hyst = TEMP_TO_REG(val); 312 data->temp_hyst = TEMP_TO_REG(val);
312 lm78_write_value(client, LM78_REG_TEMP_HYST, data->temp_hyst); 313 lm78_write_value(client, LM78_REG_TEMP_HYST, data->temp_hyst);
313 up(&data->update_lock); 314 mutex_unlock(&data->update_lock);
314 return count; 315 return count;
315} 316}
316 317
@@ -342,10 +343,10 @@ static ssize_t set_fan_min(struct device *dev, const char *buf,
342 struct lm78_data *data = i2c_get_clientdata(client); 343 struct lm78_data *data = i2c_get_clientdata(client);
343 unsigned long val = simple_strtoul(buf, NULL, 10); 344 unsigned long val = simple_strtoul(buf, NULL, 10);
344 345
345 down(&data->update_lock); 346 mutex_lock(&data->update_lock);
346 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); 347 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
347 lm78_write_value(client, LM78_REG_FAN_MIN(nr), data->fan_min[nr]); 348 lm78_write_value(client, LM78_REG_FAN_MIN(nr), data->fan_min[nr]);
348 up(&data->update_lock); 349 mutex_unlock(&data->update_lock);
349 return count; 350 return count;
350} 351}
351 352
@@ -368,7 +369,7 @@ static ssize_t set_fan_div(struct device *dev, const char *buf,
368 unsigned long min; 369 unsigned long min;
369 u8 reg; 370 u8 reg;
370 371
371 down(&data->update_lock); 372 mutex_lock(&data->update_lock);
372 min = FAN_FROM_REG(data->fan_min[nr], 373 min = FAN_FROM_REG(data->fan_min[nr],
373 DIV_FROM_REG(data->fan_div[nr])); 374 DIV_FROM_REG(data->fan_div[nr]));
374 375
@@ -380,7 +381,7 @@ static ssize_t set_fan_div(struct device *dev, const char *buf,
380 default: 381 default:
381 dev_err(&client->dev, "fan_div value %ld not " 382 dev_err(&client->dev, "fan_div value %ld not "
382 "supported. Choose one of 1, 2, 4 or 8!\n", val); 383 "supported. Choose one of 1, 2, 4 or 8!\n", val);
383 up(&data->update_lock); 384 mutex_unlock(&data->update_lock);
384 return -EINVAL; 385 return -EINVAL;
385 } 386 }
386 387
@@ -398,7 +399,7 @@ static ssize_t set_fan_div(struct device *dev, const char *buf,
398 data->fan_min[nr] = 399 data->fan_min[nr] =
399 FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr])); 400 FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr]));
400 lm78_write_value(client, LM78_REG_FAN_MIN(nr), data->fan_min[nr]); 401 lm78_write_value(client, LM78_REG_FAN_MIN(nr), data->fan_min[nr]);
401 up(&data->update_lock); 402 mutex_unlock(&data->update_lock);
402 403
403 return count; 404 return count;
404} 405}
@@ -548,7 +549,7 @@ static int lm78_detect(struct i2c_adapter *adapter, int address, int kind)
548 549
549 new_client = &data->client; 550 new_client = &data->client;
550 if (is_isa) 551 if (is_isa)
551 init_MUTEX(&data->lock); 552 mutex_init(&data->lock);
552 i2c_set_clientdata(new_client, data); 553 i2c_set_clientdata(new_client, data);
553 new_client->addr = address; 554 new_client->addr = address;
554 new_client->adapter = adapter; 555 new_client->adapter = adapter;
@@ -598,7 +599,7 @@ static int lm78_detect(struct i2c_adapter *adapter, int address, int kind)
598 data->type = kind; 599 data->type = kind;
599 600
600 data->valid = 0; 601 data->valid = 0;
601 init_MUTEX(&data->update_lock); 602 mutex_init(&data->update_lock);
602 603
603 /* Tell the I2C layer a new client has arrived */ 604 /* Tell the I2C layer a new client has arrived */
604 if ((err = i2c_attach_client(new_client))) 605 if ((err = i2c_attach_client(new_client)))
@@ -697,10 +698,10 @@ static int lm78_read_value(struct i2c_client *client, u8 reg)
697 int res; 698 int res;
698 if (i2c_is_isa_client(client)) { 699 if (i2c_is_isa_client(client)) {
699 struct lm78_data *data = i2c_get_clientdata(client); 700 struct lm78_data *data = i2c_get_clientdata(client);
700 down(&data->lock); 701 mutex_lock(&data->lock);
701 outb_p(reg, client->addr + LM78_ADDR_REG_OFFSET); 702 outb_p(reg, client->addr + LM78_ADDR_REG_OFFSET);
702 res = inb_p(client->addr + LM78_DATA_REG_OFFSET); 703 res = inb_p(client->addr + LM78_DATA_REG_OFFSET);
703 up(&data->lock); 704 mutex_unlock(&data->lock);
704 return res; 705 return res;
705 } else 706 } else
706 return i2c_smbus_read_byte_data(client, reg); 707 return i2c_smbus_read_byte_data(client, reg);
@@ -717,10 +718,10 @@ static int lm78_write_value(struct i2c_client *client, u8 reg, u8 value)
717{ 718{
718 if (i2c_is_isa_client(client)) { 719 if (i2c_is_isa_client(client)) {
719 struct lm78_data *data = i2c_get_clientdata(client); 720 struct lm78_data *data = i2c_get_clientdata(client);
720 down(&data->lock); 721 mutex_lock(&data->lock);
721 outb_p(reg, client->addr + LM78_ADDR_REG_OFFSET); 722 outb_p(reg, client->addr + LM78_ADDR_REG_OFFSET);
722 outb_p(value, client->addr + LM78_DATA_REG_OFFSET); 723 outb_p(value, client->addr + LM78_DATA_REG_OFFSET);
723 up(&data->lock); 724 mutex_unlock(&data->lock);
724 return 0; 725 return 0;
725 } else 726 } else
726 return i2c_smbus_write_byte_data(client, reg, value); 727 return i2c_smbus_write_byte_data(client, reg, value);
@@ -742,7 +743,7 @@ static struct lm78_data *lm78_update_device(struct device *dev)
742 struct lm78_data *data = i2c_get_clientdata(client); 743 struct lm78_data *data = i2c_get_clientdata(client);
743 int i; 744 int i;
744 745
745 down(&data->update_lock); 746 mutex_lock(&data->update_lock);
746 747
747 if (time_after(jiffies, data->last_updated + HZ + HZ / 2) 748 if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
748 || !data->valid) { 749 || !data->valid) {
@@ -786,7 +787,7 @@ static struct lm78_data *lm78_update_device(struct device *dev)
786 data->fan_div[2] = 1; 787 data->fan_div[2] = 1;
787 } 788 }
788 789
789 up(&data->update_lock); 790 mutex_unlock(&data->update_lock);
790 791
791 return data; 792 return data;
792} 793}
diff --git a/drivers/hwmon/lm80.c b/drivers/hwmon/lm80.c
index c9a7cdea7b..f72120d08c 100644
--- a/drivers/hwmon/lm80.c
+++ b/drivers/hwmon/lm80.c
@@ -28,6 +28,7 @@
28#include <linux/i2c.h> 28#include <linux/i2c.h>
29#include <linux/hwmon.h> 29#include <linux/hwmon.h>
30#include <linux/err.h> 30#include <linux/err.h>
31#include <linux/mutex.h>
31 32
32/* Addresses to scan */ 33/* Addresses to scan */
33static unsigned short normal_i2c[] = { 0x28, 0x29, 0x2a, 0x2b, 0x2c, 34static unsigned short normal_i2c[] = { 0x28, 0x29, 0x2a, 0x2b, 0x2c,
@@ -108,7 +109,7 @@ static inline long TEMP_FROM_REG(u16 temp)
108struct lm80_data { 109struct lm80_data {
109 struct i2c_client client; 110 struct i2c_client client;
110 struct class_device *class_dev; 111 struct class_device *class_dev;
111 struct semaphore update_lock; 112 struct mutex update_lock;
112 char valid; /* !=0 if following fields are valid */ 113 char valid; /* !=0 if following fields are valid */
113 unsigned long last_updated; /* In jiffies */ 114 unsigned long last_updated; /* In jiffies */
114 115
@@ -191,10 +192,10 @@ static ssize_t set_in_##suffix(struct device *dev, struct device_attribute *attr
191 struct lm80_data *data = i2c_get_clientdata(client); \ 192 struct lm80_data *data = i2c_get_clientdata(client); \
192 long val = simple_strtol(buf, NULL, 10); \ 193 long val = simple_strtol(buf, NULL, 10); \
193 \ 194 \
194 down(&data->update_lock);\ 195 mutex_lock(&data->update_lock);\
195 data->value = IN_TO_REG(val); \ 196 data->value = IN_TO_REG(val); \
196 lm80_write_value(client, reg, data->value); \ 197 lm80_write_value(client, reg, data->value); \
197 up(&data->update_lock);\ 198 mutex_unlock(&data->update_lock);\
198 return count; \ 199 return count; \
199} 200}
200set_in(min0, in_min[0], LM80_REG_IN_MIN(0)); 201set_in(min0, in_min[0], LM80_REG_IN_MIN(0));
@@ -241,10 +242,10 @@ static ssize_t set_fan_##suffix(struct device *dev, struct device_attribute *att
241 struct lm80_data *data = i2c_get_clientdata(client); \ 242 struct lm80_data *data = i2c_get_clientdata(client); \
242 long val = simple_strtoul(buf, NULL, 10); \ 243 long val = simple_strtoul(buf, NULL, 10); \
243 \ 244 \
244 down(&data->update_lock);\ 245 mutex_lock(&data->update_lock);\
245 data->value = FAN_TO_REG(val, DIV_FROM_REG(data->div)); \ 246 data->value = FAN_TO_REG(val, DIV_FROM_REG(data->div)); \
246 lm80_write_value(client, reg, data->value); \ 247 lm80_write_value(client, reg, data->value); \
247 up(&data->update_lock);\ 248 mutex_unlock(&data->update_lock);\
248 return count; \ 249 return count; \
249} 250}
250set_fan(min1, fan_min[0], LM80_REG_FAN_MIN(1), fan_div[0]); 251set_fan(min1, fan_min[0], LM80_REG_FAN_MIN(1), fan_div[0]);
@@ -263,7 +264,7 @@ static ssize_t set_fan_div(struct device *dev, const char *buf,
263 u8 reg; 264 u8 reg;
264 265
265 /* Save fan_min */ 266 /* Save fan_min */
266 down(&data->update_lock); 267 mutex_lock(&data->update_lock);
267 min = FAN_FROM_REG(data->fan_min[nr], 268 min = FAN_FROM_REG(data->fan_min[nr],
268 DIV_FROM_REG(data->fan_div[nr])); 269 DIV_FROM_REG(data->fan_div[nr]));
269 270
@@ -275,7 +276,7 @@ static ssize_t set_fan_div(struct device *dev, const char *buf,
275 default: 276 default:
276 dev_err(&client->dev, "fan_div value %ld not " 277 dev_err(&client->dev, "fan_div value %ld not "
277 "supported. Choose one of 1, 2, 4 or 8!\n", val); 278 "supported. Choose one of 1, 2, 4 or 8!\n", val);
278 up(&data->update_lock); 279 mutex_unlock(&data->update_lock);
279 return -EINVAL; 280 return -EINVAL;
280 } 281 }
281 282
@@ -286,7 +287,7 @@ static ssize_t set_fan_div(struct device *dev, const char *buf,
286 /* Restore fan_min */ 287 /* Restore fan_min */
287 data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr])); 288 data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr]));
288 lm80_write_value(client, LM80_REG_FAN_MIN(nr + 1), data->fan_min[nr]); 289 lm80_write_value(client, LM80_REG_FAN_MIN(nr + 1), data->fan_min[nr]);
289 up(&data->update_lock); 290 mutex_unlock(&data->update_lock);
290 291
291 return count; 292 return count;
292} 293}
@@ -325,10 +326,10 @@ static ssize_t set_temp_##suffix(struct device *dev, struct device_attribute *at
325 struct lm80_data *data = i2c_get_clientdata(client); \ 326 struct lm80_data *data = i2c_get_clientdata(client); \
326 long val = simple_strtoul(buf, NULL, 10); \ 327 long val = simple_strtoul(buf, NULL, 10); \
327 \ 328 \
328 down(&data->update_lock); \ 329 mutex_lock(&data->update_lock); \
329 data->value = TEMP_LIMIT_TO_REG(val); \ 330 data->value = TEMP_LIMIT_TO_REG(val); \
330 lm80_write_value(client, reg, data->value); \ 331 lm80_write_value(client, reg, data->value); \
331 up(&data->update_lock); \ 332 mutex_unlock(&data->update_lock); \
332 return count; \ 333 return count; \
333} 334}
334set_temp(hot_max, temp_hot_max, LM80_REG_TEMP_HOT_MAX); 335set_temp(hot_max, temp_hot_max, LM80_REG_TEMP_HOT_MAX);
@@ -437,7 +438,7 @@ static int lm80_detect(struct i2c_adapter *adapter, int address, int kind)
437 /* Fill in the remaining client fields and put it into the global list */ 438 /* Fill in the remaining client fields and put it into the global list */
438 strlcpy(new_client->name, name, I2C_NAME_SIZE); 439 strlcpy(new_client->name, name, I2C_NAME_SIZE);
439 data->valid = 0; 440 data->valid = 0;
440 init_MUTEX(&data->update_lock); 441 mutex_init(&data->update_lock);
441 442
442 /* Tell the I2C layer a new client has arrived */ 443 /* Tell the I2C layer a new client has arrived */
443 if ((err = i2c_attach_client(new_client))) 444 if ((err = i2c_attach_client(new_client)))
@@ -545,7 +546,7 @@ static struct lm80_data *lm80_update_device(struct device *dev)
545 struct lm80_data *data = i2c_get_clientdata(client); 546 struct lm80_data *data = i2c_get_clientdata(client);
546 int i; 547 int i;
547 548
548 down(&data->update_lock); 549 mutex_lock(&data->update_lock);
549 550
550 if (time_after(jiffies, data->last_updated + 2 * HZ) || !data->valid) { 551 if (time_after(jiffies, data->last_updated + 2 * HZ) || !data->valid) {
551 dev_dbg(&client->dev, "Starting lm80 update\n"); 552 dev_dbg(&client->dev, "Starting lm80 update\n");
@@ -585,7 +586,7 @@ static struct lm80_data *lm80_update_device(struct device *dev)
585 data->valid = 1; 586 data->valid = 1;
586 } 587 }
587 588
588 up(&data->update_lock); 589 mutex_unlock(&data->update_lock);
589 590
590 return data; 591 return data;
591} 592}
diff --git a/drivers/hwmon/lm83.c b/drivers/hwmon/lm83.c
index 26dfa9e216..aac4ec2bf6 100644
--- a/drivers/hwmon/lm83.c
+++ b/drivers/hwmon/lm83.c
@@ -35,6 +35,7 @@
35#include <linux/hwmon-sysfs.h> 35#include <linux/hwmon-sysfs.h>
36#include <linux/hwmon.h> 36#include <linux/hwmon.h>
37#include <linux/err.h> 37#include <linux/err.h>
38#include <linux/mutex.h>
38 39
39/* 40/*
40 * Addresses to scan 41 * Addresses to scan
@@ -139,7 +140,7 @@ static struct i2c_driver lm83_driver = {
139struct lm83_data { 140struct lm83_data {
140 struct i2c_client client; 141 struct i2c_client client;
141 struct class_device *class_dev; 142 struct class_device *class_dev;
142 struct semaphore update_lock; 143 struct mutex update_lock;
143 char valid; /* zero until following fields are valid */ 144 char valid; /* zero until following fields are valid */
144 unsigned long last_updated; /* in jiffies */ 145 unsigned long last_updated; /* in jiffies */
145 146
@@ -171,11 +172,11 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *devattr,
171 long val = simple_strtol(buf, NULL, 10); 172 long val = simple_strtol(buf, NULL, 10);
172 int nr = attr->index; 173 int nr = attr->index;
173 174
174 down(&data->update_lock); 175 mutex_lock(&data->update_lock);
175 data->temp[nr] = TEMP_TO_REG(val); 176 data->temp[nr] = TEMP_TO_REG(val);
176 i2c_smbus_write_byte_data(client, LM83_REG_W_HIGH[nr - 4], 177 i2c_smbus_write_byte_data(client, LM83_REG_W_HIGH[nr - 4],
177 data->temp[nr]); 178 data->temp[nr]);
178 up(&data->update_lock); 179 mutex_unlock(&data->update_lock);
179 return count; 180 return count;
180} 181}
181 182
@@ -300,7 +301,7 @@ static int lm83_detect(struct i2c_adapter *adapter, int address, int kind)
300 /* We can fill in the remaining client fields */ 301 /* We can fill in the remaining client fields */
301 strlcpy(new_client->name, name, I2C_NAME_SIZE); 302 strlcpy(new_client->name, name, I2C_NAME_SIZE);
302 data->valid = 0; 303 data->valid = 0;
303 init_MUTEX(&data->update_lock); 304 mutex_init(&data->update_lock);
304 305
305 /* Tell the I2C layer a new client has arrived */ 306 /* Tell the I2C layer a new client has arrived */
306 if ((err = i2c_attach_client(new_client))) 307 if ((err = i2c_attach_client(new_client)))
@@ -373,7 +374,7 @@ static struct lm83_data *lm83_update_device(struct device *dev)
373 struct i2c_client *client = to_i2c_client(dev); 374 struct i2c_client *client = to_i2c_client(dev);
374 struct lm83_data *data = i2c_get_clientdata(client); 375 struct lm83_data *data = i2c_get_clientdata(client);
375 376
376 down(&data->update_lock); 377 mutex_lock(&data->update_lock);
377 378
378 if (time_after(jiffies, data->last_updated + HZ * 2) || !data->valid) { 379 if (time_after(jiffies, data->last_updated + HZ * 2) || !data->valid) {
379 int nr; 380 int nr;
@@ -393,7 +394,7 @@ static struct lm83_data *lm83_update_device(struct device *dev)
393 data->valid = 1; 394 data->valid = 1;
394 } 395 }
395 396
396 up(&data->update_lock); 397 mutex_unlock(&data->update_lock);
397 398
398 return data; 399 return data;
399} 400}
diff --git a/drivers/hwmon/lm85.c b/drivers/hwmon/lm85.c
index 7389a01275..342e966311 100644
--- a/drivers/hwmon/lm85.c
+++ b/drivers/hwmon/lm85.c
@@ -31,6 +31,7 @@
31#include <linux/hwmon.h> 31#include <linux/hwmon.h>
32#include <linux/hwmon-vid.h> 32#include <linux/hwmon-vid.h>
33#include <linux/err.h> 33#include <linux/err.h>
34#include <linux/mutex.h>
34 35
35/* Addresses to scan */ 36/* Addresses to scan */
36static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END }; 37static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END };
@@ -331,10 +332,10 @@ struct lm85_autofan {
331struct lm85_data { 332struct lm85_data {
332 struct i2c_client client; 333 struct i2c_client client;
333 struct class_device *class_dev; 334 struct class_device *class_dev;
334 struct semaphore lock; 335 struct mutex lock;
335 enum chips type; 336 enum chips type;
336 337
337 struct semaphore update_lock; 338 struct mutex update_lock;
338 int valid; /* !=0 if following fields are valid */ 339 int valid; /* !=0 if following fields are valid */
339 unsigned long last_reading; /* In jiffies */ 340 unsigned long last_reading; /* In jiffies */
340 unsigned long last_config; /* In jiffies */ 341 unsigned long last_config; /* In jiffies */
@@ -373,8 +374,8 @@ static int lm85_detect(struct i2c_adapter *adapter, int address,
373 int kind); 374 int kind);
374static int lm85_detach_client(struct i2c_client *client); 375static int lm85_detach_client(struct i2c_client *client);
375 376
376static int lm85_read_value(struct i2c_client *client, u8 register); 377static int lm85_read_value(struct i2c_client *client, u8 reg);
377static int lm85_write_value(struct i2c_client *client, u8 register, int value); 378static int lm85_write_value(struct i2c_client *client, u8 reg, int value);
378static struct lm85_data *lm85_update_device(struct device *dev); 379static struct lm85_data *lm85_update_device(struct device *dev);
379static void lm85_init_client(struct i2c_client *client); 380static void lm85_init_client(struct i2c_client *client);
380 381
@@ -407,10 +408,10 @@ static ssize_t set_fan_min(struct device *dev, const char *buf,
407 struct lm85_data *data = i2c_get_clientdata(client); 408 struct lm85_data *data = i2c_get_clientdata(client);
408 long val = simple_strtol(buf, NULL, 10); 409 long val = simple_strtol(buf, NULL, 10);
409 410
410 down(&data->update_lock); 411 mutex_lock(&data->update_lock);
411 data->fan_min[nr] = FAN_TO_REG(val); 412 data->fan_min[nr] = FAN_TO_REG(val);
412 lm85_write_value(client, LM85_REG_FAN_MIN(nr), data->fan_min[nr]); 413 lm85_write_value(client, LM85_REG_FAN_MIN(nr), data->fan_min[nr]);
413 up(&data->update_lock); 414 mutex_unlock(&data->update_lock);
414 return count; 415 return count;
415} 416}
416 417
@@ -499,10 +500,10 @@ static ssize_t set_pwm(struct device *dev, const char *buf,
499 struct lm85_data *data = i2c_get_clientdata(client); 500 struct lm85_data *data = i2c_get_clientdata(client);
500 long val = simple_strtol(buf, NULL, 10); 501 long val = simple_strtol(buf, NULL, 10);
501 502
502 down(&data->update_lock); 503 mutex_lock(&data->update_lock);
503 data->pwm[nr] = PWM_TO_REG(val); 504 data->pwm[nr] = PWM_TO_REG(val);
504 lm85_write_value(client, LM85_REG_PWM(nr), data->pwm[nr]); 505 lm85_write_value(client, LM85_REG_PWM(nr), data->pwm[nr]);
505 up(&data->update_lock); 506 mutex_unlock(&data->update_lock);
506 return count; 507 return count;
507} 508}
508static ssize_t show_pwm_enable(struct device *dev, char *buf, int nr) 509static ssize_t show_pwm_enable(struct device *dev, char *buf, int nr)
@@ -559,10 +560,10 @@ static ssize_t set_in_min(struct device *dev, const char *buf,
559 struct lm85_data *data = i2c_get_clientdata(client); 560 struct lm85_data *data = i2c_get_clientdata(client);
560 long val = simple_strtol(buf, NULL, 10); 561 long val = simple_strtol(buf, NULL, 10);
561 562
562 down(&data->update_lock); 563 mutex_lock(&data->update_lock);
563 data->in_min[nr] = INS_TO_REG(nr, val); 564 data->in_min[nr] = INS_TO_REG(nr, val);
564 lm85_write_value(client, LM85_REG_IN_MIN(nr), data->in_min[nr]); 565 lm85_write_value(client, LM85_REG_IN_MIN(nr), data->in_min[nr]);
565 up(&data->update_lock); 566 mutex_unlock(&data->update_lock);
566 return count; 567 return count;
567} 568}
568static ssize_t show_in_max(struct device *dev, char *buf, int nr) 569static ssize_t show_in_max(struct device *dev, char *buf, int nr)
@@ -577,10 +578,10 @@ static ssize_t set_in_max(struct device *dev, const char *buf,
577 struct lm85_data *data = i2c_get_clientdata(client); 578 struct lm85_data *data = i2c_get_clientdata(client);
578 long val = simple_strtol(buf, NULL, 10); 579 long val = simple_strtol(buf, NULL, 10);
579 580
580 down(&data->update_lock); 581 mutex_lock(&data->update_lock);
581 data->in_max[nr] = INS_TO_REG(nr, val); 582 data->in_max[nr] = INS_TO_REG(nr, val);
582 lm85_write_value(client, LM85_REG_IN_MAX(nr), data->in_max[nr]); 583 lm85_write_value(client, LM85_REG_IN_MAX(nr), data->in_max[nr]);
583 up(&data->update_lock); 584 mutex_unlock(&data->update_lock);
584 return count; 585 return count;
585} 586}
586#define show_in_reg(offset) \ 587#define show_in_reg(offset) \
@@ -640,10 +641,10 @@ static ssize_t set_temp_min(struct device *dev, const char *buf,
640 struct lm85_data *data = i2c_get_clientdata(client); 641 struct lm85_data *data = i2c_get_clientdata(client);
641 long val = simple_strtol(buf, NULL, 10); 642 long val = simple_strtol(buf, NULL, 10);
642 643
643 down(&data->update_lock); 644 mutex_lock(&data->update_lock);
644 data->temp_min[nr] = TEMP_TO_REG(val); 645 data->temp_min[nr] = TEMP_TO_REG(val);
645 lm85_write_value(client, LM85_REG_TEMP_MIN(nr), data->temp_min[nr]); 646 lm85_write_value(client, LM85_REG_TEMP_MIN(nr), data->temp_min[nr]);
646 up(&data->update_lock); 647 mutex_unlock(&data->update_lock);
647 return count; 648 return count;
648} 649}
649static ssize_t show_temp_max(struct device *dev, char *buf, int nr) 650static ssize_t show_temp_max(struct device *dev, char *buf, int nr)
@@ -658,10 +659,10 @@ static ssize_t set_temp_max(struct device *dev, const char *buf,
658 struct lm85_data *data = i2c_get_clientdata(client); 659 struct lm85_data *data = i2c_get_clientdata(client);
659 long val = simple_strtol(buf, NULL, 10); 660 long val = simple_strtol(buf, NULL, 10);
660 661
661 down(&data->update_lock); 662 mutex_lock(&data->update_lock);
662 data->temp_max[nr] = TEMP_TO_REG(val); 663 data->temp_max[nr] = TEMP_TO_REG(val);
663 lm85_write_value(client, LM85_REG_TEMP_MAX(nr), data->temp_max[nr]); 664 lm85_write_value(client, LM85_REG_TEMP_MAX(nr), data->temp_max[nr]);
664 up(&data->update_lock); 665 mutex_unlock(&data->update_lock);
665 return count; 666 return count;
666} 667}
667#define show_temp_reg(offset) \ 668#define show_temp_reg(offset) \
@@ -713,12 +714,12 @@ static ssize_t set_pwm_auto_channels(struct device *dev, const char *buf,
713 struct lm85_data *data = i2c_get_clientdata(client); 714 struct lm85_data *data = i2c_get_clientdata(client);
714 long val = simple_strtol(buf, NULL, 10); 715 long val = simple_strtol(buf, NULL, 10);
715 716
716 down(&data->update_lock); 717 mutex_lock(&data->update_lock);
717 data->autofan[nr].config = (data->autofan[nr].config & (~0xe0)) 718 data->autofan[nr].config = (data->autofan[nr].config & (~0xe0))
718 | ZONE_TO_REG(val) ; 719 | ZONE_TO_REG(val) ;
719 lm85_write_value(client, LM85_REG_AFAN_CONFIG(nr), 720 lm85_write_value(client, LM85_REG_AFAN_CONFIG(nr),
720 data->autofan[nr].config); 721 data->autofan[nr].config);
721 up(&data->update_lock); 722 mutex_unlock(&data->update_lock);
722 return count; 723 return count;
723} 724}
724static ssize_t show_pwm_auto_pwm_min(struct device *dev, char *buf, int nr) 725static ssize_t show_pwm_auto_pwm_min(struct device *dev, char *buf, int nr)
@@ -733,11 +734,11 @@ static ssize_t set_pwm_auto_pwm_min(struct device *dev, const char *buf,
733 struct lm85_data *data = i2c_get_clientdata(client); 734 struct lm85_data *data = i2c_get_clientdata(client);
734 long val = simple_strtol(buf, NULL, 10); 735 long val = simple_strtol(buf, NULL, 10);
735 736
736 down(&data->update_lock); 737 mutex_lock(&data->update_lock);
737 data->autofan[nr].min_pwm = PWM_TO_REG(val); 738 data->autofan[nr].min_pwm = PWM_TO_REG(val);
738 lm85_write_value(client, LM85_REG_AFAN_MINPWM(nr), 739 lm85_write_value(client, LM85_REG_AFAN_MINPWM(nr),
739 data->autofan[nr].min_pwm); 740 data->autofan[nr].min_pwm);
740 up(&data->update_lock); 741 mutex_unlock(&data->update_lock);
741 return count; 742 return count;
742} 743}
743static ssize_t show_pwm_auto_pwm_minctl(struct device *dev, char *buf, int nr) 744static ssize_t show_pwm_auto_pwm_minctl(struct device *dev, char *buf, int nr)
@@ -752,7 +753,7 @@ static ssize_t set_pwm_auto_pwm_minctl(struct device *dev, const char *buf,
752 struct lm85_data *data = i2c_get_clientdata(client); 753 struct lm85_data *data = i2c_get_clientdata(client);
753 long val = simple_strtol(buf, NULL, 10); 754 long val = simple_strtol(buf, NULL, 10);
754 755
755 down(&data->update_lock); 756 mutex_lock(&data->update_lock);
756 data->autofan[nr].min_off = val; 757 data->autofan[nr].min_off = val;
757 lm85_write_value(client, LM85_REG_AFAN_SPIKE1, data->smooth[0] 758 lm85_write_value(client, LM85_REG_AFAN_SPIKE1, data->smooth[0]
758 | data->syncpwm3 759 | data->syncpwm3
@@ -760,7 +761,7 @@ static ssize_t set_pwm_auto_pwm_minctl(struct device *dev, const char *buf,
760 | (data->autofan[1].min_off ? 0x40 : 0) 761 | (data->autofan[1].min_off ? 0x40 : 0)
761 | (data->autofan[2].min_off ? 0x80 : 0) 762 | (data->autofan[2].min_off ? 0x80 : 0)
762 ); 763 );
763 up(&data->update_lock); 764 mutex_unlock(&data->update_lock);
764 return count; 765 return count;
765} 766}
766static ssize_t show_pwm_auto_pwm_freq(struct device *dev, char *buf, int nr) 767static ssize_t show_pwm_auto_pwm_freq(struct device *dev, char *buf, int nr)
@@ -775,13 +776,13 @@ static ssize_t set_pwm_auto_pwm_freq(struct device *dev, const char *buf,
775 struct lm85_data *data = i2c_get_clientdata(client); 776 struct lm85_data *data = i2c_get_clientdata(client);
776 long val = simple_strtol(buf, NULL, 10); 777 long val = simple_strtol(buf, NULL, 10);
777 778
778 down(&data->update_lock); 779 mutex_lock(&data->update_lock);
779 data->autofan[nr].freq = FREQ_TO_REG(val); 780 data->autofan[nr].freq = FREQ_TO_REG(val);
780 lm85_write_value(client, LM85_REG_AFAN_RANGE(nr), 781 lm85_write_value(client, LM85_REG_AFAN_RANGE(nr),
781 (data->zone[nr].range << 4) 782 (data->zone[nr].range << 4)
782 | data->autofan[nr].freq 783 | data->autofan[nr].freq
783 ); 784 );
784 up(&data->update_lock); 785 mutex_unlock(&data->update_lock);
785 return count; 786 return count;
786} 787}
787#define pwm_auto(offset) \ 788#define pwm_auto(offset) \
@@ -857,7 +858,7 @@ static ssize_t set_temp_auto_temp_off(struct device *dev, const char *buf,
857 int min; 858 int min;
858 long val = simple_strtol(buf, NULL, 10); 859 long val = simple_strtol(buf, NULL, 10);
859 860
860 down(&data->update_lock); 861 mutex_lock(&data->update_lock);
861 min = TEMP_FROM_REG(data->zone[nr].limit); 862 min = TEMP_FROM_REG(data->zone[nr].limit);
862 data->zone[nr].off_desired = TEMP_TO_REG(val); 863 data->zone[nr].off_desired = TEMP_TO_REG(val);
863 data->zone[nr].hyst = HYST_TO_REG(min - val); 864 data->zone[nr].hyst = HYST_TO_REG(min - val);
@@ -871,7 +872,7 @@ static ssize_t set_temp_auto_temp_off(struct device *dev, const char *buf,
871 (data->zone[2].hyst << 4) 872 (data->zone[2].hyst << 4)
872 ); 873 );
873 } 874 }
874 up(&data->update_lock); 875 mutex_unlock(&data->update_lock);
875 return count; 876 return count;
876} 877}
877static ssize_t show_temp_auto_temp_min(struct device *dev, char *buf, int nr) 878static ssize_t show_temp_auto_temp_min(struct device *dev, char *buf, int nr)
@@ -886,7 +887,7 @@ static ssize_t set_temp_auto_temp_min(struct device *dev, const char *buf,
886 struct lm85_data *data = i2c_get_clientdata(client); 887 struct lm85_data *data = i2c_get_clientdata(client);
887 long val = simple_strtol(buf, NULL, 10); 888 long val = simple_strtol(buf, NULL, 10);
888 889
889 down(&data->update_lock); 890 mutex_lock(&data->update_lock);
890 data->zone[nr].limit = TEMP_TO_REG(val); 891 data->zone[nr].limit = TEMP_TO_REG(val);
891 lm85_write_value(client, LM85_REG_AFAN_LIMIT(nr), 892 lm85_write_value(client, LM85_REG_AFAN_LIMIT(nr),
892 data->zone[nr].limit); 893 data->zone[nr].limit);
@@ -913,7 +914,7 @@ static ssize_t set_temp_auto_temp_min(struct device *dev, const char *buf,
913 (data->zone[2].hyst << 4) 914 (data->zone[2].hyst << 4)
914 ); 915 );
915 } 916 }
916 up(&data->update_lock); 917 mutex_unlock(&data->update_lock);
917 return count; 918 return count;
918} 919}
919static ssize_t show_temp_auto_temp_max(struct device *dev, char *buf, int nr) 920static ssize_t show_temp_auto_temp_max(struct device *dev, char *buf, int nr)
@@ -930,7 +931,7 @@ static ssize_t set_temp_auto_temp_max(struct device *dev, const char *buf,
930 int min; 931 int min;
931 long val = simple_strtol(buf, NULL, 10); 932 long val = simple_strtol(buf, NULL, 10);
932 933
933 down(&data->update_lock); 934 mutex_lock(&data->update_lock);
934 min = TEMP_FROM_REG(data->zone[nr].limit); 935 min = TEMP_FROM_REG(data->zone[nr].limit);
935 data->zone[nr].max_desired = TEMP_TO_REG(val); 936 data->zone[nr].max_desired = TEMP_TO_REG(val);
936 data->zone[nr].range = RANGE_TO_REG( 937 data->zone[nr].range = RANGE_TO_REG(
@@ -938,7 +939,7 @@ static ssize_t set_temp_auto_temp_max(struct device *dev, const char *buf,
938 lm85_write_value(client, LM85_REG_AFAN_RANGE(nr), 939 lm85_write_value(client, LM85_REG_AFAN_RANGE(nr),
939 ((data->zone[nr].range & 0x0f) << 4) 940 ((data->zone[nr].range & 0x0f) << 4)
940 | (data->autofan[nr].freq & 0x07)); 941 | (data->autofan[nr].freq & 0x07));
941 up(&data->update_lock); 942 mutex_unlock(&data->update_lock);
942 return count; 943 return count;
943} 944}
944static ssize_t show_temp_auto_temp_crit(struct device *dev, char *buf, int nr) 945static ssize_t show_temp_auto_temp_crit(struct device *dev, char *buf, int nr)
@@ -953,11 +954,11 @@ static ssize_t set_temp_auto_temp_crit(struct device *dev, const char *buf,
953 struct lm85_data *data = i2c_get_clientdata(client); 954 struct lm85_data *data = i2c_get_clientdata(client);
954 long val = simple_strtol(buf, NULL, 10); 955 long val = simple_strtol(buf, NULL, 10);
955 956
956 down(&data->update_lock); 957 mutex_lock(&data->update_lock);
957 data->zone[nr].critical = TEMP_TO_REG(val); 958 data->zone[nr].critical = TEMP_TO_REG(val);
958 lm85_write_value(client, LM85_REG_AFAN_CRITICAL(nr), 959 lm85_write_value(client, LM85_REG_AFAN_CRITICAL(nr),
959 data->zone[nr].critical); 960 data->zone[nr].critical);
960 up(&data->update_lock); 961 mutex_unlock(&data->update_lock);
961 return count; 962 return count;
962} 963}
963#define temp_auto(offset) \ 964#define temp_auto(offset) \
@@ -1149,7 +1150,7 @@ static int lm85_detect(struct i2c_adapter *adapter, int address,
1149 /* Fill in the remaining client fields */ 1150 /* Fill in the remaining client fields */
1150 data->type = kind; 1151 data->type = kind;
1151 data->valid = 0; 1152 data->valid = 0;
1152 init_MUTEX(&data->update_lock); 1153 mutex_init(&data->update_lock);
1153 1154
1154 /* Tell the I2C layer a new client has arrived */ 1155 /* Tell the I2C layer a new client has arrived */
1155 if ((err = i2c_attach_client(new_client))) 1156 if ((err = i2c_attach_client(new_client)))
@@ -1368,7 +1369,7 @@ static struct lm85_data *lm85_update_device(struct device *dev)
1368 struct lm85_data *data = i2c_get_clientdata(client); 1369 struct lm85_data *data = i2c_get_clientdata(client);
1369 int i; 1370 int i;
1370 1371
1371 down(&data->update_lock); 1372 mutex_lock(&data->update_lock);
1372 1373
1373 if ( !data->valid || 1374 if ( !data->valid ||
1374 time_after(jiffies, data->last_reading + LM85_DATA_INTERVAL) ) { 1375 time_after(jiffies, data->last_reading + LM85_DATA_INTERVAL) ) {
@@ -1571,7 +1572,7 @@ static struct lm85_data *lm85_update_device(struct device *dev)
1571 1572
1572 data->valid = 1; 1573 data->valid = 1;
1573 1574
1574 up(&data->update_lock); 1575 mutex_unlock(&data->update_lock);
1575 1576
1576 return data; 1577 return data;
1577} 1578}
diff --git a/drivers/hwmon/lm87.c b/drivers/hwmon/lm87.c
index 6ba34c302d..e229daf666 100644
--- a/drivers/hwmon/lm87.c
+++ b/drivers/hwmon/lm87.c
@@ -60,6 +60,7 @@
60#include <linux/hwmon.h> 60#include <linux/hwmon.h>
61#include <linux/hwmon-vid.h> 61#include <linux/hwmon-vid.h>
62#include <linux/err.h> 62#include <linux/err.h>
63#include <linux/mutex.h>
63 64
64/* 65/*
65 * Addresses to scan 66 * Addresses to scan
@@ -176,7 +177,7 @@ static struct i2c_driver lm87_driver = {
176struct lm87_data { 177struct lm87_data {
177 struct i2c_client client; 178 struct i2c_client client;
178 struct class_device *class_dev; 179 struct class_device *class_dev;
179 struct semaphore update_lock; 180 struct mutex update_lock;
180 char valid; /* zero until following fields are valid */ 181 char valid; /* zero until following fields are valid */
181 unsigned long last_updated; /* In jiffies */ 182 unsigned long last_updated; /* In jiffies */
182 183
@@ -253,11 +254,11 @@ static void set_in_min(struct device *dev, const char *buf, int nr)
253 struct lm87_data *data = i2c_get_clientdata(client); 254 struct lm87_data *data = i2c_get_clientdata(client);
254 long val = simple_strtol(buf, NULL, 10); 255 long val = simple_strtol(buf, NULL, 10);
255 256
256 down(&data->update_lock); 257 mutex_lock(&data->update_lock);
257 data->in_min[nr] = IN_TO_REG(val, data->in_scale[nr]); 258 data->in_min[nr] = IN_TO_REG(val, data->in_scale[nr]);
258 lm87_write_value(client, nr<6 ? LM87_REG_IN_MIN(nr) : 259 lm87_write_value(client, nr<6 ? LM87_REG_IN_MIN(nr) :
259 LM87_REG_AIN_MIN(nr-6), data->in_min[nr]); 260 LM87_REG_AIN_MIN(nr-6), data->in_min[nr]);
260 up(&data->update_lock); 261 mutex_unlock(&data->update_lock);
261} 262}
262 263
263static void set_in_max(struct device *dev, const char *buf, int nr) 264static void set_in_max(struct device *dev, const char *buf, int nr)
@@ -266,11 +267,11 @@ static void set_in_max(struct device *dev, const char *buf, int nr)
266 struct lm87_data *data = i2c_get_clientdata(client); 267 struct lm87_data *data = i2c_get_clientdata(client);
267 long val = simple_strtol(buf, NULL, 10); 268 long val = simple_strtol(buf, NULL, 10);
268 269
269 down(&data->update_lock); 270 mutex_lock(&data->update_lock);
270 data->in_max[nr] = IN_TO_REG(val, data->in_scale[nr]); 271 data->in_max[nr] = IN_TO_REG(val, data->in_scale[nr]);
271 lm87_write_value(client, nr<6 ? LM87_REG_IN_MAX(nr) : 272 lm87_write_value(client, nr<6 ? LM87_REG_IN_MAX(nr) :
272 LM87_REG_AIN_MAX(nr-6), data->in_max[nr]); 273 LM87_REG_AIN_MAX(nr-6), data->in_max[nr]);
273 up(&data->update_lock); 274 mutex_unlock(&data->update_lock);
274} 275}
275 276
276#define set_in(offset) \ 277#define set_in(offset) \
@@ -327,10 +328,10 @@ static void set_temp_low(struct device *dev, const char *buf, int nr)
327 struct lm87_data *data = i2c_get_clientdata(client); 328 struct lm87_data *data = i2c_get_clientdata(client);
328 long val = simple_strtol(buf, NULL, 10); 329 long val = simple_strtol(buf, NULL, 10);
329 330
330 down(&data->update_lock); 331 mutex_lock(&data->update_lock);
331 data->temp_low[nr] = TEMP_TO_REG(val); 332 data->temp_low[nr] = TEMP_TO_REG(val);
332 lm87_write_value(client, LM87_REG_TEMP_LOW[nr], data->temp_low[nr]); 333 lm87_write_value(client, LM87_REG_TEMP_LOW[nr], data->temp_low[nr]);
333 up(&data->update_lock); 334 mutex_unlock(&data->update_lock);
334} 335}
335 336
336static void set_temp_high(struct device *dev, const char *buf, int nr) 337static void set_temp_high(struct device *dev, const char *buf, int nr)
@@ -339,10 +340,10 @@ static void set_temp_high(struct device *dev, const char *buf, int nr)
339 struct lm87_data *data = i2c_get_clientdata(client); 340 struct lm87_data *data = i2c_get_clientdata(client);
340 long val = simple_strtol(buf, NULL, 10); 341 long val = simple_strtol(buf, NULL, 10);
341 342
342 down(&data->update_lock); 343 mutex_lock(&data->update_lock);
343 data->temp_high[nr] = TEMP_TO_REG(val); 344 data->temp_high[nr] = TEMP_TO_REG(val);
344 lm87_write_value(client, LM87_REG_TEMP_HIGH[nr], data->temp_high[nr]); 345 lm87_write_value(client, LM87_REG_TEMP_HIGH[nr], data->temp_high[nr]);
345 up(&data->update_lock); 346 mutex_unlock(&data->update_lock);
346} 347}
347 348
348#define set_temp(offset) \ 349#define set_temp(offset) \
@@ -411,11 +412,11 @@ static void set_fan_min(struct device *dev, const char *buf, int nr)
411 struct lm87_data *data = i2c_get_clientdata(client); 412 struct lm87_data *data = i2c_get_clientdata(client);
412 long val = simple_strtol(buf, NULL, 10); 413 long val = simple_strtol(buf, NULL, 10);
413 414
414 down(&data->update_lock); 415 mutex_lock(&data->update_lock);
415 data->fan_min[nr] = FAN_TO_REG(val, 416 data->fan_min[nr] = FAN_TO_REG(val,
416 FAN_DIV_FROM_REG(data->fan_div[nr])); 417 FAN_DIV_FROM_REG(data->fan_div[nr]));
417 lm87_write_value(client, LM87_REG_FAN_MIN(nr), data->fan_min[nr]); 418 lm87_write_value(client, LM87_REG_FAN_MIN(nr), data->fan_min[nr]);
418 up(&data->update_lock); 419 mutex_unlock(&data->update_lock);
419} 420}
420 421
421/* Note: we save and restore the fan minimum here, because its value is 422/* Note: we save and restore the fan minimum here, because its value is
@@ -431,7 +432,7 @@ static ssize_t set_fan_div(struct device *dev, const char *buf,
431 unsigned long min; 432 unsigned long min;
432 u8 reg; 433 u8 reg;
433 434
434 down(&data->update_lock); 435 mutex_lock(&data->update_lock);
435 min = FAN_FROM_REG(data->fan_min[nr], 436 min = FAN_FROM_REG(data->fan_min[nr],
436 FAN_DIV_FROM_REG(data->fan_div[nr])); 437 FAN_DIV_FROM_REG(data->fan_div[nr]));
437 438
@@ -441,7 +442,7 @@ static ssize_t set_fan_div(struct device *dev, const char *buf,
441 case 4: data->fan_div[nr] = 2; break; 442 case 4: data->fan_div[nr] = 2; break;
442 case 8: data->fan_div[nr] = 3; break; 443 case 8: data->fan_div[nr] = 3; break;
443 default: 444 default:
444 up(&data->update_lock); 445 mutex_unlock(&data->update_lock);
445 return -EINVAL; 446 return -EINVAL;
446 } 447 }
447 448
@@ -459,7 +460,7 @@ static ssize_t set_fan_div(struct device *dev, const char *buf,
459 data->fan_min[nr] = FAN_TO_REG(min, val); 460 data->fan_min[nr] = FAN_TO_REG(min, val);
460 lm87_write_value(client, LM87_REG_FAN_MIN(nr), 461 lm87_write_value(client, LM87_REG_FAN_MIN(nr),
461 data->fan_min[nr]); 462 data->fan_min[nr]);
462 up(&data->update_lock); 463 mutex_unlock(&data->update_lock);
463 464
464 return count; 465 return count;
465} 466}
@@ -522,10 +523,10 @@ static ssize_t set_aout(struct device *dev, struct device_attribute *attr, const
522 struct lm87_data *data = i2c_get_clientdata(client); 523 struct lm87_data *data = i2c_get_clientdata(client);
523 long val = simple_strtol(buf, NULL, 10); 524 long val = simple_strtol(buf, NULL, 10);
524 525
525 down(&data->update_lock); 526 mutex_lock(&data->update_lock);
526 data->aout = AOUT_TO_REG(val); 527 data->aout = AOUT_TO_REG(val);
527 lm87_write_value(client, LM87_REG_AOUT, data->aout); 528 lm87_write_value(client, LM87_REG_AOUT, data->aout);
528 up(&data->update_lock); 529 mutex_unlock(&data->update_lock);
529 return count; 530 return count;
530} 531}
531static DEVICE_ATTR(aout_output, S_IRUGO | S_IWUSR, show_aout, set_aout); 532static DEVICE_ATTR(aout_output, S_IRUGO | S_IWUSR, show_aout, set_aout);
@@ -589,7 +590,7 @@ static int lm87_detect(struct i2c_adapter *adapter, int address, int kind)
589 /* We can fill in the remaining client fields */ 590 /* We can fill in the remaining client fields */
590 strlcpy(new_client->name, "lm87", I2C_NAME_SIZE); 591 strlcpy(new_client->name, "lm87", I2C_NAME_SIZE);
591 data->valid = 0; 592 data->valid = 0;
592 init_MUTEX(&data->update_lock); 593 mutex_init(&data->update_lock);
593 594
594 /* Tell the I2C layer a new client has arrived */ 595 /* Tell the I2C layer a new client has arrived */
595 if ((err = i2c_attach_client(new_client))) 596 if ((err = i2c_attach_client(new_client)))
@@ -744,7 +745,7 @@ static struct lm87_data *lm87_update_device(struct device *dev)
744 struct i2c_client *client = to_i2c_client(dev); 745 struct i2c_client *client = to_i2c_client(dev);
745 struct lm87_data *data = i2c_get_clientdata(client); 746 struct lm87_data *data = i2c_get_clientdata(client);
746 747
747 down(&data->update_lock); 748 mutex_lock(&data->update_lock);
748 749
749 if (time_after(jiffies, data->last_updated + HZ) || !data->valid) { 750 if (time_after(jiffies, data->last_updated + HZ) || !data->valid) {
750 int i, j; 751 int i, j;
@@ -813,7 +814,7 @@ static struct lm87_data *lm87_update_device(struct device *dev)
813 data->valid = 1; 814 data->valid = 1;
814 } 815 }
815 816
816 up(&data->update_lock); 817 mutex_unlock(&data->update_lock);
817 818
818 return data; 819 return data;
819} 820}
diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c
index 5679464447..d9eeaf7585 100644
--- a/drivers/hwmon/lm90.c
+++ b/drivers/hwmon/lm90.c
@@ -78,6 +78,7 @@
78#include <linux/hwmon-sysfs.h> 78#include <linux/hwmon-sysfs.h>
79#include <linux/hwmon.h> 79#include <linux/hwmon.h>
80#include <linux/err.h> 80#include <linux/err.h>
81#include <linux/mutex.h>
81 82
82/* 83/*
83 * Addresses to scan 84 * Addresses to scan
@@ -201,7 +202,7 @@ static struct i2c_driver lm90_driver = {
201struct lm90_data { 202struct lm90_data {
202 struct i2c_client client; 203 struct i2c_client client;
203 struct class_device *class_dev; 204 struct class_device *class_dev;
204 struct semaphore update_lock; 205 struct mutex update_lock;
205 char valid; /* zero until following fields are valid */ 206 char valid; /* zero until following fields are valid */
206 unsigned long last_updated; /* in jiffies */ 207 unsigned long last_updated; /* in jiffies */
207 int kind; 208 int kind;
@@ -247,13 +248,13 @@ static ssize_t set_temp8(struct device *dev, struct device_attribute *devattr,
247 long val = simple_strtol(buf, NULL, 10); 248 long val = simple_strtol(buf, NULL, 10);
248 int nr = attr->index; 249 int nr = attr->index;
249 250
250 down(&data->update_lock); 251 mutex_lock(&data->update_lock);
251 if (data->kind == adt7461) 252 if (data->kind == adt7461)
252 data->temp8[nr] = TEMP1_TO_REG_ADT7461(val); 253 data->temp8[nr] = TEMP1_TO_REG_ADT7461(val);
253 else 254 else
254 data->temp8[nr] = TEMP1_TO_REG(val); 255 data->temp8[nr] = TEMP1_TO_REG(val);
255 i2c_smbus_write_byte_data(client, reg[nr - 1], data->temp8[nr]); 256 i2c_smbus_write_byte_data(client, reg[nr - 1], data->temp8[nr]);
256 up(&data->update_lock); 257 mutex_unlock(&data->update_lock);
257 return count; 258 return count;
258} 259}
259 260
@@ -281,7 +282,7 @@ static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr,
281 long val = simple_strtol(buf, NULL, 10); 282 long val = simple_strtol(buf, NULL, 10);
282 int nr = attr->index; 283 int nr = attr->index;
283 284
284 down(&data->update_lock); 285 mutex_lock(&data->update_lock);
285 if (data->kind == adt7461) 286 if (data->kind == adt7461)
286 data->temp11[nr] = TEMP2_TO_REG_ADT7461(val); 287 data->temp11[nr] = TEMP2_TO_REG_ADT7461(val);
287 else 288 else
@@ -290,7 +291,7 @@ static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr,
290 data->temp11[nr] >> 8); 291 data->temp11[nr] >> 8);
291 i2c_smbus_write_byte_data(client, reg[(nr - 1) * 2 + 1], 292 i2c_smbus_write_byte_data(client, reg[(nr - 1) * 2 + 1],
292 data->temp11[nr] & 0xff); 293 data->temp11[nr] & 0xff);
293 up(&data->update_lock); 294 mutex_unlock(&data->update_lock);
294 return count; 295 return count;
295} 296}
296 297
@@ -311,11 +312,11 @@ static ssize_t set_temphyst(struct device *dev, struct device_attribute *dummy,
311 long val = simple_strtol(buf, NULL, 10); 312 long val = simple_strtol(buf, NULL, 10);
312 long hyst; 313 long hyst;
313 314
314 down(&data->update_lock); 315 mutex_lock(&data->update_lock);
315 hyst = TEMP1_FROM_REG(data->temp8[3]) - val; 316 hyst = TEMP1_FROM_REG(data->temp8[3]) - val;
316 i2c_smbus_write_byte_data(client, LM90_REG_W_TCRIT_HYST, 317 i2c_smbus_write_byte_data(client, LM90_REG_W_TCRIT_HYST,
317 HYST_TO_REG(hyst)); 318 HYST_TO_REG(hyst));
318 up(&data->update_lock); 319 mutex_unlock(&data->update_lock);
319 return count; 320 return count;
320} 321}
321 322
@@ -558,7 +559,7 @@ static int lm90_detect(struct i2c_adapter *adapter, int address, int kind)
558 strlcpy(new_client->name, name, I2C_NAME_SIZE); 559 strlcpy(new_client->name, name, I2C_NAME_SIZE);
559 data->valid = 0; 560 data->valid = 0;
560 data->kind = kind; 561 data->kind = kind;
561 init_MUTEX(&data->update_lock); 562 mutex_init(&data->update_lock);
562 563
563 /* Tell the I2C layer a new client has arrived */ 564 /* Tell the I2C layer a new client has arrived */
564 if ((err = i2c_attach_client(new_client))) 565 if ((err = i2c_attach_client(new_client)))
@@ -646,7 +647,7 @@ static struct lm90_data *lm90_update_device(struct device *dev)
646 struct i2c_client *client = to_i2c_client(dev); 647 struct i2c_client *client = to_i2c_client(dev);
647 struct lm90_data *data = i2c_get_clientdata(client); 648 struct lm90_data *data = i2c_get_clientdata(client);
648 649
649 down(&data->update_lock); 650 mutex_lock(&data->update_lock);
650 651
651 if (time_after(jiffies, data->last_updated + HZ * 2) || !data->valid) { 652 if (time_after(jiffies, data->last_updated + HZ * 2) || !data->valid) {
652 u8 oldh, newh, l; 653 u8 oldh, newh, l;
@@ -692,7 +693,7 @@ static struct lm90_data *lm90_update_device(struct device *dev)
692 data->valid = 1; 693 data->valid = 1;
693 } 694 }
694 695
695 up(&data->update_lock); 696 mutex_unlock(&data->update_lock);
696 697
697 return data; 698 return data;
698} 699}
diff --git a/drivers/hwmon/lm92.c b/drivers/hwmon/lm92.c
index b0c4cb730a..197f77226d 100644
--- a/drivers/hwmon/lm92.c
+++ b/drivers/hwmon/lm92.c
@@ -46,6 +46,7 @@
46#include <linux/i2c.h> 46#include <linux/i2c.h>
47#include <linux/hwmon.h> 47#include <linux/hwmon.h>
48#include <linux/err.h> 48#include <linux/err.h>
49#include <linux/mutex.h>
49 50
50/* The LM92 and MAX6635 have 2 two-state pins for address selection, 51/* The LM92 and MAX6635 have 2 two-state pins for address selection,
51 resulting in 4 possible addresses. */ 52 resulting in 4 possible addresses. */
@@ -96,7 +97,7 @@ static struct i2c_driver lm92_driver;
96struct lm92_data { 97struct lm92_data {
97 struct i2c_client client; 98 struct i2c_client client;
98 struct class_device *class_dev; 99 struct class_device *class_dev;
99 struct semaphore update_lock; 100 struct mutex update_lock;
100 char valid; /* zero until following fields are valid */ 101 char valid; /* zero until following fields are valid */
101 unsigned long last_updated; /* in jiffies */ 102 unsigned long last_updated; /* in jiffies */
102 103
@@ -114,7 +115,7 @@ static struct lm92_data *lm92_update_device(struct device *dev)
114 struct i2c_client *client = to_i2c_client(dev); 115 struct i2c_client *client = to_i2c_client(dev);
115 struct lm92_data *data = i2c_get_clientdata(client); 116 struct lm92_data *data = i2c_get_clientdata(client);
116 117
117 down(&data->update_lock); 118 mutex_lock(&data->update_lock);
118 119
119 if (time_after(jiffies, data->last_updated + HZ) 120 if (time_after(jiffies, data->last_updated + HZ)
120 || !data->valid) { 121 || !data->valid) {
@@ -134,7 +135,7 @@ static struct lm92_data *lm92_update_device(struct device *dev)
134 data->valid = 1; 135 data->valid = 1;
135 } 136 }
136 137
137 up(&data->update_lock); 138 mutex_unlock(&data->update_lock);
138 139
139 return data; 140 return data;
140} 141}
@@ -158,10 +159,10 @@ static ssize_t set_##value(struct device *dev, struct device_attribute *attr, co
158 struct lm92_data *data = i2c_get_clientdata(client); \ 159 struct lm92_data *data = i2c_get_clientdata(client); \
159 long val = simple_strtol(buf, NULL, 10); \ 160 long val = simple_strtol(buf, NULL, 10); \
160 \ 161 \
161 down(&data->update_lock); \ 162 mutex_lock(&data->update_lock); \
162 data->value = TEMP_TO_REG(val); \ 163 data->value = TEMP_TO_REG(val); \
163 i2c_smbus_write_word_data(client, reg, swab16(data->value)); \ 164 i2c_smbus_write_word_data(client, reg, swab16(data->value)); \
164 up(&data->update_lock); \ 165 mutex_unlock(&data->update_lock); \
165 return count; \ 166 return count; \
166} 167}
167set_temp(temp1_crit, LM92_REG_TEMP_CRIT); 168set_temp(temp1_crit, LM92_REG_TEMP_CRIT);
@@ -194,11 +195,11 @@ static ssize_t set_temp1_crit_hyst(struct device *dev, struct device_attribute *
194 struct lm92_data *data = i2c_get_clientdata(client); 195 struct lm92_data *data = i2c_get_clientdata(client);
195 long val = simple_strtol(buf, NULL, 10); 196 long val = simple_strtol(buf, NULL, 10);
196 197
197 down(&data->update_lock); 198 mutex_lock(&data->update_lock);
198 data->temp1_hyst = TEMP_FROM_REG(data->temp1_crit) - val; 199 data->temp1_hyst = TEMP_FROM_REG(data->temp1_crit) - val;
199 i2c_smbus_write_word_data(client, LM92_REG_TEMP_HYST, 200 i2c_smbus_write_word_data(client, LM92_REG_TEMP_HYST,
200 swab16(TEMP_TO_REG(data->temp1_hyst))); 201 swab16(TEMP_TO_REG(data->temp1_hyst)));
201 up(&data->update_lock); 202 mutex_unlock(&data->update_lock);
202 return count; 203 return count;
203} 204}
204 205
@@ -348,7 +349,7 @@ static int lm92_detect(struct i2c_adapter *adapter, int address, int kind)
348 /* Fill in the remaining client fields */ 349 /* Fill in the remaining client fields */
349 strlcpy(new_client->name, name, I2C_NAME_SIZE); 350 strlcpy(new_client->name, name, I2C_NAME_SIZE);
350 data->valid = 0; 351 data->valid = 0;
351 init_MUTEX(&data->update_lock); 352 mutex_init(&data->update_lock);
352 353
353 /* Tell the i2c subsystem a new client has arrived */ 354 /* Tell the i2c subsystem a new client has arrived */
354 if ((err = i2c_attach_client(new_client))) 355 if ((err = i2c_attach_client(new_client)))
diff --git a/drivers/hwmon/max1619.c b/drivers/hwmon/max1619.c
index 3abe330b22..b4135b5971 100644
--- a/drivers/hwmon/max1619.c
+++ b/drivers/hwmon/max1619.c
@@ -33,6 +33,7 @@
33#include <linux/i2c.h> 33#include <linux/i2c.h>
34#include <linux/hwmon.h> 34#include <linux/hwmon.h>
35#include <linux/err.h> 35#include <linux/err.h>
36#include <linux/mutex.h>
36 37
37static unsigned short normal_i2c[] = { 0x18, 0x19, 0x1a, 38static unsigned short normal_i2c[] = { 0x18, 0x19, 0x1a,
38 0x29, 0x2a, 0x2b, 39 0x29, 0x2a, 0x2b,
@@ -104,7 +105,7 @@ static struct i2c_driver max1619_driver = {
104struct max1619_data { 105struct max1619_data {
105 struct i2c_client client; 106 struct i2c_client client;
106 struct class_device *class_dev; 107 struct class_device *class_dev;
107 struct semaphore update_lock; 108 struct mutex update_lock;
108 char valid; /* zero until following fields are valid */ 109 char valid; /* zero until following fields are valid */
109 unsigned long last_updated; /* in jiffies */ 110 unsigned long last_updated; /* in jiffies */
110 111
@@ -141,10 +142,10 @@ static ssize_t set_##value(struct device *dev, struct device_attribute *attr, co
141 struct max1619_data *data = i2c_get_clientdata(client); \ 142 struct max1619_data *data = i2c_get_clientdata(client); \
142 long val = simple_strtol(buf, NULL, 10); \ 143 long val = simple_strtol(buf, NULL, 10); \
143 \ 144 \
144 down(&data->update_lock); \ 145 mutex_lock(&data->update_lock); \
145 data->value = TEMP_TO_REG(val); \ 146 data->value = TEMP_TO_REG(val); \
146 i2c_smbus_write_byte_data(client, reg, data->value); \ 147 i2c_smbus_write_byte_data(client, reg, data->value); \
147 up(&data->update_lock); \ 148 mutex_unlock(&data->update_lock); \
148 return count; \ 149 return count; \
149} 150}
150 151
@@ -262,7 +263,7 @@ static int max1619_detect(struct i2c_adapter *adapter, int address, int kind)
262 /* We can fill in the remaining client fields */ 263 /* We can fill in the remaining client fields */
263 strlcpy(new_client->name, name, I2C_NAME_SIZE); 264 strlcpy(new_client->name, name, I2C_NAME_SIZE);
264 data->valid = 0; 265 data->valid = 0;
265 init_MUTEX(&data->update_lock); 266 mutex_init(&data->update_lock);
266 267
267 /* Tell the I2C layer a new client has arrived */ 268 /* Tell the I2C layer a new client has arrived */
268 if ((err = i2c_attach_client(new_client))) 269 if ((err = i2c_attach_client(new_client)))
@@ -330,7 +331,7 @@ static struct max1619_data *max1619_update_device(struct device *dev)
330 struct i2c_client *client = to_i2c_client(dev); 331 struct i2c_client *client = to_i2c_client(dev);
331 struct max1619_data *data = i2c_get_clientdata(client); 332 struct max1619_data *data = i2c_get_clientdata(client);
332 333
333 down(&data->update_lock); 334 mutex_lock(&data->update_lock);
334 335
335 if (time_after(jiffies, data->last_updated + HZ * 2) || !data->valid) { 336 if (time_after(jiffies, data->last_updated + HZ * 2) || !data->valid) {
336 dev_dbg(&client->dev, "Updating max1619 data.\n"); 337 dev_dbg(&client->dev, "Updating max1619 data.\n");
@@ -353,7 +354,7 @@ static struct max1619_data *max1619_update_device(struct device *dev)
353 data->valid = 1; 354 data->valid = 1;
354 } 355 }
355 356
356 up(&data->update_lock); 357 mutex_unlock(&data->update_lock);
357 358
358 return data; 359 return data;
359} 360}
diff --git a/drivers/hwmon/pc87360.c b/drivers/hwmon/pc87360.c
index f161e88e3b..ae05e483a7 100644
--- a/drivers/hwmon/pc87360.c
+++ b/drivers/hwmon/pc87360.c
@@ -43,6 +43,7 @@
43#include <linux/hwmon-sysfs.h> 43#include <linux/hwmon-sysfs.h>
44#include <linux/hwmon-vid.h> 44#include <linux/hwmon-vid.h>
45#include <linux/err.h> 45#include <linux/err.h>
46#include <linux/mutex.h>
46#include <asm/io.h> 47#include <asm/io.h>
47 48
48static u8 devid; 49static u8 devid;
@@ -183,8 +184,8 @@ static inline u8 PWM_TO_REG(int val, int inv)
183struct pc87360_data { 184struct pc87360_data {
184 struct i2c_client client; 185 struct i2c_client client;
185 struct class_device *class_dev; 186 struct class_device *class_dev;
186 struct semaphore lock; 187 struct mutex lock;
187 struct semaphore update_lock; 188 struct mutex update_lock;
188 char valid; /* !=0 if following fields are valid */ 189 char valid; /* !=0 if following fields are valid */
189 unsigned long last_updated; /* In jiffies */ 190 unsigned long last_updated; /* In jiffies */
190 191
@@ -283,7 +284,7 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute *devattr,
283 struct pc87360_data *data = i2c_get_clientdata(client); 284 struct pc87360_data *data = i2c_get_clientdata(client);
284 long fan_min = simple_strtol(buf, NULL, 10); 285 long fan_min = simple_strtol(buf, NULL, 10);
285 286
286 down(&data->update_lock); 287 mutex_lock(&data->update_lock);
287 fan_min = FAN_TO_REG(fan_min, FAN_DIV_FROM_REG(data->fan_status[attr->index])); 288 fan_min = FAN_TO_REG(fan_min, FAN_DIV_FROM_REG(data->fan_status[attr->index]));
288 289
289 /* If it wouldn't fit, change clock divisor */ 290 /* If it wouldn't fit, change clock divisor */
@@ -300,23 +301,31 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute *devattr,
300 /* Write new divider, preserve alarm bits */ 301 /* Write new divider, preserve alarm bits */
301 pc87360_write_value(data, LD_FAN, NO_BANK, PC87360_REG_FAN_STATUS(attr->index), 302 pc87360_write_value(data, LD_FAN, NO_BANK, PC87360_REG_FAN_STATUS(attr->index),
302 data->fan_status[attr->index] & 0xF9); 303 data->fan_status[attr->index] & 0xF9);
303 up(&data->update_lock); 304 mutex_unlock(&data->update_lock);
304 305
305 return count; 306 return count;
306} 307}
307 308
308#define show_and_set_fan(offset) \ 309static struct sensor_device_attribute fan_input[] = {
309static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \ 310 SENSOR_ATTR(fan1_input, S_IRUGO, show_fan_input, NULL, 0),
310 show_fan_input, NULL, offset-1); \ 311 SENSOR_ATTR(fan2_input, S_IRUGO, show_fan_input, NULL, 1),
311static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IWUSR | S_IRUGO, \ 312 SENSOR_ATTR(fan3_input, S_IRUGO, show_fan_input, NULL, 2),
312 show_fan_min, set_fan_min, offset-1); \ 313};
313static SENSOR_DEVICE_ATTR(fan##offset##_div, S_IRUGO, \ 314static struct sensor_device_attribute fan_status[] = {
314 show_fan_div, NULL, offset-1); \ 315 SENSOR_ATTR(fan1_status, S_IRUGO, show_fan_status, NULL, 0),
315static SENSOR_DEVICE_ATTR(fan##offset##_status, S_IRUGO, \ 316 SENSOR_ATTR(fan2_status, S_IRUGO, show_fan_status, NULL, 1),
316 show_fan_status, NULL, offset-1); 317 SENSOR_ATTR(fan3_status, S_IRUGO, show_fan_status, NULL, 2),
317show_and_set_fan(1) 318};
318show_and_set_fan(2) 319static struct sensor_device_attribute fan_div[] = {
319show_and_set_fan(3) 320 SENSOR_ATTR(fan1_div, S_IRUGO, show_fan_div, NULL, 0),
321 SENSOR_ATTR(fan2_div, S_IRUGO, show_fan_div, NULL, 1),
322 SENSOR_ATTR(fan3_div, S_IRUGO, show_fan_div, NULL, 2),
323};
324static struct sensor_device_attribute fan_min[] = {
325 SENSOR_ATTR(fan1_min, S_IWUSR | S_IRUGO, show_fan_min, set_fan_min, 0),
326 SENSOR_ATTR(fan2_min, S_IWUSR | S_IRUGO, show_fan_min, set_fan_min, 1),
327 SENSOR_ATTR(fan3_min, S_IWUSR | S_IRUGO, show_fan_min, set_fan_min, 2),
328};
320 329
321static ssize_t show_pwm(struct device *dev, struct device_attribute *devattr, char *buf) 330static ssize_t show_pwm(struct device *dev, struct device_attribute *devattr, char *buf)
322{ 331{
@@ -335,21 +344,20 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *devattr, con
335 struct pc87360_data *data = i2c_get_clientdata(client); 344 struct pc87360_data *data = i2c_get_clientdata(client);
336 long val = simple_strtol(buf, NULL, 10); 345 long val = simple_strtol(buf, NULL, 10);
337 346
338 down(&data->update_lock); 347 mutex_lock(&data->update_lock);
339 data->pwm[attr->index] = PWM_TO_REG(val, 348 data->pwm[attr->index] = PWM_TO_REG(val,
340 FAN_CONFIG_INVERT(data->fan_conf, attr->index)); 349 FAN_CONFIG_INVERT(data->fan_conf, attr->index));
341 pc87360_write_value(data, LD_FAN, NO_BANK, PC87360_REG_PWM(attr->index), 350 pc87360_write_value(data, LD_FAN, NO_BANK, PC87360_REG_PWM(attr->index),
342 data->pwm[attr->index]); 351 data->pwm[attr->index]);
343 up(&data->update_lock); 352 mutex_unlock(&data->update_lock);
344 return count; 353 return count;
345} 354}
346 355
347#define show_and_set_pwm(offset) \ 356static struct sensor_device_attribute pwm[] = {
348static SENSOR_DEVICE_ATTR(pwm##offset, S_IWUSR | S_IRUGO, \ 357 SENSOR_ATTR(pwm1, S_IWUSR | S_IRUGO, show_pwm, set_pwm, 0),
349 show_pwm, set_pwm, offset-1); 358 SENSOR_ATTR(pwm2, S_IWUSR | S_IRUGO, show_pwm, set_pwm, 1),
350show_and_set_pwm(1) 359 SENSOR_ATTR(pwm3, S_IWUSR | S_IRUGO, show_pwm, set_pwm, 2),
351show_and_set_pwm(2) 360};
352show_and_set_pwm(3)
353 361
354static ssize_t show_in_input(struct device *dev, struct device_attribute *devattr, char *buf) 362static ssize_t show_in_input(struct device *dev, struct device_attribute *devattr, char *buf)
355{ 363{
@@ -386,11 +394,11 @@ static ssize_t set_in_min(struct device *dev, struct device_attribute *devattr,
386 struct pc87360_data *data = i2c_get_clientdata(client); 394 struct pc87360_data *data = i2c_get_clientdata(client);
387 long val = simple_strtol(buf, NULL, 10); 395 long val = simple_strtol(buf, NULL, 10);
388 396
389 down(&data->update_lock); 397 mutex_lock(&data->update_lock);
390 data->in_min[attr->index] = IN_TO_REG(val, data->in_vref); 398 data->in_min[attr->index] = IN_TO_REG(val, data->in_vref);
391 pc87360_write_value(data, LD_IN, attr->index, PC87365_REG_IN_MIN, 399 pc87360_write_value(data, LD_IN, attr->index, PC87365_REG_IN_MIN,
392 data->in_min[attr->index]); 400 data->in_min[attr->index]);
393 up(&data->update_lock); 401 mutex_unlock(&data->update_lock);
394 return count; 402 return count;
395} 403}
396static ssize_t set_in_max(struct device *dev, struct device_attribute *devattr, const char *buf, 404static ssize_t set_in_max(struct device *dev, struct device_attribute *devattr, const char *buf,
@@ -401,35 +409,67 @@ static ssize_t set_in_max(struct device *dev, struct device_attribute *devattr,
401 struct pc87360_data *data = i2c_get_clientdata(client); 409 struct pc87360_data *data = i2c_get_clientdata(client);
402 long val = simple_strtol(buf, NULL, 10); 410 long val = simple_strtol(buf, NULL, 10);
403 411
404 down(&data->update_lock); 412 mutex_lock(&data->update_lock);
405 data->in_max[attr->index] = IN_TO_REG(val, 413 data->in_max[attr->index] = IN_TO_REG(val,
406 data->in_vref); 414 data->in_vref);
407 pc87360_write_value(data, LD_IN, attr->index, PC87365_REG_IN_MAX, 415 pc87360_write_value(data, LD_IN, attr->index, PC87365_REG_IN_MAX,
408 data->in_max[attr->index]); 416 data->in_max[attr->index]);
409 up(&data->update_lock); 417 mutex_unlock(&data->update_lock);
410 return count; 418 return count;
411} 419}
412 420
413#define show_and_set_in(offset) \ 421static struct sensor_device_attribute in_input[] = {
414static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \ 422 SENSOR_ATTR(in0_input, S_IRUGO, show_in_input, NULL, 0),
415 show_in_input, NULL, offset); \ 423 SENSOR_ATTR(in1_input, S_IRUGO, show_in_input, NULL, 1),
416static SENSOR_DEVICE_ATTR(in##offset##_min, S_IWUSR | S_IRUGO, \ 424 SENSOR_ATTR(in2_input, S_IRUGO, show_in_input, NULL, 2),
417 show_in_min, set_in_min, offset); \ 425 SENSOR_ATTR(in3_input, S_IRUGO, show_in_input, NULL, 3),
418static SENSOR_DEVICE_ATTR(in##offset##_max, S_IWUSR | S_IRUGO, \ 426 SENSOR_ATTR(in4_input, S_IRUGO, show_in_input, NULL, 4),
419 show_in_max, set_in_max, offset); \ 427 SENSOR_ATTR(in5_input, S_IRUGO, show_in_input, NULL, 5),
420static SENSOR_DEVICE_ATTR(in##offset##_status, S_IRUGO, \ 428 SENSOR_ATTR(in6_input, S_IRUGO, show_in_input, NULL, 6),
421 show_in_status, NULL, offset); 429 SENSOR_ATTR(in7_input, S_IRUGO, show_in_input, NULL, 7),
422show_and_set_in(0) 430 SENSOR_ATTR(in8_input, S_IRUGO, show_in_input, NULL, 8),
423show_and_set_in(1) 431 SENSOR_ATTR(in9_input, S_IRUGO, show_in_input, NULL, 9),
424show_and_set_in(2) 432 SENSOR_ATTR(in10_input, S_IRUGO, show_in_input, NULL, 10),
425show_and_set_in(3) 433};
426show_and_set_in(4) 434static struct sensor_device_attribute in_status[] = {
427show_and_set_in(5) 435 SENSOR_ATTR(in0_status, S_IRUGO, show_in_status, NULL, 0),
428show_and_set_in(6) 436 SENSOR_ATTR(in1_status, S_IRUGO, show_in_status, NULL, 1),
429show_and_set_in(7) 437 SENSOR_ATTR(in2_status, S_IRUGO, show_in_status, NULL, 2),
430show_and_set_in(8) 438 SENSOR_ATTR(in3_status, S_IRUGO, show_in_status, NULL, 3),
431show_and_set_in(9) 439 SENSOR_ATTR(in4_status, S_IRUGO, show_in_status, NULL, 4),
432show_and_set_in(10) 440 SENSOR_ATTR(in5_status, S_IRUGO, show_in_status, NULL, 5),
441 SENSOR_ATTR(in6_status, S_IRUGO, show_in_status, NULL, 6),
442 SENSOR_ATTR(in7_status, S_IRUGO, show_in_status, NULL, 7),
443 SENSOR_ATTR(in8_status, S_IRUGO, show_in_status, NULL, 8),
444 SENSOR_ATTR(in9_status, S_IRUGO, show_in_status, NULL, 9),
445 SENSOR_ATTR(in10_status, S_IRUGO, show_in_status, NULL, 10),
446};
447static struct sensor_device_attribute in_min[] = {
448 SENSOR_ATTR(in0_min, S_IWUSR | S_IRUGO, show_in_min, set_in_min, 0),
449 SENSOR_ATTR(in1_min, S_IWUSR | S_IRUGO, show_in_min, set_in_min, 1),
450 SENSOR_ATTR(in2_min, S_IWUSR | S_IRUGO, show_in_min, set_in_min, 2),
451 SENSOR_ATTR(in3_min, S_IWUSR | S_IRUGO, show_in_min, set_in_min, 3),
452 SENSOR_ATTR(in4_min, S_IWUSR | S_IRUGO, show_in_min, set_in_min, 4),
453 SENSOR_ATTR(in5_min, S_IWUSR | S_IRUGO, show_in_min, set_in_min, 5),
454 SENSOR_ATTR(in6_min, S_IWUSR | S_IRUGO, show_in_min, set_in_min, 6),
455 SENSOR_ATTR(in7_min, S_IWUSR | S_IRUGO, show_in_min, set_in_min, 7),
456 SENSOR_ATTR(in8_min, S_IWUSR | S_IRUGO, show_in_min, set_in_min, 8),
457 SENSOR_ATTR(in9_min, S_IWUSR | S_IRUGO, show_in_min, set_in_min, 9),
458 SENSOR_ATTR(in10_min, S_IWUSR | S_IRUGO, show_in_min, set_in_min, 10),
459};
460static struct sensor_device_attribute in_max[] = {
461 SENSOR_ATTR(in0_max, S_IWUSR | S_IRUGO, show_in_max, set_in_max, 0),
462 SENSOR_ATTR(in1_max, S_IWUSR | S_IRUGO, show_in_max, set_in_max, 1),
463 SENSOR_ATTR(in2_max, S_IWUSR | S_IRUGO, show_in_max, set_in_max, 2),
464 SENSOR_ATTR(in3_max, S_IWUSR | S_IRUGO, show_in_max, set_in_max, 3),
465 SENSOR_ATTR(in4_max, S_IWUSR | S_IRUGO, show_in_max, set_in_max, 4),
466 SENSOR_ATTR(in5_max, S_IWUSR | S_IRUGO, show_in_max, set_in_max, 5),
467 SENSOR_ATTR(in6_max, S_IWUSR | S_IRUGO, show_in_max, set_in_max, 6),
468 SENSOR_ATTR(in7_max, S_IWUSR | S_IRUGO, show_in_max, set_in_max, 7),
469 SENSOR_ATTR(in8_max, S_IWUSR | S_IRUGO, show_in_max, set_in_max, 8),
470 SENSOR_ATTR(in9_max, S_IWUSR | S_IRUGO, show_in_max, set_in_max, 9),
471 SENSOR_ATTR(in10_max, S_IWUSR | S_IRUGO, show_in_max, set_in_max, 10),
472};
433 473
434static ssize_t show_therm_input(struct device *dev, struct device_attribute *devattr, char *buf) 474static ssize_t show_therm_input(struct device *dev, struct device_attribute *devattr, char *buf)
435{ 475{
@@ -473,11 +513,11 @@ static ssize_t set_therm_min(struct device *dev, struct device_attribute *devatt
473 struct pc87360_data *data = i2c_get_clientdata(client); 513 struct pc87360_data *data = i2c_get_clientdata(client);
474 long val = simple_strtol(buf, NULL, 10); 514 long val = simple_strtol(buf, NULL, 10);
475 515
476 down(&data->update_lock); 516 mutex_lock(&data->update_lock);
477 data->in_min[attr->index] = IN_TO_REG(val, data->in_vref); 517 data->in_min[attr->index] = IN_TO_REG(val, data->in_vref);
478 pc87360_write_value(data, LD_IN, attr->index, PC87365_REG_TEMP_MIN, 518 pc87360_write_value(data, LD_IN, attr->index, PC87365_REG_TEMP_MIN,
479 data->in_min[attr->index]); 519 data->in_min[attr->index]);
480 up(&data->update_lock); 520 mutex_unlock(&data->update_lock);
481 return count; 521 return count;
482} 522}
483static ssize_t set_therm_max(struct device *dev, struct device_attribute *devattr, const char *buf, 523static ssize_t set_therm_max(struct device *dev, struct device_attribute *devattr, const char *buf,
@@ -488,11 +528,11 @@ static ssize_t set_therm_max(struct device *dev, struct device_attribute *devatt
488 struct pc87360_data *data = i2c_get_clientdata(client); 528 struct pc87360_data *data = i2c_get_clientdata(client);
489 long val = simple_strtol(buf, NULL, 10); 529 long val = simple_strtol(buf, NULL, 10);
490 530
491 down(&data->update_lock); 531 mutex_lock(&data->update_lock);
492 data->in_max[attr->index] = IN_TO_REG(val, data->in_vref); 532 data->in_max[attr->index] = IN_TO_REG(val, data->in_vref);
493 pc87360_write_value(data, LD_IN, attr->index, PC87365_REG_TEMP_MAX, 533 pc87360_write_value(data, LD_IN, attr->index, PC87365_REG_TEMP_MAX,
494 data->in_max[attr->index]); 534 data->in_max[attr->index]);
495 up(&data->update_lock); 535 mutex_unlock(&data->update_lock);
496 return count; 536 return count;
497} 537}
498static ssize_t set_therm_crit(struct device *dev, struct device_attribute *devattr, const char *buf, 538static ssize_t set_therm_crit(struct device *dev, struct device_attribute *devattr, const char *buf,
@@ -503,28 +543,51 @@ static ssize_t set_therm_crit(struct device *dev, struct device_attribute *devat
503 struct pc87360_data *data = i2c_get_clientdata(client); 543 struct pc87360_data *data = i2c_get_clientdata(client);
504 long val = simple_strtol(buf, NULL, 10); 544 long val = simple_strtol(buf, NULL, 10);
505 545
506 down(&data->update_lock); 546 mutex_lock(&data->update_lock);
507 data->in_crit[attr->index-11] = IN_TO_REG(val, data->in_vref); 547 data->in_crit[attr->index-11] = IN_TO_REG(val, data->in_vref);
508 pc87360_write_value(data, LD_IN, attr->index, PC87365_REG_TEMP_CRIT, 548 pc87360_write_value(data, LD_IN, attr->index, PC87365_REG_TEMP_CRIT,
509 data->in_crit[attr->index-11]); 549 data->in_crit[attr->index-11]);
510 up(&data->update_lock); 550 mutex_unlock(&data->update_lock);
511 return count; 551 return count;
512} 552}
513 553
514#define show_and_set_therm(offset) \ 554/* the +11 term below reflects the fact that VLM units 11,12,13 are
515static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \ 555 used in the chip to measure voltage across the thermistors
516 show_therm_input, NULL, 11+offset-4); \ 556*/
517static SENSOR_DEVICE_ATTR(temp##offset##_min, S_IWUSR | S_IRUGO, \ 557static struct sensor_device_attribute therm_input[] = {
518 show_therm_min, set_therm_min, 11+offset-4); \ 558 SENSOR_ATTR(temp4_input, S_IRUGO, show_therm_input, NULL, 0+11),
519static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IWUSR | S_IRUGO, \ 559 SENSOR_ATTR(temp5_input, S_IRUGO, show_therm_input, NULL, 1+11),
520 show_therm_max, set_therm_max, 11+offset-4); \ 560 SENSOR_ATTR(temp6_input, S_IRUGO, show_therm_input, NULL, 2+11),
521static SENSOR_DEVICE_ATTR(temp##offset##_crit, S_IWUSR | S_IRUGO, \ 561};
522 show_therm_crit, set_therm_crit, 11+offset-4); \ 562static struct sensor_device_attribute therm_status[] = {
523static SENSOR_DEVICE_ATTR(temp##offset##_status, S_IRUGO, \ 563 SENSOR_ATTR(temp4_status, S_IRUGO, show_therm_status, NULL, 0+11),
524 show_therm_status, NULL, 11+offset-4); 564 SENSOR_ATTR(temp5_status, S_IRUGO, show_therm_status, NULL, 1+11),
525show_and_set_therm(4) 565 SENSOR_ATTR(temp6_status, S_IRUGO, show_therm_status, NULL, 2+11),
526show_and_set_therm(5) 566};
527show_and_set_therm(6) 567static struct sensor_device_attribute therm_min[] = {
568 SENSOR_ATTR(temp4_min, S_IRUGO | S_IWUSR,
569 show_therm_min, set_therm_min, 0+11),
570 SENSOR_ATTR(temp5_min, S_IRUGO | S_IWUSR,
571 show_therm_min, set_therm_min, 1+11),
572 SENSOR_ATTR(temp6_min, S_IRUGO | S_IWUSR,
573 show_therm_min, set_therm_min, 2+11),
574};
575static struct sensor_device_attribute therm_max[] = {
576 SENSOR_ATTR(temp4_max, S_IRUGO | S_IWUSR,
577 show_therm_max, set_therm_max, 0+11),
578 SENSOR_ATTR(temp5_max, S_IRUGO | S_IWUSR,
579 show_therm_max, set_therm_max, 1+11),
580 SENSOR_ATTR(temp6_max, S_IRUGO | S_IWUSR,
581 show_therm_max, set_therm_max, 2+11),
582};
583static struct sensor_device_attribute therm_crit[] = {
584 SENSOR_ATTR(temp4_crit, S_IRUGO | S_IWUSR,
585 show_therm_crit, set_therm_crit, 0+11),
586 SENSOR_ATTR(temp5_crit, S_IRUGO | S_IWUSR,
587 show_therm_crit, set_therm_crit, 1+11),
588 SENSOR_ATTR(temp6_crit, S_IRUGO | S_IWUSR,
589 show_therm_crit, set_therm_crit, 2+11),
590};
528 591
529static ssize_t show_vid(struct device *dev, struct device_attribute *attr, char *buf) 592static ssize_t show_vid(struct device *dev, struct device_attribute *attr, char *buf)
530{ 593{
@@ -592,11 +655,11 @@ static ssize_t set_temp_min(struct device *dev, struct device_attribute *devattr
592 struct pc87360_data *data = i2c_get_clientdata(client); 655 struct pc87360_data *data = i2c_get_clientdata(client);
593 long val = simple_strtol(buf, NULL, 10); 656 long val = simple_strtol(buf, NULL, 10);
594 657
595 down(&data->update_lock); 658 mutex_lock(&data->update_lock);
596 data->temp_min[attr->index] = TEMP_TO_REG(val); 659 data->temp_min[attr->index] = TEMP_TO_REG(val);
597 pc87360_write_value(data, LD_TEMP, attr->index, PC87365_REG_TEMP_MIN, 660 pc87360_write_value(data, LD_TEMP, attr->index, PC87365_REG_TEMP_MIN,
598 data->temp_min[attr->index]); 661 data->temp_min[attr->index]);
599 up(&data->update_lock); 662 mutex_unlock(&data->update_lock);
600 return count; 663 return count;
601} 664}
602static ssize_t set_temp_max(struct device *dev, struct device_attribute *devattr, const char *buf, 665static ssize_t set_temp_max(struct device *dev, struct device_attribute *devattr, const char *buf,
@@ -607,11 +670,11 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *devattr
607 struct pc87360_data *data = i2c_get_clientdata(client); 670 struct pc87360_data *data = i2c_get_clientdata(client);
608 long val = simple_strtol(buf, NULL, 10); 671 long val = simple_strtol(buf, NULL, 10);
609 672
610 down(&data->update_lock); 673 mutex_lock(&data->update_lock);
611 data->temp_max[attr->index] = TEMP_TO_REG(val); 674 data->temp_max[attr->index] = TEMP_TO_REG(val);
612 pc87360_write_value(data, LD_TEMP, attr->index, PC87365_REG_TEMP_MAX, 675 pc87360_write_value(data, LD_TEMP, attr->index, PC87365_REG_TEMP_MAX,
613 data->temp_max[attr->index]); 676 data->temp_max[attr->index]);
614 up(&data->update_lock); 677 mutex_unlock(&data->update_lock);
615 return count; 678 return count;
616} 679}
617static ssize_t set_temp_crit(struct device *dev, struct device_attribute *devattr, const char *buf, 680static ssize_t set_temp_crit(struct device *dev, struct device_attribute *devattr, const char *buf,
@@ -622,28 +685,48 @@ static ssize_t set_temp_crit(struct device *dev, struct device_attribute *devatt
622 struct pc87360_data *data = i2c_get_clientdata(client); 685 struct pc87360_data *data = i2c_get_clientdata(client);
623 long val = simple_strtol(buf, NULL, 10); 686 long val = simple_strtol(buf, NULL, 10);
624 687
625 down(&data->update_lock); 688 mutex_lock(&data->update_lock);
626 data->temp_crit[attr->index] = TEMP_TO_REG(val); 689 data->temp_crit[attr->index] = TEMP_TO_REG(val);
627 pc87360_write_value(data, LD_TEMP, attr->index, PC87365_REG_TEMP_CRIT, 690 pc87360_write_value(data, LD_TEMP, attr->index, PC87365_REG_TEMP_CRIT,
628 data->temp_crit[attr->index]); 691 data->temp_crit[attr->index]);
629 up(&data->update_lock); 692 mutex_unlock(&data->update_lock);
630 return count; 693 return count;
631} 694}
632 695
633#define show_and_set_temp(offset) \ 696static struct sensor_device_attribute temp_input[] = {
634static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \ 697 SENSOR_ATTR(temp1_input, S_IRUGO, show_temp_input, NULL, 0),
635 show_temp_input, NULL, offset-1); \ 698 SENSOR_ATTR(temp2_input, S_IRUGO, show_temp_input, NULL, 1),
636static SENSOR_DEVICE_ATTR(temp##offset##_min, S_IWUSR | S_IRUGO, \ 699 SENSOR_ATTR(temp3_input, S_IRUGO, show_temp_input, NULL, 2),
637 show_temp_min, set_temp_min, offset-1); \ 700};
638static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IWUSR | S_IRUGO, \ 701static struct sensor_device_attribute temp_status[] = {
639 show_temp_max, set_temp_max, offset-1); \ 702 SENSOR_ATTR(temp1_status, S_IRUGO, show_temp_status, NULL, 0),
640static SENSOR_DEVICE_ATTR(temp##offset##_crit, S_IWUSR | S_IRUGO, \ 703 SENSOR_ATTR(temp2_status, S_IRUGO, show_temp_status, NULL, 1),
641 show_temp_crit, set_temp_crit, offset-1); \ 704 SENSOR_ATTR(temp3_status, S_IRUGO, show_temp_status, NULL, 2),
642static SENSOR_DEVICE_ATTR(temp##offset##_status, S_IRUGO, \ 705};
643 show_temp_status, NULL, offset-1); 706static struct sensor_device_attribute temp_min[] = {
644show_and_set_temp(1) 707 SENSOR_ATTR(temp1_min, S_IRUGO | S_IWUSR,
645show_and_set_temp(2) 708 show_temp_min, set_temp_min, 0),
646show_and_set_temp(3) 709 SENSOR_ATTR(temp2_min, S_IRUGO | S_IWUSR,
710 show_temp_min, set_temp_min, 1),
711 SENSOR_ATTR(temp3_min, S_IRUGO | S_IWUSR,
712 show_temp_min, set_temp_min, 2),
713};
714static struct sensor_device_attribute temp_max[] = {
715 SENSOR_ATTR(temp1_max, S_IRUGO | S_IWUSR,
716 show_temp_max, set_temp_max, 0),
717 SENSOR_ATTR(temp2_max, S_IRUGO | S_IWUSR,
718 show_temp_max, set_temp_max, 1),
719 SENSOR_ATTR(temp3_max, S_IRUGO | S_IWUSR,
720 show_temp_max, set_temp_max, 2),
721};
722static struct sensor_device_attribute temp_crit[] = {
723 SENSOR_ATTR(temp1_crit, S_IRUGO | S_IWUSR,
724 show_temp_crit, set_temp_crit, 0),
725 SENSOR_ATTR(temp2_crit, S_IRUGO | S_IWUSR,
726 show_temp_crit, set_temp_crit, 1),
727 SENSOR_ATTR(temp3_crit, S_IRUGO | S_IWUSR,
728 show_temp_crit, set_temp_crit, 2),
729};
647 730
648static ssize_t show_temp_alarms(struct device *dev, struct device_attribute *attr, char *buf) 731static ssize_t show_temp_alarms(struct device *dev, struct device_attribute *attr, char *buf)
649{ 732{
@@ -749,22 +832,24 @@ static int __init pc87360_find(int sioaddr, u8 *devid, unsigned short *addresses
749static int pc87360_detect(struct i2c_adapter *adapter) 832static int pc87360_detect(struct i2c_adapter *adapter)
750{ 833{
751 int i; 834 int i;
752 struct i2c_client *new_client; 835 struct i2c_client *client;
753 struct pc87360_data *data; 836 struct pc87360_data *data;
754 int err = 0; 837 int err = 0;
755 const char *name = "pc87360"; 838 const char *name = "pc87360";
756 int use_thermistors = 0; 839 int use_thermistors = 0;
840 struct device *dev;
757 841
758 if (!(data = kzalloc(sizeof(struct pc87360_data), GFP_KERNEL))) 842 if (!(data = kzalloc(sizeof(struct pc87360_data), GFP_KERNEL)))
759 return -ENOMEM; 843 return -ENOMEM;
760 844
761 new_client = &data->client; 845 client = &data->client;
762 i2c_set_clientdata(new_client, data); 846 dev = &client->dev;
763 new_client->addr = address; 847 i2c_set_clientdata(client, data);
764 init_MUTEX(&data->lock); 848 client->addr = address;
765 new_client->adapter = adapter; 849 mutex_init(&data->lock);
766 new_client->driver = &pc87360_driver; 850 client->adapter = adapter;
767 new_client->flags = 0; 851 client->driver = &pc87360_driver;
852 client->flags = 0;
768 853
769 data->fannr = 2; 854 data->fannr = 2;
770 data->innr = 0; 855 data->innr = 0;
@@ -792,15 +877,15 @@ static int pc87360_detect(struct i2c_adapter *adapter)
792 break; 877 break;
793 } 878 }
794 879
795 strcpy(new_client->name, name); 880 strlcpy(client->name, name, sizeof(client->name));
796 data->valid = 0; 881 data->valid = 0;
797 init_MUTEX(&data->update_lock); 882 mutex_init(&data->update_lock);
798 883
799 for (i = 0; i < 3; i++) { 884 for (i = 0; i < 3; i++) {
800 if (((data->address[i] = extra_isa[i])) 885 if (((data->address[i] = extra_isa[i]))
801 && !request_region(extra_isa[i], PC87360_EXTENT, 886 && !request_region(extra_isa[i], PC87360_EXTENT,
802 pc87360_driver.driver.name)) { 887 pc87360_driver.driver.name)) {
803 dev_err(&new_client->dev, "Region 0x%x-0x%x already " 888 dev_err(&client->dev, "Region 0x%x-0x%x already "
804 "in use!\n", extra_isa[i], 889 "in use!\n", extra_isa[i],
805 extra_isa[i]+PC87360_EXTENT-1); 890 extra_isa[i]+PC87360_EXTENT-1);
806 for (i--; i >= 0; i--) 891 for (i--; i >= 0; i--)
@@ -814,7 +899,7 @@ static int pc87360_detect(struct i2c_adapter *adapter)
814 if (data->fannr) 899 if (data->fannr)
815 data->fan_conf = confreg[0] | (confreg[1] << 8); 900 data->fan_conf = confreg[0] | (confreg[1] << 8);
816 901
817 if ((err = i2c_attach_client(new_client))) 902 if ((err = i2c_attach_client(client)))
818 goto ERROR2; 903 goto ERROR2;
819 904
820 /* Use the correct reference voltage 905 /* Use the correct reference voltage
@@ -828,7 +913,7 @@ static int pc87360_detect(struct i2c_adapter *adapter)
828 PC87365_REG_TEMP_CONFIG); 913 PC87365_REG_TEMP_CONFIG);
829 } 914 }
830 data->in_vref = (i&0x02) ? 3025 : 2966; 915 data->in_vref = (i&0x02) ? 3025 : 2966;
831 dev_dbg(&new_client->dev, "Using %s reference voltage\n", 916 dev_dbg(&client->dev, "Using %s reference voltage\n",
832 (i&0x02) ? "external" : "internal"); 917 (i&0x02) ? "external" : "internal");
833 918
834 data->vid_conf = confreg[3]; 919 data->vid_conf = confreg[3];
@@ -847,154 +932,64 @@ static int pc87360_detect(struct i2c_adapter *adapter)
847 if (devid == 0xe9 && data->address[1]) /* PC87366 */ 932 if (devid == 0xe9 && data->address[1]) /* PC87366 */
848 use_thermistors = confreg[2] & 0x40; 933 use_thermistors = confreg[2] & 0x40;
849 934
850 pc87360_init_client(new_client, use_thermistors); 935 pc87360_init_client(client, use_thermistors);
851 } 936 }
852 937
853 /* Register sysfs hooks */ 938 /* Register sysfs hooks */
854 data->class_dev = hwmon_device_register(&new_client->dev); 939 data->class_dev = hwmon_device_register(&client->dev);
855 if (IS_ERR(data->class_dev)) { 940 if (IS_ERR(data->class_dev)) {
856 err = PTR_ERR(data->class_dev); 941 err = PTR_ERR(data->class_dev);
857 goto ERROR3; 942 goto ERROR3;
858 } 943 }
859 944
860 if (data->innr) { 945 if (data->innr) {
861 device_create_file(&new_client->dev, &sensor_dev_attr_in0_input.dev_attr); 946 for (i = 0; i < 11; i++) {
862 device_create_file(&new_client->dev, &sensor_dev_attr_in1_input.dev_attr); 947 device_create_file(dev, &in_input[i].dev_attr);
863 device_create_file(&new_client->dev, &sensor_dev_attr_in2_input.dev_attr); 948 device_create_file(dev, &in_min[i].dev_attr);
864 device_create_file(&new_client->dev, &sensor_dev_attr_in3_input.dev_attr); 949 device_create_file(dev, &in_max[i].dev_attr);
865 device_create_file(&new_client->dev, &sensor_dev_attr_in4_input.dev_attr); 950 device_create_file(dev, &in_status[i].dev_attr);
866 device_create_file(&new_client->dev, &sensor_dev_attr_in5_input.dev_attr); 951 }
867 device_create_file(&new_client->dev, &sensor_dev_attr_in6_input.dev_attr); 952 device_create_file(dev, &dev_attr_cpu0_vid);
868 device_create_file(&new_client->dev, &sensor_dev_attr_in7_input.dev_attr); 953 device_create_file(dev, &dev_attr_vrm);
869 device_create_file(&new_client->dev, &sensor_dev_attr_in8_input.dev_attr); 954 device_create_file(dev, &dev_attr_alarms_in);
870 device_create_file(&new_client->dev, &sensor_dev_attr_in9_input.dev_attr);
871 device_create_file(&new_client->dev, &sensor_dev_attr_in10_input.dev_attr);
872 device_create_file(&new_client->dev, &sensor_dev_attr_in0_min.dev_attr);
873 device_create_file(&new_client->dev, &sensor_dev_attr_in1_min.dev_attr);
874 device_create_file(&new_client->dev, &sensor_dev_attr_in2_min.dev_attr);
875 device_create_file(&new_client->dev, &sensor_dev_attr_in3_min.dev_attr);
876 device_create_file(&new_client->dev, &sensor_dev_attr_in4_min.dev_attr);
877 device_create_file(&new_client->dev, &sensor_dev_attr_in5_min.dev_attr);
878 device_create_file(&new_client->dev, &sensor_dev_attr_in6_min.dev_attr);
879 device_create_file(&new_client->dev, &sensor_dev_attr_in7_min.dev_attr);
880 device_create_file(&new_client->dev, &sensor_dev_attr_in8_min.dev_attr);
881 device_create_file(&new_client->dev, &sensor_dev_attr_in9_min.dev_attr);
882 device_create_file(&new_client->dev, &sensor_dev_attr_in10_min.dev_attr);
883 device_create_file(&new_client->dev, &sensor_dev_attr_in0_max.dev_attr);
884 device_create_file(&new_client->dev, &sensor_dev_attr_in1_max.dev_attr);
885 device_create_file(&new_client->dev, &sensor_dev_attr_in2_max.dev_attr);
886 device_create_file(&new_client->dev, &sensor_dev_attr_in3_max.dev_attr);
887 device_create_file(&new_client->dev, &sensor_dev_attr_in4_max.dev_attr);
888 device_create_file(&new_client->dev, &sensor_dev_attr_in5_max.dev_attr);
889 device_create_file(&new_client->dev, &sensor_dev_attr_in6_max.dev_attr);
890 device_create_file(&new_client->dev, &sensor_dev_attr_in7_max.dev_attr);
891 device_create_file(&new_client->dev, &sensor_dev_attr_in8_max.dev_attr);
892 device_create_file(&new_client->dev, &sensor_dev_attr_in9_max.dev_attr);
893 device_create_file(&new_client->dev, &sensor_dev_attr_in10_max.dev_attr);
894 device_create_file(&new_client->dev, &sensor_dev_attr_in0_status.dev_attr);
895 device_create_file(&new_client->dev, &sensor_dev_attr_in1_status.dev_attr);
896 device_create_file(&new_client->dev, &sensor_dev_attr_in2_status.dev_attr);
897 device_create_file(&new_client->dev, &sensor_dev_attr_in3_status.dev_attr);
898 device_create_file(&new_client->dev, &sensor_dev_attr_in4_status.dev_attr);
899 device_create_file(&new_client->dev, &sensor_dev_attr_in5_status.dev_attr);
900 device_create_file(&new_client->dev, &sensor_dev_attr_in6_status.dev_attr);
901 device_create_file(&new_client->dev, &sensor_dev_attr_in7_status.dev_attr);
902 device_create_file(&new_client->dev, &sensor_dev_attr_in8_status.dev_attr);
903 device_create_file(&new_client->dev, &sensor_dev_attr_in9_status.dev_attr);
904 device_create_file(&new_client->dev, &sensor_dev_attr_in10_status.dev_attr);
905
906 device_create_file(&new_client->dev, &dev_attr_cpu0_vid);
907 device_create_file(&new_client->dev, &dev_attr_vrm);
908 device_create_file(&new_client->dev, &dev_attr_alarms_in);
909 } 955 }
910 956
911 if (data->tempnr) { 957 if (data->tempnr) {
912 device_create_file(&new_client->dev, &sensor_dev_attr_temp1_input.dev_attr); 958 for (i = 0; i < data->tempnr; i++) {
913 device_create_file(&new_client->dev, &sensor_dev_attr_temp2_input.dev_attr); 959 device_create_file(dev, &temp_input[i].dev_attr);
914 device_create_file(&new_client->dev, &sensor_dev_attr_temp1_min.dev_attr); 960 device_create_file(dev, &temp_min[i].dev_attr);
915 device_create_file(&new_client->dev, &sensor_dev_attr_temp2_min.dev_attr); 961 device_create_file(dev, &temp_max[i].dev_attr);
916 device_create_file(&new_client->dev, &sensor_dev_attr_temp1_max.dev_attr); 962 device_create_file(dev, &temp_crit[i].dev_attr);
917 device_create_file(&new_client->dev, &sensor_dev_attr_temp2_max.dev_attr); 963 device_create_file(dev, &temp_status[i].dev_attr);
918 device_create_file(&new_client->dev, &sensor_dev_attr_temp1_crit.dev_attr);
919 device_create_file(&new_client->dev, &sensor_dev_attr_temp2_crit.dev_attr);
920 device_create_file(&new_client->dev, &sensor_dev_attr_temp1_status.dev_attr);
921 device_create_file(&new_client->dev, &sensor_dev_attr_temp2_status.dev_attr);
922
923 device_create_file(&new_client->dev, &dev_attr_alarms_temp);
924 }
925 if (data->tempnr == 3) {
926 device_create_file(&new_client->dev, &sensor_dev_attr_temp3_input.dev_attr);
927 device_create_file(&new_client->dev, &sensor_dev_attr_temp3_min.dev_attr);
928 device_create_file(&new_client->dev, &sensor_dev_attr_temp3_max.dev_attr);
929 device_create_file(&new_client->dev, &sensor_dev_attr_temp3_crit.dev_attr);
930 device_create_file(&new_client->dev, &sensor_dev_attr_temp3_status.dev_attr);
931 }
932 if (data->innr == 14) {
933 device_create_file(&new_client->dev, &sensor_dev_attr_temp4_input.dev_attr);
934 device_create_file(&new_client->dev, &sensor_dev_attr_temp5_input.dev_attr);
935 device_create_file(&new_client->dev, &sensor_dev_attr_temp6_input.dev_attr);
936 device_create_file(&new_client->dev, &sensor_dev_attr_temp4_min.dev_attr);
937 device_create_file(&new_client->dev, &sensor_dev_attr_temp5_min.dev_attr);
938 device_create_file(&new_client->dev, &sensor_dev_attr_temp6_min.dev_attr);
939 device_create_file(&new_client->dev, &sensor_dev_attr_temp4_max.dev_attr);
940 device_create_file(&new_client->dev, &sensor_dev_attr_temp5_max.dev_attr);
941 device_create_file(&new_client->dev, &sensor_dev_attr_temp6_max.dev_attr);
942 device_create_file(&new_client->dev, &sensor_dev_attr_temp4_crit.dev_attr);
943 device_create_file(&new_client->dev, &sensor_dev_attr_temp5_crit.dev_attr);
944 device_create_file(&new_client->dev, &sensor_dev_attr_temp6_crit.dev_attr);
945 device_create_file(&new_client->dev, &sensor_dev_attr_temp4_status.dev_attr);
946 device_create_file(&new_client->dev, &sensor_dev_attr_temp5_status.dev_attr);
947 device_create_file(&new_client->dev, &sensor_dev_attr_temp6_status.dev_attr);
948 }
949
950 if (data->fannr) {
951 if (FAN_CONFIG_MONITOR(data->fan_conf, 0)) {
952 device_create_file(&new_client->dev,
953 &sensor_dev_attr_fan1_input.dev_attr);
954 device_create_file(&new_client->dev,
955 &sensor_dev_attr_fan1_min.dev_attr);
956 device_create_file(&new_client->dev,
957 &sensor_dev_attr_fan1_div.dev_attr);
958 device_create_file(&new_client->dev,
959 &sensor_dev_attr_fan1_status.dev_attr);
960 } 964 }
965 device_create_file(dev, &dev_attr_alarms_temp);
966 }
961 967
962 if (FAN_CONFIG_MONITOR(data->fan_conf, 1)) { 968 if (data->innr == 14) {
963 device_create_file(&new_client->dev, 969 for (i = 0; i < 3; i++) {
964 &sensor_dev_attr_fan2_input.dev_attr); 970 device_create_file(dev, &therm_input[i].dev_attr);
965 device_create_file(&new_client->dev, 971 device_create_file(dev, &therm_min[i].dev_attr);
966 &sensor_dev_attr_fan2_min.dev_attr); 972 device_create_file(dev, &therm_max[i].dev_attr);
967 device_create_file(&new_client->dev, 973 device_create_file(dev, &therm_crit[i].dev_attr);
968 &sensor_dev_attr_fan2_div.dev_attr); 974 device_create_file(dev, &therm_status[i].dev_attr);
969 device_create_file(&new_client->dev,
970 &sensor_dev_attr_fan2_status.dev_attr);
971 } 975 }
972
973 if (FAN_CONFIG_CONTROL(data->fan_conf, 0))
974 device_create_file(&new_client->dev, &sensor_dev_attr_pwm1.dev_attr);
975 if (FAN_CONFIG_CONTROL(data->fan_conf, 1))
976 device_create_file(&new_client->dev, &sensor_dev_attr_pwm2.dev_attr);
977 } 976 }
978 if (data->fannr == 3) {
979 if (FAN_CONFIG_MONITOR(data->fan_conf, 2)) {
980 device_create_file(&new_client->dev,
981 &sensor_dev_attr_fan3_input.dev_attr);
982 device_create_file(&new_client->dev,
983 &sensor_dev_attr_fan3_min.dev_attr);
984 device_create_file(&new_client->dev,
985 &sensor_dev_attr_fan3_div.dev_attr);
986 device_create_file(&new_client->dev,
987 &sensor_dev_attr_fan3_status.dev_attr);
988 }
989 977
990 if (FAN_CONFIG_CONTROL(data->fan_conf, 2)) 978 for (i = 0; i < data->fannr; i++) {
991 device_create_file(&new_client->dev, &sensor_dev_attr_pwm3.dev_attr); 979 if (FAN_CONFIG_MONITOR(data->fan_conf, i)) {
980 device_create_file(dev, &fan_input[i].dev_attr);
981 device_create_file(dev, &fan_min[i].dev_attr);
982 device_create_file(dev, &fan_div[i].dev_attr);
983 device_create_file(dev, &fan_status[i].dev_attr);
984 }
985 if (FAN_CONFIG_CONTROL(data->fan_conf, i))
986 device_create_file(dev, &pwm[i].dev_attr);
992 } 987 }
993 988
994 return 0; 989 return 0;
995 990
996ERROR3: 991ERROR3:
997 i2c_detach_client(new_client); 992 i2c_detach_client(client);
998ERROR2: 993ERROR2:
999 for (i = 0; i < 3; i++) { 994 for (i = 0; i < 3; i++) {
1000 if (data->address[i]) { 995 if (data->address[i]) {
@@ -1033,11 +1028,11 @@ static int pc87360_read_value(struct pc87360_data *data, u8 ldi, u8 bank,
1033{ 1028{
1034 int res; 1029 int res;
1035 1030
1036 down(&(data->lock)); 1031 mutex_lock(&(data->lock));
1037 if (bank != NO_BANK) 1032 if (bank != NO_BANK)
1038 outb_p(bank, data->address[ldi] + PC87365_REG_BANK); 1033 outb_p(bank, data->address[ldi] + PC87365_REG_BANK);
1039 res = inb_p(data->address[ldi] + reg); 1034 res = inb_p(data->address[ldi] + reg);
1040 up(&(data->lock)); 1035 mutex_unlock(&(data->lock));
1041 1036
1042 return res; 1037 return res;
1043} 1038}
@@ -1045,11 +1040,11 @@ static int pc87360_read_value(struct pc87360_data *data, u8 ldi, u8 bank,
1045static void pc87360_write_value(struct pc87360_data *data, u8 ldi, u8 bank, 1040static void pc87360_write_value(struct pc87360_data *data, u8 ldi, u8 bank,
1046 u8 reg, u8 value) 1041 u8 reg, u8 value)
1047{ 1042{
1048 down(&(data->lock)); 1043 mutex_lock(&(data->lock));
1049 if (bank != NO_BANK) 1044 if (bank != NO_BANK)
1050 outb_p(bank, data->address[ldi] + PC87365_REG_BANK); 1045 outb_p(bank, data->address[ldi] + PC87365_REG_BANK);
1051 outb_p(value, data->address[ldi] + reg); 1046 outb_p(value, data->address[ldi] + reg);
1052 up(&(data->lock)); 1047 mutex_unlock(&(data->lock));
1053} 1048}
1054 1049
1055static void pc87360_init_client(struct i2c_client *client, int use_thermistors) 1050static void pc87360_init_client(struct i2c_client *client, int use_thermistors)
@@ -1071,7 +1066,7 @@ static void pc87360_init_client(struct i2c_client *client, int use_thermistors)
1071 } 1066 }
1072 1067
1073 nr = data->innr < 11 ? data->innr : 11; 1068 nr = data->innr < 11 ? data->innr : 11;
1074 for (i=0; i<nr; i++) { 1069 for (i = 0; i < nr; i++) {
1075 if (init >= init_in[i]) { 1070 if (init >= init_in[i]) {
1076 /* Forcibly enable voltage channel */ 1071 /* Forcibly enable voltage channel */
1077 reg = pc87360_read_value(data, LD_IN, i, 1072 reg = pc87360_read_value(data, LD_IN, i,
@@ -1088,14 +1083,14 @@ static void pc87360_init_client(struct i2c_client *client, int use_thermistors)
1088 1083
1089 /* We can't blindly trust the Super-I/O space configuration bit, 1084 /* We can't blindly trust the Super-I/O space configuration bit,
1090 most BIOS won't set it properly */ 1085 most BIOS won't set it properly */
1091 for (i=11; i<data->innr; i++) { 1086 for (i = 11; i < data->innr; i++) {
1092 reg = pc87360_read_value(data, LD_IN, i, 1087 reg = pc87360_read_value(data, LD_IN, i,
1093 PC87365_REG_TEMP_STATUS); 1088 PC87365_REG_TEMP_STATUS);
1094 use_thermistors = use_thermistors || (reg & 0x01); 1089 use_thermistors = use_thermistors || (reg & 0x01);
1095 } 1090 }
1096 1091
1097 i = use_thermistors ? 2 : 0; 1092 i = use_thermistors ? 2 : 0;
1098 for (; i<data->tempnr; i++) { 1093 for (; i < data->tempnr; i++) {
1099 if (init >= init_temp[i]) { 1094 if (init >= init_temp[i]) {
1100 /* Forcibly enable temperature channel */ 1095 /* Forcibly enable temperature channel */
1101 reg = pc87360_read_value(data, LD_TEMP, i, 1096 reg = pc87360_read_value(data, LD_TEMP, i,
@@ -1111,7 +1106,7 @@ static void pc87360_init_client(struct i2c_client *client, int use_thermistors)
1111 } 1106 }
1112 1107
1113 if (use_thermistors) { 1108 if (use_thermistors) {
1114 for (i=11; i<data->innr; i++) { 1109 for (i = 11; i < data->innr; i++) {
1115 if (init >= init_in[i]) { 1110 if (init >= init_in[i]) {
1116 /* The pin may already be used by thermal 1111 /* The pin may already be used by thermal
1117 diodes */ 1112 diodes */
@@ -1221,7 +1216,7 @@ static struct pc87360_data *pc87360_update_device(struct device *dev)
1221 struct pc87360_data *data = i2c_get_clientdata(client); 1216 struct pc87360_data *data = i2c_get_clientdata(client);
1222 u8 i; 1217 u8 i;
1223 1218
1224 down(&data->update_lock); 1219 mutex_lock(&data->update_lock);
1225 1220
1226 if (time_after(jiffies, data->last_updated + HZ * 2) || !data->valid) { 1221 if (time_after(jiffies, data->last_updated + HZ * 2) || !data->valid) {
1227 dev_dbg(&client->dev, "Data update\n"); 1222 dev_dbg(&client->dev, "Data update\n");
@@ -1321,7 +1316,7 @@ static struct pc87360_data *pc87360_update_device(struct device *dev)
1321 data->valid = 1; 1316 data->valid = 1;
1322 } 1317 }
1323 1318
1324 up(&data->update_lock); 1319 mutex_unlock(&data->update_lock);
1325 1320
1326 return data; 1321 return data;
1327} 1322}
diff --git a/drivers/hwmon/sis5595.c b/drivers/hwmon/sis5595.c
index 8be5189d9b..6f3fda73f7 100644
--- a/drivers/hwmon/sis5595.c
+++ b/drivers/hwmon/sis5595.c
@@ -60,6 +60,7 @@
60#include <linux/err.h> 60#include <linux/err.h>
61#include <linux/init.h> 61#include <linux/init.h>
62#include <linux/jiffies.h> 62#include <linux/jiffies.h>
63#include <linux/mutex.h>
63#include <asm/io.h> 64#include <asm/io.h>
64 65
65 66
@@ -167,9 +168,9 @@ static inline u8 DIV_TO_REG(int val)
167struct sis5595_data { 168struct sis5595_data {
168 struct i2c_client client; 169 struct i2c_client client;
169 struct class_device *class_dev; 170 struct class_device *class_dev;
170 struct semaphore lock; 171 struct mutex lock;
171 172
172 struct semaphore update_lock; 173 struct mutex update_lock;
173 char valid; /* !=0 if following fields are valid */ 174 char valid; /* !=0 if following fields are valid */
174 unsigned long last_updated; /* In jiffies */ 175 unsigned long last_updated; /* In jiffies */
175 char maxins; /* == 3 if temp enabled, otherwise == 4 */ 176 char maxins; /* == 3 if temp enabled, otherwise == 4 */
@@ -192,8 +193,8 @@ static struct pci_dev *s_bridge; /* pointer to the (only) sis5595 */
192static int sis5595_detect(struct i2c_adapter *adapter); 193static int sis5595_detect(struct i2c_adapter *adapter);
193static int sis5595_detach_client(struct i2c_client *client); 194static int sis5595_detach_client(struct i2c_client *client);
194 195
195static int sis5595_read_value(struct i2c_client *client, u8 register); 196static int sis5595_read_value(struct i2c_client *client, u8 reg);
196static int sis5595_write_value(struct i2c_client *client, u8 register, u8 value); 197static int sis5595_write_value(struct i2c_client *client, u8 reg, u8 value);
197static struct sis5595_data *sis5595_update_device(struct device *dev); 198static struct sis5595_data *sis5595_update_device(struct device *dev);
198static void sis5595_init_client(struct i2c_client *client); 199static void sis5595_init_client(struct i2c_client *client);
199 200
@@ -231,10 +232,10 @@ static ssize_t set_in_min(struct device *dev, const char *buf,
231 struct sis5595_data *data = i2c_get_clientdata(client); 232 struct sis5595_data *data = i2c_get_clientdata(client);
232 unsigned long val = simple_strtoul(buf, NULL, 10); 233 unsigned long val = simple_strtoul(buf, NULL, 10);
233 234
234 down(&data->update_lock); 235 mutex_lock(&data->update_lock);
235 data->in_min[nr] = IN_TO_REG(val); 236 data->in_min[nr] = IN_TO_REG(val);
236 sis5595_write_value(client, SIS5595_REG_IN_MIN(nr), data->in_min[nr]); 237 sis5595_write_value(client, SIS5595_REG_IN_MIN(nr), data->in_min[nr]);
237 up(&data->update_lock); 238 mutex_unlock(&data->update_lock);
238 return count; 239 return count;
239} 240}
240 241
@@ -245,10 +246,10 @@ static ssize_t set_in_max(struct device *dev, const char *buf,
245 struct sis5595_data *data = i2c_get_clientdata(client); 246 struct sis5595_data *data = i2c_get_clientdata(client);
246 unsigned long val = simple_strtoul(buf, NULL, 10); 247 unsigned long val = simple_strtoul(buf, NULL, 10);
247 248
248 down(&data->update_lock); 249 mutex_lock(&data->update_lock);
249 data->in_max[nr] = IN_TO_REG(val); 250 data->in_max[nr] = IN_TO_REG(val);
250 sis5595_write_value(client, SIS5595_REG_IN_MAX(nr), data->in_max[nr]); 251 sis5595_write_value(client, SIS5595_REG_IN_MAX(nr), data->in_max[nr]);
251 up(&data->update_lock); 252 mutex_unlock(&data->update_lock);
252 return count; 253 return count;
253} 254}
254 255
@@ -310,10 +311,10 @@ static ssize_t set_temp_over(struct device *dev, struct device_attribute *attr,
310 struct sis5595_data *data = i2c_get_clientdata(client); 311 struct sis5595_data *data = i2c_get_clientdata(client);
311 long val = simple_strtol(buf, NULL, 10); 312 long val = simple_strtol(buf, NULL, 10);
312 313
313 down(&data->update_lock); 314 mutex_lock(&data->update_lock);
314 data->temp_over = TEMP_TO_REG(val); 315 data->temp_over = TEMP_TO_REG(val);
315 sis5595_write_value(client, SIS5595_REG_TEMP_OVER, data->temp_over); 316 sis5595_write_value(client, SIS5595_REG_TEMP_OVER, data->temp_over);
316 up(&data->update_lock); 317 mutex_unlock(&data->update_lock);
317 return count; 318 return count;
318} 319}
319 320
@@ -329,10 +330,10 @@ static ssize_t set_temp_hyst(struct device *dev, struct device_attribute *attr,
329 struct sis5595_data *data = i2c_get_clientdata(client); 330 struct sis5595_data *data = i2c_get_clientdata(client);
330 long val = simple_strtol(buf, NULL, 10); 331 long val = simple_strtol(buf, NULL, 10);
331 332
332 down(&data->update_lock); 333 mutex_lock(&data->update_lock);
333 data->temp_hyst = TEMP_TO_REG(val); 334 data->temp_hyst = TEMP_TO_REG(val);
334 sis5595_write_value(client, SIS5595_REG_TEMP_HYST, data->temp_hyst); 335 sis5595_write_value(client, SIS5595_REG_TEMP_HYST, data->temp_hyst);
335 up(&data->update_lock); 336 mutex_unlock(&data->update_lock);
336 return count; 337 return count;
337} 338}
338 339
@@ -364,10 +365,10 @@ static ssize_t set_fan_min(struct device *dev, const char *buf,
364 struct sis5595_data *data = i2c_get_clientdata(client); 365 struct sis5595_data *data = i2c_get_clientdata(client);
365 unsigned long val = simple_strtoul(buf, NULL, 10); 366 unsigned long val = simple_strtoul(buf, NULL, 10);
366 367
367 down(&data->update_lock); 368 mutex_lock(&data->update_lock);
368 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); 369 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
369 sis5595_write_value(client, SIS5595_REG_FAN_MIN(nr), data->fan_min[nr]); 370 sis5595_write_value(client, SIS5595_REG_FAN_MIN(nr), data->fan_min[nr]);
370 up(&data->update_lock); 371 mutex_unlock(&data->update_lock);
371 return count; 372 return count;
372} 373}
373 374
@@ -390,7 +391,7 @@ static ssize_t set_fan_div(struct device *dev, const char *buf,
390 unsigned long val = simple_strtoul(buf, NULL, 10); 391 unsigned long val = simple_strtoul(buf, NULL, 10);
391 int reg; 392 int reg;
392 393
393 down(&data->update_lock); 394 mutex_lock(&data->update_lock);
394 min = FAN_FROM_REG(data->fan_min[nr], 395 min = FAN_FROM_REG(data->fan_min[nr],
395 DIV_FROM_REG(data->fan_div[nr])); 396 DIV_FROM_REG(data->fan_div[nr]));
396 reg = sis5595_read_value(client, SIS5595_REG_FANDIV); 397 reg = sis5595_read_value(client, SIS5595_REG_FANDIV);
@@ -403,7 +404,7 @@ static ssize_t set_fan_div(struct device *dev, const char *buf,
403 default: 404 default:
404 dev_err(&client->dev, "fan_div value %ld not " 405 dev_err(&client->dev, "fan_div value %ld not "
405 "supported. Choose one of 1, 2, 4 or 8!\n", val); 406 "supported. Choose one of 1, 2, 4 or 8!\n", val);
406 up(&data->update_lock); 407 mutex_unlock(&data->update_lock);
407 return -EINVAL; 408 return -EINVAL;
408 } 409 }
409 410
@@ -419,7 +420,7 @@ static ssize_t set_fan_div(struct device *dev, const char *buf,
419 data->fan_min[nr] = 420 data->fan_min[nr] =
420 FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr])); 421 FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr]));
421 sis5595_write_value(client, SIS5595_REG_FAN_MIN(nr), data->fan_min[nr]); 422 sis5595_write_value(client, SIS5595_REG_FAN_MIN(nr), data->fan_min[nr]);
422 up(&data->update_lock); 423 mutex_unlock(&data->update_lock);
423 return count; 424 return count;
424} 425}
425 426
@@ -527,7 +528,7 @@ static int sis5595_detect(struct i2c_adapter *adapter)
527 528
528 new_client = &data->client; 529 new_client = &data->client;
529 new_client->addr = address; 530 new_client->addr = address;
530 init_MUTEX(&data->lock); 531 mutex_init(&data->lock);
531 i2c_set_clientdata(new_client, data); 532 i2c_set_clientdata(new_client, data);
532 new_client->adapter = adapter; 533 new_client->adapter = adapter;
533 new_client->driver = &sis5595_driver; 534 new_client->driver = &sis5595_driver;
@@ -548,7 +549,7 @@ static int sis5595_detect(struct i2c_adapter *adapter)
548 strlcpy(new_client->name, "sis5595", I2C_NAME_SIZE); 549 strlcpy(new_client->name, "sis5595", I2C_NAME_SIZE);
549 550
550 data->valid = 0; 551 data->valid = 0;
551 init_MUTEX(&data->update_lock); 552 mutex_init(&data->update_lock);
552 553
553 /* Tell the I2C layer a new client has arrived */ 554 /* Tell the I2C layer a new client has arrived */
554 if ((err = i2c_attach_client(new_client))) 555 if ((err = i2c_attach_client(new_client)))
@@ -635,20 +636,20 @@ static int sis5595_read_value(struct i2c_client *client, u8 reg)
635 int res; 636 int res;
636 637
637 struct sis5595_data *data = i2c_get_clientdata(client); 638 struct sis5595_data *data = i2c_get_clientdata(client);
638 down(&data->lock); 639 mutex_lock(&data->lock);
639 outb_p(reg, client->addr + SIS5595_ADDR_REG_OFFSET); 640 outb_p(reg, client->addr + SIS5595_ADDR_REG_OFFSET);
640 res = inb_p(client->addr + SIS5595_DATA_REG_OFFSET); 641 res = inb_p(client->addr + SIS5595_DATA_REG_OFFSET);
641 up(&data->lock); 642 mutex_unlock(&data->lock);
642 return res; 643 return res;
643} 644}
644 645
645static int sis5595_write_value(struct i2c_client *client, u8 reg, u8 value) 646static int sis5595_write_value(struct i2c_client *client, u8 reg, u8 value)
646{ 647{
647 struct sis5595_data *data = i2c_get_clientdata(client); 648 struct sis5595_data *data = i2c_get_clientdata(client);
648 down(&data->lock); 649 mutex_lock(&data->lock);
649 outb_p(reg, client->addr + SIS5595_ADDR_REG_OFFSET); 650 outb_p(reg, client->addr + SIS5595_ADDR_REG_OFFSET);
650 outb_p(value, client->addr + SIS5595_DATA_REG_OFFSET); 651 outb_p(value, client->addr + SIS5595_DATA_REG_OFFSET);
651 up(&data->lock); 652 mutex_unlock(&data->lock);
652 return 0; 653 return 0;
653} 654}
654 655
@@ -667,7 +668,7 @@ static struct sis5595_data *sis5595_update_device(struct device *dev)
667 struct sis5595_data *data = i2c_get_clientdata(client); 668 struct sis5595_data *data = i2c_get_clientdata(client);
668 int i; 669 int i;
669 670
670 down(&data->update_lock); 671 mutex_lock(&data->update_lock);
671 672
672 if (time_after(jiffies, data->last_updated + HZ + HZ / 2) 673 if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
673 || !data->valid) { 674 || !data->valid) {
@@ -707,7 +708,7 @@ static struct sis5595_data *sis5595_update_device(struct device *dev)
707 data->valid = 1; 708 data->valid = 1;
708 } 709 }
709 710
710 up(&data->update_lock); 711 mutex_unlock(&data->update_lock);
711 712
712 return data; 713 return data;
713} 714}
diff --git a/drivers/hwmon/smsc47b397.c b/drivers/hwmon/smsc47b397.c
index 8663bbbe97..b6086186d2 100644
--- a/drivers/hwmon/smsc47b397.c
+++ b/drivers/hwmon/smsc47b397.c
@@ -35,6 +35,7 @@
35#include <linux/hwmon.h> 35#include <linux/hwmon.h>
36#include <linux/err.h> 36#include <linux/err.h>
37#include <linux/init.h> 37#include <linux/init.h>
38#include <linux/mutex.h>
38#include <asm/io.h> 39#include <asm/io.h>
39 40
40/* Address is autodetected, there is no default value */ 41/* Address is autodetected, there is no default value */
@@ -92,9 +93,9 @@ static u8 smsc47b397_reg_temp[] = {0x25, 0x26, 0x27, 0x80};
92struct smsc47b397_data { 93struct smsc47b397_data {
93 struct i2c_client client; 94 struct i2c_client client;
94 struct class_device *class_dev; 95 struct class_device *class_dev;
95 struct semaphore lock; 96 struct mutex lock;
96 97
97 struct semaphore update_lock; 98 struct mutex update_lock;
98 unsigned long last_updated; /* in jiffies */ 99 unsigned long last_updated; /* in jiffies */
99 int valid; 100 int valid;
100 101
@@ -108,10 +109,10 @@ static int smsc47b397_read_value(struct i2c_client *client, u8 reg)
108 struct smsc47b397_data *data = i2c_get_clientdata(client); 109 struct smsc47b397_data *data = i2c_get_clientdata(client);
109 int res; 110 int res;
110 111
111 down(&data->lock); 112 mutex_lock(&data->lock);
112 outb(reg, client->addr); 113 outb(reg, client->addr);
113 res = inb_p(client->addr + 1); 114 res = inb_p(client->addr + 1);
114 up(&data->lock); 115 mutex_unlock(&data->lock);
115 return res; 116 return res;
116} 117}
117 118
@@ -121,7 +122,7 @@ static struct smsc47b397_data *smsc47b397_update_device(struct device *dev)
121 struct smsc47b397_data *data = i2c_get_clientdata(client); 122 struct smsc47b397_data *data = i2c_get_clientdata(client);
122 int i; 123 int i;
123 124
124 down(&data->update_lock); 125 mutex_lock(&data->update_lock);
125 126
126 if (time_after(jiffies, data->last_updated + HZ) || !data->valid) { 127 if (time_after(jiffies, data->last_updated + HZ) || !data->valid) {
127 dev_dbg(&client->dev, "starting device update...\n"); 128 dev_dbg(&client->dev, "starting device update...\n");
@@ -144,7 +145,7 @@ static struct smsc47b397_data *smsc47b397_update_device(struct device *dev)
144 dev_dbg(&client->dev, "... device update complete\n"); 145 dev_dbg(&client->dev, "... device update complete\n");
145 } 146 }
146 147
147 up(&data->update_lock); 148 mutex_unlock(&data->update_lock);
148 149
149 return data; 150 return data;
150} 151}
@@ -254,14 +255,14 @@ static int smsc47b397_detect(struct i2c_adapter *adapter)
254 new_client = &data->client; 255 new_client = &data->client;
255 i2c_set_clientdata(new_client, data); 256 i2c_set_clientdata(new_client, data);
256 new_client->addr = address; 257 new_client->addr = address;
257 init_MUTEX(&data->lock); 258 mutex_init(&data->lock);
258 new_client->adapter = adapter; 259 new_client->adapter = adapter;
259 new_client->driver = &smsc47b397_driver; 260 new_client->driver = &smsc47b397_driver;
260 new_client->flags = 0; 261 new_client->flags = 0;
261 262
262 strlcpy(new_client->name, "smsc47b397", I2C_NAME_SIZE); 263 strlcpy(new_client->name, "smsc47b397", I2C_NAME_SIZE);
263 264
264 init_MUTEX(&data->update_lock); 265 mutex_init(&data->update_lock);
265 266
266 if ((err = i2c_attach_client(new_client))) 267 if ((err = i2c_attach_client(new_client)))
267 goto error_free; 268 goto error_free;
diff --git a/drivers/hwmon/smsc47m1.c b/drivers/hwmon/smsc47m1.c
index d1e3ec0fe4..7732aec545 100644
--- a/drivers/hwmon/smsc47m1.c
+++ b/drivers/hwmon/smsc47m1.c
@@ -34,6 +34,7 @@
34#include <linux/hwmon.h> 34#include <linux/hwmon.h>
35#include <linux/err.h> 35#include <linux/err.h>
36#include <linux/init.h> 36#include <linux/init.h>
37#include <linux/mutex.h>
37#include <asm/io.h> 38#include <asm/io.h>
38 39
39/* Address is autodetected, there is no default value */ 40/* Address is autodetected, there is no default value */
@@ -102,9 +103,9 @@ superio_exit(void)
102struct smsc47m1_data { 103struct smsc47m1_data {
103 struct i2c_client client; 104 struct i2c_client client;
104 struct class_device *class_dev; 105 struct class_device *class_dev;
105 struct semaphore lock; 106 struct mutex lock;
106 107
107 struct semaphore update_lock; 108 struct mutex update_lock;
108 unsigned long last_updated; /* In jiffies */ 109 unsigned long last_updated; /* In jiffies */
109 110
110 u8 fan[2]; /* Register value */ 111 u8 fan[2]; /* Register value */
@@ -188,18 +189,18 @@ static ssize_t set_fan_min(struct device *dev, const char *buf,
188 struct smsc47m1_data *data = i2c_get_clientdata(client); 189 struct smsc47m1_data *data = i2c_get_clientdata(client);
189 long rpmdiv, val = simple_strtol(buf, NULL, 10); 190 long rpmdiv, val = simple_strtol(buf, NULL, 10);
190 191
191 down(&data->update_lock); 192 mutex_lock(&data->update_lock);
192 rpmdiv = val * DIV_FROM_REG(data->fan_div[nr]); 193 rpmdiv = val * DIV_FROM_REG(data->fan_div[nr]);
193 194
194 if (983040 > 192 * rpmdiv || 2 * rpmdiv > 983040) { 195 if (983040 > 192 * rpmdiv || 2 * rpmdiv > 983040) {
195 up(&data->update_lock); 196 mutex_unlock(&data->update_lock);
196 return -EINVAL; 197 return -EINVAL;
197 } 198 }
198 199
199 data->fan_preload[nr] = 192 - ((983040 + rpmdiv / 2) / rpmdiv); 200 data->fan_preload[nr] = 192 - ((983040 + rpmdiv / 2) / rpmdiv);
200 smsc47m1_write_value(client, SMSC47M1_REG_FAN_PRELOAD(nr), 201 smsc47m1_write_value(client, SMSC47M1_REG_FAN_PRELOAD(nr),
201 data->fan_preload[nr]); 202 data->fan_preload[nr]);
202 up(&data->update_lock); 203 mutex_unlock(&data->update_lock);
203 204
204 return count; 205 return count;
205} 206}
@@ -220,14 +221,14 @@ static ssize_t set_fan_div(struct device *dev, const char *buf,
220 if (new_div == old_div) /* No change */ 221 if (new_div == old_div) /* No change */
221 return count; 222 return count;
222 223
223 down(&data->update_lock); 224 mutex_lock(&data->update_lock);
224 switch (new_div) { 225 switch (new_div) {
225 case 1: data->fan_div[nr] = 0; break; 226 case 1: data->fan_div[nr] = 0; break;
226 case 2: data->fan_div[nr] = 1; break; 227 case 2: data->fan_div[nr] = 1; break;
227 case 4: data->fan_div[nr] = 2; break; 228 case 4: data->fan_div[nr] = 2; break;
228 case 8: data->fan_div[nr] = 3; break; 229 case 8: data->fan_div[nr] = 3; break;
229 default: 230 default:
230 up(&data->update_lock); 231 mutex_unlock(&data->update_lock);
231 return -EINVAL; 232 return -EINVAL;
232 } 233 }
233 234
@@ -241,7 +242,7 @@ static ssize_t set_fan_div(struct device *dev, const char *buf,
241 data->fan_preload[nr] = SENSORS_LIMIT(tmp, 0, 191); 242 data->fan_preload[nr] = SENSORS_LIMIT(tmp, 0, 191);
242 smsc47m1_write_value(client, SMSC47M1_REG_FAN_PRELOAD(nr), 243 smsc47m1_write_value(client, SMSC47M1_REG_FAN_PRELOAD(nr),
243 data->fan_preload[nr]); 244 data->fan_preload[nr]);
244 up(&data->update_lock); 245 mutex_unlock(&data->update_lock);
245 246
246 return count; 247 return count;
247} 248}
@@ -257,12 +258,12 @@ static ssize_t set_pwm(struct device *dev, const char *buf,
257 if (val < 0 || val > 255) 258 if (val < 0 || val > 255)
258 return -EINVAL; 259 return -EINVAL;
259 260
260 down(&data->update_lock); 261 mutex_lock(&data->update_lock);
261 data->pwm[nr] &= 0x81; /* Preserve additional bits */ 262 data->pwm[nr] &= 0x81; /* Preserve additional bits */
262 data->pwm[nr] |= PWM_TO_REG(val); 263 data->pwm[nr] |= PWM_TO_REG(val);
263 smsc47m1_write_value(client, SMSC47M1_REG_PWM(nr), 264 smsc47m1_write_value(client, SMSC47M1_REG_PWM(nr),
264 data->pwm[nr]); 265 data->pwm[nr]);
265 up(&data->update_lock); 266 mutex_unlock(&data->update_lock);
266 267
267 return count; 268 return count;
268} 269}
@@ -278,12 +279,12 @@ static ssize_t set_pwm_en(struct device *dev, const char *buf,
278 if (val != 0 && val != 1) 279 if (val != 0 && val != 1)
279 return -EINVAL; 280 return -EINVAL;
280 281
281 down(&data->update_lock); 282 mutex_lock(&data->update_lock);
282 data->pwm[nr] &= 0xFE; /* preserve the other bits */ 283 data->pwm[nr] &= 0xFE; /* preserve the other bits */
283 data->pwm[nr] |= !val; 284 data->pwm[nr] |= !val;
284 smsc47m1_write_value(client, SMSC47M1_REG_PWM(nr), 285 smsc47m1_write_value(client, SMSC47M1_REG_PWM(nr),
285 data->pwm[nr]); 286 data->pwm[nr]);
286 up(&data->update_lock); 287 mutex_unlock(&data->update_lock);
287 288
288 return count; 289 return count;
289} 290}
@@ -408,13 +409,13 @@ static int smsc47m1_detect(struct i2c_adapter *adapter)
408 new_client = &data->client; 409 new_client = &data->client;
409 i2c_set_clientdata(new_client, data); 410 i2c_set_clientdata(new_client, data);
410 new_client->addr = address; 411 new_client->addr = address;
411 init_MUTEX(&data->lock); 412 mutex_init(&data->lock);
412 new_client->adapter = adapter; 413 new_client->adapter = adapter;
413 new_client->driver = &smsc47m1_driver; 414 new_client->driver = &smsc47m1_driver;
414 new_client->flags = 0; 415 new_client->flags = 0;
415 416
416 strlcpy(new_client->name, "smsc47m1", I2C_NAME_SIZE); 417 strlcpy(new_client->name, "smsc47m1", I2C_NAME_SIZE);
417 init_MUTEX(&data->update_lock); 418 mutex_init(&data->update_lock);
418 419
419 /* If no function is properly configured, there's no point in 420 /* If no function is properly configured, there's no point in
420 actually registering the chip. */ 421 actually registering the chip. */
@@ -512,17 +513,17 @@ static int smsc47m1_read_value(struct i2c_client *client, u8 reg)
512{ 513{
513 int res; 514 int res;
514 515
515 down(&((struct smsc47m1_data *) i2c_get_clientdata(client))->lock); 516 mutex_lock(&((struct smsc47m1_data *) i2c_get_clientdata(client))->lock);
516 res = inb_p(client->addr + reg); 517 res = inb_p(client->addr + reg);
517 up(&((struct smsc47m1_data *) i2c_get_clientdata(client))->lock); 518 mutex_unlock(&((struct smsc47m1_data *) i2c_get_clientdata(client))->lock);
518 return res; 519 return res;
519} 520}
520 521
521static void smsc47m1_write_value(struct i2c_client *client, u8 reg, u8 value) 522static void smsc47m1_write_value(struct i2c_client *client, u8 reg, u8 value)
522{ 523{
523 down(&((struct smsc47m1_data *) i2c_get_clientdata(client))->lock); 524 mutex_lock(&((struct smsc47m1_data *) i2c_get_clientdata(client))->lock);
524 outb_p(value, client->addr + reg); 525 outb_p(value, client->addr + reg);
525 up(&((struct smsc47m1_data *) i2c_get_clientdata(client))->lock); 526 mutex_unlock(&((struct smsc47m1_data *) i2c_get_clientdata(client))->lock);
526} 527}
527 528
528static struct smsc47m1_data *smsc47m1_update_device(struct device *dev, 529static struct smsc47m1_data *smsc47m1_update_device(struct device *dev,
@@ -531,7 +532,7 @@ static struct smsc47m1_data *smsc47m1_update_device(struct device *dev,
531 struct i2c_client *client = to_i2c_client(dev); 532 struct i2c_client *client = to_i2c_client(dev);
532 struct smsc47m1_data *data = i2c_get_clientdata(client); 533 struct smsc47m1_data *data = i2c_get_clientdata(client);
533 534
534 down(&data->update_lock); 535 mutex_lock(&data->update_lock);
535 536
536 if (time_after(jiffies, data->last_updated + HZ + HZ / 2) || init) { 537 if (time_after(jiffies, data->last_updated + HZ + HZ / 2) || init) {
537 int i; 538 int i;
@@ -558,7 +559,7 @@ static struct smsc47m1_data *smsc47m1_update_device(struct device *dev,
558 data->last_updated = jiffies; 559 data->last_updated = jiffies;
559 } 560 }
560 561
561 up(&data->update_lock); 562 mutex_unlock(&data->update_lock);
562 return data; 563 return data;
563} 564}
564 565
diff --git a/drivers/hwmon/via686a.c b/drivers/hwmon/via686a.c
index cb01848729..166298f1f1 100644
--- a/drivers/hwmon/via686a.c
+++ b/drivers/hwmon/via686a.c
@@ -39,6 +39,7 @@
39#include <linux/hwmon.h> 39#include <linux/hwmon.h>
40#include <linux/err.h> 40#include <linux/err.h>
41#include <linux/init.h> 41#include <linux/init.h>
42#include <linux/mutex.h>
42#include <asm/io.h> 43#include <asm/io.h>
43 44
44 45
@@ -296,7 +297,7 @@ static inline long TEMP_FROM_REG10(u16 val)
296struct via686a_data { 297struct via686a_data {
297 struct i2c_client client; 298 struct i2c_client client;
298 struct class_device *class_dev; 299 struct class_device *class_dev;
299 struct semaphore update_lock; 300 struct mutex update_lock;
300 char valid; /* !=0 if following fields are valid */ 301 char valid; /* !=0 if following fields are valid */
301 unsigned long last_updated; /* In jiffies */ 302 unsigned long last_updated; /* In jiffies */
302 303
@@ -355,11 +356,11 @@ static ssize_t set_in_min(struct device *dev, const char *buf,
355 struct via686a_data *data = i2c_get_clientdata(client); 356 struct via686a_data *data = i2c_get_clientdata(client);
356 unsigned long val = simple_strtoul(buf, NULL, 10); 357 unsigned long val = simple_strtoul(buf, NULL, 10);
357 358
358 down(&data->update_lock); 359 mutex_lock(&data->update_lock);
359 data->in_min[nr] = IN_TO_REG(val, nr); 360 data->in_min[nr] = IN_TO_REG(val, nr);
360 via686a_write_value(client, VIA686A_REG_IN_MIN(nr), 361 via686a_write_value(client, VIA686A_REG_IN_MIN(nr),
361 data->in_min[nr]); 362 data->in_min[nr]);
362 up(&data->update_lock); 363 mutex_unlock(&data->update_lock);
363 return count; 364 return count;
364} 365}
365static ssize_t set_in_max(struct device *dev, const char *buf, 366static ssize_t set_in_max(struct device *dev, const char *buf,
@@ -368,11 +369,11 @@ static ssize_t set_in_max(struct device *dev, const char *buf,
368 struct via686a_data *data = i2c_get_clientdata(client); 369 struct via686a_data *data = i2c_get_clientdata(client);
369 unsigned long val = simple_strtoul(buf, NULL, 10); 370 unsigned long val = simple_strtoul(buf, NULL, 10);
370 371
371 down(&data->update_lock); 372 mutex_lock(&data->update_lock);
372 data->in_max[nr] = IN_TO_REG(val, nr); 373 data->in_max[nr] = IN_TO_REG(val, nr);
373 via686a_write_value(client, VIA686A_REG_IN_MAX(nr), 374 via686a_write_value(client, VIA686A_REG_IN_MAX(nr),
374 data->in_max[nr]); 375 data->in_max[nr]);
375 up(&data->update_lock); 376 mutex_unlock(&data->update_lock);
376 return count; 377 return count;
377} 378}
378#define show_in_offset(offset) \ 379#define show_in_offset(offset) \
@@ -432,11 +433,11 @@ static ssize_t set_temp_over(struct device *dev, const char *buf,
432 struct via686a_data *data = i2c_get_clientdata(client); 433 struct via686a_data *data = i2c_get_clientdata(client);
433 int val = simple_strtol(buf, NULL, 10); 434 int val = simple_strtol(buf, NULL, 10);
434 435
435 down(&data->update_lock); 436 mutex_lock(&data->update_lock);
436 data->temp_over[nr] = TEMP_TO_REG(val); 437 data->temp_over[nr] = TEMP_TO_REG(val);
437 via686a_write_value(client, VIA686A_REG_TEMP_OVER[nr], 438 via686a_write_value(client, VIA686A_REG_TEMP_OVER[nr],
438 data->temp_over[nr]); 439 data->temp_over[nr]);
439 up(&data->update_lock); 440 mutex_unlock(&data->update_lock);
440 return count; 441 return count;
441} 442}
442static ssize_t set_temp_hyst(struct device *dev, const char *buf, 443static ssize_t set_temp_hyst(struct device *dev, const char *buf,
@@ -445,11 +446,11 @@ static ssize_t set_temp_hyst(struct device *dev, const char *buf,
445 struct via686a_data *data = i2c_get_clientdata(client); 446 struct via686a_data *data = i2c_get_clientdata(client);
446 int val = simple_strtol(buf, NULL, 10); 447 int val = simple_strtol(buf, NULL, 10);
447 448
448 down(&data->update_lock); 449 mutex_lock(&data->update_lock);
449 data->temp_hyst[nr] = TEMP_TO_REG(val); 450 data->temp_hyst[nr] = TEMP_TO_REG(val);
450 via686a_write_value(client, VIA686A_REG_TEMP_HYST[nr], 451 via686a_write_value(client, VIA686A_REG_TEMP_HYST[nr],
451 data->temp_hyst[nr]); 452 data->temp_hyst[nr]);
452 up(&data->update_lock); 453 mutex_unlock(&data->update_lock);
453 return count; 454 return count;
454} 455}
455#define show_temp_offset(offset) \ 456#define show_temp_offset(offset) \
@@ -508,10 +509,10 @@ static ssize_t set_fan_min(struct device *dev, const char *buf,
508 struct via686a_data *data = i2c_get_clientdata(client); 509 struct via686a_data *data = i2c_get_clientdata(client);
509 int val = simple_strtol(buf, NULL, 10); 510 int val = simple_strtol(buf, NULL, 10);
510 511
511 down(&data->update_lock); 512 mutex_lock(&data->update_lock);
512 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); 513 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
513 via686a_write_value(client, VIA686A_REG_FAN_MIN(nr+1), data->fan_min[nr]); 514 via686a_write_value(client, VIA686A_REG_FAN_MIN(nr+1), data->fan_min[nr]);
514 up(&data->update_lock); 515 mutex_unlock(&data->update_lock);
515 return count; 516 return count;
516} 517}
517static ssize_t set_fan_div(struct device *dev, const char *buf, 518static ssize_t set_fan_div(struct device *dev, const char *buf,
@@ -521,12 +522,12 @@ static ssize_t set_fan_div(struct device *dev, const char *buf,
521 int val = simple_strtol(buf, NULL, 10); 522 int val = simple_strtol(buf, NULL, 10);
522 int old; 523 int old;
523 524
524 down(&data->update_lock); 525 mutex_lock(&data->update_lock);
525 old = via686a_read_value(client, VIA686A_REG_FANDIV); 526 old = via686a_read_value(client, VIA686A_REG_FANDIV);
526 data->fan_div[nr] = DIV_TO_REG(val); 527 data->fan_div[nr] = DIV_TO_REG(val);
527 old = (old & 0x0f) | (data->fan_div[1] << 6) | (data->fan_div[0] << 4); 528 old = (old & 0x0f) | (data->fan_div[1] << 6) | (data->fan_div[0] << 4);
528 via686a_write_value(client, VIA686A_REG_FANDIV, old); 529 via686a_write_value(client, VIA686A_REG_FANDIV, old);
529 up(&data->update_lock); 530 mutex_unlock(&data->update_lock);
530 return count; 531 return count;
531} 532}
532 533
@@ -639,7 +640,7 @@ static int via686a_detect(struct i2c_adapter *adapter)
639 strlcpy(new_client->name, client_name, I2C_NAME_SIZE); 640 strlcpy(new_client->name, client_name, I2C_NAME_SIZE);
640 641
641 data->valid = 0; 642 data->valid = 0;
642 init_MUTEX(&data->update_lock); 643 mutex_init(&data->update_lock);
643 /* Tell the I2C layer a new client has arrived */ 644 /* Tell the I2C layer a new client has arrived */
644 if ((err = i2c_attach_client(new_client))) 645 if ((err = i2c_attach_client(new_client)))
645 goto exit_free; 646 goto exit_free;
@@ -733,7 +734,7 @@ static struct via686a_data *via686a_update_device(struct device *dev)
733 struct via686a_data *data = i2c_get_clientdata(client); 734 struct via686a_data *data = i2c_get_clientdata(client);
734 int i; 735 int i;
735 736
736 down(&data->update_lock); 737 mutex_lock(&data->update_lock);
737 738
738 if (time_after(jiffies, data->last_updated + HZ + HZ / 2) 739 if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
739 || !data->valid) { 740 || !data->valid) {
@@ -788,7 +789,7 @@ static struct via686a_data *via686a_update_device(struct device *dev)
788 data->valid = 1; 789 data->valid = 1;
789 } 790 }
790 791
791 up(&data->update_lock); 792 mutex_unlock(&data->update_lock);
792 793
793 return data; 794 return data;
794} 795}
diff --git a/drivers/hwmon/vt8231.c b/drivers/hwmon/vt8231.c
index 271e9cb953..686f3deb30 100644
--- a/drivers/hwmon/vt8231.c
+++ b/drivers/hwmon/vt8231.c
@@ -35,6 +35,7 @@
35#include <linux/hwmon-sysfs.h> 35#include <linux/hwmon-sysfs.h>
36#include <linux/hwmon-vid.h> 36#include <linux/hwmon-vid.h>
37#include <linux/err.h> 37#include <linux/err.h>
38#include <linux/mutex.h>
38#include <asm/io.h> 39#include <asm/io.h>
39 40
40static int force_addr; 41static int force_addr;
@@ -148,7 +149,7 @@ static inline u8 FAN_TO_REG(long rpm, int div)
148 149
149struct vt8231_data { 150struct vt8231_data {
150 struct i2c_client client; 151 struct i2c_client client;
151 struct semaphore update_lock; 152 struct mutex update_lock;
152 struct class_device *class_dev; 153 struct class_device *class_dev;
153 char valid; /* !=0 if following fields are valid */ 154 char valid; /* !=0 if following fields are valid */
154 unsigned long last_updated; /* In jiffies */ 155 unsigned long last_updated; /* In jiffies */
@@ -223,10 +224,10 @@ static ssize_t set_in_min(struct device *dev, struct device_attribute *attr,
223 struct vt8231_data *data = i2c_get_clientdata(client); 224 struct vt8231_data *data = i2c_get_clientdata(client);
224 unsigned long val = simple_strtoul(buf, NULL, 10); 225 unsigned long val = simple_strtoul(buf, NULL, 10);
225 226
226 down(&data->update_lock); 227 mutex_lock(&data->update_lock);
227 data->in_min[nr] = SENSORS_LIMIT(((val * 958) / 10000) + 3, 0, 255); 228 data->in_min[nr] = SENSORS_LIMIT(((val * 958) / 10000) + 3, 0, 255);
228 vt8231_write_value(client, regvoltmin[nr], data->in_min[nr]); 229 vt8231_write_value(client, regvoltmin[nr], data->in_min[nr]);
229 up(&data->update_lock); 230 mutex_unlock(&data->update_lock);
230 return count; 231 return count;
231} 232}
232 233
@@ -239,10 +240,10 @@ static ssize_t set_in_max(struct device *dev, struct device_attribute *attr,
239 struct vt8231_data *data = i2c_get_clientdata(client); 240 struct vt8231_data *data = i2c_get_clientdata(client);
240 unsigned long val = simple_strtoul(buf, NULL, 10); 241 unsigned long val = simple_strtoul(buf, NULL, 10);
241 242
242 down(&data->update_lock); 243 mutex_lock(&data->update_lock);
243 data->in_max[nr] = SENSORS_LIMIT(((val * 958) / 10000) + 3, 0, 255); 244 data->in_max[nr] = SENSORS_LIMIT(((val * 958) / 10000) + 3, 0, 255);
244 vt8231_write_value(client, regvoltmax[nr], data->in_max[nr]); 245 vt8231_write_value(client, regvoltmax[nr], data->in_max[nr]);
245 up(&data->update_lock); 246 mutex_unlock(&data->update_lock);
246 return count; 247 return count;
247} 248}
248 249
@@ -281,11 +282,11 @@ static ssize_t set_in5_min(struct device *dev, struct device_attribute *attr,
281 struct vt8231_data *data = i2c_get_clientdata(client); 282 struct vt8231_data *data = i2c_get_clientdata(client);
282 unsigned long val = simple_strtoul(buf, NULL, 10); 283 unsigned long val = simple_strtoul(buf, NULL, 10);
283 284
284 down(&data->update_lock); 285 mutex_lock(&data->update_lock);
285 data->in_min[5] = SENSORS_LIMIT(((val * 958 * 34) / (10000 * 54)) + 3, 286 data->in_min[5] = SENSORS_LIMIT(((val * 958 * 34) / (10000 * 54)) + 3,
286 0, 255); 287 0, 255);
287 vt8231_write_value(client, regvoltmin[5], data->in_min[5]); 288 vt8231_write_value(client, regvoltmin[5], data->in_min[5]);
288 up(&data->update_lock); 289 mutex_unlock(&data->update_lock);
289 return count; 290 return count;
290} 291}
291 292
@@ -296,11 +297,11 @@ static ssize_t set_in5_max(struct device *dev, struct device_attribute *attr,
296 struct vt8231_data *data = i2c_get_clientdata(client); 297 struct vt8231_data *data = i2c_get_clientdata(client);
297 unsigned long val = simple_strtoul(buf, NULL, 10); 298 unsigned long val = simple_strtoul(buf, NULL, 10);
298 299
299 down(&data->update_lock); 300 mutex_lock(&data->update_lock);
300 data->in_max[5] = SENSORS_LIMIT(((val * 958 * 34) / (10000 * 54)) + 3, 301 data->in_max[5] = SENSORS_LIMIT(((val * 958 * 34) / (10000 * 54)) + 3,
301 0, 255); 302 0, 255);
302 vt8231_write_value(client, regvoltmax[5], data->in_max[5]); 303 vt8231_write_value(client, regvoltmax[5], data->in_max[5]);
303 up(&data->update_lock); 304 mutex_unlock(&data->update_lock);
304 return count; 305 return count;
305} 306}
306 307
@@ -351,10 +352,10 @@ static ssize_t set_temp0_max(struct device *dev, struct device_attribute *attr,
351 struct vt8231_data *data = i2c_get_clientdata(client); 352 struct vt8231_data *data = i2c_get_clientdata(client);
352 int val = simple_strtol(buf, NULL, 10); 353 int val = simple_strtol(buf, NULL, 10);
353 354
354 down(&data->update_lock); 355 mutex_lock(&data->update_lock);
355 data->temp_max[0] = SENSORS_LIMIT((val + 500) / 1000, 0, 255); 356 data->temp_max[0] = SENSORS_LIMIT((val + 500) / 1000, 0, 255);
356 vt8231_write_value(client, regtempmax[0], data->temp_max[0]); 357 vt8231_write_value(client, regtempmax[0], data->temp_max[0]);
357 up(&data->update_lock); 358 mutex_unlock(&data->update_lock);
358 return count; 359 return count;
359} 360}
360static ssize_t set_temp0_min(struct device *dev, struct device_attribute *attr, 361static ssize_t set_temp0_min(struct device *dev, struct device_attribute *attr,
@@ -364,10 +365,10 @@ static ssize_t set_temp0_min(struct device *dev, struct device_attribute *attr,
364 struct vt8231_data *data = i2c_get_clientdata(client); 365 struct vt8231_data *data = i2c_get_clientdata(client);
365 int val = simple_strtol(buf, NULL, 10); 366 int val = simple_strtol(buf, NULL, 10);
366 367
367 down(&data->update_lock); 368 mutex_lock(&data->update_lock);
368 data->temp_min[0] = SENSORS_LIMIT((val + 500) / 1000, 0, 255); 369 data->temp_min[0] = SENSORS_LIMIT((val + 500) / 1000, 0, 255);
369 vt8231_write_value(client, regtempmin[0], data->temp_min[0]); 370 vt8231_write_value(client, regtempmin[0], data->temp_min[0]);
370 up(&data->update_lock); 371 mutex_unlock(&data->update_lock);
371 return count; 372 return count;
372} 373}
373 374
@@ -407,10 +408,10 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
407 struct vt8231_data *data = i2c_get_clientdata(client); 408 struct vt8231_data *data = i2c_get_clientdata(client);
408 int val = simple_strtol(buf, NULL, 10); 409 int val = simple_strtol(buf, NULL, 10);
409 410
410 down(&data->update_lock); 411 mutex_lock(&data->update_lock);
411 data->temp_max[nr] = SENSORS_LIMIT(TEMP_MAXMIN_TO_REG(val), 0, 255); 412 data->temp_max[nr] = SENSORS_LIMIT(TEMP_MAXMIN_TO_REG(val), 0, 255);
412 vt8231_write_value(client, regtempmax[nr], data->temp_max[nr]); 413 vt8231_write_value(client, regtempmax[nr], data->temp_max[nr]);
413 up(&data->update_lock); 414 mutex_unlock(&data->update_lock);
414 return count; 415 return count;
415} 416}
416static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr, 417static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,
@@ -422,10 +423,10 @@ static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,
422 struct vt8231_data *data = i2c_get_clientdata(client); 423 struct vt8231_data *data = i2c_get_clientdata(client);
423 int val = simple_strtol(buf, NULL, 10); 424 int val = simple_strtol(buf, NULL, 10);
424 425
425 down(&data->update_lock); 426 mutex_lock(&data->update_lock);
426 data->temp_min[nr] = SENSORS_LIMIT(TEMP_MAXMIN_TO_REG(val), 0, 255); 427 data->temp_min[nr] = SENSORS_LIMIT(TEMP_MAXMIN_TO_REG(val), 0, 255);
427 vt8231_write_value(client, regtempmin[nr], data->temp_min[nr]); 428 vt8231_write_value(client, regtempmin[nr], data->temp_min[nr]);
428 up(&data->update_lock); 429 mutex_unlock(&data->update_lock);
429 return count; 430 return count;
430} 431}
431 432
@@ -520,10 +521,10 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
520 struct vt8231_data *data = i2c_get_clientdata(client); 521 struct vt8231_data *data = i2c_get_clientdata(client);
521 int val = simple_strtoul(buf, NULL, 10); 522 int val = simple_strtoul(buf, NULL, 10);
522 523
523 down(&data->update_lock); 524 mutex_lock(&data->update_lock);
524 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); 525 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
525 vt8231_write_value(client, VT8231_REG_FAN_MIN(nr), data->fan_min[nr]); 526 vt8231_write_value(client, VT8231_REG_FAN_MIN(nr), data->fan_min[nr]);
526 up(&data->update_lock); 527 mutex_unlock(&data->update_lock);
527 return count; 528 return count;
528} 529}
529 530
@@ -539,7 +540,7 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
539 long min = FAN_FROM_REG(data->fan_min[nr], 540 long min = FAN_FROM_REG(data->fan_min[nr],
540 DIV_FROM_REG(data->fan_div[nr])); 541 DIV_FROM_REG(data->fan_div[nr]));
541 542
542 down(&data->update_lock); 543 mutex_lock(&data->update_lock);
543 switch (val) { 544 switch (val) {
544 case 1: data->fan_div[nr] = 0; break; 545 case 1: data->fan_div[nr] = 0; break;
545 case 2: data->fan_div[nr] = 1; break; 546 case 2: data->fan_div[nr] = 1; break;
@@ -548,7 +549,7 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
548 default: 549 default:
549 dev_err(&client->dev, "fan_div value %ld not supported." 550 dev_err(&client->dev, "fan_div value %ld not supported."
550 "Choose one of 1, 2, 4 or 8!\n", val); 551 "Choose one of 1, 2, 4 or 8!\n", val);
551 up(&data->update_lock); 552 mutex_unlock(&data->update_lock);
552 return -EINVAL; 553 return -EINVAL;
553 } 554 }
554 555
@@ -558,7 +559,7 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
558 559
559 old = (old & 0x0f) | (data->fan_div[1] << 6) | (data->fan_div[0] << 4); 560 old = (old & 0x0f) | (data->fan_div[1] << 6) | (data->fan_div[0] << 4);
560 vt8231_write_value(client, VT8231_REG_FANDIV, old); 561 vt8231_write_value(client, VT8231_REG_FANDIV, old);
561 up(&data->update_lock); 562 mutex_unlock(&data->update_lock);
562 return count; 563 return count;
563} 564}
564 565
@@ -660,7 +661,7 @@ int vt8231_detect(struct i2c_adapter *adapter)
660 /* Fill in the remaining client fields and put into the global list */ 661 /* Fill in the remaining client fields and put into the global list */
661 strlcpy(client->name, "vt8231", I2C_NAME_SIZE); 662 strlcpy(client->name, "vt8231", I2C_NAME_SIZE);
662 663
663 init_MUTEX(&data->update_lock); 664 mutex_init(&data->update_lock);
664 665
665 /* Tell the I2C layer a new client has arrived */ 666 /* Tell the I2C layer a new client has arrived */
666 if ((err = i2c_attach_client(client))) 667 if ((err = i2c_attach_client(client)))
@@ -745,7 +746,7 @@ static struct vt8231_data *vt8231_update_device(struct device *dev)
745 int i; 746 int i;
746 u16 low; 747 u16 low;
747 748
748 down(&data->update_lock); 749 mutex_lock(&data->update_lock);
749 750
750 if (time_after(jiffies, data->last_updated + HZ + HZ / 2) 751 if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
751 || !data->valid) { 752 || !data->valid) {
@@ -804,7 +805,7 @@ static struct vt8231_data *vt8231_update_device(struct device *dev)
804 data->valid = 1; 805 data->valid = 1;
805 } 806 }
806 807
807 up(&data->update_lock); 808 mutex_unlock(&data->update_lock);
808 809
809 return data; 810 return data;
810} 811}
diff --git a/drivers/hwmon/w83627ehf.c b/drivers/hwmon/w83627ehf.c
index 12d79f5e49..b6bd5685fd 100644
--- a/drivers/hwmon/w83627ehf.c
+++ b/drivers/hwmon/w83627ehf.c
@@ -42,7 +42,9 @@
42#include <linux/i2c.h> 42#include <linux/i2c.h>
43#include <linux/i2c-isa.h> 43#include <linux/i2c-isa.h>
44#include <linux/hwmon.h> 44#include <linux/hwmon.h>
45#include <linux/hwmon-sysfs.h>
45#include <linux/err.h> 46#include <linux/err.h>
47#include <linux/mutex.h>
46#include <asm/io.h> 48#include <asm/io.h>
47#include "lm75.h" 49#include "lm75.h"
48 50
@@ -177,9 +179,9 @@ temp1_to_reg(int temp)
177struct w83627ehf_data { 179struct w83627ehf_data {
178 struct i2c_client client; 180 struct i2c_client client;
179 struct class_device *class_dev; 181 struct class_device *class_dev;
180 struct semaphore lock; 182 struct mutex lock;
181 183
182 struct semaphore update_lock; 184 struct mutex update_lock;
183 char valid; /* !=0 if following fields are valid */ 185 char valid; /* !=0 if following fields are valid */
184 unsigned long last_updated; /* In jiffies */ 186 unsigned long last_updated; /* In jiffies */
185 187
@@ -230,7 +232,7 @@ static u16 w83627ehf_read_value(struct i2c_client *client, u16 reg)
230 struct w83627ehf_data *data = i2c_get_clientdata(client); 232 struct w83627ehf_data *data = i2c_get_clientdata(client);
231 int res, word_sized = is_word_sized(reg); 233 int res, word_sized = is_word_sized(reg);
232 234
233 down(&data->lock); 235 mutex_lock(&data->lock);
234 236
235 w83627ehf_set_bank(client, reg); 237 w83627ehf_set_bank(client, reg);
236 outb_p(reg & 0xff, client->addr + ADDR_REG_OFFSET); 238 outb_p(reg & 0xff, client->addr + ADDR_REG_OFFSET);
@@ -242,7 +244,7 @@ static u16 w83627ehf_read_value(struct i2c_client *client, u16 reg)
242 } 244 }
243 w83627ehf_reset_bank(client, reg); 245 w83627ehf_reset_bank(client, reg);
244 246
245 up(&data->lock); 247 mutex_unlock(&data->lock);
246 248
247 return res; 249 return res;
248} 250}
@@ -252,7 +254,7 @@ static int w83627ehf_write_value(struct i2c_client *client, u16 reg, u16 value)
252 struct w83627ehf_data *data = i2c_get_clientdata(client); 254 struct w83627ehf_data *data = i2c_get_clientdata(client);
253 int word_sized = is_word_sized(reg); 255 int word_sized = is_word_sized(reg);
254 256
255 down(&data->lock); 257 mutex_lock(&data->lock);
256 258
257 w83627ehf_set_bank(client, reg); 259 w83627ehf_set_bank(client, reg);
258 outb_p(reg & 0xff, client->addr + ADDR_REG_OFFSET); 260 outb_p(reg & 0xff, client->addr + ADDR_REG_OFFSET);
@@ -264,7 +266,7 @@ static int w83627ehf_write_value(struct i2c_client *client, u16 reg, u16 value)
264 outb_p(value & 0xff, client->addr + DATA_REG_OFFSET); 266 outb_p(value & 0xff, client->addr + DATA_REG_OFFSET);
265 w83627ehf_reset_bank(client, reg); 267 w83627ehf_reset_bank(client, reg);
266 268
267 up(&data->lock); 269 mutex_unlock(&data->lock);
268 return 0; 270 return 0;
269} 271}
270 272
@@ -322,7 +324,7 @@ static struct w83627ehf_data *w83627ehf_update_device(struct device *dev)
322 struct w83627ehf_data *data = i2c_get_clientdata(client); 324 struct w83627ehf_data *data = i2c_get_clientdata(client);
323 int i; 325 int i;
324 326
325 down(&data->update_lock); 327 mutex_lock(&data->update_lock);
326 328
327 if (time_after(jiffies, data->last_updated + HZ) 329 if (time_after(jiffies, data->last_updated + HZ)
328 || !data->valid) { 330 || !data->valid) {
@@ -397,7 +399,7 @@ static struct w83627ehf_data *w83627ehf_update_device(struct device *dev)
397 data->valid = 1; 399 data->valid = 1;
398 } 400 }
399 401
400 up(&data->update_lock); 402 mutex_unlock(&data->update_lock);
401 return data; 403 return data;
402} 404}
403 405
@@ -407,9 +409,12 @@ static struct w83627ehf_data *w83627ehf_update_device(struct device *dev)
407 409
408#define show_fan_reg(reg) \ 410#define show_fan_reg(reg) \
409static ssize_t \ 411static ssize_t \
410show_##reg(struct device *dev, char *buf, int nr) \ 412show_##reg(struct device *dev, struct device_attribute *attr, \
413 char *buf) \
411{ \ 414{ \
412 struct w83627ehf_data *data = w83627ehf_update_device(dev); \ 415 struct w83627ehf_data *data = w83627ehf_update_device(dev); \
416 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \
417 int nr = sensor_attr->index; \
413 return sprintf(buf, "%d\n", \ 418 return sprintf(buf, "%d\n", \
414 fan_from_reg(data->reg[nr], \ 419 fan_from_reg(data->reg[nr], \
415 div_from_reg(data->fan_div[nr]))); \ 420 div_from_reg(data->fan_div[nr]))); \
@@ -418,23 +423,28 @@ show_fan_reg(fan);
418show_fan_reg(fan_min); 423show_fan_reg(fan_min);
419 424
420static ssize_t 425static ssize_t
421show_fan_div(struct device *dev, char *buf, int nr) 426show_fan_div(struct device *dev, struct device_attribute *attr,
427 char *buf)
422{ 428{
423 struct w83627ehf_data *data = w83627ehf_update_device(dev); 429 struct w83627ehf_data *data = w83627ehf_update_device(dev);
424 return sprintf(buf, "%u\n", 430 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
425 div_from_reg(data->fan_div[nr])); 431 int nr = sensor_attr->index;
432 return sprintf(buf, "%u\n", div_from_reg(data->fan_div[nr]));
426} 433}
427 434
428static ssize_t 435static ssize_t
429store_fan_min(struct device *dev, const char *buf, size_t count, int nr) 436store_fan_min(struct device *dev, struct device_attribute *attr,
437 const char *buf, size_t count)
430{ 438{
431 struct i2c_client *client = to_i2c_client(dev); 439 struct i2c_client *client = to_i2c_client(dev);
432 struct w83627ehf_data *data = i2c_get_clientdata(client); 440 struct w83627ehf_data *data = i2c_get_clientdata(client);
441 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
442 int nr = sensor_attr->index;
433 unsigned int val = simple_strtoul(buf, NULL, 10); 443 unsigned int val = simple_strtoul(buf, NULL, 10);
434 unsigned int reg; 444 unsigned int reg;
435 u8 new_div; 445 u8 new_div;
436 446
437 down(&data->update_lock); 447 mutex_lock(&data->update_lock);
438 if (!val) { 448 if (!val) {
439 /* No min limit, alarm disabled */ 449 /* No min limit, alarm disabled */
440 data->fan_min[nr] = 255; 450 data->fan_min[nr] = 255;
@@ -482,63 +492,46 @@ store_fan_min(struct device *dev, const char *buf, size_t count, int nr)
482 } 492 }
483 w83627ehf_write_value(client, W83627EHF_REG_FAN_MIN[nr], 493 w83627ehf_write_value(client, W83627EHF_REG_FAN_MIN[nr],
484 data->fan_min[nr]); 494 data->fan_min[nr]);
485 up(&data->update_lock); 495 mutex_unlock(&data->update_lock);
486 496
487 return count; 497 return count;
488} 498}
489 499
490#define sysfs_fan_offset(offset) \ 500static struct sensor_device_attribute sda_fan_input[] = {
491static ssize_t \ 501 SENSOR_ATTR(fan1_input, S_IRUGO, show_fan, NULL, 0),
492show_reg_fan_##offset(struct device *dev, struct device_attribute *attr, \ 502 SENSOR_ATTR(fan2_input, S_IRUGO, show_fan, NULL, 1),
493 char *buf) \ 503 SENSOR_ATTR(fan3_input, S_IRUGO, show_fan, NULL, 2),
494{ \ 504 SENSOR_ATTR(fan4_input, S_IRUGO, show_fan, NULL, 3),
495 return show_fan(dev, buf, offset-1); \ 505 SENSOR_ATTR(fan5_input, S_IRUGO, show_fan, NULL, 4),
496} \ 506};
497static DEVICE_ATTR(fan##offset##_input, S_IRUGO, \
498 show_reg_fan_##offset, NULL);
499 507
500#define sysfs_fan_min_offset(offset) \ 508static struct sensor_device_attribute sda_fan_min[] = {
501static ssize_t \ 509 SENSOR_ATTR(fan1_min, S_IWUSR | S_IRUGO, show_fan_min,
502show_reg_fan##offset##_min(struct device *dev, struct device_attribute *attr, \ 510 store_fan_min, 0),
503 char *buf) \ 511 SENSOR_ATTR(fan2_min, S_IWUSR | S_IRUGO, show_fan_min,
504{ \ 512 store_fan_min, 1),
505 return show_fan_min(dev, buf, offset-1); \ 513 SENSOR_ATTR(fan3_min, S_IWUSR | S_IRUGO, show_fan_min,
506} \ 514 store_fan_min, 2),
507static ssize_t \ 515 SENSOR_ATTR(fan4_min, S_IWUSR | S_IRUGO, show_fan_min,
508store_reg_fan##offset##_min(struct device *dev, struct device_attribute *attr, \ 516 store_fan_min, 3),
509 const char *buf, size_t count) \ 517 SENSOR_ATTR(fan5_min, S_IWUSR | S_IRUGO, show_fan_min,
510{ \ 518 store_fan_min, 4),
511 return store_fan_min(dev, buf, count, offset-1); \ 519};
512} \
513static DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
514 show_reg_fan##offset##_min, \
515 store_reg_fan##offset##_min);
516 520
517#define sysfs_fan_div_offset(offset) \ 521static struct sensor_device_attribute sda_fan_div[] = {
518static ssize_t \ 522 SENSOR_ATTR(fan1_div, S_IRUGO, show_fan_div, NULL, 0),
519show_reg_fan##offset##_div(struct device *dev, struct device_attribute *attr, \ 523 SENSOR_ATTR(fan2_div, S_IRUGO, show_fan_div, NULL, 1),
520 char *buf) \ 524 SENSOR_ATTR(fan3_div, S_IRUGO, show_fan_div, NULL, 2),
521{ \ 525 SENSOR_ATTR(fan4_div, S_IRUGO, show_fan_div, NULL, 3),
522 return show_fan_div(dev, buf, offset - 1); \ 526 SENSOR_ATTR(fan5_div, S_IRUGO, show_fan_div, NULL, 4),
523} \ 527};
524static DEVICE_ATTR(fan##offset##_div, S_IRUGO, \ 528
525 show_reg_fan##offset##_div, NULL); 529static void device_create_file_fan(struct device *dev, int i)
526 530{
527sysfs_fan_offset(1); 531 device_create_file(dev, &sda_fan_input[i].dev_attr);
528sysfs_fan_min_offset(1); 532 device_create_file(dev, &sda_fan_div[i].dev_attr);
529sysfs_fan_div_offset(1); 533 device_create_file(dev, &sda_fan_min[i].dev_attr);
530sysfs_fan_offset(2); 534}
531sysfs_fan_min_offset(2);
532sysfs_fan_div_offset(2);
533sysfs_fan_offset(3);
534sysfs_fan_min_offset(3);
535sysfs_fan_div_offset(3);
536sysfs_fan_offset(4);
537sysfs_fan_min_offset(4);
538sysfs_fan_div_offset(4);
539sysfs_fan_offset(5);
540sysfs_fan_min_offset(5);
541sysfs_fan_div_offset(5);
542 535
543#define show_temp1_reg(reg) \ 536#define show_temp1_reg(reg) \
544static ssize_t \ 537static ssize_t \
@@ -561,27 +554,24 @@ store_temp1_##reg(struct device *dev, struct device_attribute *attr, \
561 struct w83627ehf_data *data = i2c_get_clientdata(client); \ 554 struct w83627ehf_data *data = i2c_get_clientdata(client); \
562 u32 val = simple_strtoul(buf, NULL, 10); \ 555 u32 val = simple_strtoul(buf, NULL, 10); \
563 \ 556 \
564 down(&data->update_lock); \ 557 mutex_lock(&data->update_lock); \
565 data->temp1_##reg = temp1_to_reg(val); \ 558 data->temp1_##reg = temp1_to_reg(val); \
566 w83627ehf_write_value(client, W83627EHF_REG_TEMP1_##REG, \ 559 w83627ehf_write_value(client, W83627EHF_REG_TEMP1_##REG, \
567 data->temp1_##reg); \ 560 data->temp1_##reg); \
568 up(&data->update_lock); \ 561 mutex_unlock(&data->update_lock); \
569 return count; \ 562 return count; \
570} 563}
571store_temp1_reg(OVER, max); 564store_temp1_reg(OVER, max);
572store_temp1_reg(HYST, max_hyst); 565store_temp1_reg(HYST, max_hyst);
573 566
574static DEVICE_ATTR(temp1_input, S_IRUGO, show_temp1, NULL);
575static DEVICE_ATTR(temp1_max, S_IRUGO| S_IWUSR,
576 show_temp1_max, store_temp1_max);
577static DEVICE_ATTR(temp1_max_hyst, S_IRUGO| S_IWUSR,
578 show_temp1_max_hyst, store_temp1_max_hyst);
579
580#define show_temp_reg(reg) \ 567#define show_temp_reg(reg) \
581static ssize_t \ 568static ssize_t \
582show_##reg (struct device *dev, char *buf, int nr) \ 569show_##reg(struct device *dev, struct device_attribute *attr, \
570 char *buf) \
583{ \ 571{ \
584 struct w83627ehf_data *data = w83627ehf_update_device(dev); \ 572 struct w83627ehf_data *data = w83627ehf_update_device(dev); \
573 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \
574 int nr = sensor_attr->index; \
585 return sprintf(buf, "%d\n", \ 575 return sprintf(buf, "%d\n", \
586 LM75_TEMP_FROM_REG(data->reg[nr])); \ 576 LM75_TEMP_FROM_REG(data->reg[nr])); \
587} 577}
@@ -591,55 +581,42 @@ show_temp_reg(temp_max_hyst);
591 581
592#define store_temp_reg(REG, reg) \ 582#define store_temp_reg(REG, reg) \
593static ssize_t \ 583static ssize_t \
594store_##reg (struct device *dev, const char *buf, size_t count, int nr) \ 584store_##reg(struct device *dev, struct device_attribute *attr, \
585 const char *buf, size_t count) \
595{ \ 586{ \
596 struct i2c_client *client = to_i2c_client(dev); \ 587 struct i2c_client *client = to_i2c_client(dev); \
597 struct w83627ehf_data *data = i2c_get_clientdata(client); \ 588 struct w83627ehf_data *data = i2c_get_clientdata(client); \
589 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \
590 int nr = sensor_attr->index; \
598 u32 val = simple_strtoul(buf, NULL, 10); \ 591 u32 val = simple_strtoul(buf, NULL, 10); \
599 \ 592 \
600 down(&data->update_lock); \ 593 mutex_lock(&data->update_lock); \
601 data->reg[nr] = LM75_TEMP_TO_REG(val); \ 594 data->reg[nr] = LM75_TEMP_TO_REG(val); \
602 w83627ehf_write_value(client, W83627EHF_REG_TEMP_##REG[nr], \ 595 w83627ehf_write_value(client, W83627EHF_REG_TEMP_##REG[nr], \
603 data->reg[nr]); \ 596 data->reg[nr]); \
604 up(&data->update_lock); \ 597 mutex_unlock(&data->update_lock); \
605 return count; \ 598 return count; \
606} 599}
607store_temp_reg(OVER, temp_max); 600store_temp_reg(OVER, temp_max);
608store_temp_reg(HYST, temp_max_hyst); 601store_temp_reg(HYST, temp_max_hyst);
609 602
610#define sysfs_temp_offset(offset) \ 603static struct sensor_device_attribute sda_temp[] = {
611static ssize_t \ 604 SENSOR_ATTR(temp1_input, S_IRUGO, show_temp1, NULL, 0),
612show_reg_temp##offset (struct device *dev, struct device_attribute *attr, \ 605 SENSOR_ATTR(temp2_input, S_IRUGO, show_temp, NULL, 0),
613 char *buf) \ 606 SENSOR_ATTR(temp3_input, S_IRUGO, show_temp, NULL, 1),
614{ \ 607 SENSOR_ATTR(temp1_max, S_IRUGO | S_IWUSR, show_temp1_max,
615 return show_temp(dev, buf, offset - 2); \ 608 store_temp1_max, 0),
616} \ 609 SENSOR_ATTR(temp2_max, S_IRUGO | S_IWUSR, show_temp_max,
617static DEVICE_ATTR(temp##offset##_input, S_IRUGO, \ 610 store_temp_max, 0),
618 show_reg_temp##offset, NULL); 611 SENSOR_ATTR(temp3_max, S_IRUGO | S_IWUSR, show_temp_max,
619 612 store_temp_max, 1),
620#define sysfs_temp_reg_offset(reg, offset) \ 613 SENSOR_ATTR(temp1_max_hyst, S_IRUGO | S_IWUSR, show_temp1_max_hyst,
621static ssize_t \ 614 store_temp1_max_hyst, 0),
622show_reg_temp##offset##_##reg(struct device *dev, struct device_attribute *attr, \ 615 SENSOR_ATTR(temp2_max_hyst, S_IRUGO | S_IWUSR, show_temp_max_hyst,
623 char *buf) \ 616 store_temp_max_hyst, 0),
624{ \ 617 SENSOR_ATTR(temp3_max_hyst, S_IRUGO | S_IWUSR, show_temp_max_hyst,
625 return show_temp_##reg(dev, buf, offset - 2); \ 618 store_temp_max_hyst, 1),
626} \ 619};
627static ssize_t \
628store_reg_temp##offset##_##reg(struct device *dev, struct device_attribute *attr, \
629 const char *buf, size_t count) \
630{ \
631 return store_temp_##reg(dev, buf, count, offset - 2); \
632} \
633static DEVICE_ATTR(temp##offset##_##reg, S_IRUGO| S_IWUSR, \
634 show_reg_temp##offset##_##reg, \
635 store_reg_temp##offset##_##reg);
636
637sysfs_temp_offset(2);
638sysfs_temp_reg_offset(max, 2);
639sysfs_temp_reg_offset(max_hyst, 2);
640sysfs_temp_offset(3);
641sysfs_temp_reg_offset(max, 3);
642sysfs_temp_reg_offset(max_hyst, 3);
643 620
644/* 621/*
645 * Driver and client management 622 * Driver and client management
@@ -673,6 +650,7 @@ static int w83627ehf_detect(struct i2c_adapter *adapter)
673{ 650{
674 struct i2c_client *client; 651 struct i2c_client *client;
675 struct w83627ehf_data *data; 652 struct w83627ehf_data *data;
653 struct device *dev;
676 int i, err = 0; 654 int i, err = 0;
677 655
678 if (!request_region(address + REGION_OFFSET, REGION_LENGTH, 656 if (!request_region(address + REGION_OFFSET, REGION_LENGTH,
@@ -689,14 +667,15 @@ static int w83627ehf_detect(struct i2c_adapter *adapter)
689 client = &data->client; 667 client = &data->client;
690 i2c_set_clientdata(client, data); 668 i2c_set_clientdata(client, data);
691 client->addr = address; 669 client->addr = address;
692 init_MUTEX(&data->lock); 670 mutex_init(&data->lock);
693 client->adapter = adapter; 671 client->adapter = adapter;
694 client->driver = &w83627ehf_driver; 672 client->driver = &w83627ehf_driver;
695 client->flags = 0; 673 client->flags = 0;
674 dev = &client->dev;
696 675
697 strlcpy(client->name, "w83627ehf", I2C_NAME_SIZE); 676 strlcpy(client->name, "w83627ehf", I2C_NAME_SIZE);
698 data->valid = 0; 677 data->valid = 0;
699 init_MUTEX(&data->update_lock); 678 mutex_init(&data->update_lock);
700 679
701 /* Tell the i2c layer a new client has arrived */ 680 /* Tell the i2c layer a new client has arrived */
702 if ((err = i2c_attach_client(client))) 681 if ((err = i2c_attach_client(client)))
@@ -720,42 +699,18 @@ static int w83627ehf_detect(struct i2c_adapter *adapter)
720 data->has_fan |= (1 << 4); 699 data->has_fan |= (1 << 4);
721 700
722 /* Register sysfs hooks */ 701 /* Register sysfs hooks */
723 data->class_dev = hwmon_device_register(&client->dev); 702 data->class_dev = hwmon_device_register(dev);
724 if (IS_ERR(data->class_dev)) { 703 if (IS_ERR(data->class_dev)) {
725 err = PTR_ERR(data->class_dev); 704 err = PTR_ERR(data->class_dev);
726 goto exit_detach; 705 goto exit_detach;
727 } 706 }
728 707
729 device_create_file(&client->dev, &dev_attr_fan1_input); 708 for (i = 0; i < 5; i++) {
730 device_create_file(&client->dev, &dev_attr_fan1_min); 709 if (data->has_fan & (1 << i))
731 device_create_file(&client->dev, &dev_attr_fan1_div); 710 device_create_file_fan(dev, i);
732 device_create_file(&client->dev, &dev_attr_fan2_input);
733 device_create_file(&client->dev, &dev_attr_fan2_min);
734 device_create_file(&client->dev, &dev_attr_fan2_div);
735 device_create_file(&client->dev, &dev_attr_fan3_input);
736 device_create_file(&client->dev, &dev_attr_fan3_min);
737 device_create_file(&client->dev, &dev_attr_fan3_div);
738
739 if (data->has_fan & (1 << 3)) {
740 device_create_file(&client->dev, &dev_attr_fan4_input);
741 device_create_file(&client->dev, &dev_attr_fan4_min);
742 device_create_file(&client->dev, &dev_attr_fan4_div);
743 }
744 if (data->has_fan & (1 << 4)) {
745 device_create_file(&client->dev, &dev_attr_fan5_input);
746 device_create_file(&client->dev, &dev_attr_fan5_min);
747 device_create_file(&client->dev, &dev_attr_fan5_div);
748 } 711 }
749 712 for (i = 0; i < ARRAY_SIZE(sda_temp); i++)
750 device_create_file(&client->dev, &dev_attr_temp1_input); 713 device_create_file(dev, &sda_temp[i].dev_attr);
751 device_create_file(&client->dev, &dev_attr_temp1_max);
752 device_create_file(&client->dev, &dev_attr_temp1_max_hyst);
753 device_create_file(&client->dev, &dev_attr_temp2_input);
754 device_create_file(&client->dev, &dev_attr_temp2_max);
755 device_create_file(&client->dev, &dev_attr_temp2_max_hyst);
756 device_create_file(&client->dev, &dev_attr_temp3_input);
757 device_create_file(&client->dev, &dev_attr_temp3_max);
758 device_create_file(&client->dev, &dev_attr_temp3_max_hyst);
759 714
760 return 0; 715 return 0;
761 716
diff --git a/drivers/hwmon/w83627hf.c b/drivers/hwmon/w83627hf.c
index 7ea441d4da..71fb7f1af8 100644
--- a/drivers/hwmon/w83627hf.c
+++ b/drivers/hwmon/w83627hf.c
@@ -28,6 +28,7 @@
28 w83627hf 9 3 2 3 0x20 0x5ca3 no yes(LPC) 28 w83627hf 9 3 2 3 0x20 0x5ca3 no yes(LPC)
29 w83627thf 7 3 3 3 0x90 0x5ca3 no yes(LPC) 29 w83627thf 7 3 3 3 0x90 0x5ca3 no yes(LPC)
30 w83637hf 7 3 3 3 0x80 0x5ca3 no yes(LPC) 30 w83637hf 7 3 3 3 0x80 0x5ca3 no yes(LPC)
31 w83687thf 7 3 3 3 0x90 0x5ca3 no yes(LPC)
31 w83697hf 8 2 2 2 0x60 0x5ca3 no yes(LPC) 32 w83697hf 8 2 2 2 0x60 0x5ca3 no yes(LPC)
32 33
33 For other winbond chips, and for i2c support in the above chips, 34 For other winbond chips, and for i2c support in the above chips,
@@ -46,6 +47,7 @@
46#include <linux/hwmon.h> 47#include <linux/hwmon.h>
47#include <linux/hwmon-vid.h> 48#include <linux/hwmon-vid.h>
48#include <linux/err.h> 49#include <linux/err.h>
50#include <linux/mutex.h>
49#include <asm/io.h> 51#include <asm/io.h>
50#include "lm75.h" 52#include "lm75.h"
51 53
@@ -62,7 +64,7 @@ MODULE_PARM_DESC(force_i2c,
62static unsigned short address; 64static unsigned short address;
63 65
64/* Insmod parameters */ 66/* Insmod parameters */
65enum chips { any_chip, w83627hf, w83627thf, w83697hf, w83637hf }; 67enum chips { any_chip, w83627hf, w83627thf, w83697hf, w83637hf, w83687thf };
66 68
67static int reset; 69static int reset;
68module_param(reset, bool, 0); 70module_param(reset, bool, 0);
@@ -100,6 +102,10 @@ static int VAL; /* The value to read/write */
100#define W83627THF_GPIO5_IOSR 0xf3 /* w83627thf only */ 102#define W83627THF_GPIO5_IOSR 0xf3 /* w83627thf only */
101#define W83627THF_GPIO5_DR 0xf4 /* w83627thf only */ 103#define W83627THF_GPIO5_DR 0xf4 /* w83627thf only */
102 104
105#define W83687THF_VID_EN 0x29 /* w83687thf only */
106#define W83687THF_VID_CFG 0xF0 /* w83687thf only */
107#define W83687THF_VID_DATA 0xF1 /* w83687thf only */
108
103static inline void 109static inline void
104superio_outb(int reg, int val) 110superio_outb(int reg, int val)
105{ 111{
@@ -138,6 +144,7 @@ superio_exit(void)
138#define W627THF_DEVID 0x82 144#define W627THF_DEVID 0x82
139#define W697_DEVID 0x60 145#define W697_DEVID 0x60
140#define W637_DEVID 0x70 146#define W637_DEVID 0x70
147#define W687THF_DEVID 0x85
141#define WINB_ACT_REG 0x30 148#define WINB_ACT_REG 0x30
142#define WINB_BASE_REG 0x60 149#define WINB_BASE_REG 0x60
143/* Constants specified below */ 150/* Constants specified below */
@@ -201,11 +208,11 @@ superio_exit(void)
201#define W83627HF_REG_PWM1 0x5A 208#define W83627HF_REG_PWM1 0x5A
202#define W83627HF_REG_PWM2 0x5B 209#define W83627HF_REG_PWM2 0x5B
203 210
204#define W83627THF_REG_PWM1 0x01 /* 697HF and 637HF too */ 211#define W83627THF_REG_PWM1 0x01 /* 697HF/637HF/687THF too */
205#define W83627THF_REG_PWM2 0x03 /* 697HF and 637HF too */ 212#define W83627THF_REG_PWM2 0x03 /* 697HF/637HF/687THF too */
206#define W83627THF_REG_PWM3 0x11 /* 637HF too */ 213#define W83627THF_REG_PWM3 0x11 /* 637HF/687THF too */
207 214
208#define W83627THF_REG_VRM_OVT_CFG 0x18 /* 637HF too */ 215#define W83627THF_REG_VRM_OVT_CFG 0x18 /* 637HF/687THF too */
209 216
210static const u8 regpwm_627hf[] = { W83627HF_REG_PWM1, W83627HF_REG_PWM2 }; 217static const u8 regpwm_627hf[] = { W83627HF_REG_PWM1, W83627HF_REG_PWM2 };
211static const u8 regpwm[] = { W83627THF_REG_PWM1, W83627THF_REG_PWM2, 218static const u8 regpwm[] = { W83627THF_REG_PWM1, W83627THF_REG_PWM2,
@@ -285,10 +292,10 @@ static inline u8 DIV_TO_REG(long val)
285struct w83627hf_data { 292struct w83627hf_data {
286 struct i2c_client client; 293 struct i2c_client client;
287 struct class_device *class_dev; 294 struct class_device *class_dev;
288 struct semaphore lock; 295 struct mutex lock;
289 enum chips type; 296 enum chips type;
290 297
291 struct semaphore update_lock; 298 struct mutex update_lock;
292 char valid; /* !=0 if following fields are valid */ 299 char valid; /* !=0 if following fields are valid */
293 unsigned long last_updated; /* In jiffies */ 300 unsigned long last_updated; /* In jiffies */
294 301
@@ -318,16 +325,15 @@ struct w83627hf_data {
318 Default = 3435. 325 Default = 3435.
319 Other Betas unimplemented */ 326 Other Betas unimplemented */
320 u8 vrm; 327 u8 vrm;
321 u8 vrm_ovt; /* Register value, 627thf & 637hf only */ 328 u8 vrm_ovt; /* Register value, 627THF/637HF/687THF only */
322}; 329};
323 330
324 331
325static int w83627hf_detect(struct i2c_adapter *adapter); 332static int w83627hf_detect(struct i2c_adapter *adapter);
326static int w83627hf_detach_client(struct i2c_client *client); 333static int w83627hf_detach_client(struct i2c_client *client);
327 334
328static int w83627hf_read_value(struct i2c_client *client, u16 register); 335static int w83627hf_read_value(struct i2c_client *client, u16 reg);
329static int w83627hf_write_value(struct i2c_client *client, u16 register, 336static int w83627hf_write_value(struct i2c_client *client, u16 reg, u16 value);
330 u16 value);
331static struct w83627hf_data *w83627hf_update_device(struct device *dev); 337static struct w83627hf_data *w83627hf_update_device(struct device *dev);
332static void w83627hf_init_client(struct i2c_client *client); 338static void w83627hf_init_client(struct i2c_client *client);
333 339
@@ -360,12 +366,12 @@ store_in_##reg (struct device *dev, const char *buf, size_t count, int nr) \
360 \ 366 \
361 val = simple_strtoul(buf, NULL, 10); \ 367 val = simple_strtoul(buf, NULL, 10); \
362 \ 368 \
363 down(&data->update_lock); \ 369 mutex_lock(&data->update_lock); \
364 data->in_##reg[nr] = IN_TO_REG(val); \ 370 data->in_##reg[nr] = IN_TO_REG(val); \
365 w83627hf_write_value(client, W83781D_REG_IN_##REG(nr), \ 371 w83627hf_write_value(client, W83781D_REG_IN_##REG(nr), \
366 data->in_##reg[nr]); \ 372 data->in_##reg[nr]); \
367 \ 373 \
368 up(&data->update_lock); \ 374 mutex_unlock(&data->update_lock); \
369 return count; \ 375 return count; \
370} 376}
371store_in_reg(MIN, min) 377store_in_reg(MIN, min)
@@ -413,7 +419,8 @@ static ssize_t show_in_0(struct w83627hf_data *data, char *buf, u8 reg)
413 long in0; 419 long in0;
414 420
415 if ((data->vrm_ovt & 0x01) && 421 if ((data->vrm_ovt & 0x01) &&
416 (w83627thf == data->type || w83637hf == data->type)) 422 (w83627thf == data->type || w83637hf == data->type
423 || w83687thf == data->type))
417 424
418 /* use VRM9 calculation */ 425 /* use VRM9 calculation */
419 in0 = (long)((reg * 488 + 70000 + 50) / 100); 426 in0 = (long)((reg * 488 + 70000 + 50) / 100);
@@ -451,10 +458,11 @@ static ssize_t store_regs_in_min0(struct device *dev, struct device_attribute *a
451 458
452 val = simple_strtoul(buf, NULL, 10); 459 val = simple_strtoul(buf, NULL, 10);
453 460
454 down(&data->update_lock); 461 mutex_lock(&data->update_lock);
455 462
456 if ((data->vrm_ovt & 0x01) && 463 if ((data->vrm_ovt & 0x01) &&
457 (w83627thf == data->type || w83637hf == data->type)) 464 (w83627thf == data->type || w83637hf == data->type
465 || w83687thf == data->type))
458 466
459 /* use VRM9 calculation */ 467 /* use VRM9 calculation */
460 data->in_min[0] = 468 data->in_min[0] =
@@ -465,7 +473,7 @@ static ssize_t store_regs_in_min0(struct device *dev, struct device_attribute *a
465 data->in_min[0] = IN_TO_REG(val); 473 data->in_min[0] = IN_TO_REG(val);
466 474
467 w83627hf_write_value(client, W83781D_REG_IN_MIN(0), data->in_min[0]); 475 w83627hf_write_value(client, W83781D_REG_IN_MIN(0), data->in_min[0]);
468 up(&data->update_lock); 476 mutex_unlock(&data->update_lock);
469 return count; 477 return count;
470} 478}
471 479
@@ -478,10 +486,11 @@ static ssize_t store_regs_in_max0(struct device *dev, struct device_attribute *a
478 486
479 val = simple_strtoul(buf, NULL, 10); 487 val = simple_strtoul(buf, NULL, 10);
480 488
481 down(&data->update_lock); 489 mutex_lock(&data->update_lock);
482 490
483 if ((data->vrm_ovt & 0x01) && 491 if ((data->vrm_ovt & 0x01) &&
484 (w83627thf == data->type || w83637hf == data->type)) 492 (w83627thf == data->type || w83637hf == data->type
493 || w83687thf == data->type))
485 494
486 /* use VRM9 calculation */ 495 /* use VRM9 calculation */
487 data->in_max[0] = 496 data->in_max[0] =
@@ -492,7 +501,7 @@ static ssize_t store_regs_in_max0(struct device *dev, struct device_attribute *a
492 data->in_max[0] = IN_TO_REG(val); 501 data->in_max[0] = IN_TO_REG(val);
493 502
494 w83627hf_write_value(client, W83781D_REG_IN_MAX(0), data->in_max[0]); 503 w83627hf_write_value(client, W83781D_REG_IN_MAX(0), data->in_max[0]);
495 up(&data->update_lock); 504 mutex_unlock(&data->update_lock);
496 return count; 505 return count;
497} 506}
498 507
@@ -529,13 +538,13 @@ store_fan_min(struct device *dev, const char *buf, size_t count, int nr)
529 538
530 val = simple_strtoul(buf, NULL, 10); 539 val = simple_strtoul(buf, NULL, 10);
531 540
532 down(&data->update_lock); 541 mutex_lock(&data->update_lock);
533 data->fan_min[nr - 1] = 542 data->fan_min[nr - 1] =
534 FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr - 1])); 543 FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr - 1]));
535 w83627hf_write_value(client, W83781D_REG_FAN_MIN(nr), 544 w83627hf_write_value(client, W83781D_REG_FAN_MIN(nr),
536 data->fan_min[nr - 1]); 545 data->fan_min[nr - 1]);
537 546
538 up(&data->update_lock); 547 mutex_unlock(&data->update_lock);
539 return count; 548 return count;
540} 549}
541 550
@@ -597,7 +606,7 @@ store_temp_##reg (struct device *dev, const char *buf, size_t count, int nr) \
597 \ 606 \
598 val = simple_strtoul(buf, NULL, 10); \ 607 val = simple_strtoul(buf, NULL, 10); \
599 \ 608 \
600 down(&data->update_lock); \ 609 mutex_lock(&data->update_lock); \
601 \ 610 \
602 if (nr >= 2) { /* TEMP2 and TEMP3 */ \ 611 if (nr >= 2) { /* TEMP2 and TEMP3 */ \
603 data->temp_##reg##_add[nr-2] = LM75_TEMP_TO_REG(val); \ 612 data->temp_##reg##_add[nr-2] = LM75_TEMP_TO_REG(val); \
@@ -609,7 +618,7 @@ store_temp_##reg (struct device *dev, const char *buf, size_t count, int nr) \
609 data->temp_##reg); \ 618 data->temp_##reg); \
610 } \ 619 } \
611 \ 620 \
612 up(&data->update_lock); \ 621 mutex_unlock(&data->update_lock); \
613 return count; \ 622 return count; \
614} 623}
615store_temp_reg(OVER, max); 624store_temp_reg(OVER, max);
@@ -718,7 +727,7 @@ store_beep_reg(struct device *dev, const char *buf, size_t count,
718 727
719 val = simple_strtoul(buf, NULL, 10); 728 val = simple_strtoul(buf, NULL, 10);
720 729
721 down(&data->update_lock); 730 mutex_lock(&data->update_lock);
722 731
723 if (update_mask == BEEP_MASK) { /* We are storing beep_mask */ 732 if (update_mask == BEEP_MASK) { /* We are storing beep_mask */
724 data->beep_mask = BEEP_MASK_TO_REG(val); 733 data->beep_mask = BEEP_MASK_TO_REG(val);
@@ -736,7 +745,7 @@ store_beep_reg(struct device *dev, const char *buf, size_t count,
736 w83627hf_write_value(client, W83781D_REG_BEEP_INTS2, 745 w83627hf_write_value(client, W83781D_REG_BEEP_INTS2,
737 val2 | data->beep_enable << 7); 746 val2 | data->beep_enable << 7);
738 747
739 up(&data->update_lock); 748 mutex_unlock(&data->update_lock);
740 return count; 749 return count;
741} 750}
742 751
@@ -783,7 +792,7 @@ store_fan_div_reg(struct device *dev, const char *buf, size_t count, int nr)
783 u8 reg; 792 u8 reg;
784 unsigned long val = simple_strtoul(buf, NULL, 10); 793 unsigned long val = simple_strtoul(buf, NULL, 10);
785 794
786 down(&data->update_lock); 795 mutex_lock(&data->update_lock);
787 796
788 /* Save fan_min */ 797 /* Save fan_min */
789 min = FAN_FROM_REG(data->fan_min[nr], 798 min = FAN_FROM_REG(data->fan_min[nr],
@@ -805,7 +814,7 @@ store_fan_div_reg(struct device *dev, const char *buf, size_t count, int nr)
805 data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr])); 814 data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr]));
806 w83627hf_write_value(client, W83781D_REG_FAN_MIN(nr+1), data->fan_min[nr]); 815 w83627hf_write_value(client, W83781D_REG_FAN_MIN(nr+1), data->fan_min[nr]);
807 816
808 up(&data->update_lock); 817 mutex_unlock(&data->update_lock);
809 return count; 818 return count;
810} 819}
811 820
@@ -848,7 +857,7 @@ store_pwm_reg(struct device *dev, const char *buf, size_t count, int nr)
848 857
849 val = simple_strtoul(buf, NULL, 10); 858 val = simple_strtoul(buf, NULL, 10);
850 859
851 down(&data->update_lock); 860 mutex_lock(&data->update_lock);
852 861
853 if (data->type == w83627thf) { 862 if (data->type == w83627thf) {
854 /* bits 0-3 are reserved in 627THF */ 863 /* bits 0-3 are reserved in 627THF */
@@ -865,7 +874,7 @@ store_pwm_reg(struct device *dev, const char *buf, size_t count, int nr)
865 data->pwm[nr - 1]); 874 data->pwm[nr - 1]);
866 } 875 }
867 876
868 up(&data->update_lock); 877 mutex_unlock(&data->update_lock);
869 return count; 878 return count;
870} 879}
871 880
@@ -907,7 +916,7 @@ store_sensor_reg(struct device *dev, const char *buf, size_t count, int nr)
907 916
908 val = simple_strtoul(buf, NULL, 10); 917 val = simple_strtoul(buf, NULL, 10);
909 918
910 down(&data->update_lock); 919 mutex_lock(&data->update_lock);
911 920
912 switch (val) { 921 switch (val) {
913 case 1: /* PII/Celeron diode */ 922 case 1: /* PII/Celeron diode */
@@ -941,7 +950,7 @@ store_sensor_reg(struct device *dev, const char *buf, size_t count, int nr)
941 break; 950 break;
942 } 951 }
943 952
944 up(&data->update_lock); 953 mutex_unlock(&data->update_lock);
945 return count; 954 return count;
946} 955}
947 956
@@ -980,7 +989,8 @@ static int __init w83627hf_find(int sioaddr, unsigned short *addr)
980 if(val != W627_DEVID && 989 if(val != W627_DEVID &&
981 val != W627THF_DEVID && 990 val != W627THF_DEVID &&
982 val != W697_DEVID && 991 val != W697_DEVID &&
983 val != W637_DEVID) { 992 val != W637_DEVID &&
993 val != W687THF_DEVID) {
984 superio_exit(); 994 superio_exit();
985 return -ENODEV; 995 return -ENODEV;
986 } 996 }
@@ -1034,6 +1044,8 @@ static int w83627hf_detect(struct i2c_adapter *adapter)
1034 kind = w83627thf; 1044 kind = w83627thf;
1035 else if(val == W637_DEVID) 1045 else if(val == W637_DEVID)
1036 kind = w83637hf; 1046 kind = w83637hf;
1047 else if (val == W687THF_DEVID)
1048 kind = w83687thf;
1037 else { 1049 else {
1038 dev_info(&adapter->dev, 1050 dev_info(&adapter->dev,
1039 "Unsupported chip (dev_id=0x%02X).\n", val); 1051 "Unsupported chip (dev_id=0x%02X).\n", val);
@@ -1057,7 +1069,7 @@ static int w83627hf_detect(struct i2c_adapter *adapter)
1057 new_client = &data->client; 1069 new_client = &data->client;
1058 i2c_set_clientdata(new_client, data); 1070 i2c_set_clientdata(new_client, data);
1059 new_client->addr = address; 1071 new_client->addr = address;
1060 init_MUTEX(&data->lock); 1072 mutex_init(&data->lock);
1061 new_client->adapter = adapter; 1073 new_client->adapter = adapter;
1062 new_client->driver = &w83627hf_driver; 1074 new_client->driver = &w83627hf_driver;
1063 new_client->flags = 0; 1075 new_client->flags = 0;
@@ -1071,13 +1083,15 @@ static int w83627hf_detect(struct i2c_adapter *adapter)
1071 client_name = "w83697hf"; 1083 client_name = "w83697hf";
1072 } else if (kind == w83637hf) { 1084 } else if (kind == w83637hf) {
1073 client_name = "w83637hf"; 1085 client_name = "w83637hf";
1086 } else if (kind == w83687thf) {
1087 client_name = "w83687thf";
1074 } 1088 }
1075 1089
1076 /* Fill in the remaining client fields and put into the global list */ 1090 /* Fill in the remaining client fields and put into the global list */
1077 strlcpy(new_client->name, client_name, I2C_NAME_SIZE); 1091 strlcpy(new_client->name, client_name, I2C_NAME_SIZE);
1078 data->type = kind; 1092 data->type = kind;
1079 data->valid = 0; 1093 data->valid = 0;
1080 init_MUTEX(&data->update_lock); 1094 mutex_init(&data->update_lock);
1081 1095
1082 /* Tell the I2C layer a new client has arrived */ 1096 /* Tell the I2C layer a new client has arrived */
1083 if ((err = i2c_attach_client(new_client))) 1097 if ((err = i2c_attach_client(new_client)))
@@ -1106,7 +1120,7 @@ static int w83627hf_detect(struct i2c_adapter *adapter)
1106 device_create_file_in(new_client, 2); 1120 device_create_file_in(new_client, 2);
1107 device_create_file_in(new_client, 3); 1121 device_create_file_in(new_client, 3);
1108 device_create_file_in(new_client, 4); 1122 device_create_file_in(new_client, 4);
1109 if (kind != w83627thf && kind != w83637hf) { 1123 if (kind == w83627hf || kind == w83697hf) {
1110 device_create_file_in(new_client, 5); 1124 device_create_file_in(new_client, 5);
1111 device_create_file_in(new_client, 6); 1125 device_create_file_in(new_client, 6);
1112 } 1126 }
@@ -1139,7 +1153,7 @@ static int w83627hf_detect(struct i2c_adapter *adapter)
1139 1153
1140 device_create_file_pwm(new_client, 1); 1154 device_create_file_pwm(new_client, 1);
1141 device_create_file_pwm(new_client, 2); 1155 device_create_file_pwm(new_client, 2);
1142 if (kind == w83627thf || kind == w83637hf) 1156 if (kind == w83627thf || kind == w83637hf || kind == w83687thf)
1143 device_create_file_pwm(new_client, 3); 1157 device_create_file_pwm(new_client, 3);
1144 1158
1145 device_create_file_sensor(new_client, 1); 1159 device_create_file_sensor(new_client, 1);
@@ -1187,7 +1201,7 @@ static int w83627hf_read_value(struct i2c_client *client, u16 reg)
1187 struct w83627hf_data *data = i2c_get_clientdata(client); 1201 struct w83627hf_data *data = i2c_get_clientdata(client);
1188 int res, word_sized; 1202 int res, word_sized;
1189 1203
1190 down(&data->lock); 1204 mutex_lock(&data->lock);
1191 word_sized = (((reg & 0xff00) == 0x100) 1205 word_sized = (((reg & 0xff00) == 0x100)
1192 || ((reg & 0xff00) == 0x200)) 1206 || ((reg & 0xff00) == 0x200))
1193 && (((reg & 0x00ff) == 0x50) 1207 && (((reg & 0x00ff) == 0x50)
@@ -1213,7 +1227,7 @@ static int w83627hf_read_value(struct i2c_client *client, u16 reg)
1213 client->addr + W83781D_ADDR_REG_OFFSET); 1227 client->addr + W83781D_ADDR_REG_OFFSET);
1214 outb_p(0, client->addr + W83781D_DATA_REG_OFFSET); 1228 outb_p(0, client->addr + W83781D_DATA_REG_OFFSET);
1215 } 1229 }
1216 up(&data->lock); 1230 mutex_unlock(&data->lock);
1217 return res; 1231 return res;
1218} 1232}
1219 1233
@@ -1247,12 +1261,39 @@ exit:
1247 return res; 1261 return res;
1248} 1262}
1249 1263
1264static int w83687thf_read_vid(struct i2c_client *client)
1265{
1266 int res = 0xff;
1267
1268 superio_enter();
1269 superio_select(W83627HF_LD_HWM);
1270
1271 /* Make sure these GPIO pins are enabled */
1272 if (!(superio_inb(W83687THF_VID_EN) & (1 << 2))) {
1273 dev_dbg(&client->dev, "VID disabled, no VID function\n");
1274 goto exit;
1275 }
1276
1277 /* Make sure the pins are configured for input */
1278 if (!(superio_inb(W83687THF_VID_CFG) & (1 << 4))) {
1279 dev_dbg(&client->dev, "VID configured as output, "
1280 "no VID function\n");
1281 goto exit;
1282 }
1283
1284 res = superio_inb(W83687THF_VID_DATA) & 0x3f;
1285
1286exit:
1287 superio_exit();
1288 return res;
1289}
1290
1250static int w83627hf_write_value(struct i2c_client *client, u16 reg, u16 value) 1291static int w83627hf_write_value(struct i2c_client *client, u16 reg, u16 value)
1251{ 1292{
1252 struct w83627hf_data *data = i2c_get_clientdata(client); 1293 struct w83627hf_data *data = i2c_get_clientdata(client);
1253 int word_sized; 1294 int word_sized;
1254 1295
1255 down(&data->lock); 1296 mutex_lock(&data->lock);
1256 word_sized = (((reg & 0xff00) == 0x100) 1297 word_sized = (((reg & 0xff00) == 0x100)
1257 || ((reg & 0xff00) == 0x200)) 1298 || ((reg & 0xff00) == 0x200))
1258 && (((reg & 0x00ff) == 0x53) 1299 && (((reg & 0x00ff) == 0x53)
@@ -1277,7 +1318,7 @@ static int w83627hf_write_value(struct i2c_client *client, u16 reg, u16 value)
1277 client->addr + W83781D_ADDR_REG_OFFSET); 1318 client->addr + W83781D_ADDR_REG_OFFSET);
1278 outb_p(0, client->addr + W83781D_DATA_REG_OFFSET); 1319 outb_p(0, client->addr + W83781D_DATA_REG_OFFSET);
1279 } 1320 }
1280 up(&data->lock); 1321 mutex_unlock(&data->lock);
1281 return 0; 1322 return 0;
1282} 1323}
1283 1324
@@ -1324,10 +1365,13 @@ static void w83627hf_init_client(struct i2c_client *client)
1324 data->vid = (lo & 0x0f) | ((hi & 0x01) << 4); 1365 data->vid = (lo & 0x0f) | ((hi & 0x01) << 4);
1325 } else if (w83627thf == data->type) { 1366 } else if (w83627thf == data->type) {
1326 data->vid = w83627thf_read_gpio5(client); 1367 data->vid = w83627thf_read_gpio5(client);
1368 } else if (w83687thf == data->type) {
1369 data->vid = w83687thf_read_vid(client);
1327 } 1370 }
1328 1371
1329 /* Read VRM & OVT Config only once */ 1372 /* Read VRM & OVT Config only once */
1330 if (w83627thf == data->type || w83637hf == data->type) { 1373 if (w83627thf == data->type || w83637hf == data->type
1374 || w83687thf == data->type) {
1331 data->vrm_ovt = 1375 data->vrm_ovt =
1332 w83627hf_read_value(client, W83627THF_REG_VRM_OVT_CFG); 1376 w83627hf_read_value(client, W83627THF_REG_VRM_OVT_CFG);
1333 } 1377 }
@@ -1387,14 +1431,14 @@ static struct w83627hf_data *w83627hf_update_device(struct device *dev)
1387 struct w83627hf_data *data = i2c_get_clientdata(client); 1431 struct w83627hf_data *data = i2c_get_clientdata(client);
1388 int i; 1432 int i;
1389 1433
1390 down(&data->update_lock); 1434 mutex_lock(&data->update_lock);
1391 1435
1392 if (time_after(jiffies, data->last_updated + HZ + HZ / 2) 1436 if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
1393 || !data->valid) { 1437 || !data->valid) {
1394 for (i = 0; i <= 8; i++) { 1438 for (i = 0; i <= 8; i++) {
1395 /* skip missing sensors */ 1439 /* skip missing sensors */
1396 if (((data->type == w83697hf) && (i == 1)) || 1440 if (((data->type == w83697hf) && (i == 1)) ||
1397 ((data->type == w83627thf || data->type == w83637hf) 1441 ((data->type != w83627hf && data->type != w83697hf)
1398 && (i == 5 || i == 6))) 1442 && (i == 5 || i == 6)))
1399 continue; 1443 continue;
1400 data->in[i] = 1444 data->in[i] =
@@ -1470,7 +1514,7 @@ static struct w83627hf_data *w83627hf_update_device(struct device *dev)
1470 data->valid = 1; 1514 data->valid = 1;
1471 } 1515 }
1472 1516
1473 up(&data->update_lock); 1517 mutex_unlock(&data->update_lock);
1474 1518
1475 return data; 1519 return data;
1476} 1520}
diff --git a/drivers/hwmon/w83781d.c b/drivers/hwmon/w83781d.c
index 64c1f8af5b..e4c700356c 100644
--- a/drivers/hwmon/w83781d.c
+++ b/drivers/hwmon/w83781d.c
@@ -42,6 +42,7 @@
42#include <linux/hwmon.h> 42#include <linux/hwmon.h>
43#include <linux/hwmon-vid.h> 43#include <linux/hwmon-vid.h>
44#include <linux/err.h> 44#include <linux/err.h>
45#include <linux/mutex.h>
45#include <asm/io.h> 46#include <asm/io.h>
46#include "lm75.h" 47#include "lm75.h"
47 48
@@ -56,6 +57,10 @@ I2C_CLIENT_INSMOD_5(w83781d, w83782d, w83783s, w83627hf, as99127f);
56I2C_CLIENT_MODULE_PARM(force_subclients, "List of subclient addresses: " 57I2C_CLIENT_MODULE_PARM(force_subclients, "List of subclient addresses: "
57 "{bus, clientaddr, subclientaddr1, subclientaddr2}"); 58 "{bus, clientaddr, subclientaddr1, subclientaddr2}");
58 59
60static int reset;
61module_param(reset, bool, 0);
62MODULE_PARM_DESC(reset, "Set to one to reset chip on load");
63
59static int init = 1; 64static int init = 1;
60module_param(init, bool, 0); 65module_param(init, bool, 0);
61MODULE_PARM_DESC(init, "Set to zero to bypass chip initialization"); 66MODULE_PARM_DESC(init, "Set to zero to bypass chip initialization");
@@ -226,10 +231,10 @@ DIV_TO_REG(long val, enum chips type)
226struct w83781d_data { 231struct w83781d_data {
227 struct i2c_client client; 232 struct i2c_client client;
228 struct class_device *class_dev; 233 struct class_device *class_dev;
229 struct semaphore lock; 234 struct mutex lock;
230 enum chips type; 235 enum chips type;
231 236
232 struct semaphore update_lock; 237 struct mutex update_lock;
233 char valid; /* !=0 if following fields are valid */ 238 char valid; /* !=0 if following fields are valid */
234 unsigned long last_updated; /* In jiffies */ 239 unsigned long last_updated; /* In jiffies */
235 240
@@ -267,9 +272,8 @@ static int w83781d_isa_attach_adapter(struct i2c_adapter *adapter);
267static int w83781d_detect(struct i2c_adapter *adapter, int address, int kind); 272static int w83781d_detect(struct i2c_adapter *adapter, int address, int kind);
268static int w83781d_detach_client(struct i2c_client *client); 273static int w83781d_detach_client(struct i2c_client *client);
269 274
270static int w83781d_read_value(struct i2c_client *client, u16 register); 275static int w83781d_read_value(struct i2c_client *client, u16 reg);
271static int w83781d_write_value(struct i2c_client *client, u16 register, 276static int w83781d_write_value(struct i2c_client *client, u16 reg, u16 value);
272 u16 value);
273static struct w83781d_data *w83781d_update_device(struct device *dev); 277static struct w83781d_data *w83781d_update_device(struct device *dev);
274static void w83781d_init_client(struct i2c_client *client); 278static void w83781d_init_client(struct i2c_client *client);
275 279
@@ -311,11 +315,11 @@ static ssize_t store_in_##reg (struct device *dev, const char *buf, size_t count
311 \ 315 \
312 val = simple_strtoul(buf, NULL, 10) / 10; \ 316 val = simple_strtoul(buf, NULL, 10) / 10; \
313 \ 317 \
314 down(&data->update_lock); \ 318 mutex_lock(&data->update_lock); \
315 data->in_##reg[nr] = IN_TO_REG(val); \ 319 data->in_##reg[nr] = IN_TO_REG(val); \
316 w83781d_write_value(client, W83781D_REG_IN_##REG(nr), data->in_##reg[nr]); \ 320 w83781d_write_value(client, W83781D_REG_IN_##REG(nr), data->in_##reg[nr]); \
317 \ 321 \
318 up(&data->update_lock); \ 322 mutex_unlock(&data->update_lock); \
319 return count; \ 323 return count; \
320} 324}
321store_in_reg(MIN, min); 325store_in_reg(MIN, min);
@@ -381,13 +385,13 @@ store_fan_min(struct device *dev, const char *buf, size_t count, int nr)
381 385
382 val = simple_strtoul(buf, NULL, 10); 386 val = simple_strtoul(buf, NULL, 10);
383 387
384 down(&data->update_lock); 388 mutex_lock(&data->update_lock);
385 data->fan_min[nr - 1] = 389 data->fan_min[nr - 1] =
386 FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr - 1])); 390 FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr - 1]));
387 w83781d_write_value(client, W83781D_REG_FAN_MIN(nr), 391 w83781d_write_value(client, W83781D_REG_FAN_MIN(nr),
388 data->fan_min[nr - 1]); 392 data->fan_min[nr - 1]);
389 393
390 up(&data->update_lock); 394 mutex_unlock(&data->update_lock);
391 return count; 395 return count;
392} 396}
393 397
@@ -446,7 +450,7 @@ static ssize_t store_temp_##reg (struct device *dev, const char *buf, size_t cou
446 \ 450 \
447 val = simple_strtol(buf, NULL, 10); \ 451 val = simple_strtol(buf, NULL, 10); \
448 \ 452 \
449 down(&data->update_lock); \ 453 mutex_lock(&data->update_lock); \
450 \ 454 \
451 if (nr >= 2) { /* TEMP2 and TEMP3 */ \ 455 if (nr >= 2) { /* TEMP2 and TEMP3 */ \
452 data->temp_##reg##_add[nr-2] = LM75_TEMP_TO_REG(val); \ 456 data->temp_##reg##_add[nr-2] = LM75_TEMP_TO_REG(val); \
@@ -458,7 +462,7 @@ static ssize_t store_temp_##reg (struct device *dev, const char *buf, size_t cou
458 data->temp_##reg); \ 462 data->temp_##reg); \
459 } \ 463 } \
460 \ 464 \
461 up(&data->update_lock); \ 465 mutex_unlock(&data->update_lock); \
462 return count; \ 466 return count; \
463} 467}
464store_temp_reg(OVER, max); 468store_temp_reg(OVER, max);
@@ -571,7 +575,7 @@ store_beep_reg(struct device *dev, const char *buf, size_t count,
571 575
572 val = simple_strtoul(buf, NULL, 10); 576 val = simple_strtoul(buf, NULL, 10);
573 577
574 down(&data->update_lock); 578 mutex_lock(&data->update_lock);
575 579
576 if (update_mask == BEEP_MASK) { /* We are storing beep_mask */ 580 if (update_mask == BEEP_MASK) { /* We are storing beep_mask */
577 data->beep_mask = BEEP_MASK_TO_REG(val, data->type); 581 data->beep_mask = BEEP_MASK_TO_REG(val, data->type);
@@ -592,7 +596,7 @@ store_beep_reg(struct device *dev, const char *buf, size_t count,
592 w83781d_write_value(client, W83781D_REG_BEEP_INTS2, 596 w83781d_write_value(client, W83781D_REG_BEEP_INTS2,
593 val2 | data->beep_enable << 7); 597 val2 | data->beep_enable << 7);
594 598
595 up(&data->update_lock); 599 mutex_unlock(&data->update_lock);
596 return count; 600 return count;
597} 601}
598 602
@@ -637,7 +641,7 @@ store_fan_div_reg(struct device *dev, const char *buf, size_t count, int nr)
637 u8 reg; 641 u8 reg;
638 unsigned long val = simple_strtoul(buf, NULL, 10); 642 unsigned long val = simple_strtoul(buf, NULL, 10);
639 643
640 down(&data->update_lock); 644 mutex_lock(&data->update_lock);
641 645
642 /* Save fan_min */ 646 /* Save fan_min */
643 min = FAN_FROM_REG(data->fan_min[nr], 647 min = FAN_FROM_REG(data->fan_min[nr],
@@ -662,7 +666,7 @@ store_fan_div_reg(struct device *dev, const char *buf, size_t count, int nr)
662 data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr])); 666 data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr]));
663 w83781d_write_value(client, W83781D_REG_FAN_MIN(nr+1), data->fan_min[nr]); 667 w83781d_write_value(client, W83781D_REG_FAN_MIN(nr+1), data->fan_min[nr]);
664 668
665 up(&data->update_lock); 669 mutex_unlock(&data->update_lock);
666 return count; 670 return count;
667} 671}
668 672
@@ -709,10 +713,10 @@ store_pwm_reg(struct device *dev, const char *buf, size_t count, int nr)
709 713
710 val = simple_strtoul(buf, NULL, 10); 714 val = simple_strtoul(buf, NULL, 10);
711 715
712 down(&data->update_lock); 716 mutex_lock(&data->update_lock);
713 data->pwm[nr - 1] = PWM_TO_REG(val); 717 data->pwm[nr - 1] = PWM_TO_REG(val);
714 w83781d_write_value(client, W83781D_REG_PWM(nr), data->pwm[nr - 1]); 718 w83781d_write_value(client, W83781D_REG_PWM(nr), data->pwm[nr - 1]);
715 up(&data->update_lock); 719 mutex_unlock(&data->update_lock);
716 return count; 720 return count;
717} 721}
718 722
@@ -725,7 +729,7 @@ store_pwmenable_reg(struct device *dev, const char *buf, size_t count, int nr)
725 729
726 val = simple_strtoul(buf, NULL, 10); 730 val = simple_strtoul(buf, NULL, 10);
727 731
728 down(&data->update_lock); 732 mutex_lock(&data->update_lock);
729 733
730 switch (val) { 734 switch (val) {
731 case 0: 735 case 0:
@@ -742,11 +746,11 @@ store_pwmenable_reg(struct device *dev, const char *buf, size_t count, int nr)
742 break; 746 break;
743 747
744 default: 748 default:
745 up(&data->update_lock); 749 mutex_unlock(&data->update_lock);
746 return -EINVAL; 750 return -EINVAL;
747 } 751 }
748 752
749 up(&data->update_lock); 753 mutex_unlock(&data->update_lock);
750 return count; 754 return count;
751} 755}
752 756
@@ -808,7 +812,7 @@ store_sensor_reg(struct device *dev, const char *buf, size_t count, int nr)
808 812
809 val = simple_strtoul(buf, NULL, 10); 813 val = simple_strtoul(buf, NULL, 10);
810 814
811 down(&data->update_lock); 815 mutex_lock(&data->update_lock);
812 816
813 switch (val) { 817 switch (val) {
814 case 1: /* PII/Celeron diode */ 818 case 1: /* PII/Celeron diode */
@@ -841,7 +845,7 @@ store_sensor_reg(struct device *dev, const char *buf, size_t count, int nr)
841 break; 845 break;
842 } 846 }
843 847
844 up(&data->update_lock); 848 mutex_unlock(&data->update_lock);
845 return count; 849 return count;
846} 850}
847 851
@@ -1073,7 +1077,7 @@ w83781d_detect(struct i2c_adapter *adapter, int address, int kind)
1073 new_client = &data->client; 1077 new_client = &data->client;
1074 i2c_set_clientdata(new_client, data); 1078 i2c_set_clientdata(new_client, data);
1075 new_client->addr = address; 1079 new_client->addr = address;
1076 init_MUTEX(&data->lock); 1080 mutex_init(&data->lock);
1077 new_client->adapter = adapter; 1081 new_client->adapter = adapter;
1078 new_client->driver = is_isa ? &w83781d_isa_driver : &w83781d_driver; 1082 new_client->driver = is_isa ? &w83781d_isa_driver : &w83781d_driver;
1079 new_client->flags = 0; 1083 new_client->flags = 0;
@@ -1178,7 +1182,7 @@ w83781d_detect(struct i2c_adapter *adapter, int address, int kind)
1178 data->type = kind; 1182 data->type = kind;
1179 1183
1180 data->valid = 0; 1184 data->valid = 0;
1181 init_MUTEX(&data->update_lock); 1185 mutex_init(&data->update_lock);
1182 1186
1183 /* Tell the I2C layer a new client has arrived */ 1187 /* Tell the I2C layer a new client has arrived */
1184 if ((err = i2c_attach_client(new_client))) 1188 if ((err = i2c_attach_client(new_client)))
@@ -1325,7 +1329,7 @@ w83781d_read_value(struct i2c_client *client, u16 reg)
1325 int res, word_sized, bank; 1329 int res, word_sized, bank;
1326 struct i2c_client *cl; 1330 struct i2c_client *cl;
1327 1331
1328 down(&data->lock); 1332 mutex_lock(&data->lock);
1329 if (i2c_is_isa_client(client)) { 1333 if (i2c_is_isa_client(client)) {
1330 word_sized = (((reg & 0xff00) == 0x100) 1334 word_sized = (((reg & 0xff00) == 0x100)
1331 || ((reg & 0xff00) == 0x200)) 1335 || ((reg & 0xff00) == 0x200))
@@ -1383,7 +1387,7 @@ w83781d_read_value(struct i2c_client *client, u16 reg)
1383 if (bank > 2) 1387 if (bank > 2)
1384 i2c_smbus_write_byte_data(client, W83781D_REG_BANK, 0); 1388 i2c_smbus_write_byte_data(client, W83781D_REG_BANK, 0);
1385 } 1389 }
1386 up(&data->lock); 1390 mutex_unlock(&data->lock);
1387 return res; 1391 return res;
1388} 1392}
1389 1393
@@ -1394,7 +1398,7 @@ w83781d_write_value(struct i2c_client *client, u16 reg, u16 value)
1394 int word_sized, bank; 1398 int word_sized, bank;
1395 struct i2c_client *cl; 1399 struct i2c_client *cl;
1396 1400
1397 down(&data->lock); 1401 mutex_lock(&data->lock);
1398 if (i2c_is_isa_client(client)) { 1402 if (i2c_is_isa_client(client)) {
1399 word_sized = (((reg & 0xff00) == 0x100) 1403 word_sized = (((reg & 0xff00) == 0x100)
1400 || ((reg & 0xff00) == 0x200)) 1404 || ((reg & 0xff00) == 0x200))
@@ -1447,7 +1451,7 @@ w83781d_write_value(struct i2c_client *client, u16 reg, u16 value)
1447 if (bank > 2) 1451 if (bank > 2)
1448 i2c_smbus_write_byte_data(client, W83781D_REG_BANK, 0); 1452 i2c_smbus_write_byte_data(client, W83781D_REG_BANK, 0);
1449 } 1453 }
1450 up(&data->lock); 1454 mutex_unlock(&data->lock);
1451 return 0; 1455 return 0;
1452} 1456}
1453 1457
@@ -1459,8 +1463,17 @@ w83781d_init_client(struct i2c_client *client)
1459 int type = data->type; 1463 int type = data->type;
1460 u8 tmp; 1464 u8 tmp;
1461 1465
1462 if (init && type != as99127f) { /* this resets registers we don't have 1466 if (reset && type != as99127f) { /* this resets registers we don't have
1463 documentation for on the as99127f */ 1467 documentation for on the as99127f */
1468 /* Resetting the chip has been the default for a long time,
1469 but it causes the BIOS initializations (fan clock dividers,
1470 thermal sensor types...) to be lost, so it is now optional.
1471 It might even go away if nobody reports it as being useful,
1472 as I see very little reason why this would be needed at
1473 all. */
1474 dev_info(&client->dev, "If reset=1 solved a problem you were "
1475 "having, please report!\n");
1476
1464 /* save these registers */ 1477 /* save these registers */
1465 i = w83781d_read_value(client, W83781D_REG_BEEP_CONFIG); 1478 i = w83781d_read_value(client, W83781D_REG_BEEP_CONFIG);
1466 p = w83781d_read_value(client, W83781D_REG_PWMCLK12); 1479 p = w83781d_read_value(client, W83781D_REG_PWMCLK12);
@@ -1477,6 +1490,13 @@ w83781d_init_client(struct i2c_client *client)
1477 w83781d_write_value(client, W83781D_REG_BEEP_INTS2, 0); 1490 w83781d_write_value(client, W83781D_REG_BEEP_INTS2, 0);
1478 } 1491 }
1479 1492
1493 /* Disable power-on abnormal beep, as advised by the datasheet.
1494 Already done if reset=1. */
1495 if (init && !reset && type != as99127f) {
1496 i = w83781d_read_value(client, W83781D_REG_BEEP_CONFIG);
1497 w83781d_write_value(client, W83781D_REG_BEEP_CONFIG, i | 0x80);
1498 }
1499
1480 data->vrm = vid_which_vrm(); 1500 data->vrm = vid_which_vrm();
1481 1501
1482 if ((type != w83781d) && (type != as99127f)) { 1502 if ((type != w83781d) && (type != as99127f)) {
@@ -1533,7 +1553,7 @@ static struct w83781d_data *w83781d_update_device(struct device *dev)
1533 struct w83781d_data *data = i2c_get_clientdata(client); 1553 struct w83781d_data *data = i2c_get_clientdata(client);
1534 int i; 1554 int i;
1535 1555
1536 down(&data->update_lock); 1556 mutex_lock(&data->update_lock);
1537 1557
1538 if (time_after(jiffies, data->last_updated + HZ + HZ / 2) 1558 if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
1539 || !data->valid) { 1559 || !data->valid) {
@@ -1641,7 +1661,7 @@ static struct w83781d_data *w83781d_update_device(struct device *dev)
1641 data->valid = 1; 1661 data->valid = 1;
1642 } 1662 }
1643 1663
1644 up(&data->update_lock); 1664 mutex_unlock(&data->update_lock);
1645 1665
1646 return data; 1666 return data;
1647} 1667}
diff --git a/drivers/hwmon/w83792d.c b/drivers/hwmon/w83792d.c
index a2f6bb6762..6865c64d8a 100644
--- a/drivers/hwmon/w83792d.c
+++ b/drivers/hwmon/w83792d.c
@@ -43,6 +43,7 @@
43#include <linux/hwmon.h> 43#include <linux/hwmon.h>
44#include <linux/hwmon-sysfs.h> 44#include <linux/hwmon-sysfs.h>
45#include <linux/err.h> 45#include <linux/err.h>
46#include <linux/mutex.h>
46 47
47/* Addresses to scan */ 48/* Addresses to scan */
48static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, 0x2f, I2C_CLIENT_END }; 49static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, 0x2f, I2C_CLIENT_END };
@@ -271,7 +272,7 @@ struct w83792d_data {
271 struct class_device *class_dev; 272 struct class_device *class_dev;
272 enum chips type; 273 enum chips type;
273 274
274 struct semaphore update_lock; 275 struct mutex update_lock;
275 char valid; /* !=0 if following fields are valid */ 276 char valid; /* !=0 if following fields are valid */
276 unsigned long last_updated; /* In jiffies */ 277 unsigned long last_updated; /* In jiffies */
277 278
@@ -382,30 +383,40 @@ static ssize_t store_in_##reg (struct device *dev, \
382store_in_reg(MIN, min); 383store_in_reg(MIN, min);
383store_in_reg(MAX, max); 384store_in_reg(MAX, max);
384 385
385#define sysfs_in_reg(offset) \ 386static struct sensor_device_attribute sda_in_input[] = {
386static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, show_in, \ 387 SENSOR_ATTR(in0_input, S_IRUGO, show_in, NULL, 0),
387 NULL, offset); \ 388 SENSOR_ATTR(in1_input, S_IRUGO, show_in, NULL, 1),
388static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \ 389 SENSOR_ATTR(in2_input, S_IRUGO, show_in, NULL, 2),
389 show_in_min, store_in_min, offset); \ 390 SENSOR_ATTR(in3_input, S_IRUGO, show_in, NULL, 3),
390static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \ 391 SENSOR_ATTR(in4_input, S_IRUGO, show_in, NULL, 4),
391 show_in_max, store_in_max, offset); 392 SENSOR_ATTR(in5_input, S_IRUGO, show_in, NULL, 5),
392 393 SENSOR_ATTR(in6_input, S_IRUGO, show_in, NULL, 6),
393sysfs_in_reg(0); 394 SENSOR_ATTR(in7_input, S_IRUGO, show_in, NULL, 7),
394sysfs_in_reg(1); 395 SENSOR_ATTR(in8_input, S_IRUGO, show_in, NULL, 8),
395sysfs_in_reg(2); 396};
396sysfs_in_reg(3); 397static struct sensor_device_attribute sda_in_min[] = {
397sysfs_in_reg(4); 398 SENSOR_ATTR(in0_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 0),
398sysfs_in_reg(5); 399 SENSOR_ATTR(in1_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 1),
399sysfs_in_reg(6); 400 SENSOR_ATTR(in2_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 2),
400sysfs_in_reg(7); 401 SENSOR_ATTR(in3_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 3),
401sysfs_in_reg(8); 402 SENSOR_ATTR(in4_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 4),
402 403 SENSOR_ATTR(in5_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 5),
403#define device_create_file_in(client, offset) \ 404 SENSOR_ATTR(in6_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 6),
404do { \ 405 SENSOR_ATTR(in7_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 7),
405device_create_file(&client->dev, &sensor_dev_attr_in##offset##_input.dev_attr); \ 406 SENSOR_ATTR(in8_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 8),
406device_create_file(&client->dev, &sensor_dev_attr_in##offset##_max.dev_attr); \ 407};
407device_create_file(&client->dev, &sensor_dev_attr_in##offset##_min.dev_attr); \ 408static struct sensor_device_attribute sda_in_max[] = {
408} while (0) 409 SENSOR_ATTR(in0_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 0),
410 SENSOR_ATTR(in1_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 1),
411 SENSOR_ATTR(in2_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 2),
412 SENSOR_ATTR(in3_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 3),
413 SENSOR_ATTR(in4_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 4),
414 SENSOR_ATTR(in5_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 5),
415 SENSOR_ATTR(in6_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 6),
416 SENSOR_ATTR(in7_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 7),
417 SENSOR_ATTR(in8_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 8),
418};
419
409 420
410#define show_fan_reg(reg) \ 421#define show_fan_reg(reg) \
411static ssize_t show_##reg (struct device *dev, struct device_attribute *attr, \ 422static ssize_t show_##reg (struct device *dev, struct device_attribute *attr, \
@@ -486,28 +497,33 @@ store_fan_div(struct device *dev, struct device_attribute *attr,
486 return count; 497 return count;
487} 498}
488 499
489#define sysfs_fan(offset) \ 500static struct sensor_device_attribute sda_fan_input[] = {
490static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, show_fan, NULL, \ 501 SENSOR_ATTR(fan1_input, S_IRUGO, show_fan, NULL, 1),
491 offset); \ 502 SENSOR_ATTR(fan2_input, S_IRUGO, show_fan, NULL, 2),
492static SENSOR_DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \ 503 SENSOR_ATTR(fan3_input, S_IRUGO, show_fan, NULL, 3),
493 show_fan_div, store_fan_div, offset); \ 504 SENSOR_ATTR(fan4_input, S_IRUGO, show_fan, NULL, 4),
494static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \ 505 SENSOR_ATTR(fan5_input, S_IRUGO, show_fan, NULL, 5),
495 show_fan_min, store_fan_min, offset); 506 SENSOR_ATTR(fan6_input, S_IRUGO, show_fan, NULL, 6),
496 507 SENSOR_ATTR(fan7_input, S_IRUGO, show_fan, NULL, 7),
497sysfs_fan(1); 508};
498sysfs_fan(2); 509static struct sensor_device_attribute sda_fan_min[] = {
499sysfs_fan(3); 510 SENSOR_ATTR(fan1_min, S_IWUSR | S_IRUGO, show_fan_min, store_fan_min, 1),
500sysfs_fan(4); 511 SENSOR_ATTR(fan2_min, S_IWUSR | S_IRUGO, show_fan_min, store_fan_min, 2),
501sysfs_fan(5); 512 SENSOR_ATTR(fan3_min, S_IWUSR | S_IRUGO, show_fan_min, store_fan_min, 3),
502sysfs_fan(6); 513 SENSOR_ATTR(fan4_min, S_IWUSR | S_IRUGO, show_fan_min, store_fan_min, 4),
503sysfs_fan(7); 514 SENSOR_ATTR(fan5_min, S_IWUSR | S_IRUGO, show_fan_min, store_fan_min, 5),
504 515 SENSOR_ATTR(fan6_min, S_IWUSR | S_IRUGO, show_fan_min, store_fan_min, 6),
505#define device_create_file_fan(client, offset) \ 516 SENSOR_ATTR(fan7_min, S_IWUSR | S_IRUGO, show_fan_min, store_fan_min, 7),
506do { \ 517};
507device_create_file(&client->dev, &sensor_dev_attr_fan##offset##_input.dev_attr); \ 518static struct sensor_device_attribute sda_fan_div[] = {
508device_create_file(&client->dev, &sensor_dev_attr_fan##offset##_div.dev_attr); \ 519 SENSOR_ATTR(fan1_div, S_IWUSR | S_IRUGO, show_fan_div, store_fan_div, 1),
509device_create_file(&client->dev, &sensor_dev_attr_fan##offset##_min.dev_attr); \ 520 SENSOR_ATTR(fan2_div, S_IWUSR | S_IRUGO, show_fan_div, store_fan_div, 2),
510} while (0) 521 SENSOR_ATTR(fan3_div, S_IWUSR | S_IRUGO, show_fan_div, store_fan_div, 3),
522 SENSOR_ATTR(fan4_div, S_IWUSR | S_IRUGO, show_fan_div, store_fan_div, 4),
523 SENSOR_ATTR(fan5_div, S_IWUSR | S_IRUGO, show_fan_div, store_fan_div, 5),
524 SENSOR_ATTR(fan6_div, S_IWUSR | S_IRUGO, show_fan_div, store_fan_div, 6),
525 SENSOR_ATTR(fan7_div, S_IWUSR | S_IRUGO, show_fan_div, store_fan_div, 7),
526};
511 527
512 528
513/* read/write the temperature1, includes measured value and limits */ 529/* read/write the temperature1, includes measured value and limits */
@@ -539,21 +555,6 @@ static ssize_t store_temp1(struct device *dev, struct device_attribute *attr,
539 return count; 555 return count;
540} 556}
541 557
542
543static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp1, NULL, 0);
544static SENSOR_DEVICE_ATTR(temp1_max, S_IRUGO | S_IWUSR, show_temp1,
545 store_temp1, 1);
546static SENSOR_DEVICE_ATTR(temp1_max_hyst, S_IRUGO | S_IWUSR, show_temp1,
547 store_temp1, 2);
548
549#define device_create_file_temp1(client) \
550do { \
551device_create_file(&client->dev, &sensor_dev_attr_temp1_input.dev_attr); \
552device_create_file(&client->dev, &sensor_dev_attr_temp1_max.dev_attr); \
553device_create_file(&client->dev, &sensor_dev_attr_temp1_max_hyst.dev_attr); \
554} while (0)
555
556
557/* read/write the temperature2-3, includes measured value and limits */ 558/* read/write the temperature2-3, includes measured value and limits */
558 559
559static ssize_t show_temp23(struct device *dev, struct device_attribute *attr, 560static ssize_t show_temp23(struct device *dev, struct device_attribute *attr,
@@ -590,25 +591,23 @@ static ssize_t store_temp23(struct device *dev, struct device_attribute *attr,
590 return count; 591 return count;
591} 592}
592 593
593#define sysfs_temp23(name,idx) \ 594static struct sensor_device_attribute_2 sda_temp_input[] = {
594static SENSOR_DEVICE_ATTR_2(name##_input, S_IRUGO, show_temp23, NULL, \ 595 SENSOR_ATTR_2(temp1_input, S_IRUGO, show_temp1, NULL, 0, 0),
595 idx, 0); \ 596 SENSOR_ATTR_2(temp2_input, S_IRUGO, show_temp23, NULL, 0, 0),
596static SENSOR_DEVICE_ATTR_2(name##_max, S_IRUGO | S_IWUSR, \ 597 SENSOR_ATTR_2(temp3_input, S_IRUGO, show_temp23, NULL, 1, 0),
597 show_temp23, store_temp23, idx, 2); \ 598};
598static SENSOR_DEVICE_ATTR_2(name##_max_hyst, S_IRUGO | S_IWUSR, \
599 show_temp23, store_temp23, idx, 4);
600
601sysfs_temp23(temp2,0)
602sysfs_temp23(temp3,1)
603 599
604#define device_create_file_temp_add(client, offset) \ 600static struct sensor_device_attribute_2 sda_temp_max[] = {
605do { \ 601 SENSOR_ATTR_2(temp1_max, S_IRUGO | S_IWUSR, show_temp1, store_temp1, 0, 1),
606device_create_file(&client->dev, &sensor_dev_attr_temp##offset##_input.dev_attr); \ 602 SENSOR_ATTR_2(temp2_max, S_IRUGO | S_IWUSR, show_temp23, store_temp23, 0, 2),
607device_create_file(&client->dev, &sensor_dev_attr_temp##offset##_max.dev_attr); \ 603 SENSOR_ATTR_2(temp3_max, S_IRUGO | S_IWUSR, show_temp23, store_temp23, 1, 2),
608device_create_file(&client->dev, \ 604};
609&sensor_dev_attr_temp##offset##_max_hyst.dev_attr); \
610} while (0)
611 605
606static struct sensor_device_attribute_2 sda_temp_max_hyst[] = {
607 SENSOR_ATTR_2(temp1_max_hyst, S_IRUGO | S_IWUSR, show_temp1, store_temp1, 0, 2),
608 SENSOR_ATTR_2(temp2_max_hyst, S_IRUGO | S_IWUSR, show_temp23, store_temp23, 0, 4),
609 SENSOR_ATTR_2(temp3_max_hyst, S_IRUGO | S_IWUSR, show_temp23, store_temp23, 1, 4),
610};
612 611
613/* get reatime status of all sensors items: voltage, temp, fan */ 612/* get reatime status of all sensors items: voltage, temp, fan */
614static ssize_t 613static ssize_t
@@ -620,10 +619,6 @@ show_alarms_reg(struct device *dev, struct device_attribute *attr, char *buf)
620 619
621static 620static
622DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL); 621DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL);
623#define device_create_file_alarms(client) \
624device_create_file(&client->dev, &dev_attr_alarms);
625
626
627 622
628static ssize_t 623static ssize_t
629show_pwm(struct device *dev, struct device_attribute *attr, 624show_pwm(struct device *dev, struct device_attribute *attr,
@@ -711,26 +706,19 @@ store_pwmenable(struct device *dev, struct device_attribute *attr,
711 return count; 706 return count;
712} 707}
713 708
714#define sysfs_pwm(offset) \ 709static struct sensor_device_attribute sda_pwm[] = {
715static SENSOR_DEVICE_ATTR(pwm##offset, S_IRUGO | S_IWUSR, \ 710 SENSOR_ATTR(pwm1, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 1),
716 show_pwm, store_pwm, offset); \ 711 SENSOR_ATTR(pwm2, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 2),
717static SENSOR_DEVICE_ATTR(pwm##offset##_enable, S_IRUGO | S_IWUSR, \ 712 SENSOR_ATTR(pwm3, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 3),
718 show_pwmenable, store_pwmenable, offset); \ 713};
719 714static struct sensor_device_attribute sda_pwm_enable[] = {
720sysfs_pwm(1); 715 SENSOR_ATTR(pwm1_enable, S_IWUSR | S_IRUGO,
721sysfs_pwm(2); 716 show_pwmenable, store_pwmenable, 1),
722sysfs_pwm(3); 717 SENSOR_ATTR(pwm2_enable, S_IWUSR | S_IRUGO,
723 718 show_pwmenable, store_pwmenable, 2),
724 719 SENSOR_ATTR(pwm3_enable, S_IWUSR | S_IRUGO,
725#define device_create_file_pwm(client, offset) \ 720 show_pwmenable, store_pwmenable, 3),
726do { \ 721};
727device_create_file(&client->dev, &sensor_dev_attr_pwm##offset.dev_attr); \
728} while (0)
729
730#define device_create_file_pwmenable(client, offset) \
731do { \
732device_create_file(&client->dev, &sensor_dev_attr_pwm##offset##_enable.dev_attr); \
733} while (0)
734 722
735 723
736static ssize_t 724static ssize_t
@@ -764,18 +752,14 @@ store_pwm_mode(struct device *dev, struct device_attribute *attr,
764 return count; 752 return count;
765} 753}
766 754
767#define sysfs_pwm_mode(offset) \ 755static struct sensor_device_attribute sda_pwm_mode[] = {
768static SENSOR_DEVICE_ATTR(pwm##offset##_mode, S_IRUGO | S_IWUSR, \ 756 SENSOR_ATTR(pwm1_mode, S_IWUSR | S_IRUGO,
769 show_pwm_mode, store_pwm_mode, offset); 757 show_pwm_mode, store_pwm_mode, 1),
770 758 SENSOR_ATTR(pwm2_mode, S_IWUSR | S_IRUGO,
771sysfs_pwm_mode(1); 759 show_pwm_mode, store_pwm_mode, 2),
772sysfs_pwm_mode(2); 760 SENSOR_ATTR(pwm3_mode, S_IWUSR | S_IRUGO,
773sysfs_pwm_mode(3); 761 show_pwm_mode, store_pwm_mode, 3),
774 762};
775#define device_create_file_pwm_mode(client, offset) \
776do { \
777device_create_file(&client->dev, &sensor_dev_attr_pwm##offset##_mode.dev_attr); \
778} while (0)
779 763
780 764
781static ssize_t 765static ssize_t
@@ -788,12 +772,6 @@ show_regs_chassis(struct device *dev, struct device_attribute *attr,
788 772
789static DEVICE_ATTR(chassis, S_IRUGO, show_regs_chassis, NULL); 773static DEVICE_ATTR(chassis, S_IRUGO, show_regs_chassis, NULL);
790 774
791#define device_create_file_chassis(client) \
792do { \
793device_create_file(&client->dev, &dev_attr_chassis); \
794} while (0)
795
796
797static ssize_t 775static ssize_t
798show_chassis_clear(struct device *dev, struct device_attribute *attr, char *buf) 776show_chassis_clear(struct device *dev, struct device_attribute *attr, char *buf)
799{ 777{
@@ -824,13 +802,6 @@ store_chassis_clear(struct device *dev, struct device_attribute *attr,
824static DEVICE_ATTR(chassis_clear, S_IRUGO | S_IWUSR, 802static DEVICE_ATTR(chassis_clear, S_IRUGO | S_IWUSR,
825 show_chassis_clear, store_chassis_clear); 803 show_chassis_clear, store_chassis_clear);
826 804
827#define device_create_file_chassis_clear(client) \
828do { \
829device_create_file(&client->dev, &dev_attr_chassis_clear); \
830} while (0)
831
832
833
834/* For Smart Fan I / Thermal Cruise */ 805/* For Smart Fan I / Thermal Cruise */
835static ssize_t 806static ssize_t
836show_thermal_cruise(struct device *dev, struct device_attribute *attr, 807show_thermal_cruise(struct device *dev, struct device_attribute *attr,
@@ -864,20 +835,14 @@ store_thermal_cruise(struct device *dev, struct device_attribute *attr,
864 return count; 835 return count;
865} 836}
866 837
867#define sysfs_thermal_cruise(offset) \ 838static struct sensor_device_attribute sda_thermal_cruise[] = {
868static SENSOR_DEVICE_ATTR(thermal_cruise##offset, S_IRUGO | S_IWUSR, \ 839 SENSOR_ATTR(thermal_cruise1, S_IWUSR | S_IRUGO,
869 show_thermal_cruise, store_thermal_cruise, offset); 840 show_thermal_cruise, store_thermal_cruise, 1),
870 841 SENSOR_ATTR(thermal_cruise2, S_IWUSR | S_IRUGO,
871sysfs_thermal_cruise(1); 842 show_thermal_cruise, store_thermal_cruise, 2),
872sysfs_thermal_cruise(2); 843 SENSOR_ATTR(thermal_cruise3, S_IWUSR | S_IRUGO,
873sysfs_thermal_cruise(3); 844 show_thermal_cruise, store_thermal_cruise, 3),
874 845};
875#define device_create_file_thermal_cruise(client, offset) \
876do { \
877device_create_file(&client->dev, \
878&sensor_dev_attr_thermal_cruise##offset.dev_attr); \
879} while (0)
880
881 846
882/* For Smart Fan I/Thermal Cruise and Smart Fan II */ 847/* For Smart Fan I/Thermal Cruise and Smart Fan II */
883static ssize_t 848static ssize_t
@@ -916,19 +881,14 @@ store_tolerance(struct device *dev, struct device_attribute *attr,
916 return count; 881 return count;
917} 882}
918 883
919#define sysfs_tolerance(offset) \ 884static struct sensor_device_attribute sda_tolerance[] = {
920static SENSOR_DEVICE_ATTR(tolerance##offset, S_IRUGO | S_IWUSR, \ 885 SENSOR_ATTR(tolerance1, S_IWUSR | S_IRUGO,
921 show_tolerance, store_tolerance, offset); 886 show_tolerance, store_tolerance, 1),
922 887 SENSOR_ATTR(tolerance2, S_IWUSR | S_IRUGO,
923sysfs_tolerance(1); 888 show_tolerance, store_tolerance, 2),
924sysfs_tolerance(2); 889 SENSOR_ATTR(tolerance3, S_IWUSR | S_IRUGO,
925sysfs_tolerance(3); 890 show_tolerance, store_tolerance, 3),
926 891};
927#define device_create_file_tolerance(client, offset) \
928do { \
929device_create_file(&client->dev, &sensor_dev_attr_tolerance##offset.dev_attr); \
930} while (0)
931
932 892
933/* For Smart Fan II */ 893/* For Smart Fan II */
934static ssize_t 894static ssize_t
@@ -964,28 +924,34 @@ store_sf2_point(struct device *dev, struct device_attribute *attr,
964 return count; 924 return count;
965} 925}
966 926
967#define sysfs_sf2_point(offset, index) \ 927static struct sensor_device_attribute_2 sda_sf2_point[] = {
968static SENSOR_DEVICE_ATTR_2(sf2_point##offset##_fan##index, S_IRUGO | S_IWUSR, \ 928 SENSOR_ATTR_2(sf2_point1_fan1, S_IRUGO | S_IWUSR,
969 show_sf2_point, store_sf2_point, offset, index); 929 show_sf2_point, store_sf2_point, 1, 1),
970 930 SENSOR_ATTR_2(sf2_point2_fan1, S_IRUGO | S_IWUSR,
971sysfs_sf2_point(1, 1); /* Fan1 */ 931 show_sf2_point, store_sf2_point, 2, 1),
972sysfs_sf2_point(2, 1); /* Fan1 */ 932 SENSOR_ATTR_2(sf2_point3_fan1, S_IRUGO | S_IWUSR,
973sysfs_sf2_point(3, 1); /* Fan1 */ 933 show_sf2_point, store_sf2_point, 3, 1),
974sysfs_sf2_point(4, 1); /* Fan1 */ 934 SENSOR_ATTR_2(sf2_point4_fan1, S_IRUGO | S_IWUSR,
975sysfs_sf2_point(1, 2); /* Fan2 */ 935 show_sf2_point, store_sf2_point, 4, 1),
976sysfs_sf2_point(2, 2); /* Fan2 */ 936
977sysfs_sf2_point(3, 2); /* Fan2 */ 937 SENSOR_ATTR_2(sf2_point1_fan2, S_IRUGO | S_IWUSR,
978sysfs_sf2_point(4, 2); /* Fan2 */ 938 show_sf2_point, store_sf2_point, 1, 2),
979sysfs_sf2_point(1, 3); /* Fan3 */ 939 SENSOR_ATTR_2(sf2_point2_fan2, S_IRUGO | S_IWUSR,
980sysfs_sf2_point(2, 3); /* Fan3 */ 940 show_sf2_point, store_sf2_point, 2, 2),
981sysfs_sf2_point(3, 3); /* Fan3 */ 941 SENSOR_ATTR_2(sf2_point3_fan2, S_IRUGO | S_IWUSR,
982sysfs_sf2_point(4, 3); /* Fan3 */ 942 show_sf2_point, store_sf2_point, 3, 2),
983 943 SENSOR_ATTR_2(sf2_point4_fan2, S_IRUGO | S_IWUSR,
984#define device_create_file_sf2_point(client, offset, index) \ 944 show_sf2_point, store_sf2_point, 4, 2),
985do { \ 945
986device_create_file(&client->dev, \ 946 SENSOR_ATTR_2(sf2_point1_fan3, S_IRUGO | S_IWUSR,
987&sensor_dev_attr_sf2_point##offset##_fan##index.dev_attr); \ 947 show_sf2_point, store_sf2_point, 1, 3),
988} while (0) 948 SENSOR_ATTR_2(sf2_point2_fan3, S_IRUGO | S_IWUSR,
949 show_sf2_point, store_sf2_point, 2, 3),
950 SENSOR_ATTR_2(sf2_point3_fan3, S_IRUGO | S_IWUSR,
951 show_sf2_point, store_sf2_point, 3, 3),
952 SENSOR_ATTR_2(sf2_point4_fan3, S_IRUGO | S_IWUSR,
953 show_sf2_point, store_sf2_point, 4, 3),
954};
989 955
990 956
991static ssize_t 957static ssize_t
@@ -1026,26 +992,28 @@ store_sf2_level(struct device *dev, struct device_attribute *attr,
1026 return count; 992 return count;
1027} 993}
1028 994
1029#define sysfs_sf2_level(offset, index) \ 995static struct sensor_device_attribute_2 sda_sf2_level[] = {
1030static SENSOR_DEVICE_ATTR_2(sf2_level##offset##_fan##index, S_IRUGO | S_IWUSR, \ 996 SENSOR_ATTR_2(sf2_level1_fan1, S_IRUGO | S_IWUSR,
1031 show_sf2_level, store_sf2_level, offset, index); 997 show_sf2_level, store_sf2_level, 1, 1),
1032 998 SENSOR_ATTR_2(sf2_level2_fan1, S_IRUGO | S_IWUSR,
1033sysfs_sf2_level(1, 1); /* Fan1 */ 999 show_sf2_level, store_sf2_level, 2, 1),
1034sysfs_sf2_level(2, 1); /* Fan1 */ 1000 SENSOR_ATTR_2(sf2_level3_fan1, S_IRUGO | S_IWUSR,
1035sysfs_sf2_level(3, 1); /* Fan1 */ 1001 show_sf2_level, store_sf2_level, 3, 1),
1036sysfs_sf2_level(1, 2); /* Fan2 */ 1002
1037sysfs_sf2_level(2, 2); /* Fan2 */ 1003 SENSOR_ATTR_2(sf2_level1_fan2, S_IRUGO | S_IWUSR,
1038sysfs_sf2_level(3, 2); /* Fan2 */ 1004 show_sf2_level, store_sf2_level, 1, 2),
1039sysfs_sf2_level(1, 3); /* Fan3 */ 1005 SENSOR_ATTR_2(sf2_level2_fan2, S_IRUGO | S_IWUSR,
1040sysfs_sf2_level(2, 3); /* Fan3 */ 1006 show_sf2_level, store_sf2_level, 2, 2),
1041sysfs_sf2_level(3, 3); /* Fan3 */ 1007 SENSOR_ATTR_2(sf2_level3_fan2, S_IRUGO | S_IWUSR,
1042 1008 show_sf2_level, store_sf2_level, 3, 2),
1043#define device_create_file_sf2_level(client, offset, index) \ 1009
1044do { \ 1010 SENSOR_ATTR_2(sf2_level1_fan3, S_IRUGO | S_IWUSR,
1045device_create_file(&client->dev, \ 1011 show_sf2_level, store_sf2_level, 1, 3),
1046&sensor_dev_attr_sf2_level##offset##_fan##index.dev_attr); \ 1012 SENSOR_ATTR_2(sf2_level2_fan3, S_IRUGO | S_IWUSR,
1047} while (0) 1013 show_sf2_level, store_sf2_level, 2, 3),
1048 1014 SENSOR_ATTR_2(sf2_level3_fan3, S_IRUGO | S_IWUSR,
1015 show_sf2_level, store_sf2_level, 3, 3),
1016};
1049 1017
1050/* This function is called when: 1018/* This function is called when:
1051 * w83792d_driver is inserted (when this module is loaded), for each 1019 * w83792d_driver is inserted (when this module is loaded), for each
@@ -1147,12 +1115,19 @@ ERROR_SC_0:
1147 return err; 1115 return err;
1148} 1116}
1149 1117
1118static void device_create_file_fan(struct device *dev, int i)
1119{
1120 device_create_file(dev, &sda_fan_input[i].dev_attr);
1121 device_create_file(dev, &sda_fan_div[i].dev_attr);
1122 device_create_file(dev, &sda_fan_min[i].dev_attr);
1123}
1150 1124
1151static int 1125static int
1152w83792d_detect(struct i2c_adapter *adapter, int address, int kind) 1126w83792d_detect(struct i2c_adapter *adapter, int address, int kind)
1153{ 1127{
1154 int i = 0, val1 = 0, val2; 1128 int i = 0, val1 = 0, val2;
1155 struct i2c_client *new_client; 1129 struct i2c_client *client;
1130 struct device *dev;
1156 struct w83792d_data *data; 1131 struct w83792d_data *data;
1157 int err = 0; 1132 int err = 0;
1158 const char *client_name = ""; 1133 const char *client_name = "";
@@ -1170,12 +1145,13 @@ w83792d_detect(struct i2c_adapter *adapter, int address, int kind)
1170 goto ERROR0; 1145 goto ERROR0;
1171 } 1146 }
1172 1147
1173 new_client = &data->client; 1148 client = &data->client;
1174 i2c_set_clientdata(new_client, data); 1149 dev = &client->dev;
1175 new_client->addr = address; 1150 i2c_set_clientdata(client, data);
1176 new_client->adapter = adapter; 1151 client->addr = address;
1177 new_client->driver = &w83792d_driver; 1152 client->adapter = adapter;
1178 new_client->flags = 0; 1153 client->driver = &w83792d_driver;
1154 client->flags = 0;
1179 1155
1180 /* Now, we do the remaining detection. */ 1156 /* Now, we do the remaining detection. */
1181 1157
@@ -1184,13 +1160,12 @@ w83792d_detect(struct i2c_adapter *adapter, int address, int kind)
1184 force_*=... parameter, and the Winbond will be reset to the right 1160 force_*=... parameter, and the Winbond will be reset to the right
1185 bank. */ 1161 bank. */
1186 if (kind < 0) { 1162 if (kind < 0) {
1187 if (w83792d_read_value(new_client, W83792D_REG_CONFIG) & 0x80) { 1163 if (w83792d_read_value(client, W83792D_REG_CONFIG) & 0x80) {
1188 dev_warn(&new_client->dev, "Detection failed at step " 1164 dev_warn(dev, "Detection failed at step 3\n");
1189 "3\n");
1190 goto ERROR1; 1165 goto ERROR1;
1191 } 1166 }
1192 val1 = w83792d_read_value(new_client, W83792D_REG_BANK); 1167 val1 = w83792d_read_value(client, W83792D_REG_BANK);
1193 val2 = w83792d_read_value(new_client, W83792D_REG_CHIPMAN); 1168 val2 = w83792d_read_value(client, W83792D_REG_CHIPMAN);
1194 /* Check for Winbond ID if in bank 0 */ 1169 /* Check for Winbond ID if in bank 0 */
1195 if (!(val1 & 0x07)) { /* is Bank0 */ 1170 if (!(val1 & 0x07)) { /* is Bank0 */
1196 if (((!(val1 & 0x80)) && (val2 != 0xa3)) || 1171 if (((!(val1 & 0x80)) && (val2 != 0xa3)) ||
@@ -1200,34 +1175,33 @@ w83792d_detect(struct i2c_adapter *adapter, int address, int kind)
1200 } 1175 }
1201 /* If Winbond chip, address of chip and W83792D_REG_I2C_ADDR 1176 /* If Winbond chip, address of chip and W83792D_REG_I2C_ADDR
1202 should match */ 1177 should match */
1203 if (w83792d_read_value(new_client, 1178 if (w83792d_read_value(client,
1204 W83792D_REG_I2C_ADDR) != address) { 1179 W83792D_REG_I2C_ADDR) != address) {
1205 dev_warn(&new_client->dev, "Detection failed " 1180 dev_warn(dev, "Detection failed at step 5\n");
1206 "at step 5\n");
1207 goto ERROR1; 1181 goto ERROR1;
1208 } 1182 }
1209 } 1183 }
1210 1184
1211 /* We have either had a force parameter, or we have already detected the 1185 /* We have either had a force parameter, or we have already detected the
1212 Winbond. Put it now into bank 0 and Vendor ID High Byte */ 1186 Winbond. Put it now into bank 0 and Vendor ID High Byte */
1213 w83792d_write_value(new_client, 1187 w83792d_write_value(client,
1214 W83792D_REG_BANK, 1188 W83792D_REG_BANK,
1215 (w83792d_read_value(new_client, 1189 (w83792d_read_value(client,
1216 W83792D_REG_BANK) & 0x78) | 0x80); 1190 W83792D_REG_BANK) & 0x78) | 0x80);
1217 1191
1218 /* Determine the chip type. */ 1192 /* Determine the chip type. */
1219 if (kind <= 0) { 1193 if (kind <= 0) {
1220 /* get vendor ID */ 1194 /* get vendor ID */
1221 val2 = w83792d_read_value(new_client, W83792D_REG_CHIPMAN); 1195 val2 = w83792d_read_value(client, W83792D_REG_CHIPMAN);
1222 if (val2 != 0x5c) { /* the vendor is NOT Winbond */ 1196 if (val2 != 0x5c) { /* the vendor is NOT Winbond */
1223 goto ERROR1; 1197 goto ERROR1;
1224 } 1198 }
1225 val1 = w83792d_read_value(new_client, W83792D_REG_WCHIPID); 1199 val1 = w83792d_read_value(client, W83792D_REG_WCHIPID);
1226 if (val1 == 0x7a) { 1200 if (val1 == 0x7a) {
1227 kind = w83792d; 1201 kind = w83792d;
1228 } else { 1202 } else {
1229 if (kind == 0) 1203 if (kind == 0)
1230 dev_warn(&new_client->dev, 1204 dev_warn(dev,
1231 "w83792d: Ignoring 'force' parameter for" 1205 "w83792d: Ignoring 'force' parameter for"
1232 " unknown chip at adapter %d, address" 1206 " unknown chip at adapter %d, address"
1233 " 0x%02x\n", i2c_adapter_id(adapter), 1207 " 0x%02x\n", i2c_adapter_id(adapter),
@@ -1239,120 +1213,86 @@ w83792d_detect(struct i2c_adapter *adapter, int address, int kind)
1239 if (kind == w83792d) { 1213 if (kind == w83792d) {
1240 client_name = "w83792d"; 1214 client_name = "w83792d";
1241 } else { 1215 } else {
1242 dev_err(&new_client->dev, "w83792d: Internal error: unknown" 1216 dev_err(dev, "w83792d: Internal error: unknown"
1243 " kind (%d)?!?", kind); 1217 " kind (%d)?!?", kind);
1244 goto ERROR1; 1218 goto ERROR1;
1245 } 1219 }
1246 1220
1247 /* Fill in the remaining client fields and put into the global list */ 1221 /* Fill in the remaining client fields and put into the global list */
1248 strlcpy(new_client->name, client_name, I2C_NAME_SIZE); 1222 strlcpy(client->name, client_name, I2C_NAME_SIZE);
1249 data->type = kind; 1223 data->type = kind;
1250 1224
1251 data->valid = 0; 1225 data->valid = 0;
1252 init_MUTEX(&data->update_lock); 1226 mutex_init(&data->update_lock);
1253 1227
1254 /* Tell the I2C layer a new client has arrived */ 1228 /* Tell the I2C layer a new client has arrived */
1255 if ((err = i2c_attach_client(new_client))) 1229 if ((err = i2c_attach_client(client)))
1256 goto ERROR1; 1230 goto ERROR1;
1257 1231
1258 if ((err = w83792d_detect_subclients(adapter, address, 1232 if ((err = w83792d_detect_subclients(adapter, address,
1259 kind, new_client))) 1233 kind, client)))
1260 goto ERROR2; 1234 goto ERROR2;
1261 1235
1262 /* Initialize the chip */ 1236 /* Initialize the chip */
1263 w83792d_init_client(new_client); 1237 w83792d_init_client(client);
1264 1238
1265 /* A few vars need to be filled upon startup */ 1239 /* A few vars need to be filled upon startup */
1266 for (i = 0; i < 7; i++) { 1240 for (i = 0; i < 7; i++) {
1267 data->fan_min[i] = w83792d_read_value(new_client, 1241 data->fan_min[i] = w83792d_read_value(client,
1268 W83792D_REG_FAN_MIN[i]); 1242 W83792D_REG_FAN_MIN[i]);
1269 } 1243 }
1270 1244
1271 /* Register sysfs hooks */ 1245 /* Register sysfs hooks */
1272 data->class_dev = hwmon_device_register(&new_client->dev); 1246 data->class_dev = hwmon_device_register(dev);
1273 if (IS_ERR(data->class_dev)) { 1247 if (IS_ERR(data->class_dev)) {
1274 err = PTR_ERR(data->class_dev); 1248 err = PTR_ERR(data->class_dev);
1275 goto ERROR3; 1249 goto ERROR3;
1276 } 1250 }
1277 device_create_file_in(new_client, 0); 1251 for (i = 0; i < 9; i++) {
1278 device_create_file_in(new_client, 1); 1252 device_create_file(dev, &sda_in_input[i].dev_attr);
1279 device_create_file_in(new_client, 2); 1253 device_create_file(dev, &sda_in_max[i].dev_attr);
1280 device_create_file_in(new_client, 3); 1254 device_create_file(dev, &sda_in_min[i].dev_attr);
1281 device_create_file_in(new_client, 4); 1255 }
1282 device_create_file_in(new_client, 5); 1256 for (i = 0; i < 3; i++)
1283 device_create_file_in(new_client, 6); 1257 device_create_file_fan(dev, i);
1284 device_create_file_in(new_client, 7);
1285 device_create_file_in(new_client, 8);
1286
1287 device_create_file_fan(new_client, 1);
1288 device_create_file_fan(new_client, 2);
1289 device_create_file_fan(new_client, 3);
1290 1258
1291 /* Read GPIO enable register to check if pins for fan 4,5 are used as 1259 /* Read GPIO enable register to check if pins for fan 4,5 are used as
1292 GPIO */ 1260 GPIO */
1293 val1 = w83792d_read_value(new_client, W83792D_REG_GPIO_EN); 1261 val1 = w83792d_read_value(client, W83792D_REG_GPIO_EN);
1294 if (!(val1 & 0x40)) 1262 if (!(val1 & 0x40))
1295 device_create_file_fan(new_client, 4); 1263 device_create_file_fan(dev, 3);
1296 if (!(val1 & 0x20)) 1264 if (!(val1 & 0x20))
1297 device_create_file_fan(new_client, 5); 1265 device_create_file_fan(dev, 4);
1298 1266
1299 val1 = w83792d_read_value(new_client, W83792D_REG_PIN); 1267 val1 = w83792d_read_value(client, W83792D_REG_PIN);
1300 if (val1 & 0x40) 1268 if (val1 & 0x40)
1301 device_create_file_fan(new_client, 6); 1269 device_create_file_fan(dev, 5);
1302 if (val1 & 0x04) 1270 if (val1 & 0x04)
1303 device_create_file_fan(new_client, 7); 1271 device_create_file_fan(dev, 6);
1304 1272
1305 device_create_file_temp1(new_client); /* Temp1 */ 1273 for (i = 0; i < 3; i++) {
1306 device_create_file_temp_add(new_client, 2); /* Temp2 */ 1274 device_create_file(dev, &sda_temp_input[i].dev_attr);
1307 device_create_file_temp_add(new_client, 3); /* Temp3 */ 1275 device_create_file(dev, &sda_temp_max[i].dev_attr);
1308 1276 device_create_file(dev, &sda_temp_max_hyst[i].dev_attr);
1309 device_create_file_alarms(new_client); 1277 device_create_file(dev, &sda_thermal_cruise[i].dev_attr);
1310 1278 device_create_file(dev, &sda_tolerance[i].dev_attr);
1311 device_create_file_pwm(new_client, 1); 1279 }
1312 device_create_file_pwm(new_client, 2); 1280
1313 device_create_file_pwm(new_client, 3); 1281 for (i = 0; i < ARRAY_SIZE(sda_pwm); i++) {
1314 1282 device_create_file(dev, &sda_pwm[i].dev_attr);
1315 device_create_file_pwmenable(new_client, 1); 1283 device_create_file(dev, &sda_pwm_enable[i].dev_attr);
1316 device_create_file_pwmenable(new_client, 2); 1284 device_create_file(dev, &sda_pwm_mode[i].dev_attr);
1317 device_create_file_pwmenable(new_client, 3); 1285 }
1318 1286
1319 device_create_file_pwm_mode(new_client, 1); 1287 device_create_file(dev, &dev_attr_alarms);
1320 device_create_file_pwm_mode(new_client, 2); 1288 device_create_file(dev, &dev_attr_chassis);
1321 device_create_file_pwm_mode(new_client, 3); 1289 device_create_file(dev, &dev_attr_chassis_clear);
1322 1290
1323 device_create_file_chassis(new_client); 1291 for (i = 0; i < ARRAY_SIZE(sda_sf2_point); i++)
1324 device_create_file_chassis_clear(new_client); 1292 device_create_file(dev, &sda_sf2_point[i].dev_attr);
1325 1293
1326 device_create_file_thermal_cruise(new_client, 1); 1294 for (i = 0; i < ARRAY_SIZE(sda_sf2_level); i++)
1327 device_create_file_thermal_cruise(new_client, 2); 1295 device_create_file(dev, &sda_sf2_level[i].dev_attr);
1328 device_create_file_thermal_cruise(new_client, 3);
1329
1330 device_create_file_tolerance(new_client, 1);
1331 device_create_file_tolerance(new_client, 2);
1332 device_create_file_tolerance(new_client, 3);
1333
1334 device_create_file_sf2_point(new_client, 1, 1); /* Fan1 */
1335 device_create_file_sf2_point(new_client, 2, 1); /* Fan1 */
1336 device_create_file_sf2_point(new_client, 3, 1); /* Fan1 */
1337 device_create_file_sf2_point(new_client, 4, 1); /* Fan1 */
1338 device_create_file_sf2_point(new_client, 1, 2); /* Fan2 */
1339 device_create_file_sf2_point(new_client, 2, 2); /* Fan2 */
1340 device_create_file_sf2_point(new_client, 3, 2); /* Fan2 */
1341 device_create_file_sf2_point(new_client, 4, 2); /* Fan2 */
1342 device_create_file_sf2_point(new_client, 1, 3); /* Fan3 */
1343 device_create_file_sf2_point(new_client, 2, 3); /* Fan3 */
1344 device_create_file_sf2_point(new_client, 3, 3); /* Fan3 */
1345 device_create_file_sf2_point(new_client, 4, 3); /* Fan3 */
1346
1347 device_create_file_sf2_level(new_client, 1, 1); /* Fan1 */
1348 device_create_file_sf2_level(new_client, 2, 1); /* Fan1 */
1349 device_create_file_sf2_level(new_client, 3, 1); /* Fan1 */
1350 device_create_file_sf2_level(new_client, 1, 2); /* Fan2 */
1351 device_create_file_sf2_level(new_client, 2, 2); /* Fan2 */
1352 device_create_file_sf2_level(new_client, 3, 2); /* Fan2 */
1353 device_create_file_sf2_level(new_client, 1, 3); /* Fan3 */
1354 device_create_file_sf2_level(new_client, 2, 3); /* Fan3 */
1355 device_create_file_sf2_level(new_client, 3, 3); /* Fan3 */
1356 1296
1357 return 0; 1297 return 0;
1358 1298
@@ -1366,7 +1306,7 @@ ERROR3:
1366 kfree(data->lm75[1]); 1306 kfree(data->lm75[1]);
1367 } 1307 }
1368ERROR2: 1308ERROR2:
1369 i2c_detach_client(new_client); 1309 i2c_detach_client(client);
1370ERROR1: 1310ERROR1:
1371 kfree(data); 1311 kfree(data);
1372ERROR0: 1312ERROR0:
@@ -1434,7 +1374,7 @@ static struct w83792d_data *w83792d_update_device(struct device *dev)
1434 int i, j; 1374 int i, j;
1435 u8 reg_array_tmp[4], pwm_array_tmp[7], reg_tmp; 1375 u8 reg_array_tmp[4], pwm_array_tmp[7], reg_tmp;
1436 1376
1437 down(&data->update_lock); 1377 mutex_lock(&data->update_lock);
1438 1378
1439 if (time_after 1379 if (time_after
1440 (jiffies - data->last_updated, (unsigned long) (HZ * 3)) 1380 (jiffies - data->last_updated, (unsigned long) (HZ * 3))
@@ -1545,7 +1485,7 @@ static struct w83792d_data *w83792d_update_device(struct device *dev)
1545 data->valid = 1; 1485 data->valid = 1;
1546 } 1486 }
1547 1487
1548 up(&data->update_lock); 1488 mutex_unlock(&data->update_lock);
1549 1489
1550#ifdef DEBUG 1490#ifdef DEBUG
1551 w83792d_print_debug(data, dev); 1491 w83792d_print_debug(data, dev);
diff --git a/drivers/hwmon/w83l785ts.c b/drivers/hwmon/w83l785ts.c
index f66c0cfded..3f2bac125f 100644
--- a/drivers/hwmon/w83l785ts.c
+++ b/drivers/hwmon/w83l785ts.c
@@ -39,6 +39,7 @@
39#include <linux/hwmon.h> 39#include <linux/hwmon.h>
40#include <linux/hwmon-sysfs.h> 40#include <linux/hwmon-sysfs.h>
41#include <linux/err.h> 41#include <linux/err.h>
42#include <linux/mutex.h>
42 43
43/* How many retries on register read error */ 44/* How many retries on register read error */
44#define MAX_RETRIES 5 45#define MAX_RETRIES 5
@@ -107,7 +108,7 @@ static struct i2c_driver w83l785ts_driver = {
107struct w83l785ts_data { 108struct w83l785ts_data {
108 struct i2c_client client; 109 struct i2c_client client;
109 struct class_device *class_dev; 110 struct class_device *class_dev;
110 struct semaphore update_lock; 111 struct mutex update_lock;
111 char valid; /* zero until following fields are valid */ 112 char valid; /* zero until following fields are valid */
112 unsigned long last_updated; /* in jiffies */ 113 unsigned long last_updated; /* in jiffies */
113 114
@@ -221,7 +222,7 @@ static int w83l785ts_detect(struct i2c_adapter *adapter, int address, int kind)
221 /* We can fill in the remaining client fields. */ 222 /* We can fill in the remaining client fields. */
222 strlcpy(new_client->name, "w83l785ts", I2C_NAME_SIZE); 223 strlcpy(new_client->name, "w83l785ts", I2C_NAME_SIZE);
223 data->valid = 0; 224 data->valid = 0;
224 init_MUTEX(&data->update_lock); 225 mutex_init(&data->update_lock);
225 226
226 /* Default values in case the first read fails (unlikely). */ 227 /* Default values in case the first read fails (unlikely). */
227 data->temp[1] = data->temp[0] = 0; 228 data->temp[1] = data->temp[0] = 0;
@@ -299,7 +300,7 @@ static struct w83l785ts_data *w83l785ts_update_device(struct device *dev)
299 struct i2c_client *client = to_i2c_client(dev); 300 struct i2c_client *client = to_i2c_client(dev);
300 struct w83l785ts_data *data = i2c_get_clientdata(client); 301 struct w83l785ts_data *data = i2c_get_clientdata(client);
301 302
302 down(&data->update_lock); 303 mutex_lock(&data->update_lock);
303 304
304 if (!data->valid || time_after(jiffies, data->last_updated + HZ * 2)) { 305 if (!data->valid || time_after(jiffies, data->last_updated + HZ * 2)) {
305 dev_dbg(&client->dev, "Updating w83l785ts data.\n"); 306 dev_dbg(&client->dev, "Updating w83l785ts data.\n");
@@ -312,7 +313,7 @@ static struct w83l785ts_data *w83l785ts_update_device(struct device *dev)
312 data->valid = 1; 313 data->valid = 1;
313 } 314 }
314 315
315 up(&data->update_lock); 316 mutex_unlock(&data->update_lock);
316 317
317 return data; 318 return data;
318} 319}
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index ff92735c7c..089c6f5b24 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -168,12 +168,14 @@ config I2C_PIIX4
168 help 168 help
169 If you say yes to this option, support will be included for the Intel 169 If you say yes to this option, support will be included for the Intel
170 PIIX4 family of mainboard I2C interfaces. Specifically, the following 170 PIIX4 family of mainboard I2C interfaces. Specifically, the following
171 versions of the chipset are supported: 171 versions of the chipset are supported (note that Serverworks is part
172 of Broadcom):
172 Intel PIIX4 173 Intel PIIX4
173 Intel 440MX 174 Intel 440MX
174 Serverworks OSB4 175 Serverworks OSB4
175 Serverworks CSB5 176 Serverworks CSB5
176 Serverworks CSB6 177 Serverworks CSB6
178 Serverworks HT-1000
177 SMSC Victory66 179 SMSC Victory66
178 180
179 This driver can also be built as a module. If so, the module 181 This driver can also be built as a module. If so, the module
@@ -389,10 +391,11 @@ config SCx200_I2C_SDA
389 also be specified with a module parameter. 391 also be specified with a module parameter.
390 392
391config SCx200_ACB 393config SCx200_ACB
392 tristate "NatSemi SCx200 ACCESS.bus" 394 tristate "Geode ACCESS.bus support"
393 depends on I2C && PCI 395 depends on X86_32 && I2C && PCI
394 help 396 help
395 Enable the use of the ACCESS.bus controllers of a SCx200 processor. 397 Enable the use of the ACCESS.bus controllers on the Geode SCx200 and
398 SC1100 processors and the CS5535 and CS5536 Geode companion devices.
396 399
397 If you don't know what to do here, say N. 400 If you don't know what to do here, say N.
398 401
diff --git a/drivers/i2c/busses/i2c-ali1535.c b/drivers/i2c/busses/i2c-ali1535.c
index 3eb47890db..d3ef46aeeb 100644
--- a/drivers/i2c/busses/i2c-ali1535.c
+++ b/drivers/i2c/busses/i2c-ali1535.c
@@ -63,7 +63,6 @@
63#include <linux/i2c.h> 63#include <linux/i2c.h>
64#include <linux/init.h> 64#include <linux/init.h>
65#include <asm/io.h> 65#include <asm/io.h>
66#include <asm/semaphore.h>
67 66
68 67
69/* ALI1535 SMBus address offsets */ 68/* ALI1535 SMBus address offsets */
@@ -136,7 +135,6 @@
136 135
137static struct pci_driver ali1535_driver; 136static struct pci_driver ali1535_driver;
138static unsigned short ali1535_smba; 137static unsigned short ali1535_smba;
139static DECLARE_MUTEX(i2c_ali1535_sem);
140 138
141/* Detect whether a ALI1535 can be found, and initialize it, where necessary. 139/* Detect whether a ALI1535 can be found, and initialize it, where necessary.
142 Note the differences between kernels with the old PCI BIOS interface and 140 Note the differences between kernels with the old PCI BIOS interface and
@@ -345,7 +343,6 @@ static s32 ali1535_access(struct i2c_adapter *adap, u16 addr,
345 int timeout; 343 int timeout;
346 s32 result = 0; 344 s32 result = 0;
347 345
348 down(&i2c_ali1535_sem);
349 /* make sure SMBus is idle */ 346 /* make sure SMBus is idle */
350 temp = inb_p(SMBHSTSTS); 347 temp = inb_p(SMBHSTSTS);
351 for (timeout = 0; 348 for (timeout = 0;
@@ -460,7 +457,6 @@ static s32 ali1535_access(struct i2c_adapter *adap, u16 addr,
460 break; 457 break;
461 } 458 }
462EXIT: 459EXIT:
463 up(&i2c_ali1535_sem);
464 return result; 460 return result;
465} 461}
466 462
diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
index 56c7d98759..08e915730c 100644
--- a/drivers/i2c/busses/i2c-amd756-s4882.c
+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
@@ -38,6 +38,7 @@
38#include <linux/slab.h> 38#include <linux/slab.h>
39#include <linux/init.h> 39#include <linux/init.h>
40#include <linux/i2c.h> 40#include <linux/i2c.h>
41#include <linux/mutex.h>
41 42
42extern struct i2c_adapter amd756_smbus; 43extern struct i2c_adapter amd756_smbus;
43 44
@@ -45,7 +46,7 @@ static struct i2c_adapter *s4882_adapter;
45static struct i2c_algorithm *s4882_algo; 46static struct i2c_algorithm *s4882_algo;
46 47
47/* Wrapper access functions for multiplexed SMBus */ 48/* Wrapper access functions for multiplexed SMBus */
48static struct semaphore amd756_lock; 49static DEFINE_MUTEX(amd756_lock);
49 50
50static s32 amd756_access_virt0(struct i2c_adapter * adap, u16 addr, 51static s32 amd756_access_virt0(struct i2c_adapter * adap, u16 addr,
51 unsigned short flags, char read_write, 52 unsigned short flags, char read_write,
@@ -59,12 +60,12 @@ static s32 amd756_access_virt0(struct i2c_adapter * adap, u16 addr,
59 || addr == 0x18) 60 || addr == 0x18)
60 return -1; 61 return -1;
61 62
62 down(&amd756_lock); 63 mutex_lock(&amd756_lock);
63 64
64 error = amd756_smbus.algo->smbus_xfer(adap, addr, flags, read_write, 65 error = amd756_smbus.algo->smbus_xfer(adap, addr, flags, read_write,
65 command, size, data); 66 command, size, data);
66 67
67 up(&amd756_lock); 68 mutex_unlock(&amd756_lock);
68 69
69 return error; 70 return error;
70} 71}
@@ -87,7 +88,7 @@ static inline s32 amd756_access_channel(struct i2c_adapter * adap, u16 addr,
87 if (addr != 0x4c && (addr & 0xfc) != 0x50 && (addr & 0xfc) != 0x30) 88 if (addr != 0x4c && (addr & 0xfc) != 0x50 && (addr & 0xfc) != 0x30)
88 return -1; 89 return -1;
89 90
90 down(&amd756_lock); 91 mutex_lock(&amd756_lock);
91 92
92 if (last_channels != channels) { 93 if (last_channels != channels) {
93 union i2c_smbus_data mplxdata; 94 union i2c_smbus_data mplxdata;
@@ -105,7 +106,7 @@ static inline s32 amd756_access_channel(struct i2c_adapter * adap, u16 addr,
105 command, size, data); 106 command, size, data);
106 107
107UNLOCK: 108UNLOCK:
108 up(&amd756_lock); 109 mutex_unlock(&amd756_lock);
109 return error; 110 return error;
110} 111}
111 112
@@ -166,8 +167,6 @@ static int __init amd756_s4882_init(void)
166 } 167 }
167 168
168 printk(KERN_INFO "Enabling SMBus multiplexing for Tyan S4882\n"); 169 printk(KERN_INFO "Enabling SMBus multiplexing for Tyan S4882\n");
169 init_MUTEX(&amd756_lock);
170
171 /* Define the 5 virtual adapters and algorithms structures */ 170 /* Define the 5 virtual adapters and algorithms structures */
172 if (!(s4882_adapter = kzalloc(5 * sizeof(struct i2c_adapter), 171 if (!(s4882_adapter = kzalloc(5 * sizeof(struct i2c_adapter),
173 GFP_KERNEL))) { 172 GFP_KERNEL))) {
diff --git a/drivers/i2c/busses/i2c-frodo.c b/drivers/i2c/busses/i2c-frodo.c
deleted file mode 100644
index b6f52f5a41..0000000000
--- a/drivers/i2c/busses/i2c-frodo.c
+++ /dev/null
@@ -1,85 +0,0 @@
1
2/*
3 * linux/drivers/i2c/i2c-frodo.c
4 *
5 * Author: Abraham van der Merwe <abraham@2d3d.co.za>
6 *
7 * An I2C adapter driver for the 2d3D, Inc. StrongARM SA-1110
8 * Development board (Frodo).
9 *
10 * This source code is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * version 2 as published by the Free Software Foundation.
13 */
14
15#include <linux/module.h>
16#include <linux/kernel.h>
17#include <linux/init.h>
18#include <linux/delay.h>
19#include <linux/i2c.h>
20#include <linux/i2c-algo-bit.h>
21#include <asm/hardware.h>
22
23
24static void frodo_setsda (void *data,int state)
25{
26 if (state)
27 FRODO_CPLD_I2C |= FRODO_I2C_SDA_OUT;
28 else
29 FRODO_CPLD_I2C &= ~FRODO_I2C_SDA_OUT;
30}
31
32static void frodo_setscl (void *data,int state)
33{
34 if (state)
35 FRODO_CPLD_I2C |= FRODO_I2C_SCL_OUT;
36 else
37 FRODO_CPLD_I2C &= ~FRODO_I2C_SCL_OUT;
38}
39
40static int frodo_getsda (void *data)
41{
42 return ((FRODO_CPLD_I2C & FRODO_I2C_SDA_IN) != 0);
43}
44
45static int frodo_getscl (void *data)
46{
47 return ((FRODO_CPLD_I2C & FRODO_I2C_SCL_IN) != 0);
48}
49
50static struct i2c_algo_bit_data bit_frodo_data = {
51 .setsda = frodo_setsda,
52 .setscl = frodo_setscl,
53 .getsda = frodo_getsda,
54 .getscl = frodo_getscl,
55 .udelay = 80,
56 .mdelay = 80,
57 .timeout = HZ
58};
59
60static struct i2c_adapter frodo_ops = {
61 .owner = THIS_MODULE,
62 .id = I2C_HW_B_FRODO,
63 .algo_data = &bit_frodo_data,
64 .dev = {
65 .name = "Frodo adapter driver",
66 },
67};
68
69static int __init i2c_frodo_init (void)
70{
71 return i2c_bit_add_bus(&frodo_ops);
72}
73
74static void __exit i2c_frodo_exit (void)
75{
76 i2c_bit_del_bus(&frodo_ops);
77}
78
79MODULE_AUTHOR ("Abraham van der Merwe <abraham@2d3d.co.za>");
80MODULE_DESCRIPTION ("I2C-Bus adapter routines for Frodo");
81MODULE_LICENSE ("GPL");
82
83module_init (i2c_frodo_init);
84module_exit (i2c_frodo_exit);
85
diff --git a/drivers/i2c/busses/i2c-isa.c b/drivers/i2c/busses/i2c-isa.c
index 4344ae6b1f..c3e1d3e888 100644
--- a/drivers/i2c/busses/i2c-isa.c
+++ b/drivers/i2c/busses/i2c-isa.c
@@ -125,7 +125,7 @@ int i2c_isa_del_driver(struct i2c_driver *driver)
125 125
126static int __init i2c_isa_init(void) 126static int __init i2c_isa_init(void)
127{ 127{
128 init_MUTEX(&isa_adapter.clist_lock); 128 mutex_init(&isa_adapter.clist_lock);
129 INIT_LIST_HEAD(&isa_adapter.clients); 129 INIT_LIST_HEAD(&isa_adapter.clients);
130 130
131 isa_adapter.nr = ANY_I2C_ISA_BUS; 131 isa_adapter.nr = ANY_I2C_ISA_BUS;
diff --git a/drivers/i2c/busses/i2c-ite.c b/drivers/i2c/busses/i2c-ite.c
index 5f5d294480..d82e6dae84 100644
--- a/drivers/i2c/busses/i2c-ite.c
+++ b/drivers/i2c/busses/i2c-ite.c
@@ -200,9 +200,7 @@ static struct i2c_adapter iic_ite_ops = {
200 .owner = THIS_MODULE, 200 .owner = THIS_MODULE,
201 .id = I2C_HW_I_IIC, 201 .id = I2C_HW_I_IIC,
202 .algo_data = &iic_ite_data, 202 .algo_data = &iic_ite_data,
203 .dev = { 203 .name = "ITE IIC adapter",
204 .name = "ITE IIC adapter",
205 },
206}; 204};
207 205
208/* Called when the module is loaded. This function starts the 206/* Called when the module is loaded. This function starts the
diff --git a/drivers/i2c/busses/i2c-ixp4xx.c b/drivers/i2c/busses/i2c-ixp4xx.c
index e422d8b2d4..2ed07112d6 100644
--- a/drivers/i2c/busses/i2c-ixp4xx.c
+++ b/drivers/i2c/busses/i2c-ixp4xx.c
@@ -126,6 +126,7 @@ static int ixp4xx_i2c_probe(struct platform_device *plat_dev)
126 drv_data->algo_data.timeout = 100; 126 drv_data->algo_data.timeout = 100;
127 127
128 drv_data->adapter.id = I2C_HW_B_IXP4XX; 128 drv_data->adapter.id = I2C_HW_B_IXP4XX;
129 drv_data->adapter.class = I2C_CLASS_HWMON;
129 strlcpy(drv_data->adapter.name, plat_dev->dev.driver->name, 130 strlcpy(drv_data->adapter.name, plat_dev->dev.driver->name,
130 I2C_NAME_SIZE); 131 I2C_NAME_SIZE);
131 drv_data->adapter.algo_data = &drv_data->algo_data; 132 drv_data->adapter.algo_data = &drv_data->algo_data;
diff --git a/drivers/i2c/busses/i2c-piix4.c b/drivers/i2c/busses/i2c-piix4.c
index 692f473454..d9c7c00e71 100644
--- a/drivers/i2c/busses/i2c-piix4.c
+++ b/drivers/i2c/busses/i2c-piix4.c
@@ -22,7 +22,7 @@
22/* 22/*
23 Supports: 23 Supports:
24 Intel PIIX4, 440MX 24 Intel PIIX4, 440MX
25 Serverworks OSB4, CSB5, CSB6 25 Serverworks OSB4, CSB5, CSB6, HT-1000
26 SMSC Victory66 26 SMSC Victory66
27 27
28 Note: we assume there can only be one device, with one SMBus interface. 28 Note: we assume there can only be one device, with one SMBus interface.
@@ -419,6 +419,8 @@ static struct pci_device_id piix4_ids[] = {
419 .driver_data = 0 }, 419 .driver_data = 0 },
420 { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_CSB6), 420 { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_CSB6),
421 .driver_data = 0 }, 421 .driver_data = 0 },
422 { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_HT1000SB),
423 .driver_data = 0 },
422 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443MX_3), 424 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443MX_3),
423 .driver_data = 3 }, 425 .driver_data = 3 },
424 { PCI_DEVICE(PCI_VENDOR_ID_EFAR, PCI_DEVICE_ID_EFAR_SLC90E66_3), 426 { PCI_DEVICE(PCI_VENDOR_ID_EFAR, PCI_DEVICE_ID_EFAR_SLC90E66_3),
diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c
index 7579f4b256..5155010b45 100644
--- a/drivers/i2c/busses/i2c-pxa.c
+++ b/drivers/i2c/busses/i2c-pxa.c
@@ -647,7 +647,7 @@ static inline void i2c_pxa_start_message(struct pxa_i2c *i2c)
647} 647}
648 648
649/* 649/*
650 * We are protected by the adapter bus semaphore. 650 * We are protected by the adapter bus mutex.
651 */ 651 */
652static int i2c_pxa_do_xfer(struct pxa_i2c *i2c, struct i2c_msg *msg, int num) 652static int i2c_pxa_do_xfer(struct pxa_i2c *i2c, struct i2c_msg *msg, int num)
653{ 653{
diff --git a/drivers/i2c/busses/scx200_acb.c b/drivers/i2c/busses/scx200_acb.c
index d3478e0845..8bd305e47f 100644
--- a/drivers/i2c/busses/scx200_acb.c
+++ b/drivers/i2c/busses/scx200_acb.c
@@ -1,27 +1,26 @@
1/* linux/drivers/i2c/scx200_acb.c 1/*
2
3 Copyright (c) 2001,2002 Christer Weinigel <wingel@nano-system.com> 2 Copyright (c) 2001,2002 Christer Weinigel <wingel@nano-system.com>
4 3
5 National Semiconductor SCx200 ACCESS.bus support 4 National Semiconductor SCx200 ACCESS.bus support
6 5 Also supports the AMD CS5535 and AMD CS5536
6
7 Based on i2c-keywest.c which is: 7 Based on i2c-keywest.c which is:
8 Copyright (c) 2001 Benjamin Herrenschmidt <benh@kernel.crashing.org> 8 Copyright (c) 2001 Benjamin Herrenschmidt <benh@kernel.crashing.org>
9 Copyright (c) 2000 Philip Edelbrock <phil@stimpy.netroedge.com> 9 Copyright (c) 2000 Philip Edelbrock <phil@stimpy.netroedge.com>
10 10
11 This program is free software; you can redistribute it and/or 11 This program is free software; you can redistribute it and/or
12 modify it under the terms of the GNU General Public License as 12 modify it under the terms of the GNU General Public License as
13 published by the Free Software Foundation; either version 2 of the 13 published by the Free Software Foundation; either version 2 of the
14 License, or (at your option) any later version. 14 License, or (at your option) any later version.
15 15
16 This program is distributed in the hope that it will be useful, 16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of 17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details. 19 General Public License for more details.
20 20
21 You should have received a copy of the GNU General Public License 21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software 22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 23 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24
25*/ 24*/
26 25
27#include <linux/module.h> 26#include <linux/module.h>
@@ -32,7 +31,9 @@
32#include <linux/smp_lock.h> 31#include <linux/smp_lock.h>
33#include <linux/pci.h> 32#include <linux/pci.h>
34#include <linux/delay.h> 33#include <linux/delay.h>
34#include <linux/mutex.h>
35#include <asm/io.h> 35#include <asm/io.h>
36#include <asm/msr.h>
36 37
37#include <linux/scx200.h> 38#include <linux/scx200.h>
38 39
@@ -47,16 +48,7 @@ static int base[MAX_DEVICES] = { 0x820, 0x840 };
47module_param_array(base, int, NULL, 0); 48module_param_array(base, int, NULL, 0);
48MODULE_PARM_DESC(base, "Base addresses for the ACCESS.bus controllers"); 49MODULE_PARM_DESC(base, "Base addresses for the ACCESS.bus controllers");
49 50
50#ifdef DEBUG 51#define POLL_TIMEOUT (HZ/5)
51#define DBG(x...) printk(KERN_DEBUG NAME ": " x)
52#else
53#define DBG(x...)
54#endif
55
56/* The hardware supports interrupt driven mode too, but I haven't
57 implemented that. */
58#define POLLED_MODE 1
59#define POLL_TIMEOUT (HZ)
60 52
61enum scx200_acb_state { 53enum scx200_acb_state {
62 state_idle, 54 state_idle,
@@ -79,12 +71,11 @@ static const char *scx200_acb_state_name[] = {
79}; 71};
80 72
81/* Physical interface */ 73/* Physical interface */
82struct scx200_acb_iface 74struct scx200_acb_iface {
83{
84 struct scx200_acb_iface *next; 75 struct scx200_acb_iface *next;
85 struct i2c_adapter adapter; 76 struct i2c_adapter adapter;
86 unsigned base; 77 unsigned base;
87 struct semaphore sem; 78 struct mutex mutex;
88 79
89 /* State machine data */ 80 /* State machine data */
90 enum scx200_acb_state state; 81 enum scx200_acb_state state;
@@ -100,7 +91,7 @@ struct scx200_acb_iface
100#define ACBSDA (iface->base + 0) 91#define ACBSDA (iface->base + 0)
101#define ACBST (iface->base + 1) 92#define ACBST (iface->base + 1)
102#define ACBST_SDAST 0x40 /* SDA Status */ 93#define ACBST_SDAST 0x40 /* SDA Status */
103#define ACBST_BER 0x20 94#define ACBST_BER 0x20
104#define ACBST_NEGACK 0x10 /* Negative Acknowledge */ 95#define ACBST_NEGACK 0x10 /* Negative Acknowledge */
105#define ACBST_STASTR 0x08 /* Stall After Start */ 96#define ACBST_STASTR 0x08 /* Stall After Start */
106#define ACBST_MASTER 0x02 97#define ACBST_MASTER 0x02
@@ -109,9 +100,9 @@ struct scx200_acb_iface
109#define ACBCTL1 (iface->base + 3) 100#define ACBCTL1 (iface->base + 3)
110#define ACBCTL1_STASTRE 0x80 101#define ACBCTL1_STASTRE 0x80
111#define ACBCTL1_NMINTE 0x40 102#define ACBCTL1_NMINTE 0x40
112#define ACBCTL1_ACK 0x10 103#define ACBCTL1_ACK 0x10
113#define ACBCTL1_STOP 0x02 104#define ACBCTL1_STOP 0x02
114#define ACBCTL1_START 0x01 105#define ACBCTL1_START 0x01
115#define ACBADDR (iface->base + 4) 106#define ACBADDR (iface->base + 4)
116#define ACBCTL2 (iface->base + 5) 107#define ACBCTL2 (iface->base + 5)
117#define ACBCTL2_ENABLE 0x01 108#define ACBCTL2_ENABLE 0x01
@@ -122,8 +113,8 @@ static void scx200_acb_machine(struct scx200_acb_iface *iface, u8 status)
122{ 113{
123 const char *errmsg; 114 const char *errmsg;
124 115
125 DBG("state %s, status = 0x%02x\n", 116 dev_dbg(&iface->adapter.dev, "state %s, status = 0x%02x\n",
126 scx200_acb_state_name[iface->state], status); 117 scx200_acb_state_name[iface->state], status);
127 118
128 if (status & ACBST_BER) { 119 if (status & ACBST_BER) {
129 errmsg = "bus error"; 120 errmsg = "bus error";
@@ -133,8 +124,17 @@ static void scx200_acb_machine(struct scx200_acb_iface *iface, u8 status)
133 errmsg = "not master"; 124 errmsg = "not master";
134 goto error; 125 goto error;
135 } 126 }
136 if (status & ACBST_NEGACK) 127 if (status & ACBST_NEGACK) {
137 goto negack; 128 dev_dbg(&iface->adapter.dev, "negative ack in state %s\n",
129 scx200_acb_state_name[iface->state]);
130
131 iface->state = state_idle;
132 iface->result = -ENXIO;
133
134 outb(inb(ACBCTL1) | ACBCTL1_STOP, ACBCTL1);
135 outb(ACBST_STASTR | ACBST_NEGACK, ACBST);
136 return;
137 }
138 138
139 switch (iface->state) { 139 switch (iface->state) {
140 case state_idle: 140 case state_idle:
@@ -160,10 +160,10 @@ static void scx200_acb_machine(struct scx200_acb_iface *iface, u8 status)
160 case state_repeat_start: 160 case state_repeat_start:
161 outb(inb(ACBCTL1) | ACBCTL1_START, ACBCTL1); 161 outb(inb(ACBCTL1) | ACBCTL1_START, ACBCTL1);
162 /* fallthrough */ 162 /* fallthrough */
163 163
164 case state_quick: 164 case state_quick:
165 if (iface->address_byte & 1) { 165 if (iface->address_byte & 1) {
166 if (iface->len == 1) 166 if (iface->len == 1)
167 outb(inb(ACBCTL1) | ACBCTL1_ACK, ACBCTL1); 167 outb(inb(ACBCTL1) | ACBCTL1_ACK, ACBCTL1);
168 else 168 else
169 outb(inb(ACBCTL1) & ~ACBCTL1_ACK, ACBCTL1); 169 outb(inb(ACBCTL1) & ~ACBCTL1_ACK, ACBCTL1);
@@ -202,26 +202,15 @@ static void scx200_acb_machine(struct scx200_acb_iface *iface, u8 status)
202 outb(inb(ACBCTL1) | ACBCTL1_STOP, ACBCTL1); 202 outb(inb(ACBCTL1) | ACBCTL1_STOP, ACBCTL1);
203 break; 203 break;
204 } 204 }
205 205
206 outb(*iface->ptr++, ACBSDA); 206 outb(*iface->ptr++, ACBSDA);
207 --iface->len; 207 --iface->len;
208 208
209 break; 209 break;
210 } 210 }
211 211
212 return; 212 return;
213 213
214 negack:
215 DBG("negative acknowledge in state %s\n",
216 scx200_acb_state_name[iface->state]);
217
218 iface->state = state_idle;
219 iface->result = -ENXIO;
220
221 outb(inb(ACBCTL1) | ACBCTL1_STOP, ACBCTL1);
222 outb(ACBST_STASTR | ACBST_NEGACK, ACBST);
223 return;
224
225 error: 214 error:
226 dev_err(&iface->adapter.dev, "%s in state %s\n", errmsg, 215 dev_err(&iface->adapter.dev, "%s in state %s\n", errmsg,
227 scx200_acb_state_name[iface->state]); 216 scx200_acb_state_name[iface->state]);
@@ -231,20 +220,9 @@ static void scx200_acb_machine(struct scx200_acb_iface *iface, u8 status)
231 iface->needs_reset = 1; 220 iface->needs_reset = 1;
232} 221}
233 222
234static void scx200_acb_timeout(struct scx200_acb_iface *iface)
235{
236 dev_err(&iface->adapter.dev, "timeout in state %s\n",
237 scx200_acb_state_name[iface->state]);
238
239 iface->state = state_idle;
240 iface->result = -EIO;
241 iface->needs_reset = 1;
242}
243
244#ifdef POLLED_MODE
245static void scx200_acb_poll(struct scx200_acb_iface *iface) 223static void scx200_acb_poll(struct scx200_acb_iface *iface)
246{ 224{
247 u8 status = 0; 225 u8 status;
248 unsigned long timeout; 226 unsigned long timeout;
249 227
250 timeout = jiffies + POLL_TIMEOUT; 228 timeout = jiffies + POLL_TIMEOUT;
@@ -254,17 +232,21 @@ static void scx200_acb_poll(struct scx200_acb_iface *iface)
254 scx200_acb_machine(iface, status); 232 scx200_acb_machine(iface, status);
255 return; 233 return;
256 } 234 }
257 msleep(10); 235 yield();
258 } 236 }
259 237
260 scx200_acb_timeout(iface); 238 dev_err(&iface->adapter.dev, "timeout in state %s\n",
239 scx200_acb_state_name[iface->state]);
240
241 iface->state = state_idle;
242 iface->result = -EIO;
243 iface->needs_reset = 1;
261} 244}
262#endif /* POLLED_MODE */
263 245
264static void scx200_acb_reset(struct scx200_acb_iface *iface) 246static void scx200_acb_reset(struct scx200_acb_iface *iface)
265{ 247{
266 /* Disable the ACCESS.bus device and Configure the SCL 248 /* Disable the ACCESS.bus device and Configure the SCL
267 frequency: 16 clock cycles */ 249 frequency: 16 clock cycles */
268 outb(0x70, ACBCTL2); 250 outb(0x70, ACBCTL2);
269 /* Polling mode */ 251 /* Polling mode */
270 outb(0, ACBCTL1); 252 outb(0, ACBCTL1);
@@ -283,9 +265,9 @@ static void scx200_acb_reset(struct scx200_acb_iface *iface)
283} 265}
284 266
285static s32 scx200_acb_smbus_xfer(struct i2c_adapter *adapter, 267static s32 scx200_acb_smbus_xfer(struct i2c_adapter *adapter,
286 u16 address, unsigned short flags, 268 u16 address, unsigned short flags,
287 char rw, u8 command, int size, 269 char rw, u8 command, int size,
288 union i2c_smbus_data *data) 270 union i2c_smbus_data *data)
289{ 271{
290 struct scx200_acb_iface *iface = i2c_get_adapdata(adapter); 272 struct scx200_acb_iface *iface = i2c_get_adapdata(adapter);
291 int len; 273 int len;
@@ -295,53 +277,47 @@ static s32 scx200_acb_smbus_xfer(struct i2c_adapter *adapter,
295 277
296 switch (size) { 278 switch (size) {
297 case I2C_SMBUS_QUICK: 279 case I2C_SMBUS_QUICK:
298 len = 0; 280 len = 0;
299 buffer = NULL; 281 buffer = NULL;
300 break; 282 break;
283
301 case I2C_SMBUS_BYTE: 284 case I2C_SMBUS_BYTE:
302 if (rw == I2C_SMBUS_READ) { 285 len = 1;
303 len = 1; 286 buffer = rw ? &data->byte : &command;
304 buffer = &data->byte; 287 break;
305 } else { 288
306 len = 1;
307 buffer = &command;
308 }
309 break;
310 case I2C_SMBUS_BYTE_DATA: 289 case I2C_SMBUS_BYTE_DATA:
311 len = 1; 290 len = 1;
312 buffer = &data->byte; 291 buffer = &data->byte;
313 break; 292 break;
293
314 case I2C_SMBUS_WORD_DATA: 294 case I2C_SMBUS_WORD_DATA:
315 len = 2; 295 len = 2;
316 cur_word = cpu_to_le16(data->word); 296 cur_word = cpu_to_le16(data->word);
317 buffer = (u8 *)&cur_word; 297 buffer = (u8 *)&cur_word;
318 break; 298 break;
299
319 case I2C_SMBUS_BLOCK_DATA: 300 case I2C_SMBUS_BLOCK_DATA:
320 len = data->block[0]; 301 len = data->block[0];
321 buffer = &data->block[1]; 302 buffer = &data->block[1];
322 break; 303 break;
304
323 default: 305 default:
324 return -EINVAL; 306 return -EINVAL;
325 } 307 }
326 308
327 DBG("size=%d, address=0x%x, command=0x%x, len=%d, read=%d\n", 309 dev_dbg(&adapter->dev,
328 size, address, command, len, rw == I2C_SMBUS_READ); 310 "size=%d, address=0x%x, command=0x%x, len=%d, read=%d\n",
311 size, address, command, len, rw);
329 312
330 if (!len && rw == I2C_SMBUS_READ) { 313 if (!len && rw == I2C_SMBUS_READ) {
331 dev_warn(&adapter->dev, "zero length read\n"); 314 dev_dbg(&adapter->dev, "zero length read\n");
332 return -EINVAL; 315 return -EINVAL;
333 } 316 }
334 317
335 if (len && !buffer) { 318 mutex_lock(&iface->mutex);
336 dev_warn(&adapter->dev, "nonzero length but no buffer\n");
337 return -EFAULT;
338 }
339
340 down(&iface->sem);
341 319
342 iface->address_byte = address<<1; 320 iface->address_byte = (address << 1) | rw;
343 if (rw == I2C_SMBUS_READ)
344 iface->address_byte |= 1;
345 iface->command = command; 321 iface->command = command;
346 iface->ptr = buffer; 322 iface->ptr = buffer;
347 iface->len = len; 323 iface->len = len;
@@ -355,25 +331,21 @@ static s32 scx200_acb_smbus_xfer(struct i2c_adapter *adapter,
355 else 331 else
356 iface->state = state_address; 332 iface->state = state_address;
357 333
358#ifdef POLLED_MODE
359 while (iface->state != state_idle) 334 while (iface->state != state_idle)
360 scx200_acb_poll(iface); 335 scx200_acb_poll(iface);
361#else /* POLLED_MODE */
362#error Interrupt driven mode not implemented
363#endif /* POLLED_MODE */
364 336
365 if (iface->needs_reset) 337 if (iface->needs_reset)
366 scx200_acb_reset(iface); 338 scx200_acb_reset(iface);
367 339
368 rc = iface->result; 340 rc = iface->result;
369 341
370 up(&iface->sem); 342 mutex_unlock(&iface->mutex);
371 343
372 if (rc == 0 && size == I2C_SMBUS_WORD_DATA && rw == I2C_SMBUS_READ) 344 if (rc == 0 && size == I2C_SMBUS_WORD_DATA && rw == I2C_SMBUS_READ)
373 data->word = le16_to_cpu(cur_word); 345 data->word = le16_to_cpu(cur_word);
374 346
375#ifdef DEBUG 347#ifdef DEBUG
376 DBG(": transfer done, result: %d", rc); 348 dev_dbg(&adapter->dev, "transfer done, result: %d", rc);
377 if (buffer) { 349 if (buffer) {
378 int i; 350 int i;
379 printk(" data:"); 351 printk(" data:");
@@ -400,17 +372,18 @@ static struct i2c_algorithm scx200_acb_algorithm = {
400}; 372};
401 373
402static struct scx200_acb_iface *scx200_acb_list; 374static struct scx200_acb_iface *scx200_acb_list;
375static DECLARE_MUTEX(scx200_acb_list_mutex);
403 376
404static int scx200_acb_probe(struct scx200_acb_iface *iface) 377static int scx200_acb_probe(struct scx200_acb_iface *iface)
405{ 378{
406 u8 val; 379 u8 val;
407 380
408 /* Disable the ACCESS.bus device and Configure the SCL 381 /* Disable the ACCESS.bus device and Configure the SCL
409 frequency: 16 clock cycles */ 382 frequency: 16 clock cycles */
410 outb(0x70, ACBCTL2); 383 outb(0x70, ACBCTL2);
411 384
412 if (inb(ACBCTL2) != 0x70) { 385 if (inb(ACBCTL2) != 0x70) {
413 DBG("ACBCTL2 readback failed\n"); 386 pr_debug(NAME ": ACBCTL2 readback failed\n");
414 return -ENXIO; 387 return -ENXIO;
415 } 388 }
416 389
@@ -418,7 +391,8 @@ static int scx200_acb_probe(struct scx200_acb_iface *iface)
418 391
419 val = inb(ACBCTL1); 392 val = inb(ACBCTL1);
420 if (val) { 393 if (val) {
421 DBG("disabled, but ACBCTL1=0x%02x\n", val); 394 pr_debug(NAME ": disabled, but ACBCTL1=0x%02x\n",
395 val);
422 return -ENXIO; 396 return -ENXIO;
423 } 397 }
424 398
@@ -428,18 +402,19 @@ static int scx200_acb_probe(struct scx200_acb_iface *iface)
428 402
429 val = inb(ACBCTL1); 403 val = inb(ACBCTL1);
430 if ((val & ACBCTL1_NMINTE) != ACBCTL1_NMINTE) { 404 if ((val & ACBCTL1_NMINTE) != ACBCTL1_NMINTE) {
431 DBG("enabled, but NMINTE won't be set, ACBCTL1=0x%02x\n", val); 405 pr_debug(NAME ": enabled, but NMINTE won't be set, "
406 "ACBCTL1=0x%02x\n", val);
432 return -ENXIO; 407 return -ENXIO;
433 } 408 }
434 409
435 return 0; 410 return 0;
436} 411}
437 412
438static int __init scx200_acb_create(int base, int index) 413static int __init scx200_acb_create(const char *text, int base, int index)
439{ 414{
440 struct scx200_acb_iface *iface; 415 struct scx200_acb_iface *iface;
441 struct i2c_adapter *adapter; 416 struct i2c_adapter *adapter;
442 int rc = 0; 417 int rc;
443 char description[64]; 418 char description[64];
444 419
445 iface = kzalloc(sizeof(*iface), GFP_KERNEL); 420 iface = kzalloc(sizeof(*iface), GFP_KERNEL);
@@ -451,50 +426,51 @@ static int __init scx200_acb_create(int base, int index)
451 426
452 adapter = &iface->adapter; 427 adapter = &iface->adapter;
453 i2c_set_adapdata(adapter, iface); 428 i2c_set_adapdata(adapter, iface);
454 snprintf(adapter->name, I2C_NAME_SIZE, "SCx200 ACB%d", index); 429 snprintf(adapter->name, I2C_NAME_SIZE, "%s ACB%d", text, index);
455 adapter->owner = THIS_MODULE; 430 adapter->owner = THIS_MODULE;
456 adapter->id = I2C_HW_SMBUS_SCX200; 431 adapter->id = I2C_HW_SMBUS_SCX200;
457 adapter->algo = &scx200_acb_algorithm; 432 adapter->algo = &scx200_acb_algorithm;
458 adapter->class = I2C_CLASS_HWMON; 433 adapter->class = I2C_CLASS_HWMON;
459 434
460 init_MUTEX(&iface->sem); 435 mutex_init(&iface->mutex);
436
437 snprintf(description, sizeof(description), "%s ACCESS.bus [%s]",
438 text, adapter->name);
461 439
462 snprintf(description, sizeof(description), "NatSemi SCx200 ACCESS.bus [%s]", adapter->name);
463 if (request_region(base, 8, description) == 0) { 440 if (request_region(base, 8, description) == 0) {
464 dev_err(&adapter->dev, "can't allocate io 0x%x-0x%x\n", 441 printk(KERN_ERR NAME ": can't allocate io 0x%x-0x%x\n",
465 base, base + 8-1); 442 base, base + 8-1);
466 rc = -EBUSY; 443 rc = -EBUSY;
467 goto errout; 444 goto errout_free;
468 } 445 }
469 iface->base = base; 446 iface->base = base;
470 447
471 rc = scx200_acb_probe(iface); 448 rc = scx200_acb_probe(iface);
472 if (rc) { 449 if (rc) {
473 dev_warn(&adapter->dev, "probe failed\n"); 450 printk(KERN_WARNING NAME ": probe failed\n");
474 goto errout; 451 goto errout_release;
475 } 452 }
476 453
477 scx200_acb_reset(iface); 454 scx200_acb_reset(iface);
478 455
479 if (i2c_add_adapter(adapter) < 0) { 456 if (i2c_add_adapter(adapter) < 0) {
480 dev_err(&adapter->dev, "failed to register\n"); 457 printk(KERN_ERR NAME ": failed to register\n");
481 rc = -ENODEV; 458 rc = -ENODEV;
482 goto errout; 459 goto errout_release;
483 } 460 }
484 461
485 lock_kernel(); 462 down(&scx200_acb_list_mutex);
486 iface->next = scx200_acb_list; 463 iface->next = scx200_acb_list;
487 scx200_acb_list = iface; 464 scx200_acb_list = iface;
488 unlock_kernel(); 465 up(&scx200_acb_list_mutex);
489 466
490 return 0; 467 return 0;
491 468
469 errout_release:
470 release_region(iface->base, 8);
471 errout_free:
472 kfree(iface);
492 errout: 473 errout:
493 if (iface) {
494 if (iface->base)
495 release_region(iface->base, 8);
496 kfree(iface);
497 }
498 return rc; 474 return rc;
499} 475}
500 476
@@ -504,50 +480,69 @@ static struct pci_device_id scx200[] = {
504 { }, 480 { },
505}; 481};
506 482
483static struct pci_device_id divil_pci[] = {
484 { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_CS5535_ISA) },
485 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_CS5536_ISA) },
486 { } /* NULL entry */
487};
488
489#define MSR_LBAR_SMB 0x5140000B
490
491static int scx200_add_cs553x(void)
492{
493 u32 low, hi;
494 u32 smb_base;
495
496 /* Grab & reserve the SMB I/O range */
497 rdmsr(MSR_LBAR_SMB, low, hi);
498
499 /* Check the IO mask and whether SMB is enabled */
500 if (hi != 0x0000F001) {
501 printk(KERN_WARNING NAME ": SMBus not enabled\n");
502 return -ENODEV;
503 }
504
505 /* SMBus IO size is 8 bytes */
506 smb_base = low & 0x0000FFF8;
507
508 return scx200_acb_create("CS5535", smb_base, 0);
509}
510
507static int __init scx200_acb_init(void) 511static int __init scx200_acb_init(void)
508{ 512{
509 int i; 513 int i;
510 int rc; 514 int rc = -ENODEV;
511 515
512 pr_debug(NAME ": NatSemi SCx200 ACCESS.bus Driver\n"); 516 pr_debug(NAME ": NatSemi SCx200 ACCESS.bus Driver\n");
513 517
514 /* Verify that this really is a SCx200 processor */ 518 /* Verify that this really is a SCx200 processor */
515 if (pci_dev_present(scx200) == 0) 519 if (pci_dev_present(scx200)) {
516 return -ENODEV; 520 for (i = 0; i < MAX_DEVICES; ++i) {
521 if (base[i] > 0)
522 rc = scx200_acb_create("SCx200", base[i], i);
523 }
524 } else if (pci_dev_present(divil_pci))
525 rc = scx200_add_cs553x();
517 526
518 rc = -ENXIO;
519 for (i = 0; i < MAX_DEVICES; ++i) {
520 if (base[i] > 0)
521 rc = scx200_acb_create(base[i], i);
522 }
523 if (scx200_acb_list)
524 return 0;
525 return rc; 527 return rc;
526} 528}
527 529
528static void __exit scx200_acb_cleanup(void) 530static void __exit scx200_acb_cleanup(void)
529{ 531{
530 struct scx200_acb_iface *iface; 532 struct scx200_acb_iface *iface;
531 lock_kernel(); 533
534 down(&scx200_acb_list_mutex);
532 while ((iface = scx200_acb_list) != NULL) { 535 while ((iface = scx200_acb_list) != NULL) {
533 scx200_acb_list = iface->next; 536 scx200_acb_list = iface->next;
534 unlock_kernel(); 537 up(&scx200_acb_list_mutex);
535 538
536 i2c_del_adapter(&iface->adapter); 539 i2c_del_adapter(&iface->adapter);
537 release_region(iface->base, 8); 540 release_region(iface->base, 8);
538 kfree(iface); 541 kfree(iface);
539 lock_kernel(); 542 down(&scx200_acb_list_mutex);
540 } 543 }
541 unlock_kernel(); 544 up(&scx200_acb_list_mutex);
542} 545}
543 546
544module_init(scx200_acb_init); 547module_init(scx200_acb_init);
545module_exit(scx200_acb_cleanup); 548module_exit(scx200_acb_cleanup);
546
547/*
548 Local variables:
549 compile-command: "make -k -C ../.. SUBDIRS=drivers/i2c modules"
550 c-basic-offset: 8
551 End:
552*/
553
diff --git a/drivers/i2c/chips/ds1374.c b/drivers/i2c/chips/ds1374.c
index 0710b9da9d..03d09ed5ec 100644
--- a/drivers/i2c/chips/ds1374.c
+++ b/drivers/i2c/chips/ds1374.c
@@ -26,6 +26,7 @@
26#include <linux/i2c.h> 26#include <linux/i2c.h>
27#include <linux/rtc.h> 27#include <linux/rtc.h>
28#include <linux/bcd.h> 28#include <linux/bcd.h>
29#include <linux/mutex.h>
29 30
30#define DS1374_REG_TOD0 0x00 31#define DS1374_REG_TOD0 0x00
31#define DS1374_REG_TOD1 0x01 32#define DS1374_REG_TOD1 0x01
@@ -41,7 +42,7 @@
41 42
42#define DS1374_DRV_NAME "ds1374" 43#define DS1374_DRV_NAME "ds1374"
43 44
44static DECLARE_MUTEX(ds1374_mutex); 45static DEFINE_MUTEX(ds1374_mutex);
45 46
46static struct i2c_driver ds1374_driver; 47static struct i2c_driver ds1374_driver;
47static struct i2c_client *save_client; 48static struct i2c_client *save_client;
@@ -114,7 +115,7 @@ ulong ds1374_get_rtc_time(void)
114 ulong t1, t2; 115 ulong t1, t2;
115 int limit = 10; /* arbitrary retry limit */ 116 int limit = 10; /* arbitrary retry limit */
116 117
117 down(&ds1374_mutex); 118 mutex_lock(&ds1374_mutex);
118 119
119 /* 120 /*
120 * Since the reads are being performed one byte at a time using 121 * Since the reads are being performed one byte at a time using
@@ -127,7 +128,7 @@ ulong ds1374_get_rtc_time(void)
127 t2 = ds1374_read_rtc(); 128 t2 = ds1374_read_rtc();
128 } while (t1 != t2 && limit--); 129 } while (t1 != t2 && limit--);
129 130
130 up(&ds1374_mutex); 131 mutex_unlock(&ds1374_mutex);
131 132
132 if (t1 != t2) { 133 if (t1 != t2) {
133 dev_warn(&save_client->dev, 134 dev_warn(&save_client->dev,
@@ -145,7 +146,7 @@ static void ds1374_set_tlet(ulong arg)
145 146
146 t1 = *(ulong *) arg; 147 t1 = *(ulong *) arg;
147 148
148 down(&ds1374_mutex); 149 mutex_lock(&ds1374_mutex);
149 150
150 /* 151 /*
151 * Since the writes are being performed one byte at a time using 152 * Since the writes are being performed one byte at a time using
@@ -158,7 +159,7 @@ static void ds1374_set_tlet(ulong arg)
158 t2 = ds1374_read_rtc(); 159 t2 = ds1374_read_rtc();
159 } while (t1 != t2 && limit--); 160 } while (t1 != t2 && limit--);
160 161
161 up(&ds1374_mutex); 162 mutex_unlock(&ds1374_mutex);
162 163
163 if (t1 != t2) 164 if (t1 != t2)
164 dev_warn(&save_client->dev, 165 dev_warn(&save_client->dev,
diff --git a/drivers/i2c/chips/eeprom.c b/drivers/i2c/chips/eeprom.c
index 41116b7947..13c108269a 100644
--- a/drivers/i2c/chips/eeprom.c
+++ b/drivers/i2c/chips/eeprom.c
@@ -33,6 +33,7 @@
33#include <linux/sched.h> 33#include <linux/sched.h>
34#include <linux/jiffies.h> 34#include <linux/jiffies.h>
35#include <linux/i2c.h> 35#include <linux/i2c.h>
36#include <linux/mutex.h>
36 37
37/* Addresses to scan */ 38/* Addresses to scan */
38static unsigned short normal_i2c[] = { 0x50, 0x51, 0x52, 0x53, 0x54, 39static unsigned short normal_i2c[] = { 0x50, 0x51, 0x52, 0x53, 0x54,
@@ -54,7 +55,7 @@ enum eeprom_nature {
54/* Each client has this additional data */ 55/* Each client has this additional data */
55struct eeprom_data { 56struct eeprom_data {
56 struct i2c_client client; 57 struct i2c_client client;
57 struct semaphore update_lock; 58 struct mutex update_lock;
58 u8 valid; /* bitfield, bit!=0 if slice is valid */ 59 u8 valid; /* bitfield, bit!=0 if slice is valid */
59 unsigned long last_updated[8]; /* In jiffies, 8 slices */ 60 unsigned long last_updated[8]; /* In jiffies, 8 slices */
60 u8 data[EEPROM_SIZE]; /* Register values */ 61 u8 data[EEPROM_SIZE]; /* Register values */
@@ -81,7 +82,7 @@ static void eeprom_update_client(struct i2c_client *client, u8 slice)
81 struct eeprom_data *data = i2c_get_clientdata(client); 82 struct eeprom_data *data = i2c_get_clientdata(client);
82 int i, j; 83 int i, j;
83 84
84 down(&data->update_lock); 85 mutex_lock(&data->update_lock);
85 86
86 if (!(data->valid & (1 << slice)) || 87 if (!(data->valid & (1 << slice)) ||
87 time_after(jiffies, data->last_updated[slice] + 300 * HZ)) { 88 time_after(jiffies, data->last_updated[slice] + 300 * HZ)) {
@@ -107,7 +108,7 @@ static void eeprom_update_client(struct i2c_client *client, u8 slice)
107 data->valid |= (1 << slice); 108 data->valid |= (1 << slice);
108 } 109 }
109exit: 110exit:
110 up(&data->update_lock); 111 mutex_unlock(&data->update_lock);
111} 112}
112 113
113static ssize_t eeprom_read(struct kobject *kobj, char *buf, loff_t off, size_t count) 114static ssize_t eeprom_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
@@ -187,7 +188,7 @@ static int eeprom_detect(struct i2c_adapter *adapter, int address, int kind)
187 /* Fill in the remaining client fields */ 188 /* Fill in the remaining client fields */
188 strlcpy(new_client->name, "eeprom", I2C_NAME_SIZE); 189 strlcpy(new_client->name, "eeprom", I2C_NAME_SIZE);
189 data->valid = 0; 190 data->valid = 0;
190 init_MUTEX(&data->update_lock); 191 mutex_init(&data->update_lock);
191 data->nature = UNKNOWN; 192 data->nature = UNKNOWN;
192 193
193 /* Tell the I2C layer a new client has arrived */ 194 /* Tell the I2C layer a new client has arrived */
diff --git a/drivers/i2c/chips/isp1301_omap.c b/drivers/i2c/chips/isp1301_omap.c
index 1251c7fc18..e6f1ab7b91 100644
--- a/drivers/i2c/chips/isp1301_omap.c
+++ b/drivers/i2c/chips/isp1301_omap.c
@@ -1635,8 +1635,6 @@ static struct i2c_driver isp1301_driver = {
1635 .driver = { 1635 .driver = {
1636 .name = "isp1301_omap", 1636 .name = "isp1301_omap",
1637 }, 1637 },
1638 .id = 1301, /* FIXME "official", i2c-ids.h */
1639 .class = I2C_CLASS_HWMON,
1640 .attach_adapter = isp1301_scan_bus, 1638 .attach_adapter = isp1301_scan_bus,
1641 .detach_client = isp1301_detach_client, 1639 .detach_client = isp1301_detach_client,
1642}; 1640};
diff --git a/drivers/i2c/chips/m41t00.c b/drivers/i2c/chips/m41t00.c
index 2dc3d48375..b5aabe7cf7 100644
--- a/drivers/i2c/chips/m41t00.c
+++ b/drivers/i2c/chips/m41t00.c
@@ -24,13 +24,14 @@
24#include <linux/i2c.h> 24#include <linux/i2c.h>
25#include <linux/rtc.h> 25#include <linux/rtc.h>
26#include <linux/bcd.h> 26#include <linux/bcd.h>
27#include <linux/mutex.h>
27 28
28#include <asm/time.h> 29#include <asm/time.h>
29#include <asm/rtc.h> 30#include <asm/rtc.h>
30 31
31#define M41T00_DRV_NAME "m41t00" 32#define M41T00_DRV_NAME "m41t00"
32 33
33static DECLARE_MUTEX(m41t00_mutex); 34static DEFINE_MUTEX(m41t00_mutex);
34 35
35static struct i2c_driver m41t00_driver; 36static struct i2c_driver m41t00_driver;
36static struct i2c_client *save_client; 37static struct i2c_client *save_client;
@@ -54,7 +55,7 @@ m41t00_get_rtc_time(void)
54 sec = min = hour = day = mon = year = 0; 55 sec = min = hour = day = mon = year = 0;
55 sec1 = min1 = hour1 = day1 = mon1 = year1 = 0; 56 sec1 = min1 = hour1 = day1 = mon1 = year1 = 0;
56 57
57 down(&m41t00_mutex); 58 mutex_lock(&m41t00_mutex);
58 do { 59 do {
59 if (((sec = i2c_smbus_read_byte_data(save_client, 0)) >= 0) 60 if (((sec = i2c_smbus_read_byte_data(save_client, 0)) >= 0)
60 && ((min = i2c_smbus_read_byte_data(save_client, 1)) 61 && ((min = i2c_smbus_read_byte_data(save_client, 1))
@@ -80,7 +81,7 @@ m41t00_get_rtc_time(void)
80 mon1 = mon; 81 mon1 = mon;
81 year1 = year; 82 year1 = year;
82 } while (--limit > 0); 83 } while (--limit > 0);
83 up(&m41t00_mutex); 84 mutex_unlock(&m41t00_mutex);
84 85
85 if (limit == 0) { 86 if (limit == 0) {
86 dev_warn(&save_client->dev, 87 dev_warn(&save_client->dev,
@@ -125,7 +126,7 @@ m41t00_set_tlet(ulong arg)
125 BIN_TO_BCD(tm.tm_mday); 126 BIN_TO_BCD(tm.tm_mday);
126 BIN_TO_BCD(tm.tm_year); 127 BIN_TO_BCD(tm.tm_year);
127 128
128 down(&m41t00_mutex); 129 mutex_lock(&m41t00_mutex);
129 if ((i2c_smbus_write_byte_data(save_client, 0, tm.tm_sec & 0x7f) < 0) 130 if ((i2c_smbus_write_byte_data(save_client, 0, tm.tm_sec & 0x7f) < 0)
130 || (i2c_smbus_write_byte_data(save_client, 1, tm.tm_min & 0x7f) 131 || (i2c_smbus_write_byte_data(save_client, 1, tm.tm_min & 0x7f)
131 < 0) 132 < 0)
@@ -140,7 +141,7 @@ m41t00_set_tlet(ulong arg)
140 141
141 dev_warn(&save_client->dev,"m41t00: can't write to rtc chip\n"); 142 dev_warn(&save_client->dev,"m41t00: can't write to rtc chip\n");
142 143
143 up(&m41t00_mutex); 144 mutex_unlock(&m41t00_mutex);
144 return; 145 return;
145} 146}
146 147
diff --git a/drivers/i2c/chips/max6875.c b/drivers/i2c/chips/max6875.c
index 6d3ff58415..88d2ddee44 100644
--- a/drivers/i2c/chips/max6875.c
+++ b/drivers/i2c/chips/max6875.c
@@ -31,7 +31,7 @@
31#include <linux/module.h> 31#include <linux/module.h>
32#include <linux/slab.h> 32#include <linux/slab.h>
33#include <linux/i2c.h> 33#include <linux/i2c.h>
34#include <asm/semaphore.h> 34#include <linux/mutex.h>
35 35
36/* Do not scan - the MAX6875 access method will write to some EEPROM chips */ 36/* Do not scan - the MAX6875 access method will write to some EEPROM chips */
37static unsigned short normal_i2c[] = {I2C_CLIENT_END}; 37static unsigned short normal_i2c[] = {I2C_CLIENT_END};
@@ -54,7 +54,7 @@ I2C_CLIENT_INSMOD_1(max6875);
54/* Each client has this additional data */ 54/* Each client has this additional data */
55struct max6875_data { 55struct max6875_data {
56 struct i2c_client client; 56 struct i2c_client client;
57 struct semaphore update_lock; 57 struct mutex update_lock;
58 58
59 u32 valid; 59 u32 valid;
60 u8 data[USER_EEPROM_SIZE]; 60 u8 data[USER_EEPROM_SIZE];
@@ -83,7 +83,7 @@ static void max6875_update_slice(struct i2c_client *client, int slice)
83 if (slice >= USER_EEPROM_SLICES) 83 if (slice >= USER_EEPROM_SLICES)
84 return; 84 return;
85 85
86 down(&data->update_lock); 86 mutex_lock(&data->update_lock);
87 87
88 buf = &data->data[slice << SLICE_BITS]; 88 buf = &data->data[slice << SLICE_BITS];
89 89
@@ -122,7 +122,7 @@ static void max6875_update_slice(struct i2c_client *client, int slice)
122 data->valid |= (1 << slice); 122 data->valid |= (1 << slice);
123 } 123 }
124exit_up: 124exit_up:
125 up(&data->update_lock); 125 mutex_unlock(&data->update_lock);
126} 126}
127 127
128static ssize_t max6875_read(struct kobject *kobj, char *buf, loff_t off, 128static ssize_t max6875_read(struct kobject *kobj, char *buf, loff_t off,
@@ -196,7 +196,7 @@ static int max6875_detect(struct i2c_adapter *adapter, int address, int kind)
196 real_client->driver = &max6875_driver; 196 real_client->driver = &max6875_driver;
197 real_client->flags = 0; 197 real_client->flags = 0;
198 strlcpy(real_client->name, "max6875", I2C_NAME_SIZE); 198 strlcpy(real_client->name, "max6875", I2C_NAME_SIZE);
199 init_MUTEX(&data->update_lock); 199 mutex_init(&data->update_lock);
200 200
201 /* Init fake client data */ 201 /* Init fake client data */
202 /* set the client data to the i2c_client so that it will get freed */ 202 /* set the client data to the i2c_client so that it will get freed */
diff --git a/drivers/i2c/chips/pcf8591.c b/drivers/i2c/chips/pcf8591.c
index 36cff09c67..925a6b371f 100644
--- a/drivers/i2c/chips/pcf8591.c
+++ b/drivers/i2c/chips/pcf8591.c
@@ -24,6 +24,7 @@
24#include <linux/init.h> 24#include <linux/init.h>
25#include <linux/slab.h> 25#include <linux/slab.h>
26#include <linux/i2c.h> 26#include <linux/i2c.h>
27#include <linux/mutex.h>
27 28
28/* Addresses to scan */ 29/* Addresses to scan */
29static unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, 0x4c, 30static unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, 0x4c,
@@ -74,7 +75,7 @@ MODULE_PARM_DESC(input_mode,
74 75
75struct pcf8591_data { 76struct pcf8591_data {
76 struct i2c_client client; 77 struct i2c_client client;
77 struct semaphore update_lock; 78 struct mutex update_lock;
78 79
79 u8 control; 80 u8 control;
80 u8 aout; 81 u8 aout;
@@ -144,13 +145,13 @@ static ssize_t set_out0_enable(struct device *dev, struct device_attribute *attr
144 struct pcf8591_data *data = i2c_get_clientdata(client); 145 struct pcf8591_data *data = i2c_get_clientdata(client);
145 unsigned long val = simple_strtoul(buf, NULL, 10); 146 unsigned long val = simple_strtoul(buf, NULL, 10);
146 147
147 down(&data->update_lock); 148 mutex_lock(&data->update_lock);
148 if (val) 149 if (val)
149 data->control |= PCF8591_CONTROL_AOEF; 150 data->control |= PCF8591_CONTROL_AOEF;
150 else 151 else
151 data->control &= ~PCF8591_CONTROL_AOEF; 152 data->control &= ~PCF8591_CONTROL_AOEF;
152 i2c_smbus_write_byte(client, data->control); 153 i2c_smbus_write_byte(client, data->control);
153 up(&data->update_lock); 154 mutex_unlock(&data->update_lock);
154 return count; 155 return count;
155} 156}
156 157
@@ -200,7 +201,7 @@ static int pcf8591_detect(struct i2c_adapter *adapter, int address, int kind)
200 /* Fill in the remaining client fields and put it into the global 201 /* Fill in the remaining client fields and put it into the global
201 list */ 202 list */
202 strlcpy(new_client->name, "pcf8591", I2C_NAME_SIZE); 203 strlcpy(new_client->name, "pcf8591", I2C_NAME_SIZE);
203 init_MUTEX(&data->update_lock); 204 mutex_init(&data->update_lock);
204 205
205 /* Tell the I2C layer a new client has arrived */ 206 /* Tell the I2C layer a new client has arrived */
206 if ((err = i2c_attach_client(new_client))) 207 if ((err = i2c_attach_client(new_client)))
@@ -265,7 +266,7 @@ static int pcf8591_read_channel(struct device *dev, int channel)
265 struct i2c_client *client = to_i2c_client(dev); 266 struct i2c_client *client = to_i2c_client(dev);
266 struct pcf8591_data *data = i2c_get_clientdata(client); 267 struct pcf8591_data *data = i2c_get_clientdata(client);
267 268
268 down(&data->update_lock); 269 mutex_lock(&data->update_lock);
269 270
270 if ((data->control & PCF8591_CONTROL_AICH_MASK) != channel) { 271 if ((data->control & PCF8591_CONTROL_AICH_MASK) != channel) {
271 data->control = (data->control & ~PCF8591_CONTROL_AICH_MASK) 272 data->control = (data->control & ~PCF8591_CONTROL_AICH_MASK)
@@ -278,7 +279,7 @@ static int pcf8591_read_channel(struct device *dev, int channel)
278 } 279 }
279 value = i2c_smbus_read_byte(client); 280 value = i2c_smbus_read_byte(client);
280 281
281 up(&data->update_lock); 282 mutex_unlock(&data->update_lock);
282 283
283 if ((channel == 2 && input_mode == 2) || 284 if ((channel == 2 && input_mode == 2) ||
284 (channel != 3 && (input_mode == 1 || input_mode == 3))) 285 (channel != 3 && (input_mode == 1 || input_mode == 3)))
diff --git a/drivers/i2c/chips/rtc8564.c b/drivers/i2c/chips/rtc8564.c
index ceaa6b0bdf..0d8699b3f4 100644
--- a/drivers/i2c/chips/rtc8564.c
+++ b/drivers/i2c/chips/rtc8564.c
@@ -53,7 +53,7 @@ static inline u8 _rtc8564_ctrl2(struct i2c_client *client)
53#define CTRL1(c) _rtc8564_ctrl1(c) 53#define CTRL1(c) _rtc8564_ctrl1(c)
54#define CTRL2(c) _rtc8564_ctrl2(c) 54#define CTRL2(c) _rtc8564_ctrl2(c)
55 55
56static int debug;; 56static int debug;
57module_param(debug, int, S_IRUGO | S_IWUSR); 57module_param(debug, int, S_IRUGO | S_IWUSR);
58 58
59static struct i2c_driver rtc8564_driver; 59static struct i2c_driver rtc8564_driver;
diff --git a/drivers/i2c/chips/tps65010.c b/drivers/i2c/chips/tps65010.c
index 1af3dfbb80..179b1e022d 100644
--- a/drivers/i2c/chips/tps65010.c
+++ b/drivers/i2c/chips/tps65010.c
@@ -32,6 +32,7 @@
32#include <linux/suspend.h> 32#include <linux/suspend.h>
33#include <linux/debugfs.h> 33#include <linux/debugfs.h>
34#include <linux/seq_file.h> 34#include <linux/seq_file.h>
35#include <linux/mutex.h>
35 36
36#include <asm/irq.h> 37#include <asm/irq.h>
37#include <asm/mach-types.h> 38#include <asm/mach-types.h>
@@ -81,7 +82,7 @@ enum tps_model {
81 82
82struct tps65010 { 83struct tps65010 {
83 struct i2c_client client; 84 struct i2c_client client;
84 struct semaphore lock; 85 struct mutex lock;
85 int irq; 86 int irq;
86 struct work_struct work; 87 struct work_struct work;
87 struct dentry *file; 88 struct dentry *file;
@@ -218,7 +219,7 @@ static int dbg_show(struct seq_file *s, void *_)
218 seq_printf(s, "driver %s\nversion %s\nchip %s\n\n", 219 seq_printf(s, "driver %s\nversion %s\nchip %s\n\n",
219 DRIVER_NAME, DRIVER_VERSION, chip); 220 DRIVER_NAME, DRIVER_VERSION, chip);
220 221
221 down(&tps->lock); 222 mutex_lock(&tps->lock);
222 223
223 /* FIXME how can we tell whether a battery is present? 224 /* FIXME how can we tell whether a battery is present?
224 * likely involves a charge gauging chip (like BQ26501). 225 * likely involves a charge gauging chip (like BQ26501).
@@ -300,7 +301,7 @@ static int dbg_show(struct seq_file *s, void *_)
300 (v2 & (1 << (4 + i))) ? "rising" : "falling"); 301 (v2 & (1 << (4 + i))) ? "rising" : "falling");
301 } 302 }
302 303
303 up(&tps->lock); 304 mutex_unlock(&tps->lock);
304 return 0; 305 return 0;
305} 306}
306 307
@@ -416,7 +417,7 @@ static void tps65010_work(void *_tps)
416{ 417{
417 struct tps65010 *tps = _tps; 418 struct tps65010 *tps = _tps;
418 419
419 down(&tps->lock); 420 mutex_lock(&tps->lock);
420 421
421 tps65010_interrupt(tps); 422 tps65010_interrupt(tps);
422 423
@@ -444,7 +445,7 @@ static void tps65010_work(void *_tps)
444 if (test_and_clear_bit(FLAG_IRQ_ENABLE, &tps->flags)) 445 if (test_and_clear_bit(FLAG_IRQ_ENABLE, &tps->flags))
445 enable_irq(tps->irq); 446 enable_irq(tps->irq);
446 447
447 up(&tps->lock); 448 mutex_unlock(&tps->lock);
448} 449}
449 450
450static irqreturn_t tps65010_irq(int irq, void *_tps, struct pt_regs *regs) 451static irqreturn_t tps65010_irq(int irq, void *_tps, struct pt_regs *regs)
@@ -505,7 +506,7 @@ tps65010_probe(struct i2c_adapter *bus, int address, int kind)
505 if (!tps) 506 if (!tps)
506 return 0; 507 return 0;
507 508
508 init_MUTEX(&tps->lock); 509 mutex_init(&tps->lock);
509 INIT_WORK(&tps->work, tps65010_work, tps); 510 INIT_WORK(&tps->work, tps65010_work, tps);
510 tps->irq = -1; 511 tps->irq = -1;
511 tps->client.addr = address; 512 tps->client.addr = address;
@@ -695,7 +696,7 @@ int tps65010_set_gpio_out_value(unsigned gpio, unsigned value)
695 if ((gpio < GPIO1) || (gpio > GPIO4)) 696 if ((gpio < GPIO1) || (gpio > GPIO4))
696 return -EINVAL; 697 return -EINVAL;
697 698
698 down(&the_tps->lock); 699 mutex_lock(&the_tps->lock);
699 700
700 defgpio = i2c_smbus_read_byte_data(&the_tps->client, TPS_DEFGPIO); 701 defgpio = i2c_smbus_read_byte_data(&the_tps->client, TPS_DEFGPIO);
701 702
@@ -720,7 +721,7 @@ int tps65010_set_gpio_out_value(unsigned gpio, unsigned value)
720 gpio, value ? "high" : "low", 721 gpio, value ? "high" : "low",
721 i2c_smbus_read_byte_data(&the_tps->client, TPS_DEFGPIO)); 722 i2c_smbus_read_byte_data(&the_tps->client, TPS_DEFGPIO));
722 723
723 up(&the_tps->lock); 724 mutex_unlock(&the_tps->lock);
724 return status; 725 return status;
725} 726}
726EXPORT_SYMBOL(tps65010_set_gpio_out_value); 727EXPORT_SYMBOL(tps65010_set_gpio_out_value);
@@ -745,7 +746,7 @@ int tps65010_set_led(unsigned led, unsigned mode)
745 led = LED2; 746 led = LED2;
746 } 747 }
747 748
748 down(&the_tps->lock); 749 mutex_lock(&the_tps->lock);
749 750
750 pr_debug("%s: led%i_on 0x%02x\n", DRIVER_NAME, led, 751 pr_debug("%s: led%i_on 0x%02x\n", DRIVER_NAME, led,
751 i2c_smbus_read_byte_data(&the_tps->client, 752 i2c_smbus_read_byte_data(&the_tps->client,
@@ -771,7 +772,7 @@ int tps65010_set_led(unsigned led, unsigned mode)
771 default: 772 default:
772 printk(KERN_ERR "%s: Wrong mode parameter for set_led()\n", 773 printk(KERN_ERR "%s: Wrong mode parameter for set_led()\n",
773 DRIVER_NAME); 774 DRIVER_NAME);
774 up(&the_tps->lock); 775 mutex_unlock(&the_tps->lock);
775 return -EINVAL; 776 return -EINVAL;
776 } 777 }
777 778
@@ -781,7 +782,7 @@ int tps65010_set_led(unsigned led, unsigned mode)
781 if (status != 0) { 782 if (status != 0) {
782 printk(KERN_ERR "%s: Failed to write led%i_on register\n", 783 printk(KERN_ERR "%s: Failed to write led%i_on register\n",
783 DRIVER_NAME, led); 784 DRIVER_NAME, led);
784 up(&the_tps->lock); 785 mutex_unlock(&the_tps->lock);
785 return status; 786 return status;
786 } 787 }
787 788
@@ -794,7 +795,7 @@ int tps65010_set_led(unsigned led, unsigned mode)
794 if (status != 0) { 795 if (status != 0) {
795 printk(KERN_ERR "%s: Failed to write led%i_per register\n", 796 printk(KERN_ERR "%s: Failed to write led%i_per register\n",
796 DRIVER_NAME, led); 797 DRIVER_NAME, led);
797 up(&the_tps->lock); 798 mutex_unlock(&the_tps->lock);
798 return status; 799 return status;
799 } 800 }
800 801
@@ -802,7 +803,7 @@ int tps65010_set_led(unsigned led, unsigned mode)
802 i2c_smbus_read_byte_data(&the_tps->client, 803 i2c_smbus_read_byte_data(&the_tps->client,
803 TPS_LED1_PER + offs)); 804 TPS_LED1_PER + offs));
804 805
805 up(&the_tps->lock); 806 mutex_unlock(&the_tps->lock);
806 807
807 return status; 808 return status;
808} 809}
@@ -820,7 +821,7 @@ int tps65010_set_vib(unsigned value)
820 if (!the_tps) 821 if (!the_tps)
821 return -ENODEV; 822 return -ENODEV;
822 823
823 down(&the_tps->lock); 824 mutex_lock(&the_tps->lock);
824 825
825 vdcdc2 = i2c_smbus_read_byte_data(&the_tps->client, TPS_VDCDC2); 826 vdcdc2 = i2c_smbus_read_byte_data(&the_tps->client, TPS_VDCDC2);
826 vdcdc2 &= ~(1 << 1); 827 vdcdc2 &= ~(1 << 1);
@@ -831,7 +832,7 @@ int tps65010_set_vib(unsigned value)
831 832
832 pr_debug("%s: vibrator %s\n", DRIVER_NAME, value ? "on" : "off"); 833 pr_debug("%s: vibrator %s\n", DRIVER_NAME, value ? "on" : "off");
833 834
834 up(&the_tps->lock); 835 mutex_unlock(&the_tps->lock);
835 return status; 836 return status;
836} 837}
837EXPORT_SYMBOL(tps65010_set_vib); 838EXPORT_SYMBOL(tps65010_set_vib);
@@ -848,7 +849,7 @@ int tps65010_set_low_pwr(unsigned mode)
848 if (!the_tps) 849 if (!the_tps)
849 return -ENODEV; 850 return -ENODEV;
850 851
851 down(&the_tps->lock); 852 mutex_lock(&the_tps->lock);
852 853
853 pr_debug("%s: %s low_pwr, vdcdc1 0x%02x\n", DRIVER_NAME, 854 pr_debug("%s: %s low_pwr, vdcdc1 0x%02x\n", DRIVER_NAME,
854 mode ? "enable" : "disable", 855 mode ? "enable" : "disable",
@@ -876,7 +877,7 @@ int tps65010_set_low_pwr(unsigned mode)
876 pr_debug("%s: vdcdc1 0x%02x\n", DRIVER_NAME, 877 pr_debug("%s: vdcdc1 0x%02x\n", DRIVER_NAME,
877 i2c_smbus_read_byte_data(&the_tps->client, TPS_VDCDC1)); 878 i2c_smbus_read_byte_data(&the_tps->client, TPS_VDCDC1));
878 879
879 up(&the_tps->lock); 880 mutex_unlock(&the_tps->lock);
880 881
881 return status; 882 return status;
882} 883}
@@ -894,7 +895,7 @@ int tps65010_config_vregs1(unsigned value)
894 if (!the_tps) 895 if (!the_tps)
895 return -ENODEV; 896 return -ENODEV;
896 897
897 down(&the_tps->lock); 898 mutex_lock(&the_tps->lock);
898 899
899 pr_debug("%s: vregs1 0x%02x\n", DRIVER_NAME, 900 pr_debug("%s: vregs1 0x%02x\n", DRIVER_NAME,
900 i2c_smbus_read_byte_data(&the_tps->client, TPS_VREGS1)); 901 i2c_smbus_read_byte_data(&the_tps->client, TPS_VREGS1));
@@ -909,7 +910,7 @@ int tps65010_config_vregs1(unsigned value)
909 pr_debug("%s: vregs1 0x%02x\n", DRIVER_NAME, 910 pr_debug("%s: vregs1 0x%02x\n", DRIVER_NAME,
910 i2c_smbus_read_byte_data(&the_tps->client, TPS_VREGS1)); 911 i2c_smbus_read_byte_data(&the_tps->client, TPS_VREGS1));
911 912
912 up(&the_tps->lock); 913 mutex_unlock(&the_tps->lock);
913 914
914 return status; 915 return status;
915} 916}
@@ -931,7 +932,7 @@ int tps65013_set_low_pwr(unsigned mode)
931 if (!the_tps || the_tps->por) 932 if (!the_tps || the_tps->por)
932 return -ENODEV; 933 return -ENODEV;
933 934
934 down(&the_tps->lock); 935 mutex_lock(&the_tps->lock);
935 936
936 pr_debug("%s: %s low_pwr, chgconfig 0x%02x vdcdc1 0x%02x\n", 937 pr_debug("%s: %s low_pwr, chgconfig 0x%02x vdcdc1 0x%02x\n",
937 DRIVER_NAME, 938 DRIVER_NAME,
@@ -959,7 +960,7 @@ int tps65013_set_low_pwr(unsigned mode)
959 if (status != 0) { 960 if (status != 0) {
960 printk(KERN_ERR "%s: Failed to write chconfig register\n", 961 printk(KERN_ERR "%s: Failed to write chconfig register\n",
961 DRIVER_NAME); 962 DRIVER_NAME);
962 up(&the_tps->lock); 963 mutex_unlock(&the_tps->lock);
963 return status; 964 return status;
964 } 965 }
965 966
@@ -977,7 +978,7 @@ int tps65013_set_low_pwr(unsigned mode)
977 pr_debug("%s: vdcdc1 0x%02x\n", DRIVER_NAME, 978 pr_debug("%s: vdcdc1 0x%02x\n", DRIVER_NAME,
978 i2c_smbus_read_byte_data(&the_tps->client, TPS_VDCDC1)); 979 i2c_smbus_read_byte_data(&the_tps->client, TPS_VDCDC1));
979 980
980 up(&the_tps->lock); 981 mutex_unlock(&the_tps->lock);
981 982
982 return status; 983 return status;
983} 984}
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 1a2c9ab5d9..45e2cdf547 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -31,12 +31,13 @@
31#include <linux/idr.h> 31#include <linux/idr.h>
32#include <linux/seq_file.h> 32#include <linux/seq_file.h>
33#include <linux/platform_device.h> 33#include <linux/platform_device.h>
34#include <linux/mutex.h>
34#include <asm/uaccess.h> 35#include <asm/uaccess.h>
35 36
36 37
37static LIST_HEAD(adapters); 38static LIST_HEAD(adapters);
38static LIST_HEAD(drivers); 39static LIST_HEAD(drivers);
39static DECLARE_MUTEX(core_lists); 40static DEFINE_MUTEX(core_lists);
40static DEFINE_IDR(i2c_adapter_idr); 41static DEFINE_IDR(i2c_adapter_idr);
41 42
42/* match always succeeds, as we want the probe() to tell if we really accept this match */ 43/* match always succeeds, as we want the probe() to tell if we really accept this match */
@@ -153,7 +154,7 @@ int i2c_add_adapter(struct i2c_adapter *adap)
153 struct list_head *item; 154 struct list_head *item;
154 struct i2c_driver *driver; 155 struct i2c_driver *driver;
155 156
156 down(&core_lists); 157 mutex_lock(&core_lists);
157 158
158 if (idr_pre_get(&i2c_adapter_idr, GFP_KERNEL) == 0) { 159 if (idr_pre_get(&i2c_adapter_idr, GFP_KERNEL) == 0) {
159 res = -ENOMEM; 160 res = -ENOMEM;
@@ -168,8 +169,8 @@ int i2c_add_adapter(struct i2c_adapter *adap)
168 } 169 }
169 170
170 adap->nr = id & MAX_ID_MASK; 171 adap->nr = id & MAX_ID_MASK;
171 init_MUTEX(&adap->bus_lock); 172 mutex_init(&adap->bus_lock);
172 init_MUTEX(&adap->clist_lock); 173 mutex_init(&adap->clist_lock);
173 list_add_tail(&adap->list,&adapters); 174 list_add_tail(&adap->list,&adapters);
174 INIT_LIST_HEAD(&adap->clients); 175 INIT_LIST_HEAD(&adap->clients);
175 176
@@ -203,7 +204,7 @@ int i2c_add_adapter(struct i2c_adapter *adap)
203 } 204 }
204 205
205out_unlock: 206out_unlock:
206 up(&core_lists); 207 mutex_unlock(&core_lists);
207 return res; 208 return res;
208} 209}
209 210
@@ -216,7 +217,7 @@ int i2c_del_adapter(struct i2c_adapter *adap)
216 struct i2c_client *client; 217 struct i2c_client *client;
217 int res = 0; 218 int res = 0;
218 219
219 down(&core_lists); 220 mutex_lock(&core_lists);
220 221
221 /* First make sure that this adapter was ever added */ 222 /* First make sure that this adapter was ever added */
222 list_for_each_entry(adap_from_list, &adapters, list) { 223 list_for_each_entry(adap_from_list, &adapters, list) {
@@ -272,7 +273,7 @@ int i2c_del_adapter(struct i2c_adapter *adap)
272 dev_dbg(&adap->dev, "adapter [%s] unregistered\n", adap->name); 273 dev_dbg(&adap->dev, "adapter [%s] unregistered\n", adap->name);
273 274
274 out_unlock: 275 out_unlock:
275 up(&core_lists); 276 mutex_unlock(&core_lists);
276 return res; 277 return res;
277} 278}
278 279
@@ -287,9 +288,7 @@ int i2c_register_driver(struct module *owner, struct i2c_driver *driver)
287{ 288{
288 struct list_head *item; 289 struct list_head *item;
289 struct i2c_adapter *adapter; 290 struct i2c_adapter *adapter;
290 int res = 0; 291 int res;
291
292 down(&core_lists);
293 292
294 /* add the driver to the list of i2c drivers in the driver core */ 293 /* add the driver to the list of i2c drivers in the driver core */
295 driver->driver.owner = owner; 294 driver->driver.owner = owner;
@@ -297,8 +296,10 @@ int i2c_register_driver(struct module *owner, struct i2c_driver *driver)
297 296
298 res = driver_register(&driver->driver); 297 res = driver_register(&driver->driver);
299 if (res) 298 if (res)
300 goto out_unlock; 299 return res;
301 300
301 mutex_lock(&core_lists);
302
302 list_add_tail(&driver->list,&drivers); 303 list_add_tail(&driver->list,&drivers);
303 pr_debug("i2c-core: driver [%s] registered\n", driver->driver.name); 304 pr_debug("i2c-core: driver [%s] registered\n", driver->driver.name);
304 305
@@ -310,9 +311,8 @@ int i2c_register_driver(struct module *owner, struct i2c_driver *driver)
310 } 311 }
311 } 312 }
312 313
313 out_unlock: 314 mutex_unlock(&core_lists);
314 up(&core_lists); 315 return 0;
315 return res;
316} 316}
317EXPORT_SYMBOL(i2c_register_driver); 317EXPORT_SYMBOL(i2c_register_driver);
318 318
@@ -324,7 +324,7 @@ int i2c_del_driver(struct i2c_driver *driver)
324 324
325 int res = 0; 325 int res = 0;
326 326
327 down(&core_lists); 327 mutex_lock(&core_lists);
328 328
329 /* Have a look at each adapter, if clients of this driver are still 329 /* Have a look at each adapter, if clients of this driver are still
330 * attached. If so, detach them to be able to kill the driver 330 * attached. If so, detach them to be able to kill the driver
@@ -363,7 +363,7 @@ int i2c_del_driver(struct i2c_driver *driver)
363 pr_debug("i2c-core: driver [%s] unregistered\n", driver->driver.name); 363 pr_debug("i2c-core: driver [%s] unregistered\n", driver->driver.name);
364 364
365 out_unlock: 365 out_unlock:
366 up(&core_lists); 366 mutex_unlock(&core_lists);
367 return 0; 367 return 0;
368} 368}
369 369
@@ -384,9 +384,9 @@ int i2c_check_addr(struct i2c_adapter *adapter, int addr)
384{ 384{
385 int rval; 385 int rval;
386 386
387 down(&adapter->clist_lock); 387 mutex_lock(&adapter->clist_lock);
388 rval = __i2c_check_addr(adapter, addr); 388 rval = __i2c_check_addr(adapter, addr);
389 up(&adapter->clist_lock); 389 mutex_unlock(&adapter->clist_lock);
390 390
391 return rval; 391 return rval;
392} 392}
@@ -395,13 +395,13 @@ int i2c_attach_client(struct i2c_client *client)
395{ 395{
396 struct i2c_adapter *adapter = client->adapter; 396 struct i2c_adapter *adapter = client->adapter;
397 397
398 down(&adapter->clist_lock); 398 mutex_lock(&adapter->clist_lock);
399 if (__i2c_check_addr(client->adapter, client->addr)) { 399 if (__i2c_check_addr(client->adapter, client->addr)) {
400 up(&adapter->clist_lock); 400 mutex_unlock(&adapter->clist_lock);
401 return -EBUSY; 401 return -EBUSY;
402 } 402 }
403 list_add_tail(&client->list,&adapter->clients); 403 list_add_tail(&client->list,&adapter->clients);
404 up(&adapter->clist_lock); 404 mutex_unlock(&adapter->clist_lock);
405 405
406 if (adapter->client_register) { 406 if (adapter->client_register) {
407 if (adapter->client_register(client)) { 407 if (adapter->client_register(client)) {
@@ -450,12 +450,12 @@ int i2c_detach_client(struct i2c_client *client)
450 } 450 }
451 } 451 }
452 452
453 down(&adapter->clist_lock); 453 mutex_lock(&adapter->clist_lock);
454 list_del(&client->list); 454 list_del(&client->list);
455 init_completion(&client->released); 455 init_completion(&client->released);
456 device_remove_file(&client->dev, &dev_attr_client_name); 456 device_remove_file(&client->dev, &dev_attr_client_name);
457 device_unregister(&client->dev); 457 device_unregister(&client->dev);
458 up(&adapter->clist_lock); 458 mutex_unlock(&adapter->clist_lock);
459 wait_for_completion(&client->released); 459 wait_for_completion(&client->released);
460 460
461 out: 461 out:
@@ -513,19 +513,19 @@ void i2c_clients_command(struct i2c_adapter *adap, unsigned int cmd, void *arg)
513 struct list_head *item; 513 struct list_head *item;
514 struct i2c_client *client; 514 struct i2c_client *client;
515 515
516 down(&adap->clist_lock); 516 mutex_lock(&adap->clist_lock);
517 list_for_each(item,&adap->clients) { 517 list_for_each(item,&adap->clients) {
518 client = list_entry(item, struct i2c_client, list); 518 client = list_entry(item, struct i2c_client, list);
519 if (!try_module_get(client->driver->driver.owner)) 519 if (!try_module_get(client->driver->driver.owner))
520 continue; 520 continue;
521 if (NULL != client->driver->command) { 521 if (NULL != client->driver->command) {
522 up(&adap->clist_lock); 522 mutex_unlock(&adap->clist_lock);
523 client->driver->command(client,cmd,arg); 523 client->driver->command(client,cmd,arg);
524 down(&adap->clist_lock); 524 mutex_lock(&adap->clist_lock);
525 } 525 }
526 module_put(client->driver->driver.owner); 526 module_put(client->driver->driver.owner);
527 } 527 }
528 up(&adap->clist_lock); 528 mutex_unlock(&adap->clist_lock);
529} 529}
530 530
531static int __init i2c_init(void) 531static int __init i2c_init(void)
@@ -569,9 +569,9 @@ int i2c_transfer(struct i2c_adapter * adap, struct i2c_msg *msgs, int num)
569 } 569 }
570#endif 570#endif
571 571
572 down(&adap->bus_lock); 572 mutex_lock(&adap->bus_lock);
573 ret = adap->algo->master_xfer(adap,msgs,num); 573 ret = adap->algo->master_xfer(adap,msgs,num);
574 up(&adap->bus_lock); 574 mutex_unlock(&adap->bus_lock);
575 575
576 return ret; 576 return ret;
577 } else { 577 } else {
@@ -779,12 +779,12 @@ struct i2c_adapter* i2c_get_adapter(int id)
779{ 779{
780 struct i2c_adapter *adapter; 780 struct i2c_adapter *adapter;
781 781
782 down(&core_lists); 782 mutex_lock(&core_lists);
783 adapter = (struct i2c_adapter *)idr_find(&i2c_adapter_idr, id); 783 adapter = (struct i2c_adapter *)idr_find(&i2c_adapter_idr, id);
784 if (adapter && !try_module_get(adapter->owner)) 784 if (adapter && !try_module_get(adapter->owner))
785 adapter = NULL; 785 adapter = NULL;
786 786
787 up(&core_lists); 787 mutex_unlock(&core_lists);
788 return adapter; 788 return adapter;
789} 789}
790 790
@@ -919,12 +919,11 @@ s32 i2c_smbus_write_block_data(struct i2c_client *client, u8 command,
919 u8 length, u8 *values) 919 u8 length, u8 *values)
920{ 920{
921 union i2c_smbus_data data; 921 union i2c_smbus_data data;
922 int i; 922
923 if (length > I2C_SMBUS_BLOCK_MAX) 923 if (length > I2C_SMBUS_BLOCK_MAX)
924 length = I2C_SMBUS_BLOCK_MAX; 924 length = I2C_SMBUS_BLOCK_MAX;
925 for (i = 1; i <= length; i++)
926 data.block[i] = values[i-1];
927 data.block[0] = length; 925 data.block[0] = length;
926 memcpy(&data.block[1], values, length);
928 return i2c_smbus_xfer(client->adapter,client->addr,client->flags, 927 return i2c_smbus_xfer(client->adapter,client->addr,client->flags,
929 I2C_SMBUS_WRITE,command, 928 I2C_SMBUS_WRITE,command,
930 I2C_SMBUS_BLOCK_DATA,&data); 929 I2C_SMBUS_BLOCK_DATA,&data);
@@ -934,16 +933,14 @@ s32 i2c_smbus_write_block_data(struct i2c_client *client, u8 command,
934s32 i2c_smbus_read_i2c_block_data(struct i2c_client *client, u8 command, u8 *values) 933s32 i2c_smbus_read_i2c_block_data(struct i2c_client *client, u8 command, u8 *values)
935{ 934{
936 union i2c_smbus_data data; 935 union i2c_smbus_data data;
937 int i; 936
938 if (i2c_smbus_xfer(client->adapter,client->addr,client->flags, 937 if (i2c_smbus_xfer(client->adapter,client->addr,client->flags,
939 I2C_SMBUS_READ,command, 938 I2C_SMBUS_READ,command,
940 I2C_SMBUS_I2C_BLOCK_DATA,&data)) 939 I2C_SMBUS_I2C_BLOCK_DATA,&data))
941 return -1; 940 return -1;
942 else { 941
943 for (i = 1; i <= data.block[0]; i++) 942 memcpy(values, &data.block[1], data.block[0]);
944 values[i-1] = data.block[i]; 943 return data.block[0];
945 return data.block[0];
946 }
947} 944}
948 945
949s32 i2c_smbus_write_i2c_block_data(struct i2c_client *client, u8 command, 946s32 i2c_smbus_write_i2c_block_data(struct i2c_client *client, u8 command,
@@ -1118,10 +1115,10 @@ s32 i2c_smbus_xfer(struct i2c_adapter * adapter, u16 addr, unsigned short flags,
1118 flags &= I2C_M_TEN | I2C_CLIENT_PEC; 1115 flags &= I2C_M_TEN | I2C_CLIENT_PEC;
1119 1116
1120 if (adapter->algo->smbus_xfer) { 1117 if (adapter->algo->smbus_xfer) {
1121 down(&adapter->bus_lock); 1118 mutex_lock(&adapter->bus_lock);
1122 res = adapter->algo->smbus_xfer(adapter,addr,flags,read_write, 1119 res = adapter->algo->smbus_xfer(adapter,addr,flags,read_write,
1123 command,size,data); 1120 command,size,data);
1124 up(&adapter->bus_lock); 1121 mutex_unlock(&adapter->bus_lock);
1125 } else 1122 } else
1126 res = i2c_smbus_xfer_emulated(adapter,addr,flags,read_write, 1123 res = i2c_smbus_xfer_emulated(adapter,addr,flags,read_write,
1127 command,size,data); 1124 command,size,data);
diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
index 3325660f72..c7671e1880 100644
--- a/drivers/ide/ide-cd.c
+++ b/drivers/ide/ide-cd.c
@@ -313,6 +313,7 @@
313#include <linux/cdrom.h> 313#include <linux/cdrom.h>
314#include <linux/ide.h> 314#include <linux/ide.h>
315#include <linux/completion.h> 315#include <linux/completion.h>
316#include <linux/mutex.h>
316 317
317#include <scsi/scsi.h> /* For SCSI -> ATAPI command conversion */ 318#include <scsi/scsi.h> /* For SCSI -> ATAPI command conversion */
318 319
@@ -324,7 +325,7 @@
324 325
325#include "ide-cd.h" 326#include "ide-cd.h"
326 327
327static DECLARE_MUTEX(idecd_ref_sem); 328static DEFINE_MUTEX(idecd_ref_mutex);
328 329
329#define to_ide_cd(obj) container_of(obj, struct cdrom_info, kref) 330#define to_ide_cd(obj) container_of(obj, struct cdrom_info, kref)
330 331
@@ -335,11 +336,11 @@ static struct cdrom_info *ide_cd_get(struct gendisk *disk)
335{ 336{
336 struct cdrom_info *cd = NULL; 337 struct cdrom_info *cd = NULL;
337 338
338 down(&idecd_ref_sem); 339 mutex_lock(&idecd_ref_mutex);
339 cd = ide_cd_g(disk); 340 cd = ide_cd_g(disk);
340 if (cd) 341 if (cd)
341 kref_get(&cd->kref); 342 kref_get(&cd->kref);
342 up(&idecd_ref_sem); 343 mutex_unlock(&idecd_ref_mutex);
343 return cd; 344 return cd;
344} 345}
345 346
@@ -347,9 +348,9 @@ static void ide_cd_release(struct kref *);
347 348
348static void ide_cd_put(struct cdrom_info *cd) 349static void ide_cd_put(struct cdrom_info *cd)
349{ 350{
350 down(&idecd_ref_sem); 351 mutex_lock(&idecd_ref_mutex);
351 kref_put(&cd->kref, ide_cd_release); 352 kref_put(&cd->kref, ide_cd_release);
352 up(&idecd_ref_sem); 353 mutex_unlock(&idecd_ref_mutex);
353} 354}
354 355
355/**************************************************************************** 356/****************************************************************************
@@ -2471,52 +2472,6 @@ static int ide_cdrom_packet(struct cdrom_device_info *cdi,
2471} 2472}
2472 2473
2473static 2474static
2474int ide_cdrom_dev_ioctl (struct cdrom_device_info *cdi,
2475 unsigned int cmd, unsigned long arg)
2476{
2477 struct packet_command cgc;
2478 char buffer[16];
2479 int stat;
2480
2481 init_cdrom_command(&cgc, buffer, sizeof(buffer), CGC_DATA_UNKNOWN);
2482
2483 /* These will be moved into the Uniform layer shortly... */
2484 switch (cmd) {
2485 case CDROMSETSPINDOWN: {
2486 char spindown;
2487
2488 if (copy_from_user(&spindown, (void __user *) arg, sizeof(char)))
2489 return -EFAULT;
2490
2491 if ((stat = cdrom_mode_sense(cdi, &cgc, GPMODE_CDROM_PAGE, 0)))
2492 return stat;
2493
2494 buffer[11] = (buffer[11] & 0xf0) | (spindown & 0x0f);
2495
2496 return cdrom_mode_select(cdi, &cgc);
2497 }
2498
2499 case CDROMGETSPINDOWN: {
2500 char spindown;
2501
2502 if ((stat = cdrom_mode_sense(cdi, &cgc, GPMODE_CDROM_PAGE, 0)))
2503 return stat;
2504
2505 spindown = buffer[11] & 0x0f;
2506
2507 if (copy_to_user((void __user *) arg, &spindown, sizeof (char)))
2508 return -EFAULT;
2509
2510 return 0;
2511 }
2512
2513 default:
2514 return -EINVAL;
2515 }
2516
2517}
2518
2519static
2520int ide_cdrom_audio_ioctl (struct cdrom_device_info *cdi, 2475int ide_cdrom_audio_ioctl (struct cdrom_device_info *cdi,
2521 unsigned int cmd, void *arg) 2476 unsigned int cmd, void *arg)
2522 2477
@@ -2852,12 +2807,11 @@ static struct cdrom_device_ops ide_cdrom_dops = {
2852 .get_mcn = ide_cdrom_get_mcn, 2807 .get_mcn = ide_cdrom_get_mcn,
2853 .reset = ide_cdrom_reset, 2808 .reset = ide_cdrom_reset,
2854 .audio_ioctl = ide_cdrom_audio_ioctl, 2809 .audio_ioctl = ide_cdrom_audio_ioctl,
2855 .dev_ioctl = ide_cdrom_dev_ioctl,
2856 .capability = CDC_CLOSE_TRAY | CDC_OPEN_TRAY | CDC_LOCK | 2810 .capability = CDC_CLOSE_TRAY | CDC_OPEN_TRAY | CDC_LOCK |
2857 CDC_SELECT_SPEED | CDC_SELECT_DISC | 2811 CDC_SELECT_SPEED | CDC_SELECT_DISC |
2858 CDC_MULTI_SESSION | CDC_MCN | 2812 CDC_MULTI_SESSION | CDC_MCN |
2859 CDC_MEDIA_CHANGED | CDC_PLAY_AUDIO | CDC_RESET | 2813 CDC_MEDIA_CHANGED | CDC_PLAY_AUDIO | CDC_RESET |
2860 CDC_IOCTLS | CDC_DRIVE_STATUS | CDC_CD_R | 2814 CDC_DRIVE_STATUS | CDC_CD_R |
2861 CDC_CD_RW | CDC_DVD | CDC_DVD_R| CDC_DVD_RAM | 2815 CDC_CD_RW | CDC_DVD | CDC_DVD_R| CDC_DVD_RAM |
2862 CDC_GENERIC_PACKET | CDC_MO_DRIVE | CDC_MRW | 2816 CDC_GENERIC_PACKET | CDC_MO_DRIVE | CDC_MRW |
2863 CDC_MRW_W | CDC_RAM, 2817 CDC_MRW_W | CDC_RAM,
@@ -3367,6 +3321,45 @@ static int idecd_release(struct inode * inode, struct file * file)
3367 return 0; 3321 return 0;
3368} 3322}
3369 3323
3324static int idecd_set_spindown(struct cdrom_device_info *cdi, unsigned long arg)
3325{
3326 struct packet_command cgc;
3327 char buffer[16];
3328 int stat;
3329 char spindown;
3330
3331 if (copy_from_user(&spindown, (void __user *)arg, sizeof(char)))
3332 return -EFAULT;
3333
3334 init_cdrom_command(&cgc, buffer, sizeof(buffer), CGC_DATA_UNKNOWN);
3335
3336 stat = cdrom_mode_sense(cdi, &cgc, GPMODE_CDROM_PAGE, 0);
3337 if (stat)
3338 return stat;
3339
3340 buffer[11] = (buffer[11] & 0xf0) | (spindown & 0x0f);
3341 return cdrom_mode_select(cdi, &cgc);
3342}
3343
3344static int idecd_get_spindown(struct cdrom_device_info *cdi, unsigned long arg)
3345{
3346 struct packet_command cgc;
3347 char buffer[16];
3348 int stat;
3349 char spindown;
3350
3351 init_cdrom_command(&cgc, buffer, sizeof(buffer), CGC_DATA_UNKNOWN);
3352
3353 stat = cdrom_mode_sense(cdi, &cgc, GPMODE_CDROM_PAGE, 0);
3354 if (stat)
3355 return stat;
3356
3357 spindown = buffer[11] & 0x0f;
3358 if (copy_to_user((void __user *)arg, &spindown, sizeof (char)))
3359 return -EFAULT;
3360 return 0;
3361}
3362
3370static int idecd_ioctl (struct inode *inode, struct file *file, 3363static int idecd_ioctl (struct inode *inode, struct file *file,
3371 unsigned int cmd, unsigned long arg) 3364 unsigned int cmd, unsigned long arg)
3372{ 3365{
@@ -3374,7 +3367,16 @@ static int idecd_ioctl (struct inode *inode, struct file *file,
3374 struct cdrom_info *info = ide_cd_g(bdev->bd_disk); 3367 struct cdrom_info *info = ide_cd_g(bdev->bd_disk);
3375 int err; 3368 int err;
3376 3369
3377 err = generic_ide_ioctl(info->drive, file, bdev, cmd, arg); 3370 switch (cmd) {
3371 case CDROMSETSPINDOWN:
3372 return idecd_set_spindown(&info->devinfo, arg);
3373 case CDROMGETSPINDOWN:
3374 return idecd_get_spindown(&info->devinfo, arg);
3375 default:
3376 break;
3377 }
3378
3379 err = generic_ide_ioctl(info->drive, file, bdev, cmd, arg);
3378 if (err == -EINVAL) 3380 if (err == -EINVAL)
3379 err = cdrom_ioctl(file, &info->devinfo, inode, cmd, arg); 3381 err = cdrom_ioctl(file, &info->devinfo, inode, cmd, arg);
3380 3382
diff --git a/drivers/ide/ide-disk.c b/drivers/ide/ide-disk.c
index 09086b8b64..ccf528d733 100644
--- a/drivers/ide/ide-disk.c
+++ b/drivers/ide/ide-disk.c
@@ -60,6 +60,7 @@
60#include <linux/genhd.h> 60#include <linux/genhd.h>
61#include <linux/slab.h> 61#include <linux/slab.h>
62#include <linux/delay.h> 62#include <linux/delay.h>
63#include <linux/mutex.h>
63 64
64#define _IDE_DISK 65#define _IDE_DISK
65 66
@@ -78,7 +79,7 @@ struct ide_disk_obj {
78 struct kref kref; 79 struct kref kref;
79}; 80};
80 81
81static DECLARE_MUTEX(idedisk_ref_sem); 82static DEFINE_MUTEX(idedisk_ref_mutex);
82 83
83#define to_ide_disk(obj) container_of(obj, struct ide_disk_obj, kref) 84#define to_ide_disk(obj) container_of(obj, struct ide_disk_obj, kref)
84 85
@@ -89,11 +90,11 @@ static struct ide_disk_obj *ide_disk_get(struct gendisk *disk)
89{ 90{
90 struct ide_disk_obj *idkp = NULL; 91 struct ide_disk_obj *idkp = NULL;
91 92
92 down(&idedisk_ref_sem); 93 mutex_lock(&idedisk_ref_mutex);
93 idkp = ide_disk_g(disk); 94 idkp = ide_disk_g(disk);
94 if (idkp) 95 if (idkp)
95 kref_get(&idkp->kref); 96 kref_get(&idkp->kref);
96 up(&idedisk_ref_sem); 97 mutex_unlock(&idedisk_ref_mutex);
97 return idkp; 98 return idkp;
98} 99}
99 100
@@ -101,9 +102,9 @@ static void ide_disk_release(struct kref *);
101 102
102static void ide_disk_put(struct ide_disk_obj *idkp) 103static void ide_disk_put(struct ide_disk_obj *idkp)
103{ 104{
104 down(&idedisk_ref_sem); 105 mutex_lock(&idedisk_ref_mutex);
105 kref_put(&idkp->kref, ide_disk_release); 106 kref_put(&idkp->kref, ide_disk_release);
106 up(&idedisk_ref_sem); 107 mutex_unlock(&idedisk_ref_mutex);
107} 108}
108 109
109/* 110/*
@@ -977,8 +978,6 @@ static void idedisk_setup (ide_drive_t *drive)
977 ide_dma_verbose(drive); 978 ide_dma_verbose(drive);
978 printk("\n"); 979 printk("\n");
979 980
980 drive->no_io_32bit = id->dword_io ? 1 : 0;
981
982 /* write cache enabled? */ 981 /* write cache enabled? */
983 if ((id->csfo & 1) || (id->cfs_enable_1 & (1 << 5))) 982 if ((id->csfo & 1) || (id->cfs_enable_1 & (1 << 5)))
984 drive->wcache = 1; 983 drive->wcache = 1;
diff --git a/drivers/ide/ide-dma.c b/drivers/ide/ide-dma.c
index 0523da7742..c481be8b80 100644
--- a/drivers/ide/ide-dma.c
+++ b/drivers/ide/ide-dma.c
@@ -175,7 +175,7 @@ ide_startstop_t ide_dma_intr (ide_drive_t *drive)
175 if (rq->rq_disk) { 175 if (rq->rq_disk) {
176 ide_driver_t *drv; 176 ide_driver_t *drv;
177 177
178 drv = *(ide_driver_t **)rq->rq_disk->private_data;; 178 drv = *(ide_driver_t **)rq->rq_disk->private_data;
179 drv->end_request(drive, 1, rq->nr_sectors); 179 drv->end_request(drive, 1, rq->nr_sectors);
180 } else 180 } else
181 ide_end_request(drive, 1, rq->nr_sectors); 181 ide_end_request(drive, 1, rq->nr_sectors);
diff --git a/drivers/ide/ide-floppy.c b/drivers/ide/ide-floppy.c
index 1f8db9ac05..a53e3ce4a1 100644
--- a/drivers/ide/ide-floppy.c
+++ b/drivers/ide/ide-floppy.c
@@ -98,6 +98,7 @@
98#include <linux/cdrom.h> 98#include <linux/cdrom.h>
99#include <linux/ide.h> 99#include <linux/ide.h>
100#include <linux/bitops.h> 100#include <linux/bitops.h>
101#include <linux/mutex.h>
101 102
102#include <asm/byteorder.h> 103#include <asm/byteorder.h>
103#include <asm/irq.h> 104#include <asm/irq.h>
@@ -517,7 +518,7 @@ typedef struct {
517 u8 reserved[4]; 518 u8 reserved[4];
518} idefloppy_mode_parameter_header_t; 519} idefloppy_mode_parameter_header_t;
519 520
520static DECLARE_MUTEX(idefloppy_ref_sem); 521static DEFINE_MUTEX(idefloppy_ref_mutex);
521 522
522#define to_ide_floppy(obj) container_of(obj, struct ide_floppy_obj, kref) 523#define to_ide_floppy(obj) container_of(obj, struct ide_floppy_obj, kref)
523 524
@@ -528,11 +529,11 @@ static struct ide_floppy_obj *ide_floppy_get(struct gendisk *disk)
528{ 529{
529 struct ide_floppy_obj *floppy = NULL; 530 struct ide_floppy_obj *floppy = NULL;
530 531
531 down(&idefloppy_ref_sem); 532 mutex_lock(&idefloppy_ref_mutex);
532 floppy = ide_floppy_g(disk); 533 floppy = ide_floppy_g(disk);
533 if (floppy) 534 if (floppy)
534 kref_get(&floppy->kref); 535 kref_get(&floppy->kref);
535 up(&idefloppy_ref_sem); 536 mutex_unlock(&idefloppy_ref_mutex);
536 return floppy; 537 return floppy;
537} 538}
538 539
@@ -540,9 +541,9 @@ static void ide_floppy_release(struct kref *);
540 541
541static void ide_floppy_put(struct ide_floppy_obj *floppy) 542static void ide_floppy_put(struct ide_floppy_obj *floppy)
542{ 543{
543 down(&idefloppy_ref_sem); 544 mutex_lock(&idefloppy_ref_mutex);
544 kref_put(&floppy->kref, ide_floppy_release); 545 kref_put(&floppy->kref, ide_floppy_release);
545 up(&idefloppy_ref_sem); 546 mutex_unlock(&idefloppy_ref_mutex);
546} 547}
547 548
548/* 549/*
diff --git a/drivers/ide/ide-probe.c b/drivers/ide/ide-probe.c
index 427d1c2041..1b7b4c531b 100644
--- a/drivers/ide/ide-probe.c
+++ b/drivers/ide/ide-probe.c
@@ -858,6 +858,15 @@ static void probe_hwif(ide_hwif_t *hwif)
858 } 858 }
859 } 859 }
860 } 860 }
861
862 for (unit = 0; unit < MAX_DRIVES; ++unit) {
863 ide_drive_t *drive = &hwif->drives[unit];
864
865 if (hwif->no_io_32bit)
866 drive->no_io_32bit = 1;
867 else
868 drive->no_io_32bit = drive->id->dword_io ? 1 : 0;
869 }
861} 870}
862 871
863static int hwif_init(ide_hwif_t *hwif); 872static int hwif_init(ide_hwif_t *hwif);
diff --git a/drivers/ide/ide-tape.c b/drivers/ide/ide-tape.c
index 0101d0def7..ebc59064b4 100644
--- a/drivers/ide/ide-tape.c
+++ b/drivers/ide/ide-tape.c
@@ -443,6 +443,7 @@
443#include <linux/smp_lock.h> 443#include <linux/smp_lock.h>
444#include <linux/completion.h> 444#include <linux/completion.h>
445#include <linux/bitops.h> 445#include <linux/bitops.h>
446#include <linux/mutex.h>
446 447
447#include <asm/byteorder.h> 448#include <asm/byteorder.h>
448#include <asm/irq.h> 449#include <asm/irq.h>
@@ -1011,7 +1012,7 @@ typedef struct ide_tape_obj {
1011 int debug_level; 1012 int debug_level;
1012} idetape_tape_t; 1013} idetape_tape_t;
1013 1014
1014static DECLARE_MUTEX(idetape_ref_sem); 1015static DEFINE_MUTEX(idetape_ref_mutex);
1015 1016
1016static struct class *idetape_sysfs_class; 1017static struct class *idetape_sysfs_class;
1017 1018
@@ -1024,11 +1025,11 @@ static struct ide_tape_obj *ide_tape_get(struct gendisk *disk)
1024{ 1025{
1025 struct ide_tape_obj *tape = NULL; 1026 struct ide_tape_obj *tape = NULL;
1026 1027
1027 down(&idetape_ref_sem); 1028 mutex_lock(&idetape_ref_mutex);
1028 tape = ide_tape_g(disk); 1029 tape = ide_tape_g(disk);
1029 if (tape) 1030 if (tape)
1030 kref_get(&tape->kref); 1031 kref_get(&tape->kref);
1031 up(&idetape_ref_sem); 1032 mutex_unlock(&idetape_ref_mutex);
1032 return tape; 1033 return tape;
1033} 1034}
1034 1035
@@ -1036,9 +1037,9 @@ static void ide_tape_release(struct kref *);
1036 1037
1037static void ide_tape_put(struct ide_tape_obj *tape) 1038static void ide_tape_put(struct ide_tape_obj *tape)
1038{ 1039{
1039 down(&idetape_ref_sem); 1040 mutex_lock(&idetape_ref_mutex);
1040 kref_put(&tape->kref, ide_tape_release); 1041 kref_put(&tape->kref, ide_tape_release);
1041 up(&idetape_ref_sem); 1042 mutex_unlock(&idetape_ref_mutex);
1042} 1043}
1043 1044
1044/* 1045/*
@@ -1290,11 +1291,11 @@ static struct ide_tape_obj *ide_tape_chrdev_get(unsigned int i)
1290{ 1291{
1291 struct ide_tape_obj *tape = NULL; 1292 struct ide_tape_obj *tape = NULL;
1292 1293
1293 down(&idetape_ref_sem); 1294 mutex_lock(&idetape_ref_mutex);
1294 tape = idetape_devs[i]; 1295 tape = idetape_devs[i];
1295 if (tape) 1296 if (tape)
1296 kref_get(&tape->kref); 1297 kref_get(&tape->kref);
1297 up(&idetape_ref_sem); 1298 mutex_unlock(&idetape_ref_mutex);
1298 return tape; 1299 return tape;
1299} 1300}
1300 1301
@@ -4870,11 +4871,11 @@ static int ide_tape_probe(ide_drive_t *drive)
4870 4871
4871 drive->driver_data = tape; 4872 drive->driver_data = tape;
4872 4873
4873 down(&idetape_ref_sem); 4874 mutex_lock(&idetape_ref_mutex);
4874 for (minor = 0; idetape_devs[minor]; minor++) 4875 for (minor = 0; idetape_devs[minor]; minor++)
4875 ; 4876 ;
4876 idetape_devs[minor] = tape; 4877 idetape_devs[minor] = tape;
4877 up(&idetape_ref_sem); 4878 mutex_unlock(&idetape_ref_mutex);
4878 4879
4879 idetape_setup(drive, tape, minor); 4880 idetape_setup(drive, tape, minor);
4880 4881
diff --git a/drivers/isdn/capi/kcapi.c b/drivers/isdn/capi/kcapi.c
index feec40cf59..8c4fcb9027 100644
--- a/drivers/isdn/capi/kcapi.c
+++ b/drivers/isdn/capi/kcapi.c
@@ -32,6 +32,7 @@
32#ifdef CONFIG_AVMB1_COMPAT 32#ifdef CONFIG_AVMB1_COMPAT
33#include <linux/b1lli.h> 33#include <linux/b1lli.h>
34#endif 34#endif
35#include <linux/mutex.h>
35 36
36static char *revision = "$Revision: 1.1.2.8 $"; 37static char *revision = "$Revision: 1.1.2.8 $";
37 38
@@ -66,7 +67,7 @@ LIST_HEAD(capi_drivers);
66DEFINE_RWLOCK(capi_drivers_list_lock); 67DEFINE_RWLOCK(capi_drivers_list_lock);
67 68
68static DEFINE_RWLOCK(application_lock); 69static DEFINE_RWLOCK(application_lock);
69static DECLARE_MUTEX(controller_sem); 70static DEFINE_MUTEX(controller_mutex);
70 71
71struct capi20_appl *capi_applications[CAPI_MAXAPPL]; 72struct capi20_appl *capi_applications[CAPI_MAXAPPL];
72struct capi_ctr *capi_cards[CAPI_MAXCONTR]; 73struct capi_ctr *capi_cards[CAPI_MAXCONTR];
@@ -395,20 +396,20 @@ attach_capi_ctr(struct capi_ctr *card)
395{ 396{
396 int i; 397 int i;
397 398
398 down(&controller_sem); 399 mutex_lock(&controller_mutex);
399 400
400 for (i = 0; i < CAPI_MAXCONTR; i++) { 401 for (i = 0; i < CAPI_MAXCONTR; i++) {
401 if (capi_cards[i] == NULL) 402 if (capi_cards[i] == NULL)
402 break; 403 break;
403 } 404 }
404 if (i == CAPI_MAXCONTR) { 405 if (i == CAPI_MAXCONTR) {
405 up(&controller_sem); 406 mutex_unlock(&controller_mutex);
406 printk(KERN_ERR "kcapi: out of controller slots\n"); 407 printk(KERN_ERR "kcapi: out of controller slots\n");
407 return -EBUSY; 408 return -EBUSY;
408 } 409 }
409 capi_cards[i] = card; 410 capi_cards[i] = card;
410 411
411 up(&controller_sem); 412 mutex_unlock(&controller_mutex);
412 413
413 card->nrecvctlpkt = 0; 414 card->nrecvctlpkt = 0;
414 card->nrecvdatapkt = 0; 415 card->nrecvdatapkt = 0;
@@ -531,13 +532,13 @@ u16 capi20_register(struct capi20_appl *ap)
531 532
532 write_unlock_irqrestore(&application_lock, flags); 533 write_unlock_irqrestore(&application_lock, flags);
533 534
534 down(&controller_sem); 535 mutex_lock(&controller_mutex);
535 for (i = 0; i < CAPI_MAXCONTR; i++) { 536 for (i = 0; i < CAPI_MAXCONTR; i++) {
536 if (!capi_cards[i] || capi_cards[i]->cardstate != CARD_RUNNING) 537 if (!capi_cards[i] || capi_cards[i]->cardstate != CARD_RUNNING)
537 continue; 538 continue;
538 register_appl(capi_cards[i], applid, &ap->rparam); 539 register_appl(capi_cards[i], applid, &ap->rparam);
539 } 540 }
540 up(&controller_sem); 541 mutex_unlock(&controller_mutex);
541 542
542 if (showcapimsgs & 1) { 543 if (showcapimsgs & 1) {
543 printk(KERN_DEBUG "kcapi: appl %d up\n", applid); 544 printk(KERN_DEBUG "kcapi: appl %d up\n", applid);
@@ -560,13 +561,13 @@ u16 capi20_release(struct capi20_appl *ap)
560 capi_applications[ap->applid - 1] = NULL; 561 capi_applications[ap->applid - 1] = NULL;
561 write_unlock_irqrestore(&application_lock, flags); 562 write_unlock_irqrestore(&application_lock, flags);
562 563
563 down(&controller_sem); 564 mutex_lock(&controller_mutex);
564 for (i = 0; i < CAPI_MAXCONTR; i++) { 565 for (i = 0; i < CAPI_MAXCONTR; i++) {
565 if (!capi_cards[i] || capi_cards[i]->cardstate != CARD_RUNNING) 566 if (!capi_cards[i] || capi_cards[i]->cardstate != CARD_RUNNING)
566 continue; 567 continue;
567 release_appl(capi_cards[i], ap->applid); 568 release_appl(capi_cards[i], ap->applid);
568 } 569 }
569 up(&controller_sem); 570 mutex_unlock(&controller_mutex);
570 571
571 flush_scheduled_work(); 572 flush_scheduled_work();
572 skb_queue_purge(&ap->recv_queue); 573 skb_queue_purge(&ap->recv_queue);
diff --git a/drivers/isdn/hisax/config.c b/drivers/isdn/hisax/config.c
index df9d652018..27332506f9 100644
--- a/drivers/isdn/hisax/config.c
+++ b/drivers/isdn/hisax/config.c
@@ -25,7 +25,6 @@
25#include <linux/workqueue.h> 25#include <linux/workqueue.h>
26#include <linux/interrupt.h> 26#include <linux/interrupt.h>
27#define HISAX_STATUS_BUFSIZE 4096 27#define HISAX_STATUS_BUFSIZE 4096
28#define INCLUDE_INLINE_FUNCS
29 28
30/* 29/*
31 * This structure array contains one entry per card. An entry looks 30 * This structure array contains one entry per card. An entry looks
diff --git a/drivers/isdn/hisax/elsa.c b/drivers/isdn/hisax/elsa.c
index 110e9fd669..f8ca4b3233 100644
--- a/drivers/isdn/hisax/elsa.c
+++ b/drivers/isdn/hisax/elsa.c
@@ -108,7 +108,6 @@ static const char *ITACVer[] =
108#define ELSA_ASSIGN 4 108#define ELSA_ASSIGN 4
109 109
110#define RS_ISR_PASS_LIMIT 256 110#define RS_ISR_PASS_LIMIT 256
111#define _INLINE_ inline
112#define FLG_MODEM_ACTIVE 1 111#define FLG_MODEM_ACTIVE 1
113/* IPAC AUX */ 112/* IPAC AUX */
114#define ELSA_IPAC_LINE_LED 0x40 /* Bit 6 Gelbe LED */ 113#define ELSA_IPAC_LINE_LED 0x40 /* Bit 6 Gelbe LED */
diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
index 69596f6438..431bd37225 100644
--- a/drivers/macintosh/macio_asic.c
+++ b/drivers/macintosh/macio_asic.c
@@ -550,15 +550,12 @@ static void macio_pci_add_devices(struct macio_chip *chip)
550 */ 550 */
551int macio_register_driver(struct macio_driver *drv) 551int macio_register_driver(struct macio_driver *drv)
552{ 552{
553 int count = 0;
554
555 /* initialize common driver fields */ 553 /* initialize common driver fields */
556 drv->driver.name = drv->name; 554 drv->driver.name = drv->name;
557 drv->driver.bus = &macio_bus_type; 555 drv->driver.bus = &macio_bus_type;
558 556
559 /* register with core */ 557 /* register with core */
560 count = driver_register(&drv->driver); 558 return driver_register(&drv->driver);
561 return count ? count : 1;
562} 559}
563 560
564/** 561/**
diff --git a/drivers/macintosh/smu.c b/drivers/macintosh/smu.c
index db2ae71d07..4eb05d7143 100644
--- a/drivers/macintosh/smu.c
+++ b/drivers/macintosh/smu.c
@@ -629,8 +629,6 @@ static struct of_platform_driver smu_of_platform_driver =
629 629
630static int __init smu_init_sysfs(void) 630static int __init smu_init_sysfs(void)
631{ 631{
632 int rc;
633
634 /* 632 /*
635 * Due to sysfs bogosity, a sysdev is not a real device, so 633 * Due to sysfs bogosity, a sysdev is not a real device, so
636 * we should in fact create both if we want sysdev semantics 634 * we should in fact create both if we want sysdev semantics
@@ -639,7 +637,7 @@ static int __init smu_init_sysfs(void)
639 * I'm a bit too far from figuring out how that works with those 637 * I'm a bit too far from figuring out how that works with those
640 * new chipsets, but that will come back and bite us 638 * new chipsets, but that will come back and bite us
641 */ 639 */
642 rc = of_register_driver(&smu_of_platform_driver); 640 of_register_driver(&smu_of_platform_driver);
643 return 0; 641 return 0;
644} 642}
645 643
diff --git a/drivers/macintosh/therm_pm72.c b/drivers/macintosh/therm_pm72.c
index 4f50ee5767..231146f439 100644
--- a/drivers/macintosh/therm_pm72.c
+++ b/drivers/macintosh/therm_pm72.c
@@ -104,7 +104,6 @@
104#include <linux/kernel.h> 104#include <linux/kernel.h>
105#include <linux/delay.h> 105#include <linux/delay.h>
106#include <linux/sched.h> 106#include <linux/sched.h>
107#include <linux/i2c.h>
108#include <linux/slab.h> 107#include <linux/slab.h>
109#include <linux/init.h> 108#include <linux/init.h>
110#include <linux/spinlock.h> 109#include <linux/spinlock.h>
@@ -113,7 +112,6 @@
113#include <linux/reboot.h> 112#include <linux/reboot.h>
114#include <linux/kmod.h> 113#include <linux/kmod.h>
115#include <linux/i2c.h> 114#include <linux/i2c.h>
116#include <linux/i2c-dev.h>
117#include <asm/prom.h> 115#include <asm/prom.h>
118#include <asm/machdep.h> 116#include <asm/machdep.h>
119#include <asm/io.h> 117#include <asm/io.h>
diff --git a/drivers/macintosh/via-pmu.c b/drivers/macintosh/via-pmu.c
index 4a478eb0e2..4f5f3abc9c 100644
--- a/drivers/macintosh/via-pmu.c
+++ b/drivers/macintosh/via-pmu.c
@@ -161,7 +161,9 @@ static int drop_interrupts;
161#if defined(CONFIG_PM) && defined(CONFIG_PPC32) 161#if defined(CONFIG_PM) && defined(CONFIG_PPC32)
162static int option_lid_wakeup = 1; 162static int option_lid_wakeup = 1;
163#endif /* CONFIG_PM && CONFIG_PPC32 */ 163#endif /* CONFIG_PM && CONFIG_PPC32 */
164#if (defined(CONFIG_PM)&&defined(CONFIG_PPC32))||defined(CONFIG_PMAC_BACKLIGHT)
164static int sleep_in_progress; 165static int sleep_in_progress;
166#endif
165static unsigned long async_req_locks; 167static unsigned long async_req_locks;
166static unsigned int pmu_irq_stats[11]; 168static unsigned int pmu_irq_stats[11];
167 169
@@ -2201,8 +2203,7 @@ pmac_wakeup_devices(void)
2201#define GRACKLE_NAP (1<<4) 2203#define GRACKLE_NAP (1<<4)
2202#define GRACKLE_SLEEP (1<<3) 2204#define GRACKLE_SLEEP (1<<3)
2203 2205
2204int 2206static int powerbook_sleep_grackle(void)
2205powerbook_sleep_grackle(void)
2206{ 2207{
2207 unsigned long save_l2cr; 2208 unsigned long save_l2cr;
2208 unsigned short pmcr1; 2209 unsigned short pmcr1;
diff --git a/drivers/macintosh/windfarm_lm75_sensor.c b/drivers/macintosh/windfarm_lm75_sensor.c
index 423bfa2432..3f7967feaf 100644
--- a/drivers/macintosh/windfarm_lm75_sensor.c
+++ b/drivers/macintosh/windfarm_lm75_sensor.c
@@ -15,7 +15,6 @@
15#include <linux/init.h> 15#include <linux/init.h>
16#include <linux/wait.h> 16#include <linux/wait.h>
17#include <linux/i2c.h> 17#include <linux/i2c.h>
18#include <linux/i2c-dev.h>
19#include <asm/prom.h> 18#include <asm/prom.h>
20#include <asm/machdep.h> 19#include <asm/machdep.h>
21#include <asm/io.h> 20#include <asm/io.h>
diff --git a/drivers/macintosh/windfarm_max6690_sensor.c b/drivers/macintosh/windfarm_max6690_sensor.c
index 8e99d408fd..eae1189d6c 100644
--- a/drivers/macintosh/windfarm_max6690_sensor.c
+++ b/drivers/macintosh/windfarm_max6690_sensor.c
@@ -11,7 +11,6 @@
11#include <linux/init.h> 11#include <linux/init.h>
12#include <linux/slab.h> 12#include <linux/slab.h>
13#include <linux/i2c.h> 13#include <linux/i2c.h>
14#include <linux/i2c-dev.h>
15#include <asm/prom.h> 14#include <asm/prom.h>
16#include <asm/pmac_low_i2c.h> 15#include <asm/pmac_low_i2c.h>
17 16
diff --git a/drivers/macintosh/windfarm_smu_sat.c b/drivers/macintosh/windfarm_smu_sat.c
index 24e51d5e97..e295a07a1e 100644
--- a/drivers/macintosh/windfarm_smu_sat.c
+++ b/drivers/macintosh/windfarm_smu_sat.c
@@ -13,7 +13,6 @@
13#include <linux/init.h> 13#include <linux/init.h>
14#include <linux/wait.h> 14#include <linux/wait.h>
15#include <linux/i2c.h> 15#include <linux/i2c.h>
16#include <linux/i2c-dev.h>
17#include <asm/semaphore.h> 16#include <asm/semaphore.h>
18#include <asm/prom.h> 17#include <asm/prom.h>
19#include <asm/smu.h> 18#include <asm/smu.h>
diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index 26b08ee425..8c82373f7f 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -17,6 +17,7 @@
17#include <linux/mempool.h> 17#include <linux/mempool.h>
18#include <linux/slab.h> 18#include <linux/slab.h>
19#include <linux/idr.h> 19#include <linux/idr.h>
20#include <linux/blktrace_api.h>
20 21
21static const char *_name = DM_NAME; 22static const char *_name = DM_NAME;
22 23
@@ -334,6 +335,8 @@ static void dec_pending(struct dm_io *io, int error)
334 /* nudge anyone waiting on suspend queue */ 335 /* nudge anyone waiting on suspend queue */
335 wake_up(&io->md->wait); 336 wake_up(&io->md->wait);
336 337
338 blk_add_trace_bio(io->md->queue, io->bio, BLK_TA_COMPLETE);
339
337 bio_endio(io->bio, io->bio->bi_size, io->error); 340 bio_endio(io->bio, io->bio->bi_size, io->error);
338 free_io(io->md, io); 341 free_io(io->md, io);
339 } 342 }
@@ -392,6 +395,7 @@ static void __map_bio(struct dm_target *ti, struct bio *clone,
392 struct target_io *tio) 395 struct target_io *tio)
393{ 396{
394 int r; 397 int r;
398 sector_t sector;
395 399
396 /* 400 /*
397 * Sanity checks. 401 * Sanity checks.
@@ -407,10 +411,17 @@ static void __map_bio(struct dm_target *ti, struct bio *clone,
407 * this io. 411 * this io.
408 */ 412 */
409 atomic_inc(&tio->io->io_count); 413 atomic_inc(&tio->io->io_count);
414 sector = clone->bi_sector;
410 r = ti->type->map(ti, clone, &tio->info); 415 r = ti->type->map(ti, clone, &tio->info);
411 if (r > 0) 416 if (r > 0) {
412 /* the bio has been remapped so dispatch it */ 417 /* the bio has been remapped so dispatch it */
418
419 blk_add_trace_remap(bdev_get_queue(clone->bi_bdev), clone,
420 tio->io->bio->bi_bdev->bd_dev, sector,
421 clone->bi_sector);
422
413 generic_make_request(clone); 423 generic_make_request(clone);
424 }
414 425
415 else if (r < 0) { 426 else if (r < 0) {
416 /* error the io and bail out */ 427 /* error the io and bail out */
diff --git a/drivers/media/video/adv7170.c b/drivers/media/video/adv7170.c
index 4ce07ae62d..671e36db22 100644
--- a/drivers/media/video/adv7170.c
+++ b/drivers/media/video/adv7170.c
@@ -53,7 +53,6 @@ MODULE_AUTHOR("Maxim Yevtyushkin");
53MODULE_LICENSE("GPL"); 53MODULE_LICENSE("GPL");
54 54
55#include <linux/i2c.h> 55#include <linux/i2c.h>
56#include <linux/i2c-dev.h>
57 56
58#define I2C_NAME(x) (x)->name 57#define I2C_NAME(x) (x)->name
59 58
@@ -125,24 +124,21 @@ adv7170_write_block (struct i2c_client *client,
125 if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { 124 if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
126 /* do raw I2C, not smbus compatible */ 125 /* do raw I2C, not smbus compatible */
127 struct adv7170 *encoder = i2c_get_clientdata(client); 126 struct adv7170 *encoder = i2c_get_clientdata(client);
128 struct i2c_msg msg;
129 u8 block_data[32]; 127 u8 block_data[32];
128 int block_len;
130 129
131 msg.addr = client->addr;
132 msg.flags = 0;
133 while (len >= 2) { 130 while (len >= 2) {
134 msg.buf = (char *) block_data; 131 block_len = 0;
135 msg.len = 0; 132 block_data[block_len++] = reg = data[0];
136 block_data[msg.len++] = reg = data[0];
137 do { 133 do {
138 block_data[msg.len++] = 134 block_data[block_len++] =
139 encoder->reg[reg++] = data[1]; 135 encoder->reg[reg++] = data[1];
140 len -= 2; 136 len -= 2;
141 data += 2; 137 data += 2;
142 } while (len >= 2 && data[0] == reg && 138 } while (len >= 2 && data[0] == reg &&
143 msg.len < 32); 139 block_len < 32);
144 if ((ret = i2c_transfer(client->adapter, 140 if ((ret = i2c_master_send(client, block_data,
145 &msg, 1)) < 0) 141 block_len)) < 0)
146 break; 142 break;
147 } 143 }
148 } else { 144 } else {
diff --git a/drivers/media/video/adv7175.c b/drivers/media/video/adv7175.c
index 4e218f22b2..085e8863ca 100644
--- a/drivers/media/video/adv7175.c
+++ b/drivers/media/video/adv7175.c
@@ -49,7 +49,6 @@ MODULE_AUTHOR("Dave Perks");
49MODULE_LICENSE("GPL"); 49MODULE_LICENSE("GPL");
50 50
51#include <linux/i2c.h> 51#include <linux/i2c.h>
52#include <linux/i2c-dev.h>
53 52
54#define I2C_NAME(s) (s)->name 53#define I2C_NAME(s) (s)->name
55 54
@@ -68,8 +67,6 @@ MODULE_PARM_DESC(debug, "Debug level (0-1)");
68/* ----------------------------------------------------------------------- */ 67/* ----------------------------------------------------------------------- */
69 68
70struct adv7175 { 69struct adv7175 {
71 unsigned char reg[128];
72
73 int norm; 70 int norm;
74 int input; 71 int input;
75 int enable; 72 int enable;
@@ -95,9 +92,6 @@ adv7175_write (struct i2c_client *client,
95 u8 reg, 92 u8 reg,
96 u8 value) 93 u8 value)
97{ 94{
98 struct adv7175 *encoder = i2c_get_clientdata(client);
99
100 encoder->reg[reg] = value;
101 return i2c_smbus_write_byte_data(client, reg, value); 95 return i2c_smbus_write_byte_data(client, reg, value);
102} 96}
103 97
@@ -120,25 +114,21 @@ adv7175_write_block (struct i2c_client *client,
120 * the adapter understands raw I2C */ 114 * the adapter understands raw I2C */
121 if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { 115 if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
122 /* do raw I2C, not smbus compatible */ 116 /* do raw I2C, not smbus compatible */
123 struct adv7175 *encoder = i2c_get_clientdata(client);
124 struct i2c_msg msg;
125 u8 block_data[32]; 117 u8 block_data[32];
118 int block_len;
126 119
127 msg.addr = client->addr;
128 msg.flags = 0;
129 while (len >= 2) { 120 while (len >= 2) {
130 msg.buf = (char *) block_data; 121 block_len = 0;
131 msg.len = 0; 122 block_data[block_len++] = reg = data[0];
132 block_data[msg.len++] = reg = data[0];
133 do { 123 do {
134 block_data[msg.len++] = 124 block_data[block_len++] = data[1];
135 encoder->reg[reg++] = data[1]; 125 reg++;
136 len -= 2; 126 len -= 2;
137 data += 2; 127 data += 2;
138 } while (len >= 2 && data[0] == reg && 128 } while (len >= 2 && data[0] == reg &&
139 msg.len < 32); 129 block_len < 32);
140 if ((ret = i2c_transfer(client->adapter, 130 if ((ret = i2c_master_send(client, block_data,
141 &msg, 1)) < 0) 131 block_len)) < 0)
142 break; 132 break;
143 } 133 }
144 } else { 134 } else {
@@ -171,24 +161,6 @@ set_subcarrier_freq (struct i2c_client *client,
171 adv7175_write(client, 0x05, 0x25); 161 adv7175_write(client, 0x05, 0x25);
172} 162}
173 163
174#ifdef ENCODER_DUMP
175static void
176dump (struct i2c_client *client)
177{
178 struct adv7175 *encoder = i2c_get_clientdata(client);
179 int i, j;
180
181 printk(KERN_INFO "%s: registry dump\n", I2C_NAME(client));
182 for (i = 0; i < 182 / 8; i++) {
183 printk("%s: 0x%02x -", I2C_NAME(client), i * 8);
184 for (j = 0; j < 8; j++) {
185 printk(" 0x%02x", encoder->reg[i * 8 + j]);
186 }
187 printk("\n");
188 }
189}
190#endif
191
192/* ----------------------------------------------------------------------- */ 164/* ----------------------------------------------------------------------- */
193// Output filter: S-Video Composite 165// Output filter: S-Video Composite
194 166
@@ -407,14 +379,6 @@ adv7175_command (struct i2c_client *client,
407 } 379 }
408 break; 380 break;
409 381
410#ifdef ENCODER_DUMP
411 case ENCODER_DUMP:
412 {
413 dump(client);
414 }
415 break;
416#endif
417
418 default: 382 default:
419 return -EINVAL; 383 return -EINVAL;
420 } 384 }
diff --git a/drivers/media/video/bt819.c b/drivers/media/video/bt819.c
index d6447791d0..d8a18a6a5b 100644
--- a/drivers/media/video/bt819.c
+++ b/drivers/media/video/bt819.c
@@ -53,7 +53,6 @@ MODULE_AUTHOR("Mike Bernson & Dave Perks");
53MODULE_LICENSE("GPL"); 53MODULE_LICENSE("GPL");
54 54
55#include <linux/i2c.h> 55#include <linux/i2c.h>
56#include <linux/i2c-dev.h>
57 56
58#define I2C_NAME(s) (s)->name 57#define I2C_NAME(s) (s)->name
59 58
@@ -141,24 +140,21 @@ bt819_write_block (struct i2c_client *client,
141 if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { 140 if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
142 /* do raw I2C, not smbus compatible */ 141 /* do raw I2C, not smbus compatible */
143 struct bt819 *decoder = i2c_get_clientdata(client); 142 struct bt819 *decoder = i2c_get_clientdata(client);
144 struct i2c_msg msg;
145 u8 block_data[32]; 143 u8 block_data[32];
144 int block_len;
146 145
147 msg.addr = client->addr;
148 msg.flags = 0;
149 while (len >= 2) { 146 while (len >= 2) {
150 msg.buf = (char *) block_data; 147 block_len = 0;
151 msg.len = 0; 148 block_data[block_len++] = reg = data[0];
152 block_data[msg.len++] = reg = data[0];
153 do { 149 do {
154 block_data[msg.len++] = 150 block_data[block_len++] =
155 decoder->reg[reg++] = data[1]; 151 decoder->reg[reg++] = data[1];
156 len -= 2; 152 len -= 2;
157 data += 2; 153 data += 2;
158 } while (len >= 2 && data[0] == reg && 154 } while (len >= 2 && data[0] == reg &&
159 msg.len < 32); 155 block_len < 32);
160 if ((ret = i2c_transfer(client->adapter, 156 if ((ret = i2c_master_send(client, block_data,
161 &msg, 1)) < 0) 157 block_len)) < 0)
162 break; 158 break;
163 } 159 }
164 } else { 160 } else {
diff --git a/drivers/media/video/bt856.c b/drivers/media/video/bt856.c
index 909b593530..4d47a0a0e9 100644
--- a/drivers/media/video/bt856.c
+++ b/drivers/media/video/bt856.c
@@ -53,7 +53,6 @@ MODULE_AUTHOR("Mike Bernson & Dave Perks");
53MODULE_LICENSE("GPL"); 53MODULE_LICENSE("GPL");
54 54
55#include <linux/i2c.h> 55#include <linux/i2c.h>
56#include <linux/i2c-dev.h>
57 56
58#define I2C_NAME(s) (s)->name 57#define I2C_NAME(s) (s)->name
59 58
@@ -71,17 +70,14 @@ MODULE_PARM_DESC(debug, "Debug level (0-1)");
71 70
72/* ----------------------------------------------------------------------- */ 71/* ----------------------------------------------------------------------- */
73 72
74#define REG_OFFSET 0xCE 73#define REG_OFFSET 0xDA
74#define BT856_NR_REG 6
75 75
76struct bt856 { 76struct bt856 {
77 unsigned char reg[32]; 77 unsigned char reg[BT856_NR_REG];
78 78
79 int norm; 79 int norm;
80 int enable; 80 int enable;
81 int bright;
82 int contrast;
83 int hue;
84 int sat;
85}; 81};
86 82
87#define I2C_BT856 0x88 83#define I2C_BT856 0x88
@@ -120,8 +116,8 @@ bt856_dump (struct i2c_client *client)
120 struct bt856 *encoder = i2c_get_clientdata(client); 116 struct bt856 *encoder = i2c_get_clientdata(client);
121 117
122 printk(KERN_INFO "%s: register dump:", I2C_NAME(client)); 118 printk(KERN_INFO "%s: register dump:", I2C_NAME(client));
123 for (i = 0xd6; i <= 0xde; i += 2) 119 for (i = 0; i < BT856_NR_REG; i += 2)
124 printk(" %02x", encoder->reg[i - REG_OFFSET]); 120 printk(" %02x", encoder->reg[i]);
125 printk("\n"); 121 printk("\n");
126} 122}
127 123
diff --git a/drivers/media/video/cpia.c b/drivers/media/video/cpia.c
index d93a561e6b..3cebfa91ca 100644
--- a/drivers/media/video/cpia.c
+++ b/drivers/media/video/cpia.c
@@ -58,7 +58,7 @@ static int video_nr = -1;
58 58
59#ifdef MODULE 59#ifdef MODULE
60module_param(video_nr, int, 0); 60module_param(video_nr, int, 0);
61MODULE_AUTHOR("Scott J. Bertin <sbertin@securenym.net> & Peter Pregler <Peter_Pregler@email.com> & Johannes Erdfelt <johannes@erdfeld.com>"); 61MODULE_AUTHOR("Scott J. Bertin <sbertin@securenym.net> & Peter Pregler <Peter_Pregler@email.com> & Johannes Erdfelt <johannes@erdfelt.com>");
62MODULE_DESCRIPTION("V4L-driver for Vision CPiA based cameras"); 62MODULE_DESCRIPTION("V4L-driver for Vision CPiA based cameras");
63MODULE_LICENSE("GPL"); 63MODULE_LICENSE("GPL");
64MODULE_SUPPORTED_DEVICE("video"); 64MODULE_SUPPORTED_DEVICE("video");
diff --git a/drivers/media/video/saa7110.c b/drivers/media/video/saa7110.c
index 7bb85a7b32..e18ea26838 100644
--- a/drivers/media/video/saa7110.c
+++ b/drivers/media/video/saa7110.c
@@ -39,7 +39,6 @@ MODULE_AUTHOR("Pauline Middelink");
39MODULE_LICENSE("GPL"); 39MODULE_LICENSE("GPL");
40 40
41#include <linux/i2c.h> 41#include <linux/i2c.h>
42#include <linux/i2c-dev.h>
43 42
44#define I2C_NAME(s) (s)->name 43#define I2C_NAME(s) (s)->name
45 44
@@ -108,13 +107,8 @@ saa7110_write_block (struct i2c_client *client,
108 * the adapter understands raw I2C */ 107 * the adapter understands raw I2C */
109 if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { 108 if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
110 struct saa7110 *decoder = i2c_get_clientdata(client); 109 struct saa7110 *decoder = i2c_get_clientdata(client);
111 struct i2c_msg msg;
112 110
113 msg.len = len; 111 ret = i2c_master_send(client, data, len);
114 msg.buf = (char *) data;
115 msg.addr = client->addr;
116 msg.flags = 0;
117 ret = i2c_transfer(client->adapter, &msg, 1);
118 112
119 /* Cache the written data */ 113 /* Cache the written data */
120 memcpy(decoder->reg + reg, data + 1, len - 1); 114 memcpy(decoder->reg + reg, data + 1, len - 1);
@@ -432,15 +426,13 @@ saa7110_command (struct i2c_client *client,
432 break; 426 break;
433 427
434 case DECODER_DUMP: 428 case DECODER_DUMP:
435 for (v = 0; v < 0x34; v += 16) { 429 for (v = 0; v < SAA7110_NR_REG; v += 16) {
436 int j; 430 int j;
437 dprintk(1, KERN_INFO "%s: %03x\n", I2C_NAME(client), 431 dprintk(1, KERN_DEBUG "%s: %02x:", I2C_NAME(client),
438 v); 432 v);
439 for (j = 0; j < 16; j++) { 433 for (j = 0; j < 16 && v + j < SAA7110_NR_REG; j++)
440 dprintk(1, KERN_INFO " %02x", 434 dprintk(1, " %02x", decoder->reg[v + j]);
441 decoder->reg[v + j]); 435 dprintk(1, "\n");
442 }
443 dprintk(1, KERN_INFO "\n");
444 } 436 }
445 break; 437 break;
446 438
diff --git a/drivers/media/video/saa7111.c b/drivers/media/video/saa7111.c
index 8c06592b37..f9ba0c943a 100644
--- a/drivers/media/video/saa7111.c
+++ b/drivers/media/video/saa7111.c
@@ -52,7 +52,6 @@ MODULE_AUTHOR("Dave Perks");
52MODULE_LICENSE("GPL"); 52MODULE_LICENSE("GPL");
53 53
54#include <linux/i2c.h> 54#include <linux/i2c.h>
55#include <linux/i2c-dev.h>
56 55
57#define I2C_NAME(s) (s)->name 56#define I2C_NAME(s) (s)->name
58 57
@@ -70,8 +69,10 @@ MODULE_PARM_DESC(debug, "Debug level (0-1)");
70 69
71/* ----------------------------------------------------------------------- */ 70/* ----------------------------------------------------------------------- */
72 71
72#define SAA7111_NR_REG 0x18
73
73struct saa7111 { 74struct saa7111 {
74 unsigned char reg[32]; 75 unsigned char reg[SAA7111_NR_REG];
75 76
76 int norm; 77 int norm;
77 int input; 78 int input;
@@ -110,24 +111,21 @@ saa7111_write_block (struct i2c_client *client,
110 if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { 111 if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
111 /* do raw I2C, not smbus compatible */ 112 /* do raw I2C, not smbus compatible */
112 struct saa7111 *decoder = i2c_get_clientdata(client); 113 struct saa7111 *decoder = i2c_get_clientdata(client);
113 struct i2c_msg msg;
114 u8 block_data[32]; 114 u8 block_data[32];
115 int block_len;
115 116
116 msg.addr = client->addr;
117 msg.flags = 0;
118 while (len >= 2) { 117 while (len >= 2) {
119 msg.buf = (char *) block_data; 118 block_len = 0;
120 msg.len = 0; 119 block_data[block_len++] = reg = data[0];
121 block_data[msg.len++] = reg = data[0];
122 do { 120 do {
123 block_data[msg.len++] = 121 block_data[block_len++] =
124 decoder->reg[reg++] = data[1]; 122 decoder->reg[reg++] = data[1];
125 len -= 2; 123 len -= 2;
126 data += 2; 124 data += 2;
127 } while (len >= 2 && data[0] == reg && 125 } while (len >= 2 && data[0] == reg &&
128 msg.len < 32); 126 block_len < 32);
129 if ((ret = i2c_transfer(client->adapter, 127 if ((ret = i2c_master_send(client, block_data,
130 &msg, 1)) < 0) 128 block_len)) < 0)
131 break; 129 break;
132 } 130 }
133 } else { 131 } else {
@@ -210,6 +208,7 @@ saa7111_command (struct i2c_client *client,
210 switch (cmd) { 208 switch (cmd) {
211 209
212 case 0: 210 case 0:
211 break;
213 case DECODER_INIT: 212 case DECODER_INIT:
214 { 213 {
215 struct video_decoder_init *init = arg; 214 struct video_decoder_init *init = arg;
@@ -227,11 +226,11 @@ saa7111_command (struct i2c_client *client,
227 { 226 {
228 int i; 227 int i;
229 228
230 for (i = 0; i < 32; i += 16) { 229 for (i = 0; i < SAA7111_NR_REG; i += 16) {
231 int j; 230 int j;
232 231
233 printk(KERN_DEBUG "%s: %03x", I2C_NAME(client), i); 232 printk(KERN_DEBUG "%s: %03x", I2C_NAME(client), i);
234 for (j = 0; j < 16; ++j) { 233 for (j = 0; j < 16 && i + j < SAA7111_NR_REG; ++j) {
235 printk(" %02x", 234 printk(" %02x",
236 saa7111_read(client, i + j)); 235 saa7111_read(client, i + j));
237 } 236 }
diff --git a/drivers/media/video/saa7114.c b/drivers/media/video/saa7114.c
index fd0a4b4ef0..4a1f841d0c 100644
--- a/drivers/media/video/saa7114.c
+++ b/drivers/media/video/saa7114.c
@@ -55,7 +55,6 @@ MODULE_AUTHOR("Maxim Yevtyushkin");
55MODULE_LICENSE("GPL"); 55MODULE_LICENSE("GPL");
56 56
57#include <linux/i2c.h> 57#include <linux/i2c.h>
58#include <linux/i2c-dev.h>
59 58
60#define I2C_NAME(x) (x)->name 59#define I2C_NAME(x) (x)->name
61 60
@@ -139,9 +138,6 @@ saa7114_write (struct i2c_client *client,
139 u8 reg, 138 u8 reg,
140 u8 value) 139 u8 value)
141{ 140{
142 /*struct saa7114 *decoder = i2c_get_clientdata(client);*/
143
144 /*decoder->reg[reg] = value;*/
145 return i2c_smbus_write_byte_data(client, reg, value); 141 return i2c_smbus_write_byte_data(client, reg, value);
146} 142}
147 143
@@ -157,25 +153,21 @@ saa7114_write_block (struct i2c_client *client,
157 * the adapter understands raw I2C */ 153 * the adapter understands raw I2C */
158 if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { 154 if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
159 /* do raw I2C, not smbus compatible */ 155 /* do raw I2C, not smbus compatible */
160 /*struct saa7114 *decoder = i2c_get_clientdata(client);*/
161 struct i2c_msg msg;
162 u8 block_data[32]; 156 u8 block_data[32];
157 int block_len;
163 158
164 msg.addr = client->addr;
165 msg.flags = 0;
166 while (len >= 2) { 159 while (len >= 2) {
167 msg.buf = (char *) block_data; 160 block_len = 0;
168 msg.len = 0; 161 block_data[block_len++] = reg = data[0];
169 block_data[msg.len++] = reg = data[0];
170 do { 162 do {
171 block_data[msg.len++] = 163 block_data[block_len++] = data[1];
172 /*decoder->reg[reg++] =*/ data[1]; 164 reg++;
173 len -= 2; 165 len -= 2;
174 data += 2; 166 data += 2;
175 } while (len >= 2 && data[0] == reg && 167 } while (len >= 2 && data[0] == reg &&
176 msg.len < 32); 168 block_len < 32);
177 if ((ret = i2c_transfer(client->adapter, 169 if ((ret = i2c_master_send(client, block_data,
178 &msg, 1)) < 0) 170 block_len)) < 0)
179 break; 171 break;
180 } 172 }
181 } else { 173 } else {
diff --git a/drivers/media/video/saa711x.c b/drivers/media/video/saa711x.c
index 6c161f2f5e..708fae51e8 100644
--- a/drivers/media/video/saa711x.c
+++ b/drivers/media/video/saa711x.c
@@ -45,7 +45,6 @@ MODULE_AUTHOR("Dave Perks, Jose Ignacio Gijon, Joerg Heckenbach, Mark McClelland
45MODULE_LICENSE("GPL"); 45MODULE_LICENSE("GPL");
46 46
47#include <linux/i2c.h> 47#include <linux/i2c.h>
48#include <linux/i2c-dev.h>
49 48
50#define I2C_NAME(s) (s)->name 49#define I2C_NAME(s) (s)->name
51 50
diff --git a/drivers/media/video/saa7185.c b/drivers/media/video/saa7185.c
index 3ed0edb870..9f99ee1303 100644
--- a/drivers/media/video/saa7185.c
+++ b/drivers/media/video/saa7185.c
@@ -49,7 +49,6 @@ MODULE_AUTHOR("Dave Perks");
49MODULE_LICENSE("GPL"); 49MODULE_LICENSE("GPL");
50 50
51#include <linux/i2c.h> 51#include <linux/i2c.h>
52#include <linux/i2c-dev.h>
53 52
54#define I2C_NAME(s) (s)->name 53#define I2C_NAME(s) (s)->name
55 54
@@ -113,24 +112,21 @@ saa7185_write_block (struct i2c_client *client,
113 if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { 112 if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
114 /* do raw I2C, not smbus compatible */ 113 /* do raw I2C, not smbus compatible */
115 struct saa7185 *encoder = i2c_get_clientdata(client); 114 struct saa7185 *encoder = i2c_get_clientdata(client);
116 struct i2c_msg msg;
117 u8 block_data[32]; 115 u8 block_data[32];
116 int block_len;
118 117
119 msg.addr = client->addr;
120 msg.flags = 0;
121 while (len >= 2) { 118 while (len >= 2) {
122 msg.buf = (char *) block_data; 119 block_len = 0;
123 msg.len = 0; 120 block_data[block_len++] = reg = data[0];
124 block_data[msg.len++] = reg = data[0];
125 do { 121 do {
126 block_data[msg.len++] = 122 block_data[block_len++] =
127 encoder->reg[reg++] = data[1]; 123 encoder->reg[reg++] = data[1];
128 len -= 2; 124 len -= 2;
129 data += 2; 125 data += 2;
130 } while (len >= 2 && data[0] == reg && 126 } while (len >= 2 && data[0] == reg &&
131 msg.len < 32); 127 block_len < 32);
132 if ((ret = i2c_transfer(client->adapter, 128 if ((ret = i2c_master_send(client, block_data,
133 &msg, 1)) < 0) 129 block_len)) < 0)
134 break; 130 break;
135 } 131 }
136 } else { 132 } else {
diff --git a/drivers/media/video/vpx3220.c b/drivers/media/video/vpx3220.c
index d0a1e72ea8..4cd5799674 100644
--- a/drivers/media/video/vpx3220.c
+++ b/drivers/media/video/vpx3220.c
@@ -30,7 +30,6 @@
30#include <asm/uaccess.h> 30#include <asm/uaccess.h>
31 31
32#include <linux/i2c.h> 32#include <linux/i2c.h>
33#include <linux/i2c-dev.h>
34 33
35#define I2C_NAME(x) (x)->name 34#define I2C_NAME(x) (x)->name
36 35
diff --git a/drivers/media/video/zoran.h b/drivers/media/video/zoran.h
index 9fe6ad3b63..ad04a12949 100644
--- a/drivers/media/video/zoran.h
+++ b/drivers/media/video/zoran.h
@@ -395,7 +395,7 @@ struct zoran {
395 struct videocodec *codec; /* video codec */ 395 struct videocodec *codec; /* video codec */
396 struct videocodec *vfe; /* video front end */ 396 struct videocodec *vfe; /* video front end */
397 397
398 struct semaphore resource_lock; /* prevent evil stuff */ 398 struct mutex resource_lock; /* prevent evil stuff */
399 399
400 u8 initialized; /* flag if zoran has been correctly initalized */ 400 u8 initialized; /* flag if zoran has been correctly initalized */
401 int user; /* number of current users */ 401 int user; /* number of current users */
diff --git a/drivers/media/video/zoran_card.c b/drivers/media/video/zoran_card.c
index 246e67cd8b..b22dbb6d18 100644
--- a/drivers/media/video/zoran_card.c
+++ b/drivers/media/video/zoran_card.c
@@ -47,6 +47,7 @@
47#include <linux/interrupt.h> 47#include <linux/interrupt.h>
48#include <linux/video_decoder.h> 48#include <linux/video_decoder.h>
49#include <linux/video_encoder.h> 49#include <linux/video_encoder.h>
50#include <linux/mutex.h>
50 51
51#include <asm/io.h> 52#include <asm/io.h>
52 53
@@ -673,7 +674,7 @@ zoran_i2c_client_register (struct i2c_client *client)
673 KERN_DEBUG "%s: i2c_client_register() - driver id = %d\n", 674 KERN_DEBUG "%s: i2c_client_register() - driver id = %d\n",
674 ZR_DEVNAME(zr), client->driver->id); 675 ZR_DEVNAME(zr), client->driver->id);
675 676
676 down(&zr->resource_lock); 677 mutex_lock(&zr->resource_lock);
677 678
678 if (zr->user > 0) { 679 if (zr->user > 0) {
679 /* we're already busy, so we keep a reference to 680 /* we're already busy, so we keep a reference to
@@ -694,7 +695,7 @@ zoran_i2c_client_register (struct i2c_client *client)
694 } 695 }
695 696
696clientreg_unlock_and_return: 697clientreg_unlock_and_return:
697 up(&zr->resource_lock); 698 mutex_unlock(&zr->resource_lock);
698 699
699 return res; 700 return res;
700} 701}
@@ -707,7 +708,7 @@ zoran_i2c_client_unregister (struct i2c_client *client)
707 708
708 dprintk(2, KERN_DEBUG "%s: i2c_client_unregister()\n", ZR_DEVNAME(zr)); 709 dprintk(2, KERN_DEBUG "%s: i2c_client_unregister()\n", ZR_DEVNAME(zr));
709 710
710 down(&zr->resource_lock); 711 mutex_lock(&zr->resource_lock);
711 712
712 if (zr->user > 0) { 713 if (zr->user > 0) {
713 res = -EBUSY; 714 res = -EBUSY;
@@ -722,7 +723,7 @@ zoran_i2c_client_unregister (struct i2c_client *client)
722 snprintf(ZR_DEVNAME(zr), sizeof(ZR_DEVNAME(zr)), "MJPEG[%d]", zr->id); 723 snprintf(ZR_DEVNAME(zr), sizeof(ZR_DEVNAME(zr)), "MJPEG[%d]", zr->id);
723 } 724 }
724clientunreg_unlock_and_return: 725clientunreg_unlock_and_return:
725 up(&zr->resource_lock); 726 mutex_unlock(&zr->resource_lock);
726 return res; 727 return res;
727} 728}
728 729
@@ -995,10 +996,7 @@ test_interrupts (struct zoran *zr)
995static int __devinit 996static int __devinit
996zr36057_init (struct zoran *zr) 997zr36057_init (struct zoran *zr)
997{ 998{
998 u32 *mem; 999 int j, err;
999 void *vdev;
1000 unsigned mem_needed;
1001 int j;
1002 int two = 2; 1000 int two = 2;
1003 int zero = 0; 1001 int zero = 0;
1004 1002
@@ -1049,19 +1047,16 @@ zr36057_init (struct zoran *zr)
1049 1047
1050 /* allocate memory *before* doing anything to the hardware 1048 /* allocate memory *before* doing anything to the hardware
1051 * in case allocation fails */ 1049 * in case allocation fails */
1052 mem_needed = BUZ_NUM_STAT_COM * 4; 1050 zr->stat_com = kzalloc(BUZ_NUM_STAT_COM * 4, GFP_KERNEL);
1053 mem = kzalloc(mem_needed, GFP_KERNEL); 1051 zr->video_dev = kmalloc(sizeof(struct video_device), GFP_KERNEL);
1054 vdev = (void *) kmalloc(sizeof(struct video_device), GFP_KERNEL); 1052 if (!zr->stat_com || !zr->video_dev) {
1055 if (!mem || !vdev) {
1056 dprintk(1, 1053 dprintk(1,
1057 KERN_ERR 1054 KERN_ERR
1058 "%s: zr36057_init() - kmalloc (STAT_COM) failed\n", 1055 "%s: zr36057_init() - kmalloc (STAT_COM) failed\n",
1059 ZR_DEVNAME(zr)); 1056 ZR_DEVNAME(zr));
1060 kfree(vdev); 1057 err = -ENOMEM;
1061 kfree(mem); 1058 goto exit_free;
1062 return -ENOMEM;
1063 } 1059 }
1064 zr->stat_com = mem;
1065 for (j = 0; j < BUZ_NUM_STAT_COM; j++) { 1060 for (j = 0; j < BUZ_NUM_STAT_COM; j++) {
1066 zr->stat_com[j] = 1; /* mark as unavailable to zr36057 */ 1061 zr->stat_com[j] = 1; /* mark as unavailable to zr36057 */
1067 } 1062 }
@@ -1069,16 +1064,11 @@ zr36057_init (struct zoran *zr)
1069 /* 1064 /*
1070 * Now add the template and register the device unit. 1065 * Now add the template and register the device unit.
1071 */ 1066 */
1072 zr->video_dev = vdev;
1073 memcpy(zr->video_dev, &zoran_template, sizeof(zoran_template)); 1067 memcpy(zr->video_dev, &zoran_template, sizeof(zoran_template));
1074 strcpy(zr->video_dev->name, ZR_DEVNAME(zr)); 1068 strcpy(zr->video_dev->name, ZR_DEVNAME(zr));
1075 if (video_register_device(zr->video_dev, VFL_TYPE_GRABBER, 1069 err = video_register_device(zr->video_dev, VFL_TYPE_GRABBER, video_nr);
1076 video_nr) < 0) { 1070 if (err < 0)
1077 zoran_unregister_i2c(zr); 1071 goto exit_unregister;
1078 kfree((void *) zr->stat_com);
1079 kfree(vdev);
1080 return -1;
1081 }
1082 1072
1083 zoran_init_hardware(zr); 1073 zoran_init_hardware(zr);
1084 if (*zr_debug > 2) 1074 if (*zr_debug > 2)
@@ -1092,6 +1082,13 @@ zr36057_init (struct zoran *zr)
1092 zr->zoran_proc = NULL; 1082 zr->zoran_proc = NULL;
1093 zr->initialized = 1; 1083 zr->initialized = 1;
1094 return 0; 1084 return 0;
1085
1086exit_unregister:
1087 zoran_unregister_i2c(zr);
1088exit_free:
1089 kfree(zr->stat_com);
1090 kfree(zr->video_dev);
1091 return err;
1095} 1092}
1096 1093
1097static void 1094static void
@@ -1121,7 +1118,7 @@ zoran_release (struct zoran *zr)
1121 btwrite(0, ZR36057_SPGPPCR); 1118 btwrite(0, ZR36057_SPGPPCR);
1122 free_irq(zr->pci_dev->irq, zr); 1119 free_irq(zr->pci_dev->irq, zr);
1123 /* unmap and free memory */ 1120 /* unmap and free memory */
1124 kfree((void *) zr->stat_com); 1121 kfree(zr->stat_com);
1125 zoran_proc_cleanup(zr); 1122 zoran_proc_cleanup(zr);
1126 iounmap(zr->zr36057_mem); 1123 iounmap(zr->zr36057_mem);
1127 pci_disable_device(zr->pci_dev); 1124 pci_disable_device(zr->pci_dev);
@@ -1206,7 +1203,7 @@ find_zr36057 (void)
1206 zr->id = zoran_num; 1203 zr->id = zoran_num;
1207 snprintf(ZR_DEVNAME(zr), sizeof(ZR_DEVNAME(zr)), "MJPEG[%u]", zr->id); 1204 snprintf(ZR_DEVNAME(zr), sizeof(ZR_DEVNAME(zr)), "MJPEG[%u]", zr->id);
1208 spin_lock_init(&zr->spinlock); 1205 spin_lock_init(&zr->spinlock);
1209 init_MUTEX(&zr->resource_lock); 1206 mutex_init(&zr->resource_lock);
1210 if (pci_enable_device(dev)) 1207 if (pci_enable_device(dev))
1211 continue; 1208 continue;
1212 zr->zr36057_adr = pci_resource_start(zr->pci_dev, 0); 1209 zr->zr36057_adr = pci_resource_start(zr->pci_dev, 0);
diff --git a/drivers/media/video/zoran_driver.c b/drivers/media/video/zoran_driver.c
index 485553be19..b2c6e01e39 100644
--- a/drivers/media/video/zoran_driver.c
+++ b/drivers/media/video/zoran_driver.c
@@ -81,6 +81,7 @@
81 81
82#include <linux/video_decoder.h> 82#include <linux/video_decoder.h>
83#include <linux/video_encoder.h> 83#include <linux/video_encoder.h>
84#include <linux/mutex.h>
84#include "zoran.h" 85#include "zoran.h"
85#include "zoran_device.h" 86#include "zoran_device.h"
86#include "zoran_card.h" 87#include "zoran_card.h"
@@ -1292,7 +1293,7 @@ zoran_open (struct inode *inode,
1292 1293
1293 /* see fs/device.c - the kernel already locks during open(), 1294 /* see fs/device.c - the kernel already locks during open(),
1294 * so locking ourselves only causes deadlocks */ 1295 * so locking ourselves only causes deadlocks */
1295 /*down(&zr->resource_lock);*/ 1296 /*mutex_lock(&zr->resource_lock);*/
1296 1297
1297 if (!zr->decoder) { 1298 if (!zr->decoder) {
1298 dprintk(1, 1299 dprintk(1,
@@ -1371,7 +1372,7 @@ zoran_open (struct inode *inode,
1371 if (zr->user++ == 0) 1372 if (zr->user++ == 0)
1372 first_open = 1; 1373 first_open = 1;
1373 1374
1374 /*up(&zr->resource_lock);*/ 1375 /*mutex_unlock(&zr->resource_lock);*/
1375 1376
1376 /* default setup - TODO: look at flags */ 1377 /* default setup - TODO: look at flags */
1377 if (first_open) { /* First device open */ 1378 if (first_open) { /* First device open */
@@ -1401,7 +1402,7 @@ open_unlock_and_return:
1401 1402
1402 /* if there's no device found, we didn't obtain the lock either */ 1403 /* if there's no device found, we didn't obtain the lock either */
1403 if (zr) { 1404 if (zr) {
1404 /*up(&zr->resource_lock);*/ 1405 /*mutex_unlock(&zr->resource_lock);*/
1405 } 1406 }
1406 1407
1407 return res; 1408 return res;
@@ -1419,7 +1420,7 @@ zoran_close (struct inode *inode,
1419 1420
1420 /* kernel locks (fs/device.c), so don't do that ourselves 1421 /* kernel locks (fs/device.c), so don't do that ourselves
1421 * (prevents deadlocks) */ 1422 * (prevents deadlocks) */
1422 /*down(&zr->resource_lock);*/ 1423 /*mutex_lock(&zr->resource_lock);*/
1423 1424
1424 zoran_close_end_session(file); 1425 zoran_close_end_session(file);
1425 1426
@@ -1466,7 +1467,7 @@ zoran_close (struct inode *inode,
1466 } 1467 }
1467 module_put(THIS_MODULE); 1468 module_put(THIS_MODULE);
1468 1469
1469 /*up(&zr->resource_lock);*/ 1470 /*mutex_unlock(&zr->resource_lock);*/
1470 1471
1471 dprintk(4, KERN_INFO "%s: zoran_close() done\n", ZR_DEVNAME(zr)); 1472 dprintk(4, KERN_INFO "%s: zoran_close() done\n", ZR_DEVNAME(zr));
1472 1473
@@ -2027,14 +2028,14 @@ zoran_do_ioctl (struct inode *inode,
2027 * but moving the free code outside the munmap() handler fixes 2028 * but moving the free code outside the munmap() handler fixes
2028 * all this... If someone knows why, please explain me (Ronald) 2029 * all this... If someone knows why, please explain me (Ronald)
2029 */ 2030 */
2030 if (!down_trylock(&zr->resource_lock)) { 2031 if (!!mutex_trylock(&zr->resource_lock)) {
2031 /* we obtained it! Let's try to free some things */ 2032 /* we obtained it! Let's try to free some things */
2032 if (fh->jpg_buffers.ready_to_be_freed) 2033 if (fh->jpg_buffers.ready_to_be_freed)
2033 jpg_fbuffer_free(file); 2034 jpg_fbuffer_free(file);
2034 if (fh->v4l_buffers.ready_to_be_freed) 2035 if (fh->v4l_buffers.ready_to_be_freed)
2035 v4l_fbuffer_free(file); 2036 v4l_fbuffer_free(file);
2036 2037
2037 up(&zr->resource_lock); 2038 mutex_unlock(&zr->resource_lock);
2038 } 2039 }
2039 2040
2040 switch (cmd) { 2041 switch (cmd) {
@@ -2051,12 +2052,12 @@ zoran_do_ioctl (struct inode *inode,
2051 2052
2052 vcap->channels = zr->card.inputs; 2053 vcap->channels = zr->card.inputs;
2053 vcap->audios = 0; 2054 vcap->audios = 0;
2054 down(&zr->resource_lock); 2055 mutex_lock(&zr->resource_lock);
2055 vcap->maxwidth = BUZ_MAX_WIDTH; 2056 vcap->maxwidth = BUZ_MAX_WIDTH;
2056 vcap->maxheight = BUZ_MAX_HEIGHT; 2057 vcap->maxheight = BUZ_MAX_HEIGHT;
2057 vcap->minwidth = BUZ_MIN_WIDTH; 2058 vcap->minwidth = BUZ_MIN_WIDTH;
2058 vcap->minheight = BUZ_MIN_HEIGHT; 2059 vcap->minheight = BUZ_MIN_HEIGHT;
2059 up(&zr->resource_lock); 2060 mutex_unlock(&zr->resource_lock);
2060 2061
2061 return 0; 2062 return 0;
2062 } 2063 }
@@ -2084,9 +2085,9 @@ zoran_do_ioctl (struct inode *inode,
2084 vchan->tuners = 0; 2085 vchan->tuners = 0;
2085 vchan->flags = 0; 2086 vchan->flags = 0;
2086 vchan->type = VIDEO_TYPE_CAMERA; 2087 vchan->type = VIDEO_TYPE_CAMERA;
2087 down(&zr->resource_lock); 2088 mutex_lock(&zr->resource_lock);
2088 vchan->norm = zr->norm; 2089 vchan->norm = zr->norm;
2089 up(&zr->resource_lock); 2090 mutex_unlock(&zr->resource_lock);
2090 vchan->channel = channel; 2091 vchan->channel = channel;
2091 2092
2092 return 0; 2093 return 0;
@@ -2113,7 +2114,7 @@ zoran_do_ioctl (struct inode *inode,
2113 "%s: VIDIOCSCHAN - channel=%d, norm=%d\n", 2114 "%s: VIDIOCSCHAN - channel=%d, norm=%d\n",
2114 ZR_DEVNAME(zr), vchan->channel, vchan->norm); 2115 ZR_DEVNAME(zr), vchan->channel, vchan->norm);
2115 2116
2116 down(&zr->resource_lock); 2117 mutex_lock(&zr->resource_lock);
2117 if ((res = zoran_set_input(zr, vchan->channel))) 2118 if ((res = zoran_set_input(zr, vchan->channel)))
2118 goto schan_unlock_and_return; 2119 goto schan_unlock_and_return;
2119 if ((res = zoran_set_norm(zr, vchan->norm))) 2120 if ((res = zoran_set_norm(zr, vchan->norm)))
@@ -2122,7 +2123,7 @@ zoran_do_ioctl (struct inode *inode,
2122 /* Make sure the changes come into effect */ 2123 /* Make sure the changes come into effect */
2123 res = wait_grab_pending(zr); 2124 res = wait_grab_pending(zr);
2124 schan_unlock_and_return: 2125 schan_unlock_and_return:
2125 up(&zr->resource_lock); 2126 mutex_unlock(&zr->resource_lock);
2126 return res; 2127 return res;
2127 } 2128 }
2128 break; 2129 break;
@@ -2134,7 +2135,7 @@ zoran_do_ioctl (struct inode *inode,
2134 dprintk(3, KERN_DEBUG "%s: VIDIOCGPICT\n", ZR_DEVNAME(zr)); 2135 dprintk(3, KERN_DEBUG "%s: VIDIOCGPICT\n", ZR_DEVNAME(zr));
2135 2136
2136 memset(vpict, 0, sizeof(struct video_picture)); 2137 memset(vpict, 0, sizeof(struct video_picture));
2137 down(&zr->resource_lock); 2138 mutex_lock(&zr->resource_lock);
2138 vpict->hue = zr->hue; 2139 vpict->hue = zr->hue;
2139 vpict->brightness = zr->brightness; 2140 vpict->brightness = zr->brightness;
2140 vpict->contrast = zr->contrast; 2141 vpict->contrast = zr->contrast;
@@ -2145,7 +2146,7 @@ zoran_do_ioctl (struct inode *inode,
2145 } else { 2146 } else {
2146 vpict->depth = 0; 2147 vpict->depth = 0;
2147 } 2148 }
2148 up(&zr->resource_lock); 2149 mutex_unlock(&zr->resource_lock);
2149 2150
2150 return 0; 2151 return 0;
2151 } 2152 }
@@ -2180,7 +2181,7 @@ zoran_do_ioctl (struct inode *inode,
2180 return -EINVAL; 2181 return -EINVAL;
2181 } 2182 }
2182 2183
2183 down(&zr->resource_lock); 2184 mutex_lock(&zr->resource_lock);
2184 2185
2185 decoder_command(zr, DECODER_SET_PICTURE, vpict); 2186 decoder_command(zr, DECODER_SET_PICTURE, vpict);
2186 2187
@@ -2191,7 +2192,7 @@ zoran_do_ioctl (struct inode *inode,
2191 2192
2192 fh->overlay_settings.format = &zoran_formats[i]; 2193 fh->overlay_settings.format = &zoran_formats[i];
2193 2194
2194 up(&zr->resource_lock); 2195 mutex_unlock(&zr->resource_lock);
2195 2196
2196 return 0; 2197 return 0;
2197 } 2198 }
@@ -2204,9 +2205,9 @@ zoran_do_ioctl (struct inode *inode,
2204 dprintk(3, KERN_DEBUG "%s: VIDIOCCAPTURE - on=%d\n", 2205 dprintk(3, KERN_DEBUG "%s: VIDIOCCAPTURE - on=%d\n",
2205 ZR_DEVNAME(zr), *on); 2206 ZR_DEVNAME(zr), *on);
2206 2207
2207 down(&zr->resource_lock); 2208 mutex_lock(&zr->resource_lock);
2208 res = setup_overlay(file, *on); 2209 res = setup_overlay(file, *on);
2209 up(&zr->resource_lock); 2210 mutex_unlock(&zr->resource_lock);
2210 2211
2211 return res; 2212 return res;
2212 } 2213 }
@@ -2219,12 +2220,12 @@ zoran_do_ioctl (struct inode *inode,
2219 dprintk(3, KERN_DEBUG "%s: VIDIOCGWIN\n", ZR_DEVNAME(zr)); 2220 dprintk(3, KERN_DEBUG "%s: VIDIOCGWIN\n", ZR_DEVNAME(zr));
2220 2221
2221 memset(vwin, 0, sizeof(struct video_window)); 2222 memset(vwin, 0, sizeof(struct video_window));
2222 down(&zr->resource_lock); 2223 mutex_lock(&zr->resource_lock);
2223 vwin->x = fh->overlay_settings.x; 2224 vwin->x = fh->overlay_settings.x;
2224 vwin->y = fh->overlay_settings.y; 2225 vwin->y = fh->overlay_settings.y;
2225 vwin->width = fh->overlay_settings.width; 2226 vwin->width = fh->overlay_settings.width;
2226 vwin->height = fh->overlay_settings.height; 2227 vwin->height = fh->overlay_settings.height;
2227 up(&zr->resource_lock); 2228 mutex_unlock(&zr->resource_lock);
2228 vwin->clipcount = 0; 2229 vwin->clipcount = 0;
2229 return 0; 2230 return 0;
2230 } 2231 }
@@ -2241,12 +2242,12 @@ zoran_do_ioctl (struct inode *inode,
2241 ZR_DEVNAME(zr), vwin->x, vwin->y, vwin->width, 2242 ZR_DEVNAME(zr), vwin->x, vwin->y, vwin->width,
2242 vwin->height, vwin->clipcount); 2243 vwin->height, vwin->clipcount);
2243 2244
2244 down(&zr->resource_lock); 2245 mutex_lock(&zr->resource_lock);
2245 res = 2246 res =
2246 setup_window(file, vwin->x, vwin->y, vwin->width, 2247 setup_window(file, vwin->x, vwin->y, vwin->width,
2247 vwin->height, vwin->clips, 2248 vwin->height, vwin->clips,
2248 vwin->clipcount, NULL); 2249 vwin->clipcount, NULL);
2249 up(&zr->resource_lock); 2250 mutex_unlock(&zr->resource_lock);
2250 2251
2251 return res; 2252 return res;
2252 } 2253 }
@@ -2258,9 +2259,9 @@ zoran_do_ioctl (struct inode *inode,
2258 2259
2259 dprintk(3, KERN_DEBUG "%s: VIDIOCGFBUF\n", ZR_DEVNAME(zr)); 2260 dprintk(3, KERN_DEBUG "%s: VIDIOCGFBUF\n", ZR_DEVNAME(zr));
2260 2261
2261 down(&zr->resource_lock); 2262 mutex_lock(&zr->resource_lock);
2262 *vbuf = zr->buffer; 2263 *vbuf = zr->buffer;
2263 up(&zr->resource_lock); 2264 mutex_unlock(&zr->resource_lock);
2264 return 0; 2265 return 0;
2265 } 2266 }
2266 break; 2267 break;
@@ -2287,12 +2288,12 @@ zoran_do_ioctl (struct inode *inode,
2287 return -EINVAL; 2288 return -EINVAL;
2288 } 2289 }
2289 2290
2290 down(&zr->resource_lock); 2291 mutex_lock(&zr->resource_lock);
2291 res = 2292 res =
2292 setup_fbuffer(file, vbuf->base, &zoran_formats[i], 2293 setup_fbuffer(file, vbuf->base, &zoran_formats[i],
2293 vbuf->width, vbuf->height, 2294 vbuf->width, vbuf->height,
2294 vbuf->bytesperline); 2295 vbuf->bytesperline);
2295 up(&zr->resource_lock); 2296 mutex_unlock(&zr->resource_lock);
2296 2297
2297 return res; 2298 return res;
2298 } 2299 }
@@ -2305,9 +2306,9 @@ zoran_do_ioctl (struct inode *inode,
2305 dprintk(3, KERN_DEBUG "%s: VIDIOCSYNC - frame=%d\n", 2306 dprintk(3, KERN_DEBUG "%s: VIDIOCSYNC - frame=%d\n",
2306 ZR_DEVNAME(zr), *frame); 2307 ZR_DEVNAME(zr), *frame);
2307 2308
2308 down(&zr->resource_lock); 2309 mutex_lock(&zr->resource_lock);
2309 res = v4l_sync(file, *frame); 2310 res = v4l_sync(file, *frame);
2310 up(&zr->resource_lock); 2311 mutex_unlock(&zr->resource_lock);
2311 if (!res) 2312 if (!res)
2312 zr->v4l_sync_tail++; 2313 zr->v4l_sync_tail++;
2313 return res; 2314 return res;
@@ -2325,9 +2326,9 @@ zoran_do_ioctl (struct inode *inode,
2325 ZR_DEVNAME(zr), vmap->frame, vmap->width, vmap->height, 2326 ZR_DEVNAME(zr), vmap->frame, vmap->width, vmap->height,
2326 vmap->format); 2327 vmap->format);
2327 2328
2328 down(&zr->resource_lock); 2329 mutex_lock(&zr->resource_lock);
2329 res = v4l_grab(file, vmap); 2330 res = v4l_grab(file, vmap);
2330 up(&zr->resource_lock); 2331 mutex_unlock(&zr->resource_lock);
2331 return res; 2332 return res;
2332 } 2333 }
2333 break; 2334 break;
@@ -2348,7 +2349,7 @@ zoran_do_ioctl (struct inode *inode,
2348 i * fh->v4l_buffers.buffer_size; 2349 i * fh->v4l_buffers.buffer_size;
2349 } 2350 }
2350 2351
2351 down(&zr->resource_lock); 2352 mutex_lock(&zr->resource_lock);
2352 2353
2353 if (fh->jpg_buffers.allocated || fh->v4l_buffers.allocated) { 2354 if (fh->jpg_buffers.allocated || fh->v4l_buffers.allocated) {
2354 dprintk(1, 2355 dprintk(1,
@@ -2367,7 +2368,7 @@ zoran_do_ioctl (struct inode *inode,
2367 /* The next mmap will map the V4L buffers */ 2368 /* The next mmap will map the V4L buffers */
2368 fh->map_mode = ZORAN_MAP_MODE_RAW; 2369 fh->map_mode = ZORAN_MAP_MODE_RAW;
2369 v4l1reqbuf_unlock_and_return: 2370 v4l1reqbuf_unlock_and_return:
2370 up(&zr->resource_lock); 2371 mutex_unlock(&zr->resource_lock);
2371 2372
2372 return res; 2373 return res;
2373 } 2374 }
@@ -2421,7 +2422,7 @@ zoran_do_ioctl (struct inode *inode,
2421 bparams->major_version = MAJOR_VERSION; 2422 bparams->major_version = MAJOR_VERSION;
2422 bparams->minor_version = MINOR_VERSION; 2423 bparams->minor_version = MINOR_VERSION;
2423 2424
2424 down(&zr->resource_lock); 2425 mutex_lock(&zr->resource_lock);
2425 2426
2426 bparams->norm = zr->norm; 2427 bparams->norm = zr->norm;
2427 bparams->input = zr->input; 2428 bparams->input = zr->input;
@@ -2450,7 +2451,7 @@ zoran_do_ioctl (struct inode *inode,
2450 bparams->jpeg_markers = 2451 bparams->jpeg_markers =
2451 fh->jpg_settings.jpg_comp.jpeg_markers; 2452 fh->jpg_settings.jpg_comp.jpeg_markers;
2452 2453
2453 up(&zr->resource_lock); 2454 mutex_unlock(&zr->resource_lock);
2454 2455
2455 bparams->VFIFO_FB = 0; 2456 bparams->VFIFO_FB = 0;
2456 2457
@@ -2486,7 +2487,7 @@ zoran_do_ioctl (struct inode *inode,
2486 sizeof(bparams->COM_data)); 2487 sizeof(bparams->COM_data));
2487 settings.jpg_comp.jpeg_markers = bparams->jpeg_markers; 2488 settings.jpg_comp.jpeg_markers = bparams->jpeg_markers;
2488 2489
2489 down(&zr->resource_lock); 2490 mutex_lock(&zr->resource_lock);
2490 2491
2491 if (zr->codec_mode != BUZ_MODE_IDLE) { 2492 if (zr->codec_mode != BUZ_MODE_IDLE) {
2492 dprintk(1, 2493 dprintk(1,
@@ -2506,7 +2507,7 @@ zoran_do_ioctl (struct inode *inode,
2506 2507
2507 fh->jpg_settings = settings; 2508 fh->jpg_settings = settings;
2508 sparams_unlock_and_return: 2509 sparams_unlock_and_return:
2509 up(&zr->resource_lock); 2510 mutex_unlock(&zr->resource_lock);
2510 2511
2511 return res; 2512 return res;
2512 } 2513 }
@@ -2538,7 +2539,7 @@ zoran_do_ioctl (struct inode *inode,
2538 breq->size > MAX_KMALLOC_MEM) 2539 breq->size > MAX_KMALLOC_MEM)
2539 breq->size = MAX_KMALLOC_MEM; 2540 breq->size = MAX_KMALLOC_MEM;
2540 2541
2541 down(&zr->resource_lock); 2542 mutex_lock(&zr->resource_lock);
2542 2543
2543 if (fh->jpg_buffers.allocated || fh->v4l_buffers.allocated) { 2544 if (fh->jpg_buffers.allocated || fh->v4l_buffers.allocated) {
2544 dprintk(1, 2545 dprintk(1,
@@ -2561,7 +2562,7 @@ zoran_do_ioctl (struct inode *inode,
2561 * also be *_PLAY, but it doesn't matter here */ 2562 * also be *_PLAY, but it doesn't matter here */
2562 fh->map_mode = ZORAN_MAP_MODE_JPG_REC; 2563 fh->map_mode = ZORAN_MAP_MODE_JPG_REC;
2563 jpgreqbuf_unlock_and_return: 2564 jpgreqbuf_unlock_and_return:
2564 up(&zr->resource_lock); 2565 mutex_unlock(&zr->resource_lock);
2565 2566
2566 return res; 2567 return res;
2567 } 2568 }
@@ -2574,9 +2575,9 @@ zoran_do_ioctl (struct inode *inode,
2574 dprintk(3, KERN_DEBUG "%s: BUZIOC_QBUF_CAPT - frame=%d\n", 2575 dprintk(3, KERN_DEBUG "%s: BUZIOC_QBUF_CAPT - frame=%d\n",
2575 ZR_DEVNAME(zr), *frame); 2576 ZR_DEVNAME(zr), *frame);
2576 2577
2577 down(&zr->resource_lock); 2578 mutex_lock(&zr->resource_lock);
2578 res = jpg_qbuf(file, *frame, BUZ_MODE_MOTION_COMPRESS); 2579 res = jpg_qbuf(file, *frame, BUZ_MODE_MOTION_COMPRESS);
2579 up(&zr->resource_lock); 2580 mutex_unlock(&zr->resource_lock);
2580 2581
2581 return res; 2582 return res;
2582 } 2583 }
@@ -2589,9 +2590,9 @@ zoran_do_ioctl (struct inode *inode,
2589 dprintk(3, KERN_DEBUG "%s: BUZIOC_QBUF_PLAY - frame=%d\n", 2590 dprintk(3, KERN_DEBUG "%s: BUZIOC_QBUF_PLAY - frame=%d\n",
2590 ZR_DEVNAME(zr), *frame); 2591 ZR_DEVNAME(zr), *frame);
2591 2592
2592 down(&zr->resource_lock); 2593 mutex_lock(&zr->resource_lock);
2593 res = jpg_qbuf(file, *frame, BUZ_MODE_MOTION_DECOMPRESS); 2594 res = jpg_qbuf(file, *frame, BUZ_MODE_MOTION_DECOMPRESS);
2594 up(&zr->resource_lock); 2595 mutex_unlock(&zr->resource_lock);
2595 2596
2596 return res; 2597 return res;
2597 } 2598 }
@@ -2604,9 +2605,9 @@ zoran_do_ioctl (struct inode *inode,
2604 2605
2605 dprintk(3, KERN_DEBUG "%s: BUZIOC_SYNC\n", ZR_DEVNAME(zr)); 2606 dprintk(3, KERN_DEBUG "%s: BUZIOC_SYNC\n", ZR_DEVNAME(zr));
2606 2607
2607 down(&zr->resource_lock); 2608 mutex_lock(&zr->resource_lock);
2608 res = jpg_sync(file, bsync); 2609 res = jpg_sync(file, bsync);
2609 up(&zr->resource_lock); 2610 mutex_unlock(&zr->resource_lock);
2610 2611
2611 return res; 2612 return res;
2612 } 2613 }
@@ -2630,7 +2631,7 @@ zoran_do_ioctl (struct inode *inode,
2630 input = zr->card.input[bstat->input].muxsel; 2631 input = zr->card.input[bstat->input].muxsel;
2631 norm = VIDEO_MODE_AUTO; 2632 norm = VIDEO_MODE_AUTO;
2632 2633
2633 down(&zr->resource_lock); 2634 mutex_lock(&zr->resource_lock);
2634 2635
2635 if (zr->codec_mode != BUZ_MODE_IDLE) { 2636 if (zr->codec_mode != BUZ_MODE_IDLE) {
2636 dprintk(1, 2637 dprintk(1,
@@ -2655,7 +2656,7 @@ zoran_do_ioctl (struct inode *inode,
2655 decoder_command(zr, DECODER_SET_INPUT, &input); 2656 decoder_command(zr, DECODER_SET_INPUT, &input);
2656 decoder_command(zr, DECODER_SET_NORM, &zr->norm); 2657 decoder_command(zr, DECODER_SET_NORM, &zr->norm);
2657 gstat_unlock_and_return: 2658 gstat_unlock_and_return:
2658 up(&zr->resource_lock); 2659 mutex_unlock(&zr->resource_lock);
2659 2660
2660 if (!res) { 2661 if (!res) {
2661 bstat->signal = 2662 bstat->signal =
@@ -2763,7 +2764,7 @@ zoran_do_ioctl (struct inode *inode,
2763 switch (fmt->type) { 2764 switch (fmt->type) {
2764 case V4L2_BUF_TYPE_VIDEO_OVERLAY: 2765 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
2765 2766
2766 down(&zr->resource_lock); 2767 mutex_lock(&zr->resource_lock);
2767 2768
2768 fmt->fmt.win.w.left = fh->overlay_settings.x; 2769 fmt->fmt.win.w.left = fh->overlay_settings.x;
2769 fmt->fmt.win.w.top = fh->overlay_settings.y; 2770 fmt->fmt.win.w.top = fh->overlay_settings.y;
@@ -2776,14 +2777,14 @@ zoran_do_ioctl (struct inode *inode,
2776 else 2777 else
2777 fmt->fmt.win.field = V4L2_FIELD_TOP; 2778 fmt->fmt.win.field = V4L2_FIELD_TOP;
2778 2779
2779 up(&zr->resource_lock); 2780 mutex_unlock(&zr->resource_lock);
2780 2781
2781 break; 2782 break;
2782 2783
2783 case V4L2_BUF_TYPE_VIDEO_CAPTURE: 2784 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
2784 case V4L2_BUF_TYPE_VIDEO_OUTPUT: 2785 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
2785 2786
2786 down(&zr->resource_lock); 2787 mutex_lock(&zr->resource_lock);
2787 2788
2788 if (fmt->type == V4L2_BUF_TYPE_VIDEO_CAPTURE && 2789 if (fmt->type == V4L2_BUF_TYPE_VIDEO_CAPTURE &&
2789 fh->map_mode == ZORAN_MAP_MODE_RAW) { 2790 fh->map_mode == ZORAN_MAP_MODE_RAW) {
@@ -2837,7 +2838,7 @@ zoran_do_ioctl (struct inode *inode,
2837 V4L2_COLORSPACE_SMPTE170M; 2838 V4L2_COLORSPACE_SMPTE170M;
2838 } 2839 }
2839 2840
2840 up(&zr->resource_lock); 2841 mutex_unlock(&zr->resource_lock);
2841 2842
2842 break; 2843 break;
2843 2844
@@ -2870,7 +2871,7 @@ zoran_do_ioctl (struct inode *inode,
2870 fmt->fmt.win.w.height, 2871 fmt->fmt.win.w.height,
2871 fmt->fmt.win.clipcount, 2872 fmt->fmt.win.clipcount,
2872 fmt->fmt.win.bitmap); 2873 fmt->fmt.win.bitmap);
2873 down(&zr->resource_lock); 2874 mutex_lock(&zr->resource_lock);
2874 res = 2875 res =
2875 setup_window(file, fmt->fmt.win.w.left, 2876 setup_window(file, fmt->fmt.win.w.left,
2876 fmt->fmt.win.w.top, 2877 fmt->fmt.win.w.top,
@@ -2880,7 +2881,7 @@ zoran_do_ioctl (struct inode *inode,
2880 fmt->fmt.win.clips, 2881 fmt->fmt.win.clips,
2881 fmt->fmt.win.clipcount, 2882 fmt->fmt.win.clipcount,
2882 fmt->fmt.win.bitmap); 2883 fmt->fmt.win.bitmap);
2883 up(&zr->resource_lock); 2884 mutex_unlock(&zr->resource_lock);
2884 return res; 2885 return res;
2885 break; 2886 break;
2886 2887
@@ -2917,7 +2918,7 @@ zoran_do_ioctl (struct inode *inode,
2917 } 2918 }
2918 2919
2919 if (fmt->fmt.pix.pixelformat == V4L2_PIX_FMT_MJPEG) { 2920 if (fmt->fmt.pix.pixelformat == V4L2_PIX_FMT_MJPEG) {
2920 down(&zr->resource_lock); 2921 mutex_lock(&zr->resource_lock);
2921 2922
2922 settings = fh->jpg_settings; 2923 settings = fh->jpg_settings;
2923 2924
@@ -2995,7 +2996,7 @@ zoran_do_ioctl (struct inode *inode,
2995 ZORAN_MAP_MODE_JPG_REC : 2996 ZORAN_MAP_MODE_JPG_REC :
2996 ZORAN_MAP_MODE_JPG_PLAY; 2997 ZORAN_MAP_MODE_JPG_PLAY;
2997 sfmtjpg_unlock_and_return: 2998 sfmtjpg_unlock_and_return:
2998 up(&zr->resource_lock); 2999 mutex_unlock(&zr->resource_lock);
2999 } else { 3000 } else {
3000 for (i = 0; i < zoran_num_formats; i++) 3001 for (i = 0; i < zoran_num_formats; i++)
3001 if (fmt->fmt.pix.pixelformat == 3002 if (fmt->fmt.pix.pixelformat ==
@@ -3010,7 +3011,7 @@ zoran_do_ioctl (struct inode *inode,
3010 (char *) &printformat); 3011 (char *) &printformat);
3011 return -EINVAL; 3012 return -EINVAL;
3012 } 3013 }
3013 down(&zr->resource_lock); 3014 mutex_lock(&zr->resource_lock);
3014 if (fh->jpg_buffers.allocated || 3015 if (fh->jpg_buffers.allocated ||
3015 (fh->v4l_buffers.allocated && 3016 (fh->v4l_buffers.allocated &&
3016 fh->v4l_buffers.active != 3017 fh->v4l_buffers.active !=
@@ -3052,7 +3053,7 @@ zoran_do_ioctl (struct inode *inode,
3052 3053
3053 fh->map_mode = ZORAN_MAP_MODE_RAW; 3054 fh->map_mode = ZORAN_MAP_MODE_RAW;
3054 sfmtv4l_unlock_and_return: 3055 sfmtv4l_unlock_and_return:
3055 up(&zr->resource_lock); 3056 mutex_unlock(&zr->resource_lock);
3056 } 3057 }
3057 3058
3058 break; 3059 break;
@@ -3077,7 +3078,7 @@ zoran_do_ioctl (struct inode *inode,
3077 dprintk(3, KERN_DEBUG "%s: VIDIOC_G_FBUF\n", ZR_DEVNAME(zr)); 3078 dprintk(3, KERN_DEBUG "%s: VIDIOC_G_FBUF\n", ZR_DEVNAME(zr));
3078 3079
3079 memset(fb, 0, sizeof(*fb)); 3080 memset(fb, 0, sizeof(*fb));
3080 down(&zr->resource_lock); 3081 mutex_lock(&zr->resource_lock);
3081 fb->base = zr->buffer.base; 3082 fb->base = zr->buffer.base;
3082 fb->fmt.width = zr->buffer.width; 3083 fb->fmt.width = zr->buffer.width;
3083 fb->fmt.height = zr->buffer.height; 3084 fb->fmt.height = zr->buffer.height;
@@ -3086,7 +3087,7 @@ zoran_do_ioctl (struct inode *inode,
3086 fh->overlay_settings.format->fourcc; 3087 fh->overlay_settings.format->fourcc;
3087 } 3088 }
3088 fb->fmt.bytesperline = zr->buffer.bytesperline; 3089 fb->fmt.bytesperline = zr->buffer.bytesperline;
3089 up(&zr->resource_lock); 3090 mutex_unlock(&zr->resource_lock);
3090 fb->fmt.colorspace = V4L2_COLORSPACE_SRGB; 3091 fb->fmt.colorspace = V4L2_COLORSPACE_SRGB;
3091 fb->fmt.field = V4L2_FIELD_INTERLACED; 3092 fb->fmt.field = V4L2_FIELD_INTERLACED;
3092 fb->flags = V4L2_FBUF_FLAG_OVERLAY; 3093 fb->flags = V4L2_FBUF_FLAG_OVERLAY;
@@ -3121,12 +3122,12 @@ zoran_do_ioctl (struct inode *inode,
3121 return -EINVAL; 3122 return -EINVAL;
3122 } 3123 }
3123 3124
3124 down(&zr->resource_lock); 3125 mutex_lock(&zr->resource_lock);
3125 res = 3126 res =
3126 setup_fbuffer(file, fb->base, &zoran_formats[i], 3127 setup_fbuffer(file, fb->base, &zoran_formats[i],
3127 fb->fmt.width, fb->fmt.height, 3128 fb->fmt.width, fb->fmt.height,
3128 fb->fmt.bytesperline); 3129 fb->fmt.bytesperline);
3129 up(&zr->resource_lock); 3130 mutex_unlock(&zr->resource_lock);
3130 3131
3131 return res; 3132 return res;
3132 } 3133 }
@@ -3139,9 +3140,9 @@ zoran_do_ioctl (struct inode *inode,
3139 dprintk(3, KERN_DEBUG "%s: VIDIOC_PREVIEW - on=%d\n", 3140 dprintk(3, KERN_DEBUG "%s: VIDIOC_PREVIEW - on=%d\n",
3140 ZR_DEVNAME(zr), *on); 3141 ZR_DEVNAME(zr), *on);
3141 3142
3142 down(&zr->resource_lock); 3143 mutex_lock(&zr->resource_lock);
3143 res = setup_overlay(file, *on); 3144 res = setup_overlay(file, *on);
3144 up(&zr->resource_lock); 3145 mutex_unlock(&zr->resource_lock);
3145 3146
3146 return res; 3147 return res;
3147 } 3148 }
@@ -3163,7 +3164,7 @@ zoran_do_ioctl (struct inode *inode,
3163 return -EINVAL; 3164 return -EINVAL;
3164 } 3165 }
3165 3166
3166 down(&zr->resource_lock); 3167 mutex_lock(&zr->resource_lock);
3167 3168
3168 if (fh->v4l_buffers.allocated || fh->jpg_buffers.allocated) { 3169 if (fh->v4l_buffers.allocated || fh->jpg_buffers.allocated) {
3169 dprintk(1, 3170 dprintk(1,
@@ -3224,7 +3225,7 @@ zoran_do_ioctl (struct inode *inode,
3224 goto v4l2reqbuf_unlock_and_return; 3225 goto v4l2reqbuf_unlock_and_return;
3225 } 3226 }
3226 v4l2reqbuf_unlock_and_return: 3227 v4l2reqbuf_unlock_and_return:
3227 up(&zr->resource_lock); 3228 mutex_unlock(&zr->resource_lock);
3228 3229
3229 return 0; 3230 return 0;
3230 } 3231 }
@@ -3245,9 +3246,9 @@ zoran_do_ioctl (struct inode *inode,
3245 buf->type = type; 3246 buf->type = type;
3246 buf->index = index; 3247 buf->index = index;
3247 3248
3248 down(&zr->resource_lock); 3249 mutex_lock(&zr->resource_lock);
3249 res = zoran_v4l2_buffer_status(file, buf, buf->index); 3250 res = zoran_v4l2_buffer_status(file, buf, buf->index);
3250 up(&zr->resource_lock); 3251 mutex_unlock(&zr->resource_lock);
3251 3252
3252 return res; 3253 return res;
3253 } 3254 }
@@ -3262,7 +3263,7 @@ zoran_do_ioctl (struct inode *inode,
3262 KERN_DEBUG "%s: VIDIOC_QBUF - type=%d, index=%d\n", 3263 KERN_DEBUG "%s: VIDIOC_QBUF - type=%d, index=%d\n",
3263 ZR_DEVNAME(zr), buf->type, buf->index); 3264 ZR_DEVNAME(zr), buf->type, buf->index);
3264 3265
3265 down(&zr->resource_lock); 3266 mutex_lock(&zr->resource_lock);
3266 3267
3267 switch (fh->map_mode) { 3268 switch (fh->map_mode) {
3268 case ZORAN_MAP_MODE_RAW: 3269 case ZORAN_MAP_MODE_RAW:
@@ -3322,7 +3323,7 @@ zoran_do_ioctl (struct inode *inode,
3322 goto qbuf_unlock_and_return; 3323 goto qbuf_unlock_and_return;
3323 } 3324 }
3324 qbuf_unlock_and_return: 3325 qbuf_unlock_and_return:
3325 up(&zr->resource_lock); 3326 mutex_unlock(&zr->resource_lock);
3326 3327
3327 return res; 3328 return res;
3328 } 3329 }
@@ -3336,7 +3337,7 @@ zoran_do_ioctl (struct inode *inode,
3336 dprintk(3, KERN_DEBUG "%s: VIDIOC_DQBUF - type=%d\n", 3337 dprintk(3, KERN_DEBUG "%s: VIDIOC_DQBUF - type=%d\n",
3337 ZR_DEVNAME(zr), buf->type); 3338 ZR_DEVNAME(zr), buf->type);
3338 3339
3339 down(&zr->resource_lock); 3340 mutex_lock(&zr->resource_lock);
3340 3341
3341 switch (fh->map_mode) { 3342 switch (fh->map_mode) {
3342 case ZORAN_MAP_MODE_RAW: 3343 case ZORAN_MAP_MODE_RAW:
@@ -3410,7 +3411,7 @@ zoran_do_ioctl (struct inode *inode,
3410 goto dqbuf_unlock_and_return; 3411 goto dqbuf_unlock_and_return;
3411 } 3412 }
3412 dqbuf_unlock_and_return: 3413 dqbuf_unlock_and_return:
3413 up(&zr->resource_lock); 3414 mutex_unlock(&zr->resource_lock);
3414 3415
3415 return res; 3416 return res;
3416 } 3417 }
@@ -3422,7 +3423,7 @@ zoran_do_ioctl (struct inode *inode,
3422 3423
3423 dprintk(3, KERN_DEBUG "%s: VIDIOC_STREAMON\n", ZR_DEVNAME(zr)); 3424 dprintk(3, KERN_DEBUG "%s: VIDIOC_STREAMON\n", ZR_DEVNAME(zr));
3424 3425
3425 down(&zr->resource_lock); 3426 mutex_lock(&zr->resource_lock);
3426 3427
3427 switch (fh->map_mode) { 3428 switch (fh->map_mode) {
3428 case ZORAN_MAP_MODE_RAW: /* raw capture */ 3429 case ZORAN_MAP_MODE_RAW: /* raw capture */
@@ -3470,7 +3471,7 @@ zoran_do_ioctl (struct inode *inode,
3470 goto strmon_unlock_and_return; 3471 goto strmon_unlock_and_return;
3471 } 3472 }
3472 strmon_unlock_and_return: 3473 strmon_unlock_and_return:
3473 up(&zr->resource_lock); 3474 mutex_unlock(&zr->resource_lock);
3474 3475
3475 return res; 3476 return res;
3476 } 3477 }
@@ -3482,7 +3483,7 @@ zoran_do_ioctl (struct inode *inode,
3482 3483
3483 dprintk(3, KERN_DEBUG "%s: VIDIOC_STREAMOFF\n", ZR_DEVNAME(zr)); 3484 dprintk(3, KERN_DEBUG "%s: VIDIOC_STREAMOFF\n", ZR_DEVNAME(zr));
3484 3485
3485 down(&zr->resource_lock); 3486 mutex_lock(&zr->resource_lock);
3486 3487
3487 switch (fh->map_mode) { 3488 switch (fh->map_mode) {
3488 case ZORAN_MAP_MODE_RAW: /* raw capture */ 3489 case ZORAN_MAP_MODE_RAW: /* raw capture */
@@ -3540,7 +3541,7 @@ zoran_do_ioctl (struct inode *inode,
3540 goto strmoff_unlock_and_return; 3541 goto strmoff_unlock_and_return;
3541 } 3542 }
3542 strmoff_unlock_and_return: 3543 strmoff_unlock_and_return:
3543 up(&zr->resource_lock); 3544 mutex_unlock(&zr->resource_lock);
3544 3545
3545 return res; 3546 return res;
3546 } 3547 }
@@ -3600,7 +3601,7 @@ zoran_do_ioctl (struct inode *inode,
3600 ctrl->id > V4L2_CID_HUE) 3601 ctrl->id > V4L2_CID_HUE)
3601 return -EINVAL; 3602 return -EINVAL;
3602 3603
3603 down(&zr->resource_lock); 3604 mutex_lock(&zr->resource_lock);
3604 switch (ctrl->id) { 3605 switch (ctrl->id) {
3605 case V4L2_CID_BRIGHTNESS: 3606 case V4L2_CID_BRIGHTNESS:
3606 ctrl->value = zr->brightness; 3607 ctrl->value = zr->brightness;
@@ -3615,7 +3616,7 @@ zoran_do_ioctl (struct inode *inode,
3615 ctrl->value = zr->hue; 3616 ctrl->value = zr->hue;
3616 break; 3617 break;
3617 } 3618 }
3618 up(&zr->resource_lock); 3619 mutex_unlock(&zr->resource_lock);
3619 3620
3620 return 0; 3621 return 0;
3621 } 3622 }
@@ -3642,7 +3643,7 @@ zoran_do_ioctl (struct inode *inode,
3642 return -EINVAL; 3643 return -EINVAL;
3643 } 3644 }
3644 3645
3645 down(&zr->resource_lock); 3646 mutex_lock(&zr->resource_lock);
3646 switch (ctrl->id) { 3647 switch (ctrl->id) {
3647 case V4L2_CID_BRIGHTNESS: 3648 case V4L2_CID_BRIGHTNESS:
3648 zr->brightness = ctrl->value; 3649 zr->brightness = ctrl->value;
@@ -3664,7 +3665,7 @@ zoran_do_ioctl (struct inode *inode,
3664 3665
3665 decoder_command(zr, DECODER_SET_PICTURE, &pict); 3666 decoder_command(zr, DECODER_SET_PICTURE, &pict);
3666 3667
3667 up(&zr->resource_lock); 3668 mutex_unlock(&zr->resource_lock);
3668 3669
3669 return 0; 3670 return 0;
3670 } 3671 }
@@ -3732,9 +3733,9 @@ zoran_do_ioctl (struct inode *inode,
3732 3733
3733 dprintk(3, KERN_DEBUG "%s: VIDIOC_G_STD\n", ZR_DEVNAME(zr)); 3734 dprintk(3, KERN_DEBUG "%s: VIDIOC_G_STD\n", ZR_DEVNAME(zr));
3734 3735
3735 down(&zr->resource_lock); 3736 mutex_lock(&zr->resource_lock);
3736 norm = zr->norm; 3737 norm = zr->norm;
3737 up(&zr->resource_lock); 3738 mutex_unlock(&zr->resource_lock);
3738 3739
3739 switch (norm) { 3740 switch (norm) {
3740 case VIDEO_MODE_PAL: 3741 case VIDEO_MODE_PAL:
@@ -3776,13 +3777,13 @@ zoran_do_ioctl (struct inode *inode,
3776 return -EINVAL; 3777 return -EINVAL;
3777 } 3778 }
3778 3779
3779 down(&zr->resource_lock); 3780 mutex_lock(&zr->resource_lock);
3780 if ((res = zoran_set_norm(zr, norm))) 3781 if ((res = zoran_set_norm(zr, norm)))
3781 goto sstd_unlock_and_return; 3782 goto sstd_unlock_and_return;
3782 3783
3783 res = wait_grab_pending(zr); 3784 res = wait_grab_pending(zr);
3784 sstd_unlock_and_return: 3785 sstd_unlock_and_return:
3785 up(&zr->resource_lock); 3786 mutex_unlock(&zr->resource_lock);
3786 return res; 3787 return res;
3787 } 3788 }
3788 break; 3789 break;
@@ -3809,9 +3810,9 @@ zoran_do_ioctl (struct inode *inode,
3809 inp->std = V4L2_STD_ALL; 3810 inp->std = V4L2_STD_ALL;
3810 3811
3811 /* Get status of video decoder */ 3812 /* Get status of video decoder */
3812 down(&zr->resource_lock); 3813 mutex_lock(&zr->resource_lock);
3813 decoder_command(zr, DECODER_GET_STATUS, &status); 3814 decoder_command(zr, DECODER_GET_STATUS, &status);
3814 up(&zr->resource_lock); 3815 mutex_unlock(&zr->resource_lock);
3815 3816
3816 if (!(status & DECODER_STATUS_GOOD)) { 3817 if (!(status & DECODER_STATUS_GOOD)) {
3817 inp->status |= V4L2_IN_ST_NO_POWER; 3818 inp->status |= V4L2_IN_ST_NO_POWER;
@@ -3830,9 +3831,9 @@ zoran_do_ioctl (struct inode *inode,
3830 3831
3831 dprintk(3, KERN_DEBUG "%s: VIDIOC_G_INPUT\n", ZR_DEVNAME(zr)); 3832 dprintk(3, KERN_DEBUG "%s: VIDIOC_G_INPUT\n", ZR_DEVNAME(zr));
3832 3833
3833 down(&zr->resource_lock); 3834 mutex_lock(&zr->resource_lock);
3834 *input = zr->input; 3835 *input = zr->input;
3835 up(&zr->resource_lock); 3836 mutex_unlock(&zr->resource_lock);
3836 3837
3837 return 0; 3838 return 0;
3838 } 3839 }
@@ -3845,14 +3846,14 @@ zoran_do_ioctl (struct inode *inode,
3845 dprintk(3, KERN_DEBUG "%s: VIDIOC_S_INPUT - input=%d\n", 3846 dprintk(3, KERN_DEBUG "%s: VIDIOC_S_INPUT - input=%d\n",
3846 ZR_DEVNAME(zr), *input); 3847 ZR_DEVNAME(zr), *input);
3847 3848
3848 down(&zr->resource_lock); 3849 mutex_lock(&zr->resource_lock);
3849 if ((res = zoran_set_input(zr, *input))) 3850 if ((res = zoran_set_input(zr, *input)))
3850 goto sinput_unlock_and_return; 3851 goto sinput_unlock_and_return;
3851 3852
3852 /* Make sure the changes come into effect */ 3853 /* Make sure the changes come into effect */
3853 res = wait_grab_pending(zr); 3854 res = wait_grab_pending(zr);
3854 sinput_unlock_and_return: 3855 sinput_unlock_and_return:
3855 up(&zr->resource_lock); 3856 mutex_unlock(&zr->resource_lock);
3856 return res; 3857 return res;
3857 } 3858 }
3858 break; 3859 break;
@@ -3914,7 +3915,7 @@ zoran_do_ioctl (struct inode *inode,
3914 memset(cropcap, 0, sizeof(*cropcap)); 3915 memset(cropcap, 0, sizeof(*cropcap));
3915 cropcap->type = type; 3916 cropcap->type = type;
3916 3917
3917 down(&zr->resource_lock); 3918 mutex_lock(&zr->resource_lock);
3918 3919
3919 if (cropcap->type != V4L2_BUF_TYPE_VIDEO_OUTPUT && 3920 if (cropcap->type != V4L2_BUF_TYPE_VIDEO_OUTPUT &&
3920 (cropcap->type != V4L2_BUF_TYPE_VIDEO_CAPTURE || 3921 (cropcap->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
@@ -3934,7 +3935,7 @@ zoran_do_ioctl (struct inode *inode,
3934 cropcap->defrect.width = BUZ_MIN_WIDTH; 3935 cropcap->defrect.width = BUZ_MIN_WIDTH;
3935 cropcap->defrect.height = BUZ_MIN_HEIGHT; 3936 cropcap->defrect.height = BUZ_MIN_HEIGHT;
3936 cropcap_unlock_and_return: 3937 cropcap_unlock_and_return:
3937 up(&zr->resource_lock); 3938 mutex_unlock(&zr->resource_lock);
3938 return res; 3939 return res;
3939 } 3940 }
3940 break; 3941 break;
@@ -3950,7 +3951,7 @@ zoran_do_ioctl (struct inode *inode,
3950 memset(crop, 0, sizeof(*crop)); 3951 memset(crop, 0, sizeof(*crop));
3951 crop->type = type; 3952 crop->type = type;
3952 3953
3953 down(&zr->resource_lock); 3954 mutex_lock(&zr->resource_lock);
3954 3955
3955 if (crop->type != V4L2_BUF_TYPE_VIDEO_OUTPUT && 3956 if (crop->type != V4L2_BUF_TYPE_VIDEO_OUTPUT &&
3956 (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE || 3957 (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
@@ -3969,7 +3970,7 @@ zoran_do_ioctl (struct inode *inode,
3969 crop->c.height = fh->jpg_settings.img_height; 3970 crop->c.height = fh->jpg_settings.img_height;
3970 3971
3971 gcrop_unlock_and_return: 3972 gcrop_unlock_and_return:
3972 up(&zr->resource_lock); 3973 mutex_unlock(&zr->resource_lock);
3973 3974
3974 return res; 3975 return res;
3975 } 3976 }
@@ -3988,7 +3989,7 @@ zoran_do_ioctl (struct inode *inode,
3988 ZR_DEVNAME(zr), crop->type, crop->c.left, crop->c.top, 3989 ZR_DEVNAME(zr), crop->type, crop->c.left, crop->c.top,
3989 crop->c.width, crop->c.height); 3990 crop->c.width, crop->c.height);
3990 3991
3991 down(&zr->resource_lock); 3992 mutex_lock(&zr->resource_lock);
3992 3993
3993 if (fh->jpg_buffers.allocated || fh->v4l_buffers.allocated) { 3994 if (fh->jpg_buffers.allocated || fh->v4l_buffers.allocated) {
3994 dprintk(1, 3995 dprintk(1,
@@ -4024,7 +4025,7 @@ zoran_do_ioctl (struct inode *inode,
4024 fh->jpg_settings = settings; 4025 fh->jpg_settings = settings;
4025 4026
4026 scrop_unlock_and_return: 4027 scrop_unlock_and_return:
4027 up(&zr->resource_lock); 4028 mutex_unlock(&zr->resource_lock);
4028 return res; 4029 return res;
4029 } 4030 }
4030 break; 4031 break;
@@ -4038,7 +4039,7 @@ zoran_do_ioctl (struct inode *inode,
4038 4039
4039 memset(params, 0, sizeof(*params)); 4040 memset(params, 0, sizeof(*params));
4040 4041
4041 down(&zr->resource_lock); 4042 mutex_lock(&zr->resource_lock);
4042 4043
4043 params->quality = fh->jpg_settings.jpg_comp.quality; 4044 params->quality = fh->jpg_settings.jpg_comp.quality;
4044 params->APPn = fh->jpg_settings.jpg_comp.APPn; 4045 params->APPn = fh->jpg_settings.jpg_comp.APPn;
@@ -4053,7 +4054,7 @@ zoran_do_ioctl (struct inode *inode,
4053 params->jpeg_markers = 4054 params->jpeg_markers =
4054 fh->jpg_settings.jpg_comp.jpeg_markers; 4055 fh->jpg_settings.jpg_comp.jpeg_markers;
4055 4056
4056 up(&zr->resource_lock); 4057 mutex_unlock(&zr->resource_lock);
4057 4058
4058 return 0; 4059 return 0;
4059 } 4060 }
@@ -4074,7 +4075,7 @@ zoran_do_ioctl (struct inode *inode,
4074 4075
4075 settings.jpg_comp = *params; 4076 settings.jpg_comp = *params;
4076 4077
4077 down(&zr->resource_lock); 4078 mutex_lock(&zr->resource_lock);
4078 4079
4079 if (fh->v4l_buffers.active != ZORAN_FREE || 4080 if (fh->v4l_buffers.active != ZORAN_FREE ||
4080 fh->jpg_buffers.active != ZORAN_FREE) { 4081 fh->jpg_buffers.active != ZORAN_FREE) {
@@ -4093,7 +4094,7 @@ zoran_do_ioctl (struct inode *inode,
4093 zoran_v4l2_calc_bufsize(&fh->jpg_settings); 4094 zoran_v4l2_calc_bufsize(&fh->jpg_settings);
4094 fh->jpg_settings.jpg_comp = *params = settings.jpg_comp; 4095 fh->jpg_settings.jpg_comp = *params = settings.jpg_comp;
4095 sjpegc_unlock_and_return: 4096 sjpegc_unlock_and_return:
4096 up(&zr->resource_lock); 4097 mutex_unlock(&zr->resource_lock);
4097 4098
4098 return 0; 4099 return 0;
4099 } 4100 }
@@ -4127,7 +4128,7 @@ zoran_do_ioctl (struct inode *inode,
4127 4128
4128 switch (fmt->type) { 4129 switch (fmt->type) {
4129 case V4L2_BUF_TYPE_VIDEO_OVERLAY: 4130 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
4130 down(&zr->resource_lock); 4131 mutex_lock(&zr->resource_lock);
4131 4132
4132 if (fmt->fmt.win.w.width > BUZ_MAX_WIDTH) 4133 if (fmt->fmt.win.w.width > BUZ_MAX_WIDTH)
4133 fmt->fmt.win.w.width = BUZ_MAX_WIDTH; 4134 fmt->fmt.win.w.width = BUZ_MAX_WIDTH;
@@ -4138,7 +4139,7 @@ zoran_do_ioctl (struct inode *inode,
4138 if (fmt->fmt.win.w.height < BUZ_MIN_HEIGHT) 4139 if (fmt->fmt.win.w.height < BUZ_MIN_HEIGHT)
4139 fmt->fmt.win.w.height = BUZ_MIN_HEIGHT; 4140 fmt->fmt.win.w.height = BUZ_MIN_HEIGHT;
4140 4141
4141 up(&zr->resource_lock); 4142 mutex_unlock(&zr->resource_lock);
4142 break; 4143 break;
4143 4144
4144 case V4L2_BUF_TYPE_VIDEO_CAPTURE: 4145 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
@@ -4146,7 +4147,7 @@ zoran_do_ioctl (struct inode *inode,
4146 if (fmt->fmt.pix.bytesperline > 0) 4147 if (fmt->fmt.pix.bytesperline > 0)
4147 return -EINVAL; 4148 return -EINVAL;
4148 4149
4149 down(&zr->resource_lock); 4150 mutex_lock(&zr->resource_lock);
4150 4151
4151 if (fmt->fmt.pix.pixelformat == V4L2_PIX_FMT_MJPEG) { 4152 if (fmt->fmt.pix.pixelformat == V4L2_PIX_FMT_MJPEG) {
4152 settings = fh->jpg_settings; 4153 settings = fh->jpg_settings;
@@ -4229,7 +4230,7 @@ zoran_do_ioctl (struct inode *inode,
4229 goto tryfmt_unlock_and_return; 4230 goto tryfmt_unlock_and_return;
4230 } 4231 }
4231 tryfmt_unlock_and_return: 4232 tryfmt_unlock_and_return:
4232 up(&zr->resource_lock); 4233 mutex_unlock(&zr->resource_lock);
4233 4234
4234 return res; 4235 return res;
4235 break; 4236 break;
@@ -4280,7 +4281,7 @@ zoran_poll (struct file *file,
4280 * if no buffers queued or so, return POLLNVAL 4281 * if no buffers queued or so, return POLLNVAL
4281 */ 4282 */
4282 4283
4283 down(&zr->resource_lock); 4284 mutex_lock(&zr->resource_lock);
4284 4285
4285 switch (fh->map_mode) { 4286 switch (fh->map_mode) {
4286 case ZORAN_MAP_MODE_RAW: 4287 case ZORAN_MAP_MODE_RAW:
@@ -4329,7 +4330,7 @@ zoran_poll (struct file *file,
4329 } 4330 }
4330 4331
4331poll_unlock_and_return: 4332poll_unlock_and_return:
4332 up(&zr->resource_lock); 4333 mutex_unlock(&zr->resource_lock);
4333 4334
4334 return res; 4335 return res;
4335} 4336}
@@ -4385,7 +4386,7 @@ zoran_vm_close (struct vm_area_struct *vma)
4385 if (fh->jpg_buffers.buffer[i].map) 4386 if (fh->jpg_buffers.buffer[i].map)
4386 break; 4387 break;
4387 if (i == fh->jpg_buffers.num_buffers) { 4388 if (i == fh->jpg_buffers.num_buffers) {
4388 down(&zr->resource_lock); 4389 mutex_lock(&zr->resource_lock);
4389 4390
4390 if (fh->jpg_buffers.active != ZORAN_FREE) { 4391 if (fh->jpg_buffers.active != ZORAN_FREE) {
4391 jpg_qbuf(file, -1, zr->codec_mode); 4392 jpg_qbuf(file, -1, zr->codec_mode);
@@ -4398,7 +4399,7 @@ zoran_vm_close (struct vm_area_struct *vma)
4398 fh->jpg_buffers.allocated = 0; 4399 fh->jpg_buffers.allocated = 0;
4399 fh->jpg_buffers.ready_to_be_freed = 1; 4400 fh->jpg_buffers.ready_to_be_freed = 1;
4400 4401
4401 up(&zr->resource_lock); 4402 mutex_unlock(&zr->resource_lock);
4402 } 4403 }
4403 4404
4404 break; 4405 break;
@@ -4421,7 +4422,7 @@ zoran_vm_close (struct vm_area_struct *vma)
4421 if (fh->v4l_buffers.buffer[i].map) 4422 if (fh->v4l_buffers.buffer[i].map)
4422 break; 4423 break;
4423 if (i == fh->v4l_buffers.num_buffers) { 4424 if (i == fh->v4l_buffers.num_buffers) {
4424 down(&zr->resource_lock); 4425 mutex_lock(&zr->resource_lock);
4425 4426
4426 if (fh->v4l_buffers.active != ZORAN_FREE) { 4427 if (fh->v4l_buffers.active != ZORAN_FREE) {
4427 zr36057_set_memgrab(zr, 0); 4428 zr36057_set_memgrab(zr, 0);
@@ -4434,7 +4435,7 @@ zoran_vm_close (struct vm_area_struct *vma)
4434 fh->v4l_buffers.allocated = 0; 4435 fh->v4l_buffers.allocated = 0;
4435 fh->v4l_buffers.ready_to_be_freed = 1; 4436 fh->v4l_buffers.ready_to_be_freed = 1;
4436 4437
4437 up(&zr->resource_lock); 4438 mutex_unlock(&zr->resource_lock);
4438 } 4439 }
4439 4440
4440 break; 4441 break;
@@ -4489,7 +4490,7 @@ zoran_mmap (struct file *file,
4489 case ZORAN_MAP_MODE_JPG_PLAY: 4490 case ZORAN_MAP_MODE_JPG_PLAY:
4490 4491
4491 /* lock */ 4492 /* lock */
4492 down(&zr->resource_lock); 4493 mutex_lock(&zr->resource_lock);
4493 4494
4494 /* Map the MJPEG buffers */ 4495 /* Map the MJPEG buffers */
4495 if (!fh->jpg_buffers.allocated) { 4496 if (!fh->jpg_buffers.allocated) {
@@ -4579,13 +4580,13 @@ zoran_mmap (struct file *file,
4579 4580
4580 } 4581 }
4581 jpg_mmap_unlock_and_return: 4582 jpg_mmap_unlock_and_return:
4582 up(&zr->resource_lock); 4583 mutex_unlock(&zr->resource_lock);
4583 4584
4584 break; 4585 break;
4585 4586
4586 case ZORAN_MAP_MODE_RAW: 4587 case ZORAN_MAP_MODE_RAW:
4587 4588
4588 down(&zr->resource_lock); 4589 mutex_lock(&zr->resource_lock);
4589 4590
4590 /* Map the V4L buffers */ 4591 /* Map the V4L buffers */
4591 if (!fh->v4l_buffers.allocated) { 4592 if (!fh->v4l_buffers.allocated) {
@@ -4657,7 +4658,7 @@ zoran_mmap (struct file *file,
4657 break; 4658 break;
4658 } 4659 }
4659 v4l_mmap_unlock_and_return: 4660 v4l_mmap_unlock_and_return:
4660 up(&zr->resource_lock); 4661 mutex_unlock(&zr->resource_lock);
4661 4662
4662 break; 4663 break;
4663 4664
diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index 550f297448..fc3c8854f4 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -3,6 +3,7 @@
3# 3#
4 4
5menu "Multimedia Capabilities Port drivers" 5menu "Multimedia Capabilities Port drivers"
6 depends on ARCH_SA1100
6 7
7config MCP 8config MCP
8 tristate 9 tristate
diff --git a/drivers/mmc/Kconfig b/drivers/mmc/Kconfig
index 5d397b7a54..3f5d77f633 100644
--- a/drivers/mmc/Kconfig
+++ b/drivers/mmc/Kconfig
@@ -49,6 +49,17 @@ config MMC_PXA
49 49
50 If unsure, say N. 50 If unsure, say N.
51 51
52config MMC_SDHCI
53 tristate "Secure Digital Host Controller Interface support (EXPERIMENTAL)"
54 depends on PCI && MMC && EXPERIMENTAL
55 help
56 This select the generic Secure Digital Host Controller Interface.
57 It is used by manufacturers such as Texas Instruments(R), Ricoh(R)
58 and Toshiba(R). Most controllers found in laptops are of this type.
59 If you have a controller with this interface, say Y or M here.
60
61 If unsure, say N.
62
52config MMC_WBSD 63config MMC_WBSD
53 tristate "Winbond W83L51xD SD/MMC Card Interface support" 64 tristate "Winbond W83L51xD SD/MMC Card Interface support"
54 depends on MMC && ISA_DMA_API 65 depends on MMC && ISA_DMA_API
diff --git a/drivers/mmc/Makefile b/drivers/mmc/Makefile
index e351e71146..769d545284 100644
--- a/drivers/mmc/Makefile
+++ b/drivers/mmc/Makefile
@@ -17,6 +17,7 @@ obj-$(CONFIG_MMC_BLOCK) += mmc_block.o
17# 17#
18obj-$(CONFIG_MMC_ARMMMCI) += mmci.o 18obj-$(CONFIG_MMC_ARMMMCI) += mmci.o
19obj-$(CONFIG_MMC_PXA) += pxamci.o 19obj-$(CONFIG_MMC_PXA) += pxamci.o
20obj-$(CONFIG_MMC_SDHCI) += sdhci.o
20obj-$(CONFIG_MMC_WBSD) += wbsd.o 21obj-$(CONFIG_MMC_WBSD) += wbsd.o
21obj-$(CONFIG_MMC_AU1X) += au1xmmc.o 22obj-$(CONFIG_MMC_AU1X) += au1xmmc.o
22 23
diff --git a/drivers/mmc/sdhci.c b/drivers/mmc/sdhci.c
new file mode 100644
index 0000000000..8b811d9437
--- /dev/null
+++ b/drivers/mmc/sdhci.c
@@ -0,0 +1,1265 @@
1/*
2 * linux/drivers/mmc/sdhci.c - Secure Digital Host Controller Interface driver
3 *
4 * Copyright (C) 2005-2006 Pierre Ossman, All Rights Reserved.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
11 /*
12 * Note that PIO transfer is rather crappy atm. The buffer full/empty
13 * interrupts aren't reliable so we currently transfer the entire buffer
14 * directly. Patches to solve the problem are welcome.
15 */
16
17#include <linux/delay.h>
18#include <linux/highmem.h>
19#include <linux/pci.h>
20#include <linux/dma-mapping.h>
21
22#include <linux/mmc/host.h>
23#include <linux/mmc/protocol.h>
24
25#include <asm/scatterlist.h>
26
27#include "sdhci.h"
28
29#define DRIVER_NAME "sdhci"
30#define DRIVER_VERSION "0.11"
31
32#define BUGMAIL "<sdhci-devel@list.drzeus.cx>"
33
34#ifdef CONFIG_MMC_DEBUG
35#define DBG(f, x...) \
36 printk(KERN_DEBUG DRIVER_NAME " [%s()]: " f, __func__,## x)
37#else
38#define DBG(f, x...) do { } while (0)
39#endif
40
41static const struct pci_device_id pci_ids[] __devinitdata = {
42 /* handle any SD host controller */
43 {PCI_DEVICE_CLASS((PCI_CLASS_SYSTEM_SDHCI << 8), 0xFFFF00)},
44 { /* end: all zeroes */ },
45};
46
47MODULE_DEVICE_TABLE(pci, pci_ids);
48
49static void sdhci_prepare_data(struct sdhci_host *, struct mmc_data *);
50static void sdhci_finish_data(struct sdhci_host *);
51
52static void sdhci_send_command(struct sdhci_host *, struct mmc_command *);
53static void sdhci_finish_command(struct sdhci_host *);
54
55static void sdhci_dumpregs(struct sdhci_host *host)
56{
57 printk(KERN_DEBUG DRIVER_NAME ": ============== REGISTER DUMP ==============\n");
58
59 printk(KERN_DEBUG DRIVER_NAME ": Sys addr: 0x%08x | Version: 0x%08x\n",
60 readl(host->ioaddr + SDHCI_DMA_ADDRESS),
61 readw(host->ioaddr + SDHCI_HOST_VERSION));
62 printk(KERN_DEBUG DRIVER_NAME ": Blk size: 0x%08x | Blk cnt: 0x%08x\n",
63 readw(host->ioaddr + SDHCI_BLOCK_SIZE),
64 readw(host->ioaddr + SDHCI_BLOCK_COUNT));
65 printk(KERN_DEBUG DRIVER_NAME ": Argument: 0x%08x | Trn mode: 0x%08x\n",
66 readl(host->ioaddr + SDHCI_ARGUMENT),
67 readw(host->ioaddr + SDHCI_TRANSFER_MODE));
68 printk(KERN_DEBUG DRIVER_NAME ": Present: 0x%08x | Host ctl: 0x%08x\n",
69 readl(host->ioaddr + SDHCI_PRESENT_STATE),
70 readb(host->ioaddr + SDHCI_HOST_CONTROL));
71 printk(KERN_DEBUG DRIVER_NAME ": Power: 0x%08x | Blk gap: 0x%08x\n",
72 readb(host->ioaddr + SDHCI_POWER_CONTROL),
73 readb(host->ioaddr + SDHCI_BLOCK_GAP_CONTROL));
74 printk(KERN_DEBUG DRIVER_NAME ": Wake-up: 0x%08x | Clock: 0x%08x\n",
75 readb(host->ioaddr + SDHCI_WALK_UP_CONTROL),
76 readw(host->ioaddr + SDHCI_CLOCK_CONTROL));
77 printk(KERN_DEBUG DRIVER_NAME ": Timeout: 0x%08x | Int stat: 0x%08x\n",
78 readb(host->ioaddr + SDHCI_TIMEOUT_CONTROL),
79 readl(host->ioaddr + SDHCI_INT_STATUS));
80 printk(KERN_DEBUG DRIVER_NAME ": Int enab: 0x%08x | Sig enab: 0x%08x\n",
81 readl(host->ioaddr + SDHCI_INT_ENABLE),
82 readl(host->ioaddr + SDHCI_SIGNAL_ENABLE));
83 printk(KERN_DEBUG DRIVER_NAME ": AC12 err: 0x%08x | Slot int: 0x%08x\n",
84 readw(host->ioaddr + SDHCI_ACMD12_ERR),
85 readw(host->ioaddr + SDHCI_SLOT_INT_STATUS));
86 printk(KERN_DEBUG DRIVER_NAME ": Caps: 0x%08x | Max curr: 0x%08x\n",
87 readl(host->ioaddr + SDHCI_CAPABILITIES),
88 readl(host->ioaddr + SDHCI_MAX_CURRENT));
89
90 printk(KERN_DEBUG DRIVER_NAME ": ===========================================\n");
91}
92
93/*****************************************************************************\
94 * *
95 * Low level functions *
96 * *
97\*****************************************************************************/
98
99static void sdhci_reset(struct sdhci_host *host, u8 mask)
100{
101 writeb(mask, host->ioaddr + SDHCI_SOFTWARE_RESET);
102
103 if (mask & SDHCI_RESET_ALL) {
104 host->clock = 0;
105
106 mdelay(50);
107 }
108}
109
110static void sdhci_init(struct sdhci_host *host)
111{
112 u32 intmask;
113
114 sdhci_reset(host, SDHCI_RESET_ALL);
115
116 intmask = ~(SDHCI_INT_CARD_INT | SDHCI_INT_BUF_EMPTY | SDHCI_INT_BUF_FULL);
117
118 writel(intmask, host->ioaddr + SDHCI_INT_ENABLE);
119 writel(intmask, host->ioaddr + SDHCI_SIGNAL_ENABLE);
120
121 /* This is unknown magic. */
122 writeb(0xE, host->ioaddr + SDHCI_TIMEOUT_CONTROL);
123}
124
125static void sdhci_activate_led(struct sdhci_host *host)
126{
127 u8 ctrl;
128
129 ctrl = readb(host->ioaddr + SDHCI_HOST_CONTROL);
130 ctrl |= SDHCI_CTRL_LED;
131 writeb(ctrl, host->ioaddr + SDHCI_HOST_CONTROL);
132}
133
134static void sdhci_deactivate_led(struct sdhci_host *host)
135{
136 u8 ctrl;
137
138 ctrl = readb(host->ioaddr + SDHCI_HOST_CONTROL);
139 ctrl &= ~SDHCI_CTRL_LED;
140 writeb(ctrl, host->ioaddr + SDHCI_HOST_CONTROL);
141}
142
143/*****************************************************************************\
144 * *
145 * Core functions *
146 * *
147\*****************************************************************************/
148
149static inline char* sdhci_kmap_sg(struct sdhci_host* host)
150{
151 host->mapped_sg = kmap_atomic(host->cur_sg->page, KM_BIO_SRC_IRQ);
152 return host->mapped_sg + host->cur_sg->offset;
153}
154
155static inline void sdhci_kunmap_sg(struct sdhci_host* host)
156{
157 kunmap_atomic(host->mapped_sg, KM_BIO_SRC_IRQ);
158}
159
160static inline int sdhci_next_sg(struct sdhci_host* host)
161{
162 /*
163 * Skip to next SG entry.
164 */
165 host->cur_sg++;
166 host->num_sg--;
167
168 /*
169 * Any entries left?
170 */
171 if (host->num_sg > 0) {
172 host->offset = 0;
173 host->remain = host->cur_sg->length;
174 }
175
176 return host->num_sg;
177}
178
179static void sdhci_transfer_pio(struct sdhci_host *host)
180{
181 char *buffer;
182 u32 mask;
183 int bytes, size;
184 unsigned long max_jiffies;
185
186 BUG_ON(!host->data);
187
188 if (host->num_sg == 0)
189 return;
190
191 bytes = 0;
192 if (host->data->flags & MMC_DATA_READ)
193 mask = SDHCI_DATA_AVAILABLE;
194 else
195 mask = SDHCI_SPACE_AVAILABLE;
196
197 buffer = sdhci_kmap_sg(host) + host->offset;
198
199 /* Transfer shouldn't take more than 5 s */
200 max_jiffies = jiffies + HZ * 5;
201
202 while (host->size > 0) {
203 if (time_after(jiffies, max_jiffies)) {
204 printk(KERN_ERR "%s: PIO transfer stalled. "
205 "Please report this to "
206 BUGMAIL ".\n", mmc_hostname(host->mmc));
207 sdhci_dumpregs(host);
208
209 sdhci_kunmap_sg(host);
210
211 host->data->error = MMC_ERR_FAILED;
212 sdhci_finish_data(host);
213 return;
214 }
215
216 if (!(readl(host->ioaddr + SDHCI_PRESENT_STATE) & mask))
217 continue;
218
219 size = min(host->size, host->remain);
220
221 if (size >= 4) {
222 if (host->data->flags & MMC_DATA_READ)
223 *(u32*)buffer = readl(host->ioaddr + SDHCI_BUFFER);
224 else
225 writel(*(u32*)buffer, host->ioaddr + SDHCI_BUFFER);
226 size = 4;
227 } else if (size >= 2) {
228 if (host->data->flags & MMC_DATA_READ)
229 *(u16*)buffer = readw(host->ioaddr + SDHCI_BUFFER);
230 else
231 writew(*(u16*)buffer, host->ioaddr + SDHCI_BUFFER);
232 size = 2;
233 } else {
234 if (host->data->flags & MMC_DATA_READ)
235 *(u8*)buffer = readb(host->ioaddr + SDHCI_BUFFER);
236 else
237 writeb(*(u8*)buffer, host->ioaddr + SDHCI_BUFFER);
238 size = 1;
239 }
240
241 buffer += size;
242 host->offset += size;
243 host->remain -= size;
244
245 bytes += size;
246 host->size -= size;
247
248 if (host->remain == 0) {
249 sdhci_kunmap_sg(host);
250 if (sdhci_next_sg(host) == 0) {
251 DBG("PIO transfer: %d bytes\n", bytes);
252 return;
253 }
254 buffer = sdhci_kmap_sg(host);
255 }
256 }
257
258 sdhci_kunmap_sg(host);
259
260 DBG("PIO transfer: %d bytes\n", bytes);
261}
262
263static void sdhci_prepare_data(struct sdhci_host *host, struct mmc_data *data)
264{
265 u16 mode;
266
267 WARN_ON(host->data);
268
269 if (data == NULL) {
270 writew(0, host->ioaddr + SDHCI_TRANSFER_MODE);
271 return;
272 }
273
274 DBG("blksz %04x blks %04x flags %08x\n",
275 1 << data->blksz_bits, data->blocks, data->flags);
276 DBG("tsac %d ms nsac %d clk\n",
277 data->timeout_ns / 1000000, data->timeout_clks);
278
279 mode = SDHCI_TRNS_BLK_CNT_EN;
280 if (data->blocks > 1)
281 mode |= SDHCI_TRNS_MULTI;
282 if (data->flags & MMC_DATA_READ)
283 mode |= SDHCI_TRNS_READ;
284 if (host->flags & SDHCI_USE_DMA)
285 mode |= SDHCI_TRNS_DMA;
286
287 writew(mode, host->ioaddr + SDHCI_TRANSFER_MODE);
288
289 writew(1 << data->blksz_bits, host->ioaddr + SDHCI_BLOCK_SIZE);
290 writew(data->blocks, host->ioaddr + SDHCI_BLOCK_COUNT);
291
292 if (host->flags & SDHCI_USE_DMA) {
293 int count;
294
295 count = pci_map_sg(host->chip->pdev, data->sg, data->sg_len,
296 (data->flags & MMC_DATA_READ)?PCI_DMA_FROMDEVICE:PCI_DMA_TODEVICE);
297 BUG_ON(count != 1);
298
299 writel(sg_dma_address(data->sg), host->ioaddr + SDHCI_DMA_ADDRESS);
300 } else {
301 host->size = (1 << data->blksz_bits) * data->blocks;
302
303 host->cur_sg = data->sg;
304 host->num_sg = data->sg_len;
305
306 host->offset = 0;
307 host->remain = host->cur_sg->length;
308 }
309}
310
311static void sdhci_finish_data(struct sdhci_host *host)
312{
313 struct mmc_data *data;
314 u32 intmask;
315 u16 blocks;
316
317 BUG_ON(!host->data);
318
319 data = host->data;
320 host->data = NULL;
321
322 if (host->flags & SDHCI_USE_DMA) {
323 pci_unmap_sg(host->chip->pdev, data->sg, data->sg_len,
324 (data->flags & MMC_DATA_READ)?PCI_DMA_FROMDEVICE:PCI_DMA_TODEVICE);
325 } else {
326 intmask = readl(host->ioaddr + SDHCI_SIGNAL_ENABLE);
327 intmask &= ~(SDHCI_INT_BUF_EMPTY | SDHCI_INT_BUF_FULL);
328 writel(intmask, host->ioaddr + SDHCI_SIGNAL_ENABLE);
329
330 intmask = readl(host->ioaddr + SDHCI_INT_ENABLE);
331 intmask &= ~(SDHCI_INT_BUF_EMPTY | SDHCI_INT_BUF_FULL);
332 writel(intmask, host->ioaddr + SDHCI_INT_ENABLE);
333 }
334
335 /*
336 * Controller doesn't count down when in single block mode.
337 */
338 if ((data->blocks == 1) && (data->error == MMC_ERR_NONE))
339 blocks = 0;
340 else
341 blocks = readw(host->ioaddr + SDHCI_BLOCK_COUNT);
342 data->bytes_xfered = (1 << data->blksz_bits) * (data->blocks - blocks);
343
344 if ((data->error == MMC_ERR_NONE) && blocks) {
345 printk(KERN_ERR "%s: Controller signalled completion even "
346 "though there were blocks left. Please report this "
347 "to " BUGMAIL ".\n", mmc_hostname(host->mmc));
348 data->error = MMC_ERR_FAILED;
349 }
350
351 if (host->size != 0) {
352 printk(KERN_ERR "%s: %d bytes were left untransferred. "
353 "Please report this to " BUGMAIL ".\n",
354 mmc_hostname(host->mmc), host->size);
355 data->error = MMC_ERR_FAILED;
356 }
357
358 DBG("Ending data transfer (%d bytes)\n", data->bytes_xfered);
359
360 if (data->stop) {
361 /*
362 * The controller needs a reset of internal state machines
363 * upon error conditions.
364 */
365 if (data->error != MMC_ERR_NONE) {
366 sdhci_reset(host, SDHCI_RESET_CMD);
367 sdhci_reset(host, SDHCI_RESET_DATA);
368 }
369
370 sdhci_send_command(host, data->stop);
371 } else
372 tasklet_schedule(&host->finish_tasklet);
373}
374
375static void sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd)
376{
377 int flags;
378 u32 present;
379 unsigned long max_jiffies;
380
381 WARN_ON(host->cmd);
382
383 DBG("Sending cmd (%x)\n", cmd->opcode);
384
385 /* Wait max 10 ms */
386 max_jiffies = jiffies + (HZ + 99)/100;
387 do {
388 if (time_after(jiffies, max_jiffies)) {
389 printk(KERN_ERR "%s: Controller never released "
390 "inhibit bits. Please report this to "
391 BUGMAIL ".\n", mmc_hostname(host->mmc));
392 sdhci_dumpregs(host);
393 cmd->error = MMC_ERR_FAILED;
394 tasklet_schedule(&host->finish_tasklet);
395 return;
396 }
397 present = readl(host->ioaddr + SDHCI_PRESENT_STATE);
398 } while (present & (SDHCI_CMD_INHIBIT | SDHCI_DATA_INHIBIT));
399
400 mod_timer(&host->timer, jiffies + 10 * HZ);
401
402 host->cmd = cmd;
403
404 sdhci_prepare_data(host, cmd->data);
405
406 writel(cmd->arg, host->ioaddr + SDHCI_ARGUMENT);
407
408 if ((cmd->flags & MMC_RSP_136) && (cmd->flags & MMC_RSP_BUSY)) {
409 printk(KERN_ERR "%s: Unsupported response type! "
410 "Please report this to " BUGMAIL ".\n",
411 mmc_hostname(host->mmc));
412 cmd->error = MMC_ERR_INVALID;
413 tasklet_schedule(&host->finish_tasklet);
414 return;
415 }
416
417 if (!(cmd->flags & MMC_RSP_PRESENT))
418 flags = SDHCI_CMD_RESP_NONE;
419 else if (cmd->flags & MMC_RSP_136)
420 flags = SDHCI_CMD_RESP_LONG;
421 else if (cmd->flags & MMC_RSP_BUSY)
422 flags = SDHCI_CMD_RESP_SHORT_BUSY;
423 else
424 flags = SDHCI_CMD_RESP_SHORT;
425
426 if (cmd->flags & MMC_RSP_CRC)
427 flags |= SDHCI_CMD_CRC;
428 if (cmd->flags & MMC_RSP_OPCODE)
429 flags |= SDHCI_CMD_INDEX;
430 if (cmd->data)
431 flags |= SDHCI_CMD_DATA;
432
433 writel(SDHCI_MAKE_CMD(cmd->opcode, flags),
434 host->ioaddr + SDHCI_COMMAND);
435}
436
437static void sdhci_finish_command(struct sdhci_host *host)
438{
439 int i;
440
441 BUG_ON(host->cmd == NULL);
442
443 if (host->cmd->flags & MMC_RSP_PRESENT) {
444 if (host->cmd->flags & MMC_RSP_136) {
445 /* CRC is stripped so we need to do some shifting. */
446 for (i = 0;i < 4;i++) {
447 host->cmd->resp[i] = readl(host->ioaddr +
448 SDHCI_RESPONSE + (3-i)*4) << 8;
449 if (i != 3)
450 host->cmd->resp[i] |=
451 readb(host->ioaddr +
452 SDHCI_RESPONSE + (3-i)*4-1);
453 }
454 } else {
455 host->cmd->resp[0] = readl(host->ioaddr + SDHCI_RESPONSE);
456 }
457 }
458
459 host->cmd->error = MMC_ERR_NONE;
460
461 DBG("Ending cmd (%x)\n", host->cmd->opcode);
462
463 if (host->cmd->data) {
464 u32 intmask;
465
466 host->data = host->cmd->data;
467
468 if (!(host->flags & SDHCI_USE_DMA)) {
469 /*
470 * Don't enable the interrupts until now to make sure we
471 * get stable handling of the FIFO.
472 */
473 intmask = readl(host->ioaddr + SDHCI_INT_ENABLE);
474 intmask |= SDHCI_INT_BUF_EMPTY | SDHCI_INT_BUF_FULL;
475 writel(intmask, host->ioaddr + SDHCI_INT_ENABLE);
476
477 intmask = readl(host->ioaddr + SDHCI_SIGNAL_ENABLE);
478 intmask |= SDHCI_INT_BUF_EMPTY | SDHCI_INT_BUF_FULL;
479 writel(intmask, host->ioaddr + SDHCI_SIGNAL_ENABLE);
480
481 /*
482 * The buffer interrupts are to unreliable so we
483 * start the transfer immediatly.
484 */
485 sdhci_transfer_pio(host);
486 }
487 } else
488 tasklet_schedule(&host->finish_tasklet);
489
490 host->cmd = NULL;
491}
492
493static void sdhci_set_clock(struct sdhci_host *host, unsigned int clock)
494{
495 int div;
496 u16 clk;
497 unsigned long max_jiffies;
498
499 if (clock == host->clock)
500 return;
501
502 writew(0, host->ioaddr + SDHCI_CLOCK_CONTROL);
503
504 if (clock == 0)
505 goto out;
506
507 for (div = 1;div < 256;div *= 2) {
508 if ((host->max_clk / div) <= clock)
509 break;
510 }
511 div >>= 1;
512
513 clk = div << SDHCI_DIVIDER_SHIFT;
514 clk |= SDHCI_CLOCK_INT_EN;
515 writew(clk, host->ioaddr + SDHCI_CLOCK_CONTROL);
516
517 /* Wait max 10 ms */
518 max_jiffies = jiffies + (HZ + 99)/100;
519 do {
520 if (time_after(jiffies, max_jiffies)) {
521 printk(KERN_ERR "%s: Internal clock never stabilised. "
522 "Please report this to " BUGMAIL ".\n",
523 mmc_hostname(host->mmc));
524 sdhci_dumpregs(host);
525 return;
526 }
527 clk = readw(host->ioaddr + SDHCI_CLOCK_CONTROL);
528 } while (!(clk & SDHCI_CLOCK_INT_STABLE));
529
530 clk |= SDHCI_CLOCK_CARD_EN;
531 writew(clk, host->ioaddr + SDHCI_CLOCK_CONTROL);
532
533out:
534 host->clock = clock;
535}
536
537/*****************************************************************************\
538 * *
539 * MMC callbacks *
540 * *
541\*****************************************************************************/
542
543static void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq)
544{
545 struct sdhci_host *host;
546 unsigned long flags;
547
548 host = mmc_priv(mmc);
549
550 spin_lock_irqsave(&host->lock, flags);
551
552 WARN_ON(host->mrq != NULL);
553
554 sdhci_activate_led(host);
555
556 host->mrq = mrq;
557
558 if (!(readl(host->ioaddr + SDHCI_PRESENT_STATE) & SDHCI_CARD_PRESENT)) {
559 host->mrq->cmd->error = MMC_ERR_TIMEOUT;
560 tasklet_schedule(&host->finish_tasklet);
561 } else
562 sdhci_send_command(host, mrq->cmd);
563
564 spin_unlock_irqrestore(&host->lock, flags);
565}
566
567static void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
568{
569 struct sdhci_host *host;
570 unsigned long flags;
571 u8 ctrl;
572
573 host = mmc_priv(mmc);
574
575 spin_lock_irqsave(&host->lock, flags);
576
577 DBG("clock %uHz busmode %u powermode %u cs %u Vdd %u width %u\n",
578 ios->clock, ios->bus_mode, ios->power_mode, ios->chip_select,
579 ios->vdd, ios->bus_width);
580
581 /*
582 * Reset the chip on each power off.
583 * Should clear out any weird states.
584 */
585 if (ios->power_mode == MMC_POWER_OFF) {
586 writel(0, host->ioaddr + SDHCI_SIGNAL_ENABLE);
587 spin_unlock_irqrestore(&host->lock, flags);
588 sdhci_init(host);
589 spin_lock_irqsave(&host->lock, flags);
590 }
591
592 sdhci_set_clock(host, ios->clock);
593
594 if (ios->power_mode == MMC_POWER_OFF)
595 writeb(0, host->ioaddr + SDHCI_POWER_CONTROL);
596 else
597 writeb(0xFF, host->ioaddr + SDHCI_POWER_CONTROL);
598
599 ctrl = readb(host->ioaddr + SDHCI_HOST_CONTROL);
600 if (ios->bus_width == MMC_BUS_WIDTH_4)
601 ctrl |= SDHCI_CTRL_4BITBUS;
602 else
603 ctrl &= ~SDHCI_CTRL_4BITBUS;
604 writeb(ctrl, host->ioaddr + SDHCI_HOST_CONTROL);
605
606 spin_unlock_irqrestore(&host->lock, flags);
607}
608
609static int sdhci_get_ro(struct mmc_host *mmc)
610{
611 struct sdhci_host *host;
612 unsigned long flags;
613 int present;
614
615 host = mmc_priv(mmc);
616
617 spin_lock_irqsave(&host->lock, flags);
618
619 present = readl(host->ioaddr + SDHCI_PRESENT_STATE);
620
621 spin_unlock_irqrestore(&host->lock, flags);
622
623 return !(present & SDHCI_WRITE_PROTECT);
624}
625
626static struct mmc_host_ops sdhci_ops = {
627 .request = sdhci_request,
628 .set_ios = sdhci_set_ios,
629 .get_ro = sdhci_get_ro,
630};
631
632/*****************************************************************************\
633 * *
634 * Tasklets *
635 * *
636\*****************************************************************************/
637
638static void sdhci_tasklet_card(unsigned long param)
639{
640 struct sdhci_host *host;
641 unsigned long flags;
642
643 host = (struct sdhci_host*)param;
644
645 spin_lock_irqsave(&host->lock, flags);
646
647 if (!(readl(host->ioaddr + SDHCI_PRESENT_STATE) & SDHCI_CARD_PRESENT)) {
648 if (host->mrq) {
649 printk(KERN_ERR "%s: Card removed during transfer!\n",
650 mmc_hostname(host->mmc));
651 printk(KERN_ERR "%s: Resetting controller.\n",
652 mmc_hostname(host->mmc));
653
654 sdhci_reset(host, SDHCI_RESET_CMD);
655 sdhci_reset(host, SDHCI_RESET_DATA);
656
657 host->mrq->cmd->error = MMC_ERR_FAILED;
658 tasklet_schedule(&host->finish_tasklet);
659 }
660 }
661
662 spin_unlock_irqrestore(&host->lock, flags);
663
664 mmc_detect_change(host->mmc, msecs_to_jiffies(500));
665}
666
667static void sdhci_tasklet_finish(unsigned long param)
668{
669 struct sdhci_host *host;
670 unsigned long flags;
671 struct mmc_request *mrq;
672
673 host = (struct sdhci_host*)param;
674
675 spin_lock_irqsave(&host->lock, flags);
676
677 del_timer(&host->timer);
678
679 mrq = host->mrq;
680
681 DBG("Ending request, cmd (%x)\n", mrq->cmd->opcode);
682
683 /*
684 * The controller needs a reset of internal state machines
685 * upon error conditions.
686 */
687 if ((mrq->cmd->error != MMC_ERR_NONE) ||
688 (mrq->data && ((mrq->data->error != MMC_ERR_NONE) ||
689 (mrq->data->stop && (mrq->data->stop->error != MMC_ERR_NONE))))) {
690 sdhci_reset(host, SDHCI_RESET_CMD);
691 sdhci_reset(host, SDHCI_RESET_DATA);
692 }
693
694 host->mrq = NULL;
695 host->cmd = NULL;
696 host->data = NULL;
697
698 sdhci_deactivate_led(host);
699
700 spin_unlock_irqrestore(&host->lock, flags);
701
702 mmc_request_done(host->mmc, mrq);
703}
704
705static void sdhci_timeout_timer(unsigned long data)
706{
707 struct sdhci_host *host;
708 unsigned long flags;
709
710 host = (struct sdhci_host*)data;
711
712 spin_lock_irqsave(&host->lock, flags);
713
714 if (host->mrq) {
715 printk(KERN_ERR "%s: Timeout waiting for hardware interrupt. "
716 "Please report this to " BUGMAIL ".\n",
717 mmc_hostname(host->mmc));
718 sdhci_dumpregs(host);
719
720 if (host->data) {
721 host->data->error = MMC_ERR_TIMEOUT;
722 sdhci_finish_data(host);
723 } else {
724 if (host->cmd)
725 host->cmd->error = MMC_ERR_TIMEOUT;
726 else
727 host->mrq->cmd->error = MMC_ERR_TIMEOUT;
728
729 tasklet_schedule(&host->finish_tasklet);
730 }
731 }
732
733 spin_unlock_irqrestore(&host->lock, flags);
734}
735
736/*****************************************************************************\
737 * *
738 * Interrupt handling *
739 * *
740\*****************************************************************************/
741
742static void sdhci_cmd_irq(struct sdhci_host *host, u32 intmask)
743{
744 BUG_ON(intmask == 0);
745
746 if (!host->cmd) {
747 printk(KERN_ERR "%s: Got command interrupt even though no "
748 "command operation was in progress.\n",
749 mmc_hostname(host->mmc));
750 printk(KERN_ERR "%s: Please report this to " BUGMAIL ".\n",
751 mmc_hostname(host->mmc));
752 sdhci_dumpregs(host);
753 return;
754 }
755
756 if (intmask & SDHCI_INT_RESPONSE)
757 sdhci_finish_command(host);
758 else {
759 if (intmask & SDHCI_INT_TIMEOUT)
760 host->cmd->error = MMC_ERR_TIMEOUT;
761 else if (intmask & SDHCI_INT_CRC)
762 host->cmd->error = MMC_ERR_BADCRC;
763 else if (intmask & (SDHCI_INT_END_BIT | SDHCI_INT_INDEX))
764 host->cmd->error = MMC_ERR_FAILED;
765 else
766 host->cmd->error = MMC_ERR_INVALID;
767
768 tasklet_schedule(&host->finish_tasklet);
769 }
770}
771
772static void sdhci_data_irq(struct sdhci_host *host, u32 intmask)
773{
774 BUG_ON(intmask == 0);
775
776 if (!host->data) {
777 /*
778 * A data end interrupt is sent together with the response
779 * for the stop command.
780 */
781 if (intmask & SDHCI_INT_DATA_END)
782 return;
783
784 printk(KERN_ERR "%s: Got data interrupt even though no "
785 "data operation was in progress.\n",
786 mmc_hostname(host->mmc));
787 printk(KERN_ERR "%s: Please report this to " BUGMAIL ".\n",
788 mmc_hostname(host->mmc));
789 sdhci_dumpregs(host);
790
791 return;
792 }
793
794 if (intmask & SDHCI_INT_DATA_TIMEOUT)
795 host->data->error = MMC_ERR_TIMEOUT;
796 else if (intmask & SDHCI_INT_DATA_CRC)
797 host->data->error = MMC_ERR_BADCRC;
798 else if (intmask & SDHCI_INT_DATA_END_BIT)
799 host->data->error = MMC_ERR_FAILED;
800
801 if (host->data->error != MMC_ERR_NONE)
802 sdhci_finish_data(host);
803 else {
804 if (intmask & (SDHCI_INT_BUF_FULL | SDHCI_INT_BUF_EMPTY))
805 sdhci_transfer_pio(host);
806
807 if (intmask & SDHCI_INT_DATA_END)
808 sdhci_finish_data(host);
809 }
810}
811
812static irqreturn_t sdhci_irq(int irq, void *dev_id, struct pt_regs *regs)
813{
814 irqreturn_t result;
815 struct sdhci_host* host = dev_id;
816 u32 intmask;
817
818 spin_lock(&host->lock);
819
820 intmask = readl(host->ioaddr + SDHCI_INT_STATUS);
821
822 if (!intmask) {
823 result = IRQ_NONE;
824 goto out;
825 }
826
827 DBG("*** %s got interrupt: 0x%08x\n", host->slot_descr, intmask);
828
829 if (intmask & (SDHCI_INT_CARD_INSERT | SDHCI_INT_CARD_REMOVE))
830 tasklet_schedule(&host->card_tasklet);
831
832 if (intmask & SDHCI_INT_CMD_MASK) {
833 sdhci_cmd_irq(host, intmask & SDHCI_INT_CMD_MASK);
834
835 writel(intmask & SDHCI_INT_CMD_MASK,
836 host->ioaddr + SDHCI_INT_STATUS);
837 }
838
839 if (intmask & SDHCI_INT_DATA_MASK) {
840 sdhci_data_irq(host, intmask & SDHCI_INT_DATA_MASK);
841
842 writel(intmask & SDHCI_INT_DATA_MASK,
843 host->ioaddr + SDHCI_INT_STATUS);
844 }
845
846 intmask &= ~(SDHCI_INT_CMD_MASK | SDHCI_INT_DATA_MASK);
847
848 if (intmask & SDHCI_INT_CARD_INT) {
849 printk(KERN_ERR "%s: Unexpected card interrupt. Please "
850 "report this to " BUGMAIL ".\n",
851 mmc_hostname(host->mmc));
852 sdhci_dumpregs(host);
853 }
854
855 if (intmask & SDHCI_INT_BUS_POWER) {
856 printk(KERN_ERR "%s: Unexpected bus power interrupt. Please "
857 "report this to " BUGMAIL ".\n",
858 mmc_hostname(host->mmc));
859 sdhci_dumpregs(host);
860 }
861
862 if (intmask & SDHCI_INT_ACMD12ERR) {
863 printk(KERN_ERR "%s: Unexpected auto CMD12 error. Please "
864 "report this to " BUGMAIL ".\n",
865 mmc_hostname(host->mmc));
866 sdhci_dumpregs(host);
867
868 writew(~0, host->ioaddr + SDHCI_ACMD12_ERR);
869 }
870
871 if (intmask)
872 writel(intmask, host->ioaddr + SDHCI_INT_STATUS);
873
874 result = IRQ_HANDLED;
875
876out:
877 spin_unlock(&host->lock);
878
879 return result;
880}
881
882/*****************************************************************************\
883 * *
884 * Suspend/resume *
885 * *
886\*****************************************************************************/
887
888#ifdef CONFIG_PM
889
890static int sdhci_suspend (struct pci_dev *pdev, pm_message_t state)
891{
892 struct sdhci_chip *chip;
893 int i, ret;
894
895 chip = pci_get_drvdata(pdev);
896 if (!chip)
897 return 0;
898
899 DBG("Suspending...\n");
900
901 for (i = 0;i < chip->num_slots;i++) {
902 if (!chip->hosts[i])
903 continue;
904 ret = mmc_suspend_host(chip->hosts[i]->mmc, state);
905 if (ret) {
906 for (i--;i >= 0;i--)
907 mmc_resume_host(chip->hosts[i]->mmc);
908 return ret;
909 }
910 }
911
912 pci_save_state(pdev);
913 pci_enable_wake(pdev, pci_choose_state(pdev, state), 0);
914 pci_disable_device(pdev);
915 pci_set_power_state(pdev, pci_choose_state(pdev, state));
916
917 return 0;
918}
919
920static int sdhci_resume (struct pci_dev *pdev)
921{
922 struct sdhci_chip *chip;
923 int i, ret;
924
925 chip = pci_get_drvdata(pdev);
926 if (!chip)
927 return 0;
928
929 DBG("Resuming...\n");
930
931 pci_set_power_state(pdev, PCI_D0);
932 pci_restore_state(pdev);
933 pci_enable_device(pdev);
934
935 for (i = 0;i < chip->num_slots;i++) {
936 if (!chip->hosts[i])
937 continue;
938 if (chip->hosts[i]->flags & SDHCI_USE_DMA)
939 pci_set_master(pdev);
940 sdhci_init(chip->hosts[i]);
941 ret = mmc_resume_host(chip->hosts[i]->mmc);
942 if (ret)
943 return ret;
944 }
945
946 return 0;
947}
948
949#else /* CONFIG_PM */
950
951#define sdhci_suspend NULL
952#define sdhci_resume NULL
953
954#endif /* CONFIG_PM */
955
956/*****************************************************************************\
957 * *
958 * Device probing/removal *
959 * *
960\*****************************************************************************/
961
962static int __devinit sdhci_probe_slot(struct pci_dev *pdev, int slot)
963{
964 int ret;
965 struct sdhci_chip *chip;
966 struct mmc_host *mmc;
967 struct sdhci_host *host;
968
969 u8 first_bar;
970 unsigned int caps;
971
972 chip = pci_get_drvdata(pdev);
973 BUG_ON(!chip);
974
975 ret = pci_read_config_byte(pdev, PCI_SLOT_INFO, &first_bar);
976 if (ret)
977 return ret;
978
979 first_bar &= PCI_SLOT_INFO_FIRST_BAR_MASK;
980
981 if (first_bar > 5) {
982 printk(KERN_ERR DRIVER_NAME ": Invalid first BAR. Aborting.\n");
983 return -ENODEV;
984 }
985
986 if (!(pci_resource_flags(pdev, first_bar + slot) & IORESOURCE_MEM)) {
987 printk(KERN_ERR DRIVER_NAME ": BAR is not iomem. Aborting.\n");
988 return -ENODEV;
989 }
990
991 if (pci_resource_len(pdev, first_bar + slot) != 0x100) {
992 printk(KERN_ERR DRIVER_NAME ": Invalid iomem size. Aborting.\n");
993 return -ENODEV;
994 }
995
996 mmc = mmc_alloc_host(sizeof(struct sdhci_host), &pdev->dev);
997 if (!mmc)
998 return -ENOMEM;
999
1000 host = mmc_priv(mmc);
1001 host->mmc = mmc;
1002
1003 host->bar = first_bar + slot;
1004
1005 host->addr = pci_resource_start(pdev, host->bar);
1006 host->irq = pdev->irq;
1007
1008 DBG("slot %d at 0x%08lx, irq %d\n", slot, host->addr, host->irq);
1009
1010 snprintf(host->slot_descr, 20, "sdhci:slot%d", slot);
1011
1012 ret = pci_request_region(pdev, host->bar, host->slot_descr);
1013 if (ret)
1014 goto free;
1015
1016 host->ioaddr = ioremap_nocache(host->addr,
1017 pci_resource_len(pdev, host->bar));
1018 if (!host->ioaddr) {
1019 ret = -ENOMEM;
1020 goto release;
1021 }
1022
1023 caps = readl(host->ioaddr + SDHCI_CAPABILITIES);
1024
1025 if ((caps & SDHCI_CAN_DO_DMA) && ((pdev->class & 0x0000FF) == 0x01))
1026 host->flags |= SDHCI_USE_DMA;
1027
1028 if (host->flags & SDHCI_USE_DMA) {
1029 if (pci_set_dma_mask(pdev, DMA_32BIT_MASK)) {
1030 printk(KERN_WARNING "%s: No suitable DMA available. "
1031 "Falling back to PIO.\n", host->slot_descr);
1032 host->flags &= ~SDHCI_USE_DMA;
1033 }
1034 }
1035
1036 if (host->flags & SDHCI_USE_DMA)
1037 pci_set_master(pdev);
1038 else /* XXX: Hack to get MMC layer to avoid highmem */
1039 pdev->dma_mask = 0;
1040
1041 host->max_clk = (caps & SDHCI_CLOCK_BASE_MASK) >> SDHCI_CLOCK_BASE_SHIFT;
1042 host->max_clk *= 1000000;
1043
1044 /*
1045 * Set host parameters.
1046 */
1047 mmc->ops = &sdhci_ops;
1048 mmc->f_min = host->max_clk / 256;
1049 mmc->f_max = host->max_clk;
1050 mmc->ocr_avail = MMC_VDD_32_33|MMC_VDD_33_34;
1051 mmc->caps = MMC_CAP_4_BIT_DATA;
1052
1053 spin_lock_init(&host->lock);
1054
1055 /*
1056 * Maximum number of segments. Hardware cannot do scatter lists.
1057 */
1058 if (host->flags & SDHCI_USE_DMA)
1059 mmc->max_hw_segs = 1;
1060 else
1061 mmc->max_hw_segs = 16;
1062 mmc->max_phys_segs = 16;
1063
1064 /*
1065 * Maximum number of sectors in one transfer. Limited by sector
1066 * count register.
1067 */
1068 mmc->max_sectors = 0x3FFF;
1069
1070 /*
1071 * Maximum segment size. Could be one segment with the maximum number
1072 * of sectors.
1073 */
1074 mmc->max_seg_size = mmc->max_sectors * 512;
1075
1076 /*
1077 * Init tasklets.
1078 */
1079 tasklet_init(&host->card_tasklet,
1080 sdhci_tasklet_card, (unsigned long)host);
1081 tasklet_init(&host->finish_tasklet,
1082 sdhci_tasklet_finish, (unsigned long)host);
1083
1084 setup_timer(&host->timer, sdhci_timeout_timer, (int)host);
1085
1086 ret = request_irq(host->irq, sdhci_irq, SA_SHIRQ,
1087 host->slot_descr, host);
1088 if (ret)
1089 goto unmap;
1090
1091 sdhci_init(host);
1092
1093#ifdef CONFIG_MMC_DEBUG
1094 sdhci_dumpregs(host);
1095#endif
1096
1097 host->chip = chip;
1098 chip->hosts[slot] = host;
1099
1100 mmc_add_host(mmc);
1101
1102 printk(KERN_INFO "%s: SDHCI at 0x%08lx irq %d %s\n", mmc_hostname(mmc),
1103 host->addr, host->irq,
1104 (host->flags & SDHCI_USE_DMA)?"DMA":"PIO");
1105
1106 return 0;
1107
1108unmap:
1109 tasklet_kill(&host->card_tasklet);
1110 tasklet_kill(&host->finish_tasklet);
1111
1112 iounmap(host->ioaddr);
1113release:
1114 pci_release_region(pdev, host->bar);
1115free:
1116 mmc_free_host(mmc);
1117
1118 return ret;
1119}
1120
1121static void sdhci_remove_slot(struct pci_dev *pdev, int slot)
1122{
1123 struct sdhci_chip *chip;
1124 struct mmc_host *mmc;
1125 struct sdhci_host *host;
1126
1127 chip = pci_get_drvdata(pdev);
1128 host = chip->hosts[slot];
1129 mmc = host->mmc;
1130
1131 chip->hosts[slot] = NULL;
1132
1133 mmc_remove_host(mmc);
1134
1135 sdhci_reset(host, SDHCI_RESET_ALL);
1136
1137 free_irq(host->irq, host);
1138
1139 del_timer_sync(&host->timer);
1140
1141 tasklet_kill(&host->card_tasklet);
1142 tasklet_kill(&host->finish_tasklet);
1143
1144 iounmap(host->ioaddr);
1145
1146 pci_release_region(pdev, host->bar);
1147
1148 mmc_free_host(mmc);
1149}
1150
1151static int __devinit sdhci_probe(struct pci_dev *pdev,
1152 const struct pci_device_id *ent)
1153{
1154 int ret, i;
1155 u8 slots;
1156 struct sdhci_chip *chip;
1157
1158 BUG_ON(pdev == NULL);
1159 BUG_ON(ent == NULL);
1160
1161 DBG("found at %s\n", pci_name(pdev));
1162
1163 ret = pci_read_config_byte(pdev, PCI_SLOT_INFO, &slots);
1164 if (ret)
1165 return ret;
1166
1167 slots = PCI_SLOT_INFO_SLOTS(slots) + 1;
1168 DBG("found %d slot(s)\n", slots);
1169 if (slots == 0)
1170 return -ENODEV;
1171
1172 ret = pci_enable_device(pdev);
1173 if (ret)
1174 return ret;
1175
1176 chip = kzalloc(sizeof(struct sdhci_chip) +
1177 sizeof(struct sdhci_host*) * slots, GFP_KERNEL);
1178 if (!chip) {
1179 ret = -ENOMEM;
1180 goto err;
1181 }
1182
1183 chip->pdev = pdev;
1184
1185 chip->num_slots = slots;
1186 pci_set_drvdata(pdev, chip);
1187
1188 for (i = 0;i < slots;i++) {
1189 ret = sdhci_probe_slot(pdev, i);
1190 if (ret) {
1191 for (i--;i >= 0;i--)
1192 sdhci_remove_slot(pdev, i);
1193 goto free;
1194 }
1195 }
1196
1197 return 0;
1198
1199free:
1200 pci_set_drvdata(pdev, NULL);
1201 kfree(chip);
1202
1203err:
1204 pci_disable_device(pdev);
1205 return ret;
1206}
1207
1208static void __devexit sdhci_remove(struct pci_dev *pdev)
1209{
1210 int i;
1211 struct sdhci_chip *chip;
1212
1213 chip = pci_get_drvdata(pdev);
1214
1215 if (chip) {
1216 for (i = 0;i < chip->num_slots;i++)
1217 sdhci_remove_slot(pdev, i);
1218
1219 pci_set_drvdata(pdev, NULL);
1220
1221 kfree(chip);
1222 }
1223
1224 pci_disable_device(pdev);
1225}
1226
1227static struct pci_driver sdhci_driver = {
1228 .name = DRIVER_NAME,
1229 .id_table = pci_ids,
1230 .probe = sdhci_probe,
1231 .remove = __devexit_p(sdhci_remove),
1232 .suspend = sdhci_suspend,
1233 .resume = sdhci_resume,
1234};
1235
1236/*****************************************************************************\
1237 * *
1238 * Driver init/exit *
1239 * *
1240\*****************************************************************************/
1241
1242static int __init sdhci_drv_init(void)
1243{
1244 printk(KERN_INFO DRIVER_NAME
1245 ": Secure Digital Host Controller Interface driver, "
1246 DRIVER_VERSION "\n");
1247 printk(KERN_INFO DRIVER_NAME ": Copyright(c) Pierre Ossman\n");
1248
1249 return pci_register_driver(&sdhci_driver);
1250}
1251
1252static void __exit sdhci_drv_exit(void)
1253{
1254 DBG("Exiting\n");
1255
1256 pci_unregister_driver(&sdhci_driver);
1257}
1258
1259module_init(sdhci_drv_init);
1260module_exit(sdhci_drv_exit);
1261
1262MODULE_AUTHOR("Pierre Ossman <drzeus@drzeus.cx>");
1263MODULE_DESCRIPTION("Secure Digital Host Controller Interface driver");
1264MODULE_VERSION(DRIVER_VERSION);
1265MODULE_LICENSE("GPL");
diff --git a/drivers/mmc/sdhci.h b/drivers/mmc/sdhci.h
new file mode 100644
index 0000000000..3b270ef486
--- /dev/null
+++ b/drivers/mmc/sdhci.h
@@ -0,0 +1,185 @@
1/*
2 * linux/drivers/mmc/sdhci.h - Secure Digital Host Controller Interface driver
3 *
4 * Copyright (C) 2005 Pierre Ossman, All Rights Reserved.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
11/*
12 * PCI registers
13 */
14
15#define PCI_SLOT_INFO 0x40 /* 8 bits */
16#define PCI_SLOT_INFO_SLOTS(x) ((x >> 4) & 7)
17#define PCI_SLOT_INFO_FIRST_BAR_MASK 0x07
18
19/*
20 * Controller registers
21 */
22
23#define SDHCI_DMA_ADDRESS 0x00
24
25#define SDHCI_BLOCK_SIZE 0x04
26
27#define SDHCI_BLOCK_COUNT 0x06
28
29#define SDHCI_ARGUMENT 0x08
30
31#define SDHCI_TRANSFER_MODE 0x0C
32#define SDHCI_TRNS_DMA 0x01
33#define SDHCI_TRNS_BLK_CNT_EN 0x02
34#define SDHCI_TRNS_ACMD12 0x04
35#define SDHCI_TRNS_READ 0x10
36#define SDHCI_TRNS_MULTI 0x20
37
38#define SDHCI_COMMAND 0x0E
39#define SDHCI_CMD_RESP_MASK 0x03
40#define SDHCI_CMD_CRC 0x08
41#define SDHCI_CMD_INDEX 0x10
42#define SDHCI_CMD_DATA 0x20
43
44#define SDHCI_CMD_RESP_NONE 0x00
45#define SDHCI_CMD_RESP_LONG 0x01
46#define SDHCI_CMD_RESP_SHORT 0x02
47#define SDHCI_CMD_RESP_SHORT_BUSY 0x03
48
49#define SDHCI_MAKE_CMD(c, f) (((c & 0xff) << 8) | (f & 0xff))
50
51#define SDHCI_RESPONSE 0x10
52
53#define SDHCI_BUFFER 0x20
54
55#define SDHCI_PRESENT_STATE 0x24
56#define SDHCI_CMD_INHIBIT 0x00000001
57#define SDHCI_DATA_INHIBIT 0x00000002
58#define SDHCI_DOING_WRITE 0x00000100
59#define SDHCI_DOING_READ 0x00000200
60#define SDHCI_SPACE_AVAILABLE 0x00000400
61#define SDHCI_DATA_AVAILABLE 0x00000800
62#define SDHCI_CARD_PRESENT 0x00010000
63#define SDHCI_WRITE_PROTECT 0x00080000
64
65#define SDHCI_HOST_CONTROL 0x28
66#define SDHCI_CTRL_LED 0x01
67#define SDHCI_CTRL_4BITBUS 0x02
68
69#define SDHCI_POWER_CONTROL 0x29
70
71#define SDHCI_BLOCK_GAP_CONTROL 0x2A
72
73#define SDHCI_WALK_UP_CONTROL 0x2B
74
75#define SDHCI_CLOCK_CONTROL 0x2C
76#define SDHCI_DIVIDER_SHIFT 8
77#define SDHCI_CLOCK_CARD_EN 0x0004
78#define SDHCI_CLOCK_INT_STABLE 0x0002
79#define SDHCI_CLOCK_INT_EN 0x0001
80
81#define SDHCI_TIMEOUT_CONTROL 0x2E
82
83#define SDHCI_SOFTWARE_RESET 0x2F
84#define SDHCI_RESET_ALL 0x01
85#define SDHCI_RESET_CMD 0x02
86#define SDHCI_RESET_DATA 0x04
87
88#define SDHCI_INT_STATUS 0x30
89#define SDHCI_INT_ENABLE 0x34
90#define SDHCI_SIGNAL_ENABLE 0x38
91#define SDHCI_INT_RESPONSE 0x00000001
92#define SDHCI_INT_DATA_END 0x00000002
93#define SDHCI_INT_DMA_END 0x00000008
94#define SDHCI_INT_BUF_EMPTY 0x00000010
95#define SDHCI_INT_BUF_FULL 0x00000020
96#define SDHCI_INT_CARD_INSERT 0x00000040
97#define SDHCI_INT_CARD_REMOVE 0x00000080
98#define SDHCI_INT_CARD_INT 0x00000100
99#define SDHCI_INT_TIMEOUT 0x00010000
100#define SDHCI_INT_CRC 0x00020000
101#define SDHCI_INT_END_BIT 0x00040000
102#define SDHCI_INT_INDEX 0x00080000
103#define SDHCI_INT_DATA_TIMEOUT 0x00100000
104#define SDHCI_INT_DATA_CRC 0x00200000
105#define SDHCI_INT_DATA_END_BIT 0x00400000
106#define SDHCI_INT_BUS_POWER 0x00800000
107#define SDHCI_INT_ACMD12ERR 0x01000000
108
109#define SDHCI_INT_NORMAL_MASK 0x00007FFF
110#define SDHCI_INT_ERROR_MASK 0xFFFF8000
111
112#define SDHCI_INT_CMD_MASK (SDHCI_INT_RESPONSE | SDHCI_INT_TIMEOUT | \
113 SDHCI_INT_CRC | SDHCI_INT_END_BIT | SDHCI_INT_INDEX)
114#define SDHCI_INT_DATA_MASK (SDHCI_INT_DATA_END | SDHCI_INT_DMA_END | \
115 SDHCI_INT_BUF_EMPTY | SDHCI_INT_BUF_FULL | \
116 SDHCI_INT_DATA_TIMEOUT | SDHCI_INT_DATA_CRC | \
117 SDHCI_INT_DATA_END_BIT)
118
119#define SDHCI_ACMD12_ERR 0x3C
120
121/* 3E-3F reserved */
122
123#define SDHCI_CAPABILITIES 0x40
124#define SDHCI_CAN_DO_DMA 0x00400000
125#define SDHCI_CLOCK_BASE_MASK 0x00003F00
126#define SDHCI_CLOCK_BASE_SHIFT 8
127
128/* 44-47 reserved for more caps */
129
130#define SDHCI_MAX_CURRENT 0x48
131
132/* 4C-4F reserved for more max current */
133
134/* 50-FB reserved */
135
136#define SDHCI_SLOT_INT_STATUS 0xFC
137
138#define SDHCI_HOST_VERSION 0xFE
139
140struct sdhci_chip;
141
142struct sdhci_host {
143 struct sdhci_chip *chip;
144 struct mmc_host *mmc; /* MMC structure */
145
146 spinlock_t lock; /* Mutex */
147
148 int flags; /* Host attributes */
149#define SDHCI_USE_DMA (1<<0)
150
151 unsigned int max_clk; /* Max possible freq (MHz) */
152
153 unsigned int clock; /* Current clock (MHz) */
154
155 struct mmc_request *mrq; /* Current request */
156 struct mmc_command *cmd; /* Current command */
157 struct mmc_data *data; /* Current data request */
158
159 struct scatterlist *cur_sg; /* We're working on this */
160 char *mapped_sg; /* This is where it's mapped */
161 int num_sg; /* Entries left */
162 int offset; /* Offset into current sg */
163 int remain; /* Bytes left in current */
164
165 int size; /* Remaining bytes in transfer */
166
167 char slot_descr[20]; /* Name for reservations */
168
169 int irq; /* Device IRQ */
170 int bar; /* PCI BAR index */
171 unsigned long addr; /* Bus address */
172 void __iomem * ioaddr; /* Mapped address */
173
174 struct tasklet_struct card_tasklet; /* Tasklet structures */
175 struct tasklet_struct finish_tasklet;
176
177 struct timer_list timer; /* Timer for timeouts */
178};
179
180struct sdhci_chip {
181 struct pci_dev *pdev;
182
183 int num_slots; /* Slots on controller */
184 struct sdhci_host *hosts[0]; /* Pointers to hosts */
185};
diff --git a/drivers/net/8139too.c b/drivers/net/8139too.c
index f5ee064ab6..feae7832fc 100644
--- a/drivers/net/8139too.c
+++ b/drivers/net/8139too.c
@@ -1131,7 +1131,7 @@ static void __devexit rtl8139_remove_one (struct pci_dev *pdev)
1131 No extra delay is needed with 33Mhz PCI, but 66Mhz may change this. 1131 No extra delay is needed with 33Mhz PCI, but 66Mhz may change this.
1132 */ 1132 */
1133 1133
1134#define eeprom_delay() RTL_R32(Cfg9346) 1134#define eeprom_delay() (void)RTL_R32(Cfg9346)
1135 1135
1136/* The EEPROM commands include the alway-set leading bit. */ 1136/* The EEPROM commands include the alway-set leading bit. */
1137#define EE_WRITE_CMD (5) 1137#define EE_WRITE_CMD (5)
diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
index 00993e8ba5..e20b849a22 100644
--- a/drivers/net/Kconfig
+++ b/drivers/net/Kconfig
@@ -2172,6 +2172,7 @@ config BNX2
2172config SPIDER_NET 2172config SPIDER_NET
2173 tristate "Spider Gigabit Ethernet driver" 2173 tristate "Spider Gigabit Ethernet driver"
2174 depends on PCI && PPC_CELL 2174 depends on PCI && PPC_CELL
2175 select FW_LOADER
2175 help 2176 help
2176 This driver supports the Gigabit Ethernet chips present on the 2177 This driver supports the Gigabit Ethernet chips present on the
2177 Cell Processor-Based Blades from IBM. 2178 Cell Processor-Based Blades from IBM.
diff --git a/drivers/net/bnx2.c b/drivers/net/bnx2.c
index 7d21370700..2671da20a4 100644
--- a/drivers/net/bnx2.c
+++ b/drivers/net/bnx2.c
@@ -9,13 +9,54 @@
9 * Written by: Michael Chan (mchan@broadcom.com) 9 * Written by: Michael Chan (mchan@broadcom.com)
10 */ 10 */
11 11
12#include <linux/config.h>
13
14#include <linux/module.h>
15#include <linux/moduleparam.h>
16
17#include <linux/kernel.h>
18#include <linux/timer.h>
19#include <linux/errno.h>
20#include <linux/ioport.h>
21#include <linux/slab.h>
22#include <linux/vmalloc.h>
23#include <linux/interrupt.h>
24#include <linux/pci.h>
25#include <linux/init.h>
26#include <linux/netdevice.h>
27#include <linux/etherdevice.h>
28#include <linux/skbuff.h>
29#include <linux/dma-mapping.h>
30#include <asm/bitops.h>
31#include <asm/io.h>
32#include <asm/irq.h>
33#include <linux/delay.h>
34#include <asm/byteorder.h>
35#include <linux/time.h>
36#include <linux/ethtool.h>
37#include <linux/mii.h>
38#ifdef NETIF_F_HW_VLAN_TX
39#include <linux/if_vlan.h>
40#define BCM_VLAN 1
41#endif
42#ifdef NETIF_F_TSO
43#include <net/ip.h>
44#include <net/tcp.h>
45#include <net/checksum.h>
46#define BCM_TSO 1
47#endif
48#include <linux/workqueue.h>
49#include <linux/crc32.h>
50#include <linux/prefetch.h>
51#include <linux/cache.h>
52
12#include "bnx2.h" 53#include "bnx2.h"
13#include "bnx2_fw.h" 54#include "bnx2_fw.h"
14 55
15#define DRV_MODULE_NAME "bnx2" 56#define DRV_MODULE_NAME "bnx2"
16#define PFX DRV_MODULE_NAME ": " 57#define PFX DRV_MODULE_NAME ": "
17#define DRV_MODULE_VERSION "1.4.38" 58#define DRV_MODULE_VERSION "1.4.39"
18#define DRV_MODULE_RELDATE "February 10, 2006" 59#define DRV_MODULE_RELDATE "March 22, 2006"
19 60
20#define RUN_AT(x) (jiffies + (x)) 61#define RUN_AT(x) (jiffies + (x))
21 62
@@ -313,8 +354,6 @@ bnx2_disable_int(struct bnx2 *bp)
313static void 354static void
314bnx2_enable_int(struct bnx2 *bp) 355bnx2_enable_int(struct bnx2 *bp)
315{ 356{
316 u32 val;
317
318 REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD, 357 REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD,
319 BNX2_PCICFG_INT_ACK_CMD_INDEX_VALID | 358 BNX2_PCICFG_INT_ACK_CMD_INDEX_VALID |
320 BNX2_PCICFG_INT_ACK_CMD_MASK_INT | bp->last_status_idx); 359 BNX2_PCICFG_INT_ACK_CMD_MASK_INT | bp->last_status_idx);
@@ -322,8 +361,7 @@ bnx2_enable_int(struct bnx2 *bp)
322 REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD, 361 REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD,
323 BNX2_PCICFG_INT_ACK_CMD_INDEX_VALID | bp->last_status_idx); 362 BNX2_PCICFG_INT_ACK_CMD_INDEX_VALID | bp->last_status_idx);
324 363
325 val = REG_RD(bp, BNX2_HC_COMMAND); 364 REG_WR(bp, BNX2_HC_COMMAND, bp->hc_cmd | BNX2_HC_COMMAND_COAL_NOW);
326 REG_WR(bp, BNX2_HC_COMMAND, val | BNX2_HC_COMMAND_COAL_NOW);
327} 365}
328 366
329static void 367static void
@@ -362,15 +400,11 @@ bnx2_free_mem(struct bnx2 *bp)
362{ 400{
363 int i; 401 int i;
364 402
365 if (bp->stats_blk) {
366 pci_free_consistent(bp->pdev, sizeof(struct statistics_block),
367 bp->stats_blk, bp->stats_blk_mapping);
368 bp->stats_blk = NULL;
369 }
370 if (bp->status_blk) { 403 if (bp->status_blk) {
371 pci_free_consistent(bp->pdev, sizeof(struct status_block), 404 pci_free_consistent(bp->pdev, bp->status_stats_size,
372 bp->status_blk, bp->status_blk_mapping); 405 bp->status_blk, bp->status_blk_mapping);
373 bp->status_blk = NULL; 406 bp->status_blk = NULL;
407 bp->stats_blk = NULL;
374 } 408 }
375 if (bp->tx_desc_ring) { 409 if (bp->tx_desc_ring) {
376 pci_free_consistent(bp->pdev, 410 pci_free_consistent(bp->pdev,
@@ -395,14 +429,13 @@ bnx2_free_mem(struct bnx2 *bp)
395static int 429static int
396bnx2_alloc_mem(struct bnx2 *bp) 430bnx2_alloc_mem(struct bnx2 *bp)
397{ 431{
398 int i; 432 int i, status_blk_size;
399 433
400 bp->tx_buf_ring = kmalloc(sizeof(struct sw_bd) * TX_DESC_CNT, 434 bp->tx_buf_ring = kzalloc(sizeof(struct sw_bd) * TX_DESC_CNT,
401 GFP_KERNEL); 435 GFP_KERNEL);
402 if (bp->tx_buf_ring == NULL) 436 if (bp->tx_buf_ring == NULL)
403 return -ENOMEM; 437 return -ENOMEM;
404 438
405 memset(bp->tx_buf_ring, 0, sizeof(struct sw_bd) * TX_DESC_CNT);
406 bp->tx_desc_ring = pci_alloc_consistent(bp->pdev, 439 bp->tx_desc_ring = pci_alloc_consistent(bp->pdev,
407 sizeof(struct tx_bd) * 440 sizeof(struct tx_bd) *
408 TX_DESC_CNT, 441 TX_DESC_CNT,
@@ -428,21 +461,22 @@ bnx2_alloc_mem(struct bnx2 *bp)
428 461
429 } 462 }
430 463
431 bp->status_blk = pci_alloc_consistent(bp->pdev, 464 /* Combine status and statistics blocks into one allocation. */
432 sizeof(struct status_block), 465 status_blk_size = L1_CACHE_ALIGN(sizeof(struct status_block));
466 bp->status_stats_size = status_blk_size +
467 sizeof(struct statistics_block);
468
469 bp->status_blk = pci_alloc_consistent(bp->pdev, bp->status_stats_size,
433 &bp->status_blk_mapping); 470 &bp->status_blk_mapping);
434 if (bp->status_blk == NULL) 471 if (bp->status_blk == NULL)
435 goto alloc_mem_err; 472 goto alloc_mem_err;
436 473
437 memset(bp->status_blk, 0, sizeof(struct status_block)); 474 memset(bp->status_blk, 0, bp->status_stats_size);
438 475
439 bp->stats_blk = pci_alloc_consistent(bp->pdev, 476 bp->stats_blk = (void *) ((unsigned long) bp->status_blk +
440 sizeof(struct statistics_block), 477 status_blk_size);
441 &bp->stats_blk_mapping);
442 if (bp->stats_blk == NULL)
443 goto alloc_mem_err;
444 478
445 memset(bp->stats_blk, 0, sizeof(struct statistics_block)); 479 bp->stats_blk_mapping = bp->status_blk_mapping + status_blk_size;
446 480
447 return 0; 481 return 0;
448 482
@@ -1926,6 +1960,13 @@ bnx2_poll(struct net_device *dev, int *budget)
1926 spin_lock(&bp->phy_lock); 1960 spin_lock(&bp->phy_lock);
1927 bnx2_phy_int(bp); 1961 bnx2_phy_int(bp);
1928 spin_unlock(&bp->phy_lock); 1962 spin_unlock(&bp->phy_lock);
1963
1964 /* This is needed to take care of transient status
1965 * during link changes.
1966 */
1967 REG_WR(bp, BNX2_HC_COMMAND,
1968 bp->hc_cmd | BNX2_HC_COMMAND_COAL_NOW_WO_INT);
1969 REG_RD(bp, BNX2_HC_COMMAND);
1929 } 1970 }
1930 1971
1931 if (bp->status_blk->status_tx_quick_consumer_index0 != bp->hw_tx_cons) 1972 if (bp->status_blk->status_tx_quick_consumer_index0 != bp->hw_tx_cons)
@@ -3307,6 +3348,8 @@ bnx2_init_chip(struct bnx2 *bp)
3307 3348
3308 udelay(20); 3349 udelay(20);
3309 3350
3351 bp->hc_cmd = REG_RD(bp, BNX2_HC_COMMAND);
3352
3310 return rc; 3353 return rc;
3311} 3354}
3312 3355
@@ -3746,7 +3789,6 @@ bnx2_run_loopback(struct bnx2 *bp, int loopback_mode)
3746 struct sk_buff *skb, *rx_skb; 3789 struct sk_buff *skb, *rx_skb;
3747 unsigned char *packet; 3790 unsigned char *packet;
3748 u16 rx_start_idx, rx_idx; 3791 u16 rx_start_idx, rx_idx;
3749 u32 val;
3750 dma_addr_t map; 3792 dma_addr_t map;
3751 struct tx_bd *txbd; 3793 struct tx_bd *txbd;
3752 struct sw_bd *rx_buf; 3794 struct sw_bd *rx_buf;
@@ -3777,8 +3819,9 @@ bnx2_run_loopback(struct bnx2 *bp, int loopback_mode)
3777 map = pci_map_single(bp->pdev, skb->data, pkt_size, 3819 map = pci_map_single(bp->pdev, skb->data, pkt_size,
3778 PCI_DMA_TODEVICE); 3820 PCI_DMA_TODEVICE);
3779 3821
3780 val = REG_RD(bp, BNX2_HC_COMMAND); 3822 REG_WR(bp, BNX2_HC_COMMAND,
3781 REG_WR(bp, BNX2_HC_COMMAND, val | BNX2_HC_COMMAND_COAL_NOW_WO_INT); 3823 bp->hc_cmd | BNX2_HC_COMMAND_COAL_NOW_WO_INT);
3824
3782 REG_RD(bp, BNX2_HC_COMMAND); 3825 REG_RD(bp, BNX2_HC_COMMAND);
3783 3826
3784 udelay(5); 3827 udelay(5);
@@ -3802,8 +3845,9 @@ bnx2_run_loopback(struct bnx2 *bp, int loopback_mode)
3802 3845
3803 udelay(100); 3846 udelay(100);
3804 3847
3805 val = REG_RD(bp, BNX2_HC_COMMAND); 3848 REG_WR(bp, BNX2_HC_COMMAND,
3806 REG_WR(bp, BNX2_HC_COMMAND, val | BNX2_HC_COMMAND_COAL_NOW_WO_INT); 3849 bp->hc_cmd | BNX2_HC_COMMAND_COAL_NOW_WO_INT);
3850
3807 REG_RD(bp, BNX2_HC_COMMAND); 3851 REG_RD(bp, BNX2_HC_COMMAND);
3808 3852
3809 udelay(5); 3853 udelay(5);
@@ -3939,7 +3983,6 @@ static int
3939bnx2_test_intr(struct bnx2 *bp) 3983bnx2_test_intr(struct bnx2 *bp)
3940{ 3984{
3941 int i; 3985 int i;
3942 u32 val;
3943 u16 status_idx; 3986 u16 status_idx;
3944 3987
3945 if (!netif_running(bp->dev)) 3988 if (!netif_running(bp->dev))
@@ -3948,8 +3991,7 @@ bnx2_test_intr(struct bnx2 *bp)
3948 status_idx = REG_RD(bp, BNX2_PCICFG_INT_ACK_CMD) & 0xffff; 3991 status_idx = REG_RD(bp, BNX2_PCICFG_INT_ACK_CMD) & 0xffff;
3949 3992
3950 /* This register is not touched during run-time. */ 3993 /* This register is not touched during run-time. */
3951 val = REG_RD(bp, BNX2_HC_COMMAND); 3994 REG_WR(bp, BNX2_HC_COMMAND, bp->hc_cmd | BNX2_HC_COMMAND_COAL_NOW);
3952 REG_WR(bp, BNX2_HC_COMMAND, val | BNX2_HC_COMMAND_COAL_NOW);
3953 REG_RD(bp, BNX2_HC_COMMAND); 3995 REG_RD(bp, BNX2_HC_COMMAND);
3954 3996
3955 for (i = 0; i < 10; i++) { 3997 for (i = 0; i < 10; i++) {
diff --git a/drivers/net/bnx2.h b/drivers/net/bnx2.h
index fd4b7f2eb4..b87925f6a2 100644
--- a/drivers/net/bnx2.h
+++ b/drivers/net/bnx2.h
@@ -13,46 +13,6 @@
13#ifndef BNX2_H 13#ifndef BNX2_H
14#define BNX2_H 14#define BNX2_H
15 15
16#include <linux/config.h>
17
18#include <linux/module.h>
19#include <linux/moduleparam.h>
20
21#include <linux/kernel.h>
22#include <linux/timer.h>
23#include <linux/errno.h>
24#include <linux/ioport.h>
25#include <linux/slab.h>
26#include <linux/vmalloc.h>
27#include <linux/interrupt.h>
28#include <linux/pci.h>
29#include <linux/init.h>
30#include <linux/netdevice.h>
31#include <linux/etherdevice.h>
32#include <linux/skbuff.h>
33#include <linux/dma-mapping.h>
34#include <asm/bitops.h>
35#include <asm/io.h>
36#include <asm/irq.h>
37#include <linux/delay.h>
38#include <asm/byteorder.h>
39#include <linux/time.h>
40#include <linux/ethtool.h>
41#include <linux/mii.h>
42#ifdef NETIF_F_HW_VLAN_TX
43#include <linux/if_vlan.h>
44#define BCM_VLAN 1
45#endif
46#ifdef NETIF_F_TSO
47#include <net/ip.h>
48#include <net/tcp.h>
49#include <net/checksum.h>
50#define BCM_TSO 1
51#endif
52#include <linux/workqueue.h>
53#include <linux/crc32.h>
54#include <linux/prefetch.h>
55
56/* Hardware data structures and register definitions automatically 16/* Hardware data structures and register definitions automatically
57 * generated from RTL code. Do not modify. 17 * generated from RTL code. Do not modify.
58 */ 18 */
@@ -3917,15 +3877,17 @@ struct bnx2 {
3917#define USING_MSI_FLAG 0x20 3877#define USING_MSI_FLAG 0x20
3918#define ASF_ENABLE_FLAG 0x40 3878#define ASF_ENABLE_FLAG 0x40
3919 3879
3920 struct tx_bd *tx_desc_ring; 3880 /* Put tx producer and consumer fields in separate cache lines. */
3921 struct sw_bd *tx_buf_ring;
3922 u32 tx_prod_bseq;
3923 u16 tx_prod;
3924 u16 tx_cons;
3925 int tx_ring_size;
3926 3881
3927 u16 hw_tx_cons; 3882 u32 tx_prod_bseq __attribute__((aligned(L1_CACHE_BYTES)));
3928 u16 hw_rx_cons; 3883 u16 tx_prod;
3884
3885 struct tx_bd *tx_desc_ring;
3886 struct sw_bd *tx_buf_ring;
3887 int tx_ring_size;
3888
3889 u16 tx_cons __attribute__((aligned(L1_CACHE_BYTES)));
3890 u16 hw_tx_cons;
3929 3891
3930#ifdef BCM_VLAN 3892#ifdef BCM_VLAN
3931 struct vlan_group *vlgrp; 3893 struct vlan_group *vlgrp;
@@ -3939,6 +3901,7 @@ struct bnx2 {
3939 u32 rx_prod_bseq; 3901 u32 rx_prod_bseq;
3940 u16 rx_prod; 3902 u16 rx_prod;
3941 u16 rx_cons; 3903 u16 rx_cons;
3904 u16 hw_rx_cons;
3942 3905
3943 u32 rx_csum; 3906 u32 rx_csum;
3944 3907
@@ -4038,6 +4001,7 @@ struct bnx2 {
4038 struct statistics_block *stats_blk; 4001 struct statistics_block *stats_blk;
4039 dma_addr_t stats_blk_mapping; 4002 dma_addr_t stats_blk_mapping;
4040 4003
4004 u32 hc_cmd;
4041 u32 rx_mode; 4005 u32 rx_mode;
4042 4006
4043 u16 req_line_speed; 4007 u16 req_line_speed;
@@ -4082,6 +4046,8 @@ struct bnx2 {
4082 4046
4083 struct flash_spec *flash_info; 4047 struct flash_spec *flash_info;
4084 u32 flash_size; 4048 u32 flash_size;
4049
4050 int status_stats_size;
4085}; 4051};
4086 4052
4087static u32 bnx2_reg_rd_ind(struct bnx2 *bp, u32 offset); 4053static u32 bnx2_reg_rd_ind(struct bnx2 *bp, u32 offset);
diff --git a/drivers/net/hp-plus.c b/drivers/net/hp-plus.c
index 74e167e7de..0d7a6250e3 100644
--- a/drivers/net/hp-plus.c
+++ b/drivers/net/hp-plus.c
@@ -250,6 +250,12 @@ static int __init hpp_probe1(struct net_device *dev, int ioaddr)
250 ei_status.block_output = &hpp_mem_block_output; 250 ei_status.block_output = &hpp_mem_block_output;
251 ei_status.get_8390_hdr = &hpp_mem_get_8390_hdr; 251 ei_status.get_8390_hdr = &hpp_mem_get_8390_hdr;
252 dev->mem_start = mem_start; 252 dev->mem_start = mem_start;
253 ei_status.mem = ioremap(mem_start,
254 (HP_STOP_PG - HP_START_PG)*256);
255 if (!ei_status.mem) {
256 retval = -ENOMEM;
257 goto out;
258 }
253 ei_status.rmem_start = dev->mem_start + TX_PAGES/2*256; 259 ei_status.rmem_start = dev->mem_start + TX_PAGES/2*256;
254 dev->mem_end = ei_status.rmem_end 260 dev->mem_end = ei_status.rmem_end
255 = dev->mem_start + (HP_STOP_PG - HP_START_PG)*256; 261 = dev->mem_start + (HP_STOP_PG - HP_START_PG)*256;
@@ -262,8 +268,10 @@ static int __init hpp_probe1(struct net_device *dev, int ioaddr)
262 268
263 retval = register_netdev(dev); 269 retval = register_netdev(dev);
264 if (retval) 270 if (retval)
265 goto out; 271 goto out1;
266 return 0; 272 return 0;
273out1:
274 iounmap(ei_status.mem);
267out: 275out:
268 release_region(ioaddr, HP_IO_EXTENT); 276 release_region(ioaddr, HP_IO_EXTENT);
269 return retval; 277 return retval;
@@ -372,7 +380,7 @@ hpp_mem_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring
372 380
373 outw((ring_page<<8), ioaddr + HPP_IN_ADDR); 381 outw((ring_page<<8), ioaddr + HPP_IN_ADDR);
374 outw(option_reg & ~(MemDisable + BootROMEnb), ioaddr + HPP_OPTION); 382 outw(option_reg & ~(MemDisable + BootROMEnb), ioaddr + HPP_OPTION);
375 isa_memcpy_fromio(hdr, dev->mem_start, sizeof(struct e8390_pkt_hdr)); 383 memcpy_fromio(hdr, ei_status.mem, sizeof(struct e8390_pkt_hdr));
376 outw(option_reg, ioaddr + HPP_OPTION); 384 outw(option_reg, ioaddr + HPP_OPTION);
377 hdr->count = (le16_to_cpu(hdr->count) + 3) & ~3; /* Round up allocation. */ 385 hdr->count = (le16_to_cpu(hdr->count) + 3) & ~3; /* Round up allocation. */
378} 386}
@@ -391,7 +399,7 @@ hpp_mem_block_input(struct net_device *dev, int count, struct sk_buff *skb, int
391 Also note that we *can't* use eth_io_copy_and_sum() because 399 Also note that we *can't* use eth_io_copy_and_sum() because
392 it will not always copy "count" bytes (e.g. padded IP). */ 400 it will not always copy "count" bytes (e.g. padded IP). */
393 401
394 isa_memcpy_fromio(skb->data, dev->mem_start, count); 402 memcpy_fromio(skb->data, ei_status.mem, count);
395 outw(option_reg, ioaddr + HPP_OPTION); 403 outw(option_reg, ioaddr + HPP_OPTION);
396} 404}
397 405
@@ -416,7 +424,7 @@ hpp_mem_block_output(struct net_device *dev, int count,
416 424
417 outw(start_page << 8, ioaddr + HPP_OUT_ADDR); 425 outw(start_page << 8, ioaddr + HPP_OUT_ADDR);
418 outw(option_reg & ~(MemDisable + BootROMEnb), ioaddr + HPP_OPTION); 426 outw(option_reg & ~(MemDisable + BootROMEnb), ioaddr + HPP_OPTION);
419 isa_memcpy_toio(dev->mem_start, buf, (count + 3) & ~3); 427 memcpy_toio(ei_status.mem, buf, (count + 3) & ~3);
420 outw(option_reg, ioaddr + HPP_OPTION); 428 outw(option_reg, ioaddr + HPP_OPTION);
421 429
422 return; 430 return;
@@ -470,6 +478,7 @@ init_module(void)
470static void cleanup_card(struct net_device *dev) 478static void cleanup_card(struct net_device *dev)
471{ 479{
472 /* NB: hpp_close() handles free_irq */ 480 /* NB: hpp_close() handles free_irq */
481 iounmap(ei_status.mem);
473 release_region(dev->base_addr - NIC_OFFSET, HP_IO_EXTENT); 482 release_region(dev->base_addr - NIC_OFFSET, HP_IO_EXTENT);
474} 483}
475 484
diff --git a/drivers/net/lance.c b/drivers/net/lance.c
index d1d714faa6..bb5ad47921 100644
--- a/drivers/net/lance.c
+++ b/drivers/net/lance.c
@@ -464,20 +464,25 @@ static int __init lance_probe1(struct net_device *dev, int ioaddr, int irq, int
464 static int did_version; /* Already printed version info. */ 464 static int did_version; /* Already printed version info. */
465 unsigned long flags; 465 unsigned long flags;
466 int err = -ENOMEM; 466 int err = -ENOMEM;
467 void __iomem *bios;
467 468
468 /* First we look for special cases. 469 /* First we look for special cases.
469 Check for HP's on-board ethernet by looking for 'HP' in the BIOS. 470 Check for HP's on-board ethernet by looking for 'HP' in the BIOS.
470 There are two HP versions, check the BIOS for the configuration port. 471 There are two HP versions, check the BIOS for the configuration port.
471 This method provided by L. Julliard, Laurent_Julliard@grenoble.hp.com. 472 This method provided by L. Julliard, Laurent_Julliard@grenoble.hp.com.
472 */ 473 */
473 if (isa_readw(0x000f0102) == 0x5048) { 474 bios = ioremap(0xf00f0, 0x14);
475 if (!bios)
476 return -ENOMEM;
477 if (readw(bios + 0x12) == 0x5048) {
474 static const short ioaddr_table[] = { 0x300, 0x320, 0x340, 0x360}; 478 static const short ioaddr_table[] = { 0x300, 0x320, 0x340, 0x360};
475 int hp_port = (isa_readl(0x000f00f1) & 1) ? 0x499 : 0x99; 479 int hp_port = (readl(bios + 1) & 1) ? 0x499 : 0x99;
476 /* We can have boards other than the built-in! Verify this is on-board. */ 480 /* We can have boards other than the built-in! Verify this is on-board. */
477 if ((inb(hp_port) & 0xc0) == 0x80 481 if ((inb(hp_port) & 0xc0) == 0x80
478 && ioaddr_table[inb(hp_port) & 3] == ioaddr) 482 && ioaddr_table[inb(hp_port) & 3] == ioaddr)
479 hp_builtin = hp_port; 483 hp_builtin = hp_port;
480 } 484 }
485 iounmap(bios);
481 /* We also recognize the HP Vectra on-board here, but check below. */ 486 /* We also recognize the HP Vectra on-board here, but check below. */
482 hpJ2405A = (inb(ioaddr) == 0x08 && inb(ioaddr+1) == 0x00 487 hpJ2405A = (inb(ioaddr) == 0x08 && inb(ioaddr+1) == 0x00
483 && inb(ioaddr+2) == 0x09); 488 && inb(ioaddr+2) == 0x09);
diff --git a/drivers/net/loopback.c b/drivers/net/loopback.c
index 690a1aae0b..0c13795dca 100644
--- a/drivers/net/loopback.c
+++ b/drivers/net/loopback.c
@@ -172,11 +172,9 @@ static struct net_device_stats *get_stats(struct net_device *dev)
172 172
173 memset(stats, 0, sizeof(struct net_device_stats)); 173 memset(stats, 0, sizeof(struct net_device_stats));
174 174
175 for (i=0; i < NR_CPUS; i++) { 175 for_each_cpu(i) {
176 struct net_device_stats *lb_stats; 176 struct net_device_stats *lb_stats;
177 177
178 if (!cpu_possible(i))
179 continue;
180 lb_stats = &per_cpu(loopback_stats, i); 178 lb_stats = &per_cpu(loopback_stats, i);
181 stats->rx_bytes += lb_stats->rx_bytes; 179 stats->rx_bytes += lb_stats->rx_bytes;
182 stats->tx_bytes += lb_stats->tx_bytes; 180 stats->tx_bytes += lb_stats->tx_bytes;
diff --git a/drivers/net/ppp_generic.c b/drivers/net/ppp_generic.c
index f608c12e3e..b2073fce82 100644
--- a/drivers/net/ppp_generic.c
+++ b/drivers/net/ppp_generic.c
@@ -46,6 +46,7 @@
46#include <linux/rwsem.h> 46#include <linux/rwsem.h>
47#include <linux/stddef.h> 47#include <linux/stddef.h>
48#include <linux/device.h> 48#include <linux/device.h>
49#include <linux/mutex.h>
49#include <net/slhc_vj.h> 50#include <net/slhc_vj.h>
50#include <asm/atomic.h> 51#include <asm/atomic.h>
51 52
@@ -198,11 +199,11 @@ static unsigned int cardmap_find_first_free(struct cardmap *map);
198static void cardmap_destroy(struct cardmap **map); 199static void cardmap_destroy(struct cardmap **map);
199 200
200/* 201/*
201 * all_ppp_sem protects the all_ppp_units mapping. 202 * all_ppp_mutex protects the all_ppp_units mapping.
202 * It also ensures that finding a ppp unit in the all_ppp_units map 203 * It also ensures that finding a ppp unit in the all_ppp_units map
203 * and updating its file.refcnt field is atomic. 204 * and updating its file.refcnt field is atomic.
204 */ 205 */
205static DECLARE_MUTEX(all_ppp_sem); 206static DEFINE_MUTEX(all_ppp_mutex);
206static struct cardmap *all_ppp_units; 207static struct cardmap *all_ppp_units;
207static atomic_t ppp_unit_count = ATOMIC_INIT(0); 208static atomic_t ppp_unit_count = ATOMIC_INIT(0);
208 209
@@ -804,7 +805,7 @@ static int ppp_unattached_ioctl(struct ppp_file *pf, struct file *file,
804 /* Attach to an existing ppp unit */ 805 /* Attach to an existing ppp unit */
805 if (get_user(unit, p)) 806 if (get_user(unit, p))
806 break; 807 break;
807 down(&all_ppp_sem); 808 mutex_lock(&all_ppp_mutex);
808 err = -ENXIO; 809 err = -ENXIO;
809 ppp = ppp_find_unit(unit); 810 ppp = ppp_find_unit(unit);
810 if (ppp != 0) { 811 if (ppp != 0) {
@@ -812,7 +813,7 @@ static int ppp_unattached_ioctl(struct ppp_file *pf, struct file *file,
812 file->private_data = &ppp->file; 813 file->private_data = &ppp->file;
813 err = 0; 814 err = 0;
814 } 815 }
815 up(&all_ppp_sem); 816 mutex_unlock(&all_ppp_mutex);
816 break; 817 break;
817 818
818 case PPPIOCATTCHAN: 819 case PPPIOCATTCHAN:
@@ -2446,7 +2447,7 @@ ppp_create_interface(int unit, int *retp)
2446 dev->do_ioctl = ppp_net_ioctl; 2447 dev->do_ioctl = ppp_net_ioctl;
2447 2448
2448 ret = -EEXIST; 2449 ret = -EEXIST;
2449 down(&all_ppp_sem); 2450 mutex_lock(&all_ppp_mutex);
2450 if (unit < 0) 2451 if (unit < 0)
2451 unit = cardmap_find_first_free(all_ppp_units); 2452 unit = cardmap_find_first_free(all_ppp_units);
2452 else if (cardmap_get(all_ppp_units, unit) != NULL) 2453 else if (cardmap_get(all_ppp_units, unit) != NULL)
@@ -2465,12 +2466,12 @@ ppp_create_interface(int unit, int *retp)
2465 2466
2466 atomic_inc(&ppp_unit_count); 2467 atomic_inc(&ppp_unit_count);
2467 cardmap_set(&all_ppp_units, unit, ppp); 2468 cardmap_set(&all_ppp_units, unit, ppp);
2468 up(&all_ppp_sem); 2469 mutex_unlock(&all_ppp_mutex);
2469 *retp = 0; 2470 *retp = 0;
2470 return ppp; 2471 return ppp;
2471 2472
2472out2: 2473out2:
2473 up(&all_ppp_sem); 2474 mutex_unlock(&all_ppp_mutex);
2474 free_netdev(dev); 2475 free_netdev(dev);
2475out1: 2476out1:
2476 kfree(ppp); 2477 kfree(ppp);
@@ -2500,7 +2501,7 @@ static void ppp_shutdown_interface(struct ppp *ppp)
2500{ 2501{
2501 struct net_device *dev; 2502 struct net_device *dev;
2502 2503
2503 down(&all_ppp_sem); 2504 mutex_lock(&all_ppp_mutex);
2504 ppp_lock(ppp); 2505 ppp_lock(ppp);
2505 dev = ppp->dev; 2506 dev = ppp->dev;
2506 ppp->dev = NULL; 2507 ppp->dev = NULL;
@@ -2514,7 +2515,7 @@ static void ppp_shutdown_interface(struct ppp *ppp)
2514 ppp->file.dead = 1; 2515 ppp->file.dead = 1;
2515 ppp->owner = NULL; 2516 ppp->owner = NULL;
2516 wake_up_interruptible(&ppp->file.rwait); 2517 wake_up_interruptible(&ppp->file.rwait);
2517 up(&all_ppp_sem); 2518 mutex_unlock(&all_ppp_mutex);
2518} 2519}
2519 2520
2520/* 2521/*
@@ -2556,7 +2557,7 @@ static void ppp_destroy_interface(struct ppp *ppp)
2556 2557
2557/* 2558/*
2558 * Locate an existing ppp unit. 2559 * Locate an existing ppp unit.
2559 * The caller should have locked the all_ppp_sem. 2560 * The caller should have locked the all_ppp_mutex.
2560 */ 2561 */
2561static struct ppp * 2562static struct ppp *
2562ppp_find_unit(int unit) 2563ppp_find_unit(int unit)
@@ -2601,7 +2602,7 @@ ppp_connect_channel(struct channel *pch, int unit)
2601 int ret = -ENXIO; 2602 int ret = -ENXIO;
2602 int hdrlen; 2603 int hdrlen;
2603 2604
2604 down(&all_ppp_sem); 2605 mutex_lock(&all_ppp_mutex);
2605 ppp = ppp_find_unit(unit); 2606 ppp = ppp_find_unit(unit);
2606 if (ppp == 0) 2607 if (ppp == 0)
2607 goto out; 2608 goto out;
@@ -2626,7 +2627,7 @@ ppp_connect_channel(struct channel *pch, int unit)
2626 outl: 2627 outl:
2627 write_unlock_bh(&pch->upl); 2628 write_unlock_bh(&pch->upl);
2628 out: 2629 out:
2629 up(&all_ppp_sem); 2630 mutex_unlock(&all_ppp_mutex);
2630 return ret; 2631 return ret;
2631} 2632}
2632 2633
diff --git a/drivers/net/sk98lin/skge.c b/drivers/net/sk98lin/skge.c
index a5f2b1ee07..38a26df409 100644
--- a/drivers/net/sk98lin/skge.c
+++ b/drivers/net/sk98lin/skge.c
@@ -1727,7 +1727,7 @@ struct sk_buff *pMessage) /* pointer to send-message */
1727 pTxd->VDataHigh = (SK_U32) (PhysAddr >> 32); 1727 pTxd->VDataHigh = (SK_U32) (PhysAddr >> 32);
1728 pTxd->pMBuf = pMessage; 1728 pTxd->pMBuf = pMessage;
1729 1729
1730 pTxd->TBControl = Control | BMU_OWN | sk_frag->size;; 1730 pTxd->TBControl = Control | BMU_OWN | sk_frag->size;
1731 1731
1732 /* 1732 /*
1733 ** Do we have the last fragment? 1733 ** Do we have the last fragment?
diff --git a/drivers/net/skge.c b/drivers/net/skge.c
index 4eda81d41b..35dbf05c7f 100644
--- a/drivers/net/skge.c
+++ b/drivers/net/skge.c
@@ -44,7 +44,7 @@
44#include "skge.h" 44#include "skge.h"
45 45
46#define DRV_NAME "skge" 46#define DRV_NAME "skge"
47#define DRV_VERSION "1.4" 47#define DRV_VERSION "1.5"
48#define PFX DRV_NAME " " 48#define PFX DRV_NAME " "
49 49
50#define DEFAULT_TX_RING_SIZE 128 50#define DEFAULT_TX_RING_SIZE 128
@@ -357,7 +357,7 @@ static struct net_device_stats *skge_get_stats(struct net_device *dev)
357 skge->net_stats.rx_bytes = data[1]; 357 skge->net_stats.rx_bytes = data[1];
358 skge->net_stats.tx_packets = data[2] + data[4] + data[6]; 358 skge->net_stats.tx_packets = data[2] + data[4] + data[6];
359 skge->net_stats.rx_packets = data[3] + data[5] + data[7]; 359 skge->net_stats.rx_packets = data[3] + data[5] + data[7];
360 skge->net_stats.multicast = data[5] + data[7]; 360 skge->net_stats.multicast = data[3] + data[5];
361 skge->net_stats.collisions = data[10]; 361 skge->net_stats.collisions = data[10];
362 skge->net_stats.tx_aborted_errors = data[12]; 362 skge->net_stats.tx_aborted_errors = data[12];
363 363
@@ -781,7 +781,7 @@ static void skge_rx_setup(struct skge_port *skge, struct skge_element *e,
781 * Note: DMA address is not changed by chip. 781 * Note: DMA address is not changed by chip.
782 * MTU not changed while receiver active. 782 * MTU not changed while receiver active.
783 */ 783 */
784static void skge_rx_reuse(struct skge_element *e, unsigned int size) 784static inline void skge_rx_reuse(struct skge_element *e, unsigned int size)
785{ 785{
786 struct skge_rx_desc *rd = e->desc; 786 struct skge_rx_desc *rd = e->desc;
787 787
@@ -829,7 +829,7 @@ static int skge_rx_fill(struct skge_port *skge)
829 do { 829 do {
830 struct sk_buff *skb; 830 struct sk_buff *skb;
831 831
832 skb = dev_alloc_skb(skge->rx_buf_size + NET_IP_ALIGN); 832 skb = alloc_skb(skge->rx_buf_size + NET_IP_ALIGN, GFP_KERNEL);
833 if (!skb) 833 if (!skb)
834 return -ENOMEM; 834 return -ENOMEM;
835 835
@@ -847,8 +847,7 @@ static void skge_link_up(struct skge_port *skge)
847 LED_BLK_OFF|LED_SYNC_OFF|LED_ON); 847 LED_BLK_OFF|LED_SYNC_OFF|LED_ON);
848 848
849 netif_carrier_on(skge->netdev); 849 netif_carrier_on(skge->netdev);
850 if (skge->tx_avail > MAX_SKB_FRAGS + 1) 850 netif_wake_queue(skge->netdev);
851 netif_wake_queue(skge->netdev);
852 851
853 if (netif_msg_link(skge)) 852 if (netif_msg_link(skge))
854 printk(KERN_INFO PFX 853 printk(KERN_INFO PFX
@@ -2155,7 +2154,7 @@ static int skge_up(struct net_device *dev)
2155 printk(KERN_INFO PFX "%s: enabling interface\n", dev->name); 2154 printk(KERN_INFO PFX "%s: enabling interface\n", dev->name);
2156 2155
2157 if (dev->mtu > RX_BUF_SIZE) 2156 if (dev->mtu > RX_BUF_SIZE)
2158 skge->rx_buf_size = dev->mtu + ETH_HLEN + NET_IP_ALIGN; 2157 skge->rx_buf_size = dev->mtu + ETH_HLEN;
2159 else 2158 else
2160 skge->rx_buf_size = RX_BUF_SIZE; 2159 skge->rx_buf_size = RX_BUF_SIZE;
2161 2160
@@ -2190,8 +2189,6 @@ static int skge_up(struct net_device *dev)
2190 if (err) 2189 if (err)
2191 goto free_rx_ring; 2190 goto free_rx_ring;
2192 2191
2193 skge->tx_avail = skge->tx_ring.count - 1;
2194
2195 /* Initialize MAC */ 2192 /* Initialize MAC */
2196 spin_lock_bh(&hw->phy_lock); 2193 spin_lock_bh(&hw->phy_lock);
2197 if (hw->chip_id == CHIP_ID_GENESIS) 2194 if (hw->chip_id == CHIP_ID_GENESIS)
@@ -2294,6 +2291,12 @@ static int skge_down(struct net_device *dev)
2294 return 0; 2291 return 0;
2295} 2292}
2296 2293
2294static inline int skge_avail(const struct skge_ring *ring)
2295{
2296 return ((ring->to_clean > ring->to_use) ? 0 : ring->count)
2297 + (ring->to_clean - ring->to_use) - 1;
2298}
2299
2297static int skge_xmit_frame(struct sk_buff *skb, struct net_device *dev) 2300static int skge_xmit_frame(struct sk_buff *skb, struct net_device *dev)
2298{ 2301{
2299 struct skge_port *skge = netdev_priv(dev); 2302 struct skge_port *skge = netdev_priv(dev);
@@ -2314,7 +2317,7 @@ static int skge_xmit_frame(struct sk_buff *skb, struct net_device *dev)
2314 return NETDEV_TX_LOCKED; 2317 return NETDEV_TX_LOCKED;
2315 } 2318 }
2316 2319
2317 if (unlikely(skge->tx_avail < skb_shinfo(skb)->nr_frags +1)) { 2320 if (unlikely(skge_avail(&skge->tx_ring) < skb_shinfo(skb)->nr_frags + 1)) {
2318 if (!netif_queue_stopped(dev)) { 2321 if (!netif_queue_stopped(dev)) {
2319 netif_stop_queue(dev); 2322 netif_stop_queue(dev);
2320 2323
@@ -2390,8 +2393,7 @@ static int skge_xmit_frame(struct sk_buff *skb, struct net_device *dev)
2390 dev->name, e - ring->start, skb->len); 2393 dev->name, e - ring->start, skb->len);
2391 2394
2392 ring->to_use = e->next; 2395 ring->to_use = e->next;
2393 skge->tx_avail -= skb_shinfo(skb)->nr_frags + 1; 2396 if (skge_avail(&skge->tx_ring) <= MAX_SKB_FRAGS + 1) {
2394 if (skge->tx_avail <= MAX_SKB_FRAGS + 1) {
2395 pr_debug("%s: transmit queue full\n", dev->name); 2397 pr_debug("%s: transmit queue full\n", dev->name);
2396 netif_stop_queue(dev); 2398 netif_stop_queue(dev);
2397 } 2399 }
@@ -2404,35 +2406,37 @@ static int skge_xmit_frame(struct sk_buff *skb, struct net_device *dev)
2404 return NETDEV_TX_OK; 2406 return NETDEV_TX_OK;
2405} 2407}
2406 2408
2407static inline void skge_tx_free(struct skge_hw *hw, struct skge_element *e) 2409static void skge_tx_complete(struct skge_port *skge, struct skge_element *last)
2408{ 2410{
2409 /* This ring element can be skb or fragment */ 2411 struct pci_dev *pdev = skge->hw->pdev;
2410 if (e->skb) { 2412 struct skge_element *e;
2411 pci_unmap_single(hw->pdev, 2413
2412 pci_unmap_addr(e, mapaddr), 2414 for (e = skge->tx_ring.to_clean; e != last; e = e->next) {
2413 pci_unmap_len(e, maplen), 2415 struct sk_buff *skb = e->skb;
2414 PCI_DMA_TODEVICE); 2416 int i;
2415 dev_kfree_skb(e->skb); 2417
2416 e->skb = NULL; 2418 e->skb = NULL;
2417 } else { 2419 pci_unmap_single(pdev, pci_unmap_addr(e, mapaddr),
2418 pci_unmap_page(hw->pdev, 2420 skb_headlen(skb), PCI_DMA_TODEVICE);
2419 pci_unmap_addr(e, mapaddr), 2421
2420 pci_unmap_len(e, maplen), 2422 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
2421 PCI_DMA_TODEVICE); 2423 e = e->next;
2424 pci_unmap_page(pdev, pci_unmap_addr(e, mapaddr),
2425 skb_shinfo(skb)->frags[i].size,
2426 PCI_DMA_TODEVICE);
2427 }
2428
2429 dev_kfree_skb(skb);
2422 } 2430 }
2431 skge->tx_ring.to_clean = e;
2423} 2432}
2424 2433
2425static void skge_tx_clean(struct skge_port *skge) 2434static void skge_tx_clean(struct skge_port *skge)
2426{ 2435{
2427 struct skge_ring *ring = &skge->tx_ring;
2428 struct skge_element *e;
2429 2436
2430 spin_lock_bh(&skge->tx_lock); 2437 spin_lock_bh(&skge->tx_lock);
2431 for (e = ring->to_clean; e != ring->to_use; e = e->next) { 2438 skge_tx_complete(skge, skge->tx_ring.to_use);
2432 ++skge->tx_avail; 2439 netif_wake_queue(skge->netdev);
2433 skge_tx_free(skge->hw, e);
2434 }
2435 ring->to_clean = e;
2436 spin_unlock_bh(&skge->tx_lock); 2440 spin_unlock_bh(&skge->tx_lock);
2437} 2441}
2438 2442
@@ -2592,7 +2596,7 @@ static inline struct sk_buff *skge_rx_get(struct skge_port *skge,
2592 goto error; 2596 goto error;
2593 2597
2594 if (len < RX_COPY_THRESHOLD) { 2598 if (len < RX_COPY_THRESHOLD) {
2595 skb = dev_alloc_skb(len + 2); 2599 skb = alloc_skb(len + 2, GFP_ATOMIC);
2596 if (!skb) 2600 if (!skb)
2597 goto resubmit; 2601 goto resubmit;
2598 2602
@@ -2607,10 +2611,11 @@ static inline struct sk_buff *skge_rx_get(struct skge_port *skge,
2607 skge_rx_reuse(e, skge->rx_buf_size); 2611 skge_rx_reuse(e, skge->rx_buf_size);
2608 } else { 2612 } else {
2609 struct sk_buff *nskb; 2613 struct sk_buff *nskb;
2610 nskb = dev_alloc_skb(skge->rx_buf_size + NET_IP_ALIGN); 2614 nskb = alloc_skb(skge->rx_buf_size + NET_IP_ALIGN, GFP_ATOMIC);
2611 if (!nskb) 2615 if (!nskb)
2612 goto resubmit; 2616 goto resubmit;
2613 2617
2618 skb_reserve(nskb, NET_IP_ALIGN);
2614 pci_unmap_single(skge->hw->pdev, 2619 pci_unmap_single(skge->hw->pdev,
2615 pci_unmap_addr(e, mapaddr), 2620 pci_unmap_addr(e, mapaddr),
2616 pci_unmap_len(e, maplen), 2621 pci_unmap_len(e, maplen),
@@ -2661,30 +2666,29 @@ resubmit:
2661static void skge_tx_done(struct skge_port *skge) 2666static void skge_tx_done(struct skge_port *skge)
2662{ 2667{
2663 struct skge_ring *ring = &skge->tx_ring; 2668 struct skge_ring *ring = &skge->tx_ring;
2664 struct skge_element *e; 2669 struct skge_element *e, *last;
2665 2670
2666 spin_lock(&skge->tx_lock); 2671 spin_lock(&skge->tx_lock);
2667 for (e = ring->to_clean; prefetch(e->next), e != ring->to_use; e = e->next) { 2672 last = ring->to_clean;
2673 for (e = ring->to_clean; e != ring->to_use; e = e->next) {
2668 struct skge_tx_desc *td = e->desc; 2674 struct skge_tx_desc *td = e->desc;
2669 u32 control;
2670 2675
2671 rmb(); 2676 if (td->control & BMU_OWN)
2672 control = td->control;
2673 if (control & BMU_OWN)
2674 break; 2677 break;
2675 2678
2676 if (unlikely(netif_msg_tx_done(skge))) 2679 if (td->control & BMU_EOF) {
2677 printk(KERN_DEBUG PFX "%s: tx done slot %td status 0x%x\n", 2680 last = e->next;
2678 skge->netdev->name, e - ring->start, td->status); 2681 if (unlikely(netif_msg_tx_done(skge)))
2679 2682 printk(KERN_DEBUG PFX "%s: tx done slot %td\n",
2680 skge_tx_free(skge->hw, e); 2683 skge->netdev->name, e - ring->start);
2681 e->skb = NULL; 2684 }
2682 ++skge->tx_avail;
2683 } 2685 }
2684 ring->to_clean = e; 2686
2687 skge_tx_complete(skge, last);
2688
2685 skge_write8(skge->hw, Q_ADDR(txqaddr[skge->port], Q_CSR), CSR_IRQ_CL_F); 2689 skge_write8(skge->hw, Q_ADDR(txqaddr[skge->port], Q_CSR), CSR_IRQ_CL_F);
2686 2690
2687 if (skge->tx_avail > MAX_SKB_FRAGS + 1) 2691 if (skge_avail(&skge->tx_ring) > MAX_SKB_FRAGS + 1)
2688 netif_wake_queue(skge->netdev); 2692 netif_wake_queue(skge->netdev);
2689 2693
2690 spin_unlock(&skge->tx_lock); 2694 spin_unlock(&skge->tx_lock);
@@ -2718,8 +2722,7 @@ static int skge_poll(struct net_device *dev, int *budget)
2718 netif_receive_skb(skb); 2722 netif_receive_skb(skb);
2719 2723
2720 ++work_done; 2724 ++work_done;
2721 } else 2725 }
2722 skge_rx_reuse(e, skge->rx_buf_size);
2723 } 2726 }
2724 ring->to_clean = e; 2727 ring->to_clean = e;
2725 2728
diff --git a/drivers/net/skge.h b/drivers/net/skge.h
index 2efdacc290..1f1ce88c81 100644
--- a/drivers/net/skge.h
+++ b/drivers/net/skge.h
@@ -2418,7 +2418,6 @@ struct skge_port {
2418 int port; 2418 int port;
2419 2419
2420 spinlock_t tx_lock; 2420 spinlock_t tx_lock;
2421 u32 tx_avail;
2422 struct skge_ring tx_ring; 2421 struct skge_ring tx_ring;
2423 struct skge_ring rx_ring; 2422 struct skge_ring rx_ring;
2424 2423
diff --git a/drivers/net/sky2.c b/drivers/net/sky2.c
index 36db93811a..68f9c206a6 100644
--- a/drivers/net/sky2.c
+++ b/drivers/net/sky2.c
@@ -1175,7 +1175,7 @@ static int sky2_xmit_frame(struct sk_buff *skb, struct net_device *dev)
1175 /* just drop the packet if non-linear expansion fails */ 1175 /* just drop the packet if non-linear expansion fails */
1176 if (skb_header_cloned(skb) && 1176 if (skb_header_cloned(skb) &&
1177 pskb_expand_head(skb, 0, 0, GFP_ATOMIC)) { 1177 pskb_expand_head(skb, 0, 0, GFP_ATOMIC)) {
1178 dev_kfree_skb_any(skb); 1178 dev_kfree_skb(skb);
1179 goto out_unlock; 1179 goto out_unlock;
1180 } 1180 }
1181 1181
@@ -1324,7 +1324,7 @@ static void sky2_tx_complete(struct sky2_port *sky2, u16 done)
1324 PCI_DMA_TODEVICE); 1324 PCI_DMA_TODEVICE);
1325 } 1325 }
1326 1326
1327 dev_kfree_skb_any(skb); 1327 dev_kfree_skb(skb);
1328 } 1328 }
1329 1329
1330 sky2->tx_cons = put; 1330 sky2->tx_cons = put;
@@ -2484,7 +2484,7 @@ static const struct sky2_stat {
2484 { "single_collisions", GM_TXF_SNG_COL }, 2484 { "single_collisions", GM_TXF_SNG_COL },
2485 { "multi_collisions", GM_TXF_MUL_COL }, 2485 { "multi_collisions", GM_TXF_MUL_COL },
2486 2486
2487 { "rx_short", GM_RXE_SHT }, 2487 { "rx_short", GM_RXF_SHT },
2488 { "rx_runt", GM_RXE_FRAG }, 2488 { "rx_runt", GM_RXE_FRAG },
2489 { "rx_64_byte_packets", GM_RXF_64B }, 2489 { "rx_64_byte_packets", GM_RXF_64B },
2490 { "rx_65_to_127_byte_packets", GM_RXF_127B }, 2490 { "rx_65_to_127_byte_packets", GM_RXF_127B },
@@ -2607,7 +2607,7 @@ static struct net_device_stats *sky2_get_stats(struct net_device *dev)
2607 sky2->net_stats.rx_bytes = data[1]; 2607 sky2->net_stats.rx_bytes = data[1];
2608 sky2->net_stats.tx_packets = data[2] + data[4] + data[6]; 2608 sky2->net_stats.tx_packets = data[2] + data[4] + data[6];
2609 sky2->net_stats.rx_packets = data[3] + data[5] + data[7]; 2609 sky2->net_stats.rx_packets = data[3] + data[5] + data[7];
2610 sky2->net_stats.multicast = data[5] + data[7]; 2610 sky2->net_stats.multicast = data[3] + data[5];
2611 sky2->net_stats.collisions = data[10]; 2611 sky2->net_stats.collisions = data[10];
2612 sky2->net_stats.tx_aborted_errors = data[12]; 2612 sky2->net_stats.tx_aborted_errors = data[12];
2613 2613
diff --git a/drivers/net/sky2.h b/drivers/net/sky2.h
index 2838f661b3..62532b4e45 100644
--- a/drivers/net/sky2.h
+++ b/drivers/net/sky2.h
@@ -1804,7 +1804,7 @@ struct sky2_rx_le {
1804 __le16 length; 1804 __le16 length;
1805 u8 ctrl; 1805 u8 ctrl;
1806 u8 opcode; 1806 u8 opcode;
1807} __attribute((packed));; 1807} __attribute((packed));
1808 1808
1809struct sky2_status_le { 1809struct sky2_status_le {
1810 __le32 status; /* also checksum */ 1810 __le32 status; /* also checksum */
diff --git a/drivers/net/tg3.c b/drivers/net/tg3.c
index 88829eb956..b5473325bf 100644
--- a/drivers/net/tg3.c
+++ b/drivers/net/tg3.c
@@ -69,8 +69,8 @@
69 69
70#define DRV_MODULE_NAME "tg3" 70#define DRV_MODULE_NAME "tg3"
71#define PFX DRV_MODULE_NAME ": " 71#define PFX DRV_MODULE_NAME ": "
72#define DRV_MODULE_VERSION "3.53" 72#define DRV_MODULE_VERSION "3.54"
73#define DRV_MODULE_RELDATE "Mar 22, 2006" 73#define DRV_MODULE_RELDATE "Mar 23, 2006"
74 74
75#define TG3_DEF_MAC_MODE 0 75#define TG3_DEF_MAC_MODE 0
76#define TG3_DEF_RX_MODE 0 76#define TG3_DEF_RX_MODE 0
@@ -225,6 +225,10 @@ static struct pci_device_id tg3_pci_tbl[] = {
225 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL }, 225 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
226 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5754M, 226 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5754M,
227 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL }, 227 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
228 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5755,
229 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
230 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5755M,
231 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
228 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787, 232 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787,
229 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL }, 233 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
230 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787M, 234 { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787M,
@@ -4557,6 +4561,7 @@ static int tg3_chip_reset(struct tg3 *tp)
4557 } 4561 }
4558 4562
4559 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 || 4563 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 ||
4564 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
4560 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787) 4565 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787)
4561 tw32(GRC_FASTBOOT_PC, 0); 4566 tw32(GRC_FASTBOOT_PC, 0);
4562 4567
@@ -6152,6 +6157,9 @@ static int tg3_reset_hw(struct tg3 *tp)
6152 gpio_mask |= GRC_LCLCTRL_GPIO_OE3 | 6157 gpio_mask |= GRC_LCLCTRL_GPIO_OE3 |
6153 GRC_LCLCTRL_GPIO_OUTPUT3; 6158 GRC_LCLCTRL_GPIO_OUTPUT3;
6154 6159
6160 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755)
6161 gpio_mask |= GRC_LCLCTRL_GPIO_UART_SEL;
6162
6155 tp->grc_local_ctrl |= tr32(GRC_LOCAL_CTRL) & gpio_mask; 6163 tp->grc_local_ctrl |= tr32(GRC_LOCAL_CTRL) & gpio_mask;
6156 6164
6157 /* GPIO1 must be driven high for eeprom write protect */ 6165 /* GPIO1 must be driven high for eeprom write protect */
@@ -6191,7 +6199,8 @@ static int tg3_reset_hw(struct tg3 *tp)
6191 } 6199 }
6192 6200
6193 /* Enable host coalescing bug fix */ 6201 /* Enable host coalescing bug fix */
6194 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787) 6202 if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755) ||
6203 (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787))
6195 val |= (1 << 29); 6204 val |= (1 << 29);
6196 6205
6197 tw32_f(WDMAC_MODE, val); 6206 tw32_f(WDMAC_MODE, val);
@@ -6249,6 +6258,9 @@ static int tg3_reset_hw(struct tg3 *tp)
6249 udelay(100); 6258 udelay(100);
6250 6259
6251 tp->rx_mode = RX_MODE_ENABLE; 6260 tp->rx_mode = RX_MODE_ENABLE;
6261 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755)
6262 tp->rx_mode |= RX_MODE_IPV6_CSUM_ENABLE;
6263
6252 tw32_f(MAC_RX_MODE, tp->rx_mode); 6264 tw32_f(MAC_RX_MODE, tp->rx_mode);
6253 udelay(10); 6265 udelay(10);
6254 6266
@@ -7907,7 +7919,8 @@ static int tg3_set_tx_csum(struct net_device *dev, u32 data)
7907 return 0; 7919 return 0;
7908 } 7920 }
7909 7921
7910 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787) 7922 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
7923 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787)
7911 ethtool_op_set_tx_hw_csum(dev, data); 7924 ethtool_op_set_tx_hw_csum(dev, data);
7912 else 7925 else
7913 ethtool_op_set_tx_csum(dev, data); 7926 ethtool_op_set_tx_csum(dev, data);
@@ -8332,7 +8345,8 @@ static int tg3_test_memory(struct tg3 *tp)
8332 int i; 8345 int i;
8333 8346
8334 if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) { 8347 if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
8335 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787) 8348 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
8349 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787)
8336 mem_tbl = mem_tbl_5755; 8350 mem_tbl = mem_tbl_5755;
8337 else 8351 else
8338 mem_tbl = mem_tbl_5705; 8352 mem_tbl = mem_tbl_5705;
@@ -8924,6 +8938,47 @@ static void __devinit tg3_get_5752_nvram_info(struct tg3 *tp)
8924 } 8938 }
8925} 8939}
8926 8940
8941static void __devinit tg3_get_5755_nvram_info(struct tg3 *tp)
8942{
8943 u32 nvcfg1;
8944
8945 nvcfg1 = tr32(NVRAM_CFG1);
8946
8947 /* NVRAM protection for TPM */
8948 if (nvcfg1 & (1 << 27))
8949 tp->tg3_flags2 |= TG3_FLG2_PROTECTED_NVRAM;
8950
8951 switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) {
8952 case FLASH_5755VENDOR_ATMEL_EEPROM_64KHZ:
8953 case FLASH_5755VENDOR_ATMEL_EEPROM_376KHZ:
8954 tp->nvram_jedecnum = JEDEC_ATMEL;
8955 tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
8956 tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE;
8957
8958 nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS;
8959 tw32(NVRAM_CFG1, nvcfg1);
8960 break;
8961 case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED:
8962 case FLASH_5755VENDOR_ATMEL_FLASH_1:
8963 case FLASH_5755VENDOR_ATMEL_FLASH_2:
8964 case FLASH_5755VENDOR_ATMEL_FLASH_3:
8965 case FLASH_5755VENDOR_ATMEL_FLASH_4:
8966 tp->nvram_jedecnum = JEDEC_ATMEL;
8967 tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
8968 tp->tg3_flags2 |= TG3_FLG2_FLASH;
8969 tp->nvram_pagesize = 264;
8970 break;
8971 case FLASH_5752VENDOR_ST_M45PE10:
8972 case FLASH_5752VENDOR_ST_M45PE20:
8973 case FLASH_5752VENDOR_ST_M45PE40:
8974 tp->nvram_jedecnum = JEDEC_ST;
8975 tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
8976 tp->tg3_flags2 |= TG3_FLG2_FLASH;
8977 tp->nvram_pagesize = 256;
8978 break;
8979 }
8980}
8981
8927static void __devinit tg3_get_5787_nvram_info(struct tg3 *tp) 8982static void __devinit tg3_get_5787_nvram_info(struct tg3 *tp)
8928{ 8983{
8929 u32 nvcfg1; 8984 u32 nvcfg1;
@@ -8997,6 +9052,8 @@ static void __devinit tg3_nvram_init(struct tg3 *tp)
8997 9052
8998 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752) 9053 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752)
8999 tg3_get_5752_nvram_info(tp); 9054 tg3_get_5752_nvram_info(tp);
9055 else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755)
9056 tg3_get_5755_nvram_info(tp);
9000 else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787) 9057 else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787)
9001 tg3_get_5787_nvram_info(tp); 9058 tg3_get_5787_nvram_info(tp);
9002 else 9059 else
@@ -9310,6 +9367,7 @@ static int tg3_nvram_write_block_buffered(struct tg3 *tp, u32 offset, u32 len,
9310 nvram_cmd |= NVRAM_CMD_LAST; 9367 nvram_cmd |= NVRAM_CMD_LAST;
9311 9368
9312 if ((GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5752) && 9369 if ((GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5752) &&
9370 (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5755) &&
9313 (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5787) && 9371 (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5787) &&
9314 (tp->nvram_jedecnum == JEDEC_ST) && 9372 (tp->nvram_jedecnum == JEDEC_ST) &&
9315 (nvram_cmd & NVRAM_CMD_FIRST)) { 9373 (nvram_cmd & NVRAM_CMD_FIRST)) {
@@ -10044,6 +10102,7 @@ static int __devinit tg3_get_invariants(struct tg3 *tp)
10044 10102
10045 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 || 10103 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 ||
10046 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 || 10104 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 ||
10105 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
10047 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 || 10106 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 ||
10048 (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) 10107 (tp->tg3_flags2 & TG3_FLG2_5780_CLASS))
10049 tp->tg3_flags2 |= TG3_FLG2_5750_PLUS; 10108 tp->tg3_flags2 |= TG3_FLG2_5750_PLUS;
@@ -10053,7 +10112,8 @@ static int __devinit tg3_get_invariants(struct tg3 *tp)
10053 tp->tg3_flags2 |= TG3_FLG2_5705_PLUS; 10112 tp->tg3_flags2 |= TG3_FLG2_5705_PLUS;
10054 10113
10055 if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) { 10114 if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) {
10056 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787) { 10115 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
10116 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787) {
10057 tp->tg3_flags2 |= TG3_FLG2_HW_TSO_2; 10117 tp->tg3_flags2 |= TG3_FLG2_HW_TSO_2;
10058 tp->tg3_flags2 |= TG3_FLG2_1SHOT_MSI; 10118 tp->tg3_flags2 |= TG3_FLG2_1SHOT_MSI;
10059 } else 10119 } else
@@ -10063,6 +10123,7 @@ static int __devinit tg3_get_invariants(struct tg3 *tp)
10063 if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5705 && 10123 if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5705 &&
10064 GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5750 && 10124 GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5750 &&
10065 GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5752 && 10125 GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5752 &&
10126 GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5755 &&
10066 GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5787) 10127 GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5787)
10067 tp->tg3_flags2 |= TG3_FLG2_JUMBO_CAPABLE; 10128 tp->tg3_flags2 |= TG3_FLG2_JUMBO_CAPABLE;
10068 10129
@@ -10219,6 +10280,9 @@ static int __devinit tg3_get_invariants(struct tg3 *tp)
10219 else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752) 10280 else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752)
10220 tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE3; 10281 tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE3;
10221 10282
10283 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755)
10284 tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_UART_SEL;
10285
10222 /* Force the chip into D0. */ 10286 /* Force the chip into D0. */
10223 err = tg3_set_power_state(tp, PCI_D0); 10287 err = tg3_set_power_state(tp, PCI_D0);
10224 if (err) { 10288 if (err) {
@@ -10274,6 +10338,7 @@ static int __devinit tg3_get_invariants(struct tg3 *tp)
10274 tp->tg3_flags2 |= TG3_FLG2_PHY_5704_A0_BUG; 10338 tp->tg3_flags2 |= TG3_FLG2_PHY_5704_A0_BUG;
10275 10339
10276 if ((tp->tg3_flags2 & TG3_FLG2_5705_PLUS) && 10340 if ((tp->tg3_flags2 & TG3_FLG2_5705_PLUS) &&
10341 (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5755) &&
10277 (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5787)) 10342 (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5787))
10278 tp->tg3_flags2 |= TG3_FLG2_PHY_BER_BUG; 10343 tp->tg3_flags2 |= TG3_FLG2_PHY_BER_BUG;
10279 10344
@@ -10413,7 +10478,8 @@ static int __devinit tg3_get_invariants(struct tg3 *tp)
10413 /* All chips before 5787 can get confused if TX buffers 10478 /* All chips before 5787 can get confused if TX buffers
10414 * straddle the 4GB address boundary in some cases. 10479 * straddle the 4GB address boundary in some cases.
10415 */ 10480 */
10416 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787) 10481 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
10482 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787)
10417 tp->dev->hard_start_xmit = tg3_start_xmit; 10483 tp->dev->hard_start_xmit = tg3_start_xmit;
10418 else 10484 else
10419 tp->dev->hard_start_xmit = tg3_start_xmit_dma_bug; 10485 tp->dev->hard_start_xmit = tg3_start_xmit_dma_bug;
@@ -11002,6 +11068,7 @@ static char * __devinit tg3_phy_string(struct tg3 *tp)
11002 case PHY_ID_BCM5752: return "5752"; 11068 case PHY_ID_BCM5752: return "5752";
11003 case PHY_ID_BCM5714: return "5714"; 11069 case PHY_ID_BCM5714: return "5714";
11004 case PHY_ID_BCM5780: return "5780"; 11070 case PHY_ID_BCM5780: return "5780";
11071 case PHY_ID_BCM5755: return "5755";
11005 case PHY_ID_BCM5787: return "5787"; 11072 case PHY_ID_BCM5787: return "5787";
11006 case PHY_ID_BCM8002: return "8002/serdes"; 11073 case PHY_ID_BCM8002: return "8002/serdes";
11007 case 0: return "serdes"; 11074 case 0: return "serdes";
@@ -11350,7 +11417,8 @@ static int __devinit tg3_init_one(struct pci_dev *pdev,
11350 * checksumming. 11417 * checksumming.
11351 */ 11418 */
11352 if ((tp->tg3_flags & TG3_FLAG_BROKEN_CHECKSUMS) == 0) { 11419 if ((tp->tg3_flags & TG3_FLAG_BROKEN_CHECKSUMS) == 0) {
11353 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787) 11420 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
11421 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787)
11354 dev->features |= NETIF_F_HW_CSUM; 11422 dev->features |= NETIF_F_HW_CSUM;
11355 else 11423 else
11356 dev->features |= NETIF_F_IP_CSUM; 11424 dev->features |= NETIF_F_IP_CSUM;
diff --git a/drivers/net/tg3.h b/drivers/net/tg3.h
index baa34c4721..c43cc32642 100644
--- a/drivers/net/tg3.h
+++ b/drivers/net/tg3.h
@@ -138,6 +138,7 @@
138#define ASIC_REV_5752 0x06 138#define ASIC_REV_5752 0x06
139#define ASIC_REV_5780 0x08 139#define ASIC_REV_5780 0x08
140#define ASIC_REV_5714 0x09 140#define ASIC_REV_5714 0x09
141#define ASIC_REV_5755 0x0a
141#define ASIC_REV_5787 0x0b 142#define ASIC_REV_5787 0x0b
142#define GET_CHIP_REV(CHIP_REV_ID) ((CHIP_REV_ID) >> 8) 143#define GET_CHIP_REV(CHIP_REV_ID) ((CHIP_REV_ID) >> 8)
143#define CHIPREV_5700_AX 0x70 144#define CHIPREV_5700_AX 0x70
@@ -456,6 +457,7 @@
456#define RX_MODE_PROMISC 0x00000100 457#define RX_MODE_PROMISC 0x00000100
457#define RX_MODE_NO_CRC_CHECK 0x00000200 458#define RX_MODE_NO_CRC_CHECK 0x00000200
458#define RX_MODE_KEEP_VLAN_TAG 0x00000400 459#define RX_MODE_KEEP_VLAN_TAG 0x00000400
460#define RX_MODE_IPV6_CSUM_ENABLE 0x01000000
459#define MAC_RX_STATUS 0x0000046c 461#define MAC_RX_STATUS 0x0000046c
460#define RX_STATUS_REMOTE_TX_XOFFED 0x00000001 462#define RX_STATUS_REMOTE_TX_XOFFED 0x00000001
461#define RX_STATUS_XOFF_RCVD 0x00000002 463#define RX_STATUS_XOFF_RCVD 0x00000002
@@ -1340,6 +1342,7 @@
1340#define GRC_LCLCTRL_CLEARINT 0x00000002 1342#define GRC_LCLCTRL_CLEARINT 0x00000002
1341#define GRC_LCLCTRL_SETINT 0x00000004 1343#define GRC_LCLCTRL_SETINT 0x00000004
1342#define GRC_LCLCTRL_INT_ON_ATTN 0x00000008 1344#define GRC_LCLCTRL_INT_ON_ATTN 0x00000008
1345#define GRC_LCLCTRL_GPIO_UART_SEL 0x00000010 /* 5755 only */
1343#define GRC_LCLCTRL_USE_SIG_DETECT 0x00000010 /* 5714/5780 only */ 1346#define GRC_LCLCTRL_USE_SIG_DETECT 0x00000010 /* 5714/5780 only */
1344#define GRC_LCLCTRL_USE_EXT_SIG_DETECT 0x00000020 /* 5714/5780 only */ 1347#define GRC_LCLCTRL_USE_EXT_SIG_DETECT 0x00000020 /* 5714/5780 only */
1345#define GRC_LCLCTRL_GPIO_INPUT3 0x00000020 1348#define GRC_LCLCTRL_GPIO_INPUT3 0x00000020
@@ -1441,6 +1444,9 @@
1441#define FLASH_5755VENDOR_ATMEL_FLASH_1 0x03400001 1444#define FLASH_5755VENDOR_ATMEL_FLASH_1 0x03400001
1442#define FLASH_5755VENDOR_ATMEL_FLASH_2 0x03400002 1445#define FLASH_5755VENDOR_ATMEL_FLASH_2 0x03400002
1443#define FLASH_5755VENDOR_ATMEL_FLASH_3 0x03400000 1446#define FLASH_5755VENDOR_ATMEL_FLASH_3 0x03400000
1447#define FLASH_5755VENDOR_ATMEL_FLASH_4 0x00000003
1448#define FLASH_5755VENDOR_ATMEL_EEPROM_64KHZ 0x03c00003
1449#define FLASH_5755VENDOR_ATMEL_EEPROM_376KHZ 0x03c00002
1444#define FLASH_5787VENDOR_ATMEL_EEPROM_64KHZ 0x03000003 1450#define FLASH_5787VENDOR_ATMEL_EEPROM_64KHZ 0x03000003
1445#define FLASH_5787VENDOR_ATMEL_EEPROM_376KHZ 0x03000002 1451#define FLASH_5787VENDOR_ATMEL_EEPROM_376KHZ 0x03000002
1446#define FLASH_5787VENDOR_MICRO_EEPROM_64KHZ 0x03000000 1452#define FLASH_5787VENDOR_MICRO_EEPROM_64KHZ 0x03000000
@@ -2259,6 +2265,7 @@ struct tg3 {
2259#define PHY_ID_BCM5752 0x60008100 2265#define PHY_ID_BCM5752 0x60008100
2260#define PHY_ID_BCM5714 0x60008340 2266#define PHY_ID_BCM5714 0x60008340
2261#define PHY_ID_BCM5780 0x60008350 2267#define PHY_ID_BCM5780 0x60008350
2268#define PHY_ID_BCM5755 0xbc050cc0
2262#define PHY_ID_BCM5787 0xbc050ce0 2269#define PHY_ID_BCM5787 0xbc050ce0
2263#define PHY_ID_BCM8002 0x60010140 2270#define PHY_ID_BCM8002 0x60010140
2264#define PHY_ID_INVALID 0xffffffff 2271#define PHY_ID_INVALID 0xffffffff
@@ -2286,7 +2293,7 @@ struct tg3 {
2286 (X) == PHY_ID_BCM5705 || (X) == PHY_ID_BCM5750 || \ 2293 (X) == PHY_ID_BCM5705 || (X) == PHY_ID_BCM5750 || \
2287 (X) == PHY_ID_BCM5752 || (X) == PHY_ID_BCM5714 || \ 2294 (X) == PHY_ID_BCM5752 || (X) == PHY_ID_BCM5714 || \
2288 (X) == PHY_ID_BCM5780 || (X) == PHY_ID_BCM5787 || \ 2295 (X) == PHY_ID_BCM5780 || (X) == PHY_ID_BCM5787 || \
2289 (X) == PHY_ID_BCM8002) 2296 (X) == PHY_ID_BCM5755 || (X) == PHY_ID_BCM8002)
2290 2297
2291 struct tg3_hw_stats *hw_stats; 2298 struct tg3_hw_stats *hw_stats;
2292 dma_addr_t stats_mapping; 2299 dma_addr_t stats_mapping;
diff --git a/drivers/net/wireless/Kconfig b/drivers/net/wireless/Kconfig
index 5b0a19a505..6a1033ec06 100644
--- a/drivers/net/wireless/Kconfig
+++ b/drivers/net/wireless/Kconfig
@@ -25,6 +25,15 @@ config NET_RADIO
25 the tools from 25 the tools from
26 <http://www.hpl.hp.com/personal/Jean_Tourrilhes/Linux/Tools.html>. 26 <http://www.hpl.hp.com/personal/Jean_Tourrilhes/Linux/Tools.html>.
27 27
28config NET_WIRELESS_RTNETLINK
29 bool "Wireless Extension API over RtNetlink"
30 ---help---
31 Support the Wireless Extension API over the RtNetlink socket
32 in addition to the traditional ioctl interface (selected above).
33
34 For now, few tools use this facility, but it might grow in the
35 future. The only downside is that it adds 4.5 kB to your kernel.
36
28# Note : the cards are obsolete (can't buy them anymore), but the drivers 37# Note : the cards are obsolete (can't buy them anymore), but the drivers
29# are not, as people are still using them... 38# are not, as people are still using them...
30comment "Obsolete Wireless cards support (pre-802.11)" 39comment "Obsolete Wireless cards support (pre-802.11)"
diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
index 864937a409..108d9fed8f 100644
--- a/drivers/net/wireless/airo.c
+++ b/drivers/net/wireless/airo.c
@@ -770,6 +770,11 @@ typedef struct {
770} BSSListRid; 770} BSSListRid;
771 771
772typedef struct { 772typedef struct {
773 BSSListRid bss;
774 struct list_head list;
775} BSSListElement;
776
777typedef struct {
773 u8 rssipct; 778 u8 rssipct;
774 u8 rssidBm; 779 u8 rssidBm;
775} tdsRssiEntry; 780} tdsRssiEntry;
@@ -902,6 +907,7 @@ static char swversion[] = "2.1";
902#define NUM_MODULES 2 907#define NUM_MODULES 2
903#define MIC_MSGLEN_MAX 2400 908#define MIC_MSGLEN_MAX 2400
904#define EMMH32_MSGLEN_MAX MIC_MSGLEN_MAX 909#define EMMH32_MSGLEN_MAX MIC_MSGLEN_MAX
910#define AIRO_DEF_MTU 2312
905 911
906typedef struct { 912typedef struct {
907 u32 size; // size 913 u32 size; // size
@@ -1119,6 +1125,8 @@ static int decapsulate(struct airo_info *ai, MICBuffer *mic, etherHead *pPacket,
1119static u8 airo_rssi_to_dbm (tdsRssiEntry *rssi_rid, u8 rssi); 1125static u8 airo_rssi_to_dbm (tdsRssiEntry *rssi_rid, u8 rssi);
1120static u8 airo_dbm_to_pct (tdsRssiEntry *rssi_rid, u8 dbm); 1126static u8 airo_dbm_to_pct (tdsRssiEntry *rssi_rid, u8 dbm);
1121 1127
1128static void airo_networks_free(struct airo_info *ai);
1129
1122struct airo_info { 1130struct airo_info {
1123 struct net_device_stats stats; 1131 struct net_device_stats stats;
1124 struct net_device *dev; 1132 struct net_device *dev;
@@ -1150,7 +1158,7 @@ struct airo_info {
1150#define FLAG_COMMIT 13 1158#define FLAG_COMMIT 13
1151#define FLAG_RESET 14 1159#define FLAG_RESET 14
1152#define FLAG_FLASHING 15 1160#define FLAG_FLASHING 15
1153#define JOB_MASK 0x1ff0000 1161#define JOB_MASK 0x2ff0000
1154#define JOB_DIE 16 1162#define JOB_DIE 16
1155#define JOB_XMIT 17 1163#define JOB_XMIT 17
1156#define JOB_XMIT11 18 1164#define JOB_XMIT11 18
@@ -1160,6 +1168,7 @@ struct airo_info {
1160#define JOB_EVENT 22 1168#define JOB_EVENT 22
1161#define JOB_AUTOWEP 23 1169#define JOB_AUTOWEP 23
1162#define JOB_WSTATS 24 1170#define JOB_WSTATS 24
1171#define JOB_SCAN_RESULTS 25
1163 int (*bap_read)(struct airo_info*, u16 *pu16Dst, int bytelen, 1172 int (*bap_read)(struct airo_info*, u16 *pu16Dst, int bytelen,
1164 int whichbap); 1173 int whichbap);
1165 unsigned short *flash; 1174 unsigned short *flash;
@@ -1176,7 +1185,7 @@ struct airo_info {
1176 } xmit, xmit11; 1185 } xmit, xmit11;
1177 struct net_device *wifidev; 1186 struct net_device *wifidev;
1178 struct iw_statistics wstats; // wireless stats 1187 struct iw_statistics wstats; // wireless stats
1179 unsigned long scan_timestamp; /* Time started to scan */ 1188 unsigned long scan_timeout; /* Time scan should be read */
1180 struct iw_spy_data spy_data; 1189 struct iw_spy_data spy_data;
1181 struct iw_public_data wireless_data; 1190 struct iw_public_data wireless_data;
1182 /* MIC stuff */ 1191 /* MIC stuff */
@@ -1198,6 +1207,10 @@ struct airo_info {
1198 APListRid *APList; 1207 APListRid *APList;
1199#define PCI_SHARED_LEN 2*MPI_MAX_FIDS*PKTSIZE+RIDSIZE 1208#define PCI_SHARED_LEN 2*MPI_MAX_FIDS*PKTSIZE+RIDSIZE
1200 char proc_name[IFNAMSIZ]; 1209 char proc_name[IFNAMSIZ];
1210
1211 struct list_head network_list;
1212 struct list_head network_free_list;
1213 BSSListElement *networks;
1201}; 1214};
1202 1215
1203static inline int bap_read(struct airo_info *ai, u16 *pu16Dst, int bytelen, 1216static inline int bap_read(struct airo_info *ai, u16 *pu16Dst, int bytelen,
@@ -1216,6 +1229,22 @@ static int flashgchar(struct airo_info *ai,int matchbyte,int dwelltime);
1216static int flashputbuf(struct airo_info *ai); 1229static int flashputbuf(struct airo_info *ai);
1217static int flashrestart(struct airo_info *ai,struct net_device *dev); 1230static int flashrestart(struct airo_info *ai,struct net_device *dev);
1218 1231
1232#define airo_print(type, name, fmt, args...) \
1233 { printk(type "airo(%s): " fmt "\n", name, ##args); }
1234
1235#define airo_print_info(name, fmt, args...) \
1236 airo_print(KERN_INFO, name, fmt, ##args)
1237
1238#define airo_print_dbg(name, fmt, args...) \
1239 airo_print(KERN_DEBUG, name, fmt, ##args)
1240
1241#define airo_print_warn(name, fmt, args...) \
1242 airo_print(KERN_WARNING, name, fmt, ##args)
1243
1244#define airo_print_err(name, fmt, args...) \
1245 airo_print(KERN_ERR, name, fmt, ##args)
1246
1247
1219/*********************************************************************** 1248/***********************************************************************
1220 * MIC ROUTINES * 1249 * MIC ROUTINES *
1221 *********************************************************************** 1250 ***********************************************************************
@@ -1294,7 +1323,7 @@ static int micsetup(struct airo_info *ai) {
1294 ai->tfm = crypto_alloc_tfm("aes", CRYPTO_TFM_REQ_MAY_SLEEP); 1323 ai->tfm = crypto_alloc_tfm("aes", CRYPTO_TFM_REQ_MAY_SLEEP);
1295 1324
1296 if (ai->tfm == NULL) { 1325 if (ai->tfm == NULL) {
1297 printk(KERN_ERR "airo: failed to load transform for AES\n"); 1326 airo_print_err(ai->dev->name, "failed to load transform for AES");
1298 return ERROR; 1327 return ERROR;
1299 } 1328 }
1300 1329
@@ -1726,11 +1755,11 @@ static int writeWepKeyRid(struct airo_info*ai, WepKeyRid *pwkr, int perm, int lo
1726 wkr.kindex = cpu_to_le16(wkr.kindex); 1755 wkr.kindex = cpu_to_le16(wkr.kindex);
1727 wkr.klen = cpu_to_le16(wkr.klen); 1756 wkr.klen = cpu_to_le16(wkr.klen);
1728 rc = PC4500_writerid(ai, RID_WEP_TEMP, &wkr, sizeof(wkr), lock); 1757 rc = PC4500_writerid(ai, RID_WEP_TEMP, &wkr, sizeof(wkr), lock);
1729 if (rc!=SUCCESS) printk(KERN_ERR "airo: WEP_TEMP set %x\n", rc); 1758 if (rc!=SUCCESS) airo_print_err(ai->dev->name, "WEP_TEMP set %x", rc);
1730 if (perm) { 1759 if (perm) {
1731 rc = PC4500_writerid(ai, RID_WEP_PERM, &wkr, sizeof(wkr), lock); 1760 rc = PC4500_writerid(ai, RID_WEP_PERM, &wkr, sizeof(wkr), lock);
1732 if (rc!=SUCCESS) { 1761 if (rc!=SUCCESS) {
1733 printk(KERN_ERR "airo: WEP_PERM set %x\n", rc); 1762 airo_print_err(ai->dev->name, "WEP_PERM set %x", rc);
1734 } 1763 }
1735 } 1764 }
1736 return rc; 1765 return rc;
@@ -1909,7 +1938,7 @@ static int mpi_start_xmit(struct sk_buff *skb, struct net_device *dev) {
1909 struct airo_info *ai = dev->priv; 1938 struct airo_info *ai = dev->priv;
1910 1939
1911 if (!skb) { 1940 if (!skb) {
1912 printk(KERN_ERR "airo: %s: skb==NULL\n",__FUNCTION__); 1941 airo_print_err(dev->name, "%s: skb == NULL!",__FUNCTION__);
1913 return 0; 1942 return 0;
1914 } 1943 }
1915 npacks = skb_queue_len (&ai->txq); 1944 npacks = skb_queue_len (&ai->txq);
@@ -1955,8 +1984,8 @@ static int mpi_send_packet (struct net_device *dev)
1955 /* get a packet to send */ 1984 /* get a packet to send */
1956 1985
1957 if ((skb = skb_dequeue(&ai->txq)) == 0) { 1986 if ((skb = skb_dequeue(&ai->txq)) == 0) {
1958 printk (KERN_ERR 1987 airo_print_err(dev->name,
1959 "airo: %s: Dequeue'd zero in send_packet()\n", 1988 "%s: Dequeue'd zero in send_packet()",
1960 __FUNCTION__); 1989 __FUNCTION__);
1961 return 0; 1990 return 0;
1962 } 1991 }
@@ -2108,7 +2137,7 @@ static int airo_start_xmit(struct sk_buff *skb, struct net_device *dev) {
2108 u32 *fids = priv->fids; 2137 u32 *fids = priv->fids;
2109 2138
2110 if ( skb == NULL ) { 2139 if ( skb == NULL ) {
2111 printk( KERN_ERR "airo: skb == NULL!!!\n" ); 2140 airo_print_err(dev->name, "%s: skb == NULL!", __FUNCTION__);
2112 return 0; 2141 return 0;
2113 } 2142 }
2114 2143
@@ -2179,7 +2208,7 @@ static int airo_start_xmit11(struct sk_buff *skb, struct net_device *dev) {
2179 } 2208 }
2180 2209
2181 if ( skb == NULL ) { 2210 if ( skb == NULL ) {
2182 printk( KERN_ERR "airo: skb == NULL!!!\n" ); 2211 airo_print_err(dev->name, "%s: skb == NULL!", __FUNCTION__);
2183 return 0; 2212 return 0;
2184 } 2213 }
2185 2214
@@ -2364,6 +2393,8 @@ void stop_airo_card( struct net_device *dev, int freeres )
2364 dev_kfree_skb(skb); 2393 dev_kfree_skb(skb);
2365 } 2394 }
2366 2395
2396 airo_networks_free (ai);
2397
2367 kfree(ai->flash); 2398 kfree(ai->flash);
2368 kfree(ai->rssi); 2399 kfree(ai->rssi);
2369 kfree(ai->APList); 2400 kfree(ai->APList);
@@ -2434,7 +2465,7 @@ static int mpi_init_descriptors (struct airo_info *ai)
2434 cmd.parm2 = MPI_MAX_FIDS; 2465 cmd.parm2 = MPI_MAX_FIDS;
2435 rc=issuecommand(ai, &cmd, &rsp); 2466 rc=issuecommand(ai, &cmd, &rsp);
2436 if (rc != SUCCESS) { 2467 if (rc != SUCCESS) {
2437 printk(KERN_ERR "airo: Couldn't allocate RX FID\n"); 2468 airo_print_err(ai->dev->name, "Couldn't allocate RX FID");
2438 return rc; 2469 return rc;
2439 } 2470 }
2440 2471
@@ -2462,7 +2493,7 @@ static int mpi_init_descriptors (struct airo_info *ai)
2462 2493
2463 rc=issuecommand(ai, &cmd, &rsp); 2494 rc=issuecommand(ai, &cmd, &rsp);
2464 if (rc != SUCCESS) { 2495 if (rc != SUCCESS) {
2465 printk(KERN_ERR "airo: Couldn't allocate TX FID\n"); 2496 airo_print_err(ai->dev->name, "Couldn't allocate TX FID");
2466 return rc; 2497 return rc;
2467 } 2498 }
2468 2499
@@ -2476,7 +2507,7 @@ static int mpi_init_descriptors (struct airo_info *ai)
2476 cmd.parm2 = 1; /* Magic number... */ 2507 cmd.parm2 = 1; /* Magic number... */
2477 rc=issuecommand(ai, &cmd, &rsp); 2508 rc=issuecommand(ai, &cmd, &rsp);
2478 if (rc != SUCCESS) { 2509 if (rc != SUCCESS) {
2479 printk(KERN_ERR "airo: Couldn't allocate RID\n"); 2510 airo_print_err(ai->dev->name, "Couldn't allocate RID");
2480 return rc; 2511 return rc;
2481 } 2512 }
2482 2513
@@ -2508,25 +2539,25 @@ static int mpi_map_card(struct airo_info *ai, struct pci_dev *pci,
2508 aux_len = AUXMEMSIZE; 2539 aux_len = AUXMEMSIZE;
2509 2540
2510 if (!request_mem_region(mem_start, mem_len, name)) { 2541 if (!request_mem_region(mem_start, mem_len, name)) {
2511 printk(KERN_ERR "airo: Couldn't get region %x[%x] for %s\n", 2542 airo_print_err(ai->dev->name, "Couldn't get region %x[%x] for %s",
2512 (int)mem_start, (int)mem_len, name); 2543 (int)mem_start, (int)mem_len, name);
2513 goto out; 2544 goto out;
2514 } 2545 }
2515 if (!request_mem_region(aux_start, aux_len, name)) { 2546 if (!request_mem_region(aux_start, aux_len, name)) {
2516 printk(KERN_ERR "airo: Couldn't get region %x[%x] for %s\n", 2547 airo_print_err(ai->dev->name, "Couldn't get region %x[%x] for %s",
2517 (int)aux_start, (int)aux_len, name); 2548 (int)aux_start, (int)aux_len, name);
2518 goto free_region1; 2549 goto free_region1;
2519 } 2550 }
2520 2551
2521 ai->pcimem = ioremap(mem_start, mem_len); 2552 ai->pcimem = ioremap(mem_start, mem_len);
2522 if (!ai->pcimem) { 2553 if (!ai->pcimem) {
2523 printk(KERN_ERR "airo: Couldn't map region %x[%x] for %s\n", 2554 airo_print_err(ai->dev->name, "Couldn't map region %x[%x] for %s",
2524 (int)mem_start, (int)mem_len, name); 2555 (int)mem_start, (int)mem_len, name);
2525 goto free_region2; 2556 goto free_region2;
2526 } 2557 }
2527 ai->pciaux = ioremap(aux_start, aux_len); 2558 ai->pciaux = ioremap(aux_start, aux_len);
2528 if (!ai->pciaux) { 2559 if (!ai->pciaux) {
2529 printk(KERN_ERR "airo: Couldn't map region %x[%x] for %s\n", 2560 airo_print_err(ai->dev->name, "Couldn't map region %x[%x] for %s",
2530 (int)aux_start, (int)aux_len, name); 2561 (int)aux_start, (int)aux_len, name);
2531 goto free_memmap; 2562 goto free_memmap;
2532 } 2563 }
@@ -2534,7 +2565,7 @@ static int mpi_map_card(struct airo_info *ai, struct pci_dev *pci,
2534 /* Reserve PKTSIZE for each fid and 2K for the Rids */ 2565 /* Reserve PKTSIZE for each fid and 2K for the Rids */
2535 ai->shared = pci_alloc_consistent(pci, PCI_SHARED_LEN, &ai->shared_dma); 2566 ai->shared = pci_alloc_consistent(pci, PCI_SHARED_LEN, &ai->shared_dma);
2536 if (!ai->shared) { 2567 if (!ai->shared) {
2537 printk(KERN_ERR "airo: Couldn't alloc_consistent %d\n", 2568 airo_print_err(ai->dev->name, "Couldn't alloc_consistent %d",
2538 PCI_SHARED_LEN); 2569 PCI_SHARED_LEN);
2539 goto free_auxmap; 2570 goto free_auxmap;
2540 } 2571 }
@@ -2626,7 +2657,7 @@ static void wifi_setup(struct net_device *dev)
2626 2657
2627 dev->type = ARPHRD_IEEE80211; 2658 dev->type = ARPHRD_IEEE80211;
2628 dev->hard_header_len = ETH_HLEN; 2659 dev->hard_header_len = ETH_HLEN;
2629 dev->mtu = 2312; 2660 dev->mtu = AIRO_DEF_MTU;
2630 dev->addr_len = ETH_ALEN; 2661 dev->addr_len = ETH_ALEN;
2631 dev->tx_queue_len = 100; 2662 dev->tx_queue_len = 100;
2632 2663
@@ -2670,6 +2701,42 @@ static int reset_card( struct net_device *dev , int lock) {
2670 return 0; 2701 return 0;
2671} 2702}
2672 2703
2704#define MAX_NETWORK_COUNT 64
2705static int airo_networks_allocate(struct airo_info *ai)
2706{
2707 if (ai->networks)
2708 return 0;
2709
2710 ai->networks =
2711 kzalloc(MAX_NETWORK_COUNT * sizeof(BSSListElement),
2712 GFP_KERNEL);
2713 if (!ai->networks) {
2714 airo_print_warn(ai->dev->name, "Out of memory allocating beacons");
2715 return -ENOMEM;
2716 }
2717
2718 return 0;
2719}
2720
2721static void airo_networks_free(struct airo_info *ai)
2722{
2723 if (!ai->networks)
2724 return;
2725 kfree(ai->networks);
2726 ai->networks = NULL;
2727}
2728
2729static void airo_networks_initialize(struct airo_info *ai)
2730{
2731 int i;
2732
2733 INIT_LIST_HEAD(&ai->network_free_list);
2734 INIT_LIST_HEAD(&ai->network_list);
2735 for (i = 0; i < MAX_NETWORK_COUNT; i++)
2736 list_add_tail(&ai->networks[i].list,
2737 &ai->network_free_list);
2738}
2739
2673static struct net_device *_init_airo_card( unsigned short irq, int port, 2740static struct net_device *_init_airo_card( unsigned short irq, int port,
2674 int is_pcmcia, struct pci_dev *pci, 2741 int is_pcmcia, struct pci_dev *pci,
2675 struct device *dmdev ) 2742 struct device *dmdev )
@@ -2681,22 +2748,22 @@ static struct net_device *_init_airo_card( unsigned short irq, int port,
2681 /* Create the network device object. */ 2748 /* Create the network device object. */
2682 dev = alloc_etherdev(sizeof(*ai)); 2749 dev = alloc_etherdev(sizeof(*ai));
2683 if (!dev) { 2750 if (!dev) {
2684 printk(KERN_ERR "airo: Couldn't alloc_etherdev\n"); 2751 airo_print_err("", "Couldn't alloc_etherdev");
2685 return NULL; 2752 return NULL;
2686 } 2753 }
2687 if (dev_alloc_name(dev, dev->name) < 0) { 2754 if (dev_alloc_name(dev, dev->name) < 0) {
2688 printk(KERN_ERR "airo: Couldn't get name!\n"); 2755 airo_print_err("", "Couldn't get name!");
2689 goto err_out_free; 2756 goto err_out_free;
2690 } 2757 }
2691 2758
2692 ai = dev->priv; 2759 ai = dev->priv;
2693 ai->wifidev = NULL; 2760 ai->wifidev = NULL;
2694 ai->flags = 0; 2761 ai->flags = 0;
2762 ai->dev = dev;
2695 if (pci && (pci->device == 0x5000 || pci->device == 0xa504)) { 2763 if (pci && (pci->device == 0x5000 || pci->device == 0xa504)) {
2696 printk(KERN_DEBUG "airo: Found an MPI350 card\n"); 2764 airo_print_dbg(dev->name, "Found an MPI350 card");
2697 set_bit(FLAG_MPI, &ai->flags); 2765 set_bit(FLAG_MPI, &ai->flags);
2698 } 2766 }
2699 ai->dev = dev;
2700 spin_lock_init(&ai->aux_lock); 2767 spin_lock_init(&ai->aux_lock);
2701 sema_init(&ai->sem, 1); 2768 sema_init(&ai->sem, 1);
2702 ai->config.len = 0; 2769 ai->config.len = 0;
@@ -2711,6 +2778,10 @@ static struct net_device *_init_airo_card( unsigned short irq, int port,
2711 if (rc) 2778 if (rc)
2712 goto err_out_thr; 2779 goto err_out_thr;
2713 2780
2781 if (airo_networks_allocate (ai))
2782 goto err_out_unlink;
2783 airo_networks_initialize (ai);
2784
2714 /* The Airo-specific entries in the device structure. */ 2785 /* The Airo-specific entries in the device structure. */
2715 if (test_bit(FLAG_MPI,&ai->flags)) { 2786 if (test_bit(FLAG_MPI,&ai->flags)) {
2716 skb_queue_head_init (&ai->txq); 2787 skb_queue_head_init (&ai->txq);
@@ -2732,33 +2803,33 @@ static struct net_device *_init_airo_card( unsigned short irq, int port,
2732 2803
2733 SET_NETDEV_DEV(dev, dmdev); 2804 SET_NETDEV_DEV(dev, dmdev);
2734 2805
2735
2736 reset_card (dev, 1); 2806 reset_card (dev, 1);
2737 msleep(400); 2807 msleep(400);
2738 2808
2739 rc = request_irq( dev->irq, airo_interrupt, SA_SHIRQ, dev->name, dev ); 2809 rc = request_irq( dev->irq, airo_interrupt, SA_SHIRQ, dev->name, dev );
2740 if (rc) { 2810 if (rc) {
2741 printk(KERN_ERR "airo: register interrupt %d failed, rc %d\n", irq, rc ); 2811 airo_print_err(dev->name, "register interrupt %d failed, rc %d",
2812 irq, rc);
2742 goto err_out_unlink; 2813 goto err_out_unlink;
2743 } 2814 }
2744 if (!is_pcmcia) { 2815 if (!is_pcmcia) {
2745 if (!request_region( dev->base_addr, 64, dev->name )) { 2816 if (!request_region( dev->base_addr, 64, dev->name )) {
2746 rc = -EBUSY; 2817 rc = -EBUSY;
2747 printk(KERN_ERR "airo: Couldn't request region\n"); 2818 airo_print_err(dev->name, "Couldn't request region");
2748 goto err_out_irq; 2819 goto err_out_irq;
2749 } 2820 }
2750 } 2821 }
2751 2822
2752 if (test_bit(FLAG_MPI,&ai->flags)) { 2823 if (test_bit(FLAG_MPI,&ai->flags)) {
2753 if (mpi_map_card(ai, pci, dev->name)) { 2824 if (mpi_map_card(ai, pci, dev->name)) {
2754 printk(KERN_ERR "airo: Could not map memory\n"); 2825 airo_print_err(dev->name, "Could not map memory");
2755 goto err_out_res; 2826 goto err_out_res;
2756 } 2827 }
2757 } 2828 }
2758 2829
2759 if (probe) { 2830 if (probe) {
2760 if ( setup_card( ai, dev->dev_addr, 1 ) != SUCCESS ) { 2831 if ( setup_card( ai, dev->dev_addr, 1 ) != SUCCESS ) {
2761 printk( KERN_ERR "airo: MAC could not be enabled\n" ); 2832 airo_print_err(dev->name, "MAC could not be enabled" );
2762 rc = -EIO; 2833 rc = -EIO;
2763 goto err_out_map; 2834 goto err_out_map;
2764 } 2835 }
@@ -2769,21 +2840,20 @@ static struct net_device *_init_airo_card( unsigned short irq, int port,
2769 2840
2770 rc = register_netdev(dev); 2841 rc = register_netdev(dev);
2771 if (rc) { 2842 if (rc) {
2772 printk(KERN_ERR "airo: Couldn't register_netdev\n"); 2843 airo_print_err(dev->name, "Couldn't register_netdev");
2773 goto err_out_map; 2844 goto err_out_map;
2774 } 2845 }
2775 ai->wifidev = init_wifidev(ai, dev); 2846 ai->wifidev = init_wifidev(ai, dev);
2776 2847
2777 set_bit(FLAG_REGISTERED,&ai->flags); 2848 set_bit(FLAG_REGISTERED,&ai->flags);
2778 printk( KERN_INFO "airo: MAC enabled %s %x:%x:%x:%x:%x:%x\n", 2849 airo_print_info(dev->name, "MAC enabled %x:%x:%x:%x:%x:%x",
2779 dev->name,
2780 dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2], 2850 dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
2781 dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5] ); 2851 dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5] );
2782 2852
2783 /* Allocate the transmit buffers */ 2853 /* Allocate the transmit buffers */
2784 if (probe && !test_bit(FLAG_MPI,&ai->flags)) 2854 if (probe && !test_bit(FLAG_MPI,&ai->flags))
2785 for( i = 0; i < MAX_FIDS; i++ ) 2855 for( i = 0; i < MAX_FIDS; i++ )
2786 ai->fids[i] = transmit_allocate(ai,2312,i>=MAX_FIDS/2); 2856 ai->fids[i] = transmit_allocate(ai,AIRO_DEF_MTU,i>=MAX_FIDS/2);
2787 2857
2788 setup_proc_entry( dev, dev->priv ); /* XXX check for failure */ 2858 setup_proc_entry( dev, dev->priv ); /* XXX check for failure */
2789 netif_start_queue(dev); 2859 netif_start_queue(dev);
@@ -2840,16 +2910,16 @@ int reset_airo_card( struct net_device *dev )
2840 return -1; 2910 return -1;
2841 2911
2842 if ( setup_card(ai, dev->dev_addr, 1 ) != SUCCESS ) { 2912 if ( setup_card(ai, dev->dev_addr, 1 ) != SUCCESS ) {
2843 printk( KERN_ERR "airo: MAC could not be enabled\n" ); 2913 airo_print_err(dev->name, "MAC could not be enabled");
2844 return -1; 2914 return -1;
2845 } 2915 }
2846 printk( KERN_INFO "airo: MAC enabled %s %x:%x:%x:%x:%x:%x\n", dev->name, 2916 airo_print_info(dev->name, "MAC enabled %x:%x:%x:%x:%x:%x",
2847 dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2], 2917 dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
2848 dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]); 2918 dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
2849 /* Allocate the transmit buffers if needed */ 2919 /* Allocate the transmit buffers if needed */
2850 if (!test_bit(FLAG_MPI,&ai->flags)) 2920 if (!test_bit(FLAG_MPI,&ai->flags))
2851 for( i = 0; i < MAX_FIDS; i++ ) 2921 for( i = 0; i < MAX_FIDS; i++ )
2852 ai->fids[i] = transmit_allocate (ai,2312,i>=MAX_FIDS/2); 2922 ai->fids[i] = transmit_allocate (ai,AIRO_DEF_MTU,i>=MAX_FIDS/2);
2853 2923
2854 enable_interrupts( ai ); 2924 enable_interrupts( ai );
2855 netif_wake_queue(dev); 2925 netif_wake_queue(dev);
@@ -2875,6 +2945,65 @@ static void airo_send_event(struct net_device *dev) {
2875 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL); 2945 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
2876} 2946}
2877 2947
2948static void airo_process_scan_results (struct airo_info *ai) {
2949 union iwreq_data wrqu;
2950 BSSListRid BSSList;
2951 int rc;
2952 BSSListElement * loop_net;
2953 BSSListElement * tmp_net;
2954
2955 /* Blow away current list of scan results */
2956 list_for_each_entry_safe (loop_net, tmp_net, &ai->network_list, list) {
2957 list_move_tail (&loop_net->list, &ai->network_free_list);
2958 /* Don't blow away ->list, just BSS data */
2959 memset (loop_net, 0, sizeof (loop_net->bss));
2960 }
2961
2962 /* Try to read the first entry of the scan result */
2963 rc = PC4500_readrid(ai, RID_BSSLISTFIRST, &BSSList, sizeof(BSSList), 0);
2964 if((rc) || (BSSList.index == 0xffff)) {
2965 /* No scan results */
2966 goto out;
2967 }
2968
2969 /* Read and parse all entries */
2970 tmp_net = NULL;
2971 while((!rc) && (BSSList.index != 0xffff)) {
2972 /* Grab a network off the free list */
2973 if (!list_empty(&ai->network_free_list)) {
2974 tmp_net = list_entry(ai->network_free_list.next,
2975 BSSListElement, list);
2976 list_del(ai->network_free_list.next);
2977 }
2978
2979 if (tmp_net != NULL) {
2980 memcpy(tmp_net, &BSSList, sizeof(tmp_net->bss));
2981 list_add_tail(&tmp_net->list, &ai->network_list);
2982 tmp_net = NULL;
2983 }
2984
2985 /* Read next entry */
2986 rc = PC4500_readrid(ai, RID_BSSLISTNEXT,
2987 &BSSList, sizeof(BSSList), 0);
2988 }
2989
2990out:
2991 ai->scan_timeout = 0;
2992 clear_bit(JOB_SCAN_RESULTS, &ai->flags);
2993 up(&ai->sem);
2994
2995 /* Send an empty event to user space.
2996 * We don't send the received data on
2997 * the event because it would require
2998 * us to do complex transcoding, and
2999 * we want to minimise the work done in
3000 * the irq handler. Use a request to
3001 * extract the data - Jean II */
3002 wrqu.data.length = 0;
3003 wrqu.data.flags = 0;
3004 wireless_send_event(ai->dev, SIOCGIWSCAN, &wrqu, NULL);
3005}
3006
2878static int airo_thread(void *data) { 3007static int airo_thread(void *data) {
2879 struct net_device *dev = data; 3008 struct net_device *dev = data;
2880 struct airo_info *ai = dev->priv; 3009 struct airo_info *ai = dev->priv;
@@ -2904,13 +3033,26 @@ static int airo_thread(void *data) {
2904 set_current_state(TASK_INTERRUPTIBLE); 3033 set_current_state(TASK_INTERRUPTIBLE);
2905 if (ai->flags & JOB_MASK) 3034 if (ai->flags & JOB_MASK)
2906 break; 3035 break;
2907 if (ai->expires) { 3036 if (ai->expires || ai->scan_timeout) {
2908 if (time_after_eq(jiffies,ai->expires)){ 3037 if (ai->scan_timeout &&
3038 time_after_eq(jiffies,ai->scan_timeout)){
3039 set_bit(JOB_SCAN_RESULTS,&ai->flags);
3040 break;
3041 } else if (ai->expires &&
3042 time_after_eq(jiffies,ai->expires)){
2909 set_bit(JOB_AUTOWEP,&ai->flags); 3043 set_bit(JOB_AUTOWEP,&ai->flags);
2910 break; 3044 break;
2911 } 3045 }
2912 if (!signal_pending(current)) { 3046 if (!signal_pending(current)) {
2913 schedule_timeout(ai->expires - jiffies); 3047 unsigned long wake_at;
3048 if (!ai->expires || !ai->scan_timeout) {
3049 wake_at = max(ai->expires,
3050 ai->scan_timeout);
3051 } else {
3052 wake_at = min(ai->expires,
3053 ai->scan_timeout);
3054 }
3055 schedule_timeout(wake_at - jiffies);
2914 continue; 3056 continue;
2915 } 3057 }
2916 } else if (!signal_pending(current)) { 3058 } else if (!signal_pending(current)) {
@@ -2953,6 +3095,10 @@ static int airo_thread(void *data) {
2953 airo_send_event(dev); 3095 airo_send_event(dev);
2954 else if (test_bit(JOB_AUTOWEP, &ai->flags)) 3096 else if (test_bit(JOB_AUTOWEP, &ai->flags))
2955 timer_func(dev); 3097 timer_func(dev);
3098 else if (test_bit(JOB_SCAN_RESULTS, &ai->flags))
3099 airo_process_scan_results(ai);
3100 else /* Shouldn't get here, but we make sure to unlock */
3101 up(&ai->sem);
2956 } 3102 }
2957 complete_and_exit (&ai->thr_exited, 0); 3103 complete_and_exit (&ai->thr_exited, 0);
2958} 3104}
@@ -3047,19 +3193,15 @@ static irqreturn_t airo_interrupt ( int irq, void* dev_id, struct pt_regs *regs)
3047 * and reassociations as valid status 3193 * and reassociations as valid status
3048 * Jean II */ 3194 * Jean II */
3049 if(newStatus == ASSOCIATED) { 3195 if(newStatus == ASSOCIATED) {
3050 if (apriv->scan_timestamp) { 3196#if 0
3051 /* Send an empty event to user space. 3197 /* FIXME: Grabbing scan results here
3052 * We don't send the received data on 3198 * seems to be too early??? Just wait for
3053 * the event because it would require 3199 * timeout instead. */
3054 * us to do complex transcoding, and 3200 if (apriv->scan_timeout > 0) {
3055 * we want to minimise the work done in 3201 set_bit(JOB_SCAN_RESULTS, &apriv->flags);
3056 * the irq handler. Use a request to 3202 wake_up_interruptible(&apriv->thr_wait);
3057 * extract the data - Jean II */
3058 wrqu.data.length = 0;
3059 wrqu.data.flags = 0;
3060 wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
3061 apriv->scan_timestamp = 0;
3062 } 3203 }
3204#endif
3063 if (down_trylock(&apriv->sem) != 0) { 3205 if (down_trylock(&apriv->sem) != 0) {
3064 set_bit(JOB_EVENT, &apriv->flags); 3206 set_bit(JOB_EVENT, &apriv->flags);
3065 wake_up_interruptible(&apriv->thr_wait); 3207 wake_up_interruptible(&apriv->thr_wait);
@@ -3117,8 +3259,8 @@ static irqreturn_t airo_interrupt ( int irq, void* dev_id, struct pt_regs *regs)
3117 } 3259 }
3118 len = le16_to_cpu(hdr.len); 3260 len = le16_to_cpu(hdr.len);
3119 3261
3120 if (len > 2312) { 3262 if (len > AIRO_DEF_MTU) {
3121 printk( KERN_ERR "airo: Bad size %d\n", len ); 3263 airo_print_err(apriv->dev->name, "Bad size %d", len);
3122 goto badrx; 3264 goto badrx;
3123 } 3265 }
3124 if (len == 0) 3266 if (len == 0)
@@ -3161,10 +3303,12 @@ static irqreturn_t airo_interrupt ( int irq, void* dev_id, struct pt_regs *regs)
3161 bap_read (apriv, &gap, sizeof(gap), BAP0); 3303 bap_read (apriv, &gap, sizeof(gap), BAP0);
3162 gap = le16_to_cpu(gap); 3304 gap = le16_to_cpu(gap);
3163 if (gap) { 3305 if (gap) {
3164 if (gap <= 8) 3306 if (gap <= 8) {
3165 bap_read (apriv, tmpbuf, gap, BAP0); 3307 bap_read (apriv, tmpbuf, gap, BAP0);
3166 else 3308 } else {
3167 printk(KERN_ERR "airo: gaplen too big. Problems will follow...\n"); 3309 airo_print_err(apriv->dev->name, "gaplen too "
3310 "big. Problems will follow...");
3311 }
3168 } 3312 }
3169 bap_read (apriv, buffer + hdrlen/2, len, BAP0); 3313 bap_read (apriv, buffer + hdrlen/2, len, BAP0);
3170 } else { 3314 } else {
@@ -3281,12 +3425,13 @@ exitrx:
3281 } 3425 }
3282 } else { 3426 } else {
3283 OUT4500( apriv, EVACK, status & (EV_TX | EV_TXCPY | EV_TXEXC)); 3427 OUT4500( apriv, EVACK, status & (EV_TX | EV_TXCPY | EV_TXEXC));
3284 printk( KERN_ERR "airo: Unallocated FID was used to xmit\n" ); 3428 airo_print_err(apriv->dev->name, "Unallocated FID was "
3429 "used to xmit" );
3285 } 3430 }
3286 } 3431 }
3287exittx: 3432exittx:
3288 if ( status & ~STATUS_INTS & ~IGNORE_INTS ) 3433 if ( status & ~STATUS_INTS & ~IGNORE_INTS )
3289 printk( KERN_WARNING "airo: Got weird status %x\n", 3434 airo_print_warn(apriv->dev->name, "Got weird status %x",
3290 status & ~STATUS_INTS & ~IGNORE_INTS ); 3435 status & ~STATUS_INTS & ~IGNORE_INTS );
3291 } 3436 }
3292 3437
@@ -3359,8 +3504,8 @@ static int enable_MAC( struct airo_info *ai, Resp *rsp, int lock ) {
3359 up(&ai->sem); 3504 up(&ai->sem);
3360 3505
3361 if (rc) 3506 if (rc)
3362 printk(KERN_ERR "%s: Cannot enable MAC, err=%d\n", 3507 airo_print_err(ai->dev->name, "%s: Cannot enable MAC, err=%d",
3363 __FUNCTION__,rc); 3508 __FUNCTION__, rc);
3364 return rc; 3509 return rc;
3365} 3510}
3366 3511
@@ -3489,8 +3634,8 @@ void mpi_receive_802_11 (struct airo_info *ai)
3489 if (ai->wifidev == NULL) 3634 if (ai->wifidev == NULL)
3490 hdr.len = 0; 3635 hdr.len = 0;
3491 len = le16_to_cpu(hdr.len); 3636 len = le16_to_cpu(hdr.len);
3492 if (len > 2312) { 3637 if (len > AIRO_DEF_MTU) {
3493 printk( KERN_ERR "airo: Bad size %d\n", len ); 3638 airo_print_err(ai->dev->name, "Bad size %d", len);
3494 goto badrx; 3639 goto badrx;
3495 } 3640 }
3496 if (len == 0) 3641 if (len == 0)
@@ -3531,8 +3676,8 @@ void mpi_receive_802_11 (struct airo_info *ai)
3531 if (gap <= 8) 3676 if (gap <= 8)
3532 ptr += gap; 3677 ptr += gap;
3533 else 3678 else
3534 printk(KERN_ERR 3679 airo_print_err(ai->dev->name,
3535 "airo: gaplen too big. Problems will follow...\n"); 3680 "gaplen too big. Problems will follow...");
3536 } 3681 }
3537 memcpy ((char *)buffer + hdrlen, ptr, len); 3682 memcpy ((char *)buffer + hdrlen, ptr, len);
3538 ptr += len; 3683 ptr += len;
@@ -3604,15 +3749,15 @@ static u16 setup_card(struct airo_info *ai, u8 *mac, int lock)
3604 if (issuecommand(ai, &cmd, &rsp) != SUCCESS) { 3749 if (issuecommand(ai, &cmd, &rsp) != SUCCESS) {
3605 if (lock) 3750 if (lock)
3606 up(&ai->sem); 3751 up(&ai->sem);
3607 printk(KERN_ERR "airo: Error checking for AUX port\n"); 3752 airo_print_err(ai->dev->name, "Error checking for AUX port");
3608 return ERROR; 3753 return ERROR;
3609 } 3754 }
3610 if (!aux_bap || rsp.status & 0xff00) { 3755 if (!aux_bap || rsp.status & 0xff00) {
3611 ai->bap_read = fast_bap_read; 3756 ai->bap_read = fast_bap_read;
3612 printk(KERN_DEBUG "airo: Doing fast bap_reads\n"); 3757 airo_print_dbg(ai->dev->name, "Doing fast bap_reads");
3613 } else { 3758 } else {
3614 ai->bap_read = aux_bap_read; 3759 ai->bap_read = aux_bap_read;
3615 printk(KERN_DEBUG "airo: Doing AUX bap_reads\n"); 3760 airo_print_dbg(ai->dev->name, "Doing AUX bap_reads");
3616 } 3761 }
3617 } 3762 }
3618 if (lock) 3763 if (lock)
@@ -3643,7 +3788,8 @@ static u16 setup_card(struct airo_info *ai, u8 *mac, int lock)
3643 if (cap_rid.softCap & 8) 3788 if (cap_rid.softCap & 8)
3644 ai->config.rmode |= RXMODE_NORMALIZED_RSSI; 3789 ai->config.rmode |= RXMODE_NORMALIZED_RSSI;
3645 else 3790 else
3646 printk(KERN_WARNING "airo: unknown received signal level scale\n"); 3791 airo_print_warn(ai->dev->name, "unknown received signal "
3792 "level scale");
3647 } 3793 }
3648 ai->config.opmode = adhoc ? MODE_STA_IBSS : MODE_STA_ESS; 3794 ai->config.opmode = adhoc ? MODE_STA_IBSS : MODE_STA_ESS;
3649 ai->config.authType = AUTH_OPEN; 3795 ai->config.authType = AUTH_OPEN;
@@ -3706,7 +3852,8 @@ static u16 setup_card(struct airo_info *ai, u8 *mac, int lock)
3706 3852
3707 status = enable_MAC(ai, &rsp, lock); 3853 status = enable_MAC(ai, &rsp, lock);
3708 if ( status != SUCCESS || (rsp.status & 0xFF00) != 0) { 3854 if ( status != SUCCESS || (rsp.status & 0xFF00) != 0) {
3709 printk( KERN_ERR "airo: Bad MAC enable reason = %x, rid = %x, offset = %d\n", rsp.rsp0, rsp.rsp1, rsp.rsp2 ); 3855 airo_print_err(ai->dev->name, "Bad MAC enable reason = %x, rid = %x,"
3856 " offset = %d", rsp.rsp0, rsp.rsp1, rsp.rsp2 );
3710 return ERROR; 3857 return ERROR;
3711 } 3858 }
3712 3859
@@ -3749,8 +3896,8 @@ static u16 issuecommand(struct airo_info *ai, Cmd *pCmd, Resp *pRsp) {
3749 } 3896 }
3750 3897
3751 if ( max_tries == -1 ) { 3898 if ( max_tries == -1 ) {
3752 printk( KERN_ERR 3899 airo_print_err(ai->dev->name,
3753 "airo: Max tries exceeded when issueing command\n" ); 3900 "Max tries exceeded when issueing command");
3754 if (IN4500(ai, COMMAND) & COMMAND_BUSY) 3901 if (IN4500(ai, COMMAND) & COMMAND_BUSY)
3755 OUT4500(ai, EVACK, EV_CLEARCOMMANDBUSY); 3902 OUT4500(ai, EVACK, EV_CLEARCOMMANDBUSY);
3756 return ERROR; 3903 return ERROR;
@@ -3762,11 +3909,11 @@ static u16 issuecommand(struct airo_info *ai, Cmd *pCmd, Resp *pRsp) {
3762 pRsp->rsp1 = IN4500(ai, RESP1); 3909 pRsp->rsp1 = IN4500(ai, RESP1);
3763 pRsp->rsp2 = IN4500(ai, RESP2); 3910 pRsp->rsp2 = IN4500(ai, RESP2);
3764 if ((pRsp->status & 0xff00)!=0 && pCmd->cmd != CMD_SOFTRESET) { 3911 if ((pRsp->status & 0xff00)!=0 && pCmd->cmd != CMD_SOFTRESET) {
3765 printk (KERN_ERR "airo: cmd= %x\n", pCmd->cmd); 3912 airo_print_err(ai->dev->name, "cmd= %x\n", pCmd->cmd);
3766 printk (KERN_ERR "airo: status= %x\n", pRsp->status); 3913 airo_print_err(ai->dev->name, "status= %x\n", pRsp->status);
3767 printk (KERN_ERR "airo: Rsp0= %x\n", pRsp->rsp0); 3914 airo_print_err(ai->dev->name, "Rsp0= %x\n", pRsp->rsp0);
3768 printk (KERN_ERR "airo: Rsp1= %x\n", pRsp->rsp1); 3915 airo_print_err(ai->dev->name, "Rsp1= %x\n", pRsp->rsp1);
3769 printk (KERN_ERR "airo: Rsp2= %x\n", pRsp->rsp2); 3916 airo_print_err(ai->dev->name, "Rsp2= %x\n", pRsp->rsp2);
3770 } 3917 }
3771 3918
3772 // clear stuck command busy if necessary 3919 // clear stuck command busy if necessary
@@ -3799,15 +3946,15 @@ static int bap_setup(struct airo_info *ai, u16 rid, u16 offset, int whichbap )
3799 } 3946 }
3800 } else if ( status & BAP_ERR ) { 3947 } else if ( status & BAP_ERR ) {
3801 /* invalid rid or offset */ 3948 /* invalid rid or offset */
3802 printk( KERN_ERR "airo: BAP error %x %d\n", 3949 airo_print_err(ai->dev->name, "BAP error %x %d",
3803 status, whichbap ); 3950 status, whichbap );
3804 return ERROR; 3951 return ERROR;
3805 } else if (status & BAP_DONE) { // success 3952 } else if (status & BAP_DONE) { // success
3806 return SUCCESS; 3953 return SUCCESS;
3807 } 3954 }
3808 if ( !(max_tries--) ) { 3955 if ( !(max_tries--) ) {
3809 printk( KERN_ERR 3956 airo_print_err(ai->dev->name,
3810 "airo: BAP setup error too many retries\n" ); 3957 "airo: BAP setup error too many retries\n");
3811 return ERROR; 3958 return ERROR;
3812 } 3959 }
3813 // -- PC4500 missed it, try again 3960 // -- PC4500 missed it, try again
@@ -3962,8 +4109,8 @@ static int PC4500_readrid(struct airo_info *ai, u16 rid, void *pBuf, int len, in
3962 len = min(len, (int)le16_to_cpu(*(u16*)pBuf)) - 2; 4109 len = min(len, (int)le16_to_cpu(*(u16*)pBuf)) - 2;
3963 4110
3964 if ( len <= 2 ) { 4111 if ( len <= 2 ) {
3965 printk( KERN_ERR 4112 airo_print_err(ai->dev->name,
3966 "airo: Rid %x has a length of %d which is too short\n", 4113 "Rid %x has a length of %d which is too short",
3967 (int)rid, (int)len ); 4114 (int)rid, (int)len );
3968 rc = ERROR; 4115 rc = ERROR;
3969 goto done; 4116 goto done;
@@ -3996,8 +4143,8 @@ static int PC4500_writerid(struct airo_info *ai, u16 rid,
3996 Resp rsp; 4143 Resp rsp;
3997 4144
3998 if (test_bit(FLAG_ENABLED, &ai->flags) && (RID_WEP_TEMP != rid)) 4145 if (test_bit(FLAG_ENABLED, &ai->flags) && (RID_WEP_TEMP != rid))
3999 printk(KERN_ERR 4146 airo_print_err(ai->dev->name,
4000 "%s: MAC should be disabled (rid=%04x)\n", 4147 "%s: MAC should be disabled (rid=%04x)",
4001 __FUNCTION__, rid); 4148 __FUNCTION__, rid);
4002 memset(&cmd, 0, sizeof(cmd)); 4149 memset(&cmd, 0, sizeof(cmd));
4003 memset(&rsp, 0, sizeof(rsp)); 4150 memset(&rsp, 0, sizeof(rsp));
@@ -4013,7 +4160,7 @@ static int PC4500_writerid(struct airo_info *ai, u16 rid,
4013 &ai->config_desc.rid_desc, sizeof(Rid)); 4160 &ai->config_desc.rid_desc, sizeof(Rid));
4014 4161
4015 if (len < 4 || len > 2047) { 4162 if (len < 4 || len > 2047) {
4016 printk(KERN_ERR "%s: len=%d\n",__FUNCTION__,len); 4163 airo_print_err(ai->dev->name, "%s: len=%d", __FUNCTION__, len);
4017 rc = -1; 4164 rc = -1;
4018 } else { 4165 } else {
4019 memcpy((char *)ai->config_desc.virtual_host_addr, 4166 memcpy((char *)ai->config_desc.virtual_host_addr,
@@ -4021,10 +4168,10 @@ static int PC4500_writerid(struct airo_info *ai, u16 rid,
4021 4168
4022 rc = issuecommand(ai, &cmd, &rsp); 4169 rc = issuecommand(ai, &cmd, &rsp);
4023 if ((rc & 0xff00) != 0) { 4170 if ((rc & 0xff00) != 0) {
4024 printk(KERN_ERR "%s: Write rid Error %d\n", 4171 airo_print_err(ai->dev->name, "%s: Write rid Error %d",
4025 __FUNCTION__,rc); 4172 __FUNCTION__, rc);
4026 printk(KERN_ERR "%s: Cmd=%04x\n", 4173 airo_print_err(ai->dev->name, "%s: Cmd=%04x",
4027 __FUNCTION__,cmd.cmd); 4174 __FUNCTION__, cmd.cmd);
4028 } 4175 }
4029 4176
4030 if ((rsp.status & 0x7f00)) 4177 if ((rsp.status & 0x7f00))
@@ -4123,7 +4270,7 @@ static int transmit_802_3_packet(struct airo_info *ai, int len, char *pPacket)
4123 len >>= 16; 4270 len >>= 16;
4124 4271
4125 if (len <= ETH_ALEN * 2) { 4272 if (len <= ETH_ALEN * 2) {
4126 printk( KERN_WARNING "Short packet %d\n", len ); 4273 airo_print_warn(ai->dev->name, "Short packet %d", len);
4127 return ERROR; 4274 return ERROR;
4128 } 4275 }
4129 len -= ETH_ALEN * 2; 4276 len -= ETH_ALEN * 2;
@@ -4187,7 +4334,7 @@ static int transmit_802_11_packet(struct airo_info *ai, int len, char *pPacket)
4187 } 4334 }
4188 4335
4189 if (len < hdrlen) { 4336 if (len < hdrlen) {
4190 printk( KERN_WARNING "Short packet %d\n", len ); 4337 airo_print_warn(ai->dev->name, "Short packet %d", len);
4191 return ERROR; 4338 return ERROR;
4192 } 4339 }
4193 4340
@@ -4584,15 +4731,14 @@ static int proc_stats_rid_open( struct inode *inode,
4584 i*4<stats.len; i++){ 4731 i*4<stats.len; i++){
4585 if (!statsLabels[i]) continue; 4732 if (!statsLabels[i]) continue;
4586 if (j+strlen(statsLabels[i])+16>4096) { 4733 if (j+strlen(statsLabels[i])+16>4096) {
4587 printk(KERN_WARNING 4734 airo_print_warn(apriv->dev->name,
4588 "airo: Potentially disasterous buffer overflow averted!\n"); 4735 "Potentially disasterous buffer overflow averted!");
4589 break; 4736 break;
4590 } 4737 }
4591 j+=sprintf(data->rbuffer+j, "%s: %u\n", statsLabels[i], vals[i]); 4738 j+=sprintf(data->rbuffer+j, "%s: %u\n", statsLabels[i], vals[i]);
4592 } 4739 }
4593 if (i*4>=stats.len){ 4740 if (i*4>=stats.len){
4594 printk(KERN_WARNING 4741 airo_print_warn(apriv->dev->name, "Got a short rid");
4595 "airo: Got a short rid\n");
4596 } 4742 }
4597 data->readlen = j; 4743 data->readlen = j;
4598 return 0; 4744 return 0;
@@ -4754,7 +4900,7 @@ static void proc_config_on_close( struct inode *inode, struct file *file ) {
4754 4900
4755 line += 14; 4901 line += 14;
4756 v = get_dec_u16(line, &i, 4); 4902 v = get_dec_u16(line, &i, 4);
4757 v = (v<0) ? 0 : ((v>2312) ? 2312 : v); 4903 v = (v<0) ? 0 : ((v>AIRO_DEF_MTU) ? AIRO_DEF_MTU : v);
4758 ai->config.rtsThres = (u16)v; 4904 ai->config.rtsThres = (u16)v;
4759 set_bit (FLAG_COMMIT, &ai->flags); 4905 set_bit (FLAG_COMMIT, &ai->flags);
4760 } else if ( !strncmp( line, "TXMSDULifetime: ", 16 ) ) { 4906 } else if ( !strncmp( line, "TXMSDULifetime: ", 16 ) ) {
@@ -4788,7 +4934,7 @@ static void proc_config_on_close( struct inode *inode, struct file *file ) {
4788 4934
4789 line += 15; 4935 line += 15;
4790 v = get_dec_u16(line, &i, 4); 4936 v = get_dec_u16(line, &i, 4);
4791 v = (v<256) ? 256 : ((v>2312) ? 2312 : v); 4937 v = (v<256) ? 256 : ((v>AIRO_DEF_MTU) ? AIRO_DEF_MTU : v);
4792 v = v & 0xfffe; /* Make sure its even */ 4938 v = v & 0xfffe; /* Make sure its even */
4793 ai->config.fragThresh = (u16)v; 4939 ai->config.fragThresh = (u16)v;
4794 set_bit (FLAG_COMMIT, &ai->flags); 4940 set_bit (FLAG_COMMIT, &ai->flags);
@@ -4798,8 +4944,7 @@ static void proc_config_on_close( struct inode *inode, struct file *file ) {
4798 case 'd': ai->config.modulation=MOD_DEFAULT; set_bit(FLAG_COMMIT, &ai->flags); break; 4944 case 'd': ai->config.modulation=MOD_DEFAULT; set_bit(FLAG_COMMIT, &ai->flags); break;
4799 case 'c': ai->config.modulation=MOD_CCK; set_bit(FLAG_COMMIT, &ai->flags); break; 4945 case 'c': ai->config.modulation=MOD_CCK; set_bit(FLAG_COMMIT, &ai->flags); break;
4800 case 'm': ai->config.modulation=MOD_MOK; set_bit(FLAG_COMMIT, &ai->flags); break; 4946 case 'm': ai->config.modulation=MOD_MOK; set_bit(FLAG_COMMIT, &ai->flags); break;
4801 default: 4947 default: airo_print_warn(ai->dev->name, "Unknown modulation");
4802 printk( KERN_WARNING "airo: Unknown modulation\n" );
4803 } 4948 }
4804 } else if (!strncmp(line, "Preamble: ", 10)) { 4949 } else if (!strncmp(line, "Preamble: ", 10)) {
4805 line += 10; 4950 line += 10;
@@ -4807,10 +4952,10 @@ static void proc_config_on_close( struct inode *inode, struct file *file ) {
4807 case 'a': ai->config.preamble=PREAMBLE_AUTO; set_bit(FLAG_COMMIT, &ai->flags); break; 4952 case 'a': ai->config.preamble=PREAMBLE_AUTO; set_bit(FLAG_COMMIT, &ai->flags); break;
4808 case 'l': ai->config.preamble=PREAMBLE_LONG; set_bit(FLAG_COMMIT, &ai->flags); break; 4953 case 'l': ai->config.preamble=PREAMBLE_LONG; set_bit(FLAG_COMMIT, &ai->flags); break;
4809 case 's': ai->config.preamble=PREAMBLE_SHORT; set_bit(FLAG_COMMIT, &ai->flags); break; 4954 case 's': ai->config.preamble=PREAMBLE_SHORT; set_bit(FLAG_COMMIT, &ai->flags); break;
4810 default: printk(KERN_WARNING "airo: Unknown preamble\n"); 4955 default: airo_print_warn(ai->dev->name, "Unknown preamble");
4811 } 4956 }
4812 } else { 4957 } else {
4813 printk( KERN_WARNING "Couldn't figure out %s\n", line ); 4958 airo_print_warn(ai->dev->name, "Couldn't figure out %s", line);
4814 } 4959 }
4815 while( line[0] && line[0] != '\n' ) line++; 4960 while( line[0] && line[0] != '\n' ) line++;
4816 if ( line[0] ) line++; 4961 if ( line[0] ) line++;
@@ -5076,7 +5221,7 @@ static void proc_wepkey_on_close( struct inode *inode, struct file *file ) {
5076 } 5221 }
5077 j = 2; 5222 j = 2;
5078 } else { 5223 } else {
5079 printk(KERN_ERR "airo: WepKey passed invalid key index\n"); 5224 airo_print_err(ai->dev->name, "WepKey passed invalid key index");
5080 return; 5225 return;
5081 } 5226 }
5082 5227
@@ -5489,17 +5634,16 @@ static int __init airo_init_module( void )
5489 airo_entry->gid = proc_gid; 5634 airo_entry->gid = proc_gid;
5490 5635
5491 for( i = 0; i < 4 && io[i] && irq[i]; i++ ) { 5636 for( i = 0; i < 4 && io[i] && irq[i]; i++ ) {
5492 printk( KERN_INFO 5637 airo_print_info("", "Trying to configure ISA adapter at irq=%d "
5493 "airo: Trying to configure ISA adapter at irq=%d io=0x%x\n", 5638 "io=0x%x", irq[i], io[i] );
5494 irq[i], io[i] );
5495 if (init_airo_card( irq[i], io[i], 0, NULL )) 5639 if (init_airo_card( irq[i], io[i], 0, NULL ))
5496 have_isa_dev = 1; 5640 have_isa_dev = 1;
5497 } 5641 }
5498 5642
5499#ifdef CONFIG_PCI 5643#ifdef CONFIG_PCI
5500 printk( KERN_INFO "airo: Probing for PCI adapters\n" ); 5644 airo_print_info("", "Probing for PCI adapters");
5501 pci_register_driver(&airo_driver); 5645 pci_register_driver(&airo_driver);
5502 printk( KERN_INFO "airo: Finished probing for PCI adapters\n" ); 5646 airo_print_info("", "Finished probing for PCI adapters");
5503#endif 5647#endif
5504 5648
5505 /* Always exit with success, as we are a library module 5649 /* Always exit with success, as we are a library module
@@ -5511,7 +5655,7 @@ static int __init airo_init_module( void )
5511static void __exit airo_cleanup_module( void ) 5655static void __exit airo_cleanup_module( void )
5512{ 5656{
5513 while( airo_devices ) { 5657 while( airo_devices ) {
5514 printk( KERN_INFO "airo: Unregistering %s\n", airo_devices->dev->name ); 5658 airo_print_info(airo_devices->dev->name, "Unregistering...\n");
5515 stop_airo_card( airo_devices->dev, 1 ); 5659 stop_airo_card( airo_devices->dev, 1 );
5516 } 5660 }
5517#ifdef CONFIG_PCI 5661#ifdef CONFIG_PCI
@@ -5622,7 +5766,8 @@ static int airo_set_freq(struct net_device *dev,
5622 /* We should do a better check than that, 5766 /* We should do a better check than that,
5623 * based on the card capability !!! */ 5767 * based on the card capability !!! */
5624 if((channel < 1) || (channel > 14)) { 5768 if((channel < 1) || (channel > 14)) {
5625 printk(KERN_DEBUG "%s: New channel value of %d is invalid!\n", dev->name, fwrq->m); 5769 airo_print_dbg(dev->name, "New channel value of %d is invalid!",
5770 fwrq->m);
5626 rc = -EINVAL; 5771 rc = -EINVAL;
5627 } else { 5772 } else {
5628 readConfigRid(local, 1); 5773 readConfigRid(local, 1);
@@ -5946,8 +6091,8 @@ static int airo_set_rts(struct net_device *dev,
5946 int rthr = vwrq->value; 6091 int rthr = vwrq->value;
5947 6092
5948 if(vwrq->disabled) 6093 if(vwrq->disabled)
5949 rthr = 2312; 6094 rthr = AIRO_DEF_MTU;
5950 if((rthr < 0) || (rthr > 2312)) { 6095 if((rthr < 0) || (rthr > AIRO_DEF_MTU)) {
5951 return -EINVAL; 6096 return -EINVAL;
5952 } 6097 }
5953 readConfigRid(local, 1); 6098 readConfigRid(local, 1);
@@ -5970,7 +6115,7 @@ static int airo_get_rts(struct net_device *dev,
5970 6115
5971 readConfigRid(local, 1); 6116 readConfigRid(local, 1);
5972 vwrq->value = local->config.rtsThres; 6117 vwrq->value = local->config.rtsThres;
5973 vwrq->disabled = (vwrq->value >= 2312); 6118 vwrq->disabled = (vwrq->value >= AIRO_DEF_MTU);
5974 vwrq->fixed = 1; 6119 vwrq->fixed = 1;
5975 6120
5976 return 0; 6121 return 0;
@@ -5989,8 +6134,8 @@ static int airo_set_frag(struct net_device *dev,
5989 int fthr = vwrq->value; 6134 int fthr = vwrq->value;
5990 6135
5991 if(vwrq->disabled) 6136 if(vwrq->disabled)
5992 fthr = 2312; 6137 fthr = AIRO_DEF_MTU;
5993 if((fthr < 256) || (fthr > 2312)) { 6138 if((fthr < 256) || (fthr > AIRO_DEF_MTU)) {
5994 return -EINVAL; 6139 return -EINVAL;
5995 } 6140 }
5996 fthr &= ~0x1; /* Get an even value - is it really needed ??? */ 6141 fthr &= ~0x1; /* Get an even value - is it really needed ??? */
@@ -6014,7 +6159,7 @@ static int airo_get_frag(struct net_device *dev,
6014 6159
6015 readConfigRid(local, 1); 6160 readConfigRid(local, 1);
6016 vwrq->value = local->config.fragThresh; 6161 vwrq->value = local->config.fragThresh;
6017 vwrq->disabled = (vwrq->value >= 2312); 6162 vwrq->disabled = (vwrq->value >= AIRO_DEF_MTU);
6018 vwrq->fixed = 1; 6163 vwrq->fixed = 1;
6019 6164
6020 return 0; 6165 return 0;
@@ -6709,9 +6854,9 @@ static int airo_get_range(struct net_device *dev,
6709 range->throughput = 1500 * 1000; 6854 range->throughput = 1500 * 1000;
6710 6855
6711 range->min_rts = 0; 6856 range->min_rts = 0;
6712 range->max_rts = 2312; 6857 range->max_rts = AIRO_DEF_MTU;
6713 range->min_frag = 256; 6858 range->min_frag = 256;
6714 range->max_frag = 2312; 6859 range->max_frag = AIRO_DEF_MTU;
6715 6860
6716 if(cap_rid.softCap & 2) { 6861 if(cap_rid.softCap & 2) {
6717 // WEP: RC4 40 bits 6862 // WEP: RC4 40 bits
@@ -6972,6 +7117,7 @@ static int airo_set_scan(struct net_device *dev,
6972 struct airo_info *ai = dev->priv; 7117 struct airo_info *ai = dev->priv;
6973 Cmd cmd; 7118 Cmd cmd;
6974 Resp rsp; 7119 Resp rsp;
7120 int wake = 0;
6975 7121
6976 /* Note : you may have realised that, as this is a SET operation, 7122 /* Note : you may have realised that, as this is a SET operation,
6977 * this is privileged and therefore a normal user can't 7123 * this is privileged and therefore a normal user can't
@@ -6981,17 +7127,25 @@ static int airo_set_scan(struct net_device *dev,
6981 * Jean II */ 7127 * Jean II */
6982 if (ai->flags & FLAG_RADIO_MASK) return -ENETDOWN; 7128 if (ai->flags & FLAG_RADIO_MASK) return -ENETDOWN;
6983 7129
7130 if (down_interruptible(&ai->sem))
7131 return -ERESTARTSYS;
7132
7133 /* If there's already a scan in progress, don't
7134 * trigger another one. */
7135 if (ai->scan_timeout > 0)
7136 goto out;
7137
6984 /* Initiate a scan command */ 7138 /* Initiate a scan command */
6985 memset(&cmd, 0, sizeof(cmd)); 7139 memset(&cmd, 0, sizeof(cmd));
6986 cmd.cmd=CMD_LISTBSS; 7140 cmd.cmd=CMD_LISTBSS;
6987 if (down_interruptible(&ai->sem))
6988 return -ERESTARTSYS;
6989 issuecommand(ai, &cmd, &rsp); 7141 issuecommand(ai, &cmd, &rsp);
6990 ai->scan_timestamp = jiffies; 7142 ai->scan_timeout = RUN_AT(3*HZ);
6991 up(&ai->sem); 7143 wake = 1;
6992
6993 /* At this point, just return to the user. */
6994 7144
7145out:
7146 up(&ai->sem);
7147 if (wake)
7148 wake_up_interruptible(&ai->thr_wait);
6995 return 0; 7149 return 0;
6996} 7150}
6997 7151
@@ -7111,59 +7265,38 @@ static int airo_get_scan(struct net_device *dev,
7111 char *extra) 7265 char *extra)
7112{ 7266{
7113 struct airo_info *ai = dev->priv; 7267 struct airo_info *ai = dev->priv;
7114 BSSListRid BSSList; 7268 BSSListElement *net;
7115 int rc; 7269 int err = 0;
7116 char *current_ev = extra; 7270 char *current_ev = extra;
7117 7271
7118 /* When we are associated again, the scan has surely finished. 7272 /* If a scan is in-progress, return -EAGAIN */
7119 * Just in case, let's make sure enough time has elapsed since 7273 if (ai->scan_timeout > 0)
7120 * we started the scan. - Javier */
7121 if(ai->scan_timestamp && time_before(jiffies,ai->scan_timestamp+3*HZ)) {
7122 /* Important note : we don't want to block the caller
7123 * until results are ready for various reasons.
7124 * First, managing wait queues is complex and racy
7125 * (there may be multiple simultaneous callers).
7126 * Second, we grab some rtnetlink lock before comming
7127 * here (in dev_ioctl()).
7128 * Third, the caller can wait on the Wireless Event
7129 * - Jean II */
7130 return -EAGAIN; 7274 return -EAGAIN;
7131 }
7132 ai->scan_timestamp = 0;
7133 7275
7134 /* There's only a race with proc_BSSList_open(), but its 7276 if (down_interruptible(&ai->sem))
7135 * consequences are begnign. So I don't bother fixing it - Javier */ 7277 return -EAGAIN;
7136
7137 /* Try to read the first entry of the scan result */
7138 rc = PC4500_readrid(ai, RID_BSSLISTFIRST, &BSSList, sizeof(BSSList), 1);
7139 if((rc) || (BSSList.index == 0xffff)) {
7140 /* Client error, no scan results...
7141 * The caller need to restart the scan. */
7142 return -ENODATA;
7143 }
7144 7278
7145 /* Read and parse all entries */ 7279 list_for_each_entry (net, &ai->network_list, list) {
7146 while((!rc) && (BSSList.index != 0xffff)) {
7147 /* Translate to WE format this entry */ 7280 /* Translate to WE format this entry */
7148 current_ev = airo_translate_scan(dev, current_ev, 7281 current_ev = airo_translate_scan(dev, current_ev,
7149 extra + dwrq->length, 7282 extra + dwrq->length,
7150 &BSSList); 7283 &net->bss);
7151 7284
7152 /* Check if there is space for one more entry */ 7285 /* Check if there is space for one more entry */
7153 if((extra + dwrq->length - current_ev) <= IW_EV_ADDR_LEN) { 7286 if((extra + dwrq->length - current_ev) <= IW_EV_ADDR_LEN) {
7154 /* Ask user space to try again with a bigger buffer */ 7287 /* Ask user space to try again with a bigger buffer */
7155 return -E2BIG; 7288 err = -E2BIG;
7289 goto out;
7156 } 7290 }
7157
7158 /* Read next entry */
7159 rc = PC4500_readrid(ai, RID_BSSLISTNEXT,
7160 &BSSList, sizeof(BSSList), 1);
7161 } 7291 }
7292
7162 /* Length of data */ 7293 /* Length of data */
7163 dwrq->length = (current_ev - extra); 7294 dwrq->length = (current_ev - extra);
7164 dwrq->flags = 0; /* todo */ 7295 dwrq->flags = 0; /* todo */
7165 7296
7166 return 0; 7297out:
7298 up(&ai->sem);
7299 return err;
7167} 7300}
7168 7301
7169/*------------------------------------------------------------------*/ 7302/*------------------------------------------------------------------*/
@@ -7711,7 +7844,7 @@ static int cmdreset(struct airo_info *ai) {
7711 disable_MAC(ai, 1); 7844 disable_MAC(ai, 1);
7712 7845
7713 if(!waitbusy (ai)){ 7846 if(!waitbusy (ai)){
7714 printk(KERN_INFO "Waitbusy hang before RESET\n"); 7847 airo_print_info(ai->dev->name, "Waitbusy hang before RESET");
7715 return -EBUSY; 7848 return -EBUSY;
7716 } 7849 }
7717 7850
@@ -7720,7 +7853,7 @@ static int cmdreset(struct airo_info *ai) {
7720 ssleep(1); /* WAS 600 12/7/00 */ 7853 ssleep(1); /* WAS 600 12/7/00 */
7721 7854
7722 if(!waitbusy (ai)){ 7855 if(!waitbusy (ai)){
7723 printk(KERN_INFO "Waitbusy hang AFTER RESET\n"); 7856 airo_print_info(ai->dev->name, "Waitbusy hang AFTER RESET");
7724 return -EBUSY; 7857 return -EBUSY;
7725 } 7858 }
7726 return 0; 7859 return 0;
@@ -7748,7 +7881,7 @@ static int setflashmode (struct airo_info *ai) {
7748 7881
7749 if(!waitbusy(ai)) { 7882 if(!waitbusy(ai)) {
7750 clear_bit (FLAG_FLASHING, &ai->flags); 7883 clear_bit (FLAG_FLASHING, &ai->flags);
7751 printk(KERN_INFO "Waitbusy hang after setflash mode\n"); 7884 airo_print_info(ai->dev->name, "Waitbusy hang after setflash mode");
7752 return -EIO; 7885 return -EIO;
7753 } 7886 }
7754 return 0; 7887 return 0;
@@ -7777,7 +7910,7 @@ static int flashpchar(struct airo_info *ai,int byte,int dwelltime) {
7777 7910
7778 /* timeout for busy clear wait */ 7911 /* timeout for busy clear wait */
7779 if(waittime <= 0 ){ 7912 if(waittime <= 0 ){
7780 printk(KERN_INFO "flash putchar busywait timeout! \n"); 7913 airo_print_info(ai->dev->name, "flash putchar busywait timeout!");
7781 return -EBUSY; 7914 return -EBUSY;
7782 } 7915 }
7783 7916
@@ -7866,7 +7999,7 @@ static int flashrestart(struct airo_info *ai,struct net_device *dev){
7866 if (!test_bit(FLAG_MPI,&ai->flags)) 7999 if (!test_bit(FLAG_MPI,&ai->flags))
7867 for( i = 0; i < MAX_FIDS; i++ ) { 8000 for( i = 0; i < MAX_FIDS; i++ ) {
7868 ai->fids[i] = transmit_allocate 8001 ai->fids[i] = transmit_allocate
7869 ( ai, 2312, i >= MAX_FIDS / 2 ); 8002 ( ai, AIRO_DEF_MTU, i >= MAX_FIDS / 2 );
7870 } 8003 }
7871 8004
7872 ssleep(1); /* Added 12/7/00 */ 8005 ssleep(1); /* Added 12/7/00 */
diff --git a/drivers/net/wireless/hostap/hostap_ap.c b/drivers/net/wireless/hostap/hostap_ap.c
index 753a1de666..06c3fa32b3 100644
--- a/drivers/net/wireless/hostap/hostap_ap.c
+++ b/drivers/net/wireless/hostap/hostap_ap.c
@@ -3141,7 +3141,7 @@ int hostap_add_sta(struct ap_data *ap, u8 *sta_addr)
3141 if (ret == 1) { 3141 if (ret == 1) {
3142 sta = ap_add_sta(ap, sta_addr); 3142 sta = ap_add_sta(ap, sta_addr);
3143 if (!sta) 3143 if (!sta)
3144 ret = -1; 3144 return -1;
3145 sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC; 3145 sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC;
3146 sta->ap = 1; 3146 sta->ap = 1;
3147 memset(sta->supported_rates, 0, sizeof(sta->supported_rates)); 3147 memset(sta->supported_rates, 0, sizeof(sta->supported_rates));
diff --git a/drivers/net/wireless/hostap/hostap_cs.c b/drivers/net/wireless/hostap/hostap_cs.c
index f8f4503475..d335b25092 100644
--- a/drivers/net/wireless/hostap/hostap_cs.c
+++ b/drivers/net/wireless/hostap/hostap_cs.c
@@ -585,8 +585,6 @@ static int prism2_config(dev_link_t *link)
585 parse = kmalloc(sizeof(cisparse_t), GFP_KERNEL); 585 parse = kmalloc(sizeof(cisparse_t), GFP_KERNEL);
586 hw_priv = kmalloc(sizeof(*hw_priv), GFP_KERNEL); 586 hw_priv = kmalloc(sizeof(*hw_priv), GFP_KERNEL);
587 if (parse == NULL || hw_priv == NULL) { 587 if (parse == NULL || hw_priv == NULL) {
588 kfree(parse);
589 kfree(hw_priv);
590 ret = -ENOMEM; 588 ret = -ENOMEM;
591 goto failed; 589 goto failed;
592 } 590 }
diff --git a/drivers/net/wireless/hostap/hostap_hw.c b/drivers/net/wireless/hostap/hostap_hw.c
index b1f142d9e2..328e9a1d13 100644
--- a/drivers/net/wireless/hostap/hostap_hw.c
+++ b/drivers/net/wireless/hostap/hostap_hw.c
@@ -928,15 +928,15 @@ static int hfa384x_set_rid(struct net_device *dev, u16 rid, void *buf, int len)
928 928
929 res = hfa384x_cmd(dev, HFA384X_CMDCODE_ACCESS_WRITE, rid, NULL, NULL); 929 res = hfa384x_cmd(dev, HFA384X_CMDCODE_ACCESS_WRITE, rid, NULL, NULL);
930 up(&local->rid_bap_sem); 930 up(&local->rid_bap_sem);
931
931 if (res) { 932 if (res) {
932 printk(KERN_DEBUG "%s: hfa384x_set_rid: CMDCODE_ACCESS_WRITE " 933 printk(KERN_DEBUG "%s: hfa384x_set_rid: CMDCODE_ACCESS_WRITE "
933 "failed (res=%d, rid=%04x, len=%d)\n", 934 "failed (res=%d, rid=%04x, len=%d)\n",
934 dev->name, res, rid, len); 935 dev->name, res, rid, len);
935 return res;
936 }
937 936
938 if (res == -ETIMEDOUT) 937 if (res == -ETIMEDOUT)
939 prism2_hw_reset(dev); 938 prism2_hw_reset(dev);
939 }
940 940
941 return res; 941 return res;
942} 942}
diff --git a/drivers/net/wireless/hostap/hostap_ioctl.c b/drivers/net/wireless/hostap/hostap_ioctl.c
index f3e0ce1ee0..8b37e824df 100644
--- a/drivers/net/wireless/hostap/hostap_ioctl.c
+++ b/drivers/net/wireless/hostap/hostap_ioctl.c
@@ -3358,10 +3358,6 @@ static int prism2_ioctl_siwencodeext(struct net_device *dev,
3358 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) { 3358 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
3359 if (!sta_ptr) 3359 if (!sta_ptr)
3360 local->tx_keyidx = i; 3360 local->tx_keyidx = i;
3361 else if (i) {
3362 ret = -EINVAL;
3363 goto done;
3364 }
3365 } 3361 }
3366 3362
3367 3363
diff --git a/drivers/net/wireless/hostap/hostap_pci.c b/drivers/net/wireless/hostap/hostap_pci.c
index 2e85bdced2..194f070975 100644
--- a/drivers/net/wireless/hostap/hostap_pci.c
+++ b/drivers/net/wireless/hostap/hostap_pci.c
@@ -307,7 +307,7 @@ static int prism2_pci_probe(struct pci_dev *pdev,
307 memset(hw_priv, 0, sizeof(*hw_priv)); 307 memset(hw_priv, 0, sizeof(*hw_priv));
308 308
309 if (pci_enable_device(pdev)) 309 if (pci_enable_device(pdev))
310 return -EIO; 310 goto err_out_free;
311 311
312 phymem = pci_resource_start(pdev, 0); 312 phymem = pci_resource_start(pdev, 0);
313 313
@@ -368,6 +368,8 @@ static int prism2_pci_probe(struct pci_dev *pdev,
368 err_out_disable: 368 err_out_disable:
369 pci_disable_device(pdev); 369 pci_disable_device(pdev);
370 prism2_free_local_data(dev); 370 prism2_free_local_data(dev);
371
372 err_out_free:
371 kfree(hw_priv); 373 kfree(hw_priv);
372 374
373 return -ENODEV; 375 return -ENODEV;
diff --git a/drivers/net/wireless/hostap/hostap_plx.c b/drivers/net/wireless/hostap/hostap_plx.c
index 94fe2449f0..edaaa943eb 100644
--- a/drivers/net/wireless/hostap/hostap_plx.c
+++ b/drivers/net/wireless/hostap/hostap_plx.c
@@ -368,7 +368,7 @@ static int prism2_plx_check_cis(void __iomem *attr_mem, int attr_len,
368 368
369 switch (cis[pos]) { 369 switch (cis[pos]) {
370 case CISTPL_CONFIG: 370 case CISTPL_CONFIG:
371 if (cis[pos + 1] < 1) 371 if (cis[pos + 1] < 2)
372 goto cis_error; 372 goto cis_error;
373 rmsz = (cis[pos + 2] & 0x3c) >> 2; 373 rmsz = (cis[pos + 2] & 0x3c) >> 2;
374 rasz = cis[pos + 2] & 0x03; 374 rasz = cis[pos + 2] & 0x03;
@@ -390,7 +390,7 @@ static int prism2_plx_check_cis(void __iomem *attr_mem, int attr_len,
390 break; 390 break;
391 391
392 case CISTPL_MANFID: 392 case CISTPL_MANFID:
393 if (cis[pos + 1] < 4) 393 if (cis[pos + 1] < 5)
394 goto cis_error; 394 goto cis_error;
395 manfid1 = cis[pos + 2] + (cis[pos + 3] << 8); 395 manfid1 = cis[pos + 2] + (cis[pos + 3] << 8);
396 manfid2 = cis[pos + 4] + (cis[pos + 5] << 8); 396 manfid2 = cis[pos + 4] + (cis[pos + 5] << 8);
@@ -452,7 +452,7 @@ static int prism2_plx_probe(struct pci_dev *pdev,
452 memset(hw_priv, 0, sizeof(*hw_priv)); 452 memset(hw_priv, 0, sizeof(*hw_priv));
453 453
454 if (pci_enable_device(pdev)) 454 if (pci_enable_device(pdev))
455 return -EIO; 455 goto err_out_free;
456 456
457 /* National Datacomm NCP130 based on TMD7160, not PLX9052. */ 457 /* National Datacomm NCP130 based on TMD7160, not PLX9052. */
458 tmd7160 = (pdev->vendor == 0x15e8) && (pdev->device == 0x0131); 458 tmd7160 = (pdev->vendor == 0x15e8) && (pdev->device == 0x0131);
@@ -567,9 +567,6 @@ static int prism2_plx_probe(struct pci_dev *pdev,
567 return hostap_hw_ready(dev); 567 return hostap_hw_ready(dev);
568 568
569 fail: 569 fail:
570 prism2_free_local_data(dev);
571 kfree(hw_priv);
572
573 if (irq_registered && dev) 570 if (irq_registered && dev)
574 free_irq(dev->irq, dev); 571 free_irq(dev->irq, dev);
575 572
@@ -577,6 +574,10 @@ static int prism2_plx_probe(struct pci_dev *pdev,
577 iounmap(attr_mem); 574 iounmap(attr_mem);
578 575
579 pci_disable_device(pdev); 576 pci_disable_device(pdev);
577 prism2_free_local_data(dev);
578
579 err_out_free:
580 kfree(hw_priv);
580 581
581 return -ENODEV; 582 return -ENODEV;
582} 583}
diff --git a/drivers/net/wireless/prism54/oid_mgt.c b/drivers/net/wireless/prism54/oid_mgt.c
index eea2f04c8c..ebb2387858 100644
--- a/drivers/net/wireless/prism54/oid_mgt.c
+++ b/drivers/net/wireless/prism54/oid_mgt.c
@@ -332,7 +332,7 @@ mgt_le_to_cpu(int type, void *data)
332 case OID_TYPE_ATTACH:{ 332 case OID_TYPE_ATTACH:{
333 struct obj_attachment *attach = data; 333 struct obj_attachment *attach = data;
334 attach->id = le16_to_cpu(attach->id); 334 attach->id = le16_to_cpu(attach->id);
335 attach->size = le16_to_cpu(attach->size);; 335 attach->size = le16_to_cpu(attach->size);
336 break; 336 break;
337 } 337 }
338 case OID_TYPE_SSID: 338 case OID_TYPE_SSID:
@@ -401,7 +401,7 @@ mgt_cpu_to_le(int type, void *data)
401 case OID_TYPE_ATTACH:{ 401 case OID_TYPE_ATTACH:{
402 struct obj_attachment *attach = data; 402 struct obj_attachment *attach = data;
403 attach->id = cpu_to_le16(attach->id); 403 attach->id = cpu_to_le16(attach->id);
404 attach->size = cpu_to_le16(attach->size);; 404 attach->size = cpu_to_le16(attach->size);
405 break; 405 break;
406 } 406 }
407 case OID_TYPE_SSID: 407 case OID_TYPE_SSID:
diff --git a/drivers/net/wireless/spectrum_cs.c b/drivers/net/wireless/spectrum_cs.c
index fee4be1ce8..5fa6fbe35b 100644
--- a/drivers/net/wireless/spectrum_cs.c
+++ b/drivers/net/wireless/spectrum_cs.c
@@ -147,7 +147,7 @@ struct pdi {
147 __le16 _len; /* length of ID and data, in words */ 147 __le16 _len; /* length of ID and data, in words */
148 __le16 _id; /* record ID */ 148 __le16 _id; /* record ID */
149 char data[0]; /* plug data */ 149 char data[0]; /* plug data */
150} __attribute__ ((packed));; 150} __attribute__ ((packed));
151 151
152 152
153/* Functions for access to little-endian data */ 153/* Functions for access to little-endian data */
diff --git a/drivers/oprofile/cpu_buffer.c b/drivers/oprofile/cpu_buffer.c
index 78193e4bbd..330d3869b4 100644
--- a/drivers/oprofile/cpu_buffer.c
+++ b/drivers/oprofile/cpu_buffer.c
@@ -38,9 +38,8 @@ void free_cpu_buffers(void)
38{ 38{
39 int i; 39 int i;
40 40
41 for_each_online_cpu(i) { 41 for_each_online_cpu(i)
42 vfree(cpu_buffer[i].buffer); 42 vfree(cpu_buffer[i].buffer);
43 }
44} 43}
45 44
46int alloc_cpu_buffers(void) 45int alloc_cpu_buffers(void)
diff --git a/drivers/pci/Kconfig b/drivers/pci/Kconfig
index f187fd8aee..4d762fc487 100644
--- a/drivers/pci/Kconfig
+++ b/drivers/pci/Kconfig
@@ -11,24 +11,11 @@ config PCI_MSI
11 generate an interrupt using an inbound Memory Write on its 11 generate an interrupt using an inbound Memory Write on its
12 PCI bus instead of asserting a device IRQ pin. 12 PCI bus instead of asserting a device IRQ pin.
13 13
14 If you don't know what to do here, say N. 14 Use of PCI MSI interrupts can be disabled at kernel boot time
15 15 by using the 'pci=nomsi' option. This disables MSI for the
16config PCI_LEGACY_PROC 16 entire system.
17 bool "Legacy /proc/pci interface"
18 depends on PCI
19 ---help---
20 This feature enables a procfs file -- /proc/pci -- that provides a
21 summary of PCI devices in the system.
22
23 This feature has been deprecated as of v2.5.53, in favor of using the
24 tool lspci(8). This feature may be removed at a future date.
25 17
26 lspci can provide the same data, as well as much more. lspci is a part of 18 If you don't know what to do here, say N.
27 the pci-utils package, which should be installed by your distribution.
28 See <file:Documentation/Changes> for information on where to get the latest
29 version.
30
31 When in doubt, say N.
32 19
33config PCI_DEBUG 20config PCI_DEBUG
34 bool "PCI Debugging" 21 bool "PCI Debugging"
diff --git a/drivers/pci/hotplug/Makefile b/drivers/pci/hotplug/Makefile
index 3c71e3077f..421cfffb17 100644
--- a/drivers/pci/hotplug/Makefile
+++ b/drivers/pci/hotplug/Makefile
@@ -22,6 +22,9 @@ ifdef CONFIG_HOTPLUG_PCI_CPCI
22pci_hotplug-objs += cpci_hotplug_core.o \ 22pci_hotplug-objs += cpci_hotplug_core.o \
23 cpci_hotplug_pci.o 23 cpci_hotplug_pci.o
24endif 24endif
25ifdef CONFIG_ACPI
26pci_hotplug-objs += acpi_pcihp.o
27endif
25 28
26cpqphp-objs := cpqphp_core.o \ 29cpqphp-objs := cpqphp_core.o \
27 cpqphp_ctrl.o \ 30 cpqphp_ctrl.o \
@@ -37,7 +40,8 @@ ibmphp-objs := ibmphp_core.o \
37 ibmphp_hpc.o 40 ibmphp_hpc.o
38 41
39acpiphp-objs := acpiphp_core.o \ 42acpiphp-objs := acpiphp_core.o \
40 acpiphp_glue.o 43 acpiphp_glue.o \
44 acpiphp_dock.o
41 45
42rpaphp-objs := rpaphp_core.o \ 46rpaphp-objs := rpaphp_core.o \
43 rpaphp_pci.o \ 47 rpaphp_pci.o \
@@ -50,23 +54,9 @@ pciehp-objs := pciehp_core.o \
50 pciehp_ctrl.o \ 54 pciehp_ctrl.o \
51 pciehp_pci.o \ 55 pciehp_pci.o \
52 pciehp_hpc.o 56 pciehp_hpc.o
53ifdef CONFIG_ACPI
54 pciehp-objs += pciehprm_acpi.o
55else
56 pciehp-objs += pciehprm_nonacpi.o
57endif
58 57
59shpchp-objs := shpchp_core.o \ 58shpchp-objs := shpchp_core.o \
60 shpchp_ctrl.o \ 59 shpchp_ctrl.o \
61 shpchp_pci.o \ 60 shpchp_pci.o \
62 shpchp_sysfs.o \ 61 shpchp_sysfs.o \
63 shpchp_hpc.o 62 shpchp_hpc.o
64ifdef CONFIG_ACPI
65 shpchp-objs += shpchprm_acpi.o
66else
67 ifdef CONFIG_HOTPLUG_PCI_SHPC_PHPRM_LEGACY
68 shpchp-objs += shpchprm_legacy.o
69 else
70 shpchp-objs += shpchprm_nonacpi.o
71 endif
72endif
diff --git a/drivers/pci/hotplug/shpchprm_acpi.c b/drivers/pci/hotplug/acpi_pcihp.c
index 17145e5222..39af9c325f 100644
--- a/drivers/pci/hotplug/shpchprm_acpi.c
+++ b/drivers/pci/hotplug/acpi_pcihp.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * SHPCHPRM ACPI: PHP Resource Manager for ACPI platform 2 * Common ACPI functions for hot plug platforms
3 * 3 *
4 * Copyright (C) 2003-2004 Intel Corporation 4 * Copyright (C) 2006 Intel Corporation
5 * 5 *
6 * All rights reserved. 6 * All rights reserved.
7 * 7 *
@@ -31,26 +31,12 @@
31#include <acpi/acpi.h> 31#include <acpi/acpi.h>
32#include <acpi/acpi_bus.h> 32#include <acpi/acpi_bus.h>
33#include <acpi/actypes.h> 33#include <acpi/actypes.h>
34#include "shpchp.h" 34#include "pci_hotplug.h"
35 35
36#define METHOD_NAME__SUN "_SUN" 36#define METHOD_NAME__SUN "_SUN"
37#define METHOD_NAME__HPP "_HPP" 37#define METHOD_NAME__HPP "_HPP"
38#define METHOD_NAME_OSHP "OSHP" 38#define METHOD_NAME_OSHP "OSHP"
39 39
40static u8 * acpi_path_name( acpi_handle handle)
41{
42 acpi_status status;
43 static u8 path_name[ACPI_PATHNAME_MAX];
44 struct acpi_buffer ret_buf = { ACPI_PATHNAME_MAX, path_name };
45
46 memset(path_name, 0, sizeof (path_name));
47 status = acpi_get_name(handle, ACPI_FULL_PATHNAME, &ret_buf);
48
49 if (ACPI_FAILURE(status))
50 return NULL;
51 else
52 return path_name;
53}
54 40
55static acpi_status 41static acpi_status
56acpi_run_hpp(acpi_handle handle, struct hotplug_params *hpp) 42acpi_run_hpp(acpi_handle handle, struct hotplug_params *hpp)
@@ -58,18 +44,21 @@ acpi_run_hpp(acpi_handle handle, struct hotplug_params *hpp)
58 acpi_status status; 44 acpi_status status;
59 u8 nui[4]; 45 u8 nui[4];
60 struct acpi_buffer ret_buf = { 0, NULL}; 46 struct acpi_buffer ret_buf = { 0, NULL};
47 struct acpi_buffer string = { ACPI_ALLOCATE_BUFFER, NULL };
61 union acpi_object *ext_obj, *package; 48 union acpi_object *ext_obj, *package;
62 u8 *path_name = acpi_path_name(handle);
63 int i, len = 0; 49 int i, len = 0;
64 50
51 acpi_get_name(handle, ACPI_FULL_PATHNAME, &string);
52
65 /* get _hpp */ 53 /* get _hpp */
66 status = acpi_evaluate_object(handle, METHOD_NAME__HPP, NULL, &ret_buf); 54 status = acpi_evaluate_object(handle, METHOD_NAME__HPP, NULL, &ret_buf);
67 switch (status) { 55 switch (status) {
68 case AE_BUFFER_OVERFLOW: 56 case AE_BUFFER_OVERFLOW:
69 ret_buf.pointer = kmalloc (ret_buf.length, GFP_KERNEL); 57 ret_buf.pointer = kmalloc (ret_buf.length, GFP_KERNEL);
70 if (!ret_buf.pointer) { 58 if (!ret_buf.pointer) {
71 err ("%s:%s alloc for _HPP fail\n", __FUNCTION__, 59 printk(KERN_ERR "%s:%s alloc for _HPP fail\n",
72 path_name); 60 __FUNCTION__, (char *)string.pointer);
61 acpi_os_free(string.pointer);
73 return AE_NO_MEMORY; 62 return AE_NO_MEMORY;
74 } 63 }
75 status = acpi_evaluate_object(handle, METHOD_NAME__HPP, 64 status = acpi_evaluate_object(handle, METHOD_NAME__HPP,
@@ -78,16 +67,17 @@ acpi_run_hpp(acpi_handle handle, struct hotplug_params *hpp)
78 break; 67 break;
79 default: 68 default:
80 if (ACPI_FAILURE(status)) { 69 if (ACPI_FAILURE(status)) {
81 dbg("%s:%s _HPP fail=0x%x\n", __FUNCTION__, 70 pr_debug("%s:%s _HPP fail=0x%x\n", __FUNCTION__,
82 path_name, status); 71 (char *)string.pointer, status);
72 acpi_os_free(string.pointer);
83 return status; 73 return status;
84 } 74 }
85 } 75 }
86 76
87 ext_obj = (union acpi_object *) ret_buf.pointer; 77 ext_obj = (union acpi_object *) ret_buf.pointer;
88 if (ext_obj->type != ACPI_TYPE_PACKAGE) { 78 if (ext_obj->type != ACPI_TYPE_PACKAGE) {
89 err ("%s:%s _HPP obj not a package\n", __FUNCTION__, 79 printk(KERN_ERR "%s:%s _HPP obj not a package\n", __FUNCTION__,
90 path_name); 80 (char *)string.pointer);
91 status = AE_ERROR; 81 status = AE_ERROR;
92 goto free_and_return; 82 goto free_and_return;
93 } 83 }
@@ -101,8 +91,8 @@ acpi_run_hpp(acpi_handle handle, struct hotplug_params *hpp)
101 nui[i] = (u8)ext_obj->integer.value; 91 nui[i] = (u8)ext_obj->integer.value;
102 break; 92 break;
103 default: 93 default:
104 err ("%s:%s _HPP obj type incorrect\n", __FUNCTION__, 94 printk(KERN_ERR "%s:%s _HPP obj type incorrect\n",
105 path_name); 95 __FUNCTION__, (char *)string.pointer);
106 status = AE_ERROR; 96 status = AE_ERROR;
107 goto free_and_return; 97 goto free_and_return;
108 } 98 }
@@ -113,54 +103,52 @@ acpi_run_hpp(acpi_handle handle, struct hotplug_params *hpp)
113 hpp->enable_serr = nui[2]; 103 hpp->enable_serr = nui[2];
114 hpp->enable_perr = nui[3]; 104 hpp->enable_perr = nui[3];
115 105
116 dbg(" _HPP: cache_line_size=0x%x\n", hpp->cache_line_size); 106 pr_debug(" _HPP: cache_line_size=0x%x\n", hpp->cache_line_size);
117 dbg(" _HPP: latency timer =0x%x\n", hpp->latency_timer); 107 pr_debug(" _HPP: latency timer =0x%x\n", hpp->latency_timer);
118 dbg(" _HPP: enable SERR =0x%x\n", hpp->enable_serr); 108 pr_debug(" _HPP: enable SERR =0x%x\n", hpp->enable_serr);
119 dbg(" _HPP: enable PERR =0x%x\n", hpp->enable_perr); 109 pr_debug(" _HPP: enable PERR =0x%x\n", hpp->enable_perr);
120 110
121free_and_return: 111free_and_return:
122 kfree(ret_buf.pointer); 112 acpi_os_free(string.pointer);
113 acpi_os_free(ret_buf.pointer);
123 return status; 114 return status;
124} 115}
125 116
126static void acpi_run_oshp(acpi_handle handle) 117
118
119/* acpi_run_oshp - get control of hotplug from the firmware
120 *
121 * @handle - the handle of the hotplug controller.
122 */
123acpi_status acpi_run_oshp(acpi_handle handle)
127{ 124{
128 acpi_status status; 125 acpi_status status;
129 u8 *path_name = acpi_path_name(handle); 126 struct acpi_buffer string = { ACPI_ALLOCATE_BUFFER, NULL };
127
128 acpi_get_name(handle, ACPI_FULL_PATHNAME, &string);
130 129
131 /* run OSHP */ 130 /* run OSHP */
132 status = acpi_evaluate_object(handle, METHOD_NAME_OSHP, NULL, NULL); 131 status = acpi_evaluate_object(handle, METHOD_NAME_OSHP, NULL, NULL);
133 if (ACPI_FAILURE(status)) { 132 if (ACPI_FAILURE(status))
134 err("%s:%s OSHP fails=0x%x\n", __FUNCTION__, path_name, 133 printk(KERN_ERR "%s:%s OSHP fails=0x%x\n", __FUNCTION__,
135 status); 134 (char *)string.pointer, status);
136 } else { 135 else
137 dbg("%s:%s OSHP passes\n", __FUNCTION__, path_name); 136 pr_debug("%s:%s OSHP passes\n", __FUNCTION__,
138 } 137 (char *)string.pointer);
139}
140
141int shpchprm_get_physical_slot_number(struct controller *ctrl, u32 *sun, u8 busnum, u8 devnum)
142{
143 int offset = devnum - ctrl->slot_device_offset;
144 138
145 dbg("%s: ctrl->slot_num_inc %d, offset %d\n", __FUNCTION__, ctrl->slot_num_inc, offset); 139 acpi_os_free(string.pointer);
146 *sun = (u8) (ctrl->first_slot + ctrl->slot_num_inc *offset); 140 return status;
147 return 0;
148} 141}
142EXPORT_SYMBOL_GPL(acpi_run_oshp);
143
149 144
150void get_hp_hw_control_from_firmware(struct pci_dev *dev)
151{
152 /*
153 * OSHP is an optional ACPI firmware control method. If present,
154 * we need to run it to inform BIOS that we will control SHPC
155 * hardware from now on.
156 */
157 acpi_handle handle = DEVICE_ACPI_HANDLE(&(dev->dev));
158 if (!handle)
159 return;
160 acpi_run_oshp(handle);
161}
162 145
163void get_hp_params_from_firmware(struct pci_dev *dev, 146/* acpi_get_hp_params_from_firmware
147 *
148 * @dev - the pci_dev of the newly added device
149 * @hpp - allocated by the caller
150 */
151acpi_status acpi_get_hp_params_from_firmware(struct pci_dev *dev,
164 struct hotplug_params *hpp) 152 struct hotplug_params *hpp)
165{ 153{
166 acpi_status status = AE_NOT_FOUND; 154 acpi_status status = AE_NOT_FOUND;
@@ -182,5 +170,42 @@ void get_hp_params_from_firmware(struct pci_dev *dev,
182 /* Check if a parent object supports _HPP */ 170 /* Check if a parent object supports _HPP */
183 pdev = pdev->bus->parent->self; 171 pdev = pdev->bus->parent->self;
184 } 172 }
173 return status;
185} 174}
175EXPORT_SYMBOL_GPL(acpi_get_hp_params_from_firmware);
186 176
177
178/* acpi_root_bridge - check to see if this acpi object is a root bridge
179 *
180 * @handle - the acpi object in question.
181 */
182int acpi_root_bridge(acpi_handle handle)
183{
184 acpi_status status;
185 struct acpi_device_info *info;
186 struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
187 int i;
188
189 status = acpi_get_object_info(handle, &buffer);
190 if (ACPI_SUCCESS(status)) {
191 info = buffer.pointer;
192 if ((info->valid & ACPI_VALID_HID) &&
193 !strcmp(PCI_ROOT_HID_STRING,
194 info->hardware_id.value)) {
195 acpi_os_free(buffer.pointer);
196 return 1;
197 }
198 if (info->valid & ACPI_VALID_CID) {
199 for (i=0; i < info->compatibility_id.count; i++) {
200 if (!strcmp(PCI_ROOT_HID_STRING,
201 info->compatibility_id.id[i].value)) {
202 acpi_os_free(buffer.pointer);
203 return 1;
204 }
205 }
206 }
207 acpi_os_free(buffer.pointer);
208 }
209 return 0;
210}
211EXPORT_SYMBOL_GPL(acpi_root_bridge);
diff --git a/drivers/pci/hotplug/acpiphp.h b/drivers/pci/hotplug/acpiphp.h
index 293603e1b7..467ac70a46 100644
--- a/drivers/pci/hotplug/acpiphp.h
+++ b/drivers/pci/hotplug/acpiphp.h
@@ -37,6 +37,7 @@
37 37
38#include <linux/acpi.h> 38#include <linux/acpi.h>
39#include <linux/kobject.h> /* for KOBJ_NAME_LEN */ 39#include <linux/kobject.h> /* for KOBJ_NAME_LEN */
40#include <linux/mutex.h>
40#include "pci_hotplug.h" 41#include "pci_hotplug.h"
41 42
42#define dbg(format, arg...) \ 43#define dbg(format, arg...) \
@@ -59,26 +60,10 @@ struct acpiphp_slot;
59 * struct slot - slot information for each *physical* slot 60 * struct slot - slot information for each *physical* slot
60 */ 61 */
61struct slot { 62struct slot {
62 u8 number;
63 struct hotplug_slot *hotplug_slot; 63 struct hotplug_slot *hotplug_slot;
64 struct list_head slot_list;
65
66 struct acpiphp_slot *acpi_slot; 64 struct acpiphp_slot *acpi_slot;
67}; 65};
68 66
69/**
70 * struct hpp_param - ACPI 2.0 _HPP Hot Plug Parameters
71 * @cache_line_size in DWORD
72 * @latency_timer in PCI clock
73 * @enable_SERR 0 or 1
74 * @enable_PERR 0 or 1
75 */
76struct hpp_param {
77 u8 cache_line_size;
78 u8 latency_timer;
79 u8 enable_SERR;
80 u8 enable_PERR;
81};
82 67
83 68
84/** 69/**
@@ -102,7 +87,7 @@ struct acpiphp_bridge {
102 struct pci_dev *pci_dev; 87 struct pci_dev *pci_dev;
103 88
104 /* ACPI 2.0 _HPP parameters */ 89 /* ACPI 2.0 _HPP parameters */
105 struct hpp_param hpp; 90 struct hotplug_params hpp;
106 91
107 spinlock_t res_lock; 92 spinlock_t res_lock;
108}; 93};
@@ -118,9 +103,9 @@ struct acpiphp_slot {
118 struct acpiphp_bridge *bridge; /* parent */ 103 struct acpiphp_bridge *bridge; /* parent */
119 struct list_head funcs; /* one slot may have different 104 struct list_head funcs; /* one slot may have different
120 objects (i.e. for each function) */ 105 objects (i.e. for each function) */
121 struct semaphore crit_sect; 106 struct slot *slot;
107 struct mutex crit_sect;
122 108
123 u32 id; /* slot id (serial #) for hotplug core */
124 u8 device; /* pci device# */ 109 u8 device; /* pci device# */
125 110
126 u32 sun; /* ACPI _SUN (slot unique number) */ 111 u32 sun; /* ACPI _SUN (slot unique number) */
@@ -160,6 +145,25 @@ struct acpiphp_attention_info
160 struct module *owner; 145 struct module *owner;
161}; 146};
162 147
148
149struct dependent_device {
150 struct list_head device_list;
151 struct list_head pci_list;
152 acpi_handle handle;
153 struct acpiphp_func *func;
154};
155
156
157struct acpiphp_dock_station {
158 acpi_handle handle;
159 u32 last_dock_time;
160 u32 flags;
161 struct acpiphp_func *dock_bridge;
162 struct list_head dependent_devices;
163 struct list_head pci_dependent_devices;
164};
165
166
163/* PCI bus bridge HID */ 167/* PCI bus bridge HID */
164#define ACPI_PCI_HOST_HID "PNP0A03" 168#define ACPI_PCI_HOST_HID "PNP0A03"
165 169
@@ -197,19 +201,27 @@ struct acpiphp_attention_info
197#define FUNC_HAS_PS1 (0x00000020) 201#define FUNC_HAS_PS1 (0x00000020)
198#define FUNC_HAS_PS2 (0x00000040) 202#define FUNC_HAS_PS2 (0x00000040)
199#define FUNC_HAS_PS3 (0x00000080) 203#define FUNC_HAS_PS3 (0x00000080)
204#define FUNC_HAS_DCK (0x00000100)
205#define FUNC_IS_DD (0x00000200)
206
207/* dock station flags */
208#define DOCK_DOCKING (0x00000001)
209#define DOCK_HAS_BRIDGE (0x00000002)
200 210
201/* function prototypes */ 211/* function prototypes */
202 212
203/* acpiphp_core.c */ 213/* acpiphp_core.c */
204extern int acpiphp_register_attention(struct acpiphp_attention_info*info); 214extern int acpiphp_register_attention(struct acpiphp_attention_info*info);
205extern int acpiphp_unregister_attention(struct acpiphp_attention_info *info); 215extern int acpiphp_unregister_attention(struct acpiphp_attention_info *info);
216extern int acpiphp_register_hotplug_slot(struct acpiphp_slot *slot);
217extern void acpiphp_unregister_hotplug_slot(struct acpiphp_slot *slot);
206 218
207/* acpiphp_glue.c */ 219/* acpiphp_glue.c */
208extern int acpiphp_glue_init (void); 220extern int acpiphp_glue_init (void);
209extern void acpiphp_glue_exit (void); 221extern void acpiphp_glue_exit (void);
210extern int acpiphp_get_num_slots (void); 222extern int acpiphp_get_num_slots (void);
211extern struct acpiphp_slot *get_slot_from_id (int id);
212typedef int (*acpiphp_callback)(struct acpiphp_slot *slot, void *data); 223typedef int (*acpiphp_callback)(struct acpiphp_slot *slot, void *data);
224void handle_hotplug_event_func(acpi_handle, u32, void*);
213 225
214extern int acpiphp_enable_slot (struct acpiphp_slot *slot); 226extern int acpiphp_enable_slot (struct acpiphp_slot *slot);
215extern int acpiphp_disable_slot (struct acpiphp_slot *slot); 227extern int acpiphp_disable_slot (struct acpiphp_slot *slot);
@@ -219,6 +231,16 @@ extern u8 acpiphp_get_latch_status (struct acpiphp_slot *slot);
219extern u8 acpiphp_get_adapter_status (struct acpiphp_slot *slot); 231extern u8 acpiphp_get_adapter_status (struct acpiphp_slot *slot);
220extern u32 acpiphp_get_address (struct acpiphp_slot *slot); 232extern u32 acpiphp_get_address (struct acpiphp_slot *slot);
221 233
234/* acpiphp_dock.c */
235extern int find_dock_station(void);
236extern void remove_dock_station(void);
237extern void add_dependent_device(struct dependent_device *new_dd);
238extern void add_pci_dependent_device(struct dependent_device *new_dd);
239extern struct dependent_device *get_dependent_device(acpi_handle handle);
240extern int is_dependent_device(acpi_handle handle);
241extern int detect_dependent_devices(acpi_handle *bridge_handle);
242extern struct dependent_device *alloc_dependent_device(acpi_handle handle);
243
222/* variables */ 244/* variables */
223extern int acpiphp_debug; 245extern int acpiphp_debug;
224 246
diff --git a/drivers/pci/hotplug/acpiphp_core.c b/drivers/pci/hotplug/acpiphp_core.c
index 60c4c38047..4f1b0da8e4 100644
--- a/drivers/pci/hotplug/acpiphp_core.c
+++ b/drivers/pci/hotplug/acpiphp_core.c
@@ -44,8 +44,6 @@
44#include "pci_hotplug.h" 44#include "pci_hotplug.h"
45#include "acpiphp.h" 45#include "acpiphp.h"
46 46
47static LIST_HEAD(slot_list);
48
49#define MY_NAME "acpiphp" 47#define MY_NAME "acpiphp"
50 48
51static int debug; 49static int debug;
@@ -341,62 +339,53 @@ static void release_slot(struct hotplug_slot *hotplug_slot)
341 kfree(slot); 339 kfree(slot);
342} 340}
343 341
344/** 342/* callback routine to initialize 'struct slot' for each slot */
345 * init_slots - initialize 'struct slot' structures for each slot 343int acpiphp_register_hotplug_slot(struct acpiphp_slot *acpiphp_slot)
346 *
347 */
348static int __init init_slots(void)
349{ 344{
350 struct slot *slot; 345 struct slot *slot;
346 struct hotplug_slot *hotplug_slot;
347 struct hotplug_slot_info *hotplug_slot_info;
351 int retval = -ENOMEM; 348 int retval = -ENOMEM;
352 int i; 349
353 350 slot = kzalloc(sizeof(*slot), GFP_KERNEL);
354 for (i = 0; i < num_slots; ++i) { 351 if (!slot)
355 slot = kmalloc(sizeof(struct slot), GFP_KERNEL); 352 goto error;
356 if (!slot) 353
357 goto error; 354 slot->hotplug_slot = kzalloc(sizeof(*hotplug_slot), GFP_KERNEL);
358 memset(slot, 0, sizeof(struct slot)); 355 if (!slot->hotplug_slot)
359 356 goto error_slot;
360 slot->hotplug_slot = kmalloc(sizeof(struct hotplug_slot), GFP_KERNEL); 357
361 if (!slot->hotplug_slot) 358 slot->hotplug_slot->info = kzalloc(sizeof(*hotplug_slot_info),
362 goto error_slot; 359 GFP_KERNEL);
363 memset(slot->hotplug_slot, 0, sizeof(struct hotplug_slot)); 360 if (!slot->hotplug_slot->info)
364 361 goto error_hpslot;
365 slot->hotplug_slot->info = kmalloc(sizeof(struct hotplug_slot_info), GFP_KERNEL); 362
366 if (!slot->hotplug_slot->info) 363 slot->hotplug_slot->name = kzalloc(SLOT_NAME_SIZE, GFP_KERNEL);
367 goto error_hpslot; 364 if (!slot->hotplug_slot->name)
368 memset(slot->hotplug_slot->info, 0, sizeof(struct hotplug_slot_info)); 365 goto error_info;
369 366
370 slot->hotplug_slot->name = kmalloc(SLOT_NAME_SIZE, GFP_KERNEL); 367 slot->hotplug_slot->private = slot;
371 if (!slot->hotplug_slot->name) 368 slot->hotplug_slot->release = &release_slot;
372 goto error_info; 369 slot->hotplug_slot->ops = &acpi_hotplug_slot_ops;
373 370
374 slot->number = i; 371 slot->acpi_slot = acpiphp_slot;
375 372 slot->hotplug_slot->info->power_status = acpiphp_get_power_status(slot->acpi_slot);
376 slot->hotplug_slot->private = slot; 373 slot->hotplug_slot->info->attention_status = 0;
377 slot->hotplug_slot->release = &release_slot; 374 slot->hotplug_slot->info->latch_status = acpiphp_get_latch_status(slot->acpi_slot);
378 slot->hotplug_slot->ops = &acpi_hotplug_slot_ops; 375 slot->hotplug_slot->info->adapter_status = acpiphp_get_adapter_status(slot->acpi_slot);
379 376 slot->hotplug_slot->info->max_bus_speed = PCI_SPEED_UNKNOWN;
380 slot->acpi_slot = get_slot_from_id(i); 377 slot->hotplug_slot->info->cur_bus_speed = PCI_SPEED_UNKNOWN;
381 slot->hotplug_slot->info->power_status = acpiphp_get_power_status(slot->acpi_slot); 378
382 slot->hotplug_slot->info->attention_status = 0; 379 acpiphp_slot->slot = slot;
383 slot->hotplug_slot->info->latch_status = acpiphp_get_latch_status(slot->acpi_slot); 380 make_slot_name(slot);
384 slot->hotplug_slot->info->adapter_status = acpiphp_get_adapter_status(slot->acpi_slot); 381
385 slot->hotplug_slot->info->max_bus_speed = PCI_SPEED_UNKNOWN; 382 retval = pci_hp_register(slot->hotplug_slot);
386 slot->hotplug_slot->info->cur_bus_speed = PCI_SPEED_UNKNOWN; 383 if (retval) {
387 384 err("pci_hp_register failed with error %d\n", retval);
388 make_slot_name(slot); 385 goto error_name;
389 386 }
390 retval = pci_hp_register(slot->hotplug_slot); 387
391 if (retval) { 388 info("Slot [%s] registered\n", slot->hotplug_slot->name);
392 err("pci_hp_register failed with error %d\n", retval);
393 goto error_name;
394 }
395
396 /* add slot to our internal list */
397 list_add(&slot->slot_list, &slot_list);
398 info("Slot [%s] registered\n", slot->hotplug_slot->name);
399 }
400 389
401 return 0; 390 return 0;
402error_name: 391error_name:
@@ -412,42 +401,51 @@ error:
412} 401}
413 402
414 403
415static void __exit cleanup_slots (void) 404void acpiphp_unregister_hotplug_slot(struct acpiphp_slot *acpiphp_slot)
416{ 405{
417 struct list_head *tmp, *n; 406 struct slot *slot = acpiphp_slot->slot;
418 struct slot *slot; 407 int retval = 0;
419 408
420 list_for_each_safe (tmp, n, &slot_list) { 409 info ("Slot [%s] unregistered\n", slot->hotplug_slot->name);
421 /* memory will be freed in release_slot callback */ 410
422 slot = list_entry(tmp, struct slot, slot_list); 411 retval = pci_hp_deregister(slot->hotplug_slot);
423 list_del(&slot->slot_list); 412 if (retval)
424 pci_hp_deregister(slot->hotplug_slot); 413 err("pci_hp_deregister failed with error %d\n", retval);
425 }
426} 414}
427 415
428 416
429static int __init acpiphp_init(void) 417static int __init acpiphp_init(void)
430{ 418{
431 int retval; 419 int retval;
420 int docking_station;
432 421
433 info(DRIVER_DESC " version: " DRIVER_VERSION "\n"); 422 info(DRIVER_DESC " version: " DRIVER_VERSION "\n");
434 423
435 acpiphp_debug = debug; 424 acpiphp_debug = debug;
436 425
426 docking_station = find_dock_station();
427
437 /* read all the ACPI info from the system */ 428 /* read all the ACPI info from the system */
438 retval = init_acpi(); 429 retval = init_acpi();
439 if (retval)
440 return retval;
441 430
442 return init_slots(); 431 /* if we have found a docking station, we should
432 * go ahead and load even if init_acpi has found
433 * no slots. This handles the case when the _DCK
434 * method not defined under the actual dock bridge
435 */
436 if (docking_station)
437 return 0;
438 else
439 return retval;
443} 440}
444 441
445 442
446static void __exit acpiphp_exit(void) 443static void __exit acpiphp_exit(void)
447{ 444{
448 cleanup_slots();
449 /* deallocate internal data structures etc. */ 445 /* deallocate internal data structures etc. */
450 acpiphp_glue_exit(); 446 acpiphp_glue_exit();
447
448 remove_dock_station();
451} 449}
452 450
453module_init(acpiphp_init); 451module_init(acpiphp_init);
diff --git a/drivers/pci/hotplug/acpiphp_dock.c b/drivers/pci/hotplug/acpiphp_dock.c
new file mode 100644
index 0000000000..4f1aaf1283
--- /dev/null
+++ b/drivers/pci/hotplug/acpiphp_dock.c
@@ -0,0 +1,438 @@
1/*
2 * ACPI PCI HotPlug dock functions to ACPI CA subsystem
3 *
4 * Copyright (C) 2006 Kristen Carlson Accardi (kristen.c.accardi@intel.com)
5 * Copyright (C) 2006 Intel Corporation
6 *
7 * All rights reserved.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or (at
12 * your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
17 * NON INFRINGEMENT. See the GNU General Public License for more
18 * 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 * Send feedback to <kristen.c.accardi@intel.com>
25 *
26 */
27#include <linux/init.h>
28#include <linux/module.h>
29
30#include <linux/kernel.h>
31#include <linux/pci.h>
32#include <linux/smp_lock.h>
33#include <linux/mutex.h>
34
35#include "../pci.h"
36#include "pci_hotplug.h"
37#include "acpiphp.h"
38
39static struct acpiphp_dock_station *ds;
40#define MY_NAME "acpiphp_dock"
41
42
43int is_dependent_device(acpi_handle handle)
44{
45 return (get_dependent_device(handle) ? 1 : 0);
46}
47
48
49static acpi_status
50find_dependent_device(acpi_handle handle, u32 lvl, void *context, void **rv)
51{
52 int *count = (int *)context;
53
54 if (is_dependent_device(handle)) {
55 (*count)++;
56 return AE_CTRL_TERMINATE;
57 } else {
58 return AE_OK;
59 }
60}
61
62
63
64
65void add_dependent_device(struct dependent_device *new_dd)
66{
67 list_add_tail(&new_dd->device_list, &ds->dependent_devices);
68}
69
70
71void add_pci_dependent_device(struct dependent_device *new_dd)
72{
73 list_add_tail(&new_dd->pci_list, &ds->pci_dependent_devices);
74}
75
76
77
78struct dependent_device * get_dependent_device(acpi_handle handle)
79{
80 struct dependent_device *dd;
81
82 if (!ds)
83 return NULL;
84
85 list_for_each_entry(dd, &ds->dependent_devices, device_list) {
86 if (handle == dd->handle)
87 return dd;
88 }
89 return NULL;
90}
91
92
93
94struct dependent_device *alloc_dependent_device(acpi_handle handle)
95{
96 struct dependent_device *dd;
97
98 dd = kzalloc(sizeof(*dd), GFP_KERNEL);
99 if (dd) {
100 INIT_LIST_HEAD(&dd->pci_list);
101 INIT_LIST_HEAD(&dd->device_list);
102 dd->handle = handle;
103 }
104 return dd;
105}
106
107
108
109static int is_dock(acpi_handle handle)
110{
111 acpi_status status;
112 acpi_handle tmp;
113
114 status = acpi_get_handle(handle, "_DCK", &tmp);
115 if (ACPI_FAILURE(status)) {
116 return 0;
117 }
118 return 1;
119}
120
121
122
123static int dock_present(void)
124{
125 unsigned long sta;
126 acpi_status status;
127
128 if (ds) {
129 status = acpi_evaluate_integer(ds->handle, "_STA", NULL, &sta);
130 if (ACPI_SUCCESS(status) && sta)
131 return 1;
132 }
133 return 0;
134}
135
136
137
138static void eject_dock(void)
139{
140 struct acpi_object_list arg_list;
141 union acpi_object arg;
142
143 arg_list.count = 1;
144 arg_list.pointer = &arg;
145 arg.type = ACPI_TYPE_INTEGER;
146 arg.integer.value = 1;
147
148 if (ACPI_FAILURE(acpi_evaluate_object(ds->handle, "_EJ0",
149 &arg_list, NULL)) || dock_present())
150 warn("%s: failed to eject dock!\n", __FUNCTION__);
151
152 return;
153}
154
155
156
157
158static acpi_status handle_dock(int dock)
159{
160 acpi_status status;
161 struct acpi_object_list arg_list;
162 union acpi_object arg;
163 struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
164
165 dbg("%s: %s\n", __FUNCTION__, dock ? "docking" : "undocking");
166
167 /* _DCK method has one argument */
168 arg_list.count = 1;
169 arg_list.pointer = &arg;
170 arg.type = ACPI_TYPE_INTEGER;
171 arg.integer.value = dock;
172 status = acpi_evaluate_object(ds->handle, "_DCK",
173 &arg_list, &buffer);
174 if (ACPI_FAILURE(status))
175 err("%s: failed to execute _DCK\n", __FUNCTION__);
176 acpi_os_free(buffer.pointer);
177
178 return status;
179}
180
181
182
183static inline void dock(void)
184{
185 handle_dock(1);
186}
187
188
189
190static inline void undock(void)
191{
192 handle_dock(0);
193}
194
195
196
197/*
198 * the _DCK method can do funny things... and sometimes not
199 * hah-hah funny.
200 *
201 * TBD - figure out a way to only call fixups for
202 * systems that require them.
203 */
204static void post_dock_fixups(void)
205{
206 struct pci_bus *bus;
207 u32 buses;
208 struct dependent_device *dd;
209
210 list_for_each_entry(dd, &ds->pci_dependent_devices, pci_list) {
211 bus = dd->func->slot->bridge->pci_bus;
212
213 /* fixup bad _DCK function that rewrites
214 * secondary bridge on slot
215 */
216 pci_read_config_dword(bus->self,
217 PCI_PRIMARY_BUS,
218 &buses);
219
220 if (((buses >> 8) & 0xff) != bus->secondary) {
221 buses = (buses & 0xff000000)
222 | ((unsigned int)(bus->primary) << 0)
223 | ((unsigned int)(bus->secondary) << 8)
224 | ((unsigned int)(bus->subordinate) << 16);
225 pci_write_config_dword(bus->self,
226 PCI_PRIMARY_BUS,
227 buses);
228 }
229 }
230}
231
232
233
234static void hotplug_pci(u32 type)
235{
236 struct dependent_device *dd;
237
238 list_for_each_entry(dd, &ds->pci_dependent_devices, pci_list)
239 handle_hotplug_event_func(dd->handle, type, dd->func);
240}
241
242
243
244static inline void begin_dock(void)
245{
246 ds->flags |= DOCK_DOCKING;
247}
248
249
250static inline void complete_dock(void)
251{
252 ds->flags &= ~(DOCK_DOCKING);
253 ds->last_dock_time = jiffies;
254}
255
256
257static int dock_in_progress(void)
258{
259 if (ds->flags & DOCK_DOCKING ||
260 ds->last_dock_time == jiffies) {
261 dbg("dock in progress\n");
262 return 1;
263 }
264 return 0;
265}
266
267
268
269static void
270handle_hotplug_event_dock(acpi_handle handle, u32 type, void *context)
271{
272 dbg("%s: enter\n", __FUNCTION__);
273
274 switch (type) {
275 case ACPI_NOTIFY_BUS_CHECK:
276 dbg("BUS Check\n");
277 if (!dock_in_progress() && dock_present()) {
278 begin_dock();
279 dock();
280 if (!dock_present()) {
281 err("Unable to dock!\n");
282 break;
283 }
284 post_dock_fixups();
285 hotplug_pci(type);
286 complete_dock();
287 }
288 break;
289 case ACPI_NOTIFY_EJECT_REQUEST:
290 dbg("EJECT request\n");
291 if (!dock_in_progress() && dock_present()) {
292 hotplug_pci(type);
293 undock();
294 eject_dock();
295 if (dock_present())
296 err("Unable to undock!\n");
297 }
298 break;
299 }
300}
301
302
303
304
305static acpi_status
306find_dock_ejd(acpi_handle handle, u32 lvl, void *context, void **rv)
307{
308 acpi_status status;
309 acpi_handle tmp;
310 acpi_handle dck_handle = (acpi_handle) context;
311 char objname[64];
312 struct acpi_buffer buffer = { .length = sizeof(objname),
313 .pointer = objname };
314 struct acpi_buffer ejd_buffer = {ACPI_ALLOCATE_BUFFER, NULL};
315 union acpi_object *ejd_obj;
316
317 status = acpi_get_handle(handle, "_EJD", &tmp);
318 if (ACPI_FAILURE(status))
319 return AE_OK;
320
321 /* make sure we are dependent on the dock device,
322 * by executing the _EJD method, then getting a handle
323 * to the device referenced by that name. If that
324 * device handle is the same handle as the dock station
325 * handle, then we are a device dependent on the dock station
326 */
327 acpi_get_name(dck_handle, ACPI_FULL_PATHNAME, &buffer);
328 status = acpi_evaluate_object(handle, "_EJD", NULL, &ejd_buffer);
329 if (ACPI_FAILURE(status)) {
330 err("Unable to execute _EJD!\n");
331 goto find_ejd_out;
332 }
333 ejd_obj = ejd_buffer.pointer;
334 status = acpi_get_handle(NULL, ejd_obj->string.pointer, &tmp);
335 if (ACPI_FAILURE(status))
336 goto find_ejd_out;
337
338 if (tmp == dck_handle) {
339 struct dependent_device *dd;
340 dbg("%s: found device dependent on dock\n", __FUNCTION__);
341 dd = alloc_dependent_device(handle);
342 if (!dd) {
343 err("Can't allocate memory for dependent device!\n");
344 goto find_ejd_out;
345 }
346 add_dependent_device(dd);
347 }
348
349find_ejd_out:
350 acpi_os_free(ejd_buffer.pointer);
351 return AE_OK;
352}
353
354
355
356int detect_dependent_devices(acpi_handle *bridge_handle)
357{
358 acpi_status status;
359 int count;
360
361 count = 0;
362
363 status = acpi_walk_namespace(ACPI_TYPE_DEVICE, bridge_handle,
364 (u32)1, find_dependent_device,
365 (void *)&count, NULL);
366
367 return count;
368}
369
370
371
372
373
374static acpi_status
375find_dock(acpi_handle handle, u32 lvl, void *context, void **rv)
376{
377 int *count = (int *)context;
378
379 if (is_dock(handle)) {
380 dbg("%s: found dock\n", __FUNCTION__);
381 ds = kzalloc(sizeof(*ds), GFP_KERNEL);
382 ds->handle = handle;
383 INIT_LIST_HEAD(&ds->dependent_devices);
384 INIT_LIST_HEAD(&ds->pci_dependent_devices);
385
386 /* look for devices dependent on dock station */
387 acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
388 ACPI_UINT32_MAX, find_dock_ejd, handle, NULL);
389
390 acpi_install_notify_handler(handle, ACPI_SYSTEM_NOTIFY,
391 handle_hotplug_event_dock, ds);
392 (*count)++;
393 }
394
395 return AE_OK;
396}
397
398
399
400
401int find_dock_station(void)
402{
403 int num = 0;
404
405 ds = NULL;
406
407 /* start from the root object, because some laptops define
408 * _DCK methods outside the scope of PCI (IBM x-series laptop)
409 */
410 acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
411 ACPI_UINT32_MAX, find_dock, &num, NULL);
412
413 return num;
414}
415
416
417
418void remove_dock_station(void)
419{
420 struct dependent_device *dd, *tmp;
421 if (ds) {
422 if (ACPI_FAILURE(acpi_remove_notify_handler(ds->handle,
423 ACPI_SYSTEM_NOTIFY, handle_hotplug_event_dock)))
424 err("failed to remove dock notify handler\n");
425
426 /* free all dependent devices */
427 list_for_each_entry_safe(dd, tmp, &ds->dependent_devices,
428 device_list)
429 kfree(dd);
430
431 /* no need to touch the pci_dependent_device list,
432 * cause all memory was freed above
433 */
434 kfree(ds);
435 }
436}
437
438
diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c
index 509a5b3ae9..053ee84386 100644
--- a/drivers/pci/hotplug/acpiphp_glue.c
+++ b/drivers/pci/hotplug/acpiphp_glue.c
@@ -46,7 +46,7 @@
46#include <linux/kernel.h> 46#include <linux/kernel.h>
47#include <linux/pci.h> 47#include <linux/pci.h>
48#include <linux/smp_lock.h> 48#include <linux/smp_lock.h>
49#include <asm/semaphore.h> 49#include <linux/mutex.h>
50 50
51#include "../pci.h" 51#include "../pci.h"
52#include "pci_hotplug.h" 52#include "pci_hotplug.h"
@@ -57,7 +57,6 @@ static LIST_HEAD(bridge_list);
57#define MY_NAME "acpiphp_glue" 57#define MY_NAME "acpiphp_glue"
58 58
59static void handle_hotplug_event_bridge (acpi_handle, u32, void *); 59static void handle_hotplug_event_bridge (acpi_handle, u32, void *);
60static void handle_hotplug_event_func (acpi_handle, u32, void *);
61static void acpiphp_sanitize_bus(struct pci_bus *bus); 60static void acpiphp_sanitize_bus(struct pci_bus *bus);
62static void acpiphp_set_hpp_values(acpi_handle handle, struct pci_bus *bus); 61static void acpiphp_set_hpp_values(acpi_handle handle, struct pci_bus *bus);
63 62
@@ -125,11 +124,11 @@ register_slot(acpi_handle handle, u32 lvl, void *context, void **rv)
125 struct acpiphp_bridge *bridge = (struct acpiphp_bridge *)context; 124 struct acpiphp_bridge *bridge = (struct acpiphp_bridge *)context;
126 struct acpiphp_slot *slot; 125 struct acpiphp_slot *slot;
127 struct acpiphp_func *newfunc; 126 struct acpiphp_func *newfunc;
127 struct dependent_device *dd;
128 acpi_handle tmp; 128 acpi_handle tmp;
129 acpi_status status = AE_OK; 129 acpi_status status = AE_OK;
130 unsigned long adr, sun; 130 unsigned long adr, sun;
131 int device, function; 131 int device, function, retval;
132 static int num_slots = 0; /* XXX if we support I/O node hotplug... */
133 132
134 status = acpi_evaluate_integer(handle, "_ADR", NULL, &adr); 133 status = acpi_evaluate_integer(handle, "_ADR", NULL, &adr);
135 134
@@ -138,21 +137,21 @@ register_slot(acpi_handle handle, u32 lvl, void *context, void **rv)
138 137
139 status = acpi_get_handle(handle, "_EJ0", &tmp); 138 status = acpi_get_handle(handle, "_EJ0", &tmp);
140 139
141 if (ACPI_FAILURE(status)) 140 if (ACPI_FAILURE(status) && !(is_dependent_device(handle)))
142 return AE_OK; 141 return AE_OK;
143 142
144 device = (adr >> 16) & 0xffff; 143 device = (adr >> 16) & 0xffff;
145 function = adr & 0xffff; 144 function = adr & 0xffff;
146 145
147 newfunc = kmalloc(sizeof(struct acpiphp_func), GFP_KERNEL); 146 newfunc = kzalloc(sizeof(struct acpiphp_func), GFP_KERNEL);
148 if (!newfunc) 147 if (!newfunc)
149 return AE_NO_MEMORY; 148 return AE_NO_MEMORY;
150 memset(newfunc, 0, sizeof(struct acpiphp_func));
151 149
152 INIT_LIST_HEAD(&newfunc->sibling); 150 INIT_LIST_HEAD(&newfunc->sibling);
153 newfunc->handle = handle; 151 newfunc->handle = handle;
154 newfunc->function = function; 152 newfunc->function = function;
155 newfunc->flags = FUNC_HAS_EJ0; 153 if (ACPI_SUCCESS(status))
154 newfunc->flags = FUNC_HAS_EJ0;
156 155
157 if (ACPI_SUCCESS(acpi_get_handle(handle, "_STA", &tmp))) 156 if (ACPI_SUCCESS(acpi_get_handle(handle, "_STA", &tmp)))
158 newfunc->flags |= FUNC_HAS_STA; 157 newfunc->flags |= FUNC_HAS_STA;
@@ -163,6 +162,19 @@ register_slot(acpi_handle handle, u32 lvl, void *context, void **rv)
163 if (ACPI_SUCCESS(acpi_get_handle(handle, "_PS3", &tmp))) 162 if (ACPI_SUCCESS(acpi_get_handle(handle, "_PS3", &tmp)))
164 newfunc->flags |= FUNC_HAS_PS3; 163 newfunc->flags |= FUNC_HAS_PS3;
165 164
165 if (ACPI_SUCCESS(acpi_get_handle(handle, "_DCK", &tmp))) {
166 newfunc->flags |= FUNC_HAS_DCK;
167 /* add to devices dependent on dock station,
168 * because this may actually be the dock bridge
169 */
170 dd = alloc_dependent_device(handle);
171 if (!dd)
172 err("Can't allocate memory for "
173 "new dependent device!\n");
174 else
175 add_dependent_device(dd);
176 }
177
166 status = acpi_evaluate_integer(handle, "_SUN", NULL, &sun); 178 status = acpi_evaluate_integer(handle, "_SUN", NULL, &sun);
167 if (ACPI_FAILURE(status)) 179 if (ACPI_FAILURE(status))
168 sun = -1; 180 sun = -1;
@@ -176,19 +188,17 @@ register_slot(acpi_handle handle, u32 lvl, void *context, void **rv)
176 } 188 }
177 189
178 if (!slot) { 190 if (!slot) {
179 slot = kmalloc(sizeof(struct acpiphp_slot), GFP_KERNEL); 191 slot = kzalloc(sizeof(struct acpiphp_slot), GFP_KERNEL);
180 if (!slot) { 192 if (!slot) {
181 kfree(newfunc); 193 kfree(newfunc);
182 return AE_NO_MEMORY; 194 return AE_NO_MEMORY;
183 } 195 }
184 196
185 memset(slot, 0, sizeof(struct acpiphp_slot));
186 slot->bridge = bridge; 197 slot->bridge = bridge;
187 slot->id = num_slots++;
188 slot->device = device; 198 slot->device = device;
189 slot->sun = sun; 199 slot->sun = sun;
190 INIT_LIST_HEAD(&slot->funcs); 200 INIT_LIST_HEAD(&slot->funcs);
191 init_MUTEX(&slot->crit_sect); 201 mutex_init(&slot->crit_sect);
192 202
193 slot->next = bridge->slots; 203 slot->next = bridge->slots;
194 bridge->slots = slot; 204 bridge->slots = slot;
@@ -198,6 +208,11 @@ register_slot(acpi_handle handle, u32 lvl, void *context, void **rv)
198 dbg("found ACPI PCI Hotplug slot %d at PCI %04x:%02x:%02x\n", 208 dbg("found ACPI PCI Hotplug slot %d at PCI %04x:%02x:%02x\n",
199 slot->sun, pci_domain_nr(bridge->pci_bus), 209 slot->sun, pci_domain_nr(bridge->pci_bus),
200 bridge->pci_bus->number, slot->device); 210 bridge->pci_bus->number, slot->device);
211 retval = acpiphp_register_hotplug_slot(slot);
212 if (retval) {
213 warn("acpiphp_register_hotplug_slot failed(err code = 0x%x)\n", retval);
214 goto err_exit;
215 }
201 } 216 }
202 217
203 newfunc->slot = slot; 218 newfunc->slot = slot;
@@ -210,16 +225,41 @@ register_slot(acpi_handle handle, u32 lvl, void *context, void **rv)
210 slot->flags |= (SLOT_ENABLED | SLOT_POWEREDON); 225 slot->flags |= (SLOT_ENABLED | SLOT_POWEREDON);
211 } 226 }
212 227
228 /* if this is a device dependent on a dock station,
229 * associate the acpiphp_func to the dependent_device
230 * struct.
231 */
232 if ((dd = get_dependent_device(handle))) {
233 newfunc->flags |= FUNC_IS_DD;
234 /*
235 * we don't want any devices which is dependent
236 * on the dock to have it's _EJ0 method executed.
237 * because we need to run _DCK first.
238 */
239 newfunc->flags &= ~FUNC_HAS_EJ0;
240 dd->func = newfunc;
241 add_pci_dependent_device(dd);
242 }
243
213 /* install notify handler */ 244 /* install notify handler */
214 status = acpi_install_notify_handler(handle, 245 if (!(newfunc->flags & FUNC_HAS_DCK)) {
246 status = acpi_install_notify_handler(handle,
215 ACPI_SYSTEM_NOTIFY, 247 ACPI_SYSTEM_NOTIFY,
216 handle_hotplug_event_func, 248 handle_hotplug_event_func,
217 newfunc); 249 newfunc);
218 250
219 if (ACPI_FAILURE(status)) { 251 if (ACPI_FAILURE(status))
220 err("failed to register interrupt notify handler\n"); 252 err("failed to register interrupt notify handler\n");
221 return status; 253 } else
222 } 254 status = AE_OK;
255
256 return status;
257
258 err_exit:
259 bridge->nr_slots--;
260 bridge->slots = slot->next;
261 kfree(slot);
262 kfree(newfunc);
223 263
224 return AE_OK; 264 return AE_OK;
225} 265}
@@ -245,57 +285,19 @@ static int detect_ejectable_slots(acpi_handle *bridge_handle)
245static void decode_hpp(struct acpiphp_bridge *bridge) 285static void decode_hpp(struct acpiphp_bridge *bridge)
246{ 286{
247 acpi_status status; 287 acpi_status status;
248 struct acpi_buffer buffer = { .length = ACPI_ALLOCATE_BUFFER,
249 .pointer = NULL};
250 union acpi_object *package;
251 int i;
252
253 /* default numbers */
254 bridge->hpp.cache_line_size = 0x10;
255 bridge->hpp.latency_timer = 0x40;
256 bridge->hpp.enable_SERR = 0;
257 bridge->hpp.enable_PERR = 0;
258
259 status = acpi_evaluate_object(bridge->handle, "_HPP", NULL, &buffer);
260 288
289 status = acpi_get_hp_params_from_firmware(bridge->pci_dev, &bridge->hpp);
261 if (ACPI_FAILURE(status)) { 290 if (ACPI_FAILURE(status)) {
262 dbg("_HPP evaluation failed\n"); 291 /* use default numbers */
263 return; 292 bridge->hpp.cache_line_size = 0x10;
293 bridge->hpp.latency_timer = 0x40;
294 bridge->hpp.enable_serr = 0;
295 bridge->hpp.enable_perr = 0;
264 } 296 }
265
266 package = (union acpi_object *) buffer.pointer;
267
268 if (!package || package->type != ACPI_TYPE_PACKAGE ||
269 package->package.count != 4 || !package->package.elements) {
270 err("invalid _HPP object; ignoring\n");
271 goto err_exit;
272 }
273
274 for (i = 0; i < 4; i++) {
275 if (package->package.elements[i].type != ACPI_TYPE_INTEGER) {
276 err("invalid _HPP parameter type; ignoring\n");
277 goto err_exit;
278 }
279 }
280
281 bridge->hpp.cache_line_size = package->package.elements[0].integer.value;
282 bridge->hpp.latency_timer = package->package.elements[1].integer.value;
283 bridge->hpp.enable_SERR = package->package.elements[2].integer.value;
284 bridge->hpp.enable_PERR = package->package.elements[3].integer.value;
285
286 dbg("_HPP parameter = (%02x, %02x, %02x, %02x)\n",
287 bridge->hpp.cache_line_size,
288 bridge->hpp.latency_timer,
289 bridge->hpp.enable_SERR,
290 bridge->hpp.enable_PERR);
291
292 bridge->flags |= BRIDGE_HAS_HPP;
293
294 err_exit:
295 kfree(buffer.pointer);
296} 297}
297 298
298 299
300
299/* initialize miscellaneous stuff for both root and PCI-to-PCI bridge */ 301/* initialize miscellaneous stuff for both root and PCI-to-PCI bridge */
300static void init_bridge_misc(struct acpiphp_bridge *bridge) 302static void init_bridge_misc(struct acpiphp_bridge *bridge)
301{ 303{
@@ -304,9 +306,16 @@ static void init_bridge_misc(struct acpiphp_bridge *bridge)
304 /* decode ACPI 2.0 _HPP (hot plug parameters) */ 306 /* decode ACPI 2.0 _HPP (hot plug parameters) */
305 decode_hpp(bridge); 307 decode_hpp(bridge);
306 308
309 /* must be added to the list prior to calling register_slot */
310 list_add(&bridge->list, &bridge_list);
311
307 /* register all slot objects under this bridge */ 312 /* register all slot objects under this bridge */
308 status = acpi_walk_namespace(ACPI_TYPE_DEVICE, bridge->handle, (u32)1, 313 status = acpi_walk_namespace(ACPI_TYPE_DEVICE, bridge->handle, (u32)1,
309 register_slot, bridge, NULL); 314 register_slot, bridge, NULL);
315 if (ACPI_FAILURE(status)) {
316 list_del(&bridge->list);
317 return;
318 }
310 319
311 /* install notify handler */ 320 /* install notify handler */
312 if (bridge->type != BRIDGE_TYPE_HOST) { 321 if (bridge->type != BRIDGE_TYPE_HOST) {
@@ -319,8 +328,6 @@ static void init_bridge_misc(struct acpiphp_bridge *bridge)
319 err("failed to register interrupt notify handler\n"); 328 err("failed to register interrupt notify handler\n");
320 } 329 }
321 } 330 }
322
323 list_add(&bridge->list, &bridge_list);
324} 331}
325 332
326 333
@@ -329,12 +336,10 @@ static void add_host_bridge(acpi_handle *handle, struct pci_bus *pci_bus)
329{ 336{
330 struct acpiphp_bridge *bridge; 337 struct acpiphp_bridge *bridge;
331 338
332 bridge = kmalloc(sizeof(struct acpiphp_bridge), GFP_KERNEL); 339 bridge = kzalloc(sizeof(struct acpiphp_bridge), GFP_KERNEL);
333 if (bridge == NULL) 340 if (bridge == NULL)
334 return; 341 return;
335 342
336 memset(bridge, 0, sizeof(struct acpiphp_bridge));
337
338 bridge->type = BRIDGE_TYPE_HOST; 343 bridge->type = BRIDGE_TYPE_HOST;
339 bridge->handle = handle; 344 bridge->handle = handle;
340 345
@@ -351,14 +356,12 @@ static void add_p2p_bridge(acpi_handle *handle, struct pci_dev *pci_dev)
351{ 356{
352 struct acpiphp_bridge *bridge; 357 struct acpiphp_bridge *bridge;
353 358
354 bridge = kmalloc(sizeof(struct acpiphp_bridge), GFP_KERNEL); 359 bridge = kzalloc(sizeof(struct acpiphp_bridge), GFP_KERNEL);
355 if (bridge == NULL) { 360 if (bridge == NULL) {
356 err("out of memory\n"); 361 err("out of memory\n");
357 return; 362 return;
358 } 363 }
359 364
360 memset(bridge, 0, sizeof(struct acpiphp_bridge));
361
362 bridge->type = BRIDGE_TYPE_P2P; 365 bridge->type = BRIDGE_TYPE_P2P;
363 bridge->handle = handle; 366 bridge->handle = handle;
364 367
@@ -410,11 +413,18 @@ find_p2p_bridge(acpi_handle handle, u32 lvl, void *context, void **rv)
410 goto out; 413 goto out;
411 414
412 /* check if this bridge has ejectable slots */ 415 /* check if this bridge has ejectable slots */
413 if (detect_ejectable_slots(handle) > 0) { 416 if ((detect_ejectable_slots(handle) > 0) ||
417 (detect_dependent_devices(handle) > 0)) {
414 dbg("found PCI-to-PCI bridge at PCI %s\n", pci_name(dev)); 418 dbg("found PCI-to-PCI bridge at PCI %s\n", pci_name(dev));
415 add_p2p_bridge(handle, dev); 419 add_p2p_bridge(handle, dev);
416 } 420 }
417 421
422 /* search P2P bridges under this p2p bridge */
423 status = acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, (u32)1,
424 find_p2p_bridge, dev->subordinate, NULL);
425 if (ACPI_FAILURE(status))
426 warn("find_p2p_bridge faied (error code = 0x%x)\n", status);
427
418 out: 428 out:
419 pci_dev_put(dev); 429 pci_dev_put(dev);
420 return AE_OK; 430 return AE_OK;
@@ -512,15 +522,19 @@ static void cleanup_bridge(struct acpiphp_bridge *bridge)
512 list_for_each_safe (list, tmp, &slot->funcs) { 522 list_for_each_safe (list, tmp, &slot->funcs) {
513 struct acpiphp_func *func; 523 struct acpiphp_func *func;
514 func = list_entry(list, struct acpiphp_func, sibling); 524 func = list_entry(list, struct acpiphp_func, sibling);
515 status = acpi_remove_notify_handler(func->handle, 525 if (!(func->flags & FUNC_HAS_DCK)) {
526 status = acpi_remove_notify_handler(func->handle,
516 ACPI_SYSTEM_NOTIFY, 527 ACPI_SYSTEM_NOTIFY,
517 handle_hotplug_event_func); 528 handle_hotplug_event_func);
518 if (ACPI_FAILURE(status)) 529 if (ACPI_FAILURE(status))
519 err("failed to remove notify handler\n"); 530 err("failed to remove notify handler\n");
531 }
520 pci_dev_put(func->pci_dev); 532 pci_dev_put(func->pci_dev);
521 list_del(list); 533 list_del(list);
522 kfree(func); 534 kfree(func);
523 } 535 }
536 acpiphp_unregister_hotplug_slot(slot);
537 list_del(&slot->funcs);
524 kfree(slot); 538 kfree(slot);
525 slot = next; 539 slot = next;
526 } 540 }
@@ -551,7 +565,8 @@ static void remove_bridge(acpi_handle handle)
551 } else { 565 } else {
552 /* clean-up p2p bridges under this host bridge */ 566 /* clean-up p2p bridges under this host bridge */
553 acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, 567 acpi_walk_namespace(ACPI_TYPE_DEVICE, handle,
554 (u32)1, cleanup_p2p_bridge, NULL, NULL); 568 ACPI_UINT32_MAX, cleanup_p2p_bridge,
569 NULL, NULL);
555 } 570 }
556} 571}
557 572
@@ -751,6 +766,113 @@ static int power_off_slot(struct acpiphp_slot *slot)
751} 766}
752 767
753 768
769
770/**
771 * acpiphp_max_busnr - return the highest reserved bus number under
772 * the given bus.
773 * @bus: bus to start search with
774 *
775 */
776static unsigned char acpiphp_max_busnr(struct pci_bus *bus)
777{
778 struct list_head *tmp;
779 unsigned char max, n;
780
781 /*
782 * pci_bus_max_busnr will return the highest
783 * reserved busnr for all these children.
784 * that is equivalent to the bus->subordinate
785 * value. We don't want to use the parent's
786 * bus->subordinate value because it could have
787 * padding in it.
788 */
789 max = bus->secondary;
790
791 list_for_each(tmp, &bus->children) {
792 n = pci_bus_max_busnr(pci_bus_b(tmp));
793 if (n > max)
794 max = n;
795 }
796 return max;
797}
798
799
800
801/**
802 * get_func - get a pointer to acpiphp_func given a slot, device
803 * @slot: slot to search
804 * @dev: pci_dev struct to match.
805 *
806 * This function will increase the reference count of pci_dev,
807 * so callers should call pci_dev_put when complete.
808 *
809 */
810static struct acpiphp_func *
811get_func(struct acpiphp_slot *slot, struct pci_dev *dev)
812{
813 struct acpiphp_func *func = NULL;
814 struct pci_bus *bus = slot->bridge->pci_bus;
815 struct pci_dev *pdev;
816
817 list_for_each_entry(func, &slot->funcs, sibling) {
818 pdev = pci_get_slot(bus, PCI_DEVFN(slot->device,
819 func->function));
820 if (pdev) {
821 if (pdev == dev)
822 break;
823 pci_dev_put(pdev);
824 }
825 }
826 return func;
827}
828
829
830/**
831 * acpiphp_bus_add - add a new bus to acpi subsystem
832 * @func: acpiphp_func of the bridge
833 *
834 */
835static int acpiphp_bus_add(struct acpiphp_func *func)
836{
837 acpi_handle phandle;
838 struct acpi_device *device, *pdevice;
839 int ret_val;
840
841 acpi_get_parent(func->handle, &phandle);
842 if (acpi_bus_get_device(phandle, &pdevice)) {
843 dbg("no parent device, assuming NULL\n");
844 pdevice = NULL;
845 }
846 if (!acpi_bus_get_device(func->handle, &device)) {
847 dbg("bus exists... trim\n");
848 /* this shouldn't be in here, so remove
849 * the bus then re-add it...
850 */
851 ret_val = acpi_bus_trim(device, 1);
852 dbg("acpi_bus_trim return %x\n", ret_val);
853 }
854
855 ret_val = acpi_bus_add(&device, pdevice, func->handle,
856 ACPI_BUS_TYPE_DEVICE);
857 if (ret_val) {
858 dbg("error adding bus, %x\n",
859 -ret_val);
860 goto acpiphp_bus_add_out;
861 }
862 /*
863 * try to start anyway. We could have failed to add
864 * simply because this bus had previously been added
865 * on another add. Don't bother with the return value
866 * we just keep going.
867 */
868 ret_val = acpi_bus_start(device);
869
870acpiphp_bus_add_out:
871 return ret_val;
872}
873
874
875
754/** 876/**
755 * enable_device - enable, configure a slot 877 * enable_device - enable, configure a slot
756 * @slot: slot to be enabled 878 * @slot: slot to be enabled
@@ -788,7 +910,7 @@ static int enable_device(struct acpiphp_slot *slot)
788 goto err_exit; 910 goto err_exit;
789 } 911 }
790 912
791 max = bus->secondary; 913 max = acpiphp_max_busnr(bus);
792 for (pass = 0; pass < 2; pass++) { 914 for (pass = 0; pass < 2; pass++) {
793 list_for_each_entry(dev, &bus->devices, bus_list) { 915 list_for_each_entry(dev, &bus->devices, bus_list) {
794 if (PCI_SLOT(dev->devfn) != slot->device) 916 if (PCI_SLOT(dev->devfn) != slot->device)
@@ -796,8 +918,15 @@ static int enable_device(struct acpiphp_slot *slot)
796 if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE || 918 if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE ||
797 dev->hdr_type == PCI_HEADER_TYPE_CARDBUS) { 919 dev->hdr_type == PCI_HEADER_TYPE_CARDBUS) {
798 max = pci_scan_bridge(bus, dev, max, pass); 920 max = pci_scan_bridge(bus, dev, max, pass);
799 if (pass && dev->subordinate) 921 if (pass && dev->subordinate) {
800 pci_bus_size_bridges(dev->subordinate); 922 pci_bus_size_bridges(dev->subordinate);
923 func = get_func(slot, dev);
924 if (func) {
925 acpiphp_bus_add(func);
926 /* side effect of get_func */
927 pci_dev_put(dev);
928 }
929 }
801 } 930 }
802 } 931 }
803 } 932 }
@@ -806,8 +935,8 @@ static int enable_device(struct acpiphp_slot *slot)
806 acpiphp_sanitize_bus(bus); 935 acpiphp_sanitize_bus(bus);
807 pci_enable_bridges(bus); 936 pci_enable_bridges(bus);
808 pci_bus_add_devices(bus); 937 pci_bus_add_devices(bus);
809 acpiphp_set_hpp_values(DEVICE_ACPI_HANDLE(&bus->self->dev), bus); 938 acpiphp_set_hpp_values(slot->bridge->handle, bus);
810 acpiphp_configure_ioapics(DEVICE_ACPI_HANDLE(&bus->self->dev)); 939 acpiphp_configure_ioapics(slot->bridge->handle);
811 940
812 /* associate pci_dev to our representation */ 941 /* associate pci_dev to our representation */
813 list_for_each (l, &slot->funcs) { 942 list_for_each (l, &slot->funcs) {
@@ -987,11 +1116,11 @@ static void program_hpp(struct pci_dev *dev, struct acpiphp_bridge *bridge)
987 pci_write_config_byte(dev, PCI_LATENCY_TIMER, 1116 pci_write_config_byte(dev, PCI_LATENCY_TIMER,
988 bridge->hpp.latency_timer); 1117 bridge->hpp.latency_timer);
989 pci_read_config_word(dev, PCI_COMMAND, &pci_cmd); 1118 pci_read_config_word(dev, PCI_COMMAND, &pci_cmd);
990 if (bridge->hpp.enable_SERR) 1119 if (bridge->hpp.enable_serr)
991 pci_cmd |= PCI_COMMAND_SERR; 1120 pci_cmd |= PCI_COMMAND_SERR;
992 else 1121 else
993 pci_cmd &= ~PCI_COMMAND_SERR; 1122 pci_cmd &= ~PCI_COMMAND_SERR;
994 if (bridge->hpp.enable_PERR) 1123 if (bridge->hpp.enable_perr)
995 pci_cmd |= PCI_COMMAND_PARITY; 1124 pci_cmd |= PCI_COMMAND_PARITY;
996 else 1125 else
997 pci_cmd &= ~PCI_COMMAND_PARITY; 1126 pci_cmd &= ~PCI_COMMAND_PARITY;
@@ -1002,11 +1131,11 @@ static void program_hpp(struct pci_dev *dev, struct acpiphp_bridge *bridge)
1002 pci_write_config_byte(dev, PCI_SEC_LATENCY_TIMER, 1131 pci_write_config_byte(dev, PCI_SEC_LATENCY_TIMER,
1003 bridge->hpp.latency_timer); 1132 bridge->hpp.latency_timer);
1004 pci_read_config_word(dev, PCI_BRIDGE_CONTROL, &pci_bctl); 1133 pci_read_config_word(dev, PCI_BRIDGE_CONTROL, &pci_bctl);
1005 if (bridge->hpp.enable_SERR) 1134 if (bridge->hpp.enable_serr)
1006 pci_bctl |= PCI_BRIDGE_CTL_SERR; 1135 pci_bctl |= PCI_BRIDGE_CTL_SERR;
1007 else 1136 else
1008 pci_bctl &= ~PCI_BRIDGE_CTL_SERR; 1137 pci_bctl &= ~PCI_BRIDGE_CTL_SERR;
1009 if (bridge->hpp.enable_PERR) 1138 if (bridge->hpp.enable_perr)
1010 pci_bctl |= PCI_BRIDGE_CTL_PARITY; 1139 pci_bctl |= PCI_BRIDGE_CTL_PARITY;
1011 else 1140 else
1012 pci_bctl &= ~PCI_BRIDGE_CTL_PARITY; 1141 pci_bctl &= ~PCI_BRIDGE_CTL_PARITY;
@@ -1026,6 +1155,7 @@ static void acpiphp_set_hpp_values(acpi_handle handle, struct pci_bus *bus)
1026 1155
1027 memset(&bridge, 0, sizeof(bridge)); 1156 memset(&bridge, 0, sizeof(bridge));
1028 bridge.handle = handle; 1157 bridge.handle = handle;
1158 bridge.pci_dev = bus->self;
1029 decode_hpp(&bridge); 1159 decode_hpp(&bridge);
1030 list_for_each_entry(dev, &bus->devices, bus_list) 1160 list_for_each_entry(dev, &bus->devices, bus_list)
1031 program_hpp(dev, &bridge); 1161 program_hpp(dev, &bridge);
@@ -1200,7 +1330,7 @@ static void handle_hotplug_event_bridge(acpi_handle handle, u32 type, void *cont
1200 * handles ACPI event notification on slots 1330 * handles ACPI event notification on slots
1201 * 1331 *
1202 */ 1332 */
1203static void handle_hotplug_event_func(acpi_handle handle, u32 type, void *context) 1333void handle_hotplug_event_func(acpi_handle handle, u32 type, void *context)
1204{ 1334{
1205 struct acpiphp_func *func; 1335 struct acpiphp_func *func;
1206 char objname[64]; 1336 char objname[64];
@@ -1242,41 +1372,13 @@ static void handle_hotplug_event_func(acpi_handle handle, u32 type, void *contex
1242 } 1372 }
1243} 1373}
1244 1374
1245static int is_root_bridge(acpi_handle handle)
1246{
1247 acpi_status status;
1248 struct acpi_device_info *info;
1249 struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
1250 int i;
1251
1252 status = acpi_get_object_info(handle, &buffer);
1253 if (ACPI_SUCCESS(status)) {
1254 info = buffer.pointer;
1255 if ((info->valid & ACPI_VALID_HID) &&
1256 !strcmp(PCI_ROOT_HID_STRING,
1257 info->hardware_id.value)) {
1258 acpi_os_free(buffer.pointer);
1259 return 1;
1260 }
1261 if (info->valid & ACPI_VALID_CID) {
1262 for (i=0; i < info->compatibility_id.count; i++) {
1263 if (!strcmp(PCI_ROOT_HID_STRING,
1264 info->compatibility_id.id[i].value)) {
1265 acpi_os_free(buffer.pointer);
1266 return 1;
1267 }
1268 }
1269 }
1270 }
1271 return 0;
1272}
1273 1375
1274static acpi_status 1376static acpi_status
1275find_root_bridges(acpi_handle handle, u32 lvl, void *context, void **rv) 1377find_root_bridges(acpi_handle handle, u32 lvl, void *context, void **rv)
1276{ 1378{
1277 int *count = (int *)context; 1379 int *count = (int *)context;
1278 1380
1279 if (is_root_bridge(handle)) { 1381 if (acpi_root_bridge(handle)) {
1280 acpi_install_notify_handler(handle, ACPI_SYSTEM_NOTIFY, 1382 acpi_install_notify_handler(handle, ACPI_SYSTEM_NOTIFY,
1281 handle_hotplug_event_bridge, NULL); 1383 handle_hotplug_event_bridge, NULL);
1282 (*count)++; 1384 (*count)++;
@@ -1373,26 +1475,6 @@ static int acpiphp_for_each_slot(acpiphp_callback fn, void *data)
1373} 1475}
1374#endif 1476#endif
1375 1477
1376/* search matching slot from id */
1377struct acpiphp_slot *get_slot_from_id(int id)
1378{
1379 struct list_head *node;
1380 struct acpiphp_bridge *bridge;
1381 struct acpiphp_slot *slot;
1382
1383 list_for_each (node, &bridge_list) {
1384 bridge = (struct acpiphp_bridge *)node;
1385 for (slot = bridge->slots; slot; slot = slot->next)
1386 if (slot->id == id)
1387 return slot;
1388 }
1389
1390 /* should never happen! */
1391 err("%s: no object for id %d\n", __FUNCTION__, id);
1392 WARN_ON(1);
1393 return NULL;
1394}
1395
1396 1478
1397/** 1479/**
1398 * acpiphp_enable_slot - power on slot 1480 * acpiphp_enable_slot - power on slot
@@ -1401,7 +1483,7 @@ int acpiphp_enable_slot(struct acpiphp_slot *slot)
1401{ 1483{
1402 int retval; 1484 int retval;
1403 1485
1404 down(&slot->crit_sect); 1486 mutex_lock(&slot->crit_sect);
1405 1487
1406 /* wake up all functions */ 1488 /* wake up all functions */
1407 retval = power_on_slot(slot); 1489 retval = power_on_slot(slot);
@@ -1413,7 +1495,7 @@ int acpiphp_enable_slot(struct acpiphp_slot *slot)
1413 retval = enable_device(slot); 1495 retval = enable_device(slot);
1414 1496
1415 err_exit: 1497 err_exit:
1416 up(&slot->crit_sect); 1498 mutex_unlock(&slot->crit_sect);
1417 return retval; 1499 return retval;
1418} 1500}
1419 1501
@@ -1424,7 +1506,7 @@ int acpiphp_disable_slot(struct acpiphp_slot *slot)
1424{ 1506{
1425 int retval = 0; 1507 int retval = 0;
1426 1508
1427 down(&slot->crit_sect); 1509 mutex_lock(&slot->crit_sect);
1428 1510
1429 /* unconfigure all functions */ 1511 /* unconfigure all functions */
1430 retval = disable_device(slot); 1512 retval = disable_device(slot);
@@ -1437,7 +1519,7 @@ int acpiphp_disable_slot(struct acpiphp_slot *slot)
1437 goto err_exit; 1519 goto err_exit;
1438 1520
1439 err_exit: 1521 err_exit:
1440 up(&slot->crit_sect); 1522 mutex_unlock(&slot->crit_sect);
1441 return retval; 1523 return retval;
1442} 1524}
1443 1525
diff --git a/drivers/pci/hotplug/cpci_hotplug_core.c b/drivers/pci/hotplug/cpci_hotplug_core.c
index 30af105271..037ce4c916 100644
--- a/drivers/pci/hotplug/cpci_hotplug_core.c
+++ b/drivers/pci/hotplug/cpci_hotplug_core.c
@@ -248,22 +248,19 @@ cpci_hp_register_bus(struct pci_bus *bus, u8 first, u8 last)
248 * with the pci_hotplug subsystem. 248 * with the pci_hotplug subsystem.
249 */ 249 */
250 for (i = first; i <= last; ++i) { 250 for (i = first; i <= last; ++i) {
251 slot = kmalloc(sizeof (struct slot), GFP_KERNEL); 251 slot = kzalloc(sizeof (struct slot), GFP_KERNEL);
252 if (!slot) 252 if (!slot)
253 goto error; 253 goto error;
254 memset(slot, 0, sizeof (struct slot));
255 254
256 hotplug_slot = 255 hotplug_slot =
257 kmalloc(sizeof (struct hotplug_slot), GFP_KERNEL); 256 kzalloc(sizeof (struct hotplug_slot), GFP_KERNEL);
258 if (!hotplug_slot) 257 if (!hotplug_slot)
259 goto error_slot; 258 goto error_slot;
260 memset(hotplug_slot, 0, sizeof (struct hotplug_slot));
261 slot->hotplug_slot = hotplug_slot; 259 slot->hotplug_slot = hotplug_slot;
262 260
263 info = kmalloc(sizeof (struct hotplug_slot_info), GFP_KERNEL); 261 info = kzalloc(sizeof (struct hotplug_slot_info), GFP_KERNEL);
264 if (!info) 262 if (!info)
265 goto error_hpslot; 263 goto error_hpslot;
266 memset(info, 0, sizeof (struct hotplug_slot_info));
267 hotplug_slot->info = info; 264 hotplug_slot->info = info;
268 265
269 name = kmalloc(SLOT_NAME_SIZE, GFP_KERNEL); 266 name = kmalloc(SLOT_NAME_SIZE, GFP_KERNEL);
diff --git a/drivers/pci/hotplug/cpqphp.h b/drivers/pci/hotplug/cpqphp.h
index cb88404c89..c74e9e37e7 100644
--- a/drivers/pci/hotplug/cpqphp.h
+++ b/drivers/pci/hotplug/cpqphp.h
@@ -32,6 +32,7 @@
32#include <linux/interrupt.h> 32#include <linux/interrupt.h>
33#include <asm/io.h> /* for read? and write? functions */ 33#include <asm/io.h> /* for read? and write? functions */
34#include <linux/delay.h> /* for delays */ 34#include <linux/delay.h> /* for delays */
35#include <linux/mutex.h>
35 36
36#define MY_NAME "cpqphp" 37#define MY_NAME "cpqphp"
37 38
@@ -286,7 +287,7 @@ struct event_info {
286struct controller { 287struct controller {
287 struct controller *next; 288 struct controller *next;
288 u32 ctrl_int_comp; 289 u32 ctrl_int_comp;
289 struct semaphore crit_sect; /* critical section semaphore */ 290 struct mutex crit_sect; /* critical section mutex */
290 void __iomem *hpc_reg; /* cookie for our pci controller location */ 291 void __iomem *hpc_reg; /* cookie for our pci controller location */
291 struct pci_resource *mem_head; 292 struct pci_resource *mem_head;
292 struct pci_resource *p_mem_head; 293 struct pci_resource *p_mem_head;
diff --git a/drivers/pci/hotplug/cpqphp_core.c b/drivers/pci/hotplug/cpqphp_core.c
index b3659ffcca..9bc1deb8df 100644
--- a/drivers/pci/hotplug/cpqphp_core.c
+++ b/drivers/pci/hotplug/cpqphp_core.c
@@ -347,26 +347,22 @@ static int ctrl_slot_setup(struct controller *ctrl,
347 slot_number = ctrl->first_slot; 347 slot_number = ctrl->first_slot;
348 348
349 while (number_of_slots) { 349 while (number_of_slots) {
350 slot = kmalloc(sizeof(*slot), GFP_KERNEL); 350 slot = kzalloc(sizeof(*slot), GFP_KERNEL);
351 if (!slot) 351 if (!slot)
352 goto error; 352 goto error;
353 353
354 memset(slot, 0, sizeof(struct slot)); 354 slot->hotplug_slot = kzalloc(sizeof(*(slot->hotplug_slot)),
355 slot->hotplug_slot = kmalloc(sizeof(*(slot->hotplug_slot)),
356 GFP_KERNEL); 355 GFP_KERNEL);
357 if (!slot->hotplug_slot) 356 if (!slot->hotplug_slot)
358 goto error_slot; 357 goto error_slot;
359 hotplug_slot = slot->hotplug_slot; 358 hotplug_slot = slot->hotplug_slot;
360 memset(hotplug_slot, 0, sizeof(struct hotplug_slot));
361 359
362 hotplug_slot->info = 360 hotplug_slot->info =
363 kmalloc(sizeof(*(hotplug_slot->info)), 361 kzalloc(sizeof(*(hotplug_slot->info)),
364 GFP_KERNEL); 362 GFP_KERNEL);
365 if (!hotplug_slot->info) 363 if (!hotplug_slot->info)
366 goto error_hpslot; 364 goto error_hpslot;
367 hotplug_slot_info = hotplug_slot->info; 365 hotplug_slot_info = hotplug_slot->info;
368 memset(hotplug_slot_info, 0,
369 sizeof(struct hotplug_slot_info));
370 hotplug_slot->name = kmalloc(SLOT_NAME_SIZE, GFP_KERNEL); 366 hotplug_slot->name = kmalloc(SLOT_NAME_SIZE, GFP_KERNEL);
371 367
372 if (!hotplug_slot->name) 368 if (!hotplug_slot->name)
@@ -599,7 +595,7 @@ cpqhp_set_attention_status(struct controller *ctrl, struct pci_func *func,
599 hp_slot = func->device - ctrl->slot_device_offset; 595 hp_slot = func->device - ctrl->slot_device_offset;
600 596
601 // Wait for exclusive access to hardware 597 // Wait for exclusive access to hardware
602 down(&ctrl->crit_sect); 598 mutex_lock(&ctrl->crit_sect);
603 599
604 if (status == 1) { 600 if (status == 1) {
605 amber_LED_on (ctrl, hp_slot); 601 amber_LED_on (ctrl, hp_slot);
@@ -607,7 +603,7 @@ cpqhp_set_attention_status(struct controller *ctrl, struct pci_func *func,
607 amber_LED_off (ctrl, hp_slot); 603 amber_LED_off (ctrl, hp_slot);
608 } else { 604 } else {
609 // Done with exclusive hardware access 605 // Done with exclusive hardware access
610 up(&ctrl->crit_sect); 606 mutex_unlock(&ctrl->crit_sect);
611 return(1); 607 return(1);
612 } 608 }
613 609
@@ -617,7 +613,7 @@ cpqhp_set_attention_status(struct controller *ctrl, struct pci_func *func,
617 wait_for_ctrl_irq (ctrl); 613 wait_for_ctrl_irq (ctrl);
618 614
619 // Done with exclusive hardware access 615 // Done with exclusive hardware access
620 up(&ctrl->crit_sect); 616 mutex_unlock(&ctrl->crit_sect);
621 617
622 return(0); 618 return(0);
623} 619}
@@ -854,13 +850,12 @@ static int cpqhpc_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
854 goto err_disable_device; 850 goto err_disable_device;
855 } 851 }
856 852
857 ctrl = (struct controller *) kmalloc(sizeof(struct controller), GFP_KERNEL); 853 ctrl = kzalloc(sizeof(struct controller), GFP_KERNEL);
858 if (!ctrl) { 854 if (!ctrl) {
859 err("%s : out of memory\n", __FUNCTION__); 855 err("%s : out of memory\n", __FUNCTION__);
860 rc = -ENOMEM; 856 rc = -ENOMEM;
861 goto err_disable_device; 857 goto err_disable_device;
862 } 858 }
863 memset(ctrl, 0, sizeof(struct controller));
864 859
865 rc = pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &subsystem_deviceid); 860 rc = pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &subsystem_deviceid);
866 if (rc) { 861 if (rc) {
@@ -1084,7 +1079,7 @@ static int cpqhpc_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1084 dbg("bus device function rev: %d %d %d %d\n", ctrl->bus, 1079 dbg("bus device function rev: %d %d %d %d\n", ctrl->bus,
1085 PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn), ctrl->rev); 1080 PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn), ctrl->rev);
1086 1081
1087 init_MUTEX(&ctrl->crit_sect); 1082 mutex_init(&ctrl->crit_sect);
1088 init_waitqueue_head(&ctrl->queue); 1083 init_waitqueue_head(&ctrl->queue);
1089 1084
1090 /* initialize our threads if they haven't already been started up */ 1085 /* initialize our threads if they haven't already been started up */
@@ -1223,7 +1218,7 @@ static int cpqhpc_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1223 1218
1224 // turn off empty slots here unless command line option "ON" set 1219 // turn off empty slots here unless command line option "ON" set
1225 // Wait for exclusive access to hardware 1220 // Wait for exclusive access to hardware
1226 down(&ctrl->crit_sect); 1221 mutex_lock(&ctrl->crit_sect);
1227 1222
1228 num_of_slots = readb(ctrl->hpc_reg + SLOT_MASK) & 0x0F; 1223 num_of_slots = readb(ctrl->hpc_reg + SLOT_MASK) & 0x0F;
1229 1224
@@ -1270,12 +1265,12 @@ static int cpqhpc_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1270 rc = init_SERR(ctrl); 1265 rc = init_SERR(ctrl);
1271 if (rc) { 1266 if (rc) {
1272 err("init_SERR failed\n"); 1267 err("init_SERR failed\n");
1273 up(&ctrl->crit_sect); 1268 mutex_unlock(&ctrl->crit_sect);
1274 goto err_free_irq; 1269 goto err_free_irq;
1275 } 1270 }
1276 1271
1277 // Done with exclusive hardware access 1272 // Done with exclusive hardware access
1278 up(&ctrl->crit_sect); 1273 mutex_unlock(&ctrl->crit_sect);
1279 1274
1280 cpqhp_create_debugfs_files(ctrl); 1275 cpqhp_create_debugfs_files(ctrl);
1281 1276
diff --git a/drivers/pci/hotplug/cpqphp_ctrl.c b/drivers/pci/hotplug/cpqphp_ctrl.c
index 771ed34b18..55d2dc7e39 100644
--- a/drivers/pci/hotplug/cpqphp_ctrl.c
+++ b/drivers/pci/hotplug/cpqphp_ctrl.c
@@ -1282,9 +1282,7 @@ static u32 board_replaced(struct pci_func *func, struct controller *ctrl)
1282 u8 hp_slot; 1282 u8 hp_slot;
1283 u8 temp_byte; 1283 u8 temp_byte;
1284 u8 adapter_speed; 1284 u8 adapter_speed;
1285 u32 index;
1286 u32 rc = 0; 1285 u32 rc = 0;
1287 u32 src = 8;
1288 1286
1289 hp_slot = func->device - ctrl->slot_device_offset; 1287 hp_slot = func->device - ctrl->slot_device_offset;
1290 1288
@@ -1299,7 +1297,7 @@ static u32 board_replaced(struct pci_func *func, struct controller *ctrl)
1299 **********************************/ 1297 **********************************/
1300 rc = CARD_FUNCTIONING; 1298 rc = CARD_FUNCTIONING;
1301 } else { 1299 } else {
1302 down(&ctrl->crit_sect); 1300 mutex_lock(&ctrl->crit_sect);
1303 1301
1304 /* turn on board without attaching to the bus */ 1302 /* turn on board without attaching to the bus */
1305 enable_slot_power (ctrl, hp_slot); 1303 enable_slot_power (ctrl, hp_slot);
@@ -1333,12 +1331,12 @@ static u32 board_replaced(struct pci_func *func, struct controller *ctrl)
1333 /* Wait for SOBS to be unset */ 1331 /* Wait for SOBS to be unset */
1334 wait_for_ctrl_irq (ctrl); 1332 wait_for_ctrl_irq (ctrl);
1335 1333
1336 up(&ctrl->crit_sect); 1334 mutex_unlock(&ctrl->crit_sect);
1337 1335
1338 if (rc) 1336 if (rc)
1339 return rc; 1337 return rc;
1340 1338
1341 down(&ctrl->crit_sect); 1339 mutex_lock(&ctrl->crit_sect);
1342 1340
1343 slot_enable (ctrl, hp_slot); 1341 slot_enable (ctrl, hp_slot);
1344 green_LED_blink (ctrl, hp_slot); 1342 green_LED_blink (ctrl, hp_slot);
@@ -1350,7 +1348,7 @@ static u32 board_replaced(struct pci_func *func, struct controller *ctrl)
1350 /* Wait for SOBS to be unset */ 1348 /* Wait for SOBS to be unset */
1351 wait_for_ctrl_irq (ctrl); 1349 wait_for_ctrl_irq (ctrl);
1352 1350
1353 up(&ctrl->crit_sect); 1351 mutex_unlock(&ctrl->crit_sect);
1354 1352
1355 /* Wait for ~1 second because of hot plug spec */ 1353 /* Wait for ~1 second because of hot plug spec */
1356 long_delay(1*HZ); 1354 long_delay(1*HZ);
@@ -1368,76 +1366,30 @@ static u32 board_replaced(struct pci_func *func, struct controller *ctrl)
1368 1366
1369 rc = cpqhp_configure_board(ctrl, func); 1367 rc = cpqhp_configure_board(ctrl, func);
1370 1368
1371 if (rc || src) { 1369 /* If configuration fails, turn it off
1372 /* If configuration fails, turn it off 1370 * Get slot won't work for devices behind
1373 * Get slot won't work for devices behind 1371 * bridges, but in this case it will always be
1374 * bridges, but in this case it will always be 1372 * called for the "base" bus/dev/func of an
1375 * called for the "base" bus/dev/func of an 1373 * adapter. */
1376 * adapter. */
1377 1374
1378 down(&ctrl->crit_sect); 1375 mutex_lock(&ctrl->crit_sect);
1379 1376
1380 amber_LED_on (ctrl, hp_slot); 1377 amber_LED_on (ctrl, hp_slot);
1381 green_LED_off (ctrl, hp_slot); 1378 green_LED_off (ctrl, hp_slot);
1382 slot_disable (ctrl, hp_slot); 1379 slot_disable (ctrl, hp_slot);
1383
1384 set_SOGO(ctrl);
1385
1386 /* Wait for SOBS to be unset */
1387 wait_for_ctrl_irq (ctrl);
1388
1389 up(&ctrl->crit_sect);
1390
1391 if (rc)
1392 return rc;
1393 else
1394 return 1;
1395 }
1396
1397 func->status = 0;
1398 func->switch_save = 0x10;
1399
1400 index = 1;
1401 while (((func = cpqhp_slot_find(func->bus, func->device, index)) != NULL) && !rc) {
1402 rc |= cpqhp_configure_board(ctrl, func);
1403 index++;
1404 }
1405
1406 if (rc) {
1407 /* If configuration fails, turn it off
1408 * Get slot won't work for devices behind
1409 * bridges, but in this case it will always be
1410 * called for the "base" bus/dev/func of an
1411 * adapter. */
1412
1413 down(&ctrl->crit_sect);
1414
1415 amber_LED_on (ctrl, hp_slot);
1416 green_LED_off (ctrl, hp_slot);
1417 slot_disable (ctrl, hp_slot);
1418
1419 set_SOGO(ctrl);
1420
1421 /* Wait for SOBS to be unset */
1422 wait_for_ctrl_irq (ctrl);
1423
1424 up(&ctrl->crit_sect);
1425
1426 return rc;
1427 }
1428 /* Done configuring so turn LED on full time */
1429
1430 down(&ctrl->crit_sect);
1431
1432 green_LED_on (ctrl, hp_slot);
1433 1380
1434 set_SOGO(ctrl); 1381 set_SOGO(ctrl);
1435 1382
1436 /* Wait for SOBS to be unset */ 1383 /* Wait for SOBS to be unset */
1437 wait_for_ctrl_irq (ctrl); 1384 wait_for_ctrl_irq (ctrl);
1438 1385
1439 up(&ctrl->crit_sect); 1386 mutex_unlock(&ctrl->crit_sect);
1440 rc = 0; 1387
1388 if (rc)
1389 return rc;
1390 else
1391 return 1;
1392
1441 } else { 1393 } else {
1442 /* Something is wrong 1394 /* Something is wrong
1443 1395
@@ -1445,7 +1397,7 @@ static u32 board_replaced(struct pci_func *func, struct controller *ctrl)
1445 * in this case it will always be called for the "base" 1397 * in this case it will always be called for the "base"
1446 * bus/dev/func of an adapter. */ 1398 * bus/dev/func of an adapter. */
1447 1399
1448 down(&ctrl->crit_sect); 1400 mutex_lock(&ctrl->crit_sect);
1449 1401
1450 amber_LED_on (ctrl, hp_slot); 1402 amber_LED_on (ctrl, hp_slot);
1451 green_LED_off (ctrl, hp_slot); 1403 green_LED_off (ctrl, hp_slot);
@@ -1456,7 +1408,7 @@ static u32 board_replaced(struct pci_func *func, struct controller *ctrl)
1456 /* Wait for SOBS to be unset */ 1408 /* Wait for SOBS to be unset */
1457 wait_for_ctrl_irq (ctrl); 1409 wait_for_ctrl_irq (ctrl);
1458 1410
1459 up(&ctrl->crit_sect); 1411 mutex_unlock(&ctrl->crit_sect);
1460 } 1412 }
1461 1413
1462 } 1414 }
@@ -1488,7 +1440,7 @@ static u32 board_added(struct pci_func *func, struct controller *ctrl)
1488 dbg("%s: func->device, slot_offset, hp_slot = %d, %d ,%d\n", 1440 dbg("%s: func->device, slot_offset, hp_slot = %d, %d ,%d\n",
1489 __FUNCTION__, func->device, ctrl->slot_device_offset, hp_slot); 1441 __FUNCTION__, func->device, ctrl->slot_device_offset, hp_slot);
1490 1442
1491 down(&ctrl->crit_sect); 1443 mutex_lock(&ctrl->crit_sect);
1492 1444
1493 /* turn on board without attaching to the bus */ 1445 /* turn on board without attaching to the bus */
1494 enable_slot_power(ctrl, hp_slot); 1446 enable_slot_power(ctrl, hp_slot);
@@ -1522,7 +1474,7 @@ static u32 board_added(struct pci_func *func, struct controller *ctrl)
1522 /* Wait for SOBS to be unset */ 1474 /* Wait for SOBS to be unset */
1523 wait_for_ctrl_irq(ctrl); 1475 wait_for_ctrl_irq(ctrl);
1524 1476
1525 up(&ctrl->crit_sect); 1477 mutex_unlock(&ctrl->crit_sect);
1526 1478
1527 if (rc) 1479 if (rc)
1528 return rc; 1480 return rc;
@@ -1532,7 +1484,7 @@ static u32 board_added(struct pci_func *func, struct controller *ctrl)
1532 /* turn on board and blink green LED */ 1484 /* turn on board and blink green LED */
1533 1485
1534 dbg("%s: before down\n", __FUNCTION__); 1486 dbg("%s: before down\n", __FUNCTION__);
1535 down(&ctrl->crit_sect); 1487 mutex_lock(&ctrl->crit_sect);
1536 dbg("%s: after down\n", __FUNCTION__); 1488 dbg("%s: after down\n", __FUNCTION__);
1537 1489
1538 dbg("%s: before slot_enable\n", __FUNCTION__); 1490 dbg("%s: before slot_enable\n", __FUNCTION__);
@@ -1553,7 +1505,7 @@ static u32 board_added(struct pci_func *func, struct controller *ctrl)
1553 dbg("%s: after wait_for_ctrl_irq\n", __FUNCTION__); 1505 dbg("%s: after wait_for_ctrl_irq\n", __FUNCTION__);
1554 1506
1555 dbg("%s: before up\n", __FUNCTION__); 1507 dbg("%s: before up\n", __FUNCTION__);
1556 up(&ctrl->crit_sect); 1508 mutex_unlock(&ctrl->crit_sect);
1557 dbg("%s: after up\n", __FUNCTION__); 1509 dbg("%s: after up\n", __FUNCTION__);
1558 1510
1559 /* Wait for ~1 second because of hot plug spec */ 1511 /* Wait for ~1 second because of hot plug spec */
@@ -1607,7 +1559,7 @@ static u32 board_added(struct pci_func *func, struct controller *ctrl)
1607 cpqhp_resource_sort_and_combine(&(ctrl->bus_head)); 1559 cpqhp_resource_sort_and_combine(&(ctrl->bus_head));
1608 1560
1609 if (rc) { 1561 if (rc) {
1610 down(&ctrl->crit_sect); 1562 mutex_lock(&ctrl->crit_sect);
1611 1563
1612 amber_LED_on (ctrl, hp_slot); 1564 amber_LED_on (ctrl, hp_slot);
1613 green_LED_off (ctrl, hp_slot); 1565 green_LED_off (ctrl, hp_slot);
@@ -1618,7 +1570,7 @@ static u32 board_added(struct pci_func *func, struct controller *ctrl)
1618 /* Wait for SOBS to be unset */ 1570 /* Wait for SOBS to be unset */
1619 wait_for_ctrl_irq (ctrl); 1571 wait_for_ctrl_irq (ctrl);
1620 1572
1621 up(&ctrl->crit_sect); 1573 mutex_unlock(&ctrl->crit_sect);
1622 return rc; 1574 return rc;
1623 } else { 1575 } else {
1624 cpqhp_save_slot_config(ctrl, func); 1576 cpqhp_save_slot_config(ctrl, func);
@@ -1640,7 +1592,7 @@ static u32 board_added(struct pci_func *func, struct controller *ctrl)
1640 } 1592 }
1641 } while (new_slot); 1593 } while (new_slot);
1642 1594
1643 down(&ctrl->crit_sect); 1595 mutex_lock(&ctrl->crit_sect);
1644 1596
1645 green_LED_on (ctrl, hp_slot); 1597 green_LED_on (ctrl, hp_slot);
1646 1598
@@ -1649,9 +1601,9 @@ static u32 board_added(struct pci_func *func, struct controller *ctrl)
1649 /* Wait for SOBS to be unset */ 1601 /* Wait for SOBS to be unset */
1650 wait_for_ctrl_irq (ctrl); 1602 wait_for_ctrl_irq (ctrl);
1651 1603
1652 up(&ctrl->crit_sect); 1604 mutex_unlock(&ctrl->crit_sect);
1653 } else { 1605 } else {
1654 down(&ctrl->crit_sect); 1606 mutex_lock(&ctrl->crit_sect);
1655 1607
1656 amber_LED_on (ctrl, hp_slot); 1608 amber_LED_on (ctrl, hp_slot);
1657 green_LED_off (ctrl, hp_slot); 1609 green_LED_off (ctrl, hp_slot);
@@ -1662,7 +1614,7 @@ static u32 board_added(struct pci_func *func, struct controller *ctrl)
1662 /* Wait for SOBS to be unset */ 1614 /* Wait for SOBS to be unset */
1663 wait_for_ctrl_irq (ctrl); 1615 wait_for_ctrl_irq (ctrl);
1664 1616
1665 up(&ctrl->crit_sect); 1617 mutex_unlock(&ctrl->crit_sect);
1666 1618
1667 return rc; 1619 return rc;
1668 } 1620 }
@@ -1721,7 +1673,7 @@ static u32 remove_board(struct pci_func * func, u32 replace_flag, struct control
1721 func->status = 0x01; 1673 func->status = 0x01;
1722 func->configured = 0; 1674 func->configured = 0;
1723 1675
1724 down(&ctrl->crit_sect); 1676 mutex_lock(&ctrl->crit_sect);
1725 1677
1726 green_LED_off (ctrl, hp_slot); 1678 green_LED_off (ctrl, hp_slot);
1727 slot_disable (ctrl, hp_slot); 1679 slot_disable (ctrl, hp_slot);
@@ -1736,7 +1688,7 @@ static u32 remove_board(struct pci_func * func, u32 replace_flag, struct control
1736 /* Wait for SOBS to be unset */ 1688 /* Wait for SOBS to be unset */
1737 wait_for_ctrl_irq (ctrl); 1689 wait_for_ctrl_irq (ctrl);
1738 1690
1739 up(&ctrl->crit_sect); 1691 mutex_unlock(&ctrl->crit_sect);
1740 1692
1741 if (!replace_flag && ctrl->add_support) { 1693 if (!replace_flag && ctrl->add_support) {
1742 while (func) { 1694 while (func) {
@@ -1899,7 +1851,7 @@ static void interrupt_event_handler(struct controller *ctrl)
1899 dbg("button cancel\n"); 1851 dbg("button cancel\n");
1900 del_timer(&p_slot->task_event); 1852 del_timer(&p_slot->task_event);
1901 1853
1902 down(&ctrl->crit_sect); 1854 mutex_lock(&ctrl->crit_sect);
1903 1855
1904 if (p_slot->state == BLINKINGOFF_STATE) { 1856 if (p_slot->state == BLINKINGOFF_STATE) {
1905 /* slot is on */ 1857 /* slot is on */
@@ -1922,7 +1874,7 @@ static void interrupt_event_handler(struct controller *ctrl)
1922 /* Wait for SOBS to be unset */ 1874 /* Wait for SOBS to be unset */
1923 wait_for_ctrl_irq (ctrl); 1875 wait_for_ctrl_irq (ctrl);
1924 1876
1925 up(&ctrl->crit_sect); 1877 mutex_unlock(&ctrl->crit_sect);
1926 } 1878 }
1927 /*** button Released (No action on press...) */ 1879 /*** button Released (No action on press...) */
1928 else if (ctrl->event_queue[loop].event_type == INT_BUTTON_RELEASE) { 1880 else if (ctrl->event_queue[loop].event_type == INT_BUTTON_RELEASE) {
@@ -1937,7 +1889,7 @@ static void interrupt_event_handler(struct controller *ctrl)
1937 p_slot->state = BLINKINGON_STATE; 1889 p_slot->state = BLINKINGON_STATE;
1938 info(msg_button_on, p_slot->number); 1890 info(msg_button_on, p_slot->number);
1939 } 1891 }
1940 down(&ctrl->crit_sect); 1892 mutex_lock(&ctrl->crit_sect);
1941 1893
1942 dbg("blink green LED and turn off amber\n"); 1894 dbg("blink green LED and turn off amber\n");
1943 1895
@@ -1949,7 +1901,7 @@ static void interrupt_event_handler(struct controller *ctrl)
1949 /* Wait for SOBS to be unset */ 1901 /* Wait for SOBS to be unset */
1950 wait_for_ctrl_irq (ctrl); 1902 wait_for_ctrl_irq (ctrl);
1951 1903
1952 up(&ctrl->crit_sect); 1904 mutex_unlock(&ctrl->crit_sect);
1953 init_timer(&p_slot->task_event); 1905 init_timer(&p_slot->task_event);
1954 p_slot->hp_slot = hp_slot; 1906 p_slot->hp_slot = hp_slot;
1955 p_slot->ctrl = ctrl; 1907 p_slot->ctrl = ctrl;
diff --git a/drivers/pci/hotplug/fakephp.c b/drivers/pci/hotplug/fakephp.c
index 060d74775d..71b80c23e8 100644
--- a/drivers/pci/hotplug/fakephp.c
+++ b/drivers/pci/hotplug/fakephp.c
@@ -95,15 +95,13 @@ static int add_slot(struct pci_dev *dev)
95 struct hotplug_slot *slot; 95 struct hotplug_slot *slot;
96 int retval = -ENOMEM; 96 int retval = -ENOMEM;
97 97
98 slot = kmalloc(sizeof(struct hotplug_slot), GFP_KERNEL); 98 slot = kzalloc(sizeof(struct hotplug_slot), GFP_KERNEL);
99 if (!slot) 99 if (!slot)
100 goto error; 100 goto error;
101 memset(slot, 0, sizeof(*slot));
102 101
103 slot->info = kmalloc(sizeof(struct hotplug_slot_info), GFP_KERNEL); 102 slot->info = kzalloc(sizeof(struct hotplug_slot_info), GFP_KERNEL);
104 if (!slot->info) 103 if (!slot->info)
105 goto error_slot; 104 goto error_slot;
106 memset(slot->info, 0, sizeof(struct hotplug_slot_info));
107 105
108 slot->info->power_status = 1; 106 slot->info->power_status = 1;
109 slot->info->max_bus_speed = PCI_SPEED_UNKNOWN; 107 slot->info->max_bus_speed = PCI_SPEED_UNKNOWN;
@@ -227,11 +225,10 @@ static void pci_rescan_bus(const struct pci_bus *bus)
227{ 225{
228 unsigned int devfn; 226 unsigned int devfn;
229 struct pci_dev *dev; 227 struct pci_dev *dev;
230 dev = kmalloc(sizeof(struct pci_dev), GFP_KERNEL); 228 dev = kzalloc(sizeof(struct pci_dev), GFP_KERNEL);
231 if (!dev) 229 if (!dev)
232 return; 230 return;
233 231
234 memset(dev, 0, sizeof(dev));
235 dev->bus = (struct pci_bus*)bus; 232 dev->bus = (struct pci_bus*)bus;
236 dev->sysdata = bus->sysdata; 233 dev->sysdata = bus->sysdata;
237 for (devfn = 0; devfn < 0x100; devfn += 8) { 234 for (devfn = 0; devfn < 0x100; devfn += 8) {
diff --git a/drivers/pci/hotplug/ibmphp.h b/drivers/pci/hotplug/ibmphp.h
index c22e0284d7..dba6d8ca9b 100644
--- a/drivers/pci/hotplug/ibmphp.h
+++ b/drivers/pci/hotplug/ibmphp.h
@@ -406,8 +406,6 @@ extern void ibmphp_hpc_stop_poll_thread (void);
406//---------------------------------------------------------------------------- 406//----------------------------------------------------------------------------
407// HPC return codes 407// HPC return codes
408//---------------------------------------------------------------------------- 408//----------------------------------------------------------------------------
409#define FALSE 0x00
410#define TRUE 0x01
411#define HPC_ERROR 0xFF 409#define HPC_ERROR 0xFF
412 410
413//----------------------------------------------------------------------------- 411//-----------------------------------------------------------------------------
diff --git a/drivers/pci/hotplug/ibmphp_core.c b/drivers/pci/hotplug/ibmphp_core.c
index dc59da675c..e13d5b8724 100644
--- a/drivers/pci/hotplug/ibmphp_core.c
+++ b/drivers/pci/hotplug/ibmphp_core.c
@@ -1141,7 +1141,7 @@ static int enable_slot(struct hotplug_slot *hs)
1141 goto error_power; 1141 goto error_power;
1142 } 1142 }
1143 1143
1144 slot_cur->func = kmalloc(sizeof(struct pci_func), GFP_KERNEL); 1144 slot_cur->func = kzalloc(sizeof(struct pci_func), GFP_KERNEL);
1145 if (!slot_cur->func) { 1145 if (!slot_cur->func) {
1146 /* We cannot do update_slot_info here, since no memory for 1146 /* We cannot do update_slot_info here, since no memory for
1147 * kmalloc n.e.ways, and update_slot_info allocates some */ 1147 * kmalloc n.e.ways, and update_slot_info allocates some */
@@ -1149,7 +1149,6 @@ static int enable_slot(struct hotplug_slot *hs)
1149 rc = -ENOMEM; 1149 rc = -ENOMEM;
1150 goto error_power; 1150 goto error_power;
1151 } 1151 }
1152 memset(slot_cur->func, 0, sizeof(struct pci_func));
1153 slot_cur->func->busno = slot_cur->bus; 1152 slot_cur->func->busno = slot_cur->bus;
1154 slot_cur->func->device = slot_cur->device; 1153 slot_cur->func->device = slot_cur->device;
1155 for (i = 0; i < 4; i++) 1154 for (i = 0; i < 4; i++)
@@ -1240,9 +1239,9 @@ int ibmphp_do_disable_slot(struct slot *slot_cur)
1240 } 1239 }
1241 1240
1242 flag = slot_cur->flag; 1241 flag = slot_cur->flag;
1243 slot_cur->flag = TRUE; 1242 slot_cur->flag = 1;
1244 1243
1245 if (flag == TRUE) { 1244 if (flag == 1) {
1246 rc = validate(slot_cur, DISABLE); 1245 rc = validate(slot_cur, DISABLE);
1247 /* checking if powered off already & valid slot # */ 1246 /* checking if powered off already & valid slot # */
1248 if (rc) 1247 if (rc)
@@ -1252,13 +1251,12 @@ int ibmphp_do_disable_slot(struct slot *slot_cur)
1252 1251
1253 if (slot_cur->func == NULL) { 1252 if (slot_cur->func == NULL) {
1254 /* We need this for fncs's that were there on bootup */ 1253 /* We need this for fncs's that were there on bootup */
1255 slot_cur->func = kmalloc(sizeof(struct pci_func), GFP_KERNEL); 1254 slot_cur->func = kzalloc(sizeof(struct pci_func), GFP_KERNEL);
1256 if (!slot_cur->func) { 1255 if (!slot_cur->func) {
1257 err("out of system memory\n"); 1256 err("out of system memory\n");
1258 rc = -ENOMEM; 1257 rc = -ENOMEM;
1259 goto error; 1258 goto error;
1260 } 1259 }
1261 memset(slot_cur->func, 0, sizeof(struct pci_func));
1262 slot_cur->func->busno = slot_cur->bus; 1260 slot_cur->func->busno = slot_cur->bus;
1263 slot_cur->func->device = slot_cur->device; 1261 slot_cur->func->device = slot_cur->device;
1264 } 1262 }
diff --git a/drivers/pci/hotplug/ibmphp_ebda.c b/drivers/pci/hotplug/ibmphp_ebda.c
index aea1187c73..05e4f5a192 100644
--- a/drivers/pci/hotplug/ibmphp_ebda.c
+++ b/drivers/pci/hotplug/ibmphp_ebda.c
@@ -72,13 +72,7 @@ static int ebda_rio_table (void);
72 72
73static struct ebda_hpc_list * __init alloc_ebda_hpc_list (void) 73static struct ebda_hpc_list * __init alloc_ebda_hpc_list (void)
74{ 74{
75 struct ebda_hpc_list *list; 75 return kzalloc(sizeof(struct ebda_hpc_list), GFP_KERNEL);
76
77 list = kmalloc (sizeof (struct ebda_hpc_list), GFP_KERNEL);
78 if (!list)
79 return NULL;
80 memset (list, 0, sizeof (*list));
81 return list;
82} 76}
83 77
84static struct controller *alloc_ebda_hpc (u32 slot_count, u32 bus_count) 78static struct controller *alloc_ebda_hpc (u32 slot_count, u32 bus_count)
@@ -87,21 +81,18 @@ static struct controller *alloc_ebda_hpc (u32 slot_count, u32 bus_count)
87 struct ebda_hpc_slot *slots; 81 struct ebda_hpc_slot *slots;
88 struct ebda_hpc_bus *buses; 82 struct ebda_hpc_bus *buses;
89 83
90 controller = kmalloc (sizeof (struct controller), GFP_KERNEL); 84 controller = kzalloc(sizeof(struct controller), GFP_KERNEL);
91 if (!controller) 85 if (!controller)
92 goto error; 86 goto error;
93 memset (controller, 0, sizeof (*controller));
94 87
95 slots = kmalloc (sizeof (struct ebda_hpc_slot) * slot_count, GFP_KERNEL); 88 slots = kcalloc(slot_count, sizeof(struct ebda_hpc_slot), GFP_KERNEL);
96 if (!slots) 89 if (!slots)
97 goto error_contr; 90 goto error_contr;
98 memset (slots, 0, sizeof (*slots) * slot_count);
99 controller->slots = slots; 91 controller->slots = slots;
100 92
101 buses = kmalloc (sizeof (struct ebda_hpc_bus) * bus_count, GFP_KERNEL); 93 buses = kcalloc(bus_count, sizeof(struct ebda_hpc_bus), GFP_KERNEL);
102 if (!buses) 94 if (!buses)
103 goto error_slots; 95 goto error_slots;
104 memset (buses, 0, sizeof (*buses) * bus_count);
105 controller->buses = buses; 96 controller->buses = buses;
106 97
107 return controller; 98 return controller;
@@ -122,24 +113,12 @@ static void free_ebda_hpc (struct controller *controller)
122 113
123static struct ebda_rsrc_list * __init alloc_ebda_rsrc_list (void) 114static struct ebda_rsrc_list * __init alloc_ebda_rsrc_list (void)
124{ 115{
125 struct ebda_rsrc_list *list; 116 return kzalloc(sizeof(struct ebda_rsrc_list), GFP_KERNEL);
126
127 list = kmalloc (sizeof (struct ebda_rsrc_list), GFP_KERNEL);
128 if (!list)
129 return NULL;
130 memset (list, 0, sizeof (*list));
131 return list;
132} 117}
133 118
134static struct ebda_pci_rsrc *alloc_ebda_pci_rsrc (void) 119static struct ebda_pci_rsrc *alloc_ebda_pci_rsrc (void)
135{ 120{
136 struct ebda_pci_rsrc *resource; 121 return kzalloc(sizeof(struct ebda_pci_rsrc), GFP_KERNEL);
137
138 resource = kmalloc (sizeof (struct ebda_pci_rsrc), GFP_KERNEL);
139 if (!resource)
140 return NULL;
141 memset (resource, 0, sizeof (*resource));
142 return resource;
143} 122}
144 123
145static void __init print_bus_info (void) 124static void __init print_bus_info (void)
@@ -390,10 +369,9 @@ int __init ibmphp_access_ebda (void)
390 debug ("now enter io table ---\n"); 369 debug ("now enter io table ---\n");
391 debug ("rio blk id: %x\n", blk_id); 370 debug ("rio blk id: %x\n", blk_id);
392 371
393 rio_table_ptr = kmalloc (sizeof (struct rio_table_hdr), GFP_KERNEL); 372 rio_table_ptr = kzalloc(sizeof(struct rio_table_hdr), GFP_KERNEL);
394 if (!rio_table_ptr) 373 if (!rio_table_ptr)
395 return -ENOMEM; 374 return -ENOMEM;
396 memset (rio_table_ptr, 0, sizeof (struct rio_table_hdr) );
397 rio_table_ptr->ver_num = readb (io_mem + offset); 375 rio_table_ptr->ver_num = readb (io_mem + offset);
398 rio_table_ptr->scal_count = readb (io_mem + offset + 1); 376 rio_table_ptr->scal_count = readb (io_mem + offset + 1);
399 rio_table_ptr->riodev_count = readb (io_mem + offset + 2); 377 rio_table_ptr->riodev_count = readb (io_mem + offset + 2);
@@ -445,10 +423,9 @@ static int __init ebda_rio_table (void)
445 423
446 // we do concern about rio details 424 // we do concern about rio details
447 for (i = 0; i < rio_table_ptr->riodev_count; i++) { 425 for (i = 0; i < rio_table_ptr->riodev_count; i++) {
448 rio_detail_ptr = kmalloc (sizeof (struct rio_detail), GFP_KERNEL); 426 rio_detail_ptr = kzalloc(sizeof(struct rio_detail), GFP_KERNEL);
449 if (!rio_detail_ptr) 427 if (!rio_detail_ptr)
450 return -ENOMEM; 428 return -ENOMEM;
451 memset (rio_detail_ptr, 0, sizeof (struct rio_detail));
452 rio_detail_ptr->rio_node_id = readb (io_mem + offset); 429 rio_detail_ptr->rio_node_id = readb (io_mem + offset);
453 rio_detail_ptr->bbar = readl (io_mem + offset + 1); 430 rio_detail_ptr->bbar = readl (io_mem + offset + 1);
454 rio_detail_ptr->rio_type = readb (io_mem + offset + 5); 431 rio_detail_ptr->rio_type = readb (io_mem + offset + 5);
@@ -503,10 +480,9 @@ static int __init combine_wpg_for_chassis (void)
503 rio_detail_ptr = list_entry (list_head_ptr, struct rio_detail, rio_detail_list); 480 rio_detail_ptr = list_entry (list_head_ptr, struct rio_detail, rio_detail_list);
504 opt_rio_ptr = search_opt_vg (rio_detail_ptr->chassis_num); 481 opt_rio_ptr = search_opt_vg (rio_detail_ptr->chassis_num);
505 if (!opt_rio_ptr) { 482 if (!opt_rio_ptr) {
506 opt_rio_ptr = (struct opt_rio *) kmalloc (sizeof (struct opt_rio), GFP_KERNEL); 483 opt_rio_ptr = kzalloc(sizeof(struct opt_rio), GFP_KERNEL);
507 if (!opt_rio_ptr) 484 if (!opt_rio_ptr)
508 return -ENOMEM; 485 return -ENOMEM;
509 memset (opt_rio_ptr, 0, sizeof (struct opt_rio));
510 opt_rio_ptr->rio_type = rio_detail_ptr->rio_type; 486 opt_rio_ptr->rio_type = rio_detail_ptr->rio_type;
511 opt_rio_ptr->chassis_num = rio_detail_ptr->chassis_num; 487 opt_rio_ptr->chassis_num = rio_detail_ptr->chassis_num;
512 opt_rio_ptr->first_slot_num = rio_detail_ptr->first_slot_num; 488 opt_rio_ptr->first_slot_num = rio_detail_ptr->first_slot_num;
@@ -546,10 +522,9 @@ static int combine_wpg_for_expansion (void)
546 rio_detail_ptr = list_entry (list_head_ptr, struct rio_detail, rio_detail_list); 522 rio_detail_ptr = list_entry (list_head_ptr, struct rio_detail, rio_detail_list);
547 opt_rio_lo_ptr = search_opt_lo (rio_detail_ptr->chassis_num); 523 opt_rio_lo_ptr = search_opt_lo (rio_detail_ptr->chassis_num);
548 if (!opt_rio_lo_ptr) { 524 if (!opt_rio_lo_ptr) {
549 opt_rio_lo_ptr = (struct opt_rio_lo *) kmalloc (sizeof (struct opt_rio_lo), GFP_KERNEL); 525 opt_rio_lo_ptr = kzalloc(sizeof(struct opt_rio_lo), GFP_KERNEL);
550 if (!opt_rio_lo_ptr) 526 if (!opt_rio_lo_ptr)
551 return -ENOMEM; 527 return -ENOMEM;
552 memset (opt_rio_lo_ptr, 0, sizeof (struct opt_rio_lo));
553 opt_rio_lo_ptr->rio_type = rio_detail_ptr->rio_type; 528 opt_rio_lo_ptr->rio_type = rio_detail_ptr->rio_type;
554 opt_rio_lo_ptr->chassis_num = rio_detail_ptr->chassis_num; 529 opt_rio_lo_ptr->chassis_num = rio_detail_ptr->chassis_num;
555 opt_rio_lo_ptr->first_slot_num = rio_detail_ptr->first_slot_num; 530 opt_rio_lo_ptr->first_slot_num = rio_detail_ptr->first_slot_num;
@@ -842,12 +817,11 @@ static int __init ebda_rsrc_controller (void)
842 817
843 bus_info_ptr2 = ibmphp_find_same_bus_num (slot_ptr->slot_bus_num); 818 bus_info_ptr2 = ibmphp_find_same_bus_num (slot_ptr->slot_bus_num);
844 if (!bus_info_ptr2) { 819 if (!bus_info_ptr2) {
845 bus_info_ptr1 = (struct bus_info *) kmalloc (sizeof (struct bus_info), GFP_KERNEL); 820 bus_info_ptr1 = kzalloc(sizeof(struct bus_info), GFP_KERNEL);
846 if (!bus_info_ptr1) { 821 if (!bus_info_ptr1) {
847 rc = -ENOMEM; 822 rc = -ENOMEM;
848 goto error_no_hp_slot; 823 goto error_no_hp_slot;
849 } 824 }
850 memset (bus_info_ptr1, 0, sizeof (struct bus_info));
851 bus_info_ptr1->slot_min = slot_ptr->slot_num; 825 bus_info_ptr1->slot_min = slot_ptr->slot_num;
852 bus_info_ptr1->slot_max = slot_ptr->slot_num; 826 bus_info_ptr1->slot_max = slot_ptr->slot_num;
853 bus_info_ptr1->slot_count += 1; 827 bus_info_ptr1->slot_count += 1;
@@ -946,19 +920,17 @@ static int __init ebda_rsrc_controller (void)
946 // register slots with hpc core as well as create linked list of ibm slot 920 // register slots with hpc core as well as create linked list of ibm slot
947 for (index = 0; index < hpc_ptr->slot_count; index++) { 921 for (index = 0; index < hpc_ptr->slot_count; index++) {
948 922
949 hp_slot_ptr = kmalloc(sizeof(*hp_slot_ptr), GFP_KERNEL); 923 hp_slot_ptr = kzalloc(sizeof(*hp_slot_ptr), GFP_KERNEL);
950 if (!hp_slot_ptr) { 924 if (!hp_slot_ptr) {
951 rc = -ENOMEM; 925 rc = -ENOMEM;
952 goto error_no_hp_slot; 926 goto error_no_hp_slot;
953 } 927 }
954 memset(hp_slot_ptr, 0, sizeof(*hp_slot_ptr));
955 928
956 hp_slot_ptr->info = kmalloc (sizeof(struct hotplug_slot_info), GFP_KERNEL); 929 hp_slot_ptr->info = kzalloc(sizeof(struct hotplug_slot_info), GFP_KERNEL);
957 if (!hp_slot_ptr->info) { 930 if (!hp_slot_ptr->info) {
958 rc = -ENOMEM; 931 rc = -ENOMEM;
959 goto error_no_hp_info; 932 goto error_no_hp_info;
960 } 933 }
961 memset(hp_slot_ptr->info, 0, sizeof(struct hotplug_slot_info));
962 934
963 hp_slot_ptr->name = kmalloc(30, GFP_KERNEL); 935 hp_slot_ptr->name = kmalloc(30, GFP_KERNEL);
964 if (!hp_slot_ptr->name) { 936 if (!hp_slot_ptr->name) {
@@ -966,14 +938,13 @@ static int __init ebda_rsrc_controller (void)
966 goto error_no_hp_name; 938 goto error_no_hp_name;
967 } 939 }
968 940
969 tmp_slot = kmalloc(sizeof(*tmp_slot), GFP_KERNEL); 941 tmp_slot = kzalloc(sizeof(*tmp_slot), GFP_KERNEL);
970 if (!tmp_slot) { 942 if (!tmp_slot) {
971 rc = -ENOMEM; 943 rc = -ENOMEM;
972 goto error_no_slot; 944 goto error_no_slot;
973 } 945 }
974 memset(tmp_slot, 0, sizeof(*tmp_slot));
975 946
976 tmp_slot->flag = TRUE; 947 tmp_slot->flag = 1;
977 948
978 tmp_slot->capabilities = hpc_ptr->slots[index].slot_cap; 949 tmp_slot->capabilities = hpc_ptr->slots[index].slot_cap;
979 if ((hpc_ptr->slots[index].slot_cap & EBDA_SLOT_133_MAX) == EBDA_SLOT_133_MAX) 950 if ((hpc_ptr->slots[index].slot_cap & EBDA_SLOT_133_MAX) == EBDA_SLOT_133_MAX)
diff --git a/drivers/pci/hotplug/ibmphp_hpc.c b/drivers/pci/hotplug/ibmphp_hpc.c
index 1a3eb8d3d4..c3ac98a0a6 100644
--- a/drivers/pci/hotplug/ibmphp_hpc.c
+++ b/drivers/pci/hotplug/ibmphp_hpc.c
@@ -34,9 +34,11 @@
34#include <linux/pci.h> 34#include <linux/pci.h>
35#include <linux/smp_lock.h> 35#include <linux/smp_lock.h>
36#include <linux/init.h> 36#include <linux/init.h>
37#include <linux/mutex.h>
38
37#include "ibmphp.h" 39#include "ibmphp.h"
38 40
39static int to_debug = FALSE; 41static int to_debug = 0;
40#define debug_polling(fmt, arg...) do { if (to_debug) debug (fmt, arg); } while (0) 42#define debug_polling(fmt, arg...) do { if (to_debug) debug (fmt, arg); } while (0)
41 43
42//---------------------------------------------------------------------------- 44//----------------------------------------------------------------------------
@@ -93,15 +95,15 @@ static int to_debug = FALSE;
93//---------------------------------------------------------------------------- 95//----------------------------------------------------------------------------
94// macro utilities 96// macro utilities
95//---------------------------------------------------------------------------- 97//----------------------------------------------------------------------------
96// if bits 20,22,25,26,27,29,30 are OFF return TRUE 98// if bits 20,22,25,26,27,29,30 are OFF return 1
97#define HPC_I2CSTATUS_CHECK(s) ((u8)((s & 0x00000A76) ? FALSE : TRUE)) 99#define HPC_I2CSTATUS_CHECK(s) ((u8)((s & 0x00000A76) ? 0 : 1))
98 100
99//---------------------------------------------------------------------------- 101//----------------------------------------------------------------------------
100// global variables 102// global variables
101//---------------------------------------------------------------------------- 103//----------------------------------------------------------------------------
102static int ibmphp_shutdown; 104static int ibmphp_shutdown;
103static int tid_poll; 105static int tid_poll;
104static struct semaphore sem_hpcaccess; // lock access to HPC 106static struct mutex sem_hpcaccess; // lock access to HPC
105static struct semaphore semOperations; // lock all operations and 107static struct semaphore semOperations; // lock all operations and
106 // access to data structures 108 // access to data structures
107static struct semaphore sem_exit; // make sure polling thread goes away 109static struct semaphore sem_exit; // make sure polling thread goes away
@@ -131,11 +133,11 @@ void __init ibmphp_hpc_initvars (void)
131{ 133{
132 debug ("%s - Entry\n", __FUNCTION__); 134 debug ("%s - Entry\n", __FUNCTION__);
133 135
134 init_MUTEX (&sem_hpcaccess); 136 mutex_init(&sem_hpcaccess);
135 init_MUTEX (&semOperations); 137 init_MUTEX (&semOperations);
136 init_MUTEX_LOCKED (&sem_exit); 138 init_MUTEX_LOCKED (&sem_exit);
137 to_debug = FALSE; 139 to_debug = 0;
138 ibmphp_shutdown = FALSE; 140 ibmphp_shutdown = 0;
139 tid_poll = 0; 141 tid_poll = 0;
140 142
141 debug ("%s - Exit\n", __FUNCTION__); 143 debug ("%s - Exit\n", __FUNCTION__);
@@ -737,21 +739,21 @@ int ibmphp_hpc_writeslot (struct slot * pslot, u8 cmd)
737 // check controller is still not working on the command 739 // check controller is still not working on the command
738 //-------------------------------------------------------------------- 740 //--------------------------------------------------------------------
739 timeout = CMD_COMPLETE_TOUT_SEC; 741 timeout = CMD_COMPLETE_TOUT_SEC;
740 done = FALSE; 742 done = 0;
741 while (!done) { 743 while (!done) {
742 rc = hpc_wait_ctlr_notworking (HPC_CTLR_WORKING_TOUT, ctlr_ptr, wpg_bbar, 744 rc = hpc_wait_ctlr_notworking (HPC_CTLR_WORKING_TOUT, ctlr_ptr, wpg_bbar,
743 &status); 745 &status);
744 if (!rc) { 746 if (!rc) {
745 if (NEEDTOCHECK_CMDSTATUS (cmd)) { 747 if (NEEDTOCHECK_CMDSTATUS (cmd)) {
746 if (CTLR_FINISHED (status) == HPC_CTLR_FINISHED_YES) 748 if (CTLR_FINISHED (status) == HPC_CTLR_FINISHED_YES)
747 done = TRUE; 749 done = 1;
748 } else 750 } else
749 done = TRUE; 751 done = 1;
750 } 752 }
751 if (!done) { 753 if (!done) {
752 msleep(1000); 754 msleep(1000);
753 if (timeout < 1) { 755 if (timeout < 1) {
754 done = TRUE; 756 done = 1;
755 err ("%s - Error command complete timeout\n", __FUNCTION__); 757 err ("%s - Error command complete timeout\n", __FUNCTION__);
756 rc = -EFAULT; 758 rc = -EFAULT;
757 } else 759 } else
@@ -778,7 +780,7 @@ int ibmphp_hpc_writeslot (struct slot * pslot, u8 cmd)
778*---------------------------------------------------------------------*/ 780*---------------------------------------------------------------------*/
779static void get_hpc_access (void) 781static void get_hpc_access (void)
780{ 782{
781 down (&sem_hpcaccess); 783 mutex_lock(&sem_hpcaccess);
782} 784}
783 785
784/*---------------------------------------------------------------------- 786/*----------------------------------------------------------------------
@@ -786,7 +788,7 @@ static void get_hpc_access (void)
786*---------------------------------------------------------------------*/ 788*---------------------------------------------------------------------*/
787void free_hpc_access (void) 789void free_hpc_access (void)
788{ 790{
789 up (&sem_hpcaccess); 791 mutex_unlock(&sem_hpcaccess);
790} 792}
791 793
792/*---------------------------------------------------------------------- 794/*----------------------------------------------------------------------
@@ -797,7 +799,7 @@ void free_hpc_access (void)
797void ibmphp_lock_operations (void) 799void ibmphp_lock_operations (void)
798{ 800{
799 down (&semOperations); 801 down (&semOperations);
800 to_debug = TRUE; 802 to_debug = 1;
801} 803}
802 804
803/*---------------------------------------------------------------------- 805/*----------------------------------------------------------------------
@@ -807,7 +809,7 @@ void ibmphp_unlock_operations (void)
807{ 809{
808 debug ("%s - Entry\n", __FUNCTION__); 810 debug ("%s - Entry\n", __FUNCTION__);
809 up (&semOperations); 811 up (&semOperations);
810 to_debug = FALSE; 812 to_debug = 0;
811 debug ("%s - Exit\n", __FUNCTION__); 813 debug ("%s - Exit\n", __FUNCTION__);
812} 814}
813 815
@@ -935,40 +937,40 @@ static int process_changeinstatus (struct slot *pslot, struct slot *poldslot)
935{ 937{
936 u8 status; 938 u8 status;
937 int rc = 0; 939 int rc = 0;
938 u8 disable = FALSE; 940 u8 disable = 0;
939 u8 update = FALSE; 941 u8 update = 0;
940 942
941 debug ("process_changeinstatus - Entry pslot[%p], poldslot[%p]\n", pslot, poldslot); 943 debug ("process_changeinstatus - Entry pslot[%p], poldslot[%p]\n", pslot, poldslot);
942 944
943 // bit 0 - HPC_SLOT_POWER 945 // bit 0 - HPC_SLOT_POWER
944 if ((pslot->status & 0x01) != (poldslot->status & 0x01)) 946 if ((pslot->status & 0x01) != (poldslot->status & 0x01))
945 update = TRUE; 947 update = 1;
946 948
947 // bit 1 - HPC_SLOT_CONNECT 949 // bit 1 - HPC_SLOT_CONNECT
948 // ignore 950 // ignore
949 951
950 // bit 2 - HPC_SLOT_ATTN 952 // bit 2 - HPC_SLOT_ATTN
951 if ((pslot->status & 0x04) != (poldslot->status & 0x04)) 953 if ((pslot->status & 0x04) != (poldslot->status & 0x04))
952 update = TRUE; 954 update = 1;
953 955
954 // bit 3 - HPC_SLOT_PRSNT2 956 // bit 3 - HPC_SLOT_PRSNT2
955 // bit 4 - HPC_SLOT_PRSNT1 957 // bit 4 - HPC_SLOT_PRSNT1
956 if (((pslot->status & 0x08) != (poldslot->status & 0x08)) 958 if (((pslot->status & 0x08) != (poldslot->status & 0x08))
957 || ((pslot->status & 0x10) != (poldslot->status & 0x10))) 959 || ((pslot->status & 0x10) != (poldslot->status & 0x10)))
958 update = TRUE; 960 update = 1;
959 961
960 // bit 5 - HPC_SLOT_PWRGD 962 // bit 5 - HPC_SLOT_PWRGD
961 if ((pslot->status & 0x20) != (poldslot->status & 0x20)) 963 if ((pslot->status & 0x20) != (poldslot->status & 0x20))
962 // OFF -> ON: ignore, ON -> OFF: disable slot 964 // OFF -> ON: ignore, ON -> OFF: disable slot
963 if ((poldslot->status & 0x20) && (SLOT_CONNECT (poldslot->status) == HPC_SLOT_CONNECTED) && (SLOT_PRESENT (poldslot->status))) 965 if ((poldslot->status & 0x20) && (SLOT_CONNECT (poldslot->status) == HPC_SLOT_CONNECTED) && (SLOT_PRESENT (poldslot->status)))
964 disable = TRUE; 966 disable = 1;
965 967
966 // bit 6 - HPC_SLOT_BUS_SPEED 968 // bit 6 - HPC_SLOT_BUS_SPEED
967 // ignore 969 // ignore
968 970
969 // bit 7 - HPC_SLOT_LATCH 971 // bit 7 - HPC_SLOT_LATCH
970 if ((pslot->status & 0x80) != (poldslot->status & 0x80)) { 972 if ((pslot->status & 0x80) != (poldslot->status & 0x80)) {
971 update = TRUE; 973 update = 1;
972 // OPEN -> CLOSE 974 // OPEN -> CLOSE
973 if (pslot->status & 0x80) { 975 if (pslot->status & 0x80) {
974 if (SLOT_PWRGD (pslot->status)) { 976 if (SLOT_PWRGD (pslot->status)) {
@@ -977,7 +979,7 @@ static int process_changeinstatus (struct slot *pslot, struct slot *poldslot)
977 msleep(1000); 979 msleep(1000);
978 rc = ibmphp_hpc_readslot (pslot, READ_SLOTSTATUS, &status); 980 rc = ibmphp_hpc_readslot (pslot, READ_SLOTSTATUS, &status);
979 if (SLOT_PWRGD (status)) 981 if (SLOT_PWRGD (status))
980 update = TRUE; 982 update = 1;
981 else // overwrite power in pslot to OFF 983 else // overwrite power in pslot to OFF
982 pslot->status &= ~HPC_SLOT_POWER; 984 pslot->status &= ~HPC_SLOT_POWER;
983 } 985 }
@@ -985,17 +987,17 @@ static int process_changeinstatus (struct slot *pslot, struct slot *poldslot)
985 // CLOSE -> OPEN 987 // CLOSE -> OPEN
986 else if ((SLOT_PWRGD (poldslot->status) == HPC_SLOT_PWRGD_GOOD) 988 else if ((SLOT_PWRGD (poldslot->status) == HPC_SLOT_PWRGD_GOOD)
987 && (SLOT_CONNECT (poldslot->status) == HPC_SLOT_CONNECTED) && (SLOT_PRESENT (poldslot->status))) { 989 && (SLOT_CONNECT (poldslot->status) == HPC_SLOT_CONNECTED) && (SLOT_PRESENT (poldslot->status))) {
988 disable = TRUE; 990 disable = 1;
989 } 991 }
990 // else - ignore 992 // else - ignore
991 } 993 }
992 // bit 4 - HPC_SLOT_BLINK_ATTN 994 // bit 4 - HPC_SLOT_BLINK_ATTN
993 if ((pslot->ext_status & 0x08) != (poldslot->ext_status & 0x08)) 995 if ((pslot->ext_status & 0x08) != (poldslot->ext_status & 0x08))
994 update = TRUE; 996 update = 1;
995 997
996 if (disable) { 998 if (disable) {
997 debug ("process_changeinstatus - disable slot\n"); 999 debug ("process_changeinstatus - disable slot\n");
998 pslot->flag = FALSE; 1000 pslot->flag = 0;
999 rc = ibmphp_do_disable_slot (pslot); 1001 rc = ibmphp_do_disable_slot (pslot);
1000 } 1002 }
1001 1003
@@ -1100,7 +1102,7 @@ void __exit ibmphp_hpc_stop_poll_thread (void)
1100{ 1102{
1101 debug ("%s - Entry\n", __FUNCTION__); 1103 debug ("%s - Entry\n", __FUNCTION__);
1102 1104
1103 ibmphp_shutdown = TRUE; 1105 ibmphp_shutdown = 1;
1104 debug ("before locking operations \n"); 1106 debug ("before locking operations \n");
1105 ibmphp_lock_operations (); 1107 ibmphp_lock_operations ();
1106 debug ("after locking operations \n"); 1108 debug ("after locking operations \n");
@@ -1134,7 +1136,7 @@ static int hpc_wait_ctlr_notworking (int timeout, struct controller *ctlr_ptr, v
1134 u8 * pstatus) 1136 u8 * pstatus)
1135{ 1137{
1136 int rc = 0; 1138 int rc = 0;
1137 u8 done = FALSE; 1139 u8 done = 0;
1138 1140
1139 debug_polling ("hpc_wait_ctlr_notworking - Entry timeout[%d]\n", timeout); 1141 debug_polling ("hpc_wait_ctlr_notworking - Entry timeout[%d]\n", timeout);
1140 1142
@@ -1142,14 +1144,14 @@ static int hpc_wait_ctlr_notworking (int timeout, struct controller *ctlr_ptr, v
1142 *pstatus = ctrl_read (ctlr_ptr, wpg_bbar, WPG_CTLR_INDEX); 1144 *pstatus = ctrl_read (ctlr_ptr, wpg_bbar, WPG_CTLR_INDEX);
1143 if (*pstatus == HPC_ERROR) { 1145 if (*pstatus == HPC_ERROR) {
1144 rc = HPC_ERROR; 1146 rc = HPC_ERROR;
1145 done = TRUE; 1147 done = 1;
1146 } 1148 }
1147 if (CTLR_WORKING (*pstatus) == HPC_CTLR_WORKING_NO) 1149 if (CTLR_WORKING (*pstatus) == HPC_CTLR_WORKING_NO)
1148 done = TRUE; 1150 done = 1;
1149 if (!done) { 1151 if (!done) {
1150 msleep(1000); 1152 msleep(1000);
1151 if (timeout < 1) { 1153 if (timeout < 1) {
1152 done = TRUE; 1154 done = 1;
1153 err ("HPCreadslot - Error ctlr timeout\n"); 1155 err ("HPCreadslot - Error ctlr timeout\n");
1154 rc = HPC_ERROR; 1156 rc = HPC_ERROR;
1155 } else 1157 } else
diff --git a/drivers/pci/hotplug/ibmphp_pci.c b/drivers/pci/hotplug/ibmphp_pci.c
index 155133fe5c..d87a9e3eae 100644
--- a/drivers/pci/hotplug/ibmphp_pci.c
+++ b/drivers/pci/hotplug/ibmphp_pci.c
@@ -164,12 +164,11 @@ int ibmphp_configure_card (struct pci_func *func, u8 slotno)
164 cleanup_count = 6; 164 cleanup_count = 6;
165 goto error; 165 goto error;
166 } 166 }
167 newfunc = kmalloc(sizeof(*newfunc), GFP_KERNEL); 167 newfunc = kzalloc(sizeof(*newfunc), GFP_KERNEL);
168 if (!newfunc) { 168 if (!newfunc) {
169 err ("out of system memory\n"); 169 err ("out of system memory\n");
170 return -ENOMEM; 170 return -ENOMEM;
171 } 171 }
172 memset (newfunc, 0, sizeof (struct pci_func));
173 newfunc->busno = cur_func->busno; 172 newfunc->busno = cur_func->busno;
174 newfunc->device = device; 173 newfunc->device = device;
175 cur_func->next = newfunc; 174 cur_func->next = newfunc;
@@ -200,15 +199,14 @@ int ibmphp_configure_card (struct pci_func *func, u8 slotno)
200 } 199 }
201 200
202 pci_bus_read_config_byte (ibmphp_pci_bus, devfn, PCI_SECONDARY_BUS, &sec_number); 201 pci_bus_read_config_byte (ibmphp_pci_bus, devfn, PCI_SECONDARY_BUS, &sec_number);
203 flag = FALSE; 202 flag = 0;
204 for (i = 0; i < 32; i++) { 203 for (i = 0; i < 32; i++) {
205 if (func->devices[i]) { 204 if (func->devices[i]) {
206 newfunc = kmalloc(sizeof(*newfunc), GFP_KERNEL); 205 newfunc = kzalloc(sizeof(*newfunc), GFP_KERNEL);
207 if (!newfunc) { 206 if (!newfunc) {
208 err ("out of system memory\n"); 207 err ("out of system memory\n");
209 return -ENOMEM; 208 return -ENOMEM;
210 } 209 }
211 memset (newfunc, 0, sizeof (struct pci_func));
212 newfunc->busno = sec_number; 210 newfunc->busno = sec_number;
213 newfunc->device = (u8) i; 211 newfunc->device = (u8) i;
214 for (j = 0; j < 4; j++) 212 for (j = 0; j < 4; j++)
@@ -228,16 +226,15 @@ int ibmphp_configure_card (struct pci_func *func, u8 slotno)
228 cleanup_count = 2; 226 cleanup_count = 2;
229 goto error; 227 goto error;
230 } 228 }
231 flag = TRUE; 229 flag = 1;
232 } 230 }
233 } 231 }
234 232
235 newfunc = kmalloc(sizeof(*newfunc), GFP_KERNEL); 233 newfunc = kzalloc(sizeof(*newfunc), GFP_KERNEL);
236 if (!newfunc) { 234 if (!newfunc) {
237 err ("out of system memory\n"); 235 err ("out of system memory\n");
238 return -ENOMEM; 236 return -ENOMEM;
239 } 237 }
240 memset (newfunc, 0, sizeof (struct pci_func));
241 newfunc->busno = cur_func->busno; 238 newfunc->busno = cur_func->busno;
242 newfunc->device = device; 239 newfunc->device = device;
243 for (j = 0; j < 4; j++) 240 for (j = 0; j < 4; j++)
@@ -275,16 +272,15 @@ int ibmphp_configure_card (struct pci_func *func, u8 slotno)
275 cur_func->busno, device, function); 272 cur_func->busno, device, function);
276 pci_bus_read_config_byte (ibmphp_pci_bus, devfn, PCI_SECONDARY_BUS, &sec_number); 273 pci_bus_read_config_byte (ibmphp_pci_bus, devfn, PCI_SECONDARY_BUS, &sec_number);
277 debug ("after configuring bridge..., sec_number = %x\n", sec_number); 274 debug ("after configuring bridge..., sec_number = %x\n", sec_number);
278 flag = FALSE; 275 flag = 0;
279 for (i = 0; i < 32; i++) { 276 for (i = 0; i < 32; i++) {
280 if (func->devices[i]) { 277 if (func->devices[i]) {
281 debug ("inside for loop, device is %x\n", i); 278 debug ("inside for loop, device is %x\n", i);
282 newfunc = kmalloc(sizeof(*newfunc), GFP_KERNEL); 279 newfunc = kzalloc(sizeof(*newfunc), GFP_KERNEL);
283 if (!newfunc) { 280 if (!newfunc) {
284 err (" out of system memory\n"); 281 err (" out of system memory\n");
285 return -ENOMEM; 282 return -ENOMEM;
286 } 283 }
287 memset (newfunc, 0, sizeof (struct pci_func));
288 newfunc->busno = sec_number; 284 newfunc->busno = sec_number;
289 newfunc->device = (u8) i; 285 newfunc->device = (u8) i;
290 for (j = 0; j < 4; j++) 286 for (j = 0; j < 4; j++)
@@ -305,7 +301,7 @@ int ibmphp_configure_card (struct pci_func *func, u8 slotno)
305 cleanup_count = 2; 301 cleanup_count = 2;
306 goto error; 302 goto error;
307 } 303 }
308 flag = TRUE; 304 flag = 1;
309 } 305 }
310 } 306 }
311 307
@@ -405,13 +401,12 @@ static int configure_device (struct pci_func *func)
405 401
406 debug ("len[count] in IO %x, count %d\n", len[count], count); 402 debug ("len[count] in IO %x, count %d\n", len[count], count);
407 403
408 io[count] = kmalloc (sizeof (struct resource_node), GFP_KERNEL); 404 io[count] = kzalloc(sizeof(struct resource_node), GFP_KERNEL);
409 405
410 if (!io[count]) { 406 if (!io[count]) {
411 err ("out of system memory\n"); 407 err ("out of system memory\n");
412 return -ENOMEM; 408 return -ENOMEM;
413 } 409 }
414 memset (io[count], 0, sizeof (struct resource_node));
415 io[count]->type = IO; 410 io[count]->type = IO;
416 io[count]->busno = func->busno; 411 io[count]->busno = func->busno;
417 io[count]->devfunc = PCI_DEVFN(func->device, func->function); 412 io[count]->devfunc = PCI_DEVFN(func->device, func->function);
@@ -444,29 +439,27 @@ static int configure_device (struct pci_func *func)
444 439
445 debug ("len[count] in PFMEM %x, count %d\n", len[count], count); 440 debug ("len[count] in PFMEM %x, count %d\n", len[count], count);
446 441
447 pfmem[count] = kmalloc (sizeof (struct resource_node), GFP_KERNEL); 442 pfmem[count] = kzalloc(sizeof(struct resource_node), GFP_KERNEL);
448 if (!pfmem[count]) { 443 if (!pfmem[count]) {
449 err ("out of system memory\n"); 444 err ("out of system memory\n");
450 return -ENOMEM; 445 return -ENOMEM;
451 } 446 }
452 memset (pfmem[count], 0, sizeof (struct resource_node));
453 pfmem[count]->type = PFMEM; 447 pfmem[count]->type = PFMEM;
454 pfmem[count]->busno = func->busno; 448 pfmem[count]->busno = func->busno;
455 pfmem[count]->devfunc = PCI_DEVFN(func->device, 449 pfmem[count]->devfunc = PCI_DEVFN(func->device,
456 func->function); 450 func->function);
457 pfmem[count]->len = len[count]; 451 pfmem[count]->len = len[count];
458 pfmem[count]->fromMem = FALSE; 452 pfmem[count]->fromMem = 0;
459 if (ibmphp_check_resource (pfmem[count], 0) == 0) { 453 if (ibmphp_check_resource (pfmem[count], 0) == 0) {
460 ibmphp_add_resource (pfmem[count]); 454 ibmphp_add_resource (pfmem[count]);
461 func->pfmem[count] = pfmem[count]; 455 func->pfmem[count] = pfmem[count];
462 } else { 456 } else {
463 mem_tmp = kmalloc(sizeof(*mem_tmp), GFP_KERNEL); 457 mem_tmp = kzalloc(sizeof(*mem_tmp), GFP_KERNEL);
464 if (!mem_tmp) { 458 if (!mem_tmp) {
465 err ("out of system memory\n"); 459 err ("out of system memory\n");
466 kfree (pfmem[count]); 460 kfree (pfmem[count]);
467 return -ENOMEM; 461 return -ENOMEM;
468 } 462 }
469 memset (mem_tmp, 0, sizeof (struct resource_node));
470 mem_tmp->type = MEM; 463 mem_tmp->type = MEM;
471 mem_tmp->busno = pfmem[count]->busno; 464 mem_tmp->busno = pfmem[count]->busno;
472 mem_tmp->devfunc = pfmem[count]->devfunc; 465 mem_tmp->devfunc = pfmem[count]->devfunc;
@@ -474,7 +467,7 @@ static int configure_device (struct pci_func *func)
474 debug ("there's no pfmem... going into mem.\n"); 467 debug ("there's no pfmem... going into mem.\n");
475 if (ibmphp_check_resource (mem_tmp, 0) == 0) { 468 if (ibmphp_check_resource (mem_tmp, 0) == 0) {
476 ibmphp_add_resource (mem_tmp); 469 ibmphp_add_resource (mem_tmp);
477 pfmem[count]->fromMem = TRUE; 470 pfmem[count]->fromMem = 1;
478 pfmem[count]->rangeno = mem_tmp->rangeno; 471 pfmem[count]->rangeno = mem_tmp->rangeno;
479 pfmem[count]->start = mem_tmp->start; 472 pfmem[count]->start = mem_tmp->start;
480 pfmem[count]->end = mem_tmp->end; 473 pfmem[count]->end = mem_tmp->end;
@@ -512,12 +505,11 @@ static int configure_device (struct pci_func *func)
512 505
513 debug ("len[count] in Mem %x, count %d\n", len[count], count); 506 debug ("len[count] in Mem %x, count %d\n", len[count], count);
514 507
515 mem[count] = kmalloc (sizeof (struct resource_node), GFP_KERNEL); 508 mem[count] = kzalloc(sizeof(struct resource_node), GFP_KERNEL);
516 if (!mem[count]) { 509 if (!mem[count]) {
517 err ("out of system memory\n"); 510 err ("out of system memory\n");
518 return -ENOMEM; 511 return -ENOMEM;
519 } 512 }
520 memset (mem[count], 0, sizeof (struct resource_node));
521 mem[count]->type = MEM; 513 mem[count]->type = MEM;
522 mem[count]->busno = func->busno; 514 mem[count]->busno = func->busno;
523 mem[count]->devfunc = PCI_DEVFN(func->device, 515 mem[count]->devfunc = PCI_DEVFN(func->device,
@@ -579,11 +571,11 @@ static int configure_bridge (struct pci_func **func_passed, u8 slotno)
579 u16 pfmem_base; 571 u16 pfmem_base;
580 u32 bar[2]; 572 u32 bar[2];
581 u32 len[2]; 573 u32 len[2];
582 u8 flag_io = FALSE; 574 u8 flag_io = 0;
583 u8 flag_mem = FALSE; 575 u8 flag_mem = 0;
584 u8 flag_pfmem = FALSE; 576 u8 flag_pfmem = 0;
585 u8 need_io_upper = FALSE; 577 u8 need_io_upper = 0;
586 u8 need_pfmem_upper = FALSE; 578 u8 need_pfmem_upper = 0;
587 struct res_needed *amount_needed = NULL; 579 struct res_needed *amount_needed = NULL;
588 struct resource_node *io = NULL; 580 struct resource_node *io = NULL;
589 struct resource_node *bus_io[2] = {NULL, NULL}; 581 struct resource_node *bus_io[2] = {NULL, NULL};
@@ -677,14 +669,13 @@ static int configure_bridge (struct pci_func **func_passed, u8 slotno)
677 669
678 debug ("len[count] in IO = %x\n", len[count]); 670 debug ("len[count] in IO = %x\n", len[count]);
679 671
680 bus_io[count] = kmalloc (sizeof (struct resource_node), GFP_KERNEL); 672 bus_io[count] = kzalloc(sizeof(struct resource_node), GFP_KERNEL);
681 673
682 if (!bus_io[count]) { 674 if (!bus_io[count]) {
683 err ("out of system memory\n"); 675 err ("out of system memory\n");
684 retval = -ENOMEM; 676 retval = -ENOMEM;
685 goto error; 677 goto error;
686 } 678 }
687 memset (bus_io[count], 0, sizeof (struct resource_node));
688 bus_io[count]->type = IO; 679 bus_io[count]->type = IO;
689 bus_io[count]->busno = func->busno; 680 bus_io[count]->busno = func->busno;
690 bus_io[count]->devfunc = PCI_DEVFN(func->device, 681 bus_io[count]->devfunc = PCI_DEVFN(func->device,
@@ -711,37 +702,35 @@ static int configure_bridge (struct pci_func **func_passed, u8 slotno)
711 702
712 debug ("len[count] in PFMEM = %x\n", len[count]); 703 debug ("len[count] in PFMEM = %x\n", len[count]);
713 704
714 bus_pfmem[count] = kmalloc (sizeof (struct resource_node), GFP_KERNEL); 705 bus_pfmem[count] = kzalloc(sizeof(struct resource_node), GFP_KERNEL);
715 if (!bus_pfmem[count]) { 706 if (!bus_pfmem[count]) {
716 err ("out of system memory\n"); 707 err ("out of system memory\n");
717 retval = -ENOMEM; 708 retval = -ENOMEM;
718 goto error; 709 goto error;
719 } 710 }
720 memset (bus_pfmem[count], 0, sizeof (struct resource_node));
721 bus_pfmem[count]->type = PFMEM; 711 bus_pfmem[count]->type = PFMEM;
722 bus_pfmem[count]->busno = func->busno; 712 bus_pfmem[count]->busno = func->busno;
723 bus_pfmem[count]->devfunc = PCI_DEVFN(func->device, 713 bus_pfmem[count]->devfunc = PCI_DEVFN(func->device,
724 func->function); 714 func->function);
725 bus_pfmem[count]->len = len[count]; 715 bus_pfmem[count]->len = len[count];
726 bus_pfmem[count]->fromMem = FALSE; 716 bus_pfmem[count]->fromMem = 0;
727 if (ibmphp_check_resource (bus_pfmem[count], 0) == 0) { 717 if (ibmphp_check_resource (bus_pfmem[count], 0) == 0) {
728 ibmphp_add_resource (bus_pfmem[count]); 718 ibmphp_add_resource (bus_pfmem[count]);
729 func->pfmem[count] = bus_pfmem[count]; 719 func->pfmem[count] = bus_pfmem[count];
730 } else { 720 } else {
731 mem_tmp = kmalloc(sizeof(*mem_tmp), GFP_KERNEL); 721 mem_tmp = kzalloc(sizeof(*mem_tmp), GFP_KERNEL);
732 if (!mem_tmp) { 722 if (!mem_tmp) {
733 err ("out of system memory\n"); 723 err ("out of system memory\n");
734 retval = -ENOMEM; 724 retval = -ENOMEM;
735 goto error; 725 goto error;
736 } 726 }
737 memset (mem_tmp, 0, sizeof (struct resource_node));
738 mem_tmp->type = MEM; 727 mem_tmp->type = MEM;
739 mem_tmp->busno = bus_pfmem[count]->busno; 728 mem_tmp->busno = bus_pfmem[count]->busno;
740 mem_tmp->devfunc = bus_pfmem[count]->devfunc; 729 mem_tmp->devfunc = bus_pfmem[count]->devfunc;
741 mem_tmp->len = bus_pfmem[count]->len; 730 mem_tmp->len = bus_pfmem[count]->len;
742 if (ibmphp_check_resource (mem_tmp, 0) == 0) { 731 if (ibmphp_check_resource (mem_tmp, 0) == 0) {
743 ibmphp_add_resource (mem_tmp); 732 ibmphp_add_resource (mem_tmp);
744 bus_pfmem[count]->fromMem = TRUE; 733 bus_pfmem[count]->fromMem = 1;
745 bus_pfmem[count]->rangeno = mem_tmp->rangeno; 734 bus_pfmem[count]->rangeno = mem_tmp->rangeno;
746 ibmphp_add_pfmem_from_mem (bus_pfmem[count]); 735 ibmphp_add_pfmem_from_mem (bus_pfmem[count]);
747 func->pfmem[count] = bus_pfmem[count]; 736 func->pfmem[count] = bus_pfmem[count];
@@ -770,13 +759,12 @@ static int configure_bridge (struct pci_func **func_passed, u8 slotno)
770 759
771 debug ("len[count] in Memory is %x\n", len[count]); 760 debug ("len[count] in Memory is %x\n", len[count]);
772 761
773 bus_mem[count] = kmalloc (sizeof (struct resource_node), GFP_KERNEL); 762 bus_mem[count] = kzalloc(sizeof(struct resource_node), GFP_KERNEL);
774 if (!bus_mem[count]) { 763 if (!bus_mem[count]) {
775 err ("out of system memory\n"); 764 err ("out of system memory\n");
776 retval = -ENOMEM; 765 retval = -ENOMEM;
777 goto error; 766 goto error;
778 } 767 }
779 memset (bus_mem[count], 0, sizeof (struct resource_node));
780 bus_mem[count]->type = MEM; 768 bus_mem[count]->type = MEM;
781 bus_mem[count]->busno = func->busno; 769 bus_mem[count]->busno = func->busno;
782 bus_mem[count]->devfunc = PCI_DEVFN(func->device, 770 bus_mem[count]->devfunc = PCI_DEVFN(func->device,
@@ -838,17 +826,16 @@ static int configure_bridge (struct pci_func **func_passed, u8 slotno)
838 826
839 if (!amount_needed->io) { 827 if (!amount_needed->io) {
840 debug ("it doesn't want IO?\n"); 828 debug ("it doesn't want IO?\n");
841 flag_io = TRUE; 829 flag_io = 1;
842 } else { 830 } else {
843 debug ("it wants %x IO behind the bridge\n", amount_needed->io); 831 debug ("it wants %x IO behind the bridge\n", amount_needed->io);
844 io = kmalloc(sizeof(*io), GFP_KERNEL); 832 io = kzalloc(sizeof(*io), GFP_KERNEL);
845 833
846 if (!io) { 834 if (!io) {
847 err ("out of system memory\n"); 835 err ("out of system memory\n");
848 retval = -ENOMEM; 836 retval = -ENOMEM;
849 goto error; 837 goto error;
850 } 838 }
851 memset (io, 0, sizeof (struct resource_node));
852 io->type = IO; 839 io->type = IO;
853 io->busno = func->busno; 840 io->busno = func->busno;
854 io->devfunc = PCI_DEVFN(func->device, func->function); 841 io->devfunc = PCI_DEVFN(func->device, func->function);
@@ -856,71 +843,68 @@ static int configure_bridge (struct pci_func **func_passed, u8 slotno)
856 if (ibmphp_check_resource (io, 1) == 0) { 843 if (ibmphp_check_resource (io, 1) == 0) {
857 debug ("were we able to add io\n"); 844 debug ("were we able to add io\n");
858 ibmphp_add_resource (io); 845 ibmphp_add_resource (io);
859 flag_io = TRUE; 846 flag_io = 1;
860 } 847 }
861 } 848 }
862 849
863 if (!amount_needed->mem) { 850 if (!amount_needed->mem) {
864 debug ("it doesn't want n.e.memory?\n"); 851 debug ("it doesn't want n.e.memory?\n");
865 flag_mem = TRUE; 852 flag_mem = 1;
866 } else { 853 } else {
867 debug ("it wants %x memory behind the bridge\n", amount_needed->mem); 854 debug ("it wants %x memory behind the bridge\n", amount_needed->mem);
868 mem = kmalloc(sizeof(*mem), GFP_KERNEL); 855 mem = kzalloc(sizeof(*mem), GFP_KERNEL);
869 if (!mem) { 856 if (!mem) {
870 err ("out of system memory\n"); 857 err ("out of system memory\n");
871 retval = -ENOMEM; 858 retval = -ENOMEM;
872 goto error; 859 goto error;
873 } 860 }
874 memset (mem, 0, sizeof (struct resource_node));
875 mem->type = MEM; 861 mem->type = MEM;
876 mem->busno = func->busno; 862 mem->busno = func->busno;
877 mem->devfunc = PCI_DEVFN(func->device, func->function); 863 mem->devfunc = PCI_DEVFN(func->device, func->function);
878 mem->len = amount_needed->mem; 864 mem->len = amount_needed->mem;
879 if (ibmphp_check_resource (mem, 1) == 0) { 865 if (ibmphp_check_resource (mem, 1) == 0) {
880 ibmphp_add_resource (mem); 866 ibmphp_add_resource (mem);
881 flag_mem = TRUE; 867 flag_mem = 1;
882 debug ("were we able to add mem\n"); 868 debug ("were we able to add mem\n");
883 } 869 }
884 } 870 }
885 871
886 if (!amount_needed->pfmem) { 872 if (!amount_needed->pfmem) {
887 debug ("it doesn't want n.e.pfmem mem?\n"); 873 debug ("it doesn't want n.e.pfmem mem?\n");
888 flag_pfmem = TRUE; 874 flag_pfmem = 1;
889 } else { 875 } else {
890 debug ("it wants %x pfmemory behind the bridge\n", amount_needed->pfmem); 876 debug ("it wants %x pfmemory behind the bridge\n", amount_needed->pfmem);
891 pfmem = kmalloc(sizeof(*pfmem), GFP_KERNEL); 877 pfmem = kzalloc(sizeof(*pfmem), GFP_KERNEL);
892 if (!pfmem) { 878 if (!pfmem) {
893 err ("out of system memory\n"); 879 err ("out of system memory\n");
894 retval = -ENOMEM; 880 retval = -ENOMEM;
895 goto error; 881 goto error;
896 } 882 }
897 memset (pfmem, 0, sizeof (struct resource_node));
898 pfmem->type = PFMEM; 883 pfmem->type = PFMEM;
899 pfmem->busno = func->busno; 884 pfmem->busno = func->busno;
900 pfmem->devfunc = PCI_DEVFN(func->device, func->function); 885 pfmem->devfunc = PCI_DEVFN(func->device, func->function);
901 pfmem->len = amount_needed->pfmem; 886 pfmem->len = amount_needed->pfmem;
902 pfmem->fromMem = FALSE; 887 pfmem->fromMem = 0;
903 if (ibmphp_check_resource (pfmem, 1) == 0) { 888 if (ibmphp_check_resource (pfmem, 1) == 0) {
904 ibmphp_add_resource (pfmem); 889 ibmphp_add_resource (pfmem);
905 flag_pfmem = TRUE; 890 flag_pfmem = 1;
906 } else { 891 } else {
907 mem_tmp = kmalloc(sizeof(*mem_tmp), GFP_KERNEL); 892 mem_tmp = kzalloc(sizeof(*mem_tmp), GFP_KERNEL);
908 if (!mem_tmp) { 893 if (!mem_tmp) {
909 err ("out of system memory\n"); 894 err ("out of system memory\n");
910 retval = -ENOMEM; 895 retval = -ENOMEM;
911 goto error; 896 goto error;
912 } 897 }
913 memset (mem_tmp, 0, sizeof (struct resource_node));
914 mem_tmp->type = MEM; 898 mem_tmp->type = MEM;
915 mem_tmp->busno = pfmem->busno; 899 mem_tmp->busno = pfmem->busno;
916 mem_tmp->devfunc = pfmem->devfunc; 900 mem_tmp->devfunc = pfmem->devfunc;
917 mem_tmp->len = pfmem->len; 901 mem_tmp->len = pfmem->len;
918 if (ibmphp_check_resource (mem_tmp, 1) == 0) { 902 if (ibmphp_check_resource (mem_tmp, 1) == 0) {
919 ibmphp_add_resource (mem_tmp); 903 ibmphp_add_resource (mem_tmp);
920 pfmem->fromMem = TRUE; 904 pfmem->fromMem = 1;
921 pfmem->rangeno = mem_tmp->rangeno; 905 pfmem->rangeno = mem_tmp->rangeno;
922 ibmphp_add_pfmem_from_mem (pfmem); 906 ibmphp_add_pfmem_from_mem (pfmem);
923 flag_pfmem = TRUE; 907 flag_pfmem = 1;
924 } 908 }
925 } 909 }
926 } 910 }
@@ -936,13 +920,12 @@ static int configure_bridge (struct pci_func **func_passed, u8 slotno)
936 */ 920 */
937 bus = ibmphp_find_res_bus (sec_number); 921 bus = ibmphp_find_res_bus (sec_number);
938 if (!bus) { 922 if (!bus) {
939 bus = kmalloc(sizeof(*bus), GFP_KERNEL); 923 bus = kzalloc(sizeof(*bus), GFP_KERNEL);
940 if (!bus) { 924 if (!bus) {
941 err ("out of system memory\n"); 925 err ("out of system memory\n");
942 retval = -ENOMEM; 926 retval = -ENOMEM;
943 goto error; 927 goto error;
944 } 928 }
945 memset (bus, 0, sizeof (struct bus_node));
946 bus->busno = sec_number; 929 bus->busno = sec_number;
947 debug ("b4 adding new bus\n"); 930 debug ("b4 adding new bus\n");
948 rc = add_new_bus (bus, io, mem, pfmem, func->busno); 931 rc = add_new_bus (bus, io, mem, pfmem, func->busno);
@@ -967,11 +950,11 @@ static int configure_bridge (struct pci_func **func_passed, u8 slotno)
967 950
968 if ((io_base & PCI_IO_RANGE_TYPE_MASK) == PCI_IO_RANGE_TYPE_32) { 951 if ((io_base & PCI_IO_RANGE_TYPE_MASK) == PCI_IO_RANGE_TYPE_32) {
969 debug ("io 32\n"); 952 debug ("io 32\n");
970 need_io_upper = TRUE; 953 need_io_upper = 1;
971 } 954 }
972 if ((pfmem_base & PCI_PREF_RANGE_TYPE_MASK) == PCI_PREF_RANGE_TYPE_64) { 955 if ((pfmem_base & PCI_PREF_RANGE_TYPE_MASK) == PCI_PREF_RANGE_TYPE_64) {
973 debug ("pfmem 64\n"); 956 debug ("pfmem 64\n");
974 need_pfmem_upper = TRUE; 957 need_pfmem_upper = 1;
975 } 958 }
976 959
977 if (bus->noIORanges) { 960 if (bus->noIORanges) {
@@ -1111,10 +1094,9 @@ static struct res_needed *scan_behind_bridge (struct pci_func * func, u8 busno)
1111 }; 1094 };
1112 struct res_needed *amount; 1095 struct res_needed *amount;
1113 1096
1114 amount = kmalloc(sizeof(*amount), GFP_KERNEL); 1097 amount = kzalloc(sizeof(*amount), GFP_KERNEL);
1115 if (amount == NULL) 1098 if (amount == NULL)
1116 return NULL; 1099 return NULL;
1117 memset (amount, 0, sizeof (struct res_needed));
1118 1100
1119 ibmphp_pci_bus->number = busno; 1101 ibmphp_pci_bus->number = busno;
1120 1102
@@ -1137,7 +1119,7 @@ static struct res_needed *scan_behind_bridge (struct pci_func * func, u8 busno)
1137 debug ("hdr_type behind the bridge is %x\n", hdr_type); 1119 debug ("hdr_type behind the bridge is %x\n", hdr_type);
1138 if (hdr_type & PCI_HEADER_TYPE_BRIDGE) { 1120 if (hdr_type & PCI_HEADER_TYPE_BRIDGE) {
1139 err ("embedded bridges not supported for hot-plugging.\n"); 1121 err ("embedded bridges not supported for hot-plugging.\n");
1140 amount->not_correct = TRUE; 1122 amount->not_correct = 1;
1141 return amount; 1123 return amount;
1142 } 1124 }
1143 1125
@@ -1145,12 +1127,12 @@ static struct res_needed *scan_behind_bridge (struct pci_func * func, u8 busno)
1145 if (class == PCI_CLASS_NOT_DEFINED_VGA) { 1127 if (class == PCI_CLASS_NOT_DEFINED_VGA) {
1146 err ("The device %x is VGA compatible and as is not supported for hot plugging. " 1128 err ("The device %x is VGA compatible and as is not supported for hot plugging. "
1147 "Please choose another device.\n", device); 1129 "Please choose another device.\n", device);
1148 amount->not_correct = TRUE; 1130 amount->not_correct = 1;
1149 return amount; 1131 return amount;
1150 } else if (class == PCI_CLASS_DISPLAY_VGA) { 1132 } else if (class == PCI_CLASS_DISPLAY_VGA) {
1151 err ("The device %x is not supported for hot plugging. " 1133 err ("The device %x is not supported for hot plugging. "
1152 "Please choose another device.\n", device); 1134 "Please choose another device.\n", device);
1153 amount->not_correct = TRUE; 1135 amount->not_correct = 1;
1154 return amount; 1136 return amount;
1155 } 1137 }
1156 1138
@@ -1210,9 +1192,9 @@ static struct res_needed *scan_behind_bridge (struct pci_func * func, u8 busno)
1210 } /* end for */ 1192 } /* end for */
1211 1193
1212 if (!howmany) 1194 if (!howmany)
1213 amount->not_correct = TRUE; 1195 amount->not_correct = 1;
1214 else 1196 else
1215 amount->not_correct = FALSE; 1197 amount->not_correct = 0;
1216 if ((amount->io) && (amount->io < IOBRIDGE)) 1198 if ((amount->io) && (amount->io < IOBRIDGE))
1217 amount->io = IOBRIDGE; 1199 amount->io = IOBRIDGE;
1218 if ((amount->mem) && (amount->mem < MEMBRIDGE)) 1200 if ((amount->mem) && (amount->mem < MEMBRIDGE))
@@ -1672,12 +1654,11 @@ static int add_new_bus (struct bus_node *bus, struct resource_node *io, struct r
1672 list_add (&bus->bus_list, &cur_bus->bus_list); 1654 list_add (&bus->bus_list, &cur_bus->bus_list);
1673 } 1655 }
1674 if (io) { 1656 if (io) {
1675 io_range = kmalloc(sizeof(*io_range), GFP_KERNEL); 1657 io_range = kzalloc(sizeof(*io_range), GFP_KERNEL);
1676 if (!io_range) { 1658 if (!io_range) {
1677 err ("out of system memory\n"); 1659 err ("out of system memory\n");
1678 return -ENOMEM; 1660 return -ENOMEM;
1679 } 1661 }
1680 memset (io_range, 0, sizeof (struct range_node));
1681 io_range->start = io->start; 1662 io_range->start = io->start;
1682 io_range->end = io->end; 1663 io_range->end = io->end;
1683 io_range->rangeno = 1; 1664 io_range->rangeno = 1;
@@ -1685,12 +1666,11 @@ static int add_new_bus (struct bus_node *bus, struct resource_node *io, struct r
1685 bus->rangeIO = io_range; 1666 bus->rangeIO = io_range;
1686 } 1667 }
1687 if (mem) { 1668 if (mem) {
1688 mem_range = kmalloc(sizeof(*mem_range), GFP_KERNEL); 1669 mem_range = kzalloc(sizeof(*mem_range), GFP_KERNEL);
1689 if (!mem_range) { 1670 if (!mem_range) {
1690 err ("out of system memory\n"); 1671 err ("out of system memory\n");
1691 return -ENOMEM; 1672 return -ENOMEM;
1692 } 1673 }
1693 memset (mem_range, 0, sizeof (struct range_node));
1694 mem_range->start = mem->start; 1674 mem_range->start = mem->start;
1695 mem_range->end = mem->end; 1675 mem_range->end = mem->end;
1696 mem_range->rangeno = 1; 1676 mem_range->rangeno = 1;
@@ -1698,12 +1678,11 @@ static int add_new_bus (struct bus_node *bus, struct resource_node *io, struct r
1698 bus->rangeMem = mem_range; 1678 bus->rangeMem = mem_range;
1699 } 1679 }
1700 if (pfmem) { 1680 if (pfmem) {
1701 pfmem_range = kmalloc(sizeof(*pfmem_range), GFP_KERNEL); 1681 pfmem_range = kzalloc(sizeof(*pfmem_range), GFP_KERNEL);
1702 if (!pfmem_range) { 1682 if (!pfmem_range) {
1703 err ("out of system memory\n"); 1683 err ("out of system memory\n");
1704 return -ENOMEM; 1684 return -ENOMEM;
1705 } 1685 }
1706 memset (pfmem_range, 0, sizeof (struct range_node));
1707 pfmem_range->start = pfmem->start; 1686 pfmem_range->start = pfmem->start;
1708 pfmem_range->end = pfmem->end; 1687 pfmem_range->end = pfmem->end;
1709 pfmem_range->rangeno = 1; 1688 pfmem_range->rangeno = 1;
diff --git a/drivers/pci/hotplug/ibmphp_res.c b/drivers/pci/hotplug/ibmphp_res.c
index 9c224c94d6..5636b1ac2a 100644
--- a/drivers/pci/hotplug/ibmphp_res.c
+++ b/drivers/pci/hotplug/ibmphp_res.c
@@ -55,13 +55,12 @@ static struct bus_node * __init alloc_error_bus (struct ebda_pci_rsrc * curr, u8
55 return NULL; 55 return NULL;
56 } 56 }
57 57
58 newbus = kmalloc (sizeof (struct bus_node), GFP_KERNEL); 58 newbus = kzalloc(sizeof(struct bus_node), GFP_KERNEL);
59 if (!newbus) { 59 if (!newbus) {
60 err ("out of system memory\n"); 60 err ("out of system memory\n");
61 return NULL; 61 return NULL;
62 } 62 }
63 63
64 memset (newbus, 0, sizeof (struct bus_node));
65 if (flag) 64 if (flag)
66 newbus->busno = busno; 65 newbus->busno = busno;
67 else 66 else
@@ -79,12 +78,11 @@ static struct resource_node * __init alloc_resources (struct ebda_pci_rsrc * cur
79 return NULL; 78 return NULL;
80 } 79 }
81 80
82 rs = kmalloc (sizeof (struct resource_node), GFP_KERNEL); 81 rs = kzalloc(sizeof(struct resource_node), GFP_KERNEL);
83 if (!rs) { 82 if (!rs) {
84 err ("out of system memory\n"); 83 err ("out of system memory\n");
85 return NULL; 84 return NULL;
86 } 85 }
87 memset (rs, 0, sizeof (struct resource_node));
88 rs->busno = curr->bus_num; 86 rs->busno = curr->bus_num;
89 rs->devfunc = curr->dev_fun; 87 rs->devfunc = curr->dev_fun;
90 rs->start = curr->start_addr; 88 rs->start = curr->start_addr;
@@ -100,12 +98,11 @@ static int __init alloc_bus_range (struct bus_node **new_bus, struct range_node
100 u8 num_ranges = 0; 98 u8 num_ranges = 0;
101 99
102 if (first_bus) { 100 if (first_bus) {
103 newbus = kmalloc (sizeof (struct bus_node), GFP_KERNEL); 101 newbus = kzalloc(sizeof(struct bus_node), GFP_KERNEL);
104 if (!newbus) { 102 if (!newbus) {
105 err ("out of system memory.\n"); 103 err ("out of system memory.\n");
106 return -ENOMEM; 104 return -ENOMEM;
107 } 105 }
108 memset (newbus, 0, sizeof (struct bus_node));
109 newbus->busno = curr->bus_num; 106 newbus->busno = curr->bus_num;
110 } else { 107 } else {
111 newbus = *new_bus; 108 newbus = *new_bus;
@@ -122,14 +119,13 @@ static int __init alloc_bus_range (struct bus_node **new_bus, struct range_node
122 } 119 }
123 } 120 }
124 121
125 newrange = kmalloc (sizeof (struct range_node), GFP_KERNEL); 122 newrange = kzalloc(sizeof(struct range_node), GFP_KERNEL);
126 if (!newrange) { 123 if (!newrange) {
127 if (first_bus) 124 if (first_bus)
128 kfree (newbus); 125 kfree (newbus);
129 err ("out of system memory\n"); 126 err ("out of system memory\n");
130 return -ENOMEM; 127 return -ENOMEM;
131 } 128 }
132 memset (newrange, 0, sizeof (struct range_node));
133 newrange->start = curr->start_addr; 129 newrange->start = curr->start_addr;
134 newrange->end = curr->end_addr; 130 newrange->end = curr->end_addr;
135 131
@@ -329,7 +325,7 @@ int __init ibmphp_rsrc_init (void)
329 if (!new_pfmem) 325 if (!new_pfmem)
330 return -ENOMEM; 326 return -ENOMEM;
331 new_pfmem->type = PFMEM; 327 new_pfmem->type = PFMEM;
332 new_pfmem->fromMem = FALSE; 328 new_pfmem->fromMem = 0;
333 if (ibmphp_add_resource (new_pfmem) < 0) { 329 if (ibmphp_add_resource (new_pfmem) < 0) {
334 newbus = alloc_error_bus (curr, 0, 0); 330 newbus = alloc_error_bus (curr, 0, 0);
335 if (!newbus) 331 if (!newbus)
@@ -466,7 +462,7 @@ static int add_range (int type, struct range_node *range, struct bus_node *bus_c
466static void update_resources (struct bus_node *bus_cur, int type, int rangeno) 462static void update_resources (struct bus_node *bus_cur, int type, int rangeno)
467{ 463{
468 struct resource_node *res = NULL; 464 struct resource_node *res = NULL;
469 u8 eol = FALSE; /* end of list indicator */ 465 u8 eol = 0; /* end of list indicator */
470 466
471 switch (type) { 467 switch (type) {
472 case MEM: 468 case MEM:
@@ -492,7 +488,7 @@ static void update_resources (struct bus_node *bus_cur, int type, int rangeno)
492 else if (res->nextRange) 488 else if (res->nextRange)
493 res = res->nextRange; 489 res = res->nextRange;
494 else { 490 else {
495 eol = TRUE; 491 eol = 1;
496 break; 492 break;
497 } 493 }
498 } 494 }
@@ -983,7 +979,7 @@ int ibmphp_check_resource (struct resource_node *res, u8 bridge)
983 int noranges = 0; 979 int noranges = 0;
984 u32 tmp_start; /* this is to make sure start address is divisible by the length needed */ 980 u32 tmp_start; /* this is to make sure start address is divisible by the length needed */
985 u32 tmp_divide; 981 u32 tmp_divide;
986 u8 flag = FALSE; 982 u8 flag = 0;
987 983
988 if (!res) 984 if (!res)
989 return -EINVAL; 985 return -EINVAL;
@@ -1050,17 +1046,17 @@ int ibmphp_check_resource (struct resource_node *res, u8 bridge)
1050 1046
1051 if ((range->start % tmp_divide) == 0) { 1047 if ((range->start % tmp_divide) == 0) {
1052 /* just perfect, starting address is divisible by length */ 1048 /* just perfect, starting address is divisible by length */
1053 flag = TRUE; 1049 flag = 1;
1054 len_cur = len_tmp; 1050 len_cur = len_tmp;
1055 start_cur = range->start; 1051 start_cur = range->start;
1056 } else { 1052 } else {
1057 /* Needs adjusting */ 1053 /* Needs adjusting */
1058 tmp_start = range->start; 1054 tmp_start = range->start;
1059 flag = FALSE; 1055 flag = 0;
1060 1056
1061 while ((len_tmp = res_cur->start - 1 - tmp_start) >= res->len) { 1057 while ((len_tmp = res_cur->start - 1 - tmp_start) >= res->len) {
1062 if ((tmp_start % tmp_divide) == 0) { 1058 if ((tmp_start % tmp_divide) == 0) {
1063 flag = TRUE; 1059 flag = 1;
1064 len_cur = len_tmp; 1060 len_cur = len_tmp;
1065 start_cur = tmp_start; 1061 start_cur = tmp_start;
1066 break; 1062 break;
@@ -1089,17 +1085,17 @@ int ibmphp_check_resource (struct resource_node *res, u8 bridge)
1089 1085
1090 if (((res_cur->end + 1) % tmp_divide) == 0) { 1086 if (((res_cur->end + 1) % tmp_divide) == 0) {
1091 /* just perfect, starting address is divisible by length */ 1087 /* just perfect, starting address is divisible by length */
1092 flag = TRUE; 1088 flag = 1;
1093 len_cur = len_tmp; 1089 len_cur = len_tmp;
1094 start_cur = res_cur->end + 1; 1090 start_cur = res_cur->end + 1;
1095 } else { 1091 } else {
1096 /* Needs adjusting */ 1092 /* Needs adjusting */
1097 tmp_start = res_cur->end + 1; 1093 tmp_start = res_cur->end + 1;
1098 flag = FALSE; 1094 flag = 0;
1099 1095
1100 while ((len_tmp = range->end - tmp_start) >= res->len) { 1096 while ((len_tmp = range->end - tmp_start) >= res->len) {
1101 if ((tmp_start % tmp_divide) == 0) { 1097 if ((tmp_start % tmp_divide) == 0) {
1102 flag = TRUE; 1098 flag = 1;
1103 len_cur = len_tmp; 1099 len_cur = len_tmp;
1104 start_cur = tmp_start; 1100 start_cur = tmp_start;
1105 break; 1101 break;
@@ -1127,17 +1123,17 @@ int ibmphp_check_resource (struct resource_node *res, u8 bridge)
1127 if ((len_tmp < len_cur) || (len_cur == 0)) { 1123 if ((len_tmp < len_cur) || (len_cur == 0)) {
1128 if ((range->start % tmp_divide) == 0) { 1124 if ((range->start % tmp_divide) == 0) {
1129 /* just perfect, starting address is divisible by length */ 1125 /* just perfect, starting address is divisible by length */
1130 flag = TRUE; 1126 flag = 1;
1131 len_cur = len_tmp; 1127 len_cur = len_tmp;
1132 start_cur = range->start; 1128 start_cur = range->start;
1133 } else { 1129 } else {
1134 /* Needs adjusting */ 1130 /* Needs adjusting */
1135 tmp_start = range->start; 1131 tmp_start = range->start;
1136 flag = FALSE; 1132 flag = 0;
1137 1133
1138 while ((len_tmp = res_cur->start - 1 - tmp_start) >= res->len) { 1134 while ((len_tmp = res_cur->start - 1 - tmp_start) >= res->len) {
1139 if ((tmp_start % tmp_divide) == 0) { 1135 if ((tmp_start % tmp_divide) == 0) {
1140 flag = TRUE; 1136 flag = 1;
1141 len_cur = len_tmp; 1137 len_cur = len_tmp;
1142 start_cur = tmp_start; 1138 start_cur = tmp_start;
1143 break; 1139 break;
@@ -1162,17 +1158,17 @@ int ibmphp_check_resource (struct resource_node *res, u8 bridge)
1162 if ((len_tmp < len_cur) || (len_cur == 0)) { 1158 if ((len_tmp < len_cur) || (len_cur == 0)) {
1163 if (((res_prev->end + 1) % tmp_divide) == 0) { 1159 if (((res_prev->end + 1) % tmp_divide) == 0) {
1164 /* just perfect, starting address's divisible by length */ 1160 /* just perfect, starting address's divisible by length */
1165 flag = TRUE; 1161 flag = 1;
1166 len_cur = len_tmp; 1162 len_cur = len_tmp;
1167 start_cur = res_prev->end + 1; 1163 start_cur = res_prev->end + 1;
1168 } else { 1164 } else {
1169 /* Needs adjusting */ 1165 /* Needs adjusting */
1170 tmp_start = res_prev->end + 1; 1166 tmp_start = res_prev->end + 1;
1171 flag = FALSE; 1167 flag = 0;
1172 1168
1173 while ((len_tmp = res_cur->start - 1 - tmp_start) >= res->len) { 1169 while ((len_tmp = res_cur->start - 1 - tmp_start) >= res->len) {
1174 if ((tmp_start % tmp_divide) == 0) { 1170 if ((tmp_start % tmp_divide) == 0) {
1175 flag = TRUE; 1171 flag = 1;
1176 len_cur = len_tmp; 1172 len_cur = len_tmp;
1177 start_cur = tmp_start; 1173 start_cur = tmp_start;
1178 break; 1174 break;
@@ -1221,17 +1217,17 @@ int ibmphp_check_resource (struct resource_node *res, u8 bridge)
1221 if ((len_tmp < len_cur) || (len_cur == 0)) { 1217 if ((len_tmp < len_cur) || (len_cur == 0)) {
1222 if ((range->start % tmp_divide) == 0) { 1218 if ((range->start % tmp_divide) == 0) {
1223 /* just perfect, starting address's divisible by length */ 1219 /* just perfect, starting address's divisible by length */
1224 flag = TRUE; 1220 flag = 1;
1225 len_cur = len_tmp; 1221 len_cur = len_tmp;
1226 start_cur = range->start; 1222 start_cur = range->start;
1227 } else { 1223 } else {
1228 /* Needs adjusting */ 1224 /* Needs adjusting */
1229 tmp_start = range->start; 1225 tmp_start = range->start;
1230 flag = FALSE; 1226 flag = 0;
1231 1227
1232 while ((len_tmp = range->end - tmp_start) >= res->len) { 1228 while ((len_tmp = range->end - tmp_start) >= res->len) {
1233 if ((tmp_start % tmp_divide) == 0) { 1229 if ((tmp_start % tmp_divide) == 0) {
1234 flag = TRUE; 1230 flag = 1;
1235 len_cur = len_tmp; 1231 len_cur = len_tmp;
1236 start_cur = tmp_start; 1232 start_cur = tmp_start;
1237 break; 1233 break;
@@ -1285,17 +1281,17 @@ int ibmphp_check_resource (struct resource_node *res, u8 bridge)
1285 if ((len_tmp < len_cur) || (len_cur == 0)) { 1281 if ((len_tmp < len_cur) || (len_cur == 0)) {
1286 if ((range->start % tmp_divide) == 0) { 1282 if ((range->start % tmp_divide) == 0) {
1287 /* just perfect, starting address's divisible by length */ 1283 /* just perfect, starting address's divisible by length */
1288 flag = TRUE; 1284 flag = 1;
1289 len_cur = len_tmp; 1285 len_cur = len_tmp;
1290 start_cur = range->start; 1286 start_cur = range->start;
1291 } else { 1287 } else {
1292 /* Needs adjusting */ 1288 /* Needs adjusting */
1293 tmp_start = range->start; 1289 tmp_start = range->start;
1294 flag = FALSE; 1290 flag = 0;
1295 1291
1296 while ((len_tmp = range->end - tmp_start) >= res->len) { 1292 while ((len_tmp = range->end - tmp_start) >= res->len) {
1297 if ((tmp_start % tmp_divide) == 0) { 1293 if ((tmp_start % tmp_divide) == 0) {
1298 flag = TRUE; 1294 flag = 1;
1299 len_cur = len_tmp; 1295 len_cur = len_tmp;
1300 start_cur = tmp_start; 1296 start_cur = tmp_start;
1301 break; 1297 break;
@@ -1688,7 +1684,7 @@ static int __init once_over (void)
1688 bus_cur = list_entry (tmp, struct bus_node, bus_list); 1684 bus_cur = list_entry (tmp, struct bus_node, bus_list);
1689 if ((!bus_cur->rangePFMem) && (bus_cur->firstPFMem)) { 1685 if ((!bus_cur->rangePFMem) && (bus_cur->firstPFMem)) {
1690 for (pfmem_cur = bus_cur->firstPFMem, pfmem_prev = NULL; pfmem_cur; pfmem_prev = pfmem_cur, pfmem_cur = pfmem_cur->next) { 1686 for (pfmem_cur = bus_cur->firstPFMem, pfmem_prev = NULL; pfmem_cur; pfmem_prev = pfmem_cur, pfmem_cur = pfmem_cur->next) {
1691 pfmem_cur->fromMem = TRUE; 1687 pfmem_cur->fromMem = 1;
1692 if (pfmem_prev) 1688 if (pfmem_prev)
1693 pfmem_prev->next = pfmem_cur->next; 1689 pfmem_prev->next = pfmem_cur->next;
1694 else 1690 else
@@ -1705,12 +1701,11 @@ static int __init once_over (void)
1705 1701
1706 bus_cur->firstPFMemFromMem = pfmem_cur; 1702 bus_cur->firstPFMemFromMem = pfmem_cur;
1707 1703
1708 mem = kmalloc (sizeof (struct resource_node), GFP_KERNEL); 1704 mem = kzalloc(sizeof(struct resource_node), GFP_KERNEL);
1709 if (!mem) { 1705 if (!mem) {
1710 err ("out of system memory\n"); 1706 err ("out of system memory\n");
1711 return -ENOMEM; 1707 return -ENOMEM;
1712 } 1708 }
1713 memset (mem, 0, sizeof (struct resource_node));
1714 mem->type = MEM; 1709 mem->type = MEM;
1715 mem->busno = pfmem_cur->busno; 1710 mem->busno = pfmem_cur->busno;
1716 mem->devfunc = pfmem_cur->devfunc; 1711 mem->devfunc = pfmem_cur->devfunc;
@@ -1994,12 +1989,11 @@ static int __init update_bridge_ranges (struct bus_node **bus)
1994 end_address |= (upper_io_end << 16); 1989 end_address |= (upper_io_end << 16);
1995 1990
1996 if ((start_address) && (start_address <= end_address)) { 1991 if ((start_address) && (start_address <= end_address)) {
1997 range = kmalloc (sizeof (struct range_node), GFP_KERNEL); 1992 range = kzalloc(sizeof(struct range_node), GFP_KERNEL);
1998 if (!range) { 1993 if (!range) {
1999 err ("out of system memory\n"); 1994 err ("out of system memory\n");
2000 return -ENOMEM; 1995 return -ENOMEM;
2001 } 1996 }
2002 memset (range, 0, sizeof (struct range_node));
2003 range->start = start_address; 1997 range->start = start_address;
2004 range->end = end_address + 0xfff; 1998 range->end = end_address + 0xfff;
2005 1999
@@ -2020,13 +2014,12 @@ static int __init update_bridge_ranges (struct bus_node **bus)
2020 fix_resources (bus_sec); 2014 fix_resources (bus_sec);
2021 2015
2022 if (ibmphp_find_resource (bus_cur, start_address, &io, IO)) { 2016 if (ibmphp_find_resource (bus_cur, start_address, &io, IO)) {
2023 io = kmalloc (sizeof (struct resource_node), GFP_KERNEL); 2017 io = kzalloc(sizeof(struct resource_node), GFP_KERNEL);
2024 if (!io) { 2018 if (!io) {
2025 kfree (range); 2019 kfree (range);
2026 err ("out of system memory\n"); 2020 err ("out of system memory\n");
2027 return -ENOMEM; 2021 return -ENOMEM;
2028 } 2022 }
2029 memset (io, 0, sizeof (struct resource_node));
2030 io->type = IO; 2023 io->type = IO;
2031 io->busno = bus_cur->busno; 2024 io->busno = bus_cur->busno;
2032 io->devfunc = ((device << 3) | (function & 0x7)); 2025 io->devfunc = ((device << 3) | (function & 0x7));
@@ -2045,12 +2038,11 @@ static int __init update_bridge_ranges (struct bus_node **bus)
2045 2038
2046 if ((start_address) && (start_address <= end_address)) { 2039 if ((start_address) && (start_address <= end_address)) {
2047 2040
2048 range = kmalloc (sizeof (struct range_node), GFP_KERNEL); 2041 range = kzalloc(sizeof(struct range_node), GFP_KERNEL);
2049 if (!range) { 2042 if (!range) {
2050 err ("out of system memory\n"); 2043 err ("out of system memory\n");
2051 return -ENOMEM; 2044 return -ENOMEM;
2052 } 2045 }
2053 memset (range, 0, sizeof (struct range_node));
2054 range->start = start_address; 2046 range->start = start_address;
2055 range->end = end_address + 0xfffff; 2047 range->end = end_address + 0xfffff;
2056 2048
@@ -2072,13 +2064,12 @@ static int __init update_bridge_ranges (struct bus_node **bus)
2072 fix_resources (bus_sec); 2064 fix_resources (bus_sec);
2073 2065
2074 if (ibmphp_find_resource (bus_cur, start_address, &mem, MEM)) { 2066 if (ibmphp_find_resource (bus_cur, start_address, &mem, MEM)) {
2075 mem = kmalloc (sizeof (struct resource_node), GFP_KERNEL); 2067 mem = kzalloc(sizeof(struct resource_node), GFP_KERNEL);
2076 if (!mem) { 2068 if (!mem) {
2077 kfree (range); 2069 kfree (range);
2078 err ("out of system memory\n"); 2070 err ("out of system memory\n");
2079 return -ENOMEM; 2071 return -ENOMEM;
2080 } 2072 }
2081 memset (mem, 0, sizeof (struct resource_node));
2082 mem->type = MEM; 2073 mem->type = MEM;
2083 mem->busno = bus_cur->busno; 2074 mem->busno = bus_cur->busno;
2084 mem->devfunc = ((device << 3) | (function & 0x7)); 2075 mem->devfunc = ((device << 3) | (function & 0x7));
@@ -2101,12 +2092,11 @@ static int __init update_bridge_ranges (struct bus_node **bus)
2101 2092
2102 if ((start_address) && (start_address <= end_address)) { 2093 if ((start_address) && (start_address <= end_address)) {
2103 2094
2104 range = kmalloc (sizeof (struct range_node), GFP_KERNEL); 2095 range = kzalloc(sizeof(struct range_node), GFP_KERNEL);
2105 if (!range) { 2096 if (!range) {
2106 err ("out of system memory\n"); 2097 err ("out of system memory\n");
2107 return -ENOMEM; 2098 return -ENOMEM;
2108 } 2099 }
2109 memset (range, 0, sizeof (struct range_node));
2110 range->start = start_address; 2100 range->start = start_address;
2111 range->end = end_address + 0xfffff; 2101 range->end = end_address + 0xfffff;
2112 2102
@@ -2127,20 +2117,19 @@ static int __init update_bridge_ranges (struct bus_node **bus)
2127 2117
2128 fix_resources (bus_sec); 2118 fix_resources (bus_sec);
2129 if (ibmphp_find_resource (bus_cur, start_address, &pfmem, PFMEM)) { 2119 if (ibmphp_find_resource (bus_cur, start_address, &pfmem, PFMEM)) {
2130 pfmem = kmalloc (sizeof (struct resource_node), GFP_KERNEL); 2120 pfmem = kzalloc(sizeof(struct resource_node), GFP_KERNEL);
2131 if (!pfmem) { 2121 if (!pfmem) {
2132 kfree (range); 2122 kfree (range);
2133 err ("out of system memory\n"); 2123 err ("out of system memory\n");
2134 return -ENOMEM; 2124 return -ENOMEM;
2135 } 2125 }
2136 memset (pfmem, 0, sizeof (struct resource_node));
2137 pfmem->type = PFMEM; 2126 pfmem->type = PFMEM;
2138 pfmem->busno = bus_cur->busno; 2127 pfmem->busno = bus_cur->busno;
2139 pfmem->devfunc = ((device << 3) | (function & 0x7)); 2128 pfmem->devfunc = ((device << 3) | (function & 0x7));
2140 pfmem->start = start_address; 2129 pfmem->start = start_address;
2141 pfmem->end = end_address + 0xfffff; 2130 pfmem->end = end_address + 0xfffff;
2142 pfmem->len = pfmem->end - pfmem->start + 1; 2131 pfmem->len = pfmem->end - pfmem->start + 1;
2143 pfmem->fromMem = FALSE; 2132 pfmem->fromMem = 0;
2144 2133
2145 ibmphp_add_resource (pfmem); 2134 ibmphp_add_resource (pfmem);
2146 } 2135 }
diff --git a/drivers/pci/hotplug/pci_hotplug.h b/drivers/pci/hotplug/pci_hotplug.h
index 88d44f7fef..eb0d01d472 100644
--- a/drivers/pci/hotplug/pci_hotplug.h
+++ b/drivers/pci/hotplug/pci_hotplug.h
@@ -176,5 +176,21 @@ extern int pci_hp_change_slot_info (struct hotplug_slot *slot,
176 struct hotplug_slot_info *info); 176 struct hotplug_slot_info *info);
177extern struct subsystem pci_hotplug_slots_subsys; 177extern struct subsystem pci_hotplug_slots_subsys;
178 178
179struct hotplug_params {
180 u8 cache_line_size;
181 u8 latency_timer;
182 u8 enable_serr;
183 u8 enable_perr;
184};
185
186#ifdef CONFIG_ACPI
187#include <acpi/acpi.h>
188#include <acpi/acpi_bus.h>
189#include <acpi/actypes.h>
190extern acpi_status acpi_run_oshp(acpi_handle handle);
191extern acpi_status acpi_get_hp_params_from_firmware(struct pci_dev *dev,
192 struct hotplug_params *hpp);
193int acpi_root_bridge(acpi_handle handle);
194#endif
179#endif 195#endif
180 196
diff --git a/drivers/pci/hotplug/pciehp.h b/drivers/pci/hotplug/pciehp.h
index 0aac6a6133..92c1f0f1e1 100644
--- a/drivers/pci/hotplug/pciehp.h
+++ b/drivers/pci/hotplug/pciehp.h
@@ -34,6 +34,7 @@
34#include <linux/delay.h> 34#include <linux/delay.h>
35#include <linux/sched.h> /* signal_pending() */ 35#include <linux/sched.h> /* signal_pending() */
36#include <linux/pcieport_if.h> 36#include <linux/pcieport_if.h>
37#include <linux/mutex.h>
37#include "pci_hotplug.h" 38#include "pci_hotplug.h"
38 39
39#define MY_NAME "pciehp" 40#define MY_NAME "pciehp"
@@ -49,12 +50,6 @@ extern int pciehp_force;
49#define info(format, arg...) printk(KERN_INFO "%s: " format, MY_NAME , ## arg) 50#define info(format, arg...) printk(KERN_INFO "%s: " format, MY_NAME , ## arg)
50#define warn(format, arg...) printk(KERN_WARNING "%s: " format, MY_NAME , ## arg) 51#define warn(format, arg...) printk(KERN_WARNING "%s: " format, MY_NAME , ## arg)
51 52
52struct hotplug_params {
53 u8 cache_line_size;
54 u8 latency_timer;
55 u8 enable_serr;
56 u8 enable_perr;
57};
58 53
59struct slot { 54struct slot {
60 struct slot *next; 55 struct slot *next;
@@ -96,7 +91,7 @@ struct php_ctlr_state_s {
96#define MAX_EVENTS 10 91#define MAX_EVENTS 10
97struct controller { 92struct controller {
98 struct controller *next; 93 struct controller *next;
99 struct semaphore crit_sect; /* critical section semaphore */ 94 struct mutex crit_sect; /* critical section mutex */
100 struct php_ctlr_state_s *hpc_ctlr_handle; /* HPC controller handle */ 95 struct php_ctlr_state_s *hpc_ctlr_handle; /* HPC controller handle */
101 int num_slots; /* Number of slots on ctlr */ 96 int num_slots; /* Number of slots on ctlr */
102 int slot_num_inc; /* 1 or -1 */ 97 int slot_num_inc; /* 1 or -1 */
@@ -191,9 +186,6 @@ extern u8 pciehp_handle_power_fault (u8 hp_slot, void *inst_id);
191/* pci functions */ 186/* pci functions */
192extern int pciehp_configure_device (struct slot *p_slot); 187extern int pciehp_configure_device (struct slot *p_slot);
193extern int pciehp_unconfigure_device (struct slot *p_slot); 188extern int pciehp_unconfigure_device (struct slot *p_slot);
194extern int pciehp_get_hp_hw_control_from_firmware(struct pci_dev *dev);
195extern void pciehp_get_hp_params_from_firmware(struct pci_dev *dev,
196 struct hotplug_params *hpp);
197 189
198 190
199 191
@@ -285,4 +277,19 @@ struct hpc_ops {
285 int (*check_lnk_status) (struct controller *ctrl); 277 int (*check_lnk_status) (struct controller *ctrl);
286}; 278};
287 279
280
281#ifdef CONFIG_ACPI
282#define pciehp_get_hp_hw_control_from_firmware(dev) \
283 pciehp_acpi_get_hp_hw_control_from_firmware(dev)
284static inline int pciehp_get_hp_params_from_firmware(struct pci_dev *dev,
285 struct hotplug_params *hpp)
286{
287 if (ACPI_FAILURE(acpi_get_hp_params_from_firmware(dev, hpp)))
288 return -ENODEV;
289 return 0;
290}
291#else
292#define pciehp_get_hp_hw_control_from_firmware(dev) 0
293#define pciehp_get_hp_params_from_firmware(dev, hpp) (-ENODEV)
294#endif /* CONFIG_ACPI */
288#endif /* _PCIEHP_H */ 295#endif /* _PCIEHP_H */
diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
index 4fb569018a..601cf9045b 100644
--- a/drivers/pci/hotplug/pciehp_core.c
+++ b/drivers/pci/hotplug/pciehp_core.c
@@ -117,27 +117,23 @@ static int init_slots(struct controller *ctrl)
117 slot_number = ctrl->first_slot; 117 slot_number = ctrl->first_slot;
118 118
119 while (number_of_slots) { 119 while (number_of_slots) {
120 slot = kmalloc(sizeof(*slot), GFP_KERNEL); 120 slot = kzalloc(sizeof(*slot), GFP_KERNEL);
121 if (!slot) 121 if (!slot)
122 goto error; 122 goto error;
123 123
124 memset(slot, 0, sizeof(struct slot));
125 slot->hotplug_slot = 124 slot->hotplug_slot =
126 kmalloc(sizeof(*(slot->hotplug_slot)), 125 kzalloc(sizeof(*(slot->hotplug_slot)),
127 GFP_KERNEL); 126 GFP_KERNEL);
128 if (!slot->hotplug_slot) 127 if (!slot->hotplug_slot)
129 goto error_slot; 128 goto error_slot;
130 hotplug_slot = slot->hotplug_slot; 129 hotplug_slot = slot->hotplug_slot;
131 memset(hotplug_slot, 0, sizeof(struct hotplug_slot));
132 130
133 hotplug_slot->info = 131 hotplug_slot->info =
134 kmalloc(sizeof(*(hotplug_slot->info)), 132 kzalloc(sizeof(*(hotplug_slot->info)),
135 GFP_KERNEL); 133 GFP_KERNEL);
136 if (!hotplug_slot->info) 134 if (!hotplug_slot->info)
137 goto error_hpslot; 135 goto error_hpslot;
138 hotplug_slot_info = hotplug_slot->info; 136 hotplug_slot_info = hotplug_slot->info;
139 memset(hotplug_slot_info, 0,
140 sizeof(struct hotplug_slot_info));
141 hotplug_slot->name = kmalloc(SLOT_NAME_SIZE, GFP_KERNEL); 137 hotplug_slot->name = kmalloc(SLOT_NAME_SIZE, GFP_KERNEL);
142 if (!hotplug_slot->name) 138 if (!hotplug_slot->name)
143 goto error_info; 139 goto error_info;
@@ -373,12 +369,11 @@ static int pciehp_probe(struct pcie_device *dev, const struct pcie_port_service_
373 u8 value; 369 u8 value;
374 struct pci_dev *pdev; 370 struct pci_dev *pdev;
375 371
376 ctrl = kmalloc(sizeof(*ctrl), GFP_KERNEL); 372 ctrl = kzalloc(sizeof(*ctrl), GFP_KERNEL);
377 if (!ctrl) { 373 if (!ctrl) {
378 err("%s : out of memory\n", __FUNCTION__); 374 err("%s : out of memory\n", __FUNCTION__);
379 goto err_out_none; 375 goto err_out_none;
380 } 376 }
381 memset(ctrl, 0, sizeof(struct controller));
382 377
383 pdev = dev->port; 378 pdev = dev->port;
384 ctrl->pci_dev = pdev; 379 ctrl->pci_dev = pdev;
@@ -439,7 +434,7 @@ static int pciehp_probe(struct pcie_device *dev, const struct pcie_port_service_
439 } 434 }
440 435
441 /* Wait for exclusive access to hardware */ 436 /* Wait for exclusive access to hardware */
442 down(&ctrl->crit_sect); 437 mutex_lock(&ctrl->crit_sect);
443 438
444 t_slot->hpc_ops->get_adapter_status(t_slot, &value); /* Check if slot is occupied */ 439 t_slot->hpc_ops->get_adapter_status(t_slot, &value); /* Check if slot is occupied */
445 440
@@ -447,7 +442,7 @@ static int pciehp_probe(struct pcie_device *dev, const struct pcie_port_service_
447 rc = t_slot->hpc_ops->power_off_slot(t_slot); /* Power off slot if not occupied*/ 442 rc = t_slot->hpc_ops->power_off_slot(t_slot); /* Power off slot if not occupied*/
448 if (rc) { 443 if (rc) {
449 /* Done with exclusive hardware access */ 444 /* Done with exclusive hardware access */
450 up(&ctrl->crit_sect); 445 mutex_unlock(&ctrl->crit_sect);
451 goto err_out_free_ctrl_slot; 446 goto err_out_free_ctrl_slot;
452 } else 447 } else
453 /* Wait for the command to complete */ 448 /* Wait for the command to complete */
@@ -455,7 +450,7 @@ static int pciehp_probe(struct pcie_device *dev, const struct pcie_port_service_
455 } 450 }
456 451
457 /* Done with exclusive hardware access */ 452 /* Done with exclusive hardware access */
458 up(&ctrl->crit_sect); 453 mutex_unlock(&ctrl->crit_sect);
459 454
460 return 0; 455 return 0;
461 456
diff --git a/drivers/pci/hotplug/pciehp_ctrl.c b/drivers/pci/hotplug/pciehp_ctrl.c
index 83c4b86571..33d1987683 100644
--- a/drivers/pci/hotplug/pciehp_ctrl.c
+++ b/drivers/pci/hotplug/pciehp_ctrl.c
@@ -229,13 +229,13 @@ u8 pciehp_handle_power_fault(u8 hp_slot, void *inst_id)
229static void set_slot_off(struct controller *ctrl, struct slot * pslot) 229static void set_slot_off(struct controller *ctrl, struct slot * pslot)
230{ 230{
231 /* Wait for exclusive access to hardware */ 231 /* Wait for exclusive access to hardware */
232 down(&ctrl->crit_sect); 232 mutex_lock(&ctrl->crit_sect);
233 233
234 /* turn off slot, turn on Amber LED, turn off Green LED if supported*/ 234 /* turn off slot, turn on Amber LED, turn off Green LED if supported*/
235 if (POWER_CTRL(ctrl->ctrlcap)) { 235 if (POWER_CTRL(ctrl->ctrlcap)) {
236 if (pslot->hpc_ops->power_off_slot(pslot)) { 236 if (pslot->hpc_ops->power_off_slot(pslot)) {
237 err("%s: Issue of Slot Power Off command failed\n", __FUNCTION__); 237 err("%s: Issue of Slot Power Off command failed\n", __FUNCTION__);
238 up(&ctrl->crit_sect); 238 mutex_unlock(&ctrl->crit_sect);
239 return; 239 return;
240 } 240 }
241 wait_for_ctrl_irq (ctrl); 241 wait_for_ctrl_irq (ctrl);
@@ -249,14 +249,14 @@ static void set_slot_off(struct controller *ctrl, struct slot * pslot)
249 if (ATTN_LED(ctrl->ctrlcap)) { 249 if (ATTN_LED(ctrl->ctrlcap)) {
250 if (pslot->hpc_ops->set_attention_status(pslot, 1)) { 250 if (pslot->hpc_ops->set_attention_status(pslot, 1)) {
251 err("%s: Issue of Set Attention Led command failed\n", __FUNCTION__); 251 err("%s: Issue of Set Attention Led command failed\n", __FUNCTION__);
252 up(&ctrl->crit_sect); 252 mutex_unlock(&ctrl->crit_sect);
253 return; 253 return;
254 } 254 }
255 wait_for_ctrl_irq (ctrl); 255 wait_for_ctrl_irq (ctrl);
256 } 256 }
257 257
258 /* Done with exclusive hardware access */ 258 /* Done with exclusive hardware access */
259 up(&ctrl->crit_sect); 259 mutex_unlock(&ctrl->crit_sect);
260} 260}
261 261
262/** 262/**
@@ -279,13 +279,13 @@ static int board_added(struct slot *p_slot)
279 ctrl->slot_device_offset, hp_slot); 279 ctrl->slot_device_offset, hp_slot);
280 280
281 /* Wait for exclusive access to hardware */ 281 /* Wait for exclusive access to hardware */
282 down(&ctrl->crit_sect); 282 mutex_lock(&ctrl->crit_sect);
283 283
284 if (POWER_CTRL(ctrl->ctrlcap)) { 284 if (POWER_CTRL(ctrl->ctrlcap)) {
285 /* Power on slot */ 285 /* Power on slot */
286 rc = p_slot->hpc_ops->power_on_slot(p_slot); 286 rc = p_slot->hpc_ops->power_on_slot(p_slot);
287 if (rc) { 287 if (rc) {
288 up(&ctrl->crit_sect); 288 mutex_unlock(&ctrl->crit_sect);
289 return -1; 289 return -1;
290 } 290 }
291 291
@@ -301,7 +301,7 @@ static int board_added(struct slot *p_slot)
301 } 301 }
302 302
303 /* Done with exclusive hardware access */ 303 /* Done with exclusive hardware access */
304 up(&ctrl->crit_sect); 304 mutex_unlock(&ctrl->crit_sect);
305 305
306 /* Wait for ~1 second */ 306 /* Wait for ~1 second */
307 wait_for_ctrl_irq (ctrl); 307 wait_for_ctrl_irq (ctrl);
@@ -335,7 +335,7 @@ static int board_added(struct slot *p_slot)
335 pci_fixup_device(pci_fixup_final, ctrl->pci_dev); 335 pci_fixup_device(pci_fixup_final, ctrl->pci_dev);
336 if (PWR_LED(ctrl->ctrlcap)) { 336 if (PWR_LED(ctrl->ctrlcap)) {
337 /* Wait for exclusive access to hardware */ 337 /* Wait for exclusive access to hardware */
338 down(&ctrl->crit_sect); 338 mutex_lock(&ctrl->crit_sect);
339 339
340 p_slot->hpc_ops->green_led_on(p_slot); 340 p_slot->hpc_ops->green_led_on(p_slot);
341 341
@@ -343,7 +343,7 @@ static int board_added(struct slot *p_slot)
343 wait_for_ctrl_irq (ctrl); 343 wait_for_ctrl_irq (ctrl);
344 344
345 /* Done with exclusive hardware access */ 345 /* Done with exclusive hardware access */
346 up(&ctrl->crit_sect); 346 mutex_unlock(&ctrl->crit_sect);
347 } 347 }
348 return 0; 348 return 0;
349 349
@@ -375,14 +375,14 @@ static int remove_board(struct slot *p_slot)
375 dbg("In %s, hp_slot = %d\n", __FUNCTION__, hp_slot); 375 dbg("In %s, hp_slot = %d\n", __FUNCTION__, hp_slot);
376 376
377 /* Wait for exclusive access to hardware */ 377 /* Wait for exclusive access to hardware */
378 down(&ctrl->crit_sect); 378 mutex_lock(&ctrl->crit_sect);
379 379
380 if (POWER_CTRL(ctrl->ctrlcap)) { 380 if (POWER_CTRL(ctrl->ctrlcap)) {
381 /* power off slot */ 381 /* power off slot */
382 rc = p_slot->hpc_ops->power_off_slot(p_slot); 382 rc = p_slot->hpc_ops->power_off_slot(p_slot);
383 if (rc) { 383 if (rc) {
384 err("%s: Issue of Slot Disable command failed\n", __FUNCTION__); 384 err("%s: Issue of Slot Disable command failed\n", __FUNCTION__);
385 up(&ctrl->crit_sect); 385 mutex_unlock(&ctrl->crit_sect);
386 return rc; 386 return rc;
387 } 387 }
388 /* Wait for the command to complete */ 388 /* Wait for the command to complete */
@@ -398,7 +398,7 @@ static int remove_board(struct slot *p_slot)
398 } 398 }
399 399
400 /* Done with exclusive hardware access */ 400 /* Done with exclusive hardware access */
401 up(&ctrl->crit_sect); 401 mutex_unlock(&ctrl->crit_sect);
402 402
403 return 0; 403 return 0;
404} 404}
@@ -445,7 +445,7 @@ static void pciehp_pushbutton_thread(unsigned long slot)
445 445
446 if (pciehp_enable_slot(p_slot) && PWR_LED(p_slot->ctrl->ctrlcap)) { 446 if (pciehp_enable_slot(p_slot) && PWR_LED(p_slot->ctrl->ctrlcap)) {
447 /* Wait for exclusive access to hardware */ 447 /* Wait for exclusive access to hardware */
448 down(&p_slot->ctrl->crit_sect); 448 mutex_lock(&p_slot->ctrl->crit_sect);
449 449
450 p_slot->hpc_ops->green_led_off(p_slot); 450 p_slot->hpc_ops->green_led_off(p_slot);
451 451
@@ -453,7 +453,7 @@ static void pciehp_pushbutton_thread(unsigned long slot)
453 wait_for_ctrl_irq (p_slot->ctrl); 453 wait_for_ctrl_irq (p_slot->ctrl);
454 454
455 /* Done with exclusive hardware access */ 455 /* Done with exclusive hardware access */
456 up(&p_slot->ctrl->crit_sect); 456 mutex_unlock(&p_slot->ctrl->crit_sect);
457 } 457 }
458 p_slot->state = STATIC_STATE; 458 p_slot->state = STATIC_STATE;
459 } 459 }
@@ -495,7 +495,7 @@ static void pciehp_surprise_rm_thread(unsigned long slot)
495 495
496 if (pciehp_enable_slot(p_slot) && PWR_LED(p_slot->ctrl->ctrlcap)) { 496 if (pciehp_enable_slot(p_slot) && PWR_LED(p_slot->ctrl->ctrlcap)) {
497 /* Wait for exclusive access to hardware */ 497 /* Wait for exclusive access to hardware */
498 down(&p_slot->ctrl->crit_sect); 498 mutex_lock(&p_slot->ctrl->crit_sect);
499 499
500 p_slot->hpc_ops->green_led_off(p_slot); 500 p_slot->hpc_ops->green_led_off(p_slot);
501 501
@@ -503,7 +503,7 @@ static void pciehp_surprise_rm_thread(unsigned long slot)
503 wait_for_ctrl_irq (p_slot->ctrl); 503 wait_for_ctrl_irq (p_slot->ctrl);
504 504
505 /* Done with exclusive hardware access */ 505 /* Done with exclusive hardware access */
506 up(&p_slot->ctrl->crit_sect); 506 mutex_unlock(&p_slot->ctrl->crit_sect);
507 } 507 }
508 p_slot->state = STATIC_STATE; 508 p_slot->state = STATIC_STATE;
509 } 509 }
@@ -616,7 +616,7 @@ static void interrupt_event_handler(struct controller *ctrl)
616 switch (p_slot->state) { 616 switch (p_slot->state) {
617 case BLINKINGOFF_STATE: 617 case BLINKINGOFF_STATE:
618 /* Wait for exclusive access to hardware */ 618 /* Wait for exclusive access to hardware */
619 down(&ctrl->crit_sect); 619 mutex_lock(&ctrl->crit_sect);
620 620
621 if (PWR_LED(ctrl->ctrlcap)) { 621 if (PWR_LED(ctrl->ctrlcap)) {
622 p_slot->hpc_ops->green_led_on(p_slot); 622 p_slot->hpc_ops->green_led_on(p_slot);
@@ -630,11 +630,11 @@ static void interrupt_event_handler(struct controller *ctrl)
630 wait_for_ctrl_irq (ctrl); 630 wait_for_ctrl_irq (ctrl);
631 } 631 }
632 /* Done with exclusive hardware access */ 632 /* Done with exclusive hardware access */
633 up(&ctrl->crit_sect); 633 mutex_unlock(&ctrl->crit_sect);
634 break; 634 break;
635 case BLINKINGON_STATE: 635 case BLINKINGON_STATE:
636 /* Wait for exclusive access to hardware */ 636 /* Wait for exclusive access to hardware */
637 down(&ctrl->crit_sect); 637 mutex_lock(&ctrl->crit_sect);
638 638
639 if (PWR_LED(ctrl->ctrlcap)) { 639 if (PWR_LED(ctrl->ctrlcap)) {
640 p_slot->hpc_ops->green_led_off(p_slot); 640 p_slot->hpc_ops->green_led_off(p_slot);
@@ -647,7 +647,7 @@ static void interrupt_event_handler(struct controller *ctrl)
647 wait_for_ctrl_irq (ctrl); 647 wait_for_ctrl_irq (ctrl);
648 } 648 }
649 /* Done with exclusive hardware access */ 649 /* Done with exclusive hardware access */
650 up(&ctrl->crit_sect); 650 mutex_unlock(&ctrl->crit_sect);
651 651
652 break; 652 break;
653 default: 653 default:
@@ -676,7 +676,7 @@ static void interrupt_event_handler(struct controller *ctrl)
676 } 676 }
677 677
678 /* Wait for exclusive access to hardware */ 678 /* Wait for exclusive access to hardware */
679 down(&ctrl->crit_sect); 679 mutex_lock(&ctrl->crit_sect);
680 680
681 /* blink green LED and turn off amber */ 681 /* blink green LED and turn off amber */
682 if (PWR_LED(ctrl->ctrlcap)) { 682 if (PWR_LED(ctrl->ctrlcap)) {
@@ -693,7 +693,7 @@ static void interrupt_event_handler(struct controller *ctrl)
693 } 693 }
694 694
695 /* Done with exclusive hardware access */ 695 /* Done with exclusive hardware access */
696 up(&ctrl->crit_sect); 696 mutex_unlock(&ctrl->crit_sect);
697 697
698 init_timer(&p_slot->task_event); 698 init_timer(&p_slot->task_event);
699 p_slot->task_event.expires = jiffies + 5 * HZ; /* 5 second delay */ 699 p_slot->task_event.expires = jiffies + 5 * HZ; /* 5 second delay */
@@ -708,7 +708,7 @@ static void interrupt_event_handler(struct controller *ctrl)
708 if (POWER_CTRL(ctrl->ctrlcap)) { 708 if (POWER_CTRL(ctrl->ctrlcap)) {
709 dbg("power fault\n"); 709 dbg("power fault\n");
710 /* Wait for exclusive access to hardware */ 710 /* Wait for exclusive access to hardware */
711 down(&ctrl->crit_sect); 711 mutex_lock(&ctrl->crit_sect);
712 712
713 if (ATTN_LED(ctrl->ctrlcap)) { 713 if (ATTN_LED(ctrl->ctrlcap)) {
714 p_slot->hpc_ops->set_attention_status(p_slot, 1); 714 p_slot->hpc_ops->set_attention_status(p_slot, 1);
@@ -721,7 +721,7 @@ static void interrupt_event_handler(struct controller *ctrl)
721 } 721 }
722 722
723 /* Done with exclusive hardware access */ 723 /* Done with exclusive hardware access */
724 up(&ctrl->crit_sect); 724 mutex_unlock(&ctrl->crit_sect);
725 } 725 }
726 } 726 }
727 /***********SURPRISE REMOVAL********************/ 727 /***********SURPRISE REMOVAL********************/
@@ -756,19 +756,19 @@ int pciehp_enable_slot(struct slot *p_slot)
756 int rc; 756 int rc;
757 757
758 /* Check to see if (latch closed, card present, power off) */ 758 /* Check to see if (latch closed, card present, power off) */
759 down(&p_slot->ctrl->crit_sect); 759 mutex_lock(&p_slot->ctrl->crit_sect);
760 760
761 rc = p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus); 761 rc = p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus);
762 if (rc || !getstatus) { 762 if (rc || !getstatus) {
763 info("%s: no adapter on slot(%x)\n", __FUNCTION__, p_slot->number); 763 info("%s: no adapter on slot(%x)\n", __FUNCTION__, p_slot->number);
764 up(&p_slot->ctrl->crit_sect); 764 mutex_unlock(&p_slot->ctrl->crit_sect);
765 return 1; 765 return 1;
766 } 766 }
767 if (MRL_SENS(p_slot->ctrl->ctrlcap)) { 767 if (MRL_SENS(p_slot->ctrl->ctrlcap)) {
768 rc = p_slot->hpc_ops->get_latch_status(p_slot, &getstatus); 768 rc = p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
769 if (rc || getstatus) { 769 if (rc || getstatus) {
770 info("%s: latch open on slot(%x)\n", __FUNCTION__, p_slot->number); 770 info("%s: latch open on slot(%x)\n", __FUNCTION__, p_slot->number);
771 up(&p_slot->ctrl->crit_sect); 771 mutex_unlock(&p_slot->ctrl->crit_sect);
772 return 1; 772 return 1;
773 } 773 }
774 } 774 }
@@ -777,11 +777,11 @@ int pciehp_enable_slot(struct slot *p_slot)
777 rc = p_slot->hpc_ops->get_power_status(p_slot, &getstatus); 777 rc = p_slot->hpc_ops->get_power_status(p_slot, &getstatus);
778 if (rc || getstatus) { 778 if (rc || getstatus) {
779 info("%s: already enabled on slot(%x)\n", __FUNCTION__, p_slot->number); 779 info("%s: already enabled on slot(%x)\n", __FUNCTION__, p_slot->number);
780 up(&p_slot->ctrl->crit_sect); 780 mutex_unlock(&p_slot->ctrl->crit_sect);
781 return 1; 781 return 1;
782 } 782 }
783 } 783 }
784 up(&p_slot->ctrl->crit_sect); 784 mutex_unlock(&p_slot->ctrl->crit_sect);
785 785
786 p_slot->hpc_ops->get_latch_status(p_slot, &getstatus); 786 p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
787 787
@@ -806,13 +806,13 @@ int pciehp_disable_slot(struct slot *p_slot)
806 return 1; 806 return 1;
807 807
808 /* Check to see if (latch closed, card present, power on) */ 808 /* Check to see if (latch closed, card present, power on) */
809 down(&p_slot->ctrl->crit_sect); 809 mutex_lock(&p_slot->ctrl->crit_sect);
810 810
811 if (!HP_SUPR_RM(p_slot->ctrl->ctrlcap)) { 811 if (!HP_SUPR_RM(p_slot->ctrl->ctrlcap)) {
812 ret = p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus); 812 ret = p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus);
813 if (ret || !getstatus) { 813 if (ret || !getstatus) {
814 info("%s: no adapter on slot(%x)\n", __FUNCTION__, p_slot->number); 814 info("%s: no adapter on slot(%x)\n", __FUNCTION__, p_slot->number);
815 up(&p_slot->ctrl->crit_sect); 815 mutex_unlock(&p_slot->ctrl->crit_sect);
816 return 1; 816 return 1;
817 } 817 }
818 } 818 }
@@ -821,7 +821,7 @@ int pciehp_disable_slot(struct slot *p_slot)
821 ret = p_slot->hpc_ops->get_latch_status(p_slot, &getstatus); 821 ret = p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
822 if (ret || getstatus) { 822 if (ret || getstatus) {
823 info("%s: latch open on slot(%x)\n", __FUNCTION__, p_slot->number); 823 info("%s: latch open on slot(%x)\n", __FUNCTION__, p_slot->number);
824 up(&p_slot->ctrl->crit_sect); 824 mutex_unlock(&p_slot->ctrl->crit_sect);
825 return 1; 825 return 1;
826 } 826 }
827 } 827 }
@@ -830,12 +830,12 @@ int pciehp_disable_slot(struct slot *p_slot)
830 ret = p_slot->hpc_ops->get_power_status(p_slot, &getstatus); 830 ret = p_slot->hpc_ops->get_power_status(p_slot, &getstatus);
831 if (ret || !getstatus) { 831 if (ret || !getstatus) {
832 info("%s: already disabled slot(%x)\n", __FUNCTION__, p_slot->number); 832 info("%s: already disabled slot(%x)\n", __FUNCTION__, p_slot->number);
833 up(&p_slot->ctrl->crit_sect); 833 mutex_unlock(&p_slot->ctrl->crit_sect);
834 return 1; 834 return 1;
835 } 835 }
836 } 836 }
837 837
838 up(&p_slot->ctrl->crit_sect); 838 mutex_unlock(&p_slot->ctrl->crit_sect);
839 839
840 ret = remove_board(p_slot); 840 ret = remove_board(p_slot);
841 update_slot_info(p_slot); 841 update_slot_info(p_slot);
diff --git a/drivers/pci/hotplug/pciehp_hpc.c b/drivers/pci/hotplug/pciehp_hpc.c
index 77e530321d..6c14d9e46b 100644
--- a/drivers/pci/hotplug/pciehp_hpc.c
+++ b/drivers/pci/hotplug/pciehp_hpc.c
@@ -38,7 +38,10 @@
38 38
39#include "../pci.h" 39#include "../pci.h"
40#include "pciehp.h" 40#include "pciehp.h"
41 41#include <acpi/acpi.h>
42#include <acpi/acpi_bus.h>
43#include <acpi/actypes.h>
44#include <linux/pci-acpi.h>
42#ifdef DEBUG 45#ifdef DEBUG
43#define DBG_K_TRACE_ENTRY ((unsigned int)0x00000001) /* On function entry */ 46#define DBG_K_TRACE_ENTRY ((unsigned int)0x00000001) /* On function entry */
44#define DBG_K_TRACE_EXIT ((unsigned int)0x00000002) /* On function exit */ 47#define DBG_K_TRACE_EXIT ((unsigned int)0x00000002) /* On function exit */
@@ -1236,6 +1239,76 @@ static struct hpc_ops pciehp_hpc_ops = {
1236 .check_lnk_status = hpc_check_lnk_status, 1239 .check_lnk_status = hpc_check_lnk_status,
1237}; 1240};
1238 1241
1242#ifdef CONFIG_ACPI
1243int pciehp_acpi_get_hp_hw_control_from_firmware(struct pci_dev *dev)
1244{
1245 acpi_status status;
1246 acpi_handle chandle, handle = DEVICE_ACPI_HANDLE(&(dev->dev));
1247 struct pci_dev *pdev = dev;
1248 struct pci_bus *parent;
1249 struct acpi_buffer string = { ACPI_ALLOCATE_BUFFER, NULL };
1250
1251 /*
1252 * Per PCI firmware specification, we should run the ACPI _OSC
1253 * method to get control of hotplug hardware before using it.
1254 * If an _OSC is missing, we look for an OSHP to do the same thing.
1255 * To handle different BIOS behavior, we look for _OSC and OSHP
1256 * within the scope of the hotplug controller and its parents, upto
1257 * the host bridge under which this controller exists.
1258 */
1259 while (!handle) {
1260 /*
1261 * This hotplug controller was not listed in the ACPI name
1262 * space at all. Try to get acpi handle of parent pci bus.
1263 */
1264 if (!pdev || !pdev->bus->parent)
1265 break;
1266 parent = pdev->bus->parent;
1267 dbg("Could not find %s in acpi namespace, trying parent\n",
1268 pci_name(pdev));
1269 if (!parent->self)
1270 /* Parent must be a host bridge */
1271 handle = acpi_get_pci_rootbridge_handle(
1272 pci_domain_nr(parent),
1273 parent->number);
1274 else
1275 handle = DEVICE_ACPI_HANDLE(
1276 &(parent->self->dev));
1277 pdev = parent->self;
1278 }
1279
1280 while (handle) {
1281 acpi_get_name(handle, ACPI_FULL_PATHNAME, &string);
1282 dbg("Trying to get hotplug control for %s \n",
1283 (char *)string.pointer);
1284 status = pci_osc_control_set(handle,
1285 OSC_PCI_EXPRESS_NATIVE_HP_CONTROL);
1286 if (status == AE_NOT_FOUND)
1287 status = acpi_run_oshp(handle);
1288 if (ACPI_SUCCESS(status)) {
1289 dbg("Gained control for hotplug HW for pci %s (%s)\n",
1290 pci_name(dev), (char *)string.pointer);
1291 acpi_os_free(string.pointer);
1292 return 0;
1293 }
1294 if (acpi_root_bridge(handle))
1295 break;
1296 chandle = handle;
1297 status = acpi_get_parent(chandle, &handle);
1298 if (ACPI_FAILURE(status))
1299 break;
1300 }
1301
1302 err("Cannot get control of hotplug hardware for pci %s\n",
1303 pci_name(dev));
1304
1305 acpi_os_free(string.pointer);
1306 return -1;
1307}
1308#endif
1309
1310
1311
1239int pcie_init(struct controller * ctrl, struct pcie_device *dev) 1312int pcie_init(struct controller * ctrl, struct pcie_device *dev)
1240{ 1313{
1241 struct php_ctlr_state_s *php_ctlr, *p; 1314 struct php_ctlr_state_s *php_ctlr, *p;
@@ -1334,7 +1407,7 @@ int pcie_init(struct controller * ctrl, struct pcie_device *dev)
1334 if (pci_enable_device(pdev)) 1407 if (pci_enable_device(pdev))
1335 goto abort_free_ctlr; 1408 goto abort_free_ctlr;
1336 1409
1337 init_MUTEX(&ctrl->crit_sect); 1410 mutex_init(&ctrl->crit_sect);
1338 /* setup wait queue */ 1411 /* setup wait queue */
1339 init_waitqueue_head(&ctrl->queue); 1412 init_waitqueue_head(&ctrl->queue);
1340 1413
diff --git a/drivers/pci/hotplug/pciehprm_acpi.c b/drivers/pci/hotplug/pciehprm_acpi.c
deleted file mode 100644
index 2bdb30f68b..0000000000
--- a/drivers/pci/hotplug/pciehprm_acpi.c
+++ /dev/null
@@ -1,257 +0,0 @@
1/*
2 * PCIEHPRM ACPI: PHP Resource Manager for ACPI platform
3 *
4 * Copyright (C) 2003-2004 Intel Corporation
5 *
6 * All rights reserved.
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, GOOD TITLE or
16 * NON INFRINGEMENT. See the GNU General Public License for more
17 * details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 *
23 * Send feedback to <kristen.c.accardi@intel.com>
24 *
25 */
26
27#include <linux/module.h>
28#include <linux/kernel.h>
29#include <linux/types.h>
30#include <linux/pci.h>
31#include <linux/acpi.h>
32#include <linux/pci-acpi.h>
33#include <acpi/acpi_bus.h>
34#include <acpi/actypes.h>
35#include "pciehp.h"
36
37#define METHOD_NAME__SUN "_SUN"
38#define METHOD_NAME__HPP "_HPP"
39#define METHOD_NAME_OSHP "OSHP"
40
41static u8 * acpi_path_name( acpi_handle handle)
42{
43 acpi_status status;
44 static u8 path_name[ACPI_PATHNAME_MAX];
45 struct acpi_buffer ret_buf = { ACPI_PATHNAME_MAX, path_name };
46
47 memset(path_name, 0, sizeof (path_name));
48 status = acpi_get_name(handle, ACPI_FULL_PATHNAME, &ret_buf);
49
50 if (ACPI_FAILURE(status))
51 return NULL;
52 else
53 return path_name;
54}
55
56static acpi_status
57acpi_run_hpp(acpi_handle handle, struct hotplug_params *hpp)
58{
59 acpi_status status;
60 u8 nui[4];
61 struct acpi_buffer ret_buf = { 0, NULL};
62 union acpi_object *ext_obj, *package;
63 u8 *path_name = acpi_path_name(handle);
64 int i, len = 0;
65
66 /* get _hpp */
67 status = acpi_evaluate_object(handle, METHOD_NAME__HPP, NULL, &ret_buf);
68 switch (status) {
69 case AE_BUFFER_OVERFLOW:
70 ret_buf.pointer = kmalloc (ret_buf.length, GFP_KERNEL);
71 if (!ret_buf.pointer) {
72 err ("%s:%s alloc for _HPP fail\n", __FUNCTION__,
73 path_name);
74 return AE_NO_MEMORY;
75 }
76 status = acpi_evaluate_object(handle, METHOD_NAME__HPP,
77 NULL, &ret_buf);
78 if (ACPI_SUCCESS(status))
79 break;
80 default:
81 if (ACPI_FAILURE(status)) {
82 dbg("%s:%s _HPP fail=0x%x\n", __FUNCTION__,
83 path_name, status);
84 return status;
85 }
86 }
87
88 ext_obj = (union acpi_object *) ret_buf.pointer;
89 if (ext_obj->type != ACPI_TYPE_PACKAGE) {
90 err ("%s:%s _HPP obj not a package\n", __FUNCTION__,
91 path_name);
92 status = AE_ERROR;
93 goto free_and_return;
94 }
95
96 len = ext_obj->package.count;
97 package = (union acpi_object *) ret_buf.pointer;
98 for ( i = 0; (i < len) || (i < 4); i++) {
99 ext_obj = (union acpi_object *) &package->package.elements[i];
100 switch (ext_obj->type) {
101 case ACPI_TYPE_INTEGER:
102 nui[i] = (u8)ext_obj->integer.value;
103 break;
104 default:
105 err ("%s:%s _HPP obj type incorrect\n", __FUNCTION__,
106 path_name);
107 status = AE_ERROR;
108 goto free_and_return;
109 }
110 }
111
112 hpp->cache_line_size = nui[0];
113 hpp->latency_timer = nui[1];
114 hpp->enable_serr = nui[2];
115 hpp->enable_perr = nui[3];
116
117 dbg(" _HPP: cache_line_size=0x%x\n", hpp->cache_line_size);
118 dbg(" _HPP: latency timer =0x%x\n", hpp->latency_timer);
119 dbg(" _HPP: enable SERR =0x%x\n", hpp->enable_serr);
120 dbg(" _HPP: enable PERR =0x%x\n", hpp->enable_perr);
121
122free_and_return:
123 kfree(ret_buf.pointer);
124 return status;
125}
126
127static acpi_status acpi_run_oshp(acpi_handle handle)
128{
129 acpi_status status;
130 u8 *path_name = acpi_path_name(handle);
131
132 /* run OSHP */
133 status = acpi_evaluate_object(handle, METHOD_NAME_OSHP, NULL, NULL);
134 if (ACPI_FAILURE(status)) {
135 dbg("%s:%s OSHP fails=0x%x\n", __FUNCTION__, path_name,
136 status);
137 } else {
138 dbg("%s:%s OSHP passes\n", __FUNCTION__, path_name);
139 }
140 return status;
141}
142
143static int is_root_bridge(acpi_handle handle)
144{
145 acpi_status status;
146 struct acpi_device_info *info;
147 struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
148 int i;
149
150 status = acpi_get_object_info(handle, &buffer);
151 if (ACPI_SUCCESS(status)) {
152 info = buffer.pointer;
153 if ((info->valid & ACPI_VALID_HID) &&
154 !strcmp(PCI_ROOT_HID_STRING,
155 info->hardware_id.value)) {
156 acpi_os_free(buffer.pointer);
157 return 1;
158 }
159 if (info->valid & ACPI_VALID_CID) {
160 for (i=0; i < info->compatibility_id.count; i++) {
161 if (!strcmp(PCI_ROOT_HID_STRING,
162 info->compatibility_id.id[i].value)) {
163 acpi_os_free(buffer.pointer);
164 return 1;
165 }
166 }
167 }
168 }
169 return 0;
170}
171
172int pciehp_get_hp_hw_control_from_firmware(struct pci_dev *dev)
173{
174 acpi_status status;
175 acpi_handle chandle, handle = DEVICE_ACPI_HANDLE(&(dev->dev));
176 struct pci_dev *pdev = dev;
177 struct pci_bus *parent;
178 u8 *path_name;
179
180 /*
181 * Per PCI firmware specification, we should run the ACPI _OSC
182 * method to get control of hotplug hardware before using it.
183 * If an _OSC is missing, we look for an OSHP to do the same thing.
184 * To handle different BIOS behavior, we look for _OSC and OSHP
185 * within the scope of the hotplug controller and its parents, upto
186 * the host bridge under which this controller exists.
187 */
188 while (!handle) {
189 /*
190 * This hotplug controller was not listed in the ACPI name
191 * space at all. Try to get acpi handle of parent pci bus.
192 */
193 if (!pdev || !pdev->bus->parent)
194 break;
195 parent = pdev->bus->parent;
196 dbg("Could not find %s in acpi namespace, trying parent\n",
197 pci_name(pdev));
198 if (!parent->self)
199 /* Parent must be a host bridge */
200 handle = acpi_get_pci_rootbridge_handle(
201 pci_domain_nr(parent),
202 parent->number);
203 else
204 handle = DEVICE_ACPI_HANDLE(
205 &(parent->self->dev));
206 pdev = parent->self;
207 }
208
209 while (handle) {
210 path_name = acpi_path_name(handle);
211 dbg("Trying to get hotplug control for %s \n", path_name);
212 status = pci_osc_control_set(handle,
213 OSC_PCI_EXPRESS_NATIVE_HP_CONTROL);
214 if (status == AE_NOT_FOUND)
215 status = acpi_run_oshp(handle);
216 if (ACPI_SUCCESS(status)) {
217 dbg("Gained control for hotplug HW for pci %s (%s)\n",
218 pci_name(dev), path_name);
219 return 0;
220 }
221 if (is_root_bridge(handle))
222 break;
223 chandle = handle;
224 status = acpi_get_parent(chandle, &handle);
225 if (ACPI_FAILURE(status))
226 break;
227 }
228
229 err("Cannot get control of hotplug hardware for pci %s\n",
230 pci_name(dev));
231 return -1;
232}
233
234void pciehp_get_hp_params_from_firmware(struct pci_dev *dev,
235 struct hotplug_params *hpp)
236{
237 acpi_status status = AE_NOT_FOUND;
238 struct pci_dev *pdev = dev;
239
240 /*
241 * _HPP settings apply to all child buses, until another _HPP is
242 * encountered. If we don't find an _HPP for the input pci dev,
243 * look for it in the parent device scope since that would apply to
244 * this pci dev. If we don't find any _HPP, use hardcoded defaults
245 */
246 while (pdev && (ACPI_FAILURE(status))) {
247 acpi_handle handle = DEVICE_ACPI_HANDLE(&(pdev->dev));
248 if (!handle)
249 break;
250 status = acpi_run_hpp(handle, hpp);
251 if (!(pdev->bus->parent))
252 break;
253 /* Check if a parent object supports _HPP */
254 pdev = pdev->bus->parent->self;
255 }
256}
257
diff --git a/drivers/pci/hotplug/pciehprm_nonacpi.c b/drivers/pci/hotplug/pciehprm_nonacpi.c
deleted file mode 100644
index 29180dfe84..0000000000
--- a/drivers/pci/hotplug/pciehprm_nonacpi.c
+++ /dev/null
@@ -1,47 +0,0 @@
1/*
2 * PCIEHPRM NONACPI: PHP Resource Manager for Non-ACPI/Legacy platform
3 *
4 * Copyright (C) 1995,2001 Compaq Computer Corporation
5 * Copyright (C) 2001 Greg Kroah-Hartman (greg@kroah.com)
6 * Copyright (C) 2001 IBM Corp.
7 * Copyright (C) 2003-2004 Intel Corporation
8 *
9 * All rights reserved.
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or (at
14 * your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
19 * NON INFRINGEMENT. See the GNU General Public License for more
20 * details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 *
26 * Send feedback to <greg@kroah.com>, <kristen.c.accardi@intel.com>
27 *
28 */
29
30#include <linux/module.h>
31#include <linux/kernel.h>
32#include <linux/types.h>
33#include <linux/sched.h>
34#include <linux/pci.h>
35#include <linux/slab.h>
36#include "pciehp.h"
37
38void pciehp_get_hp_params_from_firmware(struct pci_dev *dev,
39 struct hotplug_params *hpp)
40{
41 return;
42}
43
44int pciehp_get_hp_hw_control_from_firmware(struct pci_dev *dev)
45{
46 return 0;
47}
diff --git a/drivers/pci/hotplug/pcihp_skeleton.c b/drivers/pci/hotplug/pcihp_skeleton.c
index 3194d51c6e..0a46f54967 100644
--- a/drivers/pci/hotplug/pcihp_skeleton.c
+++ b/drivers/pci/hotplug/pcihp_skeleton.c
@@ -37,10 +37,12 @@
37#include <linux/init.h> 37#include <linux/init.h>
38#include "pci_hotplug.h" 38#include "pci_hotplug.h"
39 39
40#define SLOT_NAME_SIZE 10
40struct slot { 41struct slot {
41 u8 number; 42 u8 number;
42 struct hotplug_slot *hotplug_slot; 43 struct hotplug_slot *hotplug_slot;
43 struct list_head slot_list; 44 struct list_head slot_list;
45 char name[SLOT_NAME_SIZE];
44}; 46};
45 47
46static LIST_HEAD(slot_list); 48static LIST_HEAD(slot_list);
@@ -233,12 +235,10 @@ static void release_slot(struct hotplug_slot *hotplug_slot)
233 235
234 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name); 236 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
235 kfree(slot->hotplug_slot->info); 237 kfree(slot->hotplug_slot->info);
236 kfree(slot->hotplug_slot->name);
237 kfree(slot->hotplug_slot); 238 kfree(slot->hotplug_slot);
238 kfree(slot); 239 kfree(slot);
239} 240}
240 241
241#define SLOT_NAME_SIZE 10
242static void make_slot_name(struct slot *slot) 242static void make_slot_name(struct slot *slot)
243{ 243{
244 /* 244 /*
@@ -257,7 +257,6 @@ static int __init init_slots(void)
257 struct slot *slot; 257 struct slot *slot;
258 struct hotplug_slot *hotplug_slot; 258 struct hotplug_slot *hotplug_slot;
259 struct hotplug_slot_info *info; 259 struct hotplug_slot_info *info;
260 char *name;
261 int retval = -ENOMEM; 260 int retval = -ENOMEM;
262 int i; 261 int i;
263 262
@@ -266,31 +265,23 @@ static int __init init_slots(void)
266 * with the pci_hotplug subsystem. 265 * with the pci_hotplug subsystem.
267 */ 266 */
268 for (i = 0; i < num_slots; ++i) { 267 for (i = 0; i < num_slots; ++i) {
269 slot = kmalloc(sizeof(struct slot), GFP_KERNEL); 268 slot = kzalloc(sizeof(*slot), GFP_KERNEL);
270 if (!slot) 269 if (!slot)
271 goto error; 270 goto error;
272 memset(slot, 0, sizeof(struct slot));
273 271
274 hotplug_slot = kmalloc(sizeof(struct hotplug_slot), 272 hotplug_slot = kzalloc(sizeof(*hotplug_slot), GFP_KERNEL);
275 GFP_KERNEL);
276 if (!hotplug_slot) 273 if (!hotplug_slot)
277 goto error_slot; 274 goto error_slot;
278 memset(hotplug_slot, 0, sizeof (struct hotplug_slot));
279 slot->hotplug_slot = hotplug_slot; 275 slot->hotplug_slot = hotplug_slot;
280 276
281 info = kmalloc(sizeof(struct hotplug_slot_info), GFP_KERNEL); 277 info = kzalloc(sizeof(*info), GFP_KERNEL);
282 if (!info) 278 if (!info)
283 goto error_hpslot; 279 goto error_hpslot;
284 memset(info, 0, sizeof (struct hotplug_slot_info));
285 hotplug_slot->info = info; 280 hotplug_slot->info = info;
286 281
287 name = kmalloc(SLOT_NAME_SIZE, GFP_KERNEL);
288 if (!name)
289 goto error_info;
290 hotplug_slot->name = name;
291
292 slot->number = i; 282 slot->number = i;
293 283
284 hotplug_slot->name = slot->name;
294 hotplug_slot->private = slot; 285 hotplug_slot->private = slot;
295 hotplug_slot->release = &release_slot; 286 hotplug_slot->release = &release_slot;
296 make_slot_name(slot); 287 make_slot_name(slot);
@@ -300,16 +291,16 @@ static int __init init_slots(void)
300 * Initialize the slot info structure with some known 291 * Initialize the slot info structure with some known
301 * good values. 292 * good values.
302 */ 293 */
303 info->power_status = get_power_status(slot); 294 get_power_status(hotplug_slot, &info->power_status);
304 info->attention_status = get_attention_status(slot); 295 get_attention_status(hotplug_slot, &info->attention_status);
305 info->latch_status = get_latch_status(slot); 296 get_latch_status(hotplug_slot, &info->latch_status);
306 info->adapter_status = get_adapter_status(slot); 297 get_adapter_status(hotplug_slot, &info->adapter_status);
307 298
308 dbg("registering slot %d\n", i); 299 dbg("registering slot %d\n", i);
309 retval = pci_hp_register(slot->hotplug_slot); 300 retval = pci_hp_register(slot->hotplug_slot);
310 if (retval) { 301 if (retval) {
311 err("pci_hp_register failed with error %d\n", retval); 302 err("pci_hp_register failed with error %d\n", retval);
312 goto error_name; 303 goto error_info;
313 } 304 }
314 305
315 /* add slot to our internal list */ 306 /* add slot to our internal list */
@@ -317,8 +308,6 @@ static int __init init_slots(void)
317 } 308 }
318 309
319 return 0; 310 return 0;
320error_name:
321 kfree(name);
322error_info: 311error_info:
323 kfree(info); 312 kfree(info);
324error_hpslot: 313error_hpslot:
diff --git a/drivers/pci/hotplug/rpaphp_slot.c b/drivers/pci/hotplug/rpaphp_slot.c
index 78943e064b..b771196a65 100644
--- a/drivers/pci/hotplug/rpaphp_slot.c
+++ b/drivers/pci/hotplug/rpaphp_slot.c
@@ -84,19 +84,16 @@ struct slot *alloc_slot_struct(struct device_node *dn, int drc_index, char *drc_
84{ 84{
85 struct slot *slot; 85 struct slot *slot;
86 86
87 slot = kmalloc(sizeof (struct slot), GFP_KERNEL); 87 slot = kzalloc(sizeof(struct slot), GFP_KERNEL);
88 if (!slot) 88 if (!slot)
89 goto error_nomem; 89 goto error_nomem;
90 memset(slot, 0, sizeof (struct slot)); 90 slot->hotplug_slot = kzalloc(sizeof(struct hotplug_slot), GFP_KERNEL);
91 slot->hotplug_slot = kmalloc(sizeof (struct hotplug_slot), GFP_KERNEL);
92 if (!slot->hotplug_slot) 91 if (!slot->hotplug_slot)
93 goto error_slot; 92 goto error_slot;
94 memset(slot->hotplug_slot, 0, sizeof (struct hotplug_slot)); 93 slot->hotplug_slot->info = kzalloc(sizeof(struct hotplug_slot_info),
95 slot->hotplug_slot->info = kmalloc(sizeof (struct hotplug_slot_info),
96 GFP_KERNEL); 94 GFP_KERNEL);
97 if (!slot->hotplug_slot->info) 95 if (!slot->hotplug_slot->info)
98 goto error_hpslot; 96 goto error_hpslot;
99 memset(slot->hotplug_slot->info, 0, sizeof (struct hotplug_slot_info));
100 slot->hotplug_slot->name = kmalloc(BUS_ID_SIZE + 1, GFP_KERNEL); 97 slot->hotplug_slot->name = kmalloc(BUS_ID_SIZE + 1, GFP_KERNEL);
101 if (!slot->hotplug_slot->name) 98 if (!slot->hotplug_slot->name)
102 goto error_info; 99 goto error_info;
diff --git a/drivers/pci/hotplug/sgi_hotplug.c b/drivers/pci/hotplug/sgi_hotplug.c
index a32ae82e59..c402da8e78 100644
--- a/drivers/pci/hotplug/sgi_hotplug.c
+++ b/drivers/pci/hotplug/sgi_hotplug.c
@@ -3,7 +3,7 @@
3 * License. See the file "COPYING" in the main directory of this archive 3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details. 4 * for more details.
5 * 5 *
6 * Copyright (C) 2005 Silicon Graphics, Inc. All rights reserved. 6 * Copyright (C) 2005-2006 Silicon Graphics, Inc. All rights reserved.
7 * 7 *
8 * This work was based on the 2.4/2.6 kernel development by Dick Reigner. 8 * This work was based on the 2.4/2.6 kernel development by Dick Reigner.
9 * Work to add BIOS PROM support was completed by Mike Habeck. 9 * Work to add BIOS PROM support was completed by Mike Habeck.
@@ -230,6 +230,13 @@ static void sn_bus_free_data(struct pci_dev *dev)
230 list_for_each_entry(child, &subordinate_bus->devices, bus_list) 230 list_for_each_entry(child, &subordinate_bus->devices, bus_list)
231 sn_bus_free_data(child); 231 sn_bus_free_data(child);
232 } 232 }
233 /*
234 * Some drivers may use dma accesses during the
235 * driver remove function. We release the sysdata
236 * areas after the driver remove functions have
237 * been called.
238 */
239 sn_bus_store_sysdata(dev);
233 sn_pci_unfixup_slot(dev); 240 sn_pci_unfixup_slot(dev);
234} 241}
235 242
@@ -429,13 +436,6 @@ static int disable_slot(struct hotplug_slot *bss_hotplug_slot)
429 PCI_DEVFN(slot->device_num + 1, 436 PCI_DEVFN(slot->device_num + 1,
430 PCI_FUNC(func))); 437 PCI_FUNC(func)));
431 if (dev) { 438 if (dev) {
432 /*
433 * Some drivers may use dma accesses during the
434 * driver remove function. We release the sysdata
435 * areas after the driver remove functions have
436 * been called.
437 */
438 sn_bus_store_sysdata(dev);
439 sn_bus_free_data(dev); 439 sn_bus_free_data(dev);
440 pci_remove_bus_device(dev); 440 pci_remove_bus_device(dev);
441 pci_dev_put(dev); 441 pci_dev_put(dev);
diff --git a/drivers/pci/hotplug/shpchp.h b/drivers/pci/hotplug/shpchp.h
index 7d6f521d02..5c70f43908 100644
--- a/drivers/pci/hotplug/shpchp.h
+++ b/drivers/pci/hotplug/shpchp.h
@@ -33,6 +33,7 @@
33#include <linux/pci.h> 33#include <linux/pci.h>
34#include <linux/delay.h> 34#include <linux/delay.h>
35#include <linux/sched.h> /* signal_pending(), struct timer_list */ 35#include <linux/sched.h> /* signal_pending(), struct timer_list */
36#include <linux/mutex.h>
36 37
37#include "pci_hotplug.h" 38#include "pci_hotplug.h"
38 39
@@ -45,6 +46,7 @@
45extern int shpchp_poll_mode; 46extern int shpchp_poll_mode;
46extern int shpchp_poll_time; 47extern int shpchp_poll_time;
47extern int shpchp_debug; 48extern int shpchp_debug;
49extern struct workqueue_struct *shpchp_wq;
48 50
49/*#define dbg(format, arg...) do { if (shpchp_debug) printk(KERN_DEBUG "%s: " format, MY_NAME , ## arg); } while (0)*/ 51/*#define dbg(format, arg...) do { if (shpchp_debug) printk(KERN_DEBUG "%s: " format, MY_NAME , ## arg); } while (0)*/
50#define dbg(format, arg...) do { if (shpchp_debug) printk("%s: " format, MY_NAME , ## arg); } while (0) 52#define dbg(format, arg...) do { if (shpchp_debug) printk("%s: " format, MY_NAME , ## arg); } while (0)
@@ -52,10 +54,8 @@ extern int shpchp_debug;
52#define info(format, arg...) printk(KERN_INFO "%s: " format, MY_NAME , ## arg) 54#define info(format, arg...) printk(KERN_INFO "%s: " format, MY_NAME , ## arg)
53#define warn(format, arg...) printk(KERN_WARNING "%s: " format, MY_NAME , ## arg) 55#define warn(format, arg...) printk(KERN_WARNING "%s: " format, MY_NAME , ## arg)
54 56
55#define SLOT_MAGIC 0x67267321 57#define SLOT_NAME_SIZE 10
56struct slot { 58struct slot {
57 u32 magic;
58 struct slot *next;
59 u8 bus; 59 u8 bus;
60 u8 device; 60 u8 device;
61 u16 status; 61 u16 status;
@@ -70,26 +70,27 @@ struct slot {
70 struct hpc_ops *hpc_ops; 70 struct hpc_ops *hpc_ops;
71 struct hotplug_slot *hotplug_slot; 71 struct hotplug_slot *hotplug_slot;
72 struct list_head slot_list; 72 struct list_head slot_list;
73 char name[SLOT_NAME_SIZE];
74 struct work_struct work; /* work for button event */
75 struct mutex lock;
73}; 76};
74 77
75struct event_info { 78struct event_info {
76 u32 event_type; 79 u32 event_type;
77 u8 hp_slot; 80 struct slot *p_slot;
81 struct work_struct work;
78}; 82};
79 83
80struct controller { 84struct controller {
81 struct controller *next; 85 struct mutex crit_sect; /* critical section mutex */
82 struct semaphore crit_sect; /* critical section semaphore */ 86 struct mutex cmd_lock; /* command lock */
83 struct php_ctlr_state_s *hpc_ctlr_handle; /* HPC controller handle */ 87 struct php_ctlr_state_s *hpc_ctlr_handle; /* HPC controller handle */
84 int num_slots; /* Number of slots on ctlr */ 88 int num_slots; /* Number of slots on ctlr */
85 int slot_num_inc; /* 1 or -1 */ 89 int slot_num_inc; /* 1 or -1 */
86 struct pci_dev *pci_dev; 90 struct pci_dev *pci_dev;
87 struct pci_bus *pci_bus; 91 struct list_head slot_list;
88 struct event_info event_queue[10];
89 struct slot *slot;
90 struct hpc_ops *hpc_ops; 92 struct hpc_ops *hpc_ops;
91 wait_queue_head_t queue; /* sleep & wake process */ 93 wait_queue_head_t queue; /* sleep & wake process */
92 u8 next_event;
93 u8 bus; 94 u8 bus;
94 u8 device; 95 u8 device;
95 u8 function; 96 u8 function;
@@ -105,12 +106,6 @@ struct controller {
105 volatile int cmd_busy; 106 volatile int cmd_busy;
106}; 107};
107 108
108struct hotplug_params {
109 u8 cache_line_size;
110 u8 latency_timer;
111 u8 enable_serr;
112 u8 enable_perr;
113};
114 109
115/* Define AMD SHPC ID */ 110/* Define AMD SHPC ID */
116#define PCI_DEVICE_ID_AMD_GOLAM_7450 0x7450 111#define PCI_DEVICE_ID_AMD_GOLAM_7450 0x7450
@@ -180,11 +175,8 @@ struct hotplug_params {
180/* sysfs functions for the hotplug controller info */ 175/* sysfs functions for the hotplug controller info */
181extern void shpchp_create_ctrl_files (struct controller *ctrl); 176extern void shpchp_create_ctrl_files (struct controller *ctrl);
182 177
183/* controller functions */ 178extern int shpchp_sysfs_enable_slot(struct slot *slot);
184extern int shpchp_event_start_thread(void); 179extern int shpchp_sysfs_disable_slot(struct slot *slot);
185extern void shpchp_event_stop_thread(void);
186extern int shpchp_enable_slot(struct slot *slot);
187extern int shpchp_disable_slot(struct slot *slot);
188 180
189extern u8 shpchp_handle_attention_button(u8 hp_slot, void *inst_id); 181extern u8 shpchp_handle_attention_button(u8 hp_slot, void *inst_id);
190extern u8 shpchp_handle_switch_change(u8 hp_slot, void *inst_id); 182extern u8 shpchp_handle_switch_change(u8 hp_slot, void *inst_id);
@@ -195,16 +187,28 @@ extern u8 shpchp_handle_power_fault(u8 hp_slot, void *inst_id);
195extern int shpchp_save_config(struct controller *ctrl, int busnumber, int num_ctlr_slots, int first_device_num); 187extern int shpchp_save_config(struct controller *ctrl, int busnumber, int num_ctlr_slots, int first_device_num);
196extern int shpchp_configure_device(struct slot *p_slot); 188extern int shpchp_configure_device(struct slot *p_slot);
197extern int shpchp_unconfigure_device(struct slot *p_slot); 189extern int shpchp_unconfigure_device(struct slot *p_slot);
198extern void get_hp_hw_control_from_firmware(struct pci_dev *dev);
199extern void get_hp_params_from_firmware(struct pci_dev *dev,
200 struct hotplug_params *hpp);
201extern int shpchprm_get_physical_slot_number(struct controller *ctrl,
202 u32 *sun, u8 busnum, u8 devnum);
203extern void shpchp_remove_ctrl_files(struct controller *ctrl); 190extern void shpchp_remove_ctrl_files(struct controller *ctrl);
191extern void cleanup_slots(struct controller *ctrl);
192extern void queue_pushbutton_work(void *data);
204 193
205 194
206/* Global variables */ 195#ifdef CONFIG_ACPI
207extern struct controller *shpchp_ctrl_list; 196static inline int get_hp_params_from_firmware(struct pci_dev *dev,
197 struct hotplug_params *hpp)
198{
199 if (ACPI_FAILURE(acpi_get_hp_params_from_firmware(dev, hpp)))
200 return -ENODEV;
201 return 0;
202}
203#define get_hp_hw_control_from_firmware(pdev) \
204 do { \
205 if (DEVICE_ACPI_HANDLE(&(pdev->dev))) \
206 acpi_run_oshp(DEVICE_ACPI_HANDLE(&(pdev->dev))); \
207 } while (0)
208#else
209#define get_hp_params_from_firmware(dev, hpp) (-ENODEV)
210#define get_hp_hw_control_from_firmware(dev) do { } while (0)
211#endif
208 212
209struct ctrl_reg { 213struct ctrl_reg {
210 volatile u32 base_offset; 214 volatile u32 base_offset;
@@ -286,10 +290,6 @@ static inline int slot_paranoia_check (struct slot *slot, const char *function)
286 dbg("%s - slot == NULL", function); 290 dbg("%s - slot == NULL", function);
287 return -1; 291 return -1;
288 } 292 }
289 if (slot->magic != SLOT_MAGIC) {
290 dbg("%s - bad magic number for slot", function);
291 return -1;
292 }
293 if (!slot->hotplug_slot) { 293 if (!slot->hotplug_slot) {
294 dbg("%s - slot->hotplug_slot == NULL!", function); 294 dbg("%s - slot->hotplug_slot == NULL!", function);
295 return -1; 295 return -1;
@@ -314,44 +314,19 @@ static inline struct slot *get_slot (struct hotplug_slot *hotplug_slot, const ch
314 314
315static inline struct slot *shpchp_find_slot (struct controller *ctrl, u8 device) 315static inline struct slot *shpchp_find_slot (struct controller *ctrl, u8 device)
316{ 316{
317 struct slot *p_slot, *tmp_slot = NULL; 317 struct slot *slot;
318 318
319 if (!ctrl) 319 if (!ctrl)
320 return NULL; 320 return NULL;
321 321
322 p_slot = ctrl->slot; 322 list_for_each_entry(slot, &ctrl->slot_list, slot_list) {
323 323 if (slot->device == device)
324 while (p_slot && (p_slot->device != device)) { 324 return slot;
325 tmp_slot = p_slot;
326 p_slot = p_slot->next;
327 } 325 }
328 if (p_slot == NULL) {
329 err("ERROR: shpchp_find_slot device=0x%x\n", device);
330 p_slot = tmp_slot;
331 }
332
333 return (p_slot);
334}
335
336static inline int wait_for_ctrl_irq (struct controller *ctrl)
337{
338 DECLARE_WAITQUEUE(wait, current);
339 int retval = 0;
340
341 add_wait_queue(&ctrl->queue, &wait);
342 326
343 if (!shpchp_poll_mode) { 327 err("%s: slot (device=0x%x) not found\n", __FUNCTION__, device);
344 /* Sleep for up to 1 second */
345 msleep_interruptible(1000);
346 } else {
347 /* Sleep for up to 2 seconds */
348 msleep_interruptible(2000);
349 }
350 remove_wait_queue(&ctrl->queue, &wait);
351 if (signal_pending(current))
352 retval = -EINTR;
353 328
354 return retval; 329 return NULL;
355} 330}
356 331
357static inline void amd_pogo_errata_save_misc_reg(struct slot *p_slot) 332static inline void amd_pogo_errata_save_misc_reg(struct slot *p_slot)
@@ -427,13 +402,6 @@ static inline void amd_pogo_errata_restore_misc_reg(struct slot *p_slot)
427 pci_write_config_dword(p_slot->ctrl->pci_dev, PCIX_MISCII_OFFSET, pcix_misc2_temp); 402 pci_write_config_dword(p_slot->ctrl->pci_dev, PCIX_MISCII_OFFSET, pcix_misc2_temp);
428} 403}
429 404
430#define SLOT_NAME_SIZE 10
431
432static inline void make_slot_name(char *buffer, int buffer_size, struct slot *slot)
433{
434 snprintf(buffer, buffer_size, "%04d_%04d", slot->bus, slot->number);
435}
436
437enum php_ctlr_type { 405enum php_ctlr_type {
438 PCI, 406 PCI,
439 ISA, 407 ISA,
diff --git a/drivers/pci/hotplug/shpchp_core.c b/drivers/pci/hotplug/shpchp_core.c
index a2b3f0010c..3be4d492cc 100644
--- a/drivers/pci/hotplug/shpchp_core.c
+++ b/drivers/pci/hotplug/shpchp_core.c
@@ -32,13 +32,14 @@
32#include <linux/kernel.h> 32#include <linux/kernel.h>
33#include <linux/types.h> 33#include <linux/types.h>
34#include <linux/pci.h> 34#include <linux/pci.h>
35#include <linux/workqueue.h>
35#include "shpchp.h" 36#include "shpchp.h"
36 37
37/* Global variables */ 38/* Global variables */
38int shpchp_debug; 39int shpchp_debug;
39int shpchp_poll_mode; 40int shpchp_poll_mode;
40int shpchp_poll_time; 41int shpchp_poll_time;
41struct controller *shpchp_ctrl_list; /* = NULL */ 42struct workqueue_struct *shpchp_wq;
42 43
43#define DRIVER_VERSION "0.4" 44#define DRIVER_VERSION "0.4"
44#define DRIVER_AUTHOR "Dan Zink <dan.zink@compaq.com>, Greg Kroah-Hartman <greg@kroah.com>, Dely Sy <dely.l.sy@intel.com>" 45#define DRIVER_AUTHOR "Dan Zink <dan.zink@compaq.com>, Greg Kroah-Hartman <greg@kroah.com>, Dely Sy <dely.l.sy@intel.com>"
@@ -57,7 +58,6 @@ MODULE_PARM_DESC(shpchp_poll_time, "Polling mechanism frequency, in seconds");
57 58
58#define SHPC_MODULE_NAME "shpchp" 59#define SHPC_MODULE_NAME "shpchp"
59 60
60static int shpc_start_thread (void);
61static int set_attention_status (struct hotplug_slot *slot, u8 value); 61static int set_attention_status (struct hotplug_slot *slot, u8 value);
62static int enable_slot (struct hotplug_slot *slot); 62static int enable_slot (struct hotplug_slot *slot);
63static int disable_slot (struct hotplug_slot *slot); 63static int disable_slot (struct hotplug_slot *slot);
@@ -94,107 +94,120 @@ static void release_slot(struct hotplug_slot *hotplug_slot)
94 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name); 94 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
95 95
96 kfree(slot->hotplug_slot->info); 96 kfree(slot->hotplug_slot->info);
97 kfree(slot->hotplug_slot->name);
98 kfree(slot->hotplug_slot); 97 kfree(slot->hotplug_slot);
99 kfree(slot); 98 kfree(slot);
100} 99}
101 100
101static void make_slot_name(struct slot *slot)
102{
103 snprintf(slot->hotplug_slot->name, SLOT_NAME_SIZE, "%04d_%04d",
104 slot->bus, slot->number);
105}
106
107
108
109
110static int
111shpchprm_get_physical_slot_number(struct controller *ctrl, u32 *sun,
112 u8 busnum, u8 devnum)
113{
114 int offset = devnum - ctrl->slot_device_offset;
115
116 dbg("%s: ctrl->slot_num_inc %d, offset %d\n", __FUNCTION__,
117 ctrl->slot_num_inc, offset);
118 *sun = (u8) (ctrl->first_slot + ctrl->slot_num_inc *offset);
119 return 0;
120}
121
122
123
102static int init_slots(struct controller *ctrl) 124static int init_slots(struct controller *ctrl)
103{ 125{
104 struct slot *new_slot; 126 struct slot *slot;
105 u8 number_of_slots; 127 struct hotplug_slot *hotplug_slot;
106 u8 slot_device; 128 struct hotplug_slot_info *info;
107 u32 slot_number, sun; 129 int retval = -ENOMEM;
108 int result = -ENOMEM; 130 int i;
109 131 u32 sun;
110 number_of_slots = ctrl->num_slots; 132
111 slot_device = ctrl->slot_device_offset; 133 for (i = 0; i < ctrl->num_slots; i++) {
112 slot_number = ctrl->first_slot; 134 slot = kzalloc(sizeof(*slot), GFP_KERNEL);
113 135 if (!slot)
114 while (number_of_slots) {
115 new_slot = (struct slot *) kmalloc(sizeof(struct slot), GFP_KERNEL);
116 if (!new_slot)
117 goto error; 136 goto error;
118 137
119 memset(new_slot, 0, sizeof(struct slot)); 138 hotplug_slot = kzalloc(sizeof(*hotplug_slot), GFP_KERNEL);
120 new_slot->hotplug_slot = kmalloc (sizeof (struct hotplug_slot), GFP_KERNEL); 139 if (!hotplug_slot)
121 if (!new_slot->hotplug_slot)
122 goto error_slot; 140 goto error_slot;
123 memset(new_slot->hotplug_slot, 0, sizeof (struct hotplug_slot)); 141 slot->hotplug_slot = hotplug_slot;
124 142
125 new_slot->hotplug_slot->info = kmalloc (sizeof (struct hotplug_slot_info), GFP_KERNEL); 143 info = kzalloc(sizeof(*info), GFP_KERNEL);
126 if (!new_slot->hotplug_slot->info) 144 if (!info)
127 goto error_hpslot; 145 goto error_hpslot;
128 memset(new_slot->hotplug_slot->info, 0, sizeof (struct hotplug_slot_info)); 146 hotplug_slot->info = info;
129 new_slot->hotplug_slot->name = kmalloc (SLOT_NAME_SIZE, GFP_KERNEL); 147
130 if (!new_slot->hotplug_slot->name) 148 hotplug_slot->name = slot->name;
131 goto error_info;
132 149
133 new_slot->magic = SLOT_MAGIC; 150 slot->hp_slot = i;
134 new_slot->ctrl = ctrl; 151 slot->ctrl = ctrl;
135 new_slot->bus = ctrl->slot_bus; 152 slot->bus = ctrl->slot_bus;
136 new_slot->device = slot_device; 153 slot->device = ctrl->slot_device_offset + i;
137 new_slot->hpc_ops = ctrl->hpc_ops; 154 slot->hpc_ops = ctrl->hpc_ops;
155 mutex_init(&slot->lock);
138 156
139 if (shpchprm_get_physical_slot_number(ctrl, &sun, 157 if (shpchprm_get_physical_slot_number(ctrl, &sun,
140 new_slot->bus, new_slot->device)) 158 slot->bus, slot->device))
141 goto error_name; 159 goto error_info;
142 160
143 new_slot->number = sun; 161 slot->number = sun;
144 new_slot->hp_slot = slot_device - ctrl->slot_device_offset; 162 INIT_WORK(&slot->work, queue_pushbutton_work, slot);
145 163
146 /* register this slot with the hotplug pci core */ 164 /* register this slot with the hotplug pci core */
147 new_slot->hotplug_slot->private = new_slot; 165 hotplug_slot->private = slot;
148 new_slot->hotplug_slot->release = &release_slot; 166 hotplug_slot->release = &release_slot;
149 make_slot_name(new_slot->hotplug_slot->name, SLOT_NAME_SIZE, new_slot); 167 make_slot_name(slot);
150 new_slot->hotplug_slot->ops = &shpchp_hotplug_slot_ops; 168 hotplug_slot->ops = &shpchp_hotplug_slot_ops;
151 169
152 new_slot->hpc_ops->get_power_status(new_slot, &(new_slot->hotplug_slot->info->power_status)); 170 get_power_status(hotplug_slot, &info->power_status);
153 new_slot->hpc_ops->get_attention_status(new_slot, &(new_slot->hotplug_slot->info->attention_status)); 171 get_attention_status(hotplug_slot, &info->attention_status);
154 new_slot->hpc_ops->get_latch_status(new_slot, &(new_slot->hotplug_slot->info->latch_status)); 172 get_latch_status(hotplug_slot, &info->latch_status);
155 new_slot->hpc_ops->get_adapter_status(new_slot, &(new_slot->hotplug_slot->info->adapter_status)); 173 get_adapter_status(hotplug_slot, &info->adapter_status);
156 174
157 dbg("Registering bus=%x dev=%x hp_slot=%x sun=%x slot_device_offset=%x\n", new_slot->bus, 175 dbg("Registering bus=%x dev=%x hp_slot=%x sun=%x "
158 new_slot->device, new_slot->hp_slot, new_slot->number, ctrl->slot_device_offset); 176 "slot_device_offset=%x\n", slot->bus, slot->device,
159 result = pci_hp_register (new_slot->hotplug_slot); 177 slot->hp_slot, slot->number, ctrl->slot_device_offset);
160 if (result) { 178 retval = pci_hp_register(slot->hotplug_slot);
161 err ("pci_hp_register failed with error %d\n", result); 179 if (retval) {
162 goto error_name; 180 err("pci_hp_register failed with error %d\n", retval);
181 goto error_info;
163 } 182 }
164 183
165 new_slot->next = ctrl->slot; 184 list_add(&slot->slot_list, &ctrl->slot_list);
166 ctrl->slot = new_slot;
167
168 number_of_slots--;
169 slot_device++;
170 slot_number += ctrl->slot_num_inc;
171 } 185 }
172 186
173 return 0; 187 return 0;
174
175error_name:
176 kfree(new_slot->hotplug_slot->name);
177error_info: 188error_info:
178 kfree(new_slot->hotplug_slot->info); 189 kfree(info);
179error_hpslot: 190error_hpslot:
180 kfree(new_slot->hotplug_slot); 191 kfree(hotplug_slot);
181error_slot: 192error_slot:
182 kfree(new_slot); 193 kfree(slot);
183error: 194error:
184 return result; 195 return retval;
185} 196}
186 197
187static void cleanup_slots(struct controller *ctrl) 198void cleanup_slots(struct controller *ctrl)
188{ 199{
189 struct slot *old_slot, *next_slot; 200 struct list_head *tmp;
190 201 struct list_head *next;
191 old_slot = ctrl->slot; 202 struct slot *slot;
192 ctrl->slot = NULL; 203
193 204 list_for_each_safe(tmp, next, &ctrl->slot_list) {
194 while (old_slot) { 205 slot = list_entry(tmp, struct slot, slot_list);
195 next_slot = old_slot->next; 206 list_del(&slot->slot_list);
196 pci_hp_deregister(old_slot->hotplug_slot); 207 cancel_delayed_work(&slot->work);
197 old_slot = next_slot; 208 flush_scheduled_work();
209 flush_workqueue(shpchp_wq);
210 pci_hp_deregister(slot->hotplug_slot);
198 } 211 }
199} 212}
200 213
@@ -207,9 +220,12 @@ static int get_ctlr_slot_config(struct controller *ctrl)
207 int rc; 220 int rc;
208 int flags; 221 int flags;
209 222
210 rc = shpc_get_ctlr_slot_config(ctrl, &num_ctlr_slots, &first_device_num, &physical_slot_num, &updown, &flags); 223 rc = shpc_get_ctlr_slot_config(ctrl, &num_ctlr_slots,
224 &first_device_num, &physical_slot_num,
225 &updown, &flags);
211 if (rc) { 226 if (rc) {
212 err("%s: get_ctlr_slot_config fail for b:d (%x:%x)\n", __FUNCTION__, ctrl->bus, ctrl->device); 227 err("%s: get_ctlr_slot_config fail for b:d (%x:%x)\n",
228 __FUNCTION__, ctrl->bus, ctrl->device);
213 return -1; 229 return -1;
214 } 230 }
215 231
@@ -218,19 +234,19 @@ static int get_ctlr_slot_config(struct controller *ctrl)
218 ctrl->first_slot = physical_slot_num; 234 ctrl->first_slot = physical_slot_num;
219 ctrl->slot_num_inc = updown; /* either -1 or 1 */ 235 ctrl->slot_num_inc = updown; /* either -1 or 1 */
220 236
221 dbg("%s: num_slot(0x%x) 1st_dev(0x%x) psn(0x%x) updown(%d) for b:d (%x:%x)\n", 237 dbg("%s: num_slot(0x%x) 1st_dev(0x%x) psn(0x%x) updown(%d) for b:d "
222 __FUNCTION__, num_ctlr_slots, first_device_num, physical_slot_num, updown, ctrl->bus, ctrl->device); 238 "(%x:%x)\n", __FUNCTION__, num_ctlr_slots, first_device_num,
239 physical_slot_num, updown, ctrl->bus, ctrl->device);
223 240
224 return 0; 241 return 0;
225} 242}
226 243
227
228/* 244/*
229 * set_attention_status - Turns the Amber LED for a slot on, off or blink 245 * set_attention_status - Turns the Amber LED for a slot on, off or blink
230 */ 246 */
231static int set_attention_status (struct hotplug_slot *hotplug_slot, u8 status) 247static int set_attention_status (struct hotplug_slot *hotplug_slot, u8 status)
232{ 248{
233 struct slot *slot = get_slot (hotplug_slot, __FUNCTION__); 249 struct slot *slot = get_slot(hotplug_slot, __FUNCTION__);
234 250
235 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name); 251 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
236 252
@@ -240,29 +256,27 @@ static int set_attention_status (struct hotplug_slot *hotplug_slot, u8 status)
240 return 0; 256 return 0;
241} 257}
242 258
243
244static int enable_slot (struct hotplug_slot *hotplug_slot) 259static int enable_slot (struct hotplug_slot *hotplug_slot)
245{ 260{
246 struct slot *slot = get_slot (hotplug_slot, __FUNCTION__); 261 struct slot *slot = get_slot(hotplug_slot, __FUNCTION__);
247 262
248 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name); 263 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
249 264
250 return shpchp_enable_slot(slot); 265 return shpchp_sysfs_enable_slot(slot);
251} 266}
252 267
253
254static int disable_slot (struct hotplug_slot *hotplug_slot) 268static int disable_slot (struct hotplug_slot *hotplug_slot)
255{ 269{
256 struct slot *slot = get_slot (hotplug_slot, __FUNCTION__); 270 struct slot *slot = get_slot(hotplug_slot, __FUNCTION__);
257 271
258 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name); 272 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
259 273
260 return shpchp_disable_slot(slot); 274 return shpchp_sysfs_disable_slot(slot);
261} 275}
262 276
263static int get_power_status (struct hotplug_slot *hotplug_slot, u8 *value) 277static int get_power_status (struct hotplug_slot *hotplug_slot, u8 *value)
264{ 278{
265 struct slot *slot = get_slot (hotplug_slot, __FUNCTION__); 279 struct slot *slot = get_slot(hotplug_slot, __FUNCTION__);
266 int retval; 280 int retval;
267 281
268 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name); 282 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
@@ -276,7 +290,7 @@ static int get_power_status (struct hotplug_slot *hotplug_slot, u8 *value)
276 290
277static int get_attention_status (struct hotplug_slot *hotplug_slot, u8 *value) 291static int get_attention_status (struct hotplug_slot *hotplug_slot, u8 *value)
278{ 292{
279 struct slot *slot = get_slot (hotplug_slot, __FUNCTION__); 293 struct slot *slot = get_slot(hotplug_slot, __FUNCTION__);
280 int retval; 294 int retval;
281 295
282 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name); 296 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
@@ -290,7 +304,7 @@ static int get_attention_status (struct hotplug_slot *hotplug_slot, u8 *value)
290 304
291static int get_latch_status (struct hotplug_slot *hotplug_slot, u8 *value) 305static int get_latch_status (struct hotplug_slot *hotplug_slot, u8 *value)
292{ 306{
293 struct slot *slot = get_slot (hotplug_slot, __FUNCTION__); 307 struct slot *slot = get_slot(hotplug_slot, __FUNCTION__);
294 int retval; 308 int retval;
295 309
296 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name); 310 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
@@ -304,7 +318,7 @@ static int get_latch_status (struct hotplug_slot *hotplug_slot, u8 *value)
304 318
305static int get_adapter_status (struct hotplug_slot *hotplug_slot, u8 *value) 319static int get_adapter_status (struct hotplug_slot *hotplug_slot, u8 *value)
306{ 320{
307 struct slot *slot = get_slot (hotplug_slot, __FUNCTION__); 321 struct slot *slot = get_slot(hotplug_slot, __FUNCTION__);
308 int retval; 322 int retval;
309 323
310 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name); 324 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
@@ -318,7 +332,7 @@ static int get_adapter_status (struct hotplug_slot *hotplug_slot, u8 *value)
318 332
319static int get_address (struct hotplug_slot *hotplug_slot, u32 *value) 333static int get_address (struct hotplug_slot *hotplug_slot, u32 *value)
320{ 334{
321 struct slot *slot = get_slot (hotplug_slot, __FUNCTION__); 335 struct slot *slot = get_slot(hotplug_slot, __FUNCTION__);
322 struct pci_bus *bus = slot->ctrl->pci_dev->subordinate; 336 struct pci_bus *bus = slot->ctrl->pci_dev->subordinate;
323 337
324 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name); 338 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
@@ -330,11 +344,11 @@ static int get_address (struct hotplug_slot *hotplug_slot, u32 *value)
330 344
331static int get_max_bus_speed (struct hotplug_slot *hotplug_slot, enum pci_bus_speed *value) 345static int get_max_bus_speed (struct hotplug_slot *hotplug_slot, enum pci_bus_speed *value)
332{ 346{
333 struct slot *slot = get_slot (hotplug_slot, __FUNCTION__); 347 struct slot *slot = get_slot(hotplug_slot, __FUNCTION__);
334 int retval; 348 int retval;
335 349
336 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name); 350 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
337 351
338 retval = slot->hpc_ops->get_max_bus_speed(slot, value); 352 retval = slot->hpc_ops->get_max_bus_speed(slot, value);
339 if (retval < 0) 353 if (retval < 0)
340 *value = PCI_SPEED_UNKNOWN; 354 *value = PCI_SPEED_UNKNOWN;
@@ -344,11 +358,11 @@ static int get_max_bus_speed (struct hotplug_slot *hotplug_slot, enum pci_bus_sp
344 358
345static int get_cur_bus_speed (struct hotplug_slot *hotplug_slot, enum pci_bus_speed *value) 359static int get_cur_bus_speed (struct hotplug_slot *hotplug_slot, enum pci_bus_speed *value)
346{ 360{
347 struct slot *slot = get_slot (hotplug_slot, __FUNCTION__); 361 struct slot *slot = get_slot(hotplug_slot, __FUNCTION__);
348 int retval; 362 int retval;
349 363
350 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name); 364 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
351 365
352 retval = slot->hpc_ops->get_cur_bus_speed(slot, value); 366 retval = slot->hpc_ops->get_cur_bus_speed(slot, value);
353 if (retval < 0) 367 if (retval < 0)
354 *value = PCI_SPEED_UNKNOWN; 368 *value = PCI_SPEED_UNKNOWN;
@@ -372,61 +386,54 @@ static int shpc_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
372 int rc; 386 int rc;
373 struct controller *ctrl; 387 struct controller *ctrl;
374 struct slot *t_slot; 388 struct slot *t_slot;
375 int first_device_num; /* first PCI device number supported by this SHPC */ 389 int first_device_num; /* first PCI device number */
376 int num_ctlr_slots; /* number of slots supported by this SHPC */ 390 int num_ctlr_slots; /* number of slots implemented */
377 391
378 if (!is_shpc_capable(pdev)) 392 if (!is_shpc_capable(pdev))
379 return -ENODEV; 393 return -ENODEV;
380 394
381 ctrl = (struct controller *) kmalloc(sizeof(struct controller), GFP_KERNEL); 395 ctrl = kzalloc(sizeof(*ctrl), GFP_KERNEL);
382 if (!ctrl) { 396 if (!ctrl) {
383 err("%s : out of memory\n", __FUNCTION__); 397 err("%s : out of memory\n", __FUNCTION__);
384 goto err_out_none; 398 goto err_out_none;
385 } 399 }
386 memset(ctrl, 0, sizeof(struct controller)); 400 INIT_LIST_HEAD(&ctrl->slot_list);
387 401
388 rc = shpc_init(ctrl, pdev); 402 rc = shpc_init(ctrl, pdev);
389 if (rc) { 403 if (rc) {
390 dbg("%s: controller initialization failed\n", SHPC_MODULE_NAME); 404 dbg("%s: controller initialization failed\n",
405 SHPC_MODULE_NAME);
391 goto err_out_free_ctrl; 406 goto err_out_free_ctrl;
392 } 407 }
393 408
394 pci_set_drvdata(pdev, ctrl); 409 pci_set_drvdata(pdev, ctrl);
395 410
396 ctrl->pci_bus = kmalloc (sizeof (*ctrl->pci_bus), GFP_KERNEL);
397 if (!ctrl->pci_bus) {
398 err("out of memory\n");
399 rc = -ENOMEM;
400 goto err_out_unmap_mmio_region;
401 }
402
403 memcpy (ctrl->pci_bus, pdev->bus, sizeof (*ctrl->pci_bus));
404 ctrl->bus = pdev->bus->number; 411 ctrl->bus = pdev->bus->number;
405 ctrl->slot_bus = pdev->subordinate->number; 412 ctrl->slot_bus = pdev->subordinate->number;
406
407 ctrl->device = PCI_SLOT(pdev->devfn); 413 ctrl->device = PCI_SLOT(pdev->devfn);
408 ctrl->function = PCI_FUNC(pdev->devfn); 414 ctrl->function = PCI_FUNC(pdev->devfn);
409 dbg("ctrl bus=0x%x, device=%x, function=%x, irq=%x\n", ctrl->bus, ctrl->device, ctrl->function, pdev->irq); 415
416 dbg("ctrl bus=0x%x, device=%x, function=%x, irq=%x\n",
417 ctrl->bus, ctrl->device, ctrl->function, pdev->irq);
410 418
411 /* 419 /*
412 * Save configuration headers for this and subordinate PCI buses 420 * Save configuration headers for this and subordinate PCI buses
413 */ 421 */
414
415 rc = get_ctlr_slot_config(ctrl); 422 rc = get_ctlr_slot_config(ctrl);
416 if (rc) { 423 if (rc) {
417 err(msg_initialization_err, rc); 424 err(msg_initialization_err, rc);
418 goto err_out_free_ctrl_bus; 425 goto err_out_release_ctlr;
419 } 426 }
420 first_device_num = ctrl->slot_device_offset; 427 first_device_num = ctrl->slot_device_offset;
421 num_ctlr_slots = ctrl->num_slots; 428 num_ctlr_slots = ctrl->num_slots;
422 429
423 ctrl->add_support = 1; 430 ctrl->add_support = 1;
424 431
425 /* Setup the slot information structures */ 432 /* Setup the slot information structures */
426 rc = init_slots(ctrl); 433 rc = init_slots(ctrl);
427 if (rc) { 434 if (rc) {
428 err(msg_initialization_err, 6); 435 err(msg_initialization_err, 6);
429 goto err_out_free_ctrl_slot; 436 goto err_out_release_ctlr;
430 } 437 }
431 438
432 /* Now hpc_functions (slot->hpc_ops->functions) are ready */ 439 /* Now hpc_functions (slot->hpc_ops->functions) are ready */
@@ -437,30 +444,16 @@ static int shpc_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
437 dbg("%s: t_slot->hp_slot %x\n", __FUNCTION__,t_slot->hp_slot); 444 dbg("%s: t_slot->hp_slot %x\n", __FUNCTION__,t_slot->hp_slot);
438 445
439 if (rc || ctrl->speed == PCI_SPEED_UNKNOWN) { 446 if (rc || ctrl->speed == PCI_SPEED_UNKNOWN) {
440 err(SHPC_MODULE_NAME ": Can't get current bus speed. Set to 33MHz PCI.\n"); 447 err(SHPC_MODULE_NAME ": Can't get current bus speed. "
448 "Set to 33MHz PCI.\n");
441 ctrl->speed = PCI_SPEED_33MHz; 449 ctrl->speed = PCI_SPEED_33MHz;
442 } 450 }
443 451
444 /* Finish setting up the hot plug ctrl device */
445 ctrl->next_event = 0;
446
447 if (!shpchp_ctrl_list) {
448 shpchp_ctrl_list = ctrl;
449 ctrl->next = NULL;
450 } else {
451 ctrl->next = shpchp_ctrl_list;
452 shpchp_ctrl_list = ctrl;
453 }
454
455 shpchp_create_ctrl_files(ctrl); 452 shpchp_create_ctrl_files(ctrl);
456 453
457 return 0; 454 return 0;
458 455
459err_out_free_ctrl_slot: 456err_out_release_ctlr:
460 cleanup_slots(ctrl);
461err_out_free_ctrl_bus:
462 kfree(ctrl->pci_bus);
463err_out_unmap_mmio_region:
464 ctrl->hpc_ops->release_ctlr(ctrl); 457 ctrl->hpc_ops->release_ctlr(ctrl);
465err_out_free_ctrl: 458err_out_free_ctrl:
466 kfree(ctrl); 459 kfree(ctrl);
@@ -468,74 +461,28 @@ err_out_none:
468 return -ENODEV; 461 return -ENODEV;
469} 462}
470 463
471 464static void shpc_remove(struct pci_dev *dev)
472static int shpc_start_thread(void)
473{
474 int retval = 0;
475
476 dbg("Initialize + Start the notification/polling mechanism \n");
477
478 retval = shpchp_event_start_thread();
479 if (retval) {
480 dbg("shpchp_event_start_thread() failed\n");
481 return retval;
482 }
483
484 return retval;
485}
486
487static void __exit unload_shpchpd(void)
488{ 465{
489 struct controller *ctrl; 466 struct controller *ctrl = pci_get_drvdata(dev);
490 struct controller *tctrl;
491
492 ctrl = shpchp_ctrl_list;
493
494 while (ctrl) {
495 shpchp_remove_ctrl_files(ctrl);
496 cleanup_slots(ctrl);
497
498 kfree (ctrl->pci_bus);
499 ctrl->hpc_ops->release_ctlr(ctrl);
500
501 tctrl = ctrl;
502 ctrl = ctrl->next;
503
504 kfree(tctrl);
505 }
506
507 /* Stop the notification mechanism */
508 shpchp_event_stop_thread();
509 467
468 shpchp_remove_ctrl_files(ctrl);
469 ctrl->hpc_ops->release_ctlr(ctrl);
470 kfree(ctrl);
510} 471}
511 472
512
513static struct pci_device_id shpcd_pci_tbl[] = { 473static struct pci_device_id shpcd_pci_tbl[] = {
514 { 474 {PCI_DEVICE_CLASS(((PCI_CLASS_BRIDGE_PCI << 8) | 0x00), ~0)},
515 .class = ((PCI_CLASS_BRIDGE_PCI << 8) | 0x00),
516 .class_mask = ~0,
517 .vendor = PCI_ANY_ID,
518 .device = PCI_ANY_ID,
519 .subvendor = PCI_ANY_ID,
520 .subdevice = PCI_ANY_ID,
521 },
522
523 { /* end: all zeroes */ } 475 { /* end: all zeroes */ }
524}; 476};
525
526MODULE_DEVICE_TABLE(pci, shpcd_pci_tbl); 477MODULE_DEVICE_TABLE(pci, shpcd_pci_tbl);
527 478
528
529
530static struct pci_driver shpc_driver = { 479static struct pci_driver shpc_driver = {
531 .name = SHPC_MODULE_NAME, 480 .name = SHPC_MODULE_NAME,
532 .id_table = shpcd_pci_tbl, 481 .id_table = shpcd_pci_tbl,
533 .probe = shpc_probe, 482 .probe = shpc_probe,
534 /* remove: shpc_remove_one, */ 483 .remove = shpc_remove,
535}; 484};
536 485
537
538
539static int __init shpcd_init(void) 486static int __init shpcd_init(void)
540{ 487{
541 int retval = 0; 488 int retval = 0;
@@ -544,17 +491,15 @@ static int __init shpcd_init(void)
544 shpchp_poll_mode = 1; 491 shpchp_poll_mode = 1;
545#endif 492#endif
546 493
547 retval = shpc_start_thread(); 494 shpchp_wq = create_singlethread_workqueue("shpchpd");
548 if (retval) 495 if (!shpchp_wq)
549 goto error_hpc_init; 496 return -ENOMEM;
550 497
551 retval = pci_register_driver(&shpc_driver); 498 retval = pci_register_driver(&shpc_driver);
552 dbg("%s: pci_register_driver = %d\n", __FUNCTION__, retval); 499 dbg("%s: pci_register_driver = %d\n", __FUNCTION__, retval);
553 info(DRIVER_DESC " version: " DRIVER_VERSION "\n"); 500 info(DRIVER_DESC " version: " DRIVER_VERSION "\n");
554
555error_hpc_init:
556 if (retval) { 501 if (retval) {
557 shpchp_event_stop_thread(); 502 destroy_workqueue(shpchp_wq);
558 } 503 }
559 return retval; 504 return retval;
560} 505}
@@ -562,10 +507,8 @@ error_hpc_init:
562static void __exit shpcd_cleanup(void) 507static void __exit shpcd_cleanup(void)
563{ 508{
564 dbg("unload_shpchpd()\n"); 509 dbg("unload_shpchpd()\n");
565 unload_shpchpd();
566
567 pci_unregister_driver(&shpc_driver); 510 pci_unregister_driver(&shpc_driver);
568 511 destroy_workqueue(shpchp_wq);
569 info(DRIVER_DESC " version: " DRIVER_VERSION " unloaded\n"); 512 info(DRIVER_DESC " version: " DRIVER_VERSION " unloaded\n");
570} 513}
571 514
diff --git a/drivers/pci/hotplug/shpchp_ctrl.c b/drivers/pci/hotplug/shpchp_ctrl.c
index 643252d9bf..4e6381481c 100644
--- a/drivers/pci/hotplug/shpchp_ctrl.c
+++ b/drivers/pci/hotplug/shpchp_ctrl.c
@@ -32,65 +32,50 @@
32#include <linux/types.h> 32#include <linux/types.h>
33#include <linux/smp_lock.h> 33#include <linux/smp_lock.h>
34#include <linux/pci.h> 34#include <linux/pci.h>
35#include <linux/workqueue.h>
35#include "../pci.h" 36#include "../pci.h"
36#include "shpchp.h" 37#include "shpchp.h"
37 38
38static void interrupt_event_handler(struct controller *ctrl); 39static void interrupt_event_handler(void *data);
40static int shpchp_enable_slot(struct slot *p_slot);
41static int shpchp_disable_slot(struct slot *p_slot);
39 42
40static struct semaphore event_semaphore; /* mutex for process loop (up if something to process) */ 43static int queue_interrupt_event(struct slot *p_slot, u32 event_type)
41static struct semaphore event_exit; /* guard ensure thread has exited before calling it quits */ 44{
42static int event_finished; 45 struct event_info *info;
43static unsigned long pushbutton_pending; /* = 0 */ 46
47 info = kmalloc(sizeof(*info), GFP_ATOMIC);
48 if (!info)
49 return -ENOMEM;
50
51 info->event_type = event_type;
52 info->p_slot = p_slot;
53 INIT_WORK(&info->work, interrupt_event_handler, info);
54
55 schedule_work(&info->work);
56
57 return 0;
58}
44 59
45u8 shpchp_handle_attention_button(u8 hp_slot, void *inst_id) 60u8 shpchp_handle_attention_button(u8 hp_slot, void *inst_id)
46{ 61{
47 struct controller *ctrl = (struct controller *) inst_id; 62 struct controller *ctrl = (struct controller *) inst_id;
48 struct slot *p_slot; 63 struct slot *p_slot;
49 u8 rc = 0; 64 u32 event_type;
50 u8 getstatus;
51 struct event_info *taskInfo;
52 65
53 /* Attention Button Change */ 66 /* Attention Button Change */
54 dbg("shpchp: Attention button interrupt received.\n"); 67 dbg("shpchp: Attention button interrupt received.\n");
55 68
56 /* This is the structure that tells the worker thread what to do */
57 taskInfo = &(ctrl->event_queue[ctrl->next_event]);
58 p_slot = shpchp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset); 69 p_slot = shpchp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset);
59
60 p_slot->hpc_ops->get_adapter_status(p_slot, &(p_slot->presence_save)); 70 p_slot->hpc_ops->get_adapter_status(p_slot, &(p_slot->presence_save));
61 p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
62
63 ctrl->next_event = (ctrl->next_event + 1) % 10;
64 taskInfo->hp_slot = hp_slot;
65
66 rc++;
67 71
68 /* 72 /*
69 * Button pressed - See if need to TAKE ACTION!!! 73 * Button pressed - See if need to TAKE ACTION!!!
70 */ 74 */
71 info("Button pressed on Slot(%d)\n", ctrl->first_slot + hp_slot); 75 info("Button pressed on Slot(%d)\n", ctrl->first_slot + hp_slot);
72 taskInfo->event_type = INT_BUTTON_PRESS; 76 event_type = INT_BUTTON_PRESS;
73
74 if ((p_slot->state == BLINKINGON_STATE)
75 || (p_slot->state == BLINKINGOFF_STATE)) {
76 /* Cancel if we are still blinking; this means that we press the
77 * attention again before the 5 sec. limit expires to cancel hot-add
78 * or hot-remove
79 */
80 taskInfo->event_type = INT_BUTTON_CANCEL;
81 info("Button cancel on Slot(%d)\n", ctrl->first_slot + hp_slot);
82 } else if ((p_slot->state == POWERON_STATE)
83 || (p_slot->state == POWEROFF_STATE)) {
84 /* Ignore if the slot is on power-on or power-off state; this
85 * means that the previous attention button action to hot-add or
86 * hot-remove is undergoing
87 */
88 taskInfo->event_type = INT_BUTTON_IGNORE;
89 info("Button ignore on Slot(%d)\n", ctrl->first_slot + hp_slot);
90 }
91 77
92 if (rc) 78 queue_interrupt_event(p_slot, event_type);
93 up(&event_semaphore); /* signal event thread that new event is posted */
94 79
95 return 0; 80 return 0;
96 81
@@ -100,21 +85,12 @@ u8 shpchp_handle_switch_change(u8 hp_slot, void *inst_id)
100{ 85{
101 struct controller *ctrl = (struct controller *) inst_id; 86 struct controller *ctrl = (struct controller *) inst_id;
102 struct slot *p_slot; 87 struct slot *p_slot;
103 u8 rc = 0;
104 u8 getstatus; 88 u8 getstatus;
105 struct event_info *taskInfo; 89 u32 event_type;
106 90
107 /* Switch Change */ 91 /* Switch Change */
108 dbg("shpchp: Switch interrupt received.\n"); 92 dbg("shpchp: Switch interrupt received.\n");
109 93
110 /* This is the structure that tells the worker thread
111 * what to do
112 */
113 taskInfo = &(ctrl->event_queue[ctrl->next_event]);
114 ctrl->next_event = (ctrl->next_event + 1) % 10;
115 taskInfo->hp_slot = hp_slot;
116
117 rc++;
118 p_slot = shpchp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset); 94 p_slot = shpchp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset);
119 p_slot->hpc_ops->get_adapter_status(p_slot, &(p_slot->presence_save)); 95 p_slot->hpc_ops->get_adapter_status(p_slot, &(p_slot->presence_save));
120 p_slot->hpc_ops->get_latch_status(p_slot, &getstatus); 96 p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
@@ -126,9 +102,9 @@ u8 shpchp_handle_switch_change(u8 hp_slot, void *inst_id)
126 * Switch opened 102 * Switch opened
127 */ 103 */
128 info("Latch open on Slot(%d)\n", ctrl->first_slot + hp_slot); 104 info("Latch open on Slot(%d)\n", ctrl->first_slot + hp_slot);
129 taskInfo->event_type = INT_SWITCH_OPEN; 105 event_type = INT_SWITCH_OPEN;
130 if (p_slot->pwr_save && p_slot->presence_save) { 106 if (p_slot->pwr_save && p_slot->presence_save) {
131 taskInfo->event_type = INT_POWER_FAULT; 107 event_type = INT_POWER_FAULT;
132 err("Surprise Removal of card\n"); 108 err("Surprise Removal of card\n");
133 } 109 }
134 } else { 110 } else {
@@ -136,34 +112,23 @@ u8 shpchp_handle_switch_change(u8 hp_slot, void *inst_id)
136 * Switch closed 112 * Switch closed
137 */ 113 */
138 info("Latch close on Slot(%d)\n", ctrl->first_slot + hp_slot); 114 info("Latch close on Slot(%d)\n", ctrl->first_slot + hp_slot);
139 taskInfo->event_type = INT_SWITCH_CLOSE; 115 event_type = INT_SWITCH_CLOSE;
140 } 116 }
141 117
142 if (rc) 118 queue_interrupt_event(p_slot, event_type);
143 up(&event_semaphore); /* signal event thread that new event is posted */
144 119
145 return rc; 120 return 1;
146} 121}
147 122
148u8 shpchp_handle_presence_change(u8 hp_slot, void *inst_id) 123u8 shpchp_handle_presence_change(u8 hp_slot, void *inst_id)
149{ 124{
150 struct controller *ctrl = (struct controller *) inst_id; 125 struct controller *ctrl = (struct controller *) inst_id;
151 struct slot *p_slot; 126 struct slot *p_slot;
152 u8 rc = 0; 127 u32 event_type;
153 /*u8 temp_byte;*/
154 struct event_info *taskInfo;
155 128
156 /* Presence Change */ 129 /* Presence Change */
157 dbg("shpchp: Presence/Notify input change.\n"); 130 dbg("shpchp: Presence/Notify input change.\n");
158 131
159 /* This is the structure that tells the worker thread
160 * what to do
161 */
162 taskInfo = &(ctrl->event_queue[ctrl->next_event]);
163 ctrl->next_event = (ctrl->next_event + 1) % 10;
164 taskInfo->hp_slot = hp_slot;
165
166 rc++;
167 p_slot = shpchp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset); 132 p_slot = shpchp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset);
168 133
169 /* 134 /*
@@ -175,39 +140,29 @@ u8 shpchp_handle_presence_change(u8 hp_slot, void *inst_id)
175 * Card Present 140 * Card Present
176 */ 141 */
177 info("Card present on Slot(%d)\n", ctrl->first_slot + hp_slot); 142 info("Card present on Slot(%d)\n", ctrl->first_slot + hp_slot);
178 taskInfo->event_type = INT_PRESENCE_ON; 143 event_type = INT_PRESENCE_ON;
179 } else { 144 } else {
180 /* 145 /*
181 * Not Present 146 * Not Present
182 */ 147 */
183 info("Card not present on Slot(%d)\n", ctrl->first_slot + hp_slot); 148 info("Card not present on Slot(%d)\n", ctrl->first_slot + hp_slot);
184 taskInfo->event_type = INT_PRESENCE_OFF; 149 event_type = INT_PRESENCE_OFF;
185 } 150 }
186 151
187 if (rc) 152 queue_interrupt_event(p_slot, event_type);
188 up(&event_semaphore); /* signal event thread that new event is posted */
189 153
190 return rc; 154 return 1;
191} 155}
192 156
193u8 shpchp_handle_power_fault(u8 hp_slot, void *inst_id) 157u8 shpchp_handle_power_fault(u8 hp_slot, void *inst_id)
194{ 158{
195 struct controller *ctrl = (struct controller *) inst_id; 159 struct controller *ctrl = (struct controller *) inst_id;
196 struct slot *p_slot; 160 struct slot *p_slot;
197 u8 rc = 0; 161 u32 event_type;
198 struct event_info *taskInfo;
199 162
200 /* Power fault */ 163 /* Power fault */
201 dbg("shpchp: Power fault interrupt received.\n"); 164 dbg("shpchp: Power fault interrupt received.\n");
202 165
203 /* This is the structure that tells the worker thread
204 * what to do
205 */
206 taskInfo = &(ctrl->event_queue[ctrl->next_event]);
207 ctrl->next_event = (ctrl->next_event + 1) % 10;
208 taskInfo->hp_slot = hp_slot;
209
210 rc++;
211 p_slot = shpchp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset); 166 p_slot = shpchp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset);
212 167
213 if ( !(p_slot->hpc_ops->query_power_fault(p_slot))) { 168 if ( !(p_slot->hpc_ops->query_power_fault(p_slot))) {
@@ -216,21 +171,21 @@ u8 shpchp_handle_power_fault(u8 hp_slot, void *inst_id)
216 */ 171 */
217 info("Power fault cleared on Slot(%d)\n", ctrl->first_slot + hp_slot); 172 info("Power fault cleared on Slot(%d)\n", ctrl->first_slot + hp_slot);
218 p_slot->status = 0x00; 173 p_slot->status = 0x00;
219 taskInfo->event_type = INT_POWER_FAULT_CLEAR; 174 event_type = INT_POWER_FAULT_CLEAR;
220 } else { 175 } else {
221 /* 176 /*
222 * Power fault 177 * Power fault
223 */ 178 */
224 info("Power fault on Slot(%d)\n", ctrl->first_slot + hp_slot); 179 info("Power fault on Slot(%d)\n", ctrl->first_slot + hp_slot);
225 taskInfo->event_type = INT_POWER_FAULT; 180 event_type = INT_POWER_FAULT;
226 /* set power fault status for this board */ 181 /* set power fault status for this board */
227 p_slot->status = 0xFF; 182 p_slot->status = 0xFF;
228 info("power fault bit %x set\n", hp_slot); 183 info("power fault bit %x set\n", hp_slot);
229 } 184 }
230 if (rc)
231 up(&event_semaphore); /* signal event thread that new event is posted */
232 185
233 return rc; 186 queue_interrupt_event(p_slot, event_type);
187
188 return 1;
234} 189}
235 190
236/* The following routines constitute the bulk of the 191/* The following routines constitute the bulk of the
@@ -242,21 +197,11 @@ static int change_bus_speed(struct controller *ctrl, struct slot *p_slot,
242 int rc = 0; 197 int rc = 0;
243 198
244 dbg("%s: change to speed %d\n", __FUNCTION__, speed); 199 dbg("%s: change to speed %d\n", __FUNCTION__, speed);
245 down(&ctrl->crit_sect);
246 if ((rc = p_slot->hpc_ops->set_bus_speed_mode(p_slot, speed))) { 200 if ((rc = p_slot->hpc_ops->set_bus_speed_mode(p_slot, speed))) {
247 err("%s: Issue of set bus speed mode command failed\n", __FUNCTION__); 201 err("%s: Issue of set bus speed mode command failed\n",
248 up(&ctrl->crit_sect); 202 __FUNCTION__);
249 return WRONG_BUS_FREQUENCY; 203 return WRONG_BUS_FREQUENCY;
250 } 204 }
251
252 if ((rc = p_slot->hpc_ops->check_cmd_status(ctrl))) {
253 err("%s: Can't set bus speed/mode in the case of adapter & bus mismatch\n",
254 __FUNCTION__);
255 err("%s: Error code (%d)\n", __FUNCTION__, rc);
256 up(&ctrl->crit_sect);
257 return WRONG_BUS_FREQUENCY;
258 }
259 up(&ctrl->crit_sect);
260 return rc; 205 return rc;
261} 206}
262 207
@@ -265,33 +210,26 @@ static int fix_bus_speed(struct controller *ctrl, struct slot *pslot,
265 enum pci_bus_speed msp) 210 enum pci_bus_speed msp)
266{ 211{
267 int rc = 0; 212 int rc = 0;
268 213
269 if (flag != 0) { /* Other slots on the same bus are occupied */ 214 /*
270 if ( asp < bsp ) { 215 * If other slots on the same bus are occupied, we cannot
271 err("%s: speed of bus %x and adapter %x mismatch\n", __FUNCTION__, bsp, asp); 216 * change the bus speed.
272 return WRONG_BUS_FREQUENCY; 217 */
218 if (flag) {
219 if (asp < bsp) {
220 err("%s: speed of bus %x and adapter %x mismatch\n",
221 __FUNCTION__, bsp, asp);
222 rc = WRONG_BUS_FREQUENCY;
273 } 223 }
224 return rc;
225 }
226
227 if (asp < msp) {
228 if (bsp != asp)
229 rc = change_bus_speed(ctrl, pslot, asp);
274 } else { 230 } else {
275 /* Other slots on the same bus are empty */ 231 if (bsp != msp)
276 if (msp == bsp) { 232 rc = change_bus_speed(ctrl, pslot, msp);
277 /* if adapter_speed >= bus_speed, do nothing */
278 if (asp < bsp) {
279 /*
280 * Try to lower bus speed to accommodate the adapter if other slots
281 * on the same controller are empty
282 */
283 if ((rc = change_bus_speed(ctrl, pslot, asp)))
284 return rc;
285 }
286 } else {
287 if (asp < msp) {
288 if ((rc = change_bus_speed(ctrl, pslot, asp)))
289 return rc;
290 } else {
291 if ((rc = change_bus_speed(ctrl, pslot, msp)))
292 return rc;
293 }
294 }
295 } 233 }
296 return rc; 234 return rc;
297} 235}
@@ -308,8 +246,7 @@ static int board_added(struct slot *p_slot)
308 u8 hp_slot; 246 u8 hp_slot;
309 u8 slots_not_empty = 0; 247 u8 slots_not_empty = 0;
310 int rc = 0; 248 int rc = 0;
311 enum pci_bus_speed adapter_speed, bus_speed, max_bus_speed; 249 enum pci_bus_speed asp, bsp, msp;
312 u8 pi, mode;
313 struct controller *ctrl = p_slot->ctrl; 250 struct controller *ctrl = p_slot->ctrl;
314 251
315 hp_slot = p_slot->device - ctrl->slot_device_offset; 252 hp_slot = p_slot->device - ctrl->slot_device_offset;
@@ -318,187 +255,68 @@ static int board_added(struct slot *p_slot)
318 __FUNCTION__, p_slot->device, 255 __FUNCTION__, p_slot->device,
319 ctrl->slot_device_offset, hp_slot); 256 ctrl->slot_device_offset, hp_slot);
320 257
321 /* Wait for exclusive access to hardware */
322 down(&ctrl->crit_sect);
323
324 /* Power on slot without connecting to bus */ 258 /* Power on slot without connecting to bus */
325 rc = p_slot->hpc_ops->power_on_slot(p_slot); 259 rc = p_slot->hpc_ops->power_on_slot(p_slot);
326 if (rc) { 260 if (rc) {
327 err("%s: Failed to power on slot\n", __FUNCTION__); 261 err("%s: Failed to power on slot\n", __FUNCTION__);
328 /* Done with exclusive hardware access */
329 up(&ctrl->crit_sect);
330 return -1; 262 return -1;
331 } 263 }
332 264
333 rc = p_slot->hpc_ops->check_cmd_status(ctrl);
334 if (rc) {
335 err("%s: Failed to power on slot, error code(%d)\n", __FUNCTION__, rc);
336 /* Done with exclusive hardware access */
337 up(&ctrl->crit_sect);
338 return -1;
339 }
340
341
342 if ((ctrl->pci_dev->vendor == 0x8086) && (ctrl->pci_dev->device == 0x0332)) { 265 if ((ctrl->pci_dev->vendor == 0x8086) && (ctrl->pci_dev->device == 0x0332)) {
343 if (slots_not_empty) 266 if (slots_not_empty)
344 return WRONG_BUS_FREQUENCY; 267 return WRONG_BUS_FREQUENCY;
345 268
346 if ((rc = p_slot->hpc_ops->set_bus_speed_mode(p_slot, PCI_SPEED_33MHz))) { 269 if ((rc = p_slot->hpc_ops->set_bus_speed_mode(p_slot, PCI_SPEED_33MHz))) {
347 err("%s: Issue of set bus speed mode command failed\n", __FUNCTION__); 270 err("%s: Issue of set bus speed mode command failed\n", __FUNCTION__);
348 up(&ctrl->crit_sect);
349 return WRONG_BUS_FREQUENCY; 271 return WRONG_BUS_FREQUENCY;
350 } 272 }
351 273
352 if ((rc = p_slot->hpc_ops->check_cmd_status(ctrl))) {
353 err("%s: Can't set bus speed/mode in the case of adapter & bus mismatch\n",
354 __FUNCTION__);
355 err("%s: Error code (%d)\n", __FUNCTION__, rc);
356 up(&ctrl->crit_sect);
357 return WRONG_BUS_FREQUENCY;
358 }
359 /* turn on board, blink green LED, turn off Amber LED */ 274 /* turn on board, blink green LED, turn off Amber LED */
360 if ((rc = p_slot->hpc_ops->slot_enable(p_slot))) { 275 if ((rc = p_slot->hpc_ops->slot_enable(p_slot))) {
361 err("%s: Issue of Slot Enable command failed\n", __FUNCTION__); 276 err("%s: Issue of Slot Enable command failed\n", __FUNCTION__);
362 up(&ctrl->crit_sect);
363 return rc; 277 return rc;
364 } 278 }
365
366 if ((rc = p_slot->hpc_ops->check_cmd_status(ctrl))) {
367 err("%s: Failed to enable slot, error code(%d)\n", __FUNCTION__, rc);
368 up(&ctrl->crit_sect);
369 return rc;
370 }
371 } 279 }
372 280
373 rc = p_slot->hpc_ops->get_adapter_speed(p_slot, &adapter_speed); 281 rc = p_slot->hpc_ops->get_adapter_speed(p_slot, &asp);
374 /* 0 = PCI 33Mhz, 1 = PCI 66 Mhz, 2 = PCI-X 66 PA, 4 = PCI-X 66 ECC, */ 282 if (rc) {
375 /* 5 = PCI-X 133 PA, 7 = PCI-X 133 ECC, 0xa = PCI-X 133 Mhz 266, */ 283 err("%s: Can't get adapter speed or bus mode mismatch\n",
376 /* 0xd = PCI-X 133 Mhz 533 */ 284 __FUNCTION__);
377 /* This encoding is different from the one used in cur_bus_speed & */
378 /* max_bus_speed */
379
380 if (rc || adapter_speed == PCI_SPEED_UNKNOWN) {
381 err("%s: Can't get adapter speed or bus mode mismatch\n", __FUNCTION__);
382 /* Done with exclusive hardware access */
383 up(&ctrl->crit_sect);
384 return WRONG_BUS_FREQUENCY; 285 return WRONG_BUS_FREQUENCY;
385 } 286 }
386 287
387 rc = p_slot->hpc_ops->get_cur_bus_speed(p_slot, &bus_speed); 288 rc = p_slot->hpc_ops->get_cur_bus_speed(p_slot, &bsp);
388 if (rc || bus_speed == PCI_SPEED_UNKNOWN) { 289 if (rc) {
389 err("%s: Can't get bus operation speed\n", __FUNCTION__); 290 err("%s: Can't get bus operation speed\n", __FUNCTION__);
390 /* Done with exclusive hardware access */
391 up(&ctrl->crit_sect);
392 return WRONG_BUS_FREQUENCY; 291 return WRONG_BUS_FREQUENCY;
393 } 292 }
394 293
395 rc = p_slot->hpc_ops->get_max_bus_speed(p_slot, &max_bus_speed); 294 rc = p_slot->hpc_ops->get_max_bus_speed(p_slot, &msp);
396 if (rc || max_bus_speed == PCI_SPEED_UNKNOWN) { 295 if (rc) {
397 err("%s: Can't get max bus operation speed\n", __FUNCTION__); 296 err("%s: Can't get max bus operation speed\n", __FUNCTION__);
398 max_bus_speed = bus_speed; 297 msp = bsp;
399 }
400
401 /* Done with exclusive hardware access */
402 up(&ctrl->crit_sect);
403
404 if ((rc = p_slot->hpc_ops->get_prog_int(p_slot, &pi))) {
405 err("%s: Can't get controller programming interface, set it to 1\n", __FUNCTION__);
406 pi = 1;
407 } 298 }
408 299
409 /* Check if there are other slots or devices on the same bus */ 300 /* Check if there are other slots or devices on the same bus */
410 if (!list_empty(&ctrl->pci_dev->subordinate->devices)) 301 if (!list_empty(&ctrl->pci_dev->subordinate->devices))
411 slots_not_empty = 1; 302 slots_not_empty = 1;
412 303
413 dbg("%s: slots_not_empty %d, pi %d\n", __FUNCTION__, 304 dbg("%s: slots_not_empty %d, adapter_speed %d, bus_speed %d, "
414 slots_not_empty, pi); 305 "max_bus_speed %d\n", __FUNCTION__, slots_not_empty, asp,
415 dbg("adapter_speed %d, bus_speed %d, max_bus_speed %d\n", 306 bsp, msp);
416 adapter_speed, bus_speed, max_bus_speed);
417
418 if (pi == 2) {
419 dbg("%s: In PI = %d\n", __FUNCTION__, pi);
420 if ((rc = p_slot->hpc_ops->get_mode1_ECC_cap(p_slot, &mode))) {
421 err("%s: Can't get Mode1_ECC, set mode to 0\n", __FUNCTION__);
422 mode = 0;
423 }
424 307
425 switch (adapter_speed) { 308 rc = fix_bus_speed(ctrl, p_slot, slots_not_empty, asp, bsp, msp);
426 case PCI_SPEED_133MHz_PCIX_533: 309 if (rc)
427 case PCI_SPEED_133MHz_PCIX_266: 310 return rc;
428 if ((bus_speed != adapter_speed) &&
429 ((rc = fix_bus_speed(ctrl, p_slot, slots_not_empty, adapter_speed, bus_speed, max_bus_speed))))
430 return rc;
431 break;
432 case PCI_SPEED_133MHz_PCIX_ECC:
433 case PCI_SPEED_133MHz_PCIX:
434 if (mode) { /* Bus - Mode 1 ECC */
435 if ((bus_speed != 0x7) &&
436 ((rc = fix_bus_speed(ctrl, p_slot, slots_not_empty, adapter_speed, bus_speed, max_bus_speed))))
437 return rc;
438 } else {
439 if ((bus_speed != 0x4) &&
440 ((rc = fix_bus_speed(ctrl, p_slot, slots_not_empty, adapter_speed, bus_speed, max_bus_speed))))
441 return rc;
442 }
443 break;
444 case PCI_SPEED_66MHz_PCIX_ECC:
445 case PCI_SPEED_66MHz_PCIX:
446 if (mode) { /* Bus - Mode 1 ECC */
447 if ((bus_speed != 0x5) &&
448 ((rc = fix_bus_speed(ctrl, p_slot, slots_not_empty, adapter_speed, bus_speed, max_bus_speed))))
449 return rc;
450 } else {
451 if ((bus_speed != 0x2) &&
452 ((rc = fix_bus_speed(ctrl, p_slot, slots_not_empty, adapter_speed, bus_speed, max_bus_speed))))
453 return rc;
454 }
455 break;
456 case PCI_SPEED_66MHz:
457 if ((bus_speed != 0x1) &&
458 ((rc = fix_bus_speed(ctrl, p_slot, slots_not_empty, adapter_speed, bus_speed, max_bus_speed))))
459 return rc;
460 break;
461 case PCI_SPEED_33MHz:
462 if (bus_speed > 0x0) {
463 if (slots_not_empty == 0) {
464 if ((rc = change_bus_speed(ctrl, p_slot, adapter_speed)))
465 return rc;
466 } else {
467 err("%s: speed of bus %x and adapter %x mismatch\n", __FUNCTION__, bus_speed, adapter_speed);
468 return WRONG_BUS_FREQUENCY;
469 }
470 }
471 break;
472 default:
473 err("%s: speed of bus %x and adapter %x mismatch\n", __FUNCTION__, bus_speed, adapter_speed);
474 return WRONG_BUS_FREQUENCY;
475 }
476 } else {
477 /* If adpater_speed == bus_speed, nothing to do here */
478 dbg("%s: In PI = %d\n", __FUNCTION__, pi);
479 if ((adapter_speed != bus_speed) &&
480 ((rc = fix_bus_speed(ctrl, p_slot, slots_not_empty, adapter_speed, bus_speed, max_bus_speed))))
481 return rc;
482 }
483 311
484 down(&ctrl->crit_sect);
485 /* turn on board, blink green LED, turn off Amber LED */ 312 /* turn on board, blink green LED, turn off Amber LED */
486 if ((rc = p_slot->hpc_ops->slot_enable(p_slot))) { 313 if ((rc = p_slot->hpc_ops->slot_enable(p_slot))) {
487 err("%s: Issue of Slot Enable command failed\n", __FUNCTION__); 314 err("%s: Issue of Slot Enable command failed\n", __FUNCTION__);
488 up(&ctrl->crit_sect);
489 return rc; 315 return rc;
490 } 316 }
491 317
492 if ((rc = p_slot->hpc_ops->check_cmd_status(ctrl))) {
493 err("%s: Failed to enable slot, error code(%d)\n", __FUNCTION__, rc);
494 up(&ctrl->crit_sect);
495 return rc;
496 }
497
498 up(&ctrl->crit_sect);
499
500 /* Wait for ~1 second */ 318 /* Wait for ~1 second */
501 wait_for_ctrl_irq (ctrl); 319 msleep(1000);
502 320
503 dbg("%s: slot status = %x\n", __FUNCTION__, p_slot->status); 321 dbg("%s: slot status = %x\n", __FUNCTION__, p_slot->status);
504 /* Check for a power fault */ 322 /* Check for a power fault */
@@ -520,40 +338,18 @@ static int board_added(struct slot *p_slot)
520 p_slot->is_a_board = 0x01; 338 p_slot->is_a_board = 0x01;
521 p_slot->pwr_save = 1; 339 p_slot->pwr_save = 1;
522 340
523 /* Wait for exclusive access to hardware */
524 down(&ctrl->crit_sect);
525
526 p_slot->hpc_ops->green_led_on(p_slot); 341 p_slot->hpc_ops->green_led_on(p_slot);
527 342
528 /* Done with exclusive hardware access */
529 up(&ctrl->crit_sect);
530
531 return 0; 343 return 0;
532 344
533err_exit: 345err_exit:
534 /* Wait for exclusive access to hardware */
535 down(&ctrl->crit_sect);
536
537 /* turn off slot, turn on Amber LED, turn off Green LED */ 346 /* turn off slot, turn on Amber LED, turn off Green LED */
538 rc = p_slot->hpc_ops->slot_disable(p_slot); 347 rc = p_slot->hpc_ops->slot_disable(p_slot);
539 if (rc) { 348 if (rc) {
540 err("%s: Issue of Slot Disable command failed\n", __FUNCTION__); 349 err("%s: Issue of Slot Disable command failed\n", __FUNCTION__);
541 /* Done with exclusive hardware access */
542 up(&ctrl->crit_sect);
543 return rc;
544 }
545
546 rc = p_slot->hpc_ops->check_cmd_status(ctrl);
547 if (rc) {
548 err("%s: Failed to disable slot, error code(%d)\n", __FUNCTION__, rc);
549 /* Done with exclusive hardware access */
550 up(&ctrl->crit_sect);
551 return rc; 350 return rc;
552 } 351 }
553 352
554 /* Done with exclusive hardware access */
555 up(&ctrl->crit_sect);
556
557 return(rc); 353 return(rc);
558} 354}
559 355
@@ -580,37 +376,19 @@ static int remove_board(struct slot *p_slot)
580 if (p_slot->is_a_board) 376 if (p_slot->is_a_board)
581 p_slot->status = 0x01; 377 p_slot->status = 0x01;
582 378
583 /* Wait for exclusive access to hardware */
584 down(&ctrl->crit_sect);
585
586 /* turn off slot, turn on Amber LED, turn off Green LED */ 379 /* turn off slot, turn on Amber LED, turn off Green LED */
587 rc = p_slot->hpc_ops->slot_disable(p_slot); 380 rc = p_slot->hpc_ops->slot_disable(p_slot);
588 if (rc) { 381 if (rc) {
589 err("%s: Issue of Slot Disable command failed\n", __FUNCTION__); 382 err("%s: Issue of Slot Disable command failed\n", __FUNCTION__);
590 /* Done with exclusive hardware access */
591 up(&ctrl->crit_sect);
592 return rc; 383 return rc;
593 } 384 }
594
595 rc = p_slot->hpc_ops->check_cmd_status(ctrl);
596 if (rc) {
597 err("%s: Failed to disable slot, error code(%d)\n", __FUNCTION__, rc);
598 /* Done with exclusive hardware access */
599 up(&ctrl->crit_sect);
600 return rc;
601 }
602 385
603 rc = p_slot->hpc_ops->set_attention_status(p_slot, 0); 386 rc = p_slot->hpc_ops->set_attention_status(p_slot, 0);
604 if (rc) { 387 if (rc) {
605 err("%s: Issue of Set Attention command failed\n", __FUNCTION__); 388 err("%s: Issue of Set Attention command failed\n", __FUNCTION__);
606 /* Done with exclusive hardware access */
607 up(&ctrl->crit_sect);
608 return rc; 389 return rc;
609 } 390 }
610 391
611 /* Done with exclusive hardware access */
612 up(&ctrl->crit_sect);
613
614 p_slot->pwr_save = 0; 392 p_slot->pwr_save = 0;
615 p_slot->is_a_board = 0; 393 p_slot->is_a_board = 0;
616 394
@@ -618,13 +396,10 @@ static int remove_board(struct slot *p_slot)
618} 396}
619 397
620 398
621static void pushbutton_helper_thread (unsigned long data) 399struct pushbutton_work_info {
622{ 400 struct slot *p_slot;
623 pushbutton_pending = data; 401 struct work_struct work;
624 402};
625 up(&event_semaphore);
626}
627
628 403
629/** 404/**
630 * shpchp_pushbutton_thread 405 * shpchp_pushbutton_thread
@@ -633,96 +408,63 @@ static void pushbutton_helper_thread (unsigned long data)
633 * Handles all pending events and exits. 408 * Handles all pending events and exits.
634 * 409 *
635 */ 410 */
636static void shpchp_pushbutton_thread (unsigned long slot) 411static void shpchp_pushbutton_thread(void *data)
637{ 412{
638 struct slot *p_slot = (struct slot *) slot; 413 struct pushbutton_work_info *info = data;
639 u8 getstatus; 414 struct slot *p_slot = info->p_slot;
640
641 pushbutton_pending = 0;
642
643 if (!p_slot) {
644 dbg("%s: Error! slot NULL\n", __FUNCTION__);
645 return;
646 }
647
648 p_slot->hpc_ops->get_power_status(p_slot, &getstatus);
649 if (getstatus) {
650 p_slot->state = POWEROFF_STATE;
651 415
416 mutex_lock(&p_slot->lock);
417 switch (p_slot->state) {
418 case POWEROFF_STATE:
419 mutex_unlock(&p_slot->lock);
652 shpchp_disable_slot(p_slot); 420 shpchp_disable_slot(p_slot);
421 mutex_lock(&p_slot->lock);
653 p_slot->state = STATIC_STATE; 422 p_slot->state = STATIC_STATE;
654 } else { 423 break;
655 p_slot->state = POWERON_STATE; 424 case POWERON_STATE:
656 425 mutex_unlock(&p_slot->lock);
657 if (shpchp_enable_slot(p_slot)) { 426 if (shpchp_enable_slot(p_slot))
658 /* Wait for exclusive access to hardware */
659 down(&p_slot->ctrl->crit_sect);
660
661 p_slot->hpc_ops->green_led_off(p_slot); 427 p_slot->hpc_ops->green_led_off(p_slot);
662 428 mutex_lock(&p_slot->lock);
663 /* Done with exclusive hardware access */
664 up(&p_slot->ctrl->crit_sect);
665 }
666 p_slot->state = STATIC_STATE; 429 p_slot->state = STATIC_STATE;
430 break;
431 default:
432 break;
667 } 433 }
434 mutex_unlock(&p_slot->lock);
668 435
669 return; 436 kfree(info);
670}
671
672
673/* this is the main worker thread */
674static int event_thread(void* data)
675{
676 struct controller *ctrl;
677 lock_kernel();
678 daemonize("shpchpd_event");
679 unlock_kernel();
680
681 while (1) {
682 dbg("!!!!event_thread sleeping\n");
683 down_interruptible (&event_semaphore);
684 dbg("event_thread woken finished = %d\n", event_finished);
685 if (event_finished || signal_pending(current))
686 break;
687 /* Do stuff here */
688 if (pushbutton_pending)
689 shpchp_pushbutton_thread(pushbutton_pending);
690 else
691 for (ctrl = shpchp_ctrl_list; ctrl; ctrl=ctrl->next)
692 interrupt_event_handler(ctrl);
693 }
694 dbg("event_thread signals exit\n");
695 up(&event_exit);
696 return 0;
697} 437}
698 438
699int shpchp_event_start_thread (void) 439void queue_pushbutton_work(void *data)
700{ 440{
701 int pid; 441 struct slot *p_slot = data;
442 struct pushbutton_work_info *info;
702 443
703 /* initialize our semaphores */ 444 info = kmalloc(sizeof(*info), GFP_KERNEL);
704 init_MUTEX_LOCKED(&event_exit); 445 if (!info) {
705 event_finished=0; 446 err("%s: Cannot allocate memory\n", __FUNCTION__);
706 447 return;
707 init_MUTEX_LOCKED(&event_semaphore);
708 pid = kernel_thread(event_thread, NULL, 0);
709
710 if (pid < 0) {
711 err ("Can't start up our event thread\n");
712 return -1;
713 } 448 }
714 return 0; 449 info->p_slot = p_slot;
715} 450 INIT_WORK(&info->work, shpchp_pushbutton_thread, info);
716
717 451
718void shpchp_event_stop_thread (void) 452 mutex_lock(&p_slot->lock);
719{ 453 switch (p_slot->state) {
720 event_finished = 1; 454 case BLINKINGOFF_STATE:
721 up(&event_semaphore); 455 p_slot->state = POWEROFF_STATE;
722 down(&event_exit); 456 break;
457 case BLINKINGON_STATE:
458 p_slot->state = POWERON_STATE;
459 break;
460 default:
461 goto out;
462 }
463 queue_work(shpchp_wq, &info->work);
464 out:
465 mutex_unlock(&p_slot->lock);
723} 466}
724 467
725
726static int update_slot_info (struct slot *slot) 468static int update_slot_info (struct slot *slot)
727{ 469{
728 struct hotplug_slot_info *info; 470 struct hotplug_slot_info *info;
@@ -742,149 +484,110 @@ static int update_slot_info (struct slot *slot)
742 return result; 484 return result;
743} 485}
744 486
745static void interrupt_event_handler(struct controller *ctrl) 487/*
488 * Note: This function must be called with slot->lock held
489 */
490static void handle_button_press_event(struct slot *p_slot)
746{ 491{
747 int loop = 0;
748 int change = 1;
749 u8 hp_slot;
750 u8 getstatus; 492 u8 getstatus;
751 struct slot *p_slot;
752 493
753 while (change) { 494 switch (p_slot->state) {
754 change = 0; 495 case STATIC_STATE:
755 496 p_slot->hpc_ops->get_power_status(p_slot, &getstatus);
756 for (loop = 0; loop < 10; loop++) { 497 if (getstatus) {
757 if (ctrl->event_queue[loop].event_type != 0) { 498 p_slot->state = BLINKINGOFF_STATE;
758 dbg("%s:loop %x event_type %x\n", __FUNCTION__, loop, 499 info(msg_button_off, p_slot->number);
759 ctrl->event_queue[loop].event_type); 500 } else {
760 hp_slot = ctrl->event_queue[loop].hp_slot; 501 p_slot->state = BLINKINGON_STATE;
761 502 info(msg_button_on, p_slot->number);
762 p_slot = shpchp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset); 503 }
763 504 /* blink green LED and turn off amber */
764 if (ctrl->event_queue[loop].event_type == INT_BUTTON_CANCEL) { 505 p_slot->hpc_ops->green_led_blink(p_slot);
765 dbg("%s: button cancel\n", __FUNCTION__); 506 p_slot->hpc_ops->set_attention_status(p_slot, 0);
766 del_timer(&p_slot->task_event); 507
767 508 schedule_delayed_work(&p_slot->work, 5*HZ);
768 switch (p_slot->state) { 509 break;
769 case BLINKINGOFF_STATE: 510 case BLINKINGOFF_STATE:
770 /* Wait for exclusive access to hardware */ 511 case BLINKINGON_STATE:
771 down(&ctrl->crit_sect); 512 /*
772 513 * Cancel if we are still blinking; this means that we
773 p_slot->hpc_ops->green_led_on(p_slot); 514 * press the attention again before the 5 sec. limit
774 515 * expires to cancel hot-add or hot-remove
775 p_slot->hpc_ops->set_attention_status(p_slot, 0); 516 */
776 517 info("Button cancel on Slot(%s)\n", p_slot->name);
777 /* Done with exclusive hardware access */ 518 dbg("%s: button cancel\n", __FUNCTION__);
778 up(&ctrl->crit_sect); 519 cancel_delayed_work(&p_slot->work);
779 break; 520 if (p_slot->state == BLINKINGOFF_STATE)
780 case BLINKINGON_STATE: 521 p_slot->hpc_ops->green_led_on(p_slot);
781 /* Wait for exclusive access to hardware */ 522 else
782 down(&ctrl->crit_sect); 523 p_slot->hpc_ops->green_led_off(p_slot);
783 524 p_slot->hpc_ops->set_attention_status(p_slot, 0);
784 p_slot->hpc_ops->green_led_off(p_slot); 525 info(msg_button_cancel, p_slot->number);
785 526 p_slot->state = STATIC_STATE;
786 p_slot->hpc_ops->set_attention_status(p_slot, 0); 527 break;
787 528 case POWEROFF_STATE:
788 /* Done with exclusive hardware access */ 529 case POWERON_STATE:
789 up(&ctrl->crit_sect); 530 /*
790 531 * Ignore if the slot is on power-on or power-off state;
791 break; 532 * this means that the previous attention button action
792 default: 533 * to hot-add or hot-remove is undergoing
793 warn("Not a valid state\n"); 534 */
794 return; 535 info("Button ignore on Slot(%s)\n", p_slot->name);
795 } 536 update_slot_info(p_slot);
796 info(msg_button_cancel, p_slot->number); 537 break;
797 p_slot->state = STATIC_STATE; 538 default:
798 } else if (ctrl->event_queue[loop].event_type == INT_BUTTON_PRESS) { 539 warn("Not a valid state\n");
799 /* Button Pressed (No action on 1st press...) */ 540 break;
800 dbg("%s: Button pressed\n", __FUNCTION__);
801
802 p_slot->hpc_ops->get_power_status(p_slot, &getstatus);
803 if (getstatus) {
804 /* slot is on */
805 dbg("%s: slot is on\n", __FUNCTION__);
806 p_slot->state = BLINKINGOFF_STATE;
807 info(msg_button_off, p_slot->number);
808 } else {
809 /* slot is off */
810 dbg("%s: slot is off\n", __FUNCTION__);
811 p_slot->state = BLINKINGON_STATE;
812 info(msg_button_on, p_slot->number);
813 }
814
815 /* Wait for exclusive access to hardware */
816 down(&ctrl->crit_sect);
817
818 /* blink green LED and turn off amber */
819 p_slot->hpc_ops->green_led_blink(p_slot);
820
821 p_slot->hpc_ops->set_attention_status(p_slot, 0);
822
823 /* Done with exclusive hardware access */
824 up(&ctrl->crit_sect);
825
826 init_timer(&p_slot->task_event);
827 p_slot->task_event.expires = jiffies + 5 * HZ; /* 5 second delay */
828 p_slot->task_event.function = (void (*)(unsigned long)) pushbutton_helper_thread;
829 p_slot->task_event.data = (unsigned long) p_slot;
830
831 dbg("%s: add_timer p_slot = %p\n", __FUNCTION__,(void *) p_slot);
832 add_timer(&p_slot->task_event);
833 } else if (ctrl->event_queue[loop].event_type == INT_POWER_FAULT) {
834 /***********POWER FAULT********************/
835 dbg("%s: power fault\n", __FUNCTION__);
836 /* Wait for exclusive access to hardware */
837 down(&ctrl->crit_sect);
838
839 p_slot->hpc_ops->set_attention_status(p_slot, 1);
840
841 p_slot->hpc_ops->green_led_off(p_slot);
842
843 /* Done with exclusive hardware access */
844 up(&ctrl->crit_sect);
845 } else {
846 /* refresh notification */
847 if (p_slot)
848 update_slot_info(p_slot);
849 }
850
851 ctrl->event_queue[loop].event_type = 0;
852
853 change = 1;
854 }
855 } /* End of FOR loop */
856 } 541 }
542}
543
544static void interrupt_event_handler(void *data)
545{
546 struct event_info *info = data;
547 struct slot *p_slot = info->p_slot;
548
549 mutex_lock(&p_slot->lock);
550 switch (info->event_type) {
551 case INT_BUTTON_PRESS:
552 handle_button_press_event(p_slot);
553 break;
554 case INT_POWER_FAULT:
555 dbg("%s: power fault\n", __FUNCTION__);
556 p_slot->hpc_ops->set_attention_status(p_slot, 1);
557 p_slot->hpc_ops->green_led_off(p_slot);
558 break;
559 default:
560 update_slot_info(p_slot);
561 break;
562 }
563 mutex_unlock(&p_slot->lock);
857 564
858 return; 565 kfree(info);
859} 566}
860 567
861 568
862int shpchp_enable_slot (struct slot *p_slot) 569static int shpchp_enable_slot (struct slot *p_slot)
863{ 570{
864 u8 getstatus = 0; 571 u8 getstatus = 0;
865 int rc; 572 int rc, retval = -ENODEV;
866 573
867 /* Check to see if (latch closed, card present, power off) */ 574 /* Check to see if (latch closed, card present, power off) */
868 down(&p_slot->ctrl->crit_sect); 575 mutex_lock(&p_slot->ctrl->crit_sect);
869 rc = p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus); 576 rc = p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus);
870 if (rc || !getstatus) { 577 if (rc || !getstatus) {
871 info("%s: no adapter on slot(%x)\n", __FUNCTION__, p_slot->number); 578 info("%s: no adapter on slot(%x)\n", __FUNCTION__, p_slot->number);
872 up(&p_slot->ctrl->crit_sect); 579 goto out;
873 return -ENODEV;
874 } 580 }
875 rc = p_slot->hpc_ops->get_latch_status(p_slot, &getstatus); 581 rc = p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
876 if (rc || getstatus) { 582 if (rc || getstatus) {
877 info("%s: latch open on slot(%x)\n", __FUNCTION__, p_slot->number); 583 info("%s: latch open on slot(%x)\n", __FUNCTION__, p_slot->number);
878 up(&p_slot->ctrl->crit_sect); 584 goto out;
879 return -ENODEV;
880 } 585 }
881 rc = p_slot->hpc_ops->get_power_status(p_slot, &getstatus); 586 rc = p_slot->hpc_ops->get_power_status(p_slot, &getstatus);
882 if (rc || getstatus) { 587 if (rc || getstatus) {
883 info("%s: already enabled on slot(%x)\n", __FUNCTION__, p_slot->number); 588 info("%s: already enabled on slot(%x)\n", __FUNCTION__, p_slot->number);
884 up(&p_slot->ctrl->crit_sect); 589 goto out;
885 return -ENODEV;
886 } 590 }
887 up(&p_slot->ctrl->crit_sect);
888 591
889 p_slot->is_a_board = 1; 592 p_slot->is_a_board = 1;
890 593
@@ -899,56 +602,119 @@ int shpchp_enable_slot (struct slot *p_slot)
899 && p_slot->ctrl->num_slots == 1) { 602 && p_slot->ctrl->num_slots == 1) {
900 /* handle amd pogo errata; this must be done before enable */ 603 /* handle amd pogo errata; this must be done before enable */
901 amd_pogo_errata_save_misc_reg(p_slot); 604 amd_pogo_errata_save_misc_reg(p_slot);
902 rc = board_added(p_slot); 605 retval = board_added(p_slot);
903 /* handle amd pogo errata; this must be done after enable */ 606 /* handle amd pogo errata; this must be done after enable */
904 amd_pogo_errata_restore_misc_reg(p_slot); 607 amd_pogo_errata_restore_misc_reg(p_slot);
905 } else 608 } else
906 rc = board_added(p_slot); 609 retval = board_added(p_slot);
907 610
908 if (rc) { 611 if (retval) {
909 p_slot->hpc_ops->get_adapter_status(p_slot, 612 p_slot->hpc_ops->get_adapter_status(p_slot,
910 &(p_slot->presence_save)); 613 &(p_slot->presence_save));
911 p_slot->hpc_ops->get_latch_status(p_slot, &getstatus); 614 p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
912 } 615 }
913 616
914 update_slot_info(p_slot); 617 update_slot_info(p_slot);
915 return rc; 618 out:
619 mutex_unlock(&p_slot->ctrl->crit_sect);
620 return retval;
916} 621}
917 622
918 623
919int shpchp_disable_slot (struct slot *p_slot) 624static int shpchp_disable_slot (struct slot *p_slot)
920{ 625{
921 u8 getstatus = 0; 626 u8 getstatus = 0;
922 int ret = 0; 627 int rc, retval = -ENODEV;
923 628
924 if (!p_slot->ctrl) 629 if (!p_slot->ctrl)
925 return -ENODEV; 630 return -ENODEV;
926 631
927 /* Check to see if (latch closed, card present, power on) */ 632 /* Check to see if (latch closed, card present, power on) */
928 down(&p_slot->ctrl->crit_sect); 633 mutex_lock(&p_slot->ctrl->crit_sect);
929 634
930 ret = p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus); 635 rc = p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus);
931 if (ret || !getstatus) { 636 if (rc || !getstatus) {
932 info("%s: no adapter on slot(%x)\n", __FUNCTION__, p_slot->number); 637 info("%s: no adapter on slot(%x)\n", __FUNCTION__, p_slot->number);
933 up(&p_slot->ctrl->crit_sect); 638 goto out;
934 return -ENODEV;
935 } 639 }
936 ret = p_slot->hpc_ops->get_latch_status(p_slot, &getstatus); 640 rc = p_slot->hpc_ops->get_latch_status(p_slot, &getstatus);
937 if (ret || getstatus) { 641 if (rc || getstatus) {
938 info("%s: latch open on slot(%x)\n", __FUNCTION__, p_slot->number); 642 info("%s: latch open on slot(%x)\n", __FUNCTION__, p_slot->number);
939 up(&p_slot->ctrl->crit_sect); 643 goto out;
940 return -ENODEV;
941 } 644 }
942 ret = p_slot->hpc_ops->get_power_status(p_slot, &getstatus); 645 rc = p_slot->hpc_ops->get_power_status(p_slot, &getstatus);
943 if (ret || !getstatus) { 646 if (rc || !getstatus) {
944 info("%s: already disabled slot(%x)\n", __FUNCTION__, p_slot->number); 647 info("%s: already disabled slot(%x)\n", __FUNCTION__, p_slot->number);
945 up(&p_slot->ctrl->crit_sect); 648 goto out;
946 return -ENODEV;
947 } 649 }
948 up(&p_slot->ctrl->crit_sect);
949 650
950 ret = remove_board(p_slot); 651 retval = remove_board(p_slot);
951 update_slot_info(p_slot); 652 update_slot_info(p_slot);
952 return ret; 653 out:
654 mutex_unlock(&p_slot->ctrl->crit_sect);
655 return retval;
953} 656}
954 657
658int shpchp_sysfs_enable_slot(struct slot *p_slot)
659{
660 int retval = -ENODEV;
661
662 mutex_lock(&p_slot->lock);
663 switch (p_slot->state) {
664 case BLINKINGON_STATE:
665 cancel_delayed_work(&p_slot->work);
666 case STATIC_STATE:
667 p_slot->state = POWERON_STATE;
668 mutex_unlock(&p_slot->lock);
669 retval = shpchp_enable_slot(p_slot);
670 mutex_lock(&p_slot->lock);
671 p_slot->state = STATIC_STATE;
672 break;
673 case POWERON_STATE:
674 info("Slot %s is already in powering on state\n",
675 p_slot->name);
676 break;
677 case BLINKINGOFF_STATE:
678 case POWEROFF_STATE:
679 info("Already enabled on slot %s\n", p_slot->name);
680 break;
681 default:
682 err("Not a valid state on slot %s\n", p_slot->name);
683 break;
684 }
685 mutex_unlock(&p_slot->lock);
686
687 return retval;
688}
689
690int shpchp_sysfs_disable_slot(struct slot *p_slot)
691{
692 int retval = -ENODEV;
693
694 mutex_lock(&p_slot->lock);
695 switch (p_slot->state) {
696 case BLINKINGOFF_STATE:
697 cancel_delayed_work(&p_slot->work);
698 case STATIC_STATE:
699 p_slot->state = POWEROFF_STATE;
700 mutex_unlock(&p_slot->lock);
701 retval = shpchp_disable_slot(p_slot);
702 mutex_lock(&p_slot->lock);
703 p_slot->state = STATIC_STATE;
704 break;
705 case POWEROFF_STATE:
706 info("Slot %s is already in powering off state\n",
707 p_slot->name);
708 break;
709 case BLINKINGON_STATE:
710 case POWERON_STATE:
711 info("Already disabled on slot %s\n", p_slot->name);
712 break;
713 default:
714 err("Not a valid state on slot %s\n", p_slot->name);
715 break;
716 }
717 mutex_unlock(&p_slot->lock);
718
719 return retval;
720}
diff --git a/drivers/pci/hotplug/shpchp_hpc.c b/drivers/pci/hotplug/shpchp_hpc.c
index b4226ff3a8..66123cf4de 100644
--- a/drivers/pci/hotplug/shpchp_hpc.c
+++ b/drivers/pci/hotplug/shpchp_hpc.c
@@ -82,31 +82,6 @@
82#define SLOT_100MHZ_PCIX_533 0x0f000000 82#define SLOT_100MHZ_PCIX_533 0x0f000000
83#define SLOT_133MHZ_PCIX_533 0xf0000000 83#define SLOT_133MHZ_PCIX_533 0xf0000000
84 84
85
86/* Secondary Bus Configuration Register */
87/* For PI = 1, Bits 0 to 2 have been encoded as follows to show current bus speed/mode */
88#define PCI_33MHZ 0x0
89#define PCI_66MHZ 0x1
90#define PCIX_66MHZ 0x2
91#define PCIX_100MHZ 0x3
92#define PCIX_133MHZ 0x4
93
94/* For PI = 2, Bits 0 to 3 have been encoded as follows to show current bus speed/mode */
95#define PCI_33MHZ 0x0
96#define PCI_66MHZ 0x1
97#define PCIX_66MHZ 0x2
98#define PCIX_100MHZ 0x3
99#define PCIX_133MHZ 0x4
100#define PCIX_66MHZ_ECC 0x5
101#define PCIX_100MHZ_ECC 0x6
102#define PCIX_133MHZ_ECC 0x7
103#define PCIX_66MHZ_266 0x9
104#define PCIX_100MHZ_266 0xa
105#define PCIX_133MHZ_266 0xb
106#define PCIX_66MHZ_533 0x11
107#define PCIX_100MHZ_533 0x12
108#define PCIX_133MHZ_533 0x13
109
110/* Slot Configuration */ 85/* Slot Configuration */
111#define SLOT_NUM 0x0000001F 86#define SLOT_NUM 0x0000001F
112#define FIRST_DEV_NUM 0x00001F00 87#define FIRST_DEV_NUM 0x00001F00
@@ -231,6 +206,7 @@ static spinlock_t list_lock;
231static irqreturn_t shpc_isr(int IRQ, void *dev_id, struct pt_regs *regs); 206static irqreturn_t shpc_isr(int IRQ, void *dev_id, struct pt_regs *regs);
232 207
233static void start_int_poll_timer(struct php_ctlr_state_s *php_ctlr, int seconds); 208static void start_int_poll_timer(struct php_ctlr_state_s *php_ctlr, int seconds);
209static int hpc_check_cmd_status(struct controller *ctrl);
234 210
235/* This is the interrupt polling timeout function. */ 211/* This is the interrupt polling timeout function. */
236static void int_poll_timeout(unsigned long lphp_ctlr) 212static void int_poll_timeout(unsigned long lphp_ctlr)
@@ -303,10 +279,13 @@ static int shpc_write_cmd(struct slot *slot, u8 t_slot, u8 cmd)
303 int i; 279 int i;
304 280
305 DBG_ENTER_ROUTINE 281 DBG_ENTER_ROUTINE
306 282
283 mutex_lock(&slot->ctrl->cmd_lock);
284
307 if (!php_ctlr) { 285 if (!php_ctlr) {
308 err("%s: Invalid HPC controller handle!\n", __FUNCTION__); 286 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
309 return -1; 287 retval = -EINVAL;
288 goto out;
310 } 289 }
311 290
312 for (i = 0; i < 10; i++) { 291 for (i = 0; i < 10; i++) {
@@ -323,7 +302,8 @@ static int shpc_write_cmd(struct slot *slot, u8 t_slot, u8 cmd)
323 if (cmd_status & 0x1) { 302 if (cmd_status & 0x1) {
324 /* After 1 sec and and the controller is still busy */ 303 /* After 1 sec and and the controller is still busy */
325 err("%s : Controller is still busy after 1 sec.\n", __FUNCTION__); 304 err("%s : Controller is still busy after 1 sec.\n", __FUNCTION__);
326 return -1; 305 retval = -EBUSY;
306 goto out;
327 } 307 }
328 308
329 ++t_slot; 309 ++t_slot;
@@ -340,6 +320,17 @@ static int shpc_write_cmd(struct slot *slot, u8 t_slot, u8 cmd)
340 * Wait for command completion. 320 * Wait for command completion.
341 */ 321 */
342 retval = shpc_wait_cmd(slot->ctrl); 322 retval = shpc_wait_cmd(slot->ctrl);
323 if (retval)
324 goto out;
325
326 cmd_status = hpc_check_cmd_status(slot->ctrl);
327 if (cmd_status) {
328 err("%s: Failed to issued command 0x%x (error code = %d)\n",
329 __FUNCTION__, cmd, cmd_status);
330 retval = -EIO;
331 }
332 out:
333 mutex_unlock(&slot->ctrl->cmd_lock);
343 334
344 DBG_LEAVE_ROUTINE 335 DBG_LEAVE_ROUTINE
345 return retval; 336 return retval;
@@ -532,81 +523,41 @@ static int hpc_get_prog_int(struct slot *slot, u8 *prog_int)
532 523
533static int hpc_get_adapter_speed(struct slot *slot, enum pci_bus_speed *value) 524static int hpc_get_adapter_speed(struct slot *slot, enum pci_bus_speed *value)
534{ 525{
535 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
536 u32 slot_reg;
537 u16 slot_status, sec_bus_status;
538 u8 m66_cap, pcix_cap, pi;
539 int retval = 0; 526 int retval = 0;
527 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
528 u32 slot_reg = readl(php_ctlr->creg + SLOT1 + 4 * slot->hp_slot);
529 u8 pcix_cap = (slot_reg >> 12) & 7;
530 u8 m66_cap = (slot_reg >> 9) & 1;
540 531
541 DBG_ENTER_ROUTINE 532 DBG_ENTER_ROUTINE
542 533
543 if (!slot->ctrl->hpc_ctlr_handle) { 534 dbg("%s: slot_reg = %x, pcix_cap = %x, m66_cap = %x\n",
544 err("%s: Invalid HPC controller handle!\n", __FUNCTION__); 535 __FUNCTION__, slot_reg, pcix_cap, m66_cap);
545 return -1;
546 }
547
548 if (slot->hp_slot >= php_ctlr->num_slots) {
549 err("%s: Invalid HPC slot number!\n", __FUNCTION__);
550 return -1;
551 }
552
553 pi = readb(php_ctlr->creg + PROG_INTERFACE);
554 slot_reg = readl(php_ctlr->creg + SLOT1 + 4*(slot->hp_slot));
555 dbg("%s: pi = %d, slot_reg = %x\n", __FUNCTION__, pi, slot_reg);
556 slot_status = (u16) slot_reg;
557 dbg("%s: slot_status = %x\n", __FUNCTION__, slot_status);
558 sec_bus_status = readw(php_ctlr->creg + SEC_BUS_CONFIG);
559
560 pcix_cap = (u8) ((slot_status & 0x3000) >> 12);
561 dbg("%s: pcix_cap = %x\n", __FUNCTION__, pcix_cap);
562 m66_cap = (u8) ((slot_status & 0x0200) >> 9);
563 dbg("%s: m66_cap = %x\n", __FUNCTION__, m66_cap);
564
565 536
566 if (pi == 2) { 537 switch (pcix_cap) {
567 switch (pcix_cap) { 538 case 0x0:
568 case 0: 539 *value = m66_cap ? PCI_SPEED_66MHz : PCI_SPEED_33MHz;
569 *value = m66_cap ? PCI_SPEED_66MHz : PCI_SPEED_33MHz; 540 break;
570 break; 541 case 0x1:
571 case 1: 542 *value = PCI_SPEED_66MHz_PCIX;
572 *value = PCI_SPEED_66MHz_PCIX; 543 break;
573 break; 544 case 0x3:
574 case 3: 545 *value = PCI_SPEED_133MHz_PCIX;
575 *value = PCI_SPEED_133MHz_PCIX; 546 break;
576 break; 547 case 0x4:
577 case 4: 548 *value = PCI_SPEED_133MHz_PCIX_266;
578 *value = PCI_SPEED_133MHz_PCIX_266; 549 break;
579 break; 550 case 0x5:
580 case 5: 551 *value = PCI_SPEED_133MHz_PCIX_533;
581 *value = PCI_SPEED_133MHz_PCIX_533; 552 break;
582 break; 553 case 0x2:
583 case 2: /* Reserved */ 554 default:
584 default: 555 *value = PCI_SPEED_UNKNOWN;
585 *value = PCI_SPEED_UNKNOWN; 556 retval = -ENODEV;
586 retval = -ENODEV; 557 break;
587 break;
588 }
589 } else {
590 switch (pcix_cap) {
591 case 0:
592 *value = m66_cap ? PCI_SPEED_66MHz : PCI_SPEED_33MHz;
593 break;
594 case 1:
595 *value = PCI_SPEED_66MHz_PCIX;
596 break;
597 case 3:
598 *value = PCI_SPEED_133MHz_PCIX;
599 break;
600 case 2: /* Reserved */
601 default:
602 *value = PCI_SPEED_UNKNOWN;
603 retval = -ENODEV;
604 break;
605 }
606 } 558 }
607 559
608 dbg("Adapter speed = %d\n", *value); 560 dbg("Adapter speed = %d\n", *value);
609
610 DBG_LEAVE_ROUTINE 561 DBG_LEAVE_ROUTINE
611 return retval; 562 return retval;
612} 563}
@@ -797,6 +748,7 @@ static void hpc_release_ctlr(struct controller *ctrl)
797{ 748{
798 struct php_ctlr_state_s *php_ctlr = ctrl->hpc_ctlr_handle; 749 struct php_ctlr_state_s *php_ctlr = ctrl->hpc_ctlr_handle;
799 struct php_ctlr_state_s *p, *p_prev; 750 struct php_ctlr_state_s *p, *p_prev;
751 int i;
800 752
801 DBG_ENTER_ROUTINE 753 DBG_ENTER_ROUTINE
802 754
@@ -805,6 +757,14 @@ static void hpc_release_ctlr(struct controller *ctrl)
805 return ; 757 return ;
806 } 758 }
807 759
760 /*
761 * Mask all slot event interrupts
762 */
763 for (i = 0; i < ctrl->num_slots; i++)
764 writel(0xffff3fff, php_ctlr->creg + SLOT1 + (4 * i));
765
766 cleanup_slots(ctrl);
767
808 if (shpchp_poll_mode) { 768 if (shpchp_poll_mode) {
809 del_timer(&php_ctlr->int_poll_timer); 769 del_timer(&php_ctlr->int_poll_timer);
810 } else { 770 } else {
@@ -814,6 +774,7 @@ static void hpc_release_ctlr(struct controller *ctrl)
814 pci_disable_msi(php_ctlr->pci_dev); 774 pci_disable_msi(php_ctlr->pci_dev);
815 } 775 }
816 } 776 }
777
817 if (php_ctlr->pci_dev) { 778 if (php_ctlr->pci_dev) {
818 iounmap(php_ctlr->creg); 779 iounmap(php_ctlr->creg);
819 release_mem_region(ctrl->mmio_base, ctrl->mmio_size); 780 release_mem_region(ctrl->mmio_base, ctrl->mmio_size);
@@ -939,98 +900,66 @@ static int hpc_slot_disable(struct slot * slot)
939 900
940static int hpc_set_bus_speed_mode(struct slot * slot, enum pci_bus_speed value) 901static int hpc_set_bus_speed_mode(struct slot * slot, enum pci_bus_speed value)
941{ 902{
942 u8 slot_cmd; 903 int retval;
943 u8 pi;
944 int retval = 0;
945 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle; 904 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
905 u8 pi, cmd;
946 906
947 DBG_ENTER_ROUTINE 907 DBG_ENTER_ROUTINE
948
949 if (!slot->ctrl->hpc_ctlr_handle) {
950 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
951 return -1;
952 }
953 908
954 pi = readb(php_ctlr->creg + PROG_INTERFACE); 909 pi = readb(php_ctlr->creg + PROG_INTERFACE);
955 910 if ((pi == 1) && (value > PCI_SPEED_133MHz_PCIX))
956 if (pi == 1) { 911 return -EINVAL;
957 switch (value) {
958 case 0:
959 slot_cmd = SETA_PCI_33MHZ;
960 break;
961 case 1:
962 slot_cmd = SETA_PCI_66MHZ;
963 break;
964 case 2:
965 slot_cmd = SETA_PCIX_66MHZ;
966 break;
967 case 3:
968 slot_cmd = SETA_PCIX_100MHZ;
969 break;
970 case 4:
971 slot_cmd = SETA_PCIX_133MHZ;
972 break;
973 default:
974 slot_cmd = PCI_SPEED_UNKNOWN;
975 retval = -ENODEV;
976 return retval;
977 }
978 } else {
979 switch (value) {
980 case 0:
981 slot_cmd = SETB_PCI_33MHZ;
982 break;
983 case 1:
984 slot_cmd = SETB_PCI_66MHZ;
985 break;
986 case 2:
987 slot_cmd = SETB_PCIX_66MHZ_PM;
988 break;
989 case 3:
990 slot_cmd = SETB_PCIX_100MHZ_PM;
991 break;
992 case 4:
993 slot_cmd = SETB_PCIX_133MHZ_PM;
994 break;
995 case 5:
996 slot_cmd = SETB_PCIX_66MHZ_EM;
997 break;
998 case 6:
999 slot_cmd = SETB_PCIX_100MHZ_EM;
1000 break;
1001 case 7:
1002 slot_cmd = SETB_PCIX_133MHZ_EM;
1003 break;
1004 case 8:
1005 slot_cmd = SETB_PCIX_66MHZ_266;
1006 break;
1007 case 0x9:
1008 slot_cmd = SETB_PCIX_100MHZ_266;
1009 break;
1010 case 0xa:
1011 slot_cmd = SETB_PCIX_133MHZ_266;
1012 break;
1013 case 0xb:
1014 slot_cmd = SETB_PCIX_66MHZ_533;
1015 break;
1016 case 0xc:
1017 slot_cmd = SETB_PCIX_100MHZ_533;
1018 break;
1019 case 0xd:
1020 slot_cmd = SETB_PCIX_133MHZ_533;
1021 break;
1022 default:
1023 slot_cmd = PCI_SPEED_UNKNOWN;
1024 retval = -ENODEV;
1025 return retval;
1026 }
1027 912
913 switch (value) {
914 case PCI_SPEED_33MHz:
915 cmd = SETA_PCI_33MHZ;
916 break;
917 case PCI_SPEED_66MHz:
918 cmd = SETA_PCI_66MHZ;
919 break;
920 case PCI_SPEED_66MHz_PCIX:
921 cmd = SETA_PCIX_66MHZ;
922 break;
923 case PCI_SPEED_100MHz_PCIX:
924 cmd = SETA_PCIX_100MHZ;
925 break;
926 case PCI_SPEED_133MHz_PCIX:
927 cmd = SETA_PCIX_133MHZ;
928 break;
929 case PCI_SPEED_66MHz_PCIX_ECC:
930 cmd = SETB_PCIX_66MHZ_EM;
931 break;
932 case PCI_SPEED_100MHz_PCIX_ECC:
933 cmd = SETB_PCIX_100MHZ_EM;
934 break;
935 case PCI_SPEED_133MHz_PCIX_ECC:
936 cmd = SETB_PCIX_133MHZ_EM;
937 break;
938 case PCI_SPEED_66MHz_PCIX_266:
939 cmd = SETB_PCIX_66MHZ_266;
940 break;
941 case PCI_SPEED_100MHz_PCIX_266:
942 cmd = SETB_PCIX_100MHZ_266;
943 break;
944 case PCI_SPEED_133MHz_PCIX_266:
945 cmd = SETB_PCIX_133MHZ_266;
946 break;
947 case PCI_SPEED_66MHz_PCIX_533:
948 cmd = SETB_PCIX_66MHZ_533;
949 break;
950 case PCI_SPEED_100MHz_PCIX_533:
951 cmd = SETB_PCIX_100MHZ_533;
952 break;
953 case PCI_SPEED_133MHz_PCIX_533:
954 cmd = SETB_PCIX_133MHZ_533;
955 break;
956 default:
957 return -EINVAL;
1028 } 958 }
1029 retval = shpc_write_cmd(slot, 0, slot_cmd); 959
1030 if (retval) { 960 retval = shpc_write_cmd(slot, 0, cmd);
961 if (retval)
1031 err("%s: Write command failed!\n", __FUNCTION__); 962 err("%s: Write command failed!\n", __FUNCTION__);
1032 return -1;
1033 }
1034 963
1035 DBG_LEAVE_ROUTINE 964 DBG_LEAVE_ROUTINE
1036 return retval; 965 return retval;
@@ -1093,14 +1022,8 @@ static irqreturn_t shpc_isr(int IRQ, void *dev_id, struct pt_regs *regs)
1093 wake_up_interruptible(&ctrl->queue); 1022 wake_up_interruptible(&ctrl->queue);
1094 } 1023 }
1095 1024
1096 if ((intr_loc = (intr_loc >> 1)) == 0) { 1025 if ((intr_loc = (intr_loc >> 1)) == 0)
1097 /* Unmask Global Interrupt Mask */ 1026 goto out;
1098 temp_dword = readl(php_ctlr->creg + SERR_INTR_ENABLE);
1099 temp_dword &= 0xfffffffe;
1100 writel(temp_dword, php_ctlr->creg + SERR_INTR_ENABLE);
1101
1102 return IRQ_NONE;
1103 }
1104 1027
1105 for (hp_slot = 0; hp_slot < ctrl->num_slots; hp_slot++) { 1028 for (hp_slot = 0; hp_slot < ctrl->num_slots; hp_slot++) {
1106 /* To find out which slot has interrupt pending */ 1029 /* To find out which slot has interrupt pending */
@@ -1130,6 +1053,7 @@ static irqreturn_t shpc_isr(int IRQ, void *dev_id, struct pt_regs *regs)
1130 dbg("%s: intr_loc2 = %x\n",__FUNCTION__, intr_loc2); 1053 dbg("%s: intr_loc2 = %x\n",__FUNCTION__, intr_loc2);
1131 } 1054 }
1132 } 1055 }
1056 out:
1133 if (!shpchp_poll_mode) { 1057 if (!shpchp_poll_mode) {
1134 /* Unmask Global Interrupt Mask */ 1058 /* Unmask Global Interrupt Mask */
1135 temp_dword = readl(php_ctlr->creg + SERR_INTR_ENABLE); 1059 temp_dword = readl(php_ctlr->creg + SERR_INTR_ENABLE);
@@ -1142,64 +1066,43 @@ static irqreturn_t shpc_isr(int IRQ, void *dev_id, struct pt_regs *regs)
1142 1066
1143static int hpc_get_max_bus_speed (struct slot *slot, enum pci_bus_speed *value) 1067static int hpc_get_max_bus_speed (struct slot *slot, enum pci_bus_speed *value)
1144{ 1068{
1069 int retval = 0;
1145 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle; 1070 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
1146 enum pci_bus_speed bus_speed = PCI_SPEED_UNKNOWN; 1071 enum pci_bus_speed bus_speed = PCI_SPEED_UNKNOWN;
1147 int retval = 0; 1072 u8 pi = readb(php_ctlr->creg + PROG_INTERFACE);
1148 u8 pi; 1073 u32 slot_avail1 = readl(php_ctlr->creg + SLOT_AVAIL1);
1149 u32 slot_avail1, slot_avail2; 1074 u32 slot_avail2 = readl(php_ctlr->creg + SLOT_AVAIL2);
1150 1075
1151 DBG_ENTER_ROUTINE 1076 DBG_ENTER_ROUTINE
1152 1077
1153 if (!slot->ctrl->hpc_ctlr_handle) {
1154 err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
1155 return -1;
1156 }
1157
1158 if (slot->hp_slot >= php_ctlr->num_slots) {
1159 err("%s: Invalid HPC slot number!\n", __FUNCTION__);
1160 return -1;
1161 }
1162
1163 pi = readb(php_ctlr->creg + PROG_INTERFACE);
1164 slot_avail1 = readl(php_ctlr->creg + SLOT_AVAIL1);
1165 slot_avail2 = readl(php_ctlr->creg + SLOT_AVAIL2);
1166
1167 if (pi == 2) { 1078 if (pi == 2) {
1168 if (slot_avail2 & SLOT_133MHZ_PCIX_533) 1079 if (slot_avail2 & SLOT_133MHZ_PCIX_533)
1169 bus_speed = PCIX_133MHZ_533; 1080 bus_speed = PCI_SPEED_133MHz_PCIX_533;
1170 else if (slot_avail2 & SLOT_100MHZ_PCIX_533) 1081 else if (slot_avail2 & SLOT_100MHZ_PCIX_533)
1171 bus_speed = PCIX_100MHZ_533; 1082 bus_speed = PCI_SPEED_100MHz_PCIX_533;
1172 else if (slot_avail2 & SLOT_66MHZ_PCIX_533) 1083 else if (slot_avail2 & SLOT_66MHZ_PCIX_533)
1173 bus_speed = PCIX_66MHZ_533; 1084 bus_speed = PCI_SPEED_66MHz_PCIX_533;
1174 else if (slot_avail2 & SLOT_133MHZ_PCIX_266) 1085 else if (slot_avail2 & SLOT_133MHZ_PCIX_266)
1175 bus_speed = PCIX_133MHZ_266; 1086 bus_speed = PCI_SPEED_133MHz_PCIX_266;
1176 else if (slot_avail2 & SLOT_100MHZ_PCIX_266) 1087 else if (slot_avail2 & SLOT_100MHZ_PCIX_266)
1177 bus_speed = PCIX_100MHZ_266; 1088 bus_speed = PCI_SPEED_100MHz_PCIX_266;
1178 else if (slot_avail2 & SLOT_66MHZ_PCIX_266) 1089 else if (slot_avail2 & SLOT_66MHZ_PCIX_266)
1179 bus_speed = PCIX_66MHZ_266; 1090 bus_speed = PCI_SPEED_66MHz_PCIX_266;
1180 else if (slot_avail1 & SLOT_133MHZ_PCIX) 1091 }
1181 bus_speed = PCIX_133MHZ; 1092
1182 else if (slot_avail1 & SLOT_100MHZ_PCIX) 1093 if (bus_speed == PCI_SPEED_UNKNOWN) {
1183 bus_speed = PCIX_100MHZ;
1184 else if (slot_avail1 & SLOT_66MHZ_PCIX)
1185 bus_speed = PCIX_66MHZ;
1186 else if (slot_avail2 & SLOT_66MHZ)
1187 bus_speed = PCI_66MHZ;
1188 else if (slot_avail1 & SLOT_33MHZ)
1189 bus_speed = PCI_33MHZ;
1190 else bus_speed = PCI_SPEED_UNKNOWN;
1191 } else {
1192 if (slot_avail1 & SLOT_133MHZ_PCIX) 1094 if (slot_avail1 & SLOT_133MHZ_PCIX)
1193 bus_speed = PCIX_133MHZ; 1095 bus_speed = PCI_SPEED_133MHz_PCIX;
1194 else if (slot_avail1 & SLOT_100MHZ_PCIX) 1096 else if (slot_avail1 & SLOT_100MHZ_PCIX)
1195 bus_speed = PCIX_100MHZ; 1097 bus_speed = PCI_SPEED_100MHz_PCIX;
1196 else if (slot_avail1 & SLOT_66MHZ_PCIX) 1098 else if (slot_avail1 & SLOT_66MHZ_PCIX)
1197 bus_speed = PCIX_66MHZ; 1099 bus_speed = PCI_SPEED_66MHz_PCIX;
1198 else if (slot_avail2 & SLOT_66MHZ) 1100 else if (slot_avail2 & SLOT_66MHZ)
1199 bus_speed = PCI_66MHZ; 1101 bus_speed = PCI_SPEED_66MHz;
1200 else if (slot_avail1 & SLOT_33MHZ) 1102 else if (slot_avail1 & SLOT_33MHZ)
1201 bus_speed = PCI_33MHZ; 1103 bus_speed = PCI_SPEED_33MHz;
1202 else bus_speed = PCI_SPEED_UNKNOWN; 1104 else
1105 retval = -ENODEV;
1203 } 1106 }
1204 1107
1205 *value = bus_speed; 1108 *value = bus_speed;
@@ -1210,111 +1113,69 @@ static int hpc_get_max_bus_speed (struct slot *slot, enum pci_bus_speed *value)
1210 1113
1211static int hpc_get_cur_bus_speed (struct slot *slot, enum pci_bus_speed *value) 1114static int hpc_get_cur_bus_speed (struct slot *slot, enum pci_bus_speed *value)
1212{ 1115{
1116 int retval = 0;
1213 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle; 1117 struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
1214 enum pci_bus_speed bus_speed = PCI_SPEED_UNKNOWN; 1118 enum pci_bus_speed bus_speed = PCI_SPEED_UNKNOWN;
1215 u16 sec_bus_status; 1119 u16 sec_bus_reg = readw(php_ctlr->creg + SEC_BUS_CONFIG);
1216 int retval = 0; 1120 u8 pi = readb(php_ctlr->creg + PROG_INTERFACE);
1217 u8 pi; 1121 u8 speed_mode = (pi == 2) ? (sec_bus_reg & 0xF) : (sec_bus_reg & 0x7);
1218 1122
1219 DBG_ENTER_ROUTINE 1123 DBG_ENTER_ROUTINE
1220 1124
1221 if (!slot->ctrl->hpc_ctlr_handle) { 1125 if ((pi == 1) && (speed_mode > 4)) {
1222 err("%s: Invalid HPC controller handle!\n", __FUNCTION__); 1126 *value = PCI_SPEED_UNKNOWN;
1223 return -1; 1127 return -ENODEV;
1224 }
1225
1226 if (slot->hp_slot >= php_ctlr->num_slots) {
1227 err("%s: Invalid HPC slot number!\n", __FUNCTION__);
1228 return -1;
1229 } 1128 }
1230 1129
1231 pi = readb(php_ctlr->creg + PROG_INTERFACE); 1130 switch (speed_mode) {
1232 sec_bus_status = readw(php_ctlr->creg + SEC_BUS_CONFIG); 1131 case 0x0:
1233 1132 *value = PCI_SPEED_33MHz;
1234 if (pi == 2) { 1133 break;
1235 switch (sec_bus_status & 0x000f) { 1134 case 0x1:
1236 case 0: 1135 *value = PCI_SPEED_66MHz;
1237 bus_speed = PCI_SPEED_33MHz; 1136 break;
1238 break; 1137 case 0x2:
1239 case 1: 1138 *value = PCI_SPEED_66MHz_PCIX;
1240 bus_speed = PCI_SPEED_66MHz; 1139 break;
1241 break; 1140 case 0x3:
1242 case 2: 1141 *value = PCI_SPEED_100MHz_PCIX;
1243 bus_speed = PCI_SPEED_66MHz_PCIX; 1142 break;
1244 break; 1143 case 0x4:
1245 case 3: 1144 *value = PCI_SPEED_133MHz_PCIX;
1246 bus_speed = PCI_SPEED_100MHz_PCIX; 1145 break;
1247 break; 1146 case 0x5:
1248 case 4: 1147 *value = PCI_SPEED_66MHz_PCIX_ECC;
1249 bus_speed = PCI_SPEED_133MHz_PCIX; 1148 break;
1250 break; 1149 case 0x6:
1251 case 5: 1150 *value = PCI_SPEED_100MHz_PCIX_ECC;
1252 bus_speed = PCI_SPEED_66MHz_PCIX_ECC; 1151 break;
1253 break; 1152 case 0x7:
1254 case 6: 1153 *value = PCI_SPEED_133MHz_PCIX_ECC;
1255 bus_speed = PCI_SPEED_100MHz_PCIX_ECC; 1154 break;
1256 break; 1155 case 0x8:
1257 case 7: 1156 *value = PCI_SPEED_66MHz_PCIX_266;
1258 bus_speed = PCI_SPEED_133MHz_PCIX_ECC; 1157 break;
1259 break; 1158 case 0x9:
1260 case 8: 1159 *value = PCI_SPEED_100MHz_PCIX_266;
1261 bus_speed = PCI_SPEED_66MHz_PCIX_266; 1160 break;
1262 break; 1161 case 0xa:
1263 case 9: 1162 *value = PCI_SPEED_133MHz_PCIX_266;
1264 bus_speed = PCI_SPEED_100MHz_PCIX_266; 1163 break;
1265 break; 1164 case 0xb:
1266 case 0xa: 1165 *value = PCI_SPEED_66MHz_PCIX_533;
1267 bus_speed = PCI_SPEED_133MHz_PCIX_266; 1166 break;
1268 break; 1167 case 0xc:
1269 case 0xb: 1168 *value = PCI_SPEED_100MHz_PCIX_533;
1270 bus_speed = PCI_SPEED_66MHz_PCIX_533; 1169 break;
1271 break; 1170 case 0xd:
1272 case 0xc: 1171 *value = PCI_SPEED_133MHz_PCIX_533;
1273 bus_speed = PCI_SPEED_100MHz_PCIX_533; 1172 break;
1274 break; 1173 default:
1275 case 0xd: 1174 *value = PCI_SPEED_UNKNOWN;
1276 bus_speed = PCI_SPEED_133MHz_PCIX_533; 1175 retval = -ENODEV;
1277 break; 1176 break;
1278 case 0xe:
1279 case 0xf:
1280 default:
1281 bus_speed = PCI_SPEED_UNKNOWN;
1282 break;
1283 }
1284 } else {
1285 /* In the case where pi is undefined, default it to 1 */
1286 switch (sec_bus_status & 0x0007) {
1287 case 0:
1288 bus_speed = PCI_SPEED_33MHz;
1289 break;
1290 case 1:
1291 bus_speed = PCI_SPEED_66MHz;
1292 break;
1293 case 2:
1294 bus_speed = PCI_SPEED_66MHz_PCIX;
1295 break;
1296 case 3:
1297 bus_speed = PCI_SPEED_100MHz_PCIX;
1298 break;
1299 case 4:
1300 bus_speed = PCI_SPEED_133MHz_PCIX;
1301 break;
1302 case 5:
1303 bus_speed = PCI_SPEED_UNKNOWN; /* Reserved */
1304 break;
1305 case 6:
1306 bus_speed = PCI_SPEED_UNKNOWN; /* Reserved */
1307 break;
1308 case 7:
1309 bus_speed = PCI_SPEED_UNKNOWN; /* Reserved */
1310 break;
1311 default:
1312 bus_speed = PCI_SPEED_UNKNOWN;
1313 break;
1314 }
1315 } 1177 }
1316 1178
1317 *value = bus_speed;
1318 dbg("Current bus speed = %d\n", bus_speed); 1179 dbg("Current bus speed = %d\n", bus_speed);
1319 DBG_LEAVE_ROUTINE 1180 DBG_LEAVE_ROUTINE
1320 return retval; 1181 return retval;
@@ -1343,7 +1204,6 @@ static struct hpc_ops shpchp_hpc_ops = {
1343 .green_led_blink = hpc_set_green_led_blink, 1204 .green_led_blink = hpc_set_green_led_blink,
1344 1205
1345 .release_ctlr = hpc_release_ctlr, 1206 .release_ctlr = hpc_release_ctlr,
1346 .check_cmd_status = hpc_check_cmd_status,
1347}; 1207};
1348 1208
1349inline static int shpc_indirect_creg_read(struct controller *ctrl, int index, 1209inline static int shpc_indirect_creg_read(struct controller *ctrl, int index,
@@ -1375,15 +1235,13 @@ int shpc_init(struct controller * ctrl, struct pci_dev * pdev)
1375 ctrl->pci_dev = pdev; /* pci_dev of the P2P bridge */ 1235 ctrl->pci_dev = pdev; /* pci_dev of the P2P bridge */
1376 1236
1377 spin_lock_init(&list_lock); 1237 spin_lock_init(&list_lock);
1378 php_ctlr = (struct php_ctlr_state_s *) kmalloc(sizeof(struct php_ctlr_state_s), GFP_KERNEL); 1238 php_ctlr = kzalloc(sizeof(*php_ctlr), GFP_KERNEL);
1379 1239
1380 if (!php_ctlr) { /* allocate controller state data */ 1240 if (!php_ctlr) { /* allocate controller state data */
1381 err("%s: HPC controller memory allocation error!\n", __FUNCTION__); 1241 err("%s: HPC controller memory allocation error!\n", __FUNCTION__);
1382 goto abort; 1242 goto abort;
1383 } 1243 }
1384 1244
1385 memset(php_ctlr, 0, sizeof(struct php_ctlr_state_s));
1386
1387 php_ctlr->pci_dev = pdev; /* save pci_dev in context */ 1245 php_ctlr->pci_dev = pdev; /* save pci_dev in context */
1388 1246
1389 if ((pdev->vendor == PCI_VENDOR_ID_AMD) || (pdev->device == 1247 if ((pdev->vendor == PCI_VENDOR_ID_AMD) || (pdev->device ==
@@ -1454,7 +1312,9 @@ int shpc_init(struct controller * ctrl, struct pci_dev * pdev)
1454 } 1312 }
1455 dbg("%s: php_ctlr->creg %p\n", __FUNCTION__, php_ctlr->creg); 1313 dbg("%s: php_ctlr->creg %p\n", __FUNCTION__, php_ctlr->creg);
1456 1314
1457 init_MUTEX(&ctrl->crit_sect); 1315 mutex_init(&ctrl->crit_sect);
1316 mutex_init(&ctrl->cmd_lock);
1317
1458 /* Setup wait queue */ 1318 /* Setup wait queue */
1459 init_waitqueue_head(&ctrl->queue); 1319 init_waitqueue_head(&ctrl->queue);
1460 1320
diff --git a/drivers/pci/hotplug/shpchp_pci.c b/drivers/pci/hotplug/shpchp_pci.c
index 19e1a5e1e3..257adc2339 100644
--- a/drivers/pci/hotplug/shpchp_pci.c
+++ b/drivers/pci/hotplug/shpchp_pci.c
@@ -38,7 +38,7 @@ static void program_fw_provided_values(struct pci_dev *dev)
38{ 38{
39 u16 pci_cmd, pci_bctl; 39 u16 pci_cmd, pci_bctl;
40 struct pci_dev *cdev; 40 struct pci_dev *cdev;
41 struct hotplug_params hpp = {0x8, 0x40, 0, 0}; /* defaults */ 41 struct hotplug_params hpp;
42 42
43 /* Program hpp values for this device */ 43 /* Program hpp values for this device */
44 if (!(dev->hdr_type == PCI_HEADER_TYPE_NORMAL || 44 if (!(dev->hdr_type == PCI_HEADER_TYPE_NORMAL ||
@@ -46,7 +46,13 @@ static void program_fw_provided_values(struct pci_dev *dev)
46 (dev->class >> 8) == PCI_CLASS_BRIDGE_PCI))) 46 (dev->class >> 8) == PCI_CLASS_BRIDGE_PCI)))
47 return; 47 return;
48 48
49 get_hp_params_from_firmware(dev, &hpp); 49 /* use default values if we can't get them from firmware */
50 if (get_hp_params_from_firmware(dev, &hpp)) {
51 hpp.cache_line_size = 8;
52 hpp.latency_timer = 0x40;
53 hpp.enable_serr = 0;
54 hpp.enable_perr = 0;
55 }
50 56
51 pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, hpp.cache_line_size); 57 pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, hpp.cache_line_size);
52 pci_write_config_byte(dev, PCI_LATENCY_TIMER, hpp.latency_timer); 58 pci_write_config_byte(dev, PCI_LATENCY_TIMER, hpp.latency_timer);
diff --git a/drivers/pci/hotplug/shpchprm_legacy.c b/drivers/pci/hotplug/shpchprm_legacy.c
deleted file mode 100644
index ed6c1254bf..0000000000
--- a/drivers/pci/hotplug/shpchprm_legacy.c
+++ /dev/null
@@ -1,54 +0,0 @@
1/*
2 * SHPCHPRM Legacy: PHP Resource Manager for Non-ACPI/Legacy platform
3 *
4 * Copyright (C) 1995,2001 Compaq Computer Corporation
5 * Copyright (C) 2001 Greg Kroah-Hartman (greg@kroah.com)
6 * Copyright (C) 2001 IBM Corp.
7 * Copyright (C) 2003-2004 Intel Corporation
8 *
9 * All rights reserved.
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or (at
14 * your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
19 * NON INFRINGEMENT. See the GNU General Public License for more
20 * details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 *
26 * Send feedback to <greg@kroah.com>,<kristen.c.accardi@intel.com>
27 *
28 */
29
30#include <linux/module.h>
31#include <linux/kernel.h>
32#include <linux/types.h>
33#include <linux/pci.h>
34#include "shpchp.h"
35
36int shpchprm_get_physical_slot_number(struct controller *ctrl, u32 *sun, u8 busnum, u8 devnum)
37{
38 int offset = devnum - ctrl->slot_device_offset;
39
40 *sun = (u8) (ctrl->first_slot + ctrl->slot_num_inc * offset);
41 return 0;
42}
43
44void get_hp_params_from_firmware(struct pci_dev *dev,
45 struct hotplug_params *hpp)
46{
47 return;
48}
49
50void get_hp_hw_control_from_firmware(struct pci_dev *dev)
51{
52 return;
53}
54
diff --git a/drivers/pci/hotplug/shpchprm_nonacpi.c b/drivers/pci/hotplug/shpchprm_nonacpi.c
deleted file mode 100644
index c6b40998ee..0000000000
--- a/drivers/pci/hotplug/shpchprm_nonacpi.c
+++ /dev/null
@@ -1,57 +0,0 @@
1/*
2 * SHPCHPRM NONACPI: PHP Resource Manager for Non-ACPI/Legacy platform
3 *
4 * Copyright (C) 1995,2001 Compaq Computer Corporation
5 * Copyright (C) 2001 Greg Kroah-Hartman (greg@kroah.com)
6 * Copyright (C) 2001 IBM Corp.
7 * Copyright (C) 2003-2004 Intel Corporation
8 *
9 * All rights reserved.
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or (at
14 * your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
19 * NON INFRINGEMENT. See the GNU General Public License for more
20 * details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 *
26 * Send feedback to <greg@kroah.com>, <kristen.c.accardi@intel.com>
27 *
28 */
29
30#include <linux/config.h>
31#include <linux/module.h>
32#include <linux/kernel.h>
33#include <linux/types.h>
34#include <linux/pci.h>
35#include <linux/slab.h>
36
37#include "shpchp.h"
38
39int shpchprm_get_physical_slot_number(struct controller *ctrl, u32 *sun, u8 busnum, u8 devnum)
40{
41 int offset = devnum - ctrl->slot_device_offset;
42
43 dbg("%s: ctrl->slot_num_inc %d, offset %d\n", __FUNCTION__, ctrl->slot_num_inc, offset);
44 *sun = (u8) (ctrl->first_slot + ctrl->slot_num_inc * offset);
45 return 0;
46}
47
48void get_hp_params_from_firmware(struct pci_dev *dev,
49 struct hotplug_params *hpp)
50{
51 return;
52}
53
54void get_hp_hw_control_from_firmware(struct pci_dev *dev)
55{
56 return;
57}
diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
index 48723d6fa6..a77e79c8c8 100644
--- a/drivers/pci/msi.c
+++ b/drivers/pci/msi.c
@@ -103,9 +103,9 @@ static void set_msi_affinity(unsigned int vector, cpumask_t cpu_mask)
103 switch (entry->msi_attrib.type) { 103 switch (entry->msi_attrib.type) {
104 case PCI_CAP_ID_MSI: 104 case PCI_CAP_ID_MSI:
105 { 105 {
106 int pos; 106 int pos = pci_find_capability(entry->dev, PCI_CAP_ID_MSI);
107 107
108 if (!(pos = pci_find_capability(entry->dev, PCI_CAP_ID_MSI))) 108 if (!pos)
109 return; 109 return;
110 110
111 pci_read_config_dword(entry->dev, msi_lower_address_reg(pos), 111 pci_read_config_dword(entry->dev, msi_lower_address_reg(pos),
@@ -347,9 +347,9 @@ static int assign_msi_vector(void)
347 347
348static int get_new_vector(void) 348static int get_new_vector(void)
349{ 349{
350 int vector; 350 int vector = assign_msi_vector();
351 351
352 if ((vector = assign_msi_vector()) > 0) 352 if (vector > 0)
353 set_intr_gate(vector, interrupt[vector]); 353 set_intr_gate(vector, interrupt[vector]);
354 354
355 return vector; 355 return vector;
@@ -369,7 +369,8 @@ static int msi_init(void)
369 return status; 369 return status;
370 } 370 }
371 371
372 if ((status = msi_cache_init()) < 0) { 372 status = msi_cache_init();
373 if (status < 0) {
373 pci_msi_enable = 0; 374 pci_msi_enable = 0;
374 printk(KERN_WARNING "PCI: MSI cache init failed\n"); 375 printk(KERN_WARNING "PCI: MSI cache init failed\n");
375 return status; 376 return status;
@@ -523,10 +524,12 @@ static int msi_capability_init(struct pci_dev *dev)
523 pos = pci_find_capability(dev, PCI_CAP_ID_MSI); 524 pos = pci_find_capability(dev, PCI_CAP_ID_MSI);
524 pci_read_config_word(dev, msi_control_reg(pos), &control); 525 pci_read_config_word(dev, msi_control_reg(pos), &control);
525 /* MSI Entry Initialization */ 526 /* MSI Entry Initialization */
526 if (!(entry = alloc_msi_entry())) 527 entry = alloc_msi_entry();
528 if (!entry)
527 return -ENOMEM; 529 return -ENOMEM;
528 530
529 if ((vector = get_msi_vector(dev)) < 0) { 531 vector = get_msi_vector(dev);
532 if (vector < 0) {
530 kmem_cache_free(msi_cachep, entry); 533 kmem_cache_free(msi_cachep, entry);
531 return -EBUSY; 534 return -EBUSY;
532 } 535 }
@@ -597,7 +600,8 @@ static int msix_capability_init(struct pci_dev *dev,
597 struct msg_address address; 600 struct msg_address address;
598 struct msg_data data; 601 struct msg_data data;
599 int vector, pos, i, j, nr_entries, temp = 0; 602 int vector, pos, i, j, nr_entries, temp = 0;
600 u32 phys_addr, table_offset; 603 unsigned long phys_addr;
604 u32 table_offset;
601 u16 control; 605 u16 control;
602 u8 bir; 606 u8 bir;
603 void __iomem *base; 607 void __iomem *base;
@@ -606,11 +610,11 @@ static int msix_capability_init(struct pci_dev *dev,
606 /* Request & Map MSI-X table region */ 610 /* Request & Map MSI-X table region */
607 pci_read_config_word(dev, msi_control_reg(pos), &control); 611 pci_read_config_word(dev, msi_control_reg(pos), &control);
608 nr_entries = multi_msix_capable(control); 612 nr_entries = multi_msix_capable(control);
609 pci_read_config_dword(dev, msix_table_offset_reg(pos), 613
610 &table_offset); 614 pci_read_config_dword(dev, msix_table_offset_reg(pos), &table_offset);
611 bir = (u8)(table_offset & PCI_MSIX_FLAGS_BIRMASK); 615 bir = (u8)(table_offset & PCI_MSIX_FLAGS_BIRMASK);
612 phys_addr = pci_resource_start (dev, bir); 616 table_offset &= ~PCI_MSIX_FLAGS_BIRMASK;
613 phys_addr += (u32)(table_offset & ~PCI_MSIX_FLAGS_BIRMASK); 617 phys_addr = pci_resource_start (dev, bir) + table_offset;
614 base = ioremap_nocache(phys_addr, nr_entries * PCI_MSIX_ENTRY_SIZE); 618 base = ioremap_nocache(phys_addr, nr_entries * PCI_MSIX_ENTRY_SIZE);
615 if (base == NULL) 619 if (base == NULL)
616 return -ENOMEM; 620 return -ENOMEM;
@@ -620,7 +624,8 @@ static int msix_capability_init(struct pci_dev *dev,
620 entry = alloc_msi_entry(); 624 entry = alloc_msi_entry();
621 if (!entry) 625 if (!entry)
622 break; 626 break;
623 if ((vector = get_msi_vector(dev)) < 0) 627 vector = get_msi_vector(dev);
628 if (vector < 0)
624 break; 629 break;
625 630
626 j = entries[i].entry; 631 j = entries[i].entry;
@@ -699,12 +704,17 @@ int pci_enable_msi(struct pci_dev* dev)
699 if (dev->no_msi) 704 if (dev->no_msi)
700 return status; 705 return status;
701 706
707 if (dev->bus->bus_flags & PCI_BUS_FLAGS_NO_MSI)
708 return -EINVAL;
709
702 temp = dev->irq; 710 temp = dev->irq;
703 711
704 if ((status = msi_init()) < 0) 712 status = msi_init();
713 if (status < 0)
705 return status; 714 return status;
706 715
707 if (!(pos = pci_find_capability(dev, PCI_CAP_ID_MSI))) 716 pos = pci_find_capability(dev, PCI_CAP_ID_MSI);
717 if (!pos)
708 return -EINVAL; 718 return -EINVAL;
709 719
710 pci_read_config_word(dev, msi_control_reg(pos), &control); 720 pci_read_config_word(dev, msi_control_reg(pos), &control);
@@ -728,8 +738,8 @@ int pci_enable_msi(struct pci_dev* dev)
728 dev->irq = temp; 738 dev->irq = temp;
729 } 739 }
730 /* Check whether driver already requested for MSI-X vectors */ 740 /* Check whether driver already requested for MSI-X vectors */
731 if ((pos = pci_find_capability(dev, PCI_CAP_ID_MSIX)) > 0 && 741 pos = pci_find_capability(dev, PCI_CAP_ID_MSIX);
732 !msi_lookup_vector(dev, PCI_CAP_ID_MSIX)) { 742 if (pos > 0 && !msi_lookup_vector(dev, PCI_CAP_ID_MSIX)) {
733 printk(KERN_INFO "PCI: %s: Can't enable MSI. " 743 printk(KERN_INFO "PCI: %s: Can't enable MSI. "
734 "Device already has MSI-X vectors assigned\n", 744 "Device already has MSI-X vectors assigned\n",
735 pci_name(dev)); 745 pci_name(dev));
@@ -755,7 +765,13 @@ void pci_disable_msi(struct pci_dev* dev)
755 u16 control; 765 u16 control;
756 unsigned long flags; 766 unsigned long flags;
757 767
758 if (!dev || !(pos = pci_find_capability(dev, PCI_CAP_ID_MSI))) 768 if (!pci_msi_enable)
769 return;
770 if (!dev)
771 return;
772
773 pos = pci_find_capability(dev, PCI_CAP_ID_MSI);
774 if (!pos)
759 return; 775 return;
760 776
761 pci_read_config_word(dev, msi_control_reg(pos), &control); 777 pci_read_config_word(dev, msi_control_reg(pos), &control);
@@ -826,8 +842,10 @@ static int msi_free_vector(struct pci_dev* dev, int vector, int reassign)
826 * Detect last MSI-X vector to be released. 842 * Detect last MSI-X vector to be released.
827 * Release the MSI-X memory-mapped table. 843 * Release the MSI-X memory-mapped table.
828 */ 844 */
845#if 0
829 int pos, nr_entries; 846 int pos, nr_entries;
830 u32 phys_addr, table_offset; 847 unsigned long phys_addr;
848 u32 table_offset;
831 u16 control; 849 u16 control;
832 u8 bir; 850 u8 bir;
833 851
@@ -838,9 +856,12 @@ static int msi_free_vector(struct pci_dev* dev, int vector, int reassign)
838 pci_read_config_dword(dev, msix_table_offset_reg(pos), 856 pci_read_config_dword(dev, msix_table_offset_reg(pos),
839 &table_offset); 857 &table_offset);
840 bir = (u8)(table_offset & PCI_MSIX_FLAGS_BIRMASK); 858 bir = (u8)(table_offset & PCI_MSIX_FLAGS_BIRMASK);
841 phys_addr = pci_resource_start (dev, bir); 859 table_offset &= ~PCI_MSIX_FLAGS_BIRMASK;
842 phys_addr += (u32)(table_offset & 860 phys_addr = pci_resource_start(dev, bir) + table_offset;
843 ~PCI_MSIX_FLAGS_BIRMASK); 861/*
862 * FIXME! and what did you want to do with phys_addr?
863 */
864#endif
844 iounmap(base); 865 iounmap(base);
845 } 866 }
846 } 867 }
@@ -924,10 +945,12 @@ int pci_enable_msix(struct pci_dev* dev, struct msix_entry *entries, int nvec)
924 if (!pci_msi_enable || !dev || !entries) 945 if (!pci_msi_enable || !dev || !entries)
925 return -EINVAL; 946 return -EINVAL;
926 947
927 if ((status = msi_init()) < 0) 948 status = msi_init();
949 if (status < 0)
928 return status; 950 return status;
929 951
930 if (!(pos = pci_find_capability(dev, PCI_CAP_ID_MSIX))) 952 pos = pci_find_capability(dev, PCI_CAP_ID_MSIX);
953 if (!pos)
931 return -EINVAL; 954 return -EINVAL;
932 955
933 pci_read_config_word(dev, msi_control_reg(pos), &control); 956 pci_read_config_word(dev, msi_control_reg(pos), &control);
@@ -1006,7 +1029,13 @@ void pci_disable_msix(struct pci_dev* dev)
1006 int pos, temp; 1029 int pos, temp;
1007 u16 control; 1030 u16 control;
1008 1031
1009 if (!dev || !(pos = pci_find_capability(dev, PCI_CAP_ID_MSIX))) 1032 if (!pci_msi_enable)
1033 return;
1034 if (!dev)
1035 return;
1036
1037 pos = pci_find_capability(dev, PCI_CAP_ID_MSIX);
1038 if (!pos)
1010 return; 1039 return;
1011 1040
1012 pci_read_config_word(dev, msi_control_reg(pos), &control); 1041 pci_read_config_word(dev, msi_control_reg(pos), &control);
@@ -1066,8 +1095,8 @@ void msi_remove_pci_irq_vectors(struct pci_dev* dev)
1066 return; 1095 return;
1067 1096
1068 temp = dev->irq; /* Save IOAPIC IRQ */ 1097 temp = dev->irq; /* Save IOAPIC IRQ */
1069 if ((pos = pci_find_capability(dev, PCI_CAP_ID_MSI)) > 0 && 1098 pos = pci_find_capability(dev, PCI_CAP_ID_MSI);
1070 !msi_lookup_vector(dev, PCI_CAP_ID_MSI)) { 1099 if (pos > 0 && !msi_lookup_vector(dev, PCI_CAP_ID_MSI)) {
1071 spin_lock_irqsave(&msi_lock, flags); 1100 spin_lock_irqsave(&msi_lock, flags);
1072 state = msi_desc[dev->irq]->msi_attrib.state; 1101 state = msi_desc[dev->irq]->msi_attrib.state;
1073 spin_unlock_irqrestore(&msi_lock, flags); 1102 spin_unlock_irqrestore(&msi_lock, flags);
@@ -1080,8 +1109,8 @@ void msi_remove_pci_irq_vectors(struct pci_dev* dev)
1080 msi_free_vector(dev, dev->irq, 0); 1109 msi_free_vector(dev, dev->irq, 0);
1081 dev->irq = temp; /* Restore IOAPIC IRQ */ 1110 dev->irq = temp; /* Restore IOAPIC IRQ */
1082 } 1111 }
1083 if ((pos = pci_find_capability(dev, PCI_CAP_ID_MSIX)) > 0 && 1112 pos = pci_find_capability(dev, PCI_CAP_ID_MSIX);
1084 !msi_lookup_vector(dev, PCI_CAP_ID_MSIX)) { 1113 if (pos > 0 && !msi_lookup_vector(dev, PCI_CAP_ID_MSIX)) {
1085 int vector, head, tail = 0, warning = 0; 1114 int vector, head, tail = 0, warning = 0;
1086 void __iomem *base = NULL; 1115 void __iomem *base = NULL;
1087 1116
@@ -1101,7 +1130,9 @@ void msi_remove_pci_irq_vectors(struct pci_dev* dev)
1101 msi_free_vector(dev, vector, 0); 1130 msi_free_vector(dev, vector, 0);
1102 if (warning) { 1131 if (warning) {
1103 /* Force to release the MSI-X memory-mapped table */ 1132 /* Force to release the MSI-X memory-mapped table */
1104 u32 phys_addr, table_offset; 1133#if 0
1134 unsigned long phys_addr;
1135 u32 table_offset;
1105 u16 control; 1136 u16 control;
1106 u8 bir; 1137 u8 bir;
1107 1138
@@ -1110,9 +1141,12 @@ void msi_remove_pci_irq_vectors(struct pci_dev* dev)
1110 pci_read_config_dword(dev, msix_table_offset_reg(pos), 1141 pci_read_config_dword(dev, msix_table_offset_reg(pos),
1111 &table_offset); 1142 &table_offset);
1112 bir = (u8)(table_offset & PCI_MSIX_FLAGS_BIRMASK); 1143 bir = (u8)(table_offset & PCI_MSIX_FLAGS_BIRMASK);
1113 phys_addr = pci_resource_start (dev, bir); 1144 table_offset &= ~PCI_MSIX_FLAGS_BIRMASK;
1114 phys_addr += (u32)(table_offset & 1145 phys_addr = pci_resource_start(dev, bir) + table_offset;
1115 ~PCI_MSIX_FLAGS_BIRMASK); 1146/*
1147 * FIXME! and what did you want to do with phys_addr?
1148 */
1149#endif
1116 iounmap(base); 1150 iounmap(base);
1117 printk(KERN_WARNING "PCI: %s: msi_remove_pci_irq_vectors() " 1151 printk(KERN_WARNING "PCI: %s: msi_remove_pci_irq_vectors() "
1118 "called without free_irq() on all MSI-X vectors\n", 1152 "called without free_irq() on all MSI-X vectors\n",
@@ -1123,6 +1157,11 @@ void msi_remove_pci_irq_vectors(struct pci_dev* dev)
1123 } 1157 }
1124} 1158}
1125 1159
1160void pci_no_msi(void)
1161{
1162 pci_msi_enable = 0;
1163}
1164
1126EXPORT_SYMBOL(pci_enable_msi); 1165EXPORT_SYMBOL(pci_enable_msi);
1127EXPORT_SYMBOL(pci_disable_msi); 1166EXPORT_SYMBOL(pci_disable_msi);
1128EXPORT_SYMBOL(pci_enable_msix); 1167EXPORT_SYMBOL(pci_enable_msix);
diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
index 0aa14c92b5..f22f69ac64 100644
--- a/drivers/pci/pci-driver.c
+++ b/drivers/pci/pci-driver.c
@@ -53,11 +53,10 @@ store_new_id(struct device_driver *driver, const char *buf, size_t count)
53 if (fields < 0) 53 if (fields < 0)
54 return -EINVAL; 54 return -EINVAL;
55 55
56 dynid = kmalloc(sizeof(*dynid), GFP_KERNEL); 56 dynid = kzalloc(sizeof(*dynid), GFP_KERNEL);
57 if (!dynid) 57 if (!dynid)
58 return -ENOMEM; 58 return -ENOMEM;
59 59
60 memset(dynid, 0, sizeof(*dynid));
61 INIT_LIST_HEAD(&dynid->node); 60 INIT_LIST_HEAD(&dynid->node);
62 dynid->id.vendor = vendor; 61 dynid->id.vendor = vendor;
63 dynid->id.device = device; 62 dynid->id.device = device;
@@ -380,14 +379,6 @@ int __pci_register_driver(struct pci_driver *drv, struct module *owner)
380 /* initialize common driver fields */ 379 /* initialize common driver fields */
381 drv->driver.name = drv->name; 380 drv->driver.name = drv->name;
382 drv->driver.bus = &pci_bus_type; 381 drv->driver.bus = &pci_bus_type;
383 /* FIXME, once all of the existing PCI drivers have been fixed to set
384 * the pci shutdown function, this test can go away. */
385 if (!drv->driver.shutdown)
386 drv->driver.shutdown = pci_device_shutdown;
387 else
388 printk(KERN_WARNING "Warning: PCI driver %s has a struct "
389 "device_driver shutdown method, please update!\n",
390 drv->name);
391 drv->driver.owner = owner; 382 drv->driver.owner = owner;
392 drv->driver.kobj.ktype = &pci_driver_kobj_type; 383 drv->driver.kobj.ktype = &pci_driver_kobj_type;
393 384
@@ -514,6 +505,7 @@ struct bus_type pci_bus_type = {
514 .probe = pci_device_probe, 505 .probe = pci_device_probe,
515 .remove = pci_device_remove, 506 .remove = pci_device_remove,
516 .suspend = pci_device_suspend, 507 .suspend = pci_device_suspend,
508 .shutdown = pci_device_shutdown,
517 .resume = pci_device_resume, 509 .resume = pci_device_resume,
518 .dev_attrs = pci_dev_attrs, 510 .dev_attrs = pci_dev_attrs,
519}; 511};
diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
index 965a593462..56ac2bc003 100644
--- a/drivers/pci/pci-sysfs.c
+++ b/drivers/pci/pci-sysfs.c
@@ -501,9 +501,8 @@ int pci_create_sysfs_dev_files (struct pci_dev *pdev)
501 if (pci_resource_len(pdev, PCI_ROM_RESOURCE)) { 501 if (pci_resource_len(pdev, PCI_ROM_RESOURCE)) {
502 struct bin_attribute *rom_attr; 502 struct bin_attribute *rom_attr;
503 503
504 rom_attr = kmalloc(sizeof(*rom_attr), GFP_ATOMIC); 504 rom_attr = kzalloc(sizeof(*rom_attr), GFP_ATOMIC);
505 if (rom_attr) { 505 if (rom_attr) {
506 memset(rom_attr, 0x00, sizeof(*rom_attr));
507 pdev->rom_attr = rom_attr; 506 pdev->rom_attr = rom_attr;
508 rom_attr->size = pci_resource_len(pdev, PCI_ROM_RESOURCE); 507 rom_attr->size = pci_resource_len(pdev, PCI_ROM_RESOURCE);
509 rom_attr->attr.name = "rom"; 508 rom_attr->attr.name = "rom";
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index d2d1879166..bea1ad1ad5 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -19,7 +19,6 @@
19#include <asm/dma.h> /* isa_dma_bridge_buggy */ 19#include <asm/dma.h> /* isa_dma_bridge_buggy */
20#include "pci.h" 20#include "pci.h"
21 21
22#if 0
23 22
24/** 23/**
25 * pci_bus_max_busnr - returns maximum PCI bus number of given bus' children 24 * pci_bus_max_busnr - returns maximum PCI bus number of given bus' children
@@ -34,7 +33,7 @@ pci_bus_max_busnr(struct pci_bus* bus)
34 struct list_head *tmp; 33 struct list_head *tmp;
35 unsigned char max, n; 34 unsigned char max, n;
36 35
37 max = bus->number; 36 max = bus->subordinate;
38 list_for_each(tmp, &bus->children) { 37 list_for_each(tmp, &bus->children) {
39 n = pci_bus_max_busnr(pci_bus_b(tmp)); 38 n = pci_bus_max_busnr(pci_bus_b(tmp));
40 if(n > max) 39 if(n > max)
@@ -42,7 +41,9 @@ pci_bus_max_busnr(struct pci_bus* bus)
42 } 41 }
43 return max; 42 return max;
44} 43}
44EXPORT_SYMBOL_GPL(pci_bus_max_busnr);
45 45
46#if 0
46/** 47/**
47 * pci_max_busnr - returns maximum PCI bus number 48 * pci_max_busnr - returns maximum PCI bus number
48 * 49 *
@@ -495,9 +496,8 @@ pci_enable_device_bars(struct pci_dev *dev, int bars)
495int 496int
496pci_enable_device(struct pci_dev *dev) 497pci_enable_device(struct pci_dev *dev)
497{ 498{
498 int err; 499 int err = pci_enable_device_bars(dev, (1 << PCI_NUM_RESOURCES) - 1);
499 500 if (err)
500 if ((err = pci_enable_device_bars(dev, (1 << PCI_NUM_RESOURCES) - 1)))
501 return err; 501 return err;
502 pci_fixup_device(pci_fixup_enable, dev); 502 pci_fixup_device(pci_fixup_enable, dev);
503 dev->is_enabled = 1; 503 dev->is_enabled = 1;
@@ -639,7 +639,7 @@ void pci_release_region(struct pci_dev *pdev, int bar)
639 * Returns 0 on success, or %EBUSY on error. A warning 639 * Returns 0 on success, or %EBUSY on error. A warning
640 * message is also printed on failure. 640 * message is also printed on failure.
641 */ 641 */
642int pci_request_region(struct pci_dev *pdev, int bar, char *res_name) 642int pci_request_region(struct pci_dev *pdev, int bar, const char *res_name)
643{ 643{
644 if (pci_resource_len(pdev, bar) == 0) 644 if (pci_resource_len(pdev, bar) == 0)
645 return 0; 645 return 0;
@@ -697,7 +697,7 @@ void pci_release_regions(struct pci_dev *pdev)
697 * Returns 0 on success, or %EBUSY on error. A warning 697 * Returns 0 on success, or %EBUSY on error. A warning
698 * message is also printed on failure. 698 * message is also printed on failure.
699 */ 699 */
700int pci_request_regions(struct pci_dev *pdev, char *res_name) 700int pci_request_regions(struct pci_dev *pdev, const char *res_name)
701{ 701{
702 int i; 702 int i;
703 703
@@ -900,8 +900,12 @@ static int __devinit pci_setup(char *str)
900 if (k) 900 if (k)
901 *k++ = 0; 901 *k++ = 0;
902 if (*str && (str = pcibios_setup(str)) && *str) { 902 if (*str && (str = pcibios_setup(str)) && *str) {
903 /* PCI layer options should be handled here */ 903 if (!strcmp(str, "nomsi")) {
904 printk(KERN_ERR "PCI: Unknown option `%s'\n", str); 904 pci_no_msi();
905 } else {
906 printk(KERN_ERR "PCI: Unknown option `%s'\n",
907 str);
908 }
905 } 909 }
906 str = k; 910 str = k;
907 } 911 }
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index a6dfee2f6d..8f3fb47ea6 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -50,8 +50,10 @@ extern int pci_msi_quirk;
50 50
51#ifdef CONFIG_PCI_MSI 51#ifdef CONFIG_PCI_MSI
52void disable_msi_mode(struct pci_dev *dev, int pos, int type); 52void disable_msi_mode(struct pci_dev *dev, int pos, int type);
53void pci_no_msi(void);
53#else 54#else
54static inline void disable_msi_mode(struct pci_dev *dev, int pos, int type) { } 55static inline void disable_msi_mode(struct pci_dev *dev, int pos, int type) { }
56static inline void pci_no_msi(void) { }
55#endif 57#endif
56 58
57extern int pcie_mch_quirk; 59extern int pcie_mch_quirk;
diff --git a/drivers/pci/pcie/portdrv.h b/drivers/pci/pcie/portdrv.h
index a63bd8f726..1d317d22ee 100644
--- a/drivers/pci/pcie/portdrv.h
+++ b/drivers/pci/pcie/portdrv.h
@@ -29,7 +29,6 @@
29 29
30struct pcie_port_device_ext { 30struct pcie_port_device_ext {
31 int interrupt_mode; /* [0:INTx | 1:MSI | 2:MSI-X] */ 31 int interrupt_mode; /* [0:INTx | 1:MSI | 2:MSI-X] */
32 unsigned int saved_msi_config_space[5];
33}; 32};
34 33
35extern struct bus_type pcie_port_bus_type; 34extern struct bus_type pcie_port_bus_type;
diff --git a/drivers/pci/pcie/portdrv_core.c b/drivers/pci/pcie/portdrv_core.c
index e4e5f1e8d8..55c6622678 100644
--- a/drivers/pci/pcie/portdrv_core.c
+++ b/drivers/pci/pcie/portdrv_core.c
@@ -248,11 +248,10 @@ static struct pcie_device* alloc_pcie_device(struct pci_dev *parent,
248{ 248{
249 struct pcie_device *device; 249 struct pcie_device *device;
250 250
251 device = kmalloc(sizeof(struct pcie_device), GFP_KERNEL); 251 device = kzalloc(sizeof(struct pcie_device), GFP_KERNEL);
252 if (!device) 252 if (!device)
253 return NULL; 253 return NULL;
254 254
255 memset(device, 0, sizeof(struct pcie_device));
256 pcie_device_init(parent, device, port_type, service_type, irq,irq_mode); 255 pcie_device_init(parent, device, port_type, service_type, irq,irq_mode);
257 printk(KERN_DEBUG "Allocate Port Service[%s]\n", device->device.bus_id); 256 printk(KERN_DEBUG "Allocate Port Service[%s]\n", device->device.bus_id);
258 return device; 257 return device;
diff --git a/drivers/pci/pcie/portdrv_pci.c b/drivers/pci/pcie/portdrv_pci.c
index 02260141dc..50bfc1b2f3 100644
--- a/drivers/pci/pcie/portdrv_pci.c
+++ b/drivers/pci/pcie/portdrv_pci.c
@@ -30,75 +30,16 @@ MODULE_LICENSE("GPL");
30/* global data */ 30/* global data */
31static const char device_name[] = "pcieport-driver"; 31static const char device_name[] = "pcieport-driver";
32 32
33static void pci_save_msi_state(struct pci_dev *dev) 33static int pcie_portdrv_save_config(struct pci_dev *dev)
34{ 34{
35 struct pcie_port_device_ext *p_ext = pci_get_drvdata(dev); 35 return pci_save_state(dev);
36 int i = 0, pos;
37 u16 control;
38
39 if ((pos = pci_find_capability(dev, PCI_CAP_ID_MSI)) <= 0)
40 return;
41
42 pci_read_config_dword(dev, pos, &p_ext->saved_msi_config_space[i++]);
43 control = p_ext->saved_msi_config_space[0] >> 16;
44 pci_read_config_dword(dev, pos + PCI_MSI_ADDRESS_LO,
45 &p_ext->saved_msi_config_space[i++]);
46 if (control & PCI_MSI_FLAGS_64BIT) {
47 pci_read_config_dword(dev, pos + PCI_MSI_ADDRESS_HI,
48 &p_ext->saved_msi_config_space[i++]);
49 pci_read_config_dword(dev, pos + PCI_MSI_DATA_64,
50 &p_ext->saved_msi_config_space[i++]);
51 } else
52 pci_read_config_dword(dev, pos + PCI_MSI_DATA_32,
53 &p_ext->saved_msi_config_space[i++]);
54 if (control & PCI_MSI_FLAGS_MASKBIT)
55 pci_read_config_dword(dev, pos + PCI_MSI_MASK_BIT,
56 &p_ext->saved_msi_config_space[i++]);
57}
58
59static void pci_restore_msi_state(struct pci_dev *dev)
60{
61 struct pcie_port_device_ext *p_ext = pci_get_drvdata(dev);
62 int i = 0, pos;
63 u16 control;
64
65 if ((pos = pci_find_capability(dev, PCI_CAP_ID_MSI)) <= 0)
66 return;
67
68 control = p_ext->saved_msi_config_space[i++] >> 16;
69 pci_write_config_word(dev, pos + PCI_MSI_FLAGS, control);
70 pci_write_config_dword(dev, pos + PCI_MSI_ADDRESS_LO,
71 p_ext->saved_msi_config_space[i++]);
72 if (control & PCI_MSI_FLAGS_64BIT) {
73 pci_write_config_dword(dev, pos + PCI_MSI_ADDRESS_HI,
74 p_ext->saved_msi_config_space[i++]);
75 pci_write_config_dword(dev, pos + PCI_MSI_DATA_64,
76 p_ext->saved_msi_config_space[i++]);
77 } else
78 pci_write_config_dword(dev, pos + PCI_MSI_DATA_32,
79 p_ext->saved_msi_config_space[i++]);
80 if (control & PCI_MSI_FLAGS_MASKBIT)
81 pci_write_config_dword(dev, pos + PCI_MSI_MASK_BIT,
82 p_ext->saved_msi_config_space[i++]);
83}
84
85static void pcie_portdrv_save_config(struct pci_dev *dev)
86{
87 struct pcie_port_device_ext *p_ext = pci_get_drvdata(dev);
88
89 pci_save_state(dev);
90 if (p_ext->interrupt_mode == PCIE_PORT_MSI_MODE)
91 pci_save_msi_state(dev);
92} 36}
93 37
94static int pcie_portdrv_restore_config(struct pci_dev *dev) 38static int pcie_portdrv_restore_config(struct pci_dev *dev)
95{ 39{
96 struct pcie_port_device_ext *p_ext = pci_get_drvdata(dev);
97 int retval; 40 int retval;
98 41
99 pci_restore_state(dev); 42 pci_restore_state(dev);
100 if (p_ext->interrupt_mode == PCIE_PORT_MSI_MODE)
101 pci_restore_msi_state(dev);
102 retval = pci_enable_device(dev); 43 retval = pci_enable_device(dev);
103 if (retval) 44 if (retval)
104 return retval; 45 return retval;
@@ -149,7 +90,8 @@ static int pcie_portdrv_suspend (struct pci_dev *dev, pm_message_t state)
149{ 90{
150 int ret = pcie_port_device_suspend(dev, state); 91 int ret = pcie_port_device_suspend(dev, state);
151 92
152 pcie_portdrv_save_config(dev); 93 if (!ret)
94 ret = pcie_portdrv_save_config(dev);
153 return ret; 95 return ret;
154} 96}
155 97
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index adfad4fd6a..a10ed9dab2 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -33,10 +33,9 @@ LIST_HEAD(pci_devices);
33 */ 33 */
34static void pci_create_legacy_files(struct pci_bus *b) 34static void pci_create_legacy_files(struct pci_bus *b)
35{ 35{
36 b->legacy_io = kmalloc(sizeof(struct bin_attribute) * 2, 36 b->legacy_io = kzalloc(sizeof(struct bin_attribute) * 2,
37 GFP_ATOMIC); 37 GFP_ATOMIC);
38 if (b->legacy_io) { 38 if (b->legacy_io) {
39 memset(b->legacy_io, 0, sizeof(struct bin_attribute) * 2);
40 b->legacy_io->attr.name = "legacy_io"; 39 b->legacy_io->attr.name = "legacy_io";
41 b->legacy_io->size = 0xffff; 40 b->legacy_io->size = 0xffff;
42 b->legacy_io->attr.mode = S_IRUSR | S_IWUSR; 41 b->legacy_io->attr.mode = S_IRUSR | S_IWUSR;
@@ -320,9 +319,8 @@ static struct pci_bus * __devinit pci_alloc_bus(void)
320{ 319{
321 struct pci_bus *b; 320 struct pci_bus *b;
322 321
323 b = kmalloc(sizeof(*b), GFP_KERNEL); 322 b = kzalloc(sizeof(*b), GFP_KERNEL);
324 if (b) { 323 if (b) {
325 memset(b, 0, sizeof(*b));
326 INIT_LIST_HEAD(&b->node); 324 INIT_LIST_HEAD(&b->node);
327 INIT_LIST_HEAD(&b->children); 325 INIT_LIST_HEAD(&b->children);
328 INIT_LIST_HEAD(&b->devices); 326 INIT_LIST_HEAD(&b->devices);
@@ -347,6 +345,7 @@ pci_alloc_child_bus(struct pci_bus *parent, struct pci_dev *bridge, int busnr)
347 child->parent = parent; 345 child->parent = parent;
348 child->ops = parent->ops; 346 child->ops = parent->ops;
349 child->sysdata = parent->sysdata; 347 child->sysdata = parent->sysdata;
348 child->bus_flags = parent->bus_flags;
350 child->bridge = get_device(&bridge->dev); 349 child->bridge = get_device(&bridge->dev);
351 350
352 child->class_dev.class = &pcibus_class; 351 child->class_dev.class = &pcibus_class;
@@ -456,7 +455,7 @@ int __devinit pci_scan_bridge(struct pci_bus *bus, struct pci_dev * dev, int max
456 * pass and just note the configuration. 455 * pass and just note the configuration.
457 */ 456 */
458 if (pass) 457 if (pass)
459 return max; 458 goto out;
460 busnr = (buses >> 8) & 0xFF; 459 busnr = (buses >> 8) & 0xFF;
461 460
462 /* 461 /*
@@ -466,12 +465,12 @@ int __devinit pci_scan_bridge(struct pci_bus *bus, struct pci_dev * dev, int max
466 if (pci_find_bus(pci_domain_nr(bus), busnr)) { 465 if (pci_find_bus(pci_domain_nr(bus), busnr)) {
467 printk(KERN_INFO "PCI: Bus %04x:%02x already known\n", 466 printk(KERN_INFO "PCI: Bus %04x:%02x already known\n",
468 pci_domain_nr(bus), busnr); 467 pci_domain_nr(bus), busnr);
469 return max; 468 goto out;
470 } 469 }
471 470
472 child = pci_add_new_bus(bus, dev, busnr); 471 child = pci_add_new_bus(bus, dev, busnr);
473 if (!child) 472 if (!child)
474 return max; 473 goto out;
475 child->primary = buses & 0xFF; 474 child->primary = buses & 0xFF;
476 child->subordinate = (buses >> 16) & 0xFF; 475 child->subordinate = (buses >> 16) & 0xFF;
477 child->bridge_ctl = bctl; 476 child->bridge_ctl = bctl;
@@ -496,7 +495,7 @@ int __devinit pci_scan_bridge(struct pci_bus *bus, struct pci_dev * dev, int max
496 bus ranges. */ 495 bus ranges. */
497 pci_write_config_dword(dev, PCI_PRIMARY_BUS, 496 pci_write_config_dword(dev, PCI_PRIMARY_BUS,
498 buses & ~0xffffff); 497 buses & ~0xffffff);
499 return max; 498 goto out;
500 } 499 }
501 500
502 /* Clear errors */ 501 /* Clear errors */
@@ -505,7 +504,7 @@ int __devinit pci_scan_bridge(struct pci_bus *bus, struct pci_dev * dev, int max
505 /* Prevent assigning a bus number that already exists. 504 /* Prevent assigning a bus number that already exists.
506 * This can happen when a bridge is hot-plugged */ 505 * This can happen when a bridge is hot-plugged */
507 if (pci_find_bus(pci_domain_nr(bus), max+1)) 506 if (pci_find_bus(pci_domain_nr(bus), max+1))
508 return max; 507 goto out;
509 child = pci_add_new_bus(bus, dev, ++max); 508 child = pci_add_new_bus(bus, dev, ++max);
510 buses = (buses & 0xff000000) 509 buses = (buses & 0xff000000)
511 | ((unsigned int)(child->primary) << 0) 510 | ((unsigned int)(child->primary) << 0)
@@ -537,6 +536,11 @@ int __devinit pci_scan_bridge(struct pci_bus *bus, struct pci_dev * dev, int max
537 pci_fixup_parent_subordinate_busnr(child, max); 536 pci_fixup_parent_subordinate_busnr(child, max);
538 /* Now we can scan all subordinate buses... */ 537 /* Now we can scan all subordinate buses... */
539 max = pci_scan_child_bus(child); 538 max = pci_scan_child_bus(child);
539 /*
540 * now fix it up again since we have found
541 * the real value of max.
542 */
543 pci_fixup_parent_subordinate_busnr(child, max);
540 } else { 544 } else {
541 /* 545 /*
542 * For CardBus bridges, we leave 4 bus numbers 546 * For CardBus bridges, we leave 4 bus numbers
@@ -576,8 +580,6 @@ int __devinit pci_scan_bridge(struct pci_bus *bus, struct pci_dev * dev, int max
576 pci_write_config_byte(dev, PCI_SUBORDINATE_BUS, max); 580 pci_write_config_byte(dev, PCI_SUBORDINATE_BUS, max);
577 } 581 }
578 582
579 pci_write_config_word(dev, PCI_BRIDGE_CONTROL, bctl);
580
581 sprintf(child->name, (is_cardbus ? "PCI CardBus #%02x" : "PCI Bus #%02x"), child->number); 583 sprintf(child->name, (is_cardbus ? "PCI CardBus #%02x" : "PCI Bus #%02x"), child->number);
582 584
583 while (bus->parent) { 585 while (bus->parent) {
@@ -585,17 +587,22 @@ int __devinit pci_scan_bridge(struct pci_bus *bus, struct pci_dev * dev, int max
585 (child->number > bus->subordinate) || 587 (child->number > bus->subordinate) ||
586 (child->number < bus->number) || 588 (child->number < bus->number) ||
587 (child->subordinate < bus->number)) { 589 (child->subordinate < bus->number)) {
588 printk(KERN_WARNING "PCI: Bus #%02x (-#%02x) may be " 590 printk(KERN_WARNING "PCI: Bus #%02x (-#%02x) is "
589 "hidden behind%s bridge #%02x (-#%02x)%s\n", 591 "hidden behind%s bridge #%02x (-#%02x)%s\n",
590 child->number, child->subordinate, 592 child->number, child->subordinate,
591 bus->self->transparent ? " transparent" : " ", 593 bus->self->transparent ? " transparent" : " ",
592 bus->number, bus->subordinate, 594 bus->number, bus->subordinate,
593 pcibios_assign_all_busses() ? " " : 595 pcibios_assign_all_busses() ? " " :
594 " (try 'pci=assign-busses')"); 596 " (try 'pci=assign-busses')");
597 printk(KERN_WARNING "Please report the result to "
598 "linux-kernel to fix this permanently\n");
595 } 599 }
596 bus = bus->parent; 600 bus = bus->parent;
597 } 601 }
598 602
603out:
604 pci_write_config_word(dev, PCI_BRIDGE_CONTROL, bctl);
605
599 return max; 606 return max;
600} 607}
601 608
@@ -788,11 +795,10 @@ pci_scan_device(struct pci_bus *bus, int devfn)
788 if (pci_bus_read_config_byte(bus, devfn, PCI_HEADER_TYPE, &hdr_type)) 795 if (pci_bus_read_config_byte(bus, devfn, PCI_HEADER_TYPE, &hdr_type))
789 return NULL; 796 return NULL;
790 797
791 dev = kmalloc(sizeof(struct pci_dev), GFP_KERNEL); 798 dev = kzalloc(sizeof(struct pci_dev), GFP_KERNEL);
792 if (!dev) 799 if (!dev)
793 return NULL; 800 return NULL;
794 801
795 memset(dev, 0, sizeof(struct pci_dev));
796 dev->bus = bus; 802 dev->bus = bus;
797 dev->sysdata = bus->sysdata; 803 dev->sysdata = bus->sysdata;
798 dev->dev.parent = bus->bridge; 804 dev->dev.parent = bus->bridge;
diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
index 92a8857608..54b2ebc9c9 100644
--- a/drivers/pci/proc.c
+++ b/drivers/pci/proc.c
@@ -458,131 +458,6 @@ int pci_proc_detach_bus(struct pci_bus* bus)
458 return 0; 458 return 0;
459} 459}
460 460
461#ifdef CONFIG_PCI_LEGACY_PROC
462
463/*
464 * Backward compatible /proc/pci interface.
465 */
466
467/*
468 * Convert some of the configuration space registers of the device at
469 * address (bus,devfn) into a string (possibly several lines each).
470 * The configuration string is stored starting at buf[len]. If the
471 * string would exceed the size of the buffer (SIZE), 0 is returned.
472 */
473static int show_dev_config(struct seq_file *m, void *v)
474{
475 struct pci_dev *dev = v;
476 struct pci_dev *first_dev;
477 struct pci_driver *drv;
478 u32 class_rev;
479 unsigned char latency, min_gnt, max_lat;
480 int reg;
481
482 first_dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL);
483 if (dev == first_dev)
484 seq_puts(m, "PCI devices found:\n");
485 pci_dev_put(first_dev);
486
487 drv = pci_dev_driver(dev);
488
489 pci_user_read_config_dword(dev, PCI_CLASS_REVISION, &class_rev);
490 pci_user_read_config_byte (dev, PCI_LATENCY_TIMER, &latency);
491 pci_user_read_config_byte (dev, PCI_MIN_GNT, &min_gnt);
492 pci_user_read_config_byte (dev, PCI_MAX_LAT, &max_lat);
493 seq_printf(m, " Bus %2d, device %3d, function %2d:\n",
494 dev->bus->number, PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn));
495 seq_printf(m, " Class %04x", class_rev >> 16);
496 seq_printf(m, ": PCI device %04x:%04x", dev->vendor, dev->device);
497 seq_printf(m, " (rev %d).\n", class_rev & 0xff);
498
499 if (dev->irq)
500 seq_printf(m, " IRQ %d.\n", dev->irq);
501
502 if (latency || min_gnt || max_lat) {
503 seq_printf(m, " Master Capable. ");
504 if (latency)
505 seq_printf(m, "Latency=%d. ", latency);
506 else
507 seq_puts(m, "No bursts. ");
508 if (min_gnt)
509 seq_printf(m, "Min Gnt=%d.", min_gnt);
510 if (max_lat)
511 seq_printf(m, "Max Lat=%d.", max_lat);
512 seq_putc(m, '\n');
513 }
514
515 for (reg = 0; reg < 6; reg++) {
516 struct resource *res = dev->resource + reg;
517 unsigned long base, end, flags;
518
519 base = res->start;
520 end = res->end;
521 flags = res->flags;
522 if (!end)
523 continue;
524
525 if (flags & PCI_BASE_ADDRESS_SPACE_IO) {
526 seq_printf(m, " I/O at 0x%lx [0x%lx].\n",
527 base, end);
528 } else {
529 const char *pref, *type = "unknown";
530
531 if (flags & PCI_BASE_ADDRESS_MEM_PREFETCH)
532 pref = "P";
533 else
534 pref = "Non-p";
535 switch (flags & PCI_BASE_ADDRESS_MEM_TYPE_MASK) {
536 case PCI_BASE_ADDRESS_MEM_TYPE_32:
537 type = "32 bit"; break;
538 case PCI_BASE_ADDRESS_MEM_TYPE_1M:
539 type = "20 bit"; break;
540 case PCI_BASE_ADDRESS_MEM_TYPE_64:
541 type = "64 bit"; break;
542 }
543 seq_printf(m, " %srefetchable %s memory at "
544 "0x%lx [0x%lx].\n", pref, type,
545 base,
546 end);
547 }
548 }
549 return 0;
550}
551
552static struct seq_operations proc_pci_op = {
553 .start = pci_seq_start,
554 .next = pci_seq_next,
555 .stop = pci_seq_stop,
556 .show = show_dev_config
557};
558
559static int proc_pci_open(struct inode *inode, struct file *file)
560{
561 return seq_open(file, &proc_pci_op);
562}
563static struct file_operations proc_pci_operations = {
564 .open = proc_pci_open,
565 .read = seq_read,
566 .llseek = seq_lseek,
567 .release = seq_release,
568};
569
570static void legacy_proc_init(void)
571{
572 struct proc_dir_entry * entry = create_proc_entry("pci", 0, NULL);
573 if (entry)
574 entry->proc_fops = &proc_pci_operations;
575}
576
577#else
578
579static void legacy_proc_init(void)
580{
581
582}
583
584#endif /* CONFIG_PCI_LEGACY_PROC */
585
586static int proc_bus_pci_dev_open(struct inode *inode, struct file *file) 461static int proc_bus_pci_dev_open(struct inode *inode, struct file *file)
587{ 462{
588 return seq_open(file, &proc_bus_pci_devices_op); 463 return seq_open(file, &proc_bus_pci_devices_op);
@@ -606,7 +481,6 @@ static int __init pci_proc_init(void)
606 while ((dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) { 481 while ((dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) {
607 pci_proc_attach_device(dev); 482 pci_proc_attach_device(dev);
608 } 483 }
609 legacy_proc_init();
610 return 0; 484 return 0;
611} 485}
612 486
diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
index dda6099903..4970f47be7 100644
--- a/drivers/pci/quirks.c
+++ b/drivers/pci/quirks.c
@@ -575,8 +575,11 @@ static void __init quirk_amd_8131_ioapic(struct pci_dev *dev)
575{ 575{
576 unsigned char revid, tmp; 576 unsigned char revid, tmp;
577 577
578 pci_msi_quirk = 1; 578 if (dev->subordinate) {
579 printk(KERN_WARNING "PCI: MSI quirk detected. pci_msi_quirk set.\n"); 579 printk(KERN_WARNING "PCI: MSI quirk detected. "
580 "PCI_BUS_FLAGS_NO_MSI set for subordinate bus.\n");
581 dev->subordinate->bus_flags |= PCI_BUS_FLAGS_NO_MSI;
582 }
580 583
581 if (nr_ioapics == 0) 584 if (nr_ioapics == 0)
582 return; 585 return;
@@ -934,6 +937,12 @@ static void __init asus_hides_smbus_hostbridge(struct pci_dev *dev)
934 case 0x12bd: /* HP D530 */ 937 case 0x12bd: /* HP D530 */
935 asus_hides_smbus = 1; 938 asus_hides_smbus = 1;
936 } 939 }
940 if (dev->device == PCI_DEVICE_ID_INTEL_82915GM_HB) {
941 switch (dev->subsystem_device) {
942 case 0x099c: /* HP Compaq nx6110 */
943 asus_hides_smbus = 1;
944 }
945 }
937 } else if (unlikely(dev->subsystem_vendor == PCI_VENDOR_ID_TOSHIBA)) { 946 } else if (unlikely(dev->subsystem_vendor == PCI_VENDOR_ID_TOSHIBA)) {
938 if (dev->device == PCI_DEVICE_ID_INTEL_82855GM_HB) 947 if (dev->device == PCI_DEVICE_ID_INTEL_82855GM_HB)
939 switch(dev->subsystem_device) { 948 switch(dev->subsystem_device) {
@@ -1068,6 +1077,37 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_651, quirk_sis_96x_
1068DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_735, quirk_sis_96x_compatible ); 1077DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_735, quirk_sis_96x_compatible );
1069 1078
1070DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_503, quirk_sis_503 ); 1079DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_503, quirk_sis_503 );
1080/*
1081 * On ASUS A8V and A8V Deluxe boards, the onboard AC97 audio controller
1082 * and MC97 modem controller are disabled when a second PCI soundcard is
1083 * present. This patch, tweaking the VT8237 ISA bridge, enables them.
1084 * -- bjd
1085 */
1086static void __init asus_hides_ac97_lpc(struct pci_dev *dev)
1087{
1088 u8 val;
1089 int asus_hides_ac97 = 0;
1090
1091 if (likely(dev->subsystem_vendor == PCI_VENDOR_ID_ASUSTEK)) {
1092 if (dev->device == PCI_DEVICE_ID_VIA_8237)
1093 asus_hides_ac97 = 1;
1094 }
1095
1096 if (!asus_hides_ac97)
1097 return;
1098
1099 pci_read_config_byte(dev, 0x50, &val);
1100 if (val & 0xc0) {
1101 pci_write_config_byte(dev, 0x50, val & (~0xc0));
1102 pci_read_config_byte(dev, 0x50, &val);
1103 if (val & 0xc0)
1104 printk(KERN_INFO "PCI: onboard AC97/MC97 devices continue to play 'hide and seek'! 0x%x\n", val);
1105 else
1106 printk(KERN_INFO "PCI: enabled onboard AC97/MC97 devices\n");
1107 }
1108}
1109DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237, asus_hides_ac97_lpc );
1110
1071 1111
1072DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_961, quirk_sis_96x_smbus ); 1112DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_961, quirk_sis_96x_smbus );
1073DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_962, quirk_sis_96x_smbus ); 1113DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_962, quirk_sis_96x_smbus );
@@ -1242,6 +1282,33 @@ DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PXH_1, quirk_pc
1242DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PXHV, quirk_pcie_pxh); 1282DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PXHV, quirk_pcie_pxh);
1243 1283
1244 1284
1285/*
1286 * Fixup the cardbus bridges on the IBM Dock II docking station
1287 */
1288static void __devinit quirk_ibm_dock2_cardbus(struct pci_dev *dev)
1289{
1290 u32 val;
1291
1292 /*
1293 * tie the 2 interrupt pins to INTA, and configure the
1294 * multifunction routing register to handle this.
1295 */
1296 if ((dev->subsystem_vendor == PCI_VENDOR_ID_IBM) &&
1297 (dev->subsystem_device == 0x0148)) {
1298 printk(KERN_INFO "PCI: Found IBM Dock II Cardbus Bridge "
1299 "applying quirk\n");
1300 pci_read_config_dword(dev, 0x8c, &val);
1301 val = ((val & 0xffffff00) | 0x1002);
1302 pci_write_config_dword(dev, 0x8c, val);
1303 pci_read_config_dword(dev, 0x80, &val);
1304 val = ((val & 0x00ffff00) | 0x2864c077);
1305 pci_write_config_dword(dev, 0x80, val);
1306 }
1307}
1308
1309DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_1420,
1310 quirk_ibm_dock2_cardbus);
1311
1245static void __devinit quirk_netmos(struct pci_dev *dev) 1312static void __devinit quirk_netmos(struct pci_dev *dev)
1246{ 1313{
1247 unsigned int num_parallel = (dev->subsystem_device & 0xf0) >> 4; 1314 unsigned int num_parallel = (dev->subsystem_device & 0xf0) >> 4;
diff --git a/drivers/pci/search.c b/drivers/pci/search.c
index 05fa91a31c..ce7dd6e7be 100644
--- a/drivers/pci/search.c
+++ b/drivers/pci/search.c
@@ -246,9 +246,9 @@ pci_get_subsys(unsigned int vendor, unsigned int device,
246 } 246 }
247 dev = NULL; 247 dev = NULL;
248exit: 248exit:
249 pci_dev_put(from);
250 dev = pci_dev_get(dev); 249 dev = pci_dev_get(dev);
251 spin_unlock(&pci_bus_lock); 250 spin_unlock(&pci_bus_lock);
251 pci_dev_put(from);
252 return dev; 252 return dev;
253} 253}
254 254
@@ -339,9 +339,9 @@ struct pci_dev *pci_get_class(unsigned int class, struct pci_dev *from)
339 } 339 }
340 dev = NULL; 340 dev = NULL;
341exit: 341exit:
342 pci_dev_put(from);
343 dev = pci_dev_get(dev); 342 dev = pci_dev_get(dev);
344 spin_unlock(&pci_bus_lock); 343 spin_unlock(&pci_bus_lock);
344 pci_dev_put(from);
345 return dev; 345 return dev;
346} 346}
347 347
diff --git a/drivers/pnp/pnpbios/rsparser.c b/drivers/pnp/pnpbios/rsparser.c
index 5e38cd7335..c89c98a2cc 100644
--- a/drivers/pnp/pnpbios/rsparser.c
+++ b/drivers/pnp/pnpbios/rsparser.c
@@ -448,11 +448,7 @@ pnpbios_parse_resource_option_data(unsigned char * p, unsigned char * end, struc
448 break; 448 break;
449 449
450 case SMALL_TAG_END: 450 case SMALL_TAG_END:
451 if (option_independent != option) 451 return p + 2;
452 printk(KERN_WARNING "PnPBIOS: Missing SMALL_TAG_ENDDEP tag\n");
453 p = p + 2;
454 return (unsigned char *)p;
455 break;
456 452
457 default: /* an unkown tag */ 453 default: /* an unkown tag */
458 len_err: 454 len_err:
diff --git a/drivers/s390/Kconfig b/drivers/s390/Kconfig
index 721787cc5a..4d36208ff8 100644
--- a/drivers/s390/Kconfig
+++ b/drivers/s390/Kconfig
@@ -183,7 +183,13 @@ config S390_TAPE_34XX
183 tape subsystems and 100% compatibles. 183 tape subsystems and 100% compatibles.
184 It is safe to say "Y" here. 184 It is safe to say "Y" here.
185 185
186 186config S390_TAPE_3590
187 tristate "Support for 3590 tape hardware"
188 depends on S390_TAPE
189 help
190 Select this option if you want to access IBM 3590 magnetic
191 tape subsystems and 100% compatibles.
192 It is safe to say "Y" here.
187 193
188config VMLOGRDR 194config VMLOGRDR
189 tristate "Support for the z/VM recording system services (VM only)" 195 tristate "Support for the z/VM recording system services (VM only)"
diff --git a/drivers/s390/block/Kconfig b/drivers/s390/block/Kconfig
index 6f50cc9323..929d6fff61 100644
--- a/drivers/s390/block/Kconfig
+++ b/drivers/s390/block/Kconfig
@@ -49,20 +49,18 @@ config DASD_FBA
49 49
50config DASD_DIAG 50config DASD_DIAG
51 tristate "Support for DIAG access to Disks" 51 tristate "Support for DIAG access to Disks"
52 depends on DASD && ( 64BIT = 'n' || EXPERIMENTAL) 52 depends on DASD
53 help 53 help
54 Select this option if you want to use Diagnose250 command to access 54 Select this option if you want to use Diagnose250 command to access
55 Disks under VM. If you are not running under VM or unsure what it is, 55 Disks under VM. If you are not running under VM or unsure what it is,
56 say "N". 56 say "N".
57 57
58config DASD_CMB 58config DASD_EER
59 tristate "Compatibility interface for DASD channel measurement blocks" 59 bool "Extended error reporting (EER)"
60 depends on DASD 60 depends on DASD
61 help 61 help
62 This driver provides an additional interface to the channel measurement 62 This driver provides a character device interface to the
63 facility, which is normally accessed though sysfs, with a set of 63 DASD extended error reporting. This is only needed if you want to
64 ioctl functions specific to the dasd driver. 64 use applications written for the EER facility.
65 This is only needed if you want to use applications written for
66 linux-2.4 dasd channel measurement facility interface.
67 65
68endif 66endif
diff --git a/drivers/s390/block/Makefile b/drivers/s390/block/Makefile
index 58c6780134..be9f22d52f 100644
--- a/drivers/s390/block/Makefile
+++ b/drivers/s390/block/Makefile
@@ -7,11 +7,13 @@ dasd_fba_mod-objs := dasd_fba.o dasd_3370_erp.o dasd_9336_erp.o
7dasd_diag_mod-objs := dasd_diag.o 7dasd_diag_mod-objs := dasd_diag.o
8dasd_mod-objs := dasd.o dasd_ioctl.o dasd_proc.o dasd_devmap.o \ 8dasd_mod-objs := dasd.o dasd_ioctl.o dasd_proc.o dasd_devmap.o \
9 dasd_genhd.o dasd_erp.o 9 dasd_genhd.o dasd_erp.o
10ifdef CONFIG_DASD_EER
11dasd_mod-objs += dasd_eer.o
12endif
10 13
11obj-$(CONFIG_DASD) += dasd_mod.o 14obj-$(CONFIG_DASD) += dasd_mod.o
12obj-$(CONFIG_DASD_DIAG) += dasd_diag_mod.o 15obj-$(CONFIG_DASD_DIAG) += dasd_diag_mod.o
13obj-$(CONFIG_DASD_ECKD) += dasd_eckd_mod.o 16obj-$(CONFIG_DASD_ECKD) += dasd_eckd_mod.o
14obj-$(CONFIG_DASD_FBA) += dasd_fba_mod.o 17obj-$(CONFIG_DASD_FBA) += dasd_fba_mod.o
15obj-$(CONFIG_DASD_CMB) += dasd_cmb.o
16obj-$(CONFIG_BLK_DEV_XPRAM) += xpram.o 18obj-$(CONFIG_BLK_DEV_XPRAM) += xpram.o
17obj-$(CONFIG_DCSSBLK) += dcssblk.o 19obj-$(CONFIG_DCSSBLK) += dcssblk.o
diff --git a/drivers/s390/block/dasd.c b/drivers/s390/block/dasd.c
index 33157c84d1..dfe542b206 100644
--- a/drivers/s390/block/dasd.c
+++ b/drivers/s390/block/dasd.c
@@ -71,10 +71,9 @@ dasd_alloc_device(void)
71{ 71{
72 struct dasd_device *device; 72 struct dasd_device *device;
73 73
74 device = kmalloc(sizeof (struct dasd_device), GFP_ATOMIC); 74 device = kzalloc(sizeof (struct dasd_device), GFP_ATOMIC);
75 if (device == NULL) 75 if (device == NULL)
76 return ERR_PTR(-ENOMEM); 76 return ERR_PTR(-ENOMEM);
77 memset(device, 0, sizeof (struct dasd_device));
78 /* open_count = 0 means device online but not in use */ 77 /* open_count = 0 means device online but not in use */
79 atomic_set(&device->open_count, -1); 78 atomic_set(&device->open_count, -1);
80 79
@@ -151,6 +150,8 @@ dasd_state_new_to_known(struct dasd_device *device)
151static inline void 150static inline void
152dasd_state_known_to_new(struct dasd_device * device) 151dasd_state_known_to_new(struct dasd_device * device)
153{ 152{
153 /* Disable extended error reporting for this device. */
154 dasd_eer_disable(device);
154 /* Forget the discipline information. */ 155 /* Forget the discipline information. */
155 if (device->discipline) 156 if (device->discipline)
156 module_put(device->discipline->owner); 157 module_put(device->discipline->owner);
@@ -545,29 +546,26 @@ dasd_kmalloc_request(char *magic, int cplength, int datasize,
545 (cplength*sizeof(struct ccw1)) > PAGE_SIZE) 546 (cplength*sizeof(struct ccw1)) > PAGE_SIZE)
546 BUG(); 547 BUG();
547 548
548 cqr = kmalloc(sizeof(struct dasd_ccw_req), GFP_ATOMIC); 549 cqr = kzalloc(sizeof(struct dasd_ccw_req), GFP_ATOMIC);
549 if (cqr == NULL) 550 if (cqr == NULL)
550 return ERR_PTR(-ENOMEM); 551 return ERR_PTR(-ENOMEM);
551 memset(cqr, 0, sizeof(struct dasd_ccw_req));
552 cqr->cpaddr = NULL; 552 cqr->cpaddr = NULL;
553 if (cplength > 0) { 553 if (cplength > 0) {
554 cqr->cpaddr = kmalloc(cplength*sizeof(struct ccw1), 554 cqr->cpaddr = kcalloc(cplength, sizeof(struct ccw1),
555 GFP_ATOMIC | GFP_DMA); 555 GFP_ATOMIC | GFP_DMA);
556 if (cqr->cpaddr == NULL) { 556 if (cqr->cpaddr == NULL) {
557 kfree(cqr); 557 kfree(cqr);
558 return ERR_PTR(-ENOMEM); 558 return ERR_PTR(-ENOMEM);
559 } 559 }
560 memset(cqr->cpaddr, 0, cplength*sizeof(struct ccw1));
561 } 560 }
562 cqr->data = NULL; 561 cqr->data = NULL;
563 if (datasize > 0) { 562 if (datasize > 0) {
564 cqr->data = kmalloc(datasize, GFP_ATOMIC | GFP_DMA); 563 cqr->data = kzalloc(datasize, GFP_ATOMIC | GFP_DMA);
565 if (cqr->data == NULL) { 564 if (cqr->data == NULL) {
566 kfree(cqr->cpaddr); 565 kfree(cqr->cpaddr);
567 kfree(cqr); 566 kfree(cqr);
568 return ERR_PTR(-ENOMEM); 567 return ERR_PTR(-ENOMEM);
569 } 568 }
570 memset(cqr->data, 0, datasize);
571 } 569 }
572 strncpy((char *) &cqr->magic, magic, 4); 570 strncpy((char *) &cqr->magic, magic, 4);
573 ASCEBC((char *) &cqr->magic, 4); 571 ASCEBC((char *) &cqr->magic, 4);
@@ -892,6 +890,9 @@ dasd_handle_state_change_pending(struct dasd_device *device)
892 struct dasd_ccw_req *cqr; 890 struct dasd_ccw_req *cqr;
893 struct list_head *l, *n; 891 struct list_head *l, *n;
894 892
893 /* First of all start sense subsystem status request. */
894 dasd_eer_snss(device);
895
895 device->stopped &= ~DASD_STOPPED_PENDING; 896 device->stopped &= ~DASD_STOPPED_PENDING;
896 897
897 /* restart all 'running' IO on queue */ 898 /* restart all 'running' IO on queue */
@@ -1111,6 +1112,19 @@ restart:
1111 } 1112 }
1112 goto restart; 1113 goto restart;
1113 } 1114 }
1115
1116 /* First of all call extended error reporting. */
1117 if (dasd_eer_enabled(device) &&
1118 cqr->status == DASD_CQR_FAILED) {
1119 dasd_eer_write(device, cqr, DASD_EER_FATALERROR);
1120
1121 /* restart request */
1122 cqr->status = DASD_CQR_QUEUED;
1123 cqr->retries = 255;
1124 device->stopped |= DASD_STOPPED_QUIESCE;
1125 goto restart;
1126 }
1127
1114 /* Process finished ERP request. */ 1128 /* Process finished ERP request. */
1115 if (cqr->refers) { 1129 if (cqr->refers) {
1116 __dasd_process_erp(device, cqr); 1130 __dasd_process_erp(device, cqr);
@@ -1248,7 +1262,8 @@ __dasd_start_head(struct dasd_device * device)
1248 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, list); 1262 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, list);
1249 /* check FAILFAST */ 1263 /* check FAILFAST */
1250 if (device->stopped & ~DASD_STOPPED_PENDING && 1264 if (device->stopped & ~DASD_STOPPED_PENDING &&
1251 test_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags)) { 1265 test_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags) &&
1266 (!dasd_eer_enabled(device))) {
1252 cqr->status = DASD_CQR_FAILED; 1267 cqr->status = DASD_CQR_FAILED;
1253 dasd_schedule_bh(device); 1268 dasd_schedule_bh(device);
1254 } 1269 }
@@ -1807,7 +1822,7 @@ dasd_exit(void)
1807#ifdef CONFIG_PROC_FS 1822#ifdef CONFIG_PROC_FS
1808 dasd_proc_exit(); 1823 dasd_proc_exit();
1809#endif 1824#endif
1810 dasd_ioctl_exit(); 1825 dasd_eer_exit();
1811 if (dasd_page_cache != NULL) { 1826 if (dasd_page_cache != NULL) {
1812 kmem_cache_destroy(dasd_page_cache); 1827 kmem_cache_destroy(dasd_page_cache);
1813 dasd_page_cache = NULL; 1828 dasd_page_cache = NULL;
@@ -2004,6 +2019,9 @@ dasd_generic_notify(struct ccw_device *cdev, int event)
2004 switch (event) { 2019 switch (event) {
2005 case CIO_GONE: 2020 case CIO_GONE:
2006 case CIO_NO_PATH: 2021 case CIO_NO_PATH:
2022 /* First of all call extended error reporting. */
2023 dasd_eer_write(device, NULL, DASD_EER_NOPATH);
2024
2007 if (device->state < DASD_STATE_BASIC) 2025 if (device->state < DASD_STATE_BASIC)
2008 break; 2026 break;
2009 /* Device is active. We want to keep it. */ 2027 /* Device is active. We want to keep it. */
@@ -2061,6 +2079,7 @@ dasd_generic_auto_online (struct ccw_driver *dasd_discipline_driver)
2061 put_driver(drv); 2079 put_driver(drv);
2062} 2080}
2063 2081
2082
2064static int __init 2083static int __init
2065dasd_init(void) 2084dasd_init(void)
2066{ 2085{
@@ -2093,7 +2112,7 @@ dasd_init(void)
2093 rc = dasd_parse(); 2112 rc = dasd_parse();
2094 if (rc) 2113 if (rc)
2095 goto failed; 2114 goto failed;
2096 rc = dasd_ioctl_init(); 2115 rc = dasd_eer_init();
2097 if (rc) 2116 if (rc)
2098 goto failed; 2117 goto failed;
2099#ifdef CONFIG_PROC_FS 2118#ifdef CONFIG_PROC_FS
diff --git a/drivers/s390/block/dasd_3990_erp.c b/drivers/s390/block/dasd_3990_erp.c
index 4ee0f934e3..2ed5156231 100644
--- a/drivers/s390/block/dasd_3990_erp.c
+++ b/drivers/s390/block/dasd_3990_erp.c
@@ -1108,6 +1108,9 @@ dasd_3990_handle_env_data(struct dasd_ccw_req * erp, char *sense)
1108 case 0x0B: 1108 case 0x0B:
1109 DEV_MESSAGE(KERN_WARNING, device, "%s", 1109 DEV_MESSAGE(KERN_WARNING, device, "%s",
1110 "FORMAT F - Volume is suspended duplex"); 1110 "FORMAT F - Volume is suspended duplex");
1111 /* call extended error reporting (EER) */
1112 dasd_eer_write(device, erp->refers,
1113 DASD_EER_PPRCSUSPEND);
1111 break; 1114 break;
1112 case 0x0C: 1115 case 0x0C:
1113 DEV_MESSAGE(KERN_WARNING, device, "%s", 1116 DEV_MESSAGE(KERN_WARNING, device, "%s",
diff --git a/drivers/s390/block/dasd_cmb.c b/drivers/s390/block/dasd_cmb.c
deleted file mode 100644
index e88f73ee72..0000000000
--- a/drivers/s390/block/dasd_cmb.c
+++ /dev/null
@@ -1,128 +0,0 @@
1/*
2 * Linux on zSeries Channel Measurement Facility support
3 * (dasd device driver interface)
4 *
5 * Copyright 2000,2003 IBM Corporation
6 *
7 * Author: Arnd Bergmann <arndb@de.ibm.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2, or (at your option)
12 * any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 */
23#include <linux/init.h>
24#include <linux/module.h>
25#include <asm/ccwdev.h>
26#include <asm/cmb.h>
27
28#include "dasd_int.h"
29
30static int
31dasd_ioctl_cmf_enable(struct block_device *bdev, int no, long args)
32{
33 struct dasd_device *device;
34
35 device = bdev->bd_disk->private_data;
36 if (!device)
37 return -EINVAL;
38
39 return enable_cmf(device->cdev);
40}
41
42static int
43dasd_ioctl_cmf_disable(struct block_device *bdev, int no, long args)
44{
45 struct dasd_device *device;
46
47 device = bdev->bd_disk->private_data;
48 if (!device)
49 return -EINVAL;
50
51 return disable_cmf(device->cdev);
52}
53
54static int
55dasd_ioctl_readall_cmb(struct block_device *bdev, int no, long args)
56{
57 struct dasd_device *device;
58 struct cmbdata __user *udata;
59 struct cmbdata data;
60 size_t size;
61 int ret;
62
63 device = bdev->bd_disk->private_data;
64 if (!device)
65 return -EINVAL;
66 udata = (void __user *) args;
67 size = _IOC_SIZE(no);
68
69 if (!access_ok(VERIFY_WRITE, udata, size))
70 return -EFAULT;
71 ret = cmf_readall(device->cdev, &data);
72 if (ret)
73 return ret;
74 if (copy_to_user(udata, &data, min(size, sizeof(*udata))))
75 return -EFAULT;
76 return 0;
77}
78
79/* module initialization below here. dasd already provides a mechanism
80 * to dynamically register ioctl functions, so we simply use this. */
81static inline int
82ioctl_reg(unsigned int no, dasd_ioctl_fn_t handler)
83{
84 return dasd_ioctl_no_register(THIS_MODULE, no, handler);
85}
86
87static inline void
88ioctl_unreg(unsigned int no, dasd_ioctl_fn_t handler)
89{
90 dasd_ioctl_no_unregister(THIS_MODULE, no, handler);
91}
92
93static void
94dasd_cmf_exit(void)
95{
96 ioctl_unreg(BIODASDCMFENABLE, dasd_ioctl_cmf_enable);
97 ioctl_unreg(BIODASDCMFDISABLE, dasd_ioctl_cmf_disable);
98 ioctl_unreg(BIODASDREADALLCMB, dasd_ioctl_readall_cmb);
99}
100
101static int __init
102dasd_cmf_init(void)
103{
104 int ret;
105 ret = ioctl_reg (BIODASDCMFENABLE, dasd_ioctl_cmf_enable);
106 if (ret)
107 goto err;
108 ret = ioctl_reg (BIODASDCMFDISABLE, dasd_ioctl_cmf_disable);
109 if (ret)
110 goto err;
111 ret = ioctl_reg (BIODASDREADALLCMB, dasd_ioctl_readall_cmb);
112 if (ret)
113 goto err;
114
115 return 0;
116err:
117 dasd_cmf_exit();
118
119 return ret;
120}
121
122module_init(dasd_cmf_init);
123module_exit(dasd_cmf_exit);
124
125MODULE_AUTHOR("Arnd Bergmann <arndb@de.ibm.com>");
126MODULE_LICENSE("GPL");
127MODULE_DESCRIPTION("channel measurement facility interface for dasd\n"
128 "Copyright 2003 IBM Corporation\n");
diff --git a/drivers/s390/block/dasd_devmap.c b/drivers/s390/block/dasd_devmap.c
index 1629b27c48..f576f243cd 100644
--- a/drivers/s390/block/dasd_devmap.c
+++ b/drivers/s390/block/dasd_devmap.c
@@ -715,10 +715,51 @@ dasd_discipline_show(struct device *dev, struct device_attribute *attr, char *bu
715 715
716static DEVICE_ATTR(discipline, 0444, dasd_discipline_show, NULL); 716static DEVICE_ATTR(discipline, 0444, dasd_discipline_show, NULL);
717 717
718/*
719 * extended error-reporting
720 */
721static ssize_t
722dasd_eer_show(struct device *dev, struct device_attribute *attr, char *buf)
723{
724 struct dasd_devmap *devmap;
725 int eer_flag;
726
727 devmap = dasd_find_busid(dev->bus_id);
728 if (!IS_ERR(devmap) && devmap->device)
729 eer_flag = dasd_eer_enabled(devmap->device);
730 else
731 eer_flag = 0;
732 return snprintf(buf, PAGE_SIZE, eer_flag ? "1\n" : "0\n");
733}
734
735static ssize_t
736dasd_eer_store(struct device *dev, struct device_attribute *attr,
737 const char *buf, size_t count)
738{
739 struct dasd_devmap *devmap;
740 int rc;
741
742 devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
743 if (IS_ERR(devmap))
744 return PTR_ERR(devmap);
745 if (!devmap->device)
746 return count;
747 if (buf[0] == '1') {
748 rc = dasd_eer_enable(devmap->device);
749 if (rc)
750 return rc;
751 } else
752 dasd_eer_disable(devmap->device);
753 return count;
754}
755
756static DEVICE_ATTR(eer_enabled, 0644, dasd_eer_show, dasd_eer_store);
757
718static struct attribute * dasd_attrs[] = { 758static struct attribute * dasd_attrs[] = {
719 &dev_attr_readonly.attr, 759 &dev_attr_readonly.attr,
720 &dev_attr_discipline.attr, 760 &dev_attr_discipline.attr,
721 &dev_attr_use_diag.attr, 761 &dev_attr_use_diag.attr,
762 &dev_attr_eer_enabled.attr,
722 NULL, 763 NULL,
723}; 764};
724 765
diff --git a/drivers/s390/block/dasd_eckd.c b/drivers/s390/block/dasd_eckd.c
index 822e2a2655..ee09ef33d0 100644
--- a/drivers/s390/block/dasd_eckd.c
+++ b/drivers/s390/block/dasd_eckd.c
@@ -1227,19 +1227,14 @@ dasd_eckd_fill_info(struct dasd_device * device,
1227 * (see dasd_eckd_reserve) device. 1227 * (see dasd_eckd_reserve) device.
1228 */ 1228 */
1229static int 1229static int
1230dasd_eckd_release(struct block_device *bdev, int no, long args) 1230dasd_eckd_release(struct dasd_device *device)
1231{ 1231{
1232 struct dasd_device *device;
1233 struct dasd_ccw_req *cqr; 1232 struct dasd_ccw_req *cqr;
1234 int rc; 1233 int rc;
1235 1234
1236 if (!capable(CAP_SYS_ADMIN)) 1235 if (!capable(CAP_SYS_ADMIN))
1237 return -EACCES; 1236 return -EACCES;
1238 1237
1239 device = bdev->bd_disk->private_data;
1240 if (device == NULL)
1241 return -ENODEV;
1242
1243 cqr = dasd_smalloc_request(dasd_eckd_discipline.name, 1238 cqr = dasd_smalloc_request(dasd_eckd_discipline.name,
1244 1, 32, device); 1239 1, 32, device);
1245 if (IS_ERR(cqr)) { 1240 if (IS_ERR(cqr)) {
@@ -1272,19 +1267,14 @@ dasd_eckd_release(struct block_device *bdev, int no, long args)
1272 * the interrupt is outstanding for a certain time. 1267 * the interrupt is outstanding for a certain time.
1273 */ 1268 */
1274static int 1269static int
1275dasd_eckd_reserve(struct block_device *bdev, int no, long args) 1270dasd_eckd_reserve(struct dasd_device *device)
1276{ 1271{
1277 struct dasd_device *device;
1278 struct dasd_ccw_req *cqr; 1272 struct dasd_ccw_req *cqr;
1279 int rc; 1273 int rc;
1280 1274
1281 if (!capable(CAP_SYS_ADMIN)) 1275 if (!capable(CAP_SYS_ADMIN))
1282 return -EACCES; 1276 return -EACCES;
1283 1277
1284 device = bdev->bd_disk->private_data;
1285 if (device == NULL)
1286 return -ENODEV;
1287
1288 cqr = dasd_smalloc_request(dasd_eckd_discipline.name, 1278 cqr = dasd_smalloc_request(dasd_eckd_discipline.name,
1289 1, 32, device); 1279 1, 32, device);
1290 if (IS_ERR(cqr)) { 1280 if (IS_ERR(cqr)) {
@@ -1316,19 +1306,14 @@ dasd_eckd_reserve(struct block_device *bdev, int no, long args)
1316 * (unconditional reserve) 1306 * (unconditional reserve)
1317 */ 1307 */
1318static int 1308static int
1319dasd_eckd_steal_lock(struct block_device *bdev, int no, long args) 1309dasd_eckd_steal_lock(struct dasd_device *device)
1320{ 1310{
1321 struct dasd_device *device;
1322 struct dasd_ccw_req *cqr; 1311 struct dasd_ccw_req *cqr;
1323 int rc; 1312 int rc;
1324 1313
1325 if (!capable(CAP_SYS_ADMIN)) 1314 if (!capable(CAP_SYS_ADMIN))
1326 return -EACCES; 1315 return -EACCES;
1327 1316
1328 device = bdev->bd_disk->private_data;
1329 if (device == NULL)
1330 return -ENODEV;
1331
1332 cqr = dasd_smalloc_request(dasd_eckd_discipline.name, 1317 cqr = dasd_smalloc_request(dasd_eckd_discipline.name,
1333 1, 32, device); 1318 1, 32, device);
1334 if (IS_ERR(cqr)) { 1319 if (IS_ERR(cqr)) {
@@ -1358,19 +1343,14 @@ dasd_eckd_steal_lock(struct block_device *bdev, int no, long args)
1358 * Read performance statistics 1343 * Read performance statistics
1359 */ 1344 */
1360static int 1345static int
1361dasd_eckd_performance(struct block_device *bdev, int no, long args) 1346dasd_eckd_performance(struct dasd_device *device, void __user *argp)
1362{ 1347{
1363 struct dasd_device *device;
1364 struct dasd_psf_prssd_data *prssdp; 1348 struct dasd_psf_prssd_data *prssdp;
1365 struct dasd_rssd_perf_stats_t *stats; 1349 struct dasd_rssd_perf_stats_t *stats;
1366 struct dasd_ccw_req *cqr; 1350 struct dasd_ccw_req *cqr;
1367 struct ccw1 *ccw; 1351 struct ccw1 *ccw;
1368 int rc; 1352 int rc;
1369 1353
1370 device = bdev->bd_disk->private_data;
1371 if (device == NULL)
1372 return -ENODEV;
1373
1374 cqr = dasd_smalloc_request(dasd_eckd_discipline.name, 1354 cqr = dasd_smalloc_request(dasd_eckd_discipline.name,
1375 1 /* PSF */ + 1 /* RSSD */ , 1355 1 /* PSF */ + 1 /* RSSD */ ,
1376 (sizeof (struct dasd_psf_prssd_data) + 1356 (sizeof (struct dasd_psf_prssd_data) +
@@ -1414,8 +1394,9 @@ dasd_eckd_performance(struct block_device *bdev, int no, long args)
1414 /* Prepare for Read Subsystem Data */ 1394 /* Prepare for Read Subsystem Data */
1415 prssdp = (struct dasd_psf_prssd_data *) cqr->data; 1395 prssdp = (struct dasd_psf_prssd_data *) cqr->data;
1416 stats = (struct dasd_rssd_perf_stats_t *) (prssdp + 1); 1396 stats = (struct dasd_rssd_perf_stats_t *) (prssdp + 1);
1417 rc = copy_to_user((long __user *) args, (long *) stats, 1397 if (copy_to_user(argp, stats,
1418 sizeof(struct dasd_rssd_perf_stats_t)); 1398 sizeof(struct dasd_rssd_perf_stats_t)))
1399 rc = -EFAULT;
1419 } 1400 }
1420 dasd_sfree_request(cqr, cqr->device); 1401 dasd_sfree_request(cqr, cqr->device);
1421 return rc; 1402 return rc;
@@ -1426,27 +1407,22 @@ dasd_eckd_performance(struct block_device *bdev, int no, long args)
1426 * Returnes the cache attributes used in Define Extend (DE). 1407 * Returnes the cache attributes used in Define Extend (DE).
1427 */ 1408 */
1428static int 1409static int
1429dasd_eckd_get_attrib (struct block_device *bdev, int no, long args) 1410dasd_eckd_get_attrib(struct dasd_device *device, void __user *argp)
1430{ 1411{
1431 struct dasd_device *device; 1412 struct dasd_eckd_private *private =
1432 struct dasd_eckd_private *private; 1413 (struct dasd_eckd_private *)device->private;
1433 struct attrib_data_t attrib; 1414 struct attrib_data_t attrib = private->attrib;
1434 int rc; 1415 int rc;
1435 1416
1436 if (!capable(CAP_SYS_ADMIN)) 1417 if (!capable(CAP_SYS_ADMIN))
1437 return -EACCES; 1418 return -EACCES;
1438 if (!args) 1419 if (!argp)
1439 return -EINVAL; 1420 return -EINVAL;
1440 1421
1441 device = bdev->bd_disk->private_data; 1422 rc = 0;
1442 if (device == NULL) 1423 if (copy_to_user(argp, (long *) &attrib,
1443 return -ENODEV; 1424 sizeof (struct attrib_data_t)))
1444 1425 rc = -EFAULT;
1445 private = (struct dasd_eckd_private *) device->private;
1446 attrib = private->attrib;
1447
1448 rc = copy_to_user((long __user *) args, (long *) &attrib,
1449 sizeof (struct attrib_data_t));
1450 1426
1451 return rc; 1427 return rc;
1452} 1428}
@@ -1456,26 +1432,19 @@ dasd_eckd_get_attrib (struct block_device *bdev, int no, long args)
1456 * Stores the attributes for cache operation to be used in Define Extend (DE). 1432 * Stores the attributes for cache operation to be used in Define Extend (DE).
1457 */ 1433 */
1458static int 1434static int
1459dasd_eckd_set_attrib(struct block_device *bdev, int no, long args) 1435dasd_eckd_set_attrib(struct dasd_device *device, void __user *argp)
1460{ 1436{
1461 struct dasd_device *device; 1437 struct dasd_eckd_private *private =
1462 struct dasd_eckd_private *private; 1438 (struct dasd_eckd_private *)device->private;
1463 struct attrib_data_t attrib; 1439 struct attrib_data_t attrib;
1464 1440
1465 if (!capable(CAP_SYS_ADMIN)) 1441 if (!capable(CAP_SYS_ADMIN))
1466 return -EACCES; 1442 return -EACCES;
1467 if (!args) 1443 if (!argp)
1468 return -EINVAL; 1444 return -EINVAL;
1469 1445
1470 device = bdev->bd_disk->private_data; 1446 if (copy_from_user(&attrib, argp, sizeof(struct attrib_data_t)))
1471 if (device == NULL)
1472 return -ENODEV;
1473
1474 if (copy_from_user(&attrib, (void __user *) args,
1475 sizeof (struct attrib_data_t))) {
1476 return -EFAULT; 1447 return -EFAULT;
1477 }
1478 private = (struct dasd_eckd_private *) device->private;
1479 private->attrib = attrib; 1448 private->attrib = attrib;
1480 1449
1481 DEV_MESSAGE(KERN_INFO, device, 1450 DEV_MESSAGE(KERN_INFO, device,
@@ -1484,6 +1453,27 @@ dasd_eckd_set_attrib(struct block_device *bdev, int no, long args)
1484 return 0; 1453 return 0;
1485} 1454}
1486 1455
1456static int
1457dasd_eckd_ioctl(struct dasd_device *device, unsigned int cmd, void __user *argp)
1458{
1459 switch (cmd) {
1460 case BIODASDGATTR:
1461 return dasd_eckd_get_attrib(device, argp);
1462 case BIODASDSATTR:
1463 return dasd_eckd_set_attrib(device, argp);
1464 case BIODASDPSRD:
1465 return dasd_eckd_performance(device, argp);
1466 case BIODASDRLSE:
1467 return dasd_eckd_release(device);
1468 case BIODASDRSRV:
1469 return dasd_eckd_reserve(device);
1470 case BIODASDSLCK:
1471 return dasd_eckd_steal_lock(device);
1472 default:
1473 return -ENOIOCTLCMD;
1474 }
1475}
1476
1487/* 1477/*
1488 * Print sense data and related channel program. 1478 * Print sense data and related channel program.
1489 * Parts are printed because printk buffer is only 1024 bytes. 1479 * Parts are printed because printk buffer is only 1024 bytes.
@@ -1642,6 +1632,7 @@ static struct dasd_discipline dasd_eckd_discipline = {
1642 .free_cp = dasd_eckd_free_cp, 1632 .free_cp = dasd_eckd_free_cp,
1643 .dump_sense = dasd_eckd_dump_sense, 1633 .dump_sense = dasd_eckd_dump_sense,
1644 .fill_info = dasd_eckd_fill_info, 1634 .fill_info = dasd_eckd_fill_info,
1635 .ioctl = dasd_eckd_ioctl,
1645}; 1636};
1646 1637
1647static int __init 1638static int __init
@@ -1649,59 +1640,18 @@ dasd_eckd_init(void)
1649{ 1640{
1650 int ret; 1641 int ret;
1651 1642
1652 dasd_ioctl_no_register(THIS_MODULE, BIODASDGATTR,
1653 dasd_eckd_get_attrib);
1654 dasd_ioctl_no_register(THIS_MODULE, BIODASDSATTR,
1655 dasd_eckd_set_attrib);
1656 dasd_ioctl_no_register(THIS_MODULE, BIODASDPSRD,
1657 dasd_eckd_performance);
1658 dasd_ioctl_no_register(THIS_MODULE, BIODASDRLSE,
1659 dasd_eckd_release);
1660 dasd_ioctl_no_register(THIS_MODULE, BIODASDRSRV,
1661 dasd_eckd_reserve);
1662 dasd_ioctl_no_register(THIS_MODULE, BIODASDSLCK,
1663 dasd_eckd_steal_lock);
1664
1665 ASCEBC(dasd_eckd_discipline.ebcname, 4); 1643 ASCEBC(dasd_eckd_discipline.ebcname, 4);
1666 1644
1667 ret = ccw_driver_register(&dasd_eckd_driver); 1645 ret = ccw_driver_register(&dasd_eckd_driver);
1668 if (ret) { 1646 if (!ret)
1669 dasd_ioctl_no_unregister(THIS_MODULE, BIODASDGATTR, 1647 dasd_generic_auto_online(&dasd_eckd_driver);
1670 dasd_eckd_get_attrib); 1648 return ret;
1671 dasd_ioctl_no_unregister(THIS_MODULE, BIODASDSATTR,
1672 dasd_eckd_set_attrib);
1673 dasd_ioctl_no_unregister(THIS_MODULE, BIODASDPSRD,
1674 dasd_eckd_performance);
1675 dasd_ioctl_no_unregister(THIS_MODULE, BIODASDRLSE,
1676 dasd_eckd_release);
1677 dasd_ioctl_no_unregister(THIS_MODULE, BIODASDRSRV,
1678 dasd_eckd_reserve);
1679 dasd_ioctl_no_unregister(THIS_MODULE, BIODASDSLCK,
1680 dasd_eckd_steal_lock);
1681 return ret;
1682 }
1683
1684 dasd_generic_auto_online(&dasd_eckd_driver);
1685 return 0;
1686} 1649}
1687 1650
1688static void __exit 1651static void __exit
1689dasd_eckd_cleanup(void) 1652dasd_eckd_cleanup(void)
1690{ 1653{
1691 ccw_driver_unregister(&dasd_eckd_driver); 1654 ccw_driver_unregister(&dasd_eckd_driver);
1692
1693 dasd_ioctl_no_unregister(THIS_MODULE, BIODASDGATTR,
1694 dasd_eckd_get_attrib);
1695 dasd_ioctl_no_unregister(THIS_MODULE, BIODASDSATTR,
1696 dasd_eckd_set_attrib);
1697 dasd_ioctl_no_unregister(THIS_MODULE, BIODASDPSRD,
1698 dasd_eckd_performance);
1699 dasd_ioctl_no_unregister(THIS_MODULE, BIODASDRLSE,
1700 dasd_eckd_release);
1701 dasd_ioctl_no_unregister(THIS_MODULE, BIODASDRSRV,
1702 dasd_eckd_reserve);
1703 dasd_ioctl_no_unregister(THIS_MODULE, BIODASDSLCK,
1704 dasd_eckd_steal_lock);
1705} 1655}
1706 1656
1707module_init(dasd_eckd_init); 1657module_init(dasd_eckd_init);
diff --git a/drivers/s390/block/dasd_eckd.h b/drivers/s390/block/dasd_eckd.h
index bc3823d352..ad8524bb7b 100644
--- a/drivers/s390/block/dasd_eckd.h
+++ b/drivers/s390/block/dasd_eckd.h
@@ -29,6 +29,7 @@
29#define DASD_ECKD_CCW_PSF 0x27 29#define DASD_ECKD_CCW_PSF 0x27
30#define DASD_ECKD_CCW_RSSD 0x3e 30#define DASD_ECKD_CCW_RSSD 0x3e
31#define DASD_ECKD_CCW_LOCATE_RECORD 0x47 31#define DASD_ECKD_CCW_LOCATE_RECORD 0x47
32#define DASD_ECKD_CCW_SNSS 0x54
32#define DASD_ECKD_CCW_DEFINE_EXTENT 0x63 33#define DASD_ECKD_CCW_DEFINE_EXTENT 0x63
33#define DASD_ECKD_CCW_WRITE_MT 0x85 34#define DASD_ECKD_CCW_WRITE_MT 0x85
34#define DASD_ECKD_CCW_READ_MT 0x86 35#define DASD_ECKD_CCW_READ_MT 0x86
diff --git a/drivers/s390/block/dasd_eer.c b/drivers/s390/block/dasd_eer.c
new file mode 100644
index 0000000000..2d946b6ca0
--- /dev/null
+++ b/drivers/s390/block/dasd_eer.c
@@ -0,0 +1,682 @@
1/*
2 * Character device driver for extended error reporting.
3 *
4 * Copyright (C) 2005 IBM Corporation
5 * extended error reporting for DASD ECKD devices
6 * Author(s): Stefan Weinhuber <wein@de.ibm.com>
7 */
8
9#include <linux/init.h>
10#include <linux/fs.h>
11#include <linux/kernel.h>
12#include <linux/miscdevice.h>
13#include <linux/module.h>
14#include <linux/moduleparam.h>
15#include <linux/device.h>
16#include <linux/poll.h>
17
18#include <asm/uaccess.h>
19#include <asm/semaphore.h>
20#include <asm/atomic.h>
21#include <asm/ebcdic.h>
22
23#include "dasd_int.h"
24#include "dasd_eckd.h"
25
26#ifdef PRINTK_HEADER
27#undef PRINTK_HEADER
28#endif /* PRINTK_HEADER */
29#define PRINTK_HEADER "dasd(eer):"
30
31/*
32 * SECTION: the internal buffer
33 */
34
35/*
36 * The internal buffer is meant to store obaque blobs of data, so it does
37 * not know of higher level concepts like triggers.
38 * It consists of a number of pages that are used as a ringbuffer. Each data
39 * blob is stored in a simple record that consists of an integer, which
40 * contains the size of the following data, and the data bytes themselfes.
41 *
42 * To allow for multiple independent readers we create one internal buffer
43 * each time the device is opened and destroy the buffer when the file is
44 * closed again. The number of pages used for this buffer is determined by
45 * the module parmeter eer_pages.
46 *
47 * One record can be written to a buffer by using the functions
48 * - dasd_eer_start_record (one time per record to write the size to the
49 * buffer and reserve the space for the data)
50 * - dasd_eer_write_buffer (one or more times per record to write the data)
51 * The data can be written in several steps but you will have to compute
52 * the total size up front for the invocation of dasd_eer_start_record.
53 * If the ringbuffer is full, dasd_eer_start_record will remove the required
54 * number of old records.
55 *
56 * A record is typically read in two steps, first read the integer that
57 * specifies the size of the following data, then read the data.
58 * Both can be done by
59 * - dasd_eer_read_buffer
60 *
61 * For all mentioned functions you need to get the bufferlock first and keep
62 * it until a complete record is written or read.
63 *
64 * All information necessary to keep track of an internal buffer is kept in
65 * a struct eerbuffer. The buffer specific to a file pointer is strored in
66 * the private_data field of that file. To be able to write data to all
67 * existing buffers, each buffer is also added to the bufferlist.
68 * If the user does not want to read a complete record in one go, we have to
69 * keep track of the rest of the record. residual stores the number of bytes
70 * that are still to deliver. If the rest of the record is invalidated between
71 * two reads then residual will be set to -1 so that the next read will fail.
72 * All entries in the eerbuffer structure are protected with the bufferlock.
73 * To avoid races between writing to a buffer on the one side and creating
74 * and destroying buffers on the other side, the bufferlock must also be used
75 * to protect the bufferlist.
76 */
77
78static int eer_pages = 5;
79module_param(eer_pages, int, S_IRUGO|S_IWUSR);
80
81struct eerbuffer {
82 struct list_head list;
83 char **buffer;
84 int buffersize;
85 int buffer_page_count;
86 int head;
87 int tail;
88 int residual;
89};
90
91static LIST_HEAD(bufferlist);
92static spinlock_t bufferlock = SPIN_LOCK_UNLOCKED;
93static DECLARE_WAIT_QUEUE_HEAD(dasd_eer_read_wait_queue);
94
95/*
96 * How many free bytes are available on the buffer.
97 * Needs to be called with bufferlock held.
98 */
99static int dasd_eer_get_free_bytes(struct eerbuffer *eerb)
100{
101 if (eerb->head < eerb->tail)
102 return eerb->tail - eerb->head - 1;
103 return eerb->buffersize - eerb->head + eerb->tail -1;
104}
105
106/*
107 * How many bytes of buffer space are used.
108 * Needs to be called with bufferlock held.
109 */
110static int dasd_eer_get_filled_bytes(struct eerbuffer *eerb)
111{
112
113 if (eerb->head >= eerb->tail)
114 return eerb->head - eerb->tail;
115 return eerb->buffersize - eerb->tail + eerb->head;
116}
117
118/*
119 * The dasd_eer_write_buffer function just copies count bytes of data
120 * to the buffer. Make sure to call dasd_eer_start_record first, to
121 * make sure that enough free space is available.
122 * Needs to be called with bufferlock held.
123 */
124static void dasd_eer_write_buffer(struct eerbuffer *eerb,
125 char *data, int count)
126{
127
128 unsigned long headindex,localhead;
129 unsigned long rest, len;
130 char *nextdata;
131
132 nextdata = data;
133 rest = count;
134 while (rest > 0) {
135 headindex = eerb->head / PAGE_SIZE;
136 localhead = eerb->head % PAGE_SIZE;
137 len = min(rest, PAGE_SIZE - localhead);
138 memcpy(eerb->buffer[headindex]+localhead, nextdata, len);
139 nextdata += len;
140 rest -= len;
141 eerb->head += len;
142 if (eerb->head == eerb->buffersize)
143 eerb->head = 0; /* wrap around */
144 BUG_ON(eerb->head > eerb->buffersize);
145 }
146}
147
148/*
149 * Needs to be called with bufferlock held.
150 */
151static int dasd_eer_read_buffer(struct eerbuffer *eerb, char *data, int count)
152{
153
154 unsigned long tailindex,localtail;
155 unsigned long rest, len, finalcount;
156 char *nextdata;
157
158 finalcount = min(count, dasd_eer_get_filled_bytes(eerb));
159 nextdata = data;
160 rest = finalcount;
161 while (rest > 0) {
162 tailindex = eerb->tail / PAGE_SIZE;
163 localtail = eerb->tail % PAGE_SIZE;
164 len = min(rest, PAGE_SIZE - localtail);
165 memcpy(nextdata, eerb->buffer[tailindex] + localtail, len);
166 nextdata += len;
167 rest -= len;
168 eerb->tail += len;
169 if (eerb->tail == eerb->buffersize)
170 eerb->tail = 0; /* wrap around */
171 BUG_ON(eerb->tail > eerb->buffersize);
172 }
173 return finalcount;
174}
175
176/*
177 * Whenever you want to write a blob of data to the internal buffer you
178 * have to start by using this function first. It will write the number
179 * of bytes that will be written to the buffer. If necessary it will remove
180 * old records to make room for the new one.
181 * Needs to be called with bufferlock held.
182 */
183static int dasd_eer_start_record(struct eerbuffer *eerb, int count)
184{
185 int tailcount;
186
187 if (count + sizeof(count) > eerb->buffersize)
188 return -ENOMEM;
189 while (dasd_eer_get_free_bytes(eerb) < count + sizeof(count)) {
190 if (eerb->residual > 0) {
191 eerb->tail += eerb->residual;
192 if (eerb->tail >= eerb->buffersize)
193 eerb->tail -= eerb->buffersize;
194 eerb->residual = -1;
195 }
196 dasd_eer_read_buffer(eerb, (char *) &tailcount,
197 sizeof(tailcount));
198 eerb->tail += tailcount;
199 if (eerb->tail >= eerb->buffersize)
200 eerb->tail -= eerb->buffersize;
201 }
202 dasd_eer_write_buffer(eerb, (char*) &count, sizeof(count));
203
204 return 0;
205};
206
207/*
208 * Release pages that are not used anymore.
209 */
210static void dasd_eer_free_buffer_pages(char **buf, int no_pages)
211{
212 int i;
213
214 for (i = 0; i < no_pages; i++)
215 free_page((unsigned long) buf[i]);
216}
217
218/*
219 * Allocate a new set of memory pages.
220 */
221static int dasd_eer_allocate_buffer_pages(char **buf, int no_pages)
222{
223 int i;
224
225 for (i = 0; i < no_pages; i++) {
226 buf[i] = (char *) get_zeroed_page(GFP_KERNEL);
227 if (!buf[i]) {
228 dasd_eer_free_buffer_pages(buf, i);
229 return -ENOMEM;
230 }
231 }
232 return 0;
233}
234
235/*
236 * SECTION: The extended error reporting functionality
237 */
238
239/*
240 * When a DASD device driver wants to report an error, it calls the
241 * function dasd_eer_write and gives the respective trigger ID as
242 * parameter. Currently there are four kinds of triggers:
243 *
244 * DASD_EER_FATALERROR: all kinds of unrecoverable I/O problems
245 * DASD_EER_PPRCSUSPEND: PPRC was suspended
246 * DASD_EER_NOPATH: There is no path to the device left.
247 * DASD_EER_STATECHANGE: The state of the device has changed.
248 *
249 * For the first three triggers all required information can be supplied by
250 * the caller. For these triggers a record is written by the function
251 * dasd_eer_write_standard_trigger.
252 *
253 * The DASD_EER_STATECHANGE trigger is special since a sense subsystem
254 * status ccw need to be executed to gather the necessary sense data first.
255 * The dasd_eer_snss function will queue the SNSS request and the request
256 * callback will then call dasd_eer_write with the DASD_EER_STATCHANGE
257 * trigger.
258 *
259 * To avoid memory allocations at runtime, the necessary memory is allocated
260 * when the extended error reporting is enabled for a device (by
261 * dasd_eer_probe). There is one sense subsystem status request for each
262 * eer enabled DASD device. The presence of the cqr in device->eer_cqr
263 * indicates that eer is enable for the device. The use of the snss request
264 * is protected by the DASD_FLAG_EER_IN_USE bit. When this flag indicates
265 * that the cqr is currently in use, dasd_eer_snss cannot start a second
266 * request but sets the DASD_FLAG_EER_SNSS flag instead. The callback of
267 * the SNSS request will check the bit and call dasd_eer_snss again.
268 */
269
270#define SNSS_DATA_SIZE 44
271
272#define DASD_EER_BUSID_SIZE 10
273struct dasd_eer_header {
274 __u32 total_size;
275 __u32 trigger;
276 __u64 tv_sec;
277 __u64 tv_usec;
278 char busid[DASD_EER_BUSID_SIZE];
279};
280
281/*
282 * The following function can be used for those triggers that have
283 * all necessary data available when the function is called.
284 * If the parameter cqr is not NULL, the chain of requests will be searched
285 * for valid sense data, and all valid sense data sets will be added to
286 * the triggers data.
287 */
288static void dasd_eer_write_standard_trigger(struct dasd_device *device,
289 struct dasd_ccw_req *cqr,
290 int trigger)
291{
292 struct dasd_ccw_req *temp_cqr;
293 int data_size;
294 struct timeval tv;
295 struct dasd_eer_header header;
296 unsigned long flags;
297 struct eerbuffer *eerb;
298
299 /* go through cqr chain and count the valid sense data sets */
300 data_size = 0;
301 for (temp_cqr = cqr; temp_cqr; temp_cqr = temp_cqr->refers)
302 if (temp_cqr->irb.esw.esw0.erw.cons)
303 data_size += 32;
304
305 header.total_size = sizeof(header) + data_size + 4; /* "EOR" */
306 header.trigger = trigger;
307 do_gettimeofday(&tv);
308 header.tv_sec = tv.tv_sec;
309 header.tv_usec = tv.tv_usec;
310 strncpy(header.busid, device->cdev->dev.bus_id, DASD_EER_BUSID_SIZE);
311
312 spin_lock_irqsave(&bufferlock, flags);
313 list_for_each_entry(eerb, &bufferlist, list) {
314 dasd_eer_start_record(eerb, header.total_size);
315 dasd_eer_write_buffer(eerb, (char *) &header, sizeof(header));
316 for (temp_cqr = cqr; temp_cqr; temp_cqr = temp_cqr->refers)
317 if (temp_cqr->irb.esw.esw0.erw.cons)
318 dasd_eer_write_buffer(eerb, cqr->irb.ecw, 32);
319 dasd_eer_write_buffer(eerb, "EOR", 4);
320 }
321 spin_unlock_irqrestore(&bufferlock, flags);
322 wake_up_interruptible(&dasd_eer_read_wait_queue);
323}
324
325/*
326 * This function writes a DASD_EER_STATECHANGE trigger.
327 */
328static void dasd_eer_write_snss_trigger(struct dasd_device *device,
329 struct dasd_ccw_req *cqr,
330 int trigger)
331{
332 int data_size;
333 int snss_rc;
334 struct timeval tv;
335 struct dasd_eer_header header;
336 unsigned long flags;
337 struct eerbuffer *eerb;
338
339 snss_rc = (cqr->status == DASD_CQR_FAILED) ? -EIO : 0;
340 if (snss_rc)
341 data_size = 0;
342 else
343 data_size = SNSS_DATA_SIZE;
344
345 header.total_size = sizeof(header) + data_size + 4; /* "EOR" */
346 header.trigger = DASD_EER_STATECHANGE;
347 do_gettimeofday(&tv);
348 header.tv_sec = tv.tv_sec;
349 header.tv_usec = tv.tv_usec;
350 strncpy(header.busid, device->cdev->dev.bus_id, DASD_EER_BUSID_SIZE);
351
352 spin_lock_irqsave(&bufferlock, flags);
353 list_for_each_entry(eerb, &bufferlist, list) {
354 dasd_eer_start_record(eerb, header.total_size);
355 dasd_eer_write_buffer(eerb, (char *) &header , sizeof(header));
356 if (!snss_rc)
357 dasd_eer_write_buffer(eerb, cqr->data, SNSS_DATA_SIZE);
358 dasd_eer_write_buffer(eerb, "EOR", 4);
359 }
360 spin_unlock_irqrestore(&bufferlock, flags);
361 wake_up_interruptible(&dasd_eer_read_wait_queue);
362}
363
364/*
365 * This function is called for all triggers. It calls the appropriate
366 * function that writes the actual trigger records.
367 */
368void dasd_eer_write(struct dasd_device *device, struct dasd_ccw_req *cqr,
369 unsigned int id)
370{
371 if (!device->eer_cqr)
372 return;
373 switch (id) {
374 case DASD_EER_FATALERROR:
375 case DASD_EER_PPRCSUSPEND:
376 dasd_eer_write_standard_trigger(device, cqr, id);
377 break;
378 case DASD_EER_NOPATH:
379 dasd_eer_write_standard_trigger(device, NULL, id);
380 break;
381 case DASD_EER_STATECHANGE:
382 dasd_eer_write_snss_trigger(device, cqr, id);
383 break;
384 default: /* unknown trigger, so we write it without any sense data */
385 dasd_eer_write_standard_trigger(device, NULL, id);
386 break;
387 }
388}
389EXPORT_SYMBOL(dasd_eer_write);
390
391/*
392 * Start a sense subsystem status request.
393 * Needs to be called with the device held.
394 */
395void dasd_eer_snss(struct dasd_device *device)
396{
397 struct dasd_ccw_req *cqr;
398
399 cqr = device->eer_cqr;
400 if (!cqr) /* Device not eer enabled. */
401 return;
402 if (test_and_set_bit(DASD_FLAG_EER_IN_USE, &device->flags)) {
403 /* Sense subsystem status request in use. */
404 set_bit(DASD_FLAG_EER_SNSS, &device->flags);
405 return;
406 }
407 clear_bit(DASD_FLAG_EER_SNSS, &device->flags);
408 cqr->status = DASD_CQR_QUEUED;
409 list_add(&cqr->list, &device->ccw_queue);
410 dasd_schedule_bh(device);
411}
412
413/*
414 * Callback function for use with sense subsystem status request.
415 */
416static void dasd_eer_snss_cb(struct dasd_ccw_req *cqr, void *data)
417{
418 struct dasd_device *device = cqr->device;
419 unsigned long flags;
420
421 dasd_eer_write(device, cqr, DASD_EER_STATECHANGE);
422 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
423 if (device->eer_cqr == cqr) {
424 clear_bit(DASD_FLAG_EER_IN_USE, &device->flags);
425 if (test_bit(DASD_FLAG_EER_SNSS, &device->flags))
426 /* Another SNSS has been requested in the meantime. */
427 dasd_eer_snss(device);
428 cqr = NULL;
429 }
430 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
431 if (cqr)
432 /*
433 * Extended error recovery has been switched off while
434 * the SNSS request was running. It could even have
435 * been switched off and on again in which case there
436 * is a new ccw in device->eer_cqr. Free the "old"
437 * snss request now.
438 */
439 dasd_kfree_request(cqr, device);
440}
441
442/*
443 * Enable error reporting on a given device.
444 */
445int dasd_eer_enable(struct dasd_device *device)
446{
447 struct dasd_ccw_req *cqr;
448 unsigned long flags;
449
450 if (device->eer_cqr)
451 return 0;
452
453 if (!device->discipline || strcmp(device->discipline->name, "ECKD"))
454 return -EPERM; /* FIXME: -EMEDIUMTYPE ? */
455
456 cqr = dasd_kmalloc_request("ECKD", 1 /* SNSS */,
457 SNSS_DATA_SIZE, device);
458 if (!cqr)
459 return -ENOMEM;
460
461 cqr->device = device;
462 cqr->retries = 255;
463 cqr->expires = 10 * HZ;
464
465 cqr->cpaddr->cmd_code = DASD_ECKD_CCW_SNSS;
466 cqr->cpaddr->count = SNSS_DATA_SIZE;
467 cqr->cpaddr->flags = 0;
468 cqr->cpaddr->cda = (__u32)(addr_t) cqr->data;
469
470 cqr->buildclk = get_clock();
471 cqr->status = DASD_CQR_FILLED;
472 cqr->callback = dasd_eer_snss_cb;
473
474 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
475 if (!device->eer_cqr) {
476 device->eer_cqr = cqr;
477 cqr = NULL;
478 }
479 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
480 if (cqr)
481 dasd_kfree_request(cqr, device);
482 return 0;
483}
484
485/*
486 * Disable error reporting on a given device.
487 */
488void dasd_eer_disable(struct dasd_device *device)
489{
490 struct dasd_ccw_req *cqr;
491 unsigned long flags;
492 int in_use;
493
494 if (!device->eer_cqr)
495 return;
496 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
497 cqr = device->eer_cqr;
498 device->eer_cqr = NULL;
499 clear_bit(DASD_FLAG_EER_SNSS, &device->flags);
500 in_use = test_and_clear_bit(DASD_FLAG_EER_IN_USE, &device->flags);
501 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
502 if (cqr && !in_use)
503 dasd_kfree_request(cqr, device);
504}
505
506/*
507 * SECTION: the device operations
508 */
509
510/*
511 * On the one side we need a lock to access our internal buffer, on the
512 * other side a copy_to_user can sleep. So we need to copy the data we have
513 * to transfer in a readbuffer, which is protected by the readbuffer_mutex.
514 */
515static char readbuffer[PAGE_SIZE];
516static DECLARE_MUTEX(readbuffer_mutex);
517
518static int dasd_eer_open(struct inode *inp, struct file *filp)
519{
520 struct eerbuffer *eerb;
521 unsigned long flags;
522
523 eerb = kzalloc(sizeof(struct eerbuffer), GFP_KERNEL);
524 eerb->buffer_page_count = eer_pages;
525 if (eerb->buffer_page_count < 1 ||
526 eerb->buffer_page_count > INT_MAX / PAGE_SIZE) {
527 kfree(eerb);
528 MESSAGE(KERN_WARNING, "can't open device since module "
529 "parameter eer_pages is smaller then 1 or"
530 " bigger then %d", (int)(INT_MAX / PAGE_SIZE));
531 return -EINVAL;
532 }
533 eerb->buffersize = eerb->buffer_page_count * PAGE_SIZE;
534 eerb->buffer = kmalloc(eerb->buffer_page_count * sizeof(char *),
535 GFP_KERNEL);
536 if (!eerb->buffer) {
537 kfree(eerb);
538 return -ENOMEM;
539 }
540 if (dasd_eer_allocate_buffer_pages(eerb->buffer,
541 eerb->buffer_page_count)) {
542 kfree(eerb->buffer);
543 kfree(eerb);
544 return -ENOMEM;
545 }
546 filp->private_data = eerb;
547 spin_lock_irqsave(&bufferlock, flags);
548 list_add(&eerb->list, &bufferlist);
549 spin_unlock_irqrestore(&bufferlock, flags);
550
551 return nonseekable_open(inp,filp);
552}
553
554static int dasd_eer_close(struct inode *inp, struct file *filp)
555{
556 struct eerbuffer *eerb;
557 unsigned long flags;
558
559 eerb = (struct eerbuffer *) filp->private_data;
560 spin_lock_irqsave(&bufferlock, flags);
561 list_del(&eerb->list);
562 spin_unlock_irqrestore(&bufferlock, flags);
563 dasd_eer_free_buffer_pages(eerb->buffer, eerb->buffer_page_count);
564 kfree(eerb->buffer);
565 kfree(eerb);
566
567 return 0;
568}
569
570static ssize_t dasd_eer_read(struct file *filp, char __user *buf,
571 size_t count, loff_t *ppos)
572{
573 int tc,rc;
574 int tailcount,effective_count;
575 unsigned long flags;
576 struct eerbuffer *eerb;
577
578 eerb = (struct eerbuffer *) filp->private_data;
579 if (down_interruptible(&readbuffer_mutex))
580 return -ERESTARTSYS;
581
582 spin_lock_irqsave(&bufferlock, flags);
583
584 if (eerb->residual < 0) { /* the remainder of this record */
585 /* has been deleted */
586 eerb->residual = 0;
587 spin_unlock_irqrestore(&bufferlock, flags);
588 up(&readbuffer_mutex);
589 return -EIO;
590 } else if (eerb->residual > 0) {
591 /* OK we still have a second half of a record to deliver */
592 effective_count = min(eerb->residual, (int) count);
593 eerb->residual -= effective_count;
594 } else {
595 tc = 0;
596 while (!tc) {
597 tc = dasd_eer_read_buffer(eerb, (char *) &tailcount,
598 sizeof(tailcount));
599 if (!tc) {
600 /* no data available */
601 spin_unlock_irqrestore(&bufferlock, flags);
602 up(&readbuffer_mutex);
603 if (filp->f_flags & O_NONBLOCK)
604 return -EAGAIN;
605 rc = wait_event_interruptible(
606 dasd_eer_read_wait_queue,
607 eerb->head != eerb->tail);
608 if (rc)
609 return rc;
610 if (down_interruptible(&readbuffer_mutex))
611 return -ERESTARTSYS;
612 spin_lock_irqsave(&bufferlock, flags);
613 }
614 }
615 WARN_ON(tc != sizeof(tailcount));
616 effective_count = min(tailcount,(int)count);
617 eerb->residual = tailcount - effective_count;
618 }
619
620 tc = dasd_eer_read_buffer(eerb, readbuffer, effective_count);
621 WARN_ON(tc != effective_count);
622
623 spin_unlock_irqrestore(&bufferlock, flags);
624
625 if (copy_to_user(buf, readbuffer, effective_count)) {
626 up(&readbuffer_mutex);
627 return -EFAULT;
628 }
629
630 up(&readbuffer_mutex);
631 return effective_count;
632}
633
634static unsigned int dasd_eer_poll(struct file *filp, poll_table *ptable)
635{
636 unsigned int mask;
637 unsigned long flags;
638 struct eerbuffer *eerb;
639
640 eerb = (struct eerbuffer *) filp->private_data;
641 poll_wait(filp, &dasd_eer_read_wait_queue, ptable);
642 spin_lock_irqsave(&bufferlock, flags);
643 if (eerb->head != eerb->tail)
644 mask = POLLIN | POLLRDNORM ;
645 else
646 mask = 0;
647 spin_unlock_irqrestore(&bufferlock, flags);
648 return mask;
649}
650
651static struct file_operations dasd_eer_fops = {
652 .open = &dasd_eer_open,
653 .release = &dasd_eer_close,
654 .read = &dasd_eer_read,
655 .poll = &dasd_eer_poll,
656 .owner = THIS_MODULE,
657};
658
659static struct miscdevice dasd_eer_dev = {
660 .minor = MISC_DYNAMIC_MINOR,
661 .name = "dasd_eer",
662 .fops = &dasd_eer_fops,
663};
664
665int __init dasd_eer_init(void)
666{
667 int rc;
668
669 rc = misc_register(&dasd_eer_dev);
670 if (rc) {
671 MESSAGE(KERN_ERR, "%s", "dasd_eer_init could not "
672 "register misc device");
673 return rc;
674 }
675
676 return 0;
677}
678
679void __exit dasd_eer_exit(void)
680{
681 WARN_ON(misc_deregister(&dasd_eer_dev) != 0);
682}
diff --git a/drivers/s390/block/dasd_int.h b/drivers/s390/block/dasd_int.h
index 7cb0b9e78a..4293ba8275 100644
--- a/drivers/s390/block/dasd_int.h
+++ b/drivers/s390/block/dasd_int.h
@@ -69,15 +69,6 @@
69 */ 69 */
70struct dasd_device; 70struct dasd_device;
71 71
72typedef int (*dasd_ioctl_fn_t) (struct block_device *bdev, int no, long args);
73
74struct dasd_ioctl {
75 struct list_head list;
76 struct module *owner;
77 int no;
78 dasd_ioctl_fn_t handler;
79};
80
81typedef enum { 72typedef enum {
82 dasd_era_fatal = -1, /* no chance to recover */ 73 dasd_era_fatal = -1, /* no chance to recover */
83 dasd_era_none = 0, /* don't recover, everything alright */ 74 dasd_era_none = 0, /* don't recover, everything alright */
@@ -272,10 +263,28 @@ struct dasd_discipline {
272 /* i/o control functions. */ 263 /* i/o control functions. */
273 int (*fill_geometry) (struct dasd_device *, struct hd_geometry *); 264 int (*fill_geometry) (struct dasd_device *, struct hd_geometry *);
274 int (*fill_info) (struct dasd_device *, struct dasd_information2_t *); 265 int (*fill_info) (struct dasd_device *, struct dasd_information2_t *);
266 int (*ioctl) (struct dasd_device *, unsigned int, void __user *);
275}; 267};
276 268
277extern struct dasd_discipline *dasd_diag_discipline_pointer; 269extern struct dasd_discipline *dasd_diag_discipline_pointer;
278 270
271
272/*
273 * Notification numbers for extended error reporting notifications:
274 * The DASD_EER_DISABLE notification is sent before a dasd_device (and it's
275 * eer pointer) is freed. The error reporting module needs to do all necessary
276 * cleanup steps.
277 * The DASD_EER_TRIGGER notification sends the actual error reports (triggers).
278 */
279#define DASD_EER_DISABLE 0
280#define DASD_EER_TRIGGER 1
281
282/* Trigger IDs for extended error reporting DASD_EER_TRIGGER notification */
283#define DASD_EER_FATALERROR 1
284#define DASD_EER_NOPATH 2
285#define DASD_EER_STATECHANGE 3
286#define DASD_EER_PPRCSUSPEND 4
287
279struct dasd_device { 288struct dasd_device {
280 /* Block device stuff. */ 289 /* Block device stuff. */
281 struct gendisk *gdp; 290 struct gendisk *gdp;
@@ -289,6 +298,9 @@ struct dasd_device {
289 unsigned long flags; /* per device flags */ 298 unsigned long flags; /* per device flags */
290 unsigned short features; /* copy of devmap-features (read-only!) */ 299 unsigned short features; /* copy of devmap-features (read-only!) */
291 300
301 /* extended error reporting stuff (eer) */
302 struct dasd_ccw_req *eer_cqr;
303
292 /* Device discipline stuff. */ 304 /* Device discipline stuff. */
293 struct dasd_discipline *discipline; 305 struct dasd_discipline *discipline;
294 struct dasd_discipline *base_discipline; 306 struct dasd_discipline *base_discipline;
@@ -334,6 +346,8 @@ struct dasd_device {
334/* per device flags */ 346/* per device flags */
335#define DASD_FLAG_DSC_ERROR 2 /* return -EIO when disconnected */ 347#define DASD_FLAG_DSC_ERROR 2 /* return -EIO when disconnected */
336#define DASD_FLAG_OFFLINE 3 /* device is in offline processing */ 348#define DASD_FLAG_OFFLINE 3 /* device is in offline processing */
349#define DASD_FLAG_EER_SNSS 4 /* A SNSS is required */
350#define DASD_FLAG_EER_IN_USE 5 /* A SNSS request is running */
337 351
338void dasd_put_device_wake(struct dasd_device *); 352void dasd_put_device_wake(struct dasd_device *);
339 353
@@ -523,10 +537,6 @@ int dasd_scan_partitions(struct dasd_device *);
523void dasd_destroy_partitions(struct dasd_device *); 537void dasd_destroy_partitions(struct dasd_device *);
524 538
525/* externals in dasd_ioctl.c */ 539/* externals in dasd_ioctl.c */
526int dasd_ioctl_init(void);
527void dasd_ioctl_exit(void);
528int dasd_ioctl_no_register(struct module *, int, dasd_ioctl_fn_t);
529int dasd_ioctl_no_unregister(struct module *, int, dasd_ioctl_fn_t);
530int dasd_ioctl(struct inode *, struct file *, unsigned int, unsigned long); 540int dasd_ioctl(struct inode *, struct file *, unsigned int, unsigned long);
531long dasd_compat_ioctl(struct file *, unsigned int, unsigned long); 541long dasd_compat_ioctl(struct file *, unsigned int, unsigned long);
532 542
@@ -557,6 +567,30 @@ dasd_era_t dasd_9336_erp_examine(struct dasd_ccw_req *, struct irb *);
557dasd_era_t dasd_9343_erp_examine(struct dasd_ccw_req *, struct irb *); 567dasd_era_t dasd_9343_erp_examine(struct dasd_ccw_req *, struct irb *);
558struct dasd_ccw_req *dasd_9343_erp_action(struct dasd_ccw_req *); 568struct dasd_ccw_req *dasd_9343_erp_action(struct dasd_ccw_req *);
559 569
570/* externals in dasd_eer.c */
571#ifdef CONFIG_DASD_EER
572int dasd_eer_init(void);
573void dasd_eer_exit(void);
574int dasd_eer_enable(struct dasd_device *);
575void dasd_eer_disable(struct dasd_device *);
576void dasd_eer_write(struct dasd_device *, struct dasd_ccw_req *cqr,
577 unsigned int id);
578void dasd_eer_snss(struct dasd_device *);
579
580static inline int dasd_eer_enabled(struct dasd_device *device)
581{
582 return device->eer_cqr != NULL;
583}
584#else
585#define dasd_eer_init() (0)
586#define dasd_eer_exit() do { } while (0)
587#define dasd_eer_enable(d) (0)
588#define dasd_eer_disable(d) do { } while (0)
589#define dasd_eer_write(d,c,i) do { } while (0)
590#define dasd_eer_snss(d) do { } while (0)
591#define dasd_eer_enabled(d) (0)
592#endif /* CONFIG_DASD_ERR */
593
560#endif /* __KERNEL__ */ 594#endif /* __KERNEL__ */
561 595
562#endif /* DASD_H */ 596#endif /* DASD_H */
diff --git a/drivers/s390/block/dasd_ioctl.c b/drivers/s390/block/dasd_ioctl.c
index fafeeae526..b8c80d28df 100644
--- a/drivers/s390/block/dasd_ioctl.c
+++ b/drivers/s390/block/dasd_ioctl.c
@@ -16,6 +16,7 @@
16#include <linux/blkpg.h> 16#include <linux/blkpg.h>
17 17
18#include <asm/ccwdev.h> 18#include <asm/ccwdev.h>
19#include <asm/cmb.h>
19#include <asm/uaccess.h> 20#include <asm/uaccess.h>
20 21
21/* This is ugly... */ 22/* This is ugly... */
@@ -23,116 +24,12 @@
23 24
24#include "dasd_int.h" 25#include "dasd_int.h"
25 26
26/*
27 * SECTION: ioctl functions.
28 */
29static struct list_head dasd_ioctl_list = LIST_HEAD_INIT(dasd_ioctl_list);
30
31/*
32 * Find the ioctl with number no.
33 */
34static struct dasd_ioctl *
35dasd_find_ioctl(int no)
36{
37 struct dasd_ioctl *ioctl;
38
39 list_for_each_entry (ioctl, &dasd_ioctl_list, list)
40 if (ioctl->no == no)
41 return ioctl;
42 return NULL;
43}
44
45/*
46 * Register ioctl with number no.
47 */
48int
49dasd_ioctl_no_register(struct module *owner, int no, dasd_ioctl_fn_t handler)
50{
51 struct dasd_ioctl *new;
52 if (dasd_find_ioctl(no))
53 return -EBUSY;
54 new = kmalloc(sizeof (struct dasd_ioctl), GFP_KERNEL);
55 if (new == NULL)
56 return -ENOMEM;
57 new->owner = owner;
58 new->no = no;
59 new->handler = handler;
60 list_add(&new->list, &dasd_ioctl_list);
61 return 0;
62}
63
64/*
65 * Deregister ioctl with number no.
66 */
67int
68dasd_ioctl_no_unregister(struct module *owner, int no, dasd_ioctl_fn_t handler)
69{
70 struct dasd_ioctl *old = dasd_find_ioctl(no);
71 if (old == NULL)
72 return -ENOENT;
73 if (old->no != no || old->handler != handler || owner != old->owner)
74 return -EINVAL;
75 list_del(&old->list);
76 kfree(old);
77 return 0;
78}
79
80int
81dasd_ioctl(struct inode *inp, struct file *filp,
82 unsigned int no, unsigned long data)
83{
84 struct block_device *bdev = inp->i_bdev;
85 struct dasd_device *device = bdev->bd_disk->private_data;
86 struct dasd_ioctl *ioctl;
87 const char *dir;
88 int rc;
89
90 if ((_IOC_DIR(no) != _IOC_NONE) && (data == 0)) {
91 PRINT_DEBUG("empty data ptr");
92 return -EINVAL;
93 }
94 dir = _IOC_DIR (no) == _IOC_NONE ? "0" :
95 _IOC_DIR (no) == _IOC_READ ? "r" :
96 _IOC_DIR (no) == _IOC_WRITE ? "w" :
97 _IOC_DIR (no) == (_IOC_READ | _IOC_WRITE) ? "rw" : "u";
98 DBF_DEV_EVENT(DBF_DEBUG, device,
99 "ioctl 0x%08x %s'0x%x'%d(%d) with data %8lx", no,
100 dir, _IOC_TYPE(no), _IOC_NR(no), _IOC_SIZE(no), data);
101 /* Search for ioctl no in the ioctl list. */
102 list_for_each_entry(ioctl, &dasd_ioctl_list, list) {
103 if (ioctl->no == no) {
104 /* Found a matching ioctl. Call it. */
105 if (!try_module_get(ioctl->owner))
106 continue;
107 rc = ioctl->handler(bdev, no, data);
108 module_put(ioctl->owner);
109 return rc;
110 }
111 }
112 /* No ioctl with number no. */
113 DBF_DEV_EVENT(DBF_INFO, device,
114 "unknown ioctl 0x%08x=%s'0x%x'%d(%d) data %8lx", no,
115 dir, _IOC_TYPE(no), _IOC_NR(no), _IOC_SIZE(no), data);
116 return -EINVAL;
117}
118
119long
120dasd_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
121{
122 int rval;
123
124 lock_kernel();
125 rval = dasd_ioctl(filp->f_dentry->d_inode, filp, cmd, arg);
126 unlock_kernel();
127
128 return (rval == -EINVAL) ? -ENOIOCTLCMD : rval;
129}
130 27
131static int 28static int
132dasd_ioctl_api_version(struct block_device *bdev, int no, long args) 29dasd_ioctl_api_version(void __user *argp)
133{ 30{
134 int ver = DASD_API_VERSION; 31 int ver = DASD_API_VERSION;
135 return put_user(ver, (int __user *) args); 32 return put_user(ver, (int __user *)argp);
136} 33}
137 34
138/* 35/*
@@ -140,20 +37,18 @@ dasd_ioctl_api_version(struct block_device *bdev, int no, long args)
140 * used by dasdfmt after BIODASDDISABLE to retrigger blocksize detection 37 * used by dasdfmt after BIODASDDISABLE to retrigger blocksize detection
141 */ 38 */
142static int 39static int
143dasd_ioctl_enable(struct block_device *bdev, int no, long args) 40dasd_ioctl_enable(struct block_device *bdev)
144{ 41{
145 struct dasd_device *device; 42 struct dasd_device *device = bdev->bd_disk->private_data;
146 43
147 if (!capable(CAP_SYS_ADMIN)) 44 if (!capable(CAP_SYS_ADMIN))
148 return -EACCES; 45 return -EACCES;
149 device = bdev->bd_disk->private_data; 46
150 if (device == NULL)
151 return -ENODEV;
152 dasd_enable_device(device); 47 dasd_enable_device(device);
153 /* Formatting the dasd device can change the capacity. */ 48 /* Formatting the dasd device can change the capacity. */
154 down(&bdev->bd_sem); 49 mutex_lock(&bdev->bd_mutex);
155 i_size_write(bdev->bd_inode, (loff_t)get_capacity(device->gdp) << 9); 50 i_size_write(bdev->bd_inode, (loff_t)get_capacity(device->gdp) << 9);
156 up(&bdev->bd_sem); 51 mutex_unlock(&bdev->bd_mutex);
157 return 0; 52 return 0;
158} 53}
159 54
@@ -162,15 +57,13 @@ dasd_ioctl_enable(struct block_device *bdev, int no, long args)
162 * Used by dasdfmt. Disable I/O operations but allow ioctls. 57 * Used by dasdfmt. Disable I/O operations but allow ioctls.
163 */ 58 */
164static int 59static int
165dasd_ioctl_disable(struct block_device *bdev, int no, long args) 60dasd_ioctl_disable(struct block_device *bdev)
166{ 61{
167 struct dasd_device *device; 62 struct dasd_device *device = bdev->bd_disk->private_data;
168 63
169 if (!capable(CAP_SYS_ADMIN)) 64 if (!capable(CAP_SYS_ADMIN))
170 return -EACCES; 65 return -EACCES;
171 device = bdev->bd_disk->private_data; 66
172 if (device == NULL)
173 return -ENODEV;
174 /* 67 /*
175 * Man this is sick. We don't do a real disable but only downgrade 68 * Man this is sick. We don't do a real disable but only downgrade
176 * the device to DASD_STATE_BASIC. The reason is that dasdfmt uses 69 * the device to DASD_STATE_BASIC. The reason is that dasdfmt uses
@@ -184,9 +77,9 @@ dasd_ioctl_disable(struct block_device *bdev, int no, long args)
184 * Set i_size to zero, since read, write, etc. check against this 77 * Set i_size to zero, since read, write, etc. check against this
185 * value. 78 * value.
186 */ 79 */
187 down(&bdev->bd_sem); 80 mutex_lock(&bdev->bd_mutex);
188 i_size_write(bdev->bd_inode, 0); 81 i_size_write(bdev->bd_inode, 0);
189 up(&bdev->bd_sem); 82 mutex_unlock(&bdev->bd_mutex);
190 return 0; 83 return 0;
191} 84}
192 85
@@ -194,18 +87,13 @@ dasd_ioctl_disable(struct block_device *bdev, int no, long args)
194 * Quiesce device. 87 * Quiesce device.
195 */ 88 */
196static int 89static int
197dasd_ioctl_quiesce(struct block_device *bdev, int no, long args) 90dasd_ioctl_quiesce(struct dasd_device *device)
198{ 91{
199 struct dasd_device *device;
200 unsigned long flags; 92 unsigned long flags;
201 93
202 if (!capable (CAP_SYS_ADMIN)) 94 if (!capable (CAP_SYS_ADMIN))
203 return -EACCES; 95 return -EACCES;
204 96
205 device = bdev->bd_disk->private_data;
206 if (device == NULL)
207 return -ENODEV;
208
209 DEV_MESSAGE (KERN_DEBUG, device, "%s", 97 DEV_MESSAGE (KERN_DEBUG, device, "%s",
210 "Quiesce IO on device"); 98 "Quiesce IO on device");
211 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags); 99 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
@@ -219,18 +107,13 @@ dasd_ioctl_quiesce(struct block_device *bdev, int no, long args)
219 * Quiesce device. 107 * Quiesce device.
220 */ 108 */
221static int 109static int
222dasd_ioctl_resume(struct block_device *bdev, int no, long args) 110dasd_ioctl_resume(struct dasd_device *device)
223{ 111{
224 struct dasd_device *device;
225 unsigned long flags; 112 unsigned long flags;
226 113
227 if (!capable (CAP_SYS_ADMIN)) 114 if (!capable (CAP_SYS_ADMIN))
228 return -EACCES; 115 return -EACCES;
229 116
230 device = bdev->bd_disk->private_data;
231 if (device == NULL)
232 return -ENODEV;
233
234 DEV_MESSAGE (KERN_DEBUG, device, "%s", 117 DEV_MESSAGE (KERN_DEBUG, device, "%s",
235 "resume IO on device"); 118 "resume IO on device");
236 119
@@ -302,25 +185,19 @@ dasd_format(struct dasd_device * device, struct format_data_t * fdata)
302 * Format device. 185 * Format device.
303 */ 186 */
304static int 187static int
305dasd_ioctl_format(struct block_device *bdev, int no, long args) 188dasd_ioctl_format(struct block_device *bdev, void __user *argp)
306{ 189{
307 struct dasd_device *device; 190 struct dasd_device *device = bdev->bd_disk->private_data;
308 struct format_data_t fdata; 191 struct format_data_t fdata;
309 192
310 if (!capable(CAP_SYS_ADMIN)) 193 if (!capable(CAP_SYS_ADMIN))
311 return -EACCES; 194 return -EACCES;
312 if (!args) 195 if (!argp)
313 return -EINVAL; 196 return -EINVAL;
314 /* fdata == NULL is no longer a valid arg to dasd_format ! */
315 device = bdev->bd_disk->private_data;
316
317 if (device == NULL)
318 return -ENODEV;
319 197
320 if (device->features & DASD_FEATURE_READONLY) 198 if (device->features & DASD_FEATURE_READONLY)
321 return -EROFS; 199 return -EROFS;
322 if (copy_from_user(&fdata, (void __user *) args, 200 if (copy_from_user(&fdata, argp, sizeof(struct format_data_t)))
323 sizeof (struct format_data_t)))
324 return -EFAULT; 201 return -EFAULT;
325 if (bdev != bdev->bd_contains) { 202 if (bdev != bdev->bd_contains) {
326 DEV_MESSAGE(KERN_WARNING, device, "%s", 203 DEV_MESSAGE(KERN_WARNING, device, "%s",
@@ -335,17 +212,8 @@ dasd_ioctl_format(struct block_device *bdev, int no, long args)
335 * Reset device profile information 212 * Reset device profile information
336 */ 213 */
337static int 214static int
338dasd_ioctl_reset_profile(struct block_device *bdev, int no, long args) 215dasd_ioctl_reset_profile(struct dasd_device *device)
339{ 216{
340 struct dasd_device *device;
341
342 if (!capable(CAP_SYS_ADMIN))
343 return -EACCES;
344
345 device = bdev->bd_disk->private_data;
346 if (device == NULL)
347 return -ENODEV;
348
349 memset(&device->profile, 0, sizeof (struct dasd_profile_info_t)); 217 memset(&device->profile, 0, sizeof (struct dasd_profile_info_t));
350 return 0; 218 return 0;
351} 219}
@@ -354,31 +222,24 @@ dasd_ioctl_reset_profile(struct block_device *bdev, int no, long args)
354 * Return device profile information 222 * Return device profile information
355 */ 223 */
356static int 224static int
357dasd_ioctl_read_profile(struct block_device *bdev, int no, long args) 225dasd_ioctl_read_profile(struct dasd_device *device, void __user *argp)
358{ 226{
359 struct dasd_device *device;
360
361 device = bdev->bd_disk->private_data;
362 if (device == NULL)
363 return -ENODEV;
364
365 if (dasd_profile_level == DASD_PROFILE_OFF) 227 if (dasd_profile_level == DASD_PROFILE_OFF)
366 return -EIO; 228 return -EIO;
367 229 if (copy_to_user(argp, &device->profile,
368 if (copy_to_user((long __user *) args, (long *) &device->profile,
369 sizeof (struct dasd_profile_info_t))) 230 sizeof (struct dasd_profile_info_t)))
370 return -EFAULT; 231 return -EFAULT;
371 return 0; 232 return 0;
372} 233}
373#else 234#else
374static int 235static int
375dasd_ioctl_reset_profile(struct block_device *bdev, int no, long args) 236dasd_ioctl_reset_profile(struct dasd_device *device)
376{ 237{
377 return -ENOSYS; 238 return -ENOSYS;
378} 239}
379 240
380static int 241static int
381dasd_ioctl_read_profile(struct block_device *bdev, int no, long args) 242dasd_ioctl_read_profile(struct dasd_device *device, void __user *argp)
382{ 243{
383 return -ENOSYS; 244 return -ENOSYS;
384} 245}
@@ -388,22 +249,18 @@ dasd_ioctl_read_profile(struct block_device *bdev, int no, long args)
388 * Return dasd information. Used for BIODASDINFO and BIODASDINFO2. 249 * Return dasd information. Used for BIODASDINFO and BIODASDINFO2.
389 */ 250 */
390static int 251static int
391dasd_ioctl_information(struct block_device *bdev, int no, long args) 252dasd_ioctl_information(struct dasd_device *device,
253 unsigned int cmd, void __user *argp)
392{ 254{
393 struct dasd_device *device;
394 struct dasd_information2_t *dasd_info; 255 struct dasd_information2_t *dasd_info;
395 unsigned long flags; 256 unsigned long flags;
396 int rc; 257 int rc;
397 struct ccw_device *cdev; 258 struct ccw_device *cdev;
398 259
399 device = bdev->bd_disk->private_data;
400 if (device == NULL)
401 return -ENODEV;
402
403 if (!device->discipline->fill_info) 260 if (!device->discipline->fill_info)
404 return -EINVAL; 261 return -EINVAL;
405 262
406 dasd_info = kmalloc(sizeof(struct dasd_information2_t), GFP_KERNEL); 263 dasd_info = kzalloc(sizeof(struct dasd_information2_t), GFP_KERNEL);
407 if (dasd_info == NULL) 264 if (dasd_info == NULL)
408 return -ENOMEM; 265 return -ENOMEM;
409 266
@@ -446,8 +303,7 @@ dasd_ioctl_information(struct block_device *bdev, int no, long args)
446 memcpy(dasd_info->type, device->discipline->name, 4); 303 memcpy(dasd_info->type, device->discipline->name, 4);
447 else 304 else
448 memcpy(dasd_info->type, "none", 4); 305 memcpy(dasd_info->type, "none", 4);
449 dasd_info->req_queue_len = 0; 306
450 dasd_info->chanq_len = 0;
451 if (device->request_queue->request_fn) { 307 if (device->request_queue->request_fn) {
452 struct list_head *l; 308 struct list_head *l;
453#ifdef DASD_EXTENDED_PROFILING 309#ifdef DASD_EXTENDED_PROFILING
@@ -467,8 +323,8 @@ dasd_ioctl_information(struct block_device *bdev, int no, long args)
467 } 323 }
468 324
469 rc = 0; 325 rc = 0;
470 if (copy_to_user((long __user *) args, (long *) dasd_info, 326 if (copy_to_user(argp, dasd_info,
471 ((no == (unsigned int) BIODASDINFO2) ? 327 ((cmd == (unsigned int) BIODASDINFO2) ?
472 sizeof (struct dasd_information2_t) : 328 sizeof (struct dasd_information2_t) :
473 sizeof (struct dasd_information_t)))) 329 sizeof (struct dasd_information_t))))
474 rc = -EFAULT; 330 rc = -EFAULT;
@@ -480,69 +336,103 @@ dasd_ioctl_information(struct block_device *bdev, int no, long args)
480 * Set read only 336 * Set read only
481 */ 337 */
482static int 338static int
483dasd_ioctl_set_ro(struct block_device *bdev, int no, long args) 339dasd_ioctl_set_ro(struct block_device *bdev, void __user *argp)
484{ 340{
485 struct dasd_device *device; 341 struct dasd_device *device = bdev->bd_disk->private_data;
486 int intval, rc; 342 int intval;
487 343
488 if (!capable(CAP_SYS_ADMIN)) 344 if (!capable(CAP_SYS_ADMIN))
489 return -EACCES; 345 return -EACCES;
490 if (bdev != bdev->bd_contains) 346 if (bdev != bdev->bd_contains)
491 // ro setting is not allowed for partitions 347 // ro setting is not allowed for partitions
492 return -EINVAL; 348 return -EINVAL;
493 if (get_user(intval, (int __user *) args)) 349 if (get_user(intval, (int *)argp))
494 return -EFAULT; 350 return -EFAULT;
495 device = bdev->bd_disk->private_data;
496 if (device == NULL)
497 return -ENODEV;
498 351
499 set_disk_ro(bdev->bd_disk, intval); 352 set_disk_ro(bdev->bd_disk, intval);
500 rc = dasd_set_feature(device->cdev, DASD_FEATURE_READONLY, intval); 353 return dasd_set_feature(device->cdev, DASD_FEATURE_READONLY, intval);
501
502 return rc;
503} 354}
504 355
505/* 356static int
506 * List of static ioctls. 357dasd_ioctl_readall_cmb(struct dasd_device *device, unsigned int cmd,
507 */ 358 unsigned long arg)
508static struct { int no; dasd_ioctl_fn_t fn; } dasd_ioctls[] =
509{ 359{
510 { BIODASDDISABLE, dasd_ioctl_disable }, 360 struct cmbdata __user *argp = (void __user *) arg;
511 { BIODASDENABLE, dasd_ioctl_enable }, 361 size_t size = _IOC_SIZE(cmd);
512 { BIODASDQUIESCE, dasd_ioctl_quiesce }, 362 struct cmbdata data;
513 { BIODASDRESUME, dasd_ioctl_resume }, 363 int ret;
514 { BIODASDFMT, dasd_ioctl_format }, 364
515 { BIODASDINFO, dasd_ioctl_information }, 365 ret = cmf_readall(device->cdev, &data);
516 { BIODASDINFO2, dasd_ioctl_information }, 366 if (!ret && copy_to_user(argp, &data, min(size, sizeof(*argp))))
517 { BIODASDPRRD, dasd_ioctl_read_profile }, 367 return -EFAULT;
518 { BIODASDPRRST, dasd_ioctl_reset_profile }, 368 return ret;
519 { BLKROSET, dasd_ioctl_set_ro }, 369}
520 { DASDAPIVER, dasd_ioctl_api_version },
521 { -1, NULL }
522};
523 370
524int 371int
525dasd_ioctl_init(void) 372dasd_ioctl(struct inode *inode, struct file *file,
373 unsigned int cmd, unsigned long arg)
526{ 374{
527 int i; 375 struct block_device *bdev = inode->i_bdev;
376 struct dasd_device *device = bdev->bd_disk->private_data;
377 void __user *argp = (void __user *)arg;
528 378
529 for (i = 0; dasd_ioctls[i].no != -1; i++) 379 if (!device)
530 dasd_ioctl_no_register(NULL, dasd_ioctls[i].no, 380 return -ENODEV;
531 dasd_ioctls[i].fn); 381
532 return 0; 382 if ((_IOC_DIR(cmd) != _IOC_NONE) && !arg) {
383 PRINT_DEBUG("empty data ptr");
384 return -EINVAL;
385 }
533 386
387 switch (cmd) {
388 case BIODASDDISABLE:
389 return dasd_ioctl_disable(bdev);
390 case BIODASDENABLE:
391 return dasd_ioctl_enable(bdev);
392 case BIODASDQUIESCE:
393 return dasd_ioctl_quiesce(device);
394 case BIODASDRESUME:
395 return dasd_ioctl_resume(device);
396 case BIODASDFMT:
397 return dasd_ioctl_format(bdev, argp);
398 case BIODASDINFO:
399 return dasd_ioctl_information(device, cmd, argp);
400 case BIODASDINFO2:
401 return dasd_ioctl_information(device, cmd, argp);
402 case BIODASDPRRD:
403 return dasd_ioctl_read_profile(device, argp);
404 case BIODASDPRRST:
405 return dasd_ioctl_reset_profile(device);
406 case BLKROSET:
407 return dasd_ioctl_set_ro(bdev, argp);
408 case DASDAPIVER:
409 return dasd_ioctl_api_version(argp);
410 case BIODASDCMFENABLE:
411 return enable_cmf(device->cdev);
412 case BIODASDCMFDISABLE:
413 return disable_cmf(device->cdev);
414 case BIODASDREADALLCMB:
415 return dasd_ioctl_readall_cmb(device, cmd, arg);
416 default:
417 /* if the discipline has an ioctl method try it. */
418 if (device->discipline->ioctl) {
419 int rval = device->discipline->ioctl(device, cmd, argp);
420 if (rval != -ENOIOCTLCMD)
421 return rval;
422 }
423
424 return -EINVAL;
425 }
534} 426}
535 427
536void 428long
537dasd_ioctl_exit(void) 429dasd_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
538{ 430{
539 int i; 431 int rval;
540 432
541 for (i = 0; dasd_ioctls[i].no != -1; i++) 433 lock_kernel();
542 dasd_ioctl_no_unregister(NULL, dasd_ioctls[i].no, 434 rval = dasd_ioctl(filp->f_dentry->d_inode, filp, cmd, arg);
543 dasd_ioctls[i].fn); 435 unlock_kernel();
544 436
437 return (rval == -EINVAL) ? -ENOIOCTLCMD : rval;
545} 438}
546
547EXPORT_SYMBOL(dasd_ioctl_no_register);
548EXPORT_SYMBOL(dasd_ioctl_no_unregister);
diff --git a/drivers/s390/block/dcssblk.c b/drivers/s390/block/dcssblk.c
index 44133250da..be9b05347b 100644
--- a/drivers/s390/block/dcssblk.c
+++ b/drivers/s390/block/dcssblk.c
@@ -388,12 +388,11 @@ dcssblk_add_store(struct device *dev, struct device_attribute *attr, const char
388 /* 388 /*
389 * get a struct dcssblk_dev_info 389 * get a struct dcssblk_dev_info
390 */ 390 */
391 dev_info = kmalloc(sizeof(struct dcssblk_dev_info), GFP_KERNEL); 391 dev_info = kzalloc(sizeof(struct dcssblk_dev_info), GFP_KERNEL);
392 if (dev_info == NULL) { 392 if (dev_info == NULL) {
393 rc = -ENOMEM; 393 rc = -ENOMEM;
394 goto out; 394 goto out;
395 } 395 }
396 memset(dev_info, 0, sizeof(struct dcssblk_dev_info));
397 396
398 strcpy(dev_info->segment_name, local_buf); 397 strcpy(dev_info->segment_name, local_buf);
399 strlcpy(dev_info->dev.bus_id, local_buf, BUS_ID_SIZE); 398 strlcpy(dev_info->dev.bus_id, local_buf, BUS_ID_SIZE);
diff --git a/drivers/s390/char/Makefile b/drivers/s390/char/Makefile
index 6377a96735..0c0162ff6c 100644
--- a/drivers/s390/char/Makefile
+++ b/drivers/s390/char/Makefile
@@ -26,4 +26,5 @@ tape-$(CONFIG_PROC_FS) += tape_proc.o
26tape-objs := tape_core.o tape_std.o tape_char.o $(tape-y) 26tape-objs := tape_core.o tape_std.o tape_char.o $(tape-y)
27obj-$(CONFIG_S390_TAPE) += tape.o tape_class.o 27obj-$(CONFIG_S390_TAPE) += tape.o tape_class.o
28obj-$(CONFIG_S390_TAPE_34XX) += tape_34xx.o 28obj-$(CONFIG_S390_TAPE_34XX) += tape_34xx.o
29obj-$(CONFIG_S390_TAPE_3590) += tape_3590.o
29obj-$(CONFIG_MONREADER) += monreader.o 30obj-$(CONFIG_MONREADER) += monreader.o
diff --git a/drivers/s390/char/fs3270.c b/drivers/s390/char/fs3270.c
index 5f6fa4c678..a6415377bc 100644
--- a/drivers/s390/char/fs3270.c
+++ b/drivers/s390/char/fs3270.c
@@ -368,10 +368,9 @@ fs3270_alloc_view(void)
368{ 368{
369 struct fs3270 *fp; 369 struct fs3270 *fp;
370 370
371 fp = (struct fs3270 *) kmalloc(sizeof(struct fs3270),GFP_KERNEL); 371 fp = kzalloc(sizeof(struct fs3270),GFP_KERNEL);
372 if (!fp) 372 if (!fp)
373 return ERR_PTR(-ENOMEM); 373 return ERR_PTR(-ENOMEM);
374 memset(fp, 0, sizeof(struct fs3270));
375 fp->init = raw3270_request_alloc(0); 374 fp->init = raw3270_request_alloc(0);
376 if (IS_ERR(fp->init)) { 375 if (IS_ERR(fp->init)) {
377 kfree(fp); 376 kfree(fp);
diff --git a/drivers/s390/char/keyboard.c b/drivers/s390/char/keyboard.c
index a317a123da..6badd84034 100644
--- a/drivers/s390/char/keyboard.c
+++ b/drivers/s390/char/keyboard.c
@@ -50,14 +50,12 @@ kbd_alloc(void) {
50 struct kbd_data *kbd; 50 struct kbd_data *kbd;
51 int i, len; 51 int i, len;
52 52
53 kbd = kmalloc(sizeof(struct kbd_data), GFP_KERNEL); 53 kbd = kzalloc(sizeof(struct kbd_data), GFP_KERNEL);
54 if (!kbd) 54 if (!kbd)
55 goto out; 55 goto out;
56 memset(kbd, 0, sizeof(struct kbd_data)); 56 kbd->key_maps = kzalloc(sizeof(key_maps), GFP_KERNEL);
57 kbd->key_maps = kmalloc(sizeof(key_maps), GFP_KERNEL);
58 if (!key_maps) 57 if (!key_maps)
59 goto out_kbd; 58 goto out_kbd;
60 memset(kbd->key_maps, 0, sizeof(key_maps));
61 for (i = 0; i < ARRAY_SIZE(key_maps); i++) { 59 for (i = 0; i < ARRAY_SIZE(key_maps); i++) {
62 if (key_maps[i]) { 60 if (key_maps[i]) {
63 kbd->key_maps[i] = 61 kbd->key_maps[i] =
@@ -68,10 +66,9 @@ kbd_alloc(void) {
68 sizeof(u_short)*NR_KEYS); 66 sizeof(u_short)*NR_KEYS);
69 } 67 }
70 } 68 }
71 kbd->func_table = kmalloc(sizeof(func_table), GFP_KERNEL); 69 kbd->func_table = kzalloc(sizeof(func_table), GFP_KERNEL);
72 if (!kbd->func_table) 70 if (!kbd->func_table)
73 goto out_maps; 71 goto out_maps;
74 memset(kbd->func_table, 0, sizeof(func_table));
75 for (i = 0; i < ARRAY_SIZE(func_table); i++) { 72 for (i = 0; i < ARRAY_SIZE(func_table); i++) {
76 if (func_table[i]) { 73 if (func_table[i]) {
77 len = strlen(func_table[i]) + 1; 74 len = strlen(func_table[i]) + 1;
@@ -82,10 +79,9 @@ kbd_alloc(void) {
82 } 79 }
83 } 80 }
84 kbd->fn_handler = 81 kbd->fn_handler =
85 kmalloc(sizeof(fn_handler_fn *) * NR_FN_HANDLER, GFP_KERNEL); 82 kzalloc(sizeof(fn_handler_fn *) * NR_FN_HANDLER, GFP_KERNEL);
86 if (!kbd->fn_handler) 83 if (!kbd->fn_handler)
87 goto out_func; 84 goto out_func;
88 memset(kbd->fn_handler, 0, sizeof(fn_handler_fn *) * NR_FN_HANDLER);
89 kbd->accent_table = 85 kbd->accent_table =
90 kmalloc(sizeof(struct kbdiacr)*MAX_DIACR, GFP_KERNEL); 86 kmalloc(sizeof(struct kbdiacr)*MAX_DIACR, GFP_KERNEL);
91 if (!kbd->accent_table) 87 if (!kbd->accent_table)
diff --git a/drivers/s390/char/monreader.c b/drivers/s390/char/monreader.c
index 5fd3ad8673..fb7bc9e5ee 100644
--- a/drivers/s390/char/monreader.c
+++ b/drivers/s390/char/monreader.c
@@ -257,14 +257,13 @@ mon_alloc_mem(void)
257 int i,j; 257 int i,j;
258 struct mon_private *monpriv; 258 struct mon_private *monpriv;
259 259
260 monpriv = kmalloc(sizeof(struct mon_private), GFP_KERNEL); 260 monpriv = kzalloc(sizeof(struct mon_private), GFP_KERNEL);
261 if (!monpriv) { 261 if (!monpriv) {
262 P_ERROR("no memory for monpriv\n"); 262 P_ERROR("no memory for monpriv\n");
263 return NULL; 263 return NULL;
264 } 264 }
265 memset(monpriv, 0, sizeof(struct mon_private));
266 for (i = 0; i < MON_MSGLIM; i++) { 265 for (i = 0; i < MON_MSGLIM; i++) {
267 monpriv->msg_array[i] = kmalloc(sizeof(struct mon_msg), 266 monpriv->msg_array[i] = kzalloc(sizeof(struct mon_msg),
268 GFP_KERNEL); 267 GFP_KERNEL);
269 if (!monpriv->msg_array[i]) { 268 if (!monpriv->msg_array[i]) {
270 P_ERROR("open, no memory for msg_array\n"); 269 P_ERROR("open, no memory for msg_array\n");
@@ -272,7 +271,6 @@ mon_alloc_mem(void)
272 kfree(monpriv->msg_array[j]); 271 kfree(monpriv->msg_array[j]);
273 return NULL; 272 return NULL;
274 } 273 }
275 memset(monpriv->msg_array[i], 0, sizeof(struct mon_msg));
276 } 274 }
277 return monpriv; 275 return monpriv;
278} 276}
diff --git a/drivers/s390/char/raw3270.c b/drivers/s390/char/raw3270.c
index 1026f2bc31..bd06607a5d 100644
--- a/drivers/s390/char/raw3270.c
+++ b/drivers/s390/char/raw3270.c
@@ -115,10 +115,9 @@ raw3270_request_alloc(size_t size)
115 struct raw3270_request *rq; 115 struct raw3270_request *rq;
116 116
117 /* Allocate request structure */ 117 /* Allocate request structure */
118 rq = kmalloc(sizeof(struct raw3270_request), GFP_KERNEL | GFP_DMA); 118 rq = kzalloc(sizeof(struct raw3270_request), GFP_KERNEL | GFP_DMA);
119 if (!rq) 119 if (!rq)
120 return ERR_PTR(-ENOMEM); 120 return ERR_PTR(-ENOMEM);
121 memset(rq, 0, sizeof(struct raw3270_request));
122 121
123 /* alloc output buffer. */ 122 /* alloc output buffer. */
124 if (size > 0) { 123 if (size > 0) {
diff --git a/drivers/s390/char/tape.h b/drivers/s390/char/tape.h
index 01d865d937..cd51ace8b6 100644
--- a/drivers/s390/char/tape.h
+++ b/drivers/s390/char/tape.h
@@ -250,6 +250,7 @@ extern void tape_free_request(struct tape_request *);
250extern int tape_do_io(struct tape_device *, struct tape_request *); 250extern int tape_do_io(struct tape_device *, struct tape_request *);
251extern int tape_do_io_async(struct tape_device *, struct tape_request *); 251extern int tape_do_io_async(struct tape_device *, struct tape_request *);
252extern int tape_do_io_interruptible(struct tape_device *, struct tape_request *); 252extern int tape_do_io_interruptible(struct tape_device *, struct tape_request *);
253extern int tape_cancel_io(struct tape_device *, struct tape_request *);
253void tape_hotplug_event(struct tape_device *, int major, int action); 254void tape_hotplug_event(struct tape_device *, int major, int action);
254 255
255static inline int 256static inline int
diff --git a/drivers/s390/char/tape_34xx.c b/drivers/s390/char/tape_34xx.c
index 682039cac1..d4f2da7380 100644
--- a/drivers/s390/char/tape_34xx.c
+++ b/drivers/s390/char/tape_34xx.c
@@ -2,8 +2,7 @@
2 * drivers/s390/char/tape_34xx.c 2 * drivers/s390/char/tape_34xx.c
3 * tape device discipline for 3480/3490 tapes. 3 * tape device discipline for 3480/3490 tapes.
4 * 4 *
5 * S390 and zSeries version 5 * Copyright (C) IBM Corp. 2001,2006
6 * Copyright (C) 2001,2002 IBM Deutschland Entwicklung GmbH, IBM Corporation
7 * Author(s): Carsten Otte <cotte@de.ibm.com> 6 * Author(s): Carsten Otte <cotte@de.ibm.com>
8 * Tuan Ngo-Anh <ngoanh@de.ibm.com> 7 * Tuan Ngo-Anh <ngoanh@de.ibm.com>
9 * Martin Schwidefsky <schwidefsky@de.ibm.com> 8 * Martin Schwidefsky <schwidefsky@de.ibm.com>
@@ -28,11 +27,6 @@
28debug_info_t *TAPE_DBF_AREA = NULL; 27debug_info_t *TAPE_DBF_AREA = NULL;
29EXPORT_SYMBOL(TAPE_DBF_AREA); 28EXPORT_SYMBOL(TAPE_DBF_AREA);
30 29
31enum tape_34xx_type {
32 tape_3480,
33 tape_3490,
34};
35
36#define TAPE34XX_FMT_3480 0 30#define TAPE34XX_FMT_3480 0
37#define TAPE34XX_FMT_3480_2_XF 1 31#define TAPE34XX_FMT_3480_2_XF 1
38#define TAPE34XX_FMT_3480_XF 2 32#define TAPE34XX_FMT_3480_XF 2
diff --git a/drivers/s390/char/tape_3590.c b/drivers/s390/char/tape_3590.c
new file mode 100644
index 0000000000..c3915f60a3
--- /dev/null
+++ b/drivers/s390/char/tape_3590.c
@@ -0,0 +1,1301 @@
1/*
2 * drivers/s390/char/tape_3590.c
3 * tape device discipline for 3590 tapes.
4 *
5 * Copyright (C) IBM Corp. 2001,2006
6 * Author(s): Stefan Bader <shbader@de.ibm.com>
7 * Michael Holzheu <holzheu@de.ibm.com>
8 * Martin Schwidefsky <schwidefsky@de.ibm.com>
9 */
10
11#include <linux/config.h>
12#include <linux/module.h>
13#include <linux/init.h>
14#include <linux/bio.h>
15
16#define TAPE_DBF_AREA tape_3590_dbf
17
18#include "tape.h"
19#include "tape_std.h"
20#include "tape_3590.h"
21
22/*
23 * Pointer to debug area.
24 */
25debug_info_t *TAPE_DBF_AREA = NULL;
26EXPORT_SYMBOL(TAPE_DBF_AREA);
27
28/*******************************************************************
29 * Error Recovery fuctions:
30 * - Read Opposite: implemented
31 * - Read Device (buffered) log: BRA
32 * - Read Library log: BRA
33 * - Swap Devices: BRA
34 * - Long Busy: BRA
35 * - Special Intercept: BRA
36 * - Read Alternate: implemented
37 *******************************************************************/
38
39#define PRINTK_HEADER "TAPE_3590: "
40
41static const char *tape_3590_msg[TAPE_3590_MAX_MSG] = {
42 [0x00] = "",
43 [0x10] = "Lost Sense",
44 [0x11] = "Assigned Elsewhere",
45 [0x12] = "Allegiance Reset",
46 [0x13] = "Shared Access Violation",
47 [0x20] = "Command Reject",
48 [0x21] = "Configuration Error",
49 [0x22] = "Protection Exception",
50 [0x23] = "Write Protect",
51 [0x24] = "Write Length",
52 [0x25] = "Read-Only Format",
53 [0x31] = "Beginning of Partition",
54 [0x33] = "End of Partition",
55 [0x34] = "End of Data",
56 [0x35] = "Block not found",
57 [0x40] = "Device Intervention",
58 [0x41] = "Loader Intervention",
59 [0x42] = "Library Intervention",
60 [0x50] = "Write Error",
61 [0x51] = "Erase Error",
62 [0x52] = "Formatting Error",
63 [0x53] = "Read Error",
64 [0x54] = "Unsupported Format",
65 [0x55] = "No Formatting",
66 [0x56] = "Positioning lost",
67 [0x57] = "Read Length",
68 [0x60] = "Unsupported Medium",
69 [0x61] = "Medium Length Error",
70 [0x62] = "Medium removed",
71 [0x64] = "Load Check",
72 [0x65] = "Unload Check",
73 [0x70] = "Equipment Check",
74 [0x71] = "Bus out Check",
75 [0x72] = "Protocol Error",
76 [0x73] = "Interface Error",
77 [0x74] = "Overrun",
78 [0x75] = "Halt Signal",
79 [0x90] = "Device fenced",
80 [0x91] = "Device Path fenced",
81 [0xa0] = "Volume misplaced",
82 [0xa1] = "Volume inaccessible",
83 [0xa2] = "Volume in input",
84 [0xa3] = "Volume ejected",
85 [0xa4] = "All categories reserved",
86 [0xa5] = "Duplicate Volume",
87 [0xa6] = "Library Manager Offline",
88 [0xa7] = "Library Output Station full",
89 [0xa8] = "Vision System non-operational",
90 [0xa9] = "Library Manager Equipment Check",
91 [0xaa] = "Library Equipment Check",
92 [0xab] = "All Library Cells full",
93 [0xac] = "No Cleaner Volumes in Library",
94 [0xad] = "I/O Station door open",
95 [0xae] = "Subsystem environmental alert",
96};
97
98/*
99 * 3590 IOCTL Overload
100 */
101static int
102tape_3590_ioctl(struct tape_device *device, unsigned int cmd, unsigned long arg)
103{
104 switch (cmd) {
105 case TAPE390_DISPLAY: {
106 struct display_struct disp;
107
108 if (copy_from_user(&disp, (char __user *) arg, sizeof(disp)))
109 return -EFAULT;
110
111 return tape_std_display(device, &disp);
112 }
113 default:
114 return -EINVAL; /* no additional ioctls */
115 }
116}
117
118/*
119 * SENSE Medium: Get Sense data about medium state
120 */
121static int
122tape_3590_sense_medium(struct tape_device *device)
123{
124 struct tape_request *request;
125
126 request = tape_alloc_request(1, 128);
127 if (IS_ERR(request))
128 return PTR_ERR(request);
129 request->op = TO_MSEN;
130 tape_ccw_end(request->cpaddr, MEDIUM_SENSE, 128, request->cpdata);
131 return tape_do_io_free(device, request);
132}
133
134/*
135 * MTTELL: Tell block. Return the number of block relative to current file.
136 */
137static int
138tape_3590_mttell(struct tape_device *device, int mt_count)
139{
140 __u64 block_id;
141 int rc;
142
143 rc = tape_std_read_block_id(device, &block_id);
144 if (rc)
145 return rc;
146 return block_id >> 32;
147}
148
149/*
150 * MTSEEK: seek to the specified block.
151 */
152static int
153tape_3590_mtseek(struct tape_device *device, int count)
154{
155 struct tape_request *request;
156
157 DBF_EVENT(6, "xsee id: %x\n", count);
158 request = tape_alloc_request(3, 4);
159 if (IS_ERR(request))
160 return PTR_ERR(request);
161 request->op = TO_LBL;
162 tape_ccw_cc(request->cpaddr, MODE_SET_DB, 1, device->modeset_byte);
163 *(__u32 *) request->cpdata = count;
164 tape_ccw_cc(request->cpaddr + 1, LOCATE, 4, request->cpdata);
165 tape_ccw_end(request->cpaddr + 2, NOP, 0, NULL);
166 return tape_do_io_free(device, request);
167}
168
169/*
170 * Read Opposite Error Recovery Function:
171 * Used, when Read Forward does not work
172 */
173static void
174tape_3590_read_opposite(struct tape_device *device,
175 struct tape_request *request)
176{
177 struct tape_3590_disc_data *data;
178
179 /*
180 * We have allocated 4 ccws in tape_std_read, so we can now
181 * transform the request to a read backward, followed by a
182 * forward space block.
183 */
184 request->op = TO_RBA;
185 tape_ccw_cc(request->cpaddr, MODE_SET_DB, 1, device->modeset_byte);
186 data = device->discdata;
187 tape_ccw_cc_idal(request->cpaddr + 1, data->read_back_op,
188 device->char_data.idal_buf);
189 tape_ccw_cc(request->cpaddr + 2, FORSPACEBLOCK, 0, NULL);
190 tape_ccw_end(request->cpaddr + 3, NOP, 0, NULL);
191 DBF_EVENT(6, "xrop ccwg\n");
192}
193
194/*
195 * Read Attention Msg
196 * This should be done after an interrupt with attention bit (0x80)
197 * in device state.
198 *
199 * After a "read attention message" request there are two possible
200 * results:
201 *
202 * 1. A unit check is presented, when attention sense is present (e.g. when
203 * a medium has been unloaded). The attention sense comes then
204 * together with the unit check. The recovery action is either "retry"
205 * (in case there is an attention message pending) or "permanent error".
206 *
207 * 2. The attention msg is written to the "read subsystem data" buffer.
208 * In this case we probably should print it to the console.
209 */
210static int
211tape_3590_read_attmsg(struct tape_device *device)
212{
213 struct tape_request *request;
214 char *buf;
215
216 request = tape_alloc_request(3, 4096);
217 if (IS_ERR(request))
218 return PTR_ERR(request);
219 request->op = TO_READ_ATTMSG;
220 buf = request->cpdata;
221 buf[0] = PREP_RD_SS_DATA;
222 buf[6] = RD_ATTMSG; /* read att msg */
223 tape_ccw_cc(request->cpaddr, PERFORM_SS_FUNC, 12, buf);
224 tape_ccw_cc(request->cpaddr + 1, READ_SS_DATA, 4096 - 12, buf + 12);
225 tape_ccw_end(request->cpaddr + 2, NOP, 0, NULL);
226 return tape_do_io_free(device, request);
227}
228
229/*
230 * These functions are used to schedule follow-up actions from within an
231 * interrupt context (like unsolicited interrupts).
232 */
233static void
234tape_3590_work_handler(void *data)
235{
236 struct {
237 struct tape_device *device;
238 enum tape_op op;
239 struct work_struct work;
240 } *p = data;
241
242 switch (p->op) {
243 case TO_MSEN:
244 tape_3590_sense_medium(p->device);
245 break;
246 case TO_READ_ATTMSG:
247 tape_3590_read_attmsg(p->device);
248 break;
249 default:
250 DBF_EVENT(3, "T3590: work handler undefined for "
251 "operation 0x%02x\n", p->op);
252 }
253 tape_put_device(p->device);
254 kfree(p);
255}
256
257static int
258tape_3590_schedule_work(struct tape_device *device, enum tape_op op)
259{
260 struct {
261 struct tape_device *device;
262 enum tape_op op;
263 struct work_struct work;
264 } *p;
265
266 if ((p = kzalloc(sizeof(*p), GFP_ATOMIC)) == NULL)
267 return -ENOMEM;
268
269 INIT_WORK(&p->work, tape_3590_work_handler, p);
270
271 p->device = tape_get_device_reference(device);
272 p->op = op;
273
274 schedule_work(&p->work);
275 return 0;
276}
277
278#ifdef CONFIG_S390_TAPE_BLOCK
279/*
280 * Tape Block READ
281 */
282static struct tape_request *
283tape_3590_bread(struct tape_device *device, struct request *req)
284{
285 struct tape_request *request;
286 struct ccw1 *ccw;
287 int count = 0, start_block, i;
288 unsigned off;
289 char *dst;
290 struct bio_vec *bv;
291 struct bio *bio;
292
293 DBF_EVENT(6, "xBREDid:");
294 start_block = req->sector >> TAPEBLOCK_HSEC_S2B;
295 DBF_EVENT(6, "start_block = %i\n", start_block);
296
297 rq_for_each_bio(bio, req) {
298 bio_for_each_segment(bv, bio, i) {
299 count += bv->bv_len >> (TAPEBLOCK_HSEC_S2B + 9);
300 }
301 }
302 request = tape_alloc_request(2 + count + 1, 4);
303 if (IS_ERR(request))
304 return request;
305 request->op = TO_BLOCK;
306 *(__u32 *) request->cpdata = start_block;
307 ccw = request->cpaddr;
308 ccw = tape_ccw_cc(ccw, MODE_SET_DB, 1, device->modeset_byte);
309
310 /*
311 * We always setup a nop after the mode set ccw. This slot is
312 * used in tape_std_check_locate to insert a locate ccw if the
313 * current tape position doesn't match the start block to be read.
314 */
315 ccw = tape_ccw_cc(ccw, NOP, 0, NULL);
316
317 rq_for_each_bio(bio, req) {
318 bio_for_each_segment(bv, bio, i) {
319 dst = kmap(bv->bv_page) + bv->bv_offset;
320 for (off = 0; off < bv->bv_len;
321 off += TAPEBLOCK_HSEC_SIZE) {
322 ccw->flags = CCW_FLAG_CC;
323 ccw->cmd_code = READ_FORWARD;
324 ccw->count = TAPEBLOCK_HSEC_SIZE;
325 set_normalized_cda(ccw, (void *) __pa(dst));
326 ccw++;
327 dst += TAPEBLOCK_HSEC_SIZE;
328 }
329 if (off > bv->bv_len)
330 BUG();
331 }
332 }
333 ccw = tape_ccw_end(ccw, NOP, 0, NULL);
334 DBF_EVENT(6, "xBREDccwg\n");
335 return request;
336}
337
338static void
339tape_3590_free_bread(struct tape_request *request)
340{
341 struct ccw1 *ccw;
342
343 /* Last ccw is a nop and doesn't need clear_normalized_cda */
344 for (ccw = request->cpaddr; ccw->flags & CCW_FLAG_CC; ccw++)
345 if (ccw->cmd_code == READ_FORWARD)
346 clear_normalized_cda(ccw);
347 tape_free_request(request);
348}
349
350/*
351 * check_locate is called just before the tape request is passed to
352 * the common io layer for execution. It has to check the current
353 * tape position and insert a locate ccw if it doesn't match the
354 * start block for the request.
355 */
356static void
357tape_3590_check_locate(struct tape_device *device, struct tape_request *request)
358{
359 __u32 *start_block;
360
361 start_block = (__u32 *) request->cpdata;
362 if (*start_block != device->blk_data.block_position) {
363 /* Add the start offset of the file to get the real block. */
364 *start_block += device->bof;
365 tape_ccw_cc(request->cpaddr + 1, LOCATE, 4, request->cpdata);
366 }
367}
368#endif
369
370/*
371 * The done handler is called at device/channel end and wakes up the sleeping
372 * process
373 */
374static int
375tape_3590_done(struct tape_device *device, struct tape_request *request)
376{
377 struct tape_3590_med_sense *sense;
378
379 DBF_EVENT(6, "%s done\n", tape_op_verbose[request->op]);
380
381 switch (request->op) {
382 case TO_BSB:
383 case TO_BSF:
384 case TO_DSE:
385 case TO_FSB:
386 case TO_FSF:
387 case TO_LBL:
388 case TO_RFO:
389 case TO_RBA:
390 case TO_REW:
391 case TO_WRI:
392 case TO_WTM:
393 case TO_BLOCK:
394 case TO_LOAD:
395 tape_med_state_set(device, MS_LOADED);
396 break;
397 case TO_RUN:
398 tape_med_state_set(device, MS_UNLOADED);
399 break;
400 case TO_MSEN:
401 sense = (struct tape_3590_med_sense *) request->cpdata;
402 if (sense->masst == MSENSE_UNASSOCIATED)
403 tape_med_state_set(device, MS_UNLOADED);
404 if (sense->masst == MSENSE_ASSOCIATED_MOUNT)
405 tape_med_state_set(device, MS_LOADED);
406 break;
407 case TO_RBI: /* RBI seems to succeed even without medium loaded. */
408 case TO_NOP: /* Same to NOP. */
409 case TO_READ_CONFIG:
410 case TO_READ_ATTMSG:
411 case TO_DIS:
412 case TO_ASSIGN:
413 case TO_UNASSIGN:
414 break;
415 case TO_SIZE:
416 break;
417 }
418 return TAPE_IO_SUCCESS;
419}
420
421/*
422 * This fuction is called, when error recovery was successfull
423 */
424static inline int
425tape_3590_erp_succeded(struct tape_device *device, struct tape_request *request)
426{
427 DBF_EVENT(3, "Error Recovery successfull for %s\n",
428 tape_op_verbose[request->op]);
429 return tape_3590_done(device, request);
430}
431
432/*
433 * This fuction is called, when error recovery was not successfull
434 */
435static inline int
436tape_3590_erp_failed(struct tape_device *device, struct tape_request *request,
437 struct irb *irb, int rc)
438{
439 DBF_EVENT(3, "Error Recovery failed for %s\n",
440 tape_op_verbose[request->op]);
441 tape_dump_sense_dbf(device, request, irb);
442 return rc;
443}
444
445/*
446 * Error Recovery do retry
447 */
448static inline int
449tape_3590_erp_retry(struct tape_device *device, struct tape_request *request,
450 struct irb *irb)
451{
452 DBF_EVENT(2, "Retry: %s\n", tape_op_verbose[request->op]);
453 tape_dump_sense_dbf(device, request, irb);
454 return TAPE_IO_RETRY;
455}
456
457/*
458 * Handle unsolicited interrupts
459 */
460static int
461tape_3590_unsolicited_irq(struct tape_device *device, struct irb *irb)
462{
463 if (irb->scsw.dstat == DEV_STAT_CHN_END)
464 /* Probably result of halt ssch */
465 return TAPE_IO_PENDING;
466 else if (irb->scsw.dstat == 0x85)
467 /* Device Ready -> check medium state */
468 tape_3590_schedule_work(device, TO_MSEN);
469 else if (irb->scsw.dstat & DEV_STAT_ATTENTION)
470 tape_3590_schedule_work(device, TO_READ_ATTMSG);
471 else {
472 DBF_EVENT(3, "unsol.irq! dev end: %08x\n", device->cdev_id);
473 PRINT_WARN("Unsolicited IRQ (Device End) caught.\n");
474 tape_dump_sense(device, NULL, irb);
475 }
476 return TAPE_IO_SUCCESS;
477}
478
479/*
480 * Basic Recovery routine
481 */
482static int
483tape_3590_erp_basic(struct tape_device *device, struct tape_request *request,
484 struct irb *irb, int rc)
485{
486 struct tape_3590_sense *sense;
487
488 sense = (struct tape_3590_sense *) irb->ecw;
489
490 switch (sense->bra) {
491 case SENSE_BRA_PER:
492 return tape_3590_erp_failed(device, request, irb, rc);
493 case SENSE_BRA_CONT:
494 return tape_3590_erp_succeded(device, request);
495 case SENSE_BRA_RE:
496 return tape_3590_erp_retry(device, request, irb);
497 case SENSE_BRA_DRE:
498 return tape_3590_erp_failed(device, request, irb, rc);
499 default:
500 PRINT_ERR("Unknown BRA %x - This should not happen!\n",
501 sense->bra);
502 BUG();
503 return TAPE_IO_STOP;
504 }
505}
506
507/*
508 * RDL: Read Device (buffered) log
509 */
510static int
511tape_3590_erp_read_buf_log(struct tape_device *device,
512 struct tape_request *request, struct irb *irb)
513{
514 /*
515 * We just do the basic error recovery at the moment (retry).
516 * Perhaps in the future, we read the log and dump it somewhere...
517 */
518 return tape_3590_erp_basic(device, request, irb, -EIO);
519}
520
521/*
522 * SWAP: Swap Devices
523 */
524static int
525tape_3590_erp_swap(struct tape_device *device, struct tape_request *request,
526 struct irb *irb)
527{
528 /*
529 * This error recovery should swap the tapes
530 * if the original has a problem. The operation
531 * should proceed with the new tape... this
532 * should probably be done in user space!
533 */
534 PRINT_WARN("(%s): Swap Tape Device!\n", device->cdev->dev.bus_id);
535 return tape_3590_erp_basic(device, request, irb, -EIO);
536}
537
538/*
539 * LBY: Long Busy
540 */
541static int
542tape_3590_erp_long_busy(struct tape_device *device,
543 struct tape_request *request, struct irb *irb)
544{
545 /* FIXME: how about WAITING for a minute ? */
546 PRINT_WARN("(%s): Device is busy! Please wait a minute!\n",
547 device->cdev->dev.bus_id);
548 return tape_3590_erp_basic(device, request, irb, -EBUSY);
549}
550
551/*
552 * SPI: Special Intercept
553 */
554static int
555tape_3590_erp_special_interrupt(struct tape_device *device,
556 struct tape_request *request, struct irb *irb)
557{
558 return tape_3590_erp_basic(device, request, irb, -EIO);
559}
560
561/*
562 * RDA: Read Alternate
563 */
564static int
565tape_3590_erp_read_alternate(struct tape_device *device,
566 struct tape_request *request, struct irb *irb)
567{
568 struct tape_3590_disc_data *data;
569
570 /*
571 * The issued Read Backward or Read Previous command is not
572 * supported by the device
573 * The recovery action should be to issue another command:
574 * Read Revious: if Read Backward is not supported
575 * Read Backward: if Read Previous is not supported
576 */
577 data = device->discdata;
578 if (data->read_back_op == READ_PREVIOUS) {
579 DBF_EVENT(2, "(%08x): No support for READ_PREVIOUS command\n",
580 device->cdev_id);
581 data->read_back_op = READ_BACKWARD;
582 } else {
583 DBF_EVENT(2, "(%08x): No support for READ_BACKWARD command\n",
584 device->cdev_id);
585 data->read_back_op = READ_PREVIOUS;
586 }
587 tape_3590_read_opposite(device, request);
588 return tape_3590_erp_retry(device, request, irb);
589}
590
591/*
592 * Error Recovery read opposite
593 */
594static int
595tape_3590_erp_read_opposite(struct tape_device *device,
596 struct tape_request *request, struct irb *irb)
597{
598 switch (request->op) {
599 case TO_RFO:
600 /*
601 * We did read forward, but the data could not be read.
602 * We will read backward and then skip forward again.
603 */
604 tape_3590_read_opposite(device, request);
605 return tape_3590_erp_retry(device, request, irb);
606 case TO_RBA:
607 /* We tried to read forward and backward, but hat no success */
608 return tape_3590_erp_failed(device, request, irb, -EIO);
609 break;
610 default:
611 PRINT_WARN("read_opposite_recovery_called_with_op: %s\n",
612 tape_op_verbose[request->op]);
613 return tape_3590_erp_failed(device, request, irb, -EIO);
614 }
615}
616
617/*
618 * Print an MIM (Media Information Message) (message code f0)
619 */
620static void
621tape_3590_print_mim_msg_f0(struct tape_device *device, struct irb *irb)
622{
623 struct tape_3590_sense *sense;
624
625 sense = (struct tape_3590_sense *) irb->ecw;
626 /* Exception Message */
627 switch (sense->fmt.f70.emc) {
628 case 0x02:
629 PRINT_WARN("(%s): Data degraded\n", device->cdev->dev.bus_id);
630 break;
631 case 0x03:
632 PRINT_WARN("(%s): Data degraded in partion %i\n",
633 device->cdev->dev.bus_id, sense->fmt.f70.mp);
634 break;
635 case 0x04:
636 PRINT_WARN("(%s): Medium degraded\n", device->cdev->dev.bus_id);
637 break;
638 case 0x05:
639 PRINT_WARN("(%s): Medium degraded in partition %i\n",
640 device->cdev->dev.bus_id, sense->fmt.f70.mp);
641 break;
642 case 0x06:
643 PRINT_WARN("(%s): Block 0 Error\n", device->cdev->dev.bus_id);
644 break;
645 case 0x07:
646 PRINT_WARN("(%s): Medium Exception 0x%02x\n",
647 device->cdev->dev.bus_id, sense->fmt.f70.md);
648 break;
649 default:
650 PRINT_WARN("(%s): MIM ExMsg: 0x%02x\n",
651 device->cdev->dev.bus_id, sense->fmt.f70.emc);
652 break;
653 }
654 /* Service Message */
655 switch (sense->fmt.f70.smc) {
656 case 0x02:
657 PRINT_WARN("(%s): Reference Media maintenance procedure %i\n",
658 device->cdev->dev.bus_id, sense->fmt.f70.md);
659 break;
660 default:
661 PRINT_WARN("(%s): MIM ServiceMsg: 0x%02x\n",
662 device->cdev->dev.bus_id, sense->fmt.f70.smc);
663 break;
664 }
665}
666
667/*
668 * Print an I/O Subsystem Service Information Message (message code f1)
669 */
670static void
671tape_3590_print_io_sim_msg_f1(struct tape_device *device, struct irb *irb)
672{
673 struct tape_3590_sense *sense;
674
675 sense = (struct tape_3590_sense *) irb->ecw;
676 /* Exception Message */
677 switch (sense->fmt.f71.emc) {
678 case 0x01:
679 PRINT_WARN("(%s): Effect of failure is unknown\n",
680 device->cdev->dev.bus_id);
681 break;
682 case 0x02:
683 PRINT_WARN("(%s): CU Exception - no performance impact\n",
684 device->cdev->dev.bus_id);
685 break;
686 case 0x03:
687 PRINT_WARN("(%s): CU Exception on channel interface 0x%02x\n",
688 device->cdev->dev.bus_id, sense->fmt.f71.md[0]);
689 break;
690 case 0x04:
691 PRINT_WARN("(%s): CU Exception on device path 0x%02x\n",
692 device->cdev->dev.bus_id, sense->fmt.f71.md[0]);
693 break;
694 case 0x05:
695 PRINT_WARN("(%s): CU Exception on library path 0x%02x\n",
696 device->cdev->dev.bus_id, sense->fmt.f71.md[0]);
697 break;
698 case 0x06:
699 PRINT_WARN("(%s): CU Exception on node 0x%02x\n",
700 device->cdev->dev.bus_id, sense->fmt.f71.md[0]);
701 break;
702 case 0x07:
703 PRINT_WARN("(%s): CU Exception on partition 0x%02x\n",
704 device->cdev->dev.bus_id, sense->fmt.f71.md[0]);
705 break;
706 default:
707 PRINT_WARN("(%s): SIM ExMsg: 0x%02x\n",
708 device->cdev->dev.bus_id, sense->fmt.f71.emc);
709 }
710 /* Service Message */
711 switch (sense->fmt.f71.smc) {
712 case 0x01:
713 PRINT_WARN("(%s): Repair impact is unknown\n",
714 device->cdev->dev.bus_id);
715 break;
716 case 0x02:
717 PRINT_WARN("(%s): Repair will not impact cu performance\n",
718 device->cdev->dev.bus_id);
719 break;
720 case 0x03:
721 if (sense->fmt.f71.mdf == 0)
722 PRINT_WARN("(%s): Repair will disable node "
723 "0x%x on CU\n",
724 device->cdev->dev.bus_id,
725 sense->fmt.f71.md[1]);
726 else
727 PRINT_WARN("(%s): Repair will disable nodes "
728 "(0x%x-0x%x) on CU\n",
729 device->cdev->dev.bus_id,
730 sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
731 break;
732 case 0x04:
733 if (sense->fmt.f71.mdf == 0)
734 PRINT_WARN("(%s): Repair will disable cannel path "
735 "0x%x on CU\n",
736 device->cdev->dev.bus_id,
737 sense->fmt.f71.md[1]);
738 else
739 PRINT_WARN("(%s): Repair will disable cannel paths "
740 "(0x%x-0x%x) on CU\n",
741 device->cdev->dev.bus_id,
742 sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
743 break;
744 case 0x05:
745 if (sense->fmt.f71.mdf == 0)
746 PRINT_WARN("(%s): Repair will disable device path "
747 "0x%x on CU\n",
748 device->cdev->dev.bus_id,
749 sense->fmt.f71.md[1]);
750 else
751 PRINT_WARN("(%s): Repair will disable device paths "
752 "(0x%x-0x%x) on CU\n",
753 device->cdev->dev.bus_id,
754 sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
755 break;
756 case 0x06:
757 if (sense->fmt.f71.mdf == 0)
758 PRINT_WARN("(%s): Repair will disable library path "
759 "0x%x on CU\n",
760 device->cdev->dev.bus_id,
761 sense->fmt.f71.md[1]);
762 else
763 PRINT_WARN("(%s): Repair will disable library paths "
764 "(0x%x-0x%x) on CU\n",
765 device->cdev->dev.bus_id,
766 sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
767 break;
768 case 0x07:
769 PRINT_WARN("(%s): Repair will disable access to CU\n",
770 device->cdev->dev.bus_id);
771 break;
772 default:
773 PRINT_WARN("(%s): SIM ServiceMsg: 0x%02x\n",
774 device->cdev->dev.bus_id, sense->fmt.f71.smc);
775 }
776}
777
778/*
779 * Print an Device Subsystem Service Information Message (message code f2)
780 */
781static void
782tape_3590_print_dev_sim_msg_f2(struct tape_device *device, struct irb *irb)
783{
784 struct tape_3590_sense *sense;
785
786 sense = (struct tape_3590_sense *) irb->ecw;
787 /* Exception Message */
788 switch (sense->fmt.f71.emc) {
789 case 0x01:
790 PRINT_WARN("(%s): Effect of failure is unknown\n",
791 device->cdev->dev.bus_id);
792 break;
793 case 0x02:
794 PRINT_WARN("(%s): DV Exception - no performance impact\n",
795 device->cdev->dev.bus_id);
796 break;
797 case 0x03:
798 PRINT_WARN("(%s): DV Exception on channel interface 0x%02x\n",
799 device->cdev->dev.bus_id, sense->fmt.f71.md[0]);
800 break;
801 case 0x04:
802 PRINT_WARN("(%s): DV Exception on loader 0x%02x\n",
803 device->cdev->dev.bus_id, sense->fmt.f71.md[0]);
804 break;
805 case 0x05:
806 PRINT_WARN("(%s): DV Exception on message display 0x%02x\n",
807 device->cdev->dev.bus_id, sense->fmt.f71.md[0]);
808 break;
809 case 0x06:
810 PRINT_WARN("(%s): DV Exception in tape path\n",
811 device->cdev->dev.bus_id);
812 break;
813 case 0x07:
814 PRINT_WARN("(%s): DV Exception in drive\n",
815 device->cdev->dev.bus_id);
816 break;
817 default:
818 PRINT_WARN("(%s): DSIM ExMsg: 0x%02x\n",
819 device->cdev->dev.bus_id, sense->fmt.f71.emc);
820 }
821 /* Service Message */
822 switch (sense->fmt.f71.smc) {
823 case 0x01:
824 PRINT_WARN("(%s): Repair impact is unknown\n",
825 device->cdev->dev.bus_id);
826 break;
827 case 0x02:
828 PRINT_WARN("(%s): Repair will not impact device performance\n",
829 device->cdev->dev.bus_id);
830 break;
831 case 0x03:
832 if (sense->fmt.f71.mdf == 0)
833 PRINT_WARN("(%s): Repair will disable channel path "
834 "0x%x on DV\n",
835 device->cdev->dev.bus_id,
836 sense->fmt.f71.md[1]);
837 else
838 PRINT_WARN("(%s): Repair will disable channel path "
839 "(0x%x-0x%x) on DV\n",
840 device->cdev->dev.bus_id,
841 sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
842 break;
843 case 0x04:
844 if (sense->fmt.f71.mdf == 0)
845 PRINT_WARN("(%s): Repair will disable interface 0x%x "
846 "on DV\n",
847 device->cdev->dev.bus_id,
848 sense->fmt.f71.md[1]);
849 else
850 PRINT_WARN("(%s): Repair will disable interfaces "
851 "(0x%x-0x%x) on DV\n",
852 device->cdev->dev.bus_id,
853 sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
854 break;
855 case 0x05:
856 if (sense->fmt.f71.mdf == 0)
857 PRINT_WARN("(%s): Repair will disable loader 0x%x "
858 "on DV\n",
859 device->cdev->dev.bus_id,
860 sense->fmt.f71.md[1]);
861 else
862 PRINT_WARN("(%s): Repair will disable loader "
863 "(0x%x-0x%x) on DV\n",
864 device->cdev->dev.bus_id,
865 sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
866 break;
867 case 0x07:
868 PRINT_WARN("(%s): Repair will disable access to DV\n",
869 device->cdev->dev.bus_id);
870 break;
871 case 0x08:
872 if (sense->fmt.f71.mdf == 0)
873 PRINT_WARN("(%s): Repair will disable message "
874 "display 0x%x on DV\n",
875 device->cdev->dev.bus_id,
876 sense->fmt.f71.md[1]);
877 else
878 PRINT_WARN("(%s): Repair will disable message "
879 "displays (0x%x-0x%x) on DV\n",
880 device->cdev->dev.bus_id,
881 sense->fmt.f71.md[1], sense->fmt.f71.md[2]);
882 break;
883 case 0x09:
884 PRINT_WARN("(%s): Clean DV\n", device->cdev->dev.bus_id);
885 break;
886 default:
887 PRINT_WARN("(%s): DSIM ServiceMsg: 0x%02x\n",
888 device->cdev->dev.bus_id, sense->fmt.f71.smc);
889 }
890}
891
892/*
893 * Print standard ERA Message
894 */
895static void
896tape_3590_print_era_msg(struct tape_device *device, struct irb *irb)
897{
898 struct tape_3590_sense *sense;
899
900 sense = (struct tape_3590_sense *) irb->ecw;
901 if (sense->mc == 0)
902 return;
903 if ((sense->mc > 0) && (sense->mc < TAPE_3590_MAX_MSG)) {
904 if (tape_3590_msg[sense->mc] != NULL)
905 PRINT_WARN("(%s): %s\n", device->cdev->dev.bus_id,
906 tape_3590_msg[sense->mc]);
907 else {
908 PRINT_WARN("(%s): Message Code 0x%x\n",
909 device->cdev->dev.bus_id, sense->mc);
910 }
911 return;
912 }
913 if (sense->mc == 0xf0) {
914 /* Standard Media Information Message */
915 PRINT_WARN("(%s): MIM SEV=%i, MC=%02x, ES=%x/%x, "
916 "RC=%02x-%04x-%02x\n", device->cdev->dev.bus_id,
917 sense->fmt.f70.sev, sense->mc,
918 sense->fmt.f70.emc, sense->fmt.f70.smc,
919 sense->fmt.f70.refcode, sense->fmt.f70.mid,
920 sense->fmt.f70.fid);
921 tape_3590_print_mim_msg_f0(device, irb);
922 return;
923 }
924 if (sense->mc == 0xf1) {
925 /* Standard I/O Subsystem Service Information Message */
926 PRINT_WARN("(%s): IOSIM SEV=%i, DEVTYPE=3590/%02x, "
927 "MC=%02x, ES=%x/%x, REF=0x%04x-0x%04x-0x%04x\n",
928 device->cdev->dev.bus_id, sense->fmt.f71.sev,
929 device->cdev->id.dev_model,
930 sense->mc, sense->fmt.f71.emc,
931 sense->fmt.f71.smc, sense->fmt.f71.refcode1,
932 sense->fmt.f71.refcode2, sense->fmt.f71.refcode3);
933 tape_3590_print_io_sim_msg_f1(device, irb);
934 return;
935 }
936 if (sense->mc == 0xf2) {
937 /* Standard Device Service Information Message */
938 PRINT_WARN("(%s): DEVSIM SEV=%i, DEVTYPE=3590/%02x, "
939 "MC=%02x, ES=%x/%x, REF=0x%04x-0x%04x-0x%04x\n",
940 device->cdev->dev.bus_id, sense->fmt.f71.sev,
941 device->cdev->id.dev_model,
942 sense->mc, sense->fmt.f71.emc,
943 sense->fmt.f71.smc, sense->fmt.f71.refcode1,
944 sense->fmt.f71.refcode2, sense->fmt.f71.refcode3);
945 tape_3590_print_dev_sim_msg_f2(device, irb);
946 return;
947 }
948 if (sense->mc == 0xf3) {
949 /* Standard Library Service Information Message */
950 return;
951 }
952 PRINT_WARN("(%s): Device Message(%x)\n",
953 device->cdev->dev.bus_id, sense->mc);
954}
955
956/*
957 * 3590 error Recovery routine:
958 * If possible, it tries to recover from the error. If this is not possible,
959 * inform the user about the problem.
960 */
961static int
962tape_3590_unit_check(struct tape_device *device, struct tape_request *request,
963 struct irb *irb)
964{
965 struct tape_3590_sense *sense;
966 int rc;
967
968#ifdef CONFIG_S390_TAPE_BLOCK
969 if (request->op == TO_BLOCK) {
970 /*
971 * Recovery for block device requests. Set the block_position
972 * to something invalid and retry.
973 */
974 device->blk_data.block_position = -1;
975 if (request->retries-- <= 0)
976 return tape_3590_erp_failed(device, request, irb, -EIO);
977 else
978 return tape_3590_erp_retry(device, request, irb);
979 }
980#endif
981
982 sense = (struct tape_3590_sense *) irb->ecw;
983
984 /*
985 * First check all RC-QRCs where we want to do something special
986 * - "break": basic error recovery is done
987 * - "goto out:": just print error message if available
988 */
989 rc = -EIO;
990 switch (sense->rc_rqc) {
991
992 case 0x1110:
993 tape_3590_print_era_msg(device, irb);
994 return tape_3590_erp_read_buf_log(device, request, irb);
995
996 case 0x2011:
997 tape_3590_print_era_msg(device, irb);
998 return tape_3590_erp_read_alternate(device, request, irb);
999
1000 case 0x2230:
1001 case 0x2231:
1002 tape_3590_print_era_msg(device, irb);
1003 return tape_3590_erp_special_interrupt(device, request, irb);
1004
1005 case 0x3010:
1006 DBF_EVENT(2, "(%08x): Backward at Beginning of Partition\n",
1007 device->cdev_id);
1008 return tape_3590_erp_basic(device, request, irb, -ENOSPC);
1009 case 0x3012:
1010 DBF_EVENT(2, "(%08x): Forward at End of Partition\n",
1011 device->cdev_id);
1012 return tape_3590_erp_basic(device, request, irb, -ENOSPC);
1013 case 0x3020:
1014 DBF_EVENT(2, "(%08x): End of Data Mark\n", device->cdev_id);
1015 return tape_3590_erp_basic(device, request, irb, -ENOSPC);
1016
1017 case 0x3122:
1018 DBF_EVENT(2, "(%08x): Rewind Unload initiated\n",
1019 device->cdev_id);
1020 return tape_3590_erp_basic(device, request, irb, -EIO);
1021 case 0x3123:
1022 DBF_EVENT(2, "(%08x): Rewind Unload complete\n",
1023 device->cdev_id);
1024 tape_med_state_set(device, MS_UNLOADED);
1025 return tape_3590_erp_basic(device, request, irb, 0);
1026
1027 case 0x4010:
1028 /*
1029 * print additional msg since default msg
1030 * "device intervention" is not very meaningfull
1031 */
1032 PRINT_WARN("(%s): Tape operation when medium not loaded\n",
1033 device->cdev->dev.bus_id);
1034 tape_med_state_set(device, MS_UNLOADED);
1035 return tape_3590_erp_basic(device, request, irb, -ENOMEDIUM);
1036 case 0x4012: /* Device Long Busy */
1037 tape_3590_print_era_msg(device, irb);
1038 return tape_3590_erp_long_busy(device, request, irb);
1039
1040 case 0x5010:
1041 if (sense->rac == 0xd0) {
1042 /* Swap */
1043 tape_3590_print_era_msg(device, irb);
1044 return tape_3590_erp_swap(device, request, irb);
1045 }
1046 if (sense->rac == 0x26) {
1047 /* Read Opposite */
1048 tape_3590_print_era_msg(device, irb);
1049 return tape_3590_erp_read_opposite(device, request,
1050 irb);
1051 }
1052 return tape_3590_erp_basic(device, request, irb, -EIO);
1053 case 0x5020:
1054 case 0x5021:
1055 case 0x5022:
1056 case 0x5040:
1057 case 0x5041:
1058 case 0x5042:
1059 tape_3590_print_era_msg(device, irb);
1060 return tape_3590_erp_swap(device, request, irb);
1061
1062 case 0x5110:
1063 case 0x5111:
1064 return tape_3590_erp_basic(device, request, irb, -EMEDIUMTYPE);
1065
1066 case 0x5120:
1067 case 0x1120:
1068 tape_med_state_set(device, MS_UNLOADED);
1069 return tape_3590_erp_basic(device, request, irb, -ENOMEDIUM);
1070
1071 case 0x6020:
1072 PRINT_WARN("(%s): Cartridge of wrong type ?\n",
1073 device->cdev->dev.bus_id);
1074 return tape_3590_erp_basic(device, request, irb, -EMEDIUMTYPE);
1075
1076 case 0x8011:
1077 PRINT_WARN("(%s): Another host has reserved the tape device\n",
1078 device->cdev->dev.bus_id);
1079 return tape_3590_erp_basic(device, request, irb, -EPERM);
1080 case 0x8013:
1081 PRINT_WARN("(%s): Another host has priviliged access to the "
1082 "tape device\n", device->cdev->dev.bus_id);
1083 PRINT_WARN("(%s): To solve the problem unload the current "
1084 "cartridge!\n", device->cdev->dev.bus_id);
1085 return tape_3590_erp_basic(device, request, irb, -EPERM);
1086 default:
1087 return tape_3590_erp_basic(device, request, irb, -EIO);
1088 }
1089}
1090
1091/*
1092 * 3590 interrupt handler:
1093 */
1094static int
1095tape_3590_irq(struct tape_device *device, struct tape_request *request,
1096 struct irb *irb)
1097{
1098 if (request == NULL)
1099 return tape_3590_unsolicited_irq(device, irb);
1100
1101 if ((irb->scsw.dstat & DEV_STAT_UNIT_EXCEP) &&
1102 (irb->scsw.dstat & DEV_STAT_DEV_END) && (request->op == TO_WRI)) {
1103 /* Write at end of volume */
1104 DBF_EVENT(2, "End of volume\n");
1105 return tape_3590_erp_failed(device, request, irb, -ENOSPC);
1106 }
1107
1108 if (irb->scsw.dstat & DEV_STAT_UNIT_CHECK)
1109 return tape_3590_unit_check(device, request, irb);
1110
1111 if (irb->scsw.dstat & DEV_STAT_DEV_END) {
1112 if (irb->scsw.dstat == DEV_STAT_UNIT_EXCEP) {
1113 if (request->op == TO_FSB || request->op == TO_BSB)
1114 request->rescnt++;
1115 else
1116 DBF_EVENT(5, "Unit Exception!\n");
1117 }
1118
1119 return tape_3590_done(device, request);
1120 }
1121
1122 if (irb->scsw.dstat & DEV_STAT_CHN_END) {
1123 DBF_EVENT(2, "cannel end\n");
1124 return TAPE_IO_PENDING;
1125 }
1126
1127 if (irb->scsw.dstat & DEV_STAT_ATTENTION) {
1128 DBF_EVENT(2, "Unit Attention when busy..\n");
1129 return TAPE_IO_PENDING;
1130 }
1131
1132 DBF_EVENT(6, "xunknownirq\n");
1133 PRINT_ERR("Unexpected interrupt.\n");
1134 PRINT_ERR("Current op is: %s", tape_op_verbose[request->op]);
1135 tape_dump_sense(device, request, irb);
1136 return TAPE_IO_STOP;
1137}
1138
1139/*
1140 * Setup device function
1141 */
1142static int
1143tape_3590_setup_device(struct tape_device *device)
1144{
1145 int rc;
1146 struct tape_3590_disc_data *data;
1147
1148 DBF_EVENT(6, "3590 device setup\n");
1149 data = kmalloc(sizeof(struct tape_3590_disc_data),
1150 GFP_KERNEL | GFP_DMA);
1151 if (data == NULL)
1152 return -ENOMEM;
1153 data->read_back_op = READ_PREVIOUS;
1154 device->discdata = data;
1155
1156 if ((rc = tape_std_assign(device)) == 0) {
1157 /* Try to find out if medium is loaded */
1158 if ((rc = tape_3590_sense_medium(device)) != 0)
1159 DBF_LH(3, "3590 medium sense returned %d\n", rc);
1160 }
1161
1162 return rc;
1163}
1164
1165/*
1166 * Cleanup device function
1167 */
1168static void
1169tape_3590_cleanup_device(struct tape_device *device)
1170{
1171 tape_std_unassign(device);
1172
1173 kfree(device->discdata);
1174 device->discdata = NULL;
1175}
1176
1177/*
1178 * List of 3590 magnetic tape commands.
1179 */
1180static tape_mtop_fn tape_3590_mtop[TAPE_NR_MTOPS] = {
1181 [MTRESET] = tape_std_mtreset,
1182 [MTFSF] = tape_std_mtfsf,
1183 [MTBSF] = tape_std_mtbsf,
1184 [MTFSR] = tape_std_mtfsr,
1185 [MTBSR] = tape_std_mtbsr,
1186 [MTWEOF] = tape_std_mtweof,
1187 [MTREW] = tape_std_mtrew,
1188 [MTOFFL] = tape_std_mtoffl,
1189 [MTNOP] = tape_std_mtnop,
1190 [MTRETEN] = tape_std_mtreten,
1191 [MTBSFM] = tape_std_mtbsfm,
1192 [MTFSFM] = tape_std_mtfsfm,
1193 [MTEOM] = tape_std_mteom,
1194 [MTERASE] = tape_std_mterase,
1195 [MTRAS1] = NULL,
1196 [MTRAS2] = NULL,
1197 [MTRAS3] = NULL,
1198 [MTSETBLK] = tape_std_mtsetblk,
1199 [MTSETDENSITY] = NULL,
1200 [MTSEEK] = tape_3590_mtseek,
1201 [MTTELL] = tape_3590_mttell,
1202 [MTSETDRVBUFFER] = NULL,
1203 [MTFSS] = NULL,
1204 [MTBSS] = NULL,
1205 [MTWSM] = NULL,
1206 [MTLOCK] = NULL,
1207 [MTUNLOCK] = NULL,
1208 [MTLOAD] = tape_std_mtload,
1209 [MTUNLOAD] = tape_std_mtunload,
1210 [MTCOMPRESSION] = tape_std_mtcompression,
1211 [MTSETPART] = NULL,
1212 [MTMKPART] = NULL
1213};
1214
1215/*
1216 * Tape discipline structure for 3590.
1217 */
1218static struct tape_discipline tape_discipline_3590 = {
1219 .owner = THIS_MODULE,
1220 .setup_device = tape_3590_setup_device,
1221 .cleanup_device = tape_3590_cleanup_device,
1222 .process_eov = tape_std_process_eov,
1223 .irq = tape_3590_irq,
1224 .read_block = tape_std_read_block,
1225 .write_block = tape_std_write_block,
1226#ifdef CONFIG_S390_TAPE_BLOCK
1227 .bread = tape_3590_bread,
1228 .free_bread = tape_3590_free_bread,
1229 .check_locate = tape_3590_check_locate,
1230#endif
1231 .ioctl_fn = tape_3590_ioctl,
1232 .mtop_array = tape_3590_mtop
1233};
1234
1235static struct ccw_device_id tape_3590_ids[] = {
1236 {CCW_DEVICE_DEVTYPE(0x3590, 0, 0x3590, 0), .driver_info = tape_3590},
1237 { /* end of list */ }
1238};
1239
1240static int
1241tape_3590_online(struct ccw_device *cdev)
1242{
1243 return tape_generic_online(cdev->dev.driver_data,
1244 &tape_discipline_3590);
1245}
1246
1247static int
1248tape_3590_offline(struct ccw_device *cdev)
1249{
1250 return tape_generic_offline(cdev->dev.driver_data);
1251}
1252
1253static struct ccw_driver tape_3590_driver = {
1254 .name = "tape_3590",
1255 .owner = THIS_MODULE,
1256 .ids = tape_3590_ids,
1257 .probe = tape_generic_probe,
1258 .remove = tape_generic_remove,
1259 .set_offline = tape_3590_offline,
1260 .set_online = tape_3590_online,
1261};
1262
1263/*
1264 * Setup discipline structure.
1265 */
1266static int
1267tape_3590_init(void)
1268{
1269 int rc;
1270
1271 TAPE_DBF_AREA = debug_register("tape_3590", 2, 2, 4 * sizeof(long));
1272 debug_register_view(TAPE_DBF_AREA, &debug_sprintf_view);
1273#ifdef DBF_LIKE_HELL
1274 debug_set_level(TAPE_DBF_AREA, 6);
1275#endif
1276
1277 DBF_EVENT(3, "3590 init\n");
1278 /* Register driver for 3590 tapes. */
1279 rc = ccw_driver_register(&tape_3590_driver);
1280 if (rc)
1281 DBF_EVENT(3, "3590 init failed\n");
1282 else
1283 DBF_EVENT(3, "3590 registered\n");
1284 return rc;
1285}
1286
1287static void
1288tape_3590_exit(void)
1289{
1290 ccw_driver_unregister(&tape_3590_driver);
1291
1292 debug_unregister(TAPE_DBF_AREA);
1293}
1294
1295MODULE_DEVICE_TABLE(ccw, tape_3590_ids);
1296MODULE_AUTHOR("(C) 2001,2006 IBM Corporation");
1297MODULE_DESCRIPTION("Linux on zSeries channel attached 3590 tape device driver");
1298MODULE_LICENSE("GPL");
1299
1300module_init(tape_3590_init);
1301module_exit(tape_3590_exit);
diff --git a/drivers/s390/char/tape_3590.h b/drivers/s390/char/tape_3590.h
new file mode 100644
index 0000000000..cf274b9445
--- /dev/null
+++ b/drivers/s390/char/tape_3590.h
@@ -0,0 +1,124 @@
1/*
2 * drivers/s390/char/tape_3590.h
3 * tape device discipline for 3590 tapes.
4 *
5 * Copyright (C) IBM Corp. 2001,2006
6 * Author(s): Stefan Bader <shbader@de.ibm.com>
7 * Michael Holzheu <holzheu@de.ibm.com>
8 * Martin Schwidefsky <schwidefsky@de.ibm.com>
9 */
10
11#ifndef _TAPE_3590_H
12#define _TAPE_3590_H
13
14#define MEDIUM_SENSE 0xc2
15#define READ_PREVIOUS 0x0a
16#define MODE_SENSE 0xcf
17#define PERFORM_SS_FUNC 0x77
18#define READ_SS_DATA 0x3e
19
20#define PREP_RD_SS_DATA 0x18
21#define RD_ATTMSG 0x3
22
23#define SENSE_BRA_PER 0
24#define SENSE_BRA_CONT 1
25#define SENSE_BRA_RE 2
26#define SENSE_BRA_DRE 3
27
28#define SENSE_FMT_LIBRARY 0x23
29#define SENSE_FMT_UNSOLICITED 0x40
30#define SENSE_FMT_COMMAND_REJ 0x41
31#define SENSE_FMT_COMMAND_EXEC0 0x50
32#define SENSE_FMT_COMMAND_EXEC1 0x51
33#define SENSE_FMT_EVENT0 0x60
34#define SENSE_FMT_EVENT1 0x61
35#define SENSE_FMT_MIM 0x70
36#define SENSE_FMT_SIM 0x71
37
38#define MSENSE_UNASSOCIATED 0x00
39#define MSENSE_ASSOCIATED_MOUNT 0x01
40#define MSENSE_ASSOCIATED_UMOUNT 0x02
41
42#define TAPE_3590_MAX_MSG 0xb0
43
44/* Datatypes */
45
46struct tape_3590_disc_data {
47 unsigned char modeset_byte;
48 int read_back_op;
49};
50
51struct tape_3590_sense {
52
53 unsigned int command_rej:1;
54 unsigned int interv_req:1;
55 unsigned int bus_out_check:1;
56 unsigned int eq_check:1;
57 unsigned int data_check:1;
58 unsigned int overrun:1;
59 unsigned int def_unit_check:1;
60 unsigned int assgnd_elsew:1;
61
62 unsigned int locate_fail:1;
63 unsigned int inst_online:1;
64 unsigned int reserved:1;
65 unsigned int blk_seq_err:1;
66 unsigned int begin_part:1;
67 unsigned int wr_mode:1;
68 unsigned int wr_prot:1;
69 unsigned int not_cap:1;
70
71 unsigned int bra:2;
72 unsigned int lc:3;
73 unsigned int vlf_active:1;
74 unsigned int stm:1;
75 unsigned int med_pos:1;
76
77 unsigned int rac:8;
78
79 unsigned int rc_rqc:16;
80
81 unsigned int mc:8;
82
83 unsigned int sense_fmt:8;
84
85 union {
86 struct {
87 unsigned int emc:4;
88 unsigned int smc:4;
89 unsigned int sev:2;
90 unsigned int reserved:6;
91 unsigned int md:8;
92 unsigned int refcode:8;
93 unsigned int mid:16;
94 unsigned int mp:16;
95 unsigned char volid[6];
96 unsigned int fid:8;
97 } f70;
98 struct {
99 unsigned int emc:4;
100 unsigned int smc:4;
101 unsigned int sev:2;
102 unsigned int reserved1:5;
103 unsigned int mdf:1;
104 unsigned char md[3];
105 unsigned int simid:8;
106 unsigned int uid:16;
107 unsigned int refcode1:16;
108 unsigned int refcode2:16;
109 unsigned int refcode3:16;
110 unsigned int reserved2:8;
111 } f71;
112 unsigned char data[14];
113 } fmt;
114 unsigned char pad[10];
115
116} __attribute__ ((packed));
117
118struct tape_3590_med_sense {
119 unsigned int macst:4;
120 unsigned int masst:4;
121 char pad[127];
122} __attribute__ ((packed));
123
124#endif /* _TAPE_3590_H */
diff --git a/drivers/s390/char/tape_class.c b/drivers/s390/char/tape_class.c
index b3569c82bb..a5c68e60fc 100644
--- a/drivers/s390/char/tape_class.c
+++ b/drivers/s390/char/tape_class.c
@@ -44,11 +44,10 @@ struct tape_class_device *register_tape_dev(
44 int rc; 44 int rc;
45 char * s; 45 char * s;
46 46
47 tcd = kmalloc(sizeof(struct tape_class_device), GFP_KERNEL); 47 tcd = kzalloc(sizeof(struct tape_class_device), GFP_KERNEL);
48 if (!tcd) 48 if (!tcd)
49 return ERR_PTR(-ENOMEM); 49 return ERR_PTR(-ENOMEM);
50 50
51 memset(tcd, 0, sizeof(struct tape_class_device));
52 strncpy(tcd->device_name, device_name, TAPECLASS_NAME_LEN); 51 strncpy(tcd->device_name, device_name, TAPECLASS_NAME_LEN);
53 for (s = strchr(tcd->device_name, '/'); s; s = strchr(s, '/')) 52 for (s = strchr(tcd->device_name, '/'); s; s = strchr(s, '/'))
54 *s = '!'; 53 *s = '!';
diff --git a/drivers/s390/char/tape_core.c b/drivers/s390/char/tape_core.c
index 4ea438c749..389ee2c0f4 100644
--- a/drivers/s390/char/tape_core.c
+++ b/drivers/s390/char/tape_core.c
@@ -453,16 +453,14 @@ tape_alloc_device(void)
453{ 453{
454 struct tape_device *device; 454 struct tape_device *device;
455 455
456 device = (struct tape_device *) 456 device = kzalloc(sizeof(struct tape_device), GFP_KERNEL);
457 kmalloc(sizeof(struct tape_device), GFP_KERNEL);
458 if (device == NULL) { 457 if (device == NULL) {
459 DBF_EXCEPTION(2, "ti:no mem\n"); 458 DBF_EXCEPTION(2, "ti:no mem\n");
460 PRINT_INFO ("can't allocate memory for " 459 PRINT_INFO ("can't allocate memory for "
461 "tape info structure\n"); 460 "tape info structure\n");
462 return ERR_PTR(-ENOMEM); 461 return ERR_PTR(-ENOMEM);
463 } 462 }
464 memset(device, 0, sizeof(struct tape_device)); 463 device->modeset_byte = kmalloc(1, GFP_KERNEL | GFP_DMA);
465 device->modeset_byte = (char *) kmalloc(1, GFP_KERNEL | GFP_DMA);
466 if (device->modeset_byte == NULL) { 464 if (device->modeset_byte == NULL) {
467 DBF_EXCEPTION(2, "ti:no mem\n"); 465 DBF_EXCEPTION(2, "ti:no mem\n");
468 PRINT_INFO("can't allocate memory for modeset byte\n"); 466 PRINT_INFO("can't allocate memory for modeset byte\n");
@@ -659,34 +657,30 @@ tape_alloc_request(int cplength, int datasize)
659 657
660 DBF_LH(6, "tape_alloc_request(%d, %d)\n", cplength, datasize); 658 DBF_LH(6, "tape_alloc_request(%d, %d)\n", cplength, datasize);
661 659
662 request = (struct tape_request *) kmalloc(sizeof(struct tape_request), 660 request = kzalloc(sizeof(struct tape_request), GFP_KERNEL);
663 GFP_KERNEL);
664 if (request == NULL) { 661 if (request == NULL) {
665 DBF_EXCEPTION(1, "cqra nomem\n"); 662 DBF_EXCEPTION(1, "cqra nomem\n");
666 return ERR_PTR(-ENOMEM); 663 return ERR_PTR(-ENOMEM);
667 } 664 }
668 memset(request, 0, sizeof(struct tape_request));
669 /* allocate channel program */ 665 /* allocate channel program */
670 if (cplength > 0) { 666 if (cplength > 0) {
671 request->cpaddr = kmalloc(cplength*sizeof(struct ccw1), 667 request->cpaddr = kcalloc(cplength, sizeof(struct ccw1),
672 GFP_ATOMIC | GFP_DMA); 668 GFP_ATOMIC | GFP_DMA);
673 if (request->cpaddr == NULL) { 669 if (request->cpaddr == NULL) {
674 DBF_EXCEPTION(1, "cqra nomem\n"); 670 DBF_EXCEPTION(1, "cqra nomem\n");
675 kfree(request); 671 kfree(request);
676 return ERR_PTR(-ENOMEM); 672 return ERR_PTR(-ENOMEM);
677 } 673 }
678 memset(request->cpaddr, 0, cplength*sizeof(struct ccw1));
679 } 674 }
680 /* alloc small kernel buffer */ 675 /* alloc small kernel buffer */
681 if (datasize > 0) { 676 if (datasize > 0) {
682 request->cpdata = kmalloc(datasize, GFP_KERNEL | GFP_DMA); 677 request->cpdata = kzalloc(datasize, GFP_KERNEL | GFP_DMA);
683 if (request->cpdata == NULL) { 678 if (request->cpdata == NULL) {
684 DBF_EXCEPTION(1, "cqra nomem\n"); 679 DBF_EXCEPTION(1, "cqra nomem\n");
685 kfree(request->cpaddr); 680 kfree(request->cpaddr);
686 kfree(request); 681 kfree(request);
687 return ERR_PTR(-ENOMEM); 682 return ERR_PTR(-ENOMEM);
688 } 683 }
689 memset(request->cpdata, 0, datasize);
690 } 684 }
691 DBF_LH(6, "New request %p(%p/%p)\n", request, request->cpaddr, 685 DBF_LH(6, "New request %p(%p/%p)\n", request, request->cpaddr,
692 request->cpdata); 686 request->cpdata);
@@ -761,6 +755,13 @@ __tape_start_next_request(struct tape_device *device)
761 */ 755 */
762 if (request->status == TAPE_REQUEST_IN_IO) 756 if (request->status == TAPE_REQUEST_IN_IO)
763 return; 757 return;
758 /*
759 * Request has already been stopped. We have to wait until
760 * the request is removed from the queue in the interrupt
761 * handling.
762 */
763 if (request->status == TAPE_REQUEST_DONE)
764 return;
764 765
765 /* 766 /*
766 * We wanted to cancel the request but the common I/O layer 767 * We wanted to cancel the request but the common I/O layer
@@ -1015,7 +1016,7 @@ tape_do_io_interruptible(struct tape_device *device,
1015 wq, 1016 wq,
1016 (request->callback == NULL) 1017 (request->callback == NULL)
1017 ); 1018 );
1018 } while (rc != -ERESTARTSYS); 1019 } while (rc == -ERESTARTSYS);
1019 1020
1020 DBF_EVENT(3, "IO stopped on %08x\n", device->cdev_id); 1021 DBF_EVENT(3, "IO stopped on %08x\n", device->cdev_id);
1021 rc = -ERESTARTSYS; 1022 rc = -ERESTARTSYS;
@@ -1024,6 +1025,20 @@ tape_do_io_interruptible(struct tape_device *device,
1024} 1025}
1025 1026
1026/* 1027/*
1028 * Stop running ccw.
1029 */
1030int
1031tape_cancel_io(struct tape_device *device, struct tape_request *request)
1032{
1033 int rc;
1034
1035 spin_lock_irq(get_ccwdev_lock(device->cdev));
1036 rc = __tape_cancel_io(device, request);
1037 spin_unlock_irq(get_ccwdev_lock(device->cdev));
1038 return rc;
1039}
1040
1041/*
1027 * Tape interrupt routine, called from the ccw_device layer 1042 * Tape interrupt routine, called from the ccw_device layer
1028 */ 1043 */
1029static void 1044static void
@@ -1064,15 +1079,16 @@ __tape_do_irq (struct ccw_device *cdev, unsigned long intparm, struct irb *irb)
1064 /* 1079 /*
1065 * If the condition code is not zero and the start function bit is 1080 * If the condition code is not zero and the start function bit is
1066 * still set, this is an deferred error and the last start I/O did 1081 * still set, this is an deferred error and the last start I/O did
1067 * not succeed. Restart the request now. 1082 * not succeed. At this point the condition that caused the deferred
1083 * error might still apply. So we just schedule the request to be
1084 * started later.
1068 */ 1085 */
1069 if (irb->scsw.cc != 0 && (irb->scsw.fctl & SCSW_FCTL_START_FUNC)) { 1086 if (irb->scsw.cc != 0 && (irb->scsw.fctl & SCSW_FCTL_START_FUNC) &&
1070 PRINT_WARN("(%s): deferred cc=%i. restaring\n", 1087 (request->status == TAPE_REQUEST_IN_IO)) {
1071 cdev->dev.bus_id, 1088 DBF_EVENT(3,"(%08x): deferred cc=%i, fctl=%i. restarting\n",
1072 irb->scsw.cc); 1089 device->cdev_id, irb->scsw.cc, irb->scsw.fctl);
1073 rc = __tape_start_io(device, request); 1090 request->status = TAPE_REQUEST_QUEUED;
1074 if (rc) 1091 schedule_delayed_work(&device->tape_dnr, HZ);
1075 __tape_end_request(device, request, rc);
1076 return; 1092 return;
1077 } 1093 }
1078 1094
@@ -1286,4 +1302,5 @@ EXPORT_SYMBOL(tape_dump_sense_dbf);
1286EXPORT_SYMBOL(tape_do_io); 1302EXPORT_SYMBOL(tape_do_io);
1287EXPORT_SYMBOL(tape_do_io_async); 1303EXPORT_SYMBOL(tape_do_io_async);
1288EXPORT_SYMBOL(tape_do_io_interruptible); 1304EXPORT_SYMBOL(tape_do_io_interruptible);
1305EXPORT_SYMBOL(tape_cancel_io);
1289EXPORT_SYMBOL(tape_mtop); 1306EXPORT_SYMBOL(tape_mtop);
diff --git a/drivers/s390/char/tape_std.c b/drivers/s390/char/tape_std.c
index 2f9fe30989..99cf881f41 100644
--- a/drivers/s390/char/tape_std.c
+++ b/drivers/s390/char/tape_std.c
@@ -37,20 +37,19 @@ tape_std_assign_timeout(unsigned long data)
37{ 37{
38 struct tape_request * request; 38 struct tape_request * request;
39 struct tape_device * device; 39 struct tape_device * device;
40 int rc;
40 41
41 request = (struct tape_request *) data; 42 request = (struct tape_request *) data;
42 if ((device = request->device) == NULL) 43 if ((device = request->device) == NULL)
43 BUG(); 44 BUG();
44 45
45 spin_lock_irq(get_ccwdev_lock(device->cdev)); 46 DBF_EVENT(3, "%08x: Assignment timeout. Device busy.\n",
46 if (request->callback != NULL) {
47 DBF_EVENT(3, "%08x: Assignment timeout. Device busy.\n",
48 device->cdev_id); 47 device->cdev_id);
49 PRINT_ERR("%s: Assignment timeout. Device busy.\n", 48 rc = tape_cancel_io(device, request);
50 device->cdev->dev.bus_id); 49 if(rc)
51 ccw_device_clear(device->cdev, (long) request); 50 PRINT_ERR("(%s): Assign timeout: Cancel failed with rc = %i\n",
52 } 51 device->cdev->dev.bus_id, rc);
53 spin_unlock_irq(get_ccwdev_lock(device->cdev)); 52
54} 53}
55 54
56int 55int
diff --git a/drivers/s390/char/tape_std.h b/drivers/s390/char/tape_std.h
index 3ab6aafb73..2d311798ed 100644
--- a/drivers/s390/char/tape_std.h
+++ b/drivers/s390/char/tape_std.h
@@ -1,9 +1,8 @@
1/* 1/*
2 * drivers/s390/char/tape_34xx.h 2 * drivers/s390/char/tape_std.h
3 * standard tape device functions for ibm tapes. 3 * standard tape device functions for ibm tapes.
4 * 4 *
5 * S390 and zSeries version 5 * Copyright (C) IBM Corp. 2001,2006
6 * Copyright (C) 2001,2002 IBM Deutschland Entwicklung GmbH, IBM Corporation
7 * Author(s): Carsten Otte <cotte@de.ibm.com> 6 * Author(s): Carsten Otte <cotte@de.ibm.com>
8 * Tuan Ngo-Anh <ngoanh@de.ibm.com> 7 * Tuan Ngo-Anh <ngoanh@de.ibm.com>
9 * Martin Schwidefsky <schwidefsky@de.ibm.com> 8 * Martin Schwidefsky <schwidefsky@de.ibm.com>
@@ -149,4 +148,11 @@ void tape_std_error_recovery_do_retry(struct tape_device *);
149void tape_std_error_recovery_read_opposite(struct tape_device *); 148void tape_std_error_recovery_read_opposite(struct tape_device *);
150void tape_std_error_recovery_HWBUG(struct tape_device *, int condno); 149void tape_std_error_recovery_HWBUG(struct tape_device *, int condno);
151 150
151/* S390 tape types */
152enum s390_tape_type {
153 tape_3480,
154 tape_3490,
155 tape_3590,
156};
157
152#endif // _TAPE_STD_H 158#endif // _TAPE_STD_H
diff --git a/drivers/s390/char/tty3270.c b/drivers/s390/char/tty3270.c
index 4b90693703..9a14177687 100644
--- a/drivers/s390/char/tty3270.c
+++ b/drivers/s390/char/tty3270.c
@@ -691,10 +691,9 @@ tty3270_alloc_view(void)
691 struct tty3270 *tp; 691 struct tty3270 *tp;
692 int pages; 692 int pages;
693 693
694 tp = kmalloc(sizeof(struct tty3270),GFP_KERNEL); 694 tp = kzalloc(sizeof(struct tty3270), GFP_KERNEL);
695 if (!tp) 695 if (!tp)
696 goto out_err; 696 goto out_err;
697 memset(tp, 0, sizeof(struct tty3270));
698 tp->freemem_pages = 697 tp->freemem_pages =
699 kmalloc(sizeof(void *) * TTY3270_STRING_PAGES, GFP_KERNEL); 698 kmalloc(sizeof(void *) * TTY3270_STRING_PAGES, GFP_KERNEL);
700 if (!tp->freemem_pages) 699 if (!tp->freemem_pages)
@@ -767,16 +766,14 @@ tty3270_alloc_screen(struct tty3270 *tp)
767 int lines; 766 int lines;
768 767
769 size = sizeof(struct tty3270_line) * (tp->view.rows - 2); 768 size = sizeof(struct tty3270_line) * (tp->view.rows - 2);
770 tp->screen = kmalloc(size, GFP_KERNEL); 769 tp->screen = kzalloc(size, GFP_KERNEL);
771 if (!tp->screen) 770 if (!tp->screen)
772 goto out_err; 771 goto out_err;
773 memset(tp->screen, 0, size);
774 for (lines = 0; lines < tp->view.rows - 2; lines++) { 772 for (lines = 0; lines < tp->view.rows - 2; lines++) {
775 size = sizeof(struct tty3270_cell) * tp->view.cols; 773 size = sizeof(struct tty3270_cell) * tp->view.cols;
776 tp->screen[lines].cells = kmalloc(size, GFP_KERNEL); 774 tp->screen[lines].cells = kzalloc(size, GFP_KERNEL);
777 if (!tp->screen[lines].cells) 775 if (!tp->screen[lines].cells)
778 goto out_screen; 776 goto out_screen;
779 memset(tp->screen[lines].cells, 0, size);
780 } 777 }
781 return 0; 778 return 0;
782out_screen: 779out_screen:
diff --git a/drivers/s390/char/vmlogrdr.c b/drivers/s390/char/vmlogrdr.c
index b2d75de144..c625b69ebd 100644
--- a/drivers/s390/char/vmlogrdr.c
+++ b/drivers/s390/char/vmlogrdr.c
@@ -759,9 +759,8 @@ vmlogrdr_register_device(struct vmlogrdr_priv_t *priv) {
759 struct device *dev; 759 struct device *dev;
760 int ret; 760 int ret;
761 761
762 dev = kmalloc(sizeof(struct device), GFP_KERNEL); 762 dev = kzalloc(sizeof(struct device), GFP_KERNEL);
763 if (dev) { 763 if (dev) {
764 memset(dev, 0, sizeof(struct device));
765 snprintf(dev->bus_id, BUS_ID_SIZE, "%s", 764 snprintf(dev->bus_id, BUS_ID_SIZE, "%s",
766 priv->internal_name); 765 priv->internal_name);
767 dev->bus = &iucv_bus; 766 dev->bus = &iucv_bus;
diff --git a/drivers/s390/cio/ccwgroup.c b/drivers/s390/cio/ccwgroup.c
index 8013c8eb76..bdfee7fbaa 100644
--- a/drivers/s390/cio/ccwgroup.c
+++ b/drivers/s390/cio/ccwgroup.c
@@ -157,11 +157,10 @@ ccwgroup_create(struct device *root,
157 if (argc > 256) /* disallow dumb users */ 157 if (argc > 256) /* disallow dumb users */
158 return -EINVAL; 158 return -EINVAL;
159 159
160 gdev = kmalloc(sizeof(*gdev) + argc*sizeof(gdev->cdev[0]), GFP_KERNEL); 160 gdev = kzalloc(sizeof(*gdev) + argc*sizeof(gdev->cdev[0]), GFP_KERNEL);
161 if (!gdev) 161 if (!gdev)
162 return -ENOMEM; 162 return -ENOMEM;
163 163
164 memset(gdev, 0, sizeof(*gdev) + argc*sizeof(gdev->cdev[0]));
165 atomic_set(&gdev->onoff, 0); 164 atomic_set(&gdev->onoff, 0);
166 165
167 del_drvdata = 0; 166 del_drvdata = 0;
diff --git a/drivers/s390/cio/chsc.c b/drivers/s390/cio/chsc.c
index f4183d6602..6412b2c3ed 100644
--- a/drivers/s390/cio/chsc.c
+++ b/drivers/s390/cio/chsc.c
@@ -98,10 +98,8 @@ chsc_get_sch_desc_irq(struct subchannel *sch, void *page)
98 98
99 ssd_area = page; 99 ssd_area = page;
100 100
101 ssd_area->request = (struct chsc_header) { 101 ssd_area->request.length = 0x0010;
102 .length = 0x0010, 102 ssd_area->request.code = 0x0004;
103 .code = 0x0004,
104 };
105 103
106 ssd_area->ssid = sch->schid.ssid; 104 ssd_area->ssid = sch->schid.ssid;
107 ssd_area->f_sch = sch->schid.sch_no; 105 ssd_area->f_sch = sch->schid.sch_no;
@@ -517,10 +515,8 @@ chsc_process_crw(void)
517 struct device *dev; 515 struct device *dev;
518 memset(sei_area, 0, sizeof(*sei_area)); 516 memset(sei_area, 0, sizeof(*sei_area));
519 memset(&res_data, 0, sizeof(struct res_acc_data)); 517 memset(&res_data, 0, sizeof(struct res_acc_data));
520 sei_area->request = (struct chsc_header) { 518 sei_area->request.length = 0x0010;
521 .length = 0x0010, 519 sei_area->request.code = 0x000e;
522 .code = 0x000e,
523 };
524 520
525 ccode = chsc(sei_area); 521 ccode = chsc(sei_area);
526 if (ccode > 0) 522 if (ccode > 0)
@@ -875,6 +871,264 @@ s390_vary_chpid( __u8 chpid, int on)
875} 871}
876 872
877/* 873/*
874 * Channel measurement related functions
875 */
876static ssize_t
877chp_measurement_chars_read(struct kobject *kobj, char *buf, loff_t off,
878 size_t count)
879{
880 struct channel_path *chp;
881 unsigned int size;
882
883 chp = to_channelpath(container_of(kobj, struct device, kobj));
884 if (!chp->cmg_chars)
885 return 0;
886
887 size = sizeof(struct cmg_chars);
888
889 if (off > size)
890 return 0;
891 if (off + count > size)
892 count = size - off;
893 memcpy(buf, chp->cmg_chars + off, count);
894 return count;
895}
896
897static struct bin_attribute chp_measurement_chars_attr = {
898 .attr = {
899 .name = "measurement_chars",
900 .mode = S_IRUSR,
901 .owner = THIS_MODULE,
902 },
903 .size = sizeof(struct cmg_chars),
904 .read = chp_measurement_chars_read,
905};
906
907static void
908chp_measurement_copy_block(struct cmg_entry *buf,
909 struct channel_subsystem *css, int chpid)
910{
911 void *area;
912 struct cmg_entry *entry, reference_buf;
913 int idx;
914
915 if (chpid < 128) {
916 area = css->cub_addr1;
917 idx = chpid;
918 } else {
919 area = css->cub_addr2;
920 idx = chpid - 128;
921 }
922 entry = area + (idx * sizeof(struct cmg_entry));
923 do {
924 memcpy(buf, entry, sizeof(*entry));
925 memcpy(&reference_buf, entry, sizeof(*entry));
926 } while (reference_buf.values[0] != buf->values[0]);
927}
928
929static ssize_t
930chp_measurement_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
931{
932 struct channel_path *chp;
933 struct channel_subsystem *css;
934 unsigned int size;
935
936 chp = to_channelpath(container_of(kobj, struct device, kobj));
937 css = to_css(chp->dev.parent);
938
939 size = sizeof(struct cmg_chars);
940
941 /* Only allow single reads. */
942 if (off || count < size)
943 return 0;
944 chp_measurement_copy_block((struct cmg_entry *)buf, css, chp->id);
945 return count;
946}
947
948static struct bin_attribute chp_measurement_attr = {
949 .attr = {
950 .name = "measurement",
951 .mode = S_IRUSR,
952 .owner = THIS_MODULE,
953 },
954 .size = sizeof(struct cmg_entry),
955 .read = chp_measurement_read,
956};
957
958static void
959chsc_remove_chp_cmg_attr(struct channel_path *chp)
960{
961 sysfs_remove_bin_file(&chp->dev.kobj, &chp_measurement_chars_attr);
962 sysfs_remove_bin_file(&chp->dev.kobj, &chp_measurement_attr);
963}
964
965static int
966chsc_add_chp_cmg_attr(struct channel_path *chp)
967{
968 int ret;
969
970 ret = sysfs_create_bin_file(&chp->dev.kobj,
971 &chp_measurement_chars_attr);
972 if (ret)
973 return ret;
974 ret = sysfs_create_bin_file(&chp->dev.kobj, &chp_measurement_attr);
975 if (ret)
976 sysfs_remove_bin_file(&chp->dev.kobj,
977 &chp_measurement_chars_attr);
978 return ret;
979}
980
981static void
982chsc_remove_cmg_attr(struct channel_subsystem *css)
983{
984 int i;
985
986 for (i = 0; i <= __MAX_CHPID; i++) {
987 if (!css->chps[i])
988 continue;
989 chsc_remove_chp_cmg_attr(css->chps[i]);
990 }
991}
992
993static int
994chsc_add_cmg_attr(struct channel_subsystem *css)
995{
996 int i, ret;
997
998 ret = 0;
999 for (i = 0; i <= __MAX_CHPID; i++) {
1000 if (!css->chps[i])
1001 continue;
1002 ret = chsc_add_chp_cmg_attr(css->chps[i]);
1003 if (ret)
1004 goto cleanup;
1005 }
1006 return ret;
1007cleanup:
1008 for (--i; i >= 0; i--) {
1009 if (!css->chps[i])
1010 continue;
1011 chsc_remove_chp_cmg_attr(css->chps[i]);
1012 }
1013 return ret;
1014}
1015
1016
1017static int
1018__chsc_do_secm(struct channel_subsystem *css, int enable, void *page)
1019{
1020 struct {
1021 struct chsc_header request;
1022 u32 operation_code : 2;
1023 u32 : 30;
1024 u32 key : 4;
1025 u32 : 28;
1026 u32 zeroes1;
1027 u32 cub_addr1;
1028 u32 zeroes2;
1029 u32 cub_addr2;
1030 u32 reserved[13];
1031 struct chsc_header response;
1032 u32 status : 8;
1033 u32 : 4;
1034 u32 fmt : 4;
1035 u32 : 16;
1036 } *secm_area;
1037 int ret, ccode;
1038
1039 secm_area = page;
1040 secm_area->request.length = 0x0050;
1041 secm_area->request.code = 0x0016;
1042
1043 secm_area->key = PAGE_DEFAULT_KEY;
1044 secm_area->cub_addr1 = (u64)(unsigned long)css->cub_addr1;
1045 secm_area->cub_addr2 = (u64)(unsigned long)css->cub_addr2;
1046
1047 secm_area->operation_code = enable ? 0 : 1;
1048
1049 ccode = chsc(secm_area);
1050 if (ccode > 0)
1051 return (ccode == 3) ? -ENODEV : -EBUSY;
1052
1053 switch (secm_area->response.code) {
1054 case 0x0001: /* Success. */
1055 ret = 0;
1056 break;
1057 case 0x0003: /* Invalid block. */
1058 case 0x0007: /* Invalid format. */
1059 case 0x0008: /* Other invalid block. */
1060 CIO_CRW_EVENT(2, "Error in chsc request block!\n");
1061 ret = -EINVAL;
1062 break;
1063 case 0x0004: /* Command not provided in model. */
1064 CIO_CRW_EVENT(2, "Model does not provide secm\n");
1065 ret = -EOPNOTSUPP;
1066 break;
1067 case 0x0102: /* cub adresses incorrect */
1068 CIO_CRW_EVENT(2, "Invalid addresses in chsc request block\n");
1069 ret = -EINVAL;
1070 break;
1071 case 0x0103: /* key error */
1072 CIO_CRW_EVENT(2, "Access key error in secm\n");
1073 ret = -EINVAL;
1074 break;
1075 case 0x0105: /* error while starting */
1076 CIO_CRW_EVENT(2, "Error while starting channel measurement\n");
1077 ret = -EIO;
1078 break;
1079 default:
1080 CIO_CRW_EVENT(2, "Unknown CHSC response %d\n",
1081 secm_area->response.code);
1082 ret = -EIO;
1083 }
1084 return ret;
1085}
1086
1087int
1088chsc_secm(struct channel_subsystem *css, int enable)
1089{
1090 void *secm_area;
1091 int ret;
1092
1093 secm_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
1094 if (!secm_area)
1095 return -ENOMEM;
1096
1097 mutex_lock(&css->mutex);
1098 if (enable && !css->cm_enabled) {
1099 css->cub_addr1 = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
1100 css->cub_addr2 = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
1101 if (!css->cub_addr1 || !css->cub_addr2) {
1102 free_page((unsigned long)css->cub_addr1);
1103 free_page((unsigned long)css->cub_addr2);
1104 free_page((unsigned long)secm_area);
1105 mutex_unlock(&css->mutex);
1106 return -ENOMEM;
1107 }
1108 }
1109 ret = __chsc_do_secm(css, enable, secm_area);
1110 if (!ret) {
1111 css->cm_enabled = enable;
1112 if (css->cm_enabled) {
1113 ret = chsc_add_cmg_attr(css);
1114 if (ret) {
1115 memset(secm_area, 0, PAGE_SIZE);
1116 __chsc_do_secm(css, 0, secm_area);
1117 css->cm_enabled = 0;
1118 }
1119 } else
1120 chsc_remove_cmg_attr(css);
1121 }
1122 if (enable && !css->cm_enabled) {
1123 free_page((unsigned long)css->cub_addr1);
1124 free_page((unsigned long)css->cub_addr2);
1125 }
1126 mutex_unlock(&css->mutex);
1127 free_page((unsigned long)secm_area);
1128 return ret;
1129}
1130
1131/*
878 * Files for the channel path entries. 1132 * Files for the channel path entries.
879 */ 1133 */
880static ssize_t 1134static ssize_t
@@ -925,9 +1179,39 @@ chp_type_show(struct device *dev, struct device_attribute *attr, char *buf)
925 1179
926static DEVICE_ATTR(type, 0444, chp_type_show, NULL); 1180static DEVICE_ATTR(type, 0444, chp_type_show, NULL);
927 1181
1182static ssize_t
1183chp_cmg_show(struct device *dev, struct device_attribute *attr, char *buf)
1184{
1185 struct channel_path *chp = to_channelpath(dev);
1186
1187 if (!chp)
1188 return 0;
1189 if (chp->cmg == -1) /* channel measurements not available */
1190 return sprintf(buf, "unknown\n");
1191 return sprintf(buf, "%x\n", chp->cmg);
1192}
1193
1194static DEVICE_ATTR(cmg, 0444, chp_cmg_show, NULL);
1195
1196static ssize_t
1197chp_shared_show(struct device *dev, struct device_attribute *attr, char *buf)
1198{
1199 struct channel_path *chp = to_channelpath(dev);
1200
1201 if (!chp)
1202 return 0;
1203 if (chp->shared == -1) /* channel measurements not available */
1204 return sprintf(buf, "unknown\n");
1205 return sprintf(buf, "%x\n", chp->shared);
1206}
1207
1208static DEVICE_ATTR(shared, 0444, chp_shared_show, NULL);
1209
928static struct attribute * chp_attrs[] = { 1210static struct attribute * chp_attrs[] = {
929 &dev_attr_status.attr, 1211 &dev_attr_status.attr,
930 &dev_attr_type.attr, 1212 &dev_attr_type.attr,
1213 &dev_attr_cmg.attr,
1214 &dev_attr_shared.attr,
931 NULL, 1215 NULL,
932}; 1216};
933 1217
@@ -966,10 +1250,8 @@ chsc_determine_channel_path_description(int chpid,
966 if (!scpd_area) 1250 if (!scpd_area)
967 return -ENOMEM; 1251 return -ENOMEM;
968 1252
969 scpd_area->request = (struct chsc_header) { 1253 scpd_area->request.length = 0x0010;
970 .length = 0x0010, 1254 scpd_area->request.code = 0x0002;
971 .code = 0x0002,
972 };
973 1255
974 scpd_area->first_chpid = chpid; 1256 scpd_area->first_chpid = chpid;
975 scpd_area->last_chpid = chpid; 1257 scpd_area->last_chpid = chpid;
@@ -1006,6 +1288,111 @@ out:
1006 return ret; 1288 return ret;
1007} 1289}
1008 1290
1291static void
1292chsc_initialize_cmg_chars(struct channel_path *chp, u8 cmcv,
1293 struct cmg_chars *chars)
1294{
1295 switch (chp->cmg) {
1296 case 2:
1297 case 3:
1298 chp->cmg_chars = kmalloc(sizeof(struct cmg_chars),
1299 GFP_KERNEL);
1300 if (chp->cmg_chars) {
1301 int i, mask;
1302 struct cmg_chars *cmg_chars;
1303
1304 cmg_chars = chp->cmg_chars;
1305 for (i = 0; i < NR_MEASUREMENT_CHARS; i++) {
1306 mask = 0x80 >> (i + 3);
1307 if (cmcv & mask)
1308 cmg_chars->values[i] = chars->values[i];
1309 else
1310 cmg_chars->values[i] = 0;
1311 }
1312 }
1313 break;
1314 default:
1315 /* No cmg-dependent data. */
1316 break;
1317 }
1318}
1319
1320static int
1321chsc_get_channel_measurement_chars(struct channel_path *chp)
1322{
1323 int ccode, ret;
1324
1325 struct {
1326 struct chsc_header request;
1327 u32 : 24;
1328 u32 first_chpid : 8;
1329 u32 : 24;
1330 u32 last_chpid : 8;
1331 u32 zeroes1;
1332 struct chsc_header response;
1333 u32 zeroes2;
1334 u32 not_valid : 1;
1335 u32 shared : 1;
1336 u32 : 22;
1337 u32 chpid : 8;
1338 u32 cmcv : 5;
1339 u32 : 11;
1340 u32 cmgq : 8;
1341 u32 cmg : 8;
1342 u32 zeroes3;
1343 u32 data[NR_MEASUREMENT_CHARS];
1344 } *scmc_area;
1345
1346 scmc_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
1347 if (!scmc_area)
1348 return -ENOMEM;
1349
1350 scmc_area->request.length = 0x0010;
1351 scmc_area->request.code = 0x0022;
1352
1353 scmc_area->first_chpid = chp->id;
1354 scmc_area->last_chpid = chp->id;
1355
1356 ccode = chsc(scmc_area);
1357 if (ccode > 0) {
1358 ret = (ccode == 3) ? -ENODEV : -EBUSY;
1359 goto out;
1360 }
1361
1362 switch (scmc_area->response.code) {
1363 case 0x0001: /* Success. */
1364 if (!scmc_area->not_valid) {
1365 chp->cmg = scmc_area->cmg;
1366 chp->shared = scmc_area->shared;
1367 chsc_initialize_cmg_chars(chp, scmc_area->cmcv,
1368 (struct cmg_chars *)
1369 &scmc_area->data);
1370 } else {
1371 chp->cmg = -1;
1372 chp->shared = -1;
1373 }
1374 ret = 0;
1375 break;
1376 case 0x0003: /* Invalid block. */
1377 case 0x0007: /* Invalid format. */
1378 case 0x0008: /* Invalid bit combination. */
1379 CIO_CRW_EVENT(2, "Error in chsc request block!\n");
1380 ret = -EINVAL;
1381 break;
1382 case 0x0004: /* Command not provided. */
1383 CIO_CRW_EVENT(2, "Model does not provide scmc\n");
1384 ret = -EOPNOTSUPP;
1385 break;
1386 default:
1387 CIO_CRW_EVENT(2, "Unknown CHSC response %d\n",
1388 scmc_area->response.code);
1389 ret = -EIO;
1390 }
1391out:
1392 free_page((unsigned long)scmc_area);
1393 return ret;
1394}
1395
1009/* 1396/*
1010 * Entries for chpids on the system bus. 1397 * Entries for chpids on the system bus.
1011 * This replaces /proc/chpids. 1398 * This replaces /proc/chpids.
@@ -1016,10 +1403,9 @@ new_channel_path(int chpid)
1016 struct channel_path *chp; 1403 struct channel_path *chp;
1017 int ret; 1404 int ret;
1018 1405
1019 chp = kmalloc(sizeof(struct channel_path), GFP_KERNEL); 1406 chp = kzalloc(sizeof(struct channel_path), GFP_KERNEL);
1020 if (!chp) 1407 if (!chp)
1021 return -ENOMEM; 1408 return -ENOMEM;
1022 memset(chp, 0, sizeof(struct channel_path));
1023 1409
1024 /* fill in status, etc. */ 1410 /* fill in status, etc. */
1025 chp->id = chpid; 1411 chp->id = chpid;
@@ -1034,6 +1420,22 @@ new_channel_path(int chpid)
1034 ret = chsc_determine_channel_path_description(chpid, &chp->desc); 1420 ret = chsc_determine_channel_path_description(chpid, &chp->desc);
1035 if (ret) 1421 if (ret)
1036 goto out_free; 1422 goto out_free;
1423 /* Get channel-measurement characteristics. */
1424 if (css_characteristics_avail && css_chsc_characteristics.scmc
1425 && css_chsc_characteristics.secm) {
1426 ret = chsc_get_channel_measurement_chars(chp);
1427 if (ret)
1428 goto out_free;
1429 } else {
1430 static int msg_done;
1431
1432 if (!msg_done) {
1433 printk(KERN_WARNING "cio: Channel measurements not "
1434 "available, continuing.\n");
1435 msg_done = 1;
1436 }
1437 chp->cmg = -1;
1438 }
1037 1439
1038 /* make it known to the system */ 1440 /* make it known to the system */
1039 ret = device_register(&chp->dev); 1441 ret = device_register(&chp->dev);
@@ -1046,8 +1448,19 @@ new_channel_path(int chpid)
1046 if (ret) { 1448 if (ret) {
1047 device_unregister(&chp->dev); 1449 device_unregister(&chp->dev);
1048 goto out_free; 1450 goto out_free;
1049 } else 1451 }
1050 css[0]->chps[chpid] = chp; 1452 mutex_lock(&css[0]->mutex);
1453 if (css[0]->cm_enabled) {
1454 ret = chsc_add_chp_cmg_attr(chp);
1455 if (ret) {
1456 sysfs_remove_group(&chp->dev.kobj, &chp_attr_group);
1457 device_unregister(&chp->dev);
1458 mutex_unlock(&css[0]->mutex);
1459 goto out_free;
1460 }
1461 }
1462 css[0]->chps[chpid] = chp;
1463 mutex_unlock(&css[0]->mutex);
1051 return ret; 1464 return ret;
1052out_free: 1465out_free:
1053 kfree(chp); 1466 kfree(chp);
@@ -1103,10 +1516,8 @@ chsc_enable_facility(int operation_code)
1103 sda_area = (void *)get_zeroed_page(GFP_KERNEL|GFP_DMA); 1516 sda_area = (void *)get_zeroed_page(GFP_KERNEL|GFP_DMA);
1104 if (!sda_area) 1517 if (!sda_area)
1105 return -ENOMEM; 1518 return -ENOMEM;
1106 sda_area->request = (struct chsc_header) { 1519 sda_area->request.length = 0x0400;
1107 .length = 0x0400, 1520 sda_area->request.code = 0x0031;
1108 .code = 0x0031,
1109 };
1110 sda_area->operation_code = operation_code; 1521 sda_area->operation_code = operation_code;
1111 1522
1112 ret = chsc(sda_area); 1523 ret = chsc(sda_area);
@@ -1161,10 +1572,8 @@ chsc_determine_css_characteristics(void)
1161 return -ENOMEM; 1572 return -ENOMEM;
1162 } 1573 }
1163 1574
1164 scsc_area->request = (struct chsc_header) { 1575 scsc_area->request.length = 0x0010;
1165 .length = 0x0010, 1576 scsc_area->request.code = 0x0010;
1166 .code = 0x0010,
1167 };
1168 1577
1169 result = chsc(scsc_area); 1578 result = chsc(scsc_area);
1170 if (result) { 1579 if (result) {
diff --git a/drivers/s390/cio/chsc.h b/drivers/s390/cio/chsc.h
index 3e75095f35..a259245780 100644
--- a/drivers/s390/cio/chsc.h
+++ b/drivers/s390/cio/chsc.h
@@ -12,6 +12,16 @@ struct chsc_header {
12 u16 code; 12 u16 code;
13}; 13};
14 14
15#define NR_MEASUREMENT_CHARS 5
16struct cmg_chars {
17 u32 values[NR_MEASUREMENT_CHARS];
18};
19
20#define NR_MEASUREMENT_ENTRIES 8
21struct cmg_entry {
22 u32 values[NR_MEASUREMENT_ENTRIES];
23};
24
15struct channel_path_desc { 25struct channel_path_desc {
16 u8 flags; 26 u8 flags;
17 u8 lsn; 27 u8 lsn;
@@ -27,6 +37,10 @@ struct channel_path {
27 int id; 37 int id;
28 int state; 38 int state;
29 struct channel_path_desc desc; 39 struct channel_path_desc desc;
40 /* Channel-measurement related stuff: */
41 int cmg;
42 int shared;
43 void *cmg_chars;
30 struct device dev; 44 struct device dev;
31}; 45};
32 46
@@ -52,7 +66,11 @@ struct css_general_char {
52 66
53struct css_chsc_char { 67struct css_chsc_char {
54 u64 res; 68 u64 res;
55 u64 : 43; 69 u64 : 20;
70 u32 secm : 1; /* bit 84 */
71 u32 : 1;
72 u32 scmc : 1; /* bit 86 */
73 u32 : 20;
56 u32 scssc : 1; /* bit 107 */ 74 u32 scssc : 1; /* bit 107 */
57 u32 scsscf : 1; /* bit 108 */ 75 u32 scsscf : 1; /* bit 108 */
58 u32 : 19; 76 u32 : 19;
@@ -67,6 +85,8 @@ extern int css_characteristics_avail;
67extern void *chsc_get_chp_desc(struct subchannel*, int); 85extern void *chsc_get_chp_desc(struct subchannel*, int);
68 86
69extern int chsc_enable_facility(int); 87extern int chsc_enable_facility(int);
88struct channel_subsystem;
89extern int chsc_secm(struct channel_subsystem *, int);
70 90
71#define to_channelpath(device) container_of(device, struct channel_path, dev) 91#define to_channelpath(device) container_of(device, struct channel_path, dev)
72 92
diff --git a/drivers/s390/cio/css.c b/drivers/s390/cio/css.c
index 3c77d65960..74ea8aac4b 100644
--- a/drivers/s390/cio/css.c
+++ b/drivers/s390/cio/css.c
@@ -452,15 +452,50 @@ channel_subsystem_release(struct device *dev)
452 struct channel_subsystem *css; 452 struct channel_subsystem *css;
453 453
454 css = to_css(dev); 454 css = to_css(dev);
455 mutex_destroy(&css->mutex);
455 kfree(css); 456 kfree(css);
456} 457}
457 458
459static ssize_t
460css_cm_enable_show(struct device *dev, struct device_attribute *attr,
461 char *buf)
462{
463 struct channel_subsystem *css = to_css(dev);
464
465 if (!css)
466 return 0;
467 return sprintf(buf, "%x\n", css->cm_enabled);
468}
469
470static ssize_t
471css_cm_enable_store(struct device *dev, struct device_attribute *attr,
472 const char *buf, size_t count)
473{
474 struct channel_subsystem *css = to_css(dev);
475 int ret;
476
477 switch (buf[0]) {
478 case '0':
479 ret = css->cm_enabled ? chsc_secm(css, 0) : 0;
480 break;
481 case '1':
482 ret = css->cm_enabled ? 0 : chsc_secm(css, 1);
483 break;
484 default:
485 ret = -EINVAL;
486 }
487 return ret < 0 ? ret : count;
488}
489
490static DEVICE_ATTR(cm_enable, 0644, css_cm_enable_show, css_cm_enable_store);
491
458static inline void __init 492static inline void __init
459setup_css(int nr) 493setup_css(int nr)
460{ 494{
461 u32 tod_high; 495 u32 tod_high;
462 496
463 memset(css[nr], 0, sizeof(struct channel_subsystem)); 497 memset(css[nr], 0, sizeof(struct channel_subsystem));
498 mutex_init(&css[nr]->mutex);
464 css[nr]->valid = 1; 499 css[nr]->valid = 1;
465 css[nr]->cssid = nr; 500 css[nr]->cssid = nr;
466 sprintf(css[nr]->device.bus_id, "css%x", nr); 501 sprintf(css[nr]->device.bus_id, "css%x", nr);
@@ -507,6 +542,9 @@ init_channel_subsystem (void)
507 ret = device_register(&css[i]->device); 542 ret = device_register(&css[i]->device);
508 if (ret) 543 if (ret)
509 goto out_free; 544 goto out_free;
545 if (css_characteristics_avail && css_chsc_characteristics.secm)
546 device_create_file(&css[i]->device,
547 &dev_attr_cm_enable);
510 } 548 }
511 css_init_done = 1; 549 css_init_done = 1;
512 550
@@ -519,6 +557,9 @@ out_free:
519out_unregister: 557out_unregister:
520 while (i > 0) { 558 while (i > 0) {
521 i--; 559 i--;
560 if (css_characteristics_avail && css_chsc_characteristics.secm)
561 device_remove_file(&css[i]->device,
562 &dev_attr_cm_enable);
522 device_unregister(&css[i]->device); 563 device_unregister(&css[i]->device);
523 } 564 }
524out_bus: 565out_bus:
@@ -589,10 +630,9 @@ css_enqueue_subchannel_slow(struct subchannel_id schid)
589 struct slow_subchannel *new_slow_sch; 630 struct slow_subchannel *new_slow_sch;
590 unsigned long flags; 631 unsigned long flags;
591 632
592 new_slow_sch = kmalloc(sizeof(struct slow_subchannel), GFP_ATOMIC); 633 new_slow_sch = kzalloc(sizeof(struct slow_subchannel), GFP_ATOMIC);
593 if (!new_slow_sch) 634 if (!new_slow_sch)
594 return -ENOMEM; 635 return -ENOMEM;
595 memset(new_slow_sch, 0, sizeof(struct slow_subchannel));
596 new_slow_sch->schid = schid; 636 new_slow_sch->schid = schid;
597 spin_lock_irqsave(&slow_subchannel_lock, flags); 637 spin_lock_irqsave(&slow_subchannel_lock, flags);
598 list_add_tail(&new_slow_sch->slow_list, &slow_subchannels_head); 638 list_add_tail(&new_slow_sch->slow_list, &slow_subchannels_head);
diff --git a/drivers/s390/cio/css.h b/drivers/s390/cio/css.h
index b6375861cb..74a257b233 100644
--- a/drivers/s390/cio/css.h
+++ b/drivers/s390/cio/css.h
@@ -1,6 +1,7 @@
1#ifndef _CSS_H 1#ifndef _CSS_H
2#define _CSS_H 2#define _CSS_H
3 3
4#include <linux/mutex.h>
4#include <linux/wait.h> 5#include <linux/wait.h>
5#include <linux/workqueue.h> 6#include <linux/workqueue.h>
6 7
@@ -150,6 +151,11 @@ struct channel_subsystem {
150 struct channel_path *chps[__MAX_CHPID + 1]; 151 struct channel_path *chps[__MAX_CHPID + 1];
151 struct device device; 152 struct device device;
152 struct pgid global_pgid; 153 struct pgid global_pgid;
154 struct mutex mutex;
155 /* channel measurement related */
156 int cm_enabled;
157 void *cub_addr1;
158 void *cub_addr2;
153}; 159};
154#define to_css(dev) container_of(dev, struct channel_subsystem, device) 160#define to_css(dev) container_of(dev, struct channel_subsystem, device)
155 161
diff --git a/drivers/s390/cio/device.c b/drivers/s390/cio/device.c
index afc4e88551..8e3053c2a4 100644
--- a/drivers/s390/cio/device.c
+++ b/drivers/s390/cio/device.c
@@ -826,17 +826,15 @@ io_subchannel_probe (struct subchannel *sch)
826 get_device(&cdev->dev); 826 get_device(&cdev->dev);
827 return 0; 827 return 0;
828 } 828 }
829 cdev = kmalloc (sizeof(*cdev), GFP_KERNEL); 829 cdev = kzalloc (sizeof(*cdev), GFP_KERNEL);
830 if (!cdev) 830 if (!cdev)
831 return -ENOMEM; 831 return -ENOMEM;
832 memset(cdev, 0, sizeof(struct ccw_device)); 832 cdev->private = kzalloc(sizeof(struct ccw_device_private),
833 cdev->private = kmalloc(sizeof(struct ccw_device_private),
834 GFP_KERNEL | GFP_DMA); 833 GFP_KERNEL | GFP_DMA);
835 if (!cdev->private) { 834 if (!cdev->private) {
836 kfree(cdev); 835 kfree(cdev);
837 return -ENOMEM; 836 return -ENOMEM;
838 } 837 }
839 memset(cdev->private, 0, sizeof(struct ccw_device_private));
840 atomic_set(&cdev->private->onoff, 0); 838 atomic_set(&cdev->private->onoff, 0);
841 cdev->dev = (struct device) { 839 cdev->dev = (struct device) {
842 .parent = &sch->dev, 840 .parent = &sch->dev,
diff --git a/drivers/s390/cio/device_fsm.c b/drivers/s390/cio/device_fsm.c
index b302779e7c..180b3bf8b9 100644
--- a/drivers/s390/cio/device_fsm.c
+++ b/drivers/s390/cio/device_fsm.c
@@ -827,6 +827,17 @@ ccw_device_w4sense(struct ccw_device *cdev, enum dev_event dev_event)
827 } 827 }
828 return; 828 return;
829 } 829 }
830 /*
831 * Check if a halt or clear has been issued in the meanwhile. If yes,
832 * only deliver the halt/clear interrupt to the device driver as if it
833 * had killed the original request.
834 */
835 if (irb->scsw.fctl & (SCSW_FCTL_CLEAR_FUNC | SCSW_FCTL_HALT_FUNC)) {
836 cdev->private->flags.dosense = 0;
837 memset(&cdev->private->irb, 0, sizeof(struct irb));
838 ccw_device_accumulate_irb(cdev, irb);
839 goto call_handler;
840 }
830 /* Add basic sense info to irb. */ 841 /* Add basic sense info to irb. */
831 ccw_device_accumulate_basic_sense(cdev, irb); 842 ccw_device_accumulate_basic_sense(cdev, irb);
832 if (cdev->private->flags.dosense) { 843 if (cdev->private->flags.dosense) {
@@ -834,6 +845,7 @@ ccw_device_w4sense(struct ccw_device *cdev, enum dev_event dev_event)
834 ccw_device_do_sense(cdev, irb); 845 ccw_device_do_sense(cdev, irb);
835 return; 846 return;
836 } 847 }
848call_handler:
837 cdev->private->state = DEV_STATE_ONLINE; 849 cdev->private->state = DEV_STATE_ONLINE;
838 /* Call the handler. */ 850 /* Call the handler. */
839 if (ccw_device_call_handler(cdev) && cdev->private->flags.doverify) 851 if (ccw_device_call_handler(cdev) && cdev->private->flags.doverify)
diff --git a/drivers/s390/cio/device_ops.c b/drivers/s390/cio/device_ops.c
index 3a50b19032..795abb5a65 100644
--- a/drivers/s390/cio/device_ops.c
+++ b/drivers/s390/cio/device_ops.c
@@ -359,10 +359,9 @@ read_dev_chars (struct ccw_device *cdev, void **buffer, int length)
359 CIO_TRACE_EVENT (4, "rddevch"); 359 CIO_TRACE_EVENT (4, "rddevch");
360 CIO_TRACE_EVENT (4, sch->dev.bus_id); 360 CIO_TRACE_EVENT (4, sch->dev.bus_id);
361 361
362 rdc_ccw = kmalloc(sizeof(struct ccw1), GFP_KERNEL | GFP_DMA); 362 rdc_ccw = kzalloc(sizeof(struct ccw1), GFP_KERNEL | GFP_DMA);
363 if (!rdc_ccw) 363 if (!rdc_ccw)
364 return -ENOMEM; 364 return -ENOMEM;
365 memset(rdc_ccw, 0, sizeof(struct ccw1));
366 rdc_ccw->cmd_code = CCW_CMD_RDC; 365 rdc_ccw->cmd_code = CCW_CMD_RDC;
367 rdc_ccw->count = length; 366 rdc_ccw->count = length;
368 rdc_ccw->flags = CCW_FLAG_SLI; 367 rdc_ccw->flags = CCW_FLAG_SLI;
@@ -426,16 +425,14 @@ read_conf_data_lpm (struct ccw_device *cdev, void **buffer, int *length, __u8 lp
426 if (!ciw || ciw->cmd == 0) 425 if (!ciw || ciw->cmd == 0)
427 return -EOPNOTSUPP; 426 return -EOPNOTSUPP;
428 427
429 rcd_ccw = kmalloc(sizeof(struct ccw1), GFP_KERNEL | GFP_DMA); 428 rcd_ccw = kzalloc(sizeof(struct ccw1), GFP_KERNEL | GFP_DMA);
430 if (!rcd_ccw) 429 if (!rcd_ccw)
431 return -ENOMEM; 430 return -ENOMEM;
432 memset(rcd_ccw, 0, sizeof(struct ccw1)); 431 rcd_buf = kzalloc(ciw->count, GFP_KERNEL | GFP_DMA);
433 rcd_buf = kmalloc(ciw->count, GFP_KERNEL | GFP_DMA);
434 if (!rcd_buf) { 432 if (!rcd_buf) {
435 kfree(rcd_ccw); 433 kfree(rcd_ccw);
436 return -ENOMEM; 434 return -ENOMEM;
437 } 435 }
438 memset (rcd_buf, 0, ciw->count);
439 rcd_ccw->cmd_code = ciw->cmd; 436 rcd_ccw->cmd_code = ciw->cmd;
440 rcd_ccw->cda = (__u32) __pa (rcd_buf); 437 rcd_ccw->cda = (__u32) __pa (rcd_buf);
441 rcd_ccw->count = ciw->count; 438 rcd_ccw->count = ciw->count;
diff --git a/drivers/s390/cio/qdio.c b/drivers/s390/cio/qdio.c
index 9ed37dc9a1..814f9258ce 100644
--- a/drivers/s390/cio/qdio.c
+++ b/drivers/s390/cio/qdio.c
@@ -1686,16 +1686,14 @@ qdio_alloc_qs(struct qdio_irq *irq_ptr,
1686 int result=-ENOMEM; 1686 int result=-ENOMEM;
1687 1687
1688 for (i=0;i<no_input_qs;i++) { 1688 for (i=0;i<no_input_qs;i++) {
1689 q=kmalloc(sizeof(struct qdio_q),GFP_KERNEL); 1689 q = kzalloc(sizeof(struct qdio_q), GFP_KERNEL);
1690 1690
1691 if (!q) { 1691 if (!q) {
1692 QDIO_PRINT_ERR("kmalloc of q failed!\n"); 1692 QDIO_PRINT_ERR("kmalloc of q failed!\n");
1693 goto out; 1693 goto out;
1694 } 1694 }
1695 1695
1696 memset(q,0,sizeof(struct qdio_q)); 1696 q->slib = kmalloc(PAGE_SIZE, GFP_KERNEL);
1697
1698 q->slib=kmalloc(PAGE_SIZE,GFP_KERNEL);
1699 if (!q->slib) { 1697 if (!q->slib) {
1700 QDIO_PRINT_ERR("kmalloc of slib failed!\n"); 1698 QDIO_PRINT_ERR("kmalloc of slib failed!\n");
1701 goto out; 1699 goto out;
@@ -1705,14 +1703,12 @@ qdio_alloc_qs(struct qdio_irq *irq_ptr,
1705 } 1703 }
1706 1704
1707 for (i=0;i<no_output_qs;i++) { 1705 for (i=0;i<no_output_qs;i++) {
1708 q=kmalloc(sizeof(struct qdio_q),GFP_KERNEL); 1706 q = kzalloc(sizeof(struct qdio_q), GFP_KERNEL);
1709 1707
1710 if (!q) { 1708 if (!q) {
1711 goto out; 1709 goto out;
1712 } 1710 }
1713 1711
1714 memset(q,0,sizeof(struct qdio_q));
1715
1716 q->slib=kmalloc(PAGE_SIZE,GFP_KERNEL); 1712 q->slib=kmalloc(PAGE_SIZE,GFP_KERNEL);
1717 if (!q->slib) { 1713 if (!q->slib) {
1718 QDIO_PRINT_ERR("kmalloc of slib failed!\n"); 1714 QDIO_PRINT_ERR("kmalloc of slib failed!\n");
@@ -2984,7 +2980,7 @@ qdio_allocate(struct qdio_initialize *init_data)
2984 qdio_allocate_do_dbf(init_data); 2980 qdio_allocate_do_dbf(init_data);
2985 2981
2986 /* create irq */ 2982 /* create irq */
2987 irq_ptr=kmalloc(sizeof(struct qdio_irq), GFP_KERNEL | GFP_DMA); 2983 irq_ptr = kzalloc(sizeof(struct qdio_irq), GFP_KERNEL | GFP_DMA);
2988 2984
2989 QDIO_DBF_TEXT0(0,setup,"irq_ptr:"); 2985 QDIO_DBF_TEXT0(0,setup,"irq_ptr:");
2990 QDIO_DBF_HEX0(0,setup,&irq_ptr,sizeof(void*)); 2986 QDIO_DBF_HEX0(0,setup,&irq_ptr,sizeof(void*));
@@ -2994,8 +2990,6 @@ qdio_allocate(struct qdio_initialize *init_data)
2994 return -ENOMEM; 2990 return -ENOMEM;
2995 } 2991 }
2996 2992
2997 memset(irq_ptr,0,sizeof(struct qdio_irq));
2998
2999 init_MUTEX(&irq_ptr->setting_up_sema); 2993 init_MUTEX(&irq_ptr->setting_up_sema);
3000 2994
3001 /* QDR must be in DMA area since CCW data address is only 32 bit */ 2995 /* QDR must be in DMA area since CCW data address is only 32 bit */
@@ -3686,10 +3680,10 @@ qdio_get_qdio_memory(void)
3686 3680
3687 for (i=1;i<INDICATORS_PER_CACHELINE;i++) 3681 for (i=1;i<INDICATORS_PER_CACHELINE;i++)
3688 indicator_used[i]=0; 3682 indicator_used[i]=0;
3689 indicators=(__u32*)kmalloc(sizeof(__u32)*(INDICATORS_PER_CACHELINE), 3683 indicators = kzalloc(sizeof(__u32)*(INDICATORS_PER_CACHELINE),
3690 GFP_KERNEL); 3684 GFP_KERNEL);
3691 if (!indicators) return -ENOMEM; 3685 if (!indicators)
3692 memset(indicators,0,sizeof(__u32)*(INDICATORS_PER_CACHELINE)); 3686 return -ENOMEM;
3693 return 0; 3687 return 0;
3694} 3688}
3695 3689
diff --git a/drivers/s390/crypto/z90hardware.c b/drivers/s390/crypto/z90hardware.c
index 4141919da8..be60795f4a 100644
--- a/drivers/s390/crypto/z90hardware.c
+++ b/drivers/s390/crypto/z90hardware.c
@@ -2214,7 +2214,7 @@ ICACRT_msg_to_type50CRT_msg(struct ica_rsa_modexpo_crt *icaMsg_p,
2214 long_len = 128; 2214 long_len = 128;
2215 } 2215 }
2216 2216
2217 tmp_size = ((mod_len <= 128) ? TYPE50_CRB1_LEN : TYPE50_CRB2_LEN) + 2217 tmp_size = ((long_len <= 64) ? TYPE50_CRB1_LEN : TYPE50_CRB2_LEN) +
2218 CALLER_HEADER; 2218 CALLER_HEADER;
2219 2219
2220 memset(z90cMsg_p, 0, tmp_size); 2220 memset(z90cMsg_p, 0, tmp_size);
@@ -2479,8 +2479,16 @@ convert_response(unsigned char *response, unsigned char *buffer,
2479 2479
2480 if (reply_code) 2480 if (reply_code)
2481 switch (reply_code) { 2481 switch (reply_code) {
2482 case REP82_ERROR_MACHINE_FAILURE:
2483 if (errh_p->type == TYPE82_RSP_CODE)
2484 PRINTKW("Machine check failure\n");
2485 else
2486 PRINTKW("Module failure\n");
2487 return REC_HARDWAR_ERR;
2482 case REP82_ERROR_OPERAND_INVALID: 2488 case REP82_ERROR_OPERAND_INVALID:
2489 return REC_OPERAND_INV;
2483 case REP88_ERROR_MESSAGE_MALFORMD: 2490 case REP88_ERROR_MESSAGE_MALFORMD:
2491 PRINTKW("Message malformed\n");
2484 return REC_OPERAND_INV; 2492 return REC_OPERAND_INV;
2485 case REP82_ERROR_OPERAND_SIZE: 2493 case REP82_ERROR_OPERAND_SIZE:
2486 return REC_OPERAND_SIZE; 2494 return REC_OPERAND_SIZE;
diff --git a/drivers/s390/crypto/z90main.c b/drivers/s390/crypto/z90main.c
index 7d6f19030e..982acc7303 100644
--- a/drivers/s390/crypto/z90main.c
+++ b/drivers/s390/crypto/z90main.c
@@ -1,9 +1,9 @@
1/* 1/*
2 * linux/drivers/s390/crypto/z90main.c 2 * linux/drivers/s390/crypto/z90main.c
3 * 3 *
4 * z90crypt 1.3.2 4 * z90crypt 1.3.3
5 * 5 *
6 * Copyright (C) 2001, 2004 IBM Corporation 6 * Copyright (C) 2001, 2005 IBM Corporation
7 * Author(s): Robert Burroughs (burrough@us.ibm.com) 7 * Author(s): Robert Burroughs (burrough@us.ibm.com)
8 * Eric Rossman (edrossma@us.ibm.com) 8 * Eric Rossman (edrossma@us.ibm.com)
9 * 9 *
@@ -707,13 +707,12 @@ z90crypt_open(struct inode *inode, struct file *filp)
707 if (quiesce_z90crypt) 707 if (quiesce_z90crypt)
708 return -EQUIESCE; 708 return -EQUIESCE;
709 709
710 private_data_p = kmalloc(sizeof(struct priv_data), GFP_KERNEL); 710 private_data_p = kzalloc(sizeof(struct priv_data), GFP_KERNEL);
711 if (!private_data_p) { 711 if (!private_data_p) {
712 PRINTK("Memory allocate failed\n"); 712 PRINTK("Memory allocate failed\n");
713 return -ENOMEM; 713 return -ENOMEM;
714 } 714 }
715 715
716 memset((void *)private_data_p, 0, sizeof(struct priv_data));
717 private_data_p->status = STAT_OPEN; 716 private_data_p->status = STAT_OPEN;
718 private_data_p->opener_pid = PID(); 717 private_data_p->opener_pid = PID();
719 filp->private_data = private_data_p; 718 filp->private_data = private_data_p;
@@ -991,6 +990,7 @@ remove_device(struct device *device_p)
991 * PCIXCC_MCL2 512-2048 ----- (applying any GA LIC will make an MCL3 card) 990 * PCIXCC_MCL2 512-2048 ----- (applying any GA LIC will make an MCL3 card)
992 * PCIXCC_MCL3 ----- 128-2048 991 * PCIXCC_MCL3 ----- 128-2048
993 * CEX2C 512-2048 128-2048 992 * CEX2C 512-2048 128-2048
993 * CEX2A ??-2048 same (the lower limit is less than 128 bit...)
994 * 994 *
995 * ext_bitlens (extended bitlengths) is a global, since you should not apply an 995 * ext_bitlens (extended bitlengths) is a global, since you should not apply an
996 * MCL to just one card in a machine. We assume, at first, that all cards have 996 * MCL to just one card in a machine. We assume, at first, that all cards have
@@ -2736,13 +2736,11 @@ create_z90crypt(int *cdx_p)
2736 z90crypt.max_count = Z90CRYPT_NUM_DEVS; 2736 z90crypt.max_count = Z90CRYPT_NUM_DEVS;
2737 z90crypt.cdx = *cdx_p; 2737 z90crypt.cdx = *cdx_p;
2738 2738
2739 hdware_blk_p = (struct hdware_block *) 2739 hdware_blk_p = kzalloc(sizeof(struct hdware_block), GFP_ATOMIC);
2740 kmalloc(sizeof(struct hdware_block), GFP_ATOMIC);
2741 if (!hdware_blk_p) { 2740 if (!hdware_blk_p) {
2742 PDEBUG("kmalloc for hardware block failed\n"); 2741 PDEBUG("kmalloc for hardware block failed\n");
2743 return ENOMEM; 2742 return ENOMEM;
2744 } 2743 }
2745 memset(hdware_blk_p, 0x00, sizeof(struct hdware_block));
2746 z90crypt.hdware_info = hdware_blk_p; 2744 z90crypt.hdware_info = hdware_blk_p;
2747 2745
2748 return 0; 2746 return 0;
@@ -2977,12 +2975,11 @@ create_crypto_device(int index)
2977 total_size = sizeof(struct device) + 2975 total_size = sizeof(struct device) +
2978 z90crypt.q_depth_array[index] * sizeof(int); 2976 z90crypt.q_depth_array[index] * sizeof(int);
2979 2977
2980 dev_ptr = (struct device *) kmalloc(total_size, GFP_ATOMIC); 2978 dev_ptr = kzalloc(total_size, GFP_ATOMIC);
2981 if (!dev_ptr) { 2979 if (!dev_ptr) {
2982 PRINTK("kmalloc device %d failed\n", index); 2980 PRINTK("kmalloc device %d failed\n", index);
2983 return ENOMEM; 2981 return ENOMEM;
2984 } 2982 }
2985 memset(dev_ptr, 0, total_size);
2986 dev_ptr->dev_resp_p = kmalloc(MAX_RESPONSE_SIZE, GFP_ATOMIC); 2983 dev_ptr->dev_resp_p = kmalloc(MAX_RESPONSE_SIZE, GFP_ATOMIC);
2987 if (!dev_ptr->dev_resp_p) { 2984 if (!dev_ptr->dev_resp_p) {
2988 kfree(dev_ptr); 2985 kfree(dev_ptr);
diff --git a/drivers/s390/net/claw.c b/drivers/s390/net/claw.c
index acd2a3f005..23d53bf9da 100644
--- a/drivers/s390/net/claw.c
+++ b/drivers/s390/net/claw.c
@@ -310,7 +310,7 @@ claw_probe(struct ccwgroup_device *cgdev)
310 printk(KERN_INFO "claw: variable cgdev =\n"); 310 printk(KERN_INFO "claw: variable cgdev =\n");
311 dumpit((char *)cgdev, sizeof(struct ccwgroup_device)); 311 dumpit((char *)cgdev, sizeof(struct ccwgroup_device));
312#endif 312#endif
313 privptr = kmalloc(sizeof(struct claw_privbk), GFP_KERNEL); 313 privptr = kzalloc(sizeof(struct claw_privbk), GFP_KERNEL);
314 if (privptr == NULL) { 314 if (privptr == NULL) {
315 probe_error(cgdev); 315 probe_error(cgdev);
316 put_device(&cgdev->dev); 316 put_device(&cgdev->dev);
@@ -319,7 +319,6 @@ claw_probe(struct ccwgroup_device *cgdev)
319 CLAW_DBF_TEXT_(2,setup,"probex%d",-ENOMEM); 319 CLAW_DBF_TEXT_(2,setup,"probex%d",-ENOMEM);
320 return -ENOMEM; 320 return -ENOMEM;
321 } 321 }
322 memset(privptr,0x00,sizeof(struct claw_privbk));
323 privptr->p_mtc_envelope= kmalloc( MAX_ENVELOPE_SIZE, GFP_KERNEL); 322 privptr->p_mtc_envelope= kmalloc( MAX_ENVELOPE_SIZE, GFP_KERNEL);
324 privptr->p_env = kmalloc(sizeof(struct claw_env), GFP_KERNEL); 323 privptr->p_env = kmalloc(sizeof(struct claw_env), GFP_KERNEL);
325 if ((privptr->p_mtc_envelope==NULL) || (privptr->p_env==NULL)) { 324 if ((privptr->p_mtc_envelope==NULL) || (privptr->p_env==NULL)) {
diff --git a/drivers/s390/net/fsm.c b/drivers/s390/net/fsm.c
index 6caf5fa6a3..7145e2134c 100644
--- a/drivers/s390/net/fsm.c
+++ b/drivers/s390/net/fsm.c
@@ -21,38 +21,34 @@ init_fsm(char *name, const char **state_names, const char **event_names, int nr_
21 fsm_function_t *m; 21 fsm_function_t *m;
22 fsm *f; 22 fsm *f;
23 23
24 this = (fsm_instance *)kmalloc(sizeof(fsm_instance), order); 24 this = kzalloc(sizeof(fsm_instance), order);
25 if (this == NULL) { 25 if (this == NULL) {
26 printk(KERN_WARNING 26 printk(KERN_WARNING
27 "fsm(%s): init_fsm: Couldn't alloc instance\n", name); 27 "fsm(%s): init_fsm: Couldn't alloc instance\n", name);
28 return NULL; 28 return NULL;
29 } 29 }
30 memset(this, 0, sizeof(fsm_instance));
31 strlcpy(this->name, name, sizeof(this->name)); 30 strlcpy(this->name, name, sizeof(this->name));
32 31
33 f = (fsm *)kmalloc(sizeof(fsm), order); 32 f = kzalloc(sizeof(fsm), order);
34 if (f == NULL) { 33 if (f == NULL) {
35 printk(KERN_WARNING 34 printk(KERN_WARNING
36 "fsm(%s): init_fsm: Couldn't alloc fsm\n", name); 35 "fsm(%s): init_fsm: Couldn't alloc fsm\n", name);
37 kfree_fsm(this); 36 kfree_fsm(this);
38 return NULL; 37 return NULL;
39 } 38 }
40 memset(f, 0, sizeof(fsm));
41 f->nr_events = nr_events; 39 f->nr_events = nr_events;
42 f->nr_states = nr_states; 40 f->nr_states = nr_states;
43 f->event_names = event_names; 41 f->event_names = event_names;
44 f->state_names = state_names; 42 f->state_names = state_names;
45 this->f = f; 43 this->f = f;
46 44
47 m = (fsm_function_t *)kmalloc( 45 m = kcalloc(nr_states*nr_events, sizeof(fsm_function_t), order);
48 sizeof(fsm_function_t) * nr_states * nr_events, order);
49 if (m == NULL) { 46 if (m == NULL) {
50 printk(KERN_WARNING 47 printk(KERN_WARNING
51 "fsm(%s): init_fsm: Couldn't alloc jumptable\n", name); 48 "fsm(%s): init_fsm: Couldn't alloc jumptable\n", name);
52 kfree_fsm(this); 49 kfree_fsm(this);
53 return NULL; 50 return NULL;
54 } 51 }
55 memset(m, 0, sizeof(fsm_function_t) * f->nr_states * f->nr_events);
56 f->jumpmatrix = m; 52 f->jumpmatrix = m;
57 53
58 for (i = 0; i < tmpl_len; i++) { 54 for (i = 0; i < tmpl_len; i++) {
diff --git a/drivers/s390/net/iucv.c b/drivers/s390/net/iucv.c
index 760e77ec5a..6190be9dca 100644
--- a/drivers/s390/net/iucv.c
+++ b/drivers/s390/net/iucv.c
@@ -386,7 +386,7 @@ iucv_init(void)
386 } 386 }
387 387
388 /* Note: GFP_DMA used used to get memory below 2G */ 388 /* Note: GFP_DMA used used to get memory below 2G */
389 iucv_external_int_buffer = kmalloc(sizeof(iucv_GeneralInterrupt), 389 iucv_external_int_buffer = kzalloc(sizeof(iucv_GeneralInterrupt),
390 GFP_KERNEL|GFP_DMA); 390 GFP_KERNEL|GFP_DMA);
391 if (!iucv_external_int_buffer) { 391 if (!iucv_external_int_buffer) {
392 printk(KERN_WARNING 392 printk(KERN_WARNING
@@ -396,10 +396,9 @@ iucv_init(void)
396 bus_unregister(&iucv_bus); 396 bus_unregister(&iucv_bus);
397 return -ENOMEM; 397 return -ENOMEM;
398 } 398 }
399 memset(iucv_external_int_buffer, 0, sizeof(iucv_GeneralInterrupt));
400 399
401 /* Initialize parameter pool */ 400 /* Initialize parameter pool */
402 iucv_param_pool = kmalloc(sizeof(iucv_param) * PARAM_POOL_SIZE, 401 iucv_param_pool = kzalloc(sizeof(iucv_param) * PARAM_POOL_SIZE,
403 GFP_KERNEL|GFP_DMA); 402 GFP_KERNEL|GFP_DMA);
404 if (!iucv_param_pool) { 403 if (!iucv_param_pool) {
405 printk(KERN_WARNING "%s: Could not allocate param pool\n", 404 printk(KERN_WARNING "%s: Could not allocate param pool\n",
@@ -410,7 +409,6 @@ iucv_init(void)
410 bus_unregister(&iucv_bus); 409 bus_unregister(&iucv_bus);
411 return -ENOMEM; 410 return -ENOMEM;
412 } 411 }
413 memset(iucv_param_pool, 0, sizeof(iucv_param) * PARAM_POOL_SIZE);
414 412
415 /* Initialize irq queue */ 413 /* Initialize irq queue */
416 INIT_LIST_HEAD(&iucv_irq_queue); 414 INIT_LIST_HEAD(&iucv_irq_queue);
@@ -793,15 +791,14 @@ iucv_register_program (__u8 pgmname[16],
793 } 791 }
794 792
795 max_connections = iucv_query_maxconn(); 793 max_connections = iucv_query_maxconn();
796 iucv_pathid_table = kmalloc(max_connections * sizeof(handler *), 794 iucv_pathid_table = kcalloc(max_connections, sizeof(handler *),
797 GFP_ATOMIC); 795 GFP_ATOMIC);
798 if (iucv_pathid_table == NULL) { 796 if (iucv_pathid_table == NULL) {
799 printk(KERN_WARNING "%s: iucv_pathid_table storage " 797 printk(KERN_WARNING "%s: iucv_pathid_table storage "
800 "allocation failed\n", __FUNCTION__); 798 "allocation failed\n", __FUNCTION__);
801 kfree(new_handler); 799 kfree(new_handler);
802 return NULL; 800 return NULL;
803 } 801 }
804 memset (iucv_pathid_table, 0, max_connections * sizeof(handler *));
805 } 802 }
806 memset(new_handler, 0, sizeof (handler)); 803 memset(new_handler, 0, sizeof (handler));
807 memcpy(new_handler->id.user_data, pgmname, 804 memcpy(new_handler->id.user_data, pgmname,
diff --git a/drivers/s390/net/lcs.c b/drivers/s390/net/lcs.c
index 9cf88d7201..edcf05d5d5 100644
--- a/drivers/s390/net/lcs.c
+++ b/drivers/s390/net/lcs.c
@@ -115,11 +115,10 @@ lcs_alloc_channel(struct lcs_channel *channel)
115 LCS_DBF_TEXT(2, setup, "ichalloc"); 115 LCS_DBF_TEXT(2, setup, "ichalloc");
116 for (cnt = 0; cnt < LCS_NUM_BUFFS; cnt++) { 116 for (cnt = 0; cnt < LCS_NUM_BUFFS; cnt++) {
117 /* alloc memory fo iobuffer */ 117 /* alloc memory fo iobuffer */
118 channel->iob[cnt].data = (void *) 118 channel->iob[cnt].data =
119 kmalloc(LCS_IOBUFFERSIZE, GFP_DMA | GFP_KERNEL); 119 kzalloc(LCS_IOBUFFERSIZE, GFP_DMA | GFP_KERNEL);
120 if (channel->iob[cnt].data == NULL) 120 if (channel->iob[cnt].data == NULL)
121 break; 121 break;
122 memset(channel->iob[cnt].data, 0, LCS_IOBUFFERSIZE);
123 channel->iob[cnt].state = BUF_STATE_EMPTY; 122 channel->iob[cnt].state = BUF_STATE_EMPTY;
124 } 123 }
125 if (cnt < LCS_NUM_BUFFS) { 124 if (cnt < LCS_NUM_BUFFS) {
@@ -182,10 +181,9 @@ lcs_alloc_card(void)
182 181
183 LCS_DBF_TEXT(2, setup, "alloclcs"); 182 LCS_DBF_TEXT(2, setup, "alloclcs");
184 183
185 card = kmalloc(sizeof(struct lcs_card), GFP_KERNEL | GFP_DMA); 184 card = kzalloc(sizeof(struct lcs_card), GFP_KERNEL | GFP_DMA);
186 if (card == NULL) 185 if (card == NULL)
187 return NULL; 186 return NULL;
188 memset(card, 0, sizeof(struct lcs_card));
189 card->lan_type = LCS_FRAME_TYPE_AUTO; 187 card->lan_type = LCS_FRAME_TYPE_AUTO;
190 card->pkt_seq = 0; 188 card->pkt_seq = 0;
191 card->lancmd_timeout = LCS_LANCMD_TIMEOUT_DEFAULT; 189 card->lancmd_timeout = LCS_LANCMD_TIMEOUT_DEFAULT;
@@ -793,10 +791,9 @@ lcs_alloc_reply(struct lcs_cmd *cmd)
793 791
794 LCS_DBF_TEXT(4, trace, "getreply"); 792 LCS_DBF_TEXT(4, trace, "getreply");
795 793
796 reply = kmalloc(sizeof(struct lcs_reply), GFP_ATOMIC); 794 reply = kzalloc(sizeof(struct lcs_reply), GFP_ATOMIC);
797 if (!reply) 795 if (!reply)
798 return NULL; 796 return NULL;
799 memset(reply,0,sizeof(struct lcs_reply));
800 atomic_set(&reply->refcnt,1); 797 atomic_set(&reply->refcnt,1);
801 reply->sequence_no = cmd->sequence_no; 798 reply->sequence_no = cmd->sequence_no;
802 reply->received = 0; 799 reply->received = 0;
diff --git a/drivers/s390/net/netiucv.c b/drivers/s390/net/netiucv.c
index 71d3853e86..260a93c8c4 100644
--- a/drivers/s390/net/netiucv.c
+++ b/drivers/s390/net/netiucv.c
@@ -1728,14 +1728,13 @@ static int
1728netiucv_register_device(struct net_device *ndev) 1728netiucv_register_device(struct net_device *ndev)
1729{ 1729{
1730 struct netiucv_priv *priv = ndev->priv; 1730 struct netiucv_priv *priv = ndev->priv;
1731 struct device *dev = kmalloc(sizeof(struct device), GFP_KERNEL); 1731 struct device *dev = kzalloc(sizeof(struct device), GFP_KERNEL);
1732 int ret; 1732 int ret;
1733 1733
1734 1734
1735 IUCV_DBF_TEXT(trace, 3, __FUNCTION__); 1735 IUCV_DBF_TEXT(trace, 3, __FUNCTION__);
1736 1736
1737 if (dev) { 1737 if (dev) {
1738 memset(dev, 0, sizeof(struct device));
1739 snprintf(dev->bus_id, BUS_ID_SIZE, "net%s", ndev->name); 1738 snprintf(dev->bus_id, BUS_ID_SIZE, "net%s", ndev->name);
1740 dev->bus = &iucv_bus; 1739 dev->bus = &iucv_bus;
1741 dev->parent = iucv_root; 1740 dev->parent = iucv_root;
@@ -1784,11 +1783,9 @@ netiucv_new_connection(struct net_device *dev, char *username)
1784{ 1783{
1785 struct iucv_connection **clist = &iucv_connections; 1784 struct iucv_connection **clist = &iucv_connections;
1786 struct iucv_connection *conn = 1785 struct iucv_connection *conn =
1787 (struct iucv_connection *) 1786 kzalloc(sizeof(struct iucv_connection), GFP_KERNEL);
1788 kmalloc(sizeof(struct iucv_connection), GFP_KERNEL);
1789 1787
1790 if (conn) { 1788 if (conn) {
1791 memset(conn, 0, sizeof(struct iucv_connection));
1792 skb_queue_head_init(&conn->collect_queue); 1789 skb_queue_head_init(&conn->collect_queue);
1793 skb_queue_head_init(&conn->commit_queue); 1790 skb_queue_head_init(&conn->commit_queue);
1794 conn->max_buffsize = NETIUCV_BUFSIZE_DEFAULT; 1791 conn->max_buffsize = NETIUCV_BUFSIZE_DEFAULT;
diff --git a/drivers/s390/net/qeth_eddp.c b/drivers/s390/net/qeth_eddp.c
index 82cb4af2f0..44e226f211 100644
--- a/drivers/s390/net/qeth_eddp.c
+++ b/drivers/s390/net/qeth_eddp.c
@@ -389,9 +389,8 @@ qeth_eddp_create_eddp_data(struct qeth_hdr *qh, u8 *nh, u8 nhl, u8 *th, u8 thl)
389 struct qeth_eddp_data *eddp; 389 struct qeth_eddp_data *eddp;
390 390
391 QETH_DBF_TEXT(trace, 5, "eddpcrda"); 391 QETH_DBF_TEXT(trace, 5, "eddpcrda");
392 eddp = kmalloc(sizeof(struct qeth_eddp_data), GFP_ATOMIC); 392 eddp = kzalloc(sizeof(struct qeth_eddp_data), GFP_ATOMIC);
393 if (eddp){ 393 if (eddp){
394 memset(eddp, 0, sizeof(struct qeth_eddp_data));
395 eddp->nhl = nhl; 394 eddp->nhl = nhl;
396 eddp->thl = thl; 395 eddp->thl = thl;
397 memcpy(&eddp->qh, qh, sizeof(struct qeth_hdr)); 396 memcpy(&eddp->qh, qh, sizeof(struct qeth_hdr));
@@ -542,12 +541,11 @@ qeth_eddp_create_context_generic(struct qeth_card *card, struct sk_buff *skb,
542 541
543 QETH_DBF_TEXT(trace, 5, "creddpcg"); 542 QETH_DBF_TEXT(trace, 5, "creddpcg");
544 /* create the context and allocate pages */ 543 /* create the context and allocate pages */
545 ctx = kmalloc(sizeof(struct qeth_eddp_context), GFP_ATOMIC); 544 ctx = kzalloc(sizeof(struct qeth_eddp_context), GFP_ATOMIC);
546 if (ctx == NULL){ 545 if (ctx == NULL){
547 QETH_DBF_TEXT(trace, 2, "ceddpcn1"); 546 QETH_DBF_TEXT(trace, 2, "ceddpcn1");
548 return NULL; 547 return NULL;
549 } 548 }
550 memset(ctx, 0, sizeof(struct qeth_eddp_context));
551 ctx->type = QETH_LARGE_SEND_EDDP; 549 ctx->type = QETH_LARGE_SEND_EDDP;
552 qeth_eddp_calc_num_pages(ctx, skb, hdr_len); 550 qeth_eddp_calc_num_pages(ctx, skb, hdr_len);
553 if (ctx->elements_per_skb > QETH_MAX_BUFFER_ELEMENTS(card)){ 551 if (ctx->elements_per_skb > QETH_MAX_BUFFER_ELEMENTS(card)){
@@ -555,13 +553,12 @@ qeth_eddp_create_context_generic(struct qeth_card *card, struct sk_buff *skb,
555 kfree(ctx); 553 kfree(ctx);
556 return NULL; 554 return NULL;
557 } 555 }
558 ctx->pages = kmalloc(ctx->num_pages * sizeof(u8 *), GFP_ATOMIC); 556 ctx->pages = kcalloc(ctx->num_pages, sizeof(u8 *), GFP_ATOMIC);
559 if (ctx->pages == NULL){ 557 if (ctx->pages == NULL){
560 QETH_DBF_TEXT(trace, 2, "ceddpcn2"); 558 QETH_DBF_TEXT(trace, 2, "ceddpcn2");
561 kfree(ctx); 559 kfree(ctx);
562 return NULL; 560 return NULL;
563 } 561 }
564 memset(ctx->pages, 0, ctx->num_pages * sizeof(u8 *));
565 for (i = 0; i < ctx->num_pages; ++i){ 562 for (i = 0; i < ctx->num_pages; ++i){
566 addr = (u8 *)__get_free_page(GFP_ATOMIC); 563 addr = (u8 *)__get_free_page(GFP_ATOMIC);
567 if (addr == NULL){ 564 if (addr == NULL){
@@ -573,15 +570,13 @@ qeth_eddp_create_context_generic(struct qeth_card *card, struct sk_buff *skb,
573 memset(addr, 0, PAGE_SIZE); 570 memset(addr, 0, PAGE_SIZE);
574 ctx->pages[i] = addr; 571 ctx->pages[i] = addr;
575 } 572 }
576 ctx->elements = kmalloc(ctx->num_elements * 573 ctx->elements = kcalloc(ctx->num_elements,
577 sizeof(struct qeth_eddp_element), GFP_ATOMIC); 574 sizeof(struct qeth_eddp_element), GFP_ATOMIC);
578 if (ctx->elements == NULL){ 575 if (ctx->elements == NULL){
579 QETH_DBF_TEXT(trace, 2, "ceddpcn4"); 576 QETH_DBF_TEXT(trace, 2, "ceddpcn4");
580 qeth_eddp_free_context(ctx); 577 qeth_eddp_free_context(ctx);
581 return NULL; 578 return NULL;
582 } 579 }
583 memset(ctx->elements, 0,
584 ctx->num_elements * sizeof(struct qeth_eddp_element));
585 /* reset num_elements; will be incremented again in fill_buffer to 580 /* reset num_elements; will be incremented again in fill_buffer to
586 * reflect number of actually used elements */ 581 * reflect number of actually used elements */
587 ctx->num_elements = 0; 582 ctx->num_elements = 0;
diff --git a/drivers/s390/net/qeth_main.c b/drivers/s390/net/qeth_main.c
index 021cd5d08c..b3c6e79077 100644
--- a/drivers/s390/net/qeth_main.c
+++ b/drivers/s390/net/qeth_main.c
@@ -297,12 +297,10 @@ qeth_alloc_card(void)
297 struct qeth_card *card; 297 struct qeth_card *card;
298 298
299 QETH_DBF_TEXT(setup, 2, "alloccrd"); 299 QETH_DBF_TEXT(setup, 2, "alloccrd");
300 card = (struct qeth_card *) kmalloc(sizeof(struct qeth_card), 300 card = kzalloc(sizeof(struct qeth_card), GFP_DMA|GFP_KERNEL);
301 GFP_DMA|GFP_KERNEL);
302 if (!card) 301 if (!card)
303 return NULL; 302 return NULL;
304 QETH_DBF_HEX(setup, 2, &card, sizeof(void *)); 303 QETH_DBF_HEX(setup, 2, &card, sizeof(void *));
305 memset(card, 0, sizeof(struct qeth_card));
306 if (qeth_setup_channel(&card->read)) { 304 if (qeth_setup_channel(&card->read)) {
307 kfree(card); 305 kfree(card);
308 return NULL; 306 return NULL;
@@ -1632,9 +1630,8 @@ qeth_alloc_reply(struct qeth_card *card)
1632{ 1630{
1633 struct qeth_reply *reply; 1631 struct qeth_reply *reply;
1634 1632
1635 reply = kmalloc(sizeof(struct qeth_reply), GFP_ATOMIC); 1633 reply = kzalloc(sizeof(struct qeth_reply), GFP_ATOMIC);
1636 if (reply){ 1634 if (reply){
1637 memset(reply, 0, sizeof(struct qeth_reply));
1638 atomic_set(&reply->refcnt, 1); 1635 atomic_set(&reply->refcnt, 1);
1639 reply->card = card; 1636 reply->card = card;
1640 }; 1637 };
@@ -3348,13 +3345,11 @@ qeth_qdio_establish(struct qeth_card *card)
3348 3345
3349 QETH_DBF_TEXT(setup, 2, "qdioest"); 3346 QETH_DBF_TEXT(setup, 2, "qdioest");
3350 3347
3351 qib_param_field = kmalloc(QDIO_MAX_BUFFERS_PER_Q * sizeof(char), 3348 qib_param_field = kzalloc(QDIO_MAX_BUFFERS_PER_Q * sizeof(char),
3352 GFP_KERNEL); 3349 GFP_KERNEL);
3353 if (!qib_param_field) 3350 if (!qib_param_field)
3354 return -ENOMEM; 3351 return -ENOMEM;
3355 3352
3356 memset(qib_param_field, 0, QDIO_MAX_BUFFERS_PER_Q * sizeof(char));
3357
3358 qeth_create_qib_param_field(card, qib_param_field); 3353 qeth_create_qib_param_field(card, qib_param_field);
3359 qeth_create_qib_param_field_blkt(card, qib_param_field); 3354 qeth_create_qib_param_field_blkt(card, qib_param_field);
3360 3355
@@ -4819,9 +4814,8 @@ qeth_arp_query(struct qeth_card *card, char *udata)
4819 /* get size of userspace buffer and mask_bits -> 6 bytes */ 4814 /* get size of userspace buffer and mask_bits -> 6 bytes */
4820 if (copy_from_user(&qinfo, udata, 6)) 4815 if (copy_from_user(&qinfo, udata, 6))
4821 return -EFAULT; 4816 return -EFAULT;
4822 if (!(qinfo.udata = kmalloc(qinfo.udata_len, GFP_KERNEL))) 4817 if (!(qinfo.udata = kzalloc(qinfo.udata_len, GFP_KERNEL)))
4823 return -ENOMEM; 4818 return -ENOMEM;
4824 memset(qinfo.udata, 0, qinfo.udata_len);
4825 qinfo.udata_offset = QETH_QARP_ENTRIES_OFFSET; 4819 qinfo.udata_offset = QETH_QARP_ENTRIES_OFFSET;
4826 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING, 4820 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
4827 IPA_CMD_ASS_ARP_QUERY_INFO, 4821 IPA_CMD_ASS_ARP_QUERY_INFO,
@@ -4969,11 +4963,10 @@ qeth_snmp_command(struct qeth_card *card, char *udata)
4969 return -EFAULT; 4963 return -EFAULT;
4970 } 4964 }
4971 qinfo.udata_len = ureq->hdr.data_len; 4965 qinfo.udata_len = ureq->hdr.data_len;
4972 if (!(qinfo.udata = kmalloc(qinfo.udata_len, GFP_KERNEL))){ 4966 if (!(qinfo.udata = kzalloc(qinfo.udata_len, GFP_KERNEL))){
4973 kfree(ureq); 4967 kfree(ureq);
4974 return -ENOMEM; 4968 return -ENOMEM;
4975 } 4969 }
4976 memset(qinfo.udata, 0, qinfo.udata_len);
4977 qinfo.udata_offset = sizeof(struct qeth_snmp_ureq_hdr); 4970 qinfo.udata_offset = sizeof(struct qeth_snmp_ureq_hdr);
4978 4971
4979 iob = qeth_get_adapter_cmd(card, IPA_SETADP_SET_SNMP_CONTROL, 4972 iob = qeth_get_adapter_cmd(card, IPA_SETADP_SET_SNMP_CONTROL,
@@ -5564,12 +5557,11 @@ qeth_get_addr_buffer(enum qeth_prot_versions prot)
5564{ 5557{
5565 struct qeth_ipaddr *addr; 5558 struct qeth_ipaddr *addr;
5566 5559
5567 addr = kmalloc(sizeof(struct qeth_ipaddr), GFP_ATOMIC); 5560 addr = kzalloc(sizeof(struct qeth_ipaddr), GFP_ATOMIC);
5568 if (addr == NULL) { 5561 if (addr == NULL) {
5569 PRINT_WARN("Not enough memory to add address\n"); 5562 PRINT_WARN("Not enough memory to add address\n");
5570 return NULL; 5563 return NULL;
5571 } 5564 }
5572 memset(addr,0,sizeof(struct qeth_ipaddr));
5573 addr->type = QETH_IP_TYPE_NORMAL; 5565 addr->type = QETH_IP_TYPE_NORMAL;
5574 addr->proto = prot; 5566 addr->proto = prot;
5575 return addr; 5567 return addr;
diff --git a/drivers/s390/net/qeth_sys.c b/drivers/s390/net/qeth_sys.c
index f2a076a2b2..882d419e41 100644
--- a/drivers/s390/net/qeth_sys.c
+++ b/drivers/s390/net/qeth_sys.c
@@ -1145,11 +1145,10 @@ qeth_dev_ipato_add_store(const char *buf, size_t count,
1145 if ((rc = qeth_parse_ipatoe(buf, proto, addr, &mask_bits))) 1145 if ((rc = qeth_parse_ipatoe(buf, proto, addr, &mask_bits)))
1146 return rc; 1146 return rc;
1147 1147
1148 if (!(ipatoe = kmalloc(sizeof(struct qeth_ipato_entry), GFP_KERNEL))){ 1148 if (!(ipatoe = kzalloc(sizeof(struct qeth_ipato_entry), GFP_KERNEL))){
1149 PRINT_WARN("No memory to allocate ipato entry\n"); 1149 PRINT_WARN("No memory to allocate ipato entry\n");
1150 return -ENOMEM; 1150 return -ENOMEM;
1151 } 1151 }
1152 memset(ipatoe, 0, sizeof(struct qeth_ipato_entry));
1153 ipatoe->proto = proto; 1152 ipatoe->proto = proto;
1154 memcpy(ipatoe->addr, addr, (proto == QETH_PROT_IPV4)? 4:16); 1153 memcpy(ipatoe->addr, addr, (proto == QETH_PROT_IPV4)? 4:16);
1155 ipatoe->mask_bits = mask_bits; 1154 ipatoe->mask_bits = mask_bits;
diff --git a/drivers/s390/s390_rdev.c b/drivers/s390/s390_rdev.c
index e3f6471698..3c7145d9f9 100644
--- a/drivers/s390/s390_rdev.c
+++ b/drivers/s390/s390_rdev.c
@@ -27,10 +27,9 @@ s390_root_dev_register(const char *name)
27 27
28 if (!strlen(name)) 28 if (!strlen(name))
29 return ERR_PTR(-EINVAL); 29 return ERR_PTR(-EINVAL);
30 dev = kmalloc(sizeof(struct device), GFP_KERNEL); 30 dev = kzalloc(sizeof(struct device), GFP_KERNEL);
31 if (!dev) 31 if (!dev)
32 return ERR_PTR(-ENOMEM); 32 return ERR_PTR(-ENOMEM);
33 memset(dev, 0, sizeof(struct device));
34 strncpy(dev->bus_id, name, min(strlen(name), (size_t)BUS_ID_SIZE)); 33 strncpy(dev->bus_id, name, min(strlen(name), (size_t)BUS_ID_SIZE));
35 dev->release = s390_root_dev_release; 34 dev->release = s390_root_dev_release;
36 ret = device_register(dev); 35 ret = device_register(dev);
diff --git a/drivers/scsi/ata_piix.c b/drivers/scsi/ata_piix.c
index a74e23d39b..2d5be84d8b 100644
--- a/drivers/scsi/ata_piix.c
+++ b/drivers/scsi/ata_piix.c
@@ -742,7 +742,7 @@ static int piix_disable_ahci(struct pci_dev *pdev)
742/** 742/**
743 * piix_check_450nx_errata - Check for problem 450NX setup 743 * piix_check_450nx_errata - Check for problem 450NX setup
744 * @ata_dev: the PCI device to check 744 * @ata_dev: the PCI device to check
745 * 745 *
746 * Check for the present of 450NX errata #19 and errata #25. If 746 * Check for the present of 450NX errata #19 and errata #25. If
747 * they are found return an error code so we can turn off DMA 747 * they are found return an error code so we can turn off DMA
748 */ 748 */
@@ -753,7 +753,7 @@ static int __devinit piix_check_450nx_errata(struct pci_dev *ata_dev)
753 u16 cfg; 753 u16 cfg;
754 u8 rev; 754 u8 rev;
755 int no_piix_dma = 0; 755 int no_piix_dma = 0;
756 756
757 while((pdev = pci_get_device(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82454NX, pdev)) != NULL) 757 while((pdev = pci_get_device(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82454NX, pdev)) != NULL)
758 { 758 {
759 /* Look for 450NX PXB. Check for problem configurations 759 /* Look for 450NX PXB. Check for problem configurations
@@ -772,7 +772,7 @@ static int __devinit piix_check_450nx_errata(struct pci_dev *ata_dev)
772 if(no_piix_dma == 2) 772 if(no_piix_dma == 2)
773 dev_printk(KERN_WARNING, &ata_dev->dev, "A BIOS update may resolve this.\n"); 773 dev_printk(KERN_WARNING, &ata_dev->dev, "A BIOS update may resolve this.\n");
774 return no_piix_dma; 774 return no_piix_dma;
775} 775}
776 776
777static void __devinit piix_init_sata_map(struct pci_dev *pdev, 777static void __devinit piix_init_sata_map(struct pci_dev *pdev,
778 struct ata_port_info *pinfo) 778 struct ata_port_info *pinfo)
diff --git a/drivers/scsi/g_NCR5380.c b/drivers/scsi/g_NCR5380.c
index 45756fa907..e6bcfe9493 100644
--- a/drivers/scsi/g_NCR5380.c
+++ b/drivers/scsi/g_NCR5380.c
@@ -127,7 +127,7 @@ static int ncr_53c400a = NCR_NOT_SET;
127static int dtc_3181e = NCR_NOT_SET; 127static int dtc_3181e = NCR_NOT_SET;
128 128
129static struct override { 129static struct override {
130 NCR5380_implementation_fields; 130 NCR5380_map_type NCR5380_map_name;
131 int irq; 131 int irq;
132 int dma; 132 int dma;
133 int board; /* Use NCR53c400, Ricoh, etc. extensions ? */ 133 int board; /* Use NCR53c400, Ricoh, etc. extensions ? */
@@ -299,6 +299,10 @@ int __init generic_NCR5380_detect(struct scsi_host_template * tpnt)
299 }; 299 };
300 int flags = 0; 300 int flags = 0;
301 struct Scsi_Host *instance; 301 struct Scsi_Host *instance;
302#ifdef CONFIG_SCSI_G_NCR5380_MEM
303 unsigned long base;
304 void __iomem *iomem;
305#endif
302 306
303 if (ncr_irq != NCR_NOT_SET) 307 if (ncr_irq != NCR_NOT_SET)
304 overrides[0].irq = ncr_irq; 308 overrides[0].irq = ncr_irq;
@@ -424,15 +428,22 @@ int __init generic_NCR5380_detect(struct scsi_host_template * tpnt)
424 region_size = NCR5380_region_size; 428 region_size = NCR5380_region_size;
425 } 429 }
426#else 430#else
427 if(!request_mem_region(overrides[current_override].NCR5380_map_name, NCR5380_region_size, "ncr5380")) 431 base = overrides[current_override].NCR5380_map_name;
432 if (!request_mem_region(base, NCR5380_region_size, "ncr5380"))
433 continue;
434 iomem = ioremap(base, NCR5380_region_size);
435 if (!iomem) {
436 release_mem_region(base, NCR5380_region_size);
428 continue; 437 continue;
438 }
429#endif 439#endif
430 instance = scsi_register(tpnt, sizeof(struct NCR5380_hostdata)); 440 instance = scsi_register(tpnt, sizeof(struct NCR5380_hostdata));
431 if (instance == NULL) { 441 if (instance == NULL) {
432#ifndef CONFIG_SCSI_G_NCR5380_MEM 442#ifndef CONFIG_SCSI_G_NCR5380_MEM
433 release_region(overrides[current_override].NCR5380_map_name, region_size); 443 release_region(overrides[current_override].NCR5380_map_name, region_size);
434#else 444#else
435 release_mem_region(overrides[current_override].NCR5380_map_name, NCR5380_region_size); 445 iounmap(iomem);
446 release_mem_region(base, NCR5380_region_size);
436#endif 447#endif
437 continue; 448 continue;
438 } 449 }
@@ -440,6 +451,8 @@ int __init generic_NCR5380_detect(struct scsi_host_template * tpnt)
440 instance->NCR5380_instance_name = overrides[current_override].NCR5380_map_name; 451 instance->NCR5380_instance_name = overrides[current_override].NCR5380_map_name;
441#ifndef CONFIG_SCSI_G_NCR5380_MEM 452#ifndef CONFIG_SCSI_G_NCR5380_MEM
442 instance->n_io_port = region_size; 453 instance->n_io_port = region_size;
454#else
455 ((struct NCR5380_hostdata *)instance->hostdata).iomem = iomem;
443#endif 456#endif
444 457
445 NCR5380_init(instance, flags); 458 NCR5380_init(instance, flags);
@@ -509,6 +522,7 @@ int generic_NCR5380_release_resources(struct Scsi_Host *instance)
509#ifndef CONFIG_SCSI_G_NCR5380_MEM 522#ifndef CONFIG_SCSI_G_NCR5380_MEM
510 release_region(instance->NCR5380_instance_name, instance->n_io_port); 523 release_region(instance->NCR5380_instance_name, instance->n_io_port);
511#else 524#else
525 iounmap(((struct NCR5380_hostdata *)instance->hostdata).iomem);
512 release_mem_region(instance->NCR5380_instance_name, NCR5380_region_size); 526 release_mem_region(instance->NCR5380_instance_name, NCR5380_region_size);
513#endif 527#endif
514 528
@@ -586,7 +600,7 @@ static inline int NCR5380_pread(struct Scsi_Host *instance, unsigned char *dst,
586 } 600 }
587#else 601#else
588 /* implies CONFIG_SCSI_G_NCR5380_MEM */ 602 /* implies CONFIG_SCSI_G_NCR5380_MEM */
589 isa_memcpy_fromio(dst + start, NCR53C400_host_buffer + NCR5380_map_name, 128); 603 memcpy_fromio(dst + start, iomem + NCR53C400_host_buffer, 128);
590#endif 604#endif
591 start += 128; 605 start += 128;
592 blocks--; 606 blocks--;
@@ -606,7 +620,7 @@ static inline int NCR5380_pread(struct Scsi_Host *instance, unsigned char *dst,
606 } 620 }
607#else 621#else
608 /* implies CONFIG_SCSI_G_NCR5380_MEM */ 622 /* implies CONFIG_SCSI_G_NCR5380_MEM */
609 isa_memcpy_fromio(dst + start, NCR53C400_host_buffer + NCR5380_map_name, 128); 623 memcpy_fromio(dst + start, iomem + NCR53C400_host_buffer, 128);
610#endif 624#endif
611 start += 128; 625 start += 128;
612 blocks--; 626 blocks--;
@@ -671,7 +685,7 @@ static inline int NCR5380_pwrite(struct Scsi_Host *instance, unsigned char *src,
671 } 685 }
672#else 686#else
673 /* implies CONFIG_SCSI_G_NCR5380_MEM */ 687 /* implies CONFIG_SCSI_G_NCR5380_MEM */
674 isa_memcpy_toio(NCR53C400_host_buffer + NCR5380_map_name, src + start, 128); 688 memcpy_toio(iomem + NCR53C400_host_buffer, src + start, 128);
675#endif 689#endif
676 start += 128; 690 start += 128;
677 blocks--; 691 blocks--;
@@ -687,7 +701,7 @@ static inline int NCR5380_pwrite(struct Scsi_Host *instance, unsigned char *src,
687 } 701 }
688#else 702#else
689 /* implies CONFIG_SCSI_G_NCR5380_MEM */ 703 /* implies CONFIG_SCSI_G_NCR5380_MEM */
690 isa_memcpy_toio(NCR53C400_host_buffer + NCR5380_map_name, src + start, 128); 704 memcpy_toio(iomem + NCR53C400_host_buffer, src + start, 128);
691#endif 705#endif
692 start += 128; 706 start += 128;
693 blocks--; 707 blocks--;
diff --git a/drivers/scsi/g_NCR5380.h b/drivers/scsi/g_NCR5380.h
index 656fbe2f91..d60a89cb80 100644
--- a/drivers/scsi/g_NCR5380.h
+++ b/drivers/scsi/g_NCR5380.h
@@ -82,6 +82,15 @@ static const char* generic_NCR5380_info(struct Scsi_Host *);
82#define NCR5380_read(reg) (inb(NCR5380_map_name + (reg))) 82#define NCR5380_read(reg) (inb(NCR5380_map_name + (reg)))
83#define NCR5380_write(reg, value) (outb((value), (NCR5380_map_name + (reg)))) 83#define NCR5380_write(reg, value) (outb((value), (NCR5380_map_name + (reg))))
84 84
85#define NCR5380_implementation_fields \
86 NCR5380_map_type NCR5380_map_name
87
88#define NCR5380_local_declare() \
89 register NCR5380_implementation_fields
90
91#define NCR5380_setup(instance) \
92 NCR5380_map_name = (NCR5380_map_type)((instance)->NCR5380_instance_name)
93
85#else 94#else
86/* therefore CONFIG_SCSI_G_NCR5380_MEM */ 95/* therefore CONFIG_SCSI_G_NCR5380_MEM */
87 96
@@ -95,18 +104,20 @@ static const char* generic_NCR5380_info(struct Scsi_Host *);
95#define NCR53C400_host_buffer 0x3900 104#define NCR53C400_host_buffer 0x3900
96#define NCR5380_region_size 0x3a00 105#define NCR5380_region_size 0x3a00
97 106
98#define NCR5380_read(reg) isa_readb(NCR5380_map_name + NCR53C400_mem_base + (reg)) 107#define NCR5380_read(reg) readb(iomem + NCR53C400_mem_base + (reg))
99#define NCR5380_write(reg, value) isa_writeb(value, NCR5380_map_name + NCR53C400_mem_base + (reg)) 108#define NCR5380_write(reg, value) writeb(value, iomem + NCR53C400_mem_base + (reg))
100#endif
101 109
102#define NCR5380_implementation_fields \ 110#define NCR5380_implementation_fields \
103 NCR5380_map_type NCR5380_map_name 111 NCR5380_map_type NCR5380_map_name; \
112 void __iomem *iomem;
104 113
105#define NCR5380_local_declare() \ 114#define NCR5380_local_declare() \
106 register NCR5380_implementation_fields 115 register void __iomem *iomem
107 116
108#define NCR5380_setup(instance) \ 117#define NCR5380_setup(instance) \
109 NCR5380_map_name = (NCR5380_map_type)((instance)->NCR5380_instance_name) 118 iomem = (((struct NCR5380_hostdata *)(instance)->hostdata).iomem)
119
120#endif
110 121
111#define NCR5380_intr generic_NCR5380_intr 122#define NCR5380_intr generic_NCR5380_intr
112#define NCR5380_queue_command generic_NCR5380_queue_command 123#define NCR5380_queue_command generic_NCR5380_queue_command
diff --git a/drivers/scsi/ide-scsi.c b/drivers/scsi/ide-scsi.c
index 0cf0e4c7ac..39b760a242 100644
--- a/drivers/scsi/ide-scsi.c
+++ b/drivers/scsi/ide-scsi.c
@@ -47,6 +47,7 @@
47#include <linux/ide.h> 47#include <linux/ide.h>
48#include <linux/scatterlist.h> 48#include <linux/scatterlist.h>
49#include <linux/delay.h> 49#include <linux/delay.h>
50#include <linux/mutex.h>
50 51
51#include <asm/io.h> 52#include <asm/io.h>
52#include <asm/bitops.h> 53#include <asm/bitops.h>
@@ -109,7 +110,7 @@ typedef struct ide_scsi_obj {
109 unsigned long log; /* log flags */ 110 unsigned long log; /* log flags */
110} idescsi_scsi_t; 111} idescsi_scsi_t;
111 112
112static DECLARE_MUTEX(idescsi_ref_sem); 113static DEFINE_MUTEX(idescsi_ref_mutex);
113 114
114#define ide_scsi_g(disk) \ 115#define ide_scsi_g(disk) \
115 container_of((disk)->private_data, struct ide_scsi_obj, driver) 116 container_of((disk)->private_data, struct ide_scsi_obj, driver)
@@ -118,19 +119,19 @@ static struct ide_scsi_obj *ide_scsi_get(struct gendisk *disk)
118{ 119{
119 struct ide_scsi_obj *scsi = NULL; 120 struct ide_scsi_obj *scsi = NULL;
120 121
121 down(&idescsi_ref_sem); 122 mutex_lock(&idescsi_ref_mutex);
122 scsi = ide_scsi_g(disk); 123 scsi = ide_scsi_g(disk);
123 if (scsi) 124 if (scsi)
124 scsi_host_get(scsi->host); 125 scsi_host_get(scsi->host);
125 up(&idescsi_ref_sem); 126 mutex_unlock(&idescsi_ref_mutex);
126 return scsi; 127 return scsi;
127} 128}
128 129
129static void ide_scsi_put(struct ide_scsi_obj *scsi) 130static void ide_scsi_put(struct ide_scsi_obj *scsi)
130{ 131{
131 down(&idescsi_ref_sem); 132 mutex_lock(&idescsi_ref_mutex);
132 scsi_host_put(scsi->host); 133 scsi_host_put(scsi->host);
133 up(&idescsi_ref_sem); 134 mutex_unlock(&idescsi_ref_mutex);
134} 135}
135 136
136static inline idescsi_scsi_t *scsihost_to_idescsi(struct Scsi_Host *host) 137static inline idescsi_scsi_t *scsihost_to_idescsi(struct Scsi_Host *host)
diff --git a/drivers/scsi/in2000.c b/drivers/scsi/in2000.c
index 34daa3e068..9c519876f8 100644
--- a/drivers/scsi/in2000.c
+++ b/drivers/scsi/in2000.c
@@ -1898,6 +1898,21 @@ static int int_tab[] in2000__INITDATA = {
1898 10 1898 10
1899}; 1899};
1900 1900
1901static int probe_bios(u32 addr, u32 *s1, uchar *switches)
1902{
1903 void __iomem *p = ioremap(addr, 0x34);
1904 if (!p)
1905 return 0;
1906 *s1 = readl(p + 0x10);
1907 if (*s1 == 0x41564f4e || readl(p + 0x30) == 0x61776c41) {
1908 /* Read the switch image that's mapped into EPROM space */
1909 *switches = ~readb(p + 0x20);
1910 iounmap(p);
1911 return 1;
1912 }
1913 iounmap(p);
1914 return 0;
1915}
1901 1916
1902static int __init in2000_detect(struct scsi_host_template * tpnt) 1917static int __init in2000_detect(struct scsi_host_template * tpnt)
1903{ 1918{
@@ -1930,6 +1945,7 @@ static int __init in2000_detect(struct scsi_host_template * tpnt)
1930 1945
1931 detect_count = 0; 1946 detect_count = 0;
1932 for (bios = 0; bios_tab[bios]; bios++) { 1947 for (bios = 0; bios_tab[bios]; bios++) {
1948 u32 s1 = 0;
1933 if (check_setup_args("ioport", &val, buf)) { 1949 if (check_setup_args("ioport", &val, buf)) {
1934 base = val; 1950 base = val;
1935 switches = ~inb(base + IO_SWITCHES) & 0xff; 1951 switches = ~inb(base + IO_SWITCHES) & 0xff;
@@ -1941,13 +1957,9 @@ static int __init in2000_detect(struct scsi_host_template * tpnt)
1941 * for the obvious ID strings. We look for the 2 most common ones and 1957 * for the obvious ID strings. We look for the 2 most common ones and
1942 * hope that they cover all the cases... 1958 * hope that they cover all the cases...
1943 */ 1959 */
1944 else if (isa_readl(bios_tab[bios] + 0x10) == 0x41564f4e || isa_readl(bios_tab[bios] + 0x30) == 0x61776c41) { 1960 else if (probe_bios(bios_tab[bios], &s1, &switches)) {
1945 printk("Found IN2000 BIOS at 0x%x ", (unsigned int) bios_tab[bios]); 1961 printk("Found IN2000 BIOS at 0x%x ", (unsigned int) bios_tab[bios]);
1946 1962
1947/* Read the switch image that's mapped into EPROM space */
1948
1949 switches = ~((isa_readb(bios_tab[bios] + 0x20) & 0xff));
1950
1951/* Find out where the IO space is */ 1963/* Find out where the IO space is */
1952 1964
1953 x = switches & (SW_ADDR0 | SW_ADDR1); 1965 x = switches & (SW_ADDR0 | SW_ADDR1);
@@ -2037,7 +2049,7 @@ static int __init in2000_detect(struct scsi_host_template * tpnt)
2037 2049
2038/* Older BIOS's had a 'sync on/off' switch - use its setting */ 2050/* Older BIOS's had a 'sync on/off' switch - use its setting */
2039 2051
2040 if (isa_readl(bios_tab[bios] + 0x10) == 0x41564f4e && (switches & SW_SYNC_DOS5)) 2052 if (s1 == 0x41564f4e && (switches & SW_SYNC_DOS5))
2041 hostdata->sync_off = 0x00; /* sync defaults to on */ 2053 hostdata->sync_off = 0x00; /* sync defaults to on */
2042 else 2054 else
2043 hostdata->sync_off = 0xff; /* sync defaults to off */ 2055 hostdata->sync_off = 0xff; /* sync defaults to off */
diff --git a/drivers/scsi/libata-bmdma.c b/drivers/scsi/libata-bmdma.c
index a00a78b308..95d81d86d8 100644
--- a/drivers/scsi/libata-bmdma.c
+++ b/drivers/scsi/libata-bmdma.c
@@ -941,7 +941,7 @@ err_out:
941 * @pdev: PCI device 941 * @pdev: PCI device
942 * 942 *
943 * Some PCI ATA devices report simplex mode but in fact can be told to 943 * Some PCI ATA devices report simplex mode but in fact can be told to
944 * enter non simplex mode. This implements the neccessary logic to 944 * enter non simplex mode. This implements the neccessary logic to
945 * perform the task on such devices. Calling it on other devices will 945 * perform the task on such devices. Calling it on other devices will
946 * have -undefined- behaviour. 946 * have -undefined- behaviour.
947 */ 947 */
@@ -966,7 +966,7 @@ unsigned long ata_pci_default_filter(const struct ata_port *ap, struct ata_devic
966{ 966{
967 /* Filter out DMA modes if the device has been configured by 967 /* Filter out DMA modes if the device has been configured by
968 the BIOS as PIO only */ 968 the BIOS as PIO only */
969 969
970 if (ap->ioaddr.bmdma_addr == 0) 970 if (ap->ioaddr.bmdma_addr == 0)
971 xfer_mask &= ~(ATA_MASK_MWDMA | ATA_MASK_UDMA); 971 xfer_mask &= ~(ATA_MASK_MWDMA | ATA_MASK_UDMA);
972 return xfer_mask; 972 return xfer_mask;
diff --git a/drivers/scsi/libata-core.c b/drivers/scsi/libata-core.c
index dcce0f494d..c3c4263fdb 100644
--- a/drivers/scsi/libata-core.c
+++ b/drivers/scsi/libata-core.c
@@ -64,10 +64,10 @@
64static unsigned int ata_dev_init_params(struct ata_port *ap, 64static unsigned int ata_dev_init_params(struct ata_port *ap,
65 struct ata_device *dev); 65 struct ata_device *dev);
66static void ata_set_mode(struct ata_port *ap); 66static void ata_set_mode(struct ata_port *ap);
67static void ata_dev_set_xfermode(struct ata_port *ap, struct ata_device *dev); 67static unsigned int ata_dev_set_xfermode(struct ata_port *ap,
68 struct ata_device *dev);
69static void ata_dev_xfermask(struct ata_port *ap, struct ata_device *dev);
68static void ata_pio_error(struct ata_port *ap); 70static void ata_pio_error(struct ata_port *ap);
69static unsigned int ata_dev_xfermask(struct ata_port *ap,
70 struct ata_device *dev);
71 71
72static unsigned int ata_unique_id = 1; 72static unsigned int ata_unique_id = 1;
73static struct workqueue_struct *ata_wq; 73static struct workqueue_struct *ata_wq;
@@ -191,7 +191,7 @@ static const u8 ata_rw_cmds[] = {
191 * ata_rwcmd_protocol - set taskfile r/w commands and protocol 191 * ata_rwcmd_protocol - set taskfile r/w commands and protocol
192 * @qc: command to examine and configure 192 * @qc: command to examine and configure
193 * 193 *
194 * Examine the device configuration and tf->flags to calculate 194 * Examine the device configuration and tf->flags to calculate
195 * the proper read/write commands and protocol to use. 195 * the proper read/write commands and protocol to use.
196 * 196 *
197 * LOCKING: 197 * LOCKING:
@@ -204,7 +204,7 @@ int ata_rwcmd_protocol(struct ata_queued_cmd *qc)
204 u8 cmd; 204 u8 cmd;
205 205
206 int index, fua, lba48, write; 206 int index, fua, lba48, write;
207 207
208 fua = (tf->flags & ATA_TFLAG_FUA) ? 4 : 0; 208 fua = (tf->flags & ATA_TFLAG_FUA) ? 4 : 0;
209 lba48 = (tf->flags & ATA_TFLAG_LBA48) ? 2 : 0; 209 lba48 = (tf->flags & ATA_TFLAG_LBA48) ? 2 : 0;
210 write = (tf->flags & ATA_TFLAG_WRITE) ? 1 : 0; 210 write = (tf->flags & ATA_TFLAG_WRITE) ? 1 : 0;
@@ -253,6 +253,29 @@ static unsigned int ata_pack_xfermask(unsigned int pio_mask,
253 ((udma_mask << ATA_SHIFT_UDMA) & ATA_MASK_UDMA); 253 ((udma_mask << ATA_SHIFT_UDMA) & ATA_MASK_UDMA);
254} 254}
255 255
256/**
257 * ata_unpack_xfermask - Unpack xfer_mask into pio, mwdma and udma masks
258 * @xfer_mask: xfer_mask to unpack
259 * @pio_mask: resulting pio_mask
260 * @mwdma_mask: resulting mwdma_mask
261 * @udma_mask: resulting udma_mask
262 *
263 * Unpack @xfer_mask into @pio_mask, @mwdma_mask and @udma_mask.
264 * Any NULL distination masks will be ignored.
265 */
266static void ata_unpack_xfermask(unsigned int xfer_mask,
267 unsigned int *pio_mask,
268 unsigned int *mwdma_mask,
269 unsigned int *udma_mask)
270{
271 if (pio_mask)
272 *pio_mask = (xfer_mask & ATA_MASK_PIO) >> ATA_SHIFT_PIO;
273 if (mwdma_mask)
274 *mwdma_mask = (xfer_mask & ATA_MASK_MWDMA) >> ATA_SHIFT_MWDMA;
275 if (udma_mask)
276 *udma_mask = (xfer_mask & ATA_MASK_UDMA) >> ATA_SHIFT_UDMA;
277}
278
256static const struct ata_xfer_ent { 279static const struct ata_xfer_ent {
257 unsigned int shift, bits; 280 unsigned int shift, bits;
258 u8 base; 281 u8 base;
@@ -373,6 +396,15 @@ static const char *ata_mode_string(unsigned int xfer_mask)
373 return "<n/a>"; 396 return "<n/a>";
374} 397}
375 398
399static void ata_dev_disable(struct ata_port *ap, struct ata_device *dev)
400{
401 if (ata_dev_present(dev)) {
402 printk(KERN_WARNING "ata%u: dev %u disabled\n",
403 ap->id, dev->devno);
404 dev->class++;
405 }
406}
407
376/** 408/**
377 * ata_pio_devchk - PATA device presence detection 409 * ata_pio_devchk - PATA device presence detection
378 * @ap: ATA channel to examine 410 * @ap: ATA channel to examine
@@ -988,6 +1020,22 @@ ata_exec_internal(struct ata_port *ap, struct ata_device *dev,
988 1020
989 ata_qc_free(qc); 1021 ata_qc_free(qc);
990 1022
1023 /* XXX - Some LLDDs (sata_mv) disable port on command failure.
1024 * Until those drivers are fixed, we detect the condition
1025 * here, fail the command with AC_ERR_SYSTEM and reenable the
1026 * port.
1027 *
1028 * Note that this doesn't change any behavior as internal
1029 * command failure results in disabling the device in the
1030 * higher layer for LLDDs without new reset/EH callbacks.
1031 *
1032 * Kill the following code as soon as those drivers are fixed.
1033 */
1034 if (ap->flags & ATA_FLAG_PORT_DISABLED) {
1035 err_mask |= AC_ERR_SYSTEM;
1036 ata_port_probe(ap);
1037 }
1038
991 return err_mask; 1039 return err_mask;
992} 1040}
993 1041
@@ -1008,7 +1056,7 @@ unsigned int ata_pio_need_iordy(const struct ata_device *adev)
1008 return 0; 1056 return 0;
1009 if (speed > 2) 1057 if (speed > 2)
1010 return 1; 1058 return 1;
1011 1059
1012 /* If we have no drive specific rule, then PIO 2 is non IORDY */ 1060 /* If we have no drive specific rule, then PIO 2 is non IORDY */
1013 1061
1014 if (adev->id[ATA_ID_FIELD_VALID] & 2) { /* EIDE */ 1062 if (adev->id[ATA_ID_FIELD_VALID] & 2) { /* EIDE */
@@ -1034,9 +1082,8 @@ unsigned int ata_pio_need_iordy(const struct ata_device *adev)
1034 * 1082 *
1035 * Read ID data from the specified device. ATA_CMD_ID_ATA is 1083 * Read ID data from the specified device. ATA_CMD_ID_ATA is
1036 * performed on ATA devices and ATA_CMD_ID_ATAPI on ATAPI 1084 * performed on ATA devices and ATA_CMD_ID_ATAPI on ATAPI
1037 * devices. This function also takes care of EDD signature 1085 * devices. This function also issues ATA_CMD_INIT_DEV_PARAMS
1038 * misreporting (to be removed once EDD support is gone) and 1086 * for pre-ATA4 drives.
1039 * issues ATA_CMD_INIT_DEV_PARAMS for pre-ATA4 drives.
1040 * 1087 *
1041 * LOCKING: 1088 * LOCKING:
1042 * Kernel thread context (may sleep) 1089 * Kernel thread context (may sleep)
@@ -1048,7 +1095,6 @@ static int ata_dev_read_id(struct ata_port *ap, struct ata_device *dev,
1048 unsigned int *p_class, int post_reset, u16 **p_id) 1095 unsigned int *p_class, int post_reset, u16 **p_id)
1049{ 1096{
1050 unsigned int class = *p_class; 1097 unsigned int class = *p_class;
1051 unsigned int using_edd;
1052 struct ata_taskfile tf; 1098 struct ata_taskfile tf;
1053 unsigned int err_mask = 0; 1099 unsigned int err_mask = 0;
1054 u16 *id; 1100 u16 *id;
@@ -1057,12 +1103,6 @@ static int ata_dev_read_id(struct ata_port *ap, struct ata_device *dev,
1057 1103
1058 DPRINTK("ENTER, host %u, dev %u\n", ap->id, dev->devno); 1104 DPRINTK("ENTER, host %u, dev %u\n", ap->id, dev->devno);
1059 1105
1060 if (ap->ops->probe_reset ||
1061 ap->flags & (ATA_FLAG_SRST | ATA_FLAG_SATA_RESET))
1062 using_edd = 0;
1063 else
1064 using_edd = 1;
1065
1066 ata_dev_select(ap, dev->devno, 1, 1); /* select device 0/1 */ 1106 ata_dev_select(ap, dev->devno, 1, 1); /* select device 0/1 */
1067 1107
1068 id = kmalloc(sizeof(id[0]) * ATA_ID_WORDS, GFP_KERNEL); 1108 id = kmalloc(sizeof(id[0]) * ATA_ID_WORDS, GFP_KERNEL);
@@ -1092,32 +1132,9 @@ static int ata_dev_read_id(struct ata_port *ap, struct ata_device *dev,
1092 1132
1093 err_mask = ata_exec_internal(ap, dev, &tf, DMA_FROM_DEVICE, 1133 err_mask = ata_exec_internal(ap, dev, &tf, DMA_FROM_DEVICE,
1094 id, sizeof(id[0]) * ATA_ID_WORDS); 1134 id, sizeof(id[0]) * ATA_ID_WORDS);
1095
1096 if (err_mask) { 1135 if (err_mask) {
1097 rc = -EIO; 1136 rc = -EIO;
1098 reason = "I/O error"; 1137 reason = "I/O error";
1099
1100 if (err_mask & ~AC_ERR_DEV)
1101 goto err_out;
1102
1103 /*
1104 * arg! EDD works for all test cases, but seems to return
1105 * the ATA signature for some ATAPI devices. Until the
1106 * reason for this is found and fixed, we fix up the mess
1107 * here. If IDENTIFY DEVICE returns command aborted
1108 * (as ATAPI devices do), then we issue an
1109 * IDENTIFY PACKET DEVICE.
1110 *
1111 * ATA software reset (SRST, the default) does not appear
1112 * to have this problem.
1113 */
1114 if ((using_edd) && (class == ATA_DEV_ATA)) {
1115 u8 err = tf.feature;
1116 if (err & ATA_ABORTED) {
1117 class = ATA_DEV_ATAPI;
1118 goto retry;
1119 }
1120 }
1121 goto err_out; 1138 goto err_out;
1122 } 1139 }
1123 1140
@@ -1314,7 +1331,7 @@ static int ata_dev_configure(struct ata_port *ap, struct ata_device *dev,
1314 if (print_info) 1331 if (print_info)
1315 printk(KERN_INFO "ata%u(%u): applying bridge limits\n", 1332 printk(KERN_INFO "ata%u(%u): applying bridge limits\n",
1316 ap->id, dev->devno); 1333 ap->id, dev->devno);
1317 ap->udma_mask &= ATA_UDMA5; 1334 dev->udma_mask &= ATA_UDMA5;
1318 dev->max_sectors = ATA_MAX_SECTORS; 1335 dev->max_sectors = ATA_MAX_SECTORS;
1319 } 1336 }
1320 1337
@@ -1325,8 +1342,6 @@ static int ata_dev_configure(struct ata_port *ap, struct ata_device *dev,
1325 return 0; 1342 return 0;
1326 1343
1327err_out_nosup: 1344err_out_nosup:
1328 printk(KERN_WARNING "ata%u: dev %u not supported, ignoring\n",
1329 ap->id, dev->devno);
1330 DPRINTK("EXIT, err\n"); 1345 DPRINTK("EXIT, err\n");
1331 return rc; 1346 return rc;
1332} 1347}
@@ -1393,7 +1408,7 @@ static int ata_bus_probe(struct ata_port *ap)
1393 } 1408 }
1394 1409
1395 if (ata_dev_configure(ap, dev, 1)) { 1410 if (ata_dev_configure(ap, dev, 1)) {
1396 dev->class++; /* disable device */ 1411 ata_dev_disable(ap, dev);
1397 continue; 1412 continue;
1398 } 1413 }
1399 1414
@@ -1539,6 +1554,23 @@ void sata_phy_reset(struct ata_port *ap)
1539} 1554}
1540 1555
1541/** 1556/**
1557 * ata_dev_pair - return other device on cable
1558 * @ap: port
1559 * @adev: device
1560 *
1561 * Obtain the other device on the same cable, or if none is
1562 * present NULL is returned
1563 */
1564
1565struct ata_device *ata_dev_pair(struct ata_port *ap, struct ata_device *adev)
1566{
1567 struct ata_device *pair = &ap->device[1 - adev->devno];
1568 if (!ata_dev_present(pair))
1569 return NULL;
1570 return pair;
1571}
1572
1573/**
1542 * ata_port_disable - Disable port. 1574 * ata_port_disable - Disable port.
1543 * @ap: Port to be disabled. 1575 * @ap: Port to be disabled.
1544 * 1576 *
@@ -1566,7 +1598,7 @@ void ata_port_disable(struct ata_port *ap)
1566 * PIO 0-5, MWDMA 0-2 and UDMA 0-6 timings (in nanoseconds). 1598 * PIO 0-5, MWDMA 0-2 and UDMA 0-6 timings (in nanoseconds).
1567 * These were taken from ATA/ATAPI-6 standard, rev 0a, except 1599 * These were taken from ATA/ATAPI-6 standard, rev 0a, except
1568 * for PIO 5, which is a nonstandard extension and UDMA6, which 1600 * for PIO 5, which is a nonstandard extension and UDMA6, which
1569 * is currently supported only by Maxtor drives. 1601 * is currently supported only by Maxtor drives.
1570 */ 1602 */
1571 1603
1572static const struct ata_timing ata_timing[] = { 1604static const struct ata_timing ata_timing[] = {
@@ -1581,11 +1613,11 @@ static const struct ata_timing ata_timing[] = {
1581 { XFER_UDMA_0, 0, 0, 0, 0, 0, 0, 0, 120 }, 1613 { XFER_UDMA_0, 0, 0, 0, 0, 0, 0, 0, 120 },
1582 1614
1583/* { XFER_UDMA_SLOW, 0, 0, 0, 0, 0, 0, 0, 150 }, */ 1615/* { XFER_UDMA_SLOW, 0, 0, 0, 0, 0, 0, 0, 150 }, */
1584 1616
1585 { XFER_MW_DMA_2, 25, 0, 0, 0, 70, 25, 120, 0 }, 1617 { XFER_MW_DMA_2, 25, 0, 0, 0, 70, 25, 120, 0 },
1586 { XFER_MW_DMA_1, 45, 0, 0, 0, 80, 50, 150, 0 }, 1618 { XFER_MW_DMA_1, 45, 0, 0, 0, 80, 50, 150, 0 },
1587 { XFER_MW_DMA_0, 60, 0, 0, 0, 215, 215, 480, 0 }, 1619 { XFER_MW_DMA_0, 60, 0, 0, 0, 215, 215, 480, 0 },
1588 1620
1589 { XFER_SW_DMA_2, 60, 0, 0, 0, 120, 120, 240, 0 }, 1621 { XFER_SW_DMA_2, 60, 0, 0, 0, 120, 120, 240, 0 },
1590 { XFER_SW_DMA_1, 90, 0, 0, 0, 240, 240, 480, 0 }, 1622 { XFER_SW_DMA_1, 90, 0, 0, 0, 240, 240, 480, 0 },
1591 { XFER_SW_DMA_0, 120, 0, 0, 0, 480, 480, 960, 0 }, 1623 { XFER_SW_DMA_0, 120, 0, 0, 0, 480, 480, 960, 0 },
@@ -1638,7 +1670,7 @@ static const struct ata_timing* ata_timing_find_mode(unsigned short speed)
1638 for (t = ata_timing; t->mode != speed; t++) 1670 for (t = ata_timing; t->mode != speed; t++)
1639 if (t->mode == 0xFF) 1671 if (t->mode == 0xFF)
1640 return NULL; 1672 return NULL;
1641 return t; 1673 return t;
1642} 1674}
1643 1675
1644int ata_timing_compute(struct ata_device *adev, unsigned short speed, 1676int ata_timing_compute(struct ata_device *adev, unsigned short speed,
@@ -1648,7 +1680,7 @@ int ata_timing_compute(struct ata_device *adev, unsigned short speed,
1648 struct ata_timing p; 1680 struct ata_timing p;
1649 1681
1650 /* 1682 /*
1651 * Find the mode. 1683 * Find the mode.
1652 */ 1684 */
1653 1685
1654 if (!(s = ata_timing_find_mode(speed))) 1686 if (!(s = ata_timing_find_mode(speed)))
@@ -1706,20 +1738,28 @@ int ata_timing_compute(struct ata_device *adev, unsigned short speed,
1706 return 0; 1738 return 0;
1707} 1739}
1708 1740
1709static void ata_dev_set_mode(struct ata_port *ap, struct ata_device *dev) 1741static int ata_dev_set_mode(struct ata_port *ap, struct ata_device *dev)
1710{ 1742{
1711 if (!ata_dev_present(dev) || (ap->flags & ATA_FLAG_PORT_DISABLED)) 1743 unsigned int err_mask;
1712 return; 1744 int rc;
1713 1745
1714 if (dev->xfer_shift == ATA_SHIFT_PIO) 1746 if (dev->xfer_shift == ATA_SHIFT_PIO)
1715 dev->flags |= ATA_DFLAG_PIO; 1747 dev->flags |= ATA_DFLAG_PIO;
1716 1748
1717 ata_dev_set_xfermode(ap, dev); 1749 err_mask = ata_dev_set_xfermode(ap, dev);
1750 if (err_mask) {
1751 printk(KERN_ERR
1752 "ata%u: failed to set xfermode (err_mask=0x%x)\n",
1753 ap->id, err_mask);
1754 return -EIO;
1755 }
1718 1756
1719 if (ata_dev_revalidate(ap, dev, 0)) { 1757 rc = ata_dev_revalidate(ap, dev, 0);
1720 printk(KERN_ERR "ata%u: failed to revalidate after set " 1758 if (rc) {
1721 "xfermode, disabled\n", ap->id); 1759 printk(KERN_ERR
1722 ata_port_disable(ap); 1760 "ata%u: failed to revalidate after set xfermode\n",
1761 ap->id);
1762 return rc;
1723 } 1763 }
1724 1764
1725 DPRINTK("xfer_shift=%u, xfer_mode=0x%x\n", 1765 DPRINTK("xfer_shift=%u, xfer_mode=0x%x\n",
@@ -1728,6 +1768,7 @@ static void ata_dev_set_mode(struct ata_port *ap, struct ata_device *dev)
1728 printk(KERN_INFO "ata%u: dev %u configured for %s\n", 1768 printk(KERN_INFO "ata%u: dev %u configured for %s\n",
1729 ap->id, dev->devno, 1769 ap->id, dev->devno,
1730 ata_mode_string(ata_xfer_mode2mask(dev->xfer_mode))); 1770 ata_mode_string(ata_xfer_mode2mask(dev->xfer_mode)));
1771 return 0;
1731} 1772}
1732 1773
1733static int ata_host_set_pio(struct ata_port *ap) 1774static int ata_host_set_pio(struct ata_port *ap)
@@ -1787,16 +1828,19 @@ static void ata_set_mode(struct ata_port *ap)
1787 /* step 1: calculate xfer_mask */ 1828 /* step 1: calculate xfer_mask */
1788 for (i = 0; i < ATA_MAX_DEVICES; i++) { 1829 for (i = 0; i < ATA_MAX_DEVICES; i++) {
1789 struct ata_device *dev = &ap->device[i]; 1830 struct ata_device *dev = &ap->device[i];
1790 unsigned int xfer_mask; 1831 unsigned int pio_mask, dma_mask;
1791 1832
1792 if (!ata_dev_present(dev)) 1833 if (!ata_dev_present(dev))
1793 continue; 1834 continue;
1794 1835
1795 xfer_mask = ata_dev_xfermask(ap, dev); 1836 ata_dev_xfermask(ap, dev);
1837
1838 /* TODO: let LLDD filter dev->*_mask here */
1796 1839
1797 dev->pio_mode = ata_xfer_mask2mode(xfer_mask & ATA_MASK_PIO); 1840 pio_mask = ata_pack_xfermask(dev->pio_mask, 0, 0);
1798 dev->dma_mode = ata_xfer_mask2mode(xfer_mask & (ATA_MASK_MWDMA | 1841 dma_mask = ata_pack_xfermask(0, dev->mwdma_mask, dev->udma_mask);
1799 ATA_MASK_UDMA)); 1842 dev->pio_mode = ata_xfer_mask2mode(pio_mask);
1843 dev->dma_mode = ata_xfer_mask2mode(dma_mask);
1800 } 1844 }
1801 1845
1802 /* step 2: always set host PIO timings */ 1846 /* step 2: always set host PIO timings */
@@ -1808,11 +1852,15 @@ static void ata_set_mode(struct ata_port *ap)
1808 ata_host_set_dma(ap); 1852 ata_host_set_dma(ap);
1809 1853
1810 /* step 4: update devices' xfer mode */ 1854 /* step 4: update devices' xfer mode */
1811 for (i = 0; i < ATA_MAX_DEVICES; i++) 1855 for (i = 0; i < ATA_MAX_DEVICES; i++) {
1812 ata_dev_set_mode(ap, &ap->device[i]); 1856 struct ata_device *dev = &ap->device[i];
1813 1857
1814 if (ap->flags & ATA_FLAG_PORT_DISABLED) 1858 if (!ata_dev_present(dev))
1815 return; 1859 continue;
1860
1861 if (ata_dev_set_mode(ap, dev))
1862 goto err_out;
1863 }
1816 1864
1817 if (ap->ops->post_set_mode) 1865 if (ap->ops->post_set_mode)
1818 ap->ops->post_set_mode(ap); 1866 ap->ops->post_set_mode(ap);
@@ -1935,45 +1983,6 @@ static void ata_bus_post_reset(struct ata_port *ap, unsigned int devmask)
1935 ap->ops->dev_select(ap, 0); 1983 ap->ops->dev_select(ap, 0);
1936} 1984}
1937 1985
1938/**
1939 * ata_bus_edd - Issue EXECUTE DEVICE DIAGNOSTIC command.
1940 * @ap: Port to reset and probe
1941 *
1942 * Use the EXECUTE DEVICE DIAGNOSTIC command to reset and
1943 * probe the bus. Not often used these days.
1944 *
1945 * LOCKING:
1946 * PCI/etc. bus probe sem.
1947 * Obtains host_set lock.
1948 *
1949 */
1950
1951static unsigned int ata_bus_edd(struct ata_port *ap)
1952{
1953 struct ata_taskfile tf;
1954 unsigned long flags;
1955
1956 /* set up execute-device-diag (bus reset) taskfile */
1957 /* also, take interrupts to a known state (disabled) */
1958 DPRINTK("execute-device-diag\n");
1959 ata_tf_init(ap, &tf, 0);
1960 tf.ctl |= ATA_NIEN;
1961 tf.command = ATA_CMD_EDD;
1962 tf.protocol = ATA_PROT_NODATA;
1963
1964 /* do bus reset */
1965 spin_lock_irqsave(&ap->host_set->lock, flags);
1966 ata_tf_to_host(ap, &tf);
1967 spin_unlock_irqrestore(&ap->host_set->lock, flags);
1968
1969 /* spec says at least 2ms. but who knows with those
1970 * crazy ATAPI devices...
1971 */
1972 msleep(150);
1973
1974 return ata_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT);
1975}
1976
1977static unsigned int ata_bus_softreset(struct ata_port *ap, 1986static unsigned int ata_bus_softreset(struct ata_port *ap,
1978 unsigned int devmask) 1987 unsigned int devmask)
1979{ 1988{
@@ -2008,11 +2017,11 @@ static unsigned int ata_bus_softreset(struct ata_port *ap,
2008 */ 2017 */
2009 msleep(150); 2018 msleep(150);
2010 2019
2011 2020
2012 /* Before we perform post reset processing we want to see if 2021 /* Before we perform post reset processing we want to see if
2013 the bus shows 0xFF because the odd clown forgets the D7 pulldown 2022 the bus shows 0xFF because the odd clown forgets the D7 pulldown
2014 resistor */ 2023 resistor */
2015 2024
2016 if (ata_check_status(ap) == 0xFF) 2025 if (ata_check_status(ap) == 0xFF)
2017 return 1; /* Positive is failure for some reason */ 2026 return 1; /* Positive is failure for some reason */
2018 2027
@@ -2046,7 +2055,7 @@ void ata_bus_reset(struct ata_port *ap)
2046 struct ata_ioports *ioaddr = &ap->ioaddr; 2055 struct ata_ioports *ioaddr = &ap->ioaddr;
2047 unsigned int slave_possible = ap->flags & ATA_FLAG_SLAVE_POSS; 2056 unsigned int slave_possible = ap->flags & ATA_FLAG_SLAVE_POSS;
2048 u8 err; 2057 u8 err;
2049 unsigned int dev0, dev1 = 0, rc = 0, devmask = 0; 2058 unsigned int dev0, dev1 = 0, devmask = 0;
2050 2059
2051 DPRINTK("ENTER, host %u, port %u\n", ap->id, ap->port_no); 2060 DPRINTK("ENTER, host %u, port %u\n", ap->id, ap->port_no);
2052 2061
@@ -2069,18 +2078,8 @@ void ata_bus_reset(struct ata_port *ap)
2069 2078
2070 /* issue bus reset */ 2079 /* issue bus reset */
2071 if (ap->flags & ATA_FLAG_SRST) 2080 if (ap->flags & ATA_FLAG_SRST)
2072 rc = ata_bus_softreset(ap, devmask); 2081 if (ata_bus_softreset(ap, devmask))
2073 else if ((ap->flags & ATA_FLAG_SATA_RESET) == 0) { 2082 goto err_out;
2074 /* set up device control */
2075 if (ap->flags & ATA_FLAG_MMIO)
2076 writeb(ap->ctl, (void __iomem *) ioaddr->ctl_addr);
2077 else
2078 outb(ap->ctl, ioaddr->ctl_addr);
2079 rc = ata_bus_edd(ap);
2080 }
2081
2082 if (rc)
2083 goto err_out;
2084 2083
2085 /* 2084 /*
2086 * determine by signature whether we have ATA or ATAPI devices 2085 * determine by signature whether we have ATA or ATAPI devices
@@ -2581,22 +2580,22 @@ static const char * const ata_dma_blacklist [] = {
2581 "SanDisk SDP3B-64", NULL, 2580 "SanDisk SDP3B-64", NULL,
2582 "SANYO CD-ROM CRD", NULL, 2581 "SANYO CD-ROM CRD", NULL,
2583 "HITACHI CDR-8", NULL, 2582 "HITACHI CDR-8", NULL,
2584 "HITACHI CDR-8335", NULL, 2583 "HITACHI CDR-8335", NULL,
2585 "HITACHI CDR-8435", NULL, 2584 "HITACHI CDR-8435", NULL,
2586 "Toshiba CD-ROM XM-6202B", NULL, 2585 "Toshiba CD-ROM XM-6202B", NULL,
2587 "TOSHIBA CD-ROM XM-1702BC", NULL, 2586 "TOSHIBA CD-ROM XM-1702BC", NULL,
2588 "CD-532E-A", NULL, 2587 "CD-532E-A", NULL,
2589 "E-IDE CD-ROM CR-840", NULL, 2588 "E-IDE CD-ROM CR-840", NULL,
2590 "CD-ROM Drive/F5A", NULL, 2589 "CD-ROM Drive/F5A", NULL,
2591 "WPI CDD-820", NULL, 2590 "WPI CDD-820", NULL,
2592 "SAMSUNG CD-ROM SC-148C", NULL, 2591 "SAMSUNG CD-ROM SC-148C", NULL,
2593 "SAMSUNG CD-ROM SC", NULL, 2592 "SAMSUNG CD-ROM SC", NULL,
2594 "SanDisk SDP3B-64", NULL, 2593 "SanDisk SDP3B-64", NULL,
2595 "ATAPI CD-ROM DRIVE 40X MAXIMUM",NULL, 2594 "ATAPI CD-ROM DRIVE 40X MAXIMUM",NULL,
2596 "_NEC DV5800A", NULL, 2595 "_NEC DV5800A", NULL,
2597 "SAMSUNG CD-ROM SN-124", "N001" 2596 "SAMSUNG CD-ROM SN-124", "N001"
2598}; 2597};
2599 2598
2600static int ata_strim(char *s, size_t len) 2599static int ata_strim(char *s, size_t len)
2601{ 2600{
2602 len = strnlen(s, len); 2601 len = strnlen(s, len);
@@ -2639,18 +2638,15 @@ static int ata_dma_blacklisted(const struct ata_device *dev)
2639 * @ap: Port on which the device to compute xfermask for resides 2638 * @ap: Port on which the device to compute xfermask for resides
2640 * @dev: Device to compute xfermask for 2639 * @dev: Device to compute xfermask for
2641 * 2640 *
2642 * Compute supported xfermask of @dev. This function is 2641 * Compute supported xfermask of @dev and store it in
2643 * responsible for applying all known limits including host 2642 * dev->*_mask. This function is responsible for applying all
2644 * controller limits, device blacklist, etc... 2643 * known limits including host controller limits, device
2644 * blacklist, etc...
2645 * 2645 *
2646 * LOCKING: 2646 * LOCKING:
2647 * None. 2647 * None.
2648 *
2649 * RETURNS:
2650 * Computed xfermask.
2651 */ 2648 */
2652static unsigned int ata_dev_xfermask(struct ata_port *ap, 2649static void ata_dev_xfermask(struct ata_port *ap, struct ata_device *dev)
2653 struct ata_device *dev)
2654{ 2650{
2655 unsigned long xfer_mask; 2651 unsigned long xfer_mask;
2656 int i; 2652 int i;
@@ -2663,6 +2659,8 @@ static unsigned int ata_dev_xfermask(struct ata_port *ap,
2663 struct ata_device *d = &ap->device[i]; 2659 struct ata_device *d = &ap->device[i];
2664 if (!ata_dev_present(d)) 2660 if (!ata_dev_present(d))
2665 continue; 2661 continue;
2662 xfer_mask &= ata_pack_xfermask(d->pio_mask, d->mwdma_mask,
2663 d->udma_mask);
2666 xfer_mask &= ata_id_xfermask(d->id); 2664 xfer_mask &= ata_id_xfermask(d->id);
2667 if (ata_dma_blacklisted(d)) 2665 if (ata_dma_blacklisted(d))
2668 xfer_mask &= ~(ATA_MASK_MWDMA | ATA_MASK_UDMA); 2666 xfer_mask &= ~(ATA_MASK_MWDMA | ATA_MASK_UDMA);
@@ -2672,7 +2670,8 @@ static unsigned int ata_dev_xfermask(struct ata_port *ap,
2672 printk(KERN_WARNING "ata%u: dev %u is on DMA blacklist, " 2670 printk(KERN_WARNING "ata%u: dev %u is on DMA blacklist, "
2673 "disabling DMA\n", ap->id, dev->devno); 2671 "disabling DMA\n", ap->id, dev->devno);
2674 2672
2675 return xfer_mask; 2673 ata_unpack_xfermask(xfer_mask, &dev->pio_mask, &dev->mwdma_mask,
2674 &dev->udma_mask);
2676} 2675}
2677 2676
2678/** 2677/**
@@ -2685,11 +2684,16 @@ static unsigned int ata_dev_xfermask(struct ata_port *ap,
2685 * 2684 *
2686 * LOCKING: 2685 * LOCKING:
2687 * PCI/etc. bus probe sem. 2686 * PCI/etc. bus probe sem.
2687 *
2688 * RETURNS:
2689 * 0 on success, AC_ERR_* mask otherwise.
2688 */ 2690 */
2689 2691
2690static void ata_dev_set_xfermode(struct ata_port *ap, struct ata_device *dev) 2692static unsigned int ata_dev_set_xfermode(struct ata_port *ap,
2693 struct ata_device *dev)
2691{ 2694{
2692 struct ata_taskfile tf; 2695 struct ata_taskfile tf;
2696 unsigned int err_mask;
2693 2697
2694 /* set up set-features taskfile */ 2698 /* set up set-features taskfile */
2695 DPRINTK("set features - xfer mode\n"); 2699 DPRINTK("set features - xfer mode\n");
@@ -2701,13 +2705,10 @@ static void ata_dev_set_xfermode(struct ata_port *ap, struct ata_device *dev)
2701 tf.protocol = ATA_PROT_NODATA; 2705 tf.protocol = ATA_PROT_NODATA;
2702 tf.nsect = dev->xfer_mode; 2706 tf.nsect = dev->xfer_mode;
2703 2707
2704 if (ata_exec_internal(ap, dev, &tf, DMA_NONE, NULL, 0)) { 2708 err_mask = ata_exec_internal(ap, dev, &tf, DMA_NONE, NULL, 0);
2705 printk(KERN_ERR "ata%u: failed to set xfermode, disabled\n",
2706 ap->id);
2707 ata_port_disable(ap);
2708 }
2709 2709
2710 DPRINTK("EXIT\n"); 2710 DPRINTK("EXIT, err_mask=%x\n", err_mask);
2711 return err_mask;
2711} 2712}
2712 2713
2713/** 2714/**
@@ -2784,7 +2785,7 @@ static void ata_sg_clean(struct ata_queued_cmd *qc)
2784 2785
2785 if (qc->flags & ATA_QCFLAG_SG) { 2786 if (qc->flags & ATA_QCFLAG_SG) {
2786 if (qc->n_elem) 2787 if (qc->n_elem)
2787 dma_unmap_sg(ap->host_set->dev, sg, qc->n_elem, dir); 2788 dma_unmap_sg(ap->dev, sg, qc->n_elem, dir);
2788 /* restore last sg */ 2789 /* restore last sg */
2789 sg[qc->orig_n_elem - 1].length += qc->pad_len; 2790 sg[qc->orig_n_elem - 1].length += qc->pad_len;
2790 if (pad_buf) { 2791 if (pad_buf) {
@@ -2795,7 +2796,7 @@ static void ata_sg_clean(struct ata_queued_cmd *qc)
2795 } 2796 }
2796 } else { 2797 } else {
2797 if (qc->n_elem) 2798 if (qc->n_elem)
2798 dma_unmap_single(ap->host_set->dev, 2799 dma_unmap_single(ap->dev,
2799 sg_dma_address(&sg[0]), sg_dma_len(&sg[0]), 2800 sg_dma_address(&sg[0]), sg_dma_len(&sg[0]),
2800 dir); 2801 dir);
2801 /* restore sg */ 2802 /* restore sg */
@@ -3006,7 +3007,7 @@ static int ata_sg_setup_one(struct ata_queued_cmd *qc)
3006 goto skip_map; 3007 goto skip_map;
3007 } 3008 }
3008 3009
3009 dma_address = dma_map_single(ap->host_set->dev, qc->buf_virt, 3010 dma_address = dma_map_single(ap->dev, qc->buf_virt,
3010 sg->length, dir); 3011 sg->length, dir);
3011 if (dma_mapping_error(dma_address)) { 3012 if (dma_mapping_error(dma_address)) {
3012 /* restore sg */ 3013 /* restore sg */
@@ -3094,7 +3095,7 @@ static int ata_sg_setup(struct ata_queued_cmd *qc)
3094 } 3095 }
3095 3096
3096 dir = qc->dma_dir; 3097 dir = qc->dma_dir;
3097 n_elem = dma_map_sg(ap->host_set->dev, sg, pre_n_elem, dir); 3098 n_elem = dma_map_sg(ap->dev, sg, pre_n_elem, dir);
3098 if (n_elem < 1) { 3099 if (n_elem < 1) {
3099 /* restore last sg */ 3100 /* restore last sg */
3100 lsg->length += qc->pad_len; 3101 lsg->length += qc->pad_len;
@@ -3793,7 +3794,7 @@ static void ata_pio_error(struct ata_port *ap)
3793 if (qc->tf.command != ATA_CMD_PACKET) 3794 if (qc->tf.command != ATA_CMD_PACKET)
3794 printk(KERN_WARNING "ata%u: PIO error\n", ap->id); 3795 printk(KERN_WARNING "ata%u: PIO error\n", ap->id);
3795 3796
3796 /* make sure qc->err_mask is available to 3797 /* make sure qc->err_mask is available to
3797 * know what's wrong and recover 3798 * know what's wrong and recover
3798 */ 3799 */
3799 WARN_ON(qc->err_mask == 0); 3800 WARN_ON(qc->err_mask == 0);
@@ -4630,14 +4631,15 @@ int ata_device_resume(struct ata_port *ap, struct ata_device *dev)
4630 * Flush the cache on the drive, if appropriate, then issue a 4631 * Flush the cache on the drive, if appropriate, then issue a
4631 * standbynow command. 4632 * standbynow command.
4632 */ 4633 */
4633int ata_device_suspend(struct ata_port *ap, struct ata_device *dev) 4634int ata_device_suspend(struct ata_port *ap, struct ata_device *dev, pm_message_t state)
4634{ 4635{
4635 if (!ata_dev_present(dev)) 4636 if (!ata_dev_present(dev))
4636 return 0; 4637 return 0;
4637 if (dev->class == ATA_DEV_ATA) 4638 if (dev->class == ATA_DEV_ATA)
4638 ata_flush_cache(ap, dev); 4639 ata_flush_cache(ap, dev);
4639 4640
4640 ata_standby_drive(ap, dev); 4641 if (state.event != PM_EVENT_FREEZE)
4642 ata_standby_drive(ap, dev);
4641 ap->flags |= ATA_FLAG_SUSPENDED; 4643 ap->flags |= ATA_FLAG_SUSPENDED;
4642 return 0; 4644 return 0;
4643} 4645}
@@ -4657,7 +4659,7 @@ int ata_device_suspend(struct ata_port *ap, struct ata_device *dev)
4657 4659
4658int ata_port_start (struct ata_port *ap) 4660int ata_port_start (struct ata_port *ap)
4659{ 4661{
4660 struct device *dev = ap->host_set->dev; 4662 struct device *dev = ap->dev;
4661 int rc; 4663 int rc;
4662 4664
4663 ap->prd = dma_alloc_coherent(dev, ATA_PRD_TBL_SZ, &ap->prd_dma, GFP_KERNEL); 4665 ap->prd = dma_alloc_coherent(dev, ATA_PRD_TBL_SZ, &ap->prd_dma, GFP_KERNEL);
@@ -4690,7 +4692,7 @@ int ata_port_start (struct ata_port *ap)
4690 4692
4691void ata_port_stop (struct ata_port *ap) 4693void ata_port_stop (struct ata_port *ap)
4692{ 4694{
4693 struct device *dev = ap->host_set->dev; 4695 struct device *dev = ap->dev;
4694 4696
4695 dma_free_coherent(dev, ATA_PRD_TBL_SZ, ap->prd, ap->prd_dma); 4697 dma_free_coherent(dev, ATA_PRD_TBL_SZ, ap->prd, ap->prd_dma);
4696 ata_pad_free(ap, dev); 4698 ata_pad_free(ap, dev);
@@ -4756,6 +4758,7 @@ static void ata_host_init(struct ata_port *ap, struct Scsi_Host *host,
4756 ap->host = host; 4758 ap->host = host;
4757 ap->ctl = ATA_DEVCTL_OBS; 4759 ap->ctl = ATA_DEVCTL_OBS;
4758 ap->host_set = host_set; 4760 ap->host_set = host_set;
4761 ap->dev = ent->dev;
4759 ap->port_no = port_no; 4762 ap->port_no = port_no;
4760 ap->hard_port_no = 4763 ap->hard_port_no =
4761 ent->legacy_mode ? ent->hard_port_no : port_no; 4764 ent->legacy_mode ? ent->hard_port_no : port_no;
@@ -4771,8 +4774,13 @@ static void ata_host_init(struct ata_port *ap, struct Scsi_Host *host,
4771 INIT_WORK(&ap->port_task, NULL, NULL); 4774 INIT_WORK(&ap->port_task, NULL, NULL);
4772 INIT_LIST_HEAD(&ap->eh_done_q); 4775 INIT_LIST_HEAD(&ap->eh_done_q);
4773 4776
4774 for (i = 0; i < ATA_MAX_DEVICES; i++) 4777 for (i = 0; i < ATA_MAX_DEVICES; i++) {
4775 ap->device[i].devno = i; 4778 struct ata_device *dev = &ap->device[i];
4779 dev->devno = i;
4780 dev->pio_mask = UINT_MAX;
4781 dev->mwdma_mask = UINT_MAX;
4782 dev->udma_mask = UINT_MAX;
4783 }
4776 4784
4777#ifdef ATA_IRQ_TRAP 4785#ifdef ATA_IRQ_TRAP
4778 ap->stats.unhandled_irq = 1; 4786 ap->stats.unhandled_irq = 1;
@@ -4806,6 +4814,14 @@ static struct ata_port * ata_host_add(const struct ata_probe_ent *ent,
4806 int rc; 4814 int rc;
4807 4815
4808 DPRINTK("ENTER\n"); 4816 DPRINTK("ENTER\n");
4817
4818 if (!ent->port_ops->probe_reset &&
4819 !(ent->host_flags & (ATA_FLAG_SATA_RESET | ATA_FLAG_SRST))) {
4820 printk(KERN_ERR "ata%u: no reset mechanism available\n",
4821 port_no);
4822 return NULL;
4823 }
4824
4809 host = scsi_host_alloc(ent->sht, sizeof(struct ata_port)); 4825 host = scsi_host_alloc(ent->sht, sizeof(struct ata_port));
4810 if (!host) 4826 if (!host)
4811 return NULL; 4827 return NULL;
@@ -4966,7 +4982,7 @@ err_free_ret:
4966 * ata_host_set_remove - PCI layer callback for device removal 4982 * ata_host_set_remove - PCI layer callback for device removal
4967 * @host_set: ATA host set that was removed 4983 * @host_set: ATA host set that was removed
4968 * 4984 *
4969 * Unregister all objects associated with this host set. Free those 4985 * Unregister all objects associated with this host set. Free those
4970 * objects. 4986 * objects.
4971 * 4987 *
4972 * LOCKING: 4988 * LOCKING:
@@ -5238,6 +5254,8 @@ EXPORT_SYMBOL_GPL(ata_std_postreset);
5238EXPORT_SYMBOL_GPL(ata_std_probe_reset); 5254EXPORT_SYMBOL_GPL(ata_std_probe_reset);
5239EXPORT_SYMBOL_GPL(ata_drive_probe_reset); 5255EXPORT_SYMBOL_GPL(ata_drive_probe_reset);
5240EXPORT_SYMBOL_GPL(ata_dev_revalidate); 5256EXPORT_SYMBOL_GPL(ata_dev_revalidate);
5257EXPORT_SYMBOL_GPL(ata_dev_classify);
5258EXPORT_SYMBOL_GPL(ata_dev_pair);
5241EXPORT_SYMBOL_GPL(ata_port_disable); 5259EXPORT_SYMBOL_GPL(ata_port_disable);
5242EXPORT_SYMBOL_GPL(ata_ratelimit); 5260EXPORT_SYMBOL_GPL(ata_ratelimit);
5243EXPORT_SYMBOL_GPL(ata_busy_sleep); 5261EXPORT_SYMBOL_GPL(ata_busy_sleep);
@@ -5248,7 +5266,6 @@ EXPORT_SYMBOL_GPL(ata_scsi_error);
5248EXPORT_SYMBOL_GPL(ata_scsi_slave_config); 5266EXPORT_SYMBOL_GPL(ata_scsi_slave_config);
5249EXPORT_SYMBOL_GPL(ata_scsi_release); 5267EXPORT_SYMBOL_GPL(ata_scsi_release);
5250EXPORT_SYMBOL_GPL(ata_host_intr); 5268EXPORT_SYMBOL_GPL(ata_host_intr);
5251EXPORT_SYMBOL_GPL(ata_dev_classify);
5252EXPORT_SYMBOL_GPL(ata_id_string); 5269EXPORT_SYMBOL_GPL(ata_id_string);
5253EXPORT_SYMBOL_GPL(ata_id_c_string); 5270EXPORT_SYMBOL_GPL(ata_id_c_string);
5254EXPORT_SYMBOL_GPL(ata_scsi_simulate); 5271EXPORT_SYMBOL_GPL(ata_scsi_simulate);
diff --git a/drivers/scsi/libata-scsi.c b/drivers/scsi/libata-scsi.c
index a1259b242b..628191bfd9 100644
--- a/drivers/scsi/libata-scsi.c
+++ b/drivers/scsi/libata-scsi.c
@@ -256,7 +256,7 @@ int ata_task_ioctl(struct scsi_device *scsidev, void __user *arg)
256 scsi_cmd[14] = args[0]; 256 scsi_cmd[14] = args[0];
257 257
258 /* Good values for timeout and retries? Values below 258 /* Good values for timeout and retries? Values below
259 from scsi_ioctl_send_command() for default case... */ 259 from scsi_ioctl_send_command() for default case... */
260 if (scsi_execute_req(scsidev, scsi_cmd, DMA_NONE, NULL, 0, &sshdr, 260 if (scsi_execute_req(scsidev, scsi_cmd, DMA_NONE, NULL, 0, &sshdr,
261 (10*HZ), 5)) 261 (10*HZ), 5))
262 rc = -EIO; 262 rc = -EIO;
@@ -267,20 +267,8 @@ int ata_task_ioctl(struct scsi_device *scsidev, void __user *arg)
267 267
268int ata_scsi_ioctl(struct scsi_device *scsidev, int cmd, void __user *arg) 268int ata_scsi_ioctl(struct scsi_device *scsidev, int cmd, void __user *arg)
269{ 269{
270 struct ata_port *ap;
271 struct ata_device *dev;
272 int val = -EINVAL, rc = -EINVAL; 270 int val = -EINVAL, rc = -EINVAL;
273 271
274 ap = (struct ata_port *) &scsidev->host->hostdata[0];
275 if (!ap)
276 goto out;
277
278 dev = ata_scsi_find_dev(ap, scsidev);
279 if (!dev) {
280 rc = -ENODEV;
281 goto out;
282 }
283
284 switch (cmd) { 272 switch (cmd) {
285 case ATA_IOC_GET_IO32: 273 case ATA_IOC_GET_IO32:
286 val = 0; 274 val = 0;
@@ -309,7 +297,6 @@ int ata_scsi_ioctl(struct scsi_device *scsidev, int cmd, void __user *arg)
309 break; 297 break;
310 } 298 }
311 299
312out:
313 return rc; 300 return rc;
314} 301}
315 302
@@ -414,12 +401,12 @@ int ata_scsi_device_resume(struct scsi_device *sdev)
414 return ata_device_resume(ap, dev); 401 return ata_device_resume(ap, dev);
415} 402}
416 403
417int ata_scsi_device_suspend(struct scsi_device *sdev) 404int ata_scsi_device_suspend(struct scsi_device *sdev, pm_message_t state)
418{ 405{
419 struct ata_port *ap = (struct ata_port *) &sdev->host->hostdata[0]; 406 struct ata_port *ap = (struct ata_port *) &sdev->host->hostdata[0];
420 struct ata_device *dev = &ap->device[sdev->id]; 407 struct ata_device *dev = &ap->device[sdev->id];
421 408
422 return ata_device_suspend(ap, dev); 409 return ata_device_suspend(ap, dev, state);
423} 410}
424 411
425/** 412/**
@@ -438,7 +425,7 @@ int ata_scsi_device_suspend(struct scsi_device *sdev)
438 * LOCKING: 425 * LOCKING:
439 * spin_lock_irqsave(host_set lock) 426 * spin_lock_irqsave(host_set lock)
440 */ 427 */
441void ata_to_sense_error(unsigned id, u8 drv_stat, u8 drv_err, u8 *sk, u8 *asc, 428void ata_to_sense_error(unsigned id, u8 drv_stat, u8 drv_err, u8 *sk, u8 *asc,
442 u8 *ascq) 429 u8 *ascq)
443{ 430{
444 int i; 431 int i;
@@ -495,7 +482,7 @@ void ata_to_sense_error(unsigned id, u8 drv_stat, u8 drv_err, u8 *sk, u8 *asc,
495 /* Look for drv_err */ 482 /* Look for drv_err */
496 for (i = 0; sense_table[i][0] != 0xFF; i++) { 483 for (i = 0; sense_table[i][0] != 0xFF; i++) {
497 /* Look for best matches first */ 484 /* Look for best matches first */
498 if ((sense_table[i][0] & drv_err) == 485 if ((sense_table[i][0] & drv_err) ==
499 sense_table[i][0]) { 486 sense_table[i][0]) {
500 *sk = sense_table[i][1]; 487 *sk = sense_table[i][1];
501 *asc = sense_table[i][2]; 488 *asc = sense_table[i][2];
@@ -518,7 +505,7 @@ void ata_to_sense_error(unsigned id, u8 drv_stat, u8 drv_err, u8 *sk, u8 *asc,
518 } 505 }
519 } 506 }
520 /* No error? Undecoded? */ 507 /* No error? Undecoded? */
521 printk(KERN_WARNING "ata%u: no sense translation for status: 0x%02x\n", 508 printk(KERN_WARNING "ata%u: no sense translation for status: 0x%02x\n",
522 id, drv_stat); 509 id, drv_stat);
523 510
524 /* We need a sensible error return here, which is tricky, and one 511 /* We need a sensible error return here, which is tricky, and one
@@ -1150,14 +1137,14 @@ static unsigned int ata_scsi_verify_xlat(struct ata_queued_cmd *qc, const u8 *sc
1150 1137
1151 DPRINTK("block %u track %u cyl %u head %u sect %u\n", 1138 DPRINTK("block %u track %u cyl %u head %u sect %u\n",
1152 (u32)block, track, cyl, head, sect); 1139 (u32)block, track, cyl, head, sect);
1153 1140
1154 /* Check whether the converted CHS can fit. 1141 /* Check whether the converted CHS can fit.
1155 Cylinder: 0-65535 1142 Cylinder: 0-65535
1156 Head: 0-15 1143 Head: 0-15
1157 Sector: 1-255*/ 1144 Sector: 1-255*/
1158 if ((cyl >> 16) || (head >> 4) || (sect >> 8) || (!sect)) 1145 if ((cyl >> 16) || (head >> 4) || (sect >> 8) || (!sect))
1159 goto out_of_range; 1146 goto out_of_range;
1160 1147
1161 tf->command = ATA_CMD_VERIFY; 1148 tf->command = ATA_CMD_VERIFY;
1162 tf->nsect = n_block & 0xff; /* Sector count 0 means 256 sectors */ 1149 tf->nsect = n_block & 0xff; /* Sector count 0 means 256 sectors */
1163 tf->lbal = sect; 1150 tf->lbal = sect;
@@ -1289,7 +1276,7 @@ static unsigned int ata_scsi_rw_xlat(struct ata_queued_cmd *qc, const u8 *scsicm
1289 tf->lbal = block & 0xff; 1276 tf->lbal = block & 0xff;
1290 1277
1291 tf->device |= ATA_LBA; 1278 tf->device |= ATA_LBA;
1292 } else { 1279 } else {
1293 /* CHS */ 1280 /* CHS */
1294 u32 sect, head, cyl, track; 1281 u32 sect, head, cyl, track;
1295 1282
@@ -1309,8 +1296,8 @@ static unsigned int ata_scsi_rw_xlat(struct ata_queued_cmd *qc, const u8 *scsicm
1309 DPRINTK("block %u track %u cyl %u head %u sect %u\n", 1296 DPRINTK("block %u track %u cyl %u head %u sect %u\n",
1310 (u32)block, track, cyl, head, sect); 1297 (u32)block, track, cyl, head, sect);
1311 1298
1312 /* Check whether the converted CHS can fit. 1299 /* Check whether the converted CHS can fit.
1313 Cylinder: 0-65535 1300 Cylinder: 0-65535
1314 Head: 0-15 1301 Head: 0-15
1315 Sector: 1-255*/ 1302 Sector: 1-255*/
1316 if ((cyl >> 16) || (head >> 4) || (sect >> 8) || (!sect)) 1303 if ((cyl >> 16) || (head >> 4) || (sect >> 8) || (!sect))
@@ -1697,7 +1684,7 @@ unsigned int ata_scsiop_inq_83(struct ata_scsi_args *args, u8 *rbuf,
1697 1684
1698 if (buflen > (ATA_SERNO_LEN + num + 3)) { 1685 if (buflen > (ATA_SERNO_LEN + num + 3)) {
1699 /* piv=0, assoc=lu, code_set=ACSII, designator=vendor */ 1686 /* piv=0, assoc=lu, code_set=ACSII, designator=vendor */
1700 rbuf[num + 0] = 2; 1687 rbuf[num + 0] = 2;
1701 rbuf[num + 3] = ATA_SERNO_LEN; 1688 rbuf[num + 3] = ATA_SERNO_LEN;
1702 num += 4; 1689 num += 4;
1703 ata_id_string(args->id, (unsigned char *) rbuf + num, 1690 ata_id_string(args->id, (unsigned char *) rbuf + num,
@@ -1707,8 +1694,8 @@ unsigned int ata_scsiop_inq_83(struct ata_scsi_args *args, u8 *rbuf,
1707 if (buflen > (sat_model_serial_desc_len + num + 3)) { 1694 if (buflen > (sat_model_serial_desc_len + num + 3)) {
1708 /* SAT defined lu model and serial numbers descriptor */ 1695 /* SAT defined lu model and serial numbers descriptor */
1709 /* piv=0, assoc=lu, code_set=ACSII, designator=t10 vendor id */ 1696 /* piv=0, assoc=lu, code_set=ACSII, designator=t10 vendor id */
1710 rbuf[num + 0] = 2; 1697 rbuf[num + 0] = 2;
1711 rbuf[num + 1] = 1; 1698 rbuf[num + 1] = 1;
1712 rbuf[num + 3] = sat_model_serial_desc_len; 1699 rbuf[num + 3] = sat_model_serial_desc_len;
1713 num += 4; 1700 num += 4;
1714 memcpy(rbuf + num, "ATA ", 8); 1701 memcpy(rbuf + num, "ATA ", 8);
@@ -2597,6 +2584,21 @@ static inline void ata_scsi_dump_cdb(struct ata_port *ap,
2597#endif 2584#endif
2598} 2585}
2599 2586
2587static inline void __ata_scsi_queuecmd(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *),
2588 struct ata_port *ap, struct ata_device *dev)
2589{
2590 if (dev->class == ATA_DEV_ATA) {
2591 ata_xlat_func_t xlat_func = ata_get_xlat_func(dev,
2592 cmd->cmnd[0]);
2593
2594 if (xlat_func)
2595 ata_scsi_translate(ap, dev, cmd, done, xlat_func);
2596 else
2597 ata_scsi_simulate(ap, dev, cmd, done);
2598 } else
2599 ata_scsi_translate(ap, dev, cmd, done, atapi_xlat);
2600}
2601
2600/** 2602/**
2601 * ata_scsi_queuecmd - Issue SCSI cdb to libata-managed device 2603 * ata_scsi_queuecmd - Issue SCSI cdb to libata-managed device
2602 * @cmd: SCSI command to be sent 2604 * @cmd: SCSI command to be sent
@@ -2631,24 +2633,13 @@ int ata_scsi_queuecmd(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
2631 ata_scsi_dump_cdb(ap, cmd); 2633 ata_scsi_dump_cdb(ap, cmd);
2632 2634
2633 dev = ata_scsi_find_dev(ap, scsidev); 2635 dev = ata_scsi_find_dev(ap, scsidev);
2634 if (unlikely(!dev)) { 2636 if (likely(dev))
2637 __ata_scsi_queuecmd(cmd, done, ap, dev);
2638 else {
2635 cmd->result = (DID_BAD_TARGET << 16); 2639 cmd->result = (DID_BAD_TARGET << 16);
2636 done(cmd); 2640 done(cmd);
2637 goto out_unlock;
2638 } 2641 }
2639 2642
2640 if (dev->class == ATA_DEV_ATA) {
2641 ata_xlat_func_t xlat_func = ata_get_xlat_func(dev,
2642 cmd->cmnd[0]);
2643
2644 if (xlat_func)
2645 ata_scsi_translate(ap, dev, cmd, done, xlat_func);
2646 else
2647 ata_scsi_simulate(ap, dev, cmd, done);
2648 } else
2649 ata_scsi_translate(ap, dev, cmd, done, atapi_xlat);
2650
2651out_unlock:
2652 spin_unlock(&ap->host_set->lock); 2643 spin_unlock(&ap->host_set->lock);
2653 spin_lock(shost->host_lock); 2644 spin_lock(shost->host_lock);
2654 return 0; 2645 return 0;
diff --git a/drivers/scsi/megaraid/megaraid_mbox.c b/drivers/scsi/megaraid/megaraid_mbox.c
index bf9f7f7ba3..c11e5ce686 100644
--- a/drivers/scsi/megaraid/megaraid_mbox.c
+++ b/drivers/scsi/megaraid/megaraid_mbox.c
@@ -2797,7 +2797,7 @@ mbox_post_sync_cmd(adapter_t *adapter, uint8_t raw_mbox[])
2797 // available within 1 second, assume FW is initializing and wait 2797 // available within 1 second, assume FW is initializing and wait
2798 // for an extended amount of time 2798 // for an extended amount of time
2799 if (mbox->numstatus == 0xFF) { // status not yet available 2799 if (mbox->numstatus == 0xFF) { // status not yet available
2800 udelay(25);; 2800 udelay(25);
2801 2801
2802 for (i = 0; mbox->numstatus == 0xFF && i < 1000; i++) { 2802 for (i = 0; mbox->numstatus == 0xFF && i < 1000; i++) {
2803 rmb(); 2803 rmb();
diff --git a/drivers/scsi/sata_sil.c b/drivers/scsi/sata_sil.c
index 3e75d67332..18c296c568 100644
--- a/drivers/scsi/sata_sil.c
+++ b/drivers/scsi/sata_sil.c
@@ -371,7 +371,7 @@ static void sil_dev_config(struct ata_port *ap, struct ata_device *dev)
371 if (quirks & SIL_QUIRK_UDMA5MAX) { 371 if (quirks & SIL_QUIRK_UDMA5MAX) {
372 printk(KERN_INFO "ata%u(%u): applying Maxtor errata fix %s\n", 372 printk(KERN_INFO "ata%u(%u): applying Maxtor errata fix %s\n",
373 ap->id, dev->devno, model_num); 373 ap->id, dev->devno, model_num);
374 ap->udma_mask &= ATA_UDMA5; 374 dev->udma_mask &= ATA_UDMA5;
375 return; 375 return;
376 } 376 }
377} 377}
diff --git a/drivers/scsi/sata_sil24.c b/drivers/scsi/sata_sil24.c
index 3efebea211..068c98a411 100644
--- a/drivers/scsi/sata_sil24.c
+++ b/drivers/scsi/sata_sil24.c
@@ -342,7 +342,7 @@ static struct ata_port_info sil24_port_info[] = {
342 .udma_mask = 0x3f, /* udma0-5 */ 342 .udma_mask = 0x3f, /* udma0-5 */
343 .port_ops = &sil24_ops, 343 .port_ops = &sil24_ops,
344 }, 344 },
345 /* sil_3132 */ 345 /* sil_3132 */
346 { 346 {
347 .sht = &sil24_sht, 347 .sht = &sil24_sht,
348 .host_flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY | 348 .host_flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
diff --git a/drivers/scsi/sata_vsc.c b/drivers/scsi/sata_vsc.c
index 9f621a97c9..5af6d5f9f4 100644
--- a/drivers/scsi/sata_vsc.c
+++ b/drivers/scsi/sata_vsc.c
@@ -237,11 +237,11 @@ static irqreturn_t vsc_sata_interrupt (int irq, void *dev_instance,
237 handled += ata_host_intr(ap, qc); 237 handled += ata_host_intr(ap, qc);
238 else if (is_vsc_sata_int_err(i, int_status)) { 238 else if (is_vsc_sata_int_err(i, int_status)) {
239 /* 239 /*
240 * On some chips (i.e. Intel 31244), an error 240 * On some chips (i.e. Intel 31244), an error
241 * interrupt will sneak in at initialization 241 * interrupt will sneak in at initialization
242 * time (phy state changes). Clearing the SCR 242 * time (phy state changes). Clearing the SCR
243 * error register is not required, but it prevents 243 * error register is not required, but it prevents
244 * the phy state change interrupts from recurring 244 * the phy state change interrupts from recurring
245 * later. 245 * later.
246 */ 246 */
247 u32 err_status; 247 u32 err_status;
diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
index 89055494df..a6fde52946 100644
--- a/drivers/scsi/scsi_sysfs.c
+++ b/drivers/scsi/scsi_sysfs.c
@@ -286,7 +286,7 @@ static int scsi_bus_suspend(struct device * dev, pm_message_t state)
286 return err; 286 return err;
287 287
288 if (sht->suspend) 288 if (sht->suspend)
289 err = sht->suspend(sdev); 289 err = sht->suspend(sdev, state);
290 290
291 return err; 291 return err;
292} 292}
diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c
index f9c1192dc1..7c80711e18 100644
--- a/drivers/scsi/sr.c
+++ b/drivers/scsi/sr.c
@@ -71,7 +71,7 @@ MODULE_ALIAS_BLOCKDEV_MAJOR(SCSI_CDROM_MAJOR);
71#define SR_CAPABILITIES \ 71#define SR_CAPABILITIES \
72 (CDC_CLOSE_TRAY|CDC_OPEN_TRAY|CDC_LOCK|CDC_SELECT_SPEED| \ 72 (CDC_CLOSE_TRAY|CDC_OPEN_TRAY|CDC_LOCK|CDC_SELECT_SPEED| \
73 CDC_SELECT_DISC|CDC_MULTI_SESSION|CDC_MCN|CDC_MEDIA_CHANGED| \ 73 CDC_SELECT_DISC|CDC_MULTI_SESSION|CDC_MCN|CDC_MEDIA_CHANGED| \
74 CDC_PLAY_AUDIO|CDC_RESET|CDC_IOCTLS|CDC_DRIVE_STATUS| \ 74 CDC_PLAY_AUDIO|CDC_RESET|CDC_DRIVE_STATUS| \
75 CDC_CD_R|CDC_CD_RW|CDC_DVD|CDC_DVD_R|CDC_DVD_RAM|CDC_GENERIC_PACKET| \ 75 CDC_CD_R|CDC_CD_RW|CDC_DVD|CDC_DVD_R|CDC_DVD_RAM|CDC_GENERIC_PACKET| \
76 CDC_MRW|CDC_MRW_W|CDC_RAM) 76 CDC_MRW|CDC_MRW_W|CDC_RAM)
77 77
@@ -118,7 +118,6 @@ static struct cdrom_device_ops sr_dops = {
118 .get_mcn = sr_get_mcn, 118 .get_mcn = sr_get_mcn,
119 .reset = sr_reset, 119 .reset = sr_reset,
120 .audio_ioctl = sr_audio_ioctl, 120 .audio_ioctl = sr_audio_ioctl,
121 .dev_ioctl = sr_dev_ioctl,
122 .capability = SR_CAPABILITIES, 121 .capability = SR_CAPABILITIES,
123 .generic_packet = sr_packet, 122 .generic_packet = sr_packet,
124}; 123};
@@ -456,17 +455,33 @@ static int sr_block_ioctl(struct inode *inode, struct file *file, unsigned cmd,
456{ 455{
457 struct scsi_cd *cd = scsi_cd(inode->i_bdev->bd_disk); 456 struct scsi_cd *cd = scsi_cd(inode->i_bdev->bd_disk);
458 struct scsi_device *sdev = cd->device; 457 struct scsi_device *sdev = cd->device;
458 void __user *argp = (void __user *)arg;
459 int ret;
459 460
460 /* 461 /*
461 * Send SCSI addressing ioctls directly to mid level, send other 462 * Send SCSI addressing ioctls directly to mid level, send other
462 * ioctls to cdrom/block level. 463 * ioctls to cdrom/block level.
463 */ 464 */
464 switch (cmd) { 465 switch (cmd) {
465 case SCSI_IOCTL_GET_IDLUN: 466 case SCSI_IOCTL_GET_IDLUN:
466 case SCSI_IOCTL_GET_BUS_NUMBER: 467 case SCSI_IOCTL_GET_BUS_NUMBER:
467 return scsi_ioctl(sdev, cmd, (void __user *)arg); 468 return scsi_ioctl(sdev, cmd, argp);
468 } 469 }
469 return cdrom_ioctl(file, &cd->cdi, inode, cmd, arg); 470
471 ret = cdrom_ioctl(file, &cd->cdi, inode, cmd, arg);
472 if (ret != ENOSYS)
473 return ret;
474
475 /*
476 * ENODEV means that we didn't recognise the ioctl, or that we
477 * cannot execute it in the current device state. In either
478 * case fall through to scsi_ioctl, which will return ENDOEV again
479 * if it doesn't recognise the ioctl
480 */
481 ret = scsi_nonblockable_ioctl(sdev, cmd, argp, NULL);
482 if (ret != -ENODEV)
483 return ret;
484 return scsi_ioctl(sdev, cmd, argp);
470} 485}
471 486
472static int sr_block_media_changed(struct gendisk *disk) 487static int sr_block_media_changed(struct gendisk *disk)
diff --git a/drivers/scsi/sr.h b/drivers/scsi/sr.h
index d2bcd99c27..d65de9621b 100644
--- a/drivers/scsi/sr.h
+++ b/drivers/scsi/sr.h
@@ -55,7 +55,6 @@ int sr_get_mcn(struct cdrom_device_info *, struct cdrom_mcn *);
55int sr_reset(struct cdrom_device_info *); 55int sr_reset(struct cdrom_device_info *);
56int sr_select_speed(struct cdrom_device_info *cdi, int speed); 56int sr_select_speed(struct cdrom_device_info *cdi, int speed);
57int sr_audio_ioctl(struct cdrom_device_info *, unsigned int, void *); 57int sr_audio_ioctl(struct cdrom_device_info *, unsigned int, void *);
58int sr_dev_ioctl(struct cdrom_device_info *, unsigned int, unsigned long);
59 58
60int sr_is_xa(Scsi_CD *); 59int sr_is_xa(Scsi_CD *);
61 60
diff --git a/drivers/scsi/sr_ioctl.c b/drivers/scsi/sr_ioctl.c
index b65462f764..d1268cb468 100644
--- a/drivers/scsi/sr_ioctl.c
+++ b/drivers/scsi/sr_ioctl.c
@@ -562,22 +562,3 @@ int sr_is_xa(Scsi_CD *cd)
562#endif 562#endif
563 return is_xa; 563 return is_xa;
564} 564}
565
566int sr_dev_ioctl(struct cdrom_device_info *cdi,
567 unsigned int cmd, unsigned long arg)
568{
569 Scsi_CD *cd = cdi->handle;
570 int ret;
571
572 ret = scsi_nonblockable_ioctl(cd->device, cmd,
573 (void __user *)arg, NULL);
574 /*
575 * ENODEV means that we didn't recognise the ioctl, or that we
576 * cannot execute it in the current device state. In either
577 * case fall through to scsi_ioctl, which will return ENDOEV again
578 * if it doesn't recognise the ioctl
579 */
580 if (ret != -ENODEV)
581 return ret;
582 return scsi_ioctl(cd->device, cmd, (void __user *)arg);
583}
diff --git a/drivers/serial/68328serial.c b/drivers/serial/68328serial.c
index 7f0f35a05d..b88a7c1158 100644
--- a/drivers/serial/68328serial.c
+++ b/drivers/serial/68328serial.c
@@ -101,8 +101,6 @@ struct tty_driver *serial_driver;
101 101
102#define RS_ISR_PASS_LIMIT 256 102#define RS_ISR_PASS_LIMIT 256
103 103
104#define _INLINE_ inline
105
106static void change_speed(struct m68k_serial *info); 104static void change_speed(struct m68k_serial *info);
107 105
108/* 106/*
@@ -262,7 +260,7 @@ static void batten_down_hatches(void)
262 /* Drop into the debugger */ 260 /* Drop into the debugger */
263} 261}
264 262
265static _INLINE_ void status_handle(struct m68k_serial *info, unsigned short status) 263static void status_handle(struct m68k_serial *info, unsigned short status)
266{ 264{
267#if 0 265#if 0
268 if(status & DCD) { 266 if(status & DCD) {
@@ -289,7 +287,8 @@ static _INLINE_ void status_handle(struct m68k_serial *info, unsigned short stat
289 return; 287 return;
290} 288}
291 289
292static _INLINE_ void receive_chars(struct m68k_serial *info, struct pt_regs *regs, unsigned short rx) 290static void receive_chars(struct m68k_serial *info, struct pt_regs *regs,
291 unsigned short rx)
293{ 292{
294 struct tty_struct *tty = info->tty; 293 struct tty_struct *tty = info->tty;
295 m68328_uart *uart = &uart_addr[info->line]; 294 m68328_uart *uart = &uart_addr[info->line];
@@ -359,7 +358,7 @@ clear_and_exit:
359 return; 358 return;
360} 359}
361 360
362static _INLINE_ void transmit_chars(struct m68k_serial *info) 361static void transmit_chars(struct m68k_serial *info)
363{ 362{
364 m68328_uart *uart = &uart_addr[info->line]; 363 m68328_uart *uart = &uart_addr[info->line];
365 364
diff --git a/drivers/serial/au1x00_uart.c b/drivers/serial/au1x00_uart.c
index 29f94bbb79..948880ac58 100644
--- a/drivers/serial/au1x00_uart.c
+++ b/drivers/serial/au1x00_uart.c
@@ -133,13 +133,12 @@ static const struct serial_uart_config uart_config[PORT_MAX_8250+1] = {
133 { "AU1X00_UART",16, UART_CLEAR_FIFO | UART_USE_FIFO }, 133 { "AU1X00_UART",16, UART_CLEAR_FIFO | UART_USE_FIFO },
134}; 134};
135 135
136static _INLINE_ unsigned int serial_in(struct uart_8250_port *up, int offset) 136static unsigned int serial_in(struct uart_8250_port *up, int offset)
137{ 137{
138 return au_readl((unsigned long)up->port.membase + offset); 138 return au_readl((unsigned long)up->port.membase + offset);
139} 139}
140 140
141static _INLINE_ void 141static void serial_out(struct uart_8250_port *up, int offset, int value)
142serial_out(struct uart_8250_port *up, int offset, int value)
143{ 142{
144 au_writel(value, (unsigned long)up->port.membase + offset); 143 au_writel(value, (unsigned long)up->port.membase + offset);
145} 144}
@@ -237,7 +236,7 @@ static void serial8250_enable_ms(struct uart_port *port)
237 serial_out(up, UART_IER, up->ier); 236 serial_out(up, UART_IER, up->ier);
238} 237}
239 238
240static _INLINE_ void 239static void
241receive_chars(struct uart_8250_port *up, int *status, struct pt_regs *regs) 240receive_chars(struct uart_8250_port *up, int *status, struct pt_regs *regs)
242{ 241{
243 struct tty_struct *tty = up->port.info->tty; 242 struct tty_struct *tty = up->port.info->tty;
@@ -312,7 +311,7 @@ receive_chars(struct uart_8250_port *up, int *status, struct pt_regs *regs)
312 spin_lock(&up->port.lock); 311 spin_lock(&up->port.lock);
313} 312}
314 313
315static _INLINE_ void transmit_chars(struct uart_8250_port *up) 314static void transmit_chars(struct uart_8250_port *up)
316{ 315{
317 struct circ_buf *xmit = &up->port.info->xmit; 316 struct circ_buf *xmit = &up->port.info->xmit;
318 int count; 317 int count;
@@ -346,7 +345,7 @@ static _INLINE_ void transmit_chars(struct uart_8250_port *up)
346 serial8250_stop_tx(&up->port); 345 serial8250_stop_tx(&up->port);
347} 346}
348 347
349static _INLINE_ void check_modem_status(struct uart_8250_port *up) 348static void check_modem_status(struct uart_8250_port *up)
350{ 349{
351 int status; 350 int status;
352 351
diff --git a/drivers/serial/crisv10.c b/drivers/serial/crisv10.c
index be12623d85..89700141f8 100644
--- a/drivers/serial/crisv10.c
+++ b/drivers/serial/crisv10.c
@@ -481,8 +481,6 @@ static char *serial_version = "$Revision: 1.25 $";
481#include "serial_compat.h" 481#include "serial_compat.h"
482#endif 482#endif
483 483
484#define _INLINE_ inline
485
486struct tty_driver *serial_driver; 484struct tty_driver *serial_driver;
487 485
488/* serial subtype definitions */ 486/* serial subtype definitions */
@@ -591,8 +589,6 @@ static void rs_throttle(struct tty_struct * tty);
591static void rs_wait_until_sent(struct tty_struct *tty, int timeout); 589static void rs_wait_until_sent(struct tty_struct *tty, int timeout);
592static int rs_write(struct tty_struct * tty, int from_user, 590static int rs_write(struct tty_struct * tty, int from_user,
593 const unsigned char *buf, int count); 591 const unsigned char *buf, int count);
594extern _INLINE_ int rs_raw_write(struct tty_struct * tty, int from_user,
595 const unsigned char *buf, int count);
596#ifdef CONFIG_ETRAX_RS485 592#ifdef CONFIG_ETRAX_RS485
597static int e100_write_rs485(struct tty_struct * tty, int from_user, 593static int e100_write_rs485(struct tty_struct * tty, int from_user,
598 const unsigned char *buf, int count); 594 const unsigned char *buf, int count);
@@ -1538,8 +1534,7 @@ e100_enable_rxdma_irq(struct e100_serial *info)
1538 1534
1539/* the tx DMA uses only dma_descr interrupt */ 1535/* the tx DMA uses only dma_descr interrupt */
1540 1536
1541static _INLINE_ void 1537static void e100_disable_txdma_irq(struct e100_serial *info)
1542e100_disable_txdma_irq(struct e100_serial *info)
1543{ 1538{
1544#ifdef SERIAL_DEBUG_INTR 1539#ifdef SERIAL_DEBUG_INTR
1545 printk("txdma_irq(%d): 0\n",info->line); 1540 printk("txdma_irq(%d): 0\n",info->line);
@@ -1548,8 +1543,7 @@ e100_disable_txdma_irq(struct e100_serial *info)
1548 *R_IRQ_MASK2_CLR = info->irq; 1543 *R_IRQ_MASK2_CLR = info->irq;
1549} 1544}
1550 1545
1551static _INLINE_ void 1546static void e100_enable_txdma_irq(struct e100_serial *info)
1552e100_enable_txdma_irq(struct e100_serial *info)
1553{ 1547{
1554#ifdef SERIAL_DEBUG_INTR 1548#ifdef SERIAL_DEBUG_INTR
1555 printk("txdma_irq(%d): 1\n",info->line); 1549 printk("txdma_irq(%d): 1\n",info->line);
@@ -1558,8 +1552,7 @@ e100_enable_txdma_irq(struct e100_serial *info)
1558 *R_IRQ_MASK2_SET = info->irq; 1552 *R_IRQ_MASK2_SET = info->irq;
1559} 1553}
1560 1554
1561static _INLINE_ void 1555static void e100_disable_txdma_channel(struct e100_serial *info)
1562e100_disable_txdma_channel(struct e100_serial *info)
1563{ 1556{
1564 unsigned long flags; 1557 unsigned long flags;
1565 1558
@@ -1599,8 +1592,7 @@ e100_disable_txdma_channel(struct e100_serial *info)
1599} 1592}
1600 1593
1601 1594
1602static _INLINE_ void 1595static void e100_enable_txdma_channel(struct e100_serial *info)
1603e100_enable_txdma_channel(struct e100_serial *info)
1604{ 1596{
1605 unsigned long flags; 1597 unsigned long flags;
1606 1598
@@ -1625,8 +1617,7 @@ e100_enable_txdma_channel(struct e100_serial *info)
1625 restore_flags(flags); 1617 restore_flags(flags);
1626} 1618}
1627 1619
1628static _INLINE_ void 1620static void e100_disable_rxdma_channel(struct e100_serial *info)
1629e100_disable_rxdma_channel(struct e100_serial *info)
1630{ 1621{
1631 unsigned long flags; 1622 unsigned long flags;
1632 1623
@@ -1665,8 +1656,7 @@ e100_disable_rxdma_channel(struct e100_serial *info)
1665} 1656}
1666 1657
1667 1658
1668static _INLINE_ void 1659static void e100_enable_rxdma_channel(struct e100_serial *info)
1669e100_enable_rxdma_channel(struct e100_serial *info)
1670{ 1660{
1671 unsigned long flags; 1661 unsigned long flags;
1672 1662
@@ -1913,9 +1903,7 @@ rs_start(struct tty_struct *tty)
1913 * This routine is used by the interrupt handler to schedule 1903 * This routine is used by the interrupt handler to schedule
1914 * processing in the software interrupt portion of the driver. 1904 * processing in the software interrupt portion of the driver.
1915 */ 1905 */
1916static _INLINE_ void 1906static void rs_sched_event(struct e100_serial *info, int event)
1917rs_sched_event(struct e100_serial *info,
1918 int event)
1919{ 1907{
1920 if (info->event & (1 << event)) 1908 if (info->event & (1 << event))
1921 return; 1909 return;
@@ -2155,8 +2143,9 @@ add_char_and_flag(struct e100_serial *info, unsigned char data, unsigned char fl
2155 return 1; 2143 return 1;
2156} 2144}
2157 2145
2158extern _INLINE_ unsigned int 2146static unsigned int handle_descr_data(struct e100_serial *info,
2159handle_descr_data(struct e100_serial *info, struct etrax_dma_descr *descr, unsigned int recvl) 2147 struct etrax_dma_descr *descr,
2148 unsigned int recvl)
2160{ 2149{
2161 struct etrax_recv_buffer *buffer = phys_to_virt(descr->buf) - sizeof *buffer; 2150 struct etrax_recv_buffer *buffer = phys_to_virt(descr->buf) - sizeof *buffer;
2162 2151
@@ -2182,8 +2171,7 @@ handle_descr_data(struct e100_serial *info, struct etrax_dma_descr *descr, unsig
2182 return recvl; 2171 return recvl;
2183} 2172}
2184 2173
2185static _INLINE_ unsigned int 2174static unsigned int handle_all_descr_data(struct e100_serial *info)
2186handle_all_descr_data(struct e100_serial *info)
2187{ 2175{
2188 struct etrax_dma_descr *descr; 2176 struct etrax_dma_descr *descr;
2189 unsigned int recvl; 2177 unsigned int recvl;
@@ -2230,8 +2218,7 @@ handle_all_descr_data(struct e100_serial *info)
2230 return ret; 2218 return ret;
2231} 2219}
2232 2220
2233static _INLINE_ void 2221static void receive_chars_dma(struct e100_serial *info)
2234receive_chars_dma(struct e100_serial *info)
2235{ 2222{
2236 struct tty_struct *tty; 2223 struct tty_struct *tty;
2237 unsigned char rstat; 2224 unsigned char rstat;
@@ -2292,8 +2279,7 @@ receive_chars_dma(struct e100_serial *info)
2292 *info->icmdadr = IO_STATE(R_DMA_CH6_CMD, cmd, restart); 2279 *info->icmdadr = IO_STATE(R_DMA_CH6_CMD, cmd, restart);
2293} 2280}
2294 2281
2295static _INLINE_ int 2282static int start_recv_dma(struct e100_serial *info)
2296start_recv_dma(struct e100_serial *info)
2297{ 2283{
2298 struct etrax_dma_descr *descr = info->rec_descr; 2284 struct etrax_dma_descr *descr = info->rec_descr;
2299 struct etrax_recv_buffer *buffer; 2285 struct etrax_recv_buffer *buffer;
@@ -2348,11 +2334,6 @@ start_receive(struct e100_serial *info)
2348} 2334}
2349 2335
2350 2336
2351static _INLINE_ void
2352status_handle(struct e100_serial *info, unsigned short status)
2353{
2354}
2355
2356/* the bits in the MASK2 register are laid out like this: 2337/* the bits in the MASK2 register are laid out like this:
2357 DMAI_EOP DMAI_DESCR DMAO_EOP DMAO_DESCR 2338 DMAI_EOP DMAI_DESCR DMAO_EOP DMAO_DESCR
2358 where I is the input channel and O is the output channel for the port. 2339 where I is the input channel and O is the output channel for the port.
@@ -2454,8 +2435,7 @@ rec_interrupt(int irq, void *dev_id, struct pt_regs * regs)
2454 return IRQ_RETVAL(handled); 2435 return IRQ_RETVAL(handled);
2455} /* rec_interrupt */ 2436} /* rec_interrupt */
2456 2437
2457static _INLINE_ int 2438static int force_eop_if_needed(struct e100_serial *info)
2458force_eop_if_needed(struct e100_serial *info)
2459{ 2439{
2460 /* We check data_avail bit to determine if data has 2440 /* We check data_avail bit to determine if data has
2461 * arrived since last time 2441 * arrived since last time
@@ -2499,8 +2479,7 @@ force_eop_if_needed(struct e100_serial *info)
2499 return 1; 2479 return 1;
2500} 2480}
2501 2481
2502extern _INLINE_ void 2482static void flush_to_flip_buffer(struct e100_serial *info)
2503flush_to_flip_buffer(struct e100_serial *info)
2504{ 2483{
2505 struct tty_struct *tty; 2484 struct tty_struct *tty;
2506 struct etrax_recv_buffer *buffer; 2485 struct etrax_recv_buffer *buffer;
@@ -2611,8 +2590,7 @@ flush_to_flip_buffer(struct e100_serial *info)
2611 tty_flip_buffer_push(tty); 2590 tty_flip_buffer_push(tty);
2612} 2591}
2613 2592
2614static _INLINE_ void 2593static void check_flush_timeout(struct e100_serial *info)
2615check_flush_timeout(struct e100_serial *info)
2616{ 2594{
2617 /* Flip what we've got (if we can) */ 2595 /* Flip what we've got (if we can) */
2618 flush_to_flip_buffer(info); 2596 flush_to_flip_buffer(info);
@@ -2741,7 +2719,7 @@ TODO: The break will be delayed until an F or V character is received.
2741 2719
2742*/ 2720*/
2743 2721
2744extern _INLINE_ 2722static
2745struct e100_serial * handle_ser_rx_interrupt_no_dma(struct e100_serial *info) 2723struct e100_serial * handle_ser_rx_interrupt_no_dma(struct e100_serial *info)
2746{ 2724{
2747 unsigned long data_read; 2725 unsigned long data_read;
@@ -2875,8 +2853,7 @@ more_data:
2875 return info; 2853 return info;
2876} 2854}
2877 2855
2878extern _INLINE_ 2856static struct e100_serial* handle_ser_rx_interrupt(struct e100_serial *info)
2879struct e100_serial* handle_ser_rx_interrupt(struct e100_serial *info)
2880{ 2857{
2881 unsigned char rstat; 2858 unsigned char rstat;
2882 2859
@@ -2995,7 +2972,7 @@ struct e100_serial* handle_ser_rx_interrupt(struct e100_serial *info)
2995 return info; 2972 return info;
2996} /* handle_ser_rx_interrupt */ 2973} /* handle_ser_rx_interrupt */
2997 2974
2998extern _INLINE_ void handle_ser_tx_interrupt(struct e100_serial *info) 2975static void handle_ser_tx_interrupt(struct e100_serial *info)
2999{ 2976{
3000 unsigned long flags; 2977 unsigned long flags;
3001 2978
@@ -3621,9 +3598,8 @@ rs_flush_chars(struct tty_struct *tty)
3621 restore_flags(flags); 3598 restore_flags(flags);
3622} 3599}
3623 3600
3624extern _INLINE_ int 3601static int rs_raw_write(struct tty_struct * tty, int from_user,
3625rs_raw_write(struct tty_struct * tty, int from_user, 3602 const unsigned char *buf, int count)
3626 const unsigned char *buf, int count)
3627{ 3603{
3628 int c, ret = 0; 3604 int c, ret = 0;
3629 struct e100_serial *info = (struct e100_serial *)tty->driver_data; 3605 struct e100_serial *info = (struct e100_serial *)tty->driver_data;
@@ -4710,7 +4686,7 @@ rs_open(struct tty_struct *tty, struct file * filp)
4710 * /proc fs routines.... 4686 * /proc fs routines....
4711 */ 4687 */
4712 4688
4713extern _INLINE_ int line_info(char *buf, struct e100_serial *info) 4689static int line_info(char *buf, struct e100_serial *info)
4714{ 4690{
4715 char stat_buf[30]; 4691 char stat_buf[30];
4716 int ret; 4692 int ret;
diff --git a/drivers/serial/m32r_sio.c b/drivers/serial/m32r_sio.c
index 876bc5e027..e9c10c0a30 100644
--- a/drivers/serial/m32r_sio.c
+++ b/drivers/serial/m32r_sio.c
@@ -248,17 +248,17 @@ static void sio_error(int *status)
248 248
249#endif /* CONFIG_SERIAL_M32R_PLDSIO */ 249#endif /* CONFIG_SERIAL_M32R_PLDSIO */
250 250
251static _INLINE_ unsigned int sio_in(struct uart_sio_port *up, int offset) 251static unsigned int sio_in(struct uart_sio_port *up, int offset)
252{ 252{
253 return __sio_in(up->port.iobase + offset); 253 return __sio_in(up->port.iobase + offset);
254} 254}
255 255
256static _INLINE_ void sio_out(struct uart_sio_port *up, int offset, int value) 256static void sio_out(struct uart_sio_port *up, int offset, int value)
257{ 257{
258 __sio_out(value, up->port.iobase + offset); 258 __sio_out(value, up->port.iobase + offset);
259} 259}
260 260
261static _INLINE_ unsigned int serial_in(struct uart_sio_port *up, int offset) 261static unsigned int serial_in(struct uart_sio_port *up, int offset)
262{ 262{
263 if (!offset) 263 if (!offset)
264 return 0; 264 return 0;
@@ -266,8 +266,7 @@ static _INLINE_ unsigned int serial_in(struct uart_sio_port *up, int offset)
266 return __sio_in(offset); 266 return __sio_in(offset);
267} 267}
268 268
269static _INLINE_ void 269static void serial_out(struct uart_sio_port *up, int offset, int value)
270serial_out(struct uart_sio_port *up, int offset, int value)
271{ 270{
272 if (!offset) 271 if (!offset)
273 return; 272 return;
@@ -326,8 +325,8 @@ static void m32r_sio_enable_ms(struct uart_port *port)
326 serial_out(up, UART_IER, up->ier); 325 serial_out(up, UART_IER, up->ier);
327} 326}
328 327
329static _INLINE_ void receive_chars(struct uart_sio_port *up, int *status, 328static void receive_chars(struct uart_sio_port *up, int *status,
330 struct pt_regs *regs) 329 struct pt_regs *regs)
331{ 330{
332 struct tty_struct *tty = up->port.info->tty; 331 struct tty_struct *tty = up->port.info->tty;
333 unsigned char ch; 332 unsigned char ch;
@@ -400,7 +399,7 @@ static _INLINE_ void receive_chars(struct uart_sio_port *up, int *status,
400 tty_flip_buffer_push(tty); 399 tty_flip_buffer_push(tty);
401} 400}
402 401
403static _INLINE_ void transmit_chars(struct uart_sio_port *up) 402static void transmit_chars(struct uart_sio_port *up)
404{ 403{
405 struct circ_buf *xmit = &up->port.info->xmit; 404 struct circ_buf *xmit = &up->port.info->xmit;
406 int count; 405 int count;
diff --git a/drivers/serial/sunsu.c b/drivers/serial/sunsu.c
index 7fc3d3b41d..9fe2283d91 100644
--- a/drivers/serial/sunsu.c
+++ b/drivers/serial/sunsu.c
@@ -102,9 +102,7 @@ struct uart_sunsu_port {
102#endif 102#endif
103}; 103};
104 104
105#define _INLINE_ 105static unsigned int serial_in(struct uart_sunsu_port *up, int offset)
106
107static _INLINE_ unsigned int serial_in(struct uart_sunsu_port *up, int offset)
108{ 106{
109 offset <<= up->port.regshift; 107 offset <<= up->port.regshift;
110 108
@@ -121,8 +119,7 @@ static _INLINE_ unsigned int serial_in(struct uart_sunsu_port *up, int offset)
121 } 119 }
122} 120}
123 121
124static _INLINE_ void 122static void serial_out(struct uart_sunsu_port *up, int offset, int value)
125serial_out(struct uart_sunsu_port *up, int offset, int value)
126{ 123{
127#ifndef CONFIG_SPARC64 124#ifndef CONFIG_SPARC64
128 /* 125 /*
@@ -316,7 +313,7 @@ static void sunsu_enable_ms(struct uart_port *port)
316 spin_unlock_irqrestore(&up->port.lock, flags); 313 spin_unlock_irqrestore(&up->port.lock, flags);
317} 314}
318 315
319static _INLINE_ struct tty_struct * 316static struct tty_struct *
320receive_chars(struct uart_sunsu_port *up, unsigned char *status, struct pt_regs *regs) 317receive_chars(struct uart_sunsu_port *up, unsigned char *status, struct pt_regs *regs)
321{ 318{
322 struct tty_struct *tty = up->port.info->tty; 319 struct tty_struct *tty = up->port.info->tty;
@@ -395,7 +392,7 @@ receive_chars(struct uart_sunsu_port *up, unsigned char *status, struct pt_regs
395 return tty; 392 return tty;
396} 393}
397 394
398static _INLINE_ void transmit_chars(struct uart_sunsu_port *up) 395static void transmit_chars(struct uart_sunsu_port *up)
399{ 396{
400 struct circ_buf *xmit = &up->port.info->xmit; 397 struct circ_buf *xmit = &up->port.info->xmit;
401 int count; 398 int count;
@@ -431,7 +428,7 @@ static _INLINE_ void transmit_chars(struct uart_sunsu_port *up)
431 __stop_tx(up); 428 __stop_tx(up);
432} 429}
433 430
434static _INLINE_ void check_modem_status(struct uart_sunsu_port *up) 431static void check_modem_status(struct uart_sunsu_port *up)
435{ 432{
436 int status; 433 int status;
437 434
diff --git a/drivers/tc/zs.c b/drivers/tc/zs.c
index 6756d0fab6..2dffa8e303 100644
--- a/drivers/tc/zs.c
+++ b/drivers/tc/zs.c
@@ -186,8 +186,6 @@ static struct tty_driver *serial_driver;
186#define RS_STROBE_TIME 10 186#define RS_STROBE_TIME 10
187#define RS_ISR_PASS_LIMIT 256 187#define RS_ISR_PASS_LIMIT 256
188 188
189#define _INLINE_ inline
190
191static void probe_sccs(void); 189static void probe_sccs(void);
192static void change_speed(struct dec_serial *info); 190static void change_speed(struct dec_serial *info);
193static void rs_wait_until_sent(struct tty_struct *tty, int timeout); 191static void rs_wait_until_sent(struct tty_struct *tty, int timeout);
@@ -344,14 +342,13 @@ static inline void rs_recv_clear(struct dec_zschannel *zsc)
344 * This routine is used by the interrupt handler to schedule 342 * This routine is used by the interrupt handler to schedule
345 * processing in the software interrupt portion of the driver. 343 * processing in the software interrupt portion of the driver.
346 */ 344 */
347static _INLINE_ void rs_sched_event(struct dec_serial *info, int event) 345static void rs_sched_event(struct dec_serial *info, int event)
348{ 346{
349 info->event |= 1 << event; 347 info->event |= 1 << event;
350 tasklet_schedule(&info->tlet); 348 tasklet_schedule(&info->tlet);
351} 349}
352 350
353static _INLINE_ void receive_chars(struct dec_serial *info, 351static void receive_chars(struct dec_serial *info, struct pt_regs *regs)
354 struct pt_regs *regs)
355{ 352{
356 struct tty_struct *tty = info->tty; 353 struct tty_struct *tty = info->tty;
357 unsigned char ch, stat, flag; 354 unsigned char ch, stat, flag;
@@ -441,7 +438,7 @@ static void transmit_chars(struct dec_serial *info)
441 rs_sched_event(info, RS_EVENT_WRITE_WAKEUP); 438 rs_sched_event(info, RS_EVENT_WRITE_WAKEUP);
442} 439}
443 440
444static _INLINE_ void status_handle(struct dec_serial *info) 441static void status_handle(struct dec_serial *info)
445{ 442{
446 unsigned char stat; 443 unsigned char stat;
447 444
diff --git a/drivers/usb/image/microtek.c b/drivers/usb/image/microtek.c
index 28538db9ea..2a0e18a487 100644
--- a/drivers/usb/image/microtek.c
+++ b/drivers/usb/image/microtek.c
@@ -360,7 +360,7 @@ static int mts_scsi_host_reset (Scsi_Cmnd *srb)
360 rc = usb_lock_device_for_reset(desc->usb_dev, desc->usb_intf); 360 rc = usb_lock_device_for_reset(desc->usb_dev, desc->usb_intf);
361 if (rc < 0) 361 if (rc < 0)
362 return FAILED; 362 return FAILED;
363 result = usb_reset_device(desc->usb_dev);; 363 result = usb_reset_device(desc->usb_dev);
364 if (rc) 364 if (rc)
365 usb_unlock_device(desc->usb_dev); 365 usb_unlock_device(desc->usb_dev);
366 return result ? FAILED : SUCCESS; 366 return result ? FAILED : SUCCESS;
diff --git a/drivers/usb/input/hid-core.c b/drivers/usb/input/hid-core.c
index 58b59f6e98..d4bf170104 100644
--- a/drivers/usb/input/hid-core.c
+++ b/drivers/usb/input/hid-core.c
@@ -1215,7 +1215,7 @@ static void hid_irq_out(struct urb *urb, struct pt_regs *regs)
1215 1215
1216 if (hid->outhead != hid->outtail) { 1216 if (hid->outhead != hid->outtail) {
1217 if (hid_submit_out(hid)) { 1217 if (hid_submit_out(hid)) {
1218 clear_bit(HID_OUT_RUNNING, &hid->iofl);; 1218 clear_bit(HID_OUT_RUNNING, &hid->iofl);
1219 wake_up(&hid->wait); 1219 wake_up(&hid->wait);
1220 } 1220 }
1221 spin_unlock_irqrestore(&hid->outlock, flags); 1221 spin_unlock_irqrestore(&hid->outlock, flags);
diff --git a/drivers/video/aty/radeon_pm.c b/drivers/video/aty/radeon_pm.c
index 1f8d805c61..5886a2f132 100644
--- a/drivers/video/aty/radeon_pm.c
+++ b/drivers/video/aty/radeon_pm.c
@@ -2080,7 +2080,7 @@ static void radeon_reinitialize_M9P(struct radeonfb_info *rinfo)
2080 OUTREG(0x2ec, 0x6332a3f0); 2080 OUTREG(0x2ec, 0x6332a3f0);
2081 mdelay(17); 2081 mdelay(17);
2082 2082
2083 OUTPLL(pllPPLL_REF_DIV, rinfo->pll.ref_div);; 2083 OUTPLL(pllPPLL_REF_DIV, rinfo->pll.ref_div);
2084 OUTPLL(pllPPLL_DIV_0, rinfo->save_regs[92]); 2084 OUTPLL(pllPPLL_DIV_0, rinfo->save_regs[92]);
2085 2085
2086 mdelay(40); 2086 mdelay(40);
diff --git a/drivers/w1/Kconfig b/drivers/w1/Kconfig
index 4baf61a223..5e61ed59a4 100644
--- a/drivers/w1/Kconfig
+++ b/drivers/w1/Kconfig
@@ -11,63 +11,7 @@ config W1
11 This W1 support can also be built as a module. If so, the module 11 This W1 support can also be built as a module. If so, the module
12 will be called wire.ko. 12 will be called wire.ko.
13 13
14config W1_MATROX 14source drivers/w1/masters/Kconfig
15 tristate "Matrox G400 transport layer for 1-wire" 15source drivers/w1/slaves/Kconfig
16 depends on W1 && PCI
17 help
18 Say Y here if you want to communicate with your 1-wire devices
19 using Matrox's G400 GPIO pins.
20
21 This support is also available as a module. If so, the module
22 will be called matrox_w1.ko.
23
24config W1_DS9490
25 tristate "DS9490R transport layer driver"
26 depends on W1 && USB
27 help
28 Say Y here if you want to have a driver for DS9490R UWB <-> W1 bridge.
29
30 This support is also available as a module. If so, the module
31 will be called ds9490r.ko.
32
33config W1_DS9490_BRIDGE
34 tristate "DS9490R USB <-> W1 transport layer for 1-wire"
35 depends on W1_DS9490
36 help
37 Say Y here if you want to communicate with your 1-wire devices
38 using DS9490R USB bridge.
39
40 This support is also available as a module. If so, the module
41 will be called ds_w1_bridge.ko.
42
43config W1_THERM
44 tristate "Thermal family implementation"
45 depends on W1
46 help
47 Say Y here if you want to connect 1-wire thermal sensors to you
48 wire.
49
50config W1_SMEM
51 tristate "Simple 64bit memory family implementation"
52 depends on W1
53 help
54 Say Y here if you want to connect 1-wire
55 simple 64bit memory rom(ds2401/ds2411/ds1990*) to you wire.
56
57config W1_DS2433
58 tristate "4kb EEPROM family support (DS2433)"
59 depends on W1
60 help
61 Say Y here if you want to use a 1-wire
62 4kb EEPROM family device (DS2433).
63
64config W1_DS2433_CRC
65 bool "Protect DS2433 data with a CRC16"
66 depends on W1_DS2433
67 select CRC16
68 help
69 Say Y here to protect DS2433 data with a CRC16.
70 Each block has 30 bytes of data and a two byte CRC16.
71 Full block writes are only allowed if the CRC is valid.
72 16
73endmenu 17endmenu
diff --git a/drivers/w1/Makefile b/drivers/w1/Makefile
index 01fb543914..0c2aa22d8c 100644
--- a/drivers/w1/Makefile
+++ b/drivers/w1/Makefile
@@ -13,13 +13,5 @@ endif
13obj-$(CONFIG_W1) += wire.o 13obj-$(CONFIG_W1) += wire.o
14wire-objs := w1.o w1_int.o w1_family.o w1_netlink.o w1_io.o 14wire-objs := w1.o w1_int.o w1_family.o w1_netlink.o w1_io.o
15 15
16obj-$(CONFIG_W1_MATROX) += matrox_w1.o 16obj-y += masters/ slaves/
17obj-$(CONFIG_W1_THERM) += w1_therm.o
18obj-$(CONFIG_W1_SMEM) += w1_smem.o
19 17
20obj-$(CONFIG_W1_DS9490) += ds9490r.o
21ds9490r-objs := dscore.o
22
23obj-$(CONFIG_W1_DS9490_BRIDGE) += ds_w1_bridge.o
24
25obj-$(CONFIG_W1_DS2433) += w1_ds2433.o
diff --git a/drivers/w1/masters/Kconfig b/drivers/w1/masters/Kconfig
new file mode 100644
index 0000000000..c6bad4dbdc
--- /dev/null
+++ b/drivers/w1/masters/Kconfig
@@ -0,0 +1,48 @@
1#
2# 1-wire bus master configuration
3#
4
5menu "1-wire Bus Masters"
6 depends on W1
7
8config W1_MASTER_MATROX
9 tristate "Matrox G400 transport layer for 1-wire"
10 depends on W1 && PCI
11 help
12 Say Y here if you want to communicate with your 1-wire devices
13 using Matrox's G400 GPIO pins.
14
15 This support is also available as a module. If so, the module
16 will be called matrox_w1.ko.
17
18config W1_MASTER_DS9490
19 tristate "DS9490R transport layer driver"
20 depends on W1 && USB
21 help
22 Say Y here if you want to have a driver for DS9490R UWB <-> W1 bridge.
23
24 This support is also available as a module. If so, the module
25 will be called ds9490r.ko.
26
27config W1_MASTER_DS9490_BRIDGE
28 tristate "DS9490R USB <-> W1 transport layer for 1-wire"
29 depends on W1_MASTER_DS9490
30 help
31 Say Y here if you want to communicate with your 1-wire devices
32 using DS9490R USB bridge.
33
34 This support is also available as a module. If so, the module
35 will be called ds_w1_bridge.ko.
36
37config W1_MASTER_DS2482
38 tristate "Maxim DS2482 I2C to 1-Wire bridge"
39 depends on I2C && W1 && EXPERIMENTAL
40 help
41 If you say yes here you get support for the Maxim DS2482
42 I2C to 1-Wire bridge.
43
44 This driver can also be built as a module. If so, the module
45 will be called ds2482.
46
47endmenu
48
diff --git a/drivers/w1/masters/Makefile b/drivers/w1/masters/Makefile
new file mode 100644
index 0000000000..1f3c8b983d
--- /dev/null
+++ b/drivers/w1/masters/Makefile
@@ -0,0 +1,13 @@
1#
2# Makefile for 1-wire bus master drivers.
3#
4
5obj-$(CONFIG_W1_MASTER_MATROX) += matrox_w1.o
6
7obj-$(CONFIG_W1_MASTER_DS9490) += ds9490r.o
8ds9490r-objs := dscore.o
9
10obj-$(CONFIG_W1_MASTER_DS9490_BRIDGE) += ds_w1_bridge.o
11
12obj-$(CONFIG_W1_MASTER_DS2482) += ds2482.o
13
diff --git a/drivers/w1/masters/ds2482.c b/drivers/w1/masters/ds2482.c
new file mode 100644
index 0000000000..d1cacd2357
--- /dev/null
+++ b/drivers/w1/masters/ds2482.c
@@ -0,0 +1,564 @@
1/**
2 * ds2482.c - provides i2c to w1-master bridge(s)
3 * Copyright (C) 2005 Ben Gardner <bgardner@wabtec.com>
4 *
5 * The DS2482 is a sensor chip made by Dallas Semiconductor (Maxim).
6 * It is a I2C to 1-wire bridge.
7 * There are two variations: -100 and -800, which have 1 or 8 1-wire ports.
8 * The complete datasheet can be obtained from MAXIM's website at:
9 * http://www.maxim-ic.com/quick_view2.cfm/qv_pk/4382
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; version 2 of the License.
14 */
15
16#include <linux/module.h>
17#include <linux/init.h>
18#include <linux/slab.h>
19#include <linux/i2c.h>
20#include <linux/delay.h>
21#include <asm/delay.h>
22
23#include "../w1.h"
24#include "../w1_int.h"
25
26/**
27 * Address is selected using 2 pins, resulting in 4 possible addresses.
28 * 0x18, 0x19, 0x1a, 0x1b
29 * However, the chip cannot be detected without doing an i2c write,
30 * so use the force module parameter.
31 */
32static unsigned short normal_i2c[] = {I2C_CLIENT_END};
33
34/**
35 * Insmod parameters
36 */
37I2C_CLIENT_INSMOD_1(ds2482);
38
39/**
40 * The DS2482 registers - there are 3 registers that are addressed by a read
41 * pointer. The read pointer is set by the last command executed.
42 *
43 * To read the data, issue a register read for any address
44 */
45#define DS2482_CMD_RESET 0xF0 /* No param */
46#define DS2482_CMD_SET_READ_PTR 0xE1 /* Param: DS2482_PTR_CODE_xxx */
47#define DS2482_CMD_CHANNEL_SELECT 0xC3 /* Param: Channel byte - DS2482-800 only */
48#define DS2482_CMD_WRITE_CONFIG 0xD2 /* Param: Config byte */
49#define DS2482_CMD_1WIRE_RESET 0xB4 /* Param: None */
50#define DS2482_CMD_1WIRE_SINGLE_BIT 0x87 /* Param: Bit byte (bit7) */
51#define DS2482_CMD_1WIRE_WRITE_BYTE 0xA5 /* Param: Data byte */
52#define DS2482_CMD_1WIRE_READ_BYTE 0x96 /* Param: None */
53/* Note to read the byte, Set the ReadPtr to Data then read (any addr) */
54#define DS2482_CMD_1WIRE_TRIPLET 0x78 /* Param: Dir byte (bit7) */
55
56/* Values for DS2482_CMD_SET_READ_PTR */
57#define DS2482_PTR_CODE_STATUS 0xF0
58#define DS2482_PTR_CODE_DATA 0xE1
59#define DS2482_PTR_CODE_CHANNEL 0xD2 /* DS2482-800 only */
60#define DS2482_PTR_CODE_CONFIG 0xC3
61
62/**
63 * Configure Register bit definitions
64 * The top 4 bits always read 0.
65 * To write, the top nibble must be the 1's compl. of the low nibble.
66 */
67#define DS2482_REG_CFG_1WS 0x08
68#define DS2482_REG_CFG_SPU 0x04
69#define DS2482_REG_CFG_PPM 0x02
70#define DS2482_REG_CFG_APU 0x01
71
72
73/**
74 * Write and verify codes for the CHANNEL_SELECT command (DS2482-800 only).
75 * To set the channel, write the value at the index of the channel.
76 * Read and compare against the corresponding value to verify the change.
77 */
78static const u8 ds2482_chan_wr[8] =
79 { 0xF0, 0xE1, 0xD2, 0xC3, 0xB4, 0xA5, 0x96, 0x87 };
80static const u8 ds2482_chan_rd[8] =
81 { 0xB8, 0xB1, 0xAA, 0xA3, 0x9C, 0x95, 0x8E, 0x87 };
82
83
84/**
85 * Status Register bit definitions (read only)
86 */
87#define DS2482_REG_STS_DIR 0x80
88#define DS2482_REG_STS_TSB 0x40
89#define DS2482_REG_STS_SBR 0x20
90#define DS2482_REG_STS_RST 0x10
91#define DS2482_REG_STS_LL 0x08
92#define DS2482_REG_STS_SD 0x04
93#define DS2482_REG_STS_PPD 0x02
94#define DS2482_REG_STS_1WB 0x01
95
96
97static int ds2482_attach_adapter(struct i2c_adapter *adapter);
98static int ds2482_detect(struct i2c_adapter *adapter, int address, int kind);
99static int ds2482_detach_client(struct i2c_client *client);
100
101
102/**
103 * Driver data (common to all clients)
104 */
105static struct i2c_driver ds2482_driver = {
106 .driver = {
107 .owner = THIS_MODULE,
108 .name = "ds2482",
109 },
110 .attach_adapter = ds2482_attach_adapter,
111 .detach_client = ds2482_detach_client,
112};
113
114/*
115 * Client data (each client gets its own)
116 */
117
118struct ds2482_data;
119
120struct ds2482_w1_chan {
121 struct ds2482_data *pdev;
122 u8 channel;
123 struct w1_bus_master w1_bm;
124};
125
126struct ds2482_data {
127 struct i2c_client client;
128 struct semaphore access_lock;
129
130 /* 1-wire interface(s) */
131 int w1_count; /* 1 or 8 */
132 struct ds2482_w1_chan w1_ch[8];
133
134 /* per-device values */
135 u8 channel;
136 u8 read_prt; /* see DS2482_PTR_CODE_xxx */
137 u8 reg_config;
138};
139
140
141/**
142 * Sets the read pointer.
143 * @param pdev The ds2482 client pointer
144 * @param read_ptr see DS2482_PTR_CODE_xxx above
145 * @return -1 on failure, 0 on success
146 */
147static inline int ds2482_select_register(struct ds2482_data *pdev, u8 read_ptr)
148{
149 if (pdev->read_prt != read_ptr) {
150 if (i2c_smbus_write_byte_data(&pdev->client,
151 DS2482_CMD_SET_READ_PTR,
152 read_ptr) < 0)
153 return -1;
154
155 pdev->read_prt = read_ptr;
156 }
157 return 0;
158}
159
160/**
161 * Sends a command without a parameter
162 * @param pdev The ds2482 client pointer
163 * @param cmd DS2482_CMD_RESET,
164 * DS2482_CMD_1WIRE_RESET,
165 * DS2482_CMD_1WIRE_READ_BYTE
166 * @return -1 on failure, 0 on success
167 */
168static inline int ds2482_send_cmd(struct ds2482_data *pdev, u8 cmd)
169{
170 if (i2c_smbus_write_byte(&pdev->client, cmd) < 0)
171 return -1;
172
173 pdev->read_prt = DS2482_PTR_CODE_STATUS;
174 return 0;
175}
176
177/**
178 * Sends a command with a parameter
179 * @param pdev The ds2482 client pointer
180 * @param cmd DS2482_CMD_WRITE_CONFIG,
181 * DS2482_CMD_1WIRE_SINGLE_BIT,
182 * DS2482_CMD_1WIRE_WRITE_BYTE,
183 * DS2482_CMD_1WIRE_TRIPLET
184 * @param byte The data to send
185 * @return -1 on failure, 0 on success
186 */
187static inline int ds2482_send_cmd_data(struct ds2482_data *pdev,
188 u8 cmd, u8 byte)
189{
190 if (i2c_smbus_write_byte_data(&pdev->client, cmd, byte) < 0)
191 return -1;
192
193 /* all cmds leave in STATUS, except CONFIG */
194 pdev->read_prt = (cmd != DS2482_CMD_WRITE_CONFIG) ?
195 DS2482_PTR_CODE_STATUS : DS2482_PTR_CODE_CONFIG;
196 return 0;
197}
198
199
200/*
201 * 1-Wire interface code
202 */
203
204#define DS2482_WAIT_IDLE_TIMEOUT 100
205
206/**
207 * Waits until the 1-wire interface is idle (not busy)
208 *
209 * @param pdev Pointer to the device structure
210 * @return the last value read from status or -1 (failure)
211 */
212static int ds2482_wait_1wire_idle(struct ds2482_data *pdev)
213{
214 int temp = -1;
215 int retries = 0;
216
217 if (!ds2482_select_register(pdev, DS2482_PTR_CODE_STATUS)) {
218 do {
219 temp = i2c_smbus_read_byte(&pdev->client);
220 } while ((temp >= 0) && (temp & DS2482_REG_STS_1WB) &&
221 (++retries > DS2482_WAIT_IDLE_TIMEOUT));
222 }
223
224 if (retries > DS2482_WAIT_IDLE_TIMEOUT)
225 printk(KERN_ERR "%s: timeout on channel %d\n",
226 __func__, pdev->channel);
227
228 return temp;
229}
230
231/**
232 * Selects a w1 channel.
233 * The 1-wire interface must be idle before calling this function.
234 *
235 * @param pdev The ds2482 client pointer
236 * @param channel 0-7
237 * @return -1 (failure) or 0 (success)
238 */
239static int ds2482_set_channel(struct ds2482_data *pdev, u8 channel)
240{
241 if (i2c_smbus_write_byte_data(&pdev->client, DS2482_CMD_CHANNEL_SELECT,
242 ds2482_chan_wr[channel]) < 0)
243 return -1;
244
245 pdev->read_prt = DS2482_PTR_CODE_CHANNEL;
246 pdev->channel = -1;
247 if (i2c_smbus_read_byte(&pdev->client) == ds2482_chan_rd[channel]) {
248 pdev->channel = channel;
249 return 0;
250 }
251 return -1;
252}
253
254
255/**
256 * Performs the touch-bit function, which writes a 0 or 1 and reads the level.
257 *
258 * @param data The ds2482 channel pointer
259 * @param bit The level to write: 0 or non-zero
260 * @return The level read: 0 or 1
261 */
262static u8 ds2482_w1_touch_bit(void *data, u8 bit)
263{
264 struct ds2482_w1_chan *pchan = data;
265 struct ds2482_data *pdev = pchan->pdev;
266 int status = -1;
267
268 down(&pdev->access_lock);
269
270 /* Select the channel */
271 ds2482_wait_1wire_idle(pdev);
272 if (pdev->w1_count > 1)
273 ds2482_set_channel(pdev, pchan->channel);
274
275 /* Send the touch command, wait until 1WB == 0, return the status */
276 if (!ds2482_send_cmd_data(pdev, DS2482_CMD_1WIRE_SINGLE_BIT,
277 bit ? 0xFF : 0))
278 status = ds2482_wait_1wire_idle(pdev);
279
280 up(&pdev->access_lock);
281
282 return (status & DS2482_REG_STS_SBR) ? 1 : 0;
283}
284
285/**
286 * Performs the triplet function, which reads two bits and writes a bit.
287 * The bit written is determined by the two reads:
288 * 00 => dbit, 01 => 0, 10 => 1
289 *
290 * @param data The ds2482 channel pointer
291 * @param dbit The direction to choose if both branches are valid
292 * @return b0=read1 b1=read2 b3=bit written
293 */
294static u8 ds2482_w1_triplet(void *data, u8 dbit)
295{
296 struct ds2482_w1_chan *pchan = data;
297 struct ds2482_data *pdev = pchan->pdev;
298 int status = (3 << 5);
299
300 down(&pdev->access_lock);
301
302 /* Select the channel */
303 ds2482_wait_1wire_idle(pdev);
304 if (pdev->w1_count > 1)
305 ds2482_set_channel(pdev, pchan->channel);
306
307 /* Send the triplet command, wait until 1WB == 0, return the status */
308 if (!ds2482_send_cmd_data(pdev, DS2482_CMD_1WIRE_TRIPLET,
309 dbit ? 0xFF : 0))
310 status = ds2482_wait_1wire_idle(pdev);
311
312 up(&pdev->access_lock);
313
314 /* Decode the status */
315 return (status >> 5);
316}
317
318/**
319 * Performs the write byte function.
320 *
321 * @param data The ds2482 channel pointer
322 * @param byte The value to write
323 */
324static void ds2482_w1_write_byte(void *data, u8 byte)
325{
326 struct ds2482_w1_chan *pchan = data;
327 struct ds2482_data *pdev = pchan->pdev;
328
329 down(&pdev->access_lock);
330
331 /* Select the channel */
332 ds2482_wait_1wire_idle(pdev);
333 if (pdev->w1_count > 1)
334 ds2482_set_channel(pdev, pchan->channel);
335
336 /* Send the write byte command */
337 ds2482_send_cmd_data(pdev, DS2482_CMD_1WIRE_WRITE_BYTE, byte);
338
339 up(&pdev->access_lock);
340}
341
342/**
343 * Performs the read byte function.
344 *
345 * @param data The ds2482 channel pointer
346 * @return The value read
347 */
348static u8 ds2482_w1_read_byte(void *data)
349{
350 struct ds2482_w1_chan *pchan = data;
351 struct ds2482_data *pdev = pchan->pdev;
352 int result;
353
354 down(&pdev->access_lock);
355
356 /* Select the channel */
357 ds2482_wait_1wire_idle(pdev);
358 if (pdev->w1_count > 1)
359 ds2482_set_channel(pdev, pchan->channel);
360
361 /* Send the read byte command */
362 ds2482_send_cmd(pdev, DS2482_CMD_1WIRE_READ_BYTE);
363
364 /* Wait until 1WB == 0 */
365 ds2482_wait_1wire_idle(pdev);
366
367 /* Select the data register */
368 ds2482_select_register(pdev, DS2482_PTR_CODE_DATA);
369
370 /* Read the data byte */
371 result = i2c_smbus_read_byte(&pdev->client);
372
373 up(&pdev->access_lock);
374
375 return result;
376}
377
378
379/**
380 * Sends a reset on the 1-wire interface
381 *
382 * @param data The ds2482 channel pointer
383 * @return 0=Device present, 1=No device present or error
384 */
385static u8 ds2482_w1_reset_bus(void *data)
386{
387 struct ds2482_w1_chan *pchan = data;
388 struct ds2482_data *pdev = pchan->pdev;
389 int err;
390 u8 retval = 1;
391
392 down(&pdev->access_lock);
393
394 /* Select the channel */
395 ds2482_wait_1wire_idle(pdev);
396 if (pdev->w1_count > 1)
397 ds2482_set_channel(pdev, pchan->channel);
398
399 /* Send the reset command */
400 err = ds2482_send_cmd(pdev, DS2482_CMD_1WIRE_RESET);
401 if (err >= 0) {
402 /* Wait until the reset is complete */
403 err = ds2482_wait_1wire_idle(pdev);
404 retval = !(err & DS2482_REG_STS_PPD);
405
406 /* If the chip did reset since detect, re-config it */
407 if (err & DS2482_REG_STS_RST)
408 ds2482_send_cmd_data(pdev, DS2482_CMD_WRITE_CONFIG,
409 0xF0);
410 }
411
412 up(&pdev->access_lock);
413
414 return retval;
415}
416
417
418/**
419 * Called to see if the device exists on an i2c bus.
420 */
421static int ds2482_attach_adapter(struct i2c_adapter *adapter)
422{
423 return i2c_probe(adapter, &addr_data, ds2482_detect);
424}
425
426
427/*
428 * The following function does more than just detection. If detection
429 * succeeds, it also registers the new chip.
430 */
431static int ds2482_detect(struct i2c_adapter *adapter, int address, int kind)
432{
433 struct ds2482_data *data;
434 struct i2c_client *new_client;
435 int err = 0;
436 int temp1;
437 int idx;
438
439 if (!i2c_check_functionality(adapter,
440 I2C_FUNC_SMBUS_WRITE_BYTE_DATA |
441 I2C_FUNC_SMBUS_BYTE))
442 goto exit;
443
444 if (!(data = kzalloc(sizeof(struct ds2482_data), GFP_KERNEL))) {
445 err = -ENOMEM;
446 goto exit;
447 }
448
449 new_client = &data->client;
450 i2c_set_clientdata(new_client, data);
451 new_client->addr = address;
452 new_client->driver = &ds2482_driver;
453 new_client->adapter = adapter;
454
455 /* Reset the device (sets the read_ptr to status) */
456 if (ds2482_send_cmd(data, DS2482_CMD_RESET) < 0) {
457 dev_dbg(&adapter->dev, "DS2482 reset failed at 0x%02x.\n",
458 address);
459 goto exit_free;
460 }
461
462 /* Sleep at least 525ns to allow the reset to complete */
463 ndelay(525);
464
465 /* Read the status byte - only reset bit and line should be set */
466 temp1 = i2c_smbus_read_byte(new_client);
467 if (temp1 != (DS2482_REG_STS_LL | DS2482_REG_STS_RST)) {
468 dev_dbg(&adapter->dev, "DS2482 (0x%02x) reset status "
469 "0x%02X - not a DS2482\n", address, temp1);
470 goto exit_free;
471 }
472
473 /* Detect the 8-port version */
474 data->w1_count = 1;
475 if (ds2482_set_channel(data, 7) == 0)
476 data->w1_count = 8;
477
478 /* Set all config items to 0 (off) */
479 ds2482_send_cmd_data(data, DS2482_CMD_WRITE_CONFIG, 0xF0);
480
481 /* We can fill in the remaining client fields */
482 snprintf(new_client->name, sizeof(new_client->name), "ds2482-%d00",
483 data->w1_count);
484
485 init_MUTEX(&data->access_lock);
486
487 /* Tell the I2C layer a new client has arrived */
488 if ((err = i2c_attach_client(new_client)))
489 goto exit_free;
490
491 /* Register 1-wire interface(s) */
492 for (idx = 0; idx < data->w1_count; idx++) {
493 data->w1_ch[idx].pdev = data;
494 data->w1_ch[idx].channel = idx;
495
496 /* Populate all the w1 bus master stuff */
497 data->w1_ch[idx].w1_bm.data = &data->w1_ch[idx];
498 data->w1_ch[idx].w1_bm.read_byte = ds2482_w1_read_byte;
499 data->w1_ch[idx].w1_bm.write_byte = ds2482_w1_write_byte;
500 data->w1_ch[idx].w1_bm.touch_bit = ds2482_w1_touch_bit;
501 data->w1_ch[idx].w1_bm.triplet = ds2482_w1_triplet;
502 data->w1_ch[idx].w1_bm.reset_bus = ds2482_w1_reset_bus;
503
504 err = w1_add_master_device(&data->w1_ch[idx].w1_bm);
505 if (err) {
506 data->w1_ch[idx].pdev = NULL;
507 goto exit_w1_remove;
508 }
509 }
510
511 return 0;
512
513exit_w1_remove:
514 i2c_detach_client(new_client);
515
516 for (idx = 0; idx < data->w1_count; idx++) {
517 if (data->w1_ch[idx].pdev != NULL)
518 w1_remove_master_device(&data->w1_ch[idx].w1_bm);
519 }
520exit_free:
521 kfree(data);
522exit:
523 return err;
524}
525
526static int ds2482_detach_client(struct i2c_client *client)
527{
528 struct ds2482_data *data = i2c_get_clientdata(client);
529 int err, idx;
530
531 /* Unregister the 1-wire bridge(s) */
532 for (idx = 0; idx < data->w1_count; idx++) {
533 if (data->w1_ch[idx].pdev != NULL)
534 w1_remove_master_device(&data->w1_ch[idx].w1_bm);
535 }
536
537 /* Detach the i2c device */
538 if ((err = i2c_detach_client(client))) {
539 dev_err(&client->dev,
540 "Deregistration failed, client not detached.\n");
541 return err;
542 }
543
544 /* Free the memory */
545 kfree(data);
546 return 0;
547}
548
549static int __init sensors_ds2482_init(void)
550{
551 return i2c_add_driver(&ds2482_driver);
552}
553
554static void __exit sensors_ds2482_exit(void)
555{
556 i2c_del_driver(&ds2482_driver);
557}
558
559MODULE_AUTHOR("Ben Gardner <bgardner@wabtec.com>");
560MODULE_DESCRIPTION("DS2482 driver");
561MODULE_LICENSE("GPL");
562
563module_init(sensors_ds2482_init);
564module_exit(sensors_ds2482_exit);
diff --git a/drivers/w1/ds_w1_bridge.c b/drivers/w1/masters/ds_w1_bridge.c
index a79d16d566..5d30783a3e 100644
--- a/drivers/w1/ds_w1_bridge.c
+++ b/drivers/w1/masters/ds_w1_bridge.c
@@ -22,17 +22,17 @@
22#include <linux/module.h> 22#include <linux/module.h>
23#include <linux/types.h> 23#include <linux/types.h>
24 24
25#include "../w1/w1.h" 25#include "../w1.h"
26#include "../w1/w1_int.h" 26#include "../w1_int.h"
27#include "dscore.h" 27#include "dscore.h"
28 28
29static struct ds_device *ds_dev; 29static struct ds_device *ds_dev;
30static struct w1_bus_master *ds_bus_master; 30static struct w1_bus_master *ds_bus_master;
31 31
32static u8 ds9490r_touch_bit(unsigned long data, u8 bit) 32static u8 ds9490r_touch_bit(void *data, u8 bit)
33{ 33{
34 u8 ret; 34 u8 ret;
35 struct ds_device *dev = (struct ds_device *)data; 35 struct ds_device *dev = data;
36 36
37 if (ds_touch_bit(dev, bit, &ret)) 37 if (ds_touch_bit(dev, bit, &ret))
38 return 0; 38 return 0;
@@ -40,23 +40,23 @@ static u8 ds9490r_touch_bit(unsigned long data, u8 bit)
40 return ret; 40 return ret;
41} 41}
42 42
43static void ds9490r_write_bit(unsigned long data, u8 bit) 43static void ds9490r_write_bit(void *data, u8 bit)
44{ 44{
45 struct ds_device *dev = (struct ds_device *)data; 45 struct ds_device *dev = data;
46 46
47 ds_write_bit(dev, bit); 47 ds_write_bit(dev, bit);
48} 48}
49 49
50static void ds9490r_write_byte(unsigned long data, u8 byte) 50static void ds9490r_write_byte(void *data, u8 byte)
51{ 51{
52 struct ds_device *dev = (struct ds_device *)data; 52 struct ds_device *dev = data;
53 53
54 ds_write_byte(dev, byte); 54 ds_write_byte(dev, byte);
55} 55}
56 56
57static u8 ds9490r_read_bit(unsigned long data) 57static u8 ds9490r_read_bit(void *data)
58{ 58{
59 struct ds_device *dev = (struct ds_device *)data; 59 struct ds_device *dev = data;
60 int err; 60 int err;
61 u8 bit = 0; 61 u8 bit = 0;
62 62
@@ -70,9 +70,9 @@ static u8 ds9490r_read_bit(unsigned long data)
70 return bit & 1; 70 return bit & 1;
71} 71}
72 72
73static u8 ds9490r_read_byte(unsigned long data) 73static u8 ds9490r_read_byte(void *data)
74{ 74{
75 struct ds_device *dev = (struct ds_device *)data; 75 struct ds_device *dev = data;
76 int err; 76 int err;
77 u8 byte = 0; 77 u8 byte = 0;
78 78
@@ -83,16 +83,16 @@ static u8 ds9490r_read_byte(unsigned long data)
83 return byte; 83 return byte;
84} 84}
85 85
86static void ds9490r_write_block(unsigned long data, const u8 *buf, int len) 86static void ds9490r_write_block(void *data, const u8 *buf, int len)
87{ 87{
88 struct ds_device *dev = (struct ds_device *)data; 88 struct ds_device *dev = data;
89 89
90 ds_write_block(dev, (u8 *)buf, len); 90 ds_write_block(dev, (u8 *)buf, len);
91} 91}
92 92
93static u8 ds9490r_read_block(unsigned long data, u8 *buf, int len) 93static u8 ds9490r_read_block(void *data, u8 *buf, int len)
94{ 94{
95 struct ds_device *dev = (struct ds_device *)data; 95 struct ds_device *dev = data;
96 int err; 96 int err;
97 97
98 err = ds_read_block(dev, buf, len); 98 err = ds_read_block(dev, buf, len);
@@ -102,9 +102,9 @@ static u8 ds9490r_read_block(unsigned long data, u8 *buf, int len)
102 return len; 102 return len;
103} 103}
104 104
105static u8 ds9490r_reset(unsigned long data) 105static u8 ds9490r_reset(void *data)
106{ 106{
107 struct ds_device *dev = (struct ds_device *)data; 107 struct ds_device *dev = data;
108 struct ds_status st; 108 struct ds_status st;
109 int err; 109 int err;
110 110
@@ -136,7 +136,7 @@ static int __devinit ds_w1_init(void)
136 136
137 memset(ds_bus_master, 0, sizeof(*ds_bus_master)); 137 memset(ds_bus_master, 0, sizeof(*ds_bus_master));
138 138
139 ds_bus_master->data = (unsigned long)ds_dev; 139 ds_bus_master->data = ds_dev;
140 ds_bus_master->touch_bit = &ds9490r_touch_bit; 140 ds_bus_master->touch_bit = &ds9490r_touch_bit;
141 ds_bus_master->read_bit = &ds9490r_read_bit; 141 ds_bus_master->read_bit = &ds9490r_read_bit;
142 ds_bus_master->write_bit = &ds9490r_write_bit; 142 ds_bus_master->write_bit = &ds9490r_write_bit;
diff --git a/drivers/w1/dscore.c b/drivers/w1/masters/dscore.c
index b9146306df..2cf7776a70 100644
--- a/drivers/w1/dscore.c
+++ b/drivers/w1/masters/dscore.c
@@ -340,7 +340,7 @@ int ds_reset(struct ds_device *dev, struct ds_status *st)
340 return -EIO; 340 return -EIO;
341 } 341 }
342#endif 342#endif
343 343
344 return 0; 344 return 0;
345} 345}
346 346
@@ -348,7 +348,7 @@ int ds_reset(struct ds_device *dev, struct ds_status *st)
348int ds_set_speed(struct ds_device *dev, int speed) 348int ds_set_speed(struct ds_device *dev, int speed)
349{ 349{
350 int err; 350 int err;
351 351
352 if (speed != SPEED_NORMAL && speed != SPEED_FLEXIBLE && speed != SPEED_OVERDRIVE) 352 if (speed != SPEED_NORMAL && speed != SPEED_FLEXIBLE && speed != SPEED_OVERDRIVE)
353 return -EINVAL; 353 return -EINVAL;
354 354
diff --git a/drivers/w1/dscore.h b/drivers/w1/masters/dscore.h
index 6cf5671d6e..6cf5671d6e 100644
--- a/drivers/w1/dscore.h
+++ b/drivers/w1/masters/dscore.h
diff --git a/drivers/w1/matrox_w1.c b/drivers/w1/masters/matrox_w1.c
index 0b03f8f93f..591809cbbb 100644
--- a/drivers/w1/matrox_w1.c
+++ b/drivers/w1/masters/matrox_w1.c
@@ -19,8 +19,8 @@
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */ 20 */
21 21
22#include <asm/atomic.h>
23#include <asm/types.h> 22#include <asm/types.h>
23#include <asm/atomic.h>
24#include <asm/io.h> 24#include <asm/io.h>
25 25
26#include <linux/delay.h> 26#include <linux/delay.h>
@@ -35,9 +35,9 @@
35#include <linux/pci.h> 35#include <linux/pci.h>
36#include <linux/timer.h> 36#include <linux/timer.h>
37 37
38#include "w1.h" 38#include "../w1.h"
39#include "w1_int.h" 39#include "../w1_int.h"
40#include "w1_log.h" 40#include "../w1_log.h"
41 41
42MODULE_LICENSE("GPL"); 42MODULE_LICENSE("GPL");
43MODULE_AUTHOR("Evgeniy Polyakov <johnpol@2ka.mipt.ru>"); 43MODULE_AUTHOR("Evgeniy Polyakov <johnpol@2ka.mipt.ru>");
@@ -90,8 +90,8 @@ struct matrox_device
90 struct w1_bus_master *bus_master; 90 struct w1_bus_master *bus_master;
91}; 91};
92 92
93static u8 matrox_w1_read_ddc_bit(unsigned long); 93static u8 matrox_w1_read_ddc_bit(void *);
94static void matrox_w1_write_ddc_bit(unsigned long, u8); 94static void matrox_w1_write_ddc_bit(void *, u8);
95 95
96/* 96/*
97 * These functions read and write DDC Data bit. 97 * These functions read and write DDC Data bit.
@@ -122,10 +122,10 @@ static __inline__ void matrox_w1_write_reg(struct matrox_device *dev, u8 reg, u8
122 wmb(); 122 wmb();
123} 123}
124 124
125static void matrox_w1_write_ddc_bit(unsigned long data, u8 bit) 125static void matrox_w1_write_ddc_bit(void *data, u8 bit)
126{ 126{
127 u8 ret; 127 u8 ret;
128 struct matrox_device *dev = (struct matrox_device *) data; 128 struct matrox_device *dev = data;
129 129
130 if (bit) 130 if (bit)
131 bit = 0; 131 bit = 0;
@@ -137,10 +137,10 @@ static void matrox_w1_write_ddc_bit(unsigned long data, u8 bit)
137 matrox_w1_write_reg(dev, MATROX_GET_DATA, 0x00); 137 matrox_w1_write_reg(dev, MATROX_GET_DATA, 0x00);
138} 138}
139 139
140static u8 matrox_w1_read_ddc_bit(unsigned long data) 140static u8 matrox_w1_read_ddc_bit(void *data)
141{ 141{
142 u8 ret; 142 u8 ret;
143 struct matrox_device *dev = (struct matrox_device *) data; 143 struct matrox_device *dev = data;
144 144
145 ret = matrox_w1_read_reg(dev, MATROX_GET_DATA); 145 ret = matrox_w1_read_reg(dev, MATROX_GET_DATA);
146 146
@@ -198,7 +198,7 @@ static int __devinit matrox_w1_probe(struct pci_dev *pdev, const struct pci_devi
198 198
199 matrox_w1_hw_init(dev); 199 matrox_w1_hw_init(dev);
200 200
201 dev->bus_master->data = (unsigned long) dev; 201 dev->bus_master->data = dev;
202 dev->bus_master->read_bit = &matrox_w1_read_ddc_bit; 202 dev->bus_master->read_bit = &matrox_w1_read_ddc_bit;
203 dev->bus_master->write_bit = &matrox_w1_write_ddc_bit; 203 dev->bus_master->write_bit = &matrox_w1_write_ddc_bit;
204 204
diff --git a/drivers/w1/slaves/Kconfig b/drivers/w1/slaves/Kconfig
new file mode 100644
index 0000000000..f9d4c91fc5
--- /dev/null
+++ b/drivers/w1/slaves/Kconfig
@@ -0,0 +1,38 @@
1#
2# 1-wire slaves configuration
3#
4
5menu "1-wire Slaves"
6 depends on W1
7
8config W1_SLAVE_THERM
9 tristate "Thermal family implementation"
10 depends on W1
11 help
12 Say Y here if you want to connect 1-wire thermal sensors to you
13 wire.
14
15config W1_SLAVE_SMEM
16 tristate "Simple 64bit memory family implementation"
17 depends on W1
18 help
19 Say Y here if you want to connect 1-wire
20 simple 64bit memory rom(ds2401/ds2411/ds1990*) to you wire.
21
22config W1_SLAVE_DS2433
23 tristate "4kb EEPROM family support (DS2433)"
24 depends on W1
25 help
26 Say Y here if you want to use a 1-wire
27 4kb EEPROM family device (DS2433).
28
29config W1_SLAVE_DS2433_CRC
30 bool "Protect DS2433 data with a CRC16"
31 depends on W1_DS2433
32 select CRC16
33 help
34 Say Y here to protect DS2433 data with a CRC16.
35 Each block has 30 bytes of data and a two byte CRC16.
36 Full block writes are only allowed if the CRC is valid.
37
38endmenu
diff --git a/drivers/w1/slaves/Makefile b/drivers/w1/slaves/Makefile
new file mode 100644
index 0000000000..70e21e2d70
--- /dev/null
+++ b/drivers/w1/slaves/Makefile
@@ -0,0 +1,12 @@
1#
2# Makefile for the Dallas's 1-wire slaves.
3#
4
5ifeq ($(CONFIG_W1_SLAVE_DS2433_CRC), y)
6EXTRA_CFLAGS += -DCONFIG_W1_F23_CRC
7endif
8
9obj-$(CONFIG_W1_SLAVE_THERM) += w1_therm.o
10obj-$(CONFIG_W1_SLAVE_SMEM) += w1_smem.o
11obj-$(CONFIG_W1_SLAVE_DS2433) += w1_ds2433.o
12
diff --git a/drivers/w1/w1_ds2433.c b/drivers/w1/slaves/w1_ds2433.c
index 1e3d98aac1..fb118be789 100644
--- a/drivers/w1/w1_ds2433.c
+++ b/drivers/w1/slaves/w1_ds2433.c
@@ -21,10 +21,10 @@
21 21
22#endif 22#endif
23 23
24#include "w1.h" 24#include "../w1.h"
25#include "w1_io.h" 25#include "../w1_io.h"
26#include "w1_int.h" 26#include "../w1_int.h"
27#include "w1_family.h" 27#include "../w1_family.h"
28 28
29MODULE_LICENSE("GPL"); 29MODULE_LICENSE("GPL");
30MODULE_AUTHOR("Ben Gardner <bgardner@wabtec.com>"); 30MODULE_AUTHOR("Ben Gardner <bgardner@wabtec.com>");
diff --git a/drivers/w1/w1_smem.c b/drivers/w1/slaves/w1_smem.c
index e3209d0aca..c6d3be54f9 100644
--- a/drivers/w1/w1_smem.c
+++ b/drivers/w1/slaves/w1_smem.c
@@ -27,10 +27,10 @@
27#include <linux/device.h> 27#include <linux/device.h>
28#include <linux/types.h> 28#include <linux/types.h>
29 29
30#include "w1.h" 30#include "../w1.h"
31#include "w1_io.h" 31#include "../w1_io.h"
32#include "w1_int.h" 32#include "../w1_int.h"
33#include "w1_family.h" 33#include "../w1_family.h"
34 34
35MODULE_LICENSE("GPL"); 35MODULE_LICENSE("GPL");
36MODULE_AUTHOR("Evgeniy Polyakov <johnpol@2ka.mipt.ru>"); 36MODULE_AUTHOR("Evgeniy Polyakov <johnpol@2ka.mipt.ru>");
@@ -51,7 +51,7 @@ static int __init w1_smem_init(void)
51 err = w1_register_family(&w1_smem_family_01); 51 err = w1_register_family(&w1_smem_family_01);
52 if (err) 52 if (err)
53 return err; 53 return err;
54 54
55 err = w1_register_family(&w1_smem_family_81); 55 err = w1_register_family(&w1_smem_family_81);
56 if (err) { 56 if (err) {
57 w1_unregister_family(&w1_smem_family_01); 57 w1_unregister_family(&w1_smem_family_01);
diff --git a/drivers/w1/w1_therm.c b/drivers/w1/slaves/w1_therm.c
index 4577df3cfc..536d16d78d 100644
--- a/drivers/w1/w1_therm.c
+++ b/drivers/w1/slaves/w1_therm.c
@@ -28,10 +28,10 @@
28#include <linux/types.h> 28#include <linux/types.h>
29#include <linux/delay.h> 29#include <linux/delay.h>
30 30
31#include "w1.h" 31#include "../w1.h"
32#include "w1_io.h" 32#include "../w1_io.h"
33#include "w1_int.h" 33#include "../w1_int.h"
34#include "w1_family.h" 34#include "../w1_family.h"
35 35
36MODULE_LICENSE("GPL"); 36MODULE_LICENSE("GPL");
37MODULE_AUTHOR("Evgeniy Polyakov <johnpol@2ka.mipt.ru>"); 37MODULE_AUTHOR("Evgeniy Polyakov <johnpol@2ka.mipt.ru>");
@@ -123,12 +123,12 @@ static inline int w1_DS18S20_convert_temp(u8 rom[9])
123 123
124 if (!rom[7]) 124 if (!rom[7])
125 return 0; 125 return 0;
126 126
127 if (rom[1] == 0) 127 if (rom[1] == 0)
128 t = ((s32)rom[0] >> 1)*1000; 128 t = ((s32)rom[0] >> 1)*1000;
129 else 129 else
130 t = 1000*(-1*(s32)(0x100-rom[0]) >> 1); 130 t = 1000*(-1*(s32)(0x100-rom[0]) >> 1);
131 131
132 t -= 250; 132 t -= 250;
133 h = 1000*((s32)rom[7] - (s32)rom[6]); 133 h = 1000*((s32)rom[7] - (s32)rom[6]);
134 h /= (s32)rom[7]; 134 h /= (s32)rom[7];
@@ -231,7 +231,7 @@ static ssize_t w1_therm_read_bin(struct kobject *kobj, char *buf, loff_t off, si
231 231
232 for (i = 0; i < 9; ++i) 232 for (i = 0; i < 9; ++i)
233 count += sprintf(buf + count, "%02x ", sl->rom[i]); 233 count += sprintf(buf + count, "%02x ", sl->rom[i]);
234 234
235 count += sprintf(buf + count, "t=%d\n", w1_convert_temp(rom, sl->family->fid)); 235 count += sprintf(buf + count, "t=%d\n", w1_convert_temp(rom, sl->family->fid));
236out: 236out:
237 up(&dev->mutex); 237 up(&dev->mutex);
diff --git a/drivers/w1/w1.c b/drivers/w1/w1.c
index 024206c4a0..a698b517e8 100644
--- a/drivers/w1/w1.c
+++ b/drivers/w1/w1.c
@@ -30,6 +30,7 @@
30#include <linux/device.h> 30#include <linux/device.h>
31#include <linux/slab.h> 31#include <linux/slab.h>
32#include <linux/sched.h> 32#include <linux/sched.h>
33#include <linux/kthread.h>
33 34
34#include <asm/atomic.h> 35#include <asm/atomic.h>
35 36
@@ -57,9 +58,7 @@ module_param_named(slave_ttl, w1_max_slave_ttl, int, 0);
57DEFINE_SPINLOCK(w1_mlock); 58DEFINE_SPINLOCK(w1_mlock);
58LIST_HEAD(w1_masters); 59LIST_HEAD(w1_masters);
59 60
60static pid_t control_thread; 61static struct task_struct *w1_control_thread;
61static int control_needs_exit;
62static DECLARE_COMPLETION(w1_control_complete);
63 62
64static int w1_master_match(struct device *dev, struct device_driver *drv) 63static int w1_master_match(struct device *dev, struct device_driver *drv)
65{ 64{
@@ -164,11 +163,12 @@ struct device w1_master_device = {
164 .release = &w1_master_release 163 .release = &w1_master_release
165}; 164};
166 165
167struct device_driver w1_slave_driver = { 166static struct device_driver w1_slave_driver = {
168 .name = "w1_slave_driver", 167 .name = "w1_slave_driver",
169 .bus = &w1_bus_type, 168 .bus = &w1_bus_type,
170}; 169};
171 170
171#if 0
172struct device w1_slave_device = { 172struct device w1_slave_device = {
173 .parent = NULL, 173 .parent = NULL,
174 .bus = &w1_bus_type, 174 .bus = &w1_bus_type,
@@ -176,6 +176,7 @@ struct device w1_slave_device = {
176 .driver = &w1_slave_driver, 176 .driver = &w1_slave_driver,
177 .release = &w1_slave_release 177 .release = &w1_slave_release
178}; 178};
179#endif /* 0 */
179 180
180static ssize_t w1_master_attribute_show_name(struct device *dev, struct device_attribute *attr, char *buf) 181static ssize_t w1_master_attribute_show_name(struct device *dev, struct device_attribute *attr, char *buf)
181{ 182{
@@ -355,7 +356,7 @@ int w1_create_master_attributes(struct w1_master *master)
355 return sysfs_create_group(&master->dev.kobj, &w1_master_defattr_group); 356 return sysfs_create_group(&master->dev.kobj, &w1_master_defattr_group);
356} 357}
357 358
358void w1_destroy_master_attributes(struct w1_master *master) 359static void w1_destroy_master_attributes(struct w1_master *master)
359{ 360{
360 sysfs_remove_group(&master->dev.kobj, &w1_master_defattr_group); 361 sysfs_remove_group(&master->dev.kobj, &w1_master_defattr_group);
361} 362}
@@ -386,11 +387,14 @@ static int w1_uevent(struct device *dev, char **envp, int num_envp, char *buffer
386 if (dev->driver != &w1_slave_driver || !sl) 387 if (dev->driver != &w1_slave_driver || !sl)
387 return 0; 388 return 0;
388 389
389 err = add_uevent_var(envp, num_envp, &cur_index, buffer, buffer_size, &cur_len, "W1_FID=%02X", sl->reg_num.family); 390 err = add_uevent_var(envp, num_envp, &cur_index, buffer, buffer_size,
391 &cur_len, "W1_FID=%02X", sl->reg_num.family);
390 if (err) 392 if (err)
391 return err; 393 return err;
392 394
393 err = add_uevent_var(envp, num_envp, &cur_index, buffer, buffer_size, &cur_len, "W1_SLAVE_ID=%024LX", (u64)sl->reg_num.id); 395 err = add_uevent_var(envp, num_envp, &cur_index, buffer, buffer_size,
396 &cur_len, "W1_SLAVE_ID=%024LX",
397 (unsigned long long)sl->reg_num.id);
394 if (err) 398 if (err)
395 return err; 399 return err;
396 400
@@ -552,7 +556,7 @@ static void w1_slave_detach(struct w1_slave *sl)
552 kfree(sl); 556 kfree(sl);
553} 557}
554 558
555static struct w1_master *w1_search_master(unsigned long data) 559static struct w1_master *w1_search_master(void *data)
556{ 560{
557 struct w1_master *dev; 561 struct w1_master *dev;
558 int found = 0; 562 int found = 0;
@@ -583,7 +587,7 @@ void w1_reconnect_slaves(struct w1_family *f)
583 spin_unlock_bh(&w1_mlock); 587 spin_unlock_bh(&w1_mlock);
584} 588}
585 589
586static void w1_slave_found(unsigned long data, u64 rn) 590static void w1_slave_found(void *data, u64 rn)
587{ 591{
588 int slave_count; 592 int slave_count;
589 struct w1_slave *sl; 593 struct w1_slave *sl;
@@ -595,8 +599,8 @@ static void w1_slave_found(unsigned long data, u64 rn)
595 599
596 dev = w1_search_master(data); 600 dev = w1_search_master(data);
597 if (!dev) { 601 if (!dev) {
598 printk(KERN_ERR "Failed to find w1 master device for data %08lx, it is impossible.\n", 602 printk(KERN_ERR "Failed to find w1 master device for data %p, "
599 data); 603 "it is impossible.\n", data);
600 return; 604 return;
601 } 605 }
602 606
@@ -712,22 +716,16 @@ static int w1_control(void *data)
712{ 716{
713 struct w1_slave *sl, *sln; 717 struct w1_slave *sl, *sln;
714 struct w1_master *dev, *n; 718 struct w1_master *dev, *n;
715 int err, have_to_wait = 0; 719 int have_to_wait = 0;
716 720
717 daemonize("w1_control"); 721 while (!kthread_should_stop() || have_to_wait) {
718 allow_signal(SIGTERM);
719
720 while (!control_needs_exit || have_to_wait) {
721 have_to_wait = 0; 722 have_to_wait = 0;
722 723
723 try_to_freeze(); 724 try_to_freeze();
724 msleep_interruptible(w1_control_timeout * 1000); 725 msleep_interruptible(w1_control_timeout * 1000);
725 726
726 if (signal_pending(current))
727 flush_signals(current);
728
729 list_for_each_entry_safe(dev, n, &w1_masters, w1_master_entry) { 727 list_for_each_entry_safe(dev, n, &w1_masters, w1_master_entry) {
730 if (!control_needs_exit && !dev->flags) 728 if (!kthread_should_stop() && !dev->flags)
731 continue; 729 continue;
732 /* 730 /*
733 * Little race: we can create thread but not set the flag. 731 * Little race: we can create thread but not set the flag.
@@ -738,21 +736,12 @@ static int w1_control(void *data)
738 continue; 736 continue;
739 } 737 }
740 738
741 if (control_needs_exit) { 739 if (kthread_should_stop() || test_bit(W1_MASTER_NEED_EXIT, &dev->flags)) {
742 set_bit(W1_MASTER_NEED_EXIT, &dev->flags); 740 set_bit(W1_MASTER_NEED_EXIT, &dev->flags);
743 741
744 err = kill_proc(dev->kpid, SIGTERM, 1); 742 spin_lock(&w1_mlock);
745 if (err)
746 dev_err(&dev->dev,
747 "Failed to send signal to w1 kernel thread %d.\n",
748 dev->kpid);
749 }
750
751 if (test_bit(W1_MASTER_NEED_EXIT, &dev->flags)) {
752 wait_for_completion(&dev->dev_exited);
753 spin_lock_bh(&w1_mlock);
754 list_del(&dev->w1_master_entry); 743 list_del(&dev->w1_master_entry);
755 spin_unlock_bh(&w1_mlock); 744 spin_unlock(&w1_mlock);
756 745
757 down(&dev->mutex); 746 down(&dev->mutex);
758 list_for_each_entry_safe(sl, sln, &dev->slist, w1_slave_entry) { 747 list_for_each_entry_safe(sl, sln, &dev->slist, w1_slave_entry) {
@@ -784,7 +773,7 @@ static int w1_control(void *data)
784 } 773 }
785 } 774 }
786 775
787 complete_and_exit(&w1_control_complete, 0); 776 return 0;
788} 777}
789 778
790int w1_process(void *data) 779int w1_process(void *data)
@@ -792,17 +781,11 @@ int w1_process(void *data)
792 struct w1_master *dev = (struct w1_master *) data; 781 struct w1_master *dev = (struct w1_master *) data;
793 struct w1_slave *sl, *sln; 782 struct w1_slave *sl, *sln;
794 783
795 daemonize("%s", dev->name); 784 while (!kthread_should_stop() && !test_bit(W1_MASTER_NEED_EXIT, &dev->flags)) {
796 allow_signal(SIGTERM);
797
798 while (!test_bit(W1_MASTER_NEED_EXIT, &dev->flags)) {
799 try_to_freeze(); 785 try_to_freeze();
800 msleep_interruptible(w1_timeout * 1000); 786 msleep_interruptible(w1_timeout * 1000);
801 787
802 if (signal_pending(current)) 788 if (kthread_should_stop() || test_bit(W1_MASTER_NEED_EXIT, &dev->flags))
803 flush_signals(current);
804
805 if (test_bit(W1_MASTER_NEED_EXIT, &dev->flags))
806 break; 789 break;
807 790
808 if (!dev->initialized) 791 if (!dev->initialized)
@@ -835,7 +818,6 @@ int w1_process(void *data)
835 } 818 }
836 819
837 atomic_dec(&dev->refcnt); 820 atomic_dec(&dev->refcnt);
838 complete_and_exit(&dev->dev_exited, 0);
839 821
840 return 0; 822 return 0;
841} 823}
@@ -868,11 +850,11 @@ static int w1_init(void)
868 goto err_out_master_unregister; 850 goto err_out_master_unregister;
869 } 851 }
870 852
871 control_thread = kernel_thread(&w1_control, NULL, 0); 853 w1_control_thread = kthread_run(w1_control, NULL, "w1_control");
872 if (control_thread < 0) { 854 if (IS_ERR(w1_control_thread)) {
855 retval = PTR_ERR(w1_control_thread);
873 printk(KERN_ERR "Failed to create control thread. err=%d\n", 856 printk(KERN_ERR "Failed to create control thread. err=%d\n",
874 control_thread); 857 retval);
875 retval = control_thread;
876 goto err_out_slave_unregister; 858 goto err_out_slave_unregister;
877 } 859 }
878 860
@@ -898,8 +880,7 @@ static void w1_fini(void)
898 list_for_each_entry(dev, &w1_masters, w1_master_entry) 880 list_for_each_entry(dev, &w1_masters, w1_master_entry)
899 __w1_remove_master_device(dev); 881 __w1_remove_master_device(dev);
900 882
901 control_needs_exit = 1; 883 kthread_stop(w1_control_thread);
902 wait_for_completion(&w1_control_complete);
903 884
904 driver_unregister(&w1_slave_driver); 885 driver_unregister(&w1_slave_driver);
905 driver_unregister(&w1_master_driver); 886 driver_unregister(&w1_master_driver);
diff --git a/drivers/w1/w1.h b/drivers/w1/w1.h
index d8900780c3..56980505e6 100644
--- a/drivers/w1/w1.h
+++ b/drivers/w1/w1.h
@@ -80,7 +80,7 @@ struct w1_slave
80 struct completion released; 80 struct completion released;
81}; 81};
82 82
83typedef void (* w1_slave_found_callback)(unsigned long, u64); 83typedef void (* w1_slave_found_callback)(void *, u64);
84 84
85 85
86/** 86/**
@@ -93,16 +93,16 @@ typedef void (* w1_slave_found_callback)(unsigned long, u64);
93struct w1_bus_master 93struct w1_bus_master
94{ 94{
95 /** the first parameter in all the functions below */ 95 /** the first parameter in all the functions below */
96 unsigned long data; 96 void *data;
97 97
98 /** 98 /**
99 * Sample the line level 99 * Sample the line level
100 * @return the level read (0 or 1) 100 * @return the level read (0 or 1)
101 */ 101 */
102 u8 (*read_bit)(unsigned long); 102 u8 (*read_bit)(void *);
103 103
104 /** Sets the line level */ 104 /** Sets the line level */
105 void (*write_bit)(unsigned long, u8); 105 void (*write_bit)(void *, u8);
106 106
107 /** 107 /**
108 * touch_bit is the lowest-level function for devices that really 108 * touch_bit is the lowest-level function for devices that really
@@ -111,42 +111,42 @@ struct w1_bus_master
111 * touch_bit(1) = write-1 / read cycle 111 * touch_bit(1) = write-1 / read cycle
112 * @return the bit read (0 or 1) 112 * @return the bit read (0 or 1)
113 */ 113 */
114 u8 (*touch_bit)(unsigned long, u8); 114 u8 (*touch_bit)(void *, u8);
115 115
116 /** 116 /**
117 * Reads a bytes. Same as 8 touch_bit(1) calls. 117 * Reads a bytes. Same as 8 touch_bit(1) calls.
118 * @return the byte read 118 * @return the byte read
119 */ 119 */
120 u8 (*read_byte)(unsigned long); 120 u8 (*read_byte)(void *);
121 121
122 /** 122 /**
123 * Writes a byte. Same as 8 touch_bit(x) calls. 123 * Writes a byte. Same as 8 touch_bit(x) calls.
124 */ 124 */
125 void (*write_byte)(unsigned long, u8); 125 void (*write_byte)(void *, u8);
126 126
127 /** 127 /**
128 * Same as a series of read_byte() calls 128 * Same as a series of read_byte() calls
129 * @return the number of bytes read 129 * @return the number of bytes read
130 */ 130 */
131 u8 (*read_block)(unsigned long, u8 *, int); 131 u8 (*read_block)(void *, u8 *, int);
132 132
133 /** Same as a series of write_byte() calls */ 133 /** Same as a series of write_byte() calls */
134 void (*write_block)(unsigned long, const u8 *, int); 134 void (*write_block)(void *, const u8 *, int);
135 135
136 /** 136 /**
137 * Combines two reads and a smart write for ROM searches 137 * Combines two reads and a smart write for ROM searches
138 * @return bit0=Id bit1=comp_id bit2=dir_taken 138 * @return bit0=Id bit1=comp_id bit2=dir_taken
139 */ 139 */
140 u8 (*triplet)(unsigned long, u8); 140 u8 (*triplet)(void *, u8);
141 141
142 /** 142 /**
143 * long write-0 with a read for the presence pulse detection 143 * long write-0 with a read for the presence pulse detection
144 * @return -1=Error, 0=Device present, 1=No device present 144 * @return -1=Error, 0=Device present, 1=No device present
145 */ 145 */
146 u8 (*reset_bus)(unsigned long); 146 u8 (*reset_bus)(void *);
147 147
148 /** Really nice hardware can handles the ROM searches */ 148 /** Really nice hardware can handles the ROM searches */
149 void (*search)(unsigned long, w1_slave_found_callback); 149 void (*search)(void *, w1_slave_found_callback);
150}; 150};
151 151
152#define W1_MASTER_NEED_EXIT 0 152#define W1_MASTER_NEED_EXIT 0
@@ -172,12 +172,11 @@ struct w1_master
172 172
173 long flags; 173 long flags;
174 174
175 pid_t kpid; 175 struct task_struct *thread;
176 struct semaphore mutex; 176 struct semaphore mutex;
177 177
178 struct device_driver *driver; 178 struct device_driver *driver;
179 struct device dev; 179 struct device dev;
180 struct completion dev_exited;
181 180
182 struct w1_bus_master *bus_master; 181 struct w1_bus_master *bus_master;
183 182
@@ -203,6 +202,16 @@ static inline struct w1_master* dev_to_w1_master(struct device *dev)
203 return container_of(dev, struct w1_master, dev); 202 return container_of(dev, struct w1_master, dev);
204} 203}
205 204
205extern int w1_max_slave_count;
206extern int w1_max_slave_ttl;
207extern spinlock_t w1_mlock;
208extern struct list_head w1_masters;
209extern struct device_driver w1_master_driver;
210extern struct device w1_master_device;
211
212int w1_process(void *data);
213void w1_reconnect_slaves(struct w1_family *f);
214
206#endif /* __KERNEL__ */ 215#endif /* __KERNEL__ */
207 216
208#endif /* __W1_H */ 217#endif /* __W1_H */
diff --git a/drivers/w1/w1_family.c b/drivers/w1/w1_family.c
index 9e293e139a..0e32c114f9 100644
--- a/drivers/w1/w1_family.c
+++ b/drivers/w1/w1_family.c
@@ -25,10 +25,10 @@
25#include <linux/delay.h> 25#include <linux/delay.h>
26 26
27#include "w1_family.h" 27#include "w1_family.h"
28#include "w1.h"
28 29
29DEFINE_SPINLOCK(w1_flock); 30DEFINE_SPINLOCK(w1_flock);
30static LIST_HEAD(w1_families); 31static LIST_HEAD(w1_families);
31extern void w1_reconnect_slaves(struct w1_family *f);
32 32
33int w1_register_family(struct w1_family *newf) 33int w1_register_family(struct w1_family *newf)
34{ 34{
diff --git a/drivers/w1/w1_int.c b/drivers/w1/w1_int.c
index c3f67eafc7..68565aacec 100644
--- a/drivers/w1/w1_int.c
+++ b/drivers/w1/w1_int.c
@@ -22,23 +22,15 @@
22#include <linux/kernel.h> 22#include <linux/kernel.h>
23#include <linux/list.h> 23#include <linux/list.h>
24#include <linux/delay.h> 24#include <linux/delay.h>
25#include <linux/kthread.h>
25 26
26#include "w1.h" 27#include "w1.h"
27#include "w1_log.h" 28#include "w1_log.h"
28#include "w1_netlink.h" 29#include "w1_netlink.h"
30#include "w1_int.h"
29 31
30static u32 w1_ids = 1; 32static u32 w1_ids = 1;
31 33
32extern struct device_driver w1_master_driver;
33extern struct bus_type w1_bus_type;
34extern struct device w1_master_device;
35extern int w1_max_slave_count;
36extern int w1_max_slave_ttl;
37extern struct list_head w1_masters;
38extern spinlock_t w1_mlock;
39
40extern int w1_process(void *);
41
42static struct w1_master * w1_alloc_dev(u32 id, int slave_count, int slave_ttl, 34static struct w1_master * w1_alloc_dev(u32 id, int slave_count, int slave_ttl,
43 struct device_driver *driver, 35 struct device_driver *driver,
44 struct device *device) 36 struct device *device)
@@ -65,7 +57,6 @@ static struct w1_master * w1_alloc_dev(u32 id, int slave_count, int slave_ttl,
65 dev->max_slave_count = slave_count; 57 dev->max_slave_count = slave_count;
66 dev->slave_count = 0; 58 dev->slave_count = 0;
67 dev->attempts = 0; 59 dev->attempts = 0;
68 dev->kpid = -1;
69 dev->initialized = 0; 60 dev->initialized = 0;
70 dev->id = id; 61 dev->id = id;
71 dev->slave_ttl = slave_ttl; 62 dev->slave_ttl = slave_ttl;
@@ -76,8 +67,6 @@ static struct w1_master * w1_alloc_dev(u32 id, int slave_count, int slave_ttl,
76 INIT_LIST_HEAD(&dev->slist); 67 INIT_LIST_HEAD(&dev->slist);
77 init_MUTEX(&dev->mutex); 68 init_MUTEX(&dev->mutex);
78 69
79 init_completion(&dev->dev_exited);
80
81 memcpy(&dev->dev, device, sizeof(struct device)); 70 memcpy(&dev->dev, device, sizeof(struct device));
82 snprintf(dev->dev.bus_id, sizeof(dev->dev.bus_id), 71 snprintf(dev->dev.bus_id, sizeof(dev->dev.bus_id),
83 "w1_bus_master%u", dev->id); 72 "w1_bus_master%u", dev->id);
@@ -103,7 +92,7 @@ static struct w1_master * w1_alloc_dev(u32 id, int slave_count, int slave_ttl,
103 return dev; 92 return dev;
104} 93}
105 94
106void w1_free_dev(struct w1_master *dev) 95static void w1_free_dev(struct w1_master *dev)
107{ 96{
108 device_unregister(&dev->dev); 97 device_unregister(&dev->dev);
109} 98}
@@ -125,12 +114,12 @@ int w1_add_master_device(struct w1_bus_master *master)
125 if (!dev) 114 if (!dev)
126 return -ENOMEM; 115 return -ENOMEM;
127 116
128 dev->kpid = kernel_thread(&w1_process, dev, 0); 117 dev->thread = kthread_run(&w1_process, dev, "%s", dev->name);
129 if (dev->kpid < 0) { 118 if (IS_ERR(dev->thread)) {
119 retval = PTR_ERR(dev->thread);
130 dev_err(&dev->dev, 120 dev_err(&dev->dev,
131 "Failed to create new kernel thread. err=%d\n", 121 "Failed to create new kernel thread. err=%d\n",
132 dev->kpid); 122 retval);
133 retval = dev->kpid;
134 goto err_out_free_dev; 123 goto err_out_free_dev;
135 } 124 }
136 125
@@ -147,20 +136,14 @@ int w1_add_master_device(struct w1_bus_master *master)
147 spin_unlock(&w1_mlock); 136 spin_unlock(&w1_mlock);
148 137
149 msg.id.mst.id = dev->id; 138 msg.id.mst.id = dev->id;
150 msg.id.mst.pid = dev->kpid; 139 msg.id.mst.pid = dev->thread->pid;
151 msg.type = W1_MASTER_ADD; 140 msg.type = W1_MASTER_ADD;
152 w1_netlink_send(dev, &msg); 141 w1_netlink_send(dev, &msg);
153 142
154 return 0; 143 return 0;
155 144
156err_out_kill_thread: 145err_out_kill_thread:
157 set_bit(W1_MASTER_NEED_EXIT, &dev->flags); 146 kthread_stop(dev->thread);
158 if (kill_proc(dev->kpid, SIGTERM, 1))
159 dev_err(&dev->dev,
160 "Failed to send signal to w1 kernel thread %d.\n",
161 dev->kpid);
162 wait_for_completion(&dev->dev_exited);
163
164err_out_free_dev: 147err_out_free_dev:
165 w1_free_dev(dev); 148 w1_free_dev(dev);
166 149
@@ -169,18 +152,14 @@ err_out_free_dev:
169 152
170void __w1_remove_master_device(struct w1_master *dev) 153void __w1_remove_master_device(struct w1_master *dev)
171{ 154{
172 int err;
173 struct w1_netlink_msg msg; 155 struct w1_netlink_msg msg;
156 pid_t pid = dev->thread->pid;
174 157
175 set_bit(W1_MASTER_NEED_EXIT, &dev->flags); 158 set_bit(W1_MASTER_NEED_EXIT, &dev->flags);
176 err = kill_proc(dev->kpid, SIGTERM, 1); 159 kthread_stop(dev->thread);
177 if (err)
178 dev_err(&dev->dev,
179 "%s: Failed to send signal to w1 kernel thread %d.\n",
180 __func__, dev->kpid);
181 160
182 while (atomic_read(&dev->refcnt)) { 161 while (atomic_read(&dev->refcnt)) {
183 dev_dbg(&dev->dev, "Waiting for %s to become free: refcnt=%d.\n", 162 dev_info(&dev->dev, "Waiting for %s to become free: refcnt=%d.\n",
184 dev->name, atomic_read(&dev->refcnt)); 163 dev->name, atomic_read(&dev->refcnt));
185 164
186 if (msleep_interruptible(1000)) 165 if (msleep_interruptible(1000))
@@ -188,7 +167,7 @@ void __w1_remove_master_device(struct w1_master *dev)
188 } 167 }
189 168
190 msg.id.mst.id = dev->id; 169 msg.id.mst.id = dev->id;
191 msg.id.mst.pid = dev->kpid; 170 msg.id.mst.pid = pid;
192 msg.type = W1_MASTER_REMOVE; 171 msg.type = W1_MASTER_REMOVE;
193 w1_netlink_send(dev, &msg); 172 w1_netlink_send(dev, &msg);
194 173
@@ -217,5 +196,3 @@ void w1_remove_master_device(struct w1_bus_master *bm)
217 196
218EXPORT_SYMBOL(w1_add_master_device); 197EXPORT_SYMBOL(w1_add_master_device);
219EXPORT_SYMBOL(w1_remove_master_device); 198EXPORT_SYMBOL(w1_remove_master_device);
220
221MODULE_ALIAS_NET_PF_PROTO(PF_NETLINK, NETLINK_W1);
diff --git a/drivers/w1/w1_io.c b/drivers/w1/w1_io.c
index e2a043354d..f7f7e8bec3 100644
--- a/drivers/w1/w1_io.c
+++ b/drivers/w1/w1_io.c
@@ -28,7 +28,7 @@
28#include "w1_log.h" 28#include "w1_log.h"
29#include "w1_io.h" 29#include "w1_io.h"
30 30
31int w1_delay_parm = 1; 31static int w1_delay_parm = 1;
32module_param_named(delay_coef, w1_delay_parm, int, 0); 32module_param_named(delay_coef, w1_delay_parm, int, 0);
33 33
34static u8 w1_crc8_table[] = { 34static u8 w1_crc8_table[] = {